@centrali-io/centrali-sdk 9.8.0 → 9.10.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 +12 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +26 -13
- package/package.json +1 -1
- package/src/managers/smartQueries.ts +31 -15
package/README.md
CHANGED
|
@@ -407,6 +407,18 @@ const tagNames = post.data.data._expanded.tags.map(tag => tag.data.name);
|
|
|
407
407
|
|
|
408
408
|
### Saved Queries
|
|
409
409
|
|
|
410
|
+
Lifecycle reads and deletion use workspace-scoped canonical `/saved-queries`
|
|
411
|
+
routes. `list(recordSlug)` filters the collection endpoint by `recordSlug`;
|
|
412
|
+
get, execute, update and delete resolve the resource from the query ID. The
|
|
413
|
+
existing `recordSlug` arguments remain accepted. Metadata-only updates use the
|
|
414
|
+
canonical PUT, so renaming a query does not require resending its definition.
|
|
415
|
+
List options retain SDK names: `limit` maps to `pageSize`, and
|
|
416
|
+
`sortDirection: "desc"` maps to a `-` prefix on each sort field.
|
|
417
|
+
Create and definition updates should supply canonical `query` bodies as shown
|
|
418
|
+
below. Deprecated SDK `queryDefinition` bodies still select the retired legacy
|
|
419
|
+
adapter and receive HTTP 410 after sunset; migrate them to `query`. MCP tools
|
|
420
|
+
now supply canonical bodies with or without typed declarations.
|
|
421
|
+
|
|
410
422
|
Saved queries are reusable, predefined queries created in the Centrali console and executed programmatically via the SDK. Pagination is defined in the query definition itself.
|
|
411
423
|
|
|
412
424
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -4073,6 +4073,7 @@ declare class SmartQueriesManager {
|
|
|
4073
4073
|
* ```
|
|
4074
4074
|
*/
|
|
4075
4075
|
list(structureSlug: string, options?: ListSmartQueryOptions): Promise<ApiResponse<SmartQuery[]>>;
|
|
4076
|
+
private listQueryParams;
|
|
4076
4077
|
/**
|
|
4077
4078
|
* Get a smart query by ID.
|
|
4078
4079
|
*
|
|
@@ -4086,7 +4087,7 @@ declare class SmartQueriesManager {
|
|
|
4086
4087
|
* console.log('Query name:', query.data.name);
|
|
4087
4088
|
* ```
|
|
4088
4089
|
*/
|
|
4089
|
-
get(
|
|
4090
|
+
get(_structureSlug: string, queryId: string): Promise<ApiResponse<SmartQuery>>;
|
|
4090
4091
|
/**
|
|
4091
4092
|
* Get a smart query by name.
|
|
4092
4093
|
*
|
|
@@ -4203,9 +4204,9 @@ declare class SmartQueriesManager {
|
|
|
4203
4204
|
/**
|
|
4204
4205
|
* Update an existing saved query.
|
|
4205
4206
|
*
|
|
4206
|
-
*
|
|
4207
|
-
* `PUT /saved-queries/:id
|
|
4208
|
-
*
|
|
4207
|
+
* Canonical bodies and metadata-only edits use
|
|
4208
|
+
* `PUT /saved-queries/:id`. Deprecated
|
|
4209
|
+
* `queryDefinition` bodies retain the legacy adapter.
|
|
4209
4210
|
*
|
|
4210
4211
|
* @example
|
|
4211
4212
|
* ```ts
|
|
@@ -4231,7 +4232,7 @@ declare class SmartQueriesManager {
|
|
|
4231
4232
|
* await client.smartQueries.delete('orders', 'query-uuid');
|
|
4232
4233
|
* ```
|
|
4233
4234
|
*/
|
|
4234
|
-
delete(
|
|
4235
|
+
delete(_structureSlug: string, queryId: string): Promise<ApiResponse<void>>;
|
|
4235
4236
|
/**
|
|
4236
4237
|
* Test-execute a query definition without saving it. Useful for
|
|
4237
4238
|
* validating syntax, previewing results, and dry-running a draft's
|
package/dist/index.js
CHANGED
|
@@ -6663,7 +6663,7 @@ var SmartQueriesManager = class {
|
|
|
6663
6663
|
*/
|
|
6664
6664
|
listAll(options) {
|
|
6665
6665
|
const path = getSmartQueriesApiPath(this.workspaceId);
|
|
6666
|
-
return this.requestFn("GET", path, null, options);
|
|
6666
|
+
return this.requestFn("GET", path, null, this.listQueryParams(options));
|
|
6667
6667
|
}
|
|
6668
6668
|
/**
|
|
6669
6669
|
* List smart queries for a specific structure.
|
|
@@ -6686,8 +6686,18 @@ var SmartQueriesManager = class {
|
|
|
6686
6686
|
* ```
|
|
6687
6687
|
*/
|
|
6688
6688
|
list(structureSlug, options) {
|
|
6689
|
-
const path =
|
|
6690
|
-
return this.requestFn("GET", path, null, options);
|
|
6689
|
+
const path = getSavedQueryCanonicalCollectionPath(this.workspaceId);
|
|
6690
|
+
return this.requestFn("GET", path, null, __spreadProps(__spreadValues({}, this.listQueryParams(options)), { recordSlug: structureSlug }));
|
|
6691
|
+
}
|
|
6692
|
+
listQueryParams(options) {
|
|
6693
|
+
if (!options) return void 0;
|
|
6694
|
+
const _a = options, { limit, sortDirection } = _a, params = __objRest(_a, ["limit", "sortDirection"]);
|
|
6695
|
+
return __spreadValues(__spreadValues(__spreadValues({}, params), limit !== void 0 ? { pageSize: limit } : {}), params.sort && sortDirection ? {
|
|
6696
|
+
sort: params.sort.split(",").map((field) => {
|
|
6697
|
+
const name = field.trim().replace(/^-/, "");
|
|
6698
|
+
return sortDirection === "desc" ? `-${name}` : name;
|
|
6699
|
+
}).join(",")
|
|
6700
|
+
} : {});
|
|
6691
6701
|
}
|
|
6692
6702
|
/**
|
|
6693
6703
|
* Get a smart query by ID.
|
|
@@ -6702,8 +6712,8 @@ var SmartQueriesManager = class {
|
|
|
6702
6712
|
* console.log('Query name:', query.data.name);
|
|
6703
6713
|
* ```
|
|
6704
6714
|
*/
|
|
6705
|
-
get(
|
|
6706
|
-
const path =
|
|
6715
|
+
get(_structureSlug, queryId) {
|
|
6716
|
+
const path = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
6707
6717
|
return this.requestFn("GET", path);
|
|
6708
6718
|
}
|
|
6709
6719
|
/**
|
|
@@ -6720,8 +6730,11 @@ var SmartQueriesManager = class {
|
|
|
6720
6730
|
* ```
|
|
6721
6731
|
*/
|
|
6722
6732
|
getByName(structureSlug, name) {
|
|
6723
|
-
|
|
6724
|
-
|
|
6733
|
+
return __async(this, null, function* () {
|
|
6734
|
+
const response = yield this.requestFn("GET", getSavedQueryCanonicalCollectionPath(this.workspaceId), null, { recordSlug: structureSlug, name });
|
|
6735
|
+
if (!response.data.length) throw new CentraliError("Saved query not found", 404, "Not Found", void 0, "RESOURCE_NOT_FOUND");
|
|
6736
|
+
return __spreadProps(__spreadValues({}, response), { data: response.data[0] });
|
|
6737
|
+
});
|
|
6725
6738
|
}
|
|
6726
6739
|
/**
|
|
6727
6740
|
* Execute a saved query and return results.
|
|
@@ -6846,9 +6859,9 @@ var SmartQueriesManager = class {
|
|
|
6846
6859
|
/**
|
|
6847
6860
|
* Update an existing saved query.
|
|
6848
6861
|
*
|
|
6849
|
-
*
|
|
6850
|
-
* `PUT /saved-queries/:id
|
|
6851
|
-
*
|
|
6862
|
+
* Canonical bodies and metadata-only edits use
|
|
6863
|
+
* `PUT /saved-queries/:id`. Deprecated
|
|
6864
|
+
* `queryDefinition` bodies retain the legacy adapter.
|
|
6852
6865
|
*
|
|
6853
6866
|
* @example
|
|
6854
6867
|
* ```ts
|
|
@@ -6863,7 +6876,7 @@ var SmartQueriesManager = class {
|
|
|
6863
6876
|
* ```
|
|
6864
6877
|
*/
|
|
6865
6878
|
update(structureSlug, queryId, input) {
|
|
6866
|
-
if (input.query || input.variables !== void 0) {
|
|
6879
|
+
if (input.queryDefinition === void 0 || input.query || input.variables !== void 0) {
|
|
6867
6880
|
const path2 = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
6868
6881
|
const body = {};
|
|
6869
6882
|
if (input.name !== void 0) body.name = input.name;
|
|
@@ -6886,8 +6899,8 @@ var SmartQueriesManager = class {
|
|
|
6886
6899
|
* await client.smartQueries.delete('orders', 'query-uuid');
|
|
6887
6900
|
* ```
|
|
6888
6901
|
*/
|
|
6889
|
-
delete(
|
|
6890
|
-
const path =
|
|
6902
|
+
delete(_structureSlug, queryId) {
|
|
6903
|
+
const path = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
6891
6904
|
return this.requestFn("DELETE", path);
|
|
6892
6905
|
}
|
|
6893
6906
|
/**
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// =====================================================
|
|
4
4
|
|
|
5
5
|
import type { Method } from 'axios';
|
|
6
|
+
import { CentraliError } from '../internal/error';
|
|
6
7
|
import type { ApiResponse } from '../types/common';
|
|
7
8
|
import type {
|
|
8
9
|
SmartQuery,
|
|
@@ -16,7 +17,6 @@ import type {
|
|
|
16
17
|
import {
|
|
17
18
|
getSmartQueriesApiPath,
|
|
18
19
|
getSmartQueriesStructureApiPath,
|
|
19
|
-
getSmartQueryByNameApiPath,
|
|
20
20
|
getSavedQueryCanonicalCollectionPath,
|
|
21
21
|
getSavedQueryCanonicalByIdPath,
|
|
22
22
|
getSavedQueryCanonicalExecutePath,
|
|
@@ -79,7 +79,7 @@ export class SmartQueriesManager {
|
|
|
79
79
|
*/
|
|
80
80
|
public listAll(options?: ListSmartQueryOptions): Promise<ApiResponse<SmartQuery[]>> {
|
|
81
81
|
const path = getSmartQueriesApiPath(this.workspaceId);
|
|
82
|
-
return this.requestFn<SmartQuery[]>('GET', path, null, options);
|
|
82
|
+
return this.requestFn<SmartQuery[]>('GET', path, null, this.listQueryParams(options));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -103,8 +103,23 @@ export class SmartQueriesManager {
|
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
public list(structureSlug: string, options?: ListSmartQueryOptions): Promise<ApiResponse<SmartQuery[]>> {
|
|
106
|
-
const path =
|
|
107
|
-
return this.requestFn<SmartQuery[]>('GET', path, null, options);
|
|
106
|
+
const path = getSavedQueryCanonicalCollectionPath(this.workspaceId);
|
|
107
|
+
return this.requestFn<SmartQuery[]>('GET', path, null, { ...this.listQueryParams(options), recordSlug: structureSlug });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private listQueryParams(options?: ListSmartQueryOptions): Record<string, unknown> | undefined {
|
|
111
|
+
if (!options) return undefined;
|
|
112
|
+
const { limit, sortDirection, ...params } = options;
|
|
113
|
+
return {
|
|
114
|
+
...params,
|
|
115
|
+
...(limit !== undefined ? { pageSize: limit } : {}),
|
|
116
|
+
...(params.sort && sortDirection ? {
|
|
117
|
+
sort: params.sort.split(',').map(field => {
|
|
118
|
+
const name = field.trim().replace(/^-/, '');
|
|
119
|
+
return sortDirection === 'desc' ? `-${name}` : name;
|
|
120
|
+
}).join(','),
|
|
121
|
+
} : {}),
|
|
122
|
+
};
|
|
108
123
|
}
|
|
109
124
|
|
|
110
125
|
/**
|
|
@@ -120,8 +135,8 @@ export class SmartQueriesManager {
|
|
|
120
135
|
* console.log('Query name:', query.data.name);
|
|
121
136
|
* ```
|
|
122
137
|
*/
|
|
123
|
-
public get(
|
|
124
|
-
const path =
|
|
138
|
+
public get(_structureSlug: string, queryId: string): Promise<ApiResponse<SmartQuery>> {
|
|
139
|
+
const path = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
125
140
|
return this.requestFn<SmartQuery>('GET', path);
|
|
126
141
|
}
|
|
127
142
|
|
|
@@ -138,9 +153,10 @@ export class SmartQueriesManager {
|
|
|
138
153
|
* console.log('Query ID:', query.data.id);
|
|
139
154
|
* ```
|
|
140
155
|
*/
|
|
141
|
-
public getByName(structureSlug: string, name: string): Promise<ApiResponse<SmartQuery>> {
|
|
142
|
-
const
|
|
143
|
-
|
|
156
|
+
public async getByName(structureSlug: string, name: string): Promise<ApiResponse<SmartQuery>> {
|
|
157
|
+
const response = await this.requestFn<SmartQuery[]>('GET', getSavedQueryCanonicalCollectionPath(this.workspaceId), null, { recordSlug: structureSlug, name });
|
|
158
|
+
if (!response.data.length) throw new CentraliError('Saved query not found', 404, 'Not Found', undefined, 'RESOURCE_NOT_FOUND');
|
|
159
|
+
return { ...response, data: response.data[0] };
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
/**
|
|
@@ -292,9 +308,9 @@ export class SmartQueriesManager {
|
|
|
292
308
|
/**
|
|
293
309
|
* Update an existing saved query.
|
|
294
310
|
*
|
|
295
|
-
*
|
|
296
|
-
* `PUT /saved-queries/:id
|
|
297
|
-
*
|
|
311
|
+
* Canonical bodies and metadata-only edits use
|
|
312
|
+
* `PUT /saved-queries/:id`. Deprecated
|
|
313
|
+
* `queryDefinition` bodies retain the legacy adapter.
|
|
298
314
|
*
|
|
299
315
|
* @example
|
|
300
316
|
* ```ts
|
|
@@ -309,7 +325,7 @@ export class SmartQueriesManager {
|
|
|
309
325
|
* ```
|
|
310
326
|
*/
|
|
311
327
|
public update(structureSlug: string, queryId: string, input: UpdateSmartQueryInput): Promise<ApiResponse<SmartQuery>> {
|
|
312
|
-
if (input.query || input.variables !== undefined) {
|
|
328
|
+
if (input.queryDefinition === undefined || input.query || input.variables !== undefined) {
|
|
313
329
|
const path = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
314
330
|
const body: Record<string, unknown> = {};
|
|
315
331
|
if (input.name !== undefined) body.name = input.name;
|
|
@@ -333,8 +349,8 @@ export class SmartQueriesManager {
|
|
|
333
349
|
* await client.smartQueries.delete('orders', 'query-uuid');
|
|
334
350
|
* ```
|
|
335
351
|
*/
|
|
336
|
-
public delete(
|
|
337
|
-
const path =
|
|
352
|
+
public delete(_structureSlug: string, queryId: string): Promise<ApiResponse<void>> {
|
|
353
|
+
const path = getSavedQueryCanonicalByIdPath(this.workspaceId, queryId);
|
|
338
354
|
return this.requestFn<void>('DELETE', path);
|
|
339
355
|
}
|
|
340
356
|
|