namirasoft-node 1.4.97 → 1.4.99
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/OTPOperation.d.ts +3 -3
- package/dist/OTPOperation.js +4 -0
- package/dist/OTPOperation.js.map +1 -1
- package/package.json +8 -8
- package/src/OTPOperation.ts +13 -3
package/dist/OTPOperation.d.ts
CHANGED
|
@@ -6,13 +6,13 @@ export declare class OTPOperation {
|
|
|
6
6
|
static OTP_VER_MAX_TRY_COUNT: number;
|
|
7
7
|
static generate(length?: number, digit?: number): string;
|
|
8
8
|
static getWaitTime(x_otp_req_tried_count: number): number;
|
|
9
|
-
static onSafeRequest<T>(x_otp: string | null, x_otp_time: Date | null, x_otp_req_tried_count: number, handler: (row: {
|
|
9
|
+
static onSafeRequest<T>(x_otp: string | null, x_otp_time: Date | string | null, x_otp_req_tried_count: number, handler: (row: {
|
|
10
10
|
x_otp: string;
|
|
11
|
-
x_otp_time: Date;
|
|
11
|
+
x_otp_time: Date | string;
|
|
12
12
|
x_otp_req_tried_count: number;
|
|
13
13
|
x_otp_ver_tried_count: number;
|
|
14
14
|
}) => Promise<T>): Promise<T>;
|
|
15
|
-
static onSafeVerify<T>(x_otp: string | null, x_otp_time: Date | null, x_otp_ver_tried_count: number, code: string, handler: (row: {
|
|
15
|
+
static onSafeVerify<T>(x_otp: string | null, x_otp_time: Date | string | null, x_otp_ver_tried_count: number, code: string, handler: (row: {
|
|
16
16
|
x_otp: string | null;
|
|
17
17
|
x_otp_time: Date | null;
|
|
18
18
|
x_verified: boolean;
|
package/dist/OTPOperation.js
CHANGED
|
@@ -36,6 +36,8 @@ class OTPOperation {
|
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
let wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
38
38
|
let wait_date = namirasoft_core_1.TimeOperation.secondsAgo(wait_time, new Date());
|
|
39
|
+
if (x_otp_time != null)
|
|
40
|
+
x_otp_time = new Date(x_otp_time);
|
|
39
41
|
let next_time = namirasoft_core_1.TimeOperation.diffInSecond(x_otp_time !== null && x_otp_time !== void 0 ? x_otp_time : new Date("0001-01-01"), wait_date, false);
|
|
40
42
|
if (next_time > 0) {
|
|
41
43
|
let mins = Math.max(1, Math.round(next_time / 60));
|
|
@@ -54,6 +56,8 @@ class OTPOperation {
|
|
|
54
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
57
|
if (!x_otp || !x_otp_time)
|
|
56
58
|
throw namirasoft_core_1.ErrorOperation.getHTTP(403, "The OTP not generated yet. Please request first.");
|
|
59
|
+
if (x_otp_time != null)
|
|
60
|
+
x_otp_time = new Date(x_otp_time);
|
|
57
61
|
if (x_otp_time < namirasoft_core_1.TimeOperation.minutesAgo(OTPOperation.OTP_EXPIRE_TIME, new Date()))
|
|
58
62
|
namirasoft_core_1.ErrorOperation.throwHTTP(403, "The OTP code expired. Please request again.");
|
|
59
63
|
if (x_otp_ver_tried_count > OTPOperation.OTP_VER_MAX_TRY_COUNT)
|
package/dist/OTPOperation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OTPOperation.js","sourceRoot":"","sources":["../src/OTPOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAgE;AAEhE,MAAa,YAAY;IASrB,MAAM,CAAC,QAAQ,CAAC,SAAiB,CAAC,EAAE,QAAgB,CAAC;QAEjD,IAAI,CAAC,MAAM;YACP,MAAM,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,KAAK;YACN,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;YAC1B,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CA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AG,YAAY,CAAC,qBAAqB;gBAC1D,gCAAc,CAAC,SAAS,CAAC,GAAG,EAAE,uDAAuD,CAAC,CAAC;YAE3F,IAAI,KAAK,KAAK,IAAI,EAClB,CAAC;gBACG,MAAM,YAAY,EAAE,CAAC;gBACrB,gCAAc,CAAC,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;YACjD,CAAC;YAED,OAAO,MAAM,OAAO,CAAC;gBACjB,KAAK,EAAE,IAAI;gBACX,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;KAAA;;AAtFL,oCAuFC;AArFiB,8BAAiB,GAAW,IAAI,CAAC;AACjC,4BAAe,GAAW,CAAC,CAAC;AAC5B,gCAAmB,GAAW,CAAC,CAAC;AAEhC,kCAAqB,GAAW,CAAC,CAAC;AAClC,kCAAqB,GAAW,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"framework": "npm",
|
|
9
9
|
"application": "package",
|
|
10
10
|
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
11
|
+
"version": "1.4.99",
|
|
12
12
|
"author": "Amir Abolhasani",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"main": "./dist/index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@supercharge/request-ip": "^1.2.0",
|
|
21
|
-
"@types/cors": "^2.8.
|
|
22
|
-
"@types/express": "^5.0.
|
|
23
|
-
"@types/node": "^22.15.
|
|
21
|
+
"@types/cors": "^2.8.18",
|
|
22
|
+
"@types/express": "^5.0.2",
|
|
23
|
+
"@types/node": "^22.15.21",
|
|
24
24
|
"@types/node-cron": "^3.0.11",
|
|
25
25
|
"@types/nodemailer": "^6.4.17",
|
|
26
26
|
"@types/nodemailer-smtp-transport": "^2.7.8",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"cors": "^2.8.5",
|
|
31
31
|
"express": "^5.1.0",
|
|
32
32
|
"joi": "^17.13.3",
|
|
33
|
-
"namirasoft-core": "^1.4.
|
|
34
|
-
"namirasoft-log": "^1.4.
|
|
33
|
+
"namirasoft-core": "^1.4.74",
|
|
34
|
+
"namirasoft-log": "^1.4.30",
|
|
35
35
|
"namirasoft-schema": "^1.4.25",
|
|
36
|
-
"node-cron": "^
|
|
37
|
-
"nodemailer": "^
|
|
36
|
+
"node-cron": "^4.0.6",
|
|
37
|
+
"nodemailer": "^7.0.3",
|
|
38
38
|
"nodemailer-smtp-transport": "^2.7.4",
|
|
39
39
|
"request-ip": "^3.3.0",
|
|
40
40
|
"serve-index": "^1.9.1",
|
package/src/OTPOperation.ts
CHANGED
|
@@ -31,12 +31,19 @@ export class OTPOperation
|
|
|
31
31
|
wait_time = Math.min(Math.pow(OTPOperation.INCREASE_POWER_BASE, extra_attempt), OTPOperation.OTP_MAX_WAIT_TIME) * 60;
|
|
32
32
|
return parseInt(wait_time + "");
|
|
33
33
|
}
|
|
34
|
-
static async onSafeRequest<T>(x_otp: string | null, x_otp_time: Date | null, x_otp_req_tried_count: number,
|
|
35
|
-
handler: (row: {
|
|
34
|
+
static async onSafeRequest<T>(x_otp: string | null, x_otp_time: Date | string | null, x_otp_req_tried_count: number,
|
|
35
|
+
handler: (row: {
|
|
36
|
+
x_otp: string,
|
|
37
|
+
x_otp_time: Date,
|
|
38
|
+
x_otp_req_tried_count: number,
|
|
39
|
+
x_otp_ver_tried_count: number
|
|
40
|
+
}) => Promise<T>): Promise<T>
|
|
36
41
|
{
|
|
37
42
|
// check wait time
|
|
38
43
|
let wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
39
44
|
let wait_date = TimeOperation.secondsAgo(wait_time, new Date());
|
|
45
|
+
if (x_otp_time != null)
|
|
46
|
+
x_otp_time = new Date(x_otp_time);
|
|
40
47
|
let next_time = TimeOperation.diffInSecond(x_otp_time ?? new Date("0001-01-01"), wait_date, false);
|
|
41
48
|
if (next_time > 0)
|
|
42
49
|
{
|
|
@@ -53,7 +60,7 @@ export class OTPOperation
|
|
|
53
60
|
|
|
54
61
|
return await handler({ x_otp, x_otp_time, x_otp_req_tried_count, x_otp_ver_tried_count });
|
|
55
62
|
}
|
|
56
|
-
static async onSafeVerify<T>(x_otp: string | null, x_otp_time: Date | null, x_otp_ver_tried_count: number, code: string,
|
|
63
|
+
static async onSafeVerify<T>(x_otp: string | null, x_otp_time: Date | string | null, x_otp_ver_tried_count: number, code: string,
|
|
57
64
|
handler: (row: {
|
|
58
65
|
x_otp: string | null,
|
|
59
66
|
x_otp_time: Date | null,
|
|
@@ -64,6 +71,9 @@ export class OTPOperation
|
|
|
64
71
|
if (!x_otp || !x_otp_time)
|
|
65
72
|
throw ErrorOperation.getHTTP(403, "The OTP not generated yet. Please request first.");
|
|
66
73
|
|
|
74
|
+
if (x_otp_time != null)
|
|
75
|
+
x_otp_time = new Date(x_otp_time);
|
|
76
|
+
|
|
67
77
|
if (x_otp_time < TimeOperation.minutesAgo(OTPOperation.OTP_EXPIRE_TIME, new Date()))
|
|
68
78
|
ErrorOperation.throwHTTP(403, "The OTP code expired. Please request again.");
|
|
69
79
|
|