@li-nk.me/react-native-sdk 0.1.1
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/README.md +103 -0
- package/lib/index.d.ts +56 -0
- package/lib/index.js +507 -0
- package/package.json +54 -0
- package/plugin/app.plugin.js +131 -0
- package/src/index.ts +580 -0
- package/src/react-native-stub.d.ts +11 -0
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@li-nk.me/react-native-sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Pure TypeScript React Native SDK for LinkMe deep and deferred links.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"react-native": "src/index.ts",
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"lib",
|
|
12
|
+
"plugin"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"clean": "rimraf lib",
|
|
17
|
+
"prepare": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react-native",
|
|
21
|
+
"linkme",
|
|
22
|
+
"deep-linking",
|
|
23
|
+
"deferred",
|
|
24
|
+
"sdk"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18",
|
|
29
|
+
"react-native": ">=0.72.0",
|
|
30
|
+
"expo-clipboard": ">=6.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"react": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"react-native": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"expo-clipboard": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@expo/config-plugins": "^8.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^20.12.7",
|
|
51
|
+
"rimraf": "^5.0.0",
|
|
52
|
+
"typescript": "^5.4.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const { withEntitlementsPlist, withAndroidManifest } = require('@expo/config-plugins');
|
|
2
|
+
|
|
3
|
+
function ensureArray(val) {
|
|
4
|
+
if (!val) return [];
|
|
5
|
+
return Array.isArray(val) ? val : [val];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const withLinkMe = (config, props = {}) => {
|
|
9
|
+
const schemes = ensureArray(props.schemes);
|
|
10
|
+
const associatedDomains = ensureArray(props.associatedDomains);
|
|
11
|
+
const hosts = ensureArray(props.hosts);
|
|
12
|
+
|
|
13
|
+
const withIOSEntitlements = withEntitlementsPlist(config, (conf) => {
|
|
14
|
+
const domains = associatedDomains.length ? associatedDomains : hosts;
|
|
15
|
+
if (domains.length) {
|
|
16
|
+
const current = conf.modResults['com.apple.developer.associated-domains'] || [];
|
|
17
|
+
const normalized = domains.map((domain) =>
|
|
18
|
+
String(domain).startsWith('applinks:') ? String(domain) : `applinks:${domain}`
|
|
19
|
+
);
|
|
20
|
+
const merged = Array.from(new Set([...current, ...normalized]));
|
|
21
|
+
conf.modResults['com.apple.developer.associated-domains'] = merged;
|
|
22
|
+
}
|
|
23
|
+
return conf;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return withAndroidManifest(withIOSEntitlements, (conf) => {
|
|
27
|
+
const manifest = conf.modResults;
|
|
28
|
+
if (!manifest) {
|
|
29
|
+
return conf;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Handle both possible structures: manifest.manifest or manifest directly
|
|
33
|
+
const manifestRoot = manifest.manifest || manifest;
|
|
34
|
+
const application = manifestRoot.application;
|
|
35
|
+
if (!application) {
|
|
36
|
+
return conf;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Ensure application is an array
|
|
40
|
+
const applications = Array.isArray(application) ? application : [application];
|
|
41
|
+
if (applications.length === 0) {
|
|
42
|
+
return conf;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const app = applications.find((it) => it['$']?.['android:name'] === '.MainApplication') || applications[0];
|
|
46
|
+
if (!app) {
|
|
47
|
+
return conf;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ensure activity is an array
|
|
51
|
+
if (!app.activity) {
|
|
52
|
+
app.activity = [];
|
|
53
|
+
}
|
|
54
|
+
if (!Array.isArray(app.activity)) {
|
|
55
|
+
app.activity = [app.activity];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Find MainActivity
|
|
59
|
+
const mainActivity = app.activity.find((a) => {
|
|
60
|
+
const name = a['$']?.['android:name'];
|
|
61
|
+
return name === '.MainActivity' || name === 'MainActivity';
|
|
62
|
+
}) || app.activity[0];
|
|
63
|
+
|
|
64
|
+
if (!mainActivity) {
|
|
65
|
+
return conf;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Ensure intent-filter is an array
|
|
69
|
+
if (!mainActivity['intent-filter']) {
|
|
70
|
+
mainActivity['intent-filter'] = [];
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(mainActivity['intent-filter'])) {
|
|
73
|
+
mainActivity['intent-filter'] = [mainActivity['intent-filter']];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Add HTTPS intent-filters with autoVerify for App Links
|
|
77
|
+
hosts.forEach((host) => {
|
|
78
|
+
if (!host || typeof host !== 'string') return;
|
|
79
|
+
|
|
80
|
+
// Check if this host already exists to avoid duplicates
|
|
81
|
+
const exists = mainActivity['intent-filter'].some((filter) => {
|
|
82
|
+
const filterData = filter.data;
|
|
83
|
+
if (!Array.isArray(filterData)) return false;
|
|
84
|
+
return filterData.some((d) => {
|
|
85
|
+
return d['$']?.['android:scheme'] === 'https' && d['$']?.['android:host'] === host;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!exists) {
|
|
90
|
+
mainActivity['intent-filter'].push({
|
|
91
|
+
'$': { 'android:autoVerify': 'true' },
|
|
92
|
+
action: [{ '$': { 'android:name': 'android.intent.action.VIEW' } }],
|
|
93
|
+
category: [
|
|
94
|
+
{ '$': { 'android:name': 'android.intent.category.DEFAULT' } },
|
|
95
|
+
{ '$': { 'android:name': 'android.intent.category.BROWSABLE' } },
|
|
96
|
+
],
|
|
97
|
+
data: [{ '$': { 'android:scheme': 'https', 'android:host': host } }],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Add custom scheme intent-filters
|
|
103
|
+
schemes.forEach((scheme) => {
|
|
104
|
+
if (!scheme || typeof scheme !== 'string') return;
|
|
105
|
+
|
|
106
|
+
// Check if this scheme already exists to avoid duplicates
|
|
107
|
+
const exists = mainActivity['intent-filter'].some((filter) => {
|
|
108
|
+
const filterData = filter.data;
|
|
109
|
+
if (!Array.isArray(filterData)) return false;
|
|
110
|
+
return filterData.some((d) => {
|
|
111
|
+
return d['$']?.['android:scheme'] === scheme;
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (!exists) {
|
|
116
|
+
mainActivity['intent-filter'].push({
|
|
117
|
+
action: [{ '$': { 'android:name': 'android.intent.action.VIEW' } }],
|
|
118
|
+
category: [
|
|
119
|
+
{ '$': { 'android:name': 'android.intent.category.DEFAULT' } },
|
|
120
|
+
{ '$': { 'android:name': 'android.intent.category.BROWSABLE' } },
|
|
121
|
+
],
|
|
122
|
+
data: [{ '$': { 'android:scheme': scheme } }],
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return conf;
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
module.exports = withLinkMe;
|