@rebasepro/client 0.26.0 → 0.28.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/dist/admin.d.ts +21 -1
- package/dist/apple-sign-in.d.ts +59 -0
- package/dist/auth.d.ts +55 -10
- package/dist/exports-contract.types.d.ts +4 -1
- package/dist/index.d.ts +19 -8
- package/dist/index.es.js +491 -64
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-AvuEcg7u.js → offline-BjJdcVBb.js} +32 -4
- package/dist/offline-BjJdcVBb.js.map +1 -0
- package/dist/{offline-store-BhYXViha.js → offline-store-Cxhh99Q-.js} +40 -6
- package/dist/offline-store-Cxhh99Q-.js.map +1 -0
- package/dist/offline.d.ts +11 -0
- package/dist/realtime-channel.d.ts +27 -0
- package/dist/storage-contract.types.d.ts +16 -0
- package/dist/storage.d.ts +4 -2
- package/dist/transport.d.ts +18 -1
- package/dist/websocket.d.ts +28 -0
- package/package.json +4 -4
- package/dist/offline-AvuEcg7u.js.map +0 -1
- package/dist/offline-store-BhYXViha.js.map +0 -1
package/dist/admin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transport } from "./transport.js";
|
|
2
|
-
import type { AdminUser, RoleSummary } from "@rebasepro/types";
|
|
2
|
+
import type { AdminGuest, AdminUser, DeleteGuestsResult, RoleSummary } from "@rebasepro/types";
|
|
3
3
|
export type { AdminUser };
|
|
4
4
|
export interface CreateAdminOptions {
|
|
5
5
|
adminPath?: string;
|
|
@@ -20,6 +20,13 @@ export interface ListUsersOptions {
|
|
|
20
20
|
*/
|
|
21
21
|
ids?: readonly string[];
|
|
22
22
|
}
|
|
23
|
+
/** The window and filter `GET /admin/guests` takes. */
|
|
24
|
+
export interface ListGuestsOptions {
|
|
25
|
+
limit?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
/** Only the guests last seen before this date. */
|
|
28
|
+
lastSeenBefore?: Date | string;
|
|
29
|
+
}
|
|
23
30
|
export declare function createAdmin(transport: Transport, options?: CreateAdminOptions): {
|
|
24
31
|
listUsers: (options?: ListUsersOptions) => Promise<{
|
|
25
32
|
users: AdminUser[];
|
|
@@ -64,6 +71,19 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
|
|
|
64
71
|
success: boolean;
|
|
65
72
|
removedFactors: number;
|
|
66
73
|
}>;
|
|
74
|
+
listGuests: (options?: ListGuestsOptions) => Promise<{
|
|
75
|
+
guests: AdminGuest[];
|
|
76
|
+
total: number;
|
|
77
|
+
limit: number;
|
|
78
|
+
offset: number;
|
|
79
|
+
}>;
|
|
80
|
+
deleteGuest: (userId: string) => Promise<{
|
|
81
|
+
success: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
deleteGuests: (options: {
|
|
84
|
+
lastSeenBefore: Date | string;
|
|
85
|
+
offset?: number;
|
|
86
|
+
}) => Promise<DeleteGuestsResult>;
|
|
67
87
|
resetPassword: (userId: string, options?: {
|
|
68
88
|
password?: string;
|
|
69
89
|
}) => Promise<{
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser half of Sign in with Apple.
|
|
3
|
+
*
|
|
4
|
+
* Apple is the one provider a single-page app cannot take through the usual
|
|
5
|
+
* redirect: asking for the `name` or `email` scope obliges
|
|
6
|
+
* `response_mode=form_post`, so Apple answers with a cross-site POST to the
|
|
7
|
+
* redirect URI — a request a static page never sees. Apple's own JS SDK has a
|
|
8
|
+
* popup mode that hands the answer back to the opening page with
|
|
9
|
+
* `postMessage` instead, and that is what this uses. The redirect URI still
|
|
10
|
+
* has to be listed under the Services ID's Return URLs (HTTPS, no
|
|
11
|
+
* `localhost`), because Apple matches it and the token exchange repeats it.
|
|
12
|
+
*
|
|
13
|
+
* `state` is generated and checked here, which is what binds the code that
|
|
14
|
+
* comes back to the click that started it.
|
|
15
|
+
*/
|
|
16
|
+
/** Apple's JS SDK, the only way into its popup mode. */
|
|
17
|
+
export declare const APPLE_JS_SDK_URL = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleauth.js";
|
|
18
|
+
/** What `POST /auth/apple` needs from a web sign-in. */
|
|
19
|
+
export interface AppleAuthorization {
|
|
20
|
+
code: string;
|
|
21
|
+
redirectUri: string;
|
|
22
|
+
/**
|
|
23
|
+
* Present on the first authorization only — Apple never sends the name
|
|
24
|
+
* again, so it has to reach the backend on this request or not at all.
|
|
25
|
+
*/
|
|
26
|
+
user?: {
|
|
27
|
+
name?: {
|
|
28
|
+
firstName?: string;
|
|
29
|
+
lastName?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface AppleAuthorizationRequest {
|
|
34
|
+
/** The Services ID. */
|
|
35
|
+
clientId: string;
|
|
36
|
+
/**
|
|
37
|
+
* A Return URL registered on the Services ID. Defaults to this page's
|
|
38
|
+
* origin with a trailing slash (`https://app.example.com/`).
|
|
39
|
+
*/
|
|
40
|
+
redirectUri?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Start loading Apple's SDK ahead of the click. Worth calling when the sign-in
|
|
44
|
+
* button mounts: with the SDK already on the page, the popup opens in the same
|
|
45
|
+
* task as the click, and Safari blocks a popup that opens later than that.
|
|
46
|
+
*/
|
|
47
|
+
export declare function preloadAppleSignIn(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Open Apple's sign-in popup and return the authorization code, without
|
|
50
|
+
* spending it. Call it from a click handler: browsers block a popup that no
|
|
51
|
+
* gesture opened. Call {@link preloadAppleSignIn} first (on mount) so the
|
|
52
|
+
* popup does not wait on a script download.
|
|
53
|
+
*
|
|
54
|
+
* Throws a `RebaseClientError` whose `code` is `APPLE_SIGN_IN_CANCELLED` when
|
|
55
|
+
* the visitor closes the popup or declines, `APPLE_SIGN_IN_UNAVAILABLE` when
|
|
56
|
+
* Apple's script cannot load or this is not a browser, and
|
|
57
|
+
* `APPLE_SIGN_IN_FAILED` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export declare function requestAppleAuthorization(request: AppleAuthorizationRequest): Promise<AppleAuthorization>;
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transport } from "./transport.js";
|
|
2
|
-
import type { AuthConfigDocument, AuthChangeEvent, RebaseSession, DeviceSession, User } from "@rebasepro/types";
|
|
2
|
+
import type { AuthConfigDocument, AuthChangeEvent, RebaseSession, AuthTokens, DeviceSession, User } from "@rebasepro/types";
|
|
3
3
|
export type { RebaseSession, AuthTokens, AuthChangeEvent, DeviceSession } from "@rebasepro/types";
|
|
4
4
|
/** Minimal, non-sensitive user profile returned by {@link findUserByEmail}. */
|
|
5
5
|
export interface PublicUserProfile {
|
|
@@ -17,6 +17,26 @@ export interface PublicUserProfile {
|
|
|
17
17
|
* every backend does send.
|
|
18
18
|
*/
|
|
19
19
|
export type AuthConfig = AuthConfigDocument;
|
|
20
|
+
/** The body of an Apple sign-in. See `signInWithApple`. */
|
|
21
|
+
export interface AppleSignInPayload {
|
|
22
|
+
/** The authorization code Apple returned. */
|
|
23
|
+
code: string;
|
|
24
|
+
/** Web: the redirect URI the browser authorization used. */
|
|
25
|
+
redirectUri?: string;
|
|
26
|
+
/** Native: the bundle id of the app that obtained the code. */
|
|
27
|
+
bundleId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The name Apple reports on the first authorization only. An `email`
|
|
30
|
+
* here is ignored — the backend reads the address from Apple's id_token.
|
|
31
|
+
*/
|
|
32
|
+
user?: {
|
|
33
|
+
name?: {
|
|
34
|
+
firstName?: string;
|
|
35
|
+
lastName?: string;
|
|
36
|
+
};
|
|
37
|
+
email?: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
20
40
|
export interface AuthStorage {
|
|
21
41
|
getItem: (key: string) => string | null;
|
|
22
42
|
setItem: (key: string, value: string) => void;
|
|
@@ -29,12 +49,32 @@ export interface CreateAuthOptions {
|
|
|
29
49
|
autoRefresh?: boolean;
|
|
30
50
|
persistSession?: boolean;
|
|
31
51
|
/**
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
52
|
+
* Where the refresh token lives.
|
|
53
|
+
* - `"cookie"`: in an HttpOnly cookie the server sets (its `auth.cookieAuth`),
|
|
54
|
+
* out of reach of script on the page. The access token stays in memory.
|
|
55
|
+
* - `"json"`: in the response body, kept in `storage`. For a client with no
|
|
56
|
+
* cookie jar, against a server that does not use `cookieAuth`.
|
|
57
|
+
*
|
|
58
|
+
* Defaults to `"cookie"` in a browser and `"json"` anywhere else, or when
|
|
59
|
+
* `storage` is passed: see {@link resolveAuthFlowMode}.
|
|
35
60
|
*/
|
|
36
61
|
authFlowMode?: "json" | "cookie";
|
|
37
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The flow mode a client uses when `authFlowMode` is not set.
|
|
65
|
+
*
|
|
66
|
+
* Cookie in a browser. A backend run by the Rebase runtime always keeps the
|
|
67
|
+
* refresh token in a cookie and answers the body's with `""`, so a browser
|
|
68
|
+
* client defaulting to json held nothing to renew with, and was signed out
|
|
69
|
+
* without a word once its access token expired, about an hour after sign-in.
|
|
70
|
+
*
|
|
71
|
+
* Json off the browser (Node, a worker, React Native), where there is no
|
|
72
|
+
* cookie jar to keep it in — and in a browser that passes its own `storage`,
|
|
73
|
+
* which says where the session is to be kept: a second client on the page
|
|
74
|
+
* that keeps its own sign-in apart from the page's cookie. In cookie mode
|
|
75
|
+
* nothing would be kept there, and every reload would lose that sign-in.
|
|
76
|
+
*/
|
|
77
|
+
export declare function resolveAuthFlowMode(options?: CreateAuthOptions): "json" | "cookie";
|
|
38
78
|
/**
|
|
39
79
|
* Finishing a sign-in that the server refused with `MFA_REQUIRED`.
|
|
40
80
|
*
|
|
@@ -95,12 +135,14 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
95
135
|
accessToken: string;
|
|
96
136
|
refreshToken: string;
|
|
97
137
|
}>;
|
|
98
|
-
signInWithApple: (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
138
|
+
signInWithApple: (payloadOrCode: AppleSignInPayload | string, redirectUri?: string, user?: AppleSignInPayload["user"]) => Promise<{
|
|
139
|
+
user: User;
|
|
140
|
+
accessToken: string;
|
|
141
|
+
refreshToken: string;
|
|
142
|
+
}>;
|
|
143
|
+
signInWithApplePopup: (options?: {
|
|
144
|
+
clientId?: string;
|
|
145
|
+
redirectUri?: string;
|
|
104
146
|
}) => Promise<{
|
|
105
147
|
user: User;
|
|
106
148
|
accessToken: string;
|
|
@@ -273,6 +315,8 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
273
315
|
* URL with an expiry, so copy the bytes rather than storing this.
|
|
274
316
|
*/
|
|
275
317
|
photoURL?: string | null;
|
|
318
|
+
tokens?: AuthTokens;
|
|
319
|
+
user?: Record<string, unknown>;
|
|
276
320
|
}>;
|
|
277
321
|
sendVerificationEmail: () => Promise<{
|
|
278
322
|
success: boolean;
|
|
@@ -324,6 +368,7 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
324
368
|
}>;
|
|
325
369
|
getAuthConfig: () => Promise<AuthConfigDocument>;
|
|
326
370
|
getSession: () => RebaseSession | null;
|
|
371
|
+
getAccessToken: () => Promise<string | null>;
|
|
327
372
|
onAuthStateChange: (callback: (event: AuthChangeEvent, session: RebaseSession | null) => void) => () => boolean;
|
|
328
373
|
canRestoreSession: () => boolean;
|
|
329
374
|
isInitialized: () => Promise<void>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* package only, so an argument type missing from the barrel is one it has to
|
|
9
9
|
* spell out by hand or reach into a package it never installed.
|
|
10
10
|
*/
|
|
11
|
-
import type { AggregateMeta, AggregateParams, AggregateResult, AggregateRow, AggregateSelect, FieldPath, FilterCondition, FilterConditionFor, FilterValues, IncludeOptions, IncludeSpec, InsertOf, LogicalCondition, LogicalConditionFor, OrderBySpec, QueryComputedFields, RestoreOptions, RowOf, StorageSource, TrashClient, UpdateOf, WhereConditionFor, WhereFilterOp, WhereFor, WhereValueFor, WriteOptions } from "./index.js";
|
|
11
|
+
import type { AggregateMeta, AggregateParams, AggregateResult, AggregateRow, AggregateSelect, FieldPath, FilterCondition, FilterConditionFor, FilterValues, IncludeOptions, IncludeSpec, InsertOf, LogicalCondition, LogicalConditionFor, OrderBySpec, QueryComputedFields, RestoreOptions, RowOf, StorageSource, ClientStorageSource, ClientUploadFileProps, UploadFileResult, TrashClient, UpdateOf, WhereConditionFor, WhereFilterOp, WhereFor, WhereValueFor, WriteOptions } from "./index.js";
|
|
12
12
|
export type ConsumerCanName = [
|
|
13
13
|
AggregateMeta,
|
|
14
14
|
AggregateParams,
|
|
@@ -28,6 +28,9 @@ export type ConsumerCanName = [
|
|
|
28
28
|
QueryComputedFields,
|
|
29
29
|
RowOf<Record<string, unknown>>,
|
|
30
30
|
StorageSource,
|
|
31
|
+
ClientStorageSource,
|
|
32
|
+
ClientUploadFileProps,
|
|
33
|
+
UploadFileResult,
|
|
31
34
|
UpdateOf<Record<string, unknown>>,
|
|
32
35
|
WhereConditionFor<string>,
|
|
33
36
|
WhereFilterOp,
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ import { createFunctionsClient } from "./functions.js";
|
|
|
9
9
|
import { RebaseWebSocketClient } from "./websocket.js";
|
|
10
10
|
import { RebaseRealtimeChannel, type ChannelOptions } from "./realtime-channel.js";
|
|
11
11
|
import type { OfflineApi, OfflineConfig } from "./offline.js";
|
|
12
|
-
import { type AccessSimulation, type BatchOperation, type BatchResult, type IncludeOf, InsertOf, RebaseClient, RebaseSdkData, RowOf, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf, type WriteOptions } from "@rebasepro/types";
|
|
12
|
+
import { type AccessSimulation, type BatchOperation, type BatchResult, type IncludeOf, InsertOf, RebaseClient, RebaseSdkData, RowOf, ClientStorageSource, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf, type WriteOptions } from "@rebasepro/types";
|
|
13
13
|
export { RebaseApiError } from "./transport.js";
|
|
14
14
|
export { RebaseClientError } from "./errors.js";
|
|
15
15
|
export type { RebaseErrorCode } from "@rebasepro/types";
|
|
16
|
-
export type { RebaseClientConfig, FindParams, FindResponse } from "./transport.js";
|
|
16
|
+
export type { RebaseClientConfig, RealtimeClientOptions, FindParams, FindResponse } from "./transport.js";
|
|
17
17
|
export type { CollectionClient, RestoreOptions, TrashClient } from "./collection.js";
|
|
18
18
|
export type { FindResult, SDKCollectionClient, SDKQueryBuilderInterface, PaginationMeta } from "@rebasepro/types";
|
|
19
19
|
export type { IterateParams, FindAllParams, PageWalkOptions, CursorSpec } from "@rebasepro/types";
|
|
@@ -23,9 +23,11 @@ export { or, and, not, cond } from "@rebasepro/common";
|
|
|
23
23
|
export { resolveStorageReferences, storageReference, parseStorageReference, isStorageReference, STORAGE_REFERENCE_SCHEME, storageTargetOfDownloadUrl, storageReferencesForDownloadUrls, storageTargetsInText } from "@rebasepro/types";
|
|
24
24
|
export type { StorageReferenceTarget, StorageReferenceResolver } from "@rebasepro/types";
|
|
25
25
|
export { createCookieStorage, createMemoryStorage } from "./auth.js";
|
|
26
|
-
export type { AuthConfig, AuthStorage, CookieStorageOptions, CreateAuthOptions, SessionRestoreOutcome } from "./auth.js";
|
|
26
|
+
export type { AppleSignInPayload, AuthConfig, AuthStorage, CookieStorageOptions, CreateAuthOptions, SessionRestoreOutcome } from "./auth.js";
|
|
27
|
+
export { requestAppleAuthorization, preloadAppleSignIn, APPLE_JS_SDK_URL } from "./apple-sign-in.js";
|
|
28
|
+
export type { AppleAuthorization, AppleAuthorizationRequest } from "./apple-sign-in.js";
|
|
27
29
|
export type { User, RebaseSession, AuthTokens, AuthChangeEvent, DeviceSession } from "@rebasepro/types";
|
|
28
|
-
export type { CreateAdminOptions, ListUsersOptions } from "./admin.js";
|
|
30
|
+
export type { CreateAdminOptions, ListGuestsOptions, ListUsersOptions } from "./admin.js";
|
|
29
31
|
export type { AdminUser } from "./admin.js";
|
|
30
32
|
export type { CreateCronOptions } from "./cron.js";
|
|
31
33
|
export type { BackupStream } from "./backups.js";
|
|
@@ -39,7 +41,7 @@ export { isOfflineError } from "./offline-errors.js";
|
|
|
39
41
|
export type { LiveResult, ObserveByIdOptions, ObserveOptions, RowSnapshotMeta } from "./collection.js";
|
|
40
42
|
export { etagOf } from "./collection.js";
|
|
41
43
|
export type { BatchOperation, BatchRef, BatchResult, FieldOperation, UpdateValues, UpsertOptions } from "@rebasepro/types";
|
|
42
|
-
export type { WriteOptions, WhereFilterOp, WhereFor, WhereConditionFor, WhereValueFor, FilterValues, FieldPath, OrderBySpec, LogicalCondition, LogicalConditionFor, FilterCondition, FilterConditionFor, AggregateParams, AggregateSelect, AggregateRow, AggregateResult, AggregateMeta, IncludeSpec, IncludeOptions, QueryComputedFields, RowOf, InsertOf, UpdateOf, StorageSource } from "@rebasepro/types";
|
|
44
|
+
export type { WriteOptions, WhereFilterOp, WhereFor, WhereConditionFor, WhereValueFor, FilterValues, FieldPath, OrderBySpec, LogicalCondition, LogicalConditionFor, FilterCondition, FilterConditionFor, AggregateParams, AggregateSelect, AggregateRow, AggregateResult, AggregateMeta, IncludeSpec, IncludeOptions, QueryComputedFields, RowOf, InsertOf, UpdateOf, StorageSource, ClientStorageSource, ClientUploadFileProps, UploadFileResult } from "@rebasepro/types";
|
|
43
45
|
export type { OfflineStore, OfflineCacheEntry, OfflineCacheRecord, PendingMutation, MutationRollback } from "./offline-store.js";
|
|
44
46
|
export { MemoryOfflineStore } from "./offline-store.js";
|
|
45
47
|
export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
@@ -128,8 +130,8 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
128
130
|
*
|
|
129
131
|
* Always present here, typed by the same `Database` (it is built with the
|
|
130
132
|
* same `collections` dictionary), and closable: it is a client of its own,
|
|
131
|
-
* so release it with `close()` when done. On `RebaseClient` it is optional
|
|
132
|
-
*
|
|
133
|
+
* so release it with `close()` when done. On `RebaseClient` it is optional,
|
|
134
|
+
* because a server-side client has none.
|
|
133
135
|
*/
|
|
134
136
|
simulate: (simulation: AccessSimulation) => CreateRebaseClientResult<DB>;
|
|
135
137
|
/**
|
|
@@ -187,6 +189,14 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
187
189
|
* join and on every reconnect, for channels the server retains.
|
|
188
190
|
*/
|
|
189
191
|
channel: (name: string, options?: ChannelOptions) => RebaseRealtimeChannel;
|
|
192
|
+
/**
|
|
193
|
+
* Name the group this client's socket belongs to, or clear it with
|
|
194
|
+
* `null` — {@link RealtimeClientOptions.affinity}, for a key that is
|
|
195
|
+
* only known after the client is created. Call it before the first
|
|
196
|
+
* `join()` or `listen()`: a socket already open stays where it is
|
|
197
|
+
* until it next connects. Does nothing with `realtime: false`.
|
|
198
|
+
*/
|
|
199
|
+
setAffinity: (key: string | null) => void;
|
|
190
200
|
};
|
|
191
201
|
/**
|
|
192
202
|
* Release everything this client holds that can keep a process alive: the
|
|
@@ -202,7 +212,8 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
202
212
|
* persisted session survives for the next client to restore.
|
|
203
213
|
*/
|
|
204
214
|
close: () => void;
|
|
205
|
-
storage
|
|
215
|
+
/** The default storage source. Its upload takes any `Blob`, and a key only when you want to name the object. */
|
|
216
|
+
storage: ClientStorageSource;
|
|
206
217
|
storageRegistry: StorageSourceRegistry;
|
|
207
218
|
createStorageSource: (storageId: string) => StorageSource;
|
|
208
219
|
fetchStorageSources: () => Promise<StorageSourceDefinition[]>;
|