@prosopo/client-example-server 2.7.171 → 2.7.173

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/package.json CHANGED
@@ -1,81 +1,82 @@
1
1
  {
2
- "name": "@prosopo/client-example-server",
3
- "version": "2.7.171",
4
- "description": "Backend for client-example",
5
- "main": "dist/app.js",
6
- "types": "dist/app.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "require": "./dist/cjs/index.cjs",
11
- "types": "./dist/app.d.ts"
12
- }
13
- },
14
- "type": "module",
15
- "engines": {
16
- "node": "^24",
17
- "npm": "^11"
18
- },
19
- "scripts": {
20
- "dev": "NODE_ENV=${NODE_ENV:-development}; vite serve --mode=$NODE_ENV --config ./vite.config.ts --host",
21
- "start": "NODE_ENV=${NODE_ENV:-development}; node ./dist/app.js",
22
- "start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
23
- "build": "npm run build:cross-env -- --mode ${NODE_ENV:-development}",
24
- "build:cross-env": "vite build --config vite.esm.config.ts",
25
- "build:tsc": "tsc --build --verbose",
26
- "build:cjs": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV",
27
- "docker-tag": "node ../../docker/docker-tag.mjs",
28
- "build:docker": "docker buildx build --progress=plain --tag $(npm run --silent docker-tag) --platform linux/amd64 -f ./Dockerfile ../..",
29
- "publish:docker": "docker push $(npm run --silent docker-tag)",
30
- "typecheck": "tsc --project tsconfig.types.json",
31
- "test": "NODE_ENV=${NODE_ENV:-test}; npx vitest run --config ./vite.test.config.ts",
32
- "test:watch": "NODE_ENV=${NODE_ENV:-test}; npx vitest --config ./vite.test.config.ts",
33
- "test:coverage": "NODE_ENV=${NODE_ENV:-test}; npx vitest run --coverage --config ./vite.test.config.ts",
34
- "bundle": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.config.ts --mode $NODE_ENV"
35
- },
36
- "repository": {
37
- "type": "git",
38
- "url": "git+https://github.com/prosopo/captcha.git",
39
- "directory": "demos/client-example-server"
40
- },
41
- "author": "PROSOPO LIMITED <info@prosopo.io>",
42
- "license": "Apache-2.0",
43
- "bugs": {
44
- "url": "https://github.com/prosopo/client-example-server/issues"
45
- },
46
- "homepage": "https://github.com/prosopo/client-example-server#readme",
47
- "dependencies": {
48
- "@noble/hashes": "2.4.0",
49
- "@polkadot/util": "14.0.3",
50
- "@polkadot/util-crypto": "14.0.3",
51
- "@prosopo/common": "3.1.61",
52
- "@prosopo/database": "4.1.3",
53
- "@prosopo/logger": "2.1.2",
54
- "@prosopo/dotenv": "3.0.59",
55
- "@prosopo/keyring": "2.10.0",
56
- "@prosopo/server": "2.12.14",
57
- "@prosopo/types": "5.12.0",
58
- "@prosopo/util": "3.3.13",
59
- "@typegoose/auto-increment": "5.0.1",
60
- "cors": "2.8.6",
61
- "express": "4.22.2",
62
- "jsonwebtoken": "9.0.3",
63
- "mongodb-memory-server": "10.3.0",
64
- "mongoose": "9.10.0",
65
- "zod": "3.23.8"
66
- },
67
- "devDependencies": {
68
- "@prosopo/config": "3.4.2",
69
- "@types/jsonwebtoken": "9.0.10",
70
- "@types/node": "22.10.2",
71
- "@vitest/coverage-v8": "4.1.11",
72
- "concurrently": "9.0.1",
73
- "del-cli": "6.0.0",
74
- "npm-run-all": "4.1.5",
75
- "tslib": "2.7.0",
76
- "tsx": "4.20.3",
77
- "typescript": "5.6.2",
78
- "vite": "8.1.5",
79
- "vitest": "4.1.11"
80
- }
81
- }
2
+ "name": "@prosopo/client-example-server",
3
+ "version": "2.7.173",
4
+ "description": "Backend for client-example",
5
+ "main": "dist/app.js",
6
+ "types": "dist/app.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/cjs/index.cjs",
11
+ "types": "./dist/app.d.ts"
12
+ }
13
+ },
14
+ "type": "module",
15
+ "engines": {
16
+ "node": "^24"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/prosopo/captcha.git",
21
+ "directory": "demos/client-example-server"
22
+ },
23
+ "author": "PROSOPO LIMITED <info@prosopo.io>",
24
+ "license": "Apache-2.0",
25
+ "bugs": {
26
+ "url": "https://github.com/prosopo/client-example-server/issues"
27
+ },
28
+ "homepage": "https://github.com/prosopo/client-example-server#readme",
29
+ "dependencies": {
30
+ "@noble/hashes": "2.4.0",
31
+ "@polkadot/util": "14.0.3",
32
+ "@polkadot/util-crypto": "14.0.3",
33
+ "@prosopo/common": "3.1.63",
34
+ "@prosopo/database": "4.2.0",
35
+ "@prosopo/logger": "2.1.3",
36
+ "@prosopo/dotenv": "3.0.60",
37
+ "@prosopo/keyring": "2.10.2",
38
+ "@prosopo/server": "2.13.0",
39
+ "@prosopo/types": "5.14.0",
40
+ "@prosopo/util": "3.3.14",
41
+ "@typegoose/auto-increment": "5.0.1",
42
+ "cors": "2.8.6",
43
+ "express": "4.22.2",
44
+ "jsonwebtoken": "9.0.3",
45
+ "mongodb-memory-server": "10.3.0",
46
+ "mongoose": "9.10.0",
47
+ "zod": "3.23.8"
48
+ },
49
+ "devDependencies": {
50
+ "@prosopo/config": "3.4.3",
51
+ "@types/cors": "2.8.19",
52
+ "@types/express": "4.17.25",
53
+ "@types/jsonwebtoken": "9.0.10",
54
+ "@types/node": "22.10.2",
55
+ "@vitest/coverage-v8": "4.1.11",
56
+ "concurrently": "9.0.1",
57
+ "del-cli": "6.0.0",
58
+ "npm-run-all": "4.1.5",
59
+ "tslib": "2.7.0",
60
+ "tsx": "4.20.3",
61
+ "typescript": "5.6.2",
62
+ "vite": "8.1.5",
63
+ "vitest": "4.1.11"
64
+ },
65
+ "scripts": {
66
+ "dev": "NODE_ENV=${NODE_ENV:-development}; vite serve --mode=$NODE_ENV --config ./vite.config.ts --host",
67
+ "start": "NODE_ENV=${NODE_ENV:-development}; node ./dist/app.js",
68
+ "start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
69
+ "build": "pnpm run build:cross-env --mode ${NODE_ENV:-development}",
70
+ "build:cross-env": "vite build --config vite.esm.config.ts",
71
+ "build:tsc": "tsc --build --verbose",
72
+ "build:cjs": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV",
73
+ "docker-tag": "node ../../docker/docker-tag.mjs",
74
+ "build:docker": "docker buildx build --progress=plain --tag $(pnpm run --silent docker-tag) --platform linux/amd64 -f ./Dockerfile ../..",
75
+ "publish:docker": "docker push $(pnpm run --silent docker-tag)",
76
+ "typecheck": "tsc --project tsconfig.types.json",
77
+ "test": "NODE_ENV=${NODE_ENV:-test}; pnpm exec vitest run --config ./vite.test.config.ts",
78
+ "test:watch": "NODE_ENV=${NODE_ENV:-test}; pnpm exec vitest --config ./vite.test.config.ts",
79
+ "test:coverage": "NODE_ENV=${NODE_ENV:-test}; pnpm exec vitest run --coverage --config ./vite.test.config.ts",
80
+ "bundle": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.config.ts --mode $NODE_ENV"
81
+ }
82
+ }
package/env.development DELETED
@@ -1,10 +0,0 @@
1
- PROSOPO_VERIFY_ENDPOINT=https://localhost:9235/development/siteverify
2
- PROSOPO_VERIFICATION_TYPE=api
3
- PROSOPO_SITE_KEY=5GCP69mhanZqJqnTvaaGvJCJZWSahz6xE2c7bTGETqSB5KDK
4
- PROSOPO_WEB2=true
5
- PROSOPO_SERVER_URL=https://localhost
6
- PROSOPO_SITE_PRIVATE_KEY=bottom drive obey lake curtain smoke basket hold race lonely fit walk
7
- PROSOPO_SERVER_PORT=9228
8
- PROSOPO_DEFAULT_ENVIRONMENT=development
9
- PROSOPO_MONGO_EVENTS_URI=mongodb+srv://<MONGO_URI_HERE>/frictionless_events
10
- _DEV_ONLY_WATCH_EVENTS=false
package/env.production DELETED
@@ -1,2 +0,0 @@
1
- PROSOPO_SITE_KEY=<YOUR SITE KEY HERE>
2
- PROSOPO_SITE_PRIVATE_KEY=<YOUR SECRET KEY HERE>
package/env.test DELETED
@@ -1,10 +0,0 @@
1
- PROSOPO_VERIFY_ENDPOINT=https://localhost:9235/test/siteverify
2
- PROSOPO_VERIFICATION_TYPE=api
3
- PROSOPO_SITE_KEY=5GCP69mhanZqJqnTvaaGvJCJZWSahz6xE2c7bTGETqSB5KDK
4
- PROSOPO_WEB2=true
5
- PROSOPO_SERVER_URL=https://localhost
6
- PROSOPO_SITE_PRIVATE_KEY=bottom drive obey lake curtain smoke basket hold race lonely fit walk
7
- PROSOPO_SERVER_PORT=9228
8
- PROSOPO_DEFAULT_ENVIRONMENT=test
9
- PROSOPO_MONGO_EVENTS_URI=mongodb+srv://<MONGO_URI_HERE>/frictionless_events
10
- _DEV_ONLY_WATCH_EVENTS=false
package/src/app.ts DELETED
@@ -1,210 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import fs from "node:fs";
16
- import http from "node:http";
17
- import type { Server } from "node:http";
18
- import https from "node:https";
19
- import type { ServerOptions } from "node:https";
20
- import path from "node:path";
21
- import { fileURLToPath } from "node:url";
22
- import { ProsopoEnvError } from "@prosopo/common";
23
- import { loadEnv } from "@prosopo/dotenv";
24
- import { getLogger } from "@prosopo/logger";
25
- import { getServerConfig } from "@prosopo/server";
26
- import type { ProsopoServerConfigOutput } from "@prosopo/types";
27
- import { at, isMain } from "@prosopo/util";
28
- import cors from "cors";
29
- import express from "express";
30
- import routesFactory from "./routes/routes.js";
31
- import connectionFactory from "./utils/connection.js";
32
- import memoryServerSetup from "./utils/database.js";
33
-
34
- export enum ProsopoVerificationType {
35
- api = "api",
36
- local = "local",
37
- }
38
-
39
- const logger = getLogger("info", "client-example-server:app");
40
-
41
- /**
42
- * The siteverify endpoint the deployment talks to. Non-production
43
- * environments get their name as a subdomain prefix. An unset NODE_ENV is
44
- * treated as production: prefixing it produced `undefined-api.prosopo.io`,
45
- * a host that does not exist.
46
- */
47
- export const resolveVerifyEndpoint = (): string => {
48
- const environment = process.env.NODE_ENV;
49
- const apiPrefix =
50
- !environment || environment === "production" ? "" : `${environment}-`;
51
- return (
52
- process.env.PROSOPO_VERIFY_ENDPOINT ||
53
- `https://${apiPrefix}api.prosopo.io/siteverify`
54
- );
55
- };
56
-
57
- /** Anything the enum doesn't name falls back to the hosted API. */
58
- export const resolveVerifyType = (): ProsopoVerificationType =>
59
- Object.keys(ProsopoVerificationType).includes(
60
- process.env.PROSOPO_VERIFICATION_TYPE as string,
61
- )
62
- ? (process.env.PROSOPO_VERIFICATION_TYPE as ProsopoVerificationType)
63
- : ProsopoVerificationType.api;
64
-
65
- export const isDevelopmentOrTest = (): boolean =>
66
- process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
67
-
68
- /** The express app, minus the routes, which need a database connection. */
69
- export const createApp = (): express.Express => {
70
- const app = express();
71
-
72
- // https://express-rate-limit.mintlify.app/guides/troubleshooting-proxy-issues
73
- app.set("trust proxy", 1);
74
-
75
- app.use(cors({ origin: true, credentials: true }));
76
-
77
- app.use(express.urlencoded({ extended: true }));
78
-
79
- app.use(express.json());
80
-
81
- app.use((_, res, next) => {
82
- res.setHeader("Access-Control-Allow-Origin", "*");
83
- res.setHeader(
84
- "Access-Control-Allow-Methods",
85
- "GET, POST, PUT, PATCH, DELETE",
86
- );
87
- res.setHeader(
88
- "Access-Control-Allow-Headers",
89
- "Origin, Content-Type, X-Auth-Token, Authorization",
90
- );
91
- next();
92
- });
93
-
94
- // No explicit OPTIONS handler: cors() above already answers preflight
95
- // requests with a 204 and never calls through, so the handler that used to
96
- // sit here could not run.
97
-
98
- return app;
99
- };
100
-
101
- export const DEFAULT_PORT = 9228;
102
-
103
- /**
104
- * The port is the last segment of the configured server URL. A URL without
105
- * one used to yield NaN, which node turns into an arbitrary free port — the
106
- * server came up on an address nothing was configured to talk to.
107
- */
108
- export const resolvePort = (config: ProsopoServerConfigOutput): number => {
109
- if (!config.serverUrl) return DEFAULT_PORT;
110
- const segments = config.serverUrl.split(":");
111
- if (segments.length < 3) return DEFAULT_PORT;
112
- const port = Number.parseInt(at(segments, 2));
113
- return Number.isNaN(port) ? DEFAULT_PORT : port;
114
- };
115
-
116
- /**
117
- * HTTPS in development/test when the repo's certificates exist, plain HTTP
118
- * otherwise — in production Caddy terminates TLS.
119
- */
120
- export const startServer = (
121
- app: express.Express,
122
- port: number,
123
- dirname: string = path.dirname(fileURLToPath(import.meta.url)),
124
- ): Server => {
125
- if (isDevelopmentOrTest()) {
126
- const certsDir = path.resolve(dirname, "../../../certs");
127
-
128
- const keyPath = path.join(certsDir, "server.key");
129
- const certPath = path.join(certsDir, "server.crt");
130
-
131
- if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
132
- const httpsOptions: ServerOptions = {
133
- key: fs.readFileSync(keyPath),
134
- cert: fs.readFileSync(certPath),
135
- };
136
-
137
- return https.createServer(httpsOptions, app).listen(port, () => {
138
- logger.info(() => ({ msg: `HTTPS server started on port ${port}` }));
139
- });
140
- }
141
- logger.warn(() => ({
142
- msg: "Certificates not found, starting HTTP server instead. Run ./setup_certs.sh to enable HTTPS in development.",
143
- }));
144
- return http.createServer(app).listen(port, () => {
145
- logger.info(() => ({ msg: `HTTP server started on port ${port}` }));
146
- });
147
- }
148
- return http.createServer(app).listen(port, () => {
149
- logger.info(() => ({
150
- msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)`,
151
- }));
152
- });
153
- };
154
-
155
- export async function main(): Promise<Server> {
156
- loadEnv();
157
-
158
- const verifyEndpoint = resolveVerifyEndpoint();
159
-
160
- logger.info(() => ({ data: { verifyEndpoint } }));
161
-
162
- const verifyType = resolveVerifyType();
163
-
164
- const app = createApp();
165
-
166
- if (!process.env.MONGO_URI && !isDevelopmentOrTest()) {
167
- throw new Error(
168
- "Cannot run mongo memory when NODE_ENV is neither development nor test",
169
- );
170
- }
171
- logger.info(() => ({ msg: process.env.MONGO_URI }));
172
- const uri = process.env.MONGO_URI || (await memoryServerSetup());
173
- logger.info(() => ({ msg: "mongo uri", data: { uri } }));
174
- const mongoose = connectionFactory(uri);
175
- if (!process.env.PROSOPO_SITE_PRIVATE_KEY) {
176
- const mnemonicError = new ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
177
- context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
178
- logger,
179
- });
180
-
181
- logger.error(() => ({ err: mnemonicError }));
182
- }
183
-
184
- const config = getServerConfig();
185
-
186
- logger.info(() => ({ msg: "Config", data: { config } }));
187
-
188
- app.use(routesFactory(mongoose, config, verifyEndpoint, verifyType));
189
-
190
- const port = resolvePort(config);
191
-
192
- logger.info(() => ({ msg: "Listening on port", data: { port } }));
193
-
194
- return startServer(app, port);
195
- }
196
-
197
- // Only boot when run as a binary: importing this module (a test, or another
198
- // entrypoint reusing createApp) must not open a port or spin up mongo.
199
- if (isMain(import.meta.url)) {
200
- main()
201
- .then(() => {
202
- logger.info(() => ({ msg: "Server started" }));
203
- })
204
- .catch((err) => {
205
- logger.error(() => ({ err }));
206
- // Non-zero, so a boot failure is visible to whatever supervises the
207
- // process rather than reading as a clean shutdown.
208
- process.exit(1);
209
- });
210
- }