@memberstack/dom 2.0.2-beta.0 → 2.0.3
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 +76 -61
- package/lib/index.d.ts +76 -61
- package/lib/index.js +840 -61
- package/lib/index.mjs +840 -61
- 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.js
CHANGED
|
@@ -234,10 +234,29 @@ var loadPrebuiltUI = (retries = 2) => __async(void 0, null, function* () {
|
|
|
234
234
|
const script = document.createElement("script");
|
|
235
235
|
script.src = getPrebuiltUIUrl();
|
|
236
236
|
script.async = true;
|
|
237
|
-
script.onload = () => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
237
|
+
script.onload = () => __async(void 0, null, function* () {
|
|
238
|
+
yield new Promise((r) => setTimeout(r, 0));
|
|
239
|
+
if (typeof customElements !== "undefined" && customElements.get("memberstack-prebuilt-ui")) {
|
|
240
|
+
prebuiltUILoaded = true;
|
|
241
|
+
resolve();
|
|
242
|
+
} else {
|
|
243
|
+
prebuiltUILoadPromise = null;
|
|
244
|
+
script.remove();
|
|
245
|
+
if (retries > 0) {
|
|
246
|
+
yield new Promise((r) => setTimeout(r, 1e3));
|
|
247
|
+
try {
|
|
248
|
+
yield loadPrebuiltUI(retries - 1);
|
|
249
|
+
resolve();
|
|
250
|
+
} catch (e) {
|
|
251
|
+
reject(e);
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
reject(new Error(
|
|
255
|
+
"Failed to load Memberstack modals: the script loaded but the modal component was not registered. This typically happens when the browser blocks the script body (CORS/ORB). If developing locally, set window.__MS_PREBUILT_UI_URL__ to a locally-served copy of the modal script."
|
|
256
|
+
));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
241
260
|
script.onerror = () => __async(void 0, null, function* () {
|
|
242
261
|
prebuiltUILoadPromise = null;
|
|
243
262
|
script.remove();
|
|
@@ -251,7 +270,7 @@ var loadPrebuiltUI = (retries = 2) => __async(void 0, null, function* () {
|
|
|
251
270
|
}
|
|
252
271
|
} else {
|
|
253
272
|
reject(new Error(
|
|
254
|
-
"Failed to load Memberstack modals after multiple attempts.
|
|
273
|
+
"Failed to load Memberstack modals after multiple attempts. Check your internet connection and browser console for CORS/network errors. For local development, set window.__MS_PREBUILT_UI_URL__ to a locally-served copy."
|
|
255
274
|
));
|
|
256
275
|
}
|
|
257
276
|
});
|
|
@@ -292,7 +311,7 @@ var showMessage = (msg, isError) => __async(void 0, null, function* () {
|
|
|
292
311
|
return;
|
|
293
312
|
const messageTextBox = messageBox.querySelector("[data-ms-message-text]");
|
|
294
313
|
if (messageTextBox) {
|
|
295
|
-
messageTextBox.
|
|
314
|
+
messageTextBox.textContent = msg;
|
|
296
315
|
}
|
|
297
316
|
messageBox.style.display = "block";
|
|
298
317
|
const closeBtn = messageBox.querySelector("[data-ms-message-close]");
|
|
@@ -362,6 +381,7 @@ var hideLoader = (element) => {
|
|
|
362
381
|
(_a = document.querySelector("[data-ms-modal-loader]")) == null ? void 0 : _a.remove();
|
|
363
382
|
};
|
|
364
383
|
var modal = null;
|
|
384
|
+
var resolveModal;
|
|
365
385
|
var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, params = {}) {
|
|
366
386
|
const isInspector = type.toLowerCase() === "inspector";
|
|
367
387
|
const needsLoading = !prebuiltUILoaded;
|
|
@@ -371,12 +391,32 @@ var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, par
|
|
|
371
391
|
}
|
|
372
392
|
try {
|
|
373
393
|
yield loadPrebuiltUI();
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (showLoaderForThisCall) {
|
|
396
|
+
hideLoader();
|
|
397
|
+
}
|
|
398
|
+
console.warn(
|
|
399
|
+
"[Memberstack] Modal failed to load.",
|
|
400
|
+
error instanceof Error ? error.message : error,
|
|
401
|
+
"\nHint: Set window.__MS_PREBUILT_UI_URL__ to override the CDN URL during local development."
|
|
402
|
+
);
|
|
403
|
+
throw error;
|
|
374
404
|
} finally {
|
|
375
405
|
if (showLoaderForThisCall) {
|
|
376
406
|
hideLoader();
|
|
377
407
|
}
|
|
378
408
|
}
|
|
379
|
-
|
|
409
|
+
if (modal) {
|
|
410
|
+
try {
|
|
411
|
+
modal.remove();
|
|
412
|
+
} catch (e) {
|
|
413
|
+
}
|
|
414
|
+
if (resolveModal) {
|
|
415
|
+
resolveModal({ type: "CLOSED" });
|
|
416
|
+
}
|
|
417
|
+
modal = null;
|
|
418
|
+
resolveModal = void 0;
|
|
419
|
+
}
|
|
380
420
|
const modalPromise = new Promise((resolve) => {
|
|
381
421
|
resolveModal = resolve;
|
|
382
422
|
});
|
|
@@ -393,6 +433,11 @@ var hideModal = () => {
|
|
|
393
433
|
modal == null ? void 0 : modal.remove();
|
|
394
434
|
} catch (e) {
|
|
395
435
|
}
|
|
436
|
+
if (resolveModal) {
|
|
437
|
+
resolveModal({ type: "CLOSED" });
|
|
438
|
+
}
|
|
439
|
+
modal = null;
|
|
440
|
+
resolveModal = void 0;
|
|
396
441
|
};
|
|
397
442
|
|
|
398
443
|
// src/utils/cookies.ts
|
|
@@ -453,10 +498,11 @@ var setMemberToken = (token, expires) => {
|
|
|
453
498
|
localStorage.setItem(memberAuthTokenName, token);
|
|
454
499
|
} else {
|
|
455
500
|
const domain = extractDomainFromHostname(window.location.hostname);
|
|
456
|
-
|
|
501
|
+
const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
|
|
502
|
+
import_js_cookie.default.set(memberAuthTokenName, token, __spreadValues(__spreadValues({
|
|
457
503
|
expires: expires && Number(expires) || 14,
|
|
458
504
|
sameSite: "strict"
|
|
459
|
-
}, setCookieOnRootDomain && { domain }));
|
|
505
|
+
}, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
|
|
460
506
|
}
|
|
461
507
|
};
|
|
462
508
|
var removeMemberToken = () => {
|
|
@@ -464,14 +510,11 @@ var removeMemberToken = () => {
|
|
|
464
510
|
localStorage.removeItem(memberAuthTokenName);
|
|
465
511
|
}
|
|
466
512
|
const domain = extractDomainFromHostname(window.location.hostname);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
sameSite: "strict"
|
|
470
|
-
}, setCookieOnRootDomain && { domain }));
|
|
471
|
-
import_js_cookie.default.set(memberAuthTokenName, "", {
|
|
513
|
+
const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
|
|
514
|
+
import_js_cookie.default.set(memberAuthTokenName, "", __spreadValues(__spreadValues({
|
|
472
515
|
expires: -1,
|
|
473
516
|
sameSite: "strict"
|
|
474
|
-
});
|
|
517
|
+
}, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
|
|
475
518
|
};
|
|
476
519
|
var getMemberToken = () => {
|
|
477
520
|
if (localStorageAvailable) {
|
|
@@ -485,8 +528,13 @@ var setMemberTokenIfAvailable = () => {
|
|
|
485
528
|
if (typeof window !== "undefined") {
|
|
486
529
|
const urlParams = new URLSearchParams(window.location.search);
|
|
487
530
|
const memberToken = urlParams.get("memberToken");
|
|
488
|
-
if (memberToken)
|
|
531
|
+
if (memberToken) {
|
|
489
532
|
setMemberToken(memberToken);
|
|
533
|
+
urlParams.delete("memberToken");
|
|
534
|
+
const newSearch = urlParams.toString();
|
|
535
|
+
const newUrl = newSearch ? `${window.location.pathname}?${newSearch}${window.location.hash}` : `${window.location.pathname}${window.location.hash}`;
|
|
536
|
+
window.history.replaceState({}, "", newUrl);
|
|
537
|
+
}
|
|
490
538
|
}
|
|
491
539
|
};
|
|
492
540
|
var getSessionId = () => {
|
|
@@ -529,6 +577,11 @@ var createRequestHandler = ({
|
|
|
529
577
|
token,
|
|
530
578
|
customEndpoint
|
|
531
579
|
}) => {
|
|
580
|
+
if (!publicKey) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
"Memberstack: publicKey is required. Pass your public key to memberstack.init({ publicKey: 'pk_...' })"
|
|
583
|
+
);
|
|
584
|
+
}
|
|
532
585
|
return {
|
|
533
586
|
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
534
587
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -546,7 +599,9 @@ var createRequestHandler = ({
|
|
|
546
599
|
method: data.method,
|
|
547
600
|
data: data.data,
|
|
548
601
|
url: formattedUrl,
|
|
549
|
-
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(
|
|
602
|
+
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), {
|
|
603
|
+
["X-API-Key" /* API_KEY */]: publicKey
|
|
604
|
+
}), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
550
605
|
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
551
606
|
}), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
|
|
552
607
|
["X-Session-ID" /* SESSION_ID */]: sessionToken
|
|
@@ -570,8 +625,12 @@ var createRequestHandler = ({
|
|
|
570
625
|
return res == null ? void 0 : res.data;
|
|
571
626
|
} catch (e) {
|
|
572
627
|
const error = e;
|
|
573
|
-
if (!error.response)
|
|
574
|
-
throw
|
|
628
|
+
if (!error.response) {
|
|
629
|
+
throw {
|
|
630
|
+
code: "network-error",
|
|
631
|
+
message: (error == null ? void 0 : error.message) || "Network request failed. Please check your internet connection."
|
|
632
|
+
};
|
|
633
|
+
}
|
|
575
634
|
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
576
635
|
}
|
|
577
636
|
}),
|
|
@@ -586,7 +645,9 @@ var createRequestHandler = ({
|
|
|
586
645
|
options == null ? void 0 : options.token
|
|
587
646
|
].find((x) => x);
|
|
588
647
|
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
589
|
-
const fetchHeaders = __spreadProps(__spreadValues(
|
|
648
|
+
const fetchHeaders = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), {
|
|
649
|
+
["X-API-Key" /* API_KEY */]: publicKey
|
|
650
|
+
}), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
590
651
|
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
|
|
591
652
|
"Content-Type": "application/json",
|
|
592
653
|
Referer: window.location.href
|
|
@@ -624,8 +685,13 @@ var createRequestHandler = ({
|
|
|
624
685
|
}
|
|
625
686
|
return result;
|
|
626
687
|
} catch (e) {
|
|
627
|
-
|
|
628
|
-
|
|
688
|
+
if (e && typeof e === "object" && "code" in e && "message" in e) {
|
|
689
|
+
throw e;
|
|
690
|
+
}
|
|
691
|
+
throw {
|
|
692
|
+
code: "network-error",
|
|
693
|
+
message: (e == null ? void 0 : e.message) || "Network request failed. Please check your internet connection."
|
|
694
|
+
};
|
|
629
695
|
}
|
|
630
696
|
})
|
|
631
697
|
};
|
|
@@ -650,8 +716,12 @@ var createObservable = () => {
|
|
|
650
716
|
};
|
|
651
717
|
var observable = createObservable();
|
|
652
718
|
var getPersistedMember = () => {
|
|
653
|
-
|
|
654
|
-
|
|
719
|
+
try {
|
|
720
|
+
const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
|
|
721
|
+
return stored ? JSON.parse(stored) : null;
|
|
722
|
+
} catch (e) {
|
|
723
|
+
return null;
|
|
724
|
+
}
|
|
655
725
|
};
|
|
656
726
|
var setPersistedMember = (member) => {
|
|
657
727
|
if (member) {
|
|
@@ -677,8 +747,9 @@ var unsetPersistedMember = () => {
|
|
|
677
747
|
removeSessionId();
|
|
678
748
|
observable.notify(null);
|
|
679
749
|
};
|
|
750
|
+
var nextSubscriberId = 0;
|
|
680
751
|
var onAuthChange = (cb) => {
|
|
681
|
-
const id =
|
|
752
|
+
const id = nextSubscriberId++;
|
|
682
753
|
observable.subscribe(id, cb);
|
|
683
754
|
return {
|
|
684
755
|
unsubscribe: () => observable.unsubscribe(id)
|
|
@@ -842,6 +913,8 @@ var initRequest = ({
|
|
|
842
913
|
* window.location.href = '/goodbye';
|
|
843
914
|
* }
|
|
844
915
|
* ```
|
|
916
|
+
*
|
|
917
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
845
918
|
*/
|
|
846
919
|
deleteMember() {
|
|
847
920
|
return __async(this, null, function* () {
|
|
@@ -853,6 +926,15 @@ var initRequest = ({
|
|
|
853
926
|
return data;
|
|
854
927
|
});
|
|
855
928
|
},
|
|
929
|
+
/**
|
|
930
|
+
* Sends a typing indicator to a comments channel.
|
|
931
|
+
* Used internally to show when a member is actively composing a post.
|
|
932
|
+
*
|
|
933
|
+
* @internal
|
|
934
|
+
* @param params - The typing indicator parameters
|
|
935
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
936
|
+
* @returns Promise that resolves when the typing indicator is sent
|
|
937
|
+
*/
|
|
856
938
|
postIsTyping(params) {
|
|
857
939
|
return __async(this, null, function* () {
|
|
858
940
|
return sendRequest({
|
|
@@ -864,6 +946,15 @@ var initRequest = ({
|
|
|
864
946
|
});
|
|
865
947
|
});
|
|
866
948
|
},
|
|
949
|
+
/**
|
|
950
|
+
* Retrieves information about a comments channel.
|
|
951
|
+
* Returns channel metadata and configuration.
|
|
952
|
+
*
|
|
953
|
+
* @internal
|
|
954
|
+
* @param params - The channel info parameters
|
|
955
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
956
|
+
* @returns Promise resolving to the channel information
|
|
957
|
+
*/
|
|
867
958
|
getChannelInfo(params) {
|
|
868
959
|
return __async(this, null, function* () {
|
|
869
960
|
const queryParams = new URLSearchParams({
|
|
@@ -875,6 +966,16 @@ var initRequest = ({
|
|
|
875
966
|
});
|
|
876
967
|
});
|
|
877
968
|
},
|
|
969
|
+
/**
|
|
970
|
+
* Manages a member's notification subscription to a comments channel.
|
|
971
|
+
* Allows members to subscribe or unsubscribe from channel notifications.
|
|
972
|
+
*
|
|
973
|
+
* @internal
|
|
974
|
+
* @param params - The subscription parameters
|
|
975
|
+
* @param params.channelKey - The key/identifier of the channel
|
|
976
|
+
* @param params.action - The subscription action: 'NONE' to unsubscribe, 'THREADS_ONLY' to receive thread notifications
|
|
977
|
+
* @returns Promise that resolves when the subscription is updated
|
|
978
|
+
*/
|
|
878
979
|
subscribeToChannel(params) {
|
|
879
980
|
return __async(this, null, function* () {
|
|
880
981
|
return sendRequest({
|
|
@@ -887,6 +988,27 @@ var initRequest = ({
|
|
|
887
988
|
});
|
|
888
989
|
});
|
|
889
990
|
},
|
|
991
|
+
/**
|
|
992
|
+
* Retrieves posts from a comments channel.
|
|
993
|
+
* Use this to display comments or discussion threads on your site.
|
|
994
|
+
*
|
|
995
|
+
* @param params - Query parameters
|
|
996
|
+
* @param params.channelKey - The key identifying the channel to fetch posts from
|
|
997
|
+
* @param params.order - Sort order: 'newest' or 'oldest'
|
|
998
|
+
* @param params.after - Cursor for pagination (post ID to start after)
|
|
999
|
+
* @param params.limit - Maximum number of posts to return
|
|
1000
|
+
* @returns Promise resolving to an array of posts
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* const { data } = await memberstack.getPosts({
|
|
1005
|
+
* channelKey: 'blog-comments',
|
|
1006
|
+
* order: 'newest',
|
|
1007
|
+
* limit: 20
|
|
1008
|
+
* });
|
|
1009
|
+
* data.posts.forEach(post => console.log(post.content));
|
|
1010
|
+
* ```
|
|
1011
|
+
*/
|
|
890
1012
|
getPosts(params) {
|
|
891
1013
|
return __async(this, null, function* () {
|
|
892
1014
|
const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
|
|
@@ -904,6 +1026,26 @@ var initRequest = ({
|
|
|
904
1026
|
});
|
|
905
1027
|
});
|
|
906
1028
|
},
|
|
1029
|
+
/**
|
|
1030
|
+
* Retrieves threads (replies) for a specific post.
|
|
1031
|
+
*
|
|
1032
|
+
* @param params - Query parameters
|
|
1033
|
+
* @param params.postId - The ID of the parent post
|
|
1034
|
+
* @param params.order - Sort order: 'newest' or 'oldest'
|
|
1035
|
+
* @param params.after - Cursor for pagination (thread ID to start after)
|
|
1036
|
+
* @param params.limit - Maximum number of threads to return
|
|
1037
|
+
* @returns Promise resolving to an array of threads
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* const { data } = await memberstack.getThreads({
|
|
1042
|
+
* postId: 'post_abc123',
|
|
1043
|
+
* order: 'oldest',
|
|
1044
|
+
* limit: 50
|
|
1045
|
+
* });
|
|
1046
|
+
* data.threads.forEach(thread => console.log(thread.content));
|
|
1047
|
+
* ```
|
|
1048
|
+
*/
|
|
907
1049
|
getThreads(params) {
|
|
908
1050
|
return __async(this, null, function* () {
|
|
909
1051
|
const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
|
|
@@ -921,6 +1063,23 @@ var initRequest = ({
|
|
|
921
1063
|
});
|
|
922
1064
|
});
|
|
923
1065
|
},
|
|
1066
|
+
/**
|
|
1067
|
+
* Creates a new post in a comments channel.
|
|
1068
|
+
*
|
|
1069
|
+
* @param params - Post data
|
|
1070
|
+
* @param params.channelKey - The key of the channel to post in
|
|
1071
|
+
* @param params.content - The content of the post (supports markdown)
|
|
1072
|
+
* @returns Promise resolving to the created post
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```typescript
|
|
1076
|
+
* const { data: post } = await memberstack.createPost({
|
|
1077
|
+
* channelKey: 'blog-comments',
|
|
1078
|
+
* content: 'Great article! Thanks for sharing.'
|
|
1079
|
+
* });
|
|
1080
|
+
* console.log('Posted:', post.id);
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
924
1083
|
createPost(params) {
|
|
925
1084
|
return __async(this, null, function* () {
|
|
926
1085
|
return sendRequest({
|
|
@@ -934,6 +1093,23 @@ var initRequest = ({
|
|
|
934
1093
|
});
|
|
935
1094
|
});
|
|
936
1095
|
},
|
|
1096
|
+
/**
|
|
1097
|
+
* Updates an existing post's content.
|
|
1098
|
+
* Only the post author can update their post.
|
|
1099
|
+
*
|
|
1100
|
+
* @param params - Update data
|
|
1101
|
+
* @param params.postId - The ID of the post to update
|
|
1102
|
+
* @param params.content - The new content for the post
|
|
1103
|
+
* @returns Promise resolving to the updated post
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```typescript
|
|
1107
|
+
* const { data: post } = await memberstack.updatePost({
|
|
1108
|
+
* postId: 'post_abc123',
|
|
1109
|
+
* content: 'Updated: Great article with corrections!'
|
|
1110
|
+
* });
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
937
1113
|
updatePost(params) {
|
|
938
1114
|
return __async(this, null, function* () {
|
|
939
1115
|
return sendRequest({
|
|
@@ -945,6 +1121,29 @@ var initRequest = ({
|
|
|
945
1121
|
});
|
|
946
1122
|
});
|
|
947
1123
|
},
|
|
1124
|
+
/**
|
|
1125
|
+
* Votes on a post (upvote, downvote, or remove vote).
|
|
1126
|
+
*
|
|
1127
|
+
* @param params - Vote data
|
|
1128
|
+
* @param params.postId - The ID of the post to vote on
|
|
1129
|
+
* @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
|
|
1130
|
+
* @returns Promise resolving when the vote is recorded
|
|
1131
|
+
*
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```typescript
|
|
1134
|
+
* // Upvote a post
|
|
1135
|
+
* await memberstack.postVote({
|
|
1136
|
+
* postId: 'post_abc123',
|
|
1137
|
+
* vote: 'UP'
|
|
1138
|
+
* });
|
|
1139
|
+
*
|
|
1140
|
+
* // Remove vote
|
|
1141
|
+
* await memberstack.postVote({
|
|
1142
|
+
* postId: 'post_abc123',
|
|
1143
|
+
* vote: 'NONE'
|
|
1144
|
+
* });
|
|
1145
|
+
* ```
|
|
1146
|
+
*/
|
|
948
1147
|
postVote(params) {
|
|
949
1148
|
return __async(this, null, function* () {
|
|
950
1149
|
return sendRequest({
|
|
@@ -956,6 +1155,21 @@ var initRequest = ({
|
|
|
956
1155
|
});
|
|
957
1156
|
});
|
|
958
1157
|
},
|
|
1158
|
+
/**
|
|
1159
|
+
* Deletes a post.
|
|
1160
|
+
* Only the post author can delete their post.
|
|
1161
|
+
*
|
|
1162
|
+
* @param params - Delete parameters
|
|
1163
|
+
* @param params.postId - The ID of the post to delete
|
|
1164
|
+
* @returns Promise resolving when the post is deleted
|
|
1165
|
+
*
|
|
1166
|
+
* @example
|
|
1167
|
+
* ```typescript
|
|
1168
|
+
* await memberstack.deletePost({
|
|
1169
|
+
* postId: 'post_abc123'
|
|
1170
|
+
* });
|
|
1171
|
+
* ```
|
|
1172
|
+
*/
|
|
959
1173
|
deletePost(params) {
|
|
960
1174
|
return __async(this, null, function* () {
|
|
961
1175
|
return sendRequest({
|
|
@@ -964,6 +1178,22 @@ var initRequest = ({
|
|
|
964
1178
|
});
|
|
965
1179
|
});
|
|
966
1180
|
},
|
|
1181
|
+
/**
|
|
1182
|
+
* Creates a reply thread on a post.
|
|
1183
|
+
*
|
|
1184
|
+
* @param params - Thread data
|
|
1185
|
+
* @param params.postId - The ID of the post to reply to
|
|
1186
|
+
* @param params.content - The content of the reply (supports markdown)
|
|
1187
|
+
* @returns Promise resolving to the created thread
|
|
1188
|
+
*
|
|
1189
|
+
* @example
|
|
1190
|
+
* ```typescript
|
|
1191
|
+
* const { data: thread } = await memberstack.createThread({
|
|
1192
|
+
* postId: 'post_abc123',
|
|
1193
|
+
* content: 'I agree with this point!'
|
|
1194
|
+
* });
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
967
1197
|
createThread(params) {
|
|
968
1198
|
return __async(this, null, function* () {
|
|
969
1199
|
return sendRequest({
|
|
@@ -976,6 +1206,23 @@ var initRequest = ({
|
|
|
976
1206
|
});
|
|
977
1207
|
});
|
|
978
1208
|
},
|
|
1209
|
+
/**
|
|
1210
|
+
* Updates an existing thread's content.
|
|
1211
|
+
* Only the thread author can update their thread.
|
|
1212
|
+
*
|
|
1213
|
+
* @param params - Update data
|
|
1214
|
+
* @param params.threadId - The ID of the thread to update
|
|
1215
|
+
* @param params.content - The new content for the thread
|
|
1216
|
+
* @returns Promise resolving to the updated thread
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```typescript
|
|
1220
|
+
* const { data: thread } = await memberstack.updateThread({
|
|
1221
|
+
* threadId: 'thread_xyz789',
|
|
1222
|
+
* content: 'Updated reply with more details.'
|
|
1223
|
+
* });
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
979
1226
|
updateThread(params) {
|
|
980
1227
|
return __async(this, null, function* () {
|
|
981
1228
|
return sendRequest({
|
|
@@ -987,7 +1234,22 @@ var initRequest = ({
|
|
|
987
1234
|
});
|
|
988
1235
|
});
|
|
989
1236
|
},
|
|
990
|
-
|
|
1237
|
+
/**
|
|
1238
|
+
* Votes on a thread (upvote, downvote, or remove vote).
|
|
1239
|
+
*
|
|
1240
|
+
* @param params - Vote data
|
|
1241
|
+
* @param params.threadId - The ID of the thread to vote on
|
|
1242
|
+
* @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
|
|
1243
|
+
* @returns Promise resolving when the vote is recorded
|
|
1244
|
+
*
|
|
1245
|
+
* @example
|
|
1246
|
+
* ```typescript
|
|
1247
|
+
* await memberstack.threadVote({
|
|
1248
|
+
* threadId: 'thread_xyz789',
|
|
1249
|
+
* vote: 'UP'
|
|
1250
|
+
* });
|
|
1251
|
+
* ```
|
|
1252
|
+
*/
|
|
991
1253
|
threadVote(params) {
|
|
992
1254
|
return __async(this, null, function* () {
|
|
993
1255
|
return sendRequest({
|
|
@@ -999,6 +1261,21 @@ var initRequest = ({
|
|
|
999
1261
|
});
|
|
1000
1262
|
});
|
|
1001
1263
|
},
|
|
1264
|
+
/**
|
|
1265
|
+
* Deletes a thread.
|
|
1266
|
+
* Only the thread author can delete their thread.
|
|
1267
|
+
*
|
|
1268
|
+
* @param params - Delete parameters
|
|
1269
|
+
* @param params.threadId - The ID of the thread to delete
|
|
1270
|
+
* @returns Promise resolving when the thread is deleted
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1273
|
+
* ```typescript
|
|
1274
|
+
* await memberstack.deleteThread({
|
|
1275
|
+
* threadId: 'thread_xyz789'
|
|
1276
|
+
* });
|
|
1277
|
+
* ```
|
|
1278
|
+
*/
|
|
1002
1279
|
deleteThread(params) {
|
|
1003
1280
|
return __async(this, null, function* () {
|
|
1004
1281
|
return sendRequest({
|
|
@@ -1020,8 +1297,10 @@ var initRequest = ({
|
|
|
1020
1297
|
* const { data: content } = await memberstack.getSecureContent({
|
|
1021
1298
|
* contentId: 'cnt_abc123'
|
|
1022
1299
|
* });
|
|
1023
|
-
* document.getElementById('premium-content').innerHTML = content.
|
|
1300
|
+
* document.getElementById('premium-content').innerHTML = content.content;
|
|
1024
1301
|
* ```
|
|
1302
|
+
*
|
|
1303
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Protected Content Documentation}
|
|
1025
1304
|
*/
|
|
1026
1305
|
getSecureContent(params) {
|
|
1027
1306
|
return __async(this, null, function* () {
|
|
@@ -1062,6 +1341,8 @@ var initRequest = ({
|
|
|
1062
1341
|
* plans: [{ planId: 'pln_free' }]
|
|
1063
1342
|
* });
|
|
1064
1343
|
* ```
|
|
1344
|
+
*
|
|
1345
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1065
1346
|
*/
|
|
1066
1347
|
signupWithProvider(params) {
|
|
1067
1348
|
return __async(this, null, function* () {
|
|
@@ -1112,6 +1393,8 @@ var initRequest = ({
|
|
|
1112
1393
|
* allowSignup: true
|
|
1113
1394
|
* });
|
|
1114
1395
|
* ```
|
|
1396
|
+
*
|
|
1397
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1115
1398
|
*/
|
|
1116
1399
|
loginWithProvider(params) {
|
|
1117
1400
|
return __async(this, null, function* () {
|
|
@@ -1144,6 +1427,8 @@ var initRequest = ({
|
|
|
1144
1427
|
* });
|
|
1145
1428
|
* // Member can now log in with either email/password or Google
|
|
1146
1429
|
* ```
|
|
1430
|
+
*
|
|
1431
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1147
1432
|
*/
|
|
1148
1433
|
connectProvider(params) {
|
|
1149
1434
|
return __async(this, null, function* () {
|
|
@@ -1175,6 +1460,8 @@ var initRequest = ({
|
|
|
1175
1460
|
* });
|
|
1176
1461
|
* // Member must now use email/password or another connected provider
|
|
1177
1462
|
* ```
|
|
1463
|
+
*
|
|
1464
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1178
1465
|
*/
|
|
1179
1466
|
disconnectProvider(params) {
|
|
1180
1467
|
return __async(this, null, function* () {
|
|
@@ -1187,6 +1474,16 @@ var initRequest = ({
|
|
|
1187
1474
|
});
|
|
1188
1475
|
});
|
|
1189
1476
|
},
|
|
1477
|
+
/**
|
|
1478
|
+
* Retrieves both app configuration and current member data in a single request.
|
|
1479
|
+
* Used internally for initial page load to efficiently fetch all required data.
|
|
1480
|
+
* Also handles session tracking and conversion data.
|
|
1481
|
+
*
|
|
1482
|
+
* @internal
|
|
1483
|
+
* @param params - Optional parameters
|
|
1484
|
+
* @param params.trackPageView - Whether to track this as a page view for analytics (default: false)
|
|
1485
|
+
* @returns Promise resolving to both app and member data
|
|
1486
|
+
*/
|
|
1190
1487
|
getAppAndMember(params) {
|
|
1191
1488
|
return __async(this, null, function* () {
|
|
1192
1489
|
var _a2, _b;
|
|
@@ -1195,7 +1492,6 @@ var initRequest = ({
|
|
|
1195
1492
|
url: `/app-member`,
|
|
1196
1493
|
data: {
|
|
1197
1494
|
data: {
|
|
1198
|
-
// @ts-ignore
|
|
1199
1495
|
includeSSOText: window == null ? void 0 : window.ssoUI,
|
|
1200
1496
|
trackPageView: params == null ? void 0 : params.trackPageView,
|
|
1201
1497
|
sessionData: __spreadValues({}, getConversionData())
|
|
@@ -1224,12 +1520,14 @@ var initRequest = ({
|
|
|
1224
1520
|
* console.log('App name:', app.name);
|
|
1225
1521
|
* console.log('OAuth providers:', app.authProviders);
|
|
1226
1522
|
* ```
|
|
1523
|
+
*
|
|
1524
|
+
* @see {@link https://developers.memberstack.com/dom-package/quick-start | Quick Start Documentation}
|
|
1227
1525
|
*/
|
|
1228
1526
|
getApp() {
|
|
1229
1527
|
return __async(this, null, function* () {
|
|
1528
|
+
var _a2;
|
|
1230
1529
|
const queryParams = new URLSearchParams({
|
|
1231
|
-
|
|
1232
|
-
includeSSOText: window == null ? void 0 : window.ssoUI
|
|
1530
|
+
includeSSOText: String((_a2 = window == null ? void 0 : window.ssoUI) != null ? _a2 : "")
|
|
1233
1531
|
});
|
|
1234
1532
|
return sendRequest({
|
|
1235
1533
|
method: "GET" /* GET */,
|
|
@@ -1259,6 +1557,8 @@ var initRequest = ({
|
|
|
1259
1557
|
* console.error('Login failed:', error.message);
|
|
1260
1558
|
* }
|
|
1261
1559
|
* ```
|
|
1560
|
+
*
|
|
1561
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1262
1562
|
*/
|
|
1263
1563
|
loginMemberEmailPassword(params, options) {
|
|
1264
1564
|
return __async(this, null, function* () {
|
|
@@ -1296,6 +1596,8 @@ var initRequest = ({
|
|
|
1296
1596
|
*
|
|
1297
1597
|
* // Step 2: Complete login with the code (see loginMemberPasswordless)
|
|
1298
1598
|
* ```
|
|
1599
|
+
*
|
|
1600
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1299
1601
|
*/
|
|
1300
1602
|
sendMemberLoginPasswordlessEmail(params, options) {
|
|
1301
1603
|
return __async(this, null, function* () {
|
|
@@ -1325,6 +1627,8 @@ var initRequest = ({
|
|
|
1325
1627
|
*
|
|
1326
1628
|
* // Step 2: Complete signup with the code (see signupMemberPasswordless)
|
|
1327
1629
|
* ```
|
|
1630
|
+
*
|
|
1631
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1328
1632
|
*/
|
|
1329
1633
|
sendMemberSignupPasswordlessEmail(params, options) {
|
|
1330
1634
|
return __async(this, null, function* () {
|
|
@@ -1356,6 +1660,8 @@ var initRequest = ({
|
|
|
1356
1660
|
* });
|
|
1357
1661
|
* console.log('Logged in:', data.member.auth.email);
|
|
1358
1662
|
* ```
|
|
1663
|
+
*
|
|
1664
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
1359
1665
|
*/
|
|
1360
1666
|
loginMemberPasswordless(params, options) {
|
|
1361
1667
|
return __async(this, null, function* () {
|
|
@@ -1390,6 +1696,8 @@ var initRequest = ({
|
|
|
1390
1696
|
* console.log('Plan:', plan.name);
|
|
1391
1697
|
* console.log('Prices:', plan.prices);
|
|
1392
1698
|
* ```
|
|
1699
|
+
*
|
|
1700
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1393
1701
|
*/
|
|
1394
1702
|
getPlan(params) {
|
|
1395
1703
|
return __async(this, null, function* () {
|
|
@@ -1428,6 +1736,8 @@ var initRequest = ({
|
|
|
1428
1736
|
* </div>
|
|
1429
1737
|
* `).join('');
|
|
1430
1738
|
* ```
|
|
1739
|
+
*
|
|
1740
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1431
1741
|
*/
|
|
1432
1742
|
getPlans() {
|
|
1433
1743
|
return __async(this, null, function* () {
|
|
@@ -1452,7 +1762,7 @@ var initRequest = ({
|
|
|
1452
1762
|
*
|
|
1453
1763
|
* groups.forEach(group => {
|
|
1454
1764
|
* console.log('Group:', group.name);
|
|
1455
|
-
* console.log('Required plans:', group.
|
|
1765
|
+
* console.log('Required plans:', group.plans.map(p => p.id));
|
|
1456
1766
|
* console.log('URLs:', group.urls);
|
|
1457
1767
|
* });
|
|
1458
1768
|
* ```
|
|
@@ -1499,6 +1809,8 @@ var initRequest = ({
|
|
|
1499
1809
|
* const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
|
|
1500
1810
|
* }
|
|
1501
1811
|
* ```
|
|
1812
|
+
*
|
|
1813
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1502
1814
|
*/
|
|
1503
1815
|
getCurrentMember(options) {
|
|
1504
1816
|
return __async(this, null, function* () {
|
|
@@ -1537,6 +1849,8 @@ var initRequest = ({
|
|
|
1537
1849
|
* console.log('Preferences:', json.preferences);
|
|
1538
1850
|
* console.log('Last visited:', json.lastVisitedPage);
|
|
1539
1851
|
* ```
|
|
1852
|
+
*
|
|
1853
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
|
|
1540
1854
|
*/
|
|
1541
1855
|
getMemberJSON(options) {
|
|
1542
1856
|
return __async(this, null, function* () {
|
|
@@ -1549,7 +1863,7 @@ var initRequest = ({
|
|
|
1549
1863
|
},
|
|
1550
1864
|
/**
|
|
1551
1865
|
* Updates the current member's JSON data store.
|
|
1552
|
-
* You can store any JSON-serializable data.
|
|
1866
|
+
* You can store any JSON-serializable data. This completely replaces the existing JSON.
|
|
1553
1867
|
*
|
|
1554
1868
|
* @param params - JSON data to store
|
|
1555
1869
|
* @param params.json - Object containing the data to store
|
|
@@ -1575,6 +1889,8 @@ var initRequest = ({
|
|
|
1575
1889
|
* }
|
|
1576
1890
|
* });
|
|
1577
1891
|
* ```
|
|
1892
|
+
*
|
|
1893
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
|
|
1578
1894
|
*/
|
|
1579
1895
|
updateMemberJSON(params, options) {
|
|
1580
1896
|
return __async(this, null, function* () {
|
|
@@ -1603,10 +1919,13 @@ var initRequest = ({
|
|
|
1603
1919
|
* });
|
|
1604
1920
|
* console.log('Plan added, redirect:', data.redirect);
|
|
1605
1921
|
* ```
|
|
1922
|
+
*
|
|
1923
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1606
1924
|
*/
|
|
1607
1925
|
addPlan(params, options) {
|
|
1608
1926
|
return __async(this, null, function* () {
|
|
1609
|
-
|
|
1927
|
+
var _a2;
|
|
1928
|
+
const result = yield sendRequest({
|
|
1610
1929
|
method: "POST" /* POST */,
|
|
1611
1930
|
url: `/member/plans/add`,
|
|
1612
1931
|
data: {
|
|
@@ -1614,6 +1933,10 @@ var initRequest = ({
|
|
|
1614
1933
|
},
|
|
1615
1934
|
headers: addHeaders(options)
|
|
1616
1935
|
});
|
|
1936
|
+
if ((_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.member) {
|
|
1937
|
+
setPersistedMember(result.data.member);
|
|
1938
|
+
}
|
|
1939
|
+
return result;
|
|
1617
1940
|
});
|
|
1618
1941
|
},
|
|
1619
1942
|
/**
|
|
@@ -1658,6 +1981,8 @@ var initRequest = ({
|
|
|
1658
1981
|
* cancelUrl: '/pricing'
|
|
1659
1982
|
* });
|
|
1660
1983
|
* ```
|
|
1984
|
+
*
|
|
1985
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1661
1986
|
*/
|
|
1662
1987
|
purchasePlansWithCheckout(params, options) {
|
|
1663
1988
|
return __async(this, null, function* () {
|
|
@@ -1726,6 +2051,8 @@ var initRequest = ({
|
|
|
1726
2051
|
* });
|
|
1727
2052
|
* console.log('Portal URL:', data.url);
|
|
1728
2053
|
* ```
|
|
2054
|
+
*
|
|
2055
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1729
2056
|
*/
|
|
1730
2057
|
launchStripeCustomerPortal(params, options) {
|
|
1731
2058
|
return __async(this, null, function* () {
|
|
@@ -1777,10 +2104,13 @@ var initRequest = ({
|
|
|
1777
2104
|
* });
|
|
1778
2105
|
* // Plan removed/subscription cancelled
|
|
1779
2106
|
* ```
|
|
2107
|
+
*
|
|
2108
|
+
* @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
|
|
1780
2109
|
*/
|
|
1781
2110
|
removePlan(params, options) {
|
|
1782
2111
|
return __async(this, null, function* () {
|
|
1783
|
-
|
|
2112
|
+
var _a2;
|
|
2113
|
+
const result = yield sendRequest({
|
|
1784
2114
|
method: "POST" /* POST */,
|
|
1785
2115
|
url: `/member/plans/remove`,
|
|
1786
2116
|
data: {
|
|
@@ -1788,6 +2118,10 @@ var initRequest = ({
|
|
|
1788
2118
|
},
|
|
1789
2119
|
headers: addHeaders(options)
|
|
1790
2120
|
});
|
|
2121
|
+
if ((_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.member) {
|
|
2122
|
+
setPersistedMember(result.data.member);
|
|
2123
|
+
}
|
|
2124
|
+
return result;
|
|
1791
2125
|
});
|
|
1792
2126
|
},
|
|
1793
2127
|
/**
|
|
@@ -1818,6 +2152,8 @@ var initRequest = ({
|
|
|
1818
2152
|
* }
|
|
1819
2153
|
* });
|
|
1820
2154
|
* ```
|
|
2155
|
+
*
|
|
2156
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1821
2157
|
*/
|
|
1822
2158
|
updateMember(params, options) {
|
|
1823
2159
|
return __async(this, null, function* () {
|
|
@@ -1855,6 +2191,8 @@ var initRequest = ({
|
|
|
1855
2191
|
* newPassword: 'newSecurePassword123'
|
|
1856
2192
|
* });
|
|
1857
2193
|
* ```
|
|
2194
|
+
*
|
|
2195
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1858
2196
|
*/
|
|
1859
2197
|
updateMemberAuth(params, options) {
|
|
1860
2198
|
return __async(this, null, function* () {
|
|
@@ -1882,6 +2220,8 @@ var initRequest = ({
|
|
|
1882
2220
|
* });
|
|
1883
2221
|
* // Member can now log in with email/password
|
|
1884
2222
|
* ```
|
|
2223
|
+
*
|
|
2224
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
1885
2225
|
*/
|
|
1886
2226
|
setPassword(params, options) {
|
|
1887
2227
|
return __async(this, null, function* () {
|
|
@@ -1895,6 +2235,33 @@ var initRequest = ({
|
|
|
1895
2235
|
});
|
|
1896
2236
|
});
|
|
1897
2237
|
},
|
|
2238
|
+
/**
|
|
2239
|
+
* Completes passwordless signup using the code sent via email.
|
|
2240
|
+
* Creates a new member account without requiring a password.
|
|
2241
|
+
*
|
|
2242
|
+
* @param params - Signup details
|
|
2243
|
+
* @param params.email - The new member's email address
|
|
2244
|
+
* @param params.passwordlessToken - The one-time code from the signup email
|
|
2245
|
+
* @param params.customFields - Optional custom field values defined in your Memberstack dashboard
|
|
2246
|
+
* @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
|
|
2247
|
+
* @param params.metaData - Optional metadata to store with the member
|
|
2248
|
+
* @returns Promise resolving to the new member data and tokens
|
|
2249
|
+
* @throws When the code is invalid, expired, or email is already in use
|
|
2250
|
+
*
|
|
2251
|
+
* @example Complete passwordless signup flow
|
|
2252
|
+
* ```typescript
|
|
2253
|
+
* // Step 1: Send signup code (see sendMemberSignupPasswordlessEmail)
|
|
2254
|
+
* // Step 2: User enters code, complete signup:
|
|
2255
|
+
* const { data } = await memberstack.signupMemberPasswordless({
|
|
2256
|
+
* email: 'newuser@example.com',
|
|
2257
|
+
* passwordlessToken: '123456',
|
|
2258
|
+
* customFields: { firstName: 'Jane' }
|
|
2259
|
+
* });
|
|
2260
|
+
* console.log('Welcome!', data.member.id);
|
|
2261
|
+
* ```
|
|
2262
|
+
*
|
|
2263
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
2264
|
+
*/
|
|
1898
2265
|
signupMemberPasswordless(params, options) {
|
|
1899
2266
|
return __async(this, null, function* () {
|
|
1900
2267
|
var _a2, _b, _c;
|
|
@@ -1915,9 +2282,7 @@ var initRequest = ({
|
|
|
1915
2282
|
options
|
|
1916
2283
|
}), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
|
|
1917
2284
|
rewardfulData: {
|
|
1918
|
-
// @ts-ignore
|
|
1919
2285
|
referral: window.Rewardful.referral,
|
|
1920
|
-
// @ts-ignore
|
|
1921
2286
|
coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
|
|
1922
2287
|
}
|
|
1923
2288
|
})
|
|
@@ -1964,6 +2329,8 @@ var initRequest = ({
|
|
|
1964
2329
|
* plans: [{ planId: 'pln_free_tier' }]
|
|
1965
2330
|
* });
|
|
1966
2331
|
* ```
|
|
2332
|
+
*
|
|
2333
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Signup Documentation}
|
|
1967
2334
|
*/
|
|
1968
2335
|
signupMemberEmailPassword(params, options) {
|
|
1969
2336
|
return __async(this, null, function* () {
|
|
@@ -1987,9 +2354,7 @@ var initRequest = ({
|
|
|
1987
2354
|
options
|
|
1988
2355
|
}), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
|
|
1989
2356
|
rewardfulData: {
|
|
1990
|
-
// @ts-ignore
|
|
1991
2357
|
referral: window.Rewardful.referral,
|
|
1992
|
-
// @ts-ignore
|
|
1993
2358
|
coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
|
|
1994
2359
|
}
|
|
1995
2360
|
})
|
|
@@ -2000,6 +2365,25 @@ var initRequest = ({
|
|
|
2000
2365
|
return data;
|
|
2001
2366
|
});
|
|
2002
2367
|
},
|
|
2368
|
+
/**
|
|
2369
|
+
* Joins a team using an invite token.
|
|
2370
|
+
* The invite token is typically sent by a team admin via email.
|
|
2371
|
+
*
|
|
2372
|
+
* @param params - Join parameters
|
|
2373
|
+
* @param params.inviteToken - The invite token received from the team admin
|
|
2374
|
+
* @returns Promise resolving when the member has joined the team
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```typescript
|
|
2378
|
+
* // Extract token from URL (e.g., /join?token=abc123)
|
|
2379
|
+
* const token = new URLSearchParams(window.location.search).get('token');
|
|
2380
|
+
*
|
|
2381
|
+
* await memberstack.joinTeam({
|
|
2382
|
+
* inviteToken: token
|
|
2383
|
+
* });
|
|
2384
|
+
* console.log('Successfully joined the team!');
|
|
2385
|
+
* ```
|
|
2386
|
+
*/
|
|
2003
2387
|
joinTeam(params, options) {
|
|
2004
2388
|
return __async(this, null, function* () {
|
|
2005
2389
|
return sendRequest({
|
|
@@ -2012,6 +2396,21 @@ var initRequest = ({
|
|
|
2012
2396
|
});
|
|
2013
2397
|
});
|
|
2014
2398
|
},
|
|
2399
|
+
/**
|
|
2400
|
+
* Retrieves information about a team the current member belongs to.
|
|
2401
|
+
*
|
|
2402
|
+
* @param params - Team parameters
|
|
2403
|
+
* @param params.teamId - The ID of the team to retrieve
|
|
2404
|
+
* @returns Promise resolving to the team details
|
|
2405
|
+
*
|
|
2406
|
+
* @example
|
|
2407
|
+
* ```typescript
|
|
2408
|
+
* const team = await memberstack.getTeam({
|
|
2409
|
+
* teamId: 'team_abc123'
|
|
2410
|
+
* });
|
|
2411
|
+
* console.log('Team members:', team);
|
|
2412
|
+
* ```
|
|
2413
|
+
*/
|
|
2015
2414
|
getTeam(params, options) {
|
|
2016
2415
|
return __async(this, null, function* () {
|
|
2017
2416
|
return sendRequest({
|
|
@@ -2021,6 +2420,24 @@ var initRequest = ({
|
|
|
2021
2420
|
});
|
|
2022
2421
|
});
|
|
2023
2422
|
},
|
|
2423
|
+
/**
|
|
2424
|
+
* Removes a member from a team.
|
|
2425
|
+
* Only team admins can remove other members.
|
|
2426
|
+
*
|
|
2427
|
+
* @param params - Removal parameters
|
|
2428
|
+
* @param params.teamId - The ID of the team
|
|
2429
|
+
* @param params.memberId - The ID of the member to remove
|
|
2430
|
+
* @returns Promise resolving when the member has been removed
|
|
2431
|
+
*
|
|
2432
|
+
* @example
|
|
2433
|
+
* ```typescript
|
|
2434
|
+
* await memberstack.removeMemberFromTeam({
|
|
2435
|
+
* teamId: 'team_abc123',
|
|
2436
|
+
* memberId: 'mem_xyz789'
|
|
2437
|
+
* });
|
|
2438
|
+
* console.log('Member removed from team');
|
|
2439
|
+
* ```
|
|
2440
|
+
*/
|
|
2024
2441
|
removeMemberFromTeam(params, options) {
|
|
2025
2442
|
return __async(this, null, function* () {
|
|
2026
2443
|
return sendRequest({
|
|
@@ -2034,6 +2451,23 @@ var initRequest = ({
|
|
|
2034
2451
|
});
|
|
2035
2452
|
});
|
|
2036
2453
|
},
|
|
2454
|
+
/**
|
|
2455
|
+
* Generates an invite token for a team.
|
|
2456
|
+
* The token can be shared with users to invite them to join the team.
|
|
2457
|
+
*
|
|
2458
|
+
* @param params - Token parameters
|
|
2459
|
+
* @param params.teamId - The ID of the team to generate an invite for
|
|
2460
|
+
* @returns Promise resolving to the generated invite token
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* ```typescript
|
|
2464
|
+
* const invite = await memberstack.generateInviteToken({
|
|
2465
|
+
* teamId: 'team_abc123'
|
|
2466
|
+
* });
|
|
2467
|
+
* // Share the invite link with new team members
|
|
2468
|
+
* const inviteUrl = `${window.location.origin}/join?token=${invite.token}`;
|
|
2469
|
+
* ```
|
|
2470
|
+
*/
|
|
2037
2471
|
generateInviteToken(params, options) {
|
|
2038
2472
|
return __async(this, null, function* () {
|
|
2039
2473
|
return sendRequest({
|
|
@@ -2047,12 +2481,12 @@ var initRequest = ({
|
|
|
2047
2481
|
});
|
|
2048
2482
|
},
|
|
2049
2483
|
/**
|
|
2050
|
-
*
|
|
2051
|
-
*
|
|
2484
|
+
* Updates or removes the current member's profile image.
|
|
2485
|
+
* Pass a File to upload a new image, or null to remove the existing image.
|
|
2052
2486
|
*
|
|
2053
2487
|
* @param params - Image parameters
|
|
2054
|
-
* @param params.profileImage - The image file to upload
|
|
2055
|
-
* @returns Promise resolving to the new profile image URL
|
|
2488
|
+
* @param params.profileImage - The image file to upload, or null to remove
|
|
2489
|
+
* @returns Promise resolving to the new profile image URL (or null if removed)
|
|
2056
2490
|
*
|
|
2057
2491
|
* @example Upload from file input
|
|
2058
2492
|
* ```typescript
|
|
@@ -2064,11 +2498,24 @@ var initRequest = ({
|
|
|
2064
2498
|
* });
|
|
2065
2499
|
* console.log('New image URL:', data.profileImage);
|
|
2066
2500
|
* ```
|
|
2501
|
+
*
|
|
2502
|
+
* @example Remove profile image
|
|
2503
|
+
* ```typescript
|
|
2504
|
+
* const { data } = await memberstack.updateMemberProfileImage({
|
|
2505
|
+
* profileImage: null
|
|
2506
|
+
* });
|
|
2507
|
+
* console.log('Image removed:', data.profileImage === null);
|
|
2508
|
+
* ```
|
|
2509
|
+
*
|
|
2510
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
2067
2511
|
*/
|
|
2068
2512
|
updateMemberProfileImage(params) {
|
|
2069
2513
|
return __async(this, null, function* () {
|
|
2070
|
-
if (
|
|
2071
|
-
|
|
2514
|
+
if (params.profileImage === null) {
|
|
2515
|
+
return sendRequest({
|
|
2516
|
+
method: "DELETE" /* DELETE */,
|
|
2517
|
+
url: `/member/profile-image`
|
|
2518
|
+
});
|
|
2072
2519
|
}
|
|
2073
2520
|
const formData = new FormData();
|
|
2074
2521
|
formData.append("profileImage", params.profileImage);
|
|
@@ -2080,6 +2527,28 @@ var initRequest = ({
|
|
|
2080
2527
|
});
|
|
2081
2528
|
});
|
|
2082
2529
|
},
|
|
2530
|
+
/**
|
|
2531
|
+
* Removes the current member's profile image.
|
|
2532
|
+
* After deletion, the member's profileImage field will be null.
|
|
2533
|
+
*
|
|
2534
|
+
* @returns Promise resolving to confirmation that the image was removed
|
|
2535
|
+
*
|
|
2536
|
+
* @example
|
|
2537
|
+
* ```typescript
|
|
2538
|
+
* await memberstack.deleteMemberProfileImage();
|
|
2539
|
+
* console.log('Profile image removed');
|
|
2540
|
+
* ```
|
|
2541
|
+
*
|
|
2542
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
|
|
2543
|
+
*/
|
|
2544
|
+
deleteMemberProfileImage() {
|
|
2545
|
+
return __async(this, null, function* () {
|
|
2546
|
+
return sendRequest({
|
|
2547
|
+
method: "DELETE" /* DELETE */,
|
|
2548
|
+
url: `/member/profile-image`
|
|
2549
|
+
});
|
|
2550
|
+
});
|
|
2551
|
+
},
|
|
2083
2552
|
/**
|
|
2084
2553
|
* Sends a verification email to the current member.
|
|
2085
2554
|
* Use this when email verification is enabled in your Memberstack settings.
|
|
@@ -2091,6 +2560,8 @@ var initRequest = ({
|
|
|
2091
2560
|
* await memberstack.sendMemberVerificationEmail();
|
|
2092
2561
|
* // Show message: "Verification email sent! Check your inbox."
|
|
2093
2562
|
* ```
|
|
2563
|
+
*
|
|
2564
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Verification Documentation}
|
|
2094
2565
|
*/
|
|
2095
2566
|
sendMemberVerificationEmail() {
|
|
2096
2567
|
return __async(this, null, function* () {
|
|
@@ -2119,6 +2590,8 @@ var initRequest = ({
|
|
|
2119
2590
|
* });
|
|
2120
2591
|
* // Show confirmation: "Check your email for reset instructions"
|
|
2121
2592
|
* ```
|
|
2593
|
+
*
|
|
2594
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
|
|
2122
2595
|
*/
|
|
2123
2596
|
sendMemberResetPasswordEmail(params) {
|
|
2124
2597
|
return __async(this, null, function* () {
|
|
@@ -2152,6 +2625,8 @@ var initRequest = ({
|
|
|
2152
2625
|
* });
|
|
2153
2626
|
* // Password updated, redirect to login
|
|
2154
2627
|
* ```
|
|
2628
|
+
*
|
|
2629
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
|
|
2155
2630
|
*/
|
|
2156
2631
|
resetMemberPassword(params) {
|
|
2157
2632
|
return __async(this, null, function* () {
|
|
@@ -2185,6 +2660,8 @@ var initRequest = ({
|
|
|
2185
2660
|
* window.location.href = data.redirect;
|
|
2186
2661
|
* }
|
|
2187
2662
|
* ```
|
|
2663
|
+
*
|
|
2664
|
+
* @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
|
|
2188
2665
|
*/
|
|
2189
2666
|
logout(options) {
|
|
2190
2667
|
return __async(this, null, function* () {
|
|
@@ -2206,11 +2683,13 @@ var initRequest = ({
|
|
|
2206
2683
|
*
|
|
2207
2684
|
* @example
|
|
2208
2685
|
* ```typescript
|
|
2209
|
-
* const { data
|
|
2210
|
-
* tables.forEach(table => {
|
|
2686
|
+
* const { data } = await memberstack.getDataTables();
|
|
2687
|
+
* data.tables.forEach(table => {
|
|
2211
2688
|
* console.log('Table:', table.name, table.key);
|
|
2212
2689
|
* });
|
|
2213
2690
|
* ```
|
|
2691
|
+
*
|
|
2692
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2214
2693
|
*/
|
|
2215
2694
|
getDataTables(options) {
|
|
2216
2695
|
return __async(this, null, function* () {
|
|
@@ -2233,14 +2712,15 @@ var initRequest = ({
|
|
|
2233
2712
|
* const { data: table } = await memberstack.getDataTable({
|
|
2234
2713
|
* table: 'posts'
|
|
2235
2714
|
* });
|
|
2236
|
-
* console.log('
|
|
2715
|
+
* console.log('Fields:', table.fields.map(f => f.name));
|
|
2237
2716
|
* ```
|
|
2717
|
+
*
|
|
2718
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2238
2719
|
*/
|
|
2239
2720
|
getDataTable(params, options) {
|
|
2240
2721
|
return __async(this, null, function* () {
|
|
2241
2722
|
return sendRequest({
|
|
2242
2723
|
method: "GET" /* GET */,
|
|
2243
|
-
//@ts-ignore
|
|
2244
2724
|
url: `/v1/data-tables/${params.table || params.tableKey}`,
|
|
2245
2725
|
headers: addHeaders(options)
|
|
2246
2726
|
});
|
|
@@ -2269,6 +2749,8 @@ var initRequest = ({
|
|
|
2269
2749
|
* });
|
|
2270
2750
|
* console.log('Records:', data.records);
|
|
2271
2751
|
* ```
|
|
2752
|
+
*
|
|
2753
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2272
2754
|
*/
|
|
2273
2755
|
getDataRecords(params, options) {
|
|
2274
2756
|
return __async(this, null, function* () {
|
|
@@ -2294,7 +2776,6 @@ var initRequest = ({
|
|
|
2294
2776
|
method: "POST" /* POST */,
|
|
2295
2777
|
url: `/v1/data-records/query`,
|
|
2296
2778
|
data: {
|
|
2297
|
-
// @ts-ignore
|
|
2298
2779
|
table: params.table || params.tableKey,
|
|
2299
2780
|
query: {
|
|
2300
2781
|
findMany: query
|
|
@@ -2333,6 +2814,8 @@ var initRequest = ({
|
|
|
2333
2814
|
* });
|
|
2334
2815
|
* console.log('Created record:', record.id);
|
|
2335
2816
|
* ```
|
|
2817
|
+
*
|
|
2818
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2336
2819
|
*/
|
|
2337
2820
|
createDataRecord(params, options) {
|
|
2338
2821
|
return __async(this, null, function* () {
|
|
@@ -2363,6 +2846,8 @@ var initRequest = ({
|
|
|
2363
2846
|
* });
|
|
2364
2847
|
* console.log('Post:', record.title);
|
|
2365
2848
|
* ```
|
|
2849
|
+
*
|
|
2850
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2366
2851
|
*/
|
|
2367
2852
|
getDataRecord(params, options) {
|
|
2368
2853
|
return __async(this, null, function* () {
|
|
@@ -2404,6 +2889,8 @@ var initRequest = ({
|
|
|
2404
2889
|
* }
|
|
2405
2890
|
* });
|
|
2406
2891
|
* ```
|
|
2892
|
+
*
|
|
2893
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2407
2894
|
*/
|
|
2408
2895
|
updateDataRecord(params, options) {
|
|
2409
2896
|
return __async(this, null, function* () {
|
|
@@ -2430,6 +2917,8 @@ var initRequest = ({
|
|
|
2430
2917
|
* recordId: 'rec_abc123'
|
|
2431
2918
|
* });
|
|
2432
2919
|
* ```
|
|
2920
|
+
*
|
|
2921
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2433
2922
|
*/
|
|
2434
2923
|
deleteDataRecord(params, options) {
|
|
2435
2924
|
return __async(this, null, function* () {
|
|
@@ -2475,6 +2964,8 @@ var initRequest = ({
|
|
|
2475
2964
|
* }
|
|
2476
2965
|
* });
|
|
2477
2966
|
* ```
|
|
2967
|
+
*
|
|
2968
|
+
* @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
|
|
2478
2969
|
*/
|
|
2479
2970
|
queryDataRecords(params, options) {
|
|
2480
2971
|
return __async(this, null, function* () {
|
|
@@ -2482,7 +2973,7 @@ var initRequest = ({
|
|
|
2482
2973
|
method: "POST" /* POST */,
|
|
2483
2974
|
url: `/v1/data-records/query`,
|
|
2484
2975
|
data: {
|
|
2485
|
-
table: params.table,
|
|
2976
|
+
table: params.table || params.tableKey,
|
|
2486
2977
|
query: {
|
|
2487
2978
|
findMany: params.query
|
|
2488
2979
|
}
|
|
@@ -2504,6 +2995,9 @@ function setDebugMode(enabled) {
|
|
|
2504
2995
|
"color: #6366f1; font-weight: bold;"
|
|
2505
2996
|
);
|
|
2506
2997
|
}
|
|
2998
|
+
if (!enabled && typeof window !== "undefined") {
|
|
2999
|
+
delete window.__MEMBERSTACK_DEBUG__;
|
|
3000
|
+
}
|
|
2507
3001
|
}
|
|
2508
3002
|
function debugLog(message, ...args) {
|
|
2509
3003
|
if (debugEnabled) {
|
|
@@ -2522,8 +3016,8 @@ function initDevToolsIntegration(state) {
|
|
|
2522
3016
|
publicKey: state.config.publicKey,
|
|
2523
3017
|
appId: state.config.appId
|
|
2524
3018
|
},
|
|
2525
|
-
getMember:
|
|
2526
|
-
isAuthenticated: () => state.
|
|
3019
|
+
getMember: state.getMember,
|
|
3020
|
+
isAuthenticated: () => state.getMember() !== null,
|
|
2527
3021
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2528
3022
|
};
|
|
2529
3023
|
debugLog("DevTools integration initialized. Access via window.__MEMBERSTACK_DEBUG__");
|
|
@@ -2532,6 +3026,7 @@ function initDevToolsIntegration(state) {
|
|
|
2532
3026
|
|
|
2533
3027
|
// src/methods/index.ts
|
|
2534
3028
|
var SDK_VERSION = "1.2.0";
|
|
3029
|
+
var initialized = false;
|
|
2535
3030
|
var captchaReadyPromise = new Promise((resolve) => {
|
|
2536
3031
|
if (typeof window !== "undefined") {
|
|
2537
3032
|
window._hcaptchaReady = resolve;
|
|
@@ -2549,6 +3044,16 @@ var methods = {
|
|
|
2549
3044
|
_captchaReady: captchaReadyPromise
|
|
2550
3045
|
};
|
|
2551
3046
|
function init(props) {
|
|
3047
|
+
if (!props.publicKey) {
|
|
3048
|
+
throw new Error(
|
|
3049
|
+
"Memberstack: publicKey is required. Pass your public key to init({ publicKey: 'pk_...' }). Find your key at https://app.memberstack.com/apps"
|
|
3050
|
+
);
|
|
3051
|
+
}
|
|
3052
|
+
if (!props.publicKey.startsWith("pk_")) {
|
|
3053
|
+
throw new Error(
|
|
3054
|
+
`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`
|
|
3055
|
+
);
|
|
3056
|
+
}
|
|
2552
3057
|
if (props.debug) {
|
|
2553
3058
|
setDebugMode(true);
|
|
2554
3059
|
debugLog(`Initializing Memberstack SDK v${SDK_VERSION}`);
|
|
@@ -2559,6 +3064,17 @@ function init(props) {
|
|
|
2559
3064
|
domain: props.domain
|
|
2560
3065
|
});
|
|
2561
3066
|
}
|
|
3067
|
+
if (initialized && props.debug) {
|
|
3068
|
+
console.warn(
|
|
3069
|
+
"[Memberstack] init() called multiple times. Previous instance will be replaced. This is usually unintentional \u2014 call init() once at app startup."
|
|
3070
|
+
);
|
|
3071
|
+
}
|
|
3072
|
+
if (props.sessionDurationDays !== void 0) {
|
|
3073
|
+
console.warn(
|
|
3074
|
+
"[Memberstack] sessionDurationDays is deprecated and no longer used. Session duration is now controlled server-side. You can safely remove this option."
|
|
3075
|
+
);
|
|
3076
|
+
}
|
|
3077
|
+
initialized = true;
|
|
2562
3078
|
const apiDomain2 = props.domain || endpoints.API || "https://client.memberstack.com";
|
|
2563
3079
|
setApiDomain(apiDomain2);
|
|
2564
3080
|
if (props.useCookies)
|
|
@@ -2570,14 +3086,13 @@ function init(props) {
|
|
|
2570
3086
|
token: getMemberToken(),
|
|
2571
3087
|
domain: apiDomain2
|
|
2572
3088
|
});
|
|
2573
|
-
const allMethods = Object.assign(methods, requests);
|
|
3089
|
+
const allMethods = Object.assign(methods, requests, { destroy });
|
|
2574
3090
|
if (typeof window !== "undefined") {
|
|
2575
3091
|
window.$memberstackDom = allMethods;
|
|
2576
3092
|
if (props.debug) {
|
|
2577
3093
|
initDevToolsIntegration({
|
|
2578
3094
|
config: { publicKey: props.publicKey, appId: props.appId },
|
|
2579
|
-
|
|
2580
|
-
// Will be updated by auth state
|
|
3095
|
+
getMember: () => getPersistedMember(),
|
|
2581
3096
|
version: SDK_VERSION
|
|
2582
3097
|
});
|
|
2583
3098
|
}
|
|
@@ -2587,6 +3102,14 @@ function init(props) {
|
|
|
2587
3102
|
}
|
|
2588
3103
|
return allMethods;
|
|
2589
3104
|
}
|
|
3105
|
+
function destroy() {
|
|
3106
|
+
unsetPersistedMember();
|
|
3107
|
+
initialized = false;
|
|
3108
|
+
if (typeof window !== "undefined") {
|
|
3109
|
+
delete window.$memberstackDom;
|
|
3110
|
+
delete window.__MEMBERSTACK_DEBUG__;
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
2590
3113
|
var methods_default = { init: (props) => init(props) };
|
|
2591
3114
|
|
|
2592
3115
|
// src/utils/errors.ts
|
|
@@ -2938,10 +3461,266 @@ var ErrorMetadata = {
|
|
|
2938
3461
|
"Clear your browser cache and try again"
|
|
2939
3462
|
],
|
|
2940
3463
|
docsUrl: "https://docs.memberstack.com/dom/authentication"
|
|
3464
|
+
},
|
|
3465
|
+
// Authentication — additional
|
|
3466
|
+
[ErrorCodes.MEMBER_NOT_FOUND]: {
|
|
3467
|
+
message: "No member found with this identifier.",
|
|
3468
|
+
category: "authentication",
|
|
3469
|
+
suggestions: [
|
|
3470
|
+
"Verify the email address is correct",
|
|
3471
|
+
"The member may not have signed up yet \u2014 use signupMemberEmailPassword()",
|
|
3472
|
+
"Check if the member exists in the correct environment (SANDBOX vs LIVE)"
|
|
3473
|
+
],
|
|
3474
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/login"
|
|
3475
|
+
},
|
|
3476
|
+
// Account & Social Login — additional
|
|
3477
|
+
[ErrorCodes.ACCOUNT_NOT_FOUND]: {
|
|
3478
|
+
message: "No account found with these credentials.",
|
|
3479
|
+
category: "authentication",
|
|
3480
|
+
suggestions: [
|
|
3481
|
+
"The member may need to sign up first",
|
|
3482
|
+
"Check if the account was created with a different auth method (email vs social)",
|
|
3483
|
+
"Verify the correct environment (SANDBOX vs LIVE)"
|
|
3484
|
+
]
|
|
3485
|
+
},
|
|
3486
|
+
[ErrorCodes.ACCOUNT_ALREADY_CONNECTED]: {
|
|
3487
|
+
message: "This social account is already connected.",
|
|
3488
|
+
category: "conflict",
|
|
3489
|
+
suggestions: [
|
|
3490
|
+
"Use disconnectProvider() first if you need to reconnect",
|
|
3491
|
+
"Check the member's connected providers with getCurrentMember()"
|
|
3492
|
+
],
|
|
3493
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3494
|
+
},
|
|
3495
|
+
[ErrorCodes.ACCOUNT_NOT_CONNECTED]: {
|
|
3496
|
+
message: "This social account is not connected to the member.",
|
|
3497
|
+
category: "not_found",
|
|
3498
|
+
suggestions: [
|
|
3499
|
+
"Use connectProvider() to connect the social account first",
|
|
3500
|
+
"Check the member's connected providers with getCurrentMember()"
|
|
3501
|
+
],
|
|
3502
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3503
|
+
},
|
|
3504
|
+
[ErrorCodes.ACCOUNT_CONNECT_FAILED]: {
|
|
3505
|
+
message: "Failed to connect the social account.",
|
|
3506
|
+
category: "authentication",
|
|
3507
|
+
suggestions: [
|
|
3508
|
+
"Try the connection again \u2014 this may be a temporary issue",
|
|
3509
|
+
"Ensure the social provider is enabled in your Memberstack dashboard",
|
|
3510
|
+
"Check that the OAuth redirect URLs are configured correctly"
|
|
3511
|
+
],
|
|
3512
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3513
|
+
},
|
|
3514
|
+
[ErrorCodes.ACCOUNT_CONNECT_REQUIRES_LOGIN]: {
|
|
3515
|
+
message: "You must be logged in to connect a social account.",
|
|
3516
|
+
category: "authentication",
|
|
3517
|
+
suggestions: [
|
|
3518
|
+
"Call loginMemberEmailPassword() or loginWithProvider() first",
|
|
3519
|
+
"Use getCurrentMember() to verify the member is authenticated"
|
|
3520
|
+
],
|
|
3521
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3522
|
+
},
|
|
3523
|
+
[ErrorCodes.ACCOUNT_SET_PASSWORD_FIRST]: {
|
|
3524
|
+
message: "Set a password before disconnecting your last login provider.",
|
|
3525
|
+
category: "authentication",
|
|
3526
|
+
suggestions: [
|
|
3527
|
+
"Use setPassword() to add a password before disconnecting",
|
|
3528
|
+
"This prevents the member from being locked out of their account"
|
|
3529
|
+
],
|
|
3530
|
+
docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
|
|
3531
|
+
},
|
|
3532
|
+
// Validation — additional
|
|
3533
|
+
[ErrorCodes.INVALID_PASSWORD]: {
|
|
3534
|
+
message: "The password is incorrect.",
|
|
3535
|
+
category: "authentication",
|
|
3536
|
+
suggestions: [
|
|
3537
|
+
"Check that the current password is entered correctly",
|
|
3538
|
+
"Use sendMemberResetPasswordEmail() to reset the password"
|
|
3539
|
+
]
|
|
3540
|
+
},
|
|
3541
|
+
[ErrorCodes.REQUIRED_FIELD_MISSING]: {
|
|
3542
|
+
message: "A required field is missing.",
|
|
3543
|
+
category: "validation",
|
|
3544
|
+
suggestions: [
|
|
3545
|
+
"Check that all required parameters are provided",
|
|
3546
|
+
"Review the method documentation for required fields",
|
|
3547
|
+
"Custom fields marked as required in the dashboard must be included on signup"
|
|
3548
|
+
]
|
|
3549
|
+
},
|
|
3550
|
+
[ErrorCodes.INVALID_CAPTCHA]: {
|
|
3551
|
+
message: "CAPTCHA verification failed.",
|
|
3552
|
+
category: "validation",
|
|
3553
|
+
suggestions: [
|
|
3554
|
+
"Ensure the CAPTCHA token is passed as captchaToken in the request",
|
|
3555
|
+
"The token may have expired \u2014 request a new CAPTCHA challenge",
|
|
3556
|
+
"Check that CAPTCHA is correctly configured in your Memberstack dashboard"
|
|
3557
|
+
]
|
|
3558
|
+
},
|
|
3559
|
+
// Plans — additional
|
|
3560
|
+
[ErrorCodes.NO_PLAN_FOUND]: {
|
|
3561
|
+
message: "The member does not have this plan.",
|
|
3562
|
+
category: "not_found",
|
|
3563
|
+
suggestions: [
|
|
3564
|
+
"Use getCurrentMember() to check the member's current plans",
|
|
3565
|
+
"Verify the plan ID is correct",
|
|
3566
|
+
"The plan may have been removed or expired"
|
|
3567
|
+
],
|
|
3568
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3569
|
+
},
|
|
3570
|
+
[ErrorCodes.PLAN_MEMBER_LIMIT_REACHED]: {
|
|
3571
|
+
message: "This plan has reached its member limit.",
|
|
3572
|
+
category: "limit",
|
|
3573
|
+
suggestions: [
|
|
3574
|
+
"Contact the app owner to increase the plan's member limit",
|
|
3575
|
+
"Check if a different plan is available"
|
|
3576
|
+
],
|
|
3577
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3578
|
+
},
|
|
3579
|
+
[ErrorCodes.PLAN_RESTRICTED_TO_ADMIN]: {
|
|
3580
|
+
message: "This plan can only be assigned by an admin.",
|
|
3581
|
+
category: "authorization",
|
|
3582
|
+
suggestions: [
|
|
3583
|
+
"Plans with this restriction cannot be self-assigned by members",
|
|
3584
|
+
"Use the Admin API or dashboard to assign this plan"
|
|
3585
|
+
],
|
|
3586
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3587
|
+
},
|
|
3588
|
+
[ErrorCodes.DOMAIN_NOT_PERMITTED]: {
|
|
3589
|
+
message: "Your email domain is not permitted for this plan.",
|
|
3590
|
+
category: "authorization",
|
|
3591
|
+
suggestions: [
|
|
3592
|
+
"This plan restricts signup to specific email domains",
|
|
3593
|
+
"Check the plan's domain restrictions in your Memberstack dashboard",
|
|
3594
|
+
"Use an email address with an allowed domain"
|
|
3595
|
+
],
|
|
3596
|
+
docsUrl: "https://docs.memberstack.com/dom/plans"
|
|
3597
|
+
},
|
|
3598
|
+
[ErrorCodes.PRICE_NOT_AVAILABLE]: {
|
|
3599
|
+
message: "This pricing option is no longer available.",
|
|
3600
|
+
category: "not_found",
|
|
3601
|
+
suggestions: [
|
|
3602
|
+
"Use getPlans() to see currently available pricing options",
|
|
3603
|
+
"The price may have been archived or deactivated",
|
|
3604
|
+
"Check your Stripe dashboard for the price status"
|
|
3605
|
+
],
|
|
3606
|
+
docsUrl: "https://docs.memberstack.com/dom/payments"
|
|
3607
|
+
},
|
|
3608
|
+
// Teams — additional
|
|
3609
|
+
[ErrorCodes.ONE_ACTIVE_TEAM_ONLY]: {
|
|
3610
|
+
message: "A member can only belong to one active team.",
|
|
3611
|
+
category: "conflict",
|
|
3612
|
+
suggestions: [
|
|
3613
|
+
"Remove the member from their current team first using removeMemberFromTeam()",
|
|
3614
|
+
"Check the member's current team with getTeam()"
|
|
3615
|
+
],
|
|
3616
|
+
docsUrl: "https://docs.memberstack.com/dom/teams"
|
|
3617
|
+
},
|
|
3618
|
+
[ErrorCodes.CANNOT_CHANGE_TEAM]: {
|
|
3619
|
+
message: "Cannot change team while it has active members.",
|
|
3620
|
+
category: "conflict",
|
|
3621
|
+
suggestions: [
|
|
3622
|
+
"Remove all team members before making this change",
|
|
3623
|
+
"Use removeMemberFromTeam() to remove members first"
|
|
3624
|
+
],
|
|
3625
|
+
docsUrl: "https://docs.memberstack.com/dom/teams"
|
|
3626
|
+
},
|
|
3627
|
+
// Data Tables — additional
|
|
3628
|
+
[ErrorCodes.INVALID_TABLE_KEY]: {
|
|
3629
|
+
message: "The table key format is invalid.",
|
|
3630
|
+
category: "data_tables",
|
|
3631
|
+
suggestions: [
|
|
3632
|
+
"Table keys should be lowercase alphanumeric with hyphens",
|
|
3633
|
+
"Use getDataTables() to list available tables and their keys",
|
|
3634
|
+
"Check the table key in your Memberstack dashboard"
|
|
3635
|
+
],
|
|
3636
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3637
|
+
},
|
|
3638
|
+
[ErrorCodes.UNIQUE_CONSTRAINT_VIOLATION]: {
|
|
3639
|
+
message: "A record with this value already exists (unique constraint).",
|
|
3640
|
+
category: "data_tables",
|
|
3641
|
+
suggestions: [
|
|
3642
|
+
"The field has a unique constraint \u2014 use a different value",
|
|
3643
|
+
"Use queryDataRecords() to check for existing records before creating",
|
|
3644
|
+
"If updating, use updateDataRecord() instead of createDataRecord()"
|
|
3645
|
+
],
|
|
3646
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3647
|
+
},
|
|
3648
|
+
[ErrorCodes.FIELD_LIMIT_EXCEEDED]: {
|
|
3649
|
+
message: "Maximum number of fields reached for this table.",
|
|
3650
|
+
category: "data_tables",
|
|
3651
|
+
suggestions: [
|
|
3652
|
+
"Remove unused fields before adding new ones",
|
|
3653
|
+
"Consider using a separate table for additional data",
|
|
3654
|
+
"Check your plan's field limits in the dashboard"
|
|
3655
|
+
],
|
|
3656
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3657
|
+
},
|
|
3658
|
+
[ErrorCodes.INVALID_FIELD_TYPE]: {
|
|
3659
|
+
message: "This field type is not supported.",
|
|
3660
|
+
category: "data_tables",
|
|
3661
|
+
suggestions: [
|
|
3662
|
+
"Check the supported field types in the documentation",
|
|
3663
|
+
"Use getDataTable() to see the table schema and field types"
|
|
3664
|
+
],
|
|
3665
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3666
|
+
},
|
|
3667
|
+
[ErrorCodes.INVALID_FIELD_VALUE]: {
|
|
3668
|
+
message: "The field value does not match the expected type.",
|
|
3669
|
+
category: "data_tables",
|
|
3670
|
+
suggestions: [
|
|
3671
|
+
"Check the field type \u2014 e.g., number fields require numeric values",
|
|
3672
|
+
"Use getDataTable() to see the expected field types",
|
|
3673
|
+
"Ensure dates are in ISO 8601 format for date fields"
|
|
3674
|
+
],
|
|
3675
|
+
docsUrl: "https://docs.memberstack.com/data-tables"
|
|
3676
|
+
},
|
|
3677
|
+
// Permissions
|
|
3678
|
+
[ErrorCodes.ACCESS_DENIED]: {
|
|
3679
|
+
message: "You do not have permission to access this resource.",
|
|
3680
|
+
category: "authorization",
|
|
3681
|
+
suggestions: [
|
|
3682
|
+
"Check that the member has the required plan or permissions",
|
|
3683
|
+
"Verify the content group configuration in the dashboard",
|
|
3684
|
+
"Use getCurrentMember() to check the member's permissions array"
|
|
3685
|
+
],
|
|
3686
|
+
docsUrl: "https://docs.memberstack.com/dom/content-protection"
|
|
3687
|
+
},
|
|
3688
|
+
// Catch-all
|
|
3689
|
+
[ErrorCodes.UNKNOWN_ERROR]: {
|
|
3690
|
+
message: "An unexpected error occurred.",
|
|
3691
|
+
category: "unknown",
|
|
3692
|
+
suggestions: [
|
|
3693
|
+
"Try the request again",
|
|
3694
|
+
"Check the Memberstack status page for any ongoing issues",
|
|
3695
|
+
"If the problem persists, contact support with the error details"
|
|
3696
|
+
]
|
|
2941
3697
|
}
|
|
2942
3698
|
};
|
|
3699
|
+
function normalizeErrorCode(code) {
|
|
3700
|
+
return code.toLowerCase().replace(/_/g, "-");
|
|
3701
|
+
}
|
|
3702
|
+
function getMetadataForCode(code) {
|
|
3703
|
+
if (ErrorMetadata[code]) {
|
|
3704
|
+
return ErrorMetadata[code];
|
|
3705
|
+
}
|
|
3706
|
+
const normalized = normalizeErrorCode(code);
|
|
3707
|
+
for (const key of Object.keys(ErrorMetadata)) {
|
|
3708
|
+
if (normalizeErrorCode(key) === normalized) {
|
|
3709
|
+
return ErrorMetadata[key];
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
return void 0;
|
|
3713
|
+
}
|
|
3714
|
+
var knownErrorCodes = new Set(Object.values(ErrorCodes));
|
|
2943
3715
|
function isMemberstackError(error) {
|
|
2944
|
-
|
|
3716
|
+
if (typeof error !== "object" || error === null || !("code" in error) || !("message" in error) || typeof error.code !== "string" || typeof error.message !== "string") {
|
|
3717
|
+
return false;
|
|
3718
|
+
}
|
|
3719
|
+
const code = error.code;
|
|
3720
|
+
if (knownErrorCodes.has(code) || knownErrorCodes.has(normalizeErrorCode(code))) {
|
|
3721
|
+
return true;
|
|
3722
|
+
}
|
|
3723
|
+
return code.includes("-") || code.includes("/");
|
|
2945
3724
|
}
|
|
2946
3725
|
function getErrorMessage(error, defaultMessage = "An unexpected error occurred") {
|
|
2947
3726
|
if (isMemberstackError(error)) {
|
|
@@ -2977,7 +3756,7 @@ function getErrorSuggestions(error) {
|
|
|
2977
3756
|
if (error.suggestions && error.suggestions.length > 0) {
|
|
2978
3757
|
return error.suggestions;
|
|
2979
3758
|
}
|
|
2980
|
-
const metadata =
|
|
3759
|
+
const metadata = getMetadataForCode(error.code);
|
|
2981
3760
|
return (metadata == null ? void 0 : metadata.suggestions) || [];
|
|
2982
3761
|
}
|
|
2983
3762
|
function getErrorDocsUrl(error) {
|
|
@@ -2987,7 +3766,7 @@ function getErrorDocsUrl(error) {
|
|
|
2987
3766
|
if (error.docsUrl) {
|
|
2988
3767
|
return error.docsUrl;
|
|
2989
3768
|
}
|
|
2990
|
-
const metadata =
|
|
3769
|
+
const metadata = getMetadataForCode(error.code);
|
|
2991
3770
|
return metadata == null ? void 0 : metadata.docsUrl;
|
|
2992
3771
|
}
|
|
2993
3772
|
function getErrorCategory(error) {
|
|
@@ -2997,18 +3776,18 @@ function getErrorCategory(error) {
|
|
|
2997
3776
|
if (error.category) {
|
|
2998
3777
|
return error.category;
|
|
2999
3778
|
}
|
|
3000
|
-
const metadata =
|
|
3779
|
+
const metadata = getMetadataForCode(error.code);
|
|
3001
3780
|
return (metadata == null ? void 0 : metadata.category) || "unknown";
|
|
3002
3781
|
}
|
|
3003
3782
|
function formatErrorForUser(error) {
|
|
3004
3783
|
if (!isMemberstackError(error)) {
|
|
3005
3784
|
return "An unexpected error occurred. Please try again.";
|
|
3006
3785
|
}
|
|
3007
|
-
const metadata =
|
|
3786
|
+
const metadata = getMetadataForCode(error.code);
|
|
3008
3787
|
if (metadata) {
|
|
3009
3788
|
return metadata.message;
|
|
3010
3789
|
}
|
|
3011
|
-
return
|
|
3790
|
+
return "Something went wrong. Please try again or contact support.";
|
|
3012
3791
|
}
|
|
3013
3792
|
function getErrorReport(error) {
|
|
3014
3793
|
if (!isMemberstackError(error)) {
|