@temboplus/afloat 0.1.2 → 0.1.4

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 (135) hide show
  1. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/almost_equals.d.ts.map +1 -1
  2. package/{script/deps/jsr.io/@std/assert/1.0.10 → esm/deps/jsr.io/@std/assert/1.0.11}/array_includes.d.ts.map +1 -1
  3. package/{script/deps/jsr.io/@std/assert/1.0.10 → esm/deps/jsr.io/@std/assert/1.0.11}/assert.d.ts.map +1 -1
  4. package/{script/deps/jsr.io/@std/assert/1.0.10 → esm/deps/jsr.io/@std/assert/1.0.11}/assertion_error.d.ts.map +1 -1
  5. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/equal.d.ts.map +1 -1
  6. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/equals.d.ts.map +1 -1
  7. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/exists.d.ts.map +1 -1
  8. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/fail.d.ts.map +1 -1
  9. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/false.d.ts.map +1 -1
  10. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/greater.d.ts.map +1 -1
  11. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/greater_or_equal.d.ts.map +1 -1
  12. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/instance_of.d.ts.map +1 -1
  13. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/is_error.d.ts.map +1 -1
  14. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/less.d.ts.map +1 -1
  15. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/less_or_equal.d.ts.map +1 -1
  16. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/match.d.ts.map +1 -1
  17. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/mod.d.ts.map +1 -1
  18. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_equals.d.ts.map +1 -1
  19. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_instance_of.d.ts.map +1 -1
  20. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_match.d.ts.map +1 -1
  21. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_strict_equals.d.ts.map +1 -1
  22. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/object_match.d.ts.map +1 -1
  23. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/rejects.d.ts.map +1 -1
  24. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/strict_equals.d.ts.map +1 -1
  25. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/string_includes.d.ts.map +1 -1
  26. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/throws.d.ts.map +1 -1
  27. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/unimplemented.d.ts.map +1 -1
  28. package/esm/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/unreachable.d.ts.map +1 -1
  29. package/esm/src/features/auth/contract.d.ts +14 -25
  30. package/esm/src/features/auth/contract.d.ts.map +1 -1
  31. package/esm/src/features/auth/contract.js +8 -15
  32. package/esm/src/features/auth/identity/contract.d.ts +30 -0
  33. package/esm/src/features/auth/identity/contract.d.ts.map +1 -0
  34. package/esm/src/features/auth/identity/contract.js +18 -0
  35. package/esm/src/features/auth/identity/repository.d.ts +22 -0
  36. package/esm/src/features/auth/identity/repository.d.ts.map +1 -0
  37. package/esm/src/features/auth/identity/repository.js +30 -0
  38. package/esm/src/features/auth/manager.d.ts +50 -27
  39. package/esm/src/features/auth/manager.d.ts.map +1 -1
  40. package/esm/src/features/auth/manager.js +101 -58
  41. package/esm/src/features/auth/profile/contract.d.ts +45 -0
  42. package/esm/src/features/auth/profile/contract.d.ts.map +1 -0
  43. package/esm/src/features/auth/profile/contract.js +16 -0
  44. package/esm/src/features/auth/profile/repository.d.ts +11 -0
  45. package/esm/src/features/auth/profile/repository.d.ts.map +1 -0
  46. package/esm/src/features/auth/profile/repository.js +21 -0
  47. package/esm/src/features/auth/repository.d.ts +1 -0
  48. package/esm/src/features/auth/repository.d.ts.map +1 -1
  49. package/esm/src/features/auth/repository.js +5 -22
  50. package/esm/src/features/auth/storage/client_store.d.ts +30 -0
  51. package/esm/src/features/auth/storage/client_store.d.ts.map +1 -0
  52. package/esm/src/features/auth/storage/client_store.js +47 -0
  53. package/esm/src/features/auth/storage/client_token_handler.d.ts +32 -0
  54. package/esm/src/features/auth/storage/client_token_handler.d.ts.map +1 -0
  55. package/esm/src/features/auth/storage/client_token_handler.js +36 -0
  56. package/esm/src/features/auth/storage/server_store.d.ts +24 -0
  57. package/esm/src/features/auth/storage/server_store.d.ts.map +1 -0
  58. package/esm/src/features/auth/storage/server_store.js +34 -0
  59. package/esm/src/features/auth/storage/server_token_handler.d.ts +35 -0
  60. package/esm/src/features/auth/storage/server_token_handler.d.ts.map +1 -0
  61. package/esm/src/features/auth/storage/server_token_handler.js +68 -0
  62. package/esm/src/features/auth/storage/types.d.ts +42 -0
  63. package/esm/src/features/auth/storage/types.d.ts.map +1 -0
  64. package/esm/src/features/auth/storage/types.js +1 -0
  65. package/esm/src/models/contact/derivatives/contact.d.ts +4 -0
  66. package/esm/src/models/contact/derivatives/contact.d.ts.map +1 -1
  67. package/esm/src/models/contact/derivatives/contact.js +6 -0
  68. package/package.json +1 -1
  69. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/almost_equals.d.ts.map +1 -1
  70. package/{esm/deps/jsr.io/@std/assert/1.0.10 → script/deps/jsr.io/@std/assert/1.0.11}/array_includes.d.ts.map +1 -1
  71. package/{esm/deps/jsr.io/@std/assert/1.0.10 → script/deps/jsr.io/@std/assert/1.0.11}/assert.d.ts.map +1 -1
  72. package/{esm/deps/jsr.io/@std/assert/1.0.10 → script/deps/jsr.io/@std/assert/1.0.11}/assertion_error.d.ts.map +1 -1
  73. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/equal.d.ts.map +1 -1
  74. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/equals.d.ts.map +1 -1
  75. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/exists.d.ts.map +1 -1
  76. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/fail.d.ts.map +1 -1
  77. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/false.d.ts.map +1 -1
  78. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/greater.d.ts.map +1 -1
  79. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/greater_or_equal.d.ts.map +1 -1
  80. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/instance_of.d.ts.map +1 -1
  81. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/is_error.d.ts.map +1 -1
  82. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/less.d.ts.map +1 -1
  83. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/less_or_equal.d.ts.map +1 -1
  84. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/match.d.ts.map +1 -1
  85. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/mod.d.ts.map +1 -1
  86. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_equals.d.ts.map +1 -1
  87. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_instance_of.d.ts.map +1 -1
  88. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_match.d.ts.map +1 -1
  89. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/not_strict_equals.d.ts.map +1 -1
  90. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/object_match.d.ts.map +1 -1
  91. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/rejects.d.ts.map +1 -1
  92. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/strict_equals.d.ts.map +1 -1
  93. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/string_includes.d.ts.map +1 -1
  94. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/throws.d.ts.map +1 -1
  95. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/unimplemented.d.ts.map +1 -1
  96. package/script/deps/jsr.io/@std/assert/{1.0.10 → 1.0.11}/unreachable.d.ts.map +1 -1
  97. package/script/src/features/auth/contract.d.ts +14 -25
  98. package/script/src/features/auth/contract.d.ts.map +1 -1
  99. package/script/src/features/auth/contract.js +9 -16
  100. package/script/src/features/auth/identity/contract.d.ts +30 -0
  101. package/script/src/features/auth/identity/contract.d.ts.map +1 -0
  102. package/script/src/features/auth/identity/contract.js +21 -0
  103. package/script/src/features/auth/identity/repository.d.ts +22 -0
  104. package/script/src/features/auth/identity/repository.d.ts.map +1 -0
  105. package/script/src/features/auth/identity/repository.js +34 -0
  106. package/script/src/features/auth/manager.d.ts +50 -27
  107. package/script/src/features/auth/manager.d.ts.map +1 -1
  108. package/script/src/features/auth/manager.js +101 -58
  109. package/script/src/features/auth/profile/contract.d.ts +45 -0
  110. package/script/src/features/auth/profile/contract.d.ts.map +1 -0
  111. package/script/src/features/auth/profile/contract.js +19 -0
  112. package/script/src/features/auth/profile/repository.d.ts +11 -0
  113. package/script/src/features/auth/profile/repository.d.ts.map +1 -0
  114. package/script/src/features/auth/profile/repository.js +25 -0
  115. package/script/src/features/auth/repository.d.ts +1 -0
  116. package/script/src/features/auth/repository.d.ts.map +1 -1
  117. package/script/src/features/auth/repository.js +6 -23
  118. package/script/src/features/auth/storage/client_store.d.ts +30 -0
  119. package/script/src/features/auth/storage/client_store.d.ts.map +1 -0
  120. package/script/src/features/auth/storage/client_store.js +52 -0
  121. package/script/src/features/auth/storage/client_token_handler.d.ts +32 -0
  122. package/script/src/features/auth/storage/client_token_handler.d.ts.map +1 -0
  123. package/script/src/features/auth/storage/client_token_handler.js +40 -0
  124. package/script/src/features/auth/storage/server_store.d.ts +24 -0
  125. package/script/src/features/auth/storage/server_store.d.ts.map +1 -0
  126. package/script/src/features/auth/storage/server_store.js +38 -0
  127. package/script/src/features/auth/storage/server_token_handler.d.ts +35 -0
  128. package/script/src/features/auth/storage/server_token_handler.d.ts.map +1 -0
  129. package/script/src/features/auth/storage/server_token_handler.js +72 -0
  130. package/script/src/features/auth/storage/types.d.ts +42 -0
  131. package/script/src/features/auth/storage/types.d.ts.map +1 -0
  132. package/script/src/features/auth/storage/types.js +2 -0
  133. package/script/src/models/contact/derivatives/contact.d.ts +4 -0
  134. package/script/src/models/contact/derivatives/contact.d.ts.map +1 -1
  135. package/script/src/models/contact/derivatives/contact.js +6 -0
@@ -1,80 +1,143 @@
1
- import { create, useStore, } from "zustand";
2
- import { createJSONStorage, persist } from "zustand/middleware";
3
1
  import { AuthRepository } from "./repository.js";
4
- import { User } from "../../models/index.js";
5
- const AUTH_STORE_SESSION_STORAGE_KEY = "auth-store";
2
+ import { createClientStore, useClientUser, } from "./storage/client_store.js";
3
+ import { ClientTokenHandler } from "./storage/client_token_handler.js";
4
+ import { ServerStore } from "./storage/server_store.js";
5
+ import { ServerTokenHandler } from "./storage/server_token_handler.js";
6
6
  /**
7
- * Singleton class responsible for user authentication and session management.
7
+ * Main authentication class that works in both client and server environments.
8
+ * Provides authentication functionality and user management.
8
9
  */
9
10
  export class AfloatAuth {
10
11
  /**
11
12
  * Private constructor to prevent direct instantiation.
13
+ * @param {AuthStore} store - The auth store implementation to use
14
+ * @param {TokenHandler} tokenHandler - The token handler implementation to use
12
15
  */
13
- constructor() { }
16
+ constructor(store, tokenHandler) {
17
+ /** The auth store implementation */
18
+ Object.defineProperty(this, "store", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ /** The token handler implementation */
25
+ Object.defineProperty(this, "tokenHandler", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ this.store = store;
32
+ this.tokenHandler = tokenHandler;
33
+ }
34
+ /**
35
+ * Initializes AfloatAuth for client-side use.
36
+ * This should be called once at application startup in client environments.
37
+ * @returns {AfloatAuth} The singleton instance configured for client-side
38
+ */
39
+ static initializeClient() {
40
+ if (!this._instance) {
41
+ this._instance = new AfloatAuth(createClientStore(), ClientTokenHandler.instance);
42
+ }
43
+ return this._instance;
44
+ }
45
+ /**
46
+ * Creates a new instance of AfloatAuth configured for server-side use.
47
+ * Initializes the user by fetching necessary data using the provided token.
48
+ * @param {string} token - Authentication token
49
+ * @returns {Promise<AfloatAuth>} A new instance configured for server-side
50
+ * @throws {Error} If token is invalid or required data cannot be fetched
51
+ */
52
+ static async initializeServer(token) {
53
+ if (!token) {
54
+ throw new Error("Token is required for server initialization");
55
+ }
56
+ const tokenHandler = new ServerTokenHandler(token);
57
+ const store = new ServerStore();
58
+ try {
59
+ // Fetch and construct user data
60
+ const user = await tokenHandler.constructUser();
61
+ store.setUser(user);
62
+ // Create and initialize auth instance
63
+ return new AfloatAuth(store, tokenHandler);
64
+ }
65
+ catch (error) {
66
+ if (error instanceof Error) {
67
+ throw new Error(`Failed to initialize server auth: ${error.message}`);
68
+ }
69
+ throw new Error("Failed to initialize server auth");
70
+ }
71
+ }
14
72
  /**
15
73
  * Gets the singleton instance of AfloatAuth.
16
- * @returns {AfloatAuth} The singleton instance.
74
+ * @throws {Error} If AfloatAuth hasn't been initialized
75
+ * @returns {AfloatAuth} The singleton instance
17
76
  */
18
77
  static get instance() {
19
- return this._instance || (this._instance = new this());
78
+ if (!this._instance) {
79
+ throw new Error("AfloatAuth not initialized. Call initializeClient() or initializeServer() first");
80
+ }
81
+ return this._instance;
20
82
  }
21
83
  /**
22
- * Fetches the authentication repository.
84
+ * Gets the authentication repository instance.
23
85
  * @private
24
- * @returns {AuthRepository} The repository instance for authentication-related API calls.
86
+ * @returns {AuthRepository} The repository for auth operations
25
87
  */
26
88
  get repo() {
27
89
  return new AuthRepository();
28
90
  }
29
91
  /**
30
- * Retrieves the current user's authentication token.
31
- * @returns {string | undefined} The token of the currently authenticated user.
92
+ * Gets the current authentication token.
93
+ * @returns {string | undefined} The current token or undefined if not authenticated
32
94
  */
33
95
  getUserToken() {
34
- return this.currentUser?.token;
96
+ return this.tokenHandler.getUserToken();
35
97
  }
36
98
  /**
37
- * Gets the currently logged-in user.
38
- * @returns {User | undefined} The current user object, or `undefined` if no user is logged in.
99
+ * Gets the currently authenticated user.
100
+ * @returns {User | undefined} The current user or undefined if not authenticated
39
101
  */
40
102
  get currentUser() {
41
- return store.getState().getUser();
103
+ return this.store.getUser();
42
104
  }
43
105
  /**
44
- * React hook that retrieves the currently authenticated user from the global store.
45
- *
46
- * @returns {User | undefined} The current user object if authenticated, or `undefined` if no user is logged in.
106
+ * React hook for accessing the current user in client-side code.
107
+ * @throws {Error} If called in a server environment
108
+ * @returns {User | undefined} The current user or undefined if not authenticated
47
109
  */
48
110
  useCurrentUser() {
49
- return useStore(store).getUser();
111
+ return useClientUser();
50
112
  }
51
113
  /**
52
- * Checks if the current user has the specified permission.
53
- * @param {Permission} perm - The permission to check.
54
- * @returns {boolean} `true` if the user has the permission, otherwise `false`.
114
+ * Checks if the current user has a specific permission.
115
+ * @param {Permission} perm - The permission to check
116
+ * @returns {boolean} True if the user has the permission, false otherwise
55
117
  */
56
118
  checkPermission(perm) {
57
119
  return this.currentUser?.can(perm) ?? false;
58
120
  }
59
121
  /**
60
- * Logs in a user with the provided email and password.
61
- * @param {string} email - The user's email address.
62
- * @param {string} password - The user's password.
63
- * @returns {Promise<User>} A promise that resolves to the authenticated user.
64
- * @throws Will throw an error if authentication fails.
122
+ * Authenticates a user with email and password.
123
+ * @param {string} email - The user's email
124
+ * @param {string} password - The user's password
125
+ * @returns {Promise<User>} Promise resolving to the authenticated user
126
+ * @throws Will throw an error if authentication fails
65
127
  */
66
128
  async logIn(email, password) {
67
129
  const user = await this.repo.logIn(email, password);
68
130
  this.clearSavedData();
69
- store.getState().setUser(user);
131
+ this.store.setUser(user);
132
+ this.tokenHandler.setUserToken(user.token);
70
133
  return user;
71
134
  }
72
135
  /**
73
- * Resets the user's password.
74
- * @param {string} current - The current password.
75
- * @param {string} updated - The new password.
76
- * @returns {Promise<boolean>} A promise that resolves to `true` if the operation is successful.
77
- * @throws Will throw an error if the reset fails.
136
+ * Updates the user's password.
137
+ * @param {string} current - The current password
138
+ * @param {string} updated - The new password
139
+ * @returns {Promise<boolean>} Promise resolving to true if successful
140
+ * @throws Will throw an error if the password update fails
78
141
  */
79
142
  async resetPassword(current, updated) {
80
143
  await this.repo.updatePassword(current, updated);
@@ -82,37 +145,17 @@ export class AfloatAuth {
82
145
  return true;
83
146
  }
84
147
  /**
85
- * Logs out the current user and clears session data.
148
+ * Logs out the current user.
86
149
  */
87
150
  logOut() {
88
151
  this.clearSavedData();
89
152
  }
90
153
  /**
91
- * Clears saved authentication data from the store and session storage.
154
+ * Clears all authentication data.
92
155
  * @private
93
156
  */
94
157
  clearSavedData() {
95
- store.getState().refresh();
96
- sessionStorage.removeItem(AUTH_STORE_SESSION_STORAGE_KEY);
158
+ this.store.refresh();
159
+ this.tokenHandler.clearToken();
97
160
  }
98
161
  }
99
- const initialState = { user: undefined };
100
- const store = create(persist((set, get) => ({
101
- ...initialState,
102
- getUser: () => {
103
- try {
104
- const jsonUser = get().user;
105
- if (jsonUser)
106
- return User.fromJSON(jsonUser);
107
- }
108
- catch (_) {
109
- console.log(_);
110
- }
111
- return undefined;
112
- },
113
- setUser: (user) => set({ user: user.toJSON() }),
114
- refresh: () => set(initialState),
115
- }), {
116
- name: AUTH_STORE_SESSION_STORAGE_KEY,
117
- storage: createJSONStorage(() => sessionStorage),
118
- }));
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Profile API contract
4
+ */
5
+ export declare const profileContract: {
6
+ getCurrentProfile: {
7
+ method: "GET";
8
+ path: "/me";
9
+ headers: z.ZodObject<{
10
+ token: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ token: string;
13
+ }, {
14
+ token: string;
15
+ }>;
16
+ responses: {
17
+ 200: z.ZodObject<{
18
+ id: z.ZodString;
19
+ firstName: z.ZodString;
20
+ lastName: z.ZodString;
21
+ displayName: z.ZodString;
22
+ phone: z.ZodString;
23
+ accountNo: z.ZodString;
24
+ email: z.ZodString;
25
+ }, z.UnknownKeysParam, z.ZodTypeAny, {
26
+ id: string;
27
+ firstName: string;
28
+ lastName: string;
29
+ displayName: string;
30
+ phone: string;
31
+ accountNo: string;
32
+ email: string;
33
+ }, {
34
+ id: string;
35
+ firstName: string;
36
+ lastName: string;
37
+ displayName: string;
38
+ phone: string;
39
+ accountNo: string;
40
+ email: string;
41
+ }>;
42
+ };
43
+ };
44
+ };
45
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/profile/contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAS1B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { initContract } from "@ts-rest/core";
2
+ import { profileSchema } from "../../../models/index.js";
3
+ import { z } from "zod";
4
+ /**
5
+ * Profile API contract
6
+ */
7
+ export const profileContract = initContract().router({
8
+ getCurrentProfile: {
9
+ method: "GET",
10
+ path: "/me",
11
+ headers: z.object({ token: z.string() }),
12
+ responses: {
13
+ 200: profileSchema,
14
+ },
15
+ },
16
+ });
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,21 @@
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
+ }
@@ -26,5 +26,6 @@ export declare class AuthRepository extends BaseRepository<typeof authContract>
26
26
  * @throws {APIError} If the current password is invalid or another error occurs during the update process.
27
27
  */
28
28
  updatePassword(currentPassword: string, newPassword: string): Promise<boolean>;
29
+ getAccessList(token: string): Promise<string[]>;
29
30
  }
30
31
  //# sourceMappingURL=repository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAO/D;;;GAGG;AACH,qBAAa,cAAe,SAAQ,cAAc,CAAC,OAAO,YAAY,CAAC;IACrE;;OAEG;;IAKH;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3D;;;;;;OAMG;IACG,cAAc,CAClB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;CAiBpB"}
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/auth/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C;;;GAGG;AACH,qBAAa,cAAe,SAAQ,cAAc,CAAC,OAAO,YAAY,CAAC;IACrE;;OAEG;;IAKH;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3D;;;;;;OAMG;IACG,cAAc,CAClB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;IAkBb,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAStD"}
@@ -1,7 +1,8 @@
1
1
  import { User } from "../../models/index.js";
2
2
  import { BaseRepository } from "../../shared/base_repository.js";
3
- import { authContract, identityContract } from "./contract.js";
3
+ import { authContract } from "./contract.js";
4
4
  import { APIError } from "../../errors/api_error.js";
5
+ import { LoginRepository } from "./identity/repository.js";
5
6
  /**
6
7
  * Class representing the AuthRepository.
7
8
  * Provides methods to handle authentication-related operations, such as login and password updates.
@@ -64,30 +65,12 @@ export class AuthRepository extends BaseRepository {
64
65
  statusCode: 502,
65
66
  });
66
67
  }
67
- }
68
- /**
69
- * Class representing the LoginRepository.
70
- * Provides methods to retrieve user identity-related information.
71
- */
72
- class LoginRepository extends BaseRepository {
73
- /**
74
- * Initializes an instance of LoginRepository.
75
- */
76
- constructor() {
77
- super("login", identityContract);
78
- }
79
- /**
80
- * Retrieves the user's login credentials.
81
- * @returns A promise that resolves to the user's login credentials on success.
82
- * @throws {APIError} If an error occurs while retrieving the credentials.
83
- */
84
- async getIdentity(token) {
85
- const headers = { token };
86
- const result = await this.client.getUserCredentials({ headers });
68
+ async getAccessList(token) {
69
+ const result = await this.client.access({ headers: { token: token } });
87
70
  if (result.status === 200)
88
71
  return result.body;
89
72
  throw new APIError({
90
- message: "An error occurred while trying to get login credentials",
73
+ message: "An error occurred while trying to get access list",
91
74
  statusCode: 502,
92
75
  });
93
76
  }
@@ -0,0 +1,30 @@
1
+ import { User } from "../../../models/user/index.js";
2
+ import { type StoreApi, type UseBoundStore } from "zustand";
3
+ import type { AuthStore } from "./types.js";
4
+ /** Type definition for the store's state */
5
+ type State = {
6
+ user: string | undefined;
7
+ };
8
+ /** Type definition for the store's actions */
9
+ interface Actions {
10
+ setUser: (user: User) => void;
11
+ getUser: () => User | undefined;
12
+ refresh: () => void;
13
+ }
14
+ /**
15
+ * Creates and exports the Zustand store directly for reactive hooks
16
+ * @internal This should only be used by AfloatAuth
17
+ */
18
+ export declare const clientStore: UseBoundStore<StoreApi<State & Actions>>;
19
+ /**
20
+ * Creates a client-side authentication store using Zustand.
21
+ * @returns {AuthStore} An implementation of AuthStore for client-side use
22
+ */
23
+ export declare const createClientStore: () => AuthStore;
24
+ /**
25
+ * React hook to access the current user with reactive updates.
26
+ * @returns {User | undefined} The current user or undefined if not authenticated
27
+ */
28
+ export declare const useClientUser: () => User | undefined;
29
+ export {};
30
+ //# sourceMappingURL=client_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client_store.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/storage/client_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C,4CAA4C;AAC5C,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE1C,8CAA8C;AAC9C,UAAU,OAAO;IACf,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,IAAI,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,CA2BhE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,SAMpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAO,IAAI,GAAG,SAEvC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { User } from "../../../models/user/index.js";
2
+ import { create } from "zustand";
3
+ import { persist } from "zustand/middleware";
4
+ import { createJSONStorage } from "zustand/middleware/storage";
5
+ /** Key used for storing auth data in session storage */
6
+ const AUTH_STORE_SESSION_STORAGE_KEY = "auth-store";
7
+ /**
8
+ * Creates and exports the Zustand store directly for reactive hooks
9
+ * @internal This should only be used by AfloatAuth
10
+ */
11
+ export const clientStore = create(persist((set, get) => ({
12
+ user: undefined,
13
+ getUser: () => {
14
+ try {
15
+ const jsonUser = get().user;
16
+ if (jsonUser)
17
+ return User.fromJSON(jsonUser);
18
+ }
19
+ catch (_) {
20
+ console.log(_);
21
+ }
22
+ return undefined;
23
+ },
24
+ setUser: (user) => set({ user: user.toJSON() }),
25
+ refresh: () => set({ user: undefined }),
26
+ }), {
27
+ name: AUTH_STORE_SESSION_STORAGE_KEY,
28
+ storage: createJSONStorage(() => sessionStorage),
29
+ }));
30
+ /**
31
+ * Creates a client-side authentication store using Zustand.
32
+ * @returns {AuthStore} An implementation of AuthStore for client-side use
33
+ */
34
+ export const createClientStore = () => {
35
+ return {
36
+ getUser: () => clientStore.getState().getUser(),
37
+ setUser: (user) => clientStore.getState().setUser(user),
38
+ refresh: () => clientStore.getState().refresh(),
39
+ };
40
+ };
41
+ /**
42
+ * React hook to access the current user with reactive updates.
43
+ * @returns {User | undefined} The current user or undefined if not authenticated
44
+ */
45
+ export const useClientUser = () => {
46
+ return clientStore((state) => state.getUser());
47
+ };
@@ -0,0 +1,32 @@
1
+ import type { TokenHandler } from "./types.js";
2
+ /**
3
+ * Client-side implementation of TokenHandler.
4
+ * Manages tokens using sessionStorage.
5
+ * @implements {TokenHandler}
6
+ */
7
+ export declare class ClientTokenHandler implements TokenHandler {
8
+ /** Singleton instance */
9
+ private static _instance;
10
+ /** Private constructor to enforce singleton pattern */
11
+ private constructor();
12
+ /**
13
+ * Gets the singleton instance of ClientTokenHandler.
14
+ * @returns {ClientTokenHandler} The singleton instance
15
+ */
16
+ static get instance(): ClientTokenHandler;
17
+ /**
18
+ * Retrieves the token from sessionStorage.
19
+ * @returns {string | undefined} The stored token or undefined if not present
20
+ */
21
+ getUserToken(): string | undefined;
22
+ /**
23
+ * Stores the token in sessionStorage.
24
+ * @param {string} token - The token to store
25
+ */
26
+ setUserToken(token: string): void;
27
+ /**
28
+ * Removes the token from sessionStorage.
29
+ */
30
+ clearToken(): void;
31
+ }
32
+ //# sourceMappingURL=client_token_handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client_token_handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/storage/client_token_handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IACrD,yBAAyB;IACzB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAqB;IAE7C,uDAAuD;IACvD,OAAO;IAEP;;;OAGG;IACH,MAAM,KAAK,QAAQ,IAAI,kBAAkB,CAExC;IAED;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Client-side implementation of TokenHandler.
3
+ * Manages tokens using sessionStorage.
4
+ * @implements {TokenHandler}
5
+ */
6
+ export class ClientTokenHandler {
7
+ /** Private constructor to enforce singleton pattern */
8
+ constructor() { }
9
+ /**
10
+ * Gets the singleton instance of ClientTokenHandler.
11
+ * @returns {ClientTokenHandler} The singleton instance
12
+ */
13
+ static get instance() {
14
+ return this._instance || (this._instance = new this());
15
+ }
16
+ /**
17
+ * Retrieves the token from sessionStorage.
18
+ * @returns {string | undefined} The stored token or undefined if not present
19
+ */
20
+ getUserToken() {
21
+ return sessionStorage.getItem("auth_token") || undefined;
22
+ }
23
+ /**
24
+ * Stores the token in sessionStorage.
25
+ * @param {string} token - The token to store
26
+ */
27
+ setUserToken(token) {
28
+ sessionStorage.setItem("auth_token", token);
29
+ }
30
+ /**
31
+ * Removes the token from sessionStorage.
32
+ */
33
+ clearToken() {
34
+ sessionStorage.removeItem("auth_token");
35
+ }
36
+ }
@@ -0,0 +1,24 @@
1
+ import type { User } from "../../../models/user/index.js";
2
+ import type { AuthStore } from "./types.js";
3
+ /**
4
+ * Server-side implementation of AuthStore.
5
+ * Maintains user state in memory for the duration of a request.
6
+ */
7
+ export declare class ServerStore implements AuthStore {
8
+ private user?;
9
+ /**
10
+ * Retrieves the current user from memory.
11
+ * @returns {User | undefined} The current user or undefined if not set
12
+ */
13
+ getUser(): User | undefined;
14
+ /**
15
+ * Sets the current user in memory.
16
+ * @param {User} user - The user to store
17
+ */
18
+ setUser(user: User): void;
19
+ /**
20
+ * Clears the stored user from memory.
21
+ */
22
+ refresh(): void;
23
+ }
24
+ //# sourceMappingURL=server_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server_store.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/storage/server_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;GAGG;AACH,qBAAa,WAAY,YAAW,SAAS;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAO;IAEpB;;;OAGG;IACH,OAAO,IAAI,IAAI,GAAG,SAAS;IAI3B;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIzB;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Server-side implementation of AuthStore.
3
+ * Maintains user state in memory for the duration of a request.
4
+ */
5
+ export class ServerStore {
6
+ constructor() {
7
+ Object.defineProperty(this, "user", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ }
14
+ /**
15
+ * Retrieves the current user from memory.
16
+ * @returns {User | undefined} The current user or undefined if not set
17
+ */
18
+ getUser() {
19
+ return this.user;
20
+ }
21
+ /**
22
+ * Sets the current user in memory.
23
+ * @param {User} user - The user to store
24
+ */
25
+ setUser(user) {
26
+ this.user = user;
27
+ }
28
+ /**
29
+ * Clears the stored user from memory.
30
+ */
31
+ refresh() {
32
+ this.user = undefined;
33
+ }
34
+ }
@@ -0,0 +1,35 @@
1
+ import type { TokenHandler } from "./types.js";
2
+ import { User } from "../../../models/index.js";
3
+ /**
4
+ * Server-side implementation of TokenHandler.
5
+ * Manages tokens in memory for the duration of a request.
6
+ * @implements {TokenHandler}
7
+ */
8
+ export declare class ServerTokenHandler implements TokenHandler {
9
+ private token?;
10
+ /**
11
+ * Creates a new instance of ServerTokenHandler.
12
+ * @param {string} [token] - Optional initial token value
13
+ */
14
+ constructor(token?: string | undefined);
15
+ /**
16
+ * Returns the stored token.
17
+ * @returns {string | undefined} The current token or undefined if not set
18
+ */
19
+ getUserToken(): string | undefined;
20
+ /**
21
+ * Stores the provided token in memory.
22
+ * @param {string} token - The token to store
23
+ */
24
+ setUserToken(token: string): void;
25
+ /**
26
+ * Clears the stored token from memory.
27
+ */
28
+ clearToken(): void;
29
+ /**
30
+ * Fetches and constructs the full user data
31
+ * @returns {Promise<User>}
32
+ */
33
+ constructUser(): Promise<User>;
34
+ }
35
+ //# sourceMappingURL=server_token_handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server_token_handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/features/auth/storage/server_token_handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKhD;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IAKzC,OAAO,CAAC,KAAK,CAAC;IAJ1B;;;OAGG;gBACiB,KAAK,CAAC,EAAE,MAAM,YAAA;IAElC;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAyBrC"}