@memberstack/dom 2.0.1 → 2.0.2-beta.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 +356 -3
- package/lib/auth/index.d.mts +58 -4
- package/lib/auth/index.d.ts +58 -4
- package/lib/auth/index.js +5 -2
- package/lib/auth/index.mjs +4 -2
- package/lib/constants/endpoints.js +2 -1
- package/lib/constants/endpoints.mjs +1 -1
- package/lib/index.d.mts +1874 -61
- package/lib/index.d.ts +1874 -61
- package/lib/index.js +1544 -30624
- package/lib/index.mjs +1530 -30624
- package/lib/methods/dom/index.js +1 -0
- package/lib/methods/dom/main-dom.d.mts +1 -13
- package/lib/methods/dom/main-dom.d.ts +1 -13
- package/lib/methods/dom/main-dom.js +14545 -29552
- package/lib/methods/dom/main-dom.mjs +14544 -29552
- package/lib/methods/dom/methods.d.mts +88 -6
- package/lib/methods/dom/methods.d.ts +88 -6
- package/lib/methods/dom/methods.js +137 -30637
- package/lib/methods/dom/methods.mjs +135 -30639
- package/lib/methods/index.d.mts +111 -29
- package/lib/methods/index.d.ts +111 -29
- package/lib/methods/index.js +1020 -30615
- package/lib/methods/index.mjs +1019 -30615
- package/lib/methods/requests/index.d.mts +843 -23
- package/lib/methods/requests/index.d.ts +843 -23
- package/lib/methods/requests/index.js +863 -40
- package/lib/methods/requests/index.mjs +862 -40
- package/lib/methods/requests/requests.d.mts +9 -8
- package/lib/methods/requests/requests.d.ts +9 -8
- package/lib/methods/requests/requests.js +5 -3
- package/lib/methods/requests/requests.mjs +4 -3
- package/lib/models-BmZS-mc4.d.ts +193 -0
- package/lib/models-CTRKogoR.d.ts +487 -0
- package/lib/models-le7xaT4H.d.ts +193 -0
- package/lib/testing/index.d.mts +272 -0
- package/lib/testing/index.d.ts +272 -0
- package/lib/testing/index.js +313 -0
- package/lib/testing/index.mjs +284 -0
- package/lib/types/index.d.mts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/params.d.mts +632 -8
- package/lib/types/params.d.ts +632 -8
- package/lib/types/params.js +1 -0
- package/lib/types/payloads.d.mts +200 -1
- package/lib/types/payloads.d.ts +200 -1
- package/lib/types/payloads.js +1 -0
- package/lib/types/translations.d.mts +58 -0
- package/lib/types/translations.d.ts +58 -0
- package/lib/types/translations.js +1 -0
- package/lib/types/utils/payloads.d.mts +1 -3
- package/lib/types/utils/payloads.d.ts +1 -3
- package/lib/types/utils/payloads.js +1 -0
- package/lib/utils/cookies.d.mts +5 -5
- package/lib/utils/cookies.d.ts +5 -5
- package/lib/utils/cookies.js +14 -3
- package/lib/utils/cookies.mjs +13 -3
- package/lib/utils/defaultMessageBox.js +1 -0
- package/package.json +23 -12
- package/lib/index.global.js +0 -46364
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __defProps = Object.defineProperties;
|
|
@@ -76,7 +77,7 @@ var import_axios = __toESM(require("axios"));
|
|
|
76
77
|
|
|
77
78
|
// src/constants/endpoints.ts
|
|
78
79
|
var endpoints = {
|
|
79
|
-
API: "
|
|
80
|
+
API: "http://localhost:3005"
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
// src/utils/cookies.ts
|
|
@@ -94,10 +95,11 @@ function isLocalStorageAvailable() {
|
|
|
94
95
|
var localStorageAvailable = isLocalStorageAvailable();
|
|
95
96
|
var useCookies = false;
|
|
96
97
|
var setCookieOnRootDomain = false;
|
|
97
|
-
var apiDomain;
|
|
98
|
+
var apiDomain = "";
|
|
98
99
|
var extractDomainFromHostname = (hostname) => {
|
|
100
|
+
var _a, _b;
|
|
99
101
|
const hostnameParts = hostname.split(".");
|
|
100
|
-
const isCountryCodeTLD = hostnameParts.length >=
|
|
102
|
+
const isCountryCodeTLD = hostnameParts.length >= 4 && ((_b = (_a = hostnameParts[hostnameParts.length - 2]) == null ? void 0 : _a.length) != null ? _b : 0) <= 3;
|
|
101
103
|
if (isCountryCodeTLD) {
|
|
102
104
|
return hostnameParts.slice(-3).join(".");
|
|
103
105
|
} else {
|
|
@@ -219,9 +221,10 @@ var createRequestHandler = ({
|
|
|
219
221
|
}
|
|
220
222
|
return res == null ? void 0 : res.data;
|
|
221
223
|
} catch (e) {
|
|
222
|
-
|
|
224
|
+
const error = e;
|
|
225
|
+
if (!error.response)
|
|
223
226
|
throw e;
|
|
224
|
-
throw ((_g = (_f =
|
|
227
|
+
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
225
228
|
}
|
|
226
229
|
}),
|
|
227
230
|
sendRequestWithFetch: (data, options) => __async(void 0, null, function* () {
|
|
@@ -299,7 +302,8 @@ var createObservable = () => {
|
|
|
299
302
|
};
|
|
300
303
|
var observable = createObservable();
|
|
301
304
|
var getPersistedMember = () => {
|
|
302
|
-
|
|
305
|
+
const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
|
|
306
|
+
return stored ? JSON.parse(stored) : null;
|
|
303
307
|
};
|
|
304
308
|
var setPersistedMember = (member) => {
|
|
305
309
|
if (member) {
|
|
@@ -332,9 +336,12 @@ function getSessionDurationDays(unixTimestampMillis) {
|
|
|
332
336
|
const differenceMillis = unixTimestampMillis - now;
|
|
333
337
|
return Math.ceil(differenceMillis / (24 * 60 * 60 * 1e3));
|
|
334
338
|
}
|
|
335
|
-
var addHeaders = (options) =>
|
|
336
|
-
|
|
337
|
-
})
|
|
339
|
+
var addHeaders = (options) => {
|
|
340
|
+
const opts = options;
|
|
341
|
+
return __spreadValues({}, (opts == null ? void 0 : opts.token) && {
|
|
342
|
+
Authorization: `Bearer ${opts.token}`
|
|
343
|
+
});
|
|
344
|
+
};
|
|
338
345
|
var promiseResolve;
|
|
339
346
|
var promiseReject;
|
|
340
347
|
var receiveMessage = (event) => {
|
|
@@ -348,9 +355,9 @@ var receiveMessage = (event) => {
|
|
|
348
355
|
setMemberToken(data.data.tokens.accessToken, sessionDurationDays);
|
|
349
356
|
}
|
|
350
357
|
if (data == null ? void 0 : data.error) {
|
|
351
|
-
promiseReject(data.error);
|
|
358
|
+
promiseReject == null ? void 0 : promiseReject(data.error);
|
|
352
359
|
}
|
|
353
|
-
promiseResolve(data);
|
|
360
|
+
promiseResolve == null ? void 0 : promiseResolve(data);
|
|
354
361
|
};
|
|
355
362
|
var windowObjectReference = null;
|
|
356
363
|
var previousUrl = null;
|
|
@@ -368,9 +375,9 @@ var openSignInWindow = (url, name) => __async(void 0, null, function* () {
|
|
|
368
375
|
windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
369
376
|
} else if (previousUrl !== url) {
|
|
370
377
|
windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
371
|
-
windowObjectReference.focus();
|
|
378
|
+
windowObjectReference == null ? void 0 : windowObjectReference.focus();
|
|
372
379
|
} else {
|
|
373
|
-
windowObjectReference.focus();
|
|
380
|
+
windowObjectReference == null ? void 0 : windowObjectReference.focus();
|
|
374
381
|
}
|
|
375
382
|
window.addEventListener("message", (event) => receiveMessage(event), false);
|
|
376
383
|
previousUrl = url;
|
|
@@ -466,6 +473,21 @@ var initRequest = ({
|
|
|
466
473
|
});
|
|
467
474
|
});
|
|
468
475
|
},
|
|
476
|
+
/**
|
|
477
|
+
* Permanently deletes the current member's account.
|
|
478
|
+
* This action cannot be undone. The member will be logged out after deletion.
|
|
479
|
+
*
|
|
480
|
+
* @returns Promise resolving to deletion confirmation
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* // Confirm with user before calling
|
|
485
|
+
* if (confirm('Are you sure? This cannot be undone.')) {
|
|
486
|
+
* await memberstack.deleteMember();
|
|
487
|
+
* window.location.href = '/goodbye';
|
|
488
|
+
* }
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
469
491
|
deleteMember() {
|
|
470
492
|
return __async(this, null, function* () {
|
|
471
493
|
const data = yield sendRequest({
|
|
@@ -630,6 +652,22 @@ var initRequest = ({
|
|
|
630
652
|
});
|
|
631
653
|
});
|
|
632
654
|
},
|
|
655
|
+
/**
|
|
656
|
+
* Retrieves gated/secure content by its content ID.
|
|
657
|
+
* Use this to fetch content that requires specific plan access.
|
|
658
|
+
*
|
|
659
|
+
* @param params - Content parameters
|
|
660
|
+
* @param params.contentId - The ID of the secure content block to retrieve
|
|
661
|
+
* @returns Promise resolving to the secure content data
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* const { data: content } = await memberstack.getSecureContent({
|
|
666
|
+
* contentId: 'cnt_abc123'
|
|
667
|
+
* });
|
|
668
|
+
* document.getElementById('premium-content').innerHTML = content.html;
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
633
671
|
getSecureContent(params) {
|
|
634
672
|
return __async(this, null, function* () {
|
|
635
673
|
const data = yield sendRequest({
|
|
@@ -642,22 +680,52 @@ var initRequest = ({
|
|
|
642
680
|
return data;
|
|
643
681
|
});
|
|
644
682
|
},
|
|
683
|
+
/**
|
|
684
|
+
* Signs up a new member using an OAuth provider (e.g., Google, Facebook).
|
|
685
|
+
* Opens a popup window for the OAuth flow. On success, the member is created and logged in.
|
|
686
|
+
*
|
|
687
|
+
* @param params - Signup parameters
|
|
688
|
+
* @param params.provider - The OAuth provider to use ('google', 'facebook', etc.)
|
|
689
|
+
* @param params.customFields - Optional custom field values to set during signup
|
|
690
|
+
* @param params.plans - Optional array of plan objects to assign on signup
|
|
691
|
+
* @param params.inviteToken - Optional team invite token
|
|
692
|
+
* @returns Promise resolving to the authenticated member data
|
|
693
|
+
*
|
|
694
|
+
* @example Sign up with Google
|
|
695
|
+
* ```typescript
|
|
696
|
+
* const { data } = await memberstack.signupWithProvider({
|
|
697
|
+
* provider: 'google'
|
|
698
|
+
* });
|
|
699
|
+
* console.log('Signed up:', data.member.auth.email);
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @example Sign up with custom fields
|
|
703
|
+
* ```typescript
|
|
704
|
+
* await memberstack.signupWithProvider({
|
|
705
|
+
* provider: 'google',
|
|
706
|
+
* customFields: { role: 'developer' },
|
|
707
|
+
* plans: [{ planId: 'pln_free' }]
|
|
708
|
+
* });
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
645
711
|
signupWithProvider(params) {
|
|
646
712
|
return __async(this, null, function* () {
|
|
647
713
|
const customFields = encodeURIComponent(params.customFields ? JSON.stringify(params.customFields) : "{}");
|
|
648
714
|
const plans = encodeURIComponent(params.plans ? JSON.stringify(params.plans) : "[]");
|
|
649
715
|
const conversionData = getConversionData();
|
|
650
|
-
const queryParams = new URLSearchParams(__spreadProps(__spreadValues({
|
|
716
|
+
const queryParams = new URLSearchParams(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({
|
|
651
717
|
provider: params.provider,
|
|
652
718
|
customFields,
|
|
653
719
|
plans,
|
|
654
|
-
appId
|
|
720
|
+
appId: appId != null ? appId : ""
|
|
655
721
|
}, publicKey && {
|
|
656
722
|
publicKey
|
|
723
|
+
}), params.inviteToken && {
|
|
724
|
+
inviteToken: params.inviteToken
|
|
657
725
|
}), {
|
|
658
726
|
url: window.location.pathname,
|
|
659
|
-
origin: window.location.hostname
|
|
660
|
-
|
|
727
|
+
origin: window.location.hostname
|
|
728
|
+
}), conversionData.sessionId && { sessionId: conversionData.sessionId }), {
|
|
661
729
|
browser: conversionData.browser,
|
|
662
730
|
os: conversionData.os,
|
|
663
731
|
screenSize: conversionData.screenSize
|
|
@@ -665,12 +733,37 @@ var initRequest = ({
|
|
|
665
733
|
return openSignInWindow(`${domain}/auth-provider/signup?${queryParams}`, "signup");
|
|
666
734
|
});
|
|
667
735
|
},
|
|
736
|
+
/**
|
|
737
|
+
* Logs in an existing member using an OAuth provider (e.g., Google, Facebook).
|
|
738
|
+
* Opens a popup window for the OAuth flow. Member must already have an account linked to this provider.
|
|
739
|
+
*
|
|
740
|
+
* @param params - Login parameters
|
|
741
|
+
* @param params.provider - The OAuth provider to use ('google', 'facebook', etc.)
|
|
742
|
+
* @param params.allowSignup - If true, creates a new account if one doesn't exist (default: false)
|
|
743
|
+
* @returns Promise resolving to the authenticated member data
|
|
744
|
+
*
|
|
745
|
+
* @example Log in with Google
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const { data } = await memberstack.loginWithProvider({
|
|
748
|
+
* provider: 'google'
|
|
749
|
+
* });
|
|
750
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
751
|
+
* ```
|
|
752
|
+
*
|
|
753
|
+
* @example Allow signup if account doesn't exist
|
|
754
|
+
* ```typescript
|
|
755
|
+
* const { data } = await memberstack.loginWithProvider({
|
|
756
|
+
* provider: 'google',
|
|
757
|
+
* allowSignup: true
|
|
758
|
+
* });
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
668
761
|
loginWithProvider(params) {
|
|
669
762
|
return __async(this, null, function* () {
|
|
670
|
-
const allowSignup = encodeURIComponent(params.allowSignup === true ? true : false);
|
|
763
|
+
const allowSignup = encodeURIComponent(params.allowSignup === true ? "true" : "false");
|
|
671
764
|
const queryParams = new URLSearchParams(__spreadProps(__spreadValues({
|
|
672
765
|
provider: params.provider,
|
|
673
|
-
appId
|
|
766
|
+
appId: appId != null ? appId : ""
|
|
674
767
|
}, publicKey && {
|
|
675
768
|
publicKey
|
|
676
769
|
}), {
|
|
@@ -680,20 +773,54 @@ var initRequest = ({
|
|
|
680
773
|
return openSignInWindow(`${domain}/auth-provider/login?${queryParams}`, "login");
|
|
681
774
|
});
|
|
682
775
|
},
|
|
776
|
+
/**
|
|
777
|
+
* Connects an OAuth provider to the current member's account.
|
|
778
|
+
* Allows the member to use additional OAuth providers for login.
|
|
779
|
+
* Member must be logged in to use this method.
|
|
780
|
+
*
|
|
781
|
+
* @param params - Provider parameters
|
|
782
|
+
* @param params.provider - The OAuth provider to connect ('google', 'facebook', etc.)
|
|
783
|
+
* @returns Promise resolving to the connection result
|
|
784
|
+
*
|
|
785
|
+
* @example Connect Google to existing account
|
|
786
|
+
* ```typescript
|
|
787
|
+
* await memberstack.connectProvider({
|
|
788
|
+
* provider: 'google'
|
|
789
|
+
* });
|
|
790
|
+
* // Member can now log in with either email/password or Google
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
683
793
|
connectProvider(params) {
|
|
684
794
|
return __async(this, null, function* () {
|
|
685
|
-
const
|
|
795
|
+
const memberToken = getMemberToken();
|
|
796
|
+
const queryParams = new URLSearchParams(__spreadProps(__spreadValues(__spreadValues({
|
|
686
797
|
provider: params.provider,
|
|
687
|
-
appId
|
|
798
|
+
appId: appId != null ? appId : ""
|
|
688
799
|
}, publicKey && {
|
|
689
800
|
publicKey
|
|
690
|
-
}), {
|
|
691
|
-
member: getMemberToken(),
|
|
801
|
+
}), memberToken && { member: memberToken }), {
|
|
692
802
|
origin: window.location.hostname
|
|
693
803
|
}));
|
|
694
804
|
return openSignInWindow(`${domain}/auth-provider/connect?${queryParams}`, "connect");
|
|
695
805
|
});
|
|
696
806
|
},
|
|
807
|
+
/**
|
|
808
|
+
* Disconnects an OAuth provider from the current member's account.
|
|
809
|
+
* After disconnecting, the member can no longer use this provider to log in.
|
|
810
|
+
* Member must be logged in and have another login method available.
|
|
811
|
+
*
|
|
812
|
+
* @param params - Provider parameters
|
|
813
|
+
* @param params.provider - The OAuth provider to disconnect ('google', 'facebook', etc.)
|
|
814
|
+
* @returns Promise resolving to the disconnection result
|
|
815
|
+
*
|
|
816
|
+
* @example Disconnect Google from account
|
|
817
|
+
* ```typescript
|
|
818
|
+
* await memberstack.disconnectProvider({
|
|
819
|
+
* provider: 'google'
|
|
820
|
+
* });
|
|
821
|
+
* // Member must now use email/password or another connected provider
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
697
824
|
disconnectProvider(params) {
|
|
698
825
|
return __async(this, null, function* () {
|
|
699
826
|
return sendRequest({
|
|
@@ -712,8 +839,6 @@ var initRequest = ({
|
|
|
712
839
|
method: "POST" /* POST */,
|
|
713
840
|
url: `/app-member`,
|
|
714
841
|
data: {
|
|
715
|
-
email: params.email,
|
|
716
|
-
password: params.password,
|
|
717
842
|
data: {
|
|
718
843
|
// @ts-ignore
|
|
719
844
|
includeSSOText: window == null ? void 0 : window.ssoUI,
|
|
@@ -732,6 +857,19 @@ var initRequest = ({
|
|
|
732
857
|
return data;
|
|
733
858
|
});
|
|
734
859
|
},
|
|
860
|
+
/**
|
|
861
|
+
* Retrieves your Memberstack app configuration.
|
|
862
|
+
* Returns app settings including authentication options, branding, and enabled features.
|
|
863
|
+
*
|
|
864
|
+
* @returns Promise resolving to the app configuration
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* ```typescript
|
|
868
|
+
* const { data: app } = await memberstack.getApp();
|
|
869
|
+
* console.log('App name:', app.name);
|
|
870
|
+
* console.log('OAuth providers:', app.authProviders);
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
735
873
|
getApp() {
|
|
736
874
|
return __async(this, null, function* () {
|
|
737
875
|
const queryParams = new URLSearchParams({
|
|
@@ -744,6 +882,29 @@ var initRequest = ({
|
|
|
744
882
|
});
|
|
745
883
|
});
|
|
746
884
|
},
|
|
885
|
+
/**
|
|
886
|
+
* Authenticates a member using their email and password.
|
|
887
|
+
* On success, the member's session is automatically stored and they become the current user.
|
|
888
|
+
*
|
|
889
|
+
* @param params - Login credentials
|
|
890
|
+
* @param params.email - The member's email address
|
|
891
|
+
* @param params.password - The member's password
|
|
892
|
+
* @returns Promise resolving to the authenticated member data and tokens
|
|
893
|
+
* @throws When credentials are invalid or account doesn't exist
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* ```typescript
|
|
897
|
+
* try {
|
|
898
|
+
* const { data } = await memberstack.loginMemberEmailPassword({
|
|
899
|
+
* email: 'user@example.com',
|
|
900
|
+
* password: 'securePassword123'
|
|
901
|
+
* });
|
|
902
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
903
|
+
* } catch (error) {
|
|
904
|
+
* console.error('Login failed:', error.message);
|
|
905
|
+
* }
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
747
908
|
loginMemberEmailPassword(params, options) {
|
|
748
909
|
return __async(this, null, function* () {
|
|
749
910
|
const data = yield sendRequest({
|
|
@@ -761,6 +922,26 @@ var initRequest = ({
|
|
|
761
922
|
return data;
|
|
762
923
|
});
|
|
763
924
|
},
|
|
925
|
+
/**
|
|
926
|
+
* Sends a passwordless login code to an existing member's email.
|
|
927
|
+
* The member will receive a one-time code they can use to log in without a password.
|
|
928
|
+
*
|
|
929
|
+
* @param params - Email parameters
|
|
930
|
+
* @param params.email - The member's email address
|
|
931
|
+
* @returns Promise resolving to success confirmation
|
|
932
|
+
* @throws When the email is not associated with an existing member
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```typescript
|
|
936
|
+
* // Step 1: Send the code
|
|
937
|
+
* await memberstack.sendMemberLoginPasswordlessEmail({
|
|
938
|
+
* email: 'user@example.com'
|
|
939
|
+
* });
|
|
940
|
+
* // User receives email with code
|
|
941
|
+
*
|
|
942
|
+
* // Step 2: Complete login with the code (see loginMemberPasswordless)
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
764
945
|
sendMemberLoginPasswordlessEmail(params, options) {
|
|
765
946
|
return __async(this, null, function* () {
|
|
766
947
|
return yield sendRequest({
|
|
@@ -772,6 +953,24 @@ var initRequest = ({
|
|
|
772
953
|
});
|
|
773
954
|
});
|
|
774
955
|
},
|
|
956
|
+
/**
|
|
957
|
+
* Sends a passwordless signup code to a new member's email.
|
|
958
|
+
* Use this for registration flows where you don't want to collect passwords.
|
|
959
|
+
*
|
|
960
|
+
* @param params - Email parameters
|
|
961
|
+
* @param params.email - The new member's email address
|
|
962
|
+
* @returns Promise resolving to success confirmation
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* // Step 1: Send the signup code
|
|
967
|
+
* await memberstack.sendMemberSignupPasswordlessEmail({
|
|
968
|
+
* email: 'newuser@example.com'
|
|
969
|
+
* });
|
|
970
|
+
*
|
|
971
|
+
* // Step 2: Complete signup with the code (see signupMemberPasswordless)
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
775
974
|
sendMemberSignupPasswordlessEmail(params, options) {
|
|
776
975
|
return __async(this, null, function* () {
|
|
777
976
|
return yield sendRequest({
|
|
@@ -783,6 +982,26 @@ var initRequest = ({
|
|
|
783
982
|
});
|
|
784
983
|
});
|
|
785
984
|
},
|
|
985
|
+
/**
|
|
986
|
+
* Completes passwordless login using the code sent via email.
|
|
987
|
+
* On success, the member is logged in and their session is stored.
|
|
988
|
+
*
|
|
989
|
+
* @param params - Login credentials
|
|
990
|
+
* @param params.email - The member's email address
|
|
991
|
+
* @param params.passwordlessToken - The one-time code from the email
|
|
992
|
+
* @returns Promise resolving to the authenticated member data and tokens
|
|
993
|
+
* @throws When the code is invalid or expired
|
|
994
|
+
*
|
|
995
|
+
* @example Complete passwordless login flow
|
|
996
|
+
* ```typescript
|
|
997
|
+
* // After user enters the code from their email
|
|
998
|
+
* const { data } = await memberstack.loginMemberPasswordless({
|
|
999
|
+
* email: 'user@example.com',
|
|
1000
|
+
* passwordlessToken: '123456' // Code from email
|
|
1001
|
+
* });
|
|
1002
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
786
1005
|
loginMemberPasswordless(params, options) {
|
|
787
1006
|
return __async(this, null, function* () {
|
|
788
1007
|
const data = yield sendRequest({
|
|
@@ -800,6 +1019,23 @@ var initRequest = ({
|
|
|
800
1019
|
return data;
|
|
801
1020
|
});
|
|
802
1021
|
},
|
|
1022
|
+
/**
|
|
1023
|
+
* Retrieves details for a specific plan by ID.
|
|
1024
|
+
* Returns plan information including name, description, and pricing.
|
|
1025
|
+
*
|
|
1026
|
+
* @param params - Plan parameters
|
|
1027
|
+
* @param params.planId - The ID of the plan to retrieve
|
|
1028
|
+
* @returns Promise resolving to the plan details
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* const { data: plan } = await memberstack.getPlan({
|
|
1033
|
+
* planId: 'pln_pro123'
|
|
1034
|
+
* });
|
|
1035
|
+
* console.log('Plan:', plan.name);
|
|
1036
|
+
* console.log('Prices:', plan.prices);
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
803
1039
|
getPlan(params) {
|
|
804
1040
|
return __async(this, null, function* () {
|
|
805
1041
|
return sendRequest({
|
|
@@ -808,6 +1044,36 @@ var initRequest = ({
|
|
|
808
1044
|
});
|
|
809
1045
|
});
|
|
810
1046
|
},
|
|
1047
|
+
/**
|
|
1048
|
+
* Retrieves all plans configured for your Memberstack app.
|
|
1049
|
+
* Returns both free and paid plans with their pricing information.
|
|
1050
|
+
*
|
|
1051
|
+
* @returns Promise resolving to an array of plans
|
|
1052
|
+
*
|
|
1053
|
+
* @example List all plans
|
|
1054
|
+
* ```typescript
|
|
1055
|
+
* const { data: plans } = await memberstack.getPlans();
|
|
1056
|
+
*
|
|
1057
|
+
* plans.forEach(plan => {
|
|
1058
|
+
* console.log(plan.name, plan.id);
|
|
1059
|
+
* plan.prices?.forEach(price => {
|
|
1060
|
+
* console.log(` ${price.name}: ${price.amount} ${price.currency}`);
|
|
1061
|
+
* });
|
|
1062
|
+
* });
|
|
1063
|
+
* ```
|
|
1064
|
+
*
|
|
1065
|
+
* @example Build a pricing page
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* const { data: plans } = await memberstack.getPlans();
|
|
1068
|
+
*
|
|
1069
|
+
* const pricingHtml = plans.map(plan => `
|
|
1070
|
+
* <div class="plan">
|
|
1071
|
+
* <h3>${plan.name}</h3>
|
|
1072
|
+
* <p>${plan.description}</p>
|
|
1073
|
+
* </div>
|
|
1074
|
+
* `).join('');
|
|
1075
|
+
* ```
|
|
1076
|
+
*/
|
|
811
1077
|
getPlans() {
|
|
812
1078
|
return __async(this, null, function* () {
|
|
813
1079
|
const { data } = yield sendRequest({
|
|
@@ -819,6 +1085,23 @@ var initRequest = ({
|
|
|
819
1085
|
};
|
|
820
1086
|
});
|
|
821
1087
|
},
|
|
1088
|
+
/**
|
|
1089
|
+
* Retrieves URL restriction groups configured for your app.
|
|
1090
|
+
* These define which URLs require specific plans or authentication to access.
|
|
1091
|
+
*
|
|
1092
|
+
* @returns Promise resolving to an array of content access groups
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* const { data: groups } = await memberstack.getRestrictedUrlGroups();
|
|
1097
|
+
*
|
|
1098
|
+
* groups.forEach(group => {
|
|
1099
|
+
* console.log('Group:', group.name);
|
|
1100
|
+
* console.log('Required plans:', group.planIds);
|
|
1101
|
+
* console.log('URLs:', group.urls);
|
|
1102
|
+
* });
|
|
1103
|
+
* ```
|
|
1104
|
+
*/
|
|
822
1105
|
getRestrictedUrlGroups() {
|
|
823
1106
|
return __async(this, null, function* () {
|
|
824
1107
|
const { data } = yield sendRequest({
|
|
@@ -830,6 +1113,38 @@ var initRequest = ({
|
|
|
830
1113
|
};
|
|
831
1114
|
});
|
|
832
1115
|
},
|
|
1116
|
+
/**
|
|
1117
|
+
* Retrieves the currently authenticated member's data.
|
|
1118
|
+
* Returns `null` if no user is logged in.
|
|
1119
|
+
*
|
|
1120
|
+
* @param options - Optional configuration
|
|
1121
|
+
* @param options.useCache - If true, returns cached member data instead of fetching from server
|
|
1122
|
+
* @returns Promise resolving to the current member's data, or null if not authenticated
|
|
1123
|
+
*
|
|
1124
|
+
* @example Check if user is logged in
|
|
1125
|
+
* ```typescript
|
|
1126
|
+
* const { data: member } = await memberstack.getCurrentMember();
|
|
1127
|
+
*
|
|
1128
|
+
* if (member) {
|
|
1129
|
+
* console.log('Logged in as:', member.auth.email);
|
|
1130
|
+
* console.log('Plans:', member.planConnections);
|
|
1131
|
+
* } else {
|
|
1132
|
+
* console.log('Not logged in');
|
|
1133
|
+
* }
|
|
1134
|
+
* ```
|
|
1135
|
+
*
|
|
1136
|
+
* @example Access member properties
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* const { data: member } = await memberstack.getCurrentMember();
|
|
1139
|
+
*
|
|
1140
|
+
* if (member) {
|
|
1141
|
+
* const email = member.auth.email;
|
|
1142
|
+
* const isVerified = member.verified;
|
|
1143
|
+
* const customFields = member.customFields;
|
|
1144
|
+
* const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
|
|
1145
|
+
* }
|
|
1146
|
+
* ```
|
|
1147
|
+
*/
|
|
833
1148
|
getCurrentMember(options) {
|
|
834
1149
|
return __async(this, null, function* () {
|
|
835
1150
|
const memberToken = getMemberToken();
|
|
@@ -855,6 +1170,19 @@ var initRequest = ({
|
|
|
855
1170
|
}
|
|
856
1171
|
});
|
|
857
1172
|
},
|
|
1173
|
+
/**
|
|
1174
|
+
* Retrieves the current member's JSON data store.
|
|
1175
|
+
* This is a flexible key-value store for storing arbitrary member data.
|
|
1176
|
+
*
|
|
1177
|
+
* @returns Promise resolving to the member's JSON data object
|
|
1178
|
+
*
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```typescript
|
|
1181
|
+
* const { data: json } = await memberstack.getMemberJSON();
|
|
1182
|
+
* console.log('Preferences:', json.preferences);
|
|
1183
|
+
* console.log('Last visited:', json.lastVisitedPage);
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
858
1186
|
getMemberJSON(options) {
|
|
859
1187
|
return __async(this, null, function* () {
|
|
860
1188
|
return sendRequest({
|
|
@@ -864,6 +1192,35 @@ var initRequest = ({
|
|
|
864
1192
|
});
|
|
865
1193
|
});
|
|
866
1194
|
},
|
|
1195
|
+
/**
|
|
1196
|
+
* Updates the current member's JSON data store.
|
|
1197
|
+
* You can store any JSON-serializable data. Updates are merged with existing data.
|
|
1198
|
+
*
|
|
1199
|
+
* @param params - JSON data to store
|
|
1200
|
+
* @param params.json - Object containing the data to store
|
|
1201
|
+
* @returns Promise resolving to the updated JSON data
|
|
1202
|
+
*
|
|
1203
|
+
* @example Store user preferences
|
|
1204
|
+
* ```typescript
|
|
1205
|
+
* await memberstack.updateMemberJSON({
|
|
1206
|
+
* json: {
|
|
1207
|
+
* preferences: { theme: 'dark', notifications: true },
|
|
1208
|
+
* lastVisitedPage: '/dashboard',
|
|
1209
|
+
* onboardingComplete: true
|
|
1210
|
+
* }
|
|
1211
|
+
* });
|
|
1212
|
+
* ```
|
|
1213
|
+
*
|
|
1214
|
+
* @example Store app-specific data
|
|
1215
|
+
* ```typescript
|
|
1216
|
+
* await memberstack.updateMemberJSON({
|
|
1217
|
+
* json: {
|
|
1218
|
+
* savedItems: ['item1', 'item2'],
|
|
1219
|
+
* progress: { level: 5, score: 1200 }
|
|
1220
|
+
* }
|
|
1221
|
+
* });
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
867
1224
|
updateMemberJSON(params, options) {
|
|
868
1225
|
return __async(this, null, function* () {
|
|
869
1226
|
return sendRequest({
|
|
@@ -876,6 +1233,22 @@ var initRequest = ({
|
|
|
876
1233
|
});
|
|
877
1234
|
});
|
|
878
1235
|
},
|
|
1236
|
+
/**
|
|
1237
|
+
* Adds a free plan to the current member.
|
|
1238
|
+
* For paid plans, use `purchasePlansWithCheckout()` instead.
|
|
1239
|
+
*
|
|
1240
|
+
* @param params - Plan parameters
|
|
1241
|
+
* @param params.planId - The ID of the free plan to add
|
|
1242
|
+
* @returns Promise resolving to the updated member data with the new plan
|
|
1243
|
+
*
|
|
1244
|
+
* @example Add a free tier plan
|
|
1245
|
+
* ```typescript
|
|
1246
|
+
* const { data } = await memberstack.addPlan({
|
|
1247
|
+
* planId: 'pln_free_tier'
|
|
1248
|
+
* });
|
|
1249
|
+
* console.log('Plan added, redirect:', data.redirect);
|
|
1250
|
+
* ```
|
|
1251
|
+
*/
|
|
879
1252
|
addPlan(params, options) {
|
|
880
1253
|
return __async(this, null, function* () {
|
|
881
1254
|
return sendRequest({
|
|
@@ -888,11 +1261,54 @@ var initRequest = ({
|
|
|
888
1261
|
});
|
|
889
1262
|
});
|
|
890
1263
|
},
|
|
1264
|
+
/**
|
|
1265
|
+
* Initiates a Stripe checkout session for purchasing a paid plan.
|
|
1266
|
+
* By default, redirects the user to Stripe's hosted checkout page.
|
|
1267
|
+
*
|
|
1268
|
+
* @param params - Checkout configuration
|
|
1269
|
+
* @param params.priceId - The Memberstack price ID to purchase (e.g., 'prc_monthly_pro')
|
|
1270
|
+
* @param params.successUrl - URL to redirect to after successful payment (relative or absolute)
|
|
1271
|
+
* @param params.cancelUrl - URL to redirect to if user cancels checkout (relative or absolute)
|
|
1272
|
+
* @param params.couponId - Optional Stripe coupon ID to apply
|
|
1273
|
+
* @param params.autoRedirect - Set to `false` to get the checkout URL without redirecting
|
|
1274
|
+
* @returns Promise resolving to checkout data (includes URL if autoRedirect is false)
|
|
1275
|
+
*
|
|
1276
|
+
* @example Start checkout for a plan
|
|
1277
|
+
* ```typescript
|
|
1278
|
+
* await memberstack.purchasePlansWithCheckout({
|
|
1279
|
+
* priceId: 'prc_monthly_pro',
|
|
1280
|
+
* successUrl: '/welcome',
|
|
1281
|
+
* cancelUrl: '/pricing'
|
|
1282
|
+
* });
|
|
1283
|
+
* // User is redirected to Stripe checkout
|
|
1284
|
+
* ```
|
|
1285
|
+
*
|
|
1286
|
+
* @example Get checkout URL without redirecting
|
|
1287
|
+
* ```typescript
|
|
1288
|
+
* const { data } = await memberstack.purchasePlansWithCheckout({
|
|
1289
|
+
* priceId: 'prc_monthly_pro',
|
|
1290
|
+
* successUrl: '/welcome',
|
|
1291
|
+
* cancelUrl: '/pricing',
|
|
1292
|
+
* autoRedirect: false
|
|
1293
|
+
* });
|
|
1294
|
+
* console.log('Checkout URL:', data.url);
|
|
1295
|
+
* ```
|
|
1296
|
+
*
|
|
1297
|
+
* @example Apply a coupon
|
|
1298
|
+
* ```typescript
|
|
1299
|
+
* await memberstack.purchasePlansWithCheckout({
|
|
1300
|
+
* priceId: 'prc_annual_pro',
|
|
1301
|
+
* couponId: 'SAVE20',
|
|
1302
|
+
* successUrl: '/welcome',
|
|
1303
|
+
* cancelUrl: '/pricing'
|
|
1304
|
+
* });
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
891
1307
|
purchasePlansWithCheckout(params, options) {
|
|
892
1308
|
return __async(this, null, function* () {
|
|
893
|
-
function getRedirectURL(
|
|
1309
|
+
function getRedirectURL(URL2) {
|
|
894
1310
|
let redirectUrl = window.location.href;
|
|
895
|
-
const urlParam =
|
|
1311
|
+
const urlParam = URL2;
|
|
896
1312
|
if (urlParam) {
|
|
897
1313
|
if (urlParam.indexOf("http://") === 0 || urlParam.indexOf("https://") === 0) {
|
|
898
1314
|
redirectUrl = urlParam;
|
|
@@ -903,7 +1319,7 @@ var initRequest = ({
|
|
|
903
1319
|
return redirectUrl;
|
|
904
1320
|
}
|
|
905
1321
|
const success_url = params.successUrl ? getRedirectURL(params.successUrl) : void 0;
|
|
906
|
-
const cancel_url = getRedirectURL(params.cancelUrl);
|
|
1322
|
+
const cancel_url = params.cancelUrl ? getRedirectURL(params.cancelUrl) : window.location.href;
|
|
907
1323
|
const request = yield sendRequest({
|
|
908
1324
|
method: "POST" /* POST */,
|
|
909
1325
|
url: `/member/plans/create-checkout-session`,
|
|
@@ -925,14 +1341,42 @@ var initRequest = ({
|
|
|
925
1341
|
return request;
|
|
926
1342
|
}
|
|
927
1343
|
window.location.href = request.data.url;
|
|
1344
|
+
return request;
|
|
928
1345
|
});
|
|
929
1346
|
},
|
|
930
|
-
|
|
1347
|
+
/**
|
|
1348
|
+
* Opens the Stripe Customer Portal for the current member.
|
|
1349
|
+
* The portal allows members to manage their subscriptions, update payment methods, and view invoices.
|
|
1350
|
+
* By default, redirects the user to the Stripe-hosted portal.
|
|
1351
|
+
*
|
|
1352
|
+
* @param params - Portal configuration
|
|
1353
|
+
* @param params.returnUrl - URL to redirect to when member exits the portal (relative or absolute)
|
|
1354
|
+
* @param params.priceIds - Optional array of price IDs to show for plan switching
|
|
1355
|
+
* @param params.autoRedirect - Set to `false` to get the portal URL without redirecting
|
|
1356
|
+
* @returns Promise resolving to portal data (includes URL if autoRedirect is false)
|
|
1357
|
+
*
|
|
1358
|
+
* @example Open customer portal
|
|
1359
|
+
* ```typescript
|
|
1360
|
+
* await memberstack.launchStripeCustomerPortal({
|
|
1361
|
+
* returnUrl: '/account'
|
|
1362
|
+
* });
|
|
1363
|
+
* // User is redirected to Stripe Customer Portal
|
|
1364
|
+
* ```
|
|
1365
|
+
*
|
|
1366
|
+
* @example Get portal URL without redirecting
|
|
1367
|
+
* ```typescript
|
|
1368
|
+
* const { data } = await memberstack.launchStripeCustomerPortal({
|
|
1369
|
+
* returnUrl: '/account',
|
|
1370
|
+
* autoRedirect: false
|
|
1371
|
+
* });
|
|
1372
|
+
* console.log('Portal URL:', data.url);
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
931
1375
|
launchStripeCustomerPortal(params, options) {
|
|
932
1376
|
return __async(this, null, function* () {
|
|
933
|
-
function getRedirectURL(
|
|
1377
|
+
function getRedirectURL(URL2) {
|
|
934
1378
|
let redirectUrl = window.location.href;
|
|
935
|
-
const urlParam =
|
|
1379
|
+
const urlParam = URL2;
|
|
936
1380
|
if (urlParam) {
|
|
937
1381
|
if (urlParam.indexOf("http://") === 0 || urlParam.indexOf("https://") === 0) {
|
|
938
1382
|
redirectUrl = urlParam;
|
|
@@ -960,8 +1404,25 @@ var initRequest = ({
|
|
|
960
1404
|
return request;
|
|
961
1405
|
}
|
|
962
1406
|
window.location.href = request.data.url;
|
|
1407
|
+
return request;
|
|
963
1408
|
});
|
|
964
1409
|
},
|
|
1410
|
+
/**
|
|
1411
|
+
* Removes a plan from the current member.
|
|
1412
|
+
* For paid plans, this will cancel the subscription.
|
|
1413
|
+
*
|
|
1414
|
+
* @param params - Plan parameters
|
|
1415
|
+
* @param params.planId - The ID of the plan to remove
|
|
1416
|
+
* @returns Promise resolving to the updated member data
|
|
1417
|
+
*
|
|
1418
|
+
* @example Remove a plan
|
|
1419
|
+
* ```typescript
|
|
1420
|
+
* await memberstack.removePlan({
|
|
1421
|
+
* planId: 'pln_premium'
|
|
1422
|
+
* });
|
|
1423
|
+
* // Plan removed/subscription cancelled
|
|
1424
|
+
* ```
|
|
1425
|
+
*/
|
|
965
1426
|
removePlan(params, options) {
|
|
966
1427
|
return __async(this, null, function* () {
|
|
967
1428
|
return sendRequest({
|
|
@@ -974,6 +1435,35 @@ var initRequest = ({
|
|
|
974
1435
|
});
|
|
975
1436
|
});
|
|
976
1437
|
},
|
|
1438
|
+
/**
|
|
1439
|
+
* Updates the current member's custom fields.
|
|
1440
|
+
* Only updates the fields you specify; other fields remain unchanged.
|
|
1441
|
+
*
|
|
1442
|
+
* @param params - Update data
|
|
1443
|
+
* @param params.customFields - Object containing custom field key-value pairs to update
|
|
1444
|
+
* @returns Promise resolving to the updated member data
|
|
1445
|
+
*
|
|
1446
|
+
* @example Update custom fields
|
|
1447
|
+
* ```typescript
|
|
1448
|
+
* const { data: member } = await memberstack.updateMember({
|
|
1449
|
+
* customFields: {
|
|
1450
|
+
* firstName: 'Jane',
|
|
1451
|
+
* company: 'Acme Inc',
|
|
1452
|
+
* preferences: { theme: 'dark' }
|
|
1453
|
+
* }
|
|
1454
|
+
* });
|
|
1455
|
+
* console.log('Updated:', member.customFields);
|
|
1456
|
+
* ```
|
|
1457
|
+
*
|
|
1458
|
+
* @example Update a single field
|
|
1459
|
+
* ```typescript
|
|
1460
|
+
* await memberstack.updateMember({
|
|
1461
|
+
* customFields: {
|
|
1462
|
+
* lastLoginPage: window.location.pathname
|
|
1463
|
+
* }
|
|
1464
|
+
* });
|
|
1465
|
+
* ```
|
|
1466
|
+
*/
|
|
977
1467
|
updateMember(params, options) {
|
|
978
1468
|
return __async(this, null, function* () {
|
|
979
1469
|
return sendRequest({
|
|
@@ -984,6 +1474,33 @@ var initRequest = ({
|
|
|
984
1474
|
});
|
|
985
1475
|
});
|
|
986
1476
|
},
|
|
1477
|
+
/**
|
|
1478
|
+
* Updates the current member's authentication credentials (email and/or password).
|
|
1479
|
+
* Requires the current password to verify the member's identity.
|
|
1480
|
+
*
|
|
1481
|
+
* @param params - Auth update parameters
|
|
1482
|
+
* @param params.email - New email address (optional)
|
|
1483
|
+
* @param params.oldPassword - Current password (required for password changes)
|
|
1484
|
+
* @param params.newPassword - New password (optional)
|
|
1485
|
+
* @returns Promise resolving to the updated member data
|
|
1486
|
+
* @throws When the old password is incorrect
|
|
1487
|
+
*
|
|
1488
|
+
* @example Change email
|
|
1489
|
+
* ```typescript
|
|
1490
|
+
* await memberstack.updateMemberAuth({
|
|
1491
|
+
* email: 'newemail@example.com',
|
|
1492
|
+
* oldPassword: 'currentPassword'
|
|
1493
|
+
* });
|
|
1494
|
+
* ```
|
|
1495
|
+
*
|
|
1496
|
+
* @example Change password
|
|
1497
|
+
* ```typescript
|
|
1498
|
+
* await memberstack.updateMemberAuth({
|
|
1499
|
+
* oldPassword: 'currentPassword',
|
|
1500
|
+
* newPassword: 'newSecurePassword123'
|
|
1501
|
+
* });
|
|
1502
|
+
* ```
|
|
1503
|
+
*/
|
|
987
1504
|
updateMemberAuth(params, options) {
|
|
988
1505
|
return __async(this, null, function* () {
|
|
989
1506
|
return sendRequest({
|
|
@@ -994,6 +1511,23 @@ var initRequest = ({
|
|
|
994
1511
|
});
|
|
995
1512
|
});
|
|
996
1513
|
},
|
|
1514
|
+
/**
|
|
1515
|
+
* Sets a password for a member who signed up via passwordless or OAuth.
|
|
1516
|
+
* Use this when a member wants to add password-based login to their account.
|
|
1517
|
+
*
|
|
1518
|
+
* @param params - Password parameters
|
|
1519
|
+
* @param params.password - The password to set
|
|
1520
|
+
* @returns Promise resolving to the updated member data
|
|
1521
|
+
*
|
|
1522
|
+
* @example
|
|
1523
|
+
* ```typescript
|
|
1524
|
+
* // For members who signed up via Google OAuth or passwordless
|
|
1525
|
+
* await memberstack.setPassword({
|
|
1526
|
+
* password: 'newSecurePassword123'
|
|
1527
|
+
* });
|
|
1528
|
+
* // Member can now log in with email/password
|
|
1529
|
+
* ```
|
|
1530
|
+
*/
|
|
997
1531
|
setPassword(params, options) {
|
|
998
1532
|
return __async(this, null, function* () {
|
|
999
1533
|
return sendRequest({
|
|
@@ -1039,6 +1573,43 @@ var initRequest = ({
|
|
|
1039
1573
|
return data;
|
|
1040
1574
|
});
|
|
1041
1575
|
},
|
|
1576
|
+
/**
|
|
1577
|
+
* Creates a new member account with email and password.
|
|
1578
|
+
* On success, the member is automatically logged in and their session is stored.
|
|
1579
|
+
*
|
|
1580
|
+
* @param params - Signup details
|
|
1581
|
+
* @param params.email - The new member's email address
|
|
1582
|
+
* @param params.password - The new member's password (minimum 8 characters recommended)
|
|
1583
|
+
* @param params.customFields - Optional custom field values defined in your Memberstack dashboard
|
|
1584
|
+
* @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
|
|
1585
|
+
* @param params.metaData - Optional metadata to store with the member
|
|
1586
|
+
* @param params.inviteToken - Optional team invite token for team signups
|
|
1587
|
+
* @returns Promise resolving to the new member data and tokens
|
|
1588
|
+
* @throws When email is already in use or validation fails
|
|
1589
|
+
*
|
|
1590
|
+
* @example Basic signup
|
|
1591
|
+
* ```typescript
|
|
1592
|
+
* const { data } = await memberstack.signupMemberEmailPassword({
|
|
1593
|
+
* email: 'newuser@example.com',
|
|
1594
|
+
* password: 'securePassword123'
|
|
1595
|
+
* });
|
|
1596
|
+
* console.log('Welcome!', data.member.id);
|
|
1597
|
+
* ```
|
|
1598
|
+
*
|
|
1599
|
+
* @example Signup with custom fields and a free plan
|
|
1600
|
+
* ```typescript
|
|
1601
|
+
* const { data } = await memberstack.signupMemberEmailPassword({
|
|
1602
|
+
* email: 'newuser@example.com',
|
|
1603
|
+
* password: 'securePassword123',
|
|
1604
|
+
* customFields: {
|
|
1605
|
+
* firstName: 'Jane',
|
|
1606
|
+
* lastName: 'Doe',
|
|
1607
|
+
* company: 'Acme Inc'
|
|
1608
|
+
* },
|
|
1609
|
+
* plans: [{ planId: 'pln_free_tier' }]
|
|
1610
|
+
* });
|
|
1611
|
+
* ```
|
|
1612
|
+
*/
|
|
1042
1613
|
signupMemberEmailPassword(params, options) {
|
|
1043
1614
|
return __async(this, null, function* () {
|
|
1044
1615
|
var _a2, _b, _c;
|
|
@@ -1120,20 +1691,52 @@ var initRequest = ({
|
|
|
1120
1691
|
});
|
|
1121
1692
|
});
|
|
1122
1693
|
},
|
|
1694
|
+
/**
|
|
1695
|
+
* Uploads a new profile image for the current member.
|
|
1696
|
+
* Accepts a File object (from an input element) or a Blob.
|
|
1697
|
+
*
|
|
1698
|
+
* @param params - Image parameters
|
|
1699
|
+
* @param params.profileImage - The image file to upload
|
|
1700
|
+
* @returns Promise resolving to the new profile image URL
|
|
1701
|
+
*
|
|
1702
|
+
* @example Upload from file input
|
|
1703
|
+
* ```typescript
|
|
1704
|
+
* const input = document.querySelector('input[type="file"]');
|
|
1705
|
+
* const file = input.files[0];
|
|
1706
|
+
*
|
|
1707
|
+
* const { data } = await memberstack.updateMemberProfileImage({
|
|
1708
|
+
* profileImage: file
|
|
1709
|
+
* });
|
|
1710
|
+
* console.log('New image URL:', data.profileImage);
|
|
1711
|
+
* ```
|
|
1712
|
+
*/
|
|
1123
1713
|
updateMemberProfileImage(params) {
|
|
1124
1714
|
return __async(this, null, function* () {
|
|
1125
|
-
if (params.profileImage) {
|
|
1126
|
-
|
|
1127
|
-
formData.append("profileImage", params.profileImage);
|
|
1128
|
-
return sendRequest({
|
|
1129
|
-
method: "POST" /* POST */,
|
|
1130
|
-
url: `/member/profile-image`,
|
|
1131
|
-
data: formData,
|
|
1132
|
-
contentType: "multipart/form-data"
|
|
1133
|
-
});
|
|
1715
|
+
if (!params.profileImage) {
|
|
1716
|
+
throw new Error("profileImage is required");
|
|
1134
1717
|
}
|
|
1718
|
+
const formData = new FormData();
|
|
1719
|
+
formData.append("profileImage", params.profileImage);
|
|
1720
|
+
return sendRequest({
|
|
1721
|
+
method: "POST" /* POST */,
|
|
1722
|
+
url: `/member/profile-image`,
|
|
1723
|
+
data: formData,
|
|
1724
|
+
contentType: "multipart/form-data"
|
|
1725
|
+
});
|
|
1135
1726
|
});
|
|
1136
1727
|
},
|
|
1728
|
+
/**
|
|
1729
|
+
* Sends a verification email to the current member.
|
|
1730
|
+
* Use this when email verification is enabled in your Memberstack settings.
|
|
1731
|
+
*
|
|
1732
|
+
* @returns Promise resolving to success confirmation
|
|
1733
|
+
*
|
|
1734
|
+
* @example
|
|
1735
|
+
* ```typescript
|
|
1736
|
+
* await memberstack.sendMemberVerificationEmail();
|
|
1737
|
+
* // Show message: "Verification email sent! Check your inbox."
|
|
1738
|
+
* ```
|
|
1739
|
+
*/
|
|
1137
1740
|
sendMemberVerificationEmail() {
|
|
1138
1741
|
return __async(this, null, function* () {
|
|
1139
1742
|
return sendRequest({
|
|
@@ -1146,6 +1749,22 @@ var initRequest = ({
|
|
|
1146
1749
|
});
|
|
1147
1750
|
});
|
|
1148
1751
|
},
|
|
1752
|
+
/**
|
|
1753
|
+
* Sends a password reset email to a member.
|
|
1754
|
+
* The email contains a link with a token that can be used to reset their password.
|
|
1755
|
+
*
|
|
1756
|
+
* @param params - Email parameters
|
|
1757
|
+
* @param params.email - The member's email address
|
|
1758
|
+
* @returns Promise resolving to success confirmation
|
|
1759
|
+
*
|
|
1760
|
+
* @example
|
|
1761
|
+
* ```typescript
|
|
1762
|
+
* await memberstack.sendMemberResetPasswordEmail({
|
|
1763
|
+
* email: 'user@example.com'
|
|
1764
|
+
* });
|
|
1765
|
+
* // Show confirmation: "Check your email for reset instructions"
|
|
1766
|
+
* ```
|
|
1767
|
+
*/
|
|
1149
1768
|
sendMemberResetPasswordEmail(params) {
|
|
1150
1769
|
return __async(this, null, function* () {
|
|
1151
1770
|
return sendRequest({
|
|
@@ -1157,6 +1776,28 @@ var initRequest = ({
|
|
|
1157
1776
|
});
|
|
1158
1777
|
});
|
|
1159
1778
|
},
|
|
1779
|
+
/**
|
|
1780
|
+
* Completes the password reset process using the token from the reset email.
|
|
1781
|
+
* Typically called from a password reset page that receives the token via URL parameter.
|
|
1782
|
+
*
|
|
1783
|
+
* @param params - Reset parameters
|
|
1784
|
+
* @param params.token - The reset token from the email link
|
|
1785
|
+
* @param params.newPassword - The new password to set
|
|
1786
|
+
* @returns Promise resolving to success confirmation
|
|
1787
|
+
* @throws When the token is invalid or expired
|
|
1788
|
+
*
|
|
1789
|
+
* @example
|
|
1790
|
+
* ```typescript
|
|
1791
|
+
* // Get token from URL: /reset-password?token=abc123
|
|
1792
|
+
* const token = new URLSearchParams(window.location.search).get('token');
|
|
1793
|
+
*
|
|
1794
|
+
* await memberstack.resetMemberPassword({
|
|
1795
|
+
* token,
|
|
1796
|
+
* newPassword: 'newSecurePassword123'
|
|
1797
|
+
* });
|
|
1798
|
+
* // Password updated, redirect to login
|
|
1799
|
+
* ```
|
|
1800
|
+
*/
|
|
1160
1801
|
resetMemberPassword(params) {
|
|
1161
1802
|
return __async(this, null, function* () {
|
|
1162
1803
|
return sendRequest({
|
|
@@ -1169,6 +1810,27 @@ var initRequest = ({
|
|
|
1169
1810
|
});
|
|
1170
1811
|
});
|
|
1171
1812
|
},
|
|
1813
|
+
/**
|
|
1814
|
+
* Signs out the currently authenticated member.
|
|
1815
|
+
* Clears the local session and invalidates the server-side session.
|
|
1816
|
+
*
|
|
1817
|
+
* @returns Promise resolving to logout confirmation (may include a redirect URL)
|
|
1818
|
+
*
|
|
1819
|
+
* @example
|
|
1820
|
+
* ```typescript
|
|
1821
|
+
* await memberstack.logout();
|
|
1822
|
+
* // User is now logged out
|
|
1823
|
+
* window.location.href = '/login';
|
|
1824
|
+
* ```
|
|
1825
|
+
*
|
|
1826
|
+
* @example With redirect handling
|
|
1827
|
+
* ```typescript
|
|
1828
|
+
* const { data } = await memberstack.logout();
|
|
1829
|
+
* if (data.redirect) {
|
|
1830
|
+
* window.location.href = data.redirect;
|
|
1831
|
+
* }
|
|
1832
|
+
* ```
|
|
1833
|
+
*/
|
|
1172
1834
|
logout(options) {
|
|
1173
1835
|
return __async(this, null, function* () {
|
|
1174
1836
|
const data = yield sendRequest({
|
|
@@ -1181,6 +1843,20 @@ var initRequest = ({
|
|
|
1181
1843
|
});
|
|
1182
1844
|
},
|
|
1183
1845
|
// Data Tables Methods
|
|
1846
|
+
/**
|
|
1847
|
+
* Retrieves all data tables configured for your app.
|
|
1848
|
+
* Returns the list of tables and their schemas.
|
|
1849
|
+
*
|
|
1850
|
+
* @returns Promise resolving to an array of data tables
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```typescript
|
|
1854
|
+
* const { data: tables } = await memberstack.getDataTables();
|
|
1855
|
+
* tables.forEach(table => {
|
|
1856
|
+
* console.log('Table:', table.name, table.key);
|
|
1857
|
+
* });
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1184
1860
|
getDataTables(options) {
|
|
1185
1861
|
return __async(this, null, function* () {
|
|
1186
1862
|
return sendRequest({
|
|
@@ -1190,6 +1866,21 @@ var initRequest = ({
|
|
|
1190
1866
|
});
|
|
1191
1867
|
});
|
|
1192
1868
|
},
|
|
1869
|
+
/**
|
|
1870
|
+
* Retrieves a specific data table's schema and configuration.
|
|
1871
|
+
*
|
|
1872
|
+
* @param params - Table parameters
|
|
1873
|
+
* @param params.table - The table key/identifier
|
|
1874
|
+
* @returns Promise resolving to the table schema
|
|
1875
|
+
*
|
|
1876
|
+
* @example
|
|
1877
|
+
* ```typescript
|
|
1878
|
+
* const { data: table } = await memberstack.getDataTable({
|
|
1879
|
+
* table: 'posts'
|
|
1880
|
+
* });
|
|
1881
|
+
* console.log('Columns:', table.columns);
|
|
1882
|
+
* ```
|
|
1883
|
+
*/
|
|
1193
1884
|
getDataTable(params, options) {
|
|
1194
1885
|
return __async(this, null, function* () {
|
|
1195
1886
|
return sendRequest({
|
|
@@ -1200,6 +1891,30 @@ var initRequest = ({
|
|
|
1200
1891
|
});
|
|
1201
1892
|
});
|
|
1202
1893
|
},
|
|
1894
|
+
/**
|
|
1895
|
+
* Retrieves records from a data table with optional filtering and pagination.
|
|
1896
|
+
*
|
|
1897
|
+
* @param params - Query parameters
|
|
1898
|
+
* @param params.table - The table key/identifier
|
|
1899
|
+
* @param params.limit - Maximum number of records to return
|
|
1900
|
+
* @param params.after - Cursor for pagination (record ID to start after)
|
|
1901
|
+
* @param params.sortBy - Field to sort by
|
|
1902
|
+
* @param params.sortDirection - Sort direction ('asc' or 'desc')
|
|
1903
|
+
* @param params.createdAfter - Filter records created after this date
|
|
1904
|
+
* @param params.createdBefore - Filter records created before this date
|
|
1905
|
+
* @returns Promise resolving to records array with pagination info
|
|
1906
|
+
*
|
|
1907
|
+
* @example List records with pagination
|
|
1908
|
+
* ```typescript
|
|
1909
|
+
* const { data } = await memberstack.getDataRecords({
|
|
1910
|
+
* table: 'posts',
|
|
1911
|
+
* limit: 10,
|
|
1912
|
+
* sortBy: 'createdAt',
|
|
1913
|
+
* sortDirection: 'desc'
|
|
1914
|
+
* });
|
|
1915
|
+
* console.log('Records:', data.records);
|
|
1916
|
+
* ```
|
|
1917
|
+
*/
|
|
1203
1918
|
getDataRecords(params, options) {
|
|
1204
1919
|
return __async(this, null, function* () {
|
|
1205
1920
|
var _a2;
|
|
@@ -1242,6 +1957,28 @@ var initRequest = ({
|
|
|
1242
1957
|
return res;
|
|
1243
1958
|
});
|
|
1244
1959
|
},
|
|
1960
|
+
/**
|
|
1961
|
+
* Creates a new record in a data table.
|
|
1962
|
+
*
|
|
1963
|
+
* @param params - Record parameters
|
|
1964
|
+
* @param params.table - The table key/identifier
|
|
1965
|
+
* @param params.data - The record data as key-value pairs
|
|
1966
|
+
* @param params.memberId - Optional member ID to associate with the record
|
|
1967
|
+
* @returns Promise resolving to the created record
|
|
1968
|
+
*
|
|
1969
|
+
* @example Create a new post
|
|
1970
|
+
* ```typescript
|
|
1971
|
+
* const { data: record } = await memberstack.createDataRecord({
|
|
1972
|
+
* table: 'posts',
|
|
1973
|
+
* data: {
|
|
1974
|
+
* title: 'My First Post',
|
|
1975
|
+
* content: 'Hello world!',
|
|
1976
|
+
* published: true
|
|
1977
|
+
* }
|
|
1978
|
+
* });
|
|
1979
|
+
* console.log('Created record:', record.id);
|
|
1980
|
+
* ```
|
|
1981
|
+
*/
|
|
1245
1982
|
createDataRecord(params, options) {
|
|
1246
1983
|
return __async(this, null, function* () {
|
|
1247
1984
|
return sendRequest({
|
|
@@ -1255,6 +1992,23 @@ var initRequest = ({
|
|
|
1255
1992
|
});
|
|
1256
1993
|
});
|
|
1257
1994
|
},
|
|
1995
|
+
/**
|
|
1996
|
+
* Retrieves a single record by ID from a data table.
|
|
1997
|
+
*
|
|
1998
|
+
* @param params - Record parameters
|
|
1999
|
+
* @param params.table - The table key/identifier
|
|
2000
|
+
* @param params.recordId - The ID of the record to retrieve
|
|
2001
|
+
* @returns Promise resolving to the record data
|
|
2002
|
+
*
|
|
2003
|
+
* @example Get a specific post
|
|
2004
|
+
* ```typescript
|
|
2005
|
+
* const { data: record } = await memberstack.getDataRecord({
|
|
2006
|
+
* table: 'posts',
|
|
2007
|
+
* recordId: 'rec_abc123'
|
|
2008
|
+
* });
|
|
2009
|
+
* console.log('Post:', record.title);
|
|
2010
|
+
* ```
|
|
2011
|
+
*/
|
|
1258
2012
|
getDataRecord(params, options) {
|
|
1259
2013
|
return __async(this, null, function* () {
|
|
1260
2014
|
var _a2;
|
|
@@ -1277,6 +2031,25 @@ var initRequest = ({
|
|
|
1277
2031
|
return res;
|
|
1278
2032
|
});
|
|
1279
2033
|
},
|
|
2034
|
+
/**
|
|
2035
|
+
* Updates an existing record in a data table.
|
|
2036
|
+
*
|
|
2037
|
+
* @param params - Update parameters
|
|
2038
|
+
* @param params.recordId - The ID of the record to update
|
|
2039
|
+
* @param params.data - The fields to update as key-value pairs
|
|
2040
|
+
* @returns Promise resolving to the updated record
|
|
2041
|
+
*
|
|
2042
|
+
* @example Update a post
|
|
2043
|
+
* ```typescript
|
|
2044
|
+
* const { data: record } = await memberstack.updateDataRecord({
|
|
2045
|
+
* recordId: 'rec_abc123',
|
|
2046
|
+
* data: {
|
|
2047
|
+
* title: 'Updated Title',
|
|
2048
|
+
* published: false
|
|
2049
|
+
* }
|
|
2050
|
+
* });
|
|
2051
|
+
* ```
|
|
2052
|
+
*/
|
|
1280
2053
|
updateDataRecord(params, options) {
|
|
1281
2054
|
return __async(this, null, function* () {
|
|
1282
2055
|
return sendRequest({
|
|
@@ -1289,6 +2062,20 @@ var initRequest = ({
|
|
|
1289
2062
|
});
|
|
1290
2063
|
});
|
|
1291
2064
|
},
|
|
2065
|
+
/**
|
|
2066
|
+
* Deletes a record from a data table.
|
|
2067
|
+
*
|
|
2068
|
+
* @param params - Delete parameters
|
|
2069
|
+
* @param params.recordId - The ID of the record to delete
|
|
2070
|
+
* @returns Promise resolving to deletion confirmation
|
|
2071
|
+
*
|
|
2072
|
+
* @example Delete a post
|
|
2073
|
+
* ```typescript
|
|
2074
|
+
* await memberstack.deleteDataRecord({
|
|
2075
|
+
* recordId: 'rec_abc123'
|
|
2076
|
+
* });
|
|
2077
|
+
* ```
|
|
2078
|
+
*/
|
|
1292
2079
|
deleteDataRecord(params, options) {
|
|
1293
2080
|
return __async(this, null, function* () {
|
|
1294
2081
|
return sendRequest({
|
|
@@ -1298,6 +2085,42 @@ var initRequest = ({
|
|
|
1298
2085
|
});
|
|
1299
2086
|
});
|
|
1300
2087
|
},
|
|
2088
|
+
/**
|
|
2089
|
+
* Queries records from a data table with advanced filtering.
|
|
2090
|
+
* Provides more control than getDataRecords for complex queries.
|
|
2091
|
+
*
|
|
2092
|
+
* @param params - Query parameters
|
|
2093
|
+
* @param params.table - The table key/identifier
|
|
2094
|
+
* @param params.query - Query object with where, orderBy, take, skip options
|
|
2095
|
+
* @returns Promise resolving to matching records
|
|
2096
|
+
*
|
|
2097
|
+
* @example Query with filters
|
|
2098
|
+
* ```typescript
|
|
2099
|
+
* const { data } = await memberstack.queryDataRecords({
|
|
2100
|
+
* table: 'posts',
|
|
2101
|
+
* query: {
|
|
2102
|
+
* where: {
|
|
2103
|
+
* published: { equals: true },
|
|
2104
|
+
* category: { equals: 'tech' }
|
|
2105
|
+
* },
|
|
2106
|
+
* orderBy: { createdAt: 'desc' },
|
|
2107
|
+
* take: 10
|
|
2108
|
+
* }
|
|
2109
|
+
* });
|
|
2110
|
+
* ```
|
|
2111
|
+
*
|
|
2112
|
+
* @example Query with member filter
|
|
2113
|
+
* ```typescript
|
|
2114
|
+
* const { data } = await memberstack.queryDataRecords({
|
|
2115
|
+
* table: 'comments',
|
|
2116
|
+
* query: {
|
|
2117
|
+
* where: {
|
|
2118
|
+
* memberId: { equals: 'mem_xyz789' }
|
|
2119
|
+
* }
|
|
2120
|
+
* }
|
|
2121
|
+
* });
|
|
2122
|
+
* ```
|
|
2123
|
+
*/
|
|
1301
2124
|
queryDataRecords(params, options) {
|
|
1302
2125
|
return __async(this, null, function* () {
|
|
1303
2126
|
return sendRequest({
|