@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
290 lines • 9.49 kB
TypeScript
import { IIdentified, Service, IResult, IResultList } from '../core/index.js';
import { IDeviceRegistration, IDeviceRegistrationAccept, IDeviceRegistrationCreate, IDeviceRegistrationLimit } from './IDeviceRegistration.js';
import { IDeviceCredentials } from './IDeviceCredentials.js';
/**
* Interface to use as options parameter
* to bootstrap a new device.
*/
export interface IDeviceBootstrapOptions {
/**
* If already logged in it is accessible via
* client.auth.getFetchOptions, see [[BasicAuth.getFetchOptions]]
*
* **Example**
* ``` typescript
*
* // tenant/username:password
* const basicAuthToken = 'Basic dGVuYW50L3VzZXJuYW1lOnBhc3N3b3Jk';
* ```
*/
basicAuthToken?: string;
/**
* Object to define username and password
* as string.
*
* **Example**
* ``` typescript
*
* const basicAuth = {
* user: 'username',
* pass: 'password'
* }
* ```
*/
basicAuth?: {
user: string;
pass: string;
};
}
/**
* This class allows registration of a new device.
*/
export declare class DeviceRegistrationService extends Service<IDeviceRegistration> {
protected baseUrl: string;
protected listUrl: string;
protected propertyName: string;
/**
* Gets the details of device registration.
*
* @param {string|number|IIdentified} entityOrId Entity or Id of the entity.
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* const entityId: number = 1;
*
* (async () => {
* const {data, res} = await deviceRegistrationService.detail(entityId);
* })();
* ```
*/
detail(entityOrId: string | number | IIdentified): Promise<IResult<IDeviceRegistration>>;
/**
* Creates a new device registration.
*
* @param {IDeviceRegistrationCreate} entity Device registration object with mandantory fragments.
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* const mandantoryObject: IDeviceRegistrationCreate = {
* id: 1,
* };
*
* (async () => {
* const {data, res} = await deviceRegistrationService.create(mandantoryObject);
* })();
* ```
*/
create(entity: IDeviceRegistrationCreate): Promise<IResult<IDeviceRegistration>>;
/**
* Gets the list of device registrations by parameters.
*
* @returns Response wrapped in [[IResultList]]
*
* @param {object} filter Object containing filters for querying registrations.
*
* **Example**
* ```typescript
*
* const filter: object = {
* pageSize: 100,
* withTotalPages: true
* };
*
* (async () => {
* const {data, res, paging} = await deviceRegistrationService.list(filter);
* })();
* ```
*/
list(filter?: object): Promise<IResultList<IDeviceRegistration>>;
/**
* Removes an registration with given id.
*
* @returns Response wrapped in [[IResult]]
*
* @param {string | number | IIdentified} entityOrId entity or id of the registration.
*
* **Example**
* ```typescript
*
* const id = 'abc';
*
* (async () => {
* const {data, res} = await deviceRegistrationService.delete(id);
* // data will be null
* })();
* ```
*/
delete(entityOrId: string | number | IIdentified): Promise<IResult<null>>;
/**
* Accepts the device registration for given id.
*
* @returns Response wrapped in [[IResult]]
*
* @param {string | number | IIdentified} entityOrId entity or id of registration. Using an entity object one can pass a securityToken as string next to the id.
*
* @param {string} [securityToken] optional security token to reduce the risk of devices which are not yet registered being taken over by threat actors.
*
* **Examples**
* ```typescript
*
* const id = 'abc';
*
* (async () => {
* const {data, res} = await deviceRegistrationService.accept(id);
* })();
* ```
*
* ```typescript
*
* const entity = { id: 'abc', securityToken: '<secretToken>' };
*
* (async () => {
* const {data, res} = await deviceRegistrationService.accept(entity);
* })();
* ```
*
* ```typescript
*
* const id = 'abc';
* const securityToken = '<secretToken>';
*
* (async () => {
* const {data, res} = await deviceRegistrationService.accept(id, securityToken);
* })();
* ```
*
* Providing a securityToken within an entity object together with another securityToken as a parameter of the
* method will always use the securityToken of the entity object. In the example below <secretTokenA> is
* used as the value. <secretTokenB> is obsolete and ignored.
*
* ```typescript
*
* const entity = { id: 'abc', securityToken: '<secretTokenA>'};
* const securityToken = '<secretTokenB>';
*
* (async () => {
* const {data, res} = await deviceRegistrationService.accept(entity, securityToken);
* })();
*
* ```
*/
accept(entityOrId: string | number | IIdentified, securityToken?: string): Promise<IResult<IDeviceRegistration>>;
/**
* Accepts the device registration for all registrations in pending acceptance.
*
* @returns Response wrapped in [[IResultList]]
*
* **Example**
* ```typescript
*
* (async () => {
* const {data, res} = await deviceRegistrationService.acceptAll();
* })();
* ```
*/
acceptAll(): Promise<IResultList<IDeviceRegistrationAccept>>;
/**
* Gets limitation information for registering devices to the platform
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* (async () => {
* const {data, res} = await deviceRegistrationService.limit();
* })();
* ```
*/
limit(): Promise<IResult<IDeviceRegistrationLimit>>;
/**
* Bootstraps the device with given id.
*
* @param {string | number | IIdentified} entityOrId entity or id of registration. Using an entity object one can pass a securityToken as string next to the id.
* @param options for details see [[IDeviceBootstrapOptions]]
* @param {string} [securityToken] optional security token to reduce the risk of devices which are not yet registered being taken over by threat actors.
*
* **Examples**
* ```typescript
*
* const id: 'abc';
* const options: IDeviceBootstrapOptions = {
* basicAuthToken: 'Basic dGVuYW50L3VzZXJuYW1lOnBhc3N3b3Jk',
* basicAuth: {
* user: 'username',
* pass: 'password'
* }
* };
*
* (async () => {
* const {data, res} = await deviceRegistrationService.bootstrap(id, options);
* })();
* ```
*
* ```typescript
*
* const entity: { id: '123', securityToken: '<secretToken>'};
* const options: IDeviceBootstrapOptions = {
* basicAuthToken: 'Basic dGVuYW50L3VzZXJuYW1lOnBhc3N3b3Jk',
* basicAuth: {
* user: 'username',
* pass: 'password'
* }
* };
*
* (async () => {
* const {data, res} = await deviceRegistrationService.bootstrap(entity, options);
* })();
* ```
*
* ```typescript
*
* const id: '123';
* const options: IDeviceBootstrapOptions = {
* basicAuthToken: 'Basic dGVuYW50L3VzZXJuYW1lOnBhc3N3b3Jk',
* basicAuth: {
* user: 'username',
* pass: 'password'
* }
* };
* const securityToken: '<secretToken>'
*
* (async () => {
* const {data, res} = await deviceRegistrationService.bootstrap(id, options, securityToken);
* })();
* ```
*
* Providing a securityToken within an entity object together with another securityToken as a parameter of the
* method will always use the securityToken of the entity object. In the example below <secretTokenA> is
* used as the value. <secretTokenB> is obsolete and ignored.
*
* ```typescript
*
* const options: IDeviceBootstrapOptions = {
* basicAuthToken: 'Basic dGVuYW50L3VzZXJuYW1lOnBhc3N3b3Jk',
* basicAuth: {
* user: 'username',
* pass: 'password'
* }
* };
* const entity: { id: '123', securityToken: '<secretTokenA>'};
* const securityToken: '<secretTokenB>'
*
* (async () => {
* const {data, res} = await deviceRegistrationService.accept(entity, securityToken);
* })();
* ```
*/
bootstrap(entityOrId: string | number | IIdentified, options: IDeviceBootstrapOptions, securityToken?: string): Promise<IResult<IDeviceCredentials>>;
protected onBeforeCreate(entity: IDeviceRegistrationCreate): IDeviceRegistrationCreate;
protected onBeforeUpdate(entity: IDeviceRegistrationCreate): IDeviceRegistrationCreate;
protected getDetailUrl(entityOrId: string | number | IIdentified): string;
private getSecurityToken;
}
//# sourceMappingURL=DeviceRegistrationService.d.ts.map