@centrali-io/centrali-sdk 3.0.8 → 3.1.0

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 (3) hide show
  1. package/dist/index.js +611 -1
  2. package/index.ts +1036 -20
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -517,6 +517,7 @@ export interface FunctionTrigger {
517
517
  executionType: TriggerExecutionType;
518
518
  triggerMetadata: Record<string, any>;
519
519
  schedulerJobId?: string;
520
+ enabled: boolean;
520
521
  createdBy: string;
521
522
  updatedBy: string;
522
523
  createdAt?: string;
@@ -1314,6 +1315,364 @@ export interface SmartQueryExecuteResult<T = any> {
1314
1315
  };
1315
1316
  }
1316
1317
 
1318
+ // =====================================================
1319
+ // Structure Types (Configuration-as-Code)
1320
+ // =====================================================
1321
+
1322
+ /**
1323
+ * Property type identifiers for structure properties.
1324
+ */
1325
+ export type PropertyType = 'string' | 'number' | 'boolean' | 'datetime' | 'array' | 'object' | 'reference';
1326
+
1327
+ /**
1328
+ * Schema discovery mode for a structure.
1329
+ */
1330
+ export type SchemaDiscoveryMode = 'strict' | 'schemaless' | 'auto-evolving';
1331
+
1332
+ /**
1333
+ * Base property definition shared by all property types.
1334
+ */
1335
+ export interface BasePropertyDefinition {
1336
+ id?: string;
1337
+ name: string;
1338
+ type: PropertyType;
1339
+ description?: string;
1340
+ required?: boolean;
1341
+ nullable?: boolean;
1342
+ default?: any;
1343
+ enum?: any[];
1344
+ isUnique?: boolean;
1345
+ immutable?: boolean;
1346
+ }
1347
+
1348
+ /**
1349
+ * String property definition.
1350
+ */
1351
+ export interface StringPropertyDefinition extends BasePropertyDefinition {
1352
+ type: 'string';
1353
+ minLength?: number;
1354
+ maxLength?: number;
1355
+ pattern?: string;
1356
+ renderAs?: 'textarea' | 'secret' | 'color' | 'code' | 'html' | 'markdown';
1357
+ not?: any[];
1358
+ isSecret?: boolean;
1359
+ }
1360
+
1361
+ /**
1362
+ * Number property definition.
1363
+ */
1364
+ export interface NumberPropertyDefinition extends BasePropertyDefinition {
1365
+ type: 'number';
1366
+ minimum?: number;
1367
+ maximum?: number;
1368
+ exclusiveMinimum?: boolean;
1369
+ exclusiveMaximum?: boolean;
1370
+ multipleOf?: number;
1371
+ expression?: string;
1372
+ computedMode?: 'persisted' | 'virtual';
1373
+ autoIncrement?: { startAt: number; incrementBy?: number };
1374
+ }
1375
+
1376
+ /**
1377
+ * Boolean property definition.
1378
+ */
1379
+ export interface BooleanPropertyDefinition extends BasePropertyDefinition {
1380
+ type: 'boolean';
1381
+ }
1382
+
1383
+ /**
1384
+ * DateTime property definition.
1385
+ */
1386
+ export interface DateTimePropertyDefinition extends BasePropertyDefinition {
1387
+ type: 'datetime';
1388
+ earliestDate?: string;
1389
+ latestDate?: string;
1390
+ exclusiveEarliest?: boolean;
1391
+ exclusiveLatest?: boolean;
1392
+ expression?: string;
1393
+ computedMode?: 'persisted' | 'virtual';
1394
+ }
1395
+
1396
+ /**
1397
+ * Array property definition.
1398
+ */
1399
+ export interface ArrayPropertyDefinition extends BasePropertyDefinition {
1400
+ type: 'array';
1401
+ items: { type: string };
1402
+ minItems?: number;
1403
+ maxItems?: number;
1404
+ uniqueItems?: boolean;
1405
+ itemSchema?: PropertyDefinition[];
1406
+ strictProperties?: boolean;
1407
+ }
1408
+
1409
+ /**
1410
+ * Object property definition.
1411
+ */
1412
+ export interface ObjectPropertyDefinition extends BasePropertyDefinition {
1413
+ type: 'object';
1414
+ properties?: PropertyDefinition[];
1415
+ requiredProperties?: string[];
1416
+ strictProperties?: boolean;
1417
+ }
1418
+
1419
+ /**
1420
+ * Reference property definition for foreign key-like relationships.
1421
+ */
1422
+ export interface ReferencePropertyDefinition extends BasePropertyDefinition {
1423
+ type: 'reference';
1424
+ target: string;
1425
+ targetField?: string;
1426
+ displayField?: string;
1427
+ relationship: 'many-to-one' | 'one-to-one' | 'many-to-many';
1428
+ onDelete: 'restrict' | 'cascade' | 'set_null';
1429
+ }
1430
+
1431
+ /**
1432
+ * Union of all property definition types.
1433
+ */
1434
+ export type PropertyDefinition =
1435
+ | StringPropertyDefinition
1436
+ | NumberPropertyDefinition
1437
+ | BooleanPropertyDefinition
1438
+ | DateTimePropertyDefinition
1439
+ | ArrayPropertyDefinition
1440
+ | ObjectPropertyDefinition
1441
+ | ReferencePropertyDefinition;
1442
+
1443
+ /**
1444
+ * Full structure definition.
1445
+ */
1446
+ export interface Structure {
1447
+ id: string;
1448
+ name: string;
1449
+ workspaceSlug: string;
1450
+ recordSlug: string;
1451
+ description?: string;
1452
+ properties: PropertyDefinition[];
1453
+ defaultSearchField?: string;
1454
+ metadata?: {
1455
+ recordWritesLocked?: boolean;
1456
+ structureWritesLocked?: boolean;
1457
+ lastMigrationId?: string;
1458
+ migrationInProgress?: boolean;
1459
+ migrationJobId?: string;
1460
+ migrationStartedAt?: string;
1461
+ migrationStartedBy?: string;
1462
+ };
1463
+ status: 'active' | 'inactive';
1464
+ schemaDiscoveryMode: SchemaDiscoveryMode;
1465
+ enableVersioning: boolean;
1466
+ isDeleted: boolean;
1467
+ createdBy: string;
1468
+ lastUpdatedBy: string;
1469
+ createdAt: string;
1470
+ updatedAt: string;
1471
+ tags?: string[];
1472
+ }
1473
+
1474
+ /**
1475
+ * Input for creating a new structure.
1476
+ */
1477
+ export interface CreateStructureInput {
1478
+ name: string;
1479
+ slug: string;
1480
+ description?: string;
1481
+ properties?: PropertyDefinition[];
1482
+ enableVersioning?: boolean;
1483
+ schemaDiscoveryMode?: SchemaDiscoveryMode;
1484
+ tags?: string[];
1485
+ }
1486
+
1487
+ /**
1488
+ * Input for updating an existing structure.
1489
+ */
1490
+ export interface UpdateStructureInput {
1491
+ name?: string;
1492
+ description?: string;
1493
+ properties?: PropertyDefinition[];
1494
+ enableVersioning?: boolean;
1495
+ tags?: string[];
1496
+ }
1497
+
1498
+ /**
1499
+ * Options for listing structures.
1500
+ */
1501
+ export interface ListStructuresOptions {
1502
+ page?: number;
1503
+ limit?: number;
1504
+ }
1505
+
1506
+ /**
1507
+ * Input for validating a structure definition.
1508
+ */
1509
+ export interface ValidateStructureInput {
1510
+ name?: string;
1511
+ slug?: string;
1512
+ properties?: PropertyDefinition[];
1513
+ }
1514
+
1515
+ // =====================================================
1516
+ // Compute Function Types (Configuration-as-Code)
1517
+ // =====================================================
1518
+
1519
+ /**
1520
+ * Compute function definition.
1521
+ */
1522
+ export interface ComputeFunction {
1523
+ id: string;
1524
+ name: string;
1525
+ code: string;
1526
+ description?: string;
1527
+ workspaceSlug: string;
1528
+ createdBy: string;
1529
+ updatedBy?: string;
1530
+ timeoutMs?: number;
1531
+ createdAt: string;
1532
+ updatedAt: string;
1533
+ }
1534
+
1535
+ /**
1536
+ * Input for creating a new compute function.
1537
+ */
1538
+ export interface CreateComputeFunctionInput {
1539
+ name: string;
1540
+ slug: string;
1541
+ code: string;
1542
+ description?: string;
1543
+ timeout?: number;
1544
+ }
1545
+
1546
+ /**
1547
+ * Input for updating an existing compute function.
1548
+ */
1549
+ export interface UpdateComputeFunctionInput {
1550
+ name?: string;
1551
+ description?: string;
1552
+ code?: string;
1553
+ timeout?: number;
1554
+ }
1555
+
1556
+ /**
1557
+ * Options for listing compute functions.
1558
+ */
1559
+ export interface ListComputeFunctionsOptions {
1560
+ page?: number;
1561
+ limit?: number;
1562
+ search?: string;
1563
+ searchField?: string;
1564
+ }
1565
+
1566
+ /**
1567
+ * Input for test-executing a compute function without saving.
1568
+ */
1569
+ export interface TestComputeFunctionInput {
1570
+ code: string;
1571
+ input?: Record<string, any>;
1572
+ }
1573
+
1574
+ /**
1575
+ * Result from test-executing a compute function.
1576
+ */
1577
+ export interface TestComputeFunctionResult {
1578
+ success: boolean;
1579
+ output?: any;
1580
+ duration_ms?: number;
1581
+ logs?: string[];
1582
+ error?: string;
1583
+ }
1584
+
1585
+ // =====================================================
1586
+ // Trigger CRUD Types (Configuration-as-Code)
1587
+ // =====================================================
1588
+
1589
+ /**
1590
+ * Input for creating a new function trigger.
1591
+ */
1592
+ export interface CreateTriggerInput {
1593
+ name: string;
1594
+ functionId: string;
1595
+ executionType: TriggerExecutionType;
1596
+ description?: string;
1597
+ triggerMetadata?: Record<string, any>;
1598
+ enabled?: boolean;
1599
+ }
1600
+
1601
+ /**
1602
+ * Input for updating an existing function trigger.
1603
+ */
1604
+ export interface UpdateTriggerInput {
1605
+ name?: string;
1606
+ description?: string;
1607
+ enabled?: boolean;
1608
+ triggerMetadata?: Record<string, any>;
1609
+ }
1610
+
1611
+ /**
1612
+ * Options for listing all triggers (not filtered by type).
1613
+ */
1614
+ export interface ListAllTriggersOptions {
1615
+ page?: number;
1616
+ limit?: number;
1617
+ functionId?: string;
1618
+ executionType?: TriggerExecutionType;
1619
+ includeHealth?: boolean;
1620
+ }
1621
+
1622
+ /**
1623
+ * Health status of a trigger.
1624
+ */
1625
+ export type TriggerHealthStatus = 'healthy' | 'warning' | 'error' | 'dead' | 'never_run' | 'paused';
1626
+
1627
+ /**
1628
+ * Health metrics for a trigger.
1629
+ */
1630
+ export interface TriggerHealthMetrics {
1631
+ lastRunAt: string | null;
1632
+ successCount: number;
1633
+ failureCount: number;
1634
+ avgExecutionTimeMs: number;
1635
+ totalRuns: number;
1636
+ }
1637
+
1638
+ /**
1639
+ * Trigger with health metrics included.
1640
+ */
1641
+ export interface TriggerWithHealth extends FunctionTrigger {
1642
+ health: TriggerHealthMetrics;
1643
+ healthStatus: TriggerHealthStatus;
1644
+ }
1645
+
1646
+ // =====================================================
1647
+ // Smart Query CRUD Types (Configuration-as-Code)
1648
+ // =====================================================
1649
+
1650
+ /**
1651
+ * Input for creating a new smart query.
1652
+ */
1653
+ export interface CreateSmartQueryInput {
1654
+ name: string;
1655
+ description?: string;
1656
+ queryDefinition: SmartQueryDefinition;
1657
+ }
1658
+
1659
+ /**
1660
+ * Input for updating an existing smart query.
1661
+ */
1662
+ export interface UpdateSmartQueryInput {
1663
+ name?: string;
1664
+ description?: string;
1665
+ queryDefinition?: SmartQueryDefinition;
1666
+ }
1667
+
1668
+ /**
1669
+ * Input for test-executing a smart query definition without saving.
1670
+ */
1671
+ export interface TestSmartQueryInput {
1672
+ queryDefinition: SmartQueryDefinition;
1673
+ variables?: Record<string, string>;
1674
+ }
1675
+
1317
1676
  // =====================================================
