@temboplus/afloat 0.1.11 → 0.1.12

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 (37) hide show
  1. package/esm/src/features/auth/manager.d.ts +9 -1
  2. package/esm/src/features/auth/manager.d.ts.map +1 -1
  3. package/esm/src/features/auth/manager.js +20 -3
  4. package/esm/src/features/contact/repository.d.ts +12 -1
  5. package/esm/src/features/contact/repository.d.ts.map +1 -1
  6. package/esm/src/features/contact/repository.js +25 -11
  7. package/esm/src/features/files-gen/repository.d.ts +4 -1
  8. package/esm/src/features/files-gen/repository.d.ts.map +1 -1
  9. package/esm/src/features/files-gen/repository.js +10 -3
  10. package/esm/src/features/payout/repository.d.ts +6 -1
  11. package/esm/src/features/payout/repository.d.ts.map +1 -1
  12. package/esm/src/features/payout/repository.js +12 -7
  13. package/esm/src/features/wallet/repository.d.ts +8 -1
  14. package/esm/src/features/wallet/repository.d.ts.map +1 -1
  15. package/esm/src/features/wallet/repository.js +17 -8
  16. package/esm/src/shared/base_repository.d.ts +25 -1
  17. package/esm/src/shared/base_repository.d.ts.map +1 -1
  18. package/esm/src/shared/base_repository.js +57 -6
  19. package/package.json +1 -1
  20. package/script/src/features/auth/manager.d.ts +9 -1
  21. package/script/src/features/auth/manager.d.ts.map +1 -1
  22. package/script/src/features/auth/manager.js +21 -4
  23. package/script/src/features/contact/repository.d.ts +12 -1
  24. package/script/src/features/contact/repository.d.ts.map +1 -1
  25. package/script/src/features/contact/repository.js +31 -17
  26. package/script/src/features/files-gen/repository.d.ts +4 -1
  27. package/script/src/features/files-gen/repository.d.ts.map +1 -1
  28. package/script/src/features/files-gen/repository.js +10 -3
  29. package/script/src/features/payout/repository.d.ts +6 -1
  30. package/script/src/features/payout/repository.d.ts.map +1 -1
  31. package/script/src/features/payout/repository.js +12 -7
  32. package/script/src/features/wallet/repository.d.ts +8 -1
  33. package/script/src/features/wallet/repository.d.ts.map +1 -1
  34. package/script/src/features/wallet/repository.js +17 -8
  35. package/script/src/shared/base_repository.d.ts +25 -1
  36. package/script/src/shared/base_repository.d.ts.map +1 -1
  37. package/script/src/shared/base_repository.js +57 -6
@@ -1,5 +1,6 @@
1
1
  import { type AppRouter } from "@ts-rest/core";
2
2
  import type { InitClientArgs } from "@ts-rest/core";
3
+ import { AfloatAuth } from "../features/auth/manager.js";
3
4
  /**
4
5
  * BaseRepository
5
6
  *
@@ -28,15 +29,38 @@ export declare class BaseRepository<TContract extends AppRouter> {
28
29
  * @protected
29
30
  */
30
31
  protected root: string | undefined;
32
+ /**
33
+ * The auth instance to use for authentication
34
+ *
35
+ * @protected
36
+ */
37
+ protected auth: AfloatAuth | undefined;
31
38
  /**
32
39
  * Constructs a new instance of `BaseRepository`.
33
40
  *
34
- * @param contract - The "ts-rest" contract
35
41
  * @param endpoint - API endpoint
42
+ * @param contract - The "ts-rest" contract
43
+ * @param args - Optional constructor arguments
44
+ * @param args.root - Optional API root URL
45
+ * @param args.auth - Optional auth instance to use
36
46
  */
37
47
  constructor(endpoint: string, contract: TContract, args?: {
38
48
  root?: string;
49
+ auth?: AfloatAuth;
39
50
  });
51
+ /**
52
+ * Gets an auth instance that can be used for permission checks.
53
+ * Follows a fallback strategy to find a valid auth instance.
54
+ *
55
+ * @protected
56
+ * @returns {AfloatAuth} A valid auth instance
57
+ * @throws {Error} If no valid auth instance is available
58
+ */
59
+ protected getAuthForPermissionCheck(): AfloatAuth;
60
+ /**
61
+ * Gets the initialized client for making API requests.
62
+ * Uses authentication token if available.
63
+ */
40
64
  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; };
