@qore-id/react-native-qoreid-sdk 2.0.1 → 2.1.0-rc
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/RNQoreIdSdk.podspec +9 -3
- package/android/build.gradle +2 -0
- package/android/src/main/java/com/qoreid/reactnativeqoreidsdk/RNQoreIdSdkModule.kt +26 -27
- package/app.plugin.js +30 -0
- package/ios/RNQoreIdSdk.h +0 -13
- package/ios/RNQoreIdSdk.mm +19 -10
- package/ios/ViewController.swift +10 -10
- package/package.json +25 -4
- package/scripts/android/setupQoreid.gradle.kts +225 -0
- package/scripts/ios/qoreid_sdk_pods.rb +365 -0
- package/scripts/js/android-setup.js +37 -0
- package/scripts/js/ios-setup.js +71 -0
- package/scripts/js/setup.js +10 -0
- package/scripts/js/uninstall-android.js +36 -0
- package/scripts/js/uninstall-ios.js +42 -0
- package/scripts/js/uninstall.js +10 -0
- package/scripts/js/utils.js +213 -0
- package/scripts/qoreid.config.json +1 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
const { spawn } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
function run(script) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const proc = spawn(process.execPath, [path.join(__dirname, script)], {
|
|
8
|
+
stdio: 'inherit',
|
|
9
|
+
});
|
|
10
|
+
proc.on('close', (code) =>
|
|
11
|
+
code === 0
|
|
12
|
+
? resolve()
|
|
13
|
+
: reject(new Error(`${script} exited with code ${code}`))
|
|
14
|
+
);
|
|
15
|
+
proc.on('error', reject);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function removeQoreIdExpoPlugin() {
|
|
20
|
+
const cwd = process.cwd().replace(/\/node_modules\/.*/gi, '');
|
|
21
|
+
|
|
22
|
+
const jsonPath = path.join(cwd, 'app.json');
|
|
23
|
+
const jsPath = path.join(cwd, 'app.config.js');
|
|
24
|
+
// Prefer app.json, but fall back to app.config.js if the project uses that
|
|
25
|
+
const appjsonPath = fs.existsSync(jsonPath)
|
|
26
|
+
? jsonPath
|
|
27
|
+
: fs.existsSync(jsPath)
|
|
28
|
+
? jsPath
|
|
29
|
+
: jsonPath;
|
|
30
|
+
|
|
31
|
+
if (!fs.existsSync(appjsonPath)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let content = fs.readFileSync(appjsonPath, 'utf8');
|
|
36
|
+
|
|
37
|
+
// check if expo key exists
|
|
38
|
+
const expoKeyRegex = /("expo"\s*[:=]\s*\{)|(\bexpo\s*[:=]\s*\{)/gm;
|
|
39
|
+
const expoKeyMatch = content.match(expoKeyRegex);
|
|
40
|
+
if (!expoKeyMatch) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (appjsonPath.endsWith('.js')) {
|
|
45
|
+
// Find a plugins array (supports both "plugins: [...]" and "plugins = [...]")
|
|
46
|
+
content = content.replace(
|
|
47
|
+
/(plugins\s*[:=]\s*\[)([\s\S]*?)(\])/gm,
|
|
48
|
+
(match, prefix, inner, suffix) => {
|
|
49
|
+
// Match either a string entry:
|
|
50
|
+
// '@qore-id/react-native-qoreid-sdk/plugin'
|
|
51
|
+
// or an array entry:
|
|
52
|
+
// ['@qore-id/react-native-qoreid-sdk/plugin', { ... }]
|
|
53
|
+
const pluginItemRegex =
|
|
54
|
+
/(\[\s*(['"])@qore-id\/react-native-qoreid-sdk\/plugin\2\s*(?:,\s*\{[\s\S]*?\}\s*)?\s*\]|(['"])@qore-id\/react-native-qoreid-sdk\/plugin\3)/g;
|
|
55
|
+
|
|
56
|
+
// Remove plugin entries
|
|
57
|
+
let newInner = inner.replace(pluginItemRegex, '');
|
|
58
|
+
|
|
59
|
+
// Clean up any leftover commas/whitespace caused by the removal
|
|
60
|
+
// Remove duplicated commas
|
|
61
|
+
newInner = newInner.replace(/,\s*,/g, ',');
|
|
62
|
+
// Remove leading commas
|
|
63
|
+
newInner = newInner.replace(/^\s*,\s*/g, '');
|
|
64
|
+
// Remove trailing commas
|
|
65
|
+
newInner = newInner.replace(/,\s*$/g, '');
|
|
66
|
+
// If the array becomes empty, ensure it's truly empty (no stray whitespace/newlines)
|
|
67
|
+
if (/^\s*$/.test(newInner)) newInner = '';
|
|
68
|
+
|
|
69
|
+
return prefix + newInner + suffix;
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
// Find a plugins array (supports both "plugins: [...]" and "plugins = [...]")
|
|
74
|
+
const appJson = JSON.parse(content);
|
|
75
|
+
if (!appJson.expo.plugins) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
appJson.expo.plugins = appJson.expo.plugins.filter((plugin) => {
|
|
79
|
+
if (typeof plugin === 'string') {
|
|
80
|
+
return plugin !== '@qore-id/react-native-qoreid-sdk/plugin';
|
|
81
|
+
} else if (Array.isArray(plugin) && plugin.length > 0) {
|
|
82
|
+
return plugin[0] !== '@qore-id/react-native-qoreid-sdk/plugin';
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
content = JSON.stringify(appJson, null, 2);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync(appjsonPath, content);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function extractAndroidNamespace() {
|
|
93
|
+
const configPath = path.resolve(process.cwd(), 'app.json');
|
|
94
|
+
const configJsPath = path.resolve(process.cwd(), 'app.config.js');
|
|
95
|
+
let config;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
if (fs.existsSync(configPath)) {
|
|
99
|
+
// Read app.json file
|
|
100
|
+
const rawConfig = fs.readFileSync(configPath, 'utf8');
|
|
101
|
+
config = JSON.parse(rawConfig);
|
|
102
|
+
} else if (fs.existsSync(configJsPath)) {
|
|
103
|
+
// To safely read app.config.js without executing potentially dangerous code,
|
|
104
|
+
// we typically need to use the Expo CLI's internal methods, but for a
|
|
105
|
+
// standalone script, a simple require often works if the file exports a config object.
|
|
106
|
+
config = require(configJsPath)({ projectRoot: process.cwd() });
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Could not find app.json or app.config.js');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!config.expo && !config.android) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const androidPackage =
|
|
116
|
+
config.expo?.android?.package || config.android?.package;
|
|
117
|
+
|
|
118
|
+
if (androidPackage) {
|
|
119
|
+
return androidPackage;
|
|
120
|
+
} else {
|
|
121
|
+
throw new Error('Android package name not found in config.');
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.error(
|
|
125
|
+
`❌ Error reading or parsing Expo configuration: ${e.message}`
|
|
126
|
+
);
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const sharedEnv = {
|
|
132
|
+
set(value, name) {
|
|
133
|
+
const qoreidConfig = require('../qoreid.config.json') ?? {};
|
|
134
|
+
qoreidConfig[name] = value;
|
|
135
|
+
fs.writeFileSync(
|
|
136
|
+
path.join(__dirname, '..', 'qoreid.config.json'),
|
|
137
|
+
JSON.stringify(qoreidConfig, null, 2),
|
|
138
|
+
'utf8'
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
getCommand(name) {
|
|
142
|
+
const qoreidConfig = require('../qoreid.config.json') ?? {};
|
|
143
|
+
const isWindows = process.platform === 'win32';
|
|
144
|
+
|
|
145
|
+
if (!qoreidConfig[name]) {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return isWindows
|
|
150
|
+
? `set ${name}=${qoreidConfig[name]}`
|
|
151
|
+
: `export ${name}=${qoreidConfig[name]}`;
|
|
152
|
+
},
|
|
153
|
+
get(name) {
|
|
154
|
+
const qoreidConfig = require('../qoreid.config.json') ?? {};
|
|
155
|
+
return qoreidConfig[name];
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Patch for bare RN
|
|
160
|
+
// check for use app name and set in env
|
|
161
|
+
function injectAppName() {
|
|
162
|
+
const indexJsPath = path.join(process.cwd(), 'index.js');
|
|
163
|
+
if (fs.existsSync(indexJsPath)) {
|
|
164
|
+
let indexJsContent = fs.readFileSync(indexJsPath, 'utf8');
|
|
165
|
+
const appNameRegex =
|
|
166
|
+
/import\s+\{\s*name\s+as\s+appName\s*\}\s+from\s+['"]\.\/app\.json['"];?/;
|
|
167
|
+
|
|
168
|
+
if (appNameRegex.test(indexJsContent)) {
|
|
169
|
+
const appjsonPath = path.join(process.cwd(), 'app.json');
|
|
170
|
+
const appStrContent = fs.existsSync(appjsonPath)
|
|
171
|
+
? fs.readFileSync(appjsonPath, 'utf8')
|
|
172
|
+
: '';
|
|
173
|
+
const jsonContent = appStrContent ? JSON.parse(appStrContent) : {};
|
|
174
|
+
|
|
175
|
+
sharedEnv.set(jsonContent?.name ?? 'main', 'RN_APP_NAME');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function patchExpoAndroidGeneratedAutolinking(namespace) {
|
|
181
|
+
const autolinkingJsonPath = path.join(
|
|
182
|
+
process.cwd(),
|
|
183
|
+
'android',
|
|
184
|
+
'build',
|
|
185
|
+
'generated',
|
|
186
|
+
'autolinking',
|
|
187
|
+
'autolinking.json'
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (fs.existsSync(autolinkingJsonPath)) {
|
|
191
|
+
let autolinkingContent = fs.readFileSync(autolinkingJsonPath, 'utf8');
|
|
192
|
+
const jsonContent = JSON.parse(autolinkingContent);
|
|
193
|
+
|
|
194
|
+
// Update the namespace in the JSON content
|
|
195
|
+
if (jsonContent.project.android.packageName === namespace) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
jsonContent.project.android.packageName = namespace;
|
|
200
|
+
|
|
201
|
+
// Write the updated JSON back to the file
|
|
202
|
+
fs.writeFileSync(autolinkingJsonPath, JSON.stringify(jsonContent, null, 2));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = {
|
|
207
|
+
run,
|
|
208
|
+
removeQoreIdExpoPlugin,
|
|
209
|
+
sharedEnv,
|
|
210
|
+
injectAppName,
|
|
211
|
+
extractAndroidNamespace,
|
|
212
|
+
patchExpoAndroidGeneratedAutolinking,
|
|
213
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|