arethesis 0.0.0-stage → 0.1.1

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 (150) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +21 -0
  3. package/README.md +122 -2
  4. package/dist/arethesis-DTJOJ7F-.js +5179 -0
  5. package/dist/arethesis-DTJOJ7F-.js.map +1 -0
  6. package/dist/arethesis.js +147 -0
  7. package/dist/arethesis.js.map +1 -0
  8. package/dist/binding/data-binder.d.ts +82 -0
  9. package/dist/binding/data-binder.d.ts.map +1 -0
  10. package/dist/binding/types.d.ts +119 -0
  11. package/dist/binding/types.d.ts.map +1 -0
  12. package/dist/binding/validation-engine.d.ts +22 -0
  13. package/dist/binding/validation-engine.d.ts.map +1 -0
  14. package/dist/components/component.d.ts +93 -0
  15. package/dist/components/component.d.ts.map +1 -0
  16. package/dist/components/decorators.d.ts +9 -0
  17. package/dist/components/decorators.d.ts.map +1 -0
  18. package/dist/components/runtime.d.ts +17 -0
  19. package/dist/components/runtime.d.ts.map +1 -0
  20. package/dist/components/template-loader.d.ts +37 -0
  21. package/dist/components/template-loader.d.ts.map +1 -0
  22. package/dist/components/types.d.ts +22 -0
  23. package/dist/components/types.d.ts.map +1 -0
  24. package/dist/components.js +609 -0
  25. package/dist/components.js.map +1 -0
  26. package/dist/core/arethesis.d.ts +97 -0
  27. package/dist/core/arethesis.d.ts.map +1 -0
  28. package/dist/core/types.d.ts +40 -0
  29. package/dist/core/types.d.ts.map +1 -0
  30. package/dist/data/list-view-registry.d.ts +69 -0
  31. package/dist/data/list-view-registry.d.ts.map +1 -0
  32. package/dist/data/object-store.d.ts +88 -0
  33. package/dist/data/object-store.d.ts.map +1 -0
  34. package/dist/data/optimistic-updates.d.ts +59 -0
  35. package/dist/data/optimistic-updates.d.ts.map +1 -0
  36. package/dist/data/persistence-manager.d.ts +56 -0
  37. package/dist/data/persistence-manager.d.ts.map +1 -0
  38. package/dist/data/types.d.ts +145 -0
  39. package/dist/data/types.d.ts.map +1 -0
  40. package/dist/http/auth-manager.d.ts +60 -0
  41. package/dist/http/auth-manager.d.ts.map +1 -0
  42. package/dist/http/http-client.d.ts +77 -0
  43. package/dist/http/http-client.d.ts.map +1 -0
  44. package/dist/http/http-error.d.ts +35 -0
  45. package/dist/http/http-error.d.ts.map +1 -0
  46. package/dist/http/mapping.d.ts +21 -0
  47. package/dist/http/mapping.d.ts.map +1 -0
  48. package/dist/http/types.d.ts +237 -0
  49. package/dist/http/types.d.ts.map +1 -0
  50. package/dist/index.d.ts +60 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/kit/data-table.d.ts +57 -0
  53. package/dist/kit/data-table.d.ts.map +1 -0
  54. package/dist/kit/flex-view.d.ts +42 -0
  55. package/dist/kit/flex-view.d.ts.map +1 -0
  56. package/dist/kit/form.d.ts +13 -0
  57. package/dist/kit/form.d.ts.map +1 -0
  58. package/dist/kit/index.d.ts +24 -0
  59. package/dist/kit/index.d.ts.map +1 -0
  60. package/dist/kit/list.d.ts +10 -0
  61. package/dist/kit/list.d.ts.map +1 -0
  62. package/dist/kit/theme-boot.generated.d.ts +3 -0
  63. package/dist/kit/theme-boot.generated.d.ts.map +1 -0
  64. package/dist/kit/theme.d.ts +34 -0
  65. package/dist/kit/theme.d.ts.map +1 -0
  66. package/dist/mixins/context-menu.d.ts +3 -0
  67. package/dist/mixins/context-menu.d.ts.map +1 -0
  68. package/dist/mixins/draggable.d.ts +3 -0
  69. package/dist/mixins/draggable.d.ts.map +1 -0
  70. package/dist/mixins/dropdown.d.ts +3 -0
  71. package/dist/mixins/dropdown.d.ts.map +1 -0
  72. package/dist/mixins/editable.d.ts +3 -0
  73. package/dist/mixins/editable.d.ts.map +1 -0
  74. package/dist/mixins/grid-navigation.d.ts +3 -0
  75. package/dist/mixins/grid-navigation.d.ts.map +1 -0
  76. package/dist/mixins/index.d.ts +19 -0
  77. package/dist/mixins/index.d.ts.map +1 -0
  78. package/dist/mixins/infinite-scroll.d.ts +3 -0
  79. package/dist/mixins/infinite-scroll.d.ts.map +1 -0
  80. package/dist/mixins/registry.d.ts +41 -0
  81. package/dist/mixins/registry.d.ts.map +1 -0
  82. package/dist/mixins/resizable.d.ts +3 -0
  83. package/dist/mixins/resizable.d.ts.map +1 -0
  84. package/dist/mixins/sortable.d.ts +3 -0
  85. package/dist/mixins/sortable.d.ts.map +1 -0
  86. package/dist/mixins/tooltip.d.ts +3 -0
  87. package/dist/mixins/tooltip.d.ts.map +1 -0
  88. package/dist/mixins/types.d.ts +165 -0
  89. package/dist/mixins/types.d.ts.map +1 -0
  90. package/dist/mixins/utils.d.ts +22 -0
  91. package/dist/mixins/utils.d.ts.map +1 -0
  92. package/dist/plugins/async-validators.d.ts +9 -0
  93. package/dist/plugins/async-validators.d.ts.map +1 -0
  94. package/dist/plugins/builtins.d.ts +9 -0
  95. package/dist/plugins/builtins.d.ts.map +1 -0
  96. package/dist/plugins/date-utils.d.ts +16 -0
  97. package/dist/plugins/date-utils.d.ts.map +1 -0
  98. package/dist/plugins/plugin-manager.d.ts +29 -0
  99. package/dist/plugins/plugin-manager.d.ts.map +1 -0
  100. package/dist/plugins/rich-text.d.ts +15 -0
  101. package/dist/plugins/rich-text.d.ts.map +1 -0
  102. package/dist/plugins/types.d.ts +50 -0
  103. package/dist/plugins/types.d.ts.map +1 -0
  104. package/dist/realtime/azure-pubsub-manager.d.ts +49 -0
  105. package/dist/realtime/azure-pubsub-manager.d.ts.map +1 -0
  106. package/dist/realtime/collab/collab-session.d.ts +75 -0
  107. package/dist/realtime/collab/collab-session.d.ts.map +1 -0
  108. package/dist/realtime/collab/cursor-overlay.d.ts +20 -0
  109. package/dist/realtime/collab/cursor-overlay.d.ts.map +1 -0
  110. package/dist/realtime/collab/textarea-adapter.d.ts +27 -0
  111. package/dist/realtime/collab/textarea-adapter.d.ts.map +1 -0
  112. package/dist/realtime/ot/client.d.ts +27 -0
  113. package/dist/realtime/ot/client.d.ts.map +1 -0
  114. package/dist/realtime/ot/server.d.ts +36 -0
  115. package/dist/realtime/ot/server.d.ts.map +1 -0
  116. package/dist/realtime/ot/text-operation.d.ts +55 -0
  117. package/dist/realtime/ot/text-operation.d.ts.map +1 -0
  118. package/dist/realtime/reconnect.d.ts +22 -0
  119. package/dist/realtime/reconnect.d.ts.map +1 -0
  120. package/dist/realtime/sse-manager.d.ts +37 -0
  121. package/dist/realtime/sse-manager.d.ts.map +1 -0
  122. package/dist/realtime/types.d.ts +122 -0
  123. package/dist/realtime/types.d.ts.map +1 -0
  124. package/dist/realtime/websocket-manager.d.ts +34 -0
  125. package/dist/realtime/websocket-manager.d.ts.map +1 -0
  126. package/dist/theme-boot.js +17 -0
  127. package/dist/theme.css +680 -0
  128. package/dist/tokens/arethesis.resolver.json +57 -0
  129. package/dist/tokens/base.tokens.json +55 -0
  130. package/dist/tokens/dark-high-contrast.tokens.json +172 -0
  131. package/dist/tokens/dark.tokens.json +331 -0
  132. package/dist/tokens/light-high-contrast.tokens.json +115 -0
  133. package/dist/tokens/light.tokens.json +331 -0
  134. package/dist/utils/backoff.d.ts +18 -0
  135. package/dist/utils/backoff.d.ts.map +1 -0
  136. package/dist/utils/dates.d.ts +22 -0
  137. package/dist/utils/dates.d.ts.map +1 -0
  138. package/dist/utils/dom.d.ts +16 -0
  139. package/dist/utils/dom.d.ts.map +1 -0
  140. package/dist/utils/emitter.d.ts +17 -0
  141. package/dist/utils/emitter.d.ts.map +1 -0
  142. package/dist/utils/path.d.ts +33 -0
  143. package/dist/utils/path.d.ts.map +1 -0
  144. package/dist/utils/sanitize.d.ts +20 -0
  145. package/dist/utils/sanitize.d.ts.map +1 -0
  146. package/dist/utils/url.d.ts +16 -0
  147. package/dist/utils/url.d.ts.map +1 -0
  148. package/dist/version.d.ts +3 -0
  149. package/dist/version.d.ts.map +1 -0
  150. package/package.json +102 -4
@@ -0,0 +1,56 @@
1
+ import { StoredObject } from './types';
2
+ export interface PersistenceOptions {
3
+ /** Database name. @default 'arethesis' */
4
+ dbName?: string;
5
+ /** Drop persisted objects older than this many ms when loading. */
6
+ maxAge?: number;
7
+ /** Delay before flushing batched writes. @default 50 */
8
+ flushDelay?: number;
9
+ /**
10
+ * Give up opening the database after this many ms (some browsers and
11
+ * sandboxes never answer). Persistence is then disabled. @default 5000
12
+ */
13
+ openTimeout?: number;
14
+ }
15
+ export declare class PersistenceManager {
16
+ readonly dbName: string;
17
+ private readonly maxAge?;
18
+ private readonly flushDelay;
19
+ private readonly openTimeout;
20
+ private dbPromise;
21
+ private queue;
22
+ private flushTimer;
23
+ private flushing;
24
+ private _available;
25
+ constructor(options?: PersistenceOptions);
26
+ /** Whether IndexedDB exists in this environment. */
27
+ static isSupported(): boolean;
28
+ /** False once opening the database has failed. */
29
+ get available(): boolean;
30
+ /** Open the database. Resolves to null (and disables persistence) on failure. */
31
+ open(): Promise<IDBDatabase | null>;
32
+ /** Queue an object to be written. */
33
+ save(obj: StoredObject): void;
34
+ /** Queue an object to be removed. */
35
+ delete(type: string, id: string): void;
36
+ private scheduleFlush;
37
+ /** Write everything queued now. Resolves when the transaction completes. */
38
+ flush(): Promise<void>;
39
+ private request;
40
+ private revive;
41
+ private isExpired;
42
+ /** Load one object (null if missing or expired). */
43
+ load<T = unknown>(type: string, id: string): Promise<StoredObject<T> | null>;
44
+ /** Load every object, evicting expired ones. */
45
+ loadAll(): Promise<StoredObject[]>;
46
+ /** Load objects of one type. */
47
+ loadByType<T = unknown>(type: string): Promise<StoredObject<T>[]>;
48
+ count(): Promise<number>;
49
+ /** Remove every persisted object (pending writes are discarded). */
50
+ clear(): Promise<void>;
51
+ /** Close the connection. */
52
+ close(): Promise<void>;
53
+ /** Delete the whole database. */
54
+ deleteDatabase(): Promise<void>;
55
+ }
56
+ //# sourceMappingURL=persistence-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence-manager.d.ts","sourceRoot":"","sources":["../../src/data/persistence-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;G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EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAOlF,gDAAgD;IAC1C,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IASxC,gCAAgC;IAC1B,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAMjE,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B,oEAAoE;IAC9D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,4BAA4B;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,iCAAiC;IAC3B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAUtC"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Data layer types: the ObjectStore, ListViews and persistence.
3
+ *
4
+ * @module data/types
5
+ */
6
+ /**
7
+ * Freshness of a stored object.
8
+ * - `fresh`: recently fetched or written
9
+ * - `stale`: invalidated or past its TTL; should be refetched
10
+ * - `updating`: a refetch is in flight
11
+ * - `error`: the last refetch failed
12
+ */
13
+ export type ObjectStatus = 'fresh' | 'stale' | 'updating' | 'error';
14
+ /** Context passed to custom merge functions. */
15
+ export interface MergeContext {
16
+ /** Where the incoming data came from (`'api'`, `'sse'`, `'optimistic'`, ...). */
17
+ source: string;
18
+ /** Version of the object currently in the store. */
19
+ existingVersion: number;
20
+ /** Object type. */
21
+ type: string;
22
+ /** Object id. */
23
+ id: string;
24
+ }
25
+ /** Custom merge function. */
26
+ export type MergeFunction = (existing: unknown, incoming: unknown, context: MergeContext) => unknown;
27
+ /**
28
+ * How incoming data combines with what is already stored.
29
+ * - `replace`: incoming wins entirely
30
+ * - `shallow`: `{ ...existing, ...incoming }` (default)
31
+ * - `deep`: recursive merge of plain objects; arrays replace
32
+ */
33
+ export type MergeStrategy = 'replace' | 'shallow' | 'deep' | MergeFunction;
34
+ /** An object in the store, wrapped with metadata. */
35
+ export interface StoredObject<T = unknown> {
36
+ id: string;
37
+ type: string;
38
+ data: T;
39
+ /** Incremented on every write. */
40
+ version: number;
41
+ /** Milliseconds since epoch of the last write. */
42
+ lastUpdated: number;
43
+ /** Every source that has contributed data (`'api'`, `'sse'`, `'indexeddb'`, ...). */
44
+ sources: Set<string>;
45
+ status: ObjectStatus;
46
+ }
47
+ /** Per-type configuration, registered with `defineType()` or `store.registerType()`. */
48
+ export interface TypeConfig {
49
+ /** Type name, e.g. `'Person'`. */
50
+ name: string;
51
+ /** Field holding the unique id. @default 'id' */
52
+ idField?: string;
53
+ /** Default merge strategy. @default 'shallow' */
54
+ defaultMerge?: MergeStrategy;
55
+ /** Milliseconds after which an object is considered stale. */
56
+ ttl?: number;
57
+ /** Persist objects of this type to IndexedDB. @default true */
58
+ persist?: boolean;
59
+ /**
60
+ * Field used for conflict detection (a number or ISO timestamp, e.g. `'updatedAt'`).
61
+ * Incoming data with an older value than the stored object is ignored.
62
+ */
63
+ versionField?: string;
64
+ /**
65
+ * Name of a registered endpoint that fetches one object by `:id`.
66
+ * Used to refetch automatically when a bound object is invalidated.
67
+ */
68
+ endpoint?: string;
69
+ }
70
+ /** Options for `store.upsert()`. */
71
+ export interface UpsertOptions {
72
+ /** Override the type's merge strategy. */
73
+ merge?: MergeStrategy;
74
+ /** Source tag. @default 'api' */
75
+ source?: string;
76
+ /** Skip subscriber notifications. */
77
+ silent?: boolean;
78
+ /** Write even if `versionField` says the incoming data is older. */
79
+ force?: boolean;
80
+ }
81
+ /** Store change event. */
82
+ export type SubscriptionEvent = 'update' | 'delete' | 'invalidate';
83
+ /** Store subscriber. `obj` is `null` for deletes. */
84
+ export type Subscriber<T = unknown> = (obj: StoredObject<T> | null, event: SubscriptionEvent) => void;
85
+ /** Reference to a single stored object. */
86
+ export interface ObjectRef {
87
+ type: string;
88
+ id: string | number;
89
+ }
90
+ /** Sort criterion for a ListView. */
91
+ export interface SortConfig {
92
+ field: string;
93
+ direction: 'asc' | 'desc';
94
+ }
95
+ /** ListView lifecycle state. */
96
+ export type ListViewStatus = 'idle' | 'loading' | 'loaded' | 'loading-more' | 'error' | 'stale';
97
+ /** Configuration for `listViews.getOrCreate()`. */
98
+ export interface ListViewConfig {
99
+ /** Explicit id. Defaults to a deterministic id computed from the config. */
100
+ id?: string;
101
+ /** Object type of the items. */
102
+ type: string;
103
+ /** Name of the registered list endpoint that loads pages. */
104
+ endpoint?: string;
105
+ /** Filters sent to the endpoint as query parameters. */
106
+ filters?: Record<string, unknown>;
107
+ /** Sort order, sent as `sort=field:dir,field2:dir`. */
108
+ sort?: SortConfig[];
109
+ /** Items per page. @default 50 */
110
+ pageSize?: number;
111
+ }
112
+ /** A thin, ordered view over a list endpoint: ids plus pagination state. */
113
+ export interface ListView {
114
+ readonly id: string;
115
+ type: string;
116
+ endpoint?: string;
117
+ filters: Record<string, unknown>;
118
+ sort: SortConfig[];
119
+ pageSize: number;
120
+ /** Ordered ids of objects in the store. */
121
+ ids: string[];
122
+ nextCursor: string | null;
123
+ totalCount?: number;
124
+ hasMore: boolean;
125
+ status: ListViewStatus;
126
+ error?: Error;
127
+ /** When the first page was last loaded. */
128
+ lastFetched?: number;
129
+ }
130
+ /** Pagination details extracted from a list response. */
131
+ export interface PageInfo {
132
+ nextCursor?: string | null;
133
+ hasMore?: boolean;
134
+ totalCount?: number;
135
+ }
136
+ export type ListViewSubscriber = (view: ListView) => void;
137
+ /** Function that fetches a page for a ListView. Wired up by `Arethesis.init()`. */
138
+ export type ListViewLoader = (view: ListView, options: {
139
+ append: boolean;
140
+ signal?: AbortSignal;
141
+ }) => Promise<{
142
+ ids: string[];
143
+ page: PageInfo;
144
+ }>;
145
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/data/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,MAA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AAM,CAAC;CACnB;AAED,4EAA4E;AAC5E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;AAE1D,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,KAC/C,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { AuthConfig, TokenPayload } from './types';
2
+ import { Emitter } from '../utils/emitter';
3
+ export interface AuthEvents extends Record<string, unknown> {
4
+ /** Tokens were set (login or refresh). */
5
+ change: {
6
+ authenticated: boolean;
7
+ };
8
+ login: void;
9
+ logout: void;
10
+ refresh: void;
11
+ /** The session could not be refreshed. */
12
+ expired: void;
13
+ }
14
+ export declare class AuthManager extends Emitter<AuthEvents> {
15
+ readonly config: Required<Pick<AuthConfig, 'accessTokenKey' | 'refreshTokenKey' | 'refreshThreshold' | 'refreshBodyField'>> & AuthConfig;
16
+ private storage;
17
+ private refreshPromise;
18
+ private parsed;
19
+ private fetchImpl;
20
+ private resolveUrl;
21
+ private storageListener;
22
+ constructor(config: AuthConfig, options?: {
23
+ fetch?: () => typeof fetch;
24
+ resolveUrl?: (url: string) => string;
25
+ });
26
+ getAccessToken(): string | null;
27
+ getRefreshToken(): string | null;
28
+ setTokens(accessToken: string, refreshToken?: string | null): void;
29
+ clearTokens(): void;
30
+ /** Decode a JWT payload (memoized per token). Returns null for non-JWT tokens. */
31
+ parseToken(token: string): TokenPayload | null;
32
+ /** Claims of the current token, if it is a JWT. */
33
+ getUser<T extends TokenPayload = TokenPayload>(): T | null;
34
+ /** Seconds until the token expires (`Infinity` if it has no `exp`). */
35
+ secondsUntilExpiry(token: string): number;
36
+ isTokenExpired(token: string): boolean;
37
+ isTokenExpiringSoon(token: string): boolean;
38
+ /** A token exists and has not expired. Opaque tokens count as valid. */
39
+ isAuthenticated(): boolean;
40
+ /** Return a usable token, refreshing first if it is about to expire. */
41
+ ensureValidToken(): Promise<string | null>;
42
+ /** Refresh the access token. Concurrent calls share one request. */
43
+ refreshAccessToken(): Promise<boolean>;
44
+ private doRefresh;
45
+ private readTokens;
46
+ private expire;
47
+ /**
48
+ * Post credentials to `loginUrl` and store the returned tokens.
49
+ * Resolves to the response body on success, or `null` on failure.
50
+ */
51
+ login<T = unknown>(credentials: Record<string, unknown>): Promise<T | null>;
52
+ /**
53
+ * Tell the server (if `logoutUrl` is set) and clear tokens. The refresh token
54
+ * is sent in the body (under `refreshBodyField`) so the server can revoke it.
55
+ */
56
+ logout(): Promise<void>;
57
+ /** Remove listeners. */
58
+ dest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MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAWlE,WAAW,IAAI,IAAI;IAWnB,kFAAkF;IAClF,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAoB9C,mDAAmD;IACnD,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,KAAK,CAAC,GAAG,IAAI;IAK1D,uEAAuE;IACvE,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAMzC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI3C,wEAAwE;IACxE,eAAe,IAAI,OAAO;IAK1B,wEAAwE;IAClE,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAchD,oEAAoE;IACpE,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;YASxB,SAAS;YA6BT,UAAU;IAYxB,OAAO,CAAC,MAAM;IAQd;;;OAGG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAwBjF;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB7B,wBAAwB;IACxB,OAAO,IAAI,IAAI;CAKhB"}
@@ -0,0 +1,77 @@
1
+ import { BatchOperation, BatchResult, EndpointConfig, FetchOptions, FetchResult, HeaderMap, HttpConfig, Params, RequestConfig } from './types';
2
+ import { ObjectStore } from '../data/object-store';
3
+ import { ListViewRegistry } from '../data/list-view-registry';
4
+ import { ListView, PageInfo } from '../data/types';
5
+ import { AuthManager } from './auth-manager';
6
+ export declare class HttpClient {
7
+ private config;
8
+ private endpoints;
9
+ private auth;
10
+ private store;
11
+ private listViews;
12
+ private inflight;
13
+ private batchQueue;
14
+ private batchTimer;
15
+ private batchCounter;
16
+ constructor(config?: HttpConfig);
17
+ /** Merge new configuration (called by `Arethesis.init()`). */
18
+ configure(config: HttpConfig): void;
19
+ /** Wire the store, list views and auth manager. */
20
+ connect(deps: {
21
+ store?: ObjectStore;
22
+ listViews?: ListViewRegistry;
23
+ auth?: AuthManager | null;
24
+ }): void;
25
+ get baseUrl(): string;
26
+ /** Set a global header (a string or a function evaluated per request). */
27
+ setHeader(name: string, value: HeaderMap[string]): void;
28
+ removeHeader(name: string): void;
29
+ /** Register a named endpoint. */
30
+ defineEndpoint(name: string, config: EndpointConfig): EndpointConfig;
31
+ getEndpoint(name: string): EndpointConfig | undefined;
32
+ private requireEndpoint;
33
+ /** Resolve a relative URL against `baseUrl`. */
34
+ resolveUrl(url: string): string;
35
+ /** Fill `:params` in the path and append the rest as a query string. */
36
+ buildUrl(url: string, params?: Params): string;
37
+ /** Whether the bearer token may be sent to this URL. */
38
+ isTrustedUrl(url: string): boolean;
39
+ private resolveHeaders;
40
+ /**
41
+ * Make a request with retries. Resolves with the parsed body (`undefined` for
42
+ * empty responses) or rejects with an `HttpError`.
43
+ */
44
+ request<T = unknown>(config: RequestConfig): Promise<T>;
45
+ private requestWithRetry;
46
+ private send;
47
+ private readBody;
48
+ /**
49
+ * Call an endpoint, map the response and write it to the store.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const { data } = await http.fetchEndpoint('getPerson', { id: 7 }, { cache: 'swr' });
54
+ * ```
55
+ */
56
+ fetchEndpoint<T = unknown>(ref: string | EndpointConfig, params?: Params, options?: FetchOptions): Promise<FetchResult<T>>;
57
+ /** Map a response body for an endpoint and write it to the store. */
58
+ ingest<T>(endpoint: EndpointConfig, body: unknown, params?: Params, options?: Pick<FetchOptions, 'viewId' | 'append'>): FetchResult<T>;
59
+ /** Page loader for ListViews (wired up by `Arethesis.init()`). */
60
+ loadListView(view: ListView, options: {
61
+ append: boolean;
62
+ signal?: AbortSignal;
63
+ }): Promise<{
64
+ ids: string[];
65
+ page: PageInfo;
66
+ }>;
67
+ private resolveOp;
68
+ private requireBatch;
69
+ /**
70
+ * Send several operations through the batch endpoint. Results for operations
71
+ * that reference a typed endpoint are written to the store.
72
+ */
73
+ batch(operations: BatchOperation[]): Promise<BatchResult[]>;
74
+ private sendBatch;
75
+ private enqueueBatch;
76
+ }
77
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http/http-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAEV,cAAc,EACd,WAAW,EACX,cAAc,EACd,YAAY,EACZ,WAAW,EACX,SAAS,EACT,UAAU,EAEV,MAAM,EACN,aAAa,EAId,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA4BlD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,KAAK,CAA4B;IACzC,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,UAAU,CAAyI;IAC3J,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,YAAY,CAAK;gBAEb,MAAM,GAAE,UAAe;IAInC,8DAA8D;IAC9D,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAInC,mDAAmD;IACnD,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;Q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IAC5D,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC;IAclI,OAAO,CAAC,SAAS;IAgBjB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;IACG,KAAK,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YAUnD,SAAS;IAiBvB,OAAO,CAAC,YAAY;CAwBrB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * HttpError: a failed request, with status and parsed body.
3
+ *
4
+ * @module http/http-error
5
+ */
6
+ export type HttpErrorKind = 'http' | 'network' | 'timeout' | 'parse';
7
+ export interface HttpErrorDetails {
8
+ body?: unknown;
9
+ url?: string;
10
+ method?: string;
11
+ kind?: HttpErrorKind;
12
+ /** Seconds from a `Retry-After` header. */
13
+ retryAfter?: number;
14
+ }
15
+ export declare class HttpError extends Error {
16
+ readonly name = "HttpError";
17
+ readonly status: number;
18
+ readonly body: unknown;
19
+ readonly url?: string;
20
+ readonly method?: string;
21
+ readonly kind: HttpErrorKind;
22
+ readonly retryAfter?: number;
23
+ constructor(message: string, status: number, details?: HttpErrorDetails);
24
+ /** 4xx */
25
+ get isClientError(): boolean;
26
+ /** 5xx */
27
+ get isServerError(): boolean;
28
+ /** The request never got a response. */
29
+ get isNetworkError(): boolean;
30
+ get isTimeout(): boolean;
31
+ get isUnauthorized(): boolean;
32
+ /** A message from the body (`message`, `error`, `detail`), else the status text. */
33
+ get displayMessage(): string;
34
+ }
35
+ //# sourceMappingURL=http-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../src/http/http-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAkB,IAAI,eAAe;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB;IAU3E,UAAU;IACV,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,UAAU;IACV,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,wCAAwC;IACxC,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,oFAAoF;IACpF,IAAI,cAAc,IAAI,MAAM,CAQ3B;CACF"}
@@ -0,0 +1,21 @@
1
+ import { PaginationMapping, ResponseMapping } from './types';
2
+ /** A batch of related objects found while mapping, to be written to the store. */
3
+ export interface NestedWrite {
4
+ type: string;
5
+ items: unknown[];
6
+ }
7
+ /** Extract the data at `dataPath` and apply the top-level transform. */
8
+ export declare function extractData(body: unknown, mapping?: ResponseMapping): unknown;
9
+ /**
10
+ * Map one item. Nested objects are passed to `collect` for normalization and
11
+ * replaced with their ids (or kept inline with `as: 'keep'`).
12
+ */
13
+ export declare function mapItem(item: unknown, mapping: ResponseMapping | undefined, collect: (write: NestedWrite) => string[]): unknown;
14
+ export interface ExtractedPage {
15
+ nextCursor: string | null;
16
+ hasMore: boolean;
17
+ totalCount?: number;
18
+ }
19
+ /** Read pagination fields from a list response. */
20
+ export declare function extractPage(body: unknown, pagination: PaginationMapping | undefined, itemCount: number, pageSize?: number): ExtractedPage;
21
+ //# sourceMappingURL=mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/http/mapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjF,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB;AAED,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAI7E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,GACxC,OAAO,CA6BT;AAWD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,CAYzI"}
@@ -0,0 +1,237 @@
1
+ import { HttpError } from './http-error';
2
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
3
+ /** A header value, or a function evaluated at request time (e.g. a tenant id or request id). */
4
+ export type HeaderValue = string | (() => string | undefined | null | Promise<string | undefined | null>);
5
+ export type HeaderMap = Record<string, HeaderValue>;
6
+ /** Query/path parameter values. Arrays repeat the key; Dates become ISO strings. */
7
+ export type ParamValue = string | number | boolean | Date | null | undefined | Array<string | number | boolean>;
8
+ export type Params = Record<string, ParamValue>;
9
+ export interface RetryConfig {
10
+ /** Total attempts including the first. @default 3 */
11
+ maxAttempts?: number;
12
+ /** @default 500 */
13
+ baseDelay?: number;
14
+ /** @default 10000 */
15
+ maxDelay?: number;
16
+ /** Random extra delay as a fraction (0–1). @default 0.3 */
17
+ jitter?: number;
18
+ /** Status codes worth retrying. @default [408, 425, 429, 500, 502, 503, 504] */
19
+ retryOn?: number[];
20
+ /**
21
+ * Also retry POST and PATCH. Only enable this if your API makes them idempotent
22
+ * (e.g. with an idempotency key). @default false
23
+ */
24
+ retryNonIdempotent?: boolean;
25
+ }
26
+ export interface RequestConfig {
27
+ url: string;
28
+ method?: HttpMethod;
29
+ /** Path (`:id`) and query parameters. */
30
+ params?: Params;
31
+ /** JSON-serialized unless it is FormData, Blob, URLSearchParams, ArrayBuffer or a string. */
32
+ body?: unknown;
33
+ headers?: HeaderMap;
34
+ /** Milliseconds before the request is aborted with a 408. */
35
+ timeout?: number;
36
+ signal?: AbortSignal;
37
+ /** Retry policy for this request, or `false` to disable retries. */
38
+ retry?: RetryConfig | false;
39
+ /** Attach the bearer token. @default true */
40
+ auth?: boolean;
41
+ /** How to read the body. @default 'json' (falls back to text) */
42
+ responseType?: 'json' | 'text' | 'blob' | 'response';
43
+ /** Share identical in-flight GET requests. @default true */
44
+ dedupe?: boolean;
45
+ }
46
+ /** Maps one field; `path` is a dotted path into the response item. */
47
+ export interface FieldMapping {
48
+ path: string;
49
+ transform?: (value: unknown, item: unknown) => unknown;
50
+ }
51
+ /** Extracts related objects into their own type during normalization. */
52
+ export interface NestedMapping {
53
+ /** Type of the nested objects, e.g. `'Person'`. */
54
+ type: string;
55
+ /** Path to the nested object or array. Defaults to the mapping key. */
56
+ path?: string;
57
+ /** Mapping applied to each nested item. */
58
+ mapping?: ResponseMapping;
59
+ /** Store ids in the parent (`'ids'`, default) or keep the mapped objects inline (`'keep'`). */
60
+ as?: 'ids' | 'keep';
61
+ }
62
+ export interface ResponseMapping {
63
+ /** Path to the data in the response (`'data'`, `'data.users'`). @default '' (the whole body) */
64
+ dataPath?: string;
65
+ /** Applied to the data at `dataPath` before field mapping. */
66
+ transform?: (data: unknown) => unknown;
67
+ /** `target: 'source.path'` or `target: { path, transform }`. */
68
+ fields?: Record<string, string | FieldMapping>;
69
+ /** Also copy fields that are not listed in `fields`. @default false */
70
+ keepUnmapped?: boolean;
71
+ /** Related objects to normalize into their own types. */
72
+ nested?: Record<string, NestedMapping>;
73
+ }
74
+ export interface PaginationMapping {
75
+ /** Path to the next cursor in the response body, e.g. `'meta.nextCursor'`. */
76
+ cursorPath?: string;
77
+ /** Path to a boolean "has more" flag. Defaults to `nextCursor != null`. */
78
+ hasMorePath?: string;
79
+ /** Path to the total item count. */
80
+ totalCountPath?: string;
81
+ /** Query parameter that carries the cursor. @default 'cursor' */
82
+ cursorParam?: string;
83
+ /** Query parameter that carries the page size. @default 'limit' */
84
+ limitParam?: string;
85
+ /** Query parameter for sort (`field:dir,field:dir`). @default 'sort' */
86
+ sortParam?: string;
87
+ }
88
+ /** A named endpoint, registered with `defineEndpoint(name, config)`. */
89
+ export interface EndpointConfig {
90
+ /** Path relative to `http.baseUrl`; `:name` segments are filled from params. */
91
+ url: string;
92
+ method?: HttpMethod;
93
+ /** Store results as this object type. */
94
+ type?: string;
95
+ /** The response is a list of `type`. */
96
+ list?: boolean;
97
+ headers?: HeaderMap;
98
+ mapping?: ResponseMapping;
99
+ pagination?: PaginationMapping;
100
+ retry?: RetryConfig | false;
101
+ /** Attach the bearer token. @default true */
102
+ auth?: boolean;
103
+ timeout?: number;
104
+ /** Route through the batch endpoint. */
105
+ batch?: boolean;
106
+ }
107
+ export type CacheMode = 'network' | 'cache-first' | 'swr';
108
+ export interface FetchOptions {
109
+ /**
110
+ * - `network` (default): always request
111
+ * - `cache-first`: return a fresh stored object without a request
112
+ * - `swr`: return the stored object now and revalidate in the background
113
+ */
114
+ cache?: CacheMode;
115
+ signal?: AbortSignal;
116
+ body?: unknown;
117
+ headers?: HeaderMap;
118
+ /** Populate (or append to) this ListView with the result ids. */
119
+ viewId?: string;
120
+ append?: boolean;
121
+ }
122
+ export interface FetchResult<T = unknown> {
123
+ /** Mapped data: an item, or an array for list endpoints. */
124
+ data: T;
125
+ /** Ids written to the store. */
126
+ ids: string[];
127
+ /** Pagination info for list endpoints. */
128
+ page?: {
129
+ nextCursor: string | null;
130
+ hasMore: boolean;
131
+ totalCount?: number;
132
+ };
133
+ /** True if served from the store without a request. */
134
+ fromCache: boolean;
135
+ }
136
+ export interface RequestContext {
137
+ url: string;
138
+ init: RequestInit & {
139
+ headers: Record<string, string>;
140
+ };
141
+ config: RequestConfig;
142
+ attempt: number;
143
+ }
144
+ export interface Interceptors {
145
+ /** Runs before every attempt; may mutate `ctx.init` / `ctx.url`. */
146
+ request?: (ctx: RequestContext) => void | Promise<void>;
147
+ /** Runs on every response; may return a replacement Response. */
148
+ response?: (response: Response, ctx: RequestContext) => Response | void | Promise<Response | void>;
149
+ /** Runs on every failed attempt. */
150
+ error?: (error: HttpError, ctx: RequestContext) => void;
151
+ }
152
+ export interface BatchConfig {
153
+ /** Batch endpoint URL. */
154
+ url: string;
155
+ /** Operations per request. @default 50 */
156
+ maxOperations?: number;
157
+ /** Coalesce `batch: true` endpoint calls made within this many ms. @default 10 */
158
+ window?: number;
159
+ /** Build the request body. @default `{ operations: [...] }` */
160
+ buildRequest?: (operations: ResolvedBatchOperation[]) => unknown;
161
+ /** Read per-operation results from the response. @default the array, or `body.results` */
162
+ parseResponse?: (body: unknown) => BatchResult[];
163
+ }
164
+ export interface BatchOperation {
165
+ /** Client id for matching results. Generated if omitted. */
166
+ id?: string;
167
+ /** A registered endpoint name… */
168
+ endpoint?: string;
169
+ /** …or a raw URL. */
170
+ url?: string;
171
+ method?: HttpMethod;
172
+ params?: Params;
173
+ body?: unknown;
174
+ }
175
+ export interface ResolvedBatchOperation {
176
+ id: string;
177
+ method: HttpMethod;
178
+ url: string;
179
+ body?: unknown;
180
+ }
181
+ export interface BatchResult {
182
+ id?: string;
183
+ status: number;
184
+ body?: unknown;
185
+ }
186
+ export interface HttpConfig {
187
+ /** Prefix for relative endpoint URLs, e.g. `'https://api.example.com'` or `'/api'`. */
188
+ baseUrl?: string;
189
+ /** Headers for every request; function values are evaluated per request. */
190
+ headers?: HeaderMap;
191
+ retry?: RetryConfig | false;
192
+ /** Default timeout in ms. @default 30000 */
193
+ timeout?: number;
194
+ /** `fetch` implementation (for tests, SSR or mock backends). */
195
+ fetch?: typeof fetch;
196
+ credentials?: RequestCredentials;
197
+ interceptors?: Interceptors;
198
+ batch?: BatchConfig;
199
+ /**
200
+ * Extra origins allowed to receive the bearer token. The `baseUrl` origin and
201
+ * the page origin are always trusted; every other origin is not.
202
+ */
203
+ trustedOrigins?: string[];
204
+ }
205
+ export type TokenStorage = 'local' | 'session' | 'memory' | Storage;
206
+ export interface AuthConfig {
207
+ loginUrl: string;
208
+ refreshUrl: string;
209
+ logoutUrl?: string;
210
+ /** Where tokens live. @default 'local' */
211
+ storage?: TokenStorage;
212
+ /** @default 'access_token' */
213
+ accessTokenKey?: string;
214
+ /** @default 'refresh_token' */
215
+ refreshTokenKey?: string;
216
+ /** Refresh when the token expires within this many seconds. @default 60 */
217
+ refreshThreshold?: number;
218
+ /** Called when the session can't be refreshed. */
219
+ onSessionExpired?: () => void;
220
+ /** Custom token parser (e.g. for opaque tokens with a separate expiry). */
221
+ parseToken?: (token: string) => TokenPayload | null;
222
+ /** Paths to tokens in login/refresh responses. */
223
+ tokenPaths?: {
224
+ accessToken?: string;
225
+ refreshToken?: string;
226
+ };
227
+ /** Field name for the refresh token in the refresh request body. @default 'refresh_token' */
228
+ refreshBodyField?: string;
229
+ credentials?: RequestCredentials;
230
+ }
231
+ export interface TokenPayload {
232
+ exp?: number;
233
+ iat?: number;
234
+ sub?: string;
235
+ [claim: string]: unknown;
236
+ }
237
+ //# sourceMappingURL=types.d.ts.map