@centrali-io/centrali-sdk 4.4.6 → 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 +46 -0
- package/index.ts +76 -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;
|
|
@@ -519,6 +520,12 @@ function getFunctionTriggerPauseApiPath(workspaceId, triggerId) {
|
|
|
519
520
|
function getFunctionTriggerResumeApiPath(workspaceId, triggerId) {
|
|
520
521
|
return `data/workspace/${workspaceId}/api/v1/function-triggers/${triggerId}/resume`;
|
|
521
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
|
+
}
|
|
522
529
|
/**
|
|
523
530
|
* Generate Smart Queries base API URL PATH for workspace-level operations.
|
|
524
531
|
*/
|
|
@@ -1341,6 +1348,45 @@ class TriggersManager {
|
|
|
1341
1348
|
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
1342
1349
|
return this.requestFn('GET', path, null, options);
|
|
1343
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
|
+
}
|
|
1344
1390
|
}
|
|
1345
1391
|
exports.TriggersManager = TriggersManager;
|
|
1346
1392
|
// =====================================================
|
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
|
*/
|
|
@@ -2646,6 +2672,13 @@ export function getFunctionTriggerResumeApiPath(workspaceId: string, triggerId:
|
|
|
2646
2672
|
return `data/workspace/${workspaceId}/api/v1/function-triggers/${triggerId}/resume`;
|
|
2647
2673
|
}
|
|
2648
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
|
+
|
|
2649
2682
|
/**
|
|
2650
2683
|
* Generate Smart Queries base API URL PATH for workspace-level operations.
|
|
2651
2684
|
*/
|
|
@@ -3554,6 +3587,49 @@ export class TriggersManager {
|
|
|
3554
3587
|
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
3555
3588
|
return this.requestFn<FunctionTrigger | TriggerWithHealth>('GET', path, null, options);
|
|
3556
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
|
+
}
|
|
3557
3633
|
}
|
|
3558
3634
|
|
|
3559
3635
|
// =====================================================
|