import type { InjectedOptionsParam, InjectedDependenciesParam, CurrentService, OsVersion } from '..'; import type { Device, DeviceServiceEnvironmentVariable, DeviceTag, DeviceHistory, DeviceConfigVariable, DeviceEnvironmentVariable } from '../types/models'; import { DeviceOverallStatus as OverallStatus } from '../types/device-overall-status'; import type * as DeviceState from '../types/device-state'; import type { OsUpdateActionResult } from '../util/device-actions/os-update'; import { type MergePineOptions } from '../util'; import { getCurrentServiceDetailsPineExpand } from '../util/device-service-details'; import { LOCAL_MODE_SUPPORT_PROPERTIES } from '../util/local-mode'; import type { AtLeast } from '../../typings/utils'; import type { DeviceType } from '../types/models'; import type { ODataOptionsWithoutCount, OptionsToResponse } from 'pinejs-client-core'; export * as DeviceState from '../types/device-state'; export type { DeviceOverallStatus as OverallStatus } from '../types/device-overall-status'; export type { SupervisorStatus } from './device.supervisor-api.partial'; export type DeviceMetrics = Pick; export interface DateFilters { fromDate?: Date; toDate?: Date; } declare const getDeviceModel: (deps: InjectedDependenciesParam, opts: InjectedOptionsParam) => { /** * @summary Get the target supervisor state on a device * @name getSupervisorTargetState * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Number} version - (optional) target state version (2 or 3), default to 2 * @returns {Promise} * * @example * balena.models.device.getSupervisorTargetState('7cf02a69e4d34c9da573914963cf54fd').then(function(state) { * console.log(state); * }); * * @example * balena.models.device.getSupervisorTargetState(123).then(function(state) { * console.log(state); * }); * * @example * balena.models.device.getSupervisorTargetState(123, 3).then(function(state) { * console.log(state); * }); */ getSupervisorTargetState: (uuidOrId: string | number, version?: 2 | 3) => Promise; /** * @summary Get the target supervisor state on a "generic" device on a fleet * @name getSupervisorTargetStateForApp * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - fleet uuid (string) or id (number) * @param {String} release - (optional) release uuid (default tracked) * @returns {Promise} * * @example * balena.models.device.getSupervisorTargetStateForApp('7cf02a69e4d34c9da573914963cf54fd').then(function(state) { * console.log(state); * }); * * @example * balena.models.device.getSupervisorTargetStateForApp(123).then(function(state) { * console.log(state); * }); * * @example * balena.models.device.getSupervisorTargetStateForApp(123, '7cf02a69e4d34c9da573914963cf54fd').then(function(state) { * console.log(state); * }); * */ getSupervisorTargetStateForApp: (slugOrUuidOrId: string | number, release?: string | number) => Promise; /** * @summary Generate a random key, useful for both uuid and api key. * @name generateUniqueKey * @function * @public * @memberof balena.models.device * * @returns {String} A generated key * * @example * randomKey = balena.models.device.generateUniqueKey(); * // randomKey is a randomly generated key that can be used as either a uuid or an api key * console.log(randomKey); */ generateUniqueKey(): string; /** * @summary Register a new device with a Balena application. * @name register * @public * @function * @memberof balena.models.device * * @param {String|Number} applicationSlugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {String} uuid - device uuid * @param {String} [deviceTypeSlug] - device type slug (string) or alias (string) * * @fulfil {Object} Device registration info ({ id: "...", uuid: "...", api_key: "..." }) * @returns {Promise} * * @example * var uuid = balena.models.device.generateUniqueKey(); * balena.models.device.register('myorganization/myapp', uuid).then(function(registrationInfo) { * console.log(registrationInfo); * }); * * @example * var uuid = balena.models.device.generateUniqueKey(); * balena.models.device.register('myorganization/myapp', uuid, 'raspberry-pi').then(function(registrationInfo) { * console.log(registrationInfo); * }); * * @example * var uuid = balena.models.device.generateUniqueKey(); * balena.models.device.register(123, uuid).then(function(registrationInfo) { * console.log(registrationInfo); * }); */ register(applicationSlugOrUuidOrId: string | number, uuid: string, deviceTypeSlug?: string): Promise<{ id: number; uuid: string; api_key: string; }>; /** * @summary Generate a device key * @name generateDeviceKey * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} [keyName] - Device key name * @param {String} [keyDescription] - Description for device key * @returns {Promise} * * @example * balena.models.device.generateDeviceKey('7cf02a69e4d34c9da573914963cf54fd').then(function(deviceApiKey) { * console.log(deviceApiKey); * }); * * @example * balena.models.device.generateDeviceKey(123).then(function(deviceApiKey) { * console.log(deviceApiKey); * }); */ generateDeviceKey: (uuidOrId: string | number, keyName?: string, keyDescription?: string, keyExpiryDate?: string) => Promise; /** * @summary Check if a device is web accessible with device utls * @name hasDeviceUrl * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Boolean} - has device url * @returns {Promise} * * @example * balena.models.device.hasDeviceUrl('7cf02a69e4d34c9da573914963cf54fd').then(function(hasDeviceUrl) { * if (hasDeviceUrl) { * console.log('The device has device URL enabled'); * } * }); * * @example * balena.models.device.hasDeviceUrl(123).then(function(hasDeviceUrl) { * if (hasDeviceUrl) { * console.log('The device has device URL enabled'); * } * }); */ hasDeviceUrl: (uuidOrId: string | number) => Promise; /** * @summary Get a device url * @name getDeviceUrl * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String} - device url * @returns {Promise} * * @example * balena.models.device.getDeviceUrl('7cf02a69e4d34c9da573914963cf54fd').then(function(url) { * console.log(url); * }); * * @example * balena.models.device.getDeviceUrl(123).then(function(url) { * console.log(url); * }); */ getDeviceUrl: (uuidOrId: string | number) => Promise; /** * @summary Enable device url for a device * @name enableDeviceUrl * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.enableDeviceUrl('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.enableDeviceUrl(123); */ enableDeviceUrl: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Disable device url for a device * @name disableDeviceUrl * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.disableDeviceUrl('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.disableDeviceUrl(123); */ disableDeviceUrl: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Enable local mode * @name enableLocalMode * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @returns {Promise} * * @example * balena.models.device.enableLocalMode('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.enableLocalMode(123); */ enableLocalMode(uuidOrId: string | number): Promise; /** * @summary Disable local mode * @name disableLocalMode * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @returns {Promise} * * @example * balena.models.device.disableLocalMode('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.disableLocalMode(123); */ disableLocalMode: (uuidOrId: string | number) => Promise; /** * @summary Check if local mode is enabled on the device * @name isInLocalMode * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Boolean} - has device url * @returns {Promise} * * @example * balena.models.device.isInLocalMode('7cf02a69e4d34c9da573914963cf54fd').then(function(isInLocalMode) { * if (isInLocalMode) { * console.log('The device has local mode enabled'); * } * }); * * @example * balena.models.device.isInLocalMode(123).then(function(isInLocalMode) { * if (isInLocalMode) { * console.log('The device has local mode enabled'); * } * }); */ isInLocalMode: (uuidOrId: string | number) => Promise; /** * @summary Returns whether local mode is supported along with a message describing the reason why local mode is not supported. * @name getLocalModeSupport * @public * @function * @memberof balena.models.device * * @param {Object} device - A device object * @returns {Object} Local mode support info ({ supported: true/false, message: "..." }) * * @example * balena.models.device.get('7cf02a69e4d34c9da573914963cf54fd').then(function(device) { * balena.models.device.getLocalModeSupport(device); * }) */ getLocalModeSupport: (device: AtLeast) => { supported: boolean; message: string; }; /** * @summary Enable lock override * @name enableLockOverride * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @returns {Promise} * * @example * balena.models.device.enableLockOverride('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.enableLockOverride(123); */ enableLockOverride: (uuidOrId: string | number) => Promise; /** * @summary Disable lock override * @name disableLockOverride * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @returns {Promise} * * @example * balena.models.device.disableLockOverride('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.disableLockOverride(123); */ disableLockOverride: (uuidOrId: string | number) => Promise; /** * @summary Check if a device has the lock override enabled * @name hasLockOverride * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @returns {Promise} * * @example * balena.models.device.hasLockOverride('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.hasLockOverride(123); */ hasLockOverride: (uuidOrId: string | number) => Promise; /** * @summary Get the status of a device * @name getStatus * @public * @function * @memberof balena.models.device * * @description * Convenience method for getting the overall status of a device. * It's recommended to use `balena.models.device.get()` instead, * in case that you need to retrieve more device fields than just the status. * * @see {@link balena.models.device.get} for an example on selecting the `overall_status` field. * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String} - device status * @returns {Promise} * * @example * balena.models.device.getStatus('7cf02a69e4d34c9da573914963cf54fd').then(function(status) { * console.log(status); * }); * * @example * balena.models.device.getStatus(123).then(function(status) { * console.log(status); * }); */ getStatus(uuidOrId: string | number): Promise; /** * @summary Get the progress of a device * @name getProgress * @public * @function * @memberof balena.models.device * * @description * Convenience method for getting the overall progress of a device. * It's recommended to use `balena.models.device.get()` instead, * in case that you need to retrieve more device fields than just the progress. * * @see {@link balena.models.device.get} for an example on selecting the `overall_progress` field. * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Number|null} - device progress * @returns {Promise} * * @example * balena.models.device.getProgress('7cf02a69e4d34c9da573914963cf54fd').then(function(progress) { * console.log(progress); * }); * * @example * balena.models.device.getProgress(123).then(function(progress) { * console.log(progress); * }); */ getProgress(uuidOrId: string | number): Promise; /** * @summary Grant support access to a device until a specified time * @name grantSupportAccess * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {Number} expiryTimestamp - a timestamp in ms for when the support access will expire * @returns {Promise} * * @example * balena.models.device.grantSupportAccess('7cf02a69e4d34c9da573914963cf54fd', Date.now() + 3600 * 1000); * * @example * balena.models.device.grantSupportAccess(123, Date.now() + 3600 * 1000); */ grantSupportAccess(uuidOrIdOrArray: string | string[] | number | number[], expiryTimestamp: number): Promise; /** * @summary Revoke support access to a device * @name revokeSupportAccess * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.revokeSupportAccess('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.revokeSupportAccess(123); */ revokeSupportAccess: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Get the OS version (version number and variant combined) running on a device * @name getOsVersion * @public * @function * @memberof balena.models.device * * @param {Object} device - A device object * @returns {?String} * * @example * balena.models.device.get('7cf02a69e4d34c9da573914963cf54fd').then(function(device) { * console.log(device.os_version); // => 'balenaOS 2.26.0+rev1' * console.log(device.os_variant); // => 'prod' * balena.models.device.getOsVersion(device); // => '2.26.0+rev1.prod' * }) */ getOsVersion: (device: AtLeast) => string; /** * @summary Get whether the device is configured to track the current application release * @name isTrackingApplicationRelease * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Boolean} - is tracking the current application release * @returns {Promise} * * @example * balena.models.device.isTrackingApplicationRelease('7cf02a69e4d34c9da573914963cf54fd').then(function(isEnabled) { * console.log(isEnabled); * }); */ isTrackingApplicationRelease: (uuidOrId: string | number) => Promise; /** * @summary Get the hash of the currently tracked release for a specific device * @name getTargetReleaseHash * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String} - The release hash of the currently tracked release * @returns {Promise} * * @example * balena.models.device.getTargetReleaseHash('7cf02a69e4d34c9da573914963cf54fd').then(function(release) { * console.log(release); * }); * * @example * balena.models.device.getTargetReleaseHash('7cf02a69e4d34c9da573914963cf54fd', function(release) { * console.log(release); * }); */ getTargetReleaseHash: (uuidOrId: string | number) => Promise; /** * @summary Set a specific device to run a particular release * @name pinToRelease * @public * @function * @memberof balena.models.device * * @description Configures the device to run a particular release * and not get updated when the current application release changes. * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {String|Number} fullReleaseHashOrId - the hash of a successful release (string) or id (number) * @returns {Promise} * * @example * balena.models.device.pinToRelease('7cf02a69e4d34c9da573914963cf54fd', 'f7caf4ff80114deeaefb7ab4447ad9c661c50847').then(function() { * ... * }); * * @example * balena.models.device.pinToRelease(123, 'f7caf4ff80114deeaefb7ab4447ad9c661c50847').then(function() { * ... * }); */ pinToRelease: (uuidOrIdOrArray: string | string[] | number | number[], fullReleaseHashOrId: string | number) => Promise; /** * @summary Configure a specific device to track the current application release * @name trackApplicationRelease * @public * @function * @memberof balena.models.device * * @description The device's current release will be updated with each new successfully built release. * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.trackApplicationRelease('7cf02a69e4d34c9da573914963cf54fd').then(function() { * ... * }); */ trackApplicationRelease: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Set a specific device to run a particular supervisor release * @name pinToSupervisorRelease * @public * @function * @memberof balena.models.device * * @description Configures the device to run a particular supervisor release. * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {String|Number} supervisorVersionOrId - the raw version of a supervisor release (string) or id (number) * @returns {Promise} * * @example * balena.models.device.pinToSupervisorRelease('7cf02a69e4d34c9da573914963cf54fd', '10.8.0').then(function() { * ... * }); * * @example * balena.models.device.pinToSupervisorRelease(123, '11.4.14').then(function() { * ... * }); */ pinToSupervisorRelease: (uuidOrIdOrArray: string | string[] | number | number[], supervisorVersionOrId: string | number) => Promise; /** * @summary Check whether the provided device can update to the target os version * @name _checkOsUpdateTarget * @private * @function * @memberof balena.models.device * * @description * Utility method exported for testability * * @param {Object} device - A device object * @param {String} targetOsVersion - semver-compatible version for the target device * @param {'start'|'pin'} mode * @throws Exception if update isn't supported * @returns {void} */ _checkOsUpdateTarget({ uuid, is_of__device_type, os_version, os_variant, }: Pick & { is_of__device_type: [Pick]; }, targetOsRelease: Pick, mode: "start" | "pin"): void; /** * @summary Start an OS update on a device * @name startOsUpdate * @public * @function * @memberof balena.models.device * * @param {String|String[]} uuidOrUuids - full device uuid or array of full uuids * @param {String} targetOsVersion - semver-compatible version for the target device * Unsupported (unpublished) version will result in rejection. * The version **must** be the exact version number, a "prod" variant and greater than the one running on the device. * To resolve the semver-compatible range use `balena.model.os.getMaxSatisfyingVersion`. * @param {Object} [options] - options * @param {Boolean} [options.runDetached] - run the update in detached mode. True by default * @fulfil {Object} - action response * @returns {Promise} * * @example * balena.models.device.startOsUpdate('7cf02a687b74206f92cb455969cf8e98', '2.29.2+rev1.prod').then(function(status) { * console.log(result.status); * }); */ startOsUpdate: { (uuidOrUuids: string, targetOsVersion: string, options?: { runDetached?: boolean; }): Promise; (uuidOrUuids: string[], targetOsVersion: string, options?: { runDetached?: boolean; }): Promise>; }; /** * @summary Mark a specific device to be updated to a particular OS release * @name pinToOsRelease * @experimental * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {String} osVersionOrId - the raw version of a OS release (string) or id (number) * Unsupported (unpublished) version will result in rejection. * The version **must** be the exact version number, a "prod" variant and greater than or equal to the one running on the device. * To resolve compatible update targets for a device use `balena.models.os.getSupportedOsUpdateVersions`. * @returns {Promise} * * @example * await balena.models.device.pinToOsRelease('7cf02a687b74206f92cb455969cf8e98', '2.29.2+rev1.prod'); */ pinToOsRelease(uuidOrIdOrArray: string | string[] | number | number[], osVersionOrId: string | number): Promise; /** * @namespace balena.models.device.tags * @memberof balena.models.device */ tags: { /** * @summary Get all device tags for an application * @name getAllByApplication * @public * @function * @memberof balena.models.device.tags * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device tags * @returns {Promise} * * @example * balena.models.device.tags.getAllByApplication('myorganization/myapp').then(function(tags) { * console.log(tags); * }); * * @example * balena.models.device.tags.getAllByApplication(999999).then(function(tags) { * console.log(tags); * }); */ getAllByApplication>(slugOrUuidOrId: string | number, options?: T): Promise>; /** * @summary Get all device tags for a device * @name getAllByDevice * @public * @function * @memberof balena.models.device.tags * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device tags * @returns {Promise} * * @example * balena.models.device.tags.getAllByDevice('7cf02a69e4d34c9da573914963cf54fd').then(function(tags) { * console.log(tags); * }); * * @example * balena.models.device.tags.getAllByDevice(123).then(function(tags) { * console.log(tags); * }); */ getAllByDevice: >(parentParam: string | number | Record, options?: O | undefined) => Promise>; /** * @summary Set a device tag * @name set * @public * @function * @memberof balena.models.device.tags * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} tagKey - tag key * @param {String|undefined} value - tag value * * @returns {Promise} * * @example * balena.models.device.tags.set('7cf02a69e4d34c9da573914963cf54fd', 'EDITOR', 'vim'); * * @example * balena.models.device.tags.set(123, 'EDITOR', 'vim'); */ set: (parentParam: string | number | Record, key: string, value: string) => Promise; /** * @summary Remove a device tag * @name remove * @public * @function * @memberof balena.models.device.tags * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} tagKey - tag key * @returns {Promise} * * @example * balena.models.device.tags.remove('7cf02a69e4d34c9da573914963cf54fd', 'EDITOR'); */ remove: (parentParam: string | number | Record, key: string) => Promise; }; /** * @namespace balena.models.device.configVar * @memberof balena.models.device */ configVar: { /** * @summary Get all config variables for a device * @name getAllByDevice * @public * @function * @memberof balena.models.device.configVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device config variables * @returns {Promise} * * @example * balena.models.device.configVar.getAllByDevice('7cf02a69e4d34c9da573914963cf54fd').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.configVar.getAllByDevice(999999).then(function(vars) { * console.log(vars); * }); */ getAllByDevice: >(parentParam: string | number | Record, options?: O | undefined) => Promise>; /** * @summary Get all device config variables by application * @name getAllByApplication * @public * @function * @memberof balena.models.device.configVar * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device config variables * @returns {Promise} * * @example * balena.models.device.configVar.getAllByApplication('myorganization/myapp').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.configVar.getAllByApplication(999999).then(function(vars) { * console.log(vars); * }); */ getAllByApplication>(slugOrUuidOrId: string | number, options?: T): Promise>; /** * @summary Get the value of a specific config variable * @name get * @public * @function * @memberof balena.models.device.configVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - config variable name * @fulfil {String|undefined} - the config variable value (or undefined) * @returns {Promise} * * @example * balena.models.device.configVar.get('7cf02a69e4d34c9da573914963cf54fd', 'BALENA_VAR').then(function(value) { * console.log(value); * }); * * @example * balena.models.device.configVar.get(999999, 'BALENA_VAR').then(function(value) { * console.log(value); * }); */ get: (parentParam: string | number | Record, key: string) => Promise; /** * @summary Set the value of a specific config variable * @name set * @public * @function * @memberof balena.models.device.configVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - config variable name * @param {String} value - config variable value * @returns {Promise} * * @example * balena.models.device.configVar.set('7cf02a69e4d34c9da573914963cf54fd', 'BALENA_VAR', 'newvalue').then(function() { * ... * }); * * @example * balena.models.device.configVar.set(999999, 'BALENA_VAR', 'newvalue').then(function() { * ... * }); */ set: (parentParam: string | number | Record, key: string, value: string) => Promise; /** * @summary Clear the value of a specific config variable * @name remove * @public * @function * @memberof balena.models.device.configVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - config variable name * @returns {Promise} * * @example * balena.models.device.configVar.remove('7cf02a69e4d34c9da573914963cf54fd', 'BALENA_VAR').then(function() { * ... * }); * * @example * balena.models.device.configVar.remove(999999, 'BALENA_VAR').then(function() { * ... * }); */ remove: (parentParam: string | number | Record, key: string) => Promise; }; /** * @namespace balena.models.device.envVar * @memberof balena.models.device */ envVar: { /** * @summary Get all environment variables for a device * @name getAllByDevice * @public * @function * @memberof balena.models.device.envVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device environment variables * @returns {Promise} * * @example * balena.models.device.envVar.getAllByDevice('7cf02a69e4d34c9da573914963cf54fd').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.envVar.getAllByDevice(999999).then(function(vars) { * console.log(vars); * }); */ getAllByDevice: >(parentParam: string | number | Record, options?: O | undefined) => Promise>; /** * @summary Get all device environment variables by application * @name getAllByApplication * @public * @function * @memberof balena.models.device.envVar * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - device environment variables * @returns {Promise} * * @example * balena.models.device.envVar.getAllByApplication('myorganization/myapp').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.envVar.getAllByApplication(999999).then(function(vars) { * console.log(vars); * }); */ getAllByApplication>(slugOrUuidOrId: string | number, options?: T): Promise>; /** * @summary Get the value of a specific environment variable * @name get * @public * @function * @memberof balena.models.device.envVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - environment variable name * @fulfil {String|undefined} - the environment variable value (or undefined) * @returns {Promise} * * @example * balena.models.device.envVar.get('7cf02a69e4d34c9da573914963cf54fd', 'VAR').then(function(value) { * console.log(value); * }); * * @example * balena.models.device.envVar.get(999999, 'VAR').then(function(value) { * console.log(value); * }); */ get: (parentParam: string | number | Record, key: string) => Promise; /** * @summary Set the value of a specific environment variable * @name set * @public * @function * @memberof balena.models.device.envVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - environment variable name * @param {String} value - environment variable value * @returns {Promise} * * @example * balena.models.device.envVar.set('7cf02a69e4d34c9da573914963cf54fd', 'VAR', 'newvalue').then(function() { * ... * }); * * @example * balena.models.device.envVar.set(999999, 'VAR', 'newvalue').then(function() { * ... * }); */ set: (parentParam: string | number | Record, key: string, value: string) => Promise; /** * @summary Clear the value of a specific environment variable * @name remove * @public * @function * @memberof balena.models.device.envVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} key - environment variable name * @returns {Promise} * * @example * balena.models.device.envVar.remove('7cf02a69e4d34c9da573914963cf54fd', 'VAR').then(function() { * ... * }); * * @example * balena.models.device.envVar.remove(999999, 'VAR').then(function() { * ... * }); */ remove: (parentParam: string | number | Record, key: string) => Promise; }; /** * @namespace balena.models.device.serviceVar * @memberof balena.models.device */ serviceVar: { /** * @summary Get all service variable overrides for a device * @name getAllByDevice * @public * @function * @memberof balena.models.device.serviceVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - service variables * @returns {Promise} * * @example * balena.models.device.serviceVar.getAllByDevice('7cf02a69e4d34c9da573914963cf54fd').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.serviceVar.getAllByDevice(999999).then(function(vars) { * console.log(vars); * }); */ getAllByDevice>(uuidOrId: string | number, options?: T): Promise>; /** * @summary Get all device service variable overrides by application * @name getAllByApplication * @public * @function * @memberof balena.models.device.serviceVar * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - service variables * @returns {Promise} * * @example * balena.models.device.serviceVar.getAllByApplication('myorganization/myapp').then(function(vars) { * console.log(vars); * }); * * @example * balena.models.device.serviceVar.getAllByApplication(999999).then(function(vars) { * console.log(vars); * }); */ getAllByApplication>(slugOrUuidOrId: string | number, options?: T): Promise>; /** * @summary Get the overriden value of a service variable on a device * @name get * @public * @function * @memberof balena.models.device.serviceVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String|Number} serviceNameOrId - service name (string) or id (number) * @param {String} key - variable name * @fulfil {String|undefined} - the variable value (or undefined) * @returns {Promise} * * @example * balena.models.device.serviceVar.get('7cf02a69e4d34c9da573914963cf54fd', 123, 'VAR').then(function(value) { * console.log(value); * }); * * @example * balena.models.device.serviceVar.get('7cf02a69e4d34c9da573914963cf54fd', 'myservice', 'VAR').then(function(value) { * console.log(value); * }); * * @example * balena.models.device.serviceVar.get(999999, 123, 'VAR').then(function(value) { * console.log(value); * }); */ get(uuidOrId: string | number, serviceNameOrId: string | number, key: string): Promise; /** * @summary Set the overriden value of a service variable on a device * @name set * @public * @function * @memberof balena.models.device.serviceVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String|Number} serviceNameOrId - service name (string) or id (number) * @param {String} key - variable name * @param {String} value - variable value * @returns {Promise} * * @example * balena.models.device.serviceVar.set('7cf02a69e4d34c9da573914963cf54fd', 123, 'VAR', 'override').then(function() { * ... * }); * * * @example * balena.models.device.serviceVar.set('7cf02a69e4d34c9da573914963cf54fd', 'myservice', 'VAR', 'override').then(function() { * ... * }); * * @example * balena.models.device.serviceVar.set(999999, 123, 'VAR', 'override').then(function() { * ... * }); */ set(uuidOrId: string | number, serviceNameOrId: string | number, key: string, value: string): Promise; /** * @summary Clear the overridden value of a service variable on a device * @name remove * @public * @function * @memberof balena.models.device.serviceVar * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String|Number} serviceNameOrId - service name (string) or id (number) * @param {String} key - variable name * @returns {Promise} * * @example * balena.models.device.serviceVar.remove('7cf02a69e4d34c9da573914963cf54fd', 123, 'VAR').then(function() { * ... * }); * * @example * balena.models.device.serviceVar.remove('7cf02a69e4d34c9da573914963cf54fd', 'myservice', 'VAR').then(function() { * ... * }); * * @example * balena.models.device.serviceVar.remove(999999, 123, 'VAR').then(function() { * ... * }); */ remove(uuidOrId: string | number, serviceNameOrId: string | number, key: string): Promise; }; /** * @namespace balena.models.device.history * @memberof balena.models.device */ history: { /** * @summary Get all history entries for a device * @name getAllByDevice * @public * @function * @memberof balena.models.device.history * * @param {String|Number} uuidOrId - device uuid (32 / 62 digits string) or id (number) * @param {Date} [dateFilter.fromDate=subDays(new Date(), 7)] - history entries older or equal to this date - default now() - 7 days * @param {Date} [dateFilter.toDate] - history entries younger or equal to this date * @param {Object} [options] - extra pine options to use * @fulfil {Object[]} - device history * @returns {Promise} * * @example * balena.models.device.history.getAllByDevice('7cf02a687b74206f92cb455969cf8e98').then(function(entries) { * console.log(entries); * }); * * @example * balena.models.device.history.getAllByDevice(999999).then(function(entries) { * console.log(entries); * }); * * * @example * // get all device history entries between now - 20 days and now - 10 days * balena.models.device.history.getAllByDevice(999999, { fromDate: subDays(new Date(), 20), toDate: subDays(new Date(), 10)}) * * @example * // get all device history entries between now - 20 days and now - 10 days * balena.models.device.history.getAllByDevice( * 999999, * { fromDate: subDays(new Date(), 20), toDate: subDays(new Date(), 10)}, * { $top: 10, $orderby: { id: 'desc' }} * ) */ getAllByDevice>(uuidOrId: string | number, { fromDate, toDate, }?: DateFilters, options?: T): Promise>; /** * @summary Get all device history entries by application with time frame * @name getAllByApplication * @public * @function * @memberof balena.models.device.history * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Date} [dateFilter.fromDate=subDays(new Date(), 7)] - history entries older or equal to this date - default now() - 7 days * @param {Date} [dateFilter.toDate] - history entries younger or equal to this date * @param {Object} [options] - extra pine options to use * @fulfil {Object[]} - device history * @returns {Promise} * * @example * balena.models.device.history.getAllByApplication('myorganization/myapp').then(function(entries) { * console.log(entries); * }); * * @example * balena.models.device.history.getAllByApplication(999999).then(function(entries) { * console.log(entries); * }); * * @example * // get all device history entries between now - 20 days and now - 10 days * balena.models.device.history.getAllByApplication(999999, { fromDate: subDays(new Date(), 20), toDate: subDays(new Date(), 10)}) * * @example * // get all device history entries between now - 20 days and now - 10 days * balena.models.device.history.getAllByApplication( * 999999, * { fromDate: subDays(new Date(), 20), toDate: subDays(new Date(), 10), * { $top: 10, $orderby: { id: 'desc' }} * }); * */ getAllByApplication>(slugOrUuidOrId: string | number, { fromDate, toDate, }?: DateFilters, options?: T): Promise>; }; ping: (uuidOrId: string | number) => Promise; identify: (uuidOrId: string | number) => Promise; restartApplication: (uuidOrId: string | number) => Promise; reboot: (uuidOrId: string | number, options?: { force?: boolean; }) => Promise; shutdown: (uuidOrId: string | number, options: { force?: boolean; }) => Promise; purge: (uuidOrId: string | number) => Promise; update(uuidOrId: string | number, options: { force?: boolean; }): Promise; getSupervisorState: (uuidOrId: string | number) => Promise; startService: (uuidOrId: string | number, imageId: number) => Promise; stopService: (uuidOrId: string | number, imageId: number) => Promise; restartService: (uuidOrId: string | number, imageId: number) => Promise; OverallStatus: typeof OverallStatus; /** * @summary Get Dashboard URL for a specific device * @function getDashboardUrl * @memberof balena.models.device * * @param {String} uuid - Device uuid * * @returns {String} - Dashboard URL for the specific device * @throws Exception if the uuid is empty * * @example * dashboardDeviceUrl = balena.models.device.getDashboardUrl('a44b544b8cc24d11b036c659dfeaccd8') */ getDashboardUrl(uuid: string): string; /** * @summary Get all devices by application * @name getAllByApplication * @public * @function * @memberof balena.models.device * * @description * This method returns all devices of a specific application. * In order to have the following computed properties in the result * you have to explicitly define them in a `$select` in the extra options: * * `overall_status` * * `overall_progress` * * `should_be_running__release` * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - devices * @returns {Promise} * * @example * balena.models.device.getAllByApplication('myorganization/myapp').then(function(devices) { * console.log(devices); * }); * * @example * balena.models.device.getAllByApplication(123).then(function(devices) { * console.log(devices); * }); * * @example * balena.models.device.getAllByApplication('myorganization/myapp', { $select: ['overall_status', 'overall_progress'] }).then(function(device) { * console.log(device); * }) */ getAllByApplication>(slugOrUuidOrId: string | number, options?: T): Promise>; /** * @summary Get all devices by organization * @name getAllByOrganization * @public * @function * @memberof balena.models.device * * @description * This method returns all devices of a specific application. * In order to have the following computed properties in the result * you have to explicitly define them in a `$select` in the extra options: * * `overall_status` * * `overall_progress` * * `should_be_running__release` * * @param {String|Number} handleOrId - organization handle (string) or id (number). * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - devices * @returns {Promise} * * @example * balena.models.device.getAllByOrganization('myorganization').then(function(devices) { * console.log(devices); * }); * * @example * balena.models.device.getAllByOrganization(123).then(function(devices) { * console.log(devices); * }); * * @example * balena.models.device.getAllByOrganization('myorganization', { $select: ['overall_status', 'overall_progress'] }).then(function(device) { * console.log(device); * }) */ getAllByOrganization>(handleOrId: string | number, options?: T): Promise>; /** * @summary Get a single device * @name get * @public * @function * @memberof balena.models.device * * @description * This method returns a single device by id or uuid. * In order to have the following computed properties in the result * you have to explicitly define them in a `$select` in the extra options: * * `overall_status` * * `overall_progress` * * `should_be_running__release` * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object} - device * @returns {Promise} * * @example * balena.models.device.get('7cf02a69e4d34c9da573914963cf54fd').then(function(device) { * console.log(device); * }) * * @example * balena.models.device.get(123).then(function(device) { * console.log(device); * }) * * @example * balena.models.device.get('7cf02a69e4d34c9da573914963cf54fd', { $select: ['overall_status', 'overall_progress'] }).then(function(device) { * console.log(device); * }) */ get>(uuidOrId: string | number, options?: T): Promise[number]>; /** * @summary Get a single device along with its associated services' details, * including their associated commit * @name getWithServiceDetails * @public * @function * @memberof balena.models.device * * @description * This method does not map exactly to the underlying model: it runs a * larger prebuilt query, and reformats it into an easy to use and * understand format. If you want more control, or to see the raw model * directly, use `device.get(uuidOrId, options)` instead. * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object} - device with service details * @returns {Promise} * * @example * balena.models.device.getWithServiceDetails('7cf02a69e4d34c9da573914963cf54fd').then(function(device) { * console.log(device); * }) * * @example * balena.models.device.getWithServiceDetails(123).then(function(device) { * console.log(device); * }) */ getWithServiceDetails>(uuidOrId: string | number, options?: T): Promise, typeof uuidOrId>> & { current_services_by_app: Record>; }>; /** * @summary Get devices by name * @name getByName * @public * @function * @memberof balena.models.device * * @param {String} name - device name * @fulfil {Object[]} - devices * @returns {Promise} * * @example * balena.models.device.getByName('MyDevice').then(function(devices) { * console.log(devices); * }); */ getByName>(name: string, options?: T): Promise>; /** * @summary Get the name of a device * @name getName * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String} - device name * @returns {Promise} * * @example * balena.models.device.getName('7cf02a69e4d34c9da573914963cf54fd').then(function(deviceName) { * console.log(deviceName); * }); * * @example * balena.models.device.getName(123).then(function(deviceName) { * console.log(deviceName); * }); */ getName: (uuidOrId: string | number) => Promise; /** * @summary Get application name * @name getApplicationName * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String} - application name * @returns {Promise} * * @example * balena.models.device.getApplicationName('7cf02a69e4d34c9da573914963cf54fd').then(function(applicationName) { * console.log(applicationName); * }); * * @example * balena.models.device.getApplicationName(123).then(function(applicationName) { * console.log(applicationName); * }); */ getApplicationName: (uuidOrId: string | number) => Promise; /** * @summary Check if a device exists * @name has * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Boolean} - has device * @returns {Promise} * * @example * balena.models.device.has('7cf02a69e4d34c9da573914963cf54fd').then(function(hasDevice) { * console.log(hasDevice); * }); * * @example * balena.models.device.has(123).then(function(hasDevice) { * console.log(hasDevice); * }); */ has: (uuidOrId: string | number) => Promise; /** * @summary Check if a device is online * @name isOnline * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Boolean} - is device online * @returns {Promise} * * @example * balena.models.device.isOnline('7cf02a69e4d34c9da573914963cf54fd').then(function(isOnline) { * console.log('Is device online?', isOnline); * }); * * @example * balena.models.device.isOnline(123).then(function(isOnline) { * console.log('Is device online?', isOnline); * }); */ isOnline: (uuidOrId: string | number) => Promise; /** * @summary Get the local IP addresses of a device * @name getLocalIPAddresses * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String[]} - local ip addresses * @reject {Error} Will reject if the device is offline * @returns {Promise} * * @example * balena.models.device.getLocalIPAddresses('7cf02a69e4d34c9da573914963cf54fd').then(function(localIPAddresses) { * localIPAddresses.forEach(function(localIP) { * console.log(localIP); * }); * }); * * @example * balena.models.device.getLocalIPAddresses(123).then(function(localIPAddresses) { * localIPAddresses.forEach(function(localIP) { * console.log(localIP); * }); * }); */ getLocalIPAddresses: (uuidOrId: string | number) => Promise; /** * @summary Get the MAC addresses of a device * @name getMACAddresses * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {String[]} - mac addresses * @returns {Promise} * * @example * balena.models.device.getMACAddresses('7cf02a69e4d34c9da573914963cf54fd').then(function(macAddresses) { * macAddresses.forEach(function(mac) { * console.log(mac); * }); * }); * * @example * balena.models.device.getMACAddresses(123).then(function(macAddresses) { * macAddresses.forEach(function(mac) { * console.log(mac); * }); * }); */ getMACAddresses: (uuidOrId: string | number) => Promise; /** * @summary Get the metrics related information for a device * @name getMetrics * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @fulfil {Object} - device metrics * @returns {Promise} * * @example * balena.models.device.getMetrics('7cf02a69e4d34c9da573914963cf54fd').then(function(deviceMetrics) { * console.log(deviceMetrics); * }); * * @example * balena.models.device.getMetrics(123).then(function(deviceMetrics) { * console.log(deviceMetrics); * }); */ getMetrics: (uuidOrId: string | number) => Promise; /** * @summary Remove device * @name remove * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.remove('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.remove(123); */ remove: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Deactivate device * @name deactivate * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @returns {Promise} * * @example * balena.models.device.deactivate('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.deactivate(123); */ deactivate: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Rename device * @name rename * @public * @function * @memberof balena.models.device * * @param {String|Number} uuidOrId - device uuid (string) or id (number) * @param {String} newName - the device new name * * @returns {Promise} * * @example * balena.models.device.rename('7cf02a69e4d34c9da573914963cf54fd', 'NewName'); * * @example * balena.models.device.rename(123, 'NewName'); */ rename: (uuidOrId: string | number, newName: string) => Promise; /** * @summary Note a device * @name setNote * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {String} note - the note * * @returns {Promise} * * @example * balena.models.device.setNote('7cf02a69e4d34c9da573914963cf54fd', 'My useful note'); * * @example * balena.models.device.setNote(123, 'My useful note'); */ setNote: (uuidOrIdOrArray: string | string[] | number | number[], note: string) => Promise; /** * @summary Set a custom location for a device * @name setCustomLocation * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {Object} location - the location ({ latitude: 123, longitude: 456 }) * * @returns {Promise} * * @example * balena.models.device.setCustomLocation('7cf02a69e4d34c9da573914963cf54fd', { latitude: 123, longitude: 456 }); * * @example * balena.models.device.setCustomLocation(123, { latitude: 123, longitude: 456 }); */ setCustomLocation: (uuidOrIdOrArray: string | string[] | number | number[], location: { latitude: string | number; longitude: string | number; }) => Promise; /** * @summary Clear the custom location of a device * @name unsetCustomLocation * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * * @returns {Promise} * * @example * balena.models.device.unsetCustomLocation('7cf02a69e4d34c9da573914963cf54fd'); * * @example * balena.models.device.unsetCustomLocation(123); */ unsetCustomLocation: (uuidOrIdOrArray: string | string[] | number | number[]) => Promise; /** * @summary Move a device to another application * @name move * @public * @function * @memberof balena.models.device * * @param {String|String[]|Number|Number[]} uuidOrIdOrArray - device uuid (string) or id (number) or array of full uuids or ids * @param {String|Number} applicationSlugOrUuidOrId - application slug (string), uuid (string) or id (number) * * @returns {Promise} * * @example * balena.models.device.move('7cf02a69e4d34c9da573914963cf54fd', 'myorganization/myapp'); * * @example * balena.models.device.move(123, 'myorganization/myapp'); * * @example * balena.models.device.move(123, 456); */ move: (uuidOrIdOrArray: string | string[] | number | number[], applicationSlugOrUuidOrId: string | number) => Promise; }; export { getDeviceModel as default };