@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.
Files changed (87) hide show
  1. package/lib/index.d.mts +76 -61
  2. package/lib/index.d.ts +76 -61
  3. package/lib/index.js +840 -61
  4. package/lib/index.mjs +840 -61
  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.mjs CHANGED
@@ -191,10 +191,29 @@ var loadPrebuiltUI = (retries = 2) => __async(void 0, null, function* () {
191
191
  const script = document.createElement("script");
192
192
  script.src = getPrebuiltUIUrl();
193
193
  script.async = true;
194
- script.onload = () => {
195
- prebuiltUILoaded = true;
196
- resolve();
197
- };
194
+ script.onload = () => __async(void 0, null, function* () {
195
+ yield new Promise((r) => setTimeout(r, 0));
196
+ if (typeof customElements !== "undefined" && customElements.get("memberstack-prebuilt-ui")) {
197
+ prebuiltUILoaded = true;
198
+ resolve();
199
+ } else {
200
+ prebuiltUILoadPromise = null;
201
+ script.remove();
202
+ if (retries > 0) {
203
+ yield new Promise((r) => setTimeout(r, 1e3));
204
+ try {
205
+ yield loadPrebuiltUI(retries - 1);
206
+ resolve();
207
+ } catch (e) {
208
+ reject(e);
209
+ }
210
+ } else {
211
+ reject(new Error(
212
+ "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."
213
+ ));
214
+ }
215
+ }
216
+ });
198
217
  script.onerror = () => __async(void 0, null, function* () {
199
218
  prebuiltUILoadPromise = null;
200
219
  script.remove();
@@ -208,7 +227,7 @@ var loadPrebuiltUI = (retries = 2) => __async(void 0, null, function* () {
208
227
  }
209
228
  } else {
210
229
  reject(new Error(
211
- "Failed to load Memberstack modals after multiple attempts. Please check your internet connection."
230
+ "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."
212
231
  ));
213
232
  }
214
233
  });
@@ -249,7 +268,7 @@ var showMessage = (msg, isError) => __async(void 0, null, function* () {
249
268
  return;
250
269
  const messageTextBox = messageBox.querySelector("[data-ms-message-text]");
251
270
  if (messageTextBox) {
252
- messageTextBox.innerHTML = msg;
271
+ messageTextBox.textContent = msg;
253
272
  }
254
273
  messageBox.style.display = "block";
255
274
  const closeBtn = messageBox.querySelector("[data-ms-message-close]");
@@ -319,6 +338,7 @@ var hideLoader = (element) => {
319
338
  (_a = document.querySelector("[data-ms-modal-loader]")) == null ? void 0 : _a.remove();
320
339
  };
321
340
  var modal = null;
341
+ var resolveModal;
322
342
  var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, params = {}) {
323
343
  const isInspector = type.toLowerCase() === "inspector";
324
344
  const needsLoading = !prebuiltUILoaded;
@@ -328,12 +348,32 @@ var openModal = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (type, par
328
348
  }
329
349
  try {
330
350
  yield loadPrebuiltUI();
351
+ } catch (error) {
352
+ if (showLoaderForThisCall) {
353
+ hideLoader();
354
+ }
355
+ console.warn(
356
+ "[Memberstack] Modal failed to load.",
357
+ error instanceof Error ? error.message : error,
358
+ "\nHint: Set window.__MS_PREBUILT_UI_URL__ to override the CDN URL during local development."
359
+ );
360
+ throw error;
331
361
  } finally {
332
362
  if (showLoaderForThisCall) {
333
363
  hideLoader();
334
364
  }
335
365
  }
336
- let resolveModal;
366
+ if (modal) {
367
+ try {
368
+ modal.remove();
369
+ } catch (e) {
370
+ }
371
+ if (resolveModal) {
372
+ resolveModal({ type: "CLOSED" });
373
+ }
374
+ modal = null;
375
+ resolveModal = void 0;
376
+ }
337
377
  const modalPromise = new Promise((resolve) => {
338
378
  resolveModal = resolve;
339
379
  });
@@ -350,6 +390,11 @@ var hideModal = () => {
350
390
  modal == null ? void 0 : modal.remove();
351
391
  } catch (e) {
352
392
  }
393
+ if (resolveModal) {
394
+ resolveModal({ type: "CLOSED" });
395
+ }
396
+ modal = null;
397
+ resolveModal = void 0;
353
398
  };
354
399
 
355
400
  // src/utils/cookies.ts
@@ -410,10 +455,11 @@ var setMemberToken = (token, expires) => {
410
455
  localStorage.setItem(memberAuthTokenName, token);
411
456
  } else {
412
457
  const domain = extractDomainFromHostname(window.location.hostname);
413
- Cookie.set(memberAuthTokenName, token, __spreadValues({
458
+ const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
459
+ Cookie.set(memberAuthTokenName, token, __spreadValues(__spreadValues({
414
460
  expires: expires && Number(expires) || 14,
415
461
  sameSite: "strict"
416
- }, setCookieOnRootDomain && { domain }));
462
+ }, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
417
463
  }
418
464
  };
419
465
  var removeMemberToken = () => {
@@ -421,14 +467,11 @@ var removeMemberToken = () => {
421
467
  localStorage.removeItem(memberAuthTokenName);
422
468
  }
423
469
  const domain = extractDomainFromHostname(window.location.hostname);
424
- Cookie.set(memberAuthTokenName, "", __spreadValues({
425
- expires: -1,
426
- sameSite: "strict"
427
- }, setCookieOnRootDomain && { domain }));
428
- Cookie.set(memberAuthTokenName, "", {
470
+ const isSecure = typeof window !== "undefined" && window.location.protocol === "https:";
471
+ Cookie.set(memberAuthTokenName, "", __spreadValues(__spreadValues({
429
472
  expires: -1,
430
473
  sameSite: "strict"
431
- });
474
+ }, isSecure && { secure: true }), setCookieOnRootDomain && { domain }));
432
475
  };
433
476
  var getMemberToken = () => {
434
477
  if (localStorageAvailable) {
@@ -442,8 +485,13 @@ var setMemberTokenIfAvailable = () => {
442
485
  if (typeof window !== "undefined") {
443
486
  const urlParams = new URLSearchParams(window.location.search);
444
487
  const memberToken = urlParams.get("memberToken");
445
- if (memberToken)
488
+ if (memberToken) {
446
489
  setMemberToken(memberToken);
490
+ urlParams.delete("memberToken");
491
+ const newSearch = urlParams.toString();
492
+ const newUrl = newSearch ? `${window.location.pathname}?${newSearch}${window.location.hash}` : `${window.location.pathname}${window.location.hash}`;
493
+ window.history.replaceState({}, "", newUrl);
494
+ }
447
495
  }
448
496
  };
449
497
  var getSessionId = () => {
@@ -486,6 +534,11 @@ var createRequestHandler = ({
486
534
  token,
487
535
  customEndpoint
488
536
  }) => {
537
+ if (!publicKey) {
538
+ throw new Error(
539
+ "Memberstack: publicKey is required. Pass your public key to memberstack.init({ publicKey: 'pk_...' })"
540
+ );
541
+ }
489
542
  return {
490
543
  sendRequest: (data, options) => __async(void 0, null, function* () {
491
544
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -503,7 +556,9 @@ var createRequestHandler = ({
503
556
  method: data.method,
504
557
  data: data.data,
505
558
  url: formattedUrl,
506
- 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 }), {
559
+ headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), {
560
+ ["X-API-Key" /* API_KEY */]: publicKey
561
+ }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
507
562
  ["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
508
563
  }), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
509
564
  ["X-Session-ID" /* SESSION_ID */]: sessionToken
@@ -527,8 +582,12 @@ var createRequestHandler = ({
527
582
  return res == null ? void 0 : res.data;
528
583
  } catch (e) {
529
584
  const error = e;
530
- if (!error.response)
531
- throw e;
585
+ if (!error.response) {
586
+ throw {
587
+ code: "network-error",
588
+ message: (error == null ? void 0 : error.message) || "Network request failed. Please check your internet connection."
589
+ };
590
+ }
532
591
  throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
533
592
  }
534
593
  }),
@@ -543,7 +602,9 @@ var createRequestHandler = ({
543
602
  options == null ? void 0 : options.token
544
603
  ].find((x) => x);
545
604
  const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
546
- const fetchHeaders = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
605
+ const fetchHeaders = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), {
606
+ ["X-API-Key" /* API_KEY */]: publicKey
607
+ }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
547
608
  ["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
548
609
  "Content-Type": "application/json",
549
610
  Referer: window.location.href
@@ -581,8 +642,13 @@ var createRequestHandler = ({
581
642
  }
582
643
  return result;
583
644
  } catch (e) {
584
- console.error("Error in sendRequestWithFetch:", e);
585
- throw e;
645
+ if (e && typeof e === "object" && "code" in e && "message" in e) {
646
+ throw e;
647
+ }
648
+ throw {
649
+ code: "network-error",
650
+ message: (e == null ? void 0 : e.message) || "Network request failed. Please check your internet connection."
651
+ };
586
652
  }
587
653
  })
588
654
  };
@@ -607,8 +673,12 @@ var createObservable = () => {
607
673
  };
608
674
  var observable = createObservable();
609
675
  var getPersistedMember = () => {
610
- const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
611
- return stored ? JSON.parse(stored) : null;
676
+ try {
677
+ const stored = localStorage == null ? void 0 : localStorage.getItem("_ms-mem");
678
+ return stored ? JSON.parse(stored) : null;
679
+ } catch (e) {
680
+ return null;
681
+ }
612
682
  };
613
683
  var setPersistedMember = (member) => {
614
684
  if (member) {
@@ -634,8 +704,9 @@ var unsetPersistedMember = () => {
634
704
  removeSessionId();
635
705
  observable.notify(null);
636
706
  };
707
+ var nextSubscriberId = 0;
637
708
  var onAuthChange = (cb) => {
638
- const id = Math.floor(Math.random() * 1e3);
709
+ const id = nextSubscriberId++;
639
710
  observable.subscribe(id, cb);
640
711
  return {
641
712
  unsubscribe: () => observable.unsubscribe(id)
@@ -799,6 +870,8 @@ var initRequest = ({
799
870
  * window.location.href = '/goodbye';
800
871
  * }
801
872
  * ```
873
+ *
874
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
802
875
  */
803
876
  deleteMember() {
804
877
  return __async(this, null, function* () {
@@ -810,6 +883,15 @@ var initRequest = ({
810
883
  return data;
811
884
  });
812
885
  },
886
+ /**
887
+ * Sends a typing indicator to a comments channel.
888
+ * Used internally to show when a member is actively composing a post.
889
+ *
890
+ * @internal
891
+ * @param params - The typing indicator parameters
892
+ * @param params.channelKey - The key/identifier of the channel
893
+ * @returns Promise that resolves when the typing indicator is sent
894
+ */
813
895
  postIsTyping(params) {
814
896
  return __async(this, null, function* () {
815
897
  return sendRequest({
@@ -821,6 +903,15 @@ var initRequest = ({
821
903
  });
822
904
  });
823
905
  },
906
+ /**
907
+ * Retrieves information about a comments channel.
908
+ * Returns channel metadata and configuration.
909
+ *
910
+ * @internal
911
+ * @param params - The channel info parameters
912
+ * @param params.channelKey - The key/identifier of the channel
913
+ * @returns Promise resolving to the channel information
914
+ */
824
915
  getChannelInfo(params) {
825
916
  return __async(this, null, function* () {
826
917
  const queryParams = new URLSearchParams({
@@ -832,6 +923,16 @@ var initRequest = ({
832
923
  });
833
924
  });
834
925
  },
926
+ /**
927
+ * Manages a member's notification subscription to a comments channel.
928
+ * Allows members to subscribe or unsubscribe from channel notifications.
929
+ *
930
+ * @internal
931
+ * @param params - The subscription parameters
932
+ * @param params.channelKey - The key/identifier of the channel
933
+ * @param params.action - The subscription action: 'NONE' to unsubscribe, 'THREADS_ONLY' to receive thread notifications
934
+ * @returns Promise that resolves when the subscription is updated
935
+ */
835
936
  subscribeToChannel(params) {
836
937
  return __async(this, null, function* () {
837
938
  return sendRequest({
@@ -844,6 +945,27 @@ var initRequest = ({
844
945
  });
845
946
  });
846
947
  },
948
+ /**
949
+ * Retrieves posts from a comments channel.
950
+ * Use this to display comments or discussion threads on your site.
951
+ *
952
+ * @param params - Query parameters
953
+ * @param params.channelKey - The key identifying the channel to fetch posts from
954
+ * @param params.order - Sort order: 'newest' or 'oldest'
955
+ * @param params.after - Cursor for pagination (post ID to start after)
956
+ * @param params.limit - Maximum number of posts to return
957
+ * @returns Promise resolving to an array of posts
958
+ *
959
+ * @example
960
+ * ```typescript
961
+ * const { data } = await memberstack.getPosts({
962
+ * channelKey: 'blog-comments',
963
+ * order: 'newest',
964
+ * limit: 20
965
+ * });
966
+ * data.posts.forEach(post => console.log(post.content));
967
+ * ```
968
+ */
847
969
  getPosts(params) {
848
970
  return __async(this, null, function* () {
849
971
  const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
@@ -861,6 +983,26 @@ var initRequest = ({
861
983
  });
862
984
  });
863
985
  },
986
+ /**
987
+ * Retrieves threads (replies) for a specific post.
988
+ *
989
+ * @param params - Query parameters
990
+ * @param params.postId - The ID of the parent post
991
+ * @param params.order - Sort order: 'newest' or 'oldest'
992
+ * @param params.after - Cursor for pagination (thread ID to start after)
993
+ * @param params.limit - Maximum number of threads to return
994
+ * @returns Promise resolving to an array of threads
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const { data } = await memberstack.getThreads({
999
+ * postId: 'post_abc123',
1000
+ * order: 'oldest',
1001
+ * limit: 50
1002
+ * });
1003
+ * data.threads.forEach(thread => console.log(thread.content));
1004
+ * ```
1005
+ */
864
1006
  getThreads(params) {
865
1007
  return __async(this, null, function* () {
866
1008
  const queryParams = new URLSearchParams(__spreadValues(__spreadValues(__spreadValues({
@@ -878,6 +1020,23 @@ var initRequest = ({
878
1020
  });
879
1021
  });
880
1022
  },
1023
+ /**
1024
+ * Creates a new post in a comments channel.
1025
+ *
1026
+ * @param params - Post data
1027
+ * @param params.channelKey - The key of the channel to post in
1028
+ * @param params.content - The content of the post (supports markdown)
1029
+ * @returns Promise resolving to the created post
1030
+ *
1031
+ * @example
1032
+ * ```typescript
1033
+ * const { data: post } = await memberstack.createPost({
1034
+ * channelKey: 'blog-comments',
1035
+ * content: 'Great article! Thanks for sharing.'
1036
+ * });
1037
+ * console.log('Posted:', post.id);
1038
+ * ```
1039
+ */
881
1040
  createPost(params) {
882
1041
  return __async(this, null, function* () {
883
1042
  return sendRequest({
@@ -891,6 +1050,23 @@ var initRequest = ({
891
1050
  });
892
1051
  });
893
1052
  },
1053
+ /**
1054
+ * Updates an existing post's content.
1055
+ * Only the post author can update their post.
1056
+ *
1057
+ * @param params - Update data
1058
+ * @param params.postId - The ID of the post to update
1059
+ * @param params.content - The new content for the post
1060
+ * @returns Promise resolving to the updated post
1061
+ *
1062
+ * @example
1063
+ * ```typescript
1064
+ * const { data: post } = await memberstack.updatePost({
1065
+ * postId: 'post_abc123',
1066
+ * content: 'Updated: Great article with corrections!'
1067
+ * });
1068
+ * ```
1069
+ */
894
1070
  updatePost(params) {
895
1071
  return __async(this, null, function* () {
896
1072
  return sendRequest({
@@ -902,6 +1078,29 @@ var initRequest = ({
902
1078
  });
903
1079
  });
904
1080
  },
1081
+ /**
1082
+ * Votes on a post (upvote, downvote, or remove vote).
1083
+ *
1084
+ * @param params - Vote data
1085
+ * @param params.postId - The ID of the post to vote on
1086
+ * @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
1087
+ * @returns Promise resolving when the vote is recorded
1088
+ *
1089
+ * @example
1090
+ * ```typescript
1091
+ * // Upvote a post
1092
+ * await memberstack.postVote({
1093
+ * postId: 'post_abc123',
1094
+ * vote: 'UP'
1095
+ * });
1096
+ *
1097
+ * // Remove vote
1098
+ * await memberstack.postVote({
1099
+ * postId: 'post_abc123',
1100
+ * vote: 'NONE'
1101
+ * });
1102
+ * ```
1103
+ */
905
1104
  postVote(params) {
906
1105
  return __async(this, null, function* () {
907
1106
  return sendRequest({
@@ -913,6 +1112,21 @@ var initRequest = ({
913
1112
  });
914
1113
  });
915
1114
  },
1115
+ /**
1116
+ * Deletes a post.
1117
+ * Only the post author can delete their post.
1118
+ *
1119
+ * @param params - Delete parameters
1120
+ * @param params.postId - The ID of the post to delete
1121
+ * @returns Promise resolving when the post is deleted
1122
+ *
1123
+ * @example
1124
+ * ```typescript
1125
+ * await memberstack.deletePost({
1126
+ * postId: 'post_abc123'
1127
+ * });
1128
+ * ```
1129
+ */
916
1130
  deletePost(params) {
917
1131
  return __async(this, null, function* () {
918
1132
  return sendRequest({
@@ -921,6 +1135,22 @@ var initRequest = ({
921
1135
  });
922
1136
  });
923
1137
  },
1138
+ /**
1139
+ * Creates a reply thread on a post.
1140
+ *
1141
+ * @param params - Thread data
1142
+ * @param params.postId - The ID of the post to reply to
1143
+ * @param params.content - The content of the reply (supports markdown)
1144
+ * @returns Promise resolving to the created thread
1145
+ *
1146
+ * @example
1147
+ * ```typescript
1148
+ * const { data: thread } = await memberstack.createThread({
1149
+ * postId: 'post_abc123',
1150
+ * content: 'I agree with this point!'
1151
+ * });
1152
+ * ```
1153
+ */
924
1154
  createThread(params) {
925
1155
  return __async(this, null, function* () {
926
1156
  return sendRequest({
@@ -933,6 +1163,23 @@ var initRequest = ({
933
1163
  });
934
1164
  });
935
1165
  },
1166
+ /**
1167
+ * Updates an existing thread's content.
1168
+ * Only the thread author can update their thread.
1169
+ *
1170
+ * @param params - Update data
1171
+ * @param params.threadId - The ID of the thread to update
1172
+ * @param params.content - The new content for the thread
1173
+ * @returns Promise resolving to the updated thread
1174
+ *
1175
+ * @example
1176
+ * ```typescript
1177
+ * const { data: thread } = await memberstack.updateThread({
1178
+ * threadId: 'thread_xyz789',
1179
+ * content: 'Updated reply with more details.'
1180
+ * });
1181
+ * ```
1182
+ */
936
1183
  updateThread(params) {
937
1184
  return __async(this, null, function* () {
938
1185
  return sendRequest({
@@ -944,7 +1191,22 @@ var initRequest = ({
944
1191
  });
945
1192
  });
946
1193
  },
947
- // vote thread
1194
+ /**
1195
+ * Votes on a thread (upvote, downvote, or remove vote).
1196
+ *
1197
+ * @param params - Vote data
1198
+ * @param params.threadId - The ID of the thread to vote on
1199
+ * @param params.vote - Vote type: 'UP', 'DOWN', or 'NONE' to remove vote
1200
+ * @returns Promise resolving when the vote is recorded
1201
+ *
1202
+ * @example
1203
+ * ```typescript
1204
+ * await memberstack.threadVote({
1205
+ * threadId: 'thread_xyz789',
1206
+ * vote: 'UP'
1207
+ * });
1208
+ * ```
1209
+ */
948
1210
  threadVote(params) {
949
1211
  return __async(this, null, function* () {
950
1212
  return sendRequest({
@@ -956,6 +1218,21 @@ var initRequest = ({
956
1218
  });
957
1219
  });
958
1220
  },
1221
+ /**
1222
+ * Deletes a thread.
1223
+ * Only the thread author can delete their thread.
1224
+ *
1225
+ * @param params - Delete parameters
1226
+ * @param params.threadId - The ID of the thread to delete
1227
+ * @returns Promise resolving when the thread is deleted
1228
+ *
1229
+ * @example
1230
+ * ```typescript
1231
+ * await memberstack.deleteThread({
1232
+ * threadId: 'thread_xyz789'
1233
+ * });
1234
+ * ```
1235
+ */
959
1236
  deleteThread(params) {
960
1237
  return __async(this, null, function* () {
961
1238
  return sendRequest({
@@ -977,8 +1254,10 @@ var initRequest = ({
977
1254
  * const { data: content } = await memberstack.getSecureContent({
978
1255
  * contentId: 'cnt_abc123'
979
1256
  * });
980
- * document.getElementById('premium-content').innerHTML = content.html;
1257
+ * document.getElementById('premium-content').innerHTML = content.content;
981
1258
  * ```
1259
+ *
1260
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Protected Content Documentation}
982
1261
  */
983
1262
  getSecureContent(params) {
984
1263
  return __async(this, null, function* () {
@@ -1019,6 +1298,8 @@ var initRequest = ({
1019
1298
  * plans: [{ planId: 'pln_free' }]
1020
1299
  * });
1021
1300
  * ```
1301
+ *
1302
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1022
1303
  */
1023
1304
  signupWithProvider(params) {
1024
1305
  return __async(this, null, function* () {
@@ -1069,6 +1350,8 @@ var initRequest = ({
1069
1350
  * allowSignup: true
1070
1351
  * });
1071
1352
  * ```
1353
+ *
1354
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1072
1355
  */
1073
1356
  loginWithProvider(params) {
1074
1357
  return __async(this, null, function* () {
@@ -1101,6 +1384,8 @@ var initRequest = ({
1101
1384
  * });
1102
1385
  * // Member can now log in with either email/password or Google
1103
1386
  * ```
1387
+ *
1388
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1104
1389
  */
1105
1390
  connectProvider(params) {
1106
1391
  return __async(this, null, function* () {
@@ -1132,6 +1417,8 @@ var initRequest = ({
1132
1417
  * });
1133
1418
  * // Member must now use email/password or another connected provider
1134
1419
  * ```
1420
+ *
1421
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1135
1422
  */
1136
1423
  disconnectProvider(params) {
1137
1424
  return __async(this, null, function* () {
@@ -1144,6 +1431,16 @@ var initRequest = ({
1144
1431
  });
1145
1432
  });
1146
1433
  },
1434
+ /**
1435
+ * Retrieves both app configuration and current member data in a single request.
1436
+ * Used internally for initial page load to efficiently fetch all required data.
1437
+ * Also handles session tracking and conversion data.
1438
+ *
1439
+ * @internal
1440
+ * @param params - Optional parameters
1441
+ * @param params.trackPageView - Whether to track this as a page view for analytics (default: false)
1442
+ * @returns Promise resolving to both app and member data
1443
+ */
1147
1444
  getAppAndMember(params) {
1148
1445
  return __async(this, null, function* () {
1149
1446
  var _a2, _b;
@@ -1152,7 +1449,6 @@ var initRequest = ({
1152
1449
  url: `/app-member`,
1153
1450
  data: {
1154
1451
  data: {
1155
- // @ts-ignore
1156
1452
  includeSSOText: window == null ? void 0 : window.ssoUI,
1157
1453
  trackPageView: params == null ? void 0 : params.trackPageView,
1158
1454
  sessionData: __spreadValues({}, getConversionData())
@@ -1181,12 +1477,14 @@ var initRequest = ({
1181
1477
  * console.log('App name:', app.name);
1182
1478
  * console.log('OAuth providers:', app.authProviders);
1183
1479
  * ```
1480
+ *
1481
+ * @see {@link https://developers.memberstack.com/dom-package/quick-start | Quick Start Documentation}
1184
1482
  */
1185
1483
  getApp() {
1186
1484
  return __async(this, null, function* () {
1485
+ var _a2;
1187
1486
  const queryParams = new URLSearchParams({
1188
- // @ts-ignore
1189
- includeSSOText: window == null ? void 0 : window.ssoUI
1487
+ includeSSOText: String((_a2 = window == null ? void 0 : window.ssoUI) != null ? _a2 : "")
1190
1488
  });
1191
1489
  return sendRequest({
1192
1490
  method: "GET" /* GET */,
@@ -1216,6 +1514,8 @@ var initRequest = ({
1216
1514
  * console.error('Login failed:', error.message);
1217
1515
  * }
1218
1516
  * ```
1517
+ *
1518
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1219
1519
  */
1220
1520
  loginMemberEmailPassword(params, options) {
1221
1521
  return __async(this, null, function* () {
@@ -1253,6 +1553,8 @@ var initRequest = ({
1253
1553
  *
1254
1554
  * // Step 2: Complete login with the code (see loginMemberPasswordless)
1255
1555
  * ```
1556
+ *
1557
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1256
1558
  */
1257
1559
  sendMemberLoginPasswordlessEmail(params, options) {
1258
1560
  return __async(this, null, function* () {
@@ -1282,6 +1584,8 @@ var initRequest = ({
1282
1584
  *
1283
1585
  * // Step 2: Complete signup with the code (see signupMemberPasswordless)
1284
1586
  * ```
1587
+ *
1588
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1285
1589
  */
1286
1590
  sendMemberSignupPasswordlessEmail(params, options) {
1287
1591
  return __async(this, null, function* () {
@@ -1313,6 +1617,8 @@ var initRequest = ({
1313
1617
  * });
1314
1618
  * console.log('Logged in:', data.member.auth.email);
1315
1619
  * ```
1620
+ *
1621
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
1316
1622
  */
1317
1623
  loginMemberPasswordless(params, options) {
1318
1624
  return __async(this, null, function* () {
@@ -1347,6 +1653,8 @@ var initRequest = ({
1347
1653
  * console.log('Plan:', plan.name);
1348
1654
  * console.log('Prices:', plan.prices);
1349
1655
  * ```
1656
+ *
1657
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1350
1658
  */
1351
1659
  getPlan(params) {
1352
1660
  return __async(this, null, function* () {
@@ -1385,6 +1693,8 @@ var initRequest = ({
1385
1693
  * </div>
1386
1694
  * `).join('');
1387
1695
  * ```
1696
+ *
1697
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1388
1698
  */
1389
1699
  getPlans() {
1390
1700
  return __async(this, null, function* () {
@@ -1409,7 +1719,7 @@ var initRequest = ({
1409
1719
  *
1410
1720
  * groups.forEach(group => {
1411
1721
  * console.log('Group:', group.name);
1412
- * console.log('Required plans:', group.planIds);
1722
+ * console.log('Required plans:', group.plans.map(p => p.id));
1413
1723
  * console.log('URLs:', group.urls);
1414
1724
  * });
1415
1725
  * ```
@@ -1456,6 +1766,8 @@ var initRequest = ({
1456
1766
  * const hasPro = member.planConnections.some(p => p.planId === 'pln_pro');
1457
1767
  * }
1458
1768
  * ```
1769
+ *
1770
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1459
1771
  */
1460
1772
  getCurrentMember(options) {
1461
1773
  return __async(this, null, function* () {
@@ -1494,6 +1806,8 @@ var initRequest = ({
1494
1806
  * console.log('Preferences:', json.preferences);
1495
1807
  * console.log('Last visited:', json.lastVisitedPage);
1496
1808
  * ```
1809
+ *
1810
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
1497
1811
  */
1498
1812
  getMemberJSON(options) {
1499
1813
  return __async(this, null, function* () {
@@ -1506,7 +1820,7 @@ var initRequest = ({
1506
1820
  },
1507
1821
  /**
1508
1822
  * Updates the current member's JSON data store.
1509
- * You can store any JSON-serializable data. Updates are merged with existing data.
1823
+ * You can store any JSON-serializable data. This completely replaces the existing JSON.
1510
1824
  *
1511
1825
  * @param params - JSON data to store
1512
1826
  * @param params.json - Object containing the data to store
@@ -1532,6 +1846,8 @@ var initRequest = ({
1532
1846
  * }
1533
1847
  * });
1534
1848
  * ```
1849
+ *
1850
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member JSON Documentation}
1535
1851
  */
1536
1852
  updateMemberJSON(params, options) {
1537
1853
  return __async(this, null, function* () {
@@ -1560,10 +1876,13 @@ var initRequest = ({
1560
1876
  * });
1561
1877
  * console.log('Plan added, redirect:', data.redirect);
1562
1878
  * ```
1879
+ *
1880
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1563
1881
  */
1564
1882
  addPlan(params, options) {
1565
1883
  return __async(this, null, function* () {
1566
- return sendRequest({
1884
+ var _a2;
1885
+ const result = yield sendRequest({
1567
1886
  method: "POST" /* POST */,
1568
1887
  url: `/member/plans/add`,
1569
1888
  data: {
@@ -1571,6 +1890,10 @@ var initRequest = ({
1571
1890
  },
1572
1891
  headers: addHeaders(options)
1573
1892
  });
1893
+ if ((_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.member) {
1894
+ setPersistedMember(result.data.member);
1895
+ }
1896
+ return result;
1574
1897
  });
1575
1898
  },
1576
1899
  /**
@@ -1615,6 +1938,8 @@ var initRequest = ({
1615
1938
  * cancelUrl: '/pricing'
1616
1939
  * });
1617
1940
  * ```
1941
+ *
1942
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1618
1943
  */
1619
1944
  purchasePlansWithCheckout(params, options) {
1620
1945
  return __async(this, null, function* () {
@@ -1683,6 +2008,8 @@ var initRequest = ({
1683
2008
  * });
1684
2009
  * console.log('Portal URL:', data.url);
1685
2010
  * ```
2011
+ *
2012
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1686
2013
  */
1687
2014
  launchStripeCustomerPortal(params, options) {
1688
2015
  return __async(this, null, function* () {
@@ -1734,10 +2061,13 @@ var initRequest = ({
1734
2061
  * });
1735
2062
  * // Plan removed/subscription cancelled
1736
2063
  * ```
2064
+ *
2065
+ * @see {@link https://developers.memberstack.com/dom-package/plan-management | Plan Management Documentation}
1737
2066
  */
1738
2067
  removePlan(params, options) {
1739
2068
  return __async(this, null, function* () {
1740
- return sendRequest({
2069
+ var _a2;
2070
+ const result = yield sendRequest({
1741
2071
  method: "POST" /* POST */,
1742
2072
  url: `/member/plans/remove`,
1743
2073
  data: {
@@ -1745,6 +2075,10 @@ var initRequest = ({
1745
2075
  },
1746
2076
  headers: addHeaders(options)
1747
2077
  });
2078
+ if ((_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.member) {
2079
+ setPersistedMember(result.data.member);
2080
+ }
2081
+ return result;
1748
2082
  });
1749
2083
  },
1750
2084
  /**
@@ -1775,6 +2109,8 @@ var initRequest = ({
1775
2109
  * }
1776
2110
  * });
1777
2111
  * ```
2112
+ *
2113
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1778
2114
  */
1779
2115
  updateMember(params, options) {
1780
2116
  return __async(this, null, function* () {
@@ -1812,6 +2148,8 @@ var initRequest = ({
1812
2148
  * newPassword: 'newSecurePassword123'
1813
2149
  * });
1814
2150
  * ```
2151
+ *
2152
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1815
2153
  */
1816
2154
  updateMemberAuth(params, options) {
1817
2155
  return __async(this, null, function* () {
@@ -1839,6 +2177,8 @@ var initRequest = ({
1839
2177
  * });
1840
2178
  * // Member can now log in with email/password
1841
2179
  * ```
2180
+ *
2181
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
1842
2182
  */
1843
2183
  setPassword(params, options) {
1844
2184
  return __async(this, null, function* () {
@@ -1852,6 +2192,33 @@ var initRequest = ({
1852
2192
  });
1853
2193
  });
1854
2194
  },
2195
+ /**
2196
+ * Completes passwordless signup using the code sent via email.
2197
+ * Creates a new member account without requiring a password.
2198
+ *
2199
+ * @param params - Signup details
2200
+ * @param params.email - The new member's email address
2201
+ * @param params.passwordlessToken - The one-time code from the signup email
2202
+ * @param params.customFields - Optional custom field values defined in your Memberstack dashboard
2203
+ * @param params.plans - Optional array of plan IDs to assign on signup (for free plans)
2204
+ * @param params.metaData - Optional metadata to store with the member
2205
+ * @returns Promise resolving to the new member data and tokens
2206
+ * @throws When the code is invalid, expired, or email is already in use
2207
+ *
2208
+ * @example Complete passwordless signup flow
2209
+ * ```typescript
2210
+ * // Step 1: Send signup code (see sendMemberSignupPasswordlessEmail)
2211
+ * // Step 2: User enters code, complete signup:
2212
+ * const { data } = await memberstack.signupMemberPasswordless({
2213
+ * email: 'newuser@example.com',
2214
+ * passwordlessToken: '123456',
2215
+ * customFields: { firstName: 'Jane' }
2216
+ * });
2217
+ * console.log('Welcome!', data.member.id);
2218
+ * ```
2219
+ *
2220
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
2221
+ */
1855
2222
  signupMemberPasswordless(params, options) {
1856
2223
  return __async(this, null, function* () {
1857
2224
  var _a2, _b, _c;
@@ -1872,9 +2239,7 @@ var initRequest = ({
1872
2239
  options
1873
2240
  }), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
1874
2241
  rewardfulData: {
1875
- // @ts-ignore
1876
2242
  referral: window.Rewardful.referral,
1877
- // @ts-ignore
1878
2243
  coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
1879
2244
  }
1880
2245
  })
@@ -1921,6 +2286,8 @@ var initRequest = ({
1921
2286
  * plans: [{ planId: 'pln_free_tier' }]
1922
2287
  * });
1923
2288
  * ```
2289
+ *
2290
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Signup Documentation}
1924
2291
  */
1925
2292
  signupMemberEmailPassword(params, options) {
1926
2293
  return __async(this, null, function* () {
@@ -1944,9 +2311,7 @@ var initRequest = ({
1944
2311
  options
1945
2312
  }), ((_b = window.Rewardful) == null ? void 0 : _b.referral) && {
1946
2313
  rewardfulData: {
1947
- // @ts-ignore
1948
2314
  referral: window.Rewardful.referral,
1949
- // @ts-ignore
1950
2315
  coupon: (_c = window.Rewardful.coupon) == null ? void 0 : _c.id
1951
2316
  }
1952
2317
  })
@@ -1957,6 +2322,25 @@ var initRequest = ({
1957
2322
  return data;
1958
2323
  });
1959
2324
  },
2325
+ /**
2326
+ * Joins a team using an invite token.
2327
+ * The invite token is typically sent by a team admin via email.
2328
+ *
2329
+ * @param params - Join parameters
2330
+ * @param params.inviteToken - The invite token received from the team admin
2331
+ * @returns Promise resolving when the member has joined the team
2332
+ *
2333
+ * @example
2334
+ * ```typescript
2335
+ * // Extract token from URL (e.g., /join?token=abc123)
2336
+ * const token = new URLSearchParams(window.location.search).get('token');
2337
+ *
2338
+ * await memberstack.joinTeam({
2339
+ * inviteToken: token
2340
+ * });
2341
+ * console.log('Successfully joined the team!');
2342
+ * ```
2343
+ */
1960
2344
  joinTeam(params, options) {
1961
2345
  return __async(this, null, function* () {
1962
2346
  return sendRequest({
@@ -1969,6 +2353,21 @@ var initRequest = ({
1969
2353
  });
1970
2354
  });
1971
2355
  },
2356
+ /**
2357
+ * Retrieves information about a team the current member belongs to.
2358
+ *
2359
+ * @param params - Team parameters
2360
+ * @param params.teamId - The ID of the team to retrieve
2361
+ * @returns Promise resolving to the team details
2362
+ *
2363
+ * @example
2364
+ * ```typescript
2365
+ * const team = await memberstack.getTeam({
2366
+ * teamId: 'team_abc123'
2367
+ * });
2368
+ * console.log('Team members:', team);
2369
+ * ```
2370
+ */
1972
2371
  getTeam(params, options) {
1973
2372
  return __async(this, null, function* () {
1974
2373
  return sendRequest({
@@ -1978,6 +2377,24 @@ var initRequest = ({
1978
2377
  });
1979
2378
  });
1980
2379
  },
2380
+ /**
2381
+ * Removes a member from a team.
2382
+ * Only team admins can remove other members.
2383
+ *
2384
+ * @param params - Removal parameters
2385
+ * @param params.teamId - The ID of the team
2386
+ * @param params.memberId - The ID of the member to remove
2387
+ * @returns Promise resolving when the member has been removed
2388
+ *
2389
+ * @example
2390
+ * ```typescript
2391
+ * await memberstack.removeMemberFromTeam({
2392
+ * teamId: 'team_abc123',
2393
+ * memberId: 'mem_xyz789'
2394
+ * });
2395
+ * console.log('Member removed from team');
2396
+ * ```
2397
+ */
1981
2398
  removeMemberFromTeam(params, options) {
1982
2399
  return __async(this, null, function* () {
1983
2400
  return sendRequest({
@@ -1991,6 +2408,23 @@ var initRequest = ({
1991
2408
  });
1992
2409
  });
1993
2410
  },
2411
+ /**
2412
+ * Generates an invite token for a team.
2413
+ * The token can be shared with users to invite them to join the team.
2414
+ *
2415
+ * @param params - Token parameters
2416
+ * @param params.teamId - The ID of the team to generate an invite for
2417
+ * @returns Promise resolving to the generated invite token
2418
+ *
2419
+ * @example
2420
+ * ```typescript
2421
+ * const invite = await memberstack.generateInviteToken({
2422
+ * teamId: 'team_abc123'
2423
+ * });
2424
+ * // Share the invite link with new team members
2425
+ * const inviteUrl = `${window.location.origin}/join?token=${invite.token}`;
2426
+ * ```
2427
+ */
1994
2428
  generateInviteToken(params, options) {
1995
2429
  return __async(this, null, function* () {
1996
2430
  return sendRequest({
@@ -2004,12 +2438,12 @@ var initRequest = ({
2004
2438
  });
2005
2439
  },
2006
2440
  /**
2007
- * Uploads a new profile image for the current member.
2008
- * Accepts a File object (from an input element) or a Blob.
2441
+ * Updates or removes the current member's profile image.
2442
+ * Pass a File to upload a new image, or null to remove the existing image.
2009
2443
  *
2010
2444
  * @param params - Image parameters
2011
- * @param params.profileImage - The image file to upload
2012
- * @returns Promise resolving to the new profile image URL
2445
+ * @param params.profileImage - The image file to upload, or null to remove
2446
+ * @returns Promise resolving to the new profile image URL (or null if removed)
2013
2447
  *
2014
2448
  * @example Upload from file input
2015
2449
  * ```typescript
@@ -2021,11 +2455,24 @@ var initRequest = ({
2021
2455
  * });
2022
2456
  * console.log('New image URL:', data.profileImage);
2023
2457
  * ```
2458
+ *
2459
+ * @example Remove profile image
2460
+ * ```typescript
2461
+ * const { data } = await memberstack.updateMemberProfileImage({
2462
+ * profileImage: null
2463
+ * });
2464
+ * console.log('Image removed:', data.profileImage === null);
2465
+ * ```
2466
+ *
2467
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
2024
2468
  */
2025
2469
  updateMemberProfileImage(params) {
2026
2470
  return __async(this, null, function* () {
2027
- if (!params.profileImage) {
2028
- throw new Error("profileImage is required");
2471
+ if (params.profileImage === null) {
2472
+ return sendRequest({
2473
+ method: "DELETE" /* DELETE */,
2474
+ url: `/member/profile-image`
2475
+ });
2029
2476
  }
2030
2477
  const formData = new FormData();
2031
2478
  formData.append("profileImage", params.profileImage);
@@ -2037,6 +2484,28 @@ var initRequest = ({
2037
2484
  });
2038
2485
  });
2039
2486
  },
2487
+ /**
2488
+ * Removes the current member's profile image.
2489
+ * After deletion, the member's profileImage field will be null.
2490
+ *
2491
+ * @returns Promise resolving to confirmation that the image was removed
2492
+ *
2493
+ * @example
2494
+ * ```typescript
2495
+ * await memberstack.deleteMemberProfileImage();
2496
+ * console.log('Profile image removed');
2497
+ * ```
2498
+ *
2499
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Profile Documentation}
2500
+ */
2501
+ deleteMemberProfileImage() {
2502
+ return __async(this, null, function* () {
2503
+ return sendRequest({
2504
+ method: "DELETE" /* DELETE */,
2505
+ url: `/member/profile-image`
2506
+ });
2507
+ });
2508
+ },
2040
2509
  /**
2041
2510
  * Sends a verification email to the current member.
2042
2511
  * Use this when email verification is enabled in your Memberstack settings.
@@ -2048,6 +2517,8 @@ var initRequest = ({
2048
2517
  * await memberstack.sendMemberVerificationEmail();
2049
2518
  * // Show message: "Verification email sent! Check your inbox."
2050
2519
  * ```
2520
+ *
2521
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Member Verification Documentation}
2051
2522
  */
2052
2523
  sendMemberVerificationEmail() {
2053
2524
  return __async(this, null, function* () {
@@ -2076,6 +2547,8 @@ var initRequest = ({
2076
2547
  * });
2077
2548
  * // Show confirmation: "Check your email for reset instructions"
2078
2549
  * ```
2550
+ *
2551
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
2079
2552
  */
2080
2553
  sendMemberResetPasswordEmail(params) {
2081
2554
  return __async(this, null, function* () {
@@ -2109,6 +2582,8 @@ var initRequest = ({
2109
2582
  * });
2110
2583
  * // Password updated, redirect to login
2111
2584
  * ```
2585
+ *
2586
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Password Reset Documentation}
2112
2587
  */
2113
2588
  resetMemberPassword(params) {
2114
2589
  return __async(this, null, function* () {
@@ -2142,6 +2617,8 @@ var initRequest = ({
2142
2617
  * window.location.href = data.redirect;
2143
2618
  * }
2144
2619
  * ```
2620
+ *
2621
+ * @see {@link https://developers.memberstack.com/dom-package/core-authentication | Authentication Documentation}
2145
2622
  */
2146
2623
  logout(options) {
2147
2624
  return __async(this, null, function* () {
@@ -2163,11 +2640,13 @@ var initRequest = ({
2163
2640
  *
2164
2641
  * @example
2165
2642
  * ```typescript
2166
- * const { data: tables } = await memberstack.getDataTables();
2167
- * tables.forEach(table => {
2643
+ * const { data } = await memberstack.getDataTables();
2644
+ * data.tables.forEach(table => {
2168
2645
  * console.log('Table:', table.name, table.key);
2169
2646
  * });
2170
2647
  * ```
2648
+ *
2649
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2171
2650
  */
2172
2651
  getDataTables(options) {
2173
2652
  return __async(this, null, function* () {
@@ -2190,14 +2669,15 @@ var initRequest = ({
2190
2669
  * const { data: table } = await memberstack.getDataTable({
2191
2670
  * table: 'posts'
2192
2671
  * });
2193
- * console.log('Columns:', table.columns);
2672
+ * console.log('Fields:', table.fields.map(f => f.name));
2194
2673
  * ```
2674
+ *
2675
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2195
2676
  */
2196
2677
  getDataTable(params, options) {
2197
2678
  return __async(this, null, function* () {
2198
2679
  return sendRequest({
2199
2680
  method: "GET" /* GET */,
2200
- //@ts-ignore
2201
2681
  url: `/v1/data-tables/${params.table || params.tableKey}`,
2202
2682
  headers: addHeaders(options)
2203
2683
  });
@@ -2226,6 +2706,8 @@ var initRequest = ({
2226
2706
  * });
2227
2707
  * console.log('Records:', data.records);
2228
2708
  * ```
2709
+ *
2710
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2229
2711
  */
2230
2712
  getDataRecords(params, options) {
2231
2713
  return __async(this, null, function* () {
@@ -2251,7 +2733,6 @@ var initRequest = ({
2251
2733
  method: "POST" /* POST */,
2252
2734
  url: `/v1/data-records/query`,
2253
2735
  data: {
2254
- // @ts-ignore
2255
2736
  table: params.table || params.tableKey,
2256
2737
  query: {
2257
2738
  findMany: query
@@ -2290,6 +2771,8 @@ var initRequest = ({
2290
2771
  * });
2291
2772
  * console.log('Created record:', record.id);
2292
2773
  * ```
2774
+ *
2775
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2293
2776
  */
2294
2777
  createDataRecord(params, options) {
2295
2778
  return __async(this, null, function* () {
@@ -2320,6 +2803,8 @@ var initRequest = ({
2320
2803
  * });
2321
2804
  * console.log('Post:', record.title);
2322
2805
  * ```
2806
+ *
2807
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2323
2808
  */
2324
2809
  getDataRecord(params, options) {
2325
2810
  return __async(this, null, function* () {
@@ -2361,6 +2846,8 @@ var initRequest = ({
2361
2846
  * }
2362
2847
  * });
2363
2848
  * ```
2849
+ *
2850
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2364
2851
  */
2365
2852
  updateDataRecord(params, options) {
2366
2853
  return __async(this, null, function* () {
@@ -2387,6 +2874,8 @@ var initRequest = ({
2387
2874
  * recordId: 'rec_abc123'
2388
2875
  * });
2389
2876
  * ```
2877
+ *
2878
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2390
2879
  */
2391
2880
  deleteDataRecord(params, options) {
2392
2881
  return __async(this, null, function* () {
@@ -2432,6 +2921,8 @@ var initRequest = ({
2432
2921
  * }
2433
2922
  * });
2434
2923
  * ```
2924
+ *
2925
+ * @see {@link https://developers.memberstack.com/dom-package/member-journey | Data Tables Documentation}
2435
2926
  */
2436
2927
  queryDataRecords(params, options) {
2437
2928
  return __async(this, null, function* () {
@@ -2439,7 +2930,7 @@ var initRequest = ({
2439
2930
  method: "POST" /* POST */,
2440
2931
  url: `/v1/data-records/query`,
2441
2932
  data: {
2442
- table: params.table,
2933
+ table: params.table || params.tableKey,
2443
2934
  query: {
2444
2935
  findMany: params.query
2445
2936
  }
@@ -2461,6 +2952,9 @@ function setDebugMode(enabled) {
2461
2952
  "color: #6366f1; font-weight: bold;"
2462
2953
  );
2463
2954
  }
2955
+ if (!enabled && typeof window !== "undefined") {
2956
+ delete window.__MEMBERSTACK_DEBUG__;
2957
+ }
2464
2958
  }
2465
2959
  function debugLog(message, ...args) {
2466
2960
  if (debugEnabled) {
@@ -2479,8 +2973,8 @@ function initDevToolsIntegration(state) {
2479
2973
  publicKey: state.config.publicKey,
2480
2974
  appId: state.config.appId
2481
2975
  },
2482
- getMember: () => state.member,
2483
- isAuthenticated: () => state.member !== null,
2976
+ getMember: state.getMember,
2977
+ isAuthenticated: () => state.getMember() !== null,
2484
2978
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
2485
2979
  };
2486
2980
  debugLog("DevTools integration initialized. Access via window.__MEMBERSTACK_DEBUG__");
@@ -2489,6 +2983,7 @@ function initDevToolsIntegration(state) {
2489
2983
 
2490
2984
  // src/methods/index.ts
2491
2985
  var SDK_VERSION = "1.2.0";
2986
+ var initialized = false;
2492
2987
  var captchaReadyPromise = new Promise((resolve) => {
2493
2988
  if (typeof window !== "undefined") {
2494
2989
  window._hcaptchaReady = resolve;
@@ -2506,6 +3001,16 @@ var methods = {
2506
3001
  _captchaReady: captchaReadyPromise
2507
3002
  };
2508
3003
  function init(props) {
3004
+ if (!props.publicKey) {
3005
+ throw new Error(
3006
+ "Memberstack: publicKey is required. Pass your public key to init({ publicKey: 'pk_...' }). Find your key at https://app.memberstack.com/apps"
3007
+ );
3008
+ }
3009
+ if (!props.publicKey.startsWith("pk_")) {
3010
+ throw new Error(
3011
+ `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`
3012
+ );
3013
+ }
2509
3014
  if (props.debug) {
2510
3015
  setDebugMode(true);
2511
3016
  debugLog(`Initializing Memberstack SDK v${SDK_VERSION}`);
@@ -2516,6 +3021,17 @@ function init(props) {
2516
3021
  domain: props.domain
2517
3022
  });
2518
3023
  }
3024
+ if (initialized && props.debug) {
3025
+ console.warn(
3026
+ "[Memberstack] init() called multiple times. Previous instance will be replaced. This is usually unintentional \u2014 call init() once at app startup."
3027
+ );
3028
+ }
3029
+ if (props.sessionDurationDays !== void 0) {
3030
+ console.warn(
3031
+ "[Memberstack] sessionDurationDays is deprecated and no longer used. Session duration is now controlled server-side. You can safely remove this option."
3032
+ );
3033
+ }
3034
+ initialized = true;
2519
3035
  const apiDomain2 = props.domain || endpoints.API || "https://client.memberstack.com";
2520
3036
  setApiDomain(apiDomain2);
2521
3037
  if (props.useCookies)
@@ -2527,14 +3043,13 @@ function init(props) {
2527
3043
  token: getMemberToken(),
2528
3044
  domain: apiDomain2
2529
3045
  });
2530
- const allMethods = Object.assign(methods, requests);
3046
+ const allMethods = Object.assign(methods, requests, { destroy });
2531
3047
  if (typeof window !== "undefined") {
2532
3048
  window.$memberstackDom = allMethods;
2533
3049
  if (props.debug) {
2534
3050
  initDevToolsIntegration({
2535
3051
  config: { publicKey: props.publicKey, appId: props.appId },
2536
- member: null,
2537
- // Will be updated by auth state
3052
+ getMember: () => getPersistedMember(),
2538
3053
  version: SDK_VERSION
2539
3054
  });
2540
3055
  }
@@ -2544,6 +3059,14 @@ function init(props) {
2544
3059
  }
2545
3060
  return allMethods;
2546
3061
  }
3062
+ function destroy() {
3063
+ unsetPersistedMember();
3064
+ initialized = false;
3065
+ if (typeof window !== "undefined") {
3066
+ delete window.$memberstackDom;
3067
+ delete window.__MEMBERSTACK_DEBUG__;
3068
+ }
3069
+ }
2547
3070
  var methods_default = { init: (props) => init(props) };
2548
3071
 
2549
3072
  // src/utils/errors.ts
@@ -2895,10 +3418,266 @@ var ErrorMetadata = {
2895
3418
  "Clear your browser cache and try again"
2896
3419
  ],
2897
3420
  docsUrl: "https://docs.memberstack.com/dom/authentication"
3421
+ },
3422
+ // Authentication — additional
3423
+ [ErrorCodes.MEMBER_NOT_FOUND]: {
3424
+ message: "No member found with this identifier.",
3425
+ category: "authentication",
3426
+ suggestions: [
3427
+ "Verify the email address is correct",
3428
+ "The member may not have signed up yet \u2014 use signupMemberEmailPassword()",
3429
+ "Check if the member exists in the correct environment (SANDBOX vs LIVE)"
3430
+ ],
3431
+ docsUrl: "https://docs.memberstack.com/dom/authentication/login"
3432
+ },
3433
+ // Account & Social Login — additional
3434
+ [ErrorCodes.ACCOUNT_NOT_FOUND]: {
3435
+ message: "No account found with these credentials.",
3436
+ category: "authentication",
3437
+ suggestions: [
3438
+ "The member may need to sign up first",
3439
+ "Check if the account was created with a different auth method (email vs social)",
3440
+ "Verify the correct environment (SANDBOX vs LIVE)"
3441
+ ]
3442
+ },
3443
+ [ErrorCodes.ACCOUNT_ALREADY_CONNECTED]: {
3444
+ message: "This social account is already connected.",
3445
+ category: "conflict",
3446
+ suggestions: [
3447
+ "Use disconnectProvider() first if you need to reconnect",
3448
+ "Check the member's connected providers with getCurrentMember()"
3449
+ ],
3450
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3451
+ },
3452
+ [ErrorCodes.ACCOUNT_NOT_CONNECTED]: {
3453
+ message: "This social account is not connected to the member.",
3454
+ category: "not_found",
3455
+ suggestions: [
3456
+ "Use connectProvider() to connect the social account first",
3457
+ "Check the member's connected providers with getCurrentMember()"
3458
+ ],
3459
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3460
+ },
3461
+ [ErrorCodes.ACCOUNT_CONNECT_FAILED]: {
3462
+ message: "Failed to connect the social account.",
3463
+ category: "authentication",
3464
+ suggestions: [
3465
+ "Try the connection again \u2014 this may be a temporary issue",
3466
+ "Ensure the social provider is enabled in your Memberstack dashboard",
3467
+ "Check that the OAuth redirect URLs are configured correctly"
3468
+ ],
3469
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3470
+ },
3471
+ [ErrorCodes.ACCOUNT_CONNECT_REQUIRES_LOGIN]: {
3472
+ message: "You must be logged in to connect a social account.",
3473
+ category: "authentication",
3474
+ suggestions: [
3475
+ "Call loginMemberEmailPassword() or loginWithProvider() first",
3476
+ "Use getCurrentMember() to verify the member is authenticated"
3477
+ ],
3478
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3479
+ },
3480
+ [ErrorCodes.ACCOUNT_SET_PASSWORD_FIRST]: {
3481
+ message: "Set a password before disconnecting your last login provider.",
3482
+ category: "authentication",
3483
+ suggestions: [
3484
+ "Use setPassword() to add a password before disconnecting",
3485
+ "This prevents the member from being locked out of their account"
3486
+ ],
3487
+ docsUrl: "https://docs.memberstack.com/dom/authentication/social-login"
3488
+ },
3489
+ // Validation — additional
3490
+ [ErrorCodes.INVALID_PASSWORD]: {
3491
+ message: "The password is incorrect.",
3492
+ category: "authentication",
3493
+ suggestions: [
3494
+ "Check that the current password is entered correctly",
3495
+ "Use sendMemberResetPasswordEmail() to reset the password"
3496
+ ]
3497
+ },
3498
+ [ErrorCodes.REQUIRED_FIELD_MISSING]: {
3499
+ message: "A required field is missing.",
3500
+ category: "validation",
3501
+ suggestions: [
3502
+ "Check that all required parameters are provided",
3503
+ "Review the method documentation for required fields",
3504
+ "Custom fields marked as required in the dashboard must be included on signup"
3505
+ ]
3506
+ },
3507
+ [ErrorCodes.INVALID_CAPTCHA]: {
3508
+ message: "CAPTCHA verification failed.",
3509
+ category: "validation",
3510
+ suggestions: [
3511
+ "Ensure the CAPTCHA token is passed as captchaToken in the request",
3512
+ "The token may have expired \u2014 request a new CAPTCHA challenge",
3513
+ "Check that CAPTCHA is correctly configured in your Memberstack dashboard"
3514
+ ]
3515
+ },
3516
+ // Plans — additional
3517
+ [ErrorCodes.NO_PLAN_FOUND]: {
3518
+ message: "The member does not have this plan.",
3519
+ category: "not_found",
3520
+ suggestions: [
3521
+ "Use getCurrentMember() to check the member's current plans",
3522
+ "Verify the plan ID is correct",
3523
+ "The plan may have been removed or expired"
3524
+ ],
3525
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3526
+ },
3527
+ [ErrorCodes.PLAN_MEMBER_LIMIT_REACHED]: {
3528
+ message: "This plan has reached its member limit.",
3529
+ category: "limit",
3530
+ suggestions: [
3531
+ "Contact the app owner to increase the plan's member limit",
3532
+ "Check if a different plan is available"
3533
+ ],
3534
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3535
+ },
3536
+ [ErrorCodes.PLAN_RESTRICTED_TO_ADMIN]: {
3537
+ message: "This plan can only be assigned by an admin.",
3538
+ category: "authorization",
3539
+ suggestions: [
3540
+ "Plans with this restriction cannot be self-assigned by members",
3541
+ "Use the Admin API or dashboard to assign this plan"
3542
+ ],
3543
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3544
+ },
3545
+ [ErrorCodes.DOMAIN_NOT_PERMITTED]: {
3546
+ message: "Your email domain is not permitted for this plan.",
3547
+ category: "authorization",
3548
+ suggestions: [
3549
+ "This plan restricts signup to specific email domains",
3550
+ "Check the plan's domain restrictions in your Memberstack dashboard",
3551
+ "Use an email address with an allowed domain"
3552
+ ],
3553
+ docsUrl: "https://docs.memberstack.com/dom/plans"
3554
+ },
3555
+ [ErrorCodes.PRICE_NOT_AVAILABLE]: {
3556
+ message: "This pricing option is no longer available.",
3557
+ category: "not_found",
3558
+ suggestions: [
3559
+ "Use getPlans() to see currently available pricing options",
3560
+ "The price may have been archived or deactivated",
3561
+ "Check your Stripe dashboard for the price status"
3562
+ ],
3563
+ docsUrl: "https://docs.memberstack.com/dom/payments"
3564
+ },
3565
+ // Teams — additional
3566
+ [ErrorCodes.ONE_ACTIVE_TEAM_ONLY]: {
3567
+ message: "A member can only belong to one active team.",
3568
+ category: "conflict",
3569
+ suggestions: [
3570
+ "Remove the member from their current team first using removeMemberFromTeam()",
3571
+ "Check the member's current team with getTeam()"
3572
+ ],
3573
+ docsUrl: "https://docs.memberstack.com/dom/teams"
3574
+ },
3575
+ [ErrorCodes.CANNOT_CHANGE_TEAM]: {
3576
+ message: "Cannot change team while it has active members.",
3577
+ category: "conflict",
3578
+ suggestions: [
3579
+ "Remove all team members before making this change",
3580
+ "Use removeMemberFromTeam() to remove members first"
3581
+ ],
3582
+ docsUrl: "https://docs.memberstack.com/dom/teams"
3583
+ },
3584
+ // Data Tables — additional
3585
+ [ErrorCodes.INVALID_TABLE_KEY]: {
3586
+ message: "The table key format is invalid.",
3587
+ category: "data_tables",
3588
+ suggestions: [
3589
+ "Table keys should be lowercase alphanumeric with hyphens",
3590
+ "Use getDataTables() to list available tables and their keys",
3591
+ "Check the table key in your Memberstack dashboard"
3592
+ ],
3593
+ docsUrl: "https://docs.memberstack.com/data-tables"
3594
+ },
3595
+ [ErrorCodes.UNIQUE_CONSTRAINT_VIOLATION]: {
3596
+ message: "A record with this value already exists (unique constraint).",
3597
+ category: "data_tables",
3598
+ suggestions: [
3599
+ "The field has a unique constraint \u2014 use a different value",
3600
+ "Use queryDataRecords() to check for existing records before creating",
3601
+ "If updating, use updateDataRecord() instead of createDataRecord()"
3602
+ ],
3603
+ docsUrl: "https://docs.memberstack.com/data-tables"
3604
+ },
3605
+ [ErrorCodes.FIELD_LIMIT_EXCEEDED]: {
3606
+ message: "Maximum number of fields reached for this table.",
3607
+ category: "data_tables",
3608
+ suggestions: [
3609
+ "Remove unused fields before adding new ones",
3610
+ "Consider using a separate table for additional data",
3611
+ "Check your plan's field limits in the dashboard"
3612
+ ],
3613
+ docsUrl: "https://docs.memberstack.com/data-tables"
3614
+ },
3615
+ [ErrorCodes.INVALID_FIELD_TYPE]: {
3616
+ message: "This field type is not supported.",
3617
+ category: "data_tables",
3618
+ suggestions: [
3619
+ "Check the supported field types in the documentation",
3620
+ "Use getDataTable() to see the table schema and field types"
3621
+ ],
3622
+ docsUrl: "https://docs.memberstack.com/data-tables"
3623
+ },
3624
+ [ErrorCodes.INVALID_FIELD_VALUE]: {
3625
+ message: "The field value does not match the expected type.",
3626
+ category: "data_tables",
3627
+ suggestions: [
3628
+ "Check the field type \u2014 e.g., number fields require numeric values",
3629
+ "Use getDataTable() to see the expected field types",
3630
+ "Ensure dates are in ISO 8601 format for date fields"
3631
+ ],
3632
+ docsUrl: "https://docs.memberstack.com/data-tables"
3633
+ },
3634
+ // Permissions
3635
+ [ErrorCodes.ACCESS_DENIED]: {
3636
+ message: "You do not have permission to access this resource.",
3637
+ category: "authorization",
3638
+ suggestions: [
3639
+ "Check that the member has the required plan or permissions",
3640
+ "Verify the content group configuration in the dashboard",
3641
+ "Use getCurrentMember() to check the member's permissions array"
3642
+ ],
3643
+ docsUrl: "https://docs.memberstack.com/dom/content-protection"
3644
+ },
3645
+ // Catch-all
3646
+ [ErrorCodes.UNKNOWN_ERROR]: {
3647
+ message: "An unexpected error occurred.",
3648
+ category: "unknown",
3649
+ suggestions: [
3650
+ "Try the request again",
3651
+ "Check the Memberstack status page for any ongoing issues",
3652
+ "If the problem persists, contact support with the error details"
3653
+ ]
2898
3654
  }
2899
3655
  };
3656
+ function normalizeErrorCode(code) {
3657
+ return code.toLowerCase().replace(/_/g, "-");
3658
+ }
3659
+ function getMetadataForCode(code) {
3660
+ if (ErrorMetadata[code]) {
3661
+ return ErrorMetadata[code];
3662
+ }
3663
+ const normalized = normalizeErrorCode(code);
3664
+ for (const key of Object.keys(ErrorMetadata)) {
3665
+ if (normalizeErrorCode(key) === normalized) {
3666
+ return ErrorMetadata[key];
3667
+ }
3668
+ }
3669
+ return void 0;
3670
+ }
3671
+ var knownErrorCodes = new Set(Object.values(ErrorCodes));
2900
3672
  function isMemberstackError(error) {
2901
- return typeof error === "object" && error !== null && "code" in error && "message" in error && typeof error.code === "string" && typeof error.message === "string";
3673
+ if (typeof error !== "object" || error === null || !("code" in error) || !("message" in error) || typeof error.code !== "string" || typeof error.message !== "string") {
3674
+ return false;
3675
+ }
3676
+ const code = error.code;
3677
+ if (knownErrorCodes.has(code) || knownErrorCodes.has(normalizeErrorCode(code))) {
3678
+ return true;
3679
+ }
3680
+ return code.includes("-") || code.includes("/");
2902
3681
  }
2903
3682
  function getErrorMessage(error, defaultMessage = "An unexpected error occurred") {
2904
3683
  if (isMemberstackError(error)) {
@@ -2934,7 +3713,7 @@ function getErrorSuggestions(error) {
2934
3713
  if (error.suggestions && error.suggestions.length > 0) {
2935
3714
  return error.suggestions;
2936
3715
  }
2937
- const metadata = ErrorMetadata[error.code];
3716
+ const metadata = getMetadataForCode(error.code);
2938
3717
  return (metadata == null ? void 0 : metadata.suggestions) || [];
2939
3718
  }
2940
3719
  function getErrorDocsUrl(error) {
@@ -2944,7 +3723,7 @@ function getErrorDocsUrl(error) {
2944
3723
  if (error.docsUrl) {
2945
3724
  return error.docsUrl;
2946
3725
  }
2947
- const metadata = ErrorMetadata[error.code];
3726
+ const metadata = getMetadataForCode(error.code);
2948
3727
  return metadata == null ? void 0 : metadata.docsUrl;
2949
3728
  }
2950
3729
  function getErrorCategory(error) {
@@ -2954,18 +3733,18 @@ function getErrorCategory(error) {
2954
3733
  if (error.category) {
2955
3734
  return error.category;
2956
3735
  }
2957
- const metadata = ErrorMetadata[error.code];
3736
+ const metadata = getMetadataForCode(error.code);
2958
3737
  return (metadata == null ? void 0 : metadata.category) || "unknown";
2959
3738
  }
2960
3739
  function formatErrorForUser(error) {
2961
3740
  if (!isMemberstackError(error)) {
2962
3741
  return "An unexpected error occurred. Please try again.";
2963
3742
  }
2964
- const metadata = ErrorMetadata[error.code];
3743
+ const metadata = getMetadataForCode(error.code);
2965
3744
  if (metadata) {
2966
3745
  return metadata.message;
2967
3746
  }
2968
- return error.message;
3747
+ return "Something went wrong. Please try again or contact support.";
2969
3748
  }
2970
3749
  function getErrorReport(error) {
2971
3750
  if (!isMemberstackError(error)) {