From 5c2d34a81cb62ab33ec9f6fa8fec960831d9cffe 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 | 52 ----------------------------- tests/integration/models/os.spec.ts | 41 ----------------------- 3 files changed, 119 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index c3a19a111..171a1540c 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 @@ -761,7 +760,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 @@ -5117,7 +5115,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 @@ -5215,29 +5212,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 7cf95ebd1..be2c97a56 100644 --- a/src/models/os.ts +++ b/src/models/os.ts @@ -619,57 +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, - }); - - const lastModified = response.headers.get('last-modified'); - return lastModified != null ? new Date(lastModified) : lastModified; - } catch (err) { - if (isNotFoundResponse(err)) { - throw new Error('No such version for the device type'); - } - throw err; - } - }; - /** * @summary Download an OS image * @name download @@ -1054,7 +1003,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;