@aphexcms/cms-core 11.1.1 → 11.2.1

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 (36) hide show
  1. package/dist/api/docs-ui.d.ts +22 -0
  2. package/dist/api/docs-ui.d.ts.map +1 -0
  3. package/dist/api/docs-ui.js +19 -0
  4. package/dist/api/schemas/assets.d.ts +11 -0
  5. package/dist/api/schemas/assets.d.ts.map +1 -1
  6. package/dist/api/schemas/assets.js +24 -0
  7. package/dist/auth/auth-hooks.d.ts.map +1 -1
  8. package/dist/auth/auth-hooks.js +4 -1
  9. package/dist/local-api/collection-api.d.ts.map +1 -1
  10. package/dist/local-api/collection-api.js +23 -6
  11. package/dist/server/api/index.d.ts.map +1 -1
  12. package/dist/server/api/index.js +7 -0
  13. package/dist/server/api/openapi/generate.d.ts +13 -0
  14. package/dist/server/api/openapi/generate.d.ts.map +1 -0
  15. package/dist/server/api/openapi/generate.js +529 -0
  16. package/dist/server/api/openapi/json-schema.d.ts +45 -0
  17. package/dist/server/api/openapi/json-schema.d.ts.map +1 -0
  18. package/dist/server/api/openapi/json-schema.js +206 -0
  19. package/dist/server/api/openapi/registry.d.ts +78 -0
  20. package/dist/server/api/openapi/registry.d.ts.map +1 -0
  21. package/dist/server/api/openapi/registry.js +628 -0
  22. package/dist/server/api/routes/agent-change-sets.d.ts +6 -0
  23. package/dist/server/api/routes/agent-change-sets.d.ts.map +1 -1
  24. package/dist/server/api/routes/agent-change-sets.js +2 -1
  25. package/dist/server/api/routes/jobs.d.ts +32 -0
  26. package/dist/server/api/routes/jobs.d.ts.map +1 -1
  27. package/dist/server/api/routes/jobs.js +7 -3
  28. package/dist/server/api/routes/openapi.d.ts +34 -0
  29. package/dist/server/api/routes/openapi.d.ts.map +1 -0
  30. package/dist/server/api/routes/openapi.js +97 -0
  31. package/dist/server/index.d.ts +1 -0
  32. package/dist/server/index.d.ts.map +1 -1
  33. package/dist/server/index.js +1 -0
  34. package/dist/types/config.d.ts +15 -0
  35. package/dist/types/config.d.ts.map +1 -1
  36. package/package.json +1 -1
@@ -0,0 +1,206 @@
1
+ import { isFieldRequired } from '../../../field-validation/utils.js';
2
+ /** Shared component schemas referenced by `$ref` from generated field shapes. */
3
+ export const SHARED_VALUE_COMPONENTS = {
4
+ Reference: {
5
+ type: 'object',
6
+ description: 'A link to another document. Only `_ref` is written by the caller.',
7
+ properties: {
8
+ _type: { type: 'string', const: 'reference' },
9
+ _ref: { type: 'string', description: 'Target document id.' },
10
+ _key: { type: 'string', description: 'Stable key when inside an array.' }
11
+ },
12
+ required: ['_ref']
13
+ },
14
+ ImageValue: {
15
+ type: 'object',
16
+ properties: {
17
+ _type: { type: 'string', const: 'image' },
18
+ asset: { $ref: '#/components/schemas/Reference' },
19
+ alt: { type: 'string' },
20
+ hotspot: { type: 'object', additionalProperties: true },
21
+ crop: { type: 'object', additionalProperties: true }
22
+ },
23
+ required: ['asset']
24
+ },
25
+ FileValue: {
26
+ type: 'object',
27
+ properties: {
28
+ _type: { type: 'string', const: 'file' },
29
+ asset: { $ref: '#/components/schemas/Reference' }
30
+ },
31
+ required: ['asset']
32
+ },
33
+ PortableTextBlock: {
34
+ type: 'object',
35
+ description: 'One block of Portable Text. Text blocks are managed by the editor; custom block types declared in the field’s `of` array appear as siblings with their own `_type`.',
36
+ properties: {
37
+ _type: { type: 'string' },
38
+ _key: { type: 'string' },
39
+ style: { type: 'string' },
40
+ listItem: { type: 'string' },
41
+ level: { type: 'number' },
42
+ markDefs: { type: 'array', items: { type: 'object', additionalProperties: true } },
43
+ children: {
44
+ type: 'array',
45
+ items: {
46
+ type: 'object',
47
+ properties: {
48
+ _type: { type: 'string' },
49
+ _key: { type: 'string' },
50
+ text: { type: 'string' },
51
+ marks: { type: 'array', items: { type: 'string' } }
52
+ }
53
+ }
54
+ }
55
+ },
56
+ additionalProperties: true
57
+ }
58
+ };
59
+ function withMeta(field, schema) {
60
+ const out = { ...schema };
61
+ if (field.title)
62
+ out.title = field.title;
63
+ if (field.description)
64
+ out.description = field.description;
65
+ return out;
66
+ }
67
+ /**
68
+ * Reference targets as a `$ref` union. An empty/unknown `to` degrades to the
69
+ * bare Reference component rather than dropping the field.
70
+ */
71
+ function referenceSchema(field, schemaMap) {
72
+ const to = 'to' in field ? field.to : undefined;
73
+ const targets = to?.map((t) => t.type).filter((t) => schemaMap.has(t)) ?? [];
74
+ if (targets.length === 0)
75
+ return { $ref: '#/components/schemas/Reference' };
76
+ return {
77
+ allOf: [{ $ref: '#/components/schemas/Reference' }],
78
+ description: `References: ${targets.join(', ')}`
79
+ };
80
+ }
81
+ /**
82
+ * The depth=0 *write* shape of one field as JSON Schema.
83
+ *
84
+ * Write shape, not read shape: references stay `{_ref}` rather than the resolved
85
+ * document, because that is what a caller sends and what the validator checks.
86
+ */
87
+ export function fieldToJsonSchema(field, schemaMap, seen = new Set()) {
88
+ switch (field.type) {
89
+ case 'string':
90
+ case 'text':
91
+ case 'slug':
92
+ case 'url': {
93
+ const base = { type: 'string' };
94
+ // `slug` is a bare string in Aphex — never Sanity's `{ current }`.
95
+ if (field.type === 'slug')
96
+ base.description = 'Slug as a plain string, e.g. "about-us".';
97
+ if (field.type === 'url')
98
+ base.format = 'uri';
99
+ const list = 'list' in field ? field.list : undefined;
100
+ if (Array.isArray(list) && list.length > 0) {
101
+ base.enum = list.map((o) => typeof o === 'object' && o !== null && 'value' in o ? o.value : o);
102
+ }
103
+ return withMeta(field, base);
104
+ }
105
+ case 'number':
106
+ return withMeta(field, { type: 'number' });
107
+ case 'boolean':
108
+ return withMeta(field, { type: 'boolean' });
109
+ case 'date':
110
+ return withMeta(field, { type: 'string', format: 'date', examples: ['2026-09-13'] });
111
+ case 'datetime':
112
+ return withMeta(field, {
113
+ type: 'string',
114
+ format: 'date-time',
115
+ examples: ['2026-09-13T15:00:00.000Z']
116
+ });
117
+ case 'image':
118
+ return withMeta(field, { $ref: '#/components/schemas/ImageValue' });
119
+ case 'file':
120
+ return withMeta(field, { $ref: '#/components/schemas/FileValue' });
121
+ case 'reference':
122
+ return withMeta(field, referenceSchema(field, schemaMap));
123
+ case 'array': {
124
+ const of = 'of' in field ? field.of : undefined;
125
+ if (!of || of.length === 0)
126
+ return withMeta(field, { type: 'array', items: {} });
127
+ // A `block` member anywhere in `of` makes this Portable Text.
128
+ if (of.some((item) => item.type === 'block')) {
129
+ return withMeta(field, {
130
+ type: 'array',
131
+ items: { $ref: '#/components/schemas/PortableTextBlock' }
132
+ });
133
+ }
134
+ const variants = of.map((item) => {
135
+ // A named object type becomes a `$ref` into components — which is also
136
+ // what makes a self-containing schema (an object whose array names its
137
+ // own type) terminate: the component is emitted once, not inlined.
138
+ const named = schemaMap.get(item.type);
139
+ if (named && named.type === 'object') {
140
+ return { $ref: `#/components/schemas/${componentName(named.name)}` };
141
+ }
142
+ return fieldToJsonSchema(item, schemaMap, seen);
143
+ });
144
+ return withMeta(field, {
145
+ type: 'array',
146
+ items: variants.length === 1 ? variants[0] : { oneOf: variants }
147
+ });
148
+ }
149
+ case 'object': {
150
+ const fields = 'fields' in field ? field.fields : undefined;
151
+ if (!fields || fields.length === 0) {
152
+ return withMeta(field, { type: 'object', additionalProperties: true });
153
+ }
154
+ return withMeta(field, fieldsToJsonSchema(fields, schemaMap, seen));
155
+ }
156
+ default:
157
+ return withMeta(field, {});
158
+ }
159
+ }
160
+ /** Turn a list of fields into an object schema with a `required` array. */
161
+ export function fieldsToJsonSchema(fields, schemaMap, seen = new Set()) {
162
+ const properties = {};
163
+ const required = [];
164
+ for (const field of fields) {
165
+ properties[field.name] = fieldToJsonSchema(field, schemaMap, seen);
166
+ if (isFieldRequired(field))
167
+ required.push(field.name);
168
+ }
169
+ const out = {
170
+ type: 'object',
171
+ properties,
172
+ // A write may legitimately carry a subset of fields, but it may not carry
173
+ // fields the schema doesn't declare — the validator rejects those as
174
+ // `kind: "structural"`, so the spec says so too.
175
+ additionalProperties: false
176
+ };
177
+ if (required.length > 0)
178
+ out.required = required;
179
+ return out;
180
+ }
181
+ /** PascalCase component name for a schema type, e.g. `post` → `PostData`. */
182
+ export function componentName(schemaName) {
183
+ return schemaName
184
+ .replace(/[-_](\w)/g, (_, c) => c.toUpperCase())
185
+ .replace(/^(\w)/, (_, c) => c.toUpperCase());
186
+ }
187
+ /**
188
+ * Every schema type in the instance as components: `<Type>Data` for documents
189
+ * (the `draftData`/`data` payload) and the object types they reference.
190
+ */
191
+ export function buildSchemaComponents(schemaTypes) {
192
+ const schemaMap = new Map(schemaTypes.map((s) => [s.name, s]));
193
+ const components = {};
194
+ for (const schema of schemaTypes) {
195
+ const name = componentName(schema.name);
196
+ const body = fieldsToJsonSchema(schema.fields ?? [], schemaMap, new Set([schema.name]));
197
+ components[schema.type === 'document' ? `${name}Data` : name] = {
198
+ ...body,
199
+ description: schema.description ??
200
+ (schema.type === 'document'
201
+ ? `Write shape for \`${schema.name}\` documents.`
202
+ : `Reusable object type \`${schema.name}\`.`)
203
+ };
204
+ }
205
+ return components;
206
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The route registry — what each mounted endpoint *is*, next to the zod schema
3
+ * that already governs it.
4
+ *
5
+ * This is the one hand-maintained artifact in the OpenAPI pipeline, and it exists
6
+ * because the schemas alone can't say which path they belong to. Everything else
7
+ * (properties, types, required-ness, enums) is derived, so the only thing that can
8
+ * rot here is a missing or stale *row* — which `tests/openapi-registry.test.ts`
9
+ * catches by diffing these keys against Hono's own `app.routes`. Add a route
10
+ * without a row and that test fails.
11
+ *
12
+ * `request`/`query` point at the live zod objects the handler validates with, so a
13
+ * contract change shows up in the spec without anyone editing this file.
14
+ */
15
+ import type { ZodType } from 'zod';
16
+ /** How a route answers to a read-only API key. See `auth/auth-hooks.ts`. */
17
+ export type AuthMode =
18
+ /** Session or API key; a read-only key is accepted. */
19
+ 'read'
20
+ /** Session or API key; a read-only key gets 403. */
21
+ | 'write'
22
+ /** Read-shaped, but uses POST for a complex payload — read-only keys pass. */
23
+ | 'read-via-post'
24
+ /** No credentials required. */
25
+ | 'public'
26
+ /** Session cookie only — API keys are rejected by the handler. */
27
+ | 'session'
28
+ /** Machine-to-machine, gated on a shared secret rather than user auth. */
29
+ | 'secret';
30
+ export interface RouteMeta {
31
+ /** Hono path as mounted, e.g. `/api/documents/:id`. */
32
+ path: string;
33
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
34
+ summary: string;
35
+ description?: string;
36
+ tag: string;
37
+ auth: AuthMode;
38
+ /** Zod object validating the JSON request body. */
39
+ request?: ZodType;
40
+ /** Zod object validating the query string. */
41
+ query?: ZodType;
42
+ /** Zod object describing the success response, where one exists. */
43
+ response?: ZodType;
44
+ /** Set for endpoints whose body is `multipart/form-data`, not JSON. */
45
+ formData?: {
46
+ fields: Record<string, {
47
+ type: string;
48
+ format?: string;
49
+ description?: string;
50
+ }>;
51
+ };
52
+ /**
53
+ * Replace the generated schema for named body properties.
54
+ *
55
+ * For fields the zod contract deliberately leaves as `z.unknown()` because
56
+ * something downstream validates them — `where` and `select` on the query
57
+ * endpoint, parsed by `LocalAPI.find()`. Converting `z.unknown()` yields `{}`,
58
+ * which is accurate and useless.
59
+ */
60
+ bodyOverrides?: Record<string, Record<string, unknown>>;
61
+ /** A worked request body, shown in place of a generated one. */
62
+ requestExample?: unknown;
63
+ /**
64
+ * For `/api/documents` writes: the request body's document payload is
65
+ * per-collection, so the generator expands it into a `oneOf` over
66
+ * `<Type>Data` components instead of leaving `Record<string, unknown>`.
67
+ */
68
+ expandDocumentData?: boolean;
69
+ }
70
+ export declare const ROUTE_REGISTRY: RouteMeta[];
71
+ /** `METHOD path` key, matching the shape of Hono's `app.routes` entries. */
72
+ export declare function routeKey(method: string, path: string): string;
73
+ /**
74
+ * What each tag groups, for the rendered doc's section headers. Keyed by the
75
+ * `tag` values used above; a tag without an entry still renders, just bare.
76
+ */
77
+ export declare const TAG_DESCRIPTIONS: Record<string, string>;
78
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version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