backend-test-tools 1.0.7 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.commitlintrc.js +27 -0
  2. package/.github/workflows/release.yml +46 -0
  3. package/.husky/commit-msg +1 -0
  4. package/.releaserc.js +56 -0
  5. package/CHANGELOG.md +38 -0
  6. package/dist/factory/factory.js +55 -2
  7. package/dist/factory/factory.js.map +1 -1
  8. package/dist/generators/generateAccessToken.js +23 -1
  9. package/dist/generators/generateAccessToken.js.map +1 -1
  10. package/dist/generators/generateLocale.js +16 -1
  11. package/dist/generators/generateLocale.js.map +1 -1
  12. package/dist/generators/generateUserCrypto.js +37 -6
  13. package/dist/generators/generateUserCrypto.js.map +1 -1
  14. package/dist/src/factory/factory.d.ts +59 -0
  15. package/dist/src/generators/generateAccessToken.d.ts +25 -0
  16. package/dist/src/generators/generateLocale.d.ts +20 -0
  17. package/dist/src/generators/generateUserCrypto.d.ts +45 -0
  18. package/dist/{utils → src/utils}/generateCerts/generateCerts.types.d.ts +2 -2
  19. package/dist/stubs/server-engine/sendPush.js +1 -2
  20. package/dist/stubs/server-engine/sendPush.js.map +1 -1
  21. package/dist/utils/generateCerts/generateCerts.types.js.map +1 -1
  22. package/eslint.config.mjs +21 -4
  23. package/package.json +8 -2
  24. package/src/factory/factory.ts +54 -2
  25. package/src/generators/generateAccessToken.ts +23 -1
  26. package/src/generators/generateLocale.ts +17 -2
  27. package/src/generators/generateUserCrypto.ts +37 -6
  28. package/src/utils/generateCerts/generateCerts.types.ts +2 -2
  29. package/tsconfig.build.json +4 -0
  30. package/tsconfig.json +11 -3
  31. package/dist/factory/factory.d.ts +0 -11
  32. package/dist/generators/generateAccessToken.d.ts +0 -3
  33. package/dist/generators/generateLocale.d.ts +0 -5
  34. package/dist/generators/generateUserCrypto.d.ts +0 -15
  35. /package/dist/{factory → src/factory}/factory.types.d.ts +0 -0
  36. /package/dist/{factory → src/factory}/index.d.ts +0 -0
  37. /package/dist/{factory → src/factory}/workers/index.d.ts +0 -0
  38. /package/dist/{factory → src/factory}/workers/user.d.ts +0 -0
  39. /package/dist/{factory → src/factory}/workers/user.types.d.ts +0 -0
  40. /package/dist/{generators → src/generators}/generateEcdsaKeyPair.d.ts +0 -0
  41. /package/dist/{generators → src/generators}/generateImageBuffer.d.ts +0 -0
  42. /package/dist/{generators → src/generators}/generateImageBuffer.types.d.ts +0 -0
  43. /package/dist/{generators → src/generators}/generateKeyPair.d.ts +0 -0
  44. /package/dist/{generators → src/generators}/generateKeyPair.types.d.ts +0 -0
  45. /package/dist/{generators → src/generators}/generateRsaKeyPair.d.ts +0 -0
  46. /package/dist/{generators → src/generators}/index.d.ts +0 -0
  47. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  48. /package/dist/{stubs → src/stubs}/index.d.ts +0 -0
  49. /package/dist/{stubs → src/stubs}/server-engine/Leader.types.d.ts +0 -0
  50. /package/dist/{stubs → src/stubs}/server-engine/Localizator.d.ts +0 -0
  51. /package/dist/{stubs → src/stubs}/server-engine/Localizator.types.d.ts +0 -0
  52. /package/dist/{stubs → src/stubs}/server-engine/PubSub.d.ts +0 -0
  53. /package/dist/{stubs → src/stubs}/server-engine/PubSub.types.d.ts +0 -0
  54. /package/dist/{stubs → src/stubs}/server-engine/PushNotification.d.ts +0 -0
  55. /package/dist/{stubs → src/stubs}/server-engine/PushNotification.types.d.ts +0 -0
  56. /package/dist/{stubs → src/stubs}/server-engine/index.d.ts +0 -0
  57. /package/dist/{stubs → src/stubs}/server-engine/sendPush.d.ts +0 -0
  58. /package/dist/{utils → src/utils}/generateCerts/generateCerts.const.d.ts +0 -0
  59. /package/dist/{utils → src/utils}/generateCerts/generateCerts.d.ts +0 -0
  60. /package/dist/{utils → src/utils}/generateCerts/index.d.ts +0 -0
  61. /package/dist/{utils → src/utils}/getBearer.d.ts +0 -0
  62. /package/dist/{utils → src/utils}/index.d.ts +0 -0
  63. /package/dist/{utils → src/utils}/jwtRequest.d.ts +0 -0
  64. /package/dist/{utils → src/utils}/staticRequest.d.ts +0 -0
  65. /package/dist/{utils → src/utils}/tlsRequest.d.ts +0 -0
  66. /package/dist/{utils → src/utils}/tlsRequest.types.d.ts +0 -0
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'type-enum': [
5
+ 2,
6
+ 'always',
7
+ [
8
+ 'feat', // New feature
9
+ 'fix', // Bug fix
10
+ 'docs', // Documentation only changes
11
+ 'style', // Changes that don't affect the code meaning
12
+ 'refactor', // Code change that neither fixes a bug nor adds a feature
13
+ 'perf', // Performance improvement
14
+ 'test', // Adding missing tests or correcting existing tests
15
+ 'build', // Changes that affect the build system or dependencies
16
+ 'ci', // Changes to CI configuration files and scripts
17
+ 'chore', // Other changes that don't modify src or test files
18
+ 'revert' // Reverts a previous commit
19
+ ]
20
+ ],
21
+ 'subject-case': [0],
22
+ 'subject-empty': [2, 'never'],
23
+ 'subject-full-stop': [2, 'never', '.'],
24
+ 'type-case': [2, 'always', 'lower-case'],
25
+ 'type-empty': [2, 'never']
26
+ }
27
+ };
@@ -0,0 +1,46 @@
1
+ name: Release and Publish
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+
9
+ jobs:
10
+ release:
11
+ name: Release
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: write
15
+ issues: write
16
+ pull-requests: write
17
+ id-token: write
18
+
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 0
24
+ persist-credentials: false
25
+
26
+ - name: Setup Node.js
27
+ uses: actions/setup-node@v4
28
+ with:
29
+ node-version: '22'
30
+ registry-url: 'https://registry.npmjs.org'
31
+
32
+ - name: Install dependencies
33
+ run: npm ci --ignore-scripts
34
+
35
+ - name: Build
36
+ run: npm run build
37
+
38
+ - name: Run tests
39
+ run: npm test || echo "No tests to run"
40
+
41
+ - name: Semantic Release
42
+ env:
43
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
46
+ run: npx semantic-release
@@ -0,0 +1 @@
1
+ npx --no -- commitlint --edit $1
package/.releaserc.js ADDED
@@ -0,0 +1,56 @@
1
+ module.exports = {
2
+ branches: ['main', 'master'],
3
+ plugins: [
4
+ [
5
+ '@semantic-release/commit-analyzer',
6
+ {
7
+ preset: 'conventionalcommits',
8
+ releaseRules: [
9
+ { type: 'feat', release: 'minor' },
10
+ { type: 'fix', release: 'patch' },
11
+ { type: 'perf', release: 'patch' },
12
+ { type: 'revert', release: 'patch' },
13
+ { type: 'docs', release: 'patch' },
14
+ { type: 'style', release: 'patch' },
15
+ { type: 'refactor', release: 'patch' },
16
+ { type: 'test', release: 'patch' },
17
+ { type: 'build', release: 'patch' },
18
+ { type: 'ci', release: 'patch' },
19
+ { type: 'chore', release: false },
20
+ { breaking: true, release: 'major' }
21
+ ]
22
+ }
23
+ ],
24
+ [
25
+ '@semantic-release/release-notes-generator',
26
+ {
27
+ preset: 'conventionalcommits',
28
+ presetConfig: {
29
+ types: [
30
+ { type: 'feat', section: '✨ Features' },
31
+ { type: 'fix', section: '🐛 Bug Fixes' },
32
+ { type: 'perf', section: '⚡ Performance' },
33
+ { type: 'revert', section: '⏪ Reverts' },
34
+ { type: 'docs', section: '📚 Documentation' },
35
+ { type: 'style', section: '💄 Styles' },
36
+ { type: 'refactor', section: '♻️ Code Refactoring' },
37
+ { type: 'test', section: '✅ Tests' },
38
+ { type: 'build', section: '🏗️ Build System' },
39
+ { type: 'ci', section: '👷 CI/CD' },
40
+ { type: 'chore', section: '🔧 Chores', hidden: true }
41
+ ]
42
+ }
43
+ }
44
+ ],
45
+ '@semantic-release/changelog',
46
+ '@semantic-release/npm',
47
+ [
48
+ '@semantic-release/git',
49
+ {
50
+ assets: ['package.json', 'package-lock.json', 'CHANGELOG.md'],
51
+ message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
52
+ }
53
+ ],
54
+ '@semantic-release/github'
55
+ ]
56
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ ## [1.1.2](https://github.com/prakashmahendran/backend-test-tools/compare/v1.1.1...v1.1.2) (2025-12-09)
2
+
3
+ ### 🐛 Bug Fixes
4
+
5
+ * update generateCerts types to use specific pki.rsa.PrivateKey ([26ed6e6](https://github.com/prakashmahendran/backend-test-tools/commit/26ed6e69127cd6e7f4b0036475299b9457c742c5))
6
+
7
+ ### 👷 CI/CD
8
+
9
+ * update Node.js version to 22 for semantic-release 25.x compatibility ([a3ba4fd](https://github.com/prakashmahendran/backend-test-tools/commit/a3ba4fdd92680c0f24cbf561b50596f992a3cb2d))
10
+
11
+ ## [1.1.1](https://github.com/prakashmahendran/backend-test-tools/compare/v1.1.0...v1.1.1) (2025-12-09)
12
+
13
+ ### 🐛 Bug Fixes
14
+
15
+ * revert to unscoped package name backend-test-tools ([fc94fd0](https://github.com/prakashmahendran/backend-test-tools/commit/fc94fd09df7c464929236e989e1fe17f0f1d0009))
16
+
17
+ ## [1.1.0](https://github.com/prakashmahendran/backend-test-tools/compare/v1.0.1...v1.1.0) (2025-12-09)
18
+
19
+ ### ✨ Features
20
+
21
+ * new release ([2788d85](https://github.com/prakashmahendran/backend-test-tools/commit/2788d85d454f06ab3d847e42a0629127fa830d9f))
22
+
23
+ ## [1.0.1](https://github.com/prakashmahendran/backend-test-tools/compare/v1.0.0...v1.0.1) (2025-12-09)
24
+
25
+ ### 🐛 Bug Fixes
26
+
27
+ * update package name to scoped @prakashmahendran/backend-test-tools with public access ([b290250](https://github.com/prakashmahendran/backend-test-tools/commit/b290250300e07a2f576dd0990a024b13ac965d4b))
28
+
29
+ ## 1.0.0 (2025-12-09)
30
+
31
+ ### ✨ Features
32
+
33
+ * modernization and automated versioning ([d12a529](https://github.com/prakashmahendran/backend-test-tools/commit/d12a5293c3b2e3368dc1f0229d462409d1cfadda))
34
+
35
+ ### 👷 CI/CD
36
+
37
+ * allow tests to fail gracefully ([b6f7b2a](https://github.com/prakashmahendran/backend-test-tools/commit/b6f7b2ab932e06648947e877ac277f30dd1d026a))
38
+ * skip tests if not present ([c26a07e](https://github.com/prakashmahendran/backend-test-tools/commit/c26a07e3ed2b96c4b00bbc616a7bcec11323a039))
@@ -6,12 +6,49 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.factory = void 0;
7
7
  var _crypto = require("crypto");
8
8
  var _workers = require("./workers");
9
+ /**
10
+ * Registry of available factory models and their worker functions.
11
+ * Add new models here to extend factory capabilities.
12
+ */
9
13
  const modelsMap = {
10
14
  user: _workers.userFactoryWorker
11
15
  };
16
+
17
+ /**
18
+ * Factory for generating test data objects.
19
+ *
20
+ * Provides a consistent interface for creating mock entities in tests.
21
+ * Inspired by factory-girl pattern for predictable test data generation.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Generate a single user
26
+ * const user = factory.build('user');
27
+ *
28
+ * // Generate with custom attributes
29
+ * const admin = factory.build('user', { role: 'admin' });
30
+ *
31
+ * // Generate multiple users
32
+ * const users = factory.buildMany('user', 5);
33
+ * ```
34
+ */
12
35
  const factory = exports.factory = {
13
36
  /**
14
- * Build an object according to a defined model
37
+ * Build a single object according to a defined model.
38
+ *
39
+ * @template T - The model type to build
40
+ * @param name - The name of the model to build (e.g., 'user')
41
+ * @param attributes - Override specific attributes of the generated object
42
+ * @param buildOptions - Options passed to the worker function for customization
43
+ *
44
+ * @returns A new instance of the specified model with a generated UUID
45
+ *
46
+ * @throws {Error} If the specified model name is not registered
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const user = factory.build('user', { email: 'test@example.com' });
51
+ * ```
15
52
  */
16
53
  build: function (name, attributes = {}, buildOptions = {}) {
17
54
  if (!Object.keys(modelsMap).includes(name)) throw new Error(`Factory: unknown model "${name}"`);
@@ -24,7 +61,23 @@ const factory = exports.factory = {
24
61
  };
25
62
  },
26
63
  /**
27
- * Build multiple objects according to a defined model
64
+ * Build multiple objects according to a defined model.
65
+ *
66
+ * @template T - The model type to build
67
+ * @param name - The name of the model to build (e.g., 'user')
68
+ * @param count - The number of instances to generate
69
+ * @param attributes - Override specific attributes for all generated objects
70
+ * @param buildOptions - Options passed to the worker function for customization
71
+ *
72
+ * @returns An array of new instances of the specified model
73
+ *
74
+ * @throws {Error} If the specified model name is not registered
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const users = factory.buildMany('user', 10);
79
+ * const admins = factory.buildMany('user', 3, { role: 'admin' });
80
+ * ```
28
81
  */
29
82
  buildMany: function (name, count, attributes = {}, buildOptions = {}) {
30
83
  const instances = [];
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","names":["_crypto","require","_workers","modelsMap","user","userFactoryWorker","factory","exports","build","name","attributes","buildOptions","Object","keys","includes","Error","worker","instance","id","randomUUID","buildMany","count","instances","i","push"],"sources":["../../src/factory/factory.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport {\n FactoryModel,\n FactoryBuildOptions,\n FactoryModelOverride,\n FactoryReturnType,\n ModelsMap\n} from './factory.types';\nimport { userFactoryWorker } from './workers';\n\nconst modelsMap: ModelsMap = {\n user: userFactoryWorker\n};\n\nexport const factory = {\n /**\n * Build an object according to a defined model\n */\n build: function <T extends FactoryModel>(\n name: T,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {}\n ): FactoryReturnType<T> {\n if (!Object.keys(modelsMap).includes(name)) throw new Error(`Factory: unknown model \"${name}\"`);\n const worker = modelsMap[name];\n const instance = worker(buildOptions);\n return {\n id: randomUUID(),\n ...instance,\n ...attributes\n };\n },\n\n /**\n * Build multiple objects according to a defined model\n */\n buildMany: function <T extends FactoryModel>(\n name: T,\n count: number,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {}\n ): Array<FactoryReturnType<T>> {\n const instances: Array<FactoryReturnType<T>> = [];\n for (let i = 0; i < count; i++) {\n instances.push(this.build(name, attributes, buildOptions));\n }\n return instances;\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,MAAME,SAAoB,GAAG;EAC3BC,IAAI,EAAEC;AACR,CAAC;AAEM,MAAMC,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACrB;AACF;AACA;EACEE,KAAK,EAAE,SAAAA,CACLC,IAAO,EACPC,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACnB;IACtB,IAAI,CAACC,MAAM,CAACC,IAAI,CAACV,SAAS,CAAC,CAACW,QAAQ,CAACL,IAAI,CAAC,EAAE,MAAM,IAAIM,KAAK,CAAC,2BAA2BN,IAAI,GAAG,CAAC;IAC/F,MAAMO,MAAM,GAAGb,SAAS,CAACM,IAAI,CAAC;IAC9B,MAAMQ,QAAQ,GAAGD,MAAM,CAACL,YAAY,CAAC;IACrC,OAAO;MACLO,EAAE,EAAE,IAAAC,kBAAU,EAAC,CAAC;MAChB,GAAGF,QAAQ;MACX,GAAGP;IACL,CAAC;EACH,CAAC;EAED;AACF;AACA;EACEU,SAAS,EAAE,SAAAA,CACTX,IAAO,EACPY,KAAa,EACbX,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACZ;IAC7B,MAAMW,SAAsC,GAAG,EAAE;IACjD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,KAAK,EAAEE,CAAC,EAAE,EAAE;MAC9BD,SAAS,CAACE,IAAI,CAAC,IAAI,CAAChB,KAAK,CAACC,IAAI,EAAEC,UAAU,EAAEC,YAAY,CAAC,CAAC;IAC5D;IACA,OAAOW,SAAS;EAClB;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"factory.js","names":["_crypto","require","_workers","modelsMap","user","userFactoryWorker","factory","exports","build","name","attributes","buildOptions","Object","keys","includes","Error","worker","instance","id","randomUUID","buildMany","count","instances","i","push"],"sources":["../../src/factory/factory.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport {\n FactoryModel,\n FactoryBuildOptions,\n FactoryModelOverride,\n FactoryReturnType,\n ModelsMap\n} from './factory.types';\nimport { userFactoryWorker } from './workers';\n\n/**\n * Registry of available factory models and their worker functions.\n * Add new models here to extend factory capabilities.\n */\nconst modelsMap: ModelsMap = {\n user: userFactoryWorker\n};\n\n/**\n * Factory for generating test data objects.\n * \n * Provides a consistent interface for creating mock entities in tests.\n * Inspired by factory-girl pattern for predictable test data generation.\n * \n * @example\n * ```typescript\n * // Generate a single user\n * const user = factory.build('user');\n * \n * // Generate with custom attributes\n * const admin = factory.build('user', { role: 'admin' });\n * \n * // Generate multiple users\n * const users = factory.buildMany('user', 5);\n * ```\n */\nexport const factory = {\n /**\n * Build a single object according to a defined model.\n * \n * @template T - The model type to build\n * @param name - The name of the model to build (e.g., 'user')\n * @param attributes - Override specific attributes of the generated object\n * @param buildOptions - Options passed to the worker function for customization\n * \n * @returns A new instance of the specified model with a generated UUID\n * \n * @throws {Error} If the specified model name is not registered\n * \n * @example\n * ```typescript\n * const user = factory.build('user', { email: 'test@example.com' });\n * ```\n */\n build: function <T extends FactoryModel>(\n name: T,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {}\n ): FactoryReturnType<T> {\n if (!Object.keys(modelsMap).includes(name)) throw new Error(`Factory: unknown model \"${name}\"`);\n const worker = modelsMap[name];\n const instance = worker(buildOptions);\n return {\n id: randomUUID(),\n ...instance,\n ...attributes\n };\n },\n\n /**\n * Build multiple objects according to a defined model.\n * \n * @template T - The model type to build\n * @param name - The name of the model to build (e.g., 'user')\n * @param count - The number of instances to generate\n * @param attributes - Override specific attributes for all generated objects\n * @param buildOptions - Options passed to the worker function for customization\n * \n * @returns An array of new instances of the specified model\n * \n * @throws {Error} If the specified model name is not registered\n * \n * @example\n * ```typescript\n * const users = factory.buildMany('user', 10);\n * const admins = factory.buildMany('user', 3, { role: 'admin' });\n * ```\n */\n buildMany: function <T extends FactoryModel>(\n name: T,\n count: number,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {}\n ): Array<FactoryReturnType<T>> {\n const instances: Array<FactoryReturnType<T>> = [];\n for (let i = 0; i < count; i++) {\n instances.push(this.build(name, attributes, buildOptions));\n }\n return instances;\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA,MAAME,SAAoB,GAAG;EAC3BC,IAAI,EAAEC;AACR,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACrB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,KAAK,EAAE,SAAAA,CACLC,IAAO,EACPC,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACnB;IACtB,IAAI,CAACC,MAAM,CAACC,IAAI,CAACV,SAAS,CAAC,CAACW,QAAQ,CAACL,IAAI,CAAC,EAAE,MAAM,IAAIM,KAAK,CAAC,2BAA2BN,IAAI,GAAG,CAAC;IAC/F,MAAMO,MAAM,GAAGb,SAAS,CAACM,IAAI,CAAC;IAC9B,MAAMQ,QAAQ,GAAGD,MAAM,CAACL,YAAY,CAAC;IACrC,OAAO;MACLO,EAAE,EAAE,IAAAC,kBAAU,EAAC,CAAC;MAChB,GAAGF,QAAQ;MACX,GAAGP;IACL,CAAC;EACH,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEU,SAAS,EAAE,SAAAA,CACTX,IAAO,EACPY,KAAa,EACbX,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACZ;IAC7B,MAAMW,SAAsC,GAAG,EAAE;IACjD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,KAAK,EAAEE,CAAC,EAAE,EAAE;MAC9BD,SAAS,CAACE,IAAI,CAAC,IAAI,CAAChB,KAAK,CAACC,IAAI,EAAEC,UAAU,EAAEC,YAAY,CAAC,CAAC;IAC5D;IACA,OAAOW,SAAS;EAClB;AACF,CAAC","ignoreList":[]}
@@ -6,7 +6,29 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.generateAccessToken = generateAccessToken;
7
7
  var _crypto = require("crypto");
8
8
  var _jsonwebtoken = require("jsonwebtoken");
9
- /** Returns an API access token valid in test environment */
9
+ /**
10
+ * Generates a mock JWT access token for testing purposes.
11
+ *
12
+ * This token is self-signed and only valid in test environments. It simulates
13
+ * tokens that would typically be issued by an authentication service like Auth0.
14
+ *
15
+ * @param userId - The user ID to include in the token subject. If not provided, a random UUID will be generated.
16
+ * @param options - Additional JWT signing options (expiresIn, audience, issuer, etc.)
17
+ * @param payload - Additional payload data to include in the token
18
+ *
19
+ * @returns A signed JWT token string
20
+ *
21
+ * @throws {Error} If JWT_SECRET environment variable is not set
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const token = generateAccessToken('user-123');
26
+ * const tokenWithCustomPayload = generateAccessToken('user-456', {}, { role: 'admin' });
27
+ * const shortLivedToken = generateAccessToken('user-789', { expiresIn: '1h' });
28
+ * ```
29
+ *
30
+ * @see {@link https://github.com/auth0/node-jsonwebtoken jsonwebtoken package} for available options
31
+ */
10
32
  function generateAccessToken(userId, options = {}, payload = {}) {
11
33
  const id = userId ?? (0, _crypto.randomUUID)();
12
34
  if (!process.env.JWT_SECRET) throw new Error('Missing JWT signing secret');
@@ -1 +1 @@
1
- {"version":3,"file":"generateAccessToken.js","names":["_crypto","require","_jsonwebtoken","generateAccessToken","userId","options","payload","id","randomUUID","process","env","JWT_SECRET","Error","sign","user","expiresIn","audience","ACCESS_TOKEN_AUDIENCE","issuer","ACCESS_TOKEN_ISSUER","subject","jwtid"],"sources":["../../src/generators/generateAccessToken.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport { sign, SignOptions } from 'jsonwebtoken';\n\n/** Returns an API access token valid in test environment */\nexport function generateAccessToken(\n userId: string,\n options: SignOptions = {},\n payload: string | Buffer | object = {}\n): string {\n const id = userId ?? randomUUID();\n if (!process.env.JWT_SECRET) throw new Error('Missing JWT signing secret');\n return sign(\n typeof payload === 'object' ? { ...payload, user: { id } } : payload,\n process.env.JWT_SECRET,\n {\n expiresIn: '1d',\n audience: process.env.ACCESS_TOKEN_AUDIENCE,\n issuer: process.env.ACCESS_TOKEN_ISSUER,\n subject: id,\n jwtid: randomUUID(),\n ...options\n }\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACO,SAASE,mBAAmBA,CACjCC,MAAc,EACdC,OAAoB,GAAG,CAAC,CAAC,EACzBC,OAAiC,GAAG,CAAC,CAAC,EAC9B;EACR,MAAMC,EAAE,GAAGH,MAAM,IAAI,IAAAI,kBAAU,EAAC,CAAC;EACjC,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,UAAU,EAAE,MAAM,IAAIC,KAAK,CAAC,4BAA4B,CAAC;EAC1E,OAAO,IAAAC,kBAAI,EACT,OAAOP,OAAO,KAAK,QAAQ,GAAG;IAAE,GAAGA,OAAO;IAAEQ,IAAI,EAAE;MAAEP;IAAG;EAAE,CAAC,GAAGD,OAAO,EACpEG,OAAO,CAACC,GAAG,CAACC,UAAU,EACtB;IACEI,SAAS,EAAE,IAAI;IACfC,QAAQ,EAAEP,OAAO,CAACC,GAAG,CAACO,qBAAqB;IAC3CC,MAAM,EAAET,OAAO,CAACC,GAAG,CAACS,mBAAmB;IACvCC,OAAO,EAAEb,EAAE;IACXc,KAAK,EAAE,IAAAb,kBAAU,EAAC,CAAC;IACnB,GAAGH;EACL,CACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"generateAccessToken.js","names":["_crypto","require","_jsonwebtoken","generateAccessToken","userId","options","payload","id","randomUUID","process","env","JWT_SECRET","Error","sign","user","expiresIn","audience","ACCESS_TOKEN_AUDIENCE","issuer","ACCESS_TOKEN_ISSUER","subject","jwtid"],"sources":["../../src/generators/generateAccessToken.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport { sign, SignOptions } from 'jsonwebtoken';\n\n/**\n * Generates a mock JWT access token for testing purposes.\n * \n * This token is self-signed and only valid in test environments. It simulates\n * tokens that would typically be issued by an authentication service like Auth0.\n * \n * @param userId - The user ID to include in the token subject. If not provided, a random UUID will be generated.\n * @param options - Additional JWT signing options (expiresIn, audience, issuer, etc.)\n * @param payload - Additional payload data to include in the token\n * \n * @returns A signed JWT token string\n * \n * @throws {Error} If JWT_SECRET environment variable is not set\n * \n * @example\n * ```typescript\n * const token = generateAccessToken('user-123');\n * const tokenWithCustomPayload = generateAccessToken('user-456', {}, { role: 'admin' });\n * const shortLivedToken = generateAccessToken('user-789', { expiresIn: '1h' });\n * ```\n * \n * @see {@link https://github.com/auth0/node-jsonwebtoken jsonwebtoken package} for available options\n */\nexport function generateAccessToken(\n userId: string,\n options: SignOptions = {},\n payload: string | Buffer | object = {}\n): string {\n const id = userId ?? randomUUID();\n if (!process.env.JWT_SECRET) throw new Error('Missing JWT signing secret');\n return sign(\n typeof payload === 'object' ? { ...payload, user: { id } } : payload,\n process.env.JWT_SECRET,\n {\n expiresIn: '1d',\n audience: process.env.ACCESS_TOKEN_AUDIENCE,\n issuer: process.env.ACCESS_TOKEN_ISSUER,\n subject: id,\n jwtid: randomUUID(),\n ...options\n }\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,mBAAmBA,CACjCC,MAAc,EACdC,OAAoB,GAAG,CAAC,CAAC,EACzBC,OAAiC,GAAG,CAAC,CAAC,EAC9B;EACR,MAAMC,EAAE,GAAGH,MAAM,IAAI,IAAAI,kBAAU,EAAC,CAAC;EACjC,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,UAAU,EAAE,MAAM,IAAIC,KAAK,CAAC,4BAA4B,CAAC;EAC1E,OAAO,IAAAC,kBAAI,EACT,OAAOP,OAAO,KAAK,QAAQ,GAAG;IAAE,GAAGA,OAAO;IAAEQ,IAAI,EAAE;MAAEP;IAAG;EAAE,CAAC,GAAGD,OAAO,EACpEG,OAAO,CAACC,GAAG,CAACC,UAAU,EACtB;IACEI,SAAS,EAAE,IAAI;IACfC,QAAQ,EAAEP,OAAO,CAACC,GAAG,CAACO,qBAAqB;IAC3CC,MAAM,EAAET,OAAO,CAACC,GAAG,CAACS,mBAAmB;IACvCC,OAAO,EAAEb,EAAE;IACXc,KAAK,EAAE,IAAAb,kBAAU,EAAC,CAAC;IACnB,GAAGH;EACL,CACF,CAAC;AACH","ignoreList":[]}
@@ -5,10 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.TEST_LOCALES = void 0;
7
7
  exports.generateLocale = generateLocale;
8
+ /**
9
+ * List of supported locales for testing purposes.
10
+ * Includes major languages and regional variants.
11
+ */
8
12
  const TEST_LOCALES = exports.TEST_LOCALES = ['ar', 'en-US', 'es-ES', 'fr-FR', 'id-ID', 'it-IT', 'ja-JP', 'km-KH', 'ko-KR', 'ms-MY', 'my-MM', 'nl-NL', 'pt-PT', 'ry-RU', 'th-TH', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'];
9
13
 
10
14
  /**
11
- * Pick up a random locale from the list of testable ones
15
+ * Generates a random locale from the list of supported test locales.
16
+ *
17
+ * Useful for testing internationalization (i18n) features and ensuring
18
+ * your application handles different locales correctly.
19
+ *
20
+ * @returns A randomly selected locale code (e.g., 'en-US', 'fr-FR')
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const locale = generateLocale();
25
+ * console.log(locale); // e.g., 'ja-JP'
26
+ * ```
12
27
  */
13
28
  function generateLocale() {
14
29
  return TEST_LOCALES[Math.floor(Math.random() * TEST_LOCALES.length)];
@@ -1 +1 @@
1
- {"version":3,"file":"generateLocale.js","names":["TEST_LOCALES","exports","generateLocale","Math","floor","random","length"],"sources":["../../src/generators/generateLocale.ts"],"sourcesContent":["export const TEST_LOCALES = [\n 'ar',\n 'en-US',\n 'es-ES',\n 'fr-FR',\n 'id-ID',\n 'it-IT',\n 'ja-JP',\n 'km-KH',\n 'ko-KR',\n 'ms-MY',\n 'my-MM',\n 'nl-NL',\n 'pt-PT',\n 'ry-RU',\n 'th-TH',\n 'uk-UA',\n 'vi-VN',\n 'zh-CN',\n 'zh-TW',\n];\n\n/**\n * Pick up a random locale from the list of testable ones\n */\nexport function generateLocale(): string {\n return TEST_LOCALES[Math.floor(Math.random() * TEST_LOCALES.length)];\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,CAC1B,IAAI,EACJ,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,CACR;;AAED;AACA;AACA;AACO,SAASE,cAAcA,CAAA,EAAW;EACvC,OAAOF,YAAY,CAACG,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGL,YAAY,CAACM,MAAM,CAAC,CAAC;AACtE","ignoreList":[]}
1
+ {"version":3,"file":"generateLocale.js","names":["TEST_LOCALES","exports","generateLocale","Math","floor","random","length"],"sources":["../../src/generators/generateLocale.ts"],"sourcesContent":["/**\n * List of supported locales for testing purposes.\n * Includes major languages and regional variants.\n */\nexport const TEST_LOCALES = [\n 'ar',\n 'en-US',\n 'es-ES',\n 'fr-FR',\n 'id-ID',\n 'it-IT',\n 'ja-JP',\n 'km-KH',\n 'ko-KR',\n 'ms-MY',\n 'my-MM',\n 'nl-NL',\n 'pt-PT',\n 'ry-RU',\n 'th-TH',\n 'uk-UA',\n 'vi-VN',\n 'zh-CN',\n 'zh-TW',\n] as const;\n\n/**\n * Generates a random locale from the list of supported test locales.\n * \n * Useful for testing internationalization (i18n) features and ensuring\n * your application handles different locales correctly.\n * \n * @returns A randomly selected locale code (e.g., 'en-US', 'fr-FR')\n * \n * @example\n * ```typescript\n * const locale = generateLocale();\n * console.log(locale); // e.g., 'ja-JP'\n * ```\n */\nexport function generateLocale(): string {\n return TEST_LOCALES[Math.floor(Math.random() * TEST_LOCALES.length)];\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,CAC1B,IAAI,EACJ,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,CACC;;AAEV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAAA,EAAW;EACvC,OAAOF,YAAY,CAACG,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGL,YAAY,CAACM,MAAM,CAAC,CAAC;AACtE","ignoreList":[]}
@@ -9,23 +9,54 @@ exports.generateSignKeyEncrypted = generateSignKeyEncrypted;
9
9
  exports.generateSignKeyPub = generateSignKeyPub;
10
10
  var _crypto = _interopRequireDefault(require("crypto"));
11
11
  /**
12
- * Generates a fake base64 string that looks like a user public key
13
- * /!\ This is not a valid crypto key
12
+ * Generates a fake base64 string that resembles a user public key.
13
+ *
14
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
15
+ * This function is only for testing purposes to generate mock data.
16
+ *
17
+ * @returns A base64-encoded random string (162 bytes)
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const mockPublicKey = generateSignKeyPub();
22
+ * // Use in tests where you need a public key format
23
+ * ```
14
24
  */
15
25
  function generateSignKeyPub() {
16
26
  return _crypto.default.randomBytes(162).toString('base64');
17
27
  }
28
+
18
29
  /**
19
- * Generates a fake base64 string that looks like a user encrypted private key
20
- * /!\ This is not a valid crypto key
30
+ * Generates a fake base64 string that resembles a user encrypted private key.
31
+ *
32
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
33
+ * This function is only for testing purposes to generate mock data.
34
+ *
35
+ * @returns A base64-encoded random string (640 bytes)
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const mockPrivateKey = generateSignKeyEncrypted();
40
+ * // Use in tests where you need an encrypted private key format
41
+ * ```
21
42
  */
22
43
  function generateSignKeyEncrypted() {
23
44
  return _crypto.default.randomBytes(640).toString('base64');
24
45
  }
25
46
 
26
47
  /**
27
- * Generates a fake base64 string that looks like a user encrypted Blackberry Passcode
28
- * /!\ This is not a valid crypto key
48
+ * Generates a fake base64 string that resembles an encrypted BlackBerry passcode.
49
+ *
50
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
51
+ * This function is only for testing purposes to generate mock data.
52
+ *
53
+ * @returns A base64-encoded random string (80 bytes)
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const mockPasscode = generateBbEncrypted();
58
+ * // Use in tests where you need a BlackBerry passcode format
59
+ * ```
29
60
  */
30
61
  function generateBbEncrypted() {
31
62
  return _crypto.default.randomBytes(80).toString('base64');
@@ -1 +1 @@
1
- {"version":3,"file":"generateUserCrypto.js","names":["_crypto","_interopRequireDefault","require","generateSignKeyPub","crypto","randomBytes","toString","generateSignKeyEncrypted","generateBbEncrypted"],"sources":["../../src/generators/generateUserCrypto.ts"],"sourcesContent":["import crypto from 'crypto';\n\n/**\n * Generates a fake base64 string that looks like a user public key\n * /!\\ This is not a valid crypto key\n */\nexport function generateSignKeyPub(): string {\n return crypto.randomBytes(162).toString('base64');\n}\n/**\n * Generates a fake base64 string that looks like a user encrypted private key\n * /!\\ This is not a valid crypto key\n */\nexport function generateSignKeyEncrypted(): string {\n return crypto.randomBytes(640).toString('base64');\n}\n\n/**\n * Generates a fake base64 string that looks like a user encrypted Blackberry Passcode\n * /!\\ This is not a valid crypto key\n */\nexport function generateBbEncrypted(): string {\n return crypto.randomBytes(80).toString('base64');\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAA,EAAW;EAC3C,OAAOC,eAAM,CAACC,WAAW,CAAC,GAAG,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AACnD;AACA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,CAAA,EAAW;EACjD,OAAOH,eAAM,CAACC,WAAW,CAAC,GAAG,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACO,SAASE,mBAAmBA,CAAA,EAAW;EAC5C,OAAOJ,eAAM,CAACC,WAAW,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AAClD","ignoreList":[]}
1
+ {"version":3,"file":"generateUserCrypto.js","names":["_crypto","_interopRequireDefault","require","generateSignKeyPub","crypto","randomBytes","toString","generateSignKeyEncrypted","generateBbEncrypted"],"sources":["../../src/generators/generateUserCrypto.ts"],"sourcesContent":["import crypto from 'crypto';\n\n/**\n * Generates a fake base64 string that resembles a user public key.\n * \n * ⚠️ **WARNING**: This is NOT a valid cryptographic key. \n * This function is only for testing purposes to generate mock data.\n * \n * @returns A base64-encoded random string (162 bytes)\n * \n * @example\n * ```typescript\n * const mockPublicKey = generateSignKeyPub();\n * // Use in tests where you need a public key format\n * ```\n */\nexport function generateSignKeyPub(): string {\n return crypto.randomBytes(162).toString('base64');\n}\n\n/**\n * Generates a fake base64 string that resembles a user encrypted private key.\n * \n * ⚠️ **WARNING**: This is NOT a valid cryptographic key.\n * This function is only for testing purposes to generate mock data.\n * \n * @returns A base64-encoded random string (640 bytes)\n * \n * @example\n * ```typescript\n * const mockPrivateKey = generateSignKeyEncrypted();\n * // Use in tests where you need an encrypted private key format\n * ```\n */\nexport function generateSignKeyEncrypted(): string {\n return crypto.randomBytes(640).toString('base64');\n}\n\n/**\n * Generates a fake base64 string that resembles an encrypted BlackBerry passcode.\n * \n * ⚠️ **WARNING**: This is NOT a valid cryptographic key.\n * This function is only for testing purposes to generate mock data.\n * \n * @returns A base64-encoded random string (80 bytes)\n * \n * @example\n * ```typescript\n * const mockPasscode = generateBbEncrypted();\n * // Use in tests where you need a BlackBerry passcode format\n * ```\n */\nexport function generateBbEncrypted(): string {\n return crypto.randomBytes(80).toString('base64');\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAA,EAAW;EAC3C,OAAOC,eAAM,CAACC,WAAW,CAAC,GAAG,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,CAAA,EAAW;EACjD,OAAOH,eAAM,CAACC,WAAW,CAAC,GAAG,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,mBAAmBA,CAAA,EAAW;EAC5C,OAAOJ,eAAM,CAACC,WAAW,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;AAClD","ignoreList":[]}
@@ -0,0 +1,59 @@
1
+ import { FactoryModel, FactoryBuildOptions, FactoryModelOverride, FactoryReturnType } from './factory.types';
2
+ /**
3
+ * Factory for generating test data objects.
4
+ *
5
+ * Provides a consistent interface for creating mock entities in tests.
6
+ * Inspired by factory-girl pattern for predictable test data generation.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Generate a single user
11
+ * const user = factory.build('user');
12
+ *
13
+ * // Generate with custom attributes
14
+ * const admin = factory.build('user', { role: 'admin' });
15
+ *
16
+ * // Generate multiple users
17
+ * const users = factory.buildMany('user', 5);
18
+ * ```
19
+ */
20
+ export declare const factory: {
21
+ /**
22
+ * Build a single object according to a defined model.
23
+ *
24
+ * @template T - The model type to build
25
+ * @param name - The name of the model to build (e.g., 'user')
26
+ * @param attributes - Override specific attributes of the generated object
27
+ * @param buildOptions - Options passed to the worker function for customization
28
+ *
29
+ * @returns A new instance of the specified model with a generated UUID
30
+ *
31
+ * @throws {Error} If the specified model name is not registered
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const user = factory.build('user', { email: 'test@example.com' });
36
+ * ```
37
+ */
38
+ build: <T extends FactoryModel>(name: T, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => FactoryReturnType<T>;
39
+ /**
40
+ * Build multiple objects according to a defined model.
41
+ *
42
+ * @template T - The model type to build
43
+ * @param name - The name of the model to build (e.g., 'user')
44
+ * @param count - The number of instances to generate
45
+ * @param attributes - Override specific attributes for all generated objects
46
+ * @param buildOptions - Options passed to the worker function for customization
47
+ *
48
+ * @returns An array of new instances of the specified model
49
+ *
50
+ * @throws {Error} If the specified model name is not registered
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const users = factory.buildMany('user', 10);
55
+ * const admins = factory.buildMany('user', 3, { role: 'admin' });
56
+ * ```
57
+ */
58
+ buildMany: <T extends FactoryModel>(name: T, count: number, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => Array<FactoryReturnType<T>>;
59
+ };
@@ -0,0 +1,25 @@
1
+ import { SignOptions } from 'jsonwebtoken';
2
+ /**
3
+ * Generates a mock JWT access token for testing purposes.
4
+ *
5
+ * This token is self-signed and only valid in test environments. It simulates
6
+ * tokens that would typically be issued by an authentication service like Auth0.
7
+ *
8
+ * @param userId - The user ID to include in the token subject. If not provided, a random UUID will be generated.
9
+ * @param options - Additional JWT signing options (expiresIn, audience, issuer, etc.)
10
+ * @param payload - Additional payload data to include in the token
11
+ *
12
+ * @returns A signed JWT token string
13
+ *
14
+ * @throws {Error} If JWT_SECRET environment variable is not set
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const token = generateAccessToken('user-123');
19
+ * const tokenWithCustomPayload = generateAccessToken('user-456', {}, { role: 'admin' });
20
+ * const shortLivedToken = generateAccessToken('user-789', { expiresIn: '1h' });
21
+ * ```
22
+ *
23
+ * @see {@link https://github.com/auth0/node-jsonwebtoken jsonwebtoken package} for available options
24
+ */
25
+ export declare function generateAccessToken(userId: string, options?: SignOptions, payload?: string | Buffer | object): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * List of supported locales for testing purposes.
3
+ * Includes major languages and regional variants.
4
+ */
5
+ export declare const TEST_LOCALES: readonly ["ar", "en-US", "es-ES", "fr-FR", "id-ID", "it-IT", "ja-JP", "km-KH", "ko-KR", "ms-MY", "my-MM", "nl-NL", "pt-PT", "ry-RU", "th-TH", "uk-UA", "vi-VN", "zh-CN", "zh-TW"];
6
+ /**
7
+ * Generates a random locale from the list of supported test locales.
8
+ *
9
+ * Useful for testing internationalization (i18n) features and ensuring
10
+ * your application handles different locales correctly.
11
+ *
12
+ * @returns A randomly selected locale code (e.g., 'en-US', 'fr-FR')
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const locale = generateLocale();
17
+ * console.log(locale); // e.g., 'ja-JP'
18
+ * ```
19
+ */
20
+ export declare function generateLocale(): string;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Generates a fake base64 string that resembles a user public key.
3
+ *
4
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
5
+ * This function is only for testing purposes to generate mock data.
6
+ *
7
+ * @returns A base64-encoded random string (162 bytes)
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const mockPublicKey = generateSignKeyPub();
12
+ * // Use in tests where you need a public key format
13
+ * ```
14
+ */
15
+ export declare function generateSignKeyPub(): string;
16
+ /**
17
+ * Generates a fake base64 string that resembles a user encrypted private key.
18
+ *
19
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
20
+ * This function is only for testing purposes to generate mock data.
21
+ *
22
+ * @returns A base64-encoded random string (640 bytes)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const mockPrivateKey = generateSignKeyEncrypted();
27
+ * // Use in tests where you need an encrypted private key format
28
+ * ```
29
+ */
30
+ export declare function generateSignKeyEncrypted(): string;
31
+ /**
32
+ * Generates a fake base64 string that resembles an encrypted BlackBerry passcode.
33
+ *
34
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
35
+ * This function is only for testing purposes to generate mock data.
36
+ *
37
+ * @returns A base64-encoded random string (80 bytes)
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const mockPasscode = generateBbEncrypted();
42
+ * // Use in tests where you need a BlackBerry passcode format
43
+ * ```
44
+ */
45
+ export declare function generateBbEncrypted(): string;
@@ -6,14 +6,14 @@ export interface generateCertsOptions {
6
6
  /** Certificate issue information */
7
7
  issuer?: Array<pki.CertificateField>;
8
8
  /** Private key to use to sign the certificate */
9
- key?: pki.PrivateKey;
9
+ key?: pki.rsa.PrivateKey;
10
10
  }
11
11
  /** Fake certificate generated */
12
12
  export interface GeneratedCertificate {
13
13
  /** PEM certificate */
14
14
  cert: string;
15
15
  /** Private key to use with the certificate */
16
- privateKey: pki.PrivateKey;
16
+ privateKey: pki.rsa.PrivateKey;
17
17
  /** PEM encoding of the private key */
18
18
  privateKeyPem: string;
19
19
  }
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.stubSendPush = stubSendPush;
7
7
  var sendPush = _interopRequireWildcard(require("node-server-engine/dist/utils/sendPush/sendPush"));
8
8
  var _sinon = require("sinon");
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
10
  /** Stub the sendPush function */
12
11
  function stubSendPush() {
13
12
  return (0, _sinon.stub)(sendPush, 'sendPush').resolves();
@@ -1 +1 @@
1
- {"version":3,"file":"sendPush.js","names":["sendPush","_interopRequireWildcard","require","_sinon","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","stubSendPush","stub","resolves"],"sources":["../../../src/stubs/server-engine/sendPush.ts"],"sourcesContent":["import * as sendPush from 'node-server-engine/dist/utils/sendPush/sendPush';\nimport {SinonStub, stub} from 'sinon';\n\n/** Stub the sendPush function */\nexport function stubSendPush(): SinonStub {\n return stub(sendPush, 'sendPush').resolves();\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAsC,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAEtC;AACO,SAASW,YAAYA,CAAA,EAAc;EACxC,OAAO,IAAAC,WAAI,EAACzB,QAAQ,EAAE,UAAU,CAAC,CAAC0B,QAAQ,CAAC,CAAC;AAC9C","ignoreList":[]}
1
+ {"version":3,"file":"sendPush.js","names":["sendPush","_interopRequireWildcard","require","_sinon","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","stubSendPush","stub","resolves"],"sources":["../../../src/stubs/server-engine/sendPush.ts"],"sourcesContent":["import * as sendPush from 'node-server-engine/dist/utils/sendPush/sendPush';\nimport {SinonStub, stub} from 'sinon';\n\n/** Stub the sendPush function */\nexport function stubSendPush(): SinonStub {\n return stub(sendPush, 'sendPush').resolves();\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAsC,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAEtC;AACO,SAASkB,YAAYA,CAAA,EAAc;EACxC,OAAO,IAAAC,WAAI,EAACxB,QAAQ,EAAE,UAAU,CAAC,CAACyB,QAAQ,CAAC,CAAC;AAC9C","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"generateCerts.types.js","names":[],"sources":["../../../src/utils/generateCerts/generateCerts.types.ts"],"sourcesContent":["import {pki} from 'node-forge';\n\n/** Options ot generate fake certificates */\nexport interface generateCertsOptions {\n /** Indicates that we should generate a CA certificate */\n ca?: boolean;\n /** Certificate issue information */\n issuer?: Array<pki.CertificateField>;\n /** Private key to use to sign the certificate */\n key?: pki.PrivateKey;\n}\n\n/** Fake certificate generated */\nexport interface GeneratedCertificate {\n /** PEM certificate */\n cert: string;\n /** Private key to use with the certificate */\n privateKey: pki.PrivateKey;\n /** PEM encoding of the private key */\n privateKeyPem: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"generateCerts.types.js","names":[],"sources":["../../../src/utils/generateCerts/generateCerts.types.ts"],"sourcesContent":["import {pki} from 'node-forge';\n\n/** Options ot generate fake certificates */\nexport interface generateCertsOptions {\n /** Indicates that we should generate a CA certificate */\n ca?: boolean;\n /** Certificate issue information */\n issuer?: Array<pki.CertificateField>;\n /** Private key to use to sign the certificate */\n key?: pki.rsa.PrivateKey;\n}\n\n/** Fake certificate generated */\nexport interface GeneratedCertificate {\n /** PEM certificate */\n cert: string;\n /** Private key to use with the certificate */\n privateKey: pki.rsa.PrivateKey;\n /** PEM encoding of the private key */\n privateKeyPem: string;\n}\n"],"mappings":"","ignoreList":[]}
package/eslint.config.mjs CHANGED
@@ -3,9 +3,26 @@ import pluginJs from '@eslint/js';
3
3
  import tseslint from 'typescript-eslint';
4
4
 
5
5
  export default [
6
- { files: ['.src/', '**/*.{js,mjs,cjs,ts}'] },
7
- { languageOptions: { globals: { ...globals.browser, ...globals.node } } },
6
+ { files: ['src/**/*.{js,mjs,cjs,ts}', 'test/**/*.{js,mjs,cjs,ts}'] },
7
+ {
8
+ languageOptions: {
9
+ globals: { ...globals.node },
10
+ parserOptions: {
11
+ ecmaVersion: 2023,
12
+ sourceType: 'module'
13
+ }
14
+ }
15
+ },
8
16
  pluginJs.configs.recommended,
9
- { ignores: ['**/*.test.ts', '**/*.d.ts'] },
10
- ...tseslint.configs.recommended
17
+ { ignores: ['**/*.test.ts', '**/*.d.ts', 'dist/**', 'node_modules/**'] },
18
+ ...tseslint.configs.recommended,
19
+ {
20
+ rules: {
21
+ '@typescript-eslint/no-explicit-any': 'warn',
22
+ '@typescript-eslint/no-unused-vars': ['error', {
23
+ 'argsIgnorePattern': '^_',
24
+ 'varsIgnorePattern': '^_'
25
+ }]
26
+ }
27
+ }
11
28
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "backend-test-tools",
3
- "version": "1.0.7",
4
- "description": "Node test tools",
3
+ "version": "1.1.2",
4
+ "description": "Backend Node test tools",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "lint": "eslint ./src",
@@ -28,8 +28,12 @@
28
28
  "@babel/preset-env": "^7.26.0",
29
29
  "@babel/preset-typescript": "^7.26.0",
30
30
  "@babel/register": "^7.25.9",
31
+ "@commitlint/cli": "^19.8.1",
32
+ "@commitlint/config-conventional": "^19.8.1",
31
33
  "@eslint/js": "^9.17.0",
32
34
  "@faker-js/faker": "^9.3.0",
35
+ "@semantic-release/changelog": "^6.0.3",
36
+ "@semantic-release/git": "^10.0.1",
33
37
  "@types/chai": "^5.0.1",
34
38
  "@types/jsonwebtoken": "^9.0.7",
35
39
  "@types/mocha": "^10.0.10",
@@ -43,6 +47,7 @@
43
47
  "babel-plugin-istanbul": "^7.0.0",
44
48
  "babel-plugin-module-resolver": "^5.0.2",
45
49
  "babel-plugin-tsconfig-paths": "^1.0.3",
50
+ "conventional-changelog-conventionalcommits": "^8.0.0",
46
51
  "core-js": "^3.39.0",
47
52
  "eslint": "^9.17.0",
48
53
  "globals": "^15.14.0",
@@ -52,6 +57,7 @@
52
57
  "nyc": "^17.1.0",
53
58
  "prettier": "^3.4.2",
54
59
  "rimraf": "^6.0.1",
60
+ "semantic-release": "^25.0.2",
55
61
  "ts-node": "^10.9.2",
56
62
  "tsc-alias": "^1.8.10",
57
63
  "tsconfig-paths": "^4.2.0",
@@ -8,13 +8,49 @@ import {
8
8
  } from './factory.types';
9
9
  import { userFactoryWorker } from './workers';
10
10
 
11
+ /**
12
+ * Registry of available factory models and their worker functions.
13
+ * Add new models here to extend factory capabilities.
14
+ */
11
15
  const modelsMap: ModelsMap = {
12
16
  user: userFactoryWorker
13
17
  };
14
18
 
19
+ /**
20
+ * Factory for generating test data objects.
21
+ *
22
+ * Provides a consistent interface for creating mock entities in tests.
23
+ * Inspired by factory-girl pattern for predictable test data generation.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Generate a single user
28
+ * const user = factory.build('user');
29
+ *
30
+ * // Generate with custom attributes
31
+ * const admin = factory.build('user', { role: 'admin' });
32
+ *
33
+ * // Generate multiple users
34
+ * const users = factory.buildMany('user', 5);
35
+ * ```
36
+ */
15
37
  export const factory = {
16
38
  /**
17
- * Build an object according to a defined model
39
+ * Build a single object according to a defined model.
40
+ *
41
+ * @template T - The model type to build
42
+ * @param name - The name of the model to build (e.g., 'user')
43
+ * @param attributes - Override specific attributes of the generated object
44
+ * @param buildOptions - Options passed to the worker function for customization
45
+ *
46
+ * @returns A new instance of the specified model with a generated UUID
47
+ *
48
+ * @throws {Error} If the specified model name is not registered
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const user = factory.build('user', { email: 'test@example.com' });
53
+ * ```
18
54
  */
19
55
  build: function <T extends FactoryModel>(
20
56
  name: T,
@@ -32,7 +68,23 @@ export const factory = {
32
68
  },
33
69
 
34
70
  /**
35
- * Build multiple objects according to a defined model
71
+ * Build multiple objects according to a defined model.
72
+ *
73
+ * @template T - The model type to build
74
+ * @param name - The name of the model to build (e.g., 'user')
75
+ * @param count - The number of instances to generate
76
+ * @param attributes - Override specific attributes for all generated objects
77
+ * @param buildOptions - Options passed to the worker function for customization
78
+ *
79
+ * @returns An array of new instances of the specified model
80
+ *
81
+ * @throws {Error} If the specified model name is not registered
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const users = factory.buildMany('user', 10);
86
+ * const admins = factory.buildMany('user', 3, { role: 'admin' });
87
+ * ```
36
88
  */
37
89
  buildMany: function <T extends FactoryModel>(
38
90
  name: T,
@@ -1,7 +1,29 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import { sign, SignOptions } from 'jsonwebtoken';
3
3
 
4
- /** Returns an API access token valid in test environment */
4
+ /**
5
+ * Generates a mock JWT access token for testing purposes.
6
+ *
7
+ * This token is self-signed and only valid in test environments. It simulates
8
+ * tokens that would typically be issued by an authentication service like Auth0.
9
+ *
10
+ * @param userId - The user ID to include in the token subject. If not provided, a random UUID will be generated.
11
+ * @param options - Additional JWT signing options (expiresIn, audience, issuer, etc.)
12
+ * @param payload - Additional payload data to include in the token
13
+ *
14
+ * @returns A signed JWT token string
15
+ *
16
+ * @throws {Error} If JWT_SECRET environment variable is not set
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const token = generateAccessToken('user-123');
21
+ * const tokenWithCustomPayload = generateAccessToken('user-456', {}, { role: 'admin' });
22
+ * const shortLivedToken = generateAccessToken('user-789', { expiresIn: '1h' });
23
+ * ```
24
+ *
25
+ * @see {@link https://github.com/auth0/node-jsonwebtoken jsonwebtoken package} for available options
26
+ */
5
27
  export function generateAccessToken(
6
28
  userId: string,
7
29
  options: SignOptions = {},
@@ -1,3 +1,7 @@
1
+ /**
2
+ * List of supported locales for testing purposes.
3
+ * Includes major languages and regional variants.
4
+ */
1
5
  export const TEST_LOCALES = [
2
6
  'ar',
3
7
  'en-US',
@@ -18,10 +22,21 @@ export const TEST_LOCALES = [
18
22
  'vi-VN',
19
23
  'zh-CN',
20
24
  'zh-TW',
21
- ];
25
+ ] as const;
22
26
 
23
27
  /**
24
- * Pick up a random locale from the list of testable ones
28
+ * Generates a random locale from the list of supported test locales.
29
+ *
30
+ * Useful for testing internationalization (i18n) features and ensuring
31
+ * your application handles different locales correctly.
32
+ *
33
+ * @returns A randomly selected locale code (e.g., 'en-US', 'fr-FR')
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const locale = generateLocale();
38
+ * console.log(locale); // e.g., 'ja-JP'
39
+ * ```
25
40
  */
26
41
  export function generateLocale(): string {
27
42
  return TEST_LOCALES[Math.floor(Math.random() * TEST_LOCALES.length)];
@@ -1,23 +1,54 @@
1
1
  import crypto from 'crypto';
2
2
 
3
3
  /**
4
- * Generates a fake base64 string that looks like a user public key
5
- * /!\ This is not a valid crypto key
4
+ * Generates a fake base64 string that resembles a user public key.
5
+ *
6
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
7
+ * This function is only for testing purposes to generate mock data.
8
+ *
9
+ * @returns A base64-encoded random string (162 bytes)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const mockPublicKey = generateSignKeyPub();
14
+ * // Use in tests where you need a public key format
15
+ * ```
6
16
  */
7
17
  export function generateSignKeyPub(): string {
8
18
  return crypto.randomBytes(162).toString('base64');
9
19
  }
20
+
10
21
  /**
11
- * Generates a fake base64 string that looks like a user encrypted private key
12
- * /!\ This is not a valid crypto key
22
+ * Generates a fake base64 string that resembles a user encrypted private key.
23
+ *
24
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
25
+ * This function is only for testing purposes to generate mock data.
26
+ *
27
+ * @returns A base64-encoded random string (640 bytes)
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const mockPrivateKey = generateSignKeyEncrypted();
32
+ * // Use in tests where you need an encrypted private key format
33
+ * ```
13
34
  */
14
35
  export function generateSignKeyEncrypted(): string {
15
36
  return crypto.randomBytes(640).toString('base64');
16
37
  }
17
38
 
18
39
  /**
19
- * Generates a fake base64 string that looks like a user encrypted Blackberry Passcode
20
- * /!\ This is not a valid crypto key
40
+ * Generates a fake base64 string that resembles an encrypted BlackBerry passcode.
41
+ *
42
+ * ⚠️ **WARNING**: This is NOT a valid cryptographic key.
43
+ * This function is only for testing purposes to generate mock data.
44
+ *
45
+ * @returns A base64-encoded random string (80 bytes)
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const mockPasscode = generateBbEncrypted();
50
+ * // Use in tests where you need a BlackBerry passcode format
51
+ * ```
21
52
  */
22
53
  export function generateBbEncrypted(): string {
23
54
  return crypto.randomBytes(80).toString('base64');
@@ -7,7 +7,7 @@ export interface generateCertsOptions {
7
7
  /** Certificate issue information */
8
8
  issuer?: Array<pki.CertificateField>;
9
9
  /** Private key to use to sign the certificate */
10
- key?: pki.PrivateKey;
10
+ key?: pki.rsa.PrivateKey;
11
11
  }
12
12
 
13
13
  /** Fake certificate generated */
@@ -15,7 +15,7 @@ export interface GeneratedCertificate {
15
15
  /** PEM certificate */
16
16
  cert: string;
17
17
  /** Private key to use with the certificate */
18
- privateKey: pki.PrivateKey;
18
+ privateKey: pki.rsa.PrivateKey;
19
19
  /** PEM encoding of the private key */
20
20
  privateKeyPem: string;
21
21
  }
@@ -1,4 +1,8 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noUnusedLocals": false,
5
+ "noUnusedParameters": false
6
+ },
3
7
  "include": ["src"]
4
8
  }
package/tsconfig.json CHANGED
@@ -5,14 +5,21 @@
5
5
  "test": ["../test"],
6
6
  "test/*": ["../test/*"]
7
7
  },
8
- "target": "ES6",
9
- "lib": ["es2023"],
8
+ "target": "ES2022",
9
+ "lib": ["ES2023"],
10
10
  "module": "commonjs",
11
11
  "moduleResolution": "node",
12
12
  "outDir": "./dist",
13
+ "rootDir": "./",
13
14
  "noImplicitAny": true,
14
15
  "noImplicitThis": true,
15
16
  "strictNullChecks": true,
17
+ "strictBindCallApply": true,
18
+ "strictFunctionTypes": true,
19
+ "strictPropertyInitialization": true,
20
+ "noImplicitReturns": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
16
23
  "allowJs": true,
17
24
  "skipLibCheck": true,
18
25
  "esModuleInterop": true,
@@ -26,5 +33,6 @@
26
33
  "declaration": true,
27
34
  "emitDeclarationOnly": true
28
35
  },
29
- "include": ["src", "test"]
36
+ "include": ["src", "test"],
37
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
30
38
  }
@@ -1,11 +0,0 @@
1
- import { FactoryModel, FactoryBuildOptions, FactoryModelOverride, FactoryReturnType } from './factory.types';
2
- export declare const factory: {
3
- /**
4
- * Build an object according to a defined model
5
- */
6
- build: <T extends FactoryModel>(name: T, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => FactoryReturnType<T>;
7
- /**
8
- * Build multiple objects according to a defined model
9
- */
10
- buildMany: <T extends FactoryModel>(name: T, count: number, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => Array<FactoryReturnType<T>>;
11
- };
@@ -1,3 +0,0 @@
1
- import { SignOptions } from 'jsonwebtoken';
2
- /** Returns an API access token valid in test environment */
3
- export declare function generateAccessToken(userId: string, options?: SignOptions, payload?: string | Buffer | object): string;
@@ -1,5 +0,0 @@
1
- export declare const TEST_LOCALES: string[];
2
- /**
3
- * Pick up a random locale from the list of testable ones
4
- */
5
- export declare function generateLocale(): string;
@@ -1,15 +0,0 @@
1
- /**
2
- * Generates a fake base64 string that looks like a user public key
3
- * /!\ This is not a valid crypto key
4
- */
5
- export declare function generateSignKeyPub(): string;
6
- /**
7
- * Generates a fake base64 string that looks like a user encrypted private key
8
- * /!\ This is not a valid crypto key
9
- */
10
- export declare function generateSignKeyEncrypted(): string;
11
- /**
12
- * Generates a fake base64 string that looks like a user encrypted Blackberry Passcode
13
- * /!\ This is not a valid crypto key
14
- */
15
- export declare function generateBbEncrypted(): string;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes