Repository navigation
Expand file tree
/
Copy pathextras.js
More file actions
78 lines (67 loc) · 2.3 KB
/
Copy pathextras.js
File metadata and controls
78 lines (67 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Demo-only app-link documents: /.well-known/apple-app-site-association (iOS
// Universal Links) and /.well-known/assetlinks.json (Android App Links). They
// are static once configured, so this module returns the payloads and
// server.js owns the routing.
const parseCommaList = (value) =>
String(value || '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);
const resolveIosAppIds = () => {
const fromMulti = parseCommaList(process.env.DEMO_IOS_APP_IDS);
if (fromMulti.length > 0) {
return fromMulti;
}
const teamId = process.env.DEMO_IOS_TEAM_ID;
const bundleId = process.env.DEMO_IOS_BUNDLE_ID;
if (teamId && bundleId) {
return [`${teamId}.${bundleId}`];
}
return [];
};
const resolveAndroidTargets = () => {
const multiTargets = parseCommaList(process.env.DEMO_ANDROID_APP_LINKS)
.map((entry) => {
const [packageName, fingerprint] = entry.split('|').map((part) => part?.trim());
if (!packageName || !fingerprint) return null;
return { packageName, fingerprint };
})
.filter(Boolean);
if (multiTargets.length > 0) {
return multiTargets;
}
const androidPackage = process.env.DEMO_ANDROID_PACKAGE_NAME;
const androidFingerprint = process.env.DEMO_ANDROID_SHA256;
if (androidPackage && androidFingerprint) {
return [{ packageName: androidPackage, fingerprint: androidFingerprint }];
}
return [];
};
// Returns { path: jsonPayload } for the app-link documents this process is
// configured to serve. An unconfigured platform contributes no route at all.
export const resolveExtrasRoutes = () => {
const routes = {};
const iosAppIds = resolveIosAppIds();
if (iosAppIds.length > 0) {
routes['/.well-known/apple-app-site-association'] = {
applinks: {
details: iosAppIds.map((appId) => ({
appID: appId,
paths: ['/_krdpass/oauth/callback'],
})),
},
};
}
const androidTargets = resolveAndroidTargets();
if (androidTargets.length > 0) {
routes['/.well-known/assetlinks.json'] = androidTargets.map(({ packageName, fingerprint }) => ({
relation: ['delegate_permission/common.handle_all_urls'],
target: {
namespace: 'android_app',
package_name: packageName,
sha256_cert_fingerprints: [fingerprint],
},
}));
}
return routes;
};