kardalum 0.17.0 → 0.18.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 (124) hide show
  1. package/README.md +1 -1
  2. package/dist/control/assets/index.d.ts +2 -0
  3. package/dist/control/assets/index.js +222 -0
  4. package/dist/control/confirm.d.ts +1 -1
  5. package/dist/control/confirm.js +4 -3
  6. package/dist/control/content/write.js +22 -7
  7. package/dist/control/dispatch.js +6 -1
  8. package/dist/control/errors.js +29 -1
  9. package/dist/control/msys.d.ts +4 -0
  10. package/dist/control/msys.js +51 -0
  11. package/dist/control/nouns.js +1 -0
  12. package/dist/control/output.d.ts +1 -1
  13. package/dist/control/output.js +2 -2
  14. package/dist/control/paging.d.ts +6 -0
  15. package/dist/control/paging.js +4 -2
  16. package/dist/control/plans.d.ts +1 -1
  17. package/dist/control/plans.js +2 -2
  18. package/dist/control/plugins/index.js +2 -1
  19. package/dist/control/plugins/lifecycle.d.ts +1 -0
  20. package/dist/control/plugins/lifecycle.js +154 -10
  21. package/dist/control/settings/sites.js +24 -11
  22. package/dist/control/structure/templates.js +44 -10
  23. package/dist/control/usage.d.ts +5 -4
  24. package/dist/control/usage.js +62 -11
  25. package/dist/control/verbs.d.ts +4 -1
  26. package/dist/dev/sandbox.d.ts +11 -0
  27. package/dist/dev/sandbox.js +25 -0
  28. package/dist/dev/server-resolution.d.ts +1 -1
  29. package/dist/dev/server-resolution.js +20 -20
  30. package/dist/plugin/build.d.ts +3 -3
  31. package/dist/plugin/build.js +17 -17
  32. package/dist/plugin/checks/templates.d.ts +1 -1
  33. package/dist/plugin/checks/templates.js +21 -10
  34. package/dist/plugin/copy-templates.d.ts +7 -5
  35. package/dist/plugin/copy-templates.js +7 -5
  36. package/dist/plugin/write-manifest-json.js +10 -0
  37. package/node_modules/@kardalum/api-schemas/README.md +1 -1
  38. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +16 -14
  39. package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.d.ts +21 -0
  40. package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.js +42 -0
  41. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +1 -0
  42. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +10 -3
  43. package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.d.ts +36 -0
  44. package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.js +46 -0
  45. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +12 -0
  46. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +16 -1
  47. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +12 -6
  48. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +11 -6
  49. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +50 -0
  50. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +25 -5
  51. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +1 -0
  52. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +3 -0
  53. package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.d.ts +11 -0
  54. package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.js +28 -0
  55. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +42 -2
  56. package/node_modules/@kardalum/api-schemas/dist/home.schema.d.ts +130 -0
  57. package/node_modules/@kardalum/api-schemas/dist/home.schema.js +87 -0
  58. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +41 -15
  59. package/node_modules/@kardalum/api-schemas/dist/index.js +30 -10
  60. package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.d.ts +7 -0
  61. package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.js +9 -0
  62. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +115 -1
  63. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +102 -1
  64. package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.d.ts +17 -0
  65. package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.js +16 -0
  66. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +26 -0
  67. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +6 -0
  68. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +10 -0
  69. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +4 -4
  70. package/node_modules/@kardalum/api-schemas/dist/news.schema.d.ts +93 -0
  71. package/node_modules/@kardalum/api-schemas/dist/news.schema.js +86 -0
  72. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +13 -0
  73. package/node_modules/@kardalum/api-schemas/dist/notification.schema.d.ts +410 -0
  74. package/node_modules/@kardalum/api-schemas/dist/notification.schema.js +193 -0
  75. package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.d.ts +86 -0
  76. package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.js +92 -0
  77. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +7 -2
  78. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +7 -0
  79. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +227 -0
  80. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +157 -31
  81. package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.d.ts +19 -0
  82. package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.js +33 -0
  83. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +10 -1
  84. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +24 -4
  85. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +5 -0
  86. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -20
  87. package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.d.ts +83 -0
  88. package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.js +73 -0
  89. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +14 -0
  90. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +7 -0
  91. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +3 -3
  92. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
  93. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +10 -0
  94. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +26 -11
  95. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +7 -0
  96. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +22 -10
  97. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +12 -0
  98. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +5 -0
  99. package/node_modules/@kardalum/api-schemas/dist/uuid.schema.d.ts +2 -0
  100. package/node_modules/@kardalum/api-schemas/dist/uuid.schema.js +4 -0
  101. package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.d.ts +88 -0
  102. package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.js +100 -0
  103. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +13 -0
  104. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +5 -0
  105. package/node_modules/@kardalum/plugin-package/README.md +1 -1
  106. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
  107. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +54 -6
  108. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +1 -1
  109. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +3 -0
  110. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +18 -1
  111. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +1 -1
  112. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +1 -1
  113. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +8 -4
  114. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +1 -0
  115. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +58 -1
  116. package/node_modules/@kardalum/plugin-package/dist/extract.js +1 -1
  117. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +4 -2
  118. package/node_modules/@kardalum/plugin-package/dist/index.js +3 -1
  119. package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +56 -19
  120. package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +119 -25
  121. package/node_modules/@kardalum/plugin-package/dist/vendor-token.d.ts +24 -0
  122. package/node_modules/@kardalum/plugin-package/dist/vendor-token.js +118 -0
  123. package/node_modules/@kardalum/prisma-variants/README.md +1 -1
  124. package/package.json +7 -7
