@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
|
@@ -43,7 +43,7 @@ import axios from "axios";
|
|
|
43
43
|
|
|
44
44
|
// src/constants/endpoints.ts
|
|
45
45
|
var endpoints = {
|
|
46
|
-
API: "
|
|
46
|
+
API: "http://localhost:3005"
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// src/utils/cookies.ts
|
|
@@ -61,10 +61,11 @@ function isLocalStorageAvailable() {
|
|
|
61
61
|
var localStorageAvailable = isLocalStorageAvailable();
|
|
62
62
|
var useCookies = false;
|
|
63
63
|
var setCookieOnRootDomain = false;
|
|
64
|
-
var apiDomain;
|
|
64
|
+
var apiDomain = "";
|
|
65
65
|
var extractDomainFromHostname = (hostname) => {
|
|
66
|
+
var _a, _b;
|
|
66
67
|
const hostnameParts = hostname.split(".");
|
|
67
|
-
const isCountryCodeTLD = hostnameParts.length >=
|
|
68
|
+
const isCountryCodeTLD = hostnameParts.length >= 4 && ((_b = (_a = hostnameParts[hostnameParts.length - 2]) == null ? void 0 : _a.length) != null ? _b : 0) <= 3;
|
|
68
69
|
if (isCountryCodeTLD) {
|
|
69
70
|
return hostnameParts.slice(-3).join(".");
|
|
70
71
|
} else {
|
|
@@ -186,9 +187,10 @@ var createRequestHandler = ({
|
|
|
186
187
|
}
|
|
187
188
|
return res == null ? void 0 : res.data;
|
|
188
189
|
} catch (e) {
|
|
189
|
-
|
|
190
|
+
const error = e;
|
|
191
|
+
if (!error.response)
|
|
190
192
|
throw e;
|
|
191
|
-
throw ((_g = (_f =
|
|
193
|
+
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
192
194
|
}
|
|
193
195
|
}),
|
|
194
196
|
sendRequestWithFetch: (data, options) => __async(void 0, null, function* () {
|
|
@@ -266,7 +268,8 @@ var createObservable = () => {
|
|
|
266
268
|
};
|
|
267
269
|
var observable = createObservable();
|
|
268
270
|
var getPersistedMember = () => {
|
|
269
|
-
|
|
271
|
+
const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
|
|
272
|
+
return stored ? JSON.parse(stored) : null;
|
|
270
273
|
};
|
|
271
274
|
var setPersistedMember = (member) => {
|
|
272
275
|
if (member) {
|
|
@@ -299,9 +302,12 @@ function getSessionDurationDays(unixTimestampMillis) {
|
|
|
299
302
|
const differenceMillis = unixTimestampMillis - now;
|
|
300
303
|
return Math.ceil(differenceMillis / (24 * 60 * 60 * 1e3));
|
|
301
304
|
}
|
|
302
|
-
var addHeaders = (options) =>
|
|
303
|
-
|
|
304
|
-
})
|
|
305
|
+
var addHeaders = (options) => {
|
|
306
|
+
const opts = options;
|
|
307
|
+
return __spreadValues({}, (opts == null ? void 0 : opts.token) && {
|
|
308
|
+
Authorization: `Bearer ${opts.token}`
|
|
309
|
+
});
|
|
310
|
+
};
|
|
305
311
|
var promiseResolve;
|
|
306
312
|
var promiseReject;
|
|
307
313
|
var receiveMessage = (event) => {
|
|
@@ -315,9 +321,9 @@ var receiveMessage = (event) => {
|
|
|
315
321
|
setMemberToken(data.data.tokens.accessToken, sessionDurationDays);
|
|
316
322
|
}
|
|
317
323
|
if (data == null ? void 0 : data.error) {
|
|
318
|
-
promiseReject(data.error);
|
|
324
|
+
promiseReject == null ? void 0 : promiseReject(data.error);
|
|
319
325
|
}
|
|
320
|
-
promiseResolve(data);
|
|
326
|
+
promiseResolve == null ? void 0 : promiseResolve(data);
|
|
321
327
|
};
|
|
322
328
|
var windowObjectReference = null;
|
|
323
329
|
var previousUrl = null;
|
|
@@ -335,9 +341,9 @@ var openSignInWindow = (url, name) => __async(void 0, null, function* () {
|
|
|
335
341
|
windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
336
342
|
} else if (previousUrl !== url) {
|
|
337
343
|
windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
338
|
-
windowObjectReference.focus();
|
|
344
|
+
windowObjectReference == null ? void 0 : windowObjectReference.focus();
|
|
339
345
|
} else {
|
|
340
|
-
windowObjectReference.focus();
|
|
346
|
+
windowObjectReference == null ? void 0 : windowObjectReference.focus();
|
|
341
347
|
}
|
|
342
348
|
window.addEventListener("message", (event) => receiveMessage(event), false);
|
|
343
349
|
previousUrl = url;
|
|
@@ -433,6 +439,21 @@ var initRequest = ({
|
|
|
433
439
|
});
|
|
434
440
|
});
|
|
435
441
|
},
|
|
442
|
+
/**
|
|
443
|
+
* Permanently deletes the current member's account.
|
|
444
|
+
* This action cannot be undone. The member will be logged out after deletion.
|
|
445
|
+
*
|
|
446
|
+
* @returns Promise resolving to deletion confirmation
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* // Confirm with user before calling
|
|
451
|
+
* if (confirm('Are you sure? This cannot be undone.')) {
|
|
452
|
+
* await memberstack.deleteMember();
|
|
453
|
+
* window.location.href = '/goodbye';
|
|
454
|
+
* }
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
436
457
|
deleteMember() {
|
|
437
458
|
return __async(this, null, function* () {
|
|
438
459
|
const data = yield sendRequest({
|
|
@@ -597,6 +618,22 @@ var initRequest = ({
|
|
|
597
618
|
});
|
|
598
619
|
});
|
|
599
620
|
},
|
|
621
|
+
/**
|
|
622
|
+
* Retrieves gated/secure content by its content ID.
|
|
623
|
+
* Use this to fetch content that requires specific plan access.
|
|
624
|
+
*
|
|
625
|
+
* @param params - Content parameters
|
|
626
|
+
* @param params.contentId - The ID of the secure content block to retrieve
|
|
627
|
+
* @returns Promise resolving to the secure content data
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```typescript
|
|
631
|
+
* const { data: content } = await memberstack.getSecureContent({
|
|
632
|
+
* contentId: 'cnt_abc123'
|
|
633
|
+
* });
|
|
634
|
+
* document.getElementById('premium-content').innerHTML = content.html;
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
600
637
|
getSecureContent(params) {
|
|
601
638
|
return __async(this, null, function* () {
|
|
602
639
|
const data = yield sendRequest({
|
|
@@ -609,22 +646,52 @@ var initRequest = ({
|
|
|
609
646
|
return data;
|
|
610
647
|
});
|
|
611
648
|
},
|
|
649
|
+
/**
|
|
650
|
+
* Signs up a new member using an OAuth provider (e.g., Google, Facebook).
|
|
651
|
+
* Opens a popup window for the OAuth flow. On success, the member is created and logged in.
|
|
652
|
+
*
|
|
653
|
+
* @param params - Signup parameters
|
|
654
|
+
* @param params.provider - The OAuth provider to use ('google', 'facebook', etc.)
|
|
655
|
+
* @param params.customFields - Optional custom field values to set during signup
|
|
656
|
+
* @param params.plans - Optional array of plan objects to assign on signup
|
|
657
|
+
* @param params.inviteToken - Optional team invite token
|
|
658
|
+
* @returns Promise resolving to the authenticated member data
|
|
659
|
+
*
|
|
660
|
+
* @example Sign up with Google
|
|
661
|
+
* ```typescript
|
|
662
|
+
* const { data } = await memberstack.signupWithProvider({
|
|
663
|
+
* provider: 'google'
|
|
664
|
+
* });
|
|
665
|
+
* console.log('Signed up:', data.member.auth.email);
|
|
666
|
+
* ```
|
|
667
|
+
*
|
|
668
|
+
* @example Sign up with custom fields
|
|
669
|
+
* ```typescript
|
|
670
|
+
* await memberstack.signupWithProvider({
|
|
671
|
+
* provider: 'google',
|
|
672
|
+
* customFields: { role: 'developer' },
|
|
673
|
+
* plans: [{ planId: 'pln_free' }]
|
|
674
|
+
* });
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
612
677
|
signupWithProvider(params) {
|
|
613
678
|
return __async(this, null, function* () {
|
|
614
679
|
const customFields = encodeURIComponent(params.customFields ? JSON.stringify(params.customFields) : "{}");
|
|
615
680
|
const plans = encodeURIComponent(params.plans ? JSON.stringify(params.plans) : "[]");
|
|
616
681
|
const conversionData = getConversionData();
|
|
617
|
-
const queryParams = new URLSearchParams(__spreadProps(__spreadValues({
|
|
682
|
+
const queryParams = new URLSearchParams(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({
|
|
618
683
|
provider: params.provider,
|
|
619
684
|
customFields,
|
|
620
685
|
plans,
|
|
621
|
-
appId
|
|
686
|
+
appId: appId != null ? appId : ""
|
|
622
687
|
}, publicKey && {
|
|
623
688
|
publicKey
|
|
689
|
+
}), params.inviteToken && {
|
|
690
|
+
inviteToken: params.inviteToken
|
|
624
691
|
}), {
|
|
625
692
|
url: window.location.pathname,
|
|
626
|
-
origin: window.location.hostname
|
|
627
|
-
|
|
693
|
+
origin: window.location.hostname
|
|
694
|
+
}), conversionData.sessionId && { sessionId: conversionData.sessionId }), {
|
|
628
695
|
browser: conversionData.browser,
|
|
629
696
|
os: conversionData.os,
|
|
630
697
|
screenSize: conversionData.screenSize
|
|
@@ -632,12 +699,37 @@ var initRequest = ({
|
|
|
632
699
|
return openSignInWindow(`${domain}/auth-provider/signup?${queryParams}`, "signup");
|
|
633
700
|
});
|
|
634
701
|
},
|
|
702
|
+
/**
|
|
703
|
+
* Logs in an existing member using an OAuth provider (e.g., Google, Facebook).
|
|
704
|
+
* Opens a popup window for the OAuth flow. Member must already have an account linked to this provider.
|
|
705
|
+
*
|
|
706
|
+
* @param params - Login parameters
|
|
707
|
+
* @param params.provider - The OAuth provider to use ('google', 'facebook', etc.)
|
|
708
|
+
* @param params.allowSignup - If true, creates a new account if one doesn't exist (default: false)
|
|
709
|
+
* @returns Promise resolving to the authenticated member data
|
|
710
|
+
*
|
|
711
|
+
* @example Log in with Google
|
|
712
|
+
* ```typescript
|
|
713
|
+
* const { data } = await memberstack.loginWithProvider({
|
|
714
|
+
* provider: 'google'
|
|
715
|
+
* });
|
|
716
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* @example Allow signup if account doesn't exist
|
|
720
|
+
* ```typescript
|
|
721
|
+
* const { data } = await memberstack.loginWithProvider({
|
|
722
|
+
* provider: 'google',
|
|
723
|
+
* allowSignup: true
|
|
724
|
+
* });
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
635
727
|
loginWithProvider(params) {
|
|
636
728
|
return __async(this, null, function* () {
|
|
637
|
-
const allowSignup = encodeURIComponent(params.allowSignup === true ? true : false);
|
|
729
|
+
const allowSignup = encodeURIComponent(params.allowSignup === true ? "true" : "false");
|
|
638
730
|
const queryParams = new URLSearchParams(__spreadProps(__spreadValues({
|
|
639
731
|
provider: params.provider,
|
|
640
|
-
appId
|
|
732
|
+
appId: appId != null ? appId : ""
|
|
641
733
|
}, publicKey && {
|
|
642
734
|
publicKey
|
|
643
735
|
}), {
|
|
@@ -647,20 +739,54 @@ var initRequest = ({
|
|
|
647
739
|
return openSignInWindow(`${domain}/auth-provider/login?${queryParams}`, "login");
|
|
648
740
|
});
|
|
649
741
|
},
|
|
742
|
+
/**
|
|
743
|
+
* Connects an OAuth provider to the current member's account.
|
|
744
|
+
* Allows the member to use additional OAuth providers for login.
|
|
745
|
+
* Member must be logged in to use this method.
|
|
746
|
+
*
|
|
747
|
+
* @param params - Provider parameters
|
|
748
|
+
* @param params.provider - The OAuth provider to connect ('google', 'facebook', etc.)
|
|
749
|
+
* @returns Promise resolving to the connection result
|
|
750
|
+
*
|
|
751
|
+
* @example Connect Google to existing account
|
|
752
|
+
* ```typescript
|
|
753
|
+
* await memberstack.connectProvider({
|
|
754
|
+
* provider: 'google'
|
|
755
|
+
* });
|
|
756
|
+
* // Member can now log in with either email/password or Google
|
|
757
|
+
* ```
|
|
758
|
+
*/
|
|
650
759
|
connectProvider(params) {
|
|
651
760
|
return __async(this, null, function* () {
|
|
652
|
-
const
|
|
761
|
+
const memberToken = getMemberToken();
|
|
762
|
+
const queryParams = new URLSearchParams(__spreadProps(__spreadValues(__spreadValues({
|
|
653
763
|
provider: params.provider,
|
|
654
|
-
appId
|
|
764
|
+
appId: appId != null ? appId : ""
|
|
655
765
|
}, publicKey && {
|
|
656
766
|
publicKey
|
|
657
|
-
}), {
|
|
658
|
-
member: getMemberToken(),
|
|
767
|
+
}), memberToken && { member: memberToken }), {
|
|
659
768
|
origin: window.location.hostname
|
|
660
769
|
}));
|
|
661
770
|
return openSignInWindow(`${domain}/auth-provider/connect?${queryParams}`, "connect");
|
|
662
771
|
});
|
|
663
772
|
},
|
|
773
|
+
/**
|
|
774
|
+
* Disconnects an OAuth provider from the current member's account.
|
|
775
|
+
* After disconnecting, the member can no longer use this provider to log in.
|
|
776
|
+
* Member must be logged in and have another login method available.
|
|
777
|
+
*
|
|
778
|
+
* @param params - Provider parameters
|
|
779
|
+
* @param params.provider - The OAuth provider to disconnect ('google', 'facebook', etc.)
|
|
780
|
+
* @returns Promise resolving to the disconnection result
|
|
781
|
+
*
|
|
782
|
+
* @example Disconnect Google from account
|
|
783
|
+
* ```typescript
|
|
784
|
+
* await memberstack.disconnectProvider({
|
|
785
|
+
* provider: 'google'
|
|
786
|
+
* });
|
|
787
|
+
* // Member must now use email/password or another connected provider
|
|
788
|
+
* ```
|
|
789
|
+
*/
|
|
664
790
|
disconnectProvider(params) {
|
|
665
791
|
return __async(this, null, function* () {
|
|
666
792
|
return sendRequest({
|
|
@@ -679,8 +805,6 @@ var initRequest = ({
|
|
|
679
805
|
method: "POST" /* POST */,
|
|
680
806
|
url: `/app-member`,
|
|
681
807
|
data: {
|
|
682
|
-
email: params.email,
|
|
683
|
-
password: params.password,
|
|
684
808
|
data: {
|
|
685
809
|
// @ts-ignore
|
|
686
810
|
includeSSOText: window == null ? void 0 : window.ssoUI,
|
|
@@ -699,6 +823,19 @@ var initRequest = ({
|
|
|
699
823
|
return data;
|
|
700
824
|
});
|
|
701
825
|
},
|
|
826
|
+
/**
|
|
827
|
+
* Retrieves your Memberstack app configuration.
|
|
828
|
+
* Returns app settings including authentication options, branding, and enabled features.
|
|
829
|
+
*
|
|
830
|
+
* @returns Promise resolving to the app configuration
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* const { data: app } = await memberstack.getApp();
|
|
835
|
+
* console.log('App name:', app.name);
|
|
836
|
+
* console.log('OAuth providers:', app.authProviders);
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
702
839
|
getApp() {
|
|
703
840
|
return __async(this, null, function* () {
|
|
704
841
|
const queryParams = new URLSearchParams({
|
|
@@ -711,6 +848,29 @@ var initRequest = ({
|
|
|
711
848
|
});
|
|
712
849
|
});
|
|
713
850
|
},
|
|
851
|
+
/**
|
|
852
|
+
* Authenticates a member using their email and password.
|
|
853
|
+
* On success, the member's session is automatically stored and they become the current user.
|
|
854
|
+
*
|
|
855
|
+
* @param params - Login credentials
|
|
856
|
+
* @param params.email - The member's email address
|
|
857
|
+
* @param params.password - The member's password
|
|
858
|
+
* @returns Promise resolving to the authenticated member data and tokens
|
|
859
|
+
* @throws When credentials are invalid or account doesn't exist
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
* ```typescript
|
|
863
|
+
* try {
|
|
864
|
+
* const { data } = await memberstack.loginMemberEmailPassword({
|
|
865
|
+
* email: 'user@example.com',
|
|
866
|
+
* password: 'securePassword123'
|
|
867
|
+
* });
|
|
868
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
869
|
+
* } catch (error) {
|
|
870
|
+
* console.error('Login failed:', error.message);
|
|
871
|
+
* }
|
|
872
|
+
* ```
|
|
873
|
+
*/
|
|
714
874
|
loginMemberEmailPassword(params, options) {
|
|
715
875
|
return __async(this, null, function* () {
|
|
716
876
|
const data = yield sendRequest({
|
|
@@ -728,6 +888,26 @@ var initRequest = ({
|
|
|
728
888
|
return data;
|
|
729
889
|
});
|
|
730
890
|
},
|
|
891
|
+
/**
|
|
892
|
+
* Sends a passwordless login code to an existing member's email.
|
|
893
|
+
* The member will receive a one-time code they can use to log in without a password.
|
|
894
|
+
*
|
|
895
|
+
* @param params - Email parameters
|
|
896
|
+
* @param params.email - The member's email address
|
|
897
|
+
* @returns Promise resolving to success confirmation
|
|
898
|
+
* @throws When the email is not associated with an existing member
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* // Step 1: Send the code
|
|
903
|
+
* await memberstack.sendMemberLoginPasswordlessEmail({
|
|
904
|
+
* email: 'user@example.com'
|
|
905
|
+
* });
|
|
906
|
+
* // User receives email with code
|
|
907
|
+
*
|
|
908
|
+
* // Step 2: Complete login with the code (see loginMemberPasswordless)
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
731
911
|
sendMemberLoginPasswordlessEmail(params, options) {
|
|
732
912
|
return __async(this, null, function* () {
|
|
733
913
|
return yield sendRequest({
|
|
@@ -739,6 +919,24 @@ var initRequest = ({
|
|
|
739
919
|
});
|
|
740
920
|
});
|
|
741
921
|
},
|
|
922
|
+
/**
|
|
923
|
+
* Sends a passwordless signup code to a new member's email.
|
|
924
|
+
* Use this for registration flows where you don't want to collect passwords.
|
|
925
|
+
*
|
|
926
|
+
* @param params - Email parameters
|
|
927
|
+
* @param params.email - The new member's email address
|
|
928
|
+
* @returns Promise resolving to success confirmation
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* // Step 1: Send the signup code
|
|
933
|
+
* await memberstack.sendMemberSignupPasswordlessEmail({
|
|
934
|
+
* email: 'newuser@example.com'
|
|
935
|
+
* });
|
|
936
|
+
*
|
|
937
|
+
* // Step 2: Complete signup with the code (see signupMemberPasswordless)
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
742
940
|
sendMemberSignupPasswordlessEmail(params, options) {
|
|
743
941
|
return __async(this, null, function* () {
|
|
744
942
|
return yield sendRequest({
|
|
@@ -750,6 +948,26 @@ var initRequest = ({
|
|
|
750
948
|
});
|
|
751
949
|
});
|
|
752
950
|
},
|
|
951
|
+
/**
|
|
952
|
+
* Completes passwordless login using the code sent via email.
|
|
953
|
+
* On success, the member is logged in and their session is stored.
|
|
954
|
+
*
|
|
955
|
+
* @param params - Login credentials
|
|
956
|
+
* @param params.email - The member's email address
|
|
957
|
+
* @param params.passwordlessToken - The one-time code from the email
|
|
958
|
+
* @returns Promise resolving to the authenticated member data and tokens
|
|
959
|
+
* @throws When the code is invalid or expired
|
|
960
|
+
*
|
|
961
|
+
* @example Complete passwordless login flow
|
|
962
|
+
* ```typescript
|
|
963
|
+
* // After user enters the code from their email
|
|
964
|
+
* const { data } = await memberstack.loginMemberPasswordless({
|
|
965
|
+
* email: 'user@example.com',
|
|
966
|
+
* passwordlessToken: '123456' // Code from email
|
|
967
|
+
* });
|
|
968
|
+
* console.log('Logged in:', data.member.auth.email);
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
753
971
|
loginMemberPasswordless(params, options) {
|
|
754
972
|
return __async(this, null, function* () {
|
|
755
973
|
const data = yield sendRequest({
|
|
@@ -767,6 +985,23 @@ var initRequest = ({
|
|
|
767
985
|
return data;
|
|
768
986
|
});
|
|
769
987
|
},
|
|
988
|
+
/**
|
|
989
|
+
* Retrieves details for a specific plan by ID.
|
|
990
|
+
* Returns plan information including name, description, and pricing.
|
|
991
|
+
*
|
|
992
|
+
* @param params - Plan parameters
|
|
993
|
+
* @param params.planId - The ID of the plan to retrieve
|
|
994
|
+
* @returns Promise resolving to the plan details
|
|
995
|
+
*
|
|
996
|
+
* @example
|
|
997
|
+
* ```typescript
|
|
998
|
+
* const { data: plan } = await memberstack.getPlan({
|
|
999
|
+
* planId: 'pln_pro123'
|
|
1000
|
+
* });
|
|
1001
|
+
* console.log('Plan:', plan.name);
|
|
1002
|
+
* console.log('Prices:', plan.prices);
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
770
1005
|
getPlan(params) {
|
|
771
1006
|
return __async(this, null, function* () {
|
|
772
1007
|
return sendRequest({
|
|
@@ -775,6 +1010,36 @@ var initRequest = ({
|
|
|
775
1010
|
});
|
|
776
1011
|
});
|
|
777
1012
|
},
|
|
1013
|
+
/**
|
|
1014
|
+
* Retrieves all plans configured for your Memberstack app.
|
|
1015
|
+
* Returns both free and paid plans with their pricing information.
|
|
1016
|
+
*
|
|
1017
|
+
* @returns Promise resolving to an array of plans
|
|
1018
|
+
*
|
|
1019
|
+
* @example List all plans
|
|
1020
|
+
* ```typescript
|
|
1021
|
+
* const { data: plans } = await memberstack.getPlans();
|
|
1022
|
+
*
|
|
1023
|
+
* plans.forEach(plan => {
|
|
1024
|
+
* console.log(plan.name, plan.id);
|
|
1025
|
+
* plan.prices?.forEach(price => {
|
|
1026
|
+
* console.log(` ${price.name}: ${price.amount} ${price.currency}`);
|
|
1027
|
+
* });
|
|
1028
|
+
* });
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* @example Build a pricing page
|
|
1032
|
+
* ```typescript
|
|
1033
|
+
* const { data: plans } = await memberstack.getPlans();
|
|
1034
|
+
*
|
|
1035
|
+
* const pricingHtml = plans.map(plan => `
|
|
1036
|
+
* <div class="plan">
|
|
1037
|
+
* <h3>${plan.name}</h3>
|
|
1038
|
+
* <p>${plan.description}</p>
|
|
1039
|
+
* </div>
|
|
1040
|
+
* `).join('');
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
778
1043
|
getPlans() {
|
|
779
1044
|
return __async(this, null, function* () {
|
|
780
1045
|
const { data } = yield sendRequest({
|
|
@@ -786,6 +1051,23 @@ var initRequest = ({
|
|
|
786
1051
|
};
|
|
787
1052
|
});
|
|
788
1053
|
},
|
|
1054
|
+
/**
|
|
1055
|
+
* Retrieves URL restriction groups configured for your app.
|
|
1056
|
+
* These define which URLs require specific plans or authentication to access.
|
|
1057
|
+
*
|
|
1058
|
+
* @returns Promise resolving to an array of content access groups
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* const { data: groups } = await memberstack.getRestrictedUrlGroups();
|
|
1063
|
+
*
|
|
1064
|
+
* groups.forEach(group => {
|
|
1065
|
+
* console.log('Group:', group.name);
|
|
1066
|
+
* console.log('Required plans:', group.planIds);
|
|
1067
|
+
* console.log('URLs:', group.urls);
|
|
1068
|
+
* });
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
789
1071
|
getRestrictedUrlGroups() {
|
|
790
1072
|
return __async(this, null, function* () {
|
|
791
1073
|
const { data } = yield sendRequest({
|
|
@@ -797,6 +1079,38 @@ var initRequest = ({
|
|
|
797
1079
|
};
|
|
798
1080
|
});
|
|
799
1081
|
},
|
|
1082
|
+
/**
|
|
1083
|
+
* Retrieves the currently authenticated member's data.
|
|
1084
|
+
* Returns `null` if no user is logged in.
|
|
1085
|
+
*
|
|
1086
|
+
* @param options - Optional configuration
|
|
1087
|
+
* @param options.useCache - If true, returns cached member data instead of fetching from server
|
|
1088
|
+
* @returns Promise resolving to the current member's data, or null if not authenticated
|
|
1089
|
+
*
|
|
1090
|
+
* @example Check if user is logged in
|
|
1091
|
+
* ```typescript
|
|
1092
|
+
* const { data: member } = await memberstack.getCurrentMember();
|
|
1093
|
+
*
|
|
1094
|
+
* if (member) {
|
|
1095
|
+
* console.log('Logged in as:', member.auth.email);
|
|
1096
|
+
* console.log('Plans:', member.planConnections);
|
|
1097
|
+
* } else {
|
|
1098
|
+
* console.log('Not logged in');
|
|
1099
|
+
* }
|
|
1100
|
+
* ```
|
|
1101
|
+
*
|
|
1102
|
+
* @example Access member properties
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* const { data: member } = await memberstack.getCurrentMember();
|
|
1105
|
+
*
|
|
1106
|
+
* if (member) {
|
|
1107
|
+
* const email = member.auth.email;
|
|
1108
|
+
* const isVerified = member.verified;
|
|
1109
|
+
* const customFields = member.customFields;
|
|
1110
|
+
* const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
|
|
1111
|
+
* }
|
|
1112
|
+
* ```
|
|
1113
|
+
*/
|
|
800
1114
|
getCurrentMember(options) {
|
|
801
1115
|
return __async(this, null, function* () {
|
|
802
1116
|
const memberToken = getMemberToken();
|
|
@@ -822,6 +1136,19 @@ var initRequest = ({
|
|
|
822
1136
|
}
|
|
823
1137
|
});
|
|
824
1138
|
},
|
|
1139
|
+
/**
|
|
1140
|
+
* Retrieves the current member's JSON data store.
|
|
1141
|
+
* This is a flexible key-value store for storing arbitrary member data.
|
|
1142
|
+
*
|
|
1143
|
+
* @returns Promise resolving to the member's JSON data object
|
|
1144
|
+
*
|
|
1145
|
+
* @example
|
|
1146
|
+
* ```typescript
|
|
1147
|
+
* const { data: json } = await memberstack.getMemberJSON();
|
|
1148
|
+
* console.log('Preferences:', json.preferences);
|
|
1149
|
+
* console.log('Last visited:', json.lastVisitedPage);
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
825
1152
|
getMemberJSON(options) {
|
|
826
1153
|
return __async(this, null, function* () {
|
|
827
1154
|
return sendRequest({
|
|
@@ -831,6 +1158,35 @@ var initRequest = ({
|
|
|
831
1158
|
});
|
|
832
1159
|
});
|
|
833
1160
|
},
|
|
1161
|
+
/**
|
|
1162
|
+
* Updates the current member's JSON data store.
|
|
1163
|
+
* You can store any JSON-serializable data. Updates are merged with existing data.
|
|
1164
|
+
*
|
|
1165
|
+
* @param params - JSON data to store
|
|
1166
|
+
* @param params.json - Object containing the data to store
|
|
1167
|
+
* @returns Promise resolving to the updated JSON data
|
|
1168
|
+
*
|
|
1169
|
+
* @example Store user preferences
|
|
1170
|
+
* ```typescript
|
|
1171
|
+
* await memberstack.updateMemberJSON({
|
|
1172
|
+
* json: {
|
|
1173
|
+
* preferences: { theme: 'dark', notifications: true },
|
|
1174
|
+
* lastVisitedPage: '/dashboard',
|
|
1175
|
+
* onboardingComplete: true
|
|
1176
|
+
* }
|
|
1177
|
+
* });
|
|
1178
|
+
* ```
|
|
1179
|
+
*
|
|
1180
|
+
* @example Store app-specific data
|
|
1181
|
+
* ```typescript
|
|
1182
|
+
* await memberstack.updateMemberJSON({
|
|
1183
|
+
* json: {
|
|
1184
|
+
* savedItems: ['item1', 'item2'],
|
|
1185
|
+
* progress: { level: 5, score: 1200 }
|
|
1186
|
+
* }
|
|
1187
|
+
* });
|
|
1188
|
+
* ```
|
|
1189
|
+
*/
|
|
834
1190
|
updateMemberJSON(params, options) {
|
|
835
1191
|
return __async(this, null, function* () {
|
|
836
1192
|
return sendRequest({
|
|
@@ -843,6 +1199,22 @@ var initRequest = ({
|
|
|
843
1199
|
});
|
|
844
1200
|
});
|
|
845
1201
|
},
|
|
1202
|
+
/**
|
|
1203
|
+
* Adds a free plan to the current member.
|
|
1204
|
+
* For paid plans, use `purchasePlansWithCheckout()` instead.
|
|
1205
|
+
*
|
|
1206
|
+
* @param params - Plan parameters
|
|
1207
|
+
* @param params.planId - The ID of the free plan to add
|
|
1208
|
+
* @returns Promise resolving to the updated member data with the new plan
|
|
1209
|
+
*
|
|
1210
|
+
* @example Add a free tier plan
|
|
1211
|
+
* ```typescript
|
|
1212
|
+
* const { data } = await memberstack.addPlan({
|
|
1213
|
+
* planId: 'pln_free_tier'
|
|
1214
|
+
* });
|
|
1215
|
+
* console.log('Plan added, redirect:', data.redirect);
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
846
1218
|
addPlan(params, options) {
|
|
847
1219
|
return __async(this, null, function* () {
|
|
848
1220
|
return sendRequest({
|
|
@@ -855,11 +1227,54 @@ var initRequest = ({
|
|
|
855
1227
|
});
|
|
856
1228
|
});
|
|
857
1229
|
},
|
|
1230
|
+
/**
|
|
1231
|
+
* Initiates a Stripe checkout session for purchasing a paid plan.
|
|
1232
|
+
* By default, redirects the user to Stripe's hosted checkout page.
|
|
1233
|
+
*
|
|
1234
|
+
* @param params - Checkout configuration
|
|
1235
|
+
* @param params.priceId - The Memberstack price ID to purchase (e.g., 'prc_monthly_pro')
|
|
1236
|
+
* @param params.successUrl - URL to redirect to after successful payment (relative or absolute)
|
|
1237
|
+
* @param params.cancelUrl - URL to redirect to if user cancels checkout (relative or absolute)
|
|
1238
|
+
* @param params.couponId - Optional Stripe coupon ID to apply
|
|
1239
|
+
* @param params.autoRedirect - Set to `false` to get the checkout URL without redirecting
|
|
1240
|
+
* @returns Promise resolving to checkout data (includes URL if autoRedirect is false)
|
|
1241
|
+
*
|
|
1242
|
+
* @example Start checkout for a plan
|
|
1243
|
+
* ```typescript
|
|
1244
|
+
* await memberstack.purchasePlansWithCheckout({
|
|
1245
|
+
* priceId: 'prc_monthly_pro',
|
|
1246
|
+
* successUrl: '/welcome',
|
|
1247
|
+
* cancelUrl: '/pricing'
|
|
1248
|
+
* });
|
|
1249
|
+
* // User is redirected to Stripe checkout
|
|
1250
|
+
* ```
|
|
1251
|
+
*
|
|
1252
|
+
* @example Get checkout URL without redirecting
|
|
1253
|
+
* ```typescript
|
|
1254
|
+
* const { data } = await memberstack.purchasePlansWithCheckout({
|
|
1255
|
+
* priceId: 'prc_monthly_pro',
|
|
1256
|
+
* successUrl: '/welcome',
|
|
1257
|
+
* cancelUrl: '/pricing',
|
|
1258
|
+
* autoRedirect: false
|
|
1259
|
+
* });
|
|
1260
|
+
* console.log('Checkout URL:', data.url);
|
|
1261
|
+
* ```
|
|
1262
|
+
*
|
|
1263
|
+
* @example Apply a coupon
|
|
1264
|
+
* ```typescript
|
|
1265
|
+
* await memberstack.purchasePlansWithCheckout({
|
|
1266
|
+
* priceId: 'prc_annual_pro',
|
|
1267
|
+
* couponId: 'SAVE20',
|
|
1268
|
+
* successUrl: '/welcome',
|
|
1269
|
+
* cancelUrl: '/pricing'
|
|
1270
|
+
* });
|
|
1271
|
+
* ```
|
|
1272
|
+
*/
|
|
858
1273
|
purchasePlansWithCheckout(params, options) {
|
|
859
1274
|
return __async(this, null, function* () {
|
|
860
|
-
function getRedirectURL(
|
|
1275
|
+
function getRedirectURL(URL2) {
|
|
861
1276
|
let redirectUrl = window.location.href;
|
|
862
|
-
const urlParam =
|
|
1277
|
+
const urlParam = URL2;
|
|
863
1278
|
if (urlParam) {
|
|
864
1279
|
if (urlParam.indexOf("http://") === 0 || urlParam.indexOf("https://") === 0) {
|
|
865
1280
|
redirectUrl = urlParam;
|
|
@@ -870,7 +1285,7 @@ var initRequest = ({
|
|
|
870
1285
|
return redirectUrl;
|
|
871
1286
|
}
|
|
872
1287
|
const success_url = params.successUrl ? getRedirectURL(params.successUrl) : void 0;
|
|
873
|
-
const cancel_url = getRedirectURL(params.cancelUrl);
|
|
1288
|
+
const cancel_url = params.cancelUrl ? getRedirectURL(params.cancelUrl) : window.location.href;
|
|
874
1289
|
const request = yield sendRequest({
|
|
875
1290
|
method: "POST" /* POST */,
|
|
876
1291
|
url: `/member/plans/create-checkout-session`,
|
|
@@ -892,14 +1307,42 @@ var initRequest = ({
|
|
|
892
1307
|
return request;
|
|
893
1308
|
}
|
|
894
1309
|
window.location.href = request.data.url;
|
|
1310
|
+
return request;
|
|
895
1311
|
});
|
|
896
1312
|
},
|
|
897
|
-
|
|
1313
|
+
/**
|
|
1314
|
+
* Opens the Stripe Customer Portal for the current member.
|
|
1315
|
+
* The portal allows members to manage their subscriptions, update payment methods, and view invoices.
|
|
1316
|
+
* By default, redirects the user to the Stripe-hosted portal.
|
|
1317
|
+
*
|
|
1318
|
+
* @param params - Portal configuration
|
|
1319
|
+
* @param params.returnUrl - URL to redirect to when member exits the portal (relative or absolute)
|
|
1320
|
+
* @param params.priceIds - Optional array of price IDs to show for plan switching
|
|
1321
|
+
* @param params.autoRedirect - Set to `false` to get the portal URL without redirecting
|
|
1322
|
+
* @returns Promise resolving to portal data (includes URL if autoRedirect is false)
|
|
1323
|
+
*
|
|
1324
|
+
* @example Open customer portal
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* await memberstack.launchStripeCustomerPortal({
|
|
1327
|
+
* returnUrl: '/account'
|
|
1328
|
+
* });
|
|
1329
|
+
* // User is redirected to Stripe Customer Portal
|
|
1330
|
+
* ```
|
|
1331
|
+
*
|
|
1332
|
+
* @example Get portal URL without redirecting
|
|
1333
|
+
* ```typescript
|
|
1334
|
+
* const { data } = await memberstack.launchStripeCustomerPortal({
|
|
1335
|
+
* returnUrl: '/account',
|
|
1336
|
+
* autoRedirect: false
|
|
1337
|
+
* });
|
|
1338
|
+
* console.log('Portal URL:', data.url);
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
898
1341
|
launchStripeCustomerPortal(params, options) {
|
|
899
1342
|
return __async(this, null, function* () {
|
|
900
|
-
function getRedirectURL(
|
|
1343
|
+
function getRedirectURL(URL2) {
|
|
901
1344
|
let redirectUrl = window.location.href;
|
|
902
|
-
const urlParam =
|
|
1345
|
+
const urlParam = URL2;
|
|
903
1346
|
if (urlParam) {
|
|
904
1347
|
if (urlParam.indexOf("http://") === 0 || urlParam.indexOf("https://") === 0) {
|
|
905
1348
|
redirectUrl = urlParam;
|
|
@@ -927,8 +1370,25 @@ var initRequest = ({
|
|
|
927
1370
|
return request;
|
|
928
1371
|
}
|
|
929
1372
|
window.location.href = request.data.url;
|
|
1373
|
+
return request;
|
|
930
1374
|
});
|
|
931
1375
|
},
|
|
1376
|
+
/**
|
|
1377
|
+
* Removes a plan from the current member.
|
|
1378
|
+
* For paid plans, this will cancel the subscription.
|
|
1379
|
+
*
|
|
1380
|
+
* @param params - Plan parameters
|
|
1381
|
+
* @param params.planId - The ID of the plan to remove
|
|
1382
|
+
* @returns Promise resolving to the updated member data
|
|
1383
|
+
*
|
|
1384
|
+
* @example Remove a plan
|
|
1385
|
+
* ```typescript
|
|
1386
|
+
* await memberstack.removePlan({
|
|
1387
|
+
* planId: 'pln_premium'
|
|
1388
|
+
* });
|
|
1389
|
+
* // Plan removed/subscription cancelled
|
|
1390
|
+
* ```
|
|
1391
|
+
*/
|
|
932
1392
|
removePlan(params, options) {
|
|
933
1393
|
return __async(this, null, function* () {
|
|
934
1394
|
return sendRequest({
|
|
@@ -941,6 +1401,35 @@ var initRequest = ({
|
|
|
941
1401
|
});
|
|
942
1402
|
});
|
|
943
1403
|
},
|
|
1404
|
+
/**
|
|
1405
|
+
* Updates the current member's custom fields.
|
|
1406
|
+
* Only updates the fields you specify; other fields remain unchanged.
|
|
1407
|
+
*
|
|
1408
|
+
* @param params - Update data
|
|
1409
|
+
* @param params.customFields - Object containing custom field key-value pairs to update
|
|
1410
|
+
* @returns Promise resolving to the updated member data
|
|
1411
|
+
*
|
|
1412
|
+
* @example Update custom fields
|
|
1413
|
+
* ```typescript
|
|
1414
|
+
* const { data: member } = await memberstack.updateMember({
|
|
1415
|
+
* customFields: {
|
|
1416
|
+
* firstName: 'Jane',
|
|
1417
|
+
* company: 'Acme Inc',
|
|
1418
|
+
* preferences: { theme: 'dark' }
|
|
1419
|
+
* }
|
|
1420
|
+
* });
|
|
1421
|
+
* console.log('Updated:', member.customFields);
|
|
1422
|
+
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @example Update a single field
|
|
1425
|
+
* ```typescript
|
|
1426
|
+
* await memberstack.updateMember({
|
|
1427
|
+
* customFields: {
|
|
1428
|
+
* lastLoginPage: window.location.pathname
|
|
1429
|
+
* }
|
|
1430
|
+
* });
|
|
1431
|
+
* ```
|
|
1432
|
+
*/
|
|
944
1433
|
updateMember(params, options) {
|
|
945
1434
|
return __async(this, null, function* () {
|
|
946
1435
|
return sendRequest({
|
|
@@ -951,6 +1440,33 @@ var initRequest = ({
|
|
|
951
1440
|
});
|
|
952
1441
|
});
|
|
953
1442
|
},
|
|
1443
|
+
/**
|
|
1444
|
+
* Updates the current member's authentication credentials (email and/or password).
|
|
1445
|
+
* Requires the current password to verify the member's identity.
|
|
1446
|
+
*
|
|
1447
|
+
* @param params - Auth update parameters
|
|
1448
|
+
* @param params.email - New email address (optional)
|
|
1449
|
+
* @param params.oldPassword - Current password (required for password changes)
|
|
1450
|
+
* @param params.newPassword - New password (optional)
|
|
1451
|
+
* @returns Promise resolving to the updated member data
|
|
1452
|
+
* @throws When the old password is incorrect
|
|
1453
|
+
*
|
|
1454
|
+
* @example Change email
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* await memberstack.updateMemberAuth({
|
|
1457
|
+
* email: 'newemail@example.com',
|
|
1458
|
+
* oldPassword: 'currentPassword'
|
|
1459
|
+
* });
|
|
1460
|
+
* ```
|
|
1461
|
+
*
|
|
1462
|
+
* @example Change password
|
|
1463
|
+
* ```typescript
|
|
1464
|
+
* await memberstack.updateMemberAuth({
|
|
1465
|
+
* oldPassword: 'currentPassword',
|
|
1466
|
+
* newPassword: 'newSecurePassword123'
|
|
1467
|
+
* });
|
|
1468
|
+
* ```
|
|
1469
|
+
*/
|
|
954
1470
|
updateMemberAuth(params, options) {
|
|
955
1471
|
return __async(this, null, function* () {
|
|
956
1472
|
return sendRequest({
|
|
@@ -961,6 +1477,23 @@ var initRequest = ({
|
|
|
961
1477
|
});
|
|
962
1478
|
});
|
|
963
1479
|
},
|
|
1480
|
+
/**
|
|
1481
|
+
* Sets a password for a member who signed up via passwordless or OAuth.
|
|
1482
|
+
* Use this when a member wants to add password-based login to their account.
|
|
1483
|
+
*
|
|
1484
|
+
* @param params - Password parameters
|
|
1485
|
+
* @param params.password - The password to set
|
|
1486
|
+
* @returns Promise resolving to the updated member data
|
|
1487
|
+
*
|
|
1488
|
+
* @example
|
|
1489
|
+
* ```typescript
|
|
1490
|
+
* // For members who signed up via Google OAuth or passwordless
|
|
1491
|
+
* await memberstack.setPassword({
|
|
1492
|
+
* password: 'newSecurePassword123'
|
|
1493
|
+
* });
|
|
1494
|
+
* // Member can now log in with email/password
|
|
1495
|
+
* ```
|
|
1496
|
+
*/
|
|
964
1497
|
setPassword(params, options) {
|
|
965
1498
|
return __async(this, null, function* () {
|
|
966
1499
|
return sendRequest({
|
|
@@ -1006,6 +1539,43 @@ var initRequest = ({
|
|
|
1006
1539
|
return data;
|
|
1007
1540
|
});
|
|
1008
1541
|
},
|
|
1542
|
+
/**
|
|
1543
|
+
* Creates a new member account with email and password.
|
|
1544
|
+
* On success, the member is automatically logged in and their session is stored.
|
|
1545
|
+
*
|
|
1546
|
+
* @param params - Signup details
|
|
1547
|
+
* @param params.email - The new member's email address
|
|
1548
|
+
* @param params.password - The new member's password (minimum 8 characters recommended)
|
|
1549
|
+
* @param params.customFields - Optional custom field values defined in your Memberstack dashboard
|
|
1550
|
+
* @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
|
|
1551
|
+
* @param params.metaData - Optional metadata to store with the member
|
|
1552
|
+
* @param params.inviteToken - Optional team invite token for team signups
|
|
1553
|
+
* @returns Promise resolving to the new member data and tokens
|
|
1554
|
+
* @throws When email is already in use or validation fails
|
|
1555
|
+
*
|
|
1556
|
+
* @example Basic signup
|
|
1557
|
+
* ```typescript
|
|
1558
|
+
* const { data } = await memberstack.signupMemberEmailPassword({
|
|
1559
|
+
* email: 'newuser@example.com',
|
|
1560
|
+
* password: 'securePassword123'
|
|
1561
|
+
* });
|
|
1562
|
+
* console.log('Welcome!', data.member.id);
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* @example Signup with custom fields and a free plan
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* const { data } = await memberstack.signupMemberEmailPassword({
|
|
1568
|
+
* email: 'newuser@example.com',
|
|
1569
|
+
* password: 'securePassword123',
|
|
1570
|
+
* customFields: {
|
|
1571
|
+
* firstName: 'Jane',
|
|
1572
|
+
* lastName: 'Doe',
|
|
1573
|
+
* company: 'Acme Inc'
|
|
1574
|
+
* },
|
|
1575
|
+
* plans: [{ planId: 'pln_free_tier' }]
|
|
1576
|
+
* });
|
|
1577
|
+
* ```
|
|
1578
|
+
*/
|
|
1009
1579
|
signupMemberEmailPassword(params, options) {
|
|
1010
1580
|
return __async(this, null, function* () {
|
|
1011
1581
|
var _a2, _b, _c;
|
|
@@ -1087,20 +1657,52 @@ var initRequest = ({
|
|
|
1087
1657
|
});
|
|
1088
1658
|
});
|
|
1089
1659
|
},
|
|
1660
|
+
/**
|
|
1661
|
+
* Uploads a new profile image for the current member.
|
|
1662
|
+
* Accepts a File object (from an input element) or a Blob.
|
|
1663
|
+
*
|
|
1664
|
+
* @param params - Image parameters
|
|
1665
|
+
* @param params.profileImage - The image file to upload
|
|
1666
|
+
* @returns Promise resolving to the new profile image URL
|
|
1667
|
+
*
|
|
1668
|
+
* @example Upload from file input
|
|
1669
|
+
* ```typescript
|
|
1670
|
+
* const input = document.querySelector('input[type="file"]');
|
|
1671
|
+
* const file = input.files[0];
|
|
1672
|
+
*
|
|
1673
|
+
* const { data } = await memberstack.updateMemberProfileImage({
|
|
1674
|
+
* profileImage: file
|
|
1675
|
+
* });
|
|
1676
|
+
* console.log('New image URL:', data.profileImage);
|
|
1677
|
+
* ```
|
|
1678
|
+
*/
|
|
1090
1679
|
updateMemberProfileImage(params) {
|
|
1091
1680
|
return __async(this, null, function* () {
|
|
1092
|
-
if (params.profileImage) {
|
|
1093
|
-
|
|
1094
|
-
formData.append("profileImage", params.profileImage);
|
|
1095
|
-
return sendRequest({
|
|
1096
|
-
method: "POST" /* POST */,
|
|
1097
|
-
url: `/member/profile-image`,
|
|
1098
|
-
data: formData,
|
|
1099
|
-
contentType: "multipart/form-data"
|
|
1100
|
-
});
|
|
1681
|
+
if (!params.profileImage) {
|
|
1682
|
+
throw new Error("profileImage is required");
|
|
1101
1683
|
}
|
|
1684
|
+
const formData = new FormData();
|
|
1685
|
+
formData.append("profileImage", params.profileImage);
|
|
1686
|
+
return sendRequest({
|
|
1687
|
+
method: "POST" /* POST */,
|
|
1688
|
+
url: `/member/profile-image`,
|
|
1689
|
+
data: formData,
|
|
1690
|
+
contentType: "multipart/form-data"
|
|
1691
|
+
});
|
|
1102
1692
|
});
|
|
1103
1693
|
},
|
|
1694
|
+
/**
|
|
1695
|
+
* Sends a verification email to the current member.
|
|
1696
|
+
* Use this when email verification is enabled in your Memberstack settings.
|
|
1697
|
+
*
|
|
1698
|
+
* @returns Promise resolving to success confirmation
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```typescript
|
|
1702
|
+
* await memberstack.sendMemberVerificationEmail();
|
|
1703
|
+
* // Show message: "Verification email sent! Check your inbox."
|
|
1704
|
+
* ```
|
|
1705
|
+
*/
|
|
1104
1706
|
sendMemberVerificationEmail() {
|
|
1105
1707
|
return __async(this, null, function* () {
|
|
1106
1708
|
return sendRequest({
|
|
@@ -1113,6 +1715,22 @@ var initRequest = ({
|
|
|
1113
1715
|
});
|
|
1114
1716
|
});
|
|
1115
1717
|
},
|
|
1718
|
+
/**
|
|
1719
|
+
* Sends a password reset email to a member.
|
|
1720
|
+
* The email contains a link with a token that can be used to reset their password.
|
|
1721
|
+
*
|
|
1722
|
+
* @param params - Email parameters
|
|
1723
|
+
* @param params.email - The member's email address
|
|
1724
|
+
* @returns Promise resolving to success confirmation
|
|
1725
|
+
*
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```typescript
|
|
1728
|
+
* await memberstack.sendMemberResetPasswordEmail({
|
|
1729
|
+
* email: 'user@example.com'
|
|
1730
|
+
* });
|
|
1731
|
+
* // Show confirmation: "Check your email for reset instructions"
|
|
1732
|
+
* ```
|
|
1733
|
+
*/
|
|
1116
1734
|
sendMemberResetPasswordEmail(params) {
|
|
1117
1735
|
return __async(this, null, function* () {
|
|
1118
1736
|
return sendRequest({
|
|
@@ -1124,6 +1742,28 @@ var initRequest = ({
|
|
|
1124
1742
|
});
|
|
1125
1743
|
});
|
|
1126
1744
|
},
|
|
1745
|
+
/**
|
|
1746
|
+
* Completes the password reset process using the token from the reset email.
|
|
1747
|
+
* Typically called from a password reset page that receives the token via URL parameter.
|
|
1748
|
+
*
|
|
1749
|
+
* @param params - Reset parameters
|
|
1750
|
+
* @param params.token - The reset token from the email link
|
|
1751
|
+
* @param params.newPassword - The new password to set
|
|
1752
|
+
* @returns Promise resolving to success confirmation
|
|
1753
|
+
* @throws When the token is invalid or expired
|
|
1754
|
+
*
|
|
1755
|
+
* @example
|
|
1756
|
+
* ```typescript
|
|
1757
|
+
* // Get token from URL: /reset-password?token=abc123
|
|
1758
|
+
* const token = new URLSearchParams(window.location.search).get('token');
|
|
1759
|
+
*
|
|
1760
|
+
* await memberstack.resetMemberPassword({
|
|
1761
|
+
* token,
|
|
1762
|
+
* newPassword: 'newSecurePassword123'
|
|
1763
|
+
* });
|
|
1764
|
+
* // Password updated, redirect to login
|
|
1765
|
+
* ```
|
|
1766
|
+
*/
|
|
1127
1767
|
resetMemberPassword(params) {
|
|
1128
1768
|
return __async(this, null, function* () {
|
|
1129
1769
|
return sendRequest({
|
|
@@ -1136,6 +1776,27 @@ var initRequest = ({
|
|
|
1136
1776
|
});
|
|
1137
1777
|
});
|
|
1138
1778
|
},
|
|
1779
|
+
/**
|
|
1780
|
+
* Signs out the currently authenticated member.
|
|
1781
|
+
* Clears the local session and invalidates the server-side session.
|
|
1782
|
+
*
|
|
1783
|
+
* @returns Promise resolving to logout confirmation (may include a redirect URL)
|
|
1784
|
+
*
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```typescript
|
|
1787
|
+
* await memberstack.logout();
|
|
1788
|
+
* // User is now logged out
|
|
1789
|
+
* window.location.href = '/login';
|
|
1790
|
+
* ```
|
|
1791
|
+
*
|
|
1792
|
+
* @example With redirect handling
|
|
1793
|
+
* ```typescript
|
|
1794
|
+
* const { data } = await memberstack.logout();
|
|
1795
|
+
* if (data.redirect) {
|
|
1796
|
+
* window.location.href = data.redirect;
|
|
1797
|
+
* }
|
|
1798
|
+
* ```
|
|
1799
|
+
*/
|
|
1139
1800
|
logout(options) {
|
|
1140
1801
|
return __async(this, null, function* () {
|
|
1141
1802
|
const data = yield sendRequest({
|
|
@@ -1148,6 +1809,20 @@ var initRequest = ({
|
|
|
1148
1809
|
});
|
|
1149
1810
|
},
|
|
1150
1811
|
// Data Tables Methods
|
|
1812
|
+
/**
|
|
1813
|
+
* Retrieves all data tables configured for your app.
|
|
1814
|
+
* Returns the list of tables and their schemas.
|
|
1815
|
+
*
|
|
1816
|
+
* @returns Promise resolving to an array of data tables
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* ```typescript
|
|
1820
|
+
* const { data: tables } = await memberstack.getDataTables();
|
|
1821
|
+
* tables.forEach(table => {
|
|
1822
|
+
* console.log('Table:', table.name, table.key);
|
|
1823
|
+
* });
|
|
1824
|
+
* ```
|
|
1825
|
+
*/
|
|
1151
1826
|
getDataTables(options) {
|
|
1152
1827
|
return __async(this, null, function* () {
|
|
1153
1828
|
return sendRequest({
|
|
@@ -1157,6 +1832,21 @@ var initRequest = ({
|
|
|
1157
1832
|
});
|
|
1158
1833
|
});
|
|
1159
1834
|
},
|
|
1835
|
+
/**
|
|
1836
|
+
* Retrieves a specific data table's schema and configuration.
|
|
1837
|
+
*
|
|
1838
|
+
* @param params - Table parameters
|
|
1839
|
+
* @param params.table - The table key/identifier
|
|
1840
|
+
* @returns Promise resolving to the table schema
|
|
1841
|
+
*
|
|
1842
|
+
* @example
|
|
1843
|
+
* ```typescript
|
|
1844
|
+
* const { data: table } = await memberstack.getDataTable({
|
|
1845
|
+
* table: 'posts'
|
|
1846
|
+
* });
|
|
1847
|
+
* console.log('Columns:', table.columns);
|
|
1848
|
+
* ```
|
|
1849
|
+
*/
|
|
1160
1850
|
getDataTable(params, options) {
|
|
1161
1851
|
return __async(this, null, function* () {
|
|
1162
1852
|
return sendRequest({
|
|
@@ -1167,6 +1857,30 @@ var initRequest = ({
|
|
|
1167
1857
|
});
|
|
1168
1858
|
});
|
|
1169
1859
|
},
|
|
1860
|
+
/**
|
|
1861
|
+
* Retrieves records from a data table with optional filtering and pagination.
|
|
1862
|
+
*
|
|
1863
|
+
* @param params - Query parameters
|
|
1864
|
+
* @param params.table - The table key/identifier
|
|
1865
|
+
* @param params.limit - Maximum number of records to return
|
|
1866
|
+
* @param params.after - Cursor for pagination (record ID to start after)
|
|
1867
|
+
* @param params.sortBy - Field to sort by
|
|
1868
|
+
* @param params.sortDirection - Sort direction ('asc' or 'desc')
|
|
1869
|
+
* @param params.createdAfter - Filter records created after this date
|
|
1870
|
+
* @param params.createdBefore - Filter records created before this date
|
|
1871
|
+
* @returns Promise resolving to records array with pagination info
|
|
1872
|
+
*
|
|
1873
|
+
* @example List records with pagination
|
|
1874
|
+
* ```typescript
|
|
1875
|
+
* const { data } = await memberstack.getDataRecords({
|
|
1876
|
+
* table: 'posts',
|
|
1877
|
+
* limit: 10,
|
|
1878
|
+
* sortBy: 'createdAt',
|
|
1879
|
+
* sortDirection: 'desc'
|
|
1880
|
+
* });
|
|
1881
|
+
* console.log('Records:', data.records);
|
|
1882
|
+
* ```
|
|
1883
|
+
*/
|
|
1170
1884
|
getDataRecords(params, options) {
|
|
1171
1885
|
return __async(this, null, function* () {
|
|
1172
1886
|
var _a2;
|
|
@@ -1209,6 +1923,28 @@ var initRequest = ({
|
|
|
1209
1923
|
return res;
|
|
1210
1924
|
});
|
|
1211
1925
|
},
|
|
1926
|
+
/**
|
|
1927
|
+
* Creates a new record in a data table.
|
|
1928
|
+
*
|
|
1929
|
+
* @param params - Record parameters
|
|
1930
|
+
* @param params.table - The table key/identifier
|
|
1931
|
+
* @param params.data - The record data as key-value pairs
|
|
1932
|
+
* @param params.memberId - Optional member ID to associate with the record
|
|
1933
|
+
* @returns Promise resolving to the created record
|
|
1934
|
+
*
|
|
1935
|
+
* @example Create a new post
|
|
1936
|
+
* ```typescript
|
|
1937
|
+
* const { data: record } = await memberstack.createDataRecord({
|
|
1938
|
+
* table: 'posts',
|
|
1939
|
+
* data: {
|
|
1940
|
+
* title: 'My First Post',
|
|
1941
|
+
* content: 'Hello world!',
|
|
1942
|
+
* published: true
|
|
1943
|
+
* }
|
|
1944
|
+
* });
|
|
1945
|
+
* console.log('Created record:', record.id);
|
|
1946
|
+
* ```
|
|
1947
|
+
*/
|
|
1212
1948
|
createDataRecord(params, options) {
|
|
1213
1949
|
return __async(this, null, function* () {
|
|
1214
1950
|
return sendRequest({
|
|
@@ -1222,6 +1958,23 @@ var initRequest = ({
|
|
|
1222
1958
|
});
|
|
1223
1959
|
});
|
|
1224
1960
|
},
|
|
1961
|
+
/**
|
|
1962
|
+
* Retrieves a single record by ID from a data table.
|
|
1963
|
+
*
|
|
1964
|
+
* @param params - Record parameters
|
|
1965
|
+
* @param params.table - The table key/identifier
|
|
1966
|
+
* @param params.recordId - The ID of the record to retrieve
|
|
1967
|
+
* @returns Promise resolving to the record data
|
|
1968
|
+
*
|
|
1969
|
+
* @example Get a specific post
|
|
1970
|
+
* ```typescript
|
|
1971
|
+
* const { data: record } = await memberstack.getDataRecord({
|
|
1972
|
+
* table: 'posts',
|
|
1973
|
+
* recordId: 'rec_abc123'
|
|
1974
|
+
* });
|
|
1975
|
+
* console.log('Post:', record.title);
|
|
1976
|
+
* ```
|
|
1977
|
+
*/
|
|
1225
1978
|
getDataRecord(params, options) {
|
|
1226
1979
|
return __async(this, null, function* () {
|
|
1227
1980
|
var _a2;
|
|
@@ -1244,6 +1997,25 @@ var initRequest = ({
|
|
|
1244
1997
|
return res;
|
|
1245
1998
|
});
|
|
1246
1999
|
},
|
|
2000
|
+
/**
|
|
2001
|
+
* Updates an existing record in a data table.
|
|
2002
|
+
*
|
|
2003
|
+
* @param params - Update parameters
|
|
2004
|
+
* @param params.recordId - The ID of the record to update
|
|
2005
|
+
* @param params.data - The fields to update as key-value pairs
|
|
2006
|
+
* @returns Promise resolving to the updated record
|
|
2007
|
+
*
|
|
2008
|
+
* @example Update a post
|
|
2009
|
+
* ```typescript
|
|
2010
|
+
* const { data: record } = await memberstack.updateDataRecord({
|
|
2011
|
+
* recordId: 'rec_abc123',
|
|
2012
|
+
* data: {
|
|
2013
|
+
* title: 'Updated Title',
|
|
2014
|
+
* published: false
|
|
2015
|
+
* }
|
|
2016
|
+
* });
|
|
2017
|
+
* ```
|
|
2018
|
+
*/
|
|
1247
2019
|
updateDataRecord(params, options) {
|
|
1248
2020
|
return __async(this, null, function* () {
|
|
1249
2021
|
return sendRequest({
|
|
@@ -1256,6 +2028,20 @@ var initRequest = ({
|
|
|
1256
2028
|
});
|
|
1257
2029
|
});
|
|
1258
2030
|
},
|
|
2031
|
+
/**
|
|
2032
|
+
* Deletes a record from a data table.
|
|
2033
|
+
*
|
|
2034
|
+
* @param params - Delete parameters
|
|
2035
|
+
* @param params.recordId - The ID of the record to delete
|
|
2036
|
+
* @returns Promise resolving to deletion confirmation
|
|
2037
|
+
*
|
|
2038
|
+
* @example Delete a post
|
|
2039
|
+
* ```typescript
|
|
2040
|
+
* await memberstack.deleteDataRecord({
|
|
2041
|
+
* recordId: 'rec_abc123'
|
|
2042
|
+
* });
|
|
2043
|
+
* ```
|
|
2044
|
+
*/
|
|
1259
2045
|
deleteDataRecord(params, options) {
|
|
1260
2046
|
return __async(this, null, function* () {
|
|
1261
2047
|
return sendRequest({
|
|
@@ -1265,6 +2051,42 @@ var initRequest = ({
|
|
|
1265
2051
|
});
|
|
1266
2052
|
});
|
|
1267
2053
|
},
|
|
2054
|
+
/**
|
|
2055
|
+
* Queries records from a data table with advanced filtering.
|
|
2056
|
+
* Provides more control than getDataRecords for complex queries.
|
|
2057
|
+
*
|
|
2058
|
+
* @param params - Query parameters
|
|
2059
|
+
* @param params.table - The table key/identifier
|
|
2060
|
+
* @param params.query - Query object with where, orderBy, take, skip options
|
|
2061
|
+
* @returns Promise resolving to matching records
|
|
2062
|
+
*
|
|
2063
|
+
* @example Query with filters
|
|
2064
|
+
* ```typescript
|
|
2065
|
+
* const { data } = await memberstack.queryDataRecords({
|
|
2066
|
+
* table: 'posts',
|
|
2067
|
+
* query: {
|
|
2068
|
+
* where: {
|
|
2069
|
+
* published: { equals: true },
|
|
2070
|
+
* category: { equals: 'tech' }
|
|
2071
|
+
* },
|
|
2072
|
+
* orderBy: { createdAt: 'desc' },
|
|
2073
|
+
* take: 10
|
|
2074
|
+
* }
|
|
2075
|
+
* });
|
|
2076
|
+
* ```
|
|
2077
|
+
*
|
|
2078
|
+
* @example Query with member filter
|
|
2079
|
+
* ```typescript
|
|
2080
|
+
* const { data } = await memberstack.queryDataRecords({
|
|
2081
|
+
* table: 'comments',
|
|
2082
|
+
* query: {
|
|
2083
|
+
* where: {
|
|
2084
|
+
* memberId: { equals: 'mem_xyz789' }
|
|
2085
|
+
* }
|
|
2086
|
+
* }
|
|
2087
|
+
* });
|
|
2088
|
+
* ```
|
|
2089
|
+
*/
|
|
1268
2090
|
queryDataRecords(params, options) {
|
|
1269
2091
|
return __async(this, null, function* () {
|
|
1270
2092
|
return sendRequest({
|