@bsv/overlay-express 2.4.9 → 2.5.1
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/cjs/package.json +1 -1
- package/dist/cjs/src/BanService.d.ts +2 -4
- package/dist/cjs/src/BanService.d.ts.map +1 -1
- package/dist/cjs/src/BanService.js +18 -5
- package/dist/cjs/src/BanService.js.map +1 -1
- package/dist/cjs/src/JanitorService.d.ts +7 -0
- package/dist/cjs/src/JanitorService.d.ts.map +1 -1
- package/dist/cjs/src/JanitorService.js +61 -12
- package/dist/cjs/src/JanitorService.js.map +1 -1
- package/dist/cjs/src/OverlayExpress.d.ts +6 -0
- package/dist/cjs/src/OverlayExpress.d.ts.map +1 -1
- package/dist/cjs/src/OverlayExpress.js +182 -51
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/ResourceBoundedLookupWrapper.d.ts +26 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.d.ts.map +1 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.js +70 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.js.map +1 -0
- package/dist/cjs/src/security/edgePolicy.d.ts +27 -0
- package/dist/cjs/src/security/edgePolicy.d.ts.map +1 -1
- package/dist/cjs/src/security/edgePolicy.js +210 -22
- package/dist/cjs/src/security/edgePolicy.js.map +1 -1
- package/dist/esm/src/BanService.js +18 -5
- package/dist/esm/src/BanService.js.map +1 -1
- package/dist/esm/src/JanitorService.js +62 -11
- package/dist/esm/src/JanitorService.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +182 -49
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/ResourceBoundedLookupWrapper.js +70 -0
- package/dist/esm/src/ResourceBoundedLookupWrapper.js.map +1 -0
- package/dist/esm/src/security/edgePolicy.js +196 -18
- package/dist/esm/src/security/edgePolicy.js.map +1 -1
- package/dist/types/src/BanService.d.ts +2 -4
- package/dist/types/src/BanService.d.ts.map +1 -1
- package/dist/types/src/JanitorService.d.ts +7 -0
- package/dist/types/src/JanitorService.d.ts.map +1 -1
- package/dist/types/src/OverlayExpress.d.ts +6 -0
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/ResourceBoundedLookupWrapper.d.ts +26 -0
- package/dist/types/src/ResourceBoundedLookupWrapper.d.ts.map +1 -0
- package/dist/types/src/security/edgePolicy.d.ts +27 -0
- package/dist/types/src/security/edgePolicy.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -50,6 +50,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
50
50
|
const JanitorService_js_1 = require("./JanitorService.js");
|
|
51
51
|
const BanService_js_1 = require("./BanService.js");
|
|
52
52
|
const BanAwareLookupWrapper_js_1 = require("./BanAwareLookupWrapper.js");
|
|
53
|
+
const ResourceBoundedLookupWrapper_js_1 = require("./ResourceBoundedLookupWrapper.js");
|
|
53
54
|
const BanAwareTopicManager_js_1 = require("./BanAwareTopicManager.js");
|
|
54
55
|
const BanAwareDiscoveryStorage_js_1 = require("./BanAwareDiscoveryStorage.js");
|
|
55
56
|
const ReorgStream_js_1 = require("./ReorgStream.js");
|
|
@@ -81,7 +82,9 @@ class InMemoryMigrationSource {
|
|
|
81
82
|
* @returns The name of the migration
|
|
82
83
|
*/
|
|
83
84
|
getMigrationName(migration) {
|
|
84
|
-
return typeof migration.name === 'string'
|
|
85
|
+
return typeof migration.name === 'string'
|
|
86
|
+
? migration.name
|
|
87
|
+
: `Migration at index ${this.migrations.indexOf(migration)}`;
|
|
85
88
|
}
|
|
86
89
|
/**
|
|
87
90
|
* Gets the migration object.
|
|
@@ -110,14 +113,13 @@ function parseTopicsHeader(header) {
|
|
|
110
113
|
const value = header.trim();
|
|
111
114
|
let parsed;
|
|
112
115
|
try {
|
|
113
|
-
parsed = value.startsWith('[')
|
|
114
|
-
? JSON.parse(value)
|
|
115
|
-
: value.split(',').map(topic => topic.trim());
|
|
116
|
+
parsed = value.startsWith('[') ? JSON.parse(value) : value.split(',').map(topic => topic.trim());
|
|
116
117
|
}
|
|
117
118
|
catch {
|
|
118
119
|
throw new PublicRequestError('Invalid x-topics header: expected a comma-separated list or JSON string array');
|
|
119
120
|
}
|
|
120
|
-
if (!Array.isArray(parsed) ||
|
|
121
|
+
if (!Array.isArray(parsed) ||
|
|
122
|
+
parsed.some(topic => typeof topic !== 'string' || topic.length === 0)) {
|
|
121
123
|
throw new PublicRequestError('Invalid x-topics header: expected a comma-separated list or JSON string array');
|
|
122
124
|
}
|
|
123
125
|
return parsed;
|
|
@@ -194,7 +196,9 @@ class OverlayExpress {
|
|
|
194
196
|
requestTimeoutMs: 10000, // 10 seconds
|
|
195
197
|
hostDownRevokeScore: 3,
|
|
196
198
|
autoBanOnRemoval: true,
|
|
197
|
-
allowPrivateHosts: false
|
|
199
|
+
allowPrivateHosts: false,
|
|
200
|
+
batchSize: undefined,
|
|
201
|
+
maxReportResults: undefined
|
|
198
202
|
};
|
|
199
203
|
// Health endpoint configuration
|
|
200
204
|
this.healthConfig = {
|
|
@@ -254,6 +258,8 @@ class OverlayExpress {
|
|
|
254
258
|
* - hostDownRevokeScore: Number of consecutive failures before deleting output (default: 3)
|
|
255
259
|
* - autoBanOnRemoval: Whether to auto-ban domains when removed by janitor (default: true)
|
|
256
260
|
* - allowPrivateHosts: Permit private/HTTP targets for isolated local development (default: false)
|
|
261
|
+
* - batchSize: Mongo scan batch size; -1 uses the driver default
|
|
262
|
+
* - maxReportResults: Maximum retained result details; -1 retains all
|
|
257
263
|
*/
|
|
258
264
|
configureJanitor(config) {
|
|
259
265
|
this.janitorConfig = {
|
|
@@ -585,8 +591,13 @@ class OverlayExpress {
|
|
|
585
591
|
* @param autoConfigureShipSlap - Whether to auto-configure SHIP and SLAP services (default: true)
|
|
586
592
|
*/
|
|
587
593
|
async configureEngine(autoConfigureShipSlap = true) {
|
|
588
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
594
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
589
595
|
const knex = this.ensureKnex();
|
|
596
|
+
const maxLookupResults = (_a = this.engineConfig.maxLookupResults) !== null && _a !== void 0 ? _a : (0, edgePolicy_js_1.readResourceLimit)(this.edgePolicyConfig.environmentPrefix, 'MAX_LOOKUP_RESULTS', (0, edgePolicy_js_1.profileValue)((0, edgePolicy_js_1.readResourceProfile)(this.edgePolicyConfig.environmentPrefix), {
|
|
597
|
+
small: 500,
|
|
598
|
+
standard: 1000,
|
|
599
|
+
highThroughput: 5000
|
|
600
|
+
}), 1000000);
|
|
590
601
|
if (autoConfigureShipSlap) {
|
|
591
602
|
const mongoDb = this.ensureMongo();
|
|
592
603
|
const shipStorage = new DiscoveryServices.SHIPStorage(mongoDb);
|
|
@@ -603,8 +614,8 @@ class OverlayExpress {
|
|
|
603
614
|
const slapStorageForLookup = this.banService === undefined
|
|
604
615
|
? slapStorage
|
|
605
616
|
: new BanAwareDiscoveryStorage_js_1.BanAwareSLAPStorage(slapStorage, this.banService, this.logger);
|
|
606
|
-
this.services.ls_ship = new DiscoveryServices.SHIPLookupService(shipStorageForLookup);
|
|
607
|
-
this.services.ls_slap = new DiscoveryServices.SLAPLookupService(slapStorageForLookup);
|
|
617
|
+
this.services.ls_ship = new ResourceBoundedLookupWrapper_js_1.ResourceBoundedLookupWrapper(new DiscoveryServices.SHIPLookupService(shipStorageForLookup), maxLookupResults);
|
|
618
|
+
this.services.ls_slap = new ResourceBoundedLookupWrapper_js_1.ResourceBoundedLookupWrapper(new DiscoveryServices.SLAPLookupService(slapStorageForLookup), maxLookupResults);
|
|
608
619
|
this.logger.log(chalk_1.default.blue('Configured lookup service ls_ship with MongoDB'));
|
|
609
620
|
this.logger.log(chalk_1.default.blue('Configured lookup service ls_slap with MongoDB'));
|
|
610
621
|
}
|
|
@@ -615,9 +626,9 @@ class OverlayExpress {
|
|
|
615
626
|
const broadcaster = this.buildBroadcaster();
|
|
616
627
|
const advertiser = await this.buildAdvertiser();
|
|
617
628
|
const EngineWithBASM = overlay_1.Engine;
|
|
618
|
-
this.engine = new EngineWithBASM(this.managers, this.services, storage, (
|
|
619
|
-
? ((
|
|
620
|
-
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster !== null && broadcaster !== void 0 ? broadcaster : this.engineConfig.broadcaster, advertiser, syncConfig, (
|
|
629
|
+
this.engine = new EngineWithBASM(this.managers, this.services, storage, (_b = this.engineConfig.chainTracker) !== null && _b !== void 0 ? _b : this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
|
|
630
|
+
? ((_c = this.engineConfig.shipTrackers) !== null && _c !== void 0 ? _c : sdk_1.DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
631
|
+
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster !== null && broadcaster !== void 0 ? broadcaster : this.engineConfig.broadcaster, advertiser, syncConfig, (_d = this.engineConfig.logTime) !== null && _d !== void 0 ? _d : false, (_e = this.engineConfig.logPrefix) !== null && _e !== void 0 ? _e : '[OVERLAY_ENGINE] ', (_f = this.engineConfig.throwOnBroadcastFailure) !== null && _f !== void 0 ? _f : true, (_g = this.engineConfig.overlayBroadcastFacilitator) !== null && _g !== void 0 ? _g : new sdk_1.HTTPSOverlayBroadcastFacilitator(), this.logger, (_h = this.engineConfig.suppressDefaultSyncAdvertisements) !== null && _h !== void 0 ? _h : true, this.buildTopicAnchorHeaderResolver(), (_j = this.engineConfig.enableBASMSync) !== null && _j !== void 0 ? _j : this.enableBASMSync, (_k = this.engineConfig.unprovenEvictionBlocks) !== null && _k !== void 0 ? _k : this.unprovenEvictionBlocks, maxLookupResults);
|
|
621
632
|
this.initServerWallet();
|
|
622
633
|
this.logger.log(chalk_1.default.green('Engine has been configured.'));
|
|
623
634
|
}
|
|
@@ -750,7 +761,7 @@ class OverlayExpress {
|
|
|
750
761
|
if (!response.ok) {
|
|
751
762
|
throw new Error(`WhatsOnChain header lookup failed for height ${blockHeight}: ${response.status}`);
|
|
752
763
|
}
|
|
753
|
-
const header = await response.json();
|
|
764
|
+
const header = (await response.json());
|
|
754
765
|
if (typeof header.hash !== 'string') {
|
|
755
766
|
throw new TypeError(`WhatsOnChain did not return a block hash for height ${blockHeight}`);
|
|
756
767
|
}
|
|
@@ -832,7 +843,10 @@ class OverlayExpress {
|
|
|
832
843
|
* Creates a JanitorService instance with current configuration.
|
|
833
844
|
*/
|
|
834
845
|
createJanitor() {
|
|
846
|
+
var _a, _b;
|
|
835
847
|
const mongoDb = this.ensureMongo();
|
|
848
|
+
const prefix = this.edgePolicyConfig.environmentPrefix;
|
|
849
|
+
const profile = (0, edgePolicy_js_1.readResourceProfile)(prefix);
|
|
836
850
|
return new JanitorService_js_1.JanitorService({
|
|
837
851
|
mongoDb,
|
|
838
852
|
logger: this.logger,
|
|
@@ -840,7 +854,9 @@ class OverlayExpress {
|
|
|
840
854
|
hostDownRevokeScore: this.janitorConfig.hostDownRevokeScore,
|
|
841
855
|
banService: this.banService,
|
|
842
856
|
autoBanOnRemoval: this.janitorConfig.autoBanOnRemoval,
|
|
843
|
-
allowPrivateHosts: this.janitorConfig.allowPrivateHosts
|
|
857
|
+
allowPrivateHosts: this.janitorConfig.allowPrivateHosts,
|
|
858
|
+
batchSize: (_a = this.janitorConfig.batchSize) !== null && _a !== void 0 ? _a : (0, edgePolicy_js_1.readResourceLimit)(prefix, 'JANITOR_BATCH_SIZE', (0, edgePolicy_js_1.profileValue)(profile, { small: 100, standard: 250, highThroughput: 1000 }), 100000),
|
|
859
|
+
maxReportResults: (_b = this.janitorConfig.maxReportResults) !== null && _b !== void 0 ? _b : (0, edgePolicy_js_1.readResourceLimit)(prefix, 'JANITOR_MAX_REPORT_RESULTS', (0, edgePolicy_js_1.profileValue)(profile, { small: 500, standard: 1000, highThroughput: 5000 }), 1000000)
|
|
844
860
|
});
|
|
845
861
|
}
|
|
846
862
|
/** Ban a domain and remove all its SHIP/SLAP records from MongoDB. */
|
|
@@ -860,7 +876,9 @@ class OverlayExpress {
|
|
|
860
876
|
async handleBanOutpoint(res, engine, value, reason) {
|
|
861
877
|
const dotIndex = value.lastIndexOf('.');
|
|
862
878
|
if (dotIndex === -1) {
|
|
863
|
-
return res
|
|
879
|
+
return res
|
|
880
|
+
.status(400)
|
|
881
|
+
.json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
864
882
|
}
|
|
865
883
|
const txid = value.substring(0, dotIndex);
|
|
866
884
|
const outputIndex = Number.parseInt(value.substring(dotIndex + 1));
|
|
@@ -886,7 +904,9 @@ class OverlayExpress {
|
|
|
886
904
|
try {
|
|
887
905
|
await svc.outputEvicted(txid, outputIndex);
|
|
888
906
|
}
|
|
889
|
-
catch {
|
|
907
|
+
catch {
|
|
908
|
+
/* best-effort */
|
|
909
|
+
}
|
|
890
910
|
}
|
|
891
911
|
}
|
|
892
912
|
/** Look up the domain of an outpoint from SHIP or SLAP records. */
|
|
@@ -1026,7 +1046,7 @@ class OverlayExpress {
|
|
|
1026
1046
|
handler: check.handler
|
|
1027
1047
|
});
|
|
1028
1048
|
}
|
|
1029
|
-
const filteredDefinitions = definitions.filter(
|
|
1049
|
+
const filteredDefinitions = definitions.filter(definition => {
|
|
1030
1050
|
if (mode === 'full') {
|
|
1031
1051
|
return true;
|
|
1032
1052
|
}
|
|
@@ -1195,7 +1215,51 @@ class OverlayExpress {
|
|
|
1195
1215
|
const knex = this.ensureKnex();
|
|
1196
1216
|
this.startTime = new Date();
|
|
1197
1217
|
const edgePolicy = this.edgePolicyConfig;
|
|
1218
|
+
const resourceProfile = (0, edgePolicy_js_1.readResourceProfile)(edgePolicy.environmentPrefix);
|
|
1219
|
+
const maxResponseBytes = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'MAX_RESPONSE_BYTES', (0, edgePolicy_js_1.profileValue)(resourceProfile, {
|
|
1220
|
+
small: 4 * 1024 * 1024,
|
|
1221
|
+
standard: 8 * 1024 * 1024,
|
|
1222
|
+
highThroughput: 32 * 1024 * 1024
|
|
1223
|
+
}), 512 * 1024 * 1024);
|
|
1224
|
+
const maxBasmTxids = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'MAX_BASM_TXIDS', (0, edgePolicy_js_1.profileValue)(resourceProfile, { small: 500, standard: 1000, highThroughput: 5000 }), 1000000);
|
|
1225
|
+
const maxBasmAnchorRange = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'MAX_BASM_ANCHOR_RANGE', (0, edgePolicy_js_1.profileValue)(resourceProfile, { small: 500, standard: 1000, highThroughput: 5000 }), 1000000);
|
|
1226
|
+
const adminListDefaultLimit = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'ADMIN_LIST_DEFAULT_LIMIT', (0, edgePolicy_js_1.profileValue)(resourceProfile, { small: 25, standard: 50, highThroughput: 100 }), 1000000);
|
|
1227
|
+
const adminListMaxLimit = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'ADMIN_LIST_MAX_LIMIT', (0, edgePolicy_js_1.profileValue)(resourceProfile, { small: 100, standard: 200, highThroughput: 1000 }), 1000000);
|
|
1228
|
+
const adminListMaxOffset = (0, edgePolicy_js_1.readResourceLimit)(edgePolicy.environmentPrefix, 'ADMIN_LIST_MAX_OFFSET', (0, edgePolicy_js_1.profileValue)(resourceProfile, {
|
|
1229
|
+
small: 10000,
|
|
1230
|
+
standard: 100000,
|
|
1231
|
+
highThroughput: 1000000
|
|
1232
|
+
}), 100000000);
|
|
1233
|
+
if (adminListDefaultLimit !== -1 &&
|
|
1234
|
+
adminListMaxLimit !== -1 &&
|
|
1235
|
+
adminListDefaultLimit > adminListMaxLimit) {
|
|
1236
|
+
throw new TypeError('OVERLAY_ADMIN_LIST_DEFAULT_LIMIT cannot exceed OVERLAY_ADMIN_LIST_MAX_LIMIT');
|
|
1237
|
+
}
|
|
1238
|
+
const parseAdminPage = (rawPageValue, rawLimitValue) => {
|
|
1239
|
+
const rawPage = Number.parseInt(typeof rawPageValue === 'string' ? rawPageValue : '', 10);
|
|
1240
|
+
const requestedPage = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1241
|
+
const rawLimitText = typeof rawLimitValue === 'string' ? rawLimitValue.trim().toLowerCase() : '';
|
|
1242
|
+
const parsedLimit = rawLimitText === '-1' || rawLimitText === 'unlimited'
|
|
1243
|
+
? -1
|
|
1244
|
+
: Number.parseInt(rawLimitText, 10);
|
|
1245
|
+
const requestedLimit = rawLimitText.length === 0 || Number.isNaN(parsedLimit) ? adminListDefaultLimit : parsedLimit;
|
|
1246
|
+
if (requestedLimit !== -1 && (!Number.isSafeInteger(requestedLimit) || requestedLimit < 1)) {
|
|
1247
|
+
throw new TypeError('limit must be a positive integer, -1, or unlimited');
|
|
1248
|
+
}
|
|
1249
|
+
let limit = requestedLimit;
|
|
1250
|
+
if (adminListMaxLimit !== -1) {
|
|
1251
|
+
limit =
|
|
1252
|
+
requestedLimit === -1 ? adminListMaxLimit : Math.min(requestedLimit, adminListMaxLimit);
|
|
1253
|
+
}
|
|
1254
|
+
const page = limit === -1 ? 1 : requestedPage;
|
|
1255
|
+
const skip = limit === -1 ? 0 : (page - 1) * limit;
|
|
1256
|
+
if (!Number.isSafeInteger(skip) || (adminListMaxOffset !== -1 && skip > adminListMaxOffset)) {
|
|
1257
|
+
throw new TypeError('requested page exceeds the configured maximum offset');
|
|
1258
|
+
}
|
|
1259
|
+
return { page, limit, skip };
|
|
1260
|
+
};
|
|
1198
1261
|
this.app.disable('x-powered-by');
|
|
1262
|
+
this.app.use(edgePolicy_js_1.initialDoubleSlashCompatibility);
|
|
1199
1263
|
this.app.use((0, edgePolicy_js_1.securityHeaders)({
|
|
1200
1264
|
environmentPrefix: edgePolicy.environmentPrefix,
|
|
1201
1265
|
...edgePolicy.securityHeaders
|
|
@@ -1205,7 +1269,9 @@ class OverlayExpress {
|
|
|
1205
1269
|
allowedOrigins: edgePolicy.allowedOrigins,
|
|
1206
1270
|
methods: ['GET', 'POST', 'OPTIONS']
|
|
1207
1271
|
}));
|
|
1208
|
-
this.app.use((0, edgePolicy_js_1.concurrencyLimit)(edgePolicy.environmentPrefix, edgePolicy.maxConcurrentRequests
|
|
1272
|
+
this.app.use((0, edgePolicy_js_1.concurrencyLimit)(edgePolicy.environmentPrefix, edgePolicy.maxConcurrentRequests === 200
|
|
1273
|
+
? (0, edgePolicy_js_1.profileValue)(resourceProfile, { small: 8, standard: 24, highThroughput: 96 })
|
|
1274
|
+
: edgePolicy.maxConcurrentRequests));
|
|
1209
1275
|
this.app.use(body_parser_1.default.json({
|
|
1210
1276
|
limit: (0, edgePolicy_js_1.readBodyLimitBytes)(`${edgePolicy.environmentPrefix}_JSON`, edgePolicy.jsonBodyLimitBytes),
|
|
1211
1277
|
type: 'application/json'
|
|
@@ -1215,6 +1281,7 @@ class OverlayExpress {
|
|
|
1215
1281
|
type: 'application/octet-stream'
|
|
1216
1282
|
}));
|
|
1217
1283
|
this.app.use(edgePolicy_js_1.bodyParserErrorHandler);
|
|
1284
|
+
this.app.use((0, edgePolicy_js_1.responseSizeLimit)(edgePolicy.environmentPrefix, maxResponseBytes));
|
|
1218
1285
|
if (this.verboseRequestLogging) {
|
|
1219
1286
|
this.setupVerboseRequestLogging();
|
|
1220
1287
|
}
|
|
@@ -1232,7 +1299,7 @@ class OverlayExpress {
|
|
|
1232
1299
|
(async () => {
|
|
1233
1300
|
const report = await this.collectHealthReport('live');
|
|
1234
1301
|
return res.status(report.live ? 200 : 503).json(report);
|
|
1235
|
-
})().catch(
|
|
1302
|
+
})().catch(error => {
|
|
1236
1303
|
this.logger.error({ operation: 'overlay.health_live', error });
|
|
1237
1304
|
res.status(500).json({
|
|
1238
1305
|
status: 'error',
|
|
@@ -1240,12 +1307,23 @@ class OverlayExpress {
|
|
|
1240
1307
|
});
|
|
1241
1308
|
});
|
|
1242
1309
|
});
|
|
1310
|
+
// Compatibility alias used by Kubernetes probes and existing deployments.
|
|
1311
|
+
this.app.get('/healthz', (_, res) => {
|
|
1312
|
+
;
|
|
1313
|
+
(async () => {
|
|
1314
|
+
const report = await this.collectHealthReport('live');
|
|
1315
|
+
return res.status(report.live ? 200 : 503).json(report);
|
|
1316
|
+
})().catch(error => {
|
|
1317
|
+
this.logger.error({ operation: 'overlay.healthz', error });
|
|
1318
|
+
res.status(500).json({ status: 'error', message: 'Health report unavailable' });
|
|
1319
|
+
});
|
|
1320
|
+
});
|
|
1243
1321
|
this.app.get('/health/ready', (_, res) => {
|
|
1244
1322
|
;
|
|
1245
1323
|
(async () => {
|
|
1246
1324
|
const report = await this.collectHealthReport('ready');
|
|
1247
1325
|
return res.status(report.ready ? 200 : 503).json(report);
|
|
1248
|
-
})().catch(
|
|
1326
|
+
})().catch(error => {
|
|
1249
1327
|
this.logger.error({ operation: 'overlay.health_ready', error });
|
|
1250
1328
|
res.status(500).json({
|
|
1251
1329
|
status: 'error',
|
|
@@ -1258,7 +1336,7 @@ class OverlayExpress {
|
|
|
1258
1336
|
(async () => {
|
|
1259
1337
|
const report = await this.collectHealthReport('full');
|
|
1260
1338
|
return res.status(report.ready ? 200 : 503).json(report);
|
|
1261
|
-
})().catch(
|
|
1339
|
+
})().catch(error => {
|
|
1262
1340
|
this.logger.error({ operation: 'overlay.health_full', error });
|
|
1263
1341
|
res.status(500).json({
|
|
1264
1342
|
status: 'error',
|
|
@@ -1439,7 +1517,7 @@ class OverlayExpress {
|
|
|
1439
1517
|
// Write outputIndex
|
|
1440
1518
|
writer.writeVarIntNum(output.outputIndex);
|
|
1441
1519
|
// Write context length and data
|
|
1442
|
-
if (
|
|
1520
|
+
if (output.context != null && output.context.length > 0) {
|
|
1443
1521
|
writer.writeVarIntNum(output.context.length);
|
|
1444
1522
|
writer.write(output.context);
|
|
1445
1523
|
}
|
|
@@ -1583,12 +1661,23 @@ class OverlayExpress {
|
|
|
1583
1661
|
if (!Array.isArray(value) || !value.every(txid => typeof txid === 'string')) {
|
|
1584
1662
|
throw new PublicRequestError('txids must be an array of strings');
|
|
1585
1663
|
}
|
|
1664
|
+
if (maxBasmTxids !== -1 && value.length > maxBasmTxids) {
|
|
1665
|
+
throw new PublicRequestError(`txids must contain at most ${maxBasmTxids} entries`);
|
|
1666
|
+
}
|
|
1586
1667
|
return value;
|
|
1587
1668
|
};
|
|
1588
1669
|
registerJsonRoute('/requestTopicAnchorTip', async (req) => await basmEngine.provideTopicAnchorTip(readBasmTopic(req)));
|
|
1589
1670
|
registerJsonRoute('/requestTopicAnchorRange', async (req) => {
|
|
1590
1671
|
const { fromHeight, toHeight } = req.body;
|
|
1591
|
-
|
|
1672
|
+
const from = Number(fromHeight);
|
|
1673
|
+
const to = Number(toHeight);
|
|
1674
|
+
if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to < from) {
|
|
1675
|
+
throw new PublicRequestError('fromHeight and toHeight must define a valid ascending range');
|
|
1676
|
+
}
|
|
1677
|
+
if (maxBasmAnchorRange !== -1 && to - from + 1 > maxBasmAnchorRange) {
|
|
1678
|
+
throw new PublicRequestError(`topic anchor range must contain at most ${maxBasmAnchorRange} blocks`);
|
|
1679
|
+
}
|
|
1680
|
+
return await basmEngine.provideTopicAnchorRange(readBasmTopic(req), from, to);
|
|
1592
1681
|
});
|
|
1593
1682
|
registerJsonRoute('/requestAdmittedList', async (req) => {
|
|
1594
1683
|
const { blockHeight, blockHash } = req.body;
|
|
@@ -1648,7 +1737,10 @@ class OverlayExpress {
|
|
|
1648
1737
|
res.status(403).json({ status: 'error', message: 'Forbidden: Invalid credentials' });
|
|
1649
1738
|
return;
|
|
1650
1739
|
}
|
|
1651
|
-
res.status(401).json({
|
|
1740
|
+
res.status(401).json({
|
|
1741
|
+
status: 'error',
|
|
1742
|
+
message: 'Unauthorized: Provide a Bearer token or authenticate with your wallet'
|
|
1743
|
+
});
|
|
1652
1744
|
};
|
|
1653
1745
|
/**
|
|
1654
1746
|
* Public endpoint that returns the admin identity key (if configured).
|
|
@@ -1718,11 +1810,7 @@ class OverlayExpress {
|
|
|
1718
1810
|
const db = this.ensureMongo();
|
|
1719
1811
|
const collection = db.collection('shipRecords');
|
|
1720
1812
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1721
|
-
const
|
|
1722
|
-
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1723
|
-
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1724
|
-
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1725
|
-
const skip = (page - 1) * limit;
|
|
1813
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
1726
1814
|
const query = {};
|
|
1727
1815
|
if (typeof search === 'string' && search.length > 0) {
|
|
1728
1816
|
query.$or = [
|
|
@@ -1733,12 +1821,23 @@ class OverlayExpress {
|
|
|
1733
1821
|
];
|
|
1734
1822
|
}
|
|
1735
1823
|
const [records, total] = await Promise.all([
|
|
1736
|
-
|
|
1824
|
+
(() => {
|
|
1825
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(skip);
|
|
1826
|
+
if (limit !== -1)
|
|
1827
|
+
cursor = cursor.limit(limit);
|
|
1828
|
+
return cursor.toArray();
|
|
1829
|
+
})(),
|
|
1737
1830
|
collection.countDocuments(query)
|
|
1738
1831
|
]);
|
|
1739
1832
|
return res.status(200).json({
|
|
1740
1833
|
status: 'success',
|
|
1741
|
-
data: {
|
|
1834
|
+
data: {
|
|
1835
|
+
records,
|
|
1836
|
+
total,
|
|
1837
|
+
page,
|
|
1838
|
+
limit,
|
|
1839
|
+
pages: limit === -1 ? 1 : Math.ceil(total / limit)
|
|
1840
|
+
}
|
|
1742
1841
|
});
|
|
1743
1842
|
}
|
|
1744
1843
|
catch (error) {
|
|
@@ -1761,11 +1860,7 @@ class OverlayExpress {
|
|
|
1761
1860
|
const db = this.ensureMongo();
|
|
1762
1861
|
const collection = db.collection('slapRecords');
|
|
1763
1862
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1764
|
-
const
|
|
1765
|
-
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1766
|
-
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1767
|
-
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1768
|
-
const skip = (page - 1) * limit;
|
|
1863
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
1769
1864
|
const query = {};
|
|
1770
1865
|
if (typeof search === 'string' && search.length > 0) {
|
|
1771
1866
|
query.$or = [
|
|
@@ -1776,12 +1871,23 @@ class OverlayExpress {
|
|
|
1776
1871
|
];
|
|
1777
1872
|
}
|
|
1778
1873
|
const [records, total] = await Promise.all([
|
|
1779
|
-
|
|
1874
|
+
(() => {
|
|
1875
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(skip);
|
|
1876
|
+
if (limit !== -1)
|
|
1877
|
+
cursor = cursor.limit(limit);
|
|
1878
|
+
return cursor.toArray();
|
|
1879
|
+
})(),
|
|
1780
1880
|
collection.countDocuments(query)
|
|
1781
1881
|
]);
|
|
1782
1882
|
return res.status(200).json({
|
|
1783
1883
|
status: 'success',
|
|
1784
|
-
data: {
|
|
1884
|
+
data: {
|
|
1885
|
+
records,
|
|
1886
|
+
total,
|
|
1887
|
+
page,
|
|
1888
|
+
limit,
|
|
1889
|
+
pages: limit === -1 ? 1 : Math.ceil(total / limit)
|
|
1890
|
+
}
|
|
1785
1891
|
});
|
|
1786
1892
|
}
|
|
1787
1893
|
catch (error) {
|
|
@@ -1828,11 +1934,16 @@ class OverlayExpress {
|
|
|
1828
1934
|
(async () => {
|
|
1829
1935
|
try {
|
|
1830
1936
|
if (this.banService === undefined) {
|
|
1831
|
-
return res.status(400).json({
|
|
1937
|
+
return res.status(400).json({
|
|
1938
|
+
status: 'error',
|
|
1939
|
+
message: 'Ban service not available (MongoDB not configured)'
|
|
1940
|
+
});
|
|
1832
1941
|
}
|
|
1833
1942
|
const { type, value, reason } = req.body;
|
|
1834
1943
|
if (type !== 'domain' && type !== 'outpoint') {
|
|
1835
|
-
return res
|
|
1944
|
+
return res
|
|
1945
|
+
.status(400)
|
|
1946
|
+
.json({ status: 'error', message: 'type must be "domain" or "outpoint"' });
|
|
1836
1947
|
}
|
|
1837
1948
|
if (typeof value !== 'string' || value.length === 0) {
|
|
1838
1949
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
@@ -1864,13 +1975,17 @@ class OverlayExpress {
|
|
|
1864
1975
|
}
|
|
1865
1976
|
const { type, value } = req.body;
|
|
1866
1977
|
if (type !== 'domain' && type !== 'outpoint') {
|
|
1867
|
-
return res
|
|
1978
|
+
return res
|
|
1979
|
+
.status(400)
|
|
1980
|
+
.json({ status: 'error', message: 'type must be "domain" or "outpoint"' });
|
|
1868
1981
|
}
|
|
1869
1982
|
if (typeof value !== 'string' || value.length === 0) {
|
|
1870
1983
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
1871
1984
|
}
|
|
1872
1985
|
await this.banService.removeBan(type, value);
|
|
1873
|
-
return res
|
|
1986
|
+
return res
|
|
1987
|
+
.status(200)
|
|
1988
|
+
.json({ status: 'success', message: `${type} "${String(value)}" unbanned.` });
|
|
1874
1989
|
}
|
|
1875
1990
|
catch (error) {
|
|
1876
1991
|
return res.status(400).json({
|
|
@@ -1894,8 +2009,9 @@ class OverlayExpress {
|
|
|
1894
2009
|
}
|
|
1895
2010
|
const type = req.query.type;
|
|
1896
2011
|
const validType = type === 'domain' || type === 'outpoint' ? type : undefined;
|
|
1897
|
-
const
|
|
1898
|
-
|
|
2012
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
2013
|
+
const bans = await this.banService.listBans(validType, limit, skip);
|
|
2014
|
+
return res.status(200).json({ status: 'success', data: { bans, page, limit } });
|
|
1899
2015
|
}
|
|
1900
2016
|
catch (error) {
|
|
1901
2017
|
return res.status(400).json({
|
|
@@ -1916,7 +2032,10 @@ class OverlayExpress {
|
|
|
1916
2032
|
try {
|
|
1917
2033
|
const { txid, outputIndex, service, ban, banDomain: shouldBanDomain } = req.body;
|
|
1918
2034
|
if (typeof txid !== 'string' || typeof outputIndex !== 'number') {
|
|
1919
|
-
return res.status(400).json({
|
|
2035
|
+
return res.status(400).json({
|
|
2036
|
+
status: 'error',
|
|
2037
|
+
message: 'txid (string) and outputIndex (number) are required'
|
|
2038
|
+
});
|
|
1920
2039
|
}
|
|
1921
2040
|
// Look up domain before eviction if needed for banning
|
|
1922
2041
|
let removedDomain;
|
|
@@ -1927,7 +2046,9 @@ class OverlayExpress {
|
|
|
1927
2046
|
if (ban === true && this.banService !== undefined) {
|
|
1928
2047
|
await this.banService.banOutpoint(txid, outputIndex, 'Manually removed by admin', removedDomain);
|
|
1929
2048
|
}
|
|
1930
|
-
if (shouldBanDomain === true &&
|
|
2049
|
+
if (shouldBanDomain === true &&
|
|
2050
|
+
typeof removedDomain === 'string' &&
|
|
2051
|
+
this.banService !== undefined) {
|
|
1931
2052
|
await this.banDomainAndRemoveRecords(removedDomain, 'Domain banned by admin via token removal');
|
|
1932
2053
|
}
|
|
1933
2054
|
const banMsg = ban === true ? ' Outpoint banned.' : '';
|
|
@@ -1957,7 +2078,9 @@ class OverlayExpress {
|
|
|
1957
2078
|
(async () => {
|
|
1958
2079
|
try {
|
|
1959
2080
|
await engine.syncAdvertisements();
|
|
1960
|
-
return res
|
|
2081
|
+
return res
|
|
2082
|
+
.status(200)
|
|
2083
|
+
.json({ status: 'success', message: 'Advertisements synced successfully' });
|
|
1961
2084
|
}
|
|
1962
2085
|
catch (error) {
|
|
1963
2086
|
console.error(chalk_1.default.red('Error in /admin/syncAdvertisements:'), error);
|
|
@@ -1981,7 +2104,9 @@ class OverlayExpress {
|
|
|
1981
2104
|
(async () => {
|
|
1982
2105
|
try {
|
|
1983
2106
|
await engine.startGASPSync();
|
|
1984
|
-
return res
|
|
2107
|
+
return res
|
|
2108
|
+
.status(200)
|
|
2109
|
+
.json({ status: 'success', message: 'GASP sync started and completed' });
|
|
1985
2110
|
}
|
|
1986
2111
|
catch (error) {
|
|
1987
2112
|
console.error(chalk_1.default.red('Error in /admin/startGASPSync:'), error);
|
|
@@ -2093,7 +2218,9 @@ class OverlayExpress {
|
|
|
2093
2218
|
try {
|
|
2094
2219
|
const janitor = this.createJanitor();
|
|
2095
2220
|
const report = await janitor.run();
|
|
2096
|
-
return res
|
|
2221
|
+
return res
|
|
2222
|
+
.status(200)
|
|
2223
|
+
.json({ status: 'success', message: 'Janitor run completed', data: report });
|
|
2097
2224
|
}
|
|
2098
2225
|
catch (error) {
|
|
2099
2226
|
console.error(chalk_1.default.red('Error in /admin/janitor:'), error);
|
|
@@ -2266,8 +2393,12 @@ class OverlayExpress {
|
|
|
2266
2393
|
const basmEngine = this.engine;
|
|
2267
2394
|
this.reorgAdapter = new ReorgStream_js_1.ReorgSseAdapter({
|
|
2268
2395
|
url: reorgStreamUrl,
|
|
2269
|
-
onReorg: async (input) => {
|
|
2270
|
-
|
|
2396
|
+
onReorg: async (input) => {
|
|
2397
|
+
await (basmEngine === null || basmEngine === void 0 ? void 0 : basmEngine.handleReorg(input));
|
|
2398
|
+
},
|
|
2399
|
+
onConnect: async () => {
|
|
2400
|
+
await (basmEngine === null || basmEngine === void 0 ? void 0 : basmEngine.revalidateRecentAnchors(reorgScanDepth));
|
|
2401
|
+
},
|
|
2271
2402
|
logger: this.logger
|
|
2272
2403
|
});
|
|
2273
2404
|
this.reorgAdapter.start();
|