1318
1677
  // Search Types
1319
1678
  // =====================================================
@@ -2086,6 +2445,62 @@ export function getStructureInsightsApiPath(workspaceId: string, structureSlug:
2086
2445
  return `data/workspace/${workspaceId}/api/v1/structures/${structureSlug}/insights`;
2087
2446
  }
2088
2447
 
2448
+ // =====================================================
2449
+ // Structure API Path Helpers (Configuration-as-Code)
2450
+ // =====================================================
2451
+
2452
+ /**
2453
+ * Generate Structures base API URL PATH.
2454
+ */
2455
+ export function getStructuresApiPath(workspaceId: string, structureId?: string): string {
2456
+ const basePath = `data/workspace/${workspaceId}/api/v1/structures`;
2457
+ return structureId ? `${basePath}/${structureId}` : basePath;
2458
+ }
2459
+
2460
+ /**
2461
+ * Generate Structure by slug API URL PATH.
2462
+ */
2463
+ export function getStructureBySlugApiPath(workspaceId: string, recordSlug: string): string {
2464
+ return `data/workspace/${workspaceId}/api/v1/structures/slug/${recordSlug}`;
2465
+ }
2466
+
2467
+ /**
2468
+ * Generate Structure validate API URL PATH.
2469
+ */
2470
+ export function getStructureValidateApiPath(workspaceId: string): string {
2471
+ return `data/workspace/${workspaceId}/api/v1/structures/validate`;
2472
+ }
2473
+
2474
+ // =====================================================
2475
+ // Compute Function API Path Helpers (Configuration-as-Code)
2476
+ // =====================================================
2477
+
2478
+ /**
2479
+ * Generate Compute Functions base API URL PATH.
2480
+ */
2481
+ export function getComputeFunctionsApiPath(workspaceId: string, functionId?: string): string {
2482
+ const basePath = `data/workspace/${workspaceId}/api/v1/compute-functions`;
2483
+ return functionId ? `${basePath}/${functionId}` : basePath;
2484
+ }
2485
+
2486
+ /**
2487
+ * Generate Compute Function test execution API URL PATH.
2488
+ */
2489
+ export function getComputeFunctionTestApiPath(workspaceId: string): string {
2490
+ return `data/workspace/${workspaceId}/api/v1/compute-functions/test`;
2491
+ }
2492
+
2493
+ // =====================================================
2494
+ // Smart Query Test API Path Helper (Configuration-as-Code)
2495
+ // =====================================================
2496
+
2497
+ /**
2498
+ * Generate Smart Query test execution API URL PATH.
2499
+ */
2500
+ export function getSmartQueryTestApiPath(workspaceId: string, structureSlug: string): string {
2501
+ return `data/workspace/${workspaceId}/api/v1/smart-queries/slug/${structureSlug}/test`;
2502
+ }
2503
+
2089
2504
  // =====================================================
