@gitbook/api 0.2.2 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.cjs +1054 -0
  2. package/package.json +13 -3
package/dist/index.cjs ADDED
@@ -0,0 +1,1054 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ APIIntegrationScope: () => APIIntegrationScope,
23
+ AnalyticsSearchPeriod: () => AnalyticsSearchPeriod,
24
+ AnalyticsTrafficInterval: () => AnalyticsTrafficInterval,
25
+ Api: () => Api,
26
+ BillingInterval: () => BillingInterval,
27
+ BillingProduct: () => BillingProduct,
28
+ ChangeRequestStatus: () => ChangeRequestStatus,
29
+ CloudflareHostnameStatus: () => CloudflareHostnameStatus,
30
+ CloudflareHostnameTLSStatus: () => CloudflareHostnameTLSStatus,
31
+ CloudflareHostnameTLSValidationMethod: () => CloudflareHostnameTLSValidationMethod,
32
+ ContentKitIcon: () => ContentKitIcon,
33
+ ContentType: () => ContentType,
34
+ ContentVisibility: () => ContentVisibility,
35
+ GITBOOK_DEFAULT_ENDPOINT: () => GITBOOK_DEFAULT_ENDPOINT,
36
+ GitBookAPI: () => GitBookAPI,
37
+ HttpClient: () => HttpClient,
38
+ ImportContentSource: () => ImportContentSource,
39
+ IntegrationCategory: () => IntegrationCategory,
40
+ IntegrationInstallationSpaceSelection: () => IntegrationInstallationSpaceSelection,
41
+ IntegrationInstallationStatus: () => IntegrationInstallationStatus,
42
+ IntegrationScope: () => IntegrationScope,
43
+ IntegrationVisibility: () => IntegrationVisibility,
44
+ MemberRole: () => MemberRole,
45
+ PurgeCDNCacheContextType: () => PurgeCDNCacheContextType
46
+ });
47
+ module.exports = __toCommonJS(src_exports);
48
+
49
+ // src/client.ts
50
+ var ContentVisibility = /* @__PURE__ */ ((ContentVisibility2) => {
51
+ ContentVisibility2["Public"] = "public";
52
+ ContentVisibility2["Unlisted"] = "unlisted";
53
+ ContentVisibility2["ShareLink"] = "share-link";
54
+ ContentVisibility2["VisitorAuth"] = "visitor-auth";
55
+ ContentVisibility2["InCollection"] = "in-collection";
56
+ ContentVisibility2["Private"] = "private";
57
+ return ContentVisibility2;
58
+ })(ContentVisibility || {});
59
+ var ImportContentSource = /* @__PURE__ */ ((ImportContentSource2) => {
60
+ ImportContentSource2["Website"] = "website";
61
+ ImportContentSource2["Docx"] = "docx";
62
+ ImportContentSource2["Markdown"] = "markdown";
63
+ ImportContentSource2["Html"] = "html";
64
+ ImportContentSource2["Zip"] = "zip";
65
+ ImportContentSource2["Confluence"] = "confluence";
66
+ ImportContentSource2["GithubWiki"] = "github-wiki";
67
+ ImportContentSource2["DropboxPaper"] = "dropbox-paper";
68
+ ImportContentSource2["Notion"] = "notion";
69
+ ImportContentSource2["Quip"] = "quip";
70
+ ImportContentSource2["GoogleDocs"] = "google-docs";
71
+ ImportContentSource2["OpenApi"] = "open-api";
72
+ return ImportContentSource2;
73
+ })(ImportContentSource || {});
74
+ var MemberRole = /* @__PURE__ */ ((MemberRole2) => {
75
+ MemberRole2["Admin"] = "admin";
76
+ MemberRole2["Create"] = "create";
77
+ MemberRole2["Edit"] = "edit";
78
+ MemberRole2["Review"] = "review";
79
+ MemberRole2["Comment"] = "comment";
80
+ MemberRole2["Read"] = "read";
81
+ return MemberRole2;
82
+ })(MemberRole || {});
83
+ var ChangeRequestStatus = /* @__PURE__ */ ((ChangeRequestStatus2) => {
84
+ ChangeRequestStatus2["Draft"] = "draft";
85
+ ChangeRequestStatus2["Open"] = "open";
86
+ ChangeRequestStatus2["Archived"] = "archived";
87
+ ChangeRequestStatus2["Merged"] = "merged";
88
+ return ChangeRequestStatus2;
89
+ })(ChangeRequestStatus || {});
90
+ var AnalyticsSearchPeriod = /* @__PURE__ */ ((AnalyticsSearchPeriod2) => {
91
+ AnalyticsSearchPeriod2["LastMonth"] = "last_month";
92
+ AnalyticsSearchPeriod2["LastWeek"] = "last_week";
93
+ AnalyticsSearchPeriod2["LastYear"] = "last_year";
94
+ return AnalyticsSearchPeriod2;
95
+ })(AnalyticsSearchPeriod || {});
96
+ var AnalyticsTrafficInterval = /* @__PURE__ */ ((AnalyticsTrafficInterval2) => {
97
+ AnalyticsTrafficInterval2["Daily"] = "daily";
98
+ AnalyticsTrafficInterval2["Weekly"] = "weekly";
99
+ AnalyticsTrafficInterval2["Monthly"] = "monthly";
100
+ return AnalyticsTrafficInterval2;
101
+ })(AnalyticsTrafficInterval || {});
102
+ var IntegrationScope = /* @__PURE__ */ ((IntegrationScope2) => {
103
+ IntegrationScope2["SpaceViewsRead"] = "space:views:read";
104
+ IntegrationScope2["SpaceContentRead"] = "space:content:read";
105
+ IntegrationScope2["SpaceContentWrite"] = "space:content:write";
106
+ IntegrationScope2["SpaceMetadataRead"] = "space:metadata:read";
107
+ IntegrationScope2["SpaceMetadataWrite"] = "space:metadata:write";
108
+ IntegrationScope2["SpaceScriptInject"] = "space:script:inject";
109
+ IntegrationScope2["SpaceScriptCookies"] = "space:script:cookies";
110
+ return IntegrationScope2;
111
+ })(IntegrationScope || {});
112
+ var IntegrationInstallationSpaceSelection = /* @__PURE__ */ ((IntegrationInstallationSpaceSelection2) => {
113
+ IntegrationInstallationSpaceSelection2["All"] = "all";
114
+ IntegrationInstallationSpaceSelection2["Selected"] = "selected";
115
+ return IntegrationInstallationSpaceSelection2;
116
+ })(IntegrationInstallationSpaceSelection || {});
117
+ var IntegrationCategory = /* @__PURE__ */ ((IntegrationCategory2) => {
118
+ IntegrationCategory2["Analytics"] = "analytics";
119
+ IntegrationCategory2["Collaboration"] = "collaboration";
120
+ IntegrationCategory2["Marketing"] = "marketing";
121
+ IntegrationCategory2["Content"] = "content";
122
+ IntegrationCategory2["Other"] = "other";
123
+ return IntegrationCategory2;
124
+ })(IntegrationCategory || {});
125
+ var IntegrationVisibility = /* @__PURE__ */ ((IntegrationVisibility2) => {
126
+ IntegrationVisibility2["Public"] = "public";
127
+ IntegrationVisibility2["Private"] = "private";
128
+ return IntegrationVisibility2;
129
+ })(IntegrationVisibility || {});
130
+ var IntegrationInstallationStatus = /* @__PURE__ */ ((IntegrationInstallationStatus2) => {
131
+ IntegrationInstallationStatus2["Active"] = "active";
132
+ IntegrationInstallationStatus2["Pending"] = "pending";
133
+ IntegrationInstallationStatus2["Paused"] = "paused";
134
+ return IntegrationInstallationStatus2;
135
+ })(IntegrationInstallationStatus || {});
136
+ var BillingInterval = /* @__PURE__ */ ((BillingInterval2) => {
137
+ BillingInterval2["Monthly"] = "monthly";
138
+ BillingInterval2["Yearly"] = "yearly";
139
+ return BillingInterval2;
140
+ })(BillingInterval || {});
141
+ var BillingProduct = /* @__PURE__ */ ((BillingProduct2) => {
142
+ BillingProduct2["Free"] = "free";
143
+ BillingProduct2["Plus"] = "plus";
144
+ BillingProduct2["Pro"] = "pro";
145
+ BillingProduct2["Team"] = "team";
146
+ BillingProduct2["Business"] = "business";
147
+ BillingProduct2["Legacy"] = "legacy";
148
+ BillingProduct2["Startup"] = "startup";
149
+ BillingProduct2["Enterprise"] = "enterprise";
150
+ return BillingProduct2;
151
+ })(BillingProduct || {});
152
+ var APIIntegrationScope = /* @__PURE__ */ ((APIIntegrationScope2) => {
153
+ APIIntegrationScope2["IntegrationRead"] = "integration:read";
154
+ APIIntegrationScope2["IntegrationUpdate"] = "integration:update";
155
+ APIIntegrationScope2["IntegrationInstallationRead"] = "integration:installation:read";
156
+ APIIntegrationScope2["IntegrationInstallationUpdate"] = "integration:installation:update";
157
+ return APIIntegrationScope2;
158
+ })(APIIntegrationScope || {});
159
+ var CloudflareHostnameStatus = /* @__PURE__ */ ((CloudflareHostnameStatus2) => {
160
+ CloudflareHostnameStatus2["Pending"] = "pending";
161
+ CloudflareHostnameStatus2["Active"] = "active";
162
+ CloudflareHostnameStatus2["Blocked"] = "blocked";
163
+ CloudflareHostnameStatus2["Moved"] = "moved";
164
+ CloudflareHostnameStatus2["Deleted"] = "deleted";
165
+ return CloudflareHostnameStatus2;
166
+ })(CloudflareHostnameStatus || {});
167
+ var CloudflareHostnameTLSStatus = /* @__PURE__ */ ((CloudflareHostnameTLSStatus2) => {
168
+ CloudflareHostnameTLSStatus2["Initializing"] = "initializing";
169
+ CloudflareHostnameTLSStatus2["PendingValidation"] = "pending_validation";
170
+ CloudflareHostnameTLSStatus2["PendingIssuance"] = "pending_issuance";
171
+ CloudflareHostnameTLSStatus2["PendingDeployment"] = "pending_deployment";
172
+ CloudflareHostnameTLSStatus2["Active"] = "active";
173
+ CloudflareHostnameTLSStatus2["PendingDeletion"] = "pending_deletion";
174
+ CloudflareHostnameTLSStatus2["PendingCleanup"] = "pending_cleanup";
175
+ CloudflareHostnameTLSStatus2["Deleted"] = "deleted";
176
+ return CloudflareHostnameTLSStatus2;
177
+ })(CloudflareHostnameTLSStatus || {});
178
+ var CloudflareHostnameTLSValidationMethod = /* @__PURE__ */ ((CloudflareHostnameTLSValidationMethod2) => {
179
+ CloudflareHostnameTLSValidationMethod2["Http"] = "http";
180
+ CloudflareHostnameTLSValidationMethod2["Txt"] = "txt";
181
+ CloudflareHostnameTLSValidationMethod2["Email"] = "email";
182
+ return CloudflareHostnameTLSValidationMethod2;
183
+ })(CloudflareHostnameTLSValidationMethod || {});
184
+ var PurgeCDNCacheContextType = /* @__PURE__ */ ((PurgeCDNCacheContextType2) => {
185
+ PurgeCDNCacheContextType2["Tags"] = "tags";
186
+ PurgeCDNCacheContextType2["Hosts"] = "hosts";
187
+ return PurgeCDNCacheContextType2;
188
+ })(PurgeCDNCacheContextType || {});
189
+ var ContentKitIcon = /* @__PURE__ */ ((ContentKitIcon2) => {
190
+ ContentKitIcon2["Close"] = "close";
191
+ ContentKitIcon2["Edit"] = "edit";
192
+ ContentKitIcon2["Github"] = "github";
193
+ ContentKitIcon2["Maximize"] = "maximize";
194
+ ContentKitIcon2["Email"] = "email";
195
+ ContentKitIcon2["Settings"] = "settings";
196
+ ContentKitIcon2["Search"] = "search";
197
+ ContentKitIcon2["Delete"] = "delete";
198
+ ContentKitIcon2["Star"] = "star";
199
+ ContentKitIcon2["Warning"] = "warning";
200
+ ContentKitIcon2["Link"] = "link";
201
+ ContentKitIcon2["LinkExternal"] = "link-external";
202
+ return ContentKitIcon2;
203
+ })(ContentKitIcon || {});
204
+ var ContentType = /* @__PURE__ */ ((ContentType2) => {
205
+ ContentType2["Json"] = "application/json";
206
+ ContentType2["FormData"] = "multipart/form-data";
207
+ ContentType2["UrlEncoded"] = "application/x-www-form-urlencoded";
208
+ return ContentType2;
209
+ })(ContentType || {});
210
+ var HttpClient = class {
211
+ constructor(apiConfig = {}) {
212
+ this.baseUrl = "{host}/v1";
213
+ this.securityData = null;
214
+ this.abortControllers = /* @__PURE__ */ new Map();
215
+ this.customFetch = (...fetchParams) => fetch(...fetchParams);
216
+ this.baseApiParams = {
217
+ credentials: "same-origin",
218
+ headers: {},
219
+ redirect: "follow",
220
+ referrerPolicy: "no-referrer"
221
+ };
222
+ this.setSecurityData = (data) => {
223
+ this.securityData = data;
224
+ };
225
+ this.contentFormatters = {
226
+ ["application/json" /* Json */]: (input) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
227
+ ["multipart/form-data" /* FormData */]: (input) => Object.keys(input || {}).reduce((formData, key) => {
228
+ const property = input[key];
229
+ formData.append(
230
+ key,
231
+ property instanceof Blob ? property : typeof property === "object" && property !== null ? JSON.stringify(property) : `${property}`
232
+ );
233
+ return formData;
234
+ }, new FormData()),
235
+ ["application/x-www-form-urlencoded" /* UrlEncoded */]: (input) => this.toQueryString(input)
236
+ };
237
+ this.createAbortSignal = (cancelToken) => {
238
+ if (this.abortControllers.has(cancelToken)) {
239
+ const abortController2 = this.abortControllers.get(cancelToken);
240
+ if (abortController2) {
241
+ return abortController2.signal;
242
+ }
243
+ return void 0;
244
+ }
245
+ const abortController = new AbortController();
246
+ this.abortControllers.set(cancelToken, abortController);
247
+ return abortController.signal;
248
+ };
249
+ this.abortRequest = (cancelToken) => {
250
+ const abortController = this.abortControllers.get(cancelToken);
251
+ if (abortController) {
252
+ abortController.abort();
253
+ this.abortControllers.delete(cancelToken);
254
+ }
255
+ };
256
+ this.request = async ({
257
+ body,
258
+ secure,
259
+ path,
260
+ type,
261
+ query,
262
+ format,
263
+ baseUrl,
264
+ cancelToken,
265
+ ...params
266
+ }) => {
267
+ const secureParams = (typeof secure === "boolean" ? secure : this.baseApiParams.secure) && this.securityWorker && await this.securityWorker(this.securityData) || {};
268
+ const requestParams = this.mergeRequestParams(params, secureParams);
269
+ const queryString = query && this.toQueryString(query);
270
+ const payloadFormatter = this.contentFormatters[type || "application/json" /* Json */];
271
+ const responseFormat = format || requestParams.format;
272
+ return this.customFetch(
273
+ `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`,
274
+ {
275
+ ...requestParams,
276
+ headers: {
277
+ ...type && type !== "multipart/form-data" /* FormData */ ? { "Content-Type": type } : {},
278
+ ...requestParams.headers || {}
279
+ },
280
+ signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0,
281
+ body: typeof body === "undefined" || body === null ? null : payloadFormatter(body)
282
+ }
283
+ ).then(async (response) => {
284
+ const r = response;
285
+ r.data = null;
286
+ r.error = null;
287
+ const data = !responseFormat ? r : await response[responseFormat]().then((data2) => {
288
+ if (r.ok) {
289
+ r.data = data2;
290
+ } else {
291
+ r.error = data2;
292
+ }
293
+ return r;
294
+ }).catch((e) => {
295
+ r.error = e;
296
+ return r;
297
+ });
298
+ if (cancelToken) {
299
+ this.abortControllers.delete(cancelToken);
300
+ }
301
+ if (!response.ok)
302
+ throw data;
303
+ return data;
304
+ });
305
+ };
306
+ Object.assign(this, apiConfig);
307
+ }
308
+ encodeQueryParam(key, value) {
309
+ const encodedKey = encodeURIComponent(key);
310
+ return `${encodedKey}=${encodeURIComponent(
311
+ typeof value === "number" ? value : `${value}`
312
+ )}`;
313
+ }
314
+ addQueryParam(query, key) {
315
+ return this.encodeQueryParam(key, query[key]);
316
+ }
317
+ addArrayQueryParam(query, key) {
318
+ const value = query[key];
319
+ return value.map((v) => this.encodeQueryParam(key, v)).join("&");
320
+ }
321
+ toQueryString(rawQuery) {
322
+ const query = rawQuery || {};
323
+ const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
324
+ return keys.map(
325
+ (key) => Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)
326
+ ).join("&");
327
+ }
328
+ addQueryParams(rawQuery) {
329
+ const queryString = this.toQueryString(rawQuery);
330
+ return queryString ? `?${queryString}` : "";
331
+ }
332
+ mergeRequestParams(params1, params2) {
333
+ return {
334
+ ...this.baseApiParams,
335
+ ...params1,
336
+ ...params2 || {},
337
+ headers: {
338
+ ...this.baseApiParams.headers || {},
339
+ ...params1.headers || {},
340
+ ...params2 && params2.headers || {}
341
+ }
342
+ };
343
+ }
344
+ };
345
+ var Api = class extends HttpClient {
346
+ constructor() {
347
+ super(...arguments);
348
+ this.getApiInformation = (params = {}) => this.request({
349
+ path: `/`,
350
+ method: "GET",
351
+ secure: true,
352
+ format: "json",
353
+ ...params
354
+ });
355
+ this.search = {
356
+ searchContent: (query, params = {}) => this.request({
357
+ path: `/search`,
358
+ method: "GET",
359
+ query,
360
+ secure: true,
361
+ format: "json",
362
+ ...params
363
+ }),
364
+ askQuery: (query, params = {}) => this.request({
365
+ path: `/search/ask`,
366
+ method: "GET",
367
+ query,
368
+ secure: true,
369
+ format: "json",
370
+ ...params
371
+ })
372
+ };
373
+ this.user = {
374
+ getAuthenticatedUser: (params = {}) => this.request({
375
+ path: `/user`,
376
+ method: "GET",
377
+ secure: true,
378
+ format: "json",
379
+ ...params
380
+ }),
381
+ listSpacesForAuthenticatedUser: (query, params = {}) => this.request({
382
+ path: `/user/spaces`,
383
+ method: "GET",
384
+ query,
385
+ secure: true,
386
+ format: "json",
387
+ ...params
388
+ })
389
+ };
390
+ this.users = {
391
+ getUserById: (userId, params = {}) => this.request({
392
+ path: `/users/${userId}`,
393
+ method: "GET",
394
+ secure: true,
395
+ format: "json",
396
+ ...params
397
+ })
398
+ };
399
+ this.spaces = {
400
+ getSpaceById: (spaceId, params = {}) => this.request({
401
+ path: `/spaces/${spaceId}`,
402
+ method: "GET",
403
+ secure: true,
404
+ format: "json",
405
+ ...params
406
+ }),
407
+ searchSpaceContent: (spaceId, query, params = {}) => this.request({
408
+ path: `/spaces/${spaceId}/search`,
409
+ method: "GET",
410
+ query,
411
+ secure: true,
412
+ format: "json",
413
+ ...params
414
+ }),
415
+ askQueryInSpace: (spaceId, query, params = {}) => this.request({
416
+ path: `/spaces/${spaceId}/search/ask`,
417
+ method: "GET",
418
+ query,
419
+ secure: true,
420
+ format: "json",
421
+ ...params
422
+ }),
423
+ importGitRepository: (spaceId, data, params = {}) => this.request({
424
+ path: `/spaces/${spaceId}/git/import`,
425
+ method: "POST",
426
+ body: data,
427
+ secure: true,
428
+ type: "application/json" /* Json */,
429
+ ...params
430
+ }),
431
+ exportToGitRepository: (spaceId, data, params = {}) => this.request({
432
+ path: `/spaces/${spaceId}/git/export`,
433
+ method: "POST",
434
+ body: data,
435
+ secure: true,
436
+ type: "application/json" /* Json */,
437
+ ...params
438
+ }),
439
+ getContentAnalyticsForSpaceById: (spaceId, params = {}) => this.request({
440
+ path: `/spaces/${spaceId}/insights/content`,
441
+ method: "GET",
442
+ secure: true,
443
+ format: "json",
444
+ ...params
445
+ }),
446
+ getSearchAnalyticsForSpaceById: (spaceId, query, params = {}) => this.request({
447
+ path: `/spaces/${spaceId}/insights/search`,
448
+ method: "GET",
449
+ query,
450
+ secure: true,
451
+ format: "json",
452
+ ...params
453
+ }),
454
+ getTrafficAnalyticsForSpaceById: (spaceId, query, params = {}) => this.request({
455
+ path: `/spaces/${spaceId}/insights/traffic`,
456
+ method: "GET",
457
+ query,
458
+ secure: true,
459
+ format: "json",
460
+ ...params
461
+ }),
462
+ trackViewInSpaceById: (spaceId, data, params = {}) => this.request({
463
+ path: `/spaces/${spaceId}/insights/track_view`,
464
+ method: "POST",
465
+ body: data,
466
+ secure: true,
467
+ type: "application/json" /* Json */,
468
+ ...params
469
+ }),
470
+ getCurrentRevision: (spaceId, params = {}) => this.request({
471
+ path: `/spaces/${spaceId}/content`,
472
+ method: "GET",
473
+ secure: true,
474
+ format: "json",
475
+ ...params
476
+ }),
477
+ importContent: (spaceId, data, params = {}) => this.request({
478
+ path: `/spaces/${spaceId}/content/import`,
479
+ method: "POST",
480
+ body: data,
481
+ secure: true,
482
+ type: "application/json" /* Json */,
483
+ format: "json",
484
+ ...params
485
+ }),
486
+ listFiles: (spaceId, query, params = {}) => this.request({
487
+ path: `/spaces/${spaceId}/content/files`,
488
+ method: "GET",
489
+ query,
490
+ secure: true,
491
+ ...params
492
+ }),
493
+ getPageById: (spaceId, pageId, query, params = {}) => this.request({
494
+ path: `/spaces/${spaceId}/content/page/${pageId}`,
495
+ method: "GET",
496
+ query,
497
+ secure: true,
498
+ format: "json",
499
+ ...params
500
+ }),
501
+ importContentInPageById: (spaceId, pageId, data, params = {}) => this.request({
502
+ path: `/spaces/${spaceId}/content/page/${pageId}/import`,
503
+ method: "POST",
504
+ body: data,
505
+ secure: true,
506
+ type: "application/json" /* Json */,
507
+ format: "json",
508
+ ...params
509
+ }),
510
+ getPageByPath: (spaceId, pagePath, query, params = {}) => this.request({
511
+ path: `/spaces/${spaceId}/content/path/${pagePath}`,
512
+ method: "GET",
513
+ query,
514
+ secure: true,
515
+ format: "json",
516
+ ...params
517
+ }),
518
+ createChangeRequest: (spaceId, data, params = {}) => this.request({
519
+ path: `/spaces/${spaceId}/change-requests`,
520
+ method: "POST",
521
+ body: data,
522
+ secure: true,
523
+ type: "application/json" /* Json */,
524
+ format: "json",
525
+ ...params
526
+ }),
527
+ mergeChangeRequest: (spaceId, changeRequestId, params = {}) => this.request({
528
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/merge`,
529
+ method: "POST",
530
+ secure: true,
531
+ format: "json",
532
+ ...params
533
+ }),
534
+ updateChangeRequest: (spaceId, changeRequestId, params = {}) => this.request({
535
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/update`,
536
+ method: "POST",
537
+ secure: true,
538
+ format: "json",
539
+ ...params
540
+ }),
541
+ getRevisionOfChangeRequestById: (spaceId, changeRequestId, params = {}) => this.request({
542
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content`,
543
+ method: "GET",
544
+ secure: true,
545
+ format: "json",
546
+ ...params
547
+ }),
548
+ importContentInChangeRequest: (spaceId, changeRequestId, data, params = {}) => this.request({
549
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content/import`,
550
+ method: "POST",
551
+ body: data,
552
+ secure: true,
553
+ type: "application/json" /* Json */,
554
+ format: "json",
555
+ ...params
556
+ }),
557
+ listFilesInChangeRequestById: (spaceId, changeRequestId, query, params = {}) => this.request({
558
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content/files`,
559
+ method: "GET",
560
+ query,
561
+ secure: true,
562
+ ...params
563
+ }),
564
+ getPageInChangeRequestById: (spaceId, changeRequestId, pageId, query, params = {}) => this.request({
565
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content/page/${pageId}`,
566
+ method: "GET",
567
+ query,
568
+ secure: true,
569
+ format: "json",
570
+ ...params
571
+ }),
572
+ importContentInChangeRequestPageById: (spaceId, changeRequestId, pageId, data, params = {}) => this.request({
573
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content/page/${pageId}/import`,
574
+ method: "POST",
575
+ body: data,
576
+ secure: true,
577
+ type: "application/json" /* Json */,
578
+ format: "json",
579
+ ...params
580
+ }),
581
+ getPageInChangeRequestByPath: (spaceId, changeRequestId, pagePath, query, params = {}) => this.request({
582
+ path: `/spaces/${spaceId}/change-requests/${changeRequestId}/content/path/${pagePath}`,
583
+ method: "GET",
584
+ query,
585
+ secure: true,
586
+ format: "json",
587
+ ...params
588
+ }),
589
+ getRevisionById: (spaceId, revisionId, params = {}) => this.request({
590
+ path: `/spaces/${spaceId}/revisions/${revisionId}`,
591
+ method: "GET",
592
+ secure: true,
593
+ format: "json",
594
+ ...params
595
+ }),
596
+ listFilesInRevisionById: (spaceId, revisionId, query, params = {}) => this.request({
597
+ path: `/spaces/${spaceId}/revisions/${revisionId}/files`,
598
+ method: "GET",
599
+ query,
600
+ secure: true,
601
+ ...params
602
+ }),
603
+ getPageInRevisionById: (spaceId, revisionId, pageId, query, params = {}) => this.request({
604
+ path: `/spaces/${spaceId}/revisions/${revisionId}/page/${pageId}`,
605
+ method: "GET",
606
+ query,
607
+ secure: true,
608
+ format: "json",
609
+ ...params
610
+ }),
611
+ getPageInRevisionByPath: (spaceId, revisionId, pagePath, query, params = {}) => this.request({
612
+ path: `/spaces/${spaceId}/revisions/${revisionId}/path/${pagePath}`,
613
+ method: "GET",
614
+ query,
615
+ secure: true,
616
+ format: "json",
617
+ ...params
618
+ }),
619
+ listPermissionsAggregateInSpace: (spaceId, query, params = {}) => this.request({
620
+ path: `/spaces/${spaceId}/permissions/aggregate`,
621
+ method: "GET",
622
+ query,
623
+ secure: true,
624
+ format: "json",
625
+ ...params
626
+ })
627
+ };
628
+ this.collections = {
629
+ getCollectionById: (collectionId, params = {}) => this.request({
630
+ path: `/collections/${collectionId}`,
631
+ method: "GET",
632
+ secure: true,
633
+ format: "json",
634
+ ...params
635
+ }),
636
+ listSpacesInCollectionById: (collectionId, query, params = {}) => this.request({
637
+ path: `/collections/${collectionId}/spaces`,
638
+ method: "GET",
639
+ query,
640
+ secure: true,
641
+ format: "json",
642
+ ...params
643
+ }),
644
+ listPermissionsAggregateInCollection: (collectionId, query, params = {}) => this.request({
645
+ path: `/collections/${collectionId}/permissions/aggregate`,
646
+ method: "GET",
647
+ query,
648
+ secure: true,
649
+ format: "json",
650
+ ...params
651
+ })
652
+ };
653
+ this.integrations = {
654
+ listIntegrations: (query, params = {}) => this.request({
655
+ path: `/integrations`,
656
+ method: "GET",
657
+ query,
658
+ secure: true,
659
+ format: "json",
660
+ ...params
661
+ }),
662
+ getIntegrationByName: (integrationName, params = {}) => this.request({
663
+ path: `/integrations/${integrationName}`,
664
+ method: "GET",
665
+ secure: true,
666
+ format: "json",
667
+ ...params
668
+ }),
669
+ publishIntegration: (integrationName, data, params = {}) => this.request({
670
+ path: `/integrations/${integrationName}`,
671
+ method: "POST",
672
+ body: data,
673
+ secure: true,
674
+ type: "application/json" /* Json */,
675
+ format: "json",
676
+ ...params
677
+ }),
678
+ unpublishIntegration: (integrationName, params = {}) => this.request({
679
+ path: `/integrations/${integrationName}`,
680
+ method: "DELETE",
681
+ secure: true,
682
+ ...params
683
+ }),
684
+ listIntegrationInstallations: (integrationName, query, params = {}) => this.request({
685
+ path: `/integrations/${integrationName}/installations`,
686
+ method: "GET",
687
+ query,
688
+ secure: true,
689
+ format: "json",
690
+ ...params
691
+ }),
692
+ listIntegrationSpaceInstallations: (integrationName, query, params = {}) => this.request({
693
+ path: `/integrations/${integrationName}/spaces`,
694
+ method: "GET",
695
+ query,
696
+ secure: true,
697
+ format: "json",
698
+ ...params
699
+ }),
700
+ renderIntegrationUiWithGet: (integrationName, query, params = {}) => this.request({
701
+ path: `/integrations/${integrationName}/render`,
702
+ method: "GET",
703
+ query,
704
+ secure: true,
705
+ format: "json",
706
+ ...params
707
+ }),
708
+ renderIntegrationUiWithPost: (integrationName, data, params = {}) => this.request({
709
+ path: `/integrations/${integrationName}/render`,
710
+ method: "POST",
711
+ body: data,
712
+ secure: true,
713
+ type: "application/json" /* Json */,
714
+ format: "json",
715
+ ...params
716
+ }),
717
+ updateIntegrationInstallation: (integrationName, installationId, data, params = {}) => this.request({
718
+ path: `/integrations/${integrationName}/installations/${installationId}`,
719
+ method: "PATCH",
720
+ body: data,
721
+ secure: true,
722
+ type: "application/json" /* Json */,
723
+ format: "json",
724
+ ...params
725
+ }),
726
+ createIntegrationInstallationToken: (integrationName, installationId, params = {}) => this.request({
727
+ path: `/integrations/${integrationName}/installations/${installationId}/tokens`,
728
+ method: "POST",
729
+ secure: true,
730
+ format: "json",
731
+ ...params
732
+ }),
733
+ updateIntegrationSpaceInstallation: (integrationName, installationId, spaceId, data, params = {}) => this.request({
734
+ path: `/integrations/${integrationName}/installations/${installationId}/spaces/${spaceId}`,
735
+ method: "PATCH",
736
+ body: data,
737
+ secure: true,
738
+ type: "application/json" /* Json */,
739
+ format: "json",
740
+ ...params
741
+ })
742
+ };
743
+ this.orgs = {
744
+ listOrganizationsForAuthenticatedUser: (query, params = {}) => this.request({
745
+ path: `/orgs`,
746
+ method: "GET",
747
+ query,
748
+ secure: true,
749
+ format: "json",
750
+ ...params
751
+ }),
752
+ listMembersInOrganizationById: (organizationId, query, params = {}) => this.request({
753
+ path: `/orgs/${organizationId}/members`,
754
+ method: "GET",
755
+ query,
756
+ secure: true,
757
+ format: "json",
758
+ ...params
759
+ }),
760
+ getMemberInOrganizationById: (organizationId, userId, params = {}) => this.request({
761
+ path: `/orgs/${organizationId}/members/${userId}`,
762
+ method: "GET",
763
+ secure: true,
764
+ format: "json",
765
+ ...params
766
+ }),
767
+ updateMemberInOrganizationById: (organizationId, userId, data, params = {}) => this.request({
768
+ path: `/orgs/${organizationId}/members/${userId}`,
769
+ method: "PATCH",
770
+ body: data,
771
+ secure: true,
772
+ type: "application/json" /* Json */,
773
+ format: "json",
774
+ ...params
775
+ }),
776
+ removeMemberFromOrganizationById: (organizationId, userId, params = {}) => this.request({
777
+ path: `/orgs/${organizationId}/members/${userId}`,
778
+ method: "DELETE",
779
+ secure: true,
780
+ ...params
781
+ }),
782
+ setUserAsSsoMemberForOrganization: (organizationId, userId, params = {}) => this.request({
783
+ path: `/orgs/${organizationId}/members/${userId}/sso`,
784
+ method: "POST",
785
+ secure: true,
786
+ ...params
787
+ }),
788
+ listSpacesForOrganizationMember: (organizationId, userId, query, params = {}) => this.request({
789
+ path: `/orgs/${organizationId}/members/${userId}/spaces`,
790
+ method: "GET",
791
+ query,
792
+ secure: true,
793
+ format: "json",
794
+ ...params
795
+ }),
796
+ listTeamsInOrganizationById: (organizationId, query, params = {}) => this.request({
797
+ path: `/orgs/${organizationId}/teams`,
798
+ method: "GET",
799
+ query,
800
+ secure: true,
801
+ format: "json",
802
+ ...params
803
+ }),
804
+ createOrganizationTeam: (organizationId, data, params = {}) => this.request({
805
+ path: `/orgs/${organizationId}/teams`,
806
+ method: "PUT",
807
+ body: data,
808
+ secure: true,
809
+ type: "application/json" /* Json */,
810
+ format: "json",
811
+ ...params
812
+ }),
813
+ getTeamInOrganizationById: (organizationId, teamId, params = {}) => this.request({
814
+ path: `/orgs/${organizationId}/teams/${teamId}`,
815
+ method: "GET",
816
+ secure: true,
817
+ format: "json",
818
+ ...params
819
+ }),
820
+ updateTeamInOrganizationById: (organizationId, teamId, data, params = {}) => this.request({
821
+ path: `/orgs/${organizationId}/teams/${teamId}`,
822
+ method: "PATCH",
823
+ body: data,
824
+ secure: true,
825
+ type: "application/json" /* Json */,
826
+ format: "json",
827
+ ...params
828
+ }),
829
+ removeTeamFromOrganizationById: (organizationId, teamId, params = {}) => this.request({
830
+ path: `/orgs/${organizationId}/teams/${teamId}`,
831
+ method: "DELETE",
832
+ secure: true,
833
+ ...params
834
+ }),
835
+ updateMembersInOrganizationTeam: (organizationId, teamId, data, params = {}) => this.request({
836
+ path: `/orgs/${organizationId}/teams/${teamId}/members`,
837
+ method: "PUT",
838
+ body: data,
839
+ secure: true,
840
+ type: "application/json" /* Json */,
841
+ ...params
842
+ }),
843
+ listTeamMembersInOrganizationById: (organizationId, teamId, query, params = {}) => this.request({
844
+ path: `/orgs/${organizationId}/teams/${teamId}/members`,
845
+ method: "GET",
846
+ query,
847
+ secure: true,
848
+ format: "json",
849
+ ...params
850
+ }),
851
+ addMemberToOrganizationTeamById: (organizationId, teamId, userId, params = {}) => this.request({
852
+ path: `/orgs/${organizationId}/teams/${teamId}/members/${userId}`,
853
+ method: "PUT",
854
+ secure: true,
855
+ ...params
856
+ }),
857
+ deleteMemberFromOrganizationTeamById: (organizationId, teamId, userId, params = {}) => this.request({
858
+ path: `/orgs/${organizationId}/teams/${teamId}/members/${userId}`,
859
+ method: "DELETE",
860
+ secure: true,
861
+ ...params
862
+ }),
863
+ inviteUsersToOrganization: (organizationId, data, params = {}) => this.request({
864
+ path: `/orgs/${organizationId}/invites`,
865
+ method: "POST",
866
+ body: data,
867
+ secure: true,
868
+ type: "application/json" /* Json */,
869
+ format: "json",
870
+ ...params
871
+ }),
872
+ joinOrganizationWithInvite: (organizationId, inviteId, params = {}) => this.request({
873
+ path: `/orgs/${organizationId}/invites/${inviteId}`,
874
+ method: "POST",
875
+ secure: true,
876
+ format: "json",
877
+ ...params
878
+ }),
879
+ upgradeOrganizationPlan: (organizationId, data, params = {}) => this.request({
880
+ path: `/orgs/${organizationId}/billing`,
881
+ method: "POST",
882
+ body: data,
883
+ secure: true,
884
+ type: "application/json" /* Json */,
885
+ format: "json",
886
+ ...params
887
+ }),
888
+ getOrganizationBillingPortal: (organizationId, params = {}) => this.request({
889
+ path: `/orgs/${organizationId}/billing`,
890
+ method: "GET",
891
+ secure: true,
892
+ format: "json",
893
+ ...params
894
+ }),
895
+ requestOrganizationUpgrade: (organizationId, params = {}) => this.request({
896
+ path: `/orgs/${organizationId}/request_upgrade`,
897
+ method: "POST",
898
+ secure: true,
899
+ format: "json",
900
+ ...params
901
+ }),
902
+ transferOrganization: (organizationId, data, params = {}) => this.request({
903
+ path: `/orgs/${organizationId}/transfer`,
904
+ method: "POST",
905
+ body: data,
906
+ secure: true,
907
+ type: "application/json" /* Json */,
908
+ format: "json",
909
+ ...params
910
+ }),
911
+ searchOrganizationContent: (organizationId, query, params = {}) => this.request({
912
+ path: `/orgs/${organizationId}/search`,
913
+ method: "GET",
914
+ query,
915
+ secure: true,
916
+ format: "json",
917
+ ...params
918
+ }),
919
+ listSpacesInOrganizationById: (organizationId, query, params = {}) => this.request({
920
+ path: `/orgs/${organizationId}/spaces`,
921
+ method: "GET",
922
+ query,
923
+ secure: true,
924
+ format: "json",
925
+ ...params
926
+ }),
927
+ listCollectionsInOrganizationById: (organizationId, query, params = {}) => this.request({
928
+ path: `/orgs/${organizationId}/collections`,
929
+ method: "GET",
930
+ query,
931
+ secure: true,
932
+ format: "json",
933
+ ...params
934
+ }),
935
+ setupDirectorySync: (organizationId, params = {}) => this.request({
936
+ path: `/orgs/${organizationId}/dsync`,
937
+ method: "POST",
938
+ secure: true,
939
+ format: "json",
940
+ ...params
941
+ }),
942
+ listDirectorySyncGroups: (organizationId, params = {}) => this.request({
943
+ path: `/orgs/${organizationId}/dsync/groups`,
944
+ method: "GET",
945
+ secure: true,
946
+ format: "json",
947
+ ...params
948
+ }),
949
+ syncDirectorySyncGroupsToTeams: (organizationId, data, params = {}) => this.request({
950
+ path: `/orgs/${organizationId}/dsync/teams`,
951
+ method: "POST",
952
+ body: data,
953
+ secure: true,
954
+ type: "application/json" /* Json */,
955
+ format: "json",
956
+ ...params
957
+ })
958
+ };
959
+ this.urls = {
960
+ getContentByUrl: (query, params = {}) => this.request({
961
+ path: `/urls/content`,
962
+ method: "GET",
963
+ query,
964
+ secure: true,
965
+ format: "json",
966
+ ...params
967
+ })
968
+ };
969
+ }
970
+ };
971
+
972
+ // src/index.ts
973
+ var GITBOOK_DEFAULT_ENDPOINT = "https://api.gitbook.com";
974
+ var GitBookAPI = class extends Api {
975
+ constructor(options = {}) {
976
+ const { endpoint = GITBOOK_DEFAULT_ENDPOINT, authToken } = options;
977
+ super({
978
+ baseUrl: `${endpoint}/v1`,
979
+ securityWorker: (securityData) => {
980
+ if (securityData.authToken) {
981
+ return {
982
+ headers: {
983
+ Authorization: `Bearer ${securityData.authToken}`
984
+ }
985
+ };
986
+ }
987
+ return {};
988
+ },
989
+ customFetch: async (input, init) => {
990
+ if ("credentials" in init) {
991
+ delete init.credentials;
992
+ }
993
+ if ("referrerPolicy" in init) {
994
+ delete init.referrerPolicy;
995
+ }
996
+ const response = await fetch(input, init);
997
+ if (!response.ok) {
998
+ let error = response.statusText;
999
+ try {
1000
+ const body = await response.json();
1001
+ error = body?.error?.message || error;
1002
+ } catch (err) {
1003
+ response.headers.forEach((value, key) => {
1004
+ error += `${key}:${value} `;
1005
+ });
1006
+ }
1007
+ throw new Error(
1008
+ `GitBook API failed with [${response.status}] ${response.url}: ${error}`
1009
+ );
1010
+ }
1011
+ return response;
1012
+ }
1013
+ });
1014
+ this.endpoint = endpoint;
1015
+ this.setSecurityData({ authToken });
1016
+ }
1017
+ async createInstallationClient(integrationName, installationId) {
1018
+ const { data: installationToken } = await this.integrations.createIntegrationInstallationToken(
1019
+ integrationName,
1020
+ installationId
1021
+ );
1022
+ return new GitBookAPI({
1023
+ endpoint: this.endpoint,
1024
+ authToken: installationToken.token
1025
+ });
1026
+ }
1027
+ };
1028
+ // Annotate the CommonJS export names for ESM import in node:
1029
+ 0 && (module.exports = {
1030
+ APIIntegrationScope,
1031
+ AnalyticsSearchPeriod,
1032
+ AnalyticsTrafficInterval,
1033
+ Api,
1034
+ BillingInterval,
1035
+ BillingProduct,
1036
+ ChangeRequestStatus,
1037
+ CloudflareHostnameStatus,
1038
+ CloudflareHostnameTLSStatus,
1039
+ CloudflareHostnameTLSValidationMethod,
1040
+ ContentKitIcon,
1041
+ ContentType,
1042
+ ContentVisibility,
1043
+ GITBOOK_DEFAULT_ENDPOINT,
1044
+ GitBookAPI,
1045
+ HttpClient,
1046
+ ImportContentSource,
1047
+ IntegrationCategory,
1048
+ IntegrationInstallationSpaceSelection,
1049
+ IntegrationInstallationStatus,
1050
+ IntegrationScope,
1051
+ IntegrationVisibility,
1052
+ MemberRole,
1053
+ PurgeCDNCacheContextType
1054
+ });
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@gitbook/api",
3
3
  "type": "module",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "version": "0.2.2",
4
+ "main": "./dist/index.cjs",
5
+ "module": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "version": "0.3.0",
7
8
  "sideEffects": false,
8
9
  "files": [
9
10
  "spec/**",
@@ -29,5 +30,14 @@
29
30
  "build": "./build.sh",
30
31
  "lint": "eslint ./src/**/*.ts",
31
32
  "typecheck": "tsc --noEmit"
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "require": "./dist/index.cjs",
37
+ "import": "./dist/index.js",
38
+ "types": "./dist/index.d.ts"
39
+ },
40
+ "./spec/openapi.json": "./spec/openapi.json",
41
+ "./spec/openapi.yaml": "./spec/openapi.yaml"
32
42
  }
33
43
  }