@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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { PaginatedResult, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
- export { Block, CollectionConfig, Field, FieldType, GlobalConfig, FileData as Media, PaginatedResult } from '@dyrected/core';
1
+ import { PaginatedResult, WorkflowMetadata, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
+ export { AdminIconName, Block, CollectionConfig, Field, FieldType, GlobalConfig, LifecycleEvent, FileData as Media, PaginatedResult, WorkflowMetadata } from '@dyrected/core';
3
3
 
4
4
  interface QueryArgs {
5
5
  limit?: number;
@@ -24,18 +24,36 @@ declare class QueryBuilder<T = any> {
24
24
  then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
25
25
  }
26
26
 
27
- interface SetupPromptConfig {
28
- siteName?: string;
29
- siteId?: string;
30
- apiKey?: string;
31
- baseUrl?: string;
32
- isSelfHosted?: boolean;
33
- existingSite?: boolean;
34
- defaultTechStack?: string;
27
+ /** Shape of a document returned from a workflow-enabled collection. */
28
+ interface WorkflowDocument {
29
+ id: string;
30
+ _workflow: WorkflowMetadata;
31
+ [key: string]: unknown;
32
+ }
33
+ /** Options accepted by `client.transition()`. */
34
+ interface TransitionOptions {
35
+ /**
36
+ * The revision number currently shown to the user. When provided, the server
37
+ * rejects the transition if the document has changed since it was loaded,
38
+ * preventing lost-update races.
39
+ */
40
+ expectedRevision?: number;
41
+ /** Required for transitions that have `requireComment: true` (e.g. `reject`). */
42
+ comment?: string;
43
+ }
44
+ /** A single workflow history entry returned by `client.workflowHistory()`. */
45
+ interface WorkflowHistoryEntry {
46
+ id: string;
47
+ collection: string;
48
+ documentId: string;
49
+ transition: string;
50
+ from: string;
51
+ to: string;
52
+ revision: number;
53
+ comment: string | null;
54
+ actorId: string | null;
55
+ createdAt: string;
35
56
  }
36
- declare function generateFreshSetupPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
37
- declare function generateAIPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
38
-
39
57
  type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends GlobalConfig<infer TDoc> ? TDoc : never;
40
58
  /**
41
59
  * Derives a typed `TSchema` from your exported collection and global config constants.
@@ -228,6 +246,35 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
228
246
  success: boolean;
229
247
  message: string;
230
248
  }>;
249
+ /**
250
+ * Perform a workflow transition on a single document.
251
+ *
252
+ * @param id - Document ID to transition.
253
+ * @param transitionName - The transition key (e.g. `'submit'`, `'publish'`, `'reject'`).
254
+ * @param opts - Optional `expectedRevision` (optimistic concurrency) and `comment`.
255
+ * @returns The updated document with refreshed `_workflow` metadata.
256
+ *
257
+ * @example
258
+ * // Publisher approves a submission
259
+ * const updated = await client.collection('posts').transition(id, 'publish')
260
+ *
261
+ * // Editor requests changes with a comment
262
+ * const updated = await client.collection('posts').transition(id, 'reject', {
263
+ * expectedRevision: doc._workflow.revision,
264
+ * comment: 'Please add more detail to section 2.',
265
+ * })
266
+ */
267
+ transition: (id: string, transitionName: string, opts?: TransitionOptions) => Promise<TSchema["collections"][K]>;
268
+ /**
269
+ * Fetch the workflow history for a single document — every transition that
270
+ * has ever been performed, newest first.
271
+ *
272
+ * @param id - Document ID.
273
+ * @param args - Optional `limit` (default 50, max 100).
274
+ */
275
+ workflowHistory: (id: string, args?: {
276
+ limit?: number;
277
+ }) => Promise<PaginatedResult<WorkflowHistoryEntry>>;
231
278
  };
232
279
  /**
233
280
  * Access a global by its slug with a fluent builder.
@@ -250,6 +297,33 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
250
297
  delete(collection: string, id: string): Promise<{
251
298
  message: string;
252
299
  }>;
300
+ /**
301
+ * Perform a workflow transition on a document.
302
+ *
303
+ * Sends `POST /api/collections/:collection/:id/transitions/:transition`.
304
+ * Requires the client to have a valid bearer token set via `setToken()`.
305
+ *
306
+ * @param collection - Collection slug.
307
+ * @param id - Document ID.
308
+ * @param transitionName - Transition key defined in `WorkflowConfig.transitions`.
309
+ * @param opts - Optional concurrency guard and comment.
310
+ *
311
+ * @example
312
+ * const updated = await client.transition('posts', postId, 'publish')
313
+ */
314
+ transition<T = WorkflowDocument>(collection: string, id: string, transitionName: string, opts?: TransitionOptions): Promise<T>;
315
+ /**
316
+ * Fetch the workflow history for a document.
317
+ *
318
+ * Sends `GET /api/collections/:collection/:id/workflow-history`.
319
+ *
320
+ * @param collection - Collection slug.
321
+ * @param id - Document ID.
322
+ * @param args - Optional `limit` (max 100).
323
+ */
324
+ workflowHistory(collection: string, id: string, args?: {
325
+ limit?: number;
326
+ }): Promise<PaginatedResult<WorkflowHistoryEntry>>;
253
327
  deleteMany(collection: string, ids: string[]): Promise<{
254
328
  message: string;
255
329
  }>;
@@ -275,4 +349,4 @@ declare function createClient<TSchema extends {
275
349
  globals: any;
276
350
  } = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
277
351
 
278
- export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
352
+ export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type TransitionOptions, type WorkflowDocument, type WorkflowHistoryEntry, createClient };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { PaginatedResult, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
- export { Block, CollectionConfig, Field, FieldType, GlobalConfig, FileData as Media, PaginatedResult } from '@dyrected/core';
1
+ import { PaginatedResult, WorkflowMetadata, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
+ export { AdminIconName, Block, CollectionConfig, Field, FieldType, GlobalConfig, LifecycleEvent, FileData as Media, PaginatedResult, WorkflowMetadata } from '@dyrected/core';
3
3
 
4
4
  interface QueryArgs {
5
5
  limit?: number;
@@ -24,18 +24,36 @@ declare class QueryBuilder<T = any> {
24
24
  then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
25
25
  }
26
26
 
27
- interface SetupPromptConfig {
28
- siteName?: string;
29
- siteId?: string;
30
- apiKey?: string;
31
- baseUrl?: string;
32
- isSelfHosted?: boolean;
33
- existingSite?: boolean;
34
- defaultTechStack?: string;
27
+ /** Shape of a document returned from a workflow-enabled collection. */
28
+ interface WorkflowDocument {
29
+ id: string;
30
+ _workflow: WorkflowMetadata;
31
+ [key: string]: unknown;
32
+ }
33
+ /** Options accepted by `client.transition()`. */
34
+ interface TransitionOptions {
35
+ /**
36
+ * The revision number currently shown to the user. When provided, the server
37
+ * rejects the transition if the document has changed since it was loaded,
38
+ * preventing lost-update races.
39
+ */
40
+ expectedRevision?: number;
41
+ /** Required for transitions that have `requireComment: true` (e.g. `reject`). */
42
+ comment?: string;
43
+ }
44
+ /** A single workflow history entry returned by `client.workflowHistory()`. */
45
+ interface WorkflowHistoryEntry {
46
+ id: string;
47
+ collection: string;
48
+ documentId: string;
49
+ transition: string;
50
+ from: string;
51
+ to: string;
52
+ revision: number;
53
+ comment: string | null;
54
+ actorId: string | null;
55
+ createdAt: string;
35
56
  }
36
- declare function generateFreshSetupPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
37
- declare function generateAIPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
38
-
39
57
  type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends GlobalConfig<infer TDoc> ? TDoc : never;
40
58
  /**
41
59
  * Derives a typed `TSchema` from your exported collection and global config constants.
@@ -228,6 +246,35 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
228
246
  success: boolean;
229
247
  message: string;
230
248
  }>;
249
+ /**
250
+ * Perform a workflow transition on a single document.
251
+ *
252
+ * @param id - Document ID to transition.
253
+ * @param transitionName - The transition key (e.g. `'submit'`, `'publish'`, `'reject'`).
254
+ * @param opts - Optional `expectedRevision` (optimistic concurrency) and `comment`.
255
+ * @returns The updated document with refreshed `_workflow` metadata.
256
+ *
257
+ * @example
258
+ * // Publisher approves a submission
259
+ * const updated = await client.collection('posts').transition(id, 'publish')
260
+ *
261
+ * // Editor requests changes with a comment
262
+ * const updated = await client.collection('posts').transition(id, 'reject', {
263
+ * expectedRevision: doc._workflow.revision,
264
+ * comment: 'Please add more detail to section 2.',
265
+ * })
266
+ */
267
+ transition: (id: string, transitionName: string, opts?: TransitionOptions) => Promise<TSchema["collections"][K]>;
268
+ /**
269
+ * Fetch the workflow history for a single document — every transition that
270
+ * has ever been performed, newest first.
271
+ *
272
+ * @param id - Document ID.
273
+ * @param args - Optional `limit` (default 50, max 100).
274
+ */
275
+ workflowHistory: (id: string, args?: {
276
+ limit?: number;
277
+ }) => Promise<PaginatedResult<WorkflowHistoryEntry>>;
231
278
  };
232
279
  /**
233
280
  * Access a global by its slug with a fluent builder.
@@ -250,6 +297,33 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
250
297
  delete(collection: string, id: string): Promise<{
251
298
  message: string;
252
299
  }>;
300
+ /**
301
+ * Perform a workflow transition on a document.
302
+ *
303
+ * Sends `POST /api/collections/:collection/:id/transitions/:transition`.
304
+ * Requires the client to have a valid bearer token set via `setToken()`.
305
+ *
306
+ * @param collection - Collection slug.
307
+ * @param id - Document ID.
308
+ * @param transitionName - Transition key defined in `WorkflowConfig.transitions`.
309
+ * @param opts - Optional concurrency guard and comment.
310
+ *
311
+ * @example
312
+ * const updated = await client.transition('posts', postId, 'publish')
313
+ */
314
+ transition<T = WorkflowDocument>(collection: string, id: string, transitionName: string, opts?: TransitionOptions): Promise<T>;
315
+ /**
316
+ * Fetch the workflow history for a document.
317
+ *
318
+ * Sends `GET /api/collections/:collection/:id/workflow-history`.
319
+ *
320
+ * @param collection - Collection slug.
321
+ * @param id - Document ID.
322
+ * @param args - Optional `limit` (max 100).
323
+ */
324
+ workflowHistory(collection: string, id: string, args?: {
325
+ limit?: number;
326
+ }): Promise<PaginatedResult<WorkflowHistoryEntry>>;
253
327
  deleteMany(collection: string, ids: string[]): Promise<{
254
328
  message: string;
255
329
  }>;
@@ -275,4 +349,4 @@ declare function createClient<TSchema extends {
275
349
  globals: any;
276
350
  } = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
277
351
 
278
- export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
352
+ export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type TransitionOptions, type WorkflowDocument, type WorkflowHistoryEntry, createClient };