@temboplus/frontend-core 0.2.1 → 0.2.3
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/README.md +126 -25
- package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/src/config/config_service.d.ts +11 -0
- package/esm/src/config/config_service.d.ts.map +1 -0
- package/esm/src/config/config_service.js +19 -0
- package/esm/src/config/index.d.ts +2 -0
- package/esm/src/config/index.d.ts.map +1 -0
- package/esm/src/config/index.js +1 -0
- package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
- package/esm/src/data/banks_tz.d.ts.map +1 -0
- package/esm/src/data/countries.d.ts +6 -0
- package/esm/src/data/countries.d.ts.map +1 -0
- package/esm/src/data/countries.js +974 -0
- package/esm/src/data/currencies.d.ts +1901 -0
- package/esm/src/data/currencies.d.ts.map +1 -0
- package/esm/src/data/currencies.js +1073 -0
- package/esm/src/data/phone_patterns.d.ts +3809 -0
- package/esm/src/data/phone_patterns.d.ts.map +1 -0
- package/esm/src/data/phone_patterns.js +2325 -0
- package/esm/src/models/amount/amount.d.ts +10 -12
- package/esm/src/models/amount/amount.d.ts.map +1 -1
- package/esm/src/models/amount/amount.js +58 -96
- package/esm/src/models/bank/bank.d.ts +58 -53
- package/esm/src/models/bank/bank.d.ts.map +1 -1
- package/esm/src/models/bank/bank.js +49 -84
- package/esm/src/models/bank/index.d.ts +1 -1
- package/esm/src/models/bank/index.d.ts.map +1 -1
- package/esm/src/models/bank/index.js +1 -1
- package/esm/src/models/bank/service.d.ts +106 -0
- package/esm/src/models/bank/service.d.ts.map +1 -0
- package/esm/src/models/bank/service.js +240 -0
- package/esm/src/models/country/country.d.ts +568 -0
- package/esm/src/models/country/country.d.ts.map +1 -0
- package/esm/src/models/country/country.js +165 -0
- package/esm/src/models/country/country.test.d.ts.map +1 -0
- package/esm/src/models/country/index.d.ts +3 -0
- package/esm/src/models/country/index.d.ts.map +1 -0
- package/esm/src/models/country/index.js +2 -0
- package/esm/src/models/country/service.d.ts +75 -0
- package/esm/src/models/country/service.d.ts.map +1 -0
- package/esm/src/models/country/service.js +267 -0
- package/esm/src/models/currency/currency.d.ts +341 -0
- package/esm/src/models/currency/currency.d.ts.map +1 -0
- package/esm/src/models/currency/currency.js +225 -0
- package/esm/src/models/currency/currency.test.d.ts.map +1 -0
- package/esm/src/models/currency/index.d.ts +3 -0
- package/esm/src/models/currency/index.d.ts.map +1 -0
- package/esm/src/models/currency/index.js +2 -0
- package/esm/src/models/currency/service.d.ts +96 -0
- package/esm/src/models/currency/service.d.ts.map +1 -0
- package/esm/src/models/currency/service.js +194 -0
- package/esm/src/models/index.d.ts +2 -0
- package/esm/src/models/index.d.ts.map +1 -1
- package/esm/src/models/index.js +2 -0
- package/esm/src/models/phone_number/format.d.ts +14 -0
- package/esm/src/models/phone_number/format.d.ts.map +1 -0
- package/esm/src/models/phone_number/format.js +14 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/phone_number.js +453 -0
- package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/service.d.ts +260 -0
- package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/service.js +477 -0
- package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/index.d.ts +5 -3
- package/esm/src/models/phone_number/index.d.ts.map +1 -1
- package/esm/src/models/phone_number/index.js +5 -3
- package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
- package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
- package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
- package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
- package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
- package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
- package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
- package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
- package/esm/src/reports/index.d.ts +2 -0
- package/esm/src/reports/index.d.ts.map +1 -0
- package/esm/src/reports/index.js +1 -0
- package/esm/src/reports/report_manager.d.ts +144 -0
- package/esm/src/reports/report_manager.d.ts.map +1 -0
- package/esm/src/reports/report_manager.js +315 -0
- package/package.json +4 -3
- package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -0
- package/script/src/config/config_service.d.ts +11 -0
- package/script/src/config/config_service.d.ts.map +1 -0
- package/script/src/config/config_service.js +23 -0
- package/script/src/config/index.d.ts +2 -0
- package/script/src/config/index.d.ts.map +1 -0
- package/script/src/config/index.js +17 -0
- package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
- package/script/src/data/banks_tz.d.ts.map +1 -0
- package/script/src/data/countries.d.ts +6 -0
- package/script/src/data/countries.d.ts.map +1 -0
- package/script/src/data/countries.js +976 -0
- package/script/src/data/currencies.d.ts +1901 -0
- package/script/src/data/currencies.d.ts.map +1 -0
- package/script/src/data/currencies.js +1075 -0
- package/script/src/data/phone_patterns.d.ts +3809 -0
- package/script/src/data/phone_patterns.d.ts.map +1 -0
- package/script/src/data/phone_patterns.js +2327 -0
- package/script/src/models/amount/amount.d.ts +10 -12
- package/script/src/models/amount/amount.d.ts.map +1 -1
- package/script/src/models/amount/amount.js +60 -98
- package/script/src/models/bank/bank.d.ts +58 -53
- package/script/src/models/bank/bank.d.ts.map +1 -1
- package/script/src/models/bank/bank.js +49 -87
- package/script/src/models/bank/index.d.ts +1 -1
- package/script/src/models/bank/index.d.ts.map +1 -1
- package/script/src/models/bank/index.js +1 -1
- package/script/src/models/bank/service.d.ts +106 -0
- package/script/src/models/bank/service.d.ts.map +1 -0
- package/script/src/models/bank/service.js +247 -0
- package/script/src/models/country/country.d.ts +568 -0
- package/script/src/models/country/country.d.ts.map +1 -0
- package/script/src/models/country/country.js +169 -0
- package/script/src/models/country/country.test.d.ts.map +1 -0
- package/script/src/models/country/index.d.ts +3 -0
- package/script/src/models/country/index.d.ts.map +1 -0
- package/script/src/models/country/index.js +18 -0
- package/script/src/models/country/service.d.ts +75 -0
- package/script/src/models/country/service.d.ts.map +1 -0
- package/script/src/models/country/service.js +274 -0
- package/script/src/models/currency/currency.d.ts +341 -0
- package/script/src/models/currency/currency.d.ts.map +1 -0
- package/script/src/models/currency/currency.js +229 -0
- package/script/src/models/currency/currency.test.d.ts.map +1 -0
- package/script/src/models/currency/index.d.ts +3 -0
- package/script/src/models/currency/index.d.ts.map +1 -0
- package/script/src/models/currency/index.js +18 -0
- package/script/src/models/currency/service.d.ts +96 -0
- package/script/src/models/currency/service.d.ts.map +1 -0
- package/script/src/models/currency/service.js +201 -0
- package/script/src/models/index.d.ts +2 -0
- package/script/src/models/index.d.ts.map +1 -1
- package/script/src/models/index.js +2 -0
- package/script/src/models/phone_number/format.d.ts +14 -0
- package/script/src/models/phone_number/format.d.ts.map +1 -0
- package/script/src/models/phone_number/format.js +17 -0
- package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
- package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
- package/script/src/models/phone_number/global/phone_number.js +457 -0
- package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
- package/script/src/models/phone_number/global/service.d.ts +260 -0
- package/script/src/models/phone_number/global/service.d.ts.map +1 -0
- package/script/src/models/phone_number/global/service.js +485 -0
- package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
- package/script/src/models/phone_number/index.d.ts +5 -3
- package/script/src/models/phone_number/index.d.ts.map +1 -1
- package/script/src/models/phone_number/index.js +5 -3
- package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
- package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
- package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
- package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
- package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
- package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
- package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
- package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
- package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
- package/script/src/reports/index.d.ts +2 -0
- package/script/src/reports/index.d.ts.map +1 -0
- package/script/src/reports/index.js +17 -0
- package/script/src/reports/report_manager.d.ts +144 -0
- package/script/src/reports/report_manager.d.ts.map +1 -0
- package/script/src/reports/report_manager.js +325 -0
- package/esm/src/models/bank/banks.d.ts.map +0 -1
- package/esm/src/models/bank/utils.d.ts +0 -25
- package/esm/src/models/bank/utils.d.ts.map +0 -1
- package/esm/src/models/bank/utils.js +0 -35
- package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
- package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
- package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
- package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
- package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
- package/script/src/models/bank/banks.d.ts.map +0 -1
- package/script/src/models/bank/utils.d.ts +0 -25
- package/script/src/models/bank/utils.d.ts.map +0 -1
- package/script/src/models/bank/utils.js +0 -41
- package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
- package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
- package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
- package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
- package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
- /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
- /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
- /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
- /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
- /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
- /package/script/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BankService } from "./service.js";
|
|
2
2
|
/**
|
|
3
3
|
* Represents a bank with essential details.
|
|
4
4
|
* @class Bank
|
|
5
5
|
*/
|
|
6
6
|
export class Bank {
|
|
7
7
|
/**
|
|
8
|
-
* Creates a new Bank instance.
|
|
8
|
+
* Creates a new Bank instance. Private constructor - only BankService can create instances.
|
|
9
|
+
* Clients should use static methods like Bank.from() or Bank.CRDB instead.
|
|
10
|
+
*
|
|
9
11
|
* @param {string} _fullName - The full name of the bank
|
|
10
12
|
* @param {string} _shortName - The short name or abbreviated name of the bank
|
|
11
13
|
* @param {string} _swiftCode - The SWIFT code associated with the bank
|
|
@@ -29,6 +31,11 @@ export class Bank {
|
|
|
29
31
|
writable: true,
|
|
30
32
|
value: _swiftCode
|
|
31
33
|
});
|
|
34
|
+
// Make sure only BankService can create Bank instances
|
|
35
|
+
const callerIsService = new Error().stack?.includes("BankService");
|
|
36
|
+
if (!callerIsService) {
|
|
37
|
+
throw new Error("Bank instances cannot be created directly. Use Bank.from() or access via Bank.CRDB, Bank.NMB, etc.");
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Gets the full name of the bank.
|
|
@@ -64,7 +71,7 @@ export class Bank {
|
|
|
64
71
|
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
65
72
|
*/
|
|
66
73
|
static fromSWIFTCode(swiftCode) {
|
|
67
|
-
return
|
|
74
|
+
return BankService.getInstance().fromSWIFTCode(swiftCode);
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
77
|
* Retrieves a bank by its short or full name.
|
|
@@ -72,19 +79,19 @@ export class Bank {
|
|
|
72
79
|
* @returns {Bank | undefined} The bank corresponding to the full name or `undefined` if not found.
|
|
73
80
|
*/
|
|
74
81
|
static fromBankName(bankName) {
|
|
75
|
-
return
|
|
76
|
-
|
|
82
|
+
return BankService.getInstance().fromBankName(bankName);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns all available banks.
|
|
86
|
+
* @returns {Bank[]} Array of all banks
|
|
87
|
+
*/
|
|
88
|
+
static getAll() {
|
|
89
|
+
return BankService.getInstance().getAll();
|
|
77
90
|
}
|
|
78
91
|
/**
|
|
79
92
|
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
* Should be in the format of 8 or 11 characters (e.g., 'NMIBTZTZ' or 'CRDBTZTZXXX').
|
|
83
|
-
*
|
|
84
|
-
* @returns {boolean} Returns true if:
|
|
85
|
-
* - The SWIFT code is not null/undefined
|
|
86
|
-
* - The SWIFT code successfully creates a valid Bank instance
|
|
87
|
-
* Returns false otherwise.
|
|
93
|
+
* @param swiftCode The SWIFT/BIC code to validate
|
|
94
|
+
* @returns True if the SWIFT code is valid
|
|
88
95
|
*/
|
|
89
96
|
static isValidSwiftCode(swiftCode) {
|
|
90
97
|
if (!swiftCode)
|
|
@@ -94,14 +101,8 @@ export class Bank {
|
|
|
94
101
|
}
|
|
95
102
|
/**
|
|
96
103
|
* Validates if a given bank name is valid
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
99
|
-
* Should be either 'CRDB' or 'NMB'.
|
|
100
|
-
*
|
|
101
|
-
* @returns {boolean} Returns true if:
|
|
102
|
-
* - The bank name is not null/undefined
|
|
103
|
-
* - The bank name successfully creates a valid Bank instance
|
|
104
|
-
* Returns false otherwise.
|
|
104
|
+
* @param bankName The bank name to validate
|
|
105
|
+
* @returns True if the bank name is valid
|
|
105
106
|
*/
|
|
106
107
|
static isValidBankName(bankName) {
|
|
107
108
|
if (!bankName)
|
|
@@ -109,22 +110,14 @@ export class Bank {
|
|
|
109
110
|
const bank = Bank.fromBankName(bankName);
|
|
110
111
|
return !!bank;
|
|
111
112
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Gets all banks from the JSON data.
|
|
114
|
-
* @returns {Bank[]} Array of all banks
|
|
115
|
-
*/
|
|
116
|
-
static getAll() {
|
|
117
|
-
const data = JSON.parse(JSON.stringify(file));
|
|
118
|
-
return data.map((b) => new Bank(b.fullName, b.shortName, b.swiftCode));
|
|
119
|
-
}
|
|
120
113
|
/**
|
|
121
114
|
* Checks the validity of the bank data
|
|
122
115
|
* @returns true if the bank information is available and valid
|
|
123
116
|
*/
|
|
124
117
|
validate() {
|
|
125
118
|
try {
|
|
126
|
-
return (Bank.fromBankName(this._fullName) !== undefined
|
|
127
|
-
Bank.fromBankName(this._shortName) !== undefined
|
|
119
|
+
return (Bank.fromBankName(this._fullName) !== undefined ||
|
|
120
|
+
Bank.fromBankName(this._shortName) !== undefined ||
|
|
128
121
|
Bank.fromSWIFTCode(this._swiftCode) !== undefined);
|
|
129
122
|
}
|
|
130
123
|
catch (_) {
|
|
@@ -133,14 +126,8 @@ export class Bank {
|
|
|
133
126
|
}
|
|
134
127
|
/**
|
|
135
128
|
* Attempts to create a Bank instance from a bank name or SWIFT code
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @param {string} input - The bank name or SWIFT code
|
|
139
|
-
* @returns {Bank | undefined} A Bank instance if valid input, undefined otherwise
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* const bank = Bank.from('CORUTZTZ'); // From SWIFT code
|
|
143
|
-
* const sameBank = Bank.from('CRDB'); // From bank name
|
|
129
|
+
* @param input The bank name or SWIFT code
|
|
130
|
+
* @returns A Bank instance if valid input, undefined otherwise
|
|
144
131
|
*/
|
|
145
132
|
static from(input) {
|
|
146
133
|
if (Bank.canConstruct(input)) {
|
|
@@ -155,15 +142,8 @@ export class Bank {
|
|
|
155
142
|
}
|
|
156
143
|
/**
|
|
157
144
|
* Validates if the input can be used to construct a valid Bank instance
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @param {string | null | undefined} input - The bank name or SWIFT code to validate
|
|
161
|
-
* @returns {boolean} True if input can construct a valid bank, false otherwise
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* Bank.canConstruct('CORUTZTZ'); // true
|
|
165
|
-
* Bank.canConstruct(''); // false
|
|
166
|
-
* Bank.canConstruct(null); // false
|
|
145
|
+
* @param input The bank name or SWIFT code to validate
|
|
146
|
+
* @returns True if input can construct a valid bank, false otherwise
|
|
167
147
|
*/
|
|
168
148
|
static canConstruct(input) {
|
|
169
149
|
if (!input || typeof input !== "string")
|
|
@@ -176,20 +156,9 @@ export class Bank {
|
|
|
176
156
|
return bankFromSwift !== undefined || bankFromName !== undefined;
|
|
177
157
|
}
|
|
178
158
|
/**
|
|
179
|
-
* Checks if an unknown value is a Bank instance
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @param {unknown} obj - The value to validate
|
|
183
|
-
* @returns {obj is Bank} Type predicate indicating if the value is a valid Bank
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* const maybeBank = JSON.parse(someData);
|
|
187
|
-
* if (Bank.is(maybeBank)) {
|
|
188
|
-
* console.log(maybeBank.fullName); // maybeBank is typed as Bank
|
|
189
|
-
* }
|
|
190
|
-
*
|
|
191
|
-
* @see {@link Bank.fromSWIFTCode} for creating instances from SWIFT codes
|
|
192
|
-
* @see {@link Bank.fromBankName} for creating instances from bank names
|
|
159
|
+
* Checks if an unknown value is a Bank instance
|
|
160
|
+
* @param obj The value to validate
|
|
161
|
+
* @returns Type predicate indicating if the value is a valid Bank
|
|
193
162
|
*/
|
|
194
163
|
static is(obj) {
|
|
195
164
|
if (!obj || typeof obj !== "object")
|
|
@@ -203,27 +172,23 @@ export class Bank {
|
|
|
203
172
|
if (typeof maybeBank._swiftCode !== "string")
|
|
204
173
|
return false;
|
|
205
174
|
// Validate against known banks
|
|
206
|
-
const bankFromSwift = Bank.
|
|
207
|
-
|
|
208
|
-
const bankFromName2 = Bank.from(maybeBank._shortName);
|
|
209
|
-
return Boolean(bankFromSwift &&
|
|
210
|
-
bankFromName &&
|
|
211
|
-
bankFromName2 &&
|
|
212
|
-
compare(bankFromName, bankFromName2) &&
|
|
213
|
-
compare(bankFromSwift, bankFromName) &&
|
|
214
|
-
compare(bankFromSwift, bankFromName2));
|
|
175
|
+
const bankFromSwift = Bank.fromSWIFTCode(maybeBank._swiftCode);
|
|
176
|
+
return Boolean(bankFromSwift);
|
|
215
177
|
}
|
|
216
178
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
179
|
+
// Initialize static properties by applying the references from BankService.
|
|
180
|
+
// zero-timeout to defer the initialization until after both modules have been fully loaded.
|
|
181
|
+
// The setTimeout pushes the initialization code to the end of the JavaScript event loop,
|
|
182
|
+
// which happens after all modules are loaded.
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
try {
|
|
185
|
+
const staticRefs = BankService.getInstance().getStaticReferences();
|
|
186
|
+
staticRefs.forEach((bank, key) => {
|
|
187
|
+
// deno-lint-ignore no-explicit-any
|
|
188
|
+
Bank[key] = bank;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error("Failed to initialize Bank static properties:", error);
|
|
193
|
+
}
|
|
194
|
+
}, 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Bank } from "./bank.js";
|
|
2
|
+
/**
|
|
3
|
+
* Regex pattern to validate SWIFT codes.
|
|
4
|
+
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
5
|
+
* @constant {RegExp}
|
|
6
|
+
*/
|
|
7
|
+
export declare const SWIFT_CODE_REGEX: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* Service for managing bank data.
|
|
10
|
+
* @class BankService
|
|
11
|
+
*/
|
|
12
|
+
export declare class BankService {
|
|
13
|
+
private static instance;
|
|
14
|
+
private bankList;
|
|
15
|
+
private bankRecord;
|
|
16
|
+
private banksByName;
|
|
17
|
+
private banksByShortName;
|
|
18
|
+
private staticReferences;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Gets the singleton instance of BankService.
|
|
22
|
+
* Creates the instance if it doesn't exist.
|
|
23
|
+
* @static
|
|
24
|
+
* @returns {BankService} The singleton instance
|
|
25
|
+
*/
|
|
26
|
+
static getInstance(): BankService;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes the service with bank data.
|
|
29
|
+
* Should be called once when your application starts.
|
|
30
|
+
*/
|
|
31
|
+
private initialize;
|
|
32
|
+
/**
|
|
33
|
+
* Gets all banks.
|
|
34
|
+
* @returns {Bank[]} Array of all banks
|
|
35
|
+
*/
|
|
36
|
+
getAll(): Bank[];
|
|
37
|
+
/**
|
|
38
|
+
* Gets all banks as a record.
|
|
39
|
+
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
40
|
+
*/
|
|
41
|
+
getAllAsRecord(): Record<string, Bank>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets static bank references to be used by the Bank class.
|
|
44
|
+
* @returns {Map<string, Bank>} Map of static references
|
|
45
|
+
*/
|
|
46
|
+
getStaticReferences(): Map<string, Bank>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves a bank by its SWIFT code.
|
|
49
|
+
* @param {string} swiftCode The SWIFT code of the bank.
|
|
50
|
+
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
51
|
+
*/
|
|
52
|
+
fromSWIFTCode(swiftCode: string): Bank | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves a bank by its name.
|
|
55
|
+
* @param {string} bankName The name of the bank.
|
|
56
|
+
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
57
|
+
*/
|
|
58
|
+
fromBankName(bankName: string): Bank | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
61
|
+
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
62
|
+
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
isValidSwiftCode(swiftCode?: string | null): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Validates if a given bank name is valid.
|
|
67
|
+
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
68
|
+
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
isValidBankName(bankName?: string | null): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Searches for banks that match the given search term.
|
|
73
|
+
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
74
|
+
* @param {number} [limit=10] - Maximum number of results to return.
|
|
75
|
+
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
76
|
+
*/
|
|
77
|
+
search(searchTerm: string, limit?: number): Bank[];
|
|
78
|
+
/**
|
|
79
|
+
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
80
|
+
*
|
|
81
|
+
* @param {Bank} bank1 - First bank to compare
|
|
82
|
+
* @param {Bank} bank2 - Second bank to compare
|
|
83
|
+
* @returns {boolean} True if banks are equal, false otherwise
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
compare(bank1: Bank, bank2: Bank): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
89
|
+
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
90
|
+
*/
|
|
91
|
+
getAllSwiftCodes(): string[];
|
|
92
|
+
/**
|
|
93
|
+
* Checks whether a given SWIFT code is in the correct format.
|
|
94
|
+
* @param {string} swiftCode The SWIFT code to check.
|
|
95
|
+
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
96
|
+
*/
|
|
97
|
+
isValidSwiftCodeFormat(swiftCode: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Validates whether a given SWIFT code is correct.
|
|
100
|
+
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
101
|
+
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
102
|
+
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
103
|
+
*/
|
|
104
|
+
validateSWIFTCode: (swiftCode?: string) => boolean;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,gBAAgB,CAA4B;IAGpD,OAAO,CAAC,gBAAgB,CAAgC;IAExD,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,WAAW;IAQjC;;;OAGG;IACH,OAAO,CAAC,UAAU;IA0ClB;;;OAGG;IACH,MAAM,IAAI,IAAI,EAAE;IAIhB;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;IAItC;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;IAIxC;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAKlD;;;;OAIG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAqChD;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKpD;;;;OAIG;IACH,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKlD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,IAAI,EAAE;IAetD;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO;IAQ1C;;;OAGG;IACH,gBAAgB,IAAI,MAAM,EAAE;IAI5B;;;;OAIG;IACH,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIlD;;;;;OAKG;IACH,iBAAiB,eAAgB,MAAM,KAAG,OAAO,CAQ/C;CACH"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { Bank } from "./bank.js";
|
|
2
|
+
import file from "../../data/banks_tz.js";
|
|
3
|
+
/**
|
|
4
|
+
* Regex pattern to validate SWIFT codes.
|
|
5
|
+
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
6
|
+
* @constant {RegExp}
|
|
7
|
+
*/
|
|
8
|
+
export const SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
|
|
9
|
+
/**
|
|
10
|
+
* Service for managing bank data.
|
|
11
|
+
* @class BankService
|
|
12
|
+
*/
|
|
13
|
+
export class BankService {
|
|
14
|
+
constructor() {
|
|
15
|
+
Object.defineProperty(this, "bankList", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: []
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "bankRecord", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: {}
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "banksByName", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: {}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "banksByShortName", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: {}
|
|
38
|
+
});
|
|
39
|
+
// Static references for direct access through Bank class
|
|
40
|
+
Object.defineProperty(this, "staticReferences", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: new Map()
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Validates whether a given SWIFT code is correct.
|
|
48
|
+
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
49
|
+
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
50
|
+
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
51
|
+
*/
|
|
52
|
+
Object.defineProperty(this, "validateSWIFTCode", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: (swiftCode) => {
|
|
57
|
+
if (!swiftCode)
|
|
58
|
+
return false;
|
|
59
|
+
const normalizedCode = swiftCode.trim().toUpperCase();
|
|
60
|
+
return (this.isValidSwiftCodeFormat(normalizedCode) &&
|
|
61
|
+
this.getAllSwiftCodes().includes(normalizedCode));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the singleton instance of BankService.
|
|
67
|
+
* Creates the instance if it doesn't exist.
|
|
68
|
+
* @static
|
|
69
|
+
* @returns {BankService} The singleton instance
|
|
70
|
+
*/
|
|
71
|
+
static getInstance() {
|
|
72
|
+
if (!BankService.instance) {
|
|
73
|
+
BankService.instance = new BankService();
|
|
74
|
+
BankService.instance.initialize();
|
|
75
|
+
}
|
|
76
|
+
return BankService.instance;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Initializes the service with bank data.
|
|
80
|
+
* Should be called once when your application starts.
|
|
81
|
+
*/
|
|
82
|
+
initialize() {
|
|
83
|
+
try {
|
|
84
|
+
const data = JSON.parse(JSON.stringify(file));
|
|
85
|
+
const banks = Object.values(data).map((b) => new Bank(b.fullName, b.shortName, b.swiftCode));
|
|
86
|
+
const swiftCodeRecord = {};
|
|
87
|
+
const nameRecord = {};
|
|
88
|
+
const shortNameRecord = {};
|
|
89
|
+
banks.forEach((bank) => {
|
|
90
|
+
// Populate records
|
|
91
|
+
swiftCodeRecord[bank.swiftCode.toUpperCase()] = bank;
|
|
92
|
+
nameRecord[bank.fullName.toUpperCase()] = bank;
|
|
93
|
+
shortNameRecord[bank.shortName.toUpperCase()] = bank;
|
|
94
|
+
// Add to static references with uppercase short name
|
|
95
|
+
const shortName = bank.shortName.toUpperCase();
|
|
96
|
+
this.staticReferences.set(shortName, bank);
|
|
97
|
+
// Handle bank names with spaces (like "GT BANK")
|
|
98
|
+
if (shortName.includes(" ")) {
|
|
99
|
+
const noSpaceName = shortName.replace(/\s+/g, "_");
|
|
100
|
+
this.staticReferences.set(noSpaceName, bank);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
this.bankRecord = swiftCodeRecord;
|
|
104
|
+
this.banksByName = nameRecord;
|
|
105
|
+
this.banksByShortName = shortNameRecord;
|
|
106
|
+
this.bankList = banks;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error("Failed to initialize BankService:", error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets all banks.
|
|
114
|
+
* @returns {Bank[]} Array of all banks
|
|
115
|
+
*/
|
|
116
|
+
getAll() {
|
|
117
|
+
return this.bankList;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets all banks as a record.
|
|
121
|
+
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
122
|
+
*/
|
|
123
|
+
getAllAsRecord() {
|
|
124
|
+
return this.bankRecord;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets static bank references to be used by the Bank class.
|
|
128
|
+
* @returns {Map<string, Bank>} Map of static references
|
|
129
|
+
*/
|
|
130
|
+
getStaticReferences() {
|
|
131
|
+
return this.staticReferences;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves a bank by its SWIFT code.
|
|
135
|
+
* @param {string} swiftCode The SWIFT code of the bank.
|
|
136
|
+
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
137
|
+
*/
|
|
138
|
+
fromSWIFTCode(swiftCode) {
|
|
139
|
+
if (!swiftCode || typeof swiftCode !== "string")
|
|
140
|
+
return;
|
|
141
|
+
return this.bankRecord[swiftCode.toUpperCase()];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves a bank by its name.
|
|
145
|
+
* @param {string} bankName The name of the bank.
|
|
146
|
+
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
147
|
+
*/
|
|
148
|
+
fromBankName(bankName) {
|
|
149
|
+
if (!bankName || typeof bankName !== "string")
|
|
150
|
+
return;
|
|
151
|
+
// First try shortname exact match
|
|
152
|
+
const bankByShortName = this.banksByShortName[bankName.toUpperCase()];
|
|
153
|
+
if (bankByShortName)
|
|
154
|
+
return bankByShortName;
|
|
155
|
+
// Next try fullname exact match
|
|
156
|
+
const bankByName = this.banksByName[bankName.toUpperCase()];
|
|
157
|
+
if (bankByName)
|
|
158
|
+
return bankByName;
|
|
159
|
+
// If not found, try more lenient matching on full name
|
|
160
|
+
for (const [name, bankObj] of Object.entries(this.banksByName)) {
|
|
161
|
+
if (bankName.toUpperCase() === name.toUpperCase()) {
|
|
162
|
+
return bankObj;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Try lenient matching on short name
|
|
166
|
+
for (const [shortName, bankObj] of Object.entries(this.banksByShortName)) {
|
|
167
|
+
if (bankName.toUpperCase() === shortName.toUpperCase()) {
|
|
168
|
+
return bankObj;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Legacy fallback - case insensitive exact match
|
|
172
|
+
return this.bankList.find((bank) => bank.fullName.toLowerCase() === bankName.toLowerCase() ||
|
|
173
|
+
bankName.toLowerCase() === bank.shortName.toLowerCase());
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
177
|
+
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
178
|
+
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
179
|
+
*/
|
|
180
|
+
isValidSwiftCode(swiftCode) {
|
|
181
|
+
if (!swiftCode)
|
|
182
|
+
return false;
|
|
183
|
+
return !!this.fromSWIFTCode(swiftCode);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Validates if a given bank name is valid.
|
|
187
|
+
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
188
|
+
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
189
|
+
*/
|
|
190
|
+
isValidBankName(bankName) {
|
|
191
|
+
if (!bankName)
|
|
192
|
+
return false;
|
|
193
|
+
return !!this.fromBankName(bankName);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Searches for banks that match the given search term.
|
|
197
|
+
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
198
|
+
* @param {number} [limit=10] - Maximum number of results to return.
|
|
199
|
+
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
200
|
+
*/
|
|
201
|
+
search(searchTerm, limit = 10) {
|
|
202
|
+
if (!searchTerm || typeof searchTerm !== "string")
|
|
203
|
+
return [];
|
|
204
|
+
const term = searchTerm.toLowerCase().trim();
|
|
205
|
+
if (term.length === 0)
|
|
206
|
+
return [];
|
|
207
|
+
const results = this.bankList.filter((bank) => bank.fullName.toLowerCase().includes(term) ||
|
|
208
|
+
bank.shortName.toLowerCase().includes(term) ||
|
|
209
|
+
bank.swiftCode.toLowerCase().includes(term));
|
|
210
|
+
return results.slice(0, limit);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
214
|
+
*
|
|
215
|
+
* @param {Bank} bank1 - First bank to compare
|
|
216
|
+
* @param {Bank} bank2 - Second bank to compare
|
|
217
|
+
* @returns {boolean} True if banks are equal, false otherwise
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
compare(bank1, bank2) {
|
|
221
|
+
return (bank1.fullName === bank2.fullName &&
|
|
222
|
+
bank1.shortName === bank2.shortName &&
|
|
223
|
+
bank1.swiftCode === bank2.swiftCode);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
227
|
+
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
228
|
+
*/
|
|
229
|
+
getAllSwiftCodes() {
|
|
230
|
+
return this.bankList.map((bank) => bank.swiftCode.toUpperCase());
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Checks whether a given SWIFT code is in the correct format.
|
|
234
|
+
* @param {string} swiftCode The SWIFT code to check.
|
|
235
|
+
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
236
|
+
*/
|
|
237
|
+
isValidSwiftCodeFormat(swiftCode) {
|
|
238
|
+
return SWIFT_CODE_REGEX.test(swiftCode);
|
|
239
|
+
}
|
|
240
|
+
}
|