@hot-updater/plugin-core 0.20.13 → 0.20.15

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/dist/index.cjs CHANGED
@@ -17777,9 +17777,34 @@ function removeBundleInternalKeys(bundle) {
17777
17777
  const { _updateJsonKey, _oldUpdateJsonKey,...pureBundle } = bundle;
17778
17778
  return pureBundle;
17779
17779
  }
17780
+ function normalizeTargetAppVersion(version) {
17781
+ if (!version) return null;
17782
+ return version.replace(/\s+/g, "");
17783
+ }
17780
17784
  function isExactVersion(version) {
17781
17785
  if (!version) return false;
17782
- return semver.default.valid(version) !== null;
17786
+ const normalized = normalizeTargetAppVersion(version);
17787
+ if (!normalized) return false;
17788
+ return semver.default.valid(normalized) !== null;
17789
+ }
17790
+ /**
17791
+ * Get all normalized semver versions for a version string.
17792
+ * This handles the case where clients may request with different normalized forms.
17793
+ *
17794
+ * Examples:
17795
+ * - "1.0.0" generates ["1.0.0", "1.0", "1"]
17796
+ * - "2.1.0" generates ["2.1.0", "2.1"]
17797
+ * - "1.2.3" generates ["1.2.3"]
17798
+ */
17799
+ function getSemverNormalizedVersions(version) {
17800
+ const normalized = normalizeTargetAppVersion(version) || version;
17801
+ const coerced = semver.default.coerce(normalized);
17802
+ if (!coerced) return [normalized];
17803
+ const versions = /* @__PURE__ */ new Set();
17804
+ versions.add(coerced.version);
17805
+ if (coerced.patch === 0) versions.add(`${coerced.major}.${coerced.minor}`);
17806
+ if (coerced.minor === 0 && coerced.patch === 0) versions.add(`${coerced.major}`);
17807
+ return Array.from(versions);
17783
17808
  }
