mdedit-cli 0.3.3 → 0.3.5

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Official command-line interface for [mdedit.ai](https://mdedit.ai).
4
4
 
5
5
  Links:
6
- - [CLI docs](https://docs.mdedit.ai/cli)
6
+ - [CLI docs](https://mdedit.ai/docs/cli)
7
7
  - [mdedit.ai homepage](https://mdedit.ai)
8
8
 
9
9
  ## Install
@@ -16,7 +16,7 @@ npm install -g mdedit-cli
16
16
 
17
17
  All APIs require authentication. Create an API key here:
18
18
 
19
- - [API key docs](https://docs.mdedit.ai/api-keys)
19
+ - [API key docs](https://mdedit.ai/docs/api-keys)
20
20
 
21
21
  Interactive browser OAuth is also available in explicitly enabled cohorts. It
22
22
  uses authorization code + PKCE, a fixed loopback callback, and the operating
@@ -70,29 +70,42 @@ the result or typed error is the only value written to stdout.
70
70
 
71
71
  ## Public links
72
72
 
73
- Use a key with `publishing:write` to publish or update a public snapshot. Publishing is
74
- explicit: later edits stay private until the command is run again.
73
+ Use a key with `publishing:write` to create a public `mded.it` link. New links are
74
+ **Live** by default: later durable document edits update the same URL automatically.
75
+ Use `--snapshot` for a frozen artifact that changes only when you publish again.
75
76
 
76
77
  ```bash
77
- mdedit article publish <articleId> --yes
78
- mdedit article publish <articleId> --slug my-document --yes
78
+ mdedit article publish <articleId>
79
+ mdedit article publish <articleId> --snapshot
80
+ mdedit article publish <articleId> --slug my-document
79
81
  mdedit article publish-status <articleId> --format json
80
82
  mdedit article unpublish <articleId> --yes
81
83
  ```
82
84
 
83
- Create a document from Markdown and publish it in one command:
85
+ Create a document from Markdown and publish a Live link in one command, without a
86
+ confirmation flag:
84
87
 
85
88
  ```bash
86
89
  mdedit article create \
87
90
  --file document.md \
88
- --publish \
89
- --yes
91
+ --publish
90
92
  ```
91
93
 
92
94
  Without `--title`, the CLI uses the first Markdown H1 or the filename.
93
- The JSON result includes `publication.shortUrl`, such as
94
- `https://mded.it/my-document`. If article creation succeeds but publishing fails, the
95
- article is kept private and the command reports its article ID.
95
+ The JSON result includes the stable URL, `mode`, source revision/version fields, and
96
+ `syncStatus` under `publication`. `publish-status --format json` returns the same
97
+ synchronization metadata and `syncError` when a Live update fails.
98
+
99
+ Publishing an existing link without `--live` or `--snapshot` preserves its stored
100
+ mode. Use `--live` or `--snapshot` to switch deliberately; the URL does not change.
101
+ Links created before Live mode remain Snapshots until explicitly switched:
102
+
103
+ ```bash
104
+ mdedit article publish <articleId> --live
105
+ ```
106
+
107
+ If article creation succeeds but publishing fails, the article is kept private and
108
+ the command reports its article ID.
96
109
 
97
110
  ## Review commands
98
111
 
package/dist/index.js CHANGED
@@ -1587,7 +1587,7 @@ import { AgentClientHttpError } from "@mdedit/agent-client";
1587
1587
  // src/commands/article.ts
1588
1588
  init_dist();
1589
1589
  init_output();
1590
- import { Command } from "commander";
1590
+ import { Command, Option } from "commander";
1591
1591
  import inquirer from "inquirer";
1592
1592
  import { v4 as uuidv4 } from "uuid";
1593
1593
  import { readFile, writeFile } from "fs/promises";
@@ -1795,26 +1795,31 @@ function inferFileTitle(filePath, content) {
1795
1795
  const stem = (extension ? fileName.slice(0, -extension.length) : fileName).trim();
1796
1796
  return stem || void 0;
1797
1797
  }
1798
- function publishRequest(options) {
1798
+ function requestedPublicationMode(options) {
1799
+ if (options.live && options.snapshot) {
1800
+ throw new Error("--live and --snapshot are mutually exclusive. Choose one publication mode.");
1801
+ }
1802
+ if (options.snapshot) return "snapshot";
1803
+ if (options.live) return "live";
1804
+ return void 0;
1805
+ }
1806
+ function publishRequest(options, defaultMode) {
1799
1807
  const seoMetadata = {
1800
1808
  ...options.seoTitle ? { title: options.seoTitle } : {},
1801
1809
  ...options.seoDescription ? { description: options.seoDescription } : {}
1802
1810
  };
1811
+ const mode = requestedPublicationMode(options) ?? defaultMode;
1803
1812
  return {
1804
1813
  ...options.slug ? { customSlug: options.slug } : {},
1805
- ...Object.keys(seoMetadata).length > 0 ? { seoMetadata } : {}
1814
+ ...Object.keys(seoMetadata).length > 0 ? { seoMetadata } : {},
1815
+ ...mode ? { mode } : {}
1806
1816
  };
1807
1817
  }
1808
- async function confirmPublicPublish(articleId) {
1809
- const { confirm } = await inquirer.prompt([
1810
- {
1811
- type: "confirm",
1812
- name: "confirm",
1813
- message: `Publish article ${articleId} publicly? Anyone with the link will be able to view it.`,
1814
- default: false
1815
- }
1816
- ]);
1817
- return Boolean(confirm);
1818
+ async function agentPublishRequest(client, workspaceId, articleId, options) {
1819
+ const requestedMode = requestedPublicationMode(options);
1820
+ if (requestedMode) return publishRequest(options);
1821
+ const status = await client.publish.status(workspaceId, articleId);
1822
+ return publishRequest(options, status.isPublished ? void 0 : "live");
1818
1823
  }
1819
1824
  async function readEditOperations(filePath) {
1820
1825
  const raw = await readFile(filePath, "utf-8");
@@ -1884,7 +1889,7 @@ function createArticleCommands() {
1884
1889
  output.output(presentArticleDetails(result));
1885
1890
  output.info("Hint: use `mdedit article get <articleId> --content-only` to print markdown, or `--include-content` to include it in the output.");
1886
1891
  });
1887
- article.command("create").description("Create a new article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-i, --id <articleId>", "Article ID (defaults to a UUID)").option("-t, --title <title>", "Article title").option("-f, --folder <folderId>", "Folder ID").option("-c, --collaborative", "Enable collaborative editing").option("--file <path>", "Read initial article content from a file (use - for stdin)").option("--content <text>", "Set initial article content as an inline string").option("--publish", "Publish the created article to a public mded.it link").option("--slug <slug>", "Custom public-link slug (requires --publish)").option("--seo-title <title>", "SEO/social title for the public page (requires --publish)").option("--seo-description <description>", "SEO/social description for the public page (requires --publish)").option("-y, --yes", "Skip public-publishing confirmation").action(async (options) => {
1892
+ article.command("create").description("Create a new article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-i, --id <articleId>", "Article ID (defaults to a UUID)").option("-t, --title <title>", "Article title").option("-f, --folder <folderId>", "Folder ID").option("-c, --collaborative", "Enable collaborative editing").option("--file <path>", "Read initial article content from a file (use - for stdin)").option("--content <text>", "Set initial article content as an inline string").option("--publish", "Publish the created article to a live public mded.it link").option("--snapshot", "Publish a frozen snapshot instead of a live link (requires --publish)").option("--live", "Explicitly publish a live-updating link (requires --publish)").option("--slug <slug>", "Custom public-link slug (requires --publish)").option("--seo-title <title>", "SEO/social title for the public page (requires --publish)").option("--seo-description <description>", "SEO/social description for the public page (requires --publish)").addOption(new Option("-y, --yes").hideHelp()).action(async (options) => {
1888
1893
  requireAuthentication();
1889
1894
  const credentialProvider = getAgentCredentialProvider();
1890
1895
  const client = getApiClient();
@@ -1892,8 +1897,9 @@ function createArticleCommands() {
1892
1897
  if (options.content !== void 0 && options.file !== void 0) {
1893
1898
  throw new Error("--content and --file are mutually exclusive. Provide only one.");
1894
1899
  }
1895
- if (!options.publish && (options.slug || options.seoTitle || options.seoDescription)) {
1896
- throw new Error("--slug, --seo-title, and --seo-description require --publish.");
1900
+ requestedPublicationMode(options);
1901
+ if (!options.publish && (options.slug || options.seoTitle || options.seoDescription || options.snapshot || options.live)) {
1902
+ throw new Error("--slug, --seo-title, --seo-description, --snapshot, and --live require --publish.");
1897
1903
  }
1898
1904
  let contentText = null;
1899
1905
  if (options.content !== void 0) contentText = options.content;
@@ -1914,10 +1920,6 @@ function createArticleCommands() {
1914
1920
  title = String(answers.title);
1915
1921
  }
1916
1922
  const articleId = options.id || uuidv4();
1917
- if (options.publish && !options.yes && !await confirmPublicPublish(articleId)) {
1918
- output.info("Article creation cancelled; nothing was published.");
1919
- return;
1920
- }
1921
1923
  const created = await client.article.create(workspaceId, {
1922
1924
  articleId,
1923
1925
  title: String(title),
@@ -1996,7 +1998,7 @@ function createArticleCommands() {
1996
1998
  const publication = await client.publish.publish(
1997
1999
  workspaceId,
1998
2000
  articleId,
1999
- publishRequest(options)
2001
+ publishRequest(options, "live")
2000
2002
  );
2001
2003
  output.success("Article published publicly");
2002
2004
  output.output({
@@ -2047,18 +2049,14 @@ function createArticleCommands() {
2047
2049
  output.warning("No changes provided. Use --title, --archive, --pin, --file, or --content.");
2048
2050
  }
2049
2051
  });
2050
- article.command("publish <articleId>").description("Publish or update an article at a public mded.it link").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("--slug <slug>", "Custom public-link slug").option("--seo-title <title>", "SEO/social title for the public page").option("--seo-description <description>", "SEO/social description for the public page").option("-y, --yes", "Skip public-publishing confirmation").action(async (articleId, options) => {
2052
+ article.command("publish <articleId>").description("Publish or update an article at a public mded.it link").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("--slug <slug>", "Custom public-link slug").option("--seo-title <title>", "SEO/social title for the public page").option("--seo-description <description>", "SEO/social description for the public page").option("--snapshot", "Create or switch to a frozen snapshot").option("--live", "Create or switch to a live-updating public link").addOption(new Option("-y, --yes").hideHelp()).action(async (articleId, options) => {
2051
2053
  requireApiKey();
2052
2054
  const client = getApiClient();
2053
2055
  const workspaceId = requireWorkspaceId(options.workspace);
2054
- if (!options.yes && !await confirmPublicPublish(articleId)) {
2055
- output.info("Publish cancelled.");
2056
- return;
2057
- }
2058
2056
  const result = await client.publish.publish(
2059
2057
  workspaceId,
2060
2058
  articleId,
2061
- publishRequest(options)
2059
+ await agentPublishRequest(client, workspaceId, articleId, options)
2062
2060
  );
2063
2061
  output.success("Article published publicly");
2064
2062
  output.output(result);
@@ -2478,7 +2476,7 @@ function createConfigCommands() {
2478
2476
  config.command("login").description("Set API key authentication").option("-k, --api-key <key>", "API key").option("-u, --url <url>", "API URL").action(async (options) => {
2479
2477
  let apiKey = options.apiKey || process.env.MDEDIT_API_KEY;
2480
2478
  if (!apiKey) {
2481
- output.info("Get an API key: https://docs.mdedit.ai/api-keys");
2479
+ output.info("Get an API key: https://mdedit.ai/docs/api-keys");
2482
2480
  const answers = await inquirer4.prompt([
2483
2481
  {
2484
2482
  type: "password",