@winible/winible-typed 2.69.3 → 2.69.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"campaignUtils.js","sourceRoot":"","sources":["../../utils/campaignUtils.ts"],"names":[],"mappings":";;;AAAA,gCAA2C;AA0B3C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AAE1C,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,cAAc;IAC1B,YAAY,EAAE,gBAAgB;IAC9B,SAAS,EAAE,aAAa;IACxB,aAAa,EAAE,iBAAiB;IAChC,gBAAgB,EAAE,oBAAoB;CACvC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,OAAa,EAAE,eAAgC,EAAE,EAAE;IAC5E,IAAI,YAAY,GAA2B,EAAE,CAAC;IAE9C,MAAM,OAAO,GAAG,CAAC,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC;IAC9C,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,IAAI,EAAE,CAAC;IAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAC;IAEnD,IACE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC;QACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,EACzC;QACA,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;KACjE;IAED,IACE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC;QAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,EAC3C;QACA,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,IAA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,KAAK,EAAE,YAAY,EAAE,CAAC,EAC7B,qBAAqB,EAAE;YACrB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO;YACb,eAAe,EAAE,cAAc,IAAI,EAAE;SACtC,IACE,CAAC,SAAS,IAAI;QACf,WAAW,EAAE;YACX,WAAW,EAAE,SAAS;SACvB;KACF,CAAC,CACH,CAAC;IAEF,MAAM,QAAQ,GAAG,GAAG,iBAAiB,IAAI,UAAU,IACjD,UAAU,IAAI,WAChB,EAAE,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE;YACP,aAAa,kBACX,QAAQ;gBACR,MAAM;gBACN,IAAI,EACJ,eAAe,EAAE,oBAAoB,EACrC,UAAU,IACP,CAAC,UAAU,IAAI;gBAChB,MAAM,EAAE,UAAU;aACnB,CAAC,CACH;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,mCAAmC,GAAG,CACjD,OAAe,EACf,YAAoC,EACpC,EAAE;IACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACvD,OAAO,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAClD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,mCAAmC,uCAS9C;AAEF,kBAAe;IACb,iBAAiB;IACjB,oBAAoB;IACpB,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,mCAAmC,EAAnC,2CAAmC;CACpC,CAAC"}
1
+ {"version":3,"file":"campaignUtils.js","sourceRoot":"","sources":["../../utils/campaignUtils.ts"],"names":[],"mappings":";;;AAAA,gCAA2C;AAkC3C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AAE1C,MAAM,YAAY,GAAG;IACnB,UAAU,EAA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AEH,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE;YACP,aAAa,kBACX,QAAQ;gBACR,MAAM;gBACN,IAAI,EACJ,eAAe,EAAE,oBAAoB,EACrC,UAAU,IACP,CAAC,UAAU,IAAI;gBAChB,MAAM,EAAE,UAAU;aACnB,CAAC,CACH;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,mCAAmC,GAAG,CACjD,OAAe,EACf,YAAoC,EACpC,EAAE;IACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACvD,OAAO,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAClD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,mCAAmC,uCAS9C;AAEF,kBAAe;IACb,iBAAiB;IACjB,oBAAoB;IACpB,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,mCAAmC,EAAnC,2CAAmC;CACpC,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const camelizeKeys = (obj) => {
4
+ return Object.keys(obj).reduce((acc, key) => {
5
+ acc[key
6
+ .toLowerCase()
7
+ .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())] = obj[key];
8
+ return acc;
9
+ }, {});
10
+ };
11
+ exports.default = {
12
+ camelizeKeys,
13
+ };
14
+ //# sourceMappingURL=generalUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generalUtils.js","sourceRoot":"","sources":["../../utils/generalUtils.ts"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,CAAgC,GAAM,EAAK,EAAE;IAChE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,GAAG,CACD,GAAG;aACA,WAAW,EAAE;aACb,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAC7D,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAM,CAAC;AACd,CAAC,CAAC;AAEF,kBAAe;IACb,YAAY;CACb,CAAC"}
@@ -3,7 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.campaignUtils = void 0;
6
+ exports.logger = exports.connectionManager = exports.generalUtils = exports.campaignUtils = void 0;
7
7
  var campaignUtils_1 = require("./campaignUtils");
8
8
  Object.defineProperty(exports, "campaignUtils", { enumerable: true, get: function () { return __importDefault(campaignUtils_1).default; } });
9
+ var generalUtils_1 = require("./generalUtils");
10
+ Object.defineProperty(exports, "generalUtils", { enumerable: true, get: function () { return __importDefault(generalUtils_1).default; } });
11
+ var connectionManager_1 = require("./lambdaUtils/connectionManager");
12
+ Object.defineProperty(exports, "connectionManager", { enumerable: true, get: function () { return __importDefault(connectionManager_1).default; } });
13
+ var logger_1 = require("./lambdaUtils/logger");
14
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
9
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA2D;AAAlD,+HAAA,OAAO,OAAiB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA2D;AAAlD,+HAAA,OAAO,OAAiB;AACjC,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB;AAChC,qEAA+E;AAAtE,uIAAA,OAAO,OAAqB;AACrC,+CAAyD;AAAhD,iHAAA,OAAO,OAAU"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const typed_model_1 = require("../../typed-model");
7
+ const event_collector_models_1 = require("../../event-collector-models");
8
+ const logger_1 = __importDefault(require("./logger"));
9
+ let winibleSequelizeInstance = null;
10
+ let eventCollectorSequelizeInstance = null;
11
+ /**
12
+ * Handles database connections for Lambda functions
13
+ * Can be used as a wrapper for functions that need database access
14
+ + *
15
+ + * In AWS Lambda, container instances can be reused across invocations.
16
+ + * This utility optimizes connection handling by:
17
+ + * 1. Reusing the Sequelize instance across warm invocations
18
+ + * 2. Restarting connection pools to avoid stale connections
19
+ + * 3. Properly closing connections after each invocation
20
+ */
21
+ function winibleDB(handlerMethod) {
22
+ return (async () => {
23
+ try {
24
+ // re-use the sequelize instance across invocations to improve performance
25
+ if (!winibleSequelizeInstance) {
26
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - no instance found");
27
+ winibleSequelizeInstance = typed_model_1.pbSequelize;
28
+ await (winibleSequelizeInstance === null || winibleSequelizeInstance === void 0 ? void 0 : winibleSequelizeInstance.authenticate());
29
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - new instance configured");
30
+ }
31
+ else {
32
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - instance found");
33
+ // restart connection pool to ensure connections are not re-used across invocations
34
+ winibleSequelizeInstance.connectionManager.initPools();
35
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - restarted connection pools");
36
+ // restore `getConnection()` if it has been overwritten by `close()`
37
+ if (winibleSequelizeInstance.connectionManager.hasOwnProperty("getConnection")) {
38
+ delete winibleSequelizeInstance.connectionManager
39
+ .getConnection;
40
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - restoring getConnection");
41
+ }
42
+ }
43
+ return await handlerMethod(winibleSequelizeInstance);
44
+ }
45
+ catch (error) {
46
+ throw error;
47
+ }
48
+ finally {
49
+ // close any opened connections during the invocation
50
+ // this will wait for any in-progress queries to finish before closing the connections
51
+ await (winibleSequelizeInstance === null || winibleSequelizeInstance === void 0 ? void 0 : winibleSequelizeInstance.connectionManager.close());
52
+ (0, logger_1.default)("[WINIBLE-DB] sequelize - closed opened connections");
53
+ }
54
+ })();
55
+ }
56
+ /**
57
+ * Handles database connections for Lambda functions
58
+ * Can be used as a wrapper for functions that need database access
59
+ + *
60
+ + * In AWS Lambda, container instances can be reused across invocations.
61
+ + * This utility optimizes connection handling by:
62
+ + * 1. Reusing the Sequelize instance across warm invocations
63
+ + * 2. Restarting connection pools to avoid stale connections
64
+ + * 3. Properly closing connections after each invocation
65
+ */
66
+ function eventCollectorDB(handlerMethod) {
67
+ return (async () => {
68
+ try {
69
+ // re-use the sequelize instance across invocations to improve performance
70
+ if (!eventCollectorSequelizeInstance) {
71
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - no instance found");
72
+ eventCollectorSequelizeInstance = event_collector_models_1.tsSequelize;
73
+ await eventCollectorSequelizeInstance.authenticate();
74
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - new instance configured");
75
+ }
76
+ else {
77
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - instance found");
78
+ // restart connection pool to ensure connections are not re-used across invocations
79
+ eventCollectorSequelizeInstance.connectionManager.initPools();
80
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - restarted connection pools");
81
+ // restore `getConnection()` if it has been overwritten by `close()`
82
+ if (eventCollectorSequelizeInstance.connectionManager.hasOwnProperty("getConnection")) {
83
+ delete eventCollectorSequelizeInstance.connectionManager
84
+ .getConnection;
85
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - restoring getConnection");
86
+ }
87
+ }
88
+ return await handlerMethod(eventCollectorSequelizeInstance);
89
+ }
90
+ catch (error) {
91
+ throw error;
92
+ }
93
+ finally {
94
+ // close any opened connections during the invocation
95
+ // this will wait for any in-progress queries to finish before closing the connections
96
+ await (eventCollectorSequelizeInstance === null || eventCollectorSequelizeInstance === void 0 ? void 0 : eventCollectorSequelizeInstance.connectionManager.close());
97
+ (0, logger_1.default)("[EVENT-COLLECTOR-DB] sequelize - closed opened connections");
98
+ }
99
+ })();
100
+ }
101
+ exports.default = { winibleDB, eventCollectorDB };
102
+ //# sourceMappingURL=connectionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectionManager.js","sourceRoot":"","sources":["../../../utils/lambdaUtils/connectionManager.ts"],"names":[],"mappings":";;;;;AAAA,mDAAoE;AACpE,yEAAsF;AAEtF,sDAA8B;AAE9B,IAAI,wBAAwB,GAAqB,IAAI,CAAC;AACtD,IAAI,+BAA+B,GAAqB,IAAI,CAAC;AAE7D;;;;;;;;;GASG;AACH,SAAS,SAAS,CAChB,aAAmD;IAEnD,OAAO,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI;YACF,0EAA0E;YAC1E,IAAI,CAAC,wBAAwB,EAAE;gBAC7B,IAAA,gBAAM,EAAC,4CAA4C,CAAC,CAAC;gBACrD,wBAAwB,GAAG,yBAAgB,CAAC;gBAC5C,MAAM,CAAA,wBAAwB,aAAxB,wBAAwB,uBAAxB,wBAAwB,CAAE,YAAY,EAAE,CAAA,CAAC;gBAC/C,IAAA,gBAAM,EAAC,kDAAkD,CAAC,CAAC;aAC5D;iBAAM;gBACL,IAAA,gBAAM,EAAC,yCAAyC,CAAC,CAAC;gBAElD,mFAAmF;gBACnF,wBAAwB,CAAC,iBAAiB,CAAC,SAAS,EAAE,CAAC;gBACvD,IAAA,gBAAM,EAAC,qDAAqD,CAAC,CAAC;gBAE9D,oEAAoE;gBACpE,IACE,wBAAwB,CAAC,iBAAiB,CAAC,cAAc,CACvD,eAAe,CAChB,EACD;oBACA,OAAQ,wBAAwB,CAAC,iBAAy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SACb;gBAAS;YACR,qDAAqD;YACrD,sFAAsF;YACtF,MAAM,CAAA,+BAA+B,aAA/B,+BAA+B,uBAA/B,+BAA+B,CAAE,iBAAiB,CAAC,KAAK,EAAE,CAAA,CAAC;YACjE,IAAA,gBAAM,EAAC,4DAA4D,CAAC,CAAC;SACtE;IACH,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED,kBAAe,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * @param message The log message
5
+ * @param options Additional context for the log entry
6
+ *
7
+ * @example
8
+ * // Basic usage
9
+ * logger("User login successful");
10
+ *
11
+ * @example
12
+ * // With user ID
13
+ * logger("User login successful", { userId: "123456" });
14
+ *
15
+ * @example
16
+ * // With error tracking (standard Error)
17
+ * try {
18
+ * throw new Error("Something went wrong");
19
+ * } catch (error) {
20
+ * logger("Operation failed", {
21
+ * userId: "user123",
22
+ * level: "error",
23
+ * endpoint: "/auth",
24
+ * method: "processPayment",
25
+ * error
26
+ * });
27
+ * }
28
+ *
29
+ * @example
30
+ * // With object-like error (e.g., from an API)
31
+ * const apiError = { status: 403, message: "Forbidden", code: "ACCESS_DENIED" };
32
+ * logger("API request failed", { error: apiError, level: "error" });
33
+ *
34
+ * @example
35
+ * // With primitive error
36
+ * logger("Validation failed", { error: "Invalid input", level: "warn" });
37
+ *
38
+ * @example
39
+ * // With request tracking
40
+ * logger("API request received", {
41
+ * requestId: req.headers['x-request-id'],
42
+ * endpoint: "/auth",
43
+ * method: "validateToken"
44
+ * action: "validateToken"
45
+ * });
46
+ */
47
+ const logger = (message, options) => {
48
+ const timestamp = new Date().toISOString();
49
+ const environment = process.env.ENVIRONMENT || "development";
50
+ const logEntry = Object.assign(Object.assign({ message, requestId: (options === null || options === void 0 ? void 0 : options.requestId) || "", timestamp, level: (options === null || options === void 0 ? void 0 : options.level) || "info", environment, endpoint: (options === null || options === void 0 ? void 0 : options.endpoint) || "", method: (options === null || options === void 0 ? void 0 : options.method) || "", action: (options === null || options === void 0 ? void 0 : options.action) || "", userId: (options === null || options === void 0 ? void 0 : options.userId) || "" }, ((options === null || options === void 0 ? void 0 : options.error)
51
+ ? {
52
+ error: (() => {
53
+ var _a, _b, _c;
54
+ // Handle different error types
55
+ if (options.error instanceof Error) {
56
+ // Standard Error object
57
+ return {
58
+ name: (_a = options.error) === null || _a === void 0 ? void 0 : _a.name,
59
+ message: (_b = options.error) === null || _b === void 0 ? void 0 : _b.message,
60
+ stack: (_c = options.error) === null || _c === void 0 ? void 0 : _c.stack,
61
+ };
62
+ }
63
+ else if (typeof options.error === "object" &&
64
+ options.error !== null) {
65
+ // Object-like error but not an Error instance
66
+ const errorObj = options.error;
67
+ return {
68
+ name: (errorObj === null || errorObj === void 0 ? void 0 : errorObj.name) || "UnknownError",
69
+ message: (errorObj === null || errorObj === void 0 ? void 0 : errorObj.message) || String(errorObj),
70
+ details: errorObj,
71
+ };
72
+ }
73
+ else {
74
+ // Primitive or other non-object error
75
+ return {
76
+ name: "UnknownError",
77
+ message: String(options.error),
78
+ };
79
+ }
80
+ })(),
81
+ }
82
+ : {})), ((options === null || options === void 0 ? void 0 : options.additionalData) ? { data: options.additionalData } : {}));
83
+ // Log as JSON string on production for easier parsing in CloudWatch
84
+ const outputLog = environment === "production"
85
+ ? JSON.stringify(logEntry)
86
+ : JSON.stringify(logEntry, null, 2);
87
+ console.log(outputLog);
88
+ };
89
+ exports.default = logger;
90
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../utils/lambdaUtils/logger.ts"],"names":[],"mappings":";;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,OAAuB,EAAE,EAAE;IAC1D,MAAM,SAAS,GAAG,IAAI,IAAI,EAA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A,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,KAAI,cAAc;wBACtC,OAAO,EAAE,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,KAAI,MAAM,CAAC,QAAQ,CAAC;wBAC9C,OAAO,EAAE,QAAQ;qBAClB,CAAC;iBACH;qBAAM;oBACL,sCAAsC;oBACtC,OAAO;wBACL,IAAI,EAAE,cAAc;wBACpB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;qBAC/B,CAAC;iBACH;YACH,CAAC,CAAC,EAAE;SACL;QACH,CAAC,CAAC,EAAE,CAAC,GACJ,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACrE,CAAC;IAEF,oEAAoE;IACpE,MAAM,SAAS,GACb,WAAW,KAAK,YAAY;QAC1B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC1B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAExC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winible/winible-typed",
3
- "version": "2.69.3",
3
+ "version": "2.69.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -24,6 +24,14 @@ type SmsSendQueueInput = {
24
24
  configuration: CampaignMessageConfiguration;