package/README.md CHANGED
@@ -111,7 +111,7 @@ Exit codes:
111
111
  ## Docs
112
112
 
113
113
  The CLI reference and the plugin guide are at
114
- [docs.kardalum.com](https://docs.kardalum.com/v1/reference/cli/).
114
+ [dev.kardalum.com/docs](https://dev.kardalum.com/docs/v1/reference/cli/).
115
115
 
116
116
  ## Support
117
117
 
@@ -0,0 +1,2 @@
1
+ import type { NounDef } from "../verbs.js";
2
+ export declare const assetsNoun: NounDef;
@@ -0,0 +1,222 @@
1
+ import { stat, writeFile } from "node:fs/promises";
2
+ import { dirname, resolve } from "node:path";
3
+ import { flag, stringOption } from "../args.js";
4
+ import { CliError, EXIT, UsageError } from "../errors.js";
5
+ import { cell, printKeyValue, printTable } from "../output.js";
6
+ import { PAGE_MAX, runList } from "../paging.js";
7
+ import { textPlan } from "../plans.js";
8
+ import { isId } from "../resolve.js";
9
+ import { ASSETS_USAGE } from "../usage.js";
10
+ // S314c3 (D3): the site's public files by path, over the asset routes S314g finished. Built like
11
+ // `templates`: reads, the history and the trash; make-current and restore ask first.
12
+ /** The folder without leading or trailing slashes. A linear scan: the value is typed by a person. */
13
+ function trimSlashes(text) {
14
+ let start = 0;
15
+ let end = text.length;
16
+ while (start < end && text.charCodeAt(start) === 47)
17
+ start++;
18
+ while (end > start && text.charCodeAt(end - 1) === 47)
19
+ end--;
20
+ return text.slice(start, end);
21
+ }
22
+ function onePath(args, verb) {
23
+ const [path] = args.positionals;
24
+ if (args.positionals.length !== 1 || path === undefined || path === "") {
25
+ throw new UsageError(`${verb} takes an asset path, such as css/site.css (see \`kardalum assets list\`).`);
26
+ }
27
+ return path;
28
+ }
29
+ function versionNumber(text) {
30
+ const number = Number(text);
31
+ if (text === undefined || !/^[0-9]+$/.test(text) || !Number.isSafeInteger(number) || number < 1) {
32
+ throw new UsageError("the version must be a whole number of 1 or more.");
33
+ }
34
+ return number;
35
+ }
36
+ function pathAndVersion(args, verb) {
37
+ const [path, version] = args.positionals;
38
+ if (args.positionals.length !== 2 || path === undefined || path === "")
39
+ throw new UsageError(`${verb} takes an asset path and a version number.`);
40
+ return { path, version: versionNumber(version) };
41
+ }
42
+ const list = {
43
+ remote: true,
44
+ options: { folder: { type: "string" } },
45
+ async run({ ctx, args, client }) {
46
+ if (args.positionals.length > 0)
47
+ throw new UsageError("list takes no arguments; name a folder with --folder.");
48
+ const raw = stringOption(args, "folder");
49
+ const folder = raw === undefined ? "" : trimSlashes(raw);
50
+ const tree = await (await client()).manage.assets.tree();
51
+ const entries = folder === "" ? tree.entries : tree.entries.filter((entry) => entry.path.startsWith(`${folder}/`));
52
+ if (flag(args, "json")) {
53
+ for (const entry of entries)
54
+ ctx.out(JSON.stringify(entry));
55
+ }
56
+ else {
57
+ printTable(ctx, ["path", "kind", "size", "registered", "plugin"], entries.map((e) => [e.path, e.kind, e.size, e.registered ? "yes" : "", e.pluginId]));
58
+ }
59
+ if (tree.truncated)
60
+ ctx.err("the server cut the tree at its limit: some files are not listed.");
61
+ return EXIT.ok;
62
+ },
63
+ };
64
+ const get = {
65
+ remote: true,
66
+ options: { out: { type: "string" } },
67
+ async run({ ctx, args, client }) {
68
+ const path = onePath(args, "get");
69
+ const out = stringOption(args, "out");
70
+ if (out !== undefined) {
71
+ const folder = dirname(resolve(out));
72
+ const found = await stat(folder).catch(() => null);
73
+ if (found === null || !found.isDirectory())
74
+ throw new UsageError(`--out names a folder that does not exist: ${folder}`);
75
+ }
76
+ const api = await client();
77
+ if (out !== undefined) {
78
+ const bytes = await api.manage.assets.raw(path);
79
+ await writeFile(out, bytes);
80
+ if (flag(args, "json"))
81
+ ctx.out(JSON.stringify({ path, bytes: bytes.byteLength, out }));
82
+ else
83
+ ctx.out(`wrote ${bytes.byteLength} bytes of ${cell(path)} to ${out}`);
84
+ return EXIT.ok;
85
+ }
86
+ const result = await api.manage.assets.getContent(path);
87
+ if (flag(args, "json")) {
88
+ ctx.out(JSON.stringify(result));
89
+ return EXIT.ok;
90
+ }
91
+ // Line by line, each through cell(), so a file's control characters never reach the terminal; --out keeps the bytes.
92
+ for (const line of result.content.split("\n"))
93
+ ctx.out(cell(line).trimEnd());
94
+ return EXIT.ok;
95
+ },
96
+ };
97
+ const versions = {
98
+ remote: true,
99
+ async run({ ctx, args, client }) {
100
+ const path = onePath(args, "versions");
101
+ const cursorText = stringOption(args, "cursor");
102
+ if (cursorText !== undefined && (!/^[0-9]+$/.test(cursorText) || !Number.isSafeInteger(Number(cursorText)) || Number(cursorText) < 1)) {
103
+ throw new UsageError("--cursor for versions is a version number of 1 or more, as a previous list printed.");
104
+ }
105
+ const api = await client();
106
+ const { version: current } = await api.manage.assets.getContent(path);
107
+ const fetch = async (query) => {
108
+ const result = await api.manage.assets.listVersions(path, { limit: query.limit, ...(query.cursor !== undefined ? { cursor: Number(query.cursor) } : {}) });
109
+ const nextCursor = result.nextCursor === null ? null : String(result.nextCursor);
110
+ return {
111
+ items: result.items,
112
+ nextCursor,
113
+ async *all() {
114
+ yield* result.items;
115
+ let cursor = nextCursor;
116
+ while (cursor !== null) {
117
+ const more = await fetch({ limit: query.limit, cursor });
118
+ yield* more.items;
119
+ cursor = more.nextCursor;
120
+ }
121
+ },
122
+ };
123
+ };
124
+ return runList(ctx, args, {
125
+ max: PAGE_MAX.assetVersions,
126
+ fetch,
127
+ headers: ["version", "source", "created", "current"],
128
+ row: (v) => [v.version, v.source, v.createdAt, v.version === current ? "yes" : ""],
129
+ });
130
+ },
131
+ };
132
+ const version = {
133
+ remote: true,
134
+ async run({ ctx, args, client }) {
135
+ const { path, version: number } = pathAndVersion(args, "version");
136
+ const result = await (await client()).manage.assets.getVersion(path, number);
137
+ if (flag(args, "json")) {
138
+ ctx.out(JSON.stringify(result));
139
+ return EXIT.ok;
140
+ }
141
+ const v = result.version;
142
+ printKeyValue(ctx, [["Version", v.version], ["Source", v.source], ["Created", v.createdAt], ["Hash", v.hash]]);
143
+ ctx.out("");
144
+ for (const line of v.content.split("\n"))
145
+ ctx.out(cell(line).trimEnd());
146
+ return EXIT.ok;
147
+ },
148
+ };
149
+ const makeCurrent = {
150
+ remote: true,
151
+ destructive: true,
152
+ async plan({ args, client, profile }) {
153
+ const { path, version: number } = pathAndVersion(args, "make-current");
154
+ const api = await client();
155
+ const { version: current } = await api.manage.assets.getContent(path);
156
+ const { version: target } = await api.manage.assets.getVersion(path, number);
157
+ const where = profile.name ?? profile.url;
158
+ const plan = textPlan("assets", profile, `Make version ${target.version} of asset ${cell(path)} current? The site serves it and the file gets its text; version ${current ?? "none"} stays in the history.`, `Would make version ${target.version} of asset ${cell(path)} current on ${where} (${profile.url}). Nothing changed.`);
159
+ return target.version === current ? { ...plan, nothing: `version ${target.version} of asset ${cell(path)} is already current.` } : plan;
160
+ },
161
+ async run({ ctx, args, client }) {
162
+ const { path, version: number } = pathAndVersion(args, "make-current");
163
+ const result = await (await client()).manage.assets.makeCurrent(path, number);
164
+ ctx.out(flag(args, "json") ? JSON.stringify(result) : `asset ${cell(path)} is at version ${result.version}`);
165
+ return EXIT.ok;
166
+ },
167
+ };
168
+ const trash = {
169
+ remote: true,
170
+ async run({ ctx, args, client }) {
171
+ const extra = args.positionals.length > 1 || (args.positionals.length === 1 && args.positionals[0] !== "list");
172
+ if (extra)
173
+ throw new UsageError("trash takes no arguments (or the word list).");
174
+ const api = await client();
175
+ return runList(ctx, args, {
176
+ max: PAGE_MAX.assetTrash,
177
+ fetch: (query) => api.manage.assets.listTrash(query),
178
+ headers: ["id", "path", "plugin", "deleted"],
179
+ row: (a) => [a.id, a.path, a.pluginId, a.deletedAt],
180
+ });
181
+ },
182
+ };
183
+ /** The one trashed row at `path` (or the one with --id). Several trashed rows may share a path (0014). */
184
+ async function trashedAt(api, path, id) {
185
+ if (id !== undefined && !isId(id))
186
+ throw new UsageError("--id is an id as `kardalum assets trash` prints it.");
187
+ const matches = [];
188
+ for await (const row of (await api.manage.assets.listTrash({ limit: PAGE_MAX.assetTrash })).all()) {
189
+ if (row.path === path && (id === undefined || row.id === id))
190
+ matches.push(row);
191
+ }
192
+ if (matches.length === 0) {
193
+ throw new CliError(`no asset at ${cell(path)}${id === undefined ? "" : ` with id ${id}`} is in the trash.`, EXIT.notFound, "see `kardalum assets trash`.");
194
+ }
195
+ if (matches.length > 1) {
196
+ throw new UsageError(`${matches.length} trashed assets have the path ${cell(path)}: name one with --id.`, matches.map((m) => `${m.id} deleted ${m.deletedAt}`).join("\n"));
197
+ }
198
+ return matches[0];
199
+ }
200
+ const restore = {
201
+ remote: true,
202
+ destructive: true,
203
+ options: { id: { type: "string" } },
204
+ async plan({ args, client, profile }) {
205
+ const path = onePath(args, "restore");
206
+ const found = await trashedAt(await client(), path, stringOption(args, "id"));
207
+ const where = profile.name ?? profile.url;
208
+ return textPlan("assets", profile, `Restore asset ${cell(path)} from the trash? Its file is written back from version ${found.currentVersion}, and it comes back as the site's own.`, `Would restore asset ${cell(path)} on ${where} (${profile.url}). Nothing changed.`);
209
+ },
210
+ async run({ ctx, args, client }) {
211
+ const path = onePath(args, "restore");
212
+ const api = await client();
213
+ const found = await trashedAt(api, path, stringOption(args, "id"));
214
+ const result = await api.manage.assets.restore({ path, id: found.id });
215
+ ctx.out(flag(args, "json") ? JSON.stringify(result) : `restored asset ${cell(path)} (version ${result.version})`);
216
+ return EXIT.ok;
217
+ },
218
+ };
219
+ export const assetsNoun = {
220
+ usage: ASSETS_USAGE,
221
+ verbs: { list, get, versions, version, "make-current": makeCurrent, trash, restore },
222
+ };
@@ -18,7 +18,7 @@ export declare function renderRequestEcho(request: {
18
18
  /**
19
19
  * What a dry run prints (2026-10-21-s310-the-ci-mode-design.md section 5). Without --json, the prose of
20
20
  * section 8 of the S305 design. With --json, exactly one line: {"dryRun":true,"request":{method,url,body}}
21
- * or {"dryRun":true,"plan":"<text>"}. The request shape has no header at all, so the key is not part of it.
21
+ * or {"dryRun":true,"plan":"<text>", ...data} (S314c6: a text plan's data). The request shape has no header at all, so the key is not part of it.
22
22
  */
23
23
  export declare function dryRunLines(dryRun: ConfirmPlan["dryRun"], json: boolean): string[];
24
24
  export declare function guardAndConfirm(ctx: ControlContext, plan: ConfirmPlan, flags: {
@@ -12,12 +12,12 @@ export function renderRequestEcho(request) {
12
12
  /**
13
13
  * What a dry run prints (2026-10-21-s310-the-ci-mode-design.md section 5). Without --json, the prose of
14
14
  * section 8 of the S305 design. With --json, exactly one line: {"dryRun":true,"request":{method,url,body}}
15
- * or {"dryRun":true,"plan":"<text>"}. The request shape has no header at all, so the key is not part of it.
15
+ * or {"dryRun":true,"plan":"<text>", ...data} (S314c6: a text plan's data). The request shape has no header at all, so the key is not part of it.
16
16
  */
17
17
  export function dryRunLines(dryRun, json) {
18
18
  if (json) {
19
19
  const shape = dryRun.kind === "text"
20
- ? { dryRun: true, plan: dryRun.text }
20
+ ? { dryRun: true, plan: dryRun.text, ...dryRun.data }
21
21
  : { dryRun: true, request: { method: dryRun.method, url: `${dryRun.baseUrl}${dryRun.path}`, ...(dryRun.body !== undefined ? { body: dryRun.body } : {}) } };
22
22
  return [JSON.stringify(shape)];
23
23
  }
@@ -31,7 +31,8 @@ function cannotAsk(ctx, plan) {
31
31
  export async function guardAndConfirm(ctx, plan, flags) {
32
32
  // Nothing to do: no question, nothing sent, success, whatever the flags.
33
33
  if (plan.nothing !== undefined) {
34
- ctx.out(flags.json === true ? JSON.stringify({ nothing: true, message: plan.nothing }) : plan.nothing);
34
+ const data = plan.dryRun.kind === "text" ? plan.dryRun.data : undefined;
35
+ ctx.out(flags.json === true ? JSON.stringify({ nothing: true, message: plan.nothing, ...data }) : plan.nothing);
35
36
  return { proceed: false, code: EXIT.ok };
36
37
  }
37
38
  // Rule 4: a dry run sends nothing, never prompts, and needs no production flag.
@@ -1,6 +1,6 @@
1
1
  import { flag, stringOption } from "../args.js";
2
2
  import { dryRunLines, guardAndConfirm, withProfileFacts } from "../confirm.js";
3
- import { EXIT, UsageError } from "../errors.js";
3
+ import { CliError, EXIT, UsageError } from "../errors.js";
4
4
  import { collectData, DATA_OPTIONS } from "../input.js";
5
5
  import { cell } from "../output.js";
6
6
  import { requestPlan } from "../plans.js";
@@ -58,16 +58,31 @@ export const update = {
58
58
  if (given === undefined)
59
59
  throw new UsageError("update needs --data <file|->, --field key=value or --name.");
60
60
  const patch = stringOption(args, "data") === undefined;
61
- // A patch cannot name a culture: the save replaces the whole document of the culture it targets.
62
- if (patch && culture !== undefined)
63
- throw new UsageError("a patch cannot target a culture.", "pass the whole document of that culture with --data <file|->.");
64
61
  const api = await client();
65
62
  const id = await resolveContent(api, ref);
66
63
  let data = given;
67
- // --field and --name without --data patch the newest saved version: a bare pair would drop every other field.
64
+ // --field and --name without --data patch the newest saved version of the culture they target
65
+ // (S314o D1): a bare pair would drop every other field. The patch merges over that culture's view,
66
+ // the shared values with its own over them, which is the shape a save takes (flattenForCulture).
67
+ // With --culture the read asks for that view; without it the culture is the site's default, which
68
+ // the same read names, so no settings.read is needed. A server that names none is older than this
69
+ // CLI: merging over its unflattened answer would drop every varying field (the bug D1 fixes), so the
70
+ // patch refuses and says what to do instead.
68
71
  if (patch) {
69
- const latest = await api.manage.content.getLatestVersion(id);
70
- data = { ...latest.version.data, ...given };
72
+ const latest = await api.manage.content.getLatestVersion(id, culture === undefined ? undefined : { locale: culture });
73
+ const target = culture ?? latest.defaultCulture;
74
+ if (target === undefined) {
75
+ throw new CliError("this server does not name its default culture, so a patch cannot tell which culture it targets.", EXIT.failure, "Update the server to the same release as this CLI, or pass --culture <code> to patch one culture.");
76
+ }
77
+ const { flattenForCulture } = await import("@kardalum/api-schemas");
78
+ const base = flattenForCulture(latest.version, target);
79
+ // A culture other than the default sends its own values only: the service carries the shared
80
+ // fields, the name included, forward (D2). The name it would merge in here reads as typed, and a
81
+ // name in the request lets the rename rule move a page whose slug differs from its name, so it
82
+ // stays out unless --name gave it. The default culture's save is a full snapshot and keeps it.
83
+ if (target !== latest.defaultCulture)
84
+ delete base._name;
85
+ data = { ...base, ...given };
71
86
  }
72
87
  const saved = await api.manage.content.save(id, { data, ...(culture !== undefined ? { culture } : {}) });
73
88
  ctx.out(flag(args, "json") ? JSON.stringify(saved) : `updated content ${id} (version ${saved.version.version})`);
@@ -8,11 +8,13 @@ import { timeoutSetting } from "./timeout.js";
8
8
  import { guardAndConfirm, withProfileFacts } from "./confirm.js";
9
9
  import { EXIT, reportFailure, UsageError } from "./errors.js";
10
10
  import { isNoun } from "./nouns.js";
11
+ import { msysRewrites, msysWarning } from "./msys.js";
11
12
  import { contentNoun } from "./content/index.js";
12
13
  import { mediaNoun } from "./media/index.js";
13
14
  import { pluginsNoun } from "./plugins/index.js";
14
15
  import { completionNoun } from "./completion/index.js";
15
16
  import { snapshotsNoun } from "./snapshots/index.js";
17
+ import { assetsNoun } from "./assets/index.js";
16
18
  import { datatypesNoun, templatesNoun, typesNoun } from "./structure/index.js";
17
19
  import { profileNoun } from "./profile.js";
18
20
  import { isGroup } from "./verbs.js";
@@ -63,7 +65,7 @@ function clientFor(ctx, verb, profile, phase, timeoutOverride) {
63
65
  return made;
64
66
  };
65
67
  }
66
- export const BUILT = { profile: profileNoun, whoami: whoamiNoun, content: contentNoun, media: mediaNoun, types: typesNoun, datatypes: datatypesNoun, templates: templatesNoun, snapshots: snapshotsNoun, plugins: pluginsNoun, users: usersNoun, roles: rolesNoun, settings: settingsNoun, audit: auditNoun, completion: completionNoun };
68
+ export const BUILT = { profile: profileNoun, whoami: whoamiNoun, content: contentNoun, media: mediaNoun, types: typesNoun, datatypes: datatypesNoun, templates: templatesNoun, assets: assetsNoun, snapshots: snapshotsNoun, plugins: pluginsNoun, users: usersNoun, roles: rolesNoun, settings: settingsNoun, audit: auditNoun, completion: completionNoun };
67
69
  /** Walks the verb names typed after the noun, one level or two. Throws a UsageError naming the verbs that exist at the level that failed. */
68
70
  function pickVerb(noun, argv) {
69
71
  const only = noun.verbs[""];
@@ -124,6 +126,9 @@ export async function runControl(noun, argv, ctx, nouns = BUILT) {
124
126
  const verbName = names.join(" ");
125
127
  label = names.length === 0 ? noun : `${noun} ${verbName}`;
126
128
  const args = parseCommand(rest, verb.options);
129
+ // S314o (D7): a value Git Bash rewrote is named once on stderr; the command runs as given.
130
+ for (const value of msysRewrites(args, ctx.env))
131
+ ctx.err(msysWarning(label, value));
127
132
  json = flag(args, "json");
128
133
  // A local verb accepts --timeout and ignores it: nothing it does sends a request.
129
134
  const timeoutOverride = verb.remote ? timeoutSetting(args, ctx.env) : undefined;
@@ -115,6 +115,30 @@ function blockedByLines(body) {
115
115
  return [` - document type ${cell(documentType)}${typeof contentCount === "number" ? ` (${contentCount} pages)` : ""}`];
116
116
  });
117
117
  }
118
+ /** `blockedByFields` of a switch-off or uninstall refusal (S314o3): each field that still uses one
119
+ * of the plugin's data types, by document type, at most ten document types and ten fields of each. */
120
+ function blockedByFieldsLines(body) {
121
+ const blocked = typeof body === "object" && body !== null ? body.blockedByFields : undefined;
122
+ if (!Array.isArray(blocked))
123
+ return [];
124
+ const lines = blocked.slice(0, 10).flatMap((entry) => {
125
+ const { documentType, fields } = (entry ?? {});
126
+ if (typeof documentType !== "string" || !Array.isArray(fields))
127
+ return [];
128
+ const named = fields.slice(0, 10).flatMap((field) => {
129
+ const { name, dataType } = (field ?? {});
130
+ if (typeof name !== "string")
131
+ return [];
132
+ return [` - document type ${cell(documentType)}: field ${cell(name)}${typeof dataType === "string" ? ` (data type ${cell(dataType)})` : ""}`];
133
+ });
134
+ if (fields.length > 10)
135
+ named.push(` - document type ${cell(documentType)}: and ${fields.length - 10} more field(s).`);
136
+ return named;
137
+ });
138
+ if (blocked.length > 10)
139
+ lines.push(` - and ${blocked.length - 10} more document type(s).`);
140
+ return lines;
141
+ }
118
142
  const viaMarketplace = new WeakSet();
119
143
  /** Marks a failure of a call the site answers by asking its marketplace, so a 503 with a message reads as the marketplace being unreachable, not the site. */
120
144
  export async function markViaMarketplace(call) {
@@ -155,6 +179,10 @@ function hintFor(api, info) {
155
179
  return "this update lowers the plugin's trust; run it again with --confirm-trust-downgrade if you mean it.";
156
180
  if (api.status === 409 && body.reason === "license-not-recorded")
157
181
  return "the plugin is installed but its licence key was not recorded; check `kardalum plugins list`.";
182
+ // S314o3: a switch-off or uninstall refused because fields use the plugin's data types.
183
+ if (api.status === 409 && Array.isArray(api.body?.blockedByFields)) {
184
+ return "change each field's data type or remove the field, then try again.";
185
+ }
158
186
  if (api.status === 409 && typeof body.currentVersion === "number" && info.label === "templates update") {
159
187
  return `someone saved version ${body.currentVersion} first; read it with \`kardalum templates get <id>\` and pass --base-version ${body.currentVersion}.`;
160
188
  }
@@ -205,7 +233,7 @@ export function describeFailure(error, info) {
205
233
  if (hint !== undefined)
206
234
  lines.push(` Hint: ${hint}`);
207
235
  lines.push(...fieldFailureLines(error));
208
- lines.push(...reasonLines(api.body), ...blockedByLines(api.body));
236
+ lines.push(...reasonLines(api.body), ...blockedByLines(api.body), ...blockedByFieldsLines(api.body));
209
237
  return { code, lines, ...(api.body !== undefined ? { body: api.body } : {}) };
210
238
  }
211
239
  const reason = networkReason(error);
@@ -0,0 +1,4 @@
1
+ import type { ParsedArgs } from "./args.js";
2
+ /** Every positional, string option value and --field value part that looks rewritten, in no set order. */
3
+ export declare function msysRewrites(args: ParsedArgs, env: NodeJS.ProcessEnv): string[];
4
+ export declare function msysWarning(label: string, value: string): string;
@@ -0,0 +1,51 @@
1
+ import { shorten } from "./resolve.js";
2
+ // S314o (D7): Git Bash rewrites an argument that starts with / into a Windows path under its own install
3
+ // folder before the CLI sees it, the part after = of key=/value included (--field image=/img/1.jpg arrives
4
+ // as image=C:/Program Files/Git/img/1.jpg). Checked only under Git Bash (MSYSTEM set) and only against the
5
+ // install prefixes, so a real Windows path (--data C:/doc.json) is never named. A warning, never a
6
+ // refusal: a file option may hold a real path under that folder. A content reference keeps its own
7
+ // refusal (resolveContent).
8
+ // A per-user or Scoop install (C:/Users/<u>/AppData/Local/Programs/Git, .../scoop/apps/git/current) is
9
+ // matched through the shell's own root: Git for Windows sets EXEPATH to it, with backslashes. Compared as
10
+ // a case-blind prefix with plain string operations, never a pattern built from the value.
11
+ const MSYS_PREFIX = /^[A-Za-z]:\/(?:Program Files\/Git|msys64|Git)\//i;
12
+ /** EXEPATH as a lower-case "C:/.../" prefix, or null when it is unset or names no folder below a drive. */
13
+ function exePathPrefix(env) {
14
+ const raw = env.EXEPATH;
15
+ if (raw === undefined)
16
+ return null;
17
+ let root = raw.trim().split("\\").join("/");
18
+ while (root.endsWith("/"))
19
+ root = root.slice(0, -1);
20
+ // "C:" or "C:/" alone would name every path on the drive.
21
+ if (root.length < 4 || root[1] !== ":" || root[2] !== "/")
22
+ return null;
23
+ return `${root.toLowerCase()}/`;
24
+ }
25
+ /** Every positional, string option value and --field value part that looks rewritten, in no set order. */
26
+ export function msysRewrites(args, env) {
27
+ if (env.MSYSTEM === undefined || env.MSYSTEM === "")
28
+ return [];
29
+ const found = [];
30
+ const shellRoot = exePathPrefix(env);
31
+ const check = (value) => {
32
+ if (MSYS_PREFIX.test(value) || (shellRoot !== null && value.toLowerCase().startsWith(shellRoot)))
33
+ found.push(value);
34
+ };
35
+ for (const positional of args.positionals)
36
+ check(positional);
37
+ for (const [name, value] of Object.entries(args.values)) {
38
+ for (const item of Array.isArray(value) ? value : [value]) {
39
+ if (typeof item !== "string")
40
+ continue;
41
+ check(item);
42
+ const at = item.indexOf("=");
43
+ if (name === "field" && at > 0)
44
+ check(item.slice(at + 1));
45
+ }
46
+ }
47
+ return found;
48
+ }
49
+ export function msysWarning(label, value) {
50
+ return `kardalum ${label}: "${shorten(value)}" looks like a path Git Bash rewrote into a Windows one; it is sent as given. Set MSYS_NO_PATHCONV=1 to send values as typed.`;
51
+ }
@@ -8,6 +8,7 @@ export const NOUNS = [
8
8
  { name: "types", summary: "Document types", built: true },
9
9
  { name: "datatypes", summary: "Data types", built: true },
10
10
  { name: "templates", summary: "Templates", built: true },
11
+ { name: "assets", summary: "Public files and text assets: list, read, history, trash", built: true },
11
12
  { name: "plugins", summary: "Installed plugins and the marketplace; kardalum plugin builds one", built: true },
12
13
  { name: "snapshots", summary: "Site snapshots", built: true },
13
14
  { name: "users", summary: "Users and their roles", built: true },
@@ -12,7 +12,7 @@ export declare function renderKeyValue(pairs: [string, unknown][]): string[];
12
12
  export declare function printTable(sink: Sink, headers: string[], rows: unknown[][]): void;
13
13
  export declare function printKeyValue(sink: Sink, pairs: [string, unknown][]): void;
14
14
  /** The line a list prints when a page remains. */
15
- export declare function moreRowsLine(nextCursor: string | null): string | null;
15
+ export declare function moreRowsLine(nextCursor: string | null, before?: string): string | null;
16
16
  /** Writes each row as one JSON line the moment it arrives, so `--all` over a large tree never holds the pages in memory. Returns how many rows it wrote. */
17
17
  export declare function streamNdjson(sink: Sink, rows: AsyncIterable<unknown> | Iterable<unknown>): Promise<number>;
18
18
  export {};
@@ -39,8 +39,8 @@ export function printKeyValue(sink, pairs) {
39
39
  sink.out(line);
40
40
  }
41
41
  /** The line a list prints when a page remains. */
42
- export function moreRowsLine(nextCursor) {
43
- return nextCursor === null ? null : `more rows: --cursor ${cell(nextCursor)}`;
42
+ export function moreRowsLine(nextCursor, before) {
43
+ return nextCursor === null ? null : `more rows: ${before === undefined ? "" : `${before} `}--cursor ${cell(nextCursor)}`;
44
44
  }
45
45
  /** Writes each row as one JSON line the moment it arrives, so `--all` over a large tree never holds the pages in memory. Returns how many rows it wrote. */
46
46
  export async function streamNdjson(sink, rows) {
@@ -18,6 +18,8 @@ export declare const PAGE_MAX: {
18
18
  readonly templates: 100;
19
19
  readonly templateVersions: 100;
20
20
  readonly templateTrash: 100;
21
+ readonly assetVersions: 100;
22
+ readonly assetTrash: 100;
21
23
  readonly plugins: 100;
22
24
  readonly pluginSnapshotGroups: 100;
23
25
  readonly snapshots: 100;
@@ -45,5 +47,9 @@ export interface ListSpec<T> {
45
47
  fetch: Fetch<T>;
46
48
  headers: string[];
47
49
  row(item: T): unknown[];
50
+ /** A page size the caller already worked out with pageSize(), so a list run more than once warns about --limit once. */
51
+ limit?: number;
52
+ /** Options the next page also needs, printed before --cursor on the "more rows" line ("--kind page"). */
53
+ cursorNeeds?: string;
48
54
  }
49
55
  export declare function runList<T>(ctx: ControlContext, args: ParsedArgs, spec: ListSpec<T>): Promise<number>;
@@ -20,6 +20,8 @@ export const PAGE_MAX = {
20
20
  templates: 100,
21
21
  templateVersions: 100,
22
22
  templateTrash: 100,
23
+ assetVersions: 100,
24
+ assetTrash: 100,
23
25
  plugins: 100,
24
26
  pluginSnapshotGroups: 100,
25
27
  snapshots: 100,
@@ -41,7 +43,7 @@ export function pageSize(ctx, args, max) {
41
43
  }
42
44
  export async function runList(ctx, args, spec) {
43
45
  const json = flag(args, "json");
44
- const limit = pageSize(ctx, args, spec.max);
46
+ const limit = spec.limit ?? pageSize(ctx, args, spec.max);
45
47
  const cursor = stringOption(args, "cursor");
46
48
  const first = await spec.fetch(cursor === undefined ? { limit } : { limit, cursor });
47
49
  if (flag(args, "all")) {
@@ -65,7 +67,7 @@ export async function runList(ctx, args, spec) {
65
67
  // worth of look-ahead keeps the "more rows" line from leading to an empty page.
66
68
  // The rows are already printed, so a failed probe is not the command's failure: the line is left out.
67
69
  const probe = await spec.fetch({ limit: 1, cursor: first.nextCursor }).catch(() => null);
68
- const line = probe !== null && probe.items.length > 0 ? moreRowsLine(first.nextCursor) : null;
70
+ const line = probe !== null && probe.items.length > 0 ? moreRowsLine(first.nextCursor, spec.cursorNeeds) : null;
69
71
  if (line !== null)
70
72
  (json ? ctx.err : ctx.out)(line);
71
73
  }
@@ -3,7 +3,7 @@ import type { ConfirmPlan } from "./verbs.js";
3
3
  /** The management API's base path; a request echo prints it in full. */
4
4
  export declare const MANAGE = "/api/manage/v1";
5
5
  /** A plan whose dry run is a sentence. The production facts come from the profile, never from the verb. */
6
- export declare function textPlan(noun: string, profile: ResolvedProfile, question: string, text: string): ConfirmPlan;
6
+ export declare function textPlan(noun: string, profile: ResolvedProfile, question: string, text: string, data?: Record<string, unknown>): ConfirmPlan;
7
7
  /** A plan whose dry run is the request that would be sent (path relative to MANAGE, key masked by the guard). */
8
8
  export declare function requestPlan(noun: string, profile: ResolvedProfile, question: string, request: {
9
9
  method: string;
@@ -2,8 +2,8 @@ import { withProfileFacts } from "./confirm.js";
2
2
  /** The management API's base path; a request echo prints it in full. */
3
3
  export const MANAGE = "/api/manage/v1";
4
4
  /** A plan whose dry run is a sentence. The production facts come from the profile, never from the verb. */
5
- export function textPlan(noun, profile, question, text) {
6
- return withProfileFacts({ noun, profileLine: "", question, dryRun: { kind: "text", text }, guarded: true, production: false, explicit: false, profileName: null, url: "" }, profile);
5
+ export function textPlan(noun, profile, question, text, data) {
6
+ return withProfileFacts({ noun, profileLine: "", question, dryRun: { kind: "text", text, ...(data !== undefined ? { data } : {}) }, guarded: true, production: false, explicit: false, profileName: null, url: "" }, profile);
7
7
  }
8
8
  /** A plan whose dry run is the request that would be sent (path relative to MANAGE, key masked by the guard). */
9
9
  export function requestPlan(noun, profile, question, request) {
@@ -1,5 +1,5 @@
1
1
  import { PLUGINS_USAGE } from "../usage.js";
2
- import { activate, deactivate, recheckLicence, restoreSnapshot, uninstall } from "./lifecycle.js";
2
+ import { activate, deactivate, recheckLicence, restoreDataTypes, restoreSnapshot, uninstall } from "./lifecycle.js";
3
3
  import { install } from "./install.js";
4
4
  import { installRecord, list, marketplaceGet, marketplaceList, snapshots } from "./read.js";
5
5
  export const pluginsNoun = {
@@ -14,6 +14,7 @@ export const pluginsNoun = {
14
14
  snapshots,
15
15
  uninstall,
16
16
  "restore-snapshot": restoreSnapshot,
17
+ "restore-data-types": restoreDataTypes,
17
18
  marketplace: { verbs: { list: marketplaceList, get: marketplaceGet } },
18
19
  },
19
20
  };
@@ -4,3 +4,4 @@ export declare const deactivate: VerbDef;
4
4
  export declare const recheckLicence: VerbDef;
5
5
  export declare const uninstall: VerbDef;
6
6
  export declare const restoreSnapshot: VerbDef;
7
+ export declare const restoreDataTypes: VerbDef;