@temboplus/frontend-core 0.2.5 → 0.2.6
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 +63 -14
- package/esm/src/data/countries.d.ts +12 -2
- package/esm/src/data/countries.js +496 -248
- package/esm/src/models/amount/amount.d.ts.map +1 -1
- package/esm/src/models/amount/amount.js +1 -1
- package/esm/src/models/bank/bank.d.ts +127 -0
- package/esm/src/models/bank/bank.d.ts.map +1 -1
- package/esm/src/models/bank/bank.js +264 -7
- package/esm/src/models/bank/index.d.ts +0 -1
- package/esm/src/models/bank/index.d.ts.map +1 -1
- package/esm/src/models/bank/index.js +0 -1
- package/esm/src/models/country/country.d.ts +162 -24
- package/esm/src/models/country/country.d.ts.map +1 -1
- package/esm/src/models/country/country.js +442 -42
- package/esm/src/models/country/index.d.ts +1 -1
- package/esm/src/models/country/index.d.ts.map +1 -1
- package/esm/src/models/country/index.js +1 -1
- package/esm/src/models/country/types.d.ts +53 -0
- package/esm/src/models/country/types.d.ts.map +1 -0
- package/esm/src/models/country/types.js +43 -0
- package/esm/src/models/currency/currency.d.ts +127 -4
- package/esm/src/models/currency/currency.d.ts.map +1 -1
- package/esm/src/models/currency/currency.js +229 -11
- package/esm/src/models/currency/index.d.ts +1 -1
- package/esm/src/models/currency/index.d.ts.map +1 -1
- package/esm/src/models/currency/index.js +1 -1
- package/esm/src/models/currency/types.d.ts +20 -0
- package/esm/src/models/currency/types.d.ts.map +1 -0
- package/esm/src/models/currency/types.js +13 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts +3 -2
- package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -1
- package/esm/src/models/phone_number/global/service.d.ts +27 -20
- package/esm/src/models/phone_number/global/service.d.ts.map +1 -1
- package/esm/src/models/phone_number/global/service.js +61 -40
- package/package.json +1 -1
- package/script/src/data/countries.d.ts +12 -2
- package/script/src/data/countries.js +496 -248
- package/script/src/models/amount/amount.d.ts.map +1 -1
- package/script/src/models/amount/amount.js +4 -4
- package/script/src/models/bank/bank.d.ts +127 -0
- package/script/src/models/bank/bank.d.ts.map +1 -1
- package/script/src/models/bank/bank.js +273 -12
- package/script/src/models/bank/index.d.ts +0 -1
- package/script/src/models/bank/index.d.ts.map +1 -1
- package/script/src/models/bank/index.js +0 -1
- package/script/src/models/country/country.d.ts +162 -24
- package/script/src/models/country/country.d.ts.map +1 -1
- package/script/src/models/country/country.js +453 -49
- package/script/src/models/country/index.d.ts +1 -1
- package/script/src/models/country/index.d.ts.map +1 -1
- package/script/src/models/country/index.js +1 -1
- package/script/src/models/country/types.d.ts +53 -0
- package/script/src/models/country/types.d.ts.map +1 -0
- package/script/src/models/country/types.js +46 -0
- package/script/src/models/currency/currency.d.ts +127 -4
- package/script/src/models/currency/currency.d.ts.map +1 -1
- package/script/src/models/currency/currency.js +237 -15
- package/script/src/models/currency/index.d.ts +1 -1
- package/script/src/models/currency/index.d.ts.map +1 -1
- package/script/src/models/currency/index.js +1 -1
- package/script/src/models/currency/types.d.ts +20 -0
- package/script/src/models/currency/types.d.ts.map +1 -0
- package/script/src/models/currency/types.js +14 -0
- package/script/src/models/phone_number/global/phone_number.d.ts +3 -2
- package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -1
- package/script/src/models/phone_number/global/service.d.ts +27 -20
- package/script/src/models/phone_number/global/service.d.ts.map +1 -1
- package/script/src/models/phone_number/global/service.js +61 -40
- package/esm/src/models/bank/service.d.ts +0 -106
- package/esm/src/models/bank/service.d.ts.map +0 -1
- package/esm/src/models/bank/service.js +0 -240
- package/esm/src/models/country/service.d.ts +0 -111
- package/esm/src/models/country/service.d.ts.map +0 -1
- package/esm/src/models/country/service.js +0 -366
- package/esm/src/models/currency/service.d.ts +0 -96
- package/esm/src/models/currency/service.d.ts.map +0 -1
- package/esm/src/models/currency/service.js +0 -194
- package/script/src/models/bank/service.d.ts +0 -106
- package/script/src/models/bank/service.d.ts.map +0 -1
- package/script/src/models/bank/service.js +0 -247
- package/script/src/models/country/service.d.ts +0 -111
- package/script/src/models/country/service.d.ts.map +0 -1
- package/script/src/models/country/service.js +0 -373
- package/script/src/models/currency/service.d.ts +0 -96
- package/script/src/models/currency/service.d.ts.map +0 -1
- package/script/src/models/currency/service.js +0 -201
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,YAAY,QAA2C,CAAC;AAE9D,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC,OAAO;IAcP;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,YAAY,GAAE,MAAc,GAC3B,MAAM,GAAG,SAAS;IAkCrB;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAKlC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC9B,YAAY,GAAE,MAAc,GAC3B,OAAO;IAQV;;;;;;OAMG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IA4B7C;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B;AAgDD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Regex explanation:
|
|
2
2
|
// ^(?:\d{1,3}(?:,\d{3})*|\d+) - Either grouped digits with commas OR just digits
|
|
3
|
-
import { CurrencyService } from "../currency/
|
|
3
|
+
import { CurrencyService } from "../currency/currency.js";
|
|
4
4
|
// (?:\.\d+)?$ - Optional decimal part with any number of digits
|
|
5
5
|
const AMOUNT_REGEX = /^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/;
|
|
6
6
|
class Amount {
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This file contains both the Bank class and BankService class.
|
|
3
|
+
*
|
|
4
|
+
* ARCHITECTURE NOTE: Bank and BankService Classes
|
|
5
|
+
* ===============================================
|
|
6
|
+
*
|
|
7
|
+
* These two classes have been intentionally placed in the same file to follow
|
|
8
|
+
* the established domain model pattern used with Country and Currency classes.
|
|
9
|
+
*
|
|
10
|
+
* - Bank class: Defines bank properties and static accessors
|
|
11
|
+
* - BankService class: Loads bank data and provides instance methods
|
|
12
|
+
*
|
|
13
|
+
* Benefits of this approach:
|
|
14
|
+
* 1. Prevents circular dependencies between the classes
|
|
15
|
+
* 2. Ensures static properties are immediately available on import
|
|
16
|
+
* 3. Maintains a consistent architectural pattern across domain models
|
|
17
|
+
* 4. Encapsulates all bank-related functionality in a single module
|
|
18
|
+
*
|
|
19
|
+
* This implementation follows the "Smart Models, Dumb Services" pattern where
|
|
20
|
+
* the Bank class provides a rich public API through static methods that delegate
|
|
21
|
+
* to the internal BankService. Meanwhile, BankService handles data loading and
|
|
22
|
+
* indexing without being directly exposed to external code.
|
|
23
|
+
*/
|
|
1
24
|
/**
|
|
2
25
|
* Represents a bank with essential details.
|
|
3
26
|
* @class Bank
|
|
@@ -127,4 +150,108 @@ export declare class Bank {
|
|
|
127
150
|
*/
|
|
128
151
|
static is(obj: unknown): obj is Bank;
|
|
129
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Regex pattern to validate SWIFT codes.
|
|
155
|
+
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
156
|
+
* @constant {RegExp}
|
|
157
|
+
*/
|
|
158
|
+
export declare const SWIFT_CODE_REGEX: RegExp;
|
|
159
|
+
/**
|
|
160
|
+
* Service for managing bank data.
|
|
161
|
+
* @class BankService
|
|
162
|
+
*/
|
|
163
|
+
export declare class BankService {
|
|
164
|
+
private static instance;
|
|
165
|
+
private bankList;
|
|
166
|
+
private bankRecord;
|
|
167
|
+
private banksByName;
|
|
168
|
+
private banksByShortName;
|
|
169
|
+
private staticReferences;
|
|
170
|
+
private constructor();
|
|
171
|
+
/**
|
|
172
|
+
* Gets the singleton instance of BankService.
|
|
173
|
+
* Creates the instance if it doesn't exist.
|
|
174
|
+
* @static
|
|
175
|
+
* @returns {BankService} The singleton instance
|
|
176
|
+
*/
|
|
177
|
+
static getInstance(): BankService;
|
|
178
|
+
/**
|
|
179
|
+
* Initializes the service with bank data.
|
|
180
|
+
* Should be called once when your application starts.
|
|
181
|
+
*/
|
|
182
|
+
private initialize;
|
|
183
|
+
/**
|
|
184
|
+
* Gets all banks.
|
|
185
|
+
* @returns {Bank[]} Array of all banks
|
|
186
|
+
*/
|
|
187
|
+
getAll(): Bank[];
|
|
188
|
+
/**
|
|
189
|
+
* Gets all banks as a record.
|
|
190
|
+
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
191
|
+
*/
|
|
192
|
+
getAllAsRecord(): Record<string, Bank>;
|
|
193
|
+
/**
|
|
194
|
+
* Gets static bank references to be used by the Bank class.
|
|
195
|
+
* @returns {Map<string, Bank>} Map of static references
|
|
196
|
+
*/
|
|
197
|
+
getStaticReferences(): Map<string, Bank>;
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves a bank by its SWIFT code.
|
|
200
|
+
* @param {string} swiftCode The SWIFT code of the bank.
|
|
201
|
+
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
202
|
+
*/
|
|
203
|
+
fromSWIFTCode(swiftCode: string): Bank | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Retrieves a bank by its name.
|
|
206
|
+
* @param {string} bankName The name of the bank.
|
|
207
|
+
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
208
|
+
*/
|
|
209
|
+
fromBankName(bankName: string): Bank | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
212
|
+
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
213
|
+
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
214
|
+
*/
|
|
215
|
+
isValidSwiftCode(swiftCode?: string | null): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Validates if a given bank name is valid.
|
|
218
|
+
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
219
|
+
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
220
|
+
*/
|
|
221
|
+
isValidBankName(bankName?: string | null): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Searches for banks that match the given search term.
|
|
224
|
+
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
225
|
+
* @param {number} [limit=10] - Maximum number of results to return.
|
|
226
|
+
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
227
|
+
*/
|
|
228
|
+
search(searchTerm: string, limit?: number): Bank[];
|
|
229
|
+
/**
|
|
230
|
+
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
231
|
+
*
|
|
232
|
+
* @param {Bank} bank1 - First bank to compare
|
|
233
|
+
* @param {Bank} bank2 - Second bank to compare
|
|
234
|
+
* @returns {boolean} True if banks are equal, false otherwise
|
|
235
|
+
* @private
|
|
236
|
+
*/
|
|
237
|
+
compare(bank1: Bank, bank2: Bank): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
240
|
+
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
241
|
+
*/
|
|
242
|
+
getAllSwiftCodes(): string[];
|
|
243
|
+
/**
|
|
244
|
+
* Checks whether a given SWIFT code is in the correct format.
|
|
245
|
+
* @param {string} swiftCode The SWIFT code to check.
|
|
246
|
+
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
247
|
+
*/
|
|
248
|
+
isValidSwiftCodeFormat(swiftCode: string): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Validates whether a given SWIFT code is correct.
|
|
251
|
+
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
252
|
+
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
253
|
+
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
254
|
+
*/
|
|
255
|
+
validateSWIFTCode: (swiftCode?: string) => boolean;
|
|
256
|
+
}
|
|
130
257
|
//# sourceMappingURL=bank.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bank.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/bank.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bank.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/bank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;GAGG;AACH,qBAAa,IAAI;IAmDb,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAnD7B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAC3B,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAC1B,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAC1B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAC9B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAC3B,MAAM,CAAC,QAAQ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,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"}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This file contains both the Bank class and BankService class.
|
|
3
|
+
*
|
|
4
|
+
* ARCHITECTURE NOTE: Bank and BankService Classes
|
|
5
|
+
* ===============================================
|
|
6
|
+
*
|
|
7
|
+
* These two classes have been intentionally placed in the same file to follow
|
|
8
|
+
* the established domain model pattern used with Country and Currency classes.
|
|
9
|
+
*
|
|
10
|
+
* - Bank class: Defines bank properties and static accessors
|
|
11
|
+
* - BankService class: Loads bank data and provides instance methods
|
|
12
|
+
*
|
|
13
|
+
* Benefits of this approach:
|
|
14
|
+
* 1. Prevents circular dependencies between the classes
|
|
15
|
+
* 2. Ensures static properties are immediately available on import
|
|
16
|
+
* 3. Maintains a consistent architectural pattern across domain models
|
|
17
|
+
* 4. Encapsulates all bank-related functionality in a single module
|
|
18
|
+
*
|
|
19
|
+
* This implementation follows the "Smart Models, Dumb Services" pattern where
|
|
20
|
+
* the Bank class provides a rich public API through static methods that delegate
|
|
21
|
+
* to the internal BankService. Meanwhile, BankService handles data loading and
|
|
22
|
+
* indexing without being directly exposed to external code.
|
|
23
|
+
*/
|
|
24
|
+
import file from "../../data/banks_tz.js";
|
|
2
25
|
/**
|
|
3
26
|
* Represents a bank with essential details.
|
|
4
27
|
* @class Bank
|
|
@@ -176,11 +199,245 @@ export class Bank {
|
|
|
176
199
|
return Boolean(bankFromSwift);
|
|
177
200
|
}
|
|
178
201
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Regex pattern to validate SWIFT codes.
|
|
204
|
+
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
205
|
+
* @constant {RegExp}
|
|
206
|
+
*/
|
|
207
|
+
export const SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
|
|
208
|
+
/**
|
|
209
|
+
* Service for managing bank data.
|
|
210
|
+
* @class BankService
|
|
211
|
+
*/
|
|
212
|
+
export class BankService {
|
|
213
|
+
constructor() {
|
|
214
|
+
Object.defineProperty(this, "bankList", {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
configurable: true,
|
|
217
|
+
writable: true,
|
|
218
|
+
value: []
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(this, "bankRecord", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
configurable: true,
|
|
223
|
+
writable: true,
|
|
224
|
+
value: {}
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(this, "banksByName", {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
configurable: true,
|
|
229
|
+
writable: true,
|
|
230
|
+
value: {}
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(this, "banksByShortName", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
configurable: true,
|
|
235
|
+
writable: true,
|
|
236
|
+
value: {}
|
|
237
|
+
});
|
|
238
|
+
// Static references for direct access through Bank class
|
|
239
|
+
Object.defineProperty(this, "staticReferences", {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
configurable: true,
|
|
242
|
+
writable: true,
|
|
243
|
+
value: new Map()
|
|
244
|
+
});
|
|
245
|
+
/**
|
|
246
|
+
* Validates whether a given SWIFT code is correct.
|
|
247
|
+
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
248
|
+
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
249
|
+
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
250
|
+
*/
|
|
251
|
+
Object.defineProperty(this, "validateSWIFTCode", {
|
|
252
|
+
enumerable: true,
|
|
253
|
+
configurable: true,
|
|
254
|
+
writable: true,
|
|
255
|
+
value: (swiftCode) => {
|
|
256
|
+
if (!swiftCode)
|
|
257
|
+
return false;
|
|
258
|
+
const normalizedCode = swiftCode.trim().toUpperCase();
|
|
259
|
+
return (this.isValidSwiftCodeFormat(normalizedCode) &&
|
|
260
|
+
this.getAllSwiftCodes().includes(normalizedCode));
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets the singleton instance of BankService.
|
|
266
|
+
* Creates the instance if it doesn't exist.
|
|
267
|
+
* @static
|
|
268
|
+
* @returns {BankService} The singleton instance
|
|
269
|
+
*/
|
|
270
|
+
static getInstance() {
|
|
271
|
+
if (!BankService.instance) {
|
|
272
|
+
BankService.instance = new BankService();
|
|
273
|
+
BankService.instance.initialize();
|
|
274
|
+
}
|
|
275
|
+
return BankService.instance;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Initializes the service with bank data.
|
|
279
|
+
* Should be called once when your application starts.
|
|
280
|
+
*/
|
|
281
|
+
initialize() {
|
|
282
|
+
try {
|
|
283
|
+
const data = JSON.parse(JSON.stringify(file));
|
|
284
|
+
const banks = Object.values(data).map((b) => new Bank(b.fullName, b.shortName, b.swiftCode));
|
|
285
|
+
const swiftCodeRecord = {};
|
|
286
|
+
const nameRecord = {};
|
|
287
|
+
const shortNameRecord = {};
|
|
288
|
+
banks.forEach((bank) => {
|
|
289
|
+
// Populate records
|
|
290
|
+
swiftCodeRecord[bank.swiftCode.toUpperCase()] = bank;
|
|
291
|
+
nameRecord[bank.fullName.toUpperCase()] = bank;
|
|
292
|
+
shortNameRecord[bank.shortName.toUpperCase()] = bank;
|
|
293
|
+
// Add to static references with uppercase short name
|
|
294
|
+
const shortName = bank.shortName.toUpperCase();
|
|
295
|
+
this.staticReferences.set(shortName, bank);
|
|
296
|
+
// Handle bank names with spaces (like "GT BANK")
|
|
297
|
+
if (shortName.includes(" ")) {
|
|
298
|
+
const noSpaceName = shortName.replace(/\s+/g, "_");
|
|
299
|
+
this.staticReferences.set(noSpaceName, bank);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
this.bankRecord = swiftCodeRecord;
|
|
303
|
+
this.banksByName = nameRecord;
|
|
304
|
+
this.banksByShortName = shortNameRecord;
|
|
305
|
+
this.bankList = banks;
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.error("Failed to initialize BankService:", error);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Gets all banks.
|
|
313
|
+
* @returns {Bank[]} Array of all banks
|
|
314
|
+
*/
|
|
315
|
+
getAll() {
|
|
316
|
+
return this.bankList;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Gets all banks as a record.
|
|
320
|
+
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
321
|
+
*/
|
|
322
|
+
getAllAsRecord() {
|
|
323
|
+
return this.bankRecord;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Gets static bank references to be used by the Bank class.
|
|
327
|
+
* @returns {Map<string, Bank>} Map of static references
|
|
328
|
+
*/
|
|
329
|
+
getStaticReferences() {
|
|
330
|
+
return this.staticReferences;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Retrieves a bank by its SWIFT code.
|
|
334
|
+
* @param {string} swiftCode The SWIFT code of the bank.
|
|
335
|
+
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
336
|
+
*/
|
|
337
|
+
fromSWIFTCode(swiftCode) {
|
|
338
|
+
if (!swiftCode || typeof swiftCode !== "string")
|
|
339
|
+
return;
|
|
340
|
+
return this.bankRecord[swiftCode.toUpperCase()];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Retrieves a bank by its name.
|
|
344
|
+
* @param {string} bankName The name of the bank.
|
|
345
|
+
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
346
|
+
*/
|
|
347
|
+
fromBankName(bankName) {
|
|
348
|
+
if (!bankName || typeof bankName !== "string")
|
|
349
|
+
return;
|
|
350
|
+
// First try shortname exact match
|
|
351
|
+
const bankByShortName = this.banksByShortName[bankName.toUpperCase()];
|
|
352
|
+
if (bankByShortName)
|
|
353
|
+
return bankByShortName;
|
|
354
|
+
// Next try fullname exact match
|
|
355
|
+
const bankByName = this.banksByName[bankName.toUpperCase()];
|
|
356
|
+
if (bankByName)
|
|
357
|
+
return bankByName;
|
|
358
|
+
// If not found, try more lenient matching on full name
|
|
359
|
+
for (const [name, bankObj] of Object.entries(this.banksByName)) {
|
|
360
|
+
if (bankName.toUpperCase() === name.toUpperCase()) {
|
|
361
|
+
return bankObj;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// Try lenient matching on short name
|
|
365
|
+
for (const [shortName, bankObj] of Object.entries(this.banksByShortName)) {
|
|
366
|
+
if (bankName.toUpperCase() === shortName.toUpperCase()) {
|
|
367
|
+
return bankObj;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Legacy fallback - case insensitive exact match
|
|
371
|
+
return this.bankList.find((bank) => bank.fullName.toLowerCase() === bankName.toLowerCase() ||
|
|
372
|
+
bankName.toLowerCase() === bank.shortName.toLowerCase());
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
376
|
+
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
377
|
+
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
378
|
+
*/
|
|
379
|
+
isValidSwiftCode(swiftCode) {
|
|
380
|
+
if (!swiftCode)
|
|
381
|
+
return false;
|
|
382
|
+
return !!this.fromSWIFTCode(swiftCode);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Validates if a given bank name is valid.
|
|
386
|
+
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
387
|
+
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
388
|
+
*/
|
|
389
|
+
isValidBankName(bankName) {
|
|
390
|
+
if (!bankName)
|
|
391
|
+
return false;
|
|
392
|
+
return !!this.fromBankName(bankName);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Searches for banks that match the given search term.
|
|
396
|
+
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
397
|
+
* @param {number} [limit=10] - Maximum number of results to return.
|
|
398
|
+
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
399
|
+
*/
|
|
400
|
+
search(searchTerm, limit = 10) {
|
|
401
|
+
if (!searchTerm || typeof searchTerm !== "string")
|
|
402
|
+
return [];
|
|
403
|
+
const term = searchTerm.toLowerCase().trim();
|
|
404
|
+
if (term.length === 0)
|
|
405
|
+
return [];
|
|
406
|
+
const results = this.bankList.filter((bank) => bank.fullName.toLowerCase().includes(term) ||
|
|
407
|
+
bank.shortName.toLowerCase().includes(term) ||
|
|
408
|
+
bank.swiftCode.toLowerCase().includes(term));
|
|
409
|
+
return results.slice(0, limit);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
413
|
+
*
|
|
414
|
+
* @param {Bank} bank1 - First bank to compare
|
|
415
|
+
* @param {Bank} bank2 - Second bank to compare
|
|
416
|
+
* @returns {boolean} True if banks are equal, false otherwise
|
|
417
|
+
* @private
|
|
418
|
+
*/
|
|
419
|
+
compare(bank1, bank2) {
|
|
420
|
+
return (bank1.fullName === bank2.fullName &&
|
|
421
|
+
bank1.shortName === bank2.shortName &&
|
|
422
|
+
bank1.swiftCode === bank2.swiftCode);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
426
|
+
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
427
|
+
*/
|
|
428
|
+
getAllSwiftCodes() {
|
|
429
|
+
return this.bankList.map((bank) => bank.swiftCode.toUpperCase());
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Checks whether a given SWIFT code is in the correct format.
|
|
433
|
+
* @param {string} swiftCode The SWIFT code to check.
|
|
434
|
+
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
435
|
+
*/
|
|
436
|
+
isValidSwiftCodeFormat(swiftCode) {
|
|
437
|
+
return SWIFT_CODE_REGEX.test(swiftCode);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
(function setupStaticReferences() {
|
|
184
441
|
try {
|
|
185
442
|
const staticRefs = BankService.getInstance().getStaticReferences();
|
|
186
443
|
staticRefs.forEach((bank, key) => {
|
|
@@ -191,4 +448,4 @@ setTimeout(() => {
|
|
|
191
448
|
catch (error) {
|
|
192
449
|
console.error("Failed to initialize Bank static properties:", error);
|
|
193
450
|
}
|
|
194
|
-
}
|
|
451
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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"}
|