@creator.co/wapi 1.6.1 → 1.7.1-alpha1
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/.eslintignore +2 -1
- package/.github/workflows/npmpublish.yml +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/package-lock.json +11786 -0
- package/dist/package.json +24 -22
- package/dist/src/API/Request.js +53 -59
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.js +81 -156
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +54 -132
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.js +40 -98
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.js +122 -310
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Cache/Redis.js +55 -119
- package/dist/src/Cache/Redis.js.map +1 -1
- package/dist/src/Cache/types.js +1 -2
- package/dist/src/Config/Configuration.js +46 -86
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js +57 -119
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.js +35 -82
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +1 -1
- package/dist/src/Crypto/JWT.js +12 -27
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.js +3 -8
- package/dist/src/Database/Database.js.map +1 -1
- package/dist/src/Database/DatabaseManager.js +23 -28
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/DatabaseTransaction.js +50 -166
- package/dist/src/Database/DatabaseTransaction.js.map +1 -1
- package/dist/src/Database/index.js +11 -15
- package/dist/src/Database/index.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +3 -3
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +9 -9
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
- package/dist/src/Database/types.js +1 -2
- package/dist/src/Globals.js +93 -98
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +88 -222
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +1 -1
- package/dist/src/Mailer/Mailer.js +83 -204
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.js +43 -107
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.js +22 -49
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +1 -1
- package/dist/src/Server/Router.js +12 -16
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +21 -83
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.js +50 -99
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.js +32 -107
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.js +3 -35
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.js +66 -127
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.js +12 -55
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Util/AsyncSingleton.js +40 -164
- package/dist/src/Util/AsyncSingleton.js.map +1 -1
- package/dist/src/Util/Utils.js +18 -24
- package/dist/src/Util/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.js +10 -16
- package/dist/src/Validation/Validator.js.map +1 -1
- package/jest.config.ts +1 -0
- package/jest.smoke.config.ts +35 -0
- package/package.json +24 -22
- package/src/Config/Configuration.ts +2 -2
- package/src/Crypto/JWT.ts +1 -1
- package/src/Database/DatabaseManager.ts +1 -1
- package/src/Database/integrations/knex/KnexDatabase.ts +1 -1
- package/src/Database/integrations/kysely/KyselyDatabase.ts +2 -2
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +4 -4
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +8 -8
- package/src/Globals.ts +1 -1
- package/src/Logger/Logger.ts +3 -3
- package/src/Mailer/Mailer.ts +3 -3
- package/src/Publisher/Publisher.ts +1 -1
- package/src/Server/Router.ts +1 -1
- package/src/Server/lib/container/GenericHandlerEvent.ts +1 -1
- package/src/Server/lib/container/Proxy.ts +6 -3
- package/tests/API/Response.test.ts +1 -0
- package/tests/BaseEvent/Transaction.test.ts +1 -0
- package/tests/Cache/Redis-client.test.ts +2 -0
- package/tests/Cache/Redis-cluster.test.ts +2 -0
- package/tests/Database/DatabaseManager.test.ts +4 -3
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +1 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +1 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +4 -3
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +2 -1
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +3 -2
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +4 -3
- package/tests/Logger/Logger.test.ts +6 -3
- package/tests/Server/Router.test.ts +1 -0
- package/tests/Server/lib/ContainerServer.test.ts +2 -1
- package/tests/Server/lib/container/GenericHandler.test.ts +1 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +1 -0
- package/tests/Server/lib/container/Proxy.test.ts +2 -1
- package/tests/Test.utils.ts +2 -1
- package/tsconfig.json +6 -2
- package/tsconfig.smoke.json +26 -0
- package/dist/jest.config.d.ts +0 -3
- package/dist/jest.config.js +0 -34
- package/dist/jest.config.js.map +0 -1
- package/tests/main.test.ts +0 -15
package/dist/src/Util/Utils.js
CHANGED
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Utility class containing various static methods for common operations.
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
function Utils() {
|
|
8
|
-
}
|
|
4
|
+
export default class Utils {
|
|
9
5
|
/**
|
|
10
6
|
* Checks if the application is running in a hybridless container.
|
|
11
7
|
* @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
|
|
12
8
|
*/
|
|
13
|
-
|
|
9
|
+
static isHybridlessContainer() {
|
|
14
10
|
return process.env.HYBRIDLESS_RUNTIME == 'true';
|
|
15
|
-
}
|
|
11
|
+
}
|
|
16
12
|
/**
|
|
17
13
|
* Checks if a given string is valid.
|
|
18
14
|
* @param {string} string - The string to check.
|
|
19
15
|
* @returns {boolean} - True if the string is valid, false otherwise.
|
|
20
16
|
*/
|
|
21
|
-
|
|
17
|
+
static isValidString(string) {
|
|
22
18
|
return (string === null || string === void 0 ? void 0 : string.length) > 0 && !Array.isArray(string);
|
|
23
|
-
}
|
|
19
|
+
}
|
|
24
20
|
/**
|
|
25
21
|
* Parses a string into an integer and returns null if the string is not a valid number.
|
|
26
22
|
* @param {string} str - The string to parse into an integer.
|
|
27
23
|
* @returns {number | null} - The parsed integer or null if the string is not a valid number.
|
|
28
24
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
static parseIntNullIfNaN(str) {
|
|
26
|
+
const n = parseInt(str || '');
|
|
31
27
|
return isNaN(n) ? null : n;
|
|
32
|
-
}
|
|
28
|
+
}
|
|
33
29
|
/**
|
|
34
30
|
* Parses a JSON string and returns the resulting object. If the string is empty or
|
|
35
31
|
* cannot be parsed, null is returned.
|
|
36
32
|
* @param {string} string - The JSON string to parse.
|
|
37
33
|
* @returns {any | null} - The parsed object or null if the string is empty or invalid.
|
|
38
34
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
static parseObjectNullIfEmpty(string) {
|
|
36
|
+
let o = null;
|
|
41
37
|
try {
|
|
42
38
|
o = string ? JSON.parse(string) : null;
|
|
43
39
|
if (o && Object.keys(o).length <= 0)
|
|
@@ -47,14 +43,14 @@ var Utils = /** @class */ (function () {
|
|
|
47
43
|
/* empty */
|
|
48
44
|
}
|
|
49
45
|
return o;
|
|
50
|
-
}
|
|
46
|
+
}
|
|
51
47
|
/**
|
|
52
48
|
* Checks if a given value is a valid number.
|
|
53
49
|
* @param {string} number - The value to be checked.
|
|
54
50
|
* @returns {boolean} - True if the value is a valid number, false otherwise.
|
|
55
51
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
static isValidNumber(number) {
|
|
53
|
+
let validNumb = NaN;
|
|
58
54
|
try {
|
|
59
55
|
validNumb = parseInt(number + '');
|
|
60
56
|
}
|
|
@@ -62,22 +58,20 @@ var Utils = /** @class */ (function () {
|
|
|
62
58
|
console.error('Error while validating number', e);
|
|
63
59
|
}
|
|
64
60
|
return !isNaN(validNumb) && !Array.isArray(number);
|
|
65
|
-
}
|
|
61
|
+
}
|
|
66
62
|
/**
|
|
67
63
|
* Retrieves the value from an object using a case-insensitive key lookup.
|
|
68
64
|
* @param {any} obj - The object to search for the key.
|
|
69
65
|
* @param {string} key - The key to search for in the object.
|
|
70
66
|
* @returns {any | null} The value associated with the key, or null if the key is not found.
|
|
71
67
|
*/
|
|
72
|
-
|
|
68
|
+
static caseInsensitiveObjectForKey(obj, key) {
|
|
73
69
|
if (!obj)
|
|
74
70
|
return null;
|
|
75
|
-
|
|
71
|
+
const insensitiveKey = Object.keys(obj).find(k => k.toLowerCase() === key.toLowerCase());
|
|
76
72
|
if (insensitiveKey && insensitiveKey != '')
|
|
77
73
|
return obj[insensitiveKey];
|
|
78
74
|
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}());
|
|
82
|
-
exports.default = Utils;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
83
77
|
//# sourceMappingURL=Utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/Util/Utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/Util/Utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB;;;OAGG;IACI,MAAM,CAAC,qBAAqB;QACjC,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,MAAc;QACxC,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,IAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAAC,GAAY;QAC1C,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;QAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,sBAAsB,CAAC,MAA0B;QAC7D,IAAI,CAAC,GAAG,IAAI,CAAA;QACZ,IAAI,CAAC;YACH,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACtC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC;gBAAE,CAAC,GAAG,IAAI,CAAA;QAC/C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,WAAW;QACb,CAAC;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,MAAc;QACxC,IAAI,SAAS,GAAG,GAAG,CAAA;QACnB,IAAI,CAAC;YACH,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;QACnC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAA;QACnD,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,2BAA2B,CAAC,GAAQ,EAAE,GAAW;QAC7D,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAA;QACrB,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;QACxF,IAAI,cAAc,IAAI,cAAc,IAAI,EAAE;YAAE,OAAO,GAAG,CAAC,cAAc,CAAC,CAAA;QACtE,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -1,44 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var Response_1 = require("../API/Response");
|
|
5
|
-
var Globals_1 = require("../Globals");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import Response from '../API/Response';
|
|
3
|
+
import Globals from '../Globals';
|
|
6
4
|
/**
|
|
7
5
|
* Validates the given data against the provided schema.
|
|
8
6
|
* @param {any} data - The data to be validated.
|
|
9
7
|
* @param {z.ZodObject<any>} schema - The schema to validate against.
|
|
10
8
|
* @returns {boolean | Response<ResponseErrorType>} - Returns true if the data is valid, otherwise returns a response object with an error message.
|
|
11
9
|
*/
|
|
12
|
-
|
|
13
|
-
function Validator() {
|
|
14
|
-
}
|
|
10
|
+
export default class Validator {
|
|
15
11
|
/**
|
|
16
12
|
* Validates the given data against the provided schema.
|
|
17
13
|
* @param {any} data - The data to be validated.
|
|
18
14
|
* @param {z.ZodObject<any> | z.ZodUnion<any>} schema - The schema to validate against.
|
|
19
15
|
* @returns {boolean | Response<ResponseErrorType>} - Returns either true if the data is valid or a Response object with an error message if validation fails.
|
|
20
16
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
static validateSchema(data, schema) {
|
|
18
|
+
let error, validatedInput;
|
|
23
19
|
// Validate body against known zod schema
|
|
24
20
|
try {
|
|
25
21
|
validatedInput = schema.parse(data);
|
|
26
22
|
}
|
|
27
23
|
catch (err) {
|
|
28
|
-
if (err instanceof
|
|
24
|
+
if (err instanceof z.ZodError)
|
|
29
25
|
error = JSON.parse(err.message);
|
|
30
26
|
else
|
|
31
27
|
error = 'Unknown validation error!'; //unhandled case, hard to test
|
|
32
28
|
}
|
|
33
29
|
// Error validation
|
|
34
30
|
if (!validatedInput || error) {
|
|
35
|
-
return
|
|
31
|
+
return Response.BadRequestResponse(Globals.ErrorResponseValidationFail, Globals.ErrorCode_InvalidInput, { validationFailure: error });
|
|
36
32
|
}
|
|
37
33
|
else {
|
|
38
34
|
return true;
|
|
39
35
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}());
|
|
43
|
-
exports.default = Validator;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
44
38
|
//# sourceMappingURL=Validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validation/Validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validation/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,QAA+B,MAAM,iBAAiB,CAAA;AAC7D,OAAO,OAAO,MAAM,YAAY,CAAA;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAC1B,IAAS,EACT,MAAwE;QAExE,IAAI,KAAK,EAAE,cAAc,CAAA;QAEzB,yCAAyC;QACzC,IAAI,CAAC;YACH,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAkB,CAAA;QACtD,CAAC;QAAC,OAAO,GAAqB,EAAE,CAAC;YAC/B,IAAI,GAAG,YAAY,CAAC,CAAC,QAAQ;gBAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;;gBACzD,KAAK,GAAG,2BAA2B,CAAA,CAAC,8BAA8B;QACzE,CAAC;QAED,mBAAmB;QACnB,IAAI,CAAC,cAAc,IAAI,KAAK,EAAE,CAAC;YAC7B,OAAO,QAAQ,CAAC,kBAAkB,CAChC,OAAO,CAAC,2BAA2B,EACnC,OAAO,CAAC,sBAAsB,EAC9B,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAA;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
|
package/jest.config.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
// ECMA suppport https://jestjs.io/docs/ecmascript-modules
|
|
6
|
+
transform: {},
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
reporters: [
|
|
10
|
+
'default',
|
|
11
|
+
[
|
|
12
|
+
'jest-junit',
|
|
13
|
+
{
|
|
14
|
+
outputDirectory: 'coverage',
|
|
15
|
+
outputName: 'jest-junit.xml',
|
|
16
|
+
ancestorSeparator: ' › ',
|
|
17
|
+
uniqueOutputName: 'false',
|
|
18
|
+
suiteNameTemplate: '{filepath}',
|
|
19
|
+
classNameTemplate: '{classname}',
|
|
20
|
+
titleTemplate: '{title}',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
25
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
26
|
+
coverageThreshold: {
|
|
27
|
+
global: {
|
|
28
|
+
branches: 80,
|
|
29
|
+
functions: 80,
|
|
30
|
+
lines: 80,
|
|
31
|
+
statements: 80,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
export default config
|
package/package.json
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1-alpha1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "
|
|
7
|
+
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc --build",
|
|
10
10
|
"clean": "tsc --build --clean",
|
|
11
|
-
"lint-fix": "eslint . --
|
|
12
|
-
"lint": "eslint .
|
|
13
|
-
"test": "
|
|
11
|
+
"lint-fix": "eslint . --fix",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"test": "npm run test-ts && npm run test-js",
|
|
14
|
+
"test-ts": "jest --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
|
|
15
|
+
"test-js": "rm -rf ./smoke-tests; tsc -p tsconfig.smoke.json && cd smoke-tests && npm i && NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --config=./jest.smoke.config.js --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
|
|
14
16
|
"test-dev": "jest --coverage --runInBand && cat coverage/coverage.txt"
|
|
15
17
|
},
|
|
16
18
|
"author": "",
|
|
17
19
|
"license": "ISC",
|
|
18
20
|
"dependencies": {
|
|
19
|
-
"@aws-sdk/client-kms": "^3.
|
|
20
|
-
"@aws-sdk/client-secrets-manager": "
|
|
21
|
-
"@aws-sdk/client-ses": "
|
|
22
|
-
"@aws-sdk/client-sns": "
|
|
23
|
-
"@aws-sdk/client-ssm": "
|
|
24
|
-
"@aws-sdk/credential-provider-node": "
|
|
21
|
+
"@aws-sdk/client-kms": "^3.556.0",
|
|
22
|
+
"@aws-sdk/client-secrets-manager": "3.556",
|
|
23
|
+
"@aws-sdk/client-ses": "3.556",
|
|
24
|
+
"@aws-sdk/client-sns": "3.556",
|
|
25
|
+
"@aws-sdk/client-ssm": "3.556",
|
|
26
|
+
"@aws-sdk/credential-provider-node": "3.556",
|
|
25
27
|
"@types/email-templates": "^10.0.1",
|
|
26
28
|
"@types/nodemailer": "^6.4.10",
|
|
27
29
|
"@types/object-hash": "^3.0.4",
|
|
@@ -39,30 +41,30 @@
|
|
|
39
41
|
"node-cache": "^5.1.2",
|
|
40
42
|
"object-hash": "^3.0.0",
|
|
41
43
|
"parse-duration": "^1.1.0",
|
|
42
|
-
"path-to-regexp": "^6.2.
|
|
44
|
+
"path-to-regexp": "^6.2.2",
|
|
43
45
|
"pg": "^8.11.3",
|
|
44
46
|
"redis": "^4.6.13",
|
|
45
47
|
"sha1": "^1.1.1",
|
|
46
48
|
"stack-trace": "0.0.10",
|
|
47
|
-
"zod": "^3.
|
|
49
|
+
"zod": "^3.23.4"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@jest/globals": "^29.7.0",
|
|
51
|
-
"@types/aws-lambda": "^8.10.
|
|
53
|
+
"@types/aws-lambda": "^8.10.137",
|
|
52
54
|
"@types/chai": "^4.3.9",
|
|
53
55
|
"@types/cors": "^2.8.15",
|
|
54
56
|
"@types/express": "^4.17.19",
|
|
55
57
|
"@types/jest": "^29.5.12",
|
|
56
58
|
"@types/jsonwebtoken": "^9.0.3",
|
|
57
|
-
"@types/node": "^20.
|
|
59
|
+
"@types/node": "^20.12.7",
|
|
58
60
|
"@types/path-to-regexp": "^1.7.0",
|
|
59
|
-
"@types/pg": "^8.11.
|
|
60
|
-
"@types/supertest": "^
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^
|
|
61
|
+
"@types/pg": "^8.11.5",
|
|
62
|
+
"@types/supertest": "^6.0.2",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
64
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
63
65
|
"aws-lambda": "^1.0.7",
|
|
64
|
-
"aws-sdk-client-mock": "^
|
|
65
|
-
"chai": "^4.
|
|
66
|
+
"aws-sdk-client-mock": "^4.0.0",
|
|
67
|
+
"chai": "^4.4.1",
|
|
66
68
|
"eslint": "^8.48.0",
|
|
67
69
|
"eslint-config-prettier": "^9.0.0",
|
|
68
70
|
"eslint-plugin-import": "^2.28.1",
|
|
@@ -73,6 +75,6 @@
|
|
|
73
75
|
"supertest": "^6.3.3",
|
|
74
76
|
"ts-jest": "^29.1.1",
|
|
75
77
|
"ts-node": "^10.9.1",
|
|
76
|
-
"typescript": "^5.
|
|
78
|
+
"typescript": "^5.4.5"
|
|
77
79
|
}
|
|
78
80
|
}
|
package/src/Crypto/JWT.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely'
|
|
2
|
-
import
|
|
2
|
+
import * as pg from 'pg'
|
|
3
3
|
|
|
4
4
|
import { KyselyTransaction, KyselyTransactionImpl } from './KyselyTransaction'
|
|
5
5
|
import { Database } from '../../Database'
|
|
@@ -24,7 +24,7 @@ export class KyselyDatabase<DBSchema = never> extends Database<KyselyTransaction
|
|
|
24
24
|
* A static property that represents a connection pool for PostgreSQL database connections.
|
|
25
25
|
* @type {Pool}
|
|
26
26
|
*/
|
|
27
|
-
private static pgProvider = Pool
|
|
27
|
+
private static pgProvider = pg.Pool
|
|
28
28
|
/**
|
|
29
29
|
* Represents a PostgreSQL client using the PostgresDialect.
|
|
30
30
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as pg from 'pg'
|
|
2
2
|
|
|
3
3
|
import { PostgresTransaction, PostgresTransactionImpl } from './PostgresTransaction'
|
|
4
4
|
import { Database } from '../../Database'
|
|
@@ -13,16 +13,16 @@ export class PostgresDatabase extends Database<PostgresTransaction> {
|
|
|
13
13
|
* A public static property that represents a connection pool for a PostgreSQL database.
|
|
14
14
|
* This property is used to manage and provide connections to the PostgreSQL database.
|
|
15
15
|
*/
|
|
16
|
-
private static pgProvider = Pool
|
|
16
|
+
private static pgProvider = pg.Pool
|
|
17
17
|
/**
|
|
18
18
|
* Represents a connection pool to manage multiple client connections to the database.
|
|
19
19
|
*/
|
|
20
|
-
public readonly client: Pool
|
|
20
|
+
public readonly client: pg.Pool
|
|
21
21
|
/**
|
|
22
22
|
* A private property that represents a connection pool for clients.
|
|
23
23
|
* @type {Pool | undefined}
|
|
24
24
|
*/
|
|
25
|
-
public readonly readClient?: Pool
|
|
25
|
+
public readonly readClient?: pg.Pool
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Constructor for creating a new instance of a database connection using Postgres.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as pg from 'pg'
|
|
2
2
|
|
|
3
3
|
import { PostgresDatabase } from './PostgresDatabase'
|
|
4
4
|
import { Database } from '../../Database'
|
|
@@ -8,7 +8,7 @@ import { DatabaseTransaction } from '../../DatabaseTransaction'
|
|
|
8
8
|
* A type alias representing a Postgres transaction. It extends the `PostgresTransactionImpl`
|
|
9
9
|
* interface and includes the `PoolClient` interface.
|
|
10
10
|
*/
|
|
11
|
-
export type PostgresTransaction = PostgresTransactionImpl & PoolClient
|
|
11
|
+
export type PostgresTransaction = PostgresTransactionImpl & pg.PoolClient
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Represents a transaction in a Postgres database.
|
|
@@ -18,16 +18,16 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
|
|
|
18
18
|
* A Pool object used for writing operations.
|
|
19
19
|
* @readonly
|
|
20
20
|
*/
|
|
21
|
-
public readonly writer: Pool
|
|
21
|
+
public readonly writer: pg.Pool
|
|
22
22
|
/**
|
|
23
23
|
* A readonly property representing a pool reader.
|
|
24
24
|
*/
|
|
25
|
-
public readonly reader: Pool
|
|
25
|
+
public readonly reader: pg.Pool
|
|
26
26
|
/**
|
|
27
27
|
* Represents a database transaction using a PoolClient.
|
|
28
28
|
* @type {PoolClient}
|
|
29
29
|
*/
|
|
30
|
-
protected transaction: PoolClient
|
|
30
|
+
protected transaction: pg.PoolClient
|
|
31
31
|
/**
|
|
32
32
|
* A protected property representing a database of type Database<PostgresTransaction>.
|
|
33
33
|
* This property is used to interact with a Postgres database using transactions.
|
|
@@ -39,7 +39,7 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
|
|
|
39
39
|
* @param {PostgresDatabase} database - The Postgres database instance.
|
|
40
40
|
* @param {Pool} [reader] - The reader pool for database operations (optional).
|
|
41
41
|
*/
|
|
42
|
-
private constructor(writer: Pool, database: PostgresDatabase, reader?: Pool) {
|
|
42
|
+
private constructor(writer: pg.Pool, database: PostgresDatabase, reader?: pg.Pool) {
|
|
43
43
|
super(writer, database, reader)
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -51,9 +51,9 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
|
|
|
51
51
|
* @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction instance.
|
|
52
52
|
*/
|
|
53
53
|
public static async newTransaction(
|
|
54
|
-
writer: Pool,
|
|
54
|
+
writer: pg.Pool,
|
|
55
55
|
database: PostgresDatabase,
|
|
56
|
-
reader?: Pool
|
|
56
|
+
reader?: pg.Pool
|
|
57
57
|
): Promise<PostgresTransaction> {
|
|
58
58
|
const tx = new PostgresTransactionImpl(writer, database, reader)
|
|
59
59
|
await tx.begin() // defaults to opened
|
package/src/Globals.ts
CHANGED
package/src/Logger/Logger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import abind from 'abind'
|
|
2
|
+
import stringify from 'json-stringify-safe'
|
|
3
|
+
import stackTrace from 'stack-trace'
|
|
4
4
|
|
|
5
5
|
import Utils from '../Util/Utils'
|
|
6
6
|
|
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as SES from '@aws-sdk/client-ses'
|
|
2
2
|
import { defaultProvider } from '@aws-sdk/credential-provider-node'
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import type
|
|
3
|
+
import Email from 'email-templates'
|
|
4
|
+
import nodemailer from 'nodemailer'
|
|
5
|
+
import type SESTransport from 'nodemailer/lib/ses-transport'
|
|
6
6
|
|
|
7
7
|
export default class Mailer {
|
|
8
8
|
/**
|
package/src/Server/Router.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
1
2
|
import { Server as HTTPServer, createServer } from 'http'
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
4
|
+
import cors from 'cors'
|
|
5
|
+
import express from 'express'
|
|
5
6
|
|
|
6
7
|
import Server from './../Server'
|
|
7
8
|
import GenericHandler from './GenericHandler'
|
|
8
9
|
import HealthHandler from './HealthHandler'
|
|
9
|
-
import { version as appVersion } from '../../../../package.json'
|
|
10
10
|
import Globals from '../../../Globals'
|
|
11
11
|
import Utils from '../../../Util/Utils'
|
|
12
12
|
import { RouterConfig } from '../../Router'
|
|
13
13
|
|
|
14
|
+
/* Get package.json version from Wapi on ESM */
|
|
15
|
+
const { version: appVersion } = JSON.parse(fs.readFileSync('package.json').toString())
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Represents a Proxy class that handles routing and server functionality.
|
|
16
19
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
1
2
|
import { expect } from 'chai'
|
|
2
3
|
|
|
3
4
|
import { DatabaseManager } from '../../src/Database'
|
|
@@ -17,13 +18,13 @@ describe('Database Manager', () => {
|
|
|
17
18
|
const underTest = new DatabaseManager()
|
|
18
19
|
|
|
19
20
|
underTest['databases'] = {
|
|
20
|
-
knex: jest.fn(config => {
|
|
21
|
+
knex: jest.fn((config: any) => {
|
|
21
22
|
return { host: config.host, type: 'knex' } as any
|
|
22
23
|
}) as any,
|
|
23
|
-
pg: jest.fn(config => {
|
|
24
|
+
pg: jest.fn((config: any) => {
|
|
24
25
|
return { host: config.host, type: 'pg' } as any
|
|
25
26
|
}) as any,
|
|
26
|
-
kysely: jest.fn(config => {
|
|
27
|
+
kysely: jest.fn((config: any) => {
|
|
27
28
|
return { host: config.host, type: 'kysely' } as any
|
|
28
29
|
}) as any,
|
|
29
30
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
1
2
|
import { PostgresDialect } from 'kysely'
|
|
2
|
-
import
|
|
3
|
+
import * as pg from 'pg'
|
|
3
4
|
|
|
4
5
|
import type { DbConfig } from '../../../../src/Database'
|
|
5
6
|
import { KyselyDatabase } from '../../../../src/Database/integrations/kysely/KyselyDatabase'
|
|
@@ -38,7 +39,7 @@ describe('KyselyDatabase', () => {
|
|
|
38
39
|
let mockPgClient
|
|
39
40
|
beforeEach(() => {
|
|
40
41
|
mockTrans = {
|
|
41
|
-
execute: jest.fn(async cb => {
|
|
42
|
+
execute: jest.fn(async (cb: any) => {
|
|
42
43
|
cb(mockTrans)
|
|
43
44
|
}),
|
|
44
45
|
} as any
|
|
@@ -68,7 +69,7 @@ describe('KyselyDatabase', () => {
|
|
|
68
69
|
() =>
|
|
69
70
|
({
|
|
70
71
|
connect: async () => mockPgTrans,
|
|
71
|
-
}) as PoolClient
|
|
72
|
+
}) as pg.PoolClient
|
|
72
73
|
)
|
|
73
74
|
KyselyDatabase['pgProvider'] = mockPgClient as any
|
|
74
75
|
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
1
2
|
import { Kysely, Transaction } from 'kysely'
|
|
2
3
|
|
|
3
4
|
import type { DbConfig } from '../../../../src/Database'
|
|
@@ -23,7 +24,7 @@ const testResources = async (config: Partial<DbConfig<'kysely'>>) => {
|
|
|
23
24
|
|
|
24
25
|
const transaction = jest.fn().mockImplementation(() => {
|
|
25
26
|
return {
|
|
26
|
-
execute: jest.fn(async cb => {
|
|
27
|
+
execute: jest.fn(async (cb: any) => {
|
|
27
28
|
try {
|
|
28
29
|
await cb(transaction)
|
|
29
30
|
} catch (e) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
import * as pg from 'pg'
|
|
2
3
|
|
|
3
4
|
import type { DbConfig } from '../../../../src/Database'
|
|
4
5
|
import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
|
|
@@ -39,7 +40,7 @@ describe('PostgresDatabase', () => {
|
|
|
39
40
|
() =>
|
|
40
41
|
({
|
|
41
42
|
connect: async () => mockTrans,
|
|
42
|
-
}) as PoolClient
|
|
43
|
+
}) as pg.PoolClient
|
|
43
44
|
)
|
|
44
45
|
PostgresDatabase['pgProvider'] = mockClient as any
|
|
45
46
|
})
|