react-native-bspatch 1.1.4 → 2.0.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.
Files changed (89) hide show
  1. package/README.md +22 -32
  2. package/android/src/main/java/vn/reactnativebspatch/BsPatchModule.kt +15 -102
  3. package/android/src/main/java/vn/reactnativebspatch/OtaBundleResolver.kt +21 -1
  4. package/cpp/bsdiff/bspatch.c +1 -0
  5. package/ios/OtaBundleResolver.swift +16 -1
  6. package/ios/RNBsPatch.mm +61 -154
  7. package/lib/commonjs/NativeBsPatch.js.map +1 -1
  8. package/lib/commonjs/index.js +4 -4
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/ota/OtaProvider.js +26 -22
  11. package/lib/commonjs/ota/OtaProvider.js.map +1 -1
  12. package/lib/commonjs/ota/otaAssetResolver.js +8 -2
  13. package/lib/commonjs/ota/otaAssetResolver.js.map +1 -1
  14. package/lib/commonjs/ota/otaCore.js +89 -141
  15. package/lib/commonjs/ota/otaCore.js.map +1 -1
  16. package/lib/commonjs/ota/otaLogger.js +0 -2
  17. package/lib/commonjs/ota/otaLogger.js.map +1 -1
  18. package/lib/commonjs/ota/otaMetadata.js +18 -7
  19. package/lib/commonjs/ota/otaMetadata.js.map +1 -1
  20. package/lib/commonjs/ota/storage/GitHubRawStorage.js +3 -1
  21. package/lib/commonjs/ota/storage/GitHubRawStorage.js.map +1 -1
  22. package/lib/commonjs/ota/types.js +1 -10
  23. package/lib/commonjs/ota/types.js.map +1 -1
  24. package/lib/module/NativeBsPatch.js.map +1 -1
  25. package/lib/module/index.js +1 -1
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/ota/OtaProvider.js +26 -22
  28. package/lib/module/ota/OtaProvider.js.map +1 -1
  29. package/lib/module/ota/otaAssetResolver.js +8 -2
  30. package/lib/module/ota/otaAssetResolver.js.map +1 -1
  31. package/lib/module/ota/otaCore.js +88 -139
  32. package/lib/module/ota/otaCore.js.map +1 -1
  33. package/lib/module/ota/otaLogger.js +0 -2
  34. package/lib/module/ota/otaLogger.js.map +1 -1
  35. package/lib/module/ota/otaMetadata.js +18 -7
  36. package/lib/module/ota/otaMetadata.js.map +1 -1
  37. package/lib/module/ota/storage/GitHubRawStorage.js +3 -1
  38. package/lib/module/ota/storage/GitHubRawStorage.js.map +1 -1
  39. package/lib/module/ota/types.js +0 -9
  40. package/lib/module/ota/types.js.map +1 -1
  41. package/lib/typescript/NativeBsPatch.d.ts +3 -15
  42. package/lib/typescript/NativeBsPatch.d.ts.map +1 -1
  43. package/lib/typescript/index.d.ts +1 -1
  44. package/lib/typescript/index.d.ts.map +1 -1
  45. package/lib/typescript/ota/OtaProvider.d.ts.map +1 -1
  46. package/lib/typescript/ota/otaAssetResolver.d.ts.map +1 -1
  47. package/lib/typescript/ota/otaCore.d.ts +5 -42
  48. package/lib/typescript/ota/otaCore.d.ts.map +1 -1
  49. package/lib/typescript/ota/otaLogger.d.ts +1 -3
  50. package/lib/typescript/ota/otaLogger.d.ts.map +1 -1
  51. package/lib/typescript/ota/otaMetadata.d.ts +2 -2
  52. package/lib/typescript/ota/otaMetadata.d.ts.map +1 -1
  53. package/lib/typescript/ota/types.d.ts +18 -54
  54. package/lib/typescript/ota/types.d.ts.map +1 -1
  55. package/package.json +3 -6
  56. package/react-native-bspatch.podspec +0 -1
  57. package/src/NativeBsPatch.ts +3 -16
  58. package/src/index.ts +1 -1
  59. package/src/ota/OtaProvider.tsx +24 -23
  60. package/src/ota/otaAssetResolver.ts +5 -2
  61. package/src/ota/otaCore.ts +118 -176
  62. package/src/ota/otaLogger.ts +0 -2
  63. package/src/ota/otaMetadata.ts +18 -8
  64. package/src/ota/storage/GitHubRawStorage.ts +1 -1
  65. package/src/ota/types.ts +18 -57
  66. package/tools/build_ota.sh +117 -183
  67. package/tools/setup_project.js +33 -14
  68. package/tools/update_registry.js +24 -28
  69. package/tools/{upload_ota_custom.sh → upload_ota.sh} +33 -114
  70. package/lib/commonjs/crypto-js.d.js +0 -2
  71. package/lib/commonjs/crypto-js.d.js.map +0 -1
  72. package/lib/commonjs/ota/storage/CustomStorage.js +0 -160
  73. package/lib/commonjs/ota/storage/CustomStorage.js.map +0 -1
  74. package/lib/commonjs/ota/storage/GitHubReleaseStorage.js +0 -99
  75. package/lib/commonjs/ota/storage/GitHubReleaseStorage.js.map +0 -1
  76. package/lib/module/crypto-js.d.js +0 -2
  77. package/lib/module/crypto-js.d.js.map +0 -1
  78. package/lib/module/ota/storage/CustomStorage.js +0 -154
  79. package/lib/module/ota/storage/CustomStorage.js.map +0 -1
  80. package/lib/module/ota/storage/GitHubReleaseStorage.js +0 -93
  81. package/lib/module/ota/storage/GitHubReleaseStorage.js.map +0 -1
  82. package/lib/typescript/ota/storage/CustomStorage.d.ts +0 -12
  83. package/lib/typescript/ota/storage/CustomStorage.d.ts.map +0 -1
  84. package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts +0 -20
  85. package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts.map +0 -1
  86. package/src/crypto-js.d.ts +0 -1
  87. package/src/ota/storage/CustomStorage.ts +0 -166
  88. package/src/ota/storage/GitHubReleaseStorage.ts +0 -103
  89. 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