@baasix/sdk 0.1.22 → 0.2.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/README.md CHANGED
@@ -199,6 +199,9 @@ await baasix.auth.sendMagicLink({
199
199
 
200
200
  // Verify (after user clicks link)
201
201
  const { user, token } = await baasix.auth.verifyMagicLink('verification-token');
202
+
203
+ // Session type / tenant, so the tenant's web/mobile session limits apply
204
+ await baasix.auth.verifyMagicLink(code, { authType: 'web', tenant_Id: 'tenant-uuid' });
202
205
  ```
203
206
 
204
207
  ### Password Reset
@@ -1598,6 +1601,10 @@ try {
1598
1601
  }
1599
1602
  ```
1600
1603
 
1604
+ `error.message` is the server's reason, read from `error.message`, a top-level `message`, or a plain-string `error` (`{ "error": "Authentication required" }`), and falls back to the HTTP status text. `error.code` comes from `error.code` or a top-level `code`. `error.details` is set only when the server sends an array of details.
1605
+
1606
+ A **401** with code `INVALID_SESSION` means the session is gone (logged out, expired, revoked or suspended user). With `autoRefresh` on, the SDK tries one token refresh and retries the request; if that fails, sign the user in again. A **503** `AUTH_UNAVAILABLE` is temporary — retry.
1607
+
1601
1608
  ## TypeScript Support
1602
1609
 
1603
1610
  ### Shared Types from @baasix/types
package/dist/index.cjs CHANGED
@@ -191,9 +191,11 @@ var HttpClient = class {
191
191
  errorData = await response.json();
192
192
  } catch {
193
193
  }
194
- const message = errorData.error?.message || errorData.message || response.statusText || "Request failed";
195
- const code = errorData.error?.code ?? errorData.code;
196
- const details = errorData.details;
194
+ const errorObj = typeof errorData.error === "object" && errorData.error !== null ? errorData.error : void 0;
195
+ const message = errorObj?.message || errorData.message || (typeof errorData.error === "string" ? errorData.error : "") || response.statusText || "Request failed";
196
+ const code = errorObj?.code ?? errorData.code;
197
+ const rawDetails = errorObj?.details ?? errorData.details;
198
+ const details = Array.isArray(rawDetails) ? rawDetails : void 0;
197
199
  return new BaasixError(message, response.status, code, details);
198
200
  }
199
201
  /**
@@ -899,12 +901,15 @@ var AuthModule = class {
899
901
  * @example
900
902
  * ```typescript
901
903
  * const { user, token } = await baasix.auth.verifyMagicLink('verification-token');
904
+ *
905
+ * // Enforce the tenant's web/mobile session limits for this sign-in
906
+ * await baasix.auth.verifyMagicLink(code, { authType: 'web', tenant_Id });
902
907
  * ```
903
908
  */
904
- async verifyMagicLink(token) {
909
+ async verifyMagicLink(token, opts) {
905
910
  const response = await this.client.get(
906
911
  `/auth/magiclink/${encodeURIComponent(token)}`,
907
- { skipAuth: true }
912
+ { skipAuth: true, params: opts }
908
913
  );
909
914
  await this.storeTokens(response);
910
915
  this.emitAuthStateChange("SIGNED_IN", response.user);