vr-models 1.0.45 → 1.0.47
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/models/eventLog.models.d.ts +1 -1
- package/dist/models/eventLog.models.js +3 -0
- package/dist/models/payment.models.d.ts +2 -2
- package/dist/models/payment.models.js +9 -9
- package/dist/models/phoneContact.models.d.ts +0 -5
- package/dist/models/phoneContact.models.js +0 -83
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ export interface DeviceSessionPayload {
|
|
|
10
10
|
deviceSerialNumber: string;
|
|
11
11
|
minutesGranted: number;
|
|
12
12
|
}
|
|
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"];
|
|
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", "ADMIN_CHANGED_PASSWORD", "ADMIN_RESET_USER_PASSWORD", "ADMIN_BULK_PASSWORD_RESET", "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"];
|
|
14
14
|
export type EventAction = (typeof EVENT_ACTIONS)[number];
|
|
15
15
|
export interface EventLogAttributes {
|
|
16
16
|
id: string;
|
|
@@ -22,6 +22,9 @@ exports.EVENT_ACTIONS = [
|
|
|
22
22
|
"AGENT_UPDATED_RIDER",
|
|
23
23
|
"ADMIN_CREATED_USER",
|
|
24
24
|
"ADMIN_UPDATED_USER",
|
|
25
|
+
"ADMIN_CHANGED_PASSWORD",
|
|
26
|
+
"ADMIN_RESET_USER_PASSWORD",
|
|
27
|
+
"ADMIN_BULK_PASSWORD_RESET",
|
|
25
28
|
"SUPER_ADMIN_PASSWORD_CHANGED",
|
|
26
29
|
"SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS",
|
|
27
30
|
"SUPER_ADMIN_UPDATED_USER",
|
|
@@ -4,9 +4,9 @@ import type { DevicePaymentPlan } from "./devicePaymentPlan.models";
|
|
|
4
4
|
import type { Transaction } from "./transaction.models";
|
|
5
5
|
import type { IdempotencyRecord } from "./idempotencyRecord.models";
|
|
6
6
|
export type PaymentProvider = "mtn_momo" | "airtel_money";
|
|
7
|
-
export type PaymentStatus = "
|
|
7
|
+
export type PaymentStatus = "PENDING" | "SUCCESSFUL" | "FAILED";
|
|
8
8
|
export declare const PAYMENT_PROVIDER: readonly ["mtn_momo", "airtel_money"];
|
|
9
|
-
export declare const PAYMENT_STATUS: readonly ["
|
|
9
|
+
export declare const PAYMENT_STATUS: readonly ["PENDING", "SUCCESSFUL", "FAILED"];
|
|
10
10
|
export interface PaymentAttributes {
|
|
11
11
|
id: string;
|
|
12
12
|
userId: string;
|
|
@@ -4,7 +4,7 @@ exports.Payment = exports.PAYMENT_STATUS = exports.PAYMENT_PROVIDER = void 0;
|
|
|
4
4
|
const vr_migrations_1 = require("vr-migrations");
|
|
5
5
|
// TYPES AS CONSTANTS
|
|
6
6
|
exports.PAYMENT_PROVIDER = ["mtn_momo", "airtel_money"];
|
|
7
|
-
exports.PAYMENT_STATUS = ["
|
|
7
|
+
exports.PAYMENT_STATUS = ["PENDING", "SUCCESSFUL", "FAILED"];
|
|
8
8
|
class Payment extends vr_migrations_1.Model {
|
|
9
9
|
// Static initialization method
|
|
10
10
|
static initialize(sequelize) {
|
|
@@ -29,9 +29,9 @@ class Payment extends vr_migrations_1.Model {
|
|
|
29
29
|
},
|
|
30
30
|
providerReference: { type: vr_migrations_1.DataTypes.STRING, allowNull: true },
|
|
31
31
|
status: {
|
|
32
|
-
type: vr_migrations_1.DataTypes.ENUM("
|
|
32
|
+
type: vr_migrations_1.DataTypes.ENUM("PENDING", "SUCCESSFUL", "FAILED"),
|
|
33
33
|
allowNull: false,
|
|
34
|
-
defaultValue: "
|
|
34
|
+
defaultValue: "PENDING",
|
|
35
35
|
},
|
|
36
36
|
metadata: {
|
|
37
37
|
type: vr_migrations_1.DataTypes.JSONB,
|
|
@@ -46,7 +46,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
46
46
|
modelName: "Payment",
|
|
47
47
|
hooks: {
|
|
48
48
|
beforeUpdate: (payment) => {
|
|
49
|
-
if (payment.status === "
|
|
49
|
+
if (payment.status === "SUCCESSFUL" && !payment.providerReference) {
|
|
50
50
|
throw new Error("providerReference is required for successful payments");
|
|
51
51
|
}
|
|
52
52
|
},
|
|
@@ -82,7 +82,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
82
82
|
}
|
|
83
83
|
// Custom instance methods
|
|
84
84
|
async markAsSucceeded(providerReference, metadata) {
|
|
85
|
-
this.status = "
|
|
85
|
+
this.status = "SUCCESSFUL";
|
|
86
86
|
this.providerReference = providerReference;
|
|
87
87
|
if (metadata) {
|
|
88
88
|
this.metadata = { ...this.metadata, ...metadata };
|
|
@@ -90,7 +90,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
90
90
|
await this.save();
|
|
91
91
|
}
|
|
92
92
|
async markAsFailed(reason, metadata) {
|
|
93
|
-
this.status = "
|
|
93
|
+
this.status = "FAILED";
|
|
94
94
|
const failureMetadata = {
|
|
95
95
|
failureReason: reason,
|
|
96
96
|
failedAt: new Date().toISOString(),
|
|
@@ -107,13 +107,13 @@ class Payment extends vr_migrations_1.Model {
|
|
|
107
107
|
await this.save();
|
|
108
108
|
}
|
|
109
109
|
isSuccessful() {
|
|
110
|
-
return this.status === "
|
|
110
|
+
return this.status === "SUCCESSFUL";
|
|
111
111
|
}
|
|
112
112
|
isPending() {
|
|
113
|
-
return this.status === "
|
|
113
|
+
return this.status === "PENDING";
|
|
114
114
|
}
|
|
115
115
|
isFailed() {
|
|
116
|
-
return this.status === "
|
|
116
|
+
return this.status === "FAILED";
|
|
117
117
|
}
|
|
118
118
|
getProviderDisplayName() {
|
|
119
119
|
switch (this.provider) {
|
|
@@ -55,11 +55,6 @@ export declare class PhoneContact extends Model<InferAttributes<PhoneContact>, I
|
|
|
55
55
|
user?: NonAttribute<User>;
|
|
56
56
|
static initialize(sequelize: any): void;
|
|
57
57
|
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
58
|
-
generateOTP(length?: number): Promise<string>;
|
|
59
|
-
verifyOTP(otp: string): Promise<boolean>;
|
|
60
|
-
markAsVerified(): Promise<void>;
|
|
61
|
-
markAsPrimary(): Promise<void>;
|
|
62
|
-
unmarkAsPrimary(): Promise<void>;
|
|
63
58
|
deactivate(reason?: string): Promise<void>;
|
|
64
59
|
reactivate(): Promise<void>;
|
|
65
60
|
isLocked(): boolean;
|
|
@@ -111,89 +111,6 @@ class PhoneContact extends vr_migrations_1.Model {
|
|
|
111
111
|
onUpdate: "CASCADE",
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
// Custom instance methods
|
|
115
|
-
async generateOTP(length = 6) {
|
|
116
|
-
const digits = "0123456789";
|
|
117
|
-
let otp = "";
|
|
118
|
-
for (let i = 0; i < length; i++) {
|
|
119
|
-
otp += digits[Math.floor(Math.random() * 10)];
|
|
120
|
-
}
|
|
121
|
-
const expiryMinutes = parseInt(process.env.OTP_EXPIRY_MINUTES || "15");
|
|
122
|
-
const expiresAt = new Date();
|
|
123
|
-
expiresAt.setMinutes(expiresAt.getMinutes() + expiryMinutes);
|
|
124
|
-
this.otp = otp;
|
|
125
|
-
this.otpExpiresAt = expiresAt;
|
|
126
|
-
// Update metadata
|
|
127
|
-
this.metadata = {
|
|
128
|
-
...this.metadata,
|
|
129
|
-
lastOtpSentAt: new Date(),
|
|
130
|
-
otpAttempts: 0,
|
|
131
|
-
};
|
|
132
|
-
await this.save();
|
|
133
|
-
return otp;
|
|
134
|
-
}
|
|
135
|
-
async verifyOTP(otp) {
|
|
136
|
-
// Check if locked
|
|
137
|
-
if (this.metadata.isLocked && this.metadata.lockedUntil) {
|
|
138
|
-
if (new Date() < new Date(this.metadata.lockedUntil)) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
// Unlock if past lock time
|
|
142
|
-
this.metadata.isLocked = false;
|
|
143
|
-
this.metadata.lockedUntil = undefined;
|
|
144
|
-
}
|
|
145
|
-
// Check OTP
|
|
146
|
-
if (!this.otp || !this.otpExpiresAt || this.otp !== otp) {
|
|
147
|
-
// Increment failed attempts
|
|
148
|
-
const attempts = (this.metadata.otpAttempts || 0) + 1;
|
|
149
|
-
this.metadata = {
|
|
150
|
-
...this.metadata,
|
|
151
|
-
otpAttempts: attempts,
|
|
152
|
-
lastFailedAttemptAt: new Date(),
|
|
153
|
-
};
|
|
154
|
-
// Lock after 5 failed attempts
|
|
155
|
-
if (attempts >= 5) {
|
|
156
|
-
const lockMinutes = parseInt(process.env.OTP_LOCK_MINUTES || "30");
|
|
157
|
-
const lockedUntil = new Date();
|
|
158
|
-
lockedUntil.setMinutes(lockedUntil.getMinutes() + lockMinutes);
|
|
159
|
-
this.metadata.isLocked = true;
|
|
160
|
-
this.metadata.lockedUntil = lockedUntil;
|
|
161
|
-
}
|
|
162
|
-
await this.save();
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
// Check if expired
|
|
166
|
-
if (new Date() > new Date(this.otpExpiresAt)) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
// Clear OTP on success
|
|
170
|
-
this.otp = null;
|
|
171
|
-
this.otpExpiresAt = null;
|
|
172
|
-
this.metadata = {
|
|
173
|
-
...this.metadata,
|
|
174
|
-
otpAttempts: 0,
|
|
175
|
-
lastFailedAttemptAt: undefined,
|
|
176
|
-
};
|
|
177
|
-
await this.save();
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
async markAsVerified() {
|
|
181
|
-
this.isVerified = true;
|
|
182
|
-
this.verifiedAt = new Date();
|
|
183
|
-
await this.save();
|
|
184
|
-
}
|
|
185
|
-
async markAsPrimary() {
|
|
186
|
-
// If this contact is being set as primary, ensure it's verified
|
|
187
|
-
if (!this.isVerified) {
|
|
188
|
-
throw new Error("Cannot set unverified phone as primary");
|
|
189
|
-
}
|
|
190
|
-
this.isPrimary = true;
|
|
191
|
-
await this.save();
|
|
192
|
-
}
|
|
193
|
-
async unmarkAsPrimary() {
|
|
194
|
-
this.isPrimary = false;
|
|
195
|
-
await this.save();
|
|
196
|
-
}
|
|
197
114
|
async deactivate(reason) {
|
|
198
115
|
this.isActive = false;
|
|
199
116
|
this.metadata = {
|