kardalum 0.18.0 → 0.19.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 (81) hide show
  1. package/dist/control/content/write.js +5 -2
  2. package/dist/control/plugins/lifecycle.js +11 -22
  3. package/dist/control/snapshots/index.js +1 -1
  4. package/dist/control/usage.d.ts +2 -2
  5. package/dist/control/usage.js +8 -5
  6. package/dist/dev/config.js +11 -11
  7. package/dist/dev/docker.js +1 -1
  8. package/dist/dev/port-preflight.js +1 -1
  9. package/dist/entrypoint.js +2 -2
  10. package/dist/plugin/build-federation-bundle.d.ts +8 -0
  11. package/dist/plugin/build-federation-bundle.js +23 -0
  12. package/dist/plugin/build.js +40 -76
  13. package/dist/plugin/bundle-server-manifest.d.ts +4 -4
  14. package/dist/plugin/bundle-server-manifest.js +10 -10
  15. package/dist/plugin/checks/federation-declarations.d.ts +5 -0
  16. package/dist/plugin/checks/federation-declarations.js +131 -0
  17. package/dist/plugin/checks/sdk-shared-key.js +8 -8
  18. package/dist/plugin/checks/templates.d.ts +2 -2
  19. package/dist/plugin/checks/templates.js +5 -5
  20. package/dist/plugin/copy-sample-content.d.ts +3 -3
  21. package/dist/plugin/copy-sample-content.js +3 -3
  22. package/dist/plugin/copy-templates.d.ts +7 -7
  23. package/dist/plugin/copy-templates.js +10 -10
  24. package/dist/plugin/out-dir-guard.d.ts +55 -0
  25. package/dist/plugin/out-dir-guard.js +244 -0
  26. package/dist/plugin/pack-starter.d.ts +3 -3
  27. package/dist/plugin/pack-starter.js +4 -4
  28. package/dist/plugin/pack.js +6 -0
  29. package/dist/plugin/publish.d.ts +1 -1
  30. package/dist/plugin/publish.js +1 -1
  31. package/dist/plugin/validate.js +4 -1
  32. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +1 -1
  33. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +1 -1
  34. package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +1 -1
  35. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +1 -0
  36. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +14 -8
  37. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -3
  38. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +1 -1
  39. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +2 -2
  40. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +2 -2
  41. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +1 -1
  42. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +3 -3
  43. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +90 -0
  44. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +14 -4
  45. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +8 -8
  46. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +11 -8
  47. package/node_modules/@kardalum/api-schemas/dist/index.js +6 -4
  48. package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.d.ts +46 -0
  49. package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.js +52 -0
  50. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +47 -0
  51. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +42 -8
  52. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +9 -9
  53. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +5 -5
  54. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +1 -0
  55. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +24 -0
  56. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +39 -0
  57. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +1 -1
  58. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +3 -3
  59. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +4 -4
  60. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +1 -1
  61. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.d.ts +207 -0
  62. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.js +147 -0
  63. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +11 -0
  64. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -8
  65. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +1 -1
  66. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +1 -1
  67. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +1 -1
  68. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +1 -1
  69. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +1 -1
  70. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +2 -1
  71. package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +2 -2
  72. package/node_modules/@kardalum/plugin-package/dist/envelope.js +2 -2
  73. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +3 -3
  74. package/node_modules/@kardalum/plugin-package/dist/extract.js +9 -9
  75. package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +1 -1
  76. package/node_modules/@kardalum/plugin-package/dist/hash.js +1 -1
  77. package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +2 -2
  78. package/node_modules/@kardalum/plugin-package/dist/package-contract.js +5 -5
  79. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +1 -1
  80. package/node_modules/@kardalum/prisma-variants/dist/index.js +2 -2
  81. package/package.json +6 -6
@@ -79,8 +79,11 @@ export const update = {
79
79
  // A culture other than the default sends its own values only: the service carries the shared
80
80
  // fields, the name included, forward (D2). The name it would merge in here reads as typed, and a
81
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)
82
+ // stays out unless --name gave it. S366c: the default culture's save leaves it out too when the
83
+ // server says a save without `_name` keeps the name (S366 D3, 0.19.0). An older server says
84
+ // nothing; there the default culture's save is a full snapshot that would drop a missing name,
85
+ // so the name stays in.
86
+ if (target !== latest.defaultCulture || latest.saveKeepsName === true)
84
87
  delete base._name;
85
88
  data = { ...base, ...given };
86
89
  }
@@ -42,25 +42,16 @@ async function installedPlugins(api) {
42
42
  return found;
43
43
  }
44
44
  /**
45
- * The members a bundle's uninstall takes with it. No route lists the members a bundle installed,
46
- * so the marketplace listing's members are read (a GET) and matched against what is installed; a
47
- * member installed on its own before the bundle is not the bundle's and stays, which the sentence
48
- * says. Null when the listing cannot be read.
45
+ * S349 (D1, P7): the members a bundle's uninstall takes with it: the member plugins the server
46
+ * reports the bundle declares, matched against what is installed. A member installed on its own
47
+ * before the bundle is not the bundle's and stays, which the sentence says. A plugin is a bundle
48
+ * when it declares members, whatever its label.
49
49
  */
