ecwt 0.2.1-beta.2 → 0.2.1-beta.3

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 ADDED
Binary file
package/dist/main.cjs CHANGED
@@ -44,7 +44,6 @@ var import_snowflake = require("@kirick/snowflake");
44
44
  var import_cbor_x = require("cbor-x");
45
45
  var import_evilcrypt = require("evilcrypt");
46
46
  var import_lru_cache = require("lru-cache");
47
- var import_redis = require("redis");
48
47
 
49
48
  // src/utils/time.js
50
49
  function toSeconds(value) {
@@ -151,7 +150,9 @@ var InvalidPackageInstanceError = class extends TypeError {
151
150
  * @param {string} package_name -
152
151
  */
153
152
  constructor(property, class_name, package_name) {
154
- super(`Value ${property} must be an instance of ${class_name} from package "${package_name}". That error is probably caused by two separate installations of "${package_name}". Please, make sure that "${package_name}" in your project is matches "peerDependencies" of "ecwt" package.`);
153
+ super(
154
+ `Value ${property} must be an instance of ${class_name} from package "${package_name}". That error is probably caused by two separate installations of "${package_name}". Please, make sure that "${package_name}" in your project is matches "peerDependencies" of "ecwt" package.`
155
+ );
155
156
  }
156
157
  };
157
158
  var EcwtParseError = class extends Error {
@@ -178,16 +179,6 @@ var EcwtRevokedError = class extends EcwtInvalidError {
178
179
 
179
180
  // src/factory.js
180
181
  var REDIS_PREFIX = "@ecwt:";
181
- function getAllKeysList(value) {
182
- const keys = [];
183
- for (const key in value) {
184
- keys.push(key);
185
- }
186
- return keys.sort().join(",");
187
- }
188
- var redisClient = (0, import_redis.createClient)();
189
- var redis_client_constructor_name = redisClient.constructor.name;
190
- var redis_client_keys = getAllKeysList(redisClient);
191
182
  var EcwtFactory = class {
192
183
  #redisClient;
193
184
  #lruCache;
@@ -209,7 +200,7 @@ var EcwtFactory = class {
209
200
  * @param {Record<string, number>} [param0.options.senml_key_map] Payload object keys mapped for their SenML keys.
210
201
  */
211
202
  constructor({
212
- redisClient: redisClient2,
203
+ redisClient,
213
204
  lruCache,
214
205
  snowflakeFactory,
215
206
  options: {
@@ -219,14 +210,7 @@ var EcwtFactory = class {
219
210
  senml_key_map
220
211
  }
221
212
  }) {
222
- if (redisClient2 !== void 0 && (redisClient2.constructor.name !== redis_client_constructor_name || getAllKeysList(redisClient2) !== redis_client_keys)) {
223
- throw new InvalidPackageInstanceError(
224
- "redisClient",
225
- "Commander extends RedisClient",
226
- "redis"
227
- );
228
- }
229
- this.#redisClient = redisClient2;
213
+ this.#redisClient = redisClient;
230
214
  if (lruCache !== void 0 && lruCache instanceof import_lru_cache.LRUCache !== true) {
231
215
  throw new InvalidPackageInstanceError(
232
216
  "lruCache",
@@ -341,9 +325,7 @@ var EcwtFactory = class {
341
325
  throw new EcwtParseError();
342
326
  }
343
327
  const payload = this.#cborEncoder ? this.#cborEncoder.decode(token_raw) : (0, import_cbor_x.decode)(token_raw);
344
- const [
345
- snowflake_buffer
346
- ] = payload;
328
+ const [snowflake_buffer] = payload;
347
329
  [
348
330
  ,
349
331
  ttl_initial,
@@ -440,7 +422,7 @@ var EcwtFactory = class {
440
422
  ttl_initial
441
423
  }) {
442
424
  if (this.#redisClient) {
443
- ttl_initial = ttl_initial ?? Number.MAX_SAFE_INTEGER;
425
+ ttl_initial ??= Number.MAX_SAFE_INTEGER;
444
426
  const ts_ms_expired = ts_ms_created + ttl_initial * 1e3;
445
427
  if (ts_ms_expired > Date.now()) {
446
428
  await this.#redisClient.MULTI().addCommand([
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "ecwt",
3
- "version": "0.2.1-beta.2",
3
+ "version": "0.2.1-beta.3",
4
4
  "description": "Encrypted CBOR-encoded Web Token",
5
5
  "type": "module",
6
6
  "main": "src/main.js",
7
- "types": "types/main.d.ts",
7
+ "types": "dist/types/main.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./src/main.js",
@@ -25,28 +25,21 @@
25
25
  "redis": "^4"
26
26
  },
27
27
  "devDependencies": {
28
- "@babel/eslint-parser": "7.21.8",
28
+ "@kirick/eslint-config": "^0.1.11",
29
29
  "@types/node": "^20.14.9",
30
- "eslint": "8.41.0",
31
- "eslint-config-xo": "0.43.1",
32
- "eslint-plugin-import": "2.27.5",
33
- "eslint-plugin-jsdoc": "46.5.0",
34
- "eslint-plugin-node": "11.1.0",
35
- "eslint-plugin-promise": "6.1.1",
36
- "eslint-plugin-unicorn": "47.0.0",
30
+ "eslint": "9.8.0",
37
31
  "valibot": "^0.33",
38
32
  "vitest": "^1.6"
39
33
  },
40
34
  "scripts": {
41
- "test": "export REDIS_PORT=16274 ; bun run redis:up && npm run test:vitest && bun test --coverage ; bun run redis:down",
42
- "test:vitest": "vitest run --no-file-parallelism",
43
35
  "build": "bun run build:types && bun run build:cjs",
44
36
  "build:cjs": "bunx esbuild --bundle --platform=node --format=cjs --packages=external --outfile=dist/main.cjs src/main.js",
45
- "build:types": "bunx tsc --skipLibCheck --declaration --emitDeclarationOnly --outDir types",
37
+ "build:types": "bunx tsc --skipLibCheck --declaration --emitDeclarationOnly --outDir dist/types",
46
38
  "lint": "eslint . && bunx tsc --skipLibCheck --noemit",
47
39
  "publish:npm": "bun run build && bun run lint && bun run test && npm publish",
48
- "redis:up": "docker ps | grep test-ecwt >/dev/null || docker run --rm -d -p $REDIS_PORT:6379 --name test-ecwt redis:7-alpine",
49
- "redis:down": "docker stop test-ecwt || true"
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",
42
+ "test:vitest": "vitest run --no-file-parallelism"
50
43
  },
51
44
  "repository": {
52
45
  "type": "git",
package/src/factory.js CHANGED
@@ -13,12 +13,13 @@ import { SnowflakeFactory } from '@kirick/snowflake';
13
13
  import {
14
14
  Encoder as CborEncoder,
15
15
  encode as cborEncode,
16
- decode as cborDecode } from 'cbor-x';
16
+ decode as cborDecode,
17
+ } from 'cbor-x';
17
18
  import {
18
19
  decrypt as evilcryptDecrypt,
19
- v2 as evilcryptV2 } from 'evilcrypt';
20
+ v2 as evilcryptV2,
21
+ } from 'evilcrypt';
20
22
  import { LRUCache } from 'lru-cache';
21
- import { createClient } from 'redis';
22
23
  import { Ecwt } from './token.js';
23
24
  import { base62 } from './utils/base62.js';
24
25
  import {
@@ -26,27 +27,11 @@ import {
26
27
  EcwtInvalidError,
27
28
  EcwtExpiredError,
28
29
  EcwtRevokedError,
29
- EcwtParseError } from './utils/errors.js';
30
+ EcwtParseError,
31
+ } from './utils/errors.js';
30
32
 
31
33
  const REDIS_PREFIX = '@ecwt:';
32
34
 
33
- /**
34
- * @param {object} value -
35
- * @returns {string} -
36
- */
37
- function getAllKeysList(value) {
38
- const keys = [];
39
- // eslint-disable-next-line guard-for-in
40
- for (const key in value) {
41
- keys.push(key);
42
- }
43
- return keys.sort().join(',');
44
- }
45
-
46
- const redisClient = createClient();
47
- const redis_client_constructor_name = redisClient.constructor.name;
48
- const redis_client_keys = getAllKeysList(redisClient);
49
-
50
35
  /**
51
36
  * @template {Record<string, any>} [D=Record<string, any>]
52
37
  */
@@ -54,10 +39,8 @@ export class EcwtFactory {
54
39
  #redisClient;
55
40
  #lruCache;
56
41
  #snowflakeFactory;
57
-
58
42
  #redis_key_revoked;
59
43
  #encryption_key;
60
-
61
44
  #validator;
62
45
  /** @type {CborEncoder | null} */
63
46
  #cborEncoder = null;
@@ -84,19 +67,6 @@ export class EcwtFactory {
84
67
  senml_key_map,
85
68
  },
86
69
  }) {
87
- if (
88
- redisClient !== undefined
89
- && (
90
- redisClient.constructor.name !== redis_client_constructor_name
91
- || getAllKeysList(redisClient) !== redis_client_keys
92
- )
93
- ) {
94
- throw new InvalidPackageInstanceError(
95
- 'redisClient',
96
- 'Commander extends RedisClient',
97
- 'redis',
98
- );
99
- }
100
70
  this.#redisClient = redisClient;
101
71
 
102
72
  if (
@@ -109,6 +79,7 @@ export class EcwtFactory {
109
79
  'lru-cache',
110
80
  );
111
81
  }
82
+
112
83
  this.#lruCache = lruCache;
113
84
 
114
85
  if (snowflakeFactory instanceof SnowflakeFactory !== true) {
@@ -118,6 +89,7 @@ export class EcwtFactory {
118
89
  '@kirick/snowflake',
119
90
  );
120
91
  }
92
+
121
93
  this.#snowflakeFactory = snowflakeFactory;
122
94
 
123
95
  this.#redis_key_revoked = `${REDIS_PREFIX}${namespace}:revoked`;
@@ -251,9 +223,7 @@ export class EcwtFactory {
251
223
  ? this.#cborEncoder.decode(token_raw)
252
224
  : cborDecode(token_raw);
253
225
 
254
- const [
255
- snowflake_buffer,
256
- ] = payload;
226
+ const [ snowflake_buffer ] = payload;
257
227
  [
258
228
  ,
259
229
  ttl_initial,
@@ -373,7 +343,7 @@ export class EcwtFactory {
373
343
  ttl_initial,
374
344
  }) {
375
345
  if (this.#redisClient) {
376
- ttl_initial = ttl_initial ?? Number.MAX_SAFE_INTEGER;
346
+ ttl_initial ??= Number.MAX_SAFE_INTEGER;
377
347
 
378
348
  const ts_ms_expired = ts_ms_created + (ttl_initial * 1000);
379
349
  if (ts_ms_expired > Date.now()) {
package/src/token.js CHANGED
@@ -40,7 +40,6 @@ export class Ecwt {
40
40
  * @readonly
41
41
  */
42
42
  data;
43
-
44
43
  /** @type {EcwtFactory} */
45
44
  #ecwtFactory;
46
45
  /** @type {number | null} */
@@ -10,7 +10,11 @@ export class InvalidPackageInstanceError extends TypeError {
10
10
  * @param {string} package_name -
11
11
  */
12
12
  constructor(property, class_name, package_name) {
13
- super(`Value ${property} must be an instance of ${class_name} from package "${package_name}". That error is probably caused by two separate installations of "${package_name}". Please, make sure that "${package_name}" in your project is matches "peerDependencies" of "ecwt" package.`);
13
+ super(
14
+ `Value ${property} must be an instance of ${class_name} from package "${package_name}".`
15
+ + ` That error is probably caused by two separate installations of "${package_name}".`
16
+ + ` Please, make sure that "${package_name}" in your project is matches "peerDependencies" of "ecwt" package.`,
17
+ );
14
18
  }
15
19
  }
16
20
 
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "target": "esnext",
5
- "module": "esnext",
6
- "checkJs": true,
7
- "allowJs": true,
8
- "moduleResolution": "node",
9
- "allowSyntheticDefaultImports": true,
10
- "strict": true
11
- },
12
- "include": [
13
- "src/**/*"
14
- ],
15
- "exclude": [
16
- "node_modules/",
17
- "dist/"
18
- ]
19
- }
@@ -1 +0,0 @@
1
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes