@kardalum/plugin-sdk 0.15.0 → 0.16.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 (101) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +10 -0
  3. package/dist/built-in-value-schemas.js +1 -1
  4. package/dist/built-ins.js +2 -2
  5. package/dist/capabilities.d.ts +8 -78
  6. package/dist/capabilities.js +23 -319
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.js +5 -4
  9. package/dist/license-verdict-keys.js +4 -0
  10. package/dist/manifest-entry.d.ts +2 -2
  11. package/dist/manifest-entry.js +1 -1
  12. package/dist/manifest-schema.d.ts +81 -13
  13. package/dist/manifest-schema.js +108 -59
  14. package/dist/manifest.d.ts +105 -40
  15. package/dist/media/media-picker.js +21 -12
  16. package/dist/media/upload-error.d.ts +1 -1
  17. package/dist/media/upload-error.js +1 -1
  18. package/dist/plugin-context.d.ts +7 -0
  19. package/dist/plugin-context.js +7 -0
  20. package/dist/plugin-screen-context.d.ts +33 -2
  21. package/dist/plugin-screen-context.js +27 -2
  22. package/dist/read-all-pages.d.ts +23 -0
  23. package/dist/read-all-pages.js +30 -0
  24. package/dist/richtext/block-panel.js +4 -4
  25. package/dist/richtext/insert-menu.js +3 -3
  26. package/dist/views/content-list-view.js +2 -2
  27. package/dist/views/image-view.js +24 -39
  28. package/dist/views/rich-text-view.js +2 -2
  29. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +12 -0
  30. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +19 -0
  31. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +43 -25
  32. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +60 -8
  33. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +1 -1
  34. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +5 -0
  35. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +12 -8
  36. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +1 -1
  37. package/node_modules/@kardalum/api-schemas/dist/content-path.js +11 -7
  38. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
  39. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +107 -57
  40. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +96 -60
  41. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +1 -0
  42. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +2 -0
  43. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +1 -1
  44. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +39 -28
  45. package/node_modules/@kardalum/api-schemas/dist/index.js +19 -13
  46. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
  47. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
  48. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +302 -1
  49. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +78 -6
  50. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +10 -0
  51. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +38 -30
  52. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +2 -2
  53. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +1 -1
  54. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +82 -2
  55. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +4 -0
  56. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +88 -5
  57. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +79 -17
  58. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
  59. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
  60. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +585 -0
  61. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +536 -0
  62. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +75 -0
  63. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +213 -0
  64. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +25 -3
  65. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +21 -1
  66. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +7 -0
  67. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +16 -3
  68. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +44 -0
  69. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +162 -0
  70. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +8 -0
  71. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +11 -1
  72. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
  73. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +6 -0
  74. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +6 -0
  75. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +35 -0
  76. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +79 -0
  77. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +36 -6
  78. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -5
  79. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +8 -8
  80. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +8 -8
  81. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +4 -0
  82. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +2 -0
  83. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +4 -4
  84. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +11 -3
  85. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +5 -0
  86. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +111 -0
  87. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +61 -0
  88. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
  89. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +351 -0
  90. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +3 -1
  91. package/node_modules/@kardalum/plugin-package/dist/index.js +2 -1
  92. package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +2 -0
  93. package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +6 -0
  94. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +20 -1
  95. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +56 -16
  96. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +4 -6
  97. package/node_modules/@kardalum/plugin-package/dist/types.js +15 -1
  98. package/node_modules/@kardalum/plugin-package/package.json +5 -0
  99. package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
  100. package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
  101. package/package.json +2 -2
@@ -1,7 +1,15 @@
1
1
  import type { ComponentType } from "react";
2
2
  import type { JSONSchema7 } from "json-schema";
3
3
  import { z } from "zod";
