@misterhomer1992/miit-bot-payment 1.0.9 → 1.1.0
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/package.json +2 -2
- package/dist/formatters.d.ts +0 -31
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js +0 -64
- package/dist/formatters.js.map +0 -1
- package/dist/modules/app/types.d.ts +0 -2
- package/dist/modules/app/types.d.ts.map +0 -1
- package/dist/modules/app/types.js +0 -3
- package/dist/modules/app/types.js.map +0 -1
- package/dist/modules/user/userModel.d.ts +0 -78
- package/dist/modules/user/userModel.d.ts.map +0 -1
- package/dist/modules/user/userModel.js +0 -3
- package/dist/modules/user/userModel.js.map +0 -1
- package/dist/types.d.ts +0 -36
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -15
- package/dist/types.js.map +0 -1
- package/dist/validators.d.ts +0 -23
- package/dist/validators.d.ts.map +0 -1
- package/dist/validators.js +0 -148
- package/dist/validators.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterhomer1992/miit-bot-payment",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A TypeScript utility library for payment validation and formatting",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"moment": "2.30.1",
|
|
29
29
|
"dotenv": "17.2.2",
|
|
30
30
|
"axios": "1.12.2",
|
|
31
|
-
"firebase-admin": "
|
|
31
|
+
"firebase-admin": "11.6.0",
|
|
32
32
|
"@misterhomer1992/wayforpay-api": "3.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
package/dist/formatters.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { CurrencyFormatOptions } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Formats a credit card number for display (e.g., "1234 5678 9012 3456")
|
|
4
|
-
* @param cardNumber - The card number to format
|
|
5
|
-
* @param maskDigits - Whether to mask all but the last 4 digits
|
|
6
|
-
* @returns Formatted card number
|
|
7
|
-
*/
|
|
8
|
-
export declare function formatCardNumber(cardNumber: string, maskDigits?: boolean): string;
|
|
9
|
-
/**
|
|
10
|
-
* Formats an amount as currency
|
|
11
|
-
* @param amount - The amount to format
|
|
12
|
-
* @param options - Formatting options
|
|
13
|
-
* @returns Formatted currency string
|
|
14
|
-
*/
|
|
15
|
-
export declare function formatCurrency(amount: number, options?: CurrencyFormatOptions): string;
|
|
16
|
-
/**
|
|
17
|
-
* Masks a card number showing only the last N digits
|
|
18
|
-
* @param cardNumber - The card number to mask
|
|
19
|
-
* @param visibleDigits - Number of digits to show (default: 4)
|
|
20
|
-
* @param maskChar - Character to use for masking (default: '*')
|
|
21
|
-
* @returns Masked card number
|
|
22
|
-
*/
|
|
23
|
-
export declare function maskCardNumber(cardNumber: string, visibleDigits?: number, maskChar?: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* Formats an expiry date to MM/YY format
|
|
26
|
-
* @param month - Month (1-12)
|
|
27
|
-
* @param year - Year (full year or last 2 digits)
|
|
28
|
-
* @returns Formatted expiry date
|
|
29
|
-
*/
|
|
30
|
-
export declare function formatExpiryDate(month: number, year: number): string;
|
|
31
|
-
//# sourceMappingURL=formatters.d.ts.map
|
package/dist/formatters.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,GAAE,OAAe,GAAG,MAAM,CAUxF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAc1F;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,aAAa,GAAE,MAAU,EACzB,QAAQ,GAAE,MAAY,GACrB,MAAM,CAWR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMpE"}
|
package/dist/formatters.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatCardNumber = formatCardNumber;
|
|
4
|
-
exports.formatCurrency = formatCurrency;
|
|
5
|
-
exports.maskCardNumber = maskCardNumber;
|
|
6
|
-
exports.formatExpiryDate = formatExpiryDate;
|
|
7
|
-
/**
|
|
8
|
-
* Formats a credit card number for display (e.g., "1234 5678 9012 3456")
|
|
9
|
-
* @param cardNumber - The card number to format
|
|
10
|
-
* @param maskDigits - Whether to mask all but the last 4 digits
|
|
11
|
-
* @returns Formatted card number
|
|
12
|
-
*/
|
|
13
|
-
function formatCardNumber(cardNumber, maskDigits = false) {
|
|
14
|
-
const cleanedNumber = cardNumber.replace(/[\s-]/g, '');
|
|
15
|
-
if (maskDigits && cleanedNumber.length > 4) {
|
|
16
|
-
const lastFour = cleanedNumber.slice(-4);
|
|
17
|
-
const masked = '*'.repeat(cleanedNumber.length - 4);
|
|
18
|
-
return (masked + lastFour).replace(/(.{4})/g, '$1 ').trim();
|
|
19
|
-
}
|
|
20
|
-
return cleanedNumber.replace(/(.{4})/g, '$1 ').trim();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Formats an amount as currency
|
|
24
|
-
* @param amount - The amount to format
|
|
25
|
-
* @param options - Formatting options
|
|
26
|
-
* @returns Formatted currency string
|
|
27
|
-
*/
|
|
28
|
-
function formatCurrency(amount, options = {}) {
|
|
29
|
-
const { locale = 'en-US', currency = 'USD', minimumFractionDigits = 2, maximumFractionDigits = 2, } = options;
|
|
30
|
-
return new Intl.NumberFormat(locale, {
|
|
31
|
-
style: 'currency',
|
|
32
|
-
currency,
|
|
33
|
-
minimumFractionDigits,
|
|
34
|
-
maximumFractionDigits,
|
|
35
|
-
}).format(amount);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Masks a card number showing only the last N digits
|
|
39
|
-
* @param cardNumber - The card number to mask
|
|
40
|
-
* @param visibleDigits - Number of digits to show (default: 4)
|
|
41
|
-
* @param maskChar - Character to use for masking (default: '*')
|
|
42
|
-
* @returns Masked card number
|
|
43
|
-
*/
|
|
44
|
-
function maskCardNumber(cardNumber, visibleDigits = 4, maskChar = '*') {
|
|
45
|
-
const cleanedNumber = cardNumber.replace(/[\s-]/g, '');
|
|
46
|
-
if (cleanedNumber.length <= visibleDigits) {
|
|
47
|
-
return cleanedNumber;
|
|
48
|
-
}
|
|
49
|
-
const visiblePart = cleanedNumber.slice(-visibleDigits);
|
|
50
|
-
const maskedPart = maskChar.repeat(cleanedNumber.length - visibleDigits);
|
|
51
|
-
return maskedPart + visiblePart;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Formats an expiry date to MM/YY format
|
|
55
|
-
* @param month - Month (1-12)
|
|
56
|
-
* @param year - Year (full year or last 2 digits)
|
|
57
|
-
* @returns Formatted expiry date
|
|
58
|
-
*/
|
|
59
|
-
function formatExpiryDate(month, year) {
|
|
60
|
-
const monthStr = month.toString().padStart(2, '0');
|
|
61
|
-
const yearStr = year >= 2000 ? (year % 100).toString().padStart(2, '0') : year.toString().padStart(2, '0');
|
|
62
|
-
return `${monthStr}/${yearStr}`;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=formatters.js.map
|
package/dist/formatters.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":";;AAQA,4CAUC;AAQD,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EAAE,CAAC;QAC1C,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;IAEzE,OAAO,UAAU,GAAG,WAAW,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,KAAa,EAAE,IAAY;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACnD,MAAM,OAAO,GACX,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE7F,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/app/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/app/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
-
import { AppNamespace } from '../app/types';
|
|
3
|
-
export interface User {
|
|
4
|
-
user: {
|
|
5
|
-
id: string;
|
|
6
|
-
lastUpdate: null | string;
|
|
7
|
-
name: null | string;
|
|
8
|
-
};
|
|
9
|
-
subscription: {
|
|
10
|
-
isActive: boolean;
|
|
11
|
-
isTrial: boolean;
|
|
12
|
-
payments?: {
|
|
13
|
-
planId: string;
|
|
14
|
-
orderReference: string;
|
|
15
|
-
url: string;
|
|
16
|
-
createdDate: string;
|
|
17
|
-
}[];
|
|
18
|
-
paymentUrlMessageId?: number;
|
|
19
|
-
};
|
|
20
|
-
personality?: string;
|
|
21
|
-
messages: Record<string, Record<string, unknown>>;
|
|
22
|
-
commands?: Record<string, unknown>;
|
|
23
|
-
keyboardContext?: Record<string, unknown>;
|
|
24
|
-
settings: {
|
|
25
|
-
voiceResponse: boolean;
|
|
26
|
-
languageCode: string;
|
|
27
|
-
activeMessageThread: string;
|
|
28
|
-
requestCount: number;
|
|
29
|
-
imageAutoDetection: boolean;
|
|
30
|
-
imageResolution: string;
|
|
31
|
-
activeKeyboardMessageId?: number;
|
|
32
|
-
hasFakeImage?: boolean;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export interface UserAnalytics {
|
|
36
|
-
id: string;
|
|
37
|
-
platform: AppNamespace;
|
|
38
|
-
createdDate: string;
|
|
39
|
-
chatGPT: {
|
|
40
|
-
completions: Partial<Record<number, {
|
|
41
|
-
requestTokensCount: number;
|
|
42
|
-
responseTokensCount: number;
|
|
43
|
-
}>>;
|
|
44
|
-
image: {
|
|
45
|
-
create?: {
|
|
46
|
-
'11': {
|
|
47
|
-
count: number;
|
|
48
|
-
inputImageTokens: number;
|
|
49
|
-
outputImageTokens: number;
|
|
50
|
-
inputTextTokens: number;
|
|
51
|
-
};
|
|
52
|
-
'12': {
|
|
53
|
-
count: number;
|
|
54
|
-
};
|
|
55
|
-
'18': {
|
|
56
|
-
count: number;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
vision: Partial<Record<number, {
|
|
60
|
-
requestTokensCount: number;
|
|
61
|
-
responseTokensCount: number;
|
|
62
|
-
}>>;
|
|
63
|
-
};
|
|
64
|
-
speechToText: {
|
|
65
|
-
'whisper-1': {
|
|
66
|
-
seconds: number;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
textToSpeech: {
|
|
70
|
-
'tts-1': {
|
|
71
|
-
charsCount: number;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
export type UserFieldPath = NestedPathsAccess<User>;
|
|
77
|
-
export type UserFieldAnalyticsPath = NestedPathsAccess<UserAnalytics>;
|
|
78
|
-
//# sourceMappingURL=userModel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"userModel.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE;QACF,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE;QACV,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE;YACP,MAAM,EAAE,MAAM,CAAC;YACf,cAAc,EAAE,MAAM,CAAC;YACvB,GAAG,EAAE,MAAM,CAAC;YACZ,WAAW,EAAE,MAAM,CAAC;SACvB,EAAE,CAAC;QACJ,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC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L,CAAC;CACL;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"userModel.js","sourceRoot":"","sources":["../../../src/modules/user/userModel.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supported credit card types
|
|
3
|
-
*/
|
|
4
|
-
export declare enum CardType {
|
|
5
|
-
VISA = "VISA",
|
|
6
|
-
MASTERCARD = "MASTERCARD",
|
|
7
|
-
AMEX = "AMEX",
|
|
8
|
-
DISCOVER = "DISCOVER",
|
|
9
|
-
UNKNOWN = "UNKNOWN"
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Credit card validation result
|
|
13
|
-
*/
|
|
14
|
-
export interface CardValidationResult {
|
|
15
|
-
isValid: boolean;
|
|
16
|
-
cardType: CardType;
|
|
17
|
-
message?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Currency formatting options
|
|
21
|
-
*/
|
|
22
|
-
export interface CurrencyFormatOptions {
|
|
23
|
-
locale?: string;
|
|
24
|
-
currency?: string;
|
|
25
|
-
minimumFractionDigits?: number;
|
|
26
|
-
maximumFractionDigits?: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Payment amount validation result
|
|
30
|
-
*/
|
|
31
|
-
export interface AmountValidationResult {
|
|
32
|
-
isValid: boolean;
|
|
33
|
-
amount?: number;
|
|
34
|
-
message?: string;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CardType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Supported credit card types
|
|
6
|
-
*/
|
|
7
|
-
var CardType;
|
|
8
|
-
(function (CardType) {
|
|
9
|
-
CardType["VISA"] = "VISA";
|
|
10
|
-
CardType["MASTERCARD"] = "MASTERCARD";
|
|
11
|
-
CardType["AMEX"] = "AMEX";
|
|
12
|
-
CardType["DISCOVER"] = "DISCOVER";
|
|
13
|
-
CardType["UNKNOWN"] = "UNKNOWN";
|
|
14
|
-
})(CardType || (exports.CardType = CardType = {}));
|
|
15
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,qCAAyB,CAAA;IACzB,yBAAa,CAAA;IACb,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;AACrB,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB"}
|
package/dist/validators.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CardType, CardValidationResult, AmountValidationResult } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Validates a credit card number using the Luhn algorithm
|
|
4
|
-
* @param cardNumber - The credit card number to validate
|
|
5
|
-
* @returns Validation result with card type
|
|
6
|
-
*/
|
|
7
|
-
export declare function validateCardNumber(cardNumber: string): CardValidationResult;
|
|
8
|
-
/**
|
|
9
|
-
* Validates a payment amount
|
|
10
|
-
* @param amount - The amount to validate (string or number)
|
|
11
|
-
* @param minAmount - Minimum allowed amount (default: 0.01)
|
|
12
|
-
* @param maxAmount - Maximum allowed amount (default: 999999.99)
|
|
13
|
-
* @returns Validation result
|
|
14
|
-
*/
|
|
15
|
-
export declare function validateAmount(amount: string | number, minAmount?: number, maxAmount?: number): AmountValidationResult;
|
|
16
|
-
/**
|
|
17
|
-
* Validates a CVV/CVC code
|
|
18
|
-
* @param cvv - The CVV code to validate
|
|
19
|
-
* @param cardType - The card type (AMEX uses 4 digits, others use 3)
|
|
20
|
-
* @returns Whether the CVV is valid
|
|
21
|
-
*/
|
|
22
|
-
export declare function validateCVV(cvv: string, cardType?: CardType): boolean;
|
|
23
|
-
//# sourceMappingURL=validators.d.ts.map
|
package/dist/validators.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,oBAAoB,CAiC3E;AA6DD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,GAAE,MAAa,EACxB,SAAS,GAAE,MAAkB,GAC5B,sBAAsB,CAyCxB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA2B,GAAG,OAAO,CAYvF"}
|
package/dist/validators.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateCardNumber = validateCardNumber;
|
|
4
|
-
exports.validateAmount = validateAmount;
|
|
5
|
-
exports.validateCVV = validateCVV;
|
|
6
|
-
const types_1 = require("./types");
|
|
7
|
-
/**
|
|
8
|
-
* Validates a credit card number using the Luhn algorithm
|
|
9
|
-
* @param cardNumber - The credit card number to validate
|
|
10
|
-
* @returns Validation result with card type
|
|
11
|
-
*/
|
|
12
|
-
function validateCardNumber(cardNumber) {
|
|
13
|
-
// Remove spaces and dashes
|
|
14
|
-
const cleanedNumber = cardNumber.replace(/[\s-]/g, '');
|
|
15
|
-
// Check if it contains only digits
|
|
16
|
-
if (!/^\d+$/.test(cleanedNumber)) {
|
|
17
|
-
return {
|
|
18
|
-
isValid: false,
|
|
19
|
-
cardType: types_1.CardType.UNKNOWN,
|
|
20
|
-
message: 'Card number must contain only digits',
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
// Check length (most cards are 13-19 digits)
|
|
24
|
-
if (cleanedNumber.length < 13 || cleanedNumber.length > 19) {
|
|
25
|
-
return {
|
|
26
|
-
isValid: false,
|
|
27
|
-
cardType: types_1.CardType.UNKNOWN,
|
|
28
|
-
message: 'Invalid card number length',
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// Determine card type
|
|
32
|
-
const cardType = detectCardType(cleanedNumber);
|
|
33
|
-
// Luhn algorithm validation
|
|
34
|
-
const isValidLuhn = luhnCheck(cleanedNumber);
|
|
35
|
-
return {
|
|
36
|
-
isValid: isValidLuhn,
|
|
37
|
-
cardType,
|
|
38
|
-
message: isValidLuhn ? 'Valid card number' : 'Invalid card number (failed Luhn check)',
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Performs Luhn algorithm check
|
|
43
|
-
* @param cardNumber - The card number to check
|
|
44
|
-
* @returns Whether the card passes the Luhn check
|
|
45
|
-
*/
|
|
46
|
-
function luhnCheck(cardNumber) {
|
|
47
|
-
let sum = 0;
|
|
48
|
-
let isEven = false;
|
|
49
|
-
// Loop through values starting from the rightmost digit
|
|
50
|
-
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
51
|
-
let digit = parseInt(cardNumber[i], 10);
|
|
52
|
-
if (isEven) {
|
|
53
|
-
digit *= 2;
|
|
54
|
-
if (digit > 9) {
|
|
55
|
-
digit -= 9;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
sum += digit;
|
|
59
|
-
isEven = !isEven;
|
|
60
|
-
}
|
|
61
|
-
return sum % 10 === 0;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Detects the card type based on the card number
|
|
65
|
-
* @param cardNumber - The card number
|
|
66
|
-
* @returns The detected card type
|
|
67
|
-
*/
|
|
68
|
-
function detectCardType(cardNumber) {
|
|
69
|
-
// Visa: starts with 4
|
|
70
|
-
if (/^4/.test(cardNumber)) {
|
|
71
|
-
return types_1.CardType.VISA;
|
|
72
|
-
}
|
|
73
|
-
// Mastercard: starts with 51-55 or 2221-2720
|
|
74
|
-
if (/^5[1-5]/.test(cardNumber) ||
|
|
75
|
-
/^2(22[1-9]|2[3-9]\d|[3-6]\d{2}|7[01]\d|720)/.test(cardNumber)) {
|
|
76
|
-
return types_1.CardType.MASTERCARD;
|
|
77
|
-
}
|
|
78
|
-
// American Express: starts with 34 or 37
|
|
79
|
-
if (/^3[47]/.test(cardNumber)) {
|
|
80
|
-
return types_1.CardType.AMEX;
|
|
81
|
-
}
|
|
82
|
-
// Discover: starts with 6011, 622126-622925, 644-649, or 65
|
|
83
|
-
if (/^(6011|65|64[4-9]|622)/.test(cardNumber)) {
|
|
84
|
-
return types_1.CardType.DISCOVER;
|
|
85
|
-
}
|
|
86
|
-
return types_1.CardType.UNKNOWN;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Validates a payment amount
|
|
90
|
-
* @param amount - The amount to validate (string or number)
|
|
91
|
-
* @param minAmount - Minimum allowed amount (default: 0.01)
|
|
92
|
-
* @param maxAmount - Maximum allowed amount (default: 999999.99)
|
|
93
|
-
* @returns Validation result
|
|
94
|
-
*/
|
|
95
|
-
function validateAmount(amount, minAmount = 0.01, maxAmount = 999999.99) {
|
|
96
|
-
const parsedAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
97
|
-
if (isNaN(parsedAmount)) {
|
|
98
|
-
return {
|
|
99
|
-
isValid: false,
|
|
100
|
-
message: 'Invalid amount: not a number',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (parsedAmount < minAmount) {
|
|
104
|
-
return {
|
|
105
|
-
isValid: false,
|
|
106
|
-
amount: parsedAmount,
|
|
107
|
-
message: `Amount must be at least ${minAmount}`,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (parsedAmount > maxAmount) {
|
|
111
|
-
return {
|
|
112
|
-
isValid: false,
|
|
113
|
-
amount: parsedAmount,
|
|
114
|
-
message: `Amount must not exceed ${maxAmount}`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
// Check for valid decimal places (max 2)
|
|
118
|
-
const decimalPlaces = (parsedAmount.toString().split('.')[1] || '').length;
|
|
119
|
-
if (decimalPlaces > 2) {
|
|
120
|
-
return {
|
|
121
|
-
isValid: false,
|
|
122
|
-
amount: parsedAmount,
|
|
123
|
-
message: 'Amount must have at most 2 decimal places',
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
isValid: true,
|
|
128
|
-
amount: parsedAmount,
|
|
129
|
-
message: 'Valid amount',
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Validates a CVV/CVC code
|
|
134
|
-
* @param cvv - The CVV code to validate
|
|
135
|
-
* @param cardType - The card type (AMEX uses 4 digits, others use 3)
|
|
136
|
-
* @returns Whether the CVV is valid
|
|
137
|
-
*/
|
|
138
|
-
function validateCVV(cvv, cardType = types_1.CardType.UNKNOWN) {
|
|
139
|
-
const cleanedCVV = cvv.trim();
|
|
140
|
-
if (!/^\d+$/.test(cleanedCVV)) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
if (cardType === types_1.CardType.AMEX) {
|
|
144
|
-
return cleanedCVV.length === 4;
|
|
145
|
-
}
|
|
146
|
-
return cleanedCVV.length === 3;
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=validators.js.map
|
package/dist/validators.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;AAOA,gDAiCC;AAoED,wCA6CC;AAQD,kCAYC;AA7KD,mCAAiF;AAEjF;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,UAAkB;IACnD,2BAA2B;IAC3B,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEvD,mCAAmC;IACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACjC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,gBAAQ,CAAC,OAAO;YAC1B,OAAO,EAAE,sCAAsC;SAChD,CAAC;IACJ,CAAC;IAED,6CAA6C;IAC7C,IAAI,aAAa,CAAC,MAAM,GAAG,EAAE,IAAI,aAAa,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QAC3D,OAAO;YACL,OA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