@bsv/overlay-express 2.0.2 → 2.1.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/mod.js +7 -1
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +3 -1
- package/dist/cjs/src/BanAwareLookupWrapper.js +76 -0
- package/dist/cjs/src/BanAwareLookupWrapper.js.map +1 -0
- package/dist/cjs/src/BanService.js +118 -0
- package/dist/cjs/src/BanService.js.map +1 -0
- package/dist/cjs/src/JanitorService.js +206 -93
- package/dist/cjs/src/JanitorService.js.map +1 -1
- package/dist/cjs/src/OverlayExpress.js +522 -71
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/makeUserInterface.js +889 -217
- package/dist/cjs/src/makeUserInterface.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +4 -1
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/BanAwareLookupWrapper.js +78 -0
- package/dist/esm/src/BanAwareLookupWrapper.js.map +1 -0
- package/dist/esm/src/BanService.js +115 -0
- package/dist/esm/src/BanService.js.map +1 -0
- package/dist/esm/src/JanitorService.js +199 -92
- package/dist/esm/src/JanitorService.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +528 -72
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/makeUserInterface.js +889 -217
- package/dist/esm/src/makeUserInterface.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +4 -1
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/BanAwareLookupWrapper.d.ts +31 -0
- package/dist/types/src/BanAwareLookupWrapper.d.ts.map +1 -0
- package/dist/types/src/BanService.d.ts +81 -0
- package/dist/types/src/BanService.d.ts.map +1 -0
- package/dist/types/src/JanitorService.d.ts +69 -13
- package/dist/types/src/JanitorService.d.ts.map +1 -1
- package/dist/types/src/OverlayExpress.d.ts +28 -4
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/makeUserInterface.d.ts +2 -0
- package/dist/types/src/makeUserInterface.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +4 -1
- package/package.json +3 -1
- package/src/BanAwareLookupWrapper.ts +95 -0
- package/src/BanService.ts +154 -0
- package/src/JanitorService.ts +277 -101
- package/src/OverlayExpress.ts +575 -76
- package/src/__tests__/BanAwareLookupWrapper.test.ts +255 -0
- package/src/__tests__/BanService.test.ts +310 -0
- package/src/__tests__/JanitorService.test.ts +342 -5
- package/src/__tests__/OverlayExpress.test.ts +19 -6
- package/src/__tests__/makeUserInterface.test.ts +4 -3
- package/src/makeUserInterface.ts +892 -217
package/dist/types/mod.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from './src/OverlayExpress.js';
|
|
2
|
+
export { BanService, type BannedRecord } from './src/BanService.js';
|
|
3
|
+
export { BanAwareLookupWrapper } from './src/BanAwareLookupWrapper.js';
|
|
4
|
+
export { JanitorService, type JanitorConfig, type JanitorReport, type HostHealthResult } from './src/JanitorService.js';
|
|
2
5
|
//# sourceMappingURL=mod.d.ts.map
|
package/dist/types/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LookupService, LookupFormula, AdmissionMode, SpendNotificationMode, OutputAdmittedByTopic, OutputSpent, LookupServiceMetaData } from '@bsv/overlay';
|
|
2
|
+
import { LookupQuestion } from '@bsv/sdk';
|
|
3
|
+
import { BanService } from './BanService.js';
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a SHIP or SLAP LookupService to intercept outputAdmittedByTopic calls
|
|
6
|
+
* and block outputs whose domain or outpoint appears in the persistent ban list.
|
|
7
|
+
*
|
|
8
|
+
* This prevents GASP from re-syncing stale or banned tokens that were previously
|
|
9
|
+
* removed by the Janitor or an admin.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BanAwareLookupWrapper implements LookupService {
|
|
12
|
+
private readonly wrapped;
|
|
13
|
+
private readonly banService;
|
|
14
|
+
private readonly protocol;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
readonly admissionMode: AdmissionMode;
|
|
17
|
+
readonly spendNotificationMode: SpendNotificationMode;
|
|
18
|
+
constructor(wrapped: LookupService, banService: BanService, protocol: 'SHIP' | 'SLAP', logger?: typeof console);
|
|
19
|
+
/**
|
|
20
|
+
* Intercepts admission to check the ban list before delegating to the wrapped service.
|
|
21
|
+
* If the output's domain or outpoint is banned, the admission is silently blocked.
|
|
22
|
+
*/
|
|
23
|
+
outputAdmittedByTopic(payload: OutputAdmittedByTopic): Promise<void>;
|
|
24
|
+
outputSpent(payload: OutputSpent): Promise<void>;
|
|
25
|
+
outputNoLongerRetainedInHistory(txid: string, outputIndex: number, topic: string): Promise<void>;
|
|
26
|
+
outputEvicted(txid: string, outputIndex: number): Promise<void>;
|
|
27
|
+
lookup(question: LookupQuestion): Promise<LookupFormula>;
|
|
28
|
+
getDocumentation(): Promise<string>;
|
|
29
|
+
getMetaData(): Promise<LookupServiceM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AAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAIzD,gBAAgB,IAAK,OAAO,CAAC,MAAM,CAAC;IAIpC,WAAW,IAAK,OAAO,CAAC,qBAAqB,CAAC;CAGrD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a banned record in the persistent ban list.
|
|
4
|
+
* Bans survive server restarts, GASP re-syncs, and janitor runs.
|
|
5
|
+
*/
|
|
6
|
+
export interface BannedRecord {
|
|
7
|
+
type: 'domain' | 'outpoint';
|
|
8
|
+
/** For domain bans: the domain URL. For outpoint bans: "txid.outputIndex" */
|
|
9
|
+
value: string;
|
|
10
|
+
/** For outpoint bans, the associated domain (for reference) */
|
|
11
|
+
domain?: string;
|
|
12
|
+
/** Human-readable reason for the ban */
|
|
13
|
+
reason?: string;
|
|
14
|
+
/** When the ban was created */
|
|
15
|
+
bannedAt: Date;
|
|
16
|
+
/** Identity key of the admin who created the ban */
|
|
17
|
+
bannedBy?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* BanService provides a persistent ban list stored in MongoDB.
|
|
21
|
+
*
|
|
22
|
+
* When the Janitor or an admin removes a SHIP/SLAP token, the associated
|
|
23
|
+
* domain or outpoint can be added to the ban list. The BanAwareLookupWrapper
|
|
24
|
+
* checks this list before admitting new outputs, preventing GASP from
|
|
25
|
+
* re-syncing previously removed stale tokens.
|
|
26
|
+
*/
|
|
27
|
+
export declare class BanService {
|
|
28
|
+
private readonly bans;
|
|
29
|
+
constructor(db: Db);
|
|
30
|
+
/**
|
|
31
|
+
* Sanitizes a value for use in MongoDB queries, preventing NoSQL injection.
|
|
32
|
+
* Ensures the value is a plain string and rejects objects/arrays that could
|
|
33
|
+
* contain MongoDB operators like $ne, $gt, etc.
|
|
34
|
+
*/
|
|
35
|
+
private sanitize;
|
|
36
|
+
/**
|
|
37
|
+
* Creates indexes for efficient ban lookups.
|
|
38
|
+
*/
|
|
39
|
+
ensureIndexes(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Bans a domain, preventing any SHIP/SLAP tokens referencing it from being stored.
|
|
42
|
+
*/
|
|
43
|
+
banDomain(domain: string, reason?: string, bannedBy?: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Removes a domain ban.
|
|
46
|
+
*/
|
|
47
|
+
unbanDomain(domain: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a domain is banned.
|
|
50
|
+
*/
|
|
51
|
+
isDomainBanned(domain: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Bans a specific outpoint (txid.outputIndex), preventing it from being re-admitted.
|
|
54
|
+
*/
|
|
55
|
+
banOutpoint(txid: string, outputIndex: number, reason?: string, domain?: string, bannedBy?: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Removes an outpoint ban.
|
|
58
|
+
*/
|
|
59
|
+
unbanOutpoint(txid: string, outputIndex: number): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a specific outpoint is banned.
|
|
62
|
+
*/
|
|
63
|
+
isOutpointBanned(txid: string, outputIndex: number): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Lists all bans, optionally filtered by type.
|
|
66
|
+
*/
|
|
67
|
+
listBans(type?: 'domain' | 'outpoint'): Promise<BannedRecord[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Removes a ban by type and value.
|
|
70
|
+
*/
|
|
71
|
+
removeBan(type: 'domain' | 'outpoint', value: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns ban statistics.
|
|
74
|
+
*/
|
|
75
|
+
getStats(): Promise<{
|
|
76
|
+
domainBans: number;
|
|
77
|
+
outpointBans: number;
|
|
78
|
+
totalBans: number;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=BanService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BanService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IAKtE;;OAEG;IACG,gBAAgB,CAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM5E;;OAEG;IACG,QAAQ,CAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAKtE;;OAEG;IACG,SAAS,CAAE,IAAI,EAAE,QAAQ,GAAG,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E;;OAEG;IACG,QAAQ,IAAK,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAO5F"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Db } from 'mongodb';
|
|
2
|
+
import { BanService } from './BanService.js';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration for the Janitor Service
|
|
4
5
|
*/
|
|
@@ -7,32 +8,89 @@ export interface JanitorConfig {
|
|
|
7
8
|
logger?: typeof console;
|
|
8
9
|
requestTimeoutMs?: number;
|
|
9
10
|
hostDownRevokeScore?: number;
|
|
11
|
+
/** Optional BanService for persisting bans when hosts are removed */
|
|
12
|
+
banService?: BanService;
|
|
13
|
+
/** Whether to auto-ban domains when they exceed the down threshold (default: true) */
|
|
14
|
+
autoBanOnRemoval?: boolean;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
|
-
*
|
|
17
|
+
* Health status of a single record
|
|
18
|
+
*/
|
|
19
|
+
export interface HostHealthResult {
|
|
20
|
+
txid: string;
|
|
21
|
+
outputIndex: number;
|
|
22
|
+
domain: string;
|
|
23
|
+
topic?: string;
|
|
24
|
+
service?: string;
|
|
25
|
+
identityKey?: string;
|
|
26
|
+
createdAt?: Date;
|
|
27
|
+
healthy: boolean;
|
|
28
|
+
downCount: number;
|
|
29
|
+
responseTimeMs?: number;
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Summary report from a janitor run
|
|
35
|
+
*/
|
|
36
|
+
export interface JanitorReport {
|
|
37
|
+
startedAt: Date;
|
|
38
|
+
completedAt: Date;
|
|
39
|
+
durationMs: number;
|
|
40
|
+
shipResults: HostHealthResult[];
|
|
41
|
+
slapResults: HostHealthResult[];
|
|
42
|
+
summary: {
|
|
43
|
+
totalChecked: number;
|
|
44
|
+
healthy: number;
|
|
45
|
+
unhealthy: number;
|
|
46
|
+
removed: number;
|
|
47
|
+
banned: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* JanitorService runs health checks on SHIP and SLAP outputs.
|
|
13
52
|
* It validates domain names and checks /health endpoints to ensure services are operational.
|
|
14
53
|
*
|
|
15
54
|
* When a service is down, it increments a "down" counter. When healthy, it decrements.
|
|
16
|
-
* If the down counter reaches
|
|
17
|
-
*
|
|
18
|
-
* This service is designed to be run periodically via external schedulers (e.g., cron, docker-compose).
|
|
55
|
+
* If the down counter reaches hostDownRevokeScore, the output is deleted and optionally
|
|
56
|
+
* the domain is added to the persistent ban list to prevent GASP re-sync.
|
|
19
57
|
*/
|
|
20
58
|
export declare class JanitorService {
|
|
21
59
|
private readonly mongoDb;
|
|
22
60
|
private readonly logger;
|
|
23
61
|
private readonly requestTimeoutMs;
|
|
24
62
|
private readonly hostDownRevokeScore;
|
|
63
|
+
private readonly banService?;
|
|
64
|
+
private readonly autoBanOnRemoval;
|
|
25
65
|
constructor(config: JanitorConfig);
|
|
26
66
|
/**
|
|
27
|
-
* Runs a
|
|
67
|
+
* Runs a full pass of health checks on all SHIP and SLAP outputs.
|
|
68
|
+
* Returns a detailed report of the results.
|
|
28
69
|
*/
|
|
29
|
-
run(): Promise<
|
|
70
|
+
run(): Promise<JanitorReport>;
|
|
30
71
|
/**
|
|
31
|
-
* Checks
|
|
72
|
+
* Checks a single URL's health endpoint. Used by the admin dashboard for on-demand checks.
|
|
73
|
+
*/
|
|
74
|
+
checkHost(url: string): Promise<{
|
|
75
|
+
healthy: boolean;
|
|
76
|
+
responseTimeMs: number;
|
|
77
|
+
statusCode?: number;
|
|
78
|
+
error?: string;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Gets health status for all records without modifying them.
|
|
82
|
+
* Used by the dashboard to display current state.
|
|
83
|
+
*/
|
|
84
|
+
getHealthStatus(): Promise<{
|
|
85
|
+
ship: HostHealthResult[];
|
|
86
|
+
slap: HostHealthResult[];
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Checks all outputs for a specific collection and returns results.
|
|
32
90
|
*/
|
|
33
91
|
private checkTopicOutputs;
|
|
34
92
|
/**
|
|
35
|
-
* Checks a single output for health
|
|
93
|
+
* Checks a single output for health and returns the result.
|
|
36
94
|
*/
|
|
37
95
|
private checkOutput;
|
|
38
96
|
/**
|
|
@@ -43,16 +101,14 @@ export declare class JanitorService {
|
|
|
43
101
|
* Validates if a string is a valid domain name
|
|
44
102
|
*/
|
|
45
103
|
private isValidDomain;
|
|
46
|
-
/**
|
|
47
|
-
* Checks the /health endpoint of a service
|
|
48
|
-
*/
|
|
49
|
-
private checkHealthEndpoint;
|
|
50
104
|
/**
|
|
51
105
|
* Handles a healthy output by decrementing its down counter
|
|
52
106
|
*/
|
|
53
107
|
private handleHealthyOutput;
|
|
54
108
|
/**
|
|
55
|
-
* Handles an unhealthy output by incrementing its down counter
|
|
109
|
+
* Handles an unhealthy output by incrementing its down counter.
|
|
110
|
+
* If the threshold is reached, deletes the record and optionally bans the domain.
|
|
111
|
+
* Returns true if the record was removed.
|
|
56
112
|
*/
|
|
57
113
|
private handleUnhealthyOutput;
|
|
58
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JanitorService.d.ts","sourceRoot":"","sources":["../../../src/JanitorService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,E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QACf,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAI;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAY;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;gBAE7B,MAAM,EAAE,aAAa;IASlC;;;OAGG;IACG,GAAG,IAAK,OAAO,CAAC,aAAa,CAAC;IA4CpC;;OAEG;IACG,SAAS,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAgDzH;;;OAGG;IACG,eAAe,IAAK,OAAO,CAAC;QAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;QAAC,IAAI,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC;IAkCzF;;OAEG;YACW,iBAAiB;IAiC/B;;OAEG;YACW,WAAW;IA2DzB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAyB5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;YACW,mBAAmB;IAcjC;;;;OAIG;YACW,qBAAqB;CA0CpC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { Engine, LookupService, TopicManager, Advertiser } from '@bsv/overlay';
|
|
3
|
-
import { ChainTracker, Broadcaster, OverlayBroadcastFacilitator } from '@bsv/sdk';
|
|
3
|
+
import { ChainTracker, Broadcaster, OverlayBroadcastFacilitator, WalletInterface } from '@bsv/sdk';
|
|
4
4
|
import Knex from 'knex';
|
|
5
5
|
import { Db } from 'mongodb';
|
|
6
6
|
import { type UIConfig } from './makeUserInterface.js';
|
|
7
|
+
import { BanService } from './BanService.js';
|
|
7
8
|
/**
|
|
8
9
|
* Knex database migration.
|
|
9
10
|
*/
|
|
@@ -57,7 +58,12 @@ export default class OverlayExpress {
|
|
|
57
58
|
janitorConfig: {
|
|
58
59
|
requestTimeoutMs: number;
|
|
59
60
|
hostDownRevokeScore: number;
|
|
61
|
+
autoBanOnRemoval: boolean;
|
|
60
62
|
};
|
|
63
|
+
banService?: BanService;
|
|
64
|
+
adminIdentityKey?: string;
|
|
65
|
+
serverWallet?: WalletInterface;
|
|
66
|
+
private startTime?;
|
|
61
67
|
/**
|
|
62
68
|
* Constructs an instance of OverlayExpress.
|
|
63
69
|
* @param name - The name of the service
|
|
@@ -86,8 +92,17 @@ export default class OverlayExpress {
|
|
|
86
92
|
* @param config - Janitor configuration options
|
|
87
93
|
* - requestTimeoutMs: Timeout for health check requests (default: 10000ms)
|
|
88
94
|
* - hostDownRevokeScore: Number of consecutive failures before deleting output (default: 3)
|
|
95
|
+
* - autoBanOnRemoval: Whether to auto-ban domains when removed by janitor (default: true)
|
|
89
96
|
*/
|
|
90
97
|
configureJanitor(config: Partial<typeof this.janitorConfig>): void;
|
|
98
|
+
/**
|
|
99
|
+
* Configures the admin identity key for wallet-based admin detection.
|
|
100
|
+
* When set, the frontend can compare the user's wallet identity key against this
|
|
101
|
+
* to determine whether to show the admin dashboard.
|
|
102
|
+
*
|
|
103
|
+
* @param identityKey - The hex-encoded public key of the admin
|
|
104
|
+
*/
|
|
105
|
+
configureAdminIdentityKey(identityKey: string): void;
|
|
91
106
|
/**
|
|
92
107
|
* Configures the logger to be used by the server.
|
|
93
108
|
* @param logger - A logger object (e.g., console)
|
|
@@ -128,6 +143,7 @@ export default class OverlayExpress {
|
|
|
128
143
|
configureKnex(config: Knex.Knex.Config | string): Promise<void>;
|
|
129
144
|
/**
|
|
130
145
|
* Configures the MongoDB database connection.
|
|
146
|
+
* Also initializes the BanService for persistent ban tracking.
|
|
131
147
|
* @param connectionString - MongoDB connection string
|
|
132
148
|
*/
|
|
133
149
|
configureMongo(connectionString: string): Promise<void>;
|
|
@@ -178,24 +194,32 @@ export default class OverlayExpress {
|
|
|
178
194
|
* By default, auto-configures SHIP and SLAP unless autoConfigureShipSlap = false
|
|
179
195
|
* Then it merges in any advanced engine config from `this.engineConfig`.
|
|
180
196
|
*
|
|
197
|
+
* When a BanService is available (from configureMongo), SHIP and SLAP lookup
|
|
198
|
+
* services are automatically wrapped with BanAwareLookupWrapper to prevent
|
|
199
|
+
* GASP from re-syncing banned tokens.
|
|
200
|
+
*
|
|
181
201
|
* @param autoConfigureShipSlap - Whether to auto-configure SHIP and SLAP services (default: true)
|
|
182
202
|
*/
|
|
183
203
|
configureEngine(autoConfigureShipSlap?: boolean): Promise<void>;
|
|
184
204
|
/**
|
|
185
|
-
* Ensures that Knex is configured.
|
|
205
|
+
* Ensures that Knex is configured and returns it.
|
|
186
206
|
* @throws Error if Knex is not configured
|
|
187
207
|
*/
|
|
188
208
|
private ensureKnex;
|
|
189
209
|
/**
|
|
190
|
-
* Ensures that MongoDB is configured.
|
|
210
|
+
* Ensures that MongoDB is configured and returns it.
|
|
191
211
|
* @throws Error if MongoDB is not configured
|
|
192
212
|
*/
|
|
193
213
|
private ensureMongo;
|
|
194
214
|
/**
|
|
195
|
-
* Ensures that the Overlay Engine is configured.
|
|
215
|
+
* Ensures that the Overlay Engine is configured and returns it.
|
|
196
216
|
* @throws Error if the Engine is not configured
|
|
197
217
|
*/
|
|
198
218
|
private ensureEngine;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a JanitorService instance with current configuration.
|
|
221
|
+
*/
|
|
222
|
+
private createJanitor;
|
|
199
223
|
/**
|
|
200
224
|
* Starts the Express server.
|
|
201
225
|
* Sets up routes and begins listening on the configured port.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OverlayExpress.d.ts","sourceRoot":"","sources":["../../../src/OverlayExpress.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,MAAM,EAAe,aAAa,EAAE,YAAY,EAAyB,UAAU,EAAE,MAAM,cAAc,CAAA;AAClH,OAAO,EAEL,YAAY,EAKZ,WAAW,EACX,2BAA2B,
|
|
1
|
+
{"version":3,"file":"OverlayExpress.d.ts","sourceRoot":"","sources":["../../../src/OverlayExpress.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,MAAM,EAAe,aAAa,EAAE,YAAY,EAAyB,UAAU,EAAE,MAAM,cAAc,CAAA;AAClH,OAAO,EAEL,YAAY,EAKZ,WAAW,EACX,2BAA2B,EAS3B,eAAe,EAChB,MAAM,UAAU,CAAA;AACjB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAA;AACzC,OAA0B,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAMzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAK5C;;GAEG;AACH,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1C;AAqCD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,YAAY,GAAG,cAAc,CAAA;IAC5C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,WAA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AI,CAAC;IAWtE;;;;OAIG;IACG,cAAc,CAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9D;;;;OAIG;IACH,qBAAqB,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAKjE;;;;OAIG;IACH,sBAAsB,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAKnE;;;;OAIG;IACH,8BAA8B,CAC5B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK;QAAE,OAAO,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,GACvF,IAAI;IAQP;;;;OAIG;IACH,+BAA+B,CAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,aAAa,GAAG,IAAI;IAMpG;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IAQlD;;;;;;;;;;OAUG;IACG,eAAe,CAAE,qBAAqB,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoJnE;;;OAGG;IACH,OAAO,CAAC,UAAU;IAOlB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAOnB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;;OAGG;IACG,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;CA08B9B"}
|
|
@@ -15,6 +15,8 @@ export interface UIConfig {
|
|
|
15
15
|
secondaryBackgroundColor?: string;
|
|
16
16
|
secondaryTextColor?: string;
|
|
17
17
|
defaultContent?: string;
|
|
18
|
+
/** Admin identity key for wallet-based admin detection */
|
|
19
|
+
adminIdentityKey?: string;
|
|
18
20
|
}
|
|
19
21
|
declare const _default: (config?: UIConfig) => string;
|
|
20
22
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeUserInterface.d.ts","sourceRoot":"","sources":["../../../src/makeUserInterface.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"makeUserInterface.d.ts","sourceRoot":"","sources":["../../../src/makeUserInterface.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CA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