17784
17809
  /**
17785
17810
  *
@@ -17894,7 +17919,7 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17894
17919
  for (const { operation, data } of changedSets) {
17895
17920
  if (data.targetAppVersion !== void 0) isTargetAppVersionChanged = true;
17896
17921
  if (operation === "insert") {
17897
- const target = data.targetAppVersion ?? data.fingerprintHash;
17922
+ const target = normalizeTargetAppVersion(data.targetAppVersion) ?? data.fingerprintHash;
17898
17923
  if (!target) throw new Error("target not found");
17899
17924
  const key = `${data.channel}/${data.platform}/${target}/update.json`;
17900
17925
  const bundleWithKey = {
@@ -17908,7 +17933,10 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17908
17933
  pathsToInvalidate.add(`/${key}`);
17909
17934
  if (data.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${data.platform}/${data.fingerprintHash}/${data.channel}/*`);
17910
17935
  else if (data.targetAppVersion) if (!isExactVersion(data.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/*`);
17911
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/${data.targetAppVersion}/${data.channel}/*`);
17936
+ else {
17937
+ const normalizedVersions = getSemverNormalizedVersions(data.targetAppVersion);
17938
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/${version}/${data.channel}/*`);
17939
+ }
17912
17940
  continue;
17913
17941
  }
17914
17942
  if (operation === "delete") {
@@ -17923,7 +17951,10 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17923
17951
  pathsToInvalidate.add(`/${key}`);
17924
17952
  if (bundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle$1.platform}/${bundle$1.fingerprintHash}/${bundle$1.channel}/*`);
17925
17953
  else if (bundle$1.targetAppVersion) if (!isExactVersion(bundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/*`);
17926
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/${bundle$1.targetAppVersion}/${bundle$1.channel}/*`);
17954
+ else {
17955
+ const normalizedVersions = getSemverNormalizedVersions(bundle$1.targetAppVersion);
17956
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/${version}/${bundle$1.channel}/*`);
17957
+ }
17927
17958
  continue;
17928
17959
  }
17929
17960
  let bundle = pendingBundlesMap.get(data.id);
@@ -17932,7 +17963,7 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17932
17963
  if (operation === "update") {
17933
17964
  const newChannel = data.channel !== void 0 ? data.channel : bundle.channel;
17934
17965
  const newPlatform = data.platform !== void 0 ? data.platform : bundle.platform;
17935
- const target = data.fingerprintHash ?? bundle.fingerprintHash ?? data.targetAppVersion ?? bundle.targetAppVersion;
17966
+ const target = data.fingerprintHash ?? bundle.fingerprintHash ?? normalizeTargetAppVersion(data.targetAppVersion) ?? normalizeTargetAppVersion(bundle.targetAppVersion);
17936
17967
  if (!target) throw new Error("target not found");
17937
17968
  const newKey = `${newChannel}/${newPlatform}/${target}/update.json`;
17938
17969
  if (newKey !== bundle._updateJsonKey) {
@@ -17962,16 +17993,25 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17962
17993
  }
17963
17994
  if (bundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17964
17995
  else {
17965
- pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${oldChannel}/*`);
17966
- pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${newChannel$1}/*`);
17996
+ const normalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
17997
+ for (const version of normalizedVersions) {
17998
+ pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${oldChannel}/*`);
17999
+ pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${newChannel$1}/*`);
18000
+ }
17967
18001
  }
17968
18002
  }
17969
18003
  if (updatedBundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${updatedBundle$1.fingerprintHash}/${updatedBundle$1.channel}/*`);
17970
18004
  else if (updatedBundle$1.targetAppVersion) {
17971
18005
  if (!isExactVersion(updatedBundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/*`);
17972
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/${updatedBundle$1.targetAppVersion}/${updatedBundle$1.channel}/*`);
18006
+ else {
18007
+ const normalizedVersions = getSemverNormalizedVersions(updatedBundle$1.targetAppVersion);
18008
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/${version}/${updatedBundle$1.channel}/*`);
18009
+ }
17973
18010
  if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle$1.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17974
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${bundle.channel}/*`);
18011
+ else {
18012
+ const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
18013
+ for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
18014
+ }
17975
18015
  }
17976
18016
  continue;
17977
18017
  }
@@ -17988,9 +18028,15 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17988
18028
  if (updatedBundle.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${updatedBundle.platform}/${updatedBundle.fingerprintHash}/${updatedBundle.channel}/*`);
17989
18029
  else if (updatedBundle.targetAppVersion) {
17990
18030
  if (!isExactVersion(updatedBundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/*`);
17991
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${updatedBundle.targetAppVersion}/${updatedBundle.channel}/*`);
18031
+ else {
18032
+ const normalizedVersions = getSemverNormalizedVersions(updatedBundle.targetAppVersion);
18033
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${version}/${updatedBundle.channel}/*`);
18034
+ }
17992
18035
  if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17993
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${bundle.channel}/*`);
18036
+ else {
18037
+ const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
18038
+ for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
18039
+ }
17994
18040
  }
17995
18041
  }
17996
18042
  }
@@ -18017,7 +18063,9 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
18017
18063
  for (const path$7 of updatedPaths) updatedTargetFilePaths.add(path$7);
18018
18064
  }
18019
18065
  for (const path$7 of updatedTargetFilePaths) pathsToInvalidate.add(path$7);
18020
- await invalidatePaths(context, Array.from(pathsToInvalidate));
18066
+ const encondedPaths = /* @__PURE__ */ new Set();
18067
+ for (const path$7 of pathsToInvalidate) encondedPaths.add(encodeURI(path$7));
18068
+ await invalidatePaths(context, Array.from(encondedPaths));
18021
18069
  pendingBundlesMap.clear();
18022
18070
  hooks?.onDatabaseUpdated?.();
18023
18071
  }
package/dist/index.js CHANGED
@@ -17768,9 +17768,34 @@ function removeBundleInternalKeys(bundle) {
17768
17768
  const { _updateJsonKey, _oldUpdateJsonKey,...pureBundle } = bundle;
17769
17769
  return pureBundle;
17770
17770
  }
