@rxferrix/client 0.0.0-stage → 0.1.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 (97) hide show
  1. package/dist/api.d.ts +60 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +22 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/auth.d.ts +251 -0
  6. package/dist/auth.d.ts.map +1 -0
  7. package/dist/auth.js +531 -0
  8. package/dist/auth.js.map +1 -0
  9. package/dist/bytes.d.ts +21 -0
  10. package/dist/bytes.d.ts.map +1 -0
  11. package/dist/bytes.js +51 -0
  12. package/dist/bytes.js.map +1 -0
  13. package/dist/canonical.d.ts +13 -0
  14. package/dist/canonical.d.ts.map +1 -0
  15. package/dist/canonical.js +66 -0
  16. package/dist/canonical.js.map +1 -0
  17. package/dist/client.d.ts +170 -0
  18. package/dist/client.d.ts.map +1 -0
  19. package/dist/client.js +638 -0
  20. package/dist/client.js.map +1 -0
  21. package/dist/diff.d.ts +20 -0
  22. package/dist/diff.d.ts.map +1 -0
  23. package/dist/diff.js +100 -0
  24. package/dist/diff.js.map +1 -0
  25. package/dist/errors.d.ts +24 -0
  26. package/dist/errors.d.ts.map +1 -0
  27. package/dist/errors.js +34 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/index.d.ts +14 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +12 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/local_query_set.d.ts +56 -0
  34. package/dist/local_query_set.d.ts.map +1 -0
  35. package/dist/local_query_set.js +108 -0
  36. package/dist/local_query_set.js.map +1 -0
  37. package/dist/logging.d.ts +15 -0
  38. package/dist/logging.d.ts.map +1 -0
  39. package/dist/logging.js +17 -0
  40. package/dist/logging.js.map +1 -0
  41. package/dist/optimistic_updates.d.ts +48 -0
  42. package/dist/optimistic_updates.d.ts.map +1 -0
  43. package/dist/optimistic_updates.js +113 -0
  44. package/dist/optimistic_updates.js.map +1 -0
  45. package/dist/paginated_query.d.ts +118 -0
  46. package/dist/paginated_query.d.ts.map +1 -0
  47. package/dist/paginated_query.js +199 -0
  48. package/dist/paginated_query.js.map +1 -0
  49. package/dist/protocol.d.ts +136 -0
  50. package/dist/protocol.d.ts.map +1 -0
  51. package/dist/protocol.js +11 -0
  52. package/dist/protocol.js.map +1 -0
  53. package/dist/query_state.d.ts +16 -0
  54. package/dist/query_state.d.ts.map +1 -0
  55. package/dist/query_state.js +2 -0
  56. package/dist/query_state.js.map +1 -0
  57. package/dist/remote_query_set.d.ts +37 -0
  58. package/dist/remote_query_set.d.ts.map +1 -0
  59. package/dist/remote_query_set.js +87 -0
  60. package/dist/remote_query_set.js.map +1 -0
  61. package/dist/request_manager.d.ts +57 -0
  62. package/dist/request_manager.d.ts.map +1 -0
  63. package/dist/request_manager.js +163 -0
  64. package/dist/request_manager.js.map +1 -0
  65. package/dist/storage.d.ts +45 -0
  66. package/dist/storage.d.ts.map +1 -0
  67. package/dist/storage.js +120 -0
  68. package/dist/storage.js.map +1 -0
  69. package/dist/testing.d.ts +68 -0
  70. package/dist/testing.d.ts.map +1 -0
  71. package/dist/testing.js +97 -0
  72. package/dist/testing.js.map +1 -0
  73. package/dist/web_socket_manager.d.ts +88 -0
  74. package/dist/web_socket_manager.d.ts.map +1 -0
  75. package/dist/web_socket_manager.js +291 -0
  76. package/dist/web_socket_manager.js.map +1 -0
  77. package/package.json +50 -4
  78. package/src/api.ts +86 -0
  79. package/src/auth.ts +636 -0
  80. package/src/bytes.ts +57 -0
  81. package/src/canonical.ts +61 -0
  82. package/src/client.ts +740 -0
  83. package/src/diff.ts +87 -0
  84. package/src/errors.ts +36 -0
  85. package/src/index.ts +60 -0
  86. package/src/local_query_set.ts +130 -0
  87. package/src/logging.ts +26 -0
  88. package/src/optimistic_updates.ts +137 -0
  89. package/src/paginated_query.ts +299 -0
  90. package/src/protocol.ts +152 -0
  91. package/src/query_state.ts +12 -0
  92. package/src/remote_query_set.ts +105 -0
  93. package/src/request_manager.ts +199 -0
  94. package/src/storage.ts +171 -0
  95. package/src/testing.ts +120 -0
  96. package/src/web_socket_manager.ts +322 -0
  97. package/README.md +0 -3
package/dist/api.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Function references: typed handles to server functions.
3
+ *
4
+ * Codegen emits an `api` object whose leaves are created with {@link makeFunctionReference}:
5
+ *
6
+ * ```ts
7
+ * export const api = {
8
+ * todos: {
9
+ * list: makeFunctionReference<"query", { done?: boolean | null }, Doc<"todos">[]>("query", "todos:list"),
10
+ * },
11
+ * };
12
+ * ```
13
+ */
14
+ /** The three kinds of public server functions. */
15
+ export type FunctionKind = "query" | "mutation" | "action";
16
+ /**
17
+ * A typed reference to a server function.
18
+ *
19
+ * Only `_kind` and `_path` exist at runtime. `__args` and `__output` are phantom fields that carry the argument and
20
+ * return types for inference; they are never present on the object.
21
+ */
22
+ export interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = any, Output = any> {
23
+ readonly _kind: Kind;
24
+ readonly _path: string;
25
+ /** Phantom: never present at runtime. */
26
+ readonly __args: Args;
27
+ /** Phantom: never present at runtime. */
28
+ readonly __output: Output;
29
+ }
30
+ /** Any reference to a query. */
31
+ export type AnyQueryReference = FunctionReference<"query", any, any>;
32
+ /** Any reference to a mutation. */
33
+ export type AnyMutationReference = FunctionReference<"mutation", any, any>;
34
+ /** Any reference to an action. */
35
+ export type AnyActionReference = FunctionReference<"action", any, any>;
36
+ /** Creates a function reference. Used by generated code; rarely needed by hand. */
37
+ export declare function makeFunctionReference<Kind extends FunctionKind, Args = Record<string, never>, Output = unknown>(kind: Kind, path: string): FunctionReference<Kind, Args, Output>;
38
+ /** The argument object type of a function reference. */
39
+ export type ArgsOf<F> = F extends FunctionReference<any, infer A, any> ? A : never;
40
+ /** The return type of a function reference. */
41
+ export type OutputOf<F> = F extends FunctionReference<any, any, infer O> ? O : never;
42
+ /** True when every key of `Args` is optional (so the whole object may be omitted). */
43
+ export type HasNoRequiredArgs<Args> = {} extends Args ? true : false;
44
+ /**
45
+ * Rest-parameter tuple for a function's args: optional when the args object has no required keys.
46
+ *
47
+ * `fn(ref, ...args: OptionalArgs<typeof ref>)`
48
+ */
49
+ export type OptionalArgs<F> = HasNoRequiredArgs<ArgsOf<F>> extends true ? [args?: ArgsOf<F>] : [args: ArgsOf<F>];
50
+ /** Like {@link OptionalArgs} but also accepts `"skip"` in place of the args. */
51
+ export type OptionalArgsOrSkip<F> = HasNoRequiredArgs<ArgsOf<F>> extends true ? [args?: ArgsOf<F> | "skip"] : [args: ArgsOf<F> | "skip"];
52
+ /** Args followed by an optional options object; the args are optional when they have no required keys. */
53
+ export type ArgsAndOptions<F, Options> = HasNoRequiredArgs<ArgsOf<F>> extends true ? [args?: ArgsOf<F>, options?: Options] : [args: ArgsOf<F>, options?: Options];
54
+ /** A document ID for the given table. At runtime it is a plain string. */
55
+ export type Id<TableName extends string> = string & {
56
+ __tableName: TableName;
57
+ };
58
+ /** Returns the `udfPath` (e.g. `"todos:list"`) of a function reference. */
59
+ export declare function getFunctionName(ref: FunctionReference): string;
60
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,kDAAkD;AAClD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAChC,IAAI,SAAS,YAAY,GAAG,YAAY,EACxC,IAAI,GAAG,GAAG,EACV,MAAM,GAAG,GAAG;IAEZ,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CA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B,gFAAgF;AAChF,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACzE,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAC3B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;AAE/B,0GAA0G;AAC1G,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAC9E,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,GACrC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAEzC,0EAA0E;AAC1E,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,MAAM,IAAI,MAAM,GAAG;IAAE,WAAW,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/E,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAE9D"}
package/dist/api.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Function references: typed handles to server functions.
3
+ *
4
+ * Codegen emits an `api` object whose leaves are created with {@link makeFunctionReference}:
5
+ *
6
+ * ```ts
7
+ * export const api = {
8
+ * todos: {
9
+ * list: makeFunctionReference<"query", { done?: boolean | null }, Doc<"todos">[]>("query", "todos:list"),
10
+ * },
11
+ * };
12
+ * ```
13
+ */
14
+ /** Creates a function reference. Used by generated code; rarely needed by hand. */
15
+ export function makeFunctionReference(kind, path) {
16
+ return Object.freeze({ _kind: kind, _path: path });
17
+ }
18
+ /** Returns the `udfPath` (e.g. `"todos:list"`) of a function reference. */
19
+ export function getFunctionName(ref) {
20
+ return ref._path;
21
+ }
22
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+BH,mFAAmF;AACnF,MAAM,UAAU,qBAAqB,CACnC,IAAU,EACV,IAAY;IAEZ,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAqD,CAAC;AACzG,CAAC;AAiCD,2EAA2E;AAC3E,MAAM,UAAU,eAAe,CAAC,GAAsB;IACpD,OAAO,GAAG,CAAC,KAAK,CAAC;AACnB,CAAC"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Auth for a {@link RxFerrixClient}: sign-up / sign-in against the server's `/api/auth/*` endpoints, token storage,
3
+ * automatic refresh (wired into `client.setAuth`), OAuth redirects and cross-tab sync.
4
+ *
5
+ * ```ts
6
+ * const client = new RxFerrixClient("http://localhost:8090");
7
+ * const auth = getAuth(client); // restores a stored session, if any
8
+ * await auth.signIn({ email, password });
9
+ * auth.subscribe(() => console.log(auth.state())); // { isLoading, isAuthenticated, userId, isAdmin }
10
+ * ```
11
+ *
12
+ * Tokens are kept in `localStorage` (or the `storage` you pass; an in-memory store when neither exists, e.g. SSR).
13
+ * The access token is short-lived (15 minutes by default) and refreshed with the refresh token shortly before it
14
+ * expires and whenever the server rejects it. Refresh tokens rotate on every use; refreshes are serialized across
15
+ * tabs with the Web Locks API when available, and tabs pick up each other's tokens through `storage` events.
16
+ */
17
+ import { type Id } from "./api.js";
18
+ import type { RxFerrixClient } from "./client.js";
19
+ import { RxFerrixError } from "./errors.js";
20
+ /** Where tokens are persisted. `localStorage` satisfies it; async implementations (e.g. secure storage) work too. */
21
+ export interface AuthStorage {
22
+ getItem(key: string): string | null | Promise<string | null>;
23
+ setItem(key: string, value: string): void | Promise<void>;
24
+ removeItem(key: string): void | Promise<void>;
25
+ }
26
+ /** Keeps tokens in memory only (lost on reload). */
27
+ export declare class MemoryAuthStorage implements AuthStorage {
28
+ private readonly items;
29
+ getItem(key: string): string | null;
30
+ setItem(key: string, value: string): void;
31
+ removeItem(key: string): void;
32
+ }
33
+ export interface RxFerrixAuthOptions {
34
+ /** Token storage. Defaults to `localStorage` when available, else memory. */
35
+ storage?: AuthStorage;
36
+ /** Storage key. Defaults to `"rxferrix.auth:" + client.url`. */
37
+ storageKey?: string;
38
+ /** `fetch` implementation (defaults to the global one). */
39
+ fetch?: typeof fetch;
40
+ /** Follow sign-in / sign-out / refreshes made in other tabs (via `storage` events). Default true. */
41
+ syncTabs?: boolean;
42
+ }
43
+ /** The auth state, as shown by `useRxFerrixAuth()` / `useAuth()`. */
44
+ export interface AuthState {
45
+ /** True until the stored session has been checked, and after a sign-in until the server confirmed the token. */
46
+ readonly isLoading: boolean;
47
+ /** The server has accepted the current access token. */
48
+ readonly isAuthenticated: boolean;
49
+ /** The signed-in user's id (also set while `isLoading` right after a sign-in). */
50
+ readonly userId: Id<"_users"> | null;
51
+ /** True for admin sessions (`signInAsAdmin`). */
52
+ readonly isAdmin: boolean;
53
+ }
54
+ /** The tokens the server returns on sign-in and refresh. */
55
+ export interface AuthTokens {
56
+ accessToken: string;
57
+ refreshToken: string;
58
+ /** Seconds until the access token expires. */
59
+ expiresIn: number;
60
+ userId?: string;
61
+ adminId?: string;
62
+ }
63
+ /** Proof of email ownership: the token from an email link, or the email address plus the code from the email. */
64
+ export type CodeProof = {
65
+ token: string;
66
+ } | {
67
+ email: string;
68
+ code: string;
69
+ };
70
+ /** What {@link RxFerrixAuth.handleRedirectCallback} found in the URL. */
71
+ export type RedirectResult = {
72
+ type: "signedIn";
73
+ } | {
74
+ type: "emailVerified";
75
+ }
76
+ /** A password reset link: ask for a new password, then call `resetPassword({ token }, password)`. */
77
+ | {
78
+ type: "passwordReset";
79
+ token: string;
80
+ } | {
81
+ type: "error";
82
+ error: RxFerrixError;
83
+ };
84
+ /** Sign-in methods enabled on the server (`GET /api/auth/providers`). */
85
+ export interface AuthProviders {
86
+ password: boolean;
87
+ magicLink: boolean;
88
+ signups: boolean;
89
+ /** OAuth provider ids, e.g. `["github", "google"]`. */
90
+ oauth: string[];
91
+ }
92
+ /** A user document (`_users`). Contains no secrets. */
93
+ export interface User {
94
+ _id: Id<"_users">;
95
+ _creationTime: number;
96
+ email: string | null;
97
+ emailVerified: boolean;
98
+ name: string | null;
99
+ image: string | null;
100
+ }
101
+ /**
102
+ * Hand-written references to rxferrix's built-in functions (codegen leaves system functions out of `api`).
103
+ *
104
+ * - `systemApi.auth.me`: the signed-in user (reactive), or `null`.
105
+ * - `systemApi.auth.updateProfile`: set `name` / `image`; omitted fields are unchanged, `""` clears.
106
+ */
107
+ export declare const systemApi: {
108
+ readonly auth: {
109
+ readonly me: import("./api.js").FunctionReference<"query", Record<string, never>, User | null>;
110
+ readonly updateProfile: import("./api.js").FunctionReference<"mutation", {
111
+ name?: string | null;
112
+ image?: string | null;
113
+ }, null>;
114
+ };
115
+ };
116
+ /** Auth bound to one {@link RxFerrixClient}. Create it with {@link getAuth}. */
117
+ export declare class RxFerrixAuth {
118
+ readonly client: RxFerrixClient;
119
+ private readonly storage;
120
+ private readonly storageKey;
121
+ private readonly fetchImpl;
122
+ private readonly baseUrl;
123
+ private tokens;
124
+ private current;
125
+ private readonly listeners;
126
+ private readonly loaded;
127
+ private refreshing;
128
+ private removeStorageListener;
129
+ constructor(client: RxFerrixClient, options?: RxFerrixAuthOptions);
130
+ /** The current state; referentially stable until it changes. */
131
+ state(): AuthState;
132
+ /** Calls `listener` whenever {@link state} changes. Returns an unsubscribe function. */
133
+ subscribe(listener: () => void): () => void;
134
+ private setState;
135
+ private pendingState;
136
+ /** Called by the client once the server accepted (true) or rejected / dropped (false) the token. */
137
+ private onServerAuthChange;
138
+ private load;
139
+ private readStorage;
140
+ private saveTokens;
141
+ /** Store fresh tokens and authenticate the socket with them. */
142
+ private signedIn;
143
+ /** The `fetchToken` given to `client.setAuth`. */
144
+ private fetchToken;
145
+ /**
146
+ * A valid access token (refreshed when it is about to expire), or null when signed out. Useful for calling your
147
+ * own HTTP endpoints or the HTTP function API with `Authorization: Bearer`.
148
+ */
149
+ getAccessToken(options?: {
150
+ forceRefresh?: boolean;
151
+ }): Promise<string | null>;
152
+ /** One refresh at a time per tab, and (with Web Locks) per origin. */
153
+ private refresh;
154
+ private withLock;
155
+ /** Use tokens another tab stored, if they are newer than ours and still fresh. */
156
+ private adoptNewerStoredTokens;
157
+ private doRefresh;
158
+ private listenToOtherTabs;
159
+ private onOtherTabChange;
160
+ /** Stop listening to other tabs. Does not sign out. */
161
+ dispose(): void;
162
+ private post;
163
+ /** The sign-in methods enabled on the server. */
164
+ providers(): Promise<AuthProviders>;
165
+ /**
166
+ * Create an account with email and password and sign in. Resolves `{ verificationRequired: true }` (without
167
+ * signing in) when the server requires a verified email first.
168
+ */
169
+ signUp(args: {
170
+ email: string;
171
+ password: string;
172
+ name?: string;
173
+ }): Promise<{
174
+ verificationRequired: boolean;
175
+ }>;
176
+ /** Sign in with email and password. Rejects with code `"invalid_credentials"` on a wrong email or password. */
177
+ signIn(args: {
178
+ email: string;
179
+ password: string;
180
+ }): Promise<void>;
181
+ /** Sign in to an admin account (dashboard). Functions then see `ctx.auth.is_admin()`. */
182
+ signInAsAdmin(args: {
183
+ email: string;
184
+ password: string;
185
+ }): Promise<void>;
186
+ /** Whether the server has no administrator yet (`GET /api/auth/admin/setup`). */
187
+ needsAdminSetup(): Promise<boolean>;
188
+ /**
189
+ * Create the first administrator with the one-time setup token that `serve` prints as `/_/setup#token=…`, and
190
+ * sign in as them. Rejects with code `"invalid_setup_token"` or `"setup_done"`.
191
+ */
192
+ setupAdmin(args: {
193
+ token: string;
194
+ email: string;
195
+ password: string;
196
+ }): Promise<void>;
197
+ /** End the session on the server and forget the tokens (also in other tabs). */
198
+ signOut(): Promise<void>;
199
+ /** Email a verification link and code (no-op for unknown or already verified addresses). */
200
+ requestEmailVerification(args: {
201
+ email: string;
202
+ redirectTo?: string;
203
+ }): Promise<void>;
204
+ /** Confirm an email address with the link token or the code. */
205
+ verifyEmail(proof: CodeProof): Promise<void>;
206
+ /** Email a password reset link and code. Succeeds whether or not the account exists. */
207
+ requestPasswordReset(args: {
208
+ email: string;
209
+ redirectTo?: string;
210
+ }): Promise<void>;
211
+ /** Set a new password with the reset link token or code; ends other sessions and signs in. */
212
+ resetPassword(proof: CodeProof, password: string): Promise<void>;
213
+ /** Email a magic sign-in link and a one-time code. Succeeds whether or not the account exists. */
214
+ requestMagicLink(args: {
215
+ email: string;
216
+ redirectTo?: string;
217
+ }): Promise<void>;
218
+ /** Sign in with the one-time code from a magic link email. */
219
+ verifyCode(args: {
220
+ email: string;
221
+ code: string;
222
+ }): Promise<void>;
223
+ /** Sign in with the token of a magic link (usually done by {@link handleRedirectCallback}). */
224
+ verifyMagicLink(token: string): Promise<void>;
225
+ /** The URL that starts an OAuth sign-in with `provider`, returning to `redirectTo` (default: this page). */
226
+ oauthUrl(provider: string, options?: {
227
+ redirectTo?: string;
228
+ }): string;
229
+ /**
230
+ * Start an OAuth sign-in: a full-page redirect to the provider. After approval the server redirects back to
231
+ * `redirectTo` (which must be allowed by the server's `--auth-redirect-url` list) with the tokens in the URL
232
+ * fragment; call {@link handleRedirectCallback} on that page.
233
+ */
234
+ signInWithOAuth(provider: string, options?: {
235
+ redirectTo?: string;
236
+ }): void;
237
+ /**
238
+ * Handle the `#rxferrix_…` fragment that OAuth redirects and email links put on the URL: stores tokens (OAuth),
239
+ * signs in (magic link), confirms the email (verification link) or returns the reset token (password reset). The
240
+ * `rxferrix_` parameters are removed from the address bar first, so a reload can't replay them. Returns null when
241
+ * the URL has none.
242
+ */
243
+ handleRedirectCallback(url?: string): Promise<RedirectResult | null>;
244
+ }
245
+ /**
246
+ * The {@link RxFerrixAuth} of `client`, created on first use (with `options`). Later calls return the same instance
247
+ * (and ignore `options`), so hooks like `useRxFerrixAuth()` share it. Call it once early (e.g. next to
248
+ * `new RxFerrixClient`) to pass options such as a custom `storage`.
249
+ */
250
+ export declare function getAuth(client: RxFerrixClient, options?: RxFerrixAuthOptions): RxFerrixAuth;
251
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAyB,KAAK,EAAE,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,qHAAqH;AACrH,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,oDAAoD;AACpD,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAGnC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAGzC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG9B;AAED,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,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