@creator.co/wapi 1.2.4 → 1.2.6
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/.github/workflows/npmpublish.yml +1 -1
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +13 -2
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +104 -2
- package/dist/src/BaseEvent/Transaction.js +196 -41
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +52 -52
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/jest.config.ts +1 -1
- package/package.json +13 -2
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +147 -27
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +39 -58
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +102 -44
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +6 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
2
|
+
* An enumeration representing different types of environments.
|
|
5
3
|
* @enum {number}
|
|
4
|
+
* @readonly
|
|
5
|
+
* @property {number} PlainRemote - Represents a plain remote environment.
|
|
6
|
+
* @property {number} SecureRemote - Represents a secure remote environment.
|
|
7
|
+
* @property {number} Local - Represents a local environment.
|
|
6
8
|
*/
|
|
7
9
|
export declare enum EnvironmentType {
|
|
8
10
|
PlainRemote = 0,
|
|
@@ -10,92 +12,63 @@ export declare enum EnvironmentType {
|
|
|
10
12
|
Local = 2
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @export
|
|
16
|
-
* @class EnvironmentVar
|
|
17
|
-
* @typedef {EnvironmentVar}
|
|
18
|
-
* @template T
|
|
15
|
+
* Represents an environment variable with methods to resolve its value based on the environment type.
|
|
16
|
+
* @template T - The type of the environment variable value.
|
|
19
17
|
*/
|
|
20
18
|
export default class EnvironmentVar<T> {
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @private
|
|
25
|
-
* @readonly
|
|
26
|
-
* @type {string}
|
|
20
|
+
* The name of the parameter.
|
|
27
21
|
*/
|
|
28
22
|
private readonly paramName;
|
|
29
23
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
24
|
+
* The type of environment.
|
|
33
25
|
* @readonly
|
|
34
|
-
* @type {EnvironmentType}
|
|
35
26
|
*/
|
|
36
27
|
private readonly type;
|
|
37
28
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @private
|
|
41
|
-
* @readonly
|
|
42
|
-
* @type {boolean}
|
|
29
|
+
* A boolean flag indicating whether the field is optional or not.
|
|
43
30
|
*/
|
|
44
31
|
private readonly optional;
|
|
45
32
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @private
|
|
49
|
-
* @readonly
|
|
33
|
+
* The prefix used for parameters in the class.
|
|
50
34
|
* @type {string}
|
|
51
35
|
*/
|
|
52
36
|
private readonly paramPrefix;
|
|
53
37
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {?boolean} [optional]
|
|
60
|
-
* @param {string} [paramPrefix=`/creatorco-api-\${process.env.STAGE\}/env/`]
|
|
38
|
+
* Constructs a new instance of the EnvironmentVar class.
|
|
39
|
+
* @param {string} paramName - The name of the environment variable.
|
|
40
|
+
* @param {EnvironmentType} type - The type of the environment.
|
|
41
|
+
* @param {boolean} [optional] - Indicates whether the environment variable is optional.
|
|
42
|
+
* @param {string} [paramPrefix] - The prefix to be added to the environment variable name.
|
|
61
43
|
*/
|
|
62
44
|
constructor(paramName: string, type: EnvironmentType, optional?: boolean, paramPrefix?: string);
|
|
63
45
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
* @returns {T}
|
|
46
|
+
* Resolves the value of the environment variable synchronously.
|
|
47
|
+
* @returns {T} - The resolved value of the environment variable.
|
|
48
|
+
* @throws {Error} - If the environment type is not 'Local'.
|
|
68
49
|
*/
|
|
69
50
|
syncResolve(): T;
|
|
70
51
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
* @async
|
|
75
|
-
* @returns {unknown}
|
|
52
|
+
* Resolves the value based on the environment type.
|
|
53
|
+
* @returns {Promise<any>} - The resolved value.
|
|
76
54
|
*/
|
|
77
55
|
resolve(): Promise<T>;
|
|
78
56
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
* @returns {T}
|
|
57
|
+
* Retrieves the value of a local environment variable.
|
|
58
|
+
* @returns {T} - The value of the local environment variable.
|
|
59
|
+
* @throws {Error} - If the local environment variable is not defined and is not optional.
|
|
83
60
|
*/
|
|
84
61
|
private getLocalValue;
|
|
85
62
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
89
|
-
* @async
|
|
90
|
-
* @returns {Promise<T>}
|
|
63
|
+
* Retrieves the plain value of a remote environment parameter.
|
|
64
|
+
* @returns {Promise<T>} - A promise that resolves to the plain value of the parameter.
|
|
65
|
+
* @throws {Error} - If the parameter cannot be retrieved and is not optional.
|
|
91
66
|
*/
|
|
92
67
|
private getPlainValue;
|
|
93
68
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
* @async
|
|
98
|
-
* @returns {Promise<T>}
|
|
69
|
+
* Retrieves a secure value from the secrets manager.
|
|
70
|
+
* @returns {Promise<T>} - A promise that resolves to the secure value.
|
|
71
|
+
* @throws {Error} - Throws an error if the secure value cannot be retrieved and is not optional.
|
|
99
72
|
*/
|
|
100
73
|
private getSecureValue;
|
|
101
74
|
}
|
|
@@ -49,10 +49,12 @@ var client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
|
49
49
|
*/
|
|
50
50
|
var ssmClient = null, secretsClient = null;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @export
|
|
52
|
+
* An enumeration representing different types of environments.
|
|
55
53
|
* @enum {number}
|
|
54
|
+
* @readonly
|
|
55
|
+
* @property {number} PlainRemote - Represents a plain remote environment.
|
|
56
|
+
* @property {number} SecureRemote - Represents a secure remote environment.
|
|
57
|
+
* @property {number} Local - Represents a local environment.
|
|
56
58
|
*/
|
|
57
59
|
var EnvironmentType;
|
|
58
60
|
(function (EnvironmentType) {
|
|
@@ -61,22 +63,16 @@ var EnvironmentType;
|
|
|
61
63
|
EnvironmentType[EnvironmentType["Local"] = 2] = "Local";
|
|
62
64
|
})(EnvironmentType || (exports.EnvironmentType = EnvironmentType = {}));
|
|
63
65
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @export
|
|
67
|
-
* @class EnvironmentVar
|
|
68
|
-
* @typedef {EnvironmentVar}
|
|
69
|
-
* @template T
|
|
66
|
+
* Represents an environment variable with methods to resolve its value based on the environment type.
|
|
67
|
+
* @template T - The type of the environment variable value.
|
|
70
68
|
*/
|
|
71
69
|
var EnvironmentVar = /** @class */ (function () {
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
76
|
-
* @param {
|
|
77
|
-
* @param {
|
|
78
|
-
* @param {?boolean} [optional]
|
|
79
|
-
* @param {string} [paramPrefix=`/creatorco-api-\${process.env.STAGE\}/env/`]
|
|
71
|
+
* Constructs a new instance of the EnvironmentVar class.
|
|
72
|
+
* @param {string} paramName - The name of the environment variable.
|
|
73
|
+
* @param {EnvironmentType} type - The type of the environment.
|
|
74
|
+
* @param {boolean} [optional] - Indicates whether the environment variable is optional.
|
|
75
|
+
* @param {string} [paramPrefix] - The prefix to be added to the environment variable name.
|
|
80
76
|
*/
|
|
81
77
|
function EnvironmentVar(paramName, type, optional, paramPrefix /* only allowed process.env */) {
|
|
82
78
|
if (paramPrefix === void 0) { paramPrefix = "/creatorco-api-".concat(process.env.STAGE, "/env/"); }
|
|
@@ -86,10 +82,9 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
86
82
|
this.paramPrefix = paramPrefix;
|
|
87
83
|
}
|
|
88
84
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
92
|
-
* @returns {T}
|
|
85
|
+
* Resolves the value of the environment variable synchronously.
|
|
86
|
+
* @returns {T} - The resolved value of the environment variable.
|
|
87
|
+
* @throws {Error} - If the environment type is not 'Local'.
|
|
93
88
|
*/
|
|
94
89
|
EnvironmentVar.prototype.syncResolve = function () {
|
|
95
90
|
if (this.type == EnvironmentType.Local)
|
|
@@ -99,11 +94,8 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
99
94
|
}
|
|
100
95
|
};
|
|
101
96
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @public
|
|
105
|
-
* @async
|
|
106
|
-
* @returns {unknown}
|
|
97
|
+
* Resolves the value based on the environment type.
|
|
98
|
+
* @returns {Promise<any>} - The resolved value.
|
|
107
99
|
*/
|
|
108
100
|
EnvironmentVar.prototype.resolve = function () {
|
|
109
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -119,10 +111,9 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
119
111
|
});
|
|
120
112
|
};
|
|
121
113
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @
|
|
125
|
-
* @returns {T}
|
|
114
|
+
* Retrieves the value of a local environment variable.
|
|
115
|
+
* @returns {T} - The value of the local environment variable.
|
|
116
|
+
* @throws {Error} - If the local environment variable is not defined and is not optional.
|
|
126
117
|
*/
|
|
127
118
|
EnvironmentVar.prototype.getLocalValue = function () {
|
|
128
119
|
var value = process.env[this.paramName];
|
|
@@ -132,11 +123,9 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
132
123
|
return value;
|
|
133
124
|
};
|
|
134
125
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
138
|
-
* @async
|
|
139
|
-
* @returns {Promise<T>}
|
|
126
|
+
* Retrieves the plain value of a remote environment parameter.
|
|
127
|
+
* @returns {Promise<T>} - A promise that resolves to the plain value of the parameter.
|
|
128
|
+
* @throws {Error} - If the parameter cannot be retrieved and is not optional.
|
|
140
129
|
*/
|
|
141
130
|
EnvironmentVar.prototype.getPlainValue = function () {
|
|
142
131
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -170,11 +159,9 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
170
159
|
});
|
|
171
160
|
};
|
|
172
161
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* @
|
|
176
|
-
* @async
|
|
177
|
-
* @returns {Promise<T>}
|
|
162
|
+
* Retrieves a secure value from the secrets manager.
|
|
163
|
+
* @returns {Promise<T>} - A promise that resolves to the secure value.
|
|
164
|
+
* @throws {Error} - Throws an error if the secure value cannot be retrieved and is not optional.
|
|
178
165
|
*/
|
|
179
166
|
EnvironmentVar.prototype.getSecureValue = function () {
|
|
180
167
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -191,8 +178,8 @@ var EnvironmentVar = /** @class */ (function () {
|
|
|
191
178
|
return [4 /*yield*/, secretsClient.send(new client_secrets_manager_1.GetSecretValueCommand({ SecretId: pName }))];
|
|
192
179
|
case 2:
|
|
193
180
|
data = _a.sent();
|
|
194
|
-
if (data.
|
|
195
|
-
return [2 /*return*/, data.
|
|
181
|
+
if (data.SecretString)
|
|
182
|
+
return [2 /*return*/, data.SecretString];
|
|
196
183
|
return [3 /*break*/, 4];
|
|
197
184
|
case 3:
|
|
198
185
|
error_2 = _a.sent();
|
|
@@ -1 +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,
|
|
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,GAAqB,IAAI,EACpC,aAAa,GAAgC,IAAI,CAAA;AAEnD;;;;;;;GAOG;AACH,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,m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;AAAD,CAAC,AAnHD,IAmHC"}
|
|
@@ -1,57 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @class Crypto
|
|
6
|
-
* @typedef {Crypto}
|
|
2
|
+
* Represents a Crypto class that provides encryption and decryption functionality using AWS KMS.
|
|
7
3
|
*/
|
|
8
4
|
export default class Crypto {
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @private
|
|
13
|
-
* @readonly
|
|
14
|
-
* @type {KMSClient}
|
|
6
|
+
* The KMSClient instance used for making requests to the Key Management Service (KMS).
|
|
15
7
|
*/
|
|
16
8
|
private readonly client;
|
|
17
9
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @private
|
|
21
|
-
* @readonly
|
|
22
|
-
* @type {string}
|
|
10
|
+
* The AWS region of the object. This property is readonly and cannot be modified once set.
|
|
23
11
|
*/
|
|
24
12
|
private readonly region;
|
|
25
13
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @private
|
|
14
|
+
* The unique identifier for the KMS.
|
|
29
15
|
* @readonly
|
|
30
16
|
* @type {string}
|
|
31
17
|
*/
|
|
32
18
|
private readonly keyId;
|
|
33
19
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
* @param {string} keyId
|
|
20
|
+
* Constructs a new instance of the KMSClient class.
|
|
21
|
+
* @param {string} region - The AWS region to use for the client.
|
|
22
|
+
* @param {string} keyId - The AWS KMS key ID to use for encryption and decryption operations.
|
|
23
|
+
* @returns None
|
|
39
24
|
*/
|
|
40
25
|
constructor(region: string, keyId: string);
|
|
41
26
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @
|
|
45
|
-
* @param {(string | any)} data
|
|
46
|
-
* @returns {Promise<string>}
|
|
27
|
+
* Encrypts the given data using RSAES_OAEP_SHA_256 encryption algorithm.
|
|
28
|
+
* @param {string | any} data - The data to be encrypted.
|
|
29
|
+
* @returns {Promise<string | null>} - A promise that resolves to the encrypted data as a hexadecimal string.
|
|
47
30
|
*/
|
|
48
|
-
encryptData(data: string | any): Promise<string>;
|
|
31
|
+
encryptData(data: string | any): Promise<string | null>;
|
|
49
32
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
*
|
|
54
|
-
* @returns {Promise<string>}
|
|
33
|
+
* Decrypts the given data using the RSAES_OAEP_SHA_256 encryption algorithm.
|
|
34
|
+
* @param {string} data - The encrypted data to decrypt.
|
|
35
|
+
* @returns {Promise<string | null>} - A promise that resolves to the decrypted plaintext string.
|
|
36
|
+
* If decryption fails, null is returned.
|
|
55
37
|
*/
|
|
56
|
-
decryptData(data: string): Promise<string>;
|
|
38
|
+
decryptData(data: string): Promise<string | null>;
|
|
57
39
|
}
|
|
@@ -38,32 +38,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var client_kms_1 = require("@aws-sdk/client-kms");
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @export
|
|
44
|
-
* @class Crypto
|
|
45
|
-
* @typedef {Crypto}
|
|
41
|
+
* Represents a Crypto class that provides encryption and decryption functionality using AWS KMS.
|
|
46
42
|
*/
|
|
47
43
|
var Crypto = /** @class */ (function () {
|
|
48
44
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @
|
|
53
|
-
* @param {string} keyId
|
|
45
|
+
* Constructs a new instance of the KMSClient class.
|
|
46
|
+
* @param {string} region - The AWS region to use for the client.
|
|
47
|
+
* @param {string} keyId - The AWS KMS key ID to use for encryption and decryption operations.
|
|
48
|
+
* @returns None
|
|
54
49
|
*/
|
|
55
50
|
function Crypto(region, keyId) {
|
|
56
51
|
this.region = region;
|
|
57
52
|
this.keyId = keyId;
|
|
58
53
|
this.client = new client_kms_1.KMSClient({ region: this.region });
|
|
59
54
|
}
|
|
60
|
-
//
|
|
61
55
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
* @param {(string | any)} data
|
|
66
|
-
* @returns {Promise<string>}
|
|
56
|
+
* Encrypts the given data using RSAES_OAEP_SHA_256 encryption algorithm.
|
|
57
|
+
* @param {string | any} data - The data to be encrypted.
|
|
58
|
+
* @returns {Promise<string | null>} - A promise that resolves to the encrypted data as a hexadecimal string.
|
|
67
59
|
*/
|
|
68
60
|
Crypto.prototype.encryptData = function (data) {
|
|
69
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -90,11 +82,10 @@ var Crypto = /** @class */ (function () {
|
|
|
90
82
|
});
|
|
91
83
|
};
|
|
92
84
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @
|
|
96
|
-
*
|
|
97
|
-
* @returns {Promise<string>}
|
|
85
|
+
* Decrypts the given data using the RSAES_OAEP_SHA_256 encryption algorithm.
|
|
86
|
+
* @param {string} data - The encrypted data to decrypt.
|
|
87
|
+
* @returns {Promise<string | null>} - A promise that resolves to the decrypted plaintext string.
|
|
88
|
+
* If decryption fails, null is returned.
|
|
98
89
|
*/
|
|
99
90
|
Crypto.prototype.decryptData = function (data) {
|
|
100
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA+E;AAE/E
|
|
1
|
+
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA+E;AAE/E;;GAEG;AACH;I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,IAAI,CAAC,SAAS,CAAC,EAAA;;;wBAE/C,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAC,CAAC,CAAA;wBACtC,sBAAO,IAAI,EAAA;;;;;KAEd;IACH,aAAC;AAAD,CAAC,AAxED,IAwEC"}
|
package/dist/src/Crypto/JWT.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as jwt from 'jsonwebtoken';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
3
|
+
* Represents the response of a JWT validation.
|
|
4
|
+
* @typedef {Object} JWTValidationResponse
|
|
5
|
+
* @property {boolean} isValid - Indicates whether the JWT is valid or not.
|
|
6
|
+
* @property {jwt.JwtPayload} [decodedToken] - The decoded JWT payload if the JWT is valid.
|
|
7
|
+
* @property {boolean} [isExpired] - Indicates whether the JWT is expired or not, only present if isValid is false.
|
|
6
8
|
*/
|
|
7
9
|
type JWTValidationResponse = {
|
|
8
10
|
isValid: true;
|
|
@@ -12,52 +14,39 @@ type JWTValidationResponse = {
|
|
|
12
14
|
isExpired?: boolean;
|
|
13
15
|
};
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @export
|
|
18
|
-
* @class JWT
|
|
19
|
-
* @typedef {JWT}
|
|
17
|
+
* Represents a JSON Web Token (JWT) utility class.
|
|
20
18
|
*/
|
|
21
19
|
export default class JWT {
|
|
22
20
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
* @readonly
|
|
21
|
+
* The secret key used for generating and verifying tokens.
|
|
27
22
|
* @type {string}
|
|
28
23
|
*/
|
|
29
24
|
private readonly tokenSecret;
|
|
30
25
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @private
|
|
34
|
-
* @readonly
|
|
26
|
+
* The default expiration time for a cache entry.
|
|
35
27
|
* @type {string}
|
|
36
28
|
*/
|
|
37
29
|
private readonly defaultExpiration;
|
|
38
30
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @param {?string} [defaultExpiration]
|
|
31
|
+
* Constructs a new instance of the class.
|
|
32
|
+
* @param {string} tokenSecret - The secret used to sign the tokens.
|
|
33
|
+
* @param {string} [defaultExpiration] - The default expiration time for the tokens.
|
|
34
|
+
* @returns None
|
|
44
35
|
*/
|
|
45
36
|
constructor(tokenSecret: string, defaultExpiration?: string);
|
|
46
37
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param {
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {
|
|
52
|
-
* @
|
|
53
|
-
* @returns {string}
|
|
38
|
+
* Creates a JSON Web Token (JWT) using the provided data and options.
|
|
39
|
+
* @param {object} data - The data to be included in the token payload.
|
|
40
|
+
* @param {string} [expiration] - The expiration time for the token. If not provided, the default expiration time will be used.
|
|
41
|
+
* @param {string} [overrideToken] - An optional token secret to override the default token secret.
|
|
42
|
+
* @param {any} [opts] - Additional options to be passed to the jwt.sign() function.
|
|
43
|
+
* @returns {string} - The generated JWT.
|
|
54
44
|
*/
|
|
55
45
|
createToken(data: object, expiration?: string, overrideToken?: string, opts?: any): string;
|
|
56
46
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @returns {JWTValidationResponse}
|
|
47
|
+
* Validates a JSON Web Token (JWT) and returns the validation response.
|
|
48
|
+
* @param {string} token - The JWT to validate.
|
|
49
|
+
* @returns {JWTValidationResponse} - The validation response object.
|
|
61
50
|
*/
|
|
62
51
|
validateToken(token: string): JWTValidationResponse;
|
|
63
52
|
}
|
package/dist/src/Crypto/JWT.js
CHANGED
|
@@ -13,43 +13,35 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
var jwt = require("jsonwebtoken");
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @export
|
|
19
|
-
* @class JWT
|
|
20
|
-
* @typedef {JWT}
|
|
16
|
+
* Represents a JSON Web Token (JWT) utility class.
|
|
21
17
|
*/
|
|
22
18
|
var JWT = /** @class */ (function () {
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
* @
|
|
28
|
-
* @param {?string} [defaultExpiration]
|
|
20
|
+
* Constructs a new instance of the class.
|
|
21
|
+
* @param {string} tokenSecret - The secret used to sign the tokens.
|
|
22
|
+
* @param {string} [defaultExpiration] - The default expiration time for the tokens.
|
|
23
|
+
* @returns None
|
|
29
24
|
*/
|
|
30
25
|
function JWT(tokenSecret, defaultExpiration) {
|
|
31
26
|
this.tokenSecret = tokenSecret;
|
|
32
27
|
this.defaultExpiration = defaultExpiration;
|
|
33
28
|
}
|
|
34
|
-
//
|
|
35
29
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {
|
|
41
|
-
* @
|
|
42
|
-
* @returns {string}
|
|
30
|
+
* Creates a JSON Web Token (JWT) using the provided data and options.
|
|
31
|
+
* @param {object} data - The data to be included in the token payload.
|
|
32
|
+
* @param {string} [expiration] - The expiration time for the token. If not provided, the default expiration time will be used.
|
|
33
|
+
* @param {string} [overrideToken] - An optional token secret to override the default token secret.
|
|
34
|
+
* @param {any} [opts] - Additional options to be passed to the jwt.sign() function.
|
|
35
|
+
* @returns {string} - The generated JWT.
|
|
43
36
|
*/
|
|
44
37
|
JWT.prototype.createToken = function (data, expiration, overrideToken, opts) {
|
|
45
38
|
var exp = expiration || this.defaultExpiration;
|
|
46
39
|
return jwt.sign(data, overrideToken || this.tokenSecret, exp ? __assign({ expiresIn: exp }, (opts || {})) : opts || {});
|
|
47
40
|
};
|
|
48
41
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @returns {JWTValidationResponse}
|
|
42
|
+
* Validates a JSON Web Token (JWT) and returns the validation response.
|
|
43
|
+
* @param {string} token - The JWT to validate.
|
|
44
|
+
* @returns {JWTValidationResponse} - The validation response object.
|
|
53
45
|
*/
|
|
54
46
|
JWT.prototype.validateToken = function (token) {
|
|
55
47
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kCAAmC;
|
|
1
|
+
{"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kCAAmC;AAgBnC;;GAEG;AACH;IAYE;;;;;OAKG;IACH,aAAY,WAAmB,EAAE,iBAA0B;QACzD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED;;;;;;;OAOG;IACI,yBAAW,GAAlB,UACE,IAAY,EACZ,UAAmB,EACnB,aAAsB,EACtB,IAAU;QAEV,IAAM,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,iBAAiB,CAAA;QAChD,OAAO,GAAG,CAAC,IAAI,CACb,IAAI,EACJ,aAAa,IAAI,IAAI,CAAC,WAAW,EACjC,GAAG,CAAC,CAAC,YAAG,SAAS,EAAE,GAAG,IAAK,CAAC,IAAI,IAAI,EAAE,CAAC,EAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CACvD,CAAA;IACH,CAAC;IAED;;;;OAIG;IACI,2BAAa,GAApB,UAAqB,KAAa;QAChC,IAAI;YACF,oBAAoB;YACpB,IAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YACnD,IAAI,OAAO,EAAE;gBACX,IAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;gBACjD,IAAI,OAAO;oBAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;aAC7D;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAClB,IAAI,GAAG,YAAY,GAAG,CAAC,iBAAiB;gBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;SACrF;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IAC3B,CAAC;IACH,UAAC;AAAD,CAAC,AAhED,IAgEC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DatabaseTransaction } from './DatabaseTransaction';
|
|
2
|
+
import type { DbConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract class representing a database.
|
|
5
|
+
* @template T - The type of database transaction.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Database<T extends DatabaseTransaction> {
|
|
8
|
+
readonly config: DbConfig<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a database instance, maintaining a reference to the database configuration.
|
|
11
|
+
*/
|
|
12
|
+
protected constructor(config: DbConfig<any>);
|
|
13
|
+
/**
|
|
14
|
+
* Returns a promise resolving to a new instance of the transaction impl.
|
|
15
|
+
* @returns A promise that resolves to a transaction instance.
|
|
16
|
+
*/
|
|
17
|
+
abstract transaction(): Promise<T>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Database = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract class representing a database.
|
|
6
|
+
* @template T - The type of database transaction.
|
|
7
|
+
*/
|
|
8
|
+
var Database = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a database instance, maintaining a reference to the database configuration.
|
|
11
|
+
*/
|
|
12
|
+
function Database(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
return Database;
|
|
16
|
+
}());
|
|
17
|
+
exports.Database = Database;
|
|
18
|
+
//# sourceMappingURL=Database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../../../src/Database/Database.ts"],"names":[],"mappings":";;;AAGA;;;GAGG;AACH;IACE;;OAEG;IACH,kBAAsC,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAOjE,eAAC;AAAD,CAAC,AAXD,IAWC;AAXqB,4BAAQ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { KnexDatabase } from './integrations/knex/KnexDatabase';
|
|
2
|
+
import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase';
|
|
3
|
+
import type { DatabaseImplType, DatabaseType, DbConfig } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* An object that maps database names to their corresponding database classes.
|
|
6
|
+
* @type {Object}
|
|
7
|
+
* @property {KnexDatabase} knex - The Knex database class.
|
|
8
|
+
* @property {PostgresDatabase} pg - The Postgres database class.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DATABASES: {
|
|
11
|
+
knex: typeof KnexDatabase;
|
|
12
|
+
pg: typeof PostgresDatabase;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A class that manages databases and provides methods for creating and accessing database instances.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DatabaseManager {
|
|
18
|
+
/**
|
|
19
|
+
* The singleton instance of the DatabaseManager class.
|
|
20
|
+
*/
|
|
21
|
+
static readonly INSTANCE: DatabaseManager;
|
|
22
|
+
private databases;
|
|
23
|
+
private instances;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new instance of a database based on the provided configuration.
|
|
26
|
+
* @param {DbConfig<S>} config - The configuration object for the database.
|
|
27
|
+
* @returns {DatabaseImplType<S>} - The created database instance.
|
|
28
|
+
* @template S - The type of the database.
|
|
29
|
+
*/
|
|
30
|
+
create<S extends DatabaseType>(config: DbConfig<S>): DatabaseImplType<S>;
|
|
31
|
+
private instantiateDb;
|
|
32
|
+
}
|