@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
@@ -4,21 +4,22 @@ import { CROP_EDITOR_ID, CropSettingsSchema, renditionName, renditionShape, THUM
4
4
  import { Button, cn, Input, PropertyField, usePropertyFieldControl } from "@kardalum/ui";
5
5
  import { MediaPicker } from "../media/media-picker.js";
6
6
  import { uploadFailureMessage } from "../media/upload-error.js";
7
- import { usePluginApi, usePluginSettings, usePluginSettingsValue, usePluginValue, } from "../plugin-context.js";
7
+ import { MANAGE_API, usePluginApi, usePluginSettings, usePluginSettingsValue, usePluginValue, } from "../plugin-context.js";
8
+ import { readAllPages } from "../read-all-pages.js";
8
9
  // downloadUrl is the stable app path for a public item (S186c §1/§3) but
9
10
  // carries a freshly minted, short-lived `?token=` for a private one —
10
- // never persisted; refetch GET /api/media/:id whenever the field's value
11
+ // never persisted; refetch GET /api/manage/v1/media/:id whenever the field's value
11
12
  // (media id) changes rather than caching one, so a private item's
12
13
  // preview always has a live token.
13
14
  //
14
- // The crop is read from GET /api/media/:id/renditions, and only when the
15
+ // The crop is read from GET /api/manage/v1/media/:id/renditions, and only when the
15
16
  // field asks for one. That listing is the renditions of the item's
16
17
  // CURRENT version with the version beside them, which is the same
17
18
  // question the renderer answers at read time, so what this view names is
18
19
  // what the page will really serve. It is a second request, deliberately:
19
20
  // the item response says nothing about crops, and naming a file the
20
21
  // picture may not have is worse than one more read on a field that has
21
- // just changed.
22
+ // just changed. The listing is paged (200 at a time), so every page is read before a miss means "none".
22
23
  function useMediaPreview(mediaId, rendition) {
23
24
  const fetchApi = usePluginApi();
24
25
  const [preview, setPreview] = useState(null);
@@ -33,7 +34,7 @@ function useMediaPreview(mediaId, rendition) {
33
34
  let cancelled = false;
34
35
  setLoading(true);
35
36
  setError(null);
36
- const item = fetchApi(`/api/media/${mediaId}`).then(async (response) => {
37
+ const item = fetchApi(`${MANAGE_API}/media/${mediaId}`).then(async (response) => {
37
38
  if (!response.ok)
38
39
  throw new Error(`Failed to load media (${response.status})`);
39
40
  return (await response.json());
@@ -47,13 +48,16 @@ function useMediaPreview(mediaId, rendition) {
47
48
  // here (see ResolvedCut).
48
49
  const cut = rendition === null
49
50
  ? Promise.resolve({ state: "unknown" })
50
- : fetchApi(`/api/media/${mediaId}/renditions`)
51
- .then(async (response) => {
52
- if (!response.ok)
53
- return { state: "unknown" };
54
- const body = (await response.json());
55
- const found = body.items.find((item) => item.name === rendition);
56
- return found ? { state: "found", name: found.name, filename: found.filename } : { state: "absent" };
51
+ : readAllPages(fetchApi, `${MANAGE_API}/media/${mediaId}/renditions`, "renditions", {
52
+ limit: 200,
53
+ cap: 50,
54
+ })
55
+ .then(({ items, complete }) => {
56
+ const found = items.find((item) => item.name === rendition);
57
+ if (found)
58
+ return { state: "found", name: found.name, filename: found.filename };
59
+ // A miss on a listing that was not read to its end says nothing about the crop: "could not ask", not "none".
60
+ return complete ? { state: "absent" } : { state: "unknown" };
57
61
  })
58
62
  .catch(() => ({ state: "unknown" }));
59
63
  Promise.all([item, cut])
@@ -163,7 +167,7 @@ export function ImageInputView() {
163
167
  try {
164
168
  const formData = new FormData();
165
169
  formData.append("file", file);
166
- const response = await fetchApi("/api/media", { method: "POST", body: formData });
170
+ const response = await fetchApi(`${MANAGE_API}/media`, { method: "POST", body: formData });
167
171
  // The server's own sentence, not a status code: it may be refusing
168
172
  // these bytes for the file upload type's limit, which this field
169
173
  // knows nothing about, and that refusal names the limit and the
@@ -218,31 +222,12 @@ const TYPE_PAGE_LIMIT = 100;
218
222
  const TYPE_PAGE_CAP = 20;
219
223
  const SELECT_CLASS = "h-10 w-full rounded-md border border-border-strong bg-background-elevated px-2 text-sm text-text-primary " +
220
224
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600";
221
- /** Every page of a cursor-paginated listing, up to the cap above. Both
222
- * listings are small, admin-only and read once when this view mounts.
225
+ /** A listing read to its end, or as far as the cap allowed.
223
226
  *
224
- * One function for both because both answer in the same shape:
225
- * DocumentTypeListResponseSchema and DataTypeListResponseSchema are each
226
- * `{ items, nextCursor }` over the same `{ cursor, limit }` query. */
227
- async function readAllPages(fetchApi, path, what) {
228
- const all = [];
229
- let cursor = null;
230
- for (let page = 0; page < TYPE_PAGE_CAP; page += 1) {
231
- const params = new URLSearchParams();
232
- params.set("limit", String(TYPE_PAGE_LIMIT));
233
- if (cursor)
234
- params.set("cursor", cursor);
235
- const response = await fetchApi(`${path}?${params.toString()}`);
236
- if (!response.ok)
237
- throw new Error(`Failed to load ${what} (${response.status})`);
238
- const body = (await response.json());
239
- all.push(...body.items);
240
- cursor = body.nextCursor;
241
- if (cursor === null)
242
- return { items: all, complete: true };
243
- }
244
- return { items: all, complete: false };
245
- }
227
+ * `complete` is false when the cursor was still running when the cap was
228
+ * reached. The rows in hand are real either way; what a short list cannot
229
+ * support is a statement about what is NOT in it, which is the one thing
230
+ * this view says about a stored crop it did not find. */
246
231
  /** The rendition name a data type produces, or null when it is not a
247
232
  * rendition editor at all or its settings do not parse.
248
233
  *
@@ -301,8 +286,8 @@ function useRenditionChoices() {
301
286
  setError(null);
302
287
  setComplete(true);
303
288
  Promise.all([
304
- readAllPages(fetchApi, "/api/document-types", "document types"),
305
- readAllPages(fetchApi, "/api/data-types", "data types"),
289
+ readAllPages(fetchApi, `${MANAGE_API}/document-types`, "document types", { limit: TYPE_PAGE_LIMIT, cap: TYPE_PAGE_CAP }),
290
+ readAllPages(fetchApi, `${MANAGE_API}/data-types`, "data types", { limit: TYPE_PAGE_LIMIT, cap: TYPE_PAGE_CAP }),
306
291
  ])
307
292
  .then(([documentTypes, dataTypes]) => {
308
293
  if (cancelled)
@@ -4,7 +4,7 @@ import { EditorContent, useEditor } from "@tiptap/react";
4
4
  import { NodeSelection } from "@tiptap/pm/state";
5
5
  import { Code2, Image as ImageIcon, Link as LinkIcon, List as ListIcon, Quote as QuoteIcon } from "lucide-react";
6
6
  import { cn, usePropertyFieldControl } from "@kardalum/ui";
7
- import { usePluginApi, usePluginValue } from "../plugin-context.js";
7
+ import { MANAGE_API, usePluginApi, usePluginValue } from "../plugin-context.js";
8
8
  import { buildRichtextExtensions } from "../richtext/extensions.js";
9
9
  import { MediaPicker } from "../media/media-picker.js";
10
10
  import { BlockInsertMenu, defaultBlockParams } from "../richtext/insert-menu.js";
@@ -48,7 +48,7 @@ function useTextStyles() {
48
48
  useEffect(() => {
49
49
  let cancelled = false;
50
50
  setLoading(true);
51
- fetchApi("/api/render/text-styles")
51
+ fetchApi(`${MANAGE_API}/render/text-styles`)
52
52
  .then(async (response) => {
53
53
  // The endpoint doesn't exist yet (a later task ships it) — a 404,
54
54
  // any other error status, and a genuinely empty declared list all
@@ -3,3 +3,15 @@ export declare const ApiErrorSchema: z.ZodObject<{
3
3
  message: z.ZodString;
4
4
  }, z.core.$strip>;
5
5
  export type ApiError = z.infer<typeof ApiErrorSchema>;
6
+ export declare const BodyTooLargeErrorSchema: z.ZodObject<{
7
+ statusCode: z.ZodLiteral<413>;
8
+ code: z.ZodLiteral<"FST_ERR_CTP_BODY_TOO_LARGE">;
9
+ error: z.ZodString;
10
+ message: z.ZodString;
11
+ }, z.core.$strip>;
12
+ export type BodyTooLargeError = z.infer<typeof BodyTooLargeErrorSchema>;
13
+ export declare const RateLimitErrorSchema: z.ZodObject<{
14
+ statusCode: z.ZodLiteral<429>;
15
+ message: z.ZodString;
16
+ }, z.core.$strip>;
17
+ export type RateLimitError = z.infer<typeof RateLimitErrorSchema>;
@@ -4,3 +4,22 @@ import { z } from "zod";
4
4
  export const ApiErrorSchema = z.object({
5
5
  message: z.string(),
6
6
  });
7
+ // S297: the two answers the host gives every plugin route besides its own
8
+ // error shape, documented in the plugin operations
9
+ // (apps/server/src/docs/plugin-routes-openapi.ts) and never part of the
10
+ // dispatch routes' response map, so the real bodies are not rewritten.
11
+ // Both match what the server sends: the 413 is Fastify's own error body for a
12
+ // request past bodyLimit, the 429 is the rate limiter's errorResponseBuilder
13
+ // return (auth/rate-limit.ts), which carries no `error` field. The
14
+ // integration cases that provoke each status parse the real body with these.
15
+ export const BodyTooLargeErrorSchema = z.object({
16
+ statusCode: z.literal(413),
17
+ code: z.literal("FST_ERR_CTP_BODY_TOO_LARGE"),
18
+ // Node's STATUS_CODES text for 413, which the Node version owns.
19
+ error: z.string(),
20
+ message: z.string(),
21
+ });
22
+ export const RateLimitErrorSchema = z.object({
23
+ statusCode: z.literal(429),
24
+ message: z.string(),
25
+ });
@@ -1,19 +1,14 @@
1
1
  import { z } from "zod";
2
- export declare const ApiKeyScopeSchema: z.ZodEnum<{
3
- read: "read";
4
- write: "write";
5
- }>;
6
- export type ApiKeyScope = z.infer<typeof ApiKeyScopeSchema>;
7
2
  export declare const ApiKeySummarySchema: z.ZodObject<{
8
3
  id: z.ZodString;
9
4
  name: z.ZodString;
10
- scope: z.ZodEnum<{
11
- read: "read";
12
- write: "write";
13
- }>;
5
+ actions: z.ZodArray<z.ZodString>;
14
6
  createdAt: z.ZodString;
7
+ expiresAt: z.ZodNullable<z.ZodString>;
15
8
  lastUsedAt: z.ZodNullable<z.ZodString>;
16
9
  revokedAt: z.ZodNullable<z.ZodString>;
10
+ createdById: z.ZodNullable<z.ZodString>;
11
+ createdByName: z.ZodNullable<z.ZodString>;
17
12
  }, z.core.$strip>;
18
13
  export type ApiKeySummary = z.infer<typeof ApiKeySummarySchema>;
19
14
  export declare const ApiKeyListQuerySchema: z.ZodObject<{
@@ -25,51 +20,74 @@ export declare const ApiKeyListResponseSchema: z.ZodObject<{
25
20
  items: z.ZodArray<z.ZodObject<{
26
21
  id: z.ZodString;
27
22
  name: z.ZodString;
28
- scope: z.ZodEnum<{
29
- read: "read";
30
- write: "write";
31
- }>;
23
+ actions: z.ZodArray<z.ZodString>;
32
24
  createdAt: z.ZodString;
25
+ expiresAt: z.ZodNullable<z.ZodString>;
33
26
  lastUsedAt: z.ZodNullable<z.ZodString>;
34
27
  revokedAt: z.ZodNullable<z.ZodString>;
28
+ createdById: z.ZodNullable<z.ZodString>;
29
+ createdByName: z.ZodNullable<z.ZodString>;
35
30
  }, z.core.$strip>>;
36
31
  nextCursor: z.ZodNullable<z.ZodString>;
37
32
  }, z.core.$strip>;
38
33
  export type ApiKeyListResponse = z.infer<typeof ApiKeyListResponseSchema>;
34
+ /** The most actions one key may be created with: more than the vocabulary plus any plugin will hold. */
35
+ export declare const API_KEY_MAX_ACTIONS = 500;
39
36
  export declare const CreateApiKeyRequestSchema: z.ZodObject<{
40
37
  name: z.ZodString;
41
- scope: z.ZodDefault<z.ZodEnum<{
42
- read: "read";
43
- write: "write";
44
- }>>;
38
+ actions: z.ZodArray<z.ZodString>;
39
+ expiresAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
45
40
  }, z.core.$strip>;
46
41
  export type CreateApiKeyRequest = z.infer<typeof CreateApiKeyRequestSchema>;
47
42
  export declare const CreateApiKeyResponseSchema: z.ZodObject<{
48
43
  apiKey: z.ZodObject<{
49
44
  id: z.ZodString;
50
45
  name: z.ZodString;
51
- scope: z.ZodEnum<{
52
- read: "read";
53
- write: "write";
54
- }>;
46
+ actions: z.ZodArray<z.ZodString>;
55
47
  createdAt: z.ZodString;
48
+ expiresAt: z.ZodNullable<z.ZodString>;
56
49
  lastUsedAt: z.ZodNullable<z.ZodString>;
57
50
  revokedAt: z.ZodNullable<z.ZodString>;
51
+ createdById: z.ZodNullable<z.ZodString>;
52
+ createdByName: z.ZodNullable<z.ZodString>;
58
53
  }, z.core.$strip>;
59
54
  secret: z.ZodString;
60
55
  }, z.core.$strip>;
61
56
  export type CreateApiKeyResponse = z.infer<typeof CreateApiKeyResponseSchema>;
57
+ export declare const ApiKeyRefusalSchema: z.ZodObject<{
58
+ message: z.ZodString;
59
+ action: z.ZodString;
60
+ }, z.core.$strip>;
61
+ export type ApiKeyRefusal = z.infer<typeof ApiKeyRefusalSchema>;
62
+ export declare const ApiKeyCreateForbiddenSchema: z.ZodUnion<readonly [z.ZodObject<{
63
+ message: z.ZodString;
64
+ action: z.ZodString;
65
+ }, z.core.$strip>, z.ZodObject<{
66
+ message: z.ZodString;
67
+ }, z.core.$strip>]>;
62
68
  export declare const RevokeApiKeyResponseSchema: z.ZodObject<{
63
69
  apiKey: z.ZodObject<{
64
70
  id: z.ZodString;
65
71
  name: z.ZodString;
66
- scope: z.ZodEnum<{
67
- read: "read";
68
- write: "write";
69
- }>;
72
+ actions: z.ZodArray<z.ZodString>;
70
73
  createdAt: z.ZodString;
74
+ expiresAt: z.ZodNullable<z.ZodString>;
71
75
  lastUsedAt: z.ZodNullable<z.ZodString>;
72
76
  revokedAt: z.ZodNullable<z.ZodString>;
77
+ createdById: z.ZodNullable<z.ZodString>;
78
+ createdByName: z.ZodNullable<z.ZodString>;
73
79
  }, z.core.$strip>;
74
80
  }, z.core.$strip>;
75
81
  export type RevokeApiKeyResponse = z.infer<typeof RevokeApiKeyResponseSchema>;
82
+ export declare const API_KEY_PRESETS: readonly [{
83
+ readonly id: "read";
84
+ readonly actions: readonly ["content.read", "media.read", "documentTypes.read", "templates.read", "sites.read"];
85
+ }, {
86
+ readonly id: "readWrite";
87
+ readonly actions: readonly ["content.read", "media.read", "documentTypes.read", "templates.read", "sites.read", "content.create", "content.update", "content.publish", "content.delete", "media.create", "media.update", "media.delete"];
88
+ }];
89
+ export type ApiKeyPresetId = (typeof API_KEY_PRESETS)[number]["id"];
90
+ export declare const ApiKeyParamsSchema: z.ZodObject<{
91
+ id: z.ZodString;
92
+ }, z.core.$strip>;
93
+ export type ApiKeyParams = z.infer<typeof ApiKeyParamsSchema>;
@@ -1,16 +1,30 @@
1
1
  import { z } from "zod";
2
- // What a key is allowed to do on the public /api/v1 surface. "write"
3
- // implies read; "read" is the default so a key can never write by
4
- // accident (S182 — before it, any key could write).
5
- export const ApiKeyScopeSchema = z.enum(["read", "write"]);
6
- // What key management reads — never the keyHash, never the plaintext.
2
+ import { ActionStringSchema } from "./action.schema.js";
3
+ import { ApiErrorSchema } from "./api-error.schema.js";
4
+ // What key management reads: never the keyHash, never the plaintext.
7
5
  export const ApiKeySummarySchema = z.object({
8
6
  id: z.string().uuid(),
9
7
  name: z.string(),
10
- scope: ApiKeyScopeSchema,
8
+ // The actions the key was created with, sorted. Fixed at creation; a key made
9
+ // before S299 holds none.
10
+ actions: z.array(z.string()),
11
11
  createdAt: z.string().datetime(),
12
+ // The moment the key stops working, or null when it never expires.
13
+ expiresAt: z.string().datetime().nullable(),
12
14
  lastUsedAt: z.string().datetime().nullable(),
13
15
  revokedAt: z.string().datetime().nullable(),
16
+ // Who created it, or null when that user is gone or the key came from the ops script.
17
+ createdById: z.string().uuid().nullable(),
18
+ // The display name of the user `createdById` names, so the list can say who
19
+ // made a key instead of showing an editor a uuid. Nullable rather than
20
+ // optional, because the server always decides: null means there is no name to
21
+ // show, which covers a creator who is gone, a key the ops script made and a
22
+ // creator who never set a name (`User.name` is itself nullable).
23
+ //
24
+ // NAME ONLY, deliberately: never the email and never the role. Those live on
25
+ // GET /api/manage/v1/users, which needs users.read, and holding apiKeys.read does not
26
+ // imply it (the same rule MediaVersionSchema.createdByName follows).
27
+ createdByName: z.string().nullable(),
14
28
  });
15
29
  export const ApiKeyListQuerySchema = z.object({
16
30
  cursor: z.string().uuid().optional(),
@@ -21,16 +35,54 @@ export const ApiKeyListResponseSchema = z.object({
21
35
  // null = no more pages.
22
36
  nextCursor: z.string().uuid().nullable(),
23
37
  });
38
+ /** The most actions one key may be created with: more than the vocabulary plus any plugin will hold. */
39
+ export const API_KEY_MAX_ACTIONS = 500;
24
40
  export const CreateApiKeyRequestSchema = z.object({
25
41
  name: z.string().min(1).max(100),
26
- // Omitted = read. Write keys can create, save and publish content.
27
- scope: ApiKeyScopeSchema.default("read"),
42
+ // Chosen once: a key keeps exactly these. At least one, because a key that
43
+ // holds nothing can never be given anything.
44
+ actions: z.array(ActionStringSchema).min(1).max(API_KEY_MAX_ACTIONS),
45
+ // Optional; omitted or null means the key never expires.
46
+ expiresAt: z.string().datetime().nullable().default(null),
28
47
  });
29
48
  // The only response, anywhere, that ever carries the plaintext secret.
30
49
  export const CreateApiKeyResponseSchema = z.object({
31
50
  apiKey: ApiKeySummarySchema,
32
51
  secret: z.string(),
33
52
  });
53
+ // The 403 that creating a key answers when the creator does not hold an action
54
+ // the request names (the subset rule). `action` is the first such action, as its
55
+ // id, so a client can mark that row without reading the sentence. It has the
56
+ // shape of the node refusal (`message` plus `action`, node-access.schema.ts), and
57
+ // the admin's error class already reads `action` off any failed response.
58
+ export const ApiKeyRefusalSchema = ApiErrorSchema.extend({ action: ActionStringSchema });
59
+ // The route's whole 403: the subset refusal, or the gate's plain error (the
60
+ // creator's role no longer holds apiKeys.create). The refusal is listed first so
61
+ // it is the one a body with `action` serialises as (a plain object schema would
62
+ // strip `action`), the order ContentForbiddenSchema uses.
63
+ export const ApiKeyCreateForbiddenSchema = z.union([ApiKeyRefusalSchema, ApiErrorSchema]);
34
64
  export const RevokeApiKeyResponseSchema = z.object({
35
65
  apiKey: ApiKeySummarySchema,
36
66
  });
67
+ // S299: the two starting points the admin's key form offers, and the sets the
68
+ // old scopes reached: "read" was every GET under /api/v1 and GraphQL, "write"
69
+ // added every write route (content create, update, publish, delete; media
70
+ // upload, visibility, delete). Typed against the registered actions, so a
71
+ // mistyped string fails to compile. A preset is a convenience: a key stores the
72
+ // actions it was given, never the preset.
73
+ const READ_ACTIONS = ["content.read", "media.read", "documentTypes.read", "templates.read", "sites.read"];
74
+ const WRITE_ACTIONS = [
75
+ "content.create",
76
+ "content.update",
77
+ "content.publish",
78
+ "content.delete",
79
+ "media.create",
80
+ "media.update",
81
+ "media.delete",
82
+ ];
83
+ export const API_KEY_PRESETS = [
84
+ { id: "read", actions: READ_ACTIONS },
85
+ { id: "readWrite", actions: [...READ_ACTIONS, ...WRITE_ACTIONS] },
86
+ ];
87
+ // S301: the params of POST /api-keys/:id/revoke, moved here from the route file.
88
+ export const ApiKeyParamsSchema = z.object({ id: z.string().uuid() });
@@ -33,7 +33,7 @@ export const CreateAssetFolderRequestSchema = z.object({ path: AssetPathSchema }
33
33
  export const RenameAssetRequestSchema = z
34
34
  .object({ path: AssetPathSchema, newPath: AssetPathSchema })
35
35
  .strict();
36
- // DELETE /api/assets is a two-step confirm gate like content trash and
36
+ // DELETE /api/manage/v1/assets is a two-step confirm gate like content trash and
37
37
  // plugin uninstall: confirm is a literal "true" query string (not a
38
38
  // boolean) because query params are always strings on the wire.
39
39
  export const DeleteAssetQuerySchema = z.object({
@@ -308,6 +308,10 @@ export declare const PreviewTokenResponseSchema: z.ZodObject<{
308
308
  previewUrl: z.ZodNullable<z.ZodString>;
309
309
  }, z.core.$strip>;
310
310
  export type PreviewTokenResponse = z.infer<typeof PreviewTokenResponseSchema>;
311
+ export declare const ContentUrlImpactResponseSchema: z.ZodObject<{
312
+ publishedCount: z.ZodNumber;
313
+ }, z.core.$strip>;
314
+ export type ContentUrlImpactResponse = z.infer<typeof ContentUrlImpactResponseSchema>;
311
315
  export declare const ContentItemQuerySchema: z.ZodObject<{
312
316
  locale: z.ZodOptional<z.ZodString>;
313
317
  }, z.core.$strip>;
@@ -376,6 +380,7 @@ export declare const CopyContentRequestSchema: z.ZodObject<{
376
380
  includeChildren: z.ZodDefault<z.ZodBoolean>;
377
381
  }, z.core.$strip>;
378
382
  export type CopyContentRequest = z.infer<typeof CopyContentRequestSchema>;
383
+ export type CopyContentRequestInput = z.input<typeof CopyContentRequestSchema>;
379
384
  export declare const MoveContentRequestSchema: z.ZodObject<{
380
385
  targetParentId: z.ZodNullable<z.ZodString>;
381
386
  }, z.core.$strip>;
@@ -68,7 +68,7 @@ export const ContentByPathResponseSchema = z.object({
68
68
  access: NodeAccessFlagsSchema,
69
69
  });
70
70
  // S277c: the admin's by-address lookup reads `path` as a visitor's address
71
- // (GET /api/content/by-address), where by-path reads it as a stored path.
71
+ // (GET /api/manage/v1/content/by-address), where by-path reads it as a stored path.
72
72
  // The same answer on purpose: the node it finds is described exactly as
73
73
  // by-path describes it, stored path included.
74
74
  //
@@ -116,16 +116,16 @@ export const SaveContentResponseSchema = z.object({
116
116
  // on a default address that has no name).
117
117
  url: z.string().nullable(),
118
118
  });
119
- // GET /api/content/:id/versions/latest — the newest saved version,
119
+ // GET /api/manage/v1/content/:id/versions/latest: the newest saved version,
120
120
  // regardless of the current_version pointer. This is what the content
121
- // editor edits: after a draft save, GET /api/content/:id still serves the
121
+ // editor edits: after a draft save, GET /api/manage/v1/content/:id still serves the
122
122
  // pointer (published) version by design, so the draft would otherwise be
123
123
  // unreachable over REST. Also the response shape of
124
- // GET /api/content/:id/versions/:version (same "one full version" read).
124
+ // GET /api/manage/v1/content/:id/versions/:version (same "one full version" read).
125
125
  // S230c: ?locale= reads the newest save's values for one language exactly
126
126
  // as stored, for the editor's language tab.
127
127
  export const LatestVersionQuerySchema = z.object({ locale: CultureSchema.optional() });
128
- // S233: GET /api/content/:id/versions/:version takes the same ?locale= the
128
+ // S233: GET /api/manage/v1/content/:id/versions/:version takes the same ?locale= the
129
129
  // latest read does, so the editor can load an old version for one language.
130
130
  export const VersionQuerySchema = LatestVersionQuerySchema;
131
131
  export const LatestVersionResponseSchema = z.object({
@@ -138,7 +138,7 @@ export const LatestVersionResponseSchema = z.object({
138
138
  });
139
139
  // Version history list: metadata only — `data` can be arbitrarily large
140
140
  // and the history view only needs the row facts; the full snapshot is one
141
- // GET /api/content/:id/versions/:version away.
141
+ // GET /api/manage/v1/content/:id/versions/:version away.
142
142
  export const ContentVersionMetaSchema = ContentVersionSchema.omit({ data: true });
143
143
  // Newest-first pages. Version numbers are contiguous (1..latest, rows are
144
144
  // never deleted — immutability), so the cursor is simply the last version
@@ -184,7 +184,7 @@ export const PublishAllResultSchema = z.discriminatedUnion("status", [
184
184
  z.object({ culture: z.string(), status: z.literal("incomplete"), fieldIds: z.array(z.string()) }),
185
185
  ]);
186
186
  export const PublishAllResponseSchema = z.object({ results: z.array(PublishAllResultSchema) });
187
- // POST /api/content/:id/preview-token (Session 116) — mints a stateless,
187
+ // POST /api/manage/v1/content/:id/preview-token (Session 116) mints a stateless,
188
188
  // short-TTL, single-content-id preview token (see
189
189
  // apps/server/src/auth/preview-tokens.ts). Any existing content id may be
190
190
  // minted for, published or not; `expiresAt` is an ISO datetime string.
@@ -195,6 +195,10 @@ export const PreviewTokenResponseSchema = z.object({
195
195
  expiresAt: z.string().datetime(),
196
196
  previewUrl: z.string().nullable(),
197
197
  });
198
+ // GET /api/manage/v1/content/:id/url-impact (S300b): how many
199
+ // published pages a rename would move, the node itself plus its published
200
+ // descendants. A draft has no live URL to break, so it is not counted.
201
+ export const ContentUrlImpactResponseSchema = z.object({ publishedCount: z.number().int().min(0) });
198
202
  // `locale` selects which culture of the node to read; omitted means the
199
203
  // site's default culture. There is no fallback parameter: a field the
200
204
  // culture has not translated always falls back to the default culture's
@@ -275,7 +279,7 @@ export const ContentChildrenResponseSchema = z.object({
275
279
  });
276
280
  // Whole-array reorder (mirrors the document-type fields/tabs pattern) —
277
281
  // orderedIds must exactly match the current children of the parent (or
278
- // root nodes, for /api/content/roots/reorder); the adapter rejects
282
+ // root nodes, for /api/manage/v1/content/roots/reorder); the adapter rejects
279
283
  // otherwise. Only practical for a fully-loaded sibling list, so the admin
280
284
  // UI only offers drag-reorder once every page has loaded.
281
285
  export const ReorderNodesRequestSchema = z.object({
@@ -84,7 +84,7 @@ export const CONTENT_LIST_DEFAULT_SETTINGS = {
84
84
  { kind: "property", property: "url" },
85
85
  ],
86
86
  };
87
- // GET /api/content/:id/list query (Task 3). Cursor-paginated like every
87
+ // GET /api/manage/v1/content/:id/list query (Task 3). Cursor-paginated like every
88
88
  // other content list (api-design.md), plus a name filter and a
89
89
  // comma-separated set of field ids so the response only carries the data
90
90
  // the configured columns actually need.
@@ -30,7 +30,8 @@ export const CONTENT_NAME_KEY = "_name";
30
30
  // CreateContentRequestSchema only require `path: z.string().min(1)`), so
31
31
  // this is a generous local ceiling rather than a validated contract: it
32
32
  // exists so an unusually long name cannot silently produce an unusably
33
- // long path segment.
33
+ // long path segment. It counts code points, so a letter outside the BMP is
34
+ // never split.
34
35
  const MAX_SLUG_LENGTH = 200;
35
36
  /**
36
37
  * "About us" -> "about-us", "عن فريقنا" -> "عن-فريقنا".
@@ -72,21 +73,24 @@ export function slugify(name) {
72
73
  // introducer) and control characters.
73
74
  .replace(/[^\p{L}\p{N}]+/gu, "-")
74
75
  .replace(/^-+|-+$/g, "");
75
- if (slug.length <= MAX_SLUG_LENGTH)
76
+ // Counted and cut in code points: a UTF-16 slice could end inside a
77
+ // surrogate pair and leave a lone surrogate in a path.
78
+ const points = Array.from(slug);
79
+ if (points.length <= MAX_SLUG_LENGTH)
76
80
  return slug;
77
- const truncated = slug.slice(0, MAX_SLUG_LENGTH);
81
+ const truncated = points.slice(0, MAX_SLUG_LENGTH);
78
82
  // The cut already lands between words when the very next character (just
79
83
  // past the budget) is a dash or the slug ends there exactly.
80
- const nextChar = slug.charAt(MAX_SLUG_LENGTH);
84
+ const nextChar = points[MAX_SLUG_LENGTH] ?? "";
81
85
  if (nextChar === "" || nextChar === "-")
82
- return truncated.replace(/-+$/g, "");
86
+ return truncated.join("").replace(/-+$/g, "");
83
87
  // Otherwise the cut fell mid-word: back up to the last dash boundary so
84
88
  // no word is severed, unless that dash is so early it would throw away
85
89
  // nearly all of the budget for one very long final word, in which case a
86
90
  // mid-word cut is the lesser evil.
87
91
  const lastDash = truncated.lastIndexOf("-");
88
92
  const cut = lastDash > MAX_SLUG_LENGTH / 2 ? truncated.slice(0, lastDash) : truncated;
89
- return cut.replace(/-+$/g, "");
93
+ return cut.join("").replace(/-+$/g, "");
90
94
  }
91
95
  /**
92
96
  * S228: the first free name in a "Name", "Name (2)", "Name (3)" series.
@@ -161,7 +165,7 @@ function numberedSlug(stem, number) {
161
165
  const whole = slugify(`${stem} (${number})`);
162
166
  if (whole === String(number) || whole.endsWith(suffix))
163
167
  return whole;
164
- let head = slugify(stem).slice(0, MAX_SLUG_LENGTH - suffix.length);
168
+ let head = Array.from(slugify(stem)).slice(0, MAX_SLUG_LENGTH - suffix.length).join("");
165
169
  while (head.endsWith("-"))
166
170
  head = head.slice(0, -1);
167
171
  return head === "" ? String(number) : `${head}${suffix}`;
@@ -144,6 +144,7 @@ export declare const ContentRestoreConflictSchema: z.ZodUnion<readonly [z.ZodObj
144
144
  }, z.core.$strip>, z.ZodObject<{
145
145
  message: z.ZodString;
146
146
  }, z.core.$strip>]>;
147
+ export type ContentTrashListQuery = z.infer<typeof ContentTrashListQuerySchema>;
147
148
  export type ContentTrashListResponse = z.infer<typeof ContentTrashListResponseSchema>;
148
149
  export type TrashedSubtreeDto = z.infer<typeof TrashedSubtreeSchema>;
149
150
  export type ContentRestoreBlocked = z.infer<typeof ContentRestoreBlockedSchema>;