apiblaze 0.21.28 → 0.21.29

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/index.js +40 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__
34
34
  var version;
35
35
  var init_package = __esm({
36
36
  "package.json"() {
37
- version = "0.21.28";
37
+ version = "0.21.29";
38
38
  }
39
39
  });
40
40
 
@@ -7805,6 +7805,20 @@ async function runDemo(opts = {}) {
7805
7805
  process.exit(1);
7806
7806
  }
7807
7807
  }
7808
+ function titleCard(lines) {
7809
+ const inner = Math.max(...lines.map((l) => l.length)) + 12;
7810
+ const center = (t) => {
7811
+ const left = Math.floor((inner - t.length) / 2);
7812
+ return " ".repeat(left) + t + " ".repeat(inner - t.length - left);
7813
+ };
7814
+ const edge = import_chalk24.default.magenta;
7815
+ console.log();
7816
+ console.log(` ${edge(`\u256D${"\u2500".repeat(inner)}\u256E`)}`);
7817
+ console.log(` ${edge("\u2502")}${" ".repeat(inner)}${edge("\u2502")}`);
7818
+ lines.forEach((l, i) => console.log(` ${edge("\u2502")}${i === 0 ? import_chalk24.default.bold(center(l)) : import_chalk24.default.dim(center(l))}${edge("\u2502")}`));
7819
+ console.log(` ${edge("\u2502")}${" ".repeat(inner)}${edge("\u2502")}`);
7820
+ console.log(` ${edge(`\u2570${"\u2500".repeat(inner)}\u256F`)}`);
7821
+ }
7808
7822
  function printTable(rows) {
7809
7823
  const width = Math.max(100, Math.min(process.stdout.columns || 140, 220));
7810
7824
  const leftW = Math.min(64, Math.max(...rows.map((r) => `\u2713 ${r.label.padEnd(17)} ${r.what}`.length)));
@@ -7822,7 +7836,7 @@ function printTable(rows) {
7822
7836
  return out;
7823
7837
  };
7824
7838
  const head = (l, r) => console.log(` ${import_chalk24.default.dim(l.padEnd(leftW))} ${import_chalk24.default.dim(r)}`);
7825
- head(`What ${B.product} set up`, "The command that does the same");
7839
+ head(`What ${B.product} set up`, "The command that does this");
7826
7840
  head("\u2500".repeat(leftW), "\u2500".repeat(Math.min(rightW, 60)));
7827
7841
  for (const r of rows) {
7828
7842
  const left = `${import_chalk24.default.green("\u2713")} ${import_chalk24.default.bold(r.label.padEnd(17))} ${r.what}`;
@@ -7844,6 +7858,7 @@ async function startDemo(opts) {
7844
7858
  console.log();
7845
7859
  for (const l of lines) console.log(` ${l}`);
7846
7860
  };
7861
+ titleCard(["Restaurant Reservation Service Demo", `ResiResi, with ${B.product} in front`]);
7847
7862
  await stopDemos();
7848
7863
  writeApp(dir);
7849
7864
  const appPort = await freePort(3e3);
@@ -7853,6 +7868,13 @@ async function startDemo(opts) {
7853
7868
  const ninoTenant = `ninopizza${import_crypto.default.randomBytes(2).toString("hex")}`;
7854
7869
  const backendSecret = import_crypto.default.randomBytes(18).toString("base64url");
7855
7870
  const openapi = DEMO_FILES["openapi.yaml"];
7871
+ try {
7872
+ const specPath = import_path5.default.join(dir, "openapi.yaml");
7873
+ import_fs6.default.writeFileSync(specPath, import_fs6.default.readFileSync(specPath, "utf8").replace(/^paths:/m, `servers:
7874
+ - url: http://localhost:${backendPort2}
7875
+ paths:`));
7876
+ } catch {
7877
+ }
7856
7878
  const L = (c) => `${LATEST} ${c}`;
7857
7879
  writeEnv(dir, { BACKEND_SECRET: backendSecret, DEMO_NINO_TENANT: ninoTenant, APP_PORT: appPort, BACKEND_PORT: backendPort2, DIRECT_PORT: directPort });
7858
7880
  console.log();
@@ -7860,6 +7882,12 @@ async function startDemo(opts) {
7860
7882
  console.log(` Written to ${rel}. Its routes, from openapi.yaml:`);
7861
7883
  for (const r of routesOf(openapi)) console.log(` ${r.method.padEnd(7)}${r.path.padEnd(21)}${import_chalk24.default.dim(r.summary)}`);
7862
7884
  console.log(import_chalk24.default.dim(" No login, no API keys, no permission checks in its code. It only checks one shared backend secret (in .env.local)."));
7885
+ if (!await confirmStep(opts, `Ok to serve the backend on localhost:${backendPort2}?`)) {
7886
+ return stopHere([
7887
+ `Stopped before starting anything. ResiResi is written to ${rel}.`,
7888
+ `Start it any time: ${cdDir}npm run start ${import_chalk24.default.dim("\xB7")} or run the whole demo again: ${LATEST} demo`
7889
+ ]);
7890
+ }
7863
7891
  shell(`${cdDir}npm run start`, "npm run stop \xB7 npm run restart");
7864
7892
  if (!appCtl(dir, "--background")) throw new DemoError("The ResiResi app could not start.", `Run again: ${LATEST} demo`);
7865
7893
  registerDemo(dir);
@@ -7942,11 +7970,13 @@ async function startDemo(opts) {
7942
7970
  const state = { name: project, version: version2, tenant: tenant2, teamId, cpKey, appPort, backendPort: backendPort2, apiUrl, claimCode: setup.claimCode };
7943
7971
  saveState(dir, state);
7944
7972
  printTable([
7945
- { label: "Proxy", what: `${project} (${createSecs} s, no account)`, cmds: [L(`dev --port ${backendPort2} --openapi ./openapi.yaml --name ${name} --tenant ${ninoTenant} --auto`)] },
7973
+ // `create` from the spec in the folder (it names localhost:<backend port> under servers:); step 3's
7974
+ // `dev --project` then opens the tunnel to that same proxy and creates nothing.
7975
+ { label: "Proxy", what: `${project} (${createSecs} s, no account)`, cmds: [L(`create --target ./openapi.yaml --name ${name} --tenant ${ninoTenant} --auto`)] },
7946
7976
  {
7947
7977
  label: "Customers/Tenants",
7948
7978
  what: gino ? "Nino Pizza and Gino Pizza, own API keys" : "Nino Pizza, its own API key",
7949
- cmds: gino?.tenant ? [L(`tenant create --name "Gino Pizza" --slug ${gino.tenant}`), L(`tenant attach ${project} --tenant ${gino.tenant}`), L(`apikeys mint --tenant ${gino.tenant} --backend --env dev`)] : []
7979
+ cmds: gino?.tenant ? [L(`tenant create --name "Gino Pizza" --slug ${gino.tenant}`), L(`tenant attach ${project} --tenant ${gino.tenant}`)] : []
7950
7980
  },
7951
7981
  ...adminOk ? [{
7952
7982
  label: "Admins",
@@ -7954,10 +7984,14 @@ async function startDemo(opts) {
7954
7984
  cmds: [L(`admins add ${DEMO_ADMIN_EMAIL} --tenant ${tenant2}`), ...ginaOk && gino?.tenant ? [L(`admins add ${DEMO_GINO_ADMIN_EMAIL} --tenant ${gino.tenant}`)] : []]
7955
7985
  }] : [],
7956
7986
  ...applied.length ? [{ label: "Rules", what: "only who made a reservation can change it", cmds: [L(`rule ${project} "${RULE_SENTENCE}"`)] }] : [],
7957
- { label: "AI (MCP Tools)", what: `${tools.length} tools, one per route`, cmds: ["(part of dev, above)"] },
7987
+ { label: "AI (MCP Tools)", what: `${tools.length} tools, one per route`, cmds: ["(part of create, above)"] },
7958
7988
  ...limited ? [{ label: "Limits", what: `${DEMO_RPS} calls a second per customer`, cmds: [L(`limits set ${project} --rate ${DEMO_RPS} --end-user-rate ${DEMO_RPS}`)] }] : [],
7959
7989
  { label: "Backend secret", what: "added to every call APIblaze forwards", cmds: [L(`transform ${project} set-header x-target-api-key --value-env BACKEND_SECRET --secret`)] },
7960
- { label: "Keys", what: "saved to .env.local, never printed", cmds: [] }
7990
+ {
7991
+ label: "Keys",
7992
+ what: "saved to .env.local, never printed",
7993
+ cmds: [L(`apikeys mint --tenant ${tenant2} --backend --env dev`), ...gino?.tenant ? [L(`apikeys mint --tenant ${gino.tenant} --backend --env dev`)] : []]
7994
+ }
7961
7995
  ]);
7962
7996
  if (!await confirmStep(opts, `Ok to create a tunnel allowing ${project} to forward requests to localhost:${backendPort2}?`)) {
7963
7997
  return stopHere([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.21.28",
3
+ "version": "0.21.29",
4
4
  "description": "APIblaze CLI — Chat with your APIs, Manage your API keys, users and groups with the APIblaze serverless proxy",
5
5
  "keywords": [
6
6
  "apiblaze",