@codingfrees/uap-device-control 0.1.2 → 0.1.4
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 +12 -0
- package/dist/uap-device-control.mjs +67 -13
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -65,3 +65,15 @@ The `/mcp` endpoint is required by ChatGPT/Codex and the public OpenAI plugin li
|
|
|
65
65
|
## Security boundary
|
|
66
66
|
|
|
67
67
|
The client opens only outbound HTTPS connections. Filesystem roots, executable allowlists and service allowlists remain local explicit authority. Device credentials are origin-bound and cannot be silently reused against another environment.
|
|
68
|
+
|
|
69
|
+
## Publishing
|
|
70
|
+
|
|
71
|
+
Publish a verified public release from this package with:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pnpm publish:public
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Validate the exact release without publishing with `pnpm publish:public -- --dry-run`.
|
|
78
|
+
|
|
79
|
+
The script requires a clean repository, refuses an already-published version, builds and dry-runs the package, then calls npm publish and verifies the registry version plus the `latest` dist-tag. npm account 2FA remains mandatory and is handled by npm during the publish step.
|
|
@@ -62,6 +62,25 @@ import os from "node:os";
|
|
|
62
62
|
import path from "node:path";
|
|
63
63
|
import { mkdir, readFile, rm, rename, writeFile } from "node:fs/promises";
|
|
64
64
|
import { randomUUID } from "node:crypto";
|
|
65
|
+
function defaultOwnerBootstrapPath(home = os.homedir(), platform = process.platform) {
|
|
66
|
+
if (platform === "win32") return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "UAP", "DeviceControl", "owner-bootstrap.json");
|
|
67
|
+
if (platform === "darwin") return path.join(home, "Library", "Application Support", "UAP", "DeviceControl", "owner-bootstrap.json");
|
|
68
|
+
return path.join(process.env.XDG_CONFIG_HOME || path.join(home, ".config"), "uap-device-control", "owner-bootstrap.json");
|
|
69
|
+
}
|
|
70
|
+
async function loadOwnerBootstrapCredential(expectedOrigin, file = defaultOwnerBootstrapPath()) {
|
|
71
|
+
try {
|
|
72
|
+
const raw = JSON.parse(await readFile(file, "utf8"));
|
|
73
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new TypeError("owner bootstrap credential is invalid");
|
|
74
|
+
const value = raw;
|
|
75
|
+
if (value.origin !== expectedOrigin || typeof value.secret !== "string" || value.secret.length < 24 || value.secret.length > 512 || /[\u0000-\u001f\u007f]/.test(value.secret)) {
|
|
76
|
+
throw new TypeError("owner bootstrap credential is invalid");
|
|
77
|
+
}
|
|
78
|
+
return { origin: expectedOrigin, secret: value.secret };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (missing(error)) return void 0;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
65
84
|
function defaultDeviceControlStateDirectory(home = os.homedir(), platform = process.platform) {
|
|
66
85
|
if (platform === "win32") return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "UAP", "DeviceControl");
|
|
67
86
|
if (platform === "darwin") return path.join(home, "Library", "Application Support", "UAP", "DeviceControl");
|
|
@@ -146,8 +165,8 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
|
|
|
146
165
|
authorize.searchParams.set("state", pkce.state);
|
|
147
166
|
authorize.searchParams.set("code_challenge", pkce.challenge);
|
|
148
167
|
authorize.searchParams.set("code_challenge_method", "S256");
|
|
149
|
-
await (options.
|
|
150
|
-
const result = await callback.result;
|
|
168
|
+
const configuredBootstrap = options.ownerBootstrapSecret === void 0 ? await loadOwnerBootstrapCredential(issuer).then((value) => value?.secret) : options.ownerBootstrapSecret ?? void 0;
|
|
169
|
+
const result = configuredBootstrap ? await automaticPairing(fetcher, issuer, authorize, configuredBootstrap, pkce.state) : await browserAuthorization(options.open ?? openBrowser, authorize.href, callback.result);
|
|
151
170
|
if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
|
|
152
171
|
const token = await json(
|
|
153
172
|
fetcher(tokenEndpoint, {
|
|
@@ -200,6 +219,33 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
|
|
|
200
219
|
await clearRemoteAuth(stateDirectory);
|
|
201
220
|
return true;
|
|
202
221
|
}
|
|
222
|
+
async function automaticPairing(fetcher, issuer, authorize, ownerSecret, expectedState) {
|
|
223
|
+
const started = await json(
|
|
224
|
+
fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize.href }), redirect: "error", cache: "no-store" })
|
|
225
|
+
);
|
|
226
|
+
const pairingId = text(started.pairingId, "pairing id");
|
|
227
|
+
const pollToken = text(started.pollToken, "pairing poll token");
|
|
228
|
+
await json(
|
|
229
|
+
fetcher(new URL("/pairing/approve", issuer), {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: { "content-type": "application/json", authorization: "Bearer " + ownerSecret },
|
|
232
|
+
body: JSON.stringify({ pairingId }),
|
|
233
|
+
redirect: "error",
|
|
234
|
+
cache: "no-store"
|
|
235
|
+
})
|
|
236
|
+
);
|
|
237
|
+
const status = await json(
|
|
238
|
+
fetcher(new URL("/pairing/status", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ pairingId, pollToken }), redirect: "error", cache: "no-store" })
|
|
239
|
+
);
|
|
240
|
+
if (status.status !== "approved" || typeof status.redirect !== "string") throw new TypeError("pairing approval failed");
|
|
241
|
+
const redirect = new URL(status.redirect);
|
|
242
|
+
if (redirect.searchParams.get("state") !== expectedState) throw new TypeError("pairing callback state is invalid");
|
|
243
|
+
return { code: redirect.searchParams.get("code") ?? void 0, state: redirect.searchParams.get("state") ?? void 0 };
|
|
244
|
+
}
|
|
245
|
+
async function browserAuthorization(open, authorizeUrl, result) {
|
|
246
|
+
await open(authorizeUrl);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
203
249
|
async function callbackServer(timeoutMs) {
|
|
204
250
|
let settle;
|
|
205
251
|
let reject;
|
|
@@ -231,14 +277,25 @@ async function callbackServer(timeoutMs) {
|
|
|
231
277
|
}
|
|
232
278
|
};
|
|
233
279
|
}
|
|
280
|
+
function browserOpenCommand(platform, url) {
|
|
281
|
+
if (platform === "win32") return { command: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] };
|
|
282
|
+
if (platform === "darwin") return { command: "open", args: [url] };
|
|
283
|
+
return { command: "xdg-open", args: [url] };
|
|
284
|
+
}
|
|
234
285
|
async function openBrowser(url) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
else await execute("xdg-open", [url]);
|
|
286
|
+
const launch = browserOpenCommand(process.platform, url);
|
|
287
|
+
await execute(launch.command, launch.args, { windowsHide: true });
|
|
238
288
|
}
|
|
239
289
|
async function json(response) {
|
|
240
290
|
const value = await response;
|
|
241
|
-
if (!value.ok)
|
|
291
|
+
if (!value.ok) {
|
|
292
|
+
let path6 = "request";
|
|
293
|
+
try {
|
|
294
|
+
path6 = new URL(value.url).pathname || "request";
|
|
295
|
+
} catch {
|
|
296
|
+
}
|
|
297
|
+
throw new TypeError(`OAuth request failed (${value.status}) at ${path6}`);
|
|
298
|
+
}
|
|
242
299
|
const raw = await value.json();
|
|
243
300
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new TypeError("OAuth response is invalid");
|
|
244
301
|
return raw;
|
|
@@ -1515,6 +1572,7 @@ function xml(value) {
|
|
|
1515
1572
|
}
|
|
1516
1573
|
|
|
1517
1574
|
// src/cli.ts
|
|
1575
|
+
var DEFAULT_DEVICE_CONTROL_ORIGIN = "https://device-control.aemdpc.ro";
|
|
1518
1576
|
function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
1519
1577
|
const command = args[0];
|
|
1520
1578
|
if (!["remote", "status", "login", "logout", "install-service"].includes(command ?? "")) throw new TypeError("command must be remote, status, login, logout, or install-service");
|
|
@@ -1546,7 +1604,6 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
1546
1604
|
const existingAuth = await loadRemoteAuth(config.stateDirectory);
|
|
1547
1605
|
const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
|
|
1548
1606
|
if (config.command === "login") {
|
|
1549
|
-
if (!resolvedOrigin) throw new TypeError("origin is required for first login; use --origin or UAP_DEVICE_CONTROL_ORIGIN");
|
|
1550
1607
|
const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory);
|
|
1551
1608
|
process.stdout.write(JSON.stringify({ status: "authenticated", origin: auth.origin }) + "\n");
|
|
1552
1609
|
return;
|
|
@@ -1561,31 +1618,28 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
1561
1618
|
let remote;
|
|
1562
1619
|
if (auth && deviceAuthorized) remote = await remoteStatus(auth.origin, config.stateDirectory, deviceId).catch(() => ({ online: false }));
|
|
1563
1620
|
process.stdout.write(
|
|
1564
|
-
JSON.stringify({ deviceId, origin: auth?.origin ??
|
|
1621
|
+
JSON.stringify({ deviceId, origin: auth?.origin ?? resolvedOrigin, authenticated: Boolean(auth), deviceAuthorized, remote: remote ?? null, serviceMode: config.service, platform: process.platform }) + "\n"
|
|
1565
1622
|
);
|
|
1566
1623
|
return;
|
|
1567
1624
|
}
|
|
1568
1625
|
if (config.command === "install-service") {
|
|
1569
1626
|
if (!existingAuth) throw new TypeError("login is required before install-service");
|
|
1570
|
-
if (!resolvedOrigin) throw new TypeError("origin is unavailable");
|
|
1571
1627
|
process.stdout.write(JSON.stringify({ status: "installed", ...await installRemoteService(resolvedOrigin, config.stateDirectory) }) + "\n");
|
|
1572
1628
|
return;
|
|
1573
1629
|
}
|
|
1574
1630
|
if (!existingAuth) {
|
|
1575
1631
|
if (config.service) throw new TypeError("service mode requires login");
|
|
1576
|
-
if (!resolvedOrigin) throw new TypeError("origin is required for first remote connection; use --origin or UAP_DEVICE_CONTROL_ORIGIN");
|
|
1577
1632
|
await loginDeviceControl(resolvedOrigin, config.stateDirectory);
|
|
1578
1633
|
}
|
|
1579
1634
|
const controller = new AbortController();
|
|
1580
1635
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
1581
|
-
const remoteOrigin = resolvedOrigin
|
|
1582
|
-
if (!remoteOrigin) throw new TypeError("origin is unavailable");
|
|
1636
|
+
const remoteOrigin = resolvedOrigin;
|
|
1583
1637
|
process.stdout.write(JSON.stringify({ status: "connecting", origin: remoteOrigin, platform: process.platform }) + "\n");
|
|
1584
1638
|
await runRemote({ origin: remoteOrigin, stateDirectory: config.stateDirectory, roots: config.roots, allowedExecutables: config.allowedExecutables, allowedServices: config.allowedServices, signal: controller.signal });
|
|
1585
1639
|
}
|
|
1586
1640
|
function resolveConfiguredOrigin(explicit, stored) {
|
|
1587
1641
|
if (explicit && stored && explicit !== stored) throw new TypeError("configured origin does not match the authenticated origin; logout before changing environments");
|
|
1588
|
-
return explicit ?? stored;
|
|
1642
|
+
return explicit ?? stored ?? DEFAULT_DEVICE_CONTROL_ORIGIN;
|
|
1589
1643
|
}
|
|
1590
1644
|
function canonicalOrigin3(value) {
|
|
1591
1645
|
const url = new URL(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingfrees/uap-device-control",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Cross-platform outbound UAP Device Control client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "pnpm exec esbuild src/bin.ts --bundle --platform=node --format=esm --target=node26 --outfile=dist/uap-device-control.mjs --banner:js=\"#!/usr/bin/env node\"",
|
|
20
|
-
"prepack": "pnpm run build"
|
|
20
|
+
"prepack": "pnpm run build",
|
|
21
|
+
"publish:public": "node scripts/publish.mjs"
|
|
21
22
|
}
|
|
22
23
|
}
|