@baasix/sdk 0.1.21 → 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,19 +199,28 @@ 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
205
208
 
206
209
  ```typescript
207
- // Request reset
210
+ // Request reset (link mode: emails a clickable reset URL)
208
211
  await baasix.auth.forgotPassword({
209
212
  email: 'user@example.com',
210
213
  redirectUrl: 'https://myapp.com/reset-password',
211
214
  });
212
215
 
213
- // Reset password
214
- await baasix.auth.resetPassword('reset-token', 'newpassword123');
216
+ // Request reset (code mode: emails a short one-time code, no redirectUrl needed)
217
+ await baasix.auth.forgotPassword({
218
+ email: 'user@example.com',
219
+ mode: 'code',
220
+ });
221
+
222
+ // Reset password with the token or emailed code
223
+ await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
215
224
  ```
216
225
 
217
226
  ### Change Password
@@ -1592,6 +1601,10 @@ try {
1592
1601
  }
1593
1602
  ```
1594
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
+
1595
1608
  ## TypeScript Support
1596
1609
 
1597
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);
@@ -915,10 +920,17 @@ var AuthModule = class {
915
920
  *
916
921
  * @example
917
922
  * ```typescript
923
+ * // Link mode (default): emails a clickable reset URL
918
924
  * await baasix.auth.forgotPassword({
919
925
  * email: 'user@example.com',
920
926
  * redirectUrl: 'https://myapp.com/reset-password'
921
927
  * });
928
+ *
929
+ * // Code mode: emails a short one-time code, no redirectUrl needed
930
+ * await baasix.auth.forgotPassword({
931
+ * email: 'user@example.com',
932
+ * mode: 'code'
933
+ * });
922
934
  * ```
923
935
  */
924
936
  async forgotPassword(options) {
@@ -926,17 +938,18 @@ var AuthModule = class {
926
938
  "/auth/password/reset",
927
939
  {
928
940
  email: options.email,
929
- link: options.redirectUrl
941
+ link: options.redirectUrl,
942
+ mode: options.mode || "link"
930
943
  },
931
944
  { skipAuth: true }
932
945
  );
933
946
  }
934
947
  /**
935
- * Reset password using a reset token
948
+ * Reset password using a reset token or emailed one-time code
936
949
  *
937
950
  * @example
938
951
  * ```typescript
939
- * await baasix.auth.resetPassword('reset-token', 'newpassword123');
952
+ * await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
940
953
  * ```
941
954
  */
942
955
  async resetPassword(token, newPassword) {