Skip to content

Commit 59d15fb

Browse files
Merge pull request #186 from fingerprintjs/feat/INTER-1228-expo-support
[INTER-1228] Expo support - pre-release PR
2 parents 7dae670 + 3a4b8d5 commit 59d15fb

31 files changed

+4801
-1847
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
react-native-matrix: ${{ steps.set-matrix.outputs.matrix }}
1515
steps:
1616
- id: set-matrix
17-
run: echo "matrix=['local', '0.73', '0.74', '0.75', '0.76', '0.78', '0.79']" >> $GITHUB_OUTPUT
17+
run: echo "matrix=['local', '0.73', '0.74', '0.75', '0.76', '0.78', '0.79', '0.80', '0.81']" >> $GITHUB_OUTPUT
1818

1919
build-android:
2020
strategy:
@@ -343,4 +343,43 @@ jobs:
343343
name: Delete build artifact
344344
if: success()
345345
with:
346-
name: ios-app-release-${{ matrix.react-native }}
346+
name: ios-app-release-${{ matrix.react-native }}
347+
348+
e2e-tests-web:
349+
name: Web E2E tests
350+
runs-on: ubuntu-latest
351+
steps:
352+
- uses: actions/checkout@v4
353+
354+
- uses: actions/setup-node@v3
355+
with:
356+
cache: yarn
357+
node-version: 22.x
358+
359+
- run: yarn install
360+
361+
- run: yarn build && rm -rf node_modules
362+
if: github.event_name != 'release'
363+
364+
- name: Install dependencies in e2e-app
365+
run: yarn install && yarn playwright install chromium
366+
working-directory: e2e-app
367+
368+
- name: Install ${{github.event.release.tag_name}} version of the package
369+
run: yarn add @fingerprintjs/fingerprintjs-pro-react-native@${{github.event.release.tag_name}}
370+
if: github.event_name == 'release'
371+
working-directory: e2e-app
372+
373+
- name: Build web
374+
run: yarn build:web
375+
working-directory: e2e-app
376+
377+
- run: yarn test:web
378+
working-directory: e2e-app
379+
env:
380+
MINIMUM_US_DEFAULT_PUBLIC_KEY: ${{ secrets.MINIMUM_US_DEFAULT_PUBLIC_KEY }}
381+
MINIMUM_US_DEFAULT_PRIVATE_KEY: ${{ secrets.MINIMUM_US_DEFAULT_PRIVATE_KEY }}
382+
DEFAULT_EU_DEFAULT_PUBLIC_KEY: ${{ secrets.DEFAULT_EU_DEFAULT_PUBLIC_KEY }}
383+
DEFAULT_EU_DEFAULT_PRIVATE_KEY: ${{ secrets.DEFAULT_EU_DEFAULT_PRIVATE_KEY }}
384+
MINIMUM_US_SEALED_ENCRYPTION_KEY: ${{ secrets.MINIMUM_US_SEALED_ENCRYPTION_KEY }}
385+
MINIMUM_US_SEALED_PUBLIC_KEY: ${{ secrets.MINIMUM_US_SEALED_PUBLIC_KEY }}

