@hot-updater/vercel 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.
@@ -17735,7 +17735,7 @@ const postgres = (config) => {
17735
17735
  };
17736
17736
  //#endregion
17737
17737
  //#region ../../packages/server/dist/version.mjs
17738
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.40";
17738
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.41";
17739
17739
  //#endregion
17740
17740
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
17741
17741
  const createVersionRouteHandlers = (plugins = []) => {
@@ -18969,6 +18969,11 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
18969
18969
  tx.update("ios_devices", row, { build_id: buildId });
18970
18970
  });
18971
18971
  },
18972
+ async findIosDeviceAccount() {
18973
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
18974
+ const issuerId = existing === null ? await accountOfRows() : existing.apple_issuer_id;
18975
+ return issuerId === null ? null : { issuerId };
18976
+ },
18972
18977
  async claimIosDeviceAccount(issuerId) {
18973
18978
  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.`);
18974
18979
  const answer = (held) => ({
@@ -19120,6 +19125,14 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
19120
19125
  const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
19121
19126
  const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
19122
19127
  const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
19128
+ const APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/;
19129
+ const FINGERPRINT_HASH = /^[A-Za-z0-9._~-]{1,255}$/;
19130
+ const DISTRIBUTIONS = {
19131
+ apk: ["direct"],
19132
+ app: ["direct"],
19133
+ aab: ["store"],
19134
+ ipa: ["direct", "store"]
19135
+ };
19123
19136
  var NativeBuildInputError = class extends TypeError {
19124
19137
  name = "NativeBuildInputError";
19125
19138
  };
@@ -19153,12 +19166,28 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
19153
19166
  "development",
19154
19167
  "enterprise"
19155
19168
  ]);
19156
- const SANDBOX_CHANNEL_PREFIX = "sandbox-";
19157
19169
  const OLDER_BUILDS_PAGE = 20;
19158
19170
  const MARK_ATTEMPTS = 8;
19159
19171
  const BUILD_NUMBER_MAX_LENGTH = 64;
19160
19172
  const SUBMITTED_VERSION_MAX_LENGTH = 255;
19173
+ const checkedScopeKey = (scopeKey) => {
19174
+ 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.`);
19175
+ return scopeKey;
19176
+ };
19177
+ const registeredDistribution = (kind, exportMethod) => kind !== "ipa" ? DISTRIBUTIONS[kind][0] : exportMethod === void 0 || exportMethod === null ? "unknown" : exportMethod === "app-store" ? "store" : "direct";
19178
+ const sandboxScopeKey = (scope, sandbox) => {
19179
+ const { appId, urlScheme, artifactKind, distribution } = sandbox;
19180
+ 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;
19181
+ if (problem !== null) throw new NativeBuildInputError(`Invalid sandbox build scope: ${problem}.`);
19182
+ const target = scope.fingerprintHash === null ? `app-version:${encodeURIComponent(scope.appVersion)}` : `fingerprint:${scope.fingerprintHash}`;
19183
+ return checkedScopeKey(`v1:sandbox:${scope.platform}:${appId}:${urlScheme}:${artifactKind}:${distribution}:${target}`);
19184
+ };
19161
19185
  const nativeBuildScopeKey = (scope) => {
19186
+ const { sandbox } = scope;
19187
+ if (sandbox !== void 0 && sandbox !== null) {
19188
+ if (sandbox.distribution !== "direct" && sandbox.distribution !== "store") throw new NativeBuildInputError("Invalid sandbox build scope: its distribution must be direct or store.");
19189
+ return sandboxScopeKey(scope, sandbox);
19190
+ }
19162
19191
  let scopeKey;
19163
19192
  try {
19164
19193
  const channelKey = encodeChannelKey(scope.channel);
@@ -19175,26 +19204,49 @@ const nativeBuildScopeKey = (scope) => {
19175
19204
  } catch (error) {
19176
19205
  throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
19177
19206
  }
19178
- 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.`);
19179
- return scopeKey;
19207
+ return checkedScopeKey(scopeKey);
19208
+ };
19209
+ const channelIdOf = (channel) => {
19210
+ try {
19211
+ return `channel:${encodeChannelKey(channel)}`;
19212
+ } catch (error) {
19213
+ throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
19214
+ }
19215
+ };
19216
+ const registrationScopeKey = (registration) => {
19217
+ channelIdOf(registration.channel);
19218
+ return registration.isSandbox === true ? sandboxScopeKey(registration, {
19219
+ appId: registration.sandboxAppId,
19220
+ urlScheme: registration.sandboxUrlScheme,
19221
+ artifactKind: registration.artifact.kind,
19222
+ distribution: registeredDistribution(registration.artifact.kind, registration.exportMethod)
19223
+ }) : nativeBuildScopeKey({
19224
+ ...registration,
19225
+ sandbox: null
19226
+ });
19180
19227
  };
19181
19228
  const refuseSandboxPatchBase = async (db, baseBundleId) => {
19182
19229
  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.");
19183
19230
  };
19184
19231
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
19185
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
19232
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, sandboxAppId, exportMethod, nativeAppVersion, artifact }) => {
19186
19233
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
19187
19234
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
19188
19235
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
19189
19236
  if (channel.trim().length === 0) return "channel is required";
19190
19237
  if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
19191
- const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
19192
- if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
19193
- if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
19194
19238
  if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
19195
19239
  if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
19196
19240
  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`;
19197
19241
  }
19242
+ if (sandboxAppId !== void 0 && sandboxAppId !== null) {
19243
+ if (isSandbox !== true) return "sandboxAppId is a sandbox build's, and this isn't one";
19244
+ if (typeof sandboxAppId !== "string" || !APP_ID.test(sandboxAppId)) return "sandboxAppId must be the artifact's bundle identifier or application ID, up to 255 characters";
19245
+ }
19246
+ if (isSandbox === true) {
19247
+ if (sandboxUrlScheme === void 0 || sandboxUrlScheme === null) return "a sandbox build needs the sandboxUrlScheme its artifact registers";
19248
+ 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";
19249
+ }
19198
19250
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
19199
19251
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
19200
19252
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
@@ -19213,8 +19265,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19213
19265
  async registerNativeBuild(registration) {
19214
19266
  const problem = problemOf(registration);
19215
19267
  if (problem !== null) throw new NativeBuildInputError(`Invalid native build: ${problem}.`);
19216
- const scopeKey = nativeBuildScopeKey(registration);
19217
- const channelId = `channel:${encodeChannelKey(registration.channel)}`;
19268
+ const scopeKey = registrationScopeKey(registration);
19269
+ const channelId = channelIdOf(registration.channel);
19218
19270
  const { embeddedBundle } = registration;
19219
19271
  const row = {
19220
19272
  id: registration.id,
@@ -19300,7 +19352,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19300
19352
  });
19301
19353
  };
