@spacelr/sdk 0.12.0 → 0.14.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 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,13 +245,54 @@ 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;
252
268
  refresh_token?: string;
253
269
  expires_in?: number;
254
270
  }
271
+ /**
272
+ * Response returned by redeeming a recovery phrase (#784). A recovery account is
273
+ * email-less by construction, so `email` is null — same shape as
274
+ * {@link PasskeyLoginResponse}, kept as a distinct name for clarity. Redeeming
275
+ * installs the returned tokens into the SDK session, exactly like a passkey login.
276
+ */
277
+ interface RecoveryRedeemResponse {
278
+ user: {
279
+ id: string;
280
+ email: string | null;
281
+ roles: string[];
282
+ };
283
+ access_token: string;
284
+ refresh_token?: string;
285
+ expires_in?: number;
286
+ }
287
+ /**
288
+ * Whether the signed-in account has an active recovery-phrase binding (#784),
289
+ * and when it was last bound or rotated. Used to prompt the user to set or
290
+ * refresh their recovery phrase.
291
+ */
292
+ interface RecoveryStatusResponse {
293
+ hasBinding: boolean;
294
+ boundAt?: string;
295
+ }
255
296
  /** Result of verifying a passkey registration attestation. */
256
297
  interface PasskeyRegistrationResult {
257
298
  verified: boolean;
@@ -1062,6 +1103,46 @@ declare class AuthModule {
1062
1103
  * against the options returned by `beginPasskeyLogin()`, completing login.
1063
1104
  */
1064
1105
  verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
1106
+ /**
1107
+ * Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
1108
+ * (#780) — creating a brand-new account with no email and no password. The
1109
+ * project must have passkeys AND public registration enabled. No account is
1110
+ * created until {@link verifyPasskeySignup} succeeds.
1111
+ *
1112
+ * IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
1113
+ * account. Before offering signup, the app MUST first attempt a discoverable
1114
+ * passkey login ({@link beginPasskeyLogin} with no email); only offer signup
1115
+ * when the user has no existing passkey. Skipping this creates duplicate,
1116
+ * fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
1117
+ */
1118
+ beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
1119
+ /**
1120
+ * Verify a WebAuthn attestation produced by `navigator.credentials.create()`
1121
+ * against the options from {@link beginPasskeySignup}, materializing the
1122
+ * email-less account and returning JWT tokens (the caller is now logged in).
1123
+ */
1124
+ verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
1125
+ /**
1126
+ * One-call email-less passkey signup with the B1 idempotency fallback baked
1127
+ * in. The browser WebAuthn functions are injected (the SDK stays transport-
1128
+ * only and does not depend on `@simplewebauthn/browser`):
1129
+ *
1130
+ * 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
1131
+ * 2. If verify fails with `challenge_expired`, a network/timeout error, or
1132
+ * `passkey_already_registered` (the account was in fact created but the
1133
+ * response was lost, or the passkey already exists), fall back to a fresh
1134
+ * discoverable LOGIN ceremony and return that session. That fallback IS the
1135
+ * idempotency mechanism — the server never mints a session from a bare
1136
+ * credential lookup.
1137
+ * 3. If the login fallback also fails (genuinely no credential), the original
1138
+ * error is surfaced so the app can restart signup.
1139
+ */
1140
+ createUserWithPasskey(ceremony: {
1141
+ startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
1142
+ startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
1143
+ displayName?: string;
1144
+ }): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
1145
+ private static isSignupFallbackError;
1065
1146
  /**
1066
1147
  * Fetch WebAuthn attestation options to register a new passkey for the
1067
1148
  * currently authenticated user.
@@ -1091,6 +1172,29 @@ declare class AuthModule {
1091
1172
  deleted: true;
1092
1173
  }>;
1093
1174
  private storeTokensFromLogin;
1175
+ /**
1176
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
1177
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
1178
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
1179
+ * email-less accounts may bind. `secret` is a 43-char base64url string.
1180
+ */
1181
+ bindRecoveryPhrase(secret: string): Promise<{
1182
+ bound: true;
1183
+ }>;
1184
+ /**
1185
+ * Redeem a recovery secret to restore access to the SAME account without a
1186
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
1187
+ * Single-use: after a successful redeem the client should bind a fresh phrase
1188
+ * and add a new passkey. Installs the returned tokens into the SDK session,
1189
+ * exactly like a passkey login.
1190
+ */
1191
+ redeemRecoveryPhrase(secret: string): Promise<RecoveryRedeemResponse>;
1192
+ /**
1193
+ * Whether the signed-in account has an active recovery binding, and when it
1194
+ * was last bound/rotated — so the app can prompt the user to set or refresh
1195
+ * their recovery phrase. Authenticated.
1196
+ */
1197
+ getRecoveryStatus(): Promise<RecoveryStatusResponse>;
1094
1198
  private storeTokensFromRegister;
1095
1199
  }
1096
1200
 
@@ -2119,4 +2223,4 @@ interface SpacelrClient {
2119
2223
  }
2120
2224
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2121
2225
 
2122
- 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 };
2226
+ 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 RecoveryRedeemResponse, type RecoveryStatusResponse, 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,13 +245,54 @@ 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;
252
268
  refresh_token?: string;
