-
Notifications
You must be signed in to change notification settings - Fork 0
ENG-4043: Add device tracking library #1
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 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c75e830
Install precious via mise
oschwald e460448
Add development tooling and configuration
oschwald 07710b9
Add types
oschwald 0ec4a81
Add module loader with singleton caching and timeout
oschwald 921df6f
Add public trackDevice API with input validation
oschwald 47afeca
Add tests for loader and public API
oschwald 532a97a
Update README with usage documentation
oschwald 7fa1e3c
Add GitHub Actions workflows and Dependabot config
oschwald 1f37a18
Add CLAUDE.md with project conventions and development guide
oschwald d00904c
Add pre-commit hook running precious lint
oschwald 76c842e
Do not bother testing on multiple Node versions
oschwald 072f295
Tighten host validation and add disableWebglHash runtime check
oschwald 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dist/ | ||
| node_modules/ | ||
| pnpm-lock.yaml |
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 |
|---|---|---|
| @@ -1,18 +1,69 @@ | ||
| # MaxMind Device Tracking Add-On | ||
|
|
||
| A thin loader package for MaxMind's [minFraud device tracking](https://dev.maxmind.com/minfraud/track-devices) | ||
| system. This package dynamically loads the device fingerprinting module from | ||
| MaxMind's servers at runtime, ensuring you always get the latest version without | ||
| updating the npm package. | ||
|
|
||
| The package itself contains no fingerprinting logic — it validates inputs, loads | ||
| the remote module, and returns the tracking token. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @maxmind/device-tracking | ||
| ``` | ||
|
|
||
| ## License | ||
| ## Usage | ||
|
|
||
| ```typescript | ||
| import { trackDevice } from '@maxmind/device-tracking'; | ||
|
|
||
| const result = await trackDevice({ accountId: 123456 }); | ||
| console.log(result.trackingToken); | ||
| ``` | ||
|
|
||
| ### Ad-blocker bypass | ||
|
|
||
| If you proxy MaxMind's device tracking through your own subdomain (to avoid | ||
| ad-blockers), pass the `host` option. The module will be loaded from your | ||
| custom host, and the host value is passed to the remote module for its own use: | ||
|
|
||
| ```typescript | ||
| const result = await trackDevice({ | ||
| accountId: 123456, | ||
| host: 'tracking.yourdomain.com', | ||
| }); | ||
| ``` | ||
|
|
||
| ### Disable WebGL hash | ||
|
|
||
| For performance or compatibility, you can disable WebGL hash collection: | ||
|
|
||
| ```typescript | ||
| const result = await trackDevice({ | ||
| accountId: 123456, | ||
| disableWebglHash: true, | ||
| }); | ||
| ``` | ||
|
|
||
| ## API reference | ||
|
|
||
| ### `trackDevice(options: TrackDeviceOptions): Promise<TrackResult>` | ||
|
|
||
| Loads the device tracking module (if not already cached) and collects a device | ||
| fingerprint. | ||
|
|
||
| ### `TrackDeviceOptions` | ||
|
|
||
| Licensed under either of | ||
| | Property | Type | Required | Description | | ||
| | ------------------ | --------- | -------- | ----------------------------------------------- | | ||
| | `accountId` | `number` | Yes | Your MaxMind account ID (positive integer) | | ||
| | `host` | `string` | No | Custom hostname for ad-blocker bypass | | ||
| | `disableWebglHash` | `boolean` | No | Disable WebGL hash collection | | ||
|
|
||
| - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or | ||
| https://www.apache.org/licenses/LICENSE-2.0) | ||
| - MIT license ([LICENSE-MIT](LICENSE-MIT) or | ||
| https://opensource.org/licenses/MIT) | ||
| ### `TrackResult` | ||
|
|
||
| at your option. | ||
| | Property | Type | Description | | ||
| | --------------- | -------- | ------------------------------ | | ||
| | `trackingToken` | `string` | Opaque device tracking token | | ||
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,27 @@ | ||
| import js from '@eslint/js'; | ||
| import tseslint from 'typescript-eslint'; | ||
| import prettierConfig from 'eslint-config-prettier'; | ||
| import globals from 'globals'; | ||
|
|
||
| export default tseslint.config( | ||
| { | ||
| ignores: ['dist/', 'node_modules/', 'coverage/', 'jest.config.js', '*.mjs'], | ||
| }, | ||
| js.configs.recommended, | ||
| ...tseslint.configs.recommended, | ||
| prettierConfig, | ||
| { | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.browser, | ||
| ...globals.node, | ||
| }, | ||
| parserOptions: { | ||
| projectService: { | ||
| allowDefaultProject: ['src/*.spec.ts'], | ||
| }, | ||
| tsconfigRootDir: import.meta.dirname, | ||
| }, | ||
| }, | ||
| } | ||
| ); |
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,18 @@ | ||
| /** @type {import('jest').Config} */ | ||
| export default { | ||
| testEnvironment: 'jest-environment-jsdom', | ||
| extensionsToTreatAsEsm: ['.ts'], | ||
| transform: { | ||
| '^.+\\.ts$': [ | ||
| 'ts-jest', | ||
| { | ||
| useESM: true, | ||
| tsconfig: 'tsconfig.eslint.json', | ||
| }, | ||
| ], | ||
| }, | ||
| moduleNameMapper: { | ||
| '^(\\.{1,2}/.*)\\.js$': '$1', | ||
| }, | ||
| testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
| }; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to drop this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! My thought is that it was confusing as this is just a very thin wrapper around a script that isn't under that license.