@sparkvault/sdk-js 12.0.2 → 12.0.3

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/errors.d.ts CHANGED
@@ -66,6 +66,16 @@ export declare class TimeoutError extends SparkVaultError {
66
66
  export declare class UserCancelledError extends SparkVaultError {
67
67
  constructor(message?: string);
68
68
  }
69
+ /**
70
+ * The identity provider answered a FedCM sign-in with an error of its own
71
+ * (the browser's `IdentityCredentialError`), after the browser showed the
72
+ * person its error dialog: the request reached the provider, which refused or
73
+ * failed it, so it is no cancel. `code` is the provider's answer
74
+ * (`server_error`, `access_denied`, ...).
75
+ */
76
+ export declare class IdentityProviderError extends SparkVaultError {
77
+ constructor(code: string);
78
+ }
69
79
  export declare class PopupBlockedError extends SparkVaultError {
70
80
  constructor();
71
81
  }
package/dist/index.cjs CHANGED
@@ -830,6 +830,20 @@ class UserCancelledError extends SparkVaultError {
830
830
  Object.setPrototypeOf(this, UserCancelledError.prototype);
831
831
  }
832
832
  }
833
+ /**
834
+ * The identity provider answered a FedCM sign-in with an error of its own
835
+ * (the browser's `IdentityCredentialError`), after the browser showed the
836
+ * person its error dialog: the request reached the provider, which refused or
837
+ * failed it, so it is no cancel. `code` is the provider's answer
838
+ * (`server_error`, `access_denied`, ...).
839
+ */
840
+ class IdentityProviderError extends SparkVaultError {
841
+ constructor(code) {
842
+ super('The identity provider could not complete the sign-in.', code || 'identity_provider_error');
843
+ this.name = 'IdentityProviderError';
844
+ Object.setPrototypeOf(this, IdentityProviderError.prototype);
845
+ }
846
+ }
833
847
  class PopupBlockedError extends SparkVaultError {
834
848
  constructor() {
835
849
  super('Popup was blocked. Please allow popups for this site.', 'popup_blocked');
@@ -10194,6 +10208,20 @@ function decodeTokenSegment(segment, message) {
10194
10208
  throw new ValidationError(message);
10195
10209
  }
10196
10210
  }
10211
+ /**
10212
+ * The provider's own answer to a FedCM id assertion, as the browser rejects
10213
+ * with it (an `IdentityCredentialError`, a DOMException read by its name, so
10214
+ * neither the class's presence nor the realm it was made in matters), or null
10215
+ * for any other rejection.
10216
+ */
10217
+ function identityProviderErrorOf(error) {
10218
+ if (typeof error !== 'object' || error === null)
10219
+ return null;
10220
+ const { name, error: code } = error;
10221
+ if (name !== 'IdentityCredentialError')
10222
+ return null;
10223
+ return new IdentityProviderError(typeof code === 'string' ? code : '');
10224
+ }
10197
10225
  class IdentityModule {
10198
10226
  constructor(config) {
10199
10227
  this.renderer = null;
@@ -10256,8 +10284,12 @@ class IdentityModule {
10256
10284
  * `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
10257
10285
  *
10258
10286
  * @returns the verified result, or `null` when the browser has no FedCM
10259
- * support (so the caller can fall back). Throws `UserCancelledError` when the
10260
- * person dismisses the chooser.
10287
+ * support (so the caller can fall back). Throws `UserCancelledError` when
10288
+ * the browser ends the request without a credential: the person dismissed
10289
+ * the chooser, or the browser had no SparkVault account to offer (the
10290
+ * browser reports both alike). Throws `IdentityProviderError`, carrying
10291
+ * SparkVault's own error code, when SparkVault answered the sign-in with an
10292
+ * error.
10261
10293
  *
10262
10294
  * @example
10263
10295
  * const result = (await sv.products.identity.isFedcmAvailable())
@@ -10291,9 +10323,12 @@ class IdentityModule {
10291
10323
  credential = await getCredential(request);
10292
10324
  }
10293
10325
  catch (error) {
10294
- // The browser rejects with an AbortError/NotAllowedError when the person
10295
- // dismisses the chooser — normalize that to the SDK's cancel signal.
10296
- throw new UserCancelledError(error instanceof Error ? error.message : undefined);
10326
+ // The provider's own answer to the id assertion is no cancel. Every other
10327
+ // rejection ends the request without a credential: the browser answers a
10328
+ // dismissed chooser and a provider with no account to offer with the same
10329
+ // NetworkError, so that is the SDK's cancel signal.
10330
+ throw identityProviderErrorOf(error)
10331
+ ?? new UserCancelledError(error instanceof Error ? error.message : undefined);
10297
10332
  }
10298
10333
  const token = credential?.token;
10299
10334
  if (!token) {
@@ -17652,7 +17687,7 @@ class SparkVault {
17652
17687
  }
17653
17688
  /** Get the SDK version */
17654
17689
  static get version() {
17655
- return '12.0.2';
17690
+ return '12.0.3';
17656
17691
  }
17657
17692
  }
17658
17693
  if (typeof window !== 'undefined') {
@@ -17667,6 +17702,7 @@ exports.AuthorizationError = AuthorizationError;
17667
17702
  exports.EntropyModule = EntropyModule;
17668
17703
  exports.FoldersModule = FoldersModule;
17669
17704
  exports.IdentityModule = IdentityModule;
17705
+ exports.IdentityProviderError = IdentityProviderError;
17670
17706
  exports.IngotsModule = IngotsModule;
17671
17707
  exports.NAME_CONFLICT_POLICIES = NAME_CONFLICT_POLICIES;
17672
17708
  exports.NOTIFY_PRESETS = NOTIFY_PRESETS;