@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
259 lines • 8.73 kB
TypeScript
import { Service, IResult, IResultList } from '../core/index.js';
import { ITenant } from './ITenant.js';
import { ICurrentTenant, ICurrentTenantParams } from './ICurrentTenant.js';
import { ITfaSettings } from './ITfaSettings.js';
import { IApplication } from '../application/index.js';
import { TfaStrategy } from './TfaStrategy.js';
/**
* @description
* This service allows for managing tenants.
*/
export declare class TenantService extends Service<ITenant> {
protected baseUrl: string;
protected listUrl: string;
protected currentTenantUrl: string;
protected propertyName: string;
protected fetchOptions: {
method: string;
body: string;
headers: {
'content-type': string;
accept: string;
};
};
/**
* Get a representation of a tenant.
*
* @param {string|number|IIdentified} entityOrId Tenant's id or tenant object.
*
* @returns Returns promise object that is resolved with the IIdentified wrapped by IResult.
*
* **Example**
* ```typescript
*
* const tenantId: number = 1;
*
* (async () => {
* const {data, res} = await tenantService.detail(tenantId);
* })();
* ```
*
* Required role: ROLE_TENANT_MANAGEMENT_READ<br><br>
* User password is never returned in GET response. Authentication mechanism is provided by another interface.
*/
detail(entityOrId: string | number | ITenant): Promise<IResult<ITenant>>;
/**
* Creates a new tenant.
*
* @param {IIdentified} entity Tenant object.
*
* @returns {IResult<IIdentified>} Returns promise object that is resolved with the details of newly created tenant.
*
* **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_TENANT_MANAGEMENT_ADMIN or ROLE_TENANT_MANAGEMENT_CREATE<br><br>
* Note that creating a tenant with adminName, adminPass and adminEmail, creates an admin user with these settings.
* For the tenant id SQL keywords (e.g., select, cross, where) are not allowed.
*/
create(entity: ITenant): Promise<IResult<ITenant>>;
/**
* Updates tenant data.
*
* @param {IIdentified} entity Tenant is partially updatable.
*
* @returns {IResult<IIdentified>} Returns promise object that is resolved with the saved tenant object.
*
* **Example**
* ```typescript
*
* const partialUpdateObject: IIdentified = {
* adminName : "newAdmin"
* ...
* }
*
* (async () => {
* const {data, res} = await tenantService.update(partialUpdateObject);
* })();
* ```
*
* Required role: ROLE_TENANT_MANAGEMENT_ADMIN or ROLE_TENANT_MANAGEMENT_UPDATE<br><br>
* Note that updating adminPass and adminEmail updates these settings in the admin user of the tenant.
* Updating adminName has no effect.
*/
update(entity: ITenant): Promise<IResult<ITenant>>;
/**
* Gets the list of tenants filtered by parameters.
*
* @param {object} filter Object containing filters for querying tenants.
*
* @returns Returns promise object that is resolved with the IIdentified wrapped by IResultList.
*
* **Example**
* ```typescript
*
* const filter: object = {
* severity: Severity.MAJOR,
* pageSize: 100,
* withTotalPages: true
* };
*
* (async () => {
* const {data, res, paging} = await tenantService.list(filter);
* })();
* ```
*
* Required role: ROLE_TENANT_MANAGEMENT_READ
*/
list(filter?: object): Promise<IResultList<ITenant>>;
/**
* Delete a representation of a tenant.
*
* @param {string|number|IIdentified} entityOrId Tenant's id or tenant object.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
*
* const tenantId: string = "uniqueTenantId";
*
* (async () => {
* const {data, res} = await tenantService.delete(tenantId);
* })();
* ```
*
* Required role: ROLE_TENANT_MANAGEMENT_ADMIN
*/
delete(entityOrId: string | number | ITenant): Promise<IResult<null>>;
current(filter?: ICurrentTenantParams): Promise<IResult<ICurrentTenant>>;
/**
* enable support user for current tenant.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
* (async () => {
* const {res} = await tenantService.enableSupportUser();
* })();
* ```
*/
enableSupportUser(): Promise<IResult<null>>;
/**
* disable support user for current tenant.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
* (async () => {
* const {res} = await tenantService.disableSupportUser();
* })();
* ```
*/
disableSupportUser(): Promise<IResult<null>>;
currentTenantType(tenant?: ICurrentTenant | ITenant): Promise<'TRIAL' | 'REGULAR'>;
/**
* Returns two factor-authentication settings for given tenant.
*
* @param tenant The tenant object.
*
* @returns Promise which resolves with the object with TFA settings.
*
* **Example**
* ```typescript
* (async () => {
* const currentTenant = (await tenantService.current()).data;
* const currentTenantTfaSettings = await tenantService.getTfaSettings(currentTenant);
*
* const subtenant = (await tenantService.detail('t12345')).data;
* const subtenantTfaSettings = await tenantService.getTfaSettings(subtenant);
* })();
* ```
*/
getTfaSettings(tenant: ICurrentTenant | ITenant): Promise<ITfaSettings>;
/**
* Update TFA strategy for tenant.
*
* @param tenant The tenant object.
* @param tfaStrategy The TFA strategy.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
* (async () => {
* const currentTenant = (await tenantService.current()).data;
*
* const res = await tenantService.updateTfaStrategy(currentTenant, TfaStrategy.TOTP);
* })();
* ```
*/
updateTfaStrategy(tenant: ICurrentTenant | ITenant, tfaStrategy: TfaStrategy): Promise<IResult<null>>;
/**
* Subscribes a given application to a given tenant.
*
* @param tenant The tenant object.
* @param application The application object.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
* const newApp = {
* name: 'New application',
* type: 'HOSTED',
* key: 'new-app'
* };
*
* const application = (await applicationService.create(newApp)).data;
* const currentTenant = (await tenantService.current()).data;
*
* const {data, res} = await tenantService.subscribeApplication(currentTenant, application);
* })();
* ```
*/
subscribeApplication(tenant: ICurrentTenant | ITenant, application: IApplication): Promise<IResult<null>>;
/**
* Unsubscribes a given application from a given tenant.
*
* @param tenant The tenant object.
* @param application The application object.
*
* @returns Returns promise object that is resolved with the IResult.
*
* **Example**
* ```typescript
* const newApp = {
* name: 'New application',
* type: 'HOSTED',
* key: 'new-app'
* };
*
* const application = (await applicationService.create(newApp)).data;
* const currentTenant = (await tenantService.current()).data;
* await tenantService.addApplication(currentTenant, application);
*
* await tenantService.unsubscribeApplication(currentTenant, application);
* })();
* ```
*/
unsubscribeApplication(tenant: ICurrentTenant | ITenant, application: IApplication): Promise<IResult<null>>;
protected getIdString(tenant: ITenant | ICurrentTenant): string;
protected onBeforeCreate(obj: ITenant): any;
}
//# sourceMappingURL=TenantService.d.ts.map