@gfean/react-native-bundle-drop 0.1.48 → 0.1.82

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 (44) hide show
  1. package/CLIENT_README.md +254 -84
  2. package/README.md +145 -14
  3. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +9 -22
  4. package/ios/BundleDropLocator.swift +0 -6
  5. package/lib/CLI/cli.js +48 -39
  6. package/lib/CLI/scripts/init-config.d.ts +1 -0
  7. package/lib/CLI/scripts/init-config.js +42 -2
  8. package/lib/CLI/scripts/init-native-config.js +428 -45
  9. package/lib/CLI/scripts/login-cli.js +6 -2
  10. package/lib/CLI/scripts/post-init.d.ts +1 -0
  11. package/lib/CLI/scripts/post-init.js +42 -0
  12. package/lib/CLI/scripts/upload-cli.d.ts +2 -0
  13. package/lib/CLI/scripts/upload-cli.js +11 -5
  14. package/lib/api/client.d.ts +1 -1
  15. package/lib/api/client.js +2 -2
  16. package/lib/api/clientApi.d.ts +3 -6
  17. package/lib/api/clientApi.js +7 -18
  18. package/lib/api/types.d.ts +33 -18
  19. package/lib/context.js +1 -1
  20. package/lib/errors.d.ts +2 -2
  21. package/lib/fs/bundlePointer.d.ts +14 -0
  22. package/lib/fs/bundlePointer.js +77 -0
  23. package/lib/fs/installId.d.ts +1 -0
  24. package/lib/fs/installId.js +29 -0
  25. package/lib/fs/userProperties.d.ts +6 -0
  26. package/lib/fs/userProperties.js +100 -0
  27. package/lib/index.d.ts +1 -1
  28. package/lib/index.js +8 -3
  29. package/lib/install/installFromZip.js +7 -18
  30. package/lib/loadConfig.d.ts +5 -0
  31. package/lib/manager/downloadAndInstall.d.ts +10 -0
  32. package/lib/manager/downloadAndInstall.js +50 -42
  33. package/lib/manager/initUpdateManager.js +46 -10
  34. package/lib/manager/reporting.js +5 -3
  35. package/lib/manager/rollbackState.d.ts +30 -0
  36. package/lib/manager/rollbackState.js +186 -0
  37. package/lib/manager/updateCheck.js +57 -18
  38. package/lib/scripts/download-bundle.js +19 -8
  39. package/lib/useBundleDrop.js +14 -2
  40. package/package.json +3 -3
  41. package/lib/api/utils.d.ts +0 -1
  42. package/lib/api/utils.js +0 -8
  43. package/lib/fs/iosPointer.d.ts +0 -1
  44. package/lib/fs/iosPointer.js +0 -20
@@ -1,8 +1,5 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import { LatestBundleParams, PublicChannelsParams, ReportInstalledPayload, UpdateCheckParams, UpdateCheckResponse } from './types';
3
- export declare function getUpdateCheck(params: UpdateCheckParams): Promise<AxiosResponse<UpdateCheckResponse>>;
4
- export declare function getLatestBundleDownloadUrl(params: LatestBundleParams): Promise<AxiosResponse<{
5
- downloadUrl?: string;
6
- }>>;
2
+ import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload } from './types';
3
+ export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
7
4
  export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
