@hot-updater/azure 1.2.0-rc.56 → 1.2.0-rc.58

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.
@@ -4339,14 +4339,14 @@ function modularInverse(value, modulus) {
4339
4339
  if (r > 1) throw new Error(`No modular inverse for ${value} mod ${modulus}`);
4340
4340
  return positiveMod(t, modulus);
4341
4341
  }
4342
- function getRolloutShuffleParameters(bundleId) {
4343
- let multiplier = positiveMod(hashString(`${bundleId}:multiplier`), 997);
4342
+ function getRolloutShuffleParameters(releaseId) {
4343
+ let multiplier = positiveMod(hashString(`${releaseId}:multiplier`), 997);
4344
4344
  if (multiplier === 0) multiplier = 1;
4345
4345
  while (gcd(multiplier, NUMERIC_COHORT_SIZE) !== 1) {
4346
4346
  multiplier = positiveMod(multiplier + 1, NUMERIC_COHORT_SIZE);
4347
4347
  if (multiplier === 0) multiplier = 1;
4348
4348
  }
4349
- const offset = positiveMod(hashString(`${bundleId}:offset`), NUMERIC_COHORT_SIZE);
4349
+ const offset = positiveMod(hashString(`${releaseId}:offset`), NUMERIC_COHORT_SIZE);
4350
4350
  return {
4351
4351
  multiplier,
4352
4352
  offset,
@@ -4379,16 +4379,16 @@ function isValidCohort(cohort) {
4379
4379
  const normalized = normalizeCohortValue(cohort);
4380
4380
  return isNumericCohort(normalized) || isCustomCohort(normalized);
4381
4381
  }
4382
- function getNumericCohortRolloutPosition(bundleId, cohortValue) {
4382
+ function getNumericCohortRolloutPosition(releaseId, cohortValue) {
4383
4383
  if (cohortValue < 1 || cohortValue > 1e3) throw new Error(`Invalid numeric cohort: ${cohortValue}`);
4384
- const { offset, inverseMultiplier } = getRolloutShuffleParameters(bundleId);
4384
+ const { offset, inverseMultiplier } = getRolloutShuffleParameters(releaseId);
4385
4385
  return positiveMod(inverseMultiplier * (cohortValue - 1 - offset), NUMERIC_COHORT_SIZE);
4386
4386
  }
4387
- function getRolledOutNumericCohorts(bundleId, rolloutCohortCount) {
4387
+ function getRolledOutNumericCohorts(releaseId, rolloutCohortCount) {
4388
4388
  const normalizedRolloutCount = normalizeRolloutCohortCount(rolloutCohortCount);
4389
4389
  if (normalizedRolloutCount <= 0) return [];
4390
4390
  if (normalizedRolloutCount >= 1e3) return Array.from({ length: NUMERIC_COHORT_SIZE }, (_, index) => index + 1);
4391
- const { multiplier, offset } = getRolloutShuffleParameters(bundleId);
4391
+ const { multiplier, offset } = getRolloutShuffleParameters(releaseId);
4392
4392
  return Array.from({ length: normalizedRolloutCount }, (_, position) => positiveMod(multiplier * position + offset, NUMERIC_COHORT_SIZE)).map((zeroBasedCohort) => zeroBasedCohort + 1).sort((left, right) => left - right);
4393
4393
  }
4394
4394
  const RELEASE_CATALOG_FALLBACK_POLICY = "BUILTIN_IF_ACTIVE_INELIGIBLE";
@@ -8484,7 +8484,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
8484
8484
  };
8485
8485
  //#endregion
8486
8486
  //#region ../../packages/server/dist/version.mjs
8487
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.56";
8487
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.58";
8488
8488
  //#endregion
8489
8489
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
8490
8490
  const createVersionRouteHandlers = (plugins = []) => {
@@ -9222,7 +9222,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
9222
9222
  };
9223
9223
  //#endregion
9224
9224
  //#region ../../packages/server/dist/core/reads.mjs
9225
- const PAGE$4 = 500;
9225
+ const PAGE$5 = 500;
9226
9226
  const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
9227
9227
  const toBundleRow = pick$2([
9228
9228
  "id",
@@ -9313,7 +9313,7 @@ const createCoreReads = (db, storage) => {
9313
9313
  const page = await db.findMany("bundle_patches", {
9314
9314
  index: "byBundle",
9315
9315
  where: { bundle_id: row.id },
9316
- limit: Math.min(count - patches.length, PAGE$4),
9316
+ limit: Math.min(count - patches.length, PAGE$5),
9317
9317
  ...cursor === void 0 ? {} : { cursor }
9318
9318
  });
9319
9319
  patches.push(...page.rows.map(toPatchRow));
@@ -9517,7 +9517,7 @@ const createCoreReads = (db, storage) => {
9517
9517
  return (await drain$1((page) => db.findMany("channels", {
9518
9518
  index: "all",
9519
9519
  where: {},
9520
- limit: PAGE$4,
9520
+ limit: PAGE$5,
9521
9521
  ...page
9522
9522
  }))).map(toChannelRow);
9523
9523
  },
@@ -9873,7 +9873,7 @@ const createLabelAllocator = (tx, used, caughtUp) => {
9873
9873
  };
9874
9874
  };
9875
9875
  const FILL_BATCH = 25;
9876
- const PAGE$3 = 500;
9876
+ const PAGE$4 = 500;
9877
9877
  const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
9878
9878
  const id = labelSequenceId(channelId, platform);
9879
9879
  let labeled = 0;
@@ -9919,7 +9919,7 @@ const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {})
9919
9919
  channel_id: channelId,
9920
9920
  platform
9921
9921
  },
9922
- limit: PAGE$3,
9922
+ limit: PAGE$4,
9923
9923
  ...cursor === void 0 ? {} : { cursor }
9924
9924
  });
9925
9925
  const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
@@ -10080,7 +10080,7 @@ const pendingLabelPairs = async (db) => {
10080
10080
  };
10081
10081
  //#endregion
10082
10082
  //#region ../../packages/server/dist/core/writes.mjs
10083
- const PAGE$2 = 500;
10083
+ const PAGE$3 = 500;
10084
10084
  const countBundle = (tx, platform, delta) => {
10085
10085
  for (const key of [platform, "*"]) tx.aggregate("bundle_totals", { platform_key: key }, { bundles: delta });
10086
10086
  };
@@ -10107,7 +10107,7 @@ const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
10107
10107
  const page = await tx.findMany("bundle_patches", {
10108
10108
  index: "byBundle",
10109
10109
  where: { bundle_id: bundle.id },
10110
- limit: Math.min(count - seen, PAGE$2),
10110
+ limit: Math.min(count - seen, PAGE$3),
10111
10111
  ...cursor === void 0 ? {} : { cursor }
10112
10112
  });
10113
10113
  for (const stored of page.rows) {
@@ -10590,7 +10590,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
10590
10590
  });
10591
10591
  //#endregion
10592
10592
  //#region ../../packages/server/dist/core/releases.mjs
10593
- const PAGE$1 = 500;
10593
+ const PAGE$2 = 500;
10594
10594
  const fail$1 = (code, message) => {
10595
10595
  throw new ReleaseCatalogMutationError(code, message);
10596
10596
  };
@@ -10624,7 +10624,7 @@ const enabledIn = (scopeKey, cursor) => ({
10624
10624
  scope_key: scopeKey,
10625
10625
  enabled: true
10626
10626
  },
10627
- limit: PAGE$1,
10627
+ limit: PAGE$2,
10628
10628
  ...cursor === void 0 ? {} : { cursor }
10629
10629
  });
