From 991d76e6407e8b8f7064f6767a8e9814dc935622 Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 29 Oct 2024 17:35:01 +0300 Subject: [PATCH 01/40] docs(readme): update links for docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0bffe9e..ce4c486 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ 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. @@ -62,7 +62,7 @@ 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 a custom config store name From 38383186439c5b1f7362b7462ea1a578287a59e3 Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 31 Oct 2024 14:15:10 +0300 Subject: [PATCH 02/40] feat: add prefix to config store name --- README.md | 6 +++++- __mocks__/fastly:env.js | 3 +++ scripts/api/createService.ts | 12 +++++++----- src/index.ts | 5 ++++- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 __mocks__/fastly:env.js diff --git a/README.md b/README.md index ce4c486..522e364 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,16 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -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: +The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint` with prefix of your Fastly Compute Service id. 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: ```shell CONFIG_STORE_NAME=MyCustomStoreName pnpm run build ``` +The outcome of artifact will look like this: `_` +For example: `MxLpeV9YSRbQKxlGpCVnD5_Fingerprint` if you use the artifact in the release. +Or: `MxLpeV9YSRbQKxlGpCVnD5_MyCustomConfigStoreName` if you build your own artifact with a custom config store name. + ## Feedback and support Please reach out to our [Customer Success team](https://fingerprint.com/support/) if run into any issues with the integration. diff --git a/__mocks__/fastly:env.js b/__mocks__/fastly:env.js new file mode 100644 index 0000000..2a5a0c4 --- /dev/null +++ b/__mocks__/fastly:env.js @@ -0,0 +1,3 @@ +export function env(key) { + return `TEST_${key}` +} diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index df67fbe..da04cec 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -21,7 +21,7 @@ export async function createService(domain: string) { }) await createDomain(domain, createResponse.id) await createOrigin(createResponse.id, domain) - const configStore = await createConfigStore() + const configStore = await createConfigStore(createResponse.id) console.log('config store created') console.log('linking config store') await linkConfigStore(createResponse.id, 1, configStore.id) @@ -69,26 +69,28 @@ async function createDomain(domain: string, serviceId: string) { } async function linkConfigStore(service_id: string, version_id: number, resource_id: string) { + const configStoreNameWithPrefix = `${service_id}_${CONFIG_STORE_NAME}` return createClient('resource').createResource({ service_id, version_id, resource_id, - name: CONFIG_STORE_NAME, + name: configStoreNameWithPrefix, }) } -async function createConfigStore() { +async function createConfigStore(service_id: string) { console.log('Creating config store') + const configStoreNameWithPrefix = `${service_id}_${CONFIG_STORE_NAME}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore try { configStore = await configStoreClient.createConfigStore({ - name: CONFIG_STORE_NAME, + name: configStoreNameWithPrefix, }) } catch (_) { const stores = await configStoreClient.listConfigStores() - return stores.find((t: any) => t.name === CONFIG_STORE_NAME) + return stores.find((t: any) => t.name === configStoreNameWithPrefix) } await configStoreItemClient.createConfigStoreItem({ config_store_id: configStore.id, diff --git a/src/index.ts b/src/index.ts index 0be6d65..9dc4960 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { ConfigStore } from 'fastly:config-store' import { returnHttpResponse } from './utils/returnHttpResponse' import { createFallbackErrorResponse } from './utils' import { setClientIp } from './utils/clientIp' +import { env } from 'fastly:env' addEventListener('fetch', (event) => event.respondWith(handleRequest(event))) @@ -21,9 +22,11 @@ export async function handleRequest(event: FetchEvent): Promise { } function getEnvObject(): IntegrationEnv { + const serviceId = env('FASTLY_SERVICE_ID') + const configStoreName = process.env.CONFIG_STORE_NAME ?? 'Fingerprint' let config try { - config = new ConfigStore(process.env.CONFIG_STORE_NAME ?? 'Fingerprint') + config = new ConfigStore(`${serviceId}_${configStoreName}`) } catch (e) { console.error(e) } From c34deac29c50319cb58c19aa64852beb37695057 Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 31 Oct 2024 14:28:23 +0300 Subject: [PATCH 03/40] chore: add config store create error logger on ci --- scripts/api/createService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index da04cec..dbd2667 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -88,7 +88,8 @@ async function createConfigStore(service_id: string) { configStore = await configStoreClient.createConfigStore({ name: configStoreNameWithPrefix, }) - } catch (_) { + } catch (e) { + console.error('Could not create config store', e) const stores = await configStoreClient.listConfigStores() return stores.find((t: any) => t.name === configStoreNameWithPrefix) } From e9d2f4f854491d76d7b401b8ba31cc5e55b17bdc Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 31 Oct 2024 15:00:44 +0300 Subject: [PATCH 04/40] chore: reverse order for config store name --- scripts/api/createService.ts | 4 ++-- src/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index dbd2667..c97f3c2 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -69,7 +69,7 @@ async function createDomain(domain: string, serviceId: string) { } async function linkConfigStore(service_id: string, version_id: number, resource_id: string) { - const configStoreNameWithPrefix = `${service_id}_${CONFIG_STORE_NAME}` + const configStoreNameWithPrefix = `${CONFIG_STORE_NAME}_${service_id}` return createClient('resource').createResource({ service_id, version_id, @@ -80,7 +80,7 @@ async function linkConfigStore(service_id: string, version_id: number, resource_ async function createConfigStore(service_id: string) { console.log('Creating config store') - const configStoreNameWithPrefix = `${service_id}_${CONFIG_STORE_NAME}` + const configStoreNameWithPrefix = `${CONFIG_STORE_NAME}_${service_id}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore diff --git a/src/index.ts b/src/index.ts index 9dc4960..f0358ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ function getEnvObject(): IntegrationEnv { const configStoreName = process.env.CONFIG_STORE_NAME ?? 'Fingerprint' let config try { - config = new ConfigStore(`${serviceId}_${configStoreName}`) + config = new ConfigStore(`${configStoreName}_${serviceId}`) } catch (e) { console.error(e) } From 157df3c2d74d0aaab91c3b60900a9caba9c4c32a Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 31 Oct 2024 15:11:22 +0300 Subject: [PATCH 05/40] chore: update config store name prefix --- .github/workflows/mock-e2e-pr.yml | 4 ++-- README.md | 8 ++++---- build.ts | 4 ++-- scripts/api/createService.ts | 6 +++--- src/index.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/mock-e2e-pr.yml b/.github/workflows/mock-e2e-pr.yml index 490dc84..8a09405 100644 --- a/.github/workflows/mock-e2e-pr.yml +++ b/.github/workflows/mock-e2e-pr.yml @@ -58,7 +58,7 @@ jobs: with: verbose: true env: - CONFIG_STORE_NAME: "E2ETest" + CONFIG_STORE_NAME_PREFIX: "E2ETest" - name: Deploy id: deploy env: @@ -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" + CONFIG_STORE_NAME_PREFIX: "E2ETest" run: pnpm run ci - name: Wait for 60s shell: bash diff --git a/README.md b/README.md index 522e364..85f2f94 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,15 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint` with prefix of your Fastly Compute Service id. 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: +The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint` with prefix of your Fastly Compute Service id. If you need to use a different config store name, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom worker package: ```shell -CONFIG_STORE_NAME=MyCustomStoreName pnpm run build +CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` The outcome of artifact will look like this: `_` -For example: `MxLpeV9YSRbQKxlGpCVnD5_Fingerprint` if you use the artifact in the release. -Or: `MxLpeV9YSRbQKxlGpCVnD5_MyCustomConfigStoreName` if you build your own artifact with a custom config store name. +For example: `Fingerprint_Fastly_Compute_Proxy_Integration_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. +Or: `MyCustomConfigStoreName_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. ## Feedback and support diff --git a/build.ts b/build.ts index deb9357..980aa88 100644 --- a/build.ts +++ b/build.ts @@ -1,7 +1,7 @@ import { build } from 'esbuild' // Load environment variables from process.env -const configStoreName = process.env.CONFIG_STORE_NAME || 'Fingerprint' +const configStoreNamePrefix = process.env.CONFIG_STORE_NAME_PREFIX || 'Fingerprint_Fastly_Compute_Proxy_Integration' build({ entryPoints: ['./src/index.ts'], @@ -9,5 +9,5 @@ build({ bundle: true, format: 'cjs', external: ['fastly:*'], - define: { 'process.env.CONFIG_STORE_NAME': `"${configStoreName}"` }, + define: { 'process.env.CONFIG_STORE_NAME_PREFIX': `"${configStoreNamePrefix}"` }, }).catch(() => process.exit(1)) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index c97f3c2..21bec02 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -2,7 +2,7 @@ import { createClient } from '../utils/createClient' import { activateVersion } from './activateVersion' import { deployPackage } from './deployPackage' -const CONFIG_STORE_NAME = process.env.CONFIG_STORE_NAME ?? 'Fingerprint' +const CONFIG_STORE_NAME_PREFIX = process.env.CONFIG_STORE_NAME_PREFIX ?? 'E2ETest' export async function createService(domain: string) { const client = createClient('service') @@ -69,7 +69,7 @@ async function createDomain(domain: string, serviceId: string) { } async function linkConfigStore(service_id: string, version_id: number, resource_id: string) { - const configStoreNameWithPrefix = `${CONFIG_STORE_NAME}_${service_id}` + const configStoreNameWithPrefix = `${CONFIG_STORE_NAME_PREFIX}_${service_id}` return createClient('resource').createResource({ service_id, version_id, @@ -80,7 +80,7 @@ async function linkConfigStore(service_id: string, version_id: number, resource_ async function createConfigStore(service_id: string) { console.log('Creating config store') - const configStoreNameWithPrefix = `${CONFIG_STORE_NAME}_${service_id}` + const configStoreNameWithPrefix = `${CONFIG_STORE_NAME_PREFIX}_${service_id}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore diff --git a/src/index.ts b/src/index.ts index f0358ff..fb36beb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,10 +23,10 @@ export async function handleRequest(event: FetchEvent): Promise { function getEnvObject(): IntegrationEnv { const serviceId = env('FASTLY_SERVICE_ID') - const configStoreName = process.env.CONFIG_STORE_NAME ?? 'Fingerprint' + const configStoreNamePrefix = process.env.CONFIG_STORE_NAME_PREFIX let config try { - config = new ConfigStore(`${configStoreName}_${serviceId}`) + config = new ConfigStore(`${configStoreNamePrefix}_${serviceId}`) } catch (e) { console.error(e) } From 24704c0f1231becad6e6c31f2131150d5e66a693 Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 31 Oct 2024 15:16:01 +0300 Subject: [PATCH 06/40] docs(readme): update default value for config store name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85f2f94..a35c07b 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,13 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint` with prefix of your Fastly Compute Service id. If you need to use a different config store name, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom worker package: +The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration` with prefix of your Fastly Compute Service id. If you need to use a different config store name, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom worker package: ```shell CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The outcome of artifact will look like this: `_` +The outcome of artifact will look like this: `_` For example: `Fingerprint_Fastly_Compute_Proxy_Integration_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. Or: `MyCustomConfigStoreName_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. From 029359a831b75847bca4f9161c4c23472834fe81 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 10:29:10 +0300 Subject: [PATCH 07/40] docs(readme): update typos and wordings Co-authored-by: Juraj Uhlar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a35c07b..3bbf8dc 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in Releases assumes the config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration` with prefix of your Fastly Compute Service id. If you need to use a different config store name, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom worker package: +The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom service package: ```shell CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build From d4d469f1890d67905970495cf60da05b9172f78b Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 10:30:58 +0300 Subject: [PATCH 08/40] docs(readme): update outcomes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3bbf8dc..03da23d 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The Fastly Compute package provided in releases assumes the Config store used by CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The outcome of artifact will look like this: `_` +The outcome of artifact will look like this: `_` For example: `Fingerprint_Fastly_Compute_Proxy_Integration_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. Or: `MyCustomConfigStoreName_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. From b94387882bd4d485733faa6cc712ee6e298d6e58 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 11:27:03 +0300 Subject: [PATCH 09/40] feat: move proxy secret to secret store --- .github/workflows/mock-e2e-pr.yml | 4 +-- README.md | 4 +-- build.ts | 4 +-- scripts/api/createService.ts | 52 +++++++++++++++++++++++------- scripts/utils/createClient.ts | 8 +++++ src/index.ts | 53 +++++++++++++++++++++---------- 6 files changed, 91 insertions(+), 34 deletions(-) diff --git a/.github/workflows/mock-e2e-pr.yml b/.github/workflows/mock-e2e-pr.yml index 8a09405..ad9c424 100644 --- a/.github/workflows/mock-e2e-pr.yml +++ b/.github/workflows/mock-e2e-pr.yml @@ -58,7 +58,7 @@ jobs: with: verbose: true env: - CONFIG_STORE_NAME_PREFIX: "E2ETest" + STORE_NAME_PREFIX: "E2ETest" - name: Deploy id: deploy env: @@ -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_PREFIX: "E2ETest" + STORE_NAME_PREFIX: "E2ETest" run: pnpm run ci - name: Wait for 60s shell: bash diff --git a/README.md b/README.md index 03da23d..da2f801 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom service package: +The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `STORE_NAME_PREFIX` environment variable and build a custom service package: ```shell -CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build +STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` The outcome of artifact will look like this: `_` diff --git a/build.ts b/build.ts index 980aa88..0071fee 100644 --- a/build.ts +++ b/build.ts @@ -1,7 +1,7 @@ import { build } from 'esbuild' // Load environment variables from process.env -const configStoreNamePrefix = process.env.CONFIG_STORE_NAME_PREFIX || 'Fingerprint_Fastly_Compute_Proxy_Integration' +const configStoreNamePrefix = process.env.STORE_NAME_PREFIX || 'Fingerprint_Fastly_Compute_Proxy_Integration' build({ entryPoints: ['./src/index.ts'], @@ -9,5 +9,5 @@ build({ bundle: true, format: 'cjs', external: ['fastly:*'], - define: { 'process.env.CONFIG_STORE_NAME_PREFIX': `"${configStoreNamePrefix}"` }, + define: { 'process.env.STORE_NAME_PREFIX': `"${configStoreNamePrefix}"` }, }).catch(() => process.exit(1)) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index 21bec02..820a841 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -2,7 +2,7 @@ import { createClient } from '../utils/createClient' import { activateVersion } from './activateVersion' import { deployPackage } from './deployPackage' -const CONFIG_STORE_NAME_PREFIX = process.env.CONFIG_STORE_NAME_PREFIX ?? 'E2ETest' +const STORE_NAME_PREFIX = process.env.STORE_NAME_PREFIX ?? 'E2ETest' export async function createService(domain: string) { const client = createClient('service') @@ -23,9 +23,17 @@ export async function createService(domain: string) { await createOrigin(createResponse.id, domain) const configStore = await createConfigStore(createResponse.id) console.log('config store created') + const secretStore = await createSecretStore(createResponse.id) + console.log('secret store created') + console.log('linking config store') - await linkConfigStore(createResponse.id, 1, configStore.id) + await linkStoreResource(createResponse.id, 1, configStore.id) console.log('config store linked') + + console.log('linking secret store') + await linkStoreResource(createResponse.id, 1, secretStore.id) + console.log('secret store linked') + console.log('deploying package') await deployPackage(createResponse.id, 1) console.log('package deployed') @@ -68,19 +76,46 @@ async function createDomain(domain: string, serviceId: string) { }) } -async function linkConfigStore(service_id: string, version_id: number, resource_id: string) { - const configStoreNameWithPrefix = `${CONFIG_STORE_NAME_PREFIX}_${service_id}` +async function linkStoreResource(service_id: string, version_id: number, resource_id: string) { + const storeNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` return createClient('resource').createResource({ service_id, version_id, resource_id, - name: configStoreNameWithPrefix, + name: storeNameWithPrefix, }) } +async function createSecretStore(service_id: string) { + console.log('Creating secret store') + const secretStoreNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` + const secretStoreClient = createClient('secretStore') + const secretStoreItemClient = createClient('secretStoreItem') + let secretStore + try { + secretStore = await secretStoreClient.createSecretStore({ + name: secretStoreNameWithPrefix, + }) + } catch (e) { + console.error('Could not create secret store', e) + const stores = await secretStoreClient.getSecretStores() + return stores.find((t: any) => t.name === secretStoreNameWithPrefix) + } + + await secretStoreItemClient.createSecret({ + store_id: secretStore.id, + secret: { + name: 'PROXY_SECRET', + secret: process.env.PROXY_SECRET ?? 'secret', + }, + }) + + return secretStore +} + async function createConfigStore(service_id: string) { console.log('Creating config store') - const configStoreNameWithPrefix = `${CONFIG_STORE_NAME_PREFIX}_${service_id}` + const configStoreNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore @@ -103,11 +138,6 @@ async function createConfigStore(service_id: string) { item_key: 'AGENT_SCRIPT_DOWNLOAD_PATH', item_value: process.env.AGENT_SCRIPT_DOWNLOAD_PATH ?? 'agent', }) - await configStoreItemClient.createConfigStoreItem({ - config_store_id: configStore.id, - item_key: 'PROXY_SECRET', - item_value: 'secret', - }) await configStoreItemClient.createConfigStoreItem({ config_store_id: configStore.id, item_key: 'OPEN_CLIENT_RESPONSE_ENABLED', diff --git a/scripts/utils/createClient.ts b/scripts/utils/createClient.ts index dd24a02..0ca8fbe 100644 --- a/scripts/utils/createClient.ts +++ b/scripts/utils/createClient.ts @@ -9,6 +9,8 @@ export type FastlyClientTypes = | 'configStoreItem' | 'backend' | 'resource' + | 'secretStore' + | 'secretStoreItem' export function createClient(api: FastlyClientTypes) { let client switch (api) { @@ -36,6 +38,12 @@ export function createClient(api: FastlyClientTypes) { case 'resource': client = new Fastly.ResourceApi() break + case 'secretStore': + client = new Fastly.SecretStoreApi() + break + case 'secretStoreItem': + client = new Fastly.SecretStoreItemApi() + break } Fastly.ApiClient.instance.authenticate(process.env.FASTLY_API_TOKEN) return client diff --git a/src/index.ts b/src/index.ts index fb36beb..0a72a73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,18 @@ /// import { handleReq } from './handler' -import { IntegrationEnv } from './env' +import { + agentScriptDownloadPathVarName, + getResultPathVarName, + IntegrationEnv, + openClientResponseVarName, + proxySecretVarName, +} from './env' import { ConfigStore } from 'fastly:config-store' import { returnHttpResponse } from './utils/returnHttpResponse' import { createFallbackErrorResponse } from './utils' import { setClientIp } from './utils/clientIp' import { env } from 'fastly:env' +import { SecretStore } from 'fastly:secret-store' addEventListener('fetch', (event) => event.respondWith(handleRequest(event))) @@ -13,7 +20,7 @@ export async function handleRequest(event: FetchEvent): Promise { setClientIp(event.client.address) try { const request = event.request - const envObj = getEnvObject() + const envObj = await getEnvObject() return handleReq(request, envObj).then(returnHttpResponse) } catch (e) { console.error(e) @@ -21,29 +28,41 @@ export async function handleRequest(event: FetchEvent): Promise { } } -function getEnvObject(): IntegrationEnv { +async function getEnvObject(): Promise { const serviceId = env('FASTLY_SERVICE_ID') - const configStoreNamePrefix = process.env.CONFIG_STORE_NAME_PREFIX - let config + const storeNamePrefix = process.env.STORE_NAME_PREFIX + const storeName = `${storeNamePrefix}_${serviceId}` + let configStore + let secretStore try { - config = new ConfigStore(`${configStoreNamePrefix}_${serviceId}`) + configStore = new ConfigStore(storeName) + secretStore = new SecretStore(storeName) } catch (e) { console.error(e) } - if (config == null) { - return { - AGENT_SCRIPT_DOWNLOAD_PATH: null, - GET_RESULT_PATH: null, - PROXY_SECRET: null, - OPEN_CLIENT_RESPONSE_ENABLED: 'false', + let config: IntegrationEnv = { + AGENT_SCRIPT_DOWNLOAD_PATH: null, + GET_RESULT_PATH: null, + PROXY_SECRET: null, + OPEN_CLIENT_RESPONSE_ENABLED: 'false', + } + + if (configStore != null) { + config = { + ...config, + AGENT_SCRIPT_DOWNLOAD_PATH: configStore.get(agentScriptDownloadPathVarName), + GET_RESULT_PATH: configStore.get(getResultPathVarName), + OPEN_CLIENT_RESPONSE_ENABLED: configStore.get(openClientResponseVarName), } } - return { - AGENT_SCRIPT_DOWNLOAD_PATH: config.get('AGENT_SCRIPT_DOWNLOAD_PATH'), - GET_RESULT_PATH: config.get('GET_RESULT_PATH'), - PROXY_SECRET: config.get('PROXY_SECRET'), - OPEN_CLIENT_RESPONSE_ENABLED: config.get('OPEN_CLIENT_RESPONSE_ENABLED'), + if (secretStore != null) { + config = { + ...config, + PROXY_SECRET: (await secretStore.get(proxySecretVarName))?.plaintext() ?? null, + } } + + return config } From 8ccbc747803e05080c83cdf2cd7a26f8243d6751 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 11:37:48 +0300 Subject: [PATCH 10/40] chore: update config store create step --- scripts/api/createService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index 820a841..0bd9914 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -94,7 +94,9 @@ async function createSecretStore(service_id: string) { let secretStore try { secretStore = await secretStoreClient.createSecretStore({ - name: secretStoreNameWithPrefix, + secret_store: { + name: secretStoreNameWithPrefix, + }, }) } catch (e) { console.error('Could not create secret store', e) From 849497497a73808b8b8d8a47daef5c58158b0618 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 11:50:20 +0300 Subject: [PATCH 11/40] chore: update secret store tests --- __mocks__/fastly:secret-store.js | 10 +++++++--- scripts/api/createService.ts | 2 +- test/handlers/ingressAPI.test.ts | 23 +++++++++++++++++------ test/handlers/statusPage.test.ts | 7 +++++-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/__mocks__/fastly:secret-store.js b/__mocks__/fastly:secret-store.js index a71acad..437766f 100644 --- a/__mocks__/fastly:secret-store.js +++ b/__mocks__/fastly:secret-store.js @@ -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) { diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index 0bd9914..5326779 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -105,7 +105,7 @@ async function createSecretStore(service_id: string) { } await secretStoreItemClient.createSecret({ - store_id: secretStore.id, + secret_store_id: secretStore.id, secret: { name: 'PROXY_SECRET', secret: process.env.PROXY_SECRET ?? 'secret', diff --git a/test/handlers/ingressAPI.test.ts b/test/handlers/ingressAPI.test.ts index d199cfd..0ab9913 100644 --- a/test/handlers/ingressAPI.test.ts +++ b/test/handlers/ingressAPI.test.ts @@ -3,9 +3,12 @@ import { ConfigStore } from 'fastly:config-store' import { makeRequest } from '../utils/makeRequest' import { handleRequest } from '../../src' import cookie from 'cookie' +import { SecretStore } from 'fastly:secret-store' +import { env } from 'fastly:env' describe('Browser Cache', () => { let requestHeaders: Headers + let storeName: string beforeAll(() => { jest.spyOn(globalThis, 'fetch').mockImplementation((request, init) => { @@ -14,9 +17,13 @@ describe('Browser Cache', () => { } return globalThis.fetch(request, init) }) + + const serviceId = env('FASTLY_SERVICE_ID') + const storeNamePrefix = process.env.STORE_NAME_PREFIX + storeName = `${storeNamePrefix}_${serviceId}` }) beforeEach(() => { - const config = new ConfigStore('Fingerprint') + const config = new ConfigStore(storeName) // @ts-ignore config.set('GET_RESULT_PATH', 'result') // Reset fetch spy calls between tests if needed @@ -44,6 +51,7 @@ describe('Browser Cache', () => { describe('Ingress', () => { let requestHeaders: Headers + let storeName: string beforeAll(() => { jest.spyOn(globalThis, 'fetch').mockImplementation((request, init) => { @@ -52,9 +60,12 @@ describe('Ingress', () => { } return globalThis.fetch(request, init) }) + const serviceId = env('FASTLY_SERVICE_ID') + const storeNamePrefix = process.env.STORE_NAME_PREFIX + storeName = `${storeNamePrefix}_${serviceId}` }) beforeEach(() => { - const config = new ConfigStore('Fingerprint') + const config = new ConfigStore(storeName) // @ts-ignore config.set('GET_RESULT_PATH', 'result') // Reset fetch spy calls between tests if needed @@ -104,9 +115,9 @@ describe('Ingress', () => { }) it('should add proxy integration headers if PROXY_SECRET is present', async () => { - const config = new ConfigStore('Fingerprint') + const secretStore = new SecretStore('Fingerprint') // @ts-ignore - config.set('PROXY_SECRET', 'secret') + secretStore.set('PROXY_SECRET', 'secret') const request = makeRequest(new URL('https://test/result'), { method: 'POST' }) await handleRequest(request) @@ -117,9 +128,9 @@ describe('Ingress', () => { }) it('should set client ip if request has header Fastly-Client-IP', async () => { - const config = new ConfigStore('Fingerprint') + const secretStore = new SecretStore('Fingerprint') // @ts-ignore - config.set('PROXY_SECRET', 'secret') + secretStore.set('PROXY_SECRET', 'secret') const request = makeRequest(new URL('https://test/result'), { method: 'POST', diff --git a/test/handlers/statusPage.test.ts b/test/handlers/statusPage.test.ts index 2ac1923..fcbc8e4 100644 --- a/test/handlers/statusPage.test.ts +++ b/test/handlers/statusPage.test.ts @@ -3,6 +3,7 @@ import { handleRequest } from '../../src' import { expect } from '@jest/globals' import { ConfigStore } from 'fastly:config-store' import packageJson from '../../package.json' +import { SecretStore } from 'fastly:secret-store' describe('Status Page', () => { it('should return text/html with status 200', async () => { @@ -40,10 +41,12 @@ describe('Status Page', () => { // @ts-ignore config.set('GET_RESULT_PATH', 'result') // @ts-ignore - config.set('PROXY_SECRET', 'secret') - // @ts-ignore config.set('OPEN_CLIENT_RESPONSE_ENABLED', 'true') + const secretStore = new SecretStore('Fingerprint') + // @ts-ignore + secretStore.set('PROXY_SECRET', 'secret') + const request = makeRequest(new URL('https://test/status')) const response = await handleRequest(request) From 10aafd6d12df518adbd668f0b44510d9877b6518 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 4 Nov 2024 11:57:16 +0300 Subject: [PATCH 12/40] chore: update secret store ci params --- scripts/api/createService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index 5326779..0bd9914 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -105,7 +105,7 @@ async function createSecretStore(service_id: string) { } await secretStoreItemClient.createSecret({ - secret_store_id: secretStore.id, + store_id: secretStore.id, secret: { name: 'PROXY_SECRET', secret: process.env.PROXY_SECRET ?? 'secret', From d63a4eaf733b3482afa8cd5fc7fb146f8c14789d Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 5 Nov 2024 13:42:10 +0300 Subject: [PATCH 13/40] chore: update stores with prefix --- README.md | 8 +++--- package.json | 2 +- pnpm-lock.yaml | 34 ++++++++++++++++------- scripts/api/createService.ts | 19 ++++++++----- src/env.ts | 13 ++++++--- src/handlers/handleIngressAPI.ts | 2 +- src/handlers/handleStatusPage.ts | 13 +++++++++ src/index.ts | 37 ++++++++------------------ src/utils/processOpenClientResponse.ts | 16 +++++------ 9 files changed, 83 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index da2f801..3140620 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,15 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `STORE_NAME_PREFIX` environment variable and build a custom service package: +The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `STORE_NAME_PREFIX` environment variable and build a custom service package: ```shell STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The outcome of artifact will look like this: `_` -For example: `Fingerprint_Fastly_Compute_Proxy_Integration_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. -Or: `MyCustomConfigStoreName_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. +The outcome of artifact will look like this: `_ConfigStore_` +For example: `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. +Or: `MyCustomConfigStoreName_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. ## Feedback and support diff --git a/package.json b/package.json index 915a344..782bb51 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f49f22..8c59a80 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -70,8 +70,8 @@ importers: specifier: ^0.24.0 version: 0.24.0 fastly: - specifier: 7.3.0 - version: 7.3.0 + specifier: ^7.10.0 + version: 7.10.0 fs: specifier: 0.0.1-security version: 0.0.1-security @@ -1314,6 +1314,9 @@ packages: '@types/node@22.7.9': resolution: {integrity: sha512-jrTfRC7FM6nChvU7X2KqcrgquofrWLFDeYC1hKfwNWomVvrn7JIksqf344WN2X/y8xrgqBd2dJATZV4GbatBfg==} + '@types/node@22.9.0': + resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} + '@types/pako@2.0.3': resolution: {integrity: sha512-bq0hMV9opAcrmE0Byyo0fY3Ew4tgOevJmQ9grUhpXQhYfyLJ1Kqg3P33JT5fdbT2AjeAjR51zqqVjAL/HMkx7Q==} @@ -1460,6 +1463,11 @@ packages: engines: {node: '>=0.4.0'} hasBin: true + acorn@8.14.0: + resolution: {integrity: sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==} + engines: {node: '>=0.4.0'} + hasBin: true + ajv-keywords@3.5.2: resolution: {integrity: sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==} peerDependencies: @@ -1986,8 +1994,8 @@ packages: fast-safe-stringify@2.1.1: resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} - fastly@7.3.0: - resolution: {integrity: sha512-drYeTPEruVWHMTKn6e2s4pSf09MLYKYkKDqZHyOpbzIMadt8y93Kvi3u/fdLS8EuQA5j81ChxY0C03ozWLK29g==} + fastly@7.10.0: + resolution: {integrity: sha512-aLN6iVCe3AUwURrvGtv88UJt5HMnApHq5Wan77w5OD91SF84U4/q8oJ8rVk3I5y/zyhRdkW+hGyBjwFFgJtyFA==} fastq@1.17.1: resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} @@ -4601,6 +4609,10 @@ snapshots: dependencies: undici-types: 6.19.8 + '@types/node@22.9.0': + dependencies: + undici-types: 6.19.8 + '@types/pako@2.0.3': {} '@types/semver@7.5.8': {} @@ -4781,9 +4793,9 @@ snapshots: '@xtuc/long@4.2.2': {} - acorn-import-attributes@1.9.5(acorn@8.13.0): + acorn-import-attributes@1.9.5(acorn@8.14.0): dependencies: - acorn: 8.13.0 + acorn: 8.14.0 acorn-jsx@5.3.2(acorn@8.13.0): dependencies: @@ -4795,6 +4807,8 @@ snapshots: acorn@8.13.0: {} + acorn@8.14.0: {} + ajv-keywords@3.5.2(ajv@6.12.6): dependencies: ajv: 6.12.6 @@ -5384,7 +5398,7 @@ snapshots: fast-safe-stringify@2.1.1: {} - fastly@7.3.0: + fastly@7.10.0: dependencies: superagent: 6.1.0 transitivePeerDependencies: @@ -5947,7 +5961,7 @@ snapshots: jest-worker@27.5.1: dependencies: - '@types/node': 22.7.9 + '@types/node': 22.9.0 merge-stream: 2.0.0 supports-color: 8.1.1 @@ -6649,8 +6663,8 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@webassemblyjs/wasm-edit': 1.12.1 '@webassemblyjs/wasm-parser': 1.12.1 - acorn: 8.13.0 - acorn-import-attributes: 1.9.5(acorn@8.13.0) + acorn: 8.14.0 + acorn-import-attributes: 1.9.5(acorn@8.14.0) browserslist: 4.24.2 chrome-trace-event: 1.0.4 enhanced-resolve: 5.17.1 diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index 0bd9914..c8ccf1e 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -31,7 +31,7 @@ export async function createService(domain: string) { console.log('config store linked') console.log('linking secret store') - await linkStoreResource(createResponse.id, 1, secretStore.id) + await linkStoreResource(createResponse.id, 1, secretStore.id, 'secret') console.log('secret store linked') console.log('deploying package') @@ -76,8 +76,13 @@ async function createDomain(domain: string, serviceId: string) { }) } -async function linkStoreResource(service_id: string, version_id: number, resource_id: string) { - const storeNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` +async function linkStoreResource( + service_id: string, + version_id: number, + resource_id: string, + type: 'secret' | 'config' = 'config' +) { + const storeNameWithPrefix = `${STORE_NAME_PREFIX}_${type === 'config' ? 'ConfigStore' : 'SecretStore'}_${service_id}` return createClient('resource').createResource({ service_id, version_id, @@ -88,7 +93,7 @@ async function linkStoreResource(service_id: string, version_id: number, resourc async function createSecretStore(service_id: string) { console.log('Creating secret store') - const secretStoreNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` + const secretStoreNameWithPrefix = `${STORE_NAME_PREFIX}_SecretStore_${service_id}` const secretStoreClient = createClient('secretStore') const secretStoreItemClient = createClient('secretStoreItem') let secretStore @@ -105,11 +110,11 @@ async function createSecretStore(service_id: string) { } await secretStoreItemClient.createSecret({ - store_id: secretStore.id, secret: { name: 'PROXY_SECRET', - secret: process.env.PROXY_SECRET ?? 'secret', + secret: btoa(process.env.PROXY_SECRET ?? 'secret'), }, + store_id: secretStore.id, }) return secretStore @@ -117,7 +122,7 @@ async function createSecretStore(service_id: string) { async function createConfigStore(service_id: string) { console.log('Creating config store') - const configStoreNameWithPrefix = `${STORE_NAME_PREFIX}_${service_id}` + const configStoreNameWithPrefix = `${STORE_NAME_PREFIX}_ConfigStore_${service_id}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore diff --git a/src/env.ts b/src/env.ts index 2547d1e..12f372f 100644 --- a/src/env.ts +++ b/src/env.ts @@ -3,6 +3,7 @@ export type IntegrationEnv = { GET_RESULT_PATH: string | null PROXY_SECRET: string | null OPEN_CLIENT_RESPONSE_ENABLED: string | null + DECRYPTION_KEY: string | null } const Defaults: IntegrationEnv = { @@ -10,11 +11,9 @@ const Defaults: IntegrationEnv = { GET_RESULT_PATH: 'result', PROXY_SECRET: null, OPEN_CLIENT_RESPONSE_ENABLED: 'false', + DECRYPTION_KEY: null, } -export const FingerprintSecretStoreName = 'FingerprintSecrets' -export const FingerprintDecryptionKeyName = 'decryptionKey' - function getVarOrDefault( variable: keyof IntegrationEnv, defaults: IntegrationEnv @@ -52,6 +51,10 @@ export const proxySecretVarName = 'PROXY_SECRET' const getProxySecretVar = getVarOrDefault(proxySecretVarName, Defaults) export const isProxySecretSet = isVarSet(proxySecretVarName) +export const decryptionKeyVarName = 'DECRYPTION_KEY' +const getDecryptionKeyVar = getVarOrDefault(decryptionKeyVarName, Defaults) +export const isDecryptionKeySet = isVarSet(decryptionKeyVarName) + export const openClientResponseVarName = 'OPEN_CLIENT_RESPONSE_ENABLED' export const isOpenClientResponseSet = isVarSet(openClientResponseVarName) @@ -62,6 +65,10 @@ export function getProxySecret(env: IntegrationEnv): string | null { return getProxySecretVar(env) } +export function getDecryptionKey(env: IntegrationEnv): string | null { + return getDecryptionKeyVar(env) +} + export function getStatusPagePath(): string { return `/status` } diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index 1f47cad..e523f94 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -34,7 +34,7 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) const responseBody = await response.text() - processOpenClientResponse(responseBody, response).catch((e) => + processOpenClientResponse(responseBody, response, env).catch((e) => console.error('failed when processing open client response', e) ) diff --git a/src/handlers/handleStatusPage.ts b/src/handlers/handleStatusPage.ts index d45626b..718454e 100644 --- a/src/handlers/handleStatusPage.ts +++ b/src/handlers/handleStatusPage.ts @@ -8,6 +8,9 @@ import { proxySecretVarName, isOpenClientResponseSet, openClientResponseVarName, + isDecryptionKeySet, + decryptionKeyVarName, + isOpenClientResponseEnabled, } from '../env' import packageJson from '../../package.json' @@ -52,6 +55,7 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { const isGetResultPathAvailable = isGetResultPathSet(env) const isProxySecretAvailable = isProxySecretSet(env) const isOpenClientResponseVarSet = isOpenClientResponseSet(env) + const isDecryptionKeyVarSet = isDecryptionKeySet(env) const isAllVarsAvailable = isScriptDownloadPathAvailable && isGetResultPathAvailable && isProxySecretAvailable let result = '' @@ -99,6 +103,15 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { ` } + if (isOpenClientResponseEnabled(env) && !isDecryptionKeyVarSet) { + result += ` + + ⚠️ ${decryptionKeyVarName} optional environment variable is not set
+ This environment variable is optional; your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning. +
+ ` + } + return result } diff --git a/src/index.ts b/src/index.ts index 0a72a73..e1ebb70 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { handleReq } from './handler' import { agentScriptDownloadPathVarName, + decryptionKeyVarName, getResultPathVarName, IntegrationEnv, openClientResponseVarName, @@ -31,38 +32,22 @@ export async function handleRequest(event: FetchEvent): Promise { async function getEnvObject(): Promise { const serviceId = env('FASTLY_SERVICE_ID') const storeNamePrefix = process.env.STORE_NAME_PREFIX - const storeName = `${storeNamePrefix}_${serviceId}` + const configStoreName = `${storeNamePrefix}_ConfigStore_${serviceId}` + const secretStoreName = `${storeNamePrefix}_SecretStore_${serviceId}` let configStore let secretStore try { - configStore = new ConfigStore(storeName) - secretStore = new SecretStore(storeName) + configStore = new ConfigStore(configStoreName) + secretStore = new SecretStore(secretStoreName) } catch (e) { console.error(e) } - let config: IntegrationEnv = { - AGENT_SCRIPT_DOWNLOAD_PATH: null, - GET_RESULT_PATH: null, - PROXY_SECRET: null, - OPEN_CLIENT_RESPONSE_ENABLED: 'false', + return { + AGENT_SCRIPT_DOWNLOAD_PATH: configStore?.get(agentScriptDownloadPathVarName) ?? null, + GET_RESULT_PATH: configStore?.get(getResultPathVarName) ?? null, + OPEN_CLIENT_RESPONSE_ENABLED: configStore?.get(openClientResponseVarName) ?? 'false', + PROXY_SECRET: (await secretStore?.get(proxySecretVarName))?.plaintext() ?? null, + DECRYPTION_KEY: (await secretStore?.get(decryptionKeyVarName))?.plaintext() ?? null, } - - if (configStore != null) { - config = { - ...config, - AGENT_SCRIPT_DOWNLOAD_PATH: configStore.get(agentScriptDownloadPathVarName), - GET_RESULT_PATH: configStore.get(getResultPathVarName), - OPEN_CLIENT_RESPONSE_ENABLED: configStore.get(openClientResponseVarName), - } - } - - if (secretStore != null) { - config = { - ...config, - PROXY_SECRET: (await secretStore.get(proxySecretVarName))?.plaintext() ?? null, - } - } - - return config } diff --git a/src/utils/processOpenClientResponse.ts b/src/utils/processOpenClientResponse.ts index 810bd4f..191ab16 100644 --- a/src/utils/processOpenClientResponse.ts +++ b/src/utils/processOpenClientResponse.ts @@ -1,20 +1,18 @@ import { plugins } from './registerPlugin' import { unsealData } from './unsealData' -import { SecretStore } from 'fastly:secret-store' -import { FingerprintDecryptionKeyName, FingerprintSecretStoreName } from '../env' import { cloneFastlyResponse } from './cloneFastlyResponse' +import { getDecryptionKey, IntegrationEnv } from '../env' type FingerprintSealedIngressResponseBody = { sealedResult: string } -async function getDecryptionKey() { - const secretStore = new SecretStore(FingerprintSecretStoreName) - return secretStore.get(FingerprintDecryptionKeyName).then((v) => v?.plaintext()) -} - -export async function processOpenClientResponse(body: string | undefined, response: Response): Promise { - const decryptionKey = await getDecryptionKey() +export async function processOpenClientResponse( + body: string | undefined, + response: Response, + env: IntegrationEnv +): Promise { + const decryptionKey = getDecryptionKey(env) if (!decryptionKey) { throw new Error('Decryption key not found in secret store') } From cd695cf1baf45bc6d576ddd05929c9e2be3a282e Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 5 Nov 2024 13:44:16 +0300 Subject: [PATCH 14/40] docs(readme): update outcome explanation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3140620..872127b 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The Fastly Compute package provided in releases assumes the Config store used by STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The outcome of artifact will look like this: `_ConfigStore_` +The code inside the built package will expect a config store name like: `_ConfigStore_` For example: `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. Or: `MyCustomConfigStoreName_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. From 791f8ccbc4c4abb93347c1506149d177042a7558 Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Tue, 5 Nov 2024 10:52:34 +0000 Subject: [PATCH 15/40] docs: improve readme --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 03da23d..21ee600 100644 --- a/README.md +++ b/README.md @@ -33,19 +33,20 @@ The Fastly Compute Proxy Integration is responsible for proxying identification 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 Fastly Compute service](https://docs.fastly.com/en/guides/working-with-compute-services#creating-a-new-compute-service) in your Fastly account for the proxy integration. -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: +3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values: | 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. | + | 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`. | -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. +4. 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. +5. Upload package to your Fastly Compute Service's **Package**. +6. 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' @@ -66,15 +67,13 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc ### Using a custom config store name -The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can pass the name to the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom service package: +The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can use the `CONFIG_STORE_NAME_PREFIX` environment variable and build a custom service package: ```shell CONFIG_STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The outcome of artifact will look like this: `_` -For example: `Fingerprint_Fastly_Compute_Proxy_Integration_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. -Or: `MyCustomConfigStoreName_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. +The code inside the built package will expect a config store name like `MyCustomStoreNamePrefix_`. ## Feedback and support From b01050c5159f142361a028c3ad4809da6ad1ac01 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 5 Nov 2024 11:03:29 +0000 Subject: [PATCH 16/40] chore(release): 0.2.0-rc.1 ## [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)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfb952..3962dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [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) diff --git a/package.json b/package.json index 915a344..718000f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fingerprint-pro-fastly-compute-proxy-integration", - "version": "0.1.0", + "version": "0.2.0-rc.1", "engines": { "node": ">=20" }, From 11189824d3b16e180d273b1079a705321092351b Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 5 Nov 2024 14:58:49 +0300 Subject: [PATCH 17/40] docs(readme): add secret store section --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d284d22..908f47b 100644 --- a/README.md +++ b/README.md @@ -33,20 +33,24 @@ The Fastly Compute Proxy Integration is responsible for proxying identification 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 Fastly Compute service](https://docs.fastly.com/en/guides/working-with-compute-services#creating-a-new-compute-service) in your Fastly account for the proxy integration. -3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values: +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_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: | 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. | - | 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`. | + +3. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) in your Fastly account named exactly `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: + + | Key | Example Value | Description | + |---------------|-----------------------|------------------------------------------------| + | PROXY_SECRET | 6XI9CLf3C9oHSB12TTaI | Fingerprint proxy secret generated in Step 1. | 4. 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. 5. Upload package to your Fastly Compute Service's **Package**. -6. 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. +6. 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. ```javascript import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro' @@ -65,7 +69,7 @@ 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-proxy-integration#step-4-configure-the-fingerprint-client-agent-to-use-your-service) in our documentation for more details. -### Using a custom config store name +### Using a custom store name The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can use the `STORE_NAME_PREFIX` environment variable and build a custom service package: @@ -73,7 +77,14 @@ The Fastly Compute package provided in releases assumes the Config store used by STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The code inside the built package will expect a config store name like `MyCustomStoreNamePrefix_ConfigStore_`. +The code inside the built package will expect a config store name like: `_ConfigStore_` +For example: `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. +Or: `MyCustomConfigStoreName_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. + +Same naming convention also applies for your Secret store,: + +For example: `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. +Or: `MyCustomConfigStoreName_SecretStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. ## Feedback and support From f37c13c9a941c9cad791c72f50ac134fd0ea7729 Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 5 Nov 2024 15:16:37 +0300 Subject: [PATCH 18/40] docs(readme): update store naming section --- README.md | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 908f47b..2f5b459 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,15 @@ This is a quick overview of the installation setup. For detailed step-by-step in 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 Compute Service](https://docs.fastly.com/en/guides/working-with-compute-services#creating-a-new-compute-service) in your Fastly account, with Empty Service option. + 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_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: - | Key | Example Value | Description | - |------------------------------|----------------------|---------------------------------------------------------------------------------------------| - | 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. | + | 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_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`. | 3. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) in your Fastly account named exactly `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: @@ -69,22 +71,26 @@ 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-proxy-integration#step-4-configure-the-fingerprint-client-agent-to-use-your-service) in our documentation for more details. -### Using a custom store name +### Using a Custom Store Name for ConfigStore and SecretStore + +By default, the Fastly Compute package provided in releases assumes that the integration uses ConfigStore and SecretStore names with the prefix `Fingerprint_Fastly_Compute_Proxy_Integration`. Specifically: + +**ConfigStore**: Named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_` +**SecretStore**: Named `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_` +Here, `` represents your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). -The Fastly Compute package provided in releases assumes the Config store used by the integration is named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). If you need to use a different config store name prefix, you can use the `STORE_NAME_PREFIX` environment variable and build a custom service package: +If you need to customize the naming prefix for both the ConfigStore and SecretStore, set the `STORE_NAME_PREFIX` environment variable and build a custom service package: -```shell +```shell= STORE_NAME_PREFIX=MyCustomStoreNamePrefix pnpm run build ``` -The code inside the built package will expect a config store name like: `_ConfigStore_` -For example: `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. -Or: `MyCustomConfigStoreName_ConfigStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. +After setting `STORE_NAME_PREFIX` and building the package, the following store names will be used: -Same naming convention also applies for your Secret store,: +**ConfigStore**: `MyCustomStoreNamePrefix_ConfigStore_` +**SecretStore**: `MyCustomStoreNamePrefix_SecretStore_` -For example: `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_MxLpeV9YSRbQKxlGpCVnD5` if you use the artifact in the release. -Or: `MyCustomConfigStoreName_SecretStore_MxLpeV9YSRbQKxlGpCVnD5` if you build your own artifact with a custom config store name. +This customization allows you to align store names with your organizational conventions or project requirements. ## Feedback and support From c9976665159bd314478750b914d958251e3930a9 Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Tue, 5 Nov 2024 12:34:44 +0000 Subject: [PATCH 19/40] docs: clean up readme --- README.md | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 2f5b459..a88afb5 100644 --- a/README.md +++ b/README.md @@ -34,25 +34,25 @@ This is a quick overview of the installation setup. For detailed step-by-step in 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 Compute Service](https://docs.fastly.com/en/guides/working-with-compute-services#creating-a-new-compute-service) in your Fastly account, with Empty Service option. +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. -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_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: +3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: - | 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_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`. | + | 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_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`. | -3. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) in your Fastly account named exactly `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: +4. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_`, 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. | + | Key | Example Value | Description | + | ------------ | -------------------- | --------------------------------------------- | + | PROXY_SECRET | 6XI9CLf3C9oHSB12TTaI | Fingerprint proxy secret generated in Step 1. | -4. 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. -5. Upload package to your Fastly Compute Service's **Package**. -6. 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. +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' @@ -71,26 +71,24 @@ 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-proxy-integration#step-4-configure-the-fingerprint-client-agent-to-use-your-service) in our documentation for more details. -### Using a Custom Store Name for ConfigStore and SecretStore +### Using custom store names -By default, the Fastly Compute package provided in releases assumes that the integration uses ConfigStore and SecretStore names with the prefix `Fingerprint_Fastly_Compute_Proxy_Integration`. Specifically: +By default, the service package provided in releases assumes the following names for the Config store and Secret Store: -**ConfigStore**: Named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_` -**SecretStore**: Named `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_` -Here, `` represents your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). +* `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_` +* `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_` -If you need to customize the naming prefix for both the ConfigStore and SecretStore, set the `STORE_NAME_PREFIX` environment variable and build a custom service package: +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=MyCustomStoreNamePrefix pnpm run build +STORE_NAME_PREFIX=CustomName pnpm run build ``` -After setting `STORE_NAME_PREFIX` and building the package, the following store names will be used: +Your custom built package will then use your prefix in config store names like: -**ConfigStore**: `MyCustomStoreNamePrefix_ConfigStore_` -**SecretStore**: `MyCustomStoreNamePrefix_SecretStore_` +* `CustomName_ConfigStore_` +* `CustomName_SecretStore_` -This customization allows you to align store names with your organizational conventions or project requirements. ## Feedback and support From 2a71fcd4d0b45f43ede9fd3bfd1d67604eece929 Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Tue, 5 Nov 2024 12:38:23 +0000 Subject: [PATCH 20/40] docs: clean up readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a88afb5..be47eb3 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This is a quick overview of the installation setup. For detailed step-by-step in 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. -3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). And add the following values: +3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values: | Key | Example Value | Description | | ---------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -84,7 +84,7 @@ To use a custom name prefix for both stores, use the `STORE_NAME_PREFIX` environ STORE_NAME_PREFIX=CustomName pnpm run build ``` -Your custom built package will then use your prefix in config store names like: +Your custom built package in `pkg/package.tar.gz` will use your custom prefix in store names like: * `CustomName_ConfigStore_` * `CustomName_SecretStore_` From e9963545ae6be1fa44e2fa41ef74306067e6a75e Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 7 Nov 2024 11:35:53 +0300 Subject: [PATCH 21/40] feat: show all configurations on status page --- src/env.ts | 3 +- src/handlers/handleStatusPage.ts | 99 +++++++++++++++++--------------- src/index.ts | 2 +- test/handlers/statusPage.test.ts | 39 ++++++++++--- 4 files changed, 86 insertions(+), 57 deletions(-) diff --git a/src/env.ts b/src/env.ts index 12f372f..b25e1ce 100644 --- a/src/env.ts +++ b/src/env.ts @@ -56,7 +56,8 @@ const getDecryptionKeyVar = getVarOrDefault(decryptionKeyVarName, Defaults) export const isDecryptionKeySet = isVarSet(decryptionKeyVarName) export const openClientResponseVarName = 'OPEN_CLIENT_RESPONSE_ENABLED' -export const isOpenClientResponseSet = isVarSet(openClientResponseVarName) +export const isOpenClientResponseSet = (env: IntegrationEnv) => + env.OPEN_CLIENT_RESPONSE_ENABLED === 'true' || env.OPEN_CLIENT_RESPONSE_ENABLED === 'false' export const isOpenClientResponseEnabled = (env: IntegrationEnv) => env[openClientResponseVarName]?.toLowerCase() === 'true' diff --git a/src/handlers/handleStatusPage.ts b/src/handlers/handleStatusPage.ts index 718454e..61e0300 100644 --- a/src/handlers/handleStatusPage.ts +++ b/src/handlers/handleStatusPage.ts @@ -8,9 +8,9 @@ import { proxySecretVarName, isOpenClientResponseSet, openClientResponseVarName, - isDecryptionKeySet, decryptionKeyVarName, isOpenClientResponseEnabled, + isDecryptionKeySet, } from '../env' import packageJson from '../../package.json' @@ -50,64 +50,69 @@ function createContactInformationElement(): string { ` } +type ConfigurationStatus = { + label: string + check: boolean + required: boolean + errorMessage?: string + warningMessage?: string + value?: string | null +} function createEnvVarsInformationElement(env: IntegrationEnv): string { - const isScriptDownloadPathAvailable = isScriptDownloadPathSet(env) - const isGetResultPathAvailable = isGetResultPathSet(env) - const isProxySecretAvailable = isProxySecretSet(env) - const isOpenClientResponseVarSet = isOpenClientResponseSet(env) - const isDecryptionKeyVarSet = isDecryptionKeySet(env) - const isAllVarsAvailable = isScriptDownloadPathAvailable && isGetResultPathAvailable && isProxySecretAvailable + const incorrectConfigurationMessage = 'Your integration is not working correctly.' + const configurations: ConfigurationStatus[] = [ + { + label: agentScriptDownloadPathVarName, + check: isScriptDownloadPathSet(env), + required: true, + errorMessage: incorrectConfigurationMessage, + }, + { + label: getResultPathVarName, + check: isGetResultPathSet(env), + required: true, + errorMessage: incorrectConfigurationMessage, + }, + { + label: proxySecretVarName, + check: isProxySecretSet(env), + required: true, + errorMessage: incorrectConfigurationMessage, + }, + { + label: decryptionKeyVarName, + check: isDecryptionKeySet(env), + required: isOpenClientResponseEnabled(env), + errorMessage: incorrectConfigurationMessage, + }, + { + label: openClientResponseVarName, + check: isOpenClientResponseSet(env), + required: false, + warningMessage: + "Your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning.", + }, + ] + + const isAllVarsAvailable = configurations.filter((t) => t.required && !t.check).length === 0 let result = '' - if (!isAllVarsAvailable) { + if (isAllVarsAvailable) { result += ` - The following environment variables are not defined. Please reach out our support team. - - ` - if (!isScriptDownloadPathAvailable) { - result += ` - - ⚠️ ${agentScriptDownloadPathVarName} is not set - - ` - } - if (!isGetResultPathAvailable) { - result += ` - - ⚠️ ${getResultPathVarName} is not set - - ` - } - if (!isProxySecretAvailable) { - result += ` - - ⚠️ ${proxySecretVarName} is not set - - ` - } - } else { - result += ` - - ✅ All required environment variables are set + ✅ All required configurations are set ` } - if (!isOpenClientResponseVarSet) { - result += ` - - ⚠️ ${openClientResponseVarName} optional environment variable is not set
- This environment variable is optional; your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning. -
- ` - } + result += `Your integration’s configuration values` - if (isOpenClientResponseEnabled(env) && !isDecryptionKeyVarSet) { + for (const configuration of configurations) { result += ` - ⚠️ ${decryptionKeyVarName} optional environment variable is not set
- This environment variable is optional; your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning. + ${configuration.check ? '✅' : '⚠️'} ${configuration.label} (${configuration.required ? 'REQUIRED' : 'OPTIONAL'}) is${!configuration.check ? ' not ' : ' '}set + ${configuration.required && !configuration.check && configuration.errorMessage ? `${configuration.errorMessage}` : ''} + ${!configuration.required && !configuration.check && configuration.warningMessage ? `${configuration.warningMessage}` : ''}
` } diff --git a/src/index.ts b/src/index.ts index e1ebb70..5eeade1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,7 @@ async function getEnvObject(): Promise { return { AGENT_SCRIPT_DOWNLOAD_PATH: configStore?.get(agentScriptDownloadPathVarName) ?? null, GET_RESULT_PATH: configStore?.get(getResultPathVarName) ?? null, - OPEN_CLIENT_RESPONSE_ENABLED: configStore?.get(openClientResponseVarName) ?? 'false', + OPEN_CLIENT_RESPONSE_ENABLED: configStore?.get(openClientResponseVarName) ?? null, PROXY_SECRET: (await secretStore?.get(proxySecretVarName))?.plaintext() ?? null, DECRYPTION_KEY: (await secretStore?.get(decryptionKeyVarName))?.plaintext() ?? null, } diff --git a/test/handlers/statusPage.test.ts b/test/handlers/statusPage.test.ts index fcbc8e4..4b20ae4 100644 --- a/test/handlers/statusPage.test.ts +++ b/test/handlers/statusPage.test.ts @@ -4,6 +4,13 @@ import { expect } from '@jest/globals' import { ConfigStore } from 'fastly:config-store' import packageJson from '../../package.json' import { SecretStore } from 'fastly:secret-store' +import { + agentScriptDownloadPathVarName, + decryptionKeyVarName, + getResultPathVarName, + openClientResponseVarName, + proxySecretVarName, +} from '../../src/env' describe('Status Page', () => { it('should return text/html with status 200', async () => { @@ -14,24 +21,37 @@ describe('Status Page', () => { expect(response.headers.get('Content-Type')).toBe('text/html') }) - it('should show warning for undefined variables', async () => { + it('should show error for undefined required configurations', async () => { const config = new ConfigStore('Fingerprint') + const secret = new SecretStore('Fingerprint') // @ts-ignore - config.set('GET_RESULT_PATH', 'result') + config.set(getResultPathVarName, null) + // @ts-ignore + config.set(agentScriptDownloadPathVarName, null) + // @ts-ignore + config.set(openClientResponseVarName, 'true') // @ts-ignore - config.set('PROXY_SECRET', 'secret') + secret.set(proxySecretVarName, null) + // @ts-ignore + secret.set(decryptionKeyVarName, null) const request = makeRequest(new URL('https://test/status')) const response = await handleRequest(request) const responseText = await response.text() - const isAllSet = responseText.includes('All environment variables are set') - const agentDownloadScriptPathWarning = responseText.includes( - 'AGENT_SCRIPT_DOWNLOAD_PATH is not set' + const isAllSet = responseText.includes('All required configurations are set') + const agentDownloadScriptPathError = responseText.includes( + 'AGENT_SCRIPT_DOWNLOAD_PATH (REQUIRED) is not set' ) + const resultPathError = responseText.includes('GET_RESULT_PATH (REQUIRED) is not set') + const proxySecretError = responseText.includes('PROXY_SECRET (REQUIRED) is not set') + const decryptionKeyError = responseText.includes('DECRYPTION_KEY (REQUIRED) is not set') expect(isAllSet).toBe(false) - expect(agentDownloadScriptPathWarning).toBe(true) + expect(agentDownloadScriptPathError).toBe(true) + expect(resultPathError).toBe(true) + expect(proxySecretError).toBe(true) + expect(decryptionKeyError).toBe(true) }) it('should show correctly setup env', async () => { @@ -46,12 +66,15 @@ describe('Status Page', () => { const secretStore = new SecretStore('Fingerprint') // @ts-ignore secretStore.set('PROXY_SECRET', 'secret') + // @ts-ignore + secretStore.set('DECRYPTION_KEY', 'secret') const request = makeRequest(new URL('https://test/status')) const response = await handleRequest(request) const responseText = await response.text() - const isAllSet = responseText.includes('All required environment variables are set') + const isAllSet = responseText.includes('All required configurations are set') + console.log(responseText) expect(isAllSet).toBe(true) }) From d49fb3781a4e348d39f8d2e515814d50a7d754f7 Mon Sep 17 00:00:00 2001 From: Orkun Date: Thu, 7 Nov 2024 12:24:28 +0300 Subject: [PATCH 22/40] chore: update wordings in status page --- src/handlers/handleStatusPage.ts | 4 ++-- test/handlers/statusPage.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/handlers/handleStatusPage.ts b/src/handlers/handleStatusPage.ts index 61e0300..51ba75b 100644 --- a/src/handlers/handleStatusPage.ts +++ b/src/handlers/handleStatusPage.ts @@ -100,12 +100,12 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { if (isAllVarsAvailable) { result += ` - ✅ All required configurations are set + ✅ All required configuration values are set ` } - result += `Your integration’s configuration values` + result += `Your integration’s configuration values:` for (const configuration of configurations) { result += ` diff --git a/test/handlers/statusPage.test.ts b/test/handlers/statusPage.test.ts index 4b20ae4..6d8097b 100644 --- a/test/handlers/statusPage.test.ts +++ b/test/handlers/statusPage.test.ts @@ -73,7 +73,7 @@ describe('Status Page', () => { const response = await handleRequest(request) const responseText = await response.text() - const isAllSet = responseText.includes('All required configurations are set') + const isAllSet = responseText.includes('All required configuration values are set') console.log(responseText) expect(isAllSet).toBe(true) From 6a39edb4cb8d1abd9a973cd50b4d6827febea0d0 Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 10:19:54 +0300 Subject: [PATCH 23/40] refactor: update status page --- src/handlers/handleStatusPage.ts | 30 ++++++++++++++---------------- test/handlers/statusPage.test.ts | 1 - 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/handlers/handleStatusPage.ts b/src/handlers/handleStatusPage.ts index 51ba75b..7cd0359 100644 --- a/src/handlers/handleStatusPage.ts +++ b/src/handlers/handleStatusPage.ts @@ -52,10 +52,9 @@ function createContactInformationElement(): string { type ConfigurationStatus = { label: string - check: boolean + isSet: boolean required: boolean - errorMessage?: string - warningMessage?: string + message?: string value?: string | null } function createEnvVarsInformationElement(env: IntegrationEnv): string { @@ -63,38 +62,38 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { const configurations: ConfigurationStatus[] = [ { label: agentScriptDownloadPathVarName, - check: isScriptDownloadPathSet(env), + isSet: isScriptDownloadPathSet(env), required: true, - errorMessage: incorrectConfigurationMessage, + message: incorrectConfigurationMessage, }, { label: getResultPathVarName, - check: isGetResultPathSet(env), + isSet: isGetResultPathSet(env), required: true, - errorMessage: incorrectConfigurationMessage, + message: incorrectConfigurationMessage, }, { label: proxySecretVarName, - check: isProxySecretSet(env), + isSet: isProxySecretSet(env), required: true, - errorMessage: incorrectConfigurationMessage, + message: incorrectConfigurationMessage, }, { label: decryptionKeyVarName, - check: isDecryptionKeySet(env), + isSet: isDecryptionKeySet(env), required: isOpenClientResponseEnabled(env), - errorMessage: incorrectConfigurationMessage, + message: incorrectConfigurationMessage, }, { label: openClientResponseVarName, - check: isOpenClientResponseSet(env), + isSet: isOpenClientResponseSet(env), required: false, warningMessage: "Your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning.", }, ] - const isAllVarsAvailable = configurations.filter((t) => t.required && !t.check).length === 0 + const isAllVarsAvailable = configurations.filter((t) => t.required && !t.isSet).length === 0 let result = '' if (isAllVarsAvailable) { @@ -110,9 +109,8 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { for (const configuration of configurations) { result += ` - ${configuration.check ? '✅' : '⚠️'} ${configuration.label} (${configuration.required ? 'REQUIRED' : 'OPTIONAL'}) is${!configuration.check ? ' not ' : ' '}set - ${configuration.required && !configuration.check && configuration.errorMessage ? `${configuration.errorMessage}` : ''} - ${!configuration.required && !configuration.check && configuration.warningMessage ? `${configuration.warningMessage}` : ''} + ${configuration.isSet ? '✅' : '⚠️'} ${configuration.label} (${configuration.required ? 'REQUIRED' : 'OPTIONAL'}) is${!configuration.isSet ? ' not ' : ' '}set + ${!configuration.isSet && configuration.message ? `${configuration.message}` : ''} ` } diff --git a/test/handlers/statusPage.test.ts b/test/handlers/statusPage.test.ts index 6d8097b..c795a7d 100644 --- a/test/handlers/statusPage.test.ts +++ b/test/handlers/statusPage.test.ts @@ -74,7 +74,6 @@ describe('Status Page', () => { const responseText = await response.text() const isAllSet = responseText.includes('All required configuration values are set') - console.log(responseText) expect(isAllSet).toBe(true) }) From 772cd2bc57a722fdaee09445f274063aeefd080a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 8 Nov 2024 07:28:21 +0000 Subject: [PATCH 24/40] chore(release): 0.2.0-rc.2 ## [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)) --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3962dd0..ab28085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [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) diff --git a/package.json b/package.json index c1295a4..a52ace4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fingerprint-pro-fastly-compute-proxy-integration", - "version": "0.2.0-rc.1", + "version": "0.2.0-rc.2", "engines": { "node": ">=20" }, From 8d3efef80fa6c62183b7ac52e26db8630ab4a9aa Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 10:29:35 +0300 Subject: [PATCH 25/40] refactor: change open client response flag name --- README.md | 2 +- scripts/api/createService.ts | 2 +- src/env.ts | 8 ++++---- src/handlers/handleStatusPage.ts | 2 +- src/index.ts | 2 +- test/handlers/statusPage.test.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index be47eb3..e672865 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ This is a quick overview of the installation setup. For detailed step-by-step in | ---------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 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_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`. | + | 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_Fastly_Compute_Proxy_Integration_SecretStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add your proxy secret: diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index c8ccf1e..bfd23c5 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -147,7 +147,7 @@ async function createConfigStore(service_id: string) { }) await configStoreItemClient.createConfigStoreItem({ config_store_id: configStore.id, - item_key: 'OPEN_CLIENT_RESPONSE_ENABLED', + item_key: 'OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED', item_value: 'false', }) diff --git a/src/env.ts b/src/env.ts index b25e1ce..a1d184c 100644 --- a/src/env.ts +++ b/src/env.ts @@ -2,7 +2,7 @@ export type IntegrationEnv = { AGENT_SCRIPT_DOWNLOAD_PATH: string | null GET_RESULT_PATH: string | null PROXY_SECRET: string | null - OPEN_CLIENT_RESPONSE_ENABLED: string | null + OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED: string | null DECRYPTION_KEY: string | null } @@ -10,7 +10,7 @@ const Defaults: IntegrationEnv = { AGENT_SCRIPT_DOWNLOAD_PATH: 'agent', GET_RESULT_PATH: 'result', PROXY_SECRET: null, - OPEN_CLIENT_RESPONSE_ENABLED: 'false', + OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED: 'false', DECRYPTION_KEY: null, } @@ -55,9 +55,9 @@ export const decryptionKeyVarName = 'DECRYPTION_KEY' const getDecryptionKeyVar = getVarOrDefault(decryptionKeyVarName, Defaults) export const isDecryptionKeySet = isVarSet(decryptionKeyVarName) -export const openClientResponseVarName = 'OPEN_CLIENT_RESPONSE_ENABLED' +export const openClientResponseVarName = 'OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED' export const isOpenClientResponseSet = (env: IntegrationEnv) => - env.OPEN_CLIENT_RESPONSE_ENABLED === 'true' || env.OPEN_CLIENT_RESPONSE_ENABLED === 'false' + env.OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED === 'true' || env.OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED === 'false' export const isOpenClientResponseEnabled = (env: IntegrationEnv) => env[openClientResponseVarName]?.toLowerCase() === 'true' diff --git a/src/handlers/handleStatusPage.ts b/src/handlers/handleStatusPage.ts index 7cd0359..cdbee0c 100644 --- a/src/handlers/handleStatusPage.ts +++ b/src/handlers/handleStatusPage.ts @@ -88,7 +88,7 @@ function createEnvVarsInformationElement(env: IntegrationEnv): string { label: openClientResponseVarName, isSet: isOpenClientResponseSet(env), required: false, - warningMessage: + message: "Your integration will work without the 'Open Client Response' feature. If you didn't set it intentionally, you can ignore this warning.", }, ] diff --git a/src/index.ts b/src/index.ts index 5eeade1..580f24a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,7 @@ async function getEnvObject(): Promise { return { AGENT_SCRIPT_DOWNLOAD_PATH: configStore?.get(agentScriptDownloadPathVarName) ?? null, GET_RESULT_PATH: configStore?.get(getResultPathVarName) ?? null, - OPEN_CLIENT_RESPONSE_ENABLED: configStore?.get(openClientResponseVarName) ?? null, + OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED: configStore?.get(openClientResponseVarName) ?? null, PROXY_SECRET: (await secretStore?.get(proxySecretVarName))?.plaintext() ?? null, DECRYPTION_KEY: (await secretStore?.get(decryptionKeyVarName))?.plaintext() ?? null, } diff --git a/test/handlers/statusPage.test.ts b/test/handlers/statusPage.test.ts index c795a7d..d13107e 100644 --- a/test/handlers/statusPage.test.ts +++ b/test/handlers/statusPage.test.ts @@ -61,7 +61,7 @@ describe('Status Page', () => { // @ts-ignore config.set('GET_RESULT_PATH', 'result') // @ts-ignore - config.set('OPEN_CLIENT_RESPONSE_ENABLED', 'true') + config.set('OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED', 'true') const secretStore = new SecretStore('Fingerprint') // @ts-ignore From f5a56c6abeb2026af65c05beb90608c0f9bddefe Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 10:31:34 +0300 Subject: [PATCH 26/40] chore: run plugins if response status 2xx --- src/handlers/handleIngressAPI.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index e523f94..4a0746b 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -32,13 +32,15 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) return response } - const responseBody = await response.text() - - processOpenClientResponse(responseBody, response, env).catch((e) => - console.error('failed when processing open client response', e) - ) + if (response.status >= 200 && response.status < 300) { + const responseBody = await response.text() + processOpenClientResponse(responseBody, response, env).catch((e) => + console.error('failed when processing open client response', e) + ) + return cloneFastlyResponse(responseBody, response) + } - return cloneFastlyResponse(responseBody, response) + return response } function makeCacheEndpointRequest(receivedRequest: Request, routeMatches: RegExpMatchArray | undefined) { From e0161786ceb7fa2229cd4b3a9684d5c3ad554b3e Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 10:37:20 +0300 Subject: [PATCH 27/40] chore: add SAVE_TO_KV_STORE_PLUGIN_ENABLED flag --- plugins/index.ts | 12 ++++++------ plugins/saveToKVStore.ts | 16 +++++++++++----- src/index.ts | 12 +++--------- src/utils/getStore.ts | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/utils/getStore.ts diff --git a/plugins/index.ts b/plugins/index.ts index 2c7c5ce..7209875 100644 --- a/plugins/index.ts +++ b/plugins/index.ts @@ -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[] diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index e0c4d03..a164863 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -2,11 +2,17 @@ import { KVStore } from 'fastly:kv-store' import { ProcessOpenClientResponseContext } from '../src/utils/registerPlugin' +import { getConfigStore } from '../src/utils/getStore' export async function saveFingerprintResultToKVStore(context: ProcessOpenClientResponseContext) { - const requestId = context.event?.products.identification?.data?.requestId - if (!requestId) { - return + const configStore = getConfigStore() + const isPluginEnabled = configStore?.get('SAVE_TO_KV_STORE_PLUGIN_ENABLED') === 'true' + + if (isPluginEnabled) { + const requestId = context.event?.products.identification?.data?.requestId + if (!requestId) { + return + } + const store = new KVStore('FingerprintResults') + await store.put(requestId, JSON.stringify(context.event)) } - const store = new KVStore('FingerprintResults') - await store.put(requestId, JSON.stringify(context.event)) } diff --git a/src/index.ts b/src/index.ts index 580f24a..86daebb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,12 +8,10 @@ import { openClientResponseVarName, proxySecretVarName, } from './env' -import { ConfigStore } from 'fastly:config-store' import { returnHttpResponse } from './utils/returnHttpResponse' import { createFallbackErrorResponse } from './utils' import { setClientIp } from './utils/clientIp' -import { env } from 'fastly:env' -import { SecretStore } from 'fastly:secret-store' +import { getConfigStore, getSecretStore } from './utils/getStore' addEventListener('fetch', (event) => event.respondWith(handleRequest(event))) @@ -30,15 +28,11 @@ export async function handleRequest(event: FetchEvent): Promise { } async function getEnvObject(): Promise { - const serviceId = env('FASTLY_SERVICE_ID') - const storeNamePrefix = process.env.STORE_NAME_PREFIX - const configStoreName = `${storeNamePrefix}_ConfigStore_${serviceId}` - const secretStoreName = `${storeNamePrefix}_SecretStore_${serviceId}` let configStore let secretStore try { - configStore = new ConfigStore(configStoreName) - secretStore = new SecretStore(secretStoreName) + configStore = getConfigStore() + secretStore = getSecretStore() } catch (e) { console.error(e) } diff --git a/src/utils/getStore.ts b/src/utils/getStore.ts new file mode 100644 index 0000000..36b87cd --- /dev/null +++ b/src/utils/getStore.ts @@ -0,0 +1,24 @@ +import { env } from 'fastly:env' +import { ConfigStore } from 'fastly:config-store' +import { SecretStore } from 'fastly:secret-store' + +export function getNamesForStores() { + const serviceId = env('FASTLY_SERVICE_ID') + const storeNamePrefix = process.env.STORE_NAME_PREFIX + const configStoreName = `${storeNamePrefix}_ConfigStore_${serviceId}` + const secretStoreName = `${storeNamePrefix}_SecretStore_${serviceId}` + + return { + configStoreName, + secretStoreName, + } +} +export function getConfigStore() { + const { configStoreName } = getNamesForStores() + return new ConfigStore(configStoreName) +} + +export function getSecretStore() { + const { secretStoreName } = getNamesForStores() + return new SecretStore(secretStoreName) +} From 0451fd3e6fa33e5440e0e8efe68dabe2cebd7a07 Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 10:41:26 +0300 Subject: [PATCH 28/40] chore(deps): add node sdk as peer dependency --- package.json | 4 +++- pnpm-lock.yaml | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c1295a4..a304f49 100644 --- a/package.json +++ b/package.json @@ -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", @@ -62,5 +61,8 @@ "commitizen": { "path": "./node_modules/cz-conventional-changelog" } + }, + "peerDependencies": { + "@fingerprintjs/fingerprintjs-pro-server-api": "^5.2.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8c59a80..b9ce502 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@fastly/js-compute': specifier: ^3.21.4 version: 3.25.0 + '@fingerprintjs/fingerprintjs-pro-server-api': + specifier: ^5.2.0 + version: 5.2.0 cookie: specifier: 0.7.0 version: 0.7.0 @@ -36,9 +39,6 @@ importers: '@fingerprintjs/eslint-config-dx-team': specifier: ^0.1.0 version: 0.1.0(prettier@3.2.4)(typescript@5.3.3) - '@fingerprintjs/fingerprintjs-pro-server-api': - specifier: ^5.0.0 - version: 5.1.0 '@fingerprintjs/prettier-config-dx-team': specifier: ^0.2.0 version: 0.2.0 @@ -1002,8 +1002,8 @@ packages: peerDependencies: prettier: '>=3' - '@fingerprintjs/fingerprintjs-pro-server-api@5.1.0': - resolution: {integrity: sha512-lB9Iz+v8xccQlyQa8fsLb2F/fQ4ti1iegs+BvTMND6XBsawFcG2+HzdZwmb87Dg7EHf6Ez+vDvNElzjVV+Qmwg==} + '@fingerprintjs/fingerprintjs-pro-server-api@5.2.0': + resolution: {integrity: sha512-o53t3fVO2sC3h3WFxniu9Pw3QZYCXnkSz4vOZLzh9YtiyWf3JGV8ejN7YEnwHWM+k6uMjVhqHOpDpOXIsCEHfA==} engines: {node: '>=18.17.0'} '@fingerprintjs/prettier-config-dx-team@0.2.0': @@ -4221,7 +4221,7 @@ snapshots: - supports-color - typescript - '@fingerprintjs/fingerprintjs-pro-server-api@5.1.0': {} + '@fingerprintjs/fingerprintjs-pro-server-api@5.2.0': {} '@fingerprintjs/prettier-config-dx-team@0.2.0': dependencies: From b9c6ca308e7e509f3a24e47ac3866cb29f6abd7e Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 11:00:20 +0300 Subject: [PATCH 29/40] refactor: change flag names --- build.ts | 2 +- plugins/saveToKVStore.ts | 4 +++- src/utils/getStore.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.ts b/build.ts index 0071fee..5f9f8e9 100644 --- a/build.ts +++ b/build.ts @@ -1,7 +1,7 @@ import { build } from 'esbuild' // Load environment variables from process.env -const configStoreNamePrefix = process.env.STORE_NAME_PREFIX || 'Fingerprint_Fastly_Compute_Proxy_Integration' +const configStoreNamePrefix = process.env.STORE_NAME_PREFIX || 'Fingerprint_Compute' build({ entryPoints: ['./src/index.ts'], diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index a164863..e929505 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -3,6 +3,7 @@ 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' @@ -12,7 +13,8 @@ export async function saveFingerprintResultToKVStore(context: ProcessOpenClientR if (!requestId) { 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)) } } diff --git a/src/utils/getStore.ts b/src/utils/getStore.ts index 36b87cd..4bf3200 100644 --- a/src/utils/getStore.ts +++ b/src/utils/getStore.ts @@ -5,8 +5,8 @@ import { SecretStore } from 'fastly:secret-store' export function getNamesForStores() { const serviceId = env('FASTLY_SERVICE_ID') const storeNamePrefix = process.env.STORE_NAME_PREFIX - const configStoreName = `${storeNamePrefix}_ConfigStore_${serviceId}` - const secretStoreName = `${storeNamePrefix}_SecretStore_${serviceId}` + const configStoreName = `${storeNamePrefix}_Config_Store_${serviceId}` + const secretStoreName = `${storeNamePrefix}_Secret_Store_${serviceId}` return { configStoreName, From 762204f9272a29615eb78b802dedf5c46a2c9fc9 Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 11:08:42 +0300 Subject: [PATCH 30/40] refactor: update store prefix --- README.md | 12 ++++++------ scripts/api/createService.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e672865..014f8cf 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This is a quick overview of the installation setup. For detailed step-by-step in 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. -3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values: +3. [Create a Config store](https://docs.fastly.com/en/guides/working-with-config-stores#creating-a-config-store) named `Fingerprint_Compute_Config_Store_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add the following values: | Key | Example Value | Description | | ---------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -44,7 +44,7 @@ This is a quick overview of the installation setup. For detailed step-by-step in | 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_Fastly_Compute_Proxy_Integration_SecretStore_`, where the suffix is your proxy integration's [Compute Service ID](https://docs.fastly.com/en/guides/about-services). Add your proxy secret: +4. [Create a Secret store](https://docs.fastly.com/en/guides/working-with-secret-stores#creating-a-secret-store) named `Fingerprint_Compute_Secret_Store_`, 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 | | ------------ | -------------------- | --------------------------------------------- | @@ -75,8 +75,8 @@ See the [Fastly Compute proxy integration guide](https://dev.fingerprint.com/doc By default, the service package provided in releases assumes the following names for the Config store and Secret Store: -* `Fingerprint_Fastly_Compute_Proxy_Integration_ConfigStore_` -* `Fingerprint_Fastly_Compute_Proxy_Integration_SecretStore_` +* `Fingerprint_Compute_Config_Store_` +* `Fingerprint_Compute_Secret_Store_` To use a custom name prefix for both stores, use the `STORE_NAME_PREFIX` environment variable to build a custom service package: @@ -86,8 +86,8 @@ 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_ConfigStore_` -* `CustomName_SecretStore_` +* `CustomName_Config_Store_` +* `CustomName_Secret_Store_` ## Feedback and support diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index bfd23c5..baf7bf7 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -93,7 +93,7 @@ async function linkStoreResource( async function createSecretStore(service_id: string) { console.log('Creating secret store') - const secretStoreNameWithPrefix = `${STORE_NAME_PREFIX}_SecretStore_${service_id}` + const secretStoreNameWithPrefix = `${STORE_NAME_PREFIX}_Secret_Store_${service_id}` const secretStoreClient = createClient('secretStore') const secretStoreItemClient = createClient('secretStoreItem') let secretStore @@ -122,7 +122,7 @@ async function createSecretStore(service_id: string) { async function createConfigStore(service_id: string) { console.log('Creating config store') - const configStoreNameWithPrefix = `${STORE_NAME_PREFIX}_ConfigStore_${service_id}` + const configStoreNameWithPrefix = `${STORE_NAME_PREFIX}_Config_Store_${service_id}` const configStoreClient = createClient('configStore') const configStoreItemClient = createClient('configStoreItem') let configStore From 2fb4f56be31aad6c1a9c7c66d13e90ddba667ecc Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 11:13:43 +0300 Subject: [PATCH 31/40] refactor: update store prefix --- scripts/api/createService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/api/createService.ts b/scripts/api/createService.ts index baf7bf7..c10b3f4 100644 --- a/scripts/api/createService.ts +++ b/scripts/api/createService.ts @@ -82,7 +82,7 @@ async function linkStoreResource( resource_id: string, type: 'secret' | 'config' = 'config' ) { - const storeNameWithPrefix = `${STORE_NAME_PREFIX}_${type === 'config' ? 'ConfigStore' : 'SecretStore'}_${service_id}` + const storeNameWithPrefix = `${STORE_NAME_PREFIX}_${type === 'config' ? 'Config_Store' : 'Secret_Store'}_${service_id}` return createClient('resource').createResource({ service_id, version_id, From 314e576790df800a6b3d892cb52427c81742e419 Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 11:24:40 +0300 Subject: [PATCH 32/40] chore: fix tests for kv-store --- __mocks__/fastly:kv-store.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 __mocks__/fastly:kv-store.js diff --git a/__mocks__/fastly:kv-store.js b/__mocks__/fastly:kv-store.js new file mode 100644 index 0000000..833fe89 --- /dev/null +++ b/__mocks__/fastly:kv-store.js @@ -0,0 +1,5 @@ +export class KVStore { + async put(name, value) { + return { name, value } + } +} From d0639193a317a04c887cb4d696f0a35917ab388a Mon Sep 17 00:00:00 2001 From: Orkun Date: Fri, 8 Nov 2024 12:33:10 +0300 Subject: [PATCH 33/40] chore: add logger for vpn confidence score --- plugins/saveToKVStore.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index e929505..baf452d 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -16,5 +16,6 @@ export async function saveFingerprintResultToKVStore(context: ProcessOpenClientR const serviceId = env('FASTLY_SERVICE_ID') const store = new KVStore(`Fingerprint_Results_${serviceId}`) await store.put(requestId, JSON.stringify(context.event)) + console.log('VPN Confidence', context.event?.products.vpn?.data?.confidence) } } From 992e0252091a72f0818e86178f559efb8f41c629 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 10:54:55 +0300 Subject: [PATCH 34/40] refactor: early return and log for plugin status --- plugins/saveToKVStore.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index baf452d..facc3c2 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -8,14 +8,16 @@ export async function saveFingerprintResultToKVStore(context: ProcessOpenClientR const configStore = getConfigStore() const isPluginEnabled = configStore?.get('SAVE_TO_KV_STORE_PLUGIN_ENABLED') === 'true' - if (isPluginEnabled) { - const requestId = context.event?.products.identification?.data?.requestId - if (!requestId) { - return - } - const serviceId = env('FASTLY_SERVICE_ID') - const store = new KVStore(`Fingerprint_Results_${serviceId}`) - await store.put(requestId, JSON.stringify(context.event)) - console.log('VPN Confidence', context.event?.products.vpn?.data?.confidence) + if (!isPluginEnabled) { + console.log("Plugin 'saveFingerprintResultToKVStore' is not enabled") + return } + + const requestId = context.event?.products.identification?.data?.requestId + if (!requestId) { + return + } + const serviceId = env('FASTLY_SERVICE_ID') + const store = new KVStore(`Fingerprint_Results_${serviceId}`) + await store.put(requestId, JSON.stringify(context.event)) } From 9ed299c9e1f99e381525c2a1aa00afa99b2d030c Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 12:29:38 +0300 Subject: [PATCH 35/40] refactor: add loggers for open client response plugin enabled checks --- src/handlers/handleIngressAPI.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index 4a0746b..b4d4141 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -29,9 +29,11 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) const response = await fetch(request, { backend: getIngressBackendByRegion(url) }) if (!isOpenClientResponseEnabled(env)) { + console.log('Plugin system for Open Client Response is disabled') return response } + console.log('Plugin system for Open Client Response is enabled') if (response.status >= 200 && response.status < 300) { const responseBody = await response.text() processOpenClientResponse(responseBody, response, env).catch((e) => From eb21da5366ae4e0d30d3ff0d64ebc6f7e19fd15f Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 12:44:09 +0300 Subject: [PATCH 36/40] refactor: update logger message for plugin system Co-authored-by: Juraj Uhlar --- src/handlers/handleIngressAPI.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index b4d4141..4cf516a 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -29,7 +29,7 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) const response = await fetch(request, { backend: getIngressBackendByRegion(url) }) if (!isOpenClientResponseEnabled(env)) { - console.log('Plugin system for Open Client Response is disabled') + console.log('Open client response plugings are disabled. Set OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED to `true` in your proxy integration's Config store to enable them.') return response } From a5262072a9ff2d15d369338139d9057a1dc2b690 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 12:45:45 +0300 Subject: [PATCH 37/40] refactor: update logger message for open client response fail Co-authored-by: Juraj Uhlar --- src/handlers/handleIngressAPI.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index 4cf516a..338b69d 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -37,7 +37,7 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) if (response.status >= 200 && response.status < 300) { const responseBody = await response.text() processOpenClientResponse(responseBody, response, env).catch((e) => - console.error('failed when processing open client response', e) + console.error('Processing open client response failed: ', e) ) return cloneFastlyResponse(responseBody, response) } From 9657ebae49f3cfea4d4912be19cebc04f3b5967c Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 12:47:36 +0300 Subject: [PATCH 38/40] refactor: update logger error --- src/handlers/handleIngressAPI.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/handlers/handleIngressAPI.ts b/src/handlers/handleIngressAPI.ts index 338b69d..757fec9 100644 --- a/src/handlers/handleIngressAPI.ts +++ b/src/handlers/handleIngressAPI.ts @@ -29,7 +29,9 @@ async function makeIngressRequest(receivedRequest: Request, env: IntegrationEnv) const response = await fetch(request, { backend: getIngressBackendByRegion(url) }) if (!isOpenClientResponseEnabled(env)) { - console.log('Open client response plugings are disabled. Set OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED to `true` in your proxy integration's Config store to enable them.') + console.log( + "Open client response plugings are disabled. Set OPEN_CLIENT_RESPONSE_PLUGINS_ENABLED to `true` in your proxy integration's Config store to enable them." + ) return response } From f3683faef5f83b008bf6cc54f867c7a8583b8147 Mon Sep 17 00:00:00 2001 From: Orkun Date: Mon, 11 Nov 2024 12:50:08 +0300 Subject: [PATCH 39/40] refactor: add logger for missing requestId --- plugins/saveToKVStore.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index facc3c2..8f23063 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -15,6 +15,7 @@ export async function saveFingerprintResultToKVStore(context: ProcessOpenClientR 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 serviceId = env('FASTLY_SERVICE_ID') From 6c85ea8f08727e568f0d75132245fb94856da2de Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Mon, 11 Nov 2024 10:38:59 +0000 Subject: [PATCH 40/40] chore: missing space in error --- plugins/saveToKVStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/saveToKVStore.ts b/plugins/saveToKVStore.ts index 8f23063..44c1294 100644 --- a/plugins/saveToKVStore.ts +++ b/plugins/saveToKVStore.ts @@ -15,7 +15,7 @@ export async function saveFingerprintResultToKVStore(context: ProcessOpenClientR const requestId = context.event?.products.identification?.data?.requestId if (!requestId) { - console.log('[saveFingerprintResultToKVStore]Plugin Error: request ID is undefined in the event response') + console.log('[saveFingerprintResultToKVStore] Plugin Error: request ID is undefined in the event response.') return } const serviceId = env('FASTLY_SERVICE_ID')