@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
153 lines • 5.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureService = void 0;
const index_js_1 = require("../core/index.js");
/**
* This class allows reading a feature toggles for current tenant.
*/
class FeatureService extends index_js_1.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);
* })();
* ```
*/
async list(filter = {}) {
return super.list(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);
* })();
* ```
*/
async detail(key) {
return super.detail(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);
* })();
* ```
*/
async detailByTenant(key, filter = {}) {
const headers = { accept: 'application/json' };
const url = this.getDetailUrl(key) + '/by-tenant';
const res = await this.fetch(url, this.changeFetchOptions({ headers, params: { ...filter } }, url));
const data = await 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,
* });
* ```
*/
async updateFeature(feature) {
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 = await 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');
* ```
*/
async updateFeatureByTenant(feature, tenantId) {
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 = await 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,
* });
* ```
*/
async removeTenantOverride(feature) {
const url = `${this.listUrl}/${feature['key']}/by-tenant`;
const method = 'DELETE';
const res = await 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');
* ```
*/
async removeTenantOverrideByTenant(feature, tenantId) {
const url = `${this.listUrl}/${feature['key']}/by-tenant/${tenantId}`;
const method = 'DELETE';
const res = await this.fetch(url, this.changeFetchOptions({ method }, url));
return { res, data: null };
}
}
exports.FeatureService = FeatureService;
//# sourceMappingURL=FeatureService.js.map