@centrali-io/centrali-sdk 4.4.5 → 4.4.7
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 +88 -0
- package/index.ts +136 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ exports.getFunctionTriggersApiPath = getFunctionTriggersApiPath;
|
|
|
63
63
|
exports.getFunctionTriggerExecuteApiPath = getFunctionTriggerExecuteApiPath;
|
|
64
64
|
exports.getFunctionTriggerPauseApiPath = getFunctionTriggerPauseApiPath;
|
|
65
65
|
exports.getFunctionTriggerResumeApiPath = getFunctionTriggerResumeApiPath;
|
|
66
|
+
exports.getEndpointApiPath = getEndpointApiPath;
|
|
66
67
|
exports.getSmartQueriesApiPath = getSmartQueriesApiPath;
|
|
67
68
|
exports.getSmartQueriesStructureApiPath = getSmartQueriesStructureApiPath;
|
|
68
69
|
exports.getSmartQueryByNameApiPath = getSmartQueryByNameApiPath;
|
|
@@ -87,6 +88,7 @@ exports.getComputeFunctionTestApiPath = getComputeFunctionTestApiPath;
|
|
|
87
88
|
exports.getFunctionRunsApiPath = getFunctionRunsApiPath;
|
|
88
89
|
exports.getFunctionRunsByTriggerApiPath = getFunctionRunsByTriggerApiPath;
|
|
89
90
|
exports.getFunctionRunsByFunctionApiPath = getFunctionRunsByFunctionApiPath;
|
|
91
|
+
exports.getComputeJobStatusApiPath = getComputeJobStatusApiPath;
|
|
90
92
|
exports.getSmartQueryTestApiPath = getSmartQueryTestApiPath;
|
|
91
93
|
exports.getValidationSuggestionsApiPath = getValidationSuggestionsApiPath;
|
|
92
94
|
exports.getValidationSuggestionAcceptApiPath = getValidationSuggestionAcceptApiPath;
|
|
@@ -518,6 +520,12 @@ function getFunctionTriggerPauseApiPath(workspaceId, triggerId) {
|
|
|
518
520
|
function getFunctionTriggerResumeApiPath(workspaceId, triggerId) {
|
|
519
521
|
return `data/workspace/${workspaceId}/api/v1/function-triggers/${triggerId}/resume`;
|
|
520
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Generate Endpoint trigger invocation API URL PATH.
|
|
525
|
+
*/
|
|
526
|
+
function getEndpointApiPath(workspaceId, path) {
|
|
527
|
+
return `data/workspace/${workspaceId}/api/v1/endpoints/${path}`;
|
|
528
|
+
}
|
|
521
529
|
/**
|
|
522
530
|
* Generate Smart Queries base API URL PATH for workspace-level operations.
|
|
523
531
|
*/
|
|
@@ -681,6 +689,15 @@ function getFunctionRunsByFunctionApiPath(workspaceId, functionId) {
|
|
|
681
689
|
return `data/workspace/${workspaceId}/api/v1/function-runs/function/${functionId}`;
|
|
682
690
|
}
|
|
683
691
|
// =====================================================
|
|
692
|
+
// Compute Job Status API Path Helper
|
|
693
|
+
// =====================================================
|
|
694
|
+
/**
|
|
695
|
+
* Generate Compute Job Status API URL PATH.
|
|
696
|
+
*/
|
|
697
|
+
function getComputeJobStatusApiPath(workspaceId, jobId) {
|
|
698
|
+
return `data/workspace/${workspaceId}/api/v1/jobs/compute/${jobId}`;
|
|
699
|
+
}
|
|
700
|
+
// =====================================================
|
|
684
701
|
// Smart Query Test API Path Helper (Configuration-as-Code)
|
|
685
702
|
// =====================================================
|
|
686
703
|
/**
|
|
@@ -1331,6 +1348,45 @@ class TriggersManager {
|
|
|
1331
1348
|
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
1332
1349
|
return this.requestFn('GET', path, null, options);
|
|
1333
1350
|
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Invoke a synchronous compute endpoint by its path.
|
|
1353
|
+
*
|
|
1354
|
+
* Unlike `invoke()` (which is async and returns a job ID), endpoint triggers
|
|
1355
|
+
* execute the function and return the result inline. Max 30 second timeout.
|
|
1356
|
+
*
|
|
1357
|
+
* @param endpointPath - The endpoint path (e.g., 'create-order')
|
|
1358
|
+
* @param options - Optional method, payload, headers, query params
|
|
1359
|
+
* @returns The function's response (status, data, headers)
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* ```ts
|
|
1363
|
+
* // POST to an endpoint
|
|
1364
|
+
* const result = await client.triggers.invokeEndpoint('create-order', {
|
|
1365
|
+
* payload: { product: 'Widget', quantity: 5 }
|
|
1366
|
+
* });
|
|
1367
|
+
* console.log('Status:', result.data.status);
|
|
1368
|
+
* console.log('Response:', result.data.data);
|
|
1369
|
+
*
|
|
1370
|
+
* // GET with query params
|
|
1371
|
+
* const users = await client.triggers.invokeEndpoint('list-users', {
|
|
1372
|
+
* method: 'GET',
|
|
1373
|
+
* query: { role: 'admin' }
|
|
1374
|
+
* });
|
|
1375
|
+
*
|
|
1376
|
+
* // With API key auth
|
|
1377
|
+
* const result = await client.triggers.invokeEndpoint('webhook/stripe', {
|
|
1378
|
+
* payload: stripeEvent,
|
|
1379
|
+
* headers: { 'X-API-Key': 'your-api-key' }
|
|
1380
|
+
* });
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
invokeEndpoint(endpointPath, options) {
|
|
1384
|
+
const path = getEndpointApiPath(this.workspaceId, endpointPath);
|
|
1385
|
+
const method = ((options === null || options === void 0 ? void 0 : options.method) || 'POST');
|
|
1386
|
+
const data = ['GET', 'DELETE'].includes(method) ? undefined : ((options === null || options === void 0 ? void 0 : options.payload) || {});
|
|
1387
|
+
const queryParams = options === null || options === void 0 ? void 0 : options.query;
|
|
1388
|
+
return this.requestFn(method, path, data, queryParams);
|
|
1389
|
+
}
|
|
1334
1390
|
}
|
|
1335
1391
|
exports.TriggersManager = TriggersManager;
|
|
1336
1392
|
// =====================================================
|
|
@@ -2619,6 +2675,38 @@ class FunctionRunsManager {
|
|
|
2619
2675
|
queryParams.status = options.status;
|
|
2620
2676
|
return this.requestFn('GET', path, null, queryParams);
|
|
2621
2677
|
}
|
|
2678
|
+
/**
|
|
2679
|
+
* Get the status of a compute job by job ID.
|
|
2680
|
+
*
|
|
2681
|
+
* This is the primary way to poll for the result of an async trigger
|
|
2682
|
+
* invocation. The job ID is returned by `client.triggers.invoke()`.
|
|
2683
|
+
*
|
|
2684
|
+
* @param jobId - The job ID returned by invoke
|
|
2685
|
+
* @returns Job status including returnValue (on success) or failedReason (on failure)
|
|
2686
|
+
*
|
|
2687
|
+
* @example
|
|
2688
|
+
* ```ts
|
|
2689
|
+
* // Invoke a trigger and poll for the result
|
|
2690
|
+
* const { data: jobId } = await client.triggers.invoke('trigger-uuid');
|
|
2691
|
+
*
|
|
2692
|
+
* // Poll until complete
|
|
2693
|
+
* let job;
|
|
2694
|
+
* do {
|
|
2695
|
+
* await new Promise(r => setTimeout(r, 1000));
|
|
2696
|
+
* job = await client.runs.getJobStatus(jobId);
|
|
2697
|
+
* } while (job.data.status === 'queued' || job.data.status === 'running');
|
|
2698
|
+
*
|
|
2699
|
+
* if (job.data.status === 'completed') {
|
|
2700
|
+
* console.log('Result:', job.data.returnValue);
|
|
2701
|
+
* } else {
|
|
2702
|
+
* console.error('Failed:', job.data.failedReason);
|
|
2703
|
+
* }
|
|
2704
|
+
* ```
|
|
2705
|
+
*/
|
|
2706
|
+
getJobStatus(jobId) {
|
|
2707
|
+
const path = getComputeJobStatusApiPath(this.workspaceId, jobId);
|
|
2708
|
+
return this.requestFn('GET', path);
|
|
2709
|
+
}
|
|
2622
2710
|
}
|
|
2623
2711
|
exports.FunctionRunsManager = FunctionRunsManager;
|
|
2624
2712
|
/**
|
package/index.ts
CHANGED
|
@@ -694,6 +694,32 @@ export interface InvokeTriggerOptions {
|
|
|
694
694
|
payload?: Record<string, any>;
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Options for invoking a synchronous compute endpoint.
|
|
699
|
+
*/
|
|
700
|
+
export interface InvokeEndpointOptions {
|
|
701
|
+
/** HTTP method (default: 'POST'). Must be in the trigger's allowedMethods. */
|
|
702
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
703
|
+
/** Request body payload (sent as JSON). Ignored for GET/DELETE. */
|
|
704
|
+
payload?: Record<string, any>;
|
|
705
|
+
/** Additional request headers (e.g., X-API-Key for apiKey auth). */
|
|
706
|
+
headers?: Record<string, string>;
|
|
707
|
+
/** Query string parameters. */
|
|
708
|
+
query?: Record<string, string>;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Response from a synchronous compute endpoint invocation.
|
|
713
|
+
*/
|
|
714
|
+
export interface EndpointResponse<T = any> {
|
|
715
|
+
/** HTTP status code from the compute function */
|
|
716
|
+
status: number;
|
|
717
|
+
/** Response body from the compute function */
|
|
718
|
+
data: T;
|
|
719
|
+
/** Response headers */
|
|
720
|
+
headers: Record<string, string>;
|
|
721
|
+
}
|
|
722
|
+
|
|
697
723
|
/**
|
|
698
724
|
* Options for deleting a record.
|
|
699
725
|
*/
|
|
@@ -1840,6 +1866,22 @@ export interface ListFunctionRunsOptions {
|
|
|
1840
1866
|
status?: FunctionRunStatus;
|
|
1841
1867
|
}
|
|
1842
1868
|
|
|
1869
|
+
/**
|
|
1870
|
+
* Status of a compute job in the execution pipeline.
|
|
1871
|
+
*/
|
|
1872
|
+
export type ComputeJobStatus = 'queued' | 'running' | 'completed' | 'failed';
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* A compute job status response from the job status endpoint.
|
|
1876
|
+
* Represents the state of an async compute execution.
|
|
1877
|
+
*/
|
|
1878
|
+
export interface ComputeJobStatusResponse {
|
|
1879
|
+
jobId: string;
|
|
1880
|
+
status: ComputeJobStatus;
|
|
1881
|
+
returnValue?: any;
|
|
1882
|
+
failedReason?: string | null;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1843
1885
|
// =====================================================
|
|
1844
1886
|
// Trigger CRUD Types (Configuration-as-Code)
|
|
1845
1887
|
// =====================================================
|
|
@@ -2630,6 +2672,13 @@ export function getFunctionTriggerResumeApiPath(workspaceId: string, triggerId:
|
|
|
2630
2672
|
return `data/workspace/${workspaceId}/api/v1/function-triggers/${triggerId}/resume`;
|
|
2631
2673
|
}
|
|
2632
2674
|
|
|
2675
|
+
/**
|
|
2676
|
+
* Generate Endpoint trigger invocation API URL PATH.
|
|
2677
|
+
*/
|
|
2678
|
+
export function getEndpointApiPath(workspaceId: string, path: string): string {
|
|
2679
|
+
return `data/workspace/${workspaceId}/api/v1/endpoints/${path}`;
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2633
2682
|
/**
|
|
2634
2683
|
* Generate Smart Queries base API URL PATH for workspace-level operations.
|
|
2635
2684
|
*/
|
|
@@ -2820,6 +2869,17 @@ export function getFunctionRunsByFunctionApiPath(workspaceId: string, functionId
|
|
|
2820
2869
|
return `data/workspace/${workspaceId}/api/v1/function-runs/function/${functionId}`;
|
|
2821
2870
|
}
|
|
2822
2871
|
|
|
2872
|
+
// =====================================================
|
|
2873
|
+
// Compute Job Status API Path Helper
|
|
2874
|
+
// =====================================================
|
|
2875
|
+
|
|
2876
|
+
/**
|
|
2877
|
+
* Generate Compute Job Status API URL PATH.
|
|
2878
|
+
*/
|
|
2879
|
+
export function getComputeJobStatusApiPath(workspaceId: string, jobId: string): string {
|
|
2880
|
+
return `data/workspace/${workspaceId}/api/v1/jobs/compute/${jobId}`;
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2823
2883
|
// =====================================================
|
|
2824
2884
|
// Smart Query Test API Path Helper (Configuration-as-Code)
|
|
2825
2885
|
// =====================================================
|
|
@@ -3527,6 +3587,49 @@ export class TriggersManager {
|
|
|
3527
3587
|
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
3528
3588
|
return this.requestFn<FunctionTrigger | TriggerWithHealth>('GET', path, null, options);
|
|
3529
3589
|
}
|
|
3590
|
+
|
|
3591
|
+
/**
|
|
3592
|
+
* Invoke a synchronous compute endpoint by its path.
|
|
3593
|
+
*
|
|
3594
|
+
* Unlike `invoke()` (which is async and returns a job ID), endpoint triggers
|
|
3595
|
+
* execute the function and return the result inline. Max 30 second timeout.
|
|
3596
|
+
*
|
|
3597
|
+
* @param endpointPath - The endpoint path (e.g., 'create-order')
|
|
3598
|
+
* @param options - Optional method, payload, headers, query params
|
|
3599
|
+
* @returns The function's response (status, data, headers)
|
|
3600
|
+
*
|
|
3601
|
+
* @example
|
|
3602
|
+
* ```ts
|
|
3603
|
+
* // POST to an endpoint
|
|
3604
|
+
* const result = await client.triggers.invokeEndpoint('create-order', {
|
|
3605
|
+
* payload: { product: 'Widget', quantity: 5 }
|
|
3606
|
+
* });
|
|
3607
|
+
* console.log('Status:', result.data.status);
|
|
3608
|
+
* console.log('Response:', result.data.data);
|
|
3609
|
+
*
|
|
3610
|
+
* // GET with query params
|
|
3611
|
+
* const users = await client.triggers.invokeEndpoint('list-users', {
|
|
3612
|
+
* method: 'GET',
|
|
3613
|
+
* query: { role: 'admin' }
|
|
3614
|
+
* });
|
|
3615
|
+
*
|
|
3616
|
+
* // With API key auth
|
|
3617
|
+
* const result = await client.triggers.invokeEndpoint('webhook/stripe', {
|
|
3618
|
+
* payload: stripeEvent,
|
|
3619
|
+
* headers: { 'X-API-Key': 'your-api-key' }
|
|
3620
|
+
* });
|
|
3621
|
+
* ```
|
|
3622
|
+
*/
|
|
3623
|
+
public invokeEndpoint<T = any>(
|
|
3624
|
+
endpointPath: string,
|
|
3625
|
+
options?: InvokeEndpointOptions
|
|
3626
|
+
): Promise<ApiResponse<T>> {
|
|
3627
|
+
const path = getEndpointApiPath(this.workspaceId, endpointPath);
|
|
3628
|
+
const method = (options?.method || 'POST') as Method;
|
|
3629
|
+
const data = ['GET', 'DELETE'].includes(method) ? undefined : (options?.payload || {});
|
|
3630
|
+
const queryParams = options?.query;
|
|
3631
|
+
return this.requestFn<T>(method, path, data, queryParams);
|
|
3632
|
+
}
|
|
3530
3633
|
}
|
|
3531
3634
|
|
|
3532
3635
|
// =====================================================
|
|
@@ -4939,6 +5042,39 @@ export class FunctionRunsManager {
|
|
|
4939
5042
|
if (options?.status) queryParams.status = options.status;
|
|
4940
5043
|
return this.requestFn<PaginatedResponse<FunctionRun>>('GET', path, null, queryParams);
|
|
4941
5044
|
}
|
|
5045
|
+
|
|
5046
|
+
/**
|
|
5047
|
+
* Get the status of a compute job by job ID.
|
|
5048
|
+
*
|
|
5049
|
+
* This is the primary way to poll for the result of an async trigger
|
|
5050
|
+
* invocation. The job ID is returned by `client.triggers.invoke()`.
|
|
5051
|
+
*
|
|
5052
|
+
* @param jobId - The job ID returned by invoke
|
|
5053
|
+
* @returns Job status including returnValue (on success) or failedReason (on failure)
|
|
5054
|
+
*
|
|
5055
|
+
* @example
|
|
5056
|
+
* ```ts
|
|
5057
|
+
* // Invoke a trigger and poll for the result
|
|
5058
|
+
* const { data: jobId } = await client.triggers.invoke('trigger-uuid');
|
|
5059
|
+
*
|
|
5060
|
+
* // Poll until complete
|
|
5061
|
+
* let job;
|
|
5062
|
+
* do {
|
|
5063
|
+
* await new Promise(r => setTimeout(r, 1000));
|
|
5064
|
+
* job = await client.runs.getJobStatus(jobId);
|
|
5065
|
+
* } while (job.data.status === 'queued' || job.data.status === 'running');
|
|
5066
|
+
*
|
|
5067
|
+
* if (job.data.status === 'completed') {
|
|
5068
|
+
* console.log('Result:', job.data.returnValue);
|
|
5069
|
+
* } else {
|
|
5070
|
+
* console.error('Failed:', job.data.failedReason);
|
|
5071
|
+
* }
|
|
5072
|
+
* ```
|
|
5073
|
+
*/
|
|
5074
|
+
public getJobStatus(jobId: string): Promise<ApiResponse<ComputeJobStatusResponse>> {
|
|
5075
|
+
const path = getComputeJobStatusApiPath(this.workspaceId, jobId);
|
|
5076
|
+
return this.requestFn<ComputeJobStatusResponse>('GET', path);
|
|
5077
|
+
}
|
|
4942
5078
|
}
|
|
4943
5079
|
|
|
4944
5080
|
/**
|