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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## 16.9.4 - 2021-12-29
8
+
9
+ * os: Avoid mutating the args in getAvailableOsVersions & getAllOsVersion [Thodoris Greasidis]
10
+
11
+ ## 16.9.3 - 2021-12-28
12
+
13
+ * os: Replace semver normalization with balena-semver [Thodoris Greasidis]
14
+
7
15
  ## 16.9.2 - 2021-12-28
8
16
 
9
17
  * Stop relying on the balena-pine module [Thodoris Greasidis]
@@ -9560,7 +9560,9 @@ const releaseSelectedFields = (0, types_1.toWritable)([
9560
9560
  'known_issue_list',
9561
9561
  'raw_version',
9562
9562
  ]);
9563
- const BALENAOS_VERSION_REGEX = /v?\d+\.\d+\.\d+(\.rev\d+)?((\-|\+).+)?/;
9563
+ const sortVersions = (a, b) => {
9564
+ return bSemver.rcompare(a.rawVersion, b.rawVersion);
9565
+ };
9564
9566
  const getOsModel = function (deps, opts) {
9565
9567
  const { pine, request, pubsub } = deps;
9566
9568
  const { apiUrl, isBrowser } = opts;
@@ -9572,9 +9574,6 @@ const getOsModel = function (deps, opts) {
9572
9574
  () => require('../util/device-types'));
9573
9575
  const hupActionHelper = once(() => require('../util/device-actions/os-update/utils').hupActionHelper);
9574
9576
  const authDependentMemoizer = (0, cache_1.getAuthDependentMemoize)(pubsub);
9575
- const sortVersions = (a, b) => {
9576
- return bSemver.rcompare(a.rawVersion, b.rawVersion);
9577
- };
9578
9577
  const tagsToDictionary = (tags) => {
9579
9578
  const result = {};
9580
9579
  for (const { tag_key, value } of tags) {
@@ -9701,14 +9700,12 @@ const getOsModel = function (deps, opts) {
9701
9700
  const appTags = getOsAppTags((_c = hostApp.application_tag) !== null && _c !== void 0 ? _c : []);
9702
9701
  osVersionsByDeviceType[hostAppDeviceType].push(..._getOsVersionsFromReleases((_d = hostApp.owns__release) !== null && _d !== void 0 ? _d : [], appTags));
9703
9702
  });
9704
- return osVersionsByDeviceType;
9705
- };
9706
- // This mutates the passed object.
9707
- const _transformVersionSets = (osVersionsByDeviceType) => {
9703
+ // transform version sets
9708
9704
  Object.keys(osVersionsByDeviceType).forEach((deviceType) => {
9709
9705
  osVersionsByDeviceType[deviceType].sort(sortVersions);
9710
- const recommendedPerOsType = {};
9706
+ // TODO: Drop in next major
9711
9707
  // 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.
9708
+ const recommendedPerOsType = {};
9712
9709
  osVersionsByDeviceType[deviceType].forEach((version) => {
9713
9710
  if (!recommendedPerOsType[version.osType]) {
9714
9711
  if (version.variant !== 'dev' &&
@@ -9728,7 +9725,7 @@ const getOsModel = function (deps, opts) {
9728
9725
  };
9729
9726
  const _getAllOsVersions = (deviceTypes, options) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
9730
9727
  const hostapps = yield _getOsVersions(deviceTypes, options);
9731
- return yield _transformVersionSets(_transformHostApps(hostapps));
9728
+ return yield _transformHostApps(hostapps);
9732
9729
  });
9733
9730
  const _memoizedGetAllOsVersions = authDependentMemoizer((deviceTypes, listedByDefault) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
9734
9731
  return yield _getAllOsVersions(deviceTypes, listedByDefault
@@ -9764,7 +9761,7 @@ const getOsModel = function (deps, opts) {
9764
9761
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
9765
9762
  const singleDeviceTypeArg = typeof deviceTypes === 'string' ? deviceTypes : false;
9766
9763
  deviceTypes = Array.isArray(deviceTypes) ? deviceTypes : [deviceTypes];
9767
- const versionsByDt = yield _memoizedGetAllOsVersions(deviceTypes.sort(), true);
9764
+ const versionsByDt = yield _memoizedGetAllOsVersions(deviceTypes.slice().sort(), true);
9768
9765
  return singleDeviceTypeArg
9769
9766
  ? (_a = versionsByDt[singleDeviceTypeArg]) !== null && _a !== void 0 ? _a : []
9770
9767
  : versionsByDt;
@@ -9798,7 +9795,7 @@ const getOsModel = function (deps, opts) {
9798
9795
  const singleDeviceTypeArg = typeof deviceTypes === 'string' ? deviceTypes : false;
9799
9796
  deviceTypes = Array.isArray(deviceTypes) ? deviceTypes : [deviceTypes];
9800
9797
  const versionsByDt = options == null
9801
- ? yield _memoizedGetAllOsVersions(deviceTypes.sort(), null)
9798
+ ? yield _memoizedGetAllOsVersions(deviceTypes.slice().sort(), null)
9802
9799
  : yield _getAllOsVersions(deviceTypes, options);
9803
9800
  return singleDeviceTypeArg
9804
9801
  ? (_a = versionsByDt[singleDeviceTypeArg]) !== null && _a !== void 0 ? _a : []
@@ -9855,23 +9852,12 @@ const getOsModel = function (deps, opts) {
9855
9852
  return v;
9856
9853
  }
9857
9854
  const vNormalized = v[0] === 'v' ? v.substring(1) : v;
9858
- if (!BALENAOS_VERSION_REGEX.test(vNormalized)) {
9855
+ // We still don't want to allow `balenaOS` prefixes, which balena-semver allows.
9856
+ if (!bSemver.valid(vNormalized) || !/^\d/.test(vNormalized)) {
9859
9857
  throw new Error(`Invalid semver version: ${v}`);
9860
9858
  }
9861
9859
  return vNormalized;
9862
9860
  };
9863
- const fixNonSemver = (version) => {
9864
- if (version == null) {
9865
- return version;
9866
- }
9867
- return version.replace(/\.rev(\d+)/, '+FIXED-rev$1');
9868
- };
9869
- const unfixNonSemver = (version) => {
9870
- if (version == null) {
9871
- return version;
9872
- }
9873
- return version.replace(/\+FIXED-rev(\d+)/, '.rev$1');
9874
- };
9875
9861
  /**
9876
9862
  * @summary Get the max OS version satisfying the given range.
9877
9863
  * @description Utility method exported for testability.
@@ -9892,16 +9878,13 @@ const getOsModel = function (deps, opts) {
9892
9878
  return (_d = ((_c = osVersions.find((v) => v.isRecommended)) !== null && _c !== void 0 ? _c : osVersions[0])) === null || _d === void 0 ? void 0 : _d.rawVersion;
9893
9879
  }
9894
9880
  const versions = osVersions.map((v) => v.rawVersion);
9895
- const semverVersions = versions.map(fixNonSemver);
9896
- // TODO: Once we integrate balena-semver, balena-semver should learn to handle this itself
9897
- const semverVersionOrRange = fixNonSemver(versionOrRange);
9898
- if (semverVersions.includes(semverVersionOrRange)) {
9881
+ if (versions.includes(versionOrRange)) {
9899
9882
  // If the _exact_ version you're looking for exists, it's not a range, and
9900
9883
  // we should return it exactly, not any old equivalent version.
9901
- return unfixNonSemver(semverVersionOrRange);
9884
+ return versionOrRange;
9902
9885
  }
9903
- const maxVersion = bSemver.maxSatisfying(semverVersions, semverVersionOrRange);
9904
- return unfixNonSemver(maxVersion);
9886
+ const maxVersion = bSemver.maxSatisfying(versions, versionOrRange);
9887
+ return maxVersion;
9905
9888
  };
9906
9889
  /**
9907
9890
  * @summary Get OS download size estimate
@@ -12115,7 +12098,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12115
12098
  // being embedded in the dist of the consumer project
12116
12099
  // which we want to avoid, both b/c of the dist size increase &
12117
12100
  // the security concerns of including the versions of the dependencies
12118
- const sdkVersion = '16.9.2';
12101
+ const sdkVersion = '16.9.4';
12119
12102
  exports.default = sdkVersion;
12120
12103
 
12121
12104
  },{}],47:[function(require,module,exports){