@aramiworks/app-updates 0.0.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aramiworks/app-updates",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Native app update checks and OTA flow for Expo apps",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
package/build/cache.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { StoreUpdate } from './types';
2
- /** How long a cached verified store update keeps gating the app (7 days). */
3
- export declare const VERIFIED_TTL_MS: number;
4
- export interface KeyValueStore {
5
- getItem(k: string): Promise<string | null>;
6
- setItem(k: string, v: string): Promise<void>;
7
- deleteItem(k: string): Promise<void>;
8
- }
9
- export declare const secureStore: KeyValueStore;
10
- export declare function readVerified(store: KeyValueStore, installed: string, now: number): Promise<StoreUpdate | null>;
11
- export declare function writeVerified(store: KeyValueStore, update: StoreUpdate, now: number): Promise<void>;
12
- export declare function clearVerified(store: KeyValueStore): Promise<void>;
package/build/cache.js DELETED
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.secureStore = exports.VERIFIED_TTL_MS = void 0;
37
- exports.readVerified = readVerified;
38
- exports.writeVerified = writeVerified;
39
- exports.clearVerified = clearVerified;
40
- const SecureStore = __importStar(require("expo-secure-store"));
41
- const version_1 = require("./version");
42
- /** How long a cached verified store update keeps gating the app (7 days). */
43
- exports.VERIFIED_TTL_MS = 7 * 24 * 60 * 60 * 1000;
44
- const KEY = 'aramiworks.app-updates.verified';
45
- exports.secureStore = {
46
- getItem: (k) => SecureStore.getItemAsync(k),
47
- setItem: (k, v) => SecureStore.setItemAsync(k, v),
48
- deleteItem: (k) => SecureStore.deleteItemAsync(k),
49
- };
50
- function isStored(value) {
51
- if (typeof value !== 'object' || value === null)
52
- return false;
53
- const { update, verifiedAt } = value;
54
- if (typeof verifiedAt !== 'number' || !Number.isFinite(verifiedAt))
55
- return false;
56
- if (typeof update !== 'object' || update === null)
57
- return false;
58
- const u = update;
59
- return (typeof u.installed === 'string' &&
60
- typeof u.available === 'string' &&
61
- (u.source === 'app-store' || u.source === 'play' || u.source === 'firebase') &&
62
- (typeof u.url === 'string' || u.url === null));
63
- }
64
- async function readVerified(store, installed, now) {
65
- try {
66
- const raw = await store.getItem(KEY);
67
- if (raw === null)
68
- return null;
69
- const parsed = JSON.parse(raw);
70
- if (!isStored(parsed))
71
- return null;
72
- const age = now - parsed.verifiedAt;
73
- if (age < 0 || age >= exports.VERIFIED_TTL_MS)
74
- return null;
75
- const installedV = (0, version_1.parseMajorMinor)(installed);
76
- const availableV = (0, version_1.parseMajorMinor)(parsed.update.available);
77
- if (!installedV || !availableV)
78
- return null;
79
- if (!(0, version_1.isNewerMajorMinor)(installedV, availableV)) {
80
- await clearVerified(store);
81
- return null;
82
- }
83
- return { ...parsed.update, installed };
84
- }
85
- catch {
86
- return null;
87
- }
88
- }
89
- async function writeVerified(store, update, now) {
90
- try {
91
- await store.setItem(KEY, JSON.stringify({ update, verifiedAt: now }));
92
- }
93
- catch {
94
- // fail open: a missed cache write must never break the caller
95
- }
96
- }
97
- async function clearVerified(store) {
98
- try {
99
- await store.deleteItem(KEY);
100
- }
101
- catch {
102
- // fail open
103
- }
104
- }
package/build/env.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { StoreCheckEnv } from './storeCheck';
2
- /** Reads the runtime environment the store check needs. Called once per hook mount. */
3
- export declare function getEnv(): StoreCheckEnv;
package/build/env.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getEnv = getEnv;
37
- const Application = __importStar(require("expo-application"));
38
- const expo_localization_1 = require("expo-localization");
39
- const Updates = __importStar(require("expo-updates"));
40
- const react_native_1 = require("react-native");
41
- const native_1 = require("./native");
42
- /** Reads the runtime environment the store check needs. Called once per hook mount. */
43
- function getEnv() {
44
- const os = react_native_1.Platform.OS;
45
- return {
46
- platform: os === 'ios' || os === 'android' ? os : 'web',
47
- channel: Updates.channel ?? null,
48
- installed: Application.nativeApplicationVersion ?? null,
49
- bundleId: Application.applicationId ?? null,
50
- country: (0, expo_localization_1.getLocales)()[0]?.regionCode ?? null,
51
- distribution: (0, native_1.getDistribution)(),
52
- };
53
- }
package/build/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { useAppUpdate } from './useAppUpdate';
2
- export type { AppUpdateState, UseAppUpdateOptions } from './useAppUpdate';
3
- export type { Distribution, StoreUpdate } from './types';
4
- export type { TesterState } from './tester';
5
- export { CHECK_INTERVAL_MS } from './throttle';
6
- export { COLD_START_OTA_LIMIT_MS } from './ota';
7
- export { STORE_CHECK_TIMEOUT_MS } from './storeCheck';
8
- export { VERIFIED_TTL_MS } from './cache';
package/build/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERIFIED_TTL_MS = exports.STORE_CHECK_TIMEOUT_MS = exports.COLD_START_OTA_LIMIT_MS = exports.CHECK_INTERVAL_MS = exports.useAppUpdate = void 0;
4
- var useAppUpdate_1 = require("./useAppUpdate");
5
- Object.defineProperty(exports, "useAppUpdate", { enumerable: true, get: function () { return useAppUpdate_1.useAppUpdate; } });
6
- var throttle_1 = require("./throttle");
7
- Object.defineProperty(exports, "CHECK_INTERVAL_MS", { enumerable: true, get: function () { return throttle_1.CHECK_INTERVAL_MS; } });
8
- var ota_1 = require("./ota");
9
- Object.defineProperty(exports, "COLD_START_OTA_LIMIT_MS", { enumerable: true, get: function () { return ota_1.COLD_START_OTA_LIMIT_MS; } });
10
- var storeCheck_1 = require("./storeCheck");
11
- Object.defineProperty(exports, "STORE_CHECK_TIMEOUT_MS", { enumerable: true, get: function () { return storeCheck_1.STORE_CHECK_TIMEOUT_MS; } });
12
- var cache_1 = require("./cache");
13
- Object.defineProperty(exports, "VERIFIED_TTL_MS", { enumerable: true, get: function () { return cache_1.VERIFIED_TTL_MS; } });
package/build/native.d.ts DELETED
@@ -1,56 +0,0 @@
1
- /** Which Android channel this build was distributed through ("none" off Android). */
2
- export type NativeDistribution = 'play' | 'firebase' | 'none';
3
- export interface PlayUpdateInfo {
4
- updateAvailable: boolean;
5
- availableVersionCode: number;
6
- immediateAllowed: boolean;
7
- }
8
- export interface FirebaseRelease {
9
- displayVersion: string;
10
- }
11
- /**
12
- * Whether Firebase App Distribution can work in this build: the Android native
13
- * module is linked, or on iOS the app installed `@react-native-firebase/app-distribution`.
14
- * False on web and in Expo Go.
15
- */
16
- export declare function isFirebaseAvailable(): boolean;
17
- /**
18
- * The distribution channel from the `app_updates_distribution` string resource
19
- * the config plugin writes per Gradle flavor. Defaults to "play" on Android
20
- * (resource absent or unknown) and is "none" on iOS and web.
21
- */
22
- export declare function getDistribution(): NativeDistribution;
23
- /** Google Play in-app update availability. Nothing available off Android. */
24
- export declare function getPlayUpdateInfo(): Promise<PlayUpdateInfo>;
25
- /**
26
- * Starts Play's immediate (full-screen) update flow from the current activity.
27
- * Resolves false when it couldn't start (no activity, no update, or immediate
28
- * updates not allowed).
29
- */
30
- export declare function startPlayImmediateUpdate(): Promise<boolean>;
31
- /**
32
- * Firebase calls are meaningful only on the `firebase` distribution. In the
33
- * `play` flavor the Android API-only artifact reports `isTesterSignedIn` false
34
- * and the other calls reject ("API not implemented"), so callers must use
35
- * them only when `getDistribution()` is `firebase` (or on iOS). On iOS they use
36
- * the app's optional `@react-native-firebase/app-distribution` install and
37
- * return "nothing" values when it is absent. Errors propagate.
38
- */
39
- /** Whether a Firebase App Distribution tester is signed in on this device. */
40
- export declare function isTesterSignedIn(): Promise<boolean>;
41
- /** Opens the Firebase App Distribution tester sign-in flow. */
42
- export declare function signInTester(): Promise<void>;
43
- /**
44
- * The newest Firebase App Distribution release, or null when this build is the newest.
45
- * Only meaningful on the `firebase` distribution (see above).
46
- *
47
- * Call this only after `isTesterSignedIn()` resolves true: when no tester is
48
- * signed in, the native `checkForNewRelease` opens the sign-in flow on its own.
49
- * This wrapper does not guard against that; callers must.
50
- */
51
- export declare function checkFirebaseRelease(): Promise<FirebaseRelease | null>;
52
- /**
53
- * Installs the newest Firebase App Distribution release: downloads it on Android,
54
- * opens its download URL on iOS. Only meaningful on the `firebase` distribution.
55
- */
56
- export declare function installFirebaseRelease(): Promise<void>;
package/build/native.js DELETED
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFirebaseAvailable = isFirebaseAvailable;
4
- exports.getDistribution = getDistribution;
5
- exports.getPlayUpdateInfo = getPlayUpdateInfo;
6
- exports.startPlayImmediateUpdate = startPlayImmediateUpdate;
7
- exports.isTesterSignedIn = isTesterSignedIn;
8
- exports.signInTester = signInTester;
9
- exports.checkFirebaseRelease = checkFirebaseRelease;
10
- exports.installFirebaseRelease = installFirebaseRelease;
11
- const expo_1 = require("expo");
12
- const react_native_1 = require("react-native");
13
- const NO_PLAY_UPDATE = {
14
- updateAvailable: false,
15
- availableVersionCode: 0,
16
- immediateAllowed: false,
17
- };
18
- /**
19
- * The Android native module, or null off Android or when it isn't linked
20
- * (Expo Go, tests). Looked up per call so nothing native loads on iOS or web.
21
- */
22
- function nativeModule() {
23
- if (react_native_1.Platform.OS !== 'android')
24
- return null;
25
- return (0, expo_1.requireOptionalNativeModule)('AppUpdates');
26
- }
27
- /**
28
- * The app's optional `@react-native-firebase/app-distribution` install (iOS only),
29
- * or null when it is absent or not usable. Resolved lazily at call time; supports
30
- * the modular API (v22+) and the namespaced default export.
31
- */
32
- function loadRnfbAppDistribution() {
33
- if (react_native_1.Platform.OS !== 'ios')
34
- return null;
35
- try {
36
- const rnfb = require('@react-native-firebase/app-distribution');
37
- if (typeof rnfb?.getAppDistribution === 'function') {
38
- const instance = rnfb.getAppDistribution();
39
- return {
40
- isTesterSignedIn: () => rnfb.isTesterSignedIn(instance),
41
- signInTester: () => rnfb.signInTester(instance),
42
- checkForUpdate: () => rnfb.checkForUpdate(instance),
43
- };
44
- }
45
- if (typeof rnfb?.default === 'function')
46
- return rnfb.default();
47
- return null;
48
- }
49
- catch {
50
- return null;
51
- }
52
- }
53
- /**
54
- * Whether Firebase App Distribution can work in this build: the Android native
55
- * module is linked, or on iOS the app installed `@react-native-firebase/app-distribution`.
56
- * False on web and in Expo Go.
57
- */
58
- function isFirebaseAvailable() {
59
- if (react_native_1.Platform.OS === 'android')
60
- return nativeModule() !== null;
61
- if (react_native_1.Platform.OS === 'ios')
62
- return loadRnfbAppDistribution() !== null;
63
- return false;
64
- }
65
- /**
66
- * The distribution channel from the `app_updates_distribution` string resource
67
- * the config plugin writes per Gradle flavor. Defaults to "play" on Android
68
- * (resource absent or unknown) and is "none" on iOS and web.
69
- */
70
- function getDistribution() {
71
- if (react_native_1.Platform.OS !== 'android')
72
- return 'none';
73
- const value = nativeModule()?.getDistribution();
74
- return value === 'firebase' ? 'firebase' : 'play';
75
- }
76
- /** Google Play in-app update availability. Nothing available off Android. */
77
- async function getPlayUpdateInfo() {
78
- const mod = nativeModule();
79
- if (!mod)
80
- return { ...NO_PLAY_UPDATE };
81
- return mod.getPlayUpdateInfo();
82
- }
83
- /**
84
- * Starts Play's immediate (full-screen) update flow from the current activity.
85
- * Resolves false when it couldn't start (no activity, no update, or immediate
86
- * updates not allowed).
87
- */
88
- async function startPlayImmediateUpdate() {
89
- const mod = nativeModule();
90
- if (!mod)
91
- return false;
92
- return mod.startPlayImmediateUpdate();
93
- }
94
- /**
95
- * Firebase calls are meaningful only on the `firebase` distribution. In the
96
- * `play` flavor the Android API-only artifact reports `isTesterSignedIn` false
97
- * and the other calls reject ("API not implemented"), so callers must use
98
- * them only when `getDistribution()` is `firebase` (or on iOS). On iOS they use
99
- * the app's optional `@react-native-firebase/app-distribution` install and
100
- * return "nothing" values when it is absent. Errors propagate.
101
- */
102
- /** Whether a Firebase App Distribution tester is signed in on this device. */
103
- async function isTesterSignedIn() {
104
- const rnfb = loadRnfbAppDistribution();
105
- if (rnfb)
106
- return rnfb.isTesterSignedIn();
107
- const mod = nativeModule();
108
- if (!mod)
109
- return false;
110
- return mod.isTesterSignedIn();
111
- }
112
- /** Opens the Firebase App Distribution tester sign-in flow. */
113
- async function signInTester() {
114
- const rnfb = loadRnfbAppDistribution();
115
- if (rnfb) {
116
- await rnfb.signInTester();
117
- return;
118
- }
119
- const mod = nativeModule();
120
- if (!mod)
121
- return;
122
- await mod.signInTester();
123
- }
124
- /**
125
- * The newest Firebase App Distribution release, or null when this build is the newest.
126
- * Only meaningful on the `firebase` distribution (see above).
127
- *
128
- * Call this only after `isTesterSignedIn()` resolves true: when no tester is
129
- * signed in, the native `checkForNewRelease` opens the sign-in flow on its own.
130
- * This wrapper does not guard against that; callers must.
131
- */
132
- async function checkFirebaseRelease() {
133
- const rnfb = loadRnfbAppDistribution();
134
- if (rnfb) {
135
- const release = await rnfb.checkForUpdate();
136
- return release?.displayVersion ? { displayVersion: release.displayVersion } : null;
137
- }
138
- const mod = nativeModule();
139
- if (!mod)
140
- return null;
141
- return mod.checkFirebaseRelease();
142
- }
143
- /**
144
- * Installs the newest Firebase App Distribution release: downloads it on Android,
145
- * opens its download URL on iOS. Only meaningful on the `firebase` distribution.
146
- */
147
- async function installFirebaseRelease() {
148
- const rnfb = loadRnfbAppDistribution();
149
- if (rnfb) {
150
- const release = await rnfb.checkForUpdate();
151
- if (release?.downloadURL)
152
- await react_native_1.Linking.openURL(release.downloadURL);
153
- return;
154
- }
155
- const mod = nativeModule();
156
- if (!mod)
157
- return;
158
- await mod.installFirebaseRelease();
159
- }
@@ -1,20 +0,0 @@
1
- import type { StoreUpdate } from './types';
2
- export interface OpenStoreDeps {
3
- openURL: (url: string) => Promise<unknown>;
4
- startPlayImmediateUpdate: () => Promise<boolean>;
5
- installFirebaseRelease: () => Promise<void>;
6
- }
7
- /**
8
- * Opens the update for the given source.
9
- *
10
- * - `app-store`: opens `update.url`; does nothing when it is null.
11
- * - `play`: starts Google's immediate update flow. A `true` result only means the
12
- * flow STARTED; its outcome isn't observed here (the hook re-checks when the app
13
- * returns to the foreground). When it resolves `false` or throws, falls back to
14
- * opening `update.url` (the Play Store listing), if any.
15
- * - `firebase`: installs the newest Firebase App Distribution release.
16
- *
17
- * Errors from `openURL` and `installFirebaseRelease` propagate to the caller; the
18
- * button handler shows nothing new and the gate stays up.
19
- */
20
- export declare function openStore(update: StoreUpdate, deps?: Partial<OpenStoreDeps>): Promise<void>;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.openStore = openStore;
4
- const react_native_1 = require("react-native");
5
- const native_1 = require("./native");
6
- /**
7
- * Opens the update for the given source.
8
- *
9
- * - `app-store`: opens `update.url`; does nothing when it is null.
10
- * - `play`: starts Google's immediate update flow. A `true` result only means the
11
- * flow STARTED; its outcome isn't observed here (the hook re-checks when the app
12
- * returns to the foreground). When it resolves `false` or throws, falls back to
13
- * opening `update.url` (the Play Store listing), if any.
14
- * - `firebase`: installs the newest Firebase App Distribution release.
15
- *
16
- * Errors from `openURL` and `installFirebaseRelease` propagate to the caller; the
17
- * button handler shows nothing new and the gate stays up.
18
- */
19
- async function openStore(update, deps = {}) {
20
- const d = {
21
- openURL: (url) => react_native_1.Linking.openURL(url),
22
- startPlayImmediateUpdate: native_1.startPlayImmediateUpdate,
23
- installFirebaseRelease: native_1.installFirebaseRelease,
24
- ...deps,
25
- };
26
- const openUrl = async () => {
27
- if (update.url)
28
- await d.openURL(update.url);
29
- };
30
- switch (update.source) {
31
- case 'app-store':
32
- await openUrl();
33
- return;
34
- case 'play': {
35
- let started = false;
36
- try {
37
- started = await d.startPlayImmediateUpdate();
38
- }
39
- catch {
40
- started = false;
41
- }
42
- if (!started)
43
- await openUrl();
44
- return;
45
- }
46
- case 'firebase':
47
- await d.installFirebaseRelease();
48
- }
49
- }
package/build/ota.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /** Total budget for the cold-start check + download. */
2
- export declare const COLD_START_OTA_LIMIT_MS = 10000;
3
- /** The subset of `expo-updates` this module uses (explicit so tests can fake it). */
4
- export interface UpdatesApi {
5
- isEnabled: boolean;
6
- checkForUpdateAsync(): Promise<{
7
- isAvailable: boolean;
8
- }>;
9
- fetchUpdateAsync(): Promise<{
10
- isNew: boolean;
11
- manifest?: {
12
- id?: string;
13
- } | object;
14
- }>;
15
- reloadAsync(): Promise<void>;
16
- }
17
- export interface OtaDeps {
18
- updates?: UpdatesApi;
19
- }
20
- export type ColdStartOtaResult = 'reloading' | 'none' | 'timed-out' | 'failed';
21
- /**
22
- * Mandatory cold-start OTA: check + download within COLD_START_OTA_LIMIT_MS, then reload.
23
- * After a timeout it never reloads, even if the download later finishes.
24
- */
25
- export declare function runColdStartOta(deps?: OtaDeps): Promise<ColdStartOtaResult>;
26
- /**
27
- * Optional warm OTA: check + download in the background; never reloads, never throws.
28
- * `updateId` is the downloaded manifest's id (when present) so callers can act once per update.
29
- */
30
- export declare function checkWarmOta(deps?: OtaDeps): Promise<{
31
- ready: boolean;
32
- updateId: string | null;
33
- }>;
package/build/ota.js DELETED
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.COLD_START_OTA_LIMIT_MS = void 0;
37
- exports.runColdStartOta = runColdStartOta;
38
- exports.checkWarmOta = checkWarmOta;
39
- const ExpoUpdates = __importStar(require("expo-updates"));
40
- /** Total budget for the cold-start check + download. */
41
- exports.COLD_START_OTA_LIMIT_MS = 10_000;
42
- const defaultUpdates = () => ExpoUpdates;
43
- async function checkAndFetch(updates) {
44
- const check = await updates.checkForUpdateAsync();
45
- if (!check.isAvailable)
46
- return { downloaded: false, updateId: null };
47
- const fetched = await updates.fetchUpdateAsync();
48
- if (!fetched.isNew)
49
- return { downloaded: false, updateId: null };
50
- const id = fetched.manifest?.id;
51
- return { downloaded: true, updateId: typeof id === 'string' ? id : null };
52
- }
53
- /**
54
- * Mandatory cold-start OTA: check + download within COLD_START_OTA_LIMIT_MS, then reload.
55
- * After a timeout it never reloads, even if the download later finishes.
56
- */
57
- async function runColdStartOta(deps = {}) {
58
- const updates = deps.updates ?? defaultUpdates();
59
- if (!updates.isEnabled)
60
- return 'none';
61
- let timer;
62
- const work = checkAndFetch(updates).then((r) => r, () => 'failed');
63
- const timeout = new Promise((resolve) => {
64
- timer = setTimeout(() => resolve('timed-out'), exports.COLD_START_OTA_LIMIT_MS);
65
- });
66
- try {
67
- const outcome = await Promise.race([work, timeout]);
68
- if (outcome === 'timed-out')
69
- return 'timed-out';
70
- if (outcome === 'failed')
71
- return 'failed';
72
- if (!outcome.downloaded)
73
- return 'none';
74
- try {
75
- await updates.reloadAsync();
76
- }
77
- catch {
78
- return 'failed';
79
- }
80
- return 'reloading';
81
- }
82
- finally {
83
- if (timer !== undefined)
84
- clearTimeout(timer);
85
- }
86
- }
87
- /**
88
- * Optional warm OTA: check + download in the background; never reloads, never throws.
89
- * `updateId` is the downloaded manifest's id (when present) so callers can act once per update.
90
- */
91
- async function checkWarmOta(deps = {}) {
92
- const updates = deps.updates ?? defaultUpdates();
93
- if (!updates.isEnabled)
94
- return { ready: false, updateId: null };
95
- try {
96
- const r = await checkAndFetch(updates);
97
- return { ready: r.downloaded, updateId: r.updateId };
98
- }
99
- catch {
100
- return { ready: false, updateId: null };
101
- }
102
- }
@@ -1,15 +0,0 @@
1
- export interface AppStoreOptions {
2
- bundleId: string;
3
- country: string | null;
4
- fetchFn?: typeof fetch;
5
- signal?: AbortSignal;
6
- }
7
- /**
8
- * Asks Apple's public iTunes lookup for the live App Store version.
9
- * Returns null when the app is not listed (or the result is malformed);
10
- * throws on HTTP, network or parse errors (the caller fails open).
11
- */
12
- export declare function checkAppStore(opts: AppStoreOptions): Promise<{
13
- version: string;
14
- url: string;
15
- } | null>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAppStore = checkAppStore;
4
- /**
5
- * Asks Apple's public iTunes lookup for the live App Store version.
6
- * Returns null when the app is not listed (or the result is malformed);
7
- * throws on HTTP, network or parse errors (the caller fails open).
8
- */
9
- async function checkAppStore(opts) {
10
- const fetchFn = opts.fetchFn ?? fetch;
11
- const country = (opts.country?.trim() || 'us').toLowerCase();
12
- const url = `https://itunes.apple.com/lookup?bundleId=${encodeURIComponent(opts.bundleId)}` +
13
- `&country=${encodeURIComponent(country)}`;
14
- const res = await fetchFn(url, { signal: opts.signal });
15
- if (!res.ok) {
16
- throw new Error(`App Store lookup failed with HTTP ${res.status}`);
17
- }
18
- const body = (await res.json());
19
- if (!body.resultCount)
20
- return null;
21
- const first = body.results?.[0];
22
- if (!first || typeof first.version !== 'string' || typeof first.trackViewUrl !== 'string') {
23
- return null;
24
- }
25
- return { version: first.version, url: first.trackViewUrl };
26
- }