@dyrected/core 2.5.51 → 2.5.53
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.
- package/dist/__tests__/admin-auth.test.d.ts +2 -0
- package/dist/__tests__/admin-auth.test.d.ts.map +1 -0
- package/dist/__tests__/admin-auth.test.js +440 -0
- package/dist/__tests__/admin-auth.test.js.map +1 -0
- package/dist/__tests__/config.test.js +57 -0
- package/dist/__tests__/config.test.js.map +1 -1
- package/dist/__tests__/email.service.test.d.ts +2 -0
- package/dist/__tests__/email.service.test.d.ts.map +1 -0
- package/dist/__tests__/email.service.test.js +46 -0
- package/dist/__tests__/email.service.test.js.map +1 -0
- package/dist/__tests__/fixtures/editorial-workflow.d.ts +9 -0
- package/dist/__tests__/fixtures/editorial-workflow.d.ts.map +1 -0
- package/dist/__tests__/fixtures/editorial-workflow.js +12 -0
- package/dist/__tests__/fixtures/editorial-workflow.js.map +1 -0
- package/dist/__tests__/mocks.d.ts +6 -0
- package/dist/__tests__/mocks.d.ts.map +1 -1
- package/dist/__tests__/mocks.js +8 -0
- package/dist/__tests__/mocks.js.map +1 -1
- package/dist/__tests__/openapi.test.d.ts +2 -0
- package/dist/__tests__/openapi.test.d.ts.map +1 -0
- package/dist/__tests__/openapi.test.js +95 -0
- package/dist/__tests__/openapi.test.js.map +1 -0
- package/dist/__tests__/parse-sort.test.d.ts +2 -0
- package/dist/__tests__/parse-sort.test.d.ts.map +1 -0
- package/dist/__tests__/parse-sort.test.js +24 -0
- package/dist/__tests__/parse-sort.test.js.map +1 -0
- package/dist/__tests__/preferences.test.d.ts +2 -0
- package/dist/__tests__/preferences.test.d.ts.map +1 -0
- package/dist/__tests__/preferences.test.js +168 -0
- package/dist/__tests__/preferences.test.js.map +1 -0
- package/dist/__tests__/router.test.js +4 -0
- package/dist/__tests__/router.test.js.map +1 -1
- package/dist/__tests__/where.test.js +9 -1
- package/dist/__tests__/where.test.js.map +1 -1
- package/dist/__tests__/workflow.test.d.ts +2 -0
- package/dist/__tests__/workflow.test.d.ts.map +1 -0
- package/dist/__tests__/workflow.test.js +497 -0
- package/dist/__tests__/workflow.test.js.map +1 -0
- package/dist/app-config-DLK6bCaP.d.cts +1390 -0
- package/dist/app-config-DLK6bCaP.d.ts +1390 -0
- package/dist/app-config-DqCipvSI.d.cts +1411 -0
- package/dist/app-config-DqCipvSI.d.ts +1411 -0
- package/dist/app-config-oOarB6Fw.d.cts +1411 -0
- package/dist/app-config-oOarB6Fw.d.ts +1411 -0
- package/dist/auth/token.d.ts +2 -0
- package/dist/auth/token.d.ts.map +1 -1
- package/dist/auth/token.js.map +1 -1
- package/dist/controllers/admin-auth.controller.d.ts +68 -0
- package/dist/controllers/admin-auth.controller.d.ts.map +1 -0
- package/dist/controllers/admin-auth.controller.js +414 -0
- package/dist/controllers/admin-auth.controller.js.map +1 -0
- package/dist/controllers/collection.controller.d.ts +69 -0
- package/dist/controllers/collection.controller.d.ts.map +1 -1
- package/dist/controllers/collection.controller.js +232 -7
- package/dist/controllers/collection.controller.js.map +1 -1
- package/dist/controllers/global.controller.js +19 -3
- package/dist/controllers/global.controller.js.map +1 -1
- package/dist/controllers/media.controller.d.ts +2 -0
- package/dist/controllers/media.controller.d.ts.map +1 -1
- package/dist/controllers/media.controller.js +13 -6
- package/dist/controllers/media.controller.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +168 -6
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +54 -8
- package/dist/server.d.cts +7 -1
- package/dist/server.d.ts +7 -1
- package/dist/server.js +54 -8
- package/dist/services/email-template.d.ts +46 -0
- package/dist/services/email-template.d.ts.map +1 -0
- package/dist/services/email-template.js +88 -0
- package/dist/services/email-template.js.map +1 -0
- package/dist/services/email.service.d.ts.map +1 -1
- package/dist/services/email.service.js +25 -148
- package/dist/services/email.service.js.map +1 -1
- package/dist/services/population.service.d.ts.map +1 -1
- package/dist/services/population.service.js +27 -1
- package/dist/services/population.service.js.map +1 -1
- package/dist/types/access.d.ts +38 -0
- package/dist/types/access.d.ts.map +1 -0
- package/dist/types/access.js +2 -0
- package/dist/types/access.js.map +1 -0
- package/dist/types/adapters.d.ts +146 -0
- package/dist/types/adapters.d.ts.map +1 -0
- package/dist/types/adapters.js +2 -0
- package/dist/types/adapters.js.map +1 -0
- package/dist/types/admin-auth.d.ts +132 -0
- package/dist/types/admin-auth.d.ts.map +1 -0
- package/dist/types/admin-auth.js +2 -0
- package/dist/types/admin-auth.js.map +1 -0
- package/dist/types/admin.d.ts +65 -0
- package/dist/types/admin.d.ts.map +1 -0
- package/dist/types/admin.js +2 -0
- package/dist/types/admin.js.map +1 -0
- package/dist/types/app-config.d.ts +143 -0
- package/dist/types/app-config.d.ts.map +1 -0
- package/dist/types/app-config.js +2 -0
- package/dist/types/app-config.js.map +1 -0
- package/dist/types/documents.d.ts +65 -0
- package/dist/types/documents.d.ts.map +1 -0
- package/dist/types/documents.js +2 -0
- package/dist/types/documents.js.map +1 -0
- package/dist/types/hooks.d.ts +122 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +2 -0
- package/dist/types/hooks.js.map +1 -0
- package/dist/types/index.d.ts +12 -1748
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +12 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/request.d.ts +42 -0
- package/dist/types/request.d.ts.map +1 -0
- package/dist/types/request.js +2 -0
- package/dist/types/request.js.map +1 -0
- package/dist/types/schema-config.d.ts +303 -0
- package/dist/types/schema-config.d.ts.map +1 -0
- package/dist/types/schema-config.js +2 -0
- package/dist/types/schema-config.js.map +1 -0
- package/dist/types/schema-core.d.ts +294 -0
- package/dist/types/schema-core.d.ts.map +1 -0
- package/dist/types/schema-core.js +2 -0
- package/dist/types/schema-core.js.map +1 -0
- package/dist/types/schema-inference.d.ts +73 -0
- package/dist/types/schema-inference.d.ts.map +1 -0
- package/dist/types/schema-inference.js +2 -0
- package/dist/types/schema-inference.js.map +1 -0
- package/dist/types/workflows.d.ts +84 -0
- package/dist/types/workflows.d.ts.map +1 -0
- package/dist/types/workflows.js +7 -0
- package/dist/types/workflows.js.map +1 -0
- package/dist/utils/admin-auth.d.ts +5 -0
- package/dist/utils/admin-auth.d.ts.map +1 -0
- package/dist/utils/admin-auth.js +39 -0
- package/dist/utils/admin-auth.js.map +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +86 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/hooks.d.ts.map +1 -1
- package/dist/utils/hooks.js +12 -8
- package/dist/utils/hooks.js.map +1 -1
- package/dist/utils/openapi.d.ts.map +1 -1
- package/dist/utils/openapi.js +559 -48
- package/dist/utils/openapi.js.map +1 -1
- package/dist/utils/parse-sort.d.ts +7 -0
- package/dist/utils/parse-sort.d.ts.map +1 -0
- package/dist/utils/parse-sort.js +23 -0
- package/dist/utils/parse-sort.js.map +1 -0
- package/dist/utils/swagger.d.ts +6 -0
- package/dist/utils/swagger.d.ts.map +1 -1
- package/dist/utils/swagger.js +13 -2
- package/dist/utils/swagger.js.map +1 -1
- package/dist/utils/upload-validation.d.ts +23 -0
- package/dist/utils/upload-validation.d.ts.map +1 -0
- package/dist/utils/upload-validation.js +44 -0
- package/dist/utils/upload-validation.js.map +1 -0
- package/dist/utils/where-sanitizer.d.ts.map +1 -1
- package/dist/utils/where-sanitizer.js +4 -0
- package/dist/utils/where-sanitizer.js.map +1 -1
- package/dist/workflows.d.ts +54 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +282 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1411 @@
|
|
|
1
|
+
import { icons } from 'lucide-react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimum HTTP request context passed to every server-side hook and resolver.
|
|
5
|
+
*
|
|
6
|
+
* The full Web Standard `Request` is available as `raw` when you need it, but
|
|
7
|
+
* most hooks only need `query` (URL search parameters).
|
|
8
|
+
*/
|
|
9
|
+
interface HookRequestContext {
|
|
10
|
+
/** Parsed URL query-string parameters, e.g. `{ page: '2', search: 'hello' }`. */
|
|
11
|
+
query: Record<string, string>;
|
|
12
|
+
/** Incoming HTTP headers, lowercased. */
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
/** The raw Web Standard `Request` object. Useful for streaming or advanced header inspection. */
|
|
15
|
+
raw?: Request;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Base shape of an authenticated user as decoded from the JWT.
|
|
19
|
+
*
|
|
20
|
+
* The actual shape will include every field on your auth collection — this
|
|
21
|
+
* interface only guarantees the properties that Dyrected always stamps on the
|
|
22
|
+
* token. Extend it in your own codebase for stronger typing:
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* declare module '@dyrected/core' {
|
|
26
|
+
* interface AuthenticatedUser {
|
|
27
|
+
* role: 'admin' | 'editor'
|
|
28
|
+
* organizationId: string
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
interface AuthenticatedUser {
|
|
33
|
+
/** The user's document ID in the database. */
|
|
34
|
+
sub: string;
|
|
35
|
+
/** The user's email address. */
|
|
36
|
+
email?: string;
|
|
37
|
+
/** Slug of the collection this user was authenticated against. */
|
|
38
|
+
collection: string;
|
|
39
|
+
/** Array of role strings, if your auth collection has a `roles` field. */
|
|
40
|
+
roles?: string[];
|
|
41
|
+
/** Any additional fields from the auth collection document. */
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A function that determines whether the current user can perform an operation.
|
|
47
|
+
*
|
|
48
|
+
* Return `true` to allow, `false` to deny.
|
|
49
|
+
* Return a `where`-style object to allow access only to matching documents
|
|
50
|
+
* (useful for multi-tenant setups where users can only see their own data).
|
|
51
|
+
*
|
|
52
|
+
* Can also be expressed as a Jexl expression **string** for simple role checks
|
|
53
|
+
* that need to be serialised (e.g. stored in the database or sent to the Admin UI).
|
|
54
|
+
*
|
|
55
|
+
* @template TDoc The shape of the collection's document.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Simple role check
|
|
59
|
+
* access: {
|
|
60
|
+
* delete: ({ user }) => user?.roles?.includes('admin') ?? false,
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Row-level: users can only read their own documents
|
|
65
|
+
* access: {
|
|
66
|
+
* read: ({ user }) => ({ owner: { equals: user?.sub } }),
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Jexl string — evaluated server-side
|
|
71
|
+
* access: {
|
|
72
|
+
* update: "user.roles contains 'editor'",
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
type AccessFunction<TDoc extends object = Record<string, unknown>> = (args: {
|
|
76
|
+
user: AuthenticatedUser | undefined;
|
|
77
|
+
doc?: TDoc;
|
|
78
|
+
data?: Partial<TDoc>;
|
|
79
|
+
req: HookRequestContext;
|
|
80
|
+
}) => boolean | Record<string, unknown> | Promise<boolean | Record<string, unknown>>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The minimum shape of every document returned by the database layer.
|
|
84
|
+
*
|
|
85
|
+
* All documents have an `id` field assigned by the adapter. Additional fields
|
|
86
|
+
* are stored as `unknown` until you narrow them with your own interface.
|
|
87
|
+
*
|
|
88
|
+
* Use this as the base when declaring your collection document types:
|
|
89
|
+
* ```ts
|
|
90
|
+
* interface Post extends BaseDocument {
|
|
91
|
+
* title: string
|
|
92
|
+
* slug: string
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
interface BaseDocument {
|
|
97
|
+
/** The document's unique identifier, assigned by the database adapter. */
|
|
98
|
+
id: string;
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The envelope returned by collection list endpoints (`GET /api/collections/:slug`).
|
|
103
|
+
*
|
|
104
|
+
* @template T The document type.
|
|
105
|
+
*/
|
|
106
|
+
interface PaginatedResult<T = Record<string, any>> {
|
|
107
|
+
/** The documents on the current page. */
|
|
108
|
+
docs: T[];
|
|
109
|
+
/** Total number of documents matching the query (across all pages). */
|
|
110
|
+
total: number;
|
|
111
|
+
/** Maximum number of documents per page as requested. */
|
|
112
|
+
limit: number;
|
|
113
|
+
/** The current page number (1-indexed). */
|
|
114
|
+
page: number;
|
|
115
|
+
/** Total number of pages given the current `limit`. */
|
|
116
|
+
totalPages: number;
|
|
117
|
+
/** Whether a next page exists. */
|
|
118
|
+
hasNextPage: boolean;
|
|
119
|
+
/** Whether a previous page exists. */
|
|
120
|
+
hasPrevPage: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Metadata returned after a file is uploaded and stored.
|
|
124
|
+
* Stored on the document in upload collections.
|
|
125
|
+
*/
|
|
126
|
+
interface FileData {
|
|
127
|
+
filename: string;
|
|
128
|
+
filesize?: number;
|
|
129
|
+
mimeType: string;
|
|
130
|
+
/** Public URL of the stored file. */
|
|
131
|
+
url: string;
|
|
132
|
+
width?: number;
|
|
133
|
+
height?: number;
|
|
134
|
+
focalPoint?: {
|
|
135
|
+
x: number;
|
|
136
|
+
y: number;
|
|
137
|
+
};
|
|
138
|
+
/** Base64-encoded BlurHash string for progressive image loading. */
|
|
139
|
+
blurhash?: string;
|
|
140
|
+
/** `'upload'` for server-stored files; `'external'` for provider-managed files. */
|
|
141
|
+
type?: "upload" | "external";
|
|
142
|
+
provider?: string;
|
|
143
|
+
provider_metadata?: unknown;
|
|
144
|
+
[key: string]: unknown;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A valid icon component name from the Lucide icon set bundled with Dyrected Admin. */
|
|
148
|
+
type AdminIconName = keyof typeof icons;
|
|
149
|
+
/** Ordered custom component keys rendered around the built-in Admin dashboard. */
|
|
150
|
+
interface AdminDashboardComponentSlots {
|
|
151
|
+
beforeDashboard?: string[];
|
|
152
|
+
afterDashboard?: string[];
|
|
153
|
+
}
|
|
154
|
+
/** Ordered custom component keys rendered around a collection's list content. */
|
|
155
|
+
interface CollectionListComponentSlots {
|
|
156
|
+
beforeList?: string[];
|
|
157
|
+
beforeListTable?: string[];
|
|
158
|
+
afterListTable?: string[];
|
|
159
|
+
afterList?: string[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Branding and metadata options for the Dyrected Admin UI.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* admin: {
|
|
166
|
+
* branding: {
|
|
167
|
+
* logo: '/logo.svg',
|
|
168
|
+
* primaryColor: '#6366f1',
|
|
169
|
+
* },
|
|
170
|
+
* meta: {
|
|
171
|
+
* titleSuffix: '- My App',
|
|
172
|
+
* },
|
|
173
|
+
* }
|
|
174
|
+
*/
|
|
175
|
+
interface AdminConfig {
|
|
176
|
+
/** Custom component slots around the built-in dashboard. */
|
|
177
|
+
components?: AdminDashboardComponentSlots;
|
|
178
|
+
branding?: {
|
|
179
|
+
/** Full logo image shown in the expanded sidebar. URL or imported image asset. */
|
|
180
|
+
logo?: string;
|
|
181
|
+
/** Compact logo mark used in the collapsed sidebar state. */
|
|
182
|
+
logoMark?: string;
|
|
183
|
+
/** Text alternative or addition to the logo image. */
|
|
184
|
+
logoText?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Primary accent colour as any CSS colour value.
|
|
187
|
+
* @example '#6366f1'
|
|
188
|
+
* @example 'hsl(240 50% 60%)'
|
|
189
|
+
*/
|
|
190
|
+
primaryColor?: string;
|
|
191
|
+
/** Browser tab favicon URL. */
|
|
192
|
+
favicon?: string;
|
|
193
|
+
/** Font family for body and UI text. Must be loaded separately. */
|
|
194
|
+
fontSans?: string;
|
|
195
|
+
/** Font family for headings. Must be loaded separately. */
|
|
196
|
+
fontSerif?: string;
|
|
197
|
+
};
|
|
198
|
+
meta?: {
|
|
199
|
+
/**
|
|
200
|
+
* String appended to every Admin page's `<title>`.
|
|
201
|
+
* @default '- Dyrected'
|
|
202
|
+
*/
|
|
203
|
+
titleSuffix?: string;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* The canonical/base URL of the frontend website for links and iframe live previews.
|
|
207
|
+
*/
|
|
208
|
+
siteUrl?: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type FieldType = "text" | "textarea" | "richText" | "number" | "boolean" | "date" | "datetime" | "time" | "select" | "multiSelect" | "radio" | "relationship" | "array" | "object" | "json" | "blocks" | "image" | "email" | "url" | "icon" | "join" | "row";
|
|
212
|
+
interface DynamicOptionsResolverArgs {
|
|
213
|
+
/** Database adapter available to server-side option resolvers. */
|
|
214
|
+
db?: DatabaseAdapter;
|
|
215
|
+
/** Authenticated user making the request, if any. */
|
|
216
|
+
user?: AuthenticatedUser;
|
|
217
|
+
/** Current HTTP request context, including query parameters. */
|
|
218
|
+
req: HookRequestContext;
|
|
219
|
+
}
|
|
220
|
+
type DynamicOptionsResolver = (args: DynamicOptionsResolverArgs) => Promise<DynamicOptionItem[]> | DynamicOptionItem[];
|
|
221
|
+
interface DynamicOptionsConfig {
|
|
222
|
+
/** Resolver function executed on the server to produce option items. */
|
|
223
|
+
resolve: DynamicOptionsResolver;
|
|
224
|
+
/** Cache duration in seconds for identical resolver calls. */
|
|
225
|
+
cacheTTL?: number;
|
|
226
|
+
}
|
|
227
|
+
type DynamicOptionItem = string | {
|
|
228
|
+
label: string;
|
|
229
|
+
value: unknown;
|
|
230
|
+
};
|
|
231
|
+
interface Block {
|
|
232
|
+
/** Stable identifier stored in each block row as `blockType`. */
|
|
233
|
+
slug: string;
|
|
234
|
+
/** Human-readable labels shown in the Admin block picker. */
|
|
235
|
+
labels?: {
|
|
236
|
+
/** Singular label, for example `Hero`. */
|
|
237
|
+
singular: string;
|
|
238
|
+
/** Plural label, for example `Heroes`. */
|
|
239
|
+
plural: string;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Lucide icon name shown on the block card and in the block library.
|
|
243
|
+
* Falls back to a generic layout icon when omitted.
|
|
244
|
+
*/
|
|
245
|
+
icon?: AdminIconName;
|
|
246
|
+
/** Short one-line summary shown under the block name (block card subtitle). */
|
|
247
|
+
description?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Presentation variants for this block. All variants share the same `fields`;
|
|
250
|
+
* only the rendered layout differs. The chosen variant is stored on each block
|
|
251
|
+
* row under the reserved `variant` key and passed to the render component as a
|
|
252
|
+
* `variant` prop. Switching variant preserves the author's content.
|
|
253
|
+
*/
|
|
254
|
+
variants?: BlockVariant[];
|
|
255
|
+
/** Fields that make up this block's payload. */
|
|
256
|
+
fields: Field[];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* A single presentation variant of a {@link Block}. Variants are a layout choice
|
|
260
|
+
* over a shared field set — for example a Hero rendered "centered" vs "split".
|
|
261
|
+
*/
|
|
262
|
+
interface BlockVariant {
|
|
263
|
+
/** Stable identifier stored on the block row as `variant`. */
|
|
264
|
+
slug: string;
|
|
265
|
+
/** Human-readable label shown in the variant switcher. Defaults to `slug`. */
|
|
266
|
+
label?: string;
|
|
267
|
+
/** Lucide icon name shown beside the variant label. */
|
|
268
|
+
icon?: AdminIconName;
|
|
269
|
+
/** Short one-line summary of what this variant looks like. */
|
|
270
|
+
description?: string;
|
|
271
|
+
}
|
|
272
|
+
interface FieldBase {
|
|
273
|
+
/** Stored key for this field. Omit only for layout-only fields such as `row` or `join`. */
|
|
274
|
+
name?: string;
|
|
275
|
+
/** Human-readable label shown in the Admin UI. */
|
|
276
|
+
label?: string;
|
|
277
|
+
/** Whether the field must have a value when saving. */
|
|
278
|
+
required?: boolean;
|
|
279
|
+
/** Whether values for this field must be unique across the collection. */
|
|
280
|
+
unique?: boolean;
|
|
281
|
+
/** Default value used when a new document omits this field. */
|
|
282
|
+
defaultValue?: unknown;
|
|
283
|
+
/** Static or dynamic option source for supported selection fields. */
|
|
284
|
+
options?: string[] | {
|
|
285
|
+
label: string;
|
|
286
|
+
value: unknown;
|
|
287
|
+
}[] | DynamicOptionsResolver | DynamicOptionsConfig;
|
|
288
|
+
/** Target collection slug for `relationship` fields. */
|
|
289
|
+
relationTo?: string;
|
|
290
|
+
/** Whether the field stores multiple values instead of one. */
|
|
291
|
+
hasMany?: boolean;
|
|
292
|
+
/** Child fields for `object` and `array` field types. */
|
|
293
|
+
fields?: Field[];
|
|
294
|
+
/** Allowed block definitions for a `blocks` field. */
|
|
295
|
+
blocks?: Block[];
|
|
296
|
+
/** Target collection slug for `join` fields. */
|
|
297
|
+
collection?: string;
|
|
298
|
+
/** Back-reference field name on the joined collection. */
|
|
299
|
+
on?: string;
|
|
300
|
+
/** Maximum number of joined documents returned by a `join` field. */
|
|
301
|
+
limit?: number;
|
|
302
|
+
/** Field-level read and update access rules. */
|
|
303
|
+
access?: {
|
|
304
|
+
/** Controls whether this field is returned in API responses. */
|
|
305
|
+
read?: AccessFunction | string;
|
|
306
|
+
/** Controls whether incoming writes may change this field. */
|
|
307
|
+
update?: AccessFunction | string;
|
|
308
|
+
};
|
|
309
|
+
/** Admin-only presentation options for this field. */
|
|
310
|
+
admin?: BaseFieldAdmin;
|
|
311
|
+
/** Previous storage key to migrate from during schema sync. */
|
|
312
|
+
renameTo?: string;
|
|
313
|
+
/** Whether SQL adapters should promote this field into a first-class column. */
|
|
314
|
+
promoted?: boolean;
|
|
315
|
+
}
|
|
316
|
+
interface BaseFieldAdmin {
|
|
317
|
+
/** Placeholder text shown when the input has no value. */
|
|
318
|
+
placeholder?: string;
|
|
319
|
+
/** Custom component key registered in the Admin UI. */
|
|
320
|
+
component?: string;
|
|
321
|
+
/** Help text rendered below the field. */
|
|
322
|
+
description?: string;
|
|
323
|
+
/** Hides the field from the Admin form without deleting stored data. */
|
|
324
|
+
hidden?: boolean;
|
|
325
|
+
/** Excludes the field from Admin list filtering. */
|
|
326
|
+
filterable?: boolean;
|
|
327
|
+
/** Renders the field as non-editable in the Admin UI. */
|
|
328
|
+
readOnly?: boolean;
|
|
329
|
+
/** Reactive condition controlling whether the field is visible in the Admin UI. */
|
|
330
|
+
condition?: ((data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean) | string;
|
|
331
|
+
/** Tab name used when the edit form is rendered as tabs. */
|
|
332
|
+
tab?: string;
|
|
333
|
+
/** CSS width hint used when the field appears inside a `row`. */
|
|
334
|
+
width?: string;
|
|
335
|
+
}
|
|
336
|
+
interface FieldBeforeChangeHookArgs<TValue = unknown, TDoc extends object = Record<string, unknown>> {
|
|
337
|
+
/** Current field value after previous hooks in the chain. */
|
|
338
|
+
value: TValue;
|
|
339
|
+
/** Existing stored document before the write, if this is an update. */
|
|
340
|
+
originalDoc?: TDoc;
|
|
341
|
+
/** Full incoming payload being written. */
|
|
342
|
+
data: Record<string, unknown>;
|
|
343
|
+
/** Authenticated user performing the write, if any. */
|
|
344
|
+
user?: AuthenticatedUser;
|
|
345
|
+
/** Read-only database adapter for related lookups. */
|
|
346
|
+
db: ReadonlyDatabaseAdapter;
|
|
347
|
+
}
|
|
348
|
+
type FieldBeforeChangeHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: FieldBeforeChangeHookArgs<TValue, TDoc>) => unknown;
|
|
349
|
+
interface FieldAfterReadHookArgs<TValue = unknown, TDoc extends object = Record<string, unknown>> {
|
|
350
|
+
/** Raw stored field value before this hook transforms it. */
|
|
351
|
+
value: TValue;
|
|
352
|
+
/** Full document currently being returned to the caller. */
|
|
353
|
+
doc: TDoc;
|
|
354
|
+
/** Authenticated user requesting the document, if any. */
|
|
355
|
+
user?: AuthenticatedUser;
|
|
356
|
+
/** Read-only database adapter for related lookups. */
|
|
357
|
+
db: ReadonlyDatabaseAdapter;
|
|
358
|
+
}
|
|
359
|
+
type FieldAfterReadHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: FieldAfterReadHookArgs<TValue, TDoc>) => unknown;
|
|
360
|
+
type FieldHooks<TValue> = {
|
|
361
|
+
hooks?: {
|
|
362
|
+
beforeChange?: Array<FieldBeforeChangeHook<TValue>>;
|
|
363
|
+
afterRead?: Array<FieldAfterReadHook<TValue>>;
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
interface FieldAdminOnChangeHookArgs<TValue = unknown> {
|
|
367
|
+
/** Current field value in the form state. */
|
|
368
|
+
value: TValue;
|
|
369
|
+
/** Current values for sibling fields at the same nesting level. */
|
|
370
|
+
siblingData: Record<string, unknown>;
|
|
371
|
+
/** Current values for the entire form. */
|
|
372
|
+
data: Record<string, unknown>;
|
|
373
|
+
/** Imperative setter for async or derived updates. */
|
|
374
|
+
setValue: (value: unknown) => void;
|
|
375
|
+
}
|
|
376
|
+
type FieldAdminOnChangeHook<TValue = unknown> = (args: FieldAdminOnChangeHookArgs<TValue>) => unknown;
|
|
377
|
+
type FieldAdminHooks<TValue> = {
|
|
378
|
+
admin?: {
|
|
379
|
+
hooks?: {
|
|
380
|
+
onChange?: FieldAdminOnChangeHook<TValue>;
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
interface FieldAdminOptionsHookArgs {
|
|
385
|
+
/** Current values for sibling fields at the same nesting level. */
|
|
386
|
+
siblingData: Record<string, unknown>;
|
|
387
|
+
/** Current values for the entire form. */
|
|
388
|
+
data: Record<string, unknown>;
|
|
389
|
+
}
|
|
390
|
+
type FieldAdminOptionsHookResult = Array<string | {
|
|
391
|
+
label: string;
|
|
392
|
+
value: unknown;
|
|
393
|
+
}>;
|
|
394
|
+
type FieldAdminOptionsHook = (args: FieldAdminOptionsHookArgs) => FieldAdminOptionsHookResult | Promise<FieldAdminOptionsHookResult>;
|
|
395
|
+
type TypedField<TType extends FieldType, TValue, TAdminExtra = Record<never, never>> = Omit<FieldBase, "admin"> & {
|
|
396
|
+
type: TType;
|
|
397
|
+
admin?: BaseFieldAdmin & TAdminExtra;
|
|
398
|
+
} & FieldHooks<TValue> & FieldAdminHooks<TValue>;
|
|
399
|
+
type BooleanFieldAdmin = {
|
|
400
|
+
/** Boolean presentation style. */
|
|
401
|
+
layout?: "checkbox" | "switch";
|
|
402
|
+
};
|
|
403
|
+
type SelectFieldAdmin = {
|
|
404
|
+
/** Select presentation style. */
|
|
405
|
+
layout?: "radio" | "select";
|
|
406
|
+
/** Radio orientation when `layout: 'radio'` is used. */
|
|
407
|
+
direction?: "horizontal" | "vertical";
|
|
408
|
+
hooks?: {
|
|
409
|
+
/** Client-side option recalculation for dependent dropdowns or radios. */
|
|
410
|
+
options?: FieldAdminOptionsHook;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
type RadioFieldAdmin = {
|
|
414
|
+
/** Radio group orientation. */
|
|
415
|
+
direction?: "horizontal" | "vertical";
|
|
416
|
+
hooks?: {
|
|
417
|
+
/** Client-side option recalculation for dependent radio groups. */
|
|
418
|
+
options?: FieldAdminOptionsHook;
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
type MultiSelectFieldAdmin = {
|
|
422
|
+
hooks?: {
|
|
423
|
+
/** Client-side option recalculation for dependent multi-select fields. */
|
|
424
|
+
options?: FieldAdminOptionsHook;
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
interface CharacterLimitFieldConfig {
|
|
428
|
+
/** Advisory maximum character count exposed to editors and client tooling. */
|
|
429
|
+
maxLength?: number;
|
|
430
|
+
}
|
|
431
|
+
interface WordLimitFieldConfig {
|
|
432
|
+
/** Advisory maximum word count exposed to editors and client tooling. */
|
|
433
|
+
maxWords?: number;
|
|
434
|
+
}
|
|
435
|
+
type CharacterLimitFieldAdmin = {
|
|
436
|
+
/** Admin-only compatibility alias for `field.maxLength`. Prefer the top-level field property. */
|
|
437
|
+
maxLength?: number;
|
|
438
|
+
};
|
|
439
|
+
type WordLimitFieldAdmin = {
|
|
440
|
+
/** Admin-only compatibility alias for `field.maxWords`. Prefer the top-level field property. */
|
|
441
|
+
maxWords?: number;
|
|
442
|
+
};
|
|
443
|
+
type TextFieldAdmin = CharacterLimitFieldAdmin & WordLimitFieldAdmin;
|
|
444
|
+
type TextareaFieldAdmin = CharacterLimitFieldAdmin & WordLimitFieldAdmin;
|
|
445
|
+
type EmailFieldAdmin = CharacterLimitFieldAdmin;
|
|
446
|
+
type UrlFieldAdmin = CharacterLimitFieldAdmin;
|
|
447
|
+
type IconFieldAdmin = CharacterLimitFieldAdmin;
|
|
448
|
+
type TextField = TypedField<"text", string, TextFieldAdmin> & CharacterLimitFieldConfig & WordLimitFieldConfig;
|
|
449
|
+
type TextareaField = TypedField<"textarea", string, TextareaFieldAdmin> & CharacterLimitFieldConfig & WordLimitFieldConfig;
|
|
450
|
+
type EmailField = TypedField<"email", string, EmailFieldAdmin> & CharacterLimitFieldConfig;
|
|
451
|
+
type UrlField = TypedField<"url", string, UrlFieldAdmin> & CharacterLimitFieldConfig;
|
|
452
|
+
type IconField = TypedField<"icon", string, IconFieldAdmin> & CharacterLimitFieldConfig;
|
|
453
|
+
type DateField = TypedField<"date", string>;
|
|
454
|
+
type DateTimeField = TypedField<"datetime", string>;
|
|
455
|
+
type TimeField = TypedField<"time", string>;
|
|
456
|
+
type SelectField = TypedField<"select", string, SelectFieldAdmin>;
|
|
457
|
+
type RadioField = TypedField<"radio", string, RadioFieldAdmin>;
|
|
458
|
+
type NumberField = TypedField<"number", number>;
|
|
459
|
+
type BooleanField = TypedField<"boolean", boolean, BooleanFieldAdmin>;
|
|
460
|
+
type MultiSelectField = TypedField<"multiSelect", string[], MultiSelectFieldAdmin>;
|
|
461
|
+
type RelationshipField = TypedField<"relationship", string | string[]>;
|
|
462
|
+
type ImageField = TypedField<"image", string | string[]>;
|
|
463
|
+
type RichTextField = TypedField<"richText", Record<string, unknown>>;
|
|
464
|
+
type JsonField = TypedField<"json", Record<string, unknown>>;
|
|
465
|
+
type ObjectField = TypedField<"object", unknown>;
|
|
466
|
+
type ArrayField = TypedField<"array", unknown>;
|
|
467
|
+
type BlocksField = TypedField<"blocks", unknown>;
|
|
468
|
+
type JoinField = TypedField<"join", unknown>;
|
|
469
|
+
type RowField = TypedField<"row", unknown>;
|
|
470
|
+
type Field = TextField | TextareaField | EmailField | UrlField | IconField | DateField | DateTimeField | TimeField | SelectField | RadioField | NumberField | BooleanField | MultiSelectField | RelationshipField | ImageField | RichTextField | JsonField | ObjectField | ArrayField | BlocksField | JoinField | RowField;
|
|
471
|
+
interface UploadConfig {
|
|
472
|
+
/** Allowed MIME types for uploaded files. */
|
|
473
|
+
allowedMimeTypes?: string[];
|
|
474
|
+
/** Maximum upload size in bytes. */
|
|
475
|
+
maxFileSize?: number;
|
|
476
|
+
/** Local filesystem destination used by disk-based storage adapters. */
|
|
477
|
+
staticDir?: string;
|
|
478
|
+
/** Public URL prefix for disk-based uploads. */
|
|
479
|
+
staticURL?: string;
|
|
480
|
+
/** Generated image size name used as the Admin media thumbnail. */
|
|
481
|
+
adminThumbnail?: string;
|
|
482
|
+
imageSizes?: {
|
|
483
|
+
/** Stable name used to reference this generated size. */
|
|
484
|
+
name: string;
|
|
485
|
+
/** Target width in pixels. */
|
|
486
|
+
width?: number;
|
|
487
|
+
/** Target height in pixels. */
|
|
488
|
+
height?: number;
|
|
489
|
+
/** Crop strategy forwarded to the image processor. */
|
|
490
|
+
crop?: string;
|
|
491
|
+
/** Resize fit strategy forwarded to the image processor. */
|
|
492
|
+
fit?: string;
|
|
493
|
+
/** Prevents upscaling smaller source images. */
|
|
494
|
+
withoutEnlargement?: boolean;
|
|
495
|
+
/** Format-specific options forwarded to the image processor. */
|
|
496
|
+
formatOptions?: Record<string, unknown>;
|
|
497
|
+
}[];
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @deprecated Use {@link FieldBeforeChangeHook} or `FieldAfterReadHook` instead.
|
|
502
|
+
* This alias remains for backwards compatibility.
|
|
503
|
+
*/
|
|
504
|
+
type FieldHook<TDoc extends object = Record<string, unknown>, TValue = unknown> = FieldBeforeChangeHook<TValue, TDoc>;
|
|
505
|
+
/**
|
|
506
|
+
* Runs before Dyrected queries the database for a list or single-document fetch.
|
|
507
|
+
*
|
|
508
|
+
* Return a new `where` query object to override or extend the current filter.
|
|
509
|
+
* Return `undefined` (or nothing) to leave the query unchanged.
|
|
510
|
+
*/
|
|
511
|
+
type CollectionBeforeReadHook = (args: {
|
|
512
|
+
req: HookRequestContext;
|
|
513
|
+
query?: Record<string, unknown>;
|
|
514
|
+
user?: AuthenticatedUser;
|
|
515
|
+
db: ReadonlyDatabaseAdapter;
|
|
516
|
+
}) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
|
|
517
|
+
/**
|
|
518
|
+
* Runs after a document (or list of documents) is fetched from the database,
|
|
519
|
+
* before the response is sent to the client.
|
|
520
|
+
*/
|
|
521
|
+
type CollectionAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
522
|
+
doc: TDoc;
|
|
523
|
+
req: HookRequestContext;
|
|
524
|
+
user?: AuthenticatedUser;
|
|
525
|
+
db: ReadonlyDatabaseAdapter;
|
|
526
|
+
}) => TDoc | Promise<TDoc>;
|
|
527
|
+
/**
|
|
528
|
+
* Runs **before** a document is created or updated in the database.
|
|
529
|
+
*/
|
|
530
|
+
type CollectionBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
531
|
+
data: Partial<TDoc>;
|
|
532
|
+
doc?: TDoc;
|
|
533
|
+
req: HookRequestContext;
|
|
534
|
+
user?: AuthenticatedUser;
|
|
535
|
+
operation: "create" | "update";
|
|
536
|
+
db: ReadonlyDatabaseAdapter;
|
|
537
|
+
}) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
|
|
538
|
+
/**
|
|
539
|
+
* Runs **after** a document is created or updated in the database.
|
|
540
|
+
*/
|
|
541
|
+
type CollectionAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
542
|
+
doc: TDoc;
|
|
543
|
+
previousDoc?: TDoc;
|
|
544
|
+
req: HookRequestContext;
|
|
545
|
+
user?: AuthenticatedUser;
|
|
546
|
+
operation: "create" | "update";
|
|
547
|
+
db: DatabaseAdapter;
|
|
548
|
+
}) => void | Promise<void>;
|
|
549
|
+
/**
|
|
550
|
+
* Runs **before** a document is deleted from the database.
|
|
551
|
+
*/
|
|
552
|
+
type CollectionBeforeDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
553
|
+
id: string;
|
|
554
|
+
doc: TDoc;
|
|
555
|
+
req: HookRequestContext;
|
|
556
|
+
user?: AuthenticatedUser;
|
|
557
|
+
db: ReadonlyDatabaseAdapter;
|
|
558
|
+
}) => void | Promise<void>;
|
|
559
|
+
/**
|
|
560
|
+
* Runs **after** a document has been deleted from the database.
|
|
561
|
+
*/
|
|
562
|
+
type CollectionAfterDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
563
|
+
id: string;
|
|
564
|
+
doc: TDoc;
|
|
565
|
+
req: HookRequestContext;
|
|
566
|
+
user?: AuthenticatedUser;
|
|
567
|
+
db: DatabaseAdapter;
|
|
568
|
+
}) => void | Promise<void>;
|
|
569
|
+
/** @see {@link CollectionBeforeReadHook} */
|
|
570
|
+
type GlobalBeforeReadHook = CollectionBeforeReadHook;
|
|
571
|
+
/**
|
|
572
|
+
* Runs after the global document is fetched, before the response is sent.
|
|
573
|
+
*/
|
|
574
|
+
type GlobalAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
575
|
+
doc: TDoc;
|
|
576
|
+
req: HookRequestContext;
|
|
577
|
+
user?: AuthenticatedUser;
|
|
578
|
+
db: ReadonlyDatabaseAdapter;
|
|
579
|
+
}) => TDoc | Promise<TDoc>;
|
|
580
|
+
/**
|
|
581
|
+
* Runs before the global document is updated.
|
|
582
|
+
* Operation is always `'update'` (globals cannot be created or deleted).
|
|
583
|
+
*/
|
|
584
|
+
type GlobalBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
585
|
+
data: Partial<TDoc>;
|
|
586
|
+
doc?: TDoc;
|
|
587
|
+
req: HookRequestContext;
|
|
588
|
+
user?: AuthenticatedUser;
|
|
589
|
+
operation: "update";
|
|
590
|
+
db: ReadonlyDatabaseAdapter;
|
|
591
|
+
}) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
|
|
592
|
+
/**
|
|
593
|
+
* Runs after the global document is updated. Side-effects only.
|
|
594
|
+
*/
|
|
595
|
+
type GlobalAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
|
|
596
|
+
doc: TDoc;
|
|
597
|
+
previousDoc?: TDoc;
|
|
598
|
+
req: HookRequestContext;
|
|
599
|
+
user?: AuthenticatedUser;
|
|
600
|
+
operation: "update";
|
|
601
|
+
db: DatabaseAdapter;
|
|
602
|
+
}) => void | Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* @deprecated Use the specific hook types instead:
|
|
605
|
+
* `CollectionBeforeChangeHook`, `CollectionAfterReadHook`, etc.
|
|
606
|
+
*
|
|
607
|
+
* This broad type remains for backwards compatibility with the internal hook runner.
|
|
608
|
+
*/
|
|
609
|
+
type HookFunction<TDoc extends object = Record<string, unknown>> = (args: {
|
|
610
|
+
data?: Partial<TDoc>;
|
|
611
|
+
doc?: TDoc;
|
|
612
|
+
user?: AuthenticatedUser;
|
|
613
|
+
req?: HookRequestContext;
|
|
614
|
+
operation?: "create" | "update" | "delete";
|
|
615
|
+
db?: DatabaseAdapter;
|
|
616
|
+
[key: string]: unknown;
|
|
617
|
+
}) => unknown | Promise<unknown>;
|
|
618
|
+
|
|
619
|
+
declare const LIFECYCLE_EVENT_NAMES: readonly ["revision.created", "workflow.transitioned", "entry.published", "entry.unpublished"];
|
|
620
|
+
type LifecycleEventName = (typeof LIFECYCLE_EVENT_NAMES)[number];
|
|
621
|
+
interface WorkflowState {
|
|
622
|
+
/** Stable machine-readable state key. */
|
|
623
|
+
name: string;
|
|
624
|
+
/** Label rendered in the Admin UI. */
|
|
625
|
+
label: string;
|
|
626
|
+
/** Marks the state whose revision is visible to public readers. */
|
|
627
|
+
published?: boolean;
|
|
628
|
+
/** Optional visual tone used by the Admin UI. */
|
|
629
|
+
color?: "neutral" | "warning" | "success" | "danger" | "info";
|
|
630
|
+
}
|
|
631
|
+
interface WorkflowTransition {
|
|
632
|
+
/** Stable transition key used by the REST and SDK APIs. */
|
|
633
|
+
name: string;
|
|
634
|
+
label: string;
|
|
635
|
+
from: string | string[];
|
|
636
|
+
to: string;
|
|
637
|
+
/** Every listed capability is required. */
|
|
638
|
+
requiredCapabilities?: string[];
|
|
639
|
+
/** Require a non-empty comment when performing the transition. */
|
|
640
|
+
requireComment?: boolean;
|
|
641
|
+
/** Remove the public snapshot after this transition commits. */
|
|
642
|
+
unpublish?: boolean;
|
|
643
|
+
}
|
|
644
|
+
interface WorkflowRole {
|
|
645
|
+
/** Existing user role value, for example `editor` or `publisher`. */
|
|
646
|
+
role: string;
|
|
647
|
+
capabilities: string[];
|
|
648
|
+
}
|
|
649
|
+
interface WorkflowConfig<TDoc extends object = Record<string, unknown>> {
|
|
650
|
+
initialState: string;
|
|
651
|
+
/** State used for a new working revision created from published content. */
|
|
652
|
+
draftState?: string;
|
|
653
|
+
states: WorkflowState[];
|
|
654
|
+
transitions: WorkflowTransition[];
|
|
655
|
+
/** Maps values in `user.roles` to workflow capabilities. */
|
|
656
|
+
roles?: WorkflowRole[];
|
|
657
|
+
hooks?: {
|
|
658
|
+
beforeTransition?: CollectionBeforeTransitionHook<TDoc>[];
|
|
659
|
+
afterTransition?: CollectionAfterTransitionHook<TDoc>[];
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
interface WorkflowMetadata {
|
|
663
|
+
state: string;
|
|
664
|
+
revision: number;
|
|
665
|
+
publishedRevision?: number;
|
|
666
|
+
publishedAt?: string;
|
|
667
|
+
publishedBy?: string;
|
|
668
|
+
/** Transitions currently allowed for the requesting user. Response-only. */
|
|
669
|
+
availableTransitions?: string[];
|
|
670
|
+
}
|
|
671
|
+
interface WorkflowTransitionContext<TDoc extends object = Record<string, unknown>> {
|
|
672
|
+
transition: WorkflowTransition;
|
|
673
|
+
from: string;
|
|
674
|
+
to: string;
|
|
675
|
+
doc: TDoc;
|
|
676
|
+
user?: AuthenticatedUser;
|
|
677
|
+
comment?: string;
|
|
678
|
+
req: HookRequestContext;
|
|
679
|
+
db: DatabaseAdapter;
|
|
680
|
+
}
|
|
681
|
+
type CollectionBeforeTransitionHook<TDoc extends object = Record<string, unknown>> = (args: WorkflowTransitionContext<TDoc>) => void | Promise<void>;
|
|
682
|
+
type CollectionAfterTransitionHook<TDoc extends object = Record<string, unknown>> = (args: WorkflowTransitionContext<TDoc> & {
|
|
683
|
+
event: LifecycleEvent;
|
|
684
|
+
}) => void | Promise<void>;
|
|
685
|
+
interface LifecycleEvent<TPayload = Record<string, unknown>> {
|
|
686
|
+
id: string;
|
|
687
|
+
name: LifecycleEventName;
|
|
688
|
+
collection: string;
|
|
689
|
+
documentId: string;
|
|
690
|
+
occurredAt: string;
|
|
691
|
+
actorId?: string;
|
|
692
|
+
payload: TPayload;
|
|
693
|
+
attempts: number;
|
|
694
|
+
status: "pending" | "processing" | "delivered" | "failed";
|
|
695
|
+
nextAttemptAt?: string;
|
|
696
|
+
deliveredAt?: string;
|
|
697
|
+
lastError?: string;
|
|
698
|
+
}
|
|
699
|
+
type LifecycleEventHandler = (event: LifecycleEvent) => void | Promise<void>;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Defines a Dyrected collection — a named set of documents with a shared schema.
|
|
703
|
+
*
|
|
704
|
+
* Pass your document's TypeScript type as the generic parameter `TDoc` to get
|
|
705
|
+
* fully typed hooks and access functions.
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* interface Post {
|
|
710
|
+
* id: string
|
|
711
|
+
* title: string
|
|
712
|
+
* slug: string
|
|
713
|
+
* status: 'draft' | 'published'
|
|
714
|
+
* publishedAt?: string
|
|
715
|
+
* }
|
|
716
|
+
*
|
|
717
|
+
* export const Posts = defineCollection<Post>({
|
|
718
|
+
* slug: 'posts',
|
|
719
|
+
* hooks: {
|
|
720
|
+
* beforeChange: [({ data, operation }) => {
|
|
721
|
+
* // `data` is typed as Partial<Post>
|
|
722
|
+
* if (operation === 'create') return { ...data, status: 'draft' }
|
|
723
|
+
* return data
|
|
724
|
+
* }],
|
|
725
|
+
* afterChange: [({ doc, previousDoc }) => {
|
|
726
|
+
* // `doc` and `previousDoc` are typed as Post
|
|
727
|
+
* if (doc.status !== previousDoc?.status) notifySubscribers(doc)
|
|
728
|
+
* }],
|
|
729
|
+
* },
|
|
730
|
+
* fields: [...],
|
|
731
|
+
* })
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* @template TDoc The TypeScript shape of a document in this collection.
|
|
735
|
+
* Defaults to `Record<string, unknown>` for untyped usage.
|
|
736
|
+
*/
|
|
737
|
+
interface CollectionConfig<TDoc extends object = Record<string, unknown>> {
|
|
738
|
+
/**
|
|
739
|
+
* Unique identifier for this collection.
|
|
740
|
+
* Used as the URL segment (`/api/collections/:slug`) and the database table/collection name.
|
|
741
|
+
* Use kebab-case, e.g. `'blog-posts'`.
|
|
742
|
+
*/
|
|
743
|
+
slug: string;
|
|
744
|
+
/**
|
|
745
|
+
* Restricts this collection to a specific site in a multi-tenant deployment.
|
|
746
|
+
* When set, only requests bearing a matching `X-Site-Id` header can access it.
|
|
747
|
+
*/
|
|
748
|
+
siteId?: string;
|
|
749
|
+
/**
|
|
750
|
+
* If `true`, this collection is shared across all sites in a multi-tenant
|
|
751
|
+
* deployment and accessible regardless of the `X-Site-Id` header.
|
|
752
|
+
*/
|
|
753
|
+
shared?: boolean;
|
|
754
|
+
/** Human-readable names for documents in this collection, shown in the Admin UI. */
|
|
755
|
+
labels?: {
|
|
756
|
+
singular: string;
|
|
757
|
+
plural: string;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* If `true`, this collection is an auth collection. It gains
|
|
761
|
+
* `POST /api/collections/:slug/login` and `POST /api/collections/:slug/logout`
|
|
762
|
+
* endpoints, and documents are expected to have a `password` field.
|
|
763
|
+
*/
|
|
764
|
+
auth?: boolean;
|
|
765
|
+
/**
|
|
766
|
+
* If `true` or a config object, this collection supports file uploads.
|
|
767
|
+
* Documents gain file-related fields (`url`, `filename`, `mimeType`, etc.)
|
|
768
|
+
* and the create endpoint accepts `multipart/form-data`.
|
|
769
|
+
*/
|
|
770
|
+
upload?: boolean | UploadConfig;
|
|
771
|
+
/** Field definitions that make up the document schema for this collection. */
|
|
772
|
+
fields: Field[];
|
|
773
|
+
/**
|
|
774
|
+
* If `true`, Dyrected automatically adds `createdAt` and `updatedAt`
|
|
775
|
+
* timestamp fields to every document. Defaults to `true`.
|
|
776
|
+
*/
|
|
777
|
+
timestamps?: boolean;
|
|
778
|
+
/**
|
|
779
|
+
* Initial documents to seed into this collection the first time it is
|
|
780
|
+
* fetched and found to be empty, for example demo data or defaults.
|
|
781
|
+
*/
|
|
782
|
+
initialData?: Partial<TDoc>[];
|
|
783
|
+
/**
|
|
784
|
+
* If `true`, every create, update, and delete operation on this collection
|
|
785
|
+
* is logged to the `__audit` collection with before/after snapshots and the
|
|
786
|
+
* acting user's identity.
|
|
787
|
+
*/
|
|
788
|
+
audit?: boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Optional state-machine workflow for this collection. Workflow-enabled
|
|
791
|
+
* entries keep an editable working revision and an independent public
|
|
792
|
+
* snapshot, so editing published content never changes the live response.
|
|
793
|
+
*/
|
|
794
|
+
workflow?: WorkflowConfig<TDoc>;
|
|
795
|
+
/**
|
|
796
|
+
* Collection-level access control.
|
|
797
|
+
*
|
|
798
|
+
* Each key is an operation; the value is a function or Jexl string that
|
|
799
|
+
* returns `true` to allow or `false` to deny. Returning a `where`-style
|
|
800
|
+
* object grants access only to matching documents.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* access: {
|
|
804
|
+
* read: () => true,
|
|
805
|
+
* create: ({ user }) => !!user,
|
|
806
|
+
* update: ({ user }) => user?.roles?.includes('editor') ?? false,
|
|
807
|
+
* delete: ({ user }) => user?.roles?.includes('admin') ?? false,
|
|
808
|
+
* }
|
|
809
|
+
*/
|
|
810
|
+
access?: {
|
|
811
|
+
read?: AccessFunction<TDoc> | string;
|
|
812
|
+
create?: AccessFunction<TDoc> | string;
|
|
813
|
+
update?: AccessFunction<TDoc> | string;
|
|
814
|
+
delete?: AccessFunction<TDoc> | string;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Collection-level lifecycle hooks.
|
|
818
|
+
*
|
|
819
|
+
* Hooks run in the order they appear in the array. The return value of each
|
|
820
|
+
* hook is passed as the input to the next. Throwing inside any hook aborts
|
|
821
|
+
* the operation and returns a `500` error.
|
|
822
|
+
*
|
|
823
|
+
* See the Hooks reference for the full lifecycle diagram.
|
|
824
|
+
*/
|
|
825
|
+
hooks?: {
|
|
826
|
+
/**
|
|
827
|
+
* Runs before the database is queried. Return a modified `where` object
|
|
828
|
+
* to override the query filter.
|
|
829
|
+
*/
|
|
830
|
+
beforeRead?: CollectionBeforeReadHook[];
|
|
831
|
+
/**
|
|
832
|
+
* Runs after documents are fetched. Return a modified doc to change what
|
|
833
|
+
* the client receives. Runs on every document in a list response.
|
|
834
|
+
*/
|
|
835
|
+
afterRead?: CollectionAfterReadHook<TDoc>[];
|
|
836
|
+
/**
|
|
837
|
+
* Runs before create or update. Return modified data to change what is
|
|
838
|
+
* written to the database. Throw to abort the write entirely.
|
|
839
|
+
*/
|
|
840
|
+
beforeChange?: CollectionBeforeChangeHook<TDoc>[];
|
|
841
|
+
/**
|
|
842
|
+
* Runs after create or update is committed. For side-effects only:
|
|
843
|
+
* webhooks, cache busting, and notifications. Return value is ignored.
|
|
844
|
+
*
|
|
845
|
+
* Errors are isolated: caught, logged, and discarded so a failing
|
|
846
|
+
* side-effect never turns a successful write into an HTTP 500.
|
|
847
|
+
* See `CollectionAfterChangeHook` for await-vs-fire-and-forget guidance.
|
|
848
|
+
*/
|
|
849
|
+
afterChange?: CollectionAfterChangeHook<TDoc>[];
|
|
850
|
+
/** Runs before a document is deleted. Throw to cancel the deletion. */
|
|
851
|
+
beforeDelete?: CollectionBeforeDeleteHook<TDoc>[];
|
|
852
|
+
/**
|
|
853
|
+
* Runs after a document has been deleted. For cleanup side-effects only.
|
|
854
|
+
*
|
|
855
|
+
* Errors are isolated: caught, logged, and discarded. The deletion is
|
|
856
|
+
* already committed and will not be undone.
|
|
857
|
+
*/
|
|
858
|
+
afterDelete?: CollectionAfterDeleteHook<TDoc>[];
|
|
859
|
+
};
|
|
860
|
+
/** Admin UI configuration for this collection. */
|
|
861
|
+
admin?: {
|
|
862
|
+
/**
|
|
863
|
+
* Lucide icon displayed beside this collection in the Admin sidebar.
|
|
864
|
+
* Uses Lucide component names, e.g. `'Newspaper'` or `'ShoppingBag'`.
|
|
865
|
+
*/
|
|
866
|
+
icon?: AdminIconName;
|
|
867
|
+
/** Custom component slots for this collection's list view. */
|
|
868
|
+
components?: CollectionListComponentSlots;
|
|
869
|
+
/**
|
|
870
|
+
* The field name used as the document's display title in the Admin list
|
|
871
|
+
* view and breadcrumbs. Defaults to `'title'` if the field exists.
|
|
872
|
+
*/
|
|
873
|
+
useAsTitle?: string;
|
|
874
|
+
/**
|
|
875
|
+
* Field names to show as columns in the Admin list view.
|
|
876
|
+
* Defaults to a sensible set of the first few non-structural fields.
|
|
877
|
+
*/
|
|
878
|
+
defaultColumns?: string[];
|
|
879
|
+
/**
|
|
880
|
+
* Groups this collection under a named section in the Admin sidebar.
|
|
881
|
+
* Collections with the same `group` are visually grouped together.
|
|
882
|
+
*/
|
|
883
|
+
group?: string;
|
|
884
|
+
/** If `true`, this collection is not shown in the Admin UI sidebar. */
|
|
885
|
+
hidden?: boolean;
|
|
886
|
+
/** If `false`, disables the filter UI entirely for this collection. Defaults to `true`. */
|
|
887
|
+
filterable?: boolean;
|
|
888
|
+
/**
|
|
889
|
+
* URL to open in the Live Preview pane when editing a document.
|
|
890
|
+
* Pass a function to derive the URL from the document's fields.
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* previewUrl: (doc) => `https://mysite.com/blog/${doc.slug}`
|
|
894
|
+
*/
|
|
895
|
+
previewUrl?: string | ((doc: TDoc, opts: {
|
|
896
|
+
locale?: string;
|
|
897
|
+
}) => string | null);
|
|
898
|
+
/**
|
|
899
|
+
* How the Live Preview pane communicates with the frontend.
|
|
900
|
+
* - `postMessage` sends a `postMessage` with the current doc data.
|
|
901
|
+
* - `token` passes a short-lived preview token as a query parameter.
|
|
902
|
+
*/
|
|
903
|
+
previewMode?: "postMessage" | "token";
|
|
904
|
+
/**
|
|
905
|
+
* Frontend URL pattern for this collection, used by `url` fields to
|
|
906
|
+
* resolve internal links. Use `{fieldName}` placeholders.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* urlPattern: '/blog/{slug}' // /blog/my-post
|
|
910
|
+
* urlPattern: '/{slug}' // /about
|
|
911
|
+
*/
|
|
912
|
+
urlPattern?: string;
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Defines a Dyrected global — a singleton document without pagination or IDs.
|
|
917
|
+
*
|
|
918
|
+
* Globals are ideal for site-wide settings, feature flags, or any data where
|
|
919
|
+
* there is always exactly one record, such as `site-settings`, `navigation`,
|
|
920
|
+
* or `theme`.
|
|
921
|
+
*
|
|
922
|
+
* Pass your document's TypeScript type as the generic parameter `TDoc` to get
|
|
923
|
+
* fully typed hooks.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```ts
|
|
927
|
+
* interface SiteSettings {
|
|
928
|
+
* siteName: string
|
|
929
|
+
* tagline: string
|
|
930
|
+
* maintenanceMode: boolean
|
|
931
|
+
* }
|
|
932
|
+
*
|
|
933
|
+
* export const Settings = defineGlobal<SiteSettings>({
|
|
934
|
+
* slug: 'site-settings',
|
|
935
|
+
* hooks: {
|
|
936
|
+
* afterChange: [({ doc }) => {
|
|
937
|
+
* // `doc` is typed as SiteSettings
|
|
938
|
+
* if (doc.maintenanceMode) alertOnCall()
|
|
939
|
+
* }],
|
|
940
|
+
* },
|
|
941
|
+
* fields: [...],
|
|
942
|
+
* })
|
|
943
|
+
* ```
|
|
944
|
+
*
|
|
945
|
+
* @template TDoc The TypeScript shape of this global's document.
|
|
946
|
+
*/
|
|
947
|
+
interface GlobalConfig<TDoc extends object = Record<string, unknown>> {
|
|
948
|
+
/**
|
|
949
|
+
* Unique identifier for this global.
|
|
950
|
+
* Used as the URL segment (`/api/globals/:slug`) and the storage key.
|
|
951
|
+
*/
|
|
952
|
+
slug: string;
|
|
953
|
+
/** Restricts this global to a specific site in a multi-tenant deployment. */
|
|
954
|
+
siteId?: string;
|
|
955
|
+
/**
|
|
956
|
+
* If `true`, this global is shared across all sites in a multi-tenant
|
|
957
|
+
* deployment.
|
|
958
|
+
*/
|
|
959
|
+
shared?: boolean;
|
|
960
|
+
/** Human-readable label shown in the Admin UI sidebar. */
|
|
961
|
+
label?: string;
|
|
962
|
+
/** Field definitions for this global's document schema. */
|
|
963
|
+
fields: Field[];
|
|
964
|
+
/** Access control for reading and updating this global. */
|
|
965
|
+
access?: {
|
|
966
|
+
read?: AccessFunction<TDoc>;
|
|
967
|
+
update?: AccessFunction<TDoc>;
|
|
968
|
+
};
|
|
969
|
+
/**
|
|
970
|
+
* Global-level lifecycle hooks.
|
|
971
|
+
* Globals support `beforeRead`, `afterRead`, `beforeChange`, and `afterChange`.
|
|
972
|
+
* There are no delete hooks since globals cannot be deleted.
|
|
973
|
+
*/
|
|
974
|
+
hooks?: {
|
|
975
|
+
beforeRead?: GlobalBeforeReadHook[];
|
|
976
|
+
afterRead?: GlobalAfterReadHook<TDoc>[];
|
|
977
|
+
beforeChange?: GlobalBeforeChangeHook<TDoc>[];
|
|
978
|
+
afterChange?: GlobalAfterChangeHook<TDoc>[];
|
|
979
|
+
};
|
|
980
|
+
/** Admin UI configuration for this global. */
|
|
981
|
+
admin?: {
|
|
982
|
+
/**
|
|
983
|
+
* Lucide icon displayed beside this global in the Admin sidebar.
|
|
984
|
+
* Uses Lucide component names, e.g. `'Settings2'` or `'Palette'`.
|
|
985
|
+
*/
|
|
986
|
+
icon?: AdminIconName;
|
|
987
|
+
/** Groups this global under a named section in the Admin sidebar. */
|
|
988
|
+
group?: string;
|
|
989
|
+
/** If `true`, this global is not shown in the Admin UI sidebar. */
|
|
990
|
+
hidden?: boolean;
|
|
991
|
+
};
|
|
992
|
+
/**
|
|
993
|
+
* Initial data to seed this global with the first time it is fetched and
|
|
994
|
+
* found to be empty.
|
|
995
|
+
*/
|
|
996
|
+
initialData?: Partial<TDoc>;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* The interface every database adapter must implement.
|
|
1001
|
+
*
|
|
1002
|
+
* Dyrected ships adapters for PostgreSQL, MySQL, SQLite, and MongoDB.
|
|
1003
|
+
* Implement this interface to connect any other database.
|
|
1004
|
+
*/
|
|
1005
|
+
interface DatabaseAdapter {
|
|
1006
|
+
/** Find a paginated list of documents in a collection. */
|
|
1007
|
+
find(args: {
|
|
1008
|
+
collection: string;
|
|
1009
|
+
where?: Record<string, unknown>;
|
|
1010
|
+
limit?: number;
|
|
1011
|
+
page?: number;
|
|
1012
|
+
sort?: string;
|
|
1013
|
+
}): Promise<PaginatedResult>;
|
|
1014
|
+
/** Find a single document by its ID. Returns `null` if not found. */
|
|
1015
|
+
findOne(args: {
|
|
1016
|
+
collection: string;
|
|
1017
|
+
id: string;
|
|
1018
|
+
}): Promise<BaseDocument | null>;
|
|
1019
|
+
/** Insert a new document and return it with its generated `id`. */
|
|
1020
|
+
create(args: {
|
|
1021
|
+
collection: string;
|
|
1022
|
+
data: Record<string, unknown>;
|
|
1023
|
+
}): Promise<BaseDocument>;
|
|
1024
|
+
/** Update a document by ID and return the updated document. */
|
|
1025
|
+
update(args: {
|
|
1026
|
+
collection: string;
|
|
1027
|
+
id: string;
|
|
1028
|
+
data: Record<string, unknown>;
|
|
1029
|
+
}): Promise<BaseDocument>;
|
|
1030
|
+
/** Delete a document by ID. Return value is intentionally untyped — callers do not use it. */
|
|
1031
|
+
delete(args: {
|
|
1032
|
+
collection: string;
|
|
1033
|
+
id: string;
|
|
1034
|
+
}): Promise<unknown>;
|
|
1035
|
+
/** Fetch the singleton document for a global. Returns an empty object if not yet initialised. */
|
|
1036
|
+
getGlobal(args: {
|
|
1037
|
+
slug: string;
|
|
1038
|
+
}): Promise<Record<string, unknown>>;
|
|
1039
|
+
/** Create or replace the singleton document for a global. */
|
|
1040
|
+
updateGlobal(args: {
|
|
1041
|
+
slug: string;
|
|
1042
|
+
data: Record<string, unknown>;
|
|
1043
|
+
}): Promise<Record<string, unknown>>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Sync the database schema with the current collection and global configs.
|
|
1046
|
+
* Called on startup to create tables/collections that don't exist yet.
|
|
1047
|
+
* Not all adapters implement this (e.g. MongoDB is schema-less).
|
|
1048
|
+
*/
|
|
1049
|
+
sync?(collections: CollectionConfig[], globals: GlobalConfig[]): Promise<void>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Execute a raw SQL query or database command.
|
|
1052
|
+
* Optional — not all adapters support raw access.
|
|
1053
|
+
*/
|
|
1054
|
+
execute?(query: string, params?: unknown[]): Promise<unknown>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Run all adapter operations in `callback` as one atomic transaction.
|
|
1057
|
+
* Shipped adapters implement this; workflow transitions require it.
|
|
1058
|
+
*/
|
|
1059
|
+
transaction?<T>(callback: (db: DatabaseAdapter) => Promise<T>): Promise<T>;
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Read-only view of the database adapter. Exposes only `find`, `findOne`,
|
|
1063
|
+
* and `getGlobal` — no write operations.
|
|
1064
|
+
*
|
|
1065
|
+
* Passed to `beforeChange`, `beforeDelete`, `beforeRead`, `afterRead`,
|
|
1066
|
+
* and field-level hooks. Write operations are available in `afterChange`
|
|
1067
|
+
* and `afterDelete` hooks where the full {@link DatabaseAdapter} is provided.
|
|
1068
|
+
*/
|
|
1069
|
+
type ReadonlyDatabaseAdapter = Pick<DatabaseAdapter, "find" | "findOne" | "getGlobal">;
|
|
1070
|
+
/**
|
|
1071
|
+
* The interface every storage adapter must implement.
|
|
1072
|
+
*
|
|
1073
|
+
* Dyrected ships adapters for local disk, S3, Cloudflare R2, Cloudinary, and
|
|
1074
|
+
* Backblaze B2. Implement this interface to use any other storage provider.
|
|
1075
|
+
*/
|
|
1076
|
+
interface StorageAdapter {
|
|
1077
|
+
/**
|
|
1078
|
+
* Upload a file and return its metadata (URL, dimensions, etc.).
|
|
1079
|
+
* The `prefix` is a path prefix used for multi-tenant setups.
|
|
1080
|
+
*/
|
|
1081
|
+
upload(args: {
|
|
1082
|
+
filename: string;
|
|
1083
|
+
buffer: Uint8Array;
|
|
1084
|
+
mimeType: string;
|
|
1085
|
+
prefix?: string;
|
|
1086
|
+
}): Promise<FileData>;
|
|
1087
|
+
/** Delete a file by its stored filename. */
|
|
1088
|
+
delete(args: {
|
|
1089
|
+
filename: string;
|
|
1090
|
+
}): Promise<void>;
|
|
1091
|
+
/** Return the public URL for a stored file. */
|
|
1092
|
+
getURL(args: {
|
|
1093
|
+
filename: string;
|
|
1094
|
+
}): string;
|
|
1095
|
+
/**
|
|
1096
|
+
* Retrieve the file's raw bytes and MIME type for serving via the API.
|
|
1097
|
+
* Only needed by adapters that serve files through the Dyrected API
|
|
1098
|
+
* (e.g. `LocalStorage`). Cloud adapters return `null` here and rely on
|
|
1099
|
+
* direct CDN URLs instead.
|
|
1100
|
+
*/
|
|
1101
|
+
resolve?(args: {
|
|
1102
|
+
filename: string;
|
|
1103
|
+
}): Promise<{
|
|
1104
|
+
buffer: Uint8Array;
|
|
1105
|
+
mimeType: string;
|
|
1106
|
+
} | null>;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Processes uploaded images — generates metadata (dimensions, BlurHash) and
|
|
1110
|
+
* produces resized variants defined in `UploadConfig.imageSizes`.
|
|
1111
|
+
*
|
|
1112
|
+
* @example
|
|
1113
|
+
* import { SharpImageService } from '@dyrected/image-sharp'
|
|
1114
|
+
* defineConfig({ image: new SharpImageService(), ... })
|
|
1115
|
+
*/
|
|
1116
|
+
interface ImageService {
|
|
1117
|
+
process(args: {
|
|
1118
|
+
buffer: Uint8Array;
|
|
1119
|
+
mimeType: string;
|
|
1120
|
+
config?: boolean | UploadConfig;
|
|
1121
|
+
focalPoint?: {
|
|
1122
|
+
x: number;
|
|
1123
|
+
y: number;
|
|
1124
|
+
};
|
|
1125
|
+
}): Promise<{
|
|
1126
|
+
metadata: {
|
|
1127
|
+
width?: number;
|
|
1128
|
+
height?: number;
|
|
1129
|
+
/** Base64-encoded BlurHash for progressive loading. */
|
|
1130
|
+
blurhash?: string;
|
|
1131
|
+
};
|
|
1132
|
+
/** Generated image sizes keyed by their `name`. */
|
|
1133
|
+
sizes?: Record<string, {
|
|
1134
|
+
buffer: Uint8Array;
|
|
1135
|
+
width: number;
|
|
1136
|
+
height: number;
|
|
1137
|
+
filename: string;
|
|
1138
|
+
}>;
|
|
1139
|
+
}>;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
interface AdminAuthMember {
|
|
1143
|
+
id: string;
|
|
1144
|
+
email: string;
|
|
1145
|
+
name?: string;
|
|
1146
|
+
roles: string[];
|
|
1147
|
+
siteAccess?: string[];
|
|
1148
|
+
status?: "active" | "pending";
|
|
1149
|
+
[key: string]: any;
|
|
1150
|
+
}
|
|
1151
|
+
type AdminAuthProvisioningMode = "jit_only" | "jit_plus_membership_management" | "preprovisioned_only";
|
|
1152
|
+
interface AdminAuthClaimMapping {
|
|
1153
|
+
sub?: string;
|
|
1154
|
+
email?: string;
|
|
1155
|
+
name?: string;
|
|
1156
|
+
roles?: string;
|
|
1157
|
+
groups?: string;
|
|
1158
|
+
siteIds?: string;
|
|
1159
|
+
workspaceIds?: string;
|
|
1160
|
+
}
|
|
1161
|
+
interface AdminAuthResolvedIdentity {
|
|
1162
|
+
sub: string;
|
|
1163
|
+
email?: string;
|
|
1164
|
+
name?: string;
|
|
1165
|
+
roles?: string[];
|
|
1166
|
+
groups?: string[];
|
|
1167
|
+
siteIds?: string[];
|
|
1168
|
+
workspaceIds?: string[];
|
|
1169
|
+
rawClaims?: Record<string, unknown>;
|
|
1170
|
+
}
|
|
1171
|
+
interface AdminAuthAccessResolution {
|
|
1172
|
+
allowed: boolean;
|
|
1173
|
+
roles?: string[];
|
|
1174
|
+
data?: Record<string, unknown>;
|
|
1175
|
+
}
|
|
1176
|
+
interface AdminAuthResolveAccessArgs {
|
|
1177
|
+
identity: AdminAuthResolvedIdentity;
|
|
1178
|
+
providerId: string;
|
|
1179
|
+
siteId?: string;
|
|
1180
|
+
workspaceId?: string;
|
|
1181
|
+
req: {
|
|
1182
|
+
method: string;
|
|
1183
|
+
path: string;
|
|
1184
|
+
url: string;
|
|
1185
|
+
headers: Record<string, string | undefined>;
|
|
1186
|
+
};
|
|
1187
|
+
user: Record<string, unknown> | null;
|
|
1188
|
+
}
|
|
1189
|
+
interface AdminAuthProviderMembersConfig {
|
|
1190
|
+
list?: (args: {
|
|
1191
|
+
limit?: number;
|
|
1192
|
+
page?: number;
|
|
1193
|
+
sort?: string;
|
|
1194
|
+
where?: Record<string, any>;
|
|
1195
|
+
req: HookRequestContext;
|
|
1196
|
+
}) => Promise<{
|
|
1197
|
+
docs: AdminAuthMember[];
|
|
1198
|
+
totalDocs: number;
|
|
1199
|
+
limit: number;
|
|
1200
|
+
page: number;
|
|
1201
|
+
totalPages: number;
|
|
1202
|
+
hasNextPage: boolean;
|
|
1203
|
+
hasPrevPage: boolean;
|
|
1204
|
+
}>;
|
|
1205
|
+
get?: (args: {
|
|
1206
|
+
externalSubject: string;
|
|
1207
|
+
req: HookRequestContext;
|
|
1208
|
+
}) => Promise<AdminAuthMember | null>;
|
|
1209
|
+
create?: (args: {
|
|
1210
|
+
data: Record<string, any>;
|
|
1211
|
+
req: HookRequestContext;
|
|
1212
|
+
}) => Promise<AdminAuthMember>;
|
|
1213
|
+
update?: (args: {
|
|
1214
|
+
externalSubject: string;
|
|
1215
|
+
data: Record<string, any>;
|
|
1216
|
+
req: HookRequestContext;
|
|
1217
|
+
}) => Promise<AdminAuthMember>;
|
|
1218
|
+
delete?: (args: {
|
|
1219
|
+
externalSubject: string;
|
|
1220
|
+
req: HookRequestContext;
|
|
1221
|
+
}) => Promise<void>;
|
|
1222
|
+
}
|
|
1223
|
+
interface BaseAdminAuthProvider {
|
|
1224
|
+
id: string;
|
|
1225
|
+
type: "oidc" | "custom" | "cloud";
|
|
1226
|
+
displayName?: string;
|
|
1227
|
+
autoRedirect?: boolean;
|
|
1228
|
+
allowJitProvisioning?: boolean;
|
|
1229
|
+
claimMapping?: AdminAuthClaimMapping;
|
|
1230
|
+
members?: AdminAuthProviderMembersConfig;
|
|
1231
|
+
}
|
|
1232
|
+
interface OIDCAdminAuthProvider extends BaseAdminAuthProvider {
|
|
1233
|
+
type: "oidc";
|
|
1234
|
+
issuer: string;
|
|
1235
|
+
clientId: string;
|
|
1236
|
+
clientSecret: string;
|
|
1237
|
+
redirectUri?: string;
|
|
1238
|
+
scopes?: string[];
|
|
1239
|
+
authorizationEndpoint?: string;
|
|
1240
|
+
tokenEndpoint?: string;
|
|
1241
|
+
userInfoEndpoint?: string;
|
|
1242
|
+
}
|
|
1243
|
+
interface CustomAdminAuthProvider extends BaseAdminAuthProvider {
|
|
1244
|
+
type: "custom" | "cloud";
|
|
1245
|
+
startUrl?: string;
|
|
1246
|
+
issuer?: string;
|
|
1247
|
+
audience?: string;
|
|
1248
|
+
secret?: string;
|
|
1249
|
+
jwksUri?: string;
|
|
1250
|
+
tokenParam?: string;
|
|
1251
|
+
}
|
|
1252
|
+
type AdminAuthProvider = OIDCAdminAuthProvider | CustomAdminAuthProvider;
|
|
1253
|
+
interface PublicAdminAuthProvider {
|
|
1254
|
+
id: string;
|
|
1255
|
+
type: AdminAuthProvider["type"];
|
|
1256
|
+
displayName: string;
|
|
1257
|
+
autoRedirect?: boolean;
|
|
1258
|
+
}
|
|
1259
|
+
interface PublicAdminAuthConfig {
|
|
1260
|
+
mode: "local" | "external";
|
|
1261
|
+
collectionSlug?: string;
|
|
1262
|
+
provisioningMode?: AdminAuthProvisioningMode;
|
|
1263
|
+
providers: PublicAdminAuthProvider[];
|
|
1264
|
+
}
|
|
1265
|
+
interface AdminAuthConfig {
|
|
1266
|
+
mode: "local" | "external";
|
|
1267
|
+
collectionSlug?: string;
|
|
1268
|
+
provisioningMode?: AdminAuthProvisioningMode;
|
|
1269
|
+
providers: AdminAuthProvider[];
|
|
1270
|
+
resolveAccess?: (args: AdminAuthResolveAccessArgs) => Promise<AdminAuthAccessResolution> | AdminAuthAccessResolution;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* The root configuration object passed to `createDyrectedApp`.
|
|
1275
|
+
*
|
|
1276
|
+
* This is the single source of truth for your entire Dyrected instance —
|
|
1277
|
+
* collections, globals, database adapter, storage, email, and more.
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* import { defineConfig } from '@dyrected/core'
|
|
1281
|
+
* import { SQLiteAdapter } from '@dyrected/db-sqlite'
|
|
1282
|
+
*
|
|
1283
|
+
* export default defineConfig({
|
|
1284
|
+
* db: new SQLiteAdapter({ filename: './db.sqlite' }),
|
|
1285
|
+
* collections: [Posts, Users],
|
|
1286
|
+
* globals: [SiteSettings],
|
|
1287
|
+
* })
|
|
1288
|
+
*/
|
|
1289
|
+
interface DyrectedConfig {
|
|
1290
|
+
/** Collection definitions. Each collection maps to a database table/collection. */
|
|
1291
|
+
collections: CollectionConfig<any>[];
|
|
1292
|
+
/** Global (singleton) definitions. Each global maps to a single document. */
|
|
1293
|
+
globals: GlobalConfig<any>[];
|
|
1294
|
+
/**
|
|
1295
|
+
* The database adapter. Required for all data operations.
|
|
1296
|
+
* @see DatabaseAdapter
|
|
1297
|
+
*/
|
|
1298
|
+
db?: DatabaseAdapter;
|
|
1299
|
+
/**
|
|
1300
|
+
* The storage adapter for file uploads.
|
|
1301
|
+
* Required when any collection has `upload: true`.
|
|
1302
|
+
* @see StorageAdapter
|
|
1303
|
+
*/
|
|
1304
|
+
storage?: StorageAdapter;
|
|
1305
|
+
/**
|
|
1306
|
+
* The image processing service. Required when any upload collection
|
|
1307
|
+
* defines `imageSizes`.
|
|
1308
|
+
* @see ImageService
|
|
1309
|
+
*/
|
|
1310
|
+
image?: ImageService;
|
|
1311
|
+
/** Admin UI branding and metadata. */
|
|
1312
|
+
admin?: AdminConfig;
|
|
1313
|
+
/**
|
|
1314
|
+
* Deployment-level authentication strategy for the CMS dashboard (`/admin`).
|
|
1315
|
+
* This is separate from collection-level `auth: true`, which continues to
|
|
1316
|
+
* power application/customer auth independently.
|
|
1317
|
+
*/
|
|
1318
|
+
adminAuth?: AdminAuthConfig;
|
|
1319
|
+
/**
|
|
1320
|
+
* Email transport configuration. Required for welcome emails, password
|
|
1321
|
+
* resets, and invite links.
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* email: {
|
|
1325
|
+
* from: 'no-reply@myapp.com',
|
|
1326
|
+
* send: async ({ to, subject, html }) => {
|
|
1327
|
+
* await resend.emails.send({ from, to, subject, html })
|
|
1328
|
+
* },
|
|
1329
|
+
* }
|
|
1330
|
+
*/
|
|
1331
|
+
email?: {
|
|
1332
|
+
/** The `From` address for all outbound emails. */
|
|
1333
|
+
from: string;
|
|
1334
|
+
/** The send function. Wire in any email provider (Resend, SendGrid, SES, etc.). */
|
|
1335
|
+
send: (args: {
|
|
1336
|
+
to: string;
|
|
1337
|
+
subject: string;
|
|
1338
|
+
html: string;
|
|
1339
|
+
}) => Promise<void>;
|
|
1340
|
+
/** Override the default email templates. */
|
|
1341
|
+
templates?: {
|
|
1342
|
+
welcome?: (args: {
|
|
1343
|
+
email: string;
|
|
1344
|
+
}) => {
|
|
1345
|
+
subject?: string;
|
|
1346
|
+
html: string;
|
|
1347
|
+
};
|
|
1348
|
+
invite?: (args: {
|
|
1349
|
+
token: string;
|
|
1350
|
+
invitedByEmail?: string;
|
|
1351
|
+
}) => {
|
|
1352
|
+
subject?: string;
|
|
1353
|
+
html: string;
|
|
1354
|
+
};
|
|
1355
|
+
resetPassword?: (args: {
|
|
1356
|
+
token: string;
|
|
1357
|
+
url?: string;
|
|
1358
|
+
}) => {
|
|
1359
|
+
subject?: string;
|
|
1360
|
+
html: string;
|
|
1361
|
+
};
|
|
1362
|
+
passwordChanged?: (args: {
|
|
1363
|
+
email: string;
|
|
1364
|
+
}) => {
|
|
1365
|
+
subject?: string;
|
|
1366
|
+
html: string;
|
|
1367
|
+
};
|
|
1368
|
+
};
|
|
1369
|
+
};
|
|
1370
|
+
/**
|
|
1371
|
+
* Redis connection URL. Required for distributed caching of dynamic option
|
|
1372
|
+
* resolvers and other server-side caches in multi-instance deployments.
|
|
1373
|
+
*
|
|
1374
|
+
* @example
|
|
1375
|
+
* redis: { url: process.env.REDIS_URL }
|
|
1376
|
+
*/
|
|
1377
|
+
redis?: {
|
|
1378
|
+
url: string;
|
|
1379
|
+
};
|
|
1380
|
+
/** Durable lifecycle-event delivery configuration. */
|
|
1381
|
+
events?: {
|
|
1382
|
+
handlers: LifecycleEventHandler[];
|
|
1383
|
+
/** Maximum delivery attempts before an event remains failed. Defaults to 8. */
|
|
1384
|
+
maxAttempts?: number;
|
|
1385
|
+
/** Initial exponential-backoff delay in milliseconds. Defaults to 1000. */
|
|
1386
|
+
retryDelayMs?: number;
|
|
1387
|
+
};
|
|
1388
|
+
/**
|
|
1389
|
+
* Cross-Origin Resource Sharing (CORS) configuration.
|
|
1390
|
+
* List all origins that are allowed to call the Dyrected API.
|
|
1391
|
+
*
|
|
1392
|
+
* @example
|
|
1393
|
+
* cors: { origins: ['https://myapp.com', 'https://www.myapp.com'] }
|
|
1394
|
+
*/
|
|
1395
|
+
cors?: {
|
|
1396
|
+
origins: string[];
|
|
1397
|
+
};
|
|
1398
|
+
/**
|
|
1399
|
+
* Callback to dynamically fetch additional collections and globals for a
|
|
1400
|
+
* given site ID at request time. Used in multi-tenant deployments where each
|
|
1401
|
+
* site has its own schema stored in the database.
|
|
1402
|
+
*/
|
|
1403
|
+
onSchemaFetch?: (siteId: string) => Promise<{
|
|
1404
|
+
collections?: CollectionConfig<any>[];
|
|
1405
|
+
globals?: GlobalConfig<any>[];
|
|
1406
|
+
admin?: AdminConfig;
|
|
1407
|
+
adminAuth?: AdminAuthConfig;
|
|
1408
|
+
}>;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
export { type FieldAdminOptionsHookArgs as $, type AdminAuthConfig as A, type Block as B, type CollectionConfig as C, type DyrectedConfig as D, type CollectionBeforeChangeHook as E, type Field as F, type GlobalConfig as G, type HookRequestContext as H, type CollectionBeforeDeleteHook as I, type CollectionBeforeReadHook as J, type CollectionBeforeTransitionHook as K, type LifecycleEventName as L, type CollectionListComponentSlots as M, type CustomAdminAuthProvider as N, type DatabaseAdapter as O, type PublicAdminAuthConfig as P, type DateField as Q, type DateTimeField as R, type DynamicOptionItem as S, type DynamicOptionsConfig as T, type DynamicOptionsResolver as U, type DynamicOptionsResolverArgs as V, type WorkflowConfig as W, type EmailField as X, type FieldAdminOnChangeHook as Y, type FieldAdminOnChangeHookArgs as Z, type FieldAdminOptionsHook as _, type AuthenticatedUser as a, type FieldAdminOptionsHookResult as a0, type FieldAfterReadHook as a1, type FieldAfterReadHookArgs as a2, type FieldBeforeChangeHook as a3, type FieldBeforeChangeHookArgs as a4, type FieldHook as a5, type FieldType as a6, type FileData as a7, type GlobalAfterChangeHook as a8, type GlobalAfterReadHook as a9, type UploadConfig as aA, type UrlField as aB, type WordLimitFieldConfig as aC, type WorkflowMetadata as aD, type WorkflowRole as aE, type WorkflowState as aF, type WorkflowTransitionContext as aG, type GlobalBeforeChangeHook as aa, type GlobalBeforeReadHook as ab, type HookFunction as ac, type IconField as ad, type ImageField as ae, type ImageService as af, type JoinField as ag, type JsonField as ah, LIFECYCLE_EVENT_NAMES as ai, type LifecycleEventHandler as aj, type MultiSelectField as ak, type NumberField as al, type OIDCAdminAuthProvider as am, type ObjectField as an, type PaginatedResult as ao, type PublicAdminAuthProvider as ap, type RadioField as aq, type ReadonlyDatabaseAdapter as ar, type RelationshipField as as, type RichTextField as at, type RowField as au, type SelectField as av, type StorageAdapter as aw, type TextField as ax, type TextareaField as ay, type TimeField as az, type WorkflowTransition as b, type LifecycleEvent as c, type BaseDocument as d, type AccessFunction as e, type AdminAuthAccessResolution as f, type AdminAuthClaimMapping as g, type AdminAuthMember as h, type AdminAuthProvider as i, type AdminAuthProviderMembersConfig as j, type AdminAuthProvisioningMode as k, type AdminAuthResolveAccessArgs as l, type AdminAuthResolvedIdentity as m, type AdminConfig as n, type AdminDashboardComponentSlots as o, type AdminIconName as p, type ArrayField as q, type BaseAdminAuthProvider as r, type BlockVariant as s, type BlocksField as t, type BooleanField as u, type CharacterLimitFieldConfig as v, type CollectionAfterChangeHook as w, type CollectionAfterDeleteHook as x, type CollectionAfterReadHook as y, type CollectionAfterTransitionHook as z };
|