@hot-updater/server 1.2.0-rc.21 → 1.2.0-rc.23

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.
@@ -40,12 +40,13 @@ const pick = (row) => ({
40
40
  submitted_to: row.submitted_to ?? null,
41
41
  submitted_at_ms: row.submitted_at_ms ?? null,
42
42
  submitted_version: row.submitted_version ?? null,
43
- store_build: row.store_build === true ? true : null
43
+ is_store_build: row.is_store_build === true,
44
+ is_sandbox: row.is_sandbox === true
44
45
  });
45
46
  /**
46
- * The channels only sandbox builds register on, which no store sells: the
47
- * registry's convention, as `@hot-updater/protocol/native-artifact` checks it
48
- * for a build's artifact.
47
+ * The channels only sandbox builds register on: a registration's `sandbox`
48
+ * must agree with it. The registry's convention, as
49
+ * `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
49
50
  */
50
51
  const SANDBOX_CHANNEL_PREFIX = "sandbox-";
51
52
  /**
@@ -92,11 +93,15 @@ const nativeBuildScopeKey = (scope) => {
92
93
  };
93
94
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
94
95
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
95
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
96
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, artifact }) => {
96
97
  if (!(0, _hot_updater_plugin_core.isUUIDv7)(id)) return "id must be a UUIDv7";
97
98
  if (!(0, _hot_updater_plugin_core.isUUIDv7)(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
98
99
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
99
100
  if (channel.trim().length === 0) return "channel is required";
101
+ if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
102
+ const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
103
+ if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
104
+ if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
100
105
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
101
106
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
102
107
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
@@ -132,7 +137,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
132
137
  submitted_to: null,
133
138
  submitted_at_ms: null,
134
139
  submitted_version: null,
135
- store_build: null
140
+ is_store_build: false,
141
+ is_sandbox: registration.isSandbox === true
136
142
  };
137
143
  for (let attempt = 1;; attempt += 1) {
138
144
  await require_writes.insertChannel(db, {
@@ -171,10 +177,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
171
177
  const buildKey = options?.buildKey;
172
178
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
173
179
  if (options?.storeBuild) {
174
- const marked = await db.findOne("native_builds", {
175
- scope_key: scopeKey,
176
- store_build: true
177
- });
180
+ const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
178
181
  return marked === null ? null : pick(marked);
179
182
  }
180
183
  const read = (limit, before) => {
@@ -236,34 +239,31 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
236
239
  if (row === null) return null;
237
240
  const build = pick(row);
238
241
  if (!storeBuild) {
239
- if (build.store_build !== null) tx.update("native_builds", row, { store_build: null });
242
+ if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
240
243
  return {
241
244
  nativeBuild: {
242
245
  ...build,
243
- store_build: null
246
+ is_store_build: false
244
247
  },
245
248
  previous: null
246
249
  };
247
250
  }
248
- if ((0, _hot_updater_protocol.decodeChannelKey)(build.channel_id.slice(8)).startsWith(SANDBOX_CHANNEL_PREFIX)) throw new NativeBuildInputError("A build on a sandbox channel can't be the store build.");
249
- if (build.store_build !== null) return {
251
+ if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
252
+ if (build.is_store_build) return {
250
253
  nativeBuild: build,
251
254
  previous: null
252
255
  };
253
- const holder = await tx.findOne("native_builds", {
254
- scope_key: build.scope_key,
255
- store_build: true
256
- });
257
- if (holder !== null) tx.update("native_builds", holder, { store_build: null });
258
- tx.update("native_builds", row, { store_build: true });
256
+ const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
257
+ if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
258
+ tx.update("native_builds", row, { is_store_build: true });
259
259
  return {
260
260
  nativeBuild: {
261
261
  ...build,
262
- store_build: true
262
+ is_store_build: true
263
263
  },
264
264
  previous: holder === null ? null : {
265
265
  ...pick(holder),
266
- store_build: null
266
+ is_store_build: false
267
267
  }
268
268
  };
269
269
  });
@@ -1,7 +1,7 @@
1
1
  import { after } from "./reads.mjs";
2
2
  import { insertChannel } from "./writes.mjs";
3
3
  import { DatabaseConstraintError, isUUIDv7 } from "@hot-updater/plugin-core";
4
- import { createReleaseCatalogScopeKey, decodeChannelKey, encodeChannelKey } from "@hot-updater/protocol";
4
+ import { createReleaseCatalogScopeKey, encodeChannelKey } from "@hot-updater/protocol";
5
5
  //#region src/core/nativeBuilds.ts
6
6
  /** The artifacts each platform's build produces. */
