@hot-updater/server 1.2.0-rc.42 → 1.2.0-rc.43

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,7 +40,9 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
40
40
  readonly buildKey?: string;
41
41
  readonly storeBuild?: true;
42
42
  readonly builtInOlderThan?: string;
43
+ readonly artifactKind?: import("@hot-updater/plugin-core").NativeBuildArtifactKind;
43
44
  }) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
45
+ findNativeBuildSibling: (build: import("@hot-updater/plugin-core").NativeBuildRow) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
44
46
  listNativeBuilds: (input: import("@hot-updater/plugin-core").KeysetInput & {
45
47
  readonly channelId?: string;
46
48
  }) => Promise<import("@hot-updater/plugin-core").NativeBuildRow[]>;
@@ -40,7 +40,9 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
40
40
  readonly buildKey?: string;
41
41
  readonly storeBuild?: true;
42
42
  readonly builtInOlderThan?: string;
43
+ readonly artifactKind?: import("@hot-updater/plugin-core").NativeBuildArtifactKind;
43
44
  }) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
45
+ findNativeBuildSibling: (build: import("@hot-updater/plugin-core").NativeBuildRow) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
44
46
  listNativeBuilds: (input: import("@hot-updater/plugin-core").KeysetInput & {
45
47
  readonly channelId?: string;
46
48
  }) => Promise<import("@hot-updater/plugin-core").NativeBuildRow[]>;
@@ -206,6 +206,51 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
206
206
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
207
207
  return null;
208
208
  };