10630
10630
  const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
@@ -12360,7 +12360,8 @@ const createRequestHandler = ({ api, clientPolicy, privateResponses = false, rou
12360
12360
  let authenticated;
12361
12361
  try {
12362
12362
  authenticated = await clientPolicy.authenticate(request);
12363
- } catch {
12363
+ } catch (error) {
12364
+ console.error("Hot Updater client authentication failed:", error);
12364
12365
  return errorResponse("Service unavailable", 503);
12365
12366
  }
12366
12367
  if (!authenticated) return errorResponse("Unauthorized", 401);
@@ -12861,13 +12862,15 @@ const isLaunch = (row) => {
12861
12862
  const kinds = metadataOf(row).change?.kinds ?? [];
12862
12863
  return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null;
12863
12864
  };
12864
- const bundleRefsOf = (row) => {
12865
+ const sideRef = (key, releaseId, bundleId) => key === "release" ? releaseId ?? bundleId : bundleId;
12866
+ const bundleRefsOf = (row, key = "release") => {
12865
12867
  if (isFailedCheck(row) || isLateEvent(row)) return [];
12866
- if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
12867
- if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${row.to_bundle_id}`] : [];
12868
- return [`to:${row.to_bundle_id}`];
12868
+ if (row.type === "RECOVERED") return [`from:${sideRef(key, row.from_release_id, row.from_bundle_id)}`];
12869
+ if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${sideRef(key, row.to_release_id, row.to_bundle_id)}`] : [];
12870
+ return [`to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`];
12869
12871
  };
12870
- const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromBundleId}` : filter.type === "UNCHANGED" ? `on:${filter.toBundleId}` : `to:${filter.toBundleId}`;
12872
+ const outcomeRefsOf = (row, key = "release") => [...bundleRefsOf(row, key).map((ref) => [row.type, ref]), ...metadataOf(row).implied_download === true ? [["UPDATE_DOWNLOADED", row.type === "RECOVERED" ? `to:${sideRef(key, row.from_release_id, row.from_bundle_id)}` : `to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`]] : []];
12873
+ const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromReleaseId}` : filter.type === "UNCHANGED" ? `on:${filter.toReleaseId}` : `to:${filter.toReleaseId}`;
12871
12874
  const bundleEvents = (days) => defineTable({
12872
12875
  id: {
12873
12876
  type: "string",
@@ -13297,6 +13300,70 @@ const createInsightsSchema = ({ rawDays, dailyDays } = DEFAULT_INSIGHTS_RETENTIO
13297
13300
  };
13298
13301
  createInsightsSchema();
13299
13302
  //#endregion
13303
+ //#region ../insights/dist/server/backfill.mjs
13304
+ const PAGE$1 = 500;
13305
+ const BATCH = 25;
13306
+ const sameRefs = (stored, refs) => {
13307
+ const values = Array.isArray(stored) ? stored : [];
13308
+ return values.length === refs.length && values.every((value) => refs.includes(value));
13309
+ };
13310
+ const namesArtifact = (row) => {
13311
+ const byKey = (key) => bundleRefsOf(row, key);
13312
+ return sameRefs(row.bundle_ref, byKey("artifact")) && !sameRefs(row.bundle_ref, byKey("release"));
13313
+ };
13314
+ const backfillReleaseRefs = async (db, now, { rawDays }, { dryRun = false } = {}) => {
13315
+ const today = now() - now() % DAY_MS$1;
13316
+ let events = 0;
13317
+ const move = async (candidates) => {
13318
+ if (dryRun) {
13319
+ events += candidates.length;
13320
+ return;
13321
+ }
13322
+ const moved = await rewrite(candidates).catch(async (error) => {
13323
+ if (!(error instanceof DatabaseConstraintError) || error.reason !== "too_large" || candidates.length === 1) throw error;
13324
+ const half = Math.ceil(candidates.length / 2);
13325
+ await move(candidates.slice(0, half));
13326
+ await move(candidates.slice(half));
13327
+ return 0;
13328
+ });
13329
+ events += moved;
13330
+ };
13331
+ const rewrite = (candidates) => db.transaction(async (tx) => {
13332
+ const rows = await Promise.all(candidates.map(({ id }) => tx.findOne("bundle_events", { id })));
13333
+ let moved = 0;
13334
+ for (const row of rows) {
13335
+ if (row === null || !namesArtifact(row)) continue;
13336
+ tx.update("bundle_events", row, {});
13337
+ const outcome = (ref, delta) => tx.aggregate("insights_outcomes", {
13338
+ platform: row.platform,
13339
+ channel: row.channel,
13340
+ type: ref[0],
13341
+ bundle_ref: ref[1],
13342
+ bucket_start_ms: row.received_at_ms - row.received_at_ms % HOUR_MS$1
13343
+ }, { events: delta }, { shardBy: row.install_id });
13344
+ for (const ref of outcomeRefsOf(row, "artifact")) outcome(ref, -1);
13345
+ for (const ref of outcomeRefsOf(row, "release")) outcome(ref, 1);
13346
+ moved += 1;
13347
+ }
13348
+ return moved;
13349
+ });
13350
+ for (let day = today - rawDays * DAY_MS$1; day <= today; day += DAY_MS$1) {
13351
+ let cursor;
13352
+ do {
13353
+ const page = await db.findMany("bundle_events", {
13354
+ index: "byDay",
13355
+ where: { day },
13356
+ limit: PAGE$1,
13357
+ ...cursor === void 0 ? {} : { cursor }
13358
+ });
13359
+ const stale = page.rows.filter(namesArtifact);
13360
+ for (let start = 0; start < stale.length; start += BATCH) await move(stale.slice(start, start + BATCH));
13361
+ cursor = page.next;
13362
+ } while (cursor !== void 0);
13363
+ }
13364
+ return { events };
13365
+ };
13366
+ //#endregion
13300
13367
  //#region ../insights/dist/server/eventRow.mjs
13301
13368
  const CHANGE_KINDS = /* @__PURE__ */ new Set([
13302
13369
  "first_seen",
@@ -13374,7 +13441,7 @@ const isBundleFilter = (value, withKind = false) => {
13374
13441
  "type",
13375
13442
  ...withKind ? ["kind"] : []
13376
13443
  ];
13377
- return value.type === "RECOVERED" ? isText$1(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UPDATE_FAILED" || value.type === "UNCHANGED") && isText$1(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
13444
+ return value.type === "RECOVERED" ? isText$1(value.fromReleaseId) && hasOnlyKeys(value, [...keys, "fromReleaseId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UPDATE_FAILED" || value.type === "UNCHANGED") && isText$1(value.toReleaseId) && hasOnlyKeys(value, [...keys, "toReleaseId"]);
13378
13445
  };
13379
13446
  const isEventFilter = (value) => {
13380
13447
  if (!isRecord$3(value)) return false;
@@ -13469,20 +13536,24 @@ const createValidatedInsightsModel = (model) => ({
13469
13536
  if (!isRecord$3(input) || !hasOnlyKeys(input, [
13470
13537
  "platform",
13471
13538
  "channel",
13472
- "sinceMs",
13473
- "bundle"
13474
- ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundle !== void 0 && (!Array.isArray(input.bundle) || input.bundle.length < 1 || input.bundle.length > 2 || input.bundle.some((bundle) => !isRecord$3(bundle) || !hasOnlyKeys(bundle, [
13475
- "field",
13476
- "value",
13477
- "types"
13478
- ]) || bundle.field !== "from_bundle_id" && bundle.field !== "to_bundle_id" || !isText$1(bundle.value) || !Array.isArray(bundle.types) || bundle.types.length === 0 || bundle.types.some((type) => ![
13479
- "UNCHANGED",
13480
- "UPDATE_DOWNLOADED",
13481
- "UPDATE_APPLIED",
13482
- "RECOVERED"
13483
- ].includes(type))))) invalidQuery();
13539
+ "sinceMs"
13540
+ ]) || !hasScope(input) || !isTimestamp(input.sinceMs)) invalidQuery();
13484
13541
  return validateCount(await model.countLatestEvents(input));
13485
13542
  },
13543
+ async countReleaseInstallations(input) {
13544
+ if (!isRecord$3(input) || !hasOnlyKeys(input, [
13545
+ "platform",
13546
+ "channel",
13547
+ "sinceMs",
13548
+ "releaseId"
13549
+ ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || !isText$1(input.releaseId)) invalidQuery();
13550
+ const counts = await model.countReleaseInstallations(input);
13551
+ if (!isRecord$3(counts) || !hasOnlyKeys(counts, ["installations", "release"])) invalidResult();
13552
+ return {
13553
+ installations: validateCount(counts.installations),
13554
+ release: validateCount(counts.release)
13555
+ };
13556
+ },
13486
13557
  async countEvents(input) {
13487
13558
  if (!isRecord$3(input) || !hasOnlyKeys(input, [
13488
13559
  "filter",
@@ -13535,6 +13606,7 @@ const createInsightsModel = (api) => createValidatedInsightsModel({
13535
13606
  listEvents: api.listEvents,
13536
13607
  findLatestEvents: api.findLatestEvents,
13537
13608
  countLatestEvents: api.countLatestEvents,
13609
+ countReleaseInstallations: api.countReleaseInstallations,
13538
13610
  countEvents: api.countEvents,
13539
13611
  countEventSeries: api.countEventSeries,
13540
13612
  getReleaseActivity: api.getReleaseActivity,
@@ -13903,27 +13975,27 @@ const readScope$1 = (input) => {
13903
13975
  };
13904
13976
  const bundleFilter = (input) => {
13905
13977
  const scope = readScope$1(input);
13906
- const bundleId = requireString(input.bundleId, "bundle ID", MAX_EVENT_ID_LENGTH);
13978
+ const releaseId = requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
13907
13979
  switch (input.outcome) {
13908
13980
  case "downloaded": return {
13909
13981
  ...scope,
13910
13982
  type: "UPDATE_DOWNLOADED",
13911
- toBundleId: bundleId
13983
+ toReleaseId: releaseId
13912
13984
  };
13913
13985
  case "applied": return {
13914
13986
  ...scope,
13915
13987
  type: "UPDATE_APPLIED",
13916
- toBundleId: bundleId
13988
+ toReleaseId: releaseId
13917
13989
  };
13918
13990
  case "recovered": return {
13919
13991
  ...scope,
13920
13992
  type: "RECOVERED",
13921
- fromBundleId: bundleId
13993
+ fromReleaseId: releaseId
13922
13994
  };
13923
13995
  case "failed": return {
13924
13996
  ...scope,
13925
13997
  type: "UPDATE_FAILED",
13926
- toBundleId: bundleId
13998
+ toReleaseId: releaseId
13927
13999
  };
13928
14000
  default: throw new InsightsBadRequestError("Invalid Insights outcome.");
13929
14001
  }
@@ -13933,7 +14005,7 @@ const sameFilter = (left, right) => {
13933
14005
  switch (right.kind) {
13934
14006
  case "all": return true;
13935
14007
  case "installationMovement": return left.installId === right.installId;
13936
- case "bundle": return left.platform === right.platform && left.channel === right.channel && left.type === right.type && (right.type === "RECOVERED" ? left.fromBundleId === right.fromBundleId : left.toBundleId === right.toBundleId);
14008
+ case "bundle": return left.platform === right.platform && left.channel === right.channel && left.type === right.type && (right.type === "RECOVERED" ? left.fromReleaseId === right.fromReleaseId : left.toReleaseId === right.toReleaseId);
13937
14009
  }
13938
14010
  };
13939
14011
  const readEventCursor = (value, filter) => {
@@ -13970,7 +14042,7 @@ const assertEventRows = (rows, input) => {
13970
14042
  for (let index = 0; index < rows.length; index += 1) {
13971
14043
  const row = rows[index];
13972
14044
  const previous = rows[index - 1];
13973
- if (!row || typeof row.id !== "string" || !isUUIDv7(row.id) || !Number.isSafeInteger(row.received_at_ms) || row.received_at_ms >= input.beforeReceivedAtMs || row.received_at_ms < input.sinceMs || previous !== void 0 && compareEventNewest(previous, row) >= 0 || input.after !== void 0 && !isAfterEventCursor(row, input.after) || input.filter.kind === "installationMovement" && (row.install_id !== input.filter.installId || !isInsightsMovementEvent(row)) || input.filter.kind === "bundle" && (row.platform !== input.filter.platform || row.channel !== input.filter.channel || row.type !== input.filter.type || (input.filter.type === "RECOVERED" ? row.from_bundle_id !== input.filter.fromBundleId : row.to_bundle_id !== input.filter.toBundleId))) throw new Error("Insights database returned invalid event rows.");
14045
+ if (!row || typeof row.id !== "string" || !isUUIDv7(row.id) || !Number.isSafeInteger(row.received_at_ms) || row.received_at_ms >= input.beforeReceivedAtMs || row.received_at_ms < input.sinceMs || previous !== void 0 && compareEventNewest(previous, row) >= 0 || input.after !== void 0 && !isAfterEventCursor(row, input.after) || input.filter.kind === "installationMovement" && (row.install_id !== input.filter.installId || !isInsightsMovementEvent(row)) || input.filter.kind === "bundle" && (row.platform !== input.filter.platform || row.channel !== input.filter.channel || row.type !== input.filter.type || (input.filter.type === "RECOVERED" ? (row.from_release_id ?? row.from_bundle_id) !== input.filter.fromReleaseId : (row.to_release_id ?? row.to_bundle_id) !== input.filter.toReleaseId))) throw new Error("Insights database returned invalid event rows.");
13974
14046
  }
13975
14047
  };
13976
14048
  const toFailure = (failure) => ({
@@ -14009,6 +14081,7 @@ const eventDetails = ({ type, metadata }) => ({
14009
14081
  ...metadata.implied_download === true ? { impliedDownload: true } : {}
14010
14082
  });
14011
14083
  const toEventHistoryRow = (row) => ({
14084
+ ...row.from_release_id == null ? {} : { fromReleaseId: row.from_release_id },
14012
14085
  ...row.to_release_id == null ? {} : { toReleaseId: row.to_release_id },
14013
14086
  ...row.metadata.sdk_version == null ? {} : { sdkVersion: row.metadata.sdk_version },
14014
14087
  ...row.metadata.min_bundle_id === void 0 ? {} : { minBundleId: row.metadata.min_bundle_id },
@@ -14033,6 +14106,7 @@ const toInstallationRow = (row) => ({
14033
14106
  cohort: row.metadata.cohort,
14034
14107
  installId: row.install_id,
14035
14108
  lastKnownBundleId: row.type === "UPDATE_DOWNLOADED" ? row.from_bundle_id : row.to_bundle_id,
14109
+ lastKnownReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.from_release_id : row.to_release_id,
14036
14110
  pendingBundleId: row.type === "UPDATE_DOWNLOADED" ? row.to_bundle_id : null,
14037
14111
  pendingReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.to_release_id : null,
14038
14112
  latestStatus: row.type,
@@ -14155,46 +14229,33 @@ const createInsightsProvider = (model) => Object.freeze({
14155
14229
  measuredAtMs: Date.now()
14156
14230
  };
14157
14231
  };
14158
- const bundleId = input.bundleId === void 0 ? void 0 : requireString(input.bundleId, "bundle ID", MAX_EVENT_ID_LENGTH);
14159
- const reporting = measure(model.countLatestEvents({
14160
- ...scope,
14161
- sinceMs
14162
- }));
14163
- if (bundleId === void 0) return {
14232
+ const releaseId = input.releaseId === void 0 ? void 0 : requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
14233
+ if (releaseId === void 0) return {
14164
14234
  ...scope,
14165
14235
  window,
14166
14236
  sinceMs,
14167
14237
  beforeReceivedAtMs,
14168
- reportingInstallations: await reporting
14238
+ reportingInstallations: await measure(model.countLatestEvents({
14239
+ ...scope,
14240
+ sinceMs
14241
+ }))
14169
14242
  };
14243
+ const installations = model.countReleaseInstallations({
14244
+ ...scope,
14245
+ sinceMs,
14246
+ releaseId
14247
+ }).then(async (counts) => [await measure(Promise.resolve(counts.installations)), await measure(Promise.resolve(counts.release))]);
14170
14248
  const countOutcome = (outcome) => measure(model.countEvents({
14171
14249
  filter: bundleFilter({
14172
14250
  ...scope,
14173
- bundleId,
14251
+ releaseId,
14174
14252
  outcome
14175
14253
  }),
14176
14254
  sinceMs,
14177
14255
  beforeReceivedAtMs
14178
14256
  }));
14179
- const [reportingInstallations, bundleInstallations, downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
14180
- reporting,
14181
- measure(model.countLatestEvents({
14182
- ...scope,
14183
- sinceMs,
14184
- bundle: [{
14185
- field: "from_bundle_id",
14186
- value: bundleId,
14187
- types: ["UPDATE_DOWNLOADED"]
14188
- }, {
14189
- field: "to_bundle_id",
14190
- value: bundleId,
14191
- types: [
14192
- "UNCHANGED",
14193
- "UPDATE_APPLIED",
14194
- "RECOVERED"
14195
- ]
14196
- }]
14197
- })),
14257
+ const [[reportingInstallations, bundleInstallations], downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
14258
+ installations,
14198
14259
  countOutcome("downloaded"),
14199
14260
  countOutcome("applied"),
14200
14261
  countOutcome("recovered"),
@@ -14207,7 +14268,7 @@ const createInsightsProvider = (model) => Object.freeze({
14207
14268
  beforeReceivedAtMs,
14208
14269
  reportingInstallations,
14209
14270
  bundle: {
14210
- bundleId,
14271
+ releaseId,
14211
14272
  reportingInstallations: bundleInstallations,
14212
14273
  downloadedReports,
14213
14274
  appliedReports,
@@ -14332,8 +14393,6 @@ const gaugeSlot = (head) => ({
14332
14393
  releaseId: head.type === "UPDATE_DOWNLOADED" ? head.from_release_id : head.to_release_id,
14333
14394
  builtinBundleId: runningBuiltinBundleId(head)
14334
14395
  });
14335
- const PAIR_FIELD = "from_to";
14336
- const bundlePairKey = (from, to) => insightsKey(`${from.length}:${from}${to.length}:${to}`);
14337
14396
  const countHead = (tx, head, delta) => {
14338
14397
  const { bucket, releaseId, builtinBundleId } = gaugeSlot(head);
14339
14398
  const shardBy = head.install_id;
@@ -14352,26 +14411,6 @@ const countHead = (tx, head, delta) => {
14352
14411
  builtin_bundle_id: builtinBundleId,
14353
14412
  bucket_start_ms: bucket
14354
14413
  }, { latest_installations: delta }, { shardBy });
14355
- for (const field of ["from_bundle_id", "to_bundle_id"]) {
14356
- const bundleId = head[field];
14357
- if (bundleId === null) continue;
14358
- tx.aggregate("insights_latest_by_bundle", {
14359
- platform: head.platform,
14360
- channel: head.channel,
14361
- bundle_field: field,
14362
- bundle_id: bundleId,
14363
- type: head.type,
14364
- bucket_start_ms: bucket
14365
- }, { installations: delta }, { shardBy });
14366
- }
14367
- if (head.from_bundle_id !== null) tx.aggregate("insights_latest_by_bundle", {
14368
- platform: head.platform,
14369
- channel: head.channel,
14370
- bundle_field: PAIR_FIELD,
14371
- bundle_id: bundlePairKey(head.from_bundle_id, head.to_bundle_id),
14372
- type: head.type,
14373
- bucket_start_ms: bucket
14374
- }, { installations: delta }, { shardBy });
14375
14414
  };
14376
14415
  const PERIOD_MODELS = {
14377
14416
  hour: {
@@ -14421,18 +14460,13 @@ const countEvent = (tx, event) => {
14421
14460
  };
14422
14461
  const countOutcome = (tx, event) => {
14423
14462
  const shardBy = event.install_id;
14424
- const hour = (type, bundleRef) => tx.aggregate("insights_outcomes", {
14463
+ for (const [type, bundleRef] of outcomeRefsOf(event)) tx.aggregate("insights_outcomes", {
14425
14464
  platform: event.platform,
14426
14465
  channel: event.channel,
14427
14466
  type,
14428
14467
  bundle_ref: bundleRef,
14429
14468
  bucket_start_ms: hourOf(event.received_at_ms)
14430
14469
  }, { events: 1 }, { shardBy });
14431
- for (const bundleRef of bundleRefsOf(event)) hour(event.type, bundleRef);
14432
- if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", bundleRefOfFilter({
14433
- type: "UPDATE_DOWNLOADED",
14434
- toBundleId: event.type === "RECOVERED" ? event.from_bundle_id : event.to_bundle_id
14435
- }));
14436
14470
  tx.aggregate("insights_outcomes", {
14437
14471
  ...DAILY_EVENTS,
14438
14472
  bucket_start_ms: dayOf(event.received_at_ms)
@@ -14818,25 +14852,34 @@ const countEventSeries = async (db, input) => {
14818
14852
  events: count
14819
14853
  }));
14820
14854
  };
14821
- const latestPredicates = (bundle) => {
14822
- if (bundle === void 0) return void 0;
14823
- return [...new Map(bundle.flatMap(({ field, value, types }) => types.map((type) => [JSON.stringify([
14824
- field,
14825
- value,
14826
- type
14827
- ]), {
14828
- field,
14829
- value,
14830
- type
14831
- }]))).values()];
14832
- };
14833
- const countLatestEvents = async (db, input) => {
14834
- const { platform, channel, sinceMs: start } = input;
14855
+ const distributionRows = (db, { platform, channel, sinceMs: start }) => {
14835
14856
  if (start % 864e5 !== 0) throw new DatabaseAdapterInputError("invalid-query");
14836
- const predicates = latestPredicates(input.bundle);
14857
+ return drain((page) => db.findAggregates("insights_distribution", {
14858
+ index: "byScope",
14859
+ where: {
14860
+ channel,
14861
+ platform
14862
+ },
14863
+ range: { gte: start },
14864
+ limit: PAGE,
14865
+ ...page
14866
+ }));
14867
+ };
14868
+ const installations = (count) => Math.max(0, count);
14869
+ const countLatestEvents = async (db, input) => installations((await distributionRows(db, input)).reduce((sum, row) => sum + row.latest_installations, 0));
14870
+ const countReleaseInstallations = async (db, input) => {
14871
+ const { platform, channel, sinceMs: start, releaseId } = input;
14837
14872
  let total = 0;
14838
- if (predicates === void 0) {
14839
- const rows = await drain((page) => db.findAggregates("insights_distribution", {
14873
+ let release = 0;
14874
+ let named = false;
14875
+ for (const row of await distributionRows(db, input)) {
14876
+ total += row.latest_installations;
14877
+ if (row.release_id !== releaseId) continue;
14878
+ named = true;
14879
+ release += row.latest_installations;
14880
+ }
14881
+ if (!named) {
14882
+ const builtin = await drain((page) => db.findAggregates("insights_builtin_distribution", {
14840
14883
  index: "byScope",
14841
14884
  where: {
14842
14885
  channel,
@@ -14846,33 +14889,12 @@ const countLatestEvents = async (db, input) => {
14846
14889
  limit: PAGE,
14847
14890
  ...page
14848
14891
  }));
14849
- total += rows.reduce((sum, row) => sum + row.latest_installations, 0);
14850
- } else {
14851
- const gauge = async (bundleField, bundleId, type) => {
14852
- return (await drain((page) => db.findAggregates("insights_latest_by_bundle", {
14853
- index: "byBundle",
14854
- where: {
14855
- platform,
14856
- channel,
14857
- bundle_field: bundleField,
14858
- bundle_id: bundleId,
14859
- type
14860
- },
14861
- range: { gte: start },
14862
- limit: PAGE,
14863
- ...page
14864
- }))).reduce((sum, row) => sum + row.installations, 0);
14865
- };
14866
- for (const { field, value, type } of predicates) total += await gauge(field, value, type);
14867
- for (const from of predicates) {
14868
- if (from.field !== "from_bundle_id") continue;
14869
- for (const to of predicates) {
14870
- if (to.field !== "to_bundle_id" || to.type !== from.type) continue;
14871
- total -= await gauge(PAIR_FIELD, bundlePairKey(from.value, to.value), from.type);
14872
- }
14873
- }
14892
+ for (const row of builtin) if (row.release_id === "" && row.builtin_bundle_id === releaseId) release += row.latest_installations;
14874
14893
  }
14875
- return Math.max(0, total);
14894
+ return {
14895
+ installations: installations(total),
14896
+ release: installations(release)
14897
+ };
14876
14898
  };
14877
14899
  const retained = (now, { rawDays, dailyDays }) => ({
14878
14900
  hour: hourCeil(now - rawDays * DAY_MS$1),
@@ -15289,6 +15311,20 @@ const getUpdateFailures = async (db, input, now, retention) => {
15289
15311
  };
15290
15312
  };
15291
15313
  //#endregion
15314
+ //#region ../insights/dist/server/wire.mjs
15315
+ const RELEASE_ID_PARAM = "bundleId";
15316
+ const toWireOverview = ({ bundle, ...overview }) => {
15317
+ if (bundle === void 0) return overview;
15318
+ const { releaseId, ...counts } = bundle;
15319
+ return {
15320
+ ...overview,
15321
+ bundle: {
15322
+ ...counts,
15323
+ bundleId: releaseId
15324
+ }
15325
+ };
15326
+ };
15327
+ //#endregion
15292
15328
  //#region ../insights/dist/server/queryInput.mjs
15293
15329
  const MAX_PAGE_LIMIT = 100;
15294
15330
  const MAX_IDENTITY_LENGTH = 255;
@@ -15333,7 +15369,7 @@ const readScope = (url) => {
15333
15369
  const parseEventPageInput = (request) => {
15334
15370
  const url = new URL(request.url);
15335
15371
  const bundleFields = [
15336
- "bundleId",
15372
+ RELEASE_ID_PARAM,
15337
15373
  "outcome",
15338
15374
  "platform",
15339
15375
  "channel"
@@ -15344,7 +15380,7 @@ const parseEventPageInput = (request) => {
15344
15380
  if (outcome !== "downloaded" && outcome !== "applied" && outcome !== "recovered" && outcome !== "failed") throw new InsightsBadRequestError("Invalid 'outcome' query parameter.");
15345
15381
  bundle = {
15346
15382
  ...readScope(url),
15347
- bundleId: readId(url, "bundleId", 1024),
15383
+ releaseId: readId(url, RELEASE_ID_PARAM, 1024),
15348
15384
  outcome
15349
15385
  };
15350
15386
  }
@@ -15370,11 +15406,10 @@ const parseReportingOverviewInput = (request) => {
15370
15406
  const url = new URL(request.url);
15371
15407
  const window = readSingle(url, "window") ?? "30d";
15372
15408
  if (window !== "24h" && window !== "7d" && window !== "30d") throw new InsightsBadRequestError("Invalid 'window' query parameter.");
15373
- const bundleId = readSingle(url, "bundleId");
15374
15409
  return {
15375
15410
  ...readScope(url),
15376
15411
  window,
15377
- ...bundleId === void 0 ? {} : { bundleId: readId(url, "bundleId", 1024) }
15412
+ ...readSingle(url, "bundleId") === void 0 ? {} : { releaseId: readId(url, RELEASE_ID_PARAM, 1024) }
15378
15413
  };
15379
15414
  };
15380
15415
  //#endregion
@@ -15453,7 +15488,7 @@ const createInsightsRouteHandlers = (provider) => ({
15453
15488
  await provider.appendBundleEvent(await parseBundleEventRequest(request));
15454
15489
  return new Response(null, { status: 204 });
15455
15490
  }),
15456
- getReportingOverview: (_params, request) => query(() => provider.getReportingOverview(parseReportingOverviewInput(request))),
15491
+ getReportingOverview: (_params, request) => query(async () => toWireOverview(await provider.getReportingOverview(parseReportingOverviewInput(request)))),
15457
15492
  getInstallation: (params) => run$1(async () => {
15458
15493
  const installation = await provider.getInstallation({ installId: requireParam(params, "installId") });
15459
15494
  return installation === null ? json$1({ error: "Installation not found" }, 404) : json$1(installation, 200);
@@ -15473,11 +15508,13 @@ const createInsightsApi = (db, now, retention) => ({
15473
15508
  listEvents: (input) => listEvents(db, input),
15474
15509
  findLatestEvents: (input) => findLatestEvents(db, input),
15475
15510
  countLatestEvents: (input) => countLatestEvents(db, input),
15511
+ countReleaseInstallations: (input) => countReleaseInstallations(db, input),
15476
15512
  countEvents: (input) => countEvents(db, input),
15477
15513
  countEventSeries: (input) => countEventSeries(db, input),
15478
15514
  getReleaseActivity: (input) => getReleaseActivity(db, input, now),
15479
15515
  getAppUsage: (input) => getAppUsage(db, input, now, retention),
15480
- getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention)
15516
+ getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention),
15517
+ backfillReleaseRefs: (options) => backfillReleaseRefs(db, now, retention, options)
15481
15518
  });
15482
15519
  const readFailuresQuery = (url) => {
15483
15520
  const query = url.searchParams;
@@ -7884,6 +7884,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
7884
7884
  let credential;
7885
7885
  try {
7886
7886
  await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
7887
+ await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)(server);
7887
7888
  credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
7888
7889
  env: initInputEnv,
7889
7890
  name: "Azure init"
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { createHash } from "crypto";
3
3
  import path from "path";
4
- import { ConfigBuilder, InitError, assembleServer, createHotUpdaterConfigScaffoldFromBuilder, createZip, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
4
+ import { ConfigBuilder, InitError, assembleServer, backfillInsightsReleaseRefs, createHotUpdaterConfigScaffoldFromBuilder, createZip, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
5
5
  import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
6
6
  import { CosmosClient } from "@azure/cosmos";
7
7
  import { SETTINGS_TABLE, createEngineDatabase, createKvAdapter, encodeKvKey, migrateCoreSchema, toolingTargetOf } from "@hot-updater/plugin-core";
@@ -7879,6 +7879,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
7879
7879
  let credential;
7880
7880
  try {
7881
7881
  await fillReleaseLabels(server);
7882
+ await backfillInsightsReleaseRefs(server);
7882
7883
  credential = await provisionClientCredential(server, {
7883
7884
  env: initInputEnv,
7884
7885
  name: "Azure init"
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.56",
4
+ "version": "1.2.0-rc.58",
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/plugin-core": "1.2.0-rc.56",
48
- "@hot-updater/cli-tools": "1.2.0-rc.56",
49
- "@hot-updater/protocol": "1.2.0-rc.56",
50
- "@hot-updater/server": "1.2.0-rc.56"
47
+ "@hot-updater/cli-tools": "1.2.0-rc.58",
48
+ "@hot-updater/plugin-core": "1.2.0-rc.58",
49
+ "@hot-updater/protocol": "1.2.0-rc.58",
50
+ "@hot-updater/server": "1.2.0-rc.58"
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.56"
58
+ "@hot-updater/test-utils": "1.2.0-rc.58"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "tsdown",