@lyxa.ai/core 1.3.151 → 1.3.153
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 +10 -8
- package/dist/libraries/logger-kit/logger.service.js +88 -30
- package/dist/libraries/logger-kit/logger.service.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/order-refund.model.d.ts +2 -0
- package/dist/libraries/mongo/models/embedded/order-refund.model.js +6 -0
- package/dist/libraries/mongo/models/embedded/order-refund.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/replacement-order.model.d.ts +2 -1
- package/dist/libraries/mongo/models/embedded/replacement-order.model.js +5 -0
- package/dist/libraries/mongo/models/embedded/replacement-order.model.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +12 -12
- package/package.json +1 -1
|
@@ -16,44 +16,46 @@ interface LoggerConfig {
|
|
|
16
16
|
environment?: string;
|
|
17
17
|
}
|
|
18
18
|
export declare class LyxaLoggerKit {
|
|
19
|
-
private readonly logger;
|
|
20
19
|
private readonly model;
|
|
21
20
|
private readonly config;
|
|
22
21
|
constructor(config: LoggerConfig);
|
|
23
22
|
private normalizeConfig;
|
|
24
23
|
private ensureLogDirectory;
|
|
25
|
-
private createPinoLogger;
|
|
26
24
|
private getRequestStore;
|
|
27
25
|
private enrichWithContext;
|
|
28
26
|
private shouldPersist;
|
|
29
27
|
private persistLog;
|
|
30
28
|
private normalizeError;
|
|
31
29
|
private buildLogEntry;
|
|
30
|
+
private getColorCode;
|
|
31
|
+
private formatTimestamp;
|
|
32
|
+
private formatLogMessage;
|
|
33
|
+
private consoleLog;
|
|
32
34
|
private write;
|
|
33
35
|
info(message: string, options: {
|
|
34
36
|
tag: LogTag;
|
|
35
|
-
data?:
|
|
37
|
+
data?: any;
|
|
36
38
|
metadata?: LogMetadata;
|
|
37
39
|
}): void;
|
|
38
40
|
debug(message: string, options: {
|
|
39
41
|
tag: LogTag;
|
|
40
|
-
data?:
|
|
42
|
+
data?: any;
|
|
41
43
|
metadata?: LogMetadata;
|
|
42
44
|
}): void;
|
|
43
45
|
warn(message: string, options: {
|
|
44
46
|
tag: LogTag;
|
|
45
|
-
data?:
|
|
47
|
+
data?: any;
|
|
46
48
|
metadata?: LogMetadata;
|
|
47
49
|
}): void;
|
|
48
50
|
error(message: string, error: TRPCError | Error | unknown, options: {
|
|
49
51
|
tag: LogTag;
|
|
50
|
-
data?:
|
|
52
|
+
data?: any;
|
|
51
53
|
metadata?: LogMetadata;
|
|
52
54
|
context?: RequestContext;
|
|
53
55
|
}): void;
|
|
54
56
|
fatal(message: string, error: TRPCError | Error | unknown, options: {
|
|
55
57
|
tag: LogTag;
|
|
56
|
-
data?:
|
|
58
|
+
data?: any;
|
|
57
59
|
metadata?: LogMetadata;
|
|
58
60
|
context?: RequestContext;
|
|
59
61
|
}): void;
|
|
@@ -61,7 +63,7 @@ export declare class LyxaLoggerKit {
|
|
|
61
63
|
httpRequest(method: string, url: string, statusCode: number, durationMs: number, userId?: string): void;
|
|
62
64
|
child(defaultContext: {
|
|
63
65
|
tag?: LogTag;
|
|
64
|
-
data?:
|
|
66
|
+
data?: any;
|
|
65
67
|
metadata?: LogMetadata;
|
|
66
68
|
}): {
|
|
67
69
|
info: (message: string, options?: Partial<typeof defaultContext>) => void;
|
|
@@ -16,23 +16,19 @@ 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 pino_1 = require("pino");
|
|
20
19
|
const typedi_1 = require("typedi");
|
|
21
20
|
const models_1 = require("../mongo/models");
|
|
22
21
|
const enum_1 = require("../../utilities/enum");
|
|
23
22
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
24
|
-
const EnvironmentConfigurationType_1 = require("../configuration/types/EnvironmentConfigurationType");
|
|
25
23
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
26
24
|
exports.requestContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
27
25
|
let LyxaLoggerKit = class LyxaLoggerKit {
|
|
28
|
-
logger;
|
|
29
26
|
model;
|
|
30
27
|
config;
|
|
31
28
|
constructor(config) {
|
|
32
29
|
this.config = this.normalizeConfig(config);
|
|
33
30
|
this.model = (0, models_1.createLogModel)({ ttlDays: this.config.ttlDays });
|
|
34
31
|
this.ensureLogDirectory();
|
|
35
|
-
this.logger = this.createPinoLogger();
|
|
36
32
|
}
|
|
37
33
|
normalizeConfig(config) {
|
|
38
34
|
return {
|
|
@@ -47,28 +43,6 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
47
43
|
const logPath = path_1.default.join(process.cwd(), this.config.logDirectory);
|
|
48
44
|
fs_1.default.mkdirSync(logPath, { recursive: true });
|
|
49
45
|
}
|
|
50
|
-
createPinoLogger() {
|
|
51
|
-
const isProduction = this.config.environment === EnvironmentConfigurationType_1.EnvironmentConfigurationType.PROD;
|
|
52
|
-
return (0, pino_1.pino)({
|
|
53
|
-
level: isProduction ? 'info' : 'debug',
|
|
54
|
-
base: {
|
|
55
|
-
service: this.config.instanceType,
|
|
56
|
-
pid: process.pid,
|
|
57
|
-
hostname: process.env.HOSTNAME ?? 'unknown',
|
|
58
|
-
env: this.config.environment,
|
|
59
|
-
},
|
|
60
|
-
transport: isProduction
|
|
61
|
-
? undefined
|
|
62
|
-
: {
|
|
63
|
-
target: 'pino-pretty',
|
|
64
|
-
options: {
|
|
65
|
-
colorize: true,
|
|
66
|
-
translateTime: 'SYS:standard',
|
|
67
|
-
ignore: 'pid,hostname',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
46
|
getRequestStore() {
|
|
73
47
|
return exports.requestContext.getStore() ?? {};
|
|
74
48
|
}
|
|
@@ -125,11 +99,95 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
125
99
|
requestId: store.requestId,
|
|
126
100
|
};
|
|
127
101
|
}
|
|
102
|
+
getColorCode(level) {
|
|
103
|
+
switch (level) {
|
|
104
|
+
case enum_1.LogLevel.DEBUG:
|
|
105
|
+
return '\x1b[96m';
|
|
106
|
+
case enum_1.LogLevel.INFO:
|
|
107
|
+
return '\x1b[32m';
|
|
108
|
+
case enum_1.LogLevel.WARN:
|
|
109
|
+
return '\x1b[33m';
|
|
110
|
+
case enum_1.LogLevel.ERROR:
|
|
111
|
+
return '\x1b[31m';
|
|
112
|
+
case enum_1.LogLevel.FATAL:
|
|
113
|
+
return '\x1b[35m';
|
|
114
|
+
default:
|
|
115
|
+
return '\x1b[37m';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
formatTimestamp(date) {
|
|
119
|
+
const year = date.getFullYear();
|
|
120
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
121
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
122
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
123
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
124
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
125
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
126
|
+
}
|
|
127
|
+
formatLogMessage(level, message, entry) {
|
|
128
|
+
const timestamp = this.formatTimestamp(new Date());
|
|
129
|
+
const tag = (entry.tag || 'GENERAL').toUpperCase();
|
|
130
|
+
const levelUpper = level.toUpperCase();
|
|
131
|
+
const grey = '\x1b[90m';
|
|
132
|
+
const cyan = '\x1b[36m';
|
|
133
|
+
const levelColor = this.getColorCode(level);
|
|
134
|
+
const reset = '\x1b[0m';
|
|
135
|
+
const paddedLevel = levelUpper.padEnd(5);
|
|
136
|
+
const parts = [
|
|
137
|
+
`${grey}[${timestamp}]${reset}`,
|
|
138
|
+
`${levelColor}[${levelUpper}]${reset}`,
|
|
139
|
+
`${cyan}[${tag}]${reset}`,
|
|
140
|
+
message,
|
|
141
|
+
];
|
|
142
|
+
return parts.join(' ');
|
|
143
|
+
}
|
|
144
|
+
consoleLog(level, formattedMessage, entry) {
|
|
145
|
+
switch (level) {
|
|
146
|
+
case enum_1.LogLevel.DEBUG:
|
|
147
|
+
console.log(formattedMessage);
|
|
148
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
149
|
+
console.log(entry.data);
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case enum_1.LogLevel.INFO:
|
|
153
|
+
console.log(formattedMessage);
|
|
154
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
155
|
+
console.log(entry.data);
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case enum_1.LogLevel.WARN:
|
|
159
|
+
console.warn(formattedMessage);
|
|
160
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
161
|
+
console.warn(entry.data);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case enum_1.LogLevel.ERROR:
|
|
165
|
+
console.error(formattedMessage);
|
|
166
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
167
|
+
console.error(entry.data);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case enum_1.LogLevel.FATAL:
|
|
171
|
+
console.error(formattedMessage);
|
|
172
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
173
|
+
console.error(entry.data);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
console.log(formattedMessage);
|
|
178
|
+
if (entry.data && Object.keys(entry.data).length > 0) {
|
|
179
|
+
console.log(entry.data);
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
128
184
|
write(level, message, payload, opts = {}) {
|
|
129
185
|
const { shouldWrite = true } = opts;
|
|
130
186
|
const entry = this.buildLogEntry(message, payload);
|
|
131
|
-
shouldWrite
|
|
132
|
-
this.
|
|
187
|
+
if (shouldWrite) {
|
|
188
|
+
const formattedMessage = this.formatLogMessage(level, message, entry);
|
|
189
|
+
this.consoleLog(level, formattedMessage, entry);
|
|
190
|
+
}
|
|
133
191
|
if (this.shouldPersist(level)) {
|
|
134
192
|
this.persistLog({
|
|
135
193
|
level,
|
|
@@ -153,13 +211,13 @@ let LyxaLoggerKit = class LyxaLoggerKit {
|
|
|
153
211
|
this.write(enum_1.LogLevel.DEBUG, message, options);
|
|
154
212
|
}
|
|
155
213
|
warn(message, options) {
|
|
156
|
-
this.write(enum_1.LogLevel.WARN, message, options
|
|
214
|
+
this.write(enum_1.LogLevel.WARN, message, options);
|
|
157
215
|
}
|
|
158
216
|
error(message, error, options) {
|
|
159
217
|
this.write(enum_1.LogLevel.ERROR, message, {
|
|
160
218
|
...options,
|
|
161
219
|
error: this.normalizeError(error),
|
|
162
|
-
}
|
|
220
|
+
});
|
|
163
221
|
}
|
|
164
222
|
fatal(message, error, options) {
|
|
165
223
|
this.write(enum_1.LogLevel.FATAL, message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.service.js","sourceRoot":"/","sources":["libraries/logger-kit/logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwUA,gDAUC;AAlVD,4CAAoB;AACpB,gDAAwB;AACxB,+BAAoC;AACpC,mCAAiC;AACjC,4CAAsD;AACtD,+CAAwD;AAExD,uDAAqD;AACrD,sGAAmG;AACnG,wDAAgC;AASnB,QAAA,cAAc,GAAG,IAAI,oCAAiB,EAAgB,CAAC;AAW7D,IAAM,aAAa,GAAnB,MAAM,aAAa;IACR,MAAM,CAAS;IACf,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,C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;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 { Logger, pino } from 'pino';\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 { EnvironmentConfigurationType } from '../configuration/types/EnvironmentConfigurationType';\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 logger: Logger;\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\tthis.logger = this.createPinoLogger();\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 createPinoLogger(): Logger {\n\t\tconst isProduction = this.config.environment === EnvironmentConfigurationType.PROD;\n\n\t\treturn pino({\n\t\t\tlevel: isProduction ? 'info' : 'debug',\n\t\t\tbase: {\n\t\t\t\tservice: this.config.instanceType,\n\t\t\t\tpid: process.pid,\n\t\t\t\thostname: process.env.HOSTNAME ?? 'unknown',\n\t\t\t\tenv: this.config.environment,\n\t\t\t},\n\t\t\ttransport: isProduction\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\ttarget: 'pino-pretty',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tcolorize: true,\n\t\t\t\t\t\t\ttranslateTime: 'SYS:standard',\n\t\t\t\t\t\t\tignore: 'pid,hostname',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t});\n\t}\n\n\tprivate getRequestStore(): RequestStore {\n\t\treturn requestContext.getStore() ?? {};\n\t}\n\n\tprivate enrichWithContext(data: Record<string, unknown> = {}): Record<string, unknown> {\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>): Promise<void> {\n\t\tconst currentDebug = mongoose.get('debug');\n\t\ttry {\n\t\t\tmongoose.set('debug', false);\n\t\t\tawait 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?: Record<string, unknown>;\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 write(\n\t\tlevel: LogLevel,\n\t\tmessage: string,\n\t\tpayload: {\n\t\t\ttag: LogTag;\n\t\t\tdata?: Record<string, unknown>;\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): void {\n\t\tconst { shouldWrite = true } = opts;\n\t\tconst entry = this.buildLogEntry(message, payload);\n\n\t\t// Console/Pino logging\n\t\tshouldWrite &&\n\t\t\tthis.logger[level.toLowerCase() as 'info' | 'debug' | 'warn' | 'error' | 'fatal'](entry, message);\n\n\t\t// Async persistence (fire-and-forget)\n\t\tif (this.shouldPersist(level)) {\n\t\t\tthis.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\n\t/* ---------------------------------- */\n\n\tinfo(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\ttag: LogTag;\n\t\t\tdata?: Record<string, unknown>;\n\t\t\tmetadata?: LogMetadata;\n\t\t}\n\t): void {\n\t\tthis.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, unknown>;\n\t\t\tmetadata?: LogMetadata;\n\t\t}\n\t): void {\n\t\tthis.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, unknown>;\n\t\t\tmetadata?: LogMetadata;\n\t\t}\n\t): void {\n\t\tthis.write(LogLevel.WARN, message, options, { shouldWrite: false });\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, unknown>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t}\n\t): void {\n\t\tthis.write(\n\t\t\tLogLevel.ERROR,\n\t\t\tmessage,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\terror: this.normalizeError(error),\n\t\t\t},\n\t\t\t{ shouldWrite: false }\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, unknown>;\n\t\t\tmetadata?: LogMetadata;\n\t\t\tcontext?: RequestContext;\n\t\t}\n\t): void {\n\t\tthis.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\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?: Record<string, unknown>; 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":";;;;;;;;;;;;;;;AA8YA,gDAUC;AAxZD,4CAAoB;AACpB,gDAAwB;AACxB,mCAAiC;AACjC,4CAAsD;AACtD,+CAAwD;AAExD,uDAAqD;AAErD,wDAAgC;AASnB,QAAA,cAAc,GAAG,IAAI,oCAAiB,EAAgB,CAAC;AAW7D,IAAM,aAAa,GAAnB,MAAM,aAAa;IACR,KAAK,CAAoC;IACzC,MAAM,CAAyB;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nimport { LogLevel, LogTag } from '../../utilities/enum';\nimport { ErrorInfo, LogMetadata, RequestContext } from './types';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { EnvironmentConfigurationType } from '../configuration/types/EnvironmentConfigurationType';\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>): Promise<void> {\n\t\tconst currentDebug = mongoose.get('debug');\n\t\ttry {\n\t\t\tmongoose.set('debug', false);\n\t\t\tawait 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 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): void {\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\tthis.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): void {\n\t\tthis.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): void {\n\t\tthis.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): void {\n\t\tthis.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): void {\n\t\tthis.write(\n\t\t\tLogLevel.ERROR,\n\t\t\tmessage,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\terror: this.normalizeError(error),\n\t\t\t}\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): void {\n\t\tthis.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}"]}
|
|
@@ -2,6 +2,7 @@ import { Ref } from '@typegoose/typegoose';
|
|
|
2
2
|
import { LineItem } from '../line-item.model';
|
|
3
3
|
import { LineItemAttribute } from './line-item-attribute.model';
|
|
4
4
|
import { Product } from '../product.model';
|
|
5
|
+
import { FlagReasonType } from '../../../../utilities/enum';
|
|
5
6
|
declare class SelectedLineItemsInfo {
|
|
6
7
|
lineItemId: Ref<LineItem>;
|
|
7
8
|
quantity?: number;
|
|
@@ -22,5 +23,6 @@ export declare class OrderRefund {
|
|
|
22
23
|
secondaryRefundedAmountByCompanyForDelivery?: number;
|
|
23
24
|
totalRefund?: number;
|
|
24
25
|
secondaryTotalRefund?: number;
|
|
26
|
+
reasonType?: FlagReasonType;
|
|
25
27
|
}
|
|
26
28
|
export {};
|
|
@@ -14,6 +14,7 @@ const typegoose_1 = require("@typegoose/typegoose");
|
|
|
14
14
|
const line_item_model_1 = require("../line-item.model");
|
|
15
15
|
const line_item_attribute_model_1 = require("./line-item-attribute.model");
|
|
16
16
|
const product_model_1 = require("../product.model");
|
|
17
|
+
const enum_1 = require("../../../../utilities/enum");
|
|
17
18
|
class SelectedLineItemsInfo {
|
|
18
19
|
lineItemId;
|
|
19
20
|
quantity;
|
|
@@ -54,6 +55,7 @@ class OrderRefund {
|
|
|
54
55
|
secondaryRefundedAmountByCompanyForDelivery;
|
|
55
56
|
totalRefund;
|
|
56
57
|
secondaryTotalRefund;
|
|
58
|
+
reasonType;
|
|
57
59
|
}
|
|
58
60
|
exports.OrderRefund = OrderRefund;
|
|
59
61
|
__decorate([
|
|
@@ -104,4 +106,8 @@ __decorate([
|
|
|
104
106
|
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
105
107
|
__metadata("design:type", Number)
|
|
106
108
|
], OrderRefund.prototype, "secondaryTotalRefund", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.FlagReasonType, default: enum_1.FlagReasonType.OTHER }),
|
|
111
|
+
__metadata("design:type", String)
|
|
112
|
+
], OrderRefund.prototype, "reasonType", void 0);
|
|
107
113
|
//# sourceMappingURL=order-refund.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-refund.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-refund.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,wDAA8C;AAC9C,2EAAgE;AAChE,oDAA2C;
|
|
1
|
+
{"version":3,"file":"order-refund.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-refund.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,wDAA8C;AAC9C,2EAAgE;AAChE,oDAA2C;AAC3C,qDAA4D;AAE5D,MAAM,qBAAqB;IAEnB,UAAU,CAAi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IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;iEACU;AAGtC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0EACmB;AAG/C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;oEACa;AAGzC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;6EACsB;AAGlD;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;oEACa;AAGzC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;6EACsB;AAGlD;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;uEACgB;AAG5C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;gFACyB;AAGrD;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;gDACP;AAGrB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;yDACE;AAG9B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAc,EAAE,OAAO,EAAE,qBAAc,CAAC,KAAK,EAAE,CAAC;;+CACzC","sourcesContent":["import { prop, Ref } from '@typegoose/typegoose';\nimport { LineItem } from '../line-item.model';\nimport { LineItemAttribute } from './line-item-attribute.model';\nimport { Product } from '../product.model';\nimport { FlagReasonType } from '../../../../utilities/enum';\n\nclass SelectedLineItemsInfo {\n\t@prop({ required: true, ref: () => LineItem })\n\tpublic lineItemId!: Ref<LineItem>;\n\n\t@prop({ type: Number, default: 1 })\n\tpublic quantity?: number;\n\n\t@prop({ required: true, ref: () => Product })\n\tpublic product?: Ref<Product>;\n\n\t@prop({ type: () => [[LineItemAttribute]], default: [] })\n\tpublic attributes?: LineItemAttribute[][];\n\n\t@prop({ type: Boolean })\n\tpublic isOnlyAttributeRefunded?: boolean;\n}\n\nexport class OrderRefund {\n\t@prop({ type: Boolean, default: false })\n\tpublic isFullRefund?: boolean;\n\n\t@prop({ type: () => [SelectedLineItemsInfo], default: [], _id: false })\n\tpublic selectedLineItems?: SelectedLineItemsInfo[];\n\n\t@prop({ type: Number, default: 0 })\n\tpublic refundedAmountByShopForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryRefundedAmountByShopForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic refundedAmountByShopForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryRefundedAmountByShopForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic refundedAmountByCompanyForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryRefundedAmountByCompanyForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic refundedAmountByCompanyForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryRefundedAmountByCompanyForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic totalRefund?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryTotalRefund?: number;\n\n\t@prop({ type: String, enum: FlagReasonType, default: FlagReasonType.OTHER })\n\tpublic reasonType?: FlagReasonType;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from '@typegoose/typegoose';
|
|
2
|
-
import { ReplacementType } from '../../../../utilities/enum';
|
|
2
|
+
import { FlagReasonType, ReplacementType } from '../../../../utilities/enum';
|
|
3
3
|
import { Order } from '../order.model';
|
|
4
4
|
import { LineItem } from '../line-item.model';
|
|
5
5
|
import { LineItemAttribute } from './line-item-attribute.model';
|
|
@@ -23,5 +23,6 @@ export declare class ReplacementOrder {
|
|
|
23
23
|
replacementByCompanyForDelivery?: number;
|
|
24
24
|
secondaryReplacementByCompanyForDelivery?: number;
|
|
25
25
|
bringItem?: string;
|
|
26
|
+
reasonType?: FlagReasonType;
|
|
26
27
|
}
|
|
27
28
|
export {};
|
|
@@ -51,6 +51,7 @@ class ReplacementOrder {
|
|
|
51
51
|
replacementByCompanyForDelivery;
|
|
52
52
|
secondaryReplacementByCompanyForDelivery;
|
|
53
53
|
bringItem;
|
|
54
|
+
reasonType;
|
|
54
55
|
}
|
|
55
56
|
exports.ReplacementOrder = ReplacementOrder;
|
|
56
57
|
__decorate([
|
|
@@ -101,4 +102,8 @@ __decorate([
|
|
|
101
102
|
(0, typegoose_1.prop)({ type: String }),
|
|
102
103
|
__metadata("design:type", String)
|
|
103
104
|
], ReplacementOrder.prototype, "bringItem", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, typegoose_1.prop)({ type: String, enum: enum_1.FlagReasonType, default: enum_1.FlagReasonType.OTHER }),
|
|
107
|
+
__metadata("design:type", String)
|
|
108
|
+
], ReplacementOrder.prototype, "reasonType", void 0);
|
|
104
109
|
//# sourceMappingURL=replacement-order.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replacement-order.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/replacement-order.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"replacement-order.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/replacement-order.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,qDAA6E;AAC7E,gDAAuC;AACvC,wDAA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AA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAe,EAAE,CAAC;;yDACrB;AAGlC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;mEACO;AAGnC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;4EACgB;AAG5C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;sEACU;AAGtC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;+EACmB;AAG/C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;sEACU;AAGtC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;+EACmB;AAG/C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;yEACa;AAGzC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;kFACsB;AAGlD;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDACG;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAc,EAAE,OAAO,EAAE,qBAAc,CAAC,KAAK,EAAE,CAAC;;oDACzC","sourcesContent":["import { prop, Ref } from '@typegoose/typegoose';\nimport { FlagReasonType, ReplacementType } from '../../../../utilities/enum';\nimport { Order } from '../order.model';\nimport { LineItem } from '../line-item.model';\nimport { LineItemAttribute } from './line-item-attribute.model';\nimport { Product } from '../product.model';\n\nclass SelectedLineItemsInfo {\n\t@prop({ required: true, ref: () => LineItem })\n\tpublic lineItemId!: Ref<LineItem>;\n\n\t@prop({ type: Number, default: 1 })\n\tpublic quantity?: number;\n\n\t@prop({ required: true, ref: () => Product })\n\tpublic product?: Ref<Product>;\n\n\t@prop({ type: () => [[LineItemAttribute]], default: [] })\n\tpublic attributes?: LineItemAttribute[][];\n}\n\nexport class ReplacementOrder {\n\t@prop({ required: true, ref: () => Order })\n\tpublic originalOrder!: Ref<Order>;\n\n\t@prop({ type: () => [SelectedLineItemsInfo], default: [], _id: false })\n\tpublic selectedLineItems?: SelectedLineItemsInfo[];\n\n\t@prop({ required: true, type: String, enum: ReplacementType })\n\tpublic replacementType!: ReplacementType;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic replacementByShopForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryReplacementByShopForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic replacementByShopForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryReplacementByShopForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic replacementByCompanyForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryReplacementByCompanyForItems?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic replacementByCompanyForDelivery?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic secondaryReplacementByCompanyForDelivery?: number;\n\n\t@prop({ type: String })\n\tpublic bringItem?: string;\n\n\t@prop({ type: String, enum: FlagReasonType, default: FlagReasonType.OTHER })\n\tpublic reasonType?: FlagReasonType;\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
26
26
|
searchFields?: string[] | undefined;
|
|
27
27
|
} | undefined;
|
|
28
28
|
sort?: Record<string, 1 | -1> | undefined;
|
|
29
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
30
29
|
populate?: any;
|
|
30
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
31
31
|
query?: Record<string, any> | undefined;
|
|
32
32
|
}, {
|
|
33
33
|
search?: {
|
|
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
36
36
|
} | undefined;
|
|
37
37
|
sort?: Record<string, 1 | -1> | undefined;
|
|
38
38
|
size?: number | undefined;
|
|
39
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
40
39
|
populate?: any;
|
|
40
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
41
41
|
query?: Record<string, any> | undefined;
|
|
42
42
|
page?: number | undefined;
|
|
43
43
|
}>>;
|
|
@@ -733,12 +733,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
|
|
|
733
733
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
734
734
|
}, "strip", z.ZodTypeAny, {
|
|
735
735
|
_id: import("mongoose").Types.ObjectId;
|
|
736
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
737
736
|
populate?: any;
|
|
737
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
738
738
|
}, {
|
|
739
739
|
_id: string | import("mongoose").Types.ObjectId;
|
|
740
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
741
740
|
populate?: any;
|
|
741
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
742
742
|
}>;
|
|
743
743
|
export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
|
|
744
744
|
export declare const GetProductByIdInputSchema: z.ZodObject<{
|
|
@@ -751,12 +751,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
|
|
|
751
751
|
_id: import("mongoose").Types.ObjectId;
|
|
752
752
|
withAttributeHiddenItems: boolean;
|
|
753
753
|
withAddonsHiddenItems: boolean;
|
|
754
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
755
754
|
populate?: any;
|
|
755
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
756
756
|
}, {
|
|
757
757
|
_id: string | import("mongoose").Types.ObjectId;
|
|
758
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
759
758
|
populate?: any;
|
|
759
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
760
760
|
withAttributeHiddenItems?: boolean | undefined;
|
|
761
761
|
withAddonsHiddenItems?: boolean | undefined;
|
|
762
762
|
}>;
|
|
@@ -768,13 +768,13 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
|
|
|
768
768
|
userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
|
|
769
769
|
}, "strip", z.ZodTypeAny, {
|
|
770
770
|
_id: import("mongoose").Types.ObjectId;
|
|
771
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
772
771
|
populate?: any;
|
|
772
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
773
773
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
774
774
|
}, {
|
|
775
775
|
_id: string | import("mongoose").Types.ObjectId;
|
|
776
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
777
776
|
populate?: any;
|
|
777
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
778
778
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
779
779
|
}>;
|
|
780
780
|
export type GetOrderByIdInputDTO = DTO<typeof GetOrderByIdInputSchema>;
|
|
@@ -782,11 +782,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
|
|
|
782
782
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
783
783
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
784
784
|
}, "strip", z.ZodTypeAny, {
|
|
785
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
786
785
|
populate?: any;
|
|
787
|
-
}, {
|
|
788
786
|
select?: Record<string, 0 | 1> | undefined;
|
|
787
|
+
}, {
|
|
789
788
|
populate?: any;
|
|
789
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
790
790
|
}>>;
|
|
791
791
|
export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
|
|
792
792
|
export declare const GetOneQuerySchema: z.ZodObject<{
|
|
@@ -794,12 +794,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
|
|
|
794
794
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
795
795
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
796
796
|
}, "strip", z.ZodTypeAny, {
|
|
797
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
798
797
|
populate?: any;
|
|
798
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
799
799
|
query?: Record<string, any> | undefined;
|
|
800
800
|
}, {
|
|
801
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
802
801
|
populate?: any;
|
|
802
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
803
803
|
query?: Record<string, any> | undefined;
|
|
804
804
|
}>;
|
|
805
805
|
export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
|