@temboplus/afloat 0.1.11 → 0.1.13

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 (38) hide show
  1. package/README.md +120 -2
  2. package/esm/src/features/auth/manager.d.ts +9 -1
  3. package/esm/src/features/auth/manager.d.ts.map +1 -1
  4. package/esm/src/features/auth/manager.js +20 -3
  5. package/esm/src/features/contact/repository.d.ts +12 -1
  6. package/esm/src/features/contact/repository.d.ts.map +1 -1
  7. package/esm/src/features/contact/repository.js +25 -11
  8. package/esm/src/features/files-gen/repository.d.ts +4 -1
  9. package/esm/src/features/files-gen/repository.d.ts.map +1 -1
  10. package/esm/src/features/files-gen/repository.js +10 -3
  11. package/esm/src/features/payout/repository.d.ts +6 -1
  12. package/esm/src/features/payout/repository.d.ts.map +1 -1
  13. package/esm/src/features/payout/repository.js +12 -7
  14. package/esm/src/features/wallet/repository.d.ts +8 -1
  15. package/esm/src/features/wallet/repository.d.ts.map +1 -1
  16. package/esm/src/features/wallet/repository.js +17 -8
  17. package/esm/src/shared/base_repository.d.ts +25 -1
  18. package/esm/src/shared/base_repository.d.ts.map +1 -1
  19. package/esm/src/shared/base_repository.js +57 -6
  20. package/package.json +1 -1
  21. package/script/src/features/auth/manager.d.ts +9 -1
  22. package/script/src/features/auth/manager.d.ts.map +1 -1
  23. package/script/src/features/auth/manager.js +21 -4
  24. package/script/src/features/contact/repository.d.ts +12 -1
  25. package/script/src/features/contact/repository.d.ts.map +1 -1
  26. package/script/src/features/contact/repository.js +31 -17
  27. package/script/src/features/files-gen/repository.d.ts +4 -1
  28. package/script/src/features/files-gen/repository.d.ts.map +1 -1
  29. package/script/src/features/files-gen/repository.js +10 -3
  30. package/script/src/features/payout/repository.d.ts +6 -1
  31. package/script/src/features/payout/repository.d.ts.map +1 -1
  32. package/script/src/features/payout/repository.js +12 -7
  33. package/script/src/features/wallet/repository.d.ts +8 -1
  34. package/script/src/features/wallet/repository.d.ts.map +1 -1
  35. package/script/src/features/wallet/repository.js +17 -8
  36. package/script/src/shared/base_repository.d.ts +25 -1
  37. package/script/src/shared/base_repository.d.ts.map +1 -1
  38. package/script/src/shared/base_repository.js +57 -6
package/README.md CHANGED
@@ -8,7 +8,7 @@ This JavaScript/TypeScript package provides a central hub for shared utilities,
8
8
 
9
9
  * **Abstracted Server Communication**
10
10
  * Simplifies front-end development by abstracting all interactions with the server behind model-specific repositories
11
- * Front-end projects only need to interact with these repositories, decoupling them from the underlying API implementation
11
+ * Consuming projects only need to interact with these repositories, decoupling them from the underlying API implementation
12
12
 
13
13
  * **Shared Utilities**
14
14
  * Provides a collection of reusable helper functions for common tasks across Afloat projects, such as error handling
@@ -18,4 +18,122 @@ This JavaScript/TypeScript package provides a central hub for shared utilities,
18
18
 
19
19
  * **Enhanced Maintainability**
20
20
  * Centralizes common logic, making it easier to maintain and update across all consuming projects
