@proteos/sdk 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +40 -0
  2. package/dist/chunk-7RGN4E22.cjs +1185 -0
  3. package/dist/chunk-7RGN4E22.cjs.map +1 -0
  4. package/dist/chunk-XJP5WCRZ.js +1125 -0
  5. package/dist/chunk-XJP5WCRZ.js.map +1 -0
  6. package/dist/index.cjs +2384 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +5225 -0
  9. package/dist/index.d.ts +5225 -0
  10. package/dist/index.js +2146 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/meta/index.cjs +204 -0
  13. package/dist/meta/index.cjs.map +1 -0
  14. package/dist/meta/index.d.cts +2 -0
  15. package/dist/meta/index.d.ts +2 -0
  16. package/dist/meta/index.js +3 -0
  17. package/dist/meta/index.js.map +1 -0
  18. package/dist/types-BNsjfU8N.d.cts +3299 -0
  19. package/dist/types-BNsjfU8N.d.ts +3299 -0
  20. package/package.json +86 -0
  21. package/src/agent/agents.ts +53 -0
  22. package/src/agent/index.ts +134 -0
  23. package/src/agent/mcp-servers.ts +102 -0
  24. package/src/agent/prompts.ts +80 -0
  25. package/src/agent/session-types.ts +397 -0
  26. package/src/agent/sessions.ts +197 -0
  27. package/src/agent/skills.ts +89 -0
  28. package/src/agent/tools.ts +53 -0
  29. package/src/agent/types.ts +362 -0
  30. package/src/auth/index.ts +111 -0
  31. package/src/auth/me.ts +46 -0
  32. package/src/auth/organizations.ts +128 -0
  33. package/src/auth/platform-entities.ts +78 -0
  34. package/src/auth/roles.ts +213 -0
  35. package/src/auth/types.ts +294 -0
  36. package/src/auth/users.ts +226 -0
  37. package/src/client.ts +441 -0
  38. package/src/connector/index.ts +120 -0
  39. package/src/connector/types.ts +150 -0
  40. package/src/conversation/index.ts +297 -0
  41. package/src/conversation/types.ts +590 -0
  42. package/src/conversation/voice.ts +123 -0
  43. package/src/data/index.ts +53 -0
  44. package/src/data/queries.ts +66 -0
  45. package/src/data/records.ts +122 -0
  46. package/src/data/types.ts +89 -0
  47. package/src/errors.ts +148 -0
  48. package/src/events/index.ts +172 -0
  49. package/src/events/types.ts +77 -0
  50. package/src/functions/actions.ts +95 -0
  51. package/src/functions/index.ts +32 -0
  52. package/src/functions/types.ts +71 -0
  53. package/src/http/index.ts +2 -0
  54. package/src/http/query-params.ts +106 -0
  55. package/src/index.ts +598 -0
  56. package/src/iterator.ts +183 -0
  57. package/src/knowledge/graph.ts +35 -0
  58. package/src/knowledge/index.ts +104 -0
  59. package/src/knowledge/labels.ts +70 -0
  60. package/src/knowledge/links.ts +65 -0
  61. package/src/knowledge/nodes.ts +198 -0
  62. package/src/knowledge/record-links.ts +66 -0
  63. package/src/knowledge/types.ts +569 -0
  64. package/src/meta/apps.ts +107 -0
  65. package/src/meta/components.ts +124 -0
  66. package/src/meta/currency/index.ts +202 -0
  67. package/src/meta/entities.ts +193 -0
  68. package/src/meta/filters.ts +76 -0
  69. package/src/meta/index.ts +227 -0
  70. package/src/meta/layout/common-props.ts +93 -0
  71. package/src/meta/layout/control-registry.json +70 -0
  72. package/src/meta/layout/control-registry.ts +92 -0
  73. package/src/meta/layout/elements.ts +203 -0
  74. package/src/meta/layout/index.ts +41 -0
  75. package/src/meta/layout/page-layout.ts +35 -0
  76. package/src/meta/layout/size-value.ts +27 -0
  77. package/src/meta/list-views.ts +109 -0
  78. package/src/meta/lists.ts +104 -0
  79. package/src/meta/menu-configurations.ts +128 -0
  80. package/src/meta/modules.ts +159 -0
  81. package/src/meta/pages.ts +106 -0
  82. package/src/meta/types.ts +1115 -0
  83. package/src/meta/variables.ts +98 -0
  84. package/src/storage/files.ts +183 -0
  85. package/src/storage/index.ts +33 -0
  86. package/src/storage/types.ts +70 -0
  87. package/src/types/common.ts +143 -0
  88. package/src/types/index.ts +28 -0
  89. package/src/types/options.ts +95 -0
  90. package/src/workflow/executions.ts +99 -0
  91. package/src/workflow/index.ts +109 -0
  92. package/src/workflow/node-types.ts +50 -0
  93. package/src/workflow/types.ts +658 -0
  94. package/src/workflow/workflows.ts +152 -0
