@gitbook/api 0.88.0 → 0.89.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,129 +172,103 @@ var require_node = __commonJS({
172
172
 
173
173
  // package.json
174
174
  var name = "@gitbook/api";
175
- var version = "0.88.0";
175
+ var version = "0.89.0";
176
176
 
177
177
  // src/client.ts
178
178
  var import_event_iterator = __toESM(require_node(), 1);
179
179
 
180
180
  // ../../node_modules/eventsource-parser/dist/index.js
181
- function createParser(onParse) {
182
- let isFirstChunk;
183
- let buffer;
184
- let startingPosition;
185
- let startingFieldLength;
186
- let eventId;
187
- let eventName;
188
- let data;
189
- reset();
190
- return {
191
- feed,
192
- reset
193
- };
194
- function reset() {
195
- isFirstChunk = true;
196
- buffer = "";
197
- startingPosition = 0;
198
- startingFieldLength = -1;
199
- eventId = void 0;
200
- eventName = void 0;
201
- data = "";
181
+ var __defProp2 = Object.defineProperty;
182
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
183
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
184
+ var ParseError = class extends Error {
185
+ constructor(message, options) {
186
+ super(message), __publicField(this, "type"), __publicField(this, "field"), __publicField(this, "value"), __publicField(this, "line"), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
202
187
  }
203
- function feed(chunk) {
204
- buffer = buffer ? buffer + chunk : chunk;
205
- if (isFirstChunk && hasBom(buffer)) {
206
- buffer = buffer.slice(BOM.length);
207
- }
208
- isFirstChunk = false;
209
- const length = buffer.length;
210
- let position = 0;
211
- let discardTrailingNewline = false;
212
- while (position < length) {
213
- if (discardTrailingNewline) {
214
- if (buffer[position] === "\n") {
215
- ++position;
216
- }
217
- discardTrailingNewline = false;
218
- }
219
- let lineLength = -1;
220
- let fieldLength = startingFieldLength;
221
- let character;
222
- for (let index = startingPosition; lineLength < 0 && index < length; ++index) {
223
- character = buffer[index];
224
- if (character === ":" && fieldLength < 0) {
225
- fieldLength = index - position;
226
- } else if (character === "\r") {
227
- discardTrailingNewline = true;
228
- lineLength = index - position;
229
- } else if (character === "\n") {
230
- lineLength = index - position;
231
- }
232
- }
233
- if (lineLength < 0) {
234
- startingPosition = length - position;
235
- startingFieldLength = fieldLength;
236
- break;
237
- } else {
238
- startingPosition = 0;
239
- startingFieldLength = -1;
240
- }
241
- parseEventStreamLine(buffer, position, fieldLength, lineLength);
242
- position += lineLength + 1;
243
- }
244
- if (position === length) {
245
- buffer = "";
246
- } else if (position > 0) {
247
- buffer = buffer.slice(position);
248
- }
188
+ };
189
+ function noop(_arg) {
190
+ }
191
+ function createParser(callbacks) {
192
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
193
+ let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
194
+ function feed(newChunk) {
195
+ const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
196
+ for (const line of complete)
197
+ parseLine(line);
198
+ incompleteLine = incomplete, isFirstChunk = false;
249
199
  }
250
- function parseEventStreamLine(lineBuffer, index, fieldLength, lineLength) {
251
- if (lineLength === 0) {
252
- if (data.length > 0) {
253
- onParse({
254
- type: "event",
255
- id: eventId,
256
- event: eventName || void 0,
257
- data: data.slice(0, -1)
258
- });
259
- data = "";
260
- eventId = void 0;
261
- }
262
- eventName = void 0;
200
+ function parseLine(line) {
201
+ if (line === "") {
202
+ dispatchEvent();
263
203
  return;
264
204
  }
265
- const noValue = fieldLength < 0;
266
- const field = lineBuffer.slice(index, index + (noValue ? lineLength : fieldLength));
267
- let step = 0;
268
- if (noValue) {
269
- step = lineLength;
270
- } else if (lineBuffer[index + fieldLength + 1] === " ") {
271
- step = fieldLength + 2;
272
- } else {
273
- step = fieldLength + 1;
205
+ if (line.startsWith(":")) {
206
+ onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
207
+ return;
274
208
  }
275
- const position = index + step;
276
- const valueLength = lineLength - step;
277
- const value = lineBuffer.slice(position, position + valueLength).toString();
278
- if (field === "data") {
279
- data += value ? "".concat(value, "\n") : "\n";
280
- } else if (field === "event") {
281
- eventName = value;
282
- } else if (field === "id" && !value.includes("\0")) {
283
- eventId = value;
284
- } else if (field === "retry") {
285
- const retry = parseInt(value, 10);
286
- if (!Number.isNaN(retry)) {
287
- onParse({
288
- type: "reconnect-interval",
289
- value: retry
290
- });
291
- }
209
+ const fieldSeparatorIndex = line.indexOf(":");
210
+ if (fieldSeparatorIndex !== -1) {
211
+ const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
212
+ processField(field, value, line);
213
+ return;
214
+ }
215
+ processField(line, "", line);
216
+ }
217
+ function processField(field, value, line) {
218
+ switch (field) {
219
+ case "event":
220
+ eventType = value;
221
+ break;
222
+ case "data":
223
+ data = `${data}${value}
224
+ `;
225
+ break;
226
+ case "id":
227
+ id = value.includes("\0") ? void 0 : value;
228
+ break;
229
+ case "retry":
230
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
231
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
232
+ type: "invalid-retry",
233
+ value,
234
+ line
235
+ })
236
+ );
237
+ break;
238
+ default:
239
+ onError(
240
+ new ParseError(
241
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
242
+ { type: "unknown-field", field, value, line }
243
+ )
244
+ );
245
+ break;
292
246
  }
293
247
  }
248
+ function dispatchEvent() {
249
+ data.length > 0 && onEvent({
250
+ id,
251
+ event: eventType || void 0,
252
+ data: data.endsWith(`
253
+ `) ? data.slice(0, -1) : data
254
+ }), id = void 0, data = "", eventType = "";
255
+ }
256
+ function reset(options = {}) {
257
+ incompleteLine && options.consume && parseLine(incompleteLine), id = void 0, data = "", eventType = "", incompleteLine = "";
258
+ }
259
+ return { feed, reset };
294
260
  }
295
- var BOM = [239, 187, 191];
296
- function hasBom(buffer) {
297
- return BOM.every((charCode, index) => buffer.charCodeAt(index) === charCode);
261
+ function splitLines(chunk) {
262
+ const lines = [];
263
+ let incompleteLine = "";
264
+ const totalLength = chunk.length;
265
+ for (let i = 0; i < totalLength; i++) {
266
+ const char = chunk[i];
267
+ char === "\r" && chunk[i + 1] === `
268
+ ` ? (lines.push(incompleteLine), incompleteLine = "", i++) : char === "\r" || char === `
269
+ ` ? (lines.push(incompleteLine), incompleteLine = "") : incompleteLine += char;
270
+ }
271
+ return [lines, incompleteLine];
298
272
  }
299
273
 
300
274
  // src/client.ts
@@ -643,6 +617,25 @@ var BillingInterval = /* @__PURE__ */ ((BillingInterval2) => {
643
617
  BillingInterval2["Yearly"] = "yearly";
644
618
  return BillingInterval2;
645
619
  })(BillingInterval || {});
620
+ var SiteToMigrateFeature = /* @__PURE__ */ ((SiteToMigrateFeature2) => {
621
+ SiteToMigrateFeature2["Sections"] = "sections";
622
+ SiteToMigrateFeature2["VisitorAuth"] = "visitor-auth";
623
+ SiteToMigrateFeature2["Redirects"] = "redirects";
624
+ SiteToMigrateFeature2["CustomHostname"] = "custom-hostname";
625
+ SiteToMigrateFeature2["AISearch"] = "AI-search";
626
+ SiteToMigrateFeature2["PDFExport"] = "PDF-export";
627
+ SiteToMigrateFeature2["PageRatings"] = "page-ratings";
628
+ SiteToMigrateFeature2["CustomLogo"] = "custom-logo";
629
+ SiteToMigrateFeature2["CustomThemePreset"] = "custom-theme-preset";
630
+ SiteToMigrateFeature2["CustomFonts"] = "custom-fonts";
631
+ SiteToMigrateFeature2["CustomIcons"] = "custom-icons";
632
+ SiteToMigrateFeature2["CustomFooterLogo"] = "custom-footer-logo";
633
+ SiteToMigrateFeature2["CustomFooterCopyright"] = "custom-footer-copyright";
634
+ SiteToMigrateFeature2["CustomFooterLinks"] = "custom-footer-links";
635
+ SiteToMigrateFeature2["Unlisted"] = "unlisted";
636
+ SiteToMigrateFeature2["ShareLinks"] = "share-links";
637
+ return SiteToMigrateFeature2;
638
+ })(SiteToMigrateFeature || {});
646
639
  var CustomizationIconsStyle = /* @__PURE__ */ ((CustomizationIconsStyle2) => {
647
640
  CustomizationIconsStyle2["Regular"] = "regular";
648
641
  CustomizationIconsStyle2["Solid"] = "solid";
@@ -669,16 +662,30 @@ var SiteInsightsLinkPosition = /* @__PURE__ */ ((SiteInsightsLinkPosition2) => {
669
662
  SiteInsightsLinkPosition2["Content"] = "content";
670
663
  return SiteInsightsLinkPosition2;
671
664
  })(SiteInsightsLinkPosition || {});
665
+ var SiteInsightsTrademarkPlacement = /* @__PURE__ */ ((SiteInsightsTrademarkPlacement2) => {
666
+ SiteInsightsTrademarkPlacement2["Sidebar"] = "sidebar";
667
+ SiteInsightsTrademarkPlacement2["Ad"] = "ad";
668
+ SiteInsightsTrademarkPlacement2["Footer"] = "footer";
669
+ return SiteInsightsTrademarkPlacement2;
670
+ })(SiteInsightsTrademarkPlacement || {});
671
+ var SiteInsightsAdPlacement = /* @__PURE__ */ ((SiteInsightsAdPlacement2) => {
672
+ SiteInsightsAdPlacement2["Aside"] = "aside";
673
+ return SiteInsightsAdPlacement2;
674
+ })(SiteInsightsAdPlacement || {});
672
675
  var SiteInsightsEventType = /* @__PURE__ */ ((SiteInsightsEventType2) => {
673
676
  SiteInsightsEventType2["PageView"] = "page_view";
674
677
  SiteInsightsEventType2["SearchOpen"] = "search_open";
675
678
  SiteInsightsEventType2["SearchTypeQuery"] = "search_type_query";
676
679
  SiteInsightsEventType2["SearchOpenResult"] = "search_open_result";
677
680
  SiteInsightsEventType2["PagePostFeedback"] = "page_post_feedback";
681
+ SiteInsightsEventType2["PagePostFeedbackComment"] = "page_post_feedback_comment";
678
682
  SiteInsightsEventType2["AskQuestion"] = "ask_question";
679
683
  SiteInsightsEventType2["LinkClick"] = "link_click";
680
684
  SiteInsightsEventType2["ApiClientOpen"] = "api_client_open";
681
685
  SiteInsightsEventType2["ApiClientRequest"] = "api_client_request";
686
+ SiteInsightsEventType2["AdClick"] = "ad_click";
687
+ SiteInsightsEventType2["AdDisplay"] = "ad_display";
688
+ SiteInsightsEventType2["TrademarkClick"] = "trademark_click";
682
689
  return SiteInsightsEventType2;
683
690
  })(SiteInsightsEventType || {});
684
691
  var SiteInsightsVisitorBrowser = /* @__PURE__ */ ((SiteInsightsVisitorBrowser2) => {
@@ -1030,14 +1037,22 @@ var HttpClient = class {
1030
1037
  reader.cancel();
1031
1038
  queue.stop();
1032
1039
  };
1033
- const parser = createParser((event) => {
1034
- if (event.type === "event") {
1035
- if (event.data === "done") {
1040
+ const parser = createParser({
1041
+ onEvent: (event) => {
1042
+ if (event.event === "done") {
1036
1043
  stop();
1044
+ } else if (event.event === "error") {
1045
+ const data = JSON.parse(event.data);
1046
+ reader.cancel();
1047
+ queue.fail(new Error(data.error.message));
1037
1048
  } else {
1038
1049
  const data = JSON.parse(event.data);
1039
1050
  queue.push(data);
1040
1051
  }
1052
+ },
1053
+ onError: (error) => {
1054
+ reader.cancel();
1055
+ queue.fail(error);
1041
1056
  }
1042
1057
  });
1043
1058
  const decoder = new TextDecoder();
@@ -1298,6 +1313,12 @@ var Api = class extends HttpClient {
1298
1313
  secure: true,
1299
1314
  ...params
1300
1315
  }),
1316
+ removeUserFromSpace: (spaceId, userId, params = {}) => this.request({
1317
+ path: `/spaces/${spaceId}/permissions/users/${userId}`,
1318
+ method: "DELETE",
1319
+ secure: true,
1320
+ ...params
1321
+ }),
1301
1322
  getCurrentRevision: (spaceId, query, params = {}) => this.request({
1302
1323
  path: `/spaces/${spaceId}/content`,
1303
1324
  method: "GET",
@@ -2014,6 +2035,18 @@ var Api = class extends HttpClient {
2014
2035
  type: "application/json" /* Json */,
2015
2036
  ...params
2016
2037
  }),
2038
+ removeTeamFromCollection: (collectionId, teamId, params = {}) => this.request({
2039
+ path: `/collections/${collectionId}/permissions/teams/${teamId}`,
2040
+ method: "DELETE",
2041
+ secure: true,
2042
+ ...params
2043
+ }),
2044
+ removeUserFromCollection: (collectionId, userId, params = {}) => this.request({
2045
+ path: `/collections/${collectionId}/permissions/users/${userId}`,
2046
+ method: "DELETE",
2047
+ secure: true,
2048
+ ...params
2049
+ }),
2017
2050
  listPermissionsAggregateInCollection: (collectionId, query, params = {}) => this.request({
2018
2051
  path: `/collections/${collectionId}/permissions/aggregate`,
2019
2052
  method: "GET",
@@ -2489,6 +2522,29 @@ var Api = class extends HttpClient {
2489
2522
  format: "json",
2490
2523
  ...params
2491
2524
  }),
2525
+ migrateOrganizationPlan: (organizationId, query, params = {}) => this.request({
2526
+ path: `/orgs/${organizationId}/billing/migrate`,
2527
+ method: "POST",
2528
+ query,
2529
+ secure: true,
2530
+ ...params
2531
+ }),
2532
+ previewMigrateOrganizationPlan: (organizationId, query, params = {}) => this.request({
2533
+ path: `/orgs/${organizationId}/billing/migrate`,
2534
+ method: "GET",
2535
+ query,
2536
+ secure: true,
2537
+ format: "json",
2538
+ ...params
2539
+ }),
2540
+ listSitesToMigrate: (organizationId, query, params = {}) => this.request({
2541
+ path: `/orgs/${organizationId}/billing/migrate/sites`,
2542
+ method: "GET",
2543
+ query,
2544
+ secure: true,
2545
+ format: "json",
2546
+ ...params
2547
+ }),
2492
2548
  getOrganizationBillingPortal: (organizationId, params = {}) => this.request({
2493
2549
  path: `/orgs/${organizationId}/billing/portal`,
2494
2550
  method: "GET",
@@ -2623,21 +2679,6 @@ var Api = class extends HttpClient {
2623
2679
  format: "json",
2624
2680
  ...params
2625
2681
  }),
2626
- listOrgExperimentalFeatures: (organizationId, params = {}) => this.request({
2627
- path: `/orgs/${organizationId}/experiments`,
2628
- method: "GET",
2629
- secure: true,
2630
- format: "json",
2631
- ...params
2632
- }),
2633
- updateOrgExperimentalFeatures: (organizationId, data, params = {}) => this.request({
2634
- path: `/orgs/${organizationId}/experiments`,
2635
- method: "POST",
2636
- body: data,
2637
- secure: true,
2638
- type: "application/json" /* Json */,
2639
- ...params
2640
- }),
2641
2682
  listSamlProvidersInOrganizationById: (organizationId, query, params = {}) => this.request({
2642
2683
  path: `/orgs/${organizationId}/saml`,
2643
2684
  method: "GET",
@@ -3076,6 +3117,30 @@ var Api = class extends HttpClient {
3076
3117
  format: "json",
3077
3118
  ...params
3078
3119
  }),
3120
+ addSectionGroupToSite: (organizationId, siteId, data, params = {}) => this.request({
3121
+ path: `/orgs/${organizationId}/sites/${siteId}/section-groups`,
3122
+ method: "POST",
3123
+ body: data,
3124
+ secure: true,
3125
+ type: "application/json" /* Json */,
3126
+ format: "json",
3127
+ ...params
3128
+ }),
3129
+ updateSiteSectionGroupById: (organizationId, siteId, siteSectionGroupId, data, params = {}) => this.request({
3130
+ path: `/orgs/${organizationId}/sites/${siteId}/section-groups/${siteSectionGroupId}`,
3131
+ method: "PATCH",
3132
+ body: data,
3133
+ secure: true,
3134
+ type: "application/json" /* Json */,
3135
+ format: "json",
3136
+ ...params
3137
+ }),
3138
+ deleteSiteSectionGroupById: (organizationId, siteId, siteSectionGroupId, params = {}) => this.request({
3139
+ path: `/orgs/${organizationId}/sites/${siteId}/section-groups/${siteSectionGroupId}`,
3140
+ method: "DELETE",
3141
+ secure: true,
3142
+ ...params
3143
+ }),
3079
3144
  addSectionToSite: (organizationId, siteId, data, params = {}) => this.request({
3080
3145
  path: `/orgs/${organizationId}/sites/${siteId}/sections`,
3081
3146
  method: "POST",
@@ -3159,6 +3224,12 @@ var Api = class extends HttpClient {
3159
3224
  format: "json",
3160
3225
  ...params
3161
3226
  }),
3227
+ deleteSiteSpaceCustomizationById: (organizationId, siteId, siteSpaceId, params = {}) => this.request({
3228
+ path: `/orgs/${organizationId}/sites/${siteId}/site-spaces/${siteSpaceId}/customization`,
3229
+ method: "DELETE",
3230
+ secure: true,
3231
+ ...params
3232
+ }),
3162
3233
  getSiteSpaceRawCustomizationById: (organizationId, siteId, siteSpaceId, params = {}) => this.request({
3163
3234
  path: `/orgs/${organizationId}/sites/${siteId}/site-spaces/${siteSpaceId}/customization/raw`,
3164
3235
  method: "GET",
@@ -3536,14 +3607,17 @@ export {
3536
3607
  RevisionSemanticChangeType,
3537
3608
  SiteAdsStatus,
3538
3609
  SiteAdsTopic,
3610
+ SiteInsightsAdPlacement,
3539
3611
  SiteInsightsEventType,
3540
3612
  SiteInsightsLinkPosition,
3541
3613
  SiteInsightsQueryOperator,
3542
3614
  SiteInsightsQueryRange,
3615
+ SiteInsightsTrademarkPlacement,
3543
3616
  SiteInsightsVisitorBot,
3544
3617
  SiteInsightsVisitorBrowser,
3545
3618
  SiteInsightsVisitorDevice,
3546
3619
  SiteInsightsVisitorOS,
3620
+ SiteToMigrateFeature,
3547
3621
  SiteType,
3548
3622
  SiteVisibility,
3549
3623
  SpaceBlockReason,
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.88.0",
7
+ "version": "0.89.0",
8
8
  "sideEffects": false,
9
9
  "files": [
10
10
  "README.md",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "dependencies": {
15
15
  "event-iterator": "^2.0.0",
16
- "eventsource-parser": "^1.1.1"
16
+ "eventsource-parser": "^3.0.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "swagger-typescript-api": "^13.0.3",