@sparkvault/sdk-js 7.0.1 → 7.0.2

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/config.d.ts CHANGED
@@ -16,6 +16,11 @@ export interface SparkVaultConfig {
16
16
  getAccessToken?: () => string | null | Promise<string | null>;
17
17
  /** Optional API key for server-side SDK use. */
18
18
  apiKey?: string;
19
+ /**
20
+ * OIDC client id registered for this account. Required only for FedCM
21
+ * one-click sign-in (`signInWithFedcm()`), which asserts to a registered RP.
22
+ */
23
+ clientId?: string;
19
24
  /** Request timeout in milliseconds (default: 30000) */
20
25
  timeout?: number;
21
26
  /**
@@ -43,6 +48,7 @@ export interface ResolvedConfig {
43
48
  accessToken?: string;
44
49
  getAccessToken?: () => string | null | Promise<string | null>;
45
50
  apiKey?: string;
51
+ clientId?: string;
46
52
  preloadConfig: boolean;
47
53
  backdropBlur: boolean;
48
54
  allowedDownloadHostPatterns: RegExp[];
package/dist/index.d.ts CHANGED
@@ -16,6 +16,11 @@ interface SparkVaultConfig {
16
16
  getAccessToken?: () => string | null | Promise<string | null>;
17
17
  /** Optional API key for server-side SDK use. */
18
18
  apiKey?: string;
19
+ /**
20
+ * OIDC client id registered for this account. Required only for FedCM
21
+ * one-click sign-in (`signInWithFedcm()`), which asserts to a registered RP.
22
+ */
23
+ clientId?: string;
19
24
  /** Request timeout in milliseconds (default: 30000) */
20
25
  timeout?: number;
21
26
  /**
@@ -43,6 +48,7 @@ interface ResolvedConfig {
43
48
  accessToken?: string;
44
49
  getAccessToken?: () => string | null | Promise<string | null>;
45
50
  apiKey?: string;
51
+ clientId?: string;
46
52
  preloadConfig: boolean;
47
53
  backdropBlur: boolean;
48
54
  allowedDownloadHostPatterns: RegExp[];
@@ -307,6 +313,30 @@ declare class IdentityModule {
307
313
  * @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
308
314
  */
309
315
  portalUrl(options?: PortalUrlOptions): string;
316
+ /**
317
+ * One-click sign-in through the browser's native FedCM account chooser.
318
+ *
319
+ * When the person is already signed into auth.sv (carrying the SSO session),
320
+ * the browser surfaces a "Continue as …" prompt with no popup, redirect, or
321
+ * typing. Requires a registered `clientId` in the SDK config and a browser
322
+ * with FedCM support — callers should feature-detect with
323
+ * `IdentityModule.isFedcmAvailable()` and fall back to `verify()` otherwise.
324
+ *
325
+ * @returns the verified result, or `null` when the browser has no FedCM
326
+ * support (so the caller can fall back). Throws `UserCancelledError` when the
327
+ * person dismisses the chooser.
328
+ *
329
+ * @example
330
+ * const result = (await sv.products.identity.isFedcmAvailable())
331
+ * ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.verify())
332
+ * : await sv.products.identity.verify();
333
+ */
334
+ signInWithFedcm(options?: {
335
+ mediation?: 'optional' | 'required' | 'silent';
336
+ nonce?: string;
337
+ }): Promise<VerifyResult | null>;
338
+ /** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
339
+ static isFedcmAvailable(): boolean;
310
340
  /**
311
341
  * Verify user identity.
312
342
  *
@@ -37,6 +37,30 @@ export declare class IdentityModule {
37
37
  * @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
38
38
  */
39
39
  portalUrl(options?: PortalUrlOptions): string;
40
+ /**
41
+ * One-click sign-in through the browser's native FedCM account chooser.
42
+ *
43
+ * When the person is already signed into auth.sv (carrying the SSO session),
44
+ * the browser surfaces a "Continue as …" prompt with no popup, redirect, or
45
+ * typing. Requires a registered `clientId` in the SDK config and a browser
46
+ * with FedCM support — callers should feature-detect with
47
+ * `IdentityModule.isFedcmAvailable()` and fall back to `verify()` otherwise.
48
+ *
49
+ * @returns the verified result, or `null` when the browser has no FedCM
50
+ * support (so the caller can fall back). Throws `UserCancelledError` when the
51
+ * person dismisses the chooser.
52
+ *
53
+ * @example
54
+ * const result = (await sv.products.identity.isFedcmAvailable())
55
+ * ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.verify())
56
+ * : await sv.products.identity.verify();
57
+ */
58
+ signInWithFedcm(options?: {
59
+ mediation?: 'optional' | 'required' | 'silent';
60
+ nonce?: string;
61
+ }): Promise<VerifyResult | null>;
62
+ /** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
63
+ static isFedcmAvailable(): boolean;
40
64
  /**
41
65
  * Verify user identity.
42
66
  *
@@ -181,6 +181,12 @@ export interface SdkConfig {
181
181
  methods: MethodId[];
182
182
  /** WebSocket domain for SparkLink push notifications (e.g., 'ws.sparkvault.com') */
183
183
  wsDomain?: string;
184
+ /** Cross-domain SSO posture. `enabled`: this account participates in silent
185
+ * SSO. `forced`: auth.sv is the only sign-in surface (no local widget UI). */
186
+ sso?: {
187
+ enabled: boolean;
188
+ forced: boolean;
189
+ };
184
190
  }