17771
+ function normalizeTargetAppVersion(version) {
17772
+ if (!version) return null;
17773
+ return version.replace(/\s+/g, "");
17774
+ }
17771
17775
  function isExactVersion(version) {
17772
17776
  if (!version) return false;
17773
- return semver.valid(version) !== null;
17777
+ const normalized = normalizeTargetAppVersion(version);
17778
+ if (!normalized) return false;
17779
+ return semver.valid(normalized) !== null;
17780
+ }
17781
+ /**
17782
+ * Get all normalized semver versions for a version string.
17783
+ * This handles the case where clients may request with different normalized forms.
17784
+ *
17785
+ * Examples:
17786
+ * - "1.0.0" generates ["1.0.0", "1.0", "1"]
17787
+ * - "2.1.0" generates ["2.1.0", "2.1"]
17788
+ * - "1.2.3" generates ["1.2.3"]
17789
+ */
17790
+ function getSemverNormalizedVersions(version) {
17791
+ const normalized = normalizeTargetAppVersion(version) || version;
17792
+ const coerced = semver.coerce(normalized);
17793
+ if (!coerced) return [normalized];
17794
+ const versions = /* @__PURE__ */ new Set();
17795
+ versions.add(coerced.version);
17796
+ if (coerced.patch === 0) versions.add(`${coerced.major}.${coerced.minor}`);
17797
+ if (coerced.minor === 0 && coerced.patch === 0) versions.add(`${coerced.major}`);
17798
+ return Array.from(versions);
17774
17799
  }
