-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fingerprintjs/feature/agent-js-proxy
JS agent proxy
- Loading branch information
Showing
24 changed files
with
580 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Check coverage for PR | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
run-tests-check-coverage: | ||
runs-on: ubuntu-20.04 | ||
name: Run tests & check coverage | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Jest coverage comment | ||
id: coverage | ||
uses: ArtiomTr/jest-coverage-report-action@9f733792c44d05327cb371766bf78a5261e43936 | ||
with: | ||
package-manager: yarn | ||
output: report-markdown | ||
- name: Read coverage text report | ||
uses: fingerprintjs/action-coverage-report-md@v1 | ||
id: coverage-md | ||
with: | ||
srcBasePath: './' | ||
- uses: marocchino/sticky-pull-request-comment@adca94abcaf73c10466a71cc83ae561fd66d1a56 | ||
with: | ||
message: | | ||
${{ steps.coverage.outputs.report }} | ||
<details> | ||
<summary>Show full coverage report</summary> | ||
${{ steps.coverage-md.outputs.markdownReport }} | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Coverage | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-run-tests: | ||
runs-on: ubuntu-20.04 | ||
name: Build & run tests & publish coverage | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.node-version' | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v3 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install Dependencies and prepare packages | ||
run: yarn install | ||
env: | ||
CI: true | ||
- name: Run test | ||
run: yarn test | ||
|
||
- name: Create Coverage Badges | ||
uses: jaywcjlove/coverage-badges-cli@e07f25709cd25486855c1ba1b26da53576ff3620 | ||
with: | ||
source: coverage/coverage-summary.json | ||
output: coverage/lcov-report/badges.svg | ||
|
||
- name: Deploy | ||
uses: JamesIves/github-pages-deploy-action@8817a56e5bfec6e2b08345c81f4d422db53a2cdc | ||
with: | ||
branch: gh-pages | ||
folder: ./coverage/lcov-report/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { updateCacheControlHeader } from './cacheControl' | ||
|
||
describe('updateCacheControlHeader', () => { | ||
test('adjust max-age to lower value', () => { | ||
expect(updateCacheControlHeader('public, max-age=36000, s-maxage=36000')).toBe('public, max-age=3600, s-maxage=60') | ||
}) | ||
|
||
test('keep existing smaller value', () => { | ||
expect(updateCacheControlHeader('public, max-age=600, s-maxage=600')).toBe('public, max-age=600, s-maxage=60') | ||
}) | ||
|
||
test('add max age if not exist', () => { | ||
expect(updateCacheControlHeader('no-cache')).toBe('no-cache, max-age=3600, s-maxage=60') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const CACHE_MAX_AGE = 3600 | ||
const SHARED_CACHE_MAX_AGE = 60 | ||
|
||
export function updateCacheControlHeader(headerValue: string): string { | ||
let result = updateCacheControlAge(headerValue, 'max-age', CACHE_MAX_AGE) | ||
result = updateCacheControlAge(result, 's-maxage', SHARED_CACHE_MAX_AGE) | ||
|
||
return result | ||
} | ||
|
||
function updateCacheControlAge(headerValue: string, type: 'max-age' | 's-maxage', cacheMaxAge: number): string { | ||
const cacheControlDirectives = headerValue.split(', ') | ||
const maxAgeIndex = cacheControlDirectives.findIndex( | ||
(directive) => directive.split('=')[0].trim().toLowerCase() === type, | ||
) | ||
|
||
if (maxAgeIndex === -1) { | ||
cacheControlDirectives.push(`${type}=${cacheMaxAge}`) | ||
} else { | ||
const oldMaxAge = Number(cacheControlDirectives[maxAgeIndex].split('=')[1]) | ||
const newMaxAge = Math.min(cacheMaxAge, oldMaxAge) | ||
cacheControlDirectives[maxAgeIndex] = `${type}=${newMaxAge}` | ||
} | ||
|
||
return cacheControlDirectives.join(', ') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const config = { | ||
fpdcdn: '__FPCDN__', | ||
ingressApi: '__INGRESS_API__', | ||
} |
Oops, something went wrong.