@fedify/cli 2.0.7 → 2.0.9

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/relay.js CHANGED
@@ -1,24 +1,21 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { configContext } from "./config.js";
5
3
  import { configureLogging } from "./log.js";
6
4
  import { createTunnelOption } from "./options.js";
7
5
  import { tableStyle } from "./table.js";
8
6
  import { spawnTemporaryServer } from "./tempserver.js";
9
7
  import { colors, matchesActor } from "./utils.js";
10
- import { SqliteKvStore } from "@fedify/sqlite";
11
- import process from "node:process";
12
- import { DatabaseSync } from "node:sqlite";
13
8
  import { command, constant, group, integer, merge, message, multiple, object, option, optionName, optional, string, value } from "@optique/core";
9
+ import process from "node:process";
14
10
  import { bindConfig } from "@optique/config";
15
11
  import { MemoryKvStore } from "@fedify/fedify";
16
12
  import { getLogger } from "@logtape/logtape";
17
13
  import Table from "cli-table3";
18
14
  import ora from "ora";
19
15
  import { createRelay } from "@fedify/relay";
16
+ import { SqliteKvStore } from "@fedify/sqlite";
20
17
  import { choice as choice$1 } from "@optique/core/valueparser";
21
-
18
+ import { DatabaseSync } from "node:sqlite";
22
19
  //#region src/relay.ts
