@lyxa.ai/core 1.3.192 → 1.3.194
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 +26 -8
- package/dist/libraries/logger-kit/logger.service.js +33 -5
- package/dist/libraries/logger-kit/logger.service.js.map +1 -1
- package/dist/libraries/logger-kit/types.d.ts +3 -5
- package/dist/libraries/logger-kit/types.js.map +1 -1
- package/dist/libraries/mongo/models/card.model.d.ts +19 -0
- package/dist/libraries/mongo/models/card.model.js +88 -0
- package/dist/libraries/mongo/models/card.model.js.map +1 -0
- package/dist/libraries/mongo/models/index.d.ts +2 -0
- package/dist/libraries/mongo/models/index.js +9 -0
- package/dist/libraries/mongo/models/index.js.map +1 -1
- package/dist/libraries/mongo/models/log.model.d.ts +11 -6
- package/dist/libraries/mongo/models/log.model.js +18 -8
- package/dist/libraries/mongo/models/log.model.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/enum.d.ts +63 -3
- package/dist/types/utilities/enum.js +74 -13
- package/dist/types/utilities/enum.js.map +1 -1
- package/dist/utilities/enum.d.ts +63 -3
- package/dist/utilities/enum.js +74 -13
- package/dist/utilities/enum.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Log } from '../mongo/models';
|
|
2
|
-
import { LogTag } from '../../utilities/enum';
|
|
2
|
+
import { HttpStatus, LogTag } from '../../utilities/enum';
|
|
3
3
|
import { ErrorInfo, LogMetadata, RequestContext } from './types';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
import mongoose from 'mongoose';
|
|
@@ -36,8 +36,11 @@ export declare class LyxaLoggerKit {
|
|
|
36
36
|
private write;
|
|
37
37
|
info(message: string, options: {
|
|
38
38
|
tag: LogTag;
|
|
39
|
-
data?: any
|
|
39
|
+
data?: Record<string, any>;
|
|
40
40
|
metadata?: LogMetadata;
|
|
41
|
+
request?: Record<string, any>;
|
|
42
|
+
response?: Record<string, any>;
|
|
43
|
+
status?: HttpStatus;
|
|
41
44
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
42
45
|
_id: mongoose.Types.ObjectId;
|
|
43
46
|
} & {
|
|
@@ -45,8 +48,11 @@ export declare class LyxaLoggerKit {
|
|
|
45
48
|
}, "typegooseName"> & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)>;
|
|
46
49
|
debug(message: string, options: {
|
|
47
50
|
tag: LogTag;
|
|
48
|
-
data?: any
|
|
51
|
+
data?: Record<string, any>;
|
|
49
52
|
metadata?: LogMetadata;
|
|
53
|
+
request?: Record<string, any>;
|
|
54
|
+
response?: Record<string, any>;
|
|
55
|
+
status?: HttpStatus;
|
|
50
56
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
51
57
|
_id: mongoose.Types.ObjectId;
|
|
52
58
|
} & {
|
|
@@ -54,8 +60,11 @@ export declare class LyxaLoggerKit {
|
|
|
54
60
|
}, "typegooseName"> & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)>;
|
|
55
61
|
warn(message: string, options: {
|
|
56
62
|
tag: LogTag;
|
|
57
|
-
data?: any
|
|
63
|
+
data?: Record<string, any>;
|
|
58
64
|
metadata?: LogMetadata;
|
|
65
|
+
request?: Record<string, any>;
|
|
66
|
+
response?: Record<string, any>;
|
|
67
|
+
status?: HttpStatus;
|
|
59
68
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
60
69
|
_id: mongoose.Types.ObjectId;
|
|
61
70
|
} & {
|
|
@@ -63,9 +72,12 @@ export declare class LyxaLoggerKit {
|
|
|
63
72
|
}, "typegooseName"> & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)>;
|
|
64
73
|
error(message: string, error: TRPCError | Error | unknown, options: {
|
|
65
74
|
tag: LogTag;
|
|
66
|
-
data?: any
|
|
75
|
+
data?: Record<string, any>;
|
|
67
76
|
metadata?: LogMetadata;
|
|
68
77
|
context?: RequestContext;
|
|
78
|
+
request?: Record<string, any>;
|
|
79
|
+
response?: Record<string, any>;
|
|
80
|
+
status?: HttpStatus;
|
|
69
81
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
70
82
|
_id: mongoose.Types.ObjectId;
|
|
71
83
|
} & {
|
|
@@ -73,20 +85,26 @@ export declare class LyxaLoggerKit {
|
|
|
73
85
|
}, "typegooseName"> & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)>;
|
|
74
86
|
fatal(message: string, error: TRPCError | Error | unknown, options: {
|
|
75
87
|
tag: LogTag;
|
|
76
|
-
data?: any
|
|
88
|
+
data?: Record<string, any>;
|
|
77
89
|
metadata?: LogMetadata;
|
|
78
90
|
context?: RequestContext;
|
|
91
|
+
request?: Record<string, any>;
|
|
92
|
+
response?: Record<string, any>;
|
|
93
|
+
status?: HttpStatus;
|
|
79
94
|
}): Promise<void | (mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, Log, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<Log & {
|
|
80
95
|
_id: mongoose.Types.ObjectId;
|
|
81
96
|
} & {
|
|
82
97
|
__v: number;
|
|
83
98
|
}, "typegooseName"> & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)>;
|
|
84
99
|
private getHttpLogLevel;
|
|
85
|
-
httpRequest(method: string, url: string, statusCode:
|
|
100
|
+
httpRequest(method: string, url: string, statusCode: HttpStatus, durationMs: number, userId?: string): void;
|
|
86
101
|
child(defaultContext: {
|
|
87
102
|
tag?: LogTag;
|
|
88
|
-
data?: any
|
|
103
|
+
data?: Record<string, any>;
|
|
89
104
|
metadata?: LogMetadata;
|
|
105
|
+
request?: Record<string, any>;
|
|
106
|
+
response?: Record<string, any>;
|
|
107
|
+
status?: HttpStatus;
|
|
90
108
|
}): {
|
|
91
109
|
info: (message: string, options?: Partial<typeof defaultContext>) => void;
|
|
92
110
|
debug: (message: string, options?: Partial<typeof defaultContext>) => void;
|
|
@@ -79,10 +79,22 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
79
79
|
return {
|
|
80
80
|
name: error.name,
|
|
81
81
|
message: error.message,
|
|
82
|
-
|
|
82
|
+
stacktrace: error.stack?.split('\n').map(line => line.trim()),
|
|
83
|
+
code: error.code,
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
|
-
|
|
86
|
+
if (typeof error === 'object' && error !== null) {
|
|
87
|
+
const err = error;
|
|
88
|
+
return {
|
|
89
|
+
name: err.name,
|
|
90
|
+
message: err.message,
|
|
91
|
+
stacktrace: err.stack?.split('\n').map((line) => line.trim()) || err.stacktrace,
|
|
92
|
+
code: err.code,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
message: String(error),
|
|
97
|
+
};
|
|
86
98
|
}
|
|
87
99
|
buildLogEntry(message, payload) {
|
|
88
100
|
const store = this.getRequestStore();
|
|
@@ -97,6 +109,9 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
97
109
|
error: payload.error,
|
|
98
110
|
context: payload.context,
|
|
99
111
|
requestId: store.requestId,
|
|
112
|
+
request: payload.request,
|
|
113
|
+
response: payload.response,
|
|
114
|
+
status: payload.status,
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
getColorCode(level) {
|
|
@@ -196,9 +211,11 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
196
211
|
data: entry.data,
|
|
197
212
|
metadata: entry.metadata ?? {},
|
|
198
213
|
error: payload.error,
|
|
199
|
-
stackTrace: payload.error?.stack?.split('\n'),
|
|
200
214
|
requestId: entry.requestId,
|
|
201
215
|
context: payload.context,
|
|
216
|
+
request: payload.request,
|
|
217
|
+
response: payload.response,
|
|
218
|
+
status: payload.status,
|
|
202
219
|
}).catch(e => {
|
|
203
220
|
console.error('Something went wrong', e);
|
|
204
221
|
});
|
|
@@ -238,16 +255,15 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
238
255
|
data: {
|
|
239
256
|
method,
|
|
240
257
|
url,
|
|
241
|
-
statusCode,
|
|
242
258
|
durationMs,
|
|
243
259
|
...(userId && { userId }),
|
|
244
260
|
},
|
|
245
261
|
metadata: {
|
|
246
262
|
...(userId && { userId }),
|
|
247
|
-
statusCode,
|
|
248
263
|
responseTime: durationMs,
|
|
249
264
|
},
|
|
250
265
|
context: { method, url },
|
|
266
|
+
status: statusCode,
|
|
251
267
|
});
|
|
252
268
|
}
|
|
253
269
|
child(defaultContext) {
|
|
@@ -256,21 +272,33 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
256
272
|
tag: opts.tag ?? defaultContext.tag ?? enum_1.LogTag.HTTP_REQUEST,
|
|
257
273
|
data: { ...defaultContext.data, ...opts.data },
|
|
258
274
|
metadata: { ...defaultContext.metadata, ...opts.metadata },
|
|
275
|
+
request: opts.request ?? defaultContext.request,
|
|
276
|
+
response: opts.response ?? defaultContext.response,
|
|
277
|
+
status: opts.status ?? defaultContext.status,
|
|
259
278
|
}),
|
|
260
279
|
debug: (message, opts = {}) => this.debug(message, {
|
|
261
280
|
tag: opts.tag ?? defaultContext.tag ?? enum_1.LogTag.HTTP_REQUEST,
|
|
262
281
|
data: { ...defaultContext.data, ...opts.data },
|
|
263
282
|
metadata: { ...defaultContext.metadata, ...opts.metadata },
|
|
283
|
+
request: opts.request ?? defaultContext.request,
|
|
284
|
+
response: opts.response ?? defaultContext.response,
|
|
285
|
+
status: opts.status ?? defaultContext.status,
|
|
264
286
|
}),
|
|
265
287
|
warn: (message, opts = {}) => this.warn(message, {
|
|
266
288
|
tag: opts.tag ?? defaultContext.tag ?? enum_1.LogTag.HTTP_REQUEST,
|
|
267
289
|
data: { ...defaultContext.data, ...opts.data },
|
|
268
290
|
metadata: { ...defaultContext.metadata, ...opts.metadata },
|
|
291
|
+
request: opts.request ?? defaultContext.request,
|
|
292
|
+
response: opts.response ?? defaultContext.response,
|
|
293
|
+
status: opts.status ?? defaultContext.status,
|
|
269
294
|
}),
|
|
270
295
|
error: (message, error, opts = {}) => this.error(message, error, {
|
|
271
296
|
tag: opts.tag ?? defaultContext.tag ?? enum_1.LogTag.HTTP_REQUEST,
|
|
272
297
|
data: { ...defaultContext.data, ...opts.data },
|
|
273
298
|
metadata: { ...defaultContext.metadata, ...opts.metadata },
|
|
299
|
+
request: opts.request ?? defaultContext.request,
|
|
300
|
+
response: opts.response ?? defaultContext.response,
|
|
301
|
+
status: opts.status ?? defaultContext.status,
|
|
274
302
|
}),
|
|
275
303
|
};
|
|
276
304
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.service.js","sourceRoot":"/","sources":["libraries/logger-kit/logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyYA,gDAUC;AAnZD,4CAAoB;AACpB,gDAAwB;AACxB,mCAAiC;AACjC,4CAAsD;AACtD,+CAAwD;AAExD,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,CAA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EAAE;gBAC9C,QAAQ,EAAE,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;aAC1D,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;aAC1D,CAAC;SACH,CAAC;IACH,CAAC;CACD,CAAA;AA5WY,sCAAa;wBAAb,aAAa;IADzB,IAAA,gBAAO,GAAE;;GACG,aAAa,CA4WzB;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 { Service } from 'typedi';\nimport { createLogModel, Log } from '../mongo/models';\nimport { 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: any = {}): 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\tstack: error.stack,\n\t\t\t};\n\t\t}\n\t\treturn error as ErrorInfo;\n\t}\n\n\tprivate buildLogEntry(\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\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};\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\n\t\t\terror?: ErrorInfo;\n\t\t\tcontext?: RequestContext;\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\tstackTrace: payload.error?.stack?.split('\\n'),\n\t\t\t\trequestId: entry.requestId,\n\t\t\t\tcontext: payload.context,\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\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;\n\t\t\tdata?: any;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\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: number, 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\tstatusCode,\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\tstatusCode,\n\t\t\t\tresponseTime: durationMs,\n\t\t\t},\n\t\t\tcontext: { method, url },\n\t\t});\n\t}\n\n\tchild(defaultContext: { tag?: LogTag; data?: any; metadata?: LogMetadata }): {\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}),\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}),\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}),\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}),\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":";;;;;;;;;;;;;;;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,EAAE,CAAC;IAC3B,CAAC;IAEO,eAAe,CAAC,MAAoB;QAC3C,OAAO;YACN,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC;YAC5B,YA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,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;AApaY,sCAAa;wBAAb,aAAa;IADzB,IAAA,gBAAO,GAAE;;GACG,aAAa,CAoazB;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 { 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;\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;\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;\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;\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;\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;\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;\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;\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}"]}
|
|
@@ -17,11 +17,10 @@ export interface LogMetadata {
|
|
|
17
17
|
[key: string]: unknown;
|
|
18
18
|
}
|
|
19
19
|
export interface ErrorInfo {
|
|
20
|
-
name: string;
|
|
21
|
-
message: string;
|
|
22
20
|
code?: string | number;
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
message?: string;
|
|
22
|
+
stacktrace?: string[];
|
|
23
|
+
name?: string;
|
|
25
24
|
[key: string]: unknown;
|
|
26
25
|
}
|
|
27
26
|
export interface RequestContext {
|
|
@@ -29,7 +28,6 @@ export interface RequestContext {
|
|
|
29
28
|
method?: string;
|
|
30
29
|
url?: string;
|
|
31
30
|
headers?: Record<string, string>;
|
|
32
|
-
body?: unknown;
|
|
33
31
|
query?: Record<string, unknown>;
|
|
34
32
|
params?: Record<string, unknown>;
|
|
35
33
|
}
|
|
@@ -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\
|
|
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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Ref } from '@typegoose/typegoose';
|
|
2
|
+
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
3
|
+
import { CoreUser } from './core-user.model';
|
|
4
|
+
import { CardStatus, CardType, Currency } from '../../../utilities/enum';
|
|
5
|
+
export declare class Card extends TimeStamps {
|
|
6
|
+
cardType?: CardType;
|
|
7
|
+
coreUser?: Ref<CoreUser>;
|
|
8
|
+
orderId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
currency?: Currency;
|
|
11
|
+
brand?: string;
|
|
12
|
+
expiry?: string;
|
|
13
|
+
fundingMethod?: string;
|
|
14
|
+
nameOnCard?: string;
|
|
15
|
+
number?: string;
|
|
16
|
+
scheme?: string;
|
|
17
|
+
token?: string;
|
|
18
|
+
status?: CardStatus;
|
|
19
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Card = void 0;
|
|
13
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
14
|
+
const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
|
|
15
|
+
const core_user_model_1 = require("./core-user.model");
|
|
16
|
+
const enum_1 = require("../../../utilities/enum");
|
|
17
|
+
let Card = class Card extends defaultClasses_1.TimeStamps {
|
|
18
|
+
cardType;
|
|
19
|
+
coreUser;
|
|
20
|
+
orderId;
|
|
21
|
+
sessionId;
|
|
22
|
+
currency;
|
|
23
|
+
brand;
|
|
24
|
+
expiry;
|
|
25
|
+
fundingMethod;
|
|
26
|
+
nameOnCard;
|
|
27
|
+
number;
|
|
28
|
+
scheme;
|
|
29
|
+
token;
|
|
30
|
+
status;
|
|
31
|
+
};
|
|
32
|
+
exports.Card = Card;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.CardType, default: enum_1.CardType.AREEBA }),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], Card.prototype, "cardType", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typegoose_1.prop)({ ref: () => core_user_model_1.CoreUser }),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], Card.prototype, "coreUser", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typegoose_1.prop)({ required: true, type: String }),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], Card.prototype, "orderId", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typegoose_1.prop)({ required: true, type: String }),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], Card.prototype, "sessionId", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.Currency, default: enum_1.Currency.USD }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], Card.prototype, "currency", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], Card.prototype, "brand", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], Card.prototype, "expiry", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], Card.prototype, "fundingMethod", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], Card.prototype, "nameOnCard", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
71
|
+
__metadata("design:type", String)
|
|
72
|
+
], Card.prototype, "number", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
75
|
+
__metadata("design:type", String)
|
|
76
|
+
], Card.prototype, "scheme", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], Card.prototype, "token", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.CardStatus, default: enum_1.CardStatus.PENDING }),
|
|
83
|
+
__metadata("design:type", String)
|
|
84
|
+
], Card.prototype, "status", void 0);
|
|
85
|
+
exports.Card = Card = __decorate([
|
|
86
|
+
(0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'cards' } })
|
|
87
|
+
], Card);
|
|
88
|
+
//# sourceMappingURL=card.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.model.js","sourceRoot":"/","sources":["libraries/mongo/models/card.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,uDAA6C;AAC7C,kDAAyE;AAGlE,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,2BAAU;IAE5B,QAAQ,CAAY;IAGpB,QAAQ,CAAiB;IAGzB,OAAO,CAAU;IAGjB,SAAS,CAAU;IAGnB,QAAQ,CAAY;IAGpB,KAAK,CAAU;IAGf,MAAM,CAAU;IAGhB,aAAa,CAAU;IAGvB,UAAU,CAAU;IAGpB,MAA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AAM,EAAE,IAAI,EAAE,iBAAU,EAAE,OAAO,EAAE,iBAAU,CAAC,OAAO,EAAE,CAAC;;oCAC3C;eAtCf,IAAI;IADhB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;GAC5C,IAAI,CAuChB","sourcesContent":["import { modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { CoreUser } from './core-user.model';\nimport { CardStatus, CardType, Currency } from '../../../utilities/enum';\n\n@modelOptions({ schemaOptions: { collection: 'cards' } })\nexport class Card extends TimeStamps {\n\t@prop({ type: String, enum: CardType, default: CardType.AREEBA })\n\tpublic cardType?: CardType;\n\n\t@prop({ ref: () => CoreUser })\n\tpublic coreUser?: Ref<CoreUser>;\n\n\t@prop({ required: true, type: String })\n\tpublic orderId!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic sessionId!: string;\n\n\t@prop({ type: String, enum: Currency, default: Currency.USD })\n\tpublic currency?: Currency;\n\n\t@prop({ type: String })\n\tpublic brand?: string;\n\n\t@prop({ type: String })\n\tpublic expiry?: string;\n\n\t@prop({ type: String })\n\tpublic fundingMethod?: string;\n\n\t@prop({ type: String })\n\tpublic nameOnCard?: string;\n\n\t@prop({ type: String })\n\tpublic number?: string;\n\n\t@prop({ type: String })\n\tpublic scheme?: string;\n\n\t@prop({ type: String })\n\tpublic token?: string;\n\n\t@prop({ type: String, enum: CardStatus, default: CardStatus.PENDING })\n\tpublic status?: CardStatus;\n}\n"]}
|
|
@@ -105,6 +105,7 @@ import { ZoneExtraTime } from './zone-extra-time';
|
|
|
105
105
|
import { AppAppearance } from './app-appearance.model';
|
|
106
106
|
import { ServiceControl } from './service-control.model';
|
|
107
107
|
import { Log } from './log.model';
|
|
108
|
+
import { Card } from './card.model';
|
|
108
109
|
export declare const ActivityLogModel: ReturnModelType<typeof ActivityLog>;
|
|
109
110
|
export * from './activity-log.model';
|
|
110
111
|
export declare const AdminAccessControlModel: ReturnModelType<typeof AdminAccessControl>;
|
|
@@ -131,6 +132,7 @@ export declare function getCorePhoneAuthIdentityModel(): ReturnModelType<typeof
|
|
|
131
132
|
export declare function getCoreGoogleAuthIdentityModel(): ReturnModelType<typeof CoreGoogleAuthIdentity>;
|
|
132
133
|
export declare function getCoreAppleAuthIdentityModel(): ReturnModelType<typeof CoreAppleAuthIdentity>;
|
|
133
134
|
export declare function getCoreUserModel(): ReturnModelType<typeof CoreUser>;
|
|
135
|
+
export declare function getCardModel(): ReturnModelType<typeof Card>;
|
|
134
136
|
export declare function initializeGlobalModels(globalConnection: any): void;
|
|
135
137
|
export declare const CartModel: ReturnModelType<typeof Cart>;
|
|
136
138
|
export * from './cart.model';
|
|
@@ -22,6 +22,7 @@ exports.getCorePhoneAuthIdentityModel = getCorePhoneAuthIdentityModel;
|
|
|
22
22
|
exports.getCoreGoogleAuthIdentityModel = getCoreGoogleAuthIdentityModel;
|
|
23
23
|
exports.getCoreAppleAuthIdentityModel = getCoreAppleAuthIdentityModel;
|
|
24
24
|
exports.getCoreUserModel = getCoreUserModel;
|
|
25
|
+
exports.getCardModel = getCardModel;
|
|
25
26
|
exports.initializeGlobalModels = initializeGlobalModels;
|
|
26
27
|
const service_line_item_model_1 = require("./service-line-item.model");
|
|
27
28
|
const rider_payout_model_1 = require("./providers/rider-payout.model");
|
|
@@ -133,6 +134,7 @@ const zone_extra_time_1 = require("./zone-extra-time");
|
|
|
133
134
|
const app_appearance_model_1 = require("./app-appearance.model");
|
|
134
135
|
const service_control_model_1 = require("./service-control.model");
|
|
135
136
|
const log_model_1 = require("./log.model");
|
|
137
|
+
const card_model_1 = require("./card.model");
|
|
136
138
|
exports.ActivityLogModel = (0, typegoose_1.getModelForClass)(activity_log_model_1.ActivityLog);
|
|
137
139
|
__exportStar(require("./activity-log.model"), exports);
|
|
138
140
|
exports.AdminAccessControlModel = (0, typegoose_1.getModelForClass)(admin_access_control_model_1.AdminAccessControl);
|
|
@@ -155,6 +157,7 @@ exports.ServiceControlModel = (0, typegoose_1.getModelForClass)(service_control_
|
|
|
155
157
|
__exportStar(require("./service-control.model"), exports);
|
|
156
158
|
let actualCoreAuthIdentityModel = null;
|
|
157
159
|
let actualCoreUserModel = null;
|
|
160
|
+
let actualCardModel = null;
|
|
158
161
|
let actualCoreEmailAuthIdentityModel = null;
|
|
159
162
|
let actualCorePhoneAuthIdentityModel = null;
|
|
160
163
|
let actualCoreGoogleAuthIdentityModel = null;
|
|
@@ -189,9 +192,15 @@ function getCoreUserModel() {
|
|
|
189
192
|
throw new Error('CoreUser model not initialized yet. Call initGlobalConnection() first.');
|
|
190
193
|
return actualCoreUserModel;
|
|
191
194
|
}
|
|
195
|
+
function getCardModel() {
|
|
196
|
+
if (!actualCardModel)
|
|
197
|
+
throw new Error('Card model not initialized yet. Call initGlobalConnection() first.');
|
|
198
|
+
return actualCardModel;
|
|
199
|
+
}
|
|
192
200
|
function initializeGlobalModels(globalConnection) {
|
|
193
201
|
actualCoreAuthIdentityModel = (0, typegoose_1.getModelForClass)(core_auth_identity_model_1.CoreAuthIdentity, { existingConnection: globalConnection });
|
|
194
202
|
actualCoreUserModel = (0, typegoose_1.getModelForClass)(core_user_model_1.CoreUser, { existingConnection: globalConnection });
|
|
203
|
+
actualCardModel = (0, typegoose_1.getModelForClass)(card_model_1.Card, { existingConnection: globalConnection });
|
|
195
204
|
actualCoreEmailAuthIdentityModel = (0, typegoose_1.getDiscriminatorModelForClass)(actualCoreAuthIdentityModel, core_email_auth_identity_model_1.CoreEmailAuthIdentity, enum_1.CoreAuthIdentityType.EMAIL, { existingConnection: globalConnection });
|
|
196
205
|
actualCorePhoneAuthIdentityModel = (0, typegoose_1.getDiscriminatorModelForClass)(actualCoreAuthIdentityModel, core_phone_auth_identity_model_1.CorePhoneAuthIdentity, enum_1.CoreAuthIdentityType.PHONE, { existingConnection: globalConnection });
|
|
197
206
|
actualCoreGoogleAuthIdentityModel = (0, typegoose_1.getDiscriminatorModelForClass)(actualCoreAuthIdentityModel, core_google_auth_identity_model_1.CoreGoogleAuthIdentity, enum_1.CoreAuthIdentityType.GOOGLE, { existingConnection: globalConnection });
|