@codingfrees/uap-device-control 0.1.19 → 0.1.20

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 CHANGED
@@ -101,3 +101,7 @@ Validate the exact release without publishing with `pnpm publish:public -- --dry
101
101
  For `npm whoami` HTTP 401 in Linux/WSL, renew authentication locally using `npm login --registry=https://registry.npmjs.org/ --auth-type=web`, then confirm `npm whoami`. Do not paste credentials into issue reports or logs. npm versions are immutable: bump the package version and commit a clean tree before publishing.
102
102
 
103
103
  The script requires clean package inputs, 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. The root `pnpm deploy:npm` entrypoint invokes the publisher directly; a separate package-local node_modules directory is unnecessary when workspace dependencies are installed. npm account 2FA remains mandatory and is handled by npm during the publish step.
104
+
105
+ ## UAP Downloads release candidates
106
+
107
+ The `UAP downloadable product candidates` workflow also builds the Node 26 portable `uap-device-control-remote-<version>.mjs`, its SHA-256 and sanitized provenance from the exact candidate source SHA. This executable JavaScript file **requires Node.js 26**; it is not a signed Windows/macOS native installer and is separate from the existing npm release channel. The private CI artifact is not a public UAP Downloads release. Each approved public release must embed Windows/Linux/macOS download, checksum, login, scoped-root, browser pairing and update/removal instructions in its description; live OS/browser certification and separate publication approval are required.
@@ -181,7 +181,7 @@ function exists(error) {
181
181
  // src/auth.ts
182
182
  var scopes = "device-control:device offline_access";
183
183
  async function loginDeviceControl(origin, stateDirectory, options = {}) {
184
- if (!options.pairingCode || !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("A single-use pairing code from the admin console is required");
184
+ if (options.pairingCode !== void 0 && !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("invalid single-use pairing code");
185
185
  const fetcher = options.fetcher ?? fetch;
186
186
  const issuer = canonicalOrigin(origin);
187
187
  const metadata = await json(fetcher(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" }));
@@ -208,7 +208,7 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
208
208
  authorize2.searchParams.set("state", pkce.state);
209
209
  authorize2.searchParams.set("code_challenge", pkce.challenge);
210
210
  authorize2.searchParams.set("code_challenge_method", "S256");
211
- const result = await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state);
211
+ const result = options.pairingCode ? await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state) : await browserAuthorization(authorize2, callback.result, options.onAuthorizationUrl);
212
212
  if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
213
213
  const token = await json(
214
214
  fetcher(tokenEndpoint, {
@@ -265,6 +265,10 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
265
265
  await clearRemoteAuth(stateDirectory);
266
266
  return true;
267
267
  }
268
+ async function browserAuthorization(authorize2, result, onAuthorizationUrl) {
269
+ await onAuthorizationUrl?.(authorize2.href);
270
+ return result;
271
+ }
268
272
  async function automaticPairing(fetcher, issuer, authorize2, pairingCode, expectedState) {
269
273
  const started = await json(
270
274
  fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize2.href }), redirect: "error", cache: "no-store" })
@@ -299,6 +303,11 @@ async function callbackServer(timeoutMs) {
299
303
  return;
300
304
  }
301
305
  response.writeHead(200, { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" });
306
+ if (url.searchParams.has("error")) {
307
+ response.end("UAP Device Control authorization declined. You can close this window.");
308
+ reject(new TypeError("OAuth browser authorization was declined"));
309
+ return;
310
+ }
302
311
  response.end("UAP Device Control login completed. You can close this window.");
303
312
  settle({ code: url.searchParams.get("code") ?? void 0, state: url.searchParams.get("state") ?? void 0 });
304
313
  });
@@ -615,7 +624,7 @@ import path4 from "node:path";
615
624
  // package.json
616
625
  var package_default = {
617
626
  name: "@codingfrees/uap-device-control",
618
- version: "0.1.19",
627
+ version: "0.1.20",
619
628
  description: "Cross-platform outbound UAP Device Control client",
620
629
  type: "module",
621
630
  bin: {
@@ -1790,15 +1799,22 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
1790
1799
  if (next.command === null || next.command === void 0) continue;
1791
1800
  const command = commandValue(next.command);
1792
1801
  const startedAt = Date.now();
1802
+ let outcome;
1793
1803
  try {
1794
1804
  const output = await engine.execute(command.capability, command.parameters, { workspaceId: bounded2(next.workspaceId, "workspace id") });
1795
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: true, output, executionMs: elapsed(startedAt) });
1805
+ outcome = { ok: true, output };
1796
1806
  } catch (error) {
1797
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: false, error: safeError(error), executionMs: elapsed(startedAt) });
1807
+ outcome = { ok: false, error: safeError(error) };
1808
+ }
1809
+ try {
1810
+ await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
1811
+ } catch (error) {
1812
+ if (!(error instanceof RemoteResultExpiredError)) throw error;
1813
+ log?.({ event: "remote.result", status: "expired", deviceId, requestId: command.requestId });
1798
1814
  }
1799
1815
  }
1800
1816
  } finally {
1801
- await invoke2("/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3, void 0).catch(() => void 0);
1817
+ await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3).catch(() => void 0);
1802
1818
  log?.({ event: "remote.session", status: "disconnected", deviceId });
1803
1819
  }
