@hot-updater/server 1.2.0-rc.33 → 1.2.0-rc.35

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.
@@ -104,6 +104,14 @@ const nativeBuildScopeKey = (scope) => {
104
104
  if (scopeKey.length > SCOPE_KEY_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build scope: its key is longer than ${SCOPE_KEY_MAX_LENGTH} characters; shorten the channel or app version.`);
105
105
  return scopeKey;
106
106
  };
107
+ /**
108
+ * Refuses a patch from a sandbox build's built-in bundle: no deploy patches
109
+ * from one, so no store or test install of the app gets a patch made for a
110
+ * sandbox build. One unique read of the base.
111
+ */
112
+ const refuseSandboxPatchBase = async (db, baseBundleId) => {
113
+ if ((await db.findOne("native_builds", { min_bundle_id: baseBundleId }))?.is_sandbox === true) throw new NativeBuildInputError("A sandbox build's built-in bundle is no patch base.");
114
+ };
107
115
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
108
116
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
109
117
  const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
@@ -224,10 +232,11 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
224
232
  ...page
225
233
  });
226
234
  };
235
+ const bundleId = options?.builtInOlderThan;
236
+ if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
227
237
  const { rows } = await read(1);
228
238
  const newest = rows[0];
229
239
  if (newest === void 0) return null;
230
- const bundleId = options?.builtInOlderThan;
231
240
  if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
232
241
  for (let before = newest.id;;) {
233
242
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
@@ -338,3 +347,4 @@ exports.NativeBuildInputError = NativeBuildInputError;
338
347
  exports.createNativeBuildApi = createNativeBuildApi;
339
348
  exports.isBuiltInBundle = isBuiltInBundle;
340
349
  exports.nativeBuildScopeKey = nativeBuildScopeKey;
350
+ exports.refuseSandboxPatchBase = refuseSandboxPatchBase;
@@ -104,6 +104,14 @@ const nativeBuildScopeKey = (scope) => {
104
104
  if (scopeKey.length > SCOPE_KEY_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build scope: its key is longer than ${SCOPE_KEY_MAX_LENGTH} characters; shorten the channel or app version.`);
105
105
  return scopeKey;
106
106
  };
107
+ /**
108
+ * Refuses a patch from a sandbox build's built-in bundle: no deploy patches
109
+ * from one, so no store or test install of the app gets a patch made for a
110
+ * sandbox build. One unique read of the base.
111
+ */
112
+ const refuseSandboxPatchBase = async (db, baseBundleId) => {
113
+ if ((await db.findOne("native_builds", { min_bundle_id: baseBundleId }))?.is_sandbox === true) throw new NativeBuildInputError("A sandbox build's built-in bundle is no patch base.");
114
+ };
107
115
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
108
116
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
109
117
  const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
@@ -224,10 +232,11 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
224
232
  ...page
225
233
  });
226
234
  };
235
+ const bundleId = options?.builtInOlderThan;
236
+ if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
227
237
  const { rows } = await read(1);
228
238
  const newest = rows[0];
229
239
  if (newest === void 0) return null;
230
- const bundleId = options?.builtInOlderThan;
231
240
  if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
232
241
  for (let before = newest.id;;) {
233
242
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
@@ -334,4 +343,4 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
334
343
  }
335
344
  });
336
345
  //#endregion
337
- export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey };
346
+ export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey, refuseSandboxPatchBase };
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
129
129
  for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
130
130
  const platforms = /* @__PURE__ */ new Map();
131
131
  for (const deployment of deployments) {
132
- if (!("bundleId" in deployment) || platforms.has(deployment.bundleId)) continue;
132
+ if (!("bundleId" in deployment)) {
133
+ for (const { baseBundleId } of deployment.bundle.patches ?? []) await require_nativeBuilds.refuseSandboxPatchBase(db, baseBundleId);
134
+ continue;
135
+ }
136
+ if (platforms.has(deployment.bundleId)) continue;
133
137
  const row = await db.findOne("bundles", { id: deployment.bundleId });
134
138
  if (row === null) throw new _hot_updater_plugin_core.DatabaseBundleNotFoundError(deployment.bundleId);
135
139
  if (await require_nativeBuilds.isBuiltInBundle(db, deployment.bundleId)) throw new _hot_updater_plugin_core.ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
333
337
  if (patches !== void 0) await require_writes.replaceBundlePatches(tx, current, (0, _hot_updater_plugin_core.bundleToPatchRows)({
334
338
  ...next,
335
339
  patches
336
- }));
340
+ }), (row) => require_nativeBuilds.refuseSandboxPatchBase(tx, row.base_bundle_id));
337
341
  }),
338
342
  deleteBundles: async (ids) => {
339
343
  try {
@@ -1,6 +1,6 @@
1
1
  import { toBundleRow, toReleaseRow } from "./reads.mjs";
2
2
  import { deleteBundle, deleteChannel, insertChannel, replaceBundlePatches, updateBundle } from "./writes.mjs";
3
- import { isBuiltInBundle } from "./nativeBuilds.mjs";
3
+ import { isBuiltInBundle, refuseSandboxPatchBase } from "./nativeBuilds.mjs";
4
4
  import { changeRelease, changeReleases, readCatalog, rebuildScope } from "./releases.mjs";
5
5
  import { DatabaseBundleNotFoundError, DatabaseConstraintError, DatabaseRowReferencedError, ReleaseCatalogMutationError, ReleaseManagementError, bundleToPatchRows, bundleToRow, createUUIDv7After, isUUIDv7, rowToBundle } from "@hot-updater/plugin-core";
6
6
  import { createReleaseCatalogScopeKey, decodeChannelKey, encodeChannelKey } from "@hot-updater/protocol";
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
129
129
  for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
130
130
  const platforms = /* @__PURE__ */ new Map();
131
131
  for (const deployment of deployments) {
132
- if (!("bundleId" in deployment) || platforms.has(deployment.bundleId)) continue;
132
+ if (!("bundleId" in deployment)) {
133
+ for (const { baseBundleId } of deployment.bundle.patches ?? []) await refuseSandboxPatchBase(db, baseBundleId);
134
+ continue;
135
+ }
136
+ if (platforms.has(deployment.bundleId)) continue;
133
137
  const row = await db.findOne("bundles", { id: deployment.bundleId });
134
138
  if (row === null) throw new DatabaseBundleNotFoundError(deployment.bundleId);
135
139
  if (await isBuiltInBundle(db, deployment.bundleId)) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
333
337
  if (patches !== void 0) await replaceBundlePatches(tx, current, bundleToPatchRows({
334
338
  ...next,
335
339
  patches
336
- }));
340
+ }), (row) => refuseSandboxPatchBase(tx, row.base_bundle_id));
337
341
  }),
338
342
  deleteBundles: async (ids) => {
339
343
  try {
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
29
29
  /**
30
30
  * Replaces a bundle's patches with `rows`: kept patches are updated where
31
31
  * they changed, others deleted or created, so no key is written twice.
32
+ * `checkNew` sees each patch it is about to create, and refuses one by
33
+ * throwing, which leaves the transaction's writes undone.
32
34
  */
33
- const replaceBundlePatches = async (tx, bundle, rows) => {
35
+ const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
34
36
  const wanted = new Map(rows.map((row) => [row.id, row]));
35
37
  const count = bundle._refs_bundle_patches_bundle_id ?? 0;
36
38
  let cursor;
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
55
57
  if (page.next === void 0) break;
56
58
  cursor = page.next;
57
59
  }
60
+ if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
58
61
  for (const row of wanted.values()) tx.create("bundle_patches", row);
59
62
  };
60
63
  /** A channel by name, created when missing; a concurrent creator's row is returned instead. */
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
29
29
  /**
30
30
  * Replaces a bundle's patches with `rows`: kept patches are updated where
31
31
  * they changed, others deleted or created, so no key is written twice.
32
+ * `checkNew` sees each patch it is about to create, and refuses one by
33
+ * throwing, which leaves the transaction's writes undone.
32
34
  */
33
- const replaceBundlePatches = async (tx, bundle, rows) => {
35
+ const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
34
36
  const wanted = new Map(rows.map((row) => [row.id, row]));
35
37
  const count = bundle._refs_bundle_patches_bundle_id ?? 0;
36
38
  let cursor;
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
55
57
  if (page.next === void 0) break;
56
58
  cursor = page.next;
57
59
  }
60
+ if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
58
61
  for (const row of wanted.values()) tx.create("bundle_patches", row);
59
62
  };
