@homepages/concrete 13.0.1 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +4 -5
  3. package/codemods/manifest.json +7 -0
  4. package/dist/artifact/playground/client/assets/index-DZbV6Ucf.js +1338 -0
  5. package/dist/artifact/playground/client/index.html +1 -1
  6. package/dist/artifact/playground/host.mjs +22 -22
  7. package/dist/cli/build/manifest.js +1 -1
  8. package/dist/cli/build/record.js +1 -1
  9. package/dist/cli/check/load-workspace.js +3 -6
  10. package/dist/cli/commands.js +63 -15
  11. package/dist/cli/media/deriver-plugin.js +10 -1
  12. package/dist/cli/publish/artifact.js +18 -40
  13. package/dist/cli/publish/fixtures.js +1 -1
  14. package/dist/cli/publish/index.js +90 -115
  15. package/dist/cli/publish/report.js +36 -56
  16. package/dist/cli/publish/send.js +142 -0
  17. package/dist/cli/publish/target.js +33 -31
  18. package/dist/cli/publish/verdict.js +65 -0
  19. package/dist/cli/release/client.js +69 -0
  20. package/dist/cli/release/index.js +143 -0
  21. package/dist/cli/release/report.js +73 -0
  22. package/dist/cli/upgrade/fixture-modules.js +3 -5
  23. package/dist/cli.js +1 -0
  24. package/dist/css/graph.js +29 -40
  25. package/dist/fixtures/media-plugin.js +7 -25
  26. package/dist/fixtures/package-stylesheets.js +12 -48
  27. package/dist/packages/external/concrete/package.js +1 -1
  28. package/dist/packages/internal/media-resolution/dist/image.js +23 -0
  29. package/dist/packages/internal/playground/dist/fixture-formats.js +5 -1
  30. package/dist/packages/internal/playground/dist/host/built.js +4 -12
  31. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +0 -1
  32. package/dist/packages/internal/playground/dist/host/download.js +1 -8
  33. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +3 -4
  34. package/dist/packages/internal/playground/dist/host/program.js +1 -2
  35. package/dist/packages/internal/playground/dist/host/serve.js +4 -30
  36. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +2 -9
  37. package/dist/packages/internal/playground/dist/layout.js +5 -5
  38. package/dist/packages/internal/playground/dist/send-wire.js +9 -0
  39. package/dist/packages/internal/playground/dist/server/changes.js +0 -1
  40. package/dist/packages/internal/playground/dist/server/listen.js +2 -19
  41. package/dist/packages/internal/property-facts/dist/registry-facts.js +0 -7
  42. package/dist/packages/internal/template-artifact/dist/framework-floor.js +33 -0
  43. package/dist/packages/internal/template-artifact/dist/index.js +3 -3
  44. package/dist/packages/internal/template-artifact/dist/layout.js +2 -39
  45. package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
  46. package/dist/packages/internal/template-artifact/dist/verify.js +6 -57
  47. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +1 -1
  48. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  49. package/dist/template/logic-build.js +38 -19
  50. package/guide/reference/cli/INDEX.md +5 -4
  51. package/guide/reference/cli/build.md +1 -1
  52. package/guide/reference/cli/check.md +1 -1
  53. package/guide/reference/cli/dev.md +1 -1
  54. package/guide/reference/cli/install.md +1 -1
  55. package/guide/reference/cli/property-add.md +1 -1
  56. package/guide/reference/cli/property-list.md +1 -1
  57. package/guide/reference/cli/publish.md +17 -16
  58. package/guide/reference/cli/release.md +57 -0
  59. package/guide/reference/cli/upgrade.md +1 -1
  60. package/guide/reference/rules/INDEX.md +1 -1
  61. package/package.json +6 -4
  62. package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +0 -1338
  63. package/dist/cli/publish/captures.js +0 -61
  64. package/dist/cli/publish/client.js +0 -118
  65. package/dist/cli/publish/pack.js +0 -77
  66. package/dist/cli/publish/playground.js +0 -27
  67. package/dist/cli/publish/wire.js +0 -23
@@ -1,74 +1,54 @@
1
+ import { compareVersions } from "../../packages/internal/template-artifact/dist/framework-floor.js";
1
2
  import { maskToken } from "./target.js";
2
3
 
