@temboplus/afloat 0.1.77-beta.6 → 0.1.77-beta.8
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/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/contact/contact-info.model.d.ts +129 -521
- package/dist/modules/contact/contact.model.d.ts +164 -32
- package/dist/modules/wallet/wallet.query.d.ts +95 -0
- package/dist/modules/wallet/wallet.repository.d.ts +45 -13
- package/package.json +2 -2
|
@@ -22,8 +22,8 @@ import type { BankSwiftCode, MNOId } from "@temboplus/frontend-core";
|
|
|
22
22
|
* @example
|
|
23
23
|
* ```typescript
|
|
24
24
|
* // Cannot instantiate directly - use concrete implementations
|
|
25
|
-
* const mobileContact =
|
|
26
|
-
* const bankContact =
|
|
25
|
+
* const mobileContact = MobileContactInfo.from({ name: "John Doe", phoneNumber });
|
|
26
|
+
* const bankContact = BankContactInfo.from({ accName: "Jane Smith", bank, accNo: "123456789" });
|
|
27
27
|
*
|
|
28
28
|
* // Polymorphic usage
|
|
29
29
|
* function processContact(contact: BaseContactInfo) {
|
|
@@ -115,6 +115,26 @@ declare abstract class BaseContactInfo {
|
|
|
115
115
|
* @returns {boolean} True if the contact information is valid
|
|
116
116
|
*/
|
|
117
117
|
abstract validate(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Converts the contact info to a plain JavaScript object for serialization.
|
|
120
|
+
*
|
|
121
|
+
* @abstract
|
|
122
|
+
* @returns {Record<string, unknown>} Plain object representation
|
|
123
|
+
*/
|
|
124
|
+
abstract toObject(): Record<string, unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Serializes the contact info to a JSON string.
|
|
127
|
+
*
|
|
128
|
+
* @returns {string} JSON string representation
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const contact = MobileContactInfo.from({ name: "John", phoneNumber });
|
|
133
|
+
* const jsonString = contact.toJSON();
|
|
134
|
+
* // Store or transmit jsonString
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
toJSON(): string;
|
|
118
138
|
}
|
|
119
139
|
/**
|
|
120
140
|
* Implementation of BaseContactInfo for mobile phone contacts.
|
|
@@ -144,24 +164,16 @@ declare abstract class BaseContactInfo {
|
|
|
144
164
|
*
|
|
145
165
|
* @example
|
|
146
166
|
* ```typescript
|
|
147
|
-
* //
|
|
148
|
-
* const tzContact =
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* //
|
|
153
|
-
* const tzExplicit = new MobileContactInfo("John Doe", tzPhoneNumber, TZMNOId.AIRTEL);
|
|
154
|
-
* console.log(tzExplicit.channel); // "VODACOM" (auto-detected, not AIRTEL)
|
|
155
|
-
*
|
|
156
|
-
* // Kenya - MNO must be explicit due to MNP
|
|
157
|
-
* const keContact = new MobileContactInfo("Jane Smith", kePhoneNumber, KEMNOId.SAFARICOM);
|
|
158
|
-
* console.log(keContact.countryCode); // "KE" (from phoneNumber)
|
|
167
|
+
* // Preferred: Use static factory method
|
|
168
|
+
* const tzContact = MobileContactInfo.from({
|
|
169
|
+
* name: "John Doe",
|
|
170
|
+
* phoneNumber: tzPhoneNumber
|
|
171
|
+
* });
|
|
172
|
+
* console.log(tzContact?.channelName); // "M-Pesa" (Vodacom's service)
|
|
159
173
|
*
|
|
160
|
-
* //
|
|
161
|
-
*
|
|
174
|
+
* // From JSON
|
|
175
|
+
* const jsonContact = MobileContactInfo.fromJSON(jsonString);
|
|
162
176
|
* ```
|
|
163
|
-
*
|
|
164
|
-
* @throws {ContactInfoError} When validation fails (invalid name, phone, or MNO)
|
|
165
177
|
*/
|
|
166
178
|
export declare class MobileContactInfo extends BaseContactInfo {
|
|
167
179
|
readonly name: string;
|
|
@@ -174,147 +186,100 @@ export declare class MobileContactInfo extends BaseContactInfo {
|
|
|
174
186
|
* 1. Validates name is non-empty
|
|
175
187
|
* 2. Validates phone number structure
|
|
176
188
|
* 3. Extracts country code from PhoneNumber object
|
|
177
|
-
* 4. Handles MNO validation based on country MNP status
|
|
178
|
-
* - **Countries with MNP (KE)**: Requires explicit MNO, validates it's valid for country
|
|
179
|
-
* - **Countries without MNP (TZ)**: Always auto-detects MNO from phone number prefix (ignores provided MNO)
|
|
189
|
+
* 4. Handles MNO validation based on country MNP status
|
|
180
190
|
*
|
|
191
|
+
* @deprecated Use {@link MobileContactInfo.from} static factory method instead
|
|
181
192
|
* @param {string} name - The contact's personal name (required, non-empty)
|
|
182
193
|
* @param {PhoneNumber} phoneNumber - The validated phone number object (contains country code)
|
|
183
194
|
* @param {MNOId} [mnoId] - MNO ID. Required for MNP countries (KE), ignored for non-MNP countries (TZ)
|
|
184
195
|
*
|
|
185
|
-
* @throws {ContactInfoError} When any validation fails
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
*
|
|
196
|
+
* @throws {ContactInfoError} When any validation fails
|
|
197
|
+
*/
|
|
198
|
+
constructor(name: string, phoneNumber: PhoneNumber, mnoId?: MNOId);
|
|
199
|
+
/**
|
|
200
|
+
* Creates a MobileContactInfo instance from data object.
|
|
201
|
+
* This is the preferred method for creating instances.
|
|
202
|
+
*
|
|
203
|
+
* @static
|
|
204
|
+
* @param {Object} data - The mobile contact data
|
|
205
|
+
* @param {string} data.name - The contact's personal name
|
|
206
|
+
* @param {PhoneNumber} data.phoneNumber - The validated phone number object
|
|
207
|
+
* @param {MNOId} [data.mnoId] - MNO ID (required for MNP countries)
|
|
208
|
+
*
|
|
209
|
+
* @returns {MobileContactInfo | undefined} New instance if successful, undefined if validation fails
|
|
191
210
|
*
|
|
192
211
|
* @example
|
|
193
212
|
* ```typescript
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* // Kenya - MNO must be explicit
|
|
200
|
-
* const keExplicit = new MobileContactInfo("Jane", kePhone, KEMNOId.SAFARICOM);
|
|
201
|
-
* } catch (error) {
|
|
202
|
-
* if (error instanceof ContactInfoError) {
|
|
203
|
-
* console.log(`${error.message} - Context:`, error.context);
|
|
204
|
-
* }
|
|
205
|
-
* }
|
|
213
|
+
* const contact = MobileContactInfo.from({
|
|
214
|
+
* name: "John Doe",
|
|
215
|
+
* phoneNumber: tzPhone,
|
|
216
|
+
* mnoId: TZMNOId.VODACOM // Optional for TZ, required for KE
|
|
217
|
+
* });
|
|
206
218
|
* ```
|
|
207
219
|
*/
|
|
208
|
-
|
|
220
|
+
static from(data: {
|
|
221
|
+
name: string;
|
|
222
|
+
phoneNumber: PhoneNumber;
|
|
223
|
+
mnoId?: MNOId;
|
|
224
|
+
}): MobileContactInfo | undefined;
|
|
209
225
|
/**
|
|
210
226
|
* Creates a MobileContactInfo instance from a ContactDTO object.
|
|
211
227
|
* Handles validation and MNO extraction from the DTO's channel field.
|
|
212
|
-
* The country code is automatically derived from the parsed phone number.
|
|
213
|
-
*
|
|
214
|
-
* **Process:**
|
|
215
|
-
* 1. Validates DTO type is "Mobile"
|
|
216
|
-
* 2. Parses phone number (extracts country code from E164 format)
|
|
217
|
-
* 3. Handles MNO based on country MNP status:
|
|
218
|
-
* - **MNP countries**: Uses channel field (required)
|
|
219
|
-
* - **Non-MNP countries**: Auto-detects from phone number (ignores channel field)
|
|
220
|
-
* 4. Delegates to constructor for final validation
|
|
221
228
|
*
|
|
222
229
|
* @static
|
|
223
230
|
* @param {ContactDTO} info - The contact data transfer object
|
|
224
|
-
* @param {string} info.type - Must be "Mobile"
|
|
225
|
-
* @param {string} info.accountNo - The phone number string to parse (should be E164 format)
|
|
226
|
-
* @param {string} info.displayName - The contact's name
|
|
227
|
-
* @param {string} [info.channel] - MNO ID (required for MNP countries, ignored for non-MNP countries)
|
|
228
|
-
*
|
|
229
231
|
* @returns {MobileContactInfo | undefined} New instance if successful, undefined if validation fails
|
|
230
232
|
*
|
|
231
233
|
* @example
|
|
232
234
|
* ```typescript
|
|
233
|
-
*
|
|
234
|
-
* const tzContactDTO = {
|
|
235
|
+
* const contactDTO = {
|
|
235
236
|
* type: "Mobile",
|
|
236
|
-
* accountNo: "+255712345678",
|
|
237
|
+
* accountNo: "+255712345678",
|
|
237
238
|
* displayName: "John Doe",
|
|
238
|
-
* channel: "
|
|
239
|
+
* channel: "VODACOM"
|
|
239
240
|
* };
|
|
240
241
|
*
|
|
241
|
-
*
|
|
242
|
-
* const keContactDTO = {
|
|
243
|
-
* type: "Mobile",
|
|
244
|
-
* accountNo: "+254712345678",
|
|
245
|
-
* displayName: "Jane Smith",
|
|
246
|
-
* channel: "SAFARICOM" // Required for Kenya
|
|
247
|
-
* };
|
|
248
|
-
*
|
|
249
|
-
* const tzContact = MobileContactInfo.fromContactDTO(tzContactDTO);
|
|
250
|
-
* console.log(tzContact?.channelId); // "VODACOM" (not "AIRTEL")
|
|
251
|
-
* console.log(tzContact?.countryCode); // "TZ" (from phone number)
|
|
252
|
-
*
|
|
253
|
-
* const keContact = MobileContactInfo.fromContactDTO(keContactDTO);
|
|
254
|
-
* console.log(keContact?.channelId); // "SAFARICOM"
|
|
255
|
-
* console.log(keContact?.countryCode); // "KE" (from phone number)
|
|
242
|
+
* const contact = MobileContactInfo.fromContactDTO(contactDTO);
|
|
256
243
|
* ```
|
|
257
244
|
*/
|
|
258
245
|
static fromContactDTO(info: ContactDTO): MobileContactInfo | undefined;
|
|
259
246
|
/**
|
|
260
247
|
* Creates a MobileContactInfo instance from a PayoutDTO object.
|
|
261
248
|
* Extracts mobile contact information from payout data structure.
|
|
262
|
-
* The country code is derived from the parsed phone number.
|
|
263
|
-
*
|
|
264
|
-
* **Process:**
|
|
265
|
-
* 1. Validates country code format in DTO
|
|
266
|
-
* 2. Parses phone number from msisdn field (uses DTO country as hint)
|
|
267
|
-
* 3. Uses phone number's country code (derived from E164 format)
|
|
268
|
-
* 4. Handles MNO based on country MNP status:
|
|
269
|
-
* - **MNP countries**: Uses channel field (required)
|
|
270
|
-
* - **Non-MNP countries**: Auto-detects from phone number (ignores channel field)
|
|
271
|
-
* 5. Uses payeeName as the contact name
|
|
272
|
-
* 6. Delegates to constructor for validation
|
|
273
249
|
*
|
|
274
250
|
* @static
|
|
275
251
|
* @param {PayoutDTO} info - The payout data transfer object
|
|
276
|
-
* @param {string} info.msisdn - The phone number in E164 or local format
|
|
277
|
-
* @param {string} info.countryCode - ISO2 country code (used as parsing hint)
|
|
278
|
-
* @param {string} info.payeeName - The recipient's name
|
|
279
|
-
* @param {string} [info.channel] - MNO ID (required for MNP countries, ignored for non-MNP countries)
|
|
280
|
-
*
|
|
281
252
|
* @returns {MobileContactInfo | undefined} New instance if successful, undefined if parsing fails
|
|
282
253
|
*
|
|
283
254
|
* @example
|
|
284
255
|
* ```typescript
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* msisdn: "+255712345678", // Vodacom prefix
|
|
256
|
+
* const payoutDTO = {
|
|
257
|
+
* msisdn: "+255712345678",
|
|
288
258
|
* countryCode: "TZ",
|
|
289
259
|
* payeeName: "John Doe",
|
|
290
|
-
* channel: "
|
|
260
|
+
* channel: "VODACOM"
|
|
291
261
|
* };
|
|
292
262
|
*
|
|
293
|
-
*
|
|
294
|
-
* const kePayoutDTO = {
|
|
295
|
-
* msisdn: "+254712345678",
|
|
296
|
-
* countryCode: "KE",
|
|
297
|
-
* payeeName: "Jane Smith",
|
|
298
|
-
* channel: "SAFARICOM" // Required
|
|
299
|
-
* };
|
|
300
|
-
*
|
|
301
|
-
* const tzContact = MobileContactInfo.fromPayoutDTO(tzPayoutDTO);
|
|
302
|
-
* console.log(tzContact?.channelName); // "M-Pesa" (Vodacom's service)
|
|
303
|
-
* console.log(tzContact?.countryCode); // "TZ" (from phoneNumber)
|
|
263
|
+
* const contact = MobileContactInfo.fromPayoutDTO(payoutDTO);
|
|
304
264
|
* ```
|
|
305
265
|
*/
|
|
306
266
|
static fromPayoutDTO(info: PayoutDTO): MobileContactInfo | undefined;
|
|
307
267
|
/**
|
|
308
|
-
*
|
|
309
|
-
* Performs comprehensive structural and data validation including country-specific MNO rules.
|
|
268
|
+
* Creates a MobileContactInfo instance from a JSON string.
|
|
310
269
|
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
270
|
+
* @static
|
|
271
|
+
* @param {string} jsonString - JSON string containing mobile contact data
|
|
272
|
+
* @returns {MobileContactInfo | undefined} New instance if successful, undefined if parsing fails
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const jsonString = '{"name":"John Doe","phoneNumber":"+255712345678","mnoId":"VODACOM"}';
|
|
277
|
+
* const contact = MobileContactInfo.fromJSON(jsonString);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
static fromJSON(jsonString: string): MobileContactInfo | undefined;
|
|
281
|
+
/**
|
|
282
|
+
* Type guard to validate if an unknown object is a valid MobileContactInfo instance.
|
|
318
283
|
*
|
|
319
284
|
* @static
|
|
320
285
|
* @param {unknown} obj - The object to validate
|
|
@@ -322,96 +287,22 @@ export declare class MobileContactInfo extends BaseContactInfo {
|
|
|
322
287
|
*
|
|
323
288
|
* @example
|
|
324
289
|
* ```typescript
|
|
325
|
-
* const unknownData = JSON.parse(someJsonString);
|
|
326
|
-
*
|
|
327
290
|
* if (MobileContactInfo.is(unknownData)) {
|
|
328
|
-
* //
|
|
329
|
-
* console.log(unknownData.name); // ✅ Type-safe access
|
|
330
|
-
* console.log(unknownData.phoneNumber.e164Format); // ✅ Type-safe
|
|
331
|
-
* console.log(unknownData.mnoId); // ✅ Type-safe
|
|
332
|
-
* console.log(unknownData.countryCode); // ✅ Type-safe (from phoneNumber)
|
|
333
|
-
* } else {
|
|
334
|
-
* console.log("Invalid MobileContactInfo structure");
|
|
291
|
+
* console.log(unknownData.name); // Type-safe access
|
|
335
292
|
* }
|
|
336
|
-
*
|
|
337
|
-
* // Usage in arrays
|
|
338
|
-
* const contacts = jsonArray.filter(MobileContactInfo.is);
|
|
339
|
-
* // contacts is now typed as MobileContactInfo[]
|
|
340
293
|
* ```
|
|
341
|
-
*
|
|
342
|
-
* @remarks
|
|
343
|
-
* - Validates both serialized and live objects
|
|
344
|
-
* - Phone numbers can be provided as strings or PhoneNumber objects
|
|
345
|
-
* - Uses country-specific MNO validation through MNOUtils
|
|
346
|
-
* - Returns false for any validation failure (fail-fast approach)
|
|
347
|
-
* - For non-MNP countries, validates that the MNO matches what would be auto-detected
|
|
348
294
|
*/
|
|
349
295
|
static is(obj: unknown): obj is MobileContactInfo;
|
|
350
296
|
/**
|
|
351
297
|
* Validates that all contact information is consistent and correct.
|
|
352
|
-
* Uses country-specific validation logic through MNOUtils delegation.
|
|
353
|
-
*
|
|
354
|
-
* **Validation Checks:**
|
|
355
|
-
* 1. **Name validation**: Non-empty string
|
|
356
|
-
* 2. **Phone validation**: Valid phone number structure
|
|
357
|
-
* 3. **MNO validation**: Valid MNO for the country
|
|
358
|
-
* 4. **Consistency check**: For non-MNP countries, validates MNO matches auto-detected value from phone prefix
|
|
359
298
|
*
|
|
360
299
|
* @returns {boolean} True if all validations pass, false otherwise
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* const contact = new MobileContactInfo("John", phoneNumber, TZMNOId.VODACOM);
|
|
365
|
-
*
|
|
366
|
-
* if (contact.validate()) {
|
|
367
|
-
* console.log("Contact is valid and ready to use");
|
|
368
|
-
* } else {
|
|
369
|
-
* console.log("Contact has validation issues");
|
|
370
|
-
* // Use getValidationDetails() for specific error information
|
|
371
|
-
* }
|
|
372
|
-
* ```
|
|
373
|
-
*
|
|
374
|
-
* @see {@link getValidationDetails} For detailed validation results with specific errors
|
|
375
300
|
*/
|
|
376
301
|
validate(): boolean;
|
|
377
302
|
/**
|
|
378
303
|
* Provides detailed validation results with specific error and warning information.
|
|
379
|
-
* Uses country-specific validation logic for comprehensive analysis.
|
|
380
|
-
*
|
|
381
|
-
* **Validation Categories:**
|
|
382
|
-
* - **Errors**: Critical issues that make the contact invalid
|
|
383
|
-
* - **Warnings**: Potential issues that don't prevent usage but indicate inconsistencies
|
|
384
304
|
*
|
|
385
305
|
* @returns {Object} Detailed validation results
|
|
386
|
-
* @returns {boolean} returns.isValid - True if no errors found
|
|
387
|
-
* @returns {string[]} returns.errors - Array of error messages for critical issues
|
|
388
|
-
* @returns {string[]} returns.warnings - Array of warning messages for potential issues
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* const contact = new MobileContactInfo("John", phoneNumber);
|
|
393
|
-
* const validation = contact.getValidationDetails();
|
|
394
|
-
*
|
|
395
|
-
* console.log(`Valid: ${validation.isValid}`);
|
|
396
|
-
*
|
|
397
|
-
* if (validation.errors.length > 0) {
|
|
398
|
-
* console.log("Errors found:");
|
|
399
|
-
* validation.errors.forEach(error => console.log(`- ${error}`));
|
|
400
|
-
* }
|
|
401
|
-
*
|
|
402
|
-
* if (validation.warnings.length > 0) {
|
|
403
|
-
* console.log("Warnings:");
|
|
404
|
-
* validation.warnings.forEach(warning => console.log(`- ${warning}`));
|
|
405
|
-
* }
|
|
406
|
-
*
|
|
407
|
-
* // For non-MNP countries, the MNO is always consistent as it's auto-detected
|
|
408
|
-
* // Warnings would only appear if there were other potential issues
|
|
409
|
-
* ```
|
|
410
|
-
*
|
|
411
|
-
* @remarks
|
|
412
|
-
* Uses MNOUtils for country-specific validation logic:
|
|
413
|
-
* - **Tanzania**: Validates MNO matches auto-detected value from phone number prefix
|
|
414
|
-
* - **Kenya**: Acknowledges MNP limitations, focuses on MNO validity for country
|
|
415
306
|
*/
|
|
416
307
|
getValidationDetails(): {
|
|
417
308
|
isValid: boolean;
|
|
@@ -419,131 +310,36 @@ export declare class MobileContactInfo extends BaseContactInfo {
|
|
|
419
310
|
warnings: string[];
|
|
420
311
|
};
|
|
421
312
|
/**
|
|
422
|
-
*
|
|
313
|
+
* Converts the mobile contact info to a plain object for serialization.
|
|
423
314
|
*
|
|
424
315
|
* @override
|
|
425
|
-
* @returns {string}
|
|
316
|
+
* @returns {Record<string, unknown>} Plain object representation
|
|
426
317
|
*/
|
|
318
|
+
toObject(): Record<string, unknown>;
|
|
427
319
|
get accountName(): string;
|
|
428
|
-
/**
|
|
429
|
-
* Gets the phone number formatted for display and storage.
|
|
430
|
-
* Returns the number in e164 format (with + prefix).
|
|
431
|
-
*
|
|
432
|
-
* @override
|
|
433
|
-
* @returns {string} Phone number in e164 format (e.g., "+255712345678")
|
|
434
|
-
*
|
|
435
|
-
* @example
|
|
436
|
-
* ```typescript
|
|
437
|
-
* const contact = new MobileContactInfo("John", phoneNumber);
|
|
438
|
-
* console.log(contact.accountNumber); // "+255712345678"
|
|
439
|
-
* ```
|
|
440
|
-
*/
|
|
441
320
|
get accountNumber(): string;
|
|
442
|
-
/**
|
|
443
|
-
* Gets the localized label for the display name field.
|
|
444
|
-
*
|
|
445
|
-
* @override
|
|
446
|
-
* @returns {string} Always returns "Name" for mobile contacts
|
|
447
|
-
*/
|
|
448
321
|
get accountNameLabel(): string;
|
|
449
|
-
/**
|
|
450
|
-
* Gets the localized label for the account number field.
|
|
451
|
-
*
|
|
452
|
-
* @override
|
|
453
|
-
* @returns {string} Always returns "Phone Number" for mobile contacts
|
|
454
|
-
*/
|
|
455
322
|
get accountNumberLabel(): string;
|
|
456
|
-
/**
|
|
457
|
-
* Gets the localized label for the channel field.
|
|
458
|
-
*
|
|
459
|
-
* @override
|
|
460
|
-
* @returns {string} Always returns "Channel" for mobile contacts
|
|
461
|
-
*/
|
|
462
323
|
get channelLabel(): string;
|
|
463
|
-
/**
|
|
464
|
-
* Gets the typed MNO identifier for this mobile contact.
|
|
465
|
-
* This is the programmatic identifier used for API calls and business logic.
|
|
466
|
-
*
|
|
467
|
-
* @returns {MNOId} The MNO identifier (e.g., "VODACOM", "SAFARICOM")
|
|
468
|
-
*
|
|
469
|
-
* @example
|
|
470
|
-
* ```typescript
|
|
471
|
-
* const contact = new MobileContactInfo("John", tzPhone, TZMNOId.VODACOM);
|
|
472
|
-
* console.log(contact.channelId); // "VODACOM" (for MNP countries)
|
|
473
|
-
*
|
|
474
|
-
* // For non-MNP countries, always returns auto-detected value
|
|
475
|
-
* const contact2 = new MobileContactInfo("John", tzPhone, TZMNOId.AIRTEL); // AIRTEL ignored
|
|
476
|
-
* console.log(contact2.channelId); // "VODACOM" (auto-detected from phone prefix)
|
|
477
|
-
* ```
|
|
478
|
-
*/
|
|
479
324
|
get channelId(): MNOId;
|
|
480
|
-
/**
|
|
481
|
-
* Gets the human-readable mobile money service name for display purposes.
|
|
482
|
-
* Uses MNOUtils to retrieve service information from country-specific implementations.
|
|
483
|
-
*
|
|
484
|
-
* **Behavior:**
|
|
485
|
-
* - Returns the mobile money service name (e.g., "M-Pesa", "Airtel Money")
|
|
486
|
-
* - Falls back to MNO display name if service name unavailable
|
|
487
|
-
* - Falls back to MNO ID if no display information available
|
|
488
|
-
* - For non-MNP countries, always reflects the auto-detected MNO service
|
|
489
|
-
*
|
|
490
|
-
* @returns {string} The mobile money service name for display
|
|
491
|
-
*
|
|
492
|
-
* @example
|
|
493
|
-
* ```typescript
|
|
494
|
-
* const vodacomContact = new MobileContactInfo("John", tzPhone, TZMNOId.VODACOM);
|
|
495
|
-
* console.log(vodacomContact.channelName); // "M-Pesa"
|
|
496
|
-
*
|
|
497
|
-
* const safaricomContact = new MobileContactInfo("Jane", kePhone, KEMNOId.SAFARICOM);
|
|
498
|
-
* console.log(safaricomContact.channelName); // "M-Pesa"
|
|
499
|
-
*
|
|
500
|
-
* // For non-MNP countries, shows auto-detected service regardless of provided MNO
|
|
501
|
-
* const tzContact = new MobileContactInfo("Bob", tzVodacomPhone, TZMNOId.AIRTEL); // AIRTEL ignored
|
|
502
|
-
* console.log(tzContact.channelName); // "M-Pesa" (Vodacom's service, auto-detected)
|
|
503
|
-
* ```
|
|
504
|
-
*
|
|
505
|
-
* @remarks
|
|
506
|
-
* Uses MNOUtils.getMNOById() which delegates to country-specific implementations
|
|
507
|
-
* for consistent and accurate service name retrieval.
|
|
508
|
-
*/
|
|
509
325
|
get channelName(): string;
|
|
510
326
|
}
|
|
511
327
|
/**
|
|
512
328
|
* Implementation of BaseContactInfo for bank account contacts.
|
|
513
329
|
* Handles storage, validation, and display of contact details specific to bank transfers.
|
|
514
|
-
* The country code is automatically derived from the Bank object.
|
|
515
|
-
*
|
|
516
|
-
* This class provides comprehensive validation for bank account information including
|
|
517
|
-
* SWIFT code validation, account name verification, and account number format checking.
|
|
518
|
-
*
|
|
519
|
-
* **Key Features:**
|
|
520
|
-
* - SWIFT code validation per country regulations
|
|
521
|
-
* - Account name format validation
|
|
522
|
-
* - Account number format validation (country-specific rules)
|
|
523
|
-
* - Integration with Bank service for institution data
|
|
524
|
-
* - Country code derived from Bank (single source of truth)
|
|
525
330
|
*
|
|
526
331
|
* @extends BaseContactInfo
|
|
527
332
|
* @class BankContactInfo
|
|
528
333
|
*
|
|
529
|
-
* @property {string} accName - The bank account holder's name
|
|
530
|
-
* @property {Bank} bank - The bank institution object with SWIFT code and details
|
|
531
|
-
* @property {string} accNo - The bank account number
|
|
532
|
-
*
|
|
533
334
|
* @example
|
|
534
335
|
* ```typescript
|
|
535
|
-
*
|
|
536
|
-
* const
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
* console.log(contact.accountName); // "John Doe"
|
|
542
|
-
* console.log(contact.accountNumber); // "0150123456789"
|
|
543
|
-
* console.log(contact.countryCode); // "TZ" (from bank)
|
|
336
|
+
* const bank = Bank.from("CORUTZTZ", "TZ");
|
|
337
|
+
* const contact = BankContactInfo.from({
|
|
338
|
+
* accName: "John Doe",
|
|
339
|
+
* bank,
|
|
340
|
+
* accNo: "0150123456789"
|
|
341
|
+
* });
|
|
544
342
|
* ```
|
|
545
|
-
*
|
|
546
|
-
* @throws {ContactInfoError} When validation fails (invalid account name, number, or bank)
|
|
547
343
|
*/
|
|
548
344
|
export declare class BankContactInfo extends BaseContactInfo {
|
|
549
345
|
readonly accName: string;
|
|
@@ -551,288 +347,100 @@ export declare class BankContactInfo extends BaseContactInfo {
|
|
|
551
347
|
readonly accNo: string;
|
|
552
348
|
/**
|
|
553
349
|
* Creates a new bank contact with comprehensive validation.
|
|
554
|
-
* The country code is automatically extracted from the Bank object.
|
|
555
350
|
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
* 4. **Bank validation**: Ensures bank object is valid and contains required data
|
|
351
|
+
* @deprecated Use {@link BankContactInfo.from} static factory method instead
|
|
352
|
+
* @param {string} accName - The bank account holder's name
|
|
353
|
+
* @param {Bank} bank - The bank institution object
|
|
354
|
+
* @param {string} accNo - The bank account number
|
|
561
355
|
*
|
|
562
|
-
* @
|
|
563
|
-
|
|
564
|
-
|
|
356
|
+
* @throws {ContactInfoError} When validation fails
|
|
357
|
+
*/
|
|
358
|
+
constructor(accName: string, bank: Bank, accNo: string);
|
|
359
|
+
/**
|
|
360
|
+
* Creates a BankContactInfo instance from data object.
|
|
361
|
+
* This is the preferred method for creating instances.
|
|
565
362
|
*
|
|
566
|
-
* @
|
|
567
|
-
* -
|
|
568
|
-
*
|
|
569
|
-
*
|
|
363
|
+
* @static
|
|
364
|
+
* @param {Object} data - The bank contact data
|
|
365
|
+
* @param {string} data.accName - The account holder's name
|
|
366
|
+
* @param {Bank} data.bank - The bank institution object
|
|
367
|
+
* @param {string} data.accNo - The bank account number
|
|
368
|
+
*
|
|
369
|
+
* @returns {BankContactInfo | undefined} New instance if successful, undefined if validation fails
|
|
570
370
|
*
|
|
571
371
|
* @example
|
|
572
372
|
* ```typescript
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* }
|
|
579
|
-
* if (error instanceof ContactInfoError) {
|
|
580
|
-
* console.log(`Validation failed: ${error.message}`);
|
|
581
|
-
* }
|
|
582
|
-
* }
|
|
373
|
+
* const bank = Bank.from("CORUTZTZ", "TZ");
|
|
374
|
+
* const contact = BankContactInfo.from({
|
|
375
|
+
* accName: "John Doe",
|
|
376
|
+
* bank,
|
|
377
|
+
* accNo: "0150123456789"
|
|
378
|
+
* });
|
|
583
379
|
* ```
|
|
584
380
|
*/
|
|
585
|
-
|
|
381
|
+
static from(data: {
|
|
382
|
+
accName: string;
|
|
383
|
+
bank: Bank;
|
|
384
|
+
accNo: string;
|
|
385
|
+
}): BankContactInfo | undefined;
|
|
586
386
|
/**
|
|
587
387
|
* Creates a BankContactInfo instance from a ContactDTO object.
|
|
588
|
-
* Handles SWIFT code validation and bank lookup.
|
|
589
|
-
* The country code is derived from the SWIFT code.
|
|
590
|
-
*
|
|
591
|
-
* **Process:**
|
|
592
|
-
* 1. Validates DTO type is "Bank"
|
|
593
|
-
* 2. Extracts SWIFT code from channel field
|
|
594
|
-
* 3. Derives country code from SWIFT code
|
|
595
|
-
* 4. Validates SWIFT code format and existence
|
|
596
|
-
* 5. Looks up bank information using SWIFT code
|
|
597
|
-
* 6. Delegates to constructor for final validation
|
|
598
388
|
*
|
|
599
389
|
* @static
|
|
600
390
|
* @param {ContactDTO} info - The contact data transfer object
|
|
601
|
-
* @param {string} info.type - Must be "Bank"
|
|
602
|
-
* @param {string} info.channel - The SWIFT code for the bank
|
|
603
|
-
* @param {string} info.displayName - The account holder's name
|
|
604
|
-
* @param {string} info.accountNo - The bank account number
|
|
605
|
-
*
|
|
606
391
|
* @returns {BankContactInfo | undefined} New instance if successful, undefined if validation fails
|
|
607
|
-
*
|
|
608
|
-
* @example
|
|
609
|
-
* ```typescript
|
|
610
|
-
* const contactDTO = {
|
|
611
|
-
* type: "Bank",
|
|
612
|
-
* channel: "CORUTZTZ", // CRDB Bank SWIFT code
|
|
613
|
-
* displayName: "John Doe",
|
|
614
|
-
* accountNo: "0150123456789"
|
|
615
|
-
* };
|
|
616
|
-
*
|
|
617
|
-
* const contact = BankContactInfo.fromContactDTO(contactDTO);
|
|
618
|
-
* if (contact) {
|
|
619
|
-
* console.log(`Created bank contact: ${contact.accountName} at ${contact.bank.shortName}`);
|
|
620
|
-
* console.log(`Country: ${contact.countryCode}`); // "TZ" (derived from SWIFT)
|
|
621
|
-
* }
|
|
622
|
-
* ```
|
|
623
392
|
*/
|
|
624
393
|
static fromContactDTO(info: ContactDTO): BankContactInfo | undefined;
|
|
625
394
|
/**
|
|
626
395
|
* Creates a BankContactInfo instance from a PayoutDTO object.
|
|
627
|
-
* Parses bank information from the payout's msisdn field using "swiftcode:accountno" format.
|
|
628
|
-
* The country code is derived from the parsed phone number or validated against the SWIFT code.
|
|
629
|
-
*
|
|
630
|
-
* **Expected Format:** The msisdn field should contain "SWIFTCODE:ACCOUNTNUMBER"
|
|
631
|
-
*
|
|
632
|
-
* **Process:**
|
|
633
|
-
* 1. Validates country code format in DTO (used as hint/validation)
|
|
634
|
-
* 2. Splits msisdn field on ":" delimiter
|
|
635
|
-
* 3. Validates SWIFT code format and existence
|
|
636
|
-
* 4. Looks up bank information (bank contains country code)
|
|
637
|
-
* 5. Creates contact with parsed information
|
|
638
396
|
*
|
|
639
397
|
* @static
|
|
640
398
|
* @param {PayoutDTO} info - The payout data transfer object
|
|
641
|
-
* @
|
|
642
|
-
|
|
643
|
-
|
|
399
|
+
* @returns {BankContactInfo | undefined} New instance if successful, undefined if parsing fails
|
|
400
|
+
*/
|
|
401
|
+
static fromPayoutDTO(info: PayoutDTO): BankContactInfo | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* Creates a BankContactInfo instance from a JSON string.
|
|
644
404
|
*
|
|
405
|
+
* @static
|
|
406
|
+
* @param {string} jsonString - JSON string containing bank contact data
|
|
645
407
|
* @returns {BankContactInfo | undefined} New instance if successful, undefined if parsing fails
|
|
646
408
|
*
|
|
647
409
|
* @example
|
|
648
410
|
* ```typescript
|
|
649
|
-
* const
|
|
650
|
-
*
|
|
651
|
-
* countryCode: "TZ",
|
|
652
|
-
* payeeName: "Jane Smith"
|
|
653
|
-
* };
|
|
654
|
-
*
|
|
655
|
-
* const contact = BankContactInfo.fromPayoutDTO(payoutDTO);
|
|
656
|
-
* if (contact) {
|
|
657
|
-
* console.log(`Payout to: ${contact.accountName}`);
|
|
658
|
-
* console.log(`Bank: ${contact.bank.fullName}`);
|
|
659
|
-
* console.log(`Account: ${contact.accountNumber}`);
|
|
660
|
-
* console.log(`Country: ${contact.countryCode}`); // "TZ" (from bank)
|
|
661
|
-
* }
|
|
411
|
+
* const jsonString = '{"accName":"John Doe","swiftCode":"CORUTZTZ","accNo":"0150123456789"}';
|
|
412
|
+
* const contact = BankContactInfo.fromJSON(jsonString);
|
|
662
413
|
* ```
|
|
663
|
-
*
|
|
664
|
-
* @remarks
|
|
665
|
-
* Returns undefined if:
|
|
666
|
-
* - msisdn doesn't contain exactly one ":" separator
|
|
667
|
-
* - SWIFT code is invalid for the country
|
|
668
|
-
* - Bank lookup fails
|
|
669
|
-
* - Any validation error occurs
|
|
670
414
|
*/
|
|
671
|
-
static
|
|
415
|
+
static fromJSON(jsonString: string): BankContactInfo | undefined;
|
|
672
416
|
/**
|
|
673
417
|
* Type guard to validate if an unknown object is a valid BankContactInfo instance.
|
|
674
|
-
* Performs comprehensive structural and business logic validation.
|
|
675
|
-
*
|
|
676
|
-
* **Validation Process:**
|
|
677
|
-
* 1. **Structural validation**: Checks required properties exist with correct types
|
|
678
|
-
* 2. **Account name validation**: Uses BankValidation.validateAccountName()
|
|
679
|
-
* 3. **Account number validation**: Uses country-specific BankValidation.validateAccountNumber()
|
|
680
|
-
* 4. **Bank validation**: Ensures bank object passes Bank.is() validation
|
|
681
418
|
*
|
|
682
419
|
* @static
|
|
683
420
|
* @param {unknown} obj - The object to validate
|
|
684
421
|
* @returns {obj is BankContactInfo} Type predicate indicating validity
|
|
685
|
-
*
|
|
686
|
-
* @example
|
|
687
|
-
* ```typescript
|
|
688
|
-
* const unknownData = JSON.parse(bankJsonString);
|
|
689
|
-
*
|
|
690
|
-
* if (BankContactInfo.is(unknownData)) {
|
|
691
|
-
* // TypeScript now knows this is BankContactInfo
|
|
692
|
-
* console.log(unknownData.accName); // ✅ Type-safe access
|
|
693
|
-
* console.log(unknownData.bank.fullName); // ✅ Type-safe
|
|
694
|
-
* console.log(unknownData.accNo); // ✅ Type-safe
|
|
695
|
-
* console.log(unknownData.countryCode); // ✅ Type-safe (from bank)
|
|
696
|
-
* } else {
|
|
697
|
-
* console.log("Invalid BankContactInfo structure");
|
|
698
|
-
* }
|
|
699
|
-
*
|
|
700
|
-
* // Usage in arrays
|
|
701
|
-
* const bankContacts = jsonArray.filter(BankContactInfo.is);
|
|
702
|
-
* // bankContacts is now typed as BankContactInfo[]
|
|
703
|
-
* ```
|
|
704
|
-
*
|
|
705
|
-
* @remarks
|
|
706
|
-
* - Validates both serialized and live objects
|
|
707
|
-
* - Uses banking industry validation rules through BankValidation
|
|
708
|
-
* - Ensures bank object contains valid SWIFT code and institution data
|
|
709
|
-
* - Returns false for any validation failure (fail-fast approach)
|
|
710
422
|
*/
|
|
711
423
|
static is(obj: unknown): obj is BankContactInfo;
|
|
712
424
|
validate(): boolean;
|
|
713
425
|
/**
|
|
714
|
-
*
|
|
426
|
+
* Converts the bank contact info to a plain object for serialization.
|
|
715
427
|
*
|
|
716
428
|
* @override
|
|
717
|
-
* @returns {string}
|
|
429
|
+
* @returns {Record<string, unknown>} Plain object representation
|
|
718
430
|
*/
|
|
431
|
+
toObject(): Record<string, unknown>;
|
|
719
432
|
get accountName(): string;
|
|
720
|
-
/**
|
|
721
|
-
* Gets the bank account number for display and processing.
|
|
722
|
-
*
|
|
723
|
-
* @override
|
|
724
|
-
* @returns {string} The bank account number as provided
|
|
725
|
-
*/
|
|
726
433
|
get accountNumber(): string;
|
|
727
|
-
/**
|
|
728
|
-
* Gets the localized label for the display name field.
|
|
729
|
-
*
|
|
730
|
-
* @override
|
|
731
|
-
* @returns {string} Always returns "Acc. Name" for bank contacts
|
|
732
|
-
*/
|
|
733
434
|
get accountNameLabel(): string;
|
|
734
|
-
/**
|
|
735
|
-
* Gets the localized label for the account number field.
|
|
736
|
-
*
|
|
737
|
-
* @override
|
|
738
|
-
* @returns {string} Always returns "Bank Acc. No." for bank contacts
|
|
739
|
-
*/
|
|
740
435
|
get accountNumberLabel(): string;
|
|
741
|
-
/**
|
|
742
|
-
* Gets the localized label for the channel field.
|
|
743
|
-
*
|
|
744
|
-
* @override
|
|
745
|
-
* @returns {string} Always returns "Bank" for bank contacts
|
|
746
|
-
*/
|
|
747
436
|
get channelLabel(): string;
|
|
748
|
-
/**
|
|
749
|
-
* Gets the bank's SWIFT code as the channel identifier.
|
|
750
|
-
* This is the programmatic identifier used for bank transfers and API calls.
|
|
751
|
-
*
|
|
752
|
-
* @returns {BankSwiftCode} The bank's SWIFT/BIC code (e.g., "CORUTZTZ", "KCBLKENX")
|
|
753
|
-
*
|
|
754
|
-
* @example
|
|
755
|
-
* ```typescript
|
|
756
|
-
* const contact = new BankContactInfo("John", crdBank, "123456789");
|
|
757
|
-
* console.log(contact.channelId); // "CORUTZTZ"
|
|
758
|
-
*
|
|
759
|
-
* // Type-safe usage
|
|
760
|
-
* if (contact.channelId === "CORUTZTZ") {
|
|
761
|
-
* console.log("This is a CRDB Bank account");
|
|
762
|
-
* }
|
|
763
|
-
* ```
|
|
764
|
-
*/
|
|
765
437
|
get channelId(): BankSwiftCode;
|
|
766
|
-
/**
|
|
767
|
-
* Gets the bank's short name for display purposes.
|
|
768
|
-
* Provides a human-readable identifier for the banking institution.
|
|
769
|
-
*
|
|
770
|
-
* @returns {string} The bank's abbreviated name (e.g., "CRDB", "KCB", "Equity")
|
|
771
|
-
*
|
|
772
|
-
* @example
|
|
773
|
-
* ```typescript
|
|
774
|
-
* const crdContact = new BankContactInfo("John", crdBank, "123456789");
|
|
775
|
-
* console.log(crdContact.channelName); // "CRDB"
|
|
776
|
-
*
|
|
777
|
-
* const kcbContact = new BankContactInfo("Jane", kcbBank, "987654321");
|
|
778
|
-
* console.log(kcbContact.channelName); // "KCB"
|
|
779
|
-
* ```
|
|
780
|
-
*
|
|
781
|
-
* @remarks
|
|
782
|
-
* The short name is maintained by the Bank service and represents
|
|
783
|
-
* the commonly used abbreviation for the banking institution.
|
|
784
|
-
*/
|
|
785
438
|
get channelName(): string;
|
|
786
439
|
}
|
|
787
440
|
/**
|
|
788
441
|
* Union type representing either a mobile or bank contact.
|
|
789
|
-
* Used for type-safe handling of contact information throughout the application.
|
|
790
|
-
*
|
|
791
|
-
* This discriminated union allows for:
|
|
792
|
-
* - **Type-safe polymorphism**: Handle different contact types with single interface
|
|
793
|
-
* - **Runtime type discrimination**: Use `contact.type` to determine specific type
|
|
794
|
-
* - **Comprehensive validation**: Each type provides its own validation logic
|
|
795
|
-
* - **Consistent API**: Both types implement BaseContactInfo interface
|
|
796
|
-
* - **Country code access**: Always available via contact.countryCode (derived from domain objects)
|
|
797
442
|
*
|
|
798
443
|
* @typedef {MobileContactInfo | BankContactInfo} ContactInfo
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* ```typescript
|
|
802
|
-
* // Type-safe handling of mixed contact types
|
|
803
|
-
* function processContact(contact: ContactInfo) {
|
|
804
|
-
* console.log(`Processing ${contact.type} contact: ${contact.accountName}`);
|
|
805
|
-
* console.log(`Channel: ${contact.channelName}`);
|
|
806
|
-
* console.log(`Country: ${contact.countryCode}`); // Always available
|
|
807
|
-
*
|
|
808
|
-
* // Type discrimination for specific behavior
|
|
809
|
-
* if (contact.type === "Mobile") {
|
|
810
|
-
* // TypeScript knows this is MobileContactInfo
|
|
811
|
-
* console.log(`MNO: ${contact.mnoId}`);
|
|
812
|
-
* console.log(`Phone: ${contact.phoneNumber.e164Format}`);
|
|
813
|
-
* } else {
|
|
814
|
-
* // TypeScript knows this is BankContactInfo
|
|
815
|
-
* console.log(`Bank: ${contact.bank.fullName}`);
|
|
816
|
-
* console.log(`SWIFT: ${contact.bank.swiftCode}`);
|
|
817
|
-
* }
|
|
818
|
-
* }
|
|
819
|
-
*
|
|
820
|
-
* // Usage with arrays
|
|
821
|
-
* const contacts: ContactInfo[] = [
|
|
822
|
-
* new MobileContactInfo("John", phoneNumber, TZMNOId.VODACOM),
|
|
823
|
-
* new BankContactInfo("Jane", bank, "123456789")
|
|
824
|
-
* ];
|
|
825
|
-
*
|
|
826
|
-
* contacts.forEach(processContact);
|
|
827
|
-
*
|
|
828
|
-
* // Type guards work seamlessly
|
|
829
|
-
* const mobileContacts = contacts.filter((c): c is MobileContactInfo => c.type === "Mobile");
|
|
830
|
-
* const bankContacts = contacts.filter((c): c is BankContactInfo => c.type === "Bank");
|
|
831
|
-
* ```
|
|
832
|
-
*
|
|
833
|
-
* @see {@link MobileContactInfo} For mobile money contact implementation
|
|
834
|
-
* @see {@link BankContactInfo} For bank transfer contact implementation
|
|
835
|
-
* @see {@link BaseContactInfo} For common interface and behavior
|
|
836
444
|
*/
|
|
837
445
|
export type ContactInfo = MobileContactInfo | BankContactInfo;
|
|
838
446
|
export {};
|