@liveblocks/node 1.8.1 → 1.8.3-oss1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utils.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
+ var _core = require('@liveblocks/core');
3
+
4
+ // src/version.ts
5
+ var PKG_NAME = "@liveblocks/node";
6
+ var PKG_VERSION = "1.8.3-oss1";
7
+ var PKG_FORMAT = "cjs";
8
+
9
+ // src/utils.ts
2
10
  var DEFAULT_BASE_URL = "https://api.liveblocks.io";
3
11
  async function fetchPolyfill() {
4
12
  return typeof globalThis.fetch !== "undefined" ? globalThis.fetch : (await Promise.resolve().then(() => _interopRequireWildcard(require("node-fetch")))).default;
5
13
  }
6
- function isSomething(input) {
7
- return input !== null && input !== void 0;
8
- }
9
14
  function isNonEmpty(value) {
10
15
  return typeof value === "string" && value.length > 0;
11
16
  }
@@ -96,6 +101,13 @@ function buildLiveblocksAuthorizeEndpoint(options, roomId) {
96
101
  return urljoin(options.baseUrl || DEFAULT_BASE_URL, path);
97
102
  }
98
103
 
104
+ // src/client.ts
105
+
106
+
107
+
108
+
109
+
110
+
99
111
  // src/Session.ts
