@centrali-io/centrali-sdk 5.5.0 → 6.0.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/README.md +164 -14
- package/dist/index.d.ts +1807 -878
- package/dist/index.js +9153 -4076
- package/index.ts +61 -7152
- package/package.json +10 -3
- package/query-types.ts +83 -2
- package/scripts/smoke-types.ts +145 -5
- package/src/client.ts +1507 -0
- package/src/internal/auth.ts +35 -0
- package/src/internal/deprecation.ts +11 -0
- package/src/internal/error.ts +90 -0
- package/src/internal/paths.ts +456 -0
- package/src/internal/queryGuard.ts +21 -0
- package/src/managers/allowedDomains.ts +90 -0
- package/src/managers/anomalyInsights.ts +215 -0
- package/src/managers/auditLog.ts +105 -0
- package/src/managers/collections.ts +197 -0
- package/src/managers/files.ts +182 -0
- package/src/managers/functionRuns.ts +229 -0
- package/src/managers/functions.ts +171 -0
- package/src/managers/orchestrationRuns.ts +122 -0
- package/src/managers/orchestrations.ts +297 -0
- package/src/managers/query.ts +199 -0
- package/src/managers/records.ts +186 -0
- package/src/managers/smartQueries.ts +374 -0
- package/src/managers/structures.ts +205 -0
- package/src/managers/triggers.ts +349 -0
- package/src/managers/validation.ts +303 -0
- package/src/managers/webhookSubscriptions.ts +206 -0
- package/src/realtime/manager.ts +292 -0
- package/src/types/allowedDomains.ts +29 -0
- package/src/types/auth.ts +83 -0
- package/src/types/common.ts +57 -0
- package/src/types/compute.ts +145 -0
- package/src/types/insights.ts +113 -0
- package/src/types/orchestrations.ts +460 -0
- package/src/types/realtime.ts +403 -0
- package/src/types/records.ts +261 -0
- package/src/types/search.ts +44 -0
- package/src/types/smartQueries.ts +303 -0
- package/src/types/structures.ts +203 -0
- package/src/types/triggers.ts +122 -0
- package/src/types/validation.ts +167 -0
- package/src/types/webhooks.ts +114 -0
- package/src/urls.ts +33 -0
- package/dist/query-types.d.ts +0 -187
- package/dist/query-types.js +0 -137
- package/dist/scripts/smoke-types.d.ts +0 -12
- package/dist/scripts/smoke-types.js +0 -102
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// =====================================================
|
|
2
|
+
// Structures Manager (Configuration-as-Code)
|
|
3
|
+
// =====================================================
|
|
4
|
+
|
|
5
|
+
import type { Method } from 'axios';
|
|
6
|
+
import type { ApiResponse } from '../types/common';
|
|
7
|
+
import type {
|
|
8
|
+
Structure,
|
|
9
|
+
CreateStructureInput,
|
|
10
|
+
UpdateStructureInput,
|
|
11
|
+
ListStructuresOptions,
|
|
12
|
+
ValidateStructureInput,
|
|
13
|
+
} from '../types/structures';
|
|
14
|
+
import {
|
|
15
|
+
getStructuresApiPath,
|
|
16
|
+
getStructureBySlugApiPath,
|
|
17
|
+
getStructureValidateApiPath,
|
|
18
|
+
} from '../internal/paths';
|
|
19
|
+
import { emitDeprecationWarning } from '../internal/deprecation';
|
|
20
|
+
|
|
21
|
+
// =====================================================
|
|
22
|
+
// Structures Manager (Configuration-as-Code)
|
|
23
|
+
// =====================================================
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* StructuresManager provides methods for managing data structures (schemas).
|
|
27
|
+
* Structures define the shape of records including properties, validation rules,
|
|
28
|
+
* and schema discovery modes.
|
|
29
|
+
* Access via `client.structures`.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ```ts
|
|
33
|
+
* // List all structures
|
|
34
|
+
* const structures = await client.structures.list();
|
|
35
|
+
*
|
|
36
|
+
* // Create a new structure
|
|
37
|
+
* const structure = await client.structures.create({
|
|
38
|
+
* name: 'Orders',
|
|
39
|
+
* slug: 'orders',
|
|
40
|
+
* properties: [
|
|
41
|
+
* { name: 'title', type: 'string', required: true },
|
|
42
|
+
* { name: 'amount', type: 'number', minimum: 0 }
|
|
43
|
+
* ]
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Validate before creating
|
|
47
|
+
* const validation = await client.structures.validate({ slug: 'orders' });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export class StructuresManager {
|
|
51
|
+
private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
|
|
52
|
+
private workspaceId: string;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
workspaceId: string,
|
|
56
|
+
requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
|
|
57
|
+
) {
|
|
58
|
+
this.workspaceId = workspaceId;
|
|
59
|
+
this.requestFn = requestFn;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* List all structures in the workspace.
|
|
64
|
+
*
|
|
65
|
+
* @param options - Optional list parameters (pagination)
|
|
66
|
+
* @returns List of structures
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const structures = await client.structures.list();
|
|
71
|
+
* const page2 = await client.structures.list({ page: 2, limit: 10 });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
public list(options?: ListStructuresOptions): Promise<ApiResponse<Structure[]>> {
|
|
75
|
+
emitDeprecationWarning('client.structures.list() is deprecated. Use client.collections.list() instead.');
|
|
76
|
+
const path = getStructuresApiPath(this.workspaceId);
|
|
77
|
+
return this.requestFn<Structure[]>('GET', path, null, options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get a structure by ID.
|
|
82
|
+
*
|
|
83
|
+
* @param structureId - The structure UUID
|
|
84
|
+
* @returns The structure details
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const structure = await client.structures.get('structure-uuid');
|
|
89
|
+
* console.log('Properties:', structure.data.properties.length);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
public get(structureId: string): Promise<ApiResponse<Structure>> {
|
|
93
|
+
emitDeprecationWarning('client.structures.get() is deprecated. Use client.collections.get() instead.');
|
|
94
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
95
|
+
return this.requestFn<Structure>('GET', path);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get a structure by its record slug.
|
|
100
|
+
*
|
|
101
|
+
* @param recordSlug - The structure's record slug (e.g., "orders")
|
|
102
|
+
* @returns The structure details
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const structure = await client.structures.getBySlug('orders');
|
|
107
|
+
* console.log('Structure name:', structure.data.name);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
public getBySlug(recordSlug: string): Promise<ApiResponse<Structure>> {
|
|
111
|
+
emitDeprecationWarning('client.structures.getBySlug() is deprecated. Use client.collections.getBySlug() instead.');
|
|
112
|
+
const path = getStructureBySlugApiPath(this.workspaceId, recordSlug);
|
|
113
|
+
return this.requestFn<Structure>('GET', path);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create a new structure.
|
|
118
|
+
*
|
|
119
|
+
* @param input - The structure definition
|
|
120
|
+
* @returns The created structure
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const structure = await client.structures.create({
|
|
125
|
+
* name: 'Orders',
|
|
126
|
+
* slug: 'orders',
|
|
127
|
+
* description: 'Customer orders',
|
|
128
|
+
* properties: [
|
|
129
|
+
* { name: 'title', type: 'string', required: true },
|
|
130
|
+
* { name: 'amount', type: 'number', minimum: 0 },
|
|
131
|
+
* { name: 'status', type: 'string', enum: ['pending', 'completed'] }
|
|
132
|
+
* ],
|
|
133
|
+
* enableVersioning: true,
|
|
134
|
+
* schemaDiscoveryMode: 'strict'
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
public create(input: CreateStructureInput): Promise<ApiResponse<Structure>> {
|
|
139
|
+
emitDeprecationWarning('client.structures.create() is deprecated. Use client.collections.create() instead.');
|
|
140
|
+
const path = getStructuresApiPath(this.workspaceId);
|
|
141
|
+
return this.requestFn<Structure>('POST', path, input);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Update an existing structure.
|
|
146
|
+
*
|
|
147
|
+
* @param structureId - The structure UUID
|
|
148
|
+
* @param input - The fields to update
|
|
149
|
+
* @returns The updated structure
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const updated = await client.structures.update('structure-uuid', {
|
|
154
|
+
* name: 'Updated Orders',
|
|
155
|
+
* properties: [
|
|
156
|
+
* { name: 'title', type: 'string', required: true },
|
|
157
|
+
* { name: 'amount', type: 'number', minimum: 0 },
|
|
158
|
+
* { name: 'priority', type: 'number' }
|
|
159
|
+
* ]
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
public update(structureId: string, input: UpdateStructureInput): Promise<ApiResponse<Structure>> {
|
|
164
|
+
emitDeprecationWarning('client.structures.update() is deprecated. Use client.collections.update() instead.');
|
|
165
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
166
|
+
return this.requestFn<Structure>('PUT', path, input);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Delete a structure.
|
|
171
|
+
*
|
|
172
|
+
* @param structureId - The structure UUID
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* await client.structures.delete('structure-uuid');
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
public delete(structureId: string): Promise<ApiResponse<void>> {
|
|
180
|
+
emitDeprecationWarning('client.structures.delete() is deprecated. Use client.collections.delete() instead.');
|
|
181
|
+
const path = getStructuresApiPath(this.workspaceId, structureId);
|
|
182
|
+
return this.requestFn<void>('DELETE', path);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Validate a structure definition without creating it.
|
|
187
|
+
* Useful for checking slug uniqueness and property validity before creation.
|
|
188
|
+
*
|
|
189
|
+
* @param input - The structure definition to validate
|
|
190
|
+
* @returns Validation result
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const result = await client.structures.validate({
|
|
195
|
+
* slug: 'orders',
|
|
196
|
+
* properties: [{ name: 'title', type: 'string' }]
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
public validate(input: ValidateStructureInput): Promise<ApiResponse<any>> {
|
|
201
|
+
emitDeprecationWarning('client.structures.validate() is deprecated. Use client.collections.validate() instead.');
|
|
202
|
+
const path = getStructureValidateApiPath(this.workspaceId);
|
|
203
|
+
return this.requestFn<any>('POST', path, input);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// =====================================================
|
|
2
|
+
// Triggers Manager
|
|
3
|
+
// =====================================================
|
|
4
|
+
|
|
5
|
+
import type { Method } from 'axios';
|
|
6
|
+
import type { ApiResponse } from '../types/common';
|
|
7
|
+
import type {
|
|
8
|
+
FunctionTrigger,
|
|
9
|
+
InvokeTriggerOptions,
|
|
10
|
+
InvokeEndpointOptions,
|
|
11
|
+
CreateTriggerInput,
|
|
12
|
+
UpdateTriggerInput,
|
|
13
|
+
ListAllTriggersOptions,
|
|
14
|
+
TriggerWithHealth,
|
|
15
|
+
} from '../types/triggers';
|
|
16
|
+
import type { TriggerInvokeResponse } from '../types/records';
|
|
17
|
+
import {
|
|
18
|
+
getFunctionTriggerExecuteApiPath,
|
|
19
|
+
getFunctionTriggersApiPath,
|
|
20
|
+
getFunctionTriggerPauseApiPath,
|
|
21
|
+
getFunctionTriggerResumeApiPath,
|
|
22
|
+
getEndpointApiPath,
|
|
23
|
+
} from '../internal/paths';
|
|
24
|
+
|
|
25
|
+
// =====================================================
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* TriggersManager provides methods for working with on-demand function triggers.
|
|
29
|
+
* Access via `client.triggers`.
|
|
30
|
+
*
|
|
31
|
+
* Note: This manager only works with on-demand triggers. Scheduled, event-driven,
|
|
32
|
+
* and webhook triggers are managed through other mechanisms.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Invoke an on-demand trigger
|
|
37
|
+
* const result = await client.triggers.invoke('trigger-id');
|
|
38
|
+
*
|
|
39
|
+
* // Invoke with custom payload
|
|
40
|
+
* const result = await client.triggers.invoke('trigger-id', {
|
|
41
|
+
* payload: { customData: 'value' }
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Get an on-demand trigger by ID
|
|
45
|
+
* const trigger = await client.triggers.get('trigger-id');
|
|
46
|
+
*
|
|
47
|
+
* // List all on-demand triggers
|
|
48
|
+
* const triggers = await client.triggers.list();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export class TriggersManager {
|
|
52
|
+
private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
|
|
53
|
+
private workspaceId: string;
|
|
54
|
+
|
|
55
|
+
constructor(
|
|
56
|
+
workspaceId: string,
|
|
57
|
+
requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
|
|
58
|
+
) {
|
|
59
|
+
this.workspaceId = workspaceId;
|
|
60
|
+
this.requestFn = requestFn;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Invoke an on-demand trigger by ID.
|
|
65
|
+
*
|
|
66
|
+
* @param triggerId - The ID of the trigger to invoke
|
|
67
|
+
* @param options - Optional invoke options including custom payload
|
|
68
|
+
* @returns The queued job ID for tracking the execution
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // Simple invocation
|
|
73
|
+
* const job = await client.triggers.invoke('trigger-id');
|
|
74
|
+
* console.log('Job queued:', job.data);
|
|
75
|
+
*
|
|
76
|
+
* // With custom payload
|
|
77
|
+
* const job = await client.triggers.invoke('trigger-id', {
|
|
78
|
+
* payload: { orderId: '12345', action: 'process' }
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
public invoke(
|
|
83
|
+
triggerId: string,
|
|
84
|
+
options?: InvokeTriggerOptions
|
|
85
|
+
): Promise<ApiResponse<TriggerInvokeResponse>> {
|
|
86
|
+
const path = getFunctionTriggerExecuteApiPath(this.workspaceId, triggerId);
|
|
87
|
+
const data = options?.payload ?? {};
|
|
88
|
+
return this.requestFn<TriggerInvokeResponse>('POST', path, data);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get an on-demand trigger by ID.
|
|
93
|
+
*
|
|
94
|
+
* Note: This method validates that the trigger is an on-demand trigger.
|
|
95
|
+
* If the trigger exists but is not on-demand, an error will be thrown.
|
|
96
|
+
*
|
|
97
|
+
* @param triggerId - The ID of the on-demand trigger to retrieve
|
|
98
|
+
* @returns The trigger details
|
|
99
|
+
* @throws Error if the trigger is not an on-demand trigger
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const trigger = await client.triggers.get('trigger-id');
|
|
104
|
+
* console.log('Trigger name:', trigger.data.name);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
public async get(triggerId: string): Promise<ApiResponse<FunctionTrigger>> {
|
|
108
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
109
|
+
const response = await this.requestFn<FunctionTrigger>('GET', path);
|
|
110
|
+
|
|
111
|
+
// Validate that the trigger is on-demand
|
|
112
|
+
if (response.data && response.data.executionType !== 'on-demand') {
|
|
113
|
+
throw new Error(`Trigger '${triggerId}' is not an on-demand trigger. Only on-demand triggers can be invoked via the SDK.`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* List all on-demand triggers in the workspace.
|
|
121
|
+
*
|
|
122
|
+
* This method automatically filters to only return triggers with executionType 'on-demand'.
|
|
123
|
+
*
|
|
124
|
+
* @param queryParams - Optional query parameters for pagination, search, etc.
|
|
125
|
+
* @returns List of on-demand triggers with pagination metadata
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* // List all on-demand triggers
|
|
130
|
+
* const triggers = await client.triggers.list();
|
|
131
|
+
*
|
|
132
|
+
* // With pagination
|
|
133
|
+
* const triggers = await client.triggers.list({ limit: 10, page: 1 });
|
|
134
|
+
*
|
|
135
|
+
* // With search
|
|
136
|
+
* const triggers = await client.triggers.list({ search: 'process-order' });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
public list(queryParams?: Record<string, any>): Promise<ApiResponse<FunctionTrigger[]>> {
|
|
140
|
+
const path = getFunctionTriggersApiPath(this.workspaceId);
|
|
141
|
+
// Always filter for on-demand triggers only
|
|
142
|
+
const params = {
|
|
143
|
+
...queryParams,
|
|
144
|
+
executionType: 'on-demand'
|
|
145
|
+
};
|
|
146
|
+
return this.requestFn<FunctionTrigger[]>('GET', path, null, params);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Pause a function trigger.
|
|
151
|
+
*
|
|
152
|
+
* Pauses an event-driven or scheduled trigger to temporarily disable it from firing.
|
|
153
|
+
* When paused, the trigger will not execute until resumed.
|
|
154
|
+
*
|
|
155
|
+
* For scheduled triggers, this also pauses the underlying scheduler job.
|
|
156
|
+
*
|
|
157
|
+
* @param triggerId - The ID of the trigger to pause
|
|
158
|
+
* @returns The updated trigger with enabled = false
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* // Pause a trigger
|
|
163
|
+
* const result = await client.triggers.pauseTrigger('trigger-id');
|
|
164
|
+
* console.log('Trigger paused:', result.data.enabled === false);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
public pauseTrigger(triggerId: string): Promise<ApiResponse<FunctionTrigger>> {
|
|
168
|
+
const path = getFunctionTriggerPauseApiPath(this.workspaceId, triggerId);
|
|
169
|
+
return this.requestFn<FunctionTrigger>('PATCH', path, {});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Resume a paused function trigger.
|
|
174
|
+
*
|
|
175
|
+
* Resumes a paused event-driven or scheduled trigger to re-enable it.
|
|
176
|
+
* Once resumed, the trigger will start firing again on matching events or schedules.
|
|
177
|
+
*
|
|
178
|
+
* For scheduled triggers, this also resumes the underlying scheduler job.
|
|
179
|
+
*
|
|
180
|
+
* @param triggerId - The ID of the trigger to resume
|
|
181
|
+
* @returns The updated trigger with enabled = true
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* // Resume a paused trigger
|
|
186
|
+
* const result = await client.triggers.resumeTrigger('trigger-id');
|
|
187
|
+
* console.log('Trigger resumed:', result.data.enabled === true);
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
public resumeTrigger(triggerId: string): Promise<ApiResponse<FunctionTrigger>> {
|
|
191
|
+
const path = getFunctionTriggerResumeApiPath(this.workspaceId, triggerId);
|
|
192
|
+
return this.requestFn<FunctionTrigger>('PATCH', path, {});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Create a new function trigger.
|
|
197
|
+
*
|
|
198
|
+
* @param input - The trigger definition
|
|
199
|
+
* @returns The created trigger
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* // Create an event-driven trigger
|
|
204
|
+
* const trigger = await client.triggers.create({
|
|
205
|
+
* name: 'On Order Created',
|
|
206
|
+
* functionId: 'function-uuid',
|
|
207
|
+
* executionType: 'event-driven',
|
|
208
|
+
* triggerMetadata: { event: 'record.created', recordSlug: 'orders' }
|
|
209
|
+
* });
|
|
210
|
+
*
|
|
211
|
+
* // Create a scheduled trigger
|
|
212
|
+
* const scheduled = await client.triggers.create({
|
|
213
|
+
* name: 'Daily Report',
|
|
214
|
+
* functionId: 'function-uuid',
|
|
215
|
+
* executionType: 'scheduled',
|
|
216
|
+
* triggerMetadata: { scheduleType: 'cron', cronExpression: '0 9 * * *', timezone: 'America/New_York' }
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
public create(input: CreateTriggerInput): Promise<ApiResponse<FunctionTrigger>> {
|
|
221
|
+
const path = getFunctionTriggersApiPath(this.workspaceId);
|
|
222
|
+
return this.requestFn<FunctionTrigger>('POST', path, input);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Update an existing function trigger.
|
|
227
|
+
*
|
|
228
|
+
* @param triggerId - The trigger UUID
|
|
229
|
+
* @param input - The fields to update
|
|
230
|
+
* @returns The updated trigger
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const updated = await client.triggers.update('trigger-uuid', {
|
|
235
|
+
* name: 'Updated Trigger Name',
|
|
236
|
+
* enabled: false
|
|
237
|
+
* });
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
public update(triggerId: string, input: UpdateTriggerInput): Promise<ApiResponse<FunctionTrigger>> {
|
|
241
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
242
|
+
return this.requestFn<FunctionTrigger>('PUT', path, input);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Delete a function trigger.
|
|
247
|
+
*
|
|
248
|
+
* @param triggerId - The trigger UUID
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* await client.triggers.delete('trigger-uuid');
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
public delete(triggerId: string): Promise<ApiResponse<void>> {
|
|
256
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
257
|
+
return this.requestFn<void>('DELETE', path);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* List all triggers in the workspace (not filtered by execution type).
|
|
262
|
+
* Unlike `list()` which only returns on-demand triggers, `listAll()` returns
|
|
263
|
+
* triggers of all types with optional filtering.
|
|
264
|
+
*
|
|
265
|
+
* @param options - Optional list parameters (pagination, filtering, health)
|
|
266
|
+
* @returns List of triggers
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* // List all triggers
|
|
271
|
+
* const all = await client.triggers.listAll();
|
|
272
|
+
*
|
|
273
|
+
* // Filter by execution type
|
|
274
|
+
* const scheduled = await client.triggers.listAll({ executionType: 'scheduled' });
|
|
275
|
+
*
|
|
276
|
+
* // Include health metrics
|
|
277
|
+
* const withHealth = await client.triggers.listAll({ includeHealth: true });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
public listAll(options?: ListAllTriggersOptions): Promise<ApiResponse<(FunctionTrigger | TriggerWithHealth)[]>> {
|
|
281
|
+
const path = getFunctionTriggersApiPath(this.workspaceId);
|
|
282
|
+
return this.requestFn<(FunctionTrigger | TriggerWithHealth)[]>('GET', path, null, options);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get a trigger by ID with full details (no on-demand type restriction).
|
|
287
|
+
* Unlike `get()` which validates on-demand type, `getDetails()` returns
|
|
288
|
+
* any trigger type.
|
|
289
|
+
*
|
|
290
|
+
* @param triggerId - The trigger UUID
|
|
291
|
+
* @param options - Optional parameters (includeHealth)
|
|
292
|
+
* @returns The trigger details
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const trigger = await client.triggers.getDetails('trigger-uuid');
|
|
297
|
+
*
|
|
298
|
+
* // With health metrics
|
|
299
|
+
* const withHealth = await client.triggers.getDetails('trigger-uuid', { includeHealth: true });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
public getDetails(triggerId: string, options?: { includeHealth?: boolean }): Promise<ApiResponse<FunctionTrigger | TriggerWithHealth>> {
|
|
303
|
+
const path = getFunctionTriggersApiPath(this.workspaceId, triggerId);
|
|
304
|
+
return this.requestFn<FunctionTrigger | TriggerWithHealth>('GET', path, null, options);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Invoke a synchronous compute endpoint by its path.
|
|
309
|
+
*
|
|
310
|
+
* Unlike `invoke()` (which is async and returns a job ID), endpoint triggers
|
|
311
|
+
* execute the function and return the result inline. Max 30 second timeout.
|
|
312
|
+
*
|
|
313
|
+
* @param endpointPath - The endpoint path (e.g., 'create-order')
|
|
314
|
+
* @param options - Optional method, payload, headers, query params
|
|
315
|
+
* @returns The function's response (status, data, headers)
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* // POST to an endpoint
|
|
320
|
+
* const result = await client.triggers.invokeEndpoint('create-order', {
|
|
321
|
+
* payload: { product: 'Widget', quantity: 5 }
|
|
322
|
+
* });
|
|
323
|
+
* console.log('Status:', result.data.status);
|
|
324
|
+
* console.log('Response:', result.data.data);
|
|
325
|
+
*
|
|
326
|
+
* // GET with query params
|
|
327
|
+
* const users = await client.triggers.invokeEndpoint('list-users', {
|
|
328
|
+
* method: 'GET',
|
|
329
|
+
* query: { role: 'admin' }
|
|
330
|
+
* });
|
|
331
|
+
*
|
|
332
|
+
* // With API key auth
|
|
333
|
+
* const result = await client.triggers.invokeEndpoint('webhook/stripe', {
|
|
334
|
+
* payload: stripeEvent,
|
|
335
|
+
* headers: { 'X-API-Key': 'your-api-key' }
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
public invokeEndpoint<T = any>(
|
|
340
|
+
endpointPath: string,
|
|
341
|
+
options?: InvokeEndpointOptions
|
|
342
|
+
): Promise<ApiResponse<T>> {
|
|
343
|
+
const path = getEndpointApiPath(this.workspaceId, endpointPath);
|
|
344
|
+
const method = (options?.method || 'POST') as Method;
|
|
345
|
+
const data = ['GET', 'DELETE'].includes(method) ? undefined : (options?.payload || {});
|
|
346
|
+
const queryParams = options?.query;
|
|
347
|
+
return this.requestFn<T>(method, path, data, queryParams);
|
|
348
|
+
}
|
|
349
|
+
}
|