@gitbook/api 0.208.0 → 0.209.0

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
@@ -172,7 +172,7 @@ var require_node = __commonJS({
172
172
 
173
173
  // package.json
174
174
  var name = "@gitbook/api";
175
- var version = "0.208.0";
175
+ var version = "0.209.0";
176
176
 
177
177
  // src/client.ts
178
178
  var import_event_iterator = __toESM(require_node(), 1);
@@ -183,49 +183,134 @@ var ParseError = class extends Error {
183
183
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
184
184
  }
185
185
  };
186
+ var LF = 10;
187
+ var CR = 13;
188
+ var SPACE = 32;
186
189
  function noop(_arg) {
187
190
  }
188
- function createParser(callbacks) {
189
- if (typeof callbacks == "function")
191
+ function createParser(config) {
192
+ if (typeof config == "function")
190
193
  throw new TypeError(
191
- "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
194
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
192
195
  );
193
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
194
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
195
- function feed(newChunk) {
196
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
197
- for (const line of complete)
198
- parseLine(line);
199
- incompleteLine = incomplete, isFirstChunk = false;
196
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
197
+ let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
198
+ function feed(chunk) {
199
+ if (terminated)
200
+ throw new Error(
201
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
202
+ );
203
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
204
+ const trailing2 = processLines(chunk);
205
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
206
+ return;
207
+ }
208
+ if (chunk.indexOf(`
209
+ `) === -1 && chunk.indexOf("\r") === -1) {
210
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
211
+ return;
212
+ }
213
+ pendingFragments.push(chunk);
214
+ const input = pendingFragments.join("");
215
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
216
+ const trailing = processLines(input);
217
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
200
218
  }
201
- function parseLine(line) {
202
- if (line === "") {
219
+ function checkBufferSize() {
220
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
221
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
222
+ type: "max-buffer-size-exceeded"
223
+ })
224
+ )));
225
+ }
226
+ function processLines(chunk) {
227
+ let searchIndex = 0;
228
+ if (chunk.indexOf("\r") === -1) {
229
+ let lfIndex = chunk.indexOf(`
230
+ `, searchIndex);
231
+ for (; lfIndex !== -1; ) {
232
+ if (searchIndex === lfIndex) {
233
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
234
+ `, searchIndex);
235
+ continue;
236
+ }
237
+ const firstCharCode = chunk.charCodeAt(searchIndex);
238
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
239
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
240
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
241
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
242
+ `, searchIndex);
243
+ continue;
244
+ }
245
+ data = dataLines === 0 ? value : `${data}
246
+ ${value}`, dataLines++;
247
+ } else
248
+ isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
249
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
250
+ lfIndex
251
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
252
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
253
+ `, searchIndex);
254
+ }
255
+ return chunk.slice(searchIndex);
256
+ }
257
+ for (; searchIndex < chunk.length; ) {
258
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
259
+ `, searchIndex);
260
+ let lineEnd = -1;
261
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
262
+ break;
263
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
264
+ }
265
+ return chunk.slice(searchIndex);
266
+ }
267
+ function parseLine(chunk, start, end) {
268
+ if (start === end) {
203
269
  dispatchEvent();
204
270
  return;
205
271
  }
206
- if (line.startsWith(":")) {
207
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
272
+ const firstCharCode = chunk.charCodeAt(start);
273
+ if (isDataPrefix(chunk, start, firstCharCode)) {
274
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
275
+ data = dataLines === 0 ? value2 : `${data}
276
+ ${value2}`, dataLines++;
208
277
  return;
209
278
  }
210
- const fieldSeparatorIndex = line.indexOf(":");
211
- if (fieldSeparatorIndex !== -1) {
212
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
213
- processField(field, value, line);
279
+ if (isEventPrefix(chunk, start, firstCharCode)) {
280
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
214
281
  return;
215
282
  }
216
- processField(line, "", line);
283
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
284
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
285
+ value2.includes("\0") || (id = value2);
286
+ return;
287
+ }
288
+ if (firstCharCode === 58) {
289
+ if (onComment) {
290
+ const line2 = chunk.slice(start, end);
291
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
292
+ }
293
+ return;
294
+ }
295
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
296
+ if (fieldSeparatorIndex === -1) {
297
+ processField(line, "", line);
298
+ return;
299
+ }
300
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
301
+ processField(field, value, line);
217
302
  }
218
303
  function processField(field, value, line) {
219
304
  switch (field) {
220
305
  case "event":
221
- eventType = value;
306
+ eventType = value || void 0;
222
307
  break;
223
308
  case "data":
224
- data = `${data}${value}
225
- `;
309
+ data = dataLines === 0 ? value : `${data}
310
+ ${value}`, dataLines++;
226
311
  break;
227
312
  case "id":
228
- id = value.includes("\0") ? void 0 : value;
313
+ value.includes("\0") || (id = value);
229
314
  break;
230
315
  case "retry":
231
316
  /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
@@ -247,35 +332,26 @@ function createParser(callbacks) {
247
332
  }
248
333
  }
249
334
  function dispatchEvent() {
250
- data.length > 0 && onEvent({
335
+ dataLines > 0 && onEvent({
251
336
  id,
252
- event: eventType || void 0,
253
- data: data.endsWith(`
254
- `) ? data.slice(0, -1) : data
255
- }), id = void 0, data = "", eventType = "";
337
+ event: eventType,
338
+ data
339
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
256
340
  }
257
341
  function reset(options = {}) {
258
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
342
+ if (options.consume && pendingFragments.length > 0) {
343
+ const incompleteLine = pendingFragments.join("");
344
+ parseLine(incompleteLine, 0, incompleteLine.length);
345
+ }
346
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
259
347
  }
260
348
  return { feed, reset };
261
349
  }
262
- function splitLines(chunk) {
263
- const lines = [];
264
- let incompleteLine = "", searchIndex = 0;
265
- for (; searchIndex < chunk.length; ) {
266
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
267
- `, searchIndex);
268
- let lineEnd = -1;
269
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
270
- incompleteLine = chunk.slice(searchIndex);
271
- break;
272
- } else {
273
- const line = chunk.slice(searchIndex, lineEnd);
274
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
275
- ` && searchIndex++;
276
- }
277
- }
278
- return [lines, incompleteLine];
350
+ function isDataPrefix(chunk, i, firstCharCode) {
351
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
352
+ }
353
+ function isEventPrefix(chunk, i, firstCharCode) {
354
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
279
355
  }
280
356
 
281
357
  // src/client.ts
@@ -593,6 +669,12 @@ var SiteInsightsLinkPosition = /* @__PURE__ */ ((SiteInsightsLinkPosition2) => {
593
669
  SiteInsightsLinkPosition2["Content"] = "content";
594
670
  return SiteInsightsLinkPosition2;
595
671
  })(SiteInsightsLinkPosition || {});
672
+ var PageFeedbackRating = /* @__PURE__ */ ((PageFeedbackRating2) => {
673
+ PageFeedbackRating2["Bad"] = "bad";
674
+ PageFeedbackRating2["Ok"] = "ok";
675
+ PageFeedbackRating2["Good"] = "good";
676
+ return PageFeedbackRating2;
677
+ })(PageFeedbackRating || {});
596
678
  var SiteInsightsMarkdownSource = /* @__PURE__ */ ((SiteInsightsMarkdownSource2) => {
597
679
  SiteInsightsMarkdownSource2["PageAction"] = "page-action";
598
680
  return SiteInsightsMarkdownSource2;
@@ -1230,12 +1312,6 @@ var SiteType = /* @__PURE__ */ ((SiteType2) => {
1230
1312
  SiteType2["Sponsored"] = "sponsored";
1231
1313
  return SiteType2;
1232
1314
  })(SiteType || {});
1233
- var PageFeedbackRating = /* @__PURE__ */ ((PageFeedbackRating2) => {
1234
- PageFeedbackRating2["Bad"] = "bad";
1235
- PageFeedbackRating2["Ok"] = "ok";
1236
- PageFeedbackRating2["Good"] = "good";
1237
- return PageFeedbackRating2;
1238
- })(PageFeedbackRating || {});
1239
1315
  var IntegrationInstallationSiteSelection = /* @__PURE__ */ ((IntegrationInstallationSiteSelection2) => {
1240
1316
  IntegrationInstallationSiteSelection2["All"] = "all";
1241
1317
  IntegrationInstallationSiteSelection2["Selected"] = "selected";
@@ -1357,6 +1433,7 @@ var MemberDisabledReason = /* @__PURE__ */ ((MemberDisabledReason2) => {
1357
1433
  MemberDisabledReason2["Billing"] = "billing";
1358
1434
  MemberDisabledReason2["Scim"] = "scim";
1359
1435
  MemberDisabledReason2["Admin"] = "admin";
1436
+ MemberDisabledReason2["Gitbook"] = "gitbook";
1360
1437
  return MemberDisabledReason2;
1361
1438
  })(MemberDisabledReason || {});
1362
1439
  var RevisionPageLayoutPreset = /* @__PURE__ */ ((RevisionPageLayoutPreset2) => {
@@ -2812,6 +2889,33 @@ var Api = class extends HttpClient {
2812
2889
  format: "json",
2813
2890
  ...params
2814
2891
  }),
2892
+ createIntegrationOAuthTransaction: (integrationName, installationId, data, params = {}) => this.request({
2893
+ path: `/integrations/${integrationName}/installations/${installationId}/oauth-transactions`,
2894
+ method: "POST",
2895
+ body: data,
2896
+ secure: true,
2897
+ type: "application/json" /* Json */,
2898
+ format: "json",
2899
+ ...params
2900
+ }),
2901
+ consumeIntegrationOAuthTransaction: (integrationName, transactionId, data, params = {}) => this.request({
2902
+ path: `/integrations/${integrationName}/oauth-transactions/${transactionId}/consume`,
2903
+ method: "POST",
2904
+ body: data,
2905
+ secure: true,
2906
+ type: "application/json" /* Json */,
2907
+ format: "json",
2908
+ ...params
2909
+ }),
2910
+ confirmIntegrationOAuthTransaction: (integrationName, transactionId, data, params = {}) => this.request({
2911
+ path: `/integrations/${integrationName}/oauth-transactions/${transactionId}/confirm`,
2912
+ method: "POST",
2913
+ body: data,
2914
+ secure: true,
2915
+ type: "application/json" /* Json */,
2916
+ format: "json",
2917
+ ...params
2918
+ }),
2815
2919
  listIntegrationInstallationSpaces: (integrationName, installationId, query, params = {}) => this.request({
2816
2920
  path: `/integrations/${integrationName}/installations/${installationId}/spaces`,
2817
2921
  method: "GET",
@@ -4082,15 +4186,6 @@ var Api = class extends HttpClient {
4082
4186
  format: "json",
4083
4187
  ...params
4084
4188
  }),
4085
- updateSiteFindingById: (organizationId, siteId, siteFindingId, data, params = {}) => this.request({
4086
- path: `/orgs/${organizationId}/sites/${siteId}/findings/${siteFindingId}`,
4087
- method: "PATCH",
4088
- body: data,
4089
- secure: true,
4090
- type: "application/json" /* Json */,
4091
- format: "json",
4092
- ...params
4093
- }),
4094
4189
  listChangeRequestsForSiteFinding: (organizationId, siteId, siteFindingId, query, params = {}) => this.request({
4095
4190
  path: `/orgs/${organizationId}/sites/${siteId}/findings/${siteFindingId}/change-requests`,
4096
4191
  method: "GET",
@@ -4916,9 +5011,11 @@ var CHANGE_REQUEST_REVIEW_STATUS_ENUM = ["changes-requested", "approved"];
4916
5011
  var VARIABLE_NAME_MAX_LENGTH = 64;
4917
5012
  var VARIABLE_NAME_MIN_LENGTH = 1;
4918
5013
  var VARIABLE_NAME_PATTERN = "^[a-zA-Z_$][a-zA-Z0-9_$]*$";
5014
+ var REVISION_TAG_LABEL_MAX_LENGTH = 50;
5015
+ var REVISION_TAG_LABEL_MIN_LENGTH = 1;
4919
5016
  var REVISION_PAGE_TYPE_ENUM = ["document", "group", "link", "computed"];
4920
5017
  var REVISION_PAGE_LAYOUT_PRESET_ENUM = ["docs", "editorial", "landing"];
4921
- var MEMBER_DISABLED_REASON_ENUM = ["billing", "scim", "admin"];
5018
+ var MEMBER_DISABLED_REASON_ENUM = ["billing", "scim", "admin", "gitbook"];
4922
5019
  var INTEGRATION_TITLE_MAX_LENGTH = 30;
4923
5020
  var INTEGRATION_TITLE_MIN_LENGTH = 2;
4924
5021
  var INTEGRATION_DESCRIPTION_MAX_LENGTH = 100;
@@ -4949,7 +5046,6 @@ var COLLECTION_DESCRIPTION_MIN_LENGTH = 0;
4949
5046
  var INTEGRATION_INSTALLATION_STATUS_ENUM = ["active", "pending", "paused"];
4950
5047
  var INTEGRATION_INSTALLATION_SPACE_SELECTION_ENUM = ["all", "selected"];
4951
5048
  var INTEGRATION_INSTALLATION_SITE_SELECTION_ENUM = ["all", "selected"];
4952
- var PAGE_FEEDBACK_RATING_ENUM = ["bad", "ok", "good"];
4953
5049
  var SITE_TYPE_ENUM = ["basic", "premium", "ultimate", "sponsored"];
4954
5050
  var SITE_TITLE_MAX_LENGTH = 128;
4955
5051
  var SITE_TITLE_MIN_LENGTH = 2;
@@ -5093,6 +5189,7 @@ var SITE_SETTINGS_SCAN_TOPICS_ENUM = ["auto", "never"];
5093
5189
  var SITE_SETTINGS_FINDING_CHANGE_REQUESTS_ENUM = ["always", "auto-fixable", "never"];
5094
5190
  var SITE_INSIGHTS_DISPLAY_CONTEXT_ENUM = ["site", "server", "embed", "mcp"];
5095
5191
  var SITE_INSIGHTS_MARKDOWN_SOURCE_ENUM = ["page-action"];
5192
+ var PAGE_FEEDBACK_RATING_ENUM = ["bad", "ok", "good"];
5096
5193
  var SITE_INSIGHTS_LINK_POSITION_ENUM = ["announcement", "header", "footer", "sidebar", "content"];
5097
5194
  var SITE_INSIGHTS_TRADEMARK_PLACEMENT_ENUM = ["sidebar", "ad", "footer", "pdf", "embed"];
5098
5195
  var SITE_INSIGHTS_AD_PLACEMENT_ENUM = ["aside"];
@@ -5447,6 +5544,8 @@ export {
5447
5544
  REVISION_PAGE_SLUG_MIN_LENGTH,
5448
5545
  REVISION_PAGE_TYPE_ENUM,
5449
5546
  REVISION_SEMANTIC_CHANGE_TYPE_ENUM,
5547
+ REVISION_TAG_LABEL_MAX_LENGTH,
5548
+ REVISION_TAG_LABEL_MIN_LENGTH,
5450
5549
  RevisionPageDocumentCoverTextColor,
5451
5550
  RevisionPageLayoutOptionsCoverMask,
5452
5551
  RevisionPageLayoutOptionsCoverSize,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
- "version": "0.208.0",
7
+ "version": "0.209.0",
8
8
  "sideEffects": false,
9
9
  "files": [
10
10
  "README.md",