100
112
  var ALL_PERMISSIONS = Object.freeze([
101
113
  "room:write",
@@ -276,6 +288,7 @@ var Liveblocks = class {
276
288
  /** @internal */
277
289
  async get(path, params) {
278
290
  const url2 = urljoin(this._baseUrl, path, params);
291
+ console.log("url", url2);
279
292
  const headers = {
280
293
  Authorization: `Bearer ${this._secret}`
281
294
  };
@@ -303,7 +316,7 @@ var Liveblocks = class {
303
316
  *
304
317
  */
305
318
  prepareSession(userId, options) {
306
- return new Session(this.post.bind(this), userId, _optionalChain([options, 'optionalAccess', _2 => _2.userInfo]));
319
+ return new Session(this.post.bind(this), userId, _optionalChain([options, 'optionalAccess', _ => _.userInfo]));
307
320
  }
308
321
  /**
309
322
  * Call this to authenticate the user as an actor you want to allow to use
@@ -348,7 +361,7 @@ var Liveblocks = class {
348
361
  userId,
349
362
  groupIds,
350
363
  // Optional metadata
351
- userInfo: _optionalChain([options, 'optionalAccess', _3 => _3.userInfo])
364
+ userInfo: _optionalChain([options, 'optionalAccess', _2 => _2.userInfo])
352
365
  });
353
366
  return {
354
367
  status: normalizeStatusCode(resp.status),
@@ -758,12 +771,17 @@ var Liveblocks = class {
758
771
  */
759
772
  async getThreads(params) {
760
773
  const { roomId } = params;
761
- const res = await this.get(url`/v2/rooms/${roomId}/threads`);
774
+ const res = await this.get(url`/v2/rooms/${roomId}/threads`, {
775
+ "metadata.resolved": "false"
776
+ });
762
777
  if (!res.ok) {
763
778
  const text = await res.text();
764
779
  throw new LiveblocksError(res.status, text);
765
780
  }
766
- return await res.json();
781
+ const { data } = await res.json();
782
+ return {
783
+ data: data.map((thread) => _core.convertToThreadData.call(void 0, thread))
784
+ };
767
785
  }
768
786
  /**
769
787
  * Gets a thread.
@@ -779,7 +797,9 @@ var Liveblocks = class {
779
797
  const text = await res.text();
780
798
  throw new LiveblocksError(res.status, text);
781
799
  }
782
- return await res.json();
800
+ return _core.convertToThreadData.call(void 0,
801
+ await res.json()
802
+ );
783
803
  }
784
804
  /**
785
805
  * Gets a thread's participants.
@@ -819,319 +839,181 @@ var Liveblocks = class {
819
839
  const text = await res.text();
820
840
  throw new LiveblocksError(res.status, text);
821
841
  }
822
- return await res.json();
842
+ return _core.convertToCommentData.call(void 0, await res.json());
823
843
  }
824
- };
825
- var LiveblocksError = class extends Error {
826
- constructor(status, message = "") {
827
- super(message);
828
- this.name = "LiveblocksError";
829
- this.status = status;
830
- }
831
- };
832
-
833
- // src/comment-body.ts
834
- function isCommentBodyParagraph(element) {
835
- return "type" in element && element.type === "mention";
836
- }
837
- function isCommentBodyText(element) {
838
- return "text" in element && typeof element.text === "string";
839
- }
840
- function isCommentBodyMention(element) {
841
- return "type" in element && element.type === "mention";
842
- }
843
- function isCommentBodyLink(element) {
844
- return "type" in element && element.type === "link";
845
- }
846
- var commentBodyElementsGuards = {
847
- paragraph: isCommentBodyParagraph,
848
- text: isCommentBodyText,
849
- link: isCommentBodyLink,
850
- mention: isCommentBodyMention
851
- };
852
- var commentBodyElementsTypes = {
853
- paragraph: "block",
854
- text: "inline",
855
- link: "inline",
856
- mention: "inline"
857
- };
858
- function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
859
- if (!body || !_optionalChain([body, 'optionalAccess', _4 => _4.content])) {
860
- return;
861
- }
862
- const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
863
- const type = element ? commentBodyElementsTypes[element] : "all";
864
- const guard = element ? commentBodyElementsGuards[element] : () => true;
865
- const visitor = typeof elementOrVisitor === "function" ? elementOrVisitor : possiblyVisitor;
866
- for (const block of body.content) {
867
- if (type === "all" || type === "block") {
868
- if (guard(block)) {
869
- _optionalChain([visitor, 'optionalCall', _5 => _5(block)]);
844
+ /**
845
+ * Creates a comment.
846
+ *
847
+ * @param params.roomId The room ID to create the comment in.
848
+ * @param params.threadId The thread ID to create the comment in.
849
+ * @param params.data.userId The user ID of the user who is set to create the comment.
850
+ * @param params.data.createdAt (optional) The date the comment is set to be created.
851
+ * @param params.data.body The body of the comment.
852
+ * @returns The created comment.
853
+ */
854
+ async createComment(params) {
855
+ const { roomId, threadId, data } = params;
856
+ const res = await this.post(
857
+ url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
858
+ {
859
+ ...data,
860
+ createdAt: _optionalChain([data, 'access', _3 => _3.createdAt, 'optionalAccess', _4 => _4.toISOString, 'call', _5 => _5()])
870
861
  }
862
+ );
863
+ if (!res.ok) {
864
+ const text = await res.text();
865
+ throw new LiveblocksError(res.status, text);
871
866
  }
872
- if (type === "all" || type === "inline") {
873
- for (const inline of block.children) {
874
- if (guard(inline)) {
875
- _optionalChain([visitor, 'optionalCall', _6 => _6(inline)]);
876
- }
867
+ return _core.convertToCommentData.call(void 0, await res.json());
868
+ }
869
+ /**
870
+ * Edits a comment.
871
+ * @param params.roomId The room ID to edit the comment in.
872
+ * @param params.threadId The thread ID to edit the comment in.
873
+ * @param params.commentId The comment ID to edit.
874
+ * @param params.data.body The body of the comment.
875
+ * @param params.data.editedAt (optional) The date the comment was edited.
876
+ * @returns The edited comment.
877
+ */
878
+ async editComment(params) {
879
+ const { roomId, threadId, commentId, data } = params;
880
+ const res = await this.post(
881
+ url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
882
+ {
883
+ ...data,
884
+ editedAt: _optionalChain([data, 'access', _6 => _6.editedAt, 'optionalAccess', _7 => _7.toISOString, 'call', _8 => _8()])
877
885
  }
886
+ );
887
+ if (!res.ok) {
888
+ const text = await res.text();
889
+ throw new LiveblocksError(res.status, text);
878
890
  }
891
+ return _core.convertToCommentData.call(void 0, await res.json());
879
892
  }
880
- }
881
- function getMentionedIdsFromCommentBody(body) {
882
- const mentionedIds = /* @__PURE__ */ new Set();
883
- traverseCommentBody(
884
- body,
885
- "mention",
886
- (mention) => mentionedIds.add(mention.id)
887
- );
888
- return Array.from(mentionedIds);
889
- }
890
- async function resolveUsersInCommentBody(body, resolveUsers) {
891
- const resolvedUsers = /* @__PURE__ */ new Map();
892
- if (!resolveUsers) {
893
- return resolvedUsers;
894
- }
895
- const userIds = getMentionedIdsFromCommentBody(body);
896
- const users = await resolveUsers({
897
- userIds
898
- });
899
- for (const [index, userId] of userIds.entries()) {
900
- const user = _optionalChain([users, 'optionalAccess', _7 => _7[index]]);
901
- if (user) {
902
- resolvedUsers.set(userId, user);
893
+ /**
894
+ * Deletes a comment. Deletes a comment. If there are no remaining comments in the thread, the thread is also deleted.
895
+ * @param params.roomId The room ID to delete the comment in.
896
+ * @param params.threadId The thread ID to delete the comment in.
897
+ * @param params.commentId The comment ID to delete.
898
+ */
899
+ async deleteComment(params) {
900
+ const { roomId, threadId, commentId } = params;
901
+ const res = await this.delete(
902
+ url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`
903
+ );
904
+ if (!res.ok) {
905
+ const text = await res.text();
906
+ throw new LiveblocksError(res.status, text);
903
907
  }
904
908
  }
905
- return resolvedUsers;
906
- }
907
- var htmlEscapables = {
908
- "&": "&amp;",
909
- "<": "&lt;",
910
- ">": "&gt;",
911
- '"': "&quot;",
912
- "'": "&#39;"
913
- };
914
- var htmlEscapablesRegex = new RegExp(
915
- Object.keys(htmlEscapables).map((entity) => `\\${entity}`).join("|"),
916
- "g"
917
- );
918
- function htmlSafe(value) {
919
- return new HtmlSafeString([String(value)], []);
920
- }
921
- function joinHtml(strings) {
922
- if (strings.length <= 0) {
923
- return new HtmlSafeString([""], []);
924
- }
925
- return new HtmlSafeString(
926
- ["", ...Array(strings.length - 1).fill(""), ""],
927
- strings
928
- );
929
- }
930
- function escapeHtml(value) {
931
- if (value instanceof HtmlSafeString) {
932
- return value.toString();
933
- }
934
- if (Array.isArray(value)) {
935
- return joinHtml(value).toString();
936
- }
937
- return String(value).replace(
938
- htmlEscapablesRegex,
939
- (character) => htmlEscapables[character]
940
- );
941
- }
942
- var HtmlSafeString = class {
943
- constructor(strings, values) {
944
- this._strings = strings;
945
- this._values = values;
946
- }
947
- toString() {
948
- return this._strings.reduce((result, str, i) => {
949
- return result + escapeHtml(this._values[i - 1]) + str;
950
- });
951
- }
952
- };
953
- function html(strings, ...values) {
954
- return new HtmlSafeString(strings, values);
955
- }
956
- var markdownEscapables = {
957
- _: "\\_",
958
- "*": "\\*",
959
- "#": "\\#",
960
- "`": "\\`",
961
- "~": "\\~",
962
- "!": "\\!",
963
- "|": "\\|",
964
- "(": "\\(",
965
- ")": "\\)",
966
- "{": "\\{",
967
- "}": "\\}",
968
- "[": "\\[",
969
- "]": "\\]"
970
- };
971
- var markdownEscapablesRegex = new RegExp(
972
- Object.keys(markdownEscapables).map((entity) => `\\${entity}`).join("|"),
973
- "g"
974
- );
975
- function joinMarkdown(strings) {
976
- if (strings.length <= 0) {
977
- return new MarkdownSafeString([""], []);
978
- }
979
- return new MarkdownSafeString(
980
- ["", ...Array(strings.length - 1).fill(""), ""],
981
- strings
982
- );
983
- }
984
- function escapeMarkdown(value) {
985
- if (value instanceof MarkdownSafeString) {
986
- return value.toString();
987
- }
988
- if (Array.isArray(value)) {
989
- return joinMarkdown(value).toString();
990
- }
991
- return String(value).replace(
992
- markdownEscapablesRegex,
993
- (character) => markdownEscapables[character]
994
- );
995
- }
996
- var MarkdownSafeString = class {
997
- constructor(strings, values) {
998
- this._strings = strings;
999
- this._values = values;
1000
- }
1001
- toString() {
1002
- return this._strings.reduce((result, str, i) => {
1003
- return result + escapeMarkdown(this._values[i - 1]) + str;
909
+ /**
910
+ * Creates a new thread. The thread will be created with the specified comment as its first comment.
911
+ * If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
912
+ * @param params.roomId The room ID to create the thread in.
913
+ * @param params.thread.metadata (optional) The metadata for the thread. Supports upto a maximum of 10 entries. Value must be a string, boolean or number
914
+ * @param params.thread.comment.userId The user ID of the user who created the comment.
915
+ * @param params.thread.comment.createdAt (optional) The date the comment was created.
916
+ * @param params.thread.comment.body The body of the comment.
917
+ * @returns The created thread. The thread will be created with the specified comment as its first comment.
918
+ */
919
+ async createThread(params) {
920
+ const { roomId, data } = params;
921
+ const res = await this.post(url`/v2/rooms/${roomId}/threads`, {
922
+ ...data,
923
+ comment: {
924
+ ...data.comment,
925
+ createdAt: _optionalChain([data, 'access', _9 => _9.comment, 'access', _10 => _10.createdAt, 'optionalAccess', _11 => _11.toISOString, 'call', _12 => _12()])
926
+ }
1004
927
  });
1005
- }
1006
- };
1007
- function markdown(strings, ...values) {
1008
- return new MarkdownSafeString(strings, values);
1009
- }
1010
- function toAbsoluteUrl(url2) {
1011
- if (url2.startsWith("http://") || url2.startsWith("https://")) {
1012
- return url2;
1013
- } else if (url2.startsWith("www.")) {
1014
- return "https://" + url2;
1015
- }
1016
- return;
1017
- }
1018
- var stringifyCommentBodyPlainElements = {
1019
- paragraph: ({ children }) => children,
1020
- text: ({ element }) => element.text,
1021
- link: ({ element }) => element.url,
1022
- mention: ({ element, user }) => {
1023
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _8 => _8.name]), () => ( element.id))}`;
1024
- }
1025
- };
1026
- var stringifyCommentBodyHtmlElements = {
1027
- paragraph: ({ children }) => {
1028
- return children ? html`<p>${htmlSafe(children)}</p>` : children;
1029
- },
1030
- text: ({ element }) => {
1031
- let children = element.text;
1032
- if (!children) {
1033
- return children;
1034
- }
1035
- if (element.bold) {
1036
- children = html`<strong>${children}</strong>`;
928
+ if (!res.ok) {
929
+ const text = await res.text();
930
+ throw new LiveblocksError(res.status, text);
1037
931
  }
1038
- if (element.italic) {
1039
- children = html`<em>${children}</em>`;
932
+ return _core.convertToThreadData.call(void 0,
933
+ await res.json()
934
+ );
935
+ }
936
+ /**
937
+ * Updates the metadata of the specified thread in a room.
938
+ * @param params.roomId The room ID to update the thread in.
939
+ * @param params.threadId The thread ID to update.
940
+ * @param params.data.metadata The metadata for the thread. Value must be a string, boolean or number
941
+ * @param params.data.userId The user ID of the user who updated the thread.
942
+ * @param params.data.updatedAt (optional) The date the thread is set to be updated.
943
+ * @returns The updated thread.
944
+ */
945
+ async editThreadMetadata(params) {
946
+ const { roomId, threadId, data } = params;
947
+ const res = await this.post(
948
+ url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
949
+ {
950
+ ...data,
951
+ updatedAt: _optionalChain([data, 'access', _13 => _13.updatedAt, 'optionalAccess', _14 => _14.toISOString, 'call', _15 => _15()])
952
+ }
953
+ );
954
+ if (!res.ok) {
955
+ const text = await res.text();
956
+ throw new LiveblocksError(res.status, text);
1040
957
  }
1041
- if (element.strikethrough) {
1042
- children = html`<s>${children}</s>`;
958
+ return await res.json();
959
+ }
960
+ /**
961
+ * Adds a new comment reaction to a comment.
962
+ * @param params.roomId The room ID to add the comment reaction in.
963
+ * @param params.threadId The thread ID to add the comment reaction in.
964
+ * @param params.commentId The comment ID to add the reaction in.
965
+ * @param params.data.emoji The (emoji) reaction to add.
966
+ * @param params.data.userId The user ID of the user associated with the reaction.
967
+ * @param params.data.createdAt (optional) The date the reaction is set to be created.
968
+ * @returns The created comment reaction.
969
+ */
970
+ async addCommentReaction(params) {
971
+ const { roomId, threadId, commentId, data } = params;
972
+ const res = await this.post(
973
+ url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
974
+ {
975
+ ...data,
976
+ createdAt: _optionalChain([data, 'access', _16 => _16.createdAt, 'optionalAccess', _17 => _17.toISOString, 'call', _18 => _18()])
977
+ }
978
+ );
979
+ if (!res.ok) {
980
+ const text = await res.text();
981
+ throw new LiveblocksError(res.status, text);
1043
982
  }
1044
- if (element.code) {
1045
- children = html`<code>${children}</code>`;
983
+ const reaction = await res.json();
984
+ return _core.convertToCommentUserReaction.call(void 0, reaction);
985
+ }
986
+ /**
987
+ * Removes a reaction from a comment.
988
+ * @param params.roomId The room ID to remove the comment reaction from.
989
+ * @param params.threadId The thread ID to remove the comment reaction from.
990
+ * @param params.commentId The comment ID to remove the reaction from.
991
+ * @param params.data.emoji The (emoji) reaction to remove.
992
+ * @param params.data.userId The user ID of the user associated with the reaction.
993
+ * @param params.data.removedAt (optional) The date the reaction is set to be removed.
994
+ */
995
+ async removeCommentReaction(params) {
996
+ const { roomId, threadId, data } = params;
997
+ const res = await this.post(
998
+ url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
999
+ {
1000
+ ...data,
1001
+ removedAt: _optionalChain([data, 'access', _19 => _19.removedAt, 'optionalAccess', _20 => _20.toISOString, 'call', _21 => _21()])
1002
+ }
1003
+ );
1004
+ if (!res.ok) {
1005
+ const text = await res.text();
1006
+ throw new LiveblocksError(res.status, text);
1046
1007
  }
1047
- return children;
1048
- },
1049
- link: ({ element, href }) => {
1050
- return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.url}</a>`;
1051
- },
1052
- mention: ({ element, user }) => {
1053
- return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _9 => _9.name]), () => ( element.id))}</span>`;
1054
1008
  }
1055
1009
  };
1056
- var stringifyCommentBodyMarkdownElements = {
1057
- paragraph: ({ children }) => {
1058
- return children;
1059
- },
1060
- text: ({ element }) => {
1061
- let children = element.text;
1062
- if (!children) {
1063
- return children;
1064
- }
1065
- if (element.bold) {
1066
- children = markdown`**${children}**`;
1067
- }
1068
- if (element.italic) {
1069
- children = markdown`_${children}_`;
1070
- }
1071
- if (element.strikethrough) {
1072
- children = markdown`~~${children}~~`;
1073
- }
1074
- if (element.code) {
1075
- children = markdown`\`${children}\``;
1076
- }
1077
- return children;
1078
- },
1079
- link: ({ element, href }) => {
1080
- return markdown`[${element.url}](${href})`;
1081
- },
1082
- mention: ({ element, user }) => {
1083
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _10 => _10.name]), () => ( element.id))}`;
1010
+ var LiveblocksError = class extends Error {
1011
+ constructor(status, message = "") {
1012
+ super(message);
1013
+ this.name = "LiveblocksError";
1014
+ this.status = status;
1084
1015
  }
1085
1016
  };
1086
- async function stringifyCommentBody(body, options) {
1087
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.format]), () => ( "plain"));
1088
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _12 => _12.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
1089
- const elements = {
1090
- ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
1091
- ..._optionalChain([options, 'optionalAccess', _13 => _13.elements])
1092
- };
1093
- const resolvedUsers = await resolveUsersInCommentBody(
1094
- body,
1095
- _optionalChain([options, 'optionalAccess', _14 => _14.resolveUsers])
1096
- );
1097
- const blocks = body.content.map((block, blockIndex) => {
1098
- switch (block.type) {
1099
- case "paragraph": {
1100
- const paragraph = block.children.map((inline, inlineIndex) => {
1101
- if (isCommentBodyMention(inline)) {
1102
- return inline.id ? elements.mention(
1103
- {
1104
- element: inline,
1105
- user: resolvedUsers.get(inline.id)
1106
- },
1107
- inlineIndex
1108
- ) : null;
1109
- }
1110
- if (isCommentBodyLink(inline)) {
1111
- return elements.link(
1112
- {
1113
- element: inline,
1114
- href: _nullishCoalesce(toAbsoluteUrl(inline.url), () => ( inline.url))
1115
- },
1116
- inlineIndex
1117
- );
1118
- }
1119
- if (isCommentBodyText(inline)) {
1120
- return elements.text({ element: inline }, inlineIndex);
1121
- }
1122
- return null;
1123
- }).filter(isSomething).join("");
1124
- return elements.paragraph(
1125
- { element: block, children: paragraph },
1126
- blockIndex
1127
- );
1128
- }
1129
- default:
1130
- return null;
1131
- }
1132
- });
1133
- return blocks.filter(isSomething).join(separator);
1134
- }
1135
1017
 
1136
1018
  // src/webhooks.ts
1137
1019
  var _base64 = require('@stablelib/base64'); var base64 = _interopRequireWildcard(_base64);
@@ -1151,11 +1033,15 @@ var _WebhookHandler = class _WebhookHandler {
1151
1033
  * Verifies a webhook request and returns the event
1152
1034
  */
1153
1035
  verifyRequest(request) {
1154
- const { webhookId, timestamp, rawSignatures } = this.verifyHeaders(
1155
- request.headers
1156
- );
1036
+ const { headers, rawBody } = request;
1037
+ const { webhookId, timestamp, rawSignatures } = this.verifyHeaders(headers);
1038
+ if (typeof rawBody !== "string") {
1039
+ throw new Error(
1040
+ `Invalid rawBody field, must be a string, got "${typeof rawBody}" instead. It is likely that you need to JSON.stringify the body before passing it.`
1041
+ );
1042
+ }
1157
1043
  this.verifyTimestamp(timestamp);
1158
- const signature = this.sign(`${webhookId}.${timestamp}.${request.rawBody}`);
1044
+ const signature = this.sign(`${webhookId}.${timestamp}.${rawBody}`);
1159
1045
  const expectedSignatures = rawSignatures.split(" ").map((rawSignature) => {
1160
1046
  const [, parsedSignature] = rawSignature.split(",");
1161
1047
  return parsedSignature;
@@ -1166,7 +1052,7 @@ var _WebhookHandler = class _WebhookHandler {
1166
1052
  ", "
1167
1053
  )}, got ${signature}`
1168
1054
  );
1169
- const event = JSON.parse(request.rawBody);
1055
+ const event = JSON.parse(rawBody);
1170
1056
  this.verifyWebhookEventType(event);
1171
1057
  return event;
1172
1058
  }
@@ -1248,10 +1134,17 @@ var WebhookHandler = _WebhookHandler;
1248
1134
  var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
1249
1135
  var isNotUndefined = (value) => value !== void 0;
1250
1136
 
1137
+ // src/index.ts
1138
+
1139
+
1140
+
1141
+
1142
+ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1143
+
1251
1144
 
1252
1145
 
1253
1146
 
1254
1147
 
1255
1148
 
1256
- exports.Liveblocks = Liveblocks; exports.WebhookHandler = WebhookHandler; exports.authorize = authorize; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.stringifyCommentBody = stringifyCommentBody;
1149
+ exports.Liveblocks = Liveblocks; exports.WebhookHandler = WebhookHandler; exports.authorize = authorize; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody;
1257
1150
  //# sourceMappingURL=index.js.map