17775
17800
  /**
17776
17801
  *
@@ -17885,7 +17910,7 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17885
17910
  for (const { operation, data } of changedSets) {
17886
17911
  if (data.targetAppVersion !== void 0) isTargetAppVersionChanged = true;
17887
17912
  if (operation === "insert") {
17888
- const target = data.targetAppVersion ?? data.fingerprintHash;
17913
+ const target = normalizeTargetAppVersion(data.targetAppVersion) ?? data.fingerprintHash;
17889
17914
  if (!target) throw new Error("target not found");
17890
17915
  const key = `${data.channel}/${data.platform}/${target}/update.json`;
17891
17916
  const bundleWithKey = {
@@ -17899,7 +17924,10 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17899
17924
  pathsToInvalidate.add(`/${key}`);
17900
17925
  if (data.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${data.platform}/${data.fingerprintHash}/${data.channel}/*`);
17901
17926
  else if (data.targetAppVersion) if (!isExactVersion(data.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/*`);
17902
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/${data.targetAppVersion}/${data.channel}/*`);
17927
+ else {
17928
+ const normalizedVersions = getSemverNormalizedVersions(data.targetAppVersion);
17929
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/${version}/${data.channel}/*`);
17930
+ }
17903
17931
  continue;
17904
17932
  }
17905
17933
  if (operation === "delete") {
@@ -17914,7 +17942,10 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17914
17942
  pathsToInvalidate.add(`/${key}`);
17915
17943
  if (bundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle$1.platform}/${bundle$1.fingerprintHash}/${bundle$1.channel}/*`);
17916
17944
  else if (bundle$1.targetAppVersion) if (!isExactVersion(bundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/*`);
17917
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/${bundle$1.targetAppVersion}/${bundle$1.channel}/*`);
17945
+ else {
17946
+ const normalizedVersions = getSemverNormalizedVersions(bundle$1.targetAppVersion);
17947
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/${version}/${bundle$1.channel}/*`);
17948
+ }
17918
17949
  continue;
17919
17950
  }
17920
17951
  let bundle = pendingBundlesMap.get(data.id);
@@ -17923,7 +17954,7 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17923
17954
  if (operation === "update") {
17924
17955
  const newChannel = data.channel !== void 0 ? data.channel : bundle.channel;
17925
17956
  const newPlatform = data.platform !== void 0 ? data.platform : bundle.platform;
17926
- const target = data.fingerprintHash ?? bundle.fingerprintHash ?? data.targetAppVersion ?? bundle.targetAppVersion;
17957
+ const target = data.fingerprintHash ?? bundle.fingerprintHash ?? normalizeTargetAppVersion(data.targetAppVersion) ?? normalizeTargetAppVersion(bundle.targetAppVersion);
17927
17958
  if (!target) throw new Error("target not found");
17928
17959
  const newKey = `${newChannel}/${newPlatform}/${target}/update.json`;
17929
17960
  if (newKey !== bundle._updateJsonKey) {
@@ -17953,16 +17984,25 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17953
17984
  }
17954
17985
  if (bundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17955
17986
  else {
17956
- pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${oldChannel}/*`);
17957
- pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${newChannel$1}/*`);
17987
+ const normalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
17988
+ for (const version of normalizedVersions) {
17989
+ pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${oldChannel}/*`);
17990
+ pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${newChannel$1}/*`);
17991
+ }
17958
17992
  }
17959
17993
  }
17960
17994
  if (updatedBundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${updatedBundle$1.fingerprintHash}/${updatedBundle$1.channel}/*`);
17961
17995
  else if (updatedBundle$1.targetAppVersion) {
17962
17996
  if (!isExactVersion(updatedBundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/*`);
17963
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/${updatedBundle$1.targetAppVersion}/${updatedBundle$1.channel}/*`);
17997
+ else {
17998
+ const normalizedVersions = getSemverNormalizedVersions(updatedBundle$1.targetAppVersion);
17999
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/${version}/${updatedBundle$1.channel}/*`);
18000
+ }
17964
18001
  if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle$1.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17965
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${bundle.channel}/*`);
18002
+ else {
18003
+ const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
18004
+ for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
18005
+ }
17966
18006
  }
17967
18007
  continue;
17968
18008
  }
@@ -17979,9 +18019,15 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
17979
18019
  if (updatedBundle.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${updatedBundle.platform}/${updatedBundle.fingerprintHash}/${updatedBundle.channel}/*`);
17980
18020
  else if (updatedBundle.targetAppVersion) {
17981
18021
  if (!isExactVersion(updatedBundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/*`);
17982
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${updatedBundle.targetAppVersion}/${updatedBundle.channel}/*`);
18022
+ else {
18023
+ const normalizedVersions = getSemverNormalizedVersions(updatedBundle.targetAppVersion);
18024
+ for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${version}/${updatedBundle.channel}/*`);
18025
+ }
17983
18026
  if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
17984
- else pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${bundle.targetAppVersion}/${bundle.channel}/*`);
18027
+ else {
18028
+ const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
18029
+ for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
18030
+ }
17985
18031
  }
17986
18032
  }
17987
18033
  }
@@ -18008,7 +18054,9 @@ const createBlobDatabasePlugin = ({ name, getContext, listObjects, loadObject, u
18008
18054
  for (const path$4 of updatedPaths) updatedTargetFilePaths.add(path$4);
18009
18055
  }
18010
18056
  for (const path$4 of updatedTargetFilePaths) pathsToInvalidate.add(path$4);
18011
- await invalidatePaths(context, Array.from(pathsToInvalidate));
18057
+ const encondedPaths = /* @__PURE__ */ new Set();
18058
+ for (const path$4 of pathsToInvalidate) encondedPaths.add(encodeURI(path$4));
18059
+ await invalidatePaths(context, Array.from(encondedPaths));
18012
18060
  pendingBundlesMap.clear();
18013
18061
  hooks?.onDatabaseUpdated?.();
18014
18062
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/plugin-core",
3
- "version": "0.20.13",
3
+ "version": "0.20.15",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "fast-glob": "3.3.3",
48
48
  "oxc-transform": "0.82.1",
49
49
  "semver": "^7.7.2",
50
- "@hot-updater/core": "0.20.13"
50
+ "@hot-updater/core": "0.20.15"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^20",
@@ -58,7 +58,7 @@
58
58
  "picocolors": "1.1.1",
59
59
  "typescript": "5.8.2",
60
60
  "workspace-tools": "^0.36.4",
61
- "@hot-updater/plugin-core": "0.20.13"
61
+ "@hot-updater/plugin-core": "0.20.15"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "tsdown",