@@ -0,0 +1,1115 @@
1
+ import { z } from 'zod'
2
+ import type { AuditFields, ListOptions } from '../types/common.js'
3
+ import { AuditFieldsSchema } from '../types/common.js'
4
+ import { type PageLayout, PageLayoutSchema } from './layout/page-layout.js'
5
+
6
+ export type { PageLayout } from './layout/page-layout.js'
7
+
8
+ // ============================================================================
9
+ // Shared Types
10
+ // ============================================================================
11
+
12
+ /**
13
+ * Base list options with source filters for the meta namespace.
14
+ */
15
+ export interface MetaListOptions extends ListOptions {
16
+ created_by?: string
17
+ updated_by?: string
18
+ }
19
+
20
+ // ============================================================================
21
+ // Entity Types
22
+ // ============================================================================
23
+
24
+ /**
25
+ * Attribute type — canonical to the Go `model.AttributeType` union
26
+ * (packages/go/model/meta/attribute.go). The members below are the
27
+ * full set; format/structural variation lives on `Attribute.meta` (see
28
+ * `AttributeMeta` below), not on the type discriminator.
29
+ */
30
+ export type AttributeType =
31
+ | 'string'
32
+ | 'number'
33
+ | 'integer'
34
+ | 'boolean'
35
+ | 'array'
36
+ | 'object'
37
+ | 'datetime'
38
+ | 'enum'
39
+ | 'relation'
40
+ | 'user'
41
+ | 'currency'
42
+ | 'knowledge-text'
43
+ | 'file'
44
+
45
+ // ── Attribute meta (sub-discriminators) ──────────────────────────────
46
+ // Mirrors the Go `*AttributeMeta` types in
47
+ // packages/go/model/attribute-{string,number,datetime,array,object,enum}.go.
48
+
49
+ /** JSON-Schema string formats carried by `string` attributes. */
50
+ export type StringFormat = 'email' | 'uri' | 'uuid' | 'hostname' | 'ipv4' | 'ipv6'
51
+
52
+ export interface StringAttributeMeta {
53
+ format?: StringFormat
54
+ min_length?: number
55
+ max_length?: number
56
+ pattern?: string
57
+ }
58
+
59
+ export interface NumberAttributeMeta {
60
+ minimum?: number
61
+ maximum?: number
62
+ exclusive_minimum?: number
63
+ exclusive_maximum?: number
64
+ multiple_of?: number
65
+ }
66
+
67
+ /** Datetime storage/display behavior. `format` is required. */
68
+ export type DatetimeFormat = 'date-time' | 'date' | 'time' | 'duration'
69
+
70
+ export interface DatetimeAttributeMeta {
71
+ format: DatetimeFormat
72
+ minimum?: string
73
+ maximum?: string
74
+ }
75
+
76
+ export interface ArrayAttributeMeta {
77
+ items?: Attribute
78
+ min_items?: number
79
+ max_items?: number
80
+ items_must_be_unique?: boolean
81
+ }
82
+
83
+ export interface ObjectAttributeMeta {
84
+ attributes?: Attribute[]
85
+ }
86
+
87
+ export interface EnumValue {
88
+ value: string
89
+ label?: string
90
+ description?: string
91
+ }
92
+
93
+ export interface EnumAttributeMeta {
94
+ values: EnumValue[]
95
+ }
96
+
97
+ /**
98
+ * Policy applied to the host row when the related row is deleted. Mirror
99
+ * of `model.OnDeleteAction`. The runtime semantic is enforced at the
100
+ * data-service level; this metadata declares the intent.
101
+ */
102
+ export type OnDeleteAction = 'cascade' | 'restrict' | 'set-null'
103
+
104
+ export const OnDeleteActionSchema = z.enum(['cascade', 'restrict', 'set-null'])
105
+
106
+ /**
107
+ * Metadata for a `relation`-typed attribute. The attribute is a foreign-key
108
+ * column on the host entity pointing at `related_attribute` on
109
+ * `related_entity_slug`. `predicate` reads from the host outward (e.g. on
110
+ * `Order.customerId` with `predicate: "is placed by"`, the sentence is
111
+ * "Order is placed by Customer").
112
+ */
113
+ export interface RelationAttributeMeta {
114
+ related_entity_slug: string
115
+ related_attribute: string
116
+ predicate: string
117
+ description?: string
118
+ on_delete: OnDeleteAction
119
+ }
120
+
121
+ export const RelationAttributeMetaSchema = z.object({
122
+ related_entity_slug: z.string(),
123
+ related_attribute: z.string(),
124
+ predicate: z.string(),
125
+ description: z.string().optional(),
126
+ on_delete: OnDeleteActionSchema,
127
+ })
128
+
129
+ /**
130
+ * Metadata for a `user`-typed attribute. A user attribute stores a
131
+ * {@link UserRef} `{ type, id }` (the account-service identity plus its
132
+ * kind), rendered as a people picker that resolves and filters on `id`. Mirror
133
+ * of the Go `metamodel.UserAttributeMeta`.
134
+ *
135
+ * It carries no required configuration today; the shape exists for parity
136
+ * with the other metas and reserves room for future options (e.g.
137
+ * multi-user selection).
138
+ */
139
+ export interface UserAttributeMeta {
140
+ description?: string
141
+ }
142
+
143
+ export const UserAttributeMetaSchema = z.object({
144
+ description: z.string().optional(),
145
+ })
146
+
147
+ /**
148
+ * The stored value of a `currency`-typed attribute: an exact decimal `amount`
149
+ * (a STRING, never a JS number — preserves financial-system precision and
150
+ * trailing zeros) paired with an ISO-4217 `currency_code`. This is the wire
151
+ * shape; the `@proteos/ui` `CurrencyInput` and the web control both read/write
152
+ * it directly to avoid an adapter.
153
+ */
154
+ export interface CurrencyValue {
155
+ amount: string
156
+ currency_code: string
157
+ }
158
+
159
+ /**
160
+ * Metadata for a `currency`-typed attribute. Both fields are optional: when
161
+ * `allowed_currency_codes` is empty/absent, any ISO-4217 code is accepted;
162
+ * `default_currency_code` seeds the picker for new values and must be a member
163
+ * of `allowed_currency_codes` when that allow-list is set. Mirror of the Go
164
+ * `metamodel.CurrencyAttributeMeta`.
165
+ */
166
+ export interface CurrencyAttributeMeta {
167
+ default_currency_code?: string
168
+ allowed_currency_codes?: string[]
169
+ }
170
+
171
+ export const CurrencyAttributeMetaSchema = z.object({
172
+ default_currency_code: z.string().optional(),
173
+ allowed_currency_codes: z.array(z.string()).optional(),
174
+ })
175
+
176
+ /**
177
+ * The value of a `knowledge-text`-typed attribute: a reference to the
178
+ * knowledge node (knowledge-service) that owns the text body. The record
179
+ * persists only `{ id }`; `content` is transient — accepted on writes (the
180
+ * text to materialize into the node) and filled on single-record reads.
181
+ * Clients may also write a bare string as shorthand for `{ content }`.
182
+ * Mirror of the Go `common.KnowledgeNodeRef`.
183
+ */
184
+ export interface KnowledgeNodeRef {
185
+ id: string
186
+ content?: string
187
+ }
188
+
189
+ /**
190
+ * Metadata for a `knowledge-text`-typed attribute. The value is a
191
+ * {@link KnowledgeNodeRef}; the data-service materializes client-sent text
192
+ * into a knowledge node before persisting. Mirror of the Go
193
+ * `metamodel.KnowledgeTextAttributeMeta`.
194
+ *
195
+ * It carries no required configuration today; the shape exists for parity
196
+ * with the other metas and reserves room for future options (e.g. node
197
+ * labels, status overrides).
198
+ */
199
+ export interface KnowledgeTextAttributeMeta {
200
+ description?: string
201
+ }
202
+
203
+ export const KnowledgeTextAttributeMetaSchema = z.object({
204
+ description: z.string().optional(),
205
+ })
206
+
207
+ /**
208
+ * Metadata for a `file`-typed attribute. The value is a {@link FileRef}
209
+ * `{ id, name }` referencing a storage-service file; the frontend uploads to
210
+ * the storage-service and writes the resulting id + name. Mirror of the Go
211
+ * `metamodel.FileAttributeMeta`.
212
+ *
213
+ * It carries no required configuration today; the shape exists for parity with
214
+ * the other metas and reserves room for future options (e.g. accepted content
215
+ * types, max size).
216
+ */
217
+ export interface FileAttributeMeta {
218
+ description?: string
219
+ }
220
+
221
+ export const FileAttributeMetaSchema = z.object({
222
+ description: z.string().optional(),
223
+ })
224
+
225
+ /**
226
+ * Discriminated union of attribute metas. The wire JSON carries the
227
+ * appropriate shape based on `Attribute.type`; runtime consumers can
228
+ * narrow via the `type` field.
229
+ */
230
+ export type AttributeMeta =
231
+ | StringAttributeMeta
232
+ | NumberAttributeMeta
233
+ | DatetimeAttributeMeta
234
+ | ArrayAttributeMeta
235
+ | ObjectAttributeMeta
236
+ | EnumAttributeMeta
237
+ | RelationAttributeMeta
238
+ | UserAttributeMeta
239
+ | CurrencyAttributeMeta
240
+ | KnowledgeTextAttributeMeta
241
+ | FileAttributeMeta
242
+
243
+ /**
244
+ * Entity attribute definition. Mirrors `model.Attribute` in the Go SDK.
245
+ */
246
+ export interface Attribute {
247
+ name: string
248
+ type: AttributeType
249
+ label: string
250
+ description?: string
251
+ is_required: boolean
252
+ is_nullable?: boolean
253
+ is_unique: boolean
254
+ is_read_only?: boolean
255
+ /**
256
+ * Platform-managed flag. Marks the canonical platform attributes (id,
257
+ * created_at, updated_at, created_by, updated_by) — auto-added to every
258
+ * entity, locked in the designer, and rejected from client redefinition.
259
+ * Mirrors `IsPlatformManaged` in the Go `metamodel.Attribute`.
260
+ */
261
+ is_platform_managed?: boolean
262
+ default_value?: unknown
263
+ /**
264
+ * Type-specific metadata. The concrete shape is determined by `type`
265
+ * — e.g. `type: 'string'` carries `StringAttributeMeta`. The wire
266
+ * field name is `meta`; `options` is an older alias still emitted by
267
+ * some service paths and accepted for backwards compatibility.
268
+ */
269
+ meta?: AttributeMeta
270
+ /** @deprecated Older wire alias for `meta`. Prefer `meta`. */
271
+ options?: Record<string, unknown>
272
+ }
273
+
274
+ /**
275
+ * Canonical platform attribute names — the system-managed set every entity
276
+ * carries. Mirrors `metamodel.PlatformAttribute*` constants in the Go model.
277
+ */
278
+ export const PLATFORM_ATTRIBUTE_NAMES = [
279
+ 'id',
280
+ 'created_at',
281
+ 'updated_at',
282
+ 'created_by',
283
+ 'updated_by',
284
+ ] as const
285
+
286
+ /** True when `name` is one of the canonical platform attributes. */
287
+ export function isPlatformAttributeName(name: string): boolean {
288
+ return (PLATFORM_ATTRIBUTE_NAMES as readonly string[]).includes(name)
289
+ }
290
+
291
+ /**
292
+ * The canonical platform attributes, in display order. Mirror of the Go
293
+ * `metamodel.PlatformAttributes()`. Used by the entity designer to seed new
294
+ * entities; the backend re-asserts these on save regardless.
295
+ */
296
+ export function platformAttributes(): Attribute[] {
297
+ return [
298
+ {
299
+ name: 'id',
300
+ type: 'string',
301
+ label: 'Id',
302
+ description: 'Unique identifier of the record.',
303
+ is_required: false,
304
+ is_unique: true,
305
+ is_read_only: true,
306
+ is_platform_managed: true,
307
+ },
308
+ {
309
+ name: 'created_at',
310
+ type: 'datetime',
311
+ label: 'Created At',
312
+ description: 'Timestamp when the record was created.',
313
+ is_required: false,
314
+ is_unique: false,
315
+ is_read_only: true,
316
+ is_platform_managed: true,
317
+ meta: { format: 'date-time' },
318
+ },
319
+ {
320
+ name: 'updated_at',
321
+ type: 'datetime',
322
+ label: 'Updated At',
323
+ description: 'Timestamp when the record was last updated.',
324
+ is_required: false,
325
+ is_unique: false,
326
+ is_read_only: true,
327
+ is_platform_managed: true,
328
+ meta: { format: 'date-time' },
329
+ },
330
+ {
331
+ name: 'created_by',
332
+ type: 'user',
333
+ label: 'Created By',
334
+ description: 'User who created the record ("platform" for system writes).',
335
+ is_required: false,
336
+ is_unique: false,
337
+ is_read_only: true,
338
+ is_platform_managed: true,
339
+ },
340
+ {
341
+ name: 'updated_by',
342
+ type: 'user',
343
+ label: 'Updated By',
344
+ description: 'User who last updated the record ("platform" for system writes).',
345
+ is_required: false,
346
+ is_unique: false,
347
+ is_read_only: true,
348
+ is_platform_managed: true,
349
+ },
350
+ ]
351
+ }
352
+
353
+ // Schema validation is intentionally lax on `type` (z.string()) and
354
+ // `meta` (z.unknown()) because (a) wire data may carry legacy values
355
+ // from older service deploys, and (b) the renderer narrows on
356
+ // `attribute.type` at the use site. Stricter narrowing happens in
357
+ // renderer-side helpers (e.g. `lookupControls(attr)` from the layout
358
+ // module), not in the schema parse.
359
+ export const AttributeSchema = z.object({
360
+ name: z.string(),
361
+ type: z.string(),
362
+ label: z.string(),
363
+ description: z.string().optional(),
364
+ is_required: z.boolean(),
365
+ is_nullable: z.boolean().optional(),
366
+ is_unique: z.boolean(),
367
+ is_read_only: z.boolean().optional(),
368
+ default_value: z.unknown().optional(),
369
+ meta: z.unknown().optional(),
370
+ options: z.record(z.unknown()).optional(),
371
+ })
372
+
373
+ /**
374
+ * Returns the typed `RelationAttributeMeta` when `attr` is a relation
375
+ * attribute with a valid meta shape; null otherwise. The `AttributeSchema`
376
+ * intentionally keeps `meta` lax, so callers that need the relation fields
377
+ * narrowed should go through this helper rather than casting.
378
+ */
379
+ export function parseRelationMeta(attr: Attribute): RelationAttributeMeta | null {
380
+ if (attr.type !== 'relation') return null
381
+ const parsed = RelationAttributeMetaSchema.safeParse(attr.meta)
382
+ return parsed.success ? parsed.data : null
383
+ }
384
+
385
+ /**
386
+ * Returns the typed `UserAttributeMeta` when `attr` is a user attribute;
387
+ * null otherwise. User meta is optional (and usually absent), so a user
388
+ * attribute with no meta still resolves to an empty `{}` rather than null.
389
+ */
390
+ export function parseCurrencyMeta(attr: Attribute): CurrencyAttributeMeta | null {
391
+ if (attr.type !== 'currency') return null
392
+ const parsed = CurrencyAttributeMetaSchema.safeParse(attr.meta ?? {})
393
+ return parsed.success ? parsed.data : null
394
+ }
395
+
396
+ export function parseUserMeta(attr: Attribute): UserAttributeMeta | null {
397
+ if (attr.type !== 'user') return null
398
+ if (attr.meta == null) return {}
399
+ const parsed = UserAttributeMetaSchema.safeParse(attr.meta)
400
+ return parsed.success ? parsed.data : {}
401
+ }
402
+
403
+ /**
404
+ * Returns the typed `KnowledgeTextAttributeMeta` when `attr` is a
405
+ * knowledge-text attribute; null otherwise. Knowledge-text meta is optional
406
+ * (and usually absent), so a knowledge-text attribute with no meta still
407
+ * resolves to an empty `{}` rather than null.
408
+ */
409
+ export function parseKnowledgeTextMeta(attr: Attribute): KnowledgeTextAttributeMeta | null {
410
+ if (attr.type !== 'knowledge-text') return null
411
+ if (attr.meta == null) return {}
412
+ const parsed = KnowledgeTextAttributeMetaSchema.safeParse(attr.meta)
413
+ return parsed.success ? parsed.data : {}
414
+ }
415
+
416
+ /**
417
+ * Returns the typed `FileAttributeMeta` when `attr` is a file attribute; null
418
+ * otherwise. File meta is optional (and usually absent), so a file attribute
419
+ * with no meta still resolves to an empty `{}` rather than null.
420
+ */
421
+ export function parseFileMeta(attr: Attribute): FileAttributeMeta | null {
422
+ if (attr.type !== 'file') return null
423
+ if (attr.meta == null) return {}
424
+ const parsed = FileAttributeMetaSchema.safeParse(attr.meta)
425
+ return parsed.success ? parsed.data : {}
426
+ }
427
+
428
+ /**
429
+ * Entity definition.
430
+ * Note: Entity uses `slug` as its primary identifier, not `id`.
431
+ */
432
+ export interface Entity extends AuditFields {
433
+ slug: string
434
+ name: string
435
+ description: string
436
+ is_remote: boolean
437
+ module_slug: string
438
+ /**
439
+ * Liquid template that renders a human-readable title for an instance
440
+ * (record) of this entity — e.g. `{{ first_name }} {{ last_name }}` for a
441
+ * Customer, `{{ number }}` for an Order. Empty string means "no template
442
+ * configured"; consumers fall back to the record id.
443
+ *
444
+ * Render via `renderRecordTitle(entity, record)` rather than evaluating
445
+ * the template directly, so the fallback chain stays consistent.
446
+ */
447
+ title_template: string
448
+ attributes: Attribute[]
449
+ }
450
+
451
+ export const EntitySchema = AuditFieldsSchema.extend({
452
+ slug: z.string(),
453
+ name: z.string(),
454
+ description: z.string(),
455
+ is_remote: z.boolean(),
456
+ module_slug: z.string(),
457
+ // Default keeps older API responses (pre-`title_template` rollout) parsing
458
+ // cleanly — the field is non-optional in the TS surface but tolerant on
459
+ // the wire.
460
+ title_template: z.string().default(''),
461
+ attributes: z.array(AttributeSchema),
462
+ })
463
+
464
+ /**
465
+ * Entity with JSON Schema representation.
466
+ */
467
+ export interface EntityWithSchema extends Entity {
468
+ schema: Record<string, unknown>
469
+ }
470
+
471
+ export const EntityWithSchemaSchema = EntitySchema.extend({
472
+ schema: z.record(z.unknown()),
473
+ })
474
+
475
+ /**
476
+ * Options for listing entities.
477
+ */
478
+ export interface ListEntitiesOptions extends MetaListOptions {
479
+ slug?: string
480
+ name?: string
481
+ is_remote?: boolean
482
+ module_slug?: string
483
+ }
484
+
485
+ /**
486
+ * Request to create an entity.
487
+ */
488
+ export interface CreateEntityRequest {
489
+ slug: string
490
+ name: string
491
+ is_remote: boolean
492
+ module_slug: string
493
+ description: string
494
+ title_template?: string
495
+ attributes: Attribute[]
496
+ }
497
+
498
+ /**
499
+ * Request to update an entity.
500
+ */
501
+ export interface UpdateEntityRequest {
502
+ name?: string
503
+ is_remote?: boolean
504
+ module_slug?: string
505
+ description?: string
506
+ title_template?: string
507
+ attributes?: Attribute[]
508
+ }
509
+
510
+ // ============================================================================
511
+ // Module Types
512
+ // ============================================================================
513
+
514
+ /**
515
+ * Module deployment status.
516
+ */
517
+ export type ModuleStatus =
518
+ | 'pending'
519
+ | 'deploying'
520
+ | 'active'
521
+ | 'failed'
522
+ | 'deactivating'
523
+ | 'inactive'
524
+
525
+ /**
526
+ * Module definition.
527
+ */
528
+ export interface Module extends AuditFields {
529
+ slug: string
530
+ org_id: string
531
+ name: string
532
+ description: string
533
+ version: string
534
+ file_id: string
535
+ status: ModuleStatus
536
+ status_details: string
537
+ is_deactivated: boolean
538
+ }
539
+
540
+ export const ModuleSchema = AuditFieldsSchema.extend({
541
+ slug: z.string(),
542
+ name: z.string(),
543
+ description: z.string(),
544
+ version: z.string(),
545
+ file_id: z.string(),
546
+ status: z.enum(['pending', 'deploying', 'active', 'failed', 'deactivating', 'inactive']),
547
+ status_details: z.string(),
548
+ is_deactivated: z.boolean(),
549
+ })
550
+
551
+ /**
552
+ * Options for listing modules.
553
+ */
554
+ export interface ListModulesOptions extends MetaListOptions {
555
+ slug?: string
556
+ name?: string
557
+ is_deactivated?: boolean
558
+ file_id?: string
559
+ status?: ModuleStatus
560
+ version?: string
561
+ }
562
+
563
+ /**
564
+ * Request to deploy a module.
565
+ */
566
+ export interface DeployModuleRequest {
567
+ slug: string
568
+ version: string
569
+ name: string
570
+ description: string
571
+ }
572
+
573
+ // ============================================================================
574
+ // Variable Types
575
+ // ============================================================================
576
+
577
+ /**
578
+ * Configuration/secret variable.
579
+ */
580
+ export interface Variable extends AuditFields {
581
+ id: string
582
+ org_id: string
583
+ key: string
584
+ value: string
585
+ is_secret: boolean
586
+ module: string
587
+ }
588
+
589
+ export const VariableSchema = AuditFieldsSchema.extend({
590
+ id: z.string(),
591
+ key: z.string(),
592
+ value: z.string(),
593
+ is_secret: z.boolean(),
594
+ module: z.string(),
595
+ })
596
+
597
+ /**
598
+ * Options for listing variables.
599
+ */
600
+ export interface ListVariablesOptions extends MetaListOptions {
601
+ id?: string
602
+ key?: string
603
+ is_secret?: boolean
604
+ module?: string
605
+ }
606
+
607
+ /**
608
+ * Request to create a variable.
609
+ */
610
+ export interface CreateVariableRequest {
611
+ key: string
612
+ value: string
613
+ is_secret: boolean
614
+ module: string
615
+ }
616
+
617
+ /**
618
+ * Request to update a variable.
619
+ */
620
+ export interface UpdateVariableRequest {
621
+ value?: string
622
+ }
623
+
624
+ // ============================================================================
625
+ // Component Types
626
+ // ============================================================================
627
+
628
+ /**
629
+ * UI component definition.
630
+ * Note: Component uses `slug` as its primary identifier, not `id`.
631
+ */
632
+ export interface Component extends AuditFields {
633
+ slug: string
634
+ org_id: string
635
+ name: string
636
+ description: string
637
+ module_slug: string
638
+ /** FK to the compiled, single-file ESM bundle in storage. Empty until deployed. Served via {@link ComponentService.bundleUrl}. */
639
+ bundle_file_id: string
640
+ /** FK to a tar.gz of the component source directory in storage (provenance / rebuild). Empty until deployed. */
641
+ source_file_id: string
642
+ /** The component's JSON Schema, driving the page-designer props editor + runtime validation. `null` until set. */
643
+ props_schema: Record<string, unknown> | null
644
+ }
645
+
646
+ export const ComponentSchema = AuditFieldsSchema.extend({
647
+ slug: z.string(),
648
+ name: z.string(),
649
+ description: z.string(),
650
+ module_slug: z.string(),
651
+ bundle_file_id: z.string(),
652
+ source_file_id: z.string(),
653
+ props_schema: z.record(z.unknown()).nullable(),
654
+ })
655
+
656
+ /**
657
+ * Options for listing components.
658
+ */
659
+ export interface ListComponentsOptions extends MetaListOptions {
660
+ slug?: string
661
+ name?: string
662
+ module_slug?: string
663
+ }
664
+
665
+ /**
666
+ * Request to create a component.
667
+ */
668
+ export interface CreateComponentRequest {
669
+ slug: string
670
+ name: string
671
+ module_slug: string
672
+ description: string
673
+ bundle_file_id?: string
674
+ source_file_id?: string
675
+ props_schema?: Record<string, unknown>
676
+ }
677
+
678
+ /**
679
+ * Request to update a component.
680
+ */
681
+ export interface UpdateComponentRequest {
682
+ name?: string
683
+ description?: string
684
+ bundle_file_id?: string
685
+ source_file_id?: string
686
+ props_schema?: Record<string, unknown>
687
+ }
688
+
689
+ // ============================================================================
690
+ // List Types
691
+ // ============================================================================
692
+
693
+ /**
694
+ * List column definition.
695
+ */
696
+ export interface Column {
697
+ attribute: string
698
+ label: string
699
+ width: number
700
+ }
701
+
702
+ /**
703
+ * Sort direction.
704
+ */
705
+ export type SortDirection = 'asc' | 'desc'
706
+
707
+ /**
708
+ * Sort configuration.
709
+ */
710
+ export interface SortConfig {
711
+ attribute: string
712
+ direction: SortDirection
713
+ }
714
+
715
+ // Filter / predicate types live in ./filters.js so the layout module can
716
+ // import FilterGroup without inducing a types.ts ↔ layout cycle.
717
+ import {
718
+ type ComparisonOperator,
719
+ type FilterElement,
720
+ FilterElementSchema,
721
+ type FilterGroup,
722
+ FilterGroupSchema,
723
+ type LogicalOperator,
724
+ } from './filters.js'
725
+
726
+ export {
727
+ type ComparisonOperator,
728
+ type FilterElement,
729
+ FilterElementSchema,
730
+ type FilterGroup,
731
+ FilterGroupSchema,
732
+ type LogicalOperator,
733
+ }
734
+
735
+ /**
736
+ * List configuration.
737
+ * Note: List uses `slug` as its primary identifier, not `id`.
738
+ */
739
+ export interface List extends AuditFields {
740
+ slug: string
741
+ org_id: string
742
+ module_slug: string
743
+ name: string
744
+ entity_slug: string
745
+ columns: Column[]
746
+ sorting: SortConfig[]
747
+ filters: FilterGroup[]
748
+ }
749
+
750
+ export const ColumnSchema = z.object({
751
+ attribute: z.string(),
752
+ label: z.string(),
753
+ width: z.number(),
754
+ })
755
+
756
+ export const SortConfigSchema = z.object({
757
+ attribute: z.string(),
758
+ direction: z.enum(['asc', 'desc']),
759
+ })
760
+
761
+ export const ListSchema = AuditFieldsSchema.extend({
762
+ slug: z.string(),
763
+ module_slug: z.string(),
764
+ name: z.string(),
765
+ entity_slug: z.string(),
766
+ columns: z.array(ColumnSchema),
767
+ sorting: z.array(SortConfigSchema),
768
+ filters: z.array(FilterGroupSchema),
769
+ })
770
+
771
+ /**
772
+ * Options for listing lists.
773
+ */
774
+ export interface ListListsOptions extends MetaListOptions {
775
+ slug?: string
776
+ name?: string
777
+ module_slug?: string
778
+ entity_slug?: string
779
+ }
780
+
781
+ /**
782
+ * Request to create a list.
783
+ */
784
+ export interface CreateListRequest {
785
+ slug: string
786
+ module_slug?: string
787
+ entity_slug: string
788
+ name: string
789
+ columns: Column[]
790
+ sorting: SortConfig[]
791
+ filters: FilterGroup[]
792
+ }
793
+
794
+ /**
795
+ * Request to update a list.
796
+ */
797
+ export interface UpdateListRequest {
798
+ name?: string
799
+ module_slug?: string
800
+ columns?: Column[]
801
+ sorting?: SortConfig[]
802
+ filters?: FilterGroup[]
803
+ }
804
+
805
+ // ============================================================================
806
+ // ListView Types
807
+ // ============================================================================
808
+
809
+ /**
810
+ * List view configuration.
811
+ * Note: ListView uses `slug` as its primary identifier, not `id`.
812
+ */
813
+ export interface ListView extends AuditFields {
814
+ slug: string
815
+ org_id: string
816
+ module_slug: string
817
+ list_slug: string
818
+ name: string
819
+ columns: Column[]
820
+ sorting: SortConfig[]
821
+ filters: FilterGroup[]
822
+ }
823
+
824
+ export const ListViewSchema = AuditFieldsSchema.extend({
825
+ slug: z.string(),
826
+ module_slug: z.string(),
827
+ list_slug: z.string(),
828
+ name: z.string(),
829
+ columns: z.array(ColumnSchema),
830
+ sorting: z.array(SortConfigSchema),
831
+ filters: z.array(FilterGroupSchema),
832
+ })
833
+
834
+ /**
835
+ * Options for listing list views.
836
+ */
837
+ export interface ListListViewsOptions extends MetaListOptions {
838
+ slug?: string
839
+ name?: string
840
+ module_slug?: string
841
+ list_slug?: string
842
+ }
843
+
844
+ /**
845
+ * Request to create a list view.
846
+ */
847
+ export interface CreateListViewRequest {
848
+ slug: string
849
+ module_slug?: string
850
+ list_slug: string
851
+ name: string
852
+ columns: Column[]
853
+ sorting?: SortConfig[]
854
+ filters?: FilterGroup[]
855
+ }
856
+
857
+ /**
858
+ * Request to update a list view.
859
+ */
860
+ export interface UpdateListViewRequest {
861
+ name?: string
862
+ module_slug?: string
863
+ columns?: Column[]
864
+ sorting?: SortConfig[]
865
+ filters?: FilterGroup[]
866
+ }
867
+
868
+ // ============================================================================
869
+ // Page Types
870
+ // ============================================================================
871
+
872
+ /**
873
+ * Page action definition. Page-level toolbar item; addressed by permissions
874
+ * and shortcuts systems.
875
+ */
876
+ export interface PageAction {
877
+ label: string
878
+ icon: string
879
+ action: string
880
+ }
881
+
882
+ export const PageActionSchema = z.object({
883
+ label: z.string(),
884
+ icon: z.string(),
885
+ action: z.string(),
886
+ })
887
+
888
+ /**
889
+ * Page type. `record` pages render against a single record of `entity_slug`;
890
+ * `platform` pages are standalone (no record context — e.g. a dashboard
891
+ * launched from a menu item). `external` is reserved for a future chromeless
892
+ * variant and is not yet accepted by the API.
893
+ */
894
+ export type PageType = 'record' | 'platform'
895
+
896
+ export const PageTypeSchema = z.enum(['record', 'platform'])
897
+
898
+ /**
899
+ * Page configuration. A `record` page is the detail-page shape for a single
900
+ * entity; a `platform` page is standalone (no entity, no record).
901
+ *
902
+ * `layout` is a typed tree of LayoutElements (see `./layout`). The legacy
903
+ * `mainContent` / `side_panel` / `formLayout` shape was replaced in the
904
+ * v1 PageLayout design.
905
+ */
906
+ export interface Page extends AuditFields {
907
+ slug: string
908
+ name: string
909
+ module_slug: string
910
+ type: PageType
911
+ /** Required for `record` pages; absent on `platform` pages. */
912
+ entity_slug?: string
913
+ actions: PageAction[]
914
+ layout: PageLayout
915
+ }
916
+
917
+ export const PageSchema = AuditFieldsSchema.extend({
918
+ slug: z.string(),
919
+ name: z.string(),
920
+ module_slug: z.string(),
921
+ type: PageTypeSchema,
922
+ entity_slug: z.string().optional(),
923
+ actions: z.array(PageActionSchema),
924
+ layout: PageLayoutSchema,
925
+ })
926
+
927
+ /**
928
+ * Options for listing pages.
929
+ */
930
+ export interface ListPagesOptions extends MetaListOptions {
931
+ slug?: string
932
+ name?: string
933
+ module_slug?: string
934
+ type?: PageType
935
+ entity_slug?: string
936
+ }
937
+
938
+ /**
939
+ * Request to create a page. `type` defaults to `record` when omitted.
940
+ * `entity_slug` is required for record pages and must be absent for platform
941
+ * pages.
942
+ */
943
+ export interface CreatePageRequest {
944
+ slug: string
945
+ name: string
946
+ module_slug?: string
947
+ type?: PageType
948
+ entity_slug?: string
949
+ actions: PageAction[]
950
+ layout: PageLayout
951
+ }
952
+
953
+ /**
954
+ * Request to update a page. Layout, when present, must be a complete valid
955
+ * tree — partial / element-level patches are not supported.
956
+ */
957
+ export interface UpdatePageRequest {
958
+ name?: string
959
+ module_slug?: string
960
+ actions?: PageAction[]
961
+ layout?: PageLayout
962
+ }
963
+
964
+ // ============================================================================
965
+ // Menu Configuration Types
966
+ // ============================================================================
967
+
968
+ /**
969
+ * Menu item type values. Use as both enum-like constant and type union.
970
+ */
971
+ export const MenuItemType = {
972
+ Link: 'link',
973
+ Group: 'group',
974
+ Entity: 'entity',
975
+ Page: 'page',
976
+ List: 'list',
977
+ } as const
978
+ export type MenuItemType = (typeof MenuItemType)[keyof typeof MenuItemType]
979
+
980
+ /**
981
+ * Menu item definition. Matches the backend JSON shape for nested menus.
982
+ */
983
+ export interface MenuItem {
984
+ id: string
985
+ order: number
986
+ label: string
987
+ type: MenuItemType
988
+ icon: string
989
+ reference?: string
990
+ children: MenuItem[] | null
991
+ }
992
+
993
+ /**
994
+ * Menu configuration.
995
+ */
996
+ export interface MenuConfiguration extends AuditFields {
997
+ slug: string
998
+ name: string
999
+ module_slug: string
1000
+ app_slug: string
1001
+ items: MenuItem[]
1002
+ is_default: boolean
1003
+ }
1004
+
1005
+ export const MenuItemSchema = z.lazy(() =>
1006
+ z.object({
1007
+ id: z.string(),
1008
+ order: z.number(),
1009
+ label: z.string(),
1010
+ type: z.enum(['link', 'group', 'entity', 'page', 'list']),
1011
+ icon: z.string(),
1012
+ reference: z.string().optional(),
1013
+ children: z.array(MenuItemSchema).nullable(),
1014
+ }),
1015
+ ) as unknown as z.ZodType<MenuItem>
1016
+
1017
+ export const MenuConfigurationSchema = AuditFieldsSchema.extend({
1018
+ slug: z.string(),
1019
+ name: z.string(),
1020
+ module_slug: z.string(),
1021
+ app_slug: z.string(),
1022
+ items: z.array(MenuItemSchema),
1023
+ is_default: z.boolean(),
1024
+ })
1025
+
1026
+ /**
1027
+ * Options for listing menu configurations.
1028
+ */
1029
+ export interface ListMenuConfigurationsOptions extends MetaListOptions {
1030
+ slug?: string
1031
+ name?: string
1032
+ module_slug?: string
1033
+ app_slug?: string
1034
+ is_default?: boolean
1035
+ }
1036
+
1037
+ /**
1038
+ * Request to create a menu configuration.
1039
+ */
1040
+ export interface CreateMenuConfigurationRequest {
1041
+ slug: string
1042
+ module_slug?: string
1043
+ name: string
1044
+ app_slug: string
1045
+ items: MenuItem[]
1046
+ is_default: boolean
1047
+ }
1048
+
1049
+ /**
1050
+ * Request to update a menu configuration.
1051
+ */
1052
+ export interface UpdateMenuConfigurationRequest {
1053
+ name?: string
1054
+ module_slug?: string
1055
+ items?: MenuItem[]
1056
+ is_default?: boolean
1057
+ }
1058
+
1059
+ // ============================================================================
1060
+ // App Types
1061
+ // ============================================================================
1062
+
1063
+ /**
1064
+ * App definition. Apps group menu configurations and other org-scoped
1065
+ * metadata under a stable slug. Slug is unique per org (composite key
1066
+ * `(org_id, slug)`).
1067
+ */
1068
+ export interface App extends AuditFields {
1069
+ slug: string
1070
+ org_id: string
1071
+ module_slug: string
1072
+ name: string
1073
+ description: string
1074
+ icon_slug: string
1075
+ }
1076
+
1077
+ export const AppSchema = AuditFieldsSchema.extend({
1078
+ slug: z.string(),
1079
+ org_id: z.string(),
1080
+ module_slug: z.string(),
1081
+ name: z.string(),
1082
+ description: z.string(),
1083
+ icon_slug: z.string(),
1084
+ })
1085
+
1086
+ /**
1087
+ * Options for listing apps.
1088
+ */
1089
+ export interface ListAppsOptions extends MetaListOptions {
1090
+ slug?: string
1091
+ name?: string
1092
+ module_slug?: string
1093
+ icon_slug?: string
1094
+ }
1095
+
1096
+ /**
1097
+ * Request to create an app.
1098
+ */
1099
+ export interface CreateAppRequest {
1100
+ slug: string
1101
+ module_slug?: string
1102
+ name: string
1103
+ icon_slug: string
1104
+ description?: string
1105
+ }
1106
+
1107
+ /**
1108
+ * Request to update an app. Slug and org_id are immutable.
1109
+ */
1110
+ export interface UpdateAppRequest {
1111
+ name?: string
1112
+ module_slug?: string
1113
+ description?: string
1114
+ icon_slug?: string
1115
+ }