1804
1820
  }
@@ -1833,9 +1849,12 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
1833
1849
  throw new RemoteUnavailableError(void 0, pathname, controller.signal.aborted ? "timeout" : "transport");
1834
1850
  }
1835
1851
  if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError(response.status, pathname);
1836
- if (response.status === 409 && pathname === "/device-control/remote/poll") {
1852
+ if (response.status === 409 && (pathname === "/device-control/remote/poll" || pathname === "/device-control/remote/result")) {
1837
1853
  const body2 = await response.json().catch(() => void 0);
1838
- if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2 && body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1854
+ if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2) {
1855
+ if (body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1856
+ if (pathname.endsWith("/result") && body2.error === "request_not_pending") throw new RemoteResultExpiredError(pathname);
1857
+ }
1839
1858
  }
1840
1859
  if (!response.ok) throw new RemoteUnavailableError(response.status, pathname);
1841
1860
  const raw = await response.json();
@@ -1863,6 +1882,13 @@ var RemoteSessionExpiredError = class extends Error {
1863
1882
  }
1864
1883
  pathname;
1865
1884
  };
1885
+ var RemoteResultExpiredError = class extends Error {
1886
+ constructor(pathname) {
1887
+ super("remote command waiter expired before result acceptance");
1888
+ this.pathname = pathname;
1889
+ }
1890
+ pathname;
1891
+ };
1866
1892
  var RemoteUnavailableError = class extends Error {
1867
1893
  constructor(httpStatus, pathname, reason) {
1868
1894
  super("remote endpoint is unavailable");
@@ -1973,22 +1999,22 @@ async function installRemoteService(origin, stateDirectory) {
1973
1999
  }
1974
2000
  async function runnerV2Installed(platform = process.platform, run = execute3, exists2 = existsSync) {
1975
2001
  if (platform === "linux") {
1976
- if (exists2("/opt/uap-local-node-runner-v2/current")) return true;
2002
+ if (exists2("/opt/uap-local-runner/current")) return true;
1977
2003
  for (const args of [
1978
- ["list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"],
1979
- ["--user", "list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"]
2004
+ ["list-unit-files", "uap-local-runner.service", "--no-legend"],
2005
+ ["--user", "list-unit-files", "uap-local-runner.service", "--no-legend"]
1980
2006
  ]) {
1981
2007
  try {
1982
2008
  const result = await run("systemctl", args);
1983
- if (/^uap-local-node-runner-v2\.service\s/m.test(result.stdout)) return true;
2009
+ if (/^uap-local-runner\.service\s/m.test(result.stdout)) return true;
1984
2010
  } catch {
1985
2011
  }
1986
2012
  }
1987
2013
  }
1988
2014
  if (platform === "win32") {
1989
2015
  for (const [command, args] of [
1990
- ["sc.exe", ["query", "UAPLocalNodeRunnerV2"]],
1991
- ["schtasks.exe", ["/Query", "/TN", "UAPLocalNodeRunnerV2"]]
2016
+ ["sc.exe", ["query", "UAPLocalRunner"]],
2017
+ ["schtasks.exe", ["/Query", "/TN", "UAPLocalRunner"]]
1992
2018
  ]) {
1993
2019
  try {
1994
2020
  await run(command, [...args]);
@@ -2114,7 +2140,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2114
2140
  const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
2115
2141
  const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
2116
2142
  if (config.command === "login") {
2117
- const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2143
+ const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2144
+ pairingCode: config.pairingCode,
2145
+ onAuthorizationUrl: (url) => {
2146
+ output({ event: "oauth.browser", status: "authorization-required", url });
2147
+ }
2148
+ });
2118
2149
  output({ status: "authenticated", origin: auth.origin });
2119
2150
  return;
2120
2151
  }
@@ -2148,7 +2179,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2148
2179
  try {
2149
2180
  if (!existingAuth) {
2150
2181
  if (config.service) throw new TypeError("service mode requires login");
2151
- await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2182
+ await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2183
+ pairingCode: config.pairingCode,
2184
+ onAuthorizationUrl: (url) => {
2185
+ output({ event: "oauth.browser", status: "authorization-required", url });
2186
+ }
2187
+ });
2152
2188
  }
2153
2189
  const controller = new AbortController();
2154
2190
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
@@ -2202,6 +2238,8 @@ function formatCliEvent(event, json2 = false) {
2202
2238
  if (status === "reconnecting") return "\u26A0\uFE0F Connection interrupted" + httpDetail(event) + " \xB7 retrying in " + String(event.retryMs) + " ms";
2203
2239
  if (status === "reauthorizing") return "\u{1F510} Refreshing Device Control authorization" + httpDetail(event);
2204
2240
  }
2241
+ if (event.event === "oauth.browser" && status === "authorization-required")
2242
+ return "Open this URL in a browser and explicitly approve this computer:\n" + String(event.url) + "\nIf using WSL2, open the link in Windows and keep this terminal running for the localhost callback.\nAlternatively, run login --pairing-code <code>.";
2205
2243
  if (status === "connecting") return "\u{1F310} Connecting to " + String(event.origin) + " \xB7 " + String(event.platform);
2206
2244
  if (status === "authenticated") return "\u2705 Authenticated \xB7 " + String(event.origin);
2207
2245
  if (status === "logged-out") return "\u2705 Logged out";
@@ -2235,7 +2273,7 @@ Usage:
2235
2273
  Commands:
2236
2274
  remote Connect this computer to Device Control
2237
2275
  status Show authentication, device and connection status
2238
- login Pair this computer using a temporary admin-issued code
2276
+ login Sign in through browser OAuth/PKCE or an admin-issued pairing code
2239
2277
  logout Remove the saved authorization
2240
2278
  browser-reset Reset only the saved browser-extension pairing
2241
2279
  install-service Install the authenticated Remote as a system service
@@ -2256,6 +2294,7 @@ Remote options:
2256
2294
 
2257
2295
  Examples:
2258
2296
  npx @codingfrees/uap-device-control@latest
2297
+ npx @codingfrees/uap-device-control@latest login
2259
2298
  npx @codingfrees/uap-device-control@latest login --pairing-code <code>
2260
2299
  npx @codingfrees/uap-device-control@latest browser-reset
2261
2300
  npx @codingfrees/uap-device-control@latest remote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {