@nodegx/backend 0.1.1 → 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 +14 -0
- package/bin/nodegx-online.js +3 -1
- package/dist/cloud-bundle.cjs +38 -2
- package/dist/cloudflare-deploy.cjs +284 -116
- package/dist/package.json +1 -1
- package/dist/worker/worker.mjs +6 -0
- package/package.json +1 -1
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.
|
package/bin/nodegx-online.js
CHANGED
|
@@ -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) {
|
|
@@ -77,6 +78,7 @@ function wrangler(args) {
|
|
|
77
78
|
const { wranglerCommand } = require(need(path.join(DIST, 'cloudflare-deploy.cjs'), 'The deploy (dist/cloudflare-deploy.cjs)'));
|
|
78
79
|
const [cmd, ...pre] = wranglerCommand();
|
|
79
80
|
const run = spawnSync(cmd, [...pre, ...args], { stdio: 'inherit', env: { ...process.env, WRANGLER_SEND_METRICS: 'false' } });
|
|
81
|
+
if (run.error) process.stderr.write(`@nodegx/backend: wrangler could not be started (${[cmd, ...pre].join(' ')}: ${run.error.code || run.error.message}).\n`);
|
|
80
82
|
return run.status ?? 1;
|
|
81
83
|
}
|
|
82
84
|
|
package/dist/cloud-bundle.cjs
CHANGED
|
@@ -28418,6 +28418,20 @@ var init_node_catalog = __esm({
|
|
|
28418
28418
|
valueType: "signal",
|
|
28419
28419
|
example: "changed-Sa1"
|
|
28420
28420
|
},
|
|
28421
|
+
{
|
|
28422
|
+
pattern: "changed-createdAt",
|
|
28423
|
+
plug: "output",
|
|
28424
|
+
group: "Events",
|
|
28425
|
+
valueType: "signal",
|
|
28426
|
+
example: "changed-createdAt"
|
|
28427
|
+
},
|
|
28428
|
+
{
|
|
28429
|
+
pattern: "changed-updatedAt",
|
|
28430
|
+
plug: "output",
|
|
28431
|
+
group: "Events",
|
|
28432
|
+
valueType: "signal",
|
|
28433
|
+
example: "changed-updatedAt"
|
|
28434
|
+
},
|
|
28421
28435
|
{
|
|
28422
28436
|
pattern: "collectionName",
|
|
28423
28437
|
plug: "input",
|
|
@@ -28434,6 +28448,20 @@ var init_node_catalog = __esm({
|
|
|
28434
28448
|
group: "Properties",
|
|
28435
28449
|
valueType: "string",
|
|
28436
28450
|
example: "prop-Sa1"
|
|
28451
|
+
},
|
|
28452
|
+
{
|
|
28453
|
+
pattern: "prop-createdAt",
|
|
28454
|
+
plug: "output",
|
|
28455
|
+
group: "Properties",
|
|
28456
|
+
valueType: "date",
|
|
28457
|
+
example: "prop-createdAt"
|
|
28458
|
+
},
|
|
28459
|
+
{
|
|
28460
|
+
pattern: "prop-updatedAt",
|
|
28461
|
+
plug: "output",
|
|
28462
|
+
group: "Properties",
|
|
28463
|
+
valueType: "date",
|
|
28464
|
+
example: "prop-updatedAt"
|
|
28437
28465
|
}
|
|
28438
28466
|
]
|
|
28439
28467
|
},
|
|
@@ -144602,7 +144630,7 @@ var init_cloud_node_library = __esm({
|
|
|
144602
144630
|
plug: "output",
|
|
144603
144631
|
group: "Events",
|
|
144604
144632
|
displayName: "Fetched",
|
|
144605
|
-
description: "Fires when the Id binds a record
|
|
144633
|
+
description: "Fires when the Id binds a record already in memory, when a record the Id names is first read from the backend, and when a Fetch finishes reading it; use Done to act on the answer to a Fetch"
|
|
144606
144634
|
},
|
|
144607
144635
|
{
|
|
144608
144636
|
name: "changed",
|
|
@@ -144778,6 +144806,14 @@ var init_cloud_node_library = __esm({
|
|
|
144778
144806
|
displayName: "Only If Unchanged",
|
|
144779
144807
|
description: "Property names, comma-separated (e.g. version). The update is applied only if these still hold the values the record had when it was read; otherwise Failure fires and nothing is written. Fetch the record again before retrying. Needs a NodeGX backend. Leave empty to always write."
|
|
144780
144808
|
},
|
|
144809
|
+
{
|
|
144810
|
+
name: "addTo",
|
|
144811
|
+
type: "string",
|
|
144812
|
+
plug: "input",
|
|
144813
|
+
group: "General",
|
|
144814
|
+
displayName: "Add To",
|
|
144815
|
+
description: "Property names, comma-separated (e.g. points). For these, the value wired in is an amount added to what the backend holds, in one step on the backend, instead of replacing it: two devices adding at once both count. Wire the amount (1, -1, 5). The record then shows the backend's total. Leave empty to write every value as given."
|
|
144816
|
+
},
|
|
144781
144817
|
{
|
|
144782
144818
|
name: "idSource",
|
|
144783
144819
|
type: {
|
|
@@ -151647,7 +151683,7 @@ var init_cloud_node_library = __esm({
|
|
|
151647
151683
|
},
|
|
151648
151684
|
{
|
|
151649
151685
|
name: "userId",
|
|
151650
|
-
type: "
|
|
151686
|
+
type: "string",
|
|
151651
151687
|
plug: "output",
|
|
151652
151688
|
group: "Request",
|
|
151653
151689
|
displayName: "User Id",
|
|
@@ -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
|
|
254
|
+
var path6 = name2.split(".");
|
|
255
255
|
var model = this;
|
|
256
|
-
for (var i = 0; i <
|
|
257
|
-
var v = model.get(
|
|
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(
|
|
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
|
|
274
|
+
var path6 = name2.split(".");
|
|
275
275
|
var model = this;
|
|
276
|
-
for (var i = 0; i <
|
|
277
|
-
var v = model.get(
|
|
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(
|
|
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
|
|
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 (
|
|
3126
|
-
runContext.endStep(
|
|
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
|
|
3265
|
-
if (
|
|
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(
|
|
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
|
|
3745
|
+
var fs6 = __toESM(require("node:fs"));
|
|
3746
3746
|
var os2 = __toESM(require("node:os"));
|
|
3747
|
-
var
|
|
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,
|
|
4318
|
-
const answer = await call(method,
|
|
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} /${
|
|
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,
|
|
4423
|
-
const answer = await call(method,
|
|
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} /${
|
|
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
|
|
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).`;
|
|
@@ -5088,12 +5149,99 @@ function wranglerConfig(input2) {
|
|
|
5088
5149
|
return lines.join("\n");
|
|
5089
5150
|
}
|
|
5090
5151
|
|
|
5152
|
+
// ../nodegx-backend/cloudflare/wranglerSpawn.ts
|
|
5153
|
+
var fs4 = __toESM(require("node:fs"));
|
|
5154
|
+
var path3 = __toESM(require("node:path"));
|
|
5155
|
+
var NPX_WRANGLER = ["--yes", "wrangler@4"];
|
|
5156
|
+
function windowsNpxCli(host) {
|
|
5157
|
+
const p = path3.win32;
|
|
5158
|
+
const candidates = [p.join(p.dirname(host.execPath), "node_modules", "npm", "bin", "npx-cli.js")];
|
|
5159
|
+
const npm = host.env.npm_execpath;
|
|
5160
|
+
if (npm && /npm-cli\.js$/i.test(npm)) candidates.push(p.join(p.dirname(npm), "npx-cli.js"));
|
|
5161
|
+
return candidates.find((f) => host.exists(f)) ?? null;
|
|
5162
|
+
}
|
|
5163
|
+
function wranglerCommandFor(host) {
|
|
5164
|
+
if (host.env.NODEGX_WRANGLER) return [host.execPath, host.env.NODEGX_WRANGLER];
|
|
5165
|
+
for (const from of host.from) {
|
|
5166
|
+
try {
|
|
5167
|
+
return [host.execPath, host.resolve("wrangler/bin/wrangler.js", from)];
|
|
5168
|
+
} catch {
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
if (host.platform === "win32") {
|
|
5172
|
+
const cli = windowsNpxCli(host);
|
|
5173
|
+
if (cli) return [host.execPath, cli, ...NPX_WRANGLER];
|
|
5174
|
+
}
|
|
5175
|
+
return ["npx", ...NPX_WRANGLER];
|
|
5176
|
+
}
|
|
5177
|
+
function realHost(from) {
|
|
5178
|
+
return {
|
|
5179
|
+
env: process.env,
|
|
5180
|
+
platform: process.platform,
|
|
5181
|
+
execPath: process.execPath,
|
|
5182
|
+
from,
|
|
5183
|
+
resolve: (request, dir) => require.resolve(request, { paths: [dir] }),
|
|
5184
|
+
exists: (f) => fs4.existsSync(f)
|
|
5185
|
+
};
|
|
5186
|
+
}
|
|
5187
|
+
function spawnFailure(command, error) {
|
|
5188
|
+
if (!error) return null;
|
|
5189
|
+
const code = error.code;
|
|
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.`;
|
|
5191
|
+
}
|
|
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
|
+
|
|
5091
5234
|
// ../nodegx-backend/cloudflare/deployCloudflare.ts
|
|
5092
5235
|
var HERE = process.env.NODEGX_CLOUDFLARE_SRC || __dirname;
|
|
5093
|
-
var PACKAGES =
|
|
5236
|
+
var PACKAGES = path5.resolve(HERE, "..", "..");
|
|
5094
5237
|
var DeployError = class extends Error {
|
|
5095
5238
|
};
|
|
5096
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
|
+
}
|
|
5097
5245
|
var PROGRAM = process.env.NODEGX_CLOUDFLARE_COMMAND || "deploy.mjs";
|
|
5098
5246
|
var USAGE = `usage: ${PROGRAM} <project> [--name <worker>] [--bucket <r2 bucket> | --no-bucket] [--viewer <folder>]
|
|
5099
5247
|
[--allow-development-engine] [--out <folder>] [--local [--port <n>]] [--make-roles]
|
|
@@ -5113,9 +5261,9 @@ ${USAGE}`);
|
|
|
5113
5261
|
if (a === "--name") o.name = next();
|
|
5114
5262
|
else if (a === "--bucket") o.bucket = next();
|
|
5115
5263
|
else if (a === "--no-bucket") o.bucket = null;
|
|
5116
|
-
else if (a === "--viewer") o.viewer =
|
|
5264
|
+
else if (a === "--viewer") o.viewer = path5.resolve(next());
|
|
5117
5265
|
else if (a === "--allow-development-engine") o.allowDevelopmentEngine = true;
|
|
5118
|
-
else if (a === "--out") o.out =
|
|
5266
|
+
else if (a === "--out") o.out = path5.resolve(next());
|
|
5119
5267
|
else if (a === "--local") o.local = true;
|
|
5120
5268
|
else if (a === "--port") o.port = Number(next());
|
|
5121
5269
|
else if (a === "--make-roles") o.makeRoles = true;
|
|
@@ -5130,7 +5278,7 @@ ${USAGE}`);
|
|
|
5130
5278
|
else if (a === "--account") o.account = next().trim();
|
|
5131
5279
|
else if (a.startsWith("--")) throw new DeployError(`${a} is not an option.
|
|
5132
5280
|
${USAGE}`);
|
|
5133
|
-
else if (!o.project) o.project =
|
|
5281
|
+
else if (!o.project) o.project = path5.resolve(a);
|
|
5134
5282
|
else throw new DeployError(`One project at a time.
|
|
5135
5283
|
${USAGE}`);
|
|
5136
5284
|
}
|
|
@@ -5138,20 +5286,20 @@ ${USAGE}`);
|
|
|
5138
5286
|
return o;
|
|
5139
5287
|
}
|
|
5140
5288
|
function readProject(dir) {
|
|
5141
|
-
const file =
|
|
5142
|
-
if (!
|
|
5143
|
-
const json = JSON.parse(
|
|
5144
|
-
const policyFile =
|
|
5145
|
-
const policyText =
|
|
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;
|
|
5146
5294
|
if (policyText) JSON.parse(policyText);
|
|
5147
|
-
const automationsFile =
|
|
5148
|
-
const automationsText =
|
|
5295
|
+
const automationsFile = path5.join(dir, "nodegx.automations.json");
|
|
5296
|
+
const automationsText = fs6.existsSync(automationsFile) ? fs6.readFileSync(automationsFile, "utf8") : null;
|
|
5149
5297
|
if (automationsText) JSON.parse(automationsText);
|
|
5150
|
-
const envFile =
|
|
5151
|
-
const envValues =
|
|
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) : [];
|
|
5152
5300
|
return {
|
|
5153
5301
|
dir,
|
|
5154
|
-
name: json.name ||
|
|
5302
|
+
name: json.name || path5.basename(dir),
|
|
5155
5303
|
file: json,
|
|
5156
5304
|
policyText,
|
|
5157
5305
|
automationsText,
|
|
@@ -5160,20 +5308,20 @@ function readProject(dir) {
|
|
|
5160
5308
|
};
|
|
5161
5309
|
}
|
|
5162
5310
|
function deploymentsRoot() {
|
|
5163
|
-
return process.env.NODEGX_CLOUDFLARE_HOME ||
|
|
5311
|
+
return process.env.NODEGX_CLOUDFLARE_HOME || path5.join(os2.homedir(), ".nodegx", "cloudflare");
|
|
5164
5312
|
}
|
|
5165
5313
|
function readRecord(dir) {
|
|
5166
|
-
const file =
|
|
5167
|
-
return
|
|
5314
|
+
const file = path5.join(dir, "deployment.json");
|
|
5315
|
+
return fs6.existsSync(file) ? JSON.parse(fs6.readFileSync(file, "utf8")) : null;
|
|
5168
5316
|
}
|
|
5169
5317
|
function writeRecord(dir, record) {
|
|
5170
|
-
const file =
|
|
5171
|
-
|
|
5172
|
-
|
|
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);
|
|
5173
5321
|
}
|
|
5174
5322
|
function cloudFunctions(projectDir) {
|
|
5175
|
-
const entry = process.env.NODEGX_CLOUD_BUNDLE ||
|
|
5176
|
-
if (!
|
|
5323
|
+
const entry = process.env.NODEGX_CLOUD_BUNDLE || path5.join(PACKAGES, "noodl-mcp", "dist", "cloud-bundle.cjs");
|
|
5324
|
+
if (!fs6.existsSync(entry)) {
|
|
5177
5325
|
throw new DeployError(`The cloud-function bundler is not here (${entry}): run \`npm run build\` in packages/noodl-mcp.`);
|
|
5178
5326
|
}
|
|
5179
5327
|
const run = (0, import_node_child_process.spawnSync)(process.execPath, [entry, projectDir], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 12e4 });
|
|
@@ -5184,8 +5332,8 @@ ${(run.stderr || "").trim() || "no output"}`);
|
|
|
5184
5332
|
var NOT_FOR_THE_HOST = ["DEPLOY.md", "serve.js", "package.json", ".nodegx-deploy.json", "nodegx-config.json"];
|
|
5185
5333
|
var VIEWER_HINT = "\nName a production viewer with --viewer <folder holding noodl.deploy.js>.";
|
|
5186
5334
|
function siteThroughCli(copy, out, allowDev) {
|
|
5187
|
-
const cli = process.env.NODEGX_CLI ||
|
|
5188
|
-
if (!process.env.NODEGX_CLI && process.env.NODEGX_DEPLOY_CLI && !
|
|
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;
|
|
5189
5337
|
const args = [cli, "deploy", copy, out];
|
|
5190
5338
|
if (allowDev) args.push("--allow-development-engine");
|
|
5191
5339
|
const run = (0, import_node_child_process.spawnSync)(process.execPath, args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
@@ -5197,7 +5345,7 @@ ${(run.stdout + run.stderr).trim()}` + (run.status === 11 ? VIEWER_HINT : ""));
|
|
|
5197
5345
|
}
|
|
5198
5346
|
function siteThroughEngine(copy, out, allowDev) {
|
|
5199
5347
|
const engine = process.env.NODEGX_DEPLOY_CLI;
|
|
5200
|
-
if (!
|
|
5348
|
+
if (!fs6.existsSync(engine)) throw new DeployError(`NODEGX_DEPLOY_CLI is set to ${engine}, and there is nothing there.`);
|
|
5201
5349
|
const args = [engine, copy, out];
|
|
5202
5350
|
if (allowDev) args.push("--allow-development-engine");
|
|
5203
5351
|
const run = (0, import_node_child_process.spawnSync)(process.execPath, args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
@@ -5221,45 +5369,45 @@ ${report.blank}`);
|
|
|
5221
5369
|
return notes;
|
|
5222
5370
|
}
|
|
5223
5371
|
function buildSite(project, name2, siteDir, o) {
|
|
5224
|
-
const work =
|
|
5372
|
+
const work = fs6.mkdtempSync(path5.join(os2.tmpdir(), "nodegx-cf-site-"));
|
|
5225
5373
|
try {
|
|
5226
|
-
const copy =
|
|
5227
|
-
|
|
5228
|
-
const json = JSON.parse(
|
|
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"));
|
|
5229
5377
|
json.metadata = { ...json.metadata || {}, cloudservices: { endpoint: "", appId: name2, instanceId: name2, type: "nodegx" } };
|
|
5230
|
-
|
|
5231
|
-
const out =
|
|
5378
|
+
fs6.writeFileSync(path5.join(copy, "nodegx.project.json"), JSON.stringify(json, null, 2));
|
|
5379
|
+
const out = path5.join(work, "site");
|
|
5232
5380
|
const allowDev = !!(o.viewer || o.allowDevelopmentEngine);
|
|
5233
5381
|
const notes = siteThroughCli(copy, out, allowDev) ?? siteThroughEngine(copy, out, allowDev);
|
|
5234
5382
|
if (o.viewer) {
|
|
5235
5383
|
for (const f of ["noodl.deploy.js", "noodl.deploy.js.LICENSE.txt"]) {
|
|
5236
|
-
const from =
|
|
5237
|
-
if (
|
|
5384
|
+
const from = path5.join(o.viewer, f);
|
|
5385
|
+
if (fs6.existsSync(from)) fs6.copyFileSync(from, path5.join(out, f));
|
|
5238
5386
|
else if (f === "noodl.deploy.js") throw new DeployError(`--viewer ${o.viewer} holds no noodl.deploy.js.`);
|
|
5239
5387
|
}
|
|
5240
|
-
const engine = readViewerBuild(
|
|
5388
|
+
const engine = readViewerBuild(path5.join(out, "noodl.deploy.js"));
|
|
5241
5389
|
if (engine.kind !== "production") {
|
|
5242
5390
|
throw new DeployError(`--viewer ${o.viewer} is a DEVELOPMENT build of the viewer: ${engine.reasons.join("; ")}.`);
|
|
5243
5391
|
}
|
|
5244
5392
|
notes.push(`viewer: production, from ${o.viewer} (${(engine.bytes / 1e6).toFixed(2)} MB)`);
|
|
5245
5393
|
}
|
|
5246
|
-
for (const f of NOT_FOR_THE_HOST)
|
|
5247
|
-
const hidden = filesUnder2(out).filter((f) =>
|
|
5248
|
-
for (const f of hidden)
|
|
5249
|
-
if (hidden.length) notes.push(`left out (hidden files are never published): ${hidden.map((f) =>
|
|
5250
|
-
|
|
5251
|
-
|
|
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 });
|
|
5252
5400
|
return notes;
|
|
5253
5401
|
} finally {
|
|
5254
|
-
|
|
5402
|
+
fs6.rmSync(work, { recursive: true, force: true });
|
|
5255
5403
|
}
|
|
5256
5404
|
}
|
|
5257
5405
|
async function bundleWorker(outfile, plugins = [], esbuild = require("esbuild")) {
|
|
5258
|
-
const { shared } = require(
|
|
5259
|
-
const nodeSqlite =
|
|
5406
|
+
const { shared } = require(path5.join(HERE, "..", "scripts", "build.js"));
|
|
5407
|
+
const nodeSqlite = path5.join(HERE, "nodeSqlite.ts");
|
|
5260
5408
|
await esbuild.build({
|
|
5261
5409
|
...shared,
|
|
5262
|
-
entryPoints: [
|
|
5410
|
+
entryPoints: [path5.join(HERE, "worker.ts")],
|
|
5263
5411
|
outfile,
|
|
5264
5412
|
format: "esm",
|
|
5265
5413
|
target: "es2022",
|
|
@@ -5287,55 +5435,49 @@ async function bundleWorker(outfile, plugins = [], esbuild = require("esbuild"))
|
|
|
5287
5435
|
}
|
|
5288
5436
|
var WORKER_OWN_MODULES = ["./printed-code.mjs", "./app.mjs"];
|
|
5289
5437
|
async function buildWorker(distDir, app, printed) {
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
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)};
|
|
5293
5441
|
`);
|
|
5294
5442
|
const prebuilt = process.env.NODEGX_CLOUDFLARE_WORKER;
|
|
5295
5443
|
if (prebuilt) {
|
|
5296
|
-
if (!
|
|
5297
|
-
|
|
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"));
|
|
5298
5446
|
return "prebuilt";
|
|
5299
5447
|
}
|
|
5300
|
-
await bundleWorker(
|
|
5448
|
+
await bundleWorker(path5.join(distDir, "worker.mjs"));
|
|
5301
5449
|
return "bundled";
|
|
5302
5450
|
}
|
|
5303
5451
|
function filesUnder2(dir) {
|
|
5304
5452
|
const out = [];
|
|
5305
5453
|
const walk = (d) => {
|
|
5306
|
-
for (const e of
|
|
5307
|
-
const full =
|
|
5454
|
+
for (const e of fs6.readdirSync(d, { withFileTypes: true })) {
|
|
5455
|
+
const full = path5.join(d, e.name);
|
|
5308
5456
|
if (e.isDirectory()) walk(full);
|
|
5309
5457
|
else out.push(full);
|
|
5310
5458
|
}
|
|
5311
5459
|
};
|
|
5312
|
-
if (
|
|
5460
|
+
if (fs6.existsSync(dir)) walk(dir);
|
|
5313
5461
|
return out;
|
|
5314
5462
|
}
|
|
5315
5463
|
function leaks(files, secrets) {
|
|
5316
5464
|
const found = [];
|
|
5317
5465
|
for (const f of files) {
|
|
5318
|
-
const text =
|
|
5466
|
+
const text = fs6.readFileSync(f, "latin1");
|
|
5319
5467
|
for (const s of secrets) if (s.value && text.includes(s.value)) found.push(`${s.what} is in ${f}`);
|
|
5320
5468
|
}
|
|
5321
5469
|
return found;
|
|
5322
5470
|
}
|
|
5323
5471
|
function wranglerCommand() {
|
|
5324
|
-
|
|
5325
|
-
for (const from of [process.cwd(), HERE]) {
|
|
5326
|
-
try {
|
|
5327
|
-
return [process.execPath, require.resolve("wrangler/bin/wrangler.js", { paths: [from] })];
|
|
5328
|
-
} catch {
|
|
5329
|
-
}
|
|
5330
|
-
}
|
|
5331
|
-
return ["npx", "--yes", "wrangler@4"];
|
|
5472
|
+
return wranglerCommandFor(realHost([process.cwd(), HERE]));
|
|
5332
5473
|
}
|
|
5333
5474
|
function wrangler(args, cwd, opts = {}) {
|
|
5334
5475
|
const [cmd, ...pre] = wranglerCommand();
|
|
5335
5476
|
const run = (0, import_node_child_process.spawnSync)(cmd, [...pre, ...args], { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, env: { ...process.env, WRANGLER_SEND_METRICS: "false" } });
|
|
5336
|
-
const
|
|
5477
|
+
const unstarted = spawnFailure([cmd, ...pre], run.error);
|
|
5478
|
+
const out = unstarted ?? `${run.stdout || ""}${run.stderr || ""}`;
|
|
5337
5479
|
if (!opts.quiet) process.stdout.write(out.split("\n").map((l) => l ? ` \u2502 ${l}` : l).join("\n") + "\n");
|
|
5338
|
-
return { status: run.status ?? 1, out };
|
|
5480
|
+
return { status: run.status ?? 1, out, started: !unstarted };
|
|
5339
5481
|
}
|
|
5340
5482
|
async function waitFor(url, seconds) {
|
|
5341
5483
|
const until = Date.now() + seconds * 1e3;
|
|
@@ -5396,8 +5538,8 @@ async function applyEverything(base, token, project, functions, makeRoles, where
|
|
|
5396
5538
|
const target = where.local ? "local" : "live";
|
|
5397
5539
|
const automations = await applyAutomations(call, project.automationsText, { installedSha256: where.record.automations?.[target] ?? null });
|
|
5398
5540
|
if (automations.before) {
|
|
5399
|
-
const kept =
|
|
5400
|
-
|
|
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");
|
|
5401
5543
|
automations.lines.push(`The backend's previous ones are kept in ${kept}.`);
|
|
5402
5544
|
}
|
|
5403
5545
|
for (const l of automations.lines) say(` ${l}`);
|
|
@@ -5414,6 +5556,21 @@ async function applyEverything(base, token, project, functions, makeRoles, where
|
|
|
5414
5556
|
else say(` Cloud functions: unchanged (${result.functions.map((f) => f.name).join(", ")}).`);
|
|
5415
5557
|
if (failed.length) throw new DeployError(`Cloud functions that did not deploy:
|
|
5416
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}`);
|
|
5417
5574
|
}
|
|
5418
5575
|
function alertFrom(o, before) {
|
|
5419
5576
|
if (o.alertTo === null || o.alertFrom === null) return null;
|
|
@@ -5445,15 +5602,16 @@ async function testAlert(base, record, dir, local = false) {
|
|
|
5445
5602
|
}
|
|
5446
5603
|
}
|
|
5447
5604
|
async function deploy(o) {
|
|
5605
|
+
stage = null;
|
|
5448
5606
|
const project = readProject(o.project);
|
|
5449
5607
|
const root = deploymentsRoot();
|
|
5450
5608
|
const name2 = o.name || (o.out ? readRecord(o.out)?.name : void 0) || workerNameFrom(project.name);
|
|
5451
5609
|
const problem = workerNameProblem(name2);
|
|
5452
5610
|
if (problem) throw new DeployError(problem);
|
|
5453
|
-
const dir = o.out ||
|
|
5454
|
-
|
|
5611
|
+
const dir = o.out || path5.join(root, name2);
|
|
5612
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
5455
5613
|
const before = readRecord(dir);
|
|
5456
|
-
if (before &&
|
|
5614
|
+
if (before && path5.resolve(before.project) !== path5.resolve(project.dir)) {
|
|
5457
5615
|
throw new DeployError(`${name2} was deployed from ${before.project}, not ${project.dir}. Choose another --name.`);
|
|
5458
5616
|
}
|
|
5459
5617
|
const firstDeploy = !before || !before.deploys.some((d) => d.local === !!o.local);
|
|
@@ -5477,7 +5635,8 @@ async function deploy(o) {
|
|
|
5477
5635
|
if (bad) throw new DeployError(bad);
|
|
5478
5636
|
}
|
|
5479
5637
|
say(`NodeGX \u2192 Cloudflare: "${project.name}" as the Worker ${name2}${o.local ? " (locally, on workerd)" : ""}${firstDeploy ? ", first deploy" : ""}.`);
|
|
5480
|
-
say(
|
|
5638
|
+
say(`The guide to every step below: ${guideLink()}`);
|
|
5639
|
+
step("1. Cloud functions", "functions");
|
|
5481
5640
|
const functions = cloudFunctions(project.dir);
|
|
5482
5641
|
if (functions.parts.failures.length) {
|
|
5483
5642
|
throw new DeployError(`Cloud functions that cannot be bundled:
|
|
@@ -5487,19 +5646,19 @@ ${functions.parts.failures.map((f) => ` ${f.name}: ${f.reason}`).join("\n")}`);
|
|
|
5487
5646
|
const { print, refusals } = collectCode(components);
|
|
5488
5647
|
if (refusals.length) throw new DeployError(refusals.map(refusalSentence).join("\n"));
|
|
5489
5648
|
say(` ${functions.parts.shipped.length} function(s), ${print.length} code text(s) printed.`);
|
|
5490
|
-
|
|
5491
|
-
const siteDir =
|
|
5649
|
+
step("2. The site", "site");
|
|
5650
|
+
const siteDir = path5.join(dir, "site");
|
|
5492
5651
|
for (const n of buildSite(project, name2, siteDir, o)) say(` ${n}`);
|
|
5493
|
-
|
|
5494
|
-
const distDir =
|
|
5495
|
-
|
|
5652
|
+
step("3. The Worker", "worker");
|
|
5653
|
+
const distDir = path5.join(dir, "dist");
|
|
5654
|
+
fs6.rmSync(distDir, { recursive: true, force: true });
|
|
5496
5655
|
const how = await buildWorker(distDir, { appId: name2, appName: project.name, policy: project.policyText, automations: project.automationsText }, printCodeModule(print));
|
|
5497
5656
|
if (how === "prebuilt") say(" the backend: the prebuilt Worker (nothing bundled on this computer); the app's code beside it");
|
|
5498
|
-
|
|
5657
|
+
fs6.writeFileSync(path5.join(dir, "wrangler.toml"), wranglerConfig({ name: name2, bucket: record.bucket, domain: o.local ? null : record.domain, alert: record.alert }));
|
|
5499
5658
|
const uploaded = [...filesUnder2(siteDir), ...filesUnder2(distDir)];
|
|
5500
|
-
const mb = uploaded.reduce((n, f) => n +
|
|
5659
|
+
const mb = uploaded.reduce((n, f) => n + fs6.statSync(f).size, 0) / 1e6;
|
|
5501
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)"}.`);
|
|
5502
|
-
|
|
5661
|
+
step("4. Nothing private in what is uploaded", "private");
|
|
5503
5662
|
const found = leaks(uploaded, [{ what: "the admin credential", value: record.adminToken }, ...project.envValues.map((v, i) => ({ what: `.env value ${i + 1}`, value: v }))]);
|
|
5504
5663
|
if (found.length) throw new DeployError(`Refused: ${found.join("; ")}.`);
|
|
5505
5664
|
say(` 0 of ${uploaded.length} files hold the admin credential or a .env value.`);
|
|
@@ -5509,36 +5668,39 @@ ${functions.parts.failures.map((f) => ` ${f.name}: ${f.reason}`).join("\n")}`);
|
|
|
5509
5668
|
return 0;
|
|
5510
5669
|
}
|
|
5511
5670
|
if (o.local) {
|
|
5512
|
-
|
|
5671
|
+
step("5. wrangler dev", "upload");
|
|
5513
5672
|
const port = o.port || 8787;
|
|
5514
|
-
|
|
5673
|
+
fs6.writeFileSync(path5.join(dir, ".dev.vars"), `NODEGX_ADMIN_TOKEN=${record.adminToken}
|
|
5515
5674
|
`, { mode: 384 });
|
|
5516
5675
|
const [cmd, ...pre] = wranglerCommand();
|
|
5517
|
-
const child = (0, import_node_child_process.spawn)(cmd, [...pre, "dev", "--config", "wrangler.toml", "--port", String(port), "--ip", "127.0.0.1", "--persist-to",
|
|
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")], {
|
|
5518
5677
|
cwd: dir,
|
|
5519
5678
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5520
5679
|
env: { ...process.env, WRANGLER_SEND_METRICS: "false" }
|
|
5521
5680
|
});
|
|
5522
|
-
const log =
|
|
5681
|
+
const log = fs6.createWriteStream(path5.join(dir, "wrangler-dev.log"));
|
|
5523
5682
|
child.stdout.pipe(log);
|
|
5524
5683
|
child.stderr.pipe(log);
|
|
5684
|
+
const unstarted = new Promise((_, reject) => child.on("error", (e) => reject(new DeployError(spawnFailure([cmd, ...pre], e) ?? String(e)))));
|
|
5685
|
+
unstarted.catch(() => void 0);
|
|
5525
5686
|
const base = `http://127.0.0.1:${port}`;
|
|
5526
|
-
await waitFor(`${base}/health`, 90);
|
|
5527
|
-
|
|
5687
|
+
await Promise.race([waitFor(`${base}/health`, 90), unstarted]);
|
|
5688
|
+
step(`6. The project onto the backend at ${base}`, "project");
|
|
5528
5689
|
await applyEverything(base, record.adminToken, project, functions, firstDeploy || !!o.makeRoles, { dir, record, local: true });
|
|
5529
5690
|
record.deploys.push({ at: (/* @__PURE__ */ new Date()).toISOString(), url: base, local: true });
|
|
5530
5691
|
writeRecord(dir, record);
|
|
5531
5692
|
await testAlert(base, record, dir, true);
|
|
5532
5693
|
say(`
|
|
5533
|
-
Running on workerd at ${base} (log: ${
|
|
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")}.`);
|
|
5534
5695
|
await new Promise((resolve2) => child.on("exit", () => resolve2()));
|
|
5535
5696
|
return 0;
|
|
5536
5697
|
}
|
|
5698
|
+
stage = "signIn";
|
|
5537
5699
|
const route = await chooseRoute(o);
|
|
5538
5700
|
let url;
|
|
5539
5701
|
let domainAnswer = null;
|
|
5540
5702
|
if (route.via === "api") {
|
|
5541
|
-
|
|
5703
|
+
step("5. Up to Cloudflare, through its API, with your NodeGX sign-in", "upload");
|
|
5542
5704
|
const ours = !!before?.deploys.some((d) => !d.local);
|
|
5543
5705
|
const up = await deployThroughApi({
|
|
5544
5706
|
token: route.token,
|
|
@@ -5564,14 +5726,14 @@ Running on workerd at ${base} (log: ${path3.join(dir, "wrangler-dev.log")}). Ctr
|
|
|
5564
5726
|
url = up.url;
|
|
5565
5727
|
domainAnswer = up.domain;
|
|
5566
5728
|
} else {
|
|
5567
|
-
|
|
5729
|
+
step(`5. wrangler deploy (${route.why})`, "upload");
|
|
5568
5730
|
url = wranglerDeploy(dir, record, firstDeploy, mint);
|
|
5569
5731
|
record.url = url;
|
|
5570
5732
|
record.deploys.push({ at: (/* @__PURE__ */ new Date()).toISOString(), url, local: false, via: "wrangler" });
|
|
5571
5733
|
writeRecord(dir, record);
|
|
5572
5734
|
}
|
|
5573
5735
|
await waitFor(`${url}/health`, 60);
|
|
5574
|
-
|
|
5736
|
+
step(`6. The project onto the backend at ${url}`, "project");
|
|
5575
5737
|
await applyEverything(url, record.adminToken, project, functions, firstDeploy || !!o.makeRoles, { dir, record, local: false });
|
|
5576
5738
|
say(`
|
|
5577
5739
|
Online: ${url}`);
|
|
@@ -5585,15 +5747,17 @@ Online: ${url}`);
|
|
|
5585
5747
|
);
|
|
5586
5748
|
}
|
|
5587
5749
|
await testAlert(url, record, dir);
|
|
5588
|
-
say(`The backend's dashboard: ${url}/_admin \u2014 its admin credential is in ${
|
|
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")}`);
|
|
5589
5752
|
return 0;
|
|
5590
5753
|
}
|
|
5591
5754
|
function wranglerDeploy(dir, record, firstDeploy, mint) {
|
|
5592
5755
|
if (record.bucket && firstDeploy) {
|
|
5593
5756
|
const made = wrangler(["r2", "bucket", "create", record.bucket], dir, { quiet: true });
|
|
5594
5757
|
if (made.status !== 0 && !/already exists|already own/i.test(made.out)) {
|
|
5758
|
+
if (!made.started) throw new DeployError(made.out);
|
|
5595
5759
|
throw new DeployError(`The bucket ${record.bucket} could not be made:
|
|
5596
|
-
${made.out.trim()}
|
|
5760
|
+
${made.out.trim() || `(wrangler exited ${made.status} and said nothing)`}
|
|
5597
5761
|
(R2 must be enabled on the account; --no-bucket deploys without one.)`);
|
|
5598
5762
|
}
|
|
5599
5763
|
say(` bucket ${record.bucket}: ${made.status === 0 ? "made" : "already there"}`);
|
|
@@ -5601,16 +5765,17 @@ ${made.out.trim()}
|
|
|
5601
5765
|
const deployArgs = ["deploy", "--config", "wrangler.toml"];
|
|
5602
5766
|
let secretsFile = null;
|
|
5603
5767
|
if (mint) {
|
|
5604
|
-
secretsFile =
|
|
5605
|
-
|
|
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 });
|
|
5606
5770
|
deployArgs.push("--secrets-file", secretsFile);
|
|
5607
5771
|
}
|
|
5608
5772
|
let done;
|
|
5609
5773
|
try {
|
|
5610
5774
|
done = wrangler(deployArgs, dir);
|
|
5611
5775
|
} finally {
|
|
5612
|
-
if (secretsFile)
|
|
5776
|
+
if (secretsFile) fs6.rmSync(path5.dirname(secretsFile), { recursive: true, force: true });
|
|
5613
5777
|
}
|
|
5778
|
+
if (!done.started) throw new DeployError(`${done.out} Nothing on the backend was changed.`);
|
|
5614
5779
|
if (done.status !== 0) throw new DeployError("wrangler deploy failed (above). Nothing on the backend was changed.");
|
|
5615
5780
|
const url = /https:\/\/[a-z0-9.-]+\.workers\.dev/.exec(done.out)?.[0] ?? record.url;
|
|
5616
5781
|
if (!url) throw new DeployError("wrangler deployed, but did not say the address: deploy again to finish.");
|
|
@@ -5623,6 +5788,9 @@ async function main(argv) {
|
|
|
5623
5788
|
if (e instanceof DeployError || e instanceof ApiDeployError || e?.name === "ApplyError") {
|
|
5624
5789
|
process.stderr.write(`
|
|
5625
5790
|
${e.message}
|
|
5791
|
+
`);
|
|
5792
|
+
process.stderr.write(`
|
|
5793
|
+
Help with this step: ${guideLink(stage ?? void 0)}
|
|
5626
5794
|
`);
|
|
5627
5795
|
return 1;
|
|
5628
5796
|
}
|
package/dist/package.json
CHANGED
package/dist/worker/worker.mjs
CHANGED
|
@@ -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.
|
|
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",
|