185
191
  /** Method metadata for SDK rendering (static lookup) */
186
192
  export interface MethodMetadata {
@@ -171,6 +171,7 @@ function resolveConfig(config) {
171
171
  accessToken: config.accessToken,
172
172
  getAccessToken: config.getAccessToken,
173
173
  apiKey: config.apiKey,
174
+ clientId: config.clientId,
174
175
  preloadConfig: config.preloadConfig !== false, // Default: true
175
176
  backdropBlur: config.backdropBlur !== false, // Default: true
176
177
  allowedDownloadHostPatterns: config.allowedDownloadHostPatterns ?? DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS,
@@ -7849,6 +7850,74 @@ class IdentityModule {
7849
7850
  }
7850
7851
  return new URL(path, this.config.portalBaseUrl).toString();
7851
7852
  }
7853
+ /**
7854
+ * One-click sign-in through the browser's native FedCM account chooser.
7855
+ *
7856
+ * When the person is already signed into auth.sv (carrying the SSO session),
7857
+ * the browser surfaces a "Continue as …" prompt with no popup, redirect, or
7858
+ * typing. Requires a registered `clientId` in the SDK config and a browser
7859
+ * with FedCM support — callers should feature-detect with
7860
+ * `IdentityModule.isFedcmAvailable()` and fall back to `verify()` otherwise.
7861
+ *
7862
+ * @returns the verified result, or `null` when the browser has no FedCM
7863
+ * support (so the caller can fall back). Throws `UserCancelledError` when the
7864
+ * person dismisses the chooser.
7865
+ *
7866
+ * @example
7867
+ * const result = (await sv.products.identity.isFedcmAvailable())
7868
+ * ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.verify())
7869
+ * : await sv.products.identity.verify();
7870
+ */
7871
+ async signInWithFedcm(options = {}) {
7872
+ if (!IdentityModule.isFedcmAvailable()) {
7873
+ return null;
7874
+ }
7875
+ if (!this.config.clientId) {
7876
+ throw new ValidationError('clientId must be set in the SDK config to use FedCM sign-in', {
7877
+ field: 'clientId',
7878
+ });
7879
+ }
7880
+ const nonce = options.nonce ?? generateState();
7881
+ const configURL = `${this.config.portalBaseUrl}/${this.config.accountId}/fedcm/config.json`;
7882
+ const request = {
7883
+ identity: { providers: [{ configURL, clientId: this.config.clientId, nonce }] },
7884
+ ...(options.mediation ? { mediation: options.mediation } : {}),
7885
+ };
7886
+ let credential;
7887
+ try {
7888
+ // FedCM's `identity` provider request isn't in every TS DOM lib version, so
7889
+ // adapt navigator.credentials.get through our own request/credential types
7890
+ // (avoids naming the type-only `CredentialRequestOptions` DOM global).
7891
+ const getCredential = navigator.credentials.get.bind(navigator.credentials);
7892
+ credential = await getCredential(request);
7893
+ }
7894
+ catch (error) {
7895
+ // The browser rejects with an AbortError/NotAllowedError when the person
7896
+ // dismisses the chooser — normalize that to the SDK's cancel signal.
7897
+ throw new UserCancelledError(error instanceof Error ? error.message : undefined);
7898
+ }
7899
+ const token = credential?.token;
7900
+ if (!token) {
7901
+ throw new ValidationError('FedCM did not return a token');
7902
+ }
7903
+ // Same decode + issuer/expiry/alg validation every returned token goes through.
7904
+ const claims = this.decodeToken(token);
7905
+ return {
7906
+ token,
7907
+ identity: claims.identity,
7908
+ identityType: claims.identity_type,
7909
+ svid: claims.svid,
7910
+ sessionId: claims.session_id,
7911
+ };
7912
+ }
7913
+ /** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
7914
+ static isFedcmAvailable() {
7915
+ return (typeof window !== 'undefined' &&
7916
+ 'IdentityCredential' in window &&
7917
+ typeof navigator !== 'undefined' &&
7918
+ !!navigator.credentials &&
7919
+ typeof navigator.credentials.get === 'function');
7920
+ }
7852
7921
  /**
7853
7922
  * Verify user identity.
7854
7923
  *