@centrali-io/centrali-sdk 4.4.6 → 4.4.8
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 +134 -1
- package/index.ts +164 -1
- 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
|
// =====================================================
|
|
@@ -3325,7 +3371,7 @@ class CentraliSDK {
|
|
|
3325
3371
|
*
|
|
3326
3372
|
* @param file - The file to upload
|
|
3327
3373
|
* @param location - Target folder path (e.g., '/root/shared/images'). Defaults to '/root/shared' if not specified.
|
|
3328
|
-
*
|
|
3374
|
+
* /root/shared always exists. For custom subfolders, create them first with createFolder().
|
|
3329
3375
|
* @param isPublic - If true, the file will be publicly accessible without authentication. Defaults to false.
|
|
3330
3376
|
* @returns The file URL or render ID
|
|
3331
3377
|
*
|
|
@@ -3360,6 +3406,93 @@ class CentraliSDK {
|
|
|
3360
3406
|
});
|
|
3361
3407
|
});
|
|
3362
3408
|
}
|
|
3409
|
+
// ------------------ Folder API Methods ------------------
|
|
3410
|
+
/**
|
|
3411
|
+
* Create a folder in the storage service.
|
|
3412
|
+
* Use this to create subfolders under /root/shared (which always exists).
|
|
3413
|
+
*
|
|
3414
|
+
* @param name - The folder name (e.g., 'logos', 'avatars')
|
|
3415
|
+
* @param location - Parent folder path (e.g., '/root/shared'). Defaults to '/root/shared'.
|
|
3416
|
+
* @returns The created folder object
|
|
3417
|
+
*
|
|
3418
|
+
* @example
|
|
3419
|
+
* ```ts
|
|
3420
|
+
* // Create a folder under /root/shared
|
|
3421
|
+
* const folder = await client.createFolder('logos', '/root/shared');
|
|
3422
|
+
* // Result: folder at /root/shared/logos
|
|
3423
|
+
*
|
|
3424
|
+
* // Then upload to it
|
|
3425
|
+
* const { data: renderId } = await client.uploadFile(file, '/root/shared/logos', true);
|
|
3426
|
+
* ```
|
|
3427
|
+
*/
|
|
3428
|
+
createFolder(name_1) {
|
|
3429
|
+
return __awaiter(this, arguments, void 0, function* (name, location = '/root/shared') {
|
|
3430
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders`;
|
|
3431
|
+
return this.request('POST', path, { name, location });
|
|
3432
|
+
});
|
|
3433
|
+
}
|
|
3434
|
+
/**
|
|
3435
|
+
* List folders in the workspace, optionally filtered by parent location.
|
|
3436
|
+
*
|
|
3437
|
+
* @param location - Parent folder path to list contents of (e.g., '/root/shared'). If omitted, lists top-level folders.
|
|
3438
|
+
* @returns Array of folder objects
|
|
3439
|
+
*
|
|
3440
|
+
* @example
|
|
3441
|
+
* ```ts
|
|
3442
|
+
* // List all folders under /root/shared
|
|
3443
|
+
* const folders = await client.listFolders('/root/shared');
|
|
3444
|
+
*
|
|
3445
|
+
* // Check if a folder exists before uploading
|
|
3446
|
+
* const folders = await client.listFolders('/root/shared');
|
|
3447
|
+
* const hasLogos = folders.data.some(f => f.name === 'logos');
|
|
3448
|
+
* if (!hasLogos) {
|
|
3449
|
+
* await client.createFolder('logos', '/root/shared');
|
|
3450
|
+
* }
|
|
3451
|
+
* ```
|
|
3452
|
+
*/
|
|
3453
|
+
listFolders(location) {
|
|
3454
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3455
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders`;
|
|
3456
|
+
const params = location ? { location } : undefined;
|
|
3457
|
+
return this.request('GET', path, null, params);
|
|
3458
|
+
});
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* Get a specific folder by ID.
|
|
3462
|
+
*
|
|
3463
|
+
* @param folderId - The folder ID (UUID)
|
|
3464
|
+
* @returns The folder object
|
|
3465
|
+
*/
|
|
3466
|
+
getFolder(folderId) {
|
|
3467
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3468
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}`;
|
|
3469
|
+
return this.request('GET', path);
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
/**
|
|
3473
|
+
* List sub-folders within a specific folder.
|
|
3474
|
+
*
|
|
3475
|
+
* @param folderId - The parent folder ID (UUID)
|
|
3476
|
+
* @returns Array of sub-folder objects
|
|
3477
|
+
*/
|
|
3478
|
+
listSubFolders(folderId) {
|
|
3479
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3480
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}/sub-folders`;
|
|
3481
|
+
return this.request('GET', path);
|
|
3482
|
+
});
|
|
3483
|
+
}
|
|
3484
|
+
/**
|
|
3485
|
+
* Delete a folder by ID. System folders (/root, /root/shared, /root/users) cannot be deleted.
|
|
3486
|
+
*
|
|
3487
|
+
* @param folderId - The folder ID (UUID) to delete
|
|
3488
|
+
*/
|
|
3489
|
+
deleteFolder(folderId) {
|
|
3490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3491
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}`;
|
|
3492
|
+
return this.request('DELETE', path);
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
// ------------------ File Render/Download URL Methods ------------------
|
|
3363
3496
|
/**
|
|
3364
3497
|
* Get the render URL for a file. Use this URL to display files inline (e.g., images in img tags).
|
|
3365
3498
|
* Supports optional image transformation parameters.
|
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
|
// =====================================================
|
|
@@ -5810,7 +5886,7 @@ export class CentraliSDK {
|
|
|
5810
5886
|
*
|
|
5811
5887
|
* @param file - The file to upload
|
|
5812
5888
|
* @param location - Target folder path (e.g., '/root/shared/images'). Defaults to '/root/shared' if not specified.
|
|
5813
|
-
*
|
|
5889
|
+
* /root/shared always exists. For custom subfolders, create them first with createFolder().
|
|
5814
5890
|
* @param isPublic - If true, the file will be publicly accessible without authentication. Defaults to false.
|
|
5815
5891
|
* @returns The file URL or render ID
|
|
5816
5892
|
*
|
|
@@ -5851,6 +5927,93 @@ export class CentraliSDK {
|
|
|
5851
5927
|
});
|
|
5852
5928
|
}
|
|
5853
5929
|
|
|
5930
|
+
// ------------------ Folder API Methods ------------------
|
|
5931
|
+
|
|
5932
|
+
/**
|
|
5933
|
+
* Create a folder in the storage service.
|
|
5934
|
+
* Use this to create subfolders under /root/shared (which always exists).
|
|
5935
|
+
*
|
|
5936
|
+
* @param name - The folder name (e.g., 'logos', 'avatars')
|
|
5937
|
+
* @param location - Parent folder path (e.g., '/root/shared'). Defaults to '/root/shared'.
|
|
5938
|
+
* @returns The created folder object
|
|
5939
|
+
*
|
|
5940
|
+
* @example
|
|
5941
|
+
* ```ts
|
|
5942
|
+
* // Create a folder under /root/shared
|
|
5943
|
+
* const folder = await client.createFolder('logos', '/root/shared');
|
|
5944
|
+
* // Result: folder at /root/shared/logos
|
|
5945
|
+
*
|
|
5946
|
+
* // Then upload to it
|
|
5947
|
+
* const { data: renderId } = await client.uploadFile(file, '/root/shared/logos', true);
|
|
5948
|
+
* ```
|
|
5949
|
+
*/
|
|
5950
|
+
public async createFolder(
|
|
5951
|
+
name: string,
|
|
5952
|
+
location: string = '/root/shared'
|
|
5953
|
+
): Promise<ApiResponse<any>> {
|
|
5954
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders`;
|
|
5955
|
+
return this.request<any>('POST', path, { name, location });
|
|
5956
|
+
}
|
|
5957
|
+
|
|
5958
|
+
/**
|
|
5959
|
+
* List folders in the workspace, optionally filtered by parent location.
|
|
5960
|
+
*
|
|
5961
|
+
* @param location - Parent folder path to list contents of (e.g., '/root/shared'). If omitted, lists top-level folders.
|
|
5962
|
+
* @returns Array of folder objects
|
|
5963
|
+
*
|
|
5964
|
+
* @example
|
|
5965
|
+
* ```ts
|
|
5966
|
+
* // List all folders under /root/shared
|
|
5967
|
+
* const folders = await client.listFolders('/root/shared');
|
|
5968
|
+
*
|
|
5969
|
+
* // Check if a folder exists before uploading
|
|
5970
|
+
* const folders = await client.listFolders('/root/shared');
|
|
5971
|
+
* const hasLogos = folders.data.some(f => f.name === 'logos');
|
|
5972
|
+
* if (!hasLogos) {
|
|
5973
|
+
* await client.createFolder('logos', '/root/shared');
|
|
5974
|
+
* }
|
|
5975
|
+
* ```
|
|
5976
|
+
*/
|
|
5977
|
+
public async listFolders(location?: string): Promise<ApiResponse<any[]>> {
|
|
5978
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders`;
|
|
5979
|
+
const params = location ? { location } : undefined;
|
|
5980
|
+
return this.request<any[]>('GET', path, null, params);
|
|
5981
|
+
}
|
|
5982
|
+
|
|
5983
|
+
/**
|
|
5984
|
+
* Get a specific folder by ID.
|
|
5985
|
+
*
|
|
5986
|
+
* @param folderId - The folder ID (UUID)
|
|
5987
|
+
* @returns The folder object
|
|
5988
|
+
*/
|
|
5989
|
+
public async getFolder(folderId: string): Promise<ApiResponse<any>> {
|
|
5990
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}`;
|
|
5991
|
+
return this.request<any>('GET', path);
|
|
5992
|
+
}
|
|
5993
|
+
|
|
5994
|
+
/**
|
|
5995
|
+
* List sub-folders within a specific folder.
|
|
5996
|
+
*
|
|
5997
|
+
* @param folderId - The parent folder ID (UUID)
|
|
5998
|
+
* @returns Array of sub-folder objects
|
|
5999
|
+
*/
|
|
6000
|
+
public async listSubFolders(folderId: string): Promise<ApiResponse<any[]>> {
|
|
6001
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}/sub-folders`;
|
|
6002
|
+
return this.request<any[]>('GET', path);
|
|
6003
|
+
}
|
|
6004
|
+
|
|
6005
|
+
/**
|
|
6006
|
+
* Delete a folder by ID. System folders (/root, /root/shared, /root/users) cannot be deleted.
|
|
6007
|
+
*
|
|
6008
|
+
* @param folderId - The folder ID (UUID) to delete
|
|
6009
|
+
*/
|
|
6010
|
+
public async deleteFolder(folderId: string): Promise<ApiResponse<void>> {
|
|
6011
|
+
const path = `storage/ws/${this.options.workspaceId}/api/v1/folders/${folderId}`;
|
|
6012
|
+
return this.request<void>('DELETE', path);
|
|
6013
|
+
}
|
|
6014
|
+
|
|
6015
|
+
// ------------------ File Render/Download URL Methods ------------------
|
|
6016
|
+
|
|
5854
6017
|
/**
|
|
5855
6018
|
* Get the render URL for a file. Use this URL to display files inline (e.g., images in img tags).
|
|
5856
6019
|
* Supports optional image transformation parameters.
|