@gfean/react-native-bundle-drop 0.1.38 → 0.1.47

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 (42) hide show
  1. package/CLIENT_README.md +21 -12
  2. package/README.md +19 -12
  3. package/lib/CLI/cli.js +6 -6
  4. package/lib/api/client.d.ts +1 -0
  5. package/lib/api/client.js +24 -0
  6. package/lib/api/clientApi.d.ts +8 -0
  7. package/lib/api/clientApi.js +42 -0
  8. package/lib/api/types.d.ts +36 -0
  9. package/lib/api/types.js +2 -0
  10. package/lib/api/utils.d.ts +1 -0
  11. package/lib/api/utils.js +8 -0
  12. package/lib/bootstrap.d.ts +1 -0
  13. package/lib/bootstrap.js +10 -0
  14. package/lib/context.d.ts +5 -0
  15. package/lib/context.js +16 -0
  16. package/lib/errors.d.ts +16 -0
  17. package/lib/errors.js +18 -0
  18. package/lib/fs/fsUtils.d.ts +4 -0
  19. package/lib/fs/fsUtils.js +38 -0
  20. package/lib/fs/iosPointer.d.ts +1 -0
  21. package/lib/fs/iosPointer.js +20 -0
  22. package/lib/index.d.ts +7 -49
  23. package/lib/index.js +18 -414
  24. package/lib/install/installFromZip.d.ts +12 -0
  25. package/lib/install/installFromZip.js +117 -0
  26. package/lib/manager/downloadAndInstall.d.ts +14 -0
  27. package/lib/manager/downloadAndInstall.js +144 -0
  28. package/lib/manager/initUpdateManager.d.ts +7 -0
  29. package/lib/manager/initUpdateManager.js +60 -0
  30. package/lib/manager/reporting.d.ts +5 -0
  31. package/lib/manager/reporting.js +40 -0
  32. package/lib/manager/updateCheck.d.ts +5 -0
  33. package/lib/manager/updateCheck.js +58 -0
  34. package/lib/manager/updateState.d.ts +14 -0
  35. package/lib/manager/updateState.js +62 -0
  36. package/lib/native/bundleDropNative.d.ts +2 -0
  37. package/lib/native/bundleDropNative.js +22 -0
  38. package/lib/scripts/download-bundle.js +29 -12
  39. package/lib/scripts/upload-bundle.js +26 -19
  40. package/lib/useBundleDrop.d.ts +21 -20
  41. package/lib/useBundleDrop.js +67 -73
  42. package/package.json +1 -1
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBundleDrop = useBundleDrop;
4
4
  const react_1 = require("react");
