@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 +16 -3
- package/dist/index.cjs +21 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/modules/auth.cjs +16 -5
- package/dist/modules/auth.cjs.map +1 -1
- package/dist/modules/auth.d.cts +17 -3
- package/dist/modules/auth.d.ts +17 -3
- package/dist/modules/auth.js +16 -5
- package/dist/modules/auth.js.map +1 -1
- package/package.json +2 -2
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 = Array.isArray(rawDetails) ? rawDetails : void 0;
|
|
195
197
|
return new BaasixError(message, response.status, code, details);
|
|
196
198
|
}
|
|
197
199
|
/**
|
|
@@ -897,12 +899,15 @@ 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 });
|
|
900
905
|
* ```
|
|
901
906
|
*/
|
|
902
|
-
async verifyMagicLink(token) {
|
|
907
|
+
async verifyMagicLink(token, opts) {
|
|
903
908
|
const response = await this.client.get(
|
|
904
909
|
`/auth/magiclink/${encodeURIComponent(token)}`,
|
|
905
|
-
{ skipAuth: true }
|
|
910
|
+
{ skipAuth: true, params: opts }
|
|
906
911
|
);
|
|
907
912
|
await this.storeTokens(response);
|
|
908
913
|
this.emitAuthStateChange("SIGNED_IN", response.user);
|
|
@@ -913,10 +918,17 @@ var AuthModule = class {
|
|
|
913
918
|
*
|
|
914
919
|
* @example
|
|
915
920
|
* ```typescript
|
|
921
|
+
* // Link mode (default): emails a clickable reset URL
|
|
916
922
|
* await baasix.auth.forgotPassword({
|
|
917
923
|
* email: 'user@example.com',
|
|
918
924
|
* redirectUrl: 'https://myapp.com/reset-password'
|
|
919
925
|
* });
|
|
926
|
+
*
|
|
927
|
+
* // Code mode: emails a short one-time code, no redirectUrl needed
|
|
928
|
+
* await baasix.auth.forgotPassword({
|
|
929
|
+
* email: 'user@example.com',
|
|
930
|
+
* mode: 'code'
|
|
931
|
+
* });
|
|
920
932
|
* ```
|
|
921
933
|
*/
|
|
922
934
|
async forgotPassword(options) {
|
|
@@ -924,17 +936,18 @@ var AuthModule = class {
|
|
|
924
936
|
"/auth/password/reset",
|
|
925
937
|
{
|
|
926
938
|
email: options.email,
|
|
927
|
-
link: options.redirectUrl
|
|
939
|
+
link: options.redirectUrl,
|
|
940
|
+
mode: options.mode || "link"
|
|
928
941
|
},
|
|
929
942
|
{ skipAuth: true }
|
|
930
943
|
);
|
|
931
944
|
}
|
|
932
945
|
/**
|
|
933
|
-
* Reset password using a reset token
|
|
946
|
+
* Reset password using a reset token or emailed one-time code
|
|
934
947
|
*
|
|
935
948
|
* @example
|
|
936
949
|
* ```typescript
|
|
937
|
-
* await baasix.auth.resetPassword('reset-token', 'newpassword123');
|
|
950
|
+
* await baasix.auth.resetPassword('reset-token-or-code', 'newpassword123');
|
|
938
951
|
* ```
|
|
939
952
|
*/
|
|
940
953
|
async resetPassword(token, newPassword) {
|