asyx 0.10.0 → 0.10.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asyx",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Asyx tunnel CLI — secure localhost exposure (HTTP, TCP, UDP)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"src/commands/tunnel.js",
|
|
42
42
|
"src/commands/validate-target-host.js",
|
|
43
43
|
"src/lib/.gitkeep",
|
|
44
|
+
"src/lib/aws-iot-config.js",
|
|
44
45
|
"src/lib/certs.js",
|
|
45
46
|
"src/lib/csr.js",
|
|
46
47
|
"src/lib/device.js",
|
|
@@ -78,10 +79,11 @@
|
|
|
78
79
|
"test:ci": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand --forceExit",
|
|
79
80
|
"test:e2e:httpwsv2": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand --testPathIgnorePatterns=/node_modules/ --testMatch='**/test/e2e/**/*.e2e.test.js'",
|
|
80
81
|
"pack:verify": "node scripts/pack-verify.mjs",
|
|
81
|
-
"prepublishOnly": "npm run test:ci && npm run pack:verify",
|
|
82
|
+
"prepublishOnly": "npm run test:ci && npm run pack:verify && npm run release:smoke",
|
|
82
83
|
"prepack": "node scripts/prepack.mjs",
|
|
83
84
|
"postpack": "node scripts/postpack.mjs",
|
|
84
|
-
"test:characterization": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand test/characterization"
|
|
85
|
+
"test:characterization": "NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=8192\" jest --runInBand test/characterization",
|
|
86
|
+
"release:smoke": "node scripts/release-smoke.mjs"
|
|
85
87
|
},
|
|
86
88
|
"devDependencies": {
|
|
87
89
|
"@jest/globals": "^30.2.0",
|
package/src/commands/account.js
CHANGED
|
@@ -8,7 +8,7 @@ import { normalizeLabel, describeAnswer, EXIT } from '../lib/naming.js';
|
|
|
8
8
|
const CONSOLE = 'asyx.ai/console/tunnel';
|
|
9
9
|
|
|
10
10
|
async function loadCredentials() {
|
|
11
|
-
const { loadAwsIotConfig } = await import('
|
|
11
|
+
const { loadAwsIotConfig } = await import('../lib/aws-iot-config.js');
|
|
12
12
|
const { readFileSync } = await import('node:fs');
|
|
13
13
|
const cfg = await loadAwsIotConfig();
|
|
14
14
|
return { endpoint: cfg.endpoint, clientId: cfg.clientId, ca: readFileSync(cfg.caPath), cert: readFileSync(cfg.certPath), key: readFileSync(cfg.keyPath) };
|
package/src/commands/app.js
CHANGED
|
@@ -28,7 +28,7 @@ export function localApps(home) {
|
|
|
28
28
|
export const findLocalApp = (name, home) => localApps(home).find((a) => a.name === name) || null;
|
|
29
29
|
|
|
30
30
|
async function deviceCredentials() {
|
|
31
|
-
const { loadAwsIotConfig } = await import('
|
|
31
|
+
const { loadAwsIotConfig } = await import('../lib/aws-iot-config.js');
|
|
32
32
|
const prev = process.env.ASYX_CLIENT_ID; delete process.env.ASYX_CLIENT_ID; // always the device, never an app
|
|
33
33
|
try {
|
|
34
34
|
const cfg = await loadAwsIotConfig();
|
package/src/commands/tunnel.js
CHANGED
|
@@ -380,7 +380,8 @@ function parseArgs(args) {
|
|
|
380
380
|
|
|
381
381
|
async function connect() {
|
|
382
382
|
// 0) Imports (kept local to this command to avoid global side-effects)
|
|
383
|
-
const {
|
|
383
|
+
const { AwsIotTransport } = await import("@asyx/mqtt-broker-aws");
|
|
384
|
+
const { loadAwsIotConfig } = await import("../lib/aws-iot-config.js"); // Story 12.2: apps too
|
|
384
385
|
const { MqttCore } = await import("@asyx/mqtt-core");
|
|
385
386
|
// policy module path may vary between dev/prod builds; fall back to permissive in dev
|
|
386
387
|
const { default: clientPolicyFactory } =
|
|
@@ -541,7 +542,7 @@ async function httpTunnel(localPort, secGroupSlug) {
|
|
|
541
542
|
logger.info("cli.http.start", { localPort, secGroupSlug });
|
|
542
543
|
process.stdout.write(`⚙️ Initializing tunnel on port ${localPort}…\n`);
|
|
543
544
|
|
|
544
|
-
const { loadAwsIotConfig } = await import("
|
|
545
|
+
const { loadAwsIotConfig } = await import("../lib/aws-iot-config.js"); // Story 12.2: apps too
|
|
545
546
|
const { readFileSync } = await import("node:fs");
|
|
546
547
|
|
|
547
548
|
// 1) Load IoT config (throws with clear messages if misconfigured)
|
|
@@ -718,7 +719,7 @@ async function tcpTunnel(localPort, serviceName, kind = null, requestedExternalP
|
|
|
718
719
|
const target = buildTcpTarget(localPort);
|
|
719
720
|
logger.info('cli.tcp.target', { target });
|
|
720
721
|
|
|
721
|
-
const { loadAwsIotConfig } = await import("
|
|
722
|
+
const { loadAwsIotConfig } = await import("../lib/aws-iot-config.js"); // Story 12.2: apps too
|
|
722
723
|
const { readFileSync } = await import("node:fs");
|
|
723
724
|
|
|
724
725
|
// 1) Load IoT config (throws with clear messages if misconfigured)
|
|
@@ -870,7 +871,7 @@ async function udpTunnel(targetPort, requestedExternalPort = null, targetHost =
|
|
|
870
871
|
// UDP-S13: --port is targetPort, not a port we bind to
|
|
871
872
|
logger.info('cli.udp.target', { target: `${targetHost}:${targetPort}` });
|
|
872
873
|
|
|
873
|
-
const { loadAwsIotConfig } = await import("
|
|
874
|
+
const { loadAwsIotConfig } = await import("../lib/aws-iot-config.js"); // Story 12.2: apps too
|
|
874
875
|
const { readFileSync } = await import("node:fs");
|
|
875
876
|
|
|
876
877
|
// 1) Load IoT config (throws with clear messages if misconfigured)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The device's (or, with ASYX_CLIENT_ID=app_..., an app's) AWS IoT connection settings and files.
|
|
2
|
+
// Story 12.2 c5: an app's credentials live only under ~/.asyx/apps/<appId>/; a device's under
|
|
3
|
+
// ~/.asyx/certs/<clientId>/; same file names. Kept in the CLI (not taken from @asyx/mqtt-broker-aws on
|
|
4
|
+
// npm) so the CLI release alone carries it; same rules as packages/mqtt-broker-aws/src/config.ts.
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
export function loadAwsIotConfig() {
|
|
9
|
+
const home = process.env.HOME || process.env.USERPROFILE || '.';
|
|
10
|
+
const devPath = join(home, '.asyx', 'device.json');
|
|
11
|
+
const dev = existsSync(devPath) ? JSON.parse(readFileSync(devPath, 'utf8')) : {};
|
|
12
|
+
const clientId = process.env.ASYX_CLIENT_ID || dev.clientId;
|
|
13
|
+
if (!clientId) throw new Error('missing clientId (ASYX_CLIENT_ID or ~/.asyx/device.json)');
|
|
14
|
+
if (!/^(cli|app)_[A-F0-9]{12}$/.test(clientId)) throw new Error(`invalid clientId format: ${clientId}`);
|
|
15
|
+
const isApp = clientId.startsWith('app_');
|
|
16
|
+
const base = isApp ? join(home, '.asyx', 'apps', clientId) : join(home, '.asyx', 'certs', clientId);
|
|
17
|
+
const manifestPath = join(base, 'manifest.json');
|
|
18
|
+
if (!existsSync(manifestPath)) throw new Error(`missing manifest: ${manifestPath}`);
|
|
19
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
20
|
+
const { endpoint, region } = manifest;
|
|
21
|
+
if (!endpoint || !/^[a-z0-9.-]+\.iot\.[a-z0-9-]+\.amazonaws\.com$/.test(endpoint)) throw new Error(`invalid endpoint in manifest: ${endpoint}`);
|
|
22
|
+
if (!region || !/^[a-z0-9-]+$/.test(region)) throw new Error(`invalid region in manifest: ${region}`);
|
|
23
|
+
const caPath = join(base, 'AmazonRootCA1.pem');
|
|
24
|
+
const certPath = join(base, 'device.pem.crt');
|
|
25
|
+
const keyPath = join(base, 'private.pem.key');
|
|
26
|
+
for (const p of [caPath, certPath, keyPath]) if (!existsSync(p)) throw new Error(`missing file: ${p}`);
|
|
27
|
+
return { endpoint, region, clientId, certPath, keyPath, caPath };
|
|
28
|
+
}
|