@xtr-dev/rondevu-server 0.5.7 → 0.5.9
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/dist/index.js +22 -8
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/src/config.ts +22 -7
- package/src/rpc.ts +4 -4
package/dist/index.js
CHANGED
|
@@ -2271,7 +2271,7 @@ var import_cors = require("hono/cors");
|
|
|
2271
2271
|
// src/rpc.ts
|
|
2272
2272
|
init_crypto();
|
|
2273
2273
|
var MAX_PAGE_SIZE = 100;
|
|
2274
|
-
var CREDENTIAL_RATE_WINDOW =
|
|
2274
|
+
var CREDENTIAL_RATE_WINDOW = 1e3;
|
|
2275
2275
|
var REQUEST_RATE_WINDOW = 1e3;
|
|
2276
2276
|
function getJsonDepth(obj, maxDepth, currentDepth = 0) {
|
|
2277
2277
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -2386,7 +2386,7 @@ var handlers = {
|
|
|
2386
2386
|
rateLimit = 2;
|
|
2387
2387
|
} else {
|
|
2388
2388
|
rateLimitKey = `cred_gen:${request.clientIp}`;
|
|
2389
|
-
rateLimit = config.
|
|
2389
|
+
rateLimit = config.credentialsPerIpPerSecond;
|
|
2390
2390
|
}
|
|
2391
2391
|
const allowed = await storage.checkRateLimit(
|
|
2392
2392
|
rateLimitKey,
|
|
@@ -2396,7 +2396,7 @@ var handlers = {
|
|
|
2396
2396
|
if (!allowed) {
|
|
2397
2397
|
throw new RpcError(
|
|
2398
2398
|
ErrorCodes.RATE_LIMIT_EXCEEDED,
|
|
2399
|
-
`Rate limit exceeded. Maximum ${rateLimit} credentials per
|
|
2399
|
+
`Rate limit exceeded. Maximum ${rateLimit} credentials per second${request.clientIp ? " per IP" : " (global limit for unidentified IPs)"}.`
|
|
2400
2400
|
);
|
|
2401
2401
|
}
|
|
2402
2402
|
if (params.name !== void 0) {
|
|
@@ -3018,6 +3018,20 @@ function createApp(storage, config) {
|
|
|
3018
3018
|
}
|
|
3019
3019
|
|
|
3020
3020
|
// src/config.ts
|
|
3021
|
+
var import_fs = require("fs");
|
|
3022
|
+
var import_path = require("path");
|
|
3023
|
+
var import_url = require("url");
|
|
3024
|
+
var import_meta = {};
|
|
3025
|
+
function getPackageVersion() {
|
|
3026
|
+
try {
|
|
3027
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
3028
|
+
const pkgPath = (0, import_path.join)(__dirname, "..", "package.json");
|
|
3029
|
+
const pkg = JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf-8"));
|
|
3030
|
+
return pkg.version || "unknown";
|
|
3031
|
+
} catch {
|
|
3032
|
+
return "unknown";
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3021
3035
|
function loadConfig() {
|
|
3022
3036
|
let masterEncryptionKey = process.env.MASTER_ENCRYPTION_KEY;
|
|
3023
3037
|
if (!masterEncryptionKey) {
|
|
@@ -3052,7 +3066,7 @@ function loadConfig() {
|
|
|
3052
3066
|
databaseUrl: process.env.DATABASE_URL || "",
|
|
3053
3067
|
dbPoolSize: parsePositiveInt(process.env.DB_POOL_SIZE, "10", "DB_POOL_SIZE", 1),
|
|
3054
3068
|
corsOrigins: process.env.CORS_ORIGINS ? process.env.CORS_ORIGINS.split(",").map((o) => o.trim()) : ["*"],
|
|
3055
|
-
version: process.env.VERSION ||
|
|
3069
|
+
version: process.env.VERSION || getPackageVersion(),
|
|
3056
3070
|
offerDefaultTtl: parsePositiveInt(process.env.OFFER_DEFAULT_TTL, "60000", "OFFER_DEFAULT_TTL", 1e3),
|
|
3057
3071
|
offerMaxTtl: parsePositiveInt(process.env.OFFER_MAX_TTL, "86400000", "OFFER_MAX_TTL", 1e3),
|
|
3058
3072
|
offerMinTtl: parsePositiveInt(process.env.OFFER_MIN_TTL, "60000", "OFFER_MIN_TTL", 1e3),
|
|
@@ -3076,7 +3090,7 @@ function loadConfig() {
|
|
|
3076
3090
|
maxTotalOffers: parsePositiveInt(process.env.MAX_TOTAL_OFFERS, "10000", "MAX_TOTAL_OFFERS", 1),
|
|
3077
3091
|
maxTotalCredentials: parsePositiveInt(process.env.MAX_TOTAL_CREDENTIALS, "50000", "MAX_TOTAL_CREDENTIALS", 1),
|
|
3078
3092
|
maxIceCandidatesPerOffer: parsePositiveInt(process.env.MAX_ICE_CANDIDATES_PER_OFFER, "50", "MAX_ICE_CANDIDATES_PER_OFFER", 1),
|
|
3079
|
-
|
|
3093
|
+
credentialsPerIpPerSecond: parsePositiveInt(process.env.CREDENTIALS_PER_IP_PER_SECOND, "5", "CREDENTIALS_PER_IP_PER_SECOND", 1),
|
|
3080
3094
|
requestsPerIpPerSecond: parsePositiveInt(process.env.REQUESTS_PER_IP_PER_SECOND, "50", "REQUESTS_PER_IP_PER_SECOND", 1)
|
|
3081
3095
|
};
|
|
3082
3096
|
return config;
|
|
@@ -3096,11 +3110,11 @@ var CONFIG_DEFAULTS = {
|
|
|
3096
3110
|
timestampMaxAge: 6e4,
|
|
3097
3111
|
timestampMaxFuture: 6e4,
|
|
3098
3112
|
// Resource limits
|
|
3099
|
-
maxOffersPerUser:
|
|
3100
|
-
maxTotalOffers:
|
|
3113
|
+
maxOffersPerUser: 1e3,
|
|
3114
|
+
maxTotalOffers: 1e5,
|
|
3101
3115
|
maxTotalCredentials: 5e4,
|
|
3102
3116
|
maxIceCandidatesPerOffer: 50,
|
|
3103
|
-
|
|
3117
|
+
credentialsPerIpPerSecond: 5,
|
|
3104
3118
|
requestsPerIpPerSecond: 50
|
|
3105
3119
|
};
|
|
3106
3120
|
async function runCleanup(storage, now) {
|