Skip to content

Commit

Permalink
Merge pull request #15 from fingerprintjs/rc
Browse files Browse the repository at this point in the history
Release v0.2.0-rc.1
  • Loading branch information
Orkuncakilkaya authored Nov 11, 2024
2 parents 6606640 + 5680cef commit 66ae909
Show file tree
Hide file tree
Showing 21 changed files with 368 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mock-e2e-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
with:
verbose: true
env:
CONFIG_STORE_NAME: "E2ETest"
STORE_NAME_PREFIX: "E2ETest"
- name: Deploy
id: deploy
env:
Expand All @@ -67,7 +67,7 @@ jobs:
FASTLY_API_TOKEN: ${{secrets.FASTLY_API_TOKEN}}
FPJS_BACKEND_URL: ${{secrets.MOCK_FPCDN}}
FPCDN_URL: ${{secrets.MOCK_FPCDN}}
CONFIG_STORE_NAME: "E2ETest"
STORE_NAME_PREFIX: "E2ETest"
run: pnpm run ci
- name: Wait for 60s
shell: bash
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [0.2.0-rc.2](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/compare/v0.2.0-rc.1...v0.2.0-rc.2) (2024-11-08)


### Features

* move proxy secret to secret store ([b943878](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/commit/b94387882bd4d485733faa6cc712ee6e298d6e58))
* show all configurations on status page ([e996354](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/commit/e9963545ae6be1fa44e2fa41ef74306067e6a75e))

## [0.2.0-rc.1](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/compare/v0.1.0...v0.2.0-rc.1) (2024-11-05)


### Features

* add prefix to config store name ([3838318](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/commit/38383186439c5b1f7362b7462ea1a578287a59e3))

## [0.1.0](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/compare/v0.0.0...v0.1.0) (2024-10-29)


Expand Down
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ The Fastly Compute Proxy Integration is responsible for proxying identification

## Getting started

This is a quick overview of the installation setup. For detailed step-by-step instructions, see the [Fastly Compute proxy integration guide in our documentation](https://dev.fingerprint.com/docs/fastly-compute-edge-proxy-integration).
This is a quick overview of the installation setup. For detailed step-by-step instructions, see the [Fastly Compute proxy integration guide in our documentation](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration).

1. Go to the Fingerprint Dashboard > [**API Keys**](https://dashboard.fingerprint.com/api-keys) and click **Create Proxy Key** to create a proxy secret. You will use it later to authenticate your requests to Fingerprint APIs.

2. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) in your Fastly account named exactly `Fingerprint` and add the following values:
2. [Create an empty Compute Service](https://docs.fastly.com/en/guides/working-with-compute-services#creating-a-new-compute-service) in your Fastly account.

| Key | Example Value | Description |
|------------------------------|----------------------|---------------------------------------------------------------------------------------------|
| PROXY_SECRET | 6XI9CLf3C9oHSB12TTaI | Fingerprint proxy secret generated in Step 1. |
| OPEN_CLIENT_RESPONSE_ENABLED | false | Set to `true` if you have [Open client response](https://dev.fingerprint.com/docs/open-client-response) enabled for your Fingerprint application. Defaults to `false`. |
| AGENT_SCRIPT_DOWNLOAD_PATH | z5kms2 | Random path segment for downloading the JavaScript agent. |
| GET_RESULT_PATH | nocmjw | Random path segment for Fingerprint identification requests. |
3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Compute_Config_Store_<SERVICE_ID>`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values:

3. Go to [Releases](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/releases) to download the latest `fingerprint-proxy-integration.tar.gz` package file.
4. Upload package to your Fastly Compute Service's **Package**.
5. Configure the Fingerprint [JavaScript Agent](https://dev.fingerprint.com/docs/install-the-javascript-agent#configuring-the-agent) on your website using the paths defined in Step 2.
| Key | Example Value | Description |
| ---------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AGENT_SCRIPT_DOWNLOAD_PATH | z5kms2 | Random path segment for downloading the JavaScript agent. |
| GET_RESULT_PATH | nocmjw | Random path segment for Fingerprint identification requests. |
| OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED | false | Set to `true` if you have [Open client response](https://dev.fingerprint.com/docs/open-client-response) enabled for your Fingerprint application. Defaults to `false`. |

4. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) named `Fingerprint_Compute_Secret_Store_<SERVICE_ID>`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add your proxy secret:

| Key | Example Value | Description |
| ------------ | -------------------- | --------------------------------------------- |
| PROXY_SECRET | 6XI9CLf3C9oHSB12TTaI | Fingerprint proxy secret generated in Step 1. |

5. Go to [Releases](https://github.com/fingerprintjs/fingerprint-pro-fastly-compute-proxy-integration/releases) to download the latest `fingerprint-proxy-integration.tar.gz` package file.
6. Upload package to your Fastly Compute Service's **Package**.
7. Configure the Fingerprint [JavaScript Agent](https://dev.fingerprint.com/docs/install-the-javascript-agent#configuring-the-agent) on your website using the paths defined in Step 3.
```javascript
import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro'

Expand All @@ -62,16 +69,27 @@ This is a quick overview of the installation setup. For detailed step-by-step in
});
```

See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/docs/fastly-compute-edge-proxy-integration#step-9-configure-the-fingerprint-client-agent-on-to-use-your-service) in our documentation for more details.
See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration#step-4-configure-the-fingerprint-client-agent-to-use-your-service) in our documentation for more details.

### Using custom store names

### Using a custom config store name
By default, the service package provided in releases assumes the following names for the Config store and Secret Store:

The worker package provided in Releases assumes the config store used by the integration is named exactly `Fingerprint`. If you need to use a different config store name, you can pass the name to the `CONFIG_STORE_NAME` environment variable and build a custom worker package:
* `Fingerprint_Compute_Config_Store_<SERVICE_ID>`
* `Fingerprint_Compute_Secret_Store_<SERVICE_ID>`

```shell
CONFIG_STORE_NAME=MyCustomStoreName pnpm run build
To use a custom name prefix for both stores, use the `STORE_NAME_PREFIX` environment variable to build a custom service package:

```shell=
STORE_NAME_PREFIX=CustomName pnpm run build
```

Your custom built package in `pkg/package.tar.gz` will use your custom prefix in store names like:

* `CustomName_Config_Store_<SERVICE_ID>`
* `CustomName_Secret_Store_<SERVICE_ID>`


## Feedback and support

Please reach out to our [Customer Success team](https://fingerprint.com/support/) if run into any issues with the integration.
Expand Down
3 changes: 3 additions & 0 deletions __mocks__/fastly:env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function env(key) {
return `TEST_${key}`
}
5 changes: 5 additions & 0 deletions __mocks__/fastly:kv-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class KVStore {
async put(name, value) {
return { name, value }
}
}
10 changes: 7 additions & 3 deletions __mocks__/fastly:secret-store.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const store = new Map()
export class ConfigStore {
export class SecretStore {
constructor(storeName) {
this.storeName = storeName
}

get(key) {
return store.get(key) || null
async get(key) {
return {
plaintext: () => {
return store.get(key) || null
},
}
}

set(key, value) {
Expand Down
4 changes: 2 additions & 2 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { build } from 'esbuild'

// Load environment variables from process.env
const configStoreName = process.env.CONFIG_STORE_NAME || 'Fingerprint'
const configStoreNamePrefix = process.env.STORE_NAME_PREFIX || 'Fingerprint_Compute'

build({
entryPoints: ['./src/index.ts'],
outdir: './build',
bundle: true,
format: 'cjs',
external: ['fastly:*'],
define: { 'process.env.CONFIG_STORE_NAME': `"${configStoreName}"` },
define: { 'process.env.STORE_NAME_PREFIX': `"${configStoreNamePrefix}"` },
}).catch(() => process.exit(1))
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fingerprint-pro-fastly-compute-proxy-integration",
"version": "0.1.0",
"version": "0.2.0-rc.2",
"engines": {
"node": ">=20"
},
Expand All @@ -12,7 +12,6 @@
"@fingerprintjs/commit-lint-dx-team": "^0.1.0",
"@fingerprintjs/conventional-changelog-dx-team": "^0.1.0",
"@fingerprintjs/eslint-config-dx-team": "^0.1.0",
"@fingerprintjs/fingerprintjs-pro-server-api": "^5.0.0",
"@fingerprintjs/prettier-config-dx-team": "^0.2.0",
"@fingerprintjs/tsconfig-dx-team": "^0.0.2",
"@jest/globals": "^29.7.0",
Expand All @@ -23,7 +22,7 @@
"@types/pako": "^2.0.3",
"babel-jest": "^29.7.0",
"esbuild": "^0.24.0",
"fastly": "7.3.0",
"fastly": "^7.10.0",
"fs": "0.0.1-security",
"husky": "^9.1.5",
"jest": "^29.7.0",
Expand Down Expand Up @@ -62,5 +61,8 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"peerDependencies": {
"@fingerprintjs/fingerprintjs-pro-server-api": "^5.2.0"
}
}
12 changes: 6 additions & 6 deletions plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import { saveFingerprintResultToKVStore } from './saveToKVStore'
import { saveFingerprintResultToKVStore } from './saveToKVStore'
import { Plugin } from '../src/utils/registerPlugin'

export default [
// {
// name: 'Save Fingerprint Result to KV Store',
// callback: saveFingerprintResultToKVStore,
// type: 'processOpenClientResponse',
// },
{
name: 'Save Fingerprint Result to KV Store',
callback: saveFingerprintResultToKVStore,
type: 'processOpenClientResponse',
},
] satisfies Plugin[]
14 changes: 13 additions & 1 deletion plugins/saveToKVStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

import { KVStore } from 'fastly:kv-store'
import { ProcessOpenClientResponseContext } from '../src/utils/registerPlugin'
import { getConfigStore } from '../src/utils/getStore'
import { env } from 'fastly:env'
export async function saveFingerprintResultToKVStore(context: ProcessOpenClientResponseContext) {
const configStore = getConfigStore()
const isPluginEnabled = configStore?.get('SAVE_TO_KV_STORE_PLUGIN_ENABLED') === 'true'

if (!isPluginEnabled) {
console.log("Plugin 'saveFingerprintResultToKVStore' is not enabled")
return
}

const requestId = context.event?.products.identification?.data?.requestId
if (!requestId) {
console.log('[saveFingerprintResultToKVStore] Plugin Error: request ID is undefined in the event response.')
return
}
const store = new KVStore('FingerprintResults')
const serviceId = env('FASTLY_SERVICE_ID')
const store = new KVStore(`Fingerprint_Results_${serviceId}`)
await store.put(requestId, JSON.stringify(context.event))
}
46 changes: 30 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 66ae909

Please sign in to comment.