From 57ac58f905ec1a68176a4b8057513f71ee4c5cb9 Mon Sep 17 00:00:00 2001 From: myarmolinsky Date: Tue, 3 Dec 2024 08:53:57 -0500 Subject: [PATCH] Drop `os.getLastModified` as it has not worked for a while and is unused Change-type: major --- DOCUMENTATION.md | 26 --------------- src/models/os.ts | 51 ----------------------------- tests/integration/models/os.spec.ts | 41 ----------------------- 3 files changed, 118 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index fac10752c..8b5129f4a 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -358,7 +358,6 @@ const sdk = fromSharedOptions(); * [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ Promise * [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ Promise * [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ Promise - * [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ Promise * [.download(options)](#balena.models.os.download) ⇒ Promise * [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ Promise * [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ Promise @@ -762,7 +761,6 @@ balena.models.device.get(123).catch(function (error) { * [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ Promise * [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ Promise * [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ Promise - * [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ Promise * [.download(options)](#balena.models.os.download) ⇒ Promise * [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ Promise * [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ Promise @@ -5119,7 +5117,6 @@ balena.models.organization.remove(123); * [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ Promise * [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ Promise * [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ Promise - * [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ Promise * [.download(options)](#balena.models.os.download) ⇒ Promise * [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ Promise * [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ Promise @@ -5218,29 +5215,6 @@ balena.models.os.getMaxSatisfyingVersion('raspberry-pi', '^2.11.0').then(functio console.log(version); }); ``` - - -##### os.getLastModified(deviceType, [version]) ⇒ Promise -**Kind**: static method of [os](#balena.models.os) -**Summary**: Get the OS image last modified date -**Access**: public -**Fulfil**: Date - last modified date - -| Param | Type | Description | -| --- | --- | --- | -| deviceType | String | device type slug | -| [version] | String | semver-compatible version or 'latest', defaults to 'latest'. Unsupported (unpublished) version will result in rejection. The version **must** be the exact version number. To resolve the semver-compatible range use `balena.model.os.getMaxSatisfyingVersion`. | - -**Example** -```js -balena.models.os.getLastModified('raspberry-pi').then(function(date) { - console.log('The raspberry-pi image was last modified in ' + date); -}); - -balena.models.os.getLastModified('raspberrypi3', '2.0.0').then(function(date) { - console.log('The raspberry-pi image was last modified in ' + date); -}); -``` ##### os.download(options) ⇒ Promise diff --git a/src/models/os.ts b/src/models/os.ts index 5a02dd019..f4a131944 100644 --- a/src/models/os.ts +++ b/src/models/os.ts @@ -619,56 +619,6 @@ const getOsModel = function ( return _getMaxSatisfyingVersion(versionOrRange, osVersions) ?? null; }; - /** - * @summary Get the OS image last modified date - * @name getLastModified - * @public - * @function - * @memberof balena.models.os - * - * @param {String} deviceType - device type slug - * @param {String} [version] - semver-compatible version or 'latest', defaults to 'latest'. - * Unsupported (unpublished) version will result in rejection. - * The version **must** be the exact version number. - * To resolve the semver-compatible range use `balena.model.os.getMaxSatisfyingVersion`. - * @fulfil {Date} - last modified date - * @returns {Promise} - * - * @example - * balena.models.os.getLastModified('raspberry-pi').then(function(date) { - * console.log('The raspberry-pi image was last modified in ' + date); - * }); - * - * balena.models.os.getLastModified('raspberrypi3', '2.0.0').then(function(date) { - * console.log('The raspberry-pi image was last modified in ' + date); - * }); - */ - const getLastModified = async function ( - deviceType: string, - version = 'latest', - ): Promise { - try { - deviceType = await _getNormalizedDeviceTypeSlug(deviceType); - version = normalizeVersion(version); - const response = await request.send({ - method: 'HEAD', - url: '/download', - qs: { - deviceType, - version, - }, - baseUrl: apiUrl, - }); - // TODO: Drop the ! on the next major - return new Date(response.headers.get('last-modified')!); - } catch (err) { - if (isNotFoundResponse(err)) { - throw new Error('No such version for the device type'); - } - throw err; - } - }; - /** * @summary Download an OS image * @name download @@ -1094,7 +1044,6 @@ const getOsModel = function ( getAvailableOsVersions, getMaxSatisfyingVersion, getDownloadSize, - getLastModified, download, getConfig, isSupportedOsUpdate, diff --git a/tests/integration/models/os.spec.ts b/tests/integration/models/os.spec.ts index b0da86e50..dfbe01c17 100644 --- a/tests/integration/models/os.spec.ts +++ b/tests/integration/models/os.spec.ts @@ -705,47 +705,6 @@ describe('OS model', function () { }); }); - describe('balena.models.os.getLastModified()', function () { - parallel('given a valid device slug', function () { - it('should eventually be a valid Date instance', async function () { - const lastModified = - await balena.models.os.getLastModified('raspberry-pi'); - expect(lastModified).to.be.an.instanceof(Date); - }); - - it('should eventually be a valid Date instance if passing a device type alias', async function () { - const lastModified = - await balena.models.os.getLastModified('raspberrypi'); - expect(lastModified).to.be.an.instanceof(Date); - }); - - it('should be able to query for a specific version', async function () { - const lastModified = await balena.models.os.getLastModified( - 'raspberrypi', - '1.26.1', - ); - expect(lastModified).to.be.an.instanceof(Date); - }); - - it('should be able to query for a version containing a plus', async function () { - const lastModified = await balena.models.os.getLastModified( - 'raspberrypi', - '2.0.6+rev3.prod', - ); - expect(lastModified).to.be.an.instanceof(Date); - }); - }); - - describe('given an invalid device slug', () => { - it('should be rejected with an error message', async function () { - const promise = balena.models.os.getLastModified('foo-bar-baz'); - await expect(promise).to.be.rejectedWith( - 'Invalid device type: foo-bar-baz', - ); - }); - }); - }); - describe('balena.models.os.download()', function () { if (IS_BROWSER) { return;