@temboplus/afloat 0.1.77-beta.8 → 0.1.77-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/auth/auth.contract.d.ts +2 -2
- package/dist/modules/auth/company-membership.model.d.ts +122 -9
- package/dist/modules/auth/user.model.d.ts +238 -15
- package/dist/modules/contact/contact-info.model.d.ts +99 -60
- package/dist/modules/contact/contact.model.d.ts +171 -26
- package/dist/modules/login/login.model.d.ts +53 -23
- package/dist/modules/payout/payout.model.d.ts +242 -2
- package/dist/modules/profile/profile.model.d.ts +65 -30
- package/dist/modules/team-member/role.model.d.ts +49 -1
- package/dist/modules/team-member/team-member.model.d.ts +106 -6
- package/dist/modules/wallet/narration.model.d.ts +34 -38
- package/dist/modules/wallet/statement-entry.model.d.ts +172 -73
- package/dist/modules/wallet/wallet.model.d.ts +56 -19
- package/package.json +2 -2
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
import { ContactDTO, ContactType } from "@/modules/contact/contact.dtos.js";
|
|
2
2
|
import { ContactInfo } from "./contact-info.model.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/**
|
|
5
|
+
* Zod schema for Contact JSON serialization
|
|
6
|
+
* This schema validates the JSON representation of a Contact instance
|
|
7
|
+
*
|
|
8
|
+
* The Contact JSON format wraps the ContactDTO structure for consistency
|
|
9
|
+
* and future extensibility (e.g., adding metadata, version info)
|
|
10
|
+
*/
|
|
11
|
+
export declare const ContactJSONSchema: z.ZodObject<{
|
|
12
|
+
/** The complete contact data transfer object */
|
|
13
|
+
data: z.ZodObject<{
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
profileId: z.ZodString;
|
|
16
|
+
createdAt: z.ZodString;
|
|
17
|
+
updatedAt: z.ZodString;
|
|
18
|
+
} & {
|
|
19
|
+
displayName: z.ZodString;
|
|
20
|
+
accountNo: z.ZodString;
|
|
21
|
+
channel: z.ZodString;
|
|
22
|
+
type: z.ZodNativeEnum<typeof ContactType>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
type: ContactType;
|
|
25
|
+
id: string;
|
|
26
|
+
displayName: string;
|
|
27
|
+
accountNo: string;
|
|
28
|
+
profileId: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
channel: string;
|
|
32
|
+
}, {
|
|
33
|
+
type: ContactType;
|
|
34
|
+
id: string;
|
|
35
|
+
displayName: string;
|
|
36
|
+
accountNo: string;
|
|
37
|
+
profileId: string;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
channel: string;
|
|
41
|
+
}>;
|
|
42
|
+
/** Version for future compatibility */
|
|
43
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
version: string;
|
|
46
|
+
data: {
|
|
47
|
+
type: ContactType;
|
|
48
|
+
id: string;
|
|
49
|
+
displayName: string;
|
|
50
|
+
accountNo: string;
|
|
51
|
+
profileId: string;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
updatedAt: string;
|
|
54
|
+
channel: string;
|
|
55
|
+
};
|
|
56
|
+
}, {
|
|
57
|
+
data: {
|
|
58
|
+
type: ContactType;
|
|
59
|
+
id: string;
|
|
60
|
+
displayName: string;
|
|
61
|
+
accountNo: string;
|
|
62
|
+
profileId: string;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
updatedAt: string;
|
|
65
|
+
channel: string;
|
|
66
|
+
};
|
|
67
|
+
version?: string | undefined;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Infer the ContactJSON type from the schema
|
|
71
|
+
*/
|
|
72
|
+
export type ContactJSON = z.infer<typeof ContactJSONSchema>;
|
|
3
73
|
/**
|
|
4
74
|
* Contact class that wraps the Zod schema and provides additional functionality.
|
|
5
75
|
* Represents a contact entity with validation and type-safe access to contact information.
|
|
@@ -199,23 +269,6 @@ export declare class Contact {
|
|
|
199
269
|
* ```
|
|
200
270
|
*/
|
|
201
271
|
static createSafe(data: ContactDTO): Contact | null;
|
|
202
|
-
/**
|
|
203
|
-
* Creates a Contact instance from a JSON string.
|
|
204
|
-
*
|
|
205
|
-
* @static
|
|
206
|
-
* @param {string} jsonString - JSON string containing contact data
|
|
207
|
-
* @returns {Contact | undefined} Contact instance or undefined if parsing/validation fails
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```typescript
|
|
211
|
-
* const jsonString = '{"id":"123","displayName":"John Doe",...}';
|
|
212
|
-
* const contact = Contact.fromJSON(jsonString);
|
|
213
|
-
* if (contact) {
|
|
214
|
-
* console.log(contact.displayName);
|
|
215
|
-
* }
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
static fromJSON(jsonString: string): Contact | undefined;
|
|
219
272
|
/**
|
|
220
273
|
* Checks if an unknown value contains valid data to construct a Contact instance.
|
|
221
274
|
* This is useful when validating raw data structures before instantiation.
|
|
@@ -268,29 +321,121 @@ export declare class Contact {
|
|
|
268
321
|
*/
|
|
269
322
|
static is(obj: unknown): obj is Contact;
|
|
270
323
|
/**
|
|
271
|
-
*
|
|
324
|
+
* Serializes the Contact instance to a JSON-compatible object
|
|
272
325
|
*
|
|
273
|
-
*
|
|
326
|
+
* This method creates a structured representation suitable for storage or transmission.
|
|
327
|
+
* The serialized format includes all contact data and a version identifier for
|
|
328
|
+
* future compatibility.
|
|
329
|
+
*
|
|
330
|
+
* @returns {ContactJSON} JSON-compatible object representation
|
|
274
331
|
*
|
|
275
332
|
* @example
|
|
276
333
|
* ```typescript
|
|
277
334
|
* const contact = Contact.from(contactData);
|
|
278
|
-
* const
|
|
279
|
-
* //
|
|
335
|
+
* const json = contact.toJSON();
|
|
336
|
+
* // { data: { id: "123", displayName: "John", ... }, version: "1.0" }
|
|
337
|
+
*
|
|
338
|
+
* // Store in localStorage
|
|
339
|
+
* localStorage.setItem('contact', JSON.stringify(json));
|
|
280
340
|
* ```
|
|
281
341
|
*/
|
|
282
|
-
|
|
342
|
+
toJSON(): ContactJSON;
|
|
283
343
|
/**
|
|
284
|
-
*
|
|
344
|
+
* Serializes the Contact instance to a JSON string
|
|
285
345
|
*
|
|
286
|
-
*
|
|
346
|
+
* Convenience method that combines toJSON() with JSON.stringify()
|
|
347
|
+
*
|
|
348
|
+
* @returns {string} JSON string representation
|
|
287
349
|
*
|
|
288
350
|
* @example
|
|
289
351
|
* ```typescript
|
|
290
352
|
* const contact = Contact.from(contactData);
|
|
291
|
-
* const jsonString = contact
|
|
353
|
+
* const jsonString = contact.toJSONString();
|
|
292
354
|
* localStorage.setItem('contact', jsonString);
|
|
293
355
|
* ```
|
|
294
356
|
*/
|
|
295
|
-
|
|
357
|
+
toJSONString(): string;
|
|
358
|
+
/**
|
|
359
|
+
* Creates a Contact instance from a JSON-compatible object or string
|
|
360
|
+
*
|
|
361
|
+
* This static method reconstructs a Contact instance from data that was
|
|
362
|
+
* previously serialized using toJSON(). It performs comprehensive validation
|
|
363
|
+
* to ensure data integrity.
|
|
364
|
+
*
|
|
365
|
+
* **Validation Process:**
|
|
366
|
+
* 1. Parses JSON string if provided
|
|
367
|
+
* 2. Validates structure using Zod schema
|
|
368
|
+
* 3. Extracts and validates ContactDTO data
|
|
369
|
+
* 4. Constructs Contact instance with validated data
|
|
370
|
+
*
|
|
371
|
+
* @static
|
|
372
|
+
* @param {ContactJSON | string} json - JSON object or string containing contact data
|
|
373
|
+
* @returns {Contact | undefined} New Contact instance if successful, undefined if parsing/validation fails
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* // From JSON object
|
|
378
|
+
* const json = { data: { id: "123", displayName: "John", ... }, version: "1.0" };
|
|
379
|
+
* const contact = Contact.fromJSON(json);
|
|
380
|
+
*
|
|
381
|
+
* // From JSON string
|
|
382
|
+
* const jsonString = localStorage.getItem('contact');
|
|
383
|
+
* const contact = Contact.fromJSON(jsonString);
|
|
384
|
+
*
|
|
385
|
+
* // With error handling
|
|
386
|
+
* const contact = Contact.fromJSON(jsonString);
|
|
387
|
+
* if (contact) {
|
|
388
|
+
* console.log("Contact restored:", contact.displayName);
|
|
389
|
+
* } else {
|
|
390
|
+
* console.error("Failed to restore contact from JSON");
|
|
391
|
+
* }
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
static fromJSON(json: ContactJSON | string): Contact | undefined;
|
|
395
|
+
/**
|
|
396
|
+
* Creates a Contact instance from a JSON string
|
|
397
|
+
*
|
|
398
|
+
* Convenience method that delegates to fromJSON()
|
|
399
|
+
*
|
|
400
|
+
* @static
|
|
401
|
+
* @param {string} jsonString - JSON string containing contact data
|
|
402
|
+
* @returns {Contact | undefined} New Contact instance if successful, undefined if parsing fails
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const jsonString = '{"data":{"id":"123","displayName":"John",...},"version":"1.0"}';
|
|
407
|
+
* const contact = Contact.fromJSONString(jsonString);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
static fromJSONString(jsonString: string): Contact | undefined;
|
|
411
|
+
/**
|
|
412
|
+
* Type guard to check if an object is a valid ContactJSON using Zod validation
|
|
413
|
+
*
|
|
414
|
+
* This method validates the structure of a JSON object to ensure it contains
|
|
415
|
+
* all required fields and meets the ContactJSON schema requirements.
|
|
416
|
+
*
|
|
417
|
+
* @static
|
|
418
|
+
* @param {unknown} obj - The object to validate
|
|
419
|
+
* @returns {obj is ContactJSON} Type predicate indicating if the object is valid ContactJSON
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* const data = JSON.parse(jsonString);
|
|
424
|
+
*
|
|
425
|
+
* if (Contact.isContactJSON(data)) {
|
|
426
|
+
* // TypeScript now knows data is ContactJSON
|
|
427
|
+
* const contact = Contact.fromJSON(data);
|
|
428
|
+
* } else {
|
|
429
|
+
* console.error("Invalid ContactJSON structure");
|
|
430
|
+
* }
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @remarks
|
|
434
|
+
* Use this method when:
|
|
435
|
+
* - Validating JSON data before deserialization
|
|
436
|
+
* - Implementing type guards in conditional logic
|
|
437
|
+
* - Checking API responses before processing
|
|
438
|
+
* - Validating cached data integrity
|
|
439
|
+
*/
|
|
440
|
+
static isContactJSON(obj: unknown): obj is ContactJSON;
|
|
296
441
|
}
|
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
import { LogInDTO } from "./login.dtos.js";
|
|
2
|
-
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for LogIn JSON serialization
|
|
5
|
+
* This schema validates the JSON representation of a LogIn instance
|
|
6
|
+
*/
|
|
7
|
+
export declare const LogInJSONSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
profileId: z.ZodString;
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
identity: z.ZodString;
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
roleId: z.ZodString;
|
|
14
|
+
isActive: z.ZodBoolean;
|
|
15
|
+
isArchived: z.ZodBoolean;
|
|
16
|
+
resetPassword: z.ZodBoolean;
|
|
17
|
+
createdAt: z.ZodString;
|
|
18
|
+
updatedAt: z.ZodString;
|
|
19
|
+
access: z.ZodArray<z.ZodString, "many">;
|
|
20
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
type: string;
|
|
23
|
+
name: string;
|
|
3
24
|
id: string;
|
|
25
|
+
version: string;
|
|
4
26
|
profileId: string;
|
|
5
|
-
name: string;
|
|
6
27
|
identity: string;
|
|
28
|
+
roleId: string;
|
|
29
|
+
isActive: boolean;
|
|
30
|
+
isArchived: boolean;
|
|
31
|
+
resetPassword: boolean;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
access: string[];
|
|
35
|
+
}, {
|
|
7
36
|
type: string;
|
|
37
|
+
name: string;
|
|
38
|
+
id: string;
|
|
39
|
+
profileId: string;
|
|
40
|
+
identity: string;
|
|
8
41
|
roleId: string;
|
|
9
42
|
isActive: boolean;
|
|
10
43
|
isArchived: boolean;
|
|
@@ -12,7 +45,12 @@ export type LogInJson = {
|
|
|
12
45
|
createdAt: string;
|
|
13
46
|
updatedAt: string;
|
|
14
47
|
access: string[];
|
|
15
|
-
|
|
48
|
+
version?: string | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Infer the LogInJSON type from the schema
|
|
52
|
+
*/
|
|
53
|
+
export type LogInJSON = z.infer<typeof LogInJSONSchema>;
|
|
16
54
|
/**
|
|
17
55
|
* Represents the authenticated user's identity and account information.
|
|
18
56
|
*
|
|
@@ -63,18 +101,6 @@ export declare class LogIn {
|
|
|
63
101
|
* ```
|
|
64
102
|
*/
|
|
65
103
|
static from(dto: LogInDTO): LogIn;
|
|
66
|
-
/**
|
|
67
|
-
* Creates a LogIn instance from a JSON string.
|
|
68
|
-
*
|
|
69
|
-
* @param json - JSON string containing login data
|
|
70
|
-
* @returns A new LogIn instance, or undefined if parsing failed
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* const logIn = LogIn.fromJson('{"id":"abc","name":"John",...}');
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
static fromJson(json: string): LogIn | undefined;
|
|
78
104
|
/**
|
|
79
105
|
* Gets the user's unique identifier.
|
|
80
106
|
*/
|
|
@@ -124,15 +150,19 @@ export declare class LogIn {
|
|
|
124
150
|
*/
|
|
125
151
|
get access(): ReadonlyArray<string>;
|
|
126
152
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
153
|
+
* Serializes the LogIn instance to a JSON-compatible object
|
|
154
|
+
*/
|
|
155
|
+
toJSON(): LogInJSON;
|
|
156
|
+
/**
|
|
157
|
+
* Serializes the LogIn instance to a JSON string
|
|
130
158
|
*/
|
|
131
|
-
|
|
159
|
+
toJSONString(): string;
|
|
132
160
|
/**
|
|
133
|
-
*
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
* Creates a LogIn instance from a JSON-compatible object or string
|
|
162
|
+
*/
|
|
163
|
+
static fromJSON(json: LogInJSON | string): LogIn | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Type guard using Zod schema validation
|
|
136
166
|
*/
|
|
137
|
-
|
|
167
|
+
static isLogInJSON(obj: unknown): obj is LogInJSON;
|
|
138
168
|
}
|
|
@@ -1,6 +1,119 @@
|
|
|
1
1
|
import { PayoutDTO, PayoutStatus, PayoutApprovalStatus, PayoutAuthorizer } from "@/modules/payout/payout.dtos.js";
|
|
2
2
|
import { Amount } from "@temboplus/frontend-core";
|
|
3
3
|
import { ContactInfo } from "../contact/contact-info.model.js";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for Payout JSON serialization
|
|
7
|
+
* This mirrors the PayoutDTO structure but is specifically for JSON serialization
|
|
8
|
+
*/
|
|
9
|
+
export declare const PayoutJSONSchema: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
profileId: z.ZodString;
|
|
12
|
+
payeeName: z.ZodString;
|
|
13
|
+
channel: z.ZodString;
|
|
14
|
+
msisdn: z.ZodString;
|
|
15
|
+
amount: z.ZodNumber;
|
|
16
|
+
currencyCode: z.ZodString;
|
|
17
|
+
countryCode: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
status: z.ZodNativeEnum<typeof PayoutStatus>;
|
|
21
|
+
statusMessage: z.ZodString;
|
|
22
|
+
partnerReference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
createdAt: z.ZodString;
|
|
24
|
+
updatedAt: z.ZodString;
|
|
25
|
+
actionedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
approvalStatus: z.ZodOptional<z.ZodNullable<z.ZodNativeEnum<typeof PayoutApprovalStatus>>>;
|
|
27
|
+
createdBy: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
identity: z.ZodString;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
name: string;
|
|
33
|
+
id: string;
|
|
34
|
+
identity: string;
|
|
35
|
+
}, {
|
|
36
|
+
name: string;
|
|
37
|
+
id: string;
|
|
38
|
+
identity: string;
|
|
39
|
+
}>>>;
|
|
40
|
+
actionedBy: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
identity: z.ZodString;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
name: string;
|
|
46
|
+
id: string;
|
|
47
|
+
identity: string;
|
|
48
|
+
}, {
|
|
49
|
+
name: string;
|
|
50
|
+
id: string;
|
|
51
|
+
identity: string;
|
|
52
|
+
}>>>;
|
|
53
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
status: PayoutStatus;
|
|
56
|
+
id: string;
|
|
57
|
+
version: string;
|
|
58
|
+
profileId: string;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
updatedAt: string;
|
|
61
|
+
description: string;
|
|
62
|
+
channel: string;
|
|
63
|
+
countryCode: string;
|
|
64
|
+
currencyCode: string;
|
|
65
|
+
msisdn: string;
|
|
66
|
+
amount: number;
|
|
67
|
+
payeeName: string;
|
|
68
|
+
statusMessage: string;
|
|
69
|
+
notes?: string | null | undefined;
|
|
70
|
+
partnerReference?: string | null | undefined;
|
|
71
|
+
actionedAt?: string | null | undefined;
|
|
72
|
+
approvalStatus?: PayoutApprovalStatus | null | undefined;
|
|
73
|
+
createdBy?: {
|
|
74
|
+
name: string;
|
|
75
|
+
id: string;
|
|
76
|
+
identity: string;
|
|
77
|
+
} | null | undefined;
|
|
78
|
+
actionedBy?: {
|
|
79
|
+
name: string;
|
|
80
|
+
id: string;
|
|
81
|
+
identity: string;
|
|
82
|
+
} | null | undefined;
|
|
83
|
+
}, {
|
|
84
|
+
status: PayoutStatus;
|
|
85
|
+
id: string;
|
|
86
|
+
profileId: string;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
updatedAt: string;
|
|
89
|
+
description: string;
|
|
90
|
+
channel: string;
|
|
91
|
+
countryCode: string;
|
|
92
|
+
currencyCode: string;
|
|
93
|
+
msisdn: string;
|
|
94
|
+
amount: number;
|
|
95
|
+
payeeName: string;
|
|
96
|
+
statusMessage: string;
|
|
97
|
+
version?: string | undefined;
|
|
98
|
+
notes?: string | null | undefined;
|
|
99
|
+
partnerReference?: string | null | undefined;
|
|
100
|
+
actionedAt?: string | null | undefined;
|
|
101
|
+
approvalStatus?: PayoutApprovalStatus | null | undefined;
|
|
102
|
+
createdBy?: {
|
|
103
|
+
name: string;
|
|
104
|
+
id: string;
|
|
105
|
+
identity: string;
|
|
106
|
+
} | null | undefined;
|
|
107
|
+
actionedBy?: {
|
|
108
|
+
name: string;
|
|
109
|
+
id: string;
|
|
110
|
+
identity: string;
|
|
111
|
+
} | null | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Infer the PayoutJSON type from the schema
|
|
115
|
+
*/
|
|
116
|
+
export type PayoutJSON = z.infer<typeof PayoutJSONSchema>;
|
|
4
117
|
/**
|
|
5
118
|
* Payout class that wraps the Zod schema and provides additional functionality
|
|
6
119
|
*/
|
|
@@ -133,7 +246,134 @@ export declare class Payout {
|
|
|
133
246
|
*/
|
|
134
247
|
static is(obj: unknown): obj is Payout;
|
|
135
248
|
/**
|
|
136
|
-
|
|
249
|
+
* Serializes the Payout instance to a JSON-compatible object
|
|
250
|
+
*
|
|
251
|
+
* Converts all Date objects to ISO strings for proper JSON serialization.
|
|
252
|
+
* The resulting object can be safely stringified and stored or transmitted.
|
|
253
|
+
*
|
|
254
|
+
* @returns {PayoutJSON} A plain object containing all payout data
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const payout = Payout.create(payoutData);
|
|
259
|
+
* const json = payout.toJSON();
|
|
260
|
+
* // {
|
|
261
|
+
* // id: "payout-123",
|
|
262
|
+
* // amount: 50000,
|
|
263
|
+
* // currencyCode: "TZS",
|
|
264
|
+
* // createdAt: "2024-01-15T10:30:00.000Z",
|
|
265
|
+
* // ...
|
|
266
|
+
* // }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
toJSON(): PayoutJSON;
|
|
270
|
+
/**
|
|
271
|
+
* Serializes the Payout instance to a JSON string
|
|
272
|
+
*
|
|
273
|
+
* @returns {string} JSON string representation of the payout
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const payout = Payout.create(payoutData);
|
|
278
|
+
* const jsonString = payout.toJSONString();
|
|
279
|
+
*
|
|
280
|
+
* // Store in localStorage
|
|
281
|
+
* localStorage.setItem('pendingPayout', jsonString);
|
|
282
|
+
*
|
|
283
|
+
* // Or send to server
|
|
284
|
+
* await fetch('/api/cache-payout', {
|
|
285
|
+
* method: 'POST',
|
|
286
|
+
* body: jsonString
|
|
287
|
+
* });
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
toJSONString(): string;
|
|
291
|
+
/**
|
|
292
|
+
* Creates a Payout instance from a JSON-compatible object or string
|
|
293
|
+
*
|
|
294
|
+
* This method reconstructs a Payout instance from data that was previously
|
|
295
|
+
* serialized using toJSON(). It validates the input data using Zod schema
|
|
296
|
+
* and converts ISO date strings back to Date objects.
|
|
297
|
+
*
|
|
298
|
+
* @param {PayoutJSON | string} json - Either a PayoutJSON object or a JSON string
|
|
299
|
+
* @returns {Payout | undefined} A Payout instance if valid, undefined otherwise
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* // From localStorage
|
|
304
|
+
* const stored = localStorage.getItem('pendingPayout');
|
|
305
|
+
* const payout = Payout.fromJSON(stored!);
|
|
306
|
+
*
|
|
307
|
+
* if (payout) {
|
|
308
|
+
* console.log(payout.amount.label); // "TSh 50,000.00"
|
|
309
|
+
* console.log(payout.status); // "PENDING"
|
|
310
|
+
* }
|
|
311
|
+
*
|
|
312
|
+
* // From object
|
|
313
|
+
* const payoutJson = {
|
|
314
|
+
* id: "payout-123",
|
|
315
|
+
* amount: 50000,
|
|
316
|
+
* currencyCode: "TZS",
|
|
317
|
+
* createdAt: "2024-01-15T10:30:00.000Z",
|
|
318
|
+
* ...
|
|
319
|
+
* };
|
|
320
|
+
* const payout = Payout.fromJSON(payoutJson);
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
static fromJSON(json: PayoutJSON | string): Payout | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Type guard using Zod schema validation
|
|
326
|
+
*
|
|
327
|
+
* Checks if an unknown value conforms to the PayoutJSON structure
|
|
328
|
+
* without attempting to create a Payout instance.
|
|
329
|
+
*
|
|
330
|
+
* @param {unknown} obj - The object to validate
|
|
331
|
+
* @returns {boolean} True if the object is a valid PayoutJSON
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const data = JSON.parse(localStorage.getItem('payout'));
|
|
336
|
+
*
|
|
337
|
+
* if (Payout.isPayoutJSON(data)) {
|
|
338
|
+
* const payout = Payout.fromJSON(data);
|
|
339
|
+
* // TypeScript knows data is PayoutJSON here
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
static isPayoutJSON(obj: unknown): obj is PayoutJSON;
|
|
344
|
+
/**
|
|
345
|
+
* Creates multiple Payout instances from a JSON array
|
|
346
|
+
*
|
|
347
|
+
* @param {PayoutJSON[] | string} jsonArray - Array of PayoutJSON objects or JSON string
|
|
348
|
+
* @returns {Payout[]} Array of Payout instances (invalid items are filtered out)
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* // From API response
|
|
353
|
+
* const response = await fetch('/api/payouts');
|
|
354
|
+
* const jsonArray = await response.json();
|
|
355
|
+
* const payouts = Payout.fromJSONArray(jsonArray);
|
|
356
|
+
*
|
|
357
|
+
* // From stored array
|
|
358
|
+
* const stored = localStorage.getItem('recentPayouts');
|
|
359
|
+
* const payouts = Payout.fromJSONArray(stored!);
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
static fromJSONArray(jsonArray: PayoutJSON[] | string): Payout[];
|
|
363
|
+
/**
|
|
364
|
+
* Serializes an array of Payout instances to JSON
|
|
365
|
+
*
|
|
366
|
+
* @param {Payout[]} payouts - Array of Payout instances to serialize
|
|
367
|
+
* @returns {PayoutJSON[]} Array of PayoutJSON objects
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const payouts = [payout1, payout2, payout3];
|
|
372
|
+
* const jsonArray = Payout.toJSONArray(payouts);
|
|
373
|
+
*
|
|
374
|
+
* // Store or transmit
|
|
375
|
+
* localStorage.setItem('recentPayouts', JSON.stringify(jsonArray));
|
|
376
|
+
* ```
|
|
137
377
|
*/
|
|
138
|
-
|
|
378
|
+
static toJSONArray(payouts: Payout[]): PayoutJSON[];
|
|
139
379
|
}
|