balena-sdk 16.9.2 → 16.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2018/index.d.ts CHANGED
@@ -349,7 +349,7 @@ declare const sdkTemplate: {
349
349
  _getDeviceTypes: (() => Promise<import("./types/device-type-json").DeviceType[]>) & import("memoizee").Memoized<() => Promise<import("./types/device-type-json").DeviceType[]>>;
350
350
  _getDownloadSize: ((deviceType: string, version: string) => Promise<any>) & import("memoizee").Memoized<(deviceType: string, version: string) => Promise<any>>;
351
351
  _clearDeviceTypesAndOsVersionCaches: () => void;
352
- _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Pick<import("./models/os").OsVersion, "rawVersion" | "isRecommended">[]) => string | undefined;
352
+ _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Pick<import("./models/os").OsVersion, "rawVersion" | "isRecommended">[]) => string | null | undefined;
353
353
  OsTypes: typeof import("./models/os").OsTypes;
354
354
  getAllOsVersions: {
355
355
  (deviceType: string, options?: import("../typings/pinejs-client-core").ODataOptions<import("./types/models").Release> | undefined): Promise<import("./models/os").OsVersion[]>;
@@ -269,7 +269,7 @@ declare const _default: (deps: InjectedDependenciesParam, opts: InjectedOptionsP
269
269
  _getDeviceTypes: (() => Promise<import("../types/device-type-json").DeviceType[]>) & import("memoizee").Memoized<() => Promise<import("../types/device-type-json").DeviceType[]>>;
270
270
  _getDownloadSize: ((deviceType: string, version: string) => Promise<any>) & import("memoizee").Memoized<(deviceType: string, version: string) => Promise<any>>;
271
271
  _clearDeviceTypesAndOsVersionCaches: () => void;
272
- _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Pick<import("./os").OsVersion, "rawVersion" | "isRecommended">[]) => string | undefined;
272
+ _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Pick<import("./os").OsVersion, "rawVersion" | "isRecommended">[]) => string | null | undefined;
273
273
  OsTypes: typeof import("./os").OsTypes;
