@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
192 lines • 6.2 kB
JavaScript
import { __awaiter } from "tslib";
import { Service } from '../core/index.js';
/**
* @description
* This service allows for managing tenant's options.
*/
export class TenantOptionsService extends Service {
constructor() {
super(...arguments);
this.baseUrl = 'tenant';
this.listUrl = 'options';
this.propertyName = 'options';
this.securityOptionsCategories = ['password'];
this.securityOptionsListUrl = 'security-options';
this.systemOptions = 'system';
}
/**
* Get a representation of a tenant's option.
*
* @param entity Tenant option object.
* @param params Additional query parameters.
*
* @returns Returns promise object that is resolved with
* the ITenantOption wrapped by IResult.
*
* **Example**
* ```typescript
* const option: ITenantOption = {
* category: 'access.control',
* key: 'allow.origin'
* };
* const params: ITenantOptionDetailParams = {
* evaluate: 'inherited'
* };
* (async () => {
* const { data, res } = await tenantService.detail(option);
* console.log('value inherited from parent tenant:', data.value);
* })();
* ```
*
* Required role: ROLE_OPTION_MANAGEMENT_READ
*/
detail(entity_1) {
const _super = Object.create(null, {
detail: { get: () => super.detail }
});
return __awaiter(this, arguments, void 0, function* (entity, params = {}) {
return _super.detail.call(this, entity, params);
});
}
/**
* Creates a new tenant's option.
*
* @param {ITenantOption} entity Tenant's Option object.
*
* @returns {IResult<IIdentified>} Returns promise object that is resolved with
* the details of newly created tenant option.
*
* **Example**
* ```typescript
*
* const tenantObject = {
* id: "sample_tenant",
* company: "sample_company",
* domain: "sample_domain.com",
* contactName: "Mr. Doe",
* ...
* };
*
* (async () => {
* const {data, res} = await tenantService.create(tenantObject);
* })();
* ```
*
* Required role: ROLE_OPTION_MANAGEMENT_ADMIN<br><br>
* Options are category-key-value tuples, storing tenant configuration.Some categories of options
* allow creation of new one, other are limited to predefined set of keys.<br><br>
* Any option of any tenant can be defined as "non-editable" by "management" tenant. Afterwards, any PUT or DELETE
* requests made on that option by the owner tenant, will result in 403 error (Unauthorized).
*/
create(entity) {
const _super = Object.create(null, {
create: { get: () => super.create }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.create.call(this, entity);
});
}
/**
* Updates tenant's option data.
*
* @param {ITenantOption} entity Tenant option is partially updatable.
*
* @returns {IResult<ITenantOption>} Returns promise object that is resolved with the saved tenant option object.
*
* **Example**
* ```typescript
*
* const partialUpdateObject: IIdentified = {
* value : "http://developer.cumulocity.com"
* ...
* }
*
* (async () => {
* const {data, res} = await tenantOptionsService.update(partialUpdateObject);
* })();
* ```
*
* Required role: ROLE_OPTION_MANAGEMENT_ADMIN
*/
update(entity) {
const _super = Object.create(null, {
update: { get: () => super.update }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.update.call(this, entity);
});
}
/**
* Gets the list of tenant's options filtered by parameters.
*
* @param {object} filter Object containing filters for querying tenant options.
*
* @returns {IResultList<ITenantOption>} Returns promise object that is resolved
* with the ITenantOption wrapped by IResultList.
*
* **Example**
* ```typescript
*
* const filter: object = {
* severity: Severity.MAJOR,
* pageSize: 100,
* withTotalPages: true
* };
*
* (async () => {
* const {data, res, paging} = await tenantOptionsService.list(filter);
* })();
* ```
*
* Required role: ROLE_OPTION_MANAGEMENT_READ
*/
list() {
const _super = Object.create(null, {
list: { get: () => super.list }
});
return __awaiter(this, arguments, void 0, function* (filter = {}) {
return _super.list.call(this, filter);
});
}
/**
* Delete a representation of a tenant's option.
*
* @param {string|number|IIdentified} entityOrId Tenant's option id or tenant's option object.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
*
* const tenantOptionId: string = "uniqueTenantId";
*
* (async () => {
* const {data, res} = await tenantOptionsService.delete(tenantOptionId);
* })();
* ```
*
* Required role: ROLE_TENANT_MANAGEMENT_ADMIN
*/
delete(entityOrId) {
const _super = Object.create(null, {
delete: { get: () => super.delete }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.delete.call(this, entityOrId);
});
}
getDetailUrl(entity) {
const encodedCategory = encodeURIComponent(entity.category);
const encodedKey = encodeURIComponent(entity.key);
if (this.securityOptionsCategories.indexOf(entity.category) > -1) {
return `${this.securityOptionsListUrl}/${encodedCategory}/${encodedKey}`;
}
else {
return `${this.listUrl}/${encodedCategory}/${encodedKey}`;
}
}
onBeforeCreate(obj) {
return obj;
}
}
//# sourceMappingURL=TenantOptionsService.js.map