@proveanything/smartlinks-auth-ui 0.4.3 → 0.4.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAY5D,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AA8I7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAmCjD,CAAC;AAwEF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAK/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA0sD5D,CAAC"}
1
+ {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAY5D,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AA8I7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAmCjD,CAAC;AAwEF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAK/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA8sD5D,CAAC"}
package/dist/index.esm.js CHANGED
@@ -12401,8 +12401,32 @@ function getFriendlyErrorMessage(error) {
12401
12401
  // Fall back to the server's message (already human-readable from backend)
12402
12402
  return error.message;
12403
12403
  }
12404
- // Handle standard Error objects — check message for known patterns
12404
+ // Handle standard Error objects
12405
12405
  if (error instanceof Error) {
12406
+ // SDK bug workaround: SDK may do `throw new Error(responseBodyObject)` which produces
12407
+ // message "[object Object]". Check for API error properties attached to the Error instance.
12408
+ const errAny = error;
12409
+ // Check if the Error has API error properties directly attached (e.g., error.statusCode, error.errorCode)
12410
+ if (typeof errAny.statusCode === 'number' || errAny.errorCode || errAny.response) {
12411
+ // Try to extract from attached properties
12412
+ const apiLike = errAny.response || errAny;
12413
+ if (isApiErrorLike(apiLike)) {
12414
+ return getFriendlyErrorMessage(apiLike);
12415
+ }
12416
+ }
12417
+ // Check if the Error has a `cause` with API error details (modern Error cause pattern)
12418
+ if (errAny.cause && typeof errAny.cause === 'object') {
12419
+ if (isApiErrorLike(errAny.cause)) {
12420
+ return getFriendlyErrorMessage(errAny.cause);
12421
+ }
12422
+ }
12423
+ // If the message is "[object Object]", the error was constructed from a plain object
12424
+ // This is useless - return a generic message instead
12425
+ if (error.message === '[object Object]') {
12426
+ // Log the actual error for debugging
12427
+ console.warn('[AuthKit] Error with [object Object] message. Raw error:', JSON.stringify(errAny, Object.getOwnPropertyNames(errAny)));
12428
+ return 'An unexpected error occurred. Please try again.';
12429
+ }
12406
12430
  // Check if the message itself contains a known API error pattern
12407
12431
  if (/already (registered|exists)/i.test(error.message)) {
12408
12432
  return 'This email is already registered.';
@@ -13233,6 +13257,8 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13233
13257
  }
13234
13258
  }
13235
13259
  catch (err) {
13260
+ // Debug: log the raw error shape to help diagnose SDK error wrapping issues
13261
+ log.error('handleEmailAuth error:', typeof err, err instanceof Error ? `Error.message=${err.message}` : '', JSON.stringify(err, Object.getOwnPropertyNames(err || {})));
13236
13262
  // Check if error is about email already registered (409 conflict)
13237
13263
  // Handle both SmartlinksApiError (statusCode 409) and plain Error with keyword matching
13238
13264
  if (mode === 'register' && (isConflictError(err) ||
@@ -13244,7 +13270,8 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13244
13270
  else {
13245
13271
  setError(getFriendlyErrorMessage(err));
13246
13272
  }
13247
- onAuthError?.(err instanceof Error ? err : new Error(getFriendlyErrorMessage(err)));
13273
+ const friendlyMsg = getFriendlyErrorMessage(err);
13274
+ onAuthError?.(err instanceof Error ? new Error(friendlyMsg) : new Error(friendlyMsg));
13248
13275
  }
13249
13276
  finally {
13250
13277
  setLoading(false);