19302
19354
  const bundleId = options?.builtInOlderThan;
19303
- if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
19355
+ if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
19304
19356
  const { rows } = await read(1);
19305
19357
  const newest = rows[0];
19306
19358
  if (newest === void 0) return null;
@@ -20263,7 +20315,8 @@ const nativeBuildScopeOf = (url) => {
20263
20315
  const fingerprintHash = params.get("fingerprintHash");
20264
20316
  const appVersion = params.get("appVersion");
20265
20317
  if (platform === void 0 || !isText$2(channel) || fingerprintHash === null === (appVersion === null) || fingerprintHash === "" || appVersion === "") throw new HandlerBadRequestError("A native build lookup needs platform, channel, and fingerprintHash or appVersion.");
20266
- return fingerprintHash !== null ? {
20318
+ const sandbox = sandboxScopeOf(params);
20319
+ const scope = fingerprintHash !== null ? {
20267
20320
  platform,
20268
20321
  channel,
20269
20322
  fingerprintHash,
@@ -20274,6 +20327,33 @@ const nativeBuildScopeOf = (url) => {
20274
20327
  fingerprintHash: null,
20275
20328
  appVersion
20276
20329
  };
20330
+ return sandbox === null ? scope : {
20331
+ ...scope,
20332
+ sandbox
20333
+ };
20334
+ };
20335
+ const SANDBOX_SCOPE_PARAMS = [
20336
+ "sandboxAppId",
20337
+ "sandboxUrlScheme",
20338
+ "artifactKind",
20339
+ "distribution"
20340
+ ];
20341
+ const sandboxScopeOf = (params) => {
20342
+ const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
20343
+ const named = [
20344
+ appId,
20345
+ urlScheme,
20346
+ artifactKind,
20347
+ distribution
20348
+ ].filter((value) => value !== null).length;
20349
+ if (named === 0) return null;
20350
+ if (named !== SANDBOX_SCOPE_PARAMS.length) throw new HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
20351
+ return {
20352
+ appId,
20353
+ urlScheme,
20354
+ artifactKind,
20355
+ distribution
20356
+ };
20277
20357
  };
20278
20358
  const refusingInvalid = async (operation) => {
20279
20359
  try {
@@ -20283,7 +20363,7 @@ const refusingInvalid = async (operation) => {
20283
20363
  throw error;
20284
20364
  }
20285
20365
  };
20286
- const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull$1(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull$1(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull$1(value.nativeAppVersion)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
20366
+ const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull$1(value.sandboxUrlScheme)) && (value.sandboxAppId === void 0 || isTextOrNull$1(value.sandboxAppId)) && (value.exportMethod === void 0 || isTextOrNull$1(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull$1(value.nativeAppVersion)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
20287
20367
  const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
20288
20368
  const createAdminRouteHandlers = () => ({
20289
20369
  listBundles: onCore(async (core, request) => {
@@ -20498,6 +20578,7 @@ const createAdminRouteHandlers = () => ({
20498
20578
  if (!isText$2(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
20499
20579
  return json$2({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
20500
20580
  }),
20581
+ findIosDeviceAccount: onCore(async (core) => json$2({ data: await core.findIosDeviceAccount() })),
20501
20582
  markIosDevicesInBuild: onCore(async (core, request) => {
20502
20583
  const { buildId, ids } = await body(request);
20503
20584
  if (!isText$2(buildId) || !Array.isArray(ids) || !ids.every((id) => isText$2(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
@@ -20690,6 +20771,11 @@ const ADMIN_ROUTES = [
20690
20771
  path: "/ios-devices/in-build",
20691
20772
  handler: "markIosDevicesInBuild"
20692
20773
  },
20774
+ {
20775
+ method: "GET",
20776
+ path: "/ios-devices/account",
20777
+ handler: "findIosDeviceAccount"
20778
+ },
20693
20779
  {
20694
20780
  method: "POST",
20695
20781
  path: "/ios-devices/account",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/vercel",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.40",
4
+ "version": "1.2.0-rc.41",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -41,11 +41,11 @@
41
41
  "@vercel/cli-auth": "0.3.10",
42
42
  "@vercel/cli-config": "0.3.1",
43
43
  "pg": "8.13.1",
44
- "@hot-updater/cli-tools": "1.2.0-rc.40",
45
- "@hot-updater/postgres": "1.2.0-rc.40",
46
- "@hot-updater/plugin-core": "1.2.0-rc.40",
47
- "@hot-updater/protocol": "1.2.0-rc.40",
48
- "@hot-updater/server": "1.2.0-rc.40"
44
+ "@hot-updater/cli-tools": "1.2.0-rc.41",
45
+ "@hot-updater/postgres": "1.2.0-rc.41",
46
+ "@hot-updater/protocol": "1.2.0-rc.41",
47
+ "@hot-updater/server": "1.2.0-rc.41",
48
+ "@hot-updater/plugin-core": "1.2.0-rc.41"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^20",
@@ -54,7 +54,7 @@
54
54
  "execa": "9.5.2",
55
55
  "kysely": "0.28.17",
56
56
  "vitest": "4.1.4",
57
- "@hot-updater/test-utils": "1.2.0-rc.40"
57
+ "@hot-updater/test-utils": "1.2.0-rc.41"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsdown",