@opensecret/react 0.1.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -64,7 +64,10 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
64
64
 
65
65
  #### Authentication Methods
66
66
  - `signIn(email: string, password: string): Promise<void>`: Signs in a user with the provided email and password.
67
- - `signUp(name: string, email: string, password: string, inviteCode: string): Promise<void>`: Signs up a new user with the provided name, email, password, and invite code.
67
+ - `signUp(email: string, password: string, inviteCode: string, name?: string): Promise<void>`: Signs up a new user with the provided email, password, invite code, and optional name.
68
+ - `signInGuest(id: string, password: string): Promise<void>`: Signs in a guest user with their ID and password.
69
+ - `signUpGuest(password: string, inviteCode: string): Promise<LoginResponse>`: Creates a new guest account with just a password and invite code. Returns a response containing the guest's ID, access token, and refresh token.
70
+ - `convertGuestToUserAccount(email: string, password: string, name?: string): Promise<void>`: Converts current guest account to a regular account with email authentication. Optionally sets the user's name.
68
71
  - `signOut(): Promise<void>`: Signs out the current user.
69
72
 
70
73
  #### Key-Value Storage Methods
package/dist/index.d.ts CHANGED
@@ -6,7 +6,9 @@ declare namespace api {
6
6
  export {
7
7
  setApiUrl,
8
8
  fetchLogin,
9
+ fetchGuestLogin,
9
10
  fetchSignUp,
11
+ fetchGuestSignUp,
10
12
  refreshToken,
11
13
  fetchUser,
12
14
  fetchPut,
@@ -28,6 +30,7 @@ declare namespace api {
28
30
  fetchPrivateKey,
29
31
  signMessage,
30
32
  fetchPublicKey,
33
+ convertGuestToEmailAccount,
31
34
  LoginResponse,
32
35
  UserResponse,
33
36
  KVListItem,
@@ -86,6 +89,8 @@ declare function changePassword(currentPassword: string, newPassword: string): P
86
89
 
87
90
  declare function confirmPasswordReset(email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string): Promise<void>;
88
91
 
92
+ declare function convertGuestToEmailAccount(email: string, password: string, name?: string): Promise<void>;
93
+
89
94
  declare const EXPECTED_ROOT_CERT_HASH = "641a0321a3e244efe456463195d606317ed7cdcc3c1756e09893f3c68f79bb5b";
90
95
 
91
96
  declare function fetchAttestationDocument(nonce: string): Promise<string>;
@@ -94,6 +99,10 @@ declare function fetchDelete(key: string): Promise<void>;
94
99
 
95
100
  declare function fetchGet(key: string): Promise<string | undefined>;
96
101
 
102
+ declare function fetchGuestLogin(id: string, password: string): Promise<LoginResponse>;
103
+
104
+ declare function fetchGuestSignUp(password: string, inviteCode: string): Promise<LoginResponse>;
105
+
97
106
  declare function fetchList(): Promise<KVListItem[]>;
98
107
 
99
108
  declare function fetchLogin(email: string, password: string): Promise<LoginResponse>;
@@ -106,7 +115,7 @@ declare function fetchPublicKey(algorithm: SigningAlgorithm): Promise<PublicKeyR
106
115
 
107
116
  declare function fetchPut(key: string, value: string): Promise<string>;
108
117
 
109
- declare function fetchSignUp(name: string, email: string, password: string, inviteCode: string): Promise<LoginResponse>;
118
+ declare function fetchSignUp(email: string, password: string, inviteCode: string, name?: string | null): Promise<LoginResponse>;
110
119
 
111
120
  declare function fetchUser(): Promise<UserResponse>;
112
121
 
@@ -147,8 +156,8 @@ export declare type KVListItem = {
147
156
  };
148
157
 
149
158
  export declare type LoginResponse = {
150
- id: number;
151
- email: string;
159
+ id: string;
160
+ email?: string;
152
161
  access_token: string;
153
162
  refresh_token: string;
154
163
  };
@@ -178,10 +187,10 @@ export declare type OpenSecretContextType = {
178
187
  signIn: (email: string, password: string) => Promise<void>;
179
188
  /**
180
189
  * Creates a new user account
181
- * @param name - User's full name
182
190
  * @param email - User's email address
183
191
  * @param password - User's chosen password
184
192
  * @param inviteCode - Invitation code for registration
193
+ * @param name - Optional user's full name
185
194
  * @returns A promise that resolves when account creation is complete
186
195
  * @throws {Error} If signup fails
187
196
  *
@@ -191,7 +200,53 @@ export declare type OpenSecretContextType = {
191
200
  * - Updates the auth state with new user information
192
201
  * - Throws an error if account creation fails
193
202
  */
194
- signUp: (name: string, email: string, password: string, inviteCode: string) => Promise<void>;
203
+ signUp: (email: string, password: string, inviteCode: string, name?: string) => Promise<void>;
204
+ /**
205
+ * Authenticates a guest user with user id and password
206
+ * @param id - User's unique id
207
+ * @param password - User's password
208
+ * @returns A promise that resolves when authentication is complete
209
+ * @throws {Error} If login fails
210
+ *
211
+ * @description
212
+ * - Calls the login API endpoint
213
+ * - Stores access_token and refresh_token in localStorage
214
+ * - Updates the auth state with user information
215
+ * - Throws an error if authentication fails
216
+ */
217
+ signInGuest: (id: string, password: string) => Promise<void>;
218
+ /**
219
+ * Creates a new guest account, which can be upgraded to a normal account later with email.
220
+ * @param password - User's chosen password, cannot be changed or recovered without adding email address.
221
+ * @param inviteCode - Invitation code for registration
222
+ * @returns A promise that resolves to the login response containing the guest ID
223
+ * @throws {Error} If signup fails
224
+ *
225
+ * @description
226
+ * - Calls the registration API endpoint
227
+ * - Stores access_token and refresh_token in localStorage
228
+ * - Updates the auth state with new user information
229
+ * - Throws an error if account creation fails
230
+ */
231
+ signUpGuest: (password: string, inviteCode: string) => Promise<LoginResponse>;
232
+ /**
233
+ * Upgrades a guest account to a user account with email and password authentication.
234
+ * @param email - User's email address
235
+ * @param password - User's chosen password
236
+ * @param name - Optional user's full name
237
+ * @returns A promise that resolves when account creation is complete
238
+ * @throws {Error} If:
239
+ * - The current user is not a guest account
240
+ * - The email address is already in use
241
+ * - The user is not authenticated
242
+ *
243
+ * @description
244
+ * - Upgrades the currently signed-in guest account (identified by their UUID) to a full email account
245
+ * - Requires the user to be currently authenticated as a guest
246
+ * - Updates the auth state with new user information
247
+ * - Preserves all existing data associated with the guest account
248
+ */
249
+ convertGuestToUserAccount: (email: string, password: string, name?: string) => Promise<void>;
195
250
  /**
196
251
  * Logs out the current user
197
252
  * @returns A promise that resolves when logout is complete
@@ -448,7 +503,7 @@ export declare type UserResponse = {
448
503
  user: {
449
504
  id: string;
450
505
  name: string | null;
451
- email: string;
506
+ email?: string;
452
507
  email_verified: boolean;
453
508
  login_method: string;
454
509
  created_at: string;