@bsv/overlay-express 0.7.2 → 0.7.4

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.
@@ -37,14 +37,14 @@ interface Migration {
37
37
  * Allows running migrations defined in code rather than files.
38
38
  */
39
39
  class InMemoryMigrationSource implements Knex.Knex.MigrationSource<Migration> {
40
- constructor(private readonly migrations: Migration[]) { }
40
+ constructor (private readonly migrations: Migration[]) { }
41
41
 
42
42
  /**
43
43
  * Gets the list of migrations.
44
44
  * @param loadExtensions - Array of file extensions to filter by (not used here)
45
45
  * @returns Promise resolving to the array of migrations
46
46
  */
47
- async getMigrations(loadExtensions: readonly string[]): Promise<Migration[]> {
47
+ async getMigrations (loadExtensions: readonly string[]): Promise<Migration[]> {
48
48
  return this.migrations
49
49
  }
50
50
 
@@ -53,7 +53,7 @@ class InMemoryMigrationSource implements Knex.Knex.MigrationSource<Migration> {
53
53
  * @param migration - The migration object
54
54
  * @returns The name of the migration
55
55
  */
56
- getMigrationName(migration: Migration): string {
56
+ getMigrationName (migration: Migration): string {
57
57
  return typeof migration.name === 'string' ? migration.name : `Migration at index ${this.migrations.indexOf(migration)}`
58
58
  }
59
59
 
@@ -62,7 +62,7 @@ class InMemoryMigrationSource implements Knex.Knex.MigrationSource<Migration> {
62
62
  * @param migration - The migration object
63
63
  * @returns Promise resolving to the migration object
64
64
  */
65
- async getMigration(migration: Migration): Promise<Knex.Knex.Migration> {
65
+ async getMigration (migration: Migration): Promise<Knex.Knex.Migration> {
66
66
  return await Promise.resolve(migration)
67
67
  }
68
68
  }
@@ -99,13 +99,13 @@ export default class OverlayExpress {
99
99
  logger: typeof console = console
100
100
 
101
101
  // Knex (SQL) database
102
- knex: Knex.Knex | undefined = undefined
102
+ knex: Knex.Knex = {} as unknown as Knex.Knex
103
103
 
104
104
  // Knex migrations to run
105
105
  migrationsToRun: Migration[] = []
106
106
 
107
107
  // MongoDB database
108
- mongoDb: Db | undefined = undefined
108
+ mongoDb: Db = {} as unknown as Db
109
109
 
110
110
  // Network ('main' or 'test')
111
111
  network: 'main' | 'test' = 'main'
@@ -115,7 +115,7 @@ export default class OverlayExpress {
115
115
  chainTracker: ChainTracker | 'scripts only' = new WhatsOnChain(this.network)
116
116
 
117
117
  // The Overlay Engine
118
- engine: Engine | undefined = undefined
118
+ engine: Engine = {} as unknown as Engine
119
119
 
120
120
  // Configured Topic Managers
121
121
  managers: Record<string, TopicManager> = {}
@@ -152,7 +152,7 @@ export default class OverlayExpress {
152
152
  * @param adminToken - Optional. An administrative Bearer token used to protect admin routes.
153
153
  * If not provided, a random token will be generated at runtime.
154
154
  */
155
- constructor(
155
+ constructor (
156
156
  public name: string,
157
157
  public privateKey: string,
158
158
  public advertisableFQDN: string,
@@ -160,13 +160,13 @@ export default class OverlayExpress {
160
160
  ) {
161
161
  this.app = express()
162
162
  this.logger.log(chalk.green.bold(`${name} constructed 🎉`))
163
- this.adminToken = adminToken || uuidv4() // generate random if not provided
163
+ this.adminToken = adminToken ?? uuidv4() // generate random if not provided
164
164
  }
165
165
 
166
166
  /**
167
167
  * Returns the current admin token in case you need to programmatically retrieve or display it.
168
168
  */
169
- getAdminToken(): string {
169
+ getAdminToken (): string {
170
170
  return this.adminToken
171
171
  }
172
172
 
@@ -174,7 +174,7 @@ export default class OverlayExpress {
174
174
  * Configures the port on which the server will listen.
175
175
  * @param port - The port number
176
176
  */
177
- configurePort(port: number): void {
177
+ configurePort (port: number): void {
178
178
  this.port = port
179
179
  this.logger.log(chalk.blue(`🌐 Server port set to ${port}`))
180
180
  }
@@ -183,7 +183,7 @@ export default class OverlayExpress {
183
183
  * Configures the web user interface
184
184
  * @param config - Web UI configuration options
185
185
  */
186
- configureWebUI(config: UIConfig): void {
186
+ configureWebUI (config: UIConfig): void {
187
187
  this.webUIConfig = config
188
188
  this.logger.log(chalk.blue('🖥️ Web UI has been configured.'))
189
189
  }
@@ -192,7 +192,7 @@ export default class OverlayExpress {
192
192
  * Configures the logger to be used by the server.
193
193
  * @param logger - A logger object (e.g., console)
194
194
  */
195
- configureLogger(logger: typeof console): void {
195
+ configureLogger (logger: typeof console): void {
196
196
  this.logger = logger
197
197
  this.logger.log(chalk.blue('🔍 Logger has been configured.'))
198
198
  }
@@ -202,7 +202,7 @@ export default class OverlayExpress {
202
202
  * By default, it re-initializes chainTracker as a WhatsOnChain for that network.
203
203
  * @param network - The network ('main' or 'test')
204
204
  */
205
- configureNetwork(network: 'main' | 'test'): void {
205
+ configureNetwork (network: 'main' | 'test'): void {
206
206
  this.network = network
207
207
  this.chainTracker = new WhatsOnChain(this.network)
208
208
  this.logger.log(chalk.blue(`🔗 Network set to ${network}`))
@@ -213,7 +213,7 @@ export default class OverlayExpress {
213
213
  * If 'scripts only' is used, it implies no full SPV chain tracking in the Engine.
214
214
  * @param chainTracker - An instance of ChainTracker or 'scripts only'
215
215
  */
216
- configureChainTracker(chainTracker: ChainTracker | 'scripts only' = new WhatsOnChain(this.network)): void {
216
+ configureChainTracker (chainTracker: ChainTracker | 'scripts only' = new WhatsOnChain(this.network)): void {
217
217
  this.chainTracker = chainTracker
218
218
  this.logger.log(chalk.blue('🔗 ChainTracker has been configured.'))
219
219
  }
@@ -222,7 +222,7 @@ export default class OverlayExpress {
222
222
  * Configures the ARC API key.
223
223
  * @param apiKey - The ARC API key
224
224
  */
225
- configureArcApiKey(apiKey: string): void {
225
+ configureArcApiKey (apiKey: string): void {
226
226
  this.arcApiKey = apiKey
227
227
  this.logger.log(chalk.blue('🔑 ARC API key has been configured.'))
228
228
  }
@@ -232,7 +232,7 @@ export default class OverlayExpress {
232
232
  * This is a broad toggle that can be overridden or customized through syncConfiguration.
233
233
  * @param enable - true to enable, false to disable
234
234
  */
235
- configureEnableGASPSync(enable: boolean): void {
235
+ configureEnableGASPSync (enable: boolean): void {
236
236
  this.enableGASPSync = enable
237
237
  this.logger.log(chalk.blue(`🔄 GASP synchronization ${enable ? 'enabled' : 'disabled'}.`))
238
238
  }
@@ -241,7 +241,7 @@ export default class OverlayExpress {
241
241
  * Enables or disables verbose request logging.
242
242
  * @param enable - true to enable, false to disable
243
243
  */
244
- configureVerboseRequestLogging(enable: boolean): void {
244
+ configureVerboseRequestLogging (enable: boolean): void {
245
245
  this.verboseRequestLogging = enable
246
246
  this.logger.log(chalk.blue(`📝 Verbose request logging ${enable ? 'enabled' : 'disabled'}.`))
247
247
  }
@@ -250,7 +250,7 @@ export default class OverlayExpress {
250
250
  * Configure Knex (SQL) database connection.
251
251
  * @param config - Knex configuration object, or MySQL connection string (e.g. mysql://overlayAdmin:overlay123@mysql:3306/overlay).
252
252
  */
253
- async configureKnex(config: Knex.Knex.Config | string): Promise<void> {
253
+ async configureKnex (config: Knex.Knex.Config | string): Promise<void> {
254
254
  if (typeof config === 'string') {
255
255
  config = {
256
256
  client: 'mysql2',
@@ -265,7 +265,7 @@ export default class OverlayExpress {
265
265
  * Configures the MongoDB database connection.
266
266
  * @param connectionString - MongoDB connection string
267
267
  */
268
- async configureMongo(connectionString: string): Promise<void> {
268
+ async configureMongo (connectionString: string): Promise<void> {
269
269
  const mongoClient = new MongoClient(connectionString)
270
270
  await mongoClient.connect()
271
271
  const db = mongoClient.db(`${this.name}_lookup_services`)
@@ -278,7 +278,7 @@ export default class OverlayExpress {
278
278
  * @param name - The name of the Topic Manager
279
279
  * @param manager - An instance of TopicManager
280
280
  */
281
- configureTopicManager(name: string, manager: TopicManager): void {
281
+ configureTopicManager (name: string, manager: TopicManager): void {
282
282
  this.managers[name] = manager
283
283
  this.logger.log(chalk.blue(`🗂️ Configured topic manager ${name}`))
284
284
  }
@@ -288,7 +288,7 @@ export default class OverlayExpress {
288
288
  * @param name - The name of the Lookup Service
289
289
  * @param service - An instance of LookupService
290
290
  */
291
- configureLookupService(name: string, service: LookupService): void {
291
+ configureLookupService (name: string, service: LookupService): void {
292
292
  this.services[name] = service
293
293
  this.logger.log(chalk.blue(`🔍 Configured lookup service ${name}`))
294
294
  }
@@ -298,12 +298,12 @@ export default class OverlayExpress {
298
298
  * @param name - The name of the Lookup Service
299
299
  * @param serviceFactory - A factory function that creates a LookupService instance using Knex
300
300
  */
301
- configureLookupServiceWithKnex(
301
+ configureLookupServiceWithKnex (
302
302
  name: string,
303
- serviceFactory: (knex: Knex.Knex) => { service: LookupService; migrations: Migration[] }
303
+ serviceFactory: (knex: Knex.Knex) => { service: LookupService, migrations: Migration[] }
304
304
  ): void {
305
305
  this.ensureKnex()
306
- const factoryResult = serviceFactory(this.knex as Knex.Knex)
306
+ const factoryResult = serviceFactory(this.knex)
307
307
  this.services[name] = factoryResult.service
308
308
  this.migrationsToRun.push(...factoryResult.migrations)
309
309
  this.logger.log(chalk.blue(`🔍 Configured lookup service ${name} with Knex`))
@@ -314,9 +314,9 @@ export default class OverlayExpress {
314
314
  * @param name - The name of the Lookup Service
315
315
  * @param serviceFactory - A factory function that creates a LookupService instance using MongoDB
316
316
  */
317
- configureLookupServiceWithMongo(name: string, serviceFactory: (mongoDb: Db) => LookupService): void {
317
+ configureLookupServiceWithMongo (name: string, serviceFactory: (mongoDb: Db) => LookupService): void {
318
318
  this.ensureMongo()
319
- this.services[name] = serviceFactory(this.mongoDb as Db)
319
+ this.services[name] = serviceFactory(this.mongoDb)
320
320
  this.logger.log(chalk.blue(`🔍 Configured lookup service ${name} with MongoDB`))
321
321
  }
322
322
 
@@ -334,7 +334,7 @@ export default class OverlayExpress {
334
334
  * These fields will be respected when we finally build/configure the Engine
335
335
  * in the `configureEngine()` method below.
336
336
  */
337
- configureEngineParams(params: EngineConfig): void {
337
+ configureEngineParams (params: EngineConfig): void {
338
338
  this.engineConfig = {
339
339
  ...this.engineConfig,
340
340
  ...params
@@ -349,7 +349,7 @@ export default class OverlayExpress {
349
349
  *
350
350
  * @param autoConfigureShipSlap - Whether to auto-configure SHIP and SLAP services (default: true)
351
351
  */
352
- async configureEngine(autoConfigureShipSlap = true): Promise<void> {
352
+ async configureEngine (autoConfigureShipSlap = true): Promise<void> {
353
353
  this.ensureKnex()
354
354
 
355
355
  if (autoConfigureShipSlap) {
@@ -373,11 +373,11 @@ export default class OverlayExpress {
373
373
  }
374
374
  } else {
375
375
  // If the user provided a syncConfiguration, use that. Otherwise default to an empty object.
376
- syncConfig = this.engineConfig.syncConfiguration || {}
376
+ syncConfig = this.engineConfig.syncConfiguration ?? {}
377
377
  }
378
378
 
379
379
  // Build the actual Storage
380
- const storage = new KnexStorage(this.knex as Knex.Knex)
380
+ const storage = new KnexStorage(this.knex)
381
381
  // Include the KnexStorage migrations
382
382
  this.migrationsToRun = [...KnexStorageMigrations.default, ...this.migrationsToRun]
383
383
 
@@ -456,7 +456,7 @@ export default class OverlayExpress {
456
456
  * Ensures that Knex is configured.
457
457
  * @throws Error if Knex is not configured
458
458
  */
459
- private ensureKnex(): void {
459
+ private ensureKnex (): void {
460
460
  if (typeof this.knex === 'undefined') {
461
461
  throw new Error('You must configure your SQL database with the .configureKnex() method first!')
462
462
  }
@@ -466,7 +466,7 @@ export default class OverlayExpress {
466
466
  * Ensures that MongoDB is configured.
467
467
  * @throws Error if MongoDB is not configured
468
468
  */
469
- private ensureMongo(): void {
469
+ private ensureMongo (): void {
470
470
  if (typeof this.mongoDb === 'undefined') {
471
471
  throw new Error('You must configure your MongoDB connection with the .configureMongo() method first!')
472
472
  }
@@ -476,7 +476,7 @@ export default class OverlayExpress {
476
476
  * Ensures that the Overlay Engine is configured.
477
477
  * @throws Error if the Engine is not configured
478
478
  */
479
- private ensureEngine(): void {
479
+ private ensureEngine (): void {
480
480
  if (typeof this.engine === 'undefined') {
481
481
  throw new Error('You must configure your Overlay Services engine with the .configureEngine() method first!')
482
482
  }
@@ -486,11 +486,11 @@ export default class OverlayExpress {
486
486
  * Starts the Express server.
487
487
  * Sets up routes and begins listening on the configured port.
488
488
  */
489
- async start(): Promise<void> {
489
+ async start (): Promise<void> {
490
490
  this.ensureEngine()
491
491
  this.ensureKnex()
492
- const engine = this.engine as Engine
493
- const knex = this.knex as Knex.Knex
492
+ const engine = this.engine
493
+ const knex = this.knex
494
494
 
495
495
  this.app.use(bodyParser.json({ limit: '1gb', type: 'application/json' }))
496
496
  this.app.use(bodyParser.raw({ limit: '1gb', type: 'application/octet-stream' }))
@@ -500,13 +500,13 @@ export default class OverlayExpress {
500
500
  const startTime = Date.now()
501
501
 
502
502
  // Log incoming request details
503
- this.logger.log(chalk.magenta.bold(`📥 Incoming Request: ${req.method} ${req.originalUrl}`))
503
+ this.logger.log(chalk.magenta.bold(`📥 Incoming Request: ${String(req.method)} ${String(req.originalUrl)}`))
504
504
  // Pretty-print headers
505
- this.logger.log(chalk.cyan(`Headers:`))
505
+ this.logger.log(chalk.cyan('Headers:'))
506
506
  this.logger.log(util.inspect(req.headers, { colors: true, depth: null }))
507
507
 
508
508
  // Handle request body
509
- if (req.body && Object.keys(req.body).length > 0) {
509
+ if (req.body != null && Object.keys(req.body).length > 0) {
510
510
  let bodyContent
511
511
  let bodyString
512
512
  if (typeof req.body === 'object') {
@@ -514,12 +514,12 @@ export default class OverlayExpress {
514
514
  } else if (Buffer.isBuffer(req.body)) {
515
515
  bodyString = req.body.toString('utf8')
516
516
  } else {
517
- bodyString = req.body.toString()
517
+ bodyString = String(req.body)
518
518
  }
519
519
  if (bodyString.length > 280) {
520
- bodyContent = chalk.yellow(`(Body too long to display, length: ${bodyString.length} characters)`)
520
+ bodyContent = chalk.yellow(`(Body too long to display, length: ${String(bodyString.length)} characters)`)
521
521
  } else {
522
- bodyContent = chalk.green(`Request Body:\n${bodyString}`)
522
+ bodyContent = chalk.green(`Request Body:\n${String(bodyString)}`)
523
523
  }
524
524
  this.logger.log(bodyContent)
525
525
  }
@@ -538,27 +538,29 @@ export default class OverlayExpress {
538
538
  const duration = Date.now() - startTime
539
539
  this.logger.log(
540
540
  chalk.magenta.bold(
541
- `📤 Outgoing Response: ${req.method} ${req.originalUrl} - Status: ${res.statusCode} - Duration: ${duration}ms`
541
+ `📤 Outgoing Response: ${String(req.method)} ${String(req.originalUrl)} - Status: ${String(res.statusCode)} - Duration: ${String(duration)}ms`
542
542
  )
543
543
  )
544
- this.logger.log(chalk.cyan(`Response Headers:`))
544
+ this.logger.log(chalk.cyan('Response Headers:'))
545
545
  this.logger.log(util.inspect(res.getHeaders(), { colors: true, depth: null }))
546
546
 
547
547
  // Handle response body
548
- if (responseBody) {
548
+ if (responseBody != null) {
549
549
  let bodyContent
550
550
  let bodyString
551
551
  if (typeof responseBody === 'object') {
552
552
  bodyString = JSON.stringify(responseBody, null, 2)
553
553
  } else if (Buffer.isBuffer(responseBody)) {
554
554
  bodyString = responseBody.toString('utf8')
555
+ } else if (typeof responseBody === 'string') {
556
+ bodyString = responseBody
555
557
  } else {
556
- bodyString = responseBody.toString()
558
+ bodyString = String(responseBody)
557
559
  }
558
560
  if (bodyString.length > 280) {
559
- bodyContent = chalk.yellow(`(Response body too long to display, length: ${bodyString.length} characters)`)
561
+ bodyContent = chalk.yellow(`(Response body too long to display, length: ${String(bodyString.length)} characters)`)
560
562
  } else {
561
- bodyContent = chalk.green(`Response Body:\n${bodyString}`)
563
+ bodyContent = chalk.green(`Response Body:\n${String(bodyString)}`)
562
564
  }
563
565
  this.logger.log(bodyContent)
564
566
  }
@@ -824,7 +826,7 @@ export default class OverlayExpress {
824
826
  * Middleware for checking the admin bearer token.
825
827
  */
826
828
  const checkAdminAuth = (req: express.Request, res: express.Response, next: express.NextFunction): void => {
827
- const authHeader = req.headers['authorization']
829
+ const authHeader = req.headers.authorization
828
830
  if (typeof authHeader !== 'string' || !authHeader.startsWith('Bearer ')) {
829
831
  res.status(401).json({ status: 'error', message: 'Unauthorized: Missing Bearer token' })
830
832
  return
@@ -972,7 +974,7 @@ export default class OverlayExpress {
972
974
  }
973
975
 
974
976
  // Start listening on the configured port
975
- this.app.listen(this.port, async () => {
977
+ this.app.listen(this.port, () => {
976
978
  this.logger.log(chalk.green.bold(`🎧 ${this.name} is ready and listening on local port ${this.port}`))
977
979
  })
978
980
  }
@@ -10,7 +10,7 @@ A Topic Manager controls addition and removal of transaction outputs to an Overl
10
10
  #### Request Headers
11
11
  \\\`\\\`\\\`json
12
12
  {
13
- "x-topics": "[\"tm_messagebox\"]", // array of topic identifiers as stringified JSON
13
+ "x-topics": "["tm_messagebox"]", // array of topic identifiers as stringified JSON
14
14
  "x-includes-off-chain-values": "false" // string "true" or "false"
15
15
  }
16
16
  \\\`\\\`\\\`
@@ -71,4 +71,4 @@ Usually Topic Managers and Lookup Services are paired, but they can be separated
71
71
  <br />
72
72
  <br />
73
73
  \`
74
- `;
74
+ `
@@ -1,23 +1,24 @@
1
+ /* eslint-disable */
1
2
  import generalGuide from './generalGuide.md.js'
2
3
 
3
- export type UIConfig = {
4
- host?: string;
5
- faviconUrl?: string;
6
- backgroundColor?: string;
7
- primaryColor?: string;
8
- secondaryColor?: string;
9
- fontFamily?: string;
10
- headingFontFamily?: string;
11
- additionalStyles?: string;
12
- sectionBackgroundColor?: string;
13
- primaryTextColor?: string;
14
- linkColor?: string;
15
- hoverColor?: string;
16
- borderColor?: string;
17
- secondaryBackgroundColor?: string;
18
- secondaryTextColor?: string;
19
- defaultContent?: string;
20
- };
4
+ export interface UIConfig {
5
+ host?: string
6
+ faviconUrl?: string
7
+ backgroundColor?: string
8
+ primaryColor?: string
9
+ secondaryColor?: string
10
+ fontFamily?: string
11
+ headingFontFamily?: string
12
+ additionalStyles?: string
13
+ sectionBackgroundColor?: string
14
+ primaryTextColor?: string
15
+ linkColor?: string
16
+ hoverColor?: string
17
+ borderColor?: string
18
+ secondaryBackgroundColor?: string
19
+ secondaryTextColor?: string
20
+ defaultContent?: string
21
+ }
21
22
 
22
23
  export default (config: UIConfig = {}): string => {
23
24
  const {
@@ -37,7 +38,7 @@ export default (config: UIConfig = {}): string => {
37
38
  secondaryBackgroundColor = '#f8f8f8',
38
39
  secondaryTextColor = '#0e0e0e',
39
40
  defaultContent = generalGuide
40
- } = config;
41
+ } = config
41
42
 
42
43
  return `<!DOCTYPE html>
43
44
  <html>
@@ -544,5 +545,5 @@ export default (config: UIConfig = {}): string => {
544
545
  </div>
545
546
  </div>
546
547
  </body>
547
- </html>`;
548
- };
548
+ </html>`
549
+ }