@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.
Files changed (87) hide show
  1. package/lib/index.d.mts +61 -26
  2. package/lib/index.d.ts +61 -26
  3. package/lib/index.js +793 -53
  4. package/lib/index.mjs +793 -53
  5. package/lib/{models-CTRKogoR.d.ts → models-CFT_ABd5.d.ts} +2 -2
  6. package/lib/testing/index.d.mts +25 -2
  7. package/lib/testing/index.d.ts +25 -2
  8. package/lib/testing/index.js +28 -6
  9. package/lib/testing/index.mjs +26 -5
  10. package/package.json +1 -1
  11. package/lib/auth/index.d.mts +0 -63
  12. package/lib/auth/index.d.ts +0 -63
  13. package/lib/auth/index.global.js +0 -244
  14. package/lib/auth/index.js +0 -161
  15. package/lib/auth/index.mjs +0 -123
  16. package/lib/constants/endpoints.d.mts +0 -5
  17. package/lib/constants/endpoints.d.ts +0 -5
  18. package/lib/constants/endpoints.global.js +0 -29
  19. package/lib/constants/endpoints.js +0 -32
  20. package/lib/constants/endpoints.mjs +0 -7
  21. package/lib/methods/dom/index.d.mts +0 -2
  22. package/lib/methods/dom/index.d.ts +0 -2
  23. package/lib/methods/dom/index.global.js +0 -2
  24. package/lib/methods/dom/index.js +0 -1
  25. package/lib/methods/dom/index.mjs +0 -0
  26. package/lib/methods/dom/main-dom.d.mts +0 -2
  27. package/lib/methods/dom/main-dom.d.ts +0 -2
  28. package/lib/methods/dom/main-dom.global.js +0 -30620
  29. package/lib/methods/dom/main-dom.js +0 -15611
  30. package/lib/methods/dom/main-dom.mjs +0 -15593
  31. package/lib/methods/dom/methods.d.mts +0 -100
  32. package/lib/methods/dom/methods.d.ts +0 -100
  33. package/lib/methods/dom/methods.global.js +0 -30827
  34. package/lib/methods/dom/methods.js +0 -335
  35. package/lib/methods/dom/methods.mjs +0 -302
  36. package/lib/methods/index.d.mts +0 -185
  37. package/lib/methods/index.d.ts +0 -185
  38. package/lib/methods/index.global.js +0 -46361
  39. package/lib/methods/index.js +0 -2530
  40. package/lib/methods/index.mjs +0 -2500
  41. package/lib/methods/requests/index.d.mts +0 -912
  42. package/lib/methods/requests/index.d.ts +0 -912
  43. package/lib/methods/requests/index.global.js +0 -15553
  44. package/lib/methods/requests/index.js +0 -2145
  45. package/lib/methods/requests/index.mjs +0 -2110
  46. package/lib/methods/requests/requests.d.mts +0 -43
  47. package/lib/methods/requests/requests.d.ts +0 -43
  48. package/lib/methods/requests/requests.global.js +0 -14528
  49. package/lib/methods/requests/requests.js +0 -244
  50. package/lib/methods/requests/requests.mjs +0 -210
  51. package/lib/models-BmZS-mc4.d.ts +0 -193
  52. package/lib/models-le7xaT4H.d.ts +0 -193
  53. package/lib/types/index.d.mts +0 -5
  54. package/lib/types/index.d.ts +0 -5
  55. package/lib/types/index.global.js +0 -19
  56. package/lib/types/index.js +0 -18
  57. package/lib/types/index.mjs +0 -0
  58. package/lib/types/params.d.mts +0 -946
  59. package/lib/types/params.d.ts +0 -946
  60. package/lib/types/params.global.js +0 -19
  61. package/lib/types/params.js +0 -18
  62. package/lib/types/params.mjs +0 -0
  63. package/lib/types/payloads.d.mts +0 -342
  64. package/lib/types/payloads.d.ts +0 -342
  65. package/lib/types/payloads.global.js +0 -19
  66. package/lib/types/payloads.js +0 -18
  67. package/lib/types/payloads.mjs +0 -0
  68. package/lib/types/translations.d.mts +0 -101
  69. package/lib/types/translations.d.ts +0 -101
  70. package/lib/types/translations.global.js +0 -19
  71. package/lib/types/translations.js +0 -18
  72. package/lib/types/translations.mjs +0 -0
  73. package/lib/types/utils/payloads.d.mts +0 -297
  74. package/lib/types/utils/payloads.d.ts +0 -297
  75. package/lib/types/utils/payloads.global.js +0 -19
  76. package/lib/types/utils/payloads.js +0 -18
  77. package/lib/types/utils/payloads.mjs +0 -0
  78. package/lib/utils/cookies.d.mts +0 -13
  79. package/lib/utils/cookies.d.ts +0 -13
  80. package/lib/utils/cookies.global.js +0 -261
  81. package/lib/utils/cookies.js +0 -190
  82. package/lib/utils/cookies.mjs +0 -148
  83. package/lib/utils/defaultMessageBox.d.mts +0 -5
  84. package/lib/utils/defaultMessageBox.d.ts +0 -5
  85. package/lib/utils/defaultMessageBox.global.js +0 -125
  86. package/lib/utils/defaultMessageBox.js +0 -130
  87. package/lib/utils/defaultMessageBox.mjs +0 -103
package/lib/index.js CHANGED
@@ -292,7 +292,7 @@ var showMessage = (msg, isError) => __async(void 0, null, function* () {
292
292
  return;
293
293
  const messageTextBox = messageBox.querySelector("[data-ms-message-text]");
294
294
  if (messageTextBox) {
295
- messageTextBox.innerHTML = msg;
295
+ messageTextBox.textContent = msg;
296
296
  }
297
297
  messageBox.style.display = "block";
298
298
  const closeBtn = messageBox.querySelector("[data-ms-message-close]");
@@ -362,6 +362,7 @@ var hideLoader = (element) => {
362
362
  (_a = document.querySelector("[data-ms-modal-loader]")) == null ? void 0 : _a.remove();
363
363
  };
364
364
  var modal = null;
365
+ var resolveModal;
365
366
  var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, params = {}) {
366
367
  const isInspector = type.toLowerCase() === "inspector";
367
368
  const needsLoading = !prebuiltUILoaded;
@@ -376,7 +377,17 @@ var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, par
376
377
  hideLoader();
377
378
  }
378
379
  }
379
- let resolveModal;
380
+ if (modal) {
381
+ try {
382
+ modal.remove();
383
+ } catch (e) {
384
+ }
385
+ if (resolveModal) {
386
+ resolveModal({ type: "CLOSED" });
387
+ }
388
+ modal = null;
389
+ resolveModal = void 0;
390
+ }
380
391
  const modalPromise = new Promise((resolve) => {
381
392
  resolveModal = resolve;
382
393
  });
@@ -393,6 +404,11 @@ var hideModal = () => {
393
404
  modal == null ? void 0 : modal.remove();
394
405
  } catch (e) {
395
406
  }
407
+ if (resolveModal) {
408
+ resolveModal({ type: "CLOSED" });
409
+ }
410
+ modal = null;
411
+ resolveModal = void 0;
396
412
  };
397
413
 
398
414
  // src/utils/cookies.ts
