@oxog/authkeeper 1.3.0 → 1.4.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +80 -2
  3. package/dist/auth-source-BaZ_-Fu7.d.cts +24 -0
  4. package/dist/auth-source-Cm0R6C6I.d.ts +24 -0
  5. package/dist/chunk-62XK5QLP.cjs +19 -0
  6. package/dist/chunk-62XK5QLP.cjs.map +1 -0
  7. package/dist/chunk-CYCWWUCJ.js +17 -0
  8. package/dist/chunk-CYCWWUCJ.js.map +1 -0
  9. package/dist/{chunk-7KKUG6IF.cjs → chunk-EXV2RG6T.cjs} +71 -45
  10. package/dist/chunk-EXV2RG6T.cjs.map +1 -0
  11. package/dist/{chunk-3YDUKFDO.js → chunk-KE7V52DI.js} +61 -34
  12. package/dist/chunk-KE7V52DI.js.map +1 -0
  13. package/dist/chunk-KLT44YR2.cjs +69 -0
  14. package/dist/chunk-KLT44YR2.cjs.map +1 -0
  15. package/dist/chunk-SUGFPZ6O.js +66 -0
  16. package/dist/chunk-SUGFPZ6O.js.map +1 -0
  17. package/dist/index-BF4j_buH.d.ts +488 -0
  18. package/dist/index-CuvfPscu.d.cts +488 -0
  19. package/dist/index.cjs +69 -54
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +9 -3
  22. package/dist/index.d.ts +9 -3
  23. package/dist/index.js +21 -5
  24. package/dist/index.js.map +1 -1
  25. package/dist/plugins/index.cjs +15 -14
  26. package/dist/plugins/index.d.cts +2 -1
  27. package/dist/plugins/index.d.ts +2 -1
  28. package/dist/plugins/index.js +2 -1
  29. package/dist/react/index.cjs +40 -3
  30. package/dist/react/index.cjs.map +1 -1
  31. package/dist/react/index.d.cts +42 -5
  32. package/dist/react/index.d.ts +42 -5
  33. package/dist/react/index.js +38 -3
  34. package/dist/react/index.js.map +1 -1
  35. package/dist/svelte/index.cjs +37 -3
  36. package/dist/svelte/index.cjs.map +1 -1
  37. package/dist/svelte/index.d.cts +23 -5
  38. package/dist/svelte/index.d.ts +23 -5
  39. package/dist/svelte/index.js +37 -3
  40. package/dist/svelte/index.js.map +1 -1
  41. package/dist/types-Bmo8S8O4.d.cts +421 -0
  42. package/dist/types-Bmo8S8O4.d.ts +421 -0
  43. package/dist/vue/index.cjs +46 -3
  44. package/dist/vue/index.cjs.map +1 -1
  45. package/dist/vue/index.d.cts +45 -5
  46. package/dist/vue/index.d.ts +45 -5
  47. package/dist/vue/index.js +43 -3
  48. package/dist/vue/index.js.map +1 -1
  49. package/package.json +10 -5
  50. package/dist/chunk-3YDUKFDO.js.map +0 -1
  51. package/dist/chunk-7KKUG6IF.cjs.map +0 -1
  52. package/dist/index-B05Msx7M.d.cts +0 -898
  53. package/dist/index-B05Msx7M.d.ts +0 -898
