vr-commons 1.0.155 → 1.0.157
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/utils/admin.device.utils.d.ts +23 -0
- package/dist/utils/admin.device.utils.js +200 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +13 -1
- package/dist/utils/systemLog.utils.d.ts +60 -0
- package/dist/utils/systemLog.utils.js +148 -0
- package/dist/validations/admin.devicePayment.validations.d.ts +50 -50
- package/dist/validations/admin.devicePayment.validations.js +0 -1
- package/dist/validations/admin.devices.validations.d.ts +39 -0
- package/dist/validations/admin.devices.validations.js +28 -1
- package/dist/validations/admin.installment.validations.d.ts +8 -8
- package/dist/validations/admin.installment.validations.js +0 -1
- package/dist/validations/appSpecs.validations.d.ts +18 -18
- package/dist/validations/appeals.validations.d.ts +8 -8
- package/dist/validations/auth.validations.d.ts +4 -4
- package/dist/validations/bans.validations.d.ts +8 -8
- package/dist/validations/devicePaymentPlan.validations.d.ts +16 -16
- package/dist/validations/eventlogs.admin.validations.d.ts +31 -31
- package/dist/validations/index.d.ts +1 -1
- package/dist/validations/index.js +3 -1
- package/dist/validations/moderation.validations.d.ts +105 -105
- package/dist/validations/pricings.validations.d.ts +36 -36
- package/dist/validations/product.validations.d.ts +36 -36
- package/dist/validations/profiles.validations.d.ts +56 -56
- package/dist/validations/suspensions.validations.d.ts +8 -8
- package/dist/validations/users.admin.validations.d.ts +48 -48
- package/package.json +2 -2
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { Device, UserRole } from "vr-models";
|
|
2
2
|
import { Transaction } from "sequelize";
|
|
3
3
|
import { StockChangeResult } from "./types";
|
|
4
|
+
export interface LockAllDevicesResult {
|
|
5
|
+
success: boolean;
|
|
6
|
+
lockedCount: number;
|
|
7
|
+
failedCount: number;
|
|
8
|
+
failedDeviceIds: string[];
|
|
9
|
+
errors: string[];
|
|
10
|
+
message: string;
|
|
11
|
+
totalProcessed: number;
|
|
12
|
+
}
|
|
13
|
+
export interface LockDevicesOptions {
|
|
14
|
+
actorId?: string;
|
|
15
|
+
actorRole?: UserRole | string;
|
|
16
|
+
transaction?: any;
|
|
17
|
+
batchSize?: number;
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
triggeredBy?: "cronjob" | "manual";
|
|
20
|
+
}
|
|
4
21
|
export declare const stockUtil: {
|
|
5
22
|
/**
|
|
6
23
|
* Increment stock when devices are added/created
|
|
@@ -120,4 +137,10 @@ export declare const stockUtil: {
|
|
|
120
137
|
message: string;
|
|
121
138
|
devices: Device[];
|
|
122
139
|
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Lock ALL devices regardless of payment plan status
|
|
142
|
+
* Uses batch processing for large datasets
|
|
143
|
+
* If no transaction is provided, runs without transaction
|
|
144
|
+
*/
|
|
145
|
+
lockAllDevices(options?: LockDevicesOptions): Promise<LockAllDevicesResult>;
|
|
123
146
|
};
|
|
@@ -6,6 +6,7 @@ const vr_models_1 = require("vr-models");
|
|
|
6
6
|
const sequelize_1 = require("sequelize");
|
|
7
7
|
const eventLog_utils_1 = require("./eventLog.utils");
|
|
8
8
|
const admin_devices_validations_1 = require("../validations/admin.devices.validations");
|
|
9
|
+
const systemLog_utils_1 = require("./systemLog.utils");
|
|
9
10
|
/**
|
|
10
11
|
* Extract dedication from serial number
|
|
11
12
|
*/
|
|
@@ -451,4 +452,203 @@ exports.stockUtil = {
|
|
|
451
452
|
devices: updatedDevices,
|
|
452
453
|
};
|
|
453
454
|
},
|
|
455
|
+
/**
|
|
456
|
+
* Lock ALL devices regardless of payment plan status
|
|
457
|
+
* Uses batch processing for large datasets
|
|
458
|
+
* If no transaction is provided, runs without transaction
|
|
459
|
+
*/
|
|
460
|
+
async lockAllDevices(options = {}) {
|
|
461
|
+
const { actorId = "SYSTEM", actorRole = "SYSTEM", transaction, batchSize = 100, maxRetries = 3, triggeredBy = "manual", } = options;
|
|
462
|
+
const isSystem = actorRole === "SYSTEM" || triggeredBy === "cronjob";
|
|
463
|
+
const isAdmin = !isSystem;
|
|
464
|
+
try {
|
|
465
|
+
const lockedDeviceIds = [];
|
|
466
|
+
const failedDeviceIds = [];
|
|
467
|
+
const errors = [];
|
|
468
|
+
let totalLocked = 0;
|
|
469
|
+
let totalProcessed = 0;
|
|
470
|
+
let batchNumber = 0;
|
|
471
|
+
let hasMore = true;
|
|
472
|
+
console.log(`🔒 Locking ALL devices at ${new Date().toISOString()}`);
|
|
473
|
+
// Log start of job
|
|
474
|
+
if (isSystem) {
|
|
475
|
+
await (0, systemLog_utils_1.logInfo)(`Lock all devices job started`, {
|
|
476
|
+
category: "CRONJOB",
|
|
477
|
+
source: "device-lock.cronjob",
|
|
478
|
+
details: { triggeredBy, batchSize, maxRetries },
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
await (0, systemLog_utils_1.logInfo)(`Lock all devices triggered by ${actorRole}`, {
|
|
483
|
+
category: "DEVICE",
|
|
484
|
+
userId: actorId || undefined,
|
|
485
|
+
userRole: actorRole,
|
|
486
|
+
source: "device-lock.manual",
|
|
487
|
+
details: { triggeredBy, batchSize, maxRetries },
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
// Process in batches
|
|
491
|
+
while (hasMore) {
|
|
492
|
+
batchNumber++;
|
|
493
|
+
const offset = (batchNumber - 1) * batchSize;
|
|
494
|
+
// Get devices for current batch (ALL devices except disabled)
|
|
495
|
+
const devices = await vr_models_1.Device.findAll({
|
|
496
|
+
where: {
|
|
497
|
+
status: { [sequelize_1.Op.ne]: "disabled" },
|
|
498
|
+
deletedAt: null,
|
|
499
|
+
},
|
|
500
|
+
limit: batchSize,
|
|
501
|
+
offset: offset,
|
|
502
|
+
transaction: transaction, // Use transaction if provided, otherwise undefined
|
|
503
|
+
});
|
|
504
|
+
if (devices.length === 0) {
|
|
505
|
+
hasMore = false;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
totalProcessed += devices.length;
|
|
509
|
+
console.log(`📦 Batch ${batchNumber}: Processing ${devices.length} devices (Total: ${totalProcessed})`);
|
|
510
|
+
// Process each device with retry logic
|
|
511
|
+
for (const device of devices) {
|
|
512
|
+
let retries = 0;
|
|
513
|
+
let locked = false;
|
|
514
|
+
while (!locked && retries < maxRetries) {
|
|
515
|
+
try {
|
|
516
|
+
// Skip if already locked
|
|
517
|
+
if (device.status === "locked") {
|
|
518
|
+
console.log(`🔒 Device ${device.serialNumber} already locked`);
|
|
519
|
+
locked = true;
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
// Lock the device
|
|
523
|
+
await device.update({ status: "locked" }, { transaction: transaction } // Use transaction if provided
|
|
524
|
+
);
|
|
525
|
+
lockedDeviceIds.push(device.id);
|
|
526
|
+
totalLocked++;
|
|
527
|
+
locked = true;
|
|
528
|
+
console.log(`🔒 Locked device ${device.serialNumber} (${device.id})`);
|
|
529
|
+
// Log event for each lock
|
|
530
|
+
await (0, eventLog_utils_1.logEvent)({
|
|
531
|
+
actorId: isSystem ? null : actorId,
|
|
532
|
+
actorType: isSystem ? "ADMIN" : actorRole,
|
|
533
|
+
action: "DEVICES_LOCKED",
|
|
534
|
+
entity: "Device",
|
|
535
|
+
entityId: device.id,
|
|
536
|
+
metadata: {
|
|
537
|
+
serialNumber: device.serialNumber,
|
|
538
|
+
pairId: device.pairId,
|
|
539
|
+
productId: device.productId,
|
|
540
|
+
lockedAt: new Date().toISOString(),
|
|
541
|
+
reason: "Scheduled lock all devices",
|
|
542
|
+
triggeredBy: triggeredBy,
|
|
543
|
+
batchNumber,
|
|
544
|
+
previousStatus: device.status,
|
|
545
|
+
},
|
|
546
|
+
deviceSession: null,
|
|
547
|
+
transaction: transaction,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
catch (err) {
|
|
551
|
+
retries++;
|
|
552
|
+
console.error(`❌ Failed to lock device ${device.serialNumber} (attempt ${retries}/${maxRetries}):`, err instanceof Error ? err.message : "Unknown error");
|
|
553
|
+
if (retries >= maxRetries) {
|
|
554
|
+
failedDeviceIds.push(device.id);
|
|
555
|
+
errors.push(`Device ${device.serialNumber} (${device.id}): ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
// Wait before retry (exponential backoff)
|
|
559
|
+
await new Promise((resolve) => setTimeout(resolve, retries * 1000));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// If we got fewer devices than batch size, we're done
|
|
565
|
+
if (devices.length < batchSize) {
|
|
566
|
+
hasMore = false;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const result = {
|
|
570
|
+
success: true,
|
|
571
|
+
lockedCount: totalLocked,
|
|
572
|
+
failedCount: failedDeviceIds.length,
|
|
573
|
+
failedDeviceIds,
|
|
574
|
+
errors,
|
|
575
|
+
totalProcessed,
|
|
576
|
+
message: `Successfully locked ${totalLocked} devices out of ${totalProcessed} processed${failedDeviceIds.length > 0 ? `, ${failedDeviceIds.length} failed` : ""}`,
|
|
577
|
+
};
|
|
578
|
+
console.log(`✅ Lock all devices completed:`, result);
|
|
579
|
+
// Log completion
|
|
580
|
+
if (isSystem) {
|
|
581
|
+
await (0, systemLog_utils_1.logInfo)(`Lock all devices job completed`, {
|
|
582
|
+
category: "CRONJOB",
|
|
583
|
+
source: "device-lock.cronjob",
|
|
584
|
+
details: {
|
|
585
|
+
lockedCount: result.lockedCount,
|
|
586
|
+
failedCount: result.failedCount,
|
|
587
|
+
totalProcessed: result.totalProcessed,
|
|
588
|
+
hasErrors: result.errors.length > 0,
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
await (0, systemLog_utils_1.logInfo)(`Lock all devices completed by ${actorRole}`, {
|
|
594
|
+
category: "DEVICE",
|
|
595
|
+
userId: actorId || undefined,
|
|
596
|
+
userRole: actorRole,
|
|
597
|
+
source: "device-lock.manual",
|
|
598
|
+
details: {
|
|
599
|
+
lockedCount: result.lockedCount,
|
|
600
|
+
failedCount: result.failedCount,
|
|
601
|
+
totalProcessed: result.totalProcessed,
|
|
602
|
+
hasErrors: result.errors.length > 0,
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
// Log errors if any
|
|
607
|
+
if (result.errors.length > 0) {
|
|
608
|
+
await (0, systemLog_utils_1.logError)(`Lock all devices had ${result.errors.length} failures`, {
|
|
609
|
+
category: isSystem ? "CRONJOB" : "DEVICE",
|
|
610
|
+
source: isSystem ? "device-lock.cronjob" : "device-lock.manual",
|
|
611
|
+
userId: isSystem ? null : actorId || undefined,
|
|
612
|
+
userRole: isSystem ? null : actorRole,
|
|
613
|
+
details: {
|
|
614
|
+
failedCount: result.failedCount,
|
|
615
|
+
failedDeviceIds: result.failedDeviceIds,
|
|
616
|
+
errors: result.errors,
|
|
617
|
+
},
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return result;
|
|
621
|
+
}
|
|
622
|
+
catch (err) {
|
|
623
|
+
console.error("❌ Lock all devices failed:", err);
|
|
624
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error occurred";
|
|
625
|
+
const result = {
|
|
626
|
+
success: false,
|
|
627
|
+
lockedCount: 0,
|
|
628
|
+
failedCount: 0,
|
|
629
|
+
failedDeviceIds: [],
|
|
630
|
+
errors: [errorMessage],
|
|
631
|
+
totalProcessed: 0,
|
|
632
|
+
message: `Lock all devices job failed: ${errorMessage}`,
|
|
633
|
+
};
|
|
634
|
+
// Log failure
|
|
635
|
+
if (isSystem) {
|
|
636
|
+
await (0, systemLog_utils_1.logError)(`Lock all devices job failed`, {
|
|
637
|
+
category: "CRONJOB",
|
|
638
|
+
source: "device-lock.cronjob",
|
|
639
|
+
details: { error: errorMessage },
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
await (0, systemLog_utils_1.logError)(`Lock all devices failed`, {
|
|
644
|
+
category: "DEVICE",
|
|
645
|
+
userId: actorId || undefined,
|
|
646
|
+
userRole: actorRole,
|
|
647
|
+
source: "device-lock.manual",
|
|
648
|
+
details: { error: errorMessage },
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
return result;
|
|
652
|
+
}
|
|
653
|
+
},
|
|
454
654
|
};
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export { DPP_OperationsUtil } from "./admin.devicePayment.utils";
|
|
|
15
15
|
export { PendingRegistration, VerificationMethod, ConfirmResponse, UploadResult, StockChangeResult, } from "./types";
|
|
16
16
|
export { formatDeviceSession, formatEventLog, formatEventLogs, buildEventLogWhereClause, buildSearchConditions, buildUserSearchConditions, } from "./eventlogs.admin.utils";
|
|
17
17
|
export { extractDedicatedUserFromSerial } from "./deviceUtils";
|
|
18
|
+
export { logApi, logAuth, logCronjob, logDebug, logDevice, logError, logInfo, logPayment, logSecurity, logSystem, logWarning, } from "./systemLog.utils";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateContactValue = exports.detectContactType = exports.sendVerificationCode = exports.sendSMS = exports.sendEmail = exports.getVerificationMethod = exports.getOTPExpiry = exports.generateOTP = exports.createDeviceSession = exports.suspensionUtil = exports.banUtil = exports.hasHigherAuthority = exports.getModeratableRoles = exports.canModerateUser = exports.canModerate = exports.softDeleteUser = exports.hashPassword = exports.validatePassword = exports.validateUniqueFields = exports.generateJacketId = exports.getSortOrder = exports.generateEventSearchConditions = exports.generateUserSearchConditions = exports.findSecurityClearanceByRole = exports.getUsersByRole = exports.getUserById = exports.isAccountAccessible = exports.canModifyAccount = exports.hasAllPermissions = exports.hasAnyPermission = exports.hasPermission = exports.hasRole = exports.formatUserListResponse = exports.formatUserProfile = exports.sendErrorResponse = exports.sendSuccessResponse = exports.logEvent = exports.formatTimeRemaining = exports.getTokenTimeRemaining = exports.generateToken = exports.shouldRefreshToken = exports.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = exports.checkSuspensionStatus = exports.checkIsUserBannedOrSuspended = exports.checkBanStatus = exports.hasActiveDependencies = exports.checkAccountDependencies = void 0;
|
|
4
|
-
exports.extractDedicatedUserFromSerial = exports.buildUserSearchConditions = exports.buildSearchConditions = exports.buildEventLogWhereClause = exports.formatEventLogs = exports.formatEventLog = exports.formatDeviceSession = exports.DPP_OperationsUtil = exports.cloudinaryUtil = exports.stockUtil = exports.hierarchicalView = exports.validateHierarchy = exports.isSuperiorOrEqual = exports.isSuperior = exports.isSubordinateOrEqual = exports.isSubordinate = exports.isRankEqual = exports.getUserLevel = void 0;
|
|
4
|
+
exports.logWarning = exports.logSystem = exports.logSecurity = exports.logPayment = exports.logInfo = exports.logError = exports.logDevice = exports.logDebug = exports.logCronjob = exports.logAuth = exports.logApi = exports.extractDedicatedUserFromSerial = exports.buildUserSearchConditions = exports.buildSearchConditions = exports.buildEventLogWhereClause = exports.formatEventLogs = exports.formatEventLog = exports.formatDeviceSession = exports.DPP_OperationsUtil = exports.cloudinaryUtil = exports.stockUtil = exports.hierarchicalView = exports.validateHierarchy = exports.isSuperiorOrEqual = exports.isSuperior = exports.isSubordinateOrEqual = exports.isSubordinate = exports.isRankEqual = exports.getUserLevel = void 0;
|
|
5
5
|
var account_utils_1 = require("./account.utils");
|
|
6
6
|
Object.defineProperty(exports, "checkAccountDependencies", { enumerable: true, get: function () { return account_utils_1.checkAccountDependencies; } });
|
|
7
7
|
Object.defineProperty(exports, "hasActiveDependencies", { enumerable: true, get: function () { return account_utils_1.hasActiveDependencies; } });
|
|
@@ -93,3 +93,15 @@ Object.defineProperty(exports, "buildSearchConditions", { enumerable: true, get:
|
|
|
93
93
|
Object.defineProperty(exports, "buildUserSearchConditions", { enumerable: true, get: function () { return eventlogs_admin_utils_1.buildUserSearchConditions; } });
|
|
94
94
|
var deviceUtils_1 = require("./deviceUtils");
|
|
95
95
|
Object.defineProperty(exports, "extractDedicatedUserFromSerial", { enumerable: true, get: function () { return deviceUtils_1.extractDedicatedUserFromSerial; } });
|
|
96
|
+
var systemLog_utils_1 = require("./systemLog.utils");
|
|
97
|
+
Object.defineProperty(exports, "logApi", { enumerable: true, get: function () { return systemLog_utils_1.logApi; } });
|
|
98
|
+
Object.defineProperty(exports, "logAuth", { enumerable: true, get: function () { return systemLog_utils_1.logAuth; } });
|
|
99
|
+
Object.defineProperty(exports, "logCronjob", { enumerable: true, get: function () { return systemLog_utils_1.logCronjob; } });
|
|
100
|
+
Object.defineProperty(exports, "logDebug", { enumerable: true, get: function () { return systemLog_utils_1.logDebug; } });
|
|
101
|
+
Object.defineProperty(exports, "logDevice", { enumerable: true, get: function () { return systemLog_utils_1.logDevice; } });
|
|
102
|
+
Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return systemLog_utils_1.logError; } });
|
|
103
|
+
Object.defineProperty(exports, "logInfo", { enumerable: true, get: function () { return systemLog_utils_1.logInfo; } });
|
|
104
|
+
Object.defineProperty(exports, "logPayment", { enumerable: true, get: function () { return systemLog_utils_1.logPayment; } });
|
|
105
|
+
Object.defineProperty(exports, "logSecurity", { enumerable: true, get: function () { return systemLog_utils_1.logSecurity; } });
|
|
106
|
+
Object.defineProperty(exports, "logSystem", { enumerable: true, get: function () { return systemLog_utils_1.logSystem; } });
|
|
107
|
+
Object.defineProperty(exports, "logWarning", { enumerable: true, get: function () { return systemLog_utils_1.logWarning; } });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { LogLevel, LogCategory, UserRole } from "vr-models";
|
|
2
|
+
import { Transaction } from "sequelize";
|
|
3
|
+
export interface SystemLogInput {
|
|
4
|
+
level?: LogLevel;
|
|
5
|
+
category?: LogCategory;
|
|
6
|
+
message: string;
|
|
7
|
+
details?: Record<string, any> | null;
|
|
8
|
+
source?: string | null;
|
|
9
|
+
userId?: string | null;
|
|
10
|
+
userRole?: UserRole | null;
|
|
11
|
+
ipAddress?: string | null;
|
|
12
|
+
userAgent?: string | null;
|
|
13
|
+
timestamp?: Date;
|
|
14
|
+
transaction?: Transaction;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a system log entry
|
|
18
|
+
* Uses the static methods from SystemLog model
|
|
19
|
+
*/
|
|
20
|
+
export declare const logSystem: ({ level, category, message, details, source, userId, userRole, ipAddress, userAgent, timestamp, transaction, }: SystemLogInput) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Log an error
|
|
23
|
+
*/
|
|
24
|
+
export declare const logError: (message: string, options?: Omit<SystemLogInput, "level" | "message">) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Log a warning
|
|
27
|
+
*/
|
|
28
|
+
export declare const logWarning: (message: string, options?: Omit<SystemLogInput, "level" | "message">) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Log an info message
|
|
31
|
+
*/
|
|
32
|
+
export declare const logInfo: (message: string, options?: Omit<SystemLogInput, "level" | "message">) => Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Log debug info
|
|
35
|
+
*/
|
|
36
|
+
export declare const logDebug: (message: string, options?: Omit<SystemLogInput, "level" | "message">) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Log a cronjob event
|
|
39
|
+
*/
|
|
40
|
+
export declare const logCronjob: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Log a payment event
|
|
43
|
+
*/
|
|
44
|
+
export declare const logPayment: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Log a device event
|
|
47
|
+
*/
|
|
48
|
+
export declare const logDevice: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Log an auth event
|
|
51
|
+
*/
|
|
52
|
+
export declare const logAuth: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Log a security event
|
|
55
|
+
*/
|
|
56
|
+
export declare const logSecurity: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Log an API request
|
|
59
|
+
*/
|
|
60
|
+
export declare const logApi: (message: string, options?: Omit<SystemLogInput, "level" | "category" | "message">) => Promise<void>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logApi = exports.logSecurity = exports.logAuth = exports.logDevice = exports.logPayment = exports.logCronjob = exports.logDebug = exports.logInfo = exports.logWarning = exports.logError = exports.logSystem = void 0;
|
|
4
|
+
// src/utils/systemLog.utils.ts
|
|
5
|
+
const vr_models_1 = require("vr-models");
|
|
6
|
+
/**
|
|
7
|
+
* Create a system log entry
|
|
8
|
+
* Uses the static methods from SystemLog model
|
|
9
|
+
*/
|
|
10
|
+
const logSystem = async ({ level = "INFO", category = "SYSTEM", message, details = null, source = null, userId = null, userRole = null, ipAddress = null, userAgent = null, timestamp, transaction, }) => {
|
|
11
|
+
try {
|
|
12
|
+
const logData = {
|
|
13
|
+
level,
|
|
14
|
+
category,
|
|
15
|
+
message,
|
|
16
|
+
details,
|
|
17
|
+
source,
|
|
18
|
+
userId,
|
|
19
|
+
userRole,
|
|
20
|
+
ipAddress,
|
|
21
|
+
userAgent,
|
|
22
|
+
timestamp,
|
|
23
|
+
};
|
|
24
|
+
// Create log entry with optional transaction
|
|
25
|
+
await vr_models_1.SystemLog.create(logData, { transaction });
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error("❌ Failed to create system log:", err);
|
|
29
|
+
// Don't throw - system logging should not break the main operation
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.logSystem = logSystem;
|
|
33
|
+
/**
|
|
34
|
+
* Log an error
|
|
35
|
+
*/
|
|
36
|
+
const logError = async (message, options = {}) => {
|
|
37
|
+
await (0, exports.logSystem)({
|
|
38
|
+
level: "ERROR",
|
|
39
|
+
message,
|
|
40
|
+
...options,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.logError = logError;
|
|
44
|
+
/**
|
|
45
|
+
* Log a warning
|
|
46
|
+
*/
|
|
47
|
+
const logWarning = async (message, options = {}) => {
|
|
48
|
+
await (0, exports.logSystem)({
|
|
49
|
+
level: "WARNING",
|
|
50
|
+
message,
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.logWarning = logWarning;
|
|
55
|
+
/**
|
|
56
|
+
* Log an info message
|
|
57
|
+
*/
|
|
58
|
+
const logInfo = async (message, options = {}) => {
|
|
59
|
+
await (0, exports.logSystem)({
|
|
60
|
+
level: "INFO",
|
|
61
|
+
message,
|
|
62
|
+
...options,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
exports.logInfo = logInfo;
|
|
66
|
+
/**
|
|
67
|
+
* Log debug info
|
|
68
|
+
*/
|
|
69
|
+
const logDebug = async (message, options = {}) => {
|
|
70
|
+
await (0, exports.logSystem)({
|
|
71
|
+
level: "DEBUG",
|
|
72
|
+
message,
|
|
73
|
+
...options,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
exports.logDebug = logDebug;
|
|
77
|
+
/**
|
|
78
|
+
* Log a cronjob event
|
|
79
|
+
*/
|
|
80
|
+
const logCronjob = async (message, options = {}) => {
|
|
81
|
+
await (0, exports.logSystem)({
|
|
82
|
+
level: "INFO",
|
|
83
|
+
category: "CRONJOB",
|
|
84
|
+
message,
|
|
85
|
+
...options,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
exports.logCronjob = logCronjob;
|
|
89
|
+
/**
|
|
90
|
+
* Log a payment event
|
|
91
|
+
*/
|
|
92
|
+
const logPayment = async (message, options = {}) => {
|
|
93
|
+
await (0, exports.logSystem)({
|
|
94
|
+
level: "INFO",
|
|
95
|
+
category: "PAYMENT",
|
|
96
|
+
message,
|
|
97
|
+
...options,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
exports.logPayment = logPayment;
|
|
101
|
+
/**
|
|
102
|
+
* Log a device event
|
|
103
|
+
*/
|
|
104
|
+
const logDevice = async (message, options = {}) => {
|
|
105
|
+
await (0, exports.logSystem)({
|
|
106
|
+
level: "INFO",
|
|
107
|
+
category: "DEVICE",
|
|
108
|
+
message,
|
|
109
|
+
...options,
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
exports.logDevice = logDevice;
|
|
113
|
+
/**
|
|
114
|
+
* Log an auth event
|
|
115
|
+
*/
|
|
116
|
+
const logAuth = async (message, options = {}) => {
|
|
117
|
+
await (0, exports.logSystem)({
|
|
118
|
+
level: "INFO",
|
|
119
|
+
category: "AUTH",
|
|
120
|
+
message,
|
|
121
|
+
...options,
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
exports.logAuth = logAuth;
|
|
125
|
+
/**
|
|
126
|
+
* Log a security event
|
|
127
|
+
*/
|
|
128
|
+
const logSecurity = async (message, options = {}) => {
|
|
129
|
+
await (0, exports.logSystem)({
|
|
130
|
+
level: "INFO",
|
|
131
|
+
category: "SECURITY",
|
|
132
|
+
message,
|
|
133
|
+
...options,
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
exports.logSecurity = logSecurity;
|
|
137
|
+
/**
|
|
138
|
+
* Log an API request
|
|
139
|
+
*/
|
|
140
|
+
const logApi = async (message, options = {}) => {
|
|
141
|
+
await (0, exports.logSystem)({
|
|
142
|
+
level: "INFO",
|
|
143
|
+
category: "API",
|
|
144
|
+
message,
|
|
145
|
+
...options,
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
exports.logApi = logApi;
|