sea-backend-helpers 1.5.8 → 1.5.9

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.
@@ -0,0 +1,5 @@
1
+ export type CachedToken = {
2
+ deviceId: string;
3
+ token: string;
4
+ };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/jwt/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,10 @@
1
1
  import { CacheableModules } from "../../constants/cache";
2
2
  import { Cache } from "@nestjs/cache-manager";
3
- export declare const generateCacheKey: (id: string, type: CacheableModules) => string;
4
- export declare const updateIfExist: <T>(id: string, type: CacheableModules, value: T, cache: Cache) => Promise<void>;
5
- export declare const deleteIfExist: (id: string, type: CacheableModules, cache: Cache) => void;
3
+ type Token = "Token";
4
+ export declare const generateCacheKey: (id: string, type: CacheableModules | Token) => string;
5
+ export declare const set: <T>(id: string, type: CacheableModules | Token, value: T, cache: Cache, ttl?: number) => Promise<void>;
6
+ export declare const get: <T>(id: string, type: CacheableModules | Token, cache: Cache) => Promise<T | undefined>;
7
+ export declare const updateIfExist: <T>(id: string, type: CacheableModules | Token, value: T, cache: Cache, ttl?: number) => Promise<void>;
8
+ export declare const deleteIfExist: (id: string, type: CacheableModules | Token, cache: Cache) => void;
9
+ export {};
6
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,eAAO,MAAM,gBAAgB,OAAQ,MAAM,QAAQ,gBAAgB,WAElE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,CAAC,MAC/B,MAAM,QACJ,gBAAgB,SACf,CAAC,SACD,KAAK,kBAMb,CAAC;AAEF,eAAO,MAAM,aAAa,OACpB,MAAM,QACJ,gBAAgB,SACf,KAAK,SAKb,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,KAAK,KAAK,GAAG,OAAO,CAAC;AACrB,eAAO,MAAM,gBAAgB,OACvB,MAAM,QACJ,gBAAgB,GAAG,KAAK,WAG/B,CAAC;AAEF,eAAO,MAAM,GAAG,GAAU,CAAC,MACrB,MAAM,QACJ,gBAAgB,GAAG,KAAK,SACvB,CAAC,SACD,KAAK,gCAMb,CAAC;AAEF,eAAO,MAAM,GAAG,GAAU,CAAC,MACrB,MAAM,QACJ,gBAAgB,GAAG,KAAK,SACvB,KAAK,2BAKb,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,CAAC,MAC/B,MAAM,QACJ,gBAAgB,GAAG,KAAK,SACvB,CAAC,SACD,KAAK,gCAOb,CAAC;AAEF,eAAO,MAAM,aAAa,OACpB,MAAM,QACJ,gBAAgB,GAAG,KAAK,SACvB,KAAK,SAKb,CAAC"}
@@ -9,16 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.deleteIfExist = exports.updateIfExist = exports.generateCacheKey = void 0;
12
+ exports.deleteIfExist = exports.updateIfExist = exports.get = exports.set = exports.generateCacheKey = void 0;
13
13
  const generateCacheKey = (id, type) => {
14
14
  return `${type}:${id}`;
15
15
  };
16
16
  exports.generateCacheKey = generateCacheKey;
17
- const updateIfExist = (id, type, value, cache) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const set = (id_1, type_1, value_1, cache_1, ...args_1) => __awaiter(void 0, [id_1, type_1, value_1, cache_1, ...args_1], void 0, function* (id, type, value, cache, ttl = 1000 * 3600) {
18
+ const key = (0, exports.generateCacheKey)(id, type);
19
+ cache.set(key, value, ttl);
20
+ });
21
+ exports.set = set;
22
+ const get = (id, type, cache) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const key = (0, exports.generateCacheKey)(id, type);
24
+ return cache.get(key);
25
+ });
26
+ exports.get = get;
27
+ const updateIfExist = (id_1, type_1, value_1, cache_1, ...args_1) => __awaiter(void 0, [id_1, type_1, value_1, cache_1, ...args_1], void 0, function* (id, type, value, cache, ttl = 1000 * 3600) {
18
28
  const key = (0, exports.generateCacheKey)(id, type);
19
29
  const data = yield cache.get(key);
20
30
  if (data)
21
- cache.set(key, value);
31
+ cache.set(key, value, ttl);
22
32
  });
