@creator.co/wapi 1.2.3 → 1.2.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.
Files changed (121) 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 +70 -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 +39 -0
  26. package/dist/src/BaseEvent/Transaction.js +354 -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/Database/Database.d.ts +18 -0
  41. package/dist/src/Database/Database.js +18 -0
  42. package/dist/src/Database/Database.js.map +1 -0
  43. package/dist/src/Database/DatabaseManager.d.ts +32 -0
  44. package/dist/src/Database/DatabaseManager.js +50 -0
  45. package/dist/src/Database/DatabaseManager.js.map +1 -0
  46. package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
  47. package/dist/src/Database/DatabaseTransaction.js +183 -0
  48. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  49. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
  50. package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
  51. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
  52. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
  53. package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
  54. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
  55. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
  56. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
  57. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  58. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
  59. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
  60. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  61. package/dist/src/Globals.d.ts +161 -0
  62. package/dist/src/Globals.js +173 -0
  63. package/dist/src/Globals.js.map +1 -0
  64. package/dist/src/Logger/Logger.d.ts +180 -0
  65. package/dist/src/Logger/Logger.js +412 -0
  66. package/dist/src/Logger/Logger.js.map +1 -0
  67. package/dist/src/Mailer/Mailer.d.ts +107 -0
  68. package/dist/src/Mailer/Mailer.js +313 -0
  69. package/dist/src/Mailer/Mailer.js.map +1 -0
  70. package/dist/src/Publisher/Publisher.d.ts +47 -0
  71. package/dist/src/Publisher/Publisher.js +141 -0
  72. package/dist/src/Publisher/Publisher.js.map +1 -0
  73. package/dist/src/Server/RouteResolver.d.ts +41 -0
  74. package/dist/src/Server/RouteResolver.js +135 -0
  75. package/dist/src/Server/RouteResolver.js.map +1 -0
  76. package/dist/src/Server/Router.d.ts +104 -0
  77. package/dist/src/Server/Router.js +45 -0
  78. package/dist/src/Server/Router.js.map +1 -0
  79. package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
  80. package/dist/src/Server/lib/ContainerServer.js +143 -0
  81. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  82. package/dist/src/Server/lib/Server.d.ts +60 -0
  83. package/dist/src/Server/lib/Server.js +137 -0
  84. package/dist/src/Server/lib/Server.js.map +1 -0
  85. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  86. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  87. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  88. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
  89. package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
  90. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  91. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  92. package/dist/src/Server/lib/container/HealthHandler.js +45 -0
  93. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  94. package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
  95. package/dist/src/Server/lib/container/Proxy.js +202 -0
  96. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  97. package/dist/src/Server/lib/container/Utils.d.ts +18 -0
  98. package/dist/src/Server/lib/container/Utils.js +84 -0
  99. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  100. package/dist/src/Validation/Validator.d.ts +21 -0
  101. package/dist/src/Validation/Validator.js +48 -0
  102. package/dist/src/Validation/Validator.js.map +1 -0
  103. package/jest.config.ts +2 -9
  104. package/package.json +10 -4
  105. package/src/BaseEvent/Transaction.ts +48 -18
  106. package/src/Database/Database.ts +19 -0
  107. package/src/Database/DatabaseManager.ts +51 -0
  108. package/src/Database/DatabaseTransaction.ts +118 -0
  109. package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
  110. package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
  111. package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
  112. package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
  113. package/src/Database/types.d.ts +49 -0
  114. package/src/Server/lib/container/Proxy.ts +2 -1
  115. package/tests/BaseEvent/Transaction.test.ts +59 -0
  116. package/tests/Database/DatabaseManager.test.ts +55 -0
  117. package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
  118. package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
  119. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
  120. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
  121. package/tsconfig.json +5 -0
