@hastehaul/common 1.0.20 → 1.0.22
Sign up to get free protection for your applications and to get access to all the features.
package/build/utils/enums.d.ts
CHANGED
@@ -14,8 +14,17 @@ export declare enum Status {
|
|
14
14
|
DELETED = "deleted",
|
15
15
|
EXPIRED = "expired",
|
16
16
|
BLOCKED = "blocked",
|
17
|
-
SUSPENDED = "suspended"
|
18
|
-
|
17
|
+
SUSPENDED = "suspended"
|
18
|
+
}
|
19
|
+
export declare enum SmsStatus {
|
20
|
+
SMS_PENDING = "sms-pending",
|
21
|
+
SMS_FAILED = "sms-failed",
|
22
|
+
SMS_SENT = "sms-sent"
|
23
|
+
}
|
24
|
+
export declare enum OtpStatus {
|
25
|
+
OTP_INCORRECT = "otp-incorrect",
|
26
|
+
OTP_EXPIRED = "otp-expired",
|
27
|
+
OTP_VERIFIED = "otp-verified"
|
19
28
|
}
|
20
29
|
export declare enum StatusCodes {
|
21
30
|
CONTINUE = 100,
|
package/build/utils/enums.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.StatusCodes = exports.Status = exports.Events = void 0;
|
3
|
+
exports.StatusCodes = exports.OtpStatus = exports.SmsStatus = exports.Status = exports.Events = void 0;
|
4
|
+
// Enum that defines various event types
|
4
5
|
var Events;
|
5
6
|
(function (Events) {
|
6
7
|
Events["CHARGE_SUCCESS"] = "charge.success";
|
@@ -8,8 +9,9 @@ var Events;
|
|
8
9
|
Events["TRANSFER_FAILED"] = "transfer.failed";
|
9
10
|
Events["TRANSFER_REVERSED"] = "transfer.reversed";
|
10
11
|
Events["PAYMENT_REQUEST_PENDING"] = "paymentrequest.pending";
|
11
|
-
Events["PAYMENT_REQUEST_SUCCESS"] = "paymentrequest.success";
|
12
|
+
Events["PAYMENT_REQUEST_SUCCESS"] = "paymentrequest.success"; // Payment request was successful
|
12
13
|
})(Events || (exports.Events = Events = {}));
|
14
|
+
// Enum that defines various status values
|
13
15
|
var Status;
|
14
16
|
(function (Status) {
|
15
17
|
Status["NEW"] = "new";
|
@@ -20,8 +22,21 @@ var Status;
|
|
20
22
|
Status["EXPIRED"] = "expired";
|
21
23
|
Status["BLOCKED"] = "blocked";
|
22
24
|
Status["SUSPENDED"] = "suspended";
|
23
|
-
Status["VACATION"] = "vacation";
|
24
25
|
})(Status || (exports.Status = Status = {}));
|
26
|
+
// Enum that defines various SMS status values
|
27
|
+
var SmsStatus;
|
28
|
+
(function (SmsStatus) {
|
29
|
+
SmsStatus["SMS_PENDING"] = "sms-pending";
|
30
|
+
SmsStatus["SMS_FAILED"] = "sms-failed";
|
31
|
+
SmsStatus["SMS_SENT"] = "sms-sent"; // SMS was successfully sent
|
32
|
+
})(SmsStatus || (exports.SmsStatus = SmsStatus = {}));
|
33
|
+
// Enum that defines various OTP (One-Time Password) status values
|
34
|
+
var OtpStatus;
|
35
|
+
(function (OtpStatus) {
|
36
|
+
OtpStatus["OTP_INCORRECT"] = "otp-incorrect";
|
37
|
+
OtpStatus["OTP_EXPIRED"] = "otp-expired";
|
38
|
+
OtpStatus["OTP_VERIFIED"] = "otp-verified"; // OTP was successfully verified
|
39
|
+
})(OtpStatus || (exports.OtpStatus = OtpStatus = {}));
|
25
40
|
var StatusCodes;
|
26
41
|
(function (StatusCodes) {
|
27
42
|
StatusCodes[StatusCodes["CONTINUE"] = 100] = "CONTINUE";
|
@@ -5,8 +5,7 @@
|
|
5
5
|
* @param {number} numberOfCodes - The total number of codes to generate.
|
6
6
|
* @param {number} codeSize - The size of each individual code (number of characters).
|
7
7
|
* @param {boolean} includeHyphens - Whether to include hyphens between codes.
|
8
|
-
* @param {number} chunkSize - The number of codes to generate in each chunk (iteration).
|
9
8
|
*
|
10
9
|
* @returns {Promise<string>} - A Promise that resolves with the generated codes as a string.
|
11
10
|
*/
|
12
|
-
export declare function generateRandomCodesAsync(characters
|
11
|
+
export declare function generateRandomCodesAsync(characters?: string, numberOfCodes?: number, codeSize?: number, includeHyphens?: boolean): Promise<string>;
|
@@ -17,33 +17,35 @@ exports.generateRandomCodesAsync = void 0;
|
|
17
17
|
* @param {number} numberOfCodes - The total number of codes to generate.
|
18
18
|
* @param {number} codeSize - The size of each individual code (number of characters).
|
19
19
|
* @param {boolean} includeHyphens - Whether to include hyphens between codes.
|
20
|
-
* @param {number} chunkSize - The number of codes to generate in each chunk (iteration).
|
21
20
|
*
|
22
21
|
* @returns {Promise<string>} - A Promise that resolves with the generated codes as a string.
|
23
22
|
*/
|
24
|
-
function generateRandomCodesAsync(characters, numberOfCodes, codeSize, includeHyphens
|
23
|
+
function generateRandomCodesAsync(characters, numberOfCodes, codeSize, includeHyphens) {
|
25
24
|
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
const chars = characters || "ABCDEFGHIJKLMNOPQURSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+=-,./';[]?><:\"\"}{|";
|
26
|
+
const numOfCodes = numberOfCodes || 1;
|
27
|
+
const codeLength = codeSize || 6;
|
26
28
|
let codes = "";
|
27
29
|
let hyphen = includeHyphens ? "-" : "";
|
28
30
|
let chunkStart = 0;
|
29
31
|
let generatedCodes = new Set();
|
30
32
|
function generateChunk() {
|
31
33
|
return __awaiter(this, void 0, void 0, function* () {
|
32
|
-
for (let i = chunkStart; i < chunkStart +
|
34
|
+
for (let i = chunkStart; i < chunkStart + codeLength && i < numOfCodes; i++) {
|
33
35
|
let code = "";
|
34
|
-
for (let j = 0; j <
|
35
|
-
code +=
|
36
|
+
for (let j = 0; j < codeLength; j++) {
|
37
|
+
code += chars.charAt(Math.floor(Math.random() * chars.length));
|
36
38
|
}
|
37
39
|
if (!generatedCodes.has(code)) {
|
38
40
|
generatedCodes.add(code);
|
39
|
-
codes += code + (i ===
|
41
|
+
codes += code + (i === numOfCodes - 1 ? "" : hyphen);
|
40
42
|
}
|
41
43
|
else {
|
42
44
|
i--;
|
43
45
|
}
|
44
46
|
}
|
45
|
-
chunkStart +=
|
46
|
-
if (chunkStart <
|
47
|
+
chunkStart += codeLength;
|
48
|
+
if (chunkStart < numOfCodes && generatedCodes.size < numOfCodes) {
|
47
49
|
yield generateChunk();
|
48
50
|
}
|
49
51
|
});
|