@spacelr/sdk 0.11.0 → 0.13.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/index.d.mts +126 -7
- package/dist/index.d.ts +126 -7
- package/dist/index.js +266 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,7 @@ interface LoginResponse {
|
|
|
42
42
|
user: {
|
|
43
43
|
id: string;
|
|
44
44
|
sub: string;
|
|
45
|
-
email: string;
|
|
45
|
+
email: string | null;
|
|
46
46
|
username?: string;
|
|
47
47
|
name?: string;
|
|
48
48
|
roles: string[];
|
|
@@ -90,7 +90,7 @@ interface UserInfo {
|
|
|
90
90
|
}
|
|
91
91
|
interface UserProfile {
|
|
92
92
|
id: string;
|
|
93
|
-
email: string;
|
|
93
|
+
email: string | null;
|
|
94
94
|
username?: string;
|
|
95
95
|
name?: string;
|
|
96
96
|
roles: string[];
|
|
@@ -245,7 +245,23 @@ interface PasskeyRegistrationResponseJSON {
|
|
|
245
245
|
interface PasskeyLoginResponse {
|
|
246
246
|
user: {
|
|
247
247
|
id: string;
|
|
248
|
-
email: string;
|
|
248
|
+
email: string | null;
|
|
249
|
+
roles: string[];
|
|
250
|
+
};
|
|
251
|
+
access_token: string;
|
|
252
|
+
refresh_token?: string;
|
|
253
|
+
expires_in?: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Response returned by the email-less passkey SIGNUP flow (#780). Same shape as
|
|
257
|
+
* {@link PasskeyLoginResponse} (a freshly-created passkey account is always
|
|
258
|
+
* email-less, so `email` is null), kept as a distinct name for clarity.
|
|
259
|
+
*/
|
|
260
|
+
interface PasskeySignupResponse {
|
|
261
|
+
user: {
|
|
262
|
+
id: string;
|
|
263
|
+
email: string | null;
|
|
264
|
+
username?: string;
|
|
249
265
|
roles: string[];
|
|
250
266
|
};
|
|
251
267
|
access_token: string;
|
|
@@ -647,7 +663,7 @@ interface RealtimeConfig {
|
|
|
647
663
|
*/
|
|
648
664
|
onTokenRefreshed?: (listener: (accessToken: string) => void) => () => void;
|
|
649
665
|
}
|
|
650
|
-
type GapReason = 'outside-retention-window' | 'redis-unavailable' | 'replay-error' | 'replay-truncated';
|
|
666
|
+
type GapReason = 'outside-retention-window' | 'redis-unavailable' | 'replay-error' | 'replay-truncated' | 'evicted' | 'auth-unavailable' | 'log-reset';
|
|
651
667
|
interface StreamGapInfo {
|
|
652
668
|
projectId: string;
|
|
653
669
|
collectionName: string;
|
|
@@ -659,6 +675,14 @@ interface StreamSubscriptionOptions {
|
|
|
659
675
|
projectId: string;
|
|
660
676
|
collectionName: string;
|
|
661
677
|
sinceId?: string;
|
|
678
|
+
/**
|
|
679
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
680
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
681
|
+
* and RESUMES from it (overriding `sinceId`/`fromStart`), returns
|
|
682
|
+
* `{ generation, session, resumeCursor }`, and expects `ack-events`. Absent →
|
|
683
|
+
* legacy stateless behaviour.
|
|
684
|
+
*/
|
|
685
|
+
consumerId?: string;
|
|
662
686
|
/**
|
|
663
687
|
* #685 — "replay from earliest retained". When true, a brand-new subscription
|
|
664
688
|
* (no prior cursor) replays every retained stream entry from the earliest
|
|
@@ -682,7 +706,7 @@ interface StreamSubscriptionOptions {
|
|
|
682
706
|
eventId: string;
|
|
683
707
|
event: DatabaseChangeEvent;
|
|
684
708
|
}) => void | Promise<void>;
|
|
685
|
-
/** Called when the server emits an event-gap. See GapReason for the
|
|
709
|
+
/** Called when the server emits an event-gap. See GapReason for the codes. */
|
|
686
710
|
onGap?: (info: StreamGapInfo) => void;
|
|
687
711
|
/** Called on handshake rejection (not-stream-collection, invalid sinceId, etc.) and handler failures. */
|
|
688
712
|
onError?: (error: Error) => void;
|
|
@@ -746,6 +770,10 @@ declare class RealtimeClient {
|
|
|
746
770
|
unsubscribe: () => void;
|
|
747
771
|
realtimeMode: 'pubsub' | 'stream';
|
|
748
772
|
latestStreamId: string | null;
|
|
773
|
+
/** #768 — the durable position the server RESUMED from (null for a fresh
|
|
774
|
+
* consumer, or after a reset-to-'0' following eviction/log-reset/late-grant).
|
|
775
|
+
* Non-null ⇒ this is a resume; the caller should SKIP the snapshot. */
|
|
776
|
+
resumeCursor: string | null;
|
|
749
777
|
}>;
|
|
750
778
|
/**
|
|
751
779
|
* Shared body for `subscribeWithCursor` and
|
|
@@ -852,6 +880,19 @@ declare class RealtimeClient {
|
|
|
852
880
|
*/
|
|
853
881
|
private resubscribeRoom;
|
|
854
882
|
private emitSubscribeEvents;
|
|
883
|
+
/** #768 — capture the durable fencing tokens from a successful handshake so
|
|
884
|
+
* `ack-events` echoes the (generation, session) the server expects. */
|
|
885
|
+
private captureDurableHandshake;
|
|
886
|
+
/**
|
|
887
|
+
* #768 — schedule a coalesced durable ack. Only durable subscriptions (a
|
|
888
|
+
* consumerId with a captured generation+session) ack. At most one ack per
|
|
889
|
+
* microtask drain, carrying the highest delivered seq — cumulative on the
|
|
890
|
+
* server, so a burst of N events costs one ack, not N.
|
|
891
|
+
*/
|
|
892
|
+
private scheduleDurableAck;
|
|
893
|
+
/** #768 — emit `ack-events` for `seq`; a fenced/evicted response routes into
|
|
894
|
+
* the gap-recovery path so the caller re-snapshots (§12.5/§12.1). */
|
|
895
|
+
private emitDurableAck;
|
|
855
896
|
private buildStreamPayload;
|
|
856
897
|
private unsubscribeStream;
|
|
857
898
|
private dispatchStreamEvent;
|
|
@@ -905,6 +946,28 @@ declare function memoryCursorStorage(): CursorStorage;
|
|
|
905
946
|
*/
|
|
906
947
|
declare function localStorageCursorStorage(prefix?: string): CursorStorage;
|
|
907
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Well-known storage key under which the SDK persists an auto-generated durable
|
|
951
|
+
* consumer id (one per device/app install).
|
|
952
|
+
*/
|
|
953
|
+
declare const CONSUMER_ID_STORAGE_KEY = "spacelr:consumer-id";
|
|
954
|
+
/**
|
|
955
|
+
* Resolve the durable-subscription consumer id (#768 §12.2 / R7).
|
|
956
|
+
*
|
|
957
|
+
* A durable subscription's cursor is owned by a *consumer identity* — a stable
|
|
958
|
+
* per-device/app id — not by the user, so one device's ack never hides a row
|
|
959
|
+
* from another consumer of the same user.
|
|
960
|
+
*
|
|
961
|
+
* Precedence:
|
|
962
|
+
* 1. An explicit `consumerId` the app passes → used verbatim (the app owns
|
|
963
|
+
* identity, e.g. a device id it already has).
|
|
964
|
+
* 2. Else, if `storage` is provided, load a previously-persisted id, or generate
|
|
965
|
+
* one and persist it so it is stable across restarts/reconnects.
|
|
966
|
+
* 3. Else (no storage), an ephemeral id is generated — durable resume then only
|
|
967
|
+
* holds within the live session (a reload gets a new identity).
|
|
968
|
+
*/
|
|
969
|
+
declare function resolveConsumerId(explicit: string | undefined, storage: CursorStorage | undefined, key?: string): Promise<string>;
|
|
970
|
+
|
|
908
971
|
type AuthState = 'authenticated' | 'unauthenticated';
|
|
909
972
|
type AuthStateListener = (state: AuthState) => void | Promise<void>;
|
|
910
973
|
declare class AuthModule {
|
|
@@ -1015,6 +1078,46 @@ declare class AuthModule {
|
|
|
1015
1078
|
* against the options returned by `beginPasskeyLogin()`, completing login.
|
|
1016
1079
|
*/
|
|
1017
1080
|
verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
|
|
1083
|
+
* (#780) — creating a brand-new account with no email and no password. The
|
|
1084
|
+
* project must have passkeys AND public registration enabled. No account is
|
|
1085
|
+
* created until {@link verifyPasskeySignup} succeeds.
|
|
1086
|
+
*
|
|
1087
|
+
* IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
|
|
1088
|
+
* account. Before offering signup, the app MUST first attempt a discoverable
|
|
1089
|
+
* passkey login ({@link beginPasskeyLogin} with no email); only offer signup
|
|
1090
|
+
* when the user has no existing passkey. Skipping this creates duplicate,
|
|
1091
|
+
* fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
|
|
1092
|
+
*/
|
|
1093
|
+
beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Verify a WebAuthn attestation produced by `navigator.credentials.create()`
|
|
1096
|
+
* against the options from {@link beginPasskeySignup}, materializing the
|
|
1097
|
+
* email-less account and returning JWT tokens (the caller is now logged in).
|
|
1098
|
+
*/
|
|
1099
|
+
verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
|
|
1100
|
+
/**
|
|
1101
|
+
* One-call email-less passkey signup with the B1 idempotency fallback baked
|
|
1102
|
+
* in. The browser WebAuthn functions are injected (the SDK stays transport-
|
|
1103
|
+
* only and does not depend on `@simplewebauthn/browser`):
|
|
1104
|
+
*
|
|
1105
|
+
* 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
|
|
1106
|
+
* 2. If verify fails with `challenge_expired`, a network/timeout error, or
|
|
1107
|
+
* `passkey_already_registered` (the account was in fact created but the
|
|
1108
|
+
* response was lost, or the passkey already exists), fall back to a fresh
|
|
1109
|
+
* discoverable LOGIN ceremony and return that session. That fallback IS the
|
|
1110
|
+
* idempotency mechanism — the server never mints a session from a bare
|
|
1111
|
+
* credential lookup.
|
|
1112
|
+
* 3. If the login fallback also fails (genuinely no credential), the original
|
|
1113
|
+
* error is surfaced so the app can restart signup.
|
|
1114
|
+
*/
|
|
1115
|
+
createUserWithPasskey(ceremony: {
|
|
1116
|
+
startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
|
|
1117
|
+
startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
|
|
1118
|
+
displayName?: string;
|
|
1119
|
+
}): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
|
|
1120
|
+
private static isSignupFallbackError;
|
|
1018
1121
|
/**
|
|
1019
1122
|
* Fetch WebAuthn attestation options to register a new passkey for the
|
|
1020
1123
|
* currently authenticated user.
|
|
@@ -1387,6 +1490,14 @@ interface SubscribeWithSnapshotOptions<T> {
|
|
|
1387
1490
|
* forget callback handlers don't need to also wrap the await.
|
|
1388
1491
|
*/
|
|
1389
1492
|
onSnapshotError?: (err: Error) => void;
|
|
1493
|
+
/**
|
|
1494
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
1495
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
1496
|
+
* and resumes from it across reconnects; the SDK acks consumed events and, on
|
|
1497
|
+
* a void/reset gap, re-snapshots. Omit for legacy stateless behaviour. Use
|
|
1498
|
+
* `resolveConsumerId()` (exported) to auto-generate + persist one per device.
|
|
1499
|
+
*/
|
|
1500
|
+
consumerId?: string;
|
|
1390
1501
|
}
|
|
1391
1502
|
interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
1392
1503
|
/** Cursor to resume from. Undefined = fresh subscription, deliver only new events. */
|
|
@@ -1422,6 +1533,14 @@ interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
|
1422
1533
|
* `where` filters or per-user feeds) must persist independent cursors.
|
|
1423
1534
|
*/
|
|
1424
1535
|
cursorKey?: string;
|
|
1536
|
+
/**
|
|
1537
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
1538
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
1539
|
+
* and resumes from it across reconnects; the SDK acks consumed events and, on
|
|
1540
|
+
* a void/reset gap, re-snapshots. Omit for legacy stateless behaviour. Use
|
|
1541
|
+
* `resolveConsumerId()` (exported) to auto-generate + persist one per device.
|
|
1542
|
+
*/
|
|
1543
|
+
consumerId?: string;
|
|
1425
1544
|
/** Called on inserts. Receives the document merged with `_eventId`. */
|
|
1426
1545
|
onInsert?: (doc: T & {
|
|
1427
1546
|
_id: string;
|
|
@@ -1443,7 +1562,7 @@ interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
|
1443
1562
|
* is tracked in #710. Document-bearing deletes are unaffected.
|
|
1444
1563
|
*/
|
|
1445
1564
|
onDelete?: (documentId: string, eventId: string) => void | Promise<void>;
|
|
1446
|
-
/** Called when the server emits an event-gap. See GapReason for the
|
|
1565
|
+
/** Called when the server emits an event-gap. See GapReason for the codes. */
|
|
1447
1566
|
onGap?: (info: StreamGapInfo) => void;
|
|
1448
1567
|
/** Called on handshake rejection (not-stream-collection, invalid sinceId, etc.) and handler failures. */
|
|
1449
1568
|
onError?: (error: Error) => void;
|
|
@@ -2056,4 +2175,4 @@ interface SpacelrClient {
|
|
|
2056
2175
|
}
|
|
2057
2176
|
declare function createClient(config: SpacelrClientConfig): SpacelrClient;
|
|
2058
2177
|
|
|
2059
|
-
export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
|
|
2178
|
+
export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ interface LoginResponse {
|
|
|
42
42
|
user: {
|
|
43
43
|
id: string;
|
|
44
44
|
sub: string;
|
|
45
|
-
email: string;
|
|
45
|
+
email: string | null;
|
|
46
46
|
username?: string;
|
|
47
47
|
name?: string;
|
|
48
48
|
roles: string[];
|
|
@@ -90,7 +90,7 @@ interface UserInfo {
|
|
|
90
90
|
}
|
|
91
91
|
interface UserProfile {
|
|
92
92
|
id: string;
|
|
93
|
-
email: string;
|
|
93
|
+
email: string | null;
|
|
94
94
|
username?: string;
|
|
95
95
|
name?: string;
|
|
96
96
|
roles: string[];
|
|
@@ -245,7 +245,23 @@ interface PasskeyRegistrationResponseJSON {
|
|
|
245
245
|
interface PasskeyLoginResponse {
|
|
246
246
|
user: {
|
|
247
247
|
id: string;
|
|
248
|
-
email: string;
|
|
248
|
+
email: string | null;
|
|
249
|
+
roles: string[];
|
|
250
|
+
};
|
|
251
|
+
access_token: string;
|
|
252
|
+
refresh_token?: string;
|
|
253
|
+
expires_in?: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Response returned by the email-less passkey SIGNUP flow (#780). Same shape as
|
|
257
|
+
* {@link PasskeyLoginResponse} (a freshly-created passkey account is always
|
|
258
|
+
* email-less, so `email` is null), kept as a distinct name for clarity.
|
|
259
|
+
*/
|
|
260
|
+
interface PasskeySignupResponse {
|
|
261
|
+
user: {
|
|
262
|
+
id: string;
|
|
263
|
+
email: string | null;
|
|
264
|
+
username?: string;
|
|
249
265
|
roles: string[];
|
|
250
266
|
};
|
|
251
267
|
access_token: string;
|
|
@@ -647,7 +663,7 @@ interface RealtimeConfig {
|
|
|
647
663
|
*/
|
|
648
664
|
onTokenRefreshed?: (listener: (accessToken: string) => void) => () => void;
|
|
649
665
|
}
|
|
650
|
-
type GapReason = 'outside-retention-window' | 'redis-unavailable' | 'replay-error' | 'replay-truncated';
|
|
666
|
+
type GapReason = 'outside-retention-window' | 'redis-unavailable' | 'replay-error' | 'replay-truncated' | 'evicted' | 'auth-unavailable' | 'log-reset';
|
|
651
667
|
interface StreamGapInfo {
|
|
652
668
|
projectId: string;
|
|
653
669
|
collectionName: string;
|
|
@@ -659,6 +675,14 @@ interface StreamSubscriptionOptions {
|
|
|
659
675
|
projectId: string;
|
|
660
676
|
collectionName: string;
|
|
661
677
|
sinceId?: string;
|
|
678
|
+
/**
|
|
679
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
680
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
681
|
+
* and RESUMES from it (overriding `sinceId`/`fromStart`), returns
|
|
682
|
+
* `{ generation, session, resumeCursor }`, and expects `ack-events`. Absent →
|
|
683
|
+
* legacy stateless behaviour.
|
|
684
|
+
*/
|
|
685
|
+
consumerId?: string;
|
|
662
686
|
/**
|
|
663
687
|
* #685 — "replay from earliest retained". When true, a brand-new subscription
|
|
664
688
|
* (no prior cursor) replays every retained stream entry from the earliest
|
|
@@ -682,7 +706,7 @@ interface StreamSubscriptionOptions {
|
|
|
682
706
|
eventId: string;
|
|
683
707
|
event: DatabaseChangeEvent;
|
|
684
708
|
}) => void | Promise<void>;
|
|
685
|
-
/** Called when the server emits an event-gap. See GapReason for the
|
|
709
|
+
/** Called when the server emits an event-gap. See GapReason for the codes. */
|
|
686
710
|
onGap?: (info: StreamGapInfo) => void;
|
|
687
711
|
/** Called on handshake rejection (not-stream-collection, invalid sinceId, etc.) and handler failures. */
|
|
688
712
|
onError?: (error: Error) => void;
|
|
@@ -746,6 +770,10 @@ declare class RealtimeClient {
|
|
|
746
770
|
unsubscribe: () => void;
|
|
747
771
|
realtimeMode: 'pubsub' | 'stream';
|
|
748
772
|
latestStreamId: string | null;
|
|
773
|
+
/** #768 — the durable position the server RESUMED from (null for a fresh
|
|
774
|
+
* consumer, or after a reset-to-'0' following eviction/log-reset/late-grant).
|
|
775
|
+
* Non-null ⇒ this is a resume; the caller should SKIP the snapshot. */
|
|
776
|
+
resumeCursor: string | null;
|
|
749
777
|
}>;
|
|
750
778
|
/**
|
|
751
779
|
* Shared body for `subscribeWithCursor` and
|
|
@@ -852,6 +880,19 @@ declare class RealtimeClient {
|
|
|
852
880
|
*/
|
|
853
881
|
private resubscribeRoom;
|
|
854
882
|
private emitSubscribeEvents;
|
|
883
|
+
/** #768 — capture the durable fencing tokens from a successful handshake so
|
|
884
|
+
* `ack-events` echoes the (generation, session) the server expects. */
|
|
885
|
+
private captureDurableHandshake;
|
|
886
|
+
/**
|
|
887
|
+
* #768 — schedule a coalesced durable ack. Only durable subscriptions (a
|
|
888
|
+
* consumerId with a captured generation+session) ack. At most one ack per
|
|
889
|
+
* microtask drain, carrying the highest delivered seq — cumulative on the
|
|
890
|
+
* server, so a burst of N events costs one ack, not N.
|
|
891
|
+
*/
|
|
892
|
+
private scheduleDurableAck;
|
|
893
|
+
/** #768 — emit `ack-events` for `seq`; a fenced/evicted response routes into
|
|
894
|
+
* the gap-recovery path so the caller re-snapshots (§12.5/§12.1). */
|
|
895
|
+
private emitDurableAck;
|
|
855
896
|
private buildStreamPayload;
|
|
856
897
|
private unsubscribeStream;
|
|
857
898
|
private dispatchStreamEvent;
|
|
@@ -905,6 +946,28 @@ declare function memoryCursorStorage(): CursorStorage;
|
|
|
905
946
|
*/
|
|
906
947
|
declare function localStorageCursorStorage(prefix?: string): CursorStorage;
|
|
907
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Well-known storage key under which the SDK persists an auto-generated durable
|
|
951
|
+
* consumer id (one per device/app install).
|
|
952
|
+
*/
|
|
953
|
+
declare const CONSUMER_ID_STORAGE_KEY = "spacelr:consumer-id";
|
|
954
|
+
/**
|
|
955
|
+
* Resolve the durable-subscription consumer id (#768 §12.2 / R7).
|
|
956
|
+
*
|
|
957
|
+
* A durable subscription's cursor is owned by a *consumer identity* — a stable
|
|
958
|
+
* per-device/app id — not by the user, so one device's ack never hides a row
|
|
959
|
+
* from another consumer of the same user.
|
|
960
|
+
*
|
|
961
|
+
* Precedence:
|
|
962
|
+
* 1. An explicit `consumerId` the app passes → used verbatim (the app owns
|
|
963
|
+
* identity, e.g. a device id it already has).
|
|
964
|
+
* 2. Else, if `storage` is provided, load a previously-persisted id, or generate
|
|
965
|
+
* one and persist it so it is stable across restarts/reconnects.
|
|
966
|
+
* 3. Else (no storage), an ephemeral id is generated — durable resume then only
|
|
967
|
+
* holds within the live session (a reload gets a new identity).
|
|
968
|
+
*/
|
|
969
|
+
declare function resolveConsumerId(explicit: string | undefined, storage: CursorStorage | undefined, key?: string): Promise<string>;
|
|
970
|
+
|
|
908
971
|
type AuthState = 'authenticated' | 'unauthenticated';
|
|
909
972
|
type AuthStateListener = (state: AuthState) => void | Promise<void>;
|
|
910
973
|
declare class AuthModule {
|
|
@@ -1015,6 +1078,46 @@ declare class AuthModule {
|
|
|
1015
1078
|
* against the options returned by `beginPasskeyLogin()`, completing login.
|
|
1016
1079
|
*/
|
|
1017
1080
|
verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
|
|
1083
|
+
* (#780) — creating a brand-new account with no email and no password. The
|
|
1084
|
+
* project must have passkeys AND public registration enabled. No account is
|
|
1085
|
+
* created until {@link verifyPasskeySignup} succeeds.
|
|
1086
|
+
*
|
|
1087
|
+
* IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
|
|
1088
|
+
* account. Before offering signup, the app MUST first attempt a discoverable
|
|
1089
|
+
* passkey login ({@link beginPasskeyLogin} with no email); only offer signup
|
|
1090
|
+
* when the user has no existing passkey. Skipping this creates duplicate,
|
|
1091
|
+
* fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
|
|
1092
|
+
*/
|
|
1093
|
+
beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Verify a WebAuthn attestation produced by `navigator.credentials.create()`
|
|
1096
|
+
* against the options from {@link beginPasskeySignup}, materializing the
|
|
1097
|
+
* email-less account and returning JWT tokens (the caller is now logged in).
|
|
1098
|
+
*/
|
|
1099
|
+
verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
|
|
1100
|
+
/**
|
|
1101
|
+
* One-call email-less passkey signup with the B1 idempotency fallback baked
|
|
1102
|
+
* in. The browser WebAuthn functions are injected (the SDK stays transport-
|
|
1103
|
+
* only and does not depend on `@simplewebauthn/browser`):
|
|
1104
|
+
*
|
|
1105
|
+
* 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
|
|
1106
|
+
* 2. If verify fails with `challenge_expired`, a network/timeout error, or
|
|
1107
|
+
* `passkey_already_registered` (the account was in fact created but the
|
|
1108
|
+
* response was lost, or the passkey already exists), fall back to a fresh
|
|
1109
|
+
* discoverable LOGIN ceremony and return that session. That fallback IS the
|
|
1110
|
+
* idempotency mechanism — the server never mints a session from a bare
|
|
1111
|
+
* credential lookup.
|
|
1112
|
+
* 3. If the login fallback also fails (genuinely no credential), the original
|
|
1113
|
+
* error is surfaced so the app can restart signup.
|
|
1114
|
+
*/
|
|
1115
|
+
createUserWithPasskey(ceremony: {
|
|
1116
|
+
startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
|
|
1117
|
+
startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
|
|
1118
|
+
displayName?: string;
|
|
1119
|
+
}): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
|
|
1120
|
+
private static isSignupFallbackError;
|
|
1018
1121
|
/**
|
|
1019
1122
|
* Fetch WebAuthn attestation options to register a new passkey for the
|
|
1020
1123
|
* currently authenticated user.
|
|
@@ -1387,6 +1490,14 @@ interface SubscribeWithSnapshotOptions<T> {
|
|
|
1387
1490
|
* forget callback handlers don't need to also wrap the await.
|
|
1388
1491
|
*/
|
|
1389
1492
|
onSnapshotError?: (err: Error) => void;
|
|
1493
|
+
/**
|
|
1494
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
1495
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
1496
|
+
* and resumes from it across reconnects; the SDK acks consumed events and, on
|
|
1497
|
+
* a void/reset gap, re-snapshots. Omit for legacy stateless behaviour. Use
|
|
1498
|
+
* `resolveConsumerId()` (exported) to auto-generate + persist one per device.
|
|
1499
|
+
*/
|
|
1500
|
+
consumerId?: string;
|
|
1390
1501
|
}
|
|
1391
1502
|
interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
1392
1503
|
/** Cursor to resume from. Undefined = fresh subscription, deliver only new events. */
|
|
@@ -1422,6 +1533,14 @@ interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
|
1422
1533
|
* `where` filters or per-user feeds) must persist independent cursors.
|
|
1423
1534
|
*/
|
|
1424
1535
|
cursorKey?: string;
|
|
1536
|
+
/**
|
|
1537
|
+
* #768 — durable-subscription consumer identity (opaque; a stable per-device
|
|
1538
|
+
* id). When set, the server keeps a durable delivery cursor for this consumer
|
|
1539
|
+
* and resumes from it across reconnects; the SDK acks consumed events and, on
|
|
1540
|
+
* a void/reset gap, re-snapshots. Omit for legacy stateless behaviour. Use
|
|
1541
|
+
* `resolveConsumerId()` (exported) to auto-generate + persist one per device.
|
|
1542
|
+
*/
|
|
1543
|
+
consumerId?: string;
|
|
1425
1544
|
/** Called on inserts. Receives the document merged with `_eventId`. */
|
|
1426
1545
|
onInsert?: (doc: T & {
|
|
1427
1546
|
_id: string;
|
|
@@ -1443,7 +1562,7 @@ interface SubscribeEventsHandlers<T = Record<string, unknown>> {
|
|
|
1443
1562
|
* is tracked in #710. Document-bearing deletes are unaffected.
|
|
1444
1563
|
*/
|
|
1445
1564
|
onDelete?: (documentId: string, eventId: string) => void | Promise<void>;
|
|
1446
|
-
/** Called when the server emits an event-gap. See GapReason for the
|
|
1565
|
+
/** Called when the server emits an event-gap. See GapReason for the codes. */
|
|
1447
1566
|
onGap?: (info: StreamGapInfo) => void;
|
|
1448
1567
|
/** Called on handshake rejection (not-stream-collection, invalid sinceId, etc.) and handler failures. */
|
|
1449
1568
|
onError?: (error: Error) => void;
|
|
@@ -2056,4 +2175,4 @@ interface SpacelrClient {
|
|
|
2056
2175
|
}
|
|
2057
2176
|
declare function createClient(config: SpacelrClientConfig): SpacelrClient;
|
|
2058
2177
|
|
|
2059
|
-
export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
|
|
2178
|
+
export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
|