Skip to content

Commit

Permalink
Recurrent repository care (#81)
Browse files Browse the repository at this point in the history
* chore: switch to `pnpm` from `yarn`

* fix: upgraded dependencies to latest, now using @fingerprintjs/fingerprintjs-pro@3.9.2

* chore: upgrade playground dependencies to latest

* docs: readme.md improvements

* docs: fix typo

* ci: use APP_ID and APP_PRIVATE_KEY in release.yml

* chore: use shared eslint and prettier configurations

* chore: use shared tsconfig configuration

* chore: use shared commitlint configuration

* chore: use shared conventional changelog configuration

* chore: fix build

* docs: add linkedId section to readme
  • Loading branch information
JuroUhlar authored Mar 21, 2024
1 parent 76d2879 commit cd44048
Show file tree
Hide file tree
Showing 18 changed files with 7,162 additions and 7,823 deletions.
20 changes: 1 addition & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/eslint-recommended', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'linebreak-style': ['error', 'unix'],
'prefer-const': 'error',
'prettier/prettier': 'error',
'@typescript-eslint/no-unused-vars': ['error'],
curly: [2, 'all'],
},
extends: ['eslint:recommended', '@fingerprintjs/eslint-config-dx-team', 'plugin:prettier/recommended'],
}
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
build-and-release:
name: 'Build project, run CI checks and publish new release'
uses: fingerprintjs/dx-team-toolkit/.github/workflows/release-typescript-project.yml@v1
with:
appId: ${{ vars.APP_ID }}
secrets:
GH_RELEASE_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ gh-pages/
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea
.vscode
.env
12 changes: 1 addition & 11 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always"
}
"@fingerprintjs/prettier-config-dx-team"
87 changes: 4 additions & 83 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,22 @@
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
},
{
"type": "docs",
"scope": "README",
"release": "patch"
}
]
"config": "@fingerprintjs/conventional-changelog-dx-team",
"releaseRules": "@fingerprintjs/conventional-changelog-dx-team/release-rules"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalCommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "feature",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"scope": "README",
"section": "Documentation"
},
{
"type": "build",
"scope": "deps",
"section": "Build System"
},
{
"type": "docs",
"section": "Documentation",
"hidden": true
},
{
"type": "style",
"section": "Styles",
"hidden": true
},
{
"type": "chore",
"section": "Miscellaneous Chores",
"hidden": true
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": true
},
{
"type": "test",
"section": "Tests",
"hidden": true
},
{
"type": "build",
"section": "Build System",
"hidden": true
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
]
}
"config": "@fingerprintjs/conventional-changelog-dx-team"
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/exec",
{
"prepareCmd": "yarn build"
"prepareCmd": "pnpm build"
}
],
[
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

[Fingerprint](https://fingerprint.com/) is a device intelligence platform offering 99.5% accurate visitor identification

This library is designed to be used in single-page-application framework wrappers for the Fingerprint Pro JavaScript Agent.
It has multiple built-in caching mechanisms with recommended default settings.
This library is a framework-agnostic wrapper around the Fingerprint Pro [JavaScript Agent](https://www.npmjs.com/package/@fingerprintjs/fingerprintjs-pro), adding multiple built-in caching mechanisms with recommended default settings.

If you just need the Fingerprint Pro [JS agent](https://www.npmjs.com/package/@fingerprintjs/fingerprintjs-pro), you can use it directly, without this wrapper. If you're looking for a framework-specific integration, we have dedicated SDKs for [React (including Next, Preact)](https://github.com/fingerprintjs/fingerprintjs-pro-react), [Vue](https://github.com/fingerprintjs/fingerprintjs-pro-vue), [Svelte](https://github.com/fingerprintjs/fingerprintjs-pro-svelte) and [Angular](https://github.com/fingerprintjs/fingerprintjs-pro-angular).
- If you just need the Fingerprint Pro [JS agent](https://www.npmjs.com/package/@fingerprintjs/fingerprintjs-pro) without caching, you can use it directly.
- If you're looking for a framework-specific integration, we have dedicated SDKs for [React (including Next, Preact)](https://github.com/fingerprintjs/fingerprintjs-pro-react), [Vue](https://github.com/fingerprintjs/fingerprintjs-pro-vue), [Svelte](https://github.com/fingerprintjs/fingerprintjs-pro-svelte) and [Angular](https://github.com/fingerprintjs/fingerprintjs-pro-angular).
- If you have a single-page web application that needs caching, but also more low-level control over the agent than framework-specific SDKs provide, this library is for you.

**This SDK works with Fingerprint Pro, it will not work with the open-source FingerprintJS version!**
Learn more about the [difference between Pro and OSS](https://dev.fingerprint.com/docs/pro-vs-open-source).
If you'd like to have a similar SPA wrapper for the OSS version of FingerprintJS, consider [raising an issue in our issue tracker](https://github.com/fingerprintjs/fingerprintjs-pro-spa/issues).
> [!NOTE]
> This library assumes you have a Fingerprint Pro subscription or trial, it is not compatible with the [source-available FingerprintJS](https://github.com/fingerprintjs/fingerprintjs). See our documentation to learn more about the [differences between Fingerprint Pro and FingerprintJS](https://dev.fingerprint.com/docs/identification-vs-fingerprintjs).
## Table of Contents

Expand Down Expand Up @@ -138,6 +138,20 @@ const visitorData = fpjsClient.getVisitorData({ extendedResult: true }).then((vi

See the [JS Agent API reference](https://dev.fingerprint.com/docs/js-agent) for more details.

#### Linking and tagging information

The `visitorId` provided by Fingerprint Identification is especially useful when combined with information you already know about your users, for example, account IDs, order IDs, etc. To learn more about various applications of the `linkedId` and `tag`, see [Linking and tagging information](https://dev.fingerprint.com/docs/tagging-information).

```js
const visitorData = await fpjsClient.getVisitorData({
linkedId: 'user_1234',
tag: {
userAction: 'login',
analyticsId: 'UA-5555-1111-1',
},
})
```

## Caching

Fingerprint Pro usage is billed per API call. To avoid unnecessary API calls, it is a good practice to cache identification results. The SDK provides three ways to cache visitor data out of the box:
Expand Down Expand Up @@ -209,7 +223,7 @@ We export the internal `InMemoryCache`, `LocalStorageCache`, `SessionStorageCach

### Cache time

Use the `cacheTimeInSeconds` client constructor option to set a custom cache time. To ensure high identification accuracy we recommend not to cache visitors data for longer than 24 hours. If you pass a value higher than 86400 (60 _ 60 _ 24), the `FpjsClient` constructor will throw an error.
Use the `cacheTimeInSeconds` client constructor option to set a custom cache time. To ensure high identification accuracy we recommend not to cache visitors data for longer than 24 hours. If you pass a value higher than 86400 (60 x 60 x 24), the `FpjsClient` constructor will throw an error.

## Support and feedback

Expand Down
2 changes: 1 addition & 1 deletion __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe(`SPA client`, () => {
describe(`setup`, () => {
const agentGetMock = jest.fn()

let loadSpy: jest.SpyInstance<ReturnType<typeof FingerprintJS['load']>>
let loadSpy: jest.SpyInstance<ReturnType<(typeof FingerprintJS)['load']>>

beforeEach(() => {
loadSpy = jest.spyOn(FingerprintJS, 'load')
Expand Down
4 changes: 3 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = { extends: ['@commitlint/config-conventional'] }
module.exports = {
extends: ['@fingerprintjs/commit-lint-dx-team'],
}
28 changes: 17 additions & 11 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
# Contributing to FingerprintJS Pro SPA integration
# Contributing to Fingerprint Pro SPA integration

## Working with code

We prefer using [yarn](https://yarnpkg.com/) for installing dependencies and running scripts.
We prefer using [pnpm](https://pnpm.io/) for installing dependencies and running scripts.

The main branch is locked for the push action. For proposing changes, use the standard [pull request approach](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). It's recommended to discuss fixes or new functionality in the Issues, first.

### Development playground

There is no specific playground for this library, but you can develop it with [fingerprintjs-pro-react](https://github.com/fingerprintjs/fingerprintjs-pro-react), just [link package](https://yarnpkg.com/cli/link) with the `yarn link`.

❗ Build project before testing integration
There is no specific playground for this library, but you can develop it with [fingerprintjs-pro-react](https://github.com/fingerprintjs/fingerprintjs-pro-react), just [link this package](https://pnpm.io/cli/link#replace-an-installed-package-with-a-local-version-of-it) with the `pnpm link <spa-directory>`. You need to build the project before testing the integration.

### How to build

Just run:

```shell
yarn build
pnpm build
```

### Code style

The code style is controlled by [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/). Run to check that the code style is ok:

```shell
yarn lint
pnpm lint
```

You aren't required to run the check manually, the CI will do it. Run to fix code style mistakes (not all mistakes can be fixed automatically):

```shell
yarn lint:fix
pnpm lint:fix
```

### How to test

Tests located in `__tests__` folder and run by [jest](https://jestjs.io/) in [jsdom](https://github.com/jsdom/jsdom) environment.

To run tests you can use IDE instruments or just run:

```shell
yarn test
pnpm test
```

To check the distributive TypeScript declarations, build the project and run:

```shell
yarn test:dts
pnpm test:dts
```

### Committing changes

We follow [Conventional Commits](https://conventionalcommits.org/) for committing changes. We use git hooks to check that the commit message is correct.
Expand All @@ -55,7 +61,7 @@ The library is automatically released and published to NPM on every push to the
We use [typedoc](https://typedoc.org/) to generate docs. To generate docs run:

```shell
yarn docs
pnpm docs
```

The docs will be generated into [./docs](./docs) directory.
Expand Down
61 changes: 31 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
],
"scripts": {
"prepare": "husky install",
"build": "rimraf dist && rollup -c rollup.config.js",
"build": "rimraf dist && rollup -c rollup.config.js --bundleConfigAsCjs",
"watch": "rimraf dist && rollup -c rollup.config.js -w",
"lint": "eslint --ext .js,.ts --ignore-path .gitignore --max-warnings 0 .",
"lint:fix": "yarn lint --fix",
"lint:fix": "pnpm lint --fix",
"prettier": "prettier src --check",
"prettier:fix": "yarn prettier --write",
"test": "jest",
"test:coverage": "jest --coverage",
"test:dts": "tsc --noEmit --isolatedModules dist/fp-pro-spa.d.ts",
Expand All @@ -32,7 +34,7 @@
"dist"
],
"lint-staged": {
"*.ts": "yarn run lint:fix"
"*.ts": "pnpm run lint:fix"
},
"config": {
"commitizen": {
Expand All @@ -50,35 +52,34 @@
},
"homepage": "https://github.com/fingerprintjs/fingerprintjs-pro-spa#readme",
"dependencies": {
"@fingerprintjs/fingerprintjs-pro": "^3.8.5",
"tslib": "^2.5.0"
"@fingerprintjs/fingerprintjs-pro": "^3.9.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^28.1.8",
"@types/node": "^18.14.6",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"commitizen": "^4.2.4",
"conventional-changelog-conventionalcommits": "^5.0.0",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@fingerprintjs/commit-lint-dx-team": "^0.0.2",
"@fingerprintjs/conventional-changelog-dx-team": "^0.1.0",
"@fingerprintjs/eslint-config-dx-team": "^0.1.0",
"@fingerprintjs/prettier-config-dx-team": "^0.1.0",
"@fingerprintjs/tsconfig-dx-team": "^0.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-typescript": "^11.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"commitizen": "^4.3.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lint-staged": "^13.0.2",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"rollup": "^2.44.0",
"rollup-plugin-dts": "^3.0.1",
"rollup-plugin-license": "^2.7.0",
"ts-jest": "^28.0.8",
"typedoc": "^0.23.26",
"typescript": "^4.9.5"
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^15.2.2",
"rimraf": "^5.0.5",
"rollup": "^4.13.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-license": "^3.3.1",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2"
}
}
Loading

0 comments on commit cd44048

Please sign in to comment.