@hot-updater/server 1.2.0-rc.40 → 1.2.0-rc.41

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.
@@ -33,6 +33,7 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
33
33
  readonly requestedBy?: string;
34
34
  }) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
35
35
  claimIosDeviceAccount: (issuerId: string) => Promise<import("@hot-updater/plugin-core").IosDeviceAccountClaim>;
36
+ findIosDeviceAccount: () => Promise<import("@hot-updater/plugin-core").IosDeviceAccount | null>;
36
37
  registerNativeBuild: (registration: import("@hot-updater/plugin-core").NativeBuildRegistration) => Promise<import("@hot-updater/plugin-core").NativeBuildRow>;
37
38
  getNativeBuild: (id: string) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
38
39
  findNativeBuild: (scope: import("@hot-updater/plugin-core").NativeBuildScope, options?: {
@@ -33,6 +33,7 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
33
33
  readonly requestedBy?: string;
34
34
  }) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
35
35
  claimIosDeviceAccount: (issuerId: string) => Promise<import("@hot-updater/plugin-core").IosDeviceAccountClaim>;
36
+ findIosDeviceAccount: () => Promise<import("@hot-updater/plugin-core").IosDeviceAccount | null>;
36
37
  registerNativeBuild: (registration: import("@hot-updater/plugin-core").NativeBuildRegistration) => Promise<import("@hot-updater/plugin-core").NativeBuildRow>;
37
38
  getNativeBuild: (id: string) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
38
39
  findNativeBuild: (scope: import("@hot-updater/plugin-core").NativeBuildScope, options?: {
@@ -263,6 +263,11 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
263
263
  tx.update("ios_devices", row, { build_id: buildId });
264
264
  });
265
265
  },
266
+ async findIosDeviceAccount() {
267
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
268
+ const issuerId = existing === null ? await accountOfRows() : existing.apple_issuer_id;
269
+ return issuerId === null ? null : { issuerId };
270
+ },
266
271
  async claimIosDeviceAccount(issuerId) {
267
272
  if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
268
273
  const answer = (held) => ({
@@ -263,6 +263,11 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
263
263
  tx.update("ios_devices", row, { build_id: buildId });
264
264
  });
265
265
  },