41
65
  /**
42
66
  * Handles the API response by checking the HTTP status code and returning the response body
@@ -1 +1 @@
1
- {"version":3,"file":"base_repository.d.ts","sourceRoot":"","sources":["../../../src/src/shared/base_repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD;;;;;;;;GAQG;AACH,qBAAa,cAAc,CAAC,SAAS,SAAS,SAAS;IACrD;;;;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;;;;;OAKG;gBACS,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAM3E,IAAI,MAAM,k0LAqBT;IAED;;;;;;;;;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"}
1
+ {"version":3,"file":"base_repository.d.ts","sourceRoot":"","sources":["../../../src/src/shared/base_repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAe,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;GAQG;AACH,qBAAa,cAAc,CAAC,SAAS,SAAS,SAAS;IACrD;;;;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,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAEvC;;;;;;;;OAQG;gBACS,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE;QACxD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB;IASD;;;;;;;OAOG;IACH,SAAS,CAAC,yBAAyB,IAAI,UAAU;IAgBjD;;;OAGG;IACH,IAAI,MAAM,k0LA+BT;IAED;;;;;;;;;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"}
@@ -4,7 +4,7 @@ exports.BaseRepository = void 0;
4
4
  const core_1 = require("@ts-rest/core");
5
5
  const api_error_js_1 = require("../errors/api_error.js");
6
6
  const uuid_1 = require("uuid");
7
- const index_js_1 = require("../features/auth/index.js");
7
+ const manager_js_1 = require("../features/auth/manager.js");
8
8
  /**
9
9
  * BaseRepository
10
10
  *
@@ -18,8 +18,11 @@ class BaseRepository {
18
18
  /**
19
19
  * Constructs a new instance of `BaseRepository`.
20
20
  *
21
- * @param contract - The "ts-rest" contract
22
21
  * @param endpoint - API endpoint
22
+ * @param contract - The "ts-rest" contract
23
+ * @param args - Optional constructor arguments
24
+ * @param args.root - Optional API root URL
25
+ * @param args.auth - Optional auth instance to use
23
26
  */
24
27
  constructor(endpoint, contract, args) {
25
28
  /**
@@ -55,20 +58,68 @@ class BaseRepository {
55
58
  writable: true,
56
59
  value: void 0
57
60
  });
61
+ /**
62
+ * The auth instance to use for authentication
63
+ *
64
+ * @protected
65
+ */
66
+ Object.defineProperty(this, "auth", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
58
72
  this.contract = contract;
59
73
  this.endpoint = endpoint;
60
74
  this.root = args?.root;
75
+ // Use provided auth or try to get the current context
76
+ this.auth = args?.auth || manager_js_1.AuthContext.current;
61
77
  }
78
+ /**
79
+ * Gets an auth instance that can be used for permission checks.
80
+ * Follows a fallback strategy to find a valid auth instance.
81
+ *
82
+ * @protected
83
+ * @returns {AfloatAuth} A valid auth instance
84
+ * @throws {Error} If no valid auth instance is available
85
+ */
86
+ getAuthForPermissionCheck() {
87
+ // Use the instance provided in constructor, or fallback to context
88
+ const auth = this.auth || manager_js_1.AuthContext.current;
89
+ if (!auth) {
90
+ try {
91
+ // Last resort: try to get the client singleton
92
+ return manager_js_1.AfloatAuth.instance;
93
+ }
94
+ catch (_) {
95
+ throw new Error(`No valid auth instance available for ${this.endpoint} repository`);
96
+ }
97
+ }
98
+ return auth;
99
+ }
100
+ /**
101
+ * Gets the initialized client for making API requests.
102
+ * Uses authentication token if available.
103
+ */
62
104
  get client() {
63
105
  const baseUrl = this.root
64
106
  ? `${this.root}/${this.endpoint}`
65
107
  : `https://api.afloat.money/v1/${this.endpoint}`;
66
108
  let token = "";
67
- try {
68
- token = index_js_1.AfloatAuth.instance.getUserToken() ?? "";
109
+ // Try to get token from the provided auth instance
110
+ if (this.auth) {
111
+ token = this.auth.getUserToken() ?? "";
69
112
  }
70
- catch (_) {
71
- // should fail when called within the server
113
+ // Fall back to singleton if no auth was provided, but handle exceptions
114
+ // that occur in server environments
115
+ else {
116
+ try {
117
+ token = manager_js_1.AfloatAuth.instance.getUserToken() ?? "";
118
+ }
119
+ catch (_) {
120
+ // This will fail when called within the server without initialization
121
+ // We'll proceed with an empty token
122
+ }
72
123
  }
73
124
  const args = {
74
125
  baseUrl,