@datarails-ai/dr-appspace-cli 0.12.72 → 0.12.74

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.
Files changed (2) hide show
  1. package/dist/cli.js +183 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import { fileURLToPath as fileURLToPath6 } from "url";
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "@datarails-ai/dr-appspace-cli",
16
- version: "0.12.72",
16
+ version: "0.12.74",
17
17
  description: "Datarails App Space CLI \u2014 build, try, push and publish App Space apps",
18
18
  type: "module",
19
19
  engines: {
@@ -57,7 +57,7 @@ var package_default = {
57
57
  };
58
58
 
59
59
  // src/buildInfo.ts
60
- var BUILD_TIME = "2026-11-08T16:30:50.212Z";
60
+ var BUILD_TIME = "2026-11-08T22:36:01.631Z";
61
61
  function formatBuildTime(iso) {
62
62
  if (iso === "") return "";
63
63
  const d = new Date(iso);
@@ -3122,12 +3122,37 @@ function conflictGuidance(body) {
3122
3122
  }
3123
3123
  return lines;
3124
3124
  }
3125
+ function hostsNeedingApproval(body) {
3126
+ const isObj5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3127
+ const found = isObj5(body) && isObj5(body["detail"]) ? body["detail"] : body;
3128
+ if (!isObj5(found) || found["error"] !== "http_hosts_need_approval") return void 0;
3129
+ const hosts = Array.isArray(found["hosts"]) ? found["hosts"].filter((h) => typeof h === "string") : [];
3130
+ const entries = Array.isArray(found["entries"]) ? found["entries"].filter(isObj5).map((e) => ({
3131
+ name: String(e["name"] ?? "?"),
3132
+ host: String(e["host"] ?? "?"),
3133
+ change: String(e["change"] ?? "needs approval")
3134
+ })) : [];
3135
+ return { hosts, entries };
3136
+ }
3137
+ function approveHostsFlag(hosts) {
3138
+ return `--approve-hosts ${hosts.join(",")}`;
3139
+ }
3125
3140
  function describeFailure(status, method, path3, body) {
3126
3141
  const conflicts = conflictTables(body);
3127
3142
  if (status === 409 && conflicts !== void 0) {
3128
3143
  return `${method} ${path3} failed (409) \u2014 ${conflicts.map(([table, owners]) => `table "${table}" already belongs to ${owners.join(", ")}`).join("; ")}. Rename the table in data_model.json, or share the existing one with \`connect_tables\` in manifest.json.` + conflictGuidance(body).map((l) => `
3129
3144
  ${l}`).join("");
3130
3145
  }
3146
+ const approval = hostsNeedingApproval(body);
3147
+ if (status === 409 && approval !== void 0) {
3148
+ const lines = approval.entries.map((e) => ` http.${e.name} -> ${e.host} (${e.change})`);
3149
+ return [
3150
+ `${method} ${path3} failed (409 http_hosts_need_approval) \u2014 the manifest's http key lets the app call outside hosts its Owner has not approved in this form:`,
3151
+ ...lines,
3152
+ "Only the app's Owner approves. Check each host, then push again with:",
3153
+ ` ${approveHostsFlag(approval.hosts)}`
3154
+ ].join("\n");
3155
+ }
3131
3156
  const code = body?.detail?.error;
3132
3157
  if (status === 403 && code === "studio_not_enabled") {
3133
3158
  return `${method} ${path3} failed (403) \u2014 Studio isn't enabled for your organization. Ask your Datarails admin.`;
@@ -24216,6 +24241,12 @@ function obj2(value) {
24216
24241
  }
24217
24242
 
24218
24243
  // src/commands/appspace/push.ts
24244
+ var APPROVE_HOSTS_HELP = "Approve these outside hosts (comma-separated) for the manifest's http key. Only the app's Owner may. A push that adds or changes an http entry is refused (409) until its host is named here.";
24245
+ function approveHostsList(value) {
24246
+ if (value === void 0) return void 0;
24247
+ const hosts = value.split(",").map((h) => h.trim()).filter((h) => h !== "");
24248
+ return hosts.length > 0 ? hosts : void 0;
24249
+ }
24219
24250
  var KIT_ENV = "DR_APPSPACE_KIT";
24220
24251
  function kitForPush(opts, env = process.env) {
24221
24252
  const flag = (opts.kit ?? "").trim();
@@ -24427,7 +24458,7 @@ function registerPushCommand(parent) {
24427
24458
  ).option(
24428
24459
  "--metrics-wait <seconds>",
24429
24460
  "When the contract declares Datarails metrics (data.metrics) and this push creates a BASE one, how long to wait for it to extract before pushing anyway (default 60, at most 120)."
24430
- )
24461
+ ).option("--approve-hosts <hosts>", APPROVE_HOSTS_HELP)
24431
24462
  )
24432
24463
  ).action(async (dirArg, opts) => {
24433
24464
  await pushFolder(dirArg ?? ".", opts);
@@ -24470,6 +24501,10 @@ async function pushBody(dir, opts) {
24470
24501
  if (opts.force !== true && typeof state.revision === "number") {
24471
24502
  body["expected_revision"] = state.revision;
24472
24503
  }
24504
+ const approveHosts = approveHostsList(opts.approveHosts);
24505
+ if (approveHosts !== void 0) {
24506
+ body["approve_hosts"] = approveHosts;
24507
+ }
24473
24508
  if (opts.metricBindings !== void 0 && Object.keys(opts.metricBindings).length > 0) {
24474
24509
  body["metric_bindings"] = opts.metricBindings;
24475
24510
  }
@@ -25153,6 +25188,15 @@ function fromRefusal(status, detail, contract) {
25153
25188
  };
25154
25189
  });
25155
25190
  }
25191
+ const approval = hostsNeedingApproval(detail);
25192
+ if (approval !== void 0) {
25193
+ return approval.entries.map((e) => ({
25194
+ code: "server:http-host-approval",
25195
+ pointer: "/",
25196
+ message: `${refused}: http.${e.name} calls ${e.host} (${e.change}), which the app's Owner has not approved.`,
25197
+ fix: `The app's Owner checks the host, then pushes with ${approveHostsFlag(approval.hosts)}.`
25198
+ }));
25199
+ }
25156
25200
  if (isObj4(detail) && detail["error"] === "stale_revision") {
25157
25201
  return [
25158
25202
  {
@@ -34161,7 +34205,7 @@ function metricHelpLines() {
34161
34205
  function registerCompileCommand(parent) {
34162
34206
  withJsonOption(
34163
34207
  withServerOptions(
34164
- withAssemblyOptions(parent.command("compile [dir]").description("Compile contract.json into the package, and prove it round-trips.").option("--check", "Validate, compile and round-trip into a scratch folder, and verify \u2014 everything a push runs first. Write nothing.").option("--push", "Push the compiled package, contract attached.").option("--seed <file>", "Seed rows, as JSON. Forwarded to the push.").option("--catalog <file>", "Check source ids against this catalog instead of the tenant.").option("--force", "Write over files this compiler did not write (never a custom handler, custom module or owned page).").option("--update-block", "After a push that passed, print the appspace_app_update block a build reply ends with.").option("--metrics-wait <seconds>", "With --push: how long to wait for a BASE metric this ship created to extract before pushing anyway (default 60, at most 120).").addHelpText(
34208
+ withAssemblyOptions(parent.command("compile [dir]").description("Compile contract.json into the package, and prove it round-trips.").option("--check", "Validate, compile and round-trip into a scratch folder, and verify \u2014 everything a push runs first. Write nothing.").option("--push", "Push the compiled package, contract attached.").option("--seed <file>", "Seed rows, as JSON. Forwarded to the push.").option("--catalog <file>", "Check source ids against this catalog instead of the tenant.").option("--force", "Write over files this compiler did not write (never a custom handler, custom module or owned page).").option("--update-block", "After a push that passed, print the appspace_app_update block a build reply ends with.").option("--metrics-wait <seconds>", "With --push: how long to wait for a BASE metric this ship created to extract before pushing anyway (default 60, at most 120).").option("--approve-hosts <hosts>", `With --push: ${APPROVE_HOSTS_HELP}`).addHelpText(
34165
34209
  "after",
34166
34210
  [
34167
34211
  "",
@@ -34215,7 +34259,7 @@ function registerShipCommand(parent) {
34215
34259
  parent.command("ship [dir]").description("Assemble, compile, push and prove a dashboard pass; print the update block the reply ends with.").option("--seed <file>", "Seed rows, as JSON. Forwarded to the push.").option("--force", "Write over files this compiler did not write (never a custom handler). Refused with --onto-live.").option(
34216
34260
  "--onto-live",
34217
34261
  "Land this pass's cards on the app as it is live now, keeping every card already there: pull it, add them, push against its revision, and start over when another push lands first. Needs --app-id and --skeleton, and a folder of its own."
34218
- ).option("--metrics-wait <seconds>", "How long to wait for a BASE metric this ship created to extract before pushing anyway (default 60, at most 120).").addHelpText("after", ["", ...metricHelpLines()].join("\n"))
34262
+ ).option("--metrics-wait <seconds>", "How long to wait for a BASE metric this ship created to extract before pushing anyway (default 60, at most 120).").option("--approve-hosts <hosts>", APPROVE_HOSTS_HELP).addHelpText("after", ["", ...metricHelpLines()].join("\n"))
34219
34263
  )
34220
34264
  )
34221
34265
  ).action(async (dirArg, opts) => {
@@ -42397,6 +42441,139 @@ ${METRIC_ADVICE}
42397
42441
  );
42398
42442
  }
42399
42443
 
42444
+ // src/commands/appspace/secrets.ts
42445
+ var SECRET_NAME_RE = /^[a-z][a-z0-9_]{0,63}$/;
42446
+ function promptHidden(label, input, output) {
42447
+ return new Promise((resolve17, reject) => {
42448
+ let value = "";
42449
+ output.write(label);
42450
+ input.setRawMode?.(true);
42451
+ input.setEncoding?.("utf8");
42452
+ input.resume();
42453
+ const finish2 = (err) => {
42454
+ input.removeListener("data", onData);
42455
+ input.setRawMode?.(false);
42456
+ input.pause();
42457
+ output.write("\n");
42458
+ if (err !== null) reject(err);
42459
+ else resolve17(value);
42460
+ };
42461
+ const onData = (chunk) => {
42462
+ for (const ch of String(chunk)) {
42463
+ if (ch === "\r" || ch === "\n") return finish2(null);
42464
+ if (ch === "" || ch === "" && value === "") {
42465
+ return finish2(new Error("cancelled"));
42466
+ }
42467
+ if (ch === "\x7F" || ch === "\b") value = value.slice(0, -1);
42468
+ else if (ch >= " ") value += ch;
42469
+ }
42470
+ };
42471
+ input.on("data", onData);
42472
+ });
42473
+ }
42474
+ var MAX_VALUE_BYTES = 8 * 1024;
42475
+ async function readPiped(input) {
42476
+ const chunks = [];
42477
+ let size2 = 0;
42478
+ for await (const chunk of input) {
42479
+ const buf = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
42480
+ size2 += buf.length;
42481
+ if (size2 > MAX_VALUE_BYTES + 2) {
42482
+ throw new Error(`value is longer than ${MAX_VALUE_BYTES} bytes: nothing was stored`);
42483
+ }
42484
+ chunks.push(buf);
42485
+ }
42486
+ return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
42487
+ }
42488
+ async function readSecretValue(name, input = process.stdin, output = process.stderr) {
42489
+ const value = input.isTTY === true ? await promptHidden(`Value for ${name} (not shown): `, input, output) : await readPiped(input);
42490
+ if (value === "") throw new Error("no value given: nothing was stored");
42491
+ return value;
42492
+ }
42493
+ function checkName2(name) {
42494
+ if (!SECRET_NAME_RE.test(name)) {
42495
+ throw new Error(
42496
+ `bad secret name "${name}": 1 to 64 characters, lower-case letters, digits and "_", starting with a letter`
42497
+ );
42498
+ }
42499
+ }
42500
+ function secretPath(appId, name) {
42501
+ const base = `/apps/${encodeURIComponent(appId)}/secrets`;
42502
+ return name === void 0 ? base : `${base}/${encodeURIComponent(name)}`;
42503
+ }
42504
+ function registerSecretsCommand(parent) {
42505
+ const group = parent.command("secrets").description(
42506
+ "Manage an app's secrets (Owner only). The platform sends them for the app; no command shows a value."
42507
+ );
42508
+ withJsonOption(
42509
+ withServerOptions(
42510
+ group.command("set <app-id> <name>").description(
42511
+ "Set a secret. The value comes from a hidden prompt, or from stdin when it is piped."
42512
+ ).allowExcessArguments(false)
42513
+ )
42514
+ ).action(async (appId, name, opts) => {
42515
+ checkName2(name);
42516
+ const value = await readSecretValue(name);
42517
+ const client = await connect(opts);
42518
+ try {
42519
+ const res = await client.request(secretPath(appId, name), {
42520
+ method: "PUT",
42521
+ body: { value }
42522
+ });
42523
+ if (opts.json === true) {
42524
+ printJson(res);
42525
+ return;
42526
+ }
42527
+ process.stdout.write(`Set ${res.name} for ${appId}.
42528
+ `);
42529
+ } finally {
42530
+ client.cleanup();
42531
+ }
42532
+ });
42533
+ withJsonOption(
42534
+ withServerOptions(
42535
+ group.command("list <app-id>").description("List an app's secret names, who set each, and when.")
42536
+ )
42537
+ ).action(async (appId, opts) => {
42538
+ const client = await connect(opts);
42539
+ try {
42540
+ const res = await client.request(secretPath(appId));
42541
+ if (opts.json === true) {
42542
+ printJson(res.secrets);
42543
+ return;
42544
+ }
42545
+ if (res.secrets.length === 0) {
42546
+ process.stdout.write(`No secrets set for ${appId}.
42547
+ `);
42548
+ return;
42549
+ }
42550
+ for (const s of res.secrets) {
42551
+ process.stdout.write(`${s.name} set by ${s.set_by} at ${s.set_at ?? "?"}
42552
+ `);
42553
+ }
42554
+ } finally {
42555
+ client.cleanup();
42556
+ }
42557
+ });
42558
+ withJsonOption(
42559
+ withServerOptions(group.command("remove <app-id> <name>").description("Remove a secret."))
42560
+ ).action(async (appId, name, opts) => {
42561
+ checkName2(name);
42562
+ const client = await connect(opts);
42563
+ try {
42564
+ const res = await client.request(secretPath(appId, name), { method: "DELETE" });
42565
+ if (opts.json === true) {
42566
+ printJson(res);
42567
+ return;
42568
+ }
42569
+ process.stdout.write(`Removed ${name} from ${appId}.
42570
+ `);
42571
+ } finally {
42572
+ client.cleanup();
42573
+ }
42574
+ });
42575
+ }
42576
+
42400
42577
  // src/commands/appspace/tables.ts
42401
42578
  function renderTables(rows2) {
42402
42579
  if (rows2.length === 0) return "No app owns a table you can see.\n";
@@ -42480,6 +42657,7 @@ function registerAppSpaceCommand(root) {
42480
42657
  registerShipCommand(cmd);
42481
42658
  registerEjectCommand(cmd);
42482
42659
  registerPublishCommands(cmd);
42660
+ registerSecretsCommand(cmd);
42483
42661
  }
42484
42662
 
42485
42663
  // src/commands/update.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarails-ai/dr-appspace-cli",
3
- "version": "0.12.72",
3
+ "version": "0.12.74",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {