@prosopo/client-example-server 2.7.121 → 2.7.123
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 +15 -31
- package/.turbo/turbo-build$colon$tsc.log +21 -21
- package/.turbo/turbo-build.log +16 -31
- package/CHANGELOG.md +25 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/app.js +87 -90
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/app.cjs +105 -105
- package/dist/cjs/controllers/auth.cjs +178 -244
- package/dist/cjs/models/user.cjs +21 -22
- package/dist/cjs/routes/routes.cjs +21 -24
- package/dist/cjs/utils/connection.cjs +20 -23
- package/dist/cjs/utils/database.cjs +3 -28
- package/dist/controllers/auth.js +171 -241
- package/dist/models/user.d.ts +2 -2
- package/dist/models/user.js +18 -22
- package/dist/routes/routes.js +18 -24
- package/dist/utils/connection.js +14 -19
- package/dist/utils/database.js +4 -8
- package/package.json +14 -14
- package/tsconfig.tsbuildinfo +1 -1
package/dist/cjs/app.cjs
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_routes = require("./routes/routes.cjs");
|
|
3
|
+
const require_connection = require("./utils/connection.cjs");
|
|
4
|
+
const require_database = require("./utils/database.cjs");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
7
|
+
let node_http = require("node:http");
|
|
8
|
+
node_http = require_runtime.__toESM(node_http, 1);
|
|
9
|
+
let node_https = require("node:https");
|
|
10
|
+
node_https = require_runtime.__toESM(node_https, 1);
|
|
11
|
+
let node_path = require("node:path");
|
|
12
|
+
node_path = require_runtime.__toESM(node_path, 1);
|
|
13
|
+
let node_url = require("node:url");
|
|
14
|
+
let _prosopo_common = require("@prosopo/common");
|
|
15
|
+
let _prosopo_dotenv = require("@prosopo/dotenv");
|
|
16
|
+
let _prosopo_logger = require("@prosopo/logger");
|
|
17
|
+
let _prosopo_server = require("@prosopo/server");
|
|
18
|
+
let _prosopo_util = require("@prosopo/util");
|
|
19
|
+
let cors = require("cors");
|
|
20
|
+
cors = require_runtime.__toESM(cors, 1);
|
|
21
|
+
let express = require("express");
|
|
22
|
+
express = require_runtime.__toESM(express, 1);
|
|
23
|
+
//#region src/app.ts
|
|
24
|
+
(0, _prosopo_dotenv.loadEnv)();
|
|
25
|
+
var ProsopoVerificationType = /* @__PURE__ */ function(ProsopoVerificationType) {
|
|
26
|
+
ProsopoVerificationType["api"] = "api";
|
|
27
|
+
ProsopoVerificationType["local"] = "local";
|
|
28
|
+
return ProsopoVerificationType;
|
|
29
|
+
}(ProsopoVerificationType || {});
|
|
30
|
+
var logger = (0, _prosopo_logger.getLogger)("info", "client-example-server:app");
|
|
25
31
|
async function main() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} else {
|
|
98
|
-
http.createServer(app).listen(port, () => {
|
|
99
|
-
logger.info(() => ({
|
|
100
|
-
msg: `HTTP server started on port ${port} (TLS handled by reverse proxy)`
|
|
101
|
-
}));
|
|
102
|
-
});
|
|
103
|
-
}
|
|
32
|
+
(0, _prosopo_dotenv.loadEnv)();
|
|
33
|
+
const apiPrefix = process.env.NODE_ENV && process.env.NODE_ENV === "production" ? "" : `${process.env.NODE_ENV}-`;
|
|
34
|
+
const verifyEndpoint = process.env.PROSOPO_VERIFY_ENDPOINT || `https://${apiPrefix}api.prosopo.io/siteverify`;
|
|
35
|
+
logger.info(() => ({ data: { verifyEndpoint } }));
|
|
36
|
+
const verifyType = Object.keys(ProsopoVerificationType).includes(process.env.PROSOPO_VERIFICATION_TYPE) ? process.env.PROSOPO_VERIFICATION_TYPE : "api";
|
|
37
|
+
const app = (0, express.default)();
|
|
38
|
+
app.set("trust proxy", 1);
|
|
39
|
+
app.use((0, cors.default)({
|
|
40
|
+
origin: true,
|
|
41
|
+
credentials: true
|
|
42
|
+
}));
|
|
43
|
+
app.use(express.default.urlencoded({ extended: true }));
|
|
44
|
+
app.use(express.default.json());
|
|
45
|
+
app.use((_, res, next) => {
|
|
46
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
47
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE");
|
|
48
|
+
res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Auth-Token, Authorization");
|
|
49
|
+
next();
|
|
50
|
+
});
|
|
51
|
+
app.options("/*", (_, res) => {
|
|
52
|
+
res.sendStatus(200);
|
|
53
|
+
});
|
|
54
|
+
if (!process.env.MONGO_URI && process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test") throw new Error("Cannot run mongo memory when NODE_ENV is neither development nor test");
|
|
55
|
+
logger.info(() => ({ msg: process.env.MONGO_URI }));
|
|
56
|
+
const uri = process.env.MONGO_URI || await require_database.default();
|
|
57
|
+
logger.info(() => ({
|
|
58
|
+
msg: "mongo uri",
|
|
59
|
+
data: { uri }
|
|
60
|
+
}));
|
|
61
|
+
const mongoose = require_connection.default(uri);
|
|
62
|
+
if (!process.env.PROSOPO_SITE_PRIVATE_KEY) {
|
|
63
|
+
const mnemonicError = new _prosopo_common.ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", {
|
|
64
|
+
context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] },
|
|
65
|
+
logger
|
|
66
|
+
});
|
|
67
|
+
logger.error(() => ({ err: mnemonicError }));
|
|
68
|
+
}
|
|
69
|
+
const config = (0, _prosopo_server.getServerConfig)();
|
|
70
|
+
logger.info(() => ({
|
|
71
|
+
msg: "Config",
|
|
72
|
+
data: { config }
|
|
73
|
+
}));
|
|
74
|
+
app.use(require_routes.default(mongoose, config, verifyEndpoint, verifyType));
|
|
75
|
+
const port = config.serverUrl ? Number.parseInt((0, _prosopo_util.at)(config.serverUrl.split(":"), 2)) : 9228;
|
|
76
|
+
logger.info(() => ({
|
|
77
|
+
msg: "Listening on port",
|
|
78
|
+
data: { port }
|
|
79
|
+
}));
|
|
80
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
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
|
+
});
|
|
104
103
|
}
|
|
105
104
|
main().then(() => {
|
|
106
|
-
|
|
105
|
+
logger.info(() => ({ msg: "Server started" }));
|
|
107
106
|
}).catch((err) => {
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
logger.error(() => ({ err }));
|
|
108
|
+
process.exit();
|
|
110
109
|
});
|
|
110
|
+
//#endregion
|