7
7
  const ARTIFACT_KINDS = {
@@ -40,12 +40,13 @@ const pick = (row) => ({
40
40
  submitted_to: row.submitted_to ?? null,
41
41
  submitted_at_ms: row.submitted_at_ms ?? null,
42
42
  submitted_version: row.submitted_version ?? null,
43
- store_build: row.store_build === true ? true : null
43
+ is_store_build: row.is_store_build === true,
44
+ is_sandbox: row.is_sandbox === true
44
45
  });
45
46
  /**
46
- * The channels only sandbox builds register on, which no store sells: the
47
- * registry's convention, as `@hot-updater/protocol/native-artifact` checks it
48
- * for a build's artifact.
47
+ * The channels only sandbox builds register on: a registration's `sandbox`
48
+ * must agree with it. The registry's convention, as
49
+ * `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
49
50
  */
50
51
  const SANDBOX_CHANNEL_PREFIX = "sandbox-";
51
52
  /**
@@ -92,11 +93,15 @@ const nativeBuildScopeKey = (scope) => {
92
93
  };
93
94
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
94
95
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
95
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
96
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, artifact }) => {
96
97
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
97
98
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
98
99
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
99
100
  if (channel.trim().length === 0) return "channel is required";
101
+ if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
102
+ const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
103
+ if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
104
+ if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
100
105
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
101
106
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
102
107
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
@@ -132,7 +137,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
132
137
  submitted_to: null,
133
138
  submitted_at_ms: null,
134
139
  submitted_version: null,
135
- store_build: null
140
+ is_store_build: false,
141
+ is_sandbox: registration.isSandbox === true
136
142
  };
137
143
  for (let attempt = 1;; attempt += 1) {
138
144
  await insertChannel(db, {
@@ -171,10 +177,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
171
177
  const buildKey = options?.buildKey;
172
178
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
173
179
  if (options?.storeBuild) {
174
- const marked = await db.findOne("native_builds", {
175
- scope_key: scopeKey,
176
- store_build: true
177
- });
180
+ const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
178
181
  return marked === null ? null : pick(marked);
179
182
  }
180
183
  const read = (limit, before) => {
@@ -236,34 +239,31 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
236
239
  if (row === null) return null;
237
240
  const build = pick(row);
238
241
  if (!storeBuild) {
239
- if (build.store_build !== null) tx.update("native_builds", row, { store_build: null });
242
+ if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
240
243
  return {
241
244
  nativeBuild: {
242
245
  ...build,
243
- store_build: null
246
+ is_store_build: false
244
247
  },
245
248
  previous: null
246
249
  };
247
250
  }
248
- if (decodeChannelKey(build.channel_id.slice(8)).startsWith(SANDBOX_CHANNEL_PREFIX)) throw new NativeBuildInputError("A build on a sandbox channel can't be the store build.");
249
- if (build.store_build !== null) return {
251
+ if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
252
+ if (build.is_store_build) return {
250
253
  nativeBuild: build,
251
254
  previous: null
252
255
  };
253
- const holder = await tx.findOne("native_builds", {
254
- scope_key: build.scope_key,
255
- store_build: true
256
- });
257
- if (holder !== null) tx.update("native_builds", holder, { store_build: null });
258
- tx.update("native_builds", row, { store_build: true });
256
+ const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
257
+ if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
258
+ tx.update("native_builds", row, { is_store_build: true });
259
259
  return {
260
260
  nativeBuild: {
261
261
  ...build,
262
- store_build: true
262
+ is_store_build: true
263
263
  },
264
264
  previous: holder === null ? null : {
265
265
  ...pick(holder),
266
- store_build: null
266
+ is_store_build: false
267
267
  }
268
268
  };
269
269
  });
@@ -169,7 +169,7 @@ const refusingInvalid = async (operation) => {
169
169
  throw error;
170
170
  }
171
171
  };
172
- const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
172
+ const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
173
173
  const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
174
174
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
175
175
  const createAdminRouteHandlers = () => ({
@@ -169,7 +169,7 @@ const refusingInvalid = async (operation) => {
169
169
  throw error;
170
170
  }
171
171
  };
172
- const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
172
+ const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
173
173
  const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
174
174
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
175
175
  const createAdminRouteHandlers = () => ({
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.21";
2
+ var version = "1.2.0-rc.23";
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.21";
2
+ var version = "1.2.0-rc.23";
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.21",
3
+ "version": "1.2.0-rc.23",
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/plugin-api-keys": "1.2.0-rc.21",
54
- "@hot-updater/plugin-remote-config": "1.2.0-rc.21",
55
- "@hot-updater/plugin-insights": "1.2.0-rc.21",
56
- "@hot-updater/protocol": "1.2.0-rc.21",
57
- "@hot-updater/plugin-core": "1.2.0-rc.21"
53
+ "@hot-updater/plugin-api-keys": "1.2.0-rc.23",
54
+ "@hot-updater/plugin-remote-config": "1.2.0-rc.23",
55
+ "@hot-updater/plugin-insights": "1.2.0-rc.23",
56
+ "@hot-updater/protocol": "1.2.0-rc.23",
57
+ "@hot-updater/plugin-core": "1.2.0-rc.23"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "*",