@hot-updater/azure 1.2.0-rc.51 → 1.2.0-rc.52

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.
@@ -5140,6 +5140,64 @@ function canonicalStringify(value) {
5140
5140
  const record = value;
5141
5141
  return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalStringify(record[key])}`).join(",")}}`;
5142
5142
  }
5143
+ const BOUND_SHAPE = {
5144
+ inclusive: null,
5145
+ version: null
5146
+ };
5147
+ const COMPILED_CATALOG_SHAPE = {
5148
+ fallbackPolicy: null,
5149
+ schemaVersion: null,
5150
+ strategy: null,
5151
+ releaseIndexes: null,
5152
+ rollbackReleaseIndexes: null,
5153
+ segments: {
5154
+ lower: BOUND_SHAPE,
5155
+ upper: BOUND_SHAPE,
5156
+ releaseIndexes: null,
5157
+ rollbackReleaseIndexes: null
5158
+ },
5159
+ releaseDescriptors: {
5160
+ releaseId: null,
5161
+ kind: null,
5162
+ bundleId: null,
5163
+ rolloutCohortCount: null,
5164
+ targetCohorts: null,
5165
+ shouldForceUpdate: null,
5166
+ message: null,
5167
+ label: null
5168
+ }
5169
+ };
5170
+ function readCompiledCatalogPayload(payload) {
5171
+ let fromLaterRelease = false;
5172
+ const known = (value, shape) => {
5173
+ if (Array.isArray(value)) return value.map((item) => known(item, shape));
5174
+ if (value === null || typeof value !== "object") return value;
5175
+ const entries = Object.entries(value).filter(([key]) => {
5176
+ if (Object.hasOwn(shape, key)) return true;
5177
+ fromLaterRelease = true;
5178
+ return false;
5179
+ });
5180
+ return Object.fromEntries(entries.map(([key, entry]) => {
5181
+ const inner = shape[key];
5182
+ return [key, inner === null ? entry : known(entry, inner)];
5183
+ }));
5184
+ };
5185
+ let parsed;
5186
+ try {
5187
+ parsed = JSON.parse(payload);
5188
+ } catch {
5189
+ parsed = null;
5190
+ }
5191
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {
5192
+ canonicalPayload: payload,
5193
+ fromLaterRelease: false
5194
+ };
5195
+ if ("schemaVersion" in parsed && typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 1) fromLaterRelease = true;
5196
+ return {
5197
+ canonicalPayload: canonicalStringify(known(parsed, COMPILED_CATALOG_SHAPE)),
5198
+ fromLaterRelease
5199
+ };
5200
+ }
5143
5201
  async function compileReleaseCatalog(input) {
5144
5202
  const releases = validateReleases(input.releases, input.strategy);
5145
5203
  const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
@@ -5643,6 +5701,18 @@ const SETTINGS_TABLE = {
5643
5701
  };
5644
5702
  const ENGINE_SCHEMA_KEY = "schema.engine";
5645
5703
  const CORE_SCHEMA_KEY = "schema.core";
5704
+ const compareVersions = (left, right) => {
5705
+ const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
5706
+ const [a, b] = [parse(left), parse(right)];
5707
+ if ([...a, ...b].some(Number.isNaN)) return NaN;
5708
+ for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
5709
+ const difference = (a[index] ?? 0) - (b[index] ?? 0);
5710
+ if (difference !== 0) return difference;
5711
+ }
5712
+ return 0;
5713
+ };
5714
+ const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
5715
+ const newerMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is "${found}"; expected "${expected}". The database was migrated by Hot Updater ${found}: upgrade hot-updater and the @hot-updater packages to ${found} or later.`;
5646
5716
  const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
5647
5717
  const MIGRATE_SCHEMA_FIX = "Run `npx hot-updater doctor` in the project whose hot-updater.config.ts names this database: it names the command that migrates it. In a server project, `hot-updater db migrate` migrates the database its server file names.";
5648
5718
  const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}". ${MIGRATE_SCHEMA_FIX}`;
