@prosopo/client-example-server 2.7.123 → 2.7.125
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 +4 -4
- package/.turbo/turbo-build$colon$tsc.log +21 -21
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +22 -0
- package/dist/app.d.ts +15 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +71 -39
- package/dist/app.js.map +1 -1
- package/dist/cjs/app.cjs +79 -37
- package/dist/cjs/controllers/auth.cjs +11 -9
- package/dist/cjs/routes/routes.cjs +1 -1
- package/dist/controllers/auth.d.ts +1 -1
- package/dist/controllers/auth.d.ts.map +1 -1
- package/dist/controllers/auth.js +11 -9
- package/dist/controllers/auth.js.map +1 -1
- package/dist/routes/routes.d.ts.map +1 -1
- package/dist/routes/routes.js +1 -1
- package/dist/routes/routes.js.map +1 -1
- package/dist/tests/app.unit.test.d.ts +2 -0
- package/dist/tests/app.unit.test.d.ts.map +1 -0
- package/dist/tests/app.unit.test.js +318 -0
- package/dist/tests/app.unit.test.js.map +1 -0
- package/dist/tests/appEntrypoint.unit.test.d.ts +2 -0
- package/dist/tests/appEntrypoint.unit.test.d.ts.map +1 -0
- package/dist/tests/appEntrypoint.unit.test.js +100 -0
- package/dist/tests/appEntrypoint.unit.test.js.map +1 -0
- package/dist/tests/auth.unit.test.d.ts +2 -0
- package/dist/tests/auth.unit.test.d.ts.map +1 -0
- package/dist/tests/auth.unit.test.js +426 -0
- package/dist/tests/auth.unit.test.js.map +1 -0
- package/dist/tests/authHarness.d.ts +40 -0
- package/dist/tests/authHarness.d.ts.map +1 -0
- package/dist/tests/authHarness.js +57 -0
- package/dist/tests/authHarness.js.map +1 -0
- package/dist/tests/clientExampleServer.test-d.d.ts +2 -0
- package/dist/tests/clientExampleServer.test-d.d.ts.map +1 -0
- package/dist/tests/clientExampleServer.test-d.js +84 -0
- package/dist/tests/clientExampleServer.test-d.js.map +1 -0
- package/dist/tests/routes.unit.test.d.ts +2 -0
- package/dist/tests/routes.unit.test.d.ts.map +1 -0
- package/dist/tests/routes.unit.test.js +123 -0
- package/dist/tests/routes.unit.test.js.map +1 -0
- package/dist/tests/utils.unit.test.d.ts +2 -0
- package/dist/tests/utils.unit.test.d.ts.map +1 -0
- package/dist/tests/utils.unit.test.js +125 -0
- package/dist/tests/utils.unit.test.js.map +1 -0
- package/package.json +7 -4
- package/src/app.ts +114 -73
- package/src/controllers/auth.ts +40 -31
- package/src/routes/routes.ts +5 -2
- package/src/tests/app.unit.test.ts +428 -0
- package/src/tests/appEntrypoint.unit.test.ts +154 -0
- package/src/tests/auth.unit.test.ts +859 -0
- package/src/tests/authHarness.ts +131 -0
- package/src/tests/clientExampleServer.test-d.ts +146 -0
- package/src/tests/routes.unit.test.ts +166 -0
- package/src/tests/utils.unit.test.ts +169 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.test.config.ts +18 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/client-example-server@2.7.
|
|
2
|
+
> @prosopo/client-example-server@2.7.125 build:cjs
|
|
3
3
|
> NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
|
|
4
4
|
|
|
5
5
|
ViteCommonJSConfig: .
|
|
@@ -55,7 +55,7 @@ dist/cjs/models/user.cjs 0.60 kB │ gzip: 0.26 kB
|
|
|
55
55
|
dist/cjs/utils/connection.cjs 0.89 kB │ gzip: 0.44 kB
|
|
56
56
|
dist/cjs/routes/routes.cjs 0.94 kB │ gzip: 0.41 kB
|
|
57
57
|
dist/cjs/_virtual/_rolldown/runtime.cjs 1.00 kB │ gzip: 0.50 kB
|
|
58
|
-
dist/cjs/app.cjs
|
|
59
|
-
dist/cjs/controllers/auth.cjs 7.
|
|
58
|
+
dist/cjs/app.cjs 6.62 kB │ gzip: 2.36 kB
|
|
59
|
+
dist/cjs/controllers/auth.cjs 7.62 kB │ gzip: 2.39 kB
|
|
60
60
|
|
|
61
|
-
[32m✓ built in
|
|
61
|
+
[32m✓ built in 59ms[39m
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/client-example-server@2.7.
|
|
2
|
+
> @prosopo/client-example-server@2.7.125 build:tsc
|
|
3
3
|
> tsc --build --verbose
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
11:41:21 PM - Projects in this build:
|
|
6
6
|
* ../../dev/config/tsconfig.json
|
|
7
7
|
* ../../packages/locale/tsconfig.json
|
|
8
8
|
* ../../packages/util/tsconfig.json
|
|
@@ -22,41 +22,41 @@
|
|
|
22
22
|
* ../../packages/server/tsconfig.json
|
|
23
23
|
* tsconfig.json
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
11:41:21 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'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
11:41:21 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'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
11:41:21 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'
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
11:41:21 PM - Project '../../packages/logger/tsconfig.json' is up to date because newest input '../../packages/logger/src/index.ts' is older than output '../../packages/logger/tsconfig.tsbuildinfo'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
11:41:21 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'
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
11:41:21 PM - Project '../../packages/types/tsconfig.json' is up to date because newest input '../../packages/types/src/procaptcha/api.ts' is older than output '../../packages/types/tsconfig.tsbuildinfo'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
11:41:21 PM - Project '../../packages/common/tsconfig.json' is up to date because newest input '../../packages/common/src/error.ts' is older than output '../../packages/common/tsconfig.tsbuildinfo'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
11:41:21 PM - Project '../../packages/api-route/tsconfig.json' is up to date because newest input '../../packages/api-route/src/index.ts' is older than output '../../packages/api-route/tsconfig.tsbuildinfo'
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
11:41:21 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'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
11:41:21 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'
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
11:41:21 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'
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
11:41:21 PM - Project '../../packages/types-database/tsconfig.json' is up to date because newest input '../../packages/types-database/src/types/captcha.ts' is older than output '../../packages/types-database/tsconfig.tsbuildinfo'
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
11:41:21 PM - Project '../../packages/database/tsconfig.json' is up to date because newest input '../../packages/database/src/tests/mongoGlobalSetup.ts' is older than output '../../packages/database/tsconfig.tsbuildinfo'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
11:41:21 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'
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
11:41:21 PM - Project '../../packages/keyring/tsconfig.json' is up to date because newest input '../../packages/keyring/src/index.ts' is older than output '../../packages/keyring/tsconfig.tsbuildinfo'
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
11:41:21 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'
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
11:41:21 PM - Project '../../packages/server/tsconfig.json' is up to date because newest input '../../packages/server/src/config.ts' is older than output '../../packages/server/tsconfig.tsbuildinfo'
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
11:41:21 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
11:41:21 PM - Building project '/home/runner/work/captcha/captcha/demos/client-example-server/tsconfig.json'...
|
|
62
62
|
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/client-example-server@2.7.
|
|
2
|
+
> @prosopo/client-example-server@2.7.125 build
|
|
3
3
|
> npm run build:cross-env -- --mode ${NODE_ENV:-development}
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @prosopo/client-example-server@2.7.
|
|
6
|
+
> @prosopo/client-example-server@2.7.125 build:cross-env
|
|
7
7
|
> vite build --config vite.esm.config.ts --mode production
|
|
8
8
|
|
|
9
9
|
ViteEsmConfig: .
|
|
@@ -58,8 +58,8 @@ dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
|
58
58
|
dist/utils/database.js 0.23 kB │ gzip: 0.17 kB
|
|
59
59
|
dist/models/user.js 0.45 kB │ gzip: 0.21 kB
|
|
60
60
|
dist/utils/connection.js 0.64 kB │ gzip: 0.35 kB
|
|
61
|
-
dist/routes/routes.js 0.
|
|
62
|
-
dist/app.js
|
|
63
|
-
dist/controllers/auth.js 6.
|
|
61
|
+
dist/routes/routes.js 0.79 kB │ gzip: 0.37 kB
|
|
62
|
+
dist/app.js 5.54 kB │ gzip: 2.16 kB
|
|
63
|
+
dist/controllers/auth.js 6.94 kB │ gzip: 2.26 kB
|
|
64
64
|
|
|
65
|
-
[32m✓ built in
|
|
65
|
+
[32m✓ built in 55ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @prosopo/client-example-server
|
|
2
2
|
|
|
3
|
+
## 2.7.125
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [71a5952]
|
|
7
|
+
- @prosopo/keyring@2.9.62
|
|
8
|
+
- @prosopo/server@2.10.43
|
|
9
|
+
|
|
10
|
+
## 2.7.124
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fe9424f: Add unit and type tests for the client example server, and fix the defects they exposed:
|
|
14
|
+
|
|
15
|
+
- `getRoutes` built one module-level router shared by every call, so a second call stacked handlers on the first call's bound config.
|
|
16
|
+
- `isAuth` could fall through without sending a response, and could send twice for a malformed `Authorization` header.
|
|
17
|
+
- The `if (passwordHash)` guard in signup had no else branch, leaving a request hanging when it was falsy.
|
|
18
|
+
- A `serverUrl` without a port resolved to `NaN`, so the server listened on an arbitrary free port; it now falls back to 9228.
|
|
19
|
+
- Removed the unreachable `OPTIONS` handler (`cors()` already answers preflight) and leftover debug logging.
|
|
20
|
+
- `app.ts` no longer boots a server on import; it exports `createApp`, `startServer` and `main`, and only runs when executed directly.
|
|
21
|
+
- Updated dependencies [69f8dcd]
|
|
22
|
+
- @prosopo/database@3.15.21
|
|
23
|
+
- @prosopo/server@2.10.42
|
|
24
|
+
|
|
3
25
|
## 2.7.123
|
|
4
26
|
### Patch Changes
|
|
5
27
|
|
package/dist/app.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Server } from "node:http";
|
|
2
|
+
import type { ProsopoServerConfigOutput } from "@prosopo/types";
|
|
3
|
+
import express from "express";
|
|
4
|
+
export declare enum ProsopoVerificationType {
|
|
5
|
+
api = "api",
|
|
6
|
+
local = "local"
|
|
7
|
+
}
|
|
8
|
+
export declare const resolveVerifyEndpoint: () => string;
|
|
9
|
+
export declare const resolveVerifyType: () => ProsopoVerificationType;
|
|
10
|
+
export declare const isDevelopmentOrTest: () => boolean;
|
|
11
|
+
export declare const createApp: () => express.Express;
|
|
12
|
+
export declare const DEFAULT_PORT = 9228;
|
|
13
|
+
export declare const resolvePort: (config: ProsopoServerConfigOutput) => number;
|
|
14
|
+
export declare const startServer: (app: express.Express, port: number, dirname?: string) => Server;
|
|
15
|
+
export declare function main(): Promise<Server>;
|
|
2
16
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AASxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,oBAAY,uBAAuB;IAClC,GAAG,QAAQ;IACX,KAAK,UAAU;CACf;AAUD,eAAO,MAAM,qBAAqB,QAAO,MAQxC,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAO,uBAKN,CAAC;AAEhC,eAAO,MAAM,mBAAmB,QAAO,OACmC,CAAC;AAG3E,eAAO,MAAM,SAAS,QAAO,OAAO,CAAC,OA8BpC,CAAC;AAEF,eAAO,MAAM,YAAY,OAAO,CAAC;AAOjC,eAAO,MAAM,WAAW,WAAY,yBAAyB,KAAG,MAM/D,CAAC;AAMF,eAAO,MAAM,WAAW,QAClB,OAAO,CAAC,OAAO,QACd,MAAM,YACH,MAAM,KACb,MA6BF,CAAC;AAEF,wBAAsB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAwC5C"}
|
package/dist/app.js
CHANGED
|
@@ -11,23 +11,32 @@ import { ProsopoEnvError } from "@prosopo/common";
|
|
|
11
11
|
import { loadEnv } from "@prosopo/dotenv";
|
|
12
12
|
import { getLogger } from "@prosopo/logger";
|
|
13
13
|
import { getServerConfig } from "@prosopo/server";
|
|
14
|
-
import { at } from "@prosopo/util";
|
|
14
|
+
import { at, isMain } from "@prosopo/util";
|
|
15
15
|
import cors from "cors";
|
|
16
16
|
import express from "express";
|
|
17
17
|
//#region src/app.ts
|
|
18
|
-
loadEnv();
|
|
19
18
|
var ProsopoVerificationType = /* @__PURE__ */ function(ProsopoVerificationType) {
|
|
20
19
|
ProsopoVerificationType["api"] = "api";
|
|
21
20
|
ProsopoVerificationType["local"] = "local";
|
|
22
21
|
return ProsopoVerificationType;
|
|
23
|
-
}(
|
|
22
|
+
}({});
|
|
24
23
|
var logger = getLogger("info", "client-example-server:app");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The siteverify endpoint the deployment talks to. Non-production
|
|
26
|
+
* environments get their name as a subdomain prefix. An unset NODE_ENV is
|
|
27
|
+
* treated as production: prefixing it produced `undefined-api.prosopo.io`,
|
|
28
|
+
* a host that does not exist.
|
|
29
|
+
*/
|
|
30
|
+
var resolveVerifyEndpoint = () => {
|
|
31
|
+
const environment = process.env.NODE_ENV;
|
|
32
|
+
const apiPrefix = !environment || environment === "production" ? "" : `${environment}-`;
|
|
33
|
+
return process.env.PROSOPO_VERIFY_ENDPOINT || `https://${apiPrefix}api.prosopo.io/siteverify`;
|
|
34
|
+
};
|
|
35
|
+
/** Anything the enum doesn't name falls back to the hosted API. */
|
|
36
|
+
var resolveVerifyType = () => Object.keys(ProsopoVerificationType).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
|
|
37
|
+
var isDevelopmentOrTest = () => process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
38
|
+
/** The express app, minus the routes, which need a database connection. */
|
|
39
|
+
var createApp = () => {
|
|
31
40
|
const app = express();
|
|
32
41
|
app.set("trust proxy", 1);
|
|
33
42
|
app.use(cors({
|
|
@@ -42,10 +51,55 @@ async function main() {
|
|
|
42
51
|
res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Auth-Token, Authorization");
|
|
43
52
|
next();
|
|
44
53
|
});
|
|
45
|
-
app
|
|
46
|
-
|
|
54
|
+
return app;
|
|
55
|
+
};
|
|
56
|
+
var DEFAULT_PORT = 9228;
|
|
57
|
+
/**
|
|
58
|
+
* The port is the last segment of the configured server URL. A URL without
|
|
59
|
+
* one used to yield NaN, which node turns into an arbitrary free port — the
|
|
60
|
+
* server came up on an address nothing was configured to talk to.
|
|
61
|
+
*/
|
|
62
|
+
var resolvePort = (config) => {
|
|
63
|
+
if (!config.serverUrl) return DEFAULT_PORT;
|
|
64
|
+
const segments = config.serverUrl.split(":");
|
|
65
|
+
if (segments.length < 3) return DEFAULT_PORT;
|
|
66
|
+
const port = Number.parseInt(at(segments, 2));
|
|
67
|
+
return Number.isNaN(port) ? DEFAULT_PORT : port;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* HTTPS in development/test when the repo's certificates exist, plain HTTP
|
|
71
|
+
* otherwise — in production Caddy terminates TLS.
|
|
72
|
+
*/
|
|
73
|
+
var startServer = (app, port, dirname = path.dirname(fileURLToPath(import.meta.url))) => {
|
|
74
|
+
if (isDevelopmentOrTest()) {
|
|
75
|
+
const certsDir = path.resolve(dirname, "../../../certs");
|
|
76
|
+
const keyPath = path.join(certsDir, "server.key");
|
|
77
|
+
const certPath = path.join(certsDir, "server.crt");
|
|
78
|
+
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
79
|
+
const httpsOptions = {
|
|
80
|
+
key: fs.readFileSync(keyPath),
|
|
81
|
+
cert: fs.readFileSync(certPath)
|
|
82
|
+
};
|
|
83
|
+
return https.createServer(httpsOptions, app).listen(port, () => {
|
|
84
|
+
logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
logger.warn(() => ({ msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development." }));
|
|
88
|
+
return http.createServer(app).listen(port, () => {
|
|
89
|
+
logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return http.createServer(app).listen(port, () => {
|
|
93
|
+
logger.info(() => ({ msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)` }));
|
|
47
94
|
});
|
|
48
|
-
|
|
95
|
+
};
|
|
96
|
+
async function main() {
|
|
97
|
+
loadEnv();
|
|
98
|
+
const verifyEndpoint = resolveVerifyEndpoint();
|
|
99
|
+
logger.info(() => ({ data: { verifyEndpoint } }));
|
|
100
|
+
const verifyType = resolveVerifyType();
|
|
101
|
+
const app = createApp();
|
|
102
|
+
if (!process.env.MONGO_URI && !isDevelopmentOrTest()) throw new Error("Cannot run mongo memory when NODE_ENV is neither development nor test");
|
|
49
103
|
logger.info(() => ({ msg: process.env.MONGO_URI }));
|
|
50
104
|
const uri = process.env.MONGO_URI || await memoryServerSetup();
|
|
51
105
|
logger.info(() => ({
|
|
@@ -66,40 +120,18 @@ async function main() {
|
|
|
66
120
|
data: { config }
|
|
67
121
|
}));
|
|
68
122
|
app.use(getRoutes(mongoose, config, verifyEndpoint, verifyType));
|
|
69
|
-
const port =
|
|
123
|
+
const port = resolvePort(config);
|
|
70
124
|
logger.info(() => ({
|
|
71
125
|
msg: "Listening on port",
|
|
72
126
|
data: { port }
|
|
73
127
|
}));
|
|
74
|
-
|
|
75
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
76
|
-
const __dirname = path.dirname(__filename);
|
|
77
|
-
const certsDir = path.resolve(__dirname, "../../../certs");
|
|
78
|
-
const keyPath = path.join(certsDir, "server.key");
|
|
79
|
-
const certPath = path.join(certsDir, "server.crt");
|
|
80
|
-
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
81
|
-
const httpsOptions = {
|
|
82
|
-
key: fs.readFileSync(keyPath),
|
|
83
|
-
cert: fs.readFileSync(certPath)
|
|
84
|
-
};
|
|
85
|
-
https.createServer(httpsOptions, app).listen(port, () => {
|
|
86
|
-
logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
|
|
87
|
-
});
|
|
88
|
-
} else {
|
|
89
|
-
logger.warn(() => ({ msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development." }));
|
|
90
|
-
http.createServer(app).listen(port, () => {
|
|
91
|
-
logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
} else http.createServer(app).listen(port, () => {
|
|
95
|
-
logger.info(() => ({ msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)` }));
|
|
96
|
-
});
|
|
128
|
+
return startServer(app, port);
|
|
97
129
|
}
|
|
98
|
-
main().then(() => {
|
|
130
|
+
if (isMain(import.meta.url)) main().then(() => {
|
|
99
131
|
logger.info(() => ({ msg: "Server started" }));
|
|
100
132
|
}).catch((err) => {
|
|
101
133
|
logger.error(() => ({ err }));
|
|
102
|
-
process.exit();
|
|
134
|
+
process.exit(1);
|
|
103
135
|
});
|
|
104
136
|
//#endregion
|
|
105
|
-
export {};
|
|
137
|
+
export { DEFAULT_PORT, ProsopoVerificationType, createApp, isDevelopmentOrTest, main, resolvePort, resolveVerifyEndpoint, resolveVerifyType, startServer };
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,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EjC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAElE,OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC;AAID,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC7B,IAAI,EAAE;SACJ,IAAI,CAAC,GAAG,EAAE;QACV,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACd,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;QAG9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/app.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
2
|
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_routes = require("./routes/routes.cjs");
|
|
3
4
|
const require_connection = require("./utils/connection.cjs");
|
|
@@ -21,19 +22,28 @@ cors = require_runtime.__toESM(cors, 1);
|
|
|
21
22
|
let express = require("express");
|
|
22
23
|
express = require_runtime.__toESM(express, 1);
|
|
23
24
|
//#region src/app.ts
|
|
24
|
-
(0, _prosopo_dotenv.loadEnv)();
|
|
25
25
|
var ProsopoVerificationType = /* @__PURE__ */ function(ProsopoVerificationType) {
|
|
26
26
|
ProsopoVerificationType["api"] = "api";
|
|
27
27
|
ProsopoVerificationType["local"] = "local";
|
|
28
28
|
return ProsopoVerificationType;
|
|
29
|
-
}(
|
|
29
|
+
}({});
|
|
30
30
|
var logger = (0, _prosopo_logger.getLogger)("info", "client-example-server:app");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The siteverify endpoint the deployment talks to. Non-production
|
|
33
|
+
* environments get their name as a subdomain prefix. An unset NODE_ENV is
|
|
34
|
+
* treated as production: prefixing it produced `undefined-api.prosopo.io`,
|
|
35
|
+
* a host that does not exist.
|
|
36
|
+
*/
|
|
37
|
+
var resolveVerifyEndpoint = () => {
|
|
38
|
+
const environment = process.env.NODE_ENV;
|
|
39
|
+
const apiPrefix = !environment || environment === "production" ? "" : `${environment}-`;
|
|
40
|
+
return process.env.PROSOPO_VERIFY_ENDPOINT || `https://${apiPrefix}api.prosopo.io/siteverify`;
|
|
41
|
+
};
|
|
42
|
+
/** Anything the enum doesn't name falls back to the hosted API. */
|
|
43
|
+
var resolveVerifyType = () => Object.keys(ProsopoVerificationType).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
|
|
44
|
+
var isDevelopmentOrTest = () => process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
45
|
+
/** The express app, minus the routes, which need a database connection. */
|
|
46
|
+
var createApp = () => {
|
|
37
47
|
const app = (0, express.default)();
|
|
38
48
|
app.set("trust proxy", 1);
|
|
39
49
|
app.use((0, cors.default)({
|
|
@@ -48,10 +58,55 @@ async function main() {
|
|
|
48
58
|
res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Auth-Token, Authorization");
|
|
49
59
|
next();
|
|
50
60
|
});
|
|
51
|
-
app
|
|
52
|
-
|
|
61
|
+
return app;
|
|
62
|
+
};
|
|
63
|
+
var DEFAULT_PORT = 9228;
|
|
64
|
+
/**
|
|
65
|
+
* The port is the last segment of the configured server URL. A URL without
|
|
66
|
+
* one used to yield NaN, which node turns into an arbitrary free port — the
|
|
67
|
+
* server came up on an address nothing was configured to talk to.
|
|
68
|
+
*/
|
|
69
|
+
var resolvePort = (config) => {
|
|
70
|
+
if (!config.serverUrl) return DEFAULT_PORT;
|
|
71
|
+
const segments = config.serverUrl.split(":");
|
|
72
|
+
if (segments.length < 3) return DEFAULT_PORT;
|
|
73
|
+
const port = Number.parseInt((0, _prosopo_util.at)(segments, 2));
|
|
74
|
+
return Number.isNaN(port) ? DEFAULT_PORT : port;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* HTTPS in development/test when the repo's certificates exist, plain HTTP
|
|
78
|
+
* otherwise — in production Caddy terminates TLS.
|
|
79
|
+
*/
|
|
80
|
+
var startServer = (app, port, dirname = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href))) => {
|
|
81
|
+
if (isDevelopmentOrTest()) {
|
|
82
|
+
const certsDir = node_path.default.resolve(dirname, "../../../certs");
|
|
83
|
+
const keyPath = node_path.default.join(certsDir, "server.key");
|
|
84
|
+
const certPath = node_path.default.join(certsDir, "server.crt");
|
|
85
|
+
if (node_fs.default.existsSync(keyPath) && node_fs.default.existsSync(certPath)) {
|
|
86
|
+
const httpsOptions = {
|
|
87
|
+
key: node_fs.default.readFileSync(keyPath),
|
|
88
|
+
cert: node_fs.default.readFileSync(certPath)
|
|
89
|
+
};
|
|
90
|
+
return node_https.default.createServer(httpsOptions, app).listen(port, () => {
|
|
91
|
+
logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
logger.warn(() => ({ msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development." }));
|
|
95
|
+
return node_http.default.createServer(app).listen(port, () => {
|
|
96
|
+
logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return node_http.default.createServer(app).listen(port, () => {
|
|
100
|
+
logger.info(() => ({ msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)` }));
|
|
53
101
|
});
|
|
54
|
-
|
|
102
|
+
};
|
|
103
|
+
async function main() {
|
|
104
|
+
(0, _prosopo_dotenv.loadEnv)();
|
|
105
|
+
const verifyEndpoint = resolveVerifyEndpoint();
|
|
106
|
+
logger.info(() => ({ data: { verifyEndpoint } }));
|
|
107
|
+
const verifyType = resolveVerifyType();
|
|
108
|
+
const app = createApp();
|
|
109
|
+
if (!process.env.MONGO_URI && !isDevelopmentOrTest()) throw new Error("Cannot run mongo memory when NODE_ENV is neither development nor test");
|
|
55
110
|
logger.info(() => ({ msg: process.env.MONGO_URI }));
|
|
56
111
|
const uri = process.env.MONGO_URI || await require_database.default();
|
|
57
112
|
logger.info(() => ({
|
|
@@ -72,39 +127,26 @@ async function main() {
|
|
|
72
127
|
data: { config }
|
|
73
128
|
}));
|
|
74
129
|
app.use(require_routes.default(mongoose, config, verifyEndpoint, verifyType));
|
|
75
|
-
const port =
|
|
130
|
+
const port = resolvePort(config);
|
|
76
131
|
logger.info(() => ({
|
|
77
132
|
msg: "Listening on port",
|
|
78
133
|
data: { port }
|
|
79
134
|
}));
|
|
80
|
-
|
|
81
|
-
const __filename = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
82
|
-
const __dirname = node_path.default.dirname(__filename);
|
|
83
|
-
const certsDir = node_path.default.resolve(__dirname, "../../../certs");
|
|
84
|
-
const keyPath = node_path.default.join(certsDir, "server.key");
|
|
85
|
-
const certPath = node_path.default.join(certsDir, "server.crt");
|
|
86
|
-
if (node_fs.default.existsSync(keyPath) && node_fs.default.existsSync(certPath)) {
|
|
87
|
-
const httpsOptions = {
|
|
88
|
-
key: node_fs.default.readFileSync(keyPath),
|
|
89
|
-
cert: node_fs.default.readFileSync(certPath)
|
|
90
|
-
};
|
|
91
|
-
node_https.default.createServer(httpsOptions, app).listen(port, () => {
|
|
92
|
-
logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
|
|
93
|
-
});
|
|
94
|
-
} else {
|
|
95
|
-
logger.warn(() => ({ msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development." }));
|
|
96
|
-
node_http.default.createServer(app).listen(port, () => {
|
|
97
|
-
logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
} else node_http.default.createServer(app).listen(port, () => {
|
|
101
|
-
logger.info(() => ({ msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)` }));
|
|
102
|
-
});
|
|
135
|
+
return startServer(app, port);
|
|
103
136
|
}
|
|
104
|
-
main().then(() => {
|
|
137
|
+
if ((0, _prosopo_util.isMain)(require("url").pathToFileURL(__filename).href)) main().then(() => {
|
|
105
138
|
logger.info(() => ({ msg: "Server started" }));
|
|
106
139
|
}).catch((err) => {
|
|
107
140
|
logger.error(() => ({ err }));
|
|
108
|
-
process.exit();
|
|
141
|
+
process.exit(1);
|
|
109
142
|
});
|
|
110
143
|
//#endregion
|
|
144
|
+
exports.DEFAULT_PORT = DEFAULT_PORT;
|
|
145
|
+
exports.ProsopoVerificationType = ProsopoVerificationType;
|
|
146
|
+
exports.createApp = createApp;
|
|
147
|
+
exports.isDevelopmentOrTest = isDevelopmentOrTest;
|
|
148
|
+
exports.main = main;
|
|
149
|
+
exports.resolvePort = resolvePort;
|
|
150
|
+
exports.resolveVerifyEndpoint = resolveVerifyEndpoint;
|
|
151
|
+
exports.resolveVerifyType = resolveVerifyType;
|
|
152
|
+
exports.startServer = startServer;
|
|
@@ -54,7 +54,6 @@ var getPairAndSecretForSiteKey = (baseSecret, siteKey) => {
|
|
|
54
54
|
]) {
|
|
55
55
|
const newSecret = `${baseSecret}//${captchaType}`;
|
|
56
56
|
pair = (0, _prosopo_keyring.getPair)(newSecret);
|
|
57
|
-
console.log(`[PAIR CHECK] Checking pair for ${captchaType}: ${pair?.address} (expected: ${siteKey})`);
|
|
58
57
|
logger.info(() => ({
|
|
59
58
|
msg: "Checking pair",
|
|
60
59
|
data: {
|
|
@@ -64,7 +63,6 @@ var getPairAndSecretForSiteKey = (baseSecret, siteKey) => {
|
|
|
64
63
|
}
|
|
65
64
|
}));
|
|
66
65
|
if (pair.address === siteKey) {
|
|
67
|
-
console.log(`[PAIR CHECK] ✅ Match found for ${captchaType}!`);
|
|
68
66
|
secret = newSecret;
|
|
69
67
|
break;
|
|
70
68
|
}
|
|
@@ -118,7 +116,7 @@ var signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next
|
|
|
118
116
|
if (verified === true) {
|
|
119
117
|
const salt = (0, _polkadot_util_crypto.randomAsHex)(32);
|
|
120
118
|
const passwordHash = hashPassword(`${req.body.password}${salt}`);
|
|
121
|
-
|
|
119
|
+
return User.create({
|
|
122
120
|
email,
|
|
123
121
|
name: req.body.name,
|
|
124
122
|
password: passwordHash,
|
|
@@ -132,7 +130,8 @@ var signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next
|
|
|
132
130
|
}));
|
|
133
131
|
res.status(502).json({ message: "error while creating the user" });
|
|
134
132
|
});
|
|
135
|
-
}
|
|
133
|
+
}
|
|
134
|
+
res.status(401).json({
|
|
136
135
|
message: "user has not completed a captcha",
|
|
137
136
|
verified
|
|
138
137
|
});
|
|
@@ -172,16 +171,19 @@ var login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
|
|
|
172
171
|
};
|
|
173
172
|
var isAuth = (req, res) => {
|
|
174
173
|
const authHeader = req.get("Authorization") || "";
|
|
175
|
-
if (!authHeader) res.status(401).json({ message: "not authenticated" });
|
|
176
|
-
const
|
|
174
|
+
if (!authHeader) return res.status(401).json({ message: "not authenticated" });
|
|
175
|
+
const headerParts = authHeader.split(" ");
|
|
176
|
+
if (headerParts.length < 2) return res.status(401).json({ message: "not authenticated" });
|
|
177
|
+
const token = (0, _prosopo_util.at)(headerParts, 1);
|
|
178
|
+
if (!token) return res.status(401).json({ message: "not authenticated" });
|
|
177
179
|
let decodedToken = "";
|
|
178
180
|
try {
|
|
179
181
|
decodedToken = jsonwebtoken.default.verify(token, "secret");
|
|
180
182
|
} catch (err) {
|
|
181
|
-
res.status(500).json({ message: err.message || "could not decode the token" });
|
|
183
|
+
return res.status(500).json({ message: err.message || "could not decode the token" });
|
|
182
184
|
}
|
|
183
|
-
if (!decodedToken) res.status(401).json({ message: "unauthorized" });
|
|
184
|
-
|
|
185
|
+
if (!decodedToken) return res.status(401).json({ message: "unauthorized" });
|
|
186
|
+
return res.status(200).json({ message: "here is your resource" });
|
|
185
187
|
};
|
|
186
188
|
//#endregion
|
|
187
189
|
exports.isAuth = isAuth;
|
|
@@ -3,8 +3,8 @@ const require_auth = require("../controllers/auth.cjs");
|
|
|
3
3
|
let express = require("express");
|
|
4
4
|
express = require_runtime.__toESM(express, 1);
|
|
5
5
|
//#region src/routes/routes.ts
|
|
6
|
-
var router = express.default.Router();
|
|
7
6
|
function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
|
|
7
|
+
const router = express.default.Router();
|
|
8
8
|
router.post("/login", require_auth.login.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
9
9
|
router.post("/signup", require_auth.signup.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
10
10
|
router.get("/private", require_auth.isAuth);
|
|
@@ -3,6 +3,6 @@ import type { NextFunction, Request, Response } from "express";
|
|
|
3
3
|
import type { Connection } from "mongoose";
|
|
4
4
|
declare const signup: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
5
|
declare const login: (mongoose: Connection, config: ProsopoServerConfigOutput, verifyEndpoint: string, verifyType: string, req: Request, res: Response) => Promise<void>;
|
|
6
|
-
declare const isAuth: (req: Request, res: Response) =>
|
|
6
|
+
declare const isAuth: (req: Request, res: Response) => Response<any, Record<string, any>>;
|
|
7
7
|
export { signup, login, isAuth };
|
|
8
8
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAqBA,OAAO,EAMN,KAAK,yBAAyB,EAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAqBA,OAAO,EAMN,KAAK,yBAAyB,EAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAuJ3C,QAAA,MAAM,MAAM,aACD,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,QACP,YAAY,uDAyElB,CAAC;AAEF,QAAA,MAAM,KAAK,aACA,UAAU,UACZ,yBAAyB,kBACjB,MAAM,cACV,MAAM,OACb,OAAO,OACP,QAAQ,kBAsEb,CAAC;AAEF,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,uCAkC1C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|