@xtr-dev/rondevu-server 0.5.14 → 0.5.16
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 +27 -20
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/src/app.ts +2 -2
- package/src/config.ts +4 -0
- package/src/rpc.ts +3 -1
- package/src/storage/d1.ts +14 -6
- package/src/storage/memory.ts +7 -1
- package/src/storage/mysql.ts +14 -6
- package/src/storage/postgres.ts +14 -6
- package/src/storage/sqlite.ts +9 -4
- package/src/storage/types.ts +2 -1
- package/wrangler.toml +2 -0
package/dist/index.js
CHANGED
|
@@ -152,7 +152,7 @@ var init_memory = __esm({
|
|
|
152
152
|
}
|
|
153
153
|
return count;
|
|
154
154
|
}
|
|
155
|
-
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags) {
|
|
155
|
+
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags, newExpiresAt) {
|
|
156
156
|
const offer = await this.getOfferById(offerId);
|
|
157
157
|
if (!offer) {
|
|
158
158
|
return { success: false, error: "Offer not found or expired" };
|
|
@@ -165,6 +165,9 @@ var init_memory = __esm({
|
|
|
165
165
|
offer.answerSdp = answerSdp;
|
|
166
166
|
offer.answeredAt = now;
|
|
167
167
|
offer.matchedTags = matchedTags;
|
|
168
|
+
if (newExpiresAt !== void 0) {
|
|
169
|
+
offer.expiresAt = newExpiresAt;
|
|
170
|
+
}
|
|
168
171
|
if (!this.offersByAnswerer.has(answererPublicKey)) {
|
|
169
172
|
this.offersByAnswerer.set(answererPublicKey, /* @__PURE__ */ new Set());
|
|
170
173
|
}
|
|
@@ -546,7 +549,7 @@ var init_sqlite = __esm({
|
|
|
546
549
|
const result = stmt.run(now);
|
|
547
550
|
return result.changes;
|
|
548
551
|
}
|
|
549
|
-
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags) {
|
|
552
|
+
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags, newExpiresAt) {
|
|
550
553
|
const offer = await this.getOfferById(offerId);
|
|
551
554
|
if (!offer) {
|
|
552
555
|
return {
|
|
@@ -560,13 +563,15 @@ var init_sqlite = __esm({
|
|
|
560
563
|
error: "Offer already answered"
|
|
561
564
|
};
|
|
562
565
|
}
|
|
566
|
+
const now = Date.now();
|
|
563
567
|
const stmt = this.db.prepare(`
|
|
564
568
|
UPDATE offers
|
|
565
|
-
SET answerer_public_key = ?, answer_sdp = ?, answered_at = ?, matched_tags = ?
|
|
569
|
+
SET answerer_public_key = ?, answer_sdp = ?, answered_at = ?, matched_tags = ?${newExpiresAt ? ", expires_at = ?" : ""}
|
|
566
570
|
WHERE id = ? AND answerer_public_key IS NULL
|
|
567
571
|
`);
|
|
568
572
|
const matchedTagsJson = matchedTags ? JSON.stringify(matchedTags) : null;
|
|
569
|
-
const
|
|
573
|
+
const params = newExpiresAt ? [answererPublicKey, answerSdp, now, matchedTagsJson, newExpiresAt, offerId] : [answererPublicKey, answerSdp, now, matchedTagsJson, offerId];
|
|
574
|
+
const result = stmt.run(...params);
|
|
570
575
|
if (result.changes === 0) {
|
|
571
576
|
return {
|
|
572
577
|
success: false,
|
|
@@ -971,7 +976,7 @@ var init_mysql = __esm({
|
|
|
971
976
|
);
|
|
972
977
|
return result.affectedRows;
|
|
973
978
|
}
|
|
974
|
-
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags) {
|
|
979
|
+
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags, newExpiresAt) {
|
|
975
980
|
const offer = await this.getOfferById(offerId);
|
|
976
981
|
if (!offer) {
|
|
977
982
|
return { success: false, error: "Offer not found or expired" };
|
|
@@ -979,12 +984,11 @@ var init_mysql = __esm({
|
|
|
979
984
|
if (offer.answererPublicKey) {
|
|
980
985
|
return { success: false, error: "Offer already answered" };
|
|
981
986
|
}
|
|
987
|
+
const now = Date.now();
|
|
982
988
|
const matchedTagsJson = matchedTags ? JSON.stringify(matchedTags) : null;
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
[answererPublicKey, answerSdp, Date.now(), matchedTagsJson, offerId]
|
|
987
|
-
);
|
|
989
|
+
const query = newExpiresAt ? `UPDATE offers SET answerer_public_key = ?, answer_sdp = ?, answered_at = ?, matched_tags = ?, expires_at = ? WHERE id = ? AND answerer_public_key IS NULL` : `UPDATE offers SET answerer_public_key = ?, answer_sdp = ?, answered_at = ?, matched_tags = ? WHERE id = ? AND answerer_public_key IS NULL`;
|
|
990
|
+
const params = newExpiresAt ? [answererPublicKey, answerSdp, now, matchedTagsJson, newExpiresAt, offerId] : [answererPublicKey, answerSdp, now, matchedTagsJson, offerId];
|
|
991
|
+
const [result] = await this.pool.query(query, params);
|
|
988
992
|
if (result.affectedRows === 0) {
|
|
989
993
|
return { success: false, error: "Offer already answered (race condition)" };
|
|
990
994
|
}
|
|
@@ -1364,7 +1368,7 @@ var init_postgres = __esm({
|
|
|
1364
1368
|
);
|
|
1365
1369
|
return result.rowCount ?? 0;
|
|
1366
1370
|
}
|
|
1367
|
-
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags) {
|
|
1371
|
+
async answerOffer(offerId, answererPublicKey, answerSdp, matchedTags, newExpiresAt) {
|
|
1368
1372
|
const offer = await this.getOfferById(offerId);
|
|
1369
1373
|
if (!offer) {
|
|
1370
1374
|
return { success: false, error: "Offer not found or expired" };
|
|
@@ -1372,12 +1376,11 @@ var init_postgres = __esm({
|
|
|
1372
1376
|
if (offer.answererPublicKey) {
|
|
1373
1377
|
return { success: false, error: "Offer already answered" };
|
|
1374
1378
|
}
|
|
1379
|
+
const now = Date.now();
|
|
1375
1380
|
const matchedTagsJson = matchedTags ? JSON.stringify(matchedTags) : null;
|
|
1376
|
-
const
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
[answererPublicKey, answerSdp, Date.now(), matchedTagsJson, offerId]
|
|
1380
|
-
);
|
|
1381
|
+
const query = newExpiresAt ? `UPDATE offers SET answerer_public_key = $1, answer_sdp = $2, answered_at = $3, matched_tags = $4, expires_at = $5 WHERE id = $6 AND answerer_public_key IS NULL` : `UPDATE offers SET answerer_public_key = $1, answer_sdp = $2, answered_at = $3, matched_tags = $4 WHERE id = $5 AND answerer_public_key IS NULL`;
|
|
1382
|
+
const params = newExpiresAt ? [answererPublicKey, answerSdp, now, matchedTagsJson, newExpiresAt, offerId] : [answererPublicKey, answerSdp, now, matchedTagsJson, offerId];
|
|
1383
|
+
const result = await this.pool.query(query, params);
|
|
1381
1384
|
if ((result.rowCount ?? 0) === 0) {
|
|
1382
1385
|
return { success: false, error: "Offer already answered (race condition)" };
|
|
1383
1386
|
}
|
|
@@ -2486,7 +2489,8 @@ var handlers = {
|
|
|
2486
2489
|
throw new RpcError(ErrorCodes.INVALID_PARAMS, `matchedTags contains tags not on offer: ${invalidTags.join(", ")}`);
|
|
2487
2490
|
}
|
|
2488
2491
|
}
|
|
2489
|
-
|
|
2492
|
+
const newExpiresAt = Date.now() + config.answeredOfferTtl;
|
|
2493
|
+
await storage.answerOffer(offerId, publicKey, sdp, matchedTags, newExpiresAt);
|
|
2490
2494
|
return { success: true, offerId };
|
|
2491
2495
|
},
|
|
2492
2496
|
/**
|
|
@@ -2824,7 +2828,7 @@ function createApp(storage, config) {
|
|
|
2824
2828
|
return config.corsOrigins[0];
|
|
2825
2829
|
},
|
|
2826
2830
|
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
2827
|
-
allowHeaders: ["Content-Type", "Origin", "X-
|
|
2831
|
+
allowHeaders: ["Content-Type", "Origin", "X-PublicKey", "X-Timestamp", "X-Nonce", "X-Signature"],
|
|
2828
2832
|
exposeHeaders: ["Content-Type"],
|
|
2829
2833
|
credentials: false,
|
|
2830
2834
|
maxAge: 86400
|
|
@@ -2833,7 +2837,7 @@ function createApp(storage, config) {
|
|
|
2833
2837
|
return c.json({
|
|
2834
2838
|
version: config.version,
|
|
2835
2839
|
name: "Rondevu",
|
|
2836
|
-
description: "WebRTC signaling with RPC interface and
|
|
2840
|
+
description: "WebRTC signaling with RPC interface and Ed25519 signature-based authentication"
|
|
2837
2841
|
}, 200);
|
|
2838
2842
|
});
|
|
2839
2843
|
app.get("/health", (c) => {
|
|
@@ -2889,7 +2893,7 @@ function createApp(storage, config) {
|
|
|
2889
2893
|
}
|
|
2890
2894
|
|
|
2891
2895
|
// src/config.ts
|
|
2892
|
-
var BUILD_VERSION = true ? "0.5.
|
|
2896
|
+
var BUILD_VERSION = true ? "0.5.15" : "unknown";
|
|
2893
2897
|
function loadConfig() {
|
|
2894
2898
|
function parsePositiveInt(value, defaultValue, name, min = 1) {
|
|
2895
2899
|
const parsed = parseInt(value || defaultValue, 10);
|
|
@@ -2912,6 +2916,7 @@ function loadConfig() {
|
|
|
2912
2916
|
offerDefaultTtl: parsePositiveInt(process.env.OFFER_DEFAULT_TTL, "60000", "OFFER_DEFAULT_TTL", 1e3),
|
|
2913
2917
|
offerMaxTtl: parsePositiveInt(process.env.OFFER_MAX_TTL, "86400000", "OFFER_MAX_TTL", 1e3),
|
|
2914
2918
|
offerMinTtl: parsePositiveInt(process.env.OFFER_MIN_TTL, "60000", "OFFER_MIN_TTL", 1e3),
|
|
2919
|
+
answeredOfferTtl: parsePositiveInt(process.env.ANSWERED_OFFER_TTL, "30000", "ANSWERED_OFFER_TTL", 1e3),
|
|
2915
2920
|
cleanupInterval: parsePositiveInt(process.env.CLEANUP_INTERVAL, "60000", "CLEANUP_INTERVAL", 1e3),
|
|
2916
2921
|
maxOffersPerRequest: parsePositiveInt(process.env.MAX_OFFERS_PER_REQUEST, "100", "MAX_OFFERS_PER_REQUEST", 1),
|
|
2917
2922
|
maxBatchSize: parsePositiveInt(process.env.MAX_BATCH_SIZE, "100", "MAX_BATCH_SIZE", 1),
|
|
@@ -2938,6 +2943,8 @@ var CONFIG_DEFAULTS = {
|
|
|
2938
2943
|
offerDefaultTtl: 6e4,
|
|
2939
2944
|
offerMaxTtl: 864e5,
|
|
2940
2945
|
offerMinTtl: 6e4,
|
|
2946
|
+
answeredOfferTtl: 3e4,
|
|
2947
|
+
// 30 seconds TTL after offer is answered
|
|
2941
2948
|
cleanupInterval: 6e4,
|
|
2942
2949
|
maxOffersPerRequest: 100,
|
|
2943
2950
|
maxBatchSize: 100,
|