@bsv/overlay-express 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/OverlayExpress.ts +14 -2
- package/src/makeUserInterface.ts +167 -137
package/package.json
CHANGED
package/src/OverlayExpress.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Engine, KnexStorage, LookupService, TopicManager, KnexStorageMigrations
|
|
|
4
4
|
import { ARC, ChainTracker, MerklePath, STEAK, TaggedBEEF, WhatsOnChain } from '@bsv/sdk'
|
|
5
5
|
import Knex from 'knex'
|
|
6
6
|
import { MongoClient, Db } from 'mongodb'
|
|
7
|
-
import makeUserInterface from './makeUserInterface.js'
|
|
7
|
+
import makeUserInterface, { type UIConfig } from './makeUserInterface.js'
|
|
8
8
|
import * as DiscoveryServices from '@bsv/overlay-discovery-services'
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -99,6 +99,9 @@ export default class OverlayExpress {
|
|
|
99
99
|
// Verbose request logging
|
|
100
100
|
verboseRequestLogging: boolean = false
|
|
101
101
|
|
|
102
|
+
// Web UI configuration
|
|
103
|
+
webUIConfig: UIConfig = {}
|
|
104
|
+
|
|
102
105
|
/**
|
|
103
106
|
* Constructs an instance of OverlayExpress.
|
|
104
107
|
* @param name - The name of the service
|
|
@@ -123,6 +126,15 @@ export default class OverlayExpress {
|
|
|
123
126
|
this.logger.log(`Server port set to ${port}`)
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Configures the web user interface
|
|
131
|
+
* @param config - Web UI configuration options
|
|
132
|
+
*/
|
|
133
|
+
configureWebUI(config: UIConfig) {
|
|
134
|
+
this.webUIConfig = config
|
|
135
|
+
this.logger.log('Web UI has been configured.')
|
|
136
|
+
}
|
|
137
|
+
|
|
126
138
|
/**
|
|
127
139
|
* Configures the logger to be used by the server.
|
|
128
140
|
* @param logger - A logger object (e.g., console)
|
|
@@ -384,7 +396,7 @@ export default class OverlayExpress {
|
|
|
384
396
|
// Serve a static documentation site or user interface
|
|
385
397
|
this.app.get('/', (req, res) => {
|
|
386
398
|
res.set('content-type', 'text/html')
|
|
387
|
-
res.send(makeUserInterface())
|
|
399
|
+
res.send(makeUserInterface(this.webUIConfig))
|
|
388
400
|
})
|
|
389
401
|
|
|
390
402
|
// List hosted topic managers and lookup services
|
package/src/makeUserInterface.ts
CHANGED
|
@@ -1,188 +1,219 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type UIConfig = {
|
|
2
|
+
faviconUrl?: string;
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
primaryColor?: string;
|
|
5
|
+
secondaryColor?: string;
|
|
6
|
+
fontFamily?: string;
|
|
7
|
+
headingFontFamily?: string;
|
|
8
|
+
additionalStyles?: string;
|
|
9
|
+
sectionBackgroundColor?: string;
|
|
10
|
+
linkColor?: string;
|
|
11
|
+
hoverColor?: string;
|
|
12
|
+
borderColor?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default (config: UIConfig = {}): string => {
|
|
16
|
+
const {
|
|
17
|
+
faviconUrl = 'https://bsvblockchain.org/favicon.ico',
|
|
18
|
+
backgroundColor = '#282E33',
|
|
19
|
+
primaryColor = '#B6C2CF',
|
|
20
|
+
secondaryColor = '#579DFF',
|
|
21
|
+
fontFamily = 'Arial, sans-serif',
|
|
22
|
+
headingFontFamily = 'Arial Black, Gadget, sans-serif',
|
|
23
|
+
additionalStyles = '',
|
|
24
|
+
sectionBackgroundColor = '#323940',
|
|
25
|
+
linkColor = '#579DFF',
|
|
26
|
+
hoverColor = '#3A4147',
|
|
27
|
+
borderColor = '#B6C2CF',
|
|
28
|
+
} = config;
|
|
29
|
+
|
|
30
|
+
return `<!DOCTYPE html>
|
|
2
31
|
<html>
|
|
3
32
|
<head>
|
|
4
33
|
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1
|
|
34
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
35
|
<title>Overlay Services</title>
|
|
36
|
+
<link rel="icon" type="image/x-icon" href="${faviconUrl}">
|
|
7
37
|
<style>
|
|
38
|
+
:root {
|
|
39
|
+
--background-color: ${backgroundColor};
|
|
40
|
+
--primary-color: ${primaryColor};
|
|
41
|
+
--secondary-color: ${secondaryColor};
|
|
42
|
+
--font-family: ${fontFamily};
|
|
43
|
+
--heading-font-family: ${headingFontFamily};
|
|
44
|
+
--section-background-color: ${sectionBackgroundColor};
|
|
45
|
+
--link-color: ${linkColor};
|
|
46
|
+
--hover-color: ${hoverColor};
|
|
47
|
+
--border-color: ${borderColor};
|
|
48
|
+
}
|
|
49
|
+
|
|
8
50
|
body {
|
|
9
|
-
font-family:
|
|
10
|
-
background-color:
|
|
11
|
-
|
|
51
|
+
font-family: var(--font-family);
|
|
52
|
+
background-color: var(--background-color);
|
|
53
|
+
margin: 0;
|
|
54
|
+
padding: 0;
|
|
12
55
|
}
|
|
13
56
|
|
|
14
|
-
|
|
15
|
-
|
|
57
|
+
h1, h2, h3 {
|
|
58
|
+
font-family: var(--heading-font-family);
|
|
16
59
|
}
|
|
17
60
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
word-wrap: break-word;
|
|
21
|
-
display: flex;
|
|
22
|
-
flex-direction: row;
|
|
61
|
+
* {
|
|
62
|
+
color: var(--primary-color);
|
|
23
63
|
}
|
|
24
64
|
|
|
25
65
|
a {
|
|
26
|
-
color:
|
|
66
|
+
color: var(--link-color);
|
|
67
|
+
text-decoration: none;
|
|
27
68
|
}
|
|
28
69
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
padding-bottom: 0.5em;
|
|
32
|
-
border-bottom: thin solid #B6C2CF;
|
|
70
|
+
a:hover {
|
|
71
|
+
color: var(--secondary-color);
|
|
33
72
|
}
|
|
34
73
|
|
|
35
|
-
.
|
|
36
|
-
|
|
74
|
+
.main {
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: row;
|
|
77
|
+
height: 100vh;
|
|
78
|
+
overflow: hidden;
|
|
37
79
|
}
|
|
38
80
|
|
|
39
|
-
.
|
|
40
|
-
padding
|
|
81
|
+
.column_left, .column_right {
|
|
82
|
+
padding: 1.5em;
|
|
83
|
+
overflow-y: auto;
|
|
41
84
|
}
|
|
42
85
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
margin-top: 0.5em;
|
|
47
|
-
width: 10em;
|
|
48
|
-
border-radius: 5%;
|
|
86
|
+
.column_left {
|
|
87
|
+
width: 35%;
|
|
88
|
+
background-color: var(--section-background-color);
|
|
49
89
|
}
|
|
50
90
|
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
color: #B6C2CF;
|
|
55
|
-
text-decoration: none;
|
|
91
|
+
.column_right {
|
|
92
|
+
width: 65%;
|
|
93
|
+
border-left: 1px solid var(--border-color);
|
|
56
94
|
}
|
|
57
95
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
96
|
+
.docs_heading {
|
|
97
|
+
text-align: center;
|
|
98
|
+
padding-bottom: 0.5em;
|
|
99
|
+
border-bottom: 1px solid var(--border-color);
|
|
62
100
|
}
|
|
63
101
|
|
|
64
102
|
ul {
|
|
65
103
|
list-style-type: none;
|
|
66
|
-
|
|
104
|
+
padding: 0;
|
|
67
105
|
}
|
|
68
106
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
flex-direction: column;
|
|
72
|
-
float: left;
|
|
73
|
-
width: 40%;
|
|
74
|
-
height: 100vh;
|
|
75
|
-
overflow-y: scroll;
|
|
76
|
-
padding-top: 1.5em;
|
|
107
|
+
li {
|
|
108
|
+
margin: 0.5em 0;
|
|
77
109
|
}
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
display:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
overflow-y: scroll;
|
|
86
|
-
border-left: thin solid #B6C2CF;
|
|
87
|
-
padding-top: 1.5em;
|
|
111
|
+
li a {
|
|
112
|
+
display: block;
|
|
113
|
+
padding: 0.5em;
|
|
114
|
+
background-color: transparent;
|
|
115
|
+
border-radius: 5px;
|
|
116
|
+
transition: background-color 0.3s;
|
|
88
117
|
}
|
|
89
118
|
|
|
90
|
-
|
|
119
|
+
li a:hover {
|
|
120
|
+
background-color: var(--hover-color);
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
}
|
|
91
123
|
|
|
124
|
+
/* Responsive design */
|
|
125
|
+
@media screen and (max-width: 850px) {
|
|
92
126
|
.main {
|
|
93
|
-
|
|
94
|
-
float: none;
|
|
95
|
-
overflow-y: scroll;
|
|
96
|
-
display: block;
|
|
127
|
+
flex-direction: column;
|
|
97
128
|
}
|
|
98
129
|
|
|
99
|
-
.column_left {
|
|
100
|
-
width:
|
|
101
|
-
height: auto;
|
|
102
|
-
float: none;
|
|
103
|
-
overflow-y: visible;
|
|
104
|
-
display: block;
|
|
130
|
+
.column_left, .column_right {
|
|
131
|
+
width: 100%;
|
|
105
132
|
}
|
|
106
133
|
|
|
107
134
|
.column_right {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
float: none;
|
|
111
|
-
overflow-y: visible;
|
|
112
|
-
display: block;
|
|
113
|
-
border: none;
|
|
135
|
+
border-left: none;
|
|
136
|
+
border-top: 1px solid var(--border-color);
|
|
114
137
|
}
|
|
115
|
-
|
|
116
138
|
}
|
|
139
|
+
|
|
140
|
+
${additionalStyles}
|
|
117
141
|
</style>
|
|
118
142
|
<script src="https://cdn.jsdelivr.net/npm/showdown@2.0.3/dist/showdown.min.js"></script>
|
|
119
143
|
<script>
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.
|
|
173
|
-
let
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
})
|
|
177
|
-
|
|
144
|
+
const showdown = window.showdown;
|
|
145
|
+
|
|
146
|
+
const Convert = (md) => {
|
|
147
|
+
let converter = new showdown.Converter();
|
|
148
|
+
return converter.makeHtml(md);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
window.managerDocumentation = async (manager) => {
|
|
152
|
+
try {
|
|
153
|
+
let res = await fetch(\`/getDocumentationForTopicManager?manager=\${manager}\`);
|
|
154
|
+
let docs = await res.text();
|
|
155
|
+
let managerReadme = Convert(docs);
|
|
156
|
+
document.getElementById('documentation_container').innerHTML = managerReadme;
|
|
157
|
+
document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${manager} Topic Manager</h1>\`;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error('Error fetching manager documentation:', error);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
window.topicDocumentation = async (provider) => {
|
|
164
|
+
try {
|
|
165
|
+
let res = await fetch(\`/getDocumentationForLookupServiceProvider?lookupServices=\${provider}\`);
|
|
166
|
+
let docs = await res.text();
|
|
167
|
+
let providerReadme = Convert(docs);
|
|
168
|
+
document.getElementById('documentation_container').innerHTML = providerReadme;
|
|
169
|
+
document.getElementById('documentation_title').innerHTML = \`<h1 class="docs_heading">\${provider} Lookup Service</h1>\`;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('Error fetching provider documentation:', error);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
176
|
+
fetch('/listTopicManagers')
|
|
177
|
+
.then(res => res.json())
|
|
178
|
+
.then(managers => {
|
|
179
|
+
const managerList = document.getElementById('manager_list');
|
|
180
|
+
managers.forEach(manager => {
|
|
181
|
+
let li = document.createElement('li');
|
|
182
|
+
li.innerHTML = \`<a onclick="window.managerDocumentation('\${manager}')">\${manager}</a>\`;
|
|
183
|
+
managerList.appendChild(li);
|
|
184
|
+
});
|
|
185
|
+
})
|
|
186
|
+
.catch(() => {
|
|
187
|
+
let message = document.createElement('h4');
|
|
188
|
+
message.innerText = 'Something went wrong!';
|
|
189
|
+
manager_list.insertBefore(message, manager_list.children[0]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
fetch('/listLookupServiceProviders')
|
|
193
|
+
.then(res => res.json())
|
|
194
|
+
.then(providers => {
|
|
195
|
+
const providerList = document.getElementById('provider_list');
|
|
196
|
+
providers.forEach(provider => {
|
|
197
|
+
let li = document.createElement('li');
|
|
198
|
+
li.innerHTML = \`<a onclick="window.topicDocumentation('\${provider}')">\${provider}</a>\`;
|
|
199
|
+
providerList.appendChild(li);
|
|
200
|
+
});
|
|
201
|
+
})
|
|
202
|
+
.catch(() => {
|
|
203
|
+
let message = document.createElement('h4');
|
|
204
|
+
message.innerText = 'Something went wrong!';
|
|
205
|
+
provider_list.insertBefore(message, provider_list.children[0]);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
</script>
|
|
178
209
|
</head>
|
|
179
210
|
|
|
180
211
|
<body>
|
|
181
|
-
<div class=
|
|
212
|
+
<div class="main">
|
|
182
213
|
<div class="column_left">
|
|
183
214
|
<div class="page_head">
|
|
184
|
-
<h1>
|
|
185
|
-
<p>Learn more on <a href=
|
|
215
|
+
<h1>Welcome to Overlay Services</h1>
|
|
216
|
+
<p>Learn more on <a href="https://github.com/bitcoin-sv/overlay-services" target="_blank">GitHub</a></p>
|
|
186
217
|
</div>
|
|
187
218
|
<div class="topic_container">
|
|
188
219
|
<h2>Endpoint Documentation:</h2>
|
|
@@ -193,13 +224,12 @@ export default () => `<!DOCTYPE html>
|
|
|
193
224
|
<h3>Supported Lookup Service Providers:</h3>
|
|
194
225
|
<ul id="provider_list"></ul>
|
|
195
226
|
</div>
|
|
196
|
-
<br />
|
|
197
227
|
</div>
|
|
198
228
|
<div class="column_right">
|
|
199
229
|
<div id="documentation_title"></div>
|
|
200
|
-
<div id="documentation_container" style="margin-left: 1.5em">
|
|
201
|
-
</div>
|
|
230
|
+
<div id="documentation_container" style="margin-left: 1.5em"></div>
|
|
202
231
|
</div>
|
|
203
232
|
</div>
|
|
204
233
|
</body>
|
|
205
|
-
</html
|
|
234
|
+
</html>`;
|
|
235
|
+
};
|