@baasix/sdk 0.1.22 → 0.2.1
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 +13 -0
- package/dist/index.cjs +31 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/dist/modules/auth.cjs +26 -4
- package/dist/modules/auth.cjs.map +1 -1
- package/dist/modules/auth.d.cts +18 -2
- package/dist/modules/auth.d.ts +18 -2
- package/dist/modules/auth.js +26 -4
- package/dist/modules/auth.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,6 +199,12 @@ 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' });
|
|
205
|
+
|
|
206
|
+
// Emailed code + email: wrong codes are counted and the code is burned after 5 tries
|
|
207
|
+
await baasix.auth.verifyMagicLink(code, { email: 'user@example.com', authType: 'web' });
|
|
202
208
|
```
|
|
203
209
|
|
|
204
210
|
### Password Reset
|
|
@@ -218,6 +224,9 @@ await baasix.auth.forgotPassword({
|
|
|
218
224
|
|
|
219
225
|
// Reset password with the token or emailed code
|
|
220
226
|
await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
|
|
227
|
+
|
|
228
|
+
// With an emailed code, pass the email too (5-try limit per email)
|
|
229
|
+
await baasix.auth.resetPassword('K7M2PQ9X', 'newSecurePassword', { email: 'user@example.com' });
|
|
221
230
|
```
|
|
222
231
|
|
|
223
232
|
### Change Password
|
|
@@ -1598,6 +1607,10 @@ try {
|
|
|
1598
1607
|
}
|
|
1599
1608
|
```
|
|
1600
1609
|
|
|
1610
|
+
`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 always an array: a details array from the server is passed through, and a string or object detail is wrapped (`[{ message: "…" }]` or `[{ code, errors }]`).
|
|
1611
|
+
|
|
1612
|
+
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.
|
|
1613
|
+
|
|
1601
1614
|
## TypeScript Support
|
|
1602
1615
|
|
|
1603
1616
|
### 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
|
|
195
|
-
const
|
|
196
|
-
const
|
|
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 = rawDetails == null ? void 0 : Array.isArray(rawDetails) ? rawDetails : typeof rawDetails === "object" ? [rawDetails] : [{ message: String(rawDetails) }];
|
|
197
199
|
return new BaasixError(message, response.status, code, details);
|
|
198
200
|
}
|
|
199
201
|
/**
|
|
@@ -899,12 +901,23 @@ 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 });
|
|
907
|
+
*
|
|
908
|
+
* // Emailed code + email: wrong codes are counted and the code is burned after 5
|
|
909
|
+
* await baasix.auth.verifyMagicLink(code, { email: 'user@example.com', authType: 'web' });
|
|
902
910
|
* ```
|
|
903
911
|
*/
|
|
904
|
-
async verifyMagicLink(token) {
|
|
905
|
-
const
|
|
906
|
-
|
|
912
|
+
async verifyMagicLink(token, opts) {
|
|
913
|
+
const { email, ...params } = opts || {};
|
|
914
|
+
const response = email ? await this.client.post(
|
|
915
|
+
"/auth/magiclink/verify",
|
|
916
|
+
{ email, code: token, ...params },
|
|
907
917
|
{ skipAuth: true }
|
|
918
|
+
) : await this.client.get(
|
|
919
|
+
`/auth/magiclink/${encodeURIComponent(token)}`,
|
|
920
|
+
{ skipAuth: true, params }
|
|
908
921
|
);
|
|
909
922
|
await this.storeTokens(response);
|
|
910
923
|
this.emitAuthStateChange("SIGNED_IN", response.user);
|
|
@@ -945,9 +958,20 @@ var AuthModule = class {
|
|
|
945
958
|
* @example
|
|
946
959
|
* ```typescript
|
|
947
960
|
* await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
|
|
961
|
+
*
|
|
962
|
+
* // Emailed code + email: wrong codes are counted and the code is burned after 5
|
|
963
|
+
* await baasix.auth.resetPassword('K7M2PQ9X', 'newpassword123', { email: 'user@example.com' });
|
|
948
964
|
* ```
|
|
949
965
|
*/
|
|
950
|
-
async resetPassword(token, newPassword) {
|
|
966
|
+
async resetPassword(token, newPassword, opts) {
|
|
967
|
+
if (opts?.email) {
|
|
968
|
+
await this.client.post(
|
|
969
|
+
"/auth/password/reset/verify",
|
|
970
|
+
{ email: opts.email, code: token, password: newPassword },
|
|
971
|
+
{ skipAuth: true }
|
|
972
|
+
);
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
951
975
|
await this.client.post(
|
|
952
976
|
`/auth/password/reset/${encodeURIComponent(token)}`,
|
|
953
977
|
{ password: newPassword },
|