@hot-updater/protocol 1.2.0-rc.24 → 1.2.0-rc.26
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.
- package/dist/native-artifact.cjs +142 -25
- package/dist/native-artifact.d.cts +75 -13
- package/dist/native-artifact.d.mts +75 -13
- package/dist/native-artifact.mjs +137 -26
- package/package.json +1 -1
package/dist/native-artifact.cjs
CHANGED
|
@@ -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
|
-
|
|
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,65 @@ 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
|
|
589
|
-
* the app's own scheme would ask which app to open beside
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
596
|
-
*
|
|
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
|
|
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, platform }) => {
|
|
599
672
|
require_uuid.assertCanonicalChannelName(channel);
|
|
600
|
-
|
|
673
|
+
if (platform !== void 0 && !PREVIEW_LINK_PLATFORMS.has(platform)) throw new Error(`A preview link's platform is ios or android, not ${platform}.`);
|
|
674
|
+
const link = `${(urlScheme ?? sandboxUrlSchemeOf(appId)).toLowerCase()}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
|
|
675
|
+
return platform === void 0 ? link : `${link}&platform=${platform}`;
|
|
601
676
|
};
|
|
602
|
-
|
|
677
|
+
/** Any URL scheme: which app's it is, the app that opens the link decides. */
|
|
678
|
+
const PREVIEW_LINK = /^([a-z][a-z0-9+.-]*):\/\/hot-updater\/preview\?([^#]*)$/iu;
|
|
679
|
+
/**
|
|
680
|
+
* A URL scheme in ASCII alone: case folding lets `/iu` match `K` (Kelvin) or
|
|
681
|
+
* `ſ` as a letter.
|
|
682
|
+
*/
|
|
683
|
+
const ASCII_URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
|
|
603
684
|
const MAX_FINGERPRINT_LENGTH = 256;
|
|
685
|
+
const PREVIEW_LINK_PLATFORMS = /* @__PURE__ */ new Set(["ios", "android"]);
|
|
604
686
|
/**
|
|
605
687
|
* 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.
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
688
|
+
* repeated or missing parameter, or a channel no release can target. It takes
|
|
689
|
+
* any URL scheme: a sandbox build refuses a link of another scheme than its
|
|
690
|
+
* own. A `platform` other than `ios` or `android` reads as none. Native code
|
|
691
|
+
* parses it the same way before any JavaScript runs, in HotUpdaterSandboxLink,
|
|
692
|
+
* and shares the vectors in test-utils' `sandbox-preview-links.json`.
|
|
610
693
|
*/
|
|
611
694
|
const parsePreviewLink = (link) => {
|
|
612
695
|
const match = PREVIEW_LINK.exec(link);
|
|
613
|
-
if (match === null) return null;
|
|
696
|
+
if (match === null || !ASCII_URL_SCHEME.test(match[1])) return null;
|
|
614
697
|
const parameters = /* @__PURE__ */ new Map();
|
|
615
698
|
for (const parameter of match[2].split("&")) {
|
|
616
699
|
const separator = parameter.indexOf("=");
|
|
@@ -633,10 +716,12 @@ const parsePreviewLink = (link) => {
|
|
|
633
716
|
} catch {
|
|
634
717
|
return null;
|
|
635
718
|
}
|
|
719
|
+
const platform = parameters.get("platform");
|
|
636
720
|
return {
|
|
637
721
|
urlScheme: match[1].toLowerCase(),
|
|
638
722
|
channel,
|
|
639
|
-
fingerprintHash
|
|
723
|
+
fingerprintHash,
|
|
724
|
+
...platform !== void 0 && PREVIEW_LINK_PLATFORMS.has(platform) ? { platform } : {}
|
|
640
725
|
};
|
|
641
726
|
};
|
|
642
727
|
//#endregion
|
|
@@ -1063,7 +1148,7 @@ const readAndroid = async (source, kind, entries, budget) => {
|
|
|
1063
1148
|
},
|
|
1064
1149
|
entry: {
|
|
1065
1150
|
launchers: manifest.launchers,
|
|
1066
|
-
sandboxUrlScheme: manifest
|
|
1151
|
+
sandboxUrlScheme: androidSandboxUrlScheme(manifest)
|
|
1067
1152
|
},
|
|
1068
1153
|
builtInBundle: bundle === void 0 ? null : {
|
|
1069
1154
|
path: bundle.name,
|
|
@@ -1071,16 +1156,41 @@ const readAndroid = async (source, kind, entries, budget) => {
|
|
|
1071
1156
|
}
|
|
1072
1157
|
};
|
|
1073
1158
|
};
|
|
1074
|
-
/**
|
|
1159
|
+
/**
|
|
1160
|
+
* The URL scheme an Android sandbox build registers, or null: the one its
|
|
1161
|
+
* activity's `SANDBOX_URL_SCHEME_META_DATA` names, when the activity's `VIEW`
|
|
1162
|
+
* filters take it too. An artifact built before the meta-data takes the one
|
|
1163
|
+
* with the derived scheme's prefix.
|
|
1164
|
+
*/
|
|
1165
|
+
const androidSandboxUrlScheme = (manifest) => {
|
|
1166
|
+
const schemes = manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity") ?? [];
|
|
1167
|
+
const declared = manifest.componentMetaData.get(SANDBOX_ACTIVITY)?.get(SANDBOX_URL_SCHEME_META_DATA);
|
|
1168
|
+
if (declared === void 0) return schemes.find(isSandboxUrlScheme) ?? null;
|
|
1169
|
+
if (declared.type !== "string") return null;
|
|
1170
|
+
return schemes.includes(declared.value) ? declared.value : null;
|
|
1171
|
+
};
|
|
1172
|
+
/**
|
|
1173
|
+
* The sandbox URL scheme of an Info.plist, or null: the one
|
|
1174
|
+
* `SANDBOX_URL_SCHEME_INFO_PLIST_KEY` records, by `recordedSandboxUrlScheme`'s
|
|
1175
|
+
* rule. A prerelease's artifact, with no key, gives its named URL type's one
|
|
1176
|
+
* scheme, or, with no named type, one with the derived scheme's prefix.
|
|
1177
|
+
*/
|
|
1075
1178
|
const sandboxUrlSchemeIn = (info) => {
|
|
1076
1179
|
const types = info["CFBundleURLTypes"];
|
|
1077
1180
|
if (!Array.isArray(types)) return null;
|
|
1078
|
-
|
|
1181
|
+
const schemesOf = (type) => {
|
|
1079
1182
|
const schemes = type?.CFBundleURLSchemes;
|
|
1080
|
-
|
|
1081
|
-
|
|
1183
|
+
return Array.isArray(schemes) ? schemes.filter((scheme) => typeof scheme === "string") : [];
|
|
1184
|
+
};
|
|
1185
|
+
const named = types.filter((type) => type?.CFBundleURLName === SANDBOX_URL_TYPE_NAME);
|
|
1186
|
+
const recorded = recordedSandboxUrlScheme("HOT_UPDATER_SANDBOX_URL_SCHEME" in info ? info[SANDBOX_URL_SCHEME_INFO_PLIST_KEY] : void 0, named);
|
|
1187
|
+
if (recorded !== void 0) return recorded;
|
|
1188
|
+
if (named.length > 1) return null;
|
|
1189
|
+
if (named.length === 1) {
|
|
1190
|
+
const schemes = schemesOf(named[0]);
|
|
1191
|
+
return schemes.length === 1 ? schemes[0] : null;
|
|
1082
1192
|
}
|
|
1083
|
-
return null;
|
|
1193
|
+
return types.flatMap(schemesOf).find(isSandboxUrlScheme) ?? null;
|
|
1084
1194
|
};
|
|
1085
1195
|
const stringValue = (value) => typeof value === "string" && value !== "" ? value : null;
|
|
1086
1196
|
const readIos = async (source, kind, entries, budget) => {
|
|
@@ -1265,7 +1375,8 @@ const checkNativeArtifact = (info, { updateStrategy, appIds = [], channel: chann
|
|
|
1265
1375
|
fingerprintHash,
|
|
1266
1376
|
appVersion,
|
|
1267
1377
|
builtInBundlePath: info.builtInBundle.path,
|
|
1268
|
-
sandbox: info.sandbox.code
|
|
1378
|
+
sandbox: info.sandbox.code,
|
|
1379
|
+
sandboxUrlScheme: info.sandbox.code ? info.entry.sandboxUrlScheme : null
|
|
1269
1380
|
}
|
|
1270
1381
|
};
|
|
1271
1382
|
};
|
|
@@ -1417,11 +1528,16 @@ exports.SANDBOX_APPLICATION_ID_SUFFIX = SANDBOX_APPLICATION_ID_SUFFIX;
|
|
|
1417
1528
|
exports.SANDBOX_CODE_MARKER = SANDBOX_CODE_MARKER;
|
|
1418
1529
|
exports.SANDBOX_INFO_PLIST_KEY = SANDBOX_INFO_PLIST_KEY;
|
|
1419
1530
|
exports.SANDBOX_META_DATA = SANDBOX_META_DATA;
|
|
1531
|
+
exports.SANDBOX_URL_SCHEME_INFO_PLIST_KEY = SANDBOX_URL_SCHEME_INFO_PLIST_KEY;
|
|
1532
|
+
exports.SANDBOX_URL_SCHEME_META_DATA = SANDBOX_URL_SCHEME_META_DATA;
|
|
1533
|
+
exports.SANDBOX_URL_TYPE_NAME = SANDBOX_URL_TYPE_NAME;
|
|
1420
1534
|
exports.alreadyImportedProblem = alreadyImportedProblem;
|
|
1421
1535
|
exports.blobSource = blobSource;
|
|
1422
1536
|
exports.checkNativeArtifact = checkNativeArtifact;
|
|
1423
1537
|
exports.createPreviewLink = createPreviewLink;
|
|
1424
1538
|
exports.findZipEntry = findZipEntry;
|
|
1539
|
+
exports.isConfigurableSandboxUrlScheme = isConfigurableSandboxUrlScheme;
|
|
1540
|
+
exports.isRecordedUrlSchemeSyntax = isRecordedUrlSchemeSyntax;
|
|
1425
1541
|
exports.isSandboxChannel = isSandboxChannel;
|
|
1426
1542
|
exports.isSandboxUrlScheme = isSandboxUrlScheme;
|
|
1427
1543
|
exports.normalizeIosUdid = normalizeIosUdid;
|
|
@@ -1431,6 +1547,7 @@ exports.readIpaInstallInfo = readIpaInstallInfo;
|
|
|
1431
1547
|
exports.readNativeArtifact = readNativeArtifact;
|
|
1432
1548
|
exports.readProfileServiceUdid = readProfileServiceUdid;
|
|
1433
1549
|
exports.readZipDirectory = readZipDirectory;
|
|
1550
|
+
exports.recordedSandboxUrlScheme = recordedSandboxUrlScheme;
|
|
1434
1551
|
exports.sandboxArtifactProblem = sandboxArtifactProblem;
|
|
1435
1552
|
exports.sandboxChannelOf = sandboxChannelOf;
|
|
1436
1553
|
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,25 @@ 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
|
|
276
|
-
* the app's own scheme would ask which app to open beside
|
|
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
|
-
/**
|
|
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;
|
|
326
|
+
/** The platform a preview link is for. */
|
|
327
|
+
type PreviewLinkPlatform = "ios" | "android";
|
|
281
328
|
/** What a preview link asks a sandbox build to run. */
|
|
282
329
|
interface PreviewLink {
|
|
283
330
|
/** The sandbox's URL scheme, in lower case. */
|
|
@@ -285,23 +332,38 @@ interface PreviewLink {
|
|
|
285
332
|
readonly channel: string;
|
|
286
333
|
/** The fingerprint the channel's bundles need; another build refuses them. */
|
|
287
334
|
readonly fingerprintHash: string;
|
|
335
|
+
/**
|
|
336
|
+
* The platform the link is for, absent from a link that names none: the
|
|
337
|
+
* other platform's sandbox build, which both can register the same scheme
|
|
338
|
+
* for, says which QR code to scan instead.
|
|
339
|
+
*/
|
|
340
|
+
readonly platform?: PreviewLinkPlatform;
|
|
288
341
|
}
|
|
289
342
|
/**
|
|
290
|
-
* The link a preview QR holds. `
|
|
291
|
-
*
|
|
343
|
+
* The link a preview QR holds. `urlScheme` is the one the sandbox build
|
|
344
|
+
* registered; without it, the one derived from `appId`, the scheme's
|
|
345
|
+
* `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
|
|
346
|
+
* `.sandbox` suffix.
|
|
292
347
|
*/
|
|
293
|
-
declare const createPreviewLink: ({ appId, channel, fingerprintHash }: {
|
|
294
|
-
readonly appId: string;
|
|
348
|
+
declare const createPreviewLink: ({ urlScheme, appId, channel, fingerprintHash, platform }: {
|
|
295
349
|
readonly channel: string;
|
|
296
350
|
readonly fingerprintHash: string;
|
|
297
|
-
|
|
351
|
+
readonly platform?: PreviewLinkPlatform;
|
|
352
|
+
} & ({
|
|
353
|
+
readonly urlScheme: string;
|
|
354
|
+
readonly appId?: string;
|
|
355
|
+
} | {
|
|
356
|
+
readonly urlScheme?: undefined;
|
|
357
|
+
readonly appId: string;
|
|
358
|
+
})) => string;
|
|
298
359
|
/**
|
|
299
360
|
* 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.
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
361
|
+
* repeated or missing parameter, or a channel no release can target. It takes
|
|
362
|
+
* any URL scheme: a sandbox build refuses a link of another scheme than its
|
|
363
|
+
* own. A `platform` other than `ios` or `android` reads as none. Native code
|
|
364
|
+
* parses it the same way before any JavaScript runs, in HotUpdaterSandboxLink,
|
|
365
|
+
* and shares the vectors in test-utils' `sandbox-preview-links.json`.
|
|
304
366
|
*/
|
|
305
367
|
declare const parsePreviewLink: (link: string) => PreviewLink | null;
|
|
306
368
|
//#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 };
|
|
369
|
+
export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, type PreviewLinkPlatform, 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,25 @@ 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
|
|
276
|
-
* the app's own scheme would ask which app to open beside
|
|
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
|
-
/**
|
|
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;
|
|
326
|
+
/** The platform a preview link is for. */
|
|
327
|
+
type PreviewLinkPlatform = "ios" | "android";
|
|
281
328
|
/** What a preview link asks a sandbox build to run. */
|
|
282
329
|
interface PreviewLink {
|
|
283
330
|
/** The sandbox's URL scheme, in lower case. */
|
|
@@ -285,23 +332,38 @@ interface PreviewLink {
|
|
|
285
332
|
readonly channel: string;
|
|
286
333
|
/** The fingerprint the channel's bundles need; another build refuses them. */
|
|
287
334
|
readonly fingerprintHash: string;
|
|
335
|
+
/**
|
|
336
|
+
* The platform the link is for, absent from a link that names none: the
|
|
337
|
+
* other platform's sandbox build, which both can register the same scheme
|
|
338
|
+
* for, says which QR code to scan instead.
|
|
339
|
+
*/
|
|
340
|
+
readonly platform?: PreviewLinkPlatform;
|
|
288
341
|
}
|
|
289
342
|
/**
|
|
290
|
-
* The link a preview QR holds. `
|
|
291
|
-
*
|
|
343
|
+
* The link a preview QR holds. `urlScheme` is the one the sandbox build
|
|
344
|
+
* registered; without it, the one derived from `appId`, the scheme's
|
|
345
|
+
* `bundleIdentifier` or `packageName`: the ID before the Android sandbox's
|
|
346
|
+
* `.sandbox` suffix.
|
|
292
347
|
*/
|
|
293
|
-
declare const createPreviewLink: ({ appId, channel, fingerprintHash }: {
|
|
294
|
-
readonly appId: string;
|
|
348
|
+
declare const createPreviewLink: ({ urlScheme, appId, channel, fingerprintHash, platform }: {
|
|
295
349
|
readonly channel: string;
|
|
296
350
|
readonly fingerprintHash: string;
|
|
297
|
-
|
|
351
|
+
readonly platform?: PreviewLinkPlatform;
|
|
352
|
+
} & ({
|
|
353
|
+
readonly urlScheme: string;
|
|
354
|
+
readonly appId?: string;
|
|
355
|
+
} | {
|
|
356
|
+
readonly urlScheme?: undefined;
|
|
357
|
+
readonly appId: string;
|
|
358
|
+
})) => string;
|
|
298
359
|
/**
|
|
299
360
|
* 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.
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
361
|
+
* repeated or missing parameter, or a channel no release can target. It takes
|
|
362
|
+
* any URL scheme: a sandbox build refuses a link of another scheme than its
|
|
363
|
+
* own. A `platform` other than `ios` or `android` reads as none. Native code
|
|
364
|
+
* parses it the same way before any JavaScript runs, in HotUpdaterSandboxLink,
|
|
365
|
+
* and shares the vectors in test-utils' `sandbox-preview-links.json`.
|
|
304
366
|
*/
|
|
305
367
|
declare const parsePreviewLink: (link: string) => PreviewLink | null;
|
|
306
368
|
//#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 };
|
|
369
|
+
export { type ByteSource, type ImportableNativeBuild, type IpaDistribution, type IpaInstallInfo, type NativeArtifactCheck, NativeArtifactError, type NativeArtifactInfo, type NativeArtifactKind, type NativeArtifactProblem, type NativeArtifactProblemCode, type PreviewLink, type PreviewLinkPlatform, 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 };
|
package/dist/native-artifact.mjs
CHANGED
|
@@ -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
|
-
|
|
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,65 @@ 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
|
|
588
|
-
* the app's own scheme would ask which app to open beside
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
595
|
-
*
|
|
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
|
|
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, platform }) => {
|
|
598
671
|
assertCanonicalChannelName(channel);
|
|
599
|
-
|
|
672
|
+
if (platform !== void 0 && !PREVIEW_LINK_PLATFORMS.has(platform)) throw new Error(`A preview link's platform is ios or android, not ${platform}.`);
|
|
673
|
+
const link = `${(urlScheme ?? sandboxUrlSchemeOf(appId)).toLowerCase()}://hot-updater/preview?channel=${encodeURIComponent(channel)}&fingerprint=${encodeURIComponent(fingerprintHash)}`;
|
|
674
|
+
return platform === void 0 ? link : `${link}&platform=${platform}`;
|
|
600
675
|
};
|
|
601
|
-
|
|
676
|
+
/** Any URL scheme: which app's it is, the app that opens the link decides. */
|
|
677
|
+
const PREVIEW_LINK = /^([a-z][a-z0-9+.-]*):\/\/hot-updater\/preview\?([^#]*)$/iu;
|
|
678
|
+
/**
|
|
679
|
+
* A URL scheme in ASCII alone: case folding lets `/iu` match `K` (Kelvin) or
|
|
680
|
+
* `ſ` as a letter.
|
|
681
|
+
*/
|
|
682
|
+
const ASCII_URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
|
|
602
683
|
const MAX_FINGERPRINT_LENGTH = 256;
|
|
684
|
+
const PREVIEW_LINK_PLATFORMS = /* @__PURE__ */ new Set(["ios", "android"]);
|
|
603
685
|
/**
|
|
604
686
|
* 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.
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
687
|
+
* repeated or missing parameter, or a channel no release can target. It takes
|
|
688
|
+
* any URL scheme: a sandbox build refuses a link of another scheme than its
|
|
689
|
+
* own. A `platform` other than `ios` or `android` reads as none. Native code
|
|
690
|
+
* parses it the same way before any JavaScript runs, in HotUpdaterSandboxLink,
|
|
691
|
+
* and shares the vectors in test-utils' `sandbox-preview-links.json`.
|
|
609
692
|
*/
|
|
610
693
|
const parsePreviewLink = (link) => {
|
|
611
694
|
const match = PREVIEW_LINK.exec(link);
|
|
612
|
-
if (match === null) return null;
|
|
695
|
+
if (match === null || !ASCII_URL_SCHEME.test(match[1])) return null;
|
|
613
696
|
const parameters = /* @__PURE__ */ new Map();
|
|
614
697
|
for (const parameter of match[2].split("&")) {
|
|
615
698
|
const separator = parameter.indexOf("=");
|
|
@@ -632,10 +715,12 @@ const parsePreviewLink = (link) => {
|
|
|
632
715
|
} catch {
|
|
633
716
|
return null;
|
|
634
717
|
}
|
|
718
|
+
const platform = parameters.get("platform");
|
|
635
719
|
return {
|
|
636
720
|
urlScheme: match[1].toLowerCase(),
|
|
637
721
|
channel,
|
|
638
|
-
fingerprintHash
|
|
722
|
+
fingerprintHash,
|
|
723
|
+
...platform !== void 0 && PREVIEW_LINK_PLATFORMS.has(platform) ? { platform } : {}
|
|
639
724
|
};
|
|
640
725
|
};
|
|
641
726
|
//#endregion
|
|
@@ -1062,7 +1147,7 @@ const readAndroid = async (source, kind, entries, budget) => {
|
|
|
1062
1147
|
},
|
|
1063
1148
|
entry: {
|
|
1064
1149
|
launchers: manifest.launchers,
|
|
1065
|
-
sandboxUrlScheme: manifest
|
|
1150
|
+
sandboxUrlScheme: androidSandboxUrlScheme(manifest)
|
|
1066
1151
|
},
|
|
1067
1152
|
builtInBundle: bundle === void 0 ? null : {
|
|
1068
1153
|
path: bundle.name,
|
|
@@ -1070,16 +1155,41 @@ const readAndroid = async (source, kind, entries, budget) => {
|
|
|
1070
1155
|
}
|
|
1071
1156
|
};
|
|
1072
1157
|
};
|
|
1073
|
-
/**
|
|
1158
|
+
/**
|
|
1159
|
+
* The URL scheme an Android sandbox build registers, or null: the one its
|
|
1160
|
+
* activity's `SANDBOX_URL_SCHEME_META_DATA` names, when the activity's `VIEW`
|
|
1161
|
+
* filters take it too. An artifact built before the meta-data takes the one
|
|
1162
|
+
* with the derived scheme's prefix.
|
|
1163
|
+
*/
|
|
1164
|
+
const androidSandboxUrlScheme = (manifest) => {
|
|
1165
|
+
const schemes = manifest.urlSchemes.get("com.hotupdater.HotUpdaterSandboxActivity") ?? [];
|
|
1166
|
+
const declared = manifest.componentMetaData.get(SANDBOX_ACTIVITY)?.get(SANDBOX_URL_SCHEME_META_DATA);
|
|
1167
|
+
if (declared === void 0) return schemes.find(isSandboxUrlScheme) ?? null;
|
|
1168
|
+
if (declared.type !== "string") return null;
|
|
1169
|
+
return schemes.includes(declared.value) ? declared.value : null;
|
|
1170
|
+
};
|
|
1171
|
+
/**
|
|
1172
|
+
* The sandbox URL scheme of an Info.plist, or null: the one
|
|
1173
|
+
* `SANDBOX_URL_SCHEME_INFO_PLIST_KEY` records, by `recordedSandboxUrlScheme`'s
|
|
1174
|
+
* rule. A prerelease's artifact, with no key, gives its named URL type's one
|
|
1175
|
+
* scheme, or, with no named type, one with the derived scheme's prefix.
|
|
1176
|
+
*/
|
|
1074
1177
|
const sandboxUrlSchemeIn = (info) => {
|
|
1075
1178
|
const types = info["CFBundleURLTypes"];
|
|
1076
1179
|
if (!Array.isArray(types)) return null;
|
|
1077
|
-
|
|
1180
|
+
const schemesOf = (type) => {
|
|
1078
1181
|
const schemes = type?.CFBundleURLSchemes;
|
|
1079
|
-
|
|
1080
|
-
|
|
1182
|
+
return Array.isArray(schemes) ? schemes.filter((scheme) => typeof scheme === "string") : [];
|
|
1183
|
+
};
|
|
1184
|
+
const named = types.filter((type) => type?.CFBundleURLName === SANDBOX_URL_TYPE_NAME);
|
|
1185
|
+
const recorded = recordedSandboxUrlScheme("HOT_UPDATER_SANDBOX_URL_SCHEME" in info ? info[SANDBOX_URL_SCHEME_INFO_PLIST_KEY] : void 0, named);
|
|
1186
|
+
if (recorded !== void 0) return recorded;
|
|
1187
|
+
if (named.length > 1) return null;
|
|
1188
|
+
if (named.length === 1) {
|
|
1189
|
+
const schemes = schemesOf(named[0]);
|
|
1190
|
+
return schemes.length === 1 ? schemes[0] : null;
|
|
1081
1191
|
}
|
|
1082
|
-
return null;
|
|
1192
|
+
return types.flatMap(schemesOf).find(isSandboxUrlScheme) ?? null;
|
|
1083
1193
|
};
|
|
1084
1194
|
const stringValue = (value) => typeof value === "string" && value !== "" ? value : null;
|
|
1085
1195
|
const readIos = async (source, kind, entries, budget) => {
|
|
@@ -1264,7 +1374,8 @@ const checkNativeArtifact = (info, { updateStrategy, appIds = [], channel: chann
|
|
|
1264
1374
|
fingerprintHash,
|
|
1265
1375
|
appVersion,
|
|
1266
1376
|
builtInBundlePath: info.builtInBundle.path,
|
|
1267
|
-
sandbox: info.sandbox.code
|
|
1377
|
+
sandbox: info.sandbox.code,
|
|
1378
|
+
sandboxUrlScheme: info.sandbox.code ? info.entry.sandboxUrlScheme : null
|
|
1268
1379
|
}
|
|
1269
1380
|
};
|
|
1270
1381
|
};
|
|
@@ -1410,4 +1521,4 @@ const readIpaInstallInfo = async (source) => {
|
|
|
1410
1521
|
};
|
|
1411
1522
|
};
|
|
1412
1523
|
//#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 };
|
|
1524
|
+
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 };
|