2090
2505
  // Validation API Path Helpers
2091
2506
  // =====================================================
@@ -2670,28 +3085,140 @@ export class TriggersManager {
2670
3085
  const path = getFunctionTriggerResumeApiPath(this.workspaceId, triggerId);
2671
3086
  return this.requestFn<FunctionTrigger>('PATCH', path, {});
2672
3087
  }
2673
- }
2674
3088
 
2675
- // =====================================================
2676
- // Smart Queries Manager
2677
- // =====================================================
3089
+ /**
3090
+ * Create a new function trigger.
3091
+ *
3092
+ * @param input - The trigger definition
3093
+ * @returns The created trigger
3094
+ *
3095
+ * @example
3096
+ * ```ts
3097
+ * // Create an event-driven trigger
3098
+ * const trigger = await client.triggers.create({
3099
+ * name: 'On Order Created',
3100
+ * functionId: 'function-uuid',
3101
+ * executionType: 'event-driven',
3102
+ * triggerMetadata: { event: 'record.created', recordSlug: 'orders' }
3103
+ * });
3104
+ *
3105
+ * // Create a scheduled trigger
3106
+ * const scheduled = await client.triggers.create({
3107
+ * name: 'Daily Report',
3108
+ * functionId: 'function-uuid',
3109
+ * executionType: 'scheduled',
3110
+ * triggerMetadata: { scheduleType: 'cron', cronExpression: '0 9 * * *', timezone: 'America/New_York' }
3111
+ * });
3112
+ * ```
3113
+ */
3114
+ public create(input: CreateTriggerInput): Promise<ApiResponse<FunctionTrigger>> {
3115
+ const path = getFunctionTriggersApiPath(this.workspaceId);
3116
+ return this.requestFn<FunctionTrigger>('POST', path, input);
3117
+ }
2678
3118
 