209
+ /** The other install target of an iOS sandbox build's native code. */
210
+ const SIBLING_KINDS = {
211
+ app: "ipa",
212
+ ipa: "app"
213
+ };
214
+ /**
215
+ * Whether a build is one a person installs from its file: a Simulator `.app`,
216
+ * or an `.ipa` exported for direct install, that no store took and that isn't
217
+ * the store build. One rule for a sibling and the build it is found from, so
218
+ * a build that shows its sibling is shown by it.
219
+ */
220
+ const isInstallTarget = (build) => !build.is_store_build && build.submitted_to === null && (build.artifact_kind === "app" || build.artifact_kind === "ipa" && build.export_method !== null && build.export_method !== "app-store");
221
+ /**
222
+ * The scope key of the other install target of a sandbox build, from its own
223
+ * key's app ID and URL scheme, which hold no colon, and its row's fingerprint
224
+ * or app version, through `sandboxScopeKey`; null for a key it didn't make.
225
+ */
226
+ const siblingSandboxScopeKey = (build, artifactKind) => {
227
+ const [version, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
228
+ if (version !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
229
+ const target = build.fingerprint_hash === null ? {
230
+ platform: build.platform,
231
+ fingerprintHash: null,
232
+ appVersion: build.app_version ?? ""
233
+ } : {
234
+ platform: build.platform,
235
+ fingerprintHash: build.fingerprint_hash,
236
+ appVersion: null
237
+ };
238
+ try {
239
+ return sandboxScopeKey(target, {
240
+ appId,
241
+ urlScheme,
242
+ artifactKind: build.artifact_kind,
243
+ distribution: registeredDistribution(build.artifact_kind, build.export_method)
244
+ }) === build.scope_key ? sandboxScopeKey(target, {
245
+ appId,
246
+ urlScheme,
247
+ artifactKind,
248
+ distribution: "direct"
249
+ }) : null;
250
+ } catch {
251
+ return null;
252
+ }
253
+ };
209
254
  /** The native build registry: core's `native_builds` and the built-in bundle rows. */
210
255
  const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
211
256
  async registerNativeBuild(registration) {
@@ -274,9 +319,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
274
319
  const scopeKey = nativeBuildScopeKey(scope);
275
320
  const buildKey = options?.buildKey;
276
321
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
322
+ const artifactKind = options?.artifactKind;
323
+ if (artifactKind !== void 0 && !ARTIFACT_KINDS[scope.platform].includes(artifactKind)) throw new NativeBuildInputError(`Invalid native build kind: an ${scope.platform} build is ${ARTIFACT_KINDS[scope.platform].join(" or ")}.`);
324
+ const ofKind = (row) => artifactKind === void 0 || row.artifact_kind === artifactKind;
277
325
  if (options?.storeBuild) {
278
326
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
279
- return marked === null ? null : pick(marked);
327
+ return marked === null || !ofKind(marked) ? null : pick(marked);
280
328
  }
281
329
  const read = (limit, before) => {
282
330
  const page = {
@@ -284,34 +332,60 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
284
332
  limit,
285
333
  ...before === void 0 ? {} : { range: { lt: before } }
286
334
  };
287
- return buildKey === void 0 ? db.findMany("native_builds", {
288
- index: "byScope",
289
- where: { scope_key: scopeKey },
290
- ...page
291
- }) : db.findMany("native_builds", {
335
+ return buildKey !== void 0 ? db.findMany("native_builds", {
292
336
  index: "byBuildKey",
293
337
  where: {
294
338
  scope_key: scopeKey,
295
339
  build_key: buildKey
296
340
  },
297
341
  ...page
342
+ }) : artifactKind !== void 0 ? db.findMany("native_builds", {
343
+ index: "byScopeKind",
344
+ where: {
345
+ scope_key: scopeKey,
346
+ artifact_kind: artifactKind
347
+ },
348
+ ...page
349
+ }) : db.findMany("native_builds", {
350
+ index: "byScope",
351
+ where: { scope_key: scopeKey },
352
+ ...page
298
353
  });
299
354
  };
300
355
  const bundleId = options?.builtInOlderThan;
301
356
  if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
302
357
  const { rows } = await read(1);
303
- const newest = rows[0];
304
- if (newest === void 0) return null;
305
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
358
+ const newest = (rows[0] === void 0 ? void 0 : pick(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
359
+ index: "byScope",
360
+ where: { scope_key: scopeKey },
361
+ order: "desc",
362
+ limit: 1
363
+ }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
364
+ if (newest === void 0 || !ofKind(newest)) return null;
365
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
306
366
  for (let before = newest.id;;) {
307
367
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
308
368
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
309
- if (usable !== void 0) return pick(usable);
369
+ if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
310
370
  const last = older.at(-1);
311
371
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
312
372
  before = last.id;
313
373
  }
314
374
  },
375
+ async findNativeBuildSibling(build) {
376
+ const artifactKind = SIBLING_KINDS[build.artifact_kind];
377
+ if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
378
+ const scopeKey = siblingSandboxScopeKey(build, artifactKind);
379
+ if (scopeKey === null) return null;
380
+ const { rows } = await db.findMany("native_builds", {
381
+ index: "byScope",
382
+ where: { scope_key: scopeKey },
383
+ order: "desc",
384
+ limit: 1
385
+ });
386
+ const sibling = rows[0] === void 0 ? null : pick(rows[0]);
387
+ return sibling !== null && isInstallTarget(sibling) ? sibling : null;
388
+ },
315
389
  async recordNativeBuildSubmission(id, { destination, version }) {
316
390
  if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
317
391
  return db.transaction(async (tx) => {
@@ -206,6 +206,51 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
206
206
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
207
207
  return null;
208
208
  };
209
+ /** The other install target of an iOS sandbox build's native code. */
210
+ const SIBLING_KINDS = {
211
+ app: "ipa",
212
+ ipa: "app"
213
+ };
214
+ /**
215
+ * Whether a build is one a person installs from its file: a Simulator `.app`,
216
+ * or an `.ipa` exported for direct install, that no store took and that isn't
217
+ * the store build. One rule for a sibling and the build it is found from, so
218
+ * a build that shows its sibling is shown by it.
219
+ */
220
+ const isInstallTarget = (build) => !build.is_store_build && build.submitted_to === null && (build.artifact_kind === "app" || build.artifact_kind === "ipa" && build.export_method !== null && build.export_method !== "app-store");
221
+ /**
222
+ * The scope key of the other install target of a sandbox build, from its own
223
+ * key's app ID and URL scheme, which hold no colon, and its row's fingerprint
224
+ * or app version, through `sandboxScopeKey`; null for a key it didn't make.
225
+ */
226
+ const siblingSandboxScopeKey = (build, artifactKind) => {
227
+ const [version, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
228
+ if (version !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
229
+ const target = build.fingerprint_hash === null ? {
230
+ platform: build.platform,
231
+ fingerprintHash: null,
232
+ appVersion: build.app_version ?? ""
233
+ } : {
234
+ platform: build.platform,
235
+ fingerprintHash: build.fingerprint_hash,
236
+ appVersion: null
237
+ };
238
+ try {
239
+ return sandboxScopeKey(target, {
240
+ appId,
241
+ urlScheme,
242
+ artifactKind: build.artifact_kind,
243
+ distribution: registeredDistribution(build.artifact_kind, build.export_method)
244
+ }) === build.scope_key ? sandboxScopeKey(target, {
245
+ appId,
246
+ urlScheme,
247
+ artifactKind,
248
+ distribution: "direct"
249
+ }) : null;
250
+ } catch {
251
+ return null;
252
+ }
253
+ };
209
254
  /** The native build registry: core's `native_builds` and the built-in bundle rows. */
210
255
  const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
211
256
  async registerNativeBuild(registration) {
@@ -274,9 +319,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
274
319
  const scopeKey = nativeBuildScopeKey(scope);
275
320
  const buildKey = options?.buildKey;
276
321
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
322
+ const artifactKind = options?.artifactKind;
323
+ if (artifactKind !== void 0 && !ARTIFACT_KINDS[scope.platform].includes(artifactKind)) throw new NativeBuildInputError(`Invalid native build kind: an ${scope.platform} build is ${ARTIFACT_KINDS[scope.platform].join(" or ")}.`);
324
+ const ofKind = (row) => artifactKind === void 0 || row.artifact_kind === artifactKind;
277
325
  if (options?.storeBuild) {
278
326
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
279
- return marked === null ? null : pick(marked);
327
+ return marked === null || !ofKind(marked) ? null : pick(marked);
280
328
  }
281
329
  const read = (limit, before) => {
282
330
  const page = {
@@ -284,34 +332,60 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
284
332
  limit,
285
333
  ...before === void 0 ? {} : { range: { lt: before } }
286
334
  };
287
- return buildKey === void 0 ? db.findMany("native_builds", {
288
- index: "byScope",
289
- where: { scope_key: scopeKey },
290
- ...page
291
- }) : db.findMany("native_builds", {
335
+ return buildKey !== void 0 ? db.findMany("native_builds", {
292
336
  index: "byBuildKey",
293
337
  where: {
294
338
  scope_key: scopeKey,
295
339
  build_key: buildKey
296
340
  },
297
341
  ...page
342
+ }) : artifactKind !== void 0 ? db.findMany("native_builds", {
343
+ index: "byScopeKind",
344
+ where: {
345
+ scope_key: scopeKey,
346
+ artifact_kind: artifactKind
347
+ },
348
+ ...page
349
+ }) : db.findMany("native_builds", {
350
+ index: "byScope",
351
+ where: { scope_key: scopeKey },
352
+ ...page
298
353
  });
299
354
  };
300
355
  const bundleId = options?.builtInOlderThan;
301
356
  if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
302
357
  const { rows } = await read(1);
303
- const newest = rows[0];
304
- if (newest === void 0) return null;
305
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
358
+ const newest = (rows[0] === void 0 ? void 0 : pick(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
359
+ index: "byScope",
360
+ where: { scope_key: scopeKey },
361
+ order: "desc",
362
+ limit: 1
363
+ }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
364
+ if (newest === void 0 || !ofKind(newest)) return null;
365
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
306
366
  for (let before = newest.id;;) {
307
367
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
308
368
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
309
- if (usable !== void 0) return pick(usable);
369
+ if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
310
370
  const last = older.at(-1);
311
371
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
312
372
  before = last.id;
313
373
  }
314
374
  },
375
+ async findNativeBuildSibling(build) {
376
+ const artifactKind = SIBLING_KINDS[build.artifact_kind];
377
+ if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
378
+ const scopeKey = siblingSandboxScopeKey(build, artifactKind);
379
+ if (scopeKey === null) return null;
380
+ const { rows } = await db.findMany("native_builds", {
381
+ index: "byScope",
382
+ where: { scope_key: scopeKey },
383
+ order: "desc",
384
+ limit: 1
385
+ });
386
+ const sibling = rows[0] === void 0 ? null : pick(rows[0]);
387
+ return sibling !== null && isInstallTarget(sibling) ? sibling : null;
388
+ },
315
389
  async recordNativeBuildSubmission(id, { destination, version }) {
316
390
  if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
317
391
  return db.transaction(async (tx) => {
@@ -337,13 +337,19 @@ const createAdminRouteHandlers = () => ({
337
337
  const scope = nativeBuildScopeOf(url);
338
338
  const buildKey = url.searchParams.get("buildKey");
339
339
  const builtInOlderThan = url.searchParams.get("builtInOlderThan");
340
+ const kind = url.searchParams.get("kind");
340
341
  const options = {
341
342
  ...buildKey === null ? {} : { buildKey },
342
343
  ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
343
- ...builtInOlderThan === null ? {} : { builtInOlderThan }
344
+ ...builtInOlderThan === null ? {} : { builtInOlderThan },
345
+ ...kind === null ? {} : { artifactKind: kind }
344
346
  };
345
347
  return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
346
348
  }),
349
+ findNativeBuildSibling: onCore(async (core, _request, params) => {
350
+ const build = await core.getNativeBuild(require_handlerParameters.requireRouteParam(params, "id"));
351
+ return json({ data: build === null ? null : await core.findNativeBuildSibling(build) });
352
+ }),
347
353
  getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
348
354
  listNativeBuilds: onCore(async (core, request) => {
349
355
  const url = new URL(request.url);
@@ -575,6 +581,11 @@ const ADMIN_ROUTES = [
575
581
  path: "/native-builds/latest",
576
582
  handler: "findNativeBuild"
577
583
  },
584
+ {
585
+ method: "GET",
586
+ path: "/native-builds/:id/sibling",
587
+ handler: "findNativeBuildSibling"
588
+ },
578
589
  {
579
590
  method: "GET",
580
591
  path: "/native-builds/:id",
@@ -337,13 +337,19 @@ const createAdminRouteHandlers = () => ({
337
337
  const scope = nativeBuildScopeOf(url);
338
338
  const buildKey = url.searchParams.get("buildKey");
339
339
  const builtInOlderThan = url.searchParams.get("builtInOlderThan");
340
+ const kind = url.searchParams.get("kind");
340
341
  const options = {
341
342
  ...buildKey === null ? {} : { buildKey },
342
343
  ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
343
- ...builtInOlderThan === null ? {} : { builtInOlderThan }
344
+ ...builtInOlderThan === null ? {} : { builtInOlderThan },
345
+ ...kind === null ? {} : { artifactKind: kind }
344
346
  };
345
347
  return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
346
348
  }),
349
+ findNativeBuildSibling: onCore(async (core, _request, params) => {
350
+ const build = await core.getNativeBuild(requireRouteParam(params, "id"));
351
+ return json({ data: build === null ? null : await core.findNativeBuildSibling(build) });
352
+ }),
347
353
  getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
348
354
  listNativeBuilds: onCore(async (core, request) => {
349
355
  const url = new URL(request.url);
@@ -575,6 +581,11 @@ const ADMIN_ROUTES = [
575
581
  path: "/native-builds/latest",
576
582
  handler: "findNativeBuild"
577
583
  },
584
+ {
585
+ method: "GET",
586
+ path: "/native-builds/:id/sibling",
587
+ handler: "findNativeBuildSibling"
588
+ },
578
589
  {
579
590
  method: "GET",
580
591
  path: "/native-builds/:id",
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.42";
2
+ var version = "1.2.0-rc.43";
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.42";
2
+ var version = "1.2.0-rc.43";
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.42",
3
+ "version": "1.2.0-rc.43",
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-core": "1.2.0-rc.42",
54
- "@hot-updater/plugin-api-keys": "1.2.0-rc.42",
55
- "@hot-updater/plugin-insights": "1.2.0-rc.42",
56
- "@hot-updater/protocol": "1.2.0-rc.42",
57
- "@hot-updater/plugin-remote-config": "1.2.0-rc.42"
53
+ "@hot-updater/protocol": "1.2.0-rc.43",
54
+ "@hot-updater/plugin-core": "1.2.0-rc.43",
55
+ "@hot-updater/plugin-api-keys": "1.2.0-rc.43",
56
+ "@hot-updater/plugin-remote-config": "1.2.0-rc.43",
57
+ "@hot-updater/plugin-insights": "1.2.0-rc.43"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "*",