@sparkvault/sdk-js 11.1.11 → 11.1.13

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/README.md CHANGED
@@ -245,7 +245,7 @@ await fetch('/api/auth/login', {
245
245
  |--------|------|-------------|
246
246
  | `email` | `string` | Pre-fill email address (mutually exclusive with phone) |
247
247
  | `phone` | `string` | Pre-fill phone in E.164 format, e.g. `"+14155551234"` |
248
- | `backdropBlur` | `boolean` | Override backdrop blur setting from app config |
248
+ | `backdropBlur` | `boolean` | Override the `backdropBlur` set at `SparkVault.init()` for this sign-in |
249
249
  | `flow` | `"auto" \| "popup" \| "redirect"` | `"auto"` (default) and `"popup"` open the popup; `"redirect"` navigates the tab to the sign-in page instead (its return leg is `handleRedirectResult()`) |
250
250
  | `prompt` | `"select_account"` | Always show the sign-in page's account chooser instead of silently continuing as the current account — the affordance for a "switch account" button. Any other value is ignored. |
251
251
  | `onCancel` | `function` | Callback when the person closes the popup without signing in |
package/dist/http.d.ts CHANGED
@@ -13,42 +13,9 @@ export interface RequestOptions {
13
13
  vat?: string;
14
14
  timeout?: number;
15
15
  }
16
- /** Capacity state for a pool, driving low-capacity nudges in the UI. */
17
- export type PoolState = 'ok' | 'notice' | 'warning' | 'exhausted';
18
- /** Shared storage-pool capacity snapshot carried on `meta.pools`. */
19
- export interface StoragePool {
20
- used_gb: number;
21
- limit_gb: number;
22
- pct: number;
23
- state: PoolState;
24
- }
25
- /** Shared bandwidth-pool capacity snapshot carried on `meta.pools`. */
26
- export interface BandwidthPool {
27
- used_gb: number;
28
- limit_gb: number;
29
- pct: number;
30
- state: PoolState;
31
- /** ISO timestamp when the bandwidth cycle resets. */
32
- cycle_resets_at: string;
33
- }
34
- /** Pooled-capacity snapshot that rides on every response's `meta`. */
35
- export interface PoolsMeta {
36
- storage: StoragePool;
37
- bandwidth: BandwidthPool;
38
- }
39
- /**
40
- * Response envelope metadata. `pools` rides on responses so clients can render
41
- * low-capacity nudges without a separate fetch. Unknown fields are preserved.
42
- */
43
- export interface ResponseMeta {
44
- pools?: PoolsMeta;
45
- [key: string]: unknown;
46
- }
16
+ /** A successful answer: its `data`, unwrapped from the `{ data, meta }` envelope. */
47
17
  export interface ApiResponse<T = unknown> {
48
18
  data: T;
49
- meta?: ResponseMeta;
50
- status: number;
51
- headers: Headers;
52
19
  }
53
20
  export declare class HttpClient {
54
21
  private readonly config;
@@ -67,11 +34,6 @@ export declare class HttpClient {
67
34
  */
68
35
  private createErrorFromResponse;
69
36
  private unwrapApiResponse;
70
- /**
71
- * Pull the `meta` envelope (carrying `pools` capacity snapshots) off a
72
- * standard `{ data, meta }` response. Returns undefined for bare responses.
73
- */
74
- private extractResponseMeta;
75
37
  get<T = unknown>(path: ApiPath, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
76
38
  post<T = unknown>(path: ApiPath, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
77
39
  put<T = unknown>(path: ApiPath, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
package/dist/index.cjs CHANGED
@@ -1367,13 +1367,7 @@ class HttpClient {
1367
1367
  if (!response.ok) {
1368
1368
  throw this.createErrorFromResponse(await readApiFailure(response));
1369
1369
  }
1370
- const parsed = await this.parseResponse(response);
1371
- return {
1372
- data: this.unwrapApiResponse(parsed),
1373
- meta: this.extractResponseMeta(parsed),
1374
- status: response.status,
1375
- headers: response.headers,
1376
- };
1370
+ return { data: this.unwrapApiResponse(await this.parseResponse(response)) };
1377
1371
  },
1378
1372
  fail: (failure, cause) => {
1379
1373
  switch (failure) {
@@ -1442,19 +1436,6 @@ class HttpClient {
1442
1436
  }
1443
1437
  return data;
1444
1438
  }
1445
- /**
1446
- * Pull the `meta` envelope (carrying `pools` capacity snapshots) off a
1447
- * standard `{ data, meta }` response. Returns undefined for bare responses.
1448
- */
1449
- extractResponseMeta(data) {
1450
- if (typeof data === 'object' && data !== null) {
1451
- const record = data;
1452
- if (typeof record.meta === 'object' && record.meta !== null) {
1453
- return record.meta;
1454
- }
1455
- }
1456
- return undefined;
1457
- }
1458
1439
  get(path, options) {
1459
1440
  return this.request(path, { ...options, method: 'GET' });
1460
1441
  }
@@ -2318,17 +2299,20 @@ class IdentityApi extends SparkVaultApi {
2318
2299
  });
2319
2300
  }
2320
2301
  /**
2321
- * Build auth context params for API requests (OIDC/simple mode).
2302
+ * The auth context a code or magic-link send carries: only its OIDC
2303
+ * `auth_request_id`. Simple mode is read where a login completes
2304
+ * (verifyOtp, completePasskeyVerify), never by a send.
2305
+ */
2306
+ buildAuthRequestParam(authContext) {
2307
+ return authContext?.authRequestId ? { auth_request_id: authContext.authRequestId } : {};
2308
+ }
2309
+ /**
2310
+ * Build auth context params for the completing requests (OIDC/simple mode).
2322
2311
  * Converts AuthContext to snake_case params expected by backend.
2323
2312
  */
2324
2313
  buildAuthContextParams(authContext) {
2325
- if (!authContext)
2326
- return {};
2327
- const params = {};
2328
- if (authContext.authRequestId) {
2329
- params.auth_request_id = authContext.authRequestId;
2330
- }
2331
- if (authContext.simpleMode) {
2314
+ const params = this.buildAuthRequestParam(authContext);
2315
+ if (authContext?.simpleMode) {
2332
2316
  params.simple_mode = {
2333
2317
  success_url: authContext.simpleMode.successUrl,
2334
2318
  failure_url: authContext.simpleMode.failureUrl,
@@ -2345,7 +2329,7 @@ class IdentityApi extends SparkVaultApi {
2345
2329
  return this.request('POST', apiPath `/otp/send`, {
2346
2330
  recipient: params.recipient,
2347
2331
  method: params.method,
2348
- ...this.buildAuthContextParams(params.authContext),
2332
+ ...this.buildAuthRequestParam(params.authContext),
2349
2333
  });
2350
2334
  }
2351
2335
  /**
@@ -2371,59 +2355,20 @@ class IdentityApi extends SparkVaultApi {
2371
2355
  code: params.code,
2372
2356
  });
2373
2357
  }
2374
- /**
2375
- * Start passkey registration from a freshly verified identifier.
2376
- */
2377
- async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
2378
- const body = identityType === 'phone'
2379
- ? { phone: identity, registration_token: registrationToken }
2380
- : { email: identity, registration_token: registrationToken };
2381
- // Backend returns { options: PublicKeyCredentialCreationOptions, session: {...} }
2382
- // Extract and flatten to match PasskeyChallengeResponse
2383
- const response = await this.request('POST', apiPath `/passkey/register`, body);
2384
- return {
2385
- challenge: response.options.challenge,
2386
- rpId: response.options.rp.id,
2387
- rpName: response.options.rp.name,
2388
- userId: response.options.user.id,
2389
- userName: response.options.user.name,
2390
- timeout: response.options.timeout,
2391
- session: response.session,
2392
- };
2393
- }
2394
- /**
2395
- * Complete passkey registration
2396
- */
2397
- async completePasskeyRegister(params) {
2398
- const attestation = params.credential.response;
2399
- return this.request('POST', apiPath `/passkey/register/complete`, {
2400
- session: params.session,
2401
- credential: {
2402
- id: params.credential.id,
2403
- rawId: arrayBufferToBase64url(params.credential.rawId),
2404
- type: params.credential.type,
2405
- response: {
2406
- clientDataJSON: arrayBufferToBase64url(attestation.clientDataJSON),
2407
- attestationObject: arrayBufferToBase64url(attestation.attestationObject),
2408
- },
2409
- },
2410
- });
2411
- }
2412
2358
  /**
2413
2359
  * Start passkey verification. An optional identifier scopes the ceremony to
2414
2360
  * that person's credentials (`allowCredentials`) so the authenticator offers
2415
2361
  * only the matching passkey; omit it for a discoverable ceremony. Completion
2416
2362
  * always routes via the credential userHandle, so scoping is purely a hint.
2417
2363
  */
2418
- async startPasskeyVerify(identity, identityType = 'email', authContext) {
2364
+ async startPasskeyVerify(identity, identityType = 'email') {
2419
2365
  const identityParam = identity ? { [identityType]: identity } : {};
2420
2366
  // Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
2421
2367
  // Extract and flatten to match PasskeyChallengeResponse
2422
- const response = await this.request('POST', apiPath `/passkey/verify`, { ...identityParam, ...this.buildAuthContextParams(authContext) });
2368
+ const response = await this.request('POST', apiPath `/passkey/verify`, identityParam);
2423
2369
  return {
2424
2370
  challenge: response.options.challenge,
2425
2371
  rpId: response.options.rpId,
2426
- rpName: 'SparkVault Identity', // Not returned by verify endpoint
2427
2372
  timeout: response.options.timeout,
2428
2373
  ...(response.options.allowCredentials ? { allowCredentials: response.options.allowCredentials } : {}),
2429
2374
  session: response.session,
@@ -2518,9 +2463,8 @@ class IdentityApi extends SparkVaultApi {
2518
2463
  async sendSparkLink(email, connectionId, authContext) {
2519
2464
  return this.request('POST', apiPath `/sparklink/send`, {
2520
2465
  email,
2521
- type: 'verify_identity',
2522
2466
  connection_id: connectionId,
2523
- ...this.buildAuthContextParams(authContext),
2467
+ ...this.buildAuthRequestParam(authContext),
2524
2468
  });
2525
2469
  }
2526
2470
  /**
@@ -3205,7 +3149,7 @@ class PasskeyHandler {
3205
3149
  // passkeys so the authenticator offers only the matching credential;
3206
3150
  // without one it falls back to a discoverable ceremony.
3207
3151
  const identityType = this.state.identityType === 'phone' ? 'phone' : 'email';
3208
- const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType, this.state.authContext);
3152
+ const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType);
3209
3153
  const credential = await navigator.credentials.get({
3210
3154
  ...(signal ? { signal } : {}),
3211
3155
  publicKey: {
@@ -3217,7 +3161,6 @@ class PasskeyHandler {
3217
3161
  allowCredentials: challenge.allowCredentials.map((c) => ({
3218
3162
  type: c.type,
3219
3163
  id: webauthnBuffer(c.id),
3220
- ...(c.transports ? { transports: c.transports } : {}),
3221
3164
  })),
3222
3165
  } : {}),
3223
3166
  },
@@ -5062,8 +5005,9 @@ class PasskeyAutoView {
5062
5005
  /**
5063
5006
  * Passkey Registration Prompt View
5064
5007
  *
5065
- * Shown after successful PIN verification to encourage users to add a passkey.
5066
- * Includes benefits list and skip option with 30-day cookie suppression.
5008
+ * Shown after a login whose recommendations name a passkey, to encourage the
5009
+ * person to add one. Includes a benefits list and a skip option, which the
5010
+ * server suppresses for 30 days (POST /recommendations/dismiss).
5067
5011
  */
5068
5012
  class PasskeyPromptView {
5069
5013
  constructor(props) {
@@ -6235,13 +6179,6 @@ class IdentityRenderer {
6235
6179
  if (config.branding) {
6236
6180
  this.container.updateBranding(config.branding);
6237
6181
  }
6238
- // Update backdrop blur: client override > server config (branding.backdrop_blur) > default (true)
6239
- const resolvedBackdropBlur = this.options.backdropBlur !== undefined
6240
- ? this.options.backdropBlur
6241
- : config.branding?.backdrop_blur !== undefined
6242
- ? config.branding.backdrop_blur
6243
- : true;
6244
- this.container.updateBackdropBlur(resolvedBackdropBlur);
6245
6182
  await this.showInitialAuthStep();
6246
6183
  }
6247
6184
  catch (error) {
@@ -6324,12 +6261,6 @@ class IdentityRenderer {
6324
6261
  if (config.branding) {
6325
6262
  this.container.updateBranding(config.branding);
6326
6263
  }
6327
- const resolvedBackdropBlur = this.options.backdropBlur !== undefined
6328
- ? this.options.backdropBlur
6329
- : config.branding?.backdrop_blur !== undefined
6330
- ? config.branding.backdrop_blur
6331
- : true;
6332
- this.container.updateBackdropBlur(resolvedBackdropBlur);
6333
6264
  await this.showInitialAuthStep();
6334
6265
  }
6335
6266
  catch (error) {
@@ -9332,12 +9263,11 @@ function unlockPageScroll() {
9332
9263
  class ModalShell {
9333
9264
  constructor(options) {
9334
9265
  this.open = true;
9335
- this.blurClass = `${options.classPrefix}-blur`;
9336
9266
  this.opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
9337
9267
  this.overlay = document.createElement('div');
9338
9268
  this.overlay.id = options.overlayId;
9339
9269
  this.overlay.className = `${options.classPrefix}-overlay`;
9340
- this.overlay.classList.toggle(this.blurClass, options.backdropBlur);
9270
+ this.overlay.classList.toggle(`${options.classPrefix}-blur`, options.backdropBlur);
9341
9271
  this.overlay.setAttribute('role', 'dialog');
9342
9272
  this.overlay.setAttribute('aria-modal', 'true');
9343
9273
  this.overlay.setAttribute('aria-labelledby', options.titleId);
@@ -9360,9 +9290,6 @@ class ModalShell {
9360
9290
  lockPageScroll();
9361
9291
  this.modal.focus({ preventScroll: true });
9362
9292
  }
9363
- setBackdropBlur(enabled) {
9364
- this.overlay.classList.toggle(this.blurClass, enabled);
9365
- }
9366
9293
  /** Remove the dialog, release the scroll lock, and return focus to the opener. */
9367
9294
  destroy() {
9368
9295
  if (!this.open)
@@ -9501,13 +9428,6 @@ class ModalContainer {
9501
9428
  this.floatingCloseBtn = null;
9502
9429
  }
9503
9430
  }
9504
- /**
9505
- * Update the backdrop blur setting with the resolved value (client
9506
- * override > server config > default).
9507
- */
9508
- updateBackdropBlur(enabled) {
9509
- this.shell?.setBackdropBlur(enabled);
9510
- }
9511
9431
  createHeader(branding) {
9512
9432
  const header = document.createElement('div');
9513
9433
  header.className = 'sv-header';
@@ -9930,12 +9850,6 @@ class InlineContainer {
9930
9850
  return;
9931
9851
  applyBrandingTheme(branding);
9932
9852
  }
9933
- /**
9934
- * Update backdrop blur setting (no-op for inline container).
9935
- */
9936
- updateBackdropBlur(_enabled) {
9937
- // No-op - inline containers don't have backdrop blur
9938
- }
9939
9853
  /**
9940
9854
  * Minimal-chrome toggle (no-op for inline container).
9941
9855
  * Inline containers don't own page-level chrome to hide.
@@ -13914,12 +13828,6 @@ class UploadModalContainer {
13914
13828
  this.branding = branding;
13915
13829
  this.refreshHeader();
13916
13830
  }
13917
- /**
13918
- * Update backdrop blur setting.
13919
- */
13920
- updateBackdropBlur(enabled) {
13921
- this.shell?.setBackdropBlur(enabled);
13922
- }
13923
13831
  /**
13924
13832
  * Set dark mode for uploading/ceremony states.
13925
13833
  */
@@ -14018,12 +13926,6 @@ class UploadInlineContainer {
14018
13926
  updateBranding(_branding) {
14019
13927
  // No-op
14020
13928
  }
14021
- /**
14022
- * Update backdrop blur setting (no-op for inline container).
14023
- */
14024
- updateBackdropBlur(_enabled) {
14025
- // No-op - inline containers don't have backdrop blur
14026
- }
14027
13929
  /**
14028
13930
  * Get the body element for content rendering.
14029
13931
  */
@@ -16433,15 +16335,14 @@ class IngotsModule {
16433
16335
  *
16434
16336
  * @example
16435
16337
  * await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
16436
- * await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com', { expiresInSeconds: 86400 });
16437
16338
  */
16438
- async addInvite(vault, ingotId, identity, options = {}) {
16339
+ async addInvite(vault, ingotId, identity) {
16439
16340
  if (!identity?.trim()) {
16440
16341
  throw new ValidationError('Invite identity is required');
16441
16342
  }
16442
16343
  const vaultId = requireVaultId(vault);
16443
16344
  const id = requireResourceId(ingotId, 'ingotId');
16444
- const response = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/sharing/invite`, { identity, expires_in_seconds: options.expiresInSeconds }, { vat: vault.vatToken });
16345
+ const response = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/sharing/invite`, { identity }, { vat: vault.vatToken });
16445
16346
  return mapInvite(response.data);
16446
16347
  }
16447
16348
  /**
@@ -16601,9 +16502,9 @@ function mapSharingConfig(wire) {
16601
16502
  }
16602
16503
  function mapInvite(wire) {
16603
16504
  return {
16604
- id: wire.id ?? wire.invite_id ?? '',
16505
+ id: wire.invite_id,
16605
16506
  identity: wire.identity,
16606
- identityType: wire.identity_type ?? 'email',
16507
+ identityType: wire.identity_type,
16607
16508
  };
16608
16509
  }
16609
16510
 
@@ -17163,22 +17064,6 @@ const logger = {
17163
17064
  * Error level - always logged regardless of debug mode
17164
17065
  */
17165
17066
  error: (message, ...args) => log('error', message, ...args),
17166
- /**
17167
- * Group related logs together (only in debug mode)
17168
- */
17169
- group: (label) => {
17170
- if (debugEnabled) {
17171
- console.group(`[SparkVault] ${label}`);
17172
- }
17173
- },
17174
- /**
17175
- * End a log group
17176
- */
17177
- groupEnd: () => {
17178
- if (debugEnabled) {
17179
- console.groupEnd();
17180
- }
17181
- },
17182
17067
  };
17183
17068
 
17184
17069
  /**
@@ -17315,7 +17200,7 @@ class SparkVault {
17315
17200
  }
17316
17201
  /** Get the SDK version */
17317
17202
  static get version() {
17318
- return '11.1.11';
17203
+ return '11.1.13';
17319
17204
  }
17320
17205
  }
17321
17206
  if (typeof window !== 'undefined') {