@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
170 lines • 5.92 kB
JavaScript
import { __awaiter } from "tslib";
import { Service } from '../core/index.js';
/**
* 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);
});
}
/**
* Retrieve the feature toggle state for the provided key grouped by tenant.
*
* **Example**
* ```typescript
*
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.detailByTenant(featureToggleKey);
* })();
* ```
*/
detailByTenant(key_1) {
return __awaiter(this, arguments, void 0, function* (key, filter = {}) {
const headers = { accept: 'application/json' };
const url = this.getDetailUrl(key) + '/by-tenant';
const res = yield this.fetch(url, this.changeFetchOptions({ headers, params: Object.assign({}, filter) }, url));
const data = yield res.json();
return { res, data };
});
}
/**
* 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 };
});
}
/**
* Update a specific feature toggle value for the provided tenant.
*
* **Example**
* ```typescript
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.updateFeatureByTenant({
* key: featureToggleKey,
* active: true,
* }, 't123456');
* ```
*/
updateFeatureByTenant(feature, tenantId) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${this.listUrl}/${feature['key']}/by-tenant/${tenantId}`;
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 };
});
}
/**
* Removes the feature toggle override for current tenant.
*
* Removal of the override will cause the tenant to use the feature toggle value based on the phase of the feature toggle.
*
* **Example**
* ```typescript
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.removeTenantOverride({
* key: featureToggleKey,
* active: true,
* });
* ```
*/
removeTenantOverride(feature) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${this.listUrl}/${feature['key']}/by-tenant`;
const method = 'DELETE';
const res = yield this.fetch(url, this.changeFetchOptions({ method }, url));
return { res, data: null };
});
}
/**
* Removes the feature toggle override for the provided tenant.
*
* Removal of the override will cause the tenant to use the feature toggle value based on the phase of the feature toggle.
*
* **Example**
* ```typescript
* (async () => {
* const featureToggleKey = 'my-custom-feature';
* const {data, res} = await featureService.removeTenantOverrideByTenant({
* key: featureToggleKey,
* active: true,
* }, 't123456');
* ```
*/
removeTenantOverrideByTenant(feature, tenantId) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${this.listUrl}/${feature['key']}/by-tenant/${tenantId}`;
const method = 'DELETE';
const res = yield this.fetch(url, this.changeFetchOptions({ method }, url));
return { res, data: null };
});
}
}
//# sourceMappingURL=FeatureService.js.map