@temboplus/afloat 0.1.13 → 0.1.31

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 (145) hide show
  1. package/esm/src/features/auth/access/contract.d.ts +14 -0
  2. package/esm/src/features/auth/access/contract.d.ts.map +1 -0
  3. package/esm/src/features/auth/access/contract.js +14 -0
  4. package/esm/src/features/auth/contract.d.ts +20 -20
  5. package/esm/src/features/auth/contract.js +2 -2
  6. package/esm/src/features/auth/identity/contract.d.ts +0 -7
  7. package/esm/src/features/auth/identity/contract.d.ts.map +1 -1
  8. package/esm/src/features/auth/identity/contract.js +0 -1
  9. package/esm/src/features/auth/identity/repository.d.ts +2 -2
  10. package/esm/src/features/auth/identity/repository.d.ts.map +1 -1
  11. package/esm/src/features/auth/identity/repository.js +5 -5
  12. package/esm/src/features/auth/manager.js +1 -1
  13. package/esm/src/features/auth/profile/contract.d.ts +17 -25
  14. package/esm/src/features/auth/profile/contract.d.ts.map +1 -1
  15. package/esm/src/features/auth/profile/contract.js +2 -4
  16. package/esm/src/features/auth/repository.d.ts +0 -1
  17. package/esm/src/features/auth/repository.d.ts.map +1 -1
  18. package/esm/src/features/auth/repository.js +3 -11
  19. package/esm/src/features/auth/storage/server_token_handler.d.ts +7 -6
  20. package/esm/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
  21. package/esm/src/features/auth/storage/server_token_handler.js +73 -26
  22. package/esm/src/features/contact/contract.d.ts +10 -10
  23. package/esm/src/features/payout/contract.d.ts +16 -16
  24. package/esm/src/features/wallet/contract.d.ts +3 -6
  25. package/esm/src/features/wallet/contract.d.ts.map +1 -1
  26. package/esm/src/features/wallet/repository.d.ts +1 -28
  27. package/esm/src/features/wallet/repository.d.ts.map +1 -1
  28. package/esm/src/features/wallet/repository.js +0 -51
  29. package/esm/src/models/contact/derivatives/contact.js +2 -2
  30. package/esm/src/models/contact/derivatives/contact_info.d.ts +8 -8
  31. package/esm/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
  32. package/esm/src/models/contact/derivatives/contact_info.js +12 -12
  33. package/esm/src/models/payout/channel.d.ts +4 -4
  34. package/esm/src/models/payout/channel.d.ts.map +1 -1
  35. package/esm/src/models/payout/channel.js +10 -3
  36. package/esm/src/models/payout/derivatives/payout.d.ts.map +1 -1
  37. package/esm/src/models/payout/derivatives/payout.js +2 -2
  38. package/esm/src/models/payout/schemas.d.ts +2 -1
  39. package/esm/src/models/payout/schemas.d.ts.map +1 -1
  40. package/esm/src/models/payout/schemas.js +1 -0
  41. package/esm/src/models/payout/status.d.ts +1 -0
  42. package/esm/src/models/payout/status.d.ts.map +1 -1
  43. package/esm/src/models/payout/status.js +1 -0
  44. package/esm/src/models/user/profile.d.ts +135 -12
  45. package/esm/src/models/user/profile.d.ts.map +1 -1
  46. package/esm/src/models/user/profile.js +321 -12
  47. package/esm/src/models/user/user.d.ts +14 -17
  48. package/esm/src/models/user/user.d.ts.map +1 -1
  49. package/esm/src/models/user/user.js +109 -26
  50. package/esm/src/models/wallet/guards.d.ts.map +1 -1
  51. package/esm/src/models/wallet/guards.js +8 -2
  52. package/esm/src/models/wallet/index.d.ts +0 -1
  53. package/esm/src/models/wallet/index.d.ts.map +1 -1
  54. package/esm/src/models/wallet/index.js +0 -1
  55. package/esm/src/models/wallet/schemas.d.ts +1 -2
  56. package/esm/src/models/wallet/schemas.d.ts.map +1 -1
  57. package/esm/src/models/wallet/schemas.js +3 -12
  58. package/esm/src/shared/token_required_repository.d.ts +78 -0
  59. package/esm/src/shared/token_required_repository.d.ts.map +1 -0
  60. package/esm/src/shared/token_required_repository.js +128 -0
  61. package/package.json +7 -7
  62. package/script/src/features/auth/access/contract.d.ts +14 -0
  63. package/script/src/features/auth/access/contract.d.ts.map +1 -0
  64. package/script/src/features/auth/access/contract.js +17 -0
  65. package/script/src/features/auth/contract.d.ts +20 -20
  66. package/script/src/features/auth/contract.js +1 -1
  67. package/script/src/features/auth/identity/contract.d.ts +0 -7
  68. package/script/src/features/auth/identity/contract.d.ts.map +1 -1
  69. package/script/src/features/auth/identity/contract.js +0 -1
  70. package/script/src/features/auth/identity/repository.d.ts +2 -2
  71. package/script/src/features/auth/identity/repository.d.ts.map +1 -1
  72. package/script/src/features/auth/identity/repository.js +5 -5
  73. package/script/src/features/auth/manager.js +1 -1
  74. package/script/src/features/auth/profile/contract.d.ts +17 -25
  75. package/script/src/features/auth/profile/contract.d.ts.map +1 -1
  76. package/script/src/features/auth/profile/contract.js +1 -3
  77. package/script/src/features/auth/repository.d.ts +0 -1
  78. package/script/src/features/auth/repository.d.ts.map +1 -1
  79. package/script/src/features/auth/repository.js +3 -11
  80. package/script/src/features/auth/storage/server_token_handler.d.ts +7 -6
  81. package/script/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
  82. package/script/src/features/auth/storage/server_token_handler.js +72 -25
  83. package/script/src/features/contact/contract.d.ts +10 -10
  84. package/script/src/features/payout/contract.d.ts +16 -16
  85. package/script/src/features/wallet/contract.d.ts +3 -6
  86. package/script/src/features/wallet/contract.d.ts.map +1 -1
  87. package/script/src/features/wallet/repository.d.ts +1 -28
  88. package/script/src/features/wallet/repository.d.ts.map +1 -1
  89. package/script/src/features/wallet/repository.js +0 -51
  90. package/script/src/models/contact/derivatives/contact.js +1 -1
  91. package/script/src/models/contact/derivatives/contact_info.d.ts +8 -8
  92. package/script/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
  93. package/script/src/models/contact/derivatives/contact_info.js +11 -11
  94. package/script/src/models/payout/channel.d.ts +4 -4
  95. package/script/src/models/payout/channel.d.ts.map +1 -1
  96. package/script/src/models/payout/channel.js +10 -3
  97. package/script/src/models/payout/derivatives/payout.d.ts.map +1 -1
  98. package/script/src/models/payout/derivatives/payout.js +1 -1
  99. package/script/src/models/payout/schemas.d.ts +2 -1
  100. package/script/src/models/payout/schemas.d.ts.map +1 -1
  101. package/script/src/models/payout/schemas.js +1 -0
  102. package/script/src/models/payout/status.d.ts +1 -0
  103. package/script/src/models/payout/status.d.ts.map +1 -1
  104. package/script/src/models/payout/status.js +1 -0
  105. package/script/src/models/user/profile.d.ts +135 -12
  106. package/script/src/models/user/profile.d.ts.map +1 -1
  107. package/script/src/models/user/profile.js +323 -13
  108. package/script/src/models/user/user.d.ts +14 -17
  109. package/script/src/models/user/user.d.ts.map +1 -1
  110. package/script/src/models/user/user.js +109 -26
  111. package/script/src/models/wallet/guards.d.ts.map +1 -1
  112. package/script/src/models/wallet/guards.js +8 -2
  113. package/script/src/models/wallet/index.d.ts +0 -1
  114. package/script/src/models/wallet/index.d.ts.map +1 -1
  115. package/script/src/models/wallet/index.js +0 -1
  116. package/script/src/models/wallet/schemas.d.ts +1 -2
  117. package/script/src/models/wallet/schemas.d.ts.map +1 -1
  118. package/script/src/models/wallet/schemas.js +3 -12
  119. package/script/src/shared/token_required_repository.d.ts +78 -0
  120. package/script/src/shared/token_required_repository.d.ts.map +1 -0
  121. package/script/src/shared/token_required_repository.js +132 -0
  122. package/esm/src/features/auth/profile/repository.d.ts +0 -11
  123. package/esm/src/features/auth/profile/repository.d.ts.map +0 -1
  124. package/esm/src/features/auth/profile/repository.js +0 -21
  125. package/esm/src/features/files-gen/contract.d.ts +0 -67
  126. package/esm/src/features/files-gen/contract.d.ts.map +0 -1
  127. package/esm/src/features/files-gen/contract.js +0 -40
  128. package/esm/src/features/files-gen/repository.d.ts +0 -50
  129. package/esm/src/features/files-gen/repository.d.ts.map +0 -1
  130. package/esm/src/features/files-gen/repository.js +0 -56
  131. package/esm/src/models/wallet/statement.d.ts +0 -27
  132. package/esm/src/models/wallet/statement.d.ts.map +0 -1
  133. package/esm/src/models/wallet/statement.js +0 -13
  134. package/script/src/features/auth/profile/repository.d.ts +0 -11
  135. package/script/src/features/auth/profile/repository.d.ts.map +0 -1
  136. package/script/src/features/auth/profile/repository.js +0 -25
  137. package/script/src/features/files-gen/contract.d.ts +0 -67
  138. package/script/src/features/files-gen/contract.d.ts.map +0 -1
  139. package/script/src/features/files-gen/contract.js +0 -43
  140. package/script/src/features/files-gen/repository.d.ts +0 -50
  141. package/script/src/features/files-gen/repository.d.ts.map +0 -1
  142. package/script/src/features/files-gen/repository.js +0 -60
  143. package/script/src/models/wallet/statement.d.ts +0 -27
  144. package/script/src/models/wallet/statement.d.ts.map +0 -1
  145. package/script/src/models/wallet/statement.js +0 -16
