Skip to content

Commit 8a6727e

Browse files
authored
Merge pull request #109 from fingerprintjs/feat/allow-pass-getoptions-to-getdata
Extend `getData` options with `fingerprintjs-pro` `GetDataOptions`.
2 parents 512af61 + ada1f67 commit 8a6727e

File tree

7 files changed

+144
-27
lines changed

7 files changed

+144
-27
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Analyze Commit Messages
2+
on: [pull_request]
3+
4+
permissions:
5+
pull-requests: write
6+
contents: write
7+
jobs:
8+
release-notes-comment:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- name: Collect semantic-release-info
15+
id: semantic_release_info
16+
uses: fingerprintjs/action-semantic-release-info@v1
17+
- if: ${{ steps.semantic_release_info.outputs.no_release == 'false' }}
18+
name: Add comment to the PR
19+
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
20+
with:
21+
header: ReleasePreview
22+
recreate: true
23+
message: |
24+
## This PR will create a ${{steps.semantic_release_info.outputs.type}} release :rocket:
25+
${{steps.semantic_release_info.outputs.notes}}
26+
- if: ${{ steps.semantic_release_info.outputs.no_release == 'true' }}
27+
name: Add comment to the PR
28+
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
29+
with:
30+
header: ReleasePreview
31+
recreate: true
32+
message: |
33+
## This PR will not create a new release :rocket:

__tests__/use-visitor-data.test.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,80 @@ describe('useVisitorData', () => {
153153

154154
expect(hook.result.current.error?.message).toBe(ERROR_CLIENT_TIMEOUT)
155155
})
156+
157+
it('`getVisitorData` `getOptions` should be passed from `getVisitorData` `getOptions`', async () => {
158+
const useVisitorDataId = 'useVisitorDataId'
159+
const wrapper = createWrapper()
160+
const hook = renderHook(
161+
() =>
162+
useVisitorData(
163+
{
164+
linkedId: useVisitorDataId,
165+
tag: { tagA: useVisitorDataId },
166+
},
167+
{ immediate: false }
168+
),
169+
{ wrapper }
170+
)
171+
172+
await act(async () => {
173+
await hook.result.current.getData()
174+
})
175+
expect(getVisitorData).toHaveBeenCalledTimes(1)
176+
expect(getVisitorData).toHaveBeenCalledWith(
177+
{ linkedId: useVisitorDataId, tag: { tagA: useVisitorDataId } },
178+
undefined
179+
)
180+
})
181+
182+
it('`getData` `getOptions` should be more important than `getVisitorData` `getOptions`', async () => {
183+
const getDataId = 'getDataId'
184+
const useVisitorDataId = 'useVisitorDataId'
185+
const wrapper = createWrapper()
186+
const hook = renderHook(
187+
() =>
188+
useVisitorData(
189+
{
190+
linkedId: useVisitorDataId,
191+
tag: { tagA: useVisitorDataId },
192+
},
193+
{ immediate: false }
194+
),
195+
{ wrapper }
196+
)
197+
198+
await act(async () => {
199+
await hook.result.current.getData({
200+
linkedId: getDataId,
201+
tag: { tagA: getDataId },
202+
})
203+
})
204+
expect(getVisitorData).toHaveBeenCalledTimes(1)
205+
expect(getVisitorData).toHaveBeenCalledWith({ linkedId: getDataId, tag: { tagA: getDataId } }, undefined)
206+
})
207+
208+
it('`getData` `getOptions` should extend `getVisitorData` `getOptions`', async () => {
209+
const getDataId = 'getDataId'
210+
const useVisitorDataId = 'useVisitorDataId'
211+
const wrapper = createWrapper()
212+
const hook = renderHook(
213+
() =>
214+
useVisitorData(
215+
{
216+
linkedId: useVisitorDataId,
217+
tag: { tagA: useVisitorDataId },
218+
},
219+
{ immediate: false }
220+
),
221+
{ wrapper }
222+
)
223+
224+
await act(async () => {
225+
await hook.result.current.getData({
226+
linkedId: getDataId,
227+
})
228+
})
229+
expect(getVisitorData).toHaveBeenCalledTimes(1)
230+
expect(getVisitorData).toHaveBeenCalledWith({ linkedId: getDataId, tag: { tagA: useVisitorDataId } }, undefined)
231+
})
156232
})

