@hot-updater/protocol 1.2.0-rc.24 → 1.2.0-rc.25

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.
@@ -296,6 +296,12 @@ const readAndroidManifest = (manifest) => {
296
296
  const metaData = /* @__PURE__ */ new Map();
297
297
  const launchers = [];
298
298
  const urlSchemes = /* @__PURE__ */ new Map();
299
+ const componentMetaData = /* @__PURE__ */ new Map();
300
+ const metaDataOf = (element, into) => {
301
+ const name = attributeOf(element, NAME, "name");
302
+ const value = attributeOf(element, VALUE, "value") ?? attributeOf(element, RESOURCE, "resource");
303
+ if (name?.type === "string" && value !== null) into.set(name.value, value);
304
+ };
299
305
  const stringAttribute = (element, id, name) => {
300
306
  const value = attributeOf(element, id, name);
301
307
  return value?.type === "string" ? value.value : null;
@@ -304,10 +310,17 @@ const readAndroidManifest = (manifest) => {
304
310
  if (COMPONENTS.has(element.name)) {
305
311
  const component = stringAttribute(element, NAME, "name");
306
312
  if (component === null) continue;
313
+ for (const item of element.children) {
314
+ if (item.name !== "meta-data") continue;
315
+ const own = componentMetaData.get(component) ?? /* @__PURE__ */ new Map();
316
+ metaDataOf(item, own);
317
+ componentMetaData.set(component, own);
318
+ }
307
319
  for (const filter of element.children) {
308
320
  if (filter.name !== "intent-filter") continue;
309
321
  const named = (child) => filter.children.filter(({ name }) => name === child).map((part) => stringAttribute(part, NAME, "name"));
310
322
  if (named("action").includes("android.intent.action.MAIN") && named("category").includes("android.intent.category.LAUNCHER") && !launchers.includes(component)) launchers.push(component);
323
+ if (!named("action").includes("android.intent.action.VIEW")) continue;
311
324
  for (const data of filter.children) {
312
325
  if (data.name !== "data") continue;
313
326
  const scheme = stringAttribute(data, SCHEME, "scheme");
@@ -318,9 +331,7 @@ const readAndroidManifest = (manifest) => {
318
331
  continue;
319
332
  }
320
333
  if (element.name !== "meta-data") continue;
321
- const name = attributeOf(element, NAME, "name");
322
- const value = attributeOf(element, VALUE, "value") ?? attributeOf(element, RESOURCE, "resource");
323
- if (name?.type === "string" && value !== null) metaData.set(name.value, value);
334
+ metaDataOf(element, metaData);
324
335
  }
325
336
  return {
326
337
  packageName: packageValue?.type === "string" ? packageValue.value : null,
@@ -328,7 +339,8 @@ const readAndroidManifest = (manifest) => {
328
339
  versionCode: versionCode?.type === "int" ? versionCode.value : null,
329
340
  metaData,
330
341
  launchers,
331
- urlSchemes
342
+ urlSchemes,
343
+ componentMetaData
332
344
  };
333
345
  };
334
346
  //#endregion
@@ -568,12 +580,50 @@ const parsePlist = (bytes) => {
568
580
  const SANDBOX_CODE_MARKER = "HOT_UPDATER_SANDBOX_NATIVE_LAYER";
569
581
  /** The Info.plist key an iOS sandbox build declares itself with. */
570
582
  const SANDBOX_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX";
583
+ /**
584
+ * The Info.plist key that records the URL scheme an iOS sandbox build
585
+ * registers in its `SANDBOX_URL_TYPE_NAME` URL type: the build reads its own
586
+ * scheme from it, and a later patch knows which scheme is the sandbox's.
587
+ */
588
+ const SANDBOX_URL_SCHEME_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX_URL_SCHEME";
589
+ const URL_SCHEME_SYNTAX = /^[a-z][a-z0-9+.-]*$/;
590
+ /**
591
+ * Whether a value is a URL scheme in lower-case ASCII, as written: what a
592
+ * build records, read before any lower-casing.
593
+ */
594
+ const isRecordedUrlSchemeSyntax = (value) => typeof value === "string" && URL_SCHEME_SYNTAX.test(value);
595
+ /**
596
+ * The URL scheme an iOS sandbox build registers, by one rule its patch, its
597
+ * reader, and its own code apply alike. `recorded` is the Info.plist's
598
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY`, undefined when the key is absent, and
599
+ * `namedTypes` its URL types named `SANDBOX_URL_TYPE_NAME`.
600
+ * - Absent: a prerelease's build, which recorded none. Undefined: the caller
601
+ * reads it the way that build was read.
602
+ * - Present: a scheme in lower-case ASCII, as written, that the one URL type
603
+ * of the name holds alone. Anything else is null, with no fallback.
604
+ */
605
+ const recordedSandboxUrlScheme = (recorded, namedTypes) => {
606
+ if (recorded === void 0) return void 0;
607
+ if (!isRecordedUrlSchemeSyntax(recorded) || namedTypes.length !== 1) return null;
608
+ const schemes = namedTypes[0]?.CFBundleURLSchemes;
609
+ return Array.isArray(schemes) && schemes.length === 1 && schemes[0] === recorded ? recorded : null;
610
+ };
571
611
  /** The `<meta-data>` an Android sandbox build declares itself with. */
572
612
  const SANDBOX_META_DATA = "com.hotupdater.SANDBOX";
573
613
  /** The activity that takes an Android sandbox build's launcher entry and links. */
574
614
  const SANDBOX_ACTIVITY = "com.hotupdater.HotUpdaterSandboxActivity";
575
615
  /** The `applicationIdSuffix` an Android sandbox build appends. */
576
616
  const SANDBOX_APPLICATION_ID_SUFFIX = ".sandbox";
617
+ /**
618
+ * The `CFBundleURLName` of the URL type an iOS sandbox build registers its URL
619
+ * scheme with, which the build reads its own scheme from.
620
+ */
621
+ const SANDBOX_URL_TYPE_NAME = "hot-updater-sandbox";
622
+ /**
623
+ * The `<meta-data>` of `SANDBOX_ACTIVITY` that names the URL scheme an Android
624
+ * sandbox build registers, which the build reads its own scheme from.
625
+ */
626
+ const SANDBOX_URL_SCHEME_META_DATA = "com.hotupdater.sandbox.URL_SCHEME";
577
627
  const SANDBOX_CHANNEL_PREFIX = "sandbox-";
578
628
  const SANDBOX_URL_SCHEME_PREFIX = "hu-sandbox-";
579
629
  /**
@@ -585,32 +635,62 @@ const sandboxChannelOf = (scheme) => `${SANDBOX_CHANNEL_PREFIX}${scheme}`;
585
635
  /** Whether a channel is reserved for sandbox builds. */
586
636
  const isSandboxChannel = (channel) => channel.startsWith(SANDBOX_CHANNEL_PREFIX);
587
637
  /**
588
- * The URL scheme only a sandbox build registers, derived from the app's ID:
589
- * the app's own scheme would ask which app to open beside the store app.
638
+ * The URL scheme a sandbox build registers when its scheme sets none, derived
639
+ * from the app's ID: the app's own scheme would ask which app to open beside
640
+ * the store app.
590
641
  */
591
642
  const sandboxUrlSchemeOf = (appId) => `${SANDBOX_URL_SCHEME_PREFIX}${appId.toLowerCase().replace(/[^a-z0-9]+/gu, "-")}`;
592
- /** Whether a URL scheme is one a sandbox build registers. */
643
+ /**
644
+ * Whether a URL scheme has the prefix of the derived one: how an artifact built
645
+ * before the URL scheme could be set is read, which registered no other.
646
+ */
593
647
  const isSandboxUrlScheme = (scheme) => scheme.toLowerCase().startsWith(SANDBOX_URL_SCHEME_PREFIX);
648
+ const CONFIGURED_URL_SCHEME = /^[a-z][a-z0-9+.-]{0,63}$/u;
649
+ const RESERVED_URL_SCHEMES = /* @__PURE__ */ new Set([
650
+ "http",
651
+ "https",
652
+ "file",
653
+ "data",
654
+ "javascript",
655
+ "true",
656
+ "false"
657
+ ]);
594
658
  /**
595
- * The link a preview QR holds. `appId` is the scheme's `bundleIdentifier` or
596
- * `packageName`: the ID before the Android sandbox's `.sandbox` suffix.
659
+ * Whether `sandbox: { urlScheme }` can name a URL scheme: lower case, a letter
660
+ * then up to 63 letters, digits, `+`, `.` or `-`, none the system or a browser
661
+ * owns, and neither `true` nor `false`, which Android's manifest can't hold as
662
+ * a string.
597
663
  */
598
- const createPreviewLink = ({ appId, channel, fingerprintHash }) => {
664
+ const isConfigurableSandboxUrlScheme = (urlScheme) => CONFIGURED_URL_SCHEME.test(urlScheme) && !RESERVED_URL_SCHEMES.has(urlScheme);
665
+ /**
666
+ * The link a preview QR holds. `urlScheme` is the one the sandbox build
667
+ * registered; without it, the one derived from `appId`, the scheme's
668
+ * `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
669
+ * `.sandbox` suffix.
670
+ */
671
+ const createPreviewLink = ({ urlScheme, appId, channel, fingerprintHash }) => {
599
672
  require_uuid.assertCanonicalChannelName(channel);
600
- return `${sandboxUrlSchemeOf(appId)}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
673
+ return `${(urlScheme ?? sandboxUrlSchemeOf(appId)).toLowerCase()}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
601
674
  };
602
- const PREVIEW_LINK = /^(hu-sandbox-[a-z0-9-]+):\/\/hot-updater\/preview\?([^#]*)$/iu;
675
+ /** Any URL scheme: which app's it is, the app that opens the link decides. */
676
+ const PREVIEW_LINK = /^([a-z][a-z0-9+.-]*):\/\/hot-updater\/preview\?([^#]*)$/iu;
677
+ /**
678
+ * A URL scheme in ASCII alone: case folding lets `/iu` match `K` (Kelvin) or
679
+ * `ſ` as a letter.
680
+ */
681
+ const ASCII_URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
603
682
  const MAX_FINGERPRINT_LENGTH = 256;
604
683
  /**
605
684
  * What a preview link says, or null for anything else: another shape, a
606
- * repeated or missing parameter, or a channel no release can target. Native
607
- * code parses it the same way before any JavaScript runs, in
685
+ * repeated or missing parameter, or a channel no release can target. It takes
686
+ * any URL scheme: a sandbox build refuses a link of another scheme than its
687
+ * own. Native code parses it the same way before any JavaScript runs, in
608
688
  * HotUpdaterSandboxLink, and shares the vectors in test-utils'
609
689
  * `sandbox-preview-links.json`.
610
690
  */
611
691
  const parsePreviewLink = (link) => {
612
692
  const match = PREVIEW_LINK.exec(link);
613
- if (match === null) return null;
693
+ if (match === null || !ASCII_URL_SCHEME.test(match[1])) return null;
614
694
  const parameters = /* @__PURE__ */ new Map();
615
695
  for (const parameter of match[2].split("&")) {
616
696
  const separator = parameter.indexOf("=");
@@ -1063,7 +1143,7 @@ const readAndroid = async (source, kind, entries, budget) => {
1063
1143
  },
1064
1144
  entry: {
1065
1145
  launchers: manifest.launchers,
1066
- sandboxUrlScheme: manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity")?.find(isSandboxUrlScheme) ?? null
1146
+ sandboxUrlScheme: androidSandboxUrlScheme(manifest)
1067
1147
  },
1068
1148
  builtInBundle: bundle === void 0 ? null : {
1069
1149
  path: bundle.name,
@@ -1071,16 +1151,41 @@ const readAndroid = async (source, kind, entries, budget) => {
1071
1151
  }
1072
1152
  };
1073
1153
  };
1074
- /** The sandbox URL scheme in an Info.plist's `CFBundleURLTypes`, or null. */
1154
+ /**
1155
+ * The URL scheme an Android sandbox build registers, or null: the one its
1156
+ * activity's `SANDBOX_URL_SCHEME_META_DATA` names, when the activity's `VIEW`
1157
+ * filters take it too. An artifact built before the meta-data takes the one
1158
+ * with the derived scheme's prefix.
1159
+ */
1160
+ const androidSandboxUrlScheme = (manifest) => {
1161
+ const schemes = manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity") ?? [];
1162
+ const declared = manifest.componentMetaData.get(SANDBOX_ACTIVITY)?.get(SANDBOX_URL_SCHEME_META_DATA);
1163
+ if (declared === void 0) return schemes.find(isSandboxUrlScheme) ?? null;
1164
+ if (declared.type !== "string") return null;
1165
+ return schemes.includes(declared.value) ? declared.value : null;
1166
+ };
1167
+ /**
1168
+ * The sandbox URL scheme of an Info.plist, or null: the one
1169
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY` records, by `recordedSandboxUrlScheme`'s
1170
+ * rule. A prerelease's artifact, with no key, gives its named URL type's one
1171
+ * scheme, or, with no named type, one with the derived scheme's prefix.
1172
+ */
1075
1173
  const sandboxUrlSchemeIn = (info) => {
1076
1174
  const types = info["CFBundleURLTypes"];
1077
1175
  if (!Array.isArray(types)) return null;
1078
- for (const type of types) {
1176
+ const schemesOf = (type) => {
1079
1177
  const schemes = type?.CFBundleURLSchemes;
1080
- if (!Array.isArray(schemes)) continue;
1081
- for (const scheme of schemes) if (typeof scheme === "string" && isSandboxUrlScheme(scheme)) return scheme;
1178
+ return Array.isArray(schemes) ? schemes.filter((scheme) => typeof scheme === "string") : [];
1179
+ };
1180
+ const named = types.filter((type) => type?.CFBundleURLName === SANDBOX_URL_TYPE_NAME);
1181
+ const recorded = recordedSandboxUrlScheme("HOT_UPDATER_SANDBOX_URL_SCHEME" in info ? info[SANDBOX_URL_SCHEME_INFO_PLIST_KEY] : void 0, named);
1182
+ if (recorded !== void 0) return recorded;
1183
+ if (named.length > 1) return null;
1184
+ if (named.length === 1) {
1185
+ const schemes = schemesOf(named[0]);
1186
+ return schemes.length === 1 ? schemes[0] : null;
1082
1187
  }
1083
- return null;
1188
+ return types.flatMap(schemesOf).find(isSandboxUrlScheme) ?? null;
1084
1189
  };
1085
1190
  const stringValue = (value) => typeof value === "string" && value !== "" ? value : null;
1086
1191
  const readIos = async (source, kind, entries, budget) => {
@@ -1265,7 +1370,8 @@ const checkNativeArtifact = (info, { updateStrategy, appIds = [], channel: chann
1265
1370
  fingerprintHash,
1266
1371
  appVersion,
1267
1372
  builtInBundlePath: info.builtInBundle.path,
1268
- sandbox: info.sandbox.code
1373
+ sandbox: info.sandbox.code,
1374
+ sandboxUrlScheme: info.sandbox.code ? info.entry.sandboxUrlScheme : null
1269
1375
  }
1270
1376
  };
1271
1377
  };
@@ -1417,11 +1523,16 @@ exports.SANDBOX_APPLICATION_ID_SUFFIX = SANDBOX_APPLICATION_ID_SUFFIX;
1417
1523
  exports.SANDBOX_CODE_MARKER = SANDBOX_CODE_MARKER;
1418
1524
  exports.SANDBOX_INFO_PLIST_KEY = SANDBOX_INFO_PLIST_KEY;
1419
1525
  exports.SANDBOX_META_DATA = SANDBOX_META_DATA;
1526
+ exports.SANDBOX_URL_SCHEME_INFO_PLIST_KEY = SANDBOX_URL_SCHEME_INFO_PLIST_KEY;
1527
+ exports.SANDBOX_URL_SCHEME_META_DATA = SANDBOX_URL_SCHEME_META_DATA;
1528
+ exports.SANDBOX_URL_TYPE_NAME = SANDBOX_URL_TYPE_NAME;
1420
1529
  exports.alreadyImportedProblem = alreadyImportedProblem;
1421
1530
  exports.blobSource = blobSource;
1422
1531
  exports.checkNativeArtifact = checkNativeArtifact;
1423
1532
  exports.createPreviewLink = createPreviewLink;
1424
1533
  exports.findZipEntry = findZipEntry;
1534
+ exports.isConfigurableSandboxUrlScheme = isConfigurableSandboxUrlScheme;
1535
+ exports.isRecordedUrlSchemeSyntax = isRecordedUrlSchemeSyntax;
1425
1536
  exports.isSandboxChannel = isSandboxChannel;
1426
1537
  exports.isSandboxUrlScheme = isSandboxUrlScheme;
1427
1538
  exports.normalizeIosUdid = normalizeIosUdid;
@@ -1431,6 +1542,7 @@ exports.readIpaInstallInfo = readIpaInstallInfo;
1431
1542
  exports.readNativeArtifact = readNativeArtifact;
1432
1543
  exports.readProfileServiceUdid = readProfileServiceUdid;
1433
1544
  exports.readZipDirectory = readZipDirectory;
1545
+ exports.recordedSandboxUrlScheme = recordedSandboxUrlScheme;
1434
1546
  exports.sandboxArtifactProblem = sandboxArtifactProblem;
1435
1547
  exports.sandboxChannelOf = sandboxChannelOf;
1436
1548
  exports.sandboxUrlSchemeOf = sandboxUrlSchemeOf;
@@ -121,6 +121,8 @@ interface ImportableNativeBuild {
121
121
  readonly builtInBundlePath: string;
122
122
  /** Whether the artifact holds the sandbox layer: a sandbox build. */
123
123
  readonly sandbox: boolean;
124
+ /** The URL scheme a sandbox build registers; null for any other build. */
125
+ readonly sandboxUrlScheme: string | null;
124
126
  }
125
127
  type NativeArtifactCheck = ({
126
128
  readonly ok: true;
@@ -257,12 +259,44 @@ declare const openZipEntry: (source: ByteSource, entry: ZipEntry, { maxBytes }?:
257
259
  declare const SANDBOX_CODE_MARKER = "HOT_UPDATER_SANDBOX_NATIVE_LAYER";
258
260
  /** The Info.plist key an iOS sandbox build declares itself with. */
259
261
  declare const SANDBOX_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX";
262
+ /**
263
+ * The Info.plist key that records the URL scheme an iOS sandbox build
264
+ * registers in its `SANDBOX_URL_TYPE_NAME` URL type: the build reads its own
265
+ * scheme from it, and a later patch knows which scheme is the sandbox's.
266
+ */
267
+ declare const SANDBOX_URL_SCHEME_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX_URL_SCHEME";
268
+ /**
269
+ * Whether a value is a URL scheme in lower-case ASCII, as written: what a
270
+ * build records, read before any lower-casing.
271
+ */
272
+ declare const isRecordedUrlSchemeSyntax: (value: unknown) => value is string;
273
+ /**
274
+ * The URL scheme an iOS sandbox build registers, by one rule its patch, its
275
+ * reader, and its own code apply alike. `recorded` is the Info.plist's
276
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY`, undefined when the key is absent, and
277
+ * `namedTypes` its URL types named `SANDBOX_URL_TYPE_NAME`.
278
+ * - Absent: a prerelease's build, which recorded none. Undefined: the caller
279
+ * reads it the way that build was read.
280
+ * - Present: a scheme in lower-case ASCII, as written, that the one URL type
281
+ * of the name holds alone. Anything else is null, with no fallback.
282
+ */
283
+ declare const recordedSandboxUrlScheme: (recorded: unknown, namedTypes: readonly unknown[]) => string | null | undefined;
260
284
  /** The `<meta-data>` an Android sandbox build declares itself with. */
261
285
  declare const SANDBOX_META_DATA = "com.hotupdater.SANDBOX";
262
286
  /** The activity that takes an Android sandbox build's launcher entry and links. */
263
287
  declare const SANDBOX_ACTIVITY = "com.hotupdater.HotUpdaterSandboxActivity";
264
288
  /** The `applicationIdSuffix` an Android sandbox build appends. */
265
289
  declare const SANDBOX_APPLICATION_ID_SUFFIX = ".sandbox";
290
+ /**
291
+ * The `CFBundleURLName` of the URL type an iOS sandbox build registers its URL
292
+ * scheme with, which the build reads its own scheme from.
293
+ */
294
+ declare const SANDBOX_URL_TYPE_NAME = "hot-updater-sandbox";
295
+ /**
296
+ * The `<meta-data>` of `SANDBOX_ACTIVITY` that names the URL scheme an Android
297
+ * sandbox build registers, which the build reads its own scheme from.
298
+ */
299
+ declare const SANDBOX_URL_SCHEME_META_DATA = "com.hotupdater.sandbox.URL_SCHEME";
266
300
  /**
267
301
  * The channel a scheme's sandbox build registers on. `sandbox-*` is reserved:
268
302
  * only a sandbox build registers there, and the registry records `sandbox` on
@@ -272,12 +306,23 @@ declare const sandboxChannelOf: (scheme: string) => string;
272
306
  /** Whether a channel is reserved for sandbox builds. */
273
307
  declare const isSandboxChannel: (channel: string) => boolean;
274
308
  /**
275
- * The URL scheme only a sandbox build registers, derived from the app's ID:
276
- * the app's own scheme would ask which app to open beside the store app.
309
+ * The URL scheme a sandbox build registers when its scheme sets none, derived
310
+ * from the app's ID: the app's own scheme would ask which app to open beside
311
+ * the store app.
277
312
  */
278
313
  declare const sandboxUrlSchemeOf: (appId: string) => string;
279
- /** Whether a URL scheme is one a sandbox build registers. */
314
+ /**
315
+ * Whether a URL scheme has the prefix of the derived one: how an artifact built
316
+ * before the URL scheme could be set is read, which registered no other.
317
+ */
280
318
  declare const isSandboxUrlScheme: (scheme: string) => boolean;
319
+ /**
320
+ * Whether `sandbox: { urlScheme }` can name a URL scheme: lower case, a letter
321
+ * then up to 63 letters, digits, `+`, `.` or `-`, none the system or a browser
322
+ * owns, and neither `true` nor `false`, which Android's manifest can't hold as
323
+ * a string.
324
+ */
325
+ declare const isConfigurableSandboxUrlScheme: (urlScheme: string) => boolean;
281
326
  /** What a preview link asks a sandbox build to run. */
282
327
  interface PreviewLink {
283
328
  /** The sandbox's URL scheme, in lower case. */
@@ -287,21 +332,29 @@ interface PreviewLink {
287
332
  readonly fingerprintHash: string;
288
333
  }
289
334
  /**
290
- * The link a preview QR holds. `appId` is the scheme's `bundleIdentifier` or
291
- * `packageName`: the ID before the Android sandbox's `.sandbox` suffix.
335
+ * The link a preview QR holds. `urlScheme` is the one the sandbox build
336
+ * registered; without it, the one derived from `appId`, the scheme's
337
+ * `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
338
+ * `.sandbox` suffix.
292
339
  */
293
- declare const createPreviewLink: ({ appId, channel, fingerprintHash }: {
294
- readonly appId: string;
340
+ declare const createPreviewLink: ({ urlScheme, appId, channel, fingerprintHash }: {
295
341
  readonly channel: string;
296
342
  readonly fingerprintHash: string;
297
- }) => string;
343
+ } & ({
344
+ readonly urlScheme: string;
345
+ readonly appId?: string;
346
+ } | {
347
+ readonly urlScheme?: undefined;
348
+ readonly appId: string;
349
+ })) => string;
298
350
  /**
299
351
  * What a preview link says, or null for anything else: another shape, a
300
- * repeated or missing parameter, or a channel no release can target. Native
301
- * code parses it the same way before any JavaScript runs, in
352
+ * repeated or missing parameter, or a channel no release can target. It takes
353
+ * any URL scheme: a sandbox build refuses a link of another scheme than its
354
+ * own. Native code parses it the same way before any JavaScript runs, in
302
355
  * HotUpdaterSandboxLink, and shares the vectors in test-utils'
303
356
  * `sandbox-preview-links.json`.
304
357
  */
305
358
  declare const parsePreviewLink: (link: string) => PreviewLink | null;
306
359
  //#endregion
307
- export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, type UnreadableValue, type ZipEntry, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
360
+ export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, SANDBOX_URL_SCHEME_META_DATA, SANDBOX_URL_TYPE_NAME, type UnreadableValue, type ZipEntry, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isConfigurableSandboxUrlScheme, isRecordedUrlSchemeSyntax, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, recordedSandboxUrlScheme, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
@@ -121,6 +121,8 @@ interface ImportableNativeBuild {
121
121
  readonly builtInBundlePath: string;
122
122
  /** Whether the artifact holds the sandbox layer: a sandbox build. */
123
123
  readonly sandbox: boolean;
124
+ /** The URL scheme a sandbox build registers; null for any other build. */
125
+ readonly sandboxUrlScheme: string | null;
124
126
  }
125
127
  type NativeArtifactCheck = ({
126
128
  readonly ok: true;
@@ -257,12 +259,44 @@ declare const openZipEntry: (source: ByteSource, entry: ZipEntry, { maxBytes }?:
257
259
  declare const SANDBOX_CODE_MARKER = "HOT_UPDATER_SANDBOX_NATIVE_LAYER";
258
260
  /** The Info.plist key an iOS sandbox build declares itself with. */
259
261
  declare const SANDBOX_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX";
262
+ /**
263
+ * The Info.plist key that records the URL scheme an iOS sandbox build
264
+ * registers in its `SANDBOX_URL_TYPE_NAME` URL type: the build reads its own
265
+ * scheme from it, and a later patch knows which scheme is the sandbox's.
266
+ */
267
+ declare const SANDBOX_URL_SCHEME_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX_URL_SCHEME";
268
+ /**
269
+ * Whether a value is a URL scheme in lower-case ASCII, as written: what a
270
+ * build records, read before any lower-casing.
271
+ */
272
+ declare const isRecordedUrlSchemeSyntax: (value: unknown) => value is string;
273
+ /**
274
+ * The URL scheme an iOS sandbox build registers, by one rule its patch, its
275
+ * reader, and its own code apply alike. `recorded` is the Info.plist's
276
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY`, undefined when the key is absent, and
277
+ * `namedTypes` its URL types named `SANDBOX_URL_TYPE_NAME`.
278
+ * - Absent: a prerelease's build, which recorded none. Undefined: the caller
279
+ * reads it the way that build was read.
280
+ * - Present: a scheme in lower-case ASCII, as written, that the one URL type
281
+ * of the name holds alone. Anything else is null, with no fallback.
282
+ */
283
+ declare const recordedSandboxUrlScheme: (recorded: unknown, namedTypes: readonly unknown[]) => string | null | undefined;
260
284
  /** The `<meta-data>` an Android sandbox build declares itself with. */
261
285
  declare const SANDBOX_META_DATA = "com.hotupdater.SANDBOX";
262
286
  /** The activity that takes an Android sandbox build's launcher entry and links. */
263
287
  declare const SANDBOX_ACTIVITY = "com.hotupdater.HotUpdaterSandboxActivity";
264
288
  /** The `applicationIdSuffix` an Android sandbox build appends. */
265
289
  declare const SANDBOX_APPLICATION_ID_SUFFIX = ".sandbox";
290
+ /**
291
+ * The `CFBundleURLName` of the URL type an iOS sandbox build registers its URL
292
+ * scheme with, which the build reads its own scheme from.
293
+ */
294
+ declare const SANDBOX_URL_TYPE_NAME = "hot-updater-sandbox";
295
+ /**
296
+ * The `<meta-data>` of `SANDBOX_ACTIVITY` that names the URL scheme an Android
297
+ * sandbox build registers, which the build reads its own scheme from.
298
+ */
299
+ declare const SANDBOX_URL_SCHEME_META_DATA = "com.hotupdater.sandbox.URL_SCHEME";
266
300
  /**
267
301
  * The channel a scheme's sandbox build registers on. `sandbox-*` is reserved:
268
302
  * only a sandbox build registers there, and the registry records `sandbox` on
@@ -272,12 +306,23 @@ declare const sandboxChannelOf: (scheme: string) => string;
272
306
  /** Whether a channel is reserved for sandbox builds. */
273
307
  declare const isSandboxChannel: (channel: string) => boolean;
274
308
  /**
275
- * The URL scheme only a sandbox build registers, derived from the app's ID:
276
- * the app's own scheme would ask which app to open beside the store app.
309
+ * The URL scheme a sandbox build registers when its scheme sets none, derived
310
+ * from the app's ID: the app's own scheme would ask which app to open beside
311
+ * the store app.
277
312
  */
278
313
  declare const sandboxUrlSchemeOf: (appId: string) => string;
279
- /** Whether a URL scheme is one a sandbox build registers. */
314
+ /**
315
+ * Whether a URL scheme has the prefix of the derived one: how an artifact built
316
+ * before the URL scheme could be set is read, which registered no other.
317
+ */
280
318
  declare const isSandboxUrlScheme: (scheme: string) => boolean;
319
+ /**
320
+ * Whether `sandbox: { urlScheme }` can name a URL scheme: lower case, a letter
321
+ * then up to 63 letters, digits, `+`, `.` or `-`, none the system or a browser
322
+ * owns, and neither `true` nor `false`, which Android's manifest can't hold as
323
+ * a string.
324
+ */
325
+ declare const isConfigurableSandboxUrlScheme: (urlScheme: string) => boolean;
281
326
  /** What a preview link asks a sandbox build to run. */
282
327
  interface PreviewLink {
283
328
  /** The sandbox's URL scheme, in lower case. */
@@ -287,21 +332,29 @@ interface PreviewLink {
287
332
  readonly fingerprintHash: string;
288
333
  }
289
334
  /**
290
- * The link a preview QR holds. `appId` is the scheme's `bundleIdentifier` or
291
- * `packageName`: the ID before the Android sandbox's `.sandbox` suffix.
335
+ * The link a preview QR holds. `urlScheme` is the one the sandbox build
336
+ * registered; without it, the one derived from `appId`, the scheme's
337
+ * `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
338
+ * `.sandbox` suffix.
292
339
  */
293
- declare const createPreviewLink: ({ appId, channel, fingerprintHash }: {
294
- readonly appId: string;
340
+ declare const createPreviewLink: ({ urlScheme, appId, channel, fingerprintHash }: {
295
341
  readonly channel: string;
296
342
  readonly fingerprintHash: string;
297
- }) => string;
343
+ } & ({
344
+ readonly urlScheme: string;
345
+ readonly appId?: string;
346
+ } | {
347
+ readonly urlScheme?: undefined;
348
+ readonly appId: string;
349
+ })) => string;
298
350
  /**
299
351
  * What a preview link says, or null for anything else: another shape, a
300
- * repeated or missing parameter, or a channel no release can target. Native
301
- * code parses it the same way before any JavaScript runs, in
352
+ * repeated or missing parameter, or a channel no release can target. It takes
353
+ * any URL scheme: a sandbox build refuses a link of another scheme than its
354
+ * own. Native code parses it the same way before any JavaScript runs, in
302
355
  * HotUpdaterSandboxLink, and shares the vectors in test-utils'
303
356
  * `sandbox-preview-links.json`.
304
357
  */
305
358
  declare const parsePreviewLink: (link: string) => PreviewLink | null;
306
359
  //#endregion
307
- export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, type UnreadableValue, type ZipEntry, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
360
+ export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, SANDBOX_URL_SCHEME_META_DATA, SANDBOX_URL_TYPE_NAME, type UnreadableValue, type ZipEntry, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isConfigurableSandboxUrlScheme, isRecordedUrlSchemeSyntax, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, recordedSandboxUrlScheme, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
@@ -295,6 +295,12 @@ const readAndroidManifest = (manifest) => {
295
295
  const metaData = /* @__PURE__ */ new Map();
296
296
  const launchers = [];
297
297
  const urlSchemes = /* @__PURE__ */ new Map();
298
+ const componentMetaData = /* @__PURE__ */ new Map();
299
+ const metaDataOf = (element, into) => {
300
+ const name = attributeOf(element, NAME, "name");
301
+ const value = attributeOf(element, VALUE, "value") ?? attributeOf(element, RESOURCE, "resource");
302
+ if (name?.type === "string" && value !== null) into.set(name.value, value);
303
+ };
298
304
  const stringAttribute = (element, id, name) => {
299
305
  const value = attributeOf(element, id, name);
300
306
  return value?.type === "string" ? value.value : null;
@@ -303,10 +309,17 @@ const readAndroidManifest = (manifest) => {
303
309
  if (COMPONENTS.has(element.name)) {
304
310
  const component = stringAttribute(element, NAME, "name");
305
311
  if (component === null) continue;
312
+ for (const item of element.children) {
313
+ if (item.name !== "meta-data") continue;
314
+ const own = componentMetaData.get(component) ?? /* @__PURE__ */ new Map();
315
+ metaDataOf(item, own);
316
+ componentMetaData.set(component, own);
317
+ }
306
318
  for (const filter of element.children) {
307
319
  if (filter.name !== "intent-filter") continue;
308
320
  const named = (child) => filter.children.filter(({ name }) => name === child).map((part) => stringAttribute(part, NAME, "name"));
309
321
  if (named("action").includes("android.intent.action.MAIN") && named("category").includes("android.intent.category.LAUNCHER") && !launchers.includes(component)) launchers.push(component);
322
+ if (!named("action").includes("android.intent.action.VIEW")) continue;
310
323
  for (const data of filter.children) {
311
324
  if (data.name !== "data") continue;
312
325
  const scheme = stringAttribute(data, SCHEME, "scheme");
@@ -317,9 +330,7 @@ const readAndroidManifest = (manifest) => {
317
330
  continue;
318
331
  }
319
332
  if (element.name !== "meta-data") continue;
320
- const name = attributeOf(element, NAME, "name");
321
- const value = attributeOf(element, VALUE, "value") ?? attributeOf(element, RESOURCE, "resource");
322
- if (name?.type === "string" && value !== null) metaData.set(name.value, value);
333
+ metaDataOf(element, metaData);
323
334
  }
324
335
  return {
325
336
  packageName: packageValue?.type === "string" ? packageValue.value : null,
@@ -327,7 +338,8 @@ const readAndroidManifest = (manifest) => {
327
338
  versionCode: versionCode?.type === "int" ? versionCode.value : null,
328
339
  metaData,
329
340
  launchers,
330
- urlSchemes
341
+ urlSchemes,
342
+ componentMetaData
331
343
  };
332
344
  };
333
345
  //#endregion
@@ -567,12 +579,50 @@ const parsePlist = (bytes) => {
567
579
  const SANDBOX_CODE_MARKER = "HOT_UPDATER_SANDBOX_NATIVE_LAYER";
568
580
  /** The Info.plist key an iOS sandbox build declares itself with. */
569
581
  const SANDBOX_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX";
582
+ /**
583
+ * The Info.plist key that records the URL scheme an iOS sandbox build
584
+ * registers in its `SANDBOX_URL_TYPE_NAME` URL type: the build reads its own
585
+ * scheme from it, and a later patch knows which scheme is the sandbox's.
586
+ */
587
+ const SANDBOX_URL_SCHEME_INFO_PLIST_KEY = "HOT_UPDATER_SANDBOX_URL_SCHEME";
588
+ const URL_SCHEME_SYNTAX = /^[a-z][a-z0-9+.-]*$/;
589
+ /**
590
+ * Whether a value is a URL scheme in lower-case ASCII, as written: what a
591
+ * build records, read before any lower-casing.
592
+ */
593
+ const isRecordedUrlSchemeSyntax = (value) => typeof value === "string" && URL_SCHEME_SYNTAX.test(value);
594
+ /**
595
+ * The URL scheme an iOS sandbox build registers, by one rule its patch, its
596
+ * reader, and its own code apply alike. `recorded` is the Info.plist's
597
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY`, undefined when the key is absent, and
598
+ * `namedTypes` its URL types named `SANDBOX_URL_TYPE_NAME`.
599
+ * - Absent: a prerelease's build, which recorded none. Undefined: the caller
600
+ * reads it the way that build was read.
601
+ * - Present: a scheme in lower-case ASCII, as written, that the one URL type
602
+ * of the name holds alone. Anything else is null, with no fallback.
603
+ */
604
+ const recordedSandboxUrlScheme = (recorded, namedTypes) => {
605
+ if (recorded === void 0) return void 0;
606
+ if (!isRecordedUrlSchemeSyntax(recorded) || namedTypes.length !== 1) return null;
607
+ const schemes = namedTypes[0]?.CFBundleURLSchemes;
608
+ return Array.isArray(schemes) && schemes.length === 1 && schemes[0] === recorded ? recorded : null;
609
+ };
570
610
  /** The `<meta-data>` an Android sandbox build declares itself with. */
571
611
  const SANDBOX_META_DATA = "com.hotupdater.SANDBOX";
572
612
  /** The activity that takes an Android sandbox build's launcher entry and links. */
573
613
  const SANDBOX_ACTIVITY = "com.hotupdater.HotUpdaterSandboxActivity";
574
614
  /** The `applicationIdSuffix` an Android sandbox build appends. */
575
615
  const SANDBOX_APPLICATION_ID_SUFFIX = ".sandbox";
616
+ /**
617
+ * The `CFBundleURLName` of the URL type an iOS sandbox build registers its URL
618
+ * scheme with, which the build reads its own scheme from.
619
+ */
620
+ const SANDBOX_URL_TYPE_NAME = "hot-updater-sandbox";
621
+ /**
622
+ * The `<meta-data>` of `SANDBOX_ACTIVITY` that names the URL scheme an Android
623
+ * sandbox build registers, which the build reads its own scheme from.
624
+ */
625
+ const SANDBOX_URL_SCHEME_META_DATA = "com.hotupdater.sandbox.URL_SCHEME";
576
626
  const SANDBOX_CHANNEL_PREFIX = "sandbox-";
577
627
  const SANDBOX_URL_SCHEME_PREFIX = "hu-sandbox-";
578
628
  /**
@@ -584,32 +634,62 @@ const sandboxChannelOf = (scheme) => `${SANDBOX_CHANNEL_PREFIX}${scheme}`;
584
634
  /** Whether a channel is reserved for sandbox builds. */
585
635
  const isSandboxChannel = (channel) => channel.startsWith(SANDBOX_CHANNEL_PREFIX);
586
636
  /**
587
- * The URL scheme only a sandbox build registers, derived from the app's ID:
588
- * the app's own scheme would ask which app to open beside the store app.
637
+ * The URL scheme a sandbox build registers when its scheme sets none, derived
638
+ * from the app's ID: the app's own scheme would ask which app to open beside
639
+ * the store app.
589
640
  */
590
641
  const sandboxUrlSchemeOf = (appId) => `${SANDBOX_URL_SCHEME_PREFIX}${appId.toLowerCase().replace(/[^a-z0-9]+/gu, "-")}`;
591
- /** Whether a URL scheme is one a sandbox build registers. */
642
+ /**
643
+ * Whether a URL scheme has the prefix of the derived one: how an artifact built
644
+ * before the URL scheme could be set is read, which registered no other.
645
+ */
592
646
  const isSandboxUrlScheme = (scheme) => scheme.toLowerCase().startsWith(SANDBOX_URL_SCHEME_PREFIX);
647
+ const CONFIGURED_URL_SCHEME = /^[a-z][a-z0-9+.-]{0,63}$/u;
648
+ const RESERVED_URL_SCHEMES = /* @__PURE__ */ new Set([
649
+ "http",
650
+ "https",
651
+ "file",
652
+ "data",
653
+ "javascript",
654
+ "true",
655
+ "false"
656
+ ]);
593
657
  /**
594
- * The link a preview QR holds. `appId` is the scheme's `bundleIdentifier` or
595
- * `packageName`: the ID before the Android sandbox's `.sandbox` suffix.
658
+ * Whether `sandbox: { urlScheme }` can name a URL scheme: lower case, a letter
659
+ * then up to 63 letters, digits, `+`, `.` or `-`, none the system or a browser
660
+ * owns, and neither `true` nor `false`, which Android's manifest can't hold as
661
+ * a string.
596
662
  */
597
- const createPreviewLink = ({ appId, channel, fingerprintHash }) => {
663
+ const isConfigurableSandboxUrlScheme = (urlScheme) => CONFIGURED_URL_SCHEME.test(urlScheme) && !RESERVED_URL_SCHEMES.has(urlScheme);
664
+ /**
665
+ * The link a preview QR holds. `urlScheme` is the one the sandbox build
666
+ * registered; without it, the one derived from `appId`, the scheme's
667
+ * `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
668
+ * `.sandbox` suffix.
669
+ */
670
+ const createPreviewLink = ({ urlScheme, appId, channel, fingerprintHash }) => {
598
671
  assertCanonicalChannelName(channel);
599
- return `${sandboxUrlSchemeOf(appId)}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
672
+ return `${(urlScheme ?? sandboxUrlSchemeOf(appId)).toLowerCase()}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
600
673
  };
601
- const PREVIEW_LINK = /^(hu-sandbox-[a-z0-9-]+):\/\/hot-updater\/preview\?([^#]*)$/iu;
674
+ /** Any URL scheme: which app's it is, the app that opens the link decides. */
675
+ const PREVIEW_LINK = /^([a-z][a-z0-9+.-]*):\/\/hot-updater\/preview\?([^#]*)$/iu;
676
+ /**
677
+ * A URL scheme in ASCII alone: case folding lets `/iu` match `K` (Kelvin) or
678
+ * `ſ` as a letter.
679
+ */
680
+ const ASCII_URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
602
681
  const MAX_FINGERPRINT_LENGTH = 256;
603
682
  /**
604
683
  * What a preview link says, or null for anything else: another shape, a
605
- * repeated or missing parameter, or a channel no release can target. Native
606
- * code parses it the same way before any JavaScript runs, in
684
+ * repeated or missing parameter, or a channel no release can target. It takes
685
+ * any URL scheme: a sandbox build refuses a link of another scheme than its
686
+ * own. Native code parses it the same way before any JavaScript runs, in
607
687
  * HotUpdaterSandboxLink, and shares the vectors in test-utils'
608
688
  * `sandbox-preview-links.json`.
609
689
  */
610
690
  const parsePreviewLink = (link) => {
611
691
  const match = PREVIEW_LINK.exec(link);
612
- if (match === null) return null;
692
+ if (match === null || !ASCII_URL_SCHEME.test(match[1])) return null;
613
693
  const parameters = /* @__PURE__ */ new Map();
614
694
  for (const parameter of match[2].split("&")) {
615
695
  const separator = parameter.indexOf("=");
@@ -1062,7 +1142,7 @@ const readAndroid = async (source, kind, entries, budget) => {
1062
1142
  },
1063
1143
  entry: {
1064
1144
  launchers: manifest.launchers,
1065
- sandboxUrlScheme: manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity")?.find(isSandboxUrlScheme) ?? null
1145
+ sandboxUrlScheme: androidSandboxUrlScheme(manifest)
1066
1146
  },
1067
1147
  builtInBundle: bundle === void 0 ? null : {
1068
1148
  path: bundle.name,
@@ -1070,16 +1150,41 @@ const readAndroid = async (source, kind, entries, budget) => {
1070
1150
  }
1071
1151
  };
1072
1152
  };
1073
- /** The sandbox URL scheme in an Info.plist's `CFBundleURLTypes`, or null. */
1153
+ /**
1154
+ * The URL scheme an Android sandbox build registers, or null: the one its
1155
+ * activity's `SANDBOX_URL_SCHEME_META_DATA` names, when the activity's `VIEW`
1156
+ * filters take it too. An artifact built before the meta-data takes the one
1157
+ * with the derived scheme's prefix.
1158
+ */
1159
+ const androidSandboxUrlScheme = (manifest) => {
1160
+ const schemes = manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity") ?? [];
1161
+ const declared = manifest.componentMetaData.get(SANDBOX_ACTIVITY)?.get(SANDBOX_URL_SCHEME_META_DATA);
1162
+ if (declared === void 0) return schemes.find(isSandboxUrlScheme) ?? null;
1163
+ if (declared.type !== "string") return null;
1164
+ return schemes.includes(declared.value) ? declared.value : null;
1165
+ };
1166
+ /**
1167
+ * The sandbox URL scheme of an Info.plist, or null: the one
1168
+ * `SANDBOX_URL_SCHEME_INFO_PLIST_KEY` records, by `recordedSandboxUrlScheme`'s
1169
+ * rule. A prerelease's artifact, with no key, gives its named URL type's one
1170
+ * scheme, or, with no named type, one with the derived scheme's prefix.
1171
+ */
1074
1172
  const sandboxUrlSchemeIn = (info) => {
1075
1173
  const types = info["CFBundleURLTypes"];
1076
1174
  if (!Array.isArray(types)) return null;
1077
- for (const type of types) {
1175
+ const schemesOf = (type) => {
1078
1176
  const schemes = type?.CFBundleURLSchemes;
1079
- if (!Array.isArray(schemes)) continue;
1080
- for (const scheme of schemes) if (typeof scheme === "string" && isSandboxUrlScheme(scheme)) return scheme;
1177
+ return Array.isArray(schemes) ? schemes.filter((scheme) => typeof scheme === "string") : [];
1178
+ };
1179
+ const named = types.filter((type) => type?.CFBundleURLName === SANDBOX_URL_TYPE_NAME);
1180
+ const recorded = recordedSandboxUrlScheme("HOT_UPDATER_SANDBOX_URL_SCHEME" in info ? info[SANDBOX_URL_SCHEME_INFO_PLIST_KEY] : void 0, named);
1181
+ if (recorded !== void 0) return recorded;
1182
+ if (named.length > 1) return null;
1183
+ if (named.length === 1) {
1184
+ const schemes = schemesOf(named[0]);
1185
+ return schemes.length === 1 ? schemes[0] : null;
1081
1186
  }
1082
- return null;
1187
+ return types.flatMap(schemesOf).find(isSandboxUrlScheme) ?? null;
1083
1188
  };
1084
1189
  const stringValue = (value) => typeof value === "string" && value !== "" ? value : null;
1085
1190
  const readIos = async (source, kind, entries, budget) => {
@@ -1264,7 +1369,8 @@ const checkNativeArtifact = (info, { updateStrategy, appIds = [], channel: chann
1264
1369
  fingerprintHash,
1265
1370
  appVersion,
1266
1371
  builtInBundlePath: info.builtInBundle.path,
1267
- sandbox: info.sandbox.code
1372
+ sandbox: info.sandbox.code,
1373
+ sandboxUrlScheme: info.sandbox.code ? info.entry.sandboxUrlScheme : null
1268
1374
  }
1269
1375
  };
1270
1376
  };
@@ -1410,4 +1516,4 @@ const readIpaInstallInfo = async (source) => {
1410
1516
  };
1411
1517
  };
1412
1518
  //#endregion
1413
- export { NativeArtifactError, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
1519
+ export { NativeArtifactError, SANDBOX_ACTIVITY, SANDBOX_APPLICATION_ID_SUFFIX, SANDBOX_CODE_MARKER, SANDBOX_INFO_PLIST_KEY, SANDBOX_META_DATA, SANDBOX_URL_SCHEME_INFO_PLIST_KEY, SANDBOX_URL_SCHEME_META_DATA, SANDBOX_URL_TYPE_NAME, alreadyImportedProblem, blobSource, checkNativeArtifact, createPreviewLink, findZipEntry, isConfigurableSandboxUrlScheme, isRecordedUrlSchemeSyntax, isSandboxChannel, isSandboxUrlScheme, normalizeIosUdid, openZipEntry, parsePreviewLink, readIpaInstallInfo, readNativeArtifact, readProfileServiceUdid, readZipDirectory, recordedSandboxUrlScheme, sandboxArtifactProblem, sandboxChannelOf, sandboxUrlSchemeOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/protocol",
3
- "version": "1.2.0-rc.24",
3
+ "version": "1.2.0-rc.25",
4
4
  "type": "module",
5
5
  "description": "The data formats and pure computations that Hot Updater's app and server share",
6
6
  "sideEffects": false,