@konplit-services/common 1.0.283 → 1.0.284
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.
|
@@ -8,3 +8,7 @@ export declare enum CARD_TYPES {
|
|
|
8
8
|
jcb = "JCB",
|
|
9
9
|
china_union_pay = "CHINA_UNION_PAY"
|
|
10
10
|
}
|
|
11
|
+
type CardType = "VISA" | "VERVE" | "AMEX" | "MASTERCARD" | "DISCOVER" | "DINERS" | "JCB" | "CHINA_UNION_PAY" | undefined;
|
|
12
|
+
declare const creditCardType: (cc: string) => CardType;
|
|
13
|
+
declare const getCardType: (cardNumber: string) => CardType;
|
|
14
|
+
export { creditCardType, getCardType, CardType };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CARD_TYPES = void 0;
|
|
3
|
+
exports.getCardType = exports.creditCardType = exports.CARD_TYPES = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const card_validate_1 = require("./card-validate");
|
|
6
|
+
const error_codes_1 = require("./errorCodes/error-codes");
|
|
4
7
|
var CARD_TYPES;
|
|
5
8
|
(function (CARD_TYPES) {
|
|
6
9
|
CARD_TYPES["visa"] = "VISA";
|
|
@@ -12,3 +15,39 @@ var CARD_TYPES;
|
|
|
12
15
|
CARD_TYPES["jcb"] = "JCB";
|
|
13
16
|
CARD_TYPES["china_union_pay"] = "CHINA_UNION_PAY";
|
|
14
17
|
})(CARD_TYPES = exports.CARD_TYPES || (exports.CARD_TYPES = {}));
|
|
18
|
+
const creditCardType = (cc) => {
|
|
19
|
+
// Input validation
|
|
20
|
+
if (typeof cc !== "string" || !/^\d+$/.test(cc)) {
|
|
21
|
+
throw new errors_1.BadRequestError("Invalid card number. Input must be a string of digits.", error_codes_1.error_codes.INVALID_INPUT);
|
|
22
|
+
}
|
|
23
|
+
// Card type patterns
|
|
24
|
+
const cardTypes = [
|
|
25
|
+
{ type: "VISA", pattern: /^4[0-9]{12}(?:[0-9]{3})?$/ },
|
|
26
|
+
{ type: "VERVE", pattern: /^((506(0|1))|(507(8|9))|(6500))[0-9]{12,15}$/ },
|
|
27
|
+
{ type: "AMEX", pattern: /^3[47][0-9]{13}$/ },
|
|
28
|
+
{ type: "MASTERCARD", pattern: /^(5[1-5][0-9]{14}|2[2-7][0-9]{14})$/ },
|
|
29
|
+
{
|
|
30
|
+
type: "DISCOVER",
|
|
31
|
+
pattern: /^(6011[0-9]{12}|62[24568][0-9]{13}|6[45][0-9]{14})$/,
|
|
32
|
+
},
|
|
33
|
+
{ type: "DINERS", pattern: /^3[0689][0-9]{12}$/ },
|
|
34
|
+
{ type: "JCB", pattern: /^35[0-9]{14}$/ },
|
|
35
|
+
{ type: "CHINA_UNION_PAY", pattern: /^(62[0-9]{14}|81[0-9]{14})$/ },
|
|
36
|
+
];
|
|
37
|
+
// Check card number against patterns
|
|
38
|
+
for (const { type, pattern } of cardTypes) {
|
|
39
|
+
if (pattern.test(cc)) {
|
|
40
|
+
return type;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Return undefined if no match is found
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
exports.creditCardType = creditCardType;
|
|
47
|
+
const getCardType = (cardNumber) => {
|
|
48
|
+
if (!(0, card_validate_1.cardValidate)(cardNumber)) {
|
|
49
|
+
throw new errors_1.BadRequestError("Invalid card number.", error_codes_1.error_codes.INVALID_INPUT);
|
|
50
|
+
}
|
|
51
|
+
return creditCardType(cardNumber);
|
|
52
|
+
};
|
|
53
|
+
exports.getCardType = getCardType;
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.cardValidate = void 0;
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const error_codes_1 = require("./errorCodes/error-codes");
|
|
9
11
|
const cardValidate = (cardNumber) => {
|
|
10
12
|
let sum = 0;
|
|
11
13
|
let shouldDouble = false;
|
|
12
14
|
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
13
15
|
let digit = parseInt(cardNumber[i], 10);
|
|
14
16
|
if (isNaN(digit)) {
|
|
15
|
-
throw new
|
|
17
|
+
throw new errors_1.BadRequestError(`Invalid character '${cardNumber[i]}' in card number.`, error_codes_1.error_codes.INVALID_INPUT);
|
|
16
18
|
}
|
|
17
19
|
if (shouldDouble) {
|
|
18
20
|
digit *= 2;
|
|
@@ -20,7 +20,7 @@ const generateCronExpression = (interval) => {
|
|
|
20
20
|
switch (interval) {
|
|
21
21
|
case plan_types_1.PLAN_INTERVAL.HOURLY: {
|
|
22
22
|
// Run every hour at the same minute and second
|
|
23
|
-
cronExpression = `0 ${currentDate.minute()}
|
|
23
|
+
cronExpression = `0 ${currentDate.minute()} * * * *`;
|
|
24
24
|
break;
|
|
25
25
|
}
|
|
26
26
|
case plan_types_1.PLAN_INTERVAL.DAILY: {
|