@centrali-io/centrali-sdk 2.9.6 → 2.9.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/README.md +9 -0
- package/dist/index.js +12 -2
- package/index.ts +46 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,15 @@ console.log('Query ID:', query.data.id);
|
|
|
203
203
|
// Execute a smart query
|
|
204
204
|
const results = await centrali.smartQueries.execute('employee', query.data.id);
|
|
205
205
|
console.log('Found:', results.data.length, 'employees');
|
|
206
|
+
|
|
207
|
+
// Execute with variables
|
|
208
|
+
// Query definition uses {{variableName}} syntax: { where: { status: { $eq: "{{statusFilter}}" } } }
|
|
209
|
+
const filteredResults = await centrali.smartQueries.execute('orders', query.data.id, {
|
|
210
|
+
variables: {
|
|
211
|
+
statusFilter: 'active',
|
|
212
|
+
startDate: '2024-01-01'
|
|
213
|
+
}
|
|
214
|
+
});
|
|
206
215
|
```
|
|
207
216
|
|
|
208
217
|
### Search
|
package/dist/index.js
CHANGED
|
@@ -1095,17 +1095,27 @@ class SmartQueriesManager {
|
|
|
1095
1095
|
*
|
|
1096
1096
|
* @param structureSlug - The structure's record slug
|
|
1097
1097
|
* @param queryId - The smart query UUID
|
|
1098
|
+
* @param options - Optional execution options including variables
|
|
1098
1099
|
* @returns Query results
|
|
1099
1100
|
*
|
|
1100
1101
|
* @example
|
|
1101
1102
|
* ```ts
|
|
1103
|
+
* // Simple execution without variables
|
|
1102
1104
|
* const results = await client.smartQueries.execute('employee', 'query-uuid');
|
|
1103
1105
|
* console.log('Found:', results.data.length, 'records');
|
|
1106
|
+
*
|
|
1107
|
+
* // Execution with variables
|
|
1108
|
+
* // Query definition: { where: { status: { $eq: "{{statusFilter}}" } } }
|
|
1109
|
+
* const filtered = await client.smartQueries.execute('orders', 'query-id', {
|
|
1110
|
+
* variables: { statusFilter: 'active' }
|
|
1111
|
+
* });
|
|
1104
1112
|
* ```
|
|
1105
1113
|
*/
|
|
1106
|
-
execute(structureSlug, queryId) {
|
|
1114
|
+
execute(structureSlug, queryId, options) {
|
|
1107
1115
|
const path = getSmartQueryExecuteApiPath(this.workspaceId, structureSlug, queryId);
|
|
1108
|
-
|
|
1116
|
+
// Use POST to support variables, with empty body if no options
|
|
1117
|
+
const body = (options === null || options === void 0 ? void 0 : options.variables) ? { variables: options.variables } : undefined;
|
|
1118
|
+
return this.requestFn('POST', path, body);
|
|
1109
1119
|
}
|
|
1110
1120
|
}
|
|
1111
1121
|
exports.SmartQueriesManager = SmartQueriesManager;
|
package/index.ts
CHANGED
|
@@ -1175,6 +1175,39 @@ export interface ListSmartQueryOptions {
|
|
|
1175
1175
|
sortDirection?: 'asc' | 'desc';
|
|
1176
1176
|
}
|
|
1177
1177
|
|
|
1178
|
+
/**
|
|
1179
|
+
* Options for executing a smart query.
|
|
1180
|
+
*/
|
|
1181
|
+
export interface ExecuteSmartQueryOptions {
|
|
1182
|
+
/**
|
|
1183
|
+
* Variables to substitute in the query.
|
|
1184
|
+
* Use mustache-style {{variableName}} syntax in query conditions,
|
|
1185
|
+
* then provide values here at execution time.
|
|
1186
|
+
*
|
|
1187
|
+
* @example
|
|
1188
|
+
* ```ts
|
|
1189
|
+
* // Query definition with variable: { where: { userId: { $eq: "{{currentUserId}}" } } }
|
|
1190
|
+
* const results = await client.smartQueries.execute('orders', 'query-id', {
|
|
1191
|
+
* variables: { currentUserId: 'user_123' }
|
|
1192
|
+
* });
|
|
1193
|
+
* ```
|
|
1194
|
+
*/
|
|
1195
|
+
variables?: Record<string, string>;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* Result from executing a smart query with metadata.
|
|
1200
|
+
*/
|
|
1201
|
+
export interface SmartQueryExecuteResult<T = any> {
|
|
1202
|
+
/** Query results */
|
|
1203
|
+
result: T[];
|
|
1204
|
+
/** Metadata about the execution */
|
|
1205
|
+
meta?: {
|
|
1206
|
+
/** Variables that were used in the query */
|
|
1207
|
+
variablesUsed?: string[];
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1178
1211
|
// =====================================================
|
|
1179
1212
|
// Search Types
|
|
1180
1213
|
// =====================================================
|
|
@@ -2648,20 +2681,31 @@ export class SmartQueriesManager {
|
|
|
2648
2681
|
*
|
|
2649
2682
|
* @param structureSlug - The structure's record slug
|
|
2650
2683
|
* @param queryId - The smart query UUID
|
|
2684
|
+
* @param options - Optional execution options including variables
|
|
2651
2685
|
* @returns Query results
|
|
2652
2686
|
*
|
|
2653
2687
|
* @example
|
|
2654
2688
|
* ```ts
|
|
2689
|
+
* // Simple execution without variables
|
|
2655
2690
|
* const results = await client.smartQueries.execute('employee', 'query-uuid');
|
|
2656
2691
|
* console.log('Found:', results.data.length, 'records');
|
|
2692
|
+
*
|
|
2693
|
+
* // Execution with variables
|
|
2694
|
+
* // Query definition: { where: { status: { $eq: "{{statusFilter}}" } } }
|
|
2695
|
+
* const filtered = await client.smartQueries.execute('orders', 'query-id', {
|
|
2696
|
+
* variables: { statusFilter: 'active' }
|
|
2697
|
+
* });
|
|
2657
2698
|
* ```
|
|
2658
2699
|
*/
|
|
2659
2700
|
public execute<T = any>(
|
|
2660
2701
|
structureSlug: string,
|
|
2661
|
-
queryId: string
|
|
2702
|
+
queryId: string,
|
|
2703
|
+
options?: ExecuteSmartQueryOptions
|
|
2662
2704
|
): Promise<ApiResponse<T[]>> {
|
|
2663
2705
|
const path = getSmartQueryExecuteApiPath(this.workspaceId, structureSlug, queryId);
|
|
2664
|
-
|
|
2706
|
+
// Use POST to support variables, with empty body if no options
|
|
2707
|
+
const body = options?.variables ? { variables: options.variables } : undefined;
|
|
2708
|
+
return this.requestFn<T[]>('POST', path, body);
|
|
2665
2709
|
}
|
|
2666
2710
|
}
|
|
2667
2711
|
|