@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/dist/index.js
CHANGED
|
@@ -189,9 +189,11 @@ var HttpClient = class {
|
|
|
189
189
|
errorData = await response.json();
|
|
190
190
|
} catch {
|
|
191
191
|
}
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
192
|
+
const errorObj = typeof errorData.error === "object" && errorData.error !== null ? errorData.error : void 0;
|
|
193
|
+
const message = errorObj?.message || errorData.message || (typeof errorData.error === "string" ? errorData.error : "") || response.statusText || "Request failed";
|
|
194
|
+
const code = errorObj?.code ?? errorData.code;
|
|
195
|
+
const rawDetails = errorObj?.details ?? errorData.details;
|
|
196
|
+
const details = rawDetails == null ? void 0 : Array.isArray(rawDetails) ? rawDetails : typeof rawDetails === "object" ? [rawDetails] : [{ message: String(rawDetails) }];
|
|
195
197
|
return new BaasixError(message, response.status, code, details);
|
|
196
198
|
}
|
|
197
199
|
/**
|
|
@@ -897,12 +899,23 @@ var AuthModule = class {
|
|
|
897
899
|
* @example
|
|
898
900
|
* ```typescript
|
|
899
901
|
* const { user, token } = await baasix.auth.verifyMagicLink('verification-token');
|
|
902
|
+
*
|
|
903
|
+
* // Enforce the tenant's web/mobile session limits for this sign-in
|
|
904
|
+
* await baasix.auth.verifyMagicLink(code, { authType: 'web', tenant_Id });
|
|
905
|
+
*
|
|
906
|
+
* // Emailed code + email: wrong codes are counted and the code is burned after 5
|
|
907
|
+
* await baasix.auth.verifyMagicLink(code, { email: 'user@example.com', authType: 'web' });
|
|
900
908
|
* ```
|
|
901
909
|
*/
|
|
902
|
-
async verifyMagicLink(token) {
|
|
903
|
-
const
|
|
904
|
-
|
|
910
|
+
async verifyMagicLink(token, opts) {
|
|
911
|
+
const { email, ...params } = opts || {};
|
|
912
|
+
const response = email ? await this.client.post(
|
|
913
|
+
"/auth/magiclink/verify",
|
|
914
|
+
{ email, code: token, ...params },
|
|
905
915
|
{ skipAuth: true }
|
|
916
|
+
) : await this.client.get(
|
|
917
|
+
`/auth/magiclink/${encodeURIComponent(token)}`,
|
|
918
|
+
{ skipAuth: true, params }
|
|
906
919
|
);
|
|
907
920
|
await this.storeTokens(response);
|
|
908
921
|
this.emitAuthStateChange("SIGNED_IN", response.user);
|
|
@@ -943,9 +956,20 @@ var AuthModule = class {
|
|
|
943
956
|
* @example
|
|
944
957
|
* ```typescript
|
|
945
958
|
* await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
|
|
959
|
+
*
|
|
960
|
+
* // Emailed code + email: wrong codes are counted and the code is burned after 5
|
|
961
|
+
* await baasix.auth.resetPassword('K7M2PQ9X', 'newpassword123', { email: 'user@example.com' });
|
|
946
962
|
* ```
|
|
947
963
|
*/
|
|
948
|
-
async resetPassword(token, newPassword) {
|
|
964
|
+
async resetPassword(token, newPassword, opts) {
|
|
965
|
+
if (opts?.email) {
|
|
966
|
+
await this.client.post(
|
|
967
|
+
"/auth/password/reset/verify",
|
|
968
|
+
{ email: opts.email, code: token, password: newPassword },
|
|
969
|
+
{ skipAuth: true }
|
|
970
|
+
);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
949
973
|
await this.client.post(
|
|
950
974
|
`/auth/password/reset/${encodeURIComponent(token)}`,
|
|
951
975
|
{ password: newPassword },
|