2679
- /**
2680
- * SmartQueriesManager provides methods for listing and executing smart queries.
2681
- * Smart queries are reusable, parameterized queries defined in the console
2682
- * that can be executed programmatically via the SDK.
2683
- * Access via `client.smartQueries`.
2684
- *
2685
- * Usage:
2686
- * ```ts
2687
- * // List smart queries for a structure
2688
- * const queries = await client.smartQueries.list('employee');
2689
- *
2690
- * // Execute a smart query by ID
2691
- * const results = await client.smartQueries.execute('employee', 'query-uuid');
2692
- *
2693
- * // Get a smart query by name
2694
- * const query = await client.smartQueries.getByName('employee', 'Active Employees');
3119
+ /**
3120
+ * Update an existing function trigger.
3121
+ *
3122
+ * @param triggerId - The trigger UUID
3123
+ * @param input - The fields to update
3124
+ * @returns The updated trigger
3125
+ *
3126
+ * @example
3127
+ * ```ts
3128
+ * const updated = await client.triggers.update('trigger-uuid', {
3129
+ * name: 'Updated Trigger Name',
3130
+ * enabled: false
3131
+ * });
3132
+ * ```
3133
+ */
3134
+ public update(triggerId: string, input: UpdateTriggerInput): Promise<ApiResponse<FunctionTrigger>> {
3135
+ const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
3136
+ return this.requestFn<FunctionTrigger>('PUT', path, input);
3137
+ }
3138
+
3139
+ /**
3140
+ * Delete a function trigger.
3141
+ *
3142
+ * @param triggerId - The trigger UUID
3143
+ *
3144
+ * @example
3145
+ * ```ts
3146
+ * await client.triggers.delete('trigger-uuid');
3147
+ * ```
3148
+ */
3149
+ public delete(triggerId: string): Promise<ApiResponse<void>> {
3150
+ const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
3151
+ return this.requestFn<void>('DELETE', path);
3152
+ }
3153
+
3154
+ /**
3155
+ * List all triggers in the workspace (not filtered by execution type).
3156
+ * Unlike `list()` which only returns on-demand triggers, `listAll()` returns
3157
+ * triggers of all types with optional filtering.
3158
+ *
3159
+ * @param options - Optional list parameters (pagination, filtering, health)
3160
+ * @returns List of triggers
3161
+ *
3162
+ * @example
3163
+ * ```ts
3164
+ * // List all triggers
3165
+ * const all = await client.triggers.listAll();
3166
+ *
3167
+ * // Filter by execution type
3168
+ * const scheduled = await client.triggers.listAll({ executionType: 'scheduled' });
3169
+ *
3170
+ * // Include health metrics
3171
+ * const withHealth = await client.triggers.listAll({ includeHealth: true });
3172
+ * ```
3173
+ */
3174
+ public listAll(options?: ListAllTriggersOptions): Promise<ApiResponse<(FunctionTrigger | TriggerWithHealth)[]>> {
3175
+ const path = getFunctionTriggersApiPath(this.workspaceId);
3176
+ return this.requestFn<(FunctionTrigger | TriggerWithHealth)[]>('GET', path, null, options);
3177
+ }
3178
+
3179
+ /**
3180
+ * Get a trigger by ID with full details (no on-demand type restriction).
3181
+ * Unlike `get()` which validates on-demand type, `getDetails()` returns
3182
+ * any trigger type.
3183
+ *
3184
+ * @param triggerId - The trigger UUID
3185
+ * @param options - Optional parameters (includeHealth)
3186
+ * @returns The trigger details
3187
+ *
3188
+ * @example
3189
+ * ```ts
3190
+ * const trigger = await client.triggers.getDetails('trigger-uuid');
3191
+ *
3192
+ * // With health metrics
3193
+ * const withHealth = await client.triggers.getDetails('trigger-uuid', { includeHealth: true });
3194
+ * ```
3195
+ */
3196
+ public getDetails(triggerId: string, options?: { includeHealth?: boolean }): Promise<ApiResponse<FunctionTrigger | TriggerWithHealth>> {
3197
+ const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
3198
+ return this.requestFn<FunctionTrigger | TriggerWithHealth>('GET', path, null, options);
3199
+ }
3200
+ }
3201
+
3202
+ // =====================================================
3203
+ // Smart Queries Manager
3204
+ // =====================================================
3205
+
3206
+ /**
3207
+ * SmartQueriesManager provides methods for listing and executing smart queries.
3208
+ * Smart queries are reusable, parameterized queries defined in the console
3209
+ * that can be executed programmatically via the SDK.
3210
+ * Access via `client.smartQueries`.
3211
+ *
3212
+ * Usage:
3213
+ * ```ts
3214
+ * // List smart queries for a structure
3215
+ * const queries = await client.smartQueries.list('employee');
3216
+ *
3217
+ * // Execute a smart query by ID
3218
+ * const results = await client.smartQueries.execute('employee', 'query-uuid');
3219
+ *
3220
+ * // Get a smart query by name
3221
+ * const query = await client.smartQueries.getByName('employee', 'Active Employees');
2695
3222
  * ```
2696
3223
  */