@@ -453,10 +469,11 @@ var setMemberToken = (token, expires) => {
453
469
  localStorage.setItem(memberAuthTokenName, token);
454
470
  } else {
455
471
  const domain = extractDomainFromHostname(window.location.hostname);
456
- import_js_cookie.default.set(memberAuthTokenName, token, __spreadValues({
472
+ const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
473
+ import_js_cookie.default.set(memberAuthTokenName, token, __spreadValues(__spreadValues({
457
474
  expires: expires && Number(expires) || 14,
458
475
  sameSite: "strict"
459
- }, setCookieOnRootDomain && { domain }));
476
+ }, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
460
477
  }
461
478
  };
462
479
  var removeMemberToken = () => {
@@ -464,14 +481,11 @@ var removeMemberToken = () => {
464
481
  localStorage.removeItem(memberAuthTokenName);
465
482
  }
466
483
  const domain = extractDomainFromHostname(window.location.hostname);
467
- import_js_cookie.default.set(memberAuthTokenName, "", __spreadValues({
468
- expires: -1,
469
- sameSite: "strict"
470
- }, setCookieOnRootDomain && { domain }));
471
- import_js_cookie.default.set(memberAuthTokenName, "", {
484
+ const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
485
+ import_js_cookie.default.set(memberAuthTokenName, "", __spreadValues(__spreadValues({
472
486
  expires: -1,
473
487
  sameSite: "strict"
474
- });
488
+ }, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
475
489
  };
476
490
  var getMemberToken = () => {
477
491
  if (localStorageAvailable) {
@@ -485,8 +499,13 @@ var setMemberTokenIfAvailable = () => {
485
499
  if (typeof window !== "undefined") {
486
500
  const urlParams = new URLSearchParams(window.location.search);
487
501
  const memberToken = urlParams.get("memberToken");
488
- if (memberToken)
502
+ if (memberToken) {
489
503
  setMemberToken(memberToken);
504
+ urlParams.delete("memberToken");
505
+ const newSearch = urlParams.toString();
506
+ const newUrl = newSearch ? `${window.location.pathname}?${newSearch}${window.location.hash}` : `${window.location.pathname}${window.location.hash}`;
507
+ window.history.replaceState({}, "", newUrl);
508
+ }
490
509
  }
491
510
  };
492
511
  var getSessionId = () => {
@@ -529,6 +548,11 @@ var createRequestHandler = ({
529
548
  token,
530
549
  customEndpoint
531
550
  }) => {
551
+ if (!publicKey) {
552
+ throw new Error(
553
+ "Memberstack: publicKey is required. Pass your public key to memberstack.init({ publicKey: 'pk_...' })"
554
+ );
555
+ }
532
556
  return {
533
557
  sendRequest: (data, options) => __async(void 0, null, function* () {
534
558
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -546,7 +570,9 @@ var createRequestHandler = ({
546
570
  method: data.method,
547
571
  data: data.data,
548
572
  url: formattedUrl,
549
- headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
573
+ headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), {
574
+ ["X-API-Key" /* API_KEY */]: publicKey
575
+ }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
550
576
  ["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
551
577
  }), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
552
578
  ["X-Session-ID" /* SESSION_ID */]: sessionToken
@@ -570,8 +596,12 @@ var createRequestHandler = ({
570
596
  return res == null ? void 0 : res.data;
571
597
  } catch (e) {
572
598
  const error = e;
573
- if (!error.response)
574
- throw e;
599
+ if (!error.response) {
600
+ throw {
601
+ code: "network-error",
602
+ message: (error == null ? void 0 : error.message) || "Network request failed. Please check your internet connection."
603
+ };
604
+ }
575
605
  throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
576
606
  }
577
607
  }),
@@ -586,7 +616,9 @@ var createRequestHandler = ({
586
616
  options == null ? void 0 : options.token
587
617
  ].find((x) => x);
588
618
  const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
589
- const fetchHeaders = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
619
+ const fetchHeaders = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), {
620
+ ["X-API-Key" /* API_KEY */]: publicKey
621
+ }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
590
622
  ["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
591
623
  "Content-Type": "application/json",
592
624
  Referer: window.location.href
@@ -624,8 +656,13 @@ var createRequestHandler = ({
624
656
  }
625
657
  return result;
626
658
  } catch (e) {
627
- console.error("Error in sendRequestWithFetch:", e);
628
- throw e;
659
+ if (e && typeof e === "object" && "code" in e && "message" in e) {
660
+ throw e;
661
+ }
662
+ throw {
663
+ code: "network-error",
664
+ message: (e == null ? void 0 : e.message) || "Network request failed. Please check your internet connection."
665
+ };
629
666
  }
630
667
  })
631
668
  };
@@ -650,8 +687,12 @@ var createObservable = () => {
650
687
  };
651
688
  var observable = createObservable();
652
689
  var getPersistedMember = () => {
653
- const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
654
- return stored ? JSON.parse(stored) : null;
690
+ try {
691
+ const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
692
+ return stored ? JSON.parse(stored) : null;
693
+ } catch (e) {
694
+ return null;
695
+ }
655
696
  };
656
697
  var setPersistedMember = (member) => {
657
698
  if (member) {
@@ -677,8 +718,9 @@ var unsetPersistedMember = () => {
677
718
  removeSessionId();
678
719
  observable.notify(null);
679
720
  };
721
+ var nextSubscriberId = 0;
680
722
  var onAuthChange = (cb) => {
681
- const id = Math.floor(Math.random() * 1e3);
723
+ const id = nextSubscriberId++;
682
724
  observable.subscribe(id, cb);
683
725
  return {
684
726
  unsubscribe: () => observable.unsubscribe(id)
@@ -842,6 +884,8 @@ var initRequest = ({
842
884
  * window.location.href = '/goodbye';
843
885
  * }
844
886
  * ```
887
+ *
888
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
845
889
  */
846
890
  deleteMember() {
847
891
  return __async(this, null, function* () {
@@ -853,6 +897,15 @@ var initRequest = ({
853
897
  return data;
854
898
  });
855
899
  },
900
+ /**
901
+ * Sends a typing indicator to a comments channel.
902
+ * Used internally to show when a member is actively composing a post.
903
+ *
904
+ * @internal
905
+ * @param params - The typing indicator parameters
906
+ * @param params.channelKey - The key/identifier of the channel
907
+ * @returns Promise that resolves when the typing indicator is sent
908
+ */
856
909
  postIsTyping(params) {
857
910
  return __async(this, null, function* () {
858
911
  return sendRequest({
@@ -864,6 +917,15 @@ var initRequest = ({
864
917
  });
865
918
  });
866
919
  },
920
+ /**
921
+ * Retrieves information about a comments channel.
922
+ * Returns channel metadata and configuration.
923
+ *
924
+ * @internal
925
+ * @param params - The channel info parameters
926
+ * @param params.channelKey - The key/identifier of the channel
927
+ * @returns Promise resolving to the channel information
928
+ */
867
929
  getChannelInfo(params) {
868
930
  return __async(this, null, function* () {
869
931
  const queryParams = new URLSearchParams({
@@ -875,6 +937,16 @@ var initRequest = ({
875
937
  });
876
938
  });
877
939
  },
940
+ /**
941
+ * Manages a member's notification subscription to a comments channel.
942
+ * Allows members to subscribe or unsubscribe from channel notifications.
943
+ *
944
+ * @internal
945
+ * @param params - The subscription parameters
946
+ * @param params.channelKey - The key/identifier of the channel
947
+ * @param params.action - The subscription action: 'NONE' to unsubscribe, 'THREADS_ONLY' to receive thread notifications
948
+ * @returns Promise that resolves when the subscription is updated
949
+ */
878
950
  subscribeToChannel(params) {
879
951
  return __async(this, null, function* () {
880
952
  return sendRequest({
@@ -887,6 +959,27 @@ var initRequest = ({
887
959
  });
888
960
  });
889
961
  },
962
+ /**
963
+ * Retrieves posts from a comments channel.
964
+ * Use this to display comments or discussion threads on your site.
965
+ *
966
+ * @param params - Query parameters
967
+ * @param params.channelKey - The key identifying the channel to fetch posts from
968
+ * @param params.order - Sort order: 'newest' or 'oldest'
969
+ * @param params.after - Cursor for pagination (post ID to start after)
970
+ * @param params.limit - Maximum number of posts to return
971
+ * @returns Promise resolving to an array of posts
972
+ *
973
+ * @example
974
+ * ```typescript
975
+ * const { data } = await memberstack.getPosts({
976
+ * channelKey: 'blog-comments',
977
+ * order: 'newest',
978
+ * limit: 20
979
+ * });
980
+ * data.posts.forEach(post => console.log(post.content));
981
+ * ```
982
+ */
890
983
  getPosts(params) {
891
984
  return __async(this, null, function* () {
892
985
  const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
@@ -904,6 +997,26 @@ var initRequest = ({
904
997
  });
905
998
  });
906
999
  },
1000
+ /**
1001
+ * Retrieves threads (replies) for a specific post.
1002
+ *
1003
+ * @param params - Query parameters
1004
+ * @param params.postId - The ID of the parent post
1005
+ * @param params.order - Sort order: 'newest' or 'oldest'
1006
+ * @param params.after - Cursor for pagination (thread ID to start after)
1007
+ * @param params.limit - Maximum number of threads to return
1008
+ * @returns Promise resolving to an array of threads
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const { data } = await memberstack.getThreads({
1013
+ * postId: 'post_abc123',
1014
+ * order: 'oldest',
1015
+ * limit: 50
1016
+ * });
1017
+ * data.threads.forEach(thread => console.log(thread.content));
1018
+ * ```
1019
+ */
907
1020
  getThreads(params) {
908
1021
  return __async(this, null, function* () {
909
1022
  const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
@@ -921,6 +1034,23 @@ var initRequest = ({
921
1034
  });
922
1035
  });
923
1036
  },
1037
+ /**
1038
+ * Creates a new post in a comments channel.
1039
+ *
1040
+ * @param params - Post data
1041
+ * @param params.channelKey - The key of the channel to post in
1042
+ * @param params.content - The content of the post (supports markdown)
1043
+ * @returns Promise resolving to the created post
1044
+ *
1045
+ * @example
1046
+ * ```typescript
1047
+ * const { data: post } = await memberstack.createPost({
1048
+ * channelKey: 'blog-comments',
1049
+ * content: 'Great article! Thanks for sharing.'
1050
+ * });
1051
+ * console.log('Posted:', post.id);
1052
+ * ```
1053
+ */
924
1054
  createPost(params) {
925
1055
  return __async(this, null, function* () {
926
1056
  return sendRequest({
@@ -934,6 +1064,23 @@ var initRequest = ({
934
1064
  });
935
1065
  });
936
1066
  },
1067
+ /**
1068
+ * Updates an existing post's content.
1069
+ * Only the post author can update their post.
1070
+ *
1071
+ * @param params - Update data
1072
+ * @param params.postId - The ID of the post to update
1073
+ * @param params.content - The new content for the post
1074
+ * @returns Promise resolving to the updated post
1075
+ *
1076
+ * @example
1077
+ * ```typescript
1078
+ * const { data: post } = await memberstack.updatePost({
1079
+ * postId: 'post_abc123',
1080
+ * content: 'Updated: Great article with corrections!'
1081
+ * });
1082
+ * ```
1083
+ */
937
1084
  updatePost(params) {
938
1085
  return __async(this, null, function* () {
939
1086
  return sendRequest({
@@ -945,6 +1092,29 @@ var initRequest = ({
945
1092
  });
946
1093
  });
947
1094
  },
1095
+ /**
1096
+ * Votes on a post (upvote, downvote, or remove vote).
1097
+ *
1098
+ * @param params - Vote data
1099
+ * @param params.postId - The ID of the post to vote on
1100
+ * @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
1101
+ * @returns Promise resolving when the vote is recorded
1102
+ *
1103
+ * @example
1104
+ * ```typescript
1105
+ * // Upvote a post
1106
+ * await memberstack.postVote({
1107
+ * postId: 'post_abc123',
1108
+ * vote: 'UP'
1109
+ * });
1110
+ *
1111
+ * // Remove vote
1112
+ * await memberstack.postVote({
1113
+ * postId: 'post_abc123',
1114
+ * vote: 'NONE'
1115
+ * });
1116
+ * ```
1117
+ */
948
1118
  postVote(params) {
949
1119
  return __async(this, null, function* () {
950
1120
  return sendRequest({
@@ -956,6 +1126,21 @@ var initRequest = ({
956
1126
  });
957
1127
  });
958
1128
  },
1129
+ /**
1130
+ * Deletes a post.
1131
+ * Only the post author can delete their post.
1132
+ *
1133
+ * @param params - Delete parameters
1134
+ * @param params.postId - The ID of the post to delete
1135
+ * @returns Promise resolving when the post is deleted
1136
+ *
1137
+ * @example
1138
+ * ```typescript
1139
+ * await memberstack.deletePost({
1140
+ * postId: 'post_abc123'
1141
+ * });
1142
+ * ```
1143
+ */
959
1144
  deletePost(params) {
960
1145
  return __async(this, null, function* () {
961
1146
  return sendRequest({
@@ -964,6 +1149,22 @@ var initRequest = ({
964
1149
  });
965
1150
  });
966
1151
  },
1152
+ /**
1153
+ * Creates a reply thread on a post.
1154
+ *
1155
+ * @param params - Thread data
1156
+ * @param params.postId - The ID of the post to reply to
1157
+ * @param params.content - The content of the reply (supports markdown)
1158
+ * @returns Promise resolving to the created thread
1159
+ *
1160
+ * @example
1161
+ * ```typescript
1162
+ * const { data: thread } = await memberstack.createThread({
1163
+ * postId: 'post_abc123',
1164
+ * content: 'I agree with this point!'
1165
+ * });
1166
+ * ```
1167
+ */
967
1168
  createThread(params) {
968
1169
  return __async(this, null, function* () {
969
1170
  return sendRequest({
@@ -976,6 +1177,23 @@ var initRequest = ({
976
1177
  });
977
1178
  });
978
1179
  },
1180
+ /**
1181
+ * Updates an existing thread's content.
1182
+ * Only the thread author can update their thread.
1183
+ *
1184
+ * @param params - Update data
1185
+ * @param params.threadId - The ID of the thread to update
1186
+ * @param params.content - The new content for the thread
1187
+ * @returns Promise resolving to the updated thread
1188
+ *
1189
+ * @example
1190
+ * ```typescript
1191
+ * const { data: thread } = await memberstack.updateThread({
1192
+ * threadId: 'thread_xyz789',
1193
+ * content: 'Updated reply with more details.'
1194
+ * });
1195
+ * ```
1196
+ */
979
1197
  updateThread(params) {
980
1198
  return __async(this, null, function* () {
981
1199
  return sendRequest({
@@ -987,7 +1205,22 @@ var initRequest = ({
987
1205
  });
988
1206
  });
989
1207
  },
990
- // vote thread
1208
+ /**
1209
+ * Votes on a thread (upvote, downvote, or remove vote).
1210
+ *
1211
+ * @param params - Vote data
1212
+ * @param params.threadId - The ID of the thread to vote on
1213
+ * @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
1214
+ * @returns Promise resolving when the vote is recorded
1215
+ *
1216
+ * @example
1217
+ * ```typescript
1218
+ * await memberstack.threadVote({
1219
+ * threadId: 'thread_xyz789',
1220
+ * vote: 'UP'
1221
+ * });
1222
+ * ```
1223
+ */
991
1224
  threadVote(params) {
992
1225
  return __async(this, null, function* () {
993
1226
  return sendRequest({
@@ -999,6 +1232,21 @@ var initRequest = ({
999
1232
  });
1000
1233
  });
1001
1234
  },
1235
+ /**
1236
+ * Deletes a thread.
1237
+ * Only the thread author can delete their thread.
1238
+ *
1239
+ * @param params - Delete parameters
1240
+ * @param params.threadId - The ID of the thread to delete
1241
+ * @returns Promise resolving when the thread is deleted
1242
+ *
1243
+ * @example
1244
+ * ```typescript
1245
+ * await memberstack.deleteThread({
1246
+ * threadId: 'thread_xyz789'
1247
+ * });
1248
+ * ```
1249
+ */
1002
1250
  deleteThread(params) {
1003
1251
  return __async(this, null, function* () {
1004
1252
  return sendRequest({
@@ -1020,8 +1268,10 @@ var initRequest = ({
1020
1268
  * const { data: content } = await memberstack.getSecureContent({
1021
1269
  * contentId: 'cnt_abc123'
1022
1270
  * });
1023
- * document.getElementById('premium-content').innerHTML = content.html;
1271
+ * document.getElementById('premium-content').innerHTML = content.content;
1024
1272
  * ```
1273
+ *
1274
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Protected Content Documentation}
1025
1275
  */
1026
1276
  getSecureContent(params) {
1027
1277
  return __async(this, null, function* () {
@@ -1062,6 +1312,8 @@ var initRequest = ({
1062
1312
  * plans: [{ planId: 'pln_free' }]
1063
1313
  * });
1064
1314
  * ```
1315
+ *
1316
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1065
1317
  */
1066
1318
  signupWithProvider(params) {
1067
1319
  return __async(this, null, function* () {
@@ -1112,6 +1364,8 @@ var initRequest = ({
1112
1364
  * allowSignup: true
1113
1365
  * });
1114
1366
  * ```
1367
+ *
1368
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1115
1369
  */
1116
1370
  loginWithProvider(params) {
1117
1371
  return __async(this, null, function* () {
@@ -1144,6 +1398,8 @@ var initRequest = ({
1144
1398
  * });
1145
1399
  * // Member can now log in with either email/password or Google
1146
1400
  * ```
1401
+ *
1402
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1147
1403
  */
1148
1404
  connectProvider(params) {
1149
1405
  return __async(this, null, function* () {
@@ -1175,6 +1431,8 @@ var initRequest = ({
1175
1431
  * });
1176
1432
  * // Member must now use email/password or another connected provider
1177
1433
  * ```
1434
+ *
1435
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1178
1436
  */
1179
1437
  disconnectProvider(params) {
1180
1438
  return __async(this, null, function* () {
@@ -1187,6 +1445,16 @@ var initRequest = ({
1187
1445
  });
1188
1446
  });
1189
1447
  },
1448
+ /**
1449
+ * Retrieves both app configuration and current member data in a single request.
1450
+ * Used internally for initial page load to efficiently fetch all required data.
1451
+ * Also handles session tracking and conversion data.
1452
+ *
1453
+ * @internal
1454
+ * @param params - Optional parameters
1455
+ * @param params.trackPageView - Whether to track this as a page view for analytics (default: false)
1456
+ * @returns Promise resolving to both app and member data
1457
+ */
1190
1458
  getAppAndMember(params) {
1191
1459
  return __async(this, null, function* () {
1192
1460
  var _a2, _b;
@@ -1195,7 +1463,6 @@ var initRequest = ({
1195
1463
  url: `/app-member`,
1196
1464
  data: {
1197
1465
  data: {
1198
- // @ts-ignore
1199
1466
  includeSSOText: window == null ? void 0 : window.ssoUI,
1200
1467
  trackPageView: params == null ? void 0 : params.trackPageView,
1201
1468
  sessionData: __spreadValues({}, getConversionData())
@@ -1224,12 +1491,14 @@ var initRequest = ({
1224
1491
  * console.log('App name:', app.name);
1225
1492
  * console.log('OAuth providers:', app.authProviders);
1226
1493
  * ```
1494
+ *
1495
+ * @see {@link https://developers.memberstack.com/dom-package/quick-start | Quick Start Documentation}
1227
1496
  */
1228
1497
  getApp() {
1229
1498
  return __async(this, null, function* () {
1499
+ var _a2;
1230
1500
  const queryParams = new URLSearchParams({
1231
- // @ts-ignore
1232
- includeSSOText: window == null ? void 0 : window.ssoUI
1501
+ includeSSOText: String((_a2 = window == null ? void 0 : window.ssoUI) != null ? _a2 : "")
1233
1502
  });
1234
1503
  return sendRequest({
1235
1504
  method: "GET" /* GET */,
@@ -1259,6 +1528,8 @@ var initRequest = ({
1259
1528
  * console.error('Login failed:', error.message);
1260
1529
  * }
1261
1530
  * ```
1531
+ *
1532
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1262
1533
  */
1263
1534
  loginMemberEmailPassword(params, options) {
1264
1535
  return __async(this, null, function* () {
@@ -1296,6 +1567,8 @@ var initRequest = ({
1296
1567
  *
1297
1568
  * // Step 2: Complete login with the code (see loginMemberPasswordless)
1298
1569
  * ```
1570
+ *
1571
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1299
1572
  */
1300
1573
  sendMemberLoginPasswordlessEmail(params, options) {
1301
1574
  return __async(this, null, function* () {
@@ -1325,6 +1598,8 @@ var initRequest = ({
1325
1598
  *
1326
1599
  * // Step 2: Complete signup with the code (see signupMemberPasswordless)
1327
1600
  * ```
1601
+ *
1602
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1328
1603
  */
1329
1604
  sendMemberSignupPasswordlessEmail(params, options) {
1330
1605
  return __async(this, null, function* () {
@@ -1356,6 +1631,8 @@ var initRequest = ({
1356
1631
  * });
1357
1632
  * console.log('Logged in:', data.member.auth.email);
1358
1633
  * ```
1634
+ *
1635
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1359
1636
  */
1360
1637
  loginMemberPasswordless(params, options) {
1361
1638
  return __async(this, null, function* () {
@@ -1390,6 +1667,8 @@ var initRequest = ({
1390
1667
  * console.log('Plan:', plan.name);
1391
1668
  * console.log('Prices:', plan.prices);
1392
1669
  * ```
1670
+ *
1671
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1393
1672
  */
1394
1673
  getPlan(params) {
1395
1674
  return __async(this, null, function* () {
@@ -1428,6 +1707,8 @@ var initRequest = ({
1428
1707
  * </div>
1429
1708
  * `).join('');
1430
1709
  * ```
1710
+ *
1711
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1431
1712
  */
1432
1713
  getPlans() {
1433
1714
  return __async(this, null, function* () {
@@ -1452,7 +1733,7 @@ var initRequest = ({
1452
1733
  *
1453
1734
  * groups.forEach(group => {
1454
1735
  * console.log('Group:', group.name);
1455
- * console.log('Required plans:', group.planIds);
1736
+ * console.log('Required plans:', group.plans.map(p => p.id));
1456
1737
  * console.log('URLs:', group.urls);
1457
1738
  * });
1458
1739
  * ```
@@ -1499,6 +1780,8 @@ var initRequest = ({
1499
1780
  * const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
1500
1781
  * }
1501
1782
  * ```
1783
+ *
1784
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1502
1785
  */
1503
1786
  getCurrentMember(options) {
1504
1787
  return __async(this, null, function* () {
@@ -1537,6 +1820,8 @@ var initRequest = ({
1537
1820
  * console.log('Preferences:', json.preferences);
1538
1821
  * console.log('Last visited:', json.lastVisitedPage);
1539
1822
  * ```
1823
+ *
1824
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
1540
1825
  */
1541
1826
  getMemberJSON(options) {
1542
1827
  return __async(this, null, function* () {
@@ -1549,7 +1834,7 @@ var initRequest = ({
1549
1834
  },
1550
1835
  /**
1551
1836
  * Updates the current member's JSON data store.
1552
- * You can store any JSON-serializable data. Updates are merged with existing data.
1837
+ * You can store any JSON-serializable data. This completely replaces the existing JSON.
1553
1838
  *
1554
1839
  * @param params - JSON data to store
1555
1840
  * @param params.json - Object containing the data to store
@@ -1575,6 +1860,8 @@ var initRequest = ({
1575
1860
  * }
1576
1861
  * });
1577
1862
  * ```
1863
+ *
1864
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
1578
1865
  */
1579
1866
  updateMemberJSON(params, options) {
1580
1867
  return __async(this, null, function* () {
@@ -1603,6 +1890,8 @@ var initRequest = ({
1603
1890
  * });
1604
1891
  * console.log('Plan added, redirect:', data.redirect);
1605
1892
  * ```
1893
+ *
1894
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1606
1895
  */
1607
1896
  addPlan(params, options) {
1608
1897
  return __async(this, null, function* () {
@@ -1658,6 +1947,8 @@ var initRequest = ({
1658
1947
  * cancelUrl: '/pricing'
1659
1948
  * });
1660
1949
  * ```
1950
+ *
1951
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1661
1952
  */
1662
1953
  purchasePlansWithCheckout(params, options) {
1663
1954
  return __async(this, null, function* () {
@@ -1726,6 +2017,8 @@ var initRequest = ({
1726
2017
  * });
1727
2018
  * console.log('Portal URL:', data.url);
1728
2019
  * ```
2020
+ *
2021
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1729
2022
  */
1730
2023
  launchStripeCustomerPortal(params, options) {
1731
2024
  return __async(this, null, function* () {
@@ -1777,6 +2070,8 @@ var initRequest = ({
1777
2070
  * });
1778
2071
  * // Plan removed/subscription cancelled
1779
2072
  * ```
2073
+ *
2074
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1780
2075
  */
1781
2076
  removePlan(params, options) {
1782
2077
  return __async(this, null, function* () {
@@ -1818,6 +2113,8 @@ var initRequest = ({
1818
2113
  * }
1819
2114
  * });
1820
2115
  * ```
2116
+ *
2117
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1821
2118
  */
1822
2119
  updateMember(params, options) {
1823
2120
  return __async(this, null, function* () {
@@ -1855,6 +2152,8 @@ var initRequest = ({
1855
2152
  * newPassword: 'newSecurePassword123'
1856
2153
  * });
1857
2154
  * ```
2155
+ *
2156
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1858
2157
  */
1859
2158
  updateMemberAuth(params, options) {
1860
2159
  return __async(this, null, function* () {
@@ -1882,6 +2181,8 @@ var initRequest = ({
1882
2181
  * });
1883
2182
  * // Member can now log in with email/password
1884
2183
  * ```
2184
+ *
2185
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1885
2186
  */
1886
2187
  setPassword(params, options) {
1887
2188
  return __async(this, null, function* () {
@@ -1895,6 +2196,33 @@ var initRequest = ({
1895
2196
  });
1896
2197
  });
1897
2198
  },
2199
+ /**
2200
+ * Completes passwordless signup using the code sent via email.
2201
+ * Creates a new member account without requiring a password.
2202
+ *
2203
+ * @param params - Signup details
2204
+ * @param params.email - The new member's email address
2205
+ * @param params.passwordlessToken - The one-time code from the signup email
2206
+ * @param params.customFields - Optional custom field values defined in your Memberstack dashboard
2207
+ * @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
2208
+ * @param params.metaData - Optional metadata to store with the member
2209
+ * @returns Promise resolving to the new member data and tokens
2210
+ * @throws When the code is invalid, expired, or email is already in use
2211
+ *
2212
+ * @example Complete passwordless signup flow
2213
+ * ```typescript
2214
+ * // Step 1: Send signup code (see sendMemberSignupPasswordlessEmail)
2215
+ * // Step 2: User enters code, complete signup:
2216
+ * const { data } = await memberstack.signupMemberPasswordless({
2217
+ * email: 'newuser@example.com',
2218
+ * passwordlessToken: '123456',
2219
+ * customFields: { firstName: 'Jane' }
2220
+ * });
2221
+ * console.log('Welcome!', data.member.id);
2222
+ * ```
2223
+ *
2224
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
2225
+ */
1898
2226
  signupMemberPasswordless(params, options) {
1899
2227
  return __async(this, null, function* () {
1900
2228
  var _a2, _b, _c;
@@ -1915,9 +2243,7 @@ var initRequest = ({
1915
2243
  options
1916
2244
  }), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
1917
2245
  rewardfulData: {
1918
- // @ts-ignore
1919
2246
  referral: window.Rewardful.referral,
1920
- // @ts-ignore
1921
2247
  coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
1922
2248
  }
1923
2249
  })
@@ -1964,6 +2290,8 @@ var initRequest = ({
1964
2290
  * plans: [{ planId: 'pln_free_tier' }]
1965
2291
  * });
1966
2292
  * ```
2293
+ *
2294
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Signup Documentation}
1967
2295
  */
1968
2296
  signupMemberEmailPassword(params, options) {
1969
2297
  return __async(this, null, function* () {
@@ -1987,9 +2315,7 @@ var initRequest = ({
1987
2315
  options
1988
2316
  }), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
1989
2317
  rewardfulData: {
1990
- // @ts-ignore
1991
2318
  referral: window.Rewardful.referral,
1992
- // @ts-ignore
1993
2319
  coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
1994
2320
  }
1995
2321
  })
@@ -2000,6 +2326,25 @@ var initRequest = ({
2000
2326
  return data;
2001
2327
  });
2002
2328
  },
2329
+ /**
2330
+ * Joins a team using an invite token.
2331
+ * The invite token is typically sent by a team admin via email.
2332
+ *
2333
+ * @param params - Join parameters
2334
+ * @param params.inviteToken - The invite token received from the team admin
2335
+ * @returns Promise resolving when the member has joined the team
2336
+ *
2337
+ * @example
2338
+ * ```typescript
2339
+ * // Extract token from URL (e.g., /join?token=abc123)
2340
+ * const token = new URLSearchParams(window.location.search).get('token');
2341
+ *
2342
+ * await memberstack.joinTeam({
2343
+ * inviteToken: token
2344
+ * });
2345
+ * console.log('Successfully joined the team!');
2346
+ * ```
2347
+ */
2003
2348
  joinTeam(params, options) {
2004
2349
  return __async(this, null, function* () {
2005
2350
  return sendRequest({
@@ -2012,6 +2357,21 @@ var initRequest = ({
2012
2357
  });
2013
2358
  });
2014
2359
  },
2360
+ /**
2361
+ * Retrieves information about a team the current member belongs to.
2362
+ *
2363
+ * @param params - Team parameters
2364
+ * @param params.teamId - The ID of the team to retrieve
2365
+ * @returns Promise resolving to the team details
2366
+ *
2367
+ * @example
2368
+ * ```typescript
2369
+ * const team = await memberstack.getTeam({
2370
+ * teamId: 'team_abc123'
2371
+ * });
2372
+ * console.log('Team members:', team);
2373
+ * ```
2374
+ */
2015
2375
  getTeam(params, options) {
2016
2376
  return __async(this, null, function* () {
2017
2377
  return sendRequest({
@@ -2021,6 +2381,24 @@ var initRequest = ({
2021
2381
  });
2022
2382
  });
2023
2383
  },
2384
+ /**
2385
+ * Removes a member from a team.
2386
+ * Only team admins can remove other members.
2387
+ *
2388
+ * @param params - Removal parameters
2389
+ * @param params.teamId - The ID of the team
2390
+ * @param params.memberId - The ID of the member to remove
2391
+ * @returns Promise resolving when the member has been removed
2392
+ *
2393
+ * @example
2394
+ * ```typescript
2395
+ * await memberstack.removeMemberFromTeam({
2396
+ * teamId: 'team_abc123',
2397
+ * memberId: 'mem_xyz789'
2398
+ * });
2399
+ * console.log('Member removed from team');
2400
+ * ```
2401
+ */
2024
2402
  removeMemberFromTeam(params, options) {
2025
2403
  return __async(this, null, function* () {
2026
2404
  return sendRequest({
@@ -2034,6 +2412,23 @@ var initRequest = ({
2034
2412
  });
2035
2413
  });
2036
2414
  },
2415
+ /**
2416
+ * Generates an invite token for a team.
2417
+ * The token can be shared with users to invite them to join the team.
2418
+ *
2419
+ * @param params - Token parameters
2420
+ * @param params.teamId - The ID of the team to generate an invite for
2421
+ * @returns Promise resolving to the generated invite token
2422
+ *
2423
+ * @example
2424
+ * ```typescript
2425
+ * const invite = await memberstack.generateInviteToken({
2426
+ * teamId: 'team_abc123'
2427
+ * });
2428
+ * // Share the invite link with new team members
2429
+ * const inviteUrl = `${window.location.origin}/join?token=${invite.token}`;
2430
+ * ```
2431
+ */
2037
2432
  generateInviteToken(params, options) {
2038
2433
  return __async(this, null, function* () {
2039
2434
  return sendRequest({
@@ -2047,12 +2442,12 @@ var initRequest = ({
2047
2442
  });
2048
2443
  },
2049
2444
  /**
2050
- * Uploads a new profile image for the current member.
2051
- * Accepts a File object (from an input element) or a Blob.
2445
+ * Updates or removes the current member's profile image.
2446
+ * Pass a File to upload a new image, or null to remove the existing image.
2052
2447
  *
2053
2448
  * @param params - Image parameters
2054
- * @param params.profileImage - The image file to upload
2055
- * @returns Promise resolving to the new profile image URL
2449
+ * @param params.profileImage - The image file to upload, or null to remove
2450
+ * @returns Promise resolving to the new profile image URL (or null if removed)
2056
2451
  *
2057
2452
  * @example Upload from file input
2058
2453
  * ```typescript
@@ -2064,11 +2459,24 @@ var initRequest = ({
2064
2459
  * });
2065
2460
  * console.log('New image URL:', data.profileImage);
2066
2461
  * ```
2462
+ *
2463
+ * @example Remove profile image
2464
+ * ```typescript
2465
+ * const { data } = await memberstack.updateMemberProfileImage({
2466
+ * profileImage: null
2467
+ * });
2468
+ * console.log('Image removed:', data.profileImage === null);
2469
+ * ```
2470
+ *
2471
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
2067
2472
  */
2068
2473
  updateMemberProfileImage(params) {
2069
2474
  return __async(this, null, function* () {
2070
- if (!params.profileImage) {
2071
- throw new Error("profileImage is required");
2475
+ if (params.profileImage === null) {
2476
+ return sendRequest({
2477
+ method: "DELETE" /* DELETE */,
2478
+ url: `/member/profile-image`
2479
+ });
2072
2480
  }
2073
2481
  const formData = new FormData();
2074
2482
  formData.append("profileImage", params.profileImage);
@@ -2080,6 +2488,28 @@ var initRequest = ({
2080
2488
  });
2081
2489
  });
2082
2490
  },
2491
+ /**
2492
+ * Removes the current member's profile image.
2493
+ * After deletion, the member's profileImage field will be null.
2494
+ *
2495
+ * @returns Promise resolving to confirmation that the image was removed
2496
+ *
2497
+ * @example
2498
+ * ```typescript
2499
+ * await memberstack.deleteMemberProfileImage();
2500
+ * console.log('Profile image removed');
2501
+ * ```
2502
+ *
2503
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
2504
+ */
2505
+ deleteMemberProfileImage() {
2506
+ return __async(this, null, function* () {
2507
+ return sendRequest({
2508
+ method: "DELETE" /* DELETE */,
2509
+ url: `/member/profile-image`
2510
+ });
2511
+ });
2512
+ },
2083
2513
  /**
2084
2514
  * Sends a verification email to the current member.
2085
2515
  * Use this when email verification is enabled in your Memberstack settings.
@@ -2091,6 +2521,8 @@ var initRequest = ({
2091
2521
  * await memberstack.sendMemberVerificationEmail();
2092
2522
  * // Show message: "Verification email sent! Check your inbox."
2093
2523
  * ```
2524
+ *
2525
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Verification Documentation}
2094
2526
  */
2095
2527
  sendMemberVerificationEmail() {
2096
2528
  return __async(this, null, function* () {
@@ -2119,6 +2551,8 @@ var initRequest = ({
2119
2551
  * });
2120
2552
  * // Show confirmation: "Check your email for reset instructions"
2121
2553
  * ```
2554
+ *
2555
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
2122
2556
  */
2123
2557
  sendMemberResetPasswordEmail(params) {
2124
2558
  return __async(this, null, function* () {
@@ -2152,6 +2586,8 @@ var initRequest = ({
2152
2586
  * });
2153
2587
  * // Password updated, redirect to login
2154
2588
  * ```
2589
+ *
2590
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
2155
2591
  */
2156
2592
  resetMemberPassword(params) {
2157
2593
  return __async(this, null, function* () {
@@ -2185,6 +2621,8 @@ var initRequest = ({
2185
2621
  * window.location.href = data.redirect;
2186
2622
  * }
2187
2623
  * ```
2624
+ *
2625
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
2188
2626
  */
2189
2627
  logout(options) {
2190
2628
  return __async(this, null, function* () {
@@ -2206,11 +2644,13 @@ var initRequest = ({
2206
2644
  *
2207
2645
  * @example
2208
2646
  * ```typescript
2209
- * const { data: tables } = await memberstack.getDataTables();
2210
- * tables.forEach(table => {
2647
+ * const { data } = await memberstack.getDataTables();
2648
+ * data.tables.forEach(table => {
2211
2649
  * console.log('Table:', table.name, table.key);
2212
2650
  * });
2213
2651
  * ```
2652
+ *
2653
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2214
2654
  */
2215
2655
  getDataTables(options) {
2216
2656
  return __async(this, null, function* () {
@@ -2233,14 +2673,15 @@ var initRequest = ({
2233
2673
  * const { data: table } = await memberstack.getDataTable({
2234
2674
  * table: 'posts'
2235
2675
  * });
2236
- * console.log('Columns:', table.columns);
2676
+ * console.log('Fields:', table.fields.map(f => f.name));
2237
2677
  * ```
2678
+ *
2679
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2238
2680
  */
2239
2681
  getDataTable(params, options) {
2240
2682
  return __async(this, null, function* () {
2241
2683
  return sendRequest({
2242
2684
  method: "GET" /* GET */,
2243
- //@ts-ignore
2244
2685
  url: `/v1/data-tables/${params.table || params.tableKey}`,
2245
2686
  headers: addHeaders(options)
2246
2687
  });
@@ -2269,6 +2710,8 @@ var initRequest = ({
2269
2710
  * });
2270
2711
  * console.log('Records:', data.records);
2271
2712
  * ```
2713
+ *
2714
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2272
2715
  */
2273
2716
  getDataRecords(params, options) {
2274
2717
  return __async(this, null, function* () {
@@ -2294,7 +2737,6 @@ var initRequest = ({
2294
2737
  method: "POST" /* POST */,
2295
2738
  url: `/v1/data-records/query`,
2296
2739
  data: {
2297
- // @ts-ignore
2298
2740
  table: params.table || params.tableKey,
2299
2741
  query: {
2300
2742
  findMany: query
@@ -2333,6 +2775,8 @@ var initRequest = ({
2333
2775
  * });
2334
2776
  * console.log('Created record:', record.id);
2335
2777
  * ```
2778
+ *
2779
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2336
2780
  */
2337
2781
  createDataRecord(params, options) {
2338
2782
  return __async(this, null, function* () {
@@ -2363,6 +2807,8 @@ var initRequest = ({
2363
2807
  * });
2364
2808
  * console.log('Post:', record.title);
2365
2809
  * ```
2810
+ *
2811
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2366
2812
  */
2367
2813
  getDataRecord(params, options) {
2368
2814
  return __async(this, null, function* () {
@@ -2404,6 +2850,8 @@ var initRequest = ({
2404
2850
  * }
2405
2851
  * });
2406
2852
  * ```
2853
+ *
2854
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2407
2855
  */
2408
2856
  updateDataRecord(params, options) {
2409
2857
  return __async(this, null, function* () {
@@ -2430,6 +2878,8 @@ var initRequest = ({
2430
2878
  * recordId: 'rec_abc123'
2431
2879
  * });
2432
2880
  * ```
2881
+ *
2882
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2433
2883
  */
2434
2884
  deleteDataRecord(params, options) {
2435
2885
  return __async(this, null, function* () {
@@ -2475,6 +2925,8 @@ var initRequest = ({
2475
2925
  * }
2476
2926
  * });
2477
2927
  * ```
2928
+ *
2929
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2478
2930
  */
2479
2931
  queryDataRecords(params, options) {
2480
2932
  return __async(this, null, function* () {
@@ -2504,6 +2956,9 @@ function setDebugMode(enabled) {
2504
2956
  "color: #6366f1; font-weight: bold;"
2505
2957
  );
2506
2958
  }
2959
+ if (!enabled && typeof window !== "undefined") {
2960
+ delete window.__MEMBERSTACK_DEBUG__;
2961
+ }
2507
2962
  }
2508
2963
  function debugLog(message, ...args) {
2509
2964
  if (debugEnabled) {
@@ -2522,8 +2977,8 @@ function initDevToolsIntegration(state) {
2522
2977
  publicKey: state.config.publicKey,
2523
2978
  appId: state.config.appId
2524
2979
  },
2525
- getMember: () => state.member,
2526
- isAuthenticated: () => state.member !== null,
2980
+ getMember: state.getMember,
2981
+ isAuthenticated: () => state.getMember() !== null,
2527
2982
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
2528
2983
  };
2529
2984
  debugLog("DevTools integration initialized. Access via window.__MEMBERSTACK_DEBUG__");
@@ -2532,6 +2987,7 @@ function initDevToolsIntegration(state) {
2532
2987
 
2533
2988
  // src/methods/index.ts
2534
2989
  var SDK_VERSION = "1.2.0";
2990
+ var initialized = false;
2535
2991
  var captchaReadyPromise = new Promise((resolve) => {
2536
2992
  if (typeof window !== "undefined") {
2537
2993
  window._hcaptchaReady = resolve;
@@ -2549,6 +3005,16 @@ var methods = {
2549
3005
  _captchaReady: captchaReadyPromise
2550
3006
  };
2551
3007
  function init(props) {
3008
+ if (!props.publicKey) {
3009
+ throw new Error(
3010
+ "Memberstack: publicKey is required. Pass your public key to init({ publicKey: 'pk_...' }). Find your key at https://app.memberstack.com/apps"
3011
+ );
3012
+ }
3013
+ if (!props.publicKey.startsWith("pk_")) {
3014
+ throw new Error(
3015
+ `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`
3016
+ );
3017
+ }
2552
3018
  if (props.debug) {
2553
3019
  setDebugMode(true);
2554
3020
  debugLog(`Initializing Memberstack SDK v${SDK_VERSION}`);
@@ -2559,6 +3025,17 @@ function init(props) {
2559
3025
  domain: props.domain
2560
3026
  });
2561
3027
  }
3028
+ if (initialized && props.debug) {
3029
+ console.warn(
3030
+ "[Memberstack] init() called multiple times. Previous instance will be replaced. This is usually unintentional \u2014 call init() once at app startup."
3031
+ );
3032
+ }
3033
+ if (props.sessionDurationDays !== void 0) {
3034
+ console.warn(
3035
+ "[Memberstack] sessionDurationDays is deprecated and no longer used. Session duration is now controlled server-side. You can safely remove this option."
3036
+ );
3037
+ }
3038
+ initialized = true;
2562
3039
  const apiDomain2 = props.domain || endpoints.API || "https://client.memberstack.com";
2563
3040
  setApiDomain(apiDomain2);
2564
3041
  if (props.useCookies)
@@ -2570,14 +3047,13 @@ function init(props) {
2570
3047
  token: getMemberToken(),
2571
3048
  domain: apiDomain2
2572
3049
  });
2573
- const allMethods = Object.assign(methods, requests);
3050
+ const allMethods = Object.assign(methods, requests, { destroy });
2574
3051
  if (typeof window !== "undefined") {
2575
3052
  window.$memberstackDom = allMethods;
2576
3053
  if (props.debug) {
2577
3054
  initDevToolsIntegration({
2578
3055
  config: { publicKey: props.publicKey, appId: props.appId },
2579
- member: null,
2580
- // Will be updated by auth state
3056
+ getMember: () => getPersistedMember(),
2581
3057
  version: SDK_VERSION
2582
3058
  });
2583
3059
  }
@@ -2587,6 +3063,14 @@ function init(props) {
2587
3063
  }
2588
3064
  return allMethods;
2589
3065
  }
3066
+ function destroy() {
3067
+ unsetPersistedMember();
3068
+ initialized = false;
3069
+ if (typeof window !== "undefined") {
3070
+ delete window.$memberstackDom;
3071
+ delete window.__MEMBERSTACK_DEBUG__;
3072
+ }
3073
+ }
2590
3074
  var methods_default = { init: (props) => init(props) };
2591
3075
 
2592
3076
  // src/utils/errors.ts
@@ -2938,10 +3422,266 @@ var ErrorMetadata = {
2938
3422
  "Clear your browser cache and try again"
2939
3423
  ],
2940
3424
  docsUrl: "https://docs.memberstack.com/dom/authentication"
3425
+ },
3426
+ // Authentication — additional
3427
+ [ErrorCodes.MEMBER_NOT_FOUND]: {
3428
+ message: "No member found with this identifier.",
3429
+ category: "authentication",
3430
+ suggestions: [
3431
+ "Verify the email address is correct",
3432
+ "The member may not have signed up yet \u2014 use signupMemberEmailPassword()",
3433
+ "Check if the member exists in the correct environment (SANDBOX vs LIVE)"
3434
+ ],
3435
+ docsUrl: "https://docs.memberstack.com/dom/authentication/login"
3436
+ },
3437
+ // Account & Social Login — additional
3438
+ [ErrorCodes.ACCOUNT_NOT_FOUND]: {
3439
+ message: "No account found with these credentials.",
3440
+ category: "authentication",
3441
+ suggestions: [
3442
+ "The member may need to sign up first",
3443
+ "Check if the account was created with a different auth method (email vs social)",
3444
+ "Verify the correct environment (SANDBOX vs LIVE)"
3445
+ ]
3446
+ },
3447
+ [ErrorCodes.ACCOUNT_ALREADY_CONNECTED]: {
3448
+ message: "This social account is already connected.",
3449
+ category: "conflict",
3450
+ suggestions: [
3451
+ "Use disconnectProvider() first if you need to reconnect",
3452
+ "Check the member's connected providers with getCurrentMember()"
3453
+ ],
3454
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3455
+ },
3456
+ [ErrorCodes.ACCOUNT_NOT_CONNECTED]: {
3457
+ message: "This social account is not connected to the member.",
3458
+ category: "not_found",
3459
+ suggestions: [
3460
+ "Use connectProvider() to connect the social account first",
3461
+ "Check the member's connected providers with getCurrentMember()"
3462
+ ],
3463
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3464
+ },
3465
+ [ErrorCodes.ACCOUNT_CONNECT_FAILED]: {
3466
+ message: "Failed to connect the social account.",
3467
+ category: "authentication",
3468
+ suggestions: [
3469
+ "Try the connection again \u2014 this may be a temporary issue",
3470
+ "Ensure the social provider is enabled in your Memberstack dashboard",
3471
+ "Check that the OAuth redirect URLs are configured correctly"
3472
+ ],
3473
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3474
+ },
3475
+ [ErrorCodes.ACCOUNT_CONNECT_REQUIRES_LOGIN]: {
3476
+ message: "You must be logged in to connect a social account.",
3477
+ category: "authentication",
3478
+ suggestions: [
3479
+ "Call loginMemberEmailPassword() or loginWithProvider() first",
3480
+ "Use getCurrentMember() to verify the member is authenticated"
3481
+ ],
3482
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3483
+ },
3484
+ [ErrorCodes.ACCOUNT_SET_PASSWORD_FIRST]: {
3485
+ message: "Set a password before disconnecting your last login provider.",
3486
+ category: "authentication",
3487
+ suggestions: [
3488
+ "Use setPassword() to add a password before disconnecting",
3489
+ "This prevents the member from being locked out of their account"
3490
+ ],
3491
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3492
+ },
3493
+ // Validation — additional
3494
+ [ErrorCodes.INVALID_PASSWORD]: {
3495
+ message: "The password is incorrect.",
3496
+ category: "authentication",
3497
+ suggestions: [
3498
+ "Check that the current password is entered correctly",
3499
+ "Use sendMemberResetPasswordEmail() to reset the password"
3500
+ ]
3501
+ },
3502
+ [ErrorCodes.REQUIRED_FIELD_MISSING]: {
3503
+ message: "A required field is missing.",
3504
+ category: "validation",
3505
+ suggestions: [
3506
+ "Check that all required parameters are provided",
3507
+ "Review the method documentation for required fields",
3508
+ "Custom fields marked as required in the dashboard must be included on signup"
3509
+ ]
3510
+ },
3511
+ [ErrorCodes.INVALID_CAPTCHA]: {
3512
+ message: "CAPTCHA verification failed.",
3513
+ category: "validation",
3514
+ suggestions: [
3515
+ "Ensure the CAPTCHA token is passed as captchaToken in the request",
3516
+ "The token may have expired \u2014 request a new CAPTCHA challenge",
3517
+ "Check that CAPTCHA is correctly configured in your Memberstack dashboard"
3518
+ ]
3519
+ },
3520
+ // Plans — additional
3521
+ [ErrorCodes.NO_PLAN_FOUND]: {
3522
+ message: "The member does not have this plan.",
3523
+ category: "not_found",
3524
+ suggestions: [
3525
+ "Use getCurrentMember() to check the member's current plans",
3526
+ "Verify the plan ID is correct",
3527
+ "The plan may have been removed or expired"
3528
+ ],
3529
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3530
+ },
3531
+ [ErrorCodes.PLAN_MEMBER_LIMIT_REACHED]: {
3532
+ message: "This plan has reached its member limit.",
3533
+ category: "limit",
3534
+ suggestions: [
3535
+ "Contact the app owner to increase the plan's member limit",
3536
+ "Check if a different plan is available"
3537
+ ],
3538
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3539
+ },
3540
+ [ErrorCodes.PLAN_RESTRICTED_TO_ADMIN]: {
3541
+ message: "This plan can only be assigned by an admin.",
3542
+ category: "authorization",
3543
+ suggestions: [
3544
+ "Plans with this restriction cannot be self-assigned by members",
3545
+ "Use the Admin API or dashboard to assign this plan"
3546
+ ],
3547
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3548
+ },
3549
+ [ErrorCodes.DOMAIN_NOT_PERMITTED]: {
3550
+ message: "Your email domain is not permitted for this plan.",
3551
+ category: "authorization",
3552
+ suggestions: [
3553
+ "This plan restricts signup to specific email domains",
3554
+ "Check the plan's domain restrictions in your Memberstack dashboard",
3555
+ "Use an email address with an allowed domain"
3556
+ ],
3557
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3558
+ },
3559
+ [ErrorCodes.PRICE_NOT_AVAILABLE]: {
3560
+ message: "This pricing option is no longer available.",
3561
+ category: "not_found",
3562
+ suggestions: [
3563
+ "Use getPlans() to see currently available pricing options",
3564
+ "The price may have been archived or deactivated",
3565
+ "Check your Stripe dashboard for the price status"
3566
+ ],
3567
+ docsUrl: "https://docs.memberstack.com/dom/payments"
3568
+ },
3569
+ // Teams — additional
3570
+ [ErrorCodes.ONE_ACTIVE_TEAM_ONLY]: {
3571
+ message: "A member can only belong to one active team.",
3572
+ category: "conflict",
3573
+ suggestions: [
3574
+ "Remove the member from their current team first using removeMemberFromTeam()",
3575
+ "Check the member's current team with getTeam()"
3576
+ ],
3577
+ docsUrl: "https://docs.memberstack.com/dom/teams"
3578
+ },
3579
+ [ErrorCodes.CANNOT_CHANGE_TEAM]: {
3580
+ message: "Cannot change team while it has active members.",
3581
+ category: "conflict",
3582
+ suggestions: [
3583
+ "Remove all team members before making this change",
3584
+ "Use removeMemberFromTeam() to remove members first"
3585
+ ],
3586
+ docsUrl: "https://docs.memberstack.com/dom/teams"
3587
+ },
3588
+ // Data Tables — additional
3589
+ [ErrorCodes.INVALID_TABLE_KEY]: {
3590
+ message: "The table key format is invalid.",
3591
+ category: "data_tables",
3592
+ suggestions: [
3593
+ "Table keys should be lowercase alphanumeric with hyphens",
3594
+ "Use getDataTables() to list available tables and their keys",
3595
+ "Check the table key in your Memberstack dashboard"
3596
+ ],
3597
+ docsUrl: "https://docs.memberstack.com/data-tables"
3598
+ },
3599
+ [ErrorCodes.UNIQUE_CONSTRAINT_VIOLATION]: {
3600
+ message: "A record with this value already exists (unique constraint).",
3601
+ category: "data_tables",
3602
+ suggestions: [
3603
+ "The field has a unique constraint \u2014 use a different value",
3604
+ "Use queryDataRecords() to check for existing records before creating",
3605
+ "If updating, use updateDataRecord() instead of createDataRecord()"
3606
+ ],
3607
+ docsUrl: "https://docs.memberstack.com/data-tables"
3608
+ },
3609
+ [ErrorCodes.FIELD_LIMIT_EXCEEDED]: {
3610
+ message: "Maximum number of fields reached for this table.",
3611
+ category: "data_tables",
3612
+ suggestions: [
3613
+ "Remove unused fields before adding new ones",
3614
+ "Consider using a separate table for additional data",
3615
+ "Check your plan's field limits in the dashboard"
3616
+ ],
3617
+ docsUrl: "https://docs.memberstack.com/data-tables"
3618
+ },
3619
+ [ErrorCodes.INVALID_FIELD_TYPE]: {
3620
+ message: "This field type is not supported.",
3621
+ category: "data_tables",
3622
+ suggestions: [
3623
+ "Check the supported field types in the documentation",
3624
+ "Use getDataTable() to see the table schema and field types"
3625
+ ],
3626
+ docsUrl: "https://docs.memberstack.com/data-tables"
3627
+ },
3628
+ [ErrorCodes.INVALID_FIELD_VALUE]: {
3629
+ message: "The field value does not match the expected type.",
3630
+ category: "data_tables",
3631
+ suggestions: [
3632
+ "Check the field type \u2014 e.g., number fields require numeric values",
3633
+ "Use getDataTable() to see the expected field types",
3634
+ "Ensure dates are in ISO 8601 format for date fields"
3635
+ ],
3636
+ docsUrl: "https://docs.memberstack.com/data-tables"
3637
+ },
3638
+ // Permissions
3639
+ [ErrorCodes.ACCESS_DENIED]: {
3640
+ message: "You do not have permission to access this resource.",
3641
+ category: "authorization",
3642
+ suggestions: [
3643
+ "Check that the member has the required plan or permissions",
3644
+ "Verify the content group configuration in the dashboard",
3645
+ "Use getCurrentMember() to check the member's permissions array"
3646
+ ],
3647
+ docsUrl: "https://docs.memberstack.com/dom/content-protection"
3648
+ },
3649
+ // Catch-all
3650
+ [ErrorCodes.UNKNOWN_ERROR]: {
3651
+ message: "An unexpected error occurred.",
3652
+ category: "unknown",
3653
+ suggestions: [
3654
+ "Try the request again",
3655
+ "Check the Memberstack status page for any ongoing issues",
3656
+ "If the problem persists, contact support with the error details"
3657
+ ]
2941
3658
  }
2942
3659
  };
3660
+ function normalizeErrorCode(code) {
3661
+ return code.toLowerCase().replace(/_/g, "-");
3662
+ }
3663
+ function getMetadataForCode(code) {
3664
+ if (ErrorMetadata[code]) {
3665
+ return ErrorMetadata[code];
3666
+ }
3667
+ const normalized = normalizeErrorCode(code);
3668
+ for (const key of Object.keys(ErrorMetadata)) {
3669
+ if (normalizeErrorCode(key) === normalized) {
3670
+ return ErrorMetadata[key];
3671
+ }
3672
+ }
3673
+ return void 0;
3674
+ }
3675
+ var knownErrorCodes = new Set(Object.values(ErrorCodes));
2943
3676
  function isMemberstackError(error) {
2944
- return typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string";
3677
+ if (typeof error !== "object" || error === null || !("code" in error) || !("message" in error) || typeof error.code !== "string" || typeof error.message !== "string") {
3678
+ return false;
3679
+ }
3680
+ const code = error.code;
3681
+ if (knownErrorCodes.has(code) || knownErrorCodes.has(normalizeErrorCode(code))) {
3682
+ return true;
3683
+ }
3684
+ return code.includes("-") || code.includes("/");
2945
3685
  }
2946
3686
  function getErrorMessage(error, defaultMessage = "An unexpected error occurred") {
2947
3687
  if (isMemberstackError(error)) {
@@ -2977,7 +3717,7 @@ function getErrorSuggestions(error) {
2977
3717
  if (error.suggestions && error.suggestions.length > 0) {
2978
3718
  return error.suggestions;
2979
3719
  }
2980
- const metadata = ErrorMetadata[error.code];
3720
+ const metadata = getMetadataForCode(error.code);
2981
3721
  return (metadata == null ? void 0 : metadata.suggestions) || [];
2982
3722
  }
2983
3723
  function getErrorDocsUrl(error) {
@@ -2987,7 +3727,7 @@ function getErrorDocsUrl(error) {
2987
3727
  if (error.docsUrl) {
2988
3728
  return error.docsUrl;
2989
3729
  }
2990
- const metadata = ErrorMetadata[error.code];
3730
+ const metadata = getMetadataForCode(error.code);
2991
3731
  return metadata == null ? void 0 : metadata.docsUrl;
2992
3732
  }
2993
3733
  function getErrorCategory(error) {
@@ -2997,18 +3737,18 @@ function getErrorCategory(error) {
2997
3737
  if (error.category) {
2998
3738
  return error.category;
2999
3739
  }
3000
- const metadata = ErrorMetadata[error.code];
3740
+ const metadata = getMetadataForCode(error.code);
3001
3741
  return (metadata == null ? void 0 : metadata.category) || "unknown";
3002
3742
  }
3003
3743
  function formatErrorForUser(error) {
3004
3744
  if (!isMemberstackError(error)) {
3005
3745
  return "An unexpected error occurred. Please try again.";
3006
3746
  }
3007
- const metadata = ErrorMetadata[error.code];
3747
+ const metadata = getMetadataForCode(error.code);
3008
3748
  if (metadata) {
3009
3749
  return metadata.message;
3010
3750
  }
3011
- return error.message;
3751
+ return "Something went wrong. Please try again or contact support.";
3012
3752
  }
3013
3753
  function getErrorReport(error) {
3014
3754
  if (!isMemberstackError(error)) {