@@ -5659,7 +5729,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
5659
5729
  constructor(adapterName, currentVersion, setting, options) {
5660
5730
  const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
5661
5731
  const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
5662
- super(setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
5732
+ const newer = newerCore(settings);
5733
+ super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
5663
5734
  this.adapterName = adapterName;
5664
5735
  this.currentVersion = currentVersion;
5665
5736
  this.setting = setting;
@@ -6306,16 +6377,6 @@ const refuseV0Database = (adapterName, stored) => {
6306
6377
  if (typeof version !== "string" || stored.has("schema.engine")) return;
6307
6378
  throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
6308
6379
  };
6309
- const compareVersions = (left, right) => {
6310
- const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
6311
- const [a, b] = [parse(left), parse(right)];
6312
- if ([...a, ...b].some(Number.isNaN)) return NaN;
6313
- for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
6314
- const difference = (a[index] ?? 0) - (b[index] ?? 0);
6315
- if (difference !== 0) return difference;
6316
- }
6317
- return 0;
6318
- };
6319
6380
  const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
6320
6381
  const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
6321
6382
  const newer = ordered.flatMap((key) => {
@@ -8423,7 +8484,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
8423
8484
  };
8424
8485
  //#endregion
8425
8486
  //#region ../../packages/server/dist/version.mjs
8426
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.51";
8487
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.52";
8427
8488
  //#endregion
8428
8489
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
8429
8490
  const createVersionRouteHandlers = (plugins = []) => {
@@ -10625,12 +10686,16 @@ const readCatalog = async (tx, scopeKey) => {
10625
10686
  catalog: row === null ? null : toCatalogRow(row)
10626
10687
  };
10627
10688
  };
10689
+ const refuseLaterCatalog = (scope, catalog) => {
10690
+ if (catalog !== null && readCompiledCatalogPayload(catalog.payload).fromLaterRelease) fail$1("CATALOG_FROM_LATER_RELEASE", `The ${scope.platform} release catalog of channel "${scope.channelName}" was written by a later Hot Updater.\nUpgrade hot-updater, then try again.`);
10691
+ };
10628
10692
  const assertHistory = (stored, hasReleases) => {
10629
10693
  if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
10630
10694
  };
10631
10695
  const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
10632
10696
  checkScope(scope);
10633
10697
  const stored = await readCatalog(tx, scope.scopeKey);
10698
+ refuseLaterCatalog(scope, stored.catalog);
10634
10699
  let enabled = await enabledReleases(tx, scope.scopeKey);
10635
10700
  if (bundle !== void 0) {
10636
10701
  insertBundle(tx, bundle.row);
@@ -10696,7 +10761,12 @@ const changeReleases = (db, inputs) => {
10696
10761
  return results;
10697
10762
  });
10698
10763
  };
10699
- const isCurrent = (scope, current, compilation) => current.strategy === scope.strategy && current.channel_id === scope.channelId && current.channel_key === encodeChannelKey(scope.channelName) && current.platform === scope.platform && current.fingerprint_hash === scope.fingerprintHash && current.catalog_hash === compilation.catalogHash;
10764
+ const isCurrent = (scope, current, compilation) => {
10765
+ if (current.strategy !== scope.strategy || current.channel_id !== scope.channelId || current.channel_key !== encodeChannelKey(scope.channelName) || current.platform !== scope.platform || current.fingerprint_hash !== scope.fingerprintHash) return false;
10766
+ if (current.catalog_hash === compilation.catalogHash) return true;
10767
+ const read = readCompiledCatalogPayload(current.payload);
10768
+ return read.fromLaterRelease && read.canonicalPayload === compilation.canonicalPayload;
10769
+ };
10700
10770
  const withoutLabels = (payload) => {
10701
10771
  const parsed = JSON.parse(payload);
10702
10772
  return JSON.stringify({
@@ -10744,6 +10814,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
10744
10814
  changed: false,
10745
10815
  diagnostics: compilation.diagnostics
10746
10816
  };
10817
+ refuseLaterCatalog(scope, current);
10747
10818
  const written = await writeCatalog(tx, scope, stored, enabled, updatedAtMs);
10748
10819
  return {
10749
10820
  catalog: written.catalog,
@@ -59034,7 +59105,6 @@ function azureBlobStorage(config) {
59034
59105
  const blob = (await container()).getBlockBlobClient(storageKey);
59035
59106
  if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
59036
59107
  else {
59037
- const { Readable } = await import("node:stream");
59038
59108
  const source = Readable.fromWeb(body);
59039
59109
  const aborted = new AbortController();
59040
59110
  let failure;
@@ -59043,12 +59113,15 @@ function azureBlobStorage(config) {
59043
59113
  aborted.abort(error);
59044
59114
  });
59045
59115
  try {
59046
- await blob.upload(source, contentLength, {
59116
+ await new BlockBlobClient(blob.url, newPipeline(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
59047
59117
  ...options,
59048
59118
  abortSignal: aborted.signal
59049
59119
  });
59050
59120
  } catch (error) {
59051
- throw failure ?? error;
59121
+ const status = failure === void 0 && error instanceof RestError ? error.statusCode : void 0;
59122
+ if (status === void 0) throw failure ?? error;
59123
+ const code = error.code;
59124
+ throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
59052
59125
  }
59053
59126
  }
59054
59127
  return { storageUri: createStorageUri({
package/dist/index.cjs CHANGED
@@ -127,8 +127,7 @@ function azureBlobStorage(config) {
127
127
  const blob = (await container()).getBlockBlobClient(storageKey);
128
128
  if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
129
129
  else {
130
- const { Readable } = await import("node:stream");
131
- const source = Readable.fromWeb(body);
130
+ const source = node_stream.Readable.fromWeb(body);
132
131
  const aborted = new AbortController();
133
132
  let failure;
134
133
  source.once("error", (error) => {
@@ -136,12 +135,15 @@ function azureBlobStorage(config) {
136
135
  aborted.abort(error);
137
136
  });
138
137
  try {
139
- await blob.upload(source, contentLength, {
138
+ await new _azure_storage_blob.BlockBlobClient(blob.url, (0, _azure_storage_blob.newPipeline)(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
140
139
  ...options,
141
140
  abortSignal: aborted.signal
142
141
  });
143
142
  } catch (error) {
144
- throw failure ?? error;
143
+ const status = failure === void 0 && error instanceof _azure_storage_blob.RestError ? error.statusCode : void 0;
144
+ if (status === void 0) throw failure ?? error;
145
+ const code = error.code;
146
+ throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
145
147
  }
146
148
  }
147
149
  return { storageUri: (0, _hot_updater_plugin_core.createStorageUri)({
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Readable } from "node:stream";
2
2
  import { isTokenCredential } from "@azure/core-auth";
3
- import { BlobSASPermissions, BlobServiceClient, RestError, StorageSharedKeyCredential, generateBlobSASQueryParameters } from "@azure/storage-blob";
3
+ import { BlobSASPermissions, BlobServiceClient, BlockBlobClient, RestError, StorageSharedKeyCredential, generateBlobSASQueryParameters, newPipeline } from "@azure/storage-blob";
4
4
  import { SETTINGS_TABLE, createEngineDatabase, createKvAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageUri, encodeKvKey, migrateCoreSchema, parseStorageUri, toolingTargetOf } from "@hot-updater/plugin-core";
5
5
  import { CosmosClient } from "@azure/cosmos";
6
6
  import { createHash } from "node:crypto";
@@ -126,7 +126,6 @@ function azureBlobStorage(config) {
126
126
  const blob = (await container()).getBlockBlobClient(storageKey);
127
127
  if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
128
128
  else {
129
- const { Readable } = await import("node:stream");
130
129
  const source = Readable.fromWeb(body);
131
130
  const aborted = new AbortController();
132
131
  let failure;
@@ -135,12 +134,15 @@ function azureBlobStorage(config) {
135
134
  aborted.abort(error);
136
135
  });
137
136
  try {
138
- await blob.upload(source, contentLength, {
137
+ await new BlockBlobClient(blob.url, newPipeline(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
139
138
  ...options,
140
139
  abortSignal: aborted.signal
141
140
  });
142
141
  } catch (error) {
143
- throw failure ?? error;
142
+ const status = failure === void 0 && error instanceof RestError ? error.statusCode : void 0;
143
+ if (status === void 0) throw failure ?? error;
144
+ const code = error.code;
145
+ throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
144
146
  }
145
147
  }
146
148
  return { storageUri: createStorageUri({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/azure",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.51",
4
+ "version": "1.2.0-rc.52",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "engines": {
7
7
  "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
@@ -44,10 +44,10 @@
44
44
  "@azure/identity": "4.14.0",
45
45
  "@azure/keyvault-secrets": "4.11.2",
46
46
  "@azure/storage-blob": "12.34.0",
47
- "@hot-updater/cli-tools": "1.2.0-rc.51",
48
- "@hot-updater/plugin-core": "1.2.0-rc.51",
49
- "@hot-updater/protocol": "1.2.0-rc.51",
50
- "@hot-updater/server": "1.2.0-rc.51"
47
+ "@hot-updater/cli-tools": "1.2.0-rc.52",
48
+ "@hot-updater/plugin-core": "1.2.0-rc.52",
49
+ "@hot-updater/protocol": "1.2.0-rc.52",
50
+ "@hot-updater/server": "1.2.0-rc.52"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@azure/functions": "4.16.5",
@@ -55,7 +55,7 @@
55
55
  "execa": "9.5.2",
56
56
  "jszip": "^3.10.1",
57
57
  "vitest": "4.1.4",
58
- "@hot-updater/test-utils": "1.2.0-rc.51"
58
+ "@hot-updater/test-utils": "1.2.0-rc.52"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "tsdown",