@c8y/client 1018.506.0 → 1018.509.6
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/lib/bundles/client.umd.js +5 -152
- package/lib/bundles/client.umd.js.map +1 -1
- package/lib/bundles/client.umd.min.js +1 -1
- package/lib/bundles/client.umd.min.js.map +1 -1
- package/lib/cjs/src/smart-groups/SmartGroupsService.d.ts +2 -80
- package/lib/cjs/src/smart-groups/SmartGroupsService.js +5 -136
- package/lib/cjs/src/smart-groups/SmartGroupsService.js.map +1 -1
- package/lib/esm2015/src/smart-groups/SmartGroupsService.d.ts +2 -80
- package/lib/esm2015/src/smart-groups/SmartGroupsService.js +5 -153
- package/lib/esm2015/src/smart-groups/SmartGroupsService.js.map +1 -1
- package/lib/src/smart-groups/SmartGroupsService.d.ts +2 -80
- package/package.json +1 -1
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { IFetchClient, IResult } from '../core';
|
|
2
2
|
import { Service } from '../core/Service';
|
|
3
|
-
import {
|
|
3
|
+
import { IManagedObject, IdReference } from '../inventory';
|
|
4
4
|
export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
5
5
|
protected baseUrl: string;
|
|
6
6
|
protected listUrl: string;
|
|
7
|
-
private applicationService;
|
|
8
7
|
private readonly SMART_GROUP_TYPE;
|
|
9
8
|
private readonly SMART_GROUP_FRAGMENT_TYPE;
|
|
10
|
-
private readonly DEVICE_GROUP_FRAGMENT_TYPE;
|
|
11
|
-
private readonly DEVICE_GROUP_TYPE;
|
|
12
|
-
private readonly DEVICE_SUBGROUP_TYPE;
|
|
13
9
|
private readonly COLUMNS_CONFIG_FRAGMENT;
|
|
14
10
|
private readonly FILTER_CONFIG_FRAGMENT;
|
|
15
11
|
private readonly QUERY_STRING_FRAGMENT;
|
|
16
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_APP_NAME;
|
|
17
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_BASE_PATH;
|
|
18
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH;
|
|
19
12
|
constructor(client: IFetchClient);
|
|
20
13
|
/**
|
|
21
14
|
* Gets the details of managed object
|
|
@@ -73,7 +66,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
73
66
|
* Updates smart group managed object with given id.
|
|
74
67
|
*
|
|
75
68
|
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group.
|
|
76
|
-
* @param {object} filter Filter object.
|
|
77
69
|
*
|
|
78
70
|
* @returns Response wrapped in [[IResult]]
|
|
79
71
|
*
|
|
@@ -87,26 +79,7 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
87
79
|
* })();
|
|
88
80
|
* ```
|
|
89
81
|
*/
|
|
90
|
-
update(mo: Partial<IManagedObject
|
|
91
|
-
/**
|
|
92
|
-
* Updates smart group v2 managed object with given id.
|
|
93
|
-
*
|
|
94
|
-
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group v2.
|
|
95
|
-
* @param {object} filter Filter object.
|
|
96
|
-
*
|
|
97
|
-
* @returns Response wrapped in [[IResult]]
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
*
|
|
102
|
-
* const smartGroupV2 = { id: '1', name: 'newName' };
|
|
103
|
-
*
|
|
104
|
-
* (async () => {
|
|
105
|
-
* await smartGroupsService.updateSmartGroupV2(smartGroupV2);
|
|
106
|
-
* })();
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
updateSmartGroupV2(mo: Partial<IManagedObject>, filter?: object): Promise<IResult<IManagedObject>>;
|
|
82
|
+
update(mo: Partial<IManagedObject>): Promise<IResult<IManagedObject>>;
|
|
110
83
|
/**
|
|
111
84
|
* Removes managed object with given id.
|
|
112
85
|
*
|
|
@@ -129,20 +102,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
129
102
|
* ```
|
|
130
103
|
*/
|
|
131
104
|
delete(entityOrId: IdReference, params?: any): Promise<IResult<null>>;
|
|
132
|
-
/**
|
|
133
|
-
* Checks if the smart groups v2 microservice is installed.
|
|
134
|
-
*
|
|
135
|
-
* @returns Response wrapped in [[IResult]]
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
*
|
|
140
|
-
* (async () => {
|
|
141
|
-
* const {data, res} = await smartGroupsService.isSmartGroupsV2MicroserviceInstalled();
|
|
142
|
-
* })();
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
isSmartGroupsV2MicroserviceInstalled(): Promise<IResult<boolean>>;
|
|
146
105
|
/**
|
|
147
106
|
* Checks whether a given managed object is a smart group
|
|
148
107
|
*
|
|
@@ -161,43 +120,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
161
120
|
* ```
|
|
162
121
|
*/
|
|
163
122
|
isSmartGroup(mo: Partial<IManagedObject>): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Checks whether a given managed object is a smart group v2
|
|
166
|
-
*
|
|
167
|
-
* @param {IManagedObject} mo Managed object to check.
|
|
168
|
-
*
|
|
169
|
-
* @returns boolean
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
*
|
|
174
|
-
* const mo: IManagedObject = {id: 1, type: "c8y_DeviceGroup", c8y_IsDeviceGroup: {}} as IManagedObject;
|
|
175
|
-
*
|
|
176
|
-
* (() => {
|
|
177
|
-
* const isSmartGroup = smartGroupsService.isSmartGroupV2(mo);
|
|
178
|
-
* })();
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
isSmartGroupV2(mo: Partial<IManagedObject>): boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Removes smart group v2 managed object with given id.
|
|
184
|
-
*
|
|
185
|
-
* @param {IdReference} entityOrId entity or Id of the ManagedObject.
|
|
186
|
-
*
|
|
187
|
-
* @returns Response wrapped in [[IResult]]
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
*
|
|
192
|
-
* const id: string = '1';
|
|
193
|
-
*
|
|
194
|
-
* (async () => {
|
|
195
|
-
* await smartGroupsService.removeSmartGroupV2(id);
|
|
196
|
-
* })();
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
removeSmartGroupV2(entityOrId: IdReference): Promise<IResult<null>>;
|
|
200
123
|
protected getUrl(url?: string): string;
|
|
201
|
-
private createSmartGroupV2;
|
|
202
124
|
}
|
|
203
125
|
//# sourceMappingURL=SmartGroupsService.d.ts.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SmartGroupsService = void 0;
|
|
4
|
-
const application_1 = require("../application");
|
|
5
4
|
const Service_1 = require("../core/Service");
|
|
6
5
|
class SmartGroupsService extends Service_1.Service {
|
|
7
6
|
constructor(client) {
|
|
@@ -10,16 +9,9 @@ class SmartGroupsService extends Service_1.Service {
|
|
|
10
9
|
this.listUrl = 'managedObjects';
|
|
11
10
|
this.SMART_GROUP_TYPE = 'c8y_DynamicGroup';
|
|
12
11
|
this.SMART_GROUP_FRAGMENT_TYPE = 'c8y_IsDynamicGroup';
|
|
13
|
-
this.DEVICE_GROUP_FRAGMENT_TYPE = 'c8y_IsDeviceGroup';
|
|
14
|
-
this.DEVICE_GROUP_TYPE = 'c8y_DeviceGroup';
|
|
15
|
-
this.DEVICE_SUBGROUP_TYPE = 'c8y_DeviceSubgroup';
|
|
16
12
|
this.COLUMNS_CONFIG_FRAGMENT = 'c8y_DeviceColumnsConfig';
|
|
17
13
|
this.FILTER_CONFIG_FRAGMENT = 'c8y_DeviceFilterConfig';
|
|
18
14
|
this.QUERY_STRING_FRAGMENT = 'c8y_DeviceQueryString';
|
|
19
|
-
this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME = 'smartgroup';
|
|
20
|
-
this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH = 'service/smartgroup';
|
|
21
|
-
this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH = `${this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH}/smartgroups`;
|
|
22
|
-
this.applicationService = new application_1.ApplicationService(client);
|
|
23
15
|
}
|
|
24
16
|
/**
|
|
25
17
|
* Gets the details of managed object
|
|
@@ -75,20 +67,18 @@ class SmartGroupsService extends Service_1.Service {
|
|
|
75
67
|
* ```
|
|
76
68
|
*/
|
|
77
69
|
async create(obj) {
|
|
78
|
-
const { data: isInstalled } = await this.isSmartGroupsV2MicroserviceInstalled();
|
|
79
70
|
const entity = {
|
|
80
71
|
...obj.smartGroup,
|
|
81
72
|
[this.QUERY_STRING_FRAGMENT]: obj.deviceQueryString,
|
|
82
73
|
[this.COLUMNS_CONFIG_FRAGMENT]: obj.configurableColumns,
|
|
83
74
|
...(obj.filterConfig && { [this.FILTER_CONFIG_FRAGMENT]: obj.filterConfig })
|
|
84
75
|
};
|
|
85
|
-
return
|
|
76
|
+
return super.create(entity);
|
|
86
77
|
}
|
|
87
78
|
/**
|
|
88
79
|
* Updates smart group managed object with given id.
|
|
89
80
|
*
|
|
90
81
|
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group.
|
|
91
|
-
* @param {object} filter Filter object.
|
|
92
82
|
*
|
|
93
83
|
* @returns Response wrapped in [[IResult]]
|
|
94
84
|
*
|
|
@@ -102,41 +92,8 @@ class SmartGroupsService extends Service_1.Service {
|
|
|
102
92
|
* })();
|
|
103
93
|
* ```
|
|
104
94
|
*/
|
|
105
|
-
async update(mo
|
|
106
|
-
|
|
107
|
-
const { data: isInstalled } = await this.isSmartGroupsV2MicroserviceInstalled();
|
|
108
|
-
const { data: groupMo } = await this.detail(id, { withChildren: false });
|
|
109
|
-
return isInstalled && this.isSmartGroupV2(groupMo)
|
|
110
|
-
? this.updateSmartGroupV2(mo, filter)
|
|
111
|
-
: super.update(mo);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Updates smart group v2 managed object with given id.
|
|
115
|
-
*
|
|
116
|
-
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group v2.
|
|
117
|
-
* @param {object} filter Filter object.
|
|
118
|
-
*
|
|
119
|
-
* @returns Response wrapped in [[IResult]]
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
*
|
|
124
|
-
* const smartGroupV2 = { id: '1', name: 'newName' };
|
|
125
|
-
*
|
|
126
|
-
* (async () => {
|
|
127
|
-
* await smartGroupsService.updateSmartGroupV2(smartGroupV2);
|
|
128
|
-
* })();
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
async updateSmartGroupV2(mo, filter = {}) {
|
|
132
|
-
const { id, ...partialMo } = mo;
|
|
133
|
-
const method = 'PUT';
|
|
134
|
-
const body = JSON.stringify(this.onBeforeUpdate(partialMo));
|
|
135
|
-
const headers = { 'content-type': 'application/json', accept: 'application/json' };
|
|
136
|
-
const url = `${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${id}`;
|
|
137
|
-
const res = await this.fetch(url, { method, body, headers, params: { ...filter } });
|
|
138
|
-
const data = await res.json();
|
|
139
|
-
return { res, data };
|
|
95
|
+
async update(mo) {
|
|
96
|
+
return super.update(mo);
|
|
140
97
|
}
|
|
141
98
|
/**
|
|
142
99
|
* Removes managed object with given id.
|
|
@@ -160,29 +117,8 @@ class SmartGroupsService extends Service_1.Service {
|
|
|
160
117
|
* ```
|
|
161
118
|
*/
|
|
162
119
|
async delete(entityOrId, params = {}) {
|
|
163
|
-
const { data: isInstalled } = await this.isSmartGroupsV2MicroserviceInstalled();
|
|
164
120
|
const data = (await this.detail(entityOrId, { withChildren: false })).data;
|
|
165
|
-
return
|
|
166
|
-
? await this.removeSmartGroupV2(data)
|
|
167
|
-
: await super.delete(data, params);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Checks if the smart groups v2 microservice is installed.
|
|
171
|
-
*
|
|
172
|
-
* @returns Response wrapped in [[IResult]]
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
*
|
|
177
|
-
* (async () => {
|
|
178
|
-
* const {data, res} = await smartGroupsService.isSmartGroupsV2MicroserviceInstalled();
|
|
179
|
-
* })();
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
isSmartGroupsV2MicroserviceInstalled() {
|
|
183
|
-
return this.applicationService.isAvailable({
|
|
184
|
-
name: this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME
|
|
185
|
-
});
|
|
121
|
+
return await super.delete(data, params);
|
|
186
122
|
}
|
|
187
123
|
/**
|
|
188
124
|
* Checks whether a given managed object is a smart group
|
|
@@ -206,77 +142,10 @@ class SmartGroupsService extends Service_1.Service {
|
|
|
206
142
|
const isSmartGroupType = mo && mo.type === this.SMART_GROUP_TYPE;
|
|
207
143
|
return hasSmartGroupFragmentType || isSmartGroupType;
|
|
208
144
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Checks whether a given managed object is a smart group v2
|
|
211
|
-
*
|
|
212
|
-
* @param {IManagedObject} mo Managed object to check.
|
|
213
|
-
*
|
|
214
|
-
* @returns boolean
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
*
|
|
219
|
-
* const mo: IManagedObject = {id: 1, type: "c8y_DeviceGroup", c8y_IsDeviceGroup: {}} as IManagedObject;
|
|
220
|
-
*
|
|
221
|
-
* (() => {
|
|
222
|
-
* const isSmartGroup = smartGroupsService.isSmartGroupV2(mo);
|
|
223
|
-
* })();
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
isSmartGroupV2(mo) {
|
|
227
|
-
const hasSmartGroupFragmentType = mo.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE);
|
|
228
|
-
const hasDeviceGroupFragmentType = mo.hasOwnProperty(this.DEVICE_GROUP_FRAGMENT_TYPE);
|
|
229
|
-
const isGroupOrSubgroup = (mo && mo.type === this.DEVICE_GROUP_TYPE) || mo.type === this.DEVICE_SUBGROUP_TYPE;
|
|
230
|
-
return hasSmartGroupFragmentType && hasDeviceGroupFragmentType && isGroupOrSubgroup;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Removes smart group v2 managed object with given id.
|
|
234
|
-
*
|
|
235
|
-
* @param {IdReference} entityOrId entity or Id of the ManagedObject.
|
|
236
|
-
*
|
|
237
|
-
* @returns Response wrapped in [[IResult]]
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```typescript
|
|
241
|
-
*
|
|
242
|
-
* const id: string = '1';
|
|
243
|
-
*
|
|
244
|
-
* (async () => {
|
|
245
|
-
* await smartGroupsService.removeSmartGroupV2(id);
|
|
246
|
-
* })();
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
async removeSmartGroupV2(entityOrId) {
|
|
250
|
-
let id;
|
|
251
|
-
if (typeof entityOrId === 'object' && entityOrId.id) {
|
|
252
|
-
id = entityOrId.id;
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
id = entityOrId;
|
|
256
|
-
}
|
|
257
|
-
const method = 'DELETE';
|
|
258
|
-
const url = `${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${id}`;
|
|
259
|
-
const res = await this.client.fetch(url, { method });
|
|
260
|
-
return { res, data: null };
|
|
261
|
-
}
|
|
262
145
|
getUrl(url = '') {
|
|
263
146
|
const partialUrl = url.replace(/^\/+/, '');
|
|
264
147
|
const baseUrl = this.baseUrl.replace(/\/+$/, '');
|
|
265
|
-
|
|
266
|
-
return partialUrl;
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
return `${baseUrl}/${partialUrl}`;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async createSmartGroupV2(entity) {
|
|
273
|
-
const method = 'POST';
|
|
274
|
-
const body = JSON.stringify(entity);
|
|
275
|
-
const headers = { 'content-type': 'application/json', accept: 'application/json' };
|
|
276
|
-
const url = this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH;
|
|
277
|
-
const res = await this.fetch(url, { method, body, headers });
|
|
278
|
-
const data = await res.json();
|
|
279
|
-
return { res, data };
|
|
148
|
+
return `${baseUrl}/${partialUrl}`;
|
|
280
149
|
}
|
|
281
150
|
}
|
|
282
151
|
exports.SmartGroupsService = SmartGroupsService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartGroupsService.js","sourceRoot":"","sources":["../../../../src/smart-groups/SmartGroupsService.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SmartGroupsService.js","sourceRoot":"","sources":["../../../../src/smart-groups/SmartGroupsService.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,MAAa,kBAAmB,SAAQ,iBAAuB;IAS7D,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;QATN,YAAO,GAAG,WAAW,CAAC;QACtB,YAAO,GAAG,gBAAgB,CAAC;QACpB,qBAAgB,GAAG,kBAAkB,CAAC;QACtC,8BAAyB,GAAG,oBAAoB,CAAC;QACjD,4BAAuB,GAAG,yBAAyB,CAAC;QACpD,2BAAsB,GAAG,wBAAwB,CAAC;QAClD,0BAAqB,GAAG,uBAAuB,CAAC;IAIjE,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,MAAM,CAAC,UAAuB,EAAE,SAAiB,EAAE;QACvD,OAAO,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,CAAC,MAAM,CAAC,GAA4B;QACvC,MAAM,MAAM,GAAG;YACb,GAAG,GAAG,CAAC,UAAU;YACjB,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,GAAG,CAAC,iBAAiB;YACnD,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,GAAG,CAAC,mBAAmB;YACvD,GAAG,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC;SAC7E,CAAC;QAEF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,MAAM,CAAC,EAA2B;QACtC,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,CAAC,UAAuB,EAAE,SAAc,EAAE;QACpD,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAE3E,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAA2B;QACtC,MAAM,yBAAyB,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACpF,MAAM,gBAAgB,GAAG,EAAE,IAAI,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,gBAAgB,CAAC;QAEjE,OAAO,yBAAyB,IAAI,gBAAgB,CAAC;IACvD,CAAC;IAES,MAAM,CAAC,GAAG,GAAG,EAAE;QACvB,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEjD,OAAO,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC;IACpC,CAAC;CACF;AA5JD,gDA4JC"}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { IFetchClient, IResult } from '../core';
|
|
2
2
|
import { Service } from '../core/Service';
|
|
3
|
-
import {
|
|
3
|
+
import { IManagedObject, IdReference } from '../inventory';
|
|
4
4
|
export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
5
5
|
protected baseUrl: string;
|
|
6
6
|
protected listUrl: string;
|
|
7
|
-
private applicationService;
|
|
8
7
|
private readonly SMART_GROUP_TYPE;
|
|
9
8
|
private readonly SMART_GROUP_FRAGMENT_TYPE;
|
|
10
|
-
private readonly DEVICE_GROUP_FRAGMENT_TYPE;
|
|
11
|
-
private readonly DEVICE_GROUP_TYPE;
|
|
12
|
-
private readonly DEVICE_SUBGROUP_TYPE;
|
|
13
9
|
private readonly COLUMNS_CONFIG_FRAGMENT;
|
|
14
10
|
private readonly FILTER_CONFIG_FRAGMENT;
|
|
15
11
|
private readonly QUERY_STRING_FRAGMENT;
|
|
16
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_APP_NAME;
|
|
17
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_BASE_PATH;
|
|
18
|
-
private readonly SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH;
|
|
19
12
|
constructor(client: IFetchClient);
|
|
20
13
|
/**
|
|
21
14
|
* Gets the details of managed object
|
|
@@ -73,7 +66,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
73
66
|
* Updates smart group managed object with given id.
|
|
74
67
|
*
|
|
75
68
|
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group.
|
|
76
|
-
* @param {object} filter Filter object.
|
|
77
69
|
*
|
|
78
70
|
* @returns Response wrapped in [[IResult]]
|
|
79
71
|
*
|
|
@@ -87,26 +79,7 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
87
79
|
* })();
|
|
88
80
|
* ```
|
|
89
81
|
*/
|
|
90
|
-
update(mo: Partial<IManagedObject
|
|
91
|
-
/**
|
|
92
|
-
* Updates smart group v2 managed object with given id.
|
|
93
|
-
*
|
|
94
|
-
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group v2.
|
|
95
|
-
* @param {object} filter Filter object.
|
|
96
|
-
*
|
|
97
|
-
* @returns Response wrapped in [[IResult]]
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
*
|
|
102
|
-
* const smartGroupV2 = { id: '1', name: 'newName' };
|
|
103
|
-
*
|
|
104
|
-
* (async () => {
|
|
105
|
-
* await smartGroupsService.updateSmartGroupV2(smartGroupV2);
|
|
106
|
-
* })();
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
updateSmartGroupV2(mo: Partial<IManagedObject>, filter?: object): Promise<IResult<IManagedObject>>;
|
|
82
|
+
update(mo: Partial<IManagedObject>): Promise<IResult<IManagedObject>>;
|
|
110
83
|
/**
|
|
111
84
|
* Removes managed object with given id.
|
|
112
85
|
*
|
|
@@ -129,20 +102,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
129
102
|
* ```
|
|
130
103
|
*/
|
|
131
104
|
delete(entityOrId: IdReference, params?: any): Promise<IResult<null>>;
|
|
132
|
-
/**
|
|
133
|
-
* Checks if the smart groups v2 microservice is installed.
|
|
134
|
-
*
|
|
135
|
-
* @returns Response wrapped in [[IResult]]
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
*
|
|
140
|
-
* (async () => {
|
|
141
|
-
* const {data, res} = await smartGroupsService.isSmartGroupsV2MicroserviceInstalled();
|
|
142
|
-
* })();
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
isSmartGroupsV2MicroserviceInstalled(): Promise<IResult<boolean>>;
|
|
146
105
|
/**
|
|
147
106
|
* Checks whether a given managed object is a smart group
|
|
148
107
|
*
|
|
@@ -161,43 +120,6 @@ export declare class SmartGroupsService extends Service<IManagedObject> {
|
|
|
161
120
|
* ```
|
|
162
121
|
*/
|
|
163
122
|
isSmartGroup(mo: Partial<IManagedObject>): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Checks whether a given managed object is a smart group v2
|
|
166
|
-
*
|
|
167
|
-
* @param {IManagedObject} mo Managed object to check.
|
|
168
|
-
*
|
|
169
|
-
* @returns boolean
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
*
|
|
174
|
-
* const mo: IManagedObject = {id: 1, type: "c8y_DeviceGroup", c8y_IsDeviceGroup: {}} as IManagedObject;
|
|
175
|
-
*
|
|
176
|
-
* (() => {
|
|
177
|
-
* const isSmartGroup = smartGroupsService.isSmartGroupV2(mo);
|
|
178
|
-
* })();
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
isSmartGroupV2(mo: Partial<IManagedObject>): boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Removes smart group v2 managed object with given id.
|
|
184
|
-
*
|
|
185
|
-
* @param {IdReference} entityOrId entity or Id of the ManagedObject.
|
|
186
|
-
*
|
|
187
|
-
* @returns Response wrapped in [[IResult]]
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
*
|
|
192
|
-
* const id: string = '1';
|
|
193
|
-
*
|
|
194
|
-
* (async () => {
|
|
195
|
-
* await smartGroupsService.removeSmartGroupV2(id);
|
|
196
|
-
* })();
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
removeSmartGroupV2(entityOrId: IdReference): Promise<IResult<null>>;
|
|
200
123
|
protected getUrl(url?: string): string;
|
|
201
|
-
private createSmartGroupV2;
|
|
202
124
|
}
|
|
203
125
|
//# sourceMappingURL=SmartGroupsService.d.ts.map
|
|
@@ -7,18 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
-
var t = {};
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
-
t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
import { ApplicationService } from '../application';
|
|
22
10
|
import { Service } from '../core/Service';
|
|
23
11
|
export class SmartGroupsService extends Service {
|
|
24
12
|
constructor(client) {
|
|
@@ -27,16 +15,9 @@ export class SmartGroupsService extends Service {
|
|
|
27
15
|
this.listUrl = 'managedObjects';
|
|
28
16
|
this.SMART_GROUP_TYPE = 'c8y_DynamicGroup';
|
|
29
17
|
this.SMART_GROUP_FRAGMENT_TYPE = 'c8y_IsDynamicGroup';
|
|
30
|
-
this.DEVICE_GROUP_FRAGMENT_TYPE = 'c8y_IsDeviceGroup';
|
|
31
|
-
this.DEVICE_GROUP_TYPE = 'c8y_DeviceGroup';
|
|
32
|
-
this.DEVICE_SUBGROUP_TYPE = 'c8y_DeviceSubgroup';
|
|
33
18
|
this.COLUMNS_CONFIG_FRAGMENT = 'c8y_DeviceColumnsConfig';
|
|
34
19
|
this.FILTER_CONFIG_FRAGMENT = 'c8y_DeviceFilterConfig';
|
|
35
20
|
this.QUERY_STRING_FRAGMENT = 'c8y_DeviceQueryString';
|
|
36
|
-
this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME = 'smartgroup';
|
|
37
|
-
this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH = 'service/smartgroup';
|
|
38
|
-
this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH = `${this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH}/smartgroups`;
|
|
39
|
-
this.applicationService = new ApplicationService(client);
|
|
40
21
|
}
|
|
41
22
|
/**
|
|
42
23
|
* Gets the details of managed object
|
|
@@ -101,16 +82,14 @@ export class SmartGroupsService extends Service {
|
|
|
101
82
|
create: { get: () => super.create }
|
|
102
83
|
});
|
|
103
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const { data: isInstalled } = yield this.isSmartGroupsV2MicroserviceInstalled();
|
|
105
85
|
const entity = Object.assign(Object.assign(Object.assign({}, obj.smartGroup), { [this.QUERY_STRING_FRAGMENT]: obj.deviceQueryString, [this.COLUMNS_CONFIG_FRAGMENT]: obj.configurableColumns }), (obj.filterConfig && { [this.FILTER_CONFIG_FRAGMENT]: obj.filterConfig }));
|
|
106
|
-
return
|
|
86
|
+
return _super.create.call(this, entity);
|
|
107
87
|
});
|
|
108
88
|
}
|
|
109
89
|
/**
|
|
110
90
|
* Updates smart group managed object with given id.
|
|
111
91
|
*
|
|
112
92
|
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group.
|
|
113
|
-
* @param {object} filter Filter object.
|
|
114
93
|
*
|
|
115
94
|
* @returns Response wrapped in [[IResult]]
|
|
116
95
|
*
|
|
@@ -124,47 +103,12 @@ export class SmartGroupsService extends Service {
|
|
|
124
103
|
* })();
|
|
125
104
|
* ```
|
|
126
105
|
*/
|
|
127
|
-
update(mo
|
|
106
|
+
update(mo) {
|
|
128
107
|
const _super = Object.create(null, {
|
|
129
108
|
update: { get: () => super.update }
|
|
130
109
|
});
|
|
131
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
|
|
133
|
-
const { data: isInstalled } = yield this.isSmartGroupsV2MicroserviceInstalled();
|
|
134
|
-
const { data: groupMo } = yield this.detail(id, { withChildren: false });
|
|
135
|
-
return isInstalled && this.isSmartGroupV2(groupMo)
|
|
136
|
-
? this.updateSmartGroupV2(mo, filter)
|
|
137
|
-
: _super.update.call(this, mo);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Updates smart group v2 managed object with given id.
|
|
142
|
-
*
|
|
143
|
-
* @param {Partial<IManagedObject>} mo Partial managed object of the smart group v2.
|
|
144
|
-
* @param {object} filter Filter object.
|
|
145
|
-
*
|
|
146
|
-
* @returns Response wrapped in [[IResult]]
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
*
|
|
151
|
-
* const smartGroupV2 = { id: '1', name: 'newName' };
|
|
152
|
-
*
|
|
153
|
-
* (async () => {
|
|
154
|
-
* await smartGroupsService.updateSmartGroupV2(smartGroupV2);
|
|
155
|
-
* })();
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
updateSmartGroupV2(mo, filter = {}) {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const { id } = mo, partialMo = __rest(mo, ["id"]);
|
|
161
|
-
const method = 'PUT';
|
|
162
|
-
const body = JSON.stringify(this.onBeforeUpdate(partialMo));
|
|
163
|
-
const headers = { 'content-type': 'application/json', accept: 'application/json' };
|
|
164
|
-
const url = `${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${id}`;
|
|
165
|
-
const res = yield this.fetch(url, { method, body, headers, params: Object.assign({}, filter) });
|
|
166
|
-
const data = yield res.json();
|
|
167
|
-
return { res, data };
|
|
111
|
+
return _super.update.call(this, mo);
|
|
168
112
|
});
|
|
169
113
|
}
|
|
170
114
|
/**
|
|
@@ -193,29 +137,8 @@ export class SmartGroupsService extends Service {
|
|
|
193
137
|
delete: { get: () => super.delete }
|
|
194
138
|
});
|
|
195
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
const { data: isInstalled } = yield this.isSmartGroupsV2MicroserviceInstalled();
|
|
197
140
|
const data = (yield this.detail(entityOrId, { withChildren: false })).data;
|
|
198
|
-
return
|
|
199
|
-
? yield this.removeSmartGroupV2(data)
|
|
200
|
-
: yield _super.delete.call(this, data, params);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Checks if the smart groups v2 microservice is installed.
|
|
205
|
-
*
|
|
206
|
-
* @returns Response wrapped in [[IResult]]
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```typescript
|
|
210
|
-
*
|
|
211
|
-
* (async () => {
|
|
212
|
-
* const {data, res} = await smartGroupsService.isSmartGroupsV2MicroserviceInstalled();
|
|
213
|
-
* })();
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
isSmartGroupsV2MicroserviceInstalled() {
|
|
217
|
-
return this.applicationService.isAvailable({
|
|
218
|
-
name: this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME
|
|
141
|
+
return yield _super.delete.call(this, data, params);
|
|
219
142
|
});
|
|
220
143
|
}
|
|
221
144
|
/**
|
|
@@ -240,81 +163,10 @@ export class SmartGroupsService extends Service {
|
|
|
240
163
|
const isSmartGroupType = mo && mo.type === this.SMART_GROUP_TYPE;
|
|
241
164
|
return hasSmartGroupFragmentType || isSmartGroupType;
|
|
242
165
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Checks whether a given managed object is a smart group v2
|
|
245
|
-
*
|
|
246
|
-
* @param {IManagedObject} mo Managed object to check.
|
|
247
|
-
*
|
|
248
|
-
* @returns boolean
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* ```typescript
|
|
252
|
-
*
|
|
253
|
-
* const mo: IManagedObject = {id: 1, type: "c8y_DeviceGroup", c8y_IsDeviceGroup: {}} as IManagedObject;
|
|
254
|
-
*
|
|
255
|
-
* (() => {
|
|
256
|
-
* const isSmartGroup = smartGroupsService.isSmartGroupV2(mo);
|
|
257
|
-
* })();
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
isSmartGroupV2(mo) {
|
|
261
|
-
const hasSmartGroupFragmentType = mo.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE);
|
|
262
|
-
const hasDeviceGroupFragmentType = mo.hasOwnProperty(this.DEVICE_GROUP_FRAGMENT_TYPE);
|
|
263
|
-
const isGroupOrSubgroup = (mo && mo.type === this.DEVICE_GROUP_TYPE) || mo.type === this.DEVICE_SUBGROUP_TYPE;
|
|
264
|
-
return hasSmartGroupFragmentType && hasDeviceGroupFragmentType && isGroupOrSubgroup;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Removes smart group v2 managed object with given id.
|
|
268
|
-
*
|
|
269
|
-
* @param {IdReference} entityOrId entity or Id of the ManagedObject.
|
|
270
|
-
*
|
|
271
|
-
* @returns Response wrapped in [[IResult]]
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```typescript
|
|
275
|
-
*
|
|
276
|
-
* const id: string = '1';
|
|
277
|
-
*
|
|
278
|
-
* (async () => {
|
|
279
|
-
* await smartGroupsService.removeSmartGroupV2(id);
|
|
280
|
-
* })();
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
removeSmartGroupV2(entityOrId) {
|
|
284
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
let id;
|
|
286
|
-
if (typeof entityOrId === 'object' && entityOrId.id) {
|
|
287
|
-
id = entityOrId.id;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
id = entityOrId;
|
|
291
|
-
}
|
|
292
|
-
const method = 'DELETE';
|
|
293
|
-
const url = `${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${id}`;
|
|
294
|
-
const res = yield this.client.fetch(url, { method });
|
|
295
|
-
return { res, data: null };
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
166
|
getUrl(url = '') {
|
|
299
167
|
const partialUrl = url.replace(/^\/+/, '');
|
|
300
168
|
const baseUrl = this.baseUrl.replace(/\/+$/, '');
|
|
301
|
-
|
|
302
|
-
return partialUrl;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
return `${baseUrl}/${partialUrl}`;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
createSmartGroupV2(entity) {
|
|
309
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
-
const method = 'POST';
|
|
311
|
-
const body = JSON.stringify(entity);
|
|
312
|
-
const headers = { 'content-type': 'application/json', accept: 'application/json' };
|
|
313
|
-
const url = this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH;
|
|
314
|
-
const res = yield this.fetch(url, { method, body, headers });
|
|
315
|
-
const data = yield res.json();
|
|
316
|
-
return { res, data };
|
|
317
|
-
});
|
|
169
|
+
return `${baseUrl}/${partialUrl}`;
|
|
318
170
|
}
|
|
319
171
|
}
|
|
320
172
|
//# sourceMappingURL=SmartGroupsService.js.map
|