namirasoft-node 1.4.26 → 1.4.28
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
package/dist/OTPOperation.js
CHANGED
|
@@ -26,20 +26,19 @@ class OTPOperation {
|
|
|
26
26
|
return ans;
|
|
27
27
|
}
|
|
28
28
|
static getWaitTime(x_otp_req_tried_count) {
|
|
29
|
-
let wait_time =
|
|
29
|
+
let wait_time = 0;
|
|
30
30
|
let extra_attempt = x_otp_req_tried_count - OTPOperation.OTP_REQ_MAX_TRY_COUNT;
|
|
31
|
-
if (extra_attempt
|
|
32
|
-
wait_time = Math.min(Math.pow(OTPOperation.INCREASE_POWER_BASE, extra_attempt)
|
|
31
|
+
if (extra_attempt > 0)
|
|
32
|
+
wait_time = Math.min(Math.pow(OTPOperation.INCREASE_POWER_BASE, extra_attempt), OTPOperation.OTP_MAX_WAIT_TIME) * 60;
|
|
33
33
|
return parseInt(wait_time + "");
|
|
34
34
|
}
|
|
35
35
|
static onSafeRequest(x_otp, x_otp_time, x_otp_req_tried_count, handler) {
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
let wait_time =
|
|
38
|
-
let wait_date = namirasoft_core_1.TimeOperation.
|
|
37
|
+
let wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
38
|
+
let wait_date = namirasoft_core_1.TimeOperation.secondsAgo(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
|
-
console.log({ x_otp, x_otp_time, x_otp_req_tried_count, wait_time, wait_date, next_time });
|
|
41
40
|
if (next_time > 0) {
|
|
42
|
-
let mins = Math.
|
|
41
|
+
let mins = Math.max(1, Math.round(next_time / 60));
|
|
43
42
|
namirasoft_core_1.ErrorOperation.throwHTTP(429, 'You have sent too many request, please try again in ' + mins + ' minute' + (mins > 1 ? "s" : "") + '.');
|
|
44
43
|
}
|
|
45
44
|
let x_otp_ver_tried_count = 0;
|
|
@@ -49,7 +48,7 @@ class OTPOperation {
|
|
|
49
48
|
x_otp_time = new Date();
|
|
50
49
|
x_otp_req_tried_count += 1;
|
|
51
50
|
yield handler({ x_otp, x_otp_time, x_otp_req_tried_count, x_otp_ver_tried_count });
|
|
52
|
-
wait_time =
|
|
51
|
+
wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
53
52
|
next_time = wait_time * 60;
|
|
54
53
|
return { next_time };
|
|
55
54
|
});
|
|
@@ -75,7 +74,6 @@ class OTPOperation {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
exports.OTPOperation = OTPOperation;
|
|
78
|
-
OTPOperation.OTP_MIN_WAIT_TIME = 1;
|
|
79
77
|
OTPOperation.OTP_MAX_WAIT_TIME = 1440;
|
|
80
78
|
OTPOperation.OTP_EXPIRE_TIME = 5;
|
|
81
79
|
OTPOperation.INCREASE_POWER_BASE = 2;
|
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;
|
|
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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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;;AApFL,oCAqFC;AAnFiB,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
|
@@ -2,7 +2,6 @@ import { ErrorOperation, TimeOperation } from "namirasoft-core";
|
|
|
2
2
|
|
|
3
3
|
export class OTPOperation
|
|
4
4
|
{
|
|
5
|
-
public static OTP_MIN_WAIT_TIME: number = 1; // minutes
|
|
6
5
|
public static OTP_MAX_WAIT_TIME: number = 1440; // minutes
|
|
7
6
|
public static OTP_EXPIRE_TIME: number = 5; // minutes
|
|
8
7
|
public static INCREASE_POWER_BASE: number = 2;
|
|
@@ -26,23 +25,22 @@ export class OTPOperation
|
|
|
26
25
|
}
|
|
27
26
|
static getWaitTime(x_otp_req_tried_count: number): number
|
|
28
27
|
{
|
|
29
|
-
let wait_time =
|
|
28
|
+
let wait_time = 0;
|
|
30
29
|
let extra_attempt = x_otp_req_tried_count - OTPOperation.OTP_REQ_MAX_TRY_COUNT;
|
|
31
|
-
if (extra_attempt
|
|
32
|
-
wait_time = Math.min(Math.pow(OTPOperation.INCREASE_POWER_BASE, extra_attempt)
|
|
30
|
+
if (extra_attempt > 0)
|
|
31
|
+
wait_time = Math.min(Math.pow(OTPOperation.INCREASE_POWER_BASE, extra_attempt), OTPOperation.OTP_MAX_WAIT_TIME) * 60;
|
|
33
32
|
return parseInt(wait_time + "");
|
|
34
33
|
}
|
|
35
34
|
static async onSafeRequest(x_otp: string | null, x_otp_time: Date | null, x_otp_req_tried_count: number,
|
|
36
35
|
handler: (row: { x_otp: string, x_otp_time: Date, x_otp_req_tried_count: number, x_otp_ver_tried_count: number }) => Promise<void>)
|
|
37
36
|
{
|
|
38
37
|
// check wait time
|
|
39
|
-
let wait_time =
|
|
40
|
-
let wait_date = TimeOperation.
|
|
38
|
+
let wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
39
|
+
let wait_date = TimeOperation.secondsAgo(wait_time, new Date());
|
|
41
40
|
let next_time = TimeOperation.diffInSecond(x_otp_time ?? new Date("0001-01-01"), wait_date, false);
|
|
42
|
-
console.log({ x_otp, x_otp_time, x_otp_req_tried_count, wait_time, wait_date, next_time })
|
|
43
41
|
if (next_time > 0)
|
|
44
42
|
{
|
|
45
|
-
let mins = Math.
|
|
43
|
+
let mins = Math.max(1, Math.round(next_time / 60));
|
|
46
44
|
ErrorOperation.throwHTTP(429, 'You have sent too many request, please try again in ' + mins + ' minute' + (mins > 1 ? "s" : "") + '.')
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -55,7 +53,7 @@ export class OTPOperation
|
|
|
55
53
|
|
|
56
54
|
await handler({ x_otp, x_otp_time, x_otp_req_tried_count, x_otp_ver_tried_count });
|
|
57
55
|
|
|
58
|
-
wait_time =
|
|
56
|
+
wait_time = OTPOperation.getWaitTime(x_otp_req_tried_count);
|
|
59
57
|
next_time = wait_time * 60;
|
|
60
58
|
return { next_time };
|
|
61
59
|
}
|