@@ -2,19 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WalletSchemas = void 0;
4
4
  const zod_1 = require("zod");
5
- /**
6
- * Helper function to make a field optional with undefined
7
- * Transforms null values to undefined for consistency
8
- * @param schema - The Zod schema to make optional
9
- * @returns A schema that only allows string or undefined (no null)
10
- */
11
- const makeOptional = (schema) => schema.optional().transform((val) => val ?? undefined);
12
5
  /**
13
6
  * Schema definition for a statement entry.
14
7
  * Represents a single transaction in a wallet's statement history.
15
8
  *
16
- * @property {string} accountNo - The account number associated with the transaction (optional)
17
- * @property {string} cbaRefNo - Core banking system reference number (optional)
9
+ * @property {string} accountNo - The account number associated with the transaction
18
10
  * @property {string} debitOrCredit - Indicator if transaction is debit or credit
19
11
  * @property {string} tranRefNo - Transaction reference number
20
12
  * @property {string} narration - Description of the transaction
@@ -25,8 +17,7 @@ const makeOptional = (schema) => schema.optional().transform((val) => val ?? und
25
17
  * @property {number} balance - Running balance after transaction
26
18
  */
27
19
  const statementEntrySchema = zod_1.z.object({
28
- accountNo: makeOptional(zod_1.z.string()),
29
- cbaRefNo: makeOptional(zod_1.z.string()),
20
+ accountNo: zod_1.z.string(),
30
21
  debitOrCredit: zod_1.z.string().min(1, "Transaction type is required"),
31
22
  tranRefNo: zod_1.z.string().min(1, "Transaction reference is required"),
32
23
  narration: zod_1.z.string().min(1, "Transaction description is required"),
@@ -49,7 +40,7 @@ const statementEntrySchema = zod_1.z.object({
49
40
  * @property {string} updatedAt - ISO datetime string of last wallet update
50
41
  */
51
42
  const walletSchema = zod_1.z.object({
52
- id: zod_1.z.string().uuid("Invalid wallet ID format"),
43
+ id: zod_1.z.string().min(1),
53
44
  profileId: zod_1.z.string().min(1, "Profile ID is required"),
54
45
  accountNo: zod_1.z.string().min(1, "Account number is required"),
55
46
  accountName: zod_1.z.string().min(1, "Account name is required"),
@@ -0,0 +1,78 @@
1
+ import { type AppRouter } from "@ts-rest/core";
2
+ import type { InitClientArgs } from "@ts-rest/core";
3
+ /**
4
+ * TokenRequiredRepository
5
+ *
6
+ * A generic base class to build repositories for interacting with the API,
7
+ * without any dependency on AfloatAuth. Instead, it requires token to be
8
+ * explicitly provided when initializing the repository.
9
+ *
10
+ * @template TContract - The API contract extending `AppRouter` from `@ts-rest/core`.
11
+ */
12
+ export declare class TokenRequiredRepository<TContract extends AppRouter> {
13
+ /**
14
+ * A "ts-rest" contract
15
+ *
16
+ * @protected
17
+ */
18
+ protected contract: TContract;
19
+ /**
20
+ * An API endpoint
21
+ *
22
+ * @protected
23
+ */
24
+ protected endpoint: string;
25
+ /**
26
+ * An API Root URL
27
+ *
28
+ * @protected
29
+ */
30
+ protected root: string | undefined;
31
+ /**
32
+ * Authentication token
33
+ *
34
+ * @protected
35
+ */
36
+ protected token: string;
37
+ /**
38
+ * Constructs a new instance of `TokenRequiredRepository`.
39
+ *
40
+ * @param endpoint - API endpoint
41
+ * @param contract - The "ts-rest" contract
42
+ * @param token - Authentication token (required)
43
+ * @param root - Optional API root URL
44
+ */
45
+ constructor(endpoint: string, contract: TContract, token: string, root?: string);
46
+ /**
47
+ * Gets the initialized client for making API requests.
48
+ * Uses the provided authentication token.
49
+ */
50
+ get client(): { [TKey in keyof TContract]: TContract[TKey] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey], InitClientArgs>> : TContract[TKey] extends AppRouter ? TContract[TKey] extends infer T extends AppRouter ? { [TKey_1 in keyof T]: TContract[TKey][TKey_1] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1], InitClientArgs>> : TContract[TKey][TKey_1] extends AppRouter ? TContract[TKey][TKey_1] extends infer T_1 extends AppRouter ? { [TKey_2 in keyof T_1]: TContract[TKey][TKey_1][TKey_2] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2] extends AppRouter ? TContract[TKey][TKey_1][TKey_2] extends infer T_2 extends AppRouter ? { [TKey_3 in keyof T_2]: TContract[TKey][TKey_1][TKey_2][TKey_3] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3] extends infer T_3 extends AppRouter ? { [TKey_4 in keyof T_3]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4] extends infer T_4 extends AppRouter ? { [TKey_5 in keyof T_4]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5] extends infer T_5 extends AppRouter ? { [TKey_6 in keyof T_5]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6] extends infer T_6 extends AppRouter ? { [TKey_7 in keyof T_6]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7] extends infer T_7 extends AppRouter ? { [TKey_8 in keyof T_7]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8] extends infer T_8 extends AppRouter ? { [TKey_9 in keyof T_8]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends AppRouter ? TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9] extends infer T_9 extends AppRouter ? { [TKey_10 in keyof T_9]: TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10] extends import("@ts-rest/core").AppRoute ? import("@ts-rest/core").AppRouteFunction<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10], InitClientArgs, import("@ts-rest/core").PartialClientInferRequest<TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10], InitClientArgs>> : TContract[TKey][TKey_1][TKey_2][TKey_3][TKey_4][TKey_5][TKey_6][TKey_7][TKey_8][TKey_9][TKey_10] extends AppRouter ? any : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; } : never : never; };
51
+ /**
52
+ * Updates the token used by this repository
53
+ *
54
+ * @param token - New authentication token
55
+ */
56
+ setToken(token: string): void;
57
+ /**
58
+ * Gets the current token
59
+ *
60
+ * @returns The current authentication token
61
+ */
62
+ getToken(): string;
63
+ /**
64
+ * Handles the API response by checking the HTTP status code and returning the response body
65
+ * for successful requests or throwing an `APIError` for errors.
66
+ *
67
+ * @template T - The expected type of the successful response body.
68
+ * @param result - The API response object containing the status code and response body.
69
+ * @param successStatusCode - The expected HTTP status code indicating success (e.g., 200, 201).
70
+ * @returns The response body typed as `T` if the status code matches the success criteria.
71
+ * @throws `APIError` - If the status code indicates a failure.
72
+ */
73
+ handleResponse<T>(result: {
74
+ status: number;
75
+ body: unknown;
76
+ }, successStatusCode: number): T;
77
+ }
78
+ //# sourceMappingURL=token_required_repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token_required_repository.d.ts","sourceRoot":"","sources":["../../../src/src/shared/token_required_repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD;;;;;;;;GAQG;AACH,qBAAa,uBAAuB,CAAC,SAAS,SAAS,SAAS;IAC9D;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE9B;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IAExB;;;;;;;OAOG;gBAED,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM;IAQf;;;OAGG;IACH,IAAI,MAAM,k0LAcT;IAED;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,EACd,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,EACzC,iBAAiB,EAAE,MAAM,GACxB,CAAC;CAgBL"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenRequiredRepository = void 0;
4
+ const core_1 = require("@ts-rest/core");
5
+ const api_error_js_1 = require("../errors/api_error.js");
6
+ const uuid_1 = require("uuid");
7
+ /**
8
+ * TokenRequiredRepository
9
+ *
10
+ * A generic base class to build repositories for interacting with the API,
11
+ * without any dependency on AfloatAuth. Instead, it requires token to be
12
+ * explicitly provided when initializing the repository.
13
+ *
14
+ * @template TContract - The API contract extending `AppRouter` from `@ts-rest/core`.
15
+ */
16
+ class TokenRequiredRepository {
17
+ /**
18
+ * Constructs a new instance of `TokenRequiredRepository`.
19
+ *
20
+ * @param endpoint - API endpoint
21
+ * @param contract - The "ts-rest" contract
22
+ * @param token - Authentication token (required)
23
+ * @param root - Optional API root URL
24
+ */
25
+ constructor(endpoint, contract, token, root) {
26
+ /**
27
+ * A "ts-rest" contract
28
+ *
29
+ * @protected
30
+ */
31
+ Object.defineProperty(this, "contract", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ /**
38
+ * An API endpoint
39
+ *
40
+ * @protected
41
+ */
42
+ Object.defineProperty(this, "endpoint", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ /**
49
+ * An API Root URL
50
+ *
51
+ * @protected
52
+ */
53
+ Object.defineProperty(this, "root", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ /**
60
+ * Authentication token
61
+ *
62
+ * @protected
63
+ */
64
+ Object.defineProperty(this, "token", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: void 0
69
+ });
70
+ this.contract = contract;
71
+ this.endpoint = endpoint;
72
+ this.token = token;
73
+ this.root = root;
74
+ }
75
+ /**
76
+ * Gets the initialized client for making API requests.
77
+ * Uses the provided authentication token.
78
+ */
79
+ get client() {
80
+ const baseUrl = this.root
81
+ ? `${this.root}/${this.endpoint}`
82
+ : `https://api.afloat.money/v1/${this.endpoint}`;
83
+ const args = {
84
+ baseUrl,
85
+ baseHeaders: {
86
+ "token": this.token,
87
+ "x-request-id": (0, uuid_1.v4)(),
88
+ },
89
+ };
90
+ return (0, core_1.initClient)(this.contract, args);
91
+ }
92
+ /**
93
+ * Updates the token used by this repository
94
+ *
95
+ * @param token - New authentication token
96
+ */
97
+ setToken(token) {
98
+ this.token = token;
99
+ }
100
+ /**
101
+ * Gets the current token
102
+ *
103
+ * @returns The current authentication token
104
+ */
105
+ getToken() {
106
+ return this.token;
107
+ }
108
+ /**
109
+ * Handles the API response by checking the HTTP status code and returning the response body
110
+ * for successful requests or throwing an `APIError` for errors.
111
+ *
112
+ * @template T - The expected type of the successful response body.
113
+ * @param result - The API response object containing the status code and response body.
114
+ * @param successStatusCode - The expected HTTP status code indicating success (e.g., 200, 201).
115
+ * @returns The response body typed as `T` if the status code matches the success criteria.
116
+ * @throws `APIError` - If the status code indicates a failure.
117
+ */
118
+ handleResponse(result, successStatusCode) {
119
+ if (successStatusCode === result.status) {
120
+ return result.body;
121
+ }
122
+ if (result.status === 400) {
123
+ throw new api_error_js_1.APIError(result.body);
124
+ }
125
+ throw new api_error_js_1.APIError({
126
+ message: "We encountered an error trying to process your request. Please try again later",
127
+ statusCode: 520,
128
+ error: "UNKNOWN ERROR",
129
+ });
130
+ }
131
+ }
132
+ exports.TokenRequiredRepository = TokenRequiredRepository;
@@ -1,11 +0,0 @@
1
- import type { Profile } from "../../../models/index.js";
2
- import { BaseRepository } from "../../../shared/base_repository.js";
3
- import { profileContract } from "./contract.js";
4
- export declare class ProfileRepository extends BaseRepository<typeof profileContract> {
5
- /**
6
- * Initializes an instance of ProfileRepository.
7
- */
8
- constructor();
9
- getCurrentProfile(token: string): Promise<Profile>;
10
- }
11
- //# sourceMappingURL=repository.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/profile/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,OAAO,eAAe,CAAC;IAC3E;;OAEG;;IAKG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAUzD"}
@@ -1,21 +0,0 @@
1
- import { BaseRepository } from "../../../shared/base_repository.js";
2
- import { APIError } from "../../../errors/api_error.js";
3
- import { profileContract } from "./contract.js";
4
- export class ProfileRepository extends BaseRepository {
5
- /**
6
- * Initializes an instance of ProfileRepository.
7
- */
8
- constructor() {
9
- super("profile", profileContract);
10
- }
11
- async getCurrentProfile(token) {
12
- const headers = { token };
13
- const result = await this.client.getCurrentProfile({ headers });
14
- if (result.status === 200)
15
- return result.body;
16
- throw new APIError({
17
- message: "An error occurred while trying to get the current profile",
18
- statusCode: 502,
19
- });
20
- }
21
- }
@@ -1,67 +0,0 @@
1
- import { z } from "zod";
2
- import { STATEMENT_OUTPUT_TYPE } from "../../models/wallet/index.js";
3
- export declare const contract: {
4
- genStatementPDF: {
5
- method: "POST";
6
- body: z.ZodObject<{
7
- end_date: z.ZodDate;
8
- start_date: z.ZodDate;
9
- account_no: z.ZodOptional<z.ZodString>;
10
- return_file_type: z.ZodEnum<[STATEMENT_OUTPUT_TYPE.EXCEL, STATEMENT_OUTPUT_TYPE.PDF]>;
11
- }, "strip", z.ZodTypeAny, {
12
- end_date: Date;
13
- start_date: Date;
14
- return_file_type: STATEMENT_OUTPUT_TYPE;
15
- account_no?: string | undefined;
16
- }, {
17
- end_date: Date;
18
- start_date: Date;
19
- return_file_type: STATEMENT_OUTPUT_TYPE;
20
- account_no?: string | undefined;
21
- }>;
22
- path: "/statement";
23
- responses: {
24
- 201: z.ZodObject<{
25
- file: z.ZodString;
26
- file_extension: z.ZodString;
27
- mime_type: z.ZodString;
28
- }, "strip", z.ZodTypeAny, {
29
- file: string;
30
- file_extension: string;
31
- mime_type: string;
32
- }, {
33
- file: string;
34
- file_extension: string;
35
- mime_type: string;
36
- }>;
37
- 202: z.ZodObject<{
38
- message: z.ZodString;
39
- }, "strip", z.ZodTypeAny, {
40
- message: string;
41
- }, {
42
- message: string;
43
- }>;
44
- };
45
- };
46
- genAccountDetailsPDF: {
47
- method: "POST";
48
- body: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
49
- path: "/account_details";
50
- responses: {
51
- 201: z.ZodObject<{
52
- file: z.ZodString;
53
- file_extension: z.ZodString;
54
- mime_type: z.ZodString;
55
- }, "strip", z.ZodTypeAny, {
56
- file: string;
57
- file_extension: string;
58
- mime_type: string;
59
- }, {
60
- file: string;
61
- file_extension: string;
62
- mime_type: string;
63
- }>;
64
- };
65
- };
66
- };
67
- //# sourceMappingURL=contract.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/src/features/files-gen/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCnB,CAAC"}
@@ -1,40 +0,0 @@
1
- import { z } from "zod";
2
- import { initContract } from "@ts-rest/core";
3
- import { STATEMENT_OUTPUT_TYPE } from "../../models/wallet/index.js";
4
- export const contract = initContract().router({
5
- genStatementPDF: {
6
- method: "POST",
7
- path: "/statement",
8
- body: z.object({
9
- end_date: z.date(),
10
- start_date: z.date(),
11
- account_no: z.string().optional(),
12
- return_file_type: z.enum([
13
- STATEMENT_OUTPUT_TYPE.EXCEL,
14
- STATEMENT_OUTPUT_TYPE.PDF,
15
- ]),
16
- }),
17
- responses: {
18
- 201: z.object({
19
- file: z.string(),
20
- file_extension: z.string(),
21
- mime_type: z.string(),
22
- }),
23
- 202: z.object({
24
- message: z.string(),
25
- }),
26
- },
27
- },
28
- genAccountDetailsPDF: {
29
- method: "POST",
30
- path: "/account_details",
31
- body: z.object({}),
32
- responses: {
33
- 201: z.object({
34
- file: z.string(),
35
- file_extension: z.string(),
36
- mime_type: z.string(),
37
- }),
38
- },
39
- },
40
- });
@@ -1,50 +0,0 @@
1
- import { contract } from "./contract.js";
2
- import { BaseRepository } from "../../shared/index.js";
3
- import type { ClientInferRequest, ClientInferResponseBody } from "@ts-rest/core";
4
- import type { StatementFile } from "../../models/wallet/index.js";
5
- import type { AfloatAuth } from "../auth/index.js";
6
- /**
7
- * Type definition for statement generation input parameters.
8
- * Inferred from the contract's genStatementPDF endpoint request body.
9
- * @typedef {ClientInferRequest<typeof contract.genStatementPDF>["body"]} GenStatementInput
10
- */
11
- type GenStatementInput = ClientInferRequest<typeof contract.genStatementPDF>["body"];
12
- /**
13
- * Type definition for account details response.
14
- * Inferred from the contract's genAccountDetailsPDF endpoint response body.
15
- * @typedef {ClientInferResponseBody<typeof contract.genAccountDetailsPDF>} GenAccountDetailsResponse
16
- */
17
- type GenAccountDetailsResponse = ClientInferResponseBody<typeof contract.genAccountDetailsPDF>;
18
- /**
19
- * Repository class for managing file generation operations including
20
- * statement PDFs and account details documents.
21
- * @extends {BaseRepository<typeof contract>}
22
- */
23
- export declare class AfloatFilesRepo extends BaseRepository<typeof contract> {
24
- /**
25
- * Creates an instance of AfloatFilesRepo initialized with the files generation contract.
26
- * Configures the repository with the PDF maker service endpoint.
27
- */
28
- constructor(props?: {
29
- auth?: AfloatAuth;
30
- });
31
- /**
32
- * Generates and downloads a statement PDF based on the provided parameters.
33
- * @param {GenStatementInput} body - The statement generation parameters
34
- * @param {Date} body.start_date - Start date for the statement period
35
- * @param {Date} body.end_date - End date for the statement period
36
- * @param {string} body.return_file_type - Desired file format for the statement
37
- * @param {string} [body.account_no] - Optional account number to generate statement for
38
- * @throws {APIError} If the statement generation operation fails
39
- * @returns {Promise<StatementFile>} The generated statement file
40
- */
41
- downloadStatement(body: GenStatementInput): Promise<StatementFile>;
42
- /**
43
- * Generates a PDF containing detailed account information.
44
- * @throws {APIError} If the PDF generation operation fails
45
- * @returns {Promise<GenAccountDetailsResponse>} The generated account details PDF
46
- */
47
- genAccountDetailsPDF(): Promise<GenAccountDetailsResponse>;
48
- }
49
- export {};
50
- //# sourceMappingURL=repository.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/files-gen/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,KAAK,iBAAiB,GAAG,kBAAkB,CACzC,OAAO,QAAQ,CAAC,eAAe,CAChC,CAAC,MAAM,CAAC,CAAC;AAEV;;;;GAIG;AACH,KAAK,yBAAyB,GAAG,uBAAuB,CACtD,OAAO,QAAQ,CAAC,oBAAoB,CACrC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAClE;;;OAGG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAQzC;;;;;;;;;OASG;IACG,iBAAiB,CACrB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAWjE"}
@@ -1,56 +0,0 @@
1
- import { contract } from "./contract.js";
2
- import { BaseRepository } from "../../shared/index.js";
3
- import { APIError } from "../../errors/api_error.js";
4
- /**
5
- * Repository class for managing file generation operations including
6
- * statement PDFs and account details documents.
7
- * @extends {BaseRepository<typeof contract>}
8
- */
9
- export class AfloatFilesRepo extends BaseRepository {
10
- /**
11
- * Creates an instance of AfloatFilesRepo initialized with the files generation contract.
12
- * Configures the repository with the PDF maker service endpoint.
13
- */
14
- constructor(props) {
15
- super("wallet", contract, {
16
- root: "https://api.afloat.money/pdf-maker/afloat",
17
- // root: "http://localhost:3000/afloat",
18
- auth: props?.auth,
19
- });
20
- }
21
- /**
22
- * Generates and downloads a statement PDF based on the provided parameters.
23
- * @param {GenStatementInput} body - The statement generation parameters
24
- * @param {Date} body.start_date - Start date for the statement period
25
- * @param {Date} body.end_date - End date for the statement period
26
- * @param {string} body.return_file_type - Desired file format for the statement
27
- * @param {string} [body.account_no] - Optional account number to generate statement for
28
- * @throws {APIError} If the statement generation operation fails
29
- * @returns {Promise<StatementFile>} The generated statement file
30
- */
31
- async downloadStatement(body) {
32
- const result = await this.client.genStatementPDF({ body });
33
- if (result.status === 201) {
34
- return result.body;
35
- }
36
- if (result.status === 202) {
37
- throw new APIError({
38
- message: result.body.message,
39
- statusCode: 202,
40
- });
41
- }
42
- throw APIError.unknown("An error occurred while generating statement PDF");
43
- }
44
- /**
45
- * Generates a PDF containing detailed account information.
46
- * @throws {APIError} If the PDF generation operation fails
47
- * @returns {Promise<GenAccountDetailsResponse>} The generated account details PDF
48
- */
49
- async genAccountDetailsPDF() {
50
- const result = await this.client.genAccountDetailsPDF();
51
- if (result.status === 201) {
52
- return result.body;
53
- }
54
- throw APIError.unknown("An error occurred while generating account details PDF");
55
- }
56
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Enum representing the supported output formats for statement generation.
3
- * Used to specify the desired file format when requesting statement downloads.
4
- *
5
- * @enum {string}
6
- */
7
- export declare enum STATEMENT_OUTPUT_TYPE {
8
- /** Generate statement as a PDF document */
9
- PDF = "PDF",
10
- /** Generate statement as an Excel spreadsheet */
11
- EXCEL = "EXCEL"
12
- }
13
- /**
14
- * Interface defining the structure of a generated statement file.
15
- * Contains metadata about the file and its content type.
16
- *
17
- * @interface StatementFile
18
- * @property {string} file - Base64 encoded string of the file content or file path
19
- * @property {string} file_extension - File extension (e.g., "pdf", "xlsx") without the dot
20
- * @property {string} mime_type - MIME type of the file (e.g., "application/pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
21
- */
22
- export interface StatementFile {
23
- file: string;
24
- file_extension: string;
25
- mime_type: string;
26
- }
27
- //# sourceMappingURL=statement.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"statement.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/statement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,qBAAqB;IAC/B,2CAA2C;IAC3C,GAAG,QAAQ;IACX,iDAAiD;IACjD,KAAK,UAAU;CAChB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Enum representing the supported output formats for statement generation.
3
- * Used to specify the desired file format when requesting statement downloads.
4
- *
5
- * @enum {string}
6
- */
7
- export var STATEMENT_OUTPUT_TYPE;
8
- (function (STATEMENT_OUTPUT_TYPE) {
9
- /** Generate statement as a PDF document */
10
- STATEMENT_OUTPUT_TYPE["PDF"] = "PDF";
11
- /** Generate statement as an Excel spreadsheet */
12
- STATEMENT_OUTPUT_TYPE["EXCEL"] = "EXCEL";
13
- })(STATEMENT_OUTPUT_TYPE || (STATEMENT_OUTPUT_TYPE = {}));
@@ -1,11 +0,0 @@
1
- import type { Profile } from "../../../models/index.js";
2
- import { BaseRepository } from "../../../shared/base_repository.js";
3
- import { profileContract } from "./contract.js";
4
- export declare class ProfileRepository extends BaseRepository<typeof profileContract> {
5
- /**
6
- * Initializes an instance of ProfileRepository.
7
- */
8
- constructor();
9
- getCurrentProfile(token: string): Promise<Profile>;
10
- }
11
- //# sourceMappingURL=repository.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/profile/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,OAAO,eAAe,CAAC;IAC3E;;OAEG;;IAKG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAUzD"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProfileRepository = void 0;
4
- const base_repository_js_1 = require("../../../shared/base_repository.js");
5
- const api_error_js_1 = require("../../../errors/api_error.js");
6
- const contract_js_1 = require("./contract.js");
7
- class ProfileRepository extends base_repository_js_1.BaseRepository {
8
- /**
9
- * Initializes an instance of ProfileRepository.
10
- */
11
- constructor() {
12
- super("profile", contract_js_1.profileContract);
13
- }
14
- async getCurrentProfile(token) {
15
- const headers = { token };
16
- const result = await this.client.getCurrentProfile({ headers });
17
- if (result.status === 200)
18
- return result.body;
19
- throw new api_error_js_1.APIError({
20
- message: "An error occurred while trying to get the current profile",
21
- statusCode: 502,
22
- });
23
- }
24
- }
25
- exports.ProfileRepository = ProfileRepository;