@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
170 lines • 5.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TenantOptionsService = void 0;
const index_js_1 = require("../core/index.js");
/**
* @description
* This service allows for managing tenant's options.
*/
class TenantOptionsService extends index_js_1.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
*/
async detail(entity, params = {}) {
return super.detail(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).
*/
async create(entity) {
return super.create(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
*/
async update(entity) {
return super.update(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
*/
async list(filter = {}) {
return super.list(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
*/
async delete(entityOrId) {
return super.delete(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;
}
}
exports.TenantOptionsService = TenantOptionsService;
//# sourceMappingURL=TenantOptionsService.js.map