@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
80 lines • 2.43 kB
JavaScript
import { __awaiter } from "tslib";
import { Service } from '../core';
/**
* This class allows reading a feature toggles for current tenant.
*/
export class FeatureService extends Service {
constructor() {
super(...arguments);
this.baseUrl = '';
this.listUrl = 'features';
}
/**
* Retrieve list of feature toggles with values for current tenant.
*
* **Example**
* ```typescript
*
* const filter = {
* pageSize: 1000,
* withTotalPages: true
* };
*
* (async () => {
* const {data, res, paging} = await featureService.list(filter);
* })();
* ```
*/
list() {
const _super = Object.create(null, {
list: { get: () => super.list }
});
return __awaiter(this, arguments, void 0, function* (filter = {}) {
return _super.list.call(this, filter);
});
}
/**
* Retrieve a specific feature toggle with value for current tenant.
*
* **Example**
* ```typescript
*
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.detail(featureToggleKey);
* })();
* ```
*/
detail(key) {
const _super = Object.create(null, {
detail: { get: () => super.detail }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.detail.call(this, key);
});
}
/**
* Update a specific feature toggle value for current tenant.
*
* **Example**
* ```typescript
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.updateFeature({
* key: featureToggleKey,
* active: true,
* });
* ```
*/
updateFeature(feature) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${this.listUrl}/${feature['key']}/by-tenant`;
const method = 'PUT';
const body = JSON.stringify(feature);
const headers = { 'content-type': 'application/json', accept: 'application/json' };
const res = yield this.fetch(url, this.changeFetchOptions({ method, body, headers }, url));
return { res, data: null };
});
}
}
//# sourceMappingURL=FeatureService.js.map