253
269
  expires_in?: number;
254
270
  }
271
+ /**
272
+ * Response returned by redeeming a recovery phrase (#784). A recovery account is
273
+ * email-less by construction, so `email` is null — same shape as
274
+ * {@link PasskeyLoginResponse}, kept as a distinct name for clarity. Redeeming
275
+ * installs the returned tokens into the SDK session, exactly like a passkey login.
276
+ */
277
+ interface RecoveryRedeemResponse {
278
+ user: {
279
+ id: string;
280
+ email: string | null;
281
+ roles: string[];
282
+ };
283
+ access_token: string;
284
+ refresh_token?: string;
285
+ expires_in?: number;
286
+ }
287
+ /**
288
+ * Whether the signed-in account has an active recovery-phrase binding (#784),
289
+ * and when it was last bound or rotated. Used to prompt the user to set or
290
+ * refresh their recovery phrase.
291
+ */
292
+ interface RecoveryStatusResponse {
293
+ hasBinding: boolean;
294
+ boundAt?: string;
295
+ }
255
296
  /** Result of verifying a passkey registration attestation. */
256
297
  interface PasskeyRegistrationResult {
257
298
  verified: boolean;
@@ -1062,6 +1103,46 @@ declare class AuthModule {
1062
1103
  * against the options returned by `beginPasskeyLogin()`, completing login.
1063
1104
  */
1064
1105
  verifyPasskeyLogin(response: PasskeyAuthenticationResponseJSON): Promise<PasskeyLoginResponse>;
1106
+ /**
1107
+ * Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
1108
+ * (#780) — creating a brand-new account with no email and no password. The
1109
+ * project must have passkeys AND public registration enabled. No account is
1110
+ * created until {@link verifyPasskeySignup} succeeds.
1111
+ *
1112
+ * IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
1113
+ * account. Before offering signup, the app MUST first attempt a discoverable
1114
+ * passkey login ({@link beginPasskeyLogin} with no email); only offer signup
1115
+ * when the user has no existing passkey. Skipping this creates duplicate,
1116
+ * fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
1117
+ */
1118
+ beginPasskeySignup(displayName?: string): Promise<PasskeyRegistrationOptionsJSON>;
1119
+ /**
1120
+ * Verify a WebAuthn attestation produced by `navigator.credentials.create()`
1121
+ * against the options from {@link beginPasskeySignup}, materializing the
1122
+ * email-less account and returning JWT tokens (the caller is now logged in).
1123
+ */
1124
+ verifyPasskeySignup(response: PasskeyRegistrationResponseJSON): Promise<PasskeySignupResponse>;
1125
+ /**
1126
+ * One-call email-less passkey signup with the B1 idempotency fallback baked
1127
+ * in. The browser WebAuthn functions are injected (the SDK stays transport-
1128
+ * only and does not depend on `@simplewebauthn/browser`):
1129
+ *
1130
+ * 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
1131
+ * 2. If verify fails with `challenge_expired`, a network/timeout error, or
1132
+ * `passkey_already_registered` (the account was in fact created but the
1133
+ * response was lost, or the passkey already exists), fall back to a fresh
1134
+ * discoverable LOGIN ceremony and return that session. That fallback IS the
1135
+ * idempotency mechanism — the server never mints a session from a bare
1136
+ * credential lookup.
1137
+ * 3. If the login fallback also fails (genuinely no credential), the original
1138
+ * error is surfaced so the app can restart signup.
1139
+ */
1140
+ createUserWithPasskey(ceremony: {
1141
+ startRegistration: (optionsJSON: PasskeyRegistrationOptionsJSON) => Promise<PasskeyRegistrationResponseJSON>;
1142
+ startAuthentication: (optionsJSON: PasskeyAuthenticationOptionsJSON) => Promise<PasskeyAuthenticationResponseJSON>;
1143
+ displayName?: string;
1144
+ }): Promise<PasskeySignupResponse | PasskeyLoginResponse>;
1145
+ private static isSignupFallbackError;
1065
1146
  /**
1066
1147
  * Fetch WebAuthn attestation options to register a new passkey for the
1067
1148
  * currently authenticated user.
@@ -1091,6 +1172,29 @@ declare class AuthModule {
1091
1172
  deleted: true;
1092
1173
  }>;
1093
1174
  private storeTokensFromLogin;
1175
+ /**
1176
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
1177
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
1178
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
1179
+ * email-less accounts may bind. `secret` is a 43-char base64url string.
1180
+ */
1181
+ bindRecoveryPhrase(secret: string): Promise<{
1182
+ bound: true;
1183
+ }>;
1184
+ /**
1185
+ * Redeem a recovery secret to restore access to the SAME account without a
1186
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
1187
+ * Single-use: after a successful redeem the client should bind a fresh phrase
1188
+ * and add a new passkey. Installs the returned tokens into the SDK session,
1189
+ * exactly like a passkey login.
1190
+ */
1191
+ redeemRecoveryPhrase(secret: string): Promise<RecoveryRedeemResponse>;
1192
+ /**
1193
+ * Whether the signed-in account has an active recovery binding, and when it
1194
+ * was last bound/rotated — so the app can prompt the user to set or refresh
1195
+ * their recovery phrase. Authenticated.
1196
+ */
1197
+ getRecoveryStatus(): Promise<RecoveryStatusResponse>;
1094
1198
  private storeTokensFromRegister;
1095
1199
  }
1096
1200
 
@@ -2119,4 +2223,4 @@ interface SpacelrClient {
2119
2223
  }
2120
2224
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2121
2225
 
2122
- 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 };
2226
+ 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 RecoveryRedeemResponse, type RecoveryStatusResponse, 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.js CHANGED
@@ -1870,13 +1870,14 @@ function mapProfile(u) {
1870
1870
  const name = u.name ?? ([u.firstName, u.lastName].filter(Boolean).join(" ") || void 0) ?? u.displayName;
1871
1871
  return {
1872
1872
  id: u.id ?? u._id ?? u.userId ?? u.sub ?? "",
1873
- email: u.email ?? "",
1873
+ // Honest null for email-less (passkey-only) accounts (#780), not a '' coercion.
1874
+ email: u.email ?? null,
1874
1875
  username: u.username,
1875
1876
  name,
1876
1877
  roles: u.roles ?? []
1877
1878
  };
1878
1879
  }
