@camox/cli 0.59.0 → 0.61.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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as installLocalhostDns } from "./local-dns-DQIT1ucr.mjs";
2
+ import { t as installLocalhostDns } from "./local-dns-C3ccfrzD.mjs";
3
3
  import { createORPCClient } from "@orpc/client";
4
4
  import { RPCLink } from "@orpc/client/fetch";
5
5
  //#region src/lib/uuid.ts
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export { r as verifySession } from "./api-CRGaFBkN.mjs";
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as installLocalhostDns } from "./local-dns-DQIT1ucr.mjs";
2
+ import { t as installLocalhostDns } from "./local-dns-C3ccfrzD.mjs";
3
3
  import path from "node:path";
4
4
  import fs from "node:fs";
5
5
  import os from "node:os";
package/dist/index.mjs CHANGED
@@ -1,23 +1,24 @@
1
1
  #!/usr/bin/env node
2
- import { t as installLocalhostDns } from "./local-dns-DQIT1ucr.mjs";
3
- import { i as UUID, n as pushCode, t as createCodeReadToken } from "./api-DU0iBFMw.mjs";
4
- import { a as removeAuthTokenForUrl, i as readAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "./auth-core-BpVsNVnR.mjs";
2
+ import { t as installLocalhostDns } from "./local-dns-C3ccfrzD.mjs";
3
+ import { i as UUID, n as pushCode, t as createCodeReadToken } from "./api-CRGaFBkN.mjs";
4
+ import { a as removeAuthTokenForUrl, i as readAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "./auth-core-BOANKWGQ.mjs";
5
5
  import { object, or } from "@optique/core/constructs";
6
6
  import { message } from "@optique/core/message";
7
7
  import { defineProgram } from "@optique/core/program";
8
8
  import { runSync } from "@optique/run";
9
9
  import { execSync, spawnSync } from "node:child_process";
10
- import path, { join, resolve } from "node:path";
10
+ import path, { dirname, join, resolve } from "node:path";
11
11
  import * as p from "@clack/prompts";
12
12
  import { log } from "@clack/prompts";
13
13
  import { optional } from "@optique/core/modifiers";
14
14
  import { argument, command, constant, option } from "@optique/core/primitives";
15
15
  import { string } from "@optique/core/valueparser";
16
16
  import http from "node:http";
17
- import fs, { mkdtempSync, readFileSync, rmSync } from "node:fs";
17
+ import fs, { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
18
18
  import { tmpdir } from "node:os";
19
19
  import { text } from "node:stream/consumers";
20
20
  import { ZodError, z } from "zod";
21
+ import { pathToFileURL } from "node:url";
21
22
  //#region src/lib/auth.ts
22
23
  const CAMOX_URL = process.env.CAMOX_URL || "https://app.camox.ai";
23
24
  const CAMOX_API_URL = process.env.CAMOX_API_URL || "https://api.camox.ai";
@@ -118,7 +119,7 @@ async function authenticateUser() {
118
119
  async function getOrAuthenticate() {
119
120
  const stored = readAuthToken();
120
121
  if (stored) {
121
- const { verifySession } = await import("./api-DOHUrl0V.mjs");
122
+ const { verifySession } = await import("./api-D1v4nyZr.mjs");
122
123
  if (await verifySession(stored.token)) {
123
124
  p.log.info(`Authenticated as ${stored.name}`);
124
125
  return stored;
@@ -513,7 +514,7 @@ const parser = command("release", object({
513
514
  command: constant("release"),
514
515
  dryRun: option("--dry-run", { description: message`Build the website as a release would, without logging in or syncing its definitions to Live.` })
515
516
  }));
516
- function handler(args) {
517
+ async function handler(args) {
517
518
  p.intro(args.dryRun ? "camox release --dry-run" : "camox release");
518
519
  if (!args.dryRun && !process.env.CAMOX_DEPLOY_TOKEN) {
519
520
  p.log.error("CAMOX_DEPLOY_TOKEN is required to release to Live.");
@@ -536,9 +537,41 @@ function handler(args) {
536
537
  p.log.error(args.dryRun ? "Dry run failed." : "Release failed.");
537
538
  process.exit(result.status ?? 1);
538
539
  }
540
+ try {
541
+ const names = await addSdkBundle(process.cwd());
542
+ if (names) p.log.info(`Added the SDK Bundle ${names.browser} (browser) and ${names.workerd} (workerd).`);
543
+ } catch (error) {
544
+ p.log.error(`Could not add the SDK Bundle: ${error instanceof Error ? error.message : String(error)}`);
545
+ process.exit(1);
546
+ }
539
547
  p.outro(args.dryRun ? "Dry run built successfully." : "Release prepared successfully.");
540
548
  process.exit(0);
541
549
  }
550
+ /**
551
+ * Adds the SDK Bundle the build names to its output, so it deploys on its own, with the website's
552
+ * own camox. A camox without SDK Bundles builds whole-app, so there's nothing to add.
553
+ */
554
+ async function addSdkBundle(root) {
555
+ const module = websiteModule(root, "camox", "./_internal/sdkBundle");
556
+ if (!module) return null;
557
+ const { addSdkBundleToBuild } = await import(pathToFileURL(module).href);
558
+ return addSdkBundleToBuild ? addSdkBundleToBuild({ root }) : null;
559
+ }
560
+ /**
561
+ * The file a package's export resolves to for `import`, from the website in `root`, or null when
562
+ * it isn't installed or doesn't export it.
563
+ */
564
+ function websiteModule(root, name, subpath) {
565
+ for (let dir = resolve(root);; dir = dirname(dir)) {
566
+ const manifestPath = join(dir, "node_modules", name, "package.json");
567
+ if (existsSync(manifestPath)) {
568
+ let target = JSON.parse(readFileSync(manifestPath, "utf8")).exports?.[subpath];
569
+ while (target && typeof target === "object") target = target.import ?? target.default;
570
+ return typeof target === "string" ? join(dirname(manifestPath), target) : null;
571
+ }
572
+ if (dirname(dir) === dir) return null;
573
+ }
574
+ }
542
575
  //#endregion
543
576
  //#region src/index.ts
544
577
  const program = defineProgram({
@@ -557,7 +590,7 @@ switch (result.command) {
557
590
  handler$2(result);
558
591
  break;
559
592
  case "release":
560
- handler(result);
593
+ await handler(result);
561
594
  break;
562
595
  case "clone":
563
596
  await handler$5(result);
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export { t as createPreviewSignInUrl, n as isLoopbackUrl, r as normalizeUrl, i as readAuthTokenForUrl, a as removeAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "../auth-core-BpVsNVnR.mjs";
2
+ export { t as createPreviewSignInUrl, n as isLoopbackUrl, r as normalizeUrl, i as readAuthTokenForUrl, a as removeAuthTokenForUrl, o as verifyOneTimeToken, s as writeAuthTokenForUrl } from "../auth-core-BOANKWGQ.mjs";
@@ -4,18 +4,19 @@ import dns from "node:dns";
4
4
  //#region src/lib/local-dns.ts
5
5
  const selectedHosts = /* @__PURE__ */ new Set();
6
6
  let installed = false;
7
+ /** `lookup`, resolving the selected hosts to 127.0.0.1. */
8
+ const toSelectedHosts = (lookup) => new Proxy(lookup, { apply(target, receiver, args) {
9
+ if (selectedHosts.has(args[0])) args[0] = "127.0.0.1";
10
+ return target.apply(receiver, args);
11
+ } });
7
12
  /** Resolve explicitly selected local backends without depending on OS wildcard DNS. */
8
13
  function installLocalhostDns(hostname) {
9
14
  if (!hostname.endsWith(".localhost")) return;
10
15
  selectedHosts.add(hostname);
11
16
  if (installed) return;
12
17
  installed = true;
13
- const handler = { apply(target, receiver, args) {
14
- if (selectedHosts.has(args[0])) args[0] = "127.0.0.1";
15
- return Reflect.apply(target, receiver, args);
16
- } };
17
- dns.lookup = new Proxy(dns.lookup, handler);
18
- dns.promises.lookup = new Proxy(dns.promises.lookup, handler);
18
+ dns.lookup = toSelectedHosts(dns.lookup);
19
+ dns.promises.lookup = toSelectedHosts(dns.promises.lookup);
19
20
  syncBuiltinESMExports();
20
21
  }
21
22
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camox/cli",
3
- "version": "0.59.0",
3
+ "version": "0.61.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "camox": "./dist/index.mjs"
@@ -28,7 +28,7 @@
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.12.4",
30
30
  "vite-plus": "1.3.0",
31
- "@camox/api-contract": "0.59.0"
31
+ "@camox/api-contract": "0.61.0"
32
32
  },
33
33
  "nx": {
34
34
  "tags": [
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export { r as verifySession } from "./api-DU0iBFMw.mjs";