@backifydev/cli 0.4.4 → 0.4.6
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 +70 -4
- package/dist/index.js +2162 -481
- package/package.json +1 -1
- package/templates/api/backify.config.ts +1 -1
- package/templates/web/backify.config.ts +1 -1
- package/templates/worker/backify.config.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -46,12 +46,12 @@ var init_delivery = __esm({
|
|
|
46
46
|
"use strict";
|
|
47
47
|
deliveryInstructions = `# Backify application delivery and prompt history
|
|
48
48
|
|
|
49
|
-
Instruction version:
|
|
50
|
-
Versioned guide: https://agent.backify.dev/
|
|
49
|
+
Instruction version: 21
|
|
50
|
+
Versioned guide: https://agent.backify.dev/v21/delivery.md
|
|
51
51
|
|
|
52
52
|
## Environment and documentation prerequisites
|
|
53
53
|
|
|
54
|
-
Before installation or connection, read https://agent.backify.dev/
|
|
54
|
+
Before installation or connection, read https://agent.backify.dev/v21 for execution capability checks, required endpoints (including https://docs.backify.dev), native permission requests, verified retries and fallback guidance. Follow the current tool's supported approval mechanism; never bypass restrictions. Read relevant capability documentation before implementation. Local validation must not depend on cloud deployment.
|
|
55
55
|
|
|
56
56
|
Before application implementation, all required setup checks and connected status must be verified OK. If any required check fails or remains unverified after supported recovery, stop setup and implementation; do not build a local website, minimal shell, placeholder, dependency-free fallback, or downloadable application archive. Report the blockers and recommend running the setup prompt in an AI coding tool such as Codex, Claude Code, or VS Code with GitHub Copilot agent mode, with terminal access, a persistent writable workspace, package installation, outbound HTTPS/DNS, and test execution enabled. Tool names alone do not guarantee readiness. Do not ask the application requirements question while setup is blocked. Later preview approval or deployment failures do not invalidate an already verified setup gate.
|
|
57
57
|
|
|
@@ -77,7 +77,7 @@ Initialize using App Id from the copied prompt and the current tool selection:
|
|
|
77
77
|
|
|
78
78
|
npx @backifydev/cli@latest init --app <app-id> --agent <current-tool>
|
|
79
79
|
|
|
80
|
-
For a tool without a built-in preset, replace --agent <current-tool> with --instruction-file <relative-path>. Read BACKIFY.md and the instruction file used by the current AI coding tool before changing application code. Create or update only instruction files used by that tool; never create files for other coding tools. Use --agent for a built-in tool preset or --instruction-file <relative-path> for the current tool's native instruction file, as described in the setup guide. Initialization installs this workflow alongside the persistent SDK instructions. Follow https://agent.backify.dev/
|
|
80
|
+
For a tool without a built-in preset, replace --agent <current-tool> with --instruction-file <relative-path>. Read BACKIFY.md and the instruction file used by the current AI coding tool before changing application code. Create or update only instruction files used by that tool; never create files for other coding tools. Use --agent for a built-in tool preset or --instruction-file <relative-path> for the current tool's native instruction file, as described in the setup guide. Initialization installs this workflow alongside the persistent SDK instructions. Follow https://agent.backify.dev/v21 for rebuilt applications; use the guide matching instructionVersion in backify.config.ts (or the existing older workspace metadata). Do not silently upgrade its managed instruction version or overwrite instructions outside the managed block.
|
|
81
81
|
|
|
82
82
|
Run the following to discover the connected hosting target, repository, branch, reports, releases, and deployment failures:
|
|
83
83
|
|
|
@@ -123,9 +123,15 @@ After the required setup gate passes and application requirements are supplied,
|
|
|
123
123
|
|
|
124
124
|
Start the application, wait for readiness, request the actual local application URL, and verify a representative user flow before shipping. Document safe seed data and local test identities where needed. A failed connection or required setup check must stop implementation, including local fallback. After setup passes, later preview approval or deployment failure must not prevent safe local testing; report those blockers separately without bypassing authorization. If requirements are missing after successful setup, ask the required final question without creating a minimal runnable shell. Never claim local readiness from a build or management-dashboard response alone.
|
|
125
125
|
|
|
126
|
-
## Verify, push, and deploy
|
|
126
|
+
## Verify, push, and deploy
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
An application always has production. Preview and prototype are optional environments that exist only when they have been added. A release enters the earliest activated environment and is promoted through the activated ones in the order prototype, preview, production. Before shipping, list the application's environments:
|
|
129
|
+
|
|
130
|
+
npx @backifydev/cli@latest environments
|
|
131
|
+
|
|
132
|
+
A plain deployment request deploys to the earliest activated environment: prototype when it exists, otherwise preview, otherwise production. Tell the user where the release will land before shipping. When production is the only environment, say plainly that the deployment goes live in production. Add a pre-production stage with backify environments add preview|prototype only when the user asks for one; an added environment is billed through its own compute, database, and storage usage, so never add one unasked. Never remove an environment unless the user explicitly asks; removal takes it offline and requires the application slug as confirmation.
|
|
133
|
+
|
|
134
|
+
Requests such as "Now deploy", "deploy", "ship", "launch", or "merge and retry" do not authorize promoting a release beyond the earliest activated environment. Approval to merge a remote commit, push source, retry deployment, or run checks applies only to that action and preserves the same target environment. Never infer production intent from permissive policy, a healthy earlier environment, or an existing production URL.
|
|
129
135
|
|
|
130
136
|
Run:
|
|
131
137
|
|
|
@@ -135,13 +141,19 @@ Fix relevant failures, then commit only application changes for this request usi
|
|
|
135
141
|
|
|
136
142
|
npx @backifydev/cli@latest ship
|
|
137
143
|
|
|
138
|
-
The CLI verifies the repository and branch, runs checks, pushes committed source using a short-lived repository-scoped credential, waits for the exact source's healthy
|
|
144
|
+
The CLI verifies the repository and branch, runs checks, pushes committed source using a short-lived repository-scoped credential, waits for the exact source's healthy deployment in the earliest activated environment, and returns that environment's URL without promoting the release further. It never stages or commits files, force-pushes, changes hosting, fabricates testing, or bypasses approval. The --preview-only flag is optional; stopping after the first environment is already the default.
|
|
145
|
+
|
|
146
|
+
Promoting a release to the next activated environment requires an explicit user request, such as "promote this to preview" or "promote this to production". Only for that request run:
|
|
139
147
|
|
|
140
|
-
|
|
148
|
+
npx @backifydev/cli@latest promote
|
|
149
|
+
|
|
150
|
+
Never pass --tested unless the user states that they tested the release. Use backify release-flow --json to read each environment's release, its checks, and what blocks the next promotion.
|
|
151
|
+
|
|
152
|
+
Production requires an explicit user request to deploy to production, such as "deploy to production", "publish to production", or "promote this preview to production", except when production is the application's only environment and is therefore where a plain deployment lands. Only for that explicit request run:
|
|
141
153
|
|
|
142
154
|
npx @backifydev/cli@latest ship --production-deploy
|
|
143
155
|
|
|
144
|
-
Production publication still follows existing Backify permissions, testing, and approval policy. If testing or approval is required, return the
|
|
156
|
+
Production publication still follows existing Backify permissions, testing, and approval policy. If testing or approval is required, return the earlier environment's URL and explain the remaining action; never fabricate testing or bypass approval. Otherwise return the verified production URL and actual check results only after healthy activation. For a plain deployment request, stop at the verified healthy deployment in the earliest activated environment even when production testing and approval are not required. A production-only application whose policy requires preview testing or production approval is refused with preview_required, because those rules need an environment before production: report the refusal, explain that adding a preview or prototype environment resolves it, and add one only when the user asks. An environment_not_activated response means the named environment has not been added; report it rather than targeting another environment. Inspect failures with the status command, fix them, and retry the same target without asking the user to perform routine deployment steps. Never invent a successful check or deployment.
|
|
145
157
|
|
|
146
158
|
## User-facing handoff
|
|
147
159
|
|
|
@@ -149,7 +161,7 @@ If setup is blocked, report the failed or unverified checks and recommend an AI
|
|
|
149
161
|
|
|
150
162
|
Include the verified Local URL, exact start command, and local testing/sign-in steps even when cloud delivery is blocked. If local startup was not verified, say unavailable and explain the blocker.
|
|
151
163
|
|
|
152
|
-
Include separate Preview URL and Production URL
|
|
164
|
+
Include a separate URL line for each activated environment, from Prototype URL, Preview URL and Production URL, using the actual URLs returned by CLI status or deployment results. Leave out environments the application has not added. If an activated environment's URL is unavailable, say not deployed or unavailable and explain why; never invent a URL or claim an unverified deployment is live. When production still serves an earlier release, label it as the existing production version and explain that the new changes are in an earlier environment or awaiting approval.
|
|
153
165
|
|
|
154
166
|
If application requirements are missing after successful setup, finish the response with this exact question as its final line, without any text after it:
|
|
155
167
|
|
|
@@ -371,7 +383,7 @@ function validateProtectionConfig(value, fail, path = "protection") {
|
|
|
371
383
|
if (access.denied !== void 0 && access.denied !== "403" && access.denied !== "404")
|
|
372
384
|
fail(path + ".access.denied", 'Use "403" or "404"');
|
|
373
385
|
if (access.environments !== void 0 && (!Array.isArray(access.environments) || access.environments.length === 0 || new Set(access.environments).size !== access.environments.length || access.environments.some((e) => !ENVIRONMENT_KINDS.includes(e))))
|
|
374
|
-
fail(path + ".access.environments", "List environment kinds: preview, production");
|
|
386
|
+
fail(path + ".access.environments", "List environment kinds: prototype, preview, production");
|
|
375
387
|
}
|
|
376
388
|
}
|
|
377
389
|
const page = value.blockedPage;
|
|
@@ -422,7 +434,7 @@ var init_protection = __esm({
|
|
|
422
434
|
"../platform/dist/protection.js"() {
|
|
423
435
|
"use strict";
|
|
424
436
|
PROTECTION_MODES = ["off", "monitor", "standard", "strict"];
|
|
425
|
-
ENVIRONMENT_KINDS = ["preview", "production"];
|
|
437
|
+
ENVIRONMENT_KINDS = ["prototype", "preview", "production"];
|
|
426
438
|
PROTECTION_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
|
|
427
439
|
AI_CRAWLERS = Object.freeze([
|
|
428
440
|
{ token: "GPTBot", userAgent: "GPTBot", operator: "OpenAI" },
|
|
@@ -1223,6 +1235,13 @@ function validateLockfile(value) {
|
|
|
1223
1235
|
}
|
|
1224
1236
|
if (value.auth !== void 0 && (!object4(value.auth) || !Array.isArray(value.auth.providers) || !Array.isArray(value.auth.roles)))
|
|
1225
1237
|
fail("auth requires providers and roles");
|
|
1238
|
+
else if (value.auth?.defaultProvider !== void 0 && (typeof value.auth.defaultProvider !== "string" || !value.auth.providers.includes(value.auth.defaultProvider)))
|
|
1239
|
+
fail("auth.defaultProvider must be one of auth.providers");
|
|
1240
|
+
if (object4(value.auth) && value.auth.session !== void 0) {
|
|
1241
|
+
const s = value.auth.session;
|
|
1242
|
+
if (!object4(s) || Object.keys(s).some((k) => !["duration", "refresh"].includes(k)) || s.duration !== void 0 && (typeof s.duration !== "string" || !/^(?:[1-9]|1[0-9]|2[0-4])h$/.test(s.duration)) || s.refresh !== void 0 && typeof s.refresh !== "boolean")
|
|
1243
|
+
fail("auth.session needs a 1h-24h duration and a boolean refresh, both optional");
|
|
1244
|
+
}
|
|
1226
1245
|
if (!Array.isArray(value.secrets) || value.secrets.some((s) => typeof s !== "string"))
|
|
1227
1246
|
fail("secrets must be an array of names");
|
|
1228
1247
|
if (value.jobs?.length && !capabilities.has("jobs"))
|
|
@@ -1238,8 +1257,10 @@ function validateLockfile(value) {
|
|
|
1238
1257
|
for (const issue2 of validateAppConfig({ app: { name: "lock-validation" }, kind: "worker", server: { entry: "server/index.ts" }, ...carried }))
|
|
1239
1258
|
if (["config", "ai", "http", "mail", "integrations"].some((key) => issue2.path === key || issue2.path.startsWith(key + ".")))
|
|
1240
1259
|
fail(issue2.path + ": " + issue2.message);
|
|
1260
|
+
if (value.workload !== void 0)
|
|
1261
|
+
validateWorkload(value.workload, fail);
|
|
1241
1262
|
for (const key of Object.keys(value))
|
|
1242
|
-
if (!["lockfileVersion", "app", "sdkVersion", "capabilities", "backend", "frontend", "jobs", "schedules", "events", "storage", "database", "auth", "secrets", "protection", "config", "ai", "http", "mail", "integrations", "retention"].includes(key))
|
|
1263
|
+
if (!["lockfileVersion", "app", "sdkVersion", "capabilities", "backend", "frontend", "jobs", "schedules", "events", "storage", "database", "auth", "secrets", "protection", "config", "ai", "http", "mail", "integrations", "retention", "workload"].includes(key))
|
|
1243
1264
|
fail("Unknown lockfile field " + key);
|
|
1244
1265
|
return errors;
|
|
1245
1266
|
}
|
|
@@ -1264,7 +1285,29 @@ function serializeLockfile(lockfile) {
|
|
|
1264
1285
|
const sort = (value) => Array.isArray(value) ? value.map(sort) : object4(value) ? Object.fromEntries(Object.keys(value).sort().filter((k) => value[k] !== void 0).map((k) => [k, sort(value[k])])) : value;
|
|
1265
1286
|
return JSON.stringify(sort(lockfile), null, 2) + "\n";
|
|
1266
1287
|
}
|
|
1267
|
-
|
|
1288
|
+
function validateWorkload(value, fail) {
|
|
1289
|
+
if (!object4(value)) {
|
|
1290
|
+
fail("workload must be an object");
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
for (const [key, field] of Object.entries(value)) {
|
|
1294
|
+
if (key === "shape") {
|
|
1295
|
+
if (!WORKLOAD_SHAPES.includes(field))
|
|
1296
|
+
fail("workload.shape must be one of " + WORKLOAD_SHAPES.join(", "));
|
|
1297
|
+
} else if (key === "profile") {
|
|
1298
|
+
if (!TARGET_PROFILES.includes(field))
|
|
1299
|
+
fail("workload.profile must be one of " + TARGET_PROFILES.join(", "));
|
|
1300
|
+
} else if (key === "images") {
|
|
1301
|
+
if (!object4(field) || Object.entries(field).some(([role, digest]) => !["web", "worker", "migrate"].includes(role) || typeof digest !== "string" || digest.length !== 71 || !/^sha256:[0-9a-f]{64}$/.test(digest)))
|
|
1302
|
+
fail("workload.images must be an object mapping web, worker or migrate to an immutable SHA-256 digest");
|
|
1303
|
+
} else if (["ssr", "streaming", "batch", "accelerator"].includes(key)) {
|
|
1304
|
+
if (typeof field !== "boolean")
|
|
1305
|
+
fail("workload." + key + " must be true or false");
|
|
1306
|
+
} else
|
|
1307
|
+
fail("workload." + key + " must be absent; workload accepts shape, ssr, streaming, batch, accelerator, profile and images");
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
var LOCKFILE_VERSION, LOCKFILE_NAME, LOCKFILE_MAX_BYTES, HTTP_METHODS, WORKLOAD_SHAPES, TARGET_PROFILES, object4, name, nonEmpty, sha256, ROUTE_PATH, CRON;
|
|
1268
1311
|
var init_lockfile = __esm({
|
|
1269
1312
|
"../platform/dist/lockfile.js"() {
|
|
1270
1313
|
"use strict";
|
|
@@ -1275,6 +1318,8 @@ var init_lockfile = __esm({
|
|
|
1275
1318
|
LOCKFILE_NAME = "backify.lock.json";
|
|
1276
1319
|
LOCKFILE_MAX_BYTES = 2 * 1024 * 1024;
|
|
1277
1320
|
HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
1321
|
+
WORKLOAD_SHAPES = ["static-artifact", "single-image", "separate-images"];
|
|
1322
|
+
TARGET_PROFILES = ["static-serving", "consumption", "dedicated"];
|
|
1278
1323
|
object4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1279
1324
|
name = (value) => typeof value === "string" && /^[a-z][a-z0-9-]{0,62}$/.test(value);
|
|
1280
1325
|
nonEmpty = (value, max = 200) => typeof value === "string" && value.length > 0 && value.length <= max && !/[\x00-\x1f\x7f]/.test(value);
|
|
@@ -1701,7 +1746,7 @@ Run relevant tests, typechecking, lint, and builds using the repository's script
|
|
|
1701
1746
|
|
|
1702
1747
|
## Connected application delivery
|
|
1703
1748
|
|
|
1704
|
-
For connected applications, follow \`BACKIFY.md\` and https://agent.backify.dev/v${INSTRUCTION_VERSION}/delivery.md before changing application code. Record every user build or modification request, including initial requirements, with attachment filenames only; never submit attachment contents or setup credentials. Verify checks and deploy
|
|
1749
|
+
For connected applications, follow \`BACKIFY.md\` and https://agent.backify.dev/v${INSTRUCTION_VERSION}/delivery.md before changing application code. Record every user build or modification request, including initial requirements, with attachment filenames only; never submit attachment contents or setup credentials. Verify checks and deploy through the connected CLI workflow without bypassing testing, approval, or coding-tool permissions. An application always has production; preview and prototype exist only when they have been added, and releases move through the activated environments in the order prototype, preview, production. Run \`backify environments\` before shipping and tell the user where the release will land. A plain deployment request deploys to the earliest activated environment with \`ship\`; that is production when production is the only environment. Promoting a release further toward production requires an explicit user request; approval to merge, push, or retry does not authorize it. Use \`ship --production-deploy\` only for an explicit production request. Add a pre-production stage with \`backify environments add preview|prototype\` only when the user asks for one; an added environment adds usage cost, so never add one unasked. Report only verified deployment URLs.
|
|
1705
1750
|
|
|
1706
1751
|
## Instruction maintenance
|
|
1707
1752
|
|
|
@@ -1769,7 +1814,7 @@ var init_dist = __esm({
|
|
|
1769
1814
|
init_protection();
|
|
1770
1815
|
init_auth_setup();
|
|
1771
1816
|
init_operations();
|
|
1772
|
-
INSTRUCTION_VERSION =
|
|
1817
|
+
INSTRUCTION_VERSION = 21;
|
|
1773
1818
|
SDK_PACKAGE = "@backifydev/sdk";
|
|
1774
1819
|
DOCS_URL = "https://docs.backify.dev";
|
|
1775
1820
|
MAIL_LIMITS = Object.freeze({
|
|
@@ -1914,6 +1959,487 @@ var init_project_metadata = __esm({
|
|
|
1914
1959
|
}
|
|
1915
1960
|
});
|
|
1916
1961
|
|
|
1962
|
+
// src/release-flow.ts
|
|
1963
|
+
var release_flow_exports = {};
|
|
1964
|
+
__export(release_flow_exports, {
|
|
1965
|
+
CommandError: () => CommandError,
|
|
1966
|
+
ENVIRONMENT_FLOW: () => ENVIRONMENT_FLOW,
|
|
1967
|
+
OPTIONAL_ENVIRONMENTS: () => OPTIONAL_ENVIRONMENTS,
|
|
1968
|
+
activatedEnvironments: () => activatedEnvironments,
|
|
1969
|
+
entryBlockedText: () => entryBlockedText,
|
|
1970
|
+
environmentsArguments: () => environmentsArguments,
|
|
1971
|
+
environmentsHelp: () => environmentsHelp,
|
|
1972
|
+
environmentsText: () => environmentsText,
|
|
1973
|
+
gateRows: () => gateRows,
|
|
1974
|
+
pad: () => pad,
|
|
1975
|
+
parse: () => parse,
|
|
1976
|
+
placementDetails: () => placementDetails,
|
|
1977
|
+
placementTargetsText: () => placementTargetsText,
|
|
1978
|
+
placementsText: () => placementsText,
|
|
1979
|
+
promote: () => promote,
|
|
1980
|
+
promoteArguments: () => promoteArguments,
|
|
1981
|
+
promoteHelp: () => promoteHelp,
|
|
1982
|
+
releaseFlow: () => releaseFlow,
|
|
1983
|
+
releaseFlowHelp: () => releaseFlowHelp,
|
|
1984
|
+
releaseFlowText: () => releaseFlowText,
|
|
1985
|
+
runEnvironments: () => runEnvironments,
|
|
1986
|
+
splitDetail: () => splitDetail
|
|
1987
|
+
});
|
|
1988
|
+
function entryBlockedText(flow) {
|
|
1989
|
+
const reasons2 = flow.entryBlockedBy ?? [];
|
|
1990
|
+
if (!reasons2.length) return void 0;
|
|
1991
|
+
return "Production is this application's only environment, and its deployment settings need a release to run in an earlier environment first (" + reasons2.join("; ").toLowerCase() + "). Add one with backify environments add <preview|prototype>, then ship again.";
|
|
1992
|
+
}
|
|
1993
|
+
async function activatedEnvironments(call2, applicationId) {
|
|
1994
|
+
try {
|
|
1995
|
+
const view = await call2("/apps/" + applicationId + "/environments/options");
|
|
1996
|
+
return Array.isArray(view?.flow) && view.flow.every((kind2) => typeof kind2 === "string") && view.flow.length ? view.flow : void 0;
|
|
1997
|
+
} catch {
|
|
1998
|
+
return void 0;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
function parse(args2, command2, booleans, valued) {
|
|
2002
|
+
const flags = /* @__PURE__ */ new Set(), values = {}, positional = [];
|
|
2003
|
+
for (let index = 0; index < args2.length; index++) {
|
|
2004
|
+
const value = args2[index];
|
|
2005
|
+
if (booleans.includes(value)) {
|
|
2006
|
+
if (flags.has(value)) throw new Error("Duplicate option: " + value);
|
|
2007
|
+
flags.add(value);
|
|
2008
|
+
} else if (valued.includes(value)) {
|
|
2009
|
+
if (value in values || !args2[index + 1] || args2[index + 1].startsWith("--")) throw new Error("Specify one value for " + value);
|
|
2010
|
+
values[value] = args2[++index];
|
|
2011
|
+
} else if (value.startsWith("-")) throw new Error("Unknown option for " + command2 + ": " + value);
|
|
2012
|
+
else positional.push(value);
|
|
2013
|
+
}
|
|
2014
|
+
return { flags, values, positional };
|
|
2015
|
+
}
|
|
2016
|
+
function moveArguments(flags, values, positional) {
|
|
2017
|
+
const json3 = flags.has("--json"), yes = flags.has("--yes"), usage = "Use backify environments move <environment> --target <id> --window-start <ISO> --window-end <ISO> [--check] [--yes], or move status|start|abort|confirm <environment>.";
|
|
2018
|
+
if (values["--confirm"]) throw new Error(usage);
|
|
2019
|
+
const sub = positional[1]?.toLowerCase();
|
|
2020
|
+
const moveAction = sub === "status" || sub === "start" || sub === "abort" || sub === "confirm" ? sub : "request";
|
|
2021
|
+
const rawKind = moveAction === "request" ? positional[1] : positional[2];
|
|
2022
|
+
if (positional.length !== (moveAction === "request" ? 2 : 3) || !rawKind) throw new Error("Name the environment to move. " + usage);
|
|
2023
|
+
const kind2 = rawKind.toLowerCase();
|
|
2024
|
+
if (!ENVIRONMENT_FLOW.includes(kind2)) throw new Error("Unknown environment: " + rawKind + ". Use " + ENVIRONMENT_FLOW.join(", ") + ".");
|
|
2025
|
+
const target = values["--target"]?.toLowerCase(), active = values["--active"]?.toLowerCase(), start = values["--window-start"], end = values["--window-end"];
|
|
2026
|
+
if (moveAction !== "request" && (target || start || end || flags.has("--check"))) throw new Error("--target, --window-start, --window-end and --check apply only to requesting a move.");
|
|
2027
|
+
if (moveAction !== "confirm" && active) throw new Error("--active applies to environments move confirm.");
|
|
2028
|
+
if (moveAction === "status" && yes) throw new Error("move status takes only --app and --json.");
|
|
2029
|
+
if (moveAction === "request") {
|
|
2030
|
+
if (!target || !uuid3.test(target)) throw new Error("--target takes a deployment target ID.");
|
|
2031
|
+
if (!start || !end || Number.isNaN(Date.parse(start)) || Number.isNaN(Date.parse(end))) throw new Error("--window-start and --window-end take ISO date-times, for example 2026-11-20T22:00:00Z.");
|
|
2032
|
+
if (Date.parse(end) <= Date.parse(start)) throw new Error("--window-end must be after --window-start.");
|
|
2033
|
+
return { action: "move", moveAction, kind: kind2, target, windowStart: new Date(start).toISOString(), windowEnd: new Date(end).toISOString(), check: flags.has("--check"), yes, json: json3 };
|
|
2034
|
+
}
|
|
2035
|
+
if (moveAction === "confirm" && (!active || !uuid3.test(active))) throw new Error("--active takes the ID of the deployment target that is serving the environment.");
|
|
2036
|
+
return { action: "move", moveAction, kind: kind2, ...active ? { active } : {}, yes, json: json3 };
|
|
2037
|
+
}
|
|
2038
|
+
function moveBackArguments(flags, values, positional) {
|
|
2039
|
+
const usage = "Use backify environments move-back <environment> --window-start <ISO> --window-end <ISO> --confirm <application-slug>.";
|
|
2040
|
+
const rawKind = positional[1];
|
|
2041
|
+
if (positional.length !== 2 || !rawKind) throw new Error("Name the environment to move back. " + usage);
|
|
2042
|
+
const kind2 = rawKind.toLowerCase();
|
|
2043
|
+
if (!ENVIRONMENT_FLOW.includes(kind2)) throw new Error("Unknown environment: " + rawKind + ". Use " + ENVIRONMENT_FLOW.join(", ") + ".");
|
|
2044
|
+
if (values["--target"] || values["--active"] || flags.has("--check") || flags.has("--yes")) throw new Error("A move back goes to the hosting target the environment ran on before and is confirmed with --confirm <application-slug>. " + usage);
|
|
2045
|
+
const start = values["--window-start"], end = values["--window-end"];
|
|
2046
|
+
if (!start || !end || Number.isNaN(Date.parse(start)) || Number.isNaN(Date.parse(end))) throw new Error("--window-start and --window-end take ISO date-times, for example 2026-11-20T22:00:00Z.");
|
|
2047
|
+
if (Date.parse(end) <= Date.parse(start)) throw new Error("--window-end must be after --window-start.");
|
|
2048
|
+
return { action: "move-back", kind: kind2, windowStart: new Date(start).toISOString(), windowEnd: new Date(end).toISOString(), ...values["--confirm"] ? { confirm: values["--confirm"] } : {}, yes: false, json: flags.has("--json") };
|
|
2049
|
+
}
|
|
2050
|
+
function environmentsArguments(args2) {
|
|
2051
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
2052
|
+
const { flags, values, positional } = parse(args2, "environments", ["--json", "--yes", "--check"], ["--app", "--confirm", "--target", "--window-start", "--window-end", "--active"]);
|
|
2053
|
+
const action = positional[0] ?? "list";
|
|
2054
|
+
if (action === "move") return moveArguments(flags, values, positional);
|
|
2055
|
+
if (action === "move-back") return moveBackArguments(flags, values, positional);
|
|
2056
|
+
if (action === "targets") {
|
|
2057
|
+
const kind3 = positional[1]?.toLowerCase();
|
|
2058
|
+
if (positional.length !== 2 || !kind3 || values["--confirm"] || values["--target"] || values["--window-start"] || values["--window-end"] || values["--active"] || flags.has("--yes") || flags.has("--check"))
|
|
2059
|
+
throw new Error("Use backify environments targets <environment> [--json].");
|
|
2060
|
+
if (!ENVIRONMENT_FLOW.includes(kind3)) throw new Error("Unknown environment: " + positional[1] + ". Use " + ENVIRONMENT_FLOW.join(", ") + ".");
|
|
2061
|
+
return { action, kind: kind3, yes: false, json: flags.has("--json") };
|
|
2062
|
+
}
|
|
2063
|
+
if (values["--window-start"] || values["--window-end"] || values["--active"]) throw new Error("--window-start, --window-end and --active apply to environments move.");
|
|
2064
|
+
if (action === "placement") {
|
|
2065
|
+
const json4 = flags.has("--json"), kind3 = positional[1]?.toLowerCase(), target = values["--target"]?.toLowerCase();
|
|
2066
|
+
if (values["--confirm"] || positional.length > 2) throw new Error("Use backify environments placement [<environment> --target <deployment-target-id|default> [--check] [--yes]].");
|
|
2067
|
+
if (!kind3) {
|
|
2068
|
+
if (target || flags.has("--check") || flags.has("--yes")) throw new Error("Name the environment to place: backify environments placement <environment> --target <deployment-target-id|default>.");
|
|
2069
|
+
return { action, yes: false, json: json4 };
|
|
2070
|
+
}
|
|
2071
|
+
if (!ENVIRONMENT_FLOW.includes(kind3)) throw new Error("Unknown environment: " + positional[1] + ". Use " + ENVIRONMENT_FLOW.join(", ") + ".");
|
|
2072
|
+
if (!target || target !== "default" && !uuid3.test(target)) throw new Error("--target takes a deployment target ID, or default for the application's own target.");
|
|
2073
|
+
return { action, kind: kind3, target, check: flags.has("--check"), yes: flags.has("--yes"), json: json4 };
|
|
2074
|
+
}
|
|
2075
|
+
if (flags.has("--check") || values["--target"]) throw new Error("--target and --check apply to environments placement.");
|
|
2076
|
+
if (action !== "list" && action !== "add" && action !== "remove") throw new Error("Unknown environments command: " + action + "\n\n" + environmentsHelp);
|
|
2077
|
+
const json3 = flags.has("--json");
|
|
2078
|
+
if (action === "list") {
|
|
2079
|
+
if (positional.length > 1 || flags.has("--yes") || values["--confirm"]) throw new Error("backify environments takes only --app and --json.\n\n" + environmentsHelp);
|
|
2080
|
+
return { action, yes: false, json: json3 };
|
|
2081
|
+
}
|
|
2082
|
+
const kind2 = positional[1]?.toLowerCase();
|
|
2083
|
+
if (positional.length !== 2 || !kind2) throw new Error(`Use backify environments ${action} <preview|prototype>.`);
|
|
2084
|
+
if (kind2 === "production") throw new Error(action === "add" ? "Production always exists. Add preview or prototype." : "Production cannot be removed. Delete the application instead.");
|
|
2085
|
+
if (!OPTIONAL_ENVIRONMENTS.includes(kind2)) throw new Error(`Unknown environment: ${positional[1]}. Use backify environments ${action} <preview|prototype>.`);
|
|
2086
|
+
if (action === "add" && values["--confirm"]) throw new Error("--confirm applies to environments remove. Use --yes to add without the prompt.");
|
|
2087
|
+
if (action === "remove" && flags.has("--yes")) throw new Error("Removing an environment is confirmed with --confirm <application-slug>, not --yes.");
|
|
2088
|
+
return { action, kind: kind2, confirm: values["--confirm"], yes: flags.has("--yes"), json: json3 };
|
|
2089
|
+
}
|
|
2090
|
+
function pad(rows) {
|
|
2091
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
2092
|
+
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ").trimEnd());
|
|
2093
|
+
}
|
|
2094
|
+
function environmentsText(view) {
|
|
2095
|
+
const rows = [["ENVIRONMENT", "STATE", "HOSTNAME", "BILLING"], ...view.options.map((option2) => [option2.kind, option2.activated ? "activated" : "not activated", option2.hostname, option2.billing])];
|
|
2096
|
+
const addable = view.options.filter((option2) => !option2.activated).map((option2) => option2.kind);
|
|
2097
|
+
return [
|
|
2098
|
+
"Release flow: " + flowText(view.flow),
|
|
2099
|
+
"",
|
|
2100
|
+
...pad(rows),
|
|
2101
|
+
...addable.length ? ["", "Add one with backify environments add <" + addable.join("|") + ">."] : []
|
|
2102
|
+
].join("\n");
|
|
2103
|
+
}
|
|
2104
|
+
function splitDetail(detail) {
|
|
2105
|
+
const text2 = (detail ?? "").trim(), match = /^(.*?)\s*\(([a-z][a-z0-9_]*_[a-z0-9_]+)\)\.?$/s.exec(text2);
|
|
2106
|
+
return match ? { message: match[1].trim(), code: match[2] } : { message: text2, code: null };
|
|
2107
|
+
}
|
|
2108
|
+
function placementDetails(item) {
|
|
2109
|
+
const lines = [];
|
|
2110
|
+
if (item.workloads?.length) lines.push(" workloads: " + item.workloads.map((workload) => (workloadRoles[workload.role] ?? workload.role) + " on " + (workloadProfiles[workload.profile] ?? workload.profile)).join("; "));
|
|
2111
|
+
if (item.foundation) lines.push(" foundation: " + (foundationModes[item.foundation.mode] ?? item.foundation.mode) + "; " + (foundationSeparations[item.foundation.separation] ?? item.foundation.separation));
|
|
2112
|
+
if (item.workloadConformance) {
|
|
2113
|
+
const refusal = splitDetail(item.workloadConformance);
|
|
2114
|
+
lines.push(" attention: " + refusal.message + (refusal.code ? " (" + refusal.code + ")" : ""));
|
|
2115
|
+
}
|
|
2116
|
+
return lines;
|
|
2117
|
+
}
|
|
2118
|
+
function placementsText(placements) {
|
|
2119
|
+
const rows = [["ENVIRONMENT", "HOSTING", "TARGET", "REGION", "RUNTIME", "DELIVERY"], ...placements.map((item) => [item.kind, hostingText(item.hosting), (item.targetName ?? "-") + (item.ownTarget ? " (own target)" : sourceText(item.targetSource)), item.region ?? "-", runtimeText(item.runtime), deliveryText(item.delivery)])];
|
|
2120
|
+
const locations = placements.flatMap((item) => ["", item.name + ":", ...item.locations.map((location) => " " + location.kind.padEnd(9) + " " + location.boundary + (location.region ? " (" + location.region + ")" : "") + ": " + location.detail), ...placementDetails(item)]);
|
|
2121
|
+
return [...pad(rows), ...locations].join("\n");
|
|
2122
|
+
}
|
|
2123
|
+
function placementTargetsText(kind2, result) {
|
|
2124
|
+
if (!result.targets.length) return "There are no hosting targets in this organization.";
|
|
2125
|
+
const rows = [["TARGET", "ID", "REGION", "HOSTING", "STATE", "REASON"], ...result.targets.map((target) => [target.name + (target.applicationTarget ? " (application)" : ""), target.deploymentTargetId, target.region, hostingText(target.hosting), targetState(target), target.eligible ? "" : splitDetail(target.reason).message])];
|
|
2126
|
+
const hints = [
|
|
2127
|
+
...result.targets.some((target) => !target.current && target.eligible && !target.moveRequired) ? ["Place it with backify environments placement " + kind2 + " --target <id>."] : [],
|
|
2128
|
+
...result.targets.some((target) => target.moveRequired && target.eligible) ? ["The " + kind2 + " environment has data where it runs now; reach the others with backify environments move."] : []
|
|
2129
|
+
];
|
|
2130
|
+
return [...pad(rows), ...hints.length ? ["", ...hints] : []].join("\n");
|
|
2131
|
+
}
|
|
2132
|
+
async function runTargets(call2, prefix, options) {
|
|
2133
|
+
const placements = await call2(prefix + "/environments/placements");
|
|
2134
|
+
const current = placements.find((item) => item.kind === options.kind);
|
|
2135
|
+
if (!current) throw new CommandError("This application has no " + options.kind + " environment.", "environment_not_activated", { kind: options.kind });
|
|
2136
|
+
const result = await call2(prefix + "/environments/" + current.environmentId + "/placement/targets");
|
|
2137
|
+
return { value: result, text: placementTargetsText(options.kind, result) };
|
|
2138
|
+
}
|
|
2139
|
+
async function runPlacement(call2, prefix, options, context2) {
|
|
2140
|
+
const placements = await call2(prefix + "/environments/placements");
|
|
2141
|
+
if (!options.kind) return { value: { placements }, text: placementsText(placements) };
|
|
2142
|
+
const current = placements.find((item) => item.kind === options.kind);
|
|
2143
|
+
if (!current) throw new CommandError("This application has no " + options.kind + " environment.", "environment_not_activated", { kind: options.kind });
|
|
2144
|
+
const targetId = options.target === "default" ? null : options.target;
|
|
2145
|
+
const path = prefix + "/environments/" + current.environmentId + "/placement";
|
|
2146
|
+
const preflight = await call2(path + "/preflight" + (targetId ? "?deploymentTargetId=" + encodeURIComponent(targetId) : ""));
|
|
2147
|
+
const checks = pad([["CHECK", "RESULT", "DETAIL"], ...preflight.checks.map((check) => [check.name, check.state, check.detail ?? ""])]);
|
|
2148
|
+
const failed = preflight.checks.filter((check) => check.state === "failed").map((check) => check.id);
|
|
2149
|
+
if (!preflight.ready) return { exitCode: 2, value: { status: "blocked", kind: options.kind, deploymentTargetId: targetId, failed, checks: preflight.checks }, text: [...checks, "", "The " + options.kind + " environment cannot be placed on this hosting target. Nothing was changed."].join("\n") };
|
|
2150
|
+
if (options.check) return { value: { status: "ready", kind: options.kind, deploymentTargetId: targetId, checks: preflight.checks }, text: [...checks, "", "All checks passed. Nothing was changed; re-run without --check to approve the placement."].join("\n") };
|
|
2151
|
+
const summary = "Place the " + options.kind + " environment on " + (targetId ? "deployment target " + targetId : "the application's own hosting target") + ". Its compute, data, files, backups and secrets will be created there by the next release deployed to it.";
|
|
2152
|
+
if (!options.yes) {
|
|
2153
|
+
if (!context2.confirm) throw new CommandError("Refusing to change an environment's hosting target without confirmation. Review this and re-run with --yes:\n" + summary, "confirmation_required", { kind: options.kind, deploymentTargetId: targetId });
|
|
2154
|
+
if (!await context2.confirm(summary)) throw new CommandError("Not confirmed. Nothing was changed.", "not_confirmed");
|
|
2155
|
+
}
|
|
2156
|
+
const placement = await call2(path, { method: "PUT", body: JSON.stringify({ deploymentTargetId: targetId }) });
|
|
2157
|
+
return { value: { status: "placed", kind: options.kind, placement }, text: ["The " + options.kind + " environment is now placed on " + hostingText(placement.hosting) + (placement.targetName ? ", " + placement.targetName : "") + (placement.region ? " (" + placement.region + ")" : "") + ".", "", placementsText([placement])].join("\n") };
|
|
2158
|
+
}
|
|
2159
|
+
async function runMove(call2, prefix, options, context2) {
|
|
2160
|
+
const placements = await call2(prefix + "/environments/placements");
|
|
2161
|
+
const current = placements.find((item) => item.kind === options.kind);
|
|
2162
|
+
if (!current) throw new CommandError("This application has no " + options.kind + " environment.", "environment_not_activated", { kind: options.kind });
|
|
2163
|
+
const base = prefix + "/environments/" + current.environmentId + "/moves";
|
|
2164
|
+
const confirmed = async (summary, details) => {
|
|
2165
|
+
if (options.yes) return;
|
|
2166
|
+
if (!context2.confirm) throw new CommandError("Refusing to change a hosting move without confirmation. Review this and re-run with --yes:\n" + summary, "confirmation_required", { kind: options.kind, ...details });
|
|
2167
|
+
if (!await context2.confirm(summary)) throw new CommandError("Not confirmed. Nothing was changed.", "not_confirmed");
|
|
2168
|
+
};
|
|
2169
|
+
if (options.moveAction === "request") {
|
|
2170
|
+
const query = "destinationTargetId=" + encodeURIComponent(options.target) + "&windowStart=" + encodeURIComponent(options.windowStart) + "&windowEnd=" + encodeURIComponent(options.windowEnd);
|
|
2171
|
+
const preflight = await call2(base + "/preflight?" + query);
|
|
2172
|
+
const checks = pad([["CHECK", "RESULT", "DETAIL"], ...preflight.checks.map((check) => [check.name, check.state, check.detail ?? ""])]);
|
|
2173
|
+
const failed = preflight.checks.filter((check) => check.state === "failed").map((check) => check.id);
|
|
2174
|
+
if (!preflight.ready) return { exitCode: 2, value: { status: "blocked", kind: options.kind, destinationTargetId: options.target, failed, checks: preflight.checks }, text: [...checks, "", "The " + options.kind + " environment cannot be moved to this hosting target in this window. Nothing was changed."].join("\n") };
|
|
2175
|
+
if (options.check) return { value: { status: "ready", kind: options.kind, destinationTargetId: options.target, checks: preflight.checks }, text: [...checks, "", "All checks passed. Nothing was changed; re-run without --check to request the move."].join("\n") };
|
|
2176
|
+
await confirmed("Request moving the " + options.kind + " environment to deployment target " + options.target + " in the window " + options.windowStart + " to " + options.windowEnd + ". Another person must approve it; the environment goes into maintenance only when the move is started.", { destinationTargetId: options.target });
|
|
2177
|
+
const result = await call2(base, { method: "POST", body: JSON.stringify({ destinationTargetId: options.target, windowStart: options.windowStart, windowEnd: options.windowEnd }) });
|
|
2178
|
+
if (!result.created || !result.move) return { exitCode: 2, value: { status: "blocked", kind: options.kind, destinationTargetId: options.target, failed: result.preflight.checks.filter((check) => check.state === "failed").map((check) => check.id), checks: result.preflight.checks }, text: "The checks no longer pass. Nothing was changed." };
|
|
2179
|
+
return { value: { status: "requested", kind: options.kind, move: result.move }, text: ["The move of the " + options.kind + " environment awaits approval. Another person approves it on the organization's Approvals page.", "", ...moveSummary(result.move)].join("\n") };
|
|
2180
|
+
}
|
|
2181
|
+
const moves = await call2(base);
|
|
2182
|
+
const move = moves.find((item) => !moveTerminal(item)) ?? moves[0];
|
|
2183
|
+
if (options.moveAction === "status") return { value: { move: move ?? null }, text: move ? moveSummary(move).join("\n") : "The " + options.kind + " environment has no hosting move." };
|
|
2184
|
+
if (!move) throw new CommandError("The " + options.kind + " environment has no hosting move.", "hosting_move_not_found", { kind: options.kind });
|
|
2185
|
+
const action = options.moveAction;
|
|
2186
|
+
if (!move.actions.includes(action)) throw new CommandError("The " + options.kind + " move does not offer " + action + " now: it is in phase " + move.phase + ", state " + move.state + (move.approvalStatus ? ", approval " + move.approvalStatus : "") + ".", "hosting_move_action_unavailable", { kind: options.kind, action, phase: move.phase, state: move.state, actions: move.actions });
|
|
2187
|
+
if (action === "start") await confirmed("Start the move of the " + options.kind + " environment. It goes into maintenance during the window and writes are paused until the move finishes.", { action });
|
|
2188
|
+
if (action === "abort") await confirmed("Abort the move of the " + options.kind + " environment. It returns to its current hosting.", { action });
|
|
2189
|
+
if (action === "confirm") {
|
|
2190
|
+
if (options.active !== move.sourceTargetId && options.active !== move.destinationTargetId) throw new CommandError("--active must be the current target " + move.sourceTargetId + " or the destination " + move.destinationTargetId + ".", "hosting_move_confirm_target_invalid", { kind: options.kind });
|
|
2191
|
+
await confirmed("Confirm that deployment target " + options.active + " is serving the " + options.kind + " environment. The outcome of the switch is unknown; only confirm after checking.", { action, active: options.active });
|
|
2192
|
+
}
|
|
2193
|
+
const updated = await call2(base + "/" + move.id + "/" + action, { method: "POST", ...action === "confirm" ? { body: JSON.stringify({ activeTargetId: options.active }) } : {} });
|
|
2194
|
+
return { value: { status: action, kind: options.kind, move: updated }, text: ["The " + options.kind + " move: " + action + " accepted.", "", ...moveSummary(updated)].join("\n") };
|
|
2195
|
+
}
|
|
2196
|
+
async function runMoveBack(call2, prefix, options) {
|
|
2197
|
+
const placements = await call2(prefix + "/environments/placements");
|
|
2198
|
+
const current = placements.find((item) => item.kind === options.kind);
|
|
2199
|
+
if (!current) throw new CommandError("This application has no " + options.kind + " environment.", "environment_not_activated", { kind: options.kind });
|
|
2200
|
+
const base = prefix + "/environments/" + current.environmentId + "/moves";
|
|
2201
|
+
const moves = await call2(base);
|
|
2202
|
+
const completed = moves.find((item) => item.state === "completed");
|
|
2203
|
+
if (!completed) throw new CommandError("The " + options.kind + " environment has no completed hosting move to move back.", "hosting_move_not_found", { kind: options.kind });
|
|
2204
|
+
const kept2 = completed.retained ? " The copy there is kept until " + completed.retained.retainedUntil + "; it is reused and checked first." : "";
|
|
2205
|
+
const effect = "Move the " + options.kind + " environment, with its database and files, back to deployment target " + completed.sourceTargetId + " in the window " + options.windowStart + " to " + options.windowEnd + "." + kept2 + " Another person must approve it; the environment goes into maintenance only when the move is started.";
|
|
2206
|
+
const slug = (await call2(prefix)).slug;
|
|
2207
|
+
if (!options.confirm || options.confirm !== slug)
|
|
2208
|
+
throw new CommandError(
|
|
2209
|
+
effect + "\n" + (options.confirm ? "--confirm does not match the application slug. " : "") + "Confirm with the application slug: backify environments move-back " + options.kind + " --window-start " + options.windowStart + " --window-end " + options.windowEnd + " --confirm " + (slug ?? "<application-slug>"),
|
|
2210
|
+
"confirmation_required",
|
|
2211
|
+
{ kind: options.kind, moveId: completed.id, ...slug ? { confirm: slug } : {} }
|
|
2212
|
+
);
|
|
2213
|
+
const result = await call2(base + "/" + completed.id + "/move-back", { method: "POST", body: JSON.stringify({ windowStart: options.windowStart, windowEnd: options.windowEnd }) });
|
|
2214
|
+
if (!result.created || !result.move) {
|
|
2215
|
+
const failed = result.preflight.checks.filter((check) => check.state === "failed");
|
|
2216
|
+
return {
|
|
2217
|
+
exitCode: 2,
|
|
2218
|
+
value: { status: "blocked", kind: options.kind, failed: failed.map((check) => check.id), checks: result.preflight.checks },
|
|
2219
|
+
text: [...pad([["CHECK", "RESULT", "DETAIL"], ...result.preflight.checks.map((check) => [check.name, check.state, check.detail ?? ""])]), "", "The " + options.kind + " environment cannot be moved back in this window. Nothing was changed."].join("\n")
|
|
2220
|
+
};
|
|
2221
|
+
}
|
|
2222
|
+
return { value: { status: "requested", kind: options.kind, move: result.move }, text: ["The move back of the " + options.kind + " environment awaits approval. Another person approves it on the organization's Approvals page; then start it with backify environments move start " + options.kind + ".", "", ...moveSummary(result.move)].join("\n") };
|
|
2223
|
+
}
|
|
2224
|
+
async function runEnvironments(call2, applicationId, options, context2 = {}) {
|
|
2225
|
+
if (!uuid3.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
2226
|
+
const prefix = "/apps/" + applicationId;
|
|
2227
|
+
if (options.action === "placement") return runPlacement(call2, prefix, options, context2);
|
|
2228
|
+
if (options.action === "move") return runMove(call2, prefix, options, context2);
|
|
2229
|
+
if (options.action === "move-back") return runMoveBack(call2, prefix, options);
|
|
2230
|
+
if (options.action === "targets") return runTargets(call2, prefix, options);
|
|
2231
|
+
const view = await call2(prefix + "/environments/options");
|
|
2232
|
+
if (options.action === "list") return { value: { flow: view.flow, environments: view.options }, text: environmentsText(view) };
|
|
2233
|
+
const kind2 = options.kind, option2 = view.options.find((item) => item.kind === kind2);
|
|
2234
|
+
if (!option2) throw new CommandError("This Backify version has no " + kind2 + " environment.", "invalid_environment");
|
|
2235
|
+
if (options.action === "add") {
|
|
2236
|
+
if (option2.activated) throw new CommandError(`This application already has a ${kind2} environment at https://${option2.hostname}.`, "environment_exists", { kind: kind2, hostname: option2.hostname });
|
|
2237
|
+
const flow2 = ENVIRONMENT_FLOW.filter((item) => item === kind2 || view.flow.includes(item));
|
|
2238
|
+
const summary = [
|
|
2239
|
+
`Add the ${kind2} environment at https://${option2.hostname}.`,
|
|
2240
|
+
"Billing: " + option2.billing,
|
|
2241
|
+
`Releases will then move ${flowText(flow2)}; a new release deploys to ${flow2[0]} first. The environment is provisioned by the next release deployed to it.`
|
|
2242
|
+
].join("\n");
|
|
2243
|
+
if (!options.yes) {
|
|
2244
|
+
if (!context2.confirm) throw new CommandError("Refusing to add an environment without confirmation. Review this and re-run with --yes:\n" + summary, "confirmation_required", { kind: kind2, hostname: option2.hostname, billing: option2.billing });
|
|
2245
|
+
if (!await context2.confirm(summary)) throw new CommandError("Not confirmed. Nothing was added.", "not_confirmed");
|
|
2246
|
+
}
|
|
2247
|
+
const environment = await call2(prefix + "/environments", { method: "POST", body: JSON.stringify({ kind: kind2 }) });
|
|
2248
|
+
return {
|
|
2249
|
+
value: { status: "added", kind: kind2, hostname: option2.hostname, billing: option2.billing, flow: flow2, environment },
|
|
2250
|
+
text: [`Added the ${kind2} environment: https://${option2.hostname}`, "Billing: " + option2.billing, "Release flow: " + flowText(flow2), `It is provisioned by the next release deployed to it${flow2[0] === kind2 ? " (backify ship)" : " (backify promote)"}.`].join("\n")
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
if (!option2.activated) throw new CommandError(`This application has no ${kind2} environment.`, "environment_not_activated", { kind: kind2 });
|
|
2254
|
+
const effect = `Removing ${kind2} takes https://${option2.hostname} offline and removes it from the release flow. Its database, files, secrets and configuration are kept, and adding the environment again restores them.`;
|
|
2255
|
+
if (!options.confirm) {
|
|
2256
|
+
const slug = (await call2(prefix)).slug;
|
|
2257
|
+
throw new CommandError(`${effect}
|
|
2258
|
+
Confirm with the application slug: backify environments remove ${kind2} --confirm ${slug ?? "<application-slug>"}`, "confirmation_required", { kind: kind2, hostname: option2.hostname, dataRetained: true, ...slug ? { confirm: slug } : {} });
|
|
2259
|
+
}
|
|
2260
|
+
await call2(prefix + "/environments/" + kind2, { method: "DELETE", body: JSON.stringify({ confirm: options.confirm }) });
|
|
2261
|
+
const flow = view.flow.filter((item) => item !== kind2);
|
|
2262
|
+
return {
|
|
2263
|
+
value: { status: "removed", kind: kind2, hostname: option2.hostname, dataRetained: true, flow },
|
|
2264
|
+
text: [`Removed the ${kind2} environment: https://${option2.hostname} is offline.`, "Its database, files, secrets and configuration are kept; backify environments add " + kind2 + " restores them.", "Release flow: " + flowText(flow)].join("\n")
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
function duration(seconds) {
|
|
2268
|
+
if (seconds === null || seconds === void 0) return "";
|
|
2269
|
+
return seconds >= 60 ? Math.floor(seconds / 60) + "m " + seconds % 60 + "s" : seconds + "s";
|
|
2270
|
+
}
|
|
2271
|
+
function promotionText(stage, promotion) {
|
|
2272
|
+
const label = "Promote to " + promotion.targetName + ": ";
|
|
2273
|
+
switch (promotion.state) {
|
|
2274
|
+
case "blocked":
|
|
2275
|
+
return label + "blocked by " + (promotion.blockedBy.join(", ") || "unfinished checks");
|
|
2276
|
+
case "ready":
|
|
2277
|
+
return label + "ready" + (promotion.permitted ? "" : " (you do not have permission to promote)") + (promotion.requiresTesting ? "; needs --tested" : "") + (promotion.requiresConfirmation ? "; needs confirmation" : "");
|
|
2278
|
+
case "empty":
|
|
2279
|
+
return label + "nothing to promote. " + (promotion.blockedBy[0] ?? "No release has been deployed to " + stage.name + " yet.");
|
|
2280
|
+
case "done":
|
|
2281
|
+
return "Promoted to " + promotion.targetName + (promotion.promotedBy ? " by " + promotion.promotedBy : "") + (promotion.promotedAt ? " at " + promotion.promotedAt : "");
|
|
2282
|
+
case "awaiting-approval":
|
|
2283
|
+
return label + "awaiting approval";
|
|
2284
|
+
case "awaiting-configuration":
|
|
2285
|
+
return label + "awaiting configuration";
|
|
2286
|
+
default:
|
|
2287
|
+
return label + promotion.state;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
function releaseFlowText(flow) {
|
|
2291
|
+
const lines = ["Release flow: " + flowText(flow.stages.map((stage) => stage.kind))];
|
|
2292
|
+
for (const stage of flow.stages) {
|
|
2293
|
+
lines.push("", `${stage.name} (${stage.kind}) ${stage.url}`);
|
|
2294
|
+
const release2 = stage.deployment;
|
|
2295
|
+
lines.push(release2 ? ` Release ${shortCommit(release2)}: ${release2.status}${release2.healthResult ? ", " + release2.healthResult : ""}` : " No release deployed yet");
|
|
2296
|
+
const groups = [...new Set(stage.gates.map((gate) => gate.group))];
|
|
2297
|
+
for (const group of groups) {
|
|
2298
|
+
lines.push(" " + group);
|
|
2299
|
+
const rows = stage.gates.filter((gate) => gate.group === group).map((gate) => [gate.state, gate.name, duration(gate.durationSeconds), [gate.detail, gate.actionUrl ? (gate.actionLabel ?? "Open") + ": " + gate.actionUrl : null].filter(Boolean).join(" ")]);
|
|
2300
|
+
for (const row of pad(rows)) lines.push(" " + row);
|
|
2301
|
+
}
|
|
2302
|
+
if (stage.promotion) lines.push(" " + promotionText(stage, stage.promotion));
|
|
2303
|
+
}
|
|
2304
|
+
const blocked = entryBlockedText(flow);
|
|
2305
|
+
if (blocked) lines.push("", "Blocked: " + blocked);
|
|
2306
|
+
return lines.join("\n");
|
|
2307
|
+
}
|
|
2308
|
+
function gateRows(flow) {
|
|
2309
|
+
return flow.stages.flatMap((stage) => stage.gates.map((gate) => ({ stage: stage.kind, group: gate.group, gate: gate.name, state: gate.state, durationSeconds: gate.durationSeconds ?? null, reason: gate.detail ?? null })));
|
|
2310
|
+
}
|
|
2311
|
+
async function releaseFlow(call2, applicationId) {
|
|
2312
|
+
if (!uuid3.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
2313
|
+
const flow = await call2("/apps/" + applicationId + "/release-flow");
|
|
2314
|
+
return { value: flow, text: releaseFlowText(flow) };
|
|
2315
|
+
}
|
|
2316
|
+
function promoteArguments(args2) {
|
|
2317
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
2318
|
+
const { flags, positional } = parse(args2, "promote", ["--json", "--yes", "--tested"], ["--app"]);
|
|
2319
|
+
if (positional.length) throw new Error("backify promote takes no arguments: it promotes to the next activated environment.\n\n" + promoteHelp);
|
|
2320
|
+
return { tested: flags.has("--tested"), yes: flags.has("--yes"), json: flags.has("--json") };
|
|
2321
|
+
}
|
|
2322
|
+
async function promote(call2, applicationId, options, context2 = {}) {
|
|
2323
|
+
if (!uuid3.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
2324
|
+
const prefix = "/apps/" + applicationId;
|
|
2325
|
+
const flow = await call2(prefix + "/release-flow");
|
|
2326
|
+
const stage = flow.stages.find((item) => item.promotion?.state === "ready");
|
|
2327
|
+
if (!stage) {
|
|
2328
|
+
const waiting = flow.stages.filter((item) => item.promotion && item.promotion.state !== "done");
|
|
2329
|
+
const blocked = waiting.find((item) => item.promotion.state === "blocked");
|
|
2330
|
+
const value = {
|
|
2331
|
+
status: blocked ? "blocked" : waiting.length ? "not-ready" : "nothing-to-promote",
|
|
2332
|
+
stages: waiting.map((item) => ({ environment: item.kind, target: item.promotion.target, state: item.promotion.state, blockedBy: item.promotion.blockedBy, release: item.deployment ? shortCommit(item.deployment) : null }))
|
|
2333
|
+
};
|
|
2334
|
+
const text2 = waiting.length ? ["No release is ready to promote. Nothing was sent.", ...waiting.map((item) => `${item.name}: ${promotionText(item, item.promotion)}`), "Run backify release-flow for every check."].join("\n") : flow.stages.length < 2 ? entryBlockedText(flow) ?? "Production is this application's only environment; there is nothing to promote. Add one with backify environments add <preview|prototype>." : "Every release is already promoted. Nothing was sent.";
|
|
2335
|
+
return { value, text: text2, exitCode: waiting.length ? 2 : 0 };
|
|
2336
|
+
}
|
|
2337
|
+
const promotion = stage.promotion, release2 = stage.deployment;
|
|
2338
|
+
const source = promotion.sourceDeploymentId;
|
|
2339
|
+
if (!source) throw new CommandError("The release flow names no release to promote. Run backify release-flow.", "release_unavailable");
|
|
2340
|
+
const facts = { environment: stage.kind, target: promotion.target, release: shortCommit(release2), sourceDeploymentId: source };
|
|
2341
|
+
if (!promotion.permitted) throw new CommandError(`You do not have permission to promote to ${promotion.targetName}. Nothing was sent.`, "forbidden", facts);
|
|
2342
|
+
if (promotion.requiresTesting && !options.tested)
|
|
2343
|
+
throw new CommandError(`The publish rules require this release to be tested in ${stage.name} (${stage.url}) before it goes to ${promotion.targetName}. Test it, then re-run with --tested to confirm you did. Nothing was sent.`, "testing_required", facts);
|
|
2344
|
+
if (promotion.requiresConfirmation && !options.yes) {
|
|
2345
|
+
const application = await call2(prefix);
|
|
2346
|
+
const name2 = application.name ?? application.slug ?? applicationId;
|
|
2347
|
+
const message = `Promote ${name2} release ${shortCommit(release2)} from ${stage.name} to ${promotion.targetName}?` + (options.tested ? " This records that you tested the release." : "") + (flow.policy.requireProductionApproval ? " An approval request is created; production changes after someone else approves." : " Production changes immediately.");
|
|
2348
|
+
if (!context2.confirm) throw new CommandError("Refusing to promote to " + promotion.targetName + " without confirmation. Review this and re-run with --yes:\n" + message, "confirmation_required", { ...facts, application: name2 });
|
|
2349
|
+
if (!await context2.confirm(message)) throw new CommandError("Not confirmed. Nothing was promoted.", "not_confirmed");
|
|
2350
|
+
}
|
|
2351
|
+
const result = await call2(
|
|
2352
|
+
prefix + "/deployments/promote",
|
|
2353
|
+
{ method: "POST", headers: { "Idempotency-Key": "cli-promote-" + source + "-" + promotion.target }, body: JSON.stringify({ previewDeploymentId: source, tested: options.tested, target: promotion.target }) }
|
|
2354
|
+
);
|
|
2355
|
+
const status = result.approvalId || result.status === "awaiting-approval" ? "awaiting-approval" : result.status === "awaiting-configuration" ? "awaiting-configuration" : "promoting";
|
|
2356
|
+
const outcome = status === "awaiting-approval" ? `Approval requested. ${promotion.targetName} changes after someone other than you approves.` : status === "awaiting-configuration" ? (result.error?.message ?? `${promotion.targetName} needs configuration before this release deploys.`) + (result.error?.setupUrl ? " " + result.error.setupUrl : "") : `Promotion to ${promotion.targetName} started.`;
|
|
2357
|
+
return { value: { ...facts, ...result, status }, text: `${stage.name} release ${shortCommit(release2)} -> ${promotion.targetName}
|
|
2358
|
+
${outcome}
|
|
2359
|
+
Run backify release-flow to follow it.`, exitCode: status === "promoting" ? 0 : 2 };
|
|
2360
|
+
}
|
|
2361
|
+
var ENVIRONMENT_FLOW, OPTIONAL_ENVIRONMENTS, CommandError, environmentsHelp, releaseFlowHelp, promoteHelp, uuid3, flowText, shortCommit, hostingText, runtimeText, deliveryText, workloadRoles, workloadProfiles, foundationModes, foundationSeparations, sourceText, targetState, moveTerminal, moveSummary;
|
|
2362
|
+
var init_release_flow = __esm({
|
|
2363
|
+
"src/release-flow.ts"() {
|
|
2364
|
+
"use strict";
|
|
2365
|
+
ENVIRONMENT_FLOW = ["prototype", "preview", "production"];
|
|
2366
|
+
OPTIONAL_ENVIRONMENTS = ["preview", "prototype"];
|
|
2367
|
+
CommandError = class extends Error {
|
|
2368
|
+
constructor(message, code, details = {}) {
|
|
2369
|
+
super(message);
|
|
2370
|
+
this.code = code;
|
|
2371
|
+
this.details = details;
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
environmentsHelp = [
|
|
2375
|
+
"Usage: backify environments [list|add|remove|placement|move|move-back] [options]",
|
|
2376
|
+
"",
|
|
2377
|
+
" backify environments Every environment kind in release order: activated or not, hostname and billing",
|
|
2378
|
+
" backify environments add <preview|prototype> [--yes] Add an environment; asks y/N on a terminal, otherwise needs --yes",
|
|
2379
|
+
" backify environments remove <preview|prototype> --confirm <application-slug>",
|
|
2380
|
+
" Take an environment offline; its data is kept and adding it again restores it",
|
|
2381
|
+
" backify environments placement Where each environment is hosted: target, region, Runtime state, data locations, where each workload runs and the regional foundation",
|
|
2382
|
+
" backify environments placement <environment> --target <deployment-target-id|default> [--check] [--yes]",
|
|
2383
|
+
" Check, then approve, an environment's hosting target; --check only runs the checks (exit 2 if any fails)",
|
|
2384
|
+
" backify environments targets <environment> The hosting targets the environment may use, each eligible or with the check that stops it and why",
|
|
2385
|
+
" backify environments move <environment> --target <deployment-target-id> --window-start <ISO> --window-end <ISO> [--check] [--yes]",
|
|
2386
|
+
" Move an environment that has data to another hosting target in a maintenance window; another person approves it (exit 2 if a check fails)",
|
|
2387
|
+
" backify environments move status <environment> The current or latest move: phase, state, window, approval, verification and what is retained",
|
|
2388
|
+
" backify environments move start|abort <environment> [--yes] Start an approved move (maintenance begins) or abort it (the environment stays on its current hosting)",
|
|
2389
|
+
" backify environments move confirm <environment> --active <deployment-target-id> [--yes]",
|
|
2390
|
+
" When the switch outcome is unknown: name the target you checked is serving",
|
|
2391
|
+
" backify environments move-back <environment> --window-start <ISO> --window-end <ISO> --confirm <application-slug>",
|
|
2392
|
+
" Move an environment back to the target its latest completed move left, while that target keeps its copy; another person approves it",
|
|
2393
|
+
"",
|
|
2394
|
+
"Options: --app <application> (default: the application in this folder) --json (machine-readable output and errors)",
|
|
2395
|
+
"Releases move prototype -> preview -> production through the activated environments only. Production always exists.",
|
|
2396
|
+
"A new release deploys to the earliest activated environment; backify promote moves it to the next one."
|
|
2397
|
+
].join("\n");
|
|
2398
|
+
releaseFlowHelp = [
|
|
2399
|
+
"Usage: backify release-flow [--app <application>] [--json]",
|
|
2400
|
+
"",
|
|
2401
|
+
"Shows each activated environment in release order with its current release, its checks",
|
|
2402
|
+
"(passed, failed, running, waiting, skipped, pending) with durations, and the promotion to the next",
|
|
2403
|
+
"environment with what blocks it. Exit code 0; read-only."
|
|
2404
|
+
].join("\n");
|
|
2405
|
+
promoteHelp = [
|
|
2406
|
+
"Usage: backify promote [--tested] [--yes] [--app <application>] [--json]",
|
|
2407
|
+
"",
|
|
2408
|
+
"Promotes the current release of the earliest environment whose promotion is ready to the next activated",
|
|
2409
|
+
"environment (prototype -> preview -> production). Nothing is sent when the promotion is blocked: the",
|
|
2410
|
+
"blocking checks are listed and the exit code is 2.",
|
|
2411
|
+
" --tested Confirms you tested this release; required when the publish rules ask for testing before production",
|
|
2412
|
+
" --yes Confirms a promotion to production without the y/N prompt (required when no terminal is attached)",
|
|
2413
|
+
"Production applies the publish rules: testing, approval and organization policies, as in the portal."
|
|
2414
|
+
].join("\n");
|
|
2415
|
+
uuid3 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
2416
|
+
flowText = (kinds) => kinds.join(" -> ");
|
|
2417
|
+
shortCommit = (release2) => (release2?.sourceCommitSha || release2?.commitSha || "").slice(0, 12) || "unknown commit";
|
|
2418
|
+
hostingText = (hosting) => hosting === "backify-cloud" ? "Backify Cloud" : hosting === "customer-azure" ? "Your Azure subscription" : "Local";
|
|
2419
|
+
runtimeText = (runtime) => runtime.state === "failed" ? "failed" + (runtime.failureCode ? " (" + runtime.failureCode + ")" : "") : runtime.state === "pending" ? "applying" : runtime.state === "applied" ? "up to date" : "-";
|
|
2420
|
+
deliveryText = (delivery) => !delivery ? "-" : delivery.state === "delivered" ? "delivered " + delivery.digest.replace(/^sha256:/i, "").slice(0, 12) : delivery.state === "importing" ? "delivering" : delivery.state === "pending" ? "waiting" : "failed" + (delivery.failureCode ? " (" + delivery.failureCode + ")" : "");
|
|
2421
|
+
workloadRoles = { frontend: "Static files", web: "Web", worker: "Worker", migrate: "Migrations" };
|
|
2422
|
+
workloadProfiles = { "static-serving": "Static serving", consumption: "Consumption", dedicated: "Dedicated" };
|
|
2423
|
+
foundationModes = { shared: "shared with other applications", dedicated: "dedicated to your organization", private: "private network", adopted: "your existing resources" };
|
|
2424
|
+
foundationSeparations = { required: "production and non-production run apart", shared: "production and non-production share it" };
|
|
2425
|
+
sourceText = (source) => source === "workspace-default" ? " (workspace default)" : source === "organization-default" ? " (organization default)" : "";
|
|
2426
|
+
targetState = (target) => target.current ? "current" : !target.eligible ? "not eligible" : target.moveRequired ? "needs a move" : "eligible";
|
|
2427
|
+
moveTerminal = (move) => move.state === "completed" || move.state === "aborted" || move.state === "failed";
|
|
2428
|
+
moveSummary = (move) => {
|
|
2429
|
+
const lines = ["Phase: " + move.phase, "State: " + move.state + (move.failureCode ? " (" + move.failureCode + ")" : ""), "Window: " + move.windowStart + " to " + move.windowEnd, "Approval: " + (move.approvalStatus ?? "-")];
|
|
2430
|
+
if (move.reversesMoveId) lines.push("Move back: reverses move " + move.reversesMoveId);
|
|
2431
|
+
if (move.detail) lines.push("Detail: " + move.detail);
|
|
2432
|
+
if (move.verification) {
|
|
2433
|
+
const v = move.verification;
|
|
2434
|
+
lines.push("Verified: " + (v.passed ? "passed" : "not passed") + ", " + v.tables + " tables, " + v.rows + " rows, " + v.files + " files" + (v.mismatches.length ? ", mismatches: " + v.mismatches.join("; ") : ""));
|
|
2435
|
+
}
|
|
2436
|
+
if (move.retained) lines.push("Retained: " + move.retained.assets.join(", ") + " on " + move.retained.targetId + " until " + move.retained.retainedUntil);
|
|
2437
|
+
lines.push("Actions: " + (move.actions.length ? move.actions.join(", ") : "none"));
|
|
2438
|
+
return lines;
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
});
|
|
2442
|
+
|
|
1917
2443
|
// src/human-task.ts
|
|
1918
2444
|
import { hostname } from "node:os";
|
|
1919
2445
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
@@ -1923,7 +2449,7 @@ function portalOrigin2(input) {
|
|
|
1923
2449
|
return url2.origin;
|
|
1924
2450
|
}
|
|
1925
2451
|
function validateHumanTask(status, kind2, applicationId) {
|
|
1926
|
-
if (!status || !
|
|
2452
|
+
if (!status || !uuid4.test(status.id) || status.kind !== kind2 || !states.includes(status.state) || applicationId !== void 0 && status.applicationId?.toLowerCase() !== applicationId.toLowerCase() || status.subjectId !== null && !uuid4.test(status.subjectId))
|
|
1927
2453
|
throw new Error("The server returned invalid task metadata.");
|
|
1928
2454
|
return status;
|
|
1929
2455
|
}
|
|
@@ -1973,16 +2499,16 @@ Check that the page shows the code ${status.matchCode}.` : ""));
|
|
|
1973
2499
|
status = { ...next, matchCode: status.matchCode };
|
|
1974
2500
|
}
|
|
1975
2501
|
}
|
|
1976
|
-
var
|
|
2502
|
+
var uuid4, states, isUuid, humanTaskClient, readHumanTask;
|
|
1977
2503
|
var init_human_task = __esm({
|
|
1978
2504
|
"src/human-task.ts"() {
|
|
1979
2505
|
"use strict";
|
|
1980
|
-
|
|
2506
|
+
uuid4 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
1981
2507
|
states = ["pending", "completed", "declined", "expired", "failed"];
|
|
1982
|
-
isUuid = (value) =>
|
|
2508
|
+
isUuid = (value) => uuid4.test(value);
|
|
1983
2509
|
humanTaskClient = { clientName: "Backify CLI", clientDevice: hostname() };
|
|
1984
2510
|
readHumanTask = (call2, id) => {
|
|
1985
|
-
if (!
|
|
2511
|
+
if (!uuid4.test(id)) throw new Error("Use a valid task ID.");
|
|
1986
2512
|
return call2("/tasks/" + id.toLowerCase());
|
|
1987
2513
|
};
|
|
1988
2514
|
}
|
|
@@ -1994,7 +2520,7 @@ var init_package = __esm({
|
|
|
1994
2520
|
"package.json"() {
|
|
1995
2521
|
package_default = {
|
|
1996
2522
|
name: "@backifydev/cli",
|
|
1997
|
-
version: "0.4.
|
|
2523
|
+
version: "0.4.6",
|
|
1998
2524
|
description: "Command-line setup and diagnostics for Backify applications",
|
|
1999
2525
|
type: "module",
|
|
2000
2526
|
bin: {
|
|
@@ -2079,8 +2605,8 @@ function validateDeliveryInstructions(root) {
|
|
|
2079
2605
|
function installDeliveryInstructions(root, instructionFiles2) {
|
|
2080
2606
|
validateDeliveryInstructions(root);
|
|
2081
2607
|
writeFileSync4(join4(root, "BACKIFY.md"), deliveryInstructions);
|
|
2082
|
-
for (const
|
|
2083
|
-
const instructionPath = join4(root,
|
|
2608
|
+
for (const relative5 of instructionFiles2) {
|
|
2609
|
+
const instructionPath = join4(root, relative5), content = readFileSync4(instructionPath, "utf8");
|
|
2084
2610
|
const link = relativePath(dirname(instructionPath), join4(root, "BACKIFY.md")).replaceAll("\\", "/");
|
|
2085
2611
|
const legacyLink = relativePath(dirname(instructionPath), join4(root, "BACKIFY-WORKFLOW.md")).replaceAll("\\", "/");
|
|
2086
2612
|
const legacy = "For application delivery and recording each user request, follow [BACKIFY-WORKFLOW.md](" + legacyLink + ").";
|
|
@@ -2163,8 +2689,8 @@ function detectPackageManager(root = process.cwd()) {
|
|
|
2163
2689
|
return "npm";
|
|
2164
2690
|
}
|
|
2165
2691
|
function updateInstructions(root = process.cwd(), agent, instructionFile) {
|
|
2166
|
-
const updates = selectedInstructionFiles(root, agent, instructionFile).map((
|
|
2167
|
-
const path = join6(root,
|
|
2692
|
+
const updates = selectedInstructionFiles(root, agent, instructionFile).map((relative5) => {
|
|
2693
|
+
const path = join6(root, relative5);
|
|
2168
2694
|
return { path, content: updateManagedInstructions(existsSync5(path) ? readFileSync6(path, "utf8") : "") };
|
|
2169
2695
|
});
|
|
2170
2696
|
for (const { path, content } of updates) {
|
|
@@ -2213,7 +2739,7 @@ function initialize(appId, root = process.cwd(), install = true, agent, instruct
|
|
|
2213
2739
|
if (existingApp && existingApp !== appId) throw new Error("The project is connected to a different application. Reconcile app.id before initializing.");
|
|
2214
2740
|
const selected = instructionSelection(root, agent, instructionFile), files = selected.files;
|
|
2215
2741
|
validateDeliveryInstructions(root);
|
|
2216
|
-
for (const
|
|
2742
|
+
for (const relative5 of files) if (existsSync5(join6(root, relative5))) updateManagedInstructions(readFileSync6(join6(root, relative5), "utf8"));
|
|
2217
2743
|
const customContainer = !existsSync5(join6(root, "package.json")) && existsSync5(join6(root, "Dockerfile"));
|
|
2218
2744
|
if (!customContainer) {
|
|
2219
2745
|
ensurePackageManifest(root);
|
|
@@ -2250,10 +2776,10 @@ function doctor(root = process.cwd(), agent, instructionFile) {
|
|
|
2250
2776
|
} catch (reason) {
|
|
2251
2777
|
issues.push(reason instanceof Error ? reason.message : String(reason));
|
|
2252
2778
|
}
|
|
2253
|
-
for (const
|
|
2254
|
-
const path = join6(root,
|
|
2779
|
+
for (const relative5 of files) {
|
|
2780
|
+
const path = join6(root, relative5);
|
|
2255
2781
|
if (!existsSync5(path)) {
|
|
2256
|
-
issues.push(`${
|
|
2782
|
+
issues.push(`${relative5} is missing`);
|
|
2257
2783
|
continue;
|
|
2258
2784
|
}
|
|
2259
2785
|
const content = readFileSync6(path, "utf8");
|
|
@@ -2261,10 +2787,10 @@ function doctor(root = process.cwd(), agent, instructionFile) {
|
|
|
2261
2787
|
if (config2 && config2.instructionVersion < INSTRUCTION_VERSION) {
|
|
2262
2788
|
const declared = content.match(/Instruction version:\s*(\d+)/)?.[1];
|
|
2263
2789
|
const structural = managed.filter((issue2) => !issue2.includes("stale or inconsistent"));
|
|
2264
|
-
issues.push(...structural.map((issue2) =>
|
|
2265
|
-
if (Number(declared) !== config2.instructionVersion || !content.includes("https://agent.backify.dev/v" + config2.instructionVersion)) issues.push(
|
|
2266
|
-
else warnings.push(
|
|
2267
|
-
} else issues.push(...managed.map((issue2) =>
|
|
2790
|
+
issues.push(...structural.map((issue2) => relative5 + " " + issue2));
|
|
2791
|
+
if (Number(declared) !== config2.instructionVersion || !content.includes("https://agent.backify.dev/v" + config2.instructionVersion)) issues.push(relative5 + " does not match the repository instruction version");
|
|
2792
|
+
else warnings.push(relative5 + " uses supported older instructions; follow the versioned guide. Run backify sync only when intentionally upgrading instructions.");
|
|
2793
|
+
} else issues.push(...managed.map((issue2) => relative5 + " " + issue2));
|
|
2268
2794
|
}
|
|
2269
2795
|
let version2 = "unknown";
|
|
2270
2796
|
try {
|
|
@@ -2393,6 +2919,7 @@ function apiClient(session, transport = fetch) {
|
|
|
2393
2919
|
}
|
|
2394
2920
|
throw new Error(message);
|
|
2395
2921
|
}
|
|
2922
|
+
if (new Headers(init?.headers).get("accept")?.startsWith("text/plain")) return await response.text();
|
|
2396
2923
|
return response.status === 204 ? void 0 : await response.json();
|
|
2397
2924
|
};
|
|
2398
2925
|
}
|
|
@@ -2406,7 +2933,15 @@ function saveUserConfig(path, config2) {
|
|
|
2406
2933
|
const secured = spawnSync4("icacls", [temporary, "/inheritance:r", "/grant:r", account + ":(F)"], { windowsHide: true, encoding: "utf8" });
|
|
2407
2934
|
if (secured.status !== 0) throw new Error("Could not restrict CLI credential file permissions.");
|
|
2408
2935
|
}
|
|
2409
|
-
|
|
2936
|
+
for (let attempt = 0; ; attempt++) {
|
|
2937
|
+
try {
|
|
2938
|
+
renameSync(temporary, path);
|
|
2939
|
+
break;
|
|
2940
|
+
} catch (error2) {
|
|
2941
|
+
if (process.platform !== "win32" || attempt >= 5 || !["EPERM", "EBUSY", "EACCES"].includes(error2.code ?? "")) throw error2;
|
|
2942
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 40 * (attempt + 1));
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2410
2945
|
} finally {
|
|
2411
2946
|
rmSync(temporary, { force: true });
|
|
2412
2947
|
}
|
|
@@ -2538,23 +3073,26 @@ function pushSource(appId, commit, branch, destination, root, environment) {
|
|
|
2538
3073
|
git(["push", "--", destination, commit + ":refs/heads/" + branch], root, environment);
|
|
2539
3074
|
return false;
|
|
2540
3075
|
}
|
|
2541
|
-
async function
|
|
3076
|
+
async function waitForRelease(call2, prefix, commit, environment, options = {}) {
|
|
2542
3077
|
const deadline = Date.now() + (options.timeoutMs ?? 20 * 6e4);
|
|
2543
|
-
const sleep = options.sleep ?? ((delay4) => new Promise((
|
|
3078
|
+
const sleep = options.sleep ?? ((delay4) => new Promise((resolve10) => setTimeout(resolve10, delay4)));
|
|
3079
|
+
const untouched = environment === "production" ? "" : " No production release was requested.";
|
|
2544
3080
|
do {
|
|
2545
3081
|
const deployments = await call2(prefix + "/deployments");
|
|
2546
|
-
const matching = deployments.find((release2) => release2.kind ===
|
|
3082
|
+
const matching = deployments.find((release2) => release2.kind === environment && matchesSource(release2, commit) && !options.previousDeploymentIds?.includes(release2.id));
|
|
2547
3083
|
if (matching?.status === "failed") throw new Error("Deployment of this source failed. Run backify status and inspect its deployment steps.");
|
|
2548
|
-
const
|
|
2549
|
-
|
|
3084
|
+
const flow = await call2(prefix + "/release-flow");
|
|
3085
|
+
const stage = flow.stages?.find((item) => item.kind === environment);
|
|
3086
|
+
if (!stage) throw new Error(`The application no longer has a ${environment} environment. Run backify environments, then ship again.`);
|
|
3087
|
+
if (matchesSource(stage.deployment ?? void 0, commit) && healthy(stage.deployment)) return flow;
|
|
2550
3088
|
const build2 = await call2(prefix + "/developer/build?commitSha=" + commit);
|
|
2551
3089
|
if ((options.previousBuildRunId === void 0 || build2.runId !== options.previousBuildRunId) && ["failure", "cancelled", "timed_out", "action_required", "startup_failure"].includes(build2.conclusion ?? "")) {
|
|
2552
3090
|
const details = build2.failure ? " Stage: " + build2.failure.stage + ". " + build2.failure.remediation : "";
|
|
2553
|
-
throw new Error("GitHub build " + build2.conclusion + " for source " + commit + "." + details +
|
|
3091
|
+
throw new Error("GitHub build " + build2.conclusion + " for source " + commit + "." + details + untouched + " " + (build2.url ?? "Run backify status for details."));
|
|
2554
3092
|
}
|
|
2555
3093
|
await sleep(options.intervalMs ?? 4e3);
|
|
2556
3094
|
} while (Date.now() < deadline);
|
|
2557
|
-
throw new Error(
|
|
3095
|
+
throw new Error(`Timed out waiting for this commit's healthy ${environment} release. Run backify status.` + untouched);
|
|
2558
3096
|
}
|
|
2559
3097
|
async function ship(call2, appId, options = {}) {
|
|
2560
3098
|
const root = options.root ?? process.cwd(), prefix = "/apps/" + applicationGuid(appId);
|
|
@@ -2571,10 +3109,27 @@ async function ship(call2, appId, options = {}) {
|
|
|
2571
3109
|
if (git(["branch", "--show-current"], root) !== status.branch) throw new Error("Use the connected branch: " + status.branch);
|
|
2572
3110
|
if (git(["status", "--porcelain"], root)) throw new Error("Commit application changes before shipping. The CLI never stages or commits unrelated files.");
|
|
2573
3111
|
const commit = git(["rev-parse", "HEAD"], root);
|
|
3112
|
+
const planned = await call2(prefix + "/release-flow");
|
|
3113
|
+
const entry = planned.stages?.[0];
|
|
3114
|
+
if (!entry) throw new Error("The application has no environment to deploy to. Run backify environments.");
|
|
3115
|
+
const kinds = planned.stages.map((stage) => stage.kind);
|
|
3116
|
+
const blocked = entryBlockedText(planned);
|
|
3117
|
+
if (blocked) throw new CommandError(blocked + " Nothing was pushed.", "preview_required", { flow: kinds, entryBlockedBy: planned.entryBlockedBy });
|
|
2574
3118
|
if (options.dryRun) {
|
|
2575
|
-
const
|
|
2576
|
-
const
|
|
2577
|
-
return {
|
|
3119
|
+
const current = entry.deployment, checks = localReport(false, root), staging = planned.stages.at(-2);
|
|
3120
|
+
const production = entry.kind === "production" ? "this release deploys straight to production, the application's only environment" : !options.productionDeploy || options.previewOnly ? `not requested; the healthy ${entry.kind} release is the result` : planned.policy.requirePreviewTesting ? `requested; the release must be marked tested in ${staging.kind} before promotion to production` : planned.policy.requireProductionApproval ? "requested; promotion waits for production approval" : "requested; the healthy release for this commit is promoted " + kinds.join(" -> ");
|
|
3121
|
+
return {
|
|
3122
|
+
status: "dry-run",
|
|
3123
|
+
repository: status.repository,
|
|
3124
|
+
branch: status.branch,
|
|
3125
|
+
commit,
|
|
3126
|
+
push: { destination: "https://github.com/" + status.repository + ".git", ref: "refs/heads/" + status.branch, commit },
|
|
3127
|
+
checks: checks.checks.map((check) => check.name),
|
|
3128
|
+
flow: kinds,
|
|
3129
|
+
release: matchesSource(current ?? void 0, commit) ? { environment: entry.kind, status: current.status, healthResult: current.healthResult, url: stageUrl(entry), reused: current.status === "succeeded" } : { environment: entry.kind, status: "will-build", previous: current ? { commit: current.commitSha, status: current.status } : null },
|
|
3130
|
+
promotions: entry.kind === "production" || !options.productionDeploy || options.previewOnly ? [] : planned.stages.slice(1).map((stage) => stage.kind),
|
|
3131
|
+
production
|
|
3132
|
+
};
|
|
2578
3133
|
}
|
|
2579
3134
|
const report = localReport(true, root);
|
|
2580
3135
|
await call2(prefix + "/developer/report", { method: "POST", body: JSON.stringify(report) });
|
|
@@ -2592,41 +3147,73 @@ async function ship(call2, appId, options = {}) {
|
|
|
2592
3147
|
const environment = gitEnvironment(status.repository, credential.token);
|
|
2593
3148
|
const destination = "https://github.com/" + status.repository + ".git";
|
|
2594
3149
|
const alreadyPushed = pushSource(appId, commit, status.branch, destination, root, environment);
|
|
2595
|
-
const
|
|
2596
|
-
if (alreadyPushed && (!
|
|
2597
|
-
const
|
|
2598
|
-
|
|
2599
|
-
|
|
3150
|
+
const currentRelease = previousDeployments.find((release2) => release2.kind === entry.kind && matchesSource(release2, commit));
|
|
3151
|
+
if (alreadyPushed && (!currentRelease || currentRelease.status === "failed") && !(matchesSource(entry.deployment ?? void 0, commit) && entry.deployment?.status === "succeeded")) await call2(prefix + "/deployments/preview", { method: "POST", body: JSON.stringify({ sourceRevision: "latest" }) });
|
|
3152
|
+
const flow = await waitForRelease(call2, prefix, commit, entry.kind, { timeoutMs: options.timeoutMs, previousDeploymentIds: previousDeployments.filter((deployment) => deployment.status === "failed").map((deployment) => deployment.id), previousBuildRunId: previousBuild.runId ?? null });
|
|
3153
|
+
const deployed = flow.stages.find((stage) => stage.kind === entry.kind).deployment;
|
|
3154
|
+
if (deployed.commitSha !== commit) {
|
|
3155
|
+
if (git(["status", "--porcelain"], root) || git(["rev-parse", "HEAD"], root) !== commit) throw new Error("Local work changed while the release built. Review it before synchronizing the build commit.");
|
|
2600
3156
|
const refreshed = await call2(prefix + "/developer/git-credential", { method: "POST" });
|
|
2601
3157
|
if (refreshed.repository.toLowerCase() !== status.repository.toLowerCase()) throw new Error("Repository changed while building.");
|
|
2602
3158
|
git(["fetch", "--", destination, "refs/heads/" + status.branch], root, gitEnvironment(status.repository, refreshed.token));
|
|
2603
|
-
git(["merge", "--ff-only",
|
|
2604
|
-
}
|
|
2605
|
-
return
|
|
2606
|
-
}
|
|
2607
|
-
async function
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
if (!options.productionDeploy || options.previewOnly) return { status:
|
|
2611
|
-
if (overview.policy.requirePreviewTesting && !preview.testedAt) return { status: "testing-required", url: preview.url };
|
|
2612
|
-
if (overview.live?.previewDeploymentId === preview.id && overview.live.status === "succeeded") return { status: "live", url: overview.live.url };
|
|
2613
|
-
const promotion = await call2(prefix + "/deployments/promote", { method: "POST", headers: { "Idempotency-Key": "cli-ship-" + preview.id }, body: JSON.stringify({ previewDeploymentId: preview.id, tested: false }) });
|
|
2614
|
-
if (promotion.status === "awaiting-approval" || promotion.approvalId) return { status: "awaiting-approval", url: preview.url };
|
|
2615
|
-
if (!promotion.operationId) throw new Error("Publication returned no operation to verify. Run backify status.");
|
|
3159
|
+
git(["merge", "--ff-only", deployed.commitSha], root);
|
|
3160
|
+
}
|
|
3161
|
+
return publishRelease(call2, prefix, flow, entry.kind, options);
|
|
3162
|
+
}
|
|
3163
|
+
async function publishRelease(call2, prefix, flow, environment, options = {}) {
|
|
3164
|
+
let stage = flow.stages.find((item) => item.kind === environment);
|
|
3165
|
+
if (!stage || !healthy(stage.deployment)) throw new Error("Only a verified healthy release can be published.");
|
|
3166
|
+
if (stage.kind === "production" || !options.productionDeploy || options.previewOnly) return { status: readyStatus(stage.kind), environment: stage.kind, url: stageUrl(stage) };
|
|
2616
3167
|
const deadline = Date.now() + (options.timeoutMs ?? 20 * 6e4);
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
3168
|
+
const pause = () => new Promise((resolve10) => setTimeout(resolve10, options.intervalMs ?? 4e3));
|
|
3169
|
+
const read = async () => (await call2(prefix + "/release-flow")).stages;
|
|
3170
|
+
let stages = flow.stages;
|
|
3171
|
+
while (stage.kind !== "production") {
|
|
3172
|
+
const source = stage, promotion = source.promotion, release2 = source.deployment, at = { environment: source.kind, url: stageUrl(source) };
|
|
3173
|
+
if (!promotion) throw new Error(`The release flow has no promotion from ${source.kind}. Run backify release-flow.`);
|
|
3174
|
+
const target = promotion.target;
|
|
3175
|
+
const reached = () => {
|
|
3176
|
+
const next = stages.find((item) => item.kind === target);
|
|
3177
|
+
if (!next || next.deployment?.previewDeploymentId !== release2.id || !healthy(next.deployment)) throw new Error(`${target === "production" ? "Production" : "The " + target + " environment"} did not activate this healthy release. Run backify status.`);
|
|
3178
|
+
return next;
|
|
3179
|
+
};
|
|
3180
|
+
if (promotion.state === "done") {
|
|
3181
|
+
stage = reached();
|
|
3182
|
+
continue;
|
|
3183
|
+
}
|
|
3184
|
+
if (target === "production" && promotion.requiresTesting) return { status: "testing-required", ...at };
|
|
3185
|
+
if (promotion.state === "awaiting-approval") return { status: "awaiting-approval", ...at };
|
|
3186
|
+
if (promotion.state === "awaiting-configuration") return { status: "awaiting-configuration", ...at, target };
|
|
3187
|
+
if (promotion.state === "blocked" || promotion.state === "empty") return { status: "promotion-blocked", ...at, target, blockedBy: promotion.blockedBy };
|
|
3188
|
+
if (promotion.state === "in-progress") {
|
|
3189
|
+
let current = source;
|
|
3190
|
+
while (current?.promotion?.state === "in-progress") {
|
|
3191
|
+
if (Date.now() >= deadline) throw new Error("Promotion is still pending. Run backify status; deployment success has not been verified.");
|
|
3192
|
+
await pause();
|
|
3193
|
+
stages = await read();
|
|
3194
|
+
current = stages.find((item) => item.kind === source.kind);
|
|
3195
|
+
}
|
|
3196
|
+
if (!current || current.promotion?.state === "ready") throw new Error(`Promotion to ${target} did not complete. Run backify release-flow.`);
|
|
3197
|
+
stage = current;
|
|
3198
|
+
continue;
|
|
3199
|
+
}
|
|
3200
|
+
const requested = await call2(prefix + "/deployments/promote", { method: "POST", headers: { "Idempotency-Key": "cli-ship-" + release2.id }, body: JSON.stringify({ previewDeploymentId: release2.id, tested: false, target }) });
|
|
3201
|
+
if (requested.status === "awaiting-approval" || requested.approvalId) return { status: "awaiting-approval", ...at };
|
|
3202
|
+
if (requested.status === "awaiting-configuration") return { status: "awaiting-configuration", ...at, target };
|
|
3203
|
+
if (!requested.operationId) throw new Error("Publication returned no operation to verify. Run backify status.");
|
|
3204
|
+
for (; ; ) {
|
|
3205
|
+
const operation = await call2("/operations/" + requested.operationId);
|
|
3206
|
+
if (operation.status === "failed" || operation.status === "cancelled") throw new Error(operation.errorMessage ?? `${target === "production" ? "Production deployment" : "Promotion to " + target} did not complete.`);
|
|
3207
|
+
if (operation.status === "succeeded") break;
|
|
3208
|
+
if (Date.now() >= deadline) throw new Error("Publication is still pending. Run backify status; deployment success has not been verified.");
|
|
3209
|
+
await pause();
|
|
3210
|
+
}
|
|
3211
|
+
stages = await read();
|
|
3212
|
+
stage = reached();
|
|
3213
|
+
}
|
|
3214
|
+
return { status: "live", environment: "production", url: stageUrl(stage) };
|
|
2628
3215
|
}
|
|
2629
|
-
var CliAuthenticationRequired;
|
|
3216
|
+
var CliAuthenticationRequired, healthy, stageUrl, readyStatus;
|
|
2630
3217
|
var init_development = __esm({
|
|
2631
3218
|
"src/development.ts"() {
|
|
2632
3219
|
"use strict";
|
|
@@ -2634,12 +3221,16 @@ var init_development = __esm({
|
|
|
2634
3221
|
init_setup();
|
|
2635
3222
|
init_cli_session();
|
|
2636
3223
|
init_container_build();
|
|
3224
|
+
init_release_flow();
|
|
2637
3225
|
CliAuthenticationRequired = class extends Error {
|
|
2638
3226
|
code = "authentication_required";
|
|
2639
3227
|
constructor() {
|
|
2640
3228
|
super("Backify CLI authentication expired or was revoked. Ask the user to sign in, then run backify connect --reauth. The browser lets them choose 7, 14, 30, or 90 days.");
|
|
2641
3229
|
}
|
|
2642
3230
|
};
|
|
3231
|
+
healthy = (release2) => release2?.status === "succeeded" && release2.healthResult === "healthy";
|
|
3232
|
+
stageUrl = (stage) => stage.deployment?.url || stage.url;
|
|
3233
|
+
readyStatus = (kind2) => kind2 === "production" ? "live" : kind2 + "-ready";
|
|
2643
3234
|
}
|
|
2644
3235
|
});
|
|
2645
3236
|
|
|
@@ -2677,7 +3268,7 @@ async function refreshMcpGrant(grant, transport) {
|
|
|
2677
3268
|
}
|
|
2678
3269
|
function storedGrant(config2, endpoint2) {
|
|
2679
3270
|
const grant = config2.mcp;
|
|
2680
|
-
return grant && grant.endpoint === resourceOf(endpoint2) && /^bfmcpr_[A-Za-z0-9_-]{43}$/.test(grant.refreshToken) && Array.isArray(grant.organizationIds) && grant.organizationIds.length > 0 && grant.organizationIds.every((id) =>
|
|
3271
|
+
return grant && grant.endpoint === resourceOf(endpoint2) && /^bfmcpr_[A-Za-z0-9_-]{43}$/.test(grant.refreshToken) && Array.isArray(grant.organizationIds) && grant.organizationIds.length > 0 && grant.organizationIds.every((id) => uuid7.test(id)) ? grant : void 0;
|
|
2681
3272
|
}
|
|
2682
3273
|
async function renewStoredGrant(file, endpoint2, transport) {
|
|
2683
3274
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -2693,7 +3284,7 @@ async function renewStoredGrant(file, endpoint2, transport) {
|
|
|
2693
3284
|
}
|
|
2694
3285
|
}
|
|
2695
3286
|
}
|
|
2696
|
-
var cliClientId, McpGrantRejected, scopes, resourceOf,
|
|
3287
|
+
var cliClientId, McpGrantRejected, scopes, resourceOf, uuid7;
|
|
2697
3288
|
var init_mcp_grant = __esm({
|
|
2698
3289
|
"src/mcp-grant.ts"() {
|
|
2699
3290
|
"use strict";
|
|
@@ -2702,7 +3293,7 @@ var init_mcp_grant = __esm({
|
|
|
2702
3293
|
};
|
|
2703
3294
|
scopes = /* @__PURE__ */ new Set(["organization:read", "organization:write", "deployment:manage", "billing:manage", "access:manage"]);
|
|
2704
3295
|
resourceOf = (endpoint2) => new URL(endpoint2).href.replace(/\/$/, "");
|
|
2705
|
-
|
|
3296
|
+
uuid7 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2706
3297
|
}
|
|
2707
3298
|
});
|
|
2708
3299
|
|
|
@@ -2762,8 +3353,8 @@ function installedVersion(root, name2) {
|
|
|
2762
3353
|
}
|
|
2763
3354
|
function mergeIgnoreFile(template, destination) {
|
|
2764
3355
|
const current = readFileSync9(destination, "utf8");
|
|
2765
|
-
const present2 = new Set(current.split(/\r?\n/).map((
|
|
2766
|
-
const missing = readFileSync9(template, "utf8").split(/\r?\n/).map((
|
|
3356
|
+
const present2 = new Set(current.split(/\r?\n/).map((line2) => line2.trim()));
|
|
3357
|
+
const missing = readFileSync9(template, "utf8").split(/\r?\n/).map((line2) => line2.trim()).filter((line2) => line2 && !present2.has(line2));
|
|
2767
3358
|
if (!missing.length) return false;
|
|
2768
3359
|
writeFileSync7(destination, (current && !current.endsWith("\n") ? current + "\n" : current) + missing.join("\n") + "\n");
|
|
2769
3360
|
return true;
|
|
@@ -2792,15 +3383,15 @@ function createApp(options) {
|
|
|
2792
3383
|
const written = [];
|
|
2793
3384
|
mkdirSync2(target, { recursive: true });
|
|
2794
3385
|
for (const file of walk(staging)) {
|
|
2795
|
-
const
|
|
2796
|
-
const destination = join9(target,
|
|
2797
|
-
if (existsSync8(destination) &&
|
|
2798
|
-
if ((
|
|
3386
|
+
const relative5 = file.slice(staging.length + 1);
|
|
3387
|
+
const destination = join9(target, relative5);
|
|
3388
|
+
if (existsSync8(destination) && relative5 !== "package.json") {
|
|
3389
|
+
if ((relative5 === ".gitignore" || relative5 === ".dockerignore") && mergeIgnoreFile(file, destination)) written.push(relative5);
|
|
2799
3390
|
continue;
|
|
2800
3391
|
}
|
|
2801
3392
|
mkdirSync2(dirname4(destination), { recursive: true });
|
|
2802
3393
|
cpSync2(file, destination);
|
|
2803
|
-
written.push(
|
|
3394
|
+
written.push(relative5);
|
|
2804
3395
|
}
|
|
2805
3396
|
if (connected.appId && existsSync8(join9(target, APP_CONFIG_FILE))) {
|
|
2806
3397
|
rmSync2(join9(target, "backify.json"), { force: true });
|
|
@@ -4041,17 +4632,17 @@ var init_parse = __esm({
|
|
|
4041
4632
|
return result.issues.length === 0;
|
|
4042
4633
|
};
|
|
4043
4634
|
_encode = (_Err) => {
|
|
4044
|
-
const
|
|
4635
|
+
const parse4 = _parse(_Err);
|
|
4045
4636
|
const fn = (schema, value, _ctx, _params) => {
|
|
4046
4637
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
4047
|
-
return
|
|
4638
|
+
return parse4(schema, value, ctx, finalizeParams(fn, _params));
|
|
4048
4639
|
};
|
|
4049
4640
|
return fn;
|
|
4050
4641
|
};
|
|
4051
4642
|
_decode = (_Err) => {
|
|
4052
|
-
const
|
|
4643
|
+
const parse4 = _parse(_Err);
|
|
4053
4644
|
const fn = (schema, value, _ctx, _params) => {
|
|
4054
|
-
return
|
|
4645
|
+
return parse4(schema, value, _ctx, finalizeParams(fn, _params));
|
|
4055
4646
|
};
|
|
4056
4647
|
return fn;
|
|
4057
4648
|
};
|
|
@@ -4113,7 +4704,7 @@ function datetime(args2) {
|
|
|
4113
4704
|
const timeRegex = args2.local ? `${qualified}|${timeSource({ precision: args2.precision })}` : qualified;
|
|
4114
4705
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
4115
4706
|
}
|
|
4116
|
-
var cuid, cuid2, ulid, xid, ksuid, nanoid,
|
|
4707
|
+
var cuid, cuid2, ulid, xid, ksuid, nanoid, duration2, guid3, uuid8, email, _emoji, ipv4, ipv6, cidrv4, cidrv6, base642, base64url, httpProtocol, e164, dateSource, date, anyString, bigint, integer, number, boolean, _null, lowercase, uppercase;
|
|
4117
4708
|
var init_regexes = __esm({
|
|
4118
4709
|
"../../node_modules/zod/v4/core/regexes.js"() {
|
|
4119
4710
|
cuid = /^[cC][0-9a-z]{6,}$/;
|
|
@@ -4122,9 +4713,9 @@ var init_regexes = __esm({
|
|
|
4122
4713
|
xid = /^[0-9a-vA-V]{20}$/;
|
|
4123
4714
|
ksuid = /^[A-Za-z0-9]{27}$/;
|
|
4124
4715
|
nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
4125
|
-
|
|
4716
|
+
duration2 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
4126
4717
|
guid3 = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
4127
|
-
|
|
4718
|
+
uuid8 = (version2) => {
|
|
4128
4719
|
if (!version2)
|
|
4129
4720
|
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
4130
4721
|
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version2}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
@@ -4510,8 +5101,8 @@ var init_doc = __esm({
|
|
|
4510
5101
|
const lines = content.split("\n").filter((x) => x);
|
|
4511
5102
|
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
4512
5103
|
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
4513
|
-
for (const
|
|
4514
|
-
this.content.push(
|
|
5104
|
+
for (const line2 of dedented) {
|
|
5105
|
+
this.content.push(line2);
|
|
4515
5106
|
}
|
|
4516
5107
|
}
|
|
4517
5108
|
compile() {
|
|
@@ -4666,7 +5257,7 @@ function capSize(inst, size) {
|
|
|
4666
5257
|
if (!caps.length)
|
|
4667
5258
|
return;
|
|
4668
5259
|
const cap = Math.min(...caps.map((c) => c[0]));
|
|
4669
|
-
const
|
|
5260
|
+
const parse4 = inst._zod.parse;
|
|
4670
5261
|
inst._zod.parse = (payload, ctx) => {
|
|
4671
5262
|
const n = size(payload.value);
|
|
4672
5263
|
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
@@ -4680,7 +5271,7 @@ function capSize(inst, size) {
|
|
|
4680
5271
|
}
|
|
4681
5272
|
}
|
|
4682
5273
|
}
|
|
4683
|
-
return
|
|
5274
|
+
return parse4(payload, ctx);
|
|
4684
5275
|
};
|
|
4685
5276
|
}
|
|
4686
5277
|
function handleArrayResult(result, final, index) {
|
|
@@ -5156,9 +5747,9 @@ var init_schemas = __esm({
|
|
|
5156
5747
|
const v = versionMap[def.version];
|
|
5157
5748
|
if (v === void 0)
|
|
5158
5749
|
throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
5159
|
-
def.pattern ?? (def.pattern =
|
|
5750
|
+
def.pattern ?? (def.pattern = uuid8(v));
|
|
5160
5751
|
} else
|
|
5161
|
-
def.pattern ?? (def.pattern =
|
|
5752
|
+
def.pattern ?? (def.pattern = uuid8());
|
|
5162
5753
|
$ZodStringFormat.init(inst, def);
|
|
5163
5754
|
});
|
|
5164
5755
|
$ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
@@ -5277,7 +5868,7 @@ var init_schemas = __esm({
|
|
|
5277
5868
|
$ZodStringFormat.init(inst, def);
|
|
5278
5869
|
});
|
|
5279
5870
|
$ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
|
|
5280
|
-
def.pattern ?? (def.pattern =
|
|
5871
|
+
def.pattern ?? (def.pattern = duration2);
|
|
5281
5872
|
$ZodStringFormat.init(inst, def);
|
|
5282
5873
|
});
|
|
5283
5874
|
$ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
@@ -6272,7 +6863,7 @@ function isRef(value) {
|
|
|
6272
6863
|
function cloneIssues(issues) {
|
|
6273
6864
|
return issues.map((iss) => iss.path ? { ...iss, path: iss.path.slice() } : { ...iss });
|
|
6274
6865
|
}
|
|
6275
|
-
function isRecursive(inst, stack,
|
|
6866
|
+
function isRecursive(inst, stack, resolve10) {
|
|
6276
6867
|
const cached2 = recursive.get(inst);
|
|
6277
6868
|
if (cached2 !== void 0)
|
|
6278
6869
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6282,7 +6873,7 @@ function isRecursive(inst, stack, resolve9) {
|
|
|
6282
6873
|
let result = NONE;
|
|
6283
6874
|
const check = (child) => {
|
|
6284
6875
|
if (result !== PROVEN && child?._zod) {
|
|
6285
|
-
const answer = isRecursive(child, stack,
|
|
6876
|
+
const answer = isRecursive(child, stack, resolve10);
|
|
6286
6877
|
if (answer > result)
|
|
6287
6878
|
result = answer;
|
|
6288
6879
|
}
|
|
@@ -6293,7 +6884,7 @@ function isRecursive(inst, stack, resolve9) {
|
|
|
6293
6884
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6294
6885
|
if (spread && !desc.enumerable)
|
|
6295
6886
|
continue;
|
|
6296
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6887
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve10) : NONE;
|
|
6297
6888
|
if (child > answer)
|
|
6298
6889
|
answer = child;
|
|
6299
6890
|
}
|
|
@@ -6357,7 +6948,7 @@ function isRecursive(inst, stack, resolve9) {
|
|
|
6357
6948
|
break;
|
|
6358
6949
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6359
6950
|
case "lazy": {
|
|
6360
|
-
const inner = def._cachedInner ?? (
|
|
6951
|
+
const inner = def._cachedInner ?? (resolve10 ? inst._zod.innerType : void 0);
|
|
6361
6952
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6362
6953
|
break;
|
|
6363
6954
|
}
|
|
@@ -7349,13 +7940,13 @@ function initializeContext(params) {
|
|
|
7349
7940
|
external: params?.external ?? void 0
|
|
7350
7941
|
};
|
|
7351
7942
|
}
|
|
7352
|
-
function handleUnrepresentable(schema, ctx,
|
|
7943
|
+
function handleUnrepresentable(schema, ctx, json3, params, message) {
|
|
7353
7944
|
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message }) : ctx.unrepresentable;
|
|
7354
7945
|
if (result === "any")
|
|
7355
7946
|
return false;
|
|
7356
7947
|
if (result === void 0 || result === "throw")
|
|
7357
7948
|
throw new Error(message);
|
|
7358
|
-
Object.assign(
|
|
7949
|
+
Object.assign(json3, result);
|
|
7359
7950
|
return true;
|
|
7360
7951
|
}
|
|
7361
7952
|
function processSchema(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
@@ -7589,12 +8180,12 @@ function foldObjects(members2) {
|
|
|
7589
8180
|
}
|
|
7590
8181
|
return folded;
|
|
7591
8182
|
}
|
|
7592
|
-
function foldIntersection(
|
|
7593
|
-
const allOf =
|
|
8183
|
+
function foldIntersection(json3) {
|
|
8184
|
+
const allOf = json3.allOf;
|
|
7594
8185
|
if (!Array.isArray(allOf) || allOf.length < 2)
|
|
7595
8186
|
return;
|
|
7596
8187
|
for (const key of FOLDABLE_KEYS)
|
|
7597
|
-
if (key in
|
|
8188
|
+
if (key in json3)
|
|
7598
8189
|
return;
|
|
7599
8190
|
const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
|
|
7600
8191
|
let folded = null;
|
|
@@ -7613,8 +8204,8 @@ function foldIntersection(json2) {
|
|
|
7613
8204
|
}
|
|
7614
8205
|
if (!folded)
|
|
7615
8206
|
return;
|
|
7616
|
-
delete
|
|
7617
|
-
assignProps(
|
|
8207
|
+
delete json3.allOf;
|
|
8208
|
+
assignProps(json3, folded);
|
|
7618
8209
|
}
|
|
7619
8210
|
function finalize(ctx, schema) {
|
|
7620
8211
|
const root = ctx.seen.get(schema);
|
|
@@ -7696,20 +8287,20 @@ function finalize(ctx, schema) {
|
|
|
7696
8287
|
if (ctx.intersections.length) {
|
|
7697
8288
|
const carriers = /* @__PURE__ */ new Map();
|
|
7698
8289
|
for (const seen of ctx.seen.values()) {
|
|
7699
|
-
for (const
|
|
7700
|
-
const allOf =
|
|
8290
|
+
for (const json3 of [seen.schema, seen.def]) {
|
|
8291
|
+
const allOf = json3?.allOf;
|
|
7701
8292
|
if (!Array.isArray(allOf))
|
|
7702
8293
|
continue;
|
|
7703
8294
|
const existing = carriers.get(allOf);
|
|
7704
8295
|
if (existing)
|
|
7705
|
-
existing.push(
|
|
8296
|
+
existing.push(json3);
|
|
7706
8297
|
else
|
|
7707
|
-
carriers.set(allOf, [
|
|
8298
|
+
carriers.set(allOf, [json3]);
|
|
7708
8299
|
}
|
|
7709
8300
|
}
|
|
7710
8301
|
for (const allOf of ctx.intersections) {
|
|
7711
|
-
for (const
|
|
7712
|
-
foldIntersection(
|
|
8302
|
+
for (const json3 of carriers.get(allOf) ?? [])
|
|
8303
|
+
foldIntersection(json3);
|
|
7713
8304
|
}
|
|
7714
8305
|
}
|
|
7715
8306
|
}
|
|
@@ -7889,31 +8480,31 @@ function inputOptin(schema) {
|
|
|
7889
8480
|
}
|
|
7890
8481
|
return schema._zod.optin;
|
|
7891
8482
|
}
|
|
7892
|
-
function stringifyKeyNames(bySchema,
|
|
7893
|
-
if (
|
|
7894
|
-
if (visited.has(
|
|
7895
|
-
return
|
|
7896
|
-
visited.add(
|
|
7897
|
-
const def = bySchema.get(
|
|
8483
|
+
function stringifyKeyNames(bySchema, json3, visited) {
|
|
8484
|
+
if (json3.$ref) {
|
|
8485
|
+
if (visited.has(json3))
|
|
8486
|
+
return json3;
|
|
8487
|
+
visited.add(json3);
|
|
8488
|
+
const def = bySchema.get(json3)?.def;
|
|
7898
8489
|
if (!def)
|
|
7899
|
-
return
|
|
8490
|
+
return json3;
|
|
7900
8491
|
const inlined = stringifyKeyNames(bySchema, def, visited);
|
|
7901
|
-
return inlined === def ?
|
|
8492
|
+
return inlined === def ? json3 : inlined;
|
|
7902
8493
|
}
|
|
7903
8494
|
for (const keyword of ["anyOf", "oneOf"]) {
|
|
7904
|
-
const branches =
|
|
8495
|
+
const branches = json3[keyword];
|
|
7905
8496
|
if (!Array.isArray(branches))
|
|
7906
8497
|
continue;
|
|
7907
8498
|
const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
|
|
7908
8499
|
if (mapped.some((branch, i) => branch !== branches[i]))
|
|
7909
|
-
|
|
8500
|
+
json3 = { ...json3, [keyword]: mapped };
|
|
7910
8501
|
}
|
|
7911
|
-
const types2 = Array.isArray(
|
|
8502
|
+
const types2 = Array.isArray(json3.type) ? json3.type : [json3.type];
|
|
7912
8503
|
const numericType = !types2.includes("string") && types2.some((t) => t === "number" || t === "integer");
|
|
7913
|
-
const values =
|
|
8504
|
+
const values = json3.enum ?? (json3.const !== void 0 ? [json3.const] : void 0);
|
|
7914
8505
|
if (!numericType && !values?.some((v) => typeof v === "number"))
|
|
7915
|
-
return
|
|
7916
|
-
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } =
|
|
8506
|
+
return json3;
|
|
8507
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json3;
|
|
7917
8508
|
if (rest.enum)
|
|
7918
8509
|
rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
|
|
7919
8510
|
else if (typeof rest.const === "number")
|
|
@@ -7951,7 +8542,7 @@ function rewriteKeyNames(ctx) {
|
|
|
7951
8542
|
}
|
|
7952
8543
|
}
|
|
7953
8544
|
}
|
|
7954
|
-
function serializeDefaultValue(value, schema, ctx,
|
|
8545
|
+
function serializeDefaultValue(value, schema, ctx, json3, params) {
|
|
7955
8546
|
let unrepresentable = false;
|
|
7956
8547
|
const serialized = JSON.stringify(value, (_, val) => {
|
|
7957
8548
|
if (typeof val !== "bigint")
|
|
@@ -7961,7 +8552,7 @@ function serializeDefaultValue(value, schema, ctx, json2, params) {
|
|
|
7961
8552
|
});
|
|
7962
8553
|
if (!unrepresentable)
|
|
7963
8554
|
return JSON.parse(serialized);
|
|
7964
|
-
handleUnrepresentable(schema, ctx,
|
|
8555
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
7965
8556
|
return UNREPRESENTABLE_DEFAULT;
|
|
7966
8557
|
}
|
|
7967
8558
|
var narrowMin, narrowMax, narrowBoth, addDivisor, addPattern, intersectMime, setFormat, minContributor, maxContributor, formatContributor, contributors, formatMap, exactPatterns, exactPattern, stringProcessor, numberProcessor, booleanProcessor, bigintProcessor, nullProcessor, neverProcessor, anyProcessor, unknownProcessor, dateProcessor, enumProcessor, literalProcessor, customProcessor, transformProcessor, arrayProcessor, objectProcessor, unionProcessor, intersectionProcessor, pendingRecords, recordProcessor, nullableProcessor, nonoptionalProcessor, UNREPRESENTABLE_DEFAULT, defaultProcessor, prefaultProcessor, catchProcessor, pipeProcessor, readonlyProcessor, optionalProcessor;
|
|
@@ -8045,29 +8636,29 @@ var init_json_schema_processors = __esm({
|
|
|
8045
8636
|
]);
|
|
8046
8637
|
exactPattern = (p) => exactPatterns.get(p) ?? p;
|
|
8047
8638
|
stringProcessor = (schema, ctx, _json, _params) => {
|
|
8048
|
-
const
|
|
8049
|
-
|
|
8639
|
+
const json3 = _json;
|
|
8640
|
+
json3.type = "string";
|
|
8050
8641
|
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
|
|
8051
8642
|
if (typeof minimum === "number")
|
|
8052
|
-
|
|
8643
|
+
json3.minLength = minimum;
|
|
8053
8644
|
if (typeof maximum === "number")
|
|
8054
|
-
|
|
8645
|
+
json3.maxLength = maximum;
|
|
8055
8646
|
if (format) {
|
|
8056
|
-
|
|
8057
|
-
if (
|
|
8058
|
-
delete
|
|
8647
|
+
json3.format = formatMap[format] ?? format;
|
|
8648
|
+
if (json3.format === "")
|
|
8649
|
+
delete json3.format;
|
|
8059
8650
|
if (format === "time" || laxFormat) {
|
|
8060
|
-
delete
|
|
8651
|
+
delete json3.format;
|
|
8061
8652
|
}
|
|
8062
8653
|
}
|
|
8063
8654
|
if (contentEncoding)
|
|
8064
|
-
|
|
8655
|
+
json3.contentEncoding = contentEncoding;
|
|
8065
8656
|
if (patterns && patterns.size > 0) {
|
|
8066
8657
|
const patternList = [...patterns].map(exactPattern);
|
|
8067
8658
|
if (patternList.length === 1)
|
|
8068
|
-
|
|
8659
|
+
json3.pattern = patternList[0].source;
|
|
8069
8660
|
else if (patternList.length > 1) {
|
|
8070
|
-
|
|
8661
|
+
json3.allOf = [
|
|
8071
8662
|
...patternList.map((regex) => ({
|
|
8072
8663
|
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
8073
8664
|
pattern: regex.source
|
|
@@ -8077,31 +8668,31 @@ var init_json_schema_processors = __esm({
|
|
|
8077
8668
|
}
|
|
8078
8669
|
};
|
|
8079
8670
|
numberProcessor = (schema, ctx, _json, params) => {
|
|
8080
|
-
const
|
|
8671
|
+
const json3 = _json;
|
|
8081
8672
|
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } = aggregateChecks(schema);
|
|
8082
|
-
|
|
8673
|
+
json3.type = isInt ? "integer" : "number";
|
|
8083
8674
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
8084
8675
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
8085
8676
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
8086
8677
|
if (exMin) {
|
|
8087
8678
|
if (legacy) {
|
|
8088
|
-
|
|
8089
|
-
|
|
8679
|
+
json3.minimum = exclusiveMinimum;
|
|
8680
|
+
json3.exclusiveMinimum = true;
|
|
8090
8681
|
} else {
|
|
8091
|
-
|
|
8682
|
+
json3.exclusiveMinimum = exclusiveMinimum;
|
|
8092
8683
|
}
|
|
8093
8684
|
} else if (typeof minimum === "number") {
|
|
8094
|
-
|
|
8685
|
+
json3.minimum = minimum;
|
|
8095
8686
|
}
|
|
8096
8687
|
if (exMax) {
|
|
8097
8688
|
if (legacy) {
|
|
8098
|
-
|
|
8099
|
-
|
|
8689
|
+
json3.maximum = exclusiveMaximum;
|
|
8690
|
+
json3.exclusiveMaximum = true;
|
|
8100
8691
|
} else {
|
|
8101
|
-
|
|
8692
|
+
json3.exclusiveMaximum = exclusiveMaximum;
|
|
8102
8693
|
}
|
|
8103
8694
|
} else if (typeof maximum === "number") {
|
|
8104
|
-
|
|
8695
|
+
json3.maximum = maximum;
|
|
8105
8696
|
}
|
|
8106
8697
|
if (multipleOf) {
|
|
8107
8698
|
const divisors = /* @__PURE__ */ new Set();
|
|
@@ -8109,66 +8700,66 @@ var init_json_schema_processors = __esm({
|
|
|
8109
8700
|
if (Number.isFinite(divisor) && divisor !== 0)
|
|
8110
8701
|
divisors.add(Math.abs(divisor));
|
|
8111
8702
|
else
|
|
8112
|
-
handleUnrepresentable(schema, ctx,
|
|
8703
|
+
handleUnrepresentable(schema, ctx, json3, params, `A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`);
|
|
8113
8704
|
}
|
|
8114
8705
|
const [first, ...rest] = divisors;
|
|
8115
8706
|
if (first !== void 0)
|
|
8116
|
-
|
|
8707
|
+
json3.multipleOf = first;
|
|
8117
8708
|
if (rest.length)
|
|
8118
|
-
|
|
8709
|
+
json3.allOf = [...json3.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
|
|
8119
8710
|
}
|
|
8120
8711
|
};
|
|
8121
|
-
booleanProcessor = (_schema, _ctx,
|
|
8122
|
-
|
|
8712
|
+
booleanProcessor = (_schema, _ctx, json3, _params) => {
|
|
8713
|
+
json3.type = "boolean";
|
|
8123
8714
|
};
|
|
8124
|
-
bigintProcessor = (schema, ctx,
|
|
8125
|
-
handleUnrepresentable(schema, ctx,
|
|
8715
|
+
bigintProcessor = (schema, ctx, json3, params) => {
|
|
8716
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt cannot be represented in JSON Schema");
|
|
8126
8717
|
};
|
|
8127
|
-
nullProcessor = (_schema, ctx,
|
|
8718
|
+
nullProcessor = (_schema, ctx, json3, _params) => {
|
|
8128
8719
|
if (ctx.target === "openapi-3.0") {
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8720
|
+
json3.type = "string";
|
|
8721
|
+
json3.nullable = true;
|
|
8722
|
+
json3.enum = [null];
|
|
8132
8723
|
} else {
|
|
8133
|
-
|
|
8724
|
+
json3.type = "null";
|
|
8134
8725
|
}
|
|
8135
8726
|
};
|
|
8136
|
-
neverProcessor = (_schema, _ctx,
|
|
8137
|
-
|
|
8727
|
+
neverProcessor = (_schema, _ctx, json3, _params) => {
|
|
8728
|
+
json3.not = {};
|
|
8138
8729
|
};
|
|
8139
8730
|
anyProcessor = (_schema, _ctx, _json, _params) => {
|
|
8140
8731
|
};
|
|
8141
8732
|
unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
8142
8733
|
};
|
|
8143
|
-
dateProcessor = (schema, ctx,
|
|
8144
|
-
handleUnrepresentable(schema, ctx,
|
|
8734
|
+
dateProcessor = (schema, ctx, json3, params) => {
|
|
8735
|
+
handleUnrepresentable(schema, ctx, json3, params, "Date cannot be represented in JSON Schema");
|
|
8145
8736
|
};
|
|
8146
|
-
enumProcessor = (schema, _ctx,
|
|
8737
|
+
enumProcessor = (schema, _ctx, json3, _params) => {
|
|
8147
8738
|
const def = schema._zod.def;
|
|
8148
8739
|
const values = getEnumValues(def.entries);
|
|
8149
8740
|
if (values.length === 0) {
|
|
8150
|
-
|
|
8741
|
+
json3.not = {};
|
|
8151
8742
|
return;
|
|
8152
8743
|
}
|
|
8153
8744
|
if (values.every((v) => typeof v === "number"))
|
|
8154
|
-
|
|
8745
|
+
json3.type = "number";
|
|
8155
8746
|
if (values.every((v) => typeof v === "string"))
|
|
8156
|
-
|
|
8157
|
-
|
|
8747
|
+
json3.type = "string";
|
|
8748
|
+
json3.enum = values;
|
|
8158
8749
|
};
|
|
8159
|
-
literalProcessor = (schema, ctx,
|
|
8750
|
+
literalProcessor = (schema, ctx, json3, params) => {
|
|
8160
8751
|
const def = schema._zod.def;
|
|
8161
8752
|
if (def.values.length === 0) {
|
|
8162
|
-
|
|
8753
|
+
json3.not = {};
|
|
8163
8754
|
return;
|
|
8164
8755
|
}
|
|
8165
8756
|
const vals = [];
|
|
8166
8757
|
for (const val of def.values) {
|
|
8167
8758
|
if (val === void 0) {
|
|
8168
|
-
if (handleUnrepresentable(schema, ctx,
|
|
8759
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "Literal `undefined` cannot be represented in JSON Schema"))
|
|
8169
8760
|
return;
|
|
8170
8761
|
} else if (typeof val === "bigint") {
|
|
8171
|
-
if (handleUnrepresentable(schema, ctx,
|
|
8762
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "BigInt literals cannot be represented in JSON Schema"))
|
|
8172
8763
|
return;
|
|
8173
8764
|
vals.push(Number(val));
|
|
8174
8765
|
} else {
|
|
@@ -8178,56 +8769,56 @@ var init_json_schema_processors = __esm({
|
|
|
8178
8769
|
if (vals.length === 0) {
|
|
8179
8770
|
} else if (vals.length === 1) {
|
|
8180
8771
|
const val = vals[0];
|
|
8181
|
-
|
|
8772
|
+
json3.type = val === null ? "null" : typeof val;
|
|
8182
8773
|
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
8183
|
-
|
|
8774
|
+
json3.enum = [val];
|
|
8184
8775
|
} else {
|
|
8185
|
-
|
|
8776
|
+
json3.const = val;
|
|
8186
8777
|
}
|
|
8187
8778
|
} else {
|
|
8188
8779
|
if (vals.every((v) => typeof v === "number"))
|
|
8189
|
-
|
|
8780
|
+
json3.type = "number";
|
|
8190
8781
|
if (vals.every((v) => typeof v === "string"))
|
|
8191
|
-
|
|
8782
|
+
json3.type = "string";
|
|
8192
8783
|
if (vals.every((v) => typeof v === "boolean"))
|
|
8193
|
-
|
|
8784
|
+
json3.type = "boolean";
|
|
8194
8785
|
if (vals.every((v) => v === null))
|
|
8195
|
-
|
|
8196
|
-
|
|
8786
|
+
json3.type = "null";
|
|
8787
|
+
json3.enum = vals;
|
|
8197
8788
|
}
|
|
8198
8789
|
};
|
|
8199
|
-
customProcessor = (schema, ctx,
|
|
8200
|
-
handleUnrepresentable(schema, ctx,
|
|
8790
|
+
customProcessor = (schema, ctx, json3, params) => {
|
|
8791
|
+
handleUnrepresentable(schema, ctx, json3, params, "Custom types cannot be represented in JSON Schema");
|
|
8201
8792
|
};
|
|
8202
|
-
transformProcessor = (schema, ctx,
|
|
8203
|
-
handleUnrepresentable(schema, ctx,
|
|
8793
|
+
transformProcessor = (schema, ctx, json3, params) => {
|
|
8794
|
+
handleUnrepresentable(schema, ctx, json3, params, "Transforms cannot be represented in JSON Schema");
|
|
8204
8795
|
};
|
|
8205
8796
|
arrayProcessor = (schema, ctx, _json, params) => {
|
|
8206
|
-
const
|
|
8797
|
+
const json3 = _json;
|
|
8207
8798
|
const def = schema._zod.def;
|
|
8208
8799
|
const { minimum, maximum } = aggregateChecks(schema);
|
|
8209
8800
|
if (typeof minimum === "number")
|
|
8210
|
-
|
|
8801
|
+
json3.minItems = minimum;
|
|
8211
8802
|
if (typeof maximum === "number")
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8803
|
+
json3.maxItems = maximum;
|
|
8804
|
+
json3.type = "array";
|
|
8805
|
+
json3.items = processSchema(def.element, ctx, {
|
|
8215
8806
|
...params,
|
|
8216
8807
|
path: [...params.path, "items"]
|
|
8217
8808
|
});
|
|
8218
8809
|
};
|
|
8219
8810
|
objectProcessor = (schema, ctx, _json, params) => {
|
|
8220
|
-
const
|
|
8811
|
+
const json3 = _json;
|
|
8221
8812
|
const def = schema._zod.def;
|
|
8222
8813
|
const shape = def.shape;
|
|
8223
8814
|
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
8224
|
-
if (symbolKeys.length && handleUnrepresentable(schema, ctx,
|
|
8815
|
+
if (symbolKeys.length && handleUnrepresentable(schema, ctx, json3, params, "Symbol keys cannot be represented in JSON Schema")) {
|
|
8225
8816
|
return;
|
|
8226
8817
|
}
|
|
8227
|
-
|
|
8228
|
-
|
|
8818
|
+
json3.type = "object";
|
|
8819
|
+
json3.properties = {};
|
|
8229
8820
|
for (const key in shape) {
|
|
8230
|
-
assignProp(
|
|
8821
|
+
assignProp(json3.properties, key, processSchema(shape[key], ctx, {
|
|
8231
8822
|
...params,
|
|
8232
8823
|
path: [...params.path, "properties", key]
|
|
8233
8824
|
}));
|
|
@@ -8240,21 +8831,21 @@ var init_json_schema_processors = __esm({
|
|
|
8240
8831
|
}
|
|
8241
8832
|
}
|
|
8242
8833
|
if (requiredKeys.length > 0) {
|
|
8243
|
-
|
|
8834
|
+
json3.required = requiredKeys;
|
|
8244
8835
|
}
|
|
8245
8836
|
if (def.catchall?._zod.def.type === "never") {
|
|
8246
|
-
|
|
8837
|
+
json3.additionalProperties = false;
|
|
8247
8838
|
} else if (!def.catchall) {
|
|
8248
8839
|
if (ctx.io === "output")
|
|
8249
|
-
|
|
8840
|
+
json3.additionalProperties = false;
|
|
8250
8841
|
} else if (def.catchall) {
|
|
8251
|
-
|
|
8842
|
+
json3.additionalProperties = processSchema(def.catchall, ctx, {
|
|
8252
8843
|
...params,
|
|
8253
8844
|
path: [...params.path, "additionalProperties"]
|
|
8254
8845
|
});
|
|
8255
8846
|
}
|
|
8256
8847
|
};
|
|
8257
|
-
unionProcessor = (schema, ctx,
|
|
8848
|
+
unionProcessor = (schema, ctx, json3, params) => {
|
|
8258
8849
|
const def = schema._zod.def;
|
|
8259
8850
|
const isExclusive = def.inclusive === false;
|
|
8260
8851
|
const options = def.options.map((x, i) => processSchema(x, ctx, {
|
|
@@ -8262,12 +8853,12 @@ var init_json_schema_processors = __esm({
|
|
|
8262
8853
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
8263
8854
|
}));
|
|
8264
8855
|
if (isExclusive) {
|
|
8265
|
-
|
|
8856
|
+
json3.oneOf = options;
|
|
8266
8857
|
} else {
|
|
8267
|
-
|
|
8858
|
+
json3.anyOf = options;
|
|
8268
8859
|
}
|
|
8269
8860
|
};
|
|
8270
|
-
intersectionProcessor = (schema, ctx,
|
|
8861
|
+
intersectionProcessor = (schema, ctx, json3, params) => {
|
|
8271
8862
|
const def = schema._zod.def;
|
|
8272
8863
|
const a = processSchema(def.left, ctx, {
|
|
8273
8864
|
...params,
|
|
@@ -8282,14 +8873,14 @@ var init_json_schema_processors = __esm({
|
|
|
8282
8873
|
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
8283
8874
|
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
8284
8875
|
];
|
|
8285
|
-
|
|
8876
|
+
json3.allOf = allOf;
|
|
8286
8877
|
ctx.intersections.push(allOf);
|
|
8287
8878
|
};
|
|
8288
8879
|
pendingRecords = /* @__PURE__ */ new WeakMap();
|
|
8289
8880
|
recordProcessor = (schema, ctx, _json, params) => {
|
|
8290
|
-
const
|
|
8881
|
+
const json3 = _json;
|
|
8291
8882
|
const def = schema._zod.def;
|
|
8292
|
-
|
|
8883
|
+
json3.type = "object";
|
|
8293
8884
|
const keyType = def.keyType;
|
|
8294
8885
|
const patterns = aggregateChecks(keyType).patterns;
|
|
8295
8886
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
@@ -8297,13 +8888,13 @@ var init_json_schema_processors = __esm({
|
|
|
8297
8888
|
...params,
|
|
8298
8889
|
path: [...params.path, "patternProperties", "*"]
|
|
8299
8890
|
});
|
|
8300
|
-
|
|
8891
|
+
json3.patternProperties = {};
|
|
8301
8892
|
for (const pattern of patterns) {
|
|
8302
|
-
assignProp(
|
|
8893
|
+
assignProp(json3.patternProperties, exactPattern(pattern).source, valueSchema);
|
|
8303
8894
|
}
|
|
8304
8895
|
} else {
|
|
8305
8896
|
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
8306
|
-
|
|
8897
|
+
json3.propertyNames = processSchema(def.keyType, ctx, {
|
|
8307
8898
|
...params,
|
|
8308
8899
|
path: [...params.path, "propertyNames"]
|
|
8309
8900
|
});
|
|
@@ -8315,7 +8906,7 @@ var init_json_schema_processors = __esm({
|
|
|
8315
8906
|
}
|
|
8316
8907
|
pending.push(schema);
|
|
8317
8908
|
}
|
|
8318
|
-
|
|
8909
|
+
json3.additionalProperties = processSchema(def.valueType, ctx, {
|
|
8319
8910
|
...params,
|
|
8320
8911
|
path: [...params.path, "additionalProperties"]
|
|
8321
8912
|
});
|
|
@@ -8325,19 +8916,19 @@ var init_json_schema_processors = __esm({
|
|
|
8325
8916
|
if (keyValues && !def.partial && !omittableOnInput) {
|
|
8326
8917
|
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
8327
8918
|
if (validKeyValues.length > 0) {
|
|
8328
|
-
|
|
8919
|
+
json3.required = validKeyValues.map(String);
|
|
8329
8920
|
}
|
|
8330
8921
|
}
|
|
8331
8922
|
};
|
|
8332
|
-
nullableProcessor = (schema, ctx,
|
|
8923
|
+
nullableProcessor = (schema, ctx, json3, params) => {
|
|
8333
8924
|
const def = schema._zod.def;
|
|
8334
8925
|
const inner = processSchema(def.innerType, ctx, params);
|
|
8335
8926
|
const seen = ctx.seen.get(schema);
|
|
8336
8927
|
if (ctx.target === "openapi-3.0") {
|
|
8337
8928
|
seen.ref = def.innerType;
|
|
8338
|
-
|
|
8929
|
+
json3.nullable = true;
|
|
8339
8930
|
} else {
|
|
8340
|
-
|
|
8931
|
+
json3.anyOf = [inner, { type: "null" }];
|
|
8341
8932
|
}
|
|
8342
8933
|
};
|
|
8343
8934
|
nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
@@ -8347,27 +8938,27 @@ var init_json_schema_processors = __esm({
|
|
|
8347
8938
|
seen.ref = def.innerType;
|
|
8348
8939
|
};
|
|
8349
8940
|
UNREPRESENTABLE_DEFAULT = Symbol();
|
|
8350
|
-
defaultProcessor = (schema, ctx,
|
|
8941
|
+
defaultProcessor = (schema, ctx, json3, params) => {
|
|
8351
8942
|
const def = schema._zod.def;
|
|
8352
8943
|
processSchema(def.innerType, ctx, params);
|
|
8353
8944
|
const seen = ctx.seen.get(schema);
|
|
8354
8945
|
seen.ref = def.innerType;
|
|
8355
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
8946
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
8356
8947
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
8357
|
-
|
|
8948
|
+
json3.default = value;
|
|
8358
8949
|
};
|
|
8359
|
-
prefaultProcessor = (schema, ctx,
|
|
8950
|
+
prefaultProcessor = (schema, ctx, json3, params) => {
|
|
8360
8951
|
const def = schema._zod.def;
|
|
8361
8952
|
processSchema(def.innerType, ctx, params);
|
|
8362
8953
|
const seen = ctx.seen.get(schema);
|
|
8363
8954
|
seen.ref = def.innerType;
|
|
8364
8955
|
if (ctx.io !== "input")
|
|
8365
8956
|
return;
|
|
8366
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
8957
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
8367
8958
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
8368
|
-
|
|
8959
|
+
json3._prefault = value;
|
|
8369
8960
|
};
|
|
8370
|
-
catchProcessor = (schema, ctx,
|
|
8961
|
+
catchProcessor = (schema, ctx, json3, params) => {
|
|
8371
8962
|
const def = schema._zod.def;
|
|
8372
8963
|
processSchema(def.innerType, ctx, params);
|
|
8373
8964
|
const seen = ctx.seen.get(schema);
|
|
@@ -8376,10 +8967,10 @@ var init_json_schema_processors = __esm({
|
|
|
8376
8967
|
try {
|
|
8377
8968
|
catchValue = def.catchValue(void 0);
|
|
8378
8969
|
} catch {
|
|
8379
|
-
handleUnrepresentable(schema, ctx,
|
|
8970
|
+
handleUnrepresentable(schema, ctx, json3, params, "Dynamic catch values are not supported in JSON Schema");
|
|
8380
8971
|
return;
|
|
8381
8972
|
}
|
|
8382
|
-
|
|
8973
|
+
json3.default = catchValue;
|
|
8383
8974
|
};
|
|
8384
8975
|
pipeProcessor = (schema, ctx, _json, params) => {
|
|
8385
8976
|
const def = schema._zod.def;
|
|
@@ -8389,12 +8980,12 @@ var init_json_schema_processors = __esm({
|
|
|
8389
8980
|
const seen = ctx.seen.get(schema);
|
|
8390
8981
|
seen.ref = innerType;
|
|
8391
8982
|
};
|
|
8392
|
-
readonlyProcessor = (schema, ctx,
|
|
8983
|
+
readonlyProcessor = (schema, ctx, json3, params) => {
|
|
8393
8984
|
const def = schema._zod.def;
|
|
8394
8985
|
processSchema(def.innerType, ctx, params);
|
|
8395
8986
|
const seen = ctx.seen.get(schema);
|
|
8396
8987
|
seen.ref = def.innerType;
|
|
8397
|
-
|
|
8988
|
+
json3.readOnly = true;
|
|
8398
8989
|
};
|
|
8399
8990
|
optionalProcessor = (schema, ctx, _json, params) => {
|
|
8400
8991
|
const def = schema._zod.def;
|
|
@@ -8613,13 +9204,13 @@ var init_errors2 = __esm({
|
|
|
8613
9204
|
});
|
|
8614
9205
|
|
|
8615
9206
|
// ../../node_modules/zod/v4/classic/parse.js
|
|
8616
|
-
var
|
|
9207
|
+
var parse3, parseAsync2, safeParse3, safeParseAsync2, encode2, decode2, encodeAsync2, decodeAsync2, safeEncode2, safeDecode2, safeEncodeAsync2, safeDecodeAsync2;
|
|
8617
9208
|
var init_parse3 = __esm({
|
|
8618
9209
|
"../../node_modules/zod/v4/classic/parse.js"() {
|
|
8619
9210
|
init_core2();
|
|
8620
9211
|
init_errors2();
|
|
8621
9212
|
init_core2();
|
|
8622
|
-
|
|
9213
|
+
parse3 = /* @__PURE__ */ _parse(ZodRealError);
|
|
8623
9214
|
parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
8624
9215
|
safeParse3 = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
8625
9216
|
safeParseAsync2 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
@@ -8953,7 +9544,7 @@ var init_schemas3 = __esm({
|
|
|
8953
9544
|
util_exports.own(this, "~standard", value);
|
|
8954
9545
|
},
|
|
8955
9546
|
parse: function _parse2(data, params) {
|
|
8956
|
-
return
|
|
9547
|
+
return parse3(this, data, params, { callee: _parse2 });
|
|
8957
9548
|
},
|
|
8958
9549
|
parseAsync: async function _parseAsync2(data, params) {
|
|
8959
9550
|
return await parseAsync2(this, data, params, { callee: _parseAsync2 });
|
|
@@ -9018,7 +9609,7 @@ var init_schemas3 = __esm({
|
|
|
9018
9609
|
(inst, def) => {
|
|
9019
9610
|
$ZodString.init(inst, def);
|
|
9020
9611
|
ZodType.init(inst, def);
|
|
9021
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9612
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => stringProcessor(inst, ctx, json3, params);
|
|
9022
9613
|
},
|
|
9023
9614
|
/* @__PURE__ */ util_exports.derived({
|
|
9024
9615
|
format: (inst) => aggregateChecks(inst).format ?? null,
|
|
@@ -9256,7 +9847,7 @@ var init_schemas3 = __esm({
|
|
|
9256
9847
|
(inst, def) => {
|
|
9257
9848
|
$ZodNumber.init(inst, def);
|
|
9258
9849
|
ZodType.init(inst, def);
|
|
9259
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9850
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => numberProcessor(inst, ctx, json3, params);
|
|
9260
9851
|
inst.isFinite = true;
|
|
9261
9852
|
},
|
|
9262
9853
|
/* @__PURE__ */ util_exports.derived({
|
|
@@ -9328,14 +9919,14 @@ var init_schemas3 = __esm({
|
|
|
9328
9919
|
ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
9329
9920
|
$ZodBoolean.init(inst, def);
|
|
9330
9921
|
ZodType.init(inst, def);
|
|
9331
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9922
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => booleanProcessor(inst, ctx, json3, params);
|
|
9332
9923
|
});
|
|
9333
9924
|
ZodBigInt = /* @__PURE__ */ $constructor(
|
|
9334
9925
|
"ZodBigInt",
|
|
9335
9926
|
(inst, def) => {
|
|
9336
9927
|
$ZodBigInt.init(inst, def);
|
|
9337
9928
|
ZodType.init(inst, def);
|
|
9338
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9929
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => bigintProcessor(inst, ctx, json3, params);
|
|
9339
9930
|
},
|
|
9340
9931
|
/* @__PURE__ */ util_exports.derived({
|
|
9341
9932
|
minValue: (inst) => aggregateChecks(inst).minimum ?? null,
|
|
@@ -9380,29 +9971,29 @@ var init_schemas3 = __esm({
|
|
|
9380
9971
|
ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
9381
9972
|
$ZodNull.init(inst, def);
|
|
9382
9973
|
ZodType.init(inst, def);
|
|
9383
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9974
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullProcessor(inst, ctx, json3, params);
|
|
9384
9975
|
});
|
|
9385
9976
|
ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
9386
9977
|
$ZodAny.init(inst, def);
|
|
9387
9978
|
ZodType.init(inst, def);
|
|
9388
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9979
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => anyProcessor(inst, ctx, json3, params);
|
|
9389
9980
|
});
|
|
9390
9981
|
ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
9391
9982
|
$ZodUnknown.init(inst, def);
|
|
9392
9983
|
ZodType.init(inst, def);
|
|
9393
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9984
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unknownProcessor(inst, ctx, json3, params);
|
|
9394
9985
|
});
|
|
9395
9986
|
ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
9396
9987
|
$ZodNever.init(inst, def);
|
|
9397
9988
|
ZodType.init(inst, def);
|
|
9398
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9989
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => neverProcessor(inst, ctx, json3, params);
|
|
9399
9990
|
});
|
|
9400
9991
|
ZodDate = /* @__PURE__ */ $constructor(
|
|
9401
9992
|
"ZodDate",
|
|
9402
9993
|
(inst, def) => {
|
|
9403
9994
|
$ZodDate.init(inst, def);
|
|
9404
9995
|
ZodType.init(inst, def);
|
|
9405
|
-
inst._zod.processJSONSchema = (ctx,
|
|
9996
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => dateProcessor(inst, ctx, json3, params);
|
|
9406
9997
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
9407
9998
|
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
9408
9999
|
},
|
|
@@ -9421,7 +10012,7 @@ var init_schemas3 = __esm({
|
|
|
9421
10012
|
_ensureDefaultMemoizer();
|
|
9422
10013
|
$ZodArray.init(inst, def);
|
|
9423
10014
|
ZodType.init(inst, def);
|
|
9424
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10015
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => arrayProcessor(inst, ctx, json3, params);
|
|
9425
10016
|
inst.element = def.element;
|
|
9426
10017
|
}, {
|
|
9427
10018
|
min(n, params) {
|
|
@@ -9444,7 +10035,7 @@ var init_schemas3 = __esm({
|
|
|
9444
10035
|
_ensureDefaultMemoizer();
|
|
9445
10036
|
$ZodObjectJIT.init(inst, def);
|
|
9446
10037
|
ZodType.init(inst, def);
|
|
9447
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10038
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => objectProcessor(inst, ctx, json3, params);
|
|
9448
10039
|
util_exports.installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
|
|
9449
10040
|
}, {
|
|
9450
10041
|
keyof() {
|
|
@@ -9493,7 +10084,7 @@ var init_schemas3 = __esm({
|
|
|
9493
10084
|
ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
9494
10085
|
$ZodUnion.init(inst, def);
|
|
9495
10086
|
ZodType.init(inst, def);
|
|
9496
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10087
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
|
|
9497
10088
|
inst.options = def.options;
|
|
9498
10089
|
});
|
|
9499
10090
|
ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
@@ -9503,20 +10094,20 @@ var init_schemas3 = __esm({
|
|
|
9503
10094
|
ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
9504
10095
|
$ZodIntersection.init(inst, def);
|
|
9505
10096
|
ZodType.init(inst, def);
|
|
9506
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10097
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => intersectionProcessor(inst, ctx, json3, params);
|
|
9507
10098
|
});
|
|
9508
10099
|
ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
9509
10100
|
_ensureDefaultMemoizer();
|
|
9510
10101
|
$ZodRecord.init(inst, def);
|
|
9511
10102
|
ZodType.init(inst, def);
|
|
9512
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10103
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => recordProcessor(inst, ctx, json3, params);
|
|
9513
10104
|
inst.keyType = def.keyType;
|
|
9514
10105
|
inst.valueType = def.valueType;
|
|
9515
10106
|
});
|
|
9516
10107
|
ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
9517
10108
|
$ZodEnum.init(inst, def);
|
|
9518
10109
|
ZodType.init(inst, def);
|
|
9519
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10110
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => enumProcessor(inst, ctx, json3, params);
|
|
9520
10111
|
inst.enum = def.entries;
|
|
9521
10112
|
inst.options = [...inst._zod.values];
|
|
9522
10113
|
const keys = new Set(Object.keys(def.entries));
|
|
@@ -9554,7 +10145,7 @@ var init_schemas3 = __esm({
|
|
|
9554
10145
|
ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
9555
10146
|
$ZodLiteral.init(inst, def);
|
|
9556
10147
|
ZodType.init(inst, def);
|
|
9557
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10148
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => literalProcessor(inst, ctx, json3, params);
|
|
9558
10149
|
inst.values = new Set(def.values);
|
|
9559
10150
|
Object.defineProperty(inst, "value", {
|
|
9560
10151
|
get() {
|
|
@@ -9569,7 +10160,7 @@ var init_schemas3 = __esm({
|
|
|
9569
10160
|
_ensureDefaultMemoizer();
|
|
9570
10161
|
$ZodTransform.init(inst, def);
|
|
9571
10162
|
ZodType.init(inst, def);
|
|
9572
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10163
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => transformProcessor(inst, ctx, json3, params);
|
|
9573
10164
|
inst._zod.parse = (payload, _ctx) => {
|
|
9574
10165
|
if (_ctx.direction === "backward") {
|
|
9575
10166
|
throw new $ZodEncodeError(inst.constructor.name);
|
|
@@ -9602,51 +10193,51 @@ var init_schemas3 = __esm({
|
|
|
9602
10193
|
ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
9603
10194
|
$ZodOptional.init(inst, def);
|
|
9604
10195
|
ZodType.init(inst, def);
|
|
9605
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10196
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
9606
10197
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9607
10198
|
});
|
|
9608
10199
|
ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
9609
10200
|
$ZodExactOptional.init(inst, def);
|
|
9610
10201
|
ZodType.init(inst, def);
|
|
9611
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10202
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
9612
10203
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9613
10204
|
});
|
|
9614
10205
|
ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
9615
10206
|
$ZodNullable.init(inst, def);
|
|
9616
10207
|
ZodType.init(inst, def);
|
|
9617
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10208
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullableProcessor(inst, ctx, json3, params);
|
|
9618
10209
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9619
10210
|
});
|
|
9620
10211
|
ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
9621
10212
|
$ZodDefault.init(inst, def);
|
|
9622
10213
|
ZodType.init(inst, def);
|
|
9623
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10214
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => defaultProcessor(inst, ctx, json3, params);
|
|
9624
10215
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9625
10216
|
inst.removeDefault = inst.unwrap;
|
|
9626
10217
|
});
|
|
9627
10218
|
ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
9628
10219
|
$ZodPrefault.init(inst, def);
|
|
9629
10220
|
ZodType.init(inst, def);
|
|
9630
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10221
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => prefaultProcessor(inst, ctx, json3, params);
|
|
9631
10222
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9632
10223
|
});
|
|
9633
10224
|
ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
9634
10225
|
$ZodNonOptional.init(inst, def);
|
|
9635
10226
|
ZodType.init(inst, def);
|
|
9636
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10227
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nonoptionalProcessor(inst, ctx, json3, params);
|
|
9637
10228
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9638
10229
|
});
|
|
9639
10230
|
ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
9640
10231
|
$ZodCatch.init(inst, def);
|
|
9641
10232
|
ZodType.init(inst, def);
|
|
9642
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10233
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => catchProcessor(inst, ctx, json3, params);
|
|
9643
10234
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9644
10235
|
inst.removeCatch = inst.unwrap;
|
|
9645
10236
|
});
|
|
9646
10237
|
ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
9647
10238
|
$ZodPipe.init(inst, def);
|
|
9648
10239
|
ZodType.init(inst, def);
|
|
9649
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10240
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => pipeProcessor(inst, ctx, json3, params);
|
|
9650
10241
|
inst.in = def.in;
|
|
9651
10242
|
inst.out = def.out;
|
|
9652
10243
|
});
|
|
@@ -9657,13 +10248,13 @@ var init_schemas3 = __esm({
|
|
|
9657
10248
|
ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
9658
10249
|
$ZodReadonly.init(inst, def);
|
|
9659
10250
|
ZodType.init(inst, def);
|
|
9660
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10251
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => readonlyProcessor(inst, ctx, json3, params);
|
|
9661
10252
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
9662
10253
|
});
|
|
9663
10254
|
ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
9664
10255
|
$ZodCustom.init(inst, def);
|
|
9665
10256
|
ZodType.init(inst, def);
|
|
9666
|
-
inst._zod.processJSONSchema = (ctx,
|
|
10257
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => customProcessor(inst, ctx, json3, params);
|
|
9667
10258
|
});
|
|
9668
10259
|
}
|
|
9669
10260
|
});
|
|
@@ -9699,7 +10290,7 @@ __export(iso_exports2, {
|
|
|
9699
10290
|
ZodISOTime: () => ZodISOTime,
|
|
9700
10291
|
date: () => date2,
|
|
9701
10292
|
datetime: () => datetime2,
|
|
9702
|
-
duration: () =>
|
|
10293
|
+
duration: () => duration3,
|
|
9703
10294
|
time: () => time2
|
|
9704
10295
|
});
|
|
9705
10296
|
function datetime2(params) {
|
|
@@ -9711,7 +10302,7 @@ function date2(params) {
|
|
|
9711
10302
|
function time2(params) {
|
|
9712
10303
|
return _isoTime(ZodISOTime, params);
|
|
9713
10304
|
}
|
|
9714
|
-
function
|
|
10305
|
+
function duration3(params) {
|
|
9715
10306
|
return _isoDuration(ZodISODuration, params);
|
|
9716
10307
|
}
|
|
9717
10308
|
var init_iso2 = __esm({
|
|
@@ -12242,7 +12833,7 @@ var init_protocol = __esm({
|
|
|
12242
12833
|
return;
|
|
12243
12834
|
}
|
|
12244
12835
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
12245
|
-
await new Promise((
|
|
12836
|
+
await new Promise((resolve10) => setTimeout(resolve10, pollInterval));
|
|
12246
12837
|
options?.signal?.throwIfAborted();
|
|
12247
12838
|
}
|
|
12248
12839
|
} catch (error2) {
|
|
@@ -12259,7 +12850,7 @@ var init_protocol = __esm({
|
|
|
12259
12850
|
*/
|
|
12260
12851
|
request(request, resultSchema, options) {
|
|
12261
12852
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
12262
|
-
return new Promise((
|
|
12853
|
+
return new Promise((resolve10, reject) => {
|
|
12263
12854
|
const earlyReject = (error2) => {
|
|
12264
12855
|
reject(error2);
|
|
12265
12856
|
};
|
|
@@ -12337,7 +12928,7 @@ var init_protocol = __esm({
|
|
|
12337
12928
|
if (!parseResult.success) {
|
|
12338
12929
|
reject(parseResult.error);
|
|
12339
12930
|
} else {
|
|
12340
|
-
|
|
12931
|
+
resolve10(parseResult.data);
|
|
12341
12932
|
}
|
|
12342
12933
|
} catch (error2) {
|
|
12343
12934
|
reject(error2);
|
|
@@ -12599,12 +13190,12 @@ var init_protocol = __esm({
|
|
|
12599
13190
|
}
|
|
12600
13191
|
} catch {
|
|
12601
13192
|
}
|
|
12602
|
-
return new Promise((
|
|
13193
|
+
return new Promise((resolve10, reject) => {
|
|
12603
13194
|
if (signal.aborted) {
|
|
12604
13195
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
12605
13196
|
return;
|
|
12606
13197
|
}
|
|
12607
|
-
const timeoutId = setTimeout(
|
|
13198
|
+
const timeoutId = setTimeout(resolve10, interval);
|
|
12608
13199
|
signal.addEventListener("abort", () => {
|
|
12609
13200
|
clearTimeout(timeoutId);
|
|
12610
13201
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -12893,13 +13484,13 @@ var require_scope = __commonJS({
|
|
|
12893
13484
|
}
|
|
12894
13485
|
};
|
|
12895
13486
|
exports.ValueScopeName = ValueScopeName;
|
|
12896
|
-
var
|
|
13487
|
+
var line2 = (0, code_1._)`\n`;
|
|
12897
13488
|
var ValueScope = class extends Scope {
|
|
12898
13489
|
constructor(opts) {
|
|
12899
13490
|
super(opts);
|
|
12900
13491
|
this._values = {};
|
|
12901
13492
|
this._scope = opts.scope;
|
|
12902
|
-
this.opts = { ...opts, _n: opts.lines ?
|
|
13493
|
+
this.opts = { ...opts, _n: opts.lines ? line2 : code_1.nil };
|
|
12903
13494
|
}
|
|
12904
13495
|
get() {
|
|
12905
13496
|
return this._scope;
|
|
@@ -15631,7 +16222,7 @@ var require_compile = __commonJS({
|
|
|
15631
16222
|
const schOrFunc = root.refs[ref];
|
|
15632
16223
|
if (schOrFunc)
|
|
15633
16224
|
return schOrFunc;
|
|
15634
|
-
let _sch =
|
|
16225
|
+
let _sch = resolve10.call(this, root, ref);
|
|
15635
16226
|
if (_sch === void 0) {
|
|
15636
16227
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
15637
16228
|
const { schemaId } = this.opts;
|
|
@@ -15658,7 +16249,7 @@ var require_compile = __commonJS({
|
|
|
15658
16249
|
function sameSchemaEnv(s1, s2) {
|
|
15659
16250
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
15660
16251
|
}
|
|
15661
|
-
function
|
|
16252
|
+
function resolve10(root, ref) {
|
|
15662
16253
|
let sch;
|
|
15663
16254
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
15664
16255
|
ref = sch;
|
|
@@ -16518,11 +17109,11 @@ var require_fast_uri = __commonJS({
|
|
|
16518
17109
|
normalizeString(uri, options);
|
|
16519
17110
|
} else if (typeof uri === "object") {
|
|
16520
17111
|
uri = /** @type {T} */
|
|
16521
|
-
|
|
17112
|
+
parse4(serialize(uri, options), options);
|
|
16522
17113
|
}
|
|
16523
17114
|
return uri;
|
|
16524
17115
|
}
|
|
16525
|
-
function
|
|
17116
|
+
function resolve10(baseURI, relativeURI, options) {
|
|
16526
17117
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
16527
17118
|
const {
|
|
16528
17119
|
parsed: baseParsed,
|
|
@@ -16558,50 +17149,50 @@ var require_fast_uri = __commonJS({
|
|
|
16558
17149
|
schemelessOptions.skipEscape = true;
|
|
16559
17150
|
return serialize(resolved, schemelessOptions);
|
|
16560
17151
|
}
|
|
16561
|
-
function resolveComponent(base,
|
|
17152
|
+
function resolveComponent(base, relative5, options, skipNormalization) {
|
|
16562
17153
|
const target = {};
|
|
16563
17154
|
if (!skipNormalization) {
|
|
16564
|
-
base =
|
|
16565
|
-
|
|
17155
|
+
base = parse4(serialize(base, options), options);
|
|
17156
|
+
relative5 = parse4(serialize(relative5, options), options);
|
|
16566
17157
|
}
|
|
16567
17158
|
options = options || {};
|
|
16568
|
-
if (!options.tolerant &&
|
|
16569
|
-
target.scheme =
|
|
16570
|
-
target.userinfo =
|
|
16571
|
-
target.host =
|
|
16572
|
-
target.port =
|
|
16573
|
-
target.path = removeDotSegments(
|
|
16574
|
-
target.query =
|
|
17159
|
+
if (!options.tolerant && relative5.scheme) {
|
|
17160
|
+
target.scheme = relative5.scheme;
|
|
17161
|
+
target.userinfo = relative5.userinfo;
|
|
17162
|
+
target.host = relative5.host;
|
|
17163
|
+
target.port = relative5.port;
|
|
17164
|
+
target.path = removeDotSegments(relative5.path || "");
|
|
17165
|
+
target.query = relative5.query;
|
|
16575
17166
|
} else {
|
|
16576
|
-
if (
|
|
16577
|
-
target.userinfo =
|
|
16578
|
-
target.host =
|
|
16579
|
-
target.port =
|
|
16580
|
-
target.path = removeDotSegments(
|
|
16581
|
-
target.query =
|
|
17167
|
+
if (relative5.userinfo !== void 0 || relative5.host !== void 0 || relative5.port !== void 0) {
|
|
17168
|
+
target.userinfo = relative5.userinfo;
|
|
17169
|
+
target.host = relative5.host;
|
|
17170
|
+
target.port = relative5.port;
|
|
17171
|
+
target.path = removeDotSegments(relative5.path || "");
|
|
17172
|
+
target.query = relative5.query;
|
|
16582
17173
|
} else {
|
|
16583
|
-
if (!
|
|
17174
|
+
if (!relative5.path) {
|
|
16584
17175
|
target.path = base.path;
|
|
16585
|
-
if (
|
|
16586
|
-
target.query =
|
|
17176
|
+
if (relative5.query !== void 0) {
|
|
17177
|
+
target.query = relative5.query;
|
|
16587
17178
|
} else {
|
|
16588
17179
|
target.query = base.query;
|
|
16589
17180
|
}
|
|
16590
17181
|
} else {
|
|
16591
|
-
if (
|
|
16592
|
-
target.path = removeDotSegments(
|
|
17182
|
+
if (relative5.path[0] === "/") {
|
|
17183
|
+
target.path = removeDotSegments(relative5.path);
|
|
16593
17184
|
} else {
|
|
16594
17185
|
const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
|
|
16595
17186
|
if (baseHasAuthority && !base.path) {
|
|
16596
|
-
target.path = "/" +
|
|
17187
|
+
target.path = "/" + relative5.path;
|
|
16597
17188
|
} else if (!base.path) {
|
|
16598
|
-
target.path =
|
|
17189
|
+
target.path = relative5.path;
|
|
16599
17190
|
} else {
|
|
16600
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
17191
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative5.path;
|
|
16601
17192
|
}
|
|
16602
17193
|
target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
|
|
16603
17194
|
}
|
|
16604
|
-
target.query =
|
|
17195
|
+
target.query = relative5.query;
|
|
16605
17196
|
}
|
|
16606
17197
|
target.userinfo = base.userinfo;
|
|
16607
17198
|
target.host = base.host;
|
|
@@ -16609,7 +17200,7 @@ var require_fast_uri = __commonJS({
|
|
|
16609
17200
|
}
|
|
16610
17201
|
target.scheme = base.scheme;
|
|
16611
17202
|
}
|
|
16612
|
-
target.fragment =
|
|
17203
|
+
target.fragment = relative5.fragment;
|
|
16613
17204
|
return target;
|
|
16614
17205
|
}
|
|
16615
17206
|
function equal(uriA, uriB, options) {
|
|
@@ -16880,7 +17471,7 @@ var require_fast_uri = __commonJS({
|
|
|
16880
17471
|
}
|
|
16881
17472
|
return { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
|
|
16882
17473
|
}
|
|
16883
|
-
function
|
|
17474
|
+
function parse4(uri, opts) {
|
|
16884
17475
|
return parseWithStatus(uri, opts).parsed;
|
|
16885
17476
|
}
|
|
16886
17477
|
function normalizeString(uri, opts) {
|
|
@@ -16913,11 +17504,11 @@ var require_fast_uri = __commonJS({
|
|
|
16913
17504
|
var fastUri = {
|
|
16914
17505
|
SCHEMES,
|
|
16915
17506
|
normalize,
|
|
16916
|
-
resolve:
|
|
17507
|
+
resolve: resolve10,
|
|
16917
17508
|
resolveComponent,
|
|
16918
17509
|
equal,
|
|
16919
17510
|
serialize,
|
|
16920
|
-
parse:
|
|
17511
|
+
parse: parse4
|
|
16921
17512
|
};
|
|
16922
17513
|
module.exports = fastUri;
|
|
16923
17514
|
module.exports.default = fastUri;
|
|
@@ -20707,7 +21298,7 @@ var require_content_type = __commonJS({
|
|
|
20707
21298
|
var QUOTE_REGEXP = /([\\"])/g;
|
|
20708
21299
|
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
20709
21300
|
exports.format = format;
|
|
20710
|
-
exports.parse =
|
|
21301
|
+
exports.parse = parse4;
|
|
20711
21302
|
function format(obj) {
|
|
20712
21303
|
if (!obj || typeof obj !== "object") {
|
|
20713
21304
|
throw new TypeError("argument obj is required");
|
|
@@ -20731,7 +21322,7 @@ var require_content_type = __commonJS({
|
|
|
20731
21322
|
}
|
|
20732
21323
|
return string4;
|
|
20733
21324
|
}
|
|
20734
|
-
function
|
|
21325
|
+
function parse4(string4) {
|
|
20735
21326
|
if (!string4) {
|
|
20736
21327
|
throw new TypeError("argument string is required");
|
|
20737
21328
|
}
|
|
@@ -21952,20 +22543,20 @@ ${value2}`, dataLines++;
|
|
|
21952
22543
|
}
|
|
21953
22544
|
if (firstCharCode === 58) {
|
|
21954
22545
|
if (onComment) {
|
|
21955
|
-
const
|
|
21956
|
-
onComment(
|
|
22546
|
+
const line22 = chunk.slice(start, end);
|
|
22547
|
+
onComment(line22.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
21957
22548
|
}
|
|
21958
22549
|
return;
|
|
21959
22550
|
}
|
|
21960
|
-
const
|
|
22551
|
+
const line2 = chunk.slice(start, end), fieldSeparatorIndex = line2.indexOf(":");
|
|
21961
22552
|
if (fieldSeparatorIndex === -1) {
|
|
21962
|
-
processField(
|
|
22553
|
+
processField(line2, "", line2);
|
|
21963
22554
|
return;
|
|
21964
22555
|
}
|
|
21965
|
-
const field =
|
|
21966
|
-
processField(field, value,
|
|
22556
|
+
const field = line2.slice(0, fieldSeparatorIndex), offset = line2.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line2.slice(fieldSeparatorIndex + offset);
|
|
22557
|
+
processField(field, value, line2);
|
|
21967
22558
|
}
|
|
21968
|
-
function processField(field, value,
|
|
22559
|
+
function processField(field, value, line2) {
|
|
21969
22560
|
switch (field) {
|
|
21970
22561
|
case "event":
|
|
21971
22562
|
eventType = value || void 0;
|
|
@@ -21982,7 +22573,7 @@ ${value}`, dataLines++;
|
|
|
21982
22573
|
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
21983
22574
|
type: "invalid-retry",
|
|
21984
22575
|
value,
|
|
21985
|
-
line
|
|
22576
|
+
line: line2
|
|
21986
22577
|
})
|
|
21987
22578
|
);
|
|
21988
22579
|
break;
|
|
@@ -21990,7 +22581,7 @@ ${value}`, dataLines++;
|
|
|
21990
22581
|
onError(
|
|
21991
22582
|
new ParseError(
|
|
21992
22583
|
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
21993
|
-
{ type: "unknown-field", field, value, line }
|
|
22584
|
+
{ type: "unknown-field", field, value, line: line2 }
|
|
21994
22585
|
)
|
|
21995
22586
|
);
|
|
21996
22587
|
break;
|
|
@@ -23084,8 +23675,8 @@ var init_server2 = __esm({
|
|
|
23084
23675
|
});
|
|
23085
23676
|
|
|
23086
23677
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
23087
|
-
function deserializeMessage(
|
|
23088
|
-
return JSONRPCMessageSchema.parse(JSON.parse(
|
|
23678
|
+
function deserializeMessage(line2) {
|
|
23679
|
+
return JSONRPCMessageSchema.parse(JSON.parse(line2));
|
|
23089
23680
|
}
|
|
23090
23681
|
function serializeMessage(message) {
|
|
23091
23682
|
return JSON.stringify(message) + "\n";
|
|
@@ -23115,9 +23706,9 @@ var init_stdio = __esm({
|
|
|
23115
23706
|
if (index === -1) {
|
|
23116
23707
|
return null;
|
|
23117
23708
|
}
|
|
23118
|
-
const
|
|
23709
|
+
const line2 = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
|
|
23119
23710
|
this._buffer = this._buffer.subarray(index + 1);
|
|
23120
|
-
return deserializeMessage(
|
|
23711
|
+
return deserializeMessage(line2);
|
|
23121
23712
|
}
|
|
23122
23713
|
clear() {
|
|
23123
23714
|
this._buffer = void 0;
|
|
@@ -23187,12 +23778,12 @@ var init_stdio2 = __esm({
|
|
|
23187
23778
|
this.onclose?.();
|
|
23188
23779
|
}
|
|
23189
23780
|
send(message) {
|
|
23190
|
-
return new Promise((
|
|
23191
|
-
const
|
|
23192
|
-
if (this._stdout.write(
|
|
23193
|
-
|
|
23781
|
+
return new Promise((resolve10) => {
|
|
23782
|
+
const json3 = serializeMessage(message);
|
|
23783
|
+
if (this._stdout.write(json3)) {
|
|
23784
|
+
resolve10();
|
|
23194
23785
|
} else {
|
|
23195
|
-
this._stdout.once("drain",
|
|
23786
|
+
this._stdout.once("drain", resolve10);
|
|
23196
23787
|
}
|
|
23197
23788
|
});
|
|
23198
23789
|
}
|
|
@@ -23225,7 +23816,7 @@ function createCodingMcpServer(options = {}) {
|
|
|
23225
23816
|
throw new McpError(ErrorCode.InvalidRequest, signIn);
|
|
23226
23817
|
}
|
|
23227
23818
|
};
|
|
23228
|
-
const
|
|
23819
|
+
const uuid16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
23229
23820
|
const grantOf = (config2) => storedGrant(config2, endpoint2.href);
|
|
23230
23821
|
async function renew() {
|
|
23231
23822
|
try {
|
|
@@ -23241,7 +23832,7 @@ function createCodingMcpServer(options = {}) {
|
|
|
23241
23832
|
const config2 = readConfig();
|
|
23242
23833
|
const grant = grantOf(config2);
|
|
23243
23834
|
const organizationIds = grant ? grant.organizationIds : config2.organizationId ? [config2.organizationId] : [];
|
|
23244
|
-
if (!grant && (!config2.organizationId || !
|
|
23835
|
+
if (!grant && (!config2.organizationId || !uuid16.test(config2.organizationId) || !config2.token || /[\r\n]/.test(config2.token) || /^bf(?:cli|agent|mcp)_/i.test(config2.token)))
|
|
23245
23836
|
throw new McpError(ErrorCode.InvalidRequest, signIn);
|
|
23246
23837
|
if (boundOrganizationId && !organizationIds.some((id) => id.toLowerCase() === boundOrganizationId.toLowerCase()))
|
|
23247
23838
|
throw new McpError(ErrorCode.InvalidRequest, "Organization changed. Restart the Backify MCP connection to explicitly select the new organization.");
|
|
@@ -23341,7 +23932,7 @@ function opsArguments(args2) {
|
|
|
23341
23932
|
if (value === void 0 || flag !== "--param" && value.startsWith("--")) throw new Error(flag + " needs a value.");
|
|
23342
23933
|
switch (flag) {
|
|
23343
23934
|
case "--organization":
|
|
23344
|
-
if (!
|
|
23935
|
+
if (!uuid9.test(value)) throw new Error("--organization must be an organization ID (UUID).");
|
|
23345
23936
|
parsed.organizationId = value;
|
|
23346
23937
|
break;
|
|
23347
23938
|
case "--group":
|
|
@@ -23588,7 +24179,7 @@ function searchResult(catalog, session, options) {
|
|
|
23588
24179
|
const routeWidth = Math.min(64, Math.max(0, ...page.map((operation) => operation.method.length + operation.path.length + 1)) + 2);
|
|
23589
24180
|
for (const operation of page) {
|
|
23590
24181
|
const access = operation.missingScopes === null ? " [not delegable]" : operation.missingScopes.length ? ` [needs ${operation.missingScopes.join(" ")}]` : "";
|
|
23591
|
-
lines.push(" " +
|
|
24182
|
+
lines.push(" " + pad2(operation.id, idWidth) + pad2(`${operation.method} ${operation.path}`, routeWidth) + (operation.summary ?? "") + access);
|
|
23592
24183
|
}
|
|
23593
24184
|
if (groups) lines.push("", "Groups: " + groups.join(", "));
|
|
23594
24185
|
if (page.length) lines.push("", "Next: backify ops describe <operationId>");
|
|
@@ -23674,7 +24265,7 @@ async function organizationCall(context2, organizationId) {
|
|
|
23674
24265
|
const session = await signIn2(context2, organizationId);
|
|
23675
24266
|
return { call: sessionCall(session, context2), organizationId: session.organizationId };
|
|
23676
24267
|
}
|
|
23677
|
-
var opsHelp, OpsError,
|
|
24268
|
+
var opsHelp, OpsError, uuid9, valueFlags, booleanFlags, reconnect, contentTypes, sensitiveKey, pad2;
|
|
23678
24269
|
var init_ops = __esm({
|
|
23679
24270
|
"src/ops.ts"() {
|
|
23680
24271
|
"use strict";
|
|
@@ -23704,7 +24295,7 @@ var init_ops = __esm({
|
|
|
23704
24295
|
this.details = details;
|
|
23705
24296
|
}
|
|
23706
24297
|
};
|
|
23707
|
-
|
|
24298
|
+
uuid9 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
23708
24299
|
valueFlags = {
|
|
23709
24300
|
"--organization": ["search", "describe", "get", "run"],
|
|
23710
24301
|
"--group": ["search"],
|
|
@@ -23736,21 +24327,39 @@ var init_ops = __esm({
|
|
|
23736
24327
|
".tgz": "application/gzip"
|
|
23737
24328
|
};
|
|
23738
24329
|
sensitiveKey = /secret|password|passphrase|token|credential|private|api[-_]?key|connection[-_]?string/i;
|
|
23739
|
-
|
|
24330
|
+
pad2 = (value, width) => value.length >= width ? value + " " : value + " ".repeat(width - value.length);
|
|
23740
24331
|
}
|
|
23741
24332
|
});
|
|
23742
24333
|
|
|
23743
24334
|
// src/tasks.ts
|
|
23744
24335
|
var tasks_exports = {};
|
|
23745
24336
|
__export(tasks_exports, {
|
|
24337
|
+
locationsText: () => locationsText,
|
|
23746
24338
|
opsHumanTaskHandler: () => opsHumanTaskHandler,
|
|
23747
24339
|
runTaskCommand: () => runTaskCommand,
|
|
24340
|
+
runtimeUpgradeText: () => runtimeUpgradeText,
|
|
23748
24341
|
startTask: () => startTask,
|
|
23749
24342
|
taskArguments: () => taskArguments,
|
|
23750
24343
|
taskDraft: () => taskDraft,
|
|
23751
24344
|
taskHelp: () => taskHelp
|
|
23752
24345
|
});
|
|
23753
24346
|
import { readFileSync as readFileSync12 } from "node:fs";
|
|
24347
|
+
function runtimeUpgradeText(deployment) {
|
|
24348
|
+
const upgrade = deployment.upgrade;
|
|
24349
|
+
if (!upgrade) return deployment.updateAvailable ? `Runtime ${deployment.version ?? "unknown"}. Version ${deployment.latestVersion} is available; no upgrade has been proposed yet.` : `Runtime ${deployment.version ?? "unknown"} is up to date.`;
|
|
24350
|
+
const lines = [`Upgrade to ${upgrade.targetVersion} from ${upgrade.previousVersion ?? deployment.version ?? "unknown"}: ${upgrade.phase} (${upgrade.state})`];
|
|
24351
|
+
const verification = upgrade.verification;
|
|
24352
|
+
if (verification?.signature === "valid") lines.push("Verification: signature and digest verified" + (verification.protocol ? `; protocol versions ${verification.protocol.min} to ${verification.protocol.max}` : "") + (verification.stateSchema?.reads ? `; reads data formats ${verification.stateSchema.reads.min} to ${verification.stateSchema.reads.max}` : ""));
|
|
24353
|
+
if (upgrade.phase === "canary" || upgrade.canary) {
|
|
24354
|
+
const outcome = upgrade.canary ?? { succeeded: 0, failed: 0, running: 0 };
|
|
24355
|
+
lines.push(`Canary: ${outcome.succeeded + outcome.failed} commands finished, ${outcome.failed} failed, ${outcome.running} running` + (upgrade.soakUntil && upgrade.phase === "canary" ? `; observation period ends ${upgrade.soakUntil}` : ""));
|
|
24356
|
+
}
|
|
24357
|
+
if (upgrade.phase === "canary" || upgrade.phase === "promoted") lines.push("The previous version is kept and can be restored until the upgrade is committed.");
|
|
24358
|
+
if (upgrade.phase === "rolled-back") lines.push(`Rolled back: ${upgrade.detail ?? upgrade.failureCode ?? "reason not reported"}`);
|
|
24359
|
+
if (upgrade.phase === "failed") lines.push(`Failed: ${[upgrade.failureCode, upgrade.detail].filter(Boolean).join(": ") || "no details reported"}`);
|
|
24360
|
+
if (upgrade.state === "awaiting-approval") lines.push("Approve it with: backify azure update-runtime --connection <id>");
|
|
24361
|
+
return lines.join("\n");
|
|
24362
|
+
}
|
|
23754
24363
|
function taskArguments(args2) {
|
|
23755
24364
|
const options = { noBrowser: false, noWait: false, json: false, yes: false };
|
|
23756
24365
|
const positional = [], values = {};
|
|
@@ -23843,6 +24452,82 @@ function opsHumanTaskHandler(options, context2) {
|
|
|
23843
24452
|
return result;
|
|
23844
24453
|
};
|
|
23845
24454
|
}
|
|
24455
|
+
async function readLocations(call2, organizationId, workspaceId) {
|
|
24456
|
+
const supported = (await call2(`/organizations/${organizationId}/supported-regions` + (workspaceId ? "?workspaceId=" + workspaceId : ""))).regions;
|
|
24457
|
+
const organization = (await call2("/organizations")).find((value) => value.id === organizationId);
|
|
24458
|
+
if (!organization) throw new Error("The organization was not found.");
|
|
24459
|
+
const organizationAllowed = (organization.allowedRegions ?? supported).filter((region) => supported.includes(region));
|
|
24460
|
+
if (!workspaceId) return {
|
|
24461
|
+
scope: "organization",
|
|
24462
|
+
organization,
|
|
24463
|
+
supportedRegions: supported,
|
|
24464
|
+
allowedRegions: organization.allowedRegions ?? null,
|
|
24465
|
+
defaultRegion: organization.defaultRegion,
|
|
24466
|
+
effectiveAllowedRegions: organizationAllowed,
|
|
24467
|
+
effectiveDefaultRegion: organization.defaultRegion
|
|
24468
|
+
};
|
|
24469
|
+
const workspace = (await call2("/workspaces")).find((value) => value.id === workspaceId);
|
|
24470
|
+
if (!workspace) throw new Error("The workspace was not found.");
|
|
24471
|
+
const effective = await call2(`/workspaces/${workspaceId}/effective-settings`);
|
|
24472
|
+
return {
|
|
24473
|
+
scope: "workspace",
|
|
24474
|
+
workspaceId,
|
|
24475
|
+
organization,
|
|
24476
|
+
workspace,
|
|
24477
|
+
supportedRegions: supported,
|
|
24478
|
+
allowedRegions: workspace.allowedRegions ?? null,
|
|
24479
|
+
defaultRegion: workspace.defaultRegion ?? null,
|
|
24480
|
+
effectiveAllowedRegions: effective.allowedRegions.filter((region) => supported.includes(region)),
|
|
24481
|
+
effectiveDefaultRegion: effective.region
|
|
24482
|
+
};
|
|
24483
|
+
}
|
|
24484
|
+
function locationsText(view) {
|
|
24485
|
+
const all = view.scope === "organization" ? "every supported location" : "the organization's locations";
|
|
24486
|
+
return [
|
|
24487
|
+
`Default location: ${view.effectiveDefaultRegion}${view.scope === "workspace" && view.defaultRegion === null ? " (organization default)" : ""}`,
|
|
24488
|
+
`Allowed locations: ${view.allowedRegions === null ? all + ": " : ""}${view.effectiveAllowedRegions.join(", ") || "none"}`,
|
|
24489
|
+
`Supported locations (Backify Cloud and connected clouds): ${view.supportedRegions.join(", ") || "none yet; connect a cloud or ask your platform operator"}`
|
|
24490
|
+
].join("\n");
|
|
24491
|
+
}
|
|
24492
|
+
async function setLocations(call2, organizationId, values, options, context2) {
|
|
24493
|
+
const workspaceId = workspaceOption(values);
|
|
24494
|
+
const allow = values.allow?.map((region) => region.trim().toLowerCase()), [defaultChoice] = (values.default ?? []).map((region) => region.trim().toLowerCase());
|
|
24495
|
+
if (!allow && !defaultChoice) throw new Error("Pass --default <region> and/or --allow <region> (repeat it, or use all or inherit).");
|
|
24496
|
+
const special = allow?.find((region) => region === "all" || region === "inherit");
|
|
24497
|
+
if (special && allow.length > 1) throw new Error(`--allow ${special} cannot be combined with regions.`);
|
|
24498
|
+
if (special === "inherit" && !workspaceId) throw new Error("--allow inherit is for a workspace; use --allow all for the organization.");
|
|
24499
|
+
if (defaultChoice === "inherit" && !workspaceId) throw new Error("--default inherit is for a workspace.");
|
|
24500
|
+
const current = await readLocations(call2, organizationId, workspaceId);
|
|
24501
|
+
const allowedRegions = !allow ? current.allowedRegions : special === "all" ? workspaceId ? current.supportedRegions.filter((region) => (current.organization.allowedRegions ?? current.supportedRegions).includes(region)) : null : special === "inherit" ? null : [...new Set(allow)];
|
|
24502
|
+
const scope = workspaceId ? `workspace ${current.workspace.name}` : `organization ${current.organization.name}`;
|
|
24503
|
+
const change = [allow ? `allowed locations to ${allowedRegions ? allowedRegions.join(", ") : workspaceId ? "the organization's" : "every supported location"}` : "", defaultChoice ? `default location to ${defaultChoice === "inherit" ? "the organization's" : defaultChoice}` : ""].filter(Boolean).join(" and ");
|
|
24504
|
+
if (!options.yes) {
|
|
24505
|
+
if (!context2.confirm) throw new OpsError(`Refusing to change locations without confirmation. Re-run with --yes to set the ${scope} ${change}.`, "confirmation_required");
|
|
24506
|
+
if (!await context2.confirm(`Set the ${scope} ${change}? Existing applications are not moved.`)) throw new OpsError("Not confirmed. Nothing was changed.", "not_confirmed");
|
|
24507
|
+
}
|
|
24508
|
+
if (workspaceId) {
|
|
24509
|
+
const workspace = current.workspace;
|
|
24510
|
+
const defaultRegion = defaultChoice === "inherit" ? null : defaultChoice ?? workspace.defaultRegion ?? null;
|
|
24511
|
+
await call2(`/workspaces/${workspaceId}`, { method: "PATCH", headers: json, body: JSON.stringify({
|
|
24512
|
+
name: workspace.name,
|
|
24513
|
+
description: workspace.description ?? null,
|
|
24514
|
+
isDefault: workspace.isDefault,
|
|
24515
|
+
defaultRegion,
|
|
24516
|
+
allowedRegions,
|
|
24517
|
+
cloudConnectionId: workspace.cloudConnectionId ?? null,
|
|
24518
|
+
deploymentTargetId: workspace.deploymentTargetId ?? null,
|
|
24519
|
+
githubInstallationId: workspace.githubInstallationId ?? null,
|
|
24520
|
+
allowHostingSelection: workspace.allowHostingSelection !== false,
|
|
24521
|
+
allowRepositorySelection: workspace.allowRepositorySelection !== false,
|
|
24522
|
+
repositoryNamePrefix: workspace.repositoryNamePrefix ?? "",
|
|
24523
|
+
repositoryNamePostfix: workspace.repositoryNamePostfix ?? ""
|
|
24524
|
+
}) });
|
|
24525
|
+
} else {
|
|
24526
|
+
await call2(`/organizations/${organizationId}`, { method: "PATCH", headers: json, body: JSON.stringify({ name: current.organization.name, region: defaultChoice ?? current.organization.defaultRegion, allowedRegions }) });
|
|
24527
|
+
}
|
|
24528
|
+
const { organization: _organization, workspace: _workspace, ...view } = await readLocations(call2, organizationId, workspaceId);
|
|
24529
|
+
return { value: view, text: "Locations saved.\n" + locationsText(view), exitCode: 0 };
|
|
24530
|
+
}
|
|
23846
24531
|
function scopedGrants(entries, scopeType, flag) {
|
|
23847
24532
|
return (entries ?? []).map((entry) => {
|
|
23848
24533
|
const at = entry.indexOf("="), scopeId = entry.slice(0, at), role = entry.slice(at + 1).trim();
|
|
@@ -23879,8 +24564,36 @@ async function runTaskCommand(command2, args2, context2) {
|
|
|
23879
24564
|
return { result: await start("azure.connect", { ...values.subscription ? { subscriptionId: values.subscription[0] } : {}, ...values.region ? { region: values.region[0] } : {} }), json: options.json };
|
|
23880
24565
|
case "azure reconnect":
|
|
23881
24566
|
return { result: await start("azure.elevate", { connectionId: connection(values) }), json: options.json };
|
|
23882
|
-
case "azure update-
|
|
23883
|
-
|
|
24567
|
+
case "azure update-runtime": {
|
|
24568
|
+
const id = connection(values);
|
|
24569
|
+
const alreadyRunning = (deployment) => upgradeInProgress(deployment?.upgrade) ? { result: { value: { state: "in-progress", exitCode: 0, upgrade: deployment.upgrade }, text: "An upgrade is already in progress.\n" + runtimeUpgradeText(deployment), exitCode: 0 }, json: options.json } : void 0;
|
|
24570
|
+
const current = await call2("/cloud-connections/" + id + "/runtime").catch(() => void 0);
|
|
24571
|
+
const running = alreadyRunning(current);
|
|
24572
|
+
if (running) return running;
|
|
24573
|
+
try {
|
|
24574
|
+
return { result: await start("azure.runtime_update", { connectionId: id }), json: options.json };
|
|
24575
|
+
} catch (error2) {
|
|
24576
|
+
if (error2?.code !== "runtime_upgrade_in_progress" && !String(error2?.message).includes("runtime_upgrade_in_progress")) throw error2;
|
|
24577
|
+
return alreadyRunning(await call2("/cloud-connections/" + id + "/runtime").catch(() => void 0)) ?? { result: { value: { state: "in-progress", exitCode: 0 }, text: "An upgrade is already in progress.", exitCode: 0 }, json: options.json };
|
|
24578
|
+
}
|
|
24579
|
+
}
|
|
24580
|
+
case "azure runtime-upgrade": {
|
|
24581
|
+
const deployment = await call2("/cloud-connections/" + connection(values) + "/runtime");
|
|
24582
|
+
return { result: { value: deployment, text: runtimeUpgradeText(deployment), exitCode: 0 }, json: options.json };
|
|
24583
|
+
}
|
|
24584
|
+
case "azure automatic-upgrades": {
|
|
24585
|
+
const id = connection(values);
|
|
24586
|
+
if (target !== void 0 && target !== "on" && target !== "off") throw new Error("Pass on or off, or nothing to show the setting: backify azure automatic-upgrades on|off --connection <id>.");
|
|
24587
|
+
const deployment = target === void 0 ? await call2("/cloud-connections/" + id + "/runtime") : await call2("/cloud-connections/" + id + "/runtime/automatic-upgrades", { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ enabled: target === "on" }) });
|
|
24588
|
+
const enabled = deployment.automaticUpgrades !== false;
|
|
24589
|
+
return { result: { value: { automaticUpgrades: enabled }, text: enabled ? "Automatic Runtime upgrades are on: compatible releases start their phased upgrade without approval. Releases that change Azure roles or templates, and major releases, still wait for approval." : "Automatic Runtime upgrades are off: each proposed upgrade waits for approval (backify azure update-runtime --connection <id>).", exitCode: 0 }, json: options.json };
|
|
24590
|
+
}
|
|
24591
|
+
case "azure grant-scope": {
|
|
24592
|
+
const scope = await call2("/cloud-connections/" + connection(values) + "/grant-scope");
|
|
24593
|
+
return { result: { value: scope, text: JSON.stringify(scope, null, 2), exitCode: 0 }, json: options.json };
|
|
24594
|
+
}
|
|
24595
|
+
case "azure rescope-grants":
|
|
24596
|
+
return { result: await start("azure.grant_rescope", { connectionId: connection(values) }), json: options.json };
|
|
23884
24597
|
case "azure uninstall":
|
|
23885
24598
|
return { result: await start("azure.uninstall", { connectionId: connection(values) }), json: options.json };
|
|
23886
24599
|
case "azure remove":
|
|
@@ -23890,6 +24603,12 @@ async function runTaskCommand(command2, args2, context2) {
|
|
|
23890
24603
|
const summary = await call2("/organizations/" + organizationId + "/summary");
|
|
23891
24604
|
return { result: { value: summary, text: JSON.stringify(summary, null, 2) }, json: options.json };
|
|
23892
24605
|
}
|
|
24606
|
+
case "org locations": {
|
|
24607
|
+
if (target === "set") return { result: await setLocations(call2, organizationId, values, options, context2), json: options.json };
|
|
24608
|
+
if (target) throw new Error("Use backify org locations [--workspace <id>], or backify org locations set.");
|
|
24609
|
+
const { organization: _organization, workspace: _workspace, ...view } = await readLocations(call2, organizationId, workspaceOption(values));
|
|
24610
|
+
return { result: { value: view, text: locationsText(view) }, json: options.json };
|
|
24611
|
+
}
|
|
23893
24612
|
case "billing":
|
|
23894
24613
|
case "billing show": {
|
|
23895
24614
|
const billing = await call2("/organizations/" + organizationId + "/billing");
|
|
@@ -23965,7 +24684,7 @@ async function runTaskCommand(command2, args2, context2) {
|
|
|
23965
24684
|
throw new Error("Unknown command.\n\n" + taskHelp);
|
|
23966
24685
|
}
|
|
23967
24686
|
}
|
|
23968
|
-
var taskHelp, purposes, connection;
|
|
24687
|
+
var taskHelp, purposes, upgradeEnded, upgradeInProgress, json, workspaceOption, connection;
|
|
23969
24688
|
var init_tasks = __esm({
|
|
23970
24689
|
"src/tasks.ts"() {
|
|
23971
24690
|
"use strict";
|
|
@@ -23980,11 +24699,22 @@ var init_tasks = __esm({
|
|
|
23980
24699
|
"",
|
|
23981
24700
|
" backify github connect Install or choose the Backify GitHub App (github.install)",
|
|
23982
24701
|
" backify azure connect [--subscription <id>] [--region <name>] Connect an Azure subscription (azure.connect)",
|
|
23983
|
-
" backify azure reconnect|update-
|
|
23984
|
-
" Renew authorization, approve
|
|
23985
|
-
"
|
|
23986
|
-
" azure.
|
|
24702
|
+
" backify azure reconnect|update-runtime|uninstall|remove --connection <id>",
|
|
24703
|
+
" Renew authorization, approve a proposed Runtime upgrade (applications are not",
|
|
24704
|
+
" redeployed; the previous version is kept until it is committed), uninstall the",
|
|
24705
|
+
" Runtime, or remove everything Backify created (azure.elevate, azure.runtime_update,",
|
|
24706
|
+
" azure.uninstall, azure.remove). update-runtime exits 0 with the current phase",
|
|
24707
|
+
" when an upgrade is already in progress.",
|
|
24708
|
+
" backify azure grant-scope --connection <id> [--json] Show the grant scope, proposed changes and latest re-scope operation",
|
|
24709
|
+
" backify azure rescope-grants --connection <id> Request Azure administrator review and approval of scoped grants",
|
|
24710
|
+
" backify azure runtime-upgrade --connection <id> [--json] Show the Runtime upgrade: phase, versions, verification, canary outcome, end state",
|
|
24711
|
+
" backify azure automatic-upgrades [on|off] --connection <id> Show or change automatic upgrades of compatible Runtime releases (on by default)",
|
|
23987
24712
|
" backify org Organization summary",
|
|
24713
|
+
" backify org locations [--workspace <id>] Default and allowed application locations, and the locations Backify Cloud",
|
|
24714
|
+
" or a connected cloud can host (only those can be allowed)",
|
|
24715
|
+
" backify org locations set [--workspace <id>] [--default <region>|--default inherit]",
|
|
24716
|
+
" [--allow <region> ...|--allow all|--allow inherit] [--yes]",
|
|
24717
|
+
" Change them; all and inherit follow the supported or organization locations",
|
|
23988
24718
|
" backify billing Subscription status",
|
|
23989
24719
|
" backify billing checkout|change-plan [--plan <plan>] [--interval <interval>] [--currency <currency>]",
|
|
23990
24720
|
" Review a subscription or plan change in the browser",
|
|
@@ -24002,7 +24732,8 @@ var init_tasks = __esm({
|
|
|
24002
24732
|
"github.install",
|
|
24003
24733
|
"azure.connect",
|
|
24004
24734
|
"azure.elevate",
|
|
24005
|
-
"azure.
|
|
24735
|
+
"azure.runtime_update",
|
|
24736
|
+
"azure.grant_rescope",
|
|
24006
24737
|
"azure.uninstall",
|
|
24007
24738
|
"azure.remove",
|
|
24008
24739
|
"approval",
|
|
@@ -24023,8 +24754,9 @@ var init_tasks = __esm({
|
|
|
24023
24754
|
"github.install": "connect GitHub",
|
|
24024
24755
|
"azure.connect": "connect Azure",
|
|
24025
24756
|
"azure.elevate": "renew Backify's Azure authorization",
|
|
24026
|
-
"azure.
|
|
24027
|
-
"azure.
|
|
24757
|
+
"azure.runtime_update": "approve the proposed Backify Runtime upgrade",
|
|
24758
|
+
"azure.grant_rescope": "review and approve scoped Azure grants",
|
|
24759
|
+
"azure.uninstall": "uninstall the Backify Runtime",
|
|
24028
24760
|
"azure.remove": "remove everything Backify created in Azure",
|
|
24029
24761
|
"approval": "approve or reject the request",
|
|
24030
24762
|
"sso.test_signin": "test single sign-on",
|
|
@@ -24038,6 +24770,14 @@ var init_tasks = __esm({
|
|
|
24038
24770
|
"billing.checkout": "review the subscription and complete Stripe Checkout",
|
|
24039
24771
|
"billing.change_plan": "review the plan change"
|
|
24040
24772
|
};
|
|
24773
|
+
upgradeEnded = (upgrade) => ["committed", "rolled-back", "failed"].includes(upgrade.phase);
|
|
24774
|
+
upgradeInProgress = (upgrade) => !!upgrade && !upgradeEnded(upgrade) && upgrade.state !== "awaiting-approval";
|
|
24775
|
+
json = { "content-type": "application/json" };
|
|
24776
|
+
workspaceOption = (values) => {
|
|
24777
|
+
const id = values.workspace?.[0];
|
|
24778
|
+
if (id !== void 0 && !isUuid(id)) throw new Error("--workspace takes a workspace ID (UUID).");
|
|
24779
|
+
return id;
|
|
24780
|
+
};
|
|
24041
24781
|
connection = (values) => {
|
|
24042
24782
|
const id = values.connection?.[0];
|
|
24043
24783
|
if (!id || !isUuid(id)) throw new Error("Pass --connection <cloud-connection-id>.");
|
|
@@ -24070,9 +24810,9 @@ function configureCodingTool(options) {
|
|
|
24070
24810
|
if (!codingTools.includes(options.agent)) throw new Error("Select --agent copilot, cursor, gemini, cline, or windsurf. Codex and Claude Code use the Backify plugin.");
|
|
24071
24811
|
const agent = options.agent, transport = options.transport ?? "http";
|
|
24072
24812
|
if (transport !== "http" && transport !== "stdio") throw new Error("Select --transport http or stdio.");
|
|
24073
|
-
const
|
|
24074
|
-
if (!
|
|
24075
|
-
const path = resolve5(options.root ?? process.cwd(),
|
|
24813
|
+
const relative5 = options.configPath ?? defaultPaths[agent];
|
|
24814
|
+
if (!relative5) throw new Error("Open this tool's MCP configuration and supply its exact path with --config. Backify will not guess or modify an editor's global storage.");
|
|
24815
|
+
const path = resolve5(options.root ?? process.cwd(), relative5);
|
|
24076
24816
|
for (let current = path; ; current = dirname5(current)) {
|
|
24077
24817
|
if (existsSync9(current) && (lstatSync4(current).isSymbolicLink() || current === path && !lstatSync4(current).isFile())) throw new Error("MCP configuration cannot traverse symlinks or replace a directory.");
|
|
24078
24818
|
if (dirname5(current) === current) break;
|
|
@@ -24119,6 +24859,131 @@ var init_coding_tools = __esm({
|
|
|
24119
24859
|
}
|
|
24120
24860
|
});
|
|
24121
24861
|
|
|
24862
|
+
// src/auth-identity.ts
|
|
24863
|
+
var auth_identity_exports = {};
|
|
24864
|
+
__export(auth_identity_exports, {
|
|
24865
|
+
authIdentityArguments: () => authIdentityArguments,
|
|
24866
|
+
authIdentityHelp: () => authIdentityHelp,
|
|
24867
|
+
identityFailureText: () => identityFailureText,
|
|
24868
|
+
identityStatusText: () => identityStatusText,
|
|
24869
|
+
resolveEnvironment: () => resolveEnvironment,
|
|
24870
|
+
runAuthIdentity: () => runAuthIdentity
|
|
24871
|
+
});
|
|
24872
|
+
function authIdentityArguments(args2) {
|
|
24873
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
24874
|
+
const { flags, values, positional } = parse(args2, "auth identity", ["--json"], ["--app", "--environment", "--confirm"]);
|
|
24875
|
+
const action = (positional[0] ?? "status").toLowerCase(), json3 = flags.has("--json");
|
|
24876
|
+
if (!["status", "move", "move-back", "clear"].includes(action) || positional.length > 1) throw new Error("Unknown auth identity command: " + positional.join(" ") + "\n\n" + authIdentityHelp);
|
|
24877
|
+
if (action === "status" && (values["--environment"] !== void 0 || values["--confirm"] !== void 0)) throw new Error("--environment and --confirm apply to auth identity move.");
|
|
24878
|
+
if (action === "clear" && values["--confirm"] !== void 0) throw new Error("--confirm applies to auth identity move and move-back.");
|
|
24879
|
+
if (action !== "status" && values["--environment"] === void 0) throw new Error("Name the environment to " + (action === "clear" ? "clear" : "move") + " with --environment <name|id>.");
|
|
24880
|
+
return { action, ...values["--environment"] !== void 0 ? { environment: values["--environment"] } : {}, ...values["--confirm"] !== void 0 ? { confirm: values["--confirm"] } : {}, json: json3 };
|
|
24881
|
+
}
|
|
24882
|
+
function pad3(rows) {
|
|
24883
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
24884
|
+
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ").trimEnd());
|
|
24885
|
+
}
|
|
24886
|
+
function identityStatusText(statuses, names = /* @__PURE__ */ new Map()) {
|
|
24887
|
+
if (!statuses.length) return "This application has no environments.";
|
|
24888
|
+
const name2 = (status) => names.get(status.environmentId) ?? status.kind;
|
|
24889
|
+
const rows = pad3([["ENVIRONMENT", "SIGN-IN DATA", "WAITING FOR RUNTIME"], ...statuses.map((status) => [name2(status), where(status.authority), status.pendingCommands ? status.pendingCommands + " change" + (status.pendingCommands === 1 ? "" : "s") + (status.oldestPendingAt ? " since " + status.oldestPendingAt : "") : "-"])]);
|
|
24890
|
+
const notes = statuses.flatMap((status) => {
|
|
24891
|
+
const relocation = status.relocation;
|
|
24892
|
+
if (status.authority === "relocating") return [name2(status) + ": moving sign-in data. Sign-in for this environment and user management for the application are paused."];
|
|
24893
|
+
if (status.authority === "returning") return [name2(status) + ": moving sign-in data back to Backify. Sign-in for this environment and user management for the application are paused."];
|
|
24894
|
+
const back = relocation?.direction === "to-control-plane";
|
|
24895
|
+
const reason = (code) => (identityFailureText[code ?? ""] ?? "Nothing was changed.") + (code ? " (" + code + ")" : "");
|
|
24896
|
+
if (relocation?.state === "failed" && back && status.authority === "environment") return [name2(status) + ": the last move back to Backify did not finish. " + reason(relocation.failureCode)];
|
|
24897
|
+
if (relocation?.state === "failed" && !back && status.authority !== "environment") {
|
|
24898
|
+
if (relocation.clearedAt) return [];
|
|
24899
|
+
if (relocation.clearRequestedAt) return [name2(status) + ": clearing what the failed move left in the environment's database."];
|
|
24900
|
+
return [name2(status) + ": the last move did not finish. " + reason(relocation.failureCode) + " Clear it with: backify auth identity clear --environment " + name2(status)];
|
|
24901
|
+
}
|
|
24902
|
+
return [];
|
|
24903
|
+
});
|
|
24904
|
+
const waiting = statuses.some((status) => status.pendingCommands > 0) ? ["Role and session changes wait until the Runtime applies them, usually within about 30 seconds, and stay waiting while the Runtime is unreachable."] : [];
|
|
24905
|
+
return [...rows, ...notes.length || waiting.length ? [""] : [], ...notes, ...waiting].join("\n");
|
|
24906
|
+
}
|
|
24907
|
+
function resolveEnvironment(input, environments, statuses) {
|
|
24908
|
+
const wanted = input.trim().toLowerCase();
|
|
24909
|
+
const matches = statuses.filter((status) => {
|
|
24910
|
+
const named = environments.find((value) => value.id === status.environmentId);
|
|
24911
|
+
const labels = [status.environmentId, status.kind, named?.name, named?.kind, status.kind === "live" ? "production" : void 0].filter((value) => Boolean(value)).map((value) => value.toLowerCase());
|
|
24912
|
+
return labels.includes(wanted);
|
|
24913
|
+
});
|
|
24914
|
+
if (matches.length === 1) return matches[0];
|
|
24915
|
+
const available = statuses.map((status) => environments.find((value) => value.id === status.environmentId)?.name ?? status.kind).join(", ");
|
|
24916
|
+
throw new CommandError((matches.length ? "More than one environment matches " : "No environment matches ") + input + ". Use an environment name or ID" + (available ? " (" + available + ")" : "") + ".", "environment_not_found", { environment: input });
|
|
24917
|
+
}
|
|
24918
|
+
async function runAuthIdentity(call2, applicationId, options) {
|
|
24919
|
+
if (!uuid10.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
24920
|
+
const prefix = "/apps/" + applicationId, base = prefix + "/auth/identity";
|
|
24921
|
+
const statuses = await call2(base);
|
|
24922
|
+
const environments = await call2(prefix + "/environments").catch(() => []);
|
|
24923
|
+
const names = new Map(environments.map((value) => [value.id, value.name]));
|
|
24924
|
+
if (options.action === "status") return { value: statuses, text: identityStatusText(statuses, names) };
|
|
24925
|
+
const target = resolveEnvironment(options.environment, environments, statuses), label = names.get(target.environmentId) ?? target.kind;
|
|
24926
|
+
if (target.authority === "relocating" || target.authority === "returning") throw new CommandError("Sign-in data for " + label + " is already being moved.", "identity_relocation_in_progress", { environmentId: target.environmentId });
|
|
24927
|
+
if (options.action === "clear") {
|
|
24928
|
+
const relocation2 = await call2(base + "/clear", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ environmentId: target.environmentId }) });
|
|
24929
|
+
return {
|
|
24930
|
+
value: { status: relocation2.clearedAt ? "cleared" : "clearing", environmentId: target.environmentId, relocation: relocation2 },
|
|
24931
|
+
text: relocation2.clearedAt ? "What the failed move left in " + label + "'s database is already cleared." : "Clearing what the failed move left in " + label + "'s database. Sign-in for " + label + " stays with Backify.\nCheck progress with: backify auth identity"
|
|
24932
|
+
};
|
|
24933
|
+
}
|
|
24934
|
+
if (options.action === "move-back") {
|
|
24935
|
+
if (target.authority !== "environment") throw new CommandError("Sign-in data for " + label + " is already kept by Backify.", "identity_move_back_not_needed", { environmentId: target.environmentId });
|
|
24936
|
+
const slug2 = (await call2(prefix)).slug;
|
|
24937
|
+
if (!options.confirm || options.confirm !== slug2) {
|
|
24938
|
+
const summary = "Moving sign-in data for " + label + " back to Backify pauses sign-in for that environment and user management for the application while the data is moved. Users, roles, passkeys and signed-in sessions are kept. Afterwards, sign-in for " + label + " stops working while Backify is unavailable.";
|
|
24939
|
+
throw new CommandError((options.confirm ? "The confirmation does not match the application slug. " : "") + summary + "\nConfirm with the application slug: backify auth identity move-back --environment " + options.environment + " --confirm " + (slug2 ?? "<application-slug>"), options.confirm ? "confirmation_mismatch" : "confirmation_required", slug2 ? { confirm: slug2 } : {});
|
|
24940
|
+
}
|
|
24941
|
+
const relocation2 = await call2(base + "/move-back", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ environmentId: target.environmentId }) });
|
|
24942
|
+
return { value: { status: "moving-back", environmentId: target.environmentId, relocation: relocation2 }, text: ["Moving sign-in data for " + label + " back to Backify.", "Sign-in for this environment and user management for the application are paused until it finishes, usually within a minute.", "Check progress with: backify auth identity"].join("\n") };
|
|
24943
|
+
}
|
|
24944
|
+
if (target.authority === "relocating") throw new CommandError("Sign-in data for " + label + " is already being moved.", "identity_relocation_in_progress", { environmentId: target.environmentId });
|
|
24945
|
+
if (target.authority === "environment") throw new CommandError("Sign-in data for " + label + " is already in its own database.", "identity_relocation_not_needed", { environmentId: target.environmentId });
|
|
24946
|
+
const slug = (await call2(prefix)).slug;
|
|
24947
|
+
if (!options.confirm || options.confirm !== slug) {
|
|
24948
|
+
const summary = "Moving sign-in data for " + label + " pauses sign-in for that environment and user management for the application while the data is moved. It can be moved back later with backify auth identity move-back. Afterwards, sign-in for " + label + " keeps working if Backify is unavailable.";
|
|
24949
|
+
throw new CommandError((options.confirm ? "The confirmation does not match the application slug. " : "") + summary + "\nConfirm with the application slug: backify auth identity move --environment " + options.environment + " --confirm " + (slug ?? "<application-slug>"), options.confirm ? "confirmation_mismatch" : "confirmation_required", slug ? { confirm: slug } : {});
|
|
24950
|
+
}
|
|
24951
|
+
const relocation = await call2(base + "/relocate", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ environmentId: target.environmentId }) });
|
|
24952
|
+
return { value: { status: "moving", environmentId: target.environmentId, relocation }, text: ["Moving sign-in data for " + label + ": " + relocation.users + " users, " + relocation.links + " linked identities, " + relocation.passkeys + " passkeys, " + relocation.sessions + " sessions.", "Sign-in for this environment and user management for the application are paused until it finishes, usually within a minute.", "Check progress with: backify auth identity"].join("\n") };
|
|
24953
|
+
}
|
|
24954
|
+
var authIdentityHelp, uuid10, where, identityFailureText;
|
|
24955
|
+
var init_auth_identity = __esm({
|
|
24956
|
+
"src/auth-identity.ts"() {
|
|
24957
|
+
"use strict";
|
|
24958
|
+
init_release_flow();
|
|
24959
|
+
authIdentityHelp = [
|
|
24960
|
+
"Usage: backify auth identity [options]",
|
|
24961
|
+
" backify auth identity move --environment <name|id> --confirm <application-slug> [options]",
|
|
24962
|
+
" backify auth identity move-back --environment <name|id> --confirm <application-slug> [options]",
|
|
24963
|
+
" backify auth identity clear --environment <name|id> [options]",
|
|
24964
|
+
"",
|
|
24965
|
+
" backify auth identity Where each environment's sign-in data lives (Backify or the environment's database),",
|
|
24966
|
+
" changes still waiting for the Runtime and the latest move",
|
|
24967
|
+
" backify auth identity move Move one environment's sign-in data (users, roles, passkeys, sessions) into its own database",
|
|
24968
|
+
" backify auth identity move-back Move it back from the environment's database to Backify, keeping users, roles, links and sessions",
|
|
24969
|
+
" backify auth identity clear Clear what a failed move left in the environment's database (sign-in stays with Backify)",
|
|
24970
|
+
"",
|
|
24971
|
+
"Options: --app <application> (default: the application in this folder) --json (machine-readable output and errors)",
|
|
24972
|
+
"Moving and clearing need permission to manage access. While the data is moved, sign-in for that environment and user management",
|
|
24973
|
+
"for the application pause. In the environment's database, sign-in keeps working if Backify is unavailable; moved back, it does not.",
|
|
24974
|
+
"Moving back is refused while a handoff or hosting move is active. Without --confirm a move changes nothing and prints the slug to confirm with."
|
|
24975
|
+
].join("\n");
|
|
24976
|
+
uuid10 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
24977
|
+
where = (authority) => authority === "environment" ? "this environment's database" : authority === "relocating" ? "moving to this environment's database" : authority === "returning" ? "moving back to Backify" : "Backify";
|
|
24978
|
+
identityFailureText = {
|
|
24979
|
+
identity_relocation_mismatch: "The moved data did not match what Backify holds, so nothing was changed.",
|
|
24980
|
+
identity_relocation_source_changed: "Sign-in data changed while it was being moved, so nothing was changed.",
|
|
24981
|
+
identity_relocation_too_large: "The application has more sign-in data than one move can carry.",
|
|
24982
|
+
identity_relocation_conflict: "Some of the moved data belongs to another application, so nothing was changed."
|
|
24983
|
+
};
|
|
24984
|
+
}
|
|
24985
|
+
});
|
|
24986
|
+
|
|
24122
24987
|
// src/app/project.ts
|
|
24123
24988
|
var project_exports = {};
|
|
24124
24989
|
__export(project_exports, {
|
|
@@ -24364,8 +25229,8 @@ function analyzeAppDeclarations(files) {
|
|
|
24364
25229
|
continue;
|
|
24365
25230
|
const source = ts2.createSourceFile(path, file.content, ts2.ScriptTarget.Latest, true, /\.[jt]sx$/.test(path) ? ts2.ScriptKind.TSX : ts2.ScriptKind.TS);
|
|
24366
25231
|
const report = (node2, severity, code, message) => {
|
|
24367
|
-
const { line, character } = source.getLineAndCharacterOfPosition(node2.getStart(source));
|
|
24368
|
-
diagnostics.push({ severity, code, message, file: path, line:
|
|
25232
|
+
const { line: line2, character } = source.getLineAndCharacterOfPosition(node2.getStart(source));
|
|
25233
|
+
diagnostics.push({ severity, code, message, file: path, line: line2 + 1, column: character + 1, docs: DOCS });
|
|
24369
25234
|
};
|
|
24370
25235
|
const imported = /* @__PURE__ */ new Map();
|
|
24371
25236
|
const namespaces = /* @__PURE__ */ new Set();
|
|
@@ -24612,32 +25477,32 @@ function analyzeFile(file, used, diagnostics, wrappers) {
|
|
|
24612
25477
|
if (!element.isTypeOnly)
|
|
24613
25478
|
bind(element.name, memberReference(base, (element.propertyName ?? element.name).text));
|
|
24614
25479
|
}
|
|
24615
|
-
const
|
|
25480
|
+
const resolve10 = (node2) => {
|
|
24616
25481
|
if (ts3.isParenthesizedExpression(node2) || ts3.isAsExpression(node2) || ts3.isNonNullExpression(node2) || ts3.isAwaitExpression(node2) || ts3.isSatisfiesExpression(node2))
|
|
24617
|
-
return
|
|
25482
|
+
return resolve10(node2.expression);
|
|
24618
25483
|
if (ts3.isIdentifier(node2)) {
|
|
24619
25484
|
const value = symbol(node2);
|
|
24620
25485
|
return value ? references.get(value) : void 0;
|
|
24621
25486
|
}
|
|
24622
25487
|
if (ts3.isPropertyAccessExpression(node2))
|
|
24623
|
-
return memberReference(
|
|
25488
|
+
return memberReference(resolve10(node2.expression), node2.name.text);
|
|
24624
25489
|
if (ts3.isElementAccessExpression(node2) && ts3.isStringLiteralLike(node2.argumentExpression))
|
|
24625
|
-
return memberReference(
|
|
25490
|
+
return memberReference(resolve10(node2.expression), node2.argumentExpression.text);
|
|
24626
25491
|
if (ts3.isCallExpression(node2)) {
|
|
24627
25492
|
const loaded = loadedModule(node2);
|
|
24628
25493
|
if (loaded !== void 0)
|
|
24629
25494
|
return loaded === null ? void 0 : moduleReference(loaded);
|
|
24630
|
-
return
|
|
25495
|
+
return resolve10(node2.expression)?.kind === "factory" ? { kind: "root" } : void 0;
|
|
24631
25496
|
}
|
|
24632
25497
|
return void 0;
|
|
24633
25498
|
};
|
|
24634
25499
|
const capability2 = (node2) => {
|
|
24635
|
-
const reference =
|
|
25500
|
+
const reference = resolve10(node2);
|
|
24636
25501
|
return reference?.kind === "capability" ? reference.capability : void 0;
|
|
24637
25502
|
};
|
|
24638
25503
|
const collect = (node2) => {
|
|
24639
25504
|
if (ts3.isVariableDeclaration(node2) && node2.initializer) {
|
|
24640
|
-
const base =
|
|
25505
|
+
const base = resolve10(node2.initializer);
|
|
24641
25506
|
if (base && ts3.isIdentifier(node2.name))
|
|
24642
25507
|
bind(node2.name, base);
|
|
24643
25508
|
else if (base && ts3.isObjectBindingPattern(node2.name))
|
|
@@ -24713,8 +25578,8 @@ var init_dist3 = __esm({
|
|
|
24713
25578
|
sdkCapability = (name2) => Object.hasOwn(SDK_IMPORT_CAPABILITIES, name2) ? SDK_IMPORT_CAPABILITIES[name2] : void 0;
|
|
24714
25579
|
modulePath = (path) => posix.normalize(path.replaceAll("\\", "/")).replace(/\.[cm]?[jt]sx?$/, "").replace(/\/index$/, "");
|
|
24715
25580
|
position = (source, node2) => {
|
|
24716
|
-
const { line, character } = source.getLineAndCharacterOfPosition(node2.getStart(source));
|
|
24717
|
-
return { line:
|
|
25581
|
+
const { line: line2, character } = source.getLineAndCharacterOfPosition(node2.getStart(source));
|
|
25582
|
+
return { line: line2 + 1, column: character + 1 };
|
|
24718
25583
|
};
|
|
24719
25584
|
}
|
|
24720
25585
|
});
|
|
@@ -24771,9 +25636,9 @@ async function generateLockfile(root) {
|
|
|
24771
25636
|
warnings.push(...declarations.warnings);
|
|
24772
25637
|
const result = await runNode(["--enable-source-maps", runner, "describe", bundle.file], { cwd: root, env: isolatedEnv({ BACKIFY_PROCESS_ROLE: "describe", BACKIFY_HEALTH_PATH: config2.server.health ?? "/healthz" }) });
|
|
24773
25638
|
if (result.code !== 0) throw new ProjectError("Describing the server failed. Declarations must run at module top level without connecting to databases or services.\n" + (result.stderr || result.stdout).trim().split("\n").slice(-15).join("\n"));
|
|
24774
|
-
const
|
|
25639
|
+
const line2 = result.stdout.trim().split("\n").at(-1) ?? "";
|
|
24775
25640
|
try {
|
|
24776
|
-
catalog = JSON.parse(
|
|
25641
|
+
catalog = JSON.parse(line2);
|
|
24777
25642
|
} catch {
|
|
24778
25643
|
throw new ProjectError("backify-run describe printed unexpected output:\n" + result.stdout.slice(-2e3));
|
|
24779
25644
|
}
|
|
@@ -24787,8 +25652,8 @@ async function generateLockfile(root) {
|
|
|
24787
25652
|
if (used.has("events") || catalog.jobs.length) capabilities.add("database");
|
|
24788
25653
|
const needsConfig = { storage: "storage.buckets", ai: "ai", mail: "mail", http: "http.allow", integrations: "integrations", secrets: "secrets", database: "database", protection: "protection" };
|
|
24789
25654
|
for (const capability2 of used) {
|
|
24790
|
-
const
|
|
24791
|
-
if (
|
|
25655
|
+
const where2 = needsConfig[capability2];
|
|
25656
|
+
if (where2 && !configuredCapabilities(config2).includes(capability2) && !(capability2 === "database" && capabilities.has("jobs"))) problems.push(`Server code uses ${capability2} but backify.config.ts does not configure ${where2}`);
|
|
24792
25657
|
}
|
|
24793
25658
|
if (config2.server && !catalog.backend && config2.kind !== "worker") problems.push(`A ${config2.kind} app needs a backend: call defineBackend() in ${config2.server.entry}`);
|
|
24794
25659
|
if (config2.kind === "worker" && catalog.backend) problems.push('Worker apps cannot declare a backend; use kind "api" instead');
|
|
@@ -24810,7 +25675,7 @@ async function generateLockfile(root) {
|
|
|
24810
25675
|
extensions: config2.database?.extensions?.length ? [...config2.database.extensions].sort() : void 0,
|
|
24811
25676
|
personalData: config2.database?.personalData ? normalizePersonalData(config2.database.personalData) : void 0
|
|
24812
25677
|
} : void 0,
|
|
24813
|
-
auth: config2.auth ? { providers: [...config2.auth.providers], roles: [...config2.auth.roles ?? []].sort() } : void 0,
|
|
25678
|
+
auth: config2.auth ? { providers: [...config2.auth.providers], defaultProvider: config2.auth.defaultProvider, roles: [...config2.auth.roles ?? []].sort(), session: lockSession(config2.auth.session) } : void 0,
|
|
24814
25679
|
config: config2.config,
|
|
24815
25680
|
ai: config2.ai,
|
|
24816
25681
|
http: config2.http,
|
|
@@ -24830,6 +25695,10 @@ async function generateLockfile(root) {
|
|
|
24830
25695
|
problems.push(...validateLockfile(lockfile));
|
|
24831
25696
|
return { lockfile, text: serializeLockfile(lockfile), problems, warnings };
|
|
24832
25697
|
}
|
|
25698
|
+
function lockSession(session) {
|
|
25699
|
+
if (session?.duration === void 0 && session?.refresh === void 0) return void 0;
|
|
25700
|
+
return { duration: session.duration, refresh: session.refresh };
|
|
25701
|
+
}
|
|
24833
25702
|
function personalDataWarnings(root, config2, declared) {
|
|
24834
25703
|
const directory = join14(root, config2.database?.migrations ?? "db/migrations");
|
|
24835
25704
|
const files = existsSync11(directory) ? readdirSync4(directory).filter((f) => f.endsWith(".sql")).sort().map((file) => ({ file: (config2.database?.migrations ?? "db/migrations") + "/" + file, sql: readFileSync16(join14(directory, file), "utf8") })) : [];
|
|
@@ -24846,8 +25715,8 @@ function personalDataWarnings(root, config2, declared) {
|
|
|
24846
25715
|
byTable.set(table, [...byTable.get(table) ?? [], column]);
|
|
24847
25716
|
}
|
|
24848
25717
|
for (const [table, columns] of byTable) {
|
|
24849
|
-
const
|
|
24850
|
-
warnings.push(`${
|
|
25718
|
+
const where2 = schema.tables.get(table)?.find((c) => c.name === columns[0]);
|
|
25719
|
+
warnings.push(`${where2 ? `${where2.file}:${where2.line}: ` : ""}${columns.map((c) => table + "." + c).join(", ")} may hold personal data but ${columns.length === 1 ? "is" : "are"} not declared. If so, add to database.personalData: ${declared.some((t) => t.table === table) ? `the column${columns.length === 1 ? "" : "s"} under ${table}.columns` : personalDataSnippet(table, columns)}`);
|
|
24851
25720
|
}
|
|
24852
25721
|
return warnings;
|
|
24853
25722
|
}
|
|
@@ -24896,10 +25765,10 @@ import { spawn as spawn2 } from "node:child_process";
|
|
|
24896
25765
|
import { existsSync as existsSync12, readFileSync as readFileSync17 } from "node:fs";
|
|
24897
25766
|
import { join as join15 } from "node:path";
|
|
24898
25767
|
function runScript(root, script) {
|
|
24899
|
-
return new Promise((
|
|
25768
|
+
return new Promise((resolve10) => {
|
|
24900
25769
|
const child = spawn2(process.platform === "win32" ? "npm.cmd" : "npm", ["run", script], { cwd: root, stdio: "inherit", shell: process.platform === "win32" });
|
|
24901
|
-
child.on("close", (code) =>
|
|
24902
|
-
child.on("error", () =>
|
|
25770
|
+
child.on("close", (code) => resolve10(code ?? 1));
|
|
25771
|
+
child.on("error", () => resolve10(1));
|
|
24903
25772
|
});
|
|
24904
25773
|
}
|
|
24905
25774
|
async function checkCommand(root, options = {}) {
|
|
@@ -25176,7 +26045,7 @@ var require_postgres_interval = __commonJS({
|
|
|
25176
26045
|
if (!(this instanceof PostgresInterval)) {
|
|
25177
26046
|
return new PostgresInterval(raw);
|
|
25178
26047
|
}
|
|
25179
|
-
extend2(this,
|
|
26048
|
+
extend2(this, parse4(raw));
|
|
25180
26049
|
}
|
|
25181
26050
|
var properties = ["seconds", "minutes", "hours", "days", "months", "years"];
|
|
25182
26051
|
PostgresInterval.prototype.toPostgres = function() {
|
|
@@ -25237,7 +26106,7 @@ var require_postgres_interval = __commonJS({
|
|
|
25237
26106
|
var microseconds = fraction + "000000".slice(fraction.length);
|
|
25238
26107
|
return parseInt(microseconds, 10) / 1e3;
|
|
25239
26108
|
}
|
|
25240
|
-
function
|
|
26109
|
+
function parse4(interval) {
|
|
25241
26110
|
if (!interval) return {};
|
|
25242
26111
|
var matches = INTERVAL.exec(interval);
|
|
25243
26112
|
var isNegative = matches[8] === "-";
|
|
@@ -25511,7 +26380,7 @@ var require_pg_int8 = __commonJS({
|
|
|
25511
26380
|
var carry;
|
|
25512
26381
|
var t;
|
|
25513
26382
|
var digits;
|
|
25514
|
-
var
|
|
26383
|
+
var pad5;
|
|
25515
26384
|
var l;
|
|
25516
26385
|
var i;
|
|
25517
26386
|
{
|
|
@@ -25523,12 +26392,12 @@ var require_pg_int8 = __commonJS({
|
|
|
25523
26392
|
if (low === 0 && high === 0) {
|
|
25524
26393
|
return sign + digits + result;
|
|
25525
26394
|
}
|
|
25526
|
-
|
|
26395
|
+
pad5 = "";
|
|
25527
26396
|
l = 6 - digits.length;
|
|
25528
26397
|
for (i = 0; i < l; i++) {
|
|
25529
|
-
|
|
26398
|
+
pad5 += "0";
|
|
25530
26399
|
}
|
|
25531
|
-
result =
|
|
26400
|
+
result = pad5 + digits + result;
|
|
25532
26401
|
}
|
|
25533
26402
|
{
|
|
25534
26403
|
carry = high % BASE;
|
|
@@ -25539,12 +26408,12 @@ var require_pg_int8 = __commonJS({
|
|
|
25539
26408
|
if (low === 0 && high === 0) {
|
|
25540
26409
|
return sign + digits + result;
|
|
25541
26410
|
}
|
|
25542
|
-
|
|
26411
|
+
pad5 = "";
|
|
25543
26412
|
l = 6 - digits.length;
|
|
25544
26413
|
for (i = 0; i < l; i++) {
|
|
25545
|
-
|
|
26414
|
+
pad5 += "0";
|
|
25546
26415
|
}
|
|
25547
|
-
result =
|
|
26416
|
+
result = pad5 + digits + result;
|
|
25548
26417
|
}
|
|
25549
26418
|
{
|
|
25550
26419
|
carry = high % BASE;
|
|
@@ -25555,12 +26424,12 @@ var require_pg_int8 = __commonJS({
|
|
|
25555
26424
|
if (low === 0 && high === 0) {
|
|
25556
26425
|
return sign + digits + result;
|
|
25557
26426
|
}
|
|
25558
|
-
|
|
26427
|
+
pad5 = "";
|
|
25559
26428
|
l = 6 - digits.length;
|
|
25560
26429
|
for (i = 0; i < l; i++) {
|
|
25561
|
-
|
|
26430
|
+
pad5 += "0";
|
|
25562
26431
|
}
|
|
25563
|
-
result =
|
|
26432
|
+
result = pad5 + digits + result;
|
|
25564
26433
|
}
|
|
25565
26434
|
{
|
|
25566
26435
|
carry = high % BASE;
|
|
@@ -25724,13 +26593,13 @@ var require_binaryParsers = __commonJS({
|
|
|
25724
26593
|
console.log("ERROR: ElementType not implemented: " + elementType2);
|
|
25725
26594
|
}
|
|
25726
26595
|
};
|
|
25727
|
-
var
|
|
26596
|
+
var parse4 = function(dimension, elementType2) {
|
|
25728
26597
|
var array2 = [];
|
|
25729
26598
|
var i2;
|
|
25730
26599
|
if (dimension.length > 1) {
|
|
25731
26600
|
var count = dimension.shift();
|
|
25732
26601
|
for (i2 = 0; i2 < count; i2++) {
|
|
25733
|
-
array2[i2] =
|
|
26602
|
+
array2[i2] = parse4(dimension, elementType2);
|
|
25734
26603
|
}
|
|
25735
26604
|
dimension.unshift(count);
|
|
25736
26605
|
} else {
|
|
@@ -25740,7 +26609,7 @@ var require_binaryParsers = __commonJS({
|
|
|
25740
26609
|
}
|
|
25741
26610
|
return array2;
|
|
25742
26611
|
};
|
|
25743
|
-
return
|
|
26612
|
+
return parse4(dims, elementType);
|
|
25744
26613
|
};
|
|
25745
26614
|
var parseText = function(value) {
|
|
25746
26615
|
return value.toString("utf8");
|
|
@@ -26123,7 +26992,7 @@ var require_utils3 = __commonJS({
|
|
|
26123
26992
|
postgresMd5PasswordHash,
|
|
26124
26993
|
randomBytes: randomBytes6,
|
|
26125
26994
|
deriveKey,
|
|
26126
|
-
sha256:
|
|
26995
|
+
sha256: sha2563,
|
|
26127
26996
|
hashByName,
|
|
26128
26997
|
hmacSha256,
|
|
26129
26998
|
md5
|
|
@@ -26148,7 +27017,7 @@ var require_utils3 = __commonJS({
|
|
|
26148
27017
|
const outer = await md5(Buffer.concat([Buffer.from(inner), salt]));
|
|
26149
27018
|
return "md5" + outer;
|
|
26150
27019
|
}
|
|
26151
|
-
async function
|
|
27020
|
+
async function sha2563(text2) {
|
|
26152
27021
|
return await subtleCrypto.digest("SHA-256", text2);
|
|
26153
27022
|
}
|
|
26154
27023
|
async function hashByName(hashName, text2) {
|
|
@@ -26503,7 +27372,7 @@ var require_type_overrides = __commonJS({
|
|
|
26503
27372
|
var require_pg_connection_string = __commonJS({
|
|
26504
27373
|
"../../node_modules/pg-connection-string/index.js"(exports, module) {
|
|
26505
27374
|
"use strict";
|
|
26506
|
-
function
|
|
27375
|
+
function parse4(str, options = {}) {
|
|
26507
27376
|
if (str.charAt(0) === "/") {
|
|
26508
27377
|
const config3 = str.split(" ");
|
|
26509
27378
|
return { host: config3[0], database: config3[1] };
|
|
@@ -26665,7 +27534,7 @@ var require_pg_connection_string = __commonJS({
|
|
|
26665
27534
|
return poolConfig;
|
|
26666
27535
|
}
|
|
26667
27536
|
function parseIntoClientConfig(str) {
|
|
26668
|
-
return toClientConfig(
|
|
27537
|
+
return toClientConfig(parse4(str));
|
|
26669
27538
|
}
|
|
26670
27539
|
function deprecatedSslModeWarning(sslmode) {
|
|
26671
27540
|
if (!deprecatedSslModeWarning.warned && typeof process !== "undefined" && process.emitWarning) {
|
|
@@ -26680,10 +27549,10 @@ To prepare for this change:
|
|
|
26680
27549
|
See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.`);
|
|
26681
27550
|
}
|
|
26682
27551
|
}
|
|
26683
|
-
module.exports =
|
|
26684
|
-
|
|
26685
|
-
|
|
26686
|
-
|
|
27552
|
+
module.exports = parse4;
|
|
27553
|
+
parse4.parse = parse4;
|
|
27554
|
+
parse4.toClientConfig = toClientConfig;
|
|
27555
|
+
parse4.parseIntoClientConfig = parseIntoClientConfig;
|
|
26687
27556
|
}
|
|
26688
27557
|
});
|
|
26689
27558
|
|
|
@@ -26693,7 +27562,7 @@ var require_connection_parameters = __commonJS({
|
|
|
26693
27562
|
"use strict";
|
|
26694
27563
|
var dns = __require("dns");
|
|
26695
27564
|
var defaults2 = require_defaults2();
|
|
26696
|
-
var
|
|
27565
|
+
var parse4 = require_pg_connection_string().parse;
|
|
26697
27566
|
var val = function(key, config2, envVar) {
|
|
26698
27567
|
if (config2[key]) {
|
|
26699
27568
|
return config2[key];
|
|
@@ -26731,9 +27600,9 @@ var require_connection_parameters = __commonJS({
|
|
|
26731
27600
|
};
|
|
26732
27601
|
var ConnectionParameters = class {
|
|
26733
27602
|
constructor(config2) {
|
|
26734
|
-
config2 = typeof config2 === "string" ?
|
|
27603
|
+
config2 = typeof config2 === "string" ? parse4(config2) : config2 || {};
|
|
26735
27604
|
if (config2.connectionString) {
|
|
26736
|
-
config2 = Object.assign({}, config2,
|
|
27605
|
+
config2 = Object.assign({}, config2, parse4(config2.connectionString));
|
|
26737
27606
|
}
|
|
26738
27607
|
this.user = val("user", config2);
|
|
26739
27608
|
this.database = val("database", config2);
|
|
@@ -27459,7 +28328,7 @@ var require_serializer = __commonJS({
|
|
|
27459
28328
|
);
|
|
27460
28329
|
};
|
|
27461
28330
|
var emptyArray = [];
|
|
27462
|
-
var
|
|
28331
|
+
var parse4 = (query2) => {
|
|
27463
28332
|
const name2 = query2.name || "";
|
|
27464
28333
|
if (name2.length > 63) {
|
|
27465
28334
|
console.error("Warning! Postgres only supports 63 characters for query names.");
|
|
@@ -27606,7 +28475,7 @@ var require_serializer = __commonJS({
|
|
|
27606
28475
|
sendSASLInitialResponseMessage,
|
|
27607
28476
|
sendSCRAMClientFinalMessage,
|
|
27608
28477
|
query,
|
|
27609
|
-
parse:
|
|
28478
|
+
parse: parse4,
|
|
27610
28479
|
bind,
|
|
27611
28480
|
execute,
|
|
27612
28481
|
describe: describe2,
|
|
@@ -27995,7 +28864,7 @@ var require_dist2 = __commonJS({
|
|
|
27995
28864
|
"use strict";
|
|
27996
28865
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27997
28866
|
exports.DatabaseError = exports.serialize = void 0;
|
|
27998
|
-
exports.parse =
|
|
28867
|
+
exports.parse = parse4;
|
|
27999
28868
|
var messages_1 = require_messages();
|
|
28000
28869
|
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function() {
|
|
28001
28870
|
return messages_1.DatabaseError;
|
|
@@ -28005,10 +28874,10 @@ var require_dist2 = __commonJS({
|
|
|
28005
28874
|
return serializer_1.serialize;
|
|
28006
28875
|
} });
|
|
28007
28876
|
var parser_1 = require_parser();
|
|
28008
|
-
function
|
|
28877
|
+
function parse4(stream, callback) {
|
|
28009
28878
|
const parser = new parser_1.Parser();
|
|
28010
28879
|
stream.on("data", (buffer) => parser.parse(buffer, callback));
|
|
28011
|
-
return new Promise((
|
|
28880
|
+
return new Promise((resolve10) => stream.on("end", () => resolve10()));
|
|
28012
28881
|
}
|
|
28013
28882
|
}
|
|
28014
28883
|
});
|
|
@@ -28093,7 +28962,7 @@ var require_connection = __commonJS({
|
|
|
28093
28962
|
"../../node_modules/pg/lib/connection.js"(exports, module) {
|
|
28094
28963
|
"use strict";
|
|
28095
28964
|
var EventEmitter = __require("events").EventEmitter;
|
|
28096
|
-
var { parse:
|
|
28965
|
+
var { parse: parse4, serialize } = require_dist2();
|
|
28097
28966
|
var stream = require_stream();
|
|
28098
28967
|
var { getStream } = stream;
|
|
28099
28968
|
var flushBuffer = serialize.flush();
|
|
@@ -28199,7 +29068,7 @@ var require_connection = __commonJS({
|
|
|
28199
29068
|
self.emit("sslconnect");
|
|
28200
29069
|
}
|
|
28201
29070
|
attachListeners(stream2) {
|
|
28202
|
-
|
|
29071
|
+
parse4(stream2, (msg) => {
|
|
28203
29072
|
const eventName = msg.name === "error" ? "errorMessage" : msg.name;
|
|
28204
29073
|
if (this._emitMessage) {
|
|
28205
29074
|
this.emit("message", msg);
|
|
@@ -28468,8 +29337,8 @@ var require_helper = __commonJS({
|
|
|
28468
29337
|
module.exports.getPassword = function(connInfo, stream, cb) {
|
|
28469
29338
|
var pass;
|
|
28470
29339
|
var lineStream = stream.pipe(split());
|
|
28471
|
-
function onLine(
|
|
28472
|
-
var entry = parseLine(
|
|
29340
|
+
function onLine(line2) {
|
|
29341
|
+
var entry = parseLine(line2);
|
|
28473
29342
|
if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
|
|
28474
29343
|
pass = entry[passKey];
|
|
28475
29344
|
lineStream.end();
|
|
@@ -28487,8 +29356,8 @@ var require_helper = __commonJS({
|
|
|
28487
29356
|
stream.on("error", onErr);
|
|
28488
29357
|
lineStream.on("data", onLine).on("end", onEnd).on("error", onErr);
|
|
28489
29358
|
};
|
|
28490
|
-
var parseLine = module.exports.parseLine = function(
|
|
28491
|
-
if (
|
|
29359
|
+
var parseLine = module.exports.parseLine = function(line2) {
|
|
29360
|
+
if (line2.length < 11 || line2.match(/^\s+#/)) {
|
|
28492
29361
|
return null;
|
|
28493
29362
|
}
|
|
28494
29363
|
var curChar = "";
|
|
@@ -28499,15 +29368,15 @@ var require_helper = __commonJS({
|
|
|
28499
29368
|
var obj = {};
|
|
28500
29369
|
var isLastField = false;
|
|
28501
29370
|
var addToObj = function(idx, i0, i1) {
|
|
28502
|
-
var field =
|
|
29371
|
+
var field = line2.substring(i0, i1);
|
|
28503
29372
|
if (!Object.hasOwnProperty.call(process.env, "PGPASS_NO_DEESCAPE")) {
|
|
28504
29373
|
field = field.replace(/\\([:\\])/g, "$1");
|
|
28505
29374
|
}
|
|
28506
29375
|
obj[fieldNames[idx]] = field;
|
|
28507
29376
|
};
|
|
28508
|
-
for (var i = 0; i <
|
|
28509
|
-
curChar =
|
|
28510
|
-
prevChar =
|
|
29377
|
+
for (var i = 0; i < line2.length - 1; i += 1) {
|
|
29378
|
+
curChar = line2.charAt(i + 1);
|
|
29379
|
+
prevChar = line2.charAt(i);
|
|
28511
29380
|
isLastField = fieldIdx == nrOfFields - 1;
|
|
28512
29381
|
if (isLastField) {
|
|
28513
29382
|
addToObj(fieldIdx, startIdx);
|
|
@@ -28777,12 +29646,12 @@ var require_client = __commonJS({
|
|
|
28777
29646
|
this._connect(callback);
|
|
28778
29647
|
return;
|
|
28779
29648
|
}
|
|
28780
|
-
return new this._Promise((
|
|
29649
|
+
return new this._Promise((resolve10, reject) => {
|
|
28781
29650
|
this._connect((error2) => {
|
|
28782
29651
|
if (error2) {
|
|
28783
29652
|
reject(error2);
|
|
28784
29653
|
} else {
|
|
28785
|
-
|
|
29654
|
+
resolve10(this);
|
|
28786
29655
|
}
|
|
28787
29656
|
});
|
|
28788
29657
|
});
|
|
@@ -29164,8 +30033,8 @@ var require_client = __commonJS({
|
|
|
29164
30033
|
} else {
|
|
29165
30034
|
query = new Query2(config2, values, callback);
|
|
29166
30035
|
if (!query.callback) {
|
|
29167
|
-
result = new this._Promise((
|
|
29168
|
-
query.callback = (err, res) => err ? reject(err) :
|
|
30036
|
+
result = new this._Promise((resolve10, reject) => {
|
|
30037
|
+
query.callback = (err, res) => err ? reject(err) : resolve10(res);
|
|
29169
30038
|
}).catch((err) => {
|
|
29170
30039
|
Error.captureStackTrace(err);
|
|
29171
30040
|
throw err;
|
|
@@ -29265,8 +30134,8 @@ var require_client = __commonJS({
|
|
|
29265
30134
|
if (cb) {
|
|
29266
30135
|
this.connection.once("end", cb);
|
|
29267
30136
|
} else {
|
|
29268
|
-
return new this._Promise((
|
|
29269
|
-
this.connection.once("end",
|
|
30137
|
+
return new this._Promise((resolve10) => {
|
|
30138
|
+
this.connection.once("end", resolve10);
|
|
29270
30139
|
});
|
|
29271
30140
|
}
|
|
29272
30141
|
}
|
|
@@ -29315,8 +30184,8 @@ var require_pg_pool = __commonJS({
|
|
|
29315
30184
|
const cb = function(err, client) {
|
|
29316
30185
|
err ? rej(err) : res(client);
|
|
29317
30186
|
};
|
|
29318
|
-
const result = new Promise2(function(
|
|
29319
|
-
res =
|
|
30187
|
+
const result = new Promise2(function(resolve10, reject) {
|
|
30188
|
+
res = resolve10;
|
|
29320
30189
|
rej = reject;
|
|
29321
30190
|
}).catch((err) => {
|
|
29322
30191
|
Error.captureStackTrace(err);
|
|
@@ -29377,7 +30246,7 @@ var require_pg_pool = __commonJS({
|
|
|
29377
30246
|
if (typeof Promise2.try === "function") {
|
|
29378
30247
|
return Promise2.try(f);
|
|
29379
30248
|
}
|
|
29380
|
-
return new Promise2((
|
|
30249
|
+
return new Promise2((resolve10) => resolve10(f()));
|
|
29381
30250
|
}
|
|
29382
30251
|
_isFull() {
|
|
29383
30252
|
return this._clients.length >= this.options.max;
|
|
@@ -29772,8 +30641,8 @@ var require_query2 = __commonJS({
|
|
|
29772
30641
|
NativeQuery.prototype._getPromise = function() {
|
|
29773
30642
|
if (this._promise) return this._promise;
|
|
29774
30643
|
this._promise = new Promise(
|
|
29775
|
-
function(
|
|
29776
|
-
this._once("end",
|
|
30644
|
+
function(resolve10, reject) {
|
|
30645
|
+
this._once("end", resolve10);
|
|
29777
30646
|
this._once("error", reject);
|
|
29778
30647
|
}.bind(this)
|
|
29779
30648
|
);
|
|
@@ -29952,12 +30821,12 @@ var require_client2 = __commonJS({
|
|
|
29952
30821
|
this._connect(callback);
|
|
29953
30822
|
return;
|
|
29954
30823
|
}
|
|
29955
|
-
return new this._Promise((
|
|
30824
|
+
return new this._Promise((resolve10, reject) => {
|
|
29956
30825
|
this._connect((error2) => {
|
|
29957
30826
|
if (error2) {
|
|
29958
30827
|
reject(error2);
|
|
29959
30828
|
} else {
|
|
29960
|
-
|
|
30829
|
+
resolve10(this);
|
|
29961
30830
|
}
|
|
29962
30831
|
});
|
|
29963
30832
|
});
|
|
@@ -29981,8 +30850,8 @@ var require_client2 = __commonJS({
|
|
|
29981
30850
|
query = new NativeQuery(config2, values, callback);
|
|
29982
30851
|
if (!query.callback) {
|
|
29983
30852
|
let resolveOut, rejectOut;
|
|
29984
|
-
result = new this._Promise((
|
|
29985
|
-
resolveOut =
|
|
30853
|
+
result = new this._Promise((resolve10, reject) => {
|
|
30854
|
+
resolveOut = resolve10;
|
|
29986
30855
|
rejectOut = reject;
|
|
29987
30856
|
}).catch((err) => {
|
|
29988
30857
|
Error.captureStackTrace(err);
|
|
@@ -30045,8 +30914,8 @@ var require_client2 = __commonJS({
|
|
|
30045
30914
|
}
|
|
30046
30915
|
let result;
|
|
30047
30916
|
if (!cb) {
|
|
30048
|
-
result = new this._Promise(function(
|
|
30049
|
-
cb = (err) => err ? reject(err) :
|
|
30917
|
+
result = new this._Promise(function(resolve10, reject) {
|
|
30918
|
+
cb = (err) => err ? reject(err) : resolve10();
|
|
30050
30919
|
});
|
|
30051
30920
|
}
|
|
30052
30921
|
const doEnd = function() {
|
|
@@ -30304,12 +31173,12 @@ function findPostgresBin() {
|
|
|
30304
31173
|
throw new Error("PostgreSQL 16+ was not found. Install it (https://www.postgresql.org/download/) or set BACKIFY_POSTGRES_BIN to its bin directory.");
|
|
30305
31174
|
}
|
|
30306
31175
|
function freePort(preferred = 0) {
|
|
30307
|
-
return new Promise((
|
|
31176
|
+
return new Promise((resolve10, reject) => {
|
|
30308
31177
|
const server = createServer3();
|
|
30309
|
-
server.once("error", (error2) => preferred ? freePort(0).then(
|
|
31178
|
+
server.once("error", (error2) => preferred ? freePort(0).then(resolve10, reject) : reject(error2));
|
|
30310
31179
|
server.listen(preferred, "127.0.0.1", () => {
|
|
30311
31180
|
const port = server.address().port;
|
|
30312
|
-
server.close(() =>
|
|
31181
|
+
server.close(() => resolve10(port));
|
|
30313
31182
|
});
|
|
30314
31183
|
});
|
|
30315
31184
|
}
|
|
@@ -30342,10 +31211,10 @@ async function startLocalDatabase(root, extensions = []) {
|
|
|
30342
31211
|
const port = state.port = running ? state.port : await freePort(state.port);
|
|
30343
31212
|
writeFileSync11(statePath, JSON.stringify(state), { mode: 384 });
|
|
30344
31213
|
if (!running) {
|
|
30345
|
-
await new Promise((
|
|
31214
|
+
await new Promise((resolve10, reject) => {
|
|
30346
31215
|
const child = spawn3(join16(bin, exe("pg_ctl")), ["-D", data, "-l", join16(home, "postgres.log"), "-o", `-h 127.0.0.1 -p ${port}`, "-w", "start"], { stdio: "ignore", windowsHide: true, detached: process.platform !== "win32" });
|
|
30347
31216
|
child.on("error", reject);
|
|
30348
|
-
child.on("exit", (code) => code === 0 ?
|
|
31217
|
+
child.on("exit", (code) => code === 0 ? resolve10() : reject(new Error(`PostgreSQL did not start; see ${join16(home, "postgres.log")}`)));
|
|
30349
31218
|
});
|
|
30350
31219
|
}
|
|
30351
31220
|
const url2 = (user, password, database) => `postgres://${user}:${encodeURIComponent(password)}@127.0.0.1:${port}/${database}`;
|
|
@@ -30480,7 +31349,7 @@ function readBody(req, limit = 300 * 1024 * 1024) {
|
|
|
30480
31349
|
req.on("error", reject);
|
|
30481
31350
|
});
|
|
30482
31351
|
}
|
|
30483
|
-
function
|
|
31352
|
+
function json2(res, status, body) {
|
|
30484
31353
|
res.writeHead(status, { "content-type": "application/json" });
|
|
30485
31354
|
res.end(JSON.stringify(body));
|
|
30486
31355
|
}
|
|
@@ -30570,21 +31439,21 @@ function startGateway(options) {
|
|
|
30570
31439
|
if (url2.pathname.startsWith("/signed/")) return await signed(req, res, url2);
|
|
30571
31440
|
if (url2.pathname.startsWith("/files/")) {
|
|
30572
31441
|
const [, , bucket, ...rest] = url2.pathname.split("/");
|
|
30573
|
-
if (!buckets.get(bucket)?.public) return
|
|
31442
|
+
if (!buckets.get(bucket)?.public) return json2(res, 404, { error: { code: "not_found", message: "Not found" } });
|
|
30574
31443
|
return sendFile(res, objectPath(bucket, rest.map(decodeURIComponent).join("/")));
|
|
30575
31444
|
}
|
|
30576
31445
|
const apiPrefix = config2.kind === "api" ? "/" : "/api";
|
|
30577
31446
|
if (config2.kind !== "web" || !options.frontendPort || url2.pathname === apiPrefix || url2.pathname.startsWith(apiPrefix === "/" ? "/" : apiPrefix + "/") || url2.pathname === (config2.server?.health ?? "/healthz")) {
|
|
30578
31447
|
const port = options.webPort();
|
|
30579
|
-
if (!port) return
|
|
31448
|
+
if (!port) return json2(res, 503, { error: { code: "starting", message: "The backend is starting or failed to start; see the terminal" } });
|
|
30580
31449
|
const user = sessionUser(req);
|
|
30581
31450
|
if (user) req.headers["x-backify-user"] = options.identity.signUser(user);
|
|
30582
31451
|
return proxy(req, res, port);
|
|
30583
31452
|
}
|
|
30584
31453
|
return proxy(req, res, options.frontendPort);
|
|
30585
31454
|
} catch (error2) {
|
|
30586
|
-
if (error2 instanceof InvalidKey) return
|
|
30587
|
-
if (!res.headersSent)
|
|
31455
|
+
if (error2 instanceof InvalidKey) return json2(res, 400, { error: { code: "invalid_key", message: error2.message } });
|
|
31456
|
+
if (!res.headersSent) json2(res, 500, { error: { code: "gateway_error", message: error2.message } });
|
|
30588
31457
|
}
|
|
30589
31458
|
});
|
|
30590
31459
|
server.on("upgrade", (req, socket, head) => {
|
|
@@ -30604,12 +31473,12 @@ function startGateway(options) {
|
|
|
30604
31473
|
response.pipe(res);
|
|
30605
31474
|
});
|
|
30606
31475
|
upstream.on("error", () => {
|
|
30607
|
-
if (!res.headersSent)
|
|
31476
|
+
if (!res.headersSent) json2(res, 502, { error: { code: "bad_gateway", message: `Nothing is listening on port ${port} yet` } });
|
|
30608
31477
|
});
|
|
30609
31478
|
req.pipe(upstream);
|
|
30610
31479
|
}
|
|
30611
31480
|
function sendFile(res, path, contentType2) {
|
|
30612
|
-
if (!existsSync14(path) || !statSync2(path).isFile()) return
|
|
31481
|
+
if (!existsSync14(path) || !statSync2(path).isFile()) return json2(res, 404, { error: { code: "not_found", message: "Not found" } });
|
|
30613
31482
|
const meta2 = existsSync14(path + ".meta.json") ? JSON.parse(readFileSync19(path + ".meta.json", "utf8")) : {};
|
|
30614
31483
|
res.writeHead(200, { "content-type": contentType2 ?? meta2.contentType ?? "application/octet-stream" });
|
|
30615
31484
|
createReadStream(path).pipe(res);
|
|
@@ -30619,7 +31488,7 @@ function startGateway(options) {
|
|
|
30619
31488
|
const returnTo = url2.searchParams.get("returnTo")?.startsWith("/") ? url2.searchParams.get("returnTo") : "/";
|
|
30620
31489
|
if (action === "me") {
|
|
30621
31490
|
const user = sessionUser(req);
|
|
30622
|
-
return user ?
|
|
31491
|
+
return user ? json2(res, 200, { id: user.id, email: user.email, name: user.name, roles: user.roles, permissions: user.permissions }) : json2(res, 401, { error: { code: "unauthenticated", message: "Not signed in" } });
|
|
30623
31492
|
}
|
|
30624
31493
|
if (action === "signout") {
|
|
30625
31494
|
res.writeHead(302, { location: "/", "set-cookie": `${SESSION}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0` });
|
|
@@ -30628,7 +31497,7 @@ function startGateway(options) {
|
|
|
30628
31497
|
if (action === "login" && req.method === "POST") {
|
|
30629
31498
|
const form = new URLSearchParams((await readBody(req, 64 * 1024)).toString());
|
|
30630
31499
|
const email2 = (form.get("email") ?? "").trim().toLowerCase();
|
|
30631
|
-
if (!/^[^@\s]+@[^@\s]+$/.test(email2)) return
|
|
31500
|
+
if (!/^[^@\s]+@[^@\s]+$/.test(email2)) return json2(res, 400, { error: { code: "invalid_email", message: "Enter an email address" } });
|
|
30632
31501
|
const list = (name2) => (form.get(name2) ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
30633
31502
|
const user = { id: "dev-" + createHmac("sha256", "backify-dev").update(email2).digest("hex").slice(0, 16), email: email2, name: form.get("name") || void 0, roles: list("roles"), permissions: list("permissions") };
|
|
30634
31503
|
res.writeHead(302, { location: form.get("returnTo")?.startsWith("/") ? form.get("returnTo") : "/", "set-cookie": `${SESSION}=${encodeURIComponent(sealed({ ...user, exp: Date.now() + 864e5 }))}; Path=/; HttpOnly; SameSite=Lax` });
|
|
@@ -30647,7 +31516,7 @@ function startGateway(options) {
|
|
|
30647
31516
|
<p><label>Permissions (comma separated)<br><input name="permissions" style="width:100%"></label></p>
|
|
30648
31517
|
<button>Sign in</button></form></body>`);
|
|
30649
31518
|
}
|
|
30650
|
-
return
|
|
31519
|
+
return json2(res, 404, { error: { code: "not_found", message: "Unknown auth endpoint" } });
|
|
30651
31520
|
}
|
|
30652
31521
|
async function broker(req, res, url2) {
|
|
30653
31522
|
if (req.headers.authorization !== "Bearer " + options.workloadToken) return brokerError(res, 401, "unauthorized", "Invalid workload token");
|
|
@@ -30657,7 +31526,7 @@ function startGateway(options) {
|
|
|
30657
31526
|
if (!config2.protection?.dynamicRules) return brokerError(res, 403, "protection_scope_required", "Declare protection.dynamicRules in backify.config.ts.");
|
|
30658
31527
|
const now = Date.now();
|
|
30659
31528
|
for (const [key2, rule2] of dynamicRules) if (Date.parse(rule2.expiresAt) <= now) dynamicRules.delete(key2);
|
|
30660
|
-
if (path.endsWith("/list")) return
|
|
31529
|
+
if (path.endsWith("/list")) return json2(res, 200, [...dynamicRules.values()]);
|
|
30661
31530
|
const ip = typeof body.ip === "string" ? body.ip : "";
|
|
30662
31531
|
if (!parseCidr(ip)) return brokerError(res, 400, "invalid_ip", "Use an IPv4 or IPv6 IP or CIDR range.");
|
|
30663
31532
|
if (path.endsWith("/remove")) {
|
|
@@ -30666,43 +31535,43 @@ function startGateway(options) {
|
|
|
30666
31535
|
dynamicRules.delete(key2);
|
|
30667
31536
|
removed++;
|
|
30668
31537
|
}
|
|
30669
|
-
return
|
|
31538
|
+
return json2(res, 200, { removed });
|
|
30670
31539
|
}
|
|
30671
31540
|
if (body.action !== "allow" && body.action !== "block" || typeof body.reason !== "string" || !body.reason.trim() || body.reason.length > 400 || body.ttl !== void 0 && (!Number.isInteger(body.ttl) || Number(body.ttl) < 1 || Number(body.ttl) > 2592e3)) return brokerError(res, 400, "invalid_rule", "Use allow/block, a short reason and TTL of 1 second to 30 days.");
|
|
30672
31541
|
const key = body.action + "|" + ip;
|
|
30673
31542
|
if (!dynamicRules.has(key) && dynamicRules.size >= 1e4) return brokerError(res, 409, "protection_rule_limit", "At most 10,000 active rules.");
|
|
30674
31543
|
const rule = { id: dynamicRules.get(key)?.id ?? crypto.randomUUID(), cidr: ip, action: body.action, reason: body.reason, expiresAt: new Date(now + Number(body.ttl ?? 86400) * 1e3).toISOString() };
|
|
30675
31544
|
dynamicRules.set(key, rule);
|
|
30676
|
-
return
|
|
31545
|
+
return json2(res, 200, rule);
|
|
30677
31546
|
}
|
|
30678
|
-
if (path === "/v1/token/renew") return
|
|
31547
|
+
if (path === "/v1/token/renew") return json2(res, 200, { token: options.workloadToken, expiresAt: new Date(Date.now() + 864e5).toISOString() });
|
|
30679
31548
|
if (path === "/v1/storage/credentials" || path === "/v1/storage/sign") {
|
|
30680
31549
|
const bucket = String(body.bucket);
|
|
30681
31550
|
if (!buckets.has(bucket)) return brokerError(res, 403, "bucket_not_declared", `Bucket ${bucket} is not declared in backify.config.ts storage.buckets`);
|
|
30682
|
-
if (path === "/v1/storage/credentials") return
|
|
31551
|
+
if (path === "/v1/storage/credentials") return json2(res, 200, { provider: "local", endpoint: `http://127.0.0.1:${options.port}/storage`, container: "local", prefix: bucket + "/", credential: storageCredential, expiresAt: new Date(Date.now() + 36e5).toISOString() });
|
|
30683
31552
|
const expires = Date.now() + Number(body.expiresInSeconds ?? 300) * 1e3;
|
|
30684
31553
|
objectPath(bucket, String(body.key));
|
|
30685
31554
|
const token2 = sealed({ kind: "signed", bucket, key: String(body.key), operation: body.operation, contentType: body.contentType, exp: expires });
|
|
30686
|
-
return
|
|
31555
|
+
return json2(res, 200, { url: `http://localhost:${options.port}/signed/${encodeURIComponent(token2)}`, method: body.operation === "upload" ? "PUT" : "GET", headers: body.contentType ? { "content-type": String(body.contentType) } : {}, expiresAt: new Date(expires).toISOString() });
|
|
30687
31556
|
}
|
|
30688
31557
|
if (path === "/v1/mail/send") {
|
|
30689
31558
|
const id = "mail_" + randomBytes4(6).toString("hex");
|
|
30690
31559
|
writeFileSync12(join17(mailDir, id + ".json"), JSON.stringify(body, null, 2));
|
|
30691
31560
|
options.log(`mail to ${JSON.stringify(body.to)}: "${String(body.subject)}" (saved in .backify/dev/mail/${id}.json)`);
|
|
30692
|
-
return
|
|
31561
|
+
return json2(res, 200, { id, status: "sent", from: "noreply@localhost" });
|
|
30693
31562
|
}
|
|
30694
31563
|
if (path === "/v1/http/fetch") {
|
|
30695
31564
|
const target = new URL(String(body.url));
|
|
30696
31565
|
if (target.protocol !== "https:") return brokerError(res, 403, "https_required", `Outbound HTTP to ${target.hostname} must use https`);
|
|
30697
31566
|
const response = await fetch(target, { method: String(body.method ?? "GET"), headers: body.headers, body: body.body, signal: AbortSignal.timeout(Number(body.timeoutSeconds ?? 30) * 1e3) });
|
|
30698
31567
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
30699
|
-
return
|
|
31568
|
+
return json2(res, 200, { status: response.status, headers: Object.fromEntries(response.headers), body: bytes.toString("base64"), encoding: "base64" });
|
|
30700
31569
|
}
|
|
30701
31570
|
if (path.startsWith("/v1/ai/") || path.startsWith("/v1/integrations/")) return brokerError(res, 501, "not_available_locally", `${path.split("/")[2]} is not available in local development yet; test it in a preview environment`);
|
|
30702
31571
|
return brokerError(res, 404, "not_found", "Unknown broker endpoint " + path);
|
|
30703
31572
|
}
|
|
30704
31573
|
async function storage(req, res, url2) {
|
|
30705
|
-
if (req.headers.authorization !== "Bearer " + storageCredential) return
|
|
31574
|
+
if (req.headers.authorization !== "Bearer " + storageCredential) return json2(res, 403, {});
|
|
30706
31575
|
const rest = url2.pathname.slice("/storage/local".length);
|
|
30707
31576
|
if (rest === "" || rest === "/") {
|
|
30708
31577
|
const prefix = url2.searchParams.get("prefix") ?? "";
|
|
@@ -30715,7 +31584,7 @@ function startGateway(options) {
|
|
|
30715
31584
|
}
|
|
30716
31585
|
};
|
|
30717
31586
|
walk2(storageDir);
|
|
30718
|
-
return
|
|
31587
|
+
return json2(res, 200, { keys: files.filter((f) => f.startsWith(prefix)).sort() });
|
|
30719
31588
|
}
|
|
30720
31589
|
const [bucket, ...key] = rest.slice(1).split("/").map(decodeURIComponent);
|
|
30721
31590
|
const path = objectPath(bucket, key.join("/"));
|
|
@@ -30736,7 +31605,7 @@ function startGateway(options) {
|
|
|
30736
31605
|
}
|
|
30737
31606
|
async function signed(req, res, url2) {
|
|
30738
31607
|
const grant = unseal(decodeURIComponent(url2.pathname.slice("/signed/".length)));
|
|
30739
|
-
if (!grant || grant.kind !== "signed") return
|
|
31608
|
+
if (!grant || grant.kind !== "signed") return json2(res, 403, { error: { code: "expired", message: "The signed URL is invalid or expired" } });
|
|
30740
31609
|
const path = objectPath(grant.bucket, grant.key);
|
|
30741
31610
|
if (grant.operation === "upload" && req.method === "PUT") {
|
|
30742
31611
|
mkdirSync6(dirname7(path), { recursive: true });
|
|
@@ -30746,7 +31615,7 @@ function startGateway(options) {
|
|
|
30746
31615
|
return res.end();
|
|
30747
31616
|
}
|
|
30748
31617
|
if (grant.operation === "download" && req.method === "GET") return sendFile(res, path);
|
|
30749
|
-
return
|
|
31618
|
+
return json2(res, 405, { error: { code: "method_not_allowed", message: "Wrong method for this signed URL" } });
|
|
30750
31619
|
}
|
|
30751
31620
|
return new Promise((resolveServer, reject) => {
|
|
30752
31621
|
server.once("error", reject);
|
|
@@ -30765,7 +31634,7 @@ var init_local_gateway = __esm({
|
|
|
30765
31634
|
super("Invalid object key");
|
|
30766
31635
|
}
|
|
30767
31636
|
};
|
|
30768
|
-
brokerError = (res, status, code, message) =>
|
|
31637
|
+
brokerError = (res, status, code, message) => json2(res, status, { error: { code, message, requestId: randomBytes4(6).toString("hex") } });
|
|
30769
31638
|
}
|
|
30770
31639
|
});
|
|
30771
31640
|
|
|
@@ -30787,19 +31656,19 @@ function prefixOutput(child, label, code) {
|
|
|
30787
31656
|
buffer += chunk.toString();
|
|
30788
31657
|
const lines = buffer.split(/\r?\n/);
|
|
30789
31658
|
buffer = lines.pop() ?? "";
|
|
30790
|
-
for (const
|
|
31659
|
+
for (const line2 of lines) if (line2.trim()) say(label, prettyLog(line2), code);
|
|
30791
31660
|
});
|
|
30792
31661
|
}
|
|
30793
31662
|
}
|
|
30794
|
-
function prettyLog(
|
|
31663
|
+
function prettyLog(line2) {
|
|
30795
31664
|
try {
|
|
30796
|
-
const entry = JSON.parse(
|
|
30797
|
-
if (!entry.message) return
|
|
31665
|
+
const entry = JSON.parse(line2);
|
|
31666
|
+
if (!entry.message) return line2;
|
|
30798
31667
|
const { time: _time, level, message, ...fields } = entry;
|
|
30799
31668
|
const extra = Object.keys(fields).length ? " " + JSON.stringify(fields) : "";
|
|
30800
31669
|
return `${level === "error" ? color(31, "error") : level === "warn" ? color(33, "warn") : ""}${level === "error" || level === "warn" ? " " : ""}${message}${extra}`;
|
|
30801
31670
|
} catch {
|
|
30802
|
-
return
|
|
31671
|
+
return line2;
|
|
30803
31672
|
}
|
|
30804
31673
|
}
|
|
30805
31674
|
function localSecrets(root) {
|
|
@@ -30939,6 +31808,632 @@ var init_dev = __esm({
|
|
|
30939
31808
|
}
|
|
30940
31809
|
});
|
|
30941
31810
|
|
|
31811
|
+
// src/hosting.ts
|
|
31812
|
+
var hosting_exports = {};
|
|
31813
|
+
__export(hosting_exports, {
|
|
31814
|
+
ROLLBACK_NOTICE: () => ROLLBACK_NOTICE,
|
|
31815
|
+
hostingArguments: () => hostingArguments,
|
|
31816
|
+
hostingHelp: () => hostingHelp,
|
|
31817
|
+
hostingText: () => hostingText2,
|
|
31818
|
+
rollbackArguments: () => rollbackArguments,
|
|
31819
|
+
rollbackHelp: () => rollbackHelp,
|
|
31820
|
+
runHosting: () => runHosting,
|
|
31821
|
+
runRollback: () => runRollback
|
|
31822
|
+
});
|
|
31823
|
+
function hostingArguments(args2) {
|
|
31824
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
31825
|
+
const { flags, positional } = parse(withoutApp(args2), "hosting", ["--json"], []);
|
|
31826
|
+
if (positional.length) throw new Error(hostingHelp);
|
|
31827
|
+
return { json: flags.has("--json") };
|
|
31828
|
+
}
|
|
31829
|
+
function rollbackArguments(args2) {
|
|
31830
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
31831
|
+
const { flags, positional } = parse(withoutApp(args2), "rollback", ["--yes", "--json"], []);
|
|
31832
|
+
if (positional.length !== 1 || !uuid11.test(positional[0])) throw new Error("Name the deployment to roll back to by its ID. " + rollbackHelp);
|
|
31833
|
+
return { deploymentId: positional[0].toLowerCase(), yes: flags.has("--yes"), json: flags.has("--json") };
|
|
31834
|
+
}
|
|
31835
|
+
function hostingText2(hosting) {
|
|
31836
|
+
const environmentName = (id) => id ? hosting.environments?.find((item) => item.id === id)?.name ?? id : "application-wide";
|
|
31837
|
+
const ordered = [...hosting.resources.filter((item) => !kept(item)), ...hosting.resources.filter(kept)];
|
|
31838
|
+
const lines = [
|
|
31839
|
+
"Hosting: " + (hosting.hostingTargetType === "backify-cloud" ? "Backify Cloud" : "Bring your own cloud") + (hosting.target ? ", " + hosting.target.name : "") + (hosting.region ? " (" + hosting.region + ")" : "") + (hosting.isOffline ? ", offline" : ""),
|
|
31840
|
+
""
|
|
31841
|
+
];
|
|
31842
|
+
if (!ordered.length) return [...lines, "No application infrastructure has been recorded."].join("\n");
|
|
31843
|
+
const rows = [["RESOURCE", "ENVIRONMENT", "STATUS", "DATA"], ...ordered.map((item) => [item.capability, environmentName(item.environmentId), item.status, kept(item) ? "KEPT since " + item.retainedAt : item.stateful ? "persistent" : "-"])];
|
|
31844
|
+
const retained = ordered.filter(kept), plural = retained.length !== 1;
|
|
31845
|
+
return [...lines, ...pad(rows), ...retained.length ? ["", `${retained.length} ${plural ? "resources are" : "resource is"} kept with ${plural ? "their" : "its"} data and no longer declared. Deleting ${plural ? "them" : "it"} needs a separate authorization; nothing here deletes data.`] : []].join("\n");
|
|
31846
|
+
}
|
|
31847
|
+
async function runHosting(call2, applicationId) {
|
|
31848
|
+
if (!uuid11.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
31849
|
+
const hosting = await call2("/apps/" + applicationId + "/hosting");
|
|
31850
|
+
if (!hosting || !Array.isArray(hosting.resources)) throw new CommandError("Hosting details are unavailable.", "hosting_unavailable");
|
|
31851
|
+
return { value: hosting, text: hostingText2(hosting) };
|
|
31852
|
+
}
|
|
31853
|
+
async function runRollback(call2, applicationId, options, context2 = {}) {
|
|
31854
|
+
if (!uuid11.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
31855
|
+
if (!options.yes) {
|
|
31856
|
+
const message = "Roll back production to deployment " + options.deploymentId + "? This changes the version served to visitors. " + ROLLBACK_NOTICE;
|
|
31857
|
+
if (!context2.confirm) throw new CommandError("Refusing to roll back without confirmation. Review this and re-run with --yes:\n" + message, "confirmation_required", { deploymentId: options.deploymentId, databaseRecovery: "separate", notice: ROLLBACK_NOTICE });
|
|
31858
|
+
if (!await context2.confirm(message)) throw new CommandError("Not confirmed. Nothing was rolled back.", "not_confirmed");
|
|
31859
|
+
}
|
|
31860
|
+
const accepted = await call2("/apps/" + applicationId + "/rollback", { method: "POST", headers: { "Idempotency-Key": "cli-rollback-" + options.deploymentId }, body: JSON.stringify({ deploymentId: options.deploymentId }) });
|
|
31861
|
+
const notice = accepted?.notice?.trim() || ROLLBACK_NOTICE;
|
|
31862
|
+
return { value: { databaseRecovery: "separate", ...accepted, notice }, text: ["Rollback queued" + (accepted?.operationId ? " (operation " + accepted.operationId + ")" : "") + ".", notice].join("\n") };
|
|
31863
|
+
}
|
|
31864
|
+
var uuid11, hostingHelp, rollbackHelp, ROLLBACK_NOTICE, withoutApp, kept;
|
|
31865
|
+
var init_hosting = __esm({
|
|
31866
|
+
"src/hosting.ts"() {
|
|
31867
|
+
"use strict";
|
|
31868
|
+
init_release_flow();
|
|
31869
|
+
uuid11 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
31870
|
+
hostingHelp = [
|
|
31871
|
+
"Usage: backify hosting [--app <application>] [--json]",
|
|
31872
|
+
"",
|
|
31873
|
+
"Shows the application's hosting: target, environments and infrastructure resources.",
|
|
31874
|
+
"A stateful resource that is no longer declared is marked KEPT: it stays with its data until its deletion is separately authorized.",
|
|
31875
|
+
"Nothing here deletes it. --json prints the hosting overview unchanged, including retainedAt."
|
|
31876
|
+
].join("\n");
|
|
31877
|
+
rollbackHelp = [
|
|
31878
|
+
"Usage: backify rollback <deployment-id> [--yes] [--app <application>] [--json]",
|
|
31879
|
+
"",
|
|
31880
|
+
"Rolls production back to an earlier deployment (find IDs in the portal's activity list). Asks y/N on a terminal, otherwise needs --yes.",
|
|
31881
|
+
"A rollback restores compatible web revisions and worker configuration only. It never restores or rewinds the database; restore a backup separately.",
|
|
31882
|
+
'--json prints the accepted response: operationId, status, databaseRecovery (always "separate") and notice.'
|
|
31883
|
+
].join("\n");
|
|
31884
|
+
ROLLBACK_NOTICE = "A rollback restores compatible web revisions and worker configuration only. It never restores or rewinds the database; restore a backup separately.";
|
|
31885
|
+
withoutApp = (args2) => args2.filter((value, index) => value !== "--app" && args2[index - 1] !== "--app");
|
|
31886
|
+
kept = (resource) => Boolean(resource.retainedAt);
|
|
31887
|
+
}
|
|
31888
|
+
});
|
|
31889
|
+
|
|
31890
|
+
// src/handoff.ts
|
|
31891
|
+
var handoff_exports = {};
|
|
31892
|
+
__export(handoff_exports, {
|
|
31893
|
+
handoffArguments: () => handoffArguments,
|
|
31894
|
+
handoffHelp: () => handoffHelp,
|
|
31895
|
+
handoffStatusText: () => handoffStatusText,
|
|
31896
|
+
inventoryText: () => inventoryText,
|
|
31897
|
+
packageFilePath: () => packageFilePath,
|
|
31898
|
+
replacementReason: () => replacementReason,
|
|
31899
|
+
replacementSettings: () => replacementSettings,
|
|
31900
|
+
replacementState: () => replacementState,
|
|
31901
|
+
resolveReplacementEnvironment: () => resolveReplacementEnvironment,
|
|
31902
|
+
runHandoff: () => runHandoff,
|
|
31903
|
+
validSecretName: () => validSecretName
|
|
31904
|
+
});
|
|
31905
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
31906
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync7, writeFileSync as writeFileSync13 } from "node:fs";
|
|
31907
|
+
import { dirname as dirname8, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve9, sep as sep2 } from "node:path";
|
|
31908
|
+
function extractSettings(args2) {
|
|
31909
|
+
const rest = [], settings = {};
|
|
31910
|
+
for (let index = 0; index < args2.length; index++) {
|
|
31911
|
+
const arg = args2[index];
|
|
31912
|
+
if (secretFlag.test(arg)) throw new Error(secretRefusal);
|
|
31913
|
+
const inline = arg.startsWith("--setting=");
|
|
31914
|
+
if (arg !== "--setting" && !inline) {
|
|
31915
|
+
rest.push(arg);
|
|
31916
|
+
continue;
|
|
31917
|
+
}
|
|
31918
|
+
const pair = inline ? arg.slice("--setting=".length) : args2[++index], at = pair ? pair.indexOf("=") : -1;
|
|
31919
|
+
if (!pair || at < 1) throw new Error("Write each setting as key=value, for example --setting host=smtp.example.com.");
|
|
31920
|
+
const key = pair.slice(0, at);
|
|
31921
|
+
if (key in settings) throw new Error("Duplicate setting: " + key);
|
|
31922
|
+
settings[key] = pair.slice(at + 1);
|
|
31923
|
+
}
|
|
31924
|
+
return { rest, settings };
|
|
31925
|
+
}
|
|
31926
|
+
function replacementsArguments(positional, flags, values, settings, json3, yes) {
|
|
31927
|
+
const sub = (positional[1] ?? "list").toLowerCase();
|
|
31928
|
+
if (!["list", "add", "verify", "remove"].includes(sub)) throw new Error("Unknown replacements command: " + positional.slice(1).join(" ") + "\n\n" + handoffHelp);
|
|
31929
|
+
const takesId = sub === "verify" || sub === "remove";
|
|
31930
|
+
if (positional.length > (takesId ? 3 : 2)) throw new Error("Unknown replacements command: " + positional.slice(1).join(" ") + "\n\n" + handoffHelp);
|
|
31931
|
+
if (takesId && !positional[2]) throw new Error("Name the replacement: backify handoff replacements " + sub + " <id>. List the ids with backify handoff replacements.");
|
|
31932
|
+
if (values["--confirm"] !== void 0 || values["--out"] !== void 0) throw new Error("--confirm and --out do not apply to handoff replacements.");
|
|
31933
|
+
if (sub !== "add" && (addOnlyFlags.some((name2) => values[name2] !== void 0) || Object.keys(settings).length > 0 || flags.has("--consent"))) throw new Error(addOnlyMessage);
|
|
31934
|
+
if (yes && sub !== "remove") throw new Error("--yes applies to handoff replacements remove. Adding a replacement is consented with --consent.");
|
|
31935
|
+
if (sub !== "add") return { action: "replacements", yes, json: json3, replacement: { action: sub, ...takesId ? { id: positional[2] } : {}, settings: {}, consent: false } };
|
|
31936
|
+
const kind2 = values["--kind"]?.toLowerCase(), secretName = values["--secret-name"];
|
|
31937
|
+
if (!values["--environment"]) throw new Error("Name the environment with --environment <name|id|kind>.");
|
|
31938
|
+
if (!kind2 || !replacementKinds.includes(kind2)) throw new Error("Choose what you are replacing with --kind " + replacementKinds.join(", ") + ".");
|
|
31939
|
+
if (!secretName) throw new Error("Name the secret in your environment's vault with --secret-name <vault secret name>. " + secretRefusal);
|
|
31940
|
+
if (!validSecretName(secretName)) throw new Error("--secret-name is the name of a vault secret: letters, digits and hyphens, at most 127, and not starting with backify-rt-. It is not the secret's value.");
|
|
31941
|
+
const subject = values["--subject"] ?? (kind2 === "mail" || kind2 === "ai" ? kind2 : void 0);
|
|
31942
|
+
if (!subject) throw new Error("Name what the replacement is for with --subject: the connection ID for an integration, entra or google for a sign-in provider.");
|
|
31943
|
+
return { action: "replacements", yes, json: json3, replacement: { action: "add", environment: values["--environment"], kind: kind2, subject, settings, secretName, consent: flags.has("--consent") } };
|
|
31944
|
+
}
|
|
31945
|
+
function handoffArguments(args2) {
|
|
31946
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
31947
|
+
const { rest, settings } = extractSettings(args2);
|
|
31948
|
+
const { flags, values, positional } = parse(rest, "handoff", ["--json", "--yes", "--consent"], ["--app", "--confirm", "--out", "--azure-session", ...addOnlyFlags]);
|
|
31949
|
+
const action = (positional[0] ?? "status").toLowerCase(), json3 = flags.has("--json"), yes = flags.has("--yes");
|
|
31950
|
+
const azureSessionId = values["--azure-session"];
|
|
31951
|
+
if (azureSessionId !== void 0 && (action !== "start" || !uuid12.test(azureSessionId))) throw new Error("--azure-session requires a valid Azure session ID and applies to handoff start.");
|
|
31952
|
+
if (action === "replacements") return replacementsArguments(positional, flags, values, settings, json3, yes);
|
|
31953
|
+
if (Object.keys(settings).length || flags.has("--consent") || addOnlyFlags.some((name2) => values[name2] !== void 0)) throw new Error(addOnlyMessage);
|
|
31954
|
+
if (!["status", "check", "request", "start", "abort", "foundation", "package"].includes(action) || positional.length > 1) throw new Error("Unknown handoff command: " + positional.join(" ") + "\n\n" + handoffHelp);
|
|
31955
|
+
if (values["--confirm"] !== void 0 && action !== "request") throw new Error("--confirm applies to handoff request.");
|
|
31956
|
+
if (values["--out"] !== void 0 && action !== "package" && action !== "foundation") throw new Error("--out applies to handoff foundation and handoff package.");
|
|
31957
|
+
if (yes && action !== "start" && action !== "abort") throw new Error(action === "request" ? "Requesting a handoff is confirmed with --confirm <application-slug>, not --yes." : "--yes applies to handoff start and abort.");
|
|
31958
|
+
return { action, ...values["--confirm"] !== void 0 ? { confirm: values["--confirm"] } : {}, ...values["--out"] !== void 0 ? { out: values["--out"] } : {}, ...azureSessionId !== void 0 ? { azureSessionId } : {}, yes, json: json3 };
|
|
31959
|
+
}
|
|
31960
|
+
function pad4(rows) {
|
|
31961
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
31962
|
+
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ").trimEnd());
|
|
31963
|
+
}
|
|
31964
|
+
function inventoryText(inventory) {
|
|
31965
|
+
const count = (classification) => inventory.resources.filter((item) => item.classification === classification).length;
|
|
31966
|
+
const kept2 = inventory.hostnames.filter((item) => item.kept).length;
|
|
31967
|
+
const users = inventory.reauthentication.reduce((total, item) => total + item.count, 0);
|
|
31968
|
+
return [
|
|
31969
|
+
"Resources: " + inventory.resources.length + " (" + count("dedicated") + " dedicated, " + count("shared-separable") + " shared and separable, " + count("shared-platform") + " shared platform)",
|
|
31970
|
+
"Access Backify holds: " + inventory.accessPaths.length,
|
|
31971
|
+
"Backify-hosted dependencies: " + inventory.dependencies.length + (inventory.dependencies.some((item) => !item.customerReplacement) ? " (some have no replacement yet)" : ""),
|
|
31972
|
+
"Hostnames: " + kept2 + " kept, " + (inventory.hostnames.length - kept2) + " not kept",
|
|
31973
|
+
"People who must sign in or register passkeys again: " + users
|
|
31974
|
+
];
|
|
31975
|
+
}
|
|
31976
|
+
function handoffLines(handoff2) {
|
|
31977
|
+
const lines = ["Phase: " + handoff2.phase, "State: " + handoff2.state + (handoff2.failureCode ? " (" + handoff2.failureCode + ")" : ""), "Approval: " + (handoff2.approvalStatus ?? "-")];
|
|
31978
|
+
if (handoff2.detail) lines.push((handoff2.state === "stopped" ? "Stopped: " : "Detail: ") + handoff2.detail);
|
|
31979
|
+
lines.push("Actions: " + (handoff2.actions?.length ? handoff2.actions.join(", ") : "none"));
|
|
31980
|
+
if (handoff2.hosts?.length) lines.push("", "Hosts:", ...pad4([["HOSTNAME", "TLS", "DNS", "HEALTH", "SERVED BY"], ...handoff2.hosts.map((host) => [host.hostname, host.tls, host.dns, host.health, host.served])]).map((line2) => " " + line2));
|
|
31981
|
+
const open2 = handoff2.humanTasks?.filter((task) => task.state !== "completed") ?? [];
|
|
31982
|
+
if (open2.length) lines.push("", "Only you can do:", ...open2.flatMap((task) => [" " + task.kind + (task.hostname ? " " + task.hostname : "") + " (" + task.state + ")", ...task.instructions ? [" " + task.instructions] : []]));
|
|
31983
|
+
if (handoff2.revocation?.length) {
|
|
31984
|
+
const removed = handoff2.revocation.filter((item) => item.removed).length, verified = handoff2.revocation.filter((item) => item.verified).length;
|
|
31985
|
+
lines.push("", "Access removal: " + removed + " of " + handoff2.revocation.length + " removed, " + verified + " verified", ...pad4([["ACCESS", "REMOVED", "VERIFIED", "EVIDENCE"], ...handoff2.revocation.map((item) => [item.kind + (item.principal ? " " + item.principal : ""), item.removed ? "yes" : "no", item.verified ? "yes" : "no", item.failureCode ? "failed (" + item.failureCode + ")" : item.evidence ?? ""])]).map((line2) => " " + line2));
|
|
31986
|
+
}
|
|
31987
|
+
return lines;
|
|
31988
|
+
}
|
|
31989
|
+
function handoffStatusText(status) {
|
|
31990
|
+
const heading = status.handoffState === "handed-off" ? "This application has been handed off. It is read-only in Backify." : status.handoffState === "in-progress" ? "A handoff is in progress." : "This application has no handoff.";
|
|
31991
|
+
if (!status.handoff) return [heading, "", ...inventoryText(status.inventory), "", "Run backify handoff check to see whether it can be handed off."].join("\n");
|
|
31992
|
+
return [heading, "", ...handoffLines(status.handoff)].join("\n");
|
|
31993
|
+
}
|
|
31994
|
+
function manifestText(manifest) {
|
|
31995
|
+
const files = manifestFiles(manifest);
|
|
31996
|
+
if (!files.length) return "The handoff package lists no files.";
|
|
31997
|
+
return ["Handoff package: " + files.length + " file" + (files.length === 1 ? "" : "s"), "", ...pad4([["FILE", "SIZE", "SHA-256"], ...files.map((file) => [file.path, sizeText(file.bytes), file.sha256 ?? ""])])].join("\n");
|
|
31998
|
+
}
|
|
31999
|
+
function packageFilePath(root, filePath) {
|
|
32000
|
+
if (!filePath || filePath.includes("\0") || isAbsolute2(filePath) || /^[a-z]:/i.test(filePath) || filePath.startsWith("\\")) return void 0;
|
|
32001
|
+
const target = resolve9(root, filePath), inside = relative4(resolve9(root), target);
|
|
32002
|
+
return inside && !isAbsolute2(inside) && !inside.split(sep2).includes("..") ? target : void 0;
|
|
32003
|
+
}
|
|
32004
|
+
async function runFoundation(call2, prefix, out) {
|
|
32005
|
+
const plan = await call2(prefix + "/foundation");
|
|
32006
|
+
if (typeof plan?.template !== "string" || typeof plan.parameters !== "string")
|
|
32007
|
+
throw new CommandError("The API did not return the foundation template and parameters.", "handoff_foundation_invalid");
|
|
32008
|
+
const ownerRuntimeTemplate = plan.ownerRuntimeTemplate;
|
|
32009
|
+
const includeOwnerRuntime = typeof ownerRuntimeTemplate === "string";
|
|
32010
|
+
if (!out) return { value: plan, text: "The foundation plan includes app-foundation.bicep and app.parameters.json" + (includeOwnerRuntime ? ", plus owner-runtime.bicep." : ".") + " Save the files with backify handoff foundation --out <directory>." };
|
|
32011
|
+
const root = resolve9(out);
|
|
32012
|
+
const files = [
|
|
32013
|
+
{ path: resolve9(root, "app-foundation.bicep"), content: plan.template },
|
|
32014
|
+
{ path: resolve9(root, "app.parameters.json"), content: plan.parameters }
|
|
32015
|
+
];
|
|
32016
|
+
if (includeOwnerRuntime) files.push({ path: resolve9(root, "owner-runtime.bicep"), content: ownerRuntimeTemplate });
|
|
32017
|
+
const existing = files.find((file) => existsSync16(file.path));
|
|
32018
|
+
if (existing) throw new CommandError("A foundation file already exists. Choose another directory to preserve it.", "handoff_foundation_file_exists", { path: existing.path });
|
|
32019
|
+
mkdirSync7(root, { recursive: true });
|
|
32020
|
+
for (const file of files) writeFileSync13(file.path, file.content, { encoding: "utf8", flag: "wx" });
|
|
32021
|
+
return { value: { out: root, files: files.map((file) => file.path) }, text: "Saved the handoff templates and parameters in " + root + ". Fill in your Entra group in app.parameters.json before deploying." };
|
|
32022
|
+
}
|
|
32023
|
+
async function runPackage(call2, prefix, options) {
|
|
32024
|
+
const manifest = await call2(prefix + "/package");
|
|
32025
|
+
if (!options.out) return { value: manifest, text: manifestText(manifest) };
|
|
32026
|
+
const files = manifestFiles(manifest), root = resolve9(options.out);
|
|
32027
|
+
for (const file of files) if (!packageFilePath(root, file.path)) throw new CommandError("The package lists a file outside the output directory: " + file.path + ". Nothing was written.", "handoff_package_path_invalid", { path: file.path });
|
|
32028
|
+
mkdirSync7(root, { recursive: true });
|
|
32029
|
+
const written = [];
|
|
32030
|
+
for (const file of files) {
|
|
32031
|
+
const text2 = await call2(prefix + "/package/" + file.path.split("/").map(encodeURIComponent).join("/"), { headers: { accept: "text/plain" } });
|
|
32032
|
+
if (typeof text2 !== "string") throw new CommandError("The package file " + file.path + " was not returned as text.", "handoff_package_file_invalid", { path: file.path });
|
|
32033
|
+
if (file.sha256 && sha2562(text2) !== normalizedHash(file.sha256)) throw new CommandError("The package file " + file.path + " does not match its checksum in the manifest. It was not written; " + written.length + " earlier file(s) were.", "handoff_package_checksum_mismatch", { path: file.path, written: written.map((item) => item.path) });
|
|
32034
|
+
const target = packageFilePath(root, file.path);
|
|
32035
|
+
mkdirSync7(dirname8(target), { recursive: true });
|
|
32036
|
+
writeFileSync13(target, text2, "utf8");
|
|
32037
|
+
written.push({ path: file.path, bytes: Buffer.byteLength(text2, "utf8"), verified: Boolean(file.sha256) });
|
|
32038
|
+
}
|
|
32039
|
+
const unverified = written.filter((item) => !item.verified).length;
|
|
32040
|
+
return { value: { status: "written", out: root, files: written, manifest }, text: [manifestText(manifest), "", "Wrote " + written.length + " file" + (written.length === 1 ? "" : "s") + " to " + root + (unverified ? "; " + unverified + " had no checksum in the manifest to verify." : ", each verified against the manifest checksum.")].join("\n") };
|
|
32041
|
+
}
|
|
32042
|
+
function replacementState(replacement) {
|
|
32043
|
+
switch (replacement.verification) {
|
|
32044
|
+
case "verified":
|
|
32045
|
+
return "verified" + (replacement.verifiedAt ? " " + replacement.verifiedAt : "");
|
|
32046
|
+
case "failed":
|
|
32047
|
+
return "could not be verified";
|
|
32048
|
+
case "unverified":
|
|
32049
|
+
return "not verified";
|
|
32050
|
+
default:
|
|
32051
|
+
return "waiting for check";
|
|
32052
|
+
}
|
|
32053
|
+
}
|
|
32054
|
+
function resolveReplacementEnvironment(named, environments) {
|
|
32055
|
+
const wanted = named.trim().toLowerCase(), found = environments?.find((item) => item.id.toLowerCase() === wanted || item.kind.toLowerCase() === wanted);
|
|
32056
|
+
if (found) return found.id;
|
|
32057
|
+
if (!environments?.length && uuid12.test(named)) return named;
|
|
32058
|
+
throw new CommandError("This application has no environment " + named + ". " + (environments?.length ? "Use " + environments.map((item) => item.kind).join(", ") + " or an environment ID." : "Use an environment ID."), "environment_not_found", { environment: named });
|
|
32059
|
+
}
|
|
32060
|
+
function replacementSettings(settings) {
|
|
32061
|
+
const result = {}, deployments = {};
|
|
32062
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
32063
|
+
if (key.startsWith("deployments.")) {
|
|
32064
|
+
const model = key.slice("deployments.".length);
|
|
32065
|
+
if (!model) throw new Error("Write AI deployments as deployments.<model>=<deployment>.");
|
|
32066
|
+
deployments[model] = value;
|
|
32067
|
+
} else if (key === "port") {
|
|
32068
|
+
if (!/^\d{1,5}$/.test(value)) throw new Error("--setting port must be a number such as 587.");
|
|
32069
|
+
result.port = Number(value);
|
|
32070
|
+
} else result[key] = value;
|
|
32071
|
+
}
|
|
32072
|
+
if (Object.keys(deployments).length) result.deployments = deployments;
|
|
32073
|
+
return result;
|
|
32074
|
+
}
|
|
32075
|
+
async function runReplacements(call2, prefix, options, context2) {
|
|
32076
|
+
const replacement = options.replacement, base = prefix + "/replacements";
|
|
32077
|
+
if (replacement.action === "add") {
|
|
32078
|
+
const { kind: kind2, subject, secretName, environment: named } = replacement;
|
|
32079
|
+
if (!replacement.consent) throw new CommandError(consentSummary(kind2, subject, named, secretName) + "\nNothing was changed. Add --consent to record it.", "consent_required", { kind: kind2, subject, secretName });
|
|
32080
|
+
const status = await call2(prefix), environmentId = resolveReplacementEnvironment(named, status.inventory?.environments);
|
|
32081
|
+
const created = await call2(base, { method: "POST", body: JSON.stringify({ environmentId, kind: kind2, subject, settings: replacementSettings(replacement.settings), secretReference: secretName, consent: true }) });
|
|
32082
|
+
return { value: { status: "recorded", replacement: created }, text: ["Replacement recorded for " + subjectText(created) + " in " + named + ".", "Your environment is checking it: " + replacementState(created) + ". Run backify handoff replacements to see the result, or backify handoff replacements verify " + created.id + " to check again."].join("\n") };
|
|
32083
|
+
}
|
|
32084
|
+
if (replacement.action === "verify") {
|
|
32085
|
+
if (!uuid12.test(replacement.id)) throw new Error("Use a valid replacement ID. List them with backify handoff replacements.");
|
|
32086
|
+
const checked2 = await call2(base + "/" + replacement.id + "/verify", { method: "POST" });
|
|
32087
|
+
return { value: { status: "verifying", replacement: checked2 }, text: "Check requested for " + subjectText(checked2) + ": " + replacementState(checked2) + ". It usually takes a minute; run backify handoff replacements to see the result." };
|
|
32088
|
+
}
|
|
32089
|
+
if (replacement.action === "remove") {
|
|
32090
|
+
if (!uuid12.test(replacement.id)) throw new Error("Use a valid replacement ID. List them with backify handoff replacements.");
|
|
32091
|
+
const summary = "Remove this replacement. The dependency counts as hosted by Backify again, and the application cannot be handed off until you record a new one. The secret in your vault is not touched.";
|
|
32092
|
+
if (!options.yes) {
|
|
32093
|
+
if (!context2.confirm) throw new CommandError("Refusing to remove a replacement without confirmation. Review this and re-run with --yes:\n" + summary, "confirmation_required", { id: replacement.id });
|
|
32094
|
+
if (!await context2.confirm(summary)) throw new CommandError("Not confirmed. Nothing was changed.", "not_confirmed");
|
|
32095
|
+
}
|
|
32096
|
+
await call2(base + "/" + replacement.id, { method: "DELETE" });
|
|
32097
|
+
return { value: { status: "removed", id: replacement.id }, text: "Replacement removed. The dependency counts as hosted by Backify again." };
|
|
32098
|
+
}
|
|
32099
|
+
const list = await call2(base);
|
|
32100
|
+
let environments = [];
|
|
32101
|
+
try {
|
|
32102
|
+
environments = (await call2(prefix)).inventory?.environments ?? [];
|
|
32103
|
+
} catch {
|
|
32104
|
+
}
|
|
32105
|
+
if (!list.length) return { value: list, text: "No replacements are recorded. Run backify handoff check to see what Backify hosts for you, then backify handoff replacements add." };
|
|
32106
|
+
const kindOf = (id) => environments.find((item) => item.id === id)?.kind ?? id;
|
|
32107
|
+
const rows = pad4([["ENVIRONMENT", "FOR", "STATE", "SECRET NAME", "ID"], ...list.map((item) => [kindOf(item.environmentId), subjectText(item), replacementState(item), item.secretReference, item.id])]);
|
|
32108
|
+
const problems = list.filter((item) => item.verification === "failed" || item.verification === "unverified").flatMap((item) => [" " + subjectText(item) + " (" + kindOf(item.environmentId) + "): " + replacementReason(item.verificationCode)]);
|
|
32109
|
+
return { value: list, text: [...rows, ...problems.length ? ["", "Not verified:", ...problems] : []].join("\n") };
|
|
32110
|
+
}
|
|
32111
|
+
async function runHandoff(call2, applicationId, options, context2 = {}) {
|
|
32112
|
+
if (!uuid12.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
32113
|
+
const prefix = "/apps/" + applicationId + "/handoff";
|
|
32114
|
+
if (options.action === "foundation") return runFoundation(call2, prefix, options.out);
|
|
32115
|
+
if (options.action === "package") return runPackage(call2, prefix, options);
|
|
32116
|
+
if (options.action === "replacements") return runReplacements(call2, prefix, options, context2);
|
|
32117
|
+
if (options.action === "status") {
|
|
32118
|
+
const status = await call2(prefix);
|
|
32119
|
+
return { value: status, text: handoffStatusText(status) };
|
|
32120
|
+
}
|
|
32121
|
+
if (options.action === "check" || options.action === "request") {
|
|
32122
|
+
const preflight = await call2(prefix + "/preflight");
|
|
32123
|
+
const failed = failedIds(preflight.checks), table = checkRows(preflight.checks);
|
|
32124
|
+
if (!preflight.ready) return { exitCode: 2, value: { status: "blocked", failed, checks: preflight.checks, inventory: preflight.inventory }, text: [table, "", ...inventoryText(preflight.inventory), "", "This application cannot be handed off yet" + (failed.length ? ": " + preflight.checks.filter((check) => check.state === "failed").map((check) => check.name).join(", ") : "") + ". Nothing was changed."].join("\n") };
|
|
32125
|
+
if (options.action === "check") return { value: { status: "ready", checks: preflight.checks, inventory: preflight.inventory }, text: [table, "", ...inventoryText(preflight.inventory), "", "All checks passed. Nothing was changed; run backify handoff request --confirm <application-slug> to request the handoff."].join("\n") };
|
|
32126
|
+
if (!options.confirm) {
|
|
32127
|
+
const slug = (await call2("/apps/" + applicationId)).slug;
|
|
32128
|
+
throw new CommandError("Requesting a handoff gives the application to you and removes the access Backify holds. Another person must approve it, and you can abort it before it is delivered.\nConfirm with the application slug: backify handoff request --confirm " + (slug ?? "<application-slug>"), "confirmation_required", slug ? { confirm: slug } : {});
|
|
32129
|
+
}
|
|
32130
|
+
const result = await call2(prefix, { method: "POST", body: JSON.stringify({ confirmation: options.confirm }) });
|
|
32131
|
+
if (!result.created || !result.handoff) return { exitCode: 2, value: { status: "blocked", failed: failedIds(result.preflight.checks), checks: result.preflight.checks }, text: "The checks no longer pass. Nothing was changed." };
|
|
32132
|
+
return { value: { status: "requested", handoff: result.handoff }, text: ["The handoff awaits approval. Another person approves it on the organization's Approvals page.", "", ...handoffLines(result.handoff)].join("\n") };
|
|
32133
|
+
}
|
|
32134
|
+
const action = options.action;
|
|
32135
|
+
const current = (await call2(prefix)).handoff;
|
|
32136
|
+
if (!current) throw new CommandError("This application has no handoff.", "app_handoff_not_found");
|
|
32137
|
+
if (!current.actions?.includes(action)) throw new CommandError("The handoff does not offer " + action + " now: it is in phase " + current.phase + ", state " + current.state + (current.approvalStatus ? ", approval " + current.approvalStatus : "") + ".", "handoff_action_unavailable", { action, phase: current.phase, state: current.state, actions: current.actions ?? [] });
|
|
32138
|
+
const resume = action === "start" && current.state === "stopped";
|
|
32139
|
+
if (resume && !options.azureSessionId && current.humanTasks?.some((task) => task.kind === "destination-access" && task.state === "pending"))
|
|
32140
|
+
throw new CommandError("Open the application's Handoff page and sign in as the owner Azure administrator to verify access. You can finish there or pass the returned session ID with --azure-session.", "app_handoff_destination_access_unverified");
|
|
32141
|
+
const summary = action === "abort" ? "Abort the handoff. The application stays with Backify and nothing more is changed. Access that was already removed is not restored." : (resume ? "Resume" : "Start") + " the handoff. Backify prepares your Azure, switches the hostnames you keep and then removes the access it holds. After it is delivered, every change to the application in Backify is refused.";
|
|
32142
|
+
if (!options.yes) {
|
|
32143
|
+
if (!context2.confirm) throw new CommandError("Refusing to change a handoff without confirmation. Review this and re-run with --yes:\n" + summary, "confirmation_required", { action });
|
|
32144
|
+
if (!await context2.confirm(summary)) throw new CommandError("Not confirmed. Nothing was changed.", "not_confirmed");
|
|
32145
|
+
}
|
|
32146
|
+
const updated = await call2(prefix + "/" + action, { method: "POST", ...options.azureSessionId ? { body: JSON.stringify({ azureSessionId: options.azureSessionId }) } : {} });
|
|
32147
|
+
return { value: { status: action, handoff: updated }, text: ["The handoff: " + (resume ? "resume" : action) + " accepted.", "", ...handoffLines(updated)].join("\n") };
|
|
32148
|
+
}
|
|
32149
|
+
var handoffHelp, secretFlag, replacementKinds, addOnlyFlags, validSecretName, secretRefusal, addOnlyMessage, uuid12, checkRows, failedIds, sizeText, manifestFiles, sha2562, normalizedHash, reasons, replacementReason, subjectText, consentSummary;
|
|
32150
|
+
var init_handoff = __esm({
|
|
32151
|
+
"src/handoff.ts"() {
|
|
32152
|
+
"use strict";
|
|
32153
|
+
init_release_flow();
|
|
32154
|
+
handoffHelp = [
|
|
32155
|
+
"Usage: backify handoff [status|check|request|start|abort|foundation|package] [options]",
|
|
32156
|
+
"",
|
|
32157
|
+
" backify handoff [status] State, phase, summary, hosts, tasks only you can do and access removal progress",
|
|
32158
|
+
" backify handoff check The checks and what would be handed over; exit 2 when the application cannot be handed off yet",
|
|
32159
|
+
" backify handoff request --confirm <application-slug>",
|
|
32160
|
+
" Run the checks, then request the handoff; another person approves it (exit 2 if a check fails)",
|
|
32161
|
+
" backify handoff start|abort [--yes] Start (or resume) an approved handoff, or abort it before it is delivered",
|
|
32162
|
+
" backify handoff start --azure-session <id> Verify owner Azure access and resume after administrator sign-in in the Portal",
|
|
32163
|
+
" backify handoff foundation [--out <directory>] Get the owner foundation and Runtime templates before handoff",
|
|
32164
|
+
" backify handoff package [--out <directory>] The handoff package manifest; --out writes every file there and verifies its checksum",
|
|
32165
|
+
" backify handoff replacements Your replacements for what Backify hosts (mail, AI, integrations, sign-in) and whether each was verified",
|
|
32166
|
+
" backify handoff replacements add --environment <name|id|kind> --kind <mail|ai|integration|auth-provider> --subject <subject>",
|
|
32167
|
+
" [--setting key=value ...] --secret-name <vault secret name> --consent",
|
|
32168
|
+
" Record a replacement. Store the secret itself in your environment's vault and give only its name here",
|
|
32169
|
+
" backify handoff replacements verify <id> Ask your environment to check a replacement again",
|
|
32170
|
+
" backify handoff replacements remove <id> [--yes] Remove a replacement; the dependency counts as hosted by Backify again",
|
|
32171
|
+
"",
|
|
32172
|
+
"Replacement subjects: mail and ai use their own name; integration uses the connection ID; auth-provider uses entra or google.",
|
|
32173
|
+
"Replacement settings: mail host, port, security (starttls or tls), username, sender, senderName, replyTo; ai endpoint and deployments.<model>=<deployment>;",
|
|
32174
|
+
"integration probeOperation; auth-provider clientId and tenantId (entra only). Secrets are never accepted on the command line.",
|
|
32175
|
+
"Runtime OAuth uses an approved read-only probeOperation and a Runtime vault reference backify-oauth-<environmentId>-<connectionId> with both IDs lowercase and without hyphens.",
|
|
32176
|
+
"",
|
|
32177
|
+
"Options: --app <application> (default: the application in this folder) --json (machine-readable output and errors)",
|
|
32178
|
+
"A handoff gives you the application to run independently in your own Azure and removes the access Backify holds.",
|
|
32179
|
+
"After it is delivered, every change to the application in Backify is refused."
|
|
32180
|
+
].join("\n");
|
|
32181
|
+
secretFlag = /^--(secret|secret-value|secret-text|value|password|passphrase|token|api-key|apikey|key|client-secret|credential|credentials|connection-string)(=|$)/i;
|
|
32182
|
+
replacementKinds = ["mail", "ai", "integration", "auth-provider"];
|
|
32183
|
+
addOnlyFlags = ["--environment", "--kind", "--subject", "--secret-name"];
|
|
32184
|
+
validSecretName = (name2) => /^[A-Za-z0-9-]{1,127}$/.test(name2) && !name2.toLowerCase().startsWith("backify-rt-");
|
|
32185
|
+
secretRefusal = "A secret value is never accepted on the command line, where it would stay in your shell history. Store the secret in your environment's vault, then pass only its name with --secret-name <vault secret name>.";
|
|
32186
|
+
addOnlyMessage = "--environment, --kind, --subject, --setting, --secret-name and --consent apply to handoff replacements add.";
|
|
32187
|
+
uuid12 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
32188
|
+
checkRows = (checks) => pad4([["CHECK", "RESULT", "DETAIL"], ...checks.map((check) => [check.name, check.state, check.detail ?? ""])]);
|
|
32189
|
+
failedIds = (checks) => checks.filter((check) => check.state === "failed").map((check) => check.id);
|
|
32190
|
+
sizeText = (bytes) => bytes === void 0 ? "" : bytes < 1024 ? bytes + " B" : bytes < 1024 * 1024 ? (bytes / 1024).toFixed(1) + " KB" : (bytes / 1024 / 1024).toFixed(1) + " MB";
|
|
32191
|
+
manifestFiles = (manifest) => Array.isArray(manifest.files) ? manifest.files.map((file) => ({ ...file, path: file.name ?? file.path ?? "" })) : [];
|
|
32192
|
+
sha2562 = (text2) => createHash5("sha256").update(text2, "utf8").digest("hex");
|
|
32193
|
+
normalizedHash = (value) => value.trim().toLowerCase().replace(/^sha256[:-]/, "");
|
|
32194
|
+
reasons = {
|
|
32195
|
+
replacement_secret_missing: "There is no secret with that name in your environment's vault.",
|
|
32196
|
+
replacement_credential_rejected: "The service did not accept the credential.",
|
|
32197
|
+
replacement_probe_failed: "The check could not reach the service.",
|
|
32198
|
+
replacement_settings_invalid: "Your environment did not accept the settings.",
|
|
32199
|
+
replacement_probe_unavailable: "There is no safe check for this replacement yet. For an integration, record a read-only operation as --setting probeOperation=<operation>."
|
|
32200
|
+
};
|
|
32201
|
+
replacementReason = (code) => (code ? reasons[code] : void 0) ?? "The check did not pass. Check the settings and the secret name, then run backify handoff replacements verify <id>.";
|
|
32202
|
+
subjectText = (replacement) => replacement.kind === "mail" || replacement.kind === "ai" ? replacement.kind : replacement.kind + " " + replacement.subject;
|
|
32203
|
+
consentSummary = (kind2, subject, environment, secretName) => "Recording a replacement means you state that the secret named " + secretName + " in your environment's vault is yours, that the settings you give are yours, and that they replace what Backify hosts for " + subjectText({ kind: kind2, subject }) + " in " + environment + ". Your environment then checks it.";
|
|
32204
|
+
}
|
|
32205
|
+
});
|
|
32206
|
+
|
|
32207
|
+
// src/logs-history.ts
|
|
32208
|
+
var logs_history_exports = {};
|
|
32209
|
+
__export(logs_history_exports, {
|
|
32210
|
+
LOG_STREAMS: () => LOG_STREAMS,
|
|
32211
|
+
MAX_HISTORY_PAGES: () => MAX_HISTORY_PAGES,
|
|
32212
|
+
historyPath: () => historyPath,
|
|
32213
|
+
logsArguments: () => logsArguments,
|
|
32214
|
+
logsHelp: () => logsHelp,
|
|
32215
|
+
parseDuration: () => parseDuration,
|
|
32216
|
+
resolveEnvironment: () => resolveEnvironment2,
|
|
32217
|
+
runLogsHistory: () => runLogsHistory,
|
|
32218
|
+
runLogsRecent: () => runLogsRecent
|
|
32219
|
+
});
|
|
32220
|
+
function parseDuration(value) {
|
|
32221
|
+
const match = /^(\d{1,4})([mhd])$/.exec(value);
|
|
32222
|
+
const amount = match ? Number(match[1]) : 0;
|
|
32223
|
+
if (!match || amount < 1) throw new Error("--since takes a duration such as 30m, 24h or 7d.");
|
|
32224
|
+
return amount * { m: 6e4, h: 36e5, d: 864e5 }[match[2]];
|
|
32225
|
+
}
|
|
32226
|
+
function isoTime(flag, value) {
|
|
32227
|
+
const time3 = /^\d{4}-\d{2}-\d{2}(?:T.*)?$/.test(value) ? new Date(value) : /* @__PURE__ */ new Date(NaN);
|
|
32228
|
+
if (Number.isNaN(time3.getTime())) throw new Error(flag + " takes an ISO time such as 2026-11-14T08:00:00Z.");
|
|
32229
|
+
return time3.toISOString();
|
|
32230
|
+
}
|
|
32231
|
+
function logsArguments(args2) {
|
|
32232
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
32233
|
+
const { flags, values, positional } = parse(args2, "logs", ["--all", "--json"], ["--app", "--environment", "--stream", "--since", "--from", "--to", "--contains", "--limit"]);
|
|
32234
|
+
if (!(positional[0] === "history" || positional[0] === "recent") || positional.length > 1) throw new Error("Unknown logs command. Use backify logs history or backify logs recent.\n\n" + logsHelp);
|
|
32235
|
+
const kind2 = values["--environment"]?.toLowerCase();
|
|
32236
|
+
if (positional[0] === "recent") {
|
|
32237
|
+
if (Object.keys(values).some((flag) => flag !== "--app" && flag !== "--environment") || flags.has("--all")) throw new Error("backify logs recent takes only --environment, --app and --json.");
|
|
32238
|
+
if (kind2 && !(uuid13.test(kind2) || ENVIRONMENT_FLOW.includes(kind2))) throw new Error("--environment takes prototype, preview, production or an environment UUID.");
|
|
32239
|
+
return { action: "recent", ...kind2 ? { environment: kind2 } : {}, json: flags.has("--json") };
|
|
32240
|
+
}
|
|
32241
|
+
if (!kind2 || !(uuid13.test(kind2) || ENVIRONMENT_FLOW.includes(kind2)))
|
|
32242
|
+
throw new Error("--environment takes prototype, preview, production or an environment UUID.");
|
|
32243
|
+
const stream = values["--stream"]?.toLowerCase() ?? "console";
|
|
32244
|
+
if (!LOG_STREAMS.includes(stream)) throw new Error("--stream takes console, system or audit.");
|
|
32245
|
+
if (values["--since"] && (values["--from"] || values["--to"])) throw new Error("Use either --since or --from/--to, not both.");
|
|
32246
|
+
const from = values["--from"] ? isoTime("--from", values["--from"]) : void 0, to = values["--to"] ? isoTime("--to", values["--to"]) : void 0;
|
|
32247
|
+
if (from && to && Date.parse(to) <= Date.parse(from)) throw new Error("--to must be after --from.");
|
|
32248
|
+
const limitText = values["--limit"];
|
|
32249
|
+
if (limitText !== void 0 && (!/^\d{1,4}$/.test(limitText) || Number(limitText) < 1 || Number(limitText) > 1e3)) throw new Error("--limit takes a number from 1 to 1000.");
|
|
32250
|
+
return { environment: kind2, stream, sinceMs: values["--since"] ? parseDuration(values["--since"]) : void 0, from, to, contains: values["--contains"], limit: limitText ? Number(limitText) : DEFAULT_LIMIT, all: flags.has("--all"), json: flags.has("--json") };
|
|
32251
|
+
}
|
|
32252
|
+
async function resolveEnvironment2(call2, prefix, environment) {
|
|
32253
|
+
if (uuid13.test(environment)) return environment;
|
|
32254
|
+
const view = await call2(prefix + "/environments/options");
|
|
32255
|
+
const option2 = view.options.find((item) => item.kind === environment);
|
|
32256
|
+
if (!option2?.activated || !option2.environmentId) throw new CommandError("This application has no " + environment + " environment. Run backify environments to see the activated ones.", "environment_not_activated", { kind: environment });
|
|
32257
|
+
return option2.environmentId;
|
|
32258
|
+
}
|
|
32259
|
+
function historyPath(prefix, environmentId, options, range, continuation) {
|
|
32260
|
+
const query = new URLSearchParams({ environmentId, stream: options.stream });
|
|
32261
|
+
if (range.from) query.set("from", range.from);
|
|
32262
|
+
if (range.to) query.set("to", range.to);
|
|
32263
|
+
if (options.contains) query.set("contains", options.contains);
|
|
32264
|
+
query.set("limit", String(options.limit));
|
|
32265
|
+
if (continuation) query.set("continuation", continuation);
|
|
32266
|
+
return prefix + "/logs/history?" + query.toString().replace(/\+/g, "%20");
|
|
32267
|
+
}
|
|
32268
|
+
async function runLogsRecent(call2, applicationId, options) {
|
|
32269
|
+
if (!uuid13.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
32270
|
+
const prefix = "/apps/" + applicationId;
|
|
32271
|
+
const environmentId = options.environment ? await resolveEnvironment2(call2, prefix, options.environment) : void 0;
|
|
32272
|
+
const lines = await call2(prefix + "/logs" + (environmentId ? "?environmentId=" + encodeURIComponent(environmentId) : ""));
|
|
32273
|
+
return { value: { ...environmentId ? { environmentId } : {}, lines }, text: lines.length ? lines.join("\n") : "No recent log lines." };
|
|
32274
|
+
}
|
|
32275
|
+
async function runLogsHistory(call2, applicationId, options, now = /* @__PURE__ */ new Date()) {
|
|
32276
|
+
if (!uuid13.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
32277
|
+
const prefix = "/apps/" + applicationId;
|
|
32278
|
+
const environmentId = await resolveEnvironment2(call2, prefix, options.environment);
|
|
32279
|
+
const range = options.from || options.to ? { from: options.from, to: options.to } : { from: new Date(now.getTime() - (options.sinceMs ?? DEFAULT_SINCE_MS)).toISOString(), to: now.toISOString() };
|
|
32280
|
+
const lines = [];
|
|
32281
|
+
let dropped = 0, earliest = null, continuation = null, pages = 0;
|
|
32282
|
+
do {
|
|
32283
|
+
const page = await call2(historyPath(prefix, environmentId, options, range, continuation));
|
|
32284
|
+
pages++;
|
|
32285
|
+
lines.push(...page.lines);
|
|
32286
|
+
dropped += page.droppedLines;
|
|
32287
|
+
earliest = page.earliestAvailable ?? earliest;
|
|
32288
|
+
continuation = page.continuation;
|
|
32289
|
+
} while (options.all && continuation && pages < MAX_HISTORY_PAGES);
|
|
32290
|
+
const capped = options.all && continuation !== null;
|
|
32291
|
+
const value = { environmentId, stream: options.stream, lines, droppedLines: dropped, earliestAvailable: earliest, continuation, pages, ...capped ? { capped: true } : {} };
|
|
32292
|
+
const text2 = [
|
|
32293
|
+
...lines.length ? [...lines].reverse().map((line2) => `${line2.time} ${line2.level.padEnd(5)} ${line2.message}`) : ["No log lines in this range."],
|
|
32294
|
+
...dropped > 0 ? ["", `${dropped} ${dropped === 1 ? "line was" : "lines were"} dropped because this environment went over its daily log budget.`] : [],
|
|
32295
|
+
...earliest ? [...dropped > 0 ? [] : [""], `Logs are kept for a limited time. The earliest available entry is ${earliest}.`] : [],
|
|
32296
|
+
...capped ? ["", `Stopped after ${MAX_HISTORY_PAGES} pages; older lines remain. Narrow the range or add --contains.`] : continuation ? ["", "Older lines are available. Use --all or a larger --limit."] : []
|
|
32297
|
+
].join("\n");
|
|
32298
|
+
return { value, text: text2 };
|
|
32299
|
+
}
|
|
32300
|
+
var LOG_STREAMS, MAX_HISTORY_PAGES, DEFAULT_LIMIT, DEFAULT_SINCE_MS, uuid13, logsHelp;
|
|
32301
|
+
var init_logs_history = __esm({
|
|
32302
|
+
"src/logs-history.ts"() {
|
|
32303
|
+
"use strict";
|
|
32304
|
+
init_release_flow();
|
|
32305
|
+
LOG_STREAMS = ["console", "system", "audit"];
|
|
32306
|
+
MAX_HISTORY_PAGES = 20;
|
|
32307
|
+
DEFAULT_LIMIT = 200;
|
|
32308
|
+
DEFAULT_SINCE_MS = 36e5;
|
|
32309
|
+
uuid13 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
32310
|
+
logsHelp = [
|
|
32311
|
+
"Usage: backify logs history --environment <prototype|preview|production|UUID> [options]",
|
|
32312
|
+
" backify logs recent [--environment <prototype|preview|production|UUID>] [--json]",
|
|
32313
|
+
"",
|
|
32314
|
+
" recent The latest runtime log lines from the environment's hosting. --environment is needed once",
|
|
32315
|
+
" the application's environments run on different hosting targets",
|
|
32316
|
+
"",
|
|
32317
|
+
" --stream console|system|audit Which log stream to read (default: console)",
|
|
32318
|
+
" --since <duration> How far back to read: a number and m, h or d, such as 30m, 24h or 7d (default: 1h)",
|
|
32319
|
+
" --from <ISO> --to <ISO> An explicit time range instead of --since (either may be given alone)",
|
|
32320
|
+
" --contains <text> Only lines that contain this text",
|
|
32321
|
+
" --limit <n> Lines per page, 1 to 1000 (default: 200)",
|
|
32322
|
+
" --all Follow older pages, at most " + MAX_HISTORY_PAGES + " pages",
|
|
32323
|
+
" --json Print the merged API result; errors are JSON too",
|
|
32324
|
+
" --app <application> Default: the application in this folder",
|
|
32325
|
+
"",
|
|
32326
|
+
"Reads stored logs from the environment's hosting. Lines print oldest first. Reading history is recorded in the audit log."
|
|
32327
|
+
].join("\n");
|
|
32328
|
+
}
|
|
32329
|
+
});
|
|
32330
|
+
|
|
32331
|
+
// src/monitoring.ts
|
|
32332
|
+
var monitoring_exports = {};
|
|
32333
|
+
__export(monitoring_exports, {
|
|
32334
|
+
MONITORING_RANGES: () => MONITORING_RANGES,
|
|
32335
|
+
monitoringArguments: () => monitoringArguments,
|
|
32336
|
+
monitoringHelp: () => monitoringHelp,
|
|
32337
|
+
runMonitoring: () => runMonitoring
|
|
32338
|
+
});
|
|
32339
|
+
function monitoringArguments(args2) {
|
|
32340
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
32341
|
+
const { flags, values, positional } = parse(args2, "monitoring", ["--json"], ["--app", "--environment", "--range"]);
|
|
32342
|
+
if (positional.length) throw new Error("Unknown monitoring command: " + positional.join(" ") + "\n\n" + monitoringHelp);
|
|
32343
|
+
const environment = values["--environment"]?.toLowerCase();
|
|
32344
|
+
if (environment && !(uuid14.test(environment) || ENVIRONMENT_FLOW.includes(environment))) throw new Error("--environment takes prototype, preview, production or an environment UUID.");
|
|
32345
|
+
const range = values["--range"]?.toLowerCase() ?? "24h";
|
|
32346
|
+
if (!MONITORING_RANGES.includes(range)) throw new Error("--range takes 1h, 6h, 24h or 7d.");
|
|
32347
|
+
return { ...environment ? { environment } : {}, range, json: flags.has("--json") };
|
|
32348
|
+
}
|
|
32349
|
+
async function runMonitoring(call2, applicationId, options) {
|
|
32350
|
+
if (!uuid14.test(applicationId)) throw new Error("Use a valid application ID.");
|
|
32351
|
+
const prefix = "/apps/" + applicationId;
|
|
32352
|
+
const environmentId = options.environment ? await resolveEnvironment2(call2, prefix, options.environment) : void 0;
|
|
32353
|
+
const query = new URLSearchParams({ range: options.range });
|
|
32354
|
+
if (environmentId) query.set("environmentId", environmentId);
|
|
32355
|
+
const snapshot = await call2(prefix + "/monitoring?" + query.toString());
|
|
32356
|
+
const rows = [["METRIC", "UNIT", "LATEST", "PEAK"], ...snapshot.metrics.map((metric) => [metric.name, metric.unit, reading(metric.points.at(-1)?.value), reading(metric.points.length ? Math.max(...metric.points.map((point) => point.value)) : void 0)])];
|
|
32357
|
+
const text2 = [
|
|
32358
|
+
"Collected " + snapshot.collectedAt + (snapshot.stale ? " (stale: the provider is unavailable, so these are the last readings)" : "") + ". Availability: " + snapshot.availability + ".",
|
|
32359
|
+
...snapshot.runtime ? ["Observed runtime: " + snapshot.runtime.state + " (" + snapshot.runtime.providerState + ") at " + snapshot.runtime.observedAt + "."] : [],
|
|
32360
|
+
"",
|
|
32361
|
+
...snapshot.metrics.length ? pad(rows) : ["No metrics were reported for this range."]
|
|
32362
|
+
].join("\n");
|
|
32363
|
+
return { value: { ...environmentId ? { environmentId } : {}, range: options.range, ...snapshot }, text: text2 };
|
|
32364
|
+
}
|
|
32365
|
+
var MONITORING_RANGES, uuid14, monitoringHelp, reading;
|
|
32366
|
+
var init_monitoring = __esm({
|
|
32367
|
+
"src/monitoring.ts"() {
|
|
32368
|
+
"use strict";
|
|
32369
|
+
init_logs_history();
|
|
32370
|
+
init_release_flow();
|
|
32371
|
+
MONITORING_RANGES = ["1h", "6h", "24h", "7d"];
|
|
32372
|
+
uuid14 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
32373
|
+
monitoringHelp = [
|
|
32374
|
+
"Usage: backify monitoring [--environment <prototype|preview|production|UUID>] [--range 1h|6h|24h|7d] [--json]",
|
|
32375
|
+
"",
|
|
32376
|
+
"Runtime metrics of one environment, read through the Runtime of the hosting target it runs on: the latest and peak",
|
|
32377
|
+
"reading of each metric over the range (default 24h). Without --environment it reads production; --environment is",
|
|
32378
|
+
"needed once the application's environments run on different hosting targets. Deployment state does not verify uptime.",
|
|
32379
|
+
" --app <application> Default: the application in this folder"
|
|
32380
|
+
].join("\n");
|
|
32381
|
+
reading = (value) => value === void 0 ? "-" : Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
32382
|
+
}
|
|
32383
|
+
});
|
|
32384
|
+
|
|
32385
|
+
// src/operation-progress.ts
|
|
32386
|
+
var operation_progress_exports = {};
|
|
32387
|
+
__export(operation_progress_exports, {
|
|
32388
|
+
operationArguments: () => operationArguments,
|
|
32389
|
+
operationHelp: () => operationHelp,
|
|
32390
|
+
runOperation: () => runOperation
|
|
32391
|
+
});
|
|
32392
|
+
function operationArguments(args2) {
|
|
32393
|
+
if (args2.includes("--help") || args2.includes("-h")) return "help";
|
|
32394
|
+
const { flags, positional } = parse(args2, "operation", ["--wait", "--json"], ["--app"]);
|
|
32395
|
+
if (positional.length !== 1 || !uuid15.test(positional[0])) throw new Error("Use backify operation <operation-id> [--wait] [--json].");
|
|
32396
|
+
return { operationId: positional[0].toLowerCase(), wait: flags.has("--wait"), json: flags.has("--json") };
|
|
32397
|
+
}
|
|
32398
|
+
async function runOperation(call2, options, context2 = {}) {
|
|
32399
|
+
const path = "/operations/" + options.operationId;
|
|
32400
|
+
const sleep = context2.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
|
|
32401
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32402
|
+
let operation = await call2(path), logs = await call2(path + "/logs");
|
|
32403
|
+
for (let poll = 0; options.wait && !finished.has(operation.status) && poll < (context2.maxPolls ?? 1200); poll++) {
|
|
32404
|
+
for (const entry of logs) if (!seen.has(entry.id)) {
|
|
32405
|
+
seen.add(entry.id);
|
|
32406
|
+
context2.progress?.(line(entry));
|
|
32407
|
+
}
|
|
32408
|
+
await sleep(context2.intervalMs ?? 3e3);
|
|
32409
|
+
[operation, logs] = [await call2(path), await call2(path + "/logs")];
|
|
32410
|
+
}
|
|
32411
|
+
const text2 = [
|
|
32412
|
+
"Operation " + operation.id + " (" + operation.kind + "): " + operation.status + (operation.errorMessage ? ". " + operation.errorMessage : operation.errorCode ? " (" + operation.errorCode + ")" : ""),
|
|
32413
|
+
...logs.some((entry) => !seen.has(entry.id)) ? ["", ...logs.filter((entry) => !seen.has(entry.id)).map(line)] : []
|
|
32414
|
+
].join("\n");
|
|
32415
|
+
return { value: { operation, logs }, text: text2, ...operation.status === "failed" ? { exitCode: 1 } : options.wait && !finished.has(operation.status) ? { exitCode: 2 } : {} };
|
|
32416
|
+
}
|
|
32417
|
+
var uuid15, finished, operationHelp, line;
|
|
32418
|
+
var init_operation_progress = __esm({
|
|
32419
|
+
"src/operation-progress.ts"() {
|
|
32420
|
+
"use strict";
|
|
32421
|
+
init_release_flow();
|
|
32422
|
+
uuid15 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
32423
|
+
finished = /* @__PURE__ */ new Set(["succeeded", "failed", "cancelled"]);
|
|
32424
|
+
operationHelp = [
|
|
32425
|
+
"Usage: backify operation <operation-id> [--wait] [--json]",
|
|
32426
|
+
"",
|
|
32427
|
+
"Shows a background operation's state and activity log, such as deleting an application or connecting a repository.",
|
|
32428
|
+
"When an application's environments run on different hosting targets, the log has one line per target as it is",
|
|
32429
|
+
"removed or prepared, and a failure names the target. --wait follows the log until the operation finishes",
|
|
32430
|
+
"(exit 1 when it failed).",
|
|
32431
|
+
" --app <application> Read it with this application's session (default: the application in this folder, or your sign-in)"
|
|
32432
|
+
].join("\n");
|
|
32433
|
+
line = (entry) => entry.createdAt + " " + entry.level.padEnd(11) + " " + entry.message;
|
|
32434
|
+
}
|
|
32435
|
+
});
|
|
32436
|
+
|
|
30942
32437
|
// src/index.ts
|
|
30943
32438
|
init_project_metadata();
|
|
30944
32439
|
|
|
@@ -31139,22 +32634,22 @@ async function diagnoseEnvironment(root = process.cwd(), options = {}, probes =
|
|
|
31139
32634
|
|
|
31140
32635
|
// src/integrations.ts
|
|
31141
32636
|
function integrationDiscoveryPath(command2, options) {
|
|
31142
|
-
const
|
|
31143
|
-
if (!
|
|
32637
|
+
const uuid16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
32638
|
+
if (!uuid16.test(options.applicationId)) throw new Error("An application UUID is required");
|
|
31144
32639
|
const base = "/apps/" + options.applicationId + "/integrations/connectors";
|
|
31145
32640
|
if (command2 === "list") return base;
|
|
31146
32641
|
if (command2 === "catalog") return "/apps/" + options.applicationId + "/integrations/catalog";
|
|
31147
32642
|
if (command2 === "discover") return "/apps/" + options.applicationId + "/integrations/discover?" + new URLSearchParams({ query: options.query ?? "" });
|
|
31148
32643
|
if (command2 === "prepare") return "/apps/" + options.applicationId + "/integrations/prepare";
|
|
31149
32644
|
if (command2 === "contract" && options.revisionId) {
|
|
31150
|
-
if (!
|
|
32645
|
+
if (!uuid16.test(options.revisionId)) throw new Error("Use --revision with a discovered revision UUID");
|
|
31151
32646
|
return "/apps/" + options.applicationId + "/integrations/definitions/" + options.revisionId;
|
|
31152
32647
|
}
|
|
31153
32648
|
if (command2 === "status") {
|
|
31154
|
-
if (!options.adoptionId || !
|
|
32649
|
+
if (!options.adoptionId || !uuid16.test(options.adoptionId)) throw new Error("Use --adoption with an adoption request UUID");
|
|
31155
32650
|
return "/apps/" + options.applicationId + "/integrations/adoptions/" + options.adoptionId;
|
|
31156
32651
|
}
|
|
31157
|
-
if (!options.connectionId || !
|
|
32652
|
+
if (!options.connectionId || !uuid16.test(options.connectionId)) throw new Error("Use --connection with an integration connection UUID");
|
|
31158
32653
|
const connection2 = base + "/" + options.connectionId;
|
|
31159
32654
|
if (command2 === "contract" || command2 === "types") return connection2 + "/" + command2;
|
|
31160
32655
|
if (command2 === "describe") {
|
|
@@ -31175,6 +32670,19 @@ function integrationPreparation(input) {
|
|
|
31175
32670
|
if (!["application", "user"].includes(mode) || !operations.length || operations.length > 500 || new Set(operations).size !== operations.length) throw new Error("Use --mode application|user and distinct --operations separated by commas");
|
|
31176
32671
|
return { definitionId: input.definitionId, revisionId: input.revisionId, environmentId: input.environmentId, mode, operations };
|
|
31177
32672
|
}
|
|
32673
|
+
var integrationWebhooksUsage = "Use backify integrations webhooks|webhook-deliveries --connection <UUID> --environment <UUID>, webhook-job with --binding <UUID> --job <name>, or webhook-replay with --receipt <UUID> --yes.";
|
|
32674
|
+
function integrationWebhookCall(command2, options) {
|
|
32675
|
+
const uuid16 = /^(?:[a-f0-9]{8}-)(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$/i;
|
|
32676
|
+
if (!options.connectionId || !options.environmentId || ![options.applicationId, options.connectionId, options.environmentId].every((id) => uuid16.test(id))) throw new Error(integrationWebhooksUsage);
|
|
32677
|
+
const path = "/apps/" + options.applicationId + "/integrations/connectors/" + options.connectionId;
|
|
32678
|
+
if (command2 === "webhooks" || command2 === "webhook-deliveries") return { path: path + "/" + command2 + "?" + new URLSearchParams({ environmentId: options.environmentId }) };
|
|
32679
|
+
const headers = { "content-type": "application/json" };
|
|
32680
|
+
if (command2 === "webhook-job" && options.bindingId && uuid16.test(options.bindingId) && /^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$/.test(options.job ?? ""))
|
|
32681
|
+
return { path: path + "/webhooks/" + options.bindingId, init: { method: "PUT", headers, body: JSON.stringify({ environmentId: options.environmentId, job: options.job }) } };
|
|
32682
|
+
if (command2 === "webhook-replay" && options.receiptId && uuid16.test(options.receiptId) && options.confirm)
|
|
32683
|
+
return { path: path + "/webhook-deliveries/" + options.receiptId + "/replay", init: { method: "POST", headers, body: JSON.stringify({ environmentId: options.environmentId, confirm: true }) } };
|
|
32684
|
+
throw new Error(integrationWebhooksUsage);
|
|
32685
|
+
}
|
|
31178
32686
|
|
|
31179
32687
|
// src/integration-connect.ts
|
|
31180
32688
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -31307,28 +32815,32 @@ function integrationConnectArguments(args2) {
|
|
|
31307
32815
|
}
|
|
31308
32816
|
|
|
31309
32817
|
// src/domain-connect.ts
|
|
32818
|
+
init_release_flow();
|
|
31310
32819
|
init_human_task();
|
|
31311
32820
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
31312
32821
|
import { domainToASCII } from "node:url";
|
|
31313
|
-
var domainConnectHelp = `backify domains connect [hostname] [--app <application>] [--environment
|
|
32822
|
+
var domainConnectHelp = `backify domains connect [hostname] [--app <application>] [--environment <environment>]
|
|
31314
32823
|
backify domains connect --request <UUID> [--app <application>]
|
|
31315
32824
|
Options: --hostname <hostname> --no-browser --no-wait --timeout <seconds, 1-3600> --json
|
|
32825
|
+
--environment takes one of the application's activated environments, in release order
|
|
32826
|
+
prototype|preview|production (backify environments lists them); omit it to choose in the browser.
|
|
31316
32827
|
Requests a Backify task and opens its page, where an authorized user signs in
|
|
31317
32828
|
and confirms the hostname and environment. Returns as soon as the domain is confirmed. It does not wait for DNS: Backify verifies the DNS records, issues managed HTTPS and starts
|
|
31318
32829
|
routing automatically once the user adds them. Exit code 0 means confirmed; 2 means not yet confirmed or blocked.
|
|
31319
32830
|
Re-run with --request <task-id> to read the current status without reopening the browser.`;
|
|
31320
32831
|
var kind = "domain.confirm";
|
|
31321
|
-
var
|
|
32832
|
+
var uuid5 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
31322
32833
|
var confirmedStates = ["dns_required", "certificate_pending", "ready"];
|
|
31323
32834
|
function customHostname(input) {
|
|
31324
32835
|
const hostname3 = domainToASCII(input.trim().replace(/\.$/, "")).toLowerCase(), labels = hostname3.split(".");
|
|
31325
32836
|
if (/[\s:/\\@?#%*]/.test(input.trim()) || hostname3.length > 253 || labels.length < 2 || labels.some((label) => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label)) || !/^[a-z][a-z0-9-]*$/.test(labels.at(-1)) || ["backify.dev", "backify.site"].some((suffix) => hostname3 === suffix || hostname3.endsWith("." + suffix))) throw new Error("Use a custom DNS hostname without a URL, path, port or wildcard.");
|
|
31326
32837
|
return hostname3;
|
|
31327
32838
|
}
|
|
32839
|
+
var knownEnvironment = (value) => ENVIRONMENT_FLOW.includes(value ?? "");
|
|
31328
32840
|
function validate(status, app) {
|
|
31329
|
-
if (!
|
|
31330
|
-
if (["dns_required", "certificate_pending"].includes(status.state) && (!status.domainId || !status.hostname || !
|
|
31331
|
-
if (status.state === "ready" && (!status.domainId || !status.hostname || customHostname(status.hostname) !== status.hostname || status.verificationStatus !== "verified" || status.certificateStatus !== "managed" || status.bindingStatus !== "ready" || !
|
|
32841
|
+
if (!uuid5.test(status.id) || status.applicationId !== app || !["review_required", "dns_required", "certificate_pending", "ready", "blocked"].includes(status.state) || status.domainId !== null && !uuid5.test(status.domainId)) throw new Error("The server returned invalid domain setup metadata.");
|
|
32842
|
+
if (["dns_required", "certificate_pending"].includes(status.state) && (!status.domainId || !status.hostname || !knownEnvironment(status.environment))) throw new Error("The server returned invalid domain setup metadata.");
|
|
32843
|
+
if (status.state === "ready" && (!status.domainId || !status.hostname || customHostname(status.hostname) !== status.hostname || status.verificationStatus !== "verified" || status.certificateStatus !== "managed" || status.bindingStatus !== "ready" || !knownEnvironment(status.environment) || status.url !== "https://" + status.hostname)) throw new Error("The server has not established verified DNS, managed HTTPS and routing for this domain.");
|
|
31332
32844
|
}
|
|
31333
32845
|
function checked(task, app) {
|
|
31334
32846
|
validateHumanTask(task, kind, app);
|
|
@@ -31338,10 +32850,14 @@ function checked(task, app) {
|
|
|
31338
32850
|
}
|
|
31339
32851
|
async function connectDomain(call2, options) {
|
|
31340
32852
|
const app = options.applicationId.toLowerCase();
|
|
31341
|
-
if (!
|
|
31342
|
-
if (options.environment && !["preview", "production"].includes(options.environment)) throw new Error("Use --environment preview|production, or choose in the browser.");
|
|
32853
|
+
if (!uuid5.test(app) || options.requestId && !uuid5.test(options.requestId)) throw new Error("Use valid application and domain setup request IDs.");
|
|
31343
32854
|
const hostname3 = options.hostname === void 0 ? void 0 : customHostname(options.hostname);
|
|
31344
|
-
const
|
|
32855
|
+
const environment = options.environment?.toLowerCase();
|
|
32856
|
+
if (environment && environment !== "production" && !options.requestId) {
|
|
32857
|
+
const activated = await activatedEnvironments(call2, app) ?? ENVIRONMENT_FLOW;
|
|
32858
|
+
if (!activated.includes(environment)) throw new Error((knownEnvironment(environment) ? `This application has no ${environment} environment. ` : "") + "Use --environment " + activated.join("|") + ", or choose in the browser.");
|
|
32859
|
+
}
|
|
32860
|
+
const initial = checked(options.requestId ? await readHumanTask(call2, options.requestId) : await requestHumanTask(call2, kind, { applicationId: app, hostname: hostname3 ?? null, environment: environment ?? null, requestKey: randomUUID2() }), app);
|
|
31345
32861
|
const { status: task, link, reason } = await waitForHumanTask(initial, async () => checked(await readHumanTask(call2, initial.id), app), options, "sign in and confirm the custom domain");
|
|
31346
32862
|
const status = task.result;
|
|
31347
32863
|
return {
|
|
@@ -31396,7 +32912,7 @@ on the Backify auth host. Client IDs and secrets are entered there, never in the
|
|
|
31396
32912
|
provider has a setting in every environment. Email and passkeys need no configuration, so a request for only those
|
|
31397
32913
|
completes at once. Exit code 0 means completed; 2 means setup is still required or blocked. Re-run with --request
|
|
31398
32914
|
to read the status without reopening the browser.`;
|
|
31399
|
-
var
|
|
32915
|
+
var uuid6 = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
31400
32916
|
function authOrigin(input) {
|
|
31401
32917
|
const url2 = new URL(input);
|
|
31402
32918
|
if (url2.protocol !== "https:" && !(url2.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url2.hostname)) || url2.username || url2.password || url2.search || url2.hash || url2.pathname !== "/") throw new Error("Use a trusted HTTPS auth origin, or an explicit loopback development origin.");
|
|
@@ -31405,7 +32921,7 @@ function authOrigin(input) {
|
|
|
31405
32921
|
function setupUrl(origin, app, status) {
|
|
31406
32922
|
if (!status.setupPath || !status.id) throw new Error("The server returned no sign-in setup link.");
|
|
31407
32923
|
const url2 = new URL(status.setupPath, origin);
|
|
31408
|
-
if (url2.origin !== origin || url2.pathname.toLowerCase() !== "/setup/auth/" + app + "/" + status.id.toLowerCase() || [...url2.searchParams.keys()].join() !== "organization" || !
|
|
32924
|
+
if (url2.origin !== origin || url2.pathname.toLowerCase() !== "/setup/auth/" + app + "/" + status.id.toLowerCase() || [...url2.searchParams.keys()].join() !== "organization" || !uuid6.test(url2.searchParams.get("organization")) || url2.username || url2.password || url2.hash)
|
|
31409
32925
|
throw new Error("The server returned an invalid sign-in setup link.");
|
|
31410
32926
|
return url2.href;
|
|
31411
32927
|
}
|
|
@@ -31418,7 +32934,7 @@ function configuredProviders(values) {
|
|
|
31418
32934
|
}
|
|
31419
32935
|
async function setupAuth(call2, options) {
|
|
31420
32936
|
const app = options.applicationId.toLowerCase(), timeout = options.timeoutMs ?? 9e5;
|
|
31421
|
-
if (!
|
|
32937
|
+
if (!uuid6.test(app) || options.requestId && !uuid6.test(options.requestId)) throw new Error("Use valid application and sign-in setup request IDs.");
|
|
31422
32938
|
if (!Number.isFinite(timeout) || timeout < 1e3 || timeout > 36e5) throw new Error("Use --timeout between 1 and 3600 seconds.");
|
|
31423
32939
|
const origin = authOrigin(options.authUrl), now = options.now ?? Date.now, deadline = now() + timeout;
|
|
31424
32940
|
const base = "/apps/" + app + "/auth/setup/requests";
|
|
@@ -31651,8 +33167,8 @@ async function browserAuthenticate(options) {
|
|
|
31651
33167
|
};
|
|
31652
33168
|
let rejectSession = () => {
|
|
31653
33169
|
};
|
|
31654
|
-
const completed = new Promise((
|
|
31655
|
-
resolveSession =
|
|
33170
|
+
const completed = new Promise((resolve10, reject) => {
|
|
33171
|
+
resolveSession = resolve10;
|
|
31656
33172
|
rejectSession = reject;
|
|
31657
33173
|
});
|
|
31658
33174
|
let accepted = false;
|
|
@@ -31774,13 +33290,13 @@ function reconnectingApiClient(session, reconnect2, transport = fetch) {
|
|
|
31774
33290
|
init_development();
|
|
31775
33291
|
init_setup();
|
|
31776
33292
|
init_dist();
|
|
31777
|
-
import { readFileSync as readFileSync21, existsSync as
|
|
33293
|
+
import { readFileSync as readFileSync21, existsSync as existsSync17, rmSync as rmSync5 } from "node:fs";
|
|
31778
33294
|
import { homedir as homedir2 } from "node:os";
|
|
31779
33295
|
import { join as join19 } from "node:path";
|
|
31780
33296
|
import { spawn as spawn5 } from "node:child_process";
|
|
31781
33297
|
var [command, ...args] = process.argv.slice(2);
|
|
31782
33298
|
var configPath = join19(homedir2(), ".backify.json");
|
|
31783
|
-
var userConfig = command !== "mcp" &&
|
|
33299
|
+
var userConfig = command !== "mcp" && existsSync17(configPath) ? JSON.parse(readFileSync21(configPath, "utf8")) : {};
|
|
31784
33300
|
async function call(path, init) {
|
|
31785
33301
|
let appId = option("--app");
|
|
31786
33302
|
if (!appId && hasProjectConfig(process.cwd())) appId = projectApplication();
|
|
@@ -31807,10 +33323,18 @@ var help = [
|
|
|
31807
33323
|
"Account: signup [--name <organization>] [--plan <plan>] | login | logout | connect | disconnect | status | apps",
|
|
31808
33324
|
"Coding: tools configure --agent <tool> [--transport http|stdio] [--config <path>] [--dry-run] | mcp [--organization <organization-id>]",
|
|
31809
33325
|
"Org admin: ops search [<query>] | ops describe <operation-id> | ops get|run <operation-id> [--param <name>=<value>] [--body <file>] [--yes] [--organization <id>] [--json]",
|
|
31810
|
-
"Org tasks: task start <kind> [--draft <json>] | task get|wait|open <id> | github connect | azure connect|reconnect|update-
|
|
33326
|
+
"Org tasks: task start <kind> [--draft <json>] | task get|wait|open <id> | github connect | azure connect|reconnect|update-runtime|runtime-upgrade|automatic-upgrades|grant-scope|rescope-grants|uninstall|remove | org | billing | members add|invite|list|invitations|join-links|domains (backify task --help)",
|
|
31811
33327
|
"Delivery: pull | report [--check] | ship [--production-deploy|--preview-only] [--dry-run] | deploy [<application-id>] [<source-revision>] | request | workflow refresh",
|
|
33328
|
+
" ship deploys to the earliest activated environment (production when it is the only one); --production-deploy then promotes",
|
|
33329
|
+
" through every activated environment to production; --preview-only stops after the first environment",
|
|
31812
33330
|
" prompt record --stdin --id <UUID>",
|
|
31813
|
-
"
|
|
33331
|
+
"Releases: environments [add <preview|prototype> [--yes] | remove <preview|prototype> --confirm <application-slug> | placement [<environment> --target <id|default> [--check] [--yes]] | targets <environment> | move <environment> --target <id> --window-start <ISO> --window-end <ISO> [--check] [--yes] | move status|start|abort|confirm <environment> [--active <id>] [--yes]] | release-flow [--json] | promote [--tested] [--yes]",
|
|
33332
|
+
" Releases move prototype -> preview -> production through the activated environments (backify environments --help)",
|
|
33333
|
+
" hosting [--json] shows targets, environments and resources, marking kept ones | rollback <deployment-id> [--yes] (a rollback never restores the database)",
|
|
33334
|
+
"Logs: logs history --environment <prototype|preview|production|UUID> [--stream console|system|audit] [--since <30m|24h|7d> | --from <ISO> --to <ISO>] [--contains <text>] [--limit <n>] [--all] [--json] | logs recent [--environment <...>] (backify logs --help)",
|
|
33335
|
+
"Monitoring: monitoring [--environment <prototype|preview|production|UUID>] [--range 1h|6h|24h|7d] [--json] | operation <operation-id> [--wait] [--json] (activity log, one line per hosting target)",
|
|
33336
|
+
"Handoff: handoff [status|check] | handoff request --confirm <application-slug> | handoff start|abort [--yes] | handoff package [--out <directory>] | handoff replacements [add|verify|remove] (backify handoff --help)",
|
|
33337
|
+
"Platform: database extensions|insights --environment <UUID> [--hours <n>] | privacy requests list|show|create|update|close|preview | events environments|inspect|test | outbound show|default|allow|block|remove|destinations|requests --environment <UUID> | auth setup [--providers <list>] | auth identity [move|move-back --environment <name|id> --confirm <application-slug> | clear --environment <name|id>] | domains connect [hostname] [--environment <activated environment>] | integrations connect <provider>|discover|prepare|status|list|catalog|search|describe|contract|types",
|
|
31814
33338
|
"",
|
|
31815
33339
|
"Docs: https://docs.backify.dev/"
|
|
31816
33340
|
].join("\n");
|
|
@@ -31885,7 +33409,7 @@ async function main() {
|
|
|
31885
33409
|
const controller = new AbortController(), stop = () => controller.abort();
|
|
31886
33410
|
process.once("SIGINT", stop);
|
|
31887
33411
|
process.once("SIGTERM", stop);
|
|
31888
|
-
const
|
|
33412
|
+
const json3 = args.includes("--json");
|
|
31889
33413
|
try {
|
|
31890
33414
|
const { result } = await runTaskCommand2(command, args, {
|
|
31891
33415
|
configPath,
|
|
@@ -31897,10 +33421,10 @@ async function main() {
|
|
|
31897
33421
|
progress: (message) => console.error(message),
|
|
31898
33422
|
signal: controller.signal
|
|
31899
33423
|
});
|
|
31900
|
-
console.log(
|
|
33424
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
31901
33425
|
if (result.exitCode !== void 0) process.exitCode = result.exitCode;
|
|
31902
33426
|
} catch (error2) {
|
|
31903
|
-
if (!(error2 instanceof OpsError2) || !
|
|
33427
|
+
if (!(error2 instanceof OpsError2) || !json3) throw error2;
|
|
31904
33428
|
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
31905
33429
|
process.exitCode = 1;
|
|
31906
33430
|
} finally {
|
|
@@ -31952,6 +33476,26 @@ async function main() {
|
|
|
31952
33476
|
break;
|
|
31953
33477
|
}
|
|
31954
33478
|
case "auth": {
|
|
33479
|
+
if (args[0] === "identity") {
|
|
33480
|
+
const identity = await Promise.resolve().then(() => (init_auth_identity(), auth_identity_exports));
|
|
33481
|
+
const { CommandError: CommandError2 } = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33482
|
+
const json3 = args.includes("--json");
|
|
33483
|
+
try {
|
|
33484
|
+
const options2 = identity.authIdentityArguments(args.slice(1));
|
|
33485
|
+
if (options2 === "help") {
|
|
33486
|
+
console.log(identity.authIdentityHelp);
|
|
33487
|
+
break;
|
|
33488
|
+
}
|
|
33489
|
+
const result = await identity.runAuthIdentity(call, applicationGuid(option("--app") ?? projectApplication()), options2);
|
|
33490
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33491
|
+
if (result.exitCode !== void 0) process.exitCode = result.exitCode;
|
|
33492
|
+
} catch (error2) {
|
|
33493
|
+
if (!(error2 instanceof CommandError2) || !json3) throw error2;
|
|
33494
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33495
|
+
process.exitCode = 1;
|
|
33496
|
+
}
|
|
33497
|
+
break;
|
|
33498
|
+
}
|
|
31955
33499
|
if (args[0] !== "setup" || args.includes("--help")) {
|
|
31956
33500
|
console.log(authSetupHelp);
|
|
31957
33501
|
if (args[0] !== "setup" && !args.includes("--help")) process.exitCode = 2;
|
|
@@ -32033,6 +33577,24 @@ async function main() {
|
|
|
32033
33577
|
break;
|
|
32034
33578
|
}
|
|
32035
33579
|
case "integrations": {
|
|
33580
|
+
if (["webhooks", "webhook-job", "webhook-deliveries", "webhook-replay"].includes(args[0])) {
|
|
33581
|
+
if (args.includes("--help")) {
|
|
33582
|
+
console.log(integrationWebhooksUsage);
|
|
33583
|
+
break;
|
|
33584
|
+
}
|
|
33585
|
+
const webhook = integrationWebhookCall(args[0], {
|
|
33586
|
+
applicationId: applicationGuid(option("--app") ?? projectApplication()),
|
|
33587
|
+
connectionId: option("--connection"),
|
|
33588
|
+
environmentId: option("--environment"),
|
|
33589
|
+
bindingId: option("--binding"),
|
|
33590
|
+
receiptId: option("--receipt"),
|
|
33591
|
+
job: option("--job"),
|
|
33592
|
+
confirm: args.includes("--yes")
|
|
33593
|
+
});
|
|
33594
|
+
const value2 = await call(webhook.path, webhook.init);
|
|
33595
|
+
console.log(JSON.stringify(value2 ?? { updated: true }, null, 2));
|
|
33596
|
+
break;
|
|
33597
|
+
}
|
|
32036
33598
|
if (args[0] === "connect") {
|
|
32037
33599
|
if (args.includes("--help")) {
|
|
32038
33600
|
console.log(integrationConnectHelp);
|
|
@@ -32100,7 +33662,7 @@ Next: ${here ? "" : `cd ${directory} && `}npm install && npm run dev`);
|
|
|
32100
33662
|
}
|
|
32101
33663
|
case "dev": {
|
|
32102
33664
|
const port = portOption("--port");
|
|
32103
|
-
if (!
|
|
33665
|
+
if (!existsSync17(join19(process.cwd(), "backify.config.ts"))) throw new Error("backify dev runs apps with a backify.config.ts. Create one with backify new <name>.");
|
|
32104
33666
|
const { devCommand: devCommand2 } = await Promise.resolve().then(() => (init_dev(), dev_exports));
|
|
32105
33667
|
process.exitCode = await devCommand2(process.cwd(), { port });
|
|
32106
33668
|
break;
|
|
@@ -32174,7 +33736,7 @@ Next: ${here ? "" : `cd ${directory} && `}npm install && npm run dev`);
|
|
|
32174
33736
|
userConfig.sessions[key] ??= session;
|
|
32175
33737
|
saveUserConfig(configPath, userConfig);
|
|
32176
33738
|
if (args.includes("--clone")) await cloneProject(client, appId);
|
|
32177
|
-
else if (
|
|
33739
|
+
else if (existsSync17(join19(process.cwd(), ".git"))) {
|
|
32178
33740
|
const update = await pullProject(client, appId);
|
|
32179
33741
|
console.log(JSON.stringify(update, null, 2));
|
|
32180
33742
|
if (update.status === "blocked") throw new Error(update.reason);
|
|
@@ -32232,6 +33794,125 @@ Next: ${here ? "" : `cd ${directory} && `}npm install && npm run dev`);
|
|
|
32232
33794
|
console.log(JSON.stringify(await ship(call, projectApplication(), { productionDeploy: args.includes("--production-deploy"), previewOnly: args.includes("--preview-only"), timeoutMs: timeout * 1e3, dryRun: args.includes("--dry-run") }), null, 2));
|
|
32233
33795
|
break;
|
|
32234
33796
|
}
|
|
33797
|
+
case "environments":
|
|
33798
|
+
case "release-flow":
|
|
33799
|
+
case "promote": {
|
|
33800
|
+
const flow = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33801
|
+
const { terminalConfirm: terminalConfirm2 } = await Promise.resolve().then(() => (init_ops(), ops_exports));
|
|
33802
|
+
const json3 = args.includes("--json");
|
|
33803
|
+
try {
|
|
33804
|
+
const options = command === "environments" ? flow.environmentsArguments(args) : command === "promote" ? flow.promoteArguments(args) : args.includes("--help") || args.includes("-h") ? "help" : void 0;
|
|
33805
|
+
if (options === "help") {
|
|
33806
|
+
console.log(command === "environments" ? flow.environmentsHelp : command === "promote" ? flow.promoteHelp : flow.releaseFlowHelp);
|
|
33807
|
+
break;
|
|
33808
|
+
}
|
|
33809
|
+
if (command === "release-flow" && args.some((value, index) => value !== "--json" && value !== "--app" && args[index - 1] !== "--app")) throw new Error(flow.releaseFlowHelp);
|
|
33810
|
+
const application = applicationGuid(option("--app") ?? projectApplication()), context2 = { confirm: terminalConfirm2() };
|
|
33811
|
+
const result = command === "environments" ? await flow.runEnvironments(call, application, options, context2) : command === "promote" ? await flow.promote(call, application, options, context2) : await flow.releaseFlow(call, application);
|
|
33812
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33813
|
+
if (result.exitCode !== void 0) process.exitCode = result.exitCode;
|
|
33814
|
+
} catch (error2) {
|
|
33815
|
+
if (!(error2 instanceof flow.CommandError) || !json3) throw error2;
|
|
33816
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33817
|
+
process.exitCode = 1;
|
|
33818
|
+
}
|
|
33819
|
+
break;
|
|
33820
|
+
}
|
|
33821
|
+
case "hosting":
|
|
33822
|
+
case "rollback": {
|
|
33823
|
+
const hostingModule = await Promise.resolve().then(() => (init_hosting(), hosting_exports));
|
|
33824
|
+
const { CommandError: CommandError2 } = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33825
|
+
const { terminalConfirm: terminalConfirm2 } = await Promise.resolve().then(() => (init_ops(), ops_exports));
|
|
33826
|
+
const json3 = args.includes("--json");
|
|
33827
|
+
try {
|
|
33828
|
+
const options = command === "hosting" ? hostingModule.hostingArguments(args) : hostingModule.rollbackArguments(args);
|
|
33829
|
+
if (options === "help") {
|
|
33830
|
+
console.log(command === "hosting" ? hostingModule.hostingHelp : hostingModule.rollbackHelp);
|
|
33831
|
+
break;
|
|
33832
|
+
}
|
|
33833
|
+
const application = applicationGuid(option("--app") ?? projectApplication());
|
|
33834
|
+
const result = command === "hosting" ? await hostingModule.runHosting(call, application) : await hostingModule.runRollback(call, application, options, { confirm: terminalConfirm2() });
|
|
33835
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33836
|
+
} catch (error2) {
|
|
33837
|
+
if (!(error2 instanceof CommandError2) || !json3) throw error2;
|
|
33838
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33839
|
+
process.exitCode = 1;
|
|
33840
|
+
}
|
|
33841
|
+
break;
|
|
33842
|
+
}
|
|
33843
|
+
case "handoff": {
|
|
33844
|
+
const handoff2 = await Promise.resolve().then(() => (init_handoff(), handoff_exports));
|
|
33845
|
+
const { CommandError: CommandError2 } = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33846
|
+
const { terminalConfirm: terminalConfirm2 } = await Promise.resolve().then(() => (init_ops(), ops_exports));
|
|
33847
|
+
const json3 = args.includes("--json");
|
|
33848
|
+
try {
|
|
33849
|
+
const options = handoff2.handoffArguments(args);
|
|
33850
|
+
if (options === "help") {
|
|
33851
|
+
console.log(handoff2.handoffHelp);
|
|
33852
|
+
break;
|
|
33853
|
+
}
|
|
33854
|
+
const result = await handoff2.runHandoff(call, applicationGuid(option("--app") ?? projectApplication()), options, { confirm: terminalConfirm2() });
|
|
33855
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33856
|
+
if (result.exitCode !== void 0) process.exitCode = result.exitCode;
|
|
33857
|
+
} catch (error2) {
|
|
33858
|
+
if (!(error2 instanceof CommandError2) || !json3) throw error2;
|
|
33859
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33860
|
+
process.exitCode = 1;
|
|
33861
|
+
}
|
|
33862
|
+
break;
|
|
33863
|
+
}
|
|
33864
|
+
case "logs": {
|
|
33865
|
+
const history = await Promise.resolve().then(() => (init_logs_history(), logs_history_exports));
|
|
33866
|
+
const json3 = args.includes("--json");
|
|
33867
|
+
try {
|
|
33868
|
+
const options = history.logsArguments(args);
|
|
33869
|
+
if (options === "help") {
|
|
33870
|
+
console.log(history.logsHelp);
|
|
33871
|
+
break;
|
|
33872
|
+
}
|
|
33873
|
+
const application = applicationGuid(option("--app") ?? projectApplication());
|
|
33874
|
+
const result = options.action === "recent" ? await history.runLogsRecent(call, application, options) : await history.runLogsHistory(call, application, options);
|
|
33875
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33876
|
+
} catch (error2) {
|
|
33877
|
+
const flow = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33878
|
+
if (!(error2 instanceof flow.CommandError) || !json3) throw error2;
|
|
33879
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33880
|
+
process.exitCode = 1;
|
|
33881
|
+
}
|
|
33882
|
+
break;
|
|
33883
|
+
}
|
|
33884
|
+
case "monitoring":
|
|
33885
|
+
case "operation": {
|
|
33886
|
+
const flow = await Promise.resolve().then(() => (init_release_flow(), release_flow_exports));
|
|
33887
|
+
const json3 = args.includes("--json");
|
|
33888
|
+
try {
|
|
33889
|
+
let result;
|
|
33890
|
+
if (command === "monitoring") {
|
|
33891
|
+
const monitoring = await Promise.resolve().then(() => (init_monitoring(), monitoring_exports));
|
|
33892
|
+
const options = monitoring.monitoringArguments(args);
|
|
33893
|
+
if (options === "help") {
|
|
33894
|
+
console.log(monitoring.monitoringHelp);
|
|
33895
|
+
break;
|
|
33896
|
+
}
|
|
33897
|
+
result = await monitoring.runMonitoring(call, applicationGuid(option("--app") ?? projectApplication()), options);
|
|
33898
|
+
} else {
|
|
33899
|
+
const progress = await Promise.resolve().then(() => (init_operation_progress(), operation_progress_exports));
|
|
33900
|
+
const options = progress.operationArguments(args);
|
|
33901
|
+
if (options === "help") {
|
|
33902
|
+
console.log(progress.operationHelp);
|
|
33903
|
+
break;
|
|
33904
|
+
}
|
|
33905
|
+
result = await progress.runOperation(call, options, { progress: json3 ? void 0 : (text2) => console.log(text2) });
|
|
33906
|
+
}
|
|
33907
|
+
console.log(json3 ? JSON.stringify(result.value, null, 2) : result.text);
|
|
33908
|
+
if (result.exitCode !== void 0) process.exitCode = result.exitCode;
|
|
33909
|
+
} catch (error2) {
|
|
33910
|
+
if (!(error2 instanceof flow.CommandError) || !json3) throw error2;
|
|
33911
|
+
console.log(JSON.stringify({ schemaVersion: 1, status: "failed", exitCode: 1, error: error2.message, code: error2.code, ...error2.details }, null, 2));
|
|
33912
|
+
process.exitCode = 1;
|
|
33913
|
+
}
|
|
33914
|
+
break;
|
|
33915
|
+
}
|
|
32235
33916
|
case "request": {
|
|
32236
33917
|
const workspaceId = option("--workspace"), name2 = option("--name"), slug = option("--slug"), description = option("--description"), configurationFile = option("--configuration");
|
|
32237
33918
|
if (!workspaceId || !name2 || !slug || !description) throw new Error("Use backify request --workspace <id> --name <name> --slug <slug> --description <purpose> [--configuration <json-file>]");
|