25
25
  };
26
26
 
27
+ export type Contact = {
28
+ id: string;
29
+ phoneNumber: string;
30
+ email: string;
31
+ firstName: string;
32
+ lastName: string;
33
+ };
34
+
27
35
  const CLIENT_URL = process.env.CLIENT_URL;
28
36
 
29
37
  const VARIABLE_MAP = {
@@ -0,0 +1,14 @@
1
+ const camelizeKeys = <T extends Record<string, any>>(obj: T): T => {
2
+ return Object.keys(obj).reduce((acc, key) => {
3
+ acc[
4
+ key
5
+ .toLowerCase()
6
+ .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
7
+ ] = obj[key];
8
+ return acc;
9
+ }, {}) as T;
10
+ };
11
+
12
+ export default {
13
+ camelizeKeys,
14
+ };
package/utils/index.ts CHANGED
@@ -1 +1,4 @@
1
1
  export { default as campaignUtils } from "./campaignUtils";
2
+ export { default as generalUtils } from "./generalUtils";
3
+ export { default as connectionManager } from "./lambdaUtils/connectionManager";
4
+ export { default as logger } from "./lambdaUtils/logger";
@@ -0,0 +1,113 @@
1
+ import { pbSequelize as winibleSequelize } from "../../typed-model";
2
+ import { tsSequelize as eventCollectorSequelize } from "../../event-collector-models";
3
+ import { Sequelize } from "sequelize";
4
+ import logger from "./logger";
5
+
6
+ let winibleSequelizeInstance: Sequelize | null = null;
7
+ let eventCollectorSequelizeInstance: Sequelize | null = null;
8
+
9
+ /**
10
+ * Handles database connections for Lambda functions
11
+ * Can be used as a wrapper for functions that need database access
12
+ + *
13
+ + * In AWS Lambda, container instances can be reused across invocations.
14
+ + * This utility optimizes connection handling by:
15
+ + * 1. Reusing the Sequelize instance across warm invocations
16
+ + * 2. Restarting connection pools to avoid stale connections
17
+ + * 3. Properly closing connections after each invocation
18
+ */
19
+ function winibleDB<T>(
20
+ handlerMethod: (sequelize: Sequelize) => Promise<T>
21
+ ): Promise<T> {
22
+ return (async () => {
23
+ try {
24
+ // re-use the sequelize instance across invocations to improve performance
25
+ if (!winibleSequelizeInstance) {
26
+ logger("[WINIBLE-DB] sequelize - no instance found");
27
+ winibleSequelizeInstance = winibleSequelize;
28
+ await winibleSequelizeInstance?.authenticate();
29
+ logger("[WINIBLE-DB] sequelize - new instance configured");
30
+ } else {
31
+ logger("[WINIBLE-DB] sequelize - instance found");
32
+
33
+ // restart connection pool to ensure connections are not re-used across invocations
34
+ winibleSequelizeInstance.connectionManager.initPools();
35
+ logger("[WINIBLE-DB] sequelize - restarted connection pools");
36
+
37
+ // restore `getConnection()` if it has been overwritten by `close()`
38
+ if (
39
+ winibleSequelizeInstance.connectionManager.hasOwnProperty(
40
+ "getConnection"
41
+ )
42
+ ) {
43
+ delete (winibleSequelizeInstance.connectionManager as any)
44
+ .getConnection;
45
+ logger("[WINIBLE-DB] sequelize - restoring getConnection");
46
+ }
47
+ }
48
+
49
+ return await handlerMethod(winibleSequelizeInstance);
50
+ } catch (error) {
51
+ throw error;
52
+ } finally {
53
+ // close any opened connections during the invocation
54
+ // this will wait for any in-progress queries to finish before closing the connections
55
+ await winibleSequelizeInstance?.connectionManager.close();
56
+ logger("[WINIBLE-DB] sequelize - closed opened connections");
57
+ }
58
+ })();
59
+ }
60
+
61
+ /**
62
+ * Handles database connections for Lambda functions
63
+ * Can be used as a wrapper for functions that need database access
64
+ + *
65
+ + * In AWS Lambda, container instances can be reused across invocations.
66
+ + * This utility optimizes connection handling by:
67
+ + * 1. Reusing the Sequelize instance across warm invocations
68
+ + * 2. Restarting connection pools to avoid stale connections
69
+ + * 3. Properly closing connections after each invocation
70
+ */
71
+ function eventCollectorDB<T>(
72
+ handlerMethod: (sequelize: Sequelize) => Promise<T>
73
+ ): Promise<T> {
74
+ return (async () => {
75
+ try {
76
+ // re-use the sequelize instance across invocations to improve performance
77
+ if (!eventCollectorSequelizeInstance) {
78
+ logger("[EVENT-COLLECTOR-DB] sequelize - no instance found");
79
+ eventCollectorSequelizeInstance = eventCollectorSequelize;
80
+ await eventCollectorSequelizeInstance.authenticate();
81
+ logger("[EVENT-COLLECTOR-DB] sequelize - new instance configured");
82
+ } else {
83
+ logger("[EVENT-COLLECTOR-DB] sequelize - instance found");
84
+
85
+ // restart connection pool to ensure connections are not re-used across invocations
86
+ eventCollectorSequelizeInstance.connectionManager.initPools();
87
+ logger("[EVENT-COLLECTOR-DB] sequelize - restarted connection pools");
88
+
89
+ // restore `getConnection()` if it has been overwritten by `close()`
90
+ if (
91
+ eventCollectorSequelizeInstance.connectionManager.hasOwnProperty(
92
+ "getConnection"
93
+ )
94
+ ) {
95
+ delete (eventCollectorSequelizeInstance.connectionManager as any)
96
+ .getConnection;
97
+ logger("[EVENT-COLLECTOR-DB] sequelize - restoring getConnection");
98
+ }
99
+ }
100
+
101
+ return await handlerMethod(eventCollectorSequelizeInstance);
102
+ } catch (error) {
103
+ throw error;
104
+ } finally {
105
+ // close any opened connections during the invocation
106
+ // this will wait for any in-progress queries to finish before closing the connections
107
+ await eventCollectorSequelizeInstance?.connectionManager.close();
108
+ logger("[EVENT-COLLECTOR-DB] sequelize - closed opened connections");
109
+ }
110
+ })();
111
+ }
112
+
113
+ export default { winibleDB, eventCollectorDB };
@@ -0,0 +1,114 @@
1
+ export type LoggerOptions = {
2
+ userId?: string;
3
+ level?: "info" | "error" | "warn" | "debug";
4
+ endpoint?: string;
5
+ method?: string;
6
+ action?: string;
7
+ requestId?: string;
8
+ error?: unknown;
9
+ additionalData?: Record<string, any>;
10
+ };
11
+
12
+ /**
13
+ * @param message The log message
14
+ * @param options Additional context for the log entry
15
+ *
16
+ * @example
17
+ * // Basic usage
18
+ * logger("User login successful");
19
+ *
20
+ * @example
21
+ * // With user ID
22
+ * logger("User login successful", { userId: "123456" });
23
+ *
24
+ * @example
25
+ * // With error tracking (standard Error)
26
+ * try {
27
+ * throw new Error("Something went wrong");
28
+ * } catch (error) {
29
+ * logger("Operation failed", {
30
+ * userId: "user123",
31
+ * level: "error",
32
+ * endpoint: "/auth",
33
+ * method: "processPayment",
34
+ * error
35
+ * });
36
+ * }
37
+ *
38
+ * @example
39
+ * // With object-like error (e.g., from an API)
40
+ * const apiError = { status: 403, message: "Forbidden", code: "ACCESS_DENIED" };
41
+ * logger("API request failed", { error: apiError, level: "error" });
42
+ *
43
+ * @example
44
+ * // With primitive error
45
+ * logger("Validation failed", { error: "Invalid input", level: "warn" });
46
+ *
47
+ * @example
48
+ * // With request tracking
49
+ * logger("API request received", {
50
+ * requestId: req.headers['x-request-id'],
51
+ * endpoint: "/auth",
52
+ * method: "validateToken"
53
+ * action: "validateToken"
54
+ * });
55
+ */
56
+ const logger = (message: string, options?: LoggerOptions) => {
57
+ const timestamp = new Date().toISOString();
58
+ const environment = process.env.ENVIRONMENT || "development";
59
+
60
+ const logEntry = {
61
+ message,
62
+ requestId: options?.requestId || "",
63
+ timestamp,
64
+ level: options?.level || "info",
65
+ environment,
66
+ endpoint: options?.endpoint || "",
67
+ method: options?.method || "",
68
+ action: options?.action || "",
69
+ userId: options?.userId || "",
70
+ ...(options?.error
71
+ ? {
72
+ error: (() => {
73
+ // Handle different error types
74
+ if (options.error instanceof Error) {
75
+ // Standard Error object
76
+ return {
77
+ name: options.error?.name,
78
+ message: options.error?.message,
79
+ stack: options.error?.stack,
80
+ };
81
+ } else if (
82
+ typeof options.error === "object" &&
83
+ options.error !== null
84
+ ) {
85
+ // Object-like error but not an Error instance
86
+ const errorObj = options.error as Record<string, any>;
87
+ return {
88
+ name: errorObj?.name || "UnknownError",
89
+ message: errorObj?.message || String(errorObj),
90
+ details: errorObj,
91
+ };
92
+ } else {
93
+ // Primitive or other non-object error
94
+ return {
95
+ name: "UnknownError",
96
+ message: String(options.error),
97
+ };
98
+ }
99
+ })(),
100
+ }
101
+ : {}),
102
+ ...(options?.additionalData ? { data: options.additionalData } : {}),
103
+ };
104
+
105
+ // Log as JSON string on production for easier parsing in CloudWatch
106
+ const outputLog =
107
+ environment === "production"
108
+ ? JSON.stringify(logEntry)
109
+ : JSON.stringify(logEntry, null, 2);
110
+
111
+ console.log(outputLog);
112
+ };
113
+
114
+ export default logger;