2697
3224
  export class SmartQueriesManager {
@@ -2829,6 +3356,96 @@ export class SmartQueriesManager {
2829
3356
  const body = options?.variables ? { variables: options.variables } : undefined;
2830
3357
  return this.requestFn<T[]>('POST', path, body);
2831
3358
  }
3359
+
3360
+ /**
3361
+ * Create a new smart query for a structure.
3362
+ *
3363
+ * @param structureSlug - The structure's record slug
3364
+ * @param input - The smart query definition
3365
+ * @returns The created smart query
3366
+ *
3367
+ * @example
3368
+ * ```ts
3369
+ * const query = await client.smartQueries.create('orders', {
3370
+ * name: 'Active Orders',
3371
+ * description: 'All orders with active status',
3372
+ * queryDefinition: {
3373
+ * where: { status: { $eq: 'active' } },
3374
+ * sort: [{ field: 'createdAt', direction: 'desc' }],
3375
+ * limit: 100
3376
+ * }
3377
+ * });
3378
+ * ```
3379
+ */
3380
+ public create(structureSlug: string, input: CreateSmartQueryInput): Promise<ApiResponse<SmartQuery>> {
3381
+ const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug);
3382
+ return this.requestFn<SmartQuery>('POST', path, input);
3383
+ }
3384
+
3385
+ /**
3386
+ * Update an existing smart query.
3387
+ *
3388
+ * @param structureSlug - The structure's record slug
3389
+ * @param queryId - The smart query UUID
3390
+ * @param input - The fields to update
3391
+ * @returns The updated smart query
3392
+ *
3393
+ * @example
3394
+ * ```ts
3395
+ * const updated = await client.smartQueries.update('orders', 'query-uuid', {
3396
+ * name: 'Active Orders v2',
3397
+ * queryDefinition: {
3398
+ * where: { status: { $in: ['active', 'processing'] } },
3399
+ * limit: 200
3400
+ * }
3401
+ * });
3402
+ * ```
3403
+ */
3404
+ public update(structureSlug: string, queryId: string, input: UpdateSmartQueryInput): Promise<ApiResponse<SmartQuery>> {
3405
+ const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug, queryId);
3406
+ return this.requestFn<SmartQuery>('PUT', path, input);
3407
+ }
3408
+
3409
+ /**
3410
+ * Delete a smart query.
3411
+ *
3412
+ * @param structureSlug - The structure's record slug
3413
+ * @param queryId - The smart query UUID
3414
+ *
3415
+ * @example
3416
+ * ```ts
3417
+ * await client.smartQueries.delete('orders', 'query-uuid');
3418
+ * ```
3419
+ */
3420
+ public delete(structureSlug: string, queryId: string): Promise<ApiResponse<void>> {
3421
+ const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug, queryId);
3422
+ return this.requestFn<void>('DELETE', path);
3423
+ }
3424
+
3425
+ /**
3426
+ * Test execute a query definition without saving it.
3427
+ * Useful for validating query syntax and previewing results before creating.
3428
+ *
3429
+ * @param structureSlug - The structure's record slug
3430
+ * @param input - The query definition to test and optional variables
3431
+ * @returns Test execution results
3432
+ *
3433
+ * @example
3434
+ * ```ts
3435
+ * const result = await client.smartQueries.test('orders', {
3436
+ * queryDefinition: {
3437
+ * where: { amount: { $gte: 100 } },
3438
+ * select: ['id', 'amount', 'status'],
3439
+ * limit: 5
3440
+ * }
3441
+ * });
3442
+ * console.log('Preview results:', result.data);
3443
+ * ```
3444
+ */
3445
+ public test<T = any>(structureSlug: string, input: TestSmartQueryInput): Promise<ApiResponse<T[]>> {
3446
+ const path = getSmartQueryTestApiPath(this.workspaceId, structureSlug);
3447
+ return this.requestFn<T[]>('POST', path, input);
3448
+ }
2832
3449
  }
2833
3450
 
2834
3451
  // =====================================================
@@ -3382,6 +3999,340 @@ export class AllowedDomainsManager {
3382
3999
  }
