@creator.co/wapi 1.2.3 → 1.2.4

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 (83) hide show
  1. package/.github/workflows/npmpublish.yml +2 -5
  2. package/README.md +1 -3
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.js +24 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/jest.config.d.ts +3 -0
  7. package/dist/jest.config.js +34 -0
  8. package/dist/jest.config.js.map +1 -0
  9. package/dist/package.json +64 -0
  10. package/dist/src/API/Request.d.ts +140 -0
  11. package/dist/src/API/Request.js +182 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +256 -0
  14. package/dist/src/API/Response.js +398 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/API/Utils.d.ts +63 -0
  17. package/dist/src/API/Utils.js +104 -0
  18. package/dist/src/API/Utils.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +182 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +74 -0
  23. package/dist/src/BaseEvent/Process.js +142 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/Transaction.d.ts +29 -0
  26. package/dist/src/BaseEvent/Transaction.js +244 -0
  27. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  28. package/dist/src/Config/Configuration.d.ts +131 -0
  29. package/dist/src/Config/Configuration.js +153 -0
  30. package/dist/src/Config/Configuration.js.map +1 -0
  31. package/dist/src/Config/EnvironmentVar.d.ts +101 -0
  32. package/dist/src/Config/EnvironmentVar.js +213 -0
  33. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  34. package/dist/src/Crypto/Crypto.d.ts +57 -0
  35. package/dist/src/Crypto/Crypto.js +126 -0
  36. package/dist/src/Crypto/Crypto.js.map +1 -0
  37. package/dist/src/Crypto/JWT.d.ts +64 -0
  38. package/dist/src/Crypto/JWT.js +74 -0
  39. package/dist/src/Crypto/JWT.js.map +1 -0
  40. package/dist/src/Globals.d.ts +161 -0
  41. package/dist/src/Globals.js +173 -0
  42. package/dist/src/Globals.js.map +1 -0
  43. package/dist/src/Logger/Logger.d.ts +180 -0
  44. package/dist/src/Logger/Logger.js +412 -0
  45. package/dist/src/Logger/Logger.js.map +1 -0
  46. package/dist/src/Mailer/Mailer.d.ts +107 -0
  47. package/dist/src/Mailer/Mailer.js +313 -0
  48. package/dist/src/Mailer/Mailer.js.map +1 -0
  49. package/dist/src/Publisher/Publisher.d.ts +47 -0
  50. package/dist/src/Publisher/Publisher.js +141 -0
  51. package/dist/src/Publisher/Publisher.js.map +1 -0
  52. package/dist/src/Server/RouteResolver.d.ts +41 -0
  53. package/dist/src/Server/RouteResolver.js +135 -0
  54. package/dist/src/Server/RouteResolver.js.map +1 -0
  55. package/dist/src/Server/Router.d.ts +104 -0
  56. package/dist/src/Server/Router.js +45 -0
  57. package/dist/src/Server/Router.js.map +1 -0
  58. package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
  59. package/dist/src/Server/lib/ContainerServer.js +143 -0
  60. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  61. package/dist/src/Server/lib/Server.d.ts +60 -0
  62. package/dist/src/Server/lib/Server.js +137 -0
  63. package/dist/src/Server/lib/Server.js.map +1 -0
  64. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  65. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  66. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  67. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
  68. package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
  69. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  70. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  71. package/dist/src/Server/lib/container/HealthHandler.js +45 -0
  72. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  73. package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
  74. package/dist/src/Server/lib/container/Proxy.js +201 -0
  75. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  76. package/dist/src/Server/lib/container/Utils.d.ts +18 -0
  77. package/dist/src/Server/lib/container/Utils.js +84 -0
  78. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  79. package/dist/src/Validation/Validator.d.ts +21 -0
  80. package/dist/src/Validation/Validator.js +48 -0
  81. package/dist/src/Validation/Validator.js.map +1 -0
  82. package/jest.config.ts +1 -8
  83. package/package.json +3 -3
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.EnvironmentType = void 0;
40
+ var client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
41
+ var client_ssm_1 = require("@aws-sdk/client-ssm");
42
+ // Explicity setting VM level variables in order to persist
43
+ // client across different important and instances.
44
+ // eslint-disable-next-line no-var
45
+ /**
46
+ * ${1:Description placeholder}
47
+ *
48
+ * @type {*}
49
+ */
50
+ var ssmClient = null, secretsClient = null;
51
+ /**
52
+ * ${1:Description placeholder}
53
+ *
54
+ * @export
55
+ * @enum {number}
56
+ */
57
+ var EnvironmentType;
58
+ (function (EnvironmentType) {
59
+ EnvironmentType[EnvironmentType["PlainRemote"] = 0] = "PlainRemote";
60
+ EnvironmentType[EnvironmentType["SecureRemote"] = 1] = "SecureRemote";
61
+ EnvironmentType[EnvironmentType["Local"] = 2] = "Local";
62
+ })(EnvironmentType || (exports.EnvironmentType = EnvironmentType = {}));
63
+ /**
64
+ * ${1:Description placeholder}
65
+ *
66
+ * @export
67
+ * @class EnvironmentVar
68
+ * @typedef {EnvironmentVar}
69
+ * @template T
70
+ */
71
+ var EnvironmentVar = /** @class */ (function () {
72
+ /**
73
+ * Creates an instance of EnvironmentVar.
74
+ *
75
+ * @constructor
76
+ * @param {string} paramName
77
+ * @param {EnvironmentType} type
78
+ * @param {?boolean} [optional]
79
+ * @param {string} [paramPrefix=`/creatorco-api-\${process.env.STAGE\}/env/`]
80
+ */
81
+ function EnvironmentVar(paramName, type, optional, paramPrefix /* only allowed process.env */) {
82
+ if (paramPrefix === void 0) { paramPrefix = "/creatorco-api-".concat(process.env.STAGE, "/env/"); }
83
+ this.paramName = paramName;
84
+ this.type = type;
85
+ this.optional = !!optional;
86
+ this.paramPrefix = paramPrefix;
87
+ }
88
+ /**
89
+ * ${1:Description placeholder}
90
+ *
91
+ * @public
92
+ * @returns {T}
93
+ */
94
+ EnvironmentVar.prototype.syncResolve = function () {
95
+ if (this.type == EnvironmentType.Local)
96
+ return this.getLocalValue();
97
+ else {
98
+ throw new Error("EnvironmentVar syncResolve method can only be called for environments of type 'Local'");
99
+ }
100
+ };
101
+ /**
102
+ * ${1:Description placeholder}
103
+ *
104
+ * @public
105
+ * @async
106
+ * @returns {unknown}
107
+ */
108
+ EnvironmentVar.prototype.resolve = function () {
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ return __generator(this, function (_a) {
111
+ if (this.type == EnvironmentType.Local)
112
+ return [2 /*return*/, this.getLocalValue()];
113
+ else if (this.type == EnvironmentType.SecureRemote)
114
+ return [2 /*return*/, this.getSecureValue()];
115
+ else
116
+ return [2 /*return*/, this.getPlainValue()];
117
+ return [2 /*return*/];
118
+ });
119
+ });
120
+ };
121
+ /**
122
+ * ${1:Description placeholder}
123
+ *
124
+ * @private
125
+ * @returns {T}
126
+ */
127
+ EnvironmentVar.prototype.getLocalValue = function () {
128
+ var value = process.env[this.paramName];
129
+ if (!value && !this.optional) {
130
+ throw new Error("Local environment ".concat(this.paramName, " is not defined, please reconfigure the application and redeploy!"));
131
+ }
132
+ return value;
133
+ };
134
+ /**
135
+ * ${1:Description placeholder}
136
+ *
137
+ * @private
138
+ * @async
139
+ * @returns {Promise<T>}
140
+ */
141
+ EnvironmentVar.prototype.getPlainValue = function () {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var pName, data, error_1;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0:
147
+ if (!ssmClient)
148
+ ssmClient = new client_ssm_1.SSMClient();
149
+ pName = "".concat(this.paramPrefix).concat(this.paramName);
150
+ _a.label = 1;
151
+ case 1:
152
+ _a.trys.push([1, 3, , 4]);
153
+ return [4 /*yield*/, ssmClient.send(new client_ssm_1.GetParameterCommand({ Name: pName }))];
154
+ case 2:
155
+ data = _a.sent();
156
+ if (data.Parameter && data.Parameter.Value)
157
+ return [2 /*return*/, data.Parameter.Value];
158
+ return [3 /*break*/, 4];
159
+ case 3:
160
+ error_1 = _a.sent();
161
+ console.error(error_1);
162
+ return [3 /*break*/, 4];
163
+ case 4:
164
+ if (!this.optional) {
165
+ throw new Error("Unable to retrieve plain remote env value: ".concat(pName));
166
+ }
167
+ return [2 /*return*/];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ /**
173
+ * ${1:Description placeholder}
174
+ *
175
+ * @private
176
+ * @async
177
+ * @returns {Promise<T>}
178
+ */
179
+ EnvironmentVar.prototype.getSecureValue = function () {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var pName, data, error_2;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0:
185
+ if (!secretsClient)
186
+ secretsClient = new client_secrets_manager_1.SecretsManagerClient();
187
+ pName = "".concat(this.paramPrefix).concat(this.paramName);
188
+ _a.label = 1;
189
+ case 1:
190
+ _a.trys.push([1, 3, , 4]);
191
+ return [4 /*yield*/, secretsClient.send(new client_secrets_manager_1.GetSecretValueCommand({ SecretId: pName }))];
192
+ case 2:
193
+ data = _a.sent();
194
+ if (data.Parameter && data.Parameter.Value)
195
+ return [2 /*return*/, data.Parameter.Value];
196
+ return [3 /*break*/, 4];
197
+ case 3:
198
+ error_2 = _a.sent();
199
+ console.error(error_2);
200
+ return [3 /*break*/, 4];
201
+ case 4:
202
+ if (!this.optional) {
203
+ throw new Error("Unable to retrieve secure remote env: ".concat(pName));
204
+ }
205
+ return [2 /*return*/];
206
+ }
207
+ });
208
+ });
209
+ };
210
+ return EnvironmentVar;
211
+ }());
212
+ exports.default = EnvironmentVar;
213
+ //# sourceMappingURL=EnvironmentVar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentVar.js","sourceRoot":"","sources":["../../../src/Config/EnvironmentVar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA6F;AAC7F,kDAAoE;AAEpE,2DAA2D;AAC3D,mDAAmD;AACnD,kCAAkC;AAClC;;;;GAIG;AACH,IAAI,SAAS,GAAG,IAAI,EAClB,aAAa,GAAG,IAAI,CAAA;AAEtB;;;;;GAKG;AACH,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,mEAAW,CAAA;IACX,qEAAY,CAAA;IACZ,uDAAK,CAAA;AACP,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AACD;;;;;;;GAOG;AACH;IAiCE;;;;;;;;OAQG;IACH,wBACE,SAAiB,EACjB,IAAqB,EACrB,QAAkB,EAClB,WAAwD,CAAC,8BAA8B;QAAvF,4BAAA,EAAA,uCAAgC,OAAO,CAAC,GAAG,CAAC,KAAK,UAAO;QAExD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,oCAAW,GAAlB;QACE,IAAI,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,KAAK;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QAAQ,EAAE;4BAClB,MAAM,IAAI,KAAK,CAAC,qDAA8C,KAAK,CAAE,CAAC,CAAA;yBACvE;;;;;KACF;IACD;;;;;;OAMG;IACW,uCAAc,GAA5B;;;;;;wBACE,IAAI,CAAC,aAAa;4BAAE,aAAa,GAAG,IAAI,6CAAoB,EAAE,CAAA;wBACxD,KAAK,GAAG,UAAG,IAAI,CAAC,WAAW,SAAG,IAAI,CAAC,SAAS,CAAE,CAAA;;;;wBAErC,qBAAM,aAAa,CAAC,IAAI,CAAC,IAAI,8CAAqB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,EAAA;;wBAA/E,IAAI,GAAG,SAAwE;wBACrF,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK;4BAAE,sBAAO,IAAI,CAAC,SAAS,CAAC,KAAU,EAAA;;;;wBAE5E,OAAO,CAAC,KAAK,CAAC,OAAK,CAAC,CAAA;;;wBAEtB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;4BAClB,MAAM,IAAI,KAAK,CAAC,gDAAyC,KAAK,CAAE,CAAC,CAAA;yBAClE;;;;;KACF;IACH,qBAAC;AAAD,CAAC,AAxID,IAwIC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * ${1:Description placeholder}
3
+ *
4
+ * @export
5
+ * @class Crypto
6
+ * @typedef {Crypto}
7
+ */
8
+ export default class Crypto {
9
+ /**
10
+ * ${1:Description placeholder}
11
+ *
12
+ * @private
13
+ * @readonly
14
+ * @type {KMSClient}
15
+ */
16
+ private readonly client;
17
+ /**
18
+ * ${1:Description placeholder}
19
+ *
20
+ * @private
21
+ * @readonly
22
+ * @type {string}
23
+ */
24
+ private readonly region;
25
+ /**
26
+ * ${1:Description placeholder}
27
+ *
28
+ * @private
29
+ * @readonly
30
+ * @type {string}
31
+ */
32
+ private readonly keyId;
33
+ /**
34
+ * Creates an instance of Crypto.
35
+ *
36
+ * @constructor
37
+ * @param {string} region
38
+ * @param {string} keyId
39
+ */
40
+ constructor(region: string, keyId: string);
41
+ /**
42
+ * ${1:Description placeholder}
43
+ *
44
+ * @async
45
+ * @param {(string | any)} data
46
+ * @returns {Promise<string>}
47
+ */
48
+ encryptData(data: string | any): Promise<string>;
49
+ /**
50
+ * ${1:Description placeholder}
51
+ *
52
+ * @async
53
+ * @param {string} data
54
+ * @returns {Promise<string>}
55
+ */
56
+ decryptData(data: string): Promise<string>;
57
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var client_kms_1 = require("@aws-sdk/client-kms");
40
+ /**
41
+ * ${1:Description placeholder}
42
+ *
43
+ * @export
44
+ * @class Crypto
45
+ * @typedef {Crypto}
46
+ */
47
+ var Crypto = /** @class */ (function () {
48
+ /**
49
+ * Creates an instance of Crypto.
50
+ *
51
+ * @constructor
52
+ * @param {string} region
53
+ * @param {string} keyId
54
+ */
55
+ function Crypto(region, keyId) {
56
+ this.region = region;
57
+ this.keyId = keyId;
58
+ this.client = new client_kms_1.KMSClient({ region: this.region });
59
+ }
60
+ //
61
+ /**
62
+ * ${1:Description placeholder}
63
+ *
64
+ * @async
65
+ * @param {(string | any)} data
66
+ * @returns {Promise<string>}
67
+ */
68
+ Crypto.prototype.encryptData = function (data) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var resp, e_1;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ _a.trys.push([0, 2, , 3]);
75
+ return [4 /*yield*/, this.client.send(new client_kms_1.EncryptCommand({
76
+ KeyId: this.keyId,
77
+ EncryptionAlgorithm: 'RSAES_OAEP_SHA_256',
78
+ Plaintext: new TextEncoder().encode(typeof data === 'string' ? data : JSON.stringify(data)),
79
+ }))];
80
+ case 1:
81
+ resp = _a.sent();
82
+ return [2 /*return*/, Buffer.from(resp.CiphertextBlob, 'utf8').toString('hex')];
83
+ case 2:
84
+ e_1 = _a.sent();
85
+ console.error('Encryption failure', e_1);
86
+ return [2 /*return*/, null];
87
+ case 3: return [2 /*return*/];
88
+ }
89
+ });
90
+ });
91
+ };
92
+ /**
93
+ * ${1:Description placeholder}
94
+ *
95
+ * @async
96
+ * @param {string} data
97
+ * @returns {Promise<string>}
98
+ */
99
+ Crypto.prototype.decryptData = function (data) {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ var resp, e_2;
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0:
105
+ _a.trys.push([0, 2, , 3]);
106
+ return [4 /*yield*/, this.client.send(new client_kms_1.DecryptCommand({
107
+ KeyId: this.keyId,
108
+ CiphertextBlob: Buffer.from(data, 'hex'),
109
+ EncryptionAlgorithm: 'RSAES_OAEP_SHA_256',
110
+ }))];
111
+ case 1:
112
+ resp = _a.sent();
113
+ return [2 /*return*/, new TextDecoder().decode(resp.Plaintext)];
114
+ case 2:
115
+ e_2 = _a.sent();
116
+ console.error('Decryption failure', e_2);
117
+ return [2 /*return*/, null];
118
+ case 3: return [2 /*return*/];
119
+ }
120
+ });
121
+ });
122
+ };
123
+ return Crypto;
124
+ }());
125
+ exports.default = Crypto;
126
+ //# sourceMappingURL=Crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA+E;AAE/E;;;;;;GAMG;AACH;IAyBE;;;;;;OAMG;IACH,gBAAY,MAAc,EAAE,KAAa;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,M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ACH,aAAC;AAAD,CAAC,AApFD,IAoFC"}
@@ -0,0 +1,64 @@
1
+ import * as jwt from 'jsonwebtoken';
2
+ /**
3
+ * ${1:Description placeholder}
4
+ *
5
+ * @typedef {JWTValidationResponse}
6
+ */
7
+ type JWTValidationResponse = {
8
+ isValid: true;
9
+ decodedToken: jwt.JwtPayload;
10
+ } | {
11
+ isValid: false;
12
+ isExpired?: boolean;
13
+ };
14
+ /**
15
+ * ${1:Description placeholder}
16
+ *
17
+ * @export
18
+ * @class JWT
19
+ * @typedef {JWT}
20
+ */
21
+ export default class JWT {
22
+ /**
23
+ * ${1:Description placeholder}
24
+ *
25
+ * @private
26
+ * @readonly
27
+ * @type {string}
28
+ */
29
+ private readonly tokenSecret;
30
+ /**
31
+ * ${1:Description placeholder}
32
+ *
33
+ * @private
34
+ * @readonly
35
+ * @type {string}
36
+ */
37
+ private readonly defaultExpiration;
38
+ /**
39
+ * Creates an instance of JWT.
40
+ *
41
+ * @constructor
42
+ * @param {string} tokenSecret
43
+ * @param {?string} [defaultExpiration]
44
+ */
45
+ constructor(tokenSecret: string, defaultExpiration?: string);
46
+ /**
47
+ * ${1:Description placeholder}
48
+ *
49
+ * @param {object} data
50
+ * @param {?string} [expiration]
51
+ * @param {?string} [overrideToken]
52
+ * @param {?*} [opts]
53
+ * @returns {string}
54
+ */
55
+ createToken(data: object, expiration?: string, overrideToken?: string, opts?: any): string;
56
+ /**
57
+ * ${1:Description placeholder}
58
+ *
59
+ * @param {string} token
60
+ * @returns {JWTValidationResponse}
61
+ */
62
+ validateToken(token: string): JWTValidationResponse;
63
+ }
64
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var jwt = require("jsonwebtoken");
15
+ /**
16
+ * ${1:Description placeholder}
17
+ *
18
+ * @export
19
+ * @class JWT
20
+ * @typedef {JWT}
21
+ */
22
+ var JWT = /** @class */ (function () {
23
+ /**
24
+ * Creates an instance of JWT.
25
+ *
26
+ * @constructor
27
+ * @param {string} tokenSecret
28
+ * @param {?string} [defaultExpiration]
29
+ */
30
+ function JWT(tokenSecret, defaultExpiration) {
31
+ this.tokenSecret = tokenSecret;
32
+ this.defaultExpiration = defaultExpiration;
33
+ }
34
+ //
35
+ /**
36
+ * ${1:Description placeholder}
37
+ *
38
+ * @param {object} data
39
+ * @param {?string} [expiration]
40
+ * @param {?string} [overrideToken]
41
+ * @param {?*} [opts]
42
+ * @returns {string}
43
+ */
44
+ JWT.prototype.createToken = function (data, expiration, overrideToken, opts) {
45
+ var exp = expiration || this.defaultExpiration;
46
+ return jwt.sign(data, overrideToken || this.tokenSecret, exp ? __assign({ expiresIn: exp }, (opts || {})) : opts || {});
47
+ };
48
+ /**
49
+ * ${1:Description placeholder}
50
+ *
51
+ * @param {string} token
52
+ * @returns {JWTValidationResponse}
53
+ */
54
+ JWT.prototype.validateToken = function (token) {
55
+ try {
56
+ // Check if is valid
57
+ var isValid = jwt.verify(token, this.tokenSecret);
58
+ if (isValid) {
59
+ var payload = jwt.decode(token, { json: true });
60
+ if (payload)
61
+ return { isValid: true, decodedToken: payload };
62
+ }
63
+ }
64
+ catch (err) {
65
+ console.error(err);
66
+ if (err instanceof jwt.TokenExpiredError)
67
+ return { isValid: false, isExpired: true };
68
+ }
69
+ return { isValid: false };
70
+ };
71
+ return JWT;
72
+ }());
73
+ exports.default = JWT;
74
+ //# sourceMappingURL=JWT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kCAAmC;AAcn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