vr-models 1.0.40 → 1.0.42

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 SessionPayload {
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", "PRODUCTS_LISTED", "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"];
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
- session: SessionPayload;
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
- session: SessionPayload;
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,6 +67,7 @@ exports.EVENT_ACTIONS = [
67
67
  "EVENT_LOGS_LISTED",
68
68
  "SECURITY_CLEARANCE_MANAGED",
69
69
  "DEVICE_LOCK_OVERRIDDEN",
70
+ "SESSION_EXTENDED", // Device session extended
70
71
  ];
71
72
  class EventLog extends vr_migrations_1.Model {
72
73
  // Static initialization method
@@ -80,7 +81,7 @@ class EventLog extends vr_migrations_1.Model {
80
81
  actorType: {
81
82
  type: vr_migrations_1.DataTypes.ENUM("RIDER", "PASSENGER", "AGENT", "ADMIN", "SUPER_ADMIN"),
82
83
  allowNull: false,
83
- defaultValue: "ADMIN",
84
+ defaultValue: "PASSENGER",
84
85
  },
85
86
  actorId: {
86
87
  type: vr_migrations_1.DataTypes.UUID,
@@ -111,26 +112,32 @@ class EventLog extends vr_migrations_1.Model {
111
112
  type: vr_migrations_1.DataTypes.TEXT,
112
113
  allowNull: true,
113
114
  },
114
- session: {
115
+ deviceSession: {
115
116
  type: vr_migrations_1.DataTypes.JSONB,
116
117
  allowNull: true,
118
+ field: "session", // Keep column name as 'session' for backward compatibility
117
119
  validate: {
118
- isValidSessionObject(value) {
120
+ isValidDeviceSessionObject(value) {
119
121
  if (value === null || value === undefined)
120
122
  return;
121
123
  if (typeof value !== "object" || Array.isArray(value)) {
122
- throw new Error("Sessions must be a session object");
124
+ throw new Error("Device session must be a session object");
123
125
  }
124
126
  if (typeof value.sessionId !== "string" ||
125
127
  typeof value.startedAt !== "number" ||
126
128
  typeof value.expiresAt !== "number" ||
127
129
  typeof value.userId !== "string" ||
128
130
  typeof value.tokenVersion !== "number") {
129
- throw new Error("Invalid session object: must have a string sessionId and userId plus numeric startetAt ,expiresAt and tokenVersion");
131
+ throw new Error("Invalid device session object: must have sessionId, startedAt, expiresAt, userId, and tokenVersion");
130
132
  }
131
133
  },
132
134
  },
133
135
  },
136
+ authTokenVersion: {
137
+ type: vr_migrations_1.DataTypes.INTEGER,
138
+ allowNull: true,
139
+ field: "auth_token_version",
140
+ },
134
141
  createdAt: {
135
142
  type: vr_migrations_1.DataTypes.DATE,
136
143
  defaultValue: vr_migrations_1.DataTypes.NOW,
@@ -172,7 +179,7 @@ class EventLog extends vr_migrations_1.Model {
172
179
  });
173
180
  }
174
181
  getSummary() {
175
- return `${this.actorType}:${this.actorId} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}`;
182
+ return `${this.actorType}:${this.actorId} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}${this.deviceSession ? ` (session: ${this.deviceSession.sessionId})` : ""}`;
176
183
  }
177
184
  }
178
185
  exports.EventLog = EventLog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-models",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Shared database models package for VR applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",