@liveblocks/node 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.2";
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
  }
@@ -303,7 +308,7 @@ var Liveblocks = class {
303
308
  *
304
309
  */
305
310
  prepareSession(userId, options) {
306
- return new Session(this.post.bind(this), userId, _optionalChain([options, 'optionalAccess', _2 => _2.userInfo]));
311
+ return new Session(this.post.bind(this), userId, _optionalChain([options, 'optionalAccess', _ => _.userInfo]));
307
312
  }
308
313
  /**
309
314
  * Call this to authenticate the user as an actor you want to allow to use
@@ -348,7 +353,7 @@ var Liveblocks = class {
348
353
  userId,
349
354
  groupIds,
350
355
  // Optional metadata
351
- userInfo: _optionalChain([options, 'optionalAccess', _3 => _3.userInfo])
356
+ userInfo: _optionalChain([options, 'optionalAccess', _2 => _2.userInfo])
352
357
  });
353
358
  return {
354
359
  status: normalizeStatusCode(resp.status),
@@ -830,309 +835,6 @@ var LiveblocksError = class extends Error {
830
835
  }
831
836
  };
832
837
 
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)]);
870
- }
871
- }
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
- }
877
- }
878
- }
879
- }
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);
903
- }
904
- }
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;
1004
- });
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>`;
1037
- }
1038
- if (element.italic) {
1039
- children = html`<em>${children}</em>`;
1040
- }
1041
- if (element.strikethrough) {
1042
- children = html`<s>${children}</s>`;
1043
- }
1044
- if (element.code) {
1045
- children = html`<code>${children}</code>`;
1046
- }
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
- }
1055
- };
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))}`;
1084
- }
1085
- };
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
-
1136
838
  // src/webhooks.ts
1137
839
  var _base64 = require('@stablelib/base64'); var base64 = _interopRequireWildcard(_base64);
1138
840
  var _fastsha256 = require('fast-sha256'); var sha256 = _interopRequireWildcard(_fastsha256);
@@ -1248,10 +950,17 @@ var WebhookHandler = _WebhookHandler;
1248
950
  var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
1249
951
  var isNotUndefined = (value) => value !== void 0;
1250
952
 
953
+ // src/index.ts
954
+
955
+
956
+
957
+
958
+ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
959
+
1251
960
 
1252
961
 
1253
962
 
1254
963
 
1255
964
 
1256
- exports.Liveblocks = Liveblocks; exports.WebhookHandler = WebhookHandler; exports.authorize = authorize; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.stringifyCommentBody = stringifyCommentBody;
965
+ exports.Liveblocks = Liveblocks; exports.WebhookHandler = WebhookHandler; exports.authorize = authorize; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody;
1257
966
  //# sourceMappingURL=index.js.map