@lyxa.ai/core 1.4.219 → 1.4.222
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/dist/libraries/logger-kit/logger.service.d.ts +1 -0
- package/dist/libraries/logger-kit/logger.service.js +21 -40
- package/dist/libraries/logger-kit/logger.service.js.map +1 -1
- package/dist/libraries/logger-kit/types.d.ts +1 -0
- package/dist/libraries/logger-kit/types.js.map +1 -1
- package/dist/libraries/mongo/models/limited-time-offer-participant.model.d.ts +1 -0
- package/dist/libraries/mongo/models/limited-time-offer-participant.model.js +5 -0
- package/dist/libraries/mongo/models/limited-time-offer-participant.model.js.map +1 -1
- package/dist/libraries/mongo/models/marketing.model.d.ts +2 -1
- package/dist/libraries/mongo/models/marketing.model.js +5 -0
- package/dist/libraries/mongo/models/marketing.model.js.map +1 -1
- package/dist/libraries/trpc/context.js +1 -0
- package/dist/libraries/trpc/context.js.map +1 -1
- package/dist/libraries/trpc/index.js +0 -1
- package/dist/libraries/trpc/index.js.map +1 -1
- package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/enum.d.ts +5 -1
- package/dist/types/utilities/enum.js +9 -4
- package/dist/types/utilities/enum.js.map +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +12 -12
- package/dist/utilities/enum.d.ts +5 -1
- package/dist/utilities/enum.js +9 -4
- package/dist/utilities/enum.js.map +1 -1
- package/dist/utilities/error-handler.d.ts +0 -1
- package/dist/utilities/error-handler.js +6 -24
- package/dist/utilities/error-handler.js.map +1 -1
- package/dist/utilities/error-middleware.d.ts +1 -1
- package/dist/utilities/error-middleware.js +75 -173
- package/dist/utilities/error-middleware.js.map +1 -1
- package/package.json +1 -1
|
@@ -65,6 +65,7 @@ export declare class LyxaLoggerKit {
|
|
|
65
65
|
request?: Record<string, any>;
|
|
66
66
|
response?: Record<string, any>;
|
|
67
67
|
status?: HttpStatus;
|
|
68
|
+
error?: TRPCError | Error | unknown;
|
|
68
69
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
69
70
|
_id: mongoose.Types.ObjectId;
|
|
70
71
|
} & {
|
|
@@ -16,6 +16,7 @@ exports.LyxaLoggerKit = exports.requestContext = void 0;
|
|
|
16
16
|
exports.withRequestContext = withRequestContext;
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const node_util_1 = require("node:util");
|
|
19
20
|
const typedi_1 = require("typedi");
|
|
20
21
|
const models_1 = require("../mongo/models");
|
|
21
22
|
const enum_1 = require("../../utilities/enum");
|
|
@@ -74,13 +75,15 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
74
75
|
mongoose_1.default.set('debug', currentDebug);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
normalizeError(error) {
|
|
78
|
+
normalizeError(error, depth = 0) {
|
|
79
|
+
const normalizeCause = (cause) => cause !== undefined && cause !== null && depth < 5 ? this.normalizeError(cause, depth + 1) : undefined;
|
|
78
80
|
if (error instanceof Error) {
|
|
79
81
|
return {
|
|
80
82
|
name: error.name,
|
|
81
83
|
message: error.message,
|
|
82
84
|
stacktrace: error.stack?.split('\n').map(line => line.trim()),
|
|
83
85
|
code: error.code,
|
|
86
|
+
cause: normalizeCause(error.cause),
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
89
|
if (typeof error === 'object' && error !== null) {
|
|
@@ -90,6 +93,7 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
90
93
|
message: err.message,
|
|
91
94
|
stacktrace: err.stack?.split('\n').map((line) => line.trim()) || err.stacktrace,
|
|
92
95
|
code: err.code,
|
|
96
|
+
cause: normalizeCause(err.cause),
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
99
|
return {
|
|
@@ -157,44 +161,17 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
157
161
|
return parts.join(' ');
|
|
158
162
|
}
|
|
159
163
|
consoleLog(level, formattedMessage, entry) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
case enum_1.LogLevel.WARN:
|
|
174
|
-
console.warn(formattedMessage);
|
|
175
|
-
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
176
|
-
console.warn(entry.data);
|
|
177
|
-
}
|
|
178
|
-
break;
|
|
179
|
-
case enum_1.LogLevel.ERROR:
|
|
180
|
-
console.error(formattedMessage);
|
|
181
|
-
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
182
|
-
console.error(entry.data);
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
case enum_1.LogLevel.FATAL:
|
|
186
|
-
console.error(formattedMessage);
|
|
187
|
-
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
188
|
-
console.error(entry.data);
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
default:
|
|
192
|
-
console.log(formattedMessage);
|
|
193
|
-
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
194
|
-
console.log(entry.data);
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
164
|
+
const out = level === enum_1.LogLevel.ERROR || level === enum_1.LogLevel.FATAL
|
|
165
|
+
? console.error
|
|
166
|
+
: level === enum_1.LogLevel.WARN
|
|
167
|
+
? console.warn
|
|
168
|
+
: console.log;
|
|
169
|
+
const dump = (v) => out((0, node_util_1.inspect)(v, { depth: null, colors: true, breakLength: 120 }));
|
|
170
|
+
out(formattedMessage);
|
|
171
|
+
if (entry.data && Object.keys(entry.data).length > 0)
|
|
172
|
+
dump(entry.data);
|
|
173
|
+
if (entry.error)
|
|
174
|
+
dump(entry.error);
|
|
198
175
|
}
|
|
199
176
|
async write(level, message, payload, opts = {}) {
|
|
200
177
|
const { shouldWrite = true } = opts;
|
|
@@ -228,7 +205,11 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
228
205
|
return this.write(enum_1.LogLevel.DEBUG, message, options);
|
|
229
206
|
}
|
|
230
207
|
warn(message, options) {
|
|
231
|
-
|
|
208
|
+
const { error, ...rest } = options;
|
|
209
|
+
return this.write(enum_1.LogLevel.WARN, message, {
|
|
210
|
+
...rest,
|
|
211
|
+
...(error !== undefined && { error: this.normalizeError(error) }),
|
|
212
|
+
});
|
|
232
213
|
}
|
|
233
214
|
error(message, error, options) {
|
|
234
215
|
return this.write(enum_1.LogLevel.ERROR, message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.service.js","sourceRoot":"/","sources":["libraries/logger-kit/logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAicA,gDAUC;AA3cD,4CAAoB;AACpB,gDAAwB;AACxB,mCAAiC;AACjC,4CAAsD;AACtD,+CAAoE;AAEpE,uDAAqD;AACrD,wDAAgC;AASnB,QAAA,cAAc,GAAG,IAAI,oCAAiB,EAAgB,CAAC;AAW7D,IAAM,aAAa,GAAnB,MAAM,aAAa;IACR,KAAK,CAAoC;IACzC,MAAM,CAAyB;IAEhD,YAAY,MAAoB;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,IAAA,uBAAc,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,kBAAkB,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AACJ,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { Service } from 'typedi';\nimport { createLogModel, Log } from '../mongo/models';\nimport { HttpStatus, LogLevel, LogTag } from '../../utilities/enum';\nimport { ErrorInfo, LogMetadata, RequestContext } from './types';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport mongoose from 'mongoose';\nimport { TRPCError } from '@trpc/server';\n\ninterface RequestStore {\n\trequestId?: string;\n\tuserId?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport const requestContext = new AsyncLocalStorage<RequestStore>();\n\ninterface LoggerConfig {\n\tinstanceType: string;\n\tttlDays?: number;\n\tpersistDebug?: boolean;\n\tlogDirectory?: string;\n\tenvironment?: string;\n}\n\n@Service()\nexport class LyxaLoggerKit {\n\tprivate readonly model: ReturnType<typeof createLogModel>;\n\tprivate readonly config: Required<LoggerConfig>;\n\n\tconstructor(config: LoggerConfig) {\n\t\tthis.config = this.normalizeConfig(config);\n\t\tthis.model = createLogModel({ ttlDays: this.config.ttlDays });\n\t\tthis.ensureLogDirectory();\n\t}\n\n\tprivate normalizeConfig(config: LoggerConfig): Required<LoggerConfig> {\n\t\treturn {\n\t\t\tinstanceType: config.instanceType,\n\t\t\tttlDays: config.ttlDays ?? 7,\n\t\t\tpersistDebug: config.persistDebug ?? process.env.PERSIST_DEBUG_LOGS === 'true',\n\t\t\tlogDirectory: config.logDirectory ?? 'logs',\n\t\t\tenvironment: config.environment ?? process.env.NODE_ENV ?? 'development',\n\t\t};\n\t}\n\n\tprivate ensureLogDirectory(): void {\n\t\tconst logPath = path.join(process.cwd(), this.config.logDirectory);\n\t\tfs.mkdirSync(logPath, { recursive: true });\n\t}\n\n\tprivate getRequestStore(): RequestStore {\n\t\treturn requestContext.getStore() ?? {};\n\t}\n\n\tprivate enrichWithContext(data: Record<string, any> = {}): Record<string, any> {\n\t\tconst store = this.getRequestStore();\n\t\treturn {\n\t\t\t...data,\n\t\t\t...(store.requestId && { requestId: store.requestId }),\n\t\t\t...(store.userId && { userId: store.userId }),\n\t\t};\n\t}\n\n\tprivate shouldPersist(level: LogLevel): boolean {\n\t\t// return level !== LogLevel.DEBUG || this.config.persistDebug;\n\t\treturn true;\n\t}\n\n\tprivate async persistLog(log: Partial<Log>) {\n\t\tconst currentDebug = mongoose.get('debug');\n\t\ttry {\n\t\t\tmongoose.set('debug', false);\n\t\t\treturn await this.model.create({\n\t\t\t\t...log,\n\t\t\t\tmicroService: this.config.instanceType,\n\t\t\t\ttimestamp: new Date(),\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tconsole.error('[Logger] MongoDB persistence failed:', err);\n\t\t} finally {\n\t\t\tmongoose.set('debug', currentDebug);\n\t\t}\n\t}\n\n\tprivate normalizeError(error: TRPCError | Error | unknown): ErrorInfo {\n\t\tif (error instanceof Error) {\n\t\t\treturn {\n\t\t\t\tname: error.name,\n\t\t\t\tmessage: error.message,\n\t\t\t\tstacktrace: error.stack?.split('\\n').map(line => line.trim()),\n\t\t\t\tcode: (error as any).code,\n\t\t\t};\n\t\t}\n\t\tif (typeof error === 'object' && error !== null) {\n\t\t\tconst err = error as any;\n\t\t\treturn {\n\t\t\t\tname: err.name,\n\t\t\t\tmessage: err.message,\n\t\t\t\tstacktrace: err.stack?.split('\\n').map((line: string) => line.trim()) || err.stacktrace,\n\t\t\t\tcode: err.code,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tmessage: String(error),\n\t\t};\n\t}\n\n\tprivate buildLogEntry(\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\tconst store = this.getRequestStore();\n\n\t\treturn {\n\t\t\ttag: payload.tag,\n\t\t\tmessage,\n\t\t\tdata: this.enrichWithContext(payload.data),\n\t\t\tmetadata: {\n\t\t\t\t...payload.metadata,\n\t\t\t\t...store.metadata,\n\t\t\t},\n\t\t\terror: payload.error,\n\t\t\tcontext: payload.context,\n\t\t\trequestId: store.requestId,\n\t\t\trequest: payload.request,\n\t\t\tresponse: payload.response,\n\t\t\tstatus: payload.status,\n\t\t};\n\t}\n\n\tprivate getColorCode(level: LogLevel): string {\n\t\tswitch (level) {\n\t\t\tcase LogLevel.DEBUG:\n\t\t\t\treturn '\\x1b[96m'; // Cyan\n\t\t\tcase LogLevel.INFO:\n\t\t\t\treturn '\\x1b[32m'; // Green\n\t\t\tcase LogLevel.WARN:\n\t\t\t\treturn '\\x1b[33m'; // Yellow\n\t\t\tcase LogLevel.ERROR:\n\t\t\t\treturn '\\x1b[31m'; // Red\n\t\t\tcase LogLevel.FATAL:\n\t\t\t\treturn '\\x1b[35m'; // Magenta\n\t\t\tdefault:\n\t\t\t\treturn '\\x1b[37m'; // White\n\t\t}\n\t}\n\n\tprivate formatTimestamp(date: Date): string {\n\t\tconst year = date.getFullYear();\n\t\tconst month = String(date.getMonth() + 1).padStart(2, '0');\n\t\tconst day = String(date.getDate()).padStart(2, '0');\n\t\tconst hours = String(date.getHours()).padStart(2, '0');\n\t\tconst minutes = String(date.getMinutes()).padStart(2, '0');\n\t\tconst seconds = String(date.getSeconds()).padStart(2, '0');\n\n\t\treturn `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;\n\t}\n\n\tprivate formatLogMessage(level: LogLevel, message: string, entry: any): string {\n\t\tconst timestamp = this.formatTimestamp(new Date());\n\t\tconst tag = (entry.tag || 'GENERAL').toUpperCase();\n\t\tconst levelUpper = level.toUpperCase();\n\n\t\t// ANSI color codes\n\t\tconst grey = '\\x1b[90m';\n\t\tconst cyan = '\\x1b[36m';\n\t\tconst levelColor = this.getColorCode(level);\n\t\tconst reset = '\\x1b[0m';\n\n\t\t// Pad level to 5 characters for alignment (DEBUG, INFO, WARN, ERROR, FATAL)\n\t\tconst paddedLevel = levelUpper.padEnd(5);\n\n\t\tconst parts = [\n\t\t\t`${grey}[${timestamp}]${reset}`,\n\t\t\t`${levelColor}[${levelUpper}]${reset}`,\n\t\t\t`${cyan}[${tag}]${reset}`,\n\t\t\tmessage,\n\t\t];\n\n\t\treturn parts.join(' ');\n\t}\n\n\tprivate consoleLog(level: LogLevel, formattedMessage: string, entry: any): void {\n\t\tswitch (level) {\n\t\t\tcase LogLevel.DEBUG:\n\t\t\t\tconsole.log(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.log(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LogLevel.INFO:\n\t\t\t\tconsole.log(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.log(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LogLevel.WARN:\n\t\t\t\tconsole.warn(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.warn(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LogLevel.ERROR:\n\t\t\t\tconsole.error(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.error(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LogLevel.FATAL:\n\t\t\t\tconsole.error(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.error(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tconsole.log(formattedMessage);\n\t\t\t\tif (entry.data && Object.keys(entry.data).length > 0) {\n\t\t\t\t\tconsole.log(entry.data);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate async write(\n\t\tlevel: LogLevel,\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t},\n\t\topts: { shouldWrite?: boolean } = {}\n\t) {\n\t\tconst { shouldWrite = true } = opts;\n\t\tconst entry = this.buildLogEntry(message, payload);\n\n\t\t// Console logging with switch case\n\t\tif (shouldWrite) {\n\t\t\tconst formattedMessage = this.formatLogMessage(level, message, entry);\n\t\t\tthis.consoleLog(level, formattedMessage, entry);\n\t\t}\n\n\t\t// Async persistence (fire-and-forget)\n\t\tif (this.shouldPersist(level)) {\n\t\t\treturn this.persistLog({\n\t\t\t\tlevel,\n\t\t\t\ttag: payload.tag,\n\t\t\t\tmessage,\n\t\t\t\tdata: entry.data,\n\t\t\t\tmetadata: entry.metadata ?? {},\n\t\t\t\terror: payload.error,\n\t\t\t\trequestId: entry.requestId,\n\t\t\t\tcontext: payload.context,\n\t\t\t\trequest: payload.request,\n\t\t\t\tresponse: payload.response,\n\t\t\t\tstatus: payload.status,\n\t\t\t}).catch(e => {\n\t\t\t\tconsole.error('Something went wrong', e);\n\t\t\t});\n\t\t}\n\t}\n\n\t/* ---------------------------------- */\n\t/* Public Logging API */\n\t/* ---------------------------------- */\n\n\tinfo(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.INFO, message, options);\n\t}\n\n\tdebug(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.DEBUG, message, options);\n\t}\n\n\twarn(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.WARN, message, options);\n\t}\n\n\terror(\n\t\tmessage: string,\n\t\terror: TRPCError | Error | unknown,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.ERROR, message, {\n\t\t\t...options,\n\t\t\terror: this.normalizeError(error),\n\t\t});\n\t}\n\n\tfatal(\n\t\tmessage: string,\n\t\terror: TRPCError | Error | unknown,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.FATAL, message, {\n\t\t\t...options,\n\t\t\terror: this.normalizeError(error),\n\t\t});\n\t}\n\n\t/* ---------------------------------- */\n\t/* HTTP Convenience Methods */\n\t/* ---------------------------------- */\n\n\tprivate getHttpLogLevel(statusCode: number): LogLevel {\n\t\tif (statusCode >= 500) return LogLevel.ERROR;\n\t\tif (statusCode >= 400) return LogLevel.WARN;\n\t\treturn LogLevel.INFO;\n\t}\n\n\thttpRequest(method: string, url: string, statusCode: HttpStatus, durationMs: number, userId?: string): void {\n\t\tthis.write(this.getHttpLogLevel(statusCode), 'HTTP request completed', {\n\t\t\ttag: LogTag.HTTP_REQUEST,\n\t\t\tdata: {\n\t\t\t\tmethod,\n\t\t\t\turl,\n\t\t\t\tdurationMs,\n\t\t\t\t...(userId && { userId }),\n\t\t\t},\n\t\t\tmetadata: {\n\t\t\t\t...(userId && { userId }),\n\t\t\t\tresponseTime: durationMs,\n\t\t\t},\n\t\t\tcontext: { method, url },\n\t\t\tstatus: statusCode,\n\t\t});\n\t}\n\n\tchild(defaultContext: {\n\t\ttag?: LogTag | string;\n\t\tdata?: Record<string, any>;\n\t\tmetadata?: LogMetadata;\n\t\trequest?: Record<string, any>;\n\t\tresponse?: Record<string, any>;\n\t\tstatus?: HttpStatus;\n\t}): {\n\t\tinfo: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\tdebug: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\twarn: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\terror: (message: string, error: Error | ErrorInfo, options?: Partial<typeof defaultContext>) => void;\n\t} {\n\t\treturn {\n\t\t\tinfo: (message, opts = {}) =>\n\t\t\t\tthis.info(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\tdebug: (message, opts = {}) =>\n\t\t\t\tthis.debug(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\twarn: (message, opts = {}) =>\n\t\t\t\tthis.warn(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\terror: (message, error, opts = {}) =>\n\t\t\t\tthis.error(message, error, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t};\n\t}\n}\n\nexport function withRequestContext<T>(store: RequestStore, fn: () => T | Promise<T>): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\trequestContext.run(store, async () => {\n\t\t\ttry {\n\t\t\t\tresolve(await fn());\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t});\n}"]}
|
|
1
|
+
{"version":3,"file":"logger.service.js","sourceRoot":"/","sources":["libraries/logger-kit/logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAibA,gDAUC;AA3bD,4CAAoB;AACpB,gDAAwB;AACxB,yCAAoC;AACpC,mCAAiC;AACjC,4CAAsD;AACtD,+CAAoE;AAEpE,uDAAqD;AACrD,wDAAgC;AASnB,QAAA,c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MAAM;aAC5C,CAAC;YACH,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE,CACpC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE;gBAC1B,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,cAAc,CAAC,GAAG,IAAI,aAAM,CAAC,YAAY;gBAC1D,IAAI,EAAE,EAAE,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE;gBAC9C,QAAQ,EAAE,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;gBAC1D,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;gBAC/C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,cAAc,CAAC,QAAQ;gBAClD,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM;aAC5C,CAAC;SACH,CAAC;IACH,CAAC;CACD,CAAA;AAnZY,sCAAa;wBAAb,aAAa;IADzB,IAAA,gBAAO,GAAE;;GACG,aAAa,CAmZzB;AAED,SAAgB,kBAAkB,CAAI,KAAmB,EAAE,EAAwB;IAClF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,sBAAc,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;YACpC,IAAI,CAAC;gBACJ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACrB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,CAAC;YACb,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { inspect } from 'node:util';\nimport { Service } from 'typedi';\nimport { createLogModel, Log } from '../mongo/models';\nimport { HttpStatus, LogLevel, LogTag } from '../../utilities/enum';\nimport { ErrorInfo, LogMetadata, RequestContext } from './types';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport mongoose from 'mongoose';\nimport { TRPCError } from '@trpc/server';\n\ninterface RequestStore {\n\trequestId?: string;\n\tuserId?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport const requestContext = new AsyncLocalStorage<RequestStore>();\n\ninterface LoggerConfig {\n\tinstanceType: string;\n\tttlDays?: number;\n\tpersistDebug?: boolean;\n\tlogDirectory?: string;\n\tenvironment?: string;\n}\n\n@Service()\nexport class LyxaLoggerKit {\n\tprivate readonly model: ReturnType<typeof createLogModel>;\n\tprivate readonly config: Required<LoggerConfig>;\n\n\tconstructor(config: LoggerConfig) {\n\t\tthis.config = this.normalizeConfig(config);\n\t\tthis.model = createLogModel({ ttlDays: this.config.ttlDays });\n\t\tthis.ensureLogDirectory();\n\t}\n\n\tprivate normalizeConfig(config: LoggerConfig): Required<LoggerConfig> {\n\t\treturn {\n\t\t\tinstanceType: config.instanceType,\n\t\t\tttlDays: config.ttlDays ?? 7,\n\t\t\tpersistDebug: config.persistDebug ?? process.env.PERSIST_DEBUG_LOGS === 'true',\n\t\t\tlogDirectory: config.logDirectory ?? 'logs',\n\t\t\tenvironment: config.environment ?? process.env.NODE_ENV ?? 'development',\n\t\t};\n\t}\n\n\tprivate ensureLogDirectory(): void {\n\t\tconst logPath = path.join(process.cwd(), this.config.logDirectory);\n\t\tfs.mkdirSync(logPath, { recursive: true });\n\t}\n\n\tprivate getRequestStore(): RequestStore {\n\t\treturn requestContext.getStore() ?? {};\n\t}\n\n\tprivate enrichWithContext(data: Record<string, any> = {}): Record<string, any> {\n\t\tconst store = this.getRequestStore();\n\t\treturn {\n\t\t\t...data,\n\t\t\t...(store.requestId && { requestId: store.requestId }),\n\t\t\t...(store.userId && { userId: store.userId }),\n\t\t};\n\t}\n\n\tprivate shouldPersist(level: LogLevel): boolean {\n\t\t// return level !== LogLevel.DEBUG || this.config.persistDebug;\n\t\treturn true;\n\t}\n\n\tprivate async persistLog(log: Partial<Log>) {\n\t\tconst currentDebug = mongoose.get('debug');\n\t\ttry {\n\t\t\tmongoose.set('debug', false);\n\t\t\treturn await this.model.create({\n\t\t\t\t...log,\n\t\t\t\tmicroService: this.config.instanceType,\n\t\t\t\ttimestamp: new Date(),\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tconsole.error('[Logger] MongoDB persistence failed:', err);\n\t\t} finally {\n\t\t\tmongoose.set('debug', currentDebug);\n\t\t}\n\t}\n\n\tprivate normalizeError(error: TRPCError | Error | unknown, depth = 0): ErrorInfo {\n\t\t// Walk the .cause chain so the full root cause is logged, not just the top error.\n\t\t// Cap depth to avoid runaway/circular chains.\n\t\tconst normalizeCause = (cause: unknown): ErrorInfo | undefined =>\n\t\t\tcause !== undefined && cause !== null && depth < 5 ? this.normalizeError(cause, depth + 1) : undefined;\n\n\t\tif (error instanceof Error) {\n\t\t\treturn {\n\t\t\t\tname: error.name,\n\t\t\t\tmessage: error.message,\n\t\t\t\tstacktrace: error.stack?.split('\\n').map(line => line.trim()),\n\t\t\t\tcode: (error as any).code,\n\t\t\t\tcause: normalizeCause((error as any).cause),\n\t\t\t};\n\t\t}\n\t\tif (typeof error === 'object' && error !== null) {\n\t\t\tconst err = error as any;\n\t\t\treturn {\n\t\t\t\tname: err.name,\n\t\t\t\tmessage: err.message,\n\t\t\t\tstacktrace: err.stack?.split('\\n').map((line: string) => line.trim()) || err.stacktrace,\n\t\t\t\tcode: err.code,\n\t\t\t\tcause: normalizeCause(err.cause),\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tmessage: String(error),\n\t\t};\n\t}\n\n\tprivate buildLogEntry(\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\tconst store = this.getRequestStore();\n\n\t\treturn {\n\t\t\ttag: payload.tag,\n\t\t\tmessage,\n\t\t\tdata: this.enrichWithContext(payload.data),\n\t\t\tmetadata: {\n\t\t\t\t...payload.metadata,\n\t\t\t\t...store.metadata,\n\t\t\t},\n\t\t\terror: payload.error,\n\t\t\tcontext: payload.context,\n\t\t\trequestId: store.requestId,\n\t\t\trequest: payload.request,\n\t\t\tresponse: payload.response,\n\t\t\tstatus: payload.status,\n\t\t};\n\t}\n\n\tprivate getColorCode(level: LogLevel): string {\n\t\tswitch (level) {\n\t\t\tcase LogLevel.DEBUG:\n\t\t\t\treturn '\\x1b[96m'; // Cyan\n\t\t\tcase LogLevel.INFO:\n\t\t\t\treturn '\\x1b[32m'; // Green\n\t\t\tcase LogLevel.WARN:\n\t\t\t\treturn '\\x1b[33m'; // Yellow\n\t\t\tcase LogLevel.ERROR:\n\t\t\t\treturn '\\x1b[31m'; // Red\n\t\t\tcase LogLevel.FATAL:\n\t\t\t\treturn '\\x1b[35m'; // Magenta\n\t\t\tdefault:\n\t\t\t\treturn '\\x1b[37m'; // White\n\t\t}\n\t}\n\n\tprivate formatTimestamp(date: Date): string {\n\t\tconst year = date.getFullYear();\n\t\tconst month = String(date.getMonth() + 1).padStart(2, '0');\n\t\tconst day = String(date.getDate()).padStart(2, '0');\n\t\tconst hours = String(date.getHours()).padStart(2, '0');\n\t\tconst minutes = String(date.getMinutes()).padStart(2, '0');\n\t\tconst seconds = String(date.getSeconds()).padStart(2, '0');\n\n\t\treturn `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;\n\t}\n\n\tprivate formatLogMessage(level: LogLevel, message: string, entry: any): string {\n\t\tconst timestamp = this.formatTimestamp(new Date());\n\t\tconst tag = (entry.tag || 'GENERAL').toUpperCase();\n\t\tconst levelUpper = level.toUpperCase();\n\n\t\t// ANSI color codes\n\t\tconst grey = '\\x1b[90m';\n\t\tconst cyan = '\\x1b[36m';\n\t\tconst levelColor = this.getColorCode(level);\n\t\tconst reset = '\\x1b[0m';\n\n\t\t// Pad level to 5 characters for alignment (DEBUG, INFO, WARN, ERROR, FATAL)\n\t\tconst paddedLevel = levelUpper.padEnd(5);\n\n\t\tconst parts = [\n\t\t\t`${grey}[${timestamp}]${reset}`,\n\t\t\t`${levelColor}[${levelUpper}]${reset}`,\n\t\t\t`${cyan}[${tag}]${reset}`,\n\t\t\tmessage,\n\t\t];\n\n\t\treturn parts.join(' ');\n\t}\n\n\tprivate consoleLog(level: LogLevel, formattedMessage: string, entry: any): void {\n\t\tconst out =\n\t\t\tlevel === LogLevel.ERROR || level === LogLevel.FATAL\n\t\t\t\t? console.error\n\t\t\t\t: level === LogLevel.WARN\n\t\t\t\t\t? console.warn\n\t\t\t\t\t: console.log;\n\n\t\t// inspect with depth:null so nested input payloads and the full error.cause chain\n\t\t// aren't truncated to [Object] the way console.log(obj) does at its default depth of 2.\n\t\tconst dump = (v: unknown) => out(inspect(v, { depth: null, colors: true, breakLength: 120 }));\n\n\t\tout(formattedMessage);\n\t\tif (entry.data && Object.keys(entry.data).length > 0) dump(entry.data);\n\t\tif (entry.error) dump(entry.error);\n\t}\n\n\tprivate async write(\n\t\tlevel: LogLevel,\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t},\n\t\topts: { shouldWrite?: boolean } = {}\n\t) {\n\t\tconst { shouldWrite = true } = opts;\n\t\tconst entry = this.buildLogEntry(message, payload);\n\n\t\t// Console logging with switch case\n\t\tif (shouldWrite) {\n\t\t\tconst formattedMessage = this.formatLogMessage(level, message, entry);\n\t\t\tthis.consoleLog(level, formattedMessage, entry);\n\t\t}\n\n\t\t// Async persistence (fire-and-forget)\n\t\tif (this.shouldPersist(level)) {\n\t\t\treturn this.persistLog({\n\t\t\t\tlevel,\n\t\t\t\ttag: payload.tag,\n\t\t\t\tmessage,\n\t\t\t\tdata: entry.data,\n\t\t\t\tmetadata: entry.metadata ?? {},\n\t\t\t\terror: payload.error,\n\t\t\t\trequestId: entry.requestId,\n\t\t\t\tcontext: payload.context,\n\t\t\t\trequest: payload.request,\n\t\t\t\tresponse: payload.response,\n\t\t\t\tstatus: payload.status,\n\t\t\t}).catch(e => {\n\t\t\t\tconsole.error('Something went wrong', e);\n\t\t\t});\n\t\t}\n\t}\n\n\t/* ---------------------------------- */\n\t/* Public Logging API */\n\t/* ---------------------------------- */\n\n\tinfo(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.INFO, message, options);\n\t}\n\n\tdebug(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.DEBUG, message, options);\n\t}\n\n\twarn(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t\terror?: TRPCError | Error | unknown;\n\t\t}\n\t) {\n\t\tconst { error, ...rest } = options;\n\t\treturn this.write(LogLevel.WARN, message, {\n\t\t\t...rest,\n\t\t\t...(error !== undefined && { error: this.normalizeError(error) }),\n\t\t});\n\t}\n\n\terror(\n\t\tmessage: string,\n\t\terror: TRPCError | Error | unknown,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.ERROR, message, {\n\t\t\t...options,\n\t\t\terror: this.normalizeError(error),\n\t\t});\n\t}\n\n\tfatal(\n\t\tmessage: string,\n\t\terror: TRPCError | Error | unknown,\n\t\toptions: {\n\t\t\ttag: LogTag | string;\n\t\t\tdata?: Record<string, any>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t\trequest?: Record<string, any>;\n\t\t\tresponse?: Record<string, any>;\n\t\t\tstatus?: HttpStatus;\n\t\t}\n\t) {\n\t\treturn this.write(LogLevel.FATAL, message, {\n\t\t\t...options,\n\t\t\terror: this.normalizeError(error),\n\t\t});\n\t}\n\n\t/* ---------------------------------- */\n\t/* HTTP Convenience Methods */\n\t/* ---------------------------------- */\n\n\tprivate getHttpLogLevel(statusCode: number): LogLevel {\n\t\tif (statusCode >= 500) return LogLevel.ERROR;\n\t\tif (statusCode >= 400) return LogLevel.WARN;\n\t\treturn LogLevel.INFO;\n\t}\n\n\thttpRequest(method: string, url: string, statusCode: HttpStatus, durationMs: number, userId?: string): void {\n\t\tthis.write(this.getHttpLogLevel(statusCode), 'HTTP request completed', {\n\t\t\ttag: LogTag.HTTP_REQUEST,\n\t\t\tdata: {\n\t\t\t\tmethod,\n\t\t\t\turl,\n\t\t\t\tdurationMs,\n\t\t\t\t...(userId && { userId }),\n\t\t\t},\n\t\t\tmetadata: {\n\t\t\t\t...(userId && { userId }),\n\t\t\t\tresponseTime: durationMs,\n\t\t\t},\n\t\t\tcontext: { method, url },\n\t\t\tstatus: statusCode,\n\t\t});\n\t}\n\n\tchild(defaultContext: {\n\t\ttag?: LogTag | string;\n\t\tdata?: Record<string, any>;\n\t\tmetadata?: LogMetadata;\n\t\trequest?: Record<string, any>;\n\t\tresponse?: Record<string, any>;\n\t\tstatus?: HttpStatus;\n\t}): {\n\t\tinfo: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\tdebug: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\twarn: (message: string, options?: Partial<typeof defaultContext>) => void;\n\t\terror: (message: string, error: Error | ErrorInfo, options?: Partial<typeof defaultContext>) => void;\n\t} {\n\t\treturn {\n\t\t\tinfo: (message, opts = {}) =>\n\t\t\t\tthis.info(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\tdebug: (message, opts = {}) =>\n\t\t\t\tthis.debug(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\twarn: (message, opts = {}) =>\n\t\t\t\tthis.warn(message, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t\terror: (message, error, opts = {}) =>\n\t\t\t\tthis.error(message, error, {\n\t\t\t\t\ttag: opts.tag ?? defaultContext.tag ?? LogTag.HTTP_REQUEST,\n\t\t\t\t\tdata: { ...defaultContext.data, ...opts.data },\n\t\t\t\t\tmetadata: { ...defaultContext.metadata, ...opts.metadata },\n\t\t\t\t\trequest: opts.request ?? defaultContext.request,\n\t\t\t\t\tresponse: opts.response ?? defaultContext.response,\n\t\t\t\t\tstatus: opts.status ?? defaultContext.status,\n\t\t\t\t}),\n\t\t};\n\t}\n}\n\nexport function withRequestContext<T>(store: RequestStore, fn: () => T | Promise<T>): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\trequestContext.run(store, async () => {\n\t\t\ttry {\n\t\t\t\tresolve(await fn());\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t});\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/logger-kit/types.ts"],"names":[],"mappings":"","sourcesContent":["import { LogLevel } from '../../utilities/enum';\n\nexport interface LoggerConfig {\n\tinstanceType: string;\n\tmongoURI: string;\n\tttlDays?: number;\n\tenableConsole?: boolean;\n\tenableFile?: boolean;\n\tenableMongo?: boolean;\n\tlogDirectory?: string;\n\tminLevel?: LogLevel;\n}\n\nexport interface LogMetadata {\n\tuserId?: string;\n\tsessionId?: string;\n\tipAddress?: string;\n\tuserAgent?: string;\n\n\t[key: string]: unknown;\n}\n\nexport interface ErrorInfo {\n\tcode?: string | number;\n\tmessage?: string;\n\tstacktrace?: string[];\n\tname?: string;\n\n\t[key: string]: unknown;\n}\n\nexport interface RequestContext {\n\trequestId?: string;\n\tmethod?: string;\n\turl?: string;\n\theaders?: Record<string, string>;\n\tquery?: Record<string, unknown>;\n\tparams?: Record<string, unknown>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/logger-kit/types.ts"],"names":[],"mappings":"","sourcesContent":["import { LogLevel } from '../../utilities/enum';\n\nexport interface LoggerConfig {\n\tinstanceType: string;\n\tmongoURI: string;\n\tttlDays?: number;\n\tenableConsole?: boolean;\n\tenableFile?: boolean;\n\tenableMongo?: boolean;\n\tlogDirectory?: string;\n\tminLevel?: LogLevel;\n}\n\nexport interface LogMetadata {\n\tuserId?: string;\n\tsessionId?: string;\n\tipAddress?: string;\n\tuserAgent?: string;\n\n\t[key: string]: unknown;\n}\n\nexport interface ErrorInfo {\n\tcode?: string | number;\n\tmessage?: string;\n\tstacktrace?: string[];\n\tname?: string;\n\tcause?: ErrorInfo;\n\n\t[key: string]: unknown;\n}\n\nexport interface RequestContext {\n\trequestId?: string;\n\tmethod?: string;\n\turl?: string;\n\theaders?: Record<string, string>;\n\tquery?: Record<string, unknown>;\n\tparams?: Record<string, unknown>;\n}\n"]}
|
|
@@ -25,6 +25,7 @@ let LimitedTimeOfferParticipant = class LimitedTimeOfferParticipant {
|
|
|
25
25
|
isWithdrawn;
|
|
26
26
|
withdrawnAt;
|
|
27
27
|
marketing;
|
|
28
|
+
pausedMarketings;
|
|
28
29
|
};
|
|
29
30
|
exports.LimitedTimeOfferParticipant = LimitedTimeOfferParticipant;
|
|
30
31
|
__decorate([
|
|
@@ -75,6 +76,10 @@ __decorate([
|
|
|
75
76
|
(0, typegoose_1.prop)({ ref: 'Marketing' }),
|
|
76
77
|
__metadata("design:type", Object)
|
|
77
78
|
], LimitedTimeOfferParticipant.prototype, "marketing", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, typegoose_1.prop)({ ref: 'Marketing', type: () => [mongoose_1.Types.ObjectId], default: [] }),
|
|
81
|
+
__metadata("design:type", Array)
|
|
82
|
+
], LimitedTimeOfferParticipant.prototype, "pausedMarketings", void 0);
|
|
78
83
|
exports.LimitedTimeOfferParticipant = LimitedTimeOfferParticipant = __decorate([
|
|
79
84
|
(0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'limitedTimeOfferParticipants', timestamps: true } })
|
|
80
85
|
], LimitedTimeOfferParticipant);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.model.js","sourceRoot":"/","sources":["libraries/mongo/models/limited-time-offer-participant.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAG/D,uCAAiC;AAK1B,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAEvC,QAAQ,CAAgC;IAGxC,IAAI,CAAY;IAGhB,QAAQ,CAAO;IAGf,QAAQ,CAAiB;IAGzB,YAAY,CAAU;IAGtB,kBAAkB,CAAU;IAG5B,cAAc,CAAU;IAGxB,sBAAsB,CAAU;IAGhC,gBAAgB,CAAU;IAG1B,WAAW,CAAU;IAGrB,WAAW,CAAQ;IAGnB,SAAS,CAAkB;
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.model.js","sourceRoot":"/","sources":["libraries/mongo/models/limited-time-offer-participant.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAG/D,uCAAiC;AAK1B,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAEvC,QAAQ,CAAgC;IAGxC,IAAI,CAAY;IAGhB,QAAQ,CAAO;IAGf,QAAQ,CAAiB;IAGzB,YAAY,CAAU;IAGtB,kBAAkB,CAAU;IAG5B,cAAc,CAAU;IAGxB,sBAAsB,CAAU;IAGhC,gBAAgB,CAAU;IAG1B,WAAW,CAAU;IAGrB,WAAW,CAAQ;IAGnB,SAAS,CAAkB;IAI3B,gBAAgB,CAAoB;CACpC,CAAA;AAxCY,kEAA2B;AAEvC;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,0BAA0B,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6DAClB;AAGxC;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;yDACtB;AAGhB;IADC,IAAA,gBAAI,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;8BAClB,IAAI;6DAAC;AAGf;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;6DAC3C;AAGzB;IADC,IAAA,gBAAI,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;iEACH;AAGtB;IADC,IAAA,gBAAI,GAAE;;uEACqB;AAG5B;IADC,IAAA,gBAAI,GAAE;;mEACiB;AAGxB;IADC,IAAA,gBAAI,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;2EACO;AAGhC;IADC,IAAA,gBAAI,GAAE;;qEACmB;AAG1B;IADC,IAAA,gBAAI,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;gEACJ;AAGrB;IADC,IAAA,gBAAI,GAAE;8BACO,IAAI;gEAAC;AAGnB;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC;;8DACA;AAI3B;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;qEAClC;sCAvCxB,2BAA2B;IADvC,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,8BAA8B,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;GACrF,2BAA2B,CAwCvC","sourcesContent":["import { modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { LimitedTimeOfferCampaign } from './limited-time-offer-campaign.model';\nimport { Shop } from './shop.model';\nimport { Types } from 'mongoose';\nimport { Product } from './product.model';\nimport { Marketing } from './marketing.model';\n\n@modelOptions({ schemaOptions: { collection: 'limitedTimeOfferParticipants', timestamps: true } })\nexport class LimitedTimeOfferParticipant {\n\t@prop({ ref: 'LimitedTimeOfferCampaign', required: true })\n\tcampaign: Ref<LimitedTimeOfferCampaign>;\n\n\t@prop({ ref: 'Shop', required: true })\n\tshop: Ref<Shop>;\n\n\t@prop({ default: Date.now })\n\tjoinedAt: Date;\n\n\t@prop({ ref: 'Product', type: () => [Types.ObjectId], default: [] })\n\tproducts: Ref<Product>[];\n\n\t@prop({ default: false })\n\tisEntireMenu: boolean;\n\n\t@prop()\n\tdiscountPercentage?: number;\n\n\t@prop()\n\tmaxDiscountCap?: number;\n\n\t@prop({ default: false })\n\tisOrderCapacityEnabled: boolean;\n\n\t@prop()\n\tmaxOrderCapacity?: number;\n\t\n\t@prop({ default: false })\n\tisWithdrawn: boolean;\n\n\t@prop()\n\twithdrawnAt?: Date;\n\n\t@prop({ ref: 'Marketing' })\n\tmarketing?: Ref<Marketing>;\n\n\t// Shop discounts paused when this shop joined the LTO; resumed on withdraw/expire/cancel/admin-remove.\n\t@prop({ ref: 'Marketing', type: () => [Types.ObjectId], default: [] })\n\tpausedMarketings?: Ref<Marketing>[];\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ref } from '@typegoose/typegoose';
|
|
2
2
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
3
|
-
import { MarketingStatus, MarketingType } from '../../../utilities/enum';
|
|
3
|
+
import { MarketingCampaignType, MarketingStatus, MarketingType } from '../../../utilities/enum';
|
|
4
4
|
import { Duration } from './shared/duration.model';
|
|
5
5
|
import { Shop } from './shop.model';
|
|
6
6
|
import { Admin } from './admin.model';
|
|
@@ -9,6 +9,7 @@ export declare class Marketing extends TimeStamps {
|
|
|
9
9
|
shop: Ref<Shop>;
|
|
10
10
|
marketingType: MarketingType;
|
|
11
11
|
isAppliedByCompany: boolean;
|
|
12
|
+
campaignType?: MarketingCampaignType;
|
|
12
13
|
duration: Duration;
|
|
13
14
|
status?: MarketingStatus;
|
|
14
15
|
pausedAt?: Date | null;
|
|
@@ -21,6 +21,7 @@ let Marketing = class Marketing extends defaultClasses_1.TimeStamps {
|
|
|
21
21
|
shop;
|
|
22
22
|
marketingType;
|
|
23
23
|
isAppliedByCompany;
|
|
24
|
+
campaignType;
|
|
24
25
|
duration;
|
|
25
26
|
status;
|
|
26
27
|
pausedAt;
|
|
@@ -44,6 +45,10 @@ __decorate([
|
|
|
44
45
|
(0, typegoose_1.prop)({ required: true, type: Boolean }),
|
|
45
46
|
__metadata("design:type", Boolean)
|
|
46
47
|
], Marketing.prototype, "isAppliedByCompany", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.MarketingCampaignType, default: enum_1.MarketingCampaignType.STANDARD }),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], Marketing.prototype, "campaignType", void 0);
|
|
47
52
|
__decorate([
|
|
48
53
|
(0, typegoose_1.prop)({ required: true, type: duration_model_1.Duration }),
|
|
49
54
|
__metadata("design:type", duration_model_1.Duration)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.model.js","sourceRoot":"/","sources":["libraries/mongo/models/marketing.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"marketing.model.js","sourceRoot":"/","sources":["libraries/mongo/models/marketing.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,kDAAgG;AAChG,4DAAmD;AACnD,6CAAoC;AACpC,+CAAsC;AAY/B,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,2BAAU;IAEjC,KAAK,CAAc;IAGnB,IAAI,CAAa;IAGjB,aAAa,CAAiB;IAG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C,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACK;oBAjChB,SAAS;IAVrB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,YAAY;YACxB,gBAAgB,EAAE,eAAe;YACjC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC5B,EAAE,EAAE,KAAK;SACT;KACD,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;GAC5C,SAAS,CAkCrB","sourcesContent":["import { Index, modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { MarketingCampaignType, MarketingStatus, MarketingType } from '../../../utilities/enum';\nimport { Duration } from './shared/duration.model';\nimport { Shop } from './shop.model';\nimport { Admin } from './admin.model';\n\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'marketings',\n\t\tdiscriminatorKey: 'marketingType',\n\t\ttoJSON: { virtuals: true },\n\t\ttoObject: { virtuals: true },\n\t\tid: false,\n\t},\n})\n@Index({ shop: 1, status: 1, duration: 1, deletedAt: 1 })\nexport class Marketing extends TimeStamps {\n\t@prop({ ref: () => Admin })\n\tpublic admin?: Ref<Admin>;\n\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ required: true, type: String, enum: MarketingType })\n\tpublic marketingType!: MarketingType;\n\n\t@prop({ required: true, type: Boolean })\n\tpublic isAppliedByCompany!: boolean;\n\n\t@prop({ type: String, enum: MarketingCampaignType, default: MarketingCampaignType.STANDARD })\n\tpublic campaignType?: MarketingCampaignType;\n\n\t@prop({ required: true, type: Duration })\n\tpublic duration!: Duration;\n\n\t@prop({\n\t\ttype: String,\n\t\tenum: MarketingStatus,\n\t\tdefault: MarketingStatus.ACTIVE,\n\t})\n\tpublic status?: MarketingStatus;\n\n\t@prop({ type: Date, default: null })\n\tpublic pausedAt?: Date | null;\n\n\t@prop({ type: Date, default: null })\n\tpublic expiredAt?: Date | null;\n\n\t@prop({ type: Number })\n\tpublic amountSpent?: number;\n}\n"]}
|
|
@@ -5,6 +5,7 @@ exports.withUserContext = withUserContext;
|
|
|
5
5
|
const mongoose_1 = require("mongoose");
|
|
6
6
|
const auth_ref_mapper_1 = require("../../utilities/auth-ref.mapper");
|
|
7
7
|
const createLyxaContext = async (opts) => {
|
|
8
|
+
opts.req._startTime = Date.now();
|
|
8
9
|
return {
|
|
9
10
|
entity: undefined,
|
|
10
11
|
requestId: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"/","sources":["libraries/trpc/context.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"/","sources":["libraries/trpc/context.ts"],"names":[],"mappings":";;;AA8EA,0CAUC;AAlFD,uCAAiC;AACjC,qEAAyE;AA2BlE,MAAM,iBAAiB,GAAG,KAAK,EACrC,IAAgG,EACrE,EAAE;IAG5B,IAAI,CAAC,GAAW,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1C,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAEK,MAAM,mBAAmB,GAAG,KAAK,EAAE,IAA+B,EAA0B,EAAE;IACpG,OAAO;QACN,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B;AAiBF,SAAgB,eAAe,CAAmB,KAAQ,EAAE,GAAgB;IAC3E,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAErD,OAAO;QACN,GAAG,KAAK;QACR,IAAI,EAAE,IAAI,gBAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,QAAQ,EAAE,wCAAsB,CAAC,MAAM,CAAC,IAAI,CAAC;QAC7C,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,IAAyC;KACtE,CAAC;AACH,CAAC","sourcesContent":["import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';\nimport type { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';\nimport type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws';\nimport { AuthEntityType, TokenType } from '../auth';\nimport jwt from 'jsonwebtoken';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport { Types } from 'mongoose';\nimport { AuthEntityToUserRefMap } from '../../utilities/auth-ref.mapper';\nimport { AdminRole, ShopRole, UserRef, VendorRole } from '../../utilities/enum';\n\nexport interface EntityContext extends jwt.JwtPayload {\n\tid: string;\n\ttype: AuthEntityType;\n\tparameters: Record<string, unknown>;\n}\n\nexport interface LyxaContextParams {\n\tentity?: EntityContext;\n\trequestId?: string;\n\ttokenType?: TokenType;\n\tusedRefreshToken?: boolean;\n\ttokenRenewed?: boolean;\n}\n\nexport interface LyxaHTTPContext extends LyxaContextParams {\n\treq: IncomingMessage;\n\tres: ServerResponse;\n}\n\nexport interface LyxaWSContext extends LyxaContextParams {\n\treq: any;\n\tres: any;\n}\n\nexport const createLyxaContext = async (\n\topts: CreateHTTPContextOptions | NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>\n): Promise<LyxaHTTPContext> => {\n\t// Stamp request start so the error handler can report duration. ponytail: cheapest\n\t// place to time every request without adding a dedicated timing middleware.\n\t(opts.req as any)._startTime = Date.now();\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport const createLyxaWsContext = async (opts: CreateWSSContextFnOptions): Promise<LyxaWSContext> => {\n\treturn {\n\t\tentity: undefined,\n\t\trequestId: undefined,\n\t\ttokenType: undefined,\n\t\tusedRefreshToken: false,\n\t\ttokenRenewed: false,\n\t\treq: opts.req,\n\t\tres: opts.res,\n\t};\n};\n\nexport type UserInfo = {\n\tuser: Types.ObjectId;\n\tuserType: UserRef;\n\tuserRole: AdminRole | VendorRole | ShopRole;\n};\n\n/**\n *\n * Enriches the input object with user context information from the LyxaContext.\n *\n * @param input\n * @param ctx\n *\n * @example const inp: SendMessageDTO = withUserContext(input, ctx);\n */\nexport function withUserContext<T extends object>(input: T, ctx: LyxaContext): T & UserInfo {\n\tconst entity = ctx.entity;\n\tif (!entity) throw new Error('No entity in context');\n\n\treturn {\n\t\t...input,\n\t\tuser: new Types.ObjectId(entity.id),\n\t\tuserType: AuthEntityToUserRefMap[entity.type],\n\t\tuserRole: entity.parameters?.role as AdminRole | VendorRole | ShopRole,\n\t};\n}\n\nexport type LyxaContext = Awaited<ReturnType<typeof createLyxaContext>>;\n"]}
|
|
@@ -12,7 +12,6 @@ exports.t = server_1.initTRPC.context().create({
|
|
|
12
12
|
const flattened = error.cause.flatten();
|
|
13
13
|
zodErrors = flattened.fieldErrors;
|
|
14
14
|
}
|
|
15
|
-
console.log('Error:', error, shape, 'error log', zodErrors);
|
|
16
15
|
return {
|
|
17
16
|
...shape,
|
|
18
17
|
message: zodErrors && typeof zodErrors === 'object'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/trpc/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AACxC,6BAA+B;AAE/B,uCAA2C;AAC3C,+CAA8C;AAEjC,QAAA,CAAC,GAAG,iBAAQ,CAAC,OAAO,EAAe,CAAC,MAAM,CAAC;IACvD,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE;QAC9B,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,KAAK,YAAY,cAAQ,EAAE,CAAC;YACrE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACxC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC;QACnC,CAAC;QAED,OAAO
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/trpc/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AACxC,6BAA+B;AAE/B,uCAA2C;AAC3C,+CAA8C;AAEjC,QAAA,CAAC,GAAG,iBAAQ,CAAC,OAAO,EAAe,CAAC,MAAM,CAAC;IACvD,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE;QAC9B,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,KAAK,YAAY,cAAQ,EAAE,CAAC;YACrE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACxC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC;QACnC,CAAC;QAED,OAAO;YACN,GAAG,KAAK;YACR,OAAO,EACN,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;gBACzC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,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A;AAC1B,sDAAqD;AAA5C,wGAAA,UAAU,OAAA;AACnB,uCAAyC;AAAhC,mGAAA,SAAS,OAAA","sourcesContent":["import { initTRPC } from '@trpc/server';\nimport { ZodError } from 'zod';\nimport { LyxaContext } from './context';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nexport const t = initTRPC.context<LyxaContext>().create({\n\terrorFormatter({ shape, error }) {\n\t\tlet zodErrors = null;\n\n\t\tif (error.code === 'BAD_REQUEST' && error.cause instanceof ZodError) {\n\t\t\tconst flattened = error.cause.flatten();\n\t\t\tzodErrors = flattened.fieldErrors;\n\t\t}\n\n\t\treturn {\n\t\t\t...shape,\n\t\t\tmessage:\n\t\t\t\tzodErrors && typeof zodErrors === 'object'\n\t\t\t\t\t? Object.values(zodErrors)[0]?.[0] || shape.message\n\t\t\t\t\t: shape.message,\n\t\t\tdata: {\n\t\t\t\t...shape.data,\n\n\t\t\t\tstack: undefined,\n\t\t\t\tpath: undefined,\n\t\t\t},\n\t\t\t// Prevent stack trace from being returned in the response\n\t\t\tstack: undefined,\n\t\t};\n\t},\n});\n\ninterface SlowApiLogEntry {\n\ttimestamp: string;\n\tpath: string;\n\tduration: number;\n\tinput?: any;\n\theaders?: Record<string, string | string[] | undefined>;\n\ttoken?: string;\n\tuserId?: string;\n\tuserType?: string;\n}\n\nconst SLOW_API_THRESHOLD_MS = 10000; // 10 second\n\nconst LOG_SLOW_API_INPUT = true;\n\nexport const slowApiMiddleware = t.middleware(async ({ path, ctx, next }) => {\n\tconst logger = getLibraries().getLoggerKit();\n\tconst startTime = Date.now();\n\n\tconst result = await next();\n\n\tconst duration = Date.now() - startTime;\n\n\tif (duration > SLOW_API_THRESHOLD_MS) {\n\t\tconst url = ctx.req?.url ?? '';\n\t\tconst searchParams = new URL(url, 'http://localhost').searchParams;\n\n\t\tlet parsedInput: unknown;\n\t\tconst rawInputParam = searchParams.get('input');\n\t\tif (rawInputParam) {\n\t\t\ttry {\n\t\t\t\tparsedInput = JSON.parse(rawInputParam);\n\t\t\t} catch {\n\t\t\t\tparsedInput = rawInputParam;\n\t\t\t}\n\t\t} else {\n\t\t\tconst allParams = Object.fromEntries(searchParams.entries());\n\t\t\tif (Object.keys(allParams).length > 0) parsedInput = allParams;\n\t\t}\n\n\t\tconst authHeader = ctx.req?.headers?.authorization ?? '';\n\t\tconst token = authHeader.startsWith('Bearer ') ? authHeader.slice(7) : authHeader || undefined;\n\n\t\tconst logEntry: SlowApiLogEntry & { message: string } = {\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpath,\n\t\t\tduration,\n\t\t\tuserId: ctx.entity?.id,\n\t\t\tuserType: ctx.entity?.type,\n\t\t\tinput: LOG_SLOW_API_INPUT ? parsedInput : undefined,\n\t\t\theaders: ctx.req?.headers ?? {},\n\t\t\ttoken,\n\t\t\tmessage: `Slow API call detected: ${path} took ${duration}ms`,\n\t\t};\n\n\t\tlogger.warn(logEntry.message, { tag: LogTag.SLOW_API, data: logEntry });\n\t}\n\n\treturn result;\n});\n\nexport const publicProcedure = t.procedure.use(slowApiMiddleware);\nexport const createTRPCRouter = t.router;\nexport const createCallerFactory = t.createCallerFactory;\n\nexport type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';\nexport type { AnyTRPCRouter } from '@trpc/server';\nexport { createHTTPHandler } from '@trpc/server/adapters/standalone';\nexport { observable } from '@trpc/server/observable';\nexport { TRPCError } from '@trpc/server';\n\nexport type LyxaRouter = ReturnType<typeof createTRPCRouter>;"]}
|
|
@@ -5,9 +5,9 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
req: import("http").IncomingMessage;
|
|
9
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
9
|
tokenType: TokenType | undefined;
|
|
10
|
+
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
entity: import("../context").EntityContext | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
|
|
|
4
4
|
allowedRoles: string[];
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
|
-
req: import("http").IncomingMessage;
|
|
8
7
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
8
|
tokenType: import("../../auth").TokenType | undefined;
|
|
9
|
+
req: import("http").IncomingMessage;
|
|
10
10
|
requestId: string | undefined;
|
|
11
11
|
entity: import("../context").EntityContext | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
|
|
|
3
3
|
entityTypes: AuthEntityType[];
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
|
-
req: import("http").IncomingMessage;
|
|
7
6
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
7
|
tokenType: import("../../auth").TokenType | undefined;
|
|
8
|
+
req: import("http").IncomingMessage;
|
|
9
9
|
requestId: string | undefined;
|
|
10
10
|
entity: import("../context").EntityContext | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
@@ -5,9 +5,9 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
req: import("http").IncomingMessage;
|
|
9
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
9
|
tokenType: TokenType | undefined;
|
|
10
|
+
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
entity: import("../context").EntityContext | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -497,6 +497,10 @@ export declare enum MarketingStatus {
|
|
|
497
497
|
EXPIRED = "expired",
|
|
498
498
|
DELETED = "deleted"
|
|
499
499
|
}
|
|
500
|
+
export declare enum MarketingCampaignType {
|
|
501
|
+
STANDARD = "standard",
|
|
502
|
+
LIMITED_TIME_OFFER = "limited_time_offer"
|
|
503
|
+
}
|
|
500
504
|
export declare enum PunchMarketingStatus {
|
|
501
505
|
ACTIVE = "active",
|
|
502
506
|
COMPLETED = "completed",
|
|
@@ -1085,7 +1089,7 @@ export declare enum SyncCacheEnumType {
|
|
|
1085
1089
|
}
|
|
1086
1090
|
export declare enum LogLevel {
|
|
1087
1091
|
INFO = "info",
|
|
1088
|
-
WARN = "
|
|
1092
|
+
WARN = "warn",
|
|
1089
1093
|
ERROR = "error",
|
|
1090
1094
|
DEBUG = "debug",
|
|
1091
1095
|
FATAL = "fatal"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BobChannelType = exports.BobModel = exports.BobSettlementStatus = exports.BobSettlementType = exports.BobAccountType = exports.ZoneStatus = exports.FaqAccountType = exports.CounterType = exports.BannerUserType = exports.BannerLinkType = exports.BannerClickType = exports.VendorRole = exports.ShopRole = exports.OnlineStatus = exports.ShopOnlineStatus = exports.ChargeType = exports.ClickType = exports.NotificationAccountType = exports.DishCategory = exports.ProductDietaryType = exports.ShopDietaryType = exports.PriceOption = exports.ProductType = exports.CoreAuthIdentityType = exports.ShopSectionMode = exports.UserAppSectionItemType = exports.UserAppSectionType = exports.AdminLogsUpdatedFieldsType = exports.UpdatedField = exports.GeoLocationType = exports.RatingAccountType = exports.SubscriptionStatus = exports.SubscriptionPackage = exports.PaidCurrency = exports.PaymentStatus = exports.ChangeReturnMethod = exports.PaymentMethod = exports.ValueType = exports.HolidayWorkStatus = exports.WorkStatus = exports.WeekDay = exports.GlobalItemType = exports.AdjustmentStatus = exports.ServiceItemType = exports.ItemType = exports.Status = exports.AppPlatform = exports.AccountType = exports.AgentLiveStatus = exports.AuthEntityType = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.TimeUnit = exports.CancellationReschedulingFeeType = exports.CartType = exports.TournamentParticipantStatus = exports.TournamentMatchStatus = exports.TournamentScheduledNotificationTarget = exports.TournamentNotificationTag = exports.TournamentProvider = exports.TournamentRewardType = exports.OnlinePaymentStatus = exports.BarcodeTypes = exports.RiderScoreEventTag = exports.AreebaPaymentType = exports.HttpStatus = exports.LogTag = exports.LogLevel = exports.SyncCacheEnumType = exports.DateFormatType = exports.AppAppearanceType = exports.GraphType = exports.CalendarEventType = void 0;
|
|
4
|
+
exports.PlusSettingsPackageType = exports.AddRemoveCreditSettlementType = exports.SettlementType = exports.MediaType = exports.WorkingHourSettingsType = exports.ZoneGeometryType = exports.RiderAssignmentStatus = exports.CourierServiceType = exports.TripLegStatus = exports.DeliveryStatus = exports.CourierOrderPaymentFrom = exports.UserActionReason = exports.UserActionType = exports.ShopCourierOrderStatus = exports.ServiceBookingStatus = exports.CourierOrderStatus = exports.RegularOrderStatus = exports.AdjustmentType = exports.ServiceBookingStatusTimelineType = exports.StatusTimelineType = exports.DeliveryChargeType = exports.OrderType = exports.Language = exports.OrderSize = exports.RiderBagSize = exports.RiderType = exports.ShiftType = exports.CreatedBy = exports.RiderCashEventTag = exports.RiderCashLimitReason = exports.RiderAvailability = exports.LiveStatus = exports.PaymentIntentStatus = exports.CardStatus = exports.CardUserType = exports.PaymentProvider = exports.CardType = exports.PaymentPreference = exports.CartStatus = exports.LimitedTimeOfferCampaignStatus = exports.AdminRole = exports.PunchMarketingStatus = exports.MarketingCampaignType = exports.MarketingStatus = exports.ServiceMarketingType = exports.MarketingType = exports.FavouriteType = exports.CouponExpirationReason = exports.CouponType = exports.BobType = void 0;
|
|
5
|
+
exports.LyxaTimeZoneEnum = exports.UserOrderCompletionScope = exports.GroupCartNotificationStatus = exports.Currency = exports.RequestFrom = exports.UploadState = exports.SubServiceType = exports.ServiceType = exports.ActionType = exports.DeviceType = exports.PushNotificationEventType = exports.SocketEventType = exports.SocketServiceQueue = exports.OtpMethodType = exports.ReviewType = exports.FoodNutritionType = exports.AdjustmentReason = exports.UrgentOrderReasons = exports.ServiceFlagReasonType = exports.ServiceFlagType = exports.FlagReasonType = exports.FlagType = exports.PromotionType = exports.ServiceBookingCanceledBy = exports.TRPCErrorEnum = exports.ShopFilterSortByEnum = exports.BookingStatus = exports.ProfessionalScheduleType = exports.ServiceBookingRecurrencePattern = exports.ProfessionalRecurrencePattern = exports.ServiceBookingPriority = exports.ProfessionalStatus = exports.Service = exports.ServiceLineItemType = exports.ServiceCartStatus = exports.ChatroomType = exports.UserRef = exports.TicketStatus = exports.TicketType = exports.RewardedToTypeEnum = exports.ReplacementType = exports.ReplacementReason = exports.OrderCanceledBy = exports.LogUser = exports.PayoutStatus = exports.PayoutType = exports.AddRemoveCreditAccountType = exports.SettingsReasonStatus = exports.CancellationReasonTypeEnum = exports.SupportReasonTypeEnum = void 0;
|
|
6
|
+
exports.TimeUnit = exports.CancellationReschedulingFeeType = exports.CartType = exports.TournamentParticipantStatus = exports.TournamentMatchStatus = exports.TournamentScheduledNotificationTarget = exports.TournamentNotificationTag = exports.TournamentProvider = exports.TournamentRewardType = exports.OnlinePaymentStatus = exports.BarcodeTypes = exports.RiderScoreEventTag = exports.AreebaPaymentType = exports.HttpStatus = exports.LogTag = exports.LogLevel = exports.SyncCacheEnumType = exports.DateFormatType = exports.AppAppearanceType = exports.GraphType = exports.CalendarEventType = exports.CalendarViewType = void 0;
|
|
7
7
|
var AuthEntityType;
|
|
8
8
|
(function (AuthEntityType) {
|
|
9
9
|
AuthEntityType["USER"] = "USER";
|
|
@@ -560,6 +560,11 @@ var MarketingStatus;
|
|
|
560
560
|
MarketingStatus["EXPIRED"] = "expired";
|
|
561
561
|
MarketingStatus["DELETED"] = "deleted";
|
|
562
562
|
})(MarketingStatus || (exports.MarketingStatus = MarketingStatus = {}));
|
|
563
|
+
var MarketingCampaignType;
|
|
564
|
+
(function (MarketingCampaignType) {
|
|
565
|
+
MarketingCampaignType["STANDARD"] = "standard";
|
|
566
|
+
MarketingCampaignType["LIMITED_TIME_OFFER"] = "limited_time_offer";
|
|
567
|
+
})(MarketingCampaignType || (exports.MarketingCampaignType = MarketingCampaignType = {}));
|
|
563
568
|
var PunchMarketingStatus;
|
|
564
569
|
(function (PunchMarketingStatus) {
|
|
565
570
|
PunchMarketingStatus["ACTIVE"] = "active";
|
|
@@ -1247,7 +1252,7 @@ var SyncCacheEnumType;
|
|
|
1247
1252
|
var LogLevel;
|
|
1248
1253
|
(function (LogLevel) {
|
|
1249
1254
|
LogLevel["INFO"] = "info";
|
|
1250
|
-
LogLevel["WARN"] = "
|
|
1255
|
+
LogLevel["WARN"] = "warn";
|
|
1251
1256
|
LogLevel["ERROR"] = "error";
|
|
1252
1257
|
LogLevel["DEBUG"] = "debug";
|
|
1253
1258
|
LogLevel["FATAL"] = "fatal";
|