4
- import type { HookHandler, PluginAssertions, PluginContributions, PluginManifest } from "./manifest.js";
4
+ import { API_ROUTE_METHODS } from "@kardalum/api-schemas";
5
+ import type { DatabaseDialect, HookHandler, PluginAssertions, PluginContributions, PluginManifest } from "./manifest.js";
6
+ export declare const DATABASE_DIALECTS: readonly ["postgresql", "mysql", "sqlite", "mssql", "mongodb"];
7
+ export declare const STORAGE_TYPES: readonly ["simple", "structured"];
8
+ export { API_ROUTE_METHODS };
9
+ export declare const API_ROUTE_ACCESS_TIERS: readonly ["admin", "apiKey", "public"];
10
+ export declare const TEMPLATE_KINDS: readonly ["page", "layout", "partial"];
11
+ export declare const PLUGIN_TYPES: readonly ["datatype", "section", "template", "theme", "integration", "utility", "bundle"];
12
+ export declare const DATATYPE_ENTRY_TYPES: readonly ["datatype"];
5
13
  export declare const AssertionsSchema: z.ZodObject<{
6
14
  externalNetwork: z.ZodOptional<z.ZodObject<{
7
15
  reason: z.ZodString;
@@ -22,6 +30,7 @@ export declare const AssertionsSchema: z.ZodObject<{
22
30
  * schema gives the mirror something to be pinned against.
23
31
  */
24
32
  export declare const ASSERTION_KINDS: (keyof PluginAssertions)[];
33
+ export declare const HOOK_EVENTS: readonly ["content:beforeSave", "content:afterSave", "content:beforePublish", "content:afterPublish", "content:afterTrash", "content:afterRestore", "content:beforeDelete", "media:afterUpload", "user:afterLogin", "api:beforeResponse"];
25
34
  export declare const DataTypePluginSchema: z.ZodObject<{
26
35
  id: z.ZodString;
27
36
  name: z.ZodString;
@@ -115,8 +124,8 @@ export declare const CMSPluginSchema: z.ZodObject<{
115
124
  id: z.ZodString;
116
125
  section: z.ZodEnum<{
117
126
  media: "media";
118
- settings: "settings";
119
127
  content: "content";
128
+ settings: "settings";
120
129
  users: "users";
121
130
  }>;
122
131
  label: z.ZodObject<{
@@ -151,6 +160,7 @@ export declare const CMSPluginSchema: z.ZodObject<{
151
160
  body: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
152
161
  querystring: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
153
162
  params: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
163
+ response: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
154
164
  }, z.core.$strict>>;
155
165
  handler: z.ZodCustom<(request: unknown, reply: unknown, context: import("./structured-storage-types.js").PluginApiRouteContext) => unknown, (request: unknown, reply: unknown, context: import("./structured-storage-types.js").PluginApiRouteContext) => unknown>;
156
166
  }, z.core.$strict>>>;
@@ -322,8 +332,8 @@ export declare const CMSPluginSchema: z.ZodObject<{
322
332
  pluginDependencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
323
333
  databaseCompatibility: z.ZodObject<{
324
334
  storageType: z.ZodEnum<{
325
- structured: "structured";
326
335
  simple: "simple";
336
+ structured: "structured";
327
337
  }>;
328
338
  supported: z.ZodArray<z.ZodEnum<{
329
339
  postgresql: "postgresql";
@@ -354,20 +364,16 @@ export declare const CMSPluginSchema: z.ZodObject<{
354
364
  up: z.ZodCustom<(ctx: import("./manifest.js").PluginMigrationContext) => void | Promise<void>, (ctx: import("./manifest.js").PluginMigrationContext) => void | Promise<void>>;
355
365
  down: z.ZodCustom<(ctx: import("./manifest.js").PluginMigrationContext) => void | Promise<void>, (ctx: import("./manifest.js").PluginMigrationContext) => void | Promise<void>>;
356
366
  }, z.core.$strict>>>;
357
- onInstall: z.ZodOptional<z.ZodCustom<() => void | Promise<void>, () => void | Promise<void>>>;
367
+ onInstall: z.ZodOptional<z.ZodCustom<(ctx: import("./manifest.js").PluginInstallContext) => void | Promise<void>, (ctx: import("./manifest.js").PluginInstallContext) => void | Promise<void>>>;
358
368
  onUninstall: z.ZodOptional<z.ZodCustom<() => void | Promise<void>, () => void | Promise<void>>>;
359
369
  onActivate: z.ZodOptional<z.ZodCustom<() => void | Promise<void>, () => void | Promise<void>>>;
360
370
  onDeactivate: z.ZodOptional<z.ZodCustom<() => void | Promise<void>, () => void | Promise<void>>>;
361
- onUpdate: z.ZodOptional<z.ZodCustom<(ctx: {
362
- fromVersion: string;
363
- }) => void | Promise<void>, (ctx: {
364
- fromVersion: string;
365
- }) => void | Promise<void>>>;
371
+ onUpdate: z.ZodOptional<z.ZodCustom<(ctx: import("./manifest.js").PluginUpdateContext) => void | Promise<void>, (ctx: import("./manifest.js").PluginUpdateContext) => void | Promise<void>>>;
366
372
  migrationHooks: z.ZodOptional<z.ZodObject<{
367
- beforeMigration: z.ZodOptional<z.ZodCustom<(from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => void | Promise<void>, (from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => void | Promise<void>>>;
368
- transformRow: z.ZodOptional<z.ZodCustom<(table: string, row: Record<string, unknown>, from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => Record<string, unknown> | Promise<Record<string, unknown>>, (table: string, row: Record<string, unknown>, from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => Record<string, unknown> | Promise<Record<string, unknown>>>>;
369
- afterMigration: z.ZodOptional<z.ZodCustom<(from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => void | Promise<void>, (from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => void | Promise<void>>>;
370
- validateMigration: z.ZodOptional<z.ZodCustom<(from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => import("./manifest.js").PluginMigrationValidation | Promise<import("./manifest.js").PluginMigrationValidation>, (from: import("./manifest.js").DatabaseDialect, to: import("./manifest.js").DatabaseDialect) => import("./manifest.js").PluginMigrationValidation | Promise<import("./manifest.js").PluginMigrationValidation>>>;
373
+ beforeMigration: z.ZodOptional<z.ZodCustom<(from: DatabaseDialect, to: DatabaseDialect) => void | Promise<void>, (from: DatabaseDialect, to: DatabaseDialect) => void | Promise<void>>>;
374
+ transformRow: z.ZodOptional<z.ZodCustom<(table: string, row: Record<string, unknown>, from: DatabaseDialect, to: DatabaseDialect) => Record<string, unknown> | Promise<Record<string, unknown>>, (table: string, row: Record<string, unknown>, from: DatabaseDialect, to: DatabaseDialect) => Record<string, unknown> | Promise<Record<string, unknown>>>>;
375
+ afterMigration: z.ZodOptional<z.ZodCustom<(from: DatabaseDialect, to: DatabaseDialect) => void | Promise<void>, (from: DatabaseDialect, to: DatabaseDialect) => void | Promise<void>>>;
376
+ validateMigration: z.ZodOptional<z.ZodCustom<(from: DatabaseDialect, to: DatabaseDialect) => import("./manifest.js").PluginMigrationValidation | Promise<import("./manifest.js").PluginMigrationValidation>, (from: DatabaseDialect, to: DatabaseDialect) => import("./manifest.js").PluginMigrationValidation | Promise<import("./manifest.js").PluginMigrationValidation>>>;
371
377
  }, z.core.$strict>>;
372
378
  actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
373
379
  id: z.ZodString;
@@ -389,6 +395,68 @@ export declare const CMSPluginSchema: z.ZodObject<{
389
395
  path: z.ZodString;
390
396
  title: z.ZodString;
391
397
  }, z.core.$strict>>>;
398
+ docsLanguage: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodString>>;
399
+ install: z.ZodOptional<z.ZodObject<{
400
+ steps: z.ZodArray<z.ZodObject<{
401
+ id: z.ZodString;
402
+ label: z.ZodPreprocess<z.ZodObject<{
403
+ en: z.ZodString;
404
+ }, z.core.$catchall<z.ZodString>>>;
405
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
406
+ en: z.ZodString;
407
+ }, z.core.$catchall<z.ZodString>>>>;
408
+ options: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
409
+ kind: z.ZodLiteral<"boolean">;
410
+ default: z.ZodBoolean;
411
+ id: z.ZodString;
412
+ label: z.ZodPreprocess<z.ZodObject<{
413
+ en: z.ZodString;
414
+ }, z.core.$catchall<z.ZodString>>>;
415
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
416
+ en: z.ZodString;
417
+ }, z.core.$catchall<z.ZodString>>>>;
418
+ }, z.core.$strict>, z.ZodObject<{
419
+ kind: z.ZodLiteral<"select">;
420
+ choices: z.ZodArray<z.ZodObject<{
421
+ id: z.ZodString;
422
+ label: z.ZodPreprocess<z.ZodObject<{
423
+ en: z.ZodString;
424
+ }, z.core.$catchall<z.ZodString>>>;
425
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
426
+ en: z.ZodString;
427
+ }, z.core.$catchall<z.ZodString>>>>;
428
+ }, z.core.$strict>>;
429
+ default: z.ZodOptional<z.ZodString>;
430
+ required: z.ZodOptional<z.ZodBoolean>;
431
+ id: z.ZodString;
432
+ label: z.ZodPreprocess<z.ZodObject<{
433
+ en: z.ZodString;
434
+ }, z.core.$catchall<z.ZodString>>>;
435
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
436
+ en: z.ZodString;
437
+ }, z.core.$catchall<z.ZodString>>>>;
438
+ }, z.core.$strict>, z.ZodObject<{
439
+ kind: z.ZodLiteral<"multiSelect">;
440
+ choices: z.ZodArray<z.ZodObject<{
441
+ id: z.ZodString;
442
+ label: z.ZodPreprocess<z.ZodObject<{
443
+ en: z.ZodString;
444
+ }, z.core.$catchall<z.ZodString>>>;
445
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
446
+ en: z.ZodString;
447
+ }, z.core.$catchall<z.ZodString>>>>;
448
+ }, z.core.$strict>>;
449
+ default: z.ZodArray<z.ZodString>;
450
+ id: z.ZodString;
451
+ label: z.ZodPreprocess<z.ZodObject<{
452
+ en: z.ZodString;
453
+ }, z.core.$catchall<z.ZodString>>>;
454
+ description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
455
+ en: z.ZodString;
456
+ }, z.core.$catchall<z.ZodString>>>>;
457
+ }, z.core.$strict>], "kind">>;
458
+ }, z.core.$strict>>;
459
+ }, z.core.$strict>>;
392
460
  }, z.core.$strict>;
393
461
  export declare function formatIssues(issues: z.core.$ZodIssue[]): string[];
394
462
  export type ValidatePluginManifestResult = {
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ACTION_SEGMENT_MAX, ActionStringSchema, CultureSchema, MANIFEST_ID_SEGMENT_MAX, PLUGIN_ID_REGEX, SLOT_ID_MAX, SLOT_ID_REGEX, PluginDocsPageSchema, checkDocsDeclaration, CreateDocumentTypeRequestSchema, PluginActionDeclarationSchema, PluginRoleOfferSchema, checkActionDeclarations as checkActionDeclarationsRule, isPluginActionFor } from "@kardalum/api-schemas";
2
+ import { ACTION_SEGMENT_MAX, API_ROUTE_METHODS, API_ROUTE_RESPONSE_STATUSES_MAX, isApiRouteResponseStatus, ActionStringSchema, CultureSchema, DocsLanguageSchema, MANIFEST_ID_SEGMENT_MAX, PLUGIN_ID_REGEX, SLOT_ID_MAX, SLOT_ID_REGEX, PluginDocsPageSchema, PluginInstallDeclarationSchema, checkApiRouteActions, checkApiRouteDeclarations, checkDocsDeclaration, checkInstallDeclaration, CreateDocumentTypeRequestSchema, PluginActionDeclarationSchema, PluginRoleOfferSchema, checkActionDeclarations as checkActionDeclarationsRule, isPluginActionFor } from "@kardalum/api-schemas";
3
3
  import { isActionGated } from "./capabilities.js";
4
4
  // Runtime mirror of manifest.ts — the same contract, enforced for
5
5
  // manifests that arrive as VALUES (Module Federation remotes, sideloaded
@@ -25,10 +25,11 @@ const componentSchema = z.custom((value) => typeof value === "function" || (type
25
25
  // A JSON Schema document is a plain object (DataTypePlugin.schema is the
26
26
  // JSONSchema7 object interface, not the boolean shorthand).
27
27
  const jsonSchemaSchema = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value), { message: "must be a JSON Schema object" });
28
- // A plugin-declared request schema must be a REAL Zod schema instance
29
- // (z.object(...), z.string(), etc. — every Zod schema extends the base
30
- // ZodType class), not just an object that looks like one — plugin-api-
31
- // routes.ts calls .safeParse() on it directly at request time.
28
+ // A plugin-declared request schema must be a REAL Zod v4 schema instance
29
+ // (z.object(...), z.string() and the rest: every Zod schema extends the base
30
+ // ZodType class), not just an object that looks like one. The server compiles
31
+ // it with its validator compiler (fastify-type-provider-zod), which runs it
32
+ // through Zod's core safeParse, and that needs a real v4 instance.
32
33
  const zodSchemaField = z.instanceof(z.ZodType);
33
34
  // Reverse-domain id per the documented contract, e.g. "com.vendor.name".
34
35
  // Shared by manifest ids, datatype ids and plugin references, so it carries
@@ -60,7 +61,7 @@ const manifestIdSchema = pluginIdSchema.refine((id) => id.split(".").length <= M
60
61
  // depends on (an upload of an extension nothing else claims lands on it,
61
62
  // or 400s if there is none). A plugin's install path calls
62
63
  // DocumentTypeService.createDocumentType directly, bypassing the sweep
63
- // that the /api/document-types routes use to keep the flag a singleton,
64
+ // that the /api/manage/v1/document-types routes use to keep the flag a singleton,
64
65
  // and uninstalling a plugin deletes every document type it contributed.
65
66
  // A plugin allowed to hold the catch-all could therefore take it to zero
66
67
  // on uninstall, so it is refused here, at the one schema every
@@ -84,10 +85,22 @@ const manifestDocumentTypesSchema = z
84
85
  }
85
86
  });
86
87
  });
87
- const dialectSchema = z.enum(["postgresql", "mysql", "sqlite", "mssql", "mongodb"]);
88
+ // S289: each enum the manual quotes is an exported constant the schema
89
+ // itself uses, so the manual's enum test checks against what is enforced,
90
+ // never a copy (manual-enum-examples.test.ts).
91
+ export const DATABASE_DIALECTS = ["postgresql", "mysql", "sqlite", "mssql", "mongodb"];
92
+ export const STORAGE_TYPES = ["simple", "structured"];
93
+ // S295: api-schemas' list, the one the apiRoutes rule compares, re-exported so
94
+ // the enum below and the manual's enum test read that same constant.
95
+ export { API_ROUTE_METHODS };
96
+ export const API_ROUTE_ACCESS_TIERS = ["admin", "apiKey", "public"];
97
+ export const TEMPLATE_KINDS = ["page", "layout", "partial"];
98
+ export const PLUGIN_TYPES = ["datatype", "section", "template", "theme", "integration", "utility", "bundle"];
99
+ export const DATATYPE_ENTRY_TYPES = ["datatype"];
100
+ const dialectSchema = z.enum(DATABASE_DIALECTS);
88
101
  const databaseCompatibilitySchema = z
89
102
  .object({
90
- storageType: z.enum(["simple", "structured"]),
103
+ storageType: z.enum(STORAGE_TYPES),
91
104
  // A plugin supporting zero databases can never be installed anywhere.
92
105
  supported: z.array(dialectSchema).min(1),
93
106
  unsupportedReason: z.partialRecord(dialectSchema, z.string()).optional(),
@@ -148,7 +161,7 @@ const migrationHooksSchema = z
148
161
  validateMigration: callable("validateMigration").optional(),
149
162
  })
150
163
  .strict();
151
- const HOOK_EVENTS = [
164
+ export const HOOK_EVENTS = [
152
165
  "content:beforeSave",
153
166
  "content:afterSave",
154
167
  "content:beforePublish",
@@ -160,6 +173,12 @@ const HOOK_EVENTS = [
160
173
  "user:afterLogin",
161
174
  "api:beforeResponse",
162
175
  ];
176
+ const hookEventsMatch = true;
177
+ const pluginTypesMatch = true;
178
+ const dialectsMatch = true;
179
+ void hookEventsMatch;
180
+ void pluginTypesMatch;
181
+ void dialectsMatch;
163
182
  // z.partialRecord, not z.record: with enum keys, Zod 4's record is
164
183
  // exhaustive (it would demand a handler for all ten events).
165
184
  const hooksSchema = z.partialRecord(z.enum(HOOK_EVENTS), callable("hook handler"));
@@ -172,7 +191,7 @@ export const DataTypePluginSchema = z
172
191
  name: z.string().min(1),
173
192
  icon: z.string().min(1),
174
193
  version: z.string().min(1),
175
- type: z.literal("datatype"),
194
+ type: z.literal(DATATYPE_ENTRY_TYPES[0]),
176
195
  schema: jsonSchemaSchema,
177
196
  settingsSchema: jsonSchemaSchema,
178
197
  defaultSettings: z.record(z.string(), z.unknown()),
@@ -214,13 +233,15 @@ const slotIdSchema = z
214
233
  .max(SLOT_ID_MAX, `slot ids are at most ${SLOT_ID_MAX} characters, because the id is a segment of the screen's URL`);
215
234
  // A language code to the text shown in that language; `en` is required
216
235
  // because it is what every other language falls back to. No language may
217
- // carry an empty string, which would render a blank tab. Every key is a
218
- // language code under the same rule as the site's cultures setting
236
+ // carry an empty string or whitespace alone, which would render a blank tab
237
+ // (and a blank English label is one the generated reference refuses). Every
238
+ // key is a language code under the same rule as the site's cultures setting
219
239
  // (CultureSchema), so "" or "anything" is refused rather than carried as a
220
240
  // language no locale can ever pick.
241
+ const slotLabelTextSchema = z.string().refine((text) => text.trim() !== "", { message: "must not be empty" });
221
242
  const slotLabelSchema = z
222
- .object({ en: z.string().min(1) })
223
- .catchall(z.string().min(1))
243
+ .object({ en: slotLabelTextSchema })
244
+ .catchall(slotLabelTextSchema)
224
245
  .superRefine((label, ctx) => {
225
246
  for (const key of Object.keys(label)) {
226
247
  if (!CultureSchema.safeParse(key).success) {
@@ -285,17 +306,38 @@ const dashboardWidgetSchema = z
285
306
  action: ActionStringSchema,
286
307
  })
287
308
  .strict();
309
+ // S297: a route's declared success responses. The keys are decided by the rule
310
+ // the host's route table compiles with (isApiRouteResponseStatus), so the two
311
+ // cannot disagree; the values are real Zod schemas like the request parts.
312
+ const apiRouteResponseSchema = z.record(z.string(), zodSchemaField).superRefine((value, ctx) => {
313
+ const keys = Object.keys(value);
314
+ if (keys.length > API_ROUTE_RESPONSE_STATUSES_MAX) {
315
+ ctx.addIssue({
316
+ code: "custom",
317
+ message: `declares ${keys.length} responses; at most ${API_ROUTE_RESPONSE_STATUSES_MAX} are allowed`,
318
+ });
319
+ }
320
+ for (const key of keys) {
321
+ if (!isApiRouteResponseStatus(key)) {
322
+ ctx.addIssue({ code: "custom", message: `"${key}" is not a success status: use a status code from "200" to "299"`, path: [key] });
323
+ }
324
+ }
325
+ });
288
326
  const apiRouteSchema = z
289
327
  .object({
290
- method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
291
- path: z.string().min(1).refine((p) => p.startsWith("/"), { message: 'path must start with "/"' }),
292
- access: z.enum(["admin", "apiKey", "public"]).optional(),
328
+ method: z.enum(API_ROUTE_METHODS),
329
+ // S295: the path's syntax and its relation to the plugin's other routes are
330
+ // api-schemas' checkApiRouteDeclarations, run once on the whole manifest
331
+ // below, so a bad path is reported once and in the words the door uses.
332
+ path: z.string(),
333
+ access: z.enum(API_ROUTE_ACCESS_TIERS).optional(),
293
334
  action: ActionStringSchema.optional(),
294
335
  schema: z
295
336
  .object({
296
337
  body: zodSchemaField.optional(),
297
338
  querystring: zodSchemaField.optional(),
298
339
  params: zodSchemaField.optional(),
340
+ response: apiRouteResponseSchema.optional(),
299
341
  })
300
342
  .strict()
301
343
  .optional(),
@@ -488,7 +530,7 @@ const templateEntrySchema = z
488
530
  file: templateFileSchema,
489
531
  name: z.string().min(1),
490
532
  alias: templateAliasSchema,
491
- kind: z.enum(["page", "layout", "partial"]),
533
+ kind: z.enum(TEMPLATE_KINDS),
492
534
  documentType: z.string().min(1).optional(),
493
535
  })
494
536
  .strict();
@@ -547,24 +589,6 @@ function checkTemplateAndAssetContributions(value, ctx) {
547
589
  seenAssets.add(asset);
548
590
  });
549
591
  }
550
- // Two apiRoutes entries sharing a (method, path) pair within one manifest
551
- // would silently last-wins in plugin-api-routes.ts's dispatcher: a
552
- // validation error, not a runtime surprise, same reasoning as
553
- // document-type-api.schema.ts's duplicate-field-id check.
554
- function checkApiRouteContributions(value, ctx) {
555
- const seen = new Set();
556
- (value.apiRoutes ?? []).forEach((route, index) => {
557
- const key = `${route.method} ${route.path}`;
558
- if (seen.has(key)) {
559
- ctx.addIssue({
560
- code: "custom",
561
- message: `Duplicate apiRoute "${key}": method+path pairs must be unique within a manifest`,
562
- path: ["apiRoutes", index],
563
- });
564
- }
565
- seen.add(key);
566
- });
567
- }
568
592
  // A slot's id is the last segment of its URL (spec D3), so it must be unique
569
593
  // where its URL would collide: among this plugin's sections, within one
570
594
  // section's rail, and among this plugin's built-in rail entries. Across those
@@ -591,10 +615,11 @@ function checkSlotContributions(value, ctx) {
591
615
  sections.forEach((section, index) => unique(section.rail ?? [], ["adminSections", index, "rail"], "rail entry"));
592
616
  unique(value.railEntries ?? [], ["railEntries"], "built-in rail entry");
593
617
  }
594
- // Every action a plugin declares must sit in that plugin's own namespace
595
- // (its full reverse-domain id plus a dot), so one plugin cannot declare an
596
- // action in another plugin's namespace or in core's. An admin-tier apiRoute
597
- // must declare one; a public route needs no credential and so no action.
618
+ // Every action a plugin declares must sit in that plugin's own namespace (its
619
+ // full reverse-domain id plus a dot), so one plugin cannot declare an action in
620
+ // another plugin's namespace or in core's. Whether an apiRoute must declare one
621
+ // at all is api-schemas' checkApiRouteActions, the one rule the marketplace
622
+ // door runs too.
598
623
  function checkActionContributions(value, ctx) {
599
624
  const contributions = value.contributions;
600
625
  // A section's own rail entries are gated too (S280). They are not a
@@ -616,15 +641,9 @@ function checkActionContributions(value, ctx) {
616
641
  for (const key of CONTRIBUTION_KEYS.filter(isActionGated)) {
617
642
  (contributions[key] ?? []).forEach((entry, index) => {
618
643
  if (entry.action === undefined) {
619
- if (key === "apiRoutes" && entry.access !== undefined && entry.access !== "admin")
620
- return;
621
- if (key === "apiRoutes") {
622
- ctx.addIssue({
623
- code: "custom",
624
- message: 'an admin-tier apiRoute must declare an "action" (only a "public" or "apiKey" route may omit it)',
625
- path: ["contributions", key, index, "action"],
626
- });
627
- }
644
+ // Whether an apiRoute may omit its action is checkApiRouteActions' to
645
+ // say (only a public route may), run once on the whole manifest below;
646
+ // every other gated kind requires its action through its own schema.
628
647
  return;
629
648
  }
630
649
  if (!isPluginActionFor(entry.action, value.id)) {
@@ -679,7 +698,6 @@ const contributionsShape = {
679
698
  const contributionsSchema = z
680
699
  .object(contributionsShape)
681
700
  .strict()
682
- .superRefine(checkApiRouteContributions)
683
701
  .superRefine(checkTemplateAndAssetContributions)
684
702
  .superRefine(checkSlotContributions);
685
703
  /**
@@ -725,16 +743,18 @@ const baseFields = {
725
743
  actions: z.array(PluginActionDeclarationSchema).optional(),
726
744
  roles: z.array(PluginRoleOfferSchema).optional(),
727
745
  docs: z.array(PluginDocsPageSchema).optional(),
746
+ // S291: the docs pages' language, a code under the same rule as a slot
747
+ // label's keys (CultureSchema), so "German" is refused rather than shown,
748
+ // and at most 35 characters: DocsLanguageSchema is the one rule the
749
+ // marketplace's check and its stored languages apply too.
750
+ docsLanguage: DocsLanguageSchema.optional(),
751
+ // S292: what the install asks. The shape is api-schemas'
752
+ // PluginInstallDeclarationSchema; the rule over it (caps, distinct ids,
753
+ // defaults among the choices) runs below through checkInstallDeclaration,
754
+ // the function `kardalum plugin validate` and the marketplace door run.
755
+ install: PluginInstallDeclarationSchema.optional(),
728
756
  };
729
- const pluginTypeSchema = z.enum([
730
- "datatype",
731
- "section",
732
- "template",
733
- "theme",
734
- "integration",
735
- "utility",
736
- "bundle",
737
- ]);
757
+ const pluginTypeSchema = z.enum(PLUGIN_TYPES);
738
758
  // One manifest, no union (S268). `type` is a marketplace listing label
739
759
  // that parses as one of seven values and gates nothing; what a plugin may
740
760
  // do is decided by the capability list derived from `contributions` and by
@@ -745,10 +765,39 @@ export const CMSPluginSchema = z
745
765
  .strict()
746
766
  .superRefine(checkActionContributions)
747
767
  .superRefine(checkActionDeclarations)
768
+ // S295 (2026-10-14-s295-routes-fastify-knows-about-design.md 3.1): the rule
769
+ // `kardalum plugin validate` and the marketplace door run too, rooted at the
770
+ // manifest.
771
+ .superRefine((value, ctx) => {
772
+ for (const issue of checkApiRouteDeclarations(value)) {
773
+ ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
774
+ }
775
+ })
776
+ // S299 (2026-10-15-s299-tokens-that-carry-actions-design.md D15): an admin-tier
777
+ // or apiKey-tier apiRoute names its action; the marketplace door runs the same
778
+ // function on manifest.json.
779
+ .superRefine((value, ctx) => {
780
+ for (const issue of checkApiRouteActions(value)) {
781
+ ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
782
+ }
783
+ })
748
784
  .superRefine((value, ctx) => {
749
785
  for (const issue of checkDocsDeclaration(value.docs ?? [])) {
750
786
  ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
751
787
  }
788
+ })
789
+ .superRefine((value, ctx) => {
790
+ if (!value.install)
791
+ return;
792
+ // The rule reads only a declaration its schema parsed. A refinement still
793
+ // runs when a field failed a check (an id the id rule refused), and the
794
+ // rule would then report that id a second time, as "used more than once".
795
+ const install = PluginInstallDeclarationSchema.safeParse(value.install);
796
+ if (!install.success)
797
+ return;
798
+ for (const issue of checkInstallDeclaration(install.data)) {
799
+ ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
800
+ }
752
801
  });
753
802
  // Shared by validatePluginManifest and definePlugin — one formatting
754
803
  // convention for every validation surface: `path: message`.