Skip to content

Commit

Permalink
Merge pull request #1 from ianacaburian/develop
Browse files Browse the repository at this point in the history
Publish to public npm.
  • Loading branch information
ianacaburian authored Oct 3, 2024
2 parents 3f29d20 + 314e48e commit 5ed2286
Show file tree
Hide file tree
Showing 54 changed files with 4,326 additions and 334 deletions.
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: build

on:
workflow_dispatch:
pull_request:
branches: ['master']

env:
HOMEBREW_NO_INSTALL_CLEANUP: 1

jobs:
build_and_test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- name: macOS
os: macos-14

steps:
- name: Installing OSX utils
if: ${{ matrix.name == 'macOS' }}
run: brew install osxutils

- name: Checking out code
uses: actions/checkout@v3
with:
submodules: true

- name: Install dependencies
run: npm install

- name: Lint, install tests, and build package.
run: npm run build

- name: Perform single test run.
run: npm run test run
18 changes: 18 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.cache
.next
.build
CHANGELOG.md
.contentlayer
coverage
postgres/migrations
dist
*.log
node_modules
.package-lock.json
package.json
pnpm-lock.yaml
public
*.sql
.yarn
*.html
tsconfig.json
22 changes: 19 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"semi": false,
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
"trailingComma": "none",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 80,
"tabWidth": 4
"jsxSingleQuote": true,
"proseWrap": "always",
"arrowParens": "avoid",
"importOrder": [
"",
"<BUILTIN_MODULES>",
"^react/(.*)$|^react$",
"^next/(.*)$|^next$",
"<THIRD_PARTY_MODULES>",
"",
"^(lib|app)(/.*)$",
"^[.]",
"",
".css$"
],
"importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy"]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"istream": "cpp"
}
}
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,112 @@
# generate-key-file

Provides juce_KeyGeneration::generateKeyFile() for javascript.
Ports juce_KeyGeneration::generateKeyFile() to node.

# Installation

```
npm i @ianacaburian/generate-key-file
```

# Usage

### `generateKeyFile(params: GenerateKeyFileParams, date: Date = new Date()) => string`

```
import { generateKeyFile } from '@ianacaburian/generate-key-file'
const keyFileContent = generateKeyFile({
userName: 'Ian',
userEmail: '[email protected]',
machineNumbers: '123',
appName: 'app-name-or-product-id',
privateKey: 'comma-sep-private-key'
})
```

- From juce_KeyFileGeneration.h:

```
/**
Generates the content of a key-file which can be sent to a user's machine to
unlock a product.
The returned value is a block of text containing an RSA-encoded block, followed
by some human-readable details. If you pass this block of text to
OnlineUnlockStatus::applyKeyFile(), it will decrypt it, and if the
key matches and the machine numbers match, it will unlock that machine.
Typically the way you'd use this on a server would be to build a small executable
that simply calls this method and prints the result, so that the webserver can
use this as a reply to the product's auto-registration mechanism. The
keyGenerationAppMain() function is an example of how to build such a function.
@see OnlineUnlockStatus
*/
```

- Returns the <key> string value to be used in the XML response for decryption
by the client.
- Throws ZodError for invalid params -- see
[zod](https://github.com/colinhacks/zod).

### `generateExpiringKeyFile(params: GenerateExpiringKeyFileParams, date: Date = new Date()) => string`

```
import { generateExpiringKeyFile } from '@ianacaburian/generate-key-file'
const oneDayFromNow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000)
const expiringKeyFileContent = generateExpiringKeyFile({
userName: 'Ian',
userEmail: '[email protected]',
machineNumbers: '123',
appName: 'app-name-or-product-id',
privateKey: 'comma-sep-private-key'
expiryTime: oneDayFromNow
})
```

- From juce_KeyFileGeneration.h:

```
/** Similar to the above key file generation method but with an expiry time.
You must supply a Time after which this key file should no longer be considered as active.
N.B. when an app is unlocked with an expiring key file, OnlineUnlockStatus::isUnlocked will
still return false. You must then check OnlineUnlockStatus::getExpiryTime to see if this
expiring key file is still in date and act accordingly.
@see OnlineUnlockStatus
*/
```

- Returns the <key> string value to be used in the XML response for decryption
by the client.
- Throws ZodError for invalid params -- see
[zod](https://github.com/colinhacks/zod).

# Development

```
npm run clean # Clean dist and test builds (inc test bins).
npm run lint # Lint the src dir.
npm run build # Lint, install tests, and build package.
```

## Testing

```
npm run test # Start vitest to run all tests.
npm run test -- -t "divideBy" # Start vitest to run one test.
npm run clean:test # Clean test build.
npm run open:test/console # Open test/console project in Xcode.
npm run install:test/console # Build and install the test/console bins.
```

Optional: Set "FC_NUM_RUMS" (default=1) to specify how many times to run each
(randomly generated) propery-based test -- see
[fast-check](https://github.com/dubzzz/fast-check).

```
FC_NUM_RUNS=1000 npm run test # Run each fc test 1000 times.
```
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pluginJs from '@eslint/js'
import prettierConfig from 'eslint-config-prettier'
import prettierPlugin from 'eslint-plugin-prettier'
import globals from 'globals'
import tseslint from 'typescript-eslint'

export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.{js,mjs,cjs,ts}'],
ignores: [
'dist/**',
'test/**',
'.cache/**',
'public/**',
'node_modules/**',
'*.esm.js'
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
globals: {
...globals.browser
}
},
plugins: {
'@typescript-eslint': tseslint.plugin,
prettier: prettierPlugin
},
rules: {
...tseslint.configs.recommended.rules,
...prettierConfig.rules,
...prettierPlugin.configs.recommended.rules,
'@typescript-eslint/no-unused-vars': 'off'
}
}
]
Loading

0 comments on commit 5ed2286

Please sign in to comment.