@dyrected/sdk 2.5.29 → 2.5.32

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/index.js CHANGED
@@ -77,818 +77,6 @@ var QueryBuilder = class {
77
77
  }
78
78
  };
79
79
 
80
- // src/utils/setup-prompt.ts
81
- function buildEnvironmentSection(frameworkLabel, isSelfHosted, config) {
82
- const credentialLines = isSelfHosted ? "" : `- Site ID : ${config.siteId}
83
- - API Key : ${config.apiKey}`;
84
- return `
85
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
86
- 1. ENVIRONMENT
87
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
88
- - Framework : ${frameworkLabel || "Detect it"}
89
- - Host Type : ${isSelfHosted ? "Self-Hosted (Local/Private Server)" : "Managed (Dyrected Cloud)"}
90
- - API Base : ${config.baseUrl || "http://localhost:3000"}
91
- ${credentialLines}`;
92
- }
93
- function buildDiagnosticSection() {
94
- return `
95
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
96
- 2. PHASE 0 \u2014 DISCOVERY
97
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
98
- Before writing any code, you MUST ask the user these questions.
99
- Write them exactly as shown below \u2014 in plain language with examples.
100
- Wait for the user to answer ALL of them before proceeding.
101
-
102
- \u2500\u2500\u2500 QUESTION 1 \u2500\u2500\u2500
103
- Ask:
104
- "Do you already have a website built, or are we starting fresh?
105
-
106
- \u2192 Already built: share your project or describe what pages you have
107
- (e.g. Home, About, Services, Contact)
108
- \u2192 Starting fresh: just say 'new site' and describe what the site is for"
109
-
110
- \u2500\u2500\u2500 QUESTION 2 \u2500\u2500\u2500
111
- Ask:
112
- "What kind of content will your client need to update regularly?
113
-
114
- Here are some examples to help you think:
115
- \u2192 Blog posts or news articles
116
- \u2192 Team member profiles (name, photo, bio)
117
- \u2192 Services or product descriptions
118
- \u2192 Testimonials or reviews
119
- \u2192 Event listings
120
- \u2192 FAQs
121
- \u2192 Homepage text (headline, hero image, call-to-action button)
122
-
123
- Just list the ones that apply. You can say things like:
124
- 'They need to update blog posts and team members'"
125
-
126
- \u2500\u2500\u2500 QUESTION 3 \u2500\u2500\u2500
127
- Ask:
128
- "Are there any pages on the site that should NEVER change \u2014 like a
129
- custom-coded page you want to leave exactly as it is?
130
-
131
- Example answer: 'The homepage has a custom animation, leave that alone.
132
- Everything else can be managed from the CMS.'
133
-
134
- If everything should be manageable, just say 'all pages'"
135
-
136
- \u2500\u2500\u2500 QUESTION 4 \u2500\u2500\u2500
137
- Ask:
138
- "What is this website for? Pick the closest description:
139
-
140
- A) A business or agency marketing site (show services, get leads)
141
- B) A blog or content site (publish articles regularly)
142
- C) A SaaS or product site (landing page, pricing, features)
143
- D) A portfolio (show work, case studies)
144
- E) An e-commerce or product catalogue
145
- F) Something else \u2014 describe it in one sentence"
146
-
147
- \u2500\u2500\u2500 IF EXISTING SITE \u2500\u2500\u2500
148
- If the user confirms they have an existing site, also:
149
- - Scan the codebase for all hardcoded text that should be CMS-managed
150
- - Identify repeated data structures that should become collections
151
- - Propose saving current content to a migration/ folder as .json files
152
- BEFORE touching any code
153
- - Report your findings to the user and get confirmation before proceeding
154
-
155
- Do NOT write any implementation code until all questions are answered
156
- and the user has confirmed the content plan.`;
157
- }
158
- function buildConstraintsSection() {
159
- return `
160
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
161
- 3. ARCHITECTURE & CONSTRAINTS
162
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
163
- - API ACCESS : Use client.collection(slug) as the only entry point.
164
- - ZERO-STATE : Always use initialData in all data fetches so the site
165
- renders correctly on first load and never throws during render.
166
- - MARKETING FREEDOM : Use a dynamic pages collection with a catch-all route
167
- so marketing can create and manage pages without a developer.
168
- - BLOCKS DESIGN : Use blocks for flexible page builders. Store as
169
- [{ blockType: 'slug', ...fields }] and switch on blockType
170
- in the frontend renderer.
171
- - DATA SAFETY : Never overwrite or drop existing content or pages.
172
- Preserve everything before making changes.
173
- - RESILIENCE : If Dyrected backend is unreachable, fall back to
174
- initialData and show stale content \u2014 never an error page.
175
- All relationship fields must handle null gracefully.
176
- Every block renderer must have a default fallback case.`;
177
- }
178
- function buildSchemaRulesSection() {
179
- return `
180
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
181
- 4. SCHEMA EVOLUTION RULES
182
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
183
- - Never drop existing fields from the schema. Mark unused fields as deprecated only.
184
- - All new fields must have a defaultValue.
185
- - Never rename a field slug \u2014 add a new field and migrate data separately.
186
- - For Cloud deployments, run npx @dyrected/cli sync:schema after every config change. Self-hosted deployments sync automatically on startup.`;
187
- }
188
- function buildDoNotSection() {
189
- return `
190
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
191
- 5. DO NOT
192
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
193
- - Do NOT use client.collections \u2014 always use client.collection(slug).
194
- - Do NOT add custom auth middleware to the admin route.
195
- Dyrected handles admin authentication internally. Do not wrap,
196
- protect, or redirect the admin route yourself.
197
- - Do NOT use renderAdminUI in a Nuxt.js project. Use the DyrectedAdmin
198
- component which is auto-imported by @dyrected/nuxt.
199
- - Do NOT modify or overwrite existing pages without first preserving their data.
200
- - Do NOT drop, rename, or remove fields from an existing schema.
201
- - Do NOT integrate blog posts or testimonials unless explicitly requested.
202
- - Do NOT skip the diagnostic or discovery phase.`;
203
- }
204
- function buildTechnicalReferenceSection() {
205
- return `
206
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
207
- 6. TECHNICAL REFERENCE
208
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
209
- Use defineCollection, defineGlobal, and defineConfig from '@dyrected/core'.
210
-
211
- FIELD TYPES:
212
- - Primitive : text | textarea | richText | number | boolean | date | email | url | json | image
213
- - Choice : select | multiSelect (requires options: [{ label, value }])
214
- - Structural : array | object (requires nested fields: [...])
215
- - Relation : relationship (requires relationTo: '<slug>')
216
- - Media : relationship to an upload collection (e.g. 'media')
217
- - Blocks : blocks (requires blocks: [{ slug, labels, fields }])
218
-
219
- COLLECTION OPTIONS:
220
- - upload: true \u2014 media library with file upload support
221
- - auth: true \u2014 adds login/me endpoints; password field is auto-managed
222
- - audit: true \u2014 enables activity logging
223
- - admin.useAsTitle \u2014 field used as display title in admin list view
224
- - admin.group \u2014 groups collection under a sidebar heading
225
- - admin.hidden \u2014 hides collection from the sidebar (internal/system use)
226
-
227
- FIELD OPTIONS:
228
- - label \u2014 user-friendly display name (REQUIRED for all fields)
229
- - required \u2014 validation
230
- - unique \u2014 database-level uniqueness constraint
231
- - hasMany \u2014 allow multiple values (for relationship, select, image)
232
- - defaultValue \u2014 fallback value (required on all new fields added to existing schemas)
233
- - admin.condition \u2014 Jexl expression string to conditionally show/hide field
234
- e.g. "status == \\"published\\""
235
- - admin.readOnly \u2014 display only, not editable
236
- - admin.hidden \u2014 hidden from editor UI entirely
237
- - hooks.beforeChange \u2014 [async (value) => newValue] transform before save
238
- - hooks.afterRead \u2014 [async (value) => newValue] transform after read
239
-
240
- GLOBALS:
241
- Use defineGlobal for single-instance documents like site settings or navigation.
242
- Access via client.global(slug).get() and client.global(slug).update(data).
243
-
244
- BLOCKS:
245
- Blocks are stored as [{ blockType: '<slug>', ...fields }].
246
- The admin renders a drag-and-drop block editor automatically.
247
- On the frontend, iterate the array and switch on block.blockType.
248
- Always include a default case in your switch for unknown block types.
249
-
250
- COMPLETE SCHEMA EXAMPLE:
251
- \`\`\`ts
252
- import { defineCollection, defineGlobal, defineConfig } from '@dyrected/core'
253
- import { SqliteAdapter } from '@dyrected/db-sqlite'
254
-
255
- const media = defineCollection({
256
- slug: 'media',
257
- upload: true,
258
- fields: [
259
- { name: 'alt', label: 'Alt Text', type: 'text' },
260
- ],
261
- })
262
-
263
- const pages = defineCollection({
264
- slug: 'pages',
265
- admin: { useAsTitle: 'title', group: 'Content' },
266
- fields: [
267
- { name: 'title', label: 'Title', type: 'text', required: true },
268
- { name: 'slug', label: 'URL Slug', type: 'text', required: true, unique: true },
269
- { name: 'seo', label: 'SEO Metadata', type: 'object', fields: [
270
- { name: 'metaTitle', label: 'Meta Title', type: 'text' },
271
- { name: 'metaDescription', label: 'Meta Description', type: 'textarea' },
272
- { name: 'ogImage', label: 'OG Image', type: 'relationship', relationTo: 'media' },
273
- ]},
274
- {
275
- name: 'layout',
276
- label: 'Page Layout',
277
- type: 'blocks',
278
- blocks: [
279
- {
280
- slug: 'hero',
281
- labels: { singular: 'Hero', plural: 'Heroes' },
282
- fields: [
283
- { name: 'heading', label: 'Heading', type: 'text', required: true },
284
- { name: 'subheading', label: 'Subheading', type: 'textarea' },
285
- { name: 'image', label: 'Hero Image', type: 'relationship', relationTo: 'media' },
286
- { name: 'ctaLabel', label: 'Button Label', type: 'text' },
287
- { name: 'ctaLink', label: 'Button Link', type: 'url' },
288
- ],
289
- },
290
- {
291
- slug: 'richContent',
292
- labels: { singular: 'Rich Content', plural: 'Rich Content Blocks' },
293
- fields: [
294
- { name: 'content', label: 'Content', type: 'richText', required: true },
295
- ],
296
- },
297
- {
298
- slug: 'callToAction',
299
- labels: { singular: 'Call to Action', plural: 'Calls to Action' },
300
- fields: [
301
- { name: 'heading', label: 'Heading', type: 'text', required: true },
302
- { name: 'description', label: 'Description', type: 'textarea' },
303
- { name: 'buttonLabel', label: 'Button Text', type: 'text' },
304
- { name: 'buttonLink', label: 'Button Link', type: 'url' },
305
- { name: 'theme', label: 'Theme', type: 'select', options: [
306
- { label: 'Primary', value: 'primary' },
307
- { label: 'Secondary', value: 'secondary' },
308
- { label: 'Dark', value: 'dark' },
309
- ]},
310
- ],
311
- },
312
- ],
313
- },
314
- ],
315
- })
316
-
317
- const settings = defineGlobal({
318
- slug: 'settings',
319
- label: 'Site Settings',
320
- fields: [
321
- { name: 'siteName', label: 'Site Name', type: 'text' },
322
- { name: 'tagline', label: 'Site Tagline', type: 'text' },
323
- { name: 'logo', label: 'Site Logo', type: 'relationship', relationTo: 'media' },
324
- { name: 'footerText', label: 'Footer Text', type: 'textarea' },
325
- ],
326
- })
327
-
328
- export default defineConfig({
329
- collections: [media, pages],
330
- globals: [settings],
331
- db: new SqliteAdapter({ filename: './dyrected.db' }),
332
- })
333
- \`\`\``;
334
- }
335
- function buildDeliverablesSection() {
336
- return `
337
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
338
- 7. REQUIRED DELIVERABLES \u2014 IN THIS ORDER
339
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
340
- Return your response in exactly this order. Do not combine steps. Do not skip steps.
341
-
342
- 1. Diagnostic findings (what exists, what needs to become CMS-managed)
343
- 2. dyrected.config.ts \u2014 complete file
344
- 3. Admin route file \u2014 complete file
345
- 4. Catch-all frontend page route \u2014 complete file
346
- 5. Block components \u2014 names and fields only
347
- 6. Migration/fallback strategy \u2014 numbered steps
348
- 7. Schema sync command
349
-
350
- API Reference: https://docs.dyrected.com
351
- If you are unsure about any syntax or property, refer to the documentation above.`;
352
- }
353
- function buildFrameworkSection(activeTab, isSelfHosted, config) {
354
- const envPrefix = activeTab === "next" ? "NEXT_PUBLIC_" : activeTab === "nuxt" ? "NUXT_PUBLIC_" : "";
355
- const credentialEnvLines = isSelfHosted ? "" : `
356
- apiKey: process.env.${envPrefix}DYRECTED_API_KEY || '${config.apiKey}',
357
- siteId: process.env.${envPrefix}SITE_ID || '${config.siteId}',`;
358
- const baseUrlLine = `process.env.${envPrefix}DYRECTED_URL || '${config.baseUrl || "http://localhost:3000"}'`;
359
- const sections = {
360
- next: `
361
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
362
- 8. IMPLEMENTATION \u2014 Next.js
363
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
364
- 1. SDK Setup (lib/dyrected.ts):
365
- \`\`\`ts
366
- import { createClient } from '@dyrected/sdk'
367
-
368
- export const dyrected = createClient({
369
- baseUrl: ${baseUrlLine},${credentialEnvLines}
370
- })
371
- \`\`\`
372
-
373
- 2. Admin Route (app/cms/page.tsx):
374
- \`\`\`tsx
375
- import { DyrectedAdmin } from '@dyrected/next/admin'
376
-
377
- export default function AdminPage() {
378
- // DyrectedAdmin handles routing, auth, and CSS automatically.
379
- // Do NOT wrap this in custom auth middleware.
380
- return <DyrectedAdmin basename="/cms" />
381
- }
382
- \`\`\`
383
-
384
- 3. Catch-all Page Route (app/[...slug]/page.tsx):
385
- \`\`\`tsx
386
- import { dyrected } from '@/lib/dyrected'
387
-
388
- export default async function CmsPage({ params }: { params: { slug: string[] } }) {
389
- const slug = params.slug?.join('/') || 'home'
390
- const page = await dyrected.collection('pages').findOne({ where: { slug: { equals: slug } } })
391
-
392
- if (!page) return <div>Page not found</div>
393
-
394
- return (
395
- <main>
396
- {page.layout?.map((block: any, i: number) => (
397
- <BlockRenderer key={i} block={block} />
398
- ))}
399
- </main>
400
- )
401
- }
402
- \`\`\``,
403
- nuxt: `
404
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
405
- 8. IMPLEMENTATION \u2014 Nuxt.js
406
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
407
- 1. Nuxt.js Config (nuxt.config.ts):
408
- \`\`\`ts
409
- export default defineNuxtConfig({
410
- modules: ['@dyrected/nuxt'],
411
- dyrected: {
412
- baseUrl: process.env.${envPrefix}DYRECTED_URL || '${config.baseUrl || "http://localhost:3000"}',${isSelfHosted ? "" : `
413
- apiKey: process.env.${envPrefix}DYRECTED_API_KEY || '${config.apiKey}',
414
- siteId: process.env.${envPrefix}SITE_ID || '${config.siteId}',`}
415
- },
416
- })
417
- \`\`\`
418
-
419
- 2. Admin Route (pages/cms/index.vue):
420
- \`\`\`vue
421
- <script setup lang="ts">
422
- // DyrectedAdmin is auto-imported by @dyrected/nuxt.
423
- // Do NOT manually import it.
424
- // Do NOT use renderAdminUI here.
425
- // Do NOT add custom auth middleware \u2014 Dyrected handles authentication.
426
- definePageMeta({ layout: false })
427
- </script>
428
-
429
- <template>
430
- <ClientOnly>
431
- <DyrectedAdmin basename="/cms" />
432
- </ClientOnly>
433
- </template>
434
- \`\`\`
435
-
436
- 3. Catch-all Page Route (pages/[...slug].vue):
437
- \`\`\`vue
438
- <script setup lang="ts">
439
- const route = useRoute()
440
- const slug = computed(() =>
441
- Array.isArray(route.params.slug)
442
- ? route.params.slug.join('/')
443
- : route.params.slug || 'home'
444
- )
445
-
446
- const { data: page } = await useDyrected('pages').findOne({
447
- where: { slug: { equals: slug.value } },
448
- initialData: null,
449
- })
450
- </script>
451
-
452
- <template>
453
- <main v-if="page">
454
- <BlockRenderer
455
- v-for="(block, i) in page.layout"
456
- :key="i"
457
- :block="block"
458
- />
459
- </main>
460
- <div v-else>Page not found</div>
461
- </template>
462
- \`\`\``,
463
- react: `
464
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
465
- 8. IMPLEMENTATION \u2014 React
466
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
467
- 1. SDK Setup (lib/dyrected.ts):
468
- \`\`\`ts
469
- import { createClient } from '@dyrected/sdk'
470
-
471
- export const dyrected = createClient({
472
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
473
- apiKey: '${config.apiKey}',
474
- siteId: '${config.siteId}',`}
475
- })
476
- \`\`\`
477
-
478
- 2. Admin Route (pages/cms.tsx):
479
- \`\`\`tsx
480
- import { AdminUI } from '@dyrected/admin'
481
- import '@dyrected/admin/styles'
482
-
483
- export default function AdminPage() {
484
- return (
485
- <div style={{ height: '100vh' }}>
486
- <AdminUI
487
- baseUrl="${config.baseUrl || "https://api.dyrected.cloud"}"${isSelfHosted ? "" : `
488
- apiKey="${config.apiKey}"
489
- siteId="${config.siteId}"`}
490
- />
491
- </div>
492
- )
493
- }
494
- \`\`\``,
495
- vue: `
496
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
497
- 8. IMPLEMENTATION \u2014 Vue
498
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
499
- 1. SDK Setup (lib/dyrected.ts):
500
- \`\`\`ts
501
- import { createClient } from '@dyrected/sdk'
502
-
503
- export const dyrected = createClient({
504
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
505
- apiKey: '${config.apiKey}',
506
- siteId: '${config.siteId}',`}
507
- })
508
- \`\`\`
509
-
510
- 2. Admin Route (pages/cms.vue):
511
- \`\`\`vue
512
- <template>
513
- <div ref="container" style="height: 100vh" />
514
- </template>
515
-
516
- <script setup>
517
- import { ref, onMounted, onUnmounted } from 'vue'
518
- import { renderAdminUI } from '@dyrected/admin'
519
- import '@dyrected/admin/styles'
520
-
521
- const container = ref(null)
522
- let cleanup: (() => void) | undefined
523
-
524
- onMounted(() => {
525
- cleanup = renderAdminUI(container.value, {
526
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
527
- apiKey: '${config.apiKey}',
528
- siteId: '${config.siteId}',`}
529
- })
530
- })
531
-
532
- onUnmounted(() => cleanup?.())
533
- </script>
534
- \`\`\``
535
- };
536
- return sections[activeTab] || sections.next;
537
- }
538
- function generateFreshSetupPrompt(activeTab, config) {
539
- const frameworkLabel = activeTab === "next" ? "Next.js" : activeTab === "nuxt" ? "Nuxt.js" : activeTab ? activeTab.charAt(0).toUpperCase() + activeTab.slice(1) : "the project's detected framework";
540
- const isSelfHosted = config.isSelfHosted === true || !config.apiKey && !config.siteId;
541
- const frameworkSetup = {
542
- nuxt: `
543
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
544
- 3. INSTALLATION STEPS \u2014 Run these in order
545
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
546
- Tell the user to follow these steps exactly. Explain each one in plain
547
- language before showing the command. Do not skip any step.
548
-
549
- STEP 1 \u2014 Initialize Dyrected
550
- Tell the user:
551
- "Run this command in your terminal inside your Nuxt.js project folder.
552
- It will set everything up for you automatically."
553
-
554
- \`\`\`bash
555
- npx @dyrected/cli init
556
- \`\`\`
557
-
558
- When it asks questions, tell the user to:
559
- - Choose: Nuxt.js 3
560
- - Choose: SQLite (easiest option, no extra setup needed)
561
-
562
- The CLI will automatically:
563
- - Install all required packages
564
- - Create a dyrected.config.ts file
565
- - Mount the Admin UI at pages/cms/index.vue
566
- - Generate a .env.example file
567
-
568
- STEP 2 \u2014 Register the module
569
- Tell the user to open nuxt.config.ts and add '@dyrected/nuxt' to modules:
570
-
571
- \`\`\`ts
572
- export default defineNuxtConfig({
573
- modules: ['@dyrected/nuxt'],
574
- })
575
- \`\`\`
576
-
577
- STEP 3 \u2014 Set up environment variables
578
- Tell the user:
579
- "Find the file called .env.example in your project.
580
- Make a copy of it and rename the copy to .env
581
- Then open .env and fill in the values."
582
-
583
- STEP 4 \u2014 Start the project
584
- \`\`\`bash
585
- pnpm dev
586
- \`\`\`
587
-
588
- STEP 5 \u2014 Open the dashboard
589
- Tell the user to open their browser and go to:
590
- http://localhost:3000/cms
591
-
592
- If they see the Dyrected admin dashboard, the installation worked.
593
- Tell them: "You are ready. Now let's set up your content."`,
594
- next: `
595
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
596
- 3. INSTALLATION STEPS \u2014 Run these in order
597
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
598
- Tell the user to follow these steps exactly. Explain each one in plain
599
- language before showing the command. Do not skip any step.
600
-
601
- STEP 1 \u2014 Initialize Dyrected
602
- Tell the user:
603
- "Run this command in your terminal inside your Next.js project folder."
604
-
605
- \`\`\`bash
606
- npx @dyrected/cli init
607
- \`\`\`
608
-
609
- When it asks questions, tell the user to:
610
- - Choose: Next.js
611
- - Choose: SQLite (easiest option, no extra setup needed)
612
-
613
- The CLI will automatically:
614
- - Install all required packages
615
- - Create a dyrected.config.ts file
616
- - Mount the Admin UI at app/cms/page.tsx
617
- - Generate a .env.example file
618
-
619
- STEP 2 \u2014 Set up environment variables
620
- Tell the user:
621
- "Find the file called .env.example in your project.
622
- Make a copy of it and rename the copy to .env.local
623
- Then open .env.local and fill in the values."
624
-
625
- STEP 3 \u2014 Start the project
626
- \`\`\`bash
627
- pnpm dev
628
- \`\`\`
629
-
630
- STEP 4 \u2014 Open the dashboard
631
- Tell the user to open their browser and go to:
632
- http://localhost:3000/cms
633
-
634
- If they see the Dyrected admin dashboard, the installation worked.
635
- Tell them: "You are ready. Now let's set up your content."`,
636
- react: `
637
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
638
- 3. INSTALLATION STEPS \u2014 Run these in order
639
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
640
- STEP 1 \u2014 Install the SDK and admin packages
641
- \`\`\`bash
642
- npm install @dyrected/sdk @dyrected/admin
643
- \`\`\`
644
-
645
- STEP 2 \u2014 Set up the client (lib/dyrected.ts):
646
- \`\`\`ts
647
- import { createClient } from '@dyrected/sdk'
648
-
649
- export const dyrected = createClient({
650
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
651
- apiKey: '${config.apiKey}',
652
- siteId: '${config.siteId}',`}
653
- })
654
- \`\`\`
655
-
656
- STEP 3 \u2014 Mount the Admin UI (pages/cms.tsx):
657
- \`\`\`tsx
658
- import { AdminUI } from '@dyrected/admin'
659
- import '@dyrected/admin/styles'
660
-
661
- export default function AdminPage() {
662
- return (
663
- <div style={{ height: '100vh' }}>
664
- <AdminUI
665
- baseUrl="${config.baseUrl || "https://api.dyrected.cloud"}"${isSelfHosted ? "" : `
666
- apiKey="${config.apiKey}"
667
- siteId="${config.siteId}"`}
668
- />
669
- </div>
670
- )
671
- }
672
- \`\`\``,
673
- vue: `
674
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
675
- 3. INSTALLATION STEPS \u2014 Run these in order
676
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
677
- STEP 1 \u2014 Install the SDK and admin packages
678
- \`\`\`bash
679
- npm install @dyrected/sdk @dyrected/admin
680
- \`\`\`
681
-
682
- STEP 2 \u2014 Set up the client (lib/dyrected.ts):
683
- \`\`\`ts
684
- import { createClient } from '@dyrected/sdk'
685
-
686
- export const dyrected = createClient({
687
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
688
- apiKey: '${config.apiKey}',
689
- siteId: '${config.siteId}',`}
690
- })
691
- \`\`\`
692
-
693
- STEP 3 \u2014 Mount the Admin UI (pages/cms.vue):
694
- \`\`\`vue
695
- <template>
696
- <div ref="container" style="height: 100vh" />
697
- </template>
698
-
699
- <script setup>
700
- import { ref, onMounted, onUnmounted } from 'vue'
701
- import { renderAdminUI } from '@dyrected/admin'
702
- import '@dyrected/admin/styles'
703
-
704
- const container = ref(null)
705
- let cleanup
706
-
707
- onMounted(() => {
708
- cleanup = renderAdminUI(container.value, {
709
- baseUrl: '${config.baseUrl || "https://api.dyrected.cloud"}',${isSelfHosted ? "" : `
710
- apiKey: '${config.apiKey}',
711
- siteId: '${config.siteId}',`}
712
- })
713
- })
714
-
715
- onUnmounted(() => cleanup?.())
716
- </script>
717
- \`\`\``
718
- };
719
- return [
720
- `You are a friendly technical assistant helping someone set up Dyrected CMS for the very first time in a ${frameworkLabel} project. They have NOT installed anything yet.
721
-
722
- Your job is to:
723
- 1. Understand who you are talking to before giving any instructions
724
- 2. Ask simple questions about their project and content needs
725
- 3. Walk them through setup in a way that matches their technical level
726
- 4. Confirm each step worked before moving to the next
727
- 5. Help them design their content so their client can manage it
728
-
729
- Speak in plain language at all times. Never assume technical knowledge.
730
- Never show more than one step at a time.
731
- Never mention the terminal, command line, or any commands until you have
732
- confirmed the user is comfortable running them.`,
733
- `
734
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
735
- 1. ENVIRONMENT
736
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
737
- - Framework : ${frameworkLabel}
738
- - Host Type : ${isSelfHosted ? "Self-Hosted" : "Dyrected Cloud"}
739
- - API Base : ${config.baseUrl || "http://localhost:3000"}
740
- ${isSelfHosted ? "" : `- Site ID : ${config.siteId}
741
- - API Key : ${config.apiKey}`}`.trim(),
742
- `
743
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
744
- 2. PHASE 0 \u2014 UNDERSTAND THE USER FIRST
745
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
746
- Ask these questions one at a time. Wait for each answer before asking the next.
747
- Never ask more than one question at a time.
748
-
749
- \u2500\u2500\u2500 QUESTION 1 \u2014 TECH LEVEL \u2500\u2500\u2500
750
- This is the most important question. Ask it first.
751
-
752
- Ask exactly this:
753
- "Before we dive in \u2014 how would you describe yourself?
754
-
755
- A) I write code myself (I'm comfortable with the terminal and editing files)
756
- B) I use tools like Lovable, Bolt, or v0 to build with AI \u2014 I don't write much code myself
757
- C) I'm a designer or project manager \u2014 someone else usually handles the technical stuff
758
- D) Something else \u2014 just describe how you work"
759
-
760
- Use their answer to decide how to guide them for the rest of the setup:
761
- - If A \u2192 they are TECHNICAL. You may show terminal commands and code directly.
762
- - If B \u2192 they are SEMI-TECHNICAL. Explain what each step does before showing
763
- any code or commands. Ask before running anything in the terminal.
764
- For Lovable users specifically: guide them to use the built-in
765
- terminal or ask them to paste code into the right file in their editor.
766
- - If C \u2192 they are NON-TECHNICAL. Do not show terminal commands at all.
767
- Generate all the code and config for them. Walk them through
768
- copy-pasting into specific files by name. If a terminal step is
769
- unavoidable, warn them first and offer to write the exact command
770
- with a clear explanation of what it does and where to run it.
771
- - If D \u2192 ask one follow-up question to understand their workflow before
772
- deciding which path above fits best.
773
-
774
- \u2500\u2500\u2500 QUESTION 2 \u2014 PROJECT STATUS \u2500\u2500\u2500
775
- Ask after Q1 is answered:
776
-
777
- "Do you already have a ${frameworkLabel} project open,
778
- or are we starting from scratch?
779
-
780
- \u2192 Already have a project: tell me what the site is about or
781
- share the folder name
782
- \u2192 Starting fresh: just say 'new project' and I will help you
783
- create one first"
784
-
785
- \u2500\u2500\u2500 QUESTION 3 \u2014 SITE PURPOSE \u2500\u2500\u2500
786
- Ask after Q2 is answered:
787
-
788
- "What kind of website is this?
789
-
790
- A) A business or agency site (show services, get enquiries)
791
- B) A blog or news site (publish articles regularly)
792
- C) A SaaS or product landing page (features, pricing, sign up)
793
- D) A portfolio (show work and past projects)
794
- E) Something else \u2014 describe it in one sentence"
795
-
796
- \u2500\u2500\u2500 QUESTION 4 \u2014 CONTENT NEEDS \u2500\u2500\u2500
797
- Ask after Q3 is answered:
798
-
799
- "What will your client need to update themselves \u2014 without calling you?
800
-
801
- Some examples to help you think:
802
- \u2192 Blog posts or news articles
803
- \u2192 Team member profiles (name, photo, bio)
804
- \u2192 Services or product descriptions
805
- \u2192 Homepage text (headline, buttons, images)
806
- \u2192 Testimonials or reviews
807
- \u2192 FAQs
808
- \u2192 Event listings or announcements
809
-
810
- Just list the ones that apply. Or say 'not sure yet'
811
- and we will figure it out together."
812
-
813
- \u2500\u2500\u2500 AFTER ALL QUESTIONS \u2500\u2500\u2500
814
- Once all four questions are answered:
815
- 1. Summarise what you understood in plain English
816
- 2. Ask the user to confirm before touching any code
817
- 3. Then move to the installation steps using the correct path
818
- for their tech level from Question 1`,
819
- frameworkSetup[activeTab] || frameworkSetup.nuxt,
820
- `
821
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
822
- 4. AFTER INSTALLATION \u2014 CONTENT SETUP
823
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
824
- Once the dashboard is confirmed working, help the user design their
825
- content model in dyrected.config.ts based on what they told you in
826
- Phase 0.
827
-
828
- RULES for this phase:
829
- - Use defineCollection and defineConfig from '@dyrected/core'
830
- - Use client.collection(slug) only \u2014 never client.collections
831
- - Always use initialData in all data fetches
832
- - Use a catch-all pages collection for marketing-managed pages
833
- - Use blocks for flexible page layouts
834
- - Use type: 'relationship', relationTo: 'collectionSlug' for relations
835
- - Never throw during render \u2014 fall back to initialData on errors
836
- - All relationship fields must handle null gracefully
837
-
838
- CONTENT SETUP DELIVERABLES \u2014 in this order:
839
- 1. dyrected.config.ts \u2014 complete file based on their answers
840
- 2. Catch-all page route for CMS-managed pages
841
- 3. Block components list (names and fields only)
842
- 4. One example fetch showing how to load content on a page
843
-
844
- After delivering the config, tell the user to sync their schema.
845
- For TECHNICAL users show the command directly:
846
- \`\`\`bash
847
- npx @dyrected/cli sync:schema
848
- \`\`\`
849
- For SEMI-TECHNICAL or NON-TECHNICAL users explain it first:
850
- "This next step tells Dyrected to read your content setup file
851
- and prepare the database. Here is the command to run:" then show it.
852
-
853
- Then ask: "Do you want me to help you connect this content to your
854
- frontend pages now?"
855
-
856
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
857
- DO NOT
858
- \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
859
- - Do NOT show terminal commands before confirming the user's tech level
860
- - Do NOT assume the user knows what a terminal, CLI, or package manager is
861
- - Do NOT show all steps at once \u2014 one step at a time always
862
- - Do NOT use client.collections \u2014 use client.collection(slug)
863
- - Do NOT add custom auth middleware to the admin route
864
- - Do NOT use renderAdminUI in a Nuxt.js project
865
- - Do NOT skip the confirmation after each installation step
866
- - Do NOT use jargon without explaining it in plain English first
867
- - Do NOT assume the installation worked \u2014 ask the user to confirm
868
-
869
- API Reference: https://docs.dyrected.com
870
- If you are unsure about any syntax, refer to the official documentation above.`
871
- ].join("\n");
872
- }
873
- function generateAIPrompt(activeTab, config) {
874
- const frameworkLabel = activeTab === "next" ? "Next.js" : activeTab === "nuxt" ? "Nuxt.js" : activeTab ? activeTab.charAt(0).toUpperCase() + activeTab.slice(1) : "the project's detected framework";
875
- const isSelfHosted = config.isSelfHosted === true || !config.apiKey && !config.siteId;
876
- const existingSite = config.existingSite ?? false;
877
- const missionText = existingSite ? `You are a Senior Content Architect. Your mission is to integrate Dyrected CMS into an EXISTING ${frameworkLabel} project. Your absolute priority is DATA PRESERVATION and MIGRATION of existing hardcoded content into a flexible, blocks-based schema that empowers marketing teams to move independently.` : `You are a Senior Content Architect. Your mission is to integrate Dyrected CMS into a NEW ${frameworkLabel} project. Your priority is DATA PRESERVATION and creating a CMS that empowers marketing teams to move independently without raising tickets to engineering.`;
878
- const sections = [
879
- missionText,
880
- buildEnvironmentSection(frameworkLabel, isSelfHosted, config),
881
- buildDiagnosticSection(),
882
- buildConstraintsSection(),
883
- buildSchemaRulesSection(),
884
- buildDoNotSection(),
885
- buildTechnicalReferenceSection(),
886
- buildDeliverablesSection(),
887
- buildFrameworkSection(activeTab, isSelfHosted, config)
888
- ];
889
- return sections.join("\n");
890
- }
891
-
892
80
  // src/index.ts
