Repository navigation
[INTER-2190] Final V4 adjustments #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ae8b65b
chore(gradle): bump fingerprint SDK version to 4.1.0
TheUnderScorer b144925
feat(sdk): add `validateTags` utility with tests
TheUnderScorer 8b0dfad
fix(sdk): handle `visitor_id` as optional in response
TheUnderScorer bd5f70a
fix(sdk): enforce rejection of nested undefined in tags
TheUnderScorer 2660448
fix(sdk): make `visitor_id` optional in zero-trust mode
TheUnderScorer cab66a1
fix(sdk): reorder tag validation in `get` method
TheUnderScorer f040dd4
refactor: simplify tags validation
TheUnderScorer 9dc092d
refactor(sdk): remove unused `InvalidArgumentError` class
TheUnderScorer 426fb5c
fix(sdk): update default error code to `unknown_error`
TheUnderScorer 5b2a338
docs(sdk): clarify single client creation requirement
TheUnderScorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { validateTags } from '../src/tags' | ||
|
|
||
| describe('validateTags', () => { | ||
| it.each([Infinity, -Infinity, NaN])('rejects invalid numeric values', (value) => { | ||
| expect(() => { | ||
| validateTags(value) | ||
| }).toThrow(new TypeError('tags must be a finite number')) | ||
| }) | ||
|
|
||
| it.each([Infinity, -Infinity, NaN])('rejects nested invalid numeric values', (value) => { | ||
| expect(() => { | ||
| validateTags({ | ||
| value: { | ||
| numeric: value, | ||
| }, | ||
| }) | ||
| }).toThrow(new TypeError("tags['value']['numeric'] must be a finite number")) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Rejects NaN / Infinity in `tags`. | ||
| * | ||
| * `TagsPrimitive` is `number`, so `{ score: Number('oops') }` type-checks. | ||
| * JSON has no literal for those values. Each platform rewrites them | ||
| * differently (`null` on web, `0` on iOS via `NSNumber.intValue`, usually | ||
| * `null` on Android) and identification still succeeds. Throw instead of | ||
| * storing the wrong tag. | ||
| * | ||
| * `Date`, `Map`, and class instances are already a type error on `TagsValue`. | ||
| * This walk does not reject them. The RN bridge and JS agent do not agree on | ||
| * those values (a `Date` is an ISO string on web and `{}` on native), but we | ||
| * choose to ignore that. | ||
| * | ||
| * Size is a server `payload_too_large`. | ||
| * https://docs.fingerprint.com/docs/tagging-information | ||
| */ | ||
|
|
||
| export function validateTags(tags?: unknown): void { | ||
| if (tags === null || tags === undefined) { | ||
| return | ||
| } | ||
| walk(tags, 'tags') | ||
| } | ||
|
|
||
| function walk(value: unknown, path: string): void { | ||
| if (value === null || value === undefined) { | ||
| return | ||
| } | ||
|
|
||
| if (typeof value === 'number') { | ||
| if (!Number.isFinite(value)) { | ||
| throw new TypeError(`${path} must be a finite number`) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if (typeof value !== 'object') { | ||
| return | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| for (const [index, entry] of value.entries()) { | ||
| walk(entry, `${path}[${String(index)}]`) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| for (const [key, entry] of Object.entries(value)) { | ||
| walk(entry, `${path}['${key}']`) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.