|
| 1 | +import * as Sentry from "@sentry/react-native"; |
| 2 | +import * as Application from "expo-application"; |
| 3 | +import Constants from "expo-constants"; |
| 4 | +import * as Updates from "expo-updates"; |
| 5 | + |
| 6 | +// Stamp the running bundle's identity into the manifest request via the |
| 7 | +// Expo-Extra-Params header (Updates.setExtraParamAsync persists natively and |
| 8 | +// the native client serializes the dictionary on every update check). This is |
| 9 | +// the protocol's intended escape hatch for human-readable client identifiers — |
| 10 | +// the standard expo-current-update-id / expo-runtime-version headers are |
| 11 | +// opaque UUIDs / fingerprint hashes by design. |
| 12 | +// |
| 13 | +// Steady-state accuracy: a bundle sets its own values on first launch, so |
| 14 | +// every later check reports them. The only stale check is the very first |
| 15 | +// launch after an OTA applies, because expo-updates fires the check before |
| 16 | +// JS runs setExtraParamAsync (checkAutomatically=ON_LOAD); from the next |
| 17 | +// launch onward it's accurate. |
| 18 | + |
| 19 | +const extra = Constants.expoConfig?.extra as |
| 20 | + | { gitHash?: string; appVariant?: string } |
| 21 | + | undefined; |
| 22 | +const gitHash = extra?.gitHash ?? "unknown"; |
| 23 | +const appVariant = extra?.appVariant ?? "unknown"; |
| 24 | + |
| 25 | +// Only the store-distributed staging and production apps talk to the OTA |
| 26 | +// manifest server. The dev tool loads bundles via the dev-launcher deep link |
| 27 | +// and local dev has no manifest server, so setting params there is a no-op |
| 28 | +// at best. |
| 29 | +const enabled = appVariant === "production" || appVariant === "staging"; |
| 30 | + |
| 31 | +if (enabled) { |
| 32 | + (async () => { |
| 33 | + await Updates.setExtraParamAsync("git-hash", gitHash); |
| 34 | + await Updates.setExtraParamAsync( |
| 35 | + "native-version", |
| 36 | + Application.nativeApplicationVersion ?? null, |
| 37 | + ); |
| 38 | + await Updates.setExtraParamAsync( |
| 39 | + "native-build", |
| 40 | + Application.nativeBuildVersion ?? null, |
| 41 | + ); |
| 42 | + })().catch((err) => Sentry.captureException(err)); |
| 43 | +} |
0 commit comments