asyx 0.10.1 → 0.11.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.
- package/AGENTS.md +42 -0
- package/bin/asyx.js +1 -1
- package/package.json +3 -2
- package/src/commands/account.js +80 -71
- package/src/commands/app.js +317 -151
- package/src/commands/in-use-messages.js +47 -48
- package/src/commands/mqtt-broker.js +36 -49
- package/src/commands/mqtt.js +111 -149
- package/src/commands/name.js +24 -22
- package/src/commands/reject-messages.js +123 -123
- package/src/commands/setup.js +107 -131
- package/src/commands/sts.js +45 -61
- package/src/commands/tunnel.js +853 -932
- package/src/commands/validate-target-host.js +36 -59
- package/src/lib/aws-iot-config.js +26 -24
- package/src/lib/certs.js +15 -18
- package/src/lib/csr.js +107 -182
- package/src/lib/device.js +26 -37
- package/src/lib/ids.js +1 -2
- package/src/lib/naming.js +74 -68
- package/src/lib/pairing.js +10 -11
- package/src/lib/shared-transport.js +5 -9
- package/src/main.js +63 -53
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.js +25 -287
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.js +0 -72
- package/vendor/tunnel-core/dist/control-plane/session.js +0 -20
- package/vendor/tunnel-core/dist/errors.js +0 -19
- package/vendor/tunnel-core/dist/flows/account.js +1 -6
- package/vendor/tunnel-core/dist/flows/goodbye.js +0 -4
- package/vendor/tunnel-core/dist/flows/http.js +24 -112
- package/vendor/tunnel-core/dist/flows/identity.js +11 -10
- package/vendor/tunnel-core/dist/flows/in-use.js +0 -6
- package/vendor/tunnel-core/dist/flows/reopen.js +0 -4
- package/vendor/tunnel-core/dist/flows/tcp.js +18 -84
- package/vendor/tunnel-core/dist/flows/udp.js +15 -52
- package/vendor/tunnel-core/dist/lib/fingerprint.js +38 -42
- package/vendor/tunnel-core/dist/lib/jwt-verifier.js +14 -67
- package/vendor/tunnel-core/dist/lib/logger.js +1 -9
- package/vendor/tunnel-core/dist/lib/refresh-helpers.js +1 -22
- package/vendor/tunnel-core/dist/lifecycle.js +1 -8
- package/vendor/tunnel-core/dist/mqtt/awaiter-map.js +1 -53
- package/vendor/tunnel-core/dist/mqtt/events/handlers.js +10 -64
- package/vendor/tunnel-core/dist/mqtt/events/index.js +3 -36
- package/vendor/tunnel-core/dist/mqtt/events/schemas.js +0 -1
- package/vendor/tunnel-core/dist/mqtt/ingress.js +0 -60
- package/vendor/tunnel-core/dist/state/assignment.js +6 -122
- package/vendor/tunnel-core/dist/state/instance-registry.js +0 -63
- package/vendor/tunnel-core/dist/tcp-v1/framing.js +2 -64
- package/vendor/tunnel-core/dist/tunnel/http-tunnel.js +64 -331
- package/vendor/tunnel-core/dist/tunnel/httpws-constants.js +5 -14
- package/vendor/tunnel-core/dist/tunnel/reconnect.js +10 -50
- package/vendor/tunnel-core/dist/tunnel/request-sink.js +0 -16
- package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.js +32 -195
- package/vendor/tunnel-core/dist/tunnel/udp-tunnel.js +28 -153
- package/vendor/tunnel-core/dist/tunnel/ws-control.js +4 -39
- package/vendor/tunnel-core/dist/types.js +0 -2
- package/vendor/tunnel-core/dist/udp-v1/framing.js +2 -64
- package/vendor/tunnel-core/package.json +0 -25
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.d.ts +0 -273
- package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.d.ts +0 -79
- package/vendor/tunnel-core/dist/control-plane/session.d.ts +0 -55
- package/vendor/tunnel-core/dist/errors.d.ts +0 -49
- package/vendor/tunnel-core/dist/flows/account.d.ts +0 -24
- package/vendor/tunnel-core/dist/flows/goodbye.d.ts +0 -10
- package/vendor/tunnel-core/dist/flows/http.d.ts +0 -61
- package/vendor/tunnel-core/dist/flows/identity.d.ts +0 -23
- package/vendor/tunnel-core/dist/flows/in-use.d.ts +0 -27
- package/vendor/tunnel-core/dist/flows/reopen.d.ts +0 -9
- package/vendor/tunnel-core/dist/flows/tcp.d.ts +0 -85
- package/vendor/tunnel-core/dist/flows/udp.d.ts +0 -52
- package/vendor/tunnel-core/dist/lib/adapt-logger.d.ts +0 -2
- package/vendor/tunnel-core/dist/lib/fingerprint.d.ts +0 -145
- package/vendor/tunnel-core/dist/lib/jwt-verifier.d.ts +0 -27
- package/vendor/tunnel-core/dist/lib/logger.d.ts +0 -9
- package/vendor/tunnel-core/dist/lib/refresh-helpers.d.ts +0 -16
- package/vendor/tunnel-core/dist/lifecycle.d.ts +0 -24
- package/vendor/tunnel-core/dist/mqtt/awaiter-map.d.ts +0 -56
- package/vendor/tunnel-core/dist/mqtt/events/handlers.d.ts +0 -60
- package/vendor/tunnel-core/dist/mqtt/events/index.d.ts +0 -1
- package/vendor/tunnel-core/dist/mqtt/events/schemas.d.ts +0 -498
- package/vendor/tunnel-core/dist/mqtt/ingress.d.ts +0 -63
- package/vendor/tunnel-core/dist/state/assignment.d.ts +0 -136
- package/vendor/tunnel-core/dist/state/instance-registry.d.ts +0 -88
- package/vendor/tunnel-core/dist/tcp-v1/framing.d.ts +0 -43
- package/vendor/tunnel-core/dist/tunnel/http-tunnel.d.ts +0 -140
- package/vendor/tunnel-core/dist/tunnel/httpws-constants.d.ts +0 -13
- package/vendor/tunnel-core/dist/tunnel/reconnect.d.ts +0 -76
- package/vendor/tunnel-core/dist/tunnel/request-sink.d.ts +0 -40
- package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.d.ts +0 -92
- package/vendor/tunnel-core/dist/tunnel/udp-tunnel.d.ts +0 -93
- package/vendor/tunnel-core/dist/tunnel/ws-control.d.ts +0 -22
- package/vendor/tunnel-core/dist/types.d.ts +0 -24
- package/vendor/tunnel-core/dist/udp-v1/framing.d.ts +0 -41
package/AGENTS.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Asyx tunnels from code: instructions for coding agents
|
|
2
|
+
|
|
3
|
+
Use these rules when you add an Asyx tunnel to a project with `@asyx/tunnel` or the `asyx` CLI.
|
|
4
|
+
|
|
5
|
+
## Create the app identity (once, on a set-up computer)
|
|
6
|
+
|
|
7
|
+
asyx app create <name> # new address <name>.tunnel.asyx.ai
|
|
8
|
+
asyx app create <name> --address fast # or pin it to an existing address of the account
|
|
9
|
+
|
|
10
|
+
This writes `asyx.json` (no secrets) in the project and keeps the credentials in
|
|
11
|
+
`~/.asyx/apps/<appId>/` on this computer only.
|
|
12
|
+
|
|
13
|
+
## Credentials: never in the project
|
|
14
|
+
|
|
15
|
+
- Never copy the private key into the repository, a `.env` file that is committed, logs, issues or chat.
|
|
16
|
+
- Never print the key. `asyx app export <name>` refuses to print to a terminal without `--print`.
|
|
17
|
+
- Hand credentials to a server with `asyx app export <name> --out <path>` (an owner-only file) or a
|
|
18
|
+
pipe into your secret store, then set `ASYX_CREDENTIALS` to that JSON (or to the file's path).
|
|
19
|
+
- `asyx.json` is safe to commit: it names the app and its address only.
|
|
20
|
+
|
|
21
|
+
## When an app is revoked or deleted
|
|
22
|
+
|
|
23
|
+
- `asyx app list` shows each app's state as the service knows it: active, revoked or deleted.
|
|
24
|
+
- A revoked app can no longer open tunnels; `asyx tunnel --app` says so (the SDK reports a refused connection). Replace it with
|
|
25
|
+
`asyx app create <new-name> --address <its address> --replace` (the address moves to the new app), then delete the old one in the console.
|
|
26
|
+
- A deleted app's credentials are removed from this computer the next time any `asyx app` command runs;
|
|
27
|
+
`asyx app forget <name>` removes them at once. `asyx.json` in the project is left alone.
|
|
28
|
+
|
|
29
|
+
## Open the tunnel
|
|
30
|
+
|
|
31
|
+
import { Asyx } from '@asyx/tunnel';
|
|
32
|
+
const asyx = await Asyx.connect({ credentials: Asyx.credentialsFromEnv() });
|
|
33
|
+
const tunnel = await asyx.http({ port: 3000 }); // serves https://<the app's address>
|
|
34
|
+
// ...
|
|
35
|
+
await tunnel.close(); // releases the lease at once
|
|
36
|
+
|
|
37
|
+
- An app serves only its own address. Passing another `hostname` throws `HostnameNotAssignedError`.
|
|
38
|
+
- If the address already has a live tunnel, `http()` throws `AddressInUseError` (see `error.details`);
|
|
39
|
+
pass `replace: true` only when taking over is intended.
|
|
40
|
+
- The SDK never calls `process.exit` and never logs credentials or request bodies. Pass a `logger` to see
|
|
41
|
+
what it does; it is quiet by default.
|
|
42
|
+
- Port mode only: your app keeps listening on its own port; the tunnel forwards to `localhost:<port>`.
|
package/bin/asyx.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import('../src/main.js');
|
|
2
|
+
import('../src/main.js');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asyx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Asyx tunnel CLI — secure localhost exposure (HTTP, TCP, UDP)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"src/lib/pairing.js",
|
|
51
51
|
"src/lib/shared-transport.js",
|
|
52
52
|
"src/main.js",
|
|
53
|
+
"AGENTS.md",
|
|
53
54
|
"LICENSE",
|
|
54
55
|
"README.md",
|
|
55
56
|
"SECURITY.md",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"test:ci": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand --forceExit",
|
|
80
81
|
"test:e2e:httpwsv2": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand --testPathIgnorePatterns=/node_modules/ --testMatch='**/test/e2e/**/*.e2e.test.js'",
|
|
81
82
|
"pack:verify": "node scripts/pack-verify.mjs",
|
|
82
|
-
"prepublishOnly": "npm run test:ci && npm run pack:verify && npm run release:smoke",
|
|
83
|
+
"prepublishOnly": "npm run test:ci -- --silent --reporters=summary && npm run pack:verify && npm run release:smoke",
|
|
83
84
|
"prepack": "node scripts/prepack.mjs",
|
|
84
85
|
"postpack": "node scripts/postpack.mjs",
|
|
85
86
|
"test:characterization": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand test/characterization",
|
package/src/commands/account.js
CHANGED
|
@@ -1,86 +1,95 @@
|
|
|
1
|
-
// Story 2.11 c1/c3 from the CLI (owner decision 2026-11-27): `asyx name add <name>` and
|
|
2
|
-
// `asyx port release --tcp|--udp <port>`, sent over this device's own certificate connection. The
|
|
3
|
-
// service checks the certificate, allows devices only, keeps the plan's address limit and releases only
|
|
4
|
-
// a port that is not live. Deleting an address stays in the console.
|
|
5
|
-
// exit 0 done, 1 refused or failed, 2 usage, 3 the name is not available (name add)
|
|
6
1
|
import { normalizeLabel, describeAnswer, EXIT } from '../lib/naming.js';
|
|
7
|
-
|
|
8
2
|
const CONSOLE = 'asyx.ai/console/tunnel';
|
|
9
|
-
|
|
10
3
|
async function loadCredentials() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const { loadAwsIotConfig } = await import('../lib/aws-iot-config.js');
|
|
5
|
+
const { readFileSync } = await import('node:fs');
|
|
6
|
+
const cfg = await loadAwsIotConfig();
|
|
7
|
+
return { endpoint: cfg.endpoint, clientId: cfg.clientId, ca: readFileSync(cfg.caPath), cert: readFileSync(cfg.certPath), key: readFileSync(cfg.keyPath) };
|
|
15
8
|
}
|
|
16
9
|
async function defaultSend(credentials, command) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
const { sendAccountCommand } = await import('#tunnel-core/flows/account.js');
|
|
11
|
+
const { default: logger } = await import('#tunnel-core/lib/logger.js');
|
|
12
|
+
return sendAccountCommand({ credentials, command, logger });
|
|
20
13
|
}
|
|
21
|
-
|
|
22
14
|
const REFUSALS = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
app_not_allowed: 'An app cannot change the account. Run this on a device, or use the console.',
|
|
16
|
+
identity_inactive: 'This device has been removed from its account. Run asyx setup to set it up again.',
|
|
17
|
+
identity_refused: 'The service did not accept this device\'s certificate. Run asyx setup again.',
|
|
18
|
+
account_not_migrated: 'This device is not set up for your account yet. Run asyx setup again; if that does not help, contact support@asyx.ai.',
|
|
19
|
+
account_changed_retry: 'The account changed at the same moment. Run the command again.',
|
|
20
|
+
no_port_block: 'This account has no port block yet. Contact support@asyx.ai.',
|
|
21
|
+
address_exists: 'That address is already on your account.',
|
|
30
22
|
};
|
|
31
|
-
|
|
32
23
|
export async function runAccountCommand(command, { json = false, send = defaultSend, credentials = loadCredentials, out = console.log, err = console.error } = {}) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
let creds;
|
|
25
|
+
try {
|
|
26
|
+
creds = await credentials();
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
if (json)
|
|
30
|
+
out(JSON.stringify({ ok: false, error: 'setup_required' }));
|
|
31
|
+
else
|
|
32
|
+
err('This computer is not set up yet. Run asyx setup first.');
|
|
33
|
+
return EXIT.FAILED;
|
|
34
|
+
}
|
|
35
|
+
let r;
|
|
36
|
+
try {
|
|
37
|
+
r = await send(creds, command);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
if (json)
|
|
41
|
+
out(JSON.stringify({ ok: false, error: e.code || 'network_error', message: e.message }));
|
|
42
|
+
else
|
|
43
|
+
err(`Could not reach the service: ${e.message}`);
|
|
44
|
+
return EXIT.FAILED;
|
|
45
|
+
}
|
|
46
|
+
if (json) {
|
|
47
|
+
out(JSON.stringify(r));
|
|
48
|
+
}
|
|
49
|
+
if (r?.ok) {
|
|
50
|
+
if (!json && command.type === 'address_add')
|
|
51
|
+
out(`${r.address.hostname} was added to your account. Open a tunnel on it with --to ${r.address.hostname}`);
|
|
52
|
+
if (!json && command.type === 'port_release')
|
|
53
|
+
out(`${r.released.kind.toUpperCase()} port ${r.released.port} was released${r.released.address ? ` (it was ${r.released.address}'s)` : ''}.`);
|
|
54
|
+
return EXIT.OK;
|
|
55
|
+
}
|
|
56
|
+
const e = r?.error || 'refused';
|
|
57
|
+
if (command.type === 'address_add' && /^hostname_/.test(e)) {
|
|
58
|
+
if (!json)
|
|
59
|
+
err(describeAnswer({ status: e, label: command.name, hostname: `${command.name}.tunnel.asyx.ai`, suggestions: r.suggestions || [] }));
|
|
60
|
+
return EXIT.NAME_UNAVAILABLE;
|
|
61
|
+
}
|
|
62
|
+
if (!json) {
|
|
63
|
+
if (e === 'address_limit_reached')
|
|
64
|
+
err(`Your plan allows ${r.limit} addresses and they are all in use. Delete one in the console (${CONSOLE}) first.`);
|
|
65
|
+
else if (e === 'port_live')
|
|
66
|
+
err(`${String(r.kind).toUpperCase()} port ${r.port} is in use by a running tunnel${r.address ? ` on ${r.address}` : ''}. Stop that tunnel first.`);
|
|
67
|
+
else if (e === 'port_not_assigned')
|
|
68
|
+
err(`${String(r.kind).toUpperCase()} port ${r.port} is not assigned to any of your addresses.`);
|
|
69
|
+
else
|
|
70
|
+
err(REFUSALS[e] || `The service refused the request (${e}).`);
|
|
71
|
+
}
|
|
38
72
|
return EXIT.FAILED;
|
|
39
|
-
}
|
|
40
|
-
let r;
|
|
41
|
-
try { r = await send(creds, command); }
|
|
42
|
-
catch (e) {
|
|
43
|
-
if (json) out(JSON.stringify({ ok: false, error: e.code || 'network_error', message: e.message }));
|
|
44
|
-
else err(`Could not reach the service: ${e.message}`);
|
|
45
|
-
return EXIT.FAILED;
|
|
46
|
-
}
|
|
47
|
-
if (json) { out(JSON.stringify(r)); }
|
|
48
|
-
if (r?.ok) {
|
|
49
|
-
if (!json && command.type === 'address_add') out(`${r.address.hostname} was added to your account. Open a tunnel on it with --to ${r.address.hostname}`);
|
|
50
|
-
if (!json && command.type === 'port_release') out(`${r.released.kind.toUpperCase()} port ${r.released.port} was released${r.released.address ? ` (it was ${r.released.address}'s)` : ''}.`);
|
|
51
|
-
return EXIT.OK;
|
|
52
|
-
}
|
|
53
|
-
const e = r?.error || 'refused';
|
|
54
|
-
if (command.type === 'address_add' && /^hostname_/.test(e)) {
|
|
55
|
-
if (!json) err(describeAnswer({ status: e, label: command.name, hostname: `${command.name}.tunnel.asyx.ai`, suggestions: r.suggestions || [] }));
|
|
56
|
-
return EXIT.NAME_UNAVAILABLE;
|
|
57
|
-
}
|
|
58
|
-
if (!json) {
|
|
59
|
-
if (e === 'address_limit_reached') err(`Your plan allows ${r.limit} addresses and they are all in use. Delete one in the console (${CONSOLE}) first.`);
|
|
60
|
-
else if (e === 'port_live') err(`${String(r.kind).toUpperCase()} port ${r.port} is in use by a running tunnel${r.address ? ` on ${r.address}` : ''}. Stop that tunnel first.`);
|
|
61
|
-
else if (e === 'port_not_assigned') err(`${String(r.kind).toUpperCase()} port ${r.port} is not assigned to any of your addresses.`);
|
|
62
|
-
else err(REFUSALS[e] || `The service refused the request (${e}).`);
|
|
63
|
-
}
|
|
64
|
-
return EXIT.FAILED;
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
/** `asyx name add <name> [--json]` */
|
|
68
74
|
export async function cmdNameAdd(args, opts = {}) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
const json = args.includes('--json');
|
|
76
|
+
const rest = args.filter((a) => a !== '--json');
|
|
77
|
+
if (rest.length !== 1) {
|
|
78
|
+
(opts.err || console.error)('Usage: asyx name add <name> [--json]');
|
|
79
|
+
return EXIT.USAGE;
|
|
80
|
+
}
|
|
81
|
+
const label = normalizeLabel(rest[0]) || String(rest[0]).trim().toLowerCase();
|
|
82
|
+
return runAccountCommand({ type: 'address_add', name: label }, { ...opts, json });
|
|
74
83
|
}
|
|
75
|
-
|
|
76
|
-
/** `asyx port release --tcp <port> | --udp <port> [--json]` */
|
|
77
84
|
export async function cmdPort(argv, opts = {}) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
const err = opts.err || console.error;
|
|
86
|
+
const json = argv.includes('--json');
|
|
87
|
+
const args = argv.filter((a) => a !== '--json');
|
|
88
|
+
const usage = () => { err('Usage: asyx port release --tcp <port> | --udp <port> [--json]'); return EXIT.USAGE; };
|
|
89
|
+
if (args[0] !== 'release' || args.length !== 3 || !['--tcp', '--udp'].includes(args[1]))
|
|
90
|
+
return usage();
|
|
91
|
+
const port = Number(args[2]);
|
|
92
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
93
|
+
return usage();
|
|
94
|
+
return runAccountCommand({ type: 'port_release', kind: args[1].slice(2), port }, { ...opts, json });
|
|
86
95
|
}
|