vr-models 1.0.41 → 1.0.43
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.
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
2
|
import type { User } from "./user.models";
|
|
3
3
|
import { UserRole } from "./securityClearance.models";
|
|
4
|
-
export interface
|
|
4
|
+
export interface DeviceSessionPayload {
|
|
5
5
|
sessionId: string;
|
|
6
6
|
startedAt: number;
|
|
7
7
|
expiresAt: number;
|
|
8
8
|
userId: string;
|
|
9
9
|
tokenVersion: number;
|
|
10
|
+
deviceSerialNumber: string;
|
|
11
|
+
minutesGranted: number;
|
|
10
12
|
}
|
|
11
|
-
export declare const EVENT_ACTIONS: readonly ["USER_READ", "USER_CREATED", "USER_UPDATED", "USER_DELETED", "USER_SUSPENDED", "USER_BANNED", "USER_VERIFIED", "USERS_LISTED", "ADMIN_FORGOT_PASSWORD", "ADMIN_LOGGED_IN", "ADMIN_LOGGED_OUT", "PASSENGER_ACCOUNT_DEACTIVATED", "PASSENGER_ACCOUNT_DELETED", "AGENT_CREATED_RIDER", "AGENT_UPDATED_RIDER", "ADMIN_CREATED_USER", "ADMIN_UPDATED_USER", "SUPER_ADMIN_PASSWORD_CHANGED", "SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS", "SUPER_ADMIN_UPDATED_USER", "SUPER_ADMIN_CREATED_USER", "PRODUCT_CREATED", "PRODUCT_READ", "PRODUCT_UPDATED", "PRODUCT_DELETED", "PRODUCTS_LISTED", "PRODUCTS_ACTIVATED", "PRODUCTS_DEACTIVATED", "
|
|
13
|
+
export declare const EVENT_ACTIONS: readonly ["USER_READ", "USER_CREATED", "USER_UPDATED", "USER_DELETED", "USER_SUSPENDED", "USER_BANNED", "USER_VERIFIED", "USER_UPGRADED_TO_RIDER", "USERS_LISTED", "ADMIN_FORGOT_PASSWORD", "ADMIN_LOGGED_IN", "ADMIN_LOGGED_OUT", "PASSENGER_ACCOUNT_DEACTIVATED", "PASSENGER_ACCOUNT_DELETED", "AGENT_CREATED_RIDER", "AGENT_UPDATED_RIDER", "ADMIN_CREATED_USER", "ADMIN_UPDATED_USER", "SUPER_ADMIN_PASSWORD_CHANGED", "SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS", "SUPER_ADMIN_UPDATED_USER", "SUPER_ADMIN_CREATED_USER", "PRODUCT_CREATED", "PRODUCT_READ", "PRODUCT_UPDATED", "PRODUCT_DELETED", "PRODUCTS_LISTED", "PRODUCTS_ACTIVATED", "PRODUCTS_DEACTIVATED", "PRODUCT_STOCK_SET_MANUALLY", "PRODUCT_STOCK_INCREMENTED", "PRODUCT_STOCK_DECREMENTED", "PRICING_CREATED", "PRICING_READ", "PRICING_UPDATED", "PRICING_DELETED", "DEVICE_CREATED", "DEVICES_BULK_CREATED", "DEVICE_ASSIGNED", "DEVICE_READ", "DEVICE_UPDATED", "DEVICES_LISTED", "DEVICE_LOCKED", "DEVICE_UNLOCKED", "DEVICE_DISABLED", "DEVICE_REACTIVATED", "DEVICE_DELETED_PERMANENTLY", "DEVICE_REPOSSESSED", "DEVICE_PAYMENT_PLAN_CREATED", "DEVICE_PAYMENT_PLAN_READ", "DEVICE_PAYMENT_PLAN_UPDATED", "DEVICE_PAYMENT_PLAN_MARKED_DEFAULTED", "DEVICE_PAYMENT_PLAN_SOFT_DELETED", "DEVICE_PAYMENT_PLAN_DELETED_PERMANENTLY", "PAYMENT_RECORDED", "PAYMENT_READ", "PAYMENTS_LISTED", "TRANSACTION_READ", "TRANSACTIONS_LISTED", "EVENT_LOG_READ", "EVENT_LOGS_LISTED", "SECURITY_CLEARANCE_MANAGED", "DEVICE_LOCK_OVERRIDDEN", "SESSION_EXTENDED"];
|
|
12
14
|
export type EventAction = (typeof EVENT_ACTIONS)[number];
|
|
13
15
|
export interface EventLogAttributes {
|
|
14
16
|
id: string;
|
|
@@ -20,14 +22,17 @@ export interface EventLogAttributes {
|
|
|
20
22
|
metadata: Record<string, any>;
|
|
21
23
|
ipAddress: string | null;
|
|
22
24
|
userAgent: string | null;
|
|
23
|
-
|
|
25
|
+
deviceSession?: DeviceSessionPayload | null;
|
|
26
|
+
authTokenVersion?: number;
|
|
24
27
|
createdAt: Date;
|
|
25
28
|
actor?: User;
|
|
26
29
|
}
|
|
27
|
-
export interface EventLogCreationAttributes extends Omit<EventLogAttributes, "id" | "createdAt" | "metadata" | "actorType"> {
|
|
30
|
+
export interface EventLogCreationAttributes extends Omit<EventLogAttributes, "id" | "createdAt" | "metadata" | "actorType" | "deviceSession"> {
|
|
28
31
|
id?: string;
|
|
29
32
|
metadata?: Record<string, any>;
|
|
30
33
|
actorType: UserRole;
|
|
34
|
+
deviceSession?: DeviceSessionPayload | null;
|
|
35
|
+
authTokenVersion?: number;
|
|
31
36
|
}
|
|
32
37
|
export declare class EventLog extends Model<InferAttributes<EventLog>, InferCreationAttributes<EventLog>> implements EventLogAttributes {
|
|
33
38
|
id: CreationOptional<string>;
|
|
@@ -39,7 +44,8 @@ export declare class EventLog extends Model<InferAttributes<EventLog>, InferCrea
|
|
|
39
44
|
metadata: CreationOptional<Record<string, any>>;
|
|
40
45
|
ipAddress: CreationOptional<string | null>;
|
|
41
46
|
userAgent: CreationOptional<string | null>;
|
|
42
|
-
|
|
47
|
+
deviceSession: CreationOptional<DeviceSessionPayload | null>;
|
|
48
|
+
authTokenVersion: CreationOptional<number>;
|
|
43
49
|
readonly createdAt: CreationOptional<Date>;
|
|
44
50
|
actor?: NonAttribute<User>;
|
|
45
51
|
static initialize(sequelize: any): void;
|
|
@@ -11,6 +11,7 @@ exports.EVENT_ACTIONS = [
|
|
|
11
11
|
"USER_SUSPENDED",
|
|
12
12
|
"USER_BANNED",
|
|
13
13
|
"USER_VERIFIED",
|
|
14
|
+
"USER_UPGRADED_TO_RIDER", // New action for rider upgrades
|
|
14
15
|
"USERS_LISTED",
|
|
15
16
|
"ADMIN_FORGOT_PASSWORD",
|
|
16
17
|
"ADMIN_LOGGED_IN",
|
|
@@ -32,7 +33,6 @@ exports.EVENT_ACTIONS = [
|
|
|
32
33
|
"PRODUCTS_LISTED",
|
|
33
34
|
"PRODUCTS_ACTIVATED",
|
|
34
35
|
"PRODUCTS_DEACTIVATED",
|
|
35
|
-
"PRODUCTS_LISTED",
|
|
36
36
|
"PRODUCT_STOCK_SET_MANUALLY",
|
|
37
37
|
"PRODUCT_STOCK_INCREMENTED",
|
|
38
38
|
"PRODUCT_STOCK_DECREMENTED",
|
|
@@ -47,7 +47,7 @@ exports.EVENT_ACTIONS = [
|
|
|
47
47
|
"DEVICE_UPDATED",
|
|
48
48
|
"DEVICES_LISTED",
|
|
49
49
|
"DEVICE_LOCKED",
|
|
50
|
-
"DEVICE_UNLOCKED",
|
|
50
|
+
"DEVICE_UNLOCKED", // Device unlocked via BLE
|
|
51
51
|
"DEVICE_DISABLED",
|
|
52
52
|
"DEVICE_REACTIVATED",
|
|
53
53
|
"DEVICE_DELETED_PERMANENTLY",
|
|
@@ -67,7 +67,7 @@ exports.EVENT_ACTIONS = [
|
|
|
67
67
|
"EVENT_LOGS_LISTED",
|
|
68
68
|
"SECURITY_CLEARANCE_MANAGED",
|
|
69
69
|
"DEVICE_LOCK_OVERRIDDEN",
|
|
70
|
-
"SESSION_EXTENDED",
|
|
70
|
+
"SESSION_EXTENDED", // Device session extended
|
|
71
71
|
];
|
|
72
72
|
class EventLog extends vr_migrations_1.Model {
|
|
73
73
|
// Static initialization method
|
|
@@ -81,7 +81,7 @@ class EventLog extends vr_migrations_1.Model {
|
|
|
81
81
|
actorType: {
|
|
82
82
|
type: vr_migrations_1.DataTypes.ENUM("RIDER", "PASSENGER", "AGENT", "ADMIN", "SUPER_ADMIN"),
|
|
83
83
|
allowNull: false,
|
|
84
|
-
defaultValue: "
|
|
84
|
+
defaultValue: "PASSENGER",
|
|
85
85
|
},
|
|
86
86
|
actorId: {
|
|
87
87
|
type: vr_migrations_1.DataTypes.UUID,
|
|
@@ -112,26 +112,65 @@ class EventLog extends vr_migrations_1.Model {
|
|
|
112
112
|
type: vr_migrations_1.DataTypes.TEXT,
|
|
113
113
|
allowNull: true,
|
|
114
114
|
},
|
|
115
|
-
|
|
115
|
+
// In EventLog.initialize()
|
|
116
|
+
deviceSession: {
|
|
116
117
|
type: vr_migrations_1.DataTypes.JSONB,
|
|
117
118
|
allowNull: true,
|
|
119
|
+
field: "session",
|
|
118
120
|
validate: {
|
|
119
|
-
|
|
121
|
+
isValidDeviceSessionObject(value) {
|
|
120
122
|
if (value === null || value === undefined)
|
|
121
123
|
return;
|
|
122
124
|
if (typeof value !== "object" || Array.isArray(value)) {
|
|
123
|
-
throw new Error("
|
|
125
|
+
throw new Error("Device session must be a session object");
|
|
126
|
+
}
|
|
127
|
+
// Required fields for device sessions
|
|
128
|
+
const required = [
|
|
129
|
+
"sessionId",
|
|
130
|
+
"startedAt",
|
|
131
|
+
"expiresAt",
|
|
132
|
+
"userId",
|
|
133
|
+
"tokenVersion",
|
|
134
|
+
"deviceSerialNumber",
|
|
135
|
+
"minutesGranted",
|
|
136
|
+
"isExtension",
|
|
137
|
+
"paymentPlanId",
|
|
138
|
+
];
|
|
139
|
+
for (const field of required) {
|
|
140
|
+
if (!(field in value)) {
|
|
141
|
+
throw new Error(`Device session missing required field: ${field}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Type validation
|
|
145
|
+
if (typeof value.sessionId !== "string") {
|
|
146
|
+
throw new Error("sessionId must be a string");
|
|
147
|
+
}
|
|
148
|
+
if (typeof value.startedAt !== "number") {
|
|
149
|
+
throw new Error("startedAt must be a number");
|
|
150
|
+
}
|
|
151
|
+
if (typeof value.expiresAt !== "number") {
|
|
152
|
+
throw new Error("expiresAt must be a number");
|
|
124
153
|
}
|
|
125
|
-
if (typeof value.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
154
|
+
if (typeof value.userId !== "string") {
|
|
155
|
+
throw new Error("userId must be a string");
|
|
156
|
+
}
|
|
157
|
+
if (typeof value.tokenVersion !== "number") {
|
|
158
|
+
throw new Error("tokenVersion must be a number");
|
|
159
|
+
}
|
|
160
|
+
if (typeof value.deviceSerialNumber !== "string") {
|
|
161
|
+
throw new Error("deviceSerialNumber must be a string");
|
|
162
|
+
}
|
|
163
|
+
if (typeof value.minutesGranted !== "number") {
|
|
164
|
+
throw new Error("minutesGranted must be a number");
|
|
131
165
|
}
|
|
132
166
|
},
|
|
133
167
|
},
|
|
134
168
|
},
|
|
169
|
+
authTokenVersion: {
|
|
170
|
+
type: vr_migrations_1.DataTypes.INTEGER,
|
|
171
|
+
allowNull: true,
|
|
172
|
+
field: "auth_token_version",
|
|
173
|
+
},
|
|
135
174
|
createdAt: {
|
|
136
175
|
type: vr_migrations_1.DataTypes.DATE,
|
|
137
176
|
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
@@ -173,7 +212,7 @@ class EventLog extends vr_migrations_1.Model {
|
|
|
173
212
|
});
|
|
174
213
|
}
|
|
175
214
|
getSummary() {
|
|
176
|
-
return `${this.actorType}:${this.actorId} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}`;
|
|
215
|
+
return `${this.actorType}:${this.actorId} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}${this.deviceSession ? ` (session: ${this.deviceSession.sessionId})` : ""}`;
|
|
177
216
|
}
|
|
178
217
|
}
|
|
179
218
|
exports.EventLog = EventLog;
|