mdedit-cli 0.4.5 → 0.4.7

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
@@ -10,6 +10,17 @@ var __export = (target, all) => {
10
10
  };
11
11
 
12
12
  // ../sdk/dist/index.js
13
+ async function parseMutationJson(response, options) {
14
+ const body = await response.json();
15
+ options?.onResponseMetadata?.({
16
+ idempotencyReplay: response.headers?.get?.("Idempotency-Replayed") === "true",
17
+ idempotencyReplayTruncated: response.headers?.get?.("Idempotency-Replay-Truncated") === "true"
18
+ });
19
+ return body;
20
+ }
21
+ function mutationHeaders(options) {
22
+ return options?.idempotencyKey ? { "Idempotency-Key": options.idempotencyKey } : void 0;
23
+ }
13
24
  function createFetchers(config) {
14
25
  const baseUrlV1 = (config.baseUrlV1 ?? "").replace(/\/$/, "");
15
26
  const baseUrlV2 = (config.baseUrlV2 ?? "").replace(/\/$/, "");
@@ -301,12 +312,24 @@ function createSdkClient(config) {
301
312
  list: async (workspaceId) => await withFetchError(() => getArticles(workspaceId, fetchers)) ?? [],
302
313
  listByFolder: async (workspaceId, folderId) => await withFetchError(() => getArticlesByFolder(workspaceId, folderId, fetchers)) ?? [],
303
314
  get: async (workspaceId, articleId) => await withFetchError(() => getArticle(workspaceId, articleId, fetchers)),
304
- create: (workspaceId, req) => withFetchError(() => createArticle(workspaceId, req, fetchers)),
305
- update: (workspaceId, req) => withFetchError(() => updateArticle(workspaceId, req, fetchers)),
306
- delete: async (workspaceId, articleId) => {
307
- await withFetchError(() => deleteArticle(workspaceId, articleId, fetchers));
315
+ create: (workspaceId, req, options) => withFetchError(() => createArticle(workspaceId, req, fetchers, options)),
316
+ editCommands: (workspaceId, articleId, request, options) => withFetchError(() => applyArticleEditCommands(workspaceId, articleId, request, fetchers, options)),
317
+ update: (workspaceId, req, options) => withFetchError(() => updateArticle(
318
+ workspaceId,
319
+ req,
320
+ fetchers,
321
+ options
322
+ )),
323
+ delete: async (workspaceId, articleId, options) => {
324
+ await withFetchError(() => deleteArticle(workspaceId, articleId, fetchers, options));
308
325
  },
309
- saveContent: (workspaceId, articleId, content, options) => withFetchError(() => saveArticleContent(workspaceId, articleId, content, options, fetchers)),
326
+ saveContent: (workspaceId, articleId, content, options) => withFetchError(() => saveArticleContent(
327
+ workspaceId,
328
+ articleId,
329
+ content,
330
+ options ? { ...options, request: { idempotencyKey: options.idempotencyKey } } : options,
331
+ fetchers
332
+ )),
310
333
  exportZip: (workspaceId, articleId) => withFetchError(() => exportArticleZip(workspaceId, articleId, fetchers)),
311
334
  presentation: (workspaceId, articleId) => withFetchError(() => getArticlePresentation(workspaceId, articleId, fetchers)),
312
335
  startExport: (workspaceId, articleId, format) => withFetchError(() => createArticleExportJob(workspaceId, articleId, format, fetchers)),
@@ -343,14 +366,14 @@ function createSdkClient(config) {
343
366
  startConversion: (input) => withFetchError(() => startConversionFromBytes(input, fetchers))
344
367
  },
345
368
  publish: {
346
- publish: (workspaceId, articleId, request = {}) => withFetchError(() => publishArticle(workspaceId, articleId, request, fetchers)),
369
+ publish: (workspaceId, articleId, request = {}, options) => withFetchError(() => publishArticle(workspaceId, articleId, request, fetchers, options)),
347
370
  status: (workspaceId, articleId) => withFetchError(() => getPublishStatus(workspaceId, articleId, fetchers)),
348
- update: (workspaceId, articleId, request = {}) => withFetchError(() => updatePublishedArticle(workspaceId, articleId, request, fetchers)),
349
- unpublish: (workspaceId, articleId) => withFetchError(() => unpublishArticle(workspaceId, articleId, fetchers))
371
+ update: (workspaceId, articleId, request = {}, options) => withFetchError(() => updatePublishedArticle(workspaceId, articleId, request, fetchers, options)),
372
+ unpublish: (workspaceId, articleId, options) => withFetchError(() => unpublishArticle(workspaceId, articleId, fetchers, options))
350
373
  }
351
374
  };
352
375
  }
353
- var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, updateArticle, getArticles, getArticlesByFolder, getArticle, getArticlePresentation, getArticleAssetDownloadUrls, getArticleMediaProxyUrls, getArticleSafeGists, deleteArticle, exportArticleZip, createArticleExportJob, ApiError, DEFAULT_POLL_INTERVAL_MS, DEFAULT_TIMEOUT_MS, sleep, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep2, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
376
+ var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, applyArticleEditCommands, updateArticle, getArticles, getArticlesByFolder, getArticle, getArticlePresentation, getArticleAssetDownloadUrls, getArticleMediaProxyUrls, getArticleSafeGists, deleteArticle, exportArticleZip, createArticleExportJob, ApiError, DEFAULT_POLL_INTERVAL_MS, DEFAULT_TIMEOUT_MS, sleep, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep2, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
354
377
  var init_dist = __esm({
355
378
  "../sdk/dist/index.js"() {
356
379
  "use strict";
@@ -370,10 +393,11 @@ var init_dist = __esm({
370
393
  }
371
394
  };
372
395
  errors_default = FetchError;
373
- createArticle = async (workspaceId, articleRequest, fetchers) => {
396
+ createArticle = async (workspaceId, articleRequest, fetchers, requestOptions) => {
374
397
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
375
398
  const response = await fetchV2(`/workspaces/${workspaceId}/articles`, {
376
399
  method: "POST",
400
+ headers: mutationHeaders(requestOptions),
377
401
  body: JSON.stringify({
378
402
  articleId: articleRequest.articleId,
379
403
  title: articleRequest.title,
@@ -398,9 +422,21 @@ var init_dist = __esm({
398
422
  }
399
423
  throw new errors_default(`Error creating article. ${errorText}`, response.status);
400
424
  }
401
- return response.json();
425
+ return parseMutationJson(response, requestOptions);
426
+ };
427
+ applyArticleEditCommands = async (workspaceId, articleId, body, fetchers, requestOptions) => {
428
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
429
+ const response = await fetchV2(`/workspaces/${workspaceId}/articles/${articleId}/edit-commands`, {
430
+ method: "POST",
431
+ headers: mutationHeaders(requestOptions),
432
+ body: JSON.stringify(body)
433
+ });
434
+ if (!response.ok) {
435
+ throw new errors_default(`Error editing article. ${await response.text()}`, response.status);
436
+ }
437
+ return parseMutationJson(response, requestOptions);
402
438
  };
403
- updateArticle = async (workspaceId, articleRequest, fetchers) => {
439
+ updateArticle = async (workspaceId, articleRequest, fetchers, requestOptions) => {
404
440
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
405
441
  const body = {
406
442
  title: articleRequest.title,
@@ -430,6 +466,7 @@ var init_dist = __esm({
430
466
  `/workspaces/${workspaceId}/articles/${articleRequest.articleId}`,
431
467
  {
432
468
  method: "PUT",
469
+ headers: mutationHeaders(requestOptions),
433
470
  body: JSON.stringify(body)
434
471
  }
435
472
  );
@@ -533,11 +570,11 @@ var init_dist = __esm({
533
570
  if (!response.ok) throw new errors_default(`Error loading Gists. ${await response.text()}`, response.status);
534
571
  return response.json();
535
572
  };
536
- deleteArticle = async (workspaceId, articleId, fetchers) => {
573
+ deleteArticle = async (workspaceId, articleId, fetchers, requestOptions) => {
537
574
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
538
575
  const response = await fetchV2(
539
576
  `/workspaces/${workspaceId}/articles/${articleId}`,
540
- { method: "DELETE" }
577
+ { method: "DELETE", headers: mutationHeaders(requestOptions) }
541
578
  );
542
579
  if (!response.ok) {
543
580
  throw new errors_default(
@@ -612,6 +649,7 @@ var init_dist = __esm({
612
649
  method: "POST",
613
650
  ...options ? {
614
651
  body: JSON.stringify({
652
+ uploadId: `${options.baseContentRevision}-${options.contentHash}`,
615
653
  baseContentRevision: options.baseContentRevision,
616
654
  baseContentHash: options.baseContentHash,
617
655
  contentHash: options.contentHash,
@@ -646,6 +684,7 @@ var init_dist = __esm({
646
684
  `/workspaces/${workspaceId}/articles/${articleId}/content-commit`,
647
685
  {
648
686
  method: "POST",
687
+ headers: mutationHeaders(options.request),
649
688
  body: JSON.stringify({
650
689
  uploadId,
651
690
  baseContentRevision: options.baseContentRevision,
@@ -919,12 +958,13 @@ var init_dist = __esm({
919
958
  }
920
959
  return response.json();
921
960
  };
922
- publishArticle = async (workspaceId, articleId, body, fetchers) => {
961
+ publishArticle = async (workspaceId, articleId, body, fetchers, requestOptions) => {
923
962
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
924
963
  const response = await fetchV2(
925
964
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
926
965
  {
927
966
  method: "POST",
967
+ headers: mutationHeaders(requestOptions),
928
968
  body: JSON.stringify(body)
929
969
  }
930
970
  );
@@ -934,13 +974,13 @@ var init_dist = __esm({
934
974
  response.status
935
975
  );
936
976
  }
937
- return response.json();
977
+ return parseMutationJson(response, requestOptions);
938
978
  };
939
- unpublishArticle = async (workspaceId, articleId, fetchers) => {
979
+ unpublishArticle = async (workspaceId, articleId, fetchers, requestOptions) => {
940
980
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
941
981
  const response = await fetchV2(
942
982
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
943
- { method: "DELETE" }
983
+ { method: "DELETE", headers: mutationHeaders(requestOptions) }
944
984
  );
945
985
  if (!response.ok) {
946
986
  throw new errors_default(
@@ -948,7 +988,7 @@ var init_dist = __esm({
948
988
  response.status
949
989
  );
950
990
  }
951
- return response.json();
991
+ return parseMutationJson(response, requestOptions);
952
992
  };
953
993
  getPublishStatus = async (workspaceId, articleId, fetchers) => {
954
994
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
@@ -964,12 +1004,13 @@ var init_dist = __esm({
964
1004
  }
965
1005
  return response.json();
966
1006
  };
967
- updatePublishedArticle = async (workspaceId, articleId, body, fetchers) => {
1007
+ updatePublishedArticle = async (workspaceId, articleId, body, fetchers, requestOptions) => {
968
1008
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
969
1009
  const response = await fetchV2(
970
1010
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
971
1011
  {
972
1012
  method: "PUT",
1013
+ headers: mutationHeaders(requestOptions),
973
1014
  body: JSON.stringify(body)
974
1015
  }
975
1016
  );
@@ -979,7 +1020,7 @@ var init_dist = __esm({
979
1020
  response.status
980
1021
  );
981
1022
  }
982
- return response.json();
1023
+ return parseMutationJson(response, requestOptions);
983
1024
  };
984
1025
  FetchError2 = class extends Error {
985
1026
  status;