examples/preact/src/components/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const App: FunctionalComponent = () => {
77
const [extendedResult, updateExtendedResult] = useState(false)
88
const { isLoading, error, data, getData } = useVisitorData({ extendedResult }, { immediate: true })
99

10-
const reloadData = () => {
10+
const reloadData = (): void => {
1111
getData({ ignoreCache: true })
1212
}
1313

14-
const onChangeExtendedResult = (e: TargetedEvent<HTMLInputElement, Event>) => {
14+
const onChangeExtendedResult = (e: TargetedEvent<HTMLInputElement, Event>): void => {
1515
updateExtendedResult((e.target as HTMLInputElement).checked)
1616
}
1717

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"semantic-release": "19.0.3",
103103
"ts-jest": "^27.1.5",
104104
"tslib": "2.5.0",
105-
"typedoc": "^0.23.24",
105+
"typedoc": "^0.24.8",
106106
"typescript": "^4.9.5"
107107
},
108108
"lint-staged": {

src/fpjs-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface VisitorQueryResult<TExtended extends boolean> extends QueryResu
2020
data?: VisitorData<TExtended>
2121
}
2222

23-
export interface GetDataOptions {
23+
export interface GetDataOptions<TExtended extends boolean> extends GetOptions<TExtended> {
2424
/**
2525
* When set to true, the visitor data will always be fetched from our API.
2626
* */
@@ -31,7 +31,7 @@ export interface VisitorQueryContext<TExtended extends boolean> extends VisitorQ
3131
/**
3232
* Performs identification request to server and returns visitors data.
3333
* */
34-
getData: (getDataOptions?: GetDataOptions) => Promise<VisitorData<TExtended>>
34+
getData: (getDataOptions?: GetDataOptions<TExtended>) => Promise<VisitorData<TExtended>>
3535
}
3636

3737
const stub = (): never => {

src/use-visitor-data.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import deepEquals from 'fast-deep-equal'
66
import { toError } from './utils/to-error'
77
import { assertIsTruthy } from './utils/assert-is-truthy'
88

9-
export type UseVisitorDataOptions<TExtended extends boolean> = GetOptions<TExtended> & Partial<GetDataOptions>
9+
export type UseVisitorDataOptions<TExtended extends boolean> = GetDataOptions<TExtended>
1010

1111
/**
1212
* @example
@@ -43,15 +43,17 @@ export function useVisitorData<TExtended extends boolean>(
4343
async (params = {}) => {
4444
assertIsTruthy(params, 'getDataParams')
4545

46-
const { ignoreCache } = params
46+
const { ignoreCache, ...getDataPassedOptions } = params
4747

4848
try {
4949
setState((state) => ({ ...state, isLoading: true }))
5050

5151
const { ignoreCache: defaultIgnoreCache, ...getVisitorDataOptions } = getOptions
5252

53+
const getDataOptions: GetOptions<TExtended> = { ...getVisitorDataOptions, ...getDataPassedOptions }
54+
5355
const result = await getVisitorData(
54-
getVisitorDataOptions ?? {},
56+
getDataOptions,
5557
typeof ignoreCache === 'boolean' ? ignoreCache : defaultIgnoreCache
5658
)
5759
setState((state) => ({ ...state, data: result, isLoading: false, error: undefined }))

yarn.lock

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,11 @@ ansi-regex@^6.0.1:
22082208
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a"
22092209
integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==
22102210

2211+
ansi-sequence-parser@^1.1.0:
2212+
version "1.1.0"
2213+
resolved "https://registry.yarnpkg.com/ansi-sequence-parser/-/ansi-sequence-parser-1.1.0.tgz#4d790f31236ac20366b23b3916b789e1bde39aed"
2214+
integrity sha512-lEm8mt52to2fT8GhciPCGeCXACSz2UwIN4X2e2LJSnZ5uAbn2/dsYdOmUXq0AtWS5cpAupysIneExOgH0Vd2TQ==
2215+
22112216
ansi-styles@^3.2.1:
22122217
version "3.2.1"
22132218
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
@@ -6225,10 +6230,10 @@ marked@^4.0.10:
62256230
resolved "https://registry.yarnpkg.com/marked/-/marked-4.0.17.tgz#1186193d85bb7882159cdcfc57d1dfccaffb3fe9"
62266231
integrity sha512-Wfk0ATOK5iPxM4ptrORkFemqroz0ZDxp5MWfYA7H/F+wO17NRWV5Ypxi6p3g2Xmw2bKeiYOl6oVnLHKxBA0VhA==
62276232

6228-
marked@^4.2.5:
6229-
version "4.2.12"
6230-
resolved "https://registry.yarnpkg.com/marked/-/marked-4.2.12.tgz#d69a64e21d71b06250da995dcd065c11083bebb5"
6231-
integrity sha512-yr8hSKa3Fv4D3jdZmtMMPghgVt6TWbk86WQaWhDloQjRSQhMMYCAro7jP7VDJrjjdV8pxVxMssXS8B8Y5DZ5aw==
6233+
marked@^4.3.0:
6234+
version "4.3.0"
6235+
resolved "https://registry.yarnpkg.com/marked/-/marked-4.3.0.tgz#796362821b019f734054582038b116481b456cf3"
6236+
integrity sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==
62326237

62336238
meow@^8.0.0:
62346239
version "8.1.2"
@@ -6329,10 +6334,10 @@ minimatch@^5.0.1:
63296334
dependencies:
63306335
brace-expansion "^2.0.1"
63316336

6332-
minimatch@^5.1.2:
6333-
version "5.1.6"
6334-
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
6335-
integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==
6337+
minimatch@^9.0.0:
6338+
version "9.0.1"
6339+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253"
6340+
integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==
63366341
dependencies:
63376342
brace-expansion "^2.0.1"
63386343

@@ -7844,11 +7849,12 @@ shebang-regex@^3.0.0:
78447849
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
78457850
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
78467851

7847-
shiki@^0.12.1:
7848-
version "0.12.1"
7849-
resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.12.1.tgz#26fce51da12d055f479a091a5307470786f300cd"
7850-
integrity sha512-aieaV1m349rZINEBkjxh2QbBvFFQOlgqYTNtCal82hHj4dDZ76oMlQIX+C7ryerBTDiga3e5NfH6smjdJ02BbQ==
7852+
shiki@^0.14.1:
7853+
version "0.14.2"
7854+
resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.14.2.tgz#d51440800b701392b31ce2336036058e338247a1"
7855+
integrity sha512-ltSZlSLOuSY0M0Y75KA+ieRaZ0Trf5Wl3gutE7jzLuIcWxLp5i/uEnLoQWNvgKXQ5OMpGkJnVMRLAuzjc0LJ2A==
78517856
dependencies:
7857+
ansi-sequence-parser "^1.1.0"
78527858
jsonc-parser "^3.2.0"
78537859
vscode-oniguruma "^1.7.0"
78547860
vscode-textmate "^8.0.0"
@@ -8636,15 +8642,15 @@ typedarray-to-buffer@^3.1.5:
86368642
dependencies:
86378643
is-typedarray "^1.0.0"
86388644

8639-
typedoc@^0.23.24:
8640-
version "0.23.24"
8641-
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.23.24.tgz#01cf32c09f2c19362e72a9ce1552d6e5b48c4fef"
8642-
integrity sha512-bfmy8lNQh+WrPYcJbtjQ6JEEsVl/ce1ZIXyXhyW+a1vFrjO39t6J8sL/d6FfAGrJTc7McCXgk9AanYBSNvLdIA==
8645+
typedoc@^0.24.8:
8646+
version "0.24.8"
8647+
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.24.8.tgz#cce9f47ba6a8d52389f5e583716a2b3b4335b63e"
8648+
integrity sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==
86438649
dependencies:
86448650
lunr "^2.3.9"
8645-
marked "^4.2.5"
8646-
minimatch "^5.1.2"
8647-
shiki "^0.12.1"
8651+
marked "^4.3.0"
8652+
minimatch "^9.0.0"
8653+
shiki "^0.14.1"
86488654

86498655
typescript@^4.6.4:
86508656
version "4.7.4"

0 commit comments

Comments
 (0)