@ursalock/client 0.2.2 → 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/dist/index.d.ts +11 -37
- package/dist/index.js +20 -81
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,9 +27,9 @@ interface AuthState {
|
|
|
27
27
|
/** Auth provider interface */
|
|
28
28
|
interface AuthProvider {
|
|
29
29
|
/** Sign up a new user */
|
|
30
|
-
signUp(options: SignUpOptions): Promise<ZKAuthResult
|
|
30
|
+
signUp(options: SignUpOptions): Promise<ZKAuthResult>;
|
|
31
31
|
/** Sign in an existing user */
|
|
32
|
-
signIn(options: SignInOptions): Promise<ZKAuthResult
|
|
32
|
+
signIn(options: SignInOptions): Promise<ZKAuthResult>;
|
|
33
33
|
/** Sign out the current user */
|
|
34
34
|
signOut(): Promise<void>;
|
|
35
35
|
/** Get current auth state */
|
|
@@ -58,15 +58,6 @@ interface AuthResult {
|
|
|
58
58
|
token?: string;
|
|
59
59
|
error?: string;
|
|
60
60
|
}
|
|
61
|
-
/** Result of ZK auth operations (passkey with PRF) */
|
|
62
|
-
interface ZKAuthResult$1 {
|
|
63
|
-
success: boolean;
|
|
64
|
-
user?: User;
|
|
65
|
-
token?: string;
|
|
66
|
-
/** ZK Credential with derived encryption keys */
|
|
67
|
-
credential?: ZKCredential;
|
|
68
|
-
error?: string;
|
|
69
|
-
}
|
|
70
61
|
|
|
71
62
|
/**
|
|
72
63
|
* Auth provider interfaces
|
|
@@ -251,7 +242,7 @@ declare class VaultClient {
|
|
|
251
242
|
password?: string;
|
|
252
243
|
usePasskey?: boolean;
|
|
253
244
|
displayName?: string;
|
|
254
|
-
}): Promise<ZKAuthResult
|
|
245
|
+
}): Promise<ZKAuthResult>;
|
|
255
246
|
/**
|
|
256
247
|
* Sign in an existing user
|
|
257
248
|
*/
|
|
@@ -259,7 +250,7 @@ declare class VaultClient {
|
|
|
259
250
|
email?: string;
|
|
260
251
|
password?: string;
|
|
261
252
|
usePasskey?: boolean;
|
|
262
|
-
}): Promise<ZKAuthResult
|
|
253
|
+
}): Promise<ZKAuthResult>;
|
|
263
254
|
/**
|
|
264
255
|
* Sign out
|
|
265
256
|
*/
|
|
@@ -352,27 +343,6 @@ declare class EmailAuth implements IAuthProvider {
|
|
|
352
343
|
* @deprecated Use signUp() instead
|
|
353
344
|
*/
|
|
354
345
|
register(credentials: EmailCredentials): Promise<ZKAuthResult>;
|
|
355
|
-
/**
|
|
356
|
-
* Request password reset email
|
|
357
|
-
*/
|
|
358
|
-
forgotPassword(email: string): Promise<{
|
|
359
|
-
success: boolean;
|
|
360
|
-
error?: string;
|
|
361
|
-
}>;
|
|
362
|
-
/**
|
|
363
|
-
* Reset password with token
|
|
364
|
-
*/
|
|
365
|
-
resetPassword(token: string, newPassword: string): Promise<{
|
|
366
|
-
success: boolean;
|
|
367
|
-
error?: string;
|
|
368
|
-
}>;
|
|
369
|
-
/**
|
|
370
|
-
* Change password (when logged in)
|
|
371
|
-
*/
|
|
372
|
-
changePassword(currentPassword: string, newPassword: string, authToken: string): Promise<{
|
|
373
|
-
success: boolean;
|
|
374
|
-
error?: string;
|
|
375
|
-
}>;
|
|
376
346
|
/**
|
|
377
347
|
* Validate email format
|
|
378
348
|
*/
|
|
@@ -418,9 +388,13 @@ declare class TokenManager {
|
|
|
418
388
|
*/
|
|
419
389
|
setToken(token: Token): void;
|
|
420
390
|
/**
|
|
421
|
-
* Get current token
|
|
391
|
+
* Get current token (returns null if expired, without side effects)
|
|
422
392
|
*/
|
|
423
393
|
getToken(): Token | null;
|
|
394
|
+
/**
|
|
395
|
+
* Check if the current token is expired
|
|
396
|
+
*/
|
|
397
|
+
isExpired(): boolean;
|
|
424
398
|
/**
|
|
425
399
|
* Get access token string (convenience method)
|
|
426
400
|
*/
|
|
@@ -494,7 +468,7 @@ declare function useSignUp(client: VaultClient): {
|
|
|
494
468
|
password?: string;
|
|
495
469
|
usePasskey?: boolean;
|
|
496
470
|
displayName?: string;
|
|
497
|
-
}) => Promise<ZKAuthResult
|
|
471
|
+
}) => Promise<ZKAuthResult>;
|
|
498
472
|
isLoading: boolean;
|
|
499
473
|
error: Error | null;
|
|
500
474
|
};
|
|
@@ -520,7 +494,7 @@ declare function useSignIn(client: VaultClient): {
|
|
|
520
494
|
email?: string;
|
|
521
495
|
password?: string;
|
|
522
496
|
usePasskey?: boolean;
|
|
523
|
-
}) => Promise<ZKAuthResult
|
|
497
|
+
}) => Promise<ZKAuthResult>;
|
|
524
498
|
isLoading: boolean;
|
|
525
499
|
error: Error | null;
|
|
526
500
|
};
|
package/dist/index.js
CHANGED
|
@@ -270,80 +270,6 @@ var EmailAuth = class {
|
|
|
270
270
|
async register(credentials) {
|
|
271
271
|
return this.signUp(credentials);
|
|
272
272
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Request password reset email
|
|
275
|
-
*/
|
|
276
|
-
async forgotPassword(email) {
|
|
277
|
-
if (!this.isValidEmail(email)) {
|
|
278
|
-
return { success: false, error: "Invalid email address" };
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
await this.httpClient.fetch(
|
|
282
|
-
`${this.options.serverUrl}/auth/email/forgot-password`,
|
|
283
|
-
{
|
|
284
|
-
method: "POST",
|
|
285
|
-
headers: { "Content-Type": "application/json" },
|
|
286
|
-
body: JSON.stringify({ email })
|
|
287
|
-
}
|
|
288
|
-
);
|
|
289
|
-
return { success: true };
|
|
290
|
-
} catch {
|
|
291
|
-
return { success: true };
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Reset password with token
|
|
296
|
-
*/
|
|
297
|
-
async resetPassword(token, newPassword) {
|
|
298
|
-
if (!newPassword || newPassword.length < 8) {
|
|
299
|
-
return { success: false, error: "Password must be at least 8 characters" };
|
|
300
|
-
}
|
|
301
|
-
try {
|
|
302
|
-
const res = await this.httpClient.fetch(
|
|
303
|
-
`${this.options.serverUrl}/auth/email/reset-password`,
|
|
304
|
-
{
|
|
305
|
-
method: "POST",
|
|
306
|
-
headers: { "Content-Type": "application/json" },
|
|
307
|
-
body: JSON.stringify({ token, password: newPassword })
|
|
308
|
-
}
|
|
309
|
-
);
|
|
310
|
-
if (!res.ok) {
|
|
311
|
-
const err = await res.json();
|
|
312
|
-
return { success: false, error: err.message ?? "Reset failed" };
|
|
313
|
-
}
|
|
314
|
-
return { success: true };
|
|
315
|
-
} catch {
|
|
316
|
-
return { success: false, error: "Network error" };
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Change password (when logged in)
|
|
321
|
-
*/
|
|
322
|
-
async changePassword(currentPassword, newPassword, authToken) {
|
|
323
|
-
if (!newPassword || newPassword.length < 8) {
|
|
324
|
-
return { success: false, error: "New password must be at least 8 characters" };
|
|
325
|
-
}
|
|
326
|
-
try {
|
|
327
|
-
const res = await this.httpClient.fetch(
|
|
328
|
-
`${this.options.serverUrl}/auth/email/change-password`,
|
|
329
|
-
{
|
|
330
|
-
method: "POST",
|
|
331
|
-
headers: {
|
|
332
|
-
"Content-Type": "application/json",
|
|
333
|
-
"Authorization": `Bearer ${authToken}`
|
|
334
|
-
},
|
|
335
|
-
body: JSON.stringify({ currentPassword, newPassword })
|
|
336
|
-
}
|
|
337
|
-
);
|
|
338
|
-
if (!res.ok) {
|
|
339
|
-
const err = await res.json();
|
|
340
|
-
return { success: false, error: err.message ?? "Change failed" };
|
|
341
|
-
}
|
|
342
|
-
return { success: true };
|
|
343
|
-
} catch {
|
|
344
|
-
return { success: false, error: "Network error" };
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
273
|
/**
|
|
348
274
|
* Validate email format
|
|
349
275
|
*/
|
|
@@ -381,16 +307,22 @@ var TokenManager = class _TokenManager {
|
|
|
381
307
|
this.notifyListeners();
|
|
382
308
|
}
|
|
383
309
|
/**
|
|
384
|
-
* Get current token
|
|
310
|
+
* Get current token (returns null if expired, without side effects)
|
|
385
311
|
*/
|
|
386
312
|
getToken() {
|
|
387
313
|
if (!this.token) return null;
|
|
388
|
-
if (
|
|
389
|
-
this.clearToken();
|
|
314
|
+
if (this.isExpired()) {
|
|
390
315
|
return null;
|
|
391
316
|
}
|
|
392
317
|
return this.token;
|
|
393
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Check if the current token is expired
|
|
321
|
+
*/
|
|
322
|
+
isExpired() {
|
|
323
|
+
if (!this.token) return true;
|
|
324
|
+
return Date.now() >= this.token.expiresAt;
|
|
325
|
+
}
|
|
394
326
|
/**
|
|
395
327
|
* Get access token string (convenience method)
|
|
396
328
|
*/
|
|
@@ -401,8 +333,7 @@ var TokenManager = class _TokenManager {
|
|
|
401
333
|
* Check if token is valid
|
|
402
334
|
*/
|
|
403
335
|
isValid() {
|
|
404
|
-
|
|
405
|
-
return token !== null && Date.now() < token.expiresAt;
|
|
336
|
+
return this.token !== null && !this.isExpired();
|
|
406
337
|
}
|
|
407
338
|
/**
|
|
408
339
|
* Clear token
|
|
@@ -558,7 +489,15 @@ var VaultClient = class {
|
|
|
558
489
|
error: null,
|
|
559
490
|
credential: null
|
|
560
491
|
};
|
|
561
|
-
this.initialize()
|
|
492
|
+
this.initialize().catch((err) => {
|
|
493
|
+
this.updateState({
|
|
494
|
+
isAuthenticated: false,
|
|
495
|
+
user: null,
|
|
496
|
+
isLoading: false,
|
|
497
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
498
|
+
credential: null
|
|
499
|
+
});
|
|
500
|
+
});
|
|
562
501
|
}
|
|
563
502
|
// ==================
|
|
564
503
|
// Public Auth Methods
|
|
@@ -813,7 +752,7 @@ var VaultClient = class {
|
|
|
813
752
|
function useAuth(client) {
|
|
814
753
|
const subscribe = useCallback(
|
|
815
754
|
(callback) => {
|
|
816
|
-
return client.subscribe(callback);
|
|
755
|
+
return client.subscribe(() => callback());
|
|
817
756
|
},
|
|
818
757
|
[client]
|
|
819
758
|
);
|