3
4
  //#region src/cli/publish/report.ts
4
5
  const LABEL_WIDTH = 9;
5
6
  function stageLine(stage, text) {
6
- return `${stage.padEnd(LABEL_WIDTH)}${text}\n`;
7
+ return `${(stage ?? "").padEnd(LABEL_WIDTH)}${text}\n`;
7
8
  }
8
9
  const shortHash = (hash) => hash.slice(0, 12);
9
- function formatBytes(bytes) {
10
- if (bytes < 1024) return `${String(bytes)} B`;
11
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
12
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
13
- }
14
10
  const plural = (count, one, many) => `${String(count)} ${count === 1 ? one : many}`;
15
- function targetText(target) {
16
- return `${target.environmentName} · key ${maskToken(target.token)} · ${target.endpoint}${target.overridden ? " (CONCRETE_API_URL)" : ""}`;
11
+ function consoleText(target) {
12
+ return `${target.environmentName} · team key ${maskToken(target.key)} · ${target.console}${target.overridden ? " (CONCRETE_CONSOLE_URL)" : ""}`;
13
+ }
14
+ function sendLines(answer) {
15
+ const { merge } = answer.merged;
16
+ const lines = [`version ${answer.merged.version} · ${answer.link}`];
17
+ for (const unit of merge.replaced) lines.push(`replaced on the console (it stays in the version before this one): ${unit.unit}`);
18
+ for (const unit of merge.kept) lines.push(`kept from the console (${unit.change} there): ${unit.unit}`);
19
+ for (const held of merge.held) lines.push(`kept ${held.unit}: ${held.fixtures.join(", ")} ${held.fixtures.length === 1 ? "is" : "are"} on it`);
20
+ return lines;
21
+ }
22
+ function behindText(frameworkVersion, consoleVersion) {
23
+ if (consoleVersion === null) return null;
24
+ const order = compareVersions(frameworkVersion, consoleVersion);
25
+ if (order === null || order >= 0) return null;
26
+ return `concrete publish: warning: this build's @homepages/concrete ${frameworkVersion} is older than the console's ${consoleVersion}; run \`concrete upgrade\` so the playground runs the build as the console would build it.\n`;
17
27
  }
18
28
  function builtText(manifest) {
19
29
  return `built ${shortHash(manifest.template.content_hash)} · ${plural(manifest.sections.length, "section", "sections")} · check passed`;
20
30
  }
21
- function uploadText(manifest, bytes, publisher) {
22
- return `${manifest.key} ${shortHash(manifest.template.content_hash)} · ${formatBytes(bytes)} · publisher "${publisher}"`;
23
- }
24
- function buildsOf(record) {
25
- const entries = record.builds ?? {};
26
- return {
27
- template: entries[record.template_key],
28
- sections: Object.entries(entries).filter(([key]) => key !== record.template_key).map(([, entry]) => entry)
29
- };
30
- }
31
- function isAlreadyCurrent(record) {
32
- const { template, sections } = buildsOf(record);
33
- return template !== void 0 && template.status === "unchanged" && sections.every((entry) => entry.status === "unchanged");
34
- }
35
- function sectionCounts(sections) {
36
- const count = (status) => String(sections.filter((entry) => entry.status === status).length);
37
- return `sections: ${count("new")} new, ${count("changed")} changed, ${count("unchanged")} unchanged`;
38
- }
39
- function writeText(record) {
40
- const hash = shortHash(record.artifact_hash);
41
- const { template, sections } = buildsOf(record);
42
- if (record.state === "dry_run") {
43
- if (template?.status === "new") return `would write template ${hash} as new · ${sectionCounts(sections)}`;
44
- if (template?.status === "changed") return `would replace the template's build with ${hash} · ${sectionCounts(sections)}`;
45
- return `would write nothing new · template build ${hash} is already current`;
46
- }
47
- if (isAlreadyCurrent(record)) return `already current · template build ${hash}`;
48
- return `${template?.status === "new" ? `template ${hash} is new` : `template build ${hash} replaces the previous one`} · ${sectionCounts(sections)}`;
31
+ const PROBLEMS_SHOWN = 20;
32
+ function problemLines(problems) {
33
+ const lines = problems.slice(0, PROBLEMS_SHOWN).map((problem) => ` ${problem.path}: ${problem.message}`);
34
+ if (problems.length > PROBLEMS_SHOWN) lines.push(` …and ${String(problems.length - PROBLEMS_SHOWN)} more`);
35
+ return lines;
49
36
  }
50
- function adoptText(record) {
51
- const summary = record.adopt_summary;
52
- if (summary === null) return "nothing reported";
53
- const checked = plural(summary.scanned, "deliverable checked", "deliverables checked");
54
- if (summary.enqueued === 0) return `no deliverable to move · ${checked}`;
55
- return `${plural(summary.enqueued, "deliverable", "deliverables")} adopting this build · ${checked}`;
37
+ function verdictText(verdict) {
38
+ if (verdict.passed) return `passed · platform ${verdict.platform} loads and renders every section`;
39
+ return `failed · platform ${verdict.platform} did not load the build (${plural(verdict.problems.length, "problem", "problems")})`;
56
40
  }
57
- function summaryText(record) {
58
- if (record.state === "dry_run") return `Dry run passed: ${record.template_key} verified, and nothing was written.`;
59
- if (isAlreadyCurrent(record)) return `${record.template_key} is already current.`;
60
- return `Published ${record.template_key}.`;
41
+ function notReleasedText(verdict) {
42
+ return `Not released. \`concrete release --version ${verdict.version}\` hands this build to the app.\n`;
61
43
  }
62
- const PROBLEMS_SHOWN = 20;
63
- function refusalText(record) {
64
- const refusal = record.refusal;
65
- if (refusal === null) return `concrete publish: the publication ended ${record.state} without saying why; run \`concrete publish\` again.\n`;
66
- const lines = [`concrete publish: ${refusal.detail}`];
67
- const problems = refusal.problems ?? [];
68
- for (const problem of problems.slice(0, PROBLEMS_SHOWN)) lines.push(` ${problem.path}: ${problem.message}`);
69
- if (problems.length > PROBLEMS_SHOWN) lines.push(` …and ${String(problems.length - PROBLEMS_SHOWN)} more`);
70
- return `${lines.join("\n")}\n`;
44
+ function refusedText(verdict) {
45
+ return [
46
+ `concrete publish: refused: platform ${verdict.platform} did not load the build of version ${verdict.version}:`,
47
+ ...problemLines(verdict.problems),
48
+ "concrete publish: the version stays on the console and its playground shows the build; fix the problems and run `concrete publish` again.",
49
+ ""
50
+ ].join("\n");
71
51
  }
72
52
 
73
53
  //#endregion
74
- export { adoptText, builtText, formatBytes, isAlreadyCurrent, refusalText, shortHash, stageLine, summaryText, targetText, uploadText, writeText };
54
+ export { behindText, builtText, consoleText, notReleasedText, problemLines, refusedText, sendLines, shortHash, stageLine, verdictText };
@@ -0,0 +1,142 @@
1
+ import { fixtureFormat } from "../../packages/internal/playground/dist/fixture-formats.js";
2
+ import { CONSOLE_KEY_HEADER, CONTENT_ROUTE, SEND_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
3
+ import { createHash } from "node:crypto";
4
+
5
+ //#region src/cli/publish/send.ts
6
+ const UPLOAD_CONCURRENCY = 6;
7
+ const UPLOAD_ROUNDS = 3;
8
+ const fingerprintOf = (bytes) => createHash("sha256").update(bytes).digest("hex");
9
+ const isObject = (value) => typeof value === "object" && value !== null;
10
+ function reasonOf(cause) {
11
+ if (cause instanceof Error) {
12
+ const code = cause.cause?.code;
13
+ return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
14
+ }
15
+ return String(cause);
16
+ }
17
+ async function sendTemplate(target, input, options = {}) {
18
+ const fetchFn = options.fetch ?? fetch;
19
+ const origin = target.console.replace(/\/+$/, "");
20
+ const sent = [...input.files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
21
+ const byFingerprint = /* @__PURE__ */ new Map();
22
+ const files = sent.map(([path, bytes]) => {
23
+ const fingerprint = fingerprintOf(bytes);
24
+ byFingerprint.set(fingerprint, bytes);
25
+ return {
26
+ path,
27
+ fingerprint,
28
+ size: bytes.byteLength
29
+ };
30
+ });
31
+ const body = {
32
+ template: input.template,
33
+ framework_version: input.frameworkVersion,
34
+ files,
35
+ fixture_format: fixtureFormat(),
36
+ ...input.source === void 0 ? {} : {
37
+ source_commit: input.source.commit,
38
+ source_remote: input.source.remote
39
+ }
40
+ };
41
+ const headers = {
42
+ [CONSOLE_KEY_HEADER]: target.key,
43
+ accept: "application/json"
44
+ };
45
+ async function exchange(path, init) {
46
+ let response;
47
+ try {
48
+ response = await fetchFn(`${origin}${path}`, init);
49
+ } catch (cause) {
50
+ return {
51
+ kind: "unreachable",
52
+ reason: reasonOf(cause)
53
+ };
54
+ }
55
+ const text = await response.text();
56
+ let value = null;
57
+ if (text !== "") try {
58
+ value = JSON.parse(text);
59
+ } catch {
60
+ return {
61
+ kind: "unexpected",
62
+ status: response.status,
63
+ reason: "the answer is not JSON"
64
+ };
65
+ }
66
+ if (response.status >= 400) {
67
+ const refusal = isObject(value) && typeof value["detail"] === "string" && typeof value["code"] === "string" ? value : null;
68
+ return {
69
+ kind: "refused",
70
+ status: response.status,
71
+ refusal
72
+ };
73
+ }
74
+ return {
75
+ status: response.status,
76
+ value
77
+ };
78
+ }
79
+ const isAnswer = (value) => "kind" in value;
80
+ async function upload(fingerprint) {
81
+ const bytes = byFingerprint.get(fingerprint);
82
+ if (bytes === void 0) return {
83
+ kind: "unexpected",
84
+ status: 200,
85
+ reason: `the console asked for ${fingerprint}, which the send does not carry`
86
+ };
87
+ const answer = await exchange(`${CONTENT_ROUTE}${fingerprint}`, {
88
+ method: "PUT",
89
+ headers: {
90
+ ...headers,
91
+ "content-type": "application/octet-stream"
92
+ },
93
+ body: bytes
94
+ });
95
+ return isAnswer(answer) ? answer : null;
96
+ }
97
+ for (let round = 0; round <= UPLOAD_ROUNDS; round++) {
98
+ const answer = await exchange(SEND_ROUTE, {
99
+ method: "POST",
100
+ headers: {
101
+ ...headers,
102
+ "content-type": "application/json"
103
+ },
104
+ body: JSON.stringify(body)
105
+ });
106
+ if (isAnswer(answer)) return answer;
107
+ if (answer.status === 201 && isObject(answer.value) && typeof answer.value["link"] === "string") {
108
+ const merged = answer.value;
109
+ return {
110
+ kind: "merged",
111
+ merged,
112
+ link: new URL(merged.link, `${origin}/`).href
113
+ };
114
+ }
115
+ if (answer.status !== 200 || !isObject(answer.value) || !Array.isArray(answer.value["missing"])) return {
116
+ kind: "unexpected",
117
+ status: answer.status,
118
+ reason: "the answer is not the send's"
119
+ };
120
+ if (round === UPLOAD_ROUNDS) break;
121
+ const missing = answer.value.missing;
122
+ let done = 0;
123
+ const queue = [...missing];
124
+ const failures = [];
125
+ await Promise.all(Array.from({ length: Math.min(UPLOAD_CONCURRENCY, queue.length) }, async () => {
126
+ for (let next = queue.shift(); next !== void 0 && failures.length === 0; next = queue.shift()) {
127
+ const failed = await upload(next);
128
+ if (failed !== null) failures.push(failed);
129
+ else options.uploaded?.(++done, missing.length);
130
+ }
131
+ }));
132
+ if (failures.length > 0) return failures[0];
133
+ }
134
+ return {
135
+ kind: "unexpected",
136
+ status: 200,
137
+ reason: `the console still lacked contents after ${String(UPLOAD_ROUNDS)} rounds of uploads`
138
+ };
139
+ }
140
+
141
+ //#endregion
142
+ export { sendTemplate };
@@ -2,19 +2,11 @@ import { join } from "node:path";
2
2
  import { readFile } from "node:fs/promises";
3
3
 
4
4
  //#region src/cli/publish/target.ts
5
- const TOKEN_VARIABLE = "CONCRETE_TOKEN";
6
- const API_URL_VARIABLE = "CONCRETE_API_URL";
7
- const ENDPOINTS = {
8
- prod: "https://api.homepages.io",
9
- staging: "https://api.homepages.christmas",
10
- dev: "http://localhost:8000"
11
- };
12
5
  const ENVIRONMENT_NAMES = {
13
6
  prod: "production",
14
7
  staging: "staging",
15
8
  dev: "dev"
16
9
  };
17
- const TOKEN = /^cpt_(prod|staging|dev)_[0-9A-Za-z]{43}$/;
18
10
  var TargetError = class extends Error {};
19
11
  function parseDotenv(text) {
20
12
  const values = /* @__PURE__ */ new Map();
@@ -40,7 +32,7 @@ async function readWorkspaceDotenv(root) {
40
32
  }
41
33
  }
42
34
  function maskToken(token) {
43
- return `${/^cpt_[a-z]+_/.exec(token)?.[0] ?? ""}…${token.slice(-4)}`;
35
+ return `${/^cck_[a-z]+_/.exec(token)?.[0] ?? ""}…${token.slice(-4)}`;
44
36
  }
45
37
  async function readNamedDotenv(file) {
46
38
  try {
@@ -50,41 +42,51 @@ async function readNamedDotenv(file) {
50
42
  throw cause;
51
43
  }
52
44
  }
53
- async function resolveTarget(root, env, envFile) {
45
+ async function variableReader(root, env, envFile) {
54
46
  const named = envFile === void 0 ? /* @__PURE__ */ new Map() : await readNamedDotenv(envFile);
55
47
  const dotenv = envFile === void 0 ? await readWorkspaceDotenv(root) : /* @__PURE__ */ new Map();
56
- const read = (name) => {
48
+ return (name) => {
57
49
  const value = named.get(name) ?? env[name] ?? dotenv.get(name);
58
50
  return value === void 0 || value.trim() === "" ? void 0 : value.trim();
59
51
  };
60
- const token = read(TOKEN_VARIABLE);
61
- if (token === void 0) {
52
+ }
53
+ function overrideOrigin(variable, value, example) {
54
+ let url;
55
+ try {
56
+ url = new URL(value);
57
+ } catch {
58
+ throw new TargetError(`${variable} is not a URL ("${value}"); set it to an origin such as ${example}, or unset it.`);
59
+ }
60
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new TargetError(`${variable} must be an http or https URL ("${value}"); set it to an origin such as ${example}, or unset it.`);
61
+ return value.replace(/\/+$/, "");
62
+ }
63
+ const CONSOLE_KEY_VARIABLE = "CONCRETE_CONSOLE_KEY";
64
+ const CONSOLE_URL_VARIABLE = "CONCRETE_CONSOLE_URL";
65
+ const CONSOLES = {
66
+ prod: "https://console.homepages.io",
67
+ staging: "https://console.homepages.christmas",
68
+ dev: "http://console.localhost:8010"
69
+ };
70
+ const CONSOLE_KEY = /^cck_(prod|staging|dev)_[0-9A-Za-z]{43}$/;
71
+ async function resolveConsoleTarget(root, env, envFile) {
72
+ const read = await variableReader(root, env, envFile);
73
+ const key = read(CONSOLE_KEY_VARIABLE);
74
+ if (key === void 0) {
62
75
  const where = envFile === void 0 ? "in the environment or in this workspace's .env" : `in ${envFile}`;
63
- throw new TargetError(`${TOKEN_VARIABLE} is not set; set it ${where} to the publisher key a HomePages admin issued you.`);
76
+ throw new TargetError(`${CONSOLE_KEY_VARIABLE} is not set; set it ${where} to your team's console key.`);
64
77
  }
65
- const match = TOKEN.exec(token);
66
- if (match === null) throw new TargetError(`${TOKEN_VARIABLE} is not a publisher key (a key reads cpt_prod_…, cpt_staging_… or cpt_dev_… followed by 43 letters and digits); set it to the key a HomePages admin issued you.`);
78
+ const match = CONSOLE_KEY.exec(key);
79
+ if (match === null) throw new TargetError(`${CONSOLE_KEY_VARIABLE} is not a console key (a key reads cck_prod_…, cck_staging_… or cck_dev_… followed by 43 letters and digits); set it to your team's console key.`);
67
80
  const environment = match[1];
68
- const override = read(API_URL_VARIABLE);
69
- let endpoint = ENDPOINTS[environment];
70
- if (override !== void 0) {
71
- let url;
72
- try {
73
- url = new URL(override);
74
- } catch {
75
- throw new TargetError(`${API_URL_VARIABLE} is not a URL ("${override}"); set it to an API origin such as http://localhost:8000, or unset it.`);
76
- }
77
- if (url.protocol !== "http:" && url.protocol !== "https:") throw new TargetError(`${API_URL_VARIABLE} must be an http or https URL ("${override}"); set it to an API origin, or unset it.`);
78
- endpoint = override;
79
- }
81
+ const override = read(CONSOLE_URL_VARIABLE);
80
82
  return {
81
83
  environment,
82
84
  environmentName: ENVIRONMENT_NAMES[environment],
83
- token,
84
- endpoint: endpoint.replace(/\/+$/, ""),
85
+ key,
86
+ console: override === void 0 ? CONSOLES[environment] : overrideOrigin(CONSOLE_URL_VARIABLE, override, "http://console.localhost:8010"),
85
87
  overridden: override !== void 0
86
88
  };
87
89
  }
88
90
 
89
91
  //#endregion
90
- export { API_URL_VARIABLE, ENDPOINTS, TOKEN_VARIABLE, TargetError, maskToken, parseDotenv, resolveTarget };
92
+ export { CONSOLES, CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, parseDotenv, resolveConsoleTarget };
@@ -0,0 +1,65 @@
1
+ import { CONSOLE_KEY_HEADER, VERDICT_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
2
+
3
+ //#region src/cli/publish/verdict.ts
4
+ const isObject = (value) => typeof value === "object" && value !== null;
5
+ function reasonOf(cause) {
6
+ if (cause instanceof Error) {
7
+ const code = cause.cause?.code;
8
+ return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
9
+ }
10
+ return String(cause);
11
+ }
12
+ async function askVerdict(origin, key, ask, fetchFn = fetch) {
13
+ let response;
14
+ try {
15
+ response = await fetchFn(`${origin.replace(/\/+$/, "")}${VERDICT_ROUTE}`, {
16
+ method: "POST",
17
+ headers: {
18
+ [CONSOLE_KEY_HEADER]: key,
19
+ accept: "application/json",
20
+ "content-type": "application/json"
21
+ },
22
+ body: JSON.stringify(ask)
23
+ });
24
+ } catch (cause) {
25
+ return {
26
+ kind: "unreachable",
27
+ reason: reasonOf(cause)
28
+ };
29
+ }
30
+ const text = await response.text();
31
+ let value;
32
+ try {
33
+ value = JSON.parse(text);
34
+ } catch {
35
+ return {
36
+ kind: "unexpected",
37
+ status: response.status,
38
+ reason: "the answer is not JSON"
39
+ };
40
+ }
41
+ if (response.status === 200 && isObject(value) && typeof value["passed"] === "boolean" && Array.isArray(value["problems"])) return {
42
+ kind: "given",
43
+ verdict: value
44
+ };
45
+ if (response.status === 202 && isObject(value) && isObject(value["job"])) return {
46
+ kind: "pending",
47
+ pending: value
48
+ };
49
+ if (response.status >= 400) {
50
+ const refusal = isObject(value) && typeof value["code"] === "string" && typeof value["detail"] === "string" ? value : null;
51
+ return {
52
+ kind: "refused",
53
+ status: response.status,
54
+ refusal
55
+ };
56
+ }
57
+ return {
58
+ kind: "unexpected",
59
+ status: response.status,
60
+ reason: "the answer is not the verdict's"
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ export { askVerdict };
@@ -0,0 +1,69 @@
1
+ import { CONSOLE_KEY_HEADER, RELEASE_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
2
+
3
+ //#region src/cli/release/client.ts
4
+ const OUTCOMES = /* @__PURE__ */ new Set([
5
+ "released",
6
+ "would_release",
7
+ "refused",
8
+ "ask_again",
9
+ "not_taken"
10
+ ]);
11
+ const isObject = (value) => typeof value === "object" && value !== null;
12
+ function reasonOf(cause) {
13
+ if (cause instanceof Error) {
14
+ const code = cause.cause?.code;
15
+ return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
16
+ }
17
+ return String(cause);
18
+ }
19
+ async function askRelease(origin, key, ask, fetchFn = fetch) {
20
+ let response;
21
+ try {
22
+ response = await fetchFn(`${origin.replace(/\/+$/, "")}${RELEASE_ROUTE}`, {
23
+ method: "POST",
24
+ headers: {
25
+ [CONSOLE_KEY_HEADER]: key,
26
+ accept: "application/json",
27
+ "content-type": "application/json"
28
+ },
29
+ body: JSON.stringify(ask)
30
+ });
31
+ } catch (cause) {
32
+ return {
33
+ kind: "unreachable",
34
+ reason: reasonOf(cause)
35
+ };
36
+ }
37
+ const text = await response.text();
38
+ let value;
39
+ try {
40
+ value = JSON.parse(text);
41
+ } catch {
42
+ return {
43
+ kind: "unexpected",
44
+ status: response.status,
45
+ reason: "the answer is not JSON"
46
+ };
47
+ }
48
+ if (isObject(value) && typeof value["outcome"] === "string" && OUTCOMES.has(value["outcome"])) return {
49
+ kind: "outcome",
50
+ status: response.status,
51
+ outcome: value
52
+ };
53
+ if (response.status >= 400) {
54
+ const refusal = isObject(value) && typeof value["code"] === "string" && typeof value["detail"] === "string" ? value : null;
55
+ return {
56
+ kind: "refused",
57
+ status: response.status,
58
+ refusal
59
+ };
60
+ }
61
+ return {
62
+ kind: "unexpected",
63
+ status: response.status,
64
+ reason: "the answer is not the release's"
65
+ };
66
+ }
67
+
68
+ //#endregion
69
+ export { askRelease };
@@ -0,0 +1,143 @@
1
+ import { booleanFlag, parseSpec, stringFlag } from "../commands.js";
2
+ import { findWorkspaceRoot } from "../workspace.js";
3
+ import { CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, resolveConsoleTarget } from "../publish/target.js";
4
+ import { askRelease } from "./client.js";
5
+ import { endingLines, subjectText } from "./report.js";
6
+ import { resolve } from "node:path";
7
+ import { parseArgs } from "node:util";
8
+
9
+ //#region src/cli/release/index.ts
10
+ const EXIT_OK = 0;
11
+ const EXIT_REFUSED = 1;
12
+ const EXIT_FAILED = 2;
13
+ const ASKS_TOLERATED = 60;
14
+ const DEFAULT_DEPS = {
15
+ templateKey: async (root) => {
16
+ const { loadWorkspace, TEMPLATE_FILE } = await import("../check/load-workspace.js");
17
+ const workspace = await loadWorkspace(root);
18
+ if (workspace.template !== null) return { key: workspace.template.key };
19
+ const first = workspace.violations[0];
20
+ return { problem: `${TEMPLATE_FILE} did not load${first === void 0 ? "" : ` (${first.file}: ${first.message})`}; run \`concrete check\`.` };
21
+ },
22
+ ask: (target, ask) => askRelease(target.console, target.key, ask),
23
+ now: () => /* @__PURE__ */ new Date()
24
+ };
25
+ const say = (sentence) => `concrete release: ${sentence}\n`;
26
+ function failureOf(answer, target) {
27
+ const where = target.console;
28
+ switch (answer.kind) {
29
+ case "unreachable": return {
30
+ code: EXIT_FAILED,
31
+ sentence: say(`could not reach ${where} (${answer.reason}); check the connection${target.overridden ? ` and ${CONSOLE_URL_VARIABLE}` : ""}, then run again.`)
32
+ };
33
+ case "unexpected": return {
34
+ code: EXIT_FAILED,
35
+ sentence: say(`${where} did not answer as a console (${answer.reason}); ${target.overridden ? `check that ${CONSOLE_URL_VARIABLE} names the console` : "run again, and report it if it repeats"}.`)
36
+ };
37
+ case "refused": {
38
+ const detail = answer.refusal?.detail ?? `${where} refused the release (HTTP ${String(answer.status)}).`;
39
+ if (answer.status === 401) return {
40
+ code: EXIT_FAILED,
41
+ sentence: say(`${where} did not accept ${CONSOLE_KEY_VARIABLE} (${maskToken(target.key)}): ${detail}`)
42
+ };
43
+ if (answer.status === 409 || answer.status >= 500) return {
44
+ code: EXIT_FAILED,
45
+ sentence: say(`${detail} Nothing changed in the app; run \`concrete release\` again.`)
46
+ };
47
+ return {
48
+ code: EXIT_REFUSED,
49
+ sentence: say(detail)
50
+ };
51
+ }
52
+ }
53
+ }
54
+ async function releaseTemplate(run, first) {
55
+ const { io, deps, target } = run;
56
+ let ask = first;
57
+ let named = false;
58
+ for (let asks = 1;; asks++) {
59
+ const answer = await deps.ask(target, ask);
60
+ if (answer.kind !== "outcome") {
61
+ const failure = failureOf(answer, target);
62
+ if (run.json && answer.kind === "refused" && answer.refusal !== null) io.stdout.write(`${JSON.stringify(answer.refusal, null, 2)}\n`);
63
+ io.stderr.write(failure.sentence);
64
+ return failure.code;
65
+ }
66
+ const outcome = answer.outcome;
67
+ if (!named) {
68
+ io.stderr.write(`${subjectText(outcome, deps.now())}\n`);
69
+ named = true;
70
+ }
71
+ for (const line of endingLines(outcome)) io.stderr.write(`${line}\n`);
72
+ if (outcome.outcome === "ask_again") {
73
+ if (asks < 60) {
74
+ ask = {
75
+ ...ask,
76
+ version: outcome.version
77
+ };
78
+ continue;
79
+ }
80
+ if (run.json) io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
81
+ io.stderr.write(say(`the release has not ended after ${String(asks)} asks; run \`concrete release --version ${outcome.version}\` again to pick it up.`));
82
+ return EXIT_FAILED;
83
+ }
84
+ if (run.json) io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
85
+ switch (outcome.outcome) {
86
+ case "released":
87
+ case "would_release": return EXIT_OK;
88
+ case "refused": return EXIT_REFUSED;
89
+ case "not_taken": return EXIT_FAILED;
90
+ }
91
+ }
92
+ }
93
+ async function release(argv, io, deps) {
94
+ let values;
95
+ try {
96
+ ({values} = parseArgs({
97
+ args: [...argv],
98
+ ...parseSpec("release")
99
+ }));
100
+ } catch (cause) {
101
+ io.stderr.write(say(`${cause instanceof Error ? cause.message : String(cause)}; run \`concrete --help\` for the flags release takes.`));
102
+ return EXIT_FAILED;
103
+ }
104
+ const version = stringFlag(values, "version");
105
+ let root;
106
+ try {
107
+ root = await findWorkspaceRoot(io.cwd);
108
+ } catch (cause) {
109
+ io.stderr.write(say(cause instanceof Error ? cause.message : String(cause)));
110
+ return EXIT_FAILED;
111
+ }
112
+ let target;
113
+ try {
114
+ const envFile = stringFlag(values, "env-file");
115
+ target = await resolveConsoleTarget(root, io.env, envFile === null ? void 0 : resolve(io.cwd, envFile));
116
+ } catch (cause) {
117
+ if (cause instanceof TargetError) {
118
+ io.stderr.write(say(cause.message));
119
+ return EXIT_FAILED;
120
+ }
121
+ throw cause;
122
+ }
123
+ const template = await deps.templateKey(root);
124
+ if ("problem" in template) {
125
+ io.stderr.write(say(template.problem));
126
+ return EXIT_FAILED;
127
+ }
128
+ const ask = {
129
+ template: template.key,
130
+ ...version === null ? {} : { version },
131
+ ...booleanFlag(values, "dry-run") ? { dry_run: true } : {}
132
+ };
133
+ return releaseTemplate({
134
+ io,
135
+ deps,
136
+ target,
137
+ json: booleanFlag(values, "json")
138
+ }, ask);
139
+ }
140
+ const runRelease = (argv, io) => release(argv, io, DEFAULT_DEPS);
141
+
142
+ //#endregion
143
+ export { DEFAULT_DEPS, release, runRelease };