@temboplus/afloat 0.2.0-beta.7 → 0.2.0-beta.9
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/beneficiary/beneficiary-info.model.d.ts +81 -42
- package/dist/modules/beneficiary/beneficiary.model.d.ts +11 -2
- package/dist/modules/payout/payout-channel-handler.d.ts +7 -6
- package/dist/modules/wallet/narration.model.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BeneficiaryType, BeneficiaryDTO } from "@/modules/beneficiary/beneficiary.dtos.js";
|
|
2
2
|
import { PayoutDTO } from "@/modules/payout/payout.dtos.js";
|
|
3
|
-
import { Bank,
|
|
4
|
-
import type { BankSwiftCode,
|
|
3
|
+
import { Bank, PhoneNumber } from "@temboplus/frontend-core";
|
|
4
|
+
import type { BankSwiftCode, ISO2CountryCode, MobileMoneyProviderId } from "@temboplus/frontend-core";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const MobileBeneficiaryJSONSchema: z.ZodObject<{
|
|
7
7
|
type: z.ZodLiteral<"Mobile">;
|
|
8
8
|
name: z.ZodString;
|
|
9
9
|
phoneNumber: z.ZodString;
|
|
@@ -22,7 +22,7 @@ export declare const MobileBeneficiaryInfoJSONSchema: z.ZodObject<{
|
|
|
22
22
|
mnoId: string;
|
|
23
23
|
version?: string | undefined;
|
|
24
24
|
}>;
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const BankBeneficiaryJSONSchema: z.ZodObject<{
|
|
26
26
|
type: z.ZodLiteral<"Bank">;
|
|
27
27
|
accName: z.ZodString;
|
|
28
28
|
swiftCode: z.ZodString;
|
|
@@ -44,7 +44,7 @@ export declare const BankBeneficiaryInfoJSONSchema: z.ZodObject<{
|
|
|
44
44
|
accNo: string;
|
|
45
45
|
version?: string | undefined;
|
|
46
46
|
}>;
|
|
47
|
-
export declare const
|
|
47
|
+
export declare const BeneficiaryJSONSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
48
48
|
type: z.ZodLiteral<"Mobile">;
|
|
49
49
|
name: z.ZodString;
|
|
50
50
|
phoneNumber: z.ZodString;
|
|
@@ -84,17 +84,33 @@ export declare const BeneficiaryInfoJSONSchema: z.ZodDiscriminatedUnion<"type",
|
|
|
84
84
|
accNo: string;
|
|
85
85
|
version?: string | undefined;
|
|
86
86
|
}>]>;
|
|
87
|
-
export type
|
|
88
|
-
export type
|
|
89
|
-
export type
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
export type MobileBeneficiaryJSON = z.infer<typeof MobileBeneficiaryJSONSchema>;
|
|
88
|
+
export type BankBeneficiaryJSON = z.infer<typeof BankBeneficiaryJSONSchema>;
|
|
89
|
+
export type BeneficiaryJSON = z.infer<typeof BeneficiaryJSONSchema>;
|
|
90
|
+
export declare class BeneficiaryError extends Error {
|
|
91
|
+
readonly context: {
|
|
92
|
+
phoneNumber?: string;
|
|
93
|
+
countryCode?: ISO2CountryCode;
|
|
94
|
+
mnoId?: string;
|
|
95
|
+
operation?: string;
|
|
96
|
+
};
|
|
97
|
+
constructor(message: string, context?: {
|
|
98
|
+
phoneNumber?: string;
|
|
99
|
+
countryCode?: ISO2CountryCode;
|
|
100
|
+
mnoId?: string;
|
|
101
|
+
operation?: string;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
interface ValidationResult {
|
|
105
|
+
isValid: boolean;
|
|
106
|
+
errors: string[];
|
|
107
|
+
warnings: string[];
|
|
108
|
+
}
|
|
109
|
+
declare abstract class BaseBeneficiary {
|
|
94
110
|
readonly type: BeneficiaryType;
|
|
95
111
|
readonly countryCode: ISO2CountryCode;
|
|
96
|
-
constructor(type: BeneficiaryType, countryCode: ISO2CountryCode);
|
|
97
|
-
abstract get channelId():
|
|
112
|
+
protected constructor(type: BeneficiaryType, countryCode: ISO2CountryCode);
|
|
113
|
+
abstract get channelId(): MobileMoneyProviderId | BankSwiftCode;
|
|
98
114
|
abstract get channelName(): string;
|
|
99
115
|
abstract get accountName(): string;
|
|
100
116
|
abstract get accountNumber(): string;
|
|
@@ -102,54 +118,67 @@ declare abstract class BaseBeneficiaryInfo {
|
|
|
102
118
|
abstract get accountNumberLabel(): string;
|
|
103
119
|
abstract get channelLabel(): string;
|
|
104
120
|
abstract validate(): boolean;
|
|
105
|
-
abstract
|
|
121
|
+
abstract getValidationDetails(): ValidationResult;
|
|
122
|
+
abstract toJSON(): BeneficiaryJSON;
|
|
106
123
|
toJSONString(): string;
|
|
107
124
|
get isMobile(): boolean;
|
|
108
125
|
get isBank(): boolean;
|
|
109
126
|
get displayName(): string;
|
|
110
127
|
}
|
|
111
|
-
|
|
112
|
-
* Mobile beneficiary information implementation.
|
|
113
|
-
*/
|
|
114
|
-
export declare class MobileBeneficiaryInfo extends BaseBeneficiaryInfo {
|
|
128
|
+
export declare class MobileBeneficiaryInfo extends BaseBeneficiary {
|
|
115
129
|
readonly name: string;
|
|
116
130
|
readonly phoneNumber: PhoneNumber;
|
|
117
|
-
readonly mnoId:
|
|
118
|
-
constructor(name: string, phoneNumber: PhoneNumber, mnoId?:
|
|
131
|
+
readonly mnoId: MobileMoneyProviderId;
|
|
132
|
+
constructor(name: string, phoneNumber: PhoneNumber, mnoId?: MobileMoneyProviderId);
|
|
133
|
+
/**
|
|
134
|
+
* For prefix-detectable countries the MNO is always derived from the phone,
|
|
135
|
+
* so any caller-supplied id is intentionally ignored. For explicit-only
|
|
136
|
+
* countries, the supplied id is used as-is (validation happens later).
|
|
137
|
+
*/
|
|
138
|
+
private static resolveMnoId;
|
|
139
|
+
/**
|
|
140
|
+
* Single source of truth for input validity. Used by the constructor,
|
|
141
|
+
* validate(), and getValidationDetails().
|
|
142
|
+
*/
|
|
143
|
+
private static checkInputs;
|
|
144
|
+
/** Picks an MNO from a DTO `channel` field, or auto-detects when supported. */
|
|
145
|
+
private static pickMnoIdFromDTO;
|
|
119
146
|
static from(data: {
|
|
120
147
|
name: string;
|
|
121
148
|
phoneNumber: PhoneNumber;
|
|
122
|
-
mnoId?:
|
|
149
|
+
mnoId?: MobileMoneyProviderId;
|
|
123
150
|
}): MobileBeneficiaryInfo | undefined;
|
|
124
151
|
static fromBeneficiaryDTO(info: BeneficiaryDTO): MobileBeneficiaryInfo | undefined;
|
|
125
152
|
static fromPayoutDTO(info: PayoutDTO): MobileBeneficiaryInfo | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Pure runtime brand check — no rebuilding, no coercion. Use `fromJSON` to
|
|
155
|
+
* upgrade raw JSON shape into an instance.
|
|
156
|
+
*/
|
|
126
157
|
static is(obj: unknown): obj is MobileBeneficiaryInfo;
|
|
127
158
|
validate(): boolean;
|
|
128
|
-
getValidationDetails():
|
|
129
|
-
isValid: boolean;
|
|
130
|
-
errors: string[];
|
|
131
|
-
warnings: string[];
|
|
132
|
-
};
|
|
159
|
+
getValidationDetails(): ValidationResult;
|
|
133
160
|
get accountName(): string;
|
|
134
161
|
get accountNumber(): string;
|
|
135
162
|
get accountNameLabel(): string;
|
|
136
163
|
get accountNumberLabel(): string;
|
|
137
164
|
get channelLabel(): string;
|
|
138
|
-
get channelId():
|
|
165
|
+
get channelId(): MobileMoneyProviderId;
|
|
139
166
|
get channelName(): string;
|
|
140
|
-
toJSON():
|
|
141
|
-
static fromJSON(json:
|
|
142
|
-
static fromJSONString(
|
|
143
|
-
static
|
|
167
|
+
toJSON(): MobileBeneficiaryJSON;
|
|
168
|
+
static fromJSON(json: MobileBeneficiaryJSON | string): MobileBeneficiaryInfo | undefined;
|
|
169
|
+
static fromJSONString(s: string): MobileBeneficiaryInfo | undefined;
|
|
170
|
+
static isJSON(obj: unknown): obj is MobileBeneficiaryJSON;
|
|
144
171
|
}
|
|
145
|
-
|
|
146
|
-
* Bank beneficiary information implementation.
|
|
147
|
-
*/
|
|
148
|
-
export declare class BankBeneficiaryInfo extends BaseBeneficiaryInfo {
|
|
172
|
+
export declare class BankBeneficiaryInfo extends BaseBeneficiary {
|
|
149
173
|
readonly accName: string;
|
|
150
174
|
readonly bank: Bank;
|
|
151
175
|
readonly accNo: string;
|
|
152
176
|
constructor(accName: string, bank: Bank, accNo: string);
|
|
177
|
+
/**
|
|
178
|
+
* Single source of truth for input validity. Used by the constructor,
|
|
179
|
+
* validate(), and getValidationDetails().
|
|
180
|
+
*/
|
|
181
|
+
private static checkInputs;
|
|
153
182
|
static from(data: {
|
|
154
183
|
accName: string;
|
|
155
184
|
bank: Bank;
|
|
@@ -159,6 +188,7 @@ export declare class BankBeneficiaryInfo extends BaseBeneficiaryInfo {
|
|
|
159
188
|
static fromPayoutDTO(info: PayoutDTO): BankBeneficiaryInfo | undefined;
|
|
160
189
|
static is(obj: unknown): obj is BankBeneficiaryInfo;
|
|
161
190
|
validate(): boolean;
|
|
191
|
+
getValidationDetails(): ValidationResult;
|
|
162
192
|
get accountName(): string;
|
|
163
193
|
get accountNumber(): string;
|
|
164
194
|
get accountNameLabel(): string;
|
|
@@ -166,13 +196,22 @@ export declare class BankBeneficiaryInfo extends BaseBeneficiaryInfo {
|
|
|
166
196
|
get channelLabel(): string;
|
|
167
197
|
get channelId(): BankSwiftCode;
|
|
168
198
|
get channelName(): string;
|
|
169
|
-
toJSON():
|
|
170
|
-
static fromJSON(json:
|
|
171
|
-
static fromJSONString(
|
|
172
|
-
static
|
|
199
|
+
toJSON(): BankBeneficiaryJSON;
|
|
200
|
+
static fromJSON(json: BankBeneficiaryJSON | string): BankBeneficiaryInfo | undefined;
|
|
201
|
+
static fromJSONString(s: string): BankBeneficiaryInfo | undefined;
|
|
202
|
+
static isJSON(obj: unknown): obj is BankBeneficiaryJSON;
|
|
173
203
|
}
|
|
204
|
+
export type BeneficiaryInfo = MobileBeneficiaryInfo | BankBeneficiaryInfo;
|
|
174
205
|
/**
|
|
175
|
-
*
|
|
206
|
+
* Top-level entry point for building / recognizing a beneficiary without
|
|
207
|
+
* caring about the variant. Each method dispatches on the discriminator.
|
|
176
208
|
*/
|
|
177
|
-
export
|
|
209
|
+
export declare const BeneficiaryInfo: {
|
|
210
|
+
fromBeneficiaryDTO(info: BeneficiaryDTO): BeneficiaryInfo | undefined;
|
|
211
|
+
fromPayoutDTO(info: PayoutDTO): BeneficiaryInfo | undefined;
|
|
212
|
+
fromJSON(json: BeneficiaryJSON | string): BeneficiaryInfo | undefined;
|
|
213
|
+
fromJSONString(s: string): BeneficiaryInfo | undefined;
|
|
214
|
+
is(obj: unknown): obj is BeneficiaryInfo;
|
|
215
|
+
isJSON(obj: unknown): obj is BeneficiaryJSON;
|
|
216
|
+
};
|
|
178
217
|
export {};
|
|
@@ -93,6 +93,8 @@ export type BeneficiaryJSON = z.infer<typeof BeneficiaryJSONSchema>;
|
|
|
93
93
|
*/
|
|
94
94
|
export declare class Beneficiary {
|
|
95
95
|
private readonly data;
|
|
96
|
+
private _info;
|
|
97
|
+
private _infoComputed;
|
|
96
98
|
/**
|
|
97
99
|
* Private constructor - use static factory methods to create instances.
|
|
98
100
|
*
|
|
@@ -148,6 +150,9 @@ export declare class Beneficiary {
|
|
|
148
150
|
* @remarks
|
|
149
151
|
* For mobile beneficiaries, constructs from phone number.
|
|
150
152
|
* For bank beneficiaries, constructs from SWIFT code and account number.
|
|
153
|
+
*
|
|
154
|
+
* Result is memoised — repeated accesses don't re-parse the phone number or
|
|
155
|
+
* re-resolve the bank.
|
|
151
156
|
*/
|
|
152
157
|
get info(): BeneficiaryInfo | undefined;
|
|
153
158
|
/**
|
|
@@ -275,7 +280,7 @@ export declare class Beneficiary {
|
|
|
275
280
|
*
|
|
276
281
|
* @static
|
|
277
282
|
* @param {unknown} obj - The value containing potential beneficiary data
|
|
278
|
-
* @returns {obj is
|
|
283
|
+
* @returns {obj is BeneficiaryDTO} Type predicate indicating the value is a valid BeneficiaryDTO
|
|
279
284
|
*
|
|
280
285
|
* @example
|
|
281
286
|
* ```typescript
|
|
@@ -288,8 +293,12 @@ export declare class Beneficiary {
|
|
|
288
293
|
*
|
|
289
294
|
* @remarks
|
|
290
295
|
* This method performs strict validation against the {@link BeneficiaryDTO} schema.
|
|
296
|
+
*
|
|
297
|
+
* The predicate narrows to {@link BeneficiaryDTO} (not `Beneficiary`) — what
|
|
298
|
+
* `obj` actually is on success — so callers don't accidentally try to use
|
|
299
|
+
* instance methods like `toJSON()` on a raw DTO.
|
|
291
300
|
*/
|
|
292
|
-
static canConstruct(obj: unknown): obj is
|
|
301
|
+
static canConstruct(obj: unknown): obj is BeneficiaryDTO;
|
|
293
302
|
/**
|
|
294
303
|
* Validates if an unknown value is a Beneficiary instance.
|
|
295
304
|
* This is a runtime type guard that ensures proper object structure and data validity.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Wallet } from "@/modules/wallet/wallet.model.js";
|
|
2
|
-
import { Amount,
|
|
2
|
+
import { Amount, PhoneNumber } from "@temboplus/frontend-core";
|
|
3
|
+
import type { ISO2CountryCode, MobileMoneyProviderId } from "@temboplus/frontend-core";
|
|
3
4
|
import { PayoutChannel, PayoutInputDTO } from "./payout.dtos.js";
|
|
4
5
|
import { BankBeneficiaryInfo, BeneficiaryInfo } from "../beneficiary/beneficiary-info.model.js";
|
|
5
6
|
/**
|
|
@@ -11,17 +12,17 @@ import { BankBeneficiaryInfo, BeneficiaryInfo } from "../beneficiary/beneficiary
|
|
|
11
12
|
*
|
|
12
13
|
* @see {@link PayoutChannelCodeFactory} for functions to generate valid codes
|
|
13
14
|
*/
|
|
14
|
-
export type PayoutChannelCode = `${
|
|
15
|
+
export type PayoutChannelCode = `${ISO2CountryCode}-${string}-B2C`;
|
|
15
16
|
/**
|
|
16
17
|
* Factory for creating standardized payout channel codes
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```ts
|
|
20
21
|
* // Create bank channel code
|
|
21
|
-
* const bankCode = PayoutChannelCodeFactory.forBank(bankContactInfo); // Returns "TZ-BANK-B2C"
|
|
22
|
+
* const bankCode = PayoutChannelCodeFactory.forBank(bankContactInfo, wallet); // Returns "TZ-BANK-B2C"
|
|
22
23
|
*
|
|
23
24
|
* // Create mobile channel code
|
|
24
|
-
* const mobileCode = PayoutChannelCodeFactory.forMobile(phoneNumber); // Returns "TZ-VODACOM-B2C" for Vodacom number
|
|
25
|
+
* const mobileCode = PayoutChannelCodeFactory.forMobile(phoneNumber, mnoId, wallet); // Returns "TZ-VODACOM-B2C" for Vodacom number
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
28
|
declare class PayoutChannelCodeFactory {
|
|
@@ -39,7 +40,7 @@ declare class PayoutChannelCodeFactory {
|
|
|
39
40
|
*
|
|
40
41
|
* @see {@link PhoneNumber} from "@temboplus/frontend-core" for phone number structure
|
|
41
42
|
*/
|
|
42
|
-
static forMobile(phoneNumber: PhoneNumber, mnoId:
|
|
43
|
+
static forMobile(phoneNumber: PhoneNumber, mnoId: MobileMoneyProviderId, wallet: Wallet): PayoutChannelCode;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Factory class for creating payout input DTOs based on channel and contact information
|
|
@@ -52,7 +53,7 @@ declare class PayoutChannelCodeFactory {
|
|
|
52
53
|
* receiver: mobileContactInfo,
|
|
53
54
|
* amount: new Amount(1000),
|
|
54
55
|
* notes: "Payment for services"
|
|
55
|
-
* });
|
|
56
|
+
* }, wallet);
|
|
56
57
|
* ```
|
|
57
58
|
*/
|
|
58
59
|
export declare class PayoutInputFactory {
|
|
@@ -199,8 +199,8 @@ export declare class Narration {
|
|
|
199
199
|
*/
|
|
200
200
|
static is(obj: unknown): obj is Narration;
|
|
201
201
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
* Serializes the Narration instance to a JSON-compatible object
|
|
203
|
+
*/
|
|
204
204
|
toJSON(): NarrationJSON;
|
|
205
205
|
/**
|
|
206
206
|
* Serializes the Narration instance to a JSON string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/afloat",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.9",
|
|
4
4
|
"description": "A foundational library for Temboplus-Afloat projects.",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -58,6 +58,6 @@
|
|
|
58
58
|
"typescript": "^5.9.3"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@temboplus/frontend-core": "^0.
|
|
61
|
+
"@temboplus/frontend-core": "^1.0.1-beta.2"
|
|
62
62
|
}
|
|
63
63
|
}
|