@nodegx/backend 0.1.2 → 0.1.3

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
@@ -10,6 +10,9 @@ charging you.
10
10
 
11
11
  ## Use
12
12
 
13
+ The guide, a section for every step the deploy prints: https://the-low-code-foundation.github.io/NodeGX/docs/deploy/cloudflare
14
+
15
+
13
16
  ```sh
14
17
  npx @nodegx/backend sign-in cloudflare
15
18
  npx @nodegx/backend deploy cloudflare ./my-app --no-bucket
@@ -42,6 +45,17 @@ The deployment's folder is `~/.nodegx/cloudflare/<name>/`. Its `deployment.json`
42
45
  backend's admin credential, readable only by you. The credential is never uploaded; the deploy checks every file
43
46
  before it uploads anything. The backend's dashboard is at `<address>/_admin`.
44
47
 
48
+ ## Secrets and the dashboard
49
+
50
+ A secret a cloud function reads with a Secret node (an API key, a token) does not travel with a deploy. The ones set
51
+ on your computer, on the backend's Secrets page or in the app's `.env`, stay there. After its last step the deploy
52
+ lists the secrets the functions read and says which ones the backend on Cloudflare lacks.
53
+
54
+ Set them on the backend's own dashboard, at `<address>/_admin` (with the underscore), under **Settings → Secrets**.
55
+ They are not set in Cloudflare's dashboard. Sign in the first time with the `adminToken` from `deployment.json`
56
+ (on Windows, `C:\Users\<you>\.nodegx\cloudflare\<name>\deployment.json`). A redeploy keeps what you set.
57
+ More: https://the-low-code-foundation.github.io/NodeGX/docs/deploy/cloudflare#secrets
58
+
45
59
  `npx @nodegx/backend domain find <words>` finds a name that is free and its price. `domain buy` buys one only when
46
60
  you repeat its exact price back. Buying needs Cloudflare's own `cf` command signed in, because wrangler's sign-in
47
61
  cannot buy names.
@@ -32,7 +32,8 @@ const HELP = `@nodegx/backend ${PKG.version} — put a NodeGX app online on your
32
32
  npx @nodegx/backend domain find|check|buy|status|email …
33
33
  Finds and buys the app's own name on your Cloudflare account, and sets up its email.
34
34
 
35
- Every option of deploy: npx @nodegx/backend deploy cloudflare --help`;
35
+ Every option of deploy: npx @nodegx/backend deploy cloudflare --help
36
+ The guide, step by step: https://the-low-code-foundation.github.io/NodeGX/docs/deploy/cloudflare`;
36
37
 
37
38
  /** A file inside an installed package, found the way Node finds the package (no `exports` map in the way). */
38
39
  function packageFile(name, rel) {
@@ -251,14 +251,14 @@ var require_model = __commonJS({
251
251
  };
252
252
  Model2.prototype.set = function(name2, value2, args) {
253
253
  if (args && args.resolve && name2.indexOf(".") !== -1) {
254
- var path5 = name2.split(".");
254
+ var path6 = name2.split(".");
255
255
  var model = this;
256
- for (var i = 0; i < path5.length - 1; i++) {
257
- var v = model.get(path5[i]);
256
+ for (var i = 0; i < path6.length - 1; i++) {
257
+ var v = model.get(path6[i]);
258
258
  if (Model2.instanceOf(v)) model = v;
259
259
  else return;
260
260
  }
261
- model.set(path5[path5.length - 1], value2);
261
+ model.set(path6[path6.length - 1], value2);
262
262
  return;
263
263
  }
264
264
  const forceChange = args && args.forceChange;
@@ -271,14 +271,14 @@ var require_model = __commonJS({
271
271
  };
272
272
  Model2.prototype.get = function(name2, args) {
273
273
  if (args && args.resolve && name2.indexOf(".") !== -1) {
274
- var path5 = name2.split(".");
274
+ var path6 = name2.split(".");
275
275
  var model = this;
276
- for (var i = 0; i < path5.length - 1; i++) {
277
- var v = model.get(path5[i]);
276
+ for (var i = 0; i < path6.length - 1; i++) {
277
+ var v = model.get(path6[i]);
278
278
  if (Model2.instanceOf(v)) model = v;
279
279
  else return;
280
280
  }
281
- return model.get(path5[path5.length - 1]);
281
+ return model.get(path6[path6.length - 1]);
282
282
  }
283
283
  return this.data[name2];
284
284
  };
@@ -3117,13 +3117,13 @@ var require_node = __commonJS({
3117
3117
  const runContext = scope && scope.runContext;
3118
3118
  if (!runContext || !runContext.beginStep || !runContext.endStep) return;
3119
3119
  const recordValues = !!runContext.recordValues;
3120
- const step = runContext.beginStep({
3120
+ const step2 = runContext.beginStep({
3121
3121
  nodeId: this.id,
3122
3122
  nodeType: this.name,
3123
3123
  ...recordValues ? { inputs: snapshotInputValues(this) } : {}
3124
3124
  });
3125
- if (step !== void 0 && step !== null) {
3126
- runContext.endStep(step, {
3125
+ if (step2 !== void 0 && step2 !== null) {
3126
+ runContext.endStep(step2, {
3127
3127
  status: "failure",
3128
3128
  code,
3129
3129
  message,
@@ -3261,13 +3261,13 @@ var require_node = __commonJS({
3261
3261
  this._raisingForOutcome = false;
3262
3262
  if (tokenCause && traceContext && traceContext.traceEnabled) traceContext._currentCause = causeBefore;
3263
3263
  }
3264
- const step = token.step;
3265
- if (step !== void 0 && step !== null) {
3264
+ const step2 = token.step;
3265
+ if (step2 !== void 0 && step2 !== null) {
3266
3266
  token.step = void 0;
3267
3267
  const scope = this.nodeScope;
3268
3268
  const runContext = scope && scope.runContext;
3269
3269
  if (runContext && runContext.endStep) {
3270
- runContext.endStep(step, {
3270
+ runContext.endStep(step2, {
3271
3271
  status: outcome,
3272
3272
  code: options && options.code,
3273
3273
  message: options && options.message,
@@ -3742,9 +3742,9 @@ __export(deployCloudflare_exports, {
3742
3742
  module.exports = __toCommonJS(deployCloudflare_exports);
3743
3743
  var import_node_child_process = require("node:child_process");
3744
3744
  var crypto4 = __toESM(require("node:crypto"));
3745
- var fs5 = __toESM(require("node:fs"));
3745
+ var fs6 = __toESM(require("node:fs"));
3746
3746
  var os2 = __toESM(require("node:os"));
3747
- var path4 = __toESM(require("node:path"));
3747
+ var path5 = __toESM(require("node:path"));
3748
3748
 
3749
3749
  // ../noodl-runtime/src/nodes/std-library/expression-ports.ts
3750
3750
  var EXPRESSION_MATH_ALIASES = [
@@ -4314,11 +4314,11 @@ function namedRoles(config) {
4314
4314
  // ../nodegx-backend/cloudflare/applyProject.ts
4315
4315
  var ApplyError = class extends Error {
4316
4316
  };
4317
- async function must(call, method, path5, body) {
4318
- const answer = await call(method, path5, body);
4317
+ async function must(call, method, path6, body) {
4318
+ const answer = await call(method, path6, body);
4319
4319
  if (answer.status >= 300) {
4320
4320
  const said = answer.json?.error ?? answer.text.slice(0, 600);
4321
- throw new ApplyError(`${method} /${path5.replace(/^\//, "")} answered ${answer.status}: ${said}`);
4321
+ throw new ApplyError(`${method} /${path6.replace(/^\//, "")} answered ${answer.status}: ${said}`);
4322
4322
  }
4323
4323
  return answer;
4324
4324
  }
@@ -4419,11 +4419,11 @@ async function applyProject(call, project, options) {
4419
4419
  function automationsSha256(text) {
4420
4420
  return crypto.createHash("sha256").update(text).digest("hex");
4421
4421
  }
4422
- async function must2(call, method, path5, body) {
4423
- const answer = await call(method, path5, body);
4422
+ async function must2(call, method, path6, body) {
4423
+ const answer = await call(method, path6, body);
4424
4424
  if (answer.status >= 300) {
4425
4425
  const said = answer.json?.error ?? answer.text.slice(0, 600);
4426
- throw new ApplyError(`${method} /${path5.replace(/^\//, "")} answered ${answer.status}: ${said}`);
4426
+ throw new ApplyError(`${method} /${path6.replace(/^\//, "")} answered ${answer.status}: ${said}`);
4427
4427
  }
4428
4428
  return answer;
4429
4429
  }
@@ -4527,7 +4527,7 @@ ${differences.map((d) => ` - ${d}`).join("\n")}
4527
4527
  undo.push(() => call("POST", "/admin/workflow-defs", projectWorkflow(w)));
4528
4528
  }
4529
4529
  } catch (e) {
4530
- for (const step of undo.reverse()) await step().catch(() => void 0);
4530
+ for (const step2 of undo.reverse()) await step2().catch(() => void 0);
4531
4531
  throw new ApplyError(
4532
4532
  `nodegx.automations.json could not be carried to the backend, so none of it was (the backend's are as they were): ${e.message}`
4533
4533
  );
@@ -5004,6 +5004,67 @@ async function inPublicDns(f, host) {
5004
5004
  }
5005
5005
  }
5006
5006
 
5007
+ // ../nodegx-backend/cloudflare/guide.ts
5008
+ var GUIDE_URL = "https://the-low-code-foundation.github.io/NodeGX/docs/deploy/cloudflare";
5009
+ var GUIDE_SECTIONS = {
5010
+ signIn: "sign-in",
5011
+ functions: "cloud-functions",
5012
+ site: "the-site",
5013
+ worker: "the-worker",
5014
+ private: "nothing-private",
5015
+ upload: "upload",
5016
+ project: "the-project-onto-the-backend",
5017
+ secrets: "secrets",
5018
+ dashboard: "the-dashboard"
5019
+ };
5020
+ function guideLink(section) {
5021
+ return section ? `${GUIDE_URL}#${GUIDE_SECTIONS[section]}` : GUIDE_URL;
5022
+ }
5023
+ var SECRET_NODE_TYPE = "noodl.cloud.secret";
5024
+ function secretNamesRead(components) {
5025
+ const names = /* @__PURE__ */ new Set();
5026
+ const visit = (n) => {
5027
+ const name2 = n.parameters?.name;
5028
+ if (n.type === SECRET_NODE_TYPE && typeof name2 === "string" && name2.trim()) names.add(name2.trim());
5029
+ (n.children || []).forEach(visit);
5030
+ };
5031
+ components.forEach((c) => (c.nodes || []).forEach(visit));
5032
+ return [...names].sort();
5033
+ }
5034
+ function secretsReport(o) {
5035
+ if (!o.read.length) return [];
5036
+ const setHere = new Set((o.listing?.secrets ?? []).map((s) => s.name));
5037
+ const prefix = o.listing?.envPrefix ?? "NODEGX_SECRET_";
5038
+ for (const v of o.listing?.environment ?? []) if (v.startsWith(prefix)) setHere.add(v.slice(prefix.length));
5039
+ const page = `${o.dashboard}#/secrets`;
5040
+ const signIn = `Sign in there with the adminToken in ${o.credentialFile}.`;
5041
+ if (!o.listing) {
5042
+ return [
5043
+ `Secrets the functions read: ${o.read.join(", ")}. This backend could not be asked which are set.`,
5044
+ `Check them on its Secrets page, ${page}. ${signIn}`,
5045
+ `Help: ${guideLink("secrets")}`
5046
+ ];
5047
+ }
5048
+ const missing = o.read.filter((n) => !setHere.has(n));
5049
+ const set = o.read.filter((n) => setHere.has(n));
5050
+ if (!missing.length) return [`Secrets the functions read: ${set.join(", ")}. All are set on this backend.`];
5051
+ const env = new Set(o.inEnvFile);
5052
+ const lines = [
5053
+ `Secrets the functions read: ${o.read.length}. Set on this backend: ${set.length ? set.join(", ") : "none"}.`,
5054
+ `NOT set on this backend: ${missing.join(", ")}. A function that reads one fails until it is set.`
5055
+ ];
5056
+ const fromEnv = missing.filter((n) => env.has(n));
5057
+ if (fromEnv.length) {
5058
+ lines.push(`Your app's .env has ${fromEnv.join(", ")}. That file stays on this computer, so copy each value across.`);
5059
+ }
5060
+ lines.push(
5061
+ `A secret does not travel with a deploy. Set each one on the backend's own Secrets page, ${page}, not in Cloudflare's dashboard.`,
5062
+ `${signIn} A redeploy keeps what you set.`,
5063
+ `Help: ${guideLink("secrets")}`
5064
+ );
5065
+ return lines;
5066
+ }
5067
+
5007
5068
  // ../nodegx-backend/cloudflare/wranglerConfig.ts
5008
5069
  function emailProblem(what, address) {
5009
5070
  return /^[^\s@<>"]+@[a-z0-9-]+(\.[a-z0-9-]+)+$/i.test(address) ? null : `${what} "${address}" is not an email address (write it bare, like alerts@example.com).`;
@@ -5129,12 +5190,58 @@ function spawnFailure(command, error) {
5129
5190
  return `wrangler could not be started (${command.join(" ")}: ${code || error.message}). Install it with \`npm install -g wrangler@4\` and point the deploy at it with NODEGX_WRANGLER set to its bin/wrangler.js.`;
5130
5191
  }
5131
5192
 
5193
+ // ../nodegx-backend/src/config/projectEnvFile.ts
5194
+ var fs5 = __toESM(require("fs"));
5195
+ var path4 = __toESM(require("path"));
5196
+
5197
+ // ../nodegx-backend/src/config/SecretsStore.ts
5198
+ var FUNCTION_SECRET_NAME_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/;
5199
+
5200
+ // ../nodegx-backend/src/config/projectEnvFile.ts
5201
+ var PROJECT_ENV_FILE = ".env";
5202
+ var LINE = /^(?:export\s+)?([A-Za-z0-9_.-]+)\s*=(.*)$/;
5203
+ function lineValue(raw) {
5204
+ let value2 = raw.trim();
5205
+ if (value2.length >= 2 && (value2[0] === '"' || value2[0] === "'") && value2[value2.length - 1] === value2[0]) {
5206
+ value2 = value2.slice(1, -1);
5207
+ }
5208
+ return value2;
5209
+ }
5210
+ function readText(projectDir) {
5211
+ if (!projectDir) return null;
5212
+ try {
5213
+ return fs5.readFileSync(path4.join(projectDir, PROJECT_ENV_FILE), "utf8");
5214
+ } catch {
5215
+ return null;
5216
+ }
5217
+ }
5218
+ function projectEnvSecretNames(projectDir) {
5219
+ const text = readText(projectDir);
5220
+ if (text === null) return [];
5221
+ const seen = /* @__PURE__ */ new Set();
5222
+ const filled = [];
5223
+ for (const raw of text.split(/\r?\n/)) {
5224
+ const line = raw.trim();
5225
+ if (!line || line.startsWith("#")) continue;
5226
+ const m = LINE.exec(line);
5227
+ if (!m || seen.has(m[1])) continue;
5228
+ seen.add(m[1]);
5229
+ if (FUNCTION_SECRET_NAME_PATTERN.test(m[1]) && lineValue(m[2])) filled.push(m[1]);
5230
+ }
5231
+ return filled.sort();
5232
+ }
5233
+
5132
5234
  // ../nodegx-backend/cloudflare/deployCloudflare.ts
5133
5235
  var HERE = process.env.NODEGX_CLOUDFLARE_SRC || __dirname;
5134
- var PACKAGES = path4.resolve(HERE, "..", "..");
5236
+ var PACKAGES = path5.resolve(HERE, "..", "..");
5135
5237
  var DeployError = class extends Error {
5136
5238
  };
5137
5239
  var say = (line = "") => process.stdout.write(line + "\n");
5240
+ var stage = null;
5241
+ function step(title, section) {
5242
+ stage = section;
5243
+ say(`${title} (help: ${guideLink(section)})`);
5244
+ }
5138
5245
  var PROGRAM = process.env.NODEGX_CLOUDFLARE_COMMAND || "deploy.mjs";
5139
5246
  var USAGE = `usage: ${PROGRAM} <project> [--name <worker>] [--bucket <r2 bucket> | --no-bucket] [--viewer <folder>]
5140
5247
  [--allow-development-engine] [--out <folder>] [--local [--port <n>]] [--make-roles]
@@ -5154,9 +5261,9 @@ ${USAGE}`);
5154
5261
  if (a === "--name") o.name = next();
5155
5262
  else if (a === "--bucket") o.bucket = next();
5156
5263
  else if (a === "--no-bucket") o.bucket = null;
5157
- else if (a === "--viewer") o.viewer = path4.resolve(next());
5264
+ else if (a === "--viewer") o.viewer = path5.resolve(next());
5158
5265
  else if (a === "--allow-development-engine") o.allowDevelopmentEngine = true;
5159
- else if (a === "--out") o.out = path4.resolve(next());
5266
+ else if (a === "--out") o.out = path5.resolve(next());
5160
5267
  else if (a === "--local") o.local = true;
5161
5268
  else if (a === "--port") o.port = Number(next());
5162
5269
  else if (a === "--make-roles") o.makeRoles = true;
@@ -5171,7 +5278,7 @@ ${USAGE}`);
5171
5278
  else if (a === "--account") o.account = next().trim();
5172
5279
  else if (a.startsWith("--")) throw new DeployError(`${a} is not an option.
5173
5280
  ${USAGE}`);
5174
- else if (!o.project) o.project = path4.resolve(a);
5281
+ else if (!o.project) o.project = path5.resolve(a);
5175
5282
  else throw new DeployError(`One project at a time.
5176
5283
  ${USAGE}`);
5177
5284
  }
@@ -5179,20 +5286,20 @@ ${USAGE}`);
5179
5286
  return o;
5180
5287
  }
5181
5288
  function readProject(dir) {
5182
- const file = path4.join(dir, "nodegx.project.json");
5183
- if (!fs5.existsSync(file)) throw new DeployError(`${dir} is not a NodeGX project: it has no nodegx.project.json.`);
5184
- const json = JSON.parse(fs5.readFileSync(file, "utf8"));
5185
- const policyFile = path4.join(dir, "nodegx.security.json");
5186
- const policyText = fs5.existsSync(policyFile) ? fs5.readFileSync(policyFile, "utf8") : null;
5289
+ const file = path5.join(dir, "nodegx.project.json");
5290
+ if (!fs6.existsSync(file)) throw new DeployError(`${dir} is not a NodeGX project: it has no nodegx.project.json.`);
5291
+ const json = JSON.parse(fs6.readFileSync(file, "utf8"));
5292
+ const policyFile = path5.join(dir, "nodegx.security.json");
5293
+ const policyText = fs6.existsSync(policyFile) ? fs6.readFileSync(policyFile, "utf8") : null;
5187
5294
  if (policyText) JSON.parse(policyText);
5188
- const automationsFile = path4.join(dir, "nodegx.automations.json");
5189
- const automationsText = fs5.existsSync(automationsFile) ? fs5.readFileSync(automationsFile, "utf8") : null;
5295
+ const automationsFile = path5.join(dir, "nodegx.automations.json");
5296
+ const automationsText = fs6.existsSync(automationsFile) ? fs6.readFileSync(automationsFile, "utf8") : null;
5190
5297
  if (automationsText) JSON.parse(automationsText);
5191
- const envFile = path4.join(dir, ".env");
5192
- const envValues = fs5.existsSync(envFile) ? fs5.readFileSync(envFile, "utf8").split("\n").map((l) => l.replace(/^\s*(export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=\s*/, "").replace(/^['"]|['"]\s*$/g, "").trim()).filter((v) => v.length >= 8) : [];
5298
+ const envFile = path5.join(dir, ".env");
5299
+ const envValues = fs6.existsSync(envFile) ? fs6.readFileSync(envFile, "utf8").split("\n").map((l) => l.replace(/^\s*(export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=\s*/, "").replace(/^['"]|['"]\s*$/g, "").trim()).filter((v) => v.length >= 8) : [];
5193
5300
  return {
5194
5301
  dir,
5195
- name: json.name || path4.basename(dir),
5302
+ name: json.name || path5.basename(dir),
5196
5303
  file: json,
5197
5304
  policyText,
5198
5305
  automationsText,
@@ -5201,20 +5308,20 @@ function readProject(dir) {
5201
5308
  };
5202
5309
  }
5203
5310
  function deploymentsRoot() {
5204
- return process.env.NODEGX_CLOUDFLARE_HOME || path4.join(os2.homedir(), ".nodegx", "cloudflare");
5311
+ return process.env.NODEGX_CLOUDFLARE_HOME || path5.join(os2.homedir(), ".nodegx", "cloudflare");
5205
5312
  }
5206
5313
  function readRecord(dir) {
5207
- const file = path4.join(dir, "deployment.json");
5208
- return fs5.existsSync(file) ? JSON.parse(fs5.readFileSync(file, "utf8")) : null;
5314
+ const file = path5.join(dir, "deployment.json");
5315
+ return fs6.existsSync(file) ? JSON.parse(fs6.readFileSync(file, "utf8")) : null;
5209
5316
  }
5210
5317
  function writeRecord(dir, record) {
5211
- const file = path4.join(dir, "deployment.json");
5212
- fs5.writeFileSync(file, JSON.stringify(record, null, 2) + "\n", { mode: 384 });
5213
- fs5.chmodSync(file, 384);
5318
+ const file = path5.join(dir, "deployment.json");
5319
+ fs6.writeFileSync(file, JSON.stringify(record, null, 2) + "\n", { mode: 384 });
5320
+ fs6.chmodSync(file, 384);
5214
5321
  }
5215
5322
  function cloudFunctions(projectDir) {
5216
- const entry = process.env.NODEGX_CLOUD_BUNDLE || path4.join(PACKAGES, "noodl-mcp", "dist", "cloud-bundle.cjs");
5217
- if (!fs5.existsSync(entry)) {
5323
+ const entry = process.env.NODEGX_CLOUD_BUNDLE || path5.join(PACKAGES, "noodl-mcp", "dist", "cloud-bundle.cjs");
5324
+ if (!fs6.existsSync(entry)) {
5218
5325
  throw new DeployError(`The cloud-function bundler is not here (${entry}): run \`npm run build\` in packages/noodl-mcp.`);
5219
5326
  }
5220
5327
  const run = (0, import_node_child_process.spawnSync)(process.execPath, [entry, projectDir], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 12e4 });
@@ -5225,8 +5332,8 @@ ${(run.stderr || "").trim() || "no output"}`);
5225
5332
  var NOT_FOR_THE_HOST = ["DEPLOY.md", "serve.js", "package.json", ".nodegx-deploy.json", "nodegx-config.json"];
5226
5333
  var VIEWER_HINT = "\nName a production viewer with --viewer <folder holding noodl.deploy.js>.";
5227
5334
  function siteThroughCli(copy, out, allowDev) {
5228
- const cli = process.env.NODEGX_CLI || path4.join(PACKAGES, "nodegx-export", "dist", "cli.mjs");
5229
- if (!process.env.NODEGX_CLI && process.env.NODEGX_DEPLOY_CLI && !fs5.existsSync(cli)) return null;
5335
+ const cli = process.env.NODEGX_CLI || path5.join(PACKAGES, "nodegx-export", "dist", "cli.mjs");
5336
+ if (!process.env.NODEGX_CLI && process.env.NODEGX_DEPLOY_CLI && !fs6.existsSync(cli)) return null;
5230
5337
  const args = [cli, "deploy", copy, out];
5231
5338
  if (allowDev) args.push("--allow-development-engine");
5232
5339
  const run = (0, import_node_child_process.spawnSync)(process.execPath, args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
@@ -5238,7 +5345,7 @@ ${(run.stdout + run.stderr).trim()}` + (run.status === 11 ? VIEWER_HINT : ""));
5238
5345
  }
5239
5346
  function siteThroughEngine(copy, out, allowDev) {
5240
5347
  const engine = process.env.NODEGX_DEPLOY_CLI;
5241
- if (!fs5.existsSync(engine)) throw new DeployError(`NODEGX_DEPLOY_CLI is set to ${engine}, and there is nothing there.`);
5348
+ if (!fs6.existsSync(engine)) throw new DeployError(`NODEGX_DEPLOY_CLI is set to ${engine}, and there is nothing there.`);
5242
5349
  const args = [engine, copy, out];
5243
5350
  if (allowDev) args.push("--allow-development-engine");
5244
5351
  const run = (0, import_node_child_process.spawnSync)(process.execPath, args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
@@ -5262,45 +5369,45 @@ ${report.blank}`);
5262
5369
  return notes;
5263
5370
  }
5264
5371
  function buildSite(project, name2, siteDir, o) {
5265
- const work = fs5.mkdtempSync(path4.join(os2.tmpdir(), "nodegx-cf-site-"));
5372
+ const work = fs6.mkdtempSync(path5.join(os2.tmpdir(), "nodegx-cf-site-"));
5266
5373
  try {
5267
- const copy = path4.join(work, "project");
5268
- fs5.cpSync(project.dir, copy, { recursive: true, filter: (src) => !/[/\\](\.git|node_modules|\.previews)$/.test(src) });
5269
- const json = JSON.parse(fs5.readFileSync(path4.join(copy, "nodegx.project.json"), "utf8"));
5374
+ const copy = path5.join(work, "project");
5375
+ fs6.cpSync(project.dir, copy, { recursive: true, filter: (src) => !/[/\\](\.git|node_modules|\.previews)$/.test(src) });
5376
+ const json = JSON.parse(fs6.readFileSync(path5.join(copy, "nodegx.project.json"), "utf8"));
5270
5377
  json.metadata = { ...json.metadata || {}, cloudservices: { endpoint: "", appId: name2, instanceId: name2, type: "nodegx" } };
5271
- fs5.writeFileSync(path4.join(copy, "nodegx.project.json"), JSON.stringify(json, null, 2));
5272
- const out = path4.join(work, "site");
5378
+ fs6.writeFileSync(path5.join(copy, "nodegx.project.json"), JSON.stringify(json, null, 2));
5379
+ const out = path5.join(work, "site");
5273
5380
  const allowDev = !!(o.viewer || o.allowDevelopmentEngine);
5274
5381
  const notes = siteThroughCli(copy, out, allowDev) ?? siteThroughEngine(copy, out, allowDev);
5275
5382
  if (o.viewer) {
5276
5383
  for (const f of ["noodl.deploy.js", "noodl.deploy.js.LICENSE.txt"]) {
5277
- const from = path4.join(o.viewer, f);
5278
- if (fs5.existsSync(from)) fs5.copyFileSync(from, path4.join(out, f));
5384
+ const from = path5.join(o.viewer, f);
5385
+ if (fs6.existsSync(from)) fs6.copyFileSync(from, path5.join(out, f));
5279
5386
  else if (f === "noodl.deploy.js") throw new DeployError(`--viewer ${o.viewer} holds no noodl.deploy.js.`);
5280
5387
  }
5281
- const engine = readViewerBuild(path4.join(out, "noodl.deploy.js"));
5388
+ const engine = readViewerBuild(path5.join(out, "noodl.deploy.js"));
5282
5389
  if (engine.kind !== "production") {
5283
5390
  throw new DeployError(`--viewer ${o.viewer} is a DEVELOPMENT build of the viewer: ${engine.reasons.join("; ")}.`);
5284
5391
  }
5285
5392
  notes.push(`viewer: production, from ${o.viewer} (${(engine.bytes / 1e6).toFixed(2)} MB)`);
5286
5393
  }
5287
- for (const f of NOT_FOR_THE_HOST) fs5.rmSync(path4.join(out, f), { force: true });
5288
- const hidden = filesUnder2(out).filter((f) => path4.relative(out, f).split(path4.sep).some((part) => part.startsWith(".")));
5289
- for (const f of hidden) fs5.rmSync(f, { force: true });
5290
- if (hidden.length) notes.push(`left out (hidden files are never published): ${hidden.map((f) => path4.relative(out, f)).join(", ")}`);
5291
- fs5.rmSync(siteDir, { recursive: true, force: true });
5292
- fs5.cpSync(out, siteDir, { recursive: true });
5394
+ for (const f of NOT_FOR_THE_HOST) fs6.rmSync(path5.join(out, f), { force: true });
5395
+ const hidden = filesUnder2(out).filter((f) => path5.relative(out, f).split(path5.sep).some((part) => part.startsWith(".")));
5396
+ for (const f of hidden) fs6.rmSync(f, { force: true });
5397
+ if (hidden.length) notes.push(`left out (hidden files are never published): ${hidden.map((f) => path5.relative(out, f)).join(", ")}`);
5398
+ fs6.rmSync(siteDir, { recursive: true, force: true });
5399
+ fs6.cpSync(out, siteDir, { recursive: true });
5293
5400
  return notes;
5294
5401
  } finally {
5295
- fs5.rmSync(work, { recursive: true, force: true });
5402
+ fs6.rmSync(work, { recursive: true, force: true });
5296
5403
  }
5297
5404
  }
5298
5405
  async function bundleWorker(outfile, plugins = [], esbuild = require("esbuild")) {
5299
- const { shared } = require(path4.join(HERE, "..", "scripts", "build.js"));
5300
- const nodeSqlite = path4.join(HERE, "nodeSqlite.ts");
5406
+ const { shared } = require(path5.join(HERE, "..", "scripts", "build.js"));
5407
+ const nodeSqlite = path5.join(HERE, "nodeSqlite.ts");
5301
5408
  await esbuild.build({
5302
5409
  ...shared,
5303
- entryPoints: [path4.join(HERE, "worker.ts")],
5410
+ entryPoints: [path5.join(HERE, "worker.ts")],
5304
5411
  outfile,
5305
5412
  format: "esm",
5306
5413
  target: "es2022",
@@ -5328,35 +5435,35 @@ async function bundleWorker(outfile, plugins = [], esbuild = require("esbuild"))
5328
5435
  }
5329
5436
  var WORKER_OWN_MODULES = ["./printed-code.mjs", "./app.mjs"];
5330
5437
  async function buildWorker(distDir, app, printed) {
5331
- fs5.mkdirSync(distDir, { recursive: true });
5332
- fs5.writeFileSync(path4.join(distDir, "printed-code.mjs"), printed);
5333
- fs5.writeFileSync(path4.join(distDir, "app.mjs"), `export default ${JSON.stringify(app)};
5438
+ fs6.mkdirSync(distDir, { recursive: true });
5439
+ fs6.writeFileSync(path5.join(distDir, "printed-code.mjs"), printed);
5440
+ fs6.writeFileSync(path5.join(distDir, "app.mjs"), `export default ${JSON.stringify(app)};
5334
5441
  `);
5335
5442
  const prebuilt = process.env.NODEGX_CLOUDFLARE_WORKER;
5336
5443
  if (prebuilt) {
5337
- if (!fs5.existsSync(prebuilt)) throw new DeployError(`The prebuilt Worker is not here (${prebuilt}): this copy of the deploy is incomplete.`);
5338
- fs5.copyFileSync(prebuilt, path4.join(distDir, "worker.mjs"));
5444
+ if (!fs6.existsSync(prebuilt)) throw new DeployError(`The prebuilt Worker is not here (${prebuilt}): this copy of the deploy is incomplete.`);
5445
+ fs6.copyFileSync(prebuilt, path5.join(distDir, "worker.mjs"));
5339
5446
  return "prebuilt";
5340
5447
  }
5341
- await bundleWorker(path4.join(distDir, "worker.mjs"));
5448
+ await bundleWorker(path5.join(distDir, "worker.mjs"));
5342
5449
  return "bundled";
5343
5450
  }
5344
5451
  function filesUnder2(dir) {
5345
5452
  const out = [];
5346
5453
  const walk = (d) => {
5347
- for (const e of fs5.readdirSync(d, { withFileTypes: true })) {
5348
- const full = path4.join(d, e.name);
5454
+ for (const e of fs6.readdirSync(d, { withFileTypes: true })) {
5455
+ const full = path5.join(d, e.name);
5349
5456
  if (e.isDirectory()) walk(full);
5350
5457
  else out.push(full);
5351
5458
  }
5352
5459
  };
5353
- if (fs5.existsSync(dir)) walk(dir);
5460
+ if (fs6.existsSync(dir)) walk(dir);
5354
5461
  return out;
5355
5462
  }
5356
5463
  function leaks(files, secrets) {
5357
5464
  const found = [];
5358
5465
  for (const f of files) {
5359
- const text = fs5.readFileSync(f, "latin1");
5466
+ const text = fs6.readFileSync(f, "latin1");
5360
5467
  for (const s of secrets) if (s.value && text.includes(s.value)) found.push(`${s.what} is in ${f}`);
5361
5468
  }
5362
5469
  return found;
@@ -5431,8 +5538,8 @@ async function applyEverything(base, token, project, functions, makeRoles, where
5431
5538
  const target = where.local ? "local" : "live";
5432
5539
  const automations = await applyAutomations(call, project.automationsText, { installedSha256: where.record.automations?.[target] ?? null });
5433
5540
  if (automations.before) {
5434
- const kept = path4.join(where.dir, `automations.before-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`);
5435
- fs5.writeFileSync(kept, JSON.stringify(automations.before, null, 2) + "\n");
5541
+ const kept = path5.join(where.dir, `automations.before-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`);
5542
+ fs6.writeFileSync(kept, JSON.stringify(automations.before, null, 2) + "\n");
5436
5543
  automations.lines.push(`The backend's previous ones are kept in ${kept}.`);
5437
5544
  }
5438
5545
  for (const l of automations.lines) say(` ${l}`);
@@ -5449,6 +5556,21 @@ async function applyEverything(base, token, project, functions, makeRoles, where
5449
5556
  else say(` Cloud functions: unchanged (${result.functions.map((f) => f.name).join(", ")}).`);
5450
5557
  if (failed.length) throw new DeployError(`Cloud functions that did not deploy:
5451
5558
  ${failed.map((f) => ` ${f.name}: ${f.reason}`).join("\n")}`);
5559
+ stage = "secrets";
5560
+ const read = secretNamesRead(functions.parts.bundle?.components ?? []);
5561
+ let listing = null;
5562
+ if (read.length) {
5563
+ const r = await call("GET", "/admin/secrets").catch(() => null);
5564
+ if (r && r.status === 200 && r.json && typeof r.json === "object") listing = r.json;
5565
+ }
5566
+ const lines = secretsReport({
5567
+ read,
5568
+ listing,
5569
+ inEnvFile: projectEnvSecretNames(project.dir),
5570
+ dashboard: `${base}/_admin`,
5571
+ credentialFile: path5.join(where.dir, "deployment.json")
5572
+ });
5573
+ for (const l of lines) say(` ${l}`);
5452
5574
  }
5453
5575
  function alertFrom(o, before) {
5454
5576
  if (o.alertTo === null || o.alertFrom === null) return null;
@@ -5480,15 +5602,16 @@ async function testAlert(base, record, dir, local = false) {
5480
5602
  }
5481
5603
  }
5482
5604
  async function deploy(o) {
5605
+ stage = null;
5483
5606
  const project = readProject(o.project);
5484
5607
  const root = deploymentsRoot();
5485
5608
  const name2 = o.name || (o.out ? readRecord(o.out)?.name : void 0) || workerNameFrom(project.name);
5486
5609
  const problem = workerNameProblem(name2);
5487
5610
  if (problem) throw new DeployError(problem);
5488
- const dir = o.out || path4.join(root, name2);
5489
- fs5.mkdirSync(dir, { recursive: true });
5611
+ const dir = o.out || path5.join(root, name2);
5612
+ fs6.mkdirSync(dir, { recursive: true });
5490
5613
  const before = readRecord(dir);
5491
- if (before && path4.resolve(before.project) !== path4.resolve(project.dir)) {
5614
+ if (before && path5.resolve(before.project) !== path5.resolve(project.dir)) {
5492
5615
  throw new DeployError(`${name2} was deployed from ${before.project}, not ${project.dir}. Choose another --name.`);
5493
5616
  }
5494
5617
  const firstDeploy = !before || !before.deploys.some((d) => d.local === !!o.local);
@@ -5512,7 +5635,8 @@ async function deploy(o) {
5512
5635
  if (bad) throw new DeployError(bad);
5513
5636
  }
5514
5637
  say(`NodeGX \u2192 Cloudflare: "${project.name}" as the Worker ${name2}${o.local ? " (locally, on workerd)" : ""}${firstDeploy ? ", first deploy" : ""}.`);
5515
- say("1. Cloud functions");
5638
+ say(`The guide to every step below: ${guideLink()}`);
5639
+ step("1. Cloud functions", "functions");
5516
5640
  const functions = cloudFunctions(project.dir);
5517
5641
  if (functions.parts.failures.length) {
5518
5642
  throw new DeployError(`Cloud functions that cannot be bundled:
@@ -5522,19 +5646,19 @@ ${functions.parts.failures.map((f) => ` ${f.name}: ${f.reason}`).join("\n")}`);
5522
5646
  const { print, refusals } = collectCode(components);
5523
5647
  if (refusals.length) throw new DeployError(refusals.map(refusalSentence).join("\n"));
5524
5648
  say(` ${functions.parts.shipped.length} function(s), ${print.length} code text(s) printed.`);
5525
- say("2. The site");
5526
- const siteDir = path4.join(dir, "site");
5649
+ step("2. The site", "site");
5650
+ const siteDir = path5.join(dir, "site");
5527
5651
  for (const n of buildSite(project, name2, siteDir, o)) say(` ${n}`);
5528
- say("3. The Worker");
5529
- const distDir = path4.join(dir, "dist");
5530
- fs5.rmSync(distDir, { recursive: true, force: true });
5652
+ step("3. The Worker", "worker");
5653
+ const distDir = path5.join(dir, "dist");
5654
+ fs6.rmSync(distDir, { recursive: true, force: true });
5531
5655
  const how = await buildWorker(distDir, { appId: name2, appName: project.name, policy: project.policyText, automations: project.automationsText }, printCodeModule(print));
5532
5656
  if (how === "prebuilt") say(" the backend: the prebuilt Worker (nothing bundled on this computer); the app's code beside it");
5533
- fs5.writeFileSync(path4.join(dir, "wrangler.toml"), wranglerConfig({ name: name2, bucket: record.bucket, domain: o.local ? null : record.domain, alert: record.alert }));
5657
+ fs6.writeFileSync(path5.join(dir, "wrangler.toml"), wranglerConfig({ name: name2, bucket: record.bucket, domain: o.local ? null : record.domain, alert: record.alert }));
5534
5658
  const uploaded = [...filesUnder2(siteDir), ...filesUnder2(distDir)];
5535
- const mb = uploaded.reduce((n, f) => n + fs5.statSync(f).size, 0) / 1e6;
5659
+ const mb = uploaded.reduce((n, f) => n + fs6.statSync(f).size, 0) / 1e6;
5536
5660
  say(` ${uploaded.length} files to upload, ${mb.toFixed(2)} MB; files in ${record.bucket ? `the bucket ${record.bucket}` : "NO bucket (uploads are lost on a restart)"}.`);
5537
- say("4. Nothing private in what is uploaded");
5661
+ step("4. Nothing private in what is uploaded", "private");
5538
5662
  const found = leaks(uploaded, [{ what: "the admin credential", value: record.adminToken }, ...project.envValues.map((v, i) => ({ what: `.env value ${i + 1}`, value: v }))]);
5539
5663
  if (found.length) throw new DeployError(`Refused: ${found.join("; ")}.`);
5540
5664
  say(` 0 of ${uploaded.length} files hold the admin credential or a .env value.`);
@@ -5544,38 +5668,39 @@ ${functions.parts.failures.map((f) => ` ${f.name}: ${f.reason}`).join("\n")}`);
5544
5668
  return 0;
5545
5669
  }
5546
5670
  if (o.local) {
5547
- say("5. wrangler dev");
5671
+ step("5. wrangler dev", "upload");
5548
5672
  const port = o.port || 8787;
5549
- fs5.writeFileSync(path4.join(dir, ".dev.vars"), `NODEGX_ADMIN_TOKEN=${record.adminToken}
5673
+ fs6.writeFileSync(path5.join(dir, ".dev.vars"), `NODEGX_ADMIN_TOKEN=${record.adminToken}
5550
5674
  `, { mode: 384 });
5551
5675
  const [cmd, ...pre] = wranglerCommand();
5552
- const child = (0, import_node_child_process.spawn)(cmd, [...pre, "dev", "--config", "wrangler.toml", "--port", String(port), "--ip", "127.0.0.1", "--persist-to", path4.join(dir, ".state")], {
5676
+ const child = (0, import_node_child_process.spawn)(cmd, [...pre, "dev", "--config", "wrangler.toml", "--port", String(port), "--ip", "127.0.0.1", "--persist-to", path5.join(dir, ".state")], {
5553
5677
  cwd: dir,
5554
5678
  stdio: ["ignore", "pipe", "pipe"],
5555
5679
  env: { ...process.env, WRANGLER_SEND_METRICS: "false" }
5556
5680
  });
5557
- const log = fs5.createWriteStream(path4.join(dir, "wrangler-dev.log"));
5681
+ const log = fs6.createWriteStream(path5.join(dir, "wrangler-dev.log"));
5558
5682
  child.stdout.pipe(log);
5559
5683
  child.stderr.pipe(log);
5560
5684
  const unstarted = new Promise((_, reject) => child.on("error", (e) => reject(new DeployError(spawnFailure([cmd, ...pre], e) ?? String(e)))));
5561
5685
  unstarted.catch(() => void 0);
5562
5686
  const base = `http://127.0.0.1:${port}`;
5563
5687
  await Promise.race([waitFor(`${base}/health`, 90), unstarted]);
5564
- say(`6. The project onto the backend at ${base}`);
5688
+ step(`6. The project onto the backend at ${base}`, "project");
5565
5689
  await applyEverything(base, record.adminToken, project, functions, firstDeploy || !!o.makeRoles, { dir, record, local: true });
5566
5690
  record.deploys.push({ at: (/* @__PURE__ */ new Date()).toISOString(), url: base, local: true });
5567
5691
  writeRecord(dir, record);
5568
5692
  await testAlert(base, record, dir, true);
5569
5693
  say(`
5570
- Running on workerd at ${base} (log: ${path4.join(dir, "wrangler-dev.log")}). Ctrl-C stops it; its data stays in ${path4.join(dir, ".state")}.`);
5694
+ Running on workerd at ${base} (log: ${path5.join(dir, "wrangler-dev.log")}). Ctrl-C stops it; its data stays in ${path5.join(dir, ".state")}.`);
5571
5695
  await new Promise((resolve2) => child.on("exit", () => resolve2()));
5572
5696
  return 0;
5573
5697
  }
5698
+ stage = "signIn";
5574
5699
  const route = await chooseRoute(o);
5575
5700
  let url;
5576
5701
  let domainAnswer = null;
5577
5702
  if (route.via === "api") {
5578
- say("5. Up to Cloudflare, through its API, with your NodeGX sign-in");
5703
+ step("5. Up to Cloudflare, through its API, with your NodeGX sign-in", "upload");
5579
5704
  const ours = !!before?.deploys.some((d) => !d.local);
5580
5705
  const up = await deployThroughApi({
5581
5706
  token: route.token,
@@ -5601,14 +5726,14 @@ Running on workerd at ${base} (log: ${path4.join(dir, "wrangler-dev.log")}). Ctr
5601
5726
  url = up.url;
5602
5727
  domainAnswer = up.domain;
5603
5728
  } else {
5604
- say(`5. wrangler deploy (${route.why})`);
5729
+ step(`5. wrangler deploy (${route.why})`, "upload");
5605
5730
  url = wranglerDeploy(dir, record, firstDeploy, mint);
5606
5731
  record.url = url;
5607
5732
  record.deploys.push({ at: (/* @__PURE__ */ new Date()).toISOString(), url, local: false, via: "wrangler" });
5608
5733
  writeRecord(dir, record);
5609
5734
  }
5610
5735
  await waitFor(`${url}/health`, 60);
5611
- say(`6. The project onto the backend at ${url}`);
5736
+ step(`6. The project onto the backend at ${url}`, "project");
5612
5737
  await applyEverything(url, record.adminToken, project, functions, firstDeploy || !!o.makeRoles, { dir, record, local: false });
5613
5738
  say(`
5614
5739
  Online: ${url}`);
@@ -5622,7 +5747,8 @@ Online: ${url}`);
5622
5747
  );
5623
5748
  }
5624
5749
  await testAlert(url, record, dir);
5625
- say(`The backend's dashboard: ${url}/_admin \u2014 its admin credential is in ${path4.join(dir, "deployment.json")} (never uploaded).`);
5750
+ say(`The backend's dashboard: ${url}/_admin \u2014 its admin credential is in ${path5.join(dir, "deployment.json")} (never uploaded).`);
5751
+ say(`What the dashboard is for, and how to sign in to it: ${guideLink("dashboard")}`);
5626
5752
  return 0;
5627
5753
  }
5628
5754
  function wranglerDeploy(dir, record, firstDeploy, mint) {
@@ -5639,15 +5765,15 @@ ${made.out.trim() || `(wrangler exited ${made.status} and said nothing)`}
5639
5765
  const deployArgs = ["deploy", "--config", "wrangler.toml"];
5640
5766
  let secretsFile = null;
5641
5767
  if (mint) {
5642
- secretsFile = path4.join(fs5.mkdtempSync(path4.join(os2.tmpdir(), "nodegx-cf-")), "secrets.json");
5643
- fs5.writeFileSync(secretsFile, JSON.stringify({ NODEGX_ADMIN_TOKEN: record.adminToken }), { mode: 384 });
5768
+ secretsFile = path5.join(fs6.mkdtempSync(path5.join(os2.tmpdir(), "nodegx-cf-")), "secrets.json");
5769
+ fs6.writeFileSync(secretsFile, JSON.stringify({ NODEGX_ADMIN_TOKEN: record.adminToken }), { mode: 384 });
5644
5770
  deployArgs.push("--secrets-file", secretsFile);
5645
5771
  }
5646
5772
  let done;
5647
5773
  try {
5648
5774
  done = wrangler(deployArgs, dir);
5649
5775
  } finally {
5650
- if (secretsFile) fs5.rmSync(path4.dirname(secretsFile), { recursive: true, force: true });
5776
+ if (secretsFile) fs6.rmSync(path5.dirname(secretsFile), { recursive: true, force: true });
5651
5777
  }
5652
5778
  if (!done.started) throw new DeployError(`${done.out} Nothing on the backend was changed.`);
5653
5779
  if (done.status !== 0) throw new DeployError("wrangler deploy failed (above). Nothing on the backend was changed.");
@@ -5662,6 +5788,9 @@ async function main(argv) {
5662
5788
  if (e instanceof DeployError || e instanceof ApiDeployError || e?.name === "ApplyError") {
5663
5789
  process.stderr.write(`
5664
5790
  ${e.message}
5791
+ `);
5792
+ process.stderr.write(`
5793
+ Help with this step: ${guideLink(stage ?? void 0)}
5665
5794
  `);
5666
5795
  return 1;
5667
5796
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodegx-mcp-bundles",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "private": true,
5
5
  "description": "Build metadata for the bundled CLIs beside it. See build-cloud-bundle.mjs: @noodl/platform reads it."
6
6
  }
@@ -102416,6 +102416,12 @@ var HttpServer = class {
102416
102416
  this.servedApp.handle(req, res);
102417
102417
  return;
102418
102418
  }
102419
+ if (this.dashboard && method === "GET" && seg.length === 1 && seg[0] === "admin" && /text\/html/.test(String(req.headers.accept || ""))) {
102420
+ trace.route = "(admin \u2192 _admin)";
102421
+ res.writeHead(302, { Location: "/_admin", "Cache-Control": "no-store" });
102422
+ res.end();
102423
+ return;
102424
+ }
102419
102425
  throw new HttpError(404, `Not found: ${method} ${pathname}`);
102420
102426
  }
102421
102427
  const { route, params: params6 } = match;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodegx/backend",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Put a NodeGX app online on your own Cloudflare account: its pages, its backend, its rules and its functions, on one Worker, the same address every time.",
5
5
  "license": "GPL-3.0-only",
6
6
  "homepage": "https://nodegx.io",