namirasoft-node 1.4.22 → 1.4.24
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
CHANGED
|
@@ -13,15 +13,11 @@ export declare class OTPOperation {
|
|
|
13
13
|
x_otp_req_tried_count: number;
|
|
14
14
|
x_otp_ver_tried_count: number;
|
|
15
15
|
}) => Promise<void>): Promise<{
|
|
16
|
-
error: string;
|
|
17
16
|
next_time: number;
|
|
18
|
-
} | {
|
|
19
|
-
next_time: number;
|
|
20
|
-
error?: undefined;
|
|
21
17
|
}>;
|
|
22
18
|
static onSafeVerify(x_otp: string | null, x_otp_time: Date | null, x_otp_ver_tried_count: number, code: string, handler: (row: {
|
|
23
19
|
x_otp: string | null;
|
|
24
20
|
x_otp_time: Date | null;
|
|
25
|
-
|
|
21
|
+
x_verified: boolean;
|
|
26
22
|
}) => Promise<void>, errorHandler: () => Promise<void>): Promise<void>;
|
|
27
23
|
}
|
package/dist/OTPOperation.js
CHANGED
|
@@ -38,10 +38,8 @@ class OTPOperation {
|
|
|
38
38
|
let wait_date = namirasoft_core_1.TimeOperation.minutesAgo(wait_time, new Date());
|
|
39
39
|
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
40
|
if (next_time > 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
next_time
|
|
44
|
-
};
|
|
41
|
+
let mins = Math.min(1, Math.round(next_time / 60));
|
|
42
|
+
namirasoft_core_1.ErrorOperation.throwHTTP(429, 'You have sent too many request, please try again in ' + mins + ' minute' + (mins > 1 ? "s" : "") + '.');
|
|
45
43
|
}
|
|
46
44
|
let x_otp_ver_tried_count = 0;
|
|
47
45
|
if (!x_otp)
|
|
@@ -70,7 +68,7 @@ class OTPOperation {
|
|
|
70
68
|
yield handler({
|
|
71
69
|
x_otp: null,
|
|
72
70
|
x_otp_time: null,
|
|
73
|
-
|
|
71
|
+
x_verified: true,
|
|
74
72
|
});
|
|
75
73
|
});
|
|
76
74
|
}
|
|
@@ -80,6 +78,6 @@ OTPOperation.OTP_MIN_WAIT_TIME = 1;
|
|
|
80
78
|
OTPOperation.OTP_MAX_WAIT_TIME = 1440;
|
|
81
79
|
OTPOperation.OTP_EXPIRE_TIME = 5;
|
|
82
80
|
OTPOperation.INCREASE_POWER_BASE = 2;
|
|
83
|
-
OTPOperation.OTP_REQ_MAX_TRY_COUNT =
|
|
81
|
+
OTPOperation.OTP_REQ_MAX_TRY_COUNT = 5;
|
|
84
82
|
OTPOperation.OTP_VER_MAX_TRY_COUNT = 3;
|
|
85
83
|
//# sourceMappingURL=OTPOperation.js.map
|
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;IAUrB,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,CAAC,CAAC;QACpD,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE;YAC3B,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ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AkD,CAAC,CAAC;YAE1F,IAAI,UAAU,GAAG,+BAAa,CAAC,UAAU,CAAC,YAAY,CAAC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC;gBAC/E,gCAAc,CAAC,SAAS,CAAC,GAAG,EAAE,6CAA6C,CAAC,CAAC;YAEjF,IAAI,qBAAqB,GAAG,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;YACD,MAAM,OAAO,CAAC;gBACV,KAAK,EAAE,IAAI;gBACX,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;KAAA;;AArFL,oCAsFC;AApFiB,8BAAiB,GAAW,CAAC,CAAC;AAC9B,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
package/src/OTPOperation.ts
CHANGED
|
@@ -7,7 +7,7 @@ export class OTPOperation
|
|
|
7
7
|
public static OTP_EXPIRE_TIME: number = 5; // minutes
|
|
8
8
|
public static INCREASE_POWER_BASE: number = 2;
|
|
9
9
|
|
|
10
|
-
public static OTP_REQ_MAX_TRY_COUNT: number =
|
|
10
|
+
public static OTP_REQ_MAX_TRY_COUNT: number = 5;
|
|
11
11
|
public static OTP_VER_MAX_TRY_COUNT: number = 3;
|
|
12
12
|
|
|
13
13
|
static generate(length: number = 6, digit: number = 3)
|
|
@@ -41,10 +41,8 @@ export class OTPOperation
|
|
|
41
41
|
let next_time = TimeOperation.diffInSecond(x_otp_time ?? new Date("0001-01-01"), wait_date, false);
|
|
42
42
|
if (next_time > 0)
|
|
43
43
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
next_time
|
|
47
|
-
};
|
|
44
|
+
let mins = Math.min(1, Math.round(next_time / 60));
|
|
45
|
+
ErrorOperation.throwHTTP(429, 'You have sent too many request, please try again in ' + mins + ' minute' + (mins > 1 ? "s" : "") + '.')
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
let x_otp_ver_tried_count = 0;
|
|
@@ -64,7 +62,7 @@ export class OTPOperation
|
|
|
64
62
|
handler: (row: {
|
|
65
63
|
x_otp: string | null,
|
|
66
64
|
x_otp_time: Date | null,
|
|
67
|
-
|
|
65
|
+
x_verified: boolean,
|
|
68
66
|
}) => Promise<void>,
|
|
69
67
|
errorHandler: () => Promise<void>)
|
|
70
68
|
{
|
|
@@ -85,7 +83,7 @@ export class OTPOperation
|
|
|
85
83
|
await handler({
|
|
86
84
|
x_otp: null,
|
|
87
85
|
x_otp_time: null,
|
|
88
|
-
|
|
86
|
+
x_verified: true,
|
|
89
87
|
});
|
|
90
88
|
}
|
|
91
89
|
}
|