50
- async function bundleMembers(api, id, installed) {
51
- let members = null;
52
- try {
53
- members = (await api.manage.marketplace.getListing(id)).latestVersion?.bundledMembers ?? null;
54
- }
55
- catch {
56
- members = null;
57
- }
58
- if (members === null)
59
- return null;
60
- return members.map((member) => installed.get(member.pluginId)).filter((plugin) => plugin !== undefined);
50
+ function bundleMembers(plugin, installed) {
51
+ return (plugin.bundledPlugins ?? []).map((memberId) => installed.get(memberId)).filter((member) => member !== undefined);
61
52
  }
62
53
  function bundleSentence(present) {
63
- if (present === null || present.length === 0) {
54
+ if (present.length === 0) {
64
55
  return "It is a bundle: it also uninstalls the member plugins it installed, and each member with its own data tables has them removed after a snapshot.";
65
56
  }
66
57
  const named = present.slice(0, 10).map((plugin) => `${cell(plugin.name)} (${cell(plugin.pluginId)})`);
@@ -133,14 +124,12 @@ export const uninstall = {
133
124
  if (plugin.storageType === "structured") {
134
125
  parts.push(`Its data tables are removed after a snapshot you can bring back with \`kardalum plugins restore-snapshot ${id}\`.`);
135
126
  }
136
- const members = plugin.type === "bundle" ? await bundleMembers(api, id, installed) : [];
137
- const dataTypes = await dataTypesSentence(api, new Set([id, ...(members ?? []).map((member) => member.pluginId)]));
127
+ const isBundle = (plugin.bundledPlugins ?? []).length > 0;
128
+ const members = isBundle ? bundleMembers(plugin, installed) : [];
129
+ const dataTypes = await dataTypesSentence(api, new Set([id, ...members.map((member) => member.pluginId)]));
138
130
  if (dataTypes !== "")
139
131
  parts.push(dataTypes);
140
- if (plugin.type === "bundle" && members === null) {
141
- parts.push("The data types of its member plugins are not known: the bundle's listing could not be read.");
142
- }
143
- if (plugin.type === "bundle")
132
+ if (isBundle)
144
133
  parts.push(bundleSentence(members));
145
134
  return requestPlan("plugins", profile, `Uninstall "${cell(plugin.name)}" (${id})? ${parts.join(" ")}`.trimEnd(), {
146
135
  method: "DELETE",
@@ -57,7 +57,7 @@ const restore = {
57
57
  // Built from the plan's fields, not from the server's sentence (written for API callers, it names the label again).
58
58
  const said = `It sets ${itemCount} page version pointer(s) on ${nodeCount} page(s) back to what the snapshot recorded; pages unchanged since then stay as they are.`;
59
59
  const where = profile.name ?? profile.url;
60
- return textPlan("snapshots", profile, `Restore snapshot "${label}"? ${said} The restore is not atomic: take a snapshot first with \`kardalum snapshots create\`.`, `Would restore snapshot "${label}" (${itemCount} items on ${nodeCount} pages) on ${where} (${profile.url}). Nothing changed.`);
60
+ return textPlan("snapshots", profile, `Restore snapshot "${label}"? ${said} It runs in one transaction: if it fails, no page moves. To undo it later, take a snapshot first with \`kardalum snapshots create\`.`, `Would restore snapshot "${label}" (${itemCount} items on ${nodeCount} pages) on ${where} (${profile.url}). Nothing changed.`);
61
61
  }
62
62
  throw new CliError("the server restored the snapshot without asking for confirmation.", EXIT.failure, "check the site's content.");
63
63
  },
@@ -2,12 +2,12 @@ export declare const ASSETS_USAGE = "kardalum assets: the site's public files, a
2
2
  export declare const USAGE: string;
3
3
  export declare const PROFILE_USAGE = "kardalum profile: named connections to your sites\n\nUsage:\n kardalum profile add <name> --url <url> [--production] [--default] [--key-stdin]\n kardalum profile list\n kardalum profile use <name>\n kardalum profile show <name>\n kardalum profile remove <name> [--yes] [--dry-run]\n\nOptions:\n --url <url> The site's address, for example https://staging.example.com\n --production Mark the profile production: --yes then needs --profile <name>\n --default Make this the default profile\n --key-stdin Read the API key from standard input instead of asking\n -h, --help Show this help and exit\n\nThe key is never a flag. It is asked for with hidden input, or piped in with --key-stdin,\nand kept in <home>/credentials (mode 0600 where the platform honours it; on a shared\nWindows machine check the folder's access rights). Profiles are kept in <home>/config.json.\nMint a key in the admin under Settings, API keys; it needs managementApi.use and the\nactions of the commands you will run. Key management and user creation stay in the admin.\n\nExamples:\n kardalum profile add staging --url https://staging.example.com\n printf '%s' \"$KARDALUM_STAGING_KEY\" | kardalum profile add staging --url https://staging.example.com --key-stdin\n kardalum profile add production --url https://www.example.com --production";
4
4
  export declare const WHOAMI_USAGE = "kardalum whoami: who the current profile's key is and what it may do\n\nUsage:\n kardalum whoami [--profile <name>] [--json]\n\nPrints the profile and host, the key's name and expiry, and the actions it holds.\nWith --json it prints the response body of GET /api/manage/v1/whoami.\n\nExamples:\n kardalum whoami\n kardalum whoami --profile production --json";
5
- export declare const CONTENT_USAGE = "kardalum content: pages, their versions, the trash and who may do what\n\nUsage:\n kardalum content list [<id|path>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content get <id|path> [--culture <tag>]\n kardalum content create --type <name|id> --slug <slug> [--parent <id|path|root>] [--name <text>]\n [--data <file|->] [--field key=value ...] [--sort-order <n>]\n kardalum content update <id|path> [--culture <tag>] [--name <text>] [--data <file|->] [--field key=value ...]\n kardalum content publish <id|path> [--culture <tag>] [--version <n>] [--all-cultures]\n kardalum content move <id|path> --to <id|path|root>\n kardalum content copy <id|path> --to <id|path|root> [--include-children]\n kardalum content versions <id|path> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content version <id> <n> [--culture <tag>]\n kardalum content trash [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content restore <id> [--parent <id|path>]\n kardalum content delete <id|path> [--yes] [--dry-run]\n kardalum content permissions get <id|path> [--rows-template]\n kardalum content permissions set <id|path> --rows <file|-> [--yes] [--dry-run]\n\nOptions:\n --culture <tag> The culture to read or write, for example en or pt-BR\n -h, --help Show this help and exit\n\nA path is a stored path such as /home/about (it starts with a slash); an id is a uuid.\nMutations take ids; a path is only looked up. Lists show 50 rows (--limit up to the route's\nmaximum), --all walks every page, --json prints one row per line.\n\n--field values parse as JSON when they can: --field count=3 sends a number (a large one is rounded)\nand --field price=5.50 sends the number 5.5, while a value that is not JSON is sent as the text\n(--field title=Mocha sends \"Mocha\"). Quote the value as JSON to force a string: --field 'price=\"5.50\"'.\n\nUpdate: --data replaces the document of the culture it targets (what you send is what the new\nversion holds; other cultures are kept). In the default culture send the whole document; in any\nother culture send only that culture's own fields: shared fields you leave out keep their values,\nand a shared field you send changes for every culture. --field and --name alone patch\nthe newest saved version of the culture they target (--culture, or the default): the patch merges\nover that culture's own values and the shared ones, so a save made by someone else in between is\noverwritten for those fields; use --data to send the whole culture.\n--name renames the page, and its address follows the name: the last segment of its path\nchanges, so look it up by id afterwards. Every update is a new version; nothing deletes history.\n\nRollback: kardalum content publish <id> --version <n> makes version n the published one. It is how\nyou go back; the versions stay. publish --all-cultures publishes every complete culture and exits 1\nwhen a culture is incomplete, naming its missing fields; the complete ones are published.\n\ndelete moves the page and everything below it to the trash; it asks first, naming the profile\nand how many pages go with it. permissions set replaces all five rows from a JSON file (the\nwhole request body) and can lock you out; --dry-run shows the request. Neither deletes history.\npermissions get --rows-template prints the save body; permissions set --rows also accepts the output of\npermissions get --json (grants whose role or user is gone are dropped, with a warning).\n\n--include-children copies the whole subtree in one request and asks first. A page whose parent was\npermanently removed shows orphaned: yes in content trash; restore it with --parent. Restoring under\na chosen parent follows the move rule: the role needs content.restore, content.create,\ncontent.update and content.publish at the new parent. The server refuses (exit 5) when the page is\nnot an orphan, when the chosen parent is the live page now at the page's old address, or when it\nsits below that address. The pages trashed with it come back with it; pages trashed earlier under\nit stay in the trash and move with it to the new address. Another page at the old address, live or\nin the trash, keeps its own pages.\n\nExamples:\n kardalum content list\n kardalum content list /home --limit 20\n kardalum content get /home/about --json";
5
+ export declare const CONTENT_USAGE = "kardalum content: pages, their versions, the trash and who may do what\n\nUsage:\n kardalum content list [<id|path>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content get <id|path> [--culture <tag>]\n kardalum content create --type <name|id> --slug <slug> [--parent <id|path|root>] [--name <text>]\n [--data <file|->] [--field key=value ...] [--sort-order <n>]\n kardalum content update <id|path> [--culture <tag>] [--name <text>] [--data <file|->] [--field key=value ...]\n kardalum content publish <id|path> [--culture <tag>] [--version <n>] [--all-cultures]\n kardalum content move <id|path> --to <id|path|root>\n kardalum content copy <id|path> --to <id|path|root> [--include-children]\n kardalum content versions <id|path> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content version <id> <n> [--culture <tag>]\n kardalum content trash [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum content restore <id> [--parent <id|path>]\n kardalum content delete <id|path> [--yes] [--dry-run]\n kardalum content permissions get <id|path> [--rows-template]\n kardalum content permissions set <id|path> --rows <file|-> [--yes] [--dry-run]\n\nOptions:\n --culture <tag> The culture to read or write, for example en or pt-BR\n -h, --help Show this help and exit\n\nA path is a stored path such as /home/about (it starts with a slash); an id is a uuid.\nMutations take ids; a path is only looked up. Lists show 50 rows (--limit up to the route's\nmaximum), --all walks every page, --json prints one row per line.\n\n--field values parse as JSON when they can: --field count=3 sends a number (a large one is rounded)\nand --field price=5.50 sends the number 5.5, while a value that is not JSON is sent as the text\n(--field title=Mocha sends \"Mocha\"). Quote the value as JSON to force a string: --field 'price=\"5.50\"'.\n\nUpdate: --data replaces the document's fields in the culture it targets (what you send is what the\nnew version holds; other cultures are kept). The page's name (_name) is kept unless the data names\none. In the default culture send the whole document; in any\nother culture send only that culture's own fields: shared fields you leave out keep their values,\nand a shared field you send changes for every culture. --field and --name alone patch\nthe newest saved version of the culture they target (--culture, or the default): the patch merges\nover that culture's own values and the shared ones, so a save made by someone else in between is\noverwritten for those fields; use --data to send the whole culture. A patch sends the name only\nwhen --name gives it (a server older than 0.19.0 gets the current name back in a default-culture\npatch, since it would otherwise drop it).\n--name renames the page, and its address follows the name: the last segment of its path\nchanges, so look it up by id afterwards. Every update is a new version; nothing deletes history.\n\nRollback: kardalum content publish <id> --version <n> makes version n the published one. It is how\nyou go back; the versions stay. publish --all-cultures publishes every complete culture and exits 1\nwhen a culture is incomplete, naming its missing fields; the complete ones are published.\n\ndelete moves the page and everything below it to the trash; it asks first, naming the profile\nand how many pages go with it. permissions set replaces all five rows from a JSON file (the\nwhole request body) and can lock you out; --dry-run shows the request. Neither deletes history.\npermissions get --rows-template prints the save body; permissions set --rows also accepts the output of\npermissions get --json (grants whose role or user is gone are dropped, with a warning).\n\n--include-children copies the whole subtree in one request and asks first. A page whose parent was\npermanently removed shows orphaned: yes in content trash; restore it with --parent. Restoring under\na chosen parent follows the move rule: the role needs content.restore, content.create,\ncontent.update and content.publish at the new parent. The server refuses (exit 5) when the page is\nnot an orphan, when the chosen parent is the live page now at the page's old address, or when it\nsits below that address. The pages trashed with it come back with it; pages trashed earlier under\nit stay in the trash and move with it to the new address. Another page at the old address, live or\nin the trash, keeps its own pages.\n\nExamples:\n kardalum content list\n kardalum content list /home --limit 20\n kardalum content get /home/about --json";
6
6
  export declare const MEDIA_USAGE = "kardalum media: the media library\n\nUsage:\n kardalum media list [--search <text>] [--folder <id|root>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum media get <id>\n kardalum media upload <file> [--folder <id|root>] [--content-type <type>]\n kardalum media replace <id> <file> [--content-type <type>]\n kardalum media update <id> [--visibility public|private] [--folder <id|root>]\n kardalum media link <id>\n kardalum media versions <id> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum media make-current <id> <n>\n kardalum media delete <id> [--yes] [--dry-run]\n kardalum media trash [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum media restore <id>\n kardalum media purge <id> [--yes] [--dry-run]\n kardalum media empty-trash [--yes] [--dry-run]\n kardalum media folders list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum media folders create <name> [--parent <id|root>]\n kardalum media folders update <id> [--name <text>] [--parent <id|root>]\n kardalum media folders delete <id> [--yes] [--dry-run]\n\nOptions:\n --content-type <type> The file's MIME type; by default it is read from the file name\n -h, --help Show this help and exit\n\nThe CLI reads the whole file into memory; the server refuses a file above its limit\n(50 MiB by default) with a 413. A replacement must keep the same kind of file (image stays image).\ndelete moves a file to the trash; purge and empty-trash remove files for good and ask first,\nnaming how many pages use them. empty-trash removes whatever is in the trash when you confirm,\nincluding a file trashed after the question was asked. Lists show 50 rows (--limit up to the\nroute's maximum).\n\nExamples:\n kardalum media upload ./logo.png --folder root\n kardalum media list --search logo --json\n kardalum media empty-trash --profile staging --dry-run";
7
7
  export declare const TYPES_USAGE = "kardalum types: document types\n\nUsage:\n kardalum types list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum types get <id|name> [--json]\n kardalum types create --data <file|->\n kardalum types update <id|name> --data <file|->\n kardalum types set-default-template <id|name> --template <template id|none>\n kardalum types delete <id|name> [--yes] [--dry-run]\n\nOptions:\n --data <file|-> The whole request body as JSON, from a file or standard input\n -h, --help Show this help and exit\n\nupdate is a full replace: name, icon, fields, tabs and tree rules are replaced by what the file holds,\nso start from `kardalum types get <id> --json`: its id, kind and defaultTemplateId are dropped (id and\nkind cannot change; the default template has its own command, set-default-template).\nA type is addressed by id or by its exact name. delete asks first and says the type's trashed pages are\npermanently removed; the server refuses while pages, templates or media still use the type.\n\nExamples:\n kardalum types get Article --json > article.json\n kardalum types update Article --data article.json\n kardalum types delete Article --profile staging --dry-run";
8
8
  export declare const DATATYPES_USAGE = "kardalum datatypes: data types (named, configured editors for fields)\n\nUsage:\n kardalum datatypes list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum datatypes get <id> [--json]\n kardalum datatypes create --name <text> --editor <editor id> [--settings <file|->]\n kardalum datatypes update <id> [--name <text>] [--settings <file|->]\n kardalum datatypes delete <id> [--yes] [--dry-run]\n\nOptions:\n --settings <file|-> The editor's settings as a JSON object; on update it replaces the settings\n -h, --help Show this help and exit\n\nThe editor of a data type cannot be changed. delete asks first; the server refuses a built-in data\ntype, and refuses while a document type has a field of the data type, naming those types. delete\nreads the data type first to name it, so a key profile needs dataTypes.read beside dataTypes.delete.\n\nExamples:\n kardalum datatypes list\n kardalum datatypes create --name \"Short text\" --editor com.kardalum.text";
9
9
  export declare const TEMPLATES_USAGE = "kardalum templates: render templates\n\nUsage:\n kardalum templates list [--kind page|layout|partial] [--document-type <name|id>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates get <id> [--json]\n kardalum templates create --name <text> [--alias <alias>] [--kind page|layout|partial]\n [--document-type <name|id>] [--content <file|->]\n kardalum templates update <id> [--name <text>] [--content <file|->] [--base-version <n>]\n kardalum templates delete <id> [--yes] [--dry-run]\n kardalum templates sync\n kardalum templates versions <id> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates version <id> <n> [--json]\n kardalum templates make-current <id> <n> [--yes] [--dry-run]\n kardalum templates trash [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum templates restore <id> [--yes] [--dry-run]\n\nOptions:\n --content <file|-> The template source, from a file or standard input (the site's template limit applies: 1 MiB unless KARDALUM_MAX_TEMPLATE_BYTES raises it)\n --base-version <n> Refuse the save when the template has moved past version n (exit 5)\n -h, --help Show this help and exit\n\nTemplates are addressed by id. delete asks first, naming the document types that use the template as\ntheir default and whether it is the catch-all; a confirmed delete clears those pointers.\n\nA template's file is templates/<pages|layouts|partials>/<alias>.liquid: the folder is the kind, and\naliases are unique per kind. list prints three sections, Pages, Layouts and Partials; --kind lists one\n(a --cursor belongs to one kind's list, so it needs --kind). create writes the file into its kind's\nfolder and refuses an alias whose first folder is pages, layouts or partials (a one-segment alias such\nas \"pages\" is an ordinary name). sync reads the template files in the three folders on the server's\ndisk, updates the stored versions from them and adopts a file no template owns; it names every other\nentry at the top of the templates folder as ignored, and moves nothing.\n\nversions lists a template's history, newest first; version prints one with its text. make-current\nasks first, then makes a stored version the one the site renders and writes it to the template file;\nno version is changed, and the next save becomes the version after the newest. trash lists trashed\ntemplates; restore asks first, then brings one back with its history and its file, as the site's own\n(a plugin that shipped it no longer tracks it; exit 5 when a live template uses its alias now).\n\nExamples:\n kardalum templates get 4f2a... --json\n kardalum templates update 4f2a... --content ./article.liquid --base-version 3\n kardalum templates versions 4f2a...\n kardalum templates make-current 4f2a... 2 --dry-run";
10
- export declare const SNAPSHOTS_USAGE = "kardalum snapshots: snapshots of which version of each page is published\n\nUsage:\n kardalum snapshots list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum snapshots create <label> [--description <text>]\n kardalum snapshots restore <id> [--yes] [--dry-run]\n kardalum snapshots delete <id> [--yes] [--dry-run]\n\nOptions:\n -h, --help Show this help and exit\n\nrestore repoints the published version of every page the snapshot recorded, all at once. It asks\nfirst, naming how many page versions and pages move. Pages created since keep their state and no\nversion is deleted, but the restore is one write per page and not atomic: take a snapshot first.\ndelete asks first and removes the snapshot's record only; no page changes.\nThese are site snapshots; a plugin's data snapshots are `kardalum plugins snapshots <id>`.\n\nExamples:\n kardalum snapshots create \"Before the redesign\"\n kardalum snapshots restore 4f2a... --profile staging --dry-run";
10
+ export declare const SNAPSHOTS_USAGE = "kardalum snapshots: snapshots of which version of each page is published\n\nUsage:\n kardalum snapshots list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum snapshots create <label> [--description <text>]\n kardalum snapshots restore <id> [--yes] [--dry-run]\n kardalum snapshots delete <id> [--yes] [--dry-run]\n\nOptions:\n -h, --help Show this help and exit\n\nrestore repoints the published version of every page the snapshot recorded, all at once. It asks\nfirst, naming how many page versions and pages move. Pages created since keep their state and no\nversion is deleted. The restore runs in one transaction: if it fails, no page moves.\ndelete asks first and removes the snapshot's record only; no page changes.\nThese are site snapshots; a plugin's data snapshots are `kardalum plugins snapshots <id>`.\n\nExamples:\n kardalum snapshots create \"Before the redesign\"\n kardalum snapshots restore 4f2a... --profile staging --dry-run";
11
11
  export declare const AUDIT_USAGE = "kardalum audit: the site's audit log, who did what and from where\n\nUsage:\n kardalum audit list [--limit <n>] [--all] [--cursor <c>] [--json]\n [--from <time>] [--to <time>] [--kind <kind>] [--user <id>]\n [--key <id>] [--ip <address>] [--route <pattern>] [--status <code>]\n kardalum audit export --period <YYYY-MM> [--out <file>]\n\nOptions:\n --from, --to <time> Entries at or after, at or before this time (ISO 8601: 2026-10-01T00:00:00Z)\n --kind <kind> session, key, site or anonymous\n --user <id> Only the entries of this user id\n --key <id> Only the entries of this API key id\n --ip <address> Only the entries from this address\n --route <pattern> Only this registered route, such as /api/manage/v1/content/:id/publish\n --status <code> Only this HTTP status\n --period <YYYY-MM> The month to export, in UTC\n --out <file> Write the export to this file instead of standard output\n -h, --help Show this help and exit\n\nlist prints the newest entries first, and says on standard error how many entries the server\ncould not record since it started, when there are any. export prints one JSON object per line\n(NDJSON), oldest first, and is itself recorded in the log. Piped into a command that stops\nreading early, such as head, either ends quietly: with 0, or with the run's own code when it\nhad already failed. The key needs managementApi.use with\naudit.read for list and audit.export for export: administrator actions, because every entry\ncarries the name and email of who acted.\n\nExamples:\n kardalum audit list --kind key --status 403 --json\n kardalum audit export --period 2026-10 --out audit-2026-10.ndjson --profile production";
12
12
  export declare const PLUGINS_USAGE = "kardalum plugins: the plugins installed on a site and the marketplace\n(kardalum plugin, without the s, builds a plugin: validate, build, pack, publish)\n\nUsage:\n kardalum plugins list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins install-record <id>\n kardalum plugins install <file|id> [--answers <file>] [--answers-stdin] [--print-questions]\n [--plugin-version <v>] [--license-key-stdin] [--confirm-trust-downgrade]\n kardalum plugins activate <id>\n kardalum plugins deactivate <id>\n kardalum plugins recheck-licence <id>\n kardalum plugins snapshots <id> [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins uninstall <id> [--keep-sample-content] [--keep-roles] [--yes] [--dry-run]\n kardalum plugins restore-snapshot <id> [--yes] [--dry-run]\n kardalum plugins restore-data-types <id> [--group <id>] [--yes] [--dry-run] [--json]\n kardalum plugins marketplace list [--search <text>] [--type <type>] [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum plugins marketplace get <id>\n\nOptions:\n --keep-sample-content Uninstall: keep the sample pages the install added\n --keep-roles Uninstall: keep the roles the install created\n --group <id> restore-data-types: the snapshot group whose record comes back (default: the latest)\n --answers <file> Answers to the install questions as JSON (anything left out takes its default)\n --answers-stdin The same answers, read from standard input\n --print-questions Print what the listing asks, with an answers.json to start from; installs nothing\n --plugin-version <v> A listing's version other than the latest\n --license-key-stdin A paid listing's licence key, from standard input (or set KARDALUM_LICENSE_KEY)\n --confirm-trust-downgrade\n Allow a package upload to lower an installed plugin's trust\n -h, --help Show this help and exit\n\ninstall takes a package file (made by `kardalum plugin pack`) or a marketplace plugin id. A listing\npublishes its questions: `--print-questions` prints them and an answers.json, a script passes it with\n--answers, and a person at a terminal is asked. An update asks only what the recorded answers leave\nopen; it reads the install record, so the key also needs plugins.read. A package file has no listing, so it is never asked: without --answers the server applies each\ndefault and says what it refused. A licence key is never a flag: pipe it in or set KARDALUM_LICENSE_KEY.\nThe server refuses a package above its size limit (50 MiB by default) with a 413.\n\nA plugin id is reverse-domain, such as com.example.shop. uninstall asks first, naming the sample\npages and roles that go, the media that stays, and, for a plugin with its own data tables, that they\nare removed after a snapshot; a bundle names its member plugins, which go with it. The dry run only\nreads and changes nothing. restore-snapshot brings a plugin's\ndata tables back from their newest snapshots: it asks with the plan's table count, and the confirmation\ncarries the plan it showed, so a plan that changed meanwhile is shown again and nothing is restored.\nrestore-data-types brings back the data types an uninstall recorded, with their ids, once the plugin\nis installed again: it asks with how many come back and names each one skipped with why (its id or\nname exists again, its editor's plugin is missing or switched off, or its settings no longer fit).\nThe marketplace commands exist only when the site has a marketplace (otherwise: not found, exit 4).\n\nExamples:\n kardalum plugins list\n kardalum plugins uninstall com.example.shop --keep-roles --dry-run\n kardalum plugins marketplace list --search commerce";
13
13
  export declare const USERS_USAGE = "kardalum users: the people who can sign in to a site\n\nUsage:\n kardalum users list [--limit <n>] [--all] [--cursor <c>] [--json]\n kardalum users set-role <userId> <role> [--yes] [--dry-run]\n kardalum users delete <userId> [--yes] [--dry-run]\n\nOptions:\n -h, --help Show this help and exit\n\nset-role asks first, showing the old role and the new one; it reads the roles first, so the key needs\nroles.read beside users.update, and it may assign only a role whose actions it holds. Only an\nadministrator's session may grant or revoke the admin role; a key is refused. delete asks first: the person's sessions end at once, the API\nkeys they made keep working as site credentials (revoke them in the admin if they should stop), content\nthey wrote keeps their id, and files they uploaded stay and move to the system account. A key can never\ndelete an administrator; the last administrator, the system account and your own account cannot be\ndeleted. A delete or a role change takes effect on the person's next request.\nPeople are created in the admin (Users); a key cannot create one.\n\nExamples:\n kardalum users list --json\n kardalum users set-role 4f2a... editor --profile staging --dry-run";
@@ -73,7 +73,7 @@ Environment:
73
73
  rewrites it to C:/Program Files/Git/...); the CLI warns when a value looks rewritten
74
74
 
75
75
  In a pipeline: set CI, KARDALUM_URL and KARDALUM_API_KEY, pass --yes and --json. The manual's
76
- guide "The command line in CI" (/v1/guides/cli-in-ci/) has the recipe and the production note.
76
+ guide "The command line in CI" (/v1/headless/cli-in-ci/) has the recipe and the production note.
77
77
 
78
78
  -h, --help Show this help and exit
79
79
  -V, --version Print the version and exit`;
@@ -145,13 +145,16 @@ maximum), --all walks every page, --json prints one row per line.
145
145
  and --field price=5.50 sends the number 5.5, while a value that is not JSON is sent as the text
146
146
  (--field title=Mocha sends "Mocha"). Quote the value as JSON to force a string: --field 'price="5.50"'.
147
147
 
148
- Update: --data replaces the document of the culture it targets (what you send is what the new
149
- version holds; other cultures are kept). In the default culture send the whole document; in any
148
+ Update: --data replaces the document's fields in the culture it targets (what you send is what the
149
+ new version holds; other cultures are kept). The page's name (_name) is kept unless the data names
150
+ one. In the default culture send the whole document; in any
150
151
  other culture send only that culture's own fields: shared fields you leave out keep their values,
151
152
  and a shared field you send changes for every culture. --field and --name alone patch
152
153
  the newest saved version of the culture they target (--culture, or the default): the patch merges
153
154
  over that culture's own values and the shared ones, so a save made by someone else in between is
154
- overwritten for those fields; use --data to send the whole culture.
155
+ overwritten for those fields; use --data to send the whole culture. A patch sends the name only
156
+ when --name gives it (a server older than 0.19.0 gets the current name back in a default-culture
157
+ patch, since it would otherwise drop it).
155
158
  --name renames the page, and its address follows the name: the last segment of its path
156
159
  changes, so look it up by id afterwards. Every update is a new version; nothing deletes history.
157
160
 
@@ -314,7 +317,7 @@ Options:
314
317
 
315
318
  restore repoints the published version of every page the snapshot recorded, all at once. It asks
316
319
  first, naming how many page versions and pages move. Pages created since keep their state and no
317
- version is deleted, but the restore is one write per page and not atomic: take a snapshot first.
320
+ version is deleted. The restore runs in one transaction: if it fails, no page moves.
318
321
  delete asks first and removes the snapshot's record only; no page changes.
319
322
  These are site snapshots; a plugin's data snapshots are \`kardalum plugins snapshots <id>\`.
320
323
 
@@ -14,8 +14,8 @@ const DIALECTS = ["sqlite", "postgres", "mysql"];
14
14
  // Forward slashes everywhere: Prisma file: URLs and generator output
15
15
  // paths both accept them on Windows, and they keep tests platform-stable.
16
16
  // Exported so other modules (server-resolution.ts) normalize paths the
17
- // same way before they reach a user-facing error message or console.warn
18
- // — join() re-introduces backslashes on win32 even when its inputs are
17
+ // same way before they reach a user-facing error message or console.warn.
18
+ // join() re-introduces backslashes on win32 even when its inputs are
19
19
  // already forward-slashed, so this must be applied at each message site,
20
20
  // not just once when a path is first computed.
21
21
  export function fwd(path) {
@@ -34,13 +34,13 @@ const COMPOSE_SERVICES = {
34
34
  const USAGE = "Usage: kardalum dev start [--db sqlite|postgres|mysql] [--server-port <n>] " +
35
35
  "[--plugin-port <n>] [--server-version <version>]";
36
36
  // Cold first boot compiles the whole server off tsx while vite cold-starts
37
- // the admin — on a slow disk (OneDrive-synced checkouts especially) 60s
37
+ // the admin: on a slow disk (OneDrive-synced checkouts especially) 60s
38
38
  // was genuinely not enough (2026-08-25 fresh-clone finding #3).
39
39
  const DEFAULT_READY_TIMEOUT_MS = 180_000;
40
- // apps/server/package.json relative to repoRoot — the same checkout
40
+ // apps/server/package.json relative to repoRoot, the same checkout
41
41
  // probe kardalum dev has always used (formerly a checkout assertion in
42
42
  // sandbox.ts, which failed loudly when it was missing; S187 deleted that
43
- // function — standalone is not an error state, just the other mode).
43
+ // function; standalone is not an error state, just the other mode).
44
44
  export function detectMode(repoRoot) {
45
45
  return existsSync(join(repoRoot, "apps", "server", "package.json")) ? "checkout" : "standalone";
46
46
  }
@@ -53,14 +53,14 @@ export function kardalumDevHome(env = process.env) {
53
53
  return fwd(override ? override : join(homedir(), ".kardalum", "dev"));
54
54
  }
55
55
  // S187: standalone's state dir lives under kardalumDevHome(), keyed by a
56
- // short hash of the plugin project's own absolute path — not `cwd`
56
+ // short hash of the plugin project's own absolute path, not `cwd`
57
57
  // itself, which would need escaping/truncation to become a directory
58
58
  // name and could collide across drives/casings that hash identically
59
59
  // once normalized. `fwd()`-normalize the input first so the same project
60
60
  // path hashes the same regardless of which slash style produced it (a
61
61
  // raw win32 backslash path vs. one already forward-slashed).
62
62
  //
63
- // Not cryptographically motivated — collisions just mean two unrelated
63
+ // Not cryptographically motivated: collisions just mean two unrelated
64
64
  // plugin projects would share a sandbox, which is implausible at the
65
65
  // hex-10 (40-bit) length used here for a single developer's machine, and
66
66
  // cheap to tell apart in `~/.kardalum/dev/sandboxes/` if it ever happened.
@@ -130,14 +130,14 @@ export function resolveSandboxConfig(argv, cwd, env = process.env) {
130
130
  // --admin-port is the pre-S187 flag name; --plugin-port is preferred.
131
131
  // Exactly one deprecation line, printed only when --admin-port was
132
132
  // actually passed (not merely because it happens to equal the
133
- // default) — an explicit --plugin-port still wins if both are given.
133
+ // default); an explicit --plugin-port still wins if both are given.
134
134
  if (values["admin-port"] !== undefined) {
135
135
  console.warn("[kardalum dev] --admin-port is deprecated; use --plugin-port instead.");
136
136
  }
137
137
  const pluginPortRaw = values["plugin-port"] ?? values["admin-port"];
138
138
  const pluginPort = parsePort("plugin-port", pluginPortRaw, DEFAULT_PLUGIN_PORT);
139
139
  // standalone mode preflights both as separate ports (assertPortsFree
140
- // in sandbox.ts) — a developer who passes the same number for both would
140
+ // in sandbox.ts), a developer who passes the same number for both would
141
141
  // otherwise get a confusing "port already in use" failure pointing at
142
142
  // itself, rather than a clear rejection here.
143
143
  if (serverPort === pluginPort) {
@@ -152,8 +152,8 @@ export function resolveSandboxConfig(argv, cwd, env = process.env) {
152
152
  // Checkout mode's state dir stays exactly `<cwd>/.kardalum-dev`, as it
153
153
  // always has. Standalone has no monorepo checkout to root itself
154
154
  // against, so its state lives under kardalumDevHome() instead, keyed by
155
- // the plugin project's own path (standaloneStateDir/sandboxKey above)
156
- // — two different plugin projects get two independent sandboxes.
155
+ // the plugin project's own path (standaloneStateDir/sandboxKey above);
156
+ // two different plugin projects get two independent sandboxes.
157
157
  const stateDir = mode === "standalone" ? standaloneStateDir(normalizedCwd, kardalumDevHome(env)) : fwd(join(cwd, ".kardalum-dev"));
158
158
  return {
159
159
  dialect,
@@ -1,7 +1,7 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { SandboxError } from "./config.js";
4
- // All docker interaction is synchronous — each step must finish before
4
+ // All docker interaction is synchronous: each step must finish before
5
5
  // the next starts, and none is long-running (compose --wait blocks until
6
6
  // the healthcheck passes). shell:true throughout: Windows resolves
7
7
  // docker/pnpm through .cmd shims.
@@ -3,7 +3,7 @@ import { execFileSync } from "node:child_process";
3
3
  // S180 postmortem: a stale tsx-watch server held :3100 while its parent
4
4
  // task had already died, and the sandbox's URL-based readiness check was
5
5
  // fooled into treating the imposter as the real server coming up. Failing
6
- // fast here — before anything is spawned or composed — turns that into a clear error
6
+ // fast here (before anything is spawned or composed) turns that into a clear error
7
7
  // instead of a confusing hang.
8
8
  export class PortInUseError extends Error {
9
9
  constructor(message) {
@@ -7,7 +7,7 @@ import { pathToFileURL } from "node:url";
7
7
  // silently no-ops under an npm/npx bin on Linux/macOS: those bins are real
8
8
  // SYMLINKS (node_modules/.bin/<cli> -> ../<pkg>/dist/index.js), so
9
9
  // `process.argv[1]` is the symlink path while `import.meta.url` is the
10
- // resolved realpath — a raw string compare never matches, so the CLI does
10
+ // resolved realpath: a raw string compare never matches, so the CLI does
11
11
  // nothing. (Windows uses .cmd shims, not symlinks, which is why it only
12
12
  // bit Linux/macOS.) Resolving the invoked path's realpath before comparing
13
13
  // makes symlinked/npx invocation run, while `node dist/index.js` keeps
@@ -22,7 +22,7 @@ export function isEntrypoint(moduleUrl, invokedPath, realpath = realpathSync) {
22
22
  return moduleUrl === pathToFileURL(realpath(invokedPath)).href;
23
23
  }
24
24
  catch {
25
- // realpath throws if the invoked path no longer exists — treat as
25
+ // realpath throws if the invoked path no longer exists, treat as
26
26
  // "not the entry point" rather than crashing.
27
27
  return false;
28
28
  }
@@ -1,3 +1,11 @@
1
+ /** S362 spec D3: what @module-federation/vite's type generation writes into
2
+ * outDir when a plugin's config leaves `dts` on (measured in S362: a
3
+ * directory and two files, all written before build() resolves). No Kardalum
4
+ * host reads federated type declarations, so a package that carries them
5
+ * describes an API surface that does not exist. Fixed names, joined to
6
+ * outDir: nothing an author named is ever removed here. */
7
+ export declare const TYPE_DECLARATION_ARTEFACTS: readonly string[];
8
+ export declare function removeTypeDeclarationArtefacts(outDir: string): void;
1
9
  export interface FederationBuildResult {
2
10
  outDir: string;
3
11
  remoteEntryPath: string | null;
@@ -2,6 +2,19 @@ import { mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { join, resolve } from "node:path";
4
4
  import { build } from "vite";
5
+ /** S362 spec D3: what @module-federation/vite's type generation writes into
6
+ * outDir when a plugin's config leaves `dts` on (measured in S362: a
7
+ * directory and two files, all written before build() resolves). No Kardalum
8
+ * host reads federated type declarations, so a package that carries them
9
+ * describes an API surface that does not exist. Fixed names, joined to
10
+ * outDir: nothing an author named is ever removed here. */
11
+ export const TYPE_DECLARATION_ARTEFACTS = ["@mf-types", "@mf-types.zip", "@mf-types.d.ts"];
12
+ export function removeTypeDeclarationArtefacts(outDir) {
13
+ for (const name of TYPE_DECLARATION_ARTEFACTS) {
14
+ // rmSync removes a link itself, never what it points at.
15
+ rmSync(join(outDir, name), { recursive: true, force: true, maxRetries: 10, retryDelay: 500 });
16
+ }
17
+ }
5
18
  /**
6
19
  * Shared core: runs a real Vite Module Federation build for
7
20
  * `absolutePluginDir` into `outDir` (already resolved, already
@@ -73,6 +86,16 @@ async function runFederationBuild(absolutePluginDir, outDir) {
73
86
  }
74
87
  process.chdir(previousCwd);
75
88
  }
89
+ // Both the temporary build validate measures and build's real one: the size
90
+ // check measures what ships (S362 spec D3).
91
+ try {
92
+ removeTypeDeclarationArtefacts(outDir);
93
+ }
94
+ catch (error) {
95
+ // A file a scanner still holds: report it as the build's failure, which
96
+ // build.ts handles (it discards the outDir), rather than throwing past it.
97
+ return { remoteEntryPath: null, buildError: error instanceof Error ? error.message : String(error) };
98
+ }
76
99
  const remoteEntryName = readdirSync(outDir).find((file) => /^remoteEntry.*\.js$/.test(file));
77
100
  return { remoteEntryPath: remoteEntryName ? join(outDir, remoteEntryName) : null };
78
101
  }
@@ -1,5 +1,5 @@
1
1
  import { mkdirSync, rmSync } from "node:fs";
2
- import { isAbsolute, join, relative, resolve, sep } from "node:path";
2
+ import { join, resolve } from "node:path";
3
3
  import { buildFederationBundleTo } from "./build-federation-bundle.js";
4
4
  import { bundleServerManifest } from "./bundle-server-manifest.js";
5
5
  import { copyPackageContractFiles } from "./copy-package-contract.js";
@@ -11,6 +11,7 @@ import { packStarterIfPresent } from "./pack-starter.js";
11
11
  import { validatePlugin } from "./validate.js";
12
12
  import { writeManifestJson } from "./write-manifest-json.js";
13
13
  import { writeReferenceJson } from "./build-reference.js";
14
+ import { assertDiscardableOutDir, assertSafeOutDir } from "./out-dir-guard.js";
14
15
  import { declaresClientBundle } from "@kardalum/plugin-sdk/manifest";
15
16
  export class BuildValidationError extends Error {
16
17
  validation;
@@ -67,89 +68,52 @@ export function assertFederationBuildSucceeded(result, pluginDir) {
67
68
  * neither is at risk of being clobbered by it.
68
69
  */
69
70
  export async function buildPlugin(pluginDir, outDir) {
70
- // Resolved to absolute here (not left to buildFederationBundleTo alone)
71
- // so BuildResult.outDir is always absolute and consistent for callers
72
- // (CLI output, bundleServerManifest's outDir arg) regardless of whether
73
- // pluginDir/outDir were passed in as relative paths.
74
- const resolvedOutDir = resolve(outDir ?? join(pluginDir, "kardalum-package"));
75
- const resolvedPluginDir = resolve(pluginDir);
76
- // Refuse an outDir that IS the plugin's own source directory, or an
77
- // ancestor of it, before anything here writes or deletes a single byte.
71
+ // Refuse an outDir the build must not empty, before anything here writes or
72
+ // deletes a single byte. The federation build runs Vite with emptyOutDir
73
+ // (Vite only warns about an outDir that holds the project, then empties it,
74
+ // keeping .git), and every failure path below removes outDir whole, so the
75
+ // guard is the one thing between an author's typo and their sources. S265
76
+ // built it as a comparison of two spellings; S361 makes it ask the
77
+ // filesystem: canonical paths for the plugin-or-ancestor rule, and an outDir
78
+ // the author named must be new, empty, or what a build left (S361 spec D1
79
+ // to D6). The default outDir is the build's own and skips the contents test.
80
+ // The author's own spelling goes in, so a refusal names the path they typed.
78
81
  //
79
- // This guard used to sit in the view-less branch alone, on the stated
80
- // belief that Vite protected the client-bearing branch by refusing an
81
- // outDir that is or contains the project root. Vite does not refuse.
82
- // Reproduced against vite 6.4.3: that condition produces a logger.warn
83
- // and nothing more, runFederationBuild (build-federation-bundle.ts) runs
84
- // Vite with logLevel "silent" so even that warning is swallowed, and
85
- // Vite's prepareOutDir then calls emptyDir(outDir, ['.git']) anyway
86
- // because emptyOutDir is passed explicitly. It empties AFTER rollup has
87
- // read the sources into memory, so the build SUCCEEDS on a directory it
88
- // has just emptied.
89
- //
90
- // With the federation build now running BEFORE validate (S265), that
91
- // turned `kardalum plugin build --out .` inside a client-bearing plugin
92
- // into unrecoverable loss: Vite emptied the source tree, validate then
93
- // failed against the wreckage (checkTypeScript, README, cover), and the
94
- // failure-path rmSync below removed the directory outright, .git and all.
95
- // Before S265 the same invocation was merely a footgun, because Vite
96
- // emptied the directory after validate had passed and left .git behind,
97
- // so `git checkout .` recovered everything. `--out <parent of the
98
- // plugin>` is the same shape with a larger blast radius.
99
- //
100
- // The question "is outDir the plugin directory or an ancestor of it" is a
101
- // path question, and path.relative is what answers it. The condition here
102
- // used to be
103
- // resolvedOutDir === resolvedPluginDir ||
104
- // resolvedPluginDir.startsWith(resolvedOutDir + sep)
105
- // which is a string comparison, and two shapes walked past it:
106
- // - A different spelling of the same directory. resolve normalizes
107
- // neither drive-letter case nor segment case, so on Windows
108
- // `--out e:\kardalum\plugins` against E:\kardalum\plugins\blog compared
109
- // unequal while naming the very same directory to the filesystem.
110
- // - The volume root. resolve("E:/") is "E:\", so `resolvedOutDir + sep`
111
- // was "E:\\" and nothing ever started with it: `--out E:\`, or
112
- // `--out /` on POSIX, was accepted with the largest blast radius
113
- // available.
114
- // path.win32.relative closes both: it compares case-insensitively and it
115
- // treats a root as a root. Remaining known gap, deliberate: macOS, whose
116
- // default filesystem is case-insensitive while path.posix.relative is
117
- // case-sensitive, so the different-spelling shape survives there.
118
- //
119
- // Read the three clauses of the condition below one by one, because each
120
- // excludes a shape that must NOT be refused:
121
- // rel === "" -> the same directory (refuse).
122
- // isAbsolute(rel) -> another volume, which win32's relative
123
- // reports as an absolute path rather than
124
- // a "..". Not an ancestor (allow).
125
- // rel === ".." / "../..." -> outDir sits under or beside the plugin,
126
- // which includes the DEFAULT outDir
127
- // <pluginDir>/kardalum-package, whose rel is
128
- // exactly ".." (allow).
129
- const rel = relative(resolvedOutDir, resolvedPluginDir);
130
- const outDirIsPluginDirOrAncestor = rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(".." + sep));
131
- if (outDirIsPluginDirOrAncestor) {
132
- throw new Error(`Refusing to build ${pluginDir}: outDir "${resolvedOutDir}" is the plugin's own source directory ` +
133
- `(or an ancestor of it): building here would delete the plugin's sources. Choose an outDir outside "${resolvedPluginDir}".`);
134
- }
82
+ // What comes back is the path the guard inspected (absolute, a `\\?\`
83
+ // prefix stripped), and it is the only path used below: Vite's outDir,
84
+ // every discard, every copy step and BuildResult.outDir, which is
85
+ // therefore always absolute for callers whatever spelling came in. S361
86
+ // first resolved the raw spelling here as well, and `\\?\E:` or
87
+ // `\\?\UNC\srv\share\..` then named one directory to the guard and
88
+ // another to the build (S361 fix wave, spec row S361-2).
89
+ const resolvedOutDir = assertSafeOutDir(pluginDir, outDir ?? resolve(join(pluginDir, "kardalum-package")), {
90
+ isDefault: outDir === undefined,
91
+ });
135
92
  // Every path that abandons a half-built package removes it whole rather
136
93
  // than emptying it: a package directory that no validate ever passed must
137
94
  // not survive to be installed or zipped.
138
95
  //
139
96
  // What the guard above guarantees, precisely: outDir is not the plugin's
140
- // own directory and not an ancestor of it. What it does NOT rule out is an
141
- // outDir INSIDE the plugin that the caller did not mean as a package
142
- // directory, `kardalum plugin build --out src` being the example. That shape
143
- // still reaches this delete and still loses the contents of src/.
97
+ // own directory and not an ancestor of it, and an outDir the author named
98
+ // holds nothing but a previous package or build output (S361 spec D4), so
99
+ // `--out src` never reaches this delete. It stays a whole-directory
100
+ // delete, which, unlike Vite's emptyDir, does not spare `.git`; that is
101
+ // why, since the S361 fix wave, the guard also refuses a named outDir
102
+ // holding `.git`, `package.json` or `node_modules` (a gh-pages worktree
103
+ // with a remoteEntry.js in it). The delete runs on two kinds of path:
104
+ // after a federation build that failed or did not validate, where Vite
105
+ // has already emptied outDir and only the husk or a half-built package is
106
+ // left; and on a server-only build, where no Vite ran and this delete is
107
+ // what removes a previous build's files. The default outDir skips the
108
+ // contents rule (D5) because it is the build's own, but not the project
109
+ // markers: a `.git`, `package.json` or `node_modules` in it is never a
110
+ // build's, so the guard refuses it there too (S366 spec D7).
144
111
  //
145
- // Narrowing this to a contents-only delete would not fix that, which is
146
- // why it stays a whole-directory delete. By the time any path here runs,
147
- // the federation build has already run Vite with `emptyOutDir: true` over
148
- // the same directory, so the contents are gone either way and the delete
149
- // is only removing the husk. What would fix it is refusing a non-empty
150
- // outDir up front, before the build; that is a separate decision about
151
- // what buildPlugin accepts, not a change to this helper.
112
+ // Each delete first looks again (assertDiscardableOutDir) and refuses an
113
+ // outDir that has become a link since the guard ran. That narrows the
114
+ // window between check and use; it does not close it (S361 fix wave).
152
115
  const discardOutDir = () => {
116
+ assertDiscardableOutDir(resolvedOutDir);
153
117
  rmSync(resolvedOutDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 500 });
154
118
  };
155
119
  // Read before validate() rather than after it, to answer one question:
@@ -3,23 +3,23 @@ export declare class BundleServerManifestError extends Error {
3
3
  }
4
4
  /**
5
5
  * Bundles a plugin's manifest entry (src/plugin.ts(x) plus everything it
6
- * transitively imports — INCLUDING react, react/jsx-runtime and
6
+ * transitively imports, INCLUDING react, react/jsx-runtime and
7
7
  * @kardalum/plugin-sdk) into one self-contained, Node-importable ESM file
8
8
  * at <outDir>/plugin.js. Replaces Session 81's tsc-emit
9
9
  * compileServerManifest: the emitted file kept bare import specifiers,
10
10
  * which plain `import()` can only resolve by walking ancestor
11
- * node_modules — true inside this monorepo, false on a real server (the
11
+ * node_modules, true inside this monorepo, false on a real server (the
12
12
  * S81 gap, reproduced concretely in S83 with a poisoned ancestor
13
13
  * node_modules). A bundle resolves nothing at import time, so the same
14
14
  * package installs anywhere.
15
15
  *
16
16
  * Bundling react into a SERVER-side artifact is safe by design: the
17
17
  * server validates the manifest (Zod needs the live function references),
18
- * persists it, and invokes hooks/apiRoutes handlers — it never renders
18
+ * persists it, and invokes hooks/apiRoutes handlers; it never renders
19
19
  * views. The browser keeps loading views via remoteEntry.js with the
20
20
  * host's Module Federation shared singletons; this file never reaches it.
21
21
  *
22
- * Deliberately configFile: false — the plugin's own vite.config.ts is
22
+ * Deliberately configFile: false: the plugin's own vite.config.ts is
23
23
  * the BROWSER-side federation build and must not leak in here. No
24
24
  * process.chdir() (the buildFederationBundle concurrency caveat does not
25
25
  * spread to this function); all paths resolved absolute up front.
@@ -10,23 +10,23 @@ export class BundleServerManifestError extends Error {
10
10
  }
11
11
  /**
12
12
  * Bundles a plugin's manifest entry (src/plugin.ts(x) plus everything it
13
- * transitively imports — INCLUDING react, react/jsx-runtime and
13
+ * transitively imports, INCLUDING react, react/jsx-runtime and
14
14
  * @kardalum/plugin-sdk) into one self-contained, Node-importable ESM file
15
15
  * at <outDir>/plugin.js. Replaces Session 81's tsc-emit
16
16
  * compileServerManifest: the emitted file kept bare import specifiers,
17
17
  * which plain `import()` can only resolve by walking ancestor
18
- * node_modules — true inside this monorepo, false on a real server (the
18
+ * node_modules, true inside this monorepo, false on a real server (the
19
19
  * S81 gap, reproduced concretely in S83 with a poisoned ancestor
20
20
  * node_modules). A bundle resolves nothing at import time, so the same
21
21
  * package installs anywhere.
22
22
  *
23
23
  * Bundling react into a SERVER-side artifact is safe by design: the
24
24
  * server validates the manifest (Zod needs the live function references),
25
- * persists it, and invokes hooks/apiRoutes handlers — it never renders
25
+ * persists it, and invokes hooks/apiRoutes handlers; it never renders
26
26
  * views. The browser keeps loading views via remoteEntry.js with the
27
27
  * host's Module Federation shared singletons; this file never reaches it.
28
28
  *
29
- * Deliberately configFile: false — the plugin's own vite.config.ts is
29
+ * Deliberately configFile: false: the plugin's own vite.config.ts is
30
30
  * the BROWSER-side federation build and must not leak in here. No
31
31
  * process.chdir() (the buildFederationBundle concurrency caveat does not
32
32
  * spread to this function); all paths resolved absolute up front.
@@ -47,7 +47,7 @@ export async function bundleServerManifest(pluginDir, outDir) {
47
47
  root: absolutePluginDir,
48
48
  configFile: false,
49
49
  logLevel: "silent",
50
- // Bundle EVERYTHING — this is the whole point. Only node: builtins
50
+ // Bundle EVERYTHING: this is the whole point. Only node: builtins
51
51
  // stay external (also enforced via rollupOptions.external below).
52
52
  ssr: { noExternal: true },
53
53
  build: {
@@ -73,19 +73,19 @@ export async function bundleServerManifest(pluginDir, outDir) {
73
73
  throw new BundleServerManifestError(`bundled output missing expected entry ${bundlePath}`);
74
74
  }
75
75
  // Node picks a module format per file by walking UP from that file
76
- // looking for the nearest package.json and reading its "type" field —
77
- // ancestor directories, not just the immediate one. plugin.js itself has
78
- // no extension marker (it stays "plugin.js", not "plugin.mjs" —
76
+ // looking for the nearest package.json and reading its "type" field.
77
+ // Ancestor directories, not just the immediate one. plugin.js itself has
78
+ // no extension marker (it stays "plugin.js", not "plugin.mjs":
79
79
  // resolveBuiltManifestPath's path is fixed), so without a package.json
80
80
  // right here, format detection keeps walking past this outDir to
81
81
  // whatever package.json happens to sit above wherever the package gets
82
- // extracted on a real server — usually none, which makes Node default to
82
+ // extracted on a real server: usually none, which makes Node default to
83
83
  // CommonJS and fail parsing this ESM bundle with "Unexpected token
84
84
  // 'export'". A package.json written into THIS SAME directory always
85
85
  // wins (nearest match beats any ancestor), so the package is
86
86
  // self-describing no matter where it's extracted. vitest's module runner
87
87
  // (vite-node) always executes as ESM regardless of this marker, so the
88
- // in-repo test suite alone can never catch its absence — only a plain
88
+ // in-repo test suite alone can never catch its absence; only a plain
89
89
  // Node child-process import (see bundle-server-manifest.test.ts) exposes
90
90
  // the production failure this fixes.
91
91
  writeFileSync(join(absoluteOutDir, "package.json"), '{"type":"module"}\n');
@@ -0,0 +1,5 @@
1
+ import type { CheckResult } from "../types.js";
2
+ export declare const FEDERATION_DECLARATIONS_CHECK_NAME = "federation type declarations off";
3
+ export type FederationDts = "off" | "on" | "unreadable" | "no-call";
4
+ export declare function findFederationDts(source: string): FederationDts;
5
+ export declare function checkFederationDeclarations(pluginDir: string): CheckResult;