@centrali-io/centrali-sdk 3.0.9 → 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.
- package/dist/index.js +611 -1
- package/index.ts +1036 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.CentraliSDK = exports.AllowedDomainsManager = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.OrchestrationsManager = exports.RealtimeManager = void 0;
|
|
21
|
+
exports.CentraliSDK = exports.ComputeFunctionsManager = exports.StructuresManager = exports.AllowedDomainsManager = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.OrchestrationsManager = exports.RealtimeManager = void 0;
|
|
22
22
|
exports.getApiUrl = getApiUrl;
|
|
23
23
|
exports.getAuthUrl = getAuthUrl;
|
|
24
24
|
exports.getRealtimeUrl = getRealtimeUrl;
|
|
@@ -41,6 +41,12 @@ exports.getAnomalyInsightDismissApiPath = getAnomalyInsightDismissApiPath;
|
|
|
41
41
|
exports.getAnomalyInsightsBulkAcknowledgeApiPath = getAnomalyInsightsBulkAcknowledgeApiPath;
|
|
42
42
|
exports.getAnomalyAnalysisTriggerApiPath = getAnomalyAnalysisTriggerApiPath;
|
|
43
43
|
exports.getStructureInsightsApiPath = getStructureInsightsApiPath;
|
|
44
|
+
exports.getStructuresApiPath = getStructuresApiPath;
|
|
45
|
+
exports.getStructureBySlugApiPath = getStructureBySlugApiPath;
|
|
46
|
+
exports.getStructureValidateApiPath = getStructureValidateApiPath;
|
|
47
|
+
exports.getComputeFunctionsApiPath = getComputeFunctionsApiPath;
|
|
48
|
+
exports.getComputeFunctionTestApiPath = getComputeFunctionTestApiPath;
|
|
49
|
+
exports.getSmartQueryTestApiPath = getSmartQueryTestApiPath;
|
|
44
50
|
exports.getValidationSuggestionsApiPath = getValidationSuggestionsApiPath;
|
|
45
51
|
exports.getValidationSuggestionAcceptApiPath = getValidationSuggestionAcceptApiPath;
|
|
46
52
|
exports.getValidationSuggestionRejectApiPath = getValidationSuggestionRejectApiPath;
|
|
@@ -456,6 +462,53 @@ function getStructureInsightsApiPath(workspaceId, structureSlug) {
|
|
|
456
462
|
return `data/workspace/${workspaceId}/api/v1/structures/${structureSlug}/insights`;
|
|
457
463
|
}
|
|
458
464
|
// =====================================================
|
|
465
|
+
// Structure API Path Helpers (Configuration-as-Code)
|
|
466
|
+
// =====================================================
|
|
467
|
+
/**
|
|
468
|
+
* Generate Structures base API URL PATH.
|
|
469
|
+
*/
|
|
470
|
+
function getStructuresApiPath(workspaceId, structureId) {
|
|
471
|
+
const basePath = `data/workspace/${workspaceId}/api/v1/structures`;
|
|
472
|
+
return structureId ? `${basePath}/${structureId}` : basePath;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Generate Structure by slug API URL PATH.
|
|
476
|
+
*/
|
|
477
|
+
function getStructureBySlugApiPath(workspaceId, recordSlug) {
|
|
478
|
+
return `data/workspace/${workspaceId}/api/v1/structures/slug/${recordSlug}`;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Generate Structure validate API URL PATH.
|
|
482
|
+
*/
|
|
483
|
+
function getStructureValidateApiPath(workspaceId) {
|
|
484
|
+
return `data/workspace/${workspaceId}/api/v1/structures/validate`;
|
|
485
|
+
}
|
|
486
|
+
// =====================================================
|
|
487
|
+
// Compute Function API Path Helpers (Configuration-as-Code)
|
|
488
|
+
// =====================================================
|
|
489
|
+
/**
|
|
490
|
+
* Generate Compute Functions base API URL PATH.
|
|
491
|
+
*/
|
|
492
|
+
function getComputeFunctionsApiPath(workspaceId, functionId) {
|
|
493
|
+
const basePath = `data/workspace/${workspaceId}/api/v1/compute-functions`;
|
|
494
|
+
return functionId ? `${basePath}/${functionId}` : basePath;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Generate Compute Function test execution API URL PATH.
|
|
498
|
+
*/
|
|
499
|
+
function getComputeFunctionTestApiPath(workspaceId) {
|
|
500
|
+
return `data/workspace/${workspaceId}/api/v1/compute-functions/test`;
|
|
501
|
+
}
|
|
502
|
+
// =====================================================
|
|
503
|
+
// Smart Query Test API Path Helper (Configuration-as-Code)
|
|
504
|
+
// =====================================================
|
|
505
|
+
/**
|
|
506
|
+
* Generate Smart Query test execution API URL PATH.
|
|
507
|
+
*/
|
|
508
|
+
function getSmartQueryTestApiPath(workspaceId, structureSlug) {
|
|
509
|
+
return `data/workspace/${workspaceId}/api/v1/smart-queries/slug/${structureSlug}/test`;
|
|
510
|
+
}
|
|
511
|
+
// =====================================================
|
|
459
512
|
// Validation API Path Helpers
|
|
460
513
|
// =====================================================
|
|
461
514
|
/**
|
|
@@ -990,6 +1043,113 @@ class TriggersManager {
|
|
|
990
1043
|
const path = getFunctionTriggerResumeApiPath(this.workspaceId, triggerId);
|
|
991
1044
|
return this.requestFn('PATCH', path, {});
|
|
992
1045
|
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Create a new function trigger.
|
|
1048
|
+
*
|
|
1049
|
+
* @param input - The trigger definition
|
|
1050
|
+
* @returns The created trigger
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```ts
|
|
1054
|
+
* // Create an event-driven trigger
|
|
1055
|
+
* const trigger = await client.triggers.create({
|
|
1056
|
+
* name: 'On Order Created',
|
|
1057
|
+
* functionId: 'function-uuid',
|
|
1058
|
+
* executionType: 'event-driven',
|
|
1059
|
+
* triggerMetadata: { event: 'record.created', recordSlug: 'orders' }
|
|
1060
|
+
* });
|
|
1061
|
+
*
|
|
1062
|
+
* // Create a scheduled trigger
|
|
1063
|
+
* const scheduled = await client.triggers.create({
|
|
1064
|
+
* name: 'Daily Report',
|
|
1065
|
+
* functionId: 'function-uuid',
|
|
1066
|
+
* executionType: 'scheduled',
|
|
1067
|
+
* triggerMetadata: { scheduleType: 'cron', cronExpression: '0 9 * * *', timezone: 'America/New_York' }
|
|
1068
|
+
* });
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
1071
|
+
create(input) {
|
|
1072
|
+
const path = getFunctionTriggersApiPath(this.workspaceId);
|
|
1073
|
+
return this.requestFn('POST', path, input);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Update an existing function trigger.
|
|
1077
|
+
*
|
|
1078
|
+
* @param triggerId - The trigger UUID
|
|
1079
|
+
* @param input - The fields to update
|
|
1080
|
+
* @returns The updated trigger
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* const updated = await client.triggers.update('trigger-uuid', {
|
|
1085
|
+
* name: 'Updated Trigger Name',
|
|
1086
|
+
* enabled: false
|
|
1087
|
+
* });
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
1090
|
+
update(triggerId, input) {
|
|
1091
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
1092
|
+
return this.requestFn('PUT', path, input);
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Delete a function trigger.
|
|
1096
|
+
*
|
|
1097
|
+
* @param triggerId - The trigger UUID
|
|
1098
|
+
*
|
|
1099
|
+
* @example
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* await client.triggers.delete('trigger-uuid');
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
delete(triggerId) {
|
|
1105
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
1106
|
+
return this.requestFn('DELETE', path);
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* List all triggers in the workspace (not filtered by execution type).
|
|
1110
|
+
* Unlike `list()` which only returns on-demand triggers, `listAll()` returns
|
|
1111
|
+
* triggers of all types with optional filtering.
|
|
1112
|
+
*
|
|
1113
|
+
* @param options - Optional list parameters (pagination, filtering, health)
|
|
1114
|
+
* @returns List of triggers
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* // List all triggers
|
|
1119
|
+
* const all = await client.triggers.listAll();
|
|
1120
|
+
*
|
|
1121
|
+
* // Filter by execution type
|
|
1122
|
+
* const scheduled = await client.triggers.listAll({ executionType: 'scheduled' });
|
|
1123
|
+
*
|
|
1124
|
+
* // Include health metrics
|
|
1125
|
+
* const withHealth = await client.triggers.listAll({ includeHealth: true });
|
|
1126
|
+
* ```
|
|
1127
|
+
*/
|
|
1128
|
+
listAll(options) {
|
|
1129
|
+
const path = getFunctionTriggersApiPath(this.workspaceId);
|
|
1130
|
+
return this.requestFn('GET', path, null, options);
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Get a trigger by ID with full details (no on-demand type restriction).
|
|
1134
|
+
* Unlike `get()` which validates on-demand type, `getDetails()` returns
|
|
1135
|
+
* any trigger type.
|
|
1136
|
+
*
|
|
1137
|
+
* @param triggerId - The trigger UUID
|
|
1138
|
+
* @param options - Optional parameters (includeHealth)
|
|
1139
|
+
* @returns The trigger details
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```ts
|
|
1143
|
+
* const trigger = await client.triggers.getDetails('trigger-uuid');
|
|
1144
|
+
*
|
|
1145
|
+
* // With health metrics
|
|
1146
|
+
* const withHealth = await client.triggers.getDetails('trigger-uuid', { includeHealth: true });
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
getDetails(triggerId, options) {
|
|
1150
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
1151
|
+
return this.requestFn('GET', path, null, options);
|
|
1152
|
+
}
|
|
993
1153
|
}
|
|
994
1154
|
exports.TriggersManager = TriggersManager;
|
|
995
1155
|
// =====================================================
|
|
@@ -1133,6 +1293,92 @@ class SmartQueriesManager {
|
|
|
1133
1293
|
const body = (options === null || options === void 0 ? void 0 : options.variables) ? { variables: options.variables } : undefined;
|
|
1134
1294
|
return this.requestFn('POST', path, body);
|
|
1135
1295
|
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Create a new smart query for a structure.
|
|
1298
|
+
*
|
|
1299
|
+
* @param structureSlug - The structure's record slug
|
|
1300
|
+
* @param input - The smart query definition
|
|
1301
|
+
* @returns The created smart query
|
|
1302
|
+
*
|
|
1303
|
+
* @example
|
|
1304
|
+
* ```ts
|
|
1305
|
+
* const query = await client.smartQueries.create('orders', {
|
|
1306
|
+
* name: 'Active Orders',
|
|
1307
|
+
* description: 'All orders with active status',
|
|
1308
|
+
* queryDefinition: {
|
|
1309
|
+
* where: { status: { $eq: 'active' } },
|
|
1310
|
+
* sort: [{ field: 'createdAt', direction: 'desc' }],
|
|
1311
|
+
* limit: 100
|
|
1312
|
+
* }
|
|
1313
|
+
* });
|
|
1314
|
+
* ```
|
|
1315
|
+
*/
|
|
1316
|
+
create(structureSlug, input) {
|
|
1317
|
+
const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug);
|
|
1318
|
+
return this.requestFn('POST', path, input);
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Update an existing smart query.
|
|
1322
|
+
*
|
|
1323
|
+
* @param structureSlug - The structure's record slug
|
|
1324
|
+
* @param queryId - The smart query UUID
|
|
1325
|
+
* @param input - The fields to update
|
|
1326
|
+
* @returns The updated smart query
|
|
1327
|
+
*
|
|
1328
|
+
* @example
|
|
1329
|
+
* ```ts
|
|
1330
|
+
* const updated = await client.smartQueries.update('orders', 'query-uuid', {
|
|
1331
|
+
* name: 'Active Orders v2',
|
|
1332
|
+
* queryDefinition: {
|
|
1333
|
+
* where: { status: { $in: ['active', 'processing'] } },
|
|
1334
|
+
* limit: 200
|
|
1335
|
+
* }
|
|
1336
|
+
* });
|
|
1337
|
+
* ```
|
|
1338
|
+
*/
|
|
1339
|
+
update(structureSlug, queryId, input) {
|
|
1340
|
+
const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug, queryId);
|
|
1341
|
+
return this.requestFn('PUT', path, input);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Delete a smart query.
|
|
1345
|
+
*
|
|
1346
|
+
* @param structureSlug - The structure's record slug
|
|
1347
|
+
* @param queryId - The smart query UUID
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```ts
|
|
1351
|
+
* await client.smartQueries.delete('orders', 'query-uuid');
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
delete(structureSlug, queryId) {
|
|
1355
|
+
const path = getSmartQueriesStructureApiPath(this.workspaceId, structureSlug, queryId);
|
|
1356
|
+
return this.requestFn('DELETE', path);
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Test execute a query definition without saving it.
|
|
1360
|
+
* Useful for validating query syntax and previewing results before creating.
|
|
1361
|
+
*
|
|
1362
|
+
* @param structureSlug - The structure's record slug
|
|
1363
|
+
* @param input - The query definition to test and optional variables
|
|
1364
|
+
* @returns Test execution results
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```ts
|
|
1368
|
+
* const result = await client.smartQueries.test('orders', {
|
|
1369
|
+
* queryDefinition: {
|
|
1370
|
+
* where: { amount: { $gte: 100 } },
|
|
1371
|
+
* select: ['id', 'amount', 'status'],
|
|
1372
|
+
* limit: 5
|
|
1373
|
+
* }
|
|
1374
|
+
* });
|
|
1375
|
+
* console.log('Preview results:', result.data);
|
|
1376
|
+
* ```
|
|
1377
|
+
*/
|
|
1378
|
+
test(structureSlug, input) {
|
|
1379
|
+
const path = getSmartQueryTestApiPath(this.workspaceId, structureSlug);
|
|
1380
|
+
return this.requestFn('POST', path, input);
|
|
1381
|
+
}
|
|
1136
1382
|
}
|
|
1137
1383
|
exports.SmartQueriesManager = SmartQueriesManager;
|
|
1138
1384
|
// =====================================================
|
|
@@ -1626,6 +1872,313 @@ class AllowedDomainsManager {
|
|
|
1626
1872
|
}
|
|
1627
1873
|
}
|
|
1628
1874
|
exports.AllowedDomainsManager = AllowedDomainsManager;
|
|
1875
|
+
// =====================================================
|
|
1876
|
+
// Structures Manager (Configuration-as-Code)
|
|
1877
|
+
// =====================================================
|
|
1878
|
+
/**
|
|
1879
|
+
* StructuresManager provides methods for managing data structures (schemas).
|
|
1880
|
+
* Structures define the shape of records including properties, validation rules,
|
|
1881
|
+
* and schema discovery modes.
|
|
1882
|
+
* Access via `client.structures`.
|
|
1883
|
+
*
|
|
1884
|
+
* Usage:
|
|
1885
|
+
* ```ts
|
|
1886
|
+
* // List all structures
|
|
1887
|
+
* const structures = await client.structures.list();
|
|
1888
|
+
*
|
|
1889
|
+
* // Create a new structure
|
|
1890
|
+
* const structure = await client.structures.create({
|
|
1891
|
+
* name: 'Orders',
|
|
1892
|
+
* slug: 'orders',
|
|
1893
|
+
* properties: [
|
|
1894
|
+
* { name: 'title', type: 'string', required: true },
|
|
1895
|
+
* { name: 'amount', type: 'number', minimum: 0 }
|
|
1896
|
+
* ]
|
|
1897
|
+
* });
|
|
1898
|
+
*
|
|
1899
|
+
* // Validate before creating
|
|
1900
|
+
* const validation = await client.structures.validate({ slug: 'orders' });
|
|
1901
|
+
* ```
|
|
1902
|
+
*/
|
|
1903
|
+
class StructuresManager {
|
|
1904
|
+
constructor(workspaceId, requestFn) {
|
|
1905
|
+
this.workspaceId = workspaceId;
|
|
1906
|
+
this.requestFn = requestFn;
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* List all structures in the workspace.
|
|
1910
|
+
*
|
|
1911
|
+
* @param options - Optional list parameters (pagination)
|
|
1912
|
+
* @returns List of structures
|
|
1913
|
+
*
|
|
1914
|
+
* @example
|
|
1915
|
+
* ```ts
|
|
1916
|
+
* const structures = await client.structures.list();
|
|
1917
|
+
* const page2 = await client.structures.list({ page: 2, limit: 10 });
|
|
1918
|
+
* ```
|
|
1919
|
+
*/
|
|
1920
|
+
list(options) {
|
|
1921
|
+
const path = getStructuresApiPath(this.workspaceId);
|
|
1922
|
+
return this.requestFn('GET', path, null, options);
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Get a structure by ID.
|
|
1926
|
+
*
|
|
1927
|
+
* @param structureId - The structure UUID
|
|
1928
|
+
* @returns The structure details
|
|
1929
|
+
*
|
|
1930
|
+
* @example
|
|
1931
|
+
* ```ts
|
|
1932
|
+
* const structure = await client.structures.get('structure-uuid');
|
|
1933
|
+
* console.log('Properties:', structure.data.properties.length);
|
|
1934
|
+
* ```
|
|
1935
|
+
*/
|
|
1936
|
+
get(structureId) {
|
|
1937
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
1938
|
+
return this.requestFn('GET', path);
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Get a structure by its record slug.
|
|
1942
|
+
*
|
|
1943
|
+
* @param recordSlug - The structure's record slug (e.g., "orders")
|
|
1944
|
+
* @returns The structure details
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```ts
|
|
1948
|
+
* const structure = await client.structures.getBySlug('orders');
|
|
1949
|
+
* console.log('Structure name:', structure.data.name);
|
|
1950
|
+
* ```
|
|
1951
|
+
*/
|
|
1952
|
+
getBySlug(recordSlug) {
|
|
1953
|
+
const path = getStructureBySlugApiPath(this.workspaceId, recordSlug);
|
|
1954
|
+
return this.requestFn('GET', path);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Create a new structure.
|
|
1958
|
+
*
|
|
1959
|
+
* @param input - The structure definition
|
|
1960
|
+
* @returns The created structure
|
|
1961
|
+
*
|
|
1962
|
+
* @example
|
|
1963
|
+
* ```ts
|
|
1964
|
+
* const structure = await client.structures.create({
|
|
1965
|
+
* name: 'Orders',
|
|
1966
|
+
* slug: 'orders',
|
|
1967
|
+
* description: 'Customer orders',
|
|
1968
|
+
* properties: [
|
|
1969
|
+
* { name: 'title', type: 'string', required: true },
|
|
1970
|
+
* { name: 'amount', type: 'number', minimum: 0 },
|
|
1971
|
+
* { name: 'status', type: 'string', enum: ['pending', 'completed'] }
|
|
1972
|
+
* ],
|
|
1973
|
+
* enableVersioning: true,
|
|
1974
|
+
* schemaDiscoveryMode: 'strict'
|
|
1975
|
+
* });
|
|
1976
|
+
* ```
|
|
1977
|
+
*/
|
|
1978
|
+
create(input) {
|
|
1979
|
+
const path = getStructuresApiPath(this.workspaceId);
|
|
1980
|
+
return this.requestFn('POST', path, input);
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Update an existing structure.
|
|
1984
|
+
*
|
|
1985
|
+
* @param structureId - The structure UUID
|
|
1986
|
+
* @param input - The fields to update
|
|
1987
|
+
* @returns The updated structure
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* ```ts
|
|
1991
|
+
* const updated = await client.structures.update('structure-uuid', {
|
|
1992
|
+
* name: 'Updated Orders',
|
|
1993
|
+
* properties: [
|
|
1994
|
+
* { name: 'title', type: 'string', required: true },
|
|
1995
|
+
* { name: 'amount', type: 'number', minimum: 0 },
|
|
1996
|
+
* { name: 'priority', type: 'number' }
|
|
1997
|
+
* ]
|
|
1998
|
+
* });
|
|
1999
|
+
* ```
|
|
2000
|
+
*/
|
|
2001
|
+
update(structureId, input) {
|
|
2002
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
2003
|
+
return this.requestFn('PUT', path, input);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Delete a structure.
|
|
2007
|
+
*
|
|
2008
|
+
* @param structureId - The structure UUID
|
|
2009
|
+
*
|
|
2010
|
+
* @example
|
|
2011
|
+
* ```ts
|
|
2012
|
+
* await client.structures.delete('structure-uuid');
|
|
2013
|
+
* ```
|
|
2014
|
+
*/
|
|
2015
|
+
delete(structureId) {
|
|
2016
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
2017
|
+
return this.requestFn('DELETE', path);
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Validate a structure definition without creating it.
|
|
2021
|
+
* Useful for checking slug uniqueness and property validity before creation.
|
|
2022
|
+
*
|
|
2023
|
+
* @param input - The structure definition to validate
|
|
2024
|
+
* @returns Validation result
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```ts
|
|
2028
|
+
* const result = await client.structures.validate({
|
|
2029
|
+
* slug: 'orders',
|
|
2030
|
+
* properties: [{ name: 'title', type: 'string' }]
|
|
2031
|
+
* });
|
|
2032
|
+
* ```
|
|
2033
|
+
*/
|
|
2034
|
+
validate(input) {
|
|
2035
|
+
const path = getStructureValidateApiPath(this.workspaceId);
|
|
2036
|
+
return this.requestFn('POST', path, input);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
exports.StructuresManager = StructuresManager;
|
|
2040
|
+
// =====================================================
|
|
2041
|
+
// Compute Functions Manager (Configuration-as-Code)
|
|
2042
|
+
// =====================================================
|
|
2043
|
+
/**
|
|
2044
|
+
* ComputeFunctionsManager provides methods for managing compute functions.
|
|
2045
|
+
* Compute functions are JavaScript code blocks that can be executed on triggers,
|
|
2046
|
+
* schedules, or on-demand.
|
|
2047
|
+
* Access via `client.functions`.
|
|
2048
|
+
*
|
|
2049
|
+
* Usage:
|
|
2050
|
+
* ```ts
|
|
2051
|
+
* // List all compute functions
|
|
2052
|
+
* const fns = await client.functions.list();
|
|
2053
|
+
*
|
|
2054
|
+
* // Create a new function
|
|
2055
|
+
* const fn = await client.functions.create({
|
|
2056
|
+
* name: 'Process Order',
|
|
2057
|
+
* slug: 'process-order',
|
|
2058
|
+
* code: 'module.exports = async (ctx) => { return { processed: true }; }'
|
|
2059
|
+
* });
|
|
2060
|
+
*
|
|
2061
|
+
* // Test execute code without saving
|
|
2062
|
+
* const result = await client.functions.testExecute({
|
|
2063
|
+
* code: 'module.exports = async (ctx) => { return ctx.input; }',
|
|
2064
|
+
* input: { orderId: '123' }
|
|
2065
|
+
* });
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
class ComputeFunctionsManager {
|
|
2069
|
+
constructor(workspaceId, requestFn) {
|
|
2070
|
+
this.workspaceId = workspaceId;
|
|
2071
|
+
this.requestFn = requestFn;
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* List all compute functions in the workspace.
|
|
2075
|
+
*
|
|
2076
|
+
* @param options - Optional list parameters (pagination, search)
|
|
2077
|
+
* @returns List of compute functions
|
|
2078
|
+
*
|
|
2079
|
+
* @example
|
|
2080
|
+
* ```ts
|
|
2081
|
+
* const fns = await client.functions.list();
|
|
2082
|
+
* const searched = await client.functions.list({ search: 'order', limit: 10 });
|
|
2083
|
+
* ```
|
|
2084
|
+
*/
|
|
2085
|
+
list(options) {
|
|
2086
|
+
const path = getComputeFunctionsApiPath(this.workspaceId);
|
|
2087
|
+
return this.requestFn('GET', path, null, options);
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Get a compute function by ID.
|
|
2091
|
+
*
|
|
2092
|
+
* @param functionId - The compute function UUID
|
|
2093
|
+
* @returns The compute function details
|
|
2094
|
+
*
|
|
2095
|
+
* @example
|
|
2096
|
+
* ```ts
|
|
2097
|
+
* const fn = await client.functions.get('function-uuid');
|
|
2098
|
+
* console.log('Function name:', fn.data.name);
|
|
2099
|
+
* ```
|
|
2100
|
+
*/
|
|
2101
|
+
get(functionId) {
|
|
2102
|
+
const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
|
|
2103
|
+
return this.requestFn('GET', path);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Create a new compute function.
|
|
2107
|
+
*
|
|
2108
|
+
* @param input - The function definition
|
|
2109
|
+
* @returns The created compute function
|
|
2110
|
+
*
|
|
2111
|
+
* @example
|
|
2112
|
+
* ```ts
|
|
2113
|
+
* const fn = await client.functions.create({
|
|
2114
|
+
* name: 'Process Order',
|
|
2115
|
+
* slug: 'process-order',
|
|
2116
|
+
* code: 'module.exports = async (ctx) => { return { processed: true }; }',
|
|
2117
|
+
* description: 'Processes incoming orders',
|
|
2118
|
+
* timeout: 60000
|
|
2119
|
+
* });
|
|
2120
|
+
* ```
|
|
2121
|
+
*/
|
|
2122
|
+
create(input) {
|
|
2123
|
+
const path = getComputeFunctionsApiPath(this.workspaceId);
|
|
2124
|
+
return this.requestFn('POST', path, input);
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Update an existing compute function.
|
|
2128
|
+
*
|
|
2129
|
+
* @param functionId - The compute function UUID
|
|
2130
|
+
* @param input - The fields to update
|
|
2131
|
+
* @returns The updated compute function
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
2134
|
+
* ```ts
|
|
2135
|
+
* const updated = await client.functions.update('function-uuid', {
|
|
2136
|
+
* code: 'module.exports = async (ctx) => { return { v2: true }; }',
|
|
2137
|
+
* timeout: 120000
|
|
2138
|
+
* });
|
|
2139
|
+
* ```
|
|
2140
|
+
*/
|
|
2141
|
+
update(functionId, input) {
|
|
2142
|
+
const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
|
|
2143
|
+
return this.requestFn('PUT', path, input);
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* Delete a compute function.
|
|
2147
|
+
*
|
|
2148
|
+
* @param functionId - The compute function UUID
|
|
2149
|
+
*
|
|
2150
|
+
* @example
|
|
2151
|
+
* ```ts
|
|
2152
|
+
* await client.functions.delete('function-uuid');
|
|
2153
|
+
* ```
|
|
2154
|
+
*/
|
|
2155
|
+
delete(functionId) {
|
|
2156
|
+
const path = getComputeFunctionsApiPath(this.workspaceId, functionId);
|
|
2157
|
+
return this.requestFn('DELETE', path);
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Test execute code without saving it as a function.
|
|
2161
|
+
* Useful for validating function code before creating/updating.
|
|
2162
|
+
*
|
|
2163
|
+
* @param input - The code to test and optional input data
|
|
2164
|
+
* @returns Test execution result including output, duration, and logs
|
|
2165
|
+
*
|
|
2166
|
+
* @example
|
|
2167
|
+
* ```ts
|
|
2168
|
+
* const result = await client.functions.testExecute({
|
|
2169
|
+
* code: 'module.exports = async (ctx) => { return { sum: ctx.input.a + ctx.input.b }; }',
|
|
2170
|
+
* input: { a: 1, b: 2 }
|
|
2171
|
+
* });
|
|
2172
|
+
* console.log('Output:', result.data.output); // { sum: 3 }
|
|
2173
|
+
* console.log('Duration:', result.data.duration_ms, 'ms');
|
|
2174
|
+
* ```
|
|
2175
|
+
*/
|
|
2176
|
+
testExecute(input) {
|
|
2177
|
+
const path = getComputeFunctionTestApiPath(this.workspaceId);
|
|
2178
|
+
return this.requestFn('POST', path, input);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
exports.ComputeFunctionsManager = ComputeFunctionsManager;
|
|
1629
2182
|
/**
|
|
1630
2183
|
* Main Centrali SDK client.
|
|
1631
2184
|
*/
|
|
@@ -1639,6 +2192,8 @@ class CentraliSDK {
|
|
|
1639
2192
|
this._validation = null;
|
|
1640
2193
|
this._orchestrations = null;
|
|
1641
2194
|
this._allowedDomains = null;
|
|
2195
|
+
this._structures = null;
|
|
2196
|
+
this._functions = null;
|
|
1642
2197
|
this.isRefreshingToken = false;
|
|
1643
2198
|
this.tokenRefreshPromise = null;
|
|
1644
2199
|
this.options = options;
|
|
@@ -1907,6 +2462,61 @@ class CentraliSDK {
|
|
|
1907
2462
|
}
|
|
1908
2463
|
return this._allowedDomains;
|
|
1909
2464
|
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Structures namespace for managing data structures (schemas).
|
|
2467
|
+
* Provides CRUD operations and validation for structure definitions.
|
|
2468
|
+
*
|
|
2469
|
+
* Usage:
|
|
2470
|
+
* ```ts
|
|
2471
|
+
* // List all structures
|
|
2472
|
+
* const structures = await client.structures.list();
|
|
2473
|
+
*
|
|
2474
|
+
* // Create a structure
|
|
2475
|
+
* const structure = await client.structures.create({
|
|
2476
|
+
* name: 'Orders',
|
|
2477
|
+
* slug: 'orders',
|
|
2478
|
+
* properties: [{ name: 'title', type: 'string', required: true }]
|
|
2479
|
+
* });
|
|
2480
|
+
*
|
|
2481
|
+
* // Validate before creating
|
|
2482
|
+
* const result = await client.structures.validate({ slug: 'orders' });
|
|
2483
|
+
* ```
|
|
2484
|
+
*/
|
|
2485
|
+
get structures() {
|
|
2486
|
+
if (!this._structures) {
|
|
2487
|
+
this._structures = new StructuresManager(this.options.workspaceId, this.request.bind(this));
|
|
2488
|
+
}
|
|
2489
|
+
return this._structures;
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Functions namespace for managing compute functions.
|
|
2493
|
+
* Provides CRUD operations and test execution for compute function code.
|
|
2494
|
+
*
|
|
2495
|
+
* Usage:
|
|
2496
|
+
* ```ts
|
|
2497
|
+
* // List all functions
|
|
2498
|
+
* const fns = await client.functions.list();
|
|
2499
|
+
*
|
|
2500
|
+
* // Create a function
|
|
2501
|
+
* const fn = await client.functions.create({
|
|
2502
|
+
* name: 'Process Order',
|
|
2503
|
+
* slug: 'process-order',
|
|
2504
|
+
* code: 'module.exports = async (ctx) => { return { ok: true }; }'
|
|
2505
|
+
* });
|
|
2506
|
+
*
|
|
2507
|
+
* // Test execute without saving
|
|
2508
|
+
* const result = await client.functions.testExecute({
|
|
2509
|
+
* code: 'module.exports = async (ctx) => { return ctx.input; }',
|
|
2510
|
+
* input: { test: true }
|
|
2511
|
+
* });
|
|
2512
|
+
* ```
|
|
2513
|
+
*/
|
|
2514
|
+
get functions() {
|
|
2515
|
+
if (!this._functions) {
|
|
2516
|
+
this._functions = new ComputeFunctionsManager(this.options.workspaceId, this.request.bind(this));
|
|
2517
|
+
}
|
|
2518
|
+
return this._functions;
|
|
2519
|
+
}
|
|
1910
2520
|
/**
|
|
1911
2521
|
* Manually set or update the bearer token for subsequent requests.
|
|
1912
2522
|
*/
|