23
33
  exports.updateIfExist = updateIfExist;
24
34
  const deleteIfExist = (id, type, cache) => {
@@ -3,6 +3,7 @@ export declare const verifyJWTRequest: (authorization: string | undefined, publi
3
3
  payload: any;
4
4
  success: boolean;
5
5
  message: string;
6
+ token: string;
6
7
  };
7
8
  export declare const validatePermissions: (acceptedPermissionKeys: CONSTANTS.Permission.PermissionKeys[], accountPermissionKeys: CONSTANTS.Permission.PermissionKeys[], validationStrategy: CONSTANTS.Permission.ValidationStrategy) => boolean;
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/jwt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,eAAO,MAAM,gBAAgB,kBACZ,MAAM,GAAG,SAAS,aACtB,MAAM,CAAC,eAAe,CAAC,aACvB,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC;;;;CA2BvE,CAAC;AAEF,eAAO,MAAM,mBAAmB,2BACN,SAAS,CAAC,UAAU,CAAC,cAAc,EAAE,yBACtC,SAAS,CAAC,UAAU,CAAC,cAAc,EAAE,sBACxC,SAAS,CAAC,UAAU,CAAC,kBAAkB,KAC1D,OAeF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/jwt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,eAAO,MAAM,gBAAgB,kBACZ,MAAM,GAAG,SAAS,aACtB,MAAM,CAAC,eAAe,CAAC,aACvB,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC;;;;;CA4BvE,CAAC;AAEF,eAAO,MAAM,mBAAmB,2BACN,SAAS,CAAC,UAAU,CAAC,cAAc,EAAE,yBACtC,SAAS,CAAC,UAAU,CAAC,cAAc,EAAE,sBACxC,SAAS,CAAC,UAAU,CAAC,kBAAkB,KAC1D,OAeF,CAAC"}
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePermissions = exports.verifyJWTRequest = void 0;
4
+ const sea_platform_helpers_1 = require("sea-platform-helpers");
4
5
  const verifyJWTRequest = (authorization, publicKey, verifyJWT) => {
5
6
  let success = true, message = "", payload = undefined;
6
7
  if (!authorization) {
7
8
  success = false;
8
- message = "the token is not provided in the authorization request headers";
9
+ message = sea_platform_helpers_1.CONSTANTS.Server.ERROR_MESSAGES.INVALID_INPUT;
9
10
  }
10
11
  authorization = authorization + "";
11
12
  let token = authorization;
@@ -16,12 +17,13 @@ const verifyJWTRequest = (authorization, publicKey, verifyJWT) => {
16
17
  }
17
18
  catch (error) {
18
19
  success = false;
19
- message = `invalid or expired token (${error.message})`;
20
+ message = sea_platform_helpers_1.CONSTANTS.Server.ERROR_MESSAGES.UNAUTHENTICATED;
20
21
  }
21
22
  return {
22
23
  payload,
23
24
  success,
24
25
  message,
26
+ token,
25
27
  };
26
28
  };
27
29
  exports.verifyJWTRequest = verifyJWTRequest;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sea-backend-helpers",
3
3
  "description": "SEA Backend helpers library",
4
- "version": "1.5.8",
4
+ "version": "1.5.9",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc --build",
@@ -33,7 +33,7 @@
33
33
  "reflect-metadata": "^0.1.13",
34
34
  "rxjs": "^7.0.0",
35
35
  "sea-backend-helpers": "file:",
36
- "sea-platform-helpers": "^1.5.11"
36
+ "sea-platform-helpers": "^1.5.12"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@nestjs/common": "^10.0.0",