@memberstack/dom 2.0.2-beta.0 → 2.0.2
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/lib/index.d.mts +61 -26
- package/lib/index.d.ts +61 -26
- package/lib/index.js +793 -53
- package/lib/index.mjs +793 -53
- package/lib/{models-CTRKogoR.d.ts → models-CFT_ABd5.d.ts} +2 -2
- package/lib/testing/index.d.mts +25 -2
- package/lib/testing/index.d.ts +25 -2
- package/lib/testing/index.js +28 -6
- package/lib/testing/index.mjs +26 -5
- package/package.json +1 -1
- package/lib/auth/index.d.mts +0 -63
- package/lib/auth/index.d.ts +0 -63
- package/lib/auth/index.global.js +0 -244
- package/lib/auth/index.js +0 -161
- package/lib/auth/index.mjs +0 -123
- package/lib/constants/endpoints.d.mts +0 -5
- package/lib/constants/endpoints.d.ts +0 -5
- package/lib/constants/endpoints.global.js +0 -29
- package/lib/constants/endpoints.js +0 -32
- package/lib/constants/endpoints.mjs +0 -7
- package/lib/methods/dom/index.d.mts +0 -2
- package/lib/methods/dom/index.d.ts +0 -2
- package/lib/methods/dom/index.global.js +0 -2
- package/lib/methods/dom/index.js +0 -1
- package/lib/methods/dom/index.mjs +0 -0
- package/lib/methods/dom/main-dom.d.mts +0 -2
- package/lib/methods/dom/main-dom.d.ts +0 -2
- package/lib/methods/dom/main-dom.global.js +0 -30620
- package/lib/methods/dom/main-dom.js +0 -15611
- package/lib/methods/dom/main-dom.mjs +0 -15593
- package/lib/methods/dom/methods.d.mts +0 -100
- package/lib/methods/dom/methods.d.ts +0 -100
- package/lib/methods/dom/methods.global.js +0 -30827
- package/lib/methods/dom/methods.js +0 -335
- package/lib/methods/dom/methods.mjs +0 -302
- package/lib/methods/index.d.mts +0 -185
- package/lib/methods/index.d.ts +0 -185
- package/lib/methods/index.global.js +0 -46361
- package/lib/methods/index.js +0 -2530
- package/lib/methods/index.mjs +0 -2500
- package/lib/methods/requests/index.d.mts +0 -912
- package/lib/methods/requests/index.d.ts +0 -912
- package/lib/methods/requests/index.global.js +0 -15553
- package/lib/methods/requests/index.js +0 -2145
- package/lib/methods/requests/index.mjs +0 -2110
- package/lib/methods/requests/requests.d.mts +0 -43
- package/lib/methods/requests/requests.d.ts +0 -43
- package/lib/methods/requests/requests.global.js +0 -14528
- package/lib/methods/requests/requests.js +0 -244
- package/lib/methods/requests/requests.mjs +0 -210
- package/lib/models-BmZS-mc4.d.ts +0 -193
- package/lib/models-le7xaT4H.d.ts +0 -193
- package/lib/types/index.d.mts +0 -5
- package/lib/types/index.d.ts +0 -5
- package/lib/types/index.global.js +0 -19
- package/lib/types/index.js +0 -18
- package/lib/types/index.mjs +0 -0
- package/lib/types/params.d.mts +0 -946
- package/lib/types/params.d.ts +0 -946
- package/lib/types/params.global.js +0 -19
- package/lib/types/params.js +0 -18
- package/lib/types/params.mjs +0 -0
- package/lib/types/payloads.d.mts +0 -342
- package/lib/types/payloads.d.ts +0 -342
- package/lib/types/payloads.global.js +0 -19
- package/lib/types/payloads.js +0 -18
- package/lib/types/payloads.mjs +0 -0
- package/lib/types/translations.d.mts +0 -101
- package/lib/types/translations.d.ts +0 -101
- package/lib/types/translations.global.js +0 -19
- package/lib/types/translations.js +0 -18
- package/lib/types/translations.mjs +0 -0
- package/lib/types/utils/payloads.d.mts +0 -297
- package/lib/types/utils/payloads.d.ts +0 -297
- package/lib/types/utils/payloads.global.js +0 -19
- package/lib/types/utils/payloads.js +0 -18
- package/lib/types/utils/payloads.mjs +0 -0
- package/lib/utils/cookies.d.mts +0 -13
- package/lib/utils/cookies.d.ts +0 -13
- package/lib/utils/cookies.global.js +0 -261
- package/lib/utils/cookies.js +0 -190
- package/lib/utils/cookies.mjs +0 -148
- package/lib/utils/defaultMessageBox.d.mts +0 -5
- package/lib/utils/defaultMessageBox.d.ts +0 -5
- package/lib/utils/defaultMessageBox.global.js +0 -125
- package/lib/utils/defaultMessageBox.js +0 -130
- package/lib/utils/defaultMessageBox.mjs +0 -103
package/lib/index.mjs
CHANGED
|
@@ -249,7 +249,7 @@ var showMessage = (msg, isError) => __async(void 0, null, function* () {
|
|
|
249
249
|
return;
|
|
250
250
|
const messageTextBox = messageBox.querySelector("[data-ms-message-text]");
|
|
251
251
|
if (messageTextBox) {
|
|
252
|
-
messageTextBox.
|
|
252
|
+
messageTextBox.textContent = msg;
|
|
253
253
|
}
|
|
254
254
|
messageBox.style.display = "block";
|
|
255
255
|
const closeBtn = messageBox.querySelector("[data-ms-message-close]");
|
|
@@ -319,6 +319,7 @@ var hideLoader = (element) => {
|
|
|
319
319
|
(_a = document.querySelector("[data-ms-modal-loader]")) == null ? void 0 : _a.remove();
|
|
320
320
|
};
|
|
321
321
|
var modal = null;
|
|
322
|
+
var resolveModal;
|
|
322
323
|
var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, params = {}) {
|
|
323
324
|
const isInspector = type.toLowerCase() === "inspector";
|
|
324
325
|
const needsLoading = !prebuiltUILoaded;
|
|
@@ -333,7 +334,17 @@ var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, par
|
|
|
333
334
|
hideLoader();
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
|
-
|
|
337
|
+
if (modal) {
|
|
338
|
+
try {
|
|
339
|
+
modal.remove();
|
|
340
|
+
} catch (e) {
|
|
341
|
+
}
|
|
342
|
+
if (resolveModal) {
|
|
343
|
+
resolveModal({ type: "CLOSED" });
|
|
344
|
+
}
|
|
345
|
+
modal = null;
|
|
346
|
+
resolveModal = void 0;
|
|
347
|
+
}
|
|
337
348
|
const modalPromise = new Promise((resolve) => {
|
|
338
349
|
resolveModal = resolve;
|
|
339
350
|
});
|
|
@@ -350,6 +361,11 @@ var hideModal = () => {
|
|
|
350
361
|
modal == null ? void 0 : modal.remove();
|
|
351
362
|
} catch (e) {
|
|
352
363
|
}
|
|
364
|
+
if (resolveModal) {
|
|
365
|
+
resolveModal({ type: "CLOSED" });
|
|
366
|
+
}
|
|
367
|
+
modal = null;
|
|
368
|
+
resolveModal = void 0;
|
|
353
369
|
};
|
|
354
370
|
|
|
355
371
|
// src/utils/cookies.ts
|
|
@@ -410,10 +426,11 @@ var setMemberToken = (token, expires) => {
|
|
|
410
426
|
localStorage.setItem(memberAuthTokenName, token);
|
|
411
427
|
} else {
|
|
412
428
|
const domain = extractDomainFromHostname(window.location.hostname);
|
|
413
|
-
|
|
429
|
+
const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
|
|
430
|
+
Cookie.set(memberAuthTokenName, token, __spreadValues(__spreadValues({
|
|
414
431
|
expires: expires && Number(expires) || 14,
|
|
415
432
|
sameSite: "strict"
|
|
416
|
-
}, setCookieOnRootDomain && { domain }));
|
|
433
|
+
}, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
|
|
417
434
|
}
|
|
418
435
|
};
|
|
419
436
|
var removeMemberToken = () => {
|
|
@@ -421,14 +438,11 @@ var removeMemberToken = () => {
|
|
|
421
438
|
localStorage.removeItem(memberAuthTokenName);
|
|
422
439
|
}
|
|
423
440
|
const domain = extractDomainFromHostname(window.location.hostname);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
sameSite: "strict"
|
|
427
|
-
}, setCookieOnRootDomain && { domain }));
|
|
428
|
-
Cookie.set(memberAuthTokenName, "", {
|
|
441
|
+
const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
|
|
442
|
+
Cookie.set(memberAuthTokenName, "", __spreadValues(__spreadValues({
|
|
429
443
|
expires: -1,
|
|
430
444
|
sameSite: "strict"
|
|
431
|
-
});
|
|
445
|
+
}, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
|
|
432
446
|
};
|
|
433
447
|
var getMemberToken = () => {
|
|
434
448
|
if (localStorageAvailable) {
|
|
@@ -442,8 +456,13 @@ var setMemberTokenIfAvailable = () => {
|
|
|
442
456
|
if (typeof window !== "undefined") {
|
|
443
457
|
const urlParams = new URLSearchParams(window.location.search);
|
|
444
458
|
const memberToken = urlParams.get("memberToken");
|
|
445
|
-
if (memberToken)
|
|
459
|
+
if (memberToken) {
|
|
446
460
|
setMemberToken(memberToken);
|
|
461
|
+
urlParams.delete("memberToken");
|
|
462
|
+
const newSearch = urlParams.toString();
|
|
463
|
+
const newUrl = newSearch ? `${window.location.pathname}?${newSearch}${window.location.hash}` : `${window.location.pathname}${window.location.hash}`;
|
|
464
|
+
window.history.replaceState({}, "", newUrl);
|
|
465
|
+
}
|
|
447
466
|
}
|
|
448
467
|
};
|
|
449
468
|
var getSessionId = () => {
|
|
@@ -486,6 +505,11 @@ var createRequestHandler = ({
|
|
|
486
505
|
token,
|
|
487
506
|
customEndpoint
|
|
488
507
|
}) => {
|
|
508
|
+
if (!publicKey) {
|
|
509
|
+
throw new Error(
|
|
510
|
+
"Memberstack: publicKey is required. Pass your public key to memberstack.init({ publicKey: 'pk_...' })"
|
|
511
|
+
);
|
|
512
|
+
}
|
|
489
513
|
return {
|
|
490
514
|
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
491
515
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -503,7 +527,9 @@ var createRequestHandler = ({
|
|
|
503
527
|
method: data.method,
|
|
504
528
|
data: data.data,
|
|
505
529
|
url: formattedUrl,
|
|
506
|
-
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(
|
|
530
|
+
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), {
|
|
531
|
+
["X-API-Key" /* API_KEY */]: publicKey
|
|
532
|
+
}), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
507
533
|
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
508
534
|
}), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
|
|
509
535
|
["X-Session-ID" /* SESSION_ID */]: sessionToken
|
|
@@ -527,8 +553,12 @@ var createRequestHandler = ({
|
|
|
527
553
|
return res == null ? void 0 : res.data;
|
|
528
554
|
} catch (e) {
|
|
529
555
|
const error = e;
|
|
530
|
-
if (!error.response)
|
|
531
|
-
throw
|
|
556
|
+
if (!error.response) {
|
|
557
|
+
throw {
|
|
558
|
+
code: "network-error",
|
|
559
|
+
message: (error == null ? void 0 : error.message) || "Network request failed. Please check your internet connection."
|
|
560
|
+
};
|
|
561
|
+
}
|
|
532
562
|
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
533
563
|
}
|
|
534
564
|
}),
|
|
@@ -543,7 +573,9 @@ var createRequestHandler = ({
|
|
|
543
573
|
options == null ? void 0 : options.token
|
|
544
574
|
].find((x) => x);
|
|
545
575
|
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
546
|
-
const fetchHeaders = __spreadProps(__spreadValues(
|
|
576
|
+
const fetchHeaders = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), {
|
|
577
|
+
["X-API-Key" /* API_KEY */]: publicKey
|
|
578
|
+
}), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
547
579
|
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
|
|
548
580
|
"Content-Type": "application/json",
|
|
549
581
|
Referer: window.location.href
|
|
@@ -581,8 +613,13 @@ var createRequestHandler = ({
|
|
|
581
613
|
}
|
|
582
614
|
return result;
|
|
583
615
|
} catch (e) {
|
|
584
|
-
|
|
585
|
-
|
|
616
|
+
if (e && typeof e === "object" && "code" in e && "message" in e) {
|
|
617
|
+
throw e;
|
|
618
|
+
}
|
|
619
|
+
throw {
|
|
620
|
+
code: "network-error",
|
|
621
|
+
message: (e == null ? void 0 : e.message) || "Network request failed. Please check your internet connection."
|
|
622
|
+
};
|
|
586
623
|
}
|
|
587
624
|
})
|
|
588
625
|
};
|
|
@@ -607,8 +644,12 @@ var createObservable = () => {
|
|
|
607
644
|
};
|
|
608
645
|
var observable = createObservable();
|
|
609
646
|
var getPersistedMember = () => {
|
|
610
|
-
|
|
611
|
-
|
|
647
|
+
try {
|
|
648
|
+
const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
|
|
649
|
+
return stored ? JSON.parse(stored) : null;
|
|
650
|
+
} catch (e) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
612
653
|
};
|
|
613
654
|
var setPersistedMember = (member) => {
|
|
614
655
|
if (member) {
|
|
@@ -634,8 +675,9 @@ var unsetPersistedMember = () => {
|
|
|
634
675
|
removeSessionId();
|
|
635
676
|
observable.notify(null);
|
|
636
677
|
};
|
|
678
|
+
var nextSubscriberId = 0;
|
|
637
679
|
var onAuthChange = (cb) => {
|
|
638
|
-
const id =
|
|
680
|
+
const id = nextSubscriberId++;
|
|
639
681
|
observable.subscribe(id, cb);
|
|
640
682
|
return {
|
|
641
683
|
unsubscribe: () => observable.unsubscribe(id)
|
|
@@ -799,6 +841,8 @@ var initRequest = ({
|
|
|
799
841
|
* window.location.href = '/goodbye';
|
|
800
842
|
* }
|
|
801
843
|
* ```
|
|
844
|
+
*
|
|
845
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
802
846
|
*/
|
|
803
847
|
deleteMember() {
|
|
804
848
|
return __async(this, null, function* () {
|
|
@@ -810,6 +854,15 @@ var initRequest = ({
|
|
|
810
854
|
return data;
|
|
811
855
|
});
|
|
812
856
|
},
|
|
857
|
+
/**
|
|
858
|
+
* Sends a typing indicator to a comments channel.
|
|
859
|
+
* Used internally to show when a member is actively composing a post.
|
|
860
|
+
*
|
|
861
|
+
* @internal
|
|
862
|
+
* @param params - The typing indicator parameters
|
|
863
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
864
|
+
* @returns Promise that resolves when the typing indicator is sent
|
|
865
|
+
*/
|
|
813
866
|
postIsTyping(params) {
|
|
814
867
|
return __async(this, null, function* () {
|
|
815
868
|
return sendRequest({
|
|
@@ -821,6 +874,15 @@ var initRequest = ({
|
|
|
821
874
|
});
|
|
822
875
|
});
|
|
823
876
|
},
|
|
877
|
+
/**
|
|
878
|
+
* Retrieves information about a comments channel.
|
|
879
|
+
* Returns channel metadata and configuration.
|
|
880
|
+
*
|
|
881
|
+
* @internal
|
|
882
|
+
* @param params - The channel info parameters
|
|
883
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
884
|
+
* @returns Promise resolving to the channel information
|
|
885
|
+
*/
|
|
824
886
|
getChannelInfo(params) {
|
|
825
887
|
return __async(this, null, function* () {
|
|
826
888
|
const queryParams = new URLSearchParams({
|
|
@@ -832,6 +894,16 @@ var initRequest = ({
|
|
|
832
894
|
});
|
|
833
895
|
});
|
|
834
896
|
},
|
|
897
|
+
/**
|
|
898
|
+
* Manages a member's notification subscription to a comments channel.
|
|
899
|
+
* Allows members to subscribe or unsubscribe from channel notifications.
|
|
900
|
+
*
|
|
901
|
+
* @internal
|
|
902
|
+
* @param params - The subscription parameters
|
|
903
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
904
|
+
* @param params.action - The subscription action: 'NONE' to unsubscribe, 'THREADS_ONLY' to receive thread notifications
|
|
905
|
+
* @returns Promise that resolves when the subscription is updated
|
|
906
|
+
*/
|
|
835
907
|
subscribeToChannel(params) {
|
|
836
908
|
return __async(this, null, function* () {
|
|
837
909
|
return sendRequest({
|
|
@@ -844,6 +916,27 @@ var initRequest = ({
|
|
|
844
916
|
});
|
|
845
917
|
});
|
|
846
918
|
},
|
|
919
|
+
/**
|
|
920
|
+
* Retrieves posts from a comments channel.
|
|
921
|
+
* Use this to display comments or discussion threads on your site.
|
|
922
|
+
*
|
|
923
|
+
* @param params - Query parameters
|
|
924
|
+
* @param params.channelKey - The key identifying the channel to fetch posts from
|
|
925
|
+
* @param params.order - Sort order: 'newest' or 'oldest'
|
|
926
|
+
* @param params.after - Cursor for pagination (post ID to start after)
|
|
927
|
+
* @param params.limit - Maximum number of posts to return
|
|
928
|
+
* @returns Promise resolving to an array of posts
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* const { data } = await memberstack.getPosts({
|
|
933
|
+
* channelKey: 'blog-comments',
|
|
934
|
+
* order: 'newest',
|
|
935
|
+
* limit: 20
|
|
936
|
+
* });
|
|
937
|
+
* data.posts.forEach(post => console.log(post.content));
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
847
940
|
getPosts(params) {
|
|
848
941
|
return __async(this, null, function* () {
|
|
849
942
|
const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
|
|
@@ -861,6 +954,26 @@ var initRequest = ({
|
|
|
861
954
|
});
|
|
862
955
|
});
|
|
863
956
|
},
|
|
957
|
+
/**
|
|
958
|
+
* Retrieves threads (replies) for a specific post.
|
|
959
|
+
*
|
|
960
|
+
* @param params - Query parameters
|
|
961
|
+
* @param params.postId - The ID of the parent post
|
|
962
|
+
* @param params.order - Sort order: 'newest' or 'oldest'
|
|
963
|
+
* @param params.after - Cursor for pagination (thread ID to start after)
|
|
964
|
+
* @param params.limit - Maximum number of threads to return
|
|
965
|
+
* @returns Promise resolving to an array of threads
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```typescript
|
|
969
|
+
* const { data } = await memberstack.getThreads({
|
|
970
|
+
* postId: 'post_abc123',
|
|
971
|
+
* order: 'oldest',
|
|
972
|
+
* limit: 50
|
|
973
|
+
* });
|
|
974
|
+
* data.threads.forEach(thread => console.log(thread.content));
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
864
977
|
getThreads(params) {
|
|
865
978
|
return __async(this, null, function* () {
|
|
866
979
|
const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
|
|
@@ -878,6 +991,23 @@ var initRequest = ({
|
|
|
878
991
|
});
|
|
879
992
|
});
|
|
880
993
|
},
|
|
994
|
+
/**
|
|
995
|
+
* Creates a new post in a comments channel.
|
|
996
|
+
*
|
|
997
|
+
* @param params - Post data
|
|
998
|
+
* @param params.channelKey - The key of the channel to post in
|
|
999
|
+
* @param params.content - The content of the post (supports markdown)
|
|
1000
|
+
* @returns Promise resolving to the created post
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* const { data: post } = await memberstack.createPost({
|
|
1005
|
+
* channelKey: 'blog-comments',
|
|
1006
|
+
* content: 'Great article! Thanks for sharing.'
|
|
1007
|
+
* });
|
|
1008
|
+
* console.log('Posted:', post.id);
|
|
1009
|
+
* ```
|
|
1010
|
+
*/
|
|
881
1011
|
createPost(params) {
|
|
882
1012
|
return __async(this, null, function* () {
|
|
883
1013
|
return sendRequest({
|
|
@@ -891,6 +1021,23 @@ var initRequest = ({
|
|
|
891
1021
|
});
|
|
892
1022
|
});
|
|
893
1023
|
},
|
|
1024
|
+
/**
|
|
1025
|
+
* Updates an existing post's content.
|
|
1026
|
+
* Only the post author can update their post.
|
|
1027
|
+
*
|
|
1028
|
+
* @param params - Update data
|
|
1029
|
+
* @param params.postId - The ID of the post to update
|
|
1030
|
+
* @param params.content - The new content for the post
|
|
1031
|
+
* @returns Promise resolving to the updated post
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* const { data: post } = await memberstack.updatePost({
|
|
1036
|
+
* postId: 'post_abc123',
|
|
1037
|
+
* content: 'Updated: Great article with corrections!'
|
|
1038
|
+
* });
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
894
1041
|
updatePost(params) {
|
|
895
1042
|
return __async(this, null, function* () {
|
|
896
1043
|
return sendRequest({
|
|
@@ -902,6 +1049,29 @@ var initRequest = ({
|
|
|
902
1049
|
});
|
|
903
1050
|
});
|
|
904
1051
|
},
|
|
1052
|
+
/**
|
|
1053
|
+
* Votes on a post (upvote, downvote, or remove vote).
|
|
1054
|
+
*
|
|
1055
|
+
* @param params - Vote data
|
|
1056
|
+
* @param params.postId - The ID of the post to vote on
|
|
1057
|
+
* @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
|
|
1058
|
+
* @returns Promise resolving when the vote is recorded
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* // Upvote a post
|
|
1063
|
+
* await memberstack.postVote({
|
|
1064
|
+
* postId: 'post_abc123',
|
|
1065
|
+
* vote: 'UP'
|
|
1066
|
+
* });
|
|
1067
|
+
*
|
|
1068
|
+
* // Remove vote
|
|
1069
|
+
* await memberstack.postVote({
|
|
1070
|
+
* postId: 'post_abc123',
|
|
1071
|
+
* vote: 'NONE'
|
|
1072
|
+
* });
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
905
1075
|
postVote(params) {
|
|
906
1076
|
return __async(this, null, function* () {
|
|
907
1077
|
return sendRequest({
|
|
@@ -913,6 +1083,21 @@ var initRequest = ({
|
|
|
913
1083
|
});
|
|
914
1084
|
});
|
|
915
1085
|
},
|
|
1086
|
+
/**
|
|
1087
|
+
* Deletes a post.
|
|
1088
|
+
* Only the post author can delete their post.
|
|
1089
|
+
*
|
|
1090
|
+
* @param params - Delete parameters
|
|
1091
|
+
* @param params.postId - The ID of the post to delete
|
|
1092
|
+
* @returns Promise resolving when the post is deleted
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* await memberstack.deletePost({
|
|
1097
|
+
* postId: 'post_abc123'
|
|
1098
|
+
* });
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
916
1101
|
deletePost(params) {
|
|
917
1102
|
return __async(this, null, function* () {
|
|
918
1103
|
return sendRequest({
|
|
@@ -921,6 +1106,22 @@ var initRequest = ({
|
|
|
921
1106
|
});
|
|
922
1107
|
});
|
|
923
1108
|
},
|
|
1109
|
+
/**
|
|
1110
|
+
* Creates a reply thread on a post.
|
|
1111
|
+
*
|
|
1112
|
+
* @param params - Thread data
|
|
1113
|
+
* @param params.postId - The ID of the post to reply to
|
|
1114
|
+
* @param params.content - The content of the reply (supports markdown)
|
|
1115
|
+
* @returns Promise resolving to the created thread
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```typescript
|
|
1119
|
+
* const { data: thread } = await memberstack.createThread({
|
|
1120
|
+
* postId: 'post_abc123',
|
|
1121
|
+
* content: 'I agree with this point!'
|
|
1122
|
+
* });
|
|
1123
|
+
* ```
|
|
1124
|
+
*/
|
|
924
1125
|
createThread(params) {
|
|
925
1126
|
return __async(this, null, function* () {
|
|
926
1127
|
return sendRequest({
|
|
@@ -933,6 +1134,23 @@ var initRequest = ({
|
|
|
933
1134
|
});
|
|
934
1135
|
});
|
|
935
1136
|
},
|
|
1137
|
+
/**
|
|
1138
|
+
* Updates an existing thread's content.
|
|
1139
|
+
* Only the thread author can update their thread.
|
|
1140
|
+
*
|
|
1141
|
+
* @param params - Update data
|
|
1142
|
+
* @param params.threadId - The ID of the thread to update
|
|
1143
|
+
* @param params.content - The new content for the thread
|
|
1144
|
+
* @returns Promise resolving to the updated thread
|
|
1145
|
+
*
|
|
1146
|
+
* @example
|
|
1147
|
+
* ```typescript
|
|
1148
|
+
* const { data: thread } = await memberstack.updateThread({
|
|
1149
|
+
* threadId: 'thread_xyz789',
|
|
1150
|
+
* content: 'Updated reply with more details.'
|
|
1151
|
+
* });
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
936
1154
|
updateThread(params) {
|
|
937
1155
|
return __async(this, null, function* () {
|
|
938
1156
|
return sendRequest({
|
|
@@ -944,7 +1162,22 @@ var initRequest = ({
|
|
|
944
1162
|
});
|
|
945
1163
|
});
|
|
946
1164
|
},
|
|
947
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Votes on a thread (upvote, downvote, or remove vote).
|
|
1167
|
+
*
|
|
1168
|
+
* @param params - Vote data
|
|
1169
|
+
* @param params.threadId - The ID of the thread to vote on
|
|
1170
|
+
* @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
|
|
1171
|
+
* @returns Promise resolving when the vote is recorded
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* await memberstack.threadVote({
|
|
1176
|
+
* threadId: 'thread_xyz789',
|
|
1177
|
+
* vote: 'UP'
|
|
1178
|
+
* });
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
948
1181
|
threadVote(params) {
|
|
949
1182
|
return __async(this, null, function* () {
|
|
950
1183
|
return sendRequest({
|
|
@@ -956,6 +1189,21 @@ var initRequest = ({
|
|
|
956
1189
|
});
|
|
957
1190
|
});
|
|
958
1191
|
},
|
|
1192
|
+
/**
|
|
1193
|
+
* Deletes a thread.
|
|
1194
|
+
* Only the thread author can delete their thread.
|
|
1195
|
+
*
|
|
1196
|
+
* @param params - Delete parameters
|
|
1197
|
+
* @param params.threadId - The ID of the thread to delete
|
|
1198
|
+
* @returns Promise resolving when the thread is deleted
|
|
1199
|
+
*
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```typescript
|
|
1202
|
+
* await memberstack.deleteThread({
|
|
1203
|
+
* threadId: 'thread_xyz789'
|
|
1204
|
+
* });
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
959
1207
|
deleteThread(params) {
|
|
960
1208
|
return __async(this, null, function* () {
|
|
961
1209
|
return sendRequest({
|
|
@@ -977,8 +1225,10 @@ var initRequest = ({
|
|
|
977
1225
|
* const { data: content } = await memberstack.getSecureContent({
|
|
978
1226
|
* contentId: 'cnt_abc123'
|
|
979
1227
|
* });
|
|
980
|
-
* document.getElementById('premium-content').innerHTML = content.
|
|
1228
|
+
* document.getElementById('premium-content').innerHTML = content.content;
|
|
981
1229
|
* ```
|
|
1230
|
+
*
|
|
1231
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Protected Content Documentation}
|
|
982
1232
|
*/
|
|
983
1233
|
getSecureContent(params) {
|
|
984
1234
|
return __async(this, null, function* () {
|
|
@@ -1019,6 +1269,8 @@ var initRequest = ({
|
|
|
1019
1269
|
* plans: [{ planId: 'pln_free' }]
|
|
1020
1270
|
* });
|
|
1021
1271
|
* ```
|
|
1272
|
+
*
|
|
1273
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1022
1274
|
*/
|
|
1023
1275
|
signupWithProvider(params) {
|
|
1024
1276
|
return __async(this, null, function* () {
|
|
@@ -1069,6 +1321,8 @@ var initRequest = ({
|
|
|
1069
1321
|
* allowSignup: true
|
|
1070
1322
|
* });
|
|
1071
1323
|
* ```
|
|
1324
|
+
*
|
|
1325
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1072
1326
|
*/
|
|
1073
1327
|
loginWithProvider(params) {
|
|
1074
1328
|
return __async(this, null, function* () {
|
|
@@ -1101,6 +1355,8 @@ var initRequest = ({
|
|
|
1101
1355
|
* });
|
|
1102
1356
|
* // Member can now log in with either email/password or Google
|
|
1103
1357
|
* ```
|
|
1358
|
+
*
|
|
1359
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1104
1360
|
*/
|
|
1105
1361
|
connectProvider(params) {
|
|
1106
1362
|
return __async(this, null, function* () {
|
|
@@ -1132,6 +1388,8 @@ var initRequest = ({
|
|
|
1132
1388
|
* });
|
|
1133
1389
|
* // Member must now use email/password or another connected provider
|
|
1134
1390
|
* ```
|
|
1391
|
+
*
|
|
1392
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1135
1393
|
*/
|
|
1136
1394
|
disconnectProvider(params) {
|
|
1137
1395
|
return __async(this, null, function* () {
|
|
@@ -1144,6 +1402,16 @@ var initRequest = ({
|
|
|
1144
1402
|
});
|
|
1145
1403
|
});
|
|
1146
1404
|
},
|
|
1405
|
+
/**
|
|
1406
|
+
* Retrieves both app configuration and current member data in a single request.
|
|
1407
|
+
* Used internally for initial page load to efficiently fetch all required data.
|
|
1408
|
+
* Also handles session tracking and conversion data.
|
|
1409
|
+
*
|
|
1410
|
+
* @internal
|
|
1411
|
+
* @param params - Optional parameters
|
|
1412
|
+
* @param params.trackPageView - Whether to track this as a page view for analytics (default: false)
|
|
1413
|
+
* @returns Promise resolving to both app and member data
|
|
1414
|
+
*/
|
|
1147
1415
|
getAppAndMember(params) {
|
|
1148
1416
|
return __async(this, null, function* () {
|
|
1149
1417
|
var _a2, _b;
|
|
@@ -1152,7 +1420,6 @@ var initRequest = ({
|
|
|
1152
1420
|
url: `/app-member`,
|
|
1153
1421
|
data: {
|
|
1154
1422
|
data: {
|
|
1155
|
-
// @ts-ignore
|
|
1156
1423
|
includeSSOText: window == null ? void 0 : window.ssoUI,
|
|
1157
1424
|
trackPageView: params == null ? void 0 : params.trackPageView,
|
|
1158
1425
|
sessionData: __spreadValues({}, getConversionData())
|
|
@@ -1181,12 +1448,14 @@ var initRequest = ({
|
|
|
1181
1448
|
* console.log('App name:', app.name);
|
|
1182
1449
|
* console.log('OAuth providers:', app.authProviders);
|
|
1183
1450
|
* ```
|
|
1451
|
+
*
|
|
1452
|
+
* @see {@link https://developers.memberstack.com/dom-package/quick-start | Quick Start Documentation}
|
|
1184
1453
|
*/
|
|
1185
1454
|
getApp() {
|
|
1186
1455
|
return __async(this, null, function* () {
|
|
1456
|
+
var _a2;
|
|
1187
1457
|
const queryParams = new URLSearchParams({
|
|
1188
|
-
|
|
1189
|
-
includeSSOText: window == null ? void 0 : window.ssoUI
|
|
1458
|
+
includeSSOText: String((_a2 = window == null ? void 0 : window.ssoUI) != null ? _a2 : "")
|
|
1190
1459
|
});
|
|
1191
1460
|
return sendRequest({
|
|
1192
1461
|
method: "GET" /* GET */,
|
|
@@ -1216,6 +1485,8 @@ var initRequest = ({
|
|
|
1216
1485
|
* console.error('Login failed:', error.message);
|
|
1217
1486
|
* }
|
|
1218
1487
|
* ```
|
|
1488
|
+
*
|
|
1489
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1219
1490
|
*/
|
|
1220
1491
|
loginMemberEmailPassword(params, options) {
|
|
1221
1492
|
return __async(this, null, function* () {
|
|
@@ -1253,6 +1524,8 @@ var initRequest = ({
|
|
|
1253
1524
|
*
|
|
1254
1525
|
* // Step 2: Complete login with the code (see loginMemberPasswordless)
|
|
1255
1526
|
* ```
|
|
1527
|
+
*
|
|
1528
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1256
1529
|
*/
|
|
1257
1530
|
sendMemberLoginPasswordlessEmail(params, options) {
|
|
1258
1531
|
return __async(this, null, function* () {
|
|
@@ -1282,6 +1555,8 @@ var initRequest = ({
|
|
|
1282
1555
|
*
|
|
1283
1556
|
* // Step 2: Complete signup with the code (see signupMemberPasswordless)
|
|
1284
1557
|
* ```
|
|
1558
|
+
*
|
|
1559
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1285
1560
|
*/
|
|
1286
1561
|
sendMemberSignupPasswordlessEmail(params, options) {
|
|
1287
1562
|
return __async(this, null, function* () {
|
|
@@ -1313,6 +1588,8 @@ var initRequest = ({
|
|
|
1313
1588
|
* });
|
|
1314
1589
|
* console.log('Logged in:', data.member.auth.email);
|
|
1315
1590
|
* ```
|
|
1591
|
+
*
|
|
1592
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1316
1593
|
*/
|
|
1317
1594
|
loginMemberPasswordless(params, options) {
|
|
1318
1595
|
return __async(this, null, function* () {
|
|
@@ -1347,6 +1624,8 @@ var initRequest = ({
|
|
|
1347
1624
|
* console.log('Plan:', plan.name);
|
|
1348
1625
|
* console.log('Prices:', plan.prices);
|
|
1349
1626
|
* ```
|
|
1627
|
+
*
|
|
1628
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1350
1629
|
*/
|
|
1351
1630
|
getPlan(params) {
|
|
1352
1631
|
return __async(this, null, function* () {
|
|
@@ -1385,6 +1664,8 @@ var initRequest = ({
|
|
|
1385
1664
|
* </div>
|
|
1386
1665
|
* `).join('');
|
|
1387
1666
|
* ```
|
|
1667
|
+
*
|
|
1668
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1388
1669
|
*/
|
|
1389
1670
|
getPlans() {
|
|
1390
1671
|
return __async(this, null, function* () {
|
|
@@ -1409,7 +1690,7 @@ var initRequest = ({
|
|
|
1409
1690
|
*
|
|
1410
1691
|
* groups.forEach(group => {
|
|
1411
1692
|
* console.log('Group:', group.name);
|
|
1412
|
-
* console.log('Required plans:', group.
|
|
1693
|
+
* console.log('Required plans:', group.plans.map(p => p.id));
|
|
1413
1694
|
* console.log('URLs:', group.urls);
|
|
1414
1695
|
* });
|
|
1415
1696
|
* ```
|
|
@@ -1456,6 +1737,8 @@ var initRequest = ({
|
|
|
1456
1737
|
* const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
|
|
1457
1738
|
* }
|
|
1458
1739
|
* ```
|
|
1740
|
+
*
|
|
1741
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1459
1742
|
*/
|
|
1460
1743
|
getCurrentMember(options) {
|
|
1461
1744
|
return __async(this, null, function* () {
|
|
@@ -1494,6 +1777,8 @@ var initRequest = ({
|
|
|
1494
1777
|
* console.log('Preferences:', json.preferences);
|
|
1495
1778
|
* console.log('Last visited:', json.lastVisitedPage);
|
|
1496
1779
|
* ```
|
|
1780
|
+
*
|
|
1781
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
|
|
1497
1782
|
*/
|
|
1498
1783
|
getMemberJSON(options) {
|
|
1499
1784
|
return __async(this, null, function* () {
|
|
@@ -1506,7 +1791,7 @@ var initRequest = ({
|
|
|
1506
1791
|
},
|
|
1507
1792
|
/**
|
|
1508
1793
|
* Updates the current member's JSON data store.
|
|
1509
|
-
* You can store any JSON-serializable data.
|
|
1794
|
+
* You can store any JSON-serializable data. This completely replaces the existing JSON.
|
|
1510
1795
|
*
|
|
1511
1796
|
* @param params - JSON data to store
|
|
1512
1797
|
* @param params.json - Object containing the data to store
|
|
@@ -1532,6 +1817,8 @@ var initRequest = ({
|
|
|
1532
1817
|
* }
|
|
1533
1818
|
* });
|
|
1534
1819
|
* ```
|
|
1820
|
+
*
|
|
1821
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
|
|
1535
1822
|
*/
|
|
1536
1823
|
updateMemberJSON(params, options) {
|
|
1537
1824
|
return __async(this, null, function* () {
|
|
@@ -1560,6 +1847,8 @@ var initRequest = ({
|
|
|
1560
1847
|
* });
|
|
1561
1848
|
* console.log('Plan added, redirect:', data.redirect);
|
|
1562
1849
|
* ```
|
|
1850
|
+
*
|
|
1851
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1563
1852
|
*/
|
|
1564
1853
|
addPlan(params, options) {
|
|
1565
1854
|
return __async(this, null, function* () {
|
|
@@ -1615,6 +1904,8 @@ var initRequest = ({
|
|
|
1615
1904
|
* cancelUrl: '/pricing'
|
|
1616
1905
|
* });
|
|
1617
1906
|
* ```
|
|
1907
|
+
*
|
|
1908
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1618
1909
|
*/
|
|
1619
1910
|
purchasePlansWithCheckout(params, options) {
|
|
1620
1911
|
return __async(this, null, function* () {
|
|
@@ -1683,6 +1974,8 @@ var initRequest = ({
|
|
|
1683
1974
|
* });
|
|
1684
1975
|
* console.log('Portal URL:', data.url);
|
|
1685
1976
|
* ```
|
|
1977
|
+
*
|
|
1978
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1686
1979
|
*/
|
|
1687
1980
|
launchStripeCustomerPortal(params, options) {
|
|
1688
1981
|
return __async(this, null, function* () {
|
|
@@ -1734,6 +2027,8 @@ var initRequest = ({
|
|
|
1734
2027
|
* });
|
|
1735
2028
|
* // Plan removed/subscription cancelled
|
|
1736
2029
|
* ```
|
|
2030
|
+
*
|
|
2031
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1737
2032
|
*/
|
|
1738
2033
|
removePlan(params, options) {
|
|
1739
2034
|
return __async(this, null, function* () {
|
|
@@ -1775,6 +2070,8 @@ var initRequest = ({
|
|
|
1775
2070
|
* }
|
|
1776
2071
|
* });
|
|
1777
2072
|
* ```
|
|
2073
|
+
*
|
|
2074
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1778
2075
|
*/
|
|
1779
2076
|
updateMember(params, options) {
|
|
1780
2077
|
return __async(this, null, function* () {
|
|
@@ -1812,6 +2109,8 @@ var initRequest = ({
|
|
|
1812
2109
|
* newPassword: 'newSecurePassword123'
|
|
1813
2110
|
* });
|
|
1814
2111
|
* ```
|
|
2112
|
+
*
|
|
2113
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1815
2114
|
*/
|
|
1816
2115
|
updateMemberAuth(params, options) {
|
|
1817
2116
|
return __async(this, null, function* () {
|
|
@@ -1839,6 +2138,8 @@ var initRequest = ({
|
|
|
1839
2138
|
* });
|
|
1840
2139
|
* // Member can now log in with email/password
|
|
1841
2140
|
* ```
|
|
2141
|
+
*
|
|
2142
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1842
2143
|
*/
|
|
1843
2144
|
setPassword(params, options) {
|
|
1844
2145
|
return __async(this, null, function* () {
|
|
@@ -1852,6 +2153,33 @@ var initRequest = ({
|
|
|
1852
2153
|
});
|
|
1853
2154
|
});
|
|
1854
2155
|
},
|
|
2156
|
+
/**
|
|
2157
|
+
* Completes passwordless signup using the code sent via email.
|
|
2158
|
+
* Creates a new member account without requiring a password.
|
|
2159
|
+
*
|
|
2160
|
+
* @param params - Signup details
|
|
2161
|
+
* @param params.email - The new member's email address
|
|
2162
|
+
* @param params.passwordlessToken - The one-time code from the signup email
|
|
2163
|
+
* @param params.customFields - Optional custom field values defined in your Memberstack dashboard
|
|
2164
|
+
* @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
|
|
2165
|
+
* @param params.metaData - Optional metadata to store with the member
|
|
2166
|
+
* @returns Promise resolving to the new member data and tokens
|
|
2167
|
+
* @throws When the code is invalid, expired, or email is already in use
|
|
2168
|
+
*
|
|
2169
|
+
* @example Complete passwordless signup flow
|
|
2170
|
+
* ```typescript
|
|
2171
|
+
* // Step 1: Send signup code (see sendMemberSignupPasswordlessEmail)
|
|
2172
|
+
* // Step 2: User enters code, complete signup:
|
|
2173
|
+
* const { data } = await memberstack.signupMemberPasswordless({
|
|
2174
|
+
* email: 'newuser@example.com',
|
|
2175
|
+
* passwordlessToken: '123456',
|
|
2176
|
+
* customFields: { firstName: 'Jane' }
|
|
2177
|
+
* });
|
|
2178
|
+
* console.log('Welcome!', data.member.id);
|
|
2179
|
+
* ```
|
|
2180
|
+
*
|
|
2181
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
2182
|
+
*/
|
|
1855
2183
|
signupMemberPasswordless(params, options) {
|
|
1856
2184
|
return __async(this, null, function* () {
|
|
1857
2185
|
var _a2, _b, _c;
|
|
@@ -1872,9 +2200,7 @@ var initRequest = ({
|
|
|
1872
2200
|
options
|
|
1873
2201
|
}), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
|
|
1874
2202
|
rewardfulData: {
|
|
1875
|
-
// @ts-ignore
|
|
1876
2203
|
referral: window.Rewardful.referral,
|
|
1877
|
-
// @ts-ignore
|
|
1878
2204
|
coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
|
|
1879
2205
|
}
|
|
1880
2206
|
})
|
|
@@ -1921,6 +2247,8 @@ var initRequest = ({
|
|
|
1921
2247
|
* plans: [{ planId: 'pln_free_tier' }]
|
|
1922
2248
|
* });
|
|
1923
2249
|
* ```
|
|
2250
|
+
*
|
|
2251
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Signup Documentation}
|
|
1924
2252
|
*/
|
|
1925
2253
|
signupMemberEmailPassword(params, options) {
|
|
1926
2254
|
return __async(this, null, function* () {
|
|
@@ -1944,9 +2272,7 @@ var initRequest = ({
|
|
|
1944
2272
|
options
|
|
1945
2273
|
}), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
|
|
1946
2274
|
rewardfulData: {
|
|
1947
|
-
// @ts-ignore
|
|
1948
2275
|
referral: window.Rewardful.referral,
|
|
1949
|
-
// @ts-ignore
|
|
1950
2276
|
coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
|
|
1951
2277
|
}
|
|
1952
2278
|
})
|
|
@@ -1957,6 +2283,25 @@ var initRequest = ({
|
|
|
1957
2283
|
return data;
|
|
1958
2284
|
});
|
|
1959
2285
|
},
|
|
2286
|
+
/**
|
|
2287
|
+
* Joins a team using an invite token.
|
|
2288
|
+
* The invite token is typically sent by a team admin via email.
|
|
2289
|
+
*
|
|
2290
|
+
* @param params - Join parameters
|
|
2291
|
+
* @param params.inviteToken - The invite token received from the team admin
|
|
2292
|
+
* @returns Promise resolving when the member has joined the team
|
|
2293
|
+
*
|
|
2294
|
+
* @example
|
|
2295
|
+
* ```typescript
|
|
2296
|
+
* // Extract token from URL (e.g., /join?token=abc123)
|
|
2297
|
+
* const token = new URLSearchParams(window.location.search).get('token');
|
|
2298
|
+
*
|
|
2299
|
+
* await memberstack.joinTeam({
|
|
2300
|
+
* inviteToken: token
|
|
2301
|
+
* });
|
|
2302
|
+
* console.log('Successfully joined the team!');
|
|
2303
|
+
* ```
|
|
2304
|
+
*/
|
|
1960
2305
|
joinTeam(params, options) {
|
|
1961
2306
|
return __async(this, null, function* () {
|
|
1962
2307
|
return sendRequest({
|
|
@@ -1969,6 +2314,21 @@ var initRequest = ({
|
|
|
1969
2314
|
});
|
|
1970
2315
|
});
|
|
1971
2316
|
},
|
|
2317
|
+
/**
|
|
2318
|
+
* Retrieves information about a team the current member belongs to.
|
|
2319
|
+
*
|
|
2320
|
+
* @param params - Team parameters
|
|
2321
|
+
* @param params.teamId - The ID of the team to retrieve
|
|
2322
|
+
* @returns Promise resolving to the team details
|
|
2323
|
+
*
|
|
2324
|
+
* @example
|
|
2325
|
+
* ```typescript
|
|
2326
|
+
* const team = await memberstack.getTeam({
|
|
2327
|
+
* teamId: 'team_abc123'
|
|
2328
|
+
* });
|
|
2329
|
+
* console.log('Team members:', team);
|
|
2330
|
+
* ```
|
|
2331
|
+
*/
|
|
1972
2332
|
getTeam(params, options) {
|
|
1973
2333
|
return __async(this, null, function* () {
|
|
1974
2334
|
return sendRequest({
|
|
@@ -1978,6 +2338,24 @@ var initRequest = ({
|
|
|
1978
2338
|
});
|
|
1979
2339
|
});
|
|
1980
2340
|
},
|
|
2341
|
+
/**
|
|
2342
|
+
* Removes a member from a team.
|
|
2343
|
+
* Only team admins can remove other members.
|
|
2344
|
+
*
|
|
2345
|
+
* @param params - Removal parameters
|
|
2346
|
+
* @param params.teamId - The ID of the team
|
|
2347
|
+
* @param params.memberId - The ID of the member to remove
|
|
2348
|
+
* @returns Promise resolving when the member has been removed
|
|
2349
|
+
*
|
|
2350
|
+
* @example
|
|
2351
|
+
* ```typescript
|
|
2352
|
+
* await memberstack.removeMemberFromTeam({
|
|
2353
|
+
* teamId: 'team_abc123',
|
|
2354
|
+
* memberId: 'mem_xyz789'
|
|
2355
|
+
* });
|
|
2356
|
+
* console.log('Member removed from team');
|
|
2357
|
+
* ```
|
|
2358
|
+
*/
|
|
1981
2359
|
removeMemberFromTeam(params, options) {
|
|
1982
2360
|
return __async(this, null, function* () {
|
|
1983
2361
|
return sendRequest({
|
|
@@ -1991,6 +2369,23 @@ var initRequest = ({
|
|
|
1991
2369
|
});
|
|
1992
2370
|
});
|
|
1993
2371
|
},
|
|
2372
|
+
/**
|
|
2373
|
+
* Generates an invite token for a team.
|
|
2374
|
+
* The token can be shared with users to invite them to join the team.
|
|
2375
|
+
*
|
|
2376
|
+
* @param params - Token parameters
|
|
2377
|
+
* @param params.teamId - The ID of the team to generate an invite for
|
|
2378
|
+
* @returns Promise resolving to the generated invite token
|
|
2379
|
+
*
|
|
2380
|
+
* @example
|
|
2381
|
+
* ```typescript
|
|
2382
|
+
* const invite = await memberstack.generateInviteToken({
|
|
2383
|
+
* teamId: 'team_abc123'
|
|
2384
|
+
* });
|
|
2385
|
+
* // Share the invite link with new team members
|
|
2386
|
+
* const inviteUrl = `${window.location.origin}/join?token=${invite.token}`;
|
|
2387
|
+
* ```
|
|
2388
|
+
*/
|
|
1994
2389
|
generateInviteToken(params, options) {
|
|
1995
2390
|
return __async(this, null, function* () {
|
|
1996
2391
|
return sendRequest({
|
|
@@ -2004,12 +2399,12 @@ var initRequest = ({
|
|
|
2004
2399
|
});
|
|
2005
2400
|
},
|
|
2006
2401
|
/**
|
|
2007
|
-
*
|
|
2008
|
-
*
|
|
2402
|
+
* Updates or removes the current member's profile image.
|
|
2403
|
+
* Pass a File to upload a new image, or null to remove the existing image.
|
|
2009
2404
|
*
|
|
2010
2405
|
* @param params - Image parameters
|
|
2011
|
-
* @param params.profileImage - The image file to upload
|
|
2012
|
-
* @returns Promise resolving to the new profile image URL
|
|
2406
|
+
* @param params.profileImage - The image file to upload, or null to remove
|
|
2407
|
+
* @returns Promise resolving to the new profile image URL (or null if removed)
|
|
2013
2408
|
*
|
|
2014
2409
|
* @example Upload from file input
|
|
2015
2410
|
* ```typescript
|
|
@@ -2021,11 +2416,24 @@ var initRequest = ({
|
|
|
2021
2416
|
* });
|
|
2022
2417
|
* console.log('New image URL:', data.profileImage);
|
|
2023
2418
|
* ```
|
|
2419
|
+
*
|
|
2420
|
+
* @example Remove profile image
|
|
2421
|
+
* ```typescript
|
|
2422
|
+
* const { data } = await memberstack.updateMemberProfileImage({
|
|
2423
|
+
* profileImage: null
|
|
2424
|
+
* });
|
|
2425
|
+
* console.log('Image removed:', data.profileImage === null);
|
|
2426
|
+
* ```
|
|
2427
|
+
*
|
|
2428
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
2024
2429
|
*/
|
|
2025
2430
|
updateMemberProfileImage(params) {
|
|
2026
2431
|
return __async(this, null, function* () {
|
|
2027
|
-
if (
|
|
2028
|
-
|
|
2432
|
+
if (params.profileImage === null) {
|
|
2433
|
+
return sendRequest({
|
|
2434
|
+
method: "DELETE" /* DELETE */,
|
|
2435
|
+
url: `/member/profile-image`
|
|
2436
|
+
});
|
|
2029
2437
|
}
|
|
2030
2438
|
const formData = new FormData();
|
|
2031
2439
|
formData.append("profileImage", params.profileImage);
|
|
@@ -2037,6 +2445,28 @@ var initRequest = ({
|
|
|
2037
2445
|
});
|
|
2038
2446
|
});
|
|
2039
2447
|
},
|
|
2448
|
+
/**
|
|
2449
|
+
* Removes the current member's profile image.
|
|
2450
|
+
* After deletion, the member's profileImage field will be null.
|
|
2451
|
+
*
|
|
2452
|
+
* @returns Promise resolving to confirmation that the image was removed
|
|
2453
|
+
*
|
|
2454
|
+
* @example
|
|
2455
|
+
* ```typescript
|
|
2456
|
+
* await memberstack.deleteMemberProfileImage();
|
|
2457
|
+
* console.log('Profile image removed');
|
|
2458
|
+
* ```
|
|
2459
|
+
*
|
|
2460
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
2461
|
+
*/
|
|
2462
|
+
deleteMemberProfileImage() {
|
|
2463
|
+
return __async(this, null, function* () {
|
|
2464
|
+
return sendRequest({
|
|
2465
|
+
method: "DELETE" /* DELETE */,
|
|
2466
|
+
url: `/member/profile-image`
|
|
2467
|
+
});
|
|
2468
|
+
});
|
|
2469
|
+
},
|
|
2040
2470
|
/**
|
|
2041
2471
|
* Sends a verification email to the current member.
|
|
2042
2472
|
* Use this when email verification is enabled in your Memberstack settings.
|
|
@@ -2048,6 +2478,8 @@ var initRequest = ({
|
|
|
2048
2478
|
* await memberstack.sendMemberVerificationEmail();
|
|
2049
2479
|
* // Show message: "Verification email sent! Check your inbox."
|
|
2050
2480
|
* ```
|
|
2481
|
+
*
|
|
2482
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Verification Documentation}
|
|
2051
2483
|
*/
|
|
2052
2484
|
sendMemberVerificationEmail() {
|
|
2053
2485
|
return __async(this, null, function* () {
|
|
@@ -2076,6 +2508,8 @@ var initRequest = ({
|
|
|
2076
2508
|
* });
|
|
2077
2509
|
* // Show confirmation: "Check your email for reset instructions"
|
|
2078
2510
|
* ```
|
|
2511
|
+
*
|
|
2512
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
|
|
2079
2513
|
*/
|
|
2080
2514
|
sendMemberResetPasswordEmail(params) {
|
|
2081
2515
|
return __async(this, null, function* () {
|
|
@@ -2109,6 +2543,8 @@ var initRequest = ({
|
|
|
2109
2543
|
* });
|
|
2110
2544
|
* // Password updated, redirect to login
|
|
2111
2545
|
* ```
|
|
2546
|
+
*
|
|
2547
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
|
|
2112
2548
|
*/
|
|
2113
2549
|
resetMemberPassword(params) {
|
|
2114
2550
|
return __async(this, null, function* () {
|
|
@@ -2142,6 +2578,8 @@ var initRequest = ({
|
|
|
2142
2578
|
* window.location.href = data.redirect;
|
|
2143
2579
|
* }
|
|
2144
2580
|
* ```
|
|
2581
|
+
*
|
|
2582
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
2145
2583
|
*/
|
|
2146
2584
|
logout(options) {
|
|
2147
2585
|
return __async(this, null, function* () {
|
|
@@ -2163,11 +2601,13 @@ var initRequest = ({
|
|
|
2163
2601
|
*
|
|
2164
2602
|
* @example
|
|
2165
2603
|
* ```typescript
|
|
2166
|
-
* const { data
|
|
2167
|
-
* tables.forEach(table => {
|
|
2604
|
+
* const { data } = await memberstack.getDataTables();
|
|
2605
|
+
* data.tables.forEach(table => {
|
|
2168
2606
|
* console.log('Table:', table.name, table.key);
|
|
2169
2607
|
* });
|
|
2170
2608
|
* ```
|
|
2609
|
+
*
|
|
2610
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2171
2611
|
*/
|
|
2172
2612
|
getDataTables(options) {
|
|
2173
2613
|
return __async(this, null, function* () {
|
|
@@ -2190,14 +2630,15 @@ var initRequest = ({
|
|
|
2190
2630
|
* const { data: table } = await memberstack.getDataTable({
|
|
2191
2631
|
* table: 'posts'
|
|
2192
2632
|
* });
|
|
2193
|
-
* console.log('
|
|
2633
|
+
* console.log('Fields:', table.fields.map(f => f.name));
|
|
2194
2634
|
* ```
|
|
2635
|
+
*
|
|
2636
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2195
2637
|
*/
|
|
2196
2638
|
getDataTable(params, options) {
|
|
2197
2639
|
return __async(this, null, function* () {
|
|
2198
2640
|
return sendRequest({
|
|
2199
2641
|
method: "GET" /* GET */,
|
|
2200
|
-
//@ts-ignore
|
|
2201
2642
|
url: `/v1/data-tables/${params.table || params.tableKey}`,
|
|
2202
2643
|
headers: addHeaders(options)
|
|
2203
2644
|
});
|
|
@@ -2226,6 +2667,8 @@ var initRequest = ({
|
|
|
2226
2667
|
* });
|
|
2227
2668
|
* console.log('Records:', data.records);
|
|
2228
2669
|
* ```
|
|
2670
|
+
*
|
|
2671
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2229
2672
|
*/
|
|
2230
2673
|
getDataRecords(params, options) {
|
|
2231
2674
|
return __async(this, null, function* () {
|
|
@@ -2251,7 +2694,6 @@ var initRequest = ({
|
|
|
2251
2694
|
method: "POST" /* POST */,
|
|
2252
2695
|
url: `/v1/data-records/query`,
|
|
2253
2696
|
data: {
|
|
2254
|
-
// @ts-ignore
|
|
2255
2697
|
table: params.table || params.tableKey,
|
|
2256
2698
|
query: {
|
|
2257
2699
|
findMany: query
|
|
@@ -2290,6 +2732,8 @@ var initRequest = ({
|
|
|
2290
2732
|
* });
|
|
2291
2733
|
* console.log('Created record:', record.id);
|
|
2292
2734
|
* ```
|
|
2735
|
+
*
|
|
2736
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2293
2737
|
*/
|
|
2294
2738
|
createDataRecord(params, options) {
|
|
2295
2739
|
return __async(this, null, function* () {
|
|
@@ -2320,6 +2764,8 @@ var initRequest = ({
|
|
|
2320
2764
|
* });
|
|
2321
2765
|
* console.log('Post:', record.title);
|
|
2322
2766
|
* ```
|
|
2767
|
+
*
|
|
2768
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2323
2769
|
*/
|
|
2324
2770
|
getDataRecord(params, options) {
|
|
2325
2771
|
return __async(this, null, function* () {
|
|
@@ -2361,6 +2807,8 @@ var initRequest = ({
|
|
|
2361
2807
|
* }
|
|
2362
2808
|
* });
|
|
2363
2809
|
* ```
|
|
2810
|
+
*
|
|
2811
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2364
2812
|
*/
|
|
2365
2813
|
updateDataRecord(params, options) {
|
|
2366
2814
|
return __async(this, null, function* () {
|
|
@@ -2387,6 +2835,8 @@ var initRequest = ({
|
|
|
2387
2835
|
* recordId: 'rec_abc123'
|
|
2388
2836
|
* });
|
|
2389
2837
|
* ```
|
|
2838
|
+
*
|
|
2839
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2390
2840
|
*/
|
|
2391
2841
|
deleteDataRecord(params, options) {
|
|
2392
2842
|
return __async(this, null, function* () {
|
|
@@ -2432,6 +2882,8 @@ var initRequest = ({
|
|
|
2432
2882
|
* }
|
|
2433
2883
|
* });
|
|
2434
2884
|
* ```
|
|
2885
|
+
*
|
|
2886
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2435
2887
|
*/
|
|
2436
2888
|
queryDataRecords(params, options) {
|
|
2437
2889
|
return __async(this, null, function* () {
|
|
@@ -2461,6 +2913,9 @@ function setDebugMode(enabled) {
|
|
|
2461
2913
|
"color: #6366f1; font-weight: bold;"
|
|
2462
2914
|
);
|
|
2463
2915
|
}
|
|
2916
|
+
if (!enabled && typeof window !== "undefined") {
|
|
2917
|
+
delete window.__MEMBERSTACK_DEBUG__;
|
|
2918
|
+
}
|
|
2464
2919
|
}
|
|
2465
2920
|
function debugLog(message, ...args) {
|
|
2466
2921
|
if (debugEnabled) {
|
|
@@ -2479,8 +2934,8 @@ function initDevToolsIntegration(state) {
|
|
|
2479
2934
|
publicKey: state.config.publicKey,
|
|
2480
2935
|
appId: state.config.appId
|
|
2481
2936
|
},
|
|
2482
|
-
getMember:
|
|
2483
|
-
isAuthenticated: () => state.
|
|
2937
|
+
getMember: state.getMember,
|
|
2938
|
+
isAuthenticated: () => state.getMember() !== null,
|
|
2484
2939
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2485
2940
|
};
|
|
2486
2941
|
debugLog("DevTools integration initialized. Access via window.__MEMBERSTACK_DEBUG__");
|
|
@@ -2489,6 +2944,7 @@ function initDevToolsIntegration(state) {
|
|
|
2489
2944
|
|
|
2490
2945
|
// src/methods/index.ts
|
|
2491
2946
|
var SDK_VERSION = "1.2.0";
|
|
2947
|
+
var initialized = false;
|
|
2492
2948
|
var captchaReadyPromise = new Promise((resolve) => {
|
|
2493
2949
|
if (typeof window !== "undefined") {
|
|
2494
2950
|
window._hcaptchaReady = resolve;
|
|
@@ -2506,6 +2962,16 @@ var methods = {
|
|
|
2506
2962
|
_captchaReady: captchaReadyPromise
|
|
2507
2963
|
};
|
|
2508
2964
|
function init(props) {
|
|
2965
|
+
if (!props.publicKey) {
|
|
2966
|
+
throw new Error(
|
|
2967
|
+
"Memberstack: publicKey is required. Pass your public key to init({ publicKey: 'pk_...' }). Find your key at https://app.memberstack.com/apps"
|
|
2968
|
+
);
|
|
2969
|
+
}
|
|
2970
|
+
if (!props.publicKey.startsWith("pk_")) {
|
|
2971
|
+
throw new Error(
|
|
2972
|
+
`Memberstack: Invalid publicKey format. Keys should start with "pk_sb_" (sandbox) or "pk_" (live). Received: "${props.publicKey.slice(0, 12)}...". Find your key at https://app.memberstack.com/apps`
|
|
2973
|
+
);
|
|
2974
|
+
}
|
|
2509
2975
|
if (props.debug) {
|
|
2510
2976
|
setDebugMode(true);
|
|
2511
2977
|
debugLog(`Initializing Memberstack SDK v${SDK_VERSION}`);
|
|
@@ -2516,6 +2982,17 @@ function init(props) {
|
|
|
2516
2982
|
domain: props.domain
|
|
2517
2983
|
});
|
|
2518
2984
|
}
|
|
2985
|
+
if (initialized && props.debug) {
|
|
2986
|
+
console.warn(
|
|
2987
|
+
"[Memberstack] init() called multiple times. Previous instance will be replaced. This is usually unintentional \u2014 call init() once at app startup."
|
|
2988
|
+
);
|
|
2989
|
+
}
|
|
2990
|
+
if (props.sessionDurationDays !== void 0) {
|
|
2991
|
+
console.warn(
|
|
2992
|
+
"[Memberstack] sessionDurationDays is deprecated and no longer used. Session duration is now controlled server-side. You can safely remove this option."
|
|
2993
|
+
);
|
|
2994
|
+
}
|
|
2995
|
+
initialized = true;
|
|
2519
2996
|
const apiDomain2 = props.domain || endpoints.API || "https://client.memberstack.com";
|
|
2520
2997
|
setApiDomain(apiDomain2);
|
|
2521
2998
|
if (props.useCookies)
|
|
@@ -2527,14 +3004,13 @@ function init(props) {
|
|
|
2527
3004
|
token: getMemberToken(),
|
|
2528
3005
|
domain: apiDomain2
|
|
2529
3006
|
});
|
|
2530
|
-
const allMethods = Object.assign(methods, requests);
|
|
3007
|
+
const allMethods = Object.assign(methods, requests, { destroy });
|
|
2531
3008
|
if (typeof window !== "undefined") {
|
|
2532
3009
|
window.$memberstackDom = allMethods;
|
|
2533
3010
|
if (props.debug) {
|
|
2534
3011
|
initDevToolsIntegration({
|
|
2535
3012
|
config: { publicKey: props.publicKey, appId: props.appId },
|
|
2536
|
-
|
|
2537
|
-
// Will be updated by auth state
|
|
3013
|
+
getMember: () => getPersistedMember(),
|
|
2538
3014
|
version: SDK_VERSION
|
|
2539
3015
|
});
|
|
2540
3016
|
}
|
|
@@ -2544,6 +3020,14 @@ function init(props) {
|
|
|
2544
3020
|
}
|
|
2545
3021
|
return allMethods;
|
|
2546
3022
|
}
|
|
3023
|
+
function destroy() {
|
|
3024
|
+
unsetPersistedMember();
|
|
3025
|
+
initialized = false;
|
|
3026
|
+
if (typeof window !== "undefined") {
|
|
3027
|
+
delete window.$memberstackDom;
|
|
3028
|
+
delete window.__MEMBERSTACK_DEBUG__;
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
2547
3031
|
var methods_default = { init: (props) => init(props) };
|
|
2548
3032
|
|
|
2549
3033
|
// src/utils/errors.ts
|
|
@@ -2895,10 +3379,266 @@ var ErrorMetadata = {
|
|
|
2895
3379
|
"Clear your browser cache and try again"
|
|
2896
3380
|
],
|
|
2897
3381
|
docsUrl: "https://docs.memberstack.com/dom/authentication"
|
|
3382
|
+
},
|
|
3383
|
+
// Authentication — additional
|
|
3384
|
+
[ErrorCodes.MEMBER_NOT_FOUND]: {
|
|
3385
|
+
message: "No member found with this identifier.",
|
|
3386
|
+
category: "authentication",
|
|
3387
|
+
suggestions: [
|
|
3388
|
+
"Verify the email address is correct",
|
|
3389
|
+
"The member may not have signed up yet \u2014 use signupMemberEmailPassword()",
|
|
3390
|
+
"Check if the member exists in the correct environment (SANDBOX vs LIVE)"
|
|
3391
|
+
],
|
|
3392
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/login"
|
|
3393
|
+
},
|
|
3394
|
+
// Account & Social Login — additional
|
|
3395
|
+
[ErrorCodes.ACCOUNT_NOT_FOUND]: {
|
|
3396
|
+
message: "No account found with these credentials.",
|
|
3397
|
+
category: "authentication",
|
|
3398
|
+
suggestions: [
|
|
3399
|
+
"The member may need to sign up first",
|
|
3400
|
+
"Check if the account was created with a different auth method (email vs social)",
|
|
3401
|
+
"Verify the correct environment (SANDBOX vs LIVE)"
|
|
3402
|
+
]
|
|
3403
|
+
},
|
|
3404
|
+
[ErrorCodes.ACCOUNT_ALREADY_CONNECTED]: {
|
|
3405
|
+
message: "This social account is already connected.",
|
|
3406
|
+
category: "conflict",
|
|
3407
|
+
suggestions: [
|
|
3408
|
+
"Use disconnectProvider() first if you need to reconnect",
|
|
3409
|
+
"Check the member's connected providers with getCurrentMember()"
|
|
3410
|
+
],
|
|
3411
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3412
|
+
},
|
|
3413
|
+
[ErrorCodes.ACCOUNT_NOT_CONNECTED]: {
|
|
3414
|
+
message: "This social account is not connected to the member.",
|
|
3415
|
+
category: "not_found",
|
|
3416
|
+
suggestions: [
|
|
3417
|
+
"Use connectProvider() to connect the social account first",
|
|
3418
|
+
"Check the member's connected providers with getCurrentMember()"
|
|
3419
|
+
],
|
|
3420
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3421
|
+
},
|
|
3422
|
+
[ErrorCodes.ACCOUNT_CONNECT_FAILED]: {
|
|
3423
|
+
message: "Failed to connect the social account.",
|
|
3424
|
+
category: "authentication",
|
|
3425
|
+
suggestions: [
|
|
3426
|
+
"Try the connection again \u2014 this may be a temporary issue",
|
|
3427
|
+
"Ensure the social provider is enabled in your Memberstack dashboard",
|
|
3428
|
+
"Check that the OAuth redirect URLs are configured correctly"
|
|
3429
|
+
],
|
|
3430
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3431
|
+
},
|
|
3432
|
+
[ErrorCodes.ACCOUNT_CONNECT_REQUIRES_LOGIN]: {
|
|
3433
|
+
message: "You must be logged in to connect a social account.",
|
|
3434
|
+
category: "authentication",
|
|
3435
|
+
suggestions: [
|
|
3436
|
+
"Call loginMemberEmailPassword() or loginWithProvider() first",
|
|
3437
|
+
"Use getCurrentMember() to verify the member is authenticated"
|
|
3438
|
+
],
|
|
3439
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3440
|
+
},
|
|
3441
|
+
[ErrorCodes.ACCOUNT_SET_PASSWORD_FIRST]: {
|
|
3442
|
+
message: "Set a password before disconnecting your last login provider.",
|
|
3443
|
+
category: "authentication",
|
|
3444
|
+
suggestions: [
|
|
3445
|
+
"Use setPassword() to add a password before disconnecting",
|
|
3446
|
+
"This prevents the member from being locked out of their account"
|
|
3447
|
+
],
|
|
3448
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3449
|
+
},
|
|
3450
|
+
// Validation — additional
|
|
3451
|
+
[ErrorCodes.INVALID_PASSWORD]: {
|
|
3452
|
+
message: "The password is incorrect.",
|
|
3453
|
+
category: "authentication",
|
|
3454
|
+
suggestions: [
|
|
3455
|
+
"Check that the current password is entered correctly",
|
|
3456
|
+
"Use sendMemberResetPasswordEmail() to reset the password"
|
|
3457
|
+
]
|
|
3458
|
+
},
|
|
3459
|
+
[ErrorCodes.REQUIRED_FIELD_MISSING]: {
|
|
3460
|
+
message: "A required field is missing.",
|
|
3461
|
+
category: "validation",
|
|
3462
|
+
suggestions: [
|
|
3463
|
+
"Check that all required parameters are provided",
|
|
3464
|
+
"Review the method documentation for required fields",
|
|
3465
|
+
"Custom fields marked as required in the dashboard must be included on signup"
|
|
3466
|
+
]
|
|
3467
|
+
},
|
|
3468
|
+
[ErrorCodes.INVALID_CAPTCHA]: {
|
|
3469
|
+
message: "CAPTCHA verification failed.",
|
|
3470
|
+
category: "validation",
|
|
3471
|
+
suggestions: [
|
|
3472
|
+
"Ensure the CAPTCHA token is passed as captchaToken in the request",
|
|
3473
|
+
"The token may have expired \u2014 request a new CAPTCHA challenge",
|
|
3474
|
+
"Check that CAPTCHA is correctly configured in your Memberstack dashboard"
|
|
3475
|
+
]
|
|
3476
|
+
},
|
|
3477
|
+
// Plans — additional
|
|
3478
|
+
[ErrorCodes.NO_PLAN_FOUND]: {
|
|
3479
|
+
message: "The member does not have this plan.",
|
|
3480
|
+
category: "not_found",
|
|
3481
|
+
suggestions: [
|
|
3482
|
+
"Use getCurrentMember() to check the member's current plans",
|
|
3483
|
+
"Verify the plan ID is correct",
|
|
3484
|
+
"The plan may have been removed or expired"
|
|
3485
|
+
],
|
|
3486
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3487
|
+
},
|
|
3488
|
+
[ErrorCodes.PLAN_MEMBER_LIMIT_REACHED]: {
|
|
3489
|
+
message: "This plan has reached its member limit.",
|
|
3490
|
+
category: "limit",
|
|
3491
|
+
suggestions: [
|
|
3492
|
+
"Contact the app owner to increase the plan's member limit",
|
|
3493
|
+
"Check if a different plan is available"
|
|
3494
|
+
],
|
|
3495
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3496
|
+
},
|
|
3497
|
+
[ErrorCodes.PLAN_RESTRICTED_TO_ADMIN]: {
|
|
3498
|
+
message: "This plan can only be assigned by an admin.",
|
|
3499
|
+
category: "authorization",
|
|
3500
|
+
suggestions: [
|
|
3501
|
+
"Plans with this restriction cannot be self-assigned by members",
|
|
3502
|
+
"Use the Admin API or dashboard to assign this plan"
|
|
3503
|
+
],
|
|
3504
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3505
|
+
},
|
|
3506
|
+
[ErrorCodes.DOMAIN_NOT_PERMITTED]: {
|
|
3507
|
+
message: "Your email domain is not permitted for this plan.",
|
|
3508
|
+
category: "authorization",
|
|
3509
|
+
suggestions: [
|
|
3510
|
+
"This plan restricts signup to specific email domains",
|
|
3511
|
+
"Check the plan's domain restrictions in your Memberstack dashboard",
|
|
3512
|
+
"Use an email address with an allowed domain"
|
|
3513
|
+
],
|
|
3514
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3515
|
+
},
|
|
3516
|
+
[ErrorCodes.PRICE_NOT_AVAILABLE]: {
|
|
3517
|
+
message: "This pricing option is no longer available.",
|
|
3518
|
+
category: "not_found",
|
|
3519
|
+
suggestions: [
|
|
3520
|
+
"Use getPlans() to see currently available pricing options",
|
|
3521
|
+
"The price may have been archived or deactivated",
|
|
3522
|
+
"Check your Stripe dashboard for the price status"
|
|
3523
|
+
],
|
|
3524
|
+
docsUrl: "https://docs.memberstack.com/dom/payments"
|
|
3525
|
+
},
|
|
3526
|
+
// Teams — additional
|
|
3527
|
+
[ErrorCodes.ONE_ACTIVE_TEAM_ONLY]: {
|
|
3528
|
+
message: "A member can only belong to one active team.",
|
|
3529
|
+
category: "conflict",
|
|
3530
|
+
suggestions: [
|
|
3531
|
+
"Remove the member from their current team first using removeMemberFromTeam()",
|
|
3532
|
+
"Check the member's current team with getTeam()"
|
|
3533
|
+
],
|
|
3534
|
+
docsUrl: "https://docs.memberstack.com/dom/teams"
|
|
3535
|
+
},
|
|
3536
|
+
[ErrorCodes.CANNOT_CHANGE_TEAM]: {
|
|
3537
|
+
message: "Cannot change team while it has active members.",
|
|
3538
|
+
category: "conflict",
|
|
3539
|
+
suggestions: [
|
|
3540
|
+
"Remove all team members before making this change",
|
|
3541
|
+
"Use removeMemberFromTeam() to remove members first"
|
|
3542
|
+
],
|
|
3543
|
+
docsUrl: "https://docs.memberstack.com/dom/teams"
|
|
3544
|
+
},
|
|
3545
|
+
// Data Tables — additional
|
|
3546
|
+
[ErrorCodes.INVALID_TABLE_KEY]: {
|
|
3547
|
+
message: "The table key format is invalid.",
|
|
3548
|
+
category: "data_tables",
|
|
3549
|
+
suggestions: [
|
|
3550
|
+
"Table keys should be lowercase alphanumeric with hyphens",
|
|
3551
|
+
"Use getDataTables() to list available tables and their keys",
|
|
3552
|
+
"Check the table key in your Memberstack dashboard"
|
|
3553
|
+
],
|
|
3554
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3555
|
+
},
|
|
3556
|
+
[ErrorCodes.UNIQUE_CONSTRAINT_VIOLATION]: {
|
|
3557
|
+
message: "A record with this value already exists (unique constraint).",
|
|
3558
|
+
category: "data_tables",
|
|
3559
|
+
suggestions: [
|
|
3560
|
+
"The field has a unique constraint \u2014 use a different value",
|
|
3561
|
+
"Use queryDataRecords() to check for existing records before creating",
|
|
3562
|
+
"If updating, use updateDataRecord() instead of createDataRecord()"
|
|
3563
|
+
],
|
|
3564
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3565
|
+
},
|
|
3566
|
+
[ErrorCodes.FIELD_LIMIT_EXCEEDED]: {
|
|
3567
|
+
message: "Maximum number of fields reached for this table.",
|
|
3568
|
+
category: "data_tables",
|
|
3569
|
+
suggestions: [
|
|
3570
|
+
"Remove unused fields before adding new ones",
|
|
3571
|
+
"Consider using a separate table for additional data",
|
|
3572
|
+
"Check your plan's field limits in the dashboard"
|
|
3573
|
+
],
|
|
3574
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3575
|
+
},
|
|
3576
|
+
[ErrorCodes.INVALID_FIELD_TYPE]: {
|
|
3577
|
+
message: "This field type is not supported.",
|
|
3578
|
+
category: "data_tables",
|
|
3579
|
+
suggestions: [
|
|
3580
|
+
"Check the supported field types in the documentation",
|
|
3581
|
+
"Use getDataTable() to see the table schema and field types"
|
|
3582
|
+
],
|
|
3583
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3584
|
+
},
|
|
3585
|
+
[ErrorCodes.INVALID_FIELD_VALUE]: {
|
|
3586
|
+
message: "The field value does not match the expected type.",
|
|
3587
|
+
category: "data_tables",
|
|
3588
|
+
suggestions: [
|
|
3589
|
+
"Check the field type \u2014 e.g., number fields require numeric values",
|
|
3590
|
+
"Use getDataTable() to see the expected field types",
|
|
3591
|
+
"Ensure dates are in ISO 8601 format for date fields"
|
|
3592
|
+
],
|
|
3593
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3594
|
+
},
|
|
3595
|
+
// Permissions
|
|
3596
|
+
[ErrorCodes.ACCESS_DENIED]: {
|
|
3597
|
+
message: "You do not have permission to access this resource.",
|
|
3598
|
+
category: "authorization",
|
|
3599
|
+
suggestions: [
|
|
3600
|
+
"Check that the member has the required plan or permissions",
|
|
3601
|
+
"Verify the content group configuration in the dashboard",
|
|
3602
|
+
"Use getCurrentMember() to check the member's permissions array"
|
|
3603
|
+
],
|
|
3604
|
+
docsUrl: "https://docs.memberstack.com/dom/content-protection"
|
|
3605
|
+
},
|
|
3606
|
+
// Catch-all
|
|
3607
|
+
[ErrorCodes.UNKNOWN_ERROR]: {
|
|
3608
|
+
message: "An unexpected error occurred.",
|
|
3609
|
+
category: "unknown",
|
|
3610
|
+
suggestions: [
|
|
3611
|
+
"Try the request again",
|
|
3612
|
+
"Check the Memberstack status page for any ongoing issues",
|
|
3613
|
+
"If the problem persists, contact support with the error details"
|
|
3614
|
+
]
|
|
2898
3615
|
}
|
|
2899
3616
|
};
|
|
3617
|
+
function normalizeErrorCode(code) {
|
|
3618
|
+
return code.toLowerCase().replace(/_/g, "-");
|
|
3619
|
+
}
|
|
3620
|
+
function getMetadataForCode(code) {
|
|
3621
|
+
if (ErrorMetadata[code]) {
|
|
3622
|
+
return ErrorMetadata[code];
|
|
3623
|
+
}
|
|
3624
|
+
const normalized = normalizeErrorCode(code);
|
|
3625
|
+
for (const key of Object.keys(ErrorMetadata)) {
|
|
3626
|
+
if (normalizeErrorCode(key) === normalized) {
|
|
3627
|
+
return ErrorMetadata[key];
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
return void 0;
|
|
3631
|
+
}
|
|
3632
|
+
var knownErrorCodes = new Set(Object.values(ErrorCodes));
|
|
2900
3633
|
function isMemberstackError(error) {
|
|
2901
|
-
|
|
3634
|
+
if (typeof error !== "object" || error === null || !("code" in error) || !("message" in error) || typeof error.code !== "string" || typeof error.message !== "string") {
|
|
3635
|
+
return false;
|
|
3636
|
+
}
|
|
3637
|
+
const code = error.code;
|
|
3638
|
+
if (knownErrorCodes.has(code) || knownErrorCodes.has(normalizeErrorCode(code))) {
|
|
3639
|
+
return true;
|
|
3640
|
+
}
|
|
3641
|
+
return code.includes("-") || code.includes("/");
|
|
2902
3642
|
}
|
|
2903
3643
|
function getErrorMessage(error, defaultMessage = "An unexpected error occurred") {
|
|
2904
3644
|
if (isMemberstackError(error)) {
|
|
@@ -2934,7 +3674,7 @@ function getErrorSuggestions(error) {
|
|
|
2934
3674
|
if (error.suggestions && error.suggestions.length > 0) {
|
|
2935
3675
|
return error.suggestions;
|
|
2936
3676
|
}
|
|
2937
|
-
const metadata =
|
|
3677
|
+
const metadata = getMetadataForCode(error.code);
|
|
2938
3678
|
return (metadata == null ? void 0 : metadata.suggestions) || [];
|
|
2939
3679
|
}
|
|
2940
3680
|
function getErrorDocsUrl(error) {
|
|
@@ -2944,7 +3684,7 @@ function getErrorDocsUrl(error) {
|
|
|
2944
3684
|
if (error.docsUrl) {
|
|
2945
3685
|
return error.docsUrl;
|
|
2946
3686
|
}
|
|
2947
|
-
const metadata =
|
|
3687
|
+
const metadata = getMetadataForCode(error.code);
|
|
2948
3688
|
return metadata == null ? void 0 : metadata.docsUrl;
|
|
2949
3689
|
}
|
|
2950
3690
|
function getErrorCategory(error) {
|
|
@@ -2954,18 +3694,18 @@ function getErrorCategory(error) {
|
|
|
2954
3694
|
if (error.category) {
|
|
2955
3695
|
return error.category;
|
|
2956
3696
|
}
|
|
2957
|
-
const metadata =
|
|
3697
|
+
const metadata = getMetadataForCode(error.code);
|
|
2958
3698
|
return (metadata == null ? void 0 : metadata.category) || "unknown";
|
|
2959
3699
|
}
|
|
2960
3700
|
function formatErrorForUser(error) {
|
|
2961
3701
|
if (!isMemberstackError(error)) {
|
|
2962
3702
|
return "An unexpected error occurred. Please try again.";
|
|
2963
3703
|
}
|
|
2964
|
-
const metadata =
|
|
3704
|
+
const metadata = getMetadataForCode(error.code);
|
|
2965
3705
|
if (metadata) {
|
|
2966
3706
|
return metadata.message;
|
|
2967
3707
|
}
|
|
2968
|
-
return
|
|
3708
|
+
return "Something went wrong. Please try again or contact support.";
|
|
2969
3709
|
}
|
|
2970
3710
|
function getErrorReport(error) {
|
|
2971
3711
|
if (!isMemberstackError(error)) {
|