ecwt 0.2.1-beta.3 → 0.2.1-beta.5

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.
package/bun.lockb CHANGED
Binary file
package/dist/main.cjs CHANGED
@@ -196,7 +196,7 @@ var EcwtFactory = class {
196
196
  * @param {object} param0.options -
197
197
  * @param {string} [param0.options.namespace] Namespace for Redis keys.
198
198
  * @param {Buffer} param0.options.key Encryption key, 64 bytes
199
- * @param {(value: any) => any} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
199
+ * @param {(value: unknown) => D} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
200
200
  * @param {Record<string, number>} [param0.options.senml_key_map] Payload object keys mapped for their SenML keys.
201
201
  */
202
202
  constructor({
@@ -242,7 +242,7 @@ var EcwtFactory = class {
242
242
  * @param {D} data Data to be stored in token.
243
243
  * @param {object} [options] -
244
244
  * @param {number | null} [options.ttl] Time to live in seconds. By default, token will never expire.
245
- * @returns {Promise<Ecwt>} -
245
+ * @returns {Promise<Ecwt<D>>} -
246
246
  */
247
247
  async create(data, {
248
248
  ttl = null
@@ -301,7 +301,7 @@ var EcwtFactory = class {
301
301
  * Parses token.
302
302
  * @async
303
303
  * @param {string} token String representation of token.
304
- * @returns {Promise<Ecwt>} -
304
+ * @returns {Promise<Ecwt<D>>} -
305
305
  */
306
306
  async verify(token) {
307
307
  if (typeof token !== "string") {
@@ -381,7 +381,7 @@ var EcwtFactory = class {
381
381
  * Parses token without throwing errors.
382
382
  * @async
383
383
  * @param {string} token String representation of token.
384
- * @returns {Promise<{ success: true, ecwt: Ecwt } | { success: false, ecwt: Ecwt | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
384
+ * @returns {Promise<{ success: true, ecwt: Ecwt<D> } | { success: false, ecwt: Ecwt<D> | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
385
385
  */
386
386
  async safeVerify(token) {
387
387
  let ecwt = null;
@@ -10,7 +10,7 @@ export class EcwtFactory<D extends Record<string, any> = Record<string, any>> {
10
10
  * @param {object} param0.options -
11
11
  * @param {string} [param0.options.namespace] Namespace for Redis keys.
12
12
  * @param {Buffer} param0.options.key Encryption key, 64 bytes
13
- * @param {(value: any) => any} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
13
+ * @param {(value: unknown) => D} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
14
14
  * @param {Record<string, number>} [param0.options.senml_key_map] Payload object keys mapped for their SenML keys.
15
15
  */
16
16
  constructor({ redisClient, lruCache, snowflakeFactory, options: { namespace, key, validator, senml_key_map, }, }: {
@@ -20,7 +20,7 @@ export class EcwtFactory<D extends Record<string, any> = Record<string, any>> {
20
20
  options: {
21
21
  namespace?: string | undefined;
22
22
  key: Buffer;
23
- validator?: ((value: any) => any) | undefined;
23
+ validator?: ((value: unknown) => D) | undefined;
24
24
  senml_key_map?: Record<string, number> | undefined;
25
25
  };
26
26
  });
@@ -30,30 +30,30 @@ export class EcwtFactory<D extends Record<string, any> = Record<string, any>> {
30
30
  * @param {D} data Data to be stored in token.
31
31
  * @param {object} [options] -
32
32
  * @param {number | null} [options.ttl] Time to live in seconds. By default, token will never expire.
33
- * @returns {Promise<Ecwt>} -
33
+ * @returns {Promise<Ecwt<D>>} -
34
34
  */
35
35
  create(data: D, { ttl, }?: {
36
36
  ttl?: number | null | undefined;
37
- } | undefined): Promise<Ecwt>;
37
+ } | undefined): Promise<Ecwt<D>>;
38
38
  /**
39
39
  * Parses token.
40
40
  * @async
41
41
  * @param {string} token String representation of token.
42
- * @returns {Promise<Ecwt>} -
42
+ * @returns {Promise<Ecwt<D>>} -
43
43
  */
44
- verify(token: string): Promise<Ecwt>;
44
+ verify(token: string): Promise<Ecwt<D>>;
45
45
  /**
46
46
  * Parses token without throwing errors.
47
47
  * @async
48
48
  * @param {string} token String representation of token.
49
- * @returns {Promise<{ success: true, ecwt: Ecwt } | { success: false, ecwt: Ecwt | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
49
+ * @returns {Promise<{ success: true, ecwt: Ecwt<D> } | { success: false, ecwt: Ecwt<D> | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
50
50
  */
51
51
  safeVerify(token: string): Promise<{
52
52
  success: true;
53
- ecwt: Ecwt;
53
+ ecwt: Ecwt<D>;
54
54
  } | {
55
55
  success: false;
56
- ecwt: Ecwt | null;
56
+ ecwt: Ecwt<D> | null;
57
57
  }>;
58
58
  /**
59
59
  * Revokes token.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecwt",
3
- "version": "0.2.1-beta.3",
3
+ "version": "0.2.1-beta.5",
4
4
  "description": "Encrypted CBOR-encoded Web Token",
5
5
  "type": "module",
6
6
  "main": "src/main.js",
@@ -25,20 +25,20 @@
25
25
  "redis": "^4"
26
26
  },
27
27
  "devDependencies": {
28
- "@kirick/eslint-config": "^0.1.11",
29
- "@types/node": "^20.14.9",
28
+ "@kirick/eslint-config": "^0.1.21",
29
+ "@types/node": "^22.2",
30
30
  "eslint": "9.8.0",
31
- "valibot": "^0.33",
31
+ "valibot": "^0.37",
32
32
  "vitest": "^1.6"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "bun run build:types && bun run build:cjs",
36
36
  "build:cjs": "bunx esbuild --bundle --platform=node --format=cjs --packages=external --outfile=dist/main.cjs src/main.js",
37
- "build:types": "bunx tsc --skipLibCheck --declaration --emitDeclarationOnly --outDir dist/types",
37
+ "build:types": "rm -rf dist/esm dist/types ; bunx tsc --emitDeclarationOnly && rm dist/**/*.test.d.ts",
38
38
  "lint": "eslint . && bunx tsc --skipLibCheck --noemit",
39
39
  "publish:npm": "bun run build && bun run lint && bun run test && npm publish",
40
- "redis:up": "docker ps | grep test-redis >/dev/null || docker run --rm -d -p $REDIS_PORT:6379 --name test-redis redis:7-alpine",
41
- "test": "export REDIS_PORT=16379 ; bun run redis:up && npm run test:vitest && bun test --coverage",
40
+ "redis:up": "docker ps | grep test-redis >/dev/null || docker run --rm -d -p 16379:6379 --name test-redis redis:7-alpine",
41
+ "test": "bun run redis:up && npm run test:vitest && bun test --coverage",
42
42
  "test:vitest": "vitest run --no-file-parallelism"
43
43
  },
44
44
  "repository": {
package/src/factory.js CHANGED
@@ -53,7 +53,7 @@ export class EcwtFactory {
53
53
  * @param {object} param0.options -
54
54
  * @param {string} [param0.options.namespace] Namespace for Redis keys.
55
55
  * @param {Buffer} param0.options.key Encryption key, 64 bytes
56
- * @param {(value: any) => any} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
56
+ * @param {(value: unknown) => D} [param0.options.validator] Validator for token data. Should return validated value or throw an error.
57
57
  * @param {Record<string, number>} [param0.options.senml_key_map] Payload object keys mapped for their SenML keys.
58
58
  */
59
59
  constructor({
@@ -111,7 +111,7 @@ export class EcwtFactory {
111
111
  * @param {D} data Data to be stored in token.
112
112
  * @param {object} [options] -
113
113
  * @param {number | null} [options.ttl] Time to live in seconds. By default, token will never expire.
114
- * @returns {Promise<Ecwt>} -
114
+ * @returns {Promise<Ecwt<D>>} -
115
115
  */
116
116
  async create(
117
117
  data,
@@ -190,7 +190,7 @@ export class EcwtFactory {
190
190
  * Parses token.
191
191
  * @async
192
192
  * @param {string} token String representation of token.
193
- * @returns {Promise<Ecwt>} -
193
+ * @returns {Promise<Ecwt<D>>} -
194
194
  */
195
195
  async verify(token) {
196
196
  if (typeof token !== 'string') {
@@ -297,7 +297,7 @@ export class EcwtFactory {
297
297
  * Parses token without throwing errors.
298
298
  * @async
299
299
  * @param {string} token String representation of token.
300
- * @returns {Promise<{ success: true, ecwt: Ecwt } | { success: false, ecwt: Ecwt | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
300
+ * @returns {Promise<{ success: true, ecwt: Ecwt<D> } | { success: false, ecwt: Ecwt<D> | null }>} Returns whether token was parsed and verified successfully and Ecwt if parsed.
301
301
  */
302
302
  async safeVerify(token) {
303
303
  let ecwt = null;