@otaupdate/react-native 1.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.
Files changed (57) hide show
  1. package/README.md +321 -0
  2. package/android/build.gradle +70 -0
  3. package/android/src/expo/java/com/otaupdate/OtaUpdateExpoPackage.kt +37 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/com/otaupdate/OtaUpdate.kt +98 -0
  6. package/android/src/main/java/com/otaupdate/OtaUpdateInstaller.kt +211 -0
  7. package/android/src/main/java/com/otaupdate/OtaUpdateModule.kt +278 -0
  8. package/android/src/main/java/com/otaupdate/OtaUpdatePackage.kt +15 -0
  9. package/android/src/main/java/com/otaupdate/OtaUpdateStore.kt +268 -0
  10. package/app.plugin.js +3 -0
  11. package/expo-module.config.json +6 -0
  12. package/ios/OtaUpdate.h +46 -0
  13. package/ios/OtaUpdate.m +302 -0
  14. package/ios/OtaUpdateInstaller.h +25 -0
  15. package/ios/OtaUpdateInstaller.m +278 -0
  16. package/ios/OtaUpdateStore.h +69 -0
  17. package/ios/OtaUpdateStore.m +283 -0
  18. package/lib/OtaUpdate.d.ts +28 -0
  19. package/lib/OtaUpdate.d.ts.map +1 -0
  20. package/lib/OtaUpdate.js +254 -0
  21. package/lib/OtaUpdate.js.map +1 -0
  22. package/lib/api.d.ts +36 -0
  23. package/lib/api.d.ts.map +1 -0
  24. package/lib/api.js +89 -0
  25. package/lib/api.js.map +1 -0
  26. package/lib/index.d.ts +24 -0
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +37 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/native.d.ts +34 -0
  31. package/lib/native.d.ts.map +1 -0
  32. package/lib/native.js +34 -0
  33. package/lib/native.js.map +1 -0
  34. package/lib/types.d.ts +112 -0
  35. package/lib/types.d.ts.map +1 -0
  36. package/lib/types.js +27 -0
  37. package/lib/types.js.map +1 -0
  38. package/lib/useOtaUpdate.d.ts +17 -0
  39. package/lib/useOtaUpdate.d.ts.map +1 -0
  40. package/lib/useOtaUpdate.js +81 -0
  41. package/lib/useOtaUpdate.js.map +1 -0
  42. package/lib/withOtaUpdate.d.ts +10 -0
  43. package/lib/withOtaUpdate.d.ts.map +1 -0
  44. package/lib/withOtaUpdate.js +21 -0
  45. package/lib/withOtaUpdate.js.map +1 -0
  46. package/package.json +54 -0
  47. package/plugin/build/index.d.ts +11 -0
  48. package/plugin/build/index.js +97 -0
  49. package/react-native-ota-update.podspec +43 -0
  50. package/react-native.config.js +21 -0
  51. package/src/OtaUpdate.ts +293 -0
  52. package/src/api.ts +122 -0
  53. package/src/index.ts +55 -0
  54. package/src/native.ts +64 -0
  55. package/src/types.ts +125 -0
  56. package/src/useOtaUpdate.ts +96 -0
  57. package/src/withOtaUpdate.tsx +22 -0
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkForUpdate = checkForUpdate;
4
+ exports.sync = sync;
5
+ exports.notifyAppReady = notifyAppReady;
6
+ exports.restartApp = restartApp;
7
+ exports.getCurrentPackage = getCurrentPackage;
8
+ exports.clearUpdates = clearUpdates;
9
+ exports.getConfig = getConfig;
10
+ exports.startAutoSync = startAutoSync;
11
+ exports.__resetForTests = __resetForTests;
12
+ const react_native_1 = require("react-native");
13
+ const api_1 = require("./api");
14
+ const native_1 = require("./native");
15
+ const types_1 = require("./types");
16
+ let cachedConfig = null;
17
+ let syncInFlight = null;
18
+ let lastSyncAt = 0;
19
+ let appReadyNotified = false;
20
+ async function getConfiguration(overrideDeploymentKey) {
21
+ if (!cachedConfig) {
22
+ cachedConfig = await native_1.NativeOtaUpdate.getConfiguration();
23
+ }
24
+ // Re-read the running package on every call: it changes after an install.
25
+ const current = await native_1.NativeOtaUpdate.getCurrentPackage().catch(() => null);
26
+ return {
27
+ ...cachedConfig,
28
+ deploymentKey: overrideDeploymentKey ?? cachedConfig.deploymentKey,
29
+ packageHash: current?.packageHash ?? null,
30
+ label: current?.label ?? null,
31
+ };
32
+ }
33
+ function assertConfigured(config) {
34
+ if (!config.deploymentKey) {
35
+ throw new Error('No deployment key configured. Set OtaDeploymentKey in Info.plist (iOS) / ' +
36
+ 'ota_deployment_key in strings.xml (Android), or pass `deploymentKey` to sync(). ' +
37
+ 'With Expo, set it in the config plugin options.');
38
+ }
39
+ if (!config.serverUrl) {
40
+ throw new Error('No OTA server URL configured. Set OtaServerUrl (iOS) / ota_server_url (Android), ' +
41
+ 'or the `serverUrl` config plugin option.');
42
+ }
43
+ }
44
+ function toRemotePackage(info, config) {
45
+ const remote = {
46
+ label: info.label,
47
+ packageHash: info.packageHash,
48
+ downloadUrl: info.downloadUrl ?? info.downloadURL,
49
+ size: info.size ?? 0,
50
+ isMandatory: Boolean(info.isMandatory),
51
+ description: info.description ?? null,
52
+ targetBinaryVersion: info.targetBinaryVersion ?? '',
53
+ rollout: info.rollout ?? 100,
54
+ isRollback: Boolean(info.isRollback),
55
+ deployment: info.deployment ?? '',
56
+ async download(onProgress) {
57
+ const subscription = onProgress ? (0, native_1.onDownloadProgress)(onProgress) : null;
58
+ try {
59
+ // The native side verifies the SHA-256 before unzipping, so a corrupt
60
+ // or tampered download rejects here rather than bricking the app.
61
+ const result = await native_1.NativeOtaUpdate.downloadUpdate({
62
+ label: remote.label,
63
+ packageHash: remote.packageHash,
64
+ downloadUrl: remote.downloadUrl,
65
+ size: remote.size,
66
+ isMandatory: remote.isMandatory,
67
+ description: remote.description,
68
+ });
69
+ void (0, api_1.reportStatus)(config, 'downloaded', { label: remote.label });
70
+ return toLocalPackage(result, remote);
71
+ }
72
+ finally {
73
+ subscription?.remove();
74
+ }
75
+ },
76
+ };
77
+ return remote;
78
+ }
79
+ function toLocalPackage(result, remote) {
80
+ return {
81
+ label: result.label,
82
+ packageHash: result.packageHash,
83
+ isMandatory: remote.isMandatory,
84
+ description: remote.description,
85
+ bundlePath: result.bundlePath,
86
+ size: result.size,
87
+ async install(mode = types_1.InstallMode.ON_NEXT_RESTART, minimumBackgroundDuration = 0) {
88
+ await native_1.NativeOtaUpdate.installUpdate(result.packageHash, mode, minimumBackgroundDuration);
89
+ // No status report here on purpose. `download()` already recorded
90
+ // 'downloaded', and reporting again would double-count the metric; the
91
+ // next signal is 'success' from notifyAppReady() once the new bundle
92
+ // actually boots.
93
+ },
94
+ };
95
+ }
96
+ /** Asks the server whether a newer bundle applies to this device. */
97
+ async function checkForUpdate(deploymentKey) {
98
+ const config = await getConfiguration(deploymentKey);
99
+ assertConfigured(config);
100
+ const { raw, reason, updateAppVersion } = await (0, api_1.fetchUpdate)(config);
101
+ if (!raw.isAvailable)
102
+ return { update: null, reason, updateAppVersion };
103
+ return { update: toRemotePackage(raw, config) };
104
+ }
105
+ /**
106
+ * Check → download → install, in one call. Safe to call repeatedly; concurrent
107
+ * calls share the in-flight run rather than downloading twice.
108
+ */
109
+ async function sync(options = {}) {
110
+ if (syncInFlight) {
111
+ options.onSyncStatusChange?.(types_1.SyncStatus.SYNC_IN_PROGRESS);
112
+ return syncInFlight;
113
+ }
114
+ syncInFlight = runSync(options).finally(() => {
115
+ syncInFlight = null;
116
+ lastSyncAt = Date.now();
117
+ });
118
+ return syncInFlight;
119
+ }
120
+ async function runSync(options) {
121
+ const notify = (status) => options.onSyncStatusChange?.(status);
122
+ try {
123
+ notify(types_1.SyncStatus.CHECKING_FOR_UPDATE);
124
+ const config = await getConfiguration(options.deploymentKey);
125
+ assertConfigured(config);
126
+ const { update } = await checkForUpdate(options.deploymentKey);
127
+ if (!update) {
128
+ notify(types_1.SyncStatus.UP_TO_DATE);
129
+ return types_1.SyncStatus.UP_TO_DATE;
130
+ }
131
+ if (!update.isMandatory && options.shouldInstall) {
132
+ notify(types_1.SyncStatus.AWAITING_USER_ACTION);
133
+ const proceed = await options.shouldInstall(update);
134
+ if (!proceed) {
135
+ notify(types_1.SyncStatus.UPDATE_IGNORED);
136
+ return types_1.SyncStatus.UPDATE_IGNORED;
137
+ }
138
+ }
139
+ notify(types_1.SyncStatus.DOWNLOADING_PACKAGE);
140
+ const local = await update.download(options.onDownloadProgress);
141
+ notify(types_1.SyncStatus.INSTALLING_UPDATE);
142
+ const mode = update.isMandatory
143
+ ? (options.mandatoryInstallMode ?? types_1.InstallMode.IMMEDIATE)
144
+ : (options.installMode ?? types_1.InstallMode.ON_NEXT_RESTART);
145
+ await local.install(mode, options.minimumBackgroundDuration ?? 0);
146
+ notify(types_1.SyncStatus.UPDATE_INSTALLED);
147
+ return types_1.SyncStatus.UPDATE_INSTALLED;
148
+ }
149
+ catch (err) {
150
+ const message = err instanceof Error ? err.message : String(err);
151
+ // A sync failure must never take the app down — surface it and move on.
152
+ if (!(err instanceof api_1.OtaApiError)) {
153
+ console.warn(`[ota-update] sync failed: ${message}`);
154
+ }
155
+ try {
156
+ const config = await getConfiguration(options.deploymentKey);
157
+ void (0, api_1.reportStatus)(config, 'failed', { error: message });
158
+ }
159
+ catch {
160
+ /* configuration itself was unavailable */
161
+ }
162
+ notify(types_1.SyncStatus.UNKNOWN_ERROR);
163
+ return types_1.SyncStatus.UNKNOWN_ERROR;
164
+ }
165
+ }
166
+ /**
167
+ * Confirms the running bundle works. Until this is called, the next app start
168
+ * treats the update as broken and rolls back to the previous bundle.
169
+ *
170
+ * Call it once your app has rendered and its critical startup path has run.
171
+ */
172
+ async function notifyAppReady() {
173
+ if (appReadyNotified)
174
+ return;
175
+ appReadyNotified = true;
176
+ await native_1.NativeOtaUpdate.notifyApplicationReady();
177
+ try {
178
+ const config = await getConfiguration();
179
+ const current = await native_1.NativeOtaUpdate.getCurrentPackage();
180
+ if (current?.label) {
181
+ void (0, api_1.reportStatus)(config, 'success', { label: current.label });
182
+ }
183
+ }
184
+ catch {
185
+ /* reporting is best-effort */
186
+ }
187
+ }
188
+ async function restartApp(onlyIfUpdateIsPending = false) {
189
+ await native_1.NativeOtaUpdate.restartApp(onlyIfUpdateIsPending);
190
+ }
191
+ async function getCurrentPackage() {
192
+ const raw = await native_1.NativeOtaUpdate.getCurrentPackage();
193
+ if (!raw)
194
+ return null;
195
+ return {
196
+ label: raw.label ?? null,
197
+ packageHash: raw.packageHash ?? null,
198
+ description: raw.description ?? null,
199
+ isMandatory: Boolean(raw.isMandatory),
200
+ bundlePath: raw.bundlePath ?? null,
201
+ appVersion: raw.appVersion ?? '',
202
+ isPending: Boolean(raw.isPending),
203
+ isFirstRun: Boolean(raw.isFirstRun),
204
+ };
205
+ }
206
+ /** Wipes every downloaded package and reverts to the bundle inside the binary. */
207
+ async function clearUpdates() {
208
+ await native_1.NativeOtaUpdate.clearUpdates();
209
+ }
210
+ async function getConfig() {
211
+ return getConfiguration();
212
+ }
213
+ // --- Automatic lifecycle wiring ---------------------------------------------
214
+ let lifecycleSubscription = null;
215
+ /**
216
+ * Starts the app-start / app-resume sync loop. `withOtaUpdate` calls this for
217
+ * you; call it directly if you are not using the HOC.
218
+ */
219
+ function startAutoSync(options = {}) {
220
+ const { checkOnAppStart = true, checkOnResume = true, minimumSyncInterval = 60, sync: syncOptions = {}, } = options;
221
+ if (!native_1.isNativeModuleAvailable) {
222
+ console.warn('[ota-update] native module unavailable — auto-sync disabled. ' +
223
+ 'This is expected in Expo Go and on web.');
224
+ return () => undefined;
225
+ }
226
+ // Confirm the running bundle immediately: if it was a pending update, this
227
+ // is what stops the next launch from rolling it back.
228
+ void notifyAppReady().catch(() => undefined);
229
+ if (checkOnAppStart)
230
+ void sync(syncOptions);
231
+ if (checkOnResume) {
232
+ const handler = (state) => {
233
+ if (state !== 'active')
234
+ return;
235
+ if (Date.now() - lastSyncAt < minimumSyncInterval * 1000)
236
+ return;
237
+ void sync(syncOptions);
238
+ };
239
+ const subscription = react_native_1.AppState.addEventListener('change', handler);
240
+ lifecycleSubscription = subscription;
241
+ }
242
+ return () => {
243
+ lifecycleSubscription?.remove();
244
+ lifecycleSubscription = null;
245
+ };
246
+ }
247
+ /** Test seam — resets memoised configuration and sync state. */
248
+ function __resetForTests() {
249
+ cachedConfig = null;
250
+ syncInFlight = null;
251
+ lastSyncAt = 0;
252
+ appReadyNotified = false;
253
+ }
254
+ //# sourceMappingURL=OtaUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OtaUpdate.js","sourceRoot":"","sources":["../src/OtaUpdate.ts"],"names":[],"mappings":";;AAkHA,wCAOC;AAMD,oBAUC;AA2DD,wCAcC;AAED,gCAEC;AAED,8CAaC;AAGD,oCAEC;AAED,8BAEC;AAUD,sCAoCC;AAGD,0CAKC;AApSD,+CAA6D;AAC7D,+BAA+D;AAC/D,qCAAwF;AACxF,mCAWiB;AAEjB,IAAI,YAAY,GAA4B,IAAI,CAAC;AACjD,IAAI,YAAY,GAA+B,IAAI,CAAC;AACpD,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B,KAAK,UAAU,gBAAgB,CAAC,qBAA8B;IAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,wBAAe,CAAC,gBAAgB,EAAE,CAAC;IAC1D,CAAC;IACD,0EAA0E;IAC1E,MAAM,OAAO,GAAG,MAAM,wBAAe,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO;QACL,GAAG,YAAY;QACf,aAAa,EAAE,qBAAqB,IAAI,YAAY,CAAC,aAAa;QAClE,WAAW,EAAG,OAAO,EAAE,WAAkC,IAAI,IAAI;QACjE,KAAK,EAAG,OAAO,EAAE,KAA4B,IAAI,IAAI;KACtD,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAwB;IAChD,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,2EAA2E;YACzE,kFAAkF;YAClF,iDAAiD,CACpD,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAC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CAAC;QAChC,qBAAqB,GAAG,IAAI,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,SAAgB,eAAe;IAC7B,YAAY,GAAG,IAAI,CAAC;IACpB,YAAY,GAAG,IAAI,CAAC;IACpB,UAAU,GAAG,CAAC,CAAC;IACf,gBAAgB,GAAG,KAAK,CAAC;AAC3B,CAAC"}
package/lib/api.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { CheckResult, NoUpdateReason, OtaConfiguration } from './types';
2
+ export interface UpdateCheckResponse {
3
+ updateInfo: {
4
+ isAvailable: boolean;
5
+ label?: string;
6
+ packageHash?: string;
7
+ downloadUrl?: string;
8
+ size?: number;
9
+ isMandatory?: boolean;
10
+ description?: string | null;
11
+ targetBinaryVersion?: string;
12
+ rollout?: number;
13
+ isRollback?: boolean;
14
+ deployment?: string;
15
+ reason?: NoUpdateReason;
16
+ updateAppVersion?: boolean;
17
+ };
18
+ }
19
+ export declare class OtaApiError extends Error {
20
+ readonly status?: number | undefined;
21
+ constructor(message: string, status?: number | undefined);
22
+ }
23
+ export declare function fetchUpdate(config: OtaConfiguration, timeoutMs?: number): Promise<Omit<CheckResult, 'update'> & {
24
+ raw: UpdateCheckResponse['updateInfo'];
25
+ }>;
26
+ export type InstallStatus = 'downloaded' | 'success' | 'failed' | 'rolled_back';
27
+ /**
28
+ * Best-effort telemetry. A failed report must never break the app, so callers
29
+ * are not expected to handle rejections — this never throws.
30
+ */
31
+ export declare function reportStatus(config: OtaConfiguration, status: InstallStatus, extra?: {
32
+ label?: string | null;
33
+ previousLabel?: string | null;
34
+ error?: string;
35
+ }): Promise<void>;
36
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE7E,MAAM,WAAW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lib/api.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OtaApiError = void 0;
4
+ exports.fetchUpdate = fetchUpdate;
5
+ exports.reportStatus = reportStatus;
6
+ class OtaApiError extends Error {
7
+ constructor(message, status) {
8
+ super(message);
9
+ this.status = status;
10
+ this.name = 'OtaApiError';
11
+ }
12
+ }
13
+ exports.OtaApiError = OtaApiError;
14
+ const DEFAULT_TIMEOUT_MS = 10000;
15
+ async function request(url, init, timeoutMs) {
16
+ const controller = new AbortController();
17
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
18
+ try {
19
+ const response = await fetch(url, { ...init, signal: controller.signal });
20
+ const text = await response.text();
21
+ if (!response.ok) {
22
+ let message = `${response.status} ${response.statusText}`;
23
+ try {
24
+ message = JSON.parse(text)?.error?.message ?? message;
25
+ }
26
+ catch {
27
+ /* keep the status line */
28
+ }
29
+ throw new OtaApiError(message, response.status);
30
+ }
31
+ return (text ? JSON.parse(text) : {});
32
+ }
33
+ catch (err) {
34
+ if (err instanceof OtaApiError)
35
+ throw err;
36
+ if (err.name === 'AbortError') {
37
+ throw new OtaApiError(`Update check timed out after ${timeoutMs}ms`);
38
+ }
39
+ throw new OtaApiError(err.message);
40
+ }
41
+ finally {
42
+ clearTimeout(timer);
43
+ }
44
+ }
45
+ async function fetchUpdate(config, timeoutMs = DEFAULT_TIMEOUT_MS) {
46
+ const body = {
47
+ deploymentKey: config.deploymentKey,
48
+ appVersion: config.appVersion,
49
+ clientUniqueId: config.clientUniqueId,
50
+ label: config.label ?? undefined,
51
+ packageHash: config.packageHash ?? undefined,
52
+ bundleIdentifier: config.bundleIdentifier || undefined,
53
+ };
54
+ const response = await request(`${config.serverUrl.replace(/\/+$/, '')}/updateCheck`, {
55
+ method: 'POST',
56
+ headers: { 'Content-Type': 'application/json' },
57
+ body: JSON.stringify(body),
58
+ }, timeoutMs);
59
+ return {
60
+ raw: response.updateInfo,
61
+ reason: response.updateInfo.reason,
62
+ updateAppVersion: response.updateInfo.updateAppVersion,
63
+ };
64
+ }
65
+ /**
66
+ * Best-effort telemetry. A failed report must never break the app, so callers
67
+ * are not expected to handle rejections — this never throws.
68
+ */
69
+ async function reportStatus(config, status, extra = {}) {
70
+ try {
71
+ await request(`${config.serverUrl.replace(/\/+$/, '')}/reportStatus`, {
72
+ method: 'POST',
73
+ headers: { 'Content-Type': 'application/json' },
74
+ body: JSON.stringify({
75
+ deploymentKey: config.deploymentKey,
76
+ clientUniqueId: config.clientUniqueId,
77
+ appVersion: config.appVersion,
78
+ status,
79
+ label: extra.label ?? config.label ?? undefined,
80
+ previousLabel: extra.previousLabel ?? undefined,
81
+ error: extra.error,
82
+ }),
83
+ }, DEFAULT_TIMEOUT_MS);
84
+ }
85
+ catch {
86
+ // Swallowed on purpose: metrics are not worth a crash.
87
+ }
88
+ }
89
+ //# sourceMappingURL=api.js.map
package/lib/api.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AA2DA,kCA4BC;AAQD,oCA0BC;AArGD,MAAa,WAAY,SAAQ,KAAK;IACpC,YACE,OAAe,EACN,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AARD,kCAQC;AAED,MAAM,kBAAkB,GAAG,KAAM,CAAC;AAElC,KAAK,UAAU,OAAO,CAAI,GAAW,EAAE,IAAiB,EAAE,SAAiB;IACzE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG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,CAAC;IAAC,MAAM,CAAC;QACP,uDAAuD;IACzD,CAAC;AACH,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { checkForUpdate, clearUpdates, getConfig, getCurrentPackage, notifyAppReady, restartApp, startAutoSync, sync } from './OtaUpdate';
2
+ import { isNativeModuleAvailable } from './native';
3
+ export { InstallMode, SyncStatus } from './types';
4
+ export type { CheckResult, CurrentPackage, DownloadProgress, LocalPackage, NoUpdateReason, OtaConfiguration, OtaOptions, RemotePackage, SyncOptions, } from './types';
5
+ export { checkForUpdate, clearUpdates, getConfig, getCurrentPackage, notifyAppReady, restartApp, startAutoSync, sync, };
6
+ export { withOtaUpdate } from './withOtaUpdate';
7
+ export { useOtaUpdate } from './useOtaUpdate';
8
+ export type { UseOtaUpdateState } from './useOtaUpdate';
9
+ export { OtaApiError } from './api';
10
+ export { isNativeModuleAvailable };
11
+ /** Default export, so `import OtaUpdate from '@otaupdate/react-native'` works. */
12
+ declare const OtaUpdate: {
13
+ sync: typeof sync;
14
+ checkForUpdate: typeof checkForUpdate;
15
+ notifyAppReady: typeof notifyAppReady;
16
+ restartApp: typeof restartApp;
17
+ getCurrentPackage: typeof getCurrentPackage;
18
+ getConfig: typeof getConfig;
19
+ clearUpdates: typeof clearUpdates;
20
+ startAutoSync: typeof startAutoSync;
21
+ isNativeModuleAvailable: boolean;
22
+ };
23
+ export default OtaUpdate;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,aAAa,EACb,IAAI,EACL,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClD,YAAY,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,aAAa,EACb,IAAI,GACL,CAAC;AACF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,kFAAkF;AAClF,QAAA,MAAM,SAAS;;;;;;;;;;CAUd,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNativeModuleAvailable = exports.OtaApiError = exports.useOtaUpdate = exports.withOtaUpdate = exports.sync = exports.startAutoSync = exports.restartApp = exports.notifyAppReady = exports.getCurrentPackage = exports.getConfig = exports.clearUpdates = exports.checkForUpdate = exports.SyncStatus = exports.InstallMode = void 0;
4
+ const OtaUpdate_1 = require("./OtaUpdate");
5
+ Object.defineProperty(exports, "checkForUpdate", { enumerable: true, get: function () { return OtaUpdate_1.checkForUpdate; } });
6
+ Object.defineProperty(exports, "clearUpdates", { enumerable: true, get: function () { return OtaUpdate_1.clearUpdates; } });
7
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return OtaUpdate_1.getConfig; } });
8
+ Object.defineProperty(exports, "getCurrentPackage", { enumerable: true, get: function () { return OtaUpdate_1.getCurrentPackage; } });
9
+ Object.defineProperty(exports, "notifyAppReady", { enumerable: true, get: function () { return OtaUpdate_1.notifyAppReady; } });
10
+ Object.defineProperty(exports, "restartApp", { enumerable: true, get: function () { return OtaUpdate_1.restartApp; } });
11
+ Object.defineProperty(exports, "startAutoSync", { enumerable: true, get: function () { return OtaUpdate_1.startAutoSync; } });
12
+ Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return OtaUpdate_1.sync; } });
13
+ const native_1 = require("./native");
14
+ Object.defineProperty(exports, "isNativeModuleAvailable", { enumerable: true, get: function () { return native_1.isNativeModuleAvailable; } });
15
+ var types_1 = require("./types");
16
+ Object.defineProperty(exports, "InstallMode", { enumerable: true, get: function () { return types_1.InstallMode; } });
17
+ Object.defineProperty(exports, "SyncStatus", { enumerable: true, get: function () { return types_1.SyncStatus; } });
18
+ var withOtaUpdate_1 = require("./withOtaUpdate");
19
+ Object.defineProperty(exports, "withOtaUpdate", { enumerable: true, get: function () { return withOtaUpdate_1.withOtaUpdate; } });
20
+ var useOtaUpdate_1 = require("./useOtaUpdate");
21
+ Object.defineProperty(exports, "useOtaUpdate", { enumerable: true, get: function () { return useOtaUpdate_1.useOtaUpdate; } });
22
+ var api_1 = require("./api");
23
+ Object.defineProperty(exports, "OtaApiError", { enumerable: true, get: function () { return api_1.OtaApiError; } });
24
+ /** Default export, so `import OtaUpdate from '@otaupdate/react-native'` works. */
25
+ const OtaUpdate = {
26
+ sync: OtaUpdate_1.sync,
27
+ checkForUpdate: OtaUpdate_1.checkForUpdate,
28
+ notifyAppReady: OtaUpdate_1.notifyAppReady,
29
+ restartApp: OtaUpdate_1.restartApp,
30
+ getCurrentPackage: OtaUpdate_1.getCurrentPackage,
31
+ getConfig: OtaUpdate_1.getConfig,
32
+ clearUpdates: OtaUpdate_1.clearUpdates,
33
+ startAutoSync: OtaUpdate_1.startAutoSync,
34
+ isNativeModuleAvailable: native_1.isNativeModuleAvailable,
35
+ };
36
+ exports.default = OtaUpdate;
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CASqB;AAiBnB,+FAzBA,0BAAc,OAyBA;AACd,6FAzBA,wBAAY,OAyBA;AACZ,0FAzBA,qBAAS,OAyBA;AACT,kGAzBA,6BAAiB,OAyBA;AACjB,+FAzBA,0BAAc,OAyBA;AACd,2FAzBA,sBAAU,OAyBA;AACV,8FAzBA,yBAAa,OAyBA;AACb,qFAzBA,gBAAI,OAyBA;AAvBN,qCAAmD;AA6B1C,wGA7BA,gCAAuB,OA6BA;AA3BhC,iCAAkD;AAAzC,oGAAA,WAAW,OAAA;AAAE,mGAAA,UAAU,OAAA;AAuBhC,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAErB,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AAGpB,kFAAkF;AAClF,MAAM,SAAS,GAAG;IAChB,IAAI,EAAJ,gBAAI;IACJ,cAAc,EAAd,0BAAc;IACd,cAAc,EAAd,0BAAc;IACd,UAAU,EAAV,sBAAU;IACV,iBAAiB,EAAjB,6BAAiB;IACjB,SAAS,EAAT,qBAAS;IACT,YAAY,EAAZ,wBAAY;IACZ,aAAa,EAAb,yBAAa;IACb,uBAAuB,EAAvB,gCAAuB;CACxB,CAAC;AAEF,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { DownloadProgress, OtaConfiguration } from './types';
2
+ export interface NativeOta {
3
+ getConfiguration(): Promise<OtaConfiguration>;
4
+ /** Downloads, verifies the SHA-256, and unzips. Resolves with the local path. */
5
+ downloadUpdate(update: {
6
+ label: string;
7
+ packageHash: string;
8
+ downloadUrl: string;
9
+ size: number;
10
+ isMandatory: boolean;
11
+ description: string | null;
12
+ }): Promise<{
13
+ bundlePath: string;
14
+ packageHash: string;
15
+ label: string;
16
+ size: number;
17
+ }>;
18
+ installUpdate(packageHash: string, installMode: number, minimumBackgroundDuration: number): Promise<void>;
19
+ notifyApplicationReady(): Promise<void>;
20
+ restartApp(onlyIfUpdateIsPending: boolean): Promise<void>;
21
+ getCurrentPackage(): Promise<Record<string, unknown> | null>;
22
+ /** Removes every downloaded package and reverts to the bundle in the binary. */
23
+ clearUpdates(): Promise<void>;
24
+ /** True the first time the app runs after `packageHash` was applied. */
25
+ isFirstRun(packageHash: string): Promise<boolean>;
26
+ getConstants?(): Record<string, unknown>;
27
+ }
28
+ export declare const NativeOtaUpdate: NativeOta;
29
+ export declare const isNativeModuleAvailable: boolean;
30
+ export declare const DOWNLOAD_PROGRESS_EVENT = "OtaUpdateDownloadProgress";
31
+ export declare function onDownloadProgress(listener: (progress: DownloadProgress) => void): {
32
+ remove: () => void;
33
+ };
34
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAalE,MAAM,WAAW,SAAS;IACxB,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC9C,iFAAiF;IACjF,cAAc,CAAC,MAAM,EAAE;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,OAAO,CAAC;QACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtF,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,yBAAyB,EAAE,MAAM,GAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,UAAU,CAAC,qBAAqB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7D,gFAAgF;IAChF,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,wEAAwE;IACxE,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,YAAY,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAID,eAAO,MAAM,eAAe,EAAE,SAMV,CAAC;AAErB,eAAO,MAAM,uBAAuB,SAAwB,CAAC;AAE7D,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAInE,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,GAC7C;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAKxB"}
package/lib/native.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DOWNLOAD_PROGRESS_EVENT = exports.isNativeModuleAvailable = exports.NativeOtaUpdate = void 0;
4
+ exports.onDownloadProgress = onDownloadProgress;
5
+ const react_native_1 = require("react-native");
6
+ const LINKING_ERROR = `The native module for '@otaupdate/react-native' is not available.\n\n` +
7
+ react_native_1.Platform.select({
8
+ ios: '• Run `cd ios && pod install`\n',
9
+ android: '• Rebuild the Android app (Gradle autolinking picks the module up)\n',
10
+ default: '',
11
+ }) +
12
+ '• If you use Expo, add the config plugin to app.json and run `npx expo prebuild`\n' +
13
+ '• Reload the app after a native rebuild — a Metro-only reload is not enough\n' +
14
+ '• The module does not exist in Expo Go; use a development build.';
15
+ const nativeModule = react_native_1.NativeModules.OtaUpdate;
16
+ exports.NativeOtaUpdate = nativeModule
17
+ ? nativeModule
18
+ : new Proxy({}, {
19
+ get() {
20
+ throw new Error(LINKING_ERROR);
21
+ },
22
+ });
23
+ exports.isNativeModuleAvailable = Boolean(nativeModule);
24
+ exports.DOWNLOAD_PROGRESS_EVENT = 'OtaUpdateDownloadProgress';
25
+ let emitter = null;
26
+ function onDownloadProgress(listener) {
27
+ if (!nativeModule)
28
+ return { remove: () => undefined };
29
+ if (!emitter)
30
+ emitter = new react_native_1.NativeEventEmitter(nativeModule);
31
+ const subscription = emitter.addListener(exports.DOWNLOAD_PROGRESS_EVENT, listener);
32
+ return { remove: () => subscription.remove() };
33
+ }
34
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":";;;AAwDA,gDAOC;AA/DD,+CAA2E;AAG3E,MAAM,aAAa,GACjB,uEAAuE;IACvE,uBAAQ,CAAC,MAAM,CAAC;QACd,GAAG,EAAE,iCAAiC;QACtC,OAAO,EAAE,sEAAsE;QAC/E,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,oFAAoF;IACpF,+EAA+E;IAC/E,kEAAkE,CAAC;AA4BrE,MAAM,YAAY,GAAG,4BAAa,CAAC,SAAkC,CAAC;AAEzD,QAAA,eAAe,GAAc,YAAY;IACpD,CAAC,CAAC,YAAY;IACd,CAAC,CAAE,IAAI,KAAK,CAAC,EAAe,EAAE;QAC1B,GAAG;YACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;KACF,CAAe,CAAC;AAER,QAAA,uBAAuB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEhD,QAAA,uBAAuB,GAAG,2BAA2B,CAAC;AAEnE,IAAI,OAAO,GAA8B,IAAI,CAAC;AAE9C,SAAgB,kBAAkB,CAChC,QAA8C;IAE9C,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IACtD,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,iCAAkB,CAAC,YAAqB,CAAC,CAAC;IACtE,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,+BAAuB,EAAE,QAAQ,CAAC,CAAC;IAC5E,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;AACjD,CAAC"}