@oxog/authkeeper 1.0.0 → 1.2.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/CHANGELOG.md +148 -0
- package/README.md +79 -43
- package/dist/chunk-5GAJ7NPE.js +1004 -0
- package/dist/chunk-5GAJ7NPE.js.map +1 -0
- package/dist/chunk-LIWNMGFE.cjs +1041 -0
- package/dist/chunk-LIWNMGFE.cjs.map +1 -0
- package/dist/{index-Dv1VLP97.d.cts → index-1SDXWlt6.d.cts} +183 -7
- package/dist/{index-Dv1VLP97.d.ts → index-1SDXWlt6.d.ts} +183 -7
- package/dist/index.cjs +169 -709
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -4
- package/dist/index.d.ts +43 -4
- package/dist/index.js +20 -675
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +56 -628
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -619
- package/dist/plugins/index.js.map +1 -1
- package/package.json +52 -24
|
@@ -231,7 +231,7 @@ interface Plugin {
|
|
|
231
231
|
install(kernel: AuthKeeper): any;
|
|
232
232
|
/** Uninstall plugin and cleanup */
|
|
233
233
|
uninstall?(): void | Promise<void>;
|
|
234
|
-
/**
|
|
234
|
+
/** Reserved lifecycle hooks; not invoked by the kernel yet */
|
|
235
235
|
hooks?: {
|
|
236
236
|
/** Called before tokens are set */
|
|
237
237
|
beforeSetTokens?: (tokens: TokenSet) => TokenSet | false;
|
|
@@ -274,15 +274,19 @@ type RefreshTokenFn = (refreshToken: string) => Promise<TokenSet>;
|
|
|
274
274
|
* Kernel configuration options
|
|
275
275
|
*/
|
|
276
276
|
interface KernelOptions {
|
|
277
|
-
/**
|
|
278
|
-
|
|
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;
|
|
279
283
|
/** Function to refresh tokens */
|
|
280
284
|
refreshToken: RefreshTokenFn;
|
|
281
285
|
/** Enable automatic token refresh (default: true) */
|
|
282
286
|
autoRefresh?: boolean;
|
|
283
287
|
/** Seconds before expiry to refresh (default: 60) */
|
|
284
288
|
refreshThreshold?: number;
|
|
285
|
-
/**
|
|
289
|
+
/** Reserved for multi-tab sync; not implemented yet (currently a no-op) */
|
|
286
290
|
syncTabs?: boolean;
|
|
287
291
|
/** Error handler */
|
|
288
292
|
onError?: (error: AuthError) => void;
|
|
@@ -293,7 +297,7 @@ interface KernelOptions {
|
|
|
293
297
|
* Logout options
|
|
294
298
|
*/
|
|
295
299
|
interface LogoutOptions {
|
|
296
|
-
/**
|
|
300
|
+
/** Reserved for multi-tab logout; not implemented yet (currently a no-op) */
|
|
297
301
|
allTabs?: boolean;
|
|
298
302
|
/** Redirect URL after logout */
|
|
299
303
|
redirect?: string;
|
|
@@ -435,7 +439,15 @@ interface TokenStoreAPI {
|
|
|
435
439
|
* Token Store Plugin Options
|
|
436
440
|
*/
|
|
437
441
|
interface TokenStoreOptions {
|
|
442
|
+
/** Reject access tokens that are not structurally valid JWTs (default: false) */
|
|
438
443
|
validateOnSet?: boolean;
|
|
444
|
+
/**
|
|
445
|
+
* Persist tokens in this adapter (default: none, tokens live only in memory).
|
|
446
|
+
* Tokens are restored from it when the plugin is installed.
|
|
447
|
+
*/
|
|
448
|
+
storage?: StorageAdapter;
|
|
449
|
+
/** Key used in `storage` (default: 'tokens') */
|
|
450
|
+
storageKey?: string;
|
|
439
451
|
onSet?: (tokens: StoredTokens) => void;
|
|
440
452
|
onClear?: () => void;
|
|
441
453
|
}
|
|
@@ -448,8 +460,9 @@ declare class TokenStorePlugin implements Plugin {
|
|
|
448
460
|
type: "core";
|
|
449
461
|
private tokens;
|
|
450
462
|
private options;
|
|
463
|
+
private kernel;
|
|
451
464
|
constructor(options?: TokenStoreOptions);
|
|
452
|
-
install(
|
|
465
|
+
install(kernel: AuthKeeper): TokenStoreAPI;
|
|
453
466
|
/**
|
|
454
467
|
* Set tokens
|
|
455
468
|
*/
|
|
@@ -464,8 +477,24 @@ declare class TokenStorePlugin implements Plugin {
|
|
|
464
477
|
private clear;
|
|
465
478
|
/**
|
|
466
479
|
* Uninstall plugin
|
|
480
|
+
*
|
|
481
|
+
* Drops the in-memory copy only: destroying an instance (e.g. on component
|
|
482
|
+
* unmount) must not log the user out of the persisted session.
|
|
467
483
|
*/
|
|
468
484
|
uninstall(): void;
|
|
485
|
+
private get storageKey();
|
|
486
|
+
/**
|
|
487
|
+
* Write tokens to the storage adapter (null removes them).
|
|
488
|
+
* Failures (quota exceeded, storage disabled, ...) are reported as an
|
|
489
|
+
* 'error' event with context 'storage' instead of breaking setTokens().
|
|
490
|
+
*/
|
|
491
|
+
private persist;
|
|
492
|
+
/**
|
|
493
|
+
* Load tokens from the storage adapter. Corrupt or malformed entries are
|
|
494
|
+
* removed rather than trusted.
|
|
495
|
+
*/
|
|
496
|
+
private restore;
|
|
497
|
+
private reportStorageError;
|
|
469
498
|
}
|
|
470
499
|
/**
|
|
471
500
|
* Create token-store plugin
|
|
@@ -552,6 +581,8 @@ interface RefreshEngineAPI {
|
|
|
552
581
|
scheduleRefresh(): void;
|
|
553
582
|
cancelScheduledRefresh(): void;
|
|
554
583
|
isRefreshing(): boolean;
|
|
584
|
+
/** True only while a refresh result is being stored via kernel.setTokens() */
|
|
585
|
+
isApplyingRefresh?(): boolean;
|
|
555
586
|
getNextRefreshAt(): Date | null;
|
|
556
587
|
setRefreshFn(fn: RefreshTokenFn): void;
|
|
557
588
|
setThreshold(seconds: number): void;
|
|
@@ -578,6 +609,7 @@ declare class RefreshEnginePlugin implements Plugin {
|
|
|
578
609
|
private kernel;
|
|
579
610
|
private refreshFn;
|
|
580
611
|
private isRefreshingFlag;
|
|
612
|
+
private applyingRefresh;
|
|
581
613
|
private refreshPromise;
|
|
582
614
|
private scheduledRefreshTimeout;
|
|
583
615
|
private threshold;
|
|
@@ -602,6 +634,10 @@ declare class RefreshEnginePlugin implements Plugin {
|
|
|
602
634
|
* Schedules refresh before token expires (threshold seconds before).
|
|
603
635
|
*/
|
|
604
636
|
private scheduleRefresh;
|
|
637
|
+
/**
|
|
638
|
+
* Whether the kernel has automatic refresh enabled (default: true)
|
|
639
|
+
*/
|
|
640
|
+
private isAutoRefreshEnabled;
|
|
605
641
|
/**
|
|
606
642
|
* Cancel scheduled refresh
|
|
607
643
|
*/
|
|
@@ -667,6 +703,138 @@ declare class MemoryStorageAdapter implements StorageAdapter {
|
|
|
667
703
|
*/
|
|
668
704
|
declare function createMemoryStorage(options?: MemoryStorageOptions): MemoryStorageAdapter;
|
|
669
705
|
|
|
706
|
+
/**
|
|
707
|
+
* Cookie utilities
|
|
708
|
+
*
|
|
709
|
+
* Helper functions for parsing and serializing cookies.
|
|
710
|
+
*/
|
|
711
|
+
/**
|
|
712
|
+
* Cookie attributes for serialization
|
|
713
|
+
*/
|
|
714
|
+
interface CookieAttributes {
|
|
715
|
+
/** Path where cookie is valid (default: '/') */
|
|
716
|
+
path?: string;
|
|
717
|
+
/** Domain where cookie is valid */
|
|
718
|
+
domain?: string;
|
|
719
|
+
/** Max age in seconds */
|
|
720
|
+
maxAge?: number;
|
|
721
|
+
/** Expiration date */
|
|
722
|
+
expires?: Date;
|
|
723
|
+
/** Secure flag (HTTPS only) */
|
|
724
|
+
secure?: boolean;
|
|
725
|
+
/** SameSite attribute */
|
|
726
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
727
|
+
/** HttpOnly flag (not accessible via JavaScript) */
|
|
728
|
+
httpOnly?: boolean;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Parse document.cookie string into key-value pairs
|
|
732
|
+
*
|
|
733
|
+
* @param cookieString - Cookie string from document.cookie
|
|
734
|
+
* @returns Object with cookie key-value pairs
|
|
735
|
+
*/
|
|
736
|
+
declare function parseCookies(cookieString: string): Record<string, string>;
|
|
737
|
+
/**
|
|
738
|
+
* Get cookie value by name
|
|
739
|
+
*
|
|
740
|
+
* @param name - Cookie name
|
|
741
|
+
* @returns Cookie value or null if not found
|
|
742
|
+
*/
|
|
743
|
+
declare function getCookie(name: string): string | null;
|
|
744
|
+
/**
|
|
745
|
+
* Serialize cookie with attributes to Set-Cookie format
|
|
746
|
+
*
|
|
747
|
+
* @param name - Cookie name
|
|
748
|
+
* @param value - Cookie value
|
|
749
|
+
* @param attributes - Cookie attributes
|
|
750
|
+
* @returns Set-Cookie header value
|
|
751
|
+
*/
|
|
752
|
+
declare function serializeCookie(name: string, value: string, attributes?: CookieAttributes): string;
|
|
753
|
+
/**
|
|
754
|
+
* Set cookie in document
|
|
755
|
+
*
|
|
756
|
+
* @param name - Cookie name
|
|
757
|
+
* @param value - Cookie value
|
|
758
|
+
* @param attributes - Cookie attributes
|
|
759
|
+
*/
|
|
760
|
+
declare function setCookie(name: string, value: string, attributes?: CookieAttributes): void;
|
|
761
|
+
/**
|
|
762
|
+
* Delete cookie by name
|
|
763
|
+
*
|
|
764
|
+
* @param name - Cookie name
|
|
765
|
+
* @param attributes - Cookie attributes (path and domain should match original)
|
|
766
|
+
*/
|
|
767
|
+
declare function deleteCookie(name: string, attributes?: Omit<CookieAttributes, 'maxAge' | 'expires'>): void;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Browser Storage Adapters
|
|
771
|
+
*
|
|
772
|
+
* StorageAdapter implementations backed by Web Storage (localStorage /
|
|
773
|
+
* sessionStorage) and document.cookie.
|
|
774
|
+
*
|
|
775
|
+
* Security note: anything stored here is readable by any script running on
|
|
776
|
+
* the page (XSS). In-memory storage (the default) is the safest choice; use
|
|
777
|
+
* these only when tokens must survive a page reload.
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Web Storage adapter options
|
|
782
|
+
*/
|
|
783
|
+
interface WebStorageOptions {
|
|
784
|
+
/** Key prefix (default: 'authkeeper:') */
|
|
785
|
+
prefix?: string;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* StorageAdapter backed by a Web Storage object (localStorage / sessionStorage)
|
|
789
|
+
*/
|
|
790
|
+
declare class WebStorageAdapter implements StorageAdapter {
|
|
791
|
+
private storage;
|
|
792
|
+
private prefix;
|
|
793
|
+
constructor(storage: Storage, options?: WebStorageOptions);
|
|
794
|
+
get(key: string): string | null;
|
|
795
|
+
set(key: string, value: string): void;
|
|
796
|
+
remove(key: string): void;
|
|
797
|
+
clear(): void;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Cookie adapter options
|
|
801
|
+
*/
|
|
802
|
+
interface CookieStorageOptions {
|
|
803
|
+
/** Cookie name prefix (default: 'authkeeper_') */
|
|
804
|
+
prefix?: string;
|
|
805
|
+
/**
|
|
806
|
+
* Cookie attributes. Defaults: `path: '/'`, `secure: true`,
|
|
807
|
+
* `sameSite: 'strict'`. HttpOnly cannot be set from JavaScript.
|
|
808
|
+
*/
|
|
809
|
+
attributes?: Omit<CookieAttributes, 'httpOnly'>;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* StorageAdapter backed by document.cookie
|
|
813
|
+
*/
|
|
814
|
+
declare class CookieStorageAdapter implements StorageAdapter {
|
|
815
|
+
private prefix;
|
|
816
|
+
private attributes;
|
|
817
|
+
private keys;
|
|
818
|
+
constructor(options?: CookieStorageOptions);
|
|
819
|
+
get(key: string): string | null;
|
|
820
|
+
set(key: string, value: string): void;
|
|
821
|
+
remove(key: string): void;
|
|
822
|
+
clear(): void;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Resolve the `storage` kernel option to a StorageAdapter.
|
|
826
|
+
*
|
|
827
|
+
* - `undefined` / `'memory'`: no persistence (returns `undefined`); tokens
|
|
828
|
+
* live only in the token store's memory.
|
|
829
|
+
* - `'localStorage'` / `'sessionStorage'`: Web Storage, falling back to an
|
|
830
|
+
* in-memory adapter where it is unavailable (SSR, privacy mode).
|
|
831
|
+
* - `'cookie'`: document.cookie, falling back to memory outside browsers.
|
|
832
|
+
* - a StorageAdapter object: used as-is.
|
|
833
|
+
*
|
|
834
|
+
* @throws {AuthError} CONFIG_ERROR for an unknown storage type
|
|
835
|
+
*/
|
|
836
|
+
declare function resolveStorage(storage: StorageType | StorageAdapter | undefined): StorageAdapter | undefined;
|
|
837
|
+
|
|
670
838
|
/**
|
|
671
839
|
* Fetch Interceptor Plugin
|
|
672
840
|
*
|
|
@@ -693,6 +861,14 @@ declare class FetchInterceptorPlugin implements Plugin {
|
|
|
693
861
|
type: "core";
|
|
694
862
|
private kernel;
|
|
695
863
|
private originalFetch;
|
|
864
|
+
/**
|
|
865
|
+
* The fetch implementation used to perform requests.
|
|
866
|
+
*
|
|
867
|
+
* While the global fetch is wrapped, this is the original (unwrapped)
|
|
868
|
+
* fetch; calling `globalThis.fetch` from inside the wrapper would recurse
|
|
869
|
+
* into the wrapper itself.
|
|
870
|
+
*/
|
|
871
|
+
private baseFetch;
|
|
696
872
|
install(kernel: AuthKeeper): FetchInterceptorAPI;
|
|
697
873
|
/**
|
|
698
874
|
* Create authenticated fetch function
|
|
@@ -713,4 +889,4 @@ declare class FetchInterceptorPlugin implements Plugin {
|
|
|
713
889
|
*/
|
|
714
890
|
declare function createFetchInterceptorPlugin(): FetchInterceptorPlugin;
|
|
715
891
|
|
|
716
|
-
export { type AuthKeeper as A, createTokenDecoderPlugin as B,
|
|
892
|
+
export { getCookie as $, type AuthKeeper as A, createTokenDecoderPlugin as B, CookieStorageAdapter as C, createRefreshEnginePlugin as D, type EventType as E, type FetchInterceptorOptions as F, createMemoryStorage as G, createFetchInterceptorPlugin as H, type TokenStoreAPI as I, type TokenStoreOptions as J, type KernelOptions as K, type LogoutOptions as L, MemoryStorageAdapter as M, type TokenDecoderAPI as N, type RefreshEngineAPI as O, type Plugin as P, type RefreshEngineOptions as Q, type RefreshEvent as R, type StorageAdapter as S, type TokenSet as T, type Unsubscribe as U, type MemoryStorageOptions as V, WebStorageAdapter as W, type WebStorageOptions as X, type CookieStorageOptions as Y, type FetchInterceptorAPI as Z, parseCookies as _, type EventHandler as a, serializeCookie as a0, setCookie as a1, deleteCookie as a2, type CookieAttributes 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, type TokenInfo as g, type StoredTokens as h, type AuthErrorCode as i, type AuthErrorOptions as j, type LoginEvent as k, type LogoutEvent as l, type ExpiredEvent as m, type ErrorEvent as n, type StorageChangeEvent as o, type TabSyncEvent as p, type StorageType as q, type LoginOptions as r, type UserInfo as s, type RefreshTokenFn as t, AuthError as u, TokenStorePlugin as v, TokenDecoderPlugin as w, RefreshEnginePlugin as x, FetchInterceptorPlugin as y, createTokenStorePlugin as z };
|