266
+ async findIosDeviceAccount() {
267
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
268
+ const issuerId = existing === null ? await accountOfRows() : existing.apple_issuer_id;
269
+ return issuerId === null ? null : { issuerId };
270
+ },
266
271
  async claimIosDeviceAccount(issuerId) {
267
272
  if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
268
273
  const answer = (held) => ({
@@ -26,6 +26,20 @@ const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
26
26
  * artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
27
27
  */
28
28
  const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
29
+ /**
30
+ * A bundle identifier or application ID, as an artifact reports it: letters,
31
+ * digits, dots, dashes and underscores, which a scope key holds as they are.
32
+ */
33
+ const APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/;
34
+ /** A fingerprint hash as a Release Catalog scope key holds it. */
35
+ const FINGERPRINT_HASH = /^[A-Za-z0-9._~-]{1,255}$/;
36
+ /** How each kind of artifact can install. */
37
+ const DISTRIBUTIONS = {
38
+ apk: ["direct"],
39
+ app: ["direct"],
40
+ aab: ["store"],
41
+ ipa: ["direct", "store"]
42
+ };
29
43
  /** A native build or scope core cannot store or look up: the caller's input. */
30
44
  var NativeBuildInputError = class extends TypeError {
31
45
  name = "NativeBuildInputError";
@@ -62,12 +76,6 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
62
76
  "enterprise"
63
77
  ]);
64
78
  /**
65
- * The channels only sandbox builds register on: a registration's `sandbox`
66
- * must agree with it. The registry's convention, as
67
- * `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
68
- */
69
- const SANDBOX_CHANNEL_PREFIX = "sandbox-";
70
- /**
71
79
  * How many older builds of a scope one read takes, looking for one older than
72
80
  * a bundle when a build made after the bundle is the newest.
73
81
  */
@@ -78,13 +86,42 @@ const MARK_ATTEMPTS = 8;
78
86
  const BUILD_NUMBER_MAX_LENGTH = 64;
79
87
  /** `native_builds.submitted_version`'s bound in core's schema. */
80
88
  const SUBMITTED_VERSION_MAX_LENGTH = 255;
89
+ const checkedScopeKey = (scopeKey) => {
90
+ 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.`);
91
+ return scopeKey;
92
+ };
93
+ /**
94
+ * How a registered artifact installs: an `.ipa` by its export method, and
95
+ * `unknown` for one whose export no profile confirmed, which no lookup asks
96
+ * for, so it is never reused as either.
97
+ */
98
+ const registeredDistribution = (kind, exportMethod) => kind !== "ipa" ? DISTRIBUTIONS[kind][0] : exportMethod === void 0 || exportMethod === null ? "unknown" : exportMethod === "app-store" ? "store" : "direct";
99
+ /**
100
+ * A sandbox build scope's key, which names no channel: the app ID, URL
101
+ * scheme, artifact kind and distribution in its place, then the fingerprint,
102
+ * or the app-version strategy and the exact app version. `v1:sandbox:` is no
103
+ * Release Catalog strategy, so it never meets a normal build's key.
104
+ */
105
+ const sandboxScopeKey = (scope, sandbox) => {
106
+ const { appId, urlScheme, artifactKind, distribution } = sandbox;
107
+ const problem = typeof appId !== "string" || !APP_ID.test(appId) ? "its app ID must be a bundle identifier or application ID, up to 255 characters" : typeof urlScheme !== "string" || !URL_SCHEME.test(urlScheme) ? `its URL scheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters` : !ARTIFACT_KINDS[scope.platform]?.includes(artifactKind) ? `its artifact kind must be one an ${scope.platform} build makes` : distribution !== "unknown" && !DISTRIBUTIONS[artifactKind].includes(distribution) ? `an .${artifactKind} doesn't install as ${String(distribution)}` : scope.fingerprintHash !== null && !FINGERPRINT_HASH.test(scope.fingerprintHash) ? "its fingerprint hash must be 1-255 URL-safe ASCII characters" : null;
108
+ if (problem !== null) throw new NativeBuildInputError(`Invalid sandbox build scope: ${problem}.`);
109
+ const target = scope.fingerprintHash === null ? `app-version:${encodeURIComponent(scope.appVersion)}` : `fingerprint:${scope.fingerprintHash}`;
110
+ return checkedScopeKey(`v1:sandbox:${scope.platform}:${appId}:${urlScheme}:${artifactKind}:${distribution}:${target}`);
111
+ };
81
112
  /**
82
113
  * A native build scope's key: the Release Catalog scope key of a
83
114
  * fingerprint, or of the app-version strategy followed by the exact app
84
115
  * version the build compiled in. One key serves both strategies, so one
85
- * index finds the newest build of either.
116
+ * index finds the newest build of either. A sandbox scope's key names no
117
+ * channel, so pull requests find a sandbox build on any.
86
118
  */
87
119
  const nativeBuildScopeKey = (scope) => {
120
+ const { sandbox } = scope;
121
+ if (sandbox !== void 0 && sandbox !== null) {
122
+ if (sandbox.distribution !== "direct" && sandbox.distribution !== "store") throw new NativeBuildInputError("Invalid sandbox build scope: its distribution must be direct or store.");
123
+ return sandboxScopeKey(scope, sandbox);
124
+ }
88
125
  let scopeKey;
89
126
  try {
90
127
  const channelKey = (0, _hot_updater_protocol.encodeChannelKey)(scope.channel);
@@ -101,8 +138,31 @@ const nativeBuildScopeKey = (scope) => {
101
138
  } catch (error) {
102
139
  throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
103
140
  }
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
- return scopeKey;
141
+ return checkedScopeKey(scopeKey);
142
+ };
143
+ /** The channel row a registration names, or the refusal of its channel. */
144
+ const channelIdOf = (channel) => {
145
+ try {
146
+ return `channel:${(0, _hot_updater_protocol.encodeChannelKey)(channel)}`;
147
+ } catch (error) {
148
+ throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
149
+ }
150
+ };
151
+ /**
152
+ * A registration's scope key, from the registration's own facts: a sandbox
153
+ * build's from what its artifact says, whatever `sandbox` it names.
154
+ */
155
+ const registrationScopeKey = (registration) => {
156
+ channelIdOf(registration.channel);
157
+ return registration.isSandbox === true ? sandboxScopeKey(registration, {
158
+ appId: registration.sandboxAppId,
159
+ urlScheme: registration.sandboxUrlScheme,
160
+ artifactKind: registration.artifact.kind,
161
+ distribution: registeredDistribution(registration.artifact.kind, registration.exportMethod)
162
+ }) : nativeBuildScopeKey({
163
+ ...registration,
164
+ sandbox: null
165
+ });
106
166
  };
107
167
  /**
108
168
  * Refuses a patch from a sandbox build's built-in bundle: no deploy patches
@@ -114,19 +174,24 @@ const refuseSandboxPatchBase = async (db, baseBundleId) => {
114
174
  };
115
175
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
116
176
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
117
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
177
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, sandboxAppId, exportMethod, nativeAppVersion, artifact }) => {
118
178
  if (!(0, _hot_updater_plugin_core.isUUIDv7)(id)) return "id must be a UUIDv7";
119
179
  if (!(0, _hot_updater_plugin_core.isUUIDv7)(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
120
180
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
121
181
  if (channel.trim().length === 0) return "channel is required";
122
182
  if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
123
- const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
124
- if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
125
- if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
126
183
  if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
127
184
  if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
128
185
  if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
129
186
  }
187
+ if (sandboxAppId !== void 0 && sandboxAppId !== null) {
188
+ if (isSandbox !== true) return "sandboxAppId is a sandbox build's, and this isn't one";
189
+ if (typeof sandboxAppId !== "string" || !APP_ID.test(sandboxAppId)) return "sandboxAppId must be the artifact's bundle identifier or application ID, up to 255 characters";
190
+ }
191
+ if (isSandbox === true) {
192
+ if (sandboxUrlScheme === void 0 || sandboxUrlScheme === null) return "a sandbox build needs the sandboxUrlScheme its artifact registers";
193
+ if (sandboxAppId === void 0 || sandboxAppId === null) return "a sandbox build needs the sandboxAppId its artifact reports, which an older hot-updater CLI doesn't send. Upgrade the hot-updater CLI to the version that matches this server, and build again";
194
+ }
130
195
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
131
196
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
132
197
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
@@ -146,8 +211,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
146
211
  async registerNativeBuild(registration) {
147
212
  const problem = problemOf(registration);
148
213
  if (problem !== null) throw new NativeBuildInputError(`Invalid native build: ${problem}.`);
149
- const scopeKey = nativeBuildScopeKey(registration);
150
- const channelId = `channel:${(0, _hot_updater_protocol.encodeChannelKey)(registration.channel)}`;
214
+ const scopeKey = registrationScopeKey(registration);
215
+ const channelId = channelIdOf(registration.channel);
151
216
  const { embeddedBundle } = registration;
152
217
  const row = {
153
218
  id: registration.id,
@@ -233,7 +298,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
233
298
  });
234
299
  };
235
300
  const bundleId = options?.builtInOlderThan;
236
- if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
301
+ if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
237
302
  const { rows } = await read(1);
238
303
  const newest = rows[0];
239
304
  if (newest === void 0) return null;
@@ -26,6 +26,20 @@ const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
26
26
  * artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
27
27
  */
28
28
  const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
29
+ /**
30
+ * A bundle identifier or application ID, as an artifact reports it: letters,
31
+ * digits, dots, dashes and underscores, which a scope key holds as they are.
32
+ */
33
+ const APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/;
34
+ /** A fingerprint hash as a Release Catalog scope key holds it. */
35
+ const FINGERPRINT_HASH = /^[A-Za-z0-9._~-]{1,255}$/;
36
+ /** How each kind of artifact can install. */
37
+ const DISTRIBUTIONS = {
38
+ apk: ["direct"],
39
+ app: ["direct"],
40
+ aab: ["store"],
41
+ ipa: ["direct", "store"]
42
+ };
29
43
  /** A native build or scope core cannot store or look up: the caller's input. */
30
44
  var NativeBuildInputError = class extends TypeError {
31
45
  name = "NativeBuildInputError";
@@ -62,12 +76,6 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
62
76
  "enterprise"
63
77
  ]);
64
78
  /**
65
- * The channels only sandbox builds register on: a registration's `sandbox`
66
- * must agree with it. The registry's convention, as
67
- * `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
68
- */
69
- const SANDBOX_CHANNEL_PREFIX = "sandbox-";
70
- /**
71
79
  * How many older builds of a scope one read takes, looking for one older than
72
80
  * a bundle when a build made after the bundle is the newest.
73
81
  */
@@ -78,13 +86,42 @@ const MARK_ATTEMPTS = 8;
78
86
  const BUILD_NUMBER_MAX_LENGTH = 64;
79
87
  /** `native_builds.submitted_version`'s bound in core's schema. */
80
88
  const SUBMITTED_VERSION_MAX_LENGTH = 255;
89
+ const checkedScopeKey = (scopeKey) => {
90
+ 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.`);
91
+ return scopeKey;
92
+ };
93
+ /**
94
+ * How a registered artifact installs: an `.ipa` by its export method, and
95
+ * `unknown` for one whose export no profile confirmed, which no lookup asks
96
+ * for, so it is never reused as either.
97
+ */
98
+ const registeredDistribution = (kind, exportMethod) => kind !== "ipa" ? DISTRIBUTIONS[kind][0] : exportMethod === void 0 || exportMethod === null ? "unknown" : exportMethod === "app-store" ? "store" : "direct";
99
+ /**
100
+ * A sandbox build scope's key, which names no channel: the app ID, URL
101
+ * scheme, artifact kind and distribution in its place, then the fingerprint,
102
+ * or the app-version strategy and the exact app version. `v1:sandbox:` is no
103
+ * Release Catalog strategy, so it never meets a normal build's key.
104
+ */
105
+ const sandboxScopeKey = (scope, sandbox) => {
106
+ const { appId, urlScheme, artifactKind, distribution } = sandbox;
107
+ const problem = typeof appId !== "string" || !APP_ID.test(appId) ? "its app ID must be a bundle identifier or application ID, up to 255 characters" : typeof urlScheme !== "string" || !URL_SCHEME.test(urlScheme) ? `its URL scheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters` : !ARTIFACT_KINDS[scope.platform]?.includes(artifactKind) ? `its artifact kind must be one an ${scope.platform} build makes` : distribution !== "unknown" && !DISTRIBUTIONS[artifactKind].includes(distribution) ? `an .${artifactKind} doesn't install as ${String(distribution)}` : scope.fingerprintHash !== null && !FINGERPRINT_HASH.test(scope.fingerprintHash) ? "its fingerprint hash must be 1-255 URL-safe ASCII characters" : null;
108
+ if (problem !== null) throw new NativeBuildInputError(`Invalid sandbox build scope: ${problem}.`);
109
+ const target = scope.fingerprintHash === null ? `app-version:${encodeURIComponent(scope.appVersion)}` : `fingerprint:${scope.fingerprintHash}`;
110
+ return checkedScopeKey(`v1:sandbox:${scope.platform}:${appId}:${urlScheme}:${artifactKind}:${distribution}:${target}`);
111
+ };
81
112
  /**
82
113
  * A native build scope's key: the Release Catalog scope key of a
83
114
  * fingerprint, or of the app-version strategy followed by the exact app
84
115
  * version the build compiled in. One key serves both strategies, so one
85
- * index finds the newest build of either.
116
+ * index finds the newest build of either. A sandbox scope's key names no
117
+ * channel, so pull requests find a sandbox build on any.
86
118
  */
87
119
  const nativeBuildScopeKey = (scope) => {
120
+ const { sandbox } = scope;
121
+ if (sandbox !== void 0 && sandbox !== null) {
122
+ if (sandbox.distribution !== "direct" && sandbox.distribution !== "store") throw new NativeBuildInputError("Invalid sandbox build scope: its distribution must be direct or store.");
123
+ return sandboxScopeKey(scope, sandbox);
124
+ }
88
125
  let scopeKey;
89
126
  try {
90
127
  const channelKey = encodeChannelKey(scope.channel);
@@ -101,8 +138,31 @@ const nativeBuildScopeKey = (scope) => {
101
138
  } catch (error) {
102
139
  throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
103
140
  }
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
- return scopeKey;
141
+ return checkedScopeKey(scopeKey);
142
+ };
143
+ /** The channel row a registration names, or the refusal of its channel. */
144
+ const channelIdOf = (channel) => {
145
+ try {
146
+ return `channel:${encodeChannelKey(channel)}`;
147
+ } catch (error) {
148
+ throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
149
+ }
150
+ };
151
+ /**
152
+ * A registration's scope key, from the registration's own facts: a sandbox
153
+ * build's from what its artifact says, whatever `sandbox` it names.
154
+ */
155
+ const registrationScopeKey = (registration) => {
156
+ channelIdOf(registration.channel);
157
+ return registration.isSandbox === true ? sandboxScopeKey(registration, {
158
+ appId: registration.sandboxAppId,
159
+ urlScheme: registration.sandboxUrlScheme,
160
+ artifactKind: registration.artifact.kind,
161
+ distribution: registeredDistribution(registration.artifact.kind, registration.exportMethod)
162
+ }) : nativeBuildScopeKey({
163
+ ...registration,
164
+ sandbox: null
165
+ });
106
166
  };
107
167
  /**
108
168
  * Refuses a patch from a sandbox build's built-in bundle: no deploy patches
@@ -114,19 +174,24 @@ const refuseSandboxPatchBase = async (db, baseBundleId) => {
114
174
  };
115
175
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
116
176
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
117
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
177
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, sandboxAppId, exportMethod, nativeAppVersion, artifact }) => {
118
178
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
119
179
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
120
180
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
121
181
  if (channel.trim().length === 0) return "channel is required";
122
182
  if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
123
- const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
124
- if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
125
- if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
126
183
  if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
127
184
  if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
128
185
  if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
129
186
  }
187
+ if (sandboxAppId !== void 0 && sandboxAppId !== null) {
188
+ if (isSandbox !== true) return "sandboxAppId is a sandbox build's, and this isn't one";
189
+ if (typeof sandboxAppId !== "string" || !APP_ID.test(sandboxAppId)) return "sandboxAppId must be the artifact's bundle identifier or application ID, up to 255 characters";
190
+ }
191
+ if (isSandbox === true) {
192
+ if (sandboxUrlScheme === void 0 || sandboxUrlScheme === null) return "a sandbox build needs the sandboxUrlScheme its artifact registers";
193
+ if (sandboxAppId === void 0 || sandboxAppId === null) return "a sandbox build needs the sandboxAppId its artifact reports, which an older hot-updater CLI doesn't send. Upgrade the hot-updater CLI to the version that matches this server, and build again";
194
+ }
130
195
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
131
196
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
132
197
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
@@ -146,8 +211,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
146
211
  async registerNativeBuild(registration) {
147
212
  const problem = problemOf(registration);
148
213
  if (problem !== null) throw new NativeBuildInputError(`Invalid native build: ${problem}.`);
149
- const scopeKey = nativeBuildScopeKey(registration);
150
- const channelId = `channel:${encodeChannelKey(registration.channel)}`;
214
+ const scopeKey = registrationScopeKey(registration);
215
+ const channelId = channelIdOf(registration.channel);
151
216
  const { embeddedBundle } = registration;
152
217
  const row = {
153
218
  id: registration.id,
@@ -233,7 +298,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
233
298
  });
234
299
  };
235
300
  const bundleId = options?.builtInOlderThan;
236
- if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
301
+ if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
237
302
  const { rows } = await read(1);
238
303
  const newest = rows[0];
239
304
  if (newest === void 0) return null;
@@ -152,7 +152,8 @@ const nativeBuildScopeOf = (url) => {
152
152
  const fingerprintHash = params.get("fingerprintHash");
153
153
  const appVersion = params.get("appVersion");
154
154
  if (platform === void 0 || !isText(channel) || fingerprintHash === null === (appVersion === null) || fingerprintHash === "" || appVersion === "") throw new require_handlerErrors.HandlerBadRequestError("A native build lookup needs platform, channel, and fingerprintHash or appVersion.");
155
- return fingerprintHash !== null ? {
155
+ const sandbox = sandboxScopeOf(params);
156
+ const scope = fingerprintHash !== null ? {
156
157
  platform,
157
158
  channel,
158
159
  fingerprintHash,
@@ -163,6 +164,38 @@ const nativeBuildScopeOf = (url) => {
163
164
  fingerprintHash: null,
164
165
  appVersion
165
166
  };
167
+ return sandbox === null ? scope : {
168
+ ...scope,
169
+ sandbox
170
+ };
171
+ };
172
+ /** The query parameters a sandbox lookup names, all four or none. */
173
+ const SANDBOX_SCOPE_PARAMS = [
174
+ "sandboxAppId",
175
+ "sandboxUrlScheme",
176
+ "artifactKind",
177
+ "distribution"
178
+ ];
179
+ /**
180
+ * A lookup's sandbox scope: null without one, and a bad request for one
181
+ * named in part. Core checks each value.
182
+ */
183
+ const sandboxScopeOf = (params) => {
184
+ const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
185
+ const named = [
186
+ appId,
187
+ urlScheme,
188
+ artifactKind,
189
+ distribution
190
+ ].filter((value) => value !== null).length;
191
+ if (named === 0) return null;
192
+ if (named !== SANDBOX_SCOPE_PARAMS.length) throw new require_handlerErrors.HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
193
+ return {
194
+ appId,
195
+ urlScheme,
196
+ artifactKind,
197
+ distribution
198
+ };
166
199
  };
167
200
  /** A native build or scope core refuses: a bad request. */
168
201
  const refusingInvalid = async (operation) => {
@@ -173,7 +206,7 @@ const refusingInvalid = async (operation) => {
173
206
  throw error;
174
207
  }
175
208
  };
176
- 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") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && 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));
209
+ 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") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.sandboxAppId === void 0 || isTextOrNull(value.sandboxAppId)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && 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));
177
210
  const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
178
211
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
179
212
  const createAdminRouteHandlers = () => ({
@@ -393,6 +426,7 @@ const createAdminRouteHandlers = () => ({
393
426
  if (!isText(issuerId)) throw new require_handlerErrors.HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
394
427
  return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
395
428
  }),
429
+ findIosDeviceAccount: onCore(async (core) => json({ data: await core.findIosDeviceAccount() })),
396
430
  markIosDevicesInBuild: onCore(async (core, request) => {
397
431
  const { buildId, ids } = await body(request);
398
432
  if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new require_handlerErrors.HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
@@ -586,6 +620,11 @@ const ADMIN_ROUTES = [
586
620
  path: "/ios-devices/in-build",
587
621
  handler: "markIosDevicesInBuild"
588
622
  },
623
+ {
624
+ method: "GET",
625
+ path: "/ios-devices/account",
626
+ handler: "findIosDeviceAccount"
627
+ },
589
628
  {
590
629
  method: "POST",
591
630
  path: "/ios-devices/account",
@@ -152,7 +152,8 @@ const nativeBuildScopeOf = (url) => {
152
152
  const fingerprintHash = params.get("fingerprintHash");
153
153
  const appVersion = params.get("appVersion");
154
154
  if (platform === void 0 || !isText(channel) || fingerprintHash === null === (appVersion === null) || fingerprintHash === "" || appVersion === "") throw new HandlerBadRequestError("A native build lookup needs platform, channel, and fingerprintHash or appVersion.");
155
- return fingerprintHash !== null ? {
155
+ const sandbox = sandboxScopeOf(params);
156
+ const scope = fingerprintHash !== null ? {
156
157
  platform,
157
158
  channel,
158
159
  fingerprintHash,
@@ -163,6 +164,38 @@ const nativeBuildScopeOf = (url) => {
163
164
  fingerprintHash: null,
164
165
  appVersion
165
166
  };
167
+ return sandbox === null ? scope : {
168
+ ...scope,
169
+ sandbox
170
+ };
171
+ };
172
+ /** The query parameters a sandbox lookup names, all four or none. */
173
+ const SANDBOX_SCOPE_PARAMS = [
174
+ "sandboxAppId",
175
+ "sandboxUrlScheme",
176
+ "artifactKind",
177
+ "distribution"
178
+ ];
179
+ /**
180
+ * A lookup's sandbox scope: null without one, and a bad request for one
181
+ * named in part. Core checks each value.
182
+ */
183
+ const sandboxScopeOf = (params) => {
184
+ const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
185
+ const named = [
186
+ appId,
187
+ urlScheme,
188
+ artifactKind,
189
+ distribution
190
+ ].filter((value) => value !== null).length;
191
+ if (named === 0) return null;
192
+ if (named !== SANDBOX_SCOPE_PARAMS.length) throw new HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
193
+ return {
194
+ appId,
195
+ urlScheme,
196
+ artifactKind,
197
+ distribution
198
+ };
166
199
  };
167
200
  /** A native build or scope core refuses: a bad request. */
168
201
  const refusingInvalid = async (operation) => {
@@ -173,7 +206,7 @@ const refusingInvalid = async (operation) => {
173
206
  throw error;
174
207
  }
175
208
  };
176
- 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") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && 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));
209
+ 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") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.sandboxAppId === void 0 || isTextOrNull(value.sandboxAppId)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && 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));
177
210
  const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
178
211
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
179
212
  const createAdminRouteHandlers = () => ({
@@ -393,6 +426,7 @@ const createAdminRouteHandlers = () => ({
393
426
  if (!isText(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
394
427
  return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
395
428
  }),
429
+ findIosDeviceAccount: onCore(async (core) => json({ data: await core.findIosDeviceAccount() })),
396
430
  markIosDevicesInBuild: onCore(async (core, request) => {
397
431
  const { buildId, ids } = await body(request);
398
432
  if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
@@ -586,6 +620,11 @@ const ADMIN_ROUTES = [
586
620
  path: "/ios-devices/in-build",
587
621
  handler: "markIosDevicesInBuild"
588
622
  },
623
+ {
624
+ method: "GET",
625
+ path: "/ios-devices/account",
626
+ handler: "findIosDeviceAccount"
627
+ },
589
628
  {
590
629
  method: "POST",
591
630
  path: "/ios-devices/account",
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.40";
2
+ var version = "1.2.0-rc.41";
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.40";
2
+ var version = "1.2.0-rc.41";
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.40",
3
+ "version": "1.2.0-rc.41",
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.40",
54
- "@hot-updater/plugin-insights": "1.2.0-rc.40",
55
- "@hot-updater/plugin-api-keys": "1.2.0-rc.40",
56
- "@hot-updater/plugin-remote-config": "1.2.0-rc.40",
57
- "@hot-updater/plugin-core": "1.2.0-rc.40"
53
+ "@hot-updater/protocol": "1.2.0-rc.41",
54
+ "@hot-updater/plugin-core": "1.2.0-rc.41",
55
+ "@hot-updater/plugin-api-keys": "1.2.0-rc.41",
56
+ "@hot-updater/plugin-insights": "1.2.0-rc.41",
57
+ "@hot-updater/plugin-remote-config": "1.2.0-rc.41"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "*",