UNPKG

2.11 kBTypeScriptView Raw
1import { IdToken, User } from '../global';
2export declare const CACHE_KEY_PREFIX = "@@auth0spajs@@";
3export declare const CACHE_KEY_ID_TOKEN_SUFFIX = "@@user@@";
4export declare type CacheKeyData = {
5 audience?: string;
6 scope?: string;
7 clientId: string;
8};
9export declare class CacheKey {
10 prefix: string;
11 suffix?: string | undefined;
12 clientId: string;
13 scope?: string;
14 audience?: string;
15 constructor(data: CacheKeyData, prefix?: string, suffix?: string | undefined);
16 /**
17 * Converts this `CacheKey` instance into a string for use in a cache
18 * @returns A string representation of the key
19 */
20 toKey(): string;
21 /**
22 * Converts a cache key string into a `CacheKey` instance.
23 * @param key The key to convert
24 * @returns An instance of `CacheKey`
25 */
26 static fromKey(key: string): CacheKey;
27 /**
28 * Utility function to build a `CacheKey` instance from a cache entry
29 * @param entry The entry
30 * @returns An instance of `CacheKey`
31 */
32 static fromCacheEntry(entry: CacheEntry): CacheKey;
33}
34export interface DecodedToken {
35 claims: IdToken;
36 user: User;
37}
38export interface IdTokenEntry {
39 id_token: string;
40 decodedToken: DecodedToken;
41}
42export declare type CacheEntry = {
43 id_token?: string;
44 access_token: string;
45 expires_in: number;
46 decodedToken?: DecodedToken;
47 audience: string;
48 scope: string;
49 client_id: string;
50 refresh_token?: string;
51 oauthTokenScope?: string;
52};
53export declare type WrappedCacheEntry = {
54 body: Partial<CacheEntry>;
55 expiresAt: number;
56};
57export declare type KeyManifestEntry = {
58 keys: string[];
59};
60export declare type Cacheable = WrappedCacheEntry | KeyManifestEntry;
61export declare type MaybePromise<T> = Promise<T> | T;
62export interface ICache {
63 set<T = Cacheable>(key: string, entry: T): MaybePromise<void>;
64 get<T = Cacheable>(key: string): MaybePromise<T | undefined>;
65 remove(key: string): MaybePromise<void>;
66 allKeys?(): MaybePromise<string[]>;
67}