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