23
20
  const logger = getLogger([
24
21
  "fedify",
@@ -66,17 +63,16 @@ const relayCommand = command("relay", merge(object("Relay options", {
66
63
 
67
64
  By default, the server is tunneled to the public internet for external access. Use ${optionName("--no-tunnel")} to run locally only.`
68
65
  });
69
- async function runRelay(command$1) {
70
- if (command$1.debug) await configureLogging();
66
+ async function runRelay(command) {
67
+ if (command.debug) await configureLogging();
71
68
  const spinner = ora({
72
69
  text: "Starting relay server...",
73
70
  discardStdin: false
74
71
  }).start();
75
72
  let kv;
76
- if (command$1.persistent) {
77
- logger.debug("Using SQLite storage at {path}.", { path: command$1.persistent });
78
- const db = new DatabaseSync(command$1.persistent);
79
- kv = new SqliteKvStore(db);
73
+ if (command.persistent) {
74
+ logger.debug("Using SQLite storage at {path}.", { path: command.persistent });
75
+ kv = new SqliteKvStore(new DatabaseSync(command.persistent));
80
76
  } else {
81
77
  logger.debug("Using in-memory storage.");
82
78
  kv = new MemoryKvStore();
@@ -85,18 +81,18 @@ async function runRelay(command$1) {
85
81
  let server = null;
86
82
  const acceptFollows = [];
87
83
  const rejectFollows = [];
88
- if (command$1.acceptFollow != null && command$1.acceptFollow.length > 0) acceptFollows.push(...command$1.acceptFollow ?? []);
89
- if (command$1.rejectFollow != null && command$1.rejectFollow.length > 0) rejectFollows.push(...command$1.rejectFollow ?? []);
84
+ if (command.acceptFollow != null && command.acceptFollow.length > 0) acceptFollows.push(...command.acceptFollow ?? []);
85
+ if (command.rejectFollow != null && command.rejectFollow.length > 0) rejectFollows.push(...command.rejectFollow ?? []);
90
86
  server = await spawnTemporaryServer(async (request) => {
91
87
  return await relay.fetch(request);
92
88
  }, {
93
- noTunnel: !command$1.tunnel,
94
- port: command$1.port,
95
- ...command$1.tunnel && { service: command$1.tunnelService }
89
+ noTunnel: !command.tunnel,
90
+ port: command.port,
91
+ ...command.tunnel && { service: command.tunnelService }
96
92
  });
97
- relay = createRelay(command$1.protocol, {
93
+ relay = createRelay(command.protocol, {
98
94
  origin: server?.url.origin,
99
- name: command$1.name,
95
+ name: command.name,
100
96
  kv,
101
97
  subscriptionHandler: async (_ctx, actor) => {
102
98
  const isInAcceptList = await matchesActor(actor, acceptFollows);
@@ -106,9 +102,9 @@ async function runRelay(command$1) {
106
102
  });
107
103
  spinner.succeed(`Relay server is running: ${colors.green(server.url.href)}`);
108
104
  await printRelayInfo(relay, {
109
- protocol: command$1.protocol,
110
- name: command$1.name,
111
- persistent: command$1.persistent
105
+ protocol: command.protocol,
106
+ name: command.name,
107
+ persistent: command.persistent
112
108
  });
113
109
  process.on("SIGINT", async () => {
114
110
  spinner.start("Shutting down relay server...");
@@ -131,6 +127,5 @@ async function printRelayInfo(relay, options) {
131
127
  console.log(table.toString());
132
128
  console.log("\nPress ^C to stop the relay server.");
133
129
  }
134
-
135
130
  //#endregion
136
- export { relayCommand, runRelay };
131
+ export { relayCommand, runRelay };
package/dist/table.js CHANGED
@@ -1,6 +1,4 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  //#region src/table.ts
5
3
  const tableStyle = {
6
4
  top: "─",
@@ -19,6 +17,5 @@ const tableStyle = {
19
17
  rightMid: "┤",
20
18
  middle: "│"
21
19
  };
22
-
23
20
  //#endregion
24
- export { tableStyle };
21
+ export { tableStyle };
@@ -1,10 +1,7 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { getLogger } from "@logtape/logtape";
5
3
  import { openTunnel } from "@hongminhee/localtunnel";
6
4
  import { serve } from "srvx";
7
-
8
5
  //#region src/tempserver.ts
9
6
  const logger = getLogger([
10
7
  "fedify",
@@ -14,28 +11,27 @@ const logger = getLogger([
14
11
  async function spawnTemporaryServer(fetch, options = {}) {
15
12
  const serverPort = options.port ?? 0;
16
13
  if (options.noTunnel) {
17
- const server$1 = serve({
14
+ const server = serve({
18
15
  port: serverPort,
19
16
  hostname: "::",
20
17
  silent: true,
21
18
  fetch
22
19
  });
23
- await server$1.ready();
24
- const url$1 = new URL(server$1.url);
25
- const port$1 = url$1.port;
26
- logger.debug("Temporary server is listening on port {port}.", { port: port$1 });
20
+ await server.ready();
21
+ const port = new URL(server.url).port;
22
+ logger.debug("Temporary server is listening on port {port}.", { port });
27
23
  return {
28
- url: new URL(`http://localhost:${port$1}`),
24
+ url: new URL(`http://localhost:${port}`),
29
25
  async close() {
30
- await server$1.close();
26
+ await server.close();
31
27
  }
32
28
  };
33
29
  }
34
30
  const server = serve({
35
31
  fetch: "Deno" in globalThis ? (request) => {
36
- const url$1 = new URL(request.url);
37
- url$1.protocol = "https:";
38
- const newRequest = new Request(url$1, {
32
+ const url = new URL(request.url);
33
+ url.protocol = "https:";
34
+ return fetch(new Request(url, {
39
35
  method: request.method,
40
36
  headers: request.headers,
41
37
  body: request.method === "GET" || request.method === "HEAD" ? null : request.body,
@@ -48,8 +44,7 @@ async function spawnTemporaryServer(fetch, options = {}) {
48
44
  integrity: request.integrity,
49
45
  keepalive: request.keepalive,
50
46
  signal: request.signal
51
- });
52
- return fetch(newRequest);
47
+ }));
53
48
  } : fetch,
54
49
  port: serverPort,
55
50
  hostname: "::",
@@ -57,8 +52,7 @@ async function spawnTemporaryServer(fetch, options = {}) {
57
52
  protocol: "https"
58
53
  });
59
54
  await server.ready();
60
- const url = new URL(server.url);
61
- const port = url.port;
55
+ const port = new URL(server.url).port;
62
56
  logger.debug("Temporary server is listening on port {port}.", { port });
63
57
  const tun = await openTunnel({
64
58
  port: parseInt(port),
@@ -73,6 +67,5 @@ async function spawnTemporaryServer(fetch, options = {}) {
73
67
  }
74
68
  };
75
69
  }
76
-
77
70
  //#endregion
78
- export { spawnTemporaryServer };
71
+ export { spawnTemporaryServer };
package/dist/tunnel.js CHANGED
@@ -1,14 +1,11 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { configureLogging } from "./log.js";
5
3
  import { createTunnelServiceOption } from "./options.js";
6
- import process from "node:process";
7
4
  import { argument, command, constant, integer, merge, message, object } from "@optique/core";
8
5
  import { print, printError } from "@optique/run";
6
+ import process from "node:process";
9
7
  import ora from "ora";
10
8
  import { openTunnel } from "@hongminhee/localtunnel";
11
-
12
9
  //#region src/tunnel.ts
13
10
  const tunnelCommand = command("tunnel", merge("Tunnel options", object({ command: constant("tunnel") }), object({
14
11
  port: argument(integer({
@@ -23,12 +20,12 @@ const tunnelCommand = command("tunnel", merge("Tunnel options", object({ command
23
20
 
24
21
  Note that the HTTP requests through the tunnel have X-Forwarded-* headers.`
25
22
  });
26
- async function runTunnel(command$1, deps = {
23
+ async function runTunnel(command, deps = {
27
24
  openTunnel,
28
25
  ora,
29
26
  exit: process.exit
30
27
  }) {
31
- if (command$1.debug) await configureLogging();
28
+ if (command.debug) await configureLogging();
32
29
  const spinner = deps.ora({
33
30
  text: "Creating a secure tunnel...",
34
31
  discardStdin: false
@@ -36,21 +33,20 @@ async function runTunnel(command$1, deps = {
36
33
  let tunnel;
37
34
  try {
38
35
  tunnel = await deps.openTunnel({
39
- port: command$1.port,
40
- service: command$1.service
36
+ port: command.port,
37
+ service: command.service
41
38
  });
42
39
  } catch (error) {
43
- if (command$1.debug) printError(message`${String(error)}`);
40
+ if (command.debug) printError(message`${String(error)}`);
44
41
  spinner.fail("Failed to create a secure tunnel.");
45
42
  deps.exit(1);
46
43
  }
47
- spinner.succeed(`Your local server at ${command$1.port} is now publicly accessible:\n`);
44
+ spinner.succeed(`Your local server at ${command.port} is now publicly accessible:\n`);
48
45
  print(message`${tunnel.url.href}`);
49
46
  print(message`\nPress ^C to close the tunnel.`);
50
47
  process.on("SIGINT", async () => {
51
48
  await tunnel.close();
52
49
  });
53
50
  }
54
-
55
51
  //#endregion
56
- export { runTunnel, tunnelCommand };
52
+ export { runTunnel, tunnelCommand };
package/dist/utils.js CHANGED
@@ -1,23 +1,18 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
4
- import "node:fs/promises";
5
- import process from "node:process";
1
+ import "@js-temporal/polyfill";
6
2
  import { message } from "@optique/core";
7
3
  import { print, printError } from "@optique/run";
8
4
  import { flow } from "es-toolkit";
5
+ import process from "node:process";
9
6
  import { getActorHandle } from "@fedify/vocab";
10
7
  import util from "node:util";
11
8
  import "@fxts/core";
12
9
  import { Chalk } from "chalk";
13
10
  import { highlight } from "cli-highlight";
14
- import "node:child_process";
15
-
16
11
  //#region src/utils.ts
17
12
  const colorEnabled = process.stdout.isTTY && !("NO_COLOR" in process.env && process.env.NO_COLOR !== "");
18
13
  const colors = new Chalk(colorEnabled ? {} : { level: 0 });
19
- function formatObject(obj, colors$1, json) {
20
- const enableColors = colors$1 ?? colorEnabled;
14
+ function formatObject(obj, colors, json) {
15
+ const enableColors = colors ?? colorEnabled;
21
16
  if (!json) return util.inspect(obj, { colors: enableColors });
22
17
  const formatted = JSON.stringify(obj, null, 2);
23
18
  if (enableColors) return highlight(formatted, { language: "json" });
@@ -38,8 +33,7 @@ async function matchesActor(actor, actorList) {
38
33
  }
39
34
  return false;
40
35
  }
41
- const printMessage = flow(message, print);
42
- const printErrorMessage = flow(message, printError);
43
-
36
+ flow(message, print);
37
+ flow(message, printError);
44
38
  //#endregion
45
- export { colorEnabled, colors, formatObject, matchesActor };
39
+ export { colorEnabled, colors, formatObject, matchesActor };
@@ -1,6 +1,4 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { formatObject } from "../utils.js";
5
3
  import { NotFoundError, getErrorMessage } from "./error.js";
6
4
  import { convertUrlIfHandle } from "./lib.js";
@@ -8,18 +6,15 @@ import { print } from "@optique/run";
8
6
  import { formatMessage, message } from "@optique/core/message";
9
7
  import ora from "ora";
10
8
  import { lookupWebFinger } from "@fedify/webfinger";
11
-
12
9
  //#region src/webfinger/action.ts
13
- async function runWebFinger({ command: _, resources,...options }) {
10
+ async function runWebFinger({ command: _, resources, ...options }) {
14
11
  await Array.fromAsync(resources.map((resource) => ({
15
12
  resource,
16
13
  ...options
17
14
  })), spinnerWrapper(lookupSingleWebFinger));
18
15
  }
19
- async function lookupSingleWebFinger({ resource,...options }) {
20
- const url = convertUrlIfHandle(resource);
21
- const webFinger = await lookupWebFinger(url, options) ?? new NotFoundError(resource).throw();
22
- return webFinger;
16
+ async function lookupSingleWebFinger({ resource, ...options }) {
17
+ return await lookupWebFinger(convertUrlIfHandle(resource), options) ?? new NotFoundError(resource).throw();
23
18
  }
24
19
  function spinnerWrapper(func) {
25
20
  return async (...args) => {
@@ -39,6 +34,5 @@ function spinnerWrapper(func) {
39
34
  }
40
35
  };
41
36
  }
42
-
43
37
  //#endregion
44
- export { runWebFinger };
38
+ export { runWebFinger as default };
@@ -1,11 +1,8 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { configContext } from "../config.js";
5
3
  import { userAgentOption } from "../options.js";
6
4
  import { argument, command, constant, flag, group, integer, merge, message, multiple, object, option, string } from "@optique/core";
7
5
  import { bindConfig } from "@optique/config";
8
-
9
6
  //#region src/webfinger/command.ts
10
7
  const allowPrivateAddresses = bindConfig(flag("-p", "--allow-private-address", { description: message`Allow private IP addresses in the URL.` }), {
11
8
  context: configContext,
@@ -28,6 +25,5 @@ const webFingerCommand = command("webfinger", merge("Network options", object({
28
25
 
29
26
  The argument can be multiple.`
30
27
  });
31
-
32
28
  //#endregion
33
- export { webFingerCommand };
29
+ export { webFingerCommand };
@@ -1,8 +1,5 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { message } from "@optique/core";
5
-
6
3
  //#region src/webfinger/error.ts
7
4
  /**
8
5
  * Generates a user-friendly error message based on the type of error
@@ -42,6 +39,5 @@ var NotFoundError = class extends Error {
42
39
  throw this;
43
40
  }
44
41
  };
45
-
46
42
  //#endregion
47
- export { InvalidHandleError, NotFoundError, getErrorMessage };
43
+ export { InvalidHandleError, NotFoundError, getErrorMessage };
@@ -1,12 +1,8 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
1
+ import "@js-temporal/polyfill";
4
2
  import { InvalidHandleError } from "./error.js";
5
3
  import { toAcctUrl } from "@fedify/vocab";
6
4
  import { getLogger } from "@logtape/logtape";
7
-
8
- //#region src/webfinger/lib.ts
9
- const logger = getLogger([
5
+ getLogger([
10
6
  "fedify",
11
7
  "cli",
12
8
  "webfinger"
@@ -40,6 +36,5 @@ function convertUrlIfHandle(handleOrUrl) {
40
36
  function convertHandleToUrl(handle) {
41
37
  return toAcctUrl(handle) ?? new InvalidHandleError(handle).throw();
42
38
  }
43
-
44
39
  //#endregion
45
- export { convertUrlIfHandle };
40
+ export { convertUrlIfHandle };
@@ -1,5 +1,4 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
-
4
- import { runWebFinger } from "./action.js";
5
- import { webFingerCommand } from "./command.js";
1
+ import "@js-temporal/polyfill";
2
+ import "./action.js";
3
+ import "./command.js";
4
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -86,20 +86,20 @@
86
86
  "smol-toml": "^1.6.0",
87
87
  "srvx": "^0.8.7",
88
88
  "valibot": "^1.2.0",
89
- "@fedify/fedify": "2.0.7",
90
- "@fedify/init": "2.0.7",
91
- "@fedify/relay": "2.0.7",
92
- "@fedify/sqlite": "2.0.7",
93
- "@fedify/vocab": "2.0.7",
94
- "@fedify/webfinger": "2.0.7",
95
- "@fedify/vocab-tools": "2.0.7",
96
- "@fedify/vocab-runtime": "2.0.7"
89
+ "@fedify/fedify": "2.0.9",
90
+ "@fedify/sqlite": "2.0.9",
91
+ "@fedify/relay": "2.0.9",
92
+ "@fedify/init": "2.0.9",
93
+ "@fedify/vocab": "2.0.9",
94
+ "@fedify/vocab-tools": "2.0.9",
95
+ "@fedify/vocab-runtime": "2.0.9",
96
+ "@fedify/webfinger": "2.0.9"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@types/bun": "^1.2.23",
100
100
  "@types/node": "^22.17.0",
101
- "tsdown": "^0.12.9",
102
- "typescript": "^5.9.3"
101
+ "tsdown": "^0.21.6",
102
+ "typescript": "^5.9.2"
103
103
  },
104
104
  "scripts": {
105
105
  "build:self": "tsdown",