8
- export declare function reportInstalled(hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
5
+ export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
@@ -1,39 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUpdateCheck = getUpdateCheck;
4
- exports.getLatestBundleDownloadUrl = getLatestBundleDownloadUrl;
3
+ exports.postOtaResolve = postOtaResolve;
5
4
  exports.getPublicChannels = getPublicChannels;
6
5
  exports.reportInstalled = reportInstalled;
7
6
  const client_1 = require("./client");
8
- const utils_1 = require("./utils");
9
- function getUpdateCheck(params) {
10
- const query = (0, utils_1.buildQuery)(params);
11
- return client_1.apiClient.get(`/bundle/checkForUpdate?${query}`, {
7
+ function postOtaResolve(projectSlug, payload) {
8
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/resolve`, payload, {
12
9
  headers: {
13
10
  Accept: 'application/json',
14
11
  },
15
12
  timeout: 15000,
16
13
  });
17
14
  }
18
- function getLatestBundleDownloadUrl(params) {
19
- const query = (0, utils_1.buildQuery)(params);
20
- return client_1.apiClient.get(`/bundle/latest?${query}`, {
21
- headers: {
22
- Accept: 'application/json',
23
- },
24
- });
25
- }
26
15
  function getPublicChannels(params) {
27
- const query = (0, utils_1.buildQuery)(params);
28
- return client_1.apiClient.get(`/channels/public/byProjectSlug?${query}`, {
16
+ const { projectSlug } = params;
17
+ return client_1.apiClient.get(`/projects/${encodeURIComponent(projectSlug)}/channels/public`, {
29
18
  headers: {
30
19
  Accept: 'application/json',
31
20
  },
32
21
  timeout: 15000,
33
22
  });
34
23
  }
35
- function reportInstalled(hash, payload) {
36
- return client_1.apiClient.post(`/bundle/${encodeURIComponent(hash)}/installed`, payload, {
24
+ function reportInstalled(projectSlug, hash, payload) {
25
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/installed`, payload, {
37
26
  headers: {
38
27
  Accept: 'application/json',
39
28
  },
@@ -1,4 +1,33 @@
1
+ export type OtaResolveRequest = {
2
+ channelName: string;
3
+ platform: string;
4
+ runtimeVersion?: string | null;
5
+ currentHash?: string | null;
6
+ currentUserProperties?: string[];
7
+ previousHash?: string | null;
8
+ currentBundleVersion?: number | null;
9
+ installId?: string | null;
10
+ };
11
+ export type OtaResolveResponse = {
12
+ action: 'NOOP';
13
+ reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
14
+ requestedRuntimeVersion?: string;
15
+ latestRuntimeVersionOnChannel?: string;
16
+ } | {
17
+ action: 'ROLLBACK';
18
+ reason?: string;
19
+ } | {
20
+ action: 'INSTALL';
21
+ target: {
22
+ hash: string;
23
+ downloadUrl: string;
24
+ bundleVersion?: number;
25
+ version?: string;
26
+ runtimeVersion?: string;
27
+ };
28
+ };
1
29
  export type UpdateCheckResponse = {
30
+ action: 'NOOP' | 'INSTALL' | 'ROLLBACK';
2
31
  upToDate?: boolean;
3
32
  bundleVersion?: number;
4
33
  version?: string;
@@ -8,29 +37,15 @@ export type UpdateCheckResponse = {
8
37
  reason?: string;
9
38
  incompatible?: boolean;
10
39
  runtimeVersion?: string;
11
- };
12
- export type UpdateCheckParams = {
13
- platform: string;
14
- orgSlug: string;
15
- project: string;
16
- channelName: string;
17
- currentBundleVersion?: number | null;
18
- currentHash?: string | null;
19
- runtimeVersion?: string | null;
20
- };
21
- export type LatestBundleParams = {
22
- platform: string;
23
- orgSlug: string;
24
- project: string;
25
- channelName: string;
40
+ requestedRuntimeVersion?: string;
41
+ latestRuntimeVersionOnChannel?: string;
26
42
  };
27
43
  export type PublicChannelsParams = {
28
44
  projectSlug: string;
29
- orgSlug: string;
30
45
  };
31
46
  export type ReportInstalledPayload = {
32
- orgSlug: string;
33
- projectSlug: string;
34
47
  channelName?: string;
35
48
  platform?: string;
49
+ installId?: string | null;
50
+ runtimeVersion?: string | null;
36
51
  };
package/lib/context.js CHANGED
@@ -13,4 +13,4 @@ exports.isIOS = exports.platform === 'ios';
13
13
  exports.runtimeVersion = exports.config.runtimeVersion?.[exports.platform];
14
14
  exports.BUNDLE_DROP_ROOT = exports.isIOS
15
15
  ? `${react_native_fs_1.default.LibraryDirectoryPath}/bundle-drop`
16
- : `${react_native_fs_1.default.DocumentDirectoryPath}`;
16
+ : `${react_native_fs_1.default.DocumentDirectoryPath}/bundle-drop`;
package/lib/errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type BundleDropErrorCode = 'CHECK_FAILED' | 'INCOMPATIBLE_BINARY' | 'NO_UPDATE' | 'DOWNLOAD_URL_MISSING' | 'DOWNLOAD_FAILED' | 'INSTALL_FAILED' | 'HASH_MISSING' | 'APPLY_NO_BUNDLE' | 'APPLY_ALREADY_APPLIED' | 'APPLY_FAILED' | 'UNKNOWN';
2
- export type BundleDropErrorStep = 'check' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
1
+ export type BundleDropErrorCode = 'CHECK_FAILED' | 'RESOLVE_FAILED' | 'INCOMPATIBLE_BINARY' | 'NO_UPDATE' | 'DOWNLOAD_URL_MISSING' | 'DOWNLOAD_FAILED' | 'INSTALL_FAILED' | 'HASH_MISSING' | 'APPLY_NO_BUNDLE' | 'APPLY_ALREADY_APPLIED' | 'APPLY_FAILED' | 'UNKNOWN';
2
+ export type BundleDropErrorStep = 'check' | 'resolve' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
3
3
  export declare class BundleDropError extends Error {
4
4
  code: BundleDropErrorCode;
5
5
  step: BundleDropErrorStep;
@@ -0,0 +1,14 @@
1
+ export type BundlePointer = {
2
+ hash: string;
3
+ bundlePath: string;
4
+ updatedAt: string;
5
+ };
6
+ export declare function readCurrentBundlePointer(): Promise<BundlePointer | null>;
7
+ export declare function readPreviousBundlePointer(): Promise<BundlePointer | null>;
8
+ export declare function writeCurrentBundlePointer(pointer: BundlePointer): Promise<void>;
9
+ export declare function writePreviousBundlePointer(pointer: BundlePointer): Promise<void>;
10
+ export declare function setCurrentBundlePointer(bundlePath: string, hash: string, options?: {
11
+ setPrevious?: boolean;
12
+ }): Promise<void>;
13
+ export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
14
+ export declare function clearCurrentBundlePointer(): Promise<void>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readCurrentBundlePointer = readCurrentBundlePointer;
7
+ exports.readPreviousBundlePointer = readPreviousBundlePointer;
8
+ exports.writeCurrentBundlePointer = writeCurrentBundlePointer;
9
+ exports.writePreviousBundlePointer = writePreviousBundlePointer;
10
+ exports.setCurrentBundlePointer = setCurrentBundlePointer;
11
+ exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
12
+ exports.clearCurrentBundlePointer = clearCurrentBundlePointer;
13
+ const react_native_fs_1 = __importDefault(require("react-native-fs"));
14
+ const context_1 = require("../context");
15
+ const fsUtils_1 = require("./fsUtils");
16
+ const CURRENT_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/current.json`;
17
+ const PREVIOUS_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/previous.json`;
18
+ async function readPointer(path) {
19
+ try {
20
+ if (!(await react_native_fs_1.default.exists(path)))
21
+ return null;
22
+ const raw = await react_native_fs_1.default.readFile(path, 'utf8');
23
+ const parsed = JSON.parse(raw);
24
+ if (!parsed?.hash || !parsed?.bundlePath)
25
+ return null;
26
+ return parsed;
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ async function readCurrentBundlePointer() {
33
+ return readPointer(CURRENT_POINTER_PATH);
34
+ }
35
+ async function readPreviousBundlePointer() {
36
+ return readPointer(PREVIOUS_POINTER_PATH);
37
+ }
38
+ async function writeCurrentBundlePointer(pointer) {
39
+ const root = context_1.BUNDLE_DROP_ROOT;
40
+ await (0, fsUtils_1.ensureDir)(root);
41
+ await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointer);
42
+ }
43
+ async function writePreviousBundlePointer(pointer) {
44
+ const root = context_1.BUNDLE_DROP_ROOT;
45
+ await (0, fsUtils_1.ensureDir)(root);
46
+ await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointer);
47
+ }
48
+ async function setCurrentBundlePointer(bundlePath, hash, options) {
49
+ const root = context_1.BUNDLE_DROP_ROOT;
50
+ await (0, fsUtils_1.ensureDir)(root);
51
+ const current = await readCurrentBundlePointer();
52
+ if (options?.setPrevious !== false && current?.hash && current?.bundlePath) {
53
+ await writePreviousBundlePointer({ ...current, updatedAt: new Date().toISOString() });
54
+ }
55
+ await writeCurrentBundlePointer({
56
+ hash,
57
+ bundlePath,
58
+ updatedAt: new Date().toISOString(),
59
+ });
60
+ }
61
+ async function rollbackToPreviousPointer() {
62
+ const previous = await readPreviousBundlePointer();
63
+ if (!previous)
64
+ return null;
65
+ await writeCurrentBundlePointer({ ...previous, updatedAt: new Date().toISOString() });
66
+ return previous;
67
+ }
68
+ async function clearCurrentBundlePointer() {
69
+ try {
70
+ if (await react_native_fs_1.default.exists(CURRENT_POINTER_PATH)) {
71
+ await react_native_fs_1.default.unlink(CURRENT_POINTER_PATH);
72
+ }
73
+ }
74
+ catch {
75
+ // ignore
76
+ }
77
+ }
@@ -0,0 +1 @@
1
+ export declare function getOrCreateInstallId(): Promise<string>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOrCreateInstallId = getOrCreateInstallId;
7
+ const react_native_fs_1 = __importDefault(require("react-native-fs"));
8
+ const context_1 = require("../context");
9
+ const fsUtils_1 = require("./fsUtils");
10
+ function getInstallIdPath() {
11
+ return `${context_1.BUNDLE_DROP_ROOT}/install-id.txt`;
12
+ }
13
+ async function getOrCreateInstallId() {
14
+ const path = getInstallIdPath();
15
+ try {
16
+ const existing = await react_native_fs_1.default.readFile(path, 'utf8');
17
+ if (existing?.trim())
18
+ return existing.trim();
19
+ }
20
+ catch {
21
+ // ignore and create a new one
22
+ }
23
+ const id = `${Date.now().toString(36)}-` +
24
+ `${Math.random().toString(36).slice(2, 10)}-` +
25
+ `${Math.random().toString(36).slice(2, 10)}`;
26
+ await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
27
+ await react_native_fs_1.default.writeFile(path, id, 'utf8');
28
+ return id;
29
+ }
@@ -0,0 +1,6 @@
1
+ export declare function getCurrentUserProperties(): Promise<string[]>;
2
+ export declare function getUserProperties(): Promise<string[]>;
3
+ export declare function setUserProperty(value: string): Promise<string[]>;
4
+ export declare function removeUserProperty(value: string): Promise<string[]>;
5
+ export declare function resetUserProperties(): Promise<void>;
6
+ export declare const setUserPropery: typeof setUserProperty;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setUserPropery = void 0;
7
+ exports.getCurrentUserProperties = getCurrentUserProperties;
8
+ exports.getUserProperties = getUserProperties;
9
+ exports.setUserProperty = setUserProperty;
10
+ exports.removeUserProperty = removeUserProperty;
11
+ exports.resetUserProperties = resetUserProperties;
12
+ const react_native_fs_1 = __importDefault(require("react-native-fs"));
13
+ const context_1 = require("../context");
14
+ const fsUtils_1 = require("./fsUtils");
15
+ const USER_PROPERTIES_PATH = `${context_1.BUNDLE_DROP_ROOT}/user-properties.json`;
16
+ function normalizeUserProperty(input) {
17
+ return input.trim();
18
+ }
19
+ function unique(values) {
20
+ const seen = new Set();
21
+ const result = [];
22
+ for (const value of values) {
23
+ if (seen.has(value))
24
+ continue;
25
+ seen.add(value);
26
+ result.push(value);
27
+ }
28
+ return result;
29
+ }
30
+ async function writeUserProperties(properties) {
31
+ await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
32
+ const payload = {
33
+ properties: unique(properties),
34
+ };
35
+ await (0, fsUtils_1.atomicWriteJson)(USER_PROPERTIES_PATH, payload);
36
+ }
37
+ async function getCurrentUserProperties() {
38
+ try {
39
+ if (!(await react_native_fs_1.default.exists(USER_PROPERTIES_PATH)))
40
+ return [];
41
+ const raw = await react_native_fs_1.default.readFile(USER_PROPERTIES_PATH, 'utf8');
42
+ const parsed = JSON.parse(raw);
43
+ if (Array.isArray(parsed)) {
44
+ return unique(parsed.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
45
+ }
46
+ const values = parsed?.properties;
47
+ if (!Array.isArray(values))
48
+ return [];
49
+ return unique(values.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
50
+ }
51
+ catch (e) {
52
+ console.warn('⚠️ Failed to read user-properties.json', e);
53
+ return [];
54
+ }
55
+ }
56
+ async function getUserProperties() {
57
+ return getCurrentUserProperties();
58
+ }
59
+ async function setUserProperty(value) {
60
+ const normalized = normalizeUserProperty(value);
61
+ if (!normalized) {
62
+ return getCurrentUserProperties();
63
+ }
64
+ const existing = await getCurrentUserProperties();
65
+ if (existing.includes(normalized)) {
66
+ return existing;
67
+ }
68
+ const next = [...existing, normalized];
69
+ await writeUserProperties(next);
70
+ return next;
71
+ }
72
+ async function removeUserProperty(value) {
73
+ const normalized = normalizeUserProperty(value);
74
+ if (!normalized) {
75
+ return getCurrentUserProperties();
76
+ }
77
+ const existing = await getCurrentUserProperties();
78
+ const next = existing.filter(item => item !== normalized);
79
+ if (next.length === existing.length) {
80
+ return existing;
81
+ }
82
+ if (next.length === 0) {
83
+ await resetUserProperties();
84
+ return [];
85
+ }
86
+ await writeUserProperties(next);
87
+ return next;
88
+ }
89
+ async function resetUserProperties() {
90
+ try {
91
+ if (await react_native_fs_1.default.exists(USER_PROPERTIES_PATH)) {
92
+ await react_native_fs_1.default.unlink(USER_PROPERTIES_PATH);
93
+ }
94
+ }
95
+ catch (e) {
96
+ console.warn('⚠️ Failed to reset user-properties.json', e);
97
+ }
98
+ }
99
+ // Backward-compatible alias for the requested API name.
100
+ exports.setUserPropery = setUserProperty;
package/lib/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo } from './
3
3
  export { downloadUpdate } from './manager/downloadAndInstall';
4
4
  export { getUpdateState, applyUpdate } from './manager/updateState';
5
5
  export { initUpdateManager } from './manager/initUpdateManager';
6
- export { getDownloadedBundlePathNative as getDownloadedBundlePath } from './native/bundleDropNative';
7
6
  export { BundleDropError, isBundleDropError } from './errors';
7
+ export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
8
8
  export type { BundleInfo } from './bundleInfo';
9
9
  export type { UpdatePolicy } from './types';
10
10
  export { useBundleDrop } from './useBundleDrop';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBundleDrop = exports.isBundleDropError = exports.BundleDropError = exports.getDownloadedBundlePath = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
3
+ exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
4
4
  require("./bootstrap");
5
5
  var updateCheck_1 = require("./manager/updateCheck");
6
6
  Object.defineProperty(exports, "getAvailableChannels", { enumerable: true, get: function () { return updateCheck_1.getAvailableChannels; } });
@@ -13,10 +13,15 @@ Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: functi
13
13
  Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return updateState_1.applyUpdate; } });
14
14
  var initUpdateManager_1 = require("./manager/initUpdateManager");
15
15
  Object.defineProperty(exports, "initUpdateManager", { enumerable: true, get: function () { return initUpdateManager_1.initUpdateManager; } });
16
- var bundleDropNative_1 = require("./native/bundleDropNative");
17
- Object.defineProperty(exports, "getDownloadedBundlePath", { enumerable: true, get: function () { return bundleDropNative_1.getDownloadedBundlePathNative; } });
18
16
  var errors_1 = require("./errors");
19
17
  Object.defineProperty(exports, "BundleDropError", { enumerable: true, get: function () { return errors_1.BundleDropError; } });
20
18
  Object.defineProperty(exports, "isBundleDropError", { enumerable: true, get: function () { return errors_1.isBundleDropError; } });
19
+ var userProperties_1 = require("./fs/userProperties");
20
+ Object.defineProperty(exports, "getCurrentUserProperties", { enumerable: true, get: function () { return userProperties_1.getCurrentUserProperties; } });
21
+ Object.defineProperty(exports, "getUserProperties", { enumerable: true, get: function () { return userProperties_1.getUserProperties; } });
22
+ Object.defineProperty(exports, "setUserProperty", { enumerable: true, get: function () { return userProperties_1.setUserProperty; } });
23
+ Object.defineProperty(exports, "setUserPropery", { enumerable: true, get: function () { return userProperties_1.setUserPropery; } });
24
+ Object.defineProperty(exports, "removeUserProperty", { enumerable: true, get: function () { return userProperties_1.removeUserProperty; } });
25
+ Object.defineProperty(exports, "resetUserProperties", { enumerable: true, get: function () { return userProperties_1.resetUserProperties; } });
21
26
  var useBundleDrop_1 = require("./useBundleDrop");
22
27
  Object.defineProperty(exports, "useBundleDrop", { enumerable: true, get: function () { return useBundleDrop_1.useBundleDrop; } });
@@ -46,41 +46,30 @@ async function installFromZip(params) {
46
46
  }
47
47
  // Build a runtime manifest from extracted assets to handle filename-only resolutions.
48
48
  const runtimeManifest = {};
49
- // Platform-specific bundle location
50
- const bundleDir = context_1.isIOS ? `${context_1.BUNDLE_DROP_ROOT}/bundles/${resolvedHash}` : context_1.BUNDLE_DROP_ROOT;
51
- if (context_1.isIOS) {
52
- await (0, fsUtils_1.ensureDir)(bundleDir);
53
- }
49
+ // Platform-specific bundle location (hash-scoped)
50
+ const bundleDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${resolvedHash}`;
51
+ await (0, fsUtils_1.ensureDir)(bundleDir);
54
52
  const bundlePath = `${bundleDir}/main.jsbundle`;
55
53
  for (const [filename, fileData] of Object.entries(files)) {
56
54
  const dataBuffer = buffer_1.Buffer.from(fileData);
57
55
  const base64 = dataBuffer.toString('base64');
58
56
  if (filename === 'main.jsbundle') {
59
57
  await (0, fsUtils_1.writeFileAtomicBase64)(bundlePath, base64);
60
- // Legacy copy for iOS fallback (documents/main.jsbundle + assets)
61
- if (context_1.isIOS) {
62
- const legacyPath = `${react_native_fs_1.default.DocumentDirectoryPath}/main.jsbundle`;
63
- await (0, fsUtils_1.writeFileAtomicBase64)(legacyPath, base64);
64
- }
65
58
  continue;
66
59
  }
67
60
  // Write other files under bundleDir (e.g., metadata, assets)
68
61
  const filePath = `${bundleDir}/${filename}`;
69
62
  await (0, fsUtils_1.ensureParentDir)(filePath);
70
63
  await react_native_fs_1.default.writeFile(filePath, base64, 'base64');
71
- // Legacy copy for iOS assets/metadata into Documents for fallback bundle
72
- if (context_1.isIOS) {
73
- const legacyPath = `${react_native_fs_1.default.DocumentDirectoryPath}/${filename}`;
74
- await (0, fsUtils_1.ensureParentDir)(legacyPath);
75
- await react_native_fs_1.default.writeFile(legacyPath, base64, 'base64');
76
- }
77
64
  // Collect runtime manifest entries for assets; support paths with or without "assets/" prefix.
78
65
  if (filename.includes('drawable') || filename.startsWith('assets/') || filename.startsWith('res/')) {
79
66
  const noExt = filename.replace(/\.[^.]+$/, '');
80
67
  const base = noExt.split('/').pop();
81
68
  const withAssetsPrefix = filename.startsWith('assets/') ? filename : `assets/${filename}`;
82
- // Android should not include hash prefixes; iOS uses local file assets
83
- const mappedPath = context_1.isIOS ? `${resolvedHash}/${filename}` : filename;
69
+ // Map to on-disk location relative to DocumentDirectoryPath
70
+ const mappedPath = context_1.isIOS
71
+ ? `${resolvedHash}/${filename}`
72
+ : `bundle-drop/bundles/${resolvedHash}/${filename}`;
84
73
  runtimeManifest[noExt.replace(/^assets\//, '')] = mappedPath;
85
74
  runtimeManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = mappedPath;
86
75
  if (base && !runtimeManifest[base]) {
@@ -13,5 +13,10 @@ export type BundleDropProjectConfig = {
13
13
  ios: string;
14
14
  android: string;
15
15
  };
16
+ rollback?: {
17
+ maxCrashCount?: number;
18
+ crashWindowSec?: number;
19
+ commitTimeoutSec?: number;
20
+ };
16
21
  };
17
22
  export declare function loadConfig(): BundleDropProjectConfig;
@@ -6,9 +6,19 @@ export type DownloadUpdateResult = {
6
6
  status: 'upToDate';
7
7
  } | {
8
8
  status: 'incompatible';
9
+ } | {
10
+ status: 'rollback';
11
+ reason?: string;
9
12
  };
10
13
  type DownloadOptions = {
11
14
  channelName?: string;
15
+ resolvedTarget?: {
16
+ hash: string;
17
+ downloadUrl: string;
18
+ bundleVersion?: number;
19
+ version?: string;
20
+ runtimeVersion?: string;
21
+ };
12
22
  };
13
23
  export declare const downloadUpdate: (options?: DownloadOptions, onStatusUpdate?: (status: string) => void) => Promise<DownloadUpdateResult>;
14
24
  export {};
@@ -4,67 +4,74 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.downloadUpdate = void 0;
7
- const axios_1 = __importDefault(require("axios"));
7
+ const axios_cjs_1 = __importDefault(require("axios/dist/browser/axios.cjs"));
8
8
  const context_1 = require("../context");
9
9
  const bundleInfo_1 = require("../bundleInfo");
10
- const iosPointer_1 = require("../fs/iosPointer");
10
+ const bundlePointer_1 = require("../fs/bundlePointer");
11
11
  const installFromZip_1 = require("../install/installFromZip");
12
12
  const updateCheck_1 = require("./updateCheck");
13
- const clientApi_1 = require("../api/clientApi");
14
13
  const errors_1 = require("../errors");
14
+ const rollbackState_1 = require("./rollbackState");
15
15
  async function downloadAndStageUpdate(options, onStatusUpdate) {
16
- const { project, org } = context_1.config;
16
+ const { project } = context_1.config;
17
17
  const channelName = options?.channelName || 'General';
18
18
  const platform = context_1.platform;
19
19
  const statusCb = onStatusUpdate;
20
- const latestBundleParams = {
21
- platform,
22
- orgSlug: org.slug,
23
- project: project.slug,
24
- channelName,
25
- };
26
- // Optional pre-flight check to avoid unnecessary downloads.
27
- const checkResult = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
28
- const serverHash = checkResult?.hash;
29
- const serverBundleVersion = checkResult?.bundleVersion;
30
- const serverVersion = checkResult?.version;
31
- const serverRuntimeVersion = checkResult?.runtimeVersion;
32
- if (checkResult?.upToDate) {
33
- statusCb?.('✅ You have the latest version');
34
- return { status: 'upToDate' };
20
+ const resolvedTarget = options?.resolvedTarget;
21
+ // Resolve target via /ota/resolve unless the caller already provided it.
22
+ const checkResult = resolvedTarget
23
+ ? {
24
+ action: 'INSTALL',
25
+ hash: resolvedTarget.hash,
26
+ downloadUrl: resolvedTarget.downloadUrl,
27
+ bundleVersion: resolvedTarget.bundleVersion,
28
+ version: resolvedTarget.version,
29
+ runtimeVersion: resolvedTarget.runtimeVersion,
30
+ }
31
+ : await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
32
+ if (!checkResult) {
33
+ throw new errors_1.BundleDropError({
34
+ message: 'Failed to resolve update decision',
35
+ code: 'RESOLVE_FAILED',
36
+ step: 'resolve',
37
+ context: { channelName, platform, projectSlug: project.slug },
38
+ });
35
39
  }
36
- if (checkResult?.incompatible) {
40
+ if (checkResult.incompatible) {
37
41
  statusCb?.('⛔️ No compatible update for this binary');
38
42
  return { status: 'incompatible' };
39
43
  }
40
- let bundleZipUrl = checkResult?.downloadUrl || null;
44
+ if (checkResult.action === 'NOOP') {
45
+ statusCb?.('✅ You have the latest version');
46
+ return { status: 'upToDate' };
47
+ }
48
+ if (checkResult.action === 'ROLLBACK') {
49
+ statusCb?.('↩️ Rollback requested');
50
+ return { status: 'rollback', reason: checkResult.reason };
51
+ }
52
+ const serverHash = checkResult.hash;
53
+ const serverBundleVersion = checkResult.bundleVersion;
54
+ const serverVersion = checkResult.version;
55
+ const serverRuntimeVersion = checkResult.runtimeVersion;
56
+ const bundleZipUrl = checkResult.downloadUrl || null;
41
57
  try {
42
- // Resolve download URL if not provided by checkForUpdate.
43
- if (!bundleZipUrl) {
44
- const latestResponse = await (0, clientApi_1.getLatestBundleDownloadUrl)(latestBundleParams);
45
- if (!latestResponse.data?.downloadUrl) {
46
- throw new errors_1.BundleDropError({
47
- message: 'Missing downloadUrl from latest bundle response',
48
- code: 'DOWNLOAD_URL_MISSING',
49
- step: 'resolveDownloadUrl',
50
- context: {
51
- channelName,
52
- platform,
53
- orgSlug: org.slug,
54
- projectSlug: project.slug,
55
- },
56
- });
57
- }
58
- bundleZipUrl = latestResponse.data.downloadUrl;
59
- }
60
58
  if (!bundleZipUrl) {
61
- throw new Error('Missing bundle download URL');
59
+ throw new errors_1.BundleDropError({
60
+ message: 'Missing downloadUrl from ota resolve response',
61
+ code: 'DOWNLOAD_URL_MISSING',
62
+ step: 'resolve',
63
+ context: {
64
+ channelName,
65
+ platform,
66
+ projectSlug: project.slug,
67
+ },
68
+ });
62
69
  }
63
70
  // Fetch bundle zip from server.
64
71
  statusCb?.('⬇️ Downloading full bundle ZIP!...');
65
72
  let zipResponse;
66
73
  try {
67
- zipResponse = await axios_1.default.get(bundleZipUrl, {
74
+ zipResponse = await axios_cjs_1.default.get(bundleZipUrl, {
68
75
  responseType: 'arraybuffer',
69
76
  });
70
77
  }
@@ -120,7 +127,8 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
120
127
  runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
121
128
  };
122
129
  (0, bundleInfo_1.writeBundleInfo)(installedInfo);
123
- await (0, iosPointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
130
+ await (0, bundlePointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
131
+ await (0, rollbackState_1.markCandidateActivated)(installedHash);
124
132
  return { status: 'staged', bundlePath, hash: installedHash };
125
133
  }
126
134
  catch (err) {