@mcesystems/logging-g4 1.0.70 → 1.0.72
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/Example.md +44 -0
- package/README.md +82 -9
- package/dist/index.js +456 -188
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +456 -188
- package/dist/index.mjs.map +4 -4
- package/dist/types/example/sendBatchAfterOneMinute.d.ts +2 -0
- package/dist/types/example/sendBatchAfterOneMinute.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logic/cronSchedule.d.ts +6 -0
- package/dist/types/logic/cronSchedule.d.ts.map +1 -0
- package/dist/types/logic/logClient.d.ts +12 -2
- package/dist/types/logic/logClient.d.ts.map +1 -1
- package/dist/types/logic/pendingEventsStorage.d.ts +5 -0
- package/dist/types/logic/pendingEventsStorage.d.ts.map +1 -0
- package/dist/types/types/logSendResult.d.ts +2 -0
- package/dist/types/types/logSendResult.d.ts.map +1 -0
- package/package.json +10 -6
package/dist/index.mjs
CHANGED
|
@@ -20275,55 +20275,172 @@ var require_src = __commonJS2({
|
|
|
20275
20275
|
}
|
|
20276
20276
|
});
|
|
20277
20277
|
var import_debug = __toESM2(require_src());
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
|
|
20289
|
-
|
|
20290
|
-
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20299
|
-
}
|
|
20300
|
-
|
|
20301
|
-
|
|
20302
|
-
|
|
20303
|
-
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
|
|
20308
|
-
|
|
20309
|
-
|
|
20310
|
-
|
|
20311
|
-
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
20320
|
-
|
|
20321
|
-
|
|
20322
|
-
|
|
20323
|
-
|
|
20324
|
-
|
|
20325
|
-
|
|
20278
|
+
function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
|
|
20279
|
+
const logInfo22 = (0, import_debug.default)(`${namespace}:info`);
|
|
20280
|
+
const logTask = (0, import_debug.default)(`${namespace}:task`);
|
|
20281
|
+
const logError2 = (0, import_debug.default)(`${namespace}:error`);
|
|
20282
|
+
const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
|
|
20283
|
+
const logDebug = (0, import_debug.default)(`${namespace}:debug`);
|
|
20284
|
+
const logWarning = (0, import_debug.default)(`${namespace}:warning`);
|
|
20285
|
+
const logColor = (0, import_debug.default)(`${namespace}:color`);
|
|
20286
|
+
logInfo22.color = "19";
|
|
20287
|
+
logTask.color = "25";
|
|
20288
|
+
logError2.color = "1";
|
|
20289
|
+
logDetail2.color = "199";
|
|
20290
|
+
logWarning.color = "186";
|
|
20291
|
+
logDebug.color = "211";
|
|
20292
|
+
logColor.enabled = true;
|
|
20293
|
+
function setNamespace(namespace2) {
|
|
20294
|
+
logInfo22.namespace = `${namespace2}:info`;
|
|
20295
|
+
logTask.namespace = `${namespace2}:task`;
|
|
20296
|
+
logError2.namespace = `${namespace2}:error`;
|
|
20297
|
+
logDetail2.namespace = `${namespace2}:detail`;
|
|
20298
|
+
logWarning.namespace = `${namespace2}:warning`;
|
|
20299
|
+
logDebug.namespace = `${namespace2}:debug`;
|
|
20300
|
+
}
|
|
20301
|
+
function setLogLevel(level) {
|
|
20302
|
+
switch (level) {
|
|
20303
|
+
case "info":
|
|
20304
|
+
logInfo22.enabled = true;
|
|
20305
|
+
logTask.enabled = true;
|
|
20306
|
+
logError2.enabled = true;
|
|
20307
|
+
logWarning.enabled = true;
|
|
20308
|
+
logDetail2.enabled = false;
|
|
20309
|
+
logDebug.enabled = false;
|
|
20310
|
+
break;
|
|
20311
|
+
case "debug":
|
|
20312
|
+
logInfo22.enabled = true;
|
|
20313
|
+
logTask.enabled = true;
|
|
20314
|
+
logError2.enabled = true;
|
|
20315
|
+
logWarning.enabled = true;
|
|
20316
|
+
logDetail2.enabled = true;
|
|
20317
|
+
logDebug.enabled = true;
|
|
20318
|
+
break;
|
|
20319
|
+
case "none":
|
|
20320
|
+
logInfo22.enabled = false;
|
|
20321
|
+
logTask.enabled = false;
|
|
20322
|
+
logError2.enabled = false;
|
|
20323
|
+
logWarning.enabled = false;
|
|
20324
|
+
logDetail2.enabled = false;
|
|
20325
|
+
logDebug.enabled = false;
|
|
20326
|
+
break;
|
|
20327
|
+
}
|
|
20328
|
+
}
|
|
20329
|
+
setLogLevel(logLevel);
|
|
20330
|
+
function setColors(type, color) {
|
|
20331
|
+
switch (type) {
|
|
20332
|
+
case "info":
|
|
20333
|
+
logInfo22.color = color;
|
|
20334
|
+
break;
|
|
20335
|
+
case "task":
|
|
20336
|
+
logTask.color = color;
|
|
20337
|
+
break;
|
|
20338
|
+
case "error":
|
|
20339
|
+
logError2.color = color;
|
|
20340
|
+
break;
|
|
20341
|
+
case "detail":
|
|
20342
|
+
logDetail2.color = color;
|
|
20343
|
+
break;
|
|
20344
|
+
case "warning":
|
|
20345
|
+
logWarning.color = color;
|
|
20346
|
+
break;
|
|
20347
|
+
case "debug":
|
|
20348
|
+
logDebug.color = color;
|
|
20349
|
+
break;
|
|
20350
|
+
default:
|
|
20351
|
+
throw new Error(`Invalid log type: ${type}`);
|
|
20352
|
+
}
|
|
20353
|
+
}
|
|
20354
|
+
function printColors() {
|
|
20355
|
+
for (let i = 0; i < 256; i++) {
|
|
20356
|
+
logColor.color = `${i}`;
|
|
20357
|
+
logColor(`${i}: ${i}`);
|
|
20358
|
+
}
|
|
20359
|
+
}
|
|
20360
|
+
function logDataDetail(data, prefix = "# ") {
|
|
20361
|
+
if (data === null || data === void 0) {
|
|
20362
|
+
return `${prefix}<null or undefined>`;
|
|
20363
|
+
}
|
|
20364
|
+
if (typeof data !== "object") {
|
|
20365
|
+
return `${prefix}${String(data)}`;
|
|
20366
|
+
}
|
|
20367
|
+
const keys = Object.keys(data);
|
|
20368
|
+
let result = "";
|
|
20369
|
+
for (const key of keys) {
|
|
20370
|
+
result += `${prefix}${key}: `;
|
|
20371
|
+
if (key in data) {
|
|
20372
|
+
let dataKey = key;
|
|
20373
|
+
if (key in data) {
|
|
20374
|
+
dataKey = key;
|
|
20375
|
+
const value = data[dataKey];
|
|
20376
|
+
if (value === null || value === void 0) {
|
|
20377
|
+
result += `<${value === null ? "null" : "undefined"}>
|
|
20378
|
+
`;
|
|
20379
|
+
} else if (typeof value === "object") {
|
|
20380
|
+
result += `
|
|
20381
|
+
${logDataDetail(value, `${prefix} `)}
|
|
20382
|
+
`;
|
|
20383
|
+
} else {
|
|
20384
|
+
result += `${value}
|
|
20385
|
+
`;
|
|
20386
|
+
}
|
|
20387
|
+
}
|
|
20388
|
+
}
|
|
20389
|
+
}
|
|
20390
|
+
return result.trim();
|
|
20391
|
+
}
|
|
20392
|
+
function header(title, padding = 0) {
|
|
20393
|
+
return `${" ".repeat(padding)}${"=".repeat(80)}
|
|
20394
|
+
${" ".repeat(40 - title.length / 2)}${title}
|
|
20395
|
+
${" ".repeat(padding)}${"=".repeat(80)}`;
|
|
20396
|
+
}
|
|
20397
|
+
function logHeader(title) {
|
|
20398
|
+
logInfo22(`${header(title, 2)}`);
|
|
20399
|
+
}
|
|
20400
|
+
function logDataObject2(title, ...args) {
|
|
20401
|
+
const stack = new Error().stack?.split("\n")[2] || "";
|
|
20402
|
+
const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
|
|
20403
|
+
let callerDetails = "";
|
|
20404
|
+
if (stackMatch) {
|
|
20405
|
+
const functionMatch = stack.match(/at (.+) \(/);
|
|
20406
|
+
const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
|
|
20407
|
+
callerDetails = `${functionName}`;
|
|
20408
|
+
}
|
|
20409
|
+
logDetail2(`${header(`*${title}* ${callerDetails}`)}
|
|
20410
|
+
${args.reduce((acc, arg) => `${acc}
|
|
20411
|
+
${logDataDetail(arg)}`, "")}
|
|
20412
|
+
|
|
20413
|
+
${"=".repeat(80)}`);
|
|
20414
|
+
}
|
|
20415
|
+
function logErrorObject2(error, extraDetails) {
|
|
20416
|
+
if (error instanceof Error) {
|
|
20417
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
|
|
20418
|
+
Error Message:
|
|
20419
|
+
${error.message}
|
|
20420
|
+
Error Stack:
|
|
20421
|
+
${error.stack}
|
|
20422
|
+
${"=".repeat(80)}`);
|
|
20423
|
+
} else {
|
|
20424
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
|
|
20425
|
+
${"=".repeat(80)}`);
|
|
20426
|
+
}
|
|
20326
20427
|
}
|
|
20428
|
+
return {
|
|
20429
|
+
logInfo: logInfo22,
|
|
20430
|
+
logTask,
|
|
20431
|
+
logError: logError2,
|
|
20432
|
+
logDetail: logDetail2,
|
|
20433
|
+
logDebug,
|
|
20434
|
+
logWarning,
|
|
20435
|
+
logColor,
|
|
20436
|
+
setColors,
|
|
20437
|
+
printColors,
|
|
20438
|
+
logHeader,
|
|
20439
|
+
logDataObject: logDataObject2,
|
|
20440
|
+
logErrorObject: logErrorObject2,
|
|
20441
|
+
setLogLevel,
|
|
20442
|
+
setNamespace
|
|
20443
|
+
};
|
|
20327
20444
|
}
|
|
20328
20445
|
var AUTHORIZE_QUERY = `
|
|
20329
20446
|
query Authorize($input: AuthorizeInput!) {
|
|
@@ -20342,8 +20459,7 @@ var TOKEN_QUERY = `
|
|
|
20342
20459
|
}
|
|
20343
20460
|
}
|
|
20344
20461
|
`;
|
|
20345
|
-
|
|
20346
|
-
logNamespace("auth");
|
|
20462
|
+
var { logInfo } = createLoggers("auth");
|
|
20347
20463
|
var random = promisify(randomBytes);
|
|
20348
20464
|
async function getAuthToken(credentials, apiUrl) {
|
|
20349
20465
|
const authApiUrl = apiUrl || process.env.AUTH_API_URL;
|
|
@@ -21264,120 +21380,172 @@ var require_src4 = __commonJS3({
|
|
|
21264
21380
|
}
|
|
21265
21381
|
});
|
|
21266
21382
|
var import_debug2 = __toESM3(require_src4());
|
|
21267
|
-
|
|
21268
|
-
|
|
21269
|
-
|
|
21270
|
-
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
|
|
21275
|
-
|
|
21276
|
-
|
|
21277
|
-
|
|
21278
|
-
|
|
21279
|
-
|
|
21280
|
-
|
|
21281
|
-
|
|
21282
|
-
|
|
21283
|
-
|
|
21284
|
-
|
|
21285
|
-
|
|
21286
|
-
|
|
21287
|
-
|
|
21288
|
-
}
|
|
21289
|
-
|
|
21290
|
-
|
|
21291
|
-
|
|
21292
|
-
|
|
21293
|
-
|
|
21294
|
-
|
|
21295
|
-
|
|
21296
|
-
|
|
21297
|
-
|
|
21298
|
-
|
|
21299
|
-
|
|
21300
|
-
|
|
21301
|
-
|
|
21302
|
-
|
|
21303
|
-
|
|
21304
|
-
|
|
21305
|
-
|
|
21306
|
-
|
|
21307
|
-
|
|
21308
|
-
|
|
21309
|
-
|
|
21310
|
-
|
|
21311
|
-
|
|
21312
|
-
|
|
21313
|
-
|
|
21314
|
-
|
|
21315
|
-
|
|
21316
|
-
}
|
|
21317
|
-
|
|
21318
|
-
|
|
21319
|
-
|
|
21320
|
-
|
|
21321
|
-
|
|
21322
|
-
|
|
21323
|
-
|
|
21324
|
-
|
|
21325
|
-
|
|
21326
|
-
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21383
|
+
function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
|
|
21384
|
+
const logInfo3 = (0, import_debug2.default)(`${namespace}:info`);
|
|
21385
|
+
const logTask = (0, import_debug2.default)(`${namespace}:task`);
|
|
21386
|
+
const logError2 = (0, import_debug2.default)(`${namespace}:error`);
|
|
21387
|
+
const logDetail2 = (0, import_debug2.default)(`${namespace}:detail`);
|
|
21388
|
+
const logDebug = (0, import_debug2.default)(`${namespace}:debug`);
|
|
21389
|
+
const logWarning = (0, import_debug2.default)(`${namespace}:warning`);
|
|
21390
|
+
const logColor = (0, import_debug2.default)(`${namespace}:color`);
|
|
21391
|
+
logInfo3.color = "19";
|
|
21392
|
+
logTask.color = "25";
|
|
21393
|
+
logError2.color = "1";
|
|
21394
|
+
logDetail2.color = "199";
|
|
21395
|
+
logWarning.color = "186";
|
|
21396
|
+
logDebug.color = "211";
|
|
21397
|
+
logColor.enabled = true;
|
|
21398
|
+
function setNamespace(namespace2) {
|
|
21399
|
+
logInfo3.namespace = `${namespace2}:info`;
|
|
21400
|
+
logTask.namespace = `${namespace2}:task`;
|
|
21401
|
+
logError2.namespace = `${namespace2}:error`;
|
|
21402
|
+
logDetail2.namespace = `${namespace2}:detail`;
|
|
21403
|
+
logWarning.namespace = `${namespace2}:warning`;
|
|
21404
|
+
logDebug.namespace = `${namespace2}:debug`;
|
|
21405
|
+
}
|
|
21406
|
+
function setLogLevel(level) {
|
|
21407
|
+
switch (level) {
|
|
21408
|
+
case "info":
|
|
21409
|
+
logInfo3.enabled = true;
|
|
21410
|
+
logTask.enabled = true;
|
|
21411
|
+
logError2.enabled = true;
|
|
21412
|
+
logWarning.enabled = true;
|
|
21413
|
+
logDetail2.enabled = false;
|
|
21414
|
+
logDebug.enabled = false;
|
|
21415
|
+
break;
|
|
21416
|
+
case "debug":
|
|
21417
|
+
logInfo3.enabled = true;
|
|
21418
|
+
logTask.enabled = true;
|
|
21419
|
+
logError2.enabled = true;
|
|
21420
|
+
logWarning.enabled = true;
|
|
21421
|
+
logDetail2.enabled = true;
|
|
21422
|
+
logDebug.enabled = true;
|
|
21423
|
+
break;
|
|
21424
|
+
case "none":
|
|
21425
|
+
logInfo3.enabled = false;
|
|
21426
|
+
logTask.enabled = false;
|
|
21427
|
+
logError2.enabled = false;
|
|
21428
|
+
logWarning.enabled = false;
|
|
21429
|
+
logDetail2.enabled = false;
|
|
21430
|
+
logDebug.enabled = false;
|
|
21431
|
+
break;
|
|
21432
|
+
}
|
|
21433
|
+
}
|
|
21434
|
+
setLogLevel(logLevel);
|
|
21435
|
+
function setColors(type, color) {
|
|
21436
|
+
switch (type) {
|
|
21437
|
+
case "info":
|
|
21438
|
+
logInfo3.color = color;
|
|
21439
|
+
break;
|
|
21440
|
+
case "task":
|
|
21441
|
+
logTask.color = color;
|
|
21442
|
+
break;
|
|
21443
|
+
case "error":
|
|
21444
|
+
logError2.color = color;
|
|
21445
|
+
break;
|
|
21446
|
+
case "detail":
|
|
21447
|
+
logDetail2.color = color;
|
|
21448
|
+
break;
|
|
21449
|
+
case "warning":
|
|
21450
|
+
logWarning.color = color;
|
|
21451
|
+
break;
|
|
21452
|
+
case "debug":
|
|
21453
|
+
logDebug.color = color;
|
|
21454
|
+
break;
|
|
21455
|
+
default:
|
|
21456
|
+
throw new Error(`Invalid log type: ${type}`);
|
|
21457
|
+
}
|
|
21458
|
+
}
|
|
21459
|
+
function printColors() {
|
|
21460
|
+
for (let i = 0; i < 256; i++) {
|
|
21461
|
+
logColor.color = `${i}`;
|
|
21462
|
+
logColor(`${i}: ${i}`);
|
|
21463
|
+
}
|
|
21464
|
+
}
|
|
21465
|
+
function logDataDetail(data, prefix = "# ") {
|
|
21466
|
+
if (data === null || data === void 0) {
|
|
21467
|
+
return `${prefix}<null or undefined>`;
|
|
21468
|
+
}
|
|
21469
|
+
if (typeof data !== "object") {
|
|
21470
|
+
return `${prefix}${String(data)}`;
|
|
21471
|
+
}
|
|
21472
|
+
const keys = Object.keys(data);
|
|
21473
|
+
let result = "";
|
|
21474
|
+
for (const key of keys) {
|
|
21475
|
+
result += `${prefix}${key}: `;
|
|
21330
21476
|
if (key in data) {
|
|
21331
|
-
dataKey = key;
|
|
21332
|
-
|
|
21333
|
-
|
|
21334
|
-
|
|
21477
|
+
let dataKey = key;
|
|
21478
|
+
if (key in data) {
|
|
21479
|
+
dataKey = key;
|
|
21480
|
+
const value = data[dataKey];
|
|
21481
|
+
if (value === null || value === void 0) {
|
|
21482
|
+
result += `<${value === null ? "null" : "undefined"}>
|
|
21335
21483
|
`;
|
|
21336
|
-
|
|
21337
|
-
|
|
21338
|
-
${logDataDetail(value, `${prefix} `)}
|
|
21484
|
+
} else if (typeof value === "object") {
|
|
21485
|
+
result += `
|
|
21486
|
+
${logDataDetail(value, `${prefix} `)}
|
|
21339
21487
|
`;
|
|
21340
|
-
|
|
21341
|
-
|
|
21488
|
+
} else {
|
|
21489
|
+
result += `${value}
|
|
21342
21490
|
`;
|
|
21491
|
+
}
|
|
21343
21492
|
}
|
|
21344
21493
|
}
|
|
21345
21494
|
}
|
|
21495
|
+
return result.trim();
|
|
21346
21496
|
}
|
|
21347
|
-
|
|
21348
|
-
}
|
|
21349
|
-
function header(title, padding = 0) {
|
|
21350
|
-
return `${" ".repeat(padding)}${"=".repeat(80)}
|
|
21497
|
+
function header(title, padding = 0) {
|
|
21498
|
+
return `${" ".repeat(padding)}${"=".repeat(80)}
|
|
21351
21499
|
${" ".repeat(40 - title.length / 2)}${title}
|
|
21352
21500
|
${" ".repeat(padding)}${"=".repeat(80)}`;
|
|
21353
|
-
}
|
|
21354
|
-
function
|
|
21355
|
-
|
|
21356
|
-
|
|
21357
|
-
|
|
21358
|
-
|
|
21359
|
-
const
|
|
21360
|
-
|
|
21361
|
-
|
|
21362
|
-
|
|
21363
|
-
|
|
21501
|
+
}
|
|
21502
|
+
function logHeader(title) {
|
|
21503
|
+
logInfo3(`${header(title, 2)}`);
|
|
21504
|
+
}
|
|
21505
|
+
function logDataObject2(title, ...args) {
|
|
21506
|
+
const stack = new Error().stack?.split("\n")[2] || "";
|
|
21507
|
+
const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
|
|
21508
|
+
let callerDetails = "";
|
|
21509
|
+
if (stackMatch) {
|
|
21510
|
+
const functionMatch = stack.match(/at (.+) \(/);
|
|
21511
|
+
const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
|
|
21512
|
+
callerDetails = `${functionName}`;
|
|
21513
|
+
}
|
|
21514
|
+
logDetail2(`${header(`*${title}* ${callerDetails}`)}
|
|
21364
21515
|
${args.reduce((acc, arg) => `${acc}
|
|
21365
21516
|
${logDataDetail(arg)}`, "")}
|
|
21366
|
-
|
|
21517
|
+
|
|
21367
21518
|
${"=".repeat(80)}`);
|
|
21368
|
-
}
|
|
21369
|
-
function logErrorObject(error, extraDetails) {
|
|
21370
|
-
if (error instanceof Error) {
|
|
21371
|
-
logError2(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
|
|
21372
|
-
Error Message:
|
|
21373
|
-
${error.message}
|
|
21374
|
-
Error Stack:
|
|
21375
|
-
${error.stack}
|
|
21376
|
-
${"=".repeat(80)}`);
|
|
21377
|
-
} else {
|
|
21378
|
-
logError2(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
|
|
21379
|
-
${"=".repeat(80)}`);
|
|
21380
21519
|
}
|
|
21520
|
+
function logErrorObject2(error, extraDetails) {
|
|
21521
|
+
if (error instanceof Error) {
|
|
21522
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
|
|
21523
|
+
Error Message:
|
|
21524
|
+
${error.message}
|
|
21525
|
+
Error Stack:
|
|
21526
|
+
${error.stack}
|
|
21527
|
+
${"=".repeat(80)}`);
|
|
21528
|
+
} else {
|
|
21529
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
|
|
21530
|
+
${"=".repeat(80)}`);
|
|
21531
|
+
}
|
|
21532
|
+
}
|
|
21533
|
+
return {
|
|
21534
|
+
logInfo: logInfo3,
|
|
21535
|
+
logTask,
|
|
21536
|
+
logError: logError2,
|
|
21537
|
+
logDetail: logDetail2,
|
|
21538
|
+
logDebug,
|
|
21539
|
+
logWarning,
|
|
21540
|
+
logColor,
|
|
21541
|
+
setColors,
|
|
21542
|
+
printColors,
|
|
21543
|
+
logHeader,
|
|
21544
|
+
logDataObject: logDataObject2,
|
|
21545
|
+
logErrorObject: logErrorObject2,
|
|
21546
|
+
setLogLevel,
|
|
21547
|
+
setNamespace
|
|
21548
|
+
};
|
|
21381
21549
|
}
|
|
21382
21550
|
|
|
21383
21551
|
// ../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist-node/stringify.js
|
|
@@ -21434,16 +21602,79 @@ function v4(options, buf, offset) {
|
|
|
21434
21602
|
}
|
|
21435
21603
|
var v4_default = v4;
|
|
21436
21604
|
|
|
21605
|
+
// src/logic/cronSchedule.ts
|
|
21606
|
+
function getNextCronRun(intervalMs) {
|
|
21607
|
+
const now = Date.now();
|
|
21608
|
+
const midnight = new Date(now);
|
|
21609
|
+
midnight.setHours(0, 0, 0, 0);
|
|
21610
|
+
const msSinceMidnight = now - midnight.getTime();
|
|
21611
|
+
const nextBoundaryMs = Math.ceil(msSinceMidnight / intervalMs) * intervalMs;
|
|
21612
|
+
let nextRun = midnight.getTime() + nextBoundaryMs;
|
|
21613
|
+
if (nextRun <= now) {
|
|
21614
|
+
nextRun += intervalMs;
|
|
21615
|
+
}
|
|
21616
|
+
return nextRun;
|
|
21617
|
+
}
|
|
21618
|
+
|
|
21619
|
+
// src/logic/pendingEventsStorage.ts
|
|
21620
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
21621
|
+
async function readPendingEvents(filePath) {
|
|
21622
|
+
try {
|
|
21623
|
+
const data = await readFile(filePath, "utf-8");
|
|
21624
|
+
return JSON.parse(data);
|
|
21625
|
+
} catch (error) {
|
|
21626
|
+
const err = error;
|
|
21627
|
+
if (err.code === "ENOENT") {
|
|
21628
|
+
return [];
|
|
21629
|
+
}
|
|
21630
|
+
throw error;
|
|
21631
|
+
}
|
|
21632
|
+
}
|
|
21633
|
+
async function writePendingEvents(filePath, events) {
|
|
21634
|
+
await writeFile(filePath, JSON.stringify(events), "utf-8");
|
|
21635
|
+
}
|
|
21636
|
+
async function deletePendingEvents(filePath) {
|
|
21637
|
+
try {
|
|
21638
|
+
await unlink(filePath);
|
|
21639
|
+
} catch (error) {
|
|
21640
|
+
const err = error;
|
|
21641
|
+
if (err.code !== "ENOENT") {
|
|
21642
|
+
throw error;
|
|
21643
|
+
}
|
|
21644
|
+
}
|
|
21645
|
+
}
|
|
21646
|
+
|
|
21437
21647
|
// src/logic/logClient.ts
|
|
21648
|
+
var { logInfo: logInfo2, logError, logErrorObject, logDetail, logDataObject } = createLoggers2("logging");
|
|
21438
21649
|
var LogClient = class {
|
|
21439
21650
|
credentials;
|
|
21440
21651
|
loggingClient;
|
|
21441
|
-
offlinetime;
|
|
21442
21652
|
cachedEvents = [];
|
|
21443
21653
|
initialized = false;
|
|
21654
|
+
firstOfflineTime;
|
|
21655
|
+
sendTimeoutId;
|
|
21656
|
+
timeBetweenLogMs;
|
|
21657
|
+
maxOfflineTimeMs;
|
|
21658
|
+
pendingEventsPath;
|
|
21659
|
+
sendInProgress = false;
|
|
21660
|
+
schedulerStarted = false;
|
|
21444
21661
|
async init() {
|
|
21445
|
-
|
|
21446
|
-
|
|
21662
|
+
if (typeof this.timeBetweenLogMs !== "number") {
|
|
21663
|
+
const DEFAULT_TIME_BETWEEN_LOG_MS = 10 * 60 * 1e3;
|
|
21664
|
+
const DEFAULT_MAX_OFFLINE_TIME_MS = 60 * 60 * 1e3;
|
|
21665
|
+
const timeBetweenLog = process.env.TIME_BETWEEN_LOG;
|
|
21666
|
+
const maxOfflineTime = process.env.MAX_OFFLINE_TIME;
|
|
21667
|
+
const cachedEventsPath = process.env.CACHED_EVENTS_PATH;
|
|
21668
|
+
if (!cachedEventsPath) {
|
|
21669
|
+
throw new Error("CACHED_EVENTS_PATH must be set");
|
|
21670
|
+
}
|
|
21671
|
+
this.timeBetweenLogMs = Number(timeBetweenLog) || DEFAULT_TIME_BETWEEN_LOG_MS;
|
|
21672
|
+
this.maxOfflineTimeMs = Number(maxOfflineTime) || DEFAULT_MAX_OFFLINE_TIME_MS;
|
|
21673
|
+
this.pendingEventsPath = cachedEventsPath;
|
|
21674
|
+
if (!Number.isFinite(this.timeBetweenLogMs) || this.timeBetweenLogMs <= 0 || !Number.isFinite(this.maxOfflineTimeMs) || this.maxOfflineTimeMs <= 0) {
|
|
21675
|
+
throw new Error("TIME_BETWEEN_LOG and MAX_OFFLINE_TIME must be positive numbers");
|
|
21676
|
+
}
|
|
21677
|
+
}
|
|
21447
21678
|
const os4 = await import("node:os");
|
|
21448
21679
|
const path = await import("node:path");
|
|
21449
21680
|
const fs = await import("node:fs/promises");
|
|
@@ -21456,7 +21687,7 @@ var LogClient = class {
|
|
|
21456
21687
|
const tokenData = await fs.readFile(tokenFilePath, "utf-8");
|
|
21457
21688
|
tokenFile = JSON.parse(tokenData);
|
|
21458
21689
|
logInfo2(`Loaded token from temp file: ${tokenFilePath}`);
|
|
21459
|
-
|
|
21690
|
+
logDetail(
|
|
21460
21691
|
`Token will expire ${(tokenFile.time + tokenFile.token.expiresIn * 1e3 - Date.now()) / (1e3 * 60)} minutes`
|
|
21461
21692
|
);
|
|
21462
21693
|
} catch (_error) {
|
|
@@ -21482,18 +21713,81 @@ var LogClient = class {
|
|
|
21482
21713
|
} else {
|
|
21483
21714
|
token = tokenFile.token;
|
|
21484
21715
|
}
|
|
21485
|
-
if (
|
|
21486
|
-
throw new Error("Token not found");
|
|
21487
|
-
}
|
|
21488
|
-
try {
|
|
21716
|
+
if (token) {
|
|
21489
21717
|
const loggingApi = process.env.LOGGING_API_URL ?? "";
|
|
21490
21718
|
if (!loggingApi) {
|
|
21491
21719
|
throw new Error("LOGGING_API_URL is not set");
|
|
21492
21720
|
}
|
|
21493
21721
|
this.loggingClient = new import_gql_logging_client.default(loggingApi, token.accessToken);
|
|
21494
21722
|
this.initialized = true;
|
|
21495
|
-
}
|
|
21496
|
-
|
|
21723
|
+
} else {
|
|
21724
|
+
logError("Check your internet connection - token not found");
|
|
21725
|
+
}
|
|
21726
|
+
if (!this.schedulerStarted) {
|
|
21727
|
+
this.schedulerStarted = true;
|
|
21728
|
+
this.scheduleNextRun();
|
|
21729
|
+
}
|
|
21730
|
+
}
|
|
21731
|
+
scheduleNextRun() {
|
|
21732
|
+
if (this.sendTimeoutId !== void 0) {
|
|
21733
|
+
clearTimeout(this.sendTimeoutId);
|
|
21734
|
+
this.sendTimeoutId = void 0;
|
|
21735
|
+
}
|
|
21736
|
+
const nextRun = getNextCronRun(this.timeBetweenLogMs);
|
|
21737
|
+
const delay = Math.max(0, nextRun - Date.now());
|
|
21738
|
+
this.sendTimeoutId = setTimeout(() => {
|
|
21739
|
+
void this.runScheduledSend();
|
|
21740
|
+
}, delay);
|
|
21741
|
+
}
|
|
21742
|
+
async runScheduledSend() {
|
|
21743
|
+
try {
|
|
21744
|
+
await this.sendBatch();
|
|
21745
|
+
} catch {
|
|
21746
|
+
this.sendTimeoutId = void 0;
|
|
21747
|
+
return;
|
|
21748
|
+
}
|
|
21749
|
+
this.scheduleNextRun();
|
|
21750
|
+
}
|
|
21751
|
+
async sendBatch() {
|
|
21752
|
+
if (this.sendInProgress) {
|
|
21753
|
+
return;
|
|
21754
|
+
}
|
|
21755
|
+
this.sendInProgress = true;
|
|
21756
|
+
try {
|
|
21757
|
+
const loaded = await readPendingEvents(this.pendingEventsPath);
|
|
21758
|
+
const batch = [...this.cachedEvents, ...loaded];
|
|
21759
|
+
this.cachedEvents = [];
|
|
21760
|
+
if (batch.length === 0) {
|
|
21761
|
+
this.firstOfflineTime = void 0;
|
|
21762
|
+
return;
|
|
21763
|
+
}
|
|
21764
|
+
if (!this.loggingClient) {
|
|
21765
|
+
if (this.firstOfflineTime === void 0) {
|
|
21766
|
+
this.firstOfflineTime = Date.now();
|
|
21767
|
+
}
|
|
21768
|
+
await writePendingEvents(this.pendingEventsPath, batch);
|
|
21769
|
+
if (Date.now() - this.firstOfflineTime > this.maxOfflineTimeMs) {
|
|
21770
|
+
throw new Error("Exceeded max offline time");
|
|
21771
|
+
}
|
|
21772
|
+
return;
|
|
21773
|
+
}
|
|
21774
|
+
try {
|
|
21775
|
+
await this.loggingClient.mutate({ events: batch }).promise();
|
|
21776
|
+
await deletePendingEvents(this.pendingEventsPath);
|
|
21777
|
+
this.firstOfflineTime = void 0;
|
|
21778
|
+
logInfo2(`Logging batch result: ${batch.length} events sent`);
|
|
21779
|
+
} catch (error) {
|
|
21780
|
+
logError("Send batch failed", error);
|
|
21781
|
+
if (this.firstOfflineTime === void 0) {
|
|
21782
|
+
this.firstOfflineTime = Date.now();
|
|
21783
|
+
}
|
|
21784
|
+
await writePendingEvents(this.pendingEventsPath, batch);
|
|
21785
|
+
if (Date.now() - this.firstOfflineTime > this.maxOfflineTimeMs) {
|
|
21786
|
+
throw new Error("Exceeded max offline time");
|
|
21787
|
+
}
|
|
21788
|
+
}
|
|
21789
|
+
} finally {
|
|
21790
|
+
this.sendInProgress = false;
|
|
21497
21791
|
}
|
|
21498
21792
|
}
|
|
21499
21793
|
async logEvent(event) {
|
|
@@ -21510,34 +21804,8 @@ var LogClient = class {
|
|
|
21510
21804
|
...event
|
|
21511
21805
|
};
|
|
21512
21806
|
logDataObject("Logging event", newEvent);
|
|
21513
|
-
|
|
21514
|
-
|
|
21515
|
-
if (!this.offlinetime) {
|
|
21516
|
-
this.offlinetime = Date.now();
|
|
21517
|
-
} else if (Date.now() - this.offlinetime > +(process.env.OFFLINE_TIME ?? 1e3 * 60 * 60)) {
|
|
21518
|
-
if (process.env.APP_TYPE === "node") {
|
|
21519
|
-
const { writeFile } = await import("node:fs/promises");
|
|
21520
|
-
if (!process.env.CACHED_EVENTS_PATH) {
|
|
21521
|
-
throw new Error("CACHED_EVENTS_PATH is not set");
|
|
21522
|
-
}
|
|
21523
|
-
await writeFile(
|
|
21524
|
-
`${process.env.CACHED_EVENTS_PATH}-${Date.now()}.json`,
|
|
21525
|
-
JSON.stringify(this.cachedEvents)
|
|
21526
|
-
);
|
|
21527
|
-
logInfo2(`Cached events saved to: ${process.env.CACHED_EVENTS_PATH}`);
|
|
21528
|
-
this.offlinetime = Date.now();
|
|
21529
|
-
this.cachedEvents = [];
|
|
21530
|
-
}
|
|
21531
|
-
}
|
|
21532
|
-
this.cachedEvents.push(newEvent);
|
|
21533
|
-
return;
|
|
21534
|
-
}
|
|
21535
|
-
const result = await this.loggingClient.mutate({
|
|
21536
|
-
events: [newEvent, ...this.cachedEvents]
|
|
21537
|
-
}).promise();
|
|
21538
|
-
this.cachedEvents = [];
|
|
21539
|
-
logInfo2(`Logging event result: ${JSON.stringify(result)}`);
|
|
21540
|
-
return result;
|
|
21807
|
+
this.cachedEvents.push(newEvent);
|
|
21808
|
+
return "delayed";
|
|
21541
21809
|
}
|
|
21542
21810
|
};
|
|
21543
21811
|
export {
|