3383
4000
  }
3384
4001
 
4002
+ // =====================================================
4003
+ // Structures Manager (Configuration-as-Code)
4004
+ // =====================================================
4005
+
4006
+ /**
4007
+ * StructuresManager provides methods for managing data structures (schemas).
4008
+ * Structures define the shape of records including properties, validation rules,
4009
+ * and schema discovery modes.
4010
+ * Access via `client.structures`.
4011
+ *
4012
+ * Usage:
4013
+ * ```ts
4014
+ * // List all structures
4015
+ * const structures = await client.structures.list();
4016
+ *
4017
+ * // Create a new structure
4018
+ * const structure = await client.structures.create({
4019
+ * name: 'Orders',
4020
+ * slug: 'orders',
4021
+ * properties: [
4022
+ * { name: 'title', type: 'string', required: true },
4023
+ * { name: 'amount', type: 'number', minimum: 0 }
4024
+ * ]
4025
+ * });
4026
+ *
4027
+ * // Validate before creating
4028
+ * const validation = await client.structures.validate({ slug: 'orders' });
4029
+ * ```
4030
+ */
4031
+ export class StructuresManager {
4032
+ private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
4033
+ private workspaceId: string;
4034
+
4035
+ constructor(
4036
+ workspaceId: string,
4037
+ requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
4038
+ ) {
4039
+ this.workspaceId = workspaceId;
4040
+ this.requestFn = requestFn;
4041
+ }
4042
+
4043
+ /**
4044
+ * List all structures in the workspace.
4045
+ *
4046
+ * @param options - Optional list parameters (pagination)
4047
+ * @returns List of structures
4048
+ *
4049
+ * @example
4050
+ * ```ts
4051
+ * const structures = await client.structures.list();
4052
+ * const page2 = await client.structures.list({ page: 2, limit: 10 });
4053
+ * ```
4054
+ */
4055
+ public list(options?: ListStructuresOptions): Promise<ApiResponse<Structure[]>> {
4056
+ const path = getStructuresApiPath(this.workspaceId);
4057
+ return this.requestFn<Structure[]>('GET', path, null, options);
4058
+ }
4059
+
4060
+ /**
4061
+ * Get a structure by ID.
4062
+ *
4063
+ * @param structureId - The structure UUID
4064
+ * @returns The structure details
4065
+ *
4066
+ * @example
4067
+ * ```ts
4068
+ * const structure = await client.structures.get('structure-uuid');
4069
+ * console.log('Properties:', structure.data.properties.length);
4070
+ * ```
4071
+ */
4072
+ public get(structureId: string): Promise<ApiResponse<Structure>> {
4073
+ const path = getStructuresApiPath(this.workspaceId, structureId);
4074
+ return this.requestFn<Structure>('GET', path);
4075
+ }
4076
+
4077
+ /**
4078
+ * Get a structure by its record slug.
4079
+ *
4080
+ * @param recordSlug - The structure's record slug (e.g., "orders")
4081
+ * @returns The structure details
4082
+ *
4083
+ * @example
4084
+ * ```ts
4085
+ * const structure = await client.structures.getBySlug('orders');
4086
+ * console.log('Structure name:', structure.data.name);
4087
+ * ```
4088
+ */
4089
+ public getBySlug(recordSlug: string): Promise<ApiResponse<Structure>> {
4090
+ const path = getStructureBySlugApiPath(this.workspaceId, recordSlug);
4091
+ return this.requestFn<Structure>('GET', path);
4092
+ }
4093
+
4094
+ /**
4095
+ * Create a new structure.
4096
+ *
4097
+ * @param input - The structure definition
4098
+ * @returns The created structure
4099
+ *
4100
+ * @example
4101
+ * ```ts
4102
+ * const structure = await client.structures.create({
4103
+ * name: 'Orders',
4104
+ * slug: 'orders',
4105
+ * description: 'Customer orders',
4106
+ * properties: [
4107
+ * { name: 'title', type: 'string', required: true },
4108
+ * { name: 'amount', type: 'number', minimum: 0 },
4109
+ * { name: 'status', type: 'string', enum: ['pending', 'completed'] }
4110
+ * ],
4111
+ * enableVersioning: true,
4112
+ * schemaDiscoveryMode: 'strict'
4113
+ * });
4114
+ * ```
4115
+ */
4116
+ public create(input: CreateStructureInput): Promise<ApiResponse<Structure>> {
4117
+ const path = getStructuresApiPath(this.workspaceId);
4118
+ return this.requestFn<Structure>('POST', path, input);
4119
+ }
4120
+
4121
+ /**
4122
+ * Update an existing structure.
4123
+ *
4124
+ * @param structureId - The structure UUID
4125
+ * @param input - The fields to update
4126
+ * @returns The updated structure
4127
+ *
4128
+ * @example
4129
+ * ```ts
4130
+ * const updated = await client.structures.update('structure-uuid', {
4131
+ * name: 'Updated Orders',
4132
+ * properties: [
4133
+ * { name: 'title', type: 'string', required: true },
4134
+ * { name: 'amount', type: 'number', minimum: 0 },
4135
+ * { name: 'priority', type: 'number' }
4136
+ * ]
4137
+ * });
4138
+ * ```
4139
+ */
4140
+ public update(structureId: string, input: UpdateStructureInput): Promise<ApiResponse<Structure>> {
4141
+ const path = getStructuresApiPath(this.workspaceId, structureId);
4142
+ return this.requestFn<Structure>('PUT', path, input);
4143
+ }
4144
+
4145
+ /**
4146
+ * Delete a structure.
4147
+ *
4148
+ * @param structureId - The structure UUID
4149
+ *
4150
+ * @example
4151
+ * ```ts
4152
+ * await client.structures.delete('structure-uuid');
4153
+ * ```
4154
+ */
4155
+ public delete(structureId: string): Promise<ApiResponse<void>> {
4156
+ const path = getStructuresApiPath(this.workspaceId, structureId);
4157
+ return this.requestFn<void>('DELETE', path);
4158
+ }
4159
+
4160
+ /**
4161
+ * Validate a structure definition without creating it.
4162
+ * Useful for checking slug uniqueness and property validity before creation.
4163
+ *
4164
+ * @param input - The structure definition to validate
4165
+ * @returns Validation result
4166
+ *
4167
+ * @example
4168
+ * ```ts
4169
+ * const result = await client.structures.validate({
4170
+ * slug: 'orders',
4171
+ * properties: [{ name: 'title', type: 'string' }]
4172
+ * });
4173
+ * ```
4174
+ */
4175
+ public validate(input: ValidateStructureInput): Promise<ApiResponse<any>> {
4176
+ const path = getStructureValidateApiPath(this.workspaceId);
4177
+ return this.requestFn<any>('POST', path, input);
4178
+ }
4179
+ }
4180
+
4181
+ // =====================================================
4182
+ // Compute Functions Manager (Configuration-as-Code)
4183
+ // =====================================================
4184
+
4185
+ /**
4186
+ * ComputeFunctionsManager provides methods for managing compute functions.
4187
+ * Compute functions are JavaScript code blocks that can be executed on triggers,
4188
+ * schedules, or on-demand.
4189
+ * Access via `client.functions`.
4190
+ *
4191
+ * Usage:
4192
+ * ```ts
4193
+ * // List all compute functions
4194
+ * const fns = await client.functions.list();
4195
+ *
4196
+ * // Create a new function
4197
+ * const fn = await client.functions.create({
4198
+ * name: 'Process Order',
4199
+ * slug: 'process-order',
4200
+ * code: 'module.exports = async (ctx) => { return { processed: true }; }'
4201
+ * });
4202
+ *
4203
+ * // Test execute code without saving
4204
+ * const result = await client.functions.testExecute({
4205
+ * code: 'module.exports = async (ctx) => { return ctx.input; }',
4206
+ * input: { orderId: '123' }
4207
+ * });
4208
+ * ```
4209
+ */
4210
+ export class ComputeFunctionsManager {
4211
+ private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
4212
+ private workspaceId: string;
4213
+
4214
+ constructor(
4215
+ workspaceId: string,
4216
+ requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
4217
+ ) {
4218
+ this.workspaceId = workspaceId;
4219
+ this.requestFn = requestFn;
4220
+ }
4221
+
4222
+ /**
4223
+ * List all compute functions in the workspace.
4224
+ *
4225
+ * @param options - Optional list parameters (pagination, search)
4226
+ * @returns List of compute functions
4227
+ *
4228
+ * @example
4229
+ * ```ts
4230
+ * const fns = await client.functions.list();
4231
+ * const searched = await client.functions.list({ search: 'order', limit: 10 });
4232
+ * ```
4233
+ */
4234
+ public list(options?: ListComputeFunctionsOptions): Promise<ApiResponse<ComputeFunction[]>> {
4235
+ const path = getComputeFunctionsApiPath(this.workspaceId);
4236
+ return this.requestFn<ComputeFunction[]>('GET', path, null, options);
4237
+ }
4238
+
4239
+ /**
4240
+ * Get a compute function by ID.
4241
+ *
4242
+ * @param functionId - The compute function UUID
4243
+ * @returns The compute function details
4244
+ *
4245
+ * @example
4246
+ * ```ts
4247
+ * const fn = await client.functions.get('function-uuid');
4248
+ * console.log('Function name:', fn.data.name);
4249
+ * ```
4250
+ */
4251
+ public get(functionId: string): Promise<ApiResponse<ComputeFunction>> {
4252
+ const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
4253
+ return this.requestFn<ComputeFunction>('GET', path);
4254
+ }
4255
+
4256
+ /**
4257
+ * Create a new compute function.
4258
+ *
4259
+ * @param input - The function definition
4260
+ * @returns The created compute function
4261
+ *
4262
+ * @example
4263
+ * ```ts
4264
+ * const fn = await client.functions.create({
4265
+ * name: 'Process Order',
4266
+ * slug: 'process-order',
4267
+ * code: 'module.exports = async (ctx) => { return { processed: true }; }',
4268
+ * description: 'Processes incoming orders',
4269
+ * timeout: 60000
4270
+ * });
4271
+ * ```
4272
+ */
4273
+ public create(input: CreateComputeFunctionInput): Promise<ApiResponse<ComputeFunction>> {
4274
+ const path = getComputeFunctionsApiPath(this.workspaceId);
4275
+ return this.requestFn<ComputeFunction>('POST', path, input);
4276
+ }
4277
+
4278
+ /**
4279
+ * Update an existing compute function.
4280
+ *
4281
+ * @param functionId - The compute function UUID
4282
+ * @param input - The fields to update
4283
+ * @returns The updated compute function
4284
+ *
4285
+ * @example
4286
+ * ```ts
4287
+ * const updated = await client.functions.update('function-uuid', {
4288
+ * code: 'module.exports = async (ctx) => { return { v2: true }; }',
4289
+ * timeout: 120000
4290
+ * });
4291
+ * ```
4292
+ */
4293
+ public update(functionId: string, input: UpdateComputeFunctionInput): Promise<ApiResponse<ComputeFunction>> {
4294
+ const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
4295
+ return this.requestFn<ComputeFunction>('PUT', path, input);
4296
+ }
4297
+
4298
+ /**
4299
+ * Delete a compute function.
4300
+ *
4301
+ * @param functionId - The compute function UUID
4302
+ *
4303
+ * @example
4304
+ * ```ts
4305
+ * await client.functions.delete('function-uuid');
4306
+ * ```
4307
+ */
4308
+ public delete(functionId: string): Promise<ApiResponse<void>> {
4309
+ const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
4310
+ return this.requestFn<void>('DELETE', path);
4311
+ }
4312
+
4313
+ /**
4314
+ * Test execute code without saving it as a function.
4315
+ * Useful for validating function code before creating/updating.
4316
+ *
4317
+ * @param input - The code to test and optional input data
4318
+ * @returns Test execution result including output, duration, and logs
4319
+ *
4320
+ * @example
4321
+ * ```ts
4322
+ * const result = await client.functions.testExecute({
4323
+ * code: 'module.exports = async (ctx) => { return { sum: ctx.input.a + ctx.input.b }; }',
4324
+ * input: { a: 1, b: 2 }
4325
+ * });
4326
+ * console.log('Output:', result.data.output); // { sum: 3 }
4327
+ * console.log('Duration:', result.data.duration_ms, 'ms');
4328
+ * ```
4329
+ */
4330
+ public testExecute(input: TestComputeFunctionInput): Promise<ApiResponse<TestComputeFunctionResult>> {
4331
+ const path = getComputeFunctionTestApiPath(this.workspaceId);
4332
+ return this.requestFn<TestComputeFunctionResult>('POST', path, input);
4333
+ }
4334
+ }
4335
+
3385
4336
  /**
3386
4337
  * Main Centrali SDK client.
3387
4338
  */
