@prosopo/provider-mock 2.8.143 → 2.8.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$cjs.log +8 -6
- package/.turbo/turbo-build$colon$tsc.log +26 -26
- package/.turbo/turbo-build.log +9 -7
- package/CHANGELOG.md +52 -0
- package/Dockerfile +11 -0
- package/dist/api.d.ts +35 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +97 -67
- package/dist/api.js.map +1 -1
- package/dist/cjs/api.cjs +105 -66
- package/dist/cjs/db.cjs +16 -7
- package/dist/cjs/isMain.cjs +16 -0
- package/dist/cjs/start.cjs +59 -16
- package/dist/cjs/verify.cjs +39 -0
- package/dist/db.d.ts +8 -4
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +16 -7
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/isMain.d.ts +2 -0
- package/dist/isMain.d.ts.map +1 -0
- package/dist/isMain.js +16 -0
- package/dist/isMain.js.map +1 -0
- package/dist/start.d.ts +17 -0
- package/dist/start.d.ts.map +1 -1
- package/dist/start.js +54 -17
- package/dist/start.js.map +1 -1
- package/dist/tests/db.unit.test.d.ts +2 -0
- package/dist/tests/db.unit.test.d.ts.map +1 -0
- package/dist/tests/db.unit.test.js +184 -0
- package/dist/tests/db.unit.test.js.map +1 -0
- package/dist/tests/fixtures.d.ts +33 -0
- package/dist/tests/fixtures.d.ts.map +1 -0
- package/dist/tests/fixtures.js +55 -0
- package/dist/tests/fixtures.js.map +1 -0
- package/dist/tests/handlers.unit.test.d.ts +2 -0
- package/dist/tests/handlers.unit.test.d.ts.map +1 -0
- package/dist/tests/handlers.unit.test.js +204 -0
- package/dist/tests/handlers.unit.test.js.map +1 -0
- package/dist/tests/providerMock.test-d.d.ts +2 -0
- package/dist/tests/providerMock.test-d.d.ts.map +1 -0
- package/dist/tests/providerMock.test-d.js +88 -0
- package/dist/tests/providerMock.test-d.js.map +1 -0
- package/dist/tests/start.unit.test.d.ts +2 -0
- package/dist/tests/start.unit.test.d.ts.map +1 -0
- package/dist/tests/start.unit.test.js +205 -0
- package/dist/tests/start.unit.test.js.map +1 -0
- package/dist/tests/verify.unit.test.d.ts +2 -0
- package/dist/tests/verify.unit.test.d.ts.map +1 -0
- package/dist/tests/verify.unit.test.js +63 -0
- package/dist/tests/verify.unit.test.js.map +1 -0
- package/dist/tests/wiring.unit.test.d.ts +2 -0
- package/dist/tests/wiring.unit.test.d.ts.map +1 -0
- package/dist/tests/wiring.unit.test.js +181 -0
- package/dist/tests/wiring.unit.test.js.map +1 -0
- package/dist/verify.d.ts +13 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +34 -0
- package/dist/verify.js.map +1 -0
- package/package.json +20 -12
- package/src/api.ts +170 -79
- package/src/db.ts +39 -12
- package/src/index.ts +18 -0
- package/src/isMain.ts +37 -0
- package/src/start.ts +92 -18
- package/src/tests/db.unit.test.ts +287 -0
- package/src/tests/fixtures.ts +117 -0
- package/src/tests/handlers.unit.test.ts +325 -0
- package/src/tests/providerMock.test-d.ts +165 -0
- package/src/tests/start.unit.test.ts +291 -0
- package/src/tests/verify.unit.test.ts +143 -0
- package/src/tests/wiring.unit.test.ts +293 -0
- package/src/verify.ts +63 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.test.config.ts +32 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/provider-mock@2.8.
|
|
2
|
+
> @prosopo/provider-mock@2.8.145 build:cjs
|
|
3
3
|
> NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
|
|
4
4
|
|
|
5
5
|
ViteCommonJSConfig: .
|
|
@@ -57,12 +57,14 @@ ViteCommonJSConfig: .
|
|
|
57
57
|
[36mvite v8.1.5 [32mbuilding ssr environment for production...[36m[39m
|
|
58
58
|
Bundle build started
|
|
59
59
|
[2K
|
|
60
|
-
✓
|
|
60
|
+
✓ 6 modules transformed.
|
|
61
61
|
rendering chunks...
|
|
62
62
|
computing gzip size...
|
|
63
|
+
dist/cjs/isMain.cjs 0.57 kB │ gzip: 0.33 kB
|
|
63
64
|
dist/cjs/_virtual/_rolldown/runtime.cjs 1.00 kB │ gzip: 0.50 kB
|
|
64
|
-
dist/cjs/
|
|
65
|
-
dist/cjs/
|
|
66
|
-
dist/cjs/
|
|
65
|
+
dist/cjs/verify.cjs 1.60 kB │ gzip: 0.76 kB
|
|
66
|
+
dist/cjs/start.cjs 2.70 kB │ gzip: 1.19 kB
|
|
67
|
+
dist/cjs/db.cjs 2.71 kB │ gzip: 1.02 kB
|
|
68
|
+
dist/cjs/api.cjs 4.67 kB │ gzip: 1.86 kB
|
|
67
69
|
|
|
68
|
-
[32m✓ built in
|
|
70
|
+
[32m✓ built in 48ms[39m
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/provider-mock@2.8.
|
|
2
|
+
> @prosopo/provider-mock@2.8.145 build:tsc
|
|
3
3
|
> tsc --build --verbose
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
3:32:10 PM - Projects in this build:
|
|
6
6
|
* ../../dev/config/tsconfig.json
|
|
7
7
|
* ../../packages/util/tsconfig.json
|
|
8
8
|
* ../../packages/logger/tsconfig.json
|
|
@@ -27,51 +27,51 @@
|
|
|
27
27
|
* ../../packages/dotenv/tsconfig.json
|
|
28
28
|
* tsconfig.json
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
3:32:10 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
3:32:10 PM - Project '../../packages/util/tsconfig.json' is up to date because newest input '../../packages/util/src/url.ts' is older than output '../../packages/util/tsconfig.tsbuildinfo'
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
3:32:10 PM - Project '../../packages/logger/tsconfig.json' is up to date because newest input '../../packages/logger/src/logger.ts' is older than output '../../packages/logger/tsconfig.tsbuildinfo'
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
3:32:10 PM - Project '../../packages/api-route/tsconfig.json' is up to date because newest input '../../packages/api-route/src/apiRoutes.ts' is older than output '../../packages/api-route/tsconfig.tsbuildinfo'
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
3:32:10 PM - Project '../../packages/locale/tsconfig.json' is up to date because newest input '../../packages/locale/src/translationKey.ts' is older than output '../../packages/locale/tsconfig.tsbuildinfo'
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
3:32:10 PM - Project '../../packages/util-crypto/tsconfig.json' is up to date because newest input '../../packages/util-crypto/src/types.ts' is older than output '../../packages/util-crypto/tsconfig.tsbuildinfo'
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
3:32:10 PM - Project '../../packages/types/tsconfig.json' is up to date because newest input '../../packages/types/src/types.test-d.ts' is older than output '../../packages/types/tsconfig.tsbuildinfo'
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
3:32:10 PM - Project '../../packages/common/tsconfig.json' is up to date because newest input '../../packages/common/src/index.ts' is older than output '../../packages/common/tsconfig.tsbuildinfo'
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
3:32:10 PM - Project '../../packages/ipinfo/tsconfig.json' is up to date because newest input '../../packages/ipinfo/src/IpInfoService.ts' is older than output '../../packages/ipinfo/tsconfig.tsbuildinfo'
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
3:32:10 PM - Project '../../packages/redis-client/tsconfig.json' is up to date because newest input '../../packages/redis-client/src/index.ts' is older than output '../../packages/redis-client/tsconfig.tsbuildinfo'
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
3:32:10 PM - Project '../../packages/api/tsconfig.json' is up to date because newest input '../../packages/api/src/index.ts' is older than output '../../packages/api/tsconfig.tsbuildinfo'
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
3:32:10 PM - Project '../../packages/user-access-policy/tsconfig.json' is up to date because newest input '../../packages/user-access-policy/src/transformRule.ts' is older than output '../../packages/user-access-policy/tsconfig.tsbuildinfo'
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
3:32:10 PM - Project '../../packages/types-database/tsconfig.json' is up to date because newest input '../../packages/types-database/src/types.test-d.ts' is older than output '../../packages/types-database/tsconfig.tsbuildinfo'
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
3:32:10 PM - Project '../../packages/database/tsconfig.json' is up to date because newest input '../../packages/database/src/tests/unit/redisCacheEscalation.unit.test.ts' is older than output '../../packages/database/tsconfig.tsbuildinfo'
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
3:32:10 PM - Project '../../packages/keyring/tsconfig.json' is up to date because newest input '../../packages/keyring/src/keyring/keyring.test.ts' is older than output '../../packages/keyring/tsconfig.tsbuildinfo'
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
3:32:11 PM - Project '../../packages/types-env/tsconfig.json' is up to date because newest input '../../packages/types-env/src/env.ts' is older than output '../../packages/types-env/tsconfig.tsbuildinfo'
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
3:32:11 PM - Project '../../packages/env/tsconfig.json' is up to date because newest input '../../packages/env/src/index.ts' is older than output '../../packages/env/tsconfig.tsbuildinfo'
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
3:32:11 PM - Project '../../packages/api-express-router/tsconfig.json' is up to date because newest input '../../packages/api-express-router/src/middlewares/requestLoggerMiddleware.ts' is older than output '../../packages/api-express-router/tsconfig.tsbuildinfo'
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
3:32:11 PM - Project '../../packages/datasets/tsconfig.json' is up to date because newest input '../../packages/datasets/src/tests/dataset.unit.test.ts' is older than output '../../packages/datasets/tsconfig.tsbuildinfo'
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
3:32:11 PM - Project '../../packages/load-balancer/tsconfig.json' is up to date because newest input '../../packages/load-balancer/src/balancer.ts' is older than output '../../packages/load-balancer/tsconfig.tsbuildinfo'
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
3:32:11 PM - Project '../../packages/provider/tsconfig.json' is up to date because newest input '../../packages/provider/src/util.ts' is older than output '../../packages/provider/tsconfig.tsbuildinfo'
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
3:32:11 PM - Project '../../packages/dotenv/tsconfig.json' is up to date because newest input '../../packages/dotenv/src/env.ts' is older than output '../../packages/dotenv/tsconfig.tsbuildinfo'
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
3:32:11 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
3:32:11 PM - Building project '/home/runner/work/captcha/captcha/demos/provider-mock/tsconfig.json'...
|
|
77
77
|
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/provider-mock@2.8.
|
|
2
|
+
> @prosopo/provider-mock@2.8.145 build
|
|
3
3
|
> npm run build:cross-env -- --mode ${NODE_ENV:-development}
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @prosopo/provider-mock@2.8.
|
|
6
|
+
> @prosopo/provider-mock@2.8.145 build:cross-env
|
|
7
7
|
> vite build --config vite.esm.config.ts --mode production
|
|
8
8
|
|
|
9
9
|
ViteEsmConfig: .
|
|
@@ -61,12 +61,14 @@ ViteEsmConfig: .
|
|
|
61
61
|
[36mvite v8.1.5 [32mbuilding ssr environment for production...[36m[39m
|
|
62
62
|
Bundle build started
|
|
63
63
|
[2K
|
|
64
|
-
✓
|
|
64
|
+
✓ 6 modules transformed.
|
|
65
65
|
rendering chunks...
|
|
66
66
|
computing gzip size...
|
|
67
67
|
dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
68
|
-
dist/
|
|
69
|
-
dist/
|
|
70
|
-
dist/
|
|
68
|
+
dist/isMain.js 0.52 kB │ gzip: 0.32 kB
|
|
69
|
+
dist/verify.js 1.45 kB │ gzip: 0.74 kB
|
|
70
|
+
dist/start.js 2.21 kB │ gzip: 1.05 kB
|
|
71
|
+
dist/db.js 2.66 kB │ gzip: 1.01 kB
|
|
72
|
+
dist/api.js 4.12 kB │ gzip: 1.74 kB
|
|
71
73
|
|
|
72
|
-
[32m✓ built in
|
|
74
|
+
[32m✓ built in 57ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# @prosopo/provider-mock
|
|
2
2
|
|
|
3
|
+
## 2.8.145
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [216f8cd]
|
|
7
|
+
- @prosopo/types-database@5.0.4
|
|
8
|
+
- @prosopo/provider@5.0.5
|
|
9
|
+
- @prosopo/types@5.0.4
|
|
10
|
+
- @prosopo/database@4.0.5
|
|
11
|
+
- @prosopo/api-express-router@3.1.59
|
|
12
|
+
|
|
13
|
+
## 2.8.144
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 1b2cca9: Add unit and type tests for the provider mock, and fix the defects they found:
|
|
17
|
+
|
|
18
|
+
- `/test` opened a mongo connection and only closed it after a successful write, so
|
|
19
|
+
every failing request leaked a connection for the life of the process. The close
|
|
20
|
+
now happens in a `finally`.
|
|
21
|
+
- `JA4Database.connect()` read models off `this.connection` without checking the base
|
|
22
|
+
class had set one, turning a failed connect into "cannot read properties of
|
|
23
|
+
undefined" much later; it now throws `DATABASE.CONNECTION_UNDEFINED`.
|
|
24
|
+
- Queries issued before `connect()` hit an unreachable `!this.tables` guard and threw a
|
|
25
|
+
`TypeError`; they now report a `ProsopoDBError`.
|
|
26
|
+
- The api port was the hardcoded string `"9229"`. It is now read from
|
|
27
|
+
`PROVIDER_MOCK_PORT`, validated as a port number, and defaulted when unusable.
|
|
28
|
+
- `start.ts` called `startApi()` at module scope, so importing anything from the
|
|
29
|
+
package started a server. Startup is now behind an `isMain` guard.
|
|
30
|
+
- Startup failures resolved quietly, leaving a container with nothing listening in it;
|
|
31
|
+
`main` now exits non-zero.
|
|
32
|
+
- Route handlers are adapted through `toRequestHandler`, which forwards a rejected
|
|
33
|
+
handler to the error middleware instead of leaving an unhandled rejection and a
|
|
34
|
+
hanging request.
|
|
35
|
+
- Updated dependencies [132e9e3]
|
|
36
|
+
- Updated dependencies [a308b9b]
|
|
37
|
+
- Updated dependencies [8386644]
|
|
38
|
+
- Updated dependencies [16dbab0]
|
|
39
|
+
- Updated dependencies [69c6982]
|
|
40
|
+
- Updated dependencies [9091a78]
|
|
41
|
+
- Updated dependencies [9ec6cc4]
|
|
42
|
+
- Updated dependencies [6d4bb65]
|
|
43
|
+
- Updated dependencies [d7b93f1]
|
|
44
|
+
- Updated dependencies [063e69d]
|
|
45
|
+
- @prosopo/provider@5.0.4
|
|
46
|
+
- @prosopo/types@5.0.3
|
|
47
|
+
- @prosopo/database@4.0.4
|
|
48
|
+
- @prosopo/locale@3.3.0
|
|
49
|
+
- @prosopo/api-express-router@3.1.58
|
|
50
|
+
- @prosopo/types-database@5.0.3
|
|
51
|
+
- @prosopo/common@3.1.50
|
|
52
|
+
- @prosopo/logger@2.0.6
|
|
53
|
+
- @prosopo/dotenv@3.0.52
|
|
54
|
+
|
|
3
55
|
## 2.8.143
|
|
4
56
|
### Patch Changes
|
|
5
57
|
|
package/Dockerfile
ADDED
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
import { type Logger } from "@prosopo/logger";
|
|
3
|
+
import { type ProcaptchaOutput, type ProcaptchaToken } from "@prosopo/types";
|
|
4
|
+
import { type RequestHandler, type Router } from "express";
|
|
5
|
+
import { JA4Database, type JA4Store } from "./db.js";
|
|
6
|
+
export interface ApiRequest {
|
|
7
|
+
body: unknown;
|
|
8
|
+
headers: IncomingHttpHeaders;
|
|
9
|
+
t: (key: string) => string;
|
|
10
|
+
}
|
|
11
|
+
export interface ApiResponse {
|
|
12
|
+
json: (body: object) => unknown;
|
|
13
|
+
status: (code: number) => {
|
|
14
|
+
send: (body: string) => unknown;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export type ApiNext = (error: unknown) => void;
|
|
18
|
+
export interface RouterDeps {
|
|
19
|
+
db: JA4Store;
|
|
20
|
+
getJA4: (headers: IncomingHttpHeaders, logger?: Logger) => Promise<{
|
|
21
|
+
ja4PlusFingerprint: string;
|
|
22
|
+
}>;
|
|
23
|
+
decodeToken: (token: ProcaptchaToken) => ProcaptchaOutput;
|
|
24
|
+
logger: Logger;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_MONGO_URL = "mongodb://localhost:27017";
|
|
27
|
+
export declare const DEFAULT_MONGO_DBNAME = "client";
|
|
28
|
+
export declare const DEFAULT_MONGO_AUTH_SOURCE = "admin";
|
|
29
|
+
export declare const createDatabase: (env?: NodeJS.ProcessEnv) => JA4Database;
|
|
30
|
+
export declare const defaultRouterDeps: () => RouterDeps;
|
|
31
|
+
export declare const createVerifyHandler: (deps: RouterDeps) => (req: ApiRequest, res: ApiResponse, next: ApiNext) => Promise<void>;
|
|
32
|
+
export declare const createTestHandler: (deps: RouterDeps) => (req: ApiRequest, res: ApiResponse) => Promise<void>;
|
|
33
|
+
export declare const verifyRateLimit: () => RequestHandler;
|
|
34
|
+
export declare const toRequestHandler: (handler: (req: ApiRequest, res: ApiResponse, next: ApiNext) => Promise<void>) => RequestHandler;
|
|
35
|
+
export declare function prosopoRouter(deps?: RouterDeps): Router;
|
|
3
36
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[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C;AAC7C,eAAO,MAAM,yBAAyB,UAAU,CAAC;AAEjD,eAAO,MAAM,cAAc,SACrB,MAAM,CAAC,UAAU,KACpB,WAKD,CAAC;AAEH,eAAO,MAAM,iBAAiB,QAAO,UAKnC,CAAC;AAUH,eAAO,MAAM,mBAAmB,SACxB,UAAU,WACL,UAAU,OAAO,WAAW,QAAQ,OAAO,KAAG,OAAO,CAAC,IAAI,CA4BrE,CAAC;AAGH,eAAO,MAAM,iBAAiB,SACtB,UAAU,WACL,UAAU,OAAO,WAAW,KAAG,OAAO,CAAC,IAAI,CA8BtD,CAAC;AAQH,eAAO,MAAM,eAAe,QAAO,cAMhC,CAAC;AAOJ,eAAO,MAAM,gBAAgB,YACnB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAC1E,cAYF,CAAC;AAOF,wBAAgB,aAAa,CAAC,IAAI,GAAE,UAAgC,GAAG,MAAM,CAgB5E"}
|
package/dist/api.js
CHANGED
|
@@ -1,85 +1,115 @@
|
|
|
1
1
|
import { JA4Database } from "./db.js";
|
|
2
|
+
import { verifyProcaptchaOutput } from "./verify.js";
|
|
2
3
|
import { getLogger } from "@prosopo/logger";
|
|
3
4
|
import express from "express";
|
|
4
5
|
import { ProsopoApiError } from "@prosopo/common";
|
|
5
6
|
import { getJA4 } from "@prosopo/provider";
|
|
6
7
|
import { ClientApiPaths, VerifySolutionBody, decodeProcaptchaOutput } from "@prosopo/types";
|
|
8
|
+
import { rateLimit } from "express-rate-limit";
|
|
7
9
|
//#region src/api.ts
|
|
10
|
+
var DEFAULT_MONGO_URL = "mongodb://localhost:27017";
|
|
11
|
+
var DEFAULT_MONGO_DBNAME = "client";
|
|
12
|
+
var DEFAULT_MONGO_AUTH_SOURCE = "admin";
|
|
13
|
+
var createDatabase = (env = process.env) => new JA4Database(env.MONGO_URL || "mongodb://localhost:27017", env.MONGO_DBNAME || "client", env.MONGO_AUTH_SOURCE || "admin");
|
|
14
|
+
var defaultRouterDeps = () => ({
|
|
15
|
+
db: createDatabase(),
|
|
16
|
+
getJA4,
|
|
17
|
+
decodeToken: decodeProcaptchaOutput,
|
|
18
|
+
logger: getLogger("info", "provider-mock:api")
|
|
19
|
+
});
|
|
8
20
|
/**
|
|
9
|
-
*
|
|
21
|
+
* Verify a solution, as the real provider would.
|
|
10
22
|
*
|
|
11
|
-
*
|
|
23
|
+
* A body that does not parse is the caller's fault and is reported as a 400; a
|
|
24
|
+
* token that parses but cannot be decoded is reported as a 500, because at that
|
|
25
|
+
* point the request looked well formed and the mock cannot tell the difference
|
|
26
|
+
* between a corrupt token and a bug of its own.
|
|
12
27
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param {string} commitmentId - The captcha solution to look up
|
|
21
|
-
*/
|
|
22
|
-
router.post(ClientApiPaths.VerifyImageCaptchaSolutionDapp, async (req, res, next) => {
|
|
23
|
-
let body;
|
|
24
|
-
try {
|
|
25
|
-
body = VerifySolutionBody.parse(req.body);
|
|
26
|
-
} catch (err) {
|
|
27
|
-
return next(new ProsopoApiError("CAPTCHA.PARSE_ERROR", {
|
|
28
|
-
context: {
|
|
29
|
-
error: err,
|
|
30
|
-
code: 400
|
|
31
|
-
},
|
|
32
|
-
logLevel: "info"
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
const { token } = body;
|
|
37
|
-
const { user, dapp, commitmentId } = decodeProcaptchaOutput(token);
|
|
38
|
-
const testCommitmentId = "0x123456789test";
|
|
39
|
-
const testAccount = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
|
|
40
|
-
const testDapp = "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM";
|
|
41
|
-
let statusMessage = "API.USER_NOT_VERIFIED";
|
|
42
|
-
let approved = false;
|
|
43
|
-
if (user && user === testAccount || commitmentId && commitmentId === testCommitmentId || dapp && dapp === testDapp) {
|
|
44
|
-
approved = true;
|
|
45
|
-
statusMessage = "API.USER_VERIFIED";
|
|
46
|
-
return res.json({
|
|
47
|
-
status: req.t(statusMessage),
|
|
48
|
-
verified: approved,
|
|
49
|
-
commitmentId: testCommitmentId
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return res.json({
|
|
53
|
-
status: req.t(statusMessage),
|
|
54
|
-
verified: false
|
|
55
|
-
});
|
|
56
|
-
} catch (err) {
|
|
57
|
-
return next(new ProsopoApiError("API.UNKNOWN", { context: {
|
|
28
|
+
var createVerifyHandler = (deps) => async (req, res, next) => {
|
|
29
|
+
let body;
|
|
30
|
+
try {
|
|
31
|
+
body = VerifySolutionBody.parse(req.body);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return next(new ProsopoApiError("CAPTCHA.PARSE_ERROR", {
|
|
34
|
+
context: {
|
|
58
35
|
error: err,
|
|
59
|
-
code:
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
code: 400
|
|
37
|
+
},
|
|
38
|
+
logLevel: "info"
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const outcome = verifyProcaptchaOutput(deps.decodeToken(body.token));
|
|
43
|
+
res.json({
|
|
44
|
+
status: req.t(outcome.statusMessage),
|
|
45
|
+
verified: outcome.verified,
|
|
46
|
+
...outcome.commitmentId === void 0 ? {} : { commitmentId: outcome.commitmentId }
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return next(new ProsopoApiError("API.UNKNOWN", { context: {
|
|
50
|
+
error: err,
|
|
51
|
+
code: 500
|
|
52
|
+
} }));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/** Record the caller's JA4 fingerprint and hand it back to them. */
|
|
56
|
+
var createTestHandler = (deps) => async (req, res) => {
|
|
57
|
+
try {
|
|
58
|
+
const { ja4PlusFingerprint } = await deps.getJA4(req.headers, deps.logger);
|
|
64
59
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await db.addOrUpdateJA4Record({
|
|
69
|
-
ja4_fingerprint: ja4PlusFingerprint.ja4PlusFingerprint,
|
|
60
|
+
await deps.db.connect();
|
|
61
|
+
await deps.db.addOrUpdateJA4Record({
|
|
62
|
+
ja4_fingerprint: ja4PlusFingerprint,
|
|
70
63
|
user_agent_string: req.headers["user-agent"] || ""
|
|
71
64
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ja4: ja4PlusFingerprint.ja4PlusFingerprint,
|
|
75
|
-
ua: req.headers["user-agent"]
|
|
76
|
-
});
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.error("Error parsing ClientHello:", e);
|
|
79
|
-
return res.status(500).send("Error parsing ClientHello.");
|
|
65
|
+
} finally {
|
|
66
|
+
await deps.db.close();
|
|
80
67
|
}
|
|
81
|
-
|
|
68
|
+
res.json({
|
|
69
|
+
ja4: ja4PlusFingerprint,
|
|
70
|
+
ua: req.headers["user-agent"]
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
deps.logger.error(() => ({
|
|
74
|
+
err: e instanceof Error ? e : new Error(String(e)),
|
|
75
|
+
msg: "Failed to record the caller's JA4 fingerprint"
|
|
76
|
+
}));
|
|
77
|
+
res.status(500).send("Failed to record the caller's JA4 fingerprint.");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Both routes do unauthenticated work on the caller's behalf — one verifies a
|
|
82
|
+
* token, the other writes a fingerprint to mongo — so an unthrottled client can
|
|
83
|
+
* drive the database as fast as it can send. The window is generous enough that
|
|
84
|
+
* the demos and cypress runs never see it.
|
|
85
|
+
*/
|
|
86
|
+
var verifyRateLimit = () => rateLimit({
|
|
87
|
+
windowMs: 6e4,
|
|
88
|
+
limit: 600,
|
|
89
|
+
standardHeaders: true,
|
|
90
|
+
legacyHeaders: false
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Adapt a handler written against the narrow request/response types above to
|
|
94
|
+
* the express signature. Express hands the same objects through untouched; the
|
|
95
|
+
* narrow types exist only so tests can pass plain objects.
|
|
96
|
+
*/
|
|
97
|
+
var toRequestHandler = (handler) => {
|
|
98
|
+
const adapted = (req, res, next) => {
|
|
99
|
+
handler(req, res, next).catch(next);
|
|
100
|
+
};
|
|
101
|
+
return adapted;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Returns a router connected to the database which can interact with the Proposo protocol
|
|
105
|
+
*
|
|
106
|
+
* @return {Router} - A middleware router that can interact with the Prosopo protocol
|
|
107
|
+
*/
|
|
108
|
+
function prosopoRouter(deps = defaultRouterDeps()) {
|
|
109
|
+
const router = express.Router();
|
|
110
|
+
router.post(ClientApiPaths.VerifyImageCaptchaSolutionDapp, verifyRateLimit(), toRequestHandler(createVerifyHandler(deps)));
|
|
111
|
+
router.get("/test", verifyRateLimit(), toRequestHandler(createTestHandler(deps)));
|
|
82
112
|
return router;
|
|
83
113
|
}
|
|
84
114
|
//#endregion
|
|
85
|
-
export { prosopoRouter };
|
|
115
|
+
export { DEFAULT_MONGO_AUTH_SOURCE, DEFAULT_MONGO_DBNAME, DEFAULT_MONGO_URL, createDatabase, createTestHandler, createVerifyHandler, defaultRouterDeps, prosopoRouter, toRequestHandler, verifyRateLimit };
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAe,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,mBA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