README.md

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ application to call the native Fingerprint Pro libraries (Android and iOS) and i
4141
- [Requirements and limitations](#requirements-and-limitations)
4242
- [Dependencies](#dependencies)
4343
- [How to install](#how-to-install)
44-
- [1. Install the package using your favorite package manager:](#1-install-the-package-using-your-favorite-package-manager)
45-
- [2. Configure iOS dependencies (if developing on iOS)](#2-configure-ios-dependencies-if-developing-on-ios)
46-
- [3. Configure Android dependencies (if developing on Android)](#3-configure-android-dependencies-if-developing-on-android)
47-
- [Gradle 7 or newer](#gradle-7-or-newer)
48-
- [Gradle 6.0 or older](#gradle-60-or-older)
44+
- [Expo setup](#expo-setup)
45+
- [1. Add config plugin](#1-add-config-plugin)
46+
- [2. Rebuild the native code](#2-rebuild-the-native-code)
47+
- [3. Rebuild the app](#3-rebuild-the-app)
48+
- [Bare react-native](#bare-react-native-setup)
49+
- [1. Configure iOS dependencies (if developing on iOS)](#1-configure-ios-dependencies-if-developing-on-ios)
50+
- [2. Configure Android dependencies (if developing on Android)](#2-configure-android-dependencies-if-developing-on-android)
51+
- [Gradle 7 or newer](#gradle-7-or-newer)
52+
- [Gradle 6.0 or older](#gradle-60-or-older)
4953
- [Usage](#usage)
5054
- [Hooks approach](#hooks-approach)
5155
- [API Client approach](#api-client-approach)
@@ -59,6 +63,7 @@ application to call the native Fingerprint Pro libraries (Android and iOS) and i
5963
## Requirements and limitations
6064

6165
- React Native versions 0.73 through 0.79 are supported
66+
- Expo 51.0.0 or higher is supported
6267
- Android 5.0 (API level 21+) or higher
6368
- iOS 13+/tvOS 15+, Swift 5.7 or higher (stable releases)
6469

@@ -72,7 +77,7 @@ application to call the native Fingerprint Pro libraries (Android and iOS) and i
7277

7378
## How to install
7479

75-
### 1. Install the package using your favorite package manager:
80+
Install the package using your favorite package manager:
7681

7782
- [NPM](https://npmjs.org):
7883

@@ -90,14 +95,71 @@ application to call the native Fingerprint Pro libraries (Android and iOS) and i
9095
```shell
9196
pnpm add @fingerprintjs/fingerprintjs-pro-react-native
9297
```
98+
99+
## Expo setup
93100

94-
### 2. Configure iOS dependencies (if developing on iOS)
101+
> ℹ️ Our SDK cannot be used in [Expo Go](https://expo.dev/go) because it requires custom native code.
102+
103+
<details>
104+
<summary>Web support</summary>
105+
To use the SDK on the web, install the peer dependency with your preferred package manager:
106+
107+
- [NPM](https://npmjs.org):
108+
109+
```shell
110+
npm install @fingerprintjs/fingerprintjs-pro-spa --save
111+
```
112+
113+
- [Yarn](https://yarnpkg.com):
114+
115+
```shell
116+
yarn add @fingerprintjs/fingerprintjs-pro-spa
117+
```
118+
119+
- [PNPM](https://pnpm.js.org):
120+
```shell
121+
pnpm add @fingerprintjs/fingerprintjs-pro-spa
122+
```
123+
124+
Then, use the SDK as you would with the native version.
125+
</details>
126+
127+
### 1. Add config plugin
128+
```json
129+
{
130+
"expo": {
131+
"plugins": [
132+
"@fingerprintjs/fingerprintjs-pro-react-native"
133+
]
134+
}
135+
}
136+
```
137+
138+
### 2. Rebuild the native code
139+
```bash
140+
npx expo prebuild --clean
141+
```
142+
143+
### 3. Rebuild the app
144+
For Android:
145+
```bash
146+
npx expo run:android
147+
```
148+
149+
For iOS:
150+
```bash
151+
npx expo run:ios
152+
```
153+
154+
## Bare react-native setup
155+
156+
### 1. Configure iOS dependencies (if developing on iOS)
95157

96158
```shell
97159
cd ios && pod install
98160
```
99161

100-
### 3. Configure Android dependencies (if developing on Android)
162+
### 2. Configure Android dependencies (if developing on Android)
101163

102164
Add the repositories to your Gradle configuration file. The location for these additions depends on your project's structure and the Gradle version you're using:
103165

__tests__/FingerprintJsProProvider.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { renderHook } from '@testing-library/react'
33
import { createWrapper, getDefaultLoadOptions } from './helpers'
44
import { FingerprintJsProContext } from '../src/FingerprintJsProContext'
55
import { NativeModules } from 'react-native'
6-
import * as packageInfo from '../package.json'
76
import { FingerprintJsProAgent } from '../src'
87

98
const configure = jest.fn()
@@ -24,7 +23,7 @@ const mockedVisitorId = 'some visitor id'
2423
const mockedRequestId = 'some request id'
2524
const mockedConfidenceScore = 0.99
2625

27-
const pluginVersion = packageInfo.version
26+
const pluginVersion = '__VERSION__'
2827

2928
describe(`FingerprintJsProProvider`, () => {
3029
it('should pass options to agent with regular result', () => {

__tests__/errors.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ApiKeyRequiredError, JsonParsingError, UnknownError, unwrapError } from '../src/errors'
1+
import { ApiKeyRequiredError, JsonParsingError, UnknownError } from '../src/errors'
2+
import { unwrapError } from '../src/unwrapError'
23

34
describe('unwrapError function', () => {
45
it('should return ApiKeyRequiredError when TokenRequired error passed', () => {

app.plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./plugin/dist/withFingerprint.js')

e2e-app/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sub from US region that will be used in tests. Ideally, it should have the least amounf of featires enabled.
1+
# Sub from US region that will be used in tests. Ideally, it should have the least amount of features enabled.
22
MINIMUM_US_DEFAULT_PUBLIC_KEY=<US_SUB_PUBLIC_KEY>
33
MINIMUM_US_DEFAULT_PRIVATE_KEY=<US_SUB_PRIVATE_KEY>
44

e2e-app/.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ yarn-error.*
4141
*.tsbuildinfo
4242

4343
app-example
44-
*.env
44+
*.env
45+
46+
# Playwright
47+
/test-results/
48+
/playwright-report/
49+
/blob-report/
50+
/playwright/.cache/

e2e-app/App.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import { Pressable, SafeAreaView, Text, View } from 'react-native'
2-
import { LaunchArguments } from 'react-native-launch-arguments'
3-
import { FingerprintJsProProvider, Region, useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react-native'
2+
import { FingerprintJsProProvider, useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react-native'
43
import { testIds } from '@/e2e/ids'
54
import { useEffect } from 'react'
65
import { testTags } from '@/e2e/tags'
7-
8-
export type LaunchArgs = {
9-
apiKey: string
10-
region: Region
11-
useTags?: boolean
12-
linkedId?: string
13-
}
14-
15-
const args = LaunchArguments.value<LaunchArgs>()
6+
import config from '@/src/config'
167

178
function InnerApp() {
189
const { isLoading, error, data, getData } = useVisitorData()
@@ -33,22 +24,22 @@ function InnerApp() {
3324
flex: 1,
3425
}}
3526
>
36-
{isLoading && <Text testID={testIds.loading}>Loading...</Text>}
37-
{error && (
27+
{isLoading ? <Text testID={testIds.loading}>Loading...</Text> : null}
28+
{error ? (
3829
<View>
3930
<Text testID={testIds.errorName}>{error.name}</Text>
4031
<Text testID={testIds.errorMessage}>{error.message}</Text>
41-
{error.stack && <Text testID={testIds.errorStack}>{error.stack}</Text>}
42-
{Boolean(error.cause) && <Text testID={testIds.errorCause}>{JSON.stringify(error.cause)}</Text>}
32+
{error.stack ? <Text testID={testIds.errorStack}>{error.stack}</Text> : null}
33+
{error.cause ? <Text testID={testIds.errorCause}>{JSON.stringify(error.cause)}</Text> : null}
4334
</View>
44-
)}
45-
{data && <Text testID={testIds.data}>{JSON.stringify(data)}</Text>}
35+
) : null}
36+
{data ? <Text testID={testIds.data}>{JSON.stringify(data)}</Text> : null}
4637
<Pressable
4738
testID={testIds.getData}
4839
onPress={async () => {
49-
const tags = args.useTags ? testTags : undefined
40+
const tags = config.useTags ? testTags : undefined
5041

51-
await getData(tags, args.linkedId)
42+
await getData(tags, config.linkedId)
5243
}}
5344
style={{
5445
paddingBottom: 48,
@@ -64,7 +55,7 @@ function InnerApp() {
6455

6556
export default function App() {
6657
return (
67-
<FingerprintJsProProvider apiKey={args.apiKey} region={args.region}>
58+
<FingerprintJsProProvider apiKey={config.apiKey} region={config.region}>
6859
<InnerApp />
6960
</FingerprintJsProProvider>
7061
)

e2e-app/app-config-tools/android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const androidBuildProperties = {
33
compileSdkVersion: 35,
44
targetSdkVersion: 35,
55
buildToolsVersion: '34.0.0',
6-
extraMavenRepos: ['https://maven.fpregistry.io/releases'],
6+
enableBundleCompression: false,
77
} as Record<string, any>
88

99
export function stripAndroidExtraBuildProperties() {

e2e-app/app.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Required in order to import other .ts files - https://docs.expo.dev/guides/typescript/#appconfigjs
2-
import 'ts-node/register'
2+
import 'tsx/cjs'
33
import { ExpoConfig } from '@expo/config'
44
import { dependencies } from './package.json'
55
import * as semver from 'semver'
@@ -40,6 +40,7 @@ const config: ExpoConfig = {
4040
package: 'com.fingerprint.e2eapp',
4141
},
4242
plugins: [
43+
'@fingerprintjs/fingerprintjs-pro-react-native',
4344
[
4445
'expo-build-properties',
4546
{

0 commit comments

Comments
 (0)