5
- const index_1 = require("./index");
5
+ const updateCheck_1 = require("./manager/updateCheck");
6
+ const downloadAndInstall_1 = require("./manager/downloadAndInstall");
7
+ const updateState_1 = require("./manager/updateState");
6
8
  function useBundleDrop(options) {
7
9
  const channelName = options?.channelName || 'General';
8
10
  const [status, setStatus] = (0, react_1.useState)('Click the button to check for updates');
@@ -10,8 +12,9 @@ function useBundleDrop(options) {
10
12
  const [pendingApply, setPendingApply] = (0, react_1.useState)(false);
11
13
  const [hasBundle, setHasBundle] = (0, react_1.useState)(false);
12
14
  const [isBusy, setIsBusy] = (0, react_1.useState)(false);
15
+ const [availableChannels, setAvailableChannels] = (0, react_1.useState)([]);
13
16
  const refresh = (0, react_1.useCallback)(async () => {
14
- const state = await (0, index_1.getUpdateState)();
17
+ const state = await (0, updateState_1.getUpdateState)();
15
18
  setInstalledInfo(state.info || null);
16
19
  setPendingApply(state.pendingApply);
17
20
  setHasBundle(state.hasBundle);
@@ -19,102 +22,94 @@ function useBundleDrop(options) {
19
22
  const withBusy = (0, react_1.useCallback)(async (fn) => {
20
23
  setIsBusy(true);
21
24
  try {
22
- await fn();
25
+ const result = await fn();
23
26
  await refresh();
27
+ return result;
24
28
  }
25
29
  finally {
26
30
  setIsBusy(false);
27
31
  }
28
32
  }, [refresh]);
29
33
  const checkLatest = (0, react_1.useCallback)(async () => {
30
- await withBusy(async () => {
31
- const res = await (0, index_1.checkForUpdate)(channelName, msg => setStatus(msg));
34
+ return withBusy(async () => {
35
+ const res = await (0, updateCheck_1.checkForUpdate)(channelName, msg => setStatus(msg));
32
36
  if (!res) {
33
- setStatus('⚠️ Unable to check for updates. Try again.');
34
- return;
37
+ const nextStatus = '⚠️ Unable to check for updates. Try again.';
38
+ setStatus(nextStatus);
39
+ return { response: null, status: nextStatus };
35
40
  }
36
41
  if (res.upToDate) {
37
- setStatus('✅ You have the latest version');
38
- return;
42
+ const nextStatus = '✅ You have the latest version';
43
+ setStatus(nextStatus);
44
+ return { response: res, status: nextStatus };
39
45
  }
40
46
  if (res.incompatible) {
41
- setStatus('⛔️ No compatible update for this binary');
42
- return;
47
+ const nextStatus = '⛔️ No compatible update for this binary';
48
+ setStatus(nextStatus);
49
+ return { response: res, status: nextStatus };
43
50
  }
44
51
  const nextLabel = res.bundleVersion
45
52
  ? `⬇️ Update available${res.bundleVersion ? ` (v${res.bundleVersion})` : ''}`
46
53
  : '⬇️ Update available';
47
54
  setStatus(nextLabel);
55
+ return { response: res, status: nextLabel };
48
56
  });
49
57
  }, [channelName, withBusy]);
50
- const downloadImmediate = (0, react_1.useCallback)(async () => {
51
- await withBusy(async () => {
52
- await (0, index_1.restartAppAndInstallUpdate)(msg => setStatus(msg), {
53
- channelName,
54
- applyBehavior: 'immediate',
55
- });
56
- });
57
- }, [channelName, withBusy]);
58
- const downloadForNextLaunch = (0, react_1.useCallback)(async () => {
59
- await withBusy(async () => {
60
- const check = await (0, index_1.checkForUpdate)(channelName, msg => setStatus(msg));
61
- if (check?.upToDate) {
62
- setStatus('✅ You have the latest version');
63
- return;
58
+ const downloadAndStage = (0, react_1.useCallback)(async () => {
59
+ return withBusy(async () => {
60
+ const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, msg => setStatus(msg));
61
+ if (result.status === 'upToDate') {
62
+ const nextStatus = '✅ You have the latest version';
63
+ setStatus(nextStatus);
64
+ return { result, status: nextStatus };
64
65
  }
65
- if (check?.incompatible) {
66
- setStatus('⛔️ No compatible update for this binary');
67
- return;
66
+ if (result.status === 'incompatible') {
67
+ const nextStatus = '⛔️ No compatible update for this binary';
68
+ setStatus(nextStatus);
69
+ return { result, status: nextStatus };
68
70
  }
69
- await (0, index_1.downloadUpdate)({ channelName, applyBehavior: 'on-next-launch' }, msg => setStatus(msg));
70
- setStatus('✅ Update downloaded. It will apply on next launch.');
71
+ const nextStatus = '✅ Update downloaded. Will apply on next launch or when you call applyUpdate.';
72
+ setStatus(nextStatus);
73
+ return { result, status: nextStatus };
71
74
  });
72
75
  }, [channelName, withBusy]);
73
- const downloadManual = (0, react_1.useCallback)(async () => {
74
- await withBusy(async () => {
75
- const check = await (0, index_1.checkForUpdate)(channelName, msg => setStatus(msg));
76
- if (check?.upToDate) {
77
- setStatus('✅ You have the latest version');
78
- return;
76
+ const applyUpdate = (0, react_1.useCallback)(async () => {
77
+ return withBusy(async () => {
78
+ const applied = await (0, updateState_1.applyUpdate)(msg => setStatus(msg));
79
+ let nextStatus;
80
+ if (applied.status === 'applied') {
81
+ nextStatus = '✅ Update applied, reloading...';
82
+ setStatus(nextStatus);
79
83
  }
80
- if (check?.incompatible) {
81
- setStatus('⛔️ No compatible update for this binary');
82
- return;
84
+ if (applied.status === 'noBundle') {
85
+ nextStatus = '⚠️ No downloaded bundle to apply';
86
+ setStatus(nextStatus);
83
87
  }
84
- await (0, index_1.downloadUpdate)({ channelName, applyBehavior: 'manual' }, msg => setStatus(msg));
85
- setStatus('✅ Update downloaded. Tap Apply to reload when ready.');
86
- });
87
- }, [channelName, withBusy]);
88
- const applyPending = (0, react_1.useCallback)(async () => {
89
- await withBusy(async () => {
90
- const applied = await (0, index_1.applyReadyUpdate)(msg => setStatus(msg));
91
- if (applied) {
92
- setStatus('✅ Update applied, reloading...');
88
+ if (applied.status === 'alreadyApplied') {
89
+ nextStatus = 'ℹ️ Bundle already applied';
90
+ setStatus(nextStatus);
93
91
  }
92
+ return { result: applied, status: nextStatus };
94
93
  });
95
94
  }, [withBusy]);
96
- // Optional auto-init to mimic Expo/CodePush style.
97
- (0, react_1.useEffect)(() => {
98
- if (options?.autoInit && options.policy && options.policy !== 'manual') {
99
- const run = async () => {
100
- try {
101
- await (0, index_1.initUpdateManager)({
102
- channelName,
103
- policy: options.policy,
104
- onStatusUpdate: msg => setStatus(msg),
105
- checkOnly: options.checkOnly,
106
- });
107
- }
108
- finally {
109
- await refresh();
110
- }
111
- };
112
- run();
95
+ const fetchAvailableChannels = (0, react_1.useCallback)(async () => {
96
+ setIsBusy(true);
97
+ try {
98
+ const channels = await (0, updateCheck_1.getAvailableChannels)();
99
+ setAvailableChannels(channels);
100
+ return channels;
101
+ }
102
+ catch (e) {
103
+ setStatus('⚠️ Unable to fetch channels.');
104
+ return [];
113
105
  }
114
- else {
115
- refresh();
106
+ finally {
107
+ setIsBusy(false);
116
108
  }
117
- }, [channelName, options?.autoInit, options?.policy, options?.checkOnly, refresh]);
109
+ }, [setAvailableChannels, setStatus]);
110
+ (0, react_1.useEffect)(() => {
111
+ refresh();
112
+ }, [refresh]);
118
113
  return {
119
114
  status,
120
115
  isBusy,
@@ -122,10 +117,9 @@ function useBundleDrop(options) {
122
117
  pendingApply,
123
118
  hasBundle,
124
119
  checkLatest,
125
- downloadImmediate,
126
- downloadForNextLaunch,
127
- downloadManual,
128
- applyPending,
129
- refresh,
120
+ downloadUpdate: downloadAndStage,
121
+ applyUpdate,
122
+ fetchAvailableChannels,
123
+ availableChannels,
130
124
  };
131
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.1.38",
3
+ "version": "0.1.47",
4
4
  "description": "react native ota by gFean",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",