60
63
  /** A channel by name, created when missing; a concurrent creator's row is returned instead. */
@@ -255,7 +255,8 @@ const createAdminRouteHandlers = () => ({
255
255
  rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
256
256
  updateBundle: onCore(async (core, request, params) => {
257
257
  const bundleId = require_handlerParameters.requireRouteParam(params, "id");
258
- await core.updateBundle(bundleId, bundleUpdateOf(await request.json(), bundleId));
258
+ const update = bundleUpdateOf(await request.json(), bundleId);
259
+ await refusingInvalid(() => core.updateBundle(bundleId, update));
259
260
  return noContent();
260
261
  }),
261
262
  countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
@@ -279,7 +280,7 @@ const createAdminRouteHandlers = () => ({
279
280
  deployReleases: onCore(async (core, request) => {
280
281
  const { deployments } = await body(request);
281
282
  if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new require_handlerErrors.HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
282
- return json({ data: await core.deploy(deployments) }, 201);
283
+ return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
283
284
  }),
284
285
  promoteRelease: onCore(async (core, request, params) => {
285
286
  const input = await body(request);
@@ -255,7 +255,8 @@ const createAdminRouteHandlers = () => ({
255
255
  rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
256
256
  updateBundle: onCore(async (core, request, params) => {
257
257
  const bundleId = requireRouteParam(params, "id");
258
- await core.updateBundle(bundleId, bundleUpdateOf(await request.json(), bundleId));
258
+ const update = bundleUpdateOf(await request.json(), bundleId);
259
+ await refusingInvalid(() => core.updateBundle(bundleId, update));
259
260
  return noContent();
260
261
  }),
261
262
  countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
@@ -279,7 +280,7 @@ const createAdminRouteHandlers = () => ({
279
280
  deployReleases: onCore(async (core, request) => {
280
281
  const { deployments } = await body(request);
281
282
  if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
282
- return json({ data: await core.deploy(deployments) }, 201);
283
+ return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
283
284
  }),
284
285
  promoteRelease: onCore(async (core, request, params) => {
285
286
  const input = await body(request);
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.33";
2
+ var version = "1.2.0-rc.35";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.33";
2
+ var version = "1.2.0-rc.35";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/server",
3
- "version": "1.2.0-rc.33",
3
+ "version": "1.2.0-rc.35",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -50,11 +50,11 @@
50
50
  "dependencies": {
51
51
  "rou3": "0.7.9",
52
52
  "verkit": "0.4.0",
53
- "@hot-updater/protocol": "1.2.0-rc.33",
54
- "@hot-updater/plugin-core": "1.2.0-rc.33",
55
- "@hot-updater/plugin-api-keys": "1.2.0-rc.33",
56
- "@hot-updater/plugin-insights": "1.2.0-rc.33",
57
- "@hot-updater/plugin-remote-config": "1.2.0-rc.33"
53
+ "@hot-updater/protocol": "1.2.0-rc.35",
54
+ "@hot-updater/plugin-core": "1.2.0-rc.35",
55
+ "@hot-updater/plugin-api-keys": "1.2.0-rc.35",
56
+ "@hot-updater/plugin-insights": "1.2.0-rc.35",
57
+ "@hot-updater/plugin-remote-config": "1.2.0-rc.35"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "*",