274
274
  getAllOsVersions: {
275
275
  (deviceType: string, options?: import("..").PineOptions<import("..").Release> | undefined): Promise<import("./os").OsVersion[]>;
@@ -51,7 +51,7 @@ declare const getOsModel: (deps: InjectedDependenciesParam, opts: InjectedOption
51
51
  _getDeviceTypes: (() => Promise<DeviceTypeJson.DeviceType[]>) & import("memoizee").Memoized<() => Promise<DeviceTypeJson.DeviceType[]>>;
52
52
  _getDownloadSize: ((deviceType: string, version: string) => Promise<any>) & import("memoizee").Memoized<(deviceType: string, version: string) => Promise<any>>;
53
53
  _clearDeviceTypesAndOsVersionCaches: () => void;
54
- _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Array<Pick<OsVersion, 'rawVersion' | 'isRecommended'>>) => string | undefined;
54
+ _getMaxSatisfyingVersion: (versionOrRange: string, osVersions: Array<Pick<OsVersion, 'rawVersion' | 'isRecommended'>>) => string | null | undefined;
55
55
  OsTypes: typeof OsTypes;
56
56
  getAllOsVersions: {
57
57
  (deviceType: string, options?: PineOptions<Release> | undefined): Promise<OsVersion[]>;
@@ -45,7 +45,9 @@ const releaseSelectedFields = (0, types_1.toWritable)([
45
45
  'known_issue_list',
46
46
  'raw_version',
47
47
  ]);
48
- const BALENAOS_VERSION_REGEX = /v?\d+\.\d+\.\d+(\.rev\d+)?((\-|\+).+)?/;
48
+ const sortVersions = (a, b) => {
49
+ return bSemver.rcompare(a.rawVersion, b.rawVersion);
50
+ };
49
51
  const getOsModel = function (deps, opts) {
50
52
  const { pine, request, pubsub } = deps;
51
53
  const { apiUrl, isBrowser } = opts;
@@ -57,9 +59,6 @@ const getOsModel = function (deps, opts) {
57
59
  () => require('../util/device-types'));
58
60
  const hupActionHelper = once(() => require('../util/device-actions/os-update/utils').hupActionHelper);
59
61
  const authDependentMemoizer = (0, cache_1.getAuthDependentMemoize)(pubsub);
60
- const sortVersions = (a, b) => {
61
- return bSemver.rcompare(a.rawVersion, b.rawVersion);
62
- };
63
62
  const tagsToDictionary = (tags) => {
64
63
  const result = {};
65
64
  for (const { tag_key, value } of tags) {
@@ -194,14 +193,12 @@ const getOsModel = function (deps, opts) {
194
193
  const appTags = getOsAppTags((_c = hostApp.application_tag) !== null && _c !== void 0 ? _c : []);
195
194
  osVersionsByDeviceType[hostAppDeviceType].push(..._getOsVersionsFromReleases((_d = hostApp.owns__release) !== null && _d !== void 0 ? _d : [], appTags));
196
195
  });
197
- return osVersionsByDeviceType;
198
- };
199
- // This mutates the passed object.
200
- const _transformVersionSets = (osVersionsByDeviceType) => {
196
+ // transform version sets
201
197
  Object.keys(osVersionsByDeviceType).forEach((deviceType) => {
202
198
  osVersionsByDeviceType[deviceType].sort(sortVersions);
203
- const recommendedPerOsType = {};
199
+ // TODO: Drop in next major
204
200
  // Note: the recommended version settings might come from the server in the future, for now we just set it to the latest version for each os type.
201
+ const recommendedPerOsType = {};
205
202
  osVersionsByDeviceType[deviceType].forEach((version) => {
206
203
  if (!recommendedPerOsType[version.osType]) {
207
204
  if (version.variant !== 'dev' &&
@@ -221,7 +218,7 @@ const getOsModel = function (deps, opts) {
221
218
  };
222
219
  const _getAllOsVersions = async (deviceTypes, options) => {
223
220
  const hostapps = await _getOsVersions(deviceTypes, options);
224
- return await _transformVersionSets(_transformHostApps(hostapps));
221
+ return await _transformHostApps(hostapps);
225
222
  };
226
223
  const _memoizedGetAllOsVersions = authDependentMemoizer(async (deviceTypes, listedByDefault) => {
227
224
  return await _getAllOsVersions(deviceTypes, listedByDefault
@@ -256,7 +253,7 @@ const getOsModel = function (deps, opts) {
256
253
  var _a;
257
254
  const singleDeviceTypeArg = typeof deviceTypes === 'string' ? deviceTypes : false;
258
255
  deviceTypes = Array.isArray(deviceTypes) ? deviceTypes : [deviceTypes];
259
- const versionsByDt = await _memoizedGetAllOsVersions(deviceTypes.sort(), true);
256
+ const versionsByDt = await _memoizedGetAllOsVersions(deviceTypes.slice().sort(), true);
260
257
  return singleDeviceTypeArg
261
258
  ? (_a = versionsByDt[singleDeviceTypeArg]) !== null && _a !== void 0 ? _a : []
262
259
  : versionsByDt;
@@ -288,7 +285,7 @@ const getOsModel = function (deps, opts) {
288
285
  const singleDeviceTypeArg = typeof deviceTypes === 'string' ? deviceTypes : false;
289
286
  deviceTypes = Array.isArray(deviceTypes) ? deviceTypes : [deviceTypes];
290
287
  const versionsByDt = options == null
291
- ? await _memoizedGetAllOsVersions(deviceTypes.sort(), null)
288
+ ? await _memoizedGetAllOsVersions(deviceTypes.slice().sort(), null)
292
289
  : await _getAllOsVersions(deviceTypes, options);
293
290
  return singleDeviceTypeArg
294
291
  ? (_a = versionsByDt[singleDeviceTypeArg]) !== null && _a !== void 0 ? _a : []
@@ -344,23 +341,12 @@ const getOsModel = function (deps, opts) {
344
341
  return v;
345
342
  }
346
343
  const vNormalized = v[0] === 'v' ? v.substring(1) : v;
347
- if (!BALENAOS_VERSION_REGEX.test(vNormalized)) {
344
+ // We still don't want to allow `balenaOS` prefixes, which balena-semver allows.
345
+ if (!bSemver.valid(vNormalized) || !/^\d/.test(vNormalized)) {
348
346
  throw new Error(`Invalid semver version: ${v}`);
349
347
  }
350
348
  return vNormalized;
351
349
  };
352
- const fixNonSemver = (version) => {
353
- if (version == null) {
354
- return version;
355
- }
356
- return version.replace(/\.rev(\d+)/, '+FIXED-rev$1');
357
- };
358
- const unfixNonSemver = (version) => {
359
- if (version == null) {
360
- return version;
361
- }
362
- return version.replace(/\+FIXED-rev(\d+)/, '.rev$1');
363
- };
364
350
  /**
365
351
  * @summary Get the max OS version satisfying the given range.
366
352
  * @description Utility method exported for testability.
@@ -381,16 +367,13 @@ const getOsModel = function (deps, opts) {
381
367
  return (_d = ((_c = osVersions.find((v) => v.isRecommended)) !== null && _c !== void 0 ? _c : osVersions[0])) === null || _d === void 0 ? void 0 : _d.rawVersion;
382
368
  }
383
369
  const versions = osVersions.map((v) => v.rawVersion);
384
- const semverVersions = versions.map(fixNonSemver);
385
- // TODO: Once we integrate balena-semver, balena-semver should learn to handle this itself
386
- const semverVersionOrRange = fixNonSemver(versionOrRange);
387
- if (semverVersions.includes(semverVersionOrRange)) {
370
+ if (versions.includes(versionOrRange)) {
388
371
  // If the _exact_ version you're looking for exists, it's not a range, and
389
372
  // we should return it exactly, not any old equivalent version.
390
- return unfixNonSemver(semverVersionOrRange);
373
+ return versionOrRange;
391
374
  }
392
- const maxVersion = bSemver.maxSatisfying(semverVersions, semverVersionOrRange);
393
- return unfixNonSemver(maxVersion);
375
+ const maxVersion = bSemver.maxSatisfying(versions, versionOrRange);
376
+ return maxVersion;
394
377
  };
395
378
  /**
396
379
  * @summary Get OS download size estimate
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // being embedded in the dist of the consumer project
7
7
  // which we want to avoid, both b/c of the dist size increase &
8
8
  // the security concerns of including the versions of the dependencies
9
- const sdkVersion = '16.9.2';
9
+ const sdkVersion = '16.9.4';
10
10
  exports.default = sdkVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balena-sdk",
3
- "version": "16.9.2",
3
+ "version": "16.9.4",
4
4
  "description": "The Balena JavaScript SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -120,6 +120,6 @@
120
120
  "tslib": "^2.1.0"
121
121
  },
122
122
  "versionist": {
123
- "publishedAt": "2021-12-28T17:20:53.079Z"
123
+ "publishedAt": "2021-12-29T14:38:42.067Z"
124
124
  }
125
125
  }