@@ -0,0 +1,153 @@
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 MemCache = require("node-cache");
40
+ var DurationParser = require("parse-duration");
41
+ var EnvironmentVar_1 = require("./EnvironmentVar");
42
+ // Hold cached values at nodeVM level
43
+ // eslint-disable-next-line no-var
44
+ /**
45
+ * ${1:Description placeholder}
46
+ *
47
+ * @type {*}
48
+ */
49
+ var cacheStore = new MemCache();
50
+ /**
51
+ * ${1:Description placeholder}
52
+ *
53
+ * @export
54
+ * @class Configuration
55
+ * @typedef {Configuration}
56
+ * @template {ConfigurationSchema} T
57
+ */
58
+ var Configuration = /** @class */ (function () {
59
+ /**
60
+ * Creates an instance of Configuration.
61
+ *
62
+ * @constructor
63
+ * @param {T} schema
64
+ * @param {string} remotePrefix
65
+ */
66
+ function Configuration(schema, remotePrefix) {
67
+ this.schema = schema;
68
+ this.remotePrefix = remotePrefix;
69
+ }
70
+ /**
71
+ * ${1:Description placeholder}
72
+ *
73
+ * @public
74
+ * @param {keyof OmitByValueType<ExtractLocal<T>, null>} propName
75
+ * @returns {*}
76
+ */
77
+ Configuration.prototype.get = function (propName) {
78
+ var propString = propName;
79
+ var propSchema = this.schema[propString];
80
+ var v = this.getCachedValue(propString);
81
+ v =
82
+ v ||
83
+ new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.Local, !propSchema.required, this.remotePrefix).syncResolve();
84
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
85
+ return v;
86
+ };
87
+ /**
88
+ * ${1:Description placeholder}
89
+ *
90
+ * @public
91
+ * @async
92
+ * @param {keyof OmitByValueType<ExtractRemote<T>, null>} propName
93
+ * @returns {Promise<any>}
94
+ */
95
+ Configuration.prototype.asyncGet = function (propName) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ var propString, propSchema, v, _a;
98
+ return __generator(this, function (_b) {
99
+ switch (_b.label) {
100
+ case 0:
101
+ propString = propName;
102
+ propSchema = this.schema[propString];
103
+ v = this.getCachedValue(propString);
104
+ _a = v;
105
+ if (_a) return [3 /*break*/, 2];
106
+ return [4 /*yield*/, new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.PlainRemote, !propSchema.required, this.remotePrefix).resolve()];
107
+ case 1:
108
+ _a = (_b.sent());
109
+ _b.label = 2;
110
+ case 2:
111
+ v = _a;
112
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
113
+ return [2 /*return*/, v];
114
+ }
115
+ });
116
+ });
117
+ };
118
+ // caching layer
119
+ /**
120
+ * ${1:Description placeholder}
121
+ *
122
+ * @private
123
+ * @param {string} valueKey
124
+ * @returns {*}
125
+ */
126
+ Configuration.prototype.getCachedValue = function (valueKey) {
127
+ return cacheStore.get(valueKey);
128
+ };
129
+ /**
130
+ * ${1:Description placeholder}
131
+ *
132
+ * @private
133
+ * @param {string} valueKey
134
+ * @param {*} value
135
+ * @param {string} [policy="1d"]
136
+ */
137
+ Configuration.prototype.cacheValue = function (valueKey, value, policy) {
138
+ if (policy === void 0) { policy = '1d'; }
139
+ cacheStore.set(valueKey, value, DurationParser(policy, 's'));
140
+ };
141
+ // unit-test support
142
+ /**
143
+ * ${1:Description placeholder}
144
+ *
145
+ * @private
146
+ */
147
+ Configuration.prototype.resetCache = function () {
148
+ cacheStore = new MemCache();
149
+ };
150
+ return Configuration;
151
+ }());
152
+ exports.default = Configuration;
153
+ //# sourceMappingURL=Configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,kCAAkC;AAClC;;;;GAIG;AACH,IAAI,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AAwE/B;;;;;;;GAOG;AACH;IAiBE;;;;;;OAMG;IACH,uBAAY,MAAS,EAAE,YAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED;;;;;;OAMG;IACI,2BAAG,GAAV,UAAW,QAAsD;QAC/D,IAAM,UAAU,GAAG,QAAkB,CAAA;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAC1C,IAAI,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;QACvC,CAAC;YACC,CAAC;gBACD,IAAI,wBAAc,CAChB,UAAU,EACV,gCAAe,CAAC,KAAK,EACrB,CAAC,UAAU,CAAC,QAAQ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AAD,CAAC,AAzGD,IAyGC"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * ${1:Description placeholder}
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export declare enum EnvironmentType {
8
+ PlainRemote = 0,
9
+ SecureRemote = 1,
10
+ Local = 2
11
+ }
12
+ /**
13
+ * ${1:Description placeholder}
14
+ *
15
+ * @export
16
+ * @class EnvironmentVar
17
+ * @typedef {EnvironmentVar}
18
+ * @template T
19
+ */
20
+ export default class EnvironmentVar<T> {
21
+ /**
22
+ * ${1:Description placeholder}
23
+ *
24
+ * @private
25
+ * @readonly
26
+ * @type {string}
27
+ */
28
+ private readonly paramName;
29
+ /**
30
+ * ${1:Description placeholder}
31
+ *
32
+ * @private
33
+ * @readonly
34
+ * @type {EnvironmentType}
35
+ */
36
+ private readonly type;
37
+ /**
38
+ * ${1:Description placeholder}
39
+ *
40
+ * @private
41
+ * @readonly
42
+ * @type {boolean}
43
+ */
44
+ private readonly optional;
45
+ /**
46
+ * ${1:Description placeholder}
47
+ *
48
+ * @private
49
+ * @readonly
50
+ * @type {string}
51
+ */
52
+ private readonly paramPrefix;
53
+ /**
54
+ * Creates an instance of EnvironmentVar.
55
+ *
56
+ * @constructor
57
+ * @param {string} paramName
58
+ * @param {EnvironmentType} type
59
+ * @param {?boolean} [optional]
60
+ * @param {string} [paramPrefix=`/creatorco-api-\${process.env.STAGE\}/env/`]
61
+ */
62
+ constructor(paramName: string, type: EnvironmentType, optional?: boolean, paramPrefix?: string);
63
+ /**
64
+ * ${1:Description placeholder}
65
+ *
66
+ * @public
67
+ * @returns {T}
68
+ */
69
+ syncResolve(): T;
70
+ /**
71
+ * ${1:Description placeholder}
72
+ *
73
+ * @public
74
+ * @async
75
+ * @returns {unknown}
76
+ */
77
+ resolve(): Promise<T>;
78
+ /**
79
+ * ${1:Description placeholder}
80
+ *
81
+ * @private
82
+ * @returns {T}
83
+ */
84
+ private getLocalValue;
85
+ /**
86
+ * ${1:Description placeholder}
87
+ *
88
+ * @private
89
+ * @async
90
+ * @returns {Promise<T>}
91
+ */
92
+ private getPlainValue;
93
+ /**
94
+ * ${1:Description placeholder}
95
+ *
96
+ * @private
97
+ * @async
98
+ * @returns {Promise<T>}
99
+ */
100
+ private getSecureValue;
101
+ }
@@ -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;YAAE,OAAO,IAAI,CAAC,aAAa,EAAE,CAAA;aAC9D;YACH,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAA;SACF;IACH,CAAC;IACD;;;;;;OAMG;IACU,gCAAO,GAApB;;;gBACE,IAAI,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,KAAK;oBAAE,sBAAO,IAAI,CAAC,aA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AI,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,MAAM,GAAG,IAAI,sBAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,EAAE;IACF;;;;;;OAMG;IACG,4BAAW,GAAjB,UAAkB,IAAkB;;;;;;;wBAEnB,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,2BAAc,CAA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