@@ -1,898 +0,0 @@
1
- /**
2
- * AuthKeeper Type Definitions
3
- *
4
- * Complete type system for the AuthKeeper library.
5
- * All interfaces and types are exported for use by consumers.
6
- */
7
- /**
8
- * Token set returned from authentication/refresh operations
9
- */
10
- interface TokenSet {
11
- /** JWT access token */
12
- accessToken: string;
13
- /** Optional refresh token for obtaining new access tokens */
14
- refreshToken?: string;
15
- /** Token expiration in seconds from now */
16
- expiresIn?: number;
17
- /** Token expiration as Unix timestamp (seconds) */
18
- expiresAt?: number;
19
- /** Token type (default: 'Bearer') */
20
- tokenType?: string;
21
- }
22
- /**
23
- * Standard JWT payload with common claims
24
- */
25
- interface TokenPayload {
26
- /** Subject - usually the user ID */
27
- sub?: string;
28
- /** Issuer - who created the token */
29
- iss?: string;
30
- /** Audience - who the token is intended for */
31
- aud?: string | string[];
32
- /** Expiration time (Unix timestamp in seconds) */
33
- exp?: number;
34
- /** Not before time (Unix timestamp in seconds) */
35
- nbf?: number;
36
- /** Issued at time (Unix timestamp in seconds) */
37
- iat?: number;
38
- /** JWT ID - unique identifier */
39
- jti?: string;
40
- /** User email address */
41
- email?: string;
42
- /** User display name */
43
- name?: string;
44
- /** User roles */
45
- roles?: string[];
46
- /** User permissions */
47
- permissions?: string[];
48
- /** OAuth2 scope */
49
- scope?: string;
50
- [key: string]: unknown;
51
- }
52
- /**
53
- * JWT header information
54
- */
55
- interface TokenHeader {
56
- /** Algorithm used to sign the token */
57
- alg: string;
58
- /** Token type (usually 'JWT') */
59
- typ?: string;
60
- /** Key ID used to sign the token */
61
- kid?: string;
62
- [key: string]: unknown;
63
- }
64
- /**
65
- * Complete token information including decoded parts
66
- */
67
- interface TokenInfo {
68
- /** Raw JWT string */
69
- raw: string;
70
- /** Decoded payload */
71
- payload: TokenPayload;
72
- /** Decoded header */
73
- header: TokenHeader;
74
- /** When the token expires (null if no expiry) */
75
- expiresAt: Date | null;
76
- /** Whether the token is expired */
77
- isExpired: boolean;
78
- /** Time until expiry in milliseconds (null if no expiry) */
79
- expiresIn: number | null;
80
- }
81
- /**
82
- * Stored token data with metadata
83
- */
84
- interface StoredTokens {
85
- /** Access token */
86
- accessToken: string;
87
- /** Refresh token (null if not available) */
88
- refreshToken: string | null;
89
- /** Token type (e.g., 'Bearer') */
90
- tokenType: string;
91
- /** Expiration timestamp in milliseconds (null if no expiry) */
92
- expiresAt: number | null;
93
- /** When tokens were set (timestamp in milliseconds) */
94
- setAt: number;
95
- /** Number of times tokens have been refreshed */
96
- refreshCount: number;
97
- }
98
- /**
99
- * Error codes for authentication errors
100
- */
101
- type AuthErrorCode = 'TOKEN_EXPIRED' | 'TOKEN_INVALID' | 'TOKEN_DECODE_FAILED' | 'REFRESH_FAILED' | 'REFRESH_TOKEN_MISSING' | 'STORAGE_ERROR' | 'NETWORK_ERROR' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'OAUTH_ERROR' | 'PKCE_ERROR' | 'CALLBACK_ERROR' | 'CONFIG_ERROR';
102
- /**
103
- * Options for creating an AuthError
104
- */
105
- interface AuthErrorOptions {
106
- /** Additional context about the error */
107
- context?: Record<string, unknown>;
108
- /** Original error that caused this error */
109
- cause?: Error;
110
- }
111
- /**
112
- * Custom error class for authentication errors
113
- */
114
- declare class AuthError extends Error {
115
- /** Error code identifying the type of error */
116
- code: AuthErrorCode;
117
- /** Additional context about the error */
118
- context?: Record<string, unknown>;
119
- /** Original error that caused this error */
120
- cause?: Error;
121
- constructor(code: AuthErrorCode, message: string, options?: AuthErrorOptions);
122
- }
123
- /**
124
- * All possible event types
125
- */
126
- type EventType = 'login' | 'logout' | 'refresh' | 'expired' | 'error' | 'storage-change' | 'tab-sync';
127
- /**
128
- * Login event - fired when user logs in
129
- */
130
- interface LoginEvent {
131
- type: 'login';
132
- tokens: TokenSet;
133
- timestamp: number;
134
- }
135
- /**
136
- * Logout event - fired when user logs out
137
- */
138
- interface LogoutEvent {
139
- type: 'logout';
140
- reason: 'manual' | 'expired' | 'error' | 'tab-sync';
141
- timestamp: number;
142
- }
143
- /**
144
- * Refresh event - fired when tokens are refreshed
145
- */
146
- interface RefreshEvent {
147
- type: 'refresh';
148
- tokens: TokenSet;
149
- previousExpiresAt: Date | null;
150
- newExpiresAt: Date | null;
151
- timestamp: number;
152
- }
153
- /**
154
- * Expired event - fired when token expires
155
- */
156
- interface ExpiredEvent {
157
- type: 'expired';
158
- expiredAt: Date;
159
- timestamp: number;
160
- }
161
- /**
162
- * Error event - fired when an error occurs
163
- */
164
- interface ErrorEvent {
165
- type: 'error';
166
- error: AuthError;
167
- context: 'refresh' | 'storage' | 'decode' | 'network' | 'plugin';
168
- timestamp: number;
169
- }
170
- /**
171
- * Storage change event - fired when storage changes
172
- */
173
- interface StorageChangeEvent {
174
- type: 'storage-change';
175
- key: string;
176
- oldValue: string | null;
177
- newValue: string | null;
178
- timestamp: number;
179
- }
180
- /**
181
- * Tab sync event - fired when syncing across tabs
182
- */
183
- interface TabSyncEvent {
184
- type: 'tab-sync';
185
- action: 'login' | 'logout' | 'refresh';
186
- sourceTabId: string;
187
- timestamp: number;
188
- }
189
- /**
190
- * Union of all event types
191
- */
192
- type AuthEvent = LoginEvent | LogoutEvent | RefreshEvent | ExpiredEvent | ErrorEvent | StorageChangeEvent | TabSyncEvent;
193
- /**
194
- * Event handler function type
195
- */
196
- type EventHandler<E extends EventType> = (event: Extract<AuthEvent, {
197
- type: E;
198
- }>) => void;
199
- /**
200
- * Unsubscribe function returned from event handlers
201
- */
202
- type Unsubscribe = () => void;
203
- /**
204
- * Storage adapter interface for token persistence
205
- */
206
- interface StorageAdapter {
207
- /** Get value by key */
208
- get(key: string): string | null;
209
- /** Set value by key */
210
- set(key: string, value: string): void;
211
- /** Remove value by key */
212
- remove(key: string): void;
213
- /** Clear all values */
214
- clear(): void;
215
- }
216
- /**
217
- * Built-in storage types
218
- */
219
- type StorageType = 'memory' | 'localStorage' | 'sessionStorage' | 'cookie';
220
- /**
221
- * Plugin interface for extending AuthKeeper
222
- */
223
- interface Plugin {
224
- /** Unique plugin name */
225
- name: string;
226
- /** Plugin version */
227
- version: string;
228
- /** Plugin type */
229
- type: 'core' | 'optional';
230
- /** Install plugin and return API */
231
- install(kernel: AuthKeeper): any;
232
- /** Uninstall plugin and cleanup */
233
- uninstall?(): void | Promise<void>;
234
- /** Reserved lifecycle hooks; not invoked by the kernel yet */
235
- hooks?: {
236
- /** Called before tokens are set */
237
- beforeSetTokens?: (tokens: TokenSet) => TokenSet | false;
238
- /** Called after tokens are set */
239
- afterSetTokens?: (tokens: TokenSet) => void;
240
- /** Called before refresh */
241
- beforeRefresh?: () => boolean;
242
- /** Called after refresh */
243
- afterRefresh?: (tokens: TokenSet) => void;
244
- /** Called before logout */
245
- beforeLogout?: () => boolean;
246
- /** Called after logout */
247
- afterLogout?: () => void;
248
- /** Called when token expires */
249
- onExpired?: () => void;
250
- /** Called on error */
251
- onError?: (error: AuthError) => void;
252
- /** Called before request */
253
- beforeRequest?: (request: Request) => Request;
254
- /** Called after response */
255
- afterResponse?: (response: Response) => Response;
256
- };
257
- /** Plugin API exposed to consumers */
258
- api?: Record<string, unknown>;
259
- }
260
- /**
261
- * Plugin information
262
- */
263
- interface PluginInfo {
264
- name: string;
265
- version: string;
266
- type: 'core' | 'optional';
267
- enabled: boolean;
268
- }
269
- /**
270
- * Refresh token function type
271
- */
272
- type RefreshTokenFn = (refreshToken: string) => Promise<TokenSet>;
273
- /**
274
- * Kernel configuration options
275
- */
276
- interface KernelOptions {
277
- /**
278
- * Where tokens are persisted (default: 'memory', i.e. not persisted).
279
- * 'localStorage' / 'sessionStorage' / 'cookie' fall back to memory where
280
- * unavailable. Persistent storage is readable by any script on the page.
281
- */
282
- storage?: StorageType | StorageAdapter;
283
- /** Function to refresh tokens */
284
- refreshToken: RefreshTokenFn;
285
- /** Enable automatic token refresh (default: true) */
286
- autoRefresh?: boolean;
287
- /** Seconds before expiry to refresh (default: 60) */
288
- refreshThreshold?: number;
289
- /**
290
- * Reserved for multi-tab sync; not implemented yet (currently a no-op).
291
- * `getOptions().syncTabs` always reports `false`.
292
- */
293
- syncTabs?: boolean;
294
- /** Error handler */
295
- onError?: (error: AuthError) => void;
296
- /** Additional plugins to install */
297
- plugins?: Plugin[];
298
- }
299
- /**
300
- * Logout options
301
- */
302
- interface LogoutOptions {
303
- /** Reserved for multi-tab logout; not implemented yet (currently a no-op) */
304
- allTabs?: boolean;
305
- /** Redirect URL after logout */
306
- redirect?: string;
307
- }
308
- /**
309
- * Authenticated fetch function
310
- */
311
- type AuthFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
312
- /**
313
- * Fetch interceptor options
314
- */
315
- interface FetchInterceptorOptions {
316
- /** Header name for auth token (default: 'Authorization') */
317
- headerName?: string;
318
- /** Header prefix (default: 'Bearer ') */
319
- headerPrefix?: string;
320
- /** Only include auth header for these URLs */
321
- includeUrls?: (string | RegExp)[];
322
- /** Exclude auth header for these URLs */
323
- excludeUrls?: (string | RegExp)[];
324
- /** Callback on 401 response */
325
- onUnauthorized?: (response: Response) => void;
326
- /** Retry on 401 after refresh (default: true) */
327
- retry401?: boolean;
328
- /** Max retries (default: 1) */
329
- maxRetries?: number;
330
- }
331
- /**
332
- * OAuth2 login options
333
- */
334
- interface LoginOptions {
335
- /** OAuth2 scope */
336
- scope?: string;
337
- /** OAuth2 state parameter */
338
- state?: string;
339
- /** OAuth2 prompt parameter */
340
- prompt?: 'none' | 'login' | 'consent' | 'select_account';
341
- /** Login hint (email, etc.) */
342
- loginHint?: string;
343
- /** Additional OAuth2 parameters */
344
- extraParams?: Record<string, string>;
345
- }
346
- /**
347
- * User info from OIDC userinfo endpoint
348
- */
349
- interface UserInfo {
350
- sub: string;
351
- email?: string;
352
- name?: string;
353
- picture?: string;
354
- [key: string]: unknown;
355
- }
356
- /**
357
- * Main AuthKeeper interface - the kernel
358
- */
359
- interface AuthKeeper {
360
- /** Set authentication tokens */
361
- setTokens(tokens: TokenSet): void;
362
- /** Get access token */
363
- getAccessToken(): string | null;
364
- /** Get refresh token */
365
- getRefreshToken(): string | null;
366
- /** Clear all tokens */
367
- clearTokens(): void;
368
- /** Check if user is authenticated */
369
- isAuthenticated(): boolean;
370
- /** Check if token is expired */
371
- isExpired(): boolean;
372
- /** Get token expiration date */
373
- getExpiresAt(): Date | null;
374
- /** Get time until expiry in milliseconds */
375
- getTimeUntilExpiry(): number | null;
376
- /** Decode token payload */
377
- decode<T = TokenPayload>(): T | null;
378
- /** Get specific claim from token */
379
- getClaim<K extends keyof TokenPayload>(key: K): TokenPayload[K] | undefined;
380
- /** Get multiple claims from token */
381
- getClaims<K extends keyof TokenPayload>(keys: K[]): Pick<TokenPayload, K>;
382
- /** Manually refresh tokens */
383
- refresh(): Promise<TokenSet>;
384
- /** Schedule automatic refresh */
385
- scheduleRefresh(): void;
386
- /** Cancel scheduled refresh */
387
- cancelScheduledRefresh(): void;
388
- /** Logout user */
389
- logout(options?: LogoutOptions): void;
390
- /** Create authenticated fetch function */
391
- createFetch(options?: FetchInterceptorOptions): AuthFetch;
392
- /** Wrap global fetch with auth */
393
- wrapFetch(fetch: typeof globalThis.fetch): void;
394
- /**
395
- * Register and install a plugin. Rejects if installation fails; the failure
396
- * is also emitted as an 'error' event with context 'plugin'.
397
- */
398
- register(plugin: Plugin): Promise<void>;
399
- /** Unregister a plugin */
400
- unregister(pluginName: string): Promise<void>;
401
- /** Get plugin by name */
402
- getPlugin<P extends Plugin>(name: string): P | undefined;
403
- /** List all plugins */
404
- listPlugins(): PluginInfo[];
405
- /** Emit an event */
406
- emit(event: AuthEvent): void;
407
- /** Subscribe to events */
408
- on<E extends EventType>(eventType: E, handler: EventHandler<E>): Unsubscribe;
409
- /** Unsubscribe from events */
410
- off<E extends EventType>(eventType: E, handler: EventHandler<E>): void;
411
- /** Initialize kernel */
412
- init(): Promise<void>;
413
- /** Destroy kernel and cleanup */
414
- destroy(): void;
415
- /** Update configuration */
416
- configure(options: Partial<KernelOptions>): void;
417
- /** Get current configuration */
418
- getOptions(): KernelOptions;
419
- }
420
-
421
- /**
422
- * Token Store Plugin
423
- *
424
- * Core plugin for token state management.
425
- * Stores tokens in memory with metadata (setAt, refreshCount).
426
- */
427
-
428
- /**
429
- * Token Store API
430
- */
431
- interface TokenStoreAPI {
432
- set(tokens: TokenSet): void;
433
- get(): StoredTokens | null;
434
- clear(): void;
435
- getAccessToken(): string | null;
436
- getRefreshToken(): string | null;
437
- getTokenType(): string;
438
- getExpiresAt(): Date | null;
439
- getExpiresIn(): number | null;
440
- isExpired(): boolean;
441
- getSetAt(): Date | null;
442
- getRefreshCount(): number;
443
- }
444
- /**
445
- * Token Store Plugin Options
446
- */
447
- interface TokenStoreOptions {
448
- /** Reject access tokens that are not structurally valid JWTs (default: false) */
449
- validateOnSet?: boolean;
450
- /**
451
- * Persist tokens in this adapter (default: none, tokens live only in memory).
452
- * Tokens are restored from it when the plugin is installed.
453
- */
454
- storage?: StorageAdapter;
455
- /** Key used in `storage` (default: 'tokens') */
456
- storageKey?: string;
457
- onSet?: (tokens: StoredTokens) => void;
458
- onClear?: () => void;
459
- }
460
- /**
461
- * TokenStorePlugin class
462
- */
463
- declare class TokenStorePlugin implements Plugin {
464
- name: string;
465
- version: string;
466
- type: "core";
467
- private tokens;
468
- private options;
469
- private kernel;
470
- constructor(options?: TokenStoreOptions);
471
- install(kernel: AuthKeeper): TokenStoreAPI;
472
- /**
473
- * Set tokens
474
- */
475
- private set;
476
- /**
477
- * Get tokens
478
- */
479
- private get;
480
- /**
481
- * Clear tokens
482
- */
483
- private clear;
484
- /**
485
- * Uninstall plugin
486
- *
487
- * Drops the in-memory copy only: destroying an instance (e.g. on component
488
- * unmount) must not log the user out of the persisted session.
489
- */
490
- uninstall(): void;
491
- private get storageKey();
492
- /**
493
- * Write tokens to the storage adapter (null removes them).
494
- * Failures (quota exceeded, storage disabled, ...) are reported as an
495
- * 'error' event with context 'storage' instead of breaking setTokens().
496
- */
497
- private persist;
498
- /**
499
- * Load tokens from the storage adapter. Corrupt or malformed entries are
500
- * removed rather than trusted.
501
- */
502
- private restore;
503
- private reportStorageError;
504
- }
505
- /**
506
- * Create token-store plugin
507
- */
508
- declare function createTokenStorePlugin(options?: TokenStoreOptions): TokenStorePlugin;
509
-
510
- /**
511
- * Token Decoder Plugin
512
- *
513
- * Core plugin for JWT token decoding.
514
- * Does NOT validate signatures (client-side doesn't need to).
515
- */
516
-
517
- /**
518
- * Token Decoder API
519
- */
520
- interface TokenDecoderAPI {
521
- decode<T = TokenPayload>(token?: string): T | null;
522
- getHeader(token?: string): TokenHeader | null;
523
- getClaim<K extends keyof TokenPayload>(key: K, token?: string): TokenPayload[K] | undefined;
524
- getClaims<K extends keyof TokenPayload>(keys: K[], token?: string): Pick<TokenPayload, K>;
525
- getExpiry(token?: string): Date | null;
526
- isExpired(token?: string): boolean;
527
- getTokenInfo(token?: string): TokenInfo | null;
528
- }
529
- /**
530
- * TokenDecoderPlugin class
531
- */
532
- declare class TokenDecoderPlugin implements Plugin {
533
- name: string;
534
- version: string;
535
- type: "core";
536
- private kernel;
537
- install(kernel: AuthKeeper): TokenDecoderAPI;
538
- /**
539
- * Decode token payload
540
- */
541
- private decode;
542
- /**
543
- * Decode token header
544
- */
545
- private getHeader;
546
- /**
547
- * Get specific claim from token
548
- */
549
- private getClaimFromToken;
550
- /**
551
- * Get multiple claims from token
552
- */
553
- private getClaimsFromToken;
554
- /**
555
- * Get token expiry
556
- */
557
- private getExpiry;
558
- /**
559
- * Check if token is expired
560
- */
561
- private isExpiredToken;
562
- /**
563
- * Get complete token information
564
- */
565
- private getTokenInfo;
566
- uninstall(): void;
567
- }
568
- /**
569
- * Create token-decoder plugin
570
- */
571
- declare function createTokenDecoderPlugin(): TokenDecoderPlugin;
572
-
573
- /**
574
- * Refresh Engine Plugin
575
- *
576
- * Core plugin for automatic token refresh with queue management.
577
- * - Queues concurrent refresh requests
578
- * - Schedules refresh before expiry
579
- * - Retries with exponential backoff
580
- */
581
-
582
- /**
583
- * Refresh Engine API
584
- */
585
- interface RefreshEngineAPI {
586
- refresh(): Promise<TokenSet>;
587
- scheduleRefresh(): void;
588
- cancelScheduledRefresh(): void;
589
- isRefreshing(): boolean;
590
- /** True only while a refresh result is being stored via kernel.setTokens() */
591
- isApplyingRefresh?(): boolean;
592
- getNextRefreshAt(): Date | null;
593
- setRefreshFn(fn: RefreshTokenFn): void;
594
- setThreshold(seconds: number): void;
595
- }
596
- /**
597
- * Refresh Engine Options
598
- */
599
- interface RefreshEngineOptions {
600
- refreshFn: RefreshTokenFn;
601
- threshold?: number;
602
- maxRetries?: number;
603
- retryDelay?: number;
604
- onRefreshStart?: () => void;
605
- onRefreshSuccess?: (tokens: TokenSet) => void;
606
- onRefreshError?: (error: Error) => void;
607
- }
608
- /**
609
- * RefreshEnginePlugin class
610
- */
611
- declare class RefreshEnginePlugin implements Plugin {
612
- name: string;
613
- version: string;
614
- type: "core";
615
- private kernel;
616
- private refreshFn;
617
- private isRefreshingFlag;
618
- private applyingRefresh;
619
- private refreshPromise;
620
- private scheduledRefreshTimeout;
621
- private threshold;
622
- private maxRetries;
623
- private retryDelay;
624
- private options;
625
- constructor(options: RefreshEngineOptions);
626
- install(kernel: AuthKeeper): RefreshEngineAPI;
627
- /**
628
- * Refresh tokens
629
- *
630
- * Queues concurrent requests - only one refresh executes at a time.
631
- */
632
- private refresh;
633
- /**
634
- * Execute token refresh with retry logic
635
- */
636
- private executeRefresh;
637
- /**
638
- * Schedule automatic refresh
639
- *
640
- * Schedules refresh before token expires (threshold seconds before).
641
- */
642
- private scheduleRefresh;
643
- /**
644
- * Whether the kernel has automatic refresh enabled (default: true)
645
- */
646
- private isAutoRefreshEnabled;
647
- /**
648
- * Cancel scheduled refresh
649
- */
650
- private cancelScheduledRefresh;
651
- /**
652
- * Get next scheduled refresh time
653
- */
654
- private getNextRefreshAt;
655
- /**
656
- * Uninstall plugin
657
- */
658
- uninstall(): void;
659
- }
660
- /**
661
- * Create refresh-engine plugin
662
- */
663
- declare function createRefreshEnginePlugin(options: RefreshEngineOptions): RefreshEnginePlugin;
664
-
665
- /**
666
- * Memory Storage Plugin
667
- *
668
- * Core plugin for in-memory token storage.
669
- * - Most secure (not accessible via XSS)
670
- * - Lost on page refresh
671
- * - Not shared across tabs
672
- */
673
-
674
- /**
675
- * Memory Storage Options
676
- */
677
- interface MemoryStorageOptions {
678
- prefix?: string;
679
- }
680
- /**
681
- * Memory Storage Adapter
682
- *
683
- * Stores data in a Map (in memory).
684
- * Data is lost on page refresh.
685
- */
686
- declare class MemoryStorageAdapter implements StorageAdapter {
687
- private store;
688
- private prefix;
689
- constructor(options?: MemoryStorageOptions);
690
- /**
691
- * Get value by key
692
- */
693
- get(key: string): string | null;
694
- /**
695
- * Set value by key
696
- */
697
- set(key: string, value: string): void;
698
- /**
699
- * Remove value by key
700
- */
701
- remove(key: string): void;
702
- /**
703
- * Clear all values
704
- */
705
- clear(): void;
706
- }
707
- /**
708
- * Create memory storage adapter
709
- */
710
- declare function createMemoryStorage(options?: MemoryStorageOptions): MemoryStorageAdapter;
711
-
712
- /**
713
- * Cookie utilities
714
- *
715
- * Helper functions for parsing and serializing cookies.
716
- */
717
- /**
718
- * Cookie attributes for serialization
719
- */
720
- interface CookieAttributes {
721
- /** Path where cookie is valid (default: '/') */
722
- path?: string;
723
- /** Domain where cookie is valid */
724
- domain?: string;
725
- /** Max age in seconds */
726
- maxAge?: number;
727
- /** Expiration date */
728
- expires?: Date;
729
- /** Secure flag (HTTPS only) */
730
- secure?: boolean;
731
- /** SameSite attribute */
732
- sameSite?: 'strict' | 'lax' | 'none';
733
- /** HttpOnly flag (not accessible via JavaScript) */
734
- httpOnly?: boolean;
735
- }
736
- /**
737
- * Parse document.cookie string into key-value pairs
738
- *
739
- * @param cookieString - Cookie string from document.cookie
740
- * @returns Object with cookie key-value pairs
741
- */
742
- declare function parseCookies(cookieString: string): Record<string, string>;
743
- /**
744
- * Get cookie value by name
745
- *
746
- * @param name - Cookie name
747
- * @returns Cookie value or null if not found
748
- */
749
- declare function getCookie(name: string): string | null;
750
- /**
751
- * Serialize cookie with attributes to Set-Cookie format
752
- *
753
- * @param name - Cookie name
754
- * @param value - Cookie value
755
- * @param attributes - Cookie attributes
756
- * @returns Set-Cookie header value
757
- */
758
- declare function serializeCookie(name: string, value: string, attributes?: CookieAttributes): string;
759
- /**
760
- * Set cookie in document
761
- *
762
- * @param name - Cookie name
763
- * @param value - Cookie value
764
- * @param attributes - Cookie attributes
765
- */
766
- declare function setCookie(name: string, value: string, attributes?: CookieAttributes): void;
767
- /**
768
- * Delete cookie by name
769
- *
770
- * @param name - Cookie name
771
- * @param attributes - Cookie attributes (path and domain should match original)
772
- */
773
- declare function deleteCookie(name: string, attributes?: Omit<CookieAttributes, 'maxAge' | 'expires'>): void;
774
-
775
- /**
776
- * Browser Storage Adapters
777
- *
778
- * StorageAdapter implementations backed by Web Storage (localStorage /
779
- * sessionStorage) and document.cookie.
780
- *
781
- * Security note: anything stored here is readable by any script running on
782
- * the page (XSS). In-memory storage (the default) is the safest choice; use
783
- * these only when tokens must survive a page reload.
784
- */
785
-
786
- /**
787
- * Web Storage adapter options
788
- */
789
- interface WebStorageOptions {
790
- /** Key prefix (default: 'authkeeper:') */
791
- prefix?: string;
792
- }
793
- /**
794
- * StorageAdapter backed by a Web Storage object (localStorage / sessionStorage)
795
- */
796
- declare class WebStorageAdapter implements StorageAdapter {
797
- private storage;
798
- private prefix;
799
- constructor(storage: Storage, options?: WebStorageOptions);
800
- get(key: string): string | null;
801
- set(key: string, value: string): void;
802
- remove(key: string): void;
803
- clear(): void;
804
- }
805
- /**
806
- * Cookie adapter options
807
- */
808
- interface CookieStorageOptions {
809
- /** Cookie name prefix (default: 'authkeeper_') */
810
- prefix?: string;
811
- /**
812
- * Cookie attributes. Defaults: `path: '/'`, `secure: true`,
813
- * `sameSite: 'strict'`. HttpOnly cannot be set from JavaScript.
814
- */
815
- attributes?: Omit<CookieAttributes, 'httpOnly'>;
816
- }
817
- /**
818
- * StorageAdapter backed by document.cookie
819
- */
820
- declare class CookieStorageAdapter implements StorageAdapter {
821
- private prefix;
822
- private attributes;
823
- private keys;
824
- constructor(options?: CookieStorageOptions);
825
- get(key: string): string | null;
826
- set(key: string, value: string): void;
827
- remove(key: string): void;
828
- clear(): void;
829
- }
830
- /**
831
- * Resolve the `storage` kernel option to a StorageAdapter.
832
- *
833
- * - `undefined` / `'memory'`: no persistence (returns `undefined`); tokens
834
- * live only in the token store's memory.
835
- * - `'localStorage'` / `'sessionStorage'`: Web Storage, falling back to an
836
- * in-memory adapter where it is unavailable (SSR, privacy mode).
837
- * - `'cookie'`: document.cookie, falling back to memory outside browsers.
838
- * - a StorageAdapter object: used as-is.
839
- *
840
- * @throws {AuthError} CONFIG_ERROR for an unknown storage type
841
- */
842
- declare function resolveStorage(storage: StorageType | StorageAdapter | undefined): StorageAdapter | undefined;
843
-
844
- /**
845
- * Fetch Interceptor Plugin
846
- *
847
- * Core plugin for fetch() wrapper with auth header injection and 401 retry.
848
- * - Injects Authorization header
849
- * - URL filtering (include/exclude)
850
- * - 401 retry after token refresh
851
- */
852
-
853
- /**
854
- * Fetch Interceptor API
855
- */
856
- interface FetchInterceptorAPI {
857
- createFetch(options?: FetchInterceptorOptions): AuthFetch;
858
- wrapFetch(fetch: typeof globalThis.fetch): void;
859
- unwrapFetch(): void;
860
- }
861
- /**
862
- * FetchInterceptorPlugin class
863
- */
864
- declare class FetchInterceptorPlugin implements Plugin {
865
- name: string;
866
- version: string;
867
- type: "core";
868
- private kernel;
869
- private originalFetch;
870
- /**
871
- * The fetch implementation used to perform requests.
872
- *
873
- * While the global fetch is wrapped, this is the original (unwrapped)
874
- * fetch; calling `globalThis.fetch` from inside the wrapper would recurse
875
- * into the wrapper itself.
876
- */
877
- private baseFetch;
878
- install(kernel: AuthKeeper): FetchInterceptorAPI;
879
- /**
880
- * Create authenticated fetch function
881
- */
882
- private createFetch;
883
- /**
884
- * Wrap global fetch with auth
885
- */
886
- private wrapFetch;
887
- /**
888
- * Restore original fetch
889
- */
890
- private unwrapFetch;
891
- uninstall(): void;
892
- }
893
- /**
894
- * Create fetch-interceptor plugin
895
- */
896
- declare function createFetchInterceptorPlugin(): FetchInterceptorPlugin;
897
-
898
- export { deleteCookie as $, type AuthKeeper as A, type TabSyncEvent as B, type CookieAttributes as C, type TokenDecoderAPI as D, type EventType as E, type FetchInterceptorOptions as F, TokenDecoderPlugin as G, type TokenInfo as H, type TokenStoreAPI as I, type TokenStoreOptions as J, type KernelOptions as K, type LogoutOptions as L, MemoryStorageAdapter as M, TokenStorePlugin as N, type UserInfo as O, type Plugin as P, type WebStorageOptions as Q, type RefreshEngineAPI as R, type StorageAdapter as S, type TokenSet as T, type Unsubscribe as U, createFetchInterceptorPlugin as V, WebStorageAdapter as W, createMemoryStorage as X, createRefreshEnginePlugin as Y, createTokenDecoderPlugin as Z, createTokenStorePlugin as _, type EventHandler as a, getCookie as a0, parseCookies as a1, serializeCookie as a2, setCookie as a3, resolveStorage as a4, type AuthEvent as b, type PluginInfo as c, type TokenPayload as d, type AuthFetch as e, type TokenHeader as f, AuthError as g, type AuthErrorCode as h, type AuthErrorOptions as i, CookieStorageAdapter as j, type CookieStorageOptions as k, type ErrorEvent as l, type ExpiredEvent as m, type FetchInterceptorAPI as n, FetchInterceptorPlugin as o, type LoginEvent as p, type LoginOptions as q, type LogoutEvent as r, type MemoryStorageOptions as s, type RefreshEngineOptions as t, RefreshEnginePlugin as u, type RefreshEvent as v, type RefreshTokenFn as w, type StorageChangeEvent as x, type StorageType as y, type StoredTokens as z };