peakurl 0.3.0 → 0.3.2

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 (3) hide show
  1. package/README.md +5 -20
  2. package/bin/peakurl.js +139 -48
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # PeakURL - Command-Line Interface
2
2
 
3
+ ![PeakURL CLI](https://github.com/PeakURL/PeakURL/blob/main/.github/images/peakurl-cli.jpg?raw=1)
4
+
3
5
  The official command-line interface for PeakURL.
4
6
 
5
7
  Use `peakurl` to create short links, inspect existing links, and manage your PeakURL account from the terminal.
@@ -11,7 +13,7 @@ Learn more in the full CLI docs: <https://peakurl.org/docs/cli>
11
13
  Node.js 20 or later is required.
12
14
 
13
15
  ```bash
14
- npm install -g peakurl
16
+ npm i -g peakurl
15
17
  ```
16
18
 
17
19
  ## Quick Start
@@ -190,7 +192,7 @@ peakurl update
190
192
  Install the latest version manually:
191
193
 
192
194
  ```bash
193
- npm install -g peakurl@latest
195
+ npm i -g peakurl@latest
194
196
  ```
195
197
 
196
198
  Disable update notices in the current shell:
@@ -205,27 +207,10 @@ export PEAKURL_DISABLE_UPDATE_CHECK=1
205
207
  - `--json` prints machine-readable JSON where supported
206
208
  - `--quiet` minimizes output for scripts
207
209
 
208
- If you run an authenticated command before logging in, the CLI explains what to do next and shows the command to retry:
209
-
210
- ```text
211
- Authentication required.
212
- PeakURL could not find credentials for this command.
213
- Use one of the first two steps below, then run the last command.
214
- +---------------------------+-----------------------------------------------------+-----------------------------------------+
215
- | Step | Command | Notes |
216
- +---------------------------+-----------------------------------------------------+-----------------------------------------+
217
- | Save credentials | peakurl login --base-url https://example.com/api/v1 | Regular use on this machine |
218
- | | --api-key YOUR_API_KEY | |
219
- | Set environment variables | PEAKURL_BASE_URL=https://example.com/api/v1 | CI, scripts, or one-off use |
220
- | | PEAKURL_API_KEY=YOUR_API_KEY | |
221
- | Then run | peakurl whoami | After completing one of the steps above |
222
- +---------------------------+-----------------------------------------------------+-----------------------------------------+
223
- ```
224
-
225
210
  ## Links
226
211
 
227
212
  - Website: <https://peakurl.org/>
228
213
  - CLI docs: <https://peakurl.org/docs/cli>
229
214
  - API docs: <https://peakurl.org/docs/api>
230
215
  - npm package: <https://www.npmjs.com/package/peakurl>
231
- - Issues: <https://github.com/PeakURL/PeakURL-CLI/issues>
216
+ - Issues: <https://github.com/PeakURL/CLI/issues>
package/bin/peakurl.js CHANGED
@@ -1539,7 +1539,7 @@ function compareSemver(left, right) {
1539
1539
  return comparePrerelease(parsedLeft.prerelease, parsedRight.prerelease);
1540
1540
  }
1541
1541
  function getUpdateInstallCommand() {
1542
- return `npm install -g ${PACKAGE_NAME}@latest`;
1542
+ return `npm i -g ${PACKAGE_NAME}@latest`;
1543
1543
  }
1544
1544
  async function fetchLatestVersion(env) {
1545
1545
  const registryUrl = normalizeRegistryUrl(getRegistryBaseUrl(env));
@@ -2168,6 +2168,17 @@ function parseNumber(label) {
2168
2168
  return parsed;
2169
2169
  };
2170
2170
  }
2171
+ function addExamples(command, lines) {
2172
+ return command.addHelpText(
2173
+ "after",
2174
+ `
2175
+ Examples:
2176
+ ${lines.map((line) => ` ${line}`).join("\n")}
2177
+
2178
+ Documentation:
2179
+ https://peakurl.org/docs/cli`
2180
+ );
2181
+ }
2171
2182
  async function getCliVersion() {
2172
2183
  const packageJson = new URL("../package.json", import.meta.url);
2173
2184
  const content = await readFile3(packageJson, "utf8");
@@ -2190,23 +2201,26 @@ function getRetryCommandName(argv) {
2190
2201
  async function main() {
2191
2202
  const program = new Command();
2192
2203
  const version = await getCliVersion();
2193
- program.name("peakurl").description("PeakURL command-line interface").version(version).showHelpAfterError().showSuggestionAfterError().addHelpText(
2204
+ program.name("peakurl").description("Manage your PeakURL site from the terminal.").helpOption("-h, --help", "Show help").helpCommand("help [command]", "Show help for a command").version(version, "-V, --version", "Show CLI version").showHelpAfterError().showSuggestionAfterError().addHelpText(
2194
2205
  "after",
2195
2206
  `
2196
- Examples:
2197
- peakurl login --base-url https://example.com/api/v1 --api-key 0123456789abcdef0123456789abcdef0123456789abcdef
2198
- peakurl whoami --json
2199
- peakurl logout
2207
+ Get Started:
2208
+ peakurl login --base-url https://example.com/api/v1 --api-key YOUR_API_KEY
2209
+ peakurl whoami
2210
+ peakurl create https://example.com/docs --alias docs
2211
+
2212
+ Common Commands:
2200
2213
  peakurl status
2201
- peakurl create https://example.com --alias example
2214
+ peakurl list --limit 10
2202
2215
  peakurl import ./links.csv
2203
2216
  peakurl export --format csv
2204
- peakurl list --limit 10
2205
2217
  peakurl webhook list
2206
- peakurl webhook create https://example.com/api/webhooks/peakurl --event link.clicked
2207
2218
  peakurl update --check
2208
- peakurl get example
2209
- peakurl delete example --quiet`
2219
+
2220
+ Documentation:
2221
+ https://peakurl.org/docs/cli
2222
+
2223
+ Run 'peakurl <command> --help' for command-specific flags and examples.`
2210
2224
  ).exitOverride();
2211
2225
  program.hook("preAction", async (_command, actionCommand) => {
2212
2226
  const options = actionCommand.optsWithGlobals();
@@ -2217,43 +2231,120 @@ Examples:
2217
2231
  env: process.env
2218
2232
  });
2219
2233
  });
2220
- program.command("login").description(
2221
- "Save PeakURL credentials after verifying them with GET /users/me."
2222
- ).option(
2223
- "--base-url <url>",
2224
- "PeakURL API base URL, for example https://example.com/api/v1"
2225
- ).option("--api-key <token>", "PeakURL API key to store").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(login);
2226
- program.command("whoami").description("Show the current authenticated PeakURL user.").option("--json", "Print machine-readable output").option("--quiet", "Print a minimal identity value").action(whoami);
2227
- program.command("logout").description("Remove saved PeakURL credentials from this device.").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(logout);
2228
- program.command("status").description("Show the current PeakURL system status snapshot.").option("--json", "Print machine-readable output").option("--quiet", "Print only the overall health value").action(status);
2229
- program.command("create").description("Create a PeakURL short link.").argument("<url>", "Destination URL to shorten").option("--alias <alias>", "Custom alias for the short link").option("--title <title>", "Title to store with the short link").option("--password <password>", "Password-protect the short link").option(
2230
- "--status <status>",
2231
- "Link status, for example active or paused"
2232
- ).option("--expires-at <iso>", "Expiration timestamp in ISO-8601 format").option("--utm-source <value>", "UTM source").option("--utm-medium <value>", "UTM medium").option("--utm-campaign <value>", "UTM campaign").option("--utm-term <value>", "UTM term").option("--utm-content <value>", "UTM content").option("--json", "Print machine-readable output").option("--quiet", "Print only the created short URL").action(createLink);
2233
- program.command("import").description(
2234
- "Import multiple short links from a local CSV, JSON, or XML file."
2235
- ).argument("<file>", "Path to the import file").option("--format <format>", "File format: csv, json, or xml").option("--json", "Print machine-readable output").option("--quiet", "Print only the created short URLs").action(importLinks);
2236
- program.command("export").description(
2237
- "Export accessible links as a local CSV, JSON, or XML file."
2238
- ).option("--format <format>", "File format: csv, json, or xml").option("--output <path>", "Write the export to a specific file").option("--stdout", "Write the raw export content to stdout").option("--search <query>", "Search term").option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order, for example asc or desc").option("--quiet", "Print only the saved export path").action(exportLinks);
2239
- program.command("list").description("List PeakURL short links.").option("--page <number>", "Page number", parseNumber("page")).option("--limit <number>", "Page size", parseNumber("limit")).option("--search <query>", "Search term").option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order, for example asc or desc").option("--json", "Print machine-readable output").option("--quiet", "Print a minimal per-link value").action(listLinks);
2240
- program.command("get").description("Fetch a single PeakURL short link by id or alias.").argument("<id-or-alias>", "Link identifier or alias").option("--json", "Print machine-readable output").option("--quiet", "Print only the short URL").action(getLink);
2241
- program.command("delete").description("Delete a PeakURL short link by id or alias.").argument("<id-or-alias>", "Link identifier or alias").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(deleteLink);
2242
- program.command("update").description(
2243
- "Check for a newer CLI version and print the npm command to install it."
2244
- ).option(
2245
- "--check",
2246
- "Alias for checking update status without changing anything"
2247
- ).option("--json", "Print machine-readable output").option("--quiet", "Print minimal output").action((options) => checkUpdate(options, version));
2248
- const webhook = program.command("webhook").alias("webhooks").description("Manage outbound webhook integrations.");
2249
- webhook.command("list").description("List outbound webhooks.").option("--json", "Print machine-readable output").option("--quiet", "Print minimal webhook identifiers").action(listWebhooks);
2250
- webhook.command("create").description("Create an outbound webhook.").argument("<url>", "Webhook endpoint URL").option(
2251
- "--event <event>",
2252
- "Webhook event id, for example link.clicked",
2253
- parseWebhookEvents
2254
- ).option("--json", "Print machine-readable output").option("--quiet", "Print only the created webhook ID").action(createWebhook);
2255
- webhook.command("delete").description("Delete an outbound webhook by id.").argument("<id>", "Webhook identifier").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(deleteWebhook);
2256
- webhook.command("events").description("List the webhook events supported by the CLI.").option("--json", "Print machine-readable output").option("--quiet", "Print only event ids").action(listWebhookEvents);
2234
+ addExamples(
2235
+ program.command("login").summary("Save API credentials").description(
2236
+ "Save PeakURL credentials after verifying them with GET /users/me."
2237
+ ).helpOption("-h, --help", "Show help").option(
2238
+ "--base-url <url>",
2239
+ "PeakURL API base URL, for example https://example.com/api/v1"
2240
+ ).option("--api-key <token>", "PeakURL API key to store").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(login),
2241
+ [
2242
+ "peakurl login --base-url https://example.com/api/v1 --api-key YOUR_API_KEY",
2243
+ "peakurl login --json"
2244
+ ]
2245
+ );
2246
+ addExamples(
2247
+ program.command("whoami").summary("Show the current account").description("Show the current authenticated PeakURL user.").helpOption("-h, --help", "Show help").option("--json", "Print machine-readable output").option("--quiet", "Print a minimal identity value").action(whoami),
2248
+ ["peakurl whoami", "peakurl whoami --json"]
2249
+ );
2250
+ addExamples(
2251
+ program.command("logout").summary("Remove saved credentials").description("Remove saved PeakURL credentials from this device.").helpOption("-h, --help", "Show help").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(logout),
2252
+ ["peakurl logout", "peakurl logout --json"]
2253
+ );
2254
+ addExamples(
2255
+ program.command("status").summary("Show site system status").description("Show the current PeakURL system status snapshot.").helpOption("-h, --help", "Show help").option("--json", "Print machine-readable output").option("--quiet", "Print only the overall health value").action(status),
2256
+ ["peakurl status", "peakurl status --json", "peakurl status --quiet"]
2257
+ );
2258
+ addExamples(
2259
+ program.command("create").summary("Create a short link").description("Create a PeakURL short link.").helpOption("-h, --help", "Show help").argument("<url>", "Destination URL to shorten").option("--alias <alias>", "Custom alias for the short link").option("--title <title>", "Title to store with the short link").option("--password <password>", "Password-protect the short link").option(
2260
+ "--status <status>",
2261
+ "Link status, for example active or paused"
2262
+ ).option(
2263
+ "--expires-at <iso>",
2264
+ "Expiration timestamp in ISO-8601 format"
2265
+ ).option("--utm-source <value>", "UTM source").option("--utm-medium <value>", "UTM medium").option("--utm-campaign <value>", "UTM campaign").option("--utm-term <value>", "UTM term").option("--utm-content <value>", "UTM content").option("--json", "Print machine-readable output").option("--quiet", "Print only the created short URL").action(createLink),
2266
+ [
2267
+ "peakurl create https://example.com/docs --alias docs",
2268
+ 'peakurl create https://example.com/launch --title "Launch Page"',
2269
+ "peakurl create https://example.com --json"
2270
+ ]
2271
+ );
2272
+ addExamples(
2273
+ program.command("import").summary("Import links from a file").description(
2274
+ "Import multiple short links from a local CSV, JSON, or XML file."
2275
+ ).helpOption("-h, --help", "Show help").argument("<file>", "Path to the import file").option("--format <format>", "File format: csv, json, or xml").option("--json", "Print machine-readable output").option("--quiet", "Print only the created short URLs").action(importLinks),
2276
+ ["peakurl import ./links.csv", "peakurl import ./links.xml --json"]
2277
+ );
2278
+ addExamples(
2279
+ program.command("export").summary("Export links to a file").description(
2280
+ "Export accessible links as a local CSV, JSON, or XML file."
2281
+ ).helpOption("-h, --help", "Show help").option("--format <format>", "File format: csv, json, or xml").option("--output <path>", "Write the export to a specific file").option("--stdout", "Write the raw export content to stdout").option("--search <query>", "Search term").option("--sort-by <field>", "Sort field").option(
2282
+ "--sort-order <order>",
2283
+ "Sort order, for example asc or desc"
2284
+ ).option("--quiet", "Print only the saved export path").action(exportLinks),
2285
+ [
2286
+ "peakurl export --format csv",
2287
+ "peakurl export --format json --stdout",
2288
+ "peakurl export --format xml --output ./backups/links.xml"
2289
+ ]
2290
+ );
2291
+ addExamples(
2292
+ program.command("list").summary("List short links").description("List PeakURL short links.").helpOption("-h, --help", "Show help").option("--page <number>", "Page number", parseNumber("page")).option("--limit <number>", "Page size", parseNumber("limit")).option("--search <query>", "Search term").option("--sort-by <field>", "Sort field").option(
2293
+ "--sort-order <order>",
2294
+ "Sort order, for example asc or desc"
2295
+ ).option("--json", "Print machine-readable output").option("--quiet", "Print a minimal per-link value").action(listLinks),
2296
+ [
2297
+ "peakurl list",
2298
+ "peakurl list --limit 25 --page 1",
2299
+ "peakurl list --search launch --json"
2300
+ ]
2301
+ );
2302
+ addExamples(
2303
+ program.command("get").summary("Show one short link").description("Fetch a single PeakURL short link by id or alias.").helpOption("-h, --help", "Show help").argument("<id-or-alias>", "Link identifier or alias").option("--json", "Print machine-readable output").option("--quiet", "Print only the short URL").action(getLink),
2304
+ ["peakurl get docs", "peakurl get url_123 --json"]
2305
+ );
2306
+ addExamples(
2307
+ program.command("delete").summary("Delete one short link").description("Delete a PeakURL short link by id or alias.").helpOption("-h, --help", "Show help").argument("<id-or-alias>", "Link identifier or alias").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(deleteLink),
2308
+ ["peakurl delete docs", "peakurl delete url_123 --quiet"]
2309
+ );
2310
+ addExamples(
2311
+ program.command("update").summary("Check for CLI updates").description(
2312
+ "Check for a newer CLI version and print the npm command to install it."
2313
+ ).helpOption("-h, --help", "Show help").option(
2314
+ "--check",
2315
+ "Alias for checking update status without changing anything"
2316
+ ).option("--json", "Print machine-readable output").option("--quiet", "Print minimal output").action((options) => checkUpdate(options, version)),
2317
+ ["peakurl update", "peakurl update --check", "peakurl update --json"]
2318
+ );
2319
+ const webhook = program.command("webhook").alias("webhooks").summary("Manage webhooks").helpOption("-h, --help", "Show help").description("Manage outbound webhook integrations.");
2320
+ addExamples(webhook, [
2321
+ "peakurl webhook list",
2322
+ "peakurl webhook create https://example.com/api/webhooks/peakurl --event link.clicked",
2323
+ "peakurl webhook events"
2324
+ ]);
2325
+ addExamples(
2326
+ webhook.command("list").summary("List webhooks").description("List outbound webhooks.").helpOption("-h, --help", "Show help").option("--json", "Print machine-readable output").option("--quiet", "Print minimal webhook identifiers").action(listWebhooks),
2327
+ ["peakurl webhook list", "peakurl webhook list --json"]
2328
+ );
2329
+ addExamples(
2330
+ webhook.command("create").summary("Create a webhook").description("Create an outbound webhook.").helpOption("-h, --help", "Show help").argument("<url>", "Webhook endpoint URL").option(
2331
+ "--event <event>",
2332
+ "Webhook event id, for example link.clicked",
2333
+ parseWebhookEvents
2334
+ ).option("--json", "Print machine-readable output").option("--quiet", "Print only the created webhook ID").action(createWebhook),
2335
+ [
2336
+ "peakurl webhook create https://example.com/api/webhooks/peakurl --event link.clicked",
2337
+ "peakurl webhook create https://example.com/api/webhooks/peakurl --event link.clicked --event link.created"
2338
+ ]
2339
+ );
2340
+ addExamples(
2341
+ webhook.command("delete").summary("Delete a webhook").description("Delete an outbound webhook by id.").helpOption("-h, --help", "Show help").argument("<id>", "Webhook identifier").option("--json", "Print machine-readable output").option("--quiet", "Suppress success output").action(deleteWebhook),
2342
+ ["peakurl webhook delete webhook_123"]
2343
+ );
2344
+ addExamples(
2345
+ webhook.command("events").summary("List supported events").description("List the webhook events supported by the CLI.").helpOption("-h, --help", "Show help").option("--json", "Print machine-readable output").option("--quiet", "Print only event ids").action(listWebhookEvents),
2346
+ ["peakurl webhook events", "peakurl webhook events --json"]
2347
+ );
2257
2348
  try {
2258
2349
  await program.parseAsync(process.argv);
2259
2350
  } catch (error) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "peakurl",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Official CLI for creating, listing, and managing PeakURL short links from the terminal",
5
5
  "homepage": "https://peakurl.org",
6
6
  "bugs": {
7
- "url": "https://github.com/PeakURL/PeakURL-CLI/issues"
7
+ "url": "https://github.com/PeakURL/CLI/issues"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/PeakURL/PeakURL-CLI.git"
11
+ "url": "git+https://github.com/PeakURL/CLI.git"
12
12
  },
13
13
  "keywords": [
14
14
  "peakurl",