Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/sdks/react-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@ import type {
} from '@openpanel/sdk';
import { OpenPanel as OpenPanelBase } from '@openpanel/sdk';
import * as Application from 'expo-application';
import Constants from 'expo-constants';
import * as ExpoConstants from 'expo-constants';
import { AppState, Platform } from 'react-native';

export * from '@openpanel/sdk';

const QUEUE_STORAGE_KEY = '@openpanel/offline_queue';

/**
* Metro/CJS interop can nest the real module under `.default` when this
* package is consumed as ESM. Prefer the same `import *` shape we already
* use for expo-application, and fall back if the helper is missing so init
* never crashes (e.g. Expo SDK 55+ with previously unmet peers).
*/
function getWebViewUserAgent(): Promise<string | null> {
const mod = ExpoConstants as typeof ExpoConstants & {
default?: typeof ExpoConstants;
};
const constants = (mod.default ?? mod) as {
getWebViewUserAgentAsync?: () => Promise<string | null>;
};
if (typeof constants.getWebViewUserAgentAsync !== 'function') {
return Promise.resolve(null);
}
return constants.getWebViewUserAgentAsync();
}

interface StorageLike {
getItem(key: string): Promise<string | null>;
setItem(key: string, value: string): Promise<void>;
Expand Down Expand Up @@ -59,7 +78,7 @@ export class OpenPanel extends OpenPanelBase {
sdkVersion: process.env.REACT_NATIVE_VERSION!,
});

this.api.addHeader('User-Agent', Constants.getWebViewUserAgentAsync());
this.api.addHeader('User-Agent', getWebViewUserAgent());
this.storage = options.storage;

if (options.networkInfo) {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdks/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"typescript": "catalog:"
},
"peerDependencies": {
"expo-application": "5 - 7",
"expo-constants": "14 - 18",
"expo-application": "5 - 7 || 50 - 55",
"expo-constants": "14 - 18 || 50 - 55",
"react-native": "*"
}
}
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.