react-native-bspatch 1.1.4 → 2.0.0
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 +22 -32
- package/android/src/main/java/vn/reactnativebspatch/BsPatchModule.kt +15 -102
- package/android/src/main/java/vn/reactnativebspatch/OtaBundleResolver.kt +21 -1
- package/cpp/bsdiff/bspatch.c +1 -0
- package/ios/OtaBundleResolver.swift +16 -1
- package/ios/RNBsPatch.mm +61 -154
- package/lib/commonjs/NativeBsPatch.js.map +1 -1
- package/lib/commonjs/index.js +4 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ota/OtaProvider.js +26 -22
- package/lib/commonjs/ota/OtaProvider.js.map +1 -1
- package/lib/commonjs/ota/otaAssetResolver.js +8 -2
- package/lib/commonjs/ota/otaAssetResolver.js.map +1 -1
- package/lib/commonjs/ota/otaCore.js +89 -141
- package/lib/commonjs/ota/otaCore.js.map +1 -1
- package/lib/commonjs/ota/otaLogger.js +0 -2
- package/lib/commonjs/ota/otaLogger.js.map +1 -1
- package/lib/commonjs/ota/otaMetadata.js +18 -7
- package/lib/commonjs/ota/otaMetadata.js.map +1 -1
- package/lib/commonjs/ota/storage/GitHubRawStorage.js +3 -1
- package/lib/commonjs/ota/storage/GitHubRawStorage.js.map +1 -1
- package/lib/commonjs/ota/types.js +1 -10
- package/lib/commonjs/ota/types.js.map +1 -1
- package/lib/module/NativeBsPatch.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/ota/OtaProvider.js +26 -22
- package/lib/module/ota/OtaProvider.js.map +1 -1
- package/lib/module/ota/otaAssetResolver.js +8 -2
- package/lib/module/ota/otaAssetResolver.js.map +1 -1
- package/lib/module/ota/otaCore.js +88 -139
- package/lib/module/ota/otaCore.js.map +1 -1
- package/lib/module/ota/otaLogger.js +0 -2
- package/lib/module/ota/otaLogger.js.map +1 -1
- package/lib/module/ota/otaMetadata.js +18 -7
- package/lib/module/ota/otaMetadata.js.map +1 -1
- package/lib/module/ota/storage/GitHubRawStorage.js +3 -1
- package/lib/module/ota/storage/GitHubRawStorage.js.map +1 -1
- package/lib/module/ota/types.js +0 -9
- package/lib/module/ota/types.js.map +1 -1
- package/lib/typescript/NativeBsPatch.d.ts +3 -15
- package/lib/typescript/NativeBsPatch.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/ota/OtaProvider.d.ts.map +1 -1
- package/lib/typescript/ota/otaAssetResolver.d.ts.map +1 -1
- package/lib/typescript/ota/otaCore.d.ts +5 -42
- package/lib/typescript/ota/otaCore.d.ts.map +1 -1
- package/lib/typescript/ota/otaLogger.d.ts +1 -3
- package/lib/typescript/ota/otaLogger.d.ts.map +1 -1
- package/lib/typescript/ota/otaMetadata.d.ts +2 -2
- package/lib/typescript/ota/otaMetadata.d.ts.map +1 -1
- package/lib/typescript/ota/types.d.ts +18 -54
- package/lib/typescript/ota/types.d.ts.map +1 -1
- package/package.json +3 -6
- package/react-native-bspatch.podspec +0 -1
- package/src/NativeBsPatch.ts +3 -16
- package/src/index.ts +1 -1
- package/src/ota/OtaProvider.tsx +24 -23
- package/src/ota/otaAssetResolver.ts +5 -2
- package/src/ota/otaCore.ts +118 -176
- package/src/ota/otaLogger.ts +0 -2
- package/src/ota/otaMetadata.ts +18 -8
- package/src/ota/storage/GitHubRawStorage.ts +1 -1
- package/src/ota/types.ts +18 -57
- package/tools/build_ota.sh +101 -174
- package/tools/setup_project.js +33 -14
- package/tools/update_registry.js +24 -28
- package/tools/{upload_ota_custom.sh → upload_ota.sh} +33 -114
- package/lib/commonjs/crypto-js.d.js +0 -2
- package/lib/commonjs/crypto-js.d.js.map +0 -1
- package/lib/commonjs/ota/storage/CustomStorage.js +0 -160
- package/lib/commonjs/ota/storage/CustomStorage.js.map +0 -1
- package/lib/commonjs/ota/storage/GitHubReleaseStorage.js +0 -99
- package/lib/commonjs/ota/storage/GitHubReleaseStorage.js.map +0 -1
- package/lib/module/crypto-js.d.js +0 -2
- package/lib/module/crypto-js.d.js.map +0 -1
- package/lib/module/ota/storage/CustomStorage.js +0 -154
- package/lib/module/ota/storage/CustomStorage.js.map +0 -1
- package/lib/module/ota/storage/GitHubReleaseStorage.js +0 -93
- package/lib/module/ota/storage/GitHubReleaseStorage.js.map +0 -1
- package/lib/typescript/ota/storage/CustomStorage.d.ts +0 -12
- package/lib/typescript/ota/storage/CustomStorage.d.ts.map +0 -1
- package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts +0 -20
- package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts.map +0 -1
- package/src/crypto-js.d.ts +0 -1
- package/src/ota/storage/CustomStorage.ts +0 -166
- package/src/ota/storage/GitHubReleaseStorage.ts +0 -103
- package/tools/bsdiff +0 -0
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GitHub Releases Storage Provider
|
|
3
|
-
*
|
|
4
|
-
* Reads the OTA registry from a GitHub Release asset and resolves download URLs
|
|
5
|
-
* directly from the release. Supports both public and token-authenticated repos.
|
|
6
|
-
*
|
|
7
|
-
* Registry format:
|
|
8
|
-
* - Expected at: `https://raw.githubusercontent.com/{owner}/{repo}/{tag}/{registryPath}`
|
|
9
|
-
* - Asset download: `https://github.com/{owner}/{repo}/releases/download/{tag}/{filename}`
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { Platform } from 'react-native';
|
|
13
|
-
import ReactNativeBlobUtil from 'react-native-blob-util';
|
|
14
|
-
import type { OtaPatch, OtaConfig, OtaStorageProvider } from '../types';
|
|
15
|
-
|
|
16
|
-
export class GitHubReleaseStorageProvider implements OtaStorageProvider {
|
|
17
|
-
private getRawRegistryUrl(config: OtaConfig): string {
|
|
18
|
-
const { repo, tag, registryPath = 'ota_registry.json' } = config.githubRelease!;
|
|
19
|
-
return `https://raw.githubusercontent.com/${repo}/${tag}/${registryPath}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private getAssetDownloadUrl(config: OtaConfig, filename: string): string {
|
|
23
|
-
const { repo, tag } = config.githubRelease!;
|
|
24
|
-
return `https://github.com/${repo}/releases/download/${tag}/${filename}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private authHeaders(token?: string): Record<string, string> {
|
|
28
|
-
if (!token) return {};
|
|
29
|
-
return { Authorization: `Bearer ${token}` };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async fetchManifest(config: OtaConfig): Promise<OtaPatch[]> {
|
|
33
|
-
if (!config.githubRelease) return config.bundledPatches || [];
|
|
34
|
-
|
|
35
|
-
const { token } = config.githubRelease;
|
|
36
|
-
const url = this.getRawRegistryUrl(config);
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const res = await ReactNativeBlobUtil.fetch(
|
|
40
|
-
'GET',
|
|
41
|
-
url,
|
|
42
|
-
this.authHeaders(token),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (res.respInfo.status !== 200) {
|
|
46
|
-
throw new Error(`Registry fetch failed with status ${res.respInfo.status}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const registry =
|
|
50
|
-
typeof res.data === 'string'
|
|
51
|
-
? JSON.parse(res.data)
|
|
52
|
-
: JSON.parse(JSON.stringify(res.data));
|
|
53
|
-
|
|
54
|
-
// Support both flat array (legacy) and structured format
|
|
55
|
-
if (Array.isArray(registry)) {
|
|
56
|
-
return registry.filter(
|
|
57
|
-
(p: OtaPatch) => !p.platform || p.platform === Platform.OS,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Structured: apps["1.0.0"].channels["production"].patches[]
|
|
62
|
-
if (!config.appVersion) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'[GitHubReleaseStorage] config.appVersion is required to query OTA registry',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
const appGroup = registry?.apps?.[config.appVersion];
|
|
68
|
-
const channelGroup = appGroup?.channels?.[config.githubRelease.repo] // use repo as channel fallback
|
|
69
|
-
?? appGroup?.channels?.production
|
|
70
|
-
?? appGroup?.flavors?.production;
|
|
71
|
-
|
|
72
|
-
if (!channelGroup?.patches?.length) {
|
|
73
|
-
return config.bundledPatches || [];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return channelGroup.patches.filter(
|
|
77
|
-
(p: OtaPatch) => !p.platform || p.platform === Platform.OS,
|
|
78
|
-
);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.warn('[GitHubStorage] Manifest fetch error:', (error as Error).message);
|
|
81
|
-
return config.bundledPatches || [];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async getUpdateFileUrl(filename: string, config: OtaConfig): Promise<string> {
|
|
86
|
-
if (!config.githubRelease) throw new Error('githubRelease config missing');
|
|
87
|
-
return this.getAssetDownloadUrl(config, filename);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async getAssetUrl(hash: string, ext: string, config: OtaConfig): Promise<string> {
|
|
91
|
-
if (!config.githubRelease) return '';
|
|
92
|
-
|
|
93
|
-
const { assetBaseUrl, tag, repo } = config.githubRelease;
|
|
94
|
-
|
|
95
|
-
// If a custom CDN/base is provided, use it
|
|
96
|
-
if (assetBaseUrl) {
|
|
97
|
-
return `${assetBaseUrl}/${hash}.${ext}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Fallback: serve from GitHub raw with optional token
|
|
101
|
-
return `https://raw.githubusercontent.com/${repo}/${tag}/assets/${hash}.${ext}`;
|
|
102
|
-
}
|
|
103
|
-
}
|
package/tools/bsdiff
DELETED
|
Binary file
|