893
81
  var DyrectedError = class extends Error {
894
82
  statusCode;
@@ -972,12 +160,19 @@ var DyrectedClient = class {
972
160
  normalizedArgs.where = JSON.stringify(normalizedArgs.where);
973
161
  }
974
162
  const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
975
- const res = await this.request(`/api/collections/${collection}${query}`);
163
+ const res = await this.request(
164
+ `/api/collections/${collection}${query}`
165
+ );
976
166
  if (res.docs.length === 0 && initialData && initialData.length > 0) {
977
167
  this.request(`/api/collections/${collection}/seed`, {
978
168
  method: "POST",
979
169
  body: JSON.stringify({ data: initialData })
980
- }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed collection "${collection}":`, err));
170
+ }).catch(
171
+ (err) => console.error(
172
+ `[dyrected/sdk] Failed to auto-seed collection "${collection}":`,
173
+ err
174
+ )
175
+ );
981
176
  return {
982
177
  docs: initialData,
983
178
  total: initialData.length,
@@ -996,7 +191,10 @@ var DyrectedClient = class {
996
191
  collection(slug) {
997
192
  return {
998
193
  find: (args) => {
999
- const qb = new QueryBuilder(slug, (c, a) => this.find(c, a));
194
+ const qb = new QueryBuilder(
195
+ slug,
196
+ (c, a) => this.find(c, a)
197
+ );
1000
198
  if (args) {
1001
199
  if (args.where) qb.where(args.where);
1002
200
  if (args.sort) qb.sort(args.sort);
@@ -1032,7 +230,9 @@ var DyrectedClient = class {
1032
230
  /** Return the currently authenticated user (requires a token via setToken). */
1033
231
  me: () => this.request(`/api/collections/${slug}/me`),
1034
232
  /** Issue a fresh token for the currently authenticated user. */
1035
- refreshToken: () => this.request(`/api/collections/${slug}/refresh-token`, { method: "POST" }),
233
+ refreshToken: () => this.request(`/api/collections/${slug}/refresh-token`, {
234
+ method: "POST"
235
+ }),
1036
236
  /** Check if this auth collection has any users (initialized). */
1037
237
  isInitialized: () => this.request(`/api/collections/${slug}/init`),
1038
238
  /** Register the very first user in an empty auth collection. */
@@ -1073,7 +273,39 @@ var DyrectedClient = class {
1073
273
  resetPassword: (token, password) => this.request(`/api/collections/${slug}/reset-password`, {
1074
274
  method: "POST",
1075
275
  body: JSON.stringify({ token, password })
1076
- })
276
+ }),
277
+ /**
278
+ * Perform a workflow transition on a single document.
279
+ *
280
+ * @param id - Document ID to transition.
281
+ * @param transitionName - The transition key (e.g. `'submit'`, `'publish'`, `'reject'`).
282
+ * @param opts - Optional `expectedRevision` (optimistic concurrency) and `comment`.
283
+ * @returns The updated document with refreshed `_workflow` metadata.
284
+ *
285
+ * @example
286
+ * // Publisher approves a submission
287
+ * const updated = await client.collection('posts').transition(id, 'publish')
288
+ *
289
+ * // Editor requests changes with a comment
290
+ * const updated = await client.collection('posts').transition(id, 'reject', {
291
+ * expectedRevision: doc._workflow.revision,
292
+ * comment: 'Please add more detail to section 2.',
293
+ * })
294
+ */
295
+ transition: (id, transitionName, opts) => this.transition(
296
+ slug,
297
+ id,
298
+ transitionName,
299
+ opts
300
+ ),
301
+ /**
302
+ * Fetch the workflow history for a single document — every transition that
303
+ * has ever been performed, newest first.
304
+ *
305
+ * @param id - Document ID.
306
+ * @param args - Optional `limit` (default 50, max 100).
307
+ */
308
+ workflowHistory: (id, args = {}) => this.workflowHistory(slug, id, args)
1077
309
  };
1078
310
  }
1079
311
  /**
@@ -1098,7 +330,10 @@ var DyrectedClient = class {
1098
330
  method: "POST",
1099
331
  body: JSON.stringify({ data: [{ id, ...initialData }] })
1100
332
  }).catch(
1101
- (err2) => console.error(`[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`, err2)
333
+ (err2) => console.error(
334
+ `[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`,
335
+ err2
336
+ )
1102
337
  );
1103
338
  return initialData;
1104
339
  }
@@ -1122,6 +357,44 @@ var DyrectedClient = class {
1122
357
  method: "DELETE"
1123
358
  });
1124
359
  }
360
+ /**
361
+ * Perform a workflow transition on a document.
362
+ *
363
+ * Sends `POST /api/collections/:collection/:id/transitions/:transition`.
364
+ * Requires the client to have a valid bearer token set via `setToken()`.
365
+ *
366
+ * @param collection - Collection slug.
367
+ * @param id - Document ID.
368
+ * @param transitionName - Transition key defined in `WorkflowConfig.transitions`.
369
+ * @param opts - Optional concurrency guard and comment.
370
+ *
371
+ * @example
372
+ * const updated = await client.transition('posts', postId, 'publish')
373
+ */
374
+ async transition(collection, id, transitionName, opts = {}) {
375
+ return this.request(
376
+ `/api/collections/${collection}/${id}/transitions/${encodeURIComponent(transitionName)}`,
377
+ {
378
+ method: "POST",
379
+ body: JSON.stringify(opts)
380
+ }
381
+ );
382
+ }
383
+ /**
384
+ * Fetch the workflow history for a document.
385
+ *
386
+ * Sends `GET /api/collections/:collection/:id/workflow-history`.
387
+ *
388
+ * @param collection - Collection slug.
389
+ * @param id - Document ID.
390
+ * @param args - Optional `limit` (max 100).
391
+ */
392
+ async workflowHistory(collection, id, args = {}) {
393
+ const query = args.limit ? `?limit=${args.limit}` : "";
394
+ return this.request(
395
+ `/api/collections/${collection}/${id}/workflow-history${query}`
396
+ );
397
+ }
1125
398
  async deleteMany(collection, ids) {
1126
399
  return this.request(`/api/collections/${collection}/delete-many`, {
1127
400
  method: "DELETE",
@@ -1137,7 +410,12 @@ var DyrectedClient = class {
1137
410
  this.request(`/api/globals/${slug}/seed`, {
1138
411
  method: "POST",
1139
412
  body: JSON.stringify({ data: initialData })
1140
- }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err));
413
+ }).catch(
414
+ (err) => console.error(
415
+ `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
416
+ err
417
+ )
418
+ );
1141
419
  return initialData;
1142
420
  }
1143
421
  return res;
@@ -1146,7 +424,12 @@ var DyrectedClient = class {
1146
424
  this.request(`/api/globals/${slug}/seed`, {
1147
425
  method: "POST",
1148
426
  body: JSON.stringify({ data: initialData })
1149
- }).catch((err2) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err2));
427
+ }).catch(
428
+ (err2) => console.error(
429
+ `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
430
+ err2
431
+ )
432
+ );
1150
433
  return initialData;
1151
434
  }
1152
435
  throw err;
@@ -1208,11 +491,17 @@ var DyrectedClient = class {
1208
491
  if (!res.ok) {
1209
492
  const body = await res.json().catch(() => ({ message: "Unknown error" }));
1210
493
  if (res.status === 429 && typeof window !== "undefined") {
1211
- window.dispatchEvent(new CustomEvent("dyrected:rate-limit", {
1212
- detail: { message: body.message, code: body.code }
1213
- }));
494
+ window.dispatchEvent(
495
+ new CustomEvent("dyrected:rate-limit", {
496
+ detail: { message: body.message, code: body.code }
497
+ })
498
+ );
1214
499
  }
1215
- throw new DyrectedError(body.message || `Request failed with status ${res.status}`, res.status, body.code);
500
+ throw new DyrectedError(
501
+ body.message || `Request failed with status ${res.status}`,
502
+ res.status,
503
+ body.code
504
+ );
1216
505
  }
1217
506
  return res.json();
1218
507
  }
@@ -1225,7 +514,5 @@ function createClient(config) {
1225
514
  export {
1226
515
  DyrectedClient,
1227
516
  DyrectedError,
1228
- createClient,
1229
- generateAIPrompt,
1230
- generateFreshSetupPrompt
517
+ createClient
1231
518
  };