@layers/amba-react-native 4.0.0 → 4.0.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/dist/index.cjs +56 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +48 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -351,7 +351,7 @@ function freshSeed() {
|
|
|
351
351
|
//#endregion
|
|
352
352
|
//#region src/index.ts
|
|
353
353
|
/** SDK semver — burned in at build time. Bump alongside package.json. */
|
|
354
|
-
const SDK_VERSION = "4.0.
|
|
354
|
+
const SDK_VERSION = "4.0.1";
|
|
355
355
|
let state = null;
|
|
356
356
|
function getState() {
|
|
357
357
|
if (!state) throw new AmbaApiError("NOT_INITIALIZED", "@layers/amba-react-native: SDK not configured. Call Amba.configure({ projectId, clientKey }) at app start.");
|
|
@@ -395,6 +395,24 @@ async function postAuth(state_, path, body) {
|
|
|
395
395
|
await notifyFromAuthResult(result);
|
|
396
396
|
return result;
|
|
397
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* POST helper for endpoints that return `{ data: { user } }` WITHOUT
|
|
400
|
+
* minting new tokens. Used by `linkSmsOtp` / `linkEmailOtp` / `unlink*`
|
|
401
|
+
* — these are "decorate the current user," not "re-authenticate."
|
|
402
|
+
* Existing session tokens stay untouched.
|
|
403
|
+
*/
|
|
404
|
+
async function postUserNoRotate(state_, path, body) {
|
|
405
|
+
return (await state_.http.post(path, body)).data.user;
|
|
406
|
+
}
|
|
407
|
+
async function unlinkProvider(provider) {
|
|
408
|
+
const s = getState();
|
|
409
|
+
const sessionToken = s.identity.getSessionToken();
|
|
410
|
+
if (!sessionToken) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
|
|
411
|
+
return postUserNoRotate(s, P.authUnlink, {
|
|
412
|
+
provider,
|
|
413
|
+
session_token: sessionToken
|
|
414
|
+
});
|
|
415
|
+
}
|
|
398
416
|
function requireEmail(email) {
|
|
399
417
|
const trimmed = email.trim();
|
|
400
418
|
if (trimmed === "") throw new AmbaApiError("VALIDATION_ERROR", "email must not be empty");
|
|
@@ -422,6 +440,8 @@ const P = {
|
|
|
422
440
|
authMagicLinkRequest: "/v1/client/auth/magic-link/request",
|
|
423
441
|
authMagicLinkVerify: "/v1/client/auth/magic-link/verify",
|
|
424
442
|
authLink: "/v1/client/auth/link",
|
|
443
|
+
authUnlink: "/v1/client/auth/unlink",
|
|
444
|
+
authIdentifiers: "/v1/client/auth/identifiers",
|
|
425
445
|
authRefresh: "/v1/client/auth/refresh",
|
|
426
446
|
authLogout: "/v1/client/auth/logout",
|
|
427
447
|
authMe: "/v1/client/auth/me",
|
|
@@ -605,6 +625,41 @@ const Amba = {
|
|
|
605
625
|
session_token: sessionToken
|
|
606
626
|
});
|
|
607
627
|
},
|
|
628
|
+
linkSmsOtp: async (phone, code) => {
|
|
629
|
+
requireE164Phone(phone);
|
|
630
|
+
requireOtpCode(code);
|
|
631
|
+
const s = getState();
|
|
632
|
+
const sessionToken = s.identity.getSessionToken();
|
|
633
|
+
if (!sessionToken) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
|
|
634
|
+
return postUserNoRotate(s, P.authLink, {
|
|
635
|
+
provider: "sms_otp",
|
|
636
|
+
phone,
|
|
637
|
+
code,
|
|
638
|
+
session_token: sessionToken
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
linkEmailOtp: async (email, code) => {
|
|
642
|
+
requireEmail(email);
|
|
643
|
+
requireOtpCode(code);
|
|
644
|
+
const s = getState();
|
|
645
|
+
const sessionToken = s.identity.getSessionToken();
|
|
646
|
+
if (!sessionToken) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
|
|
647
|
+
return postUserNoRotate(s, P.authLink, {
|
|
648
|
+
provider: "email_otp",
|
|
649
|
+
email,
|
|
650
|
+
code,
|
|
651
|
+
session_token: sessionToken
|
|
652
|
+
});
|
|
653
|
+
},
|
|
654
|
+
unlinkSmsOtp: async () => unlinkProvider("sms_otp"),
|
|
655
|
+
unlinkEmailOtp: async () => unlinkProvider("email_otp"),
|
|
656
|
+
unlinkApple: async () => unlinkProvider("apple"),
|
|
657
|
+
unlinkGoogle: async () => unlinkProvider("google"),
|
|
658
|
+
getCurrentIdentifiers: async () => {
|
|
659
|
+
const s = getState();
|
|
660
|
+
if (!s.identity.getSessionToken()) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
|
|
661
|
+
return (await s.http.get(P.authIdentifiers)).data.identifiers;
|
|
662
|
+
},
|
|
608
663
|
signOut: async (rotateAnonymousId = false) => {
|
|
609
664
|
const s = getState();
|
|
610
665
|
if (s.identity.getSessionToken()) try {
|