@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
|
@@ -1,255 +1,189 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _prosopo_common = require("@prosopo/common");
|
|
3
|
+
let _prosopo_logger = require("@prosopo/logger");
|
|
4
|
+
let _prosopo_server = require("@prosopo/server");
|
|
5
|
+
let _prosopo_util = require("@prosopo/util");
|
|
6
|
+
let _noble_hashes_blake2b = require("@noble/hashes/blake2b");
|
|
7
|
+
let _polkadot_util = require("@polkadot/util");
|
|
8
|
+
let _polkadot_util_crypto = require("@polkadot/util-crypto");
|
|
9
|
+
let _prosopo_keyring = require("@prosopo/keyring");
|
|
10
|
+
let _prosopo_types = require("@prosopo/types");
|
|
11
|
+
let jsonwebtoken = require("jsonwebtoken");
|
|
12
|
+
jsonwebtoken = require_runtime.__toESM(jsonwebtoken, 1);
|
|
13
|
+
let zod = require("zod");
|
|
14
|
+
//#region src/controllers/auth.ts
|
|
15
|
+
var logger = (0, _prosopo_logger.getLogger)("info", "client-example-server:auth");
|
|
16
|
+
var SubscribeBodySpec = _prosopo_types.ProcaptchaResponse.merge(zod.z.object({
|
|
17
|
+
email: zod.z.string().email(),
|
|
18
|
+
password: zod.z.string(),
|
|
19
|
+
siteKey: zod.z.string()
|
|
20
|
+
}));
|
|
22
21
|
function hashPassword(password) {
|
|
23
|
-
|
|
22
|
+
return (0, _polkadot_util.u8aToHex)((0, _noble_hashes_blake2b.blake2b)(password));
|
|
24
23
|
}
|
|
25
|
-
|
|
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
|
-
|
|
24
|
+
var NO_IP = "NO_IP";
|
|
25
|
+
/**
|
|
26
|
+
* Derives the correct KeyringPair and secret for a given site key by trying different captcha types.
|
|
27
|
+
* @param baseSecret - The base secret from config
|
|
28
|
+
* @param siteKey - The site key to match against
|
|
29
|
+
* @returns Object containing the matched pair and its corresponding secret
|
|
30
|
+
* @throws Error if no matching pair is found
|
|
31
|
+
*/
|
|
32
|
+
var getPairAndSecretForSiteKey = (baseSecret, siteKey) => {
|
|
33
|
+
let pair;
|
|
34
|
+
let secret = baseSecret;
|
|
35
|
+
pair = (0, _prosopo_keyring.getPair)(secret);
|
|
36
|
+
if (pair.address === siteKey) {
|
|
37
|
+
logger.info(() => ({
|
|
38
|
+
msg: "Site key matches the server configuration without captcha type suffix",
|
|
39
|
+
data: {
|
|
40
|
+
siteKeyDerived: pair?.address,
|
|
41
|
+
siteKey
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
return {
|
|
45
|
+
pair,
|
|
46
|
+
secret
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
for (const captchaType of [
|
|
50
|
+
_prosopo_types.CaptchaType.pow,
|
|
51
|
+
_prosopo_types.CaptchaType.image,
|
|
52
|
+
_prosopo_types.CaptchaType.frictionless,
|
|
53
|
+
_prosopo_types.CaptchaType.puzzle
|
|
54
|
+
]) {
|
|
55
|
+
const newSecret = `${baseSecret}//${captchaType}`;
|
|
56
|
+
pair = (0, _prosopo_keyring.getPair)(newSecret);
|
|
57
|
+
console.log(`[PAIR CHECK] Checking pair for ${captchaType}: ${pair?.address} (expected: ${siteKey})`);
|
|
58
|
+
logger.info(() => ({
|
|
59
|
+
msg: "Checking pair",
|
|
60
|
+
data: {
|
|
61
|
+
captchaType,
|
|
62
|
+
siteKeyDerived: pair?.address,
|
|
63
|
+
siteKey
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
if (pair.address === siteKey) {
|
|
67
|
+
console.log(`[PAIR CHECK] ✅ Match found for ${captchaType}!`);
|
|
68
|
+
secret = newSecret;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!pair || pair.address !== siteKey) throw new Error(`Site key does not match the server configuration: Provided ${siteKey} vs Server ${pair?.address}`);
|
|
73
|
+
return {
|
|
74
|
+
pair,
|
|
75
|
+
secret
|
|
76
|
+
};
|
|
71
77
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
const response = await fetch(verifyEndpoint, {
|
|
87
|
-
method: "POST",
|
|
88
|
-
body: JSON.stringify(body)
|
|
89
|
-
});
|
|
90
|
-
return response.json();
|
|
78
|
+
var getResponse = async (ip, token, secret, verifyEndpoint, email) => {
|
|
79
|
+
const body = {
|
|
80
|
+
[_prosopo_types.ApiParams.token]: token,
|
|
81
|
+
[_prosopo_types.ApiParams.secret]: secret,
|
|
82
|
+
...email ? { [_prosopo_types.ApiParams.email]: email } : {}
|
|
83
|
+
};
|
|
84
|
+
if (process.env.NODE_ENV !== "development") body[_prosopo_types.ApiParams.ip] = ip;
|
|
85
|
+
logger.info(() => ({ data: { body } }));
|
|
86
|
+
return (await fetch(verifyEndpoint, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
body: JSON.stringify(body)
|
|
89
|
+
})).json();
|
|
91
90
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
email
|
|
106
|
-
);
|
|
107
|
-
logger.info(() => ({
|
|
108
|
-
data: {
|
|
109
|
-
response
|
|
110
|
-
}
|
|
111
|
-
}));
|
|
112
|
-
return response.verified;
|
|
113
|
-
}
|
|
114
|
-
const verified = await prosopoServer.isVerified(token, ip, email);
|
|
115
|
-
logger.info(() => ({
|
|
116
|
-
data: {
|
|
117
|
-
verified
|
|
118
|
-
}
|
|
119
|
-
}));
|
|
120
|
-
return verified[types.ApiParams.verified];
|
|
91
|
+
var verify = async (prosopoServer, verifyType, verifyEndpoint, token, secret, ip, email) => {
|
|
92
|
+
if (verifyType === "api") {
|
|
93
|
+
logger.info(() => ({
|
|
94
|
+
msg: "Verifying using the API endpoint",
|
|
95
|
+
data: { verifyEndpoint }
|
|
96
|
+
}));
|
|
97
|
+
const response = await getResponse(ip, token, secret, verifyEndpoint, email);
|
|
98
|
+
logger.info(() => ({ data: { response } }));
|
|
99
|
+
return response.verified;
|
|
100
|
+
}
|
|
101
|
+
const verified = await prosopoServer.isVerified(token, ip, email);
|
|
102
|
+
logger.info(() => ({ data: { verified } }));
|
|
103
|
+
return verified[_prosopo_types.ApiParams.verified];
|
|
121
104
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
name: req.body.name,
|
|
161
|
-
password: passwordHash,
|
|
162
|
-
salt
|
|
163
|
-
}).then(() => {
|
|
164
|
-
res.status(200).json({ message: "user created" });
|
|
165
|
-
}).catch((err) => {
|
|
166
|
-
logger.error(() => ({
|
|
167
|
-
err,
|
|
168
|
-
msg: "Error creating user in database"
|
|
169
|
-
}));
|
|
170
|
-
res.status(502).json({ message: "error while creating the user" });
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
res.status(401).json({ message: "user has not completed a captcha", verified });
|
|
175
|
-
}
|
|
176
|
-
} catch (err) {
|
|
177
|
-
console.error("error", err);
|
|
178
|
-
res.status(500).json({ message: err.message || "internal server error" });
|
|
179
|
-
}
|
|
105
|
+
var signup = async (mongoose, config, verifyEndpoint, verifyType, req, res, next) => {
|
|
106
|
+
try {
|
|
107
|
+
if (!config.account.secret) throw new _prosopo_common.ProsopoEnvError("GENERAL.MNEMONIC_UNDEFINED", { context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] } });
|
|
108
|
+
const User = mongoose.model("User");
|
|
109
|
+
const dbUser = await User.findOne({ email: { $eq: req.body.email } });
|
|
110
|
+
const payload = SubscribeBodySpec.parse(req.body);
|
|
111
|
+
const token = payload[_prosopo_types.ApiParams.procaptchaResponse];
|
|
112
|
+
const siteKey = payload[_prosopo_types.ApiParams.siteKey];
|
|
113
|
+
const { pair, secret } = getPairAndSecretForSiteKey(config.account.secret, siteKey);
|
|
114
|
+
const prosopoServer = new _prosopo_server.ProsopoServer(config, pair);
|
|
115
|
+
if (dbUser) return res.status(409).json({ message: "email already exists" });
|
|
116
|
+
const email = req.body.email;
|
|
117
|
+
const verified = await verify(prosopoServer, verifyType, verifyEndpoint, token, secret, req.headers["x-client-ip"]?.toString() || "127.0.0.1", email);
|
|
118
|
+
if (verified === true) {
|
|
119
|
+
const salt = (0, _polkadot_util_crypto.randomAsHex)(32);
|
|
120
|
+
const passwordHash = hashPassword(`${req.body.password}${salt}`);
|
|
121
|
+
if (passwordHash) return User.create({
|
|
122
|
+
email,
|
|
123
|
+
name: req.body.name,
|
|
124
|
+
password: passwordHash,
|
|
125
|
+
salt
|
|
126
|
+
}).then(() => {
|
|
127
|
+
res.status(200).json({ message: "user created" });
|
|
128
|
+
}).catch((err) => {
|
|
129
|
+
logger.error(() => ({
|
|
130
|
+
err,
|
|
131
|
+
msg: "Error creating user in database"
|
|
132
|
+
}));
|
|
133
|
+
res.status(502).json({ message: "error while creating the user" });
|
|
134
|
+
});
|
|
135
|
+
} else res.status(401).json({
|
|
136
|
+
message: "user has not completed a captcha",
|
|
137
|
+
verified
|
|
138
|
+
});
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("error", err);
|
|
141
|
+
res.status(500).json({ message: err.message || "internal server error" });
|
|
142
|
+
}
|
|
180
143
|
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
data: {
|
|
210
|
-
verified
|
|
211
|
-
}
|
|
212
|
-
}));
|
|
213
|
-
if (verified) {
|
|
214
|
-
const passwordHash = hashPassword(
|
|
215
|
-
`${req.body.password}${dbUser.salt}`
|
|
216
|
-
);
|
|
217
|
-
if (passwordHash !== dbUser.password) {
|
|
218
|
-
return res.status(401).json({ message: "invalid credentials" });
|
|
219
|
-
}
|
|
220
|
-
const token2 = jwt.sign({ email: req.body.email }, "secret", {
|
|
221
|
-
expiresIn: "1h"
|
|
222
|
-
});
|
|
223
|
-
return res.status(200).json({ message: "user logged in", token: token2 });
|
|
224
|
-
}
|
|
225
|
-
return res.status(401).json({ message: "user has not completed a captcha", verified });
|
|
226
|
-
}
|
|
227
|
-
return res.status(404).json({ message: "user not found" });
|
|
228
|
-
}).catch((err) => {
|
|
229
|
-
console.error("error", err);
|
|
230
|
-
res.status(500).json({ message: err.message || "internal server error" });
|
|
231
|
-
});
|
|
144
|
+
var login = async (mongoose, config, verifyEndpoint, verifyType, req, res) => {
|
|
145
|
+
await mongoose.model("User").findOne({ email: { $eq: req.body.email } }).then(async (dbUser) => {
|
|
146
|
+
if (dbUser) {
|
|
147
|
+
const payload = SubscribeBodySpec.parse(req.body);
|
|
148
|
+
const token = payload[_prosopo_types.ApiParams.procaptchaResponse];
|
|
149
|
+
const siteKey = payload[_prosopo_types.ApiParams.siteKey];
|
|
150
|
+
if (!config.account.secret) throw new _prosopo_common.ProsopoEnvError("GENERAL.SECRET_MISSING", { context: { missingParams: ["PROSOPO_SITE_PRIVATE_KEY"] } });
|
|
151
|
+
const { pair, secret } = getPairAndSecretForSiteKey(config.account.secret, siteKey);
|
|
152
|
+
const verified = await verify(new _prosopo_server.ProsopoServer(config, pair), verifyType, verifyEndpoint, token, secret, req.headers["x-client-ip"]?.toString() || NO_IP);
|
|
153
|
+
logger.info(() => ({ data: { verified } }));
|
|
154
|
+
if (verified) {
|
|
155
|
+
if (hashPassword(`${req.body.password}${dbUser.salt}`) !== dbUser.password) return res.status(401).json({ message: "invalid credentials" });
|
|
156
|
+
const token = jsonwebtoken.default.sign({ email: req.body.email }, "secret", { expiresIn: "1h" });
|
|
157
|
+
return res.status(200).json({
|
|
158
|
+
message: "user logged in",
|
|
159
|
+
token
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return res.status(401).json({
|
|
163
|
+
message: "user has not completed a captcha",
|
|
164
|
+
verified
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return res.status(404).json({ message: "user not found" });
|
|
168
|
+
}).catch((err) => {
|
|
169
|
+
console.error("error", err);
|
|
170
|
+
res.status(500).json({ message: err.message || "internal server error" });
|
|
171
|
+
});
|
|
232
172
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
if (!decodedToken) {
|
|
248
|
-
res.status(401).json({ message: "unauthorized" });
|
|
249
|
-
} else {
|
|
250
|
-
res.status(200).json({ message: "here is your resource" });
|
|
251
|
-
}
|
|
173
|
+
var isAuth = (req, res) => {
|
|
174
|
+
const authHeader = req.get("Authorization") || "";
|
|
175
|
+
if (!authHeader) res.status(401).json({ message: "not authenticated" });
|
|
176
|
+
const token = (0, _prosopo_util.at)(authHeader.split(" "), 1);
|
|
177
|
+
let decodedToken = "";
|
|
178
|
+
try {
|
|
179
|
+
decodedToken = jsonwebtoken.default.verify(token, "secret");
|
|
180
|
+
} catch (err) {
|
|
181
|
+
res.status(500).json({ message: err.message || "could not decode the token" });
|
|
182
|
+
}
|
|
183
|
+
if (!decodedToken) res.status(401).json({ message: "unauthorized" });
|
|
184
|
+
else res.status(200).json({ message: "here is your resource" });
|
|
252
185
|
};
|
|
186
|
+
//#endregion
|
|
253
187
|
exports.isAuth = isAuth;
|
|
254
188
|
exports.login = login;
|
|
255
189
|
exports.signup = signup;
|
package/dist/cjs/models/user.cjs
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
required: true
|
|
21
|
-
}
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let mongoose = require("mongoose");
|
|
3
|
+
mongoose = require_runtime.__toESM(mongoose, 1);
|
|
4
|
+
//#region src/models/user.ts
|
|
5
|
+
var UserSchema = new mongoose.Schema({
|
|
6
|
+
email: {
|
|
7
|
+
type: mongoose.default.SchemaTypes.String,
|
|
8
|
+
required: true
|
|
9
|
+
},
|
|
10
|
+
name: { type: mongoose.default.SchemaTypes.String },
|
|
11
|
+
password: {
|
|
12
|
+
type: mongoose.default.SchemaTypes.String,
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
id: { type: mongoose.default.SchemaTypes.Number },
|
|
16
|
+
salt: {
|
|
17
|
+
type: mongoose.default.SchemaTypes.String,
|
|
18
|
+
required: true
|
|
19
|
+
}
|
|
22
20
|
});
|
|
23
|
-
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.default = UserSchema;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_auth = require("../controllers/auth.cjs");
|
|
3
|
+
let express = require("express");
|
|
4
|
+
express = require_runtime.__toESM(express, 1);
|
|
5
|
+
//#region src/routes/routes.ts
|
|
6
|
+
var router = express.default.Router();
|
|
5
7
|
function getRoutes(mongoose, config, verifyEndpoint, verifyType) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
res.status(200).json({ status: "ok" });
|
|
20
|
-
});
|
|
21
|
-
router.use("/", (req, res) => {
|
|
22
|
-
res.status(404).json({ error: "page not found" });
|
|
23
|
-
});
|
|
24
|
-
return router;
|
|
8
|
+
router.post("/login", require_auth.login.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
9
|
+
router.post("/signup", require_auth.signup.bind(null, mongoose, config, verifyEndpoint, verifyType));
|
|
10
|
+
router.get("/private", require_auth.isAuth);
|
|
11
|
+
router.get("/public", (req, res) => {
|
|
12
|
+
res.status(200).json({ message: "here is your public resource" });
|
|
13
|
+
});
|
|
14
|
+
router.get("/health", (req, res) => {
|
|
15
|
+
res.status(200).json({ status: "ok" });
|
|
16
|
+
});
|
|
17
|
+
router.use("/", (req, res) => {
|
|
18
|
+
res.status(404).json({ error: "page not found" });
|
|
19
|
+
});
|
|
20
|
+
return router;
|
|
25
21
|
}
|
|
26
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.default = getRoutes;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_user = require("../models/user.cjs");
|
|
3
|
+
let node_url = require("node:url");
|
|
4
|
+
let _prosopo_database = require("@prosopo/database");
|
|
5
|
+
let _typegoose_auto_increment = require("@typegoose/auto-increment");
|
|
6
|
+
let mongoose = require("mongoose");
|
|
7
|
+
mongoose = require_runtime.__toESM(mongoose, 1);
|
|
8
|
+
//#region src/utils/connection.ts
|
|
8
9
|
function connectionFactory(uri) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
field: "id"
|
|
20
|
-
});
|
|
21
|
-
conn.model("User", user);
|
|
22
|
-
}
|
|
23
|
-
return conn;
|
|
10
|
+
const appName = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
11
|
+
const conn = mongoose.default.createConnection(uri, (0, _prosopo_database.getMongoConnectionOptions)({
|
|
12
|
+
url: uri,
|
|
13
|
+
appName
|
|
14
|
+
}));
|
|
15
|
+
if (!conn.models.user) {
|
|
16
|
+
require_user.default.plugin(_typegoose_auto_increment.AutoIncrementID, { field: "id" });
|
|
17
|
+
conn.model("User", require_user.default);
|
|
18
|
+
}
|
|
19
|
+
return conn;
|
|
24
20
|
}
|
|
25
|
-
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.default = connectionFactory;
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
1
|
+
//#region src/utils/database.ts
|
|
25
2
|
async function memoryServerSetup() {
|
|
26
|
-
|
|
27
|
-
const mongod = MongoMemoryServer.create();
|
|
28
|
-
const memoryServer = await mongod;
|
|
29
|
-
return memoryServer.getUri();
|
|
3
|
+
return (await (await import("mongodb-memory-server")).MongoMemoryServer.create()).getUri();
|
|
30
4
|
}
|
|
5
|
+
//#endregion
|
|
31
6
|
exports.default = memoryServerSetup;
|
|
32
7
|
exports.memoryServerSetup = memoryServerSetup;
|