@@ -3396,6 +4347,8 @@ export class CentraliSDK {
3396
4347
  private _validation: ValidationManager | null = null;
3397
4348
  private _orchestrations: OrchestrationsManager | null = null;
3398
4349
  private _allowedDomains: AllowedDomainsManager | null = null;
4350
+ private _structures: StructuresManager | null = null;
4351
+ private _functions: ComputeFunctionsManager | null = null;
3399
4352
  private isRefreshingToken: boolean = false;
3400
4353
  private tokenRefreshPromise: Promise<string> | null = null;
3401
4354
 
@@ -3723,6 +4676,69 @@ export class CentraliSDK {
3723
4676
  return this._allowedDomains;
3724
4677
  }
3725
4678
 
4679
+ /**
4680
+ * Structures namespace for managing data structures (schemas).
4681
+ * Provides CRUD operations and validation for structure definitions.
4682
+ *
4683
+ * Usage:
4684
+ * ```ts
4685
+ * // List all structures
4686
+ * const structures = await client.structures.list();
4687
+ *
4688
+ * // Create a structure
4689
+ * const structure = await client.structures.create({
4690
+ * name: 'Orders',
4691
+ * slug: 'orders',
4692
+ * properties: [{ name: 'title', type: 'string', required: true }]
4693
+ * });
4694
+ *
4695
+ * // Validate before creating
4696
+ * const result = await client.structures.validate({ slug: 'orders' });
4697
+ * ```
4698
+ */
4699
+ public get structures(): StructuresManager {
4700
+ if (!this._structures) {
4701
+ this._structures = new StructuresManager(
4702
+ this.options.workspaceId,
4703
+ this.request.bind(this)
4704
+ );
4705
+ }
4706
+ return this._structures;
4707
+ }
4708
+
4709
+ /**
4710
+ * Functions namespace for managing compute functions.
4711
+ * Provides CRUD operations and test execution for compute function code.
4712
+ *
4713
+ * Usage:
4714
+ * ```ts
4715
+ * // List all functions
4716
+ * const fns = await client.functions.list();
4717
+ *
4718
+ * // Create a function
4719
+ * const fn = await client.functions.create({
4720
+ * name: 'Process Order',
4721
+ * slug: 'process-order',
4722
+ * code: 'module.exports = async (ctx) => { return { ok: true }; }'
4723
+ * });
4724
+ *
4725
+ * // Test execute without saving
4726
+ * const result = await client.functions.testExecute({
4727
+ * code: 'module.exports = async (ctx) => { return ctx.input; }',
4728
+ * input: { test: true }
4729
+ * });
4730
+ * ```
4731
+ */
4732
+ public get functions(): ComputeFunctionsManager {
4733
+ if (!this._functions) {
4734
+ this._functions = new ComputeFunctionsManager(
4735
+ this.options.workspaceId,
4736
+ this.request.bind(this)
4737
+ );
4738
+ }
4739
+ return this._functions;
4740
+ }
4741
+
3726
4742
  /**
3727
4743
  * Manually set or update the bearer token for subsequent requests.
3728
4744
  */