21
- * Reduces code duplication and improves consistency
21
+ * Reduces code duplication and improves consistency
22
+
23
+ * **Cross-Environment Compatibility**
24
+ * Works seamlessly in both client-side and server-side environments
25
+ * Supports both synchronous and asynchronous initialization patterns
26
+
27
+ ## Usage
28
+
29
+ ### Authentication Setup
30
+
31
+ #### Client-Side Usage
32
+
33
+ In client-side applications, authentication is initialized synchronously:
34
+
35
+ ```typescript
36
+ import { AfloatAuth } from "@temboplus/afloat";
37
+
38
+ // Initialize client auth (typically in your app entry point)
39
+ const auth = AfloatAuth.instance;
40
+
41
+ // Check if user is authenticated
42
+ console.log("User authenticated:", !!auth.currentUser);
43
+
44
+ // Access current user
45
+ const user = auth.currentUser;
46
+ if (user) {
47
+ console.log(`Logged in as: ${user.email}`);
48
+ }
49
+ ```
50
+
51
+ #### Server-Side Usage
52
+
53
+ In server-side environments, authentication requires asynchronous initialization:
54
+
55
+ ```typescript
56
+ import { AfloatAuth } from "@temboplus/afloat";
57
+
58
+ // In a server route handler or similar context
59
+ async function handleRequest(req, res) {
60
+ try {
61
+ // Extract token from request
62
+ const token = req.headers.authorization?.replace('Bearer ', '');
63
+
64
+ if (!token) {
65
+ return res.status(401).json({ error: 'Unauthorized' });
66
+ }
67
+
68
+ // Initialize server-side auth
69
+ const auth = await AfloatAuth.initializeServer(token);
70
+
71
+ // Now you can use auth for permission checks
72
+ const isAdmin = auth.checkPermission(Permissions.Payout.View);
73
+
74
+ // Continue with your handler logic...
75
+ } catch (error) {
76
+ console.error('Authentication error:', error);
77
+ return res.status(500).json({ error: 'Authentication failed' });
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### Using Repositories
83
+
84
+ Repositories provide a consistent interface for data operations across environments.
85
+
86
+ #### Client-Side Repository Usage
87
+
88
+ ```typescript
89
+ import { WalletRepo } from "@temboplus/afloat";
90
+
91
+ // Create repository - auth is automatically handled
92
+ const walletRepo = new WalletRepo();
93
+
94
+ // Use repository methods
95
+ async function displayBalance() {
96
+ try {
97
+ const balance = await walletRepo.getBalance();
98
+ console.log(`Current balance: ${balance}`);
99
+ } catch (error) {
100
+ console.error('Error fetching balance:', error);
101
+ }
102
+ }
103
+ ```
104
+
105
+ #### Server-Side Repository Usage
106
+
107
+ ```typescript
108
+ import { AfloatAuth, WalletRepo } from "@temboplus/afloat";
109
+
110
+ async function processServerRequest(token) {
111
+ // Initialize auth for this request
112
+ const auth = await AfloatAuth.initializeServer(token);
113
+
114
+ // Create repository with explicit auth instance
115
+ const walletRepo = new WalletRepo({ auth });
116
+
117
+ // Use repository methods
118
+ const balance = await walletRepo.getBalance();
119
+ const wallets = await walletRepo.getWallets();
120
+
121
+ return { balance, wallets };
122
+ }
123
+ ```
124
+
125
+ ## Best Practices
126
+
127
+ 1. **Client-Side Applications**
128
+ - Initialize `AfloatAuth.instance` early in your application lifecycle
129
+ - Create repositories without explicit auth parameters
130
+ - Handle permission errors appropriately in your UI
131
+
132
+ 2. **Server-Side Applications**
133
+ - Always use `await AfloatAuth.initializeServer(token)` for each request
134
+ - Pass the auth instance explicitly to repositories
135
+ - Implement proper error handling for authentication failures
136
+
137
+ 3. **Testing**
138
+ - Use the `AuthContext` to inject mock auth instances during testing
139
+ - Reset `AuthContext.current` after each test to prevent test pollution
@@ -1,5 +1,13 @@
1
1
  import type { User } from "../../models/index.js";
2
2
  import type { Permission } from "../../models/permission.js";
3
+ /**
4
+ * Global context to hold the current auth instance reference.
5
+ * This provides a way to access the auth instance across the application
6
+ * without directly coupling to the singleton pattern.
7
+ */
8
+ export declare const AuthContext: {
9
+ current: AfloatAuth | undefined;
10
+ };
3
11
  /**
4
12
  * Main authentication class that works in both client and server environments.
5
13
  * Provides authentication functionality and user management.
@@ -12,7 +20,7 @@ export declare class AfloatAuth {
12
20
  /** client AfloatAuth instance */
13
21
  private static _instance;
14
22
  /**
15
- * Private constructor to prevent direct instantiation.
23
+ * Private constructor to maintain control over instantiation.
16
24
  * @param {AuthStore} store - The auth store implementation to use
17
25
  * @param {TokenHandler} tokenHandler - The token handler implementation to use
18
26
  */
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAU7D;;;GAGG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,OAAO,CAAC,KAAK,CAAY;IAEzB,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAe;IAEnC,iCAAiC;IACjC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2B;IACnD;;;;OAIG;IACH,OAAO;IAKP;;;;;;;;;;;;OAYG;IACH,WAAkB,QAAQ,IAAI,UAAU,CAKvC;IAED;;;;;;;OAOG;WACiB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBxE;;;;OAIG;IACH,OAAO,KAAK,IAAI,GAEf;IAED;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;OAGG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AAG,SAAS,CAElC;IAED;;;;OAIG;IACH,cAAc,IAAI,IAAI,GAAG,SAAS;IAIlC;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAI1C;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3D;;;;;;OAMG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMvE;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,OAAO,CAAC,cAAc;CAIvB"}
@@ -3,13 +3,22 @@ import { createClientStore, useClientUser, } from "./storage/client_store.js";
3
3
  import { ClientTokenHandler } from "./storage/client_token_handler.js";
4
4
  import { ServerStore } from "./storage/server_store.js";
5
5
  import { ServerTokenHandler } from "./storage/server_token_handler.js";
6
+ /**
7
+ * Global context to hold the current auth instance reference.
8
+ * This provides a way to access the auth instance across the application
9
+ * without directly coupling to the singleton pattern.
10
+ */
11
+ export const AuthContext = {
12
+ // Default undefined state - will be set during initialization
13
+ current: undefined,
14
+ };
6
15
  /**
7
16
  * Main authentication class that works in both client and server environments.
8
17
  * Provides authentication functionality and user management.
9
18
  */
10
19
  export class AfloatAuth {
11
20
  /**
12
- * Private constructor to prevent direct instantiation.
21
+ * Private constructor to maintain control over instantiation.
13
22
  * @param {AuthStore} store - The auth store implementation to use
14
23
  * @param {TokenHandler} tokenHandler - The token handler implementation to use
15
24
  */
@@ -45,7 +54,12 @@ export class AfloatAuth {
45
54
  * const serverAuth = await AfloatAuth.initializeServer(token);
46
55
  */
47
56
  static get instance() {
48
- return AfloatAuth._instance || (AfloatAuth._instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance));
57
+ if (!AfloatAuth._instance) {
58
+ AfloatAuth._instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance);
59
+ // Set as current instance for global access
60
+ AuthContext.current = AfloatAuth._instance;
61
+ }
62
+ return AfloatAuth._instance;
49
63
  }
50
64
  /**
51
65
  * Creates a new server-side instance of AfloatAuth.
@@ -66,7 +80,10 @@ export class AfloatAuth {
66
80
  const user = await tokenHandler.constructUser();
67
81
  store.setUser(user);
68
82
  // Create and initialize auth instance
69
- return new AfloatAuth(store, tokenHandler);
83
+ const auth = new AfloatAuth(store, tokenHandler);
84
+ // Set as current instance for global access
85
+ AuthContext.current = auth;
86
+ return auth;
70
87
  }
71
88
  catch (error) {
72
89
  if (error instanceof Error) {
@@ -1,6 +1,7 @@
1
1
  import { BaseRepository } from "../../shared/base_repository.js";
2
2
  import { contract } from "./contract.js";
3
3
  import { Contact, type ContactInput } from "../../models/contact/index.js";
4
+ import type { AfloatAuth } from "../auth/manager.js";
4
5
  /**
5
6
  * Repository class for managing `Contact` data through API interactions.
6
7
  * Extends the `BaseRepository` to leverage shared functionality.
@@ -8,12 +9,19 @@ import { Contact, type ContactInput } from "../../models/contact/index.js";
8
9
  export declare class ContactRepository extends BaseRepository<typeof contract> {
9
10
  /**
10
11
  * Creates an instance of `ContactRepository` using the contact contract.
12
+ * @param {Object} [props] - Optional constructor properties
13
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
14
+ * @param {string} [props.root] - Optional API root URL
11
15
  */
12
- constructor();
16
+ constructor(props?: {
17
+ auth?: AfloatAuth;
18
+ root?: string;
19
+ });
13
20
  /**
14
21
  * Creates a new contact record.
15
22
  * @param {ContactInput} input - The data required to create a new contact.
16
23
  * @returns {Promise<Contact>} A promise that resolves to the newly created contact.
24
+ * @throws {PermissionError} If the user lacks required permissions
17
25
  * @throws {APIError} If the response status code is not 201.
18
26
  */
19
27
  create(input: ContactInput): Promise<Contact>;
@@ -22,6 +30,7 @@ export declare class ContactRepository extends BaseRepository<typeof contract> {
22
30
  * @param {string} id - The unique identifier of the contact to edit.
23
31
  * @param {ContactInput} input - The data to update the contact with.
24
32
  * @returns {Promise<Contact>} A promise that resolves to the updated contact.
33
+ * @throws {PermissionError} If the user lacks required permissions
25
34
  * @throws {APIError} If the response status code is not 200.
26
35
  */
27
36
  edit(id: string, input: ContactInput): Promise<Contact>;
@@ -29,6 +38,7 @@ export declare class ContactRepository extends BaseRepository<typeof contract> {
29
38
  * Deletes a contact record by ID.
30
39
  * @param {string} id - The unique identifier of the contact to remove.
31
40
  * @returns {Promise<void>} A promise that resolves when the deletion is complete.
41
+ * @throws {PermissionError} If the user lacks required permissions
32
42
  * @throws {APIError} If the response status code is not 200.
33
43
  */
34
44
  remove(id: string): Promise<void>;
@@ -37,6 +47,7 @@ export declare class ContactRepository extends BaseRepository<typeof contract> {
37
47
  * Results are ordered in descending order by default.
38
48
  *
39
49
  * @returns {Promise<Contact[]>} A promise that resolves to an array of contacts.
50
+ * @throws {PermissionError} If the user lacks required permissions
40
51
  * @throws {APIError} If the response status code is not 200 or the range is invalid.
41
52
  * @example
42
53
  * const repository = new ContactRepository();
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/contact/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,OAAO,EAEP,KAAK,YAAY,EAClB,MAAM,+BAA+B,CAAC;AAKvC;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IACpE;;OAEG;;IAKH;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAanD;;;;;;OAMG;IACG,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB7D;;;;;OAKG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvC;;;;;;;;;OASG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAanC"}
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/contact/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,OAAO,EAEP,KAAK,YAAY,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IACpE;;;;;OAKG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAIxD;;;;;;OAMG;IACG,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBnD;;;;;;;OAOG;IACG,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB7D;;;;;;OAMG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAevC;;;;;;;;;;OAUG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAgBnC"}
@@ -1,7 +1,6 @@
1
1
  import { BaseRepository } from "../../shared/base_repository.js";
2
2
  import { contract } from "./contract.js";
3
3
  import { Contact, } from "../../models/contact/index.js";
4
- import { AfloatAuth } from "../auth/index.js";
5
4
  import { Permissions } from "../../models/index.js";
6
5
  import { PermissionError } from "../../errors/index.js";
7
6
  /**
@@ -11,21 +10,27 @@ import { PermissionError } from "../../errors/index.js";
11
10
  export class ContactRepository extends BaseRepository {
12
11
  /**
13
12
  * Creates an instance of `ContactRepository` using the contact contract.
13
+ * @param {Object} [props] - Optional constructor properties
14
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
15
+ * @param {string} [props.root] - Optional API root URL
14
16
  */
15
- constructor() {
16
- super("contact", contract);
17
+ constructor(props) {
18
+ super("contact", contract, props);
17
19
  }
18
20
  /**
19
21
  * Creates a new contact record.
20
22
  * @param {ContactInput} input - The data required to create a new contact.
21
23
  * @returns {Promise<Contact>} A promise that resolves to the newly created contact.
24
+ * @throws {PermissionError} If the user lacks required permissions
22
25
  * @throws {APIError} If the response status code is not 201.
23
26
  */
24
27
  async create(input) {
25
- if (!AfloatAuth.instance.checkPermission(Permissions.Contact.Create)) {
28
+ const auth = this.getAuthForPermissionCheck();
29
+ const requiredPerm = Permissions.Contact.Create;
30
+ if (!auth.checkPermission(requiredPerm)) {
26
31
  throw new PermissionError({
27
32
  message: "You are not authorized to add contacts.",
28
- requiredPermissions: [Permissions.Contact.Create],
33
+ requiredPermissions: [requiredPerm],
29
34
  });
30
35
  }
31
36
  const result = await this.client.postContact({ body: input });
@@ -37,13 +42,16 @@ export class ContactRepository extends BaseRepository {
37
42
  * @param {string} id - The unique identifier of the contact to edit.
38
43
  * @param {ContactInput} input - The data to update the contact with.
39
44
  * @returns {Promise<Contact>} A promise that resolves to the updated contact.
45
+ * @throws {PermissionError} If the user lacks required permissions
40
46
  * @throws {APIError} If the response status code is not 200.
41
47
  */
42
48
  async edit(id, input) {
43
- if (!AfloatAuth.instance.checkPermission(Permissions.Contact.Update)) {
49
+ const auth = this.getAuthForPermissionCheck();
50
+ const requiredPerm = Permissions.Contact.Update;
51
+ if (!auth.checkPermission(requiredPerm)) {
44
52
  throw new PermissionError({
45
53
  message: "You are not authorized to update contacts.",
46
- requiredPermissions: [Permissions.Contact.Update],
54
+ requiredPermissions: [requiredPerm],
47
55
  });
48
56
  }
49
57
  const result = await this.client.editContact({
@@ -57,13 +65,16 @@ export class ContactRepository extends BaseRepository {
57
65
  * Deletes a contact record by ID.
58
66
  * @param {string} id - The unique identifier of the contact to remove.
59
67
  * @returns {Promise<void>} A promise that resolves when the deletion is complete.
68
+ * @throws {PermissionError} If the user lacks required permissions
60
69
  * @throws {APIError} If the response status code is not 200.
61
70
  */
62
71
  async remove(id) {
63
- if (!AfloatAuth.instance.checkPermission(Permissions.Contact.Delete)) {
72
+ const auth = this.getAuthForPermissionCheck();
73
+ const requiredPerm = Permissions.Contact.Delete;
74
+ if (!auth.checkPermission(requiredPerm)) {
64
75
  throw new PermissionError({
65
76
  message: "You are not authorized to delete contacts.",
66
- requiredPermissions: [Permissions.Contact.Delete],
77
+ requiredPermissions: [requiredPerm],
67
78
  });
68
79
  }
69
80
  const result = await this.client.deleteContact({ params: { id } });
@@ -74,16 +85,19 @@ export class ContactRepository extends BaseRepository {
74
85
  * Results are ordered in descending order by default.
75
86
  *
76
87
  * @returns {Promise<Contact[]>} A promise that resolves to an array of contacts.
88
+ * @throws {PermissionError} If the user lacks required permissions
77
89
  * @throws {APIError} If the response status code is not 200 or the range is invalid.
78
90
  * @example
79
91
  * const repository = new ContactRepository();
80
92
  * repository.getAll().then(contacts => console.log(contacts));
81
93
  */
82
94
  async getAll() {
83
- if (!AfloatAuth.instance.checkPermission(Permissions.Contact.List)) {
95
+ const auth = this.getAuthForPermissionCheck();
96
+ const requiredPerm = Permissions.Contact.List;
97
+ if (!auth.checkPermission(requiredPerm)) {
84
98
  throw new PermissionError({
85
99
  message: "You are not authorized to view contacts.",
86
- requiredPermissions: [Permissions.Contact.List],
100
+ requiredPermissions: [requiredPerm],
87
101
  });
88
102
  }
89
103
  const query = { orderByDesc: "createdAt" };
@@ -2,6 +2,7 @@ import { contract } from "./contract.js";
2
2
  import { BaseRepository } from "../../shared/index.js";
3
3
  import type { ClientInferRequest, ClientInferResponseBody } from "@ts-rest/core";
4
4
  import type { StatementFile } from "../../models/wallet/index.js";
5
+ import type { AfloatAuth } from "../auth/index.js";
5
6
  /**
6
7
  * Type definition for statement generation input parameters.
7
8
  * Inferred from the contract's genStatementPDF endpoint request body.
@@ -24,7 +25,9 @@ export declare class AfloatFilesRepo extends BaseRepository<typeof contract> {
24
25
  * Creates an instance of AfloatFilesRepo initialized with the files generation contract.
25
26
  * Configures the repository with the PDF maker service endpoint.
26
27
  */
27
- constructor();
28
+ constructor(props?: {
29
+ auth?: AfloatAuth;
30
+ });
28
31
  /**
29
32
  * Generates and downloads a statement PDF based on the provided parameters.
30
33
  * @param {GenStatementInput} body - The statement generation parameters
@@ -1 +1 @@
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;AAElE;;;;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;;IAQH;;;;;;;;;OASG;IACG,iBAAiB,CACrB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAWjE"}
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"}
@@ -11,10 +11,11 @@ export class AfloatFilesRepo extends BaseRepository {
11
11
  * Creates an instance of AfloatFilesRepo initialized with the files generation contract.
12
12
  * Configures the repository with the PDF maker service endpoint.
13
13
  */
14
- constructor() {
14
+ constructor(props) {
15
15
  super("wallet", contract, {
16
- //root: "https://api.afloat.money/pdf-maker/afloat",
17
- root: "http://localhost:3000/afloat"
16
+ root: "https://api.afloat.money/pdf-maker/afloat",
17
+ // root: "http://localhost:3000/afloat",
18
+ auth: props?.auth,
18
19
  });
19
20
  }
20
21
  /**
@@ -32,6 +33,12 @@ export class AfloatFilesRepo extends BaseRepository {
32
33
  if (result.status === 201) {
33
34
  return result.body;
34
35
  }
36
+ if (result.status === 202) {
37
+ throw new APIError({
38
+ message: result.body.message,
39
+ statusCode: 202,
40
+ });
41
+ }
35
42
  throw APIError.unknown("An error occurred while generating statement PDF");
36
43
  }
37
44
  /**
@@ -1,6 +1,7 @@
1
1
  import { BaseRepository } from "../../shared/index.js";
2
2
  import { type PayoutAPI } from "./contract.js";
3
3
  import { type GetPayoutsAPIArgs, type PayoutInput } from "../../models/payout/index.js";
4
+ import type { AfloatAuth } from "../auth/manager.js";
4
5
  import { Payout } from "../../models/payout/derivatives/payout.js";
5
6
  /**
6
7
  * Repository class for managing payout operations including creation, approval,
@@ -10,8 +11,12 @@ import { Payout } from "../../models/payout/derivatives/payout.js";
10
11
  export declare class PayoutRepository extends BaseRepository<PayoutAPI> {
11
12
  /**
12
13
  * Creates an instance of PayoutRepository initialized with the payout contract.
14
+ * @param {Object} [props] - Optional constructor properties
15
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
13
16
  */
14
- constructor();
17
+ constructor(props?: {
18
+ auth?: AfloatAuth;
19
+ });
15
20
  /**
16
21
  * Retrieves a paginated list of payouts with optional filtering for pending status.
17
22
  * @param {GetPayoutsAPIArgs} [args] - Optional arguments for filtering and pagination
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/payout/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAAC,SAAS,CAAC;IAC7D;;OAEG;;IAKH;;;;;;;;;OASG;IACG,MAAM,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAC9C,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACf,C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EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgCrE;;;;;;;;OAQG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CA+BrE"}
@@ -1,7 +1,6 @@
1
1
  import { BaseRepository } from "../../shared/index.js";
2
2
  import { contract } from "./contract.js";
3
3
  import { PAYOUT_APPROVAL_STATUS, } from "../../models/payout/index.js";
4
- import { AfloatAuth } from "../auth/manager.js";
5
4
  import { Permissions } from "../../models/permission.js";
6
5
  import { APIError, PermissionError } from "../../errors/index.js";
7
6
  import { Payout } from "../../models/payout/derivatives/payout.js";
@@ -13,9 +12,11 @@ import { Payout } from "../../models/payout/derivatives/payout.js";
13
12
  export class PayoutRepository extends BaseRepository {
14
13
  /**
15
14
  * Creates an instance of PayoutRepository initialized with the payout contract.
15
+ * @param {Object} [props] - Optional constructor properties
16
+ * @param {AfloatAuth} [props.auth] - Optional auth instance to use
16
17
  */
17
- constructor() {
18
- super("payout", contract);
18
+ constructor(props) {
19
+ super("payout", contract, { auth: props?.auth });
19
20
  }
20
21
  /**
21
22
  * Retrieves a paginated list of payouts with optional filtering for pending status.
@@ -28,8 +29,9 @@ export class PayoutRepository extends BaseRepository {
28
29
  * @returns {Promise<{results: Payout[]; total: number}>} Paginated payout results and total count
29
30
  */
30
31
  async getAll(args) {
32
+ const auth = this.getAuthForPermissionCheck();
31
33
  const requiredPerm = Permissions.Payout.List;
32
- if (!AfloatAuth.instance.checkPermission(requiredPerm)) {
34
+ if (!auth.checkPermission(requiredPerm)) {
33
35
  throw new PermissionError({
34
36
  message: "You are not authorized to view payouts.",
35
37
  requiredPermissions: [requiredPerm],
@@ -70,8 +72,9 @@ export class PayoutRepository extends BaseRepository {
70
72
  * @returns {Promise<Payout>} The created payout
71
73
  */
72
74
  async pay(input) {
75
+ const auth = this.getAuthForPermissionCheck();
73
76
  const requiredPerm = Permissions.Payout.Create;
74
- if (!AfloatAuth.instance.checkPermission(Permissions.Payout.Create)) {
77
+ if (!auth.checkPermission(requiredPerm)) {
75
78
  throw new PermissionError({
76
79
  message: "You are not authorized to create payouts.",
77
80
  requiredPermissions: [requiredPerm],
@@ -95,8 +98,9 @@ export class PayoutRepository extends BaseRepository {
95
98
  * @returns {Promise<Payout>} The approved payout
96
99
  */
97
100
  async approve(id, args) {
101
+ const auth = this.getAuthForPermissionCheck();
98
102
  const requiredPerm = Permissions.Payout.Approve;
99
- if (!AfloatAuth.instance.checkPermission(requiredPerm)) {
103
+ if (!auth.checkPermission(requiredPerm)) {
100
104
  throw new PermissionError({
101
105
  message: "You are not authorized to approve or reject payouts.",
102
106
  requiredPermissions: [requiredPerm],
@@ -130,8 +134,9 @@ export class PayoutRepository extends BaseRepository {
130
134
  * @returns {Promise<Payout>} The rejected payout
131
135
  */
132
136
  async reject(id, args) {
137
+ const auth = this.getAuthForPermissionCheck();
133
138
  const requiredPerm = Permissions.Payout.Approve;
134
- if (!AfloatAuth.instance.checkPermission(requiredPerm)) {
139
+ if (!auth.checkPermission(requiredPerm)) {
135
140
  throw new PermissionError({
136
141
  message: "You are not authorized to approve or reject payouts.",
137
142
  requiredPermissions: [requiredPerm],
@@ -1,6 +1,7 @@
1
1
  import { BaseRepository } from "../../shared/base_repository.js";
2
2
  import { contract } from "./contract.js";
3
3
  import type { STATEMENT_OUTPUT_TYPE, StatementFile, Wallet, WalletStatementItem } from "../../models/wallet/index.js";
4
+ import type { AfloatAuth } from "../auth/manager.js";
4
5
  /**
5
6
  * Repository class for managing wallet operations including balance checking,
6
7
  * statement generation, and wallet information retrieval.
@@ -9,8 +10,14 @@ import type { STATEMENT_OUTPUT_TYPE, StatementFile, Wallet, WalletStatementItem
9
10
  export declare class WalletRepo extends BaseRepository<typeof contract> {
10
11
  /**
11
12
  * Creates an instance of WalletRepo initialized with the wallet contract.
13
+ * @param {Object} [options] - Optional configuration
14
+ * @param {string} [options.root] - Custom API root URL
15
+ * @param {AfloatAuth} [options.auth] - Auth instance to use
12
16
  */
13
- constructor();
17
+ constructor(props?: {
18
+ root?: string;
19
+ auth?: AfloatAuth;
20
+ });
14
21
  /**
15
22
  * Gets an instance of the file generation repository.
16
23
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,MAAM,EACN,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAMtC;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAC7D;;OAEG;;IAKH;;;;OAIG;IACH,OAAO,KAAK,WAAW,GAEtB;IAED;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAkBnC;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAUrC;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE;YAAE,SAAS,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,IAAI,CAAA;SAAE,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,mBAAmB,EAAE,CAAC;IA0BjC;;;;;;;;;OASG;IACG,YAAY,CAChB,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE;QACL,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;OAIG;I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C,aAAa,CAAC;CAapD"}
@@ -1,7 +1,6 @@
1
1
  import { BaseRepository } from "../../shared/base_repository.js";
2
2
  import { contract } from "./contract.js";
3
3
  import { AfloatFilesRepo } from "../files-gen/repository.js";
4
- import { AfloatAuth } from "../auth/manager.js";
5
4
  import { Permissions } from "../../models/permission.js";
6
5
  import { PermissionError } from "../../errors/index.js";
7
6
  /**
@@ -12,9 +11,15 @@ import { PermissionError } from "../../errors/index.js";
12
11
  export class WalletRepo extends BaseRepository {
13
12
  /**
14
13
  * Creates an instance of WalletRepo initialized with the wallet contract.
14
+ * @param {Object} [options] - Optional configuration
15
+ * @param {string} [options.root] - Custom API root URL
16
+ * @param {AfloatAuth} [options.auth] - Auth instance to use
15
17
  */
16
- constructor() {
17
- super("wallet", contract);
18
+ constructor(props) {
19
+ super("wallet", contract, {
20
+ root: props?.root,
21
+ auth: props?.auth,
22
+ });
18
23
  }
19
24
  /**
20
25
  * Gets an instance of the file generation repository.
@@ -22,7 +27,7 @@ export class WalletRepo extends BaseRepository {
22
27
  * @returns {AfloatFilesRepo} A new instance of AfloatFilesRepo
23
28
  */
24
29
  get fileGenRepo() {
25
- return new AfloatFilesRepo();
30
+ return new AfloatFilesRepo({ auth: this.auth });
26
31
  }
27
32
  /**
28
33
  * Retrieves the current available balance for the wallet.
@@ -31,8 +36,9 @@ export class WalletRepo extends BaseRepository {
31
36
  * @returns {Promise<number>} The available balance amount
32
37
  */
33
38
  async getBalance() {
39
+ const auth = this.getAuthForPermissionCheck();
34
40
  const requirePerm = Permissions.Wallet.ViewBalance;
35
- if (!AfloatAuth.instance.checkPermission(requirePerm)) {
41
+ if (!auth.checkPermission(requirePerm)) {
36
42
  throw new PermissionError({
37
43
  message: "You are not authorized to view the account balance.",
38
44
  requiredPermissions: [requirePerm],
@@ -69,8 +75,9 @@ export class WalletRepo extends BaseRepository {
69
75
  * @returns {Promise<WalletStatementItem[]>} Array of statement items for the specified period
70
76
  */
71
77
  async getStatement(props) {
78
+ const auth = this.getAuthForPermissionCheck();
72
79
  const requirePerm = Permissions.Wallet.ViewStatement;
73
- if (!AfloatAuth.instance.checkPermission(requirePerm)) {
80
+ if (!auth.checkPermission(requirePerm)) {
74
81
  throw new PermissionError({
75
82
  message: "You are not authorized to view the statement.",
76
83
  requiredPermissions: [requirePerm],
@@ -100,8 +107,9 @@ export class WalletRepo extends BaseRepository {
100
107
  * @returns {Promise<StatementFile>} The generated statement file
101
108
  */
102
109
  async genStatement(fileType, props) {
110
+ const auth = this.getAuthForPermissionCheck();
103
111
  const requirePerm = Permissions.Wallet.ViewStatement;
104
- if (!AfloatAuth.instance.checkPermission(requirePerm)) {
112
+ if (!auth.checkPermission(requirePerm)) {
105
113
  throw new PermissionError({
106
114
  message: "You are not authorized to view the statement.",
107
115
  requiredPermissions: [requirePerm],
@@ -120,8 +128,9 @@ export class WalletRepo extends BaseRepository {
120
128
  * @returns {Promise<StatementFile>} The generated PDF file containing wallet details
121
129
  */
122
130
  async genWalletDetailsPDF() {
131
+ const auth = this.getAuthForPermissionCheck();
123
132
  const requirePerm = Permissions.Wallet.ViewBalance;
124
- if (!AfloatAuth.instance.checkPermission(requirePerm)) {
133
+ if (!auth.checkPermission(requirePerm)) {
125
134
  throw new PermissionError({
126
135
  message: "You are not authorized to view the account details.",
127
136
  requiredPermissions: [requirePerm],