1879
- var AuthModule = class {
1880
+ var AuthModule = class _AuthModule {
1880
1881
  constructor(http, tokenManager, config) {
1881
1882
  this.stateListeners = /* @__PURE__ */ new Set();
1882
1883
  this.lastEmittedState = null;
@@ -2192,6 +2193,82 @@ var AuthModule = class {
2192
2193
  await this.storeTokensFromLogin(result);
2193
2194
  return result;
2194
2195
  }
2196
+ /**
2197
+ * Fetch WebAuthn attestation options to begin an email-less passkey SIGNUP
2198
+ * (#780) — creating a brand-new account with no email and no password. The
2199
+ * project must have passkeys AND public registration enabled. No account is
2200
+ * created until {@link verifyPasskeySignup} succeeds.
2201
+ *
2202
+ * IMPORTANT (identity routing, B8): a signup ceremony always mints a NEW
2203
+ * account. Before offering signup, the app MUST first attempt a discoverable
2204
+ * passkey login ({@link beginPasskeyLogin} with no email); only offer signup
2205
+ * when the user has no existing passkey. Skipping this creates duplicate,
2206
+ * fragmented accounts. {@link createUserWithPasskey} bundles that fallback.
2207
+ */
2208
+ async beginPasskeySignup(displayName) {
2209
+ return this.http.request({
2210
+ method: "POST",
2211
+ path: "/auth/passkey/signup/options",
2212
+ body: displayName ? { displayName } : {}
2213
+ });
2214
+ }
2215
+ /**
2216
+ * Verify a WebAuthn attestation produced by `navigator.credentials.create()`
2217
+ * against the options from {@link beginPasskeySignup}, materializing the
2218
+ * email-less account and returning JWT tokens (the caller is now logged in).
2219
+ */
2220
+ async verifyPasskeySignup(response) {
2221
+ const result = await this.http.request({
2222
+ method: "POST",
2223
+ path: "/auth/passkey/signup/verify",
2224
+ body: { response }
2225
+ });
2226
+ await this.storeTokensFromLogin(result);
2227
+ return result;
2228
+ }
2229
+ /**
2230
+ * One-call email-less passkey signup with the B1 idempotency fallback baked
2231
+ * in. The browser WebAuthn functions are injected (the SDK stays transport-
2232
+ * only and does not depend on `@simplewebauthn/browser`):
2233
+ *
2234
+ * 1. `beginPasskeySignup` → `startRegistration` → `verifyPasskeySignup`.
2235
+ * 2. If verify fails with `challenge_expired`, a network/timeout error, or
2236
+ * `passkey_already_registered` (the account was in fact created but the
2237
+ * response was lost, or the passkey already exists), fall back to a fresh
2238
+ * discoverable LOGIN ceremony and return that session. That fallback IS the
2239
+ * idempotency mechanism — the server never mints a session from a bare
2240
+ * credential lookup.
2241
+ * 3. If the login fallback also fails (genuinely no credential), the original
2242
+ * error is surfaced so the app can restart signup.
2243
+ */
2244
+ async createUserWithPasskey(ceremony) {
2245
+ const options = await this.beginPasskeySignup(ceremony.displayName);
2246
+ const attestation = await ceremony.startRegistration(options);
2247
+ try {
2248
+ return await this.verifyPasskeySignup(attestation);
2249
+ } catch (error) {
2250
+ if (!_AuthModule.isSignupFallbackError(error)) {
2251
+ throw error;
2252
+ }
2253
+ try {
2254
+ const loginOptions = await this.beginPasskeyLogin();
2255
+ const assertion = await ceremony.startAuthentication(loginOptions);
2256
+ return await this.verifyPasskeyLogin(assertion);
2257
+ } catch {
2258
+ throw error;
2259
+ }
2260
+ }
2261
+ }
2262
+ static isSignupFallbackError(error) {
2263
+ if (error instanceof SpacelrNetworkError || error instanceof SpacelrTimeoutError) {
2264
+ return true;
2265
+ }
2266
+ if (error instanceof SpacelrError) {
2267
+ const message = (error.message || "").toLowerCase();
2268
+ return error.statusCode === 409 || message.includes("challenge_expired") || message.includes("already_registered");
2269
+ }
2270
+ return false;
2271
+ }
2195
2272
  /**
2196
2273
  * Fetch WebAuthn attestation options to register a new passkey for the
2197
2274
  * currently authenticated user.
@@ -2258,6 +2335,53 @@ var AuthModule = class {
2258
2335
  });
2259
2336
  this.emitState("authenticated");
2260
2337
  }
2338
+ // ─── Recover-with-phrase (#784) ───
2339
+ // For an email-less passkey account (#780) that has lost every passkey. The
2340
+ // caller derives an opaque 32-byte base64url secret from a BIP39 phrase and
2341
+ // passes it here — the SDK is transport-only and never sees or generates the
2342
+ // phrase (no wordlist in the bundle).
2343
+ /**
2344
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
2345
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
2346
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
2347
+ * email-less accounts may bind. `secret` is a 43-char base64url string.
2348
+ */
2349
+ async bindRecoveryPhrase(secret) {
2350
+ return this.http.request({
2351
+ method: "POST",
2352
+ path: "/auth/recovery/bind",
2353
+ body: { secret },
2354
+ authenticated: true
2355
+ });
2356
+ }
2357
+ /**
2358
+ * Redeem a recovery secret to restore access to the SAME account without a
2359
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
2360
+ * Single-use: after a successful redeem the client should bind a fresh phrase
2361
+ * and add a new passkey. Installs the returned tokens into the SDK session,
2362
+ * exactly like a passkey login.
2363
+ */
2364
+ async redeemRecoveryPhrase(secret) {
2365
+ const result = await this.http.request({
2366
+ method: "POST",
2367
+ path: "/auth/recovery/redeem",
2368
+ body: { secret }
2369
+ });
2370
+ await this.storeTokensFromLogin(result);
2371
+ return result;
2372
+ }
2373
+ /**
2374
+ * Whether the signed-in account has an active recovery binding, and when it
2375
+ * was last bound/rotated — so the app can prompt the user to set or refresh
2376
+ * their recovery phrase. Authenticated.
2377
+ */
2378
+ async getRecoveryStatus() {
2379
+ return this.http.request({
2380
+ method: "GET",
2381
+ path: "/auth/recovery/status",
2382
+ authenticated: true
2383
+ });
2384
+ }
2261
2385
  async storeTokensFromRegister(response) {
2262
2386
  if (!response.access_token) return;
2263
2387
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;