@bsv/overlay-express 2.0.2 → 2.1.0

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.
Files changed (52) hide show
  1. package/dist/cjs/mod.js +7 -1
  2. package/dist/cjs/mod.js.map +1 -1
  3. package/dist/cjs/package.json +3 -1
  4. package/dist/cjs/src/BanAwareLookupWrapper.js +76 -0
  5. package/dist/cjs/src/BanAwareLookupWrapper.js.map +1 -0
  6. package/dist/cjs/src/BanService.js +118 -0
  7. package/dist/cjs/src/BanService.js.map +1 -0
  8. package/dist/cjs/src/JanitorService.js +206 -93
  9. package/dist/cjs/src/JanitorService.js.map +1 -1
  10. package/dist/cjs/src/OverlayExpress.js +522 -71
  11. package/dist/cjs/src/OverlayExpress.js.map +1 -1
  12. package/dist/cjs/src/makeUserInterface.js +889 -217
  13. package/dist/cjs/src/makeUserInterface.js.map +1 -1
  14. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  15. package/dist/esm/mod.js +4 -1
  16. package/dist/esm/mod.js.map +1 -1
  17. package/dist/esm/src/BanAwareLookupWrapper.js +78 -0
  18. package/dist/esm/src/BanAwareLookupWrapper.js.map +1 -0
  19. package/dist/esm/src/BanService.js +115 -0
  20. package/dist/esm/src/BanService.js.map +1 -0
  21. package/dist/esm/src/JanitorService.js +199 -92
  22. package/dist/esm/src/JanitorService.js.map +1 -1
  23. package/dist/esm/src/OverlayExpress.js +528 -72
  24. package/dist/esm/src/OverlayExpress.js.map +1 -1
  25. package/dist/esm/src/makeUserInterface.js +889 -217
  26. package/dist/esm/src/makeUserInterface.js.map +1 -1
  27. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  28. package/dist/types/mod.d.ts +4 -1
  29. package/dist/types/mod.d.ts.map +1 -1
  30. package/dist/types/src/BanAwareLookupWrapper.d.ts +31 -0
  31. package/dist/types/src/BanAwareLookupWrapper.d.ts.map +1 -0
  32. package/dist/types/src/BanService.d.ts +81 -0
  33. package/dist/types/src/BanService.d.ts.map +1 -0
  34. package/dist/types/src/JanitorService.d.ts +69 -13
  35. package/dist/types/src/JanitorService.d.ts.map +1 -1
  36. package/dist/types/src/OverlayExpress.d.ts +28 -4
  37. package/dist/types/src/OverlayExpress.d.ts.map +1 -1
  38. package/dist/types/src/makeUserInterface.d.ts +2 -0
  39. package/dist/types/src/makeUserInterface.d.ts.map +1 -1
  40. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  41. package/mod.ts +4 -1
  42. package/package.json +3 -1
  43. package/src/BanAwareLookupWrapper.ts +95 -0
  44. package/src/BanService.ts +154 -0
  45. package/src/JanitorService.ts +277 -101
  46. package/src/OverlayExpress.ts +575 -76
  47. package/src/__tests__/BanAwareLookupWrapper.test.ts +255 -0
  48. package/src/__tests__/BanService.test.ts +310 -0
  49. package/src/__tests__/JanitorService.test.ts +342 -5
  50. package/src/__tests__/OverlayExpress.test.ts +19 -6
  51. package/src/__tests__/makeUserInterface.test.ts +4 -3
  52. package/src/makeUserInterface.ts +892 -217
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  import generalGuide from './generalGuide.md.js';
3
3
  export default (config = {}) => {
4
- const { host = '', faviconUrl = 'https://bsvblockchain.org/favicon.ico', backgroundColor = '#191919', primaryTextColor = '#f0f0f0', primaryColor = '#3b6efb', secondaryColor = '#001242', fontFamily = 'Helvetica, Arial, sans-serif', headingFontFamily = 'Helvetica, Arial, sans-serif', additionalStyles = '', sectionBackgroundColor = '#323940', linkColor = '#579DFF', hoverColor = '#3A4147', borderColor = '#B6C2CF', secondaryBackgroundColor = '#f8f8f8', secondaryTextColor = '#0e0e0e', defaultContent = generalGuide } = config;
4
+ const { host = '', faviconUrl = 'https://bsvblockchain.org/favicon.ico', backgroundColor = '#191919', primaryTextColor = '#f0f0f0', primaryColor = '#3b6efb', secondaryColor = '#001242', fontFamily = 'Helvetica, Arial, sans-serif', headingFontFamily = 'Helvetica, Arial, sans-serif', additionalStyles = '', sectionBackgroundColor = '#323940', linkColor = '#579DFF', hoverColor = '#3A4147', borderColor = '#B6C2CF', secondaryBackgroundColor = '#f8f8f8', secondaryTextColor = '#0e0e0e', defaultContent = generalGuide, adminIdentityKey = '' } = config;
5
5
  return `<!DOCTYPE html>
6
6
  <html>
7
7
  <head>
@@ -23,8 +23,14 @@ export default (config = {}) => {
23
23
  --secondary-background-color: ${secondaryBackgroundColor};
24
24
  --secondary-text-color: ${secondaryTextColor};
25
25
  --primary-text-color: ${primaryTextColor};
26
+ --success-color: #22c55e;
27
+ --warning-color: #f59e0b;
28
+ --danger-color: #ef4444;
29
+ --info-color: #3b82f6;
26
30
  }
27
31
 
32
+ * { box-sizing: border-box; }
33
+
28
34
  body {
29
35
  font-family: var(--font-family);
30
36
  background-color: var(--background-color);
@@ -33,13 +39,8 @@ export default (config = {}) => {
33
39
  color: var(--primary-text-color);
34
40
  }
35
41
 
36
- h1, h2, h3 {
37
- font-family: var(--heading-font-family);
38
- }
39
-
40
- p {
41
- line-height: 1.5;
42
- }
42
+ h1, h2, h3 { font-family: var(--heading-font-family); }
43
+ p { line-height: 1.5; }
43
44
 
44
45
  .welcome {
45
46
  background-clip: text;
@@ -48,14 +49,8 @@ export default (config = {}) => {
48
49
  cursor: pointer;
49
50
  }
50
51
 
51
- a {
52
- color: var(--link-color);
53
- text-decoration: none;
54
- }
55
-
56
- a:hover {
57
- color: var(--secondary-color);
58
- }
52
+ a { color: var(--link-color); text-decoration: none; }
53
+ a:hover { color: var(--secondary-color); }
59
54
 
60
55
  .main {
61
56
  display: flex;
@@ -73,24 +68,16 @@ export default (config = {}) => {
73
68
  padding: 15px 15px 15px 35px;
74
69
  overflow-y: auto;
75
70
  width: 360px;
71
+ min-width: 360px;
76
72
  background-color: var(--secondary-background-color);
77
73
  color: var(--secondary-text-color);
78
74
  }
79
75
 
80
- .column_right {
81
- width: calc(100% - 360px);
82
- }
83
-
84
- #documentation_container {
85
- padding: 0 8em;
86
- margin: 0;
87
- }
76
+ .column_right { width: calc(100% - 360px); }
88
77
 
89
- /* List styles */
90
- .list-item {
91
- margin: 0;
92
- }
78
+ #documentation_container { padding: 0 8em; margin: 0; }
93
79
 
80
+ .list-item { margin: 0; }
94
81
  .list-item a {
95
82
  display: block;
96
83
  width: 100%;
@@ -103,51 +90,25 @@ export default (config = {}) => {
103
90
  font-weight: 500;
104
91
  cursor: pointer;
105
92
  }
106
-
107
93
  .list-item a:hover, .list-item a.active {
108
94
  background: var(--primary-color) linear-gradient(90deg, var(--primary-color), var(--secondary-color));
109
95
  color: white;
110
96
  cursor: pointer;
111
97
  border-radius: 8px 0 0 8px;
112
98
  }
113
-
114
- ul#manager_list, ul#provider_list, ul#external_list {
99
+ ul#manager_list, ul#provider_list, ul#external_list, ul#admin_list {
115
100
  list-style-type: none;
116
101
  padding-left: 0;
117
102
  margin-top: 0.5em;
118
103
  }
119
104
 
120
- /* Detail styles */
121
- .detail-header {
122
- display: flex;
123
- align-items: center;
124
- margin-bottom: 1em;
125
- }
126
-
127
- .detail-icon {
128
- width: 60px;
129
- height: 60px;
130
- margin-right: 1em;
131
- }
132
-
133
- .detail-text {
134
- display: flex;
135
- flex-direction: column;
136
- }
105
+ .detail-header { display: flex; align-items: center; margin-bottom: 1em; }
106
+ .detail-icon { width: 60px; height: 60px; margin-right: 1em; }
107
+ .detail-text { display: flex; flex-direction: column; }
108
+ .detail-title { margin: 0; }
109
+ .detail-description, .detail-version, .detail-info { margin: 0.2em 0; }
110
+ .detail-info a { color: var(--link-color); }
137
111
 
138
- .detail-title {
139
- margin: 0;
140
- }
141
-
142
- .detail-description, .detail-version, .detail-info {
143
- margin: 0.2em 0;
144
- }
145
-
146
- .detail-info a {
147
- color: var(--link-color);
148
- }
149
-
150
- /* Code highlighting styles */
151
112
  pre {
152
113
  position: relative;
153
114
  padding: 1em;
@@ -156,7 +117,6 @@ export default (config = {}) => {
156
117
  background-color: #282c34;
157
118
  margin: 1em 0;
158
119
  }
159
-
160
120
  pre[data-language]:before {
161
121
  content: attr(data-language);
162
122
  position: absolute;
@@ -169,13 +129,10 @@ export default (config = {}) => {
169
129
  border-radius: 0 0 0 4px;
170
130
  text-transform: uppercase;
171
131
  }
172
-
173
132
  code {
174
133
  font-family: Menlo, Monaco, 'Courier New', monospace;
175
134
  font-size: 0.9em;
176
135
  }
177
-
178
- /* Inline code */
179
136
  p code, li code {
180
137
  background-color: #3e4451;
181
138
  padding: 0.2em 0.4em;
@@ -183,26 +140,227 @@ export default (config = {}) => {
183
140
  white-space: nowrap;
184
141
  }
185
142
 
186
- /* Responsive design */
187
- @media screen and (max-width: 850px) {
188
- .main {
189
- flex-direction: column;
190
- }
143
+ /* ============ ADMIN DASHBOARD STYLES ============ */
144
+ #admin_section { display: none; }
145
+ #admin_section.visible { display: block; }
146
+ .admin-divider { border-top: 1px solid #ccc; margin-top: 1em; padding-top: 0.5em; }
191
147
 
192
- .column_left {
193
- max-height: 30vh;
194
- }
148
+ .admin-login {
149
+ padding: 2em 8em;
150
+ }
151
+ .admin-login h2 { margin-bottom: 0.5em; }
152
+ .admin-login p { color: #999; margin-bottom: 1.5em; }
153
+ .admin-login-form { display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; }
154
+ .admin-login-form input {
155
+ padding: 0.6em 1em;
156
+ border: 1px solid #555;
157
+ border-radius: 6px;
158
+ background: #2a2a2a;
159
+ color: var(--primary-text-color);
160
+ font-size: 0.9em;
161
+ width: 350px;
162
+ }
163
+ .admin-login-form input::placeholder { color: #777; }
195
164
 
196
- .column_left, .column_right {
197
- width: 90%;
198
- margin: 0;
199
- padding: 0 5%;
200
- }
165
+ .btn {
166
+ padding: 0.6em 1.2em;
167
+ border: none;
168
+ border-radius: 6px;
169
+ cursor: pointer;
170
+ font-size: 0.85em;
171
+ font-weight: 600;
172
+ transition: all 0.2s;
173
+ display: inline-flex;
174
+ align-items: center;
175
+ gap: 0.4em;
176
+ }
177
+ .btn:hover { filter: brightness(1.1); }
178
+ .btn-primary { background: var(--primary-color); color: white; }
179
+ .btn-danger { background: var(--danger-color); color: white; }
180
+ .btn-warning { background: var(--warning-color); color: #111; }
181
+ .btn-success { background: var(--success-color); color: white; }
182
+ .btn-sm { padding: 0.3em 0.7em; font-size: 0.8em; }
183
+ .btn-outline {
184
+ background: transparent;
185
+ border: 1px solid var(--primary-color);
186
+ color: var(--primary-color);
187
+ }
201
188
 
202
- #documentation_container {
203
- margin: 0;
204
- padding: 0;
205
- }
189
+ .admin-panel { padding: 0 8em 2em; }
190
+ .admin-panel h2 { margin-bottom: 0.3em; }
191
+ .admin-panel .subtitle { color: #999; margin-top: 0; margin-bottom: 1.5em; }
192
+
193
+ .stats-grid {
194
+ display: grid;
195
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
196
+ gap: 1em;
197
+ margin-bottom: 2em;
198
+ }
199
+ .stat-card {
200
+ background: var(--section-background-color);
201
+ border-radius: 10px;
202
+ padding: 1.2em;
203
+ }
204
+ .stat-card .stat-label { font-size: 0.8em; color: #999; text-transform: uppercase; letter-spacing: 0.05em; }
205
+ .stat-card .stat-value { font-size: 1.8em; font-weight: 700; margin: 0.1em 0; }
206
+ .stat-card .stat-value.success { color: var(--success-color); }
207
+ .stat-card .stat-value.warning { color: var(--warning-color); }
208
+ .stat-card .stat-value.danger { color: var(--danger-color); }
209
+ .stat-card .stat-value.info { color: var(--info-color); }
210
+
211
+ .action-bar {
212
+ display: flex;
213
+ gap: 0.5em;
214
+ flex-wrap: wrap;
215
+ margin-bottom: 1.5em;
216
+ }
217
+
218
+ .search-bar {
219
+ display: flex;
220
+ gap: 0.5em;
221
+ margin-bottom: 1em;
222
+ }
223
+ .search-bar input {
224
+ flex: 1;
225
+ padding: 0.6em 1em;
226
+ border: 1px solid #555;
227
+ border-radius: 6px;
228
+ background: #2a2a2a;
229
+ color: var(--primary-text-color);
230
+ font-size: 0.9em;
231
+ }
232
+ .search-bar input::placeholder { color: #777; }
233
+
234
+ .data-table {
235
+ width: 100%;
236
+ border-collapse: collapse;
237
+ font-size: 0.85em;
238
+ }
239
+ .data-table th {
240
+ text-align: left;
241
+ padding: 0.7em 0.8em;
242
+ background: var(--section-background-color);
243
+ border-bottom: 2px solid #555;
244
+ font-weight: 600;
245
+ white-space: nowrap;
246
+ }
247
+ .data-table td {
248
+ padding: 0.6em 0.8em;
249
+ border-bottom: 1px solid #333;
250
+ vertical-align: middle;
251
+ }
252
+ .data-table tr:hover td { background: rgba(255,255,255,0.03); }
253
+ .data-table .mono {
254
+ font-family: Menlo, Monaco, 'Courier New', monospace;
255
+ font-size: 0.85em;
256
+ }
257
+ .data-table .truncate {
258
+ max-width: 200px;
259
+ overflow: hidden;
260
+ text-overflow: ellipsis;
261
+ white-space: nowrap;
262
+ }
263
+
264
+ .health-dot {
265
+ width: 10px;
266
+ height: 10px;
267
+ border-radius: 50%;
268
+ display: inline-block;
269
+ margin-right: 0.4em;
270
+ }
271
+ .health-dot.green { background: var(--success-color); }
272
+ .health-dot.yellow { background: var(--warning-color); }
273
+ .health-dot.red { background: var(--danger-color); }
274
+ .health-dot.gray { background: #666; }
275
+
276
+ .pagination {
277
+ display: flex;
278
+ align-items: center;
279
+ gap: 0.5em;
280
+ margin-top: 1em;
281
+ justify-content: center;
282
+ }
283
+ .pagination .page-info { color: #999; font-size: 0.85em; }
284
+
285
+ .toast-container {
286
+ position: fixed;
287
+ top: 1em;
288
+ right: 1em;
289
+ z-index: 9999;
290
+ display: flex;
291
+ flex-direction: column;
292
+ gap: 0.5em;
293
+ }
294
+ .toast {
295
+ padding: 0.8em 1.2em;
296
+ border-radius: 8px;
297
+ font-size: 0.85em;
298
+ font-weight: 500;
299
+ animation: slideIn 0.3s ease;
300
+ max-width: 400px;
301
+ }
302
+ .toast.success { background: var(--success-color); color: white; }
303
+ .toast.error { background: var(--danger-color); color: white; }
304
+ .toast.info { background: var(--info-color); color: white; }
305
+ @keyframes slideIn { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }
306
+
307
+ .loading { color: #999; font-style: italic; padding: 2em; text-align: center; }
308
+ .empty-state { color: #777; text-align: center; padding: 3em 1em; }
309
+ .empty-state p { font-size: 1.1em; }
310
+
311
+ .admin-form-row {
312
+ display: flex; gap: 0.5em; align-items: center; margin-bottom: 1em; flex-wrap: wrap;
313
+ }
314
+ .admin-form-row select, .admin-form-row input {
315
+ padding: 0.6em 1em;
316
+ border: 1px solid #555;
317
+ border-radius: 6px;
318
+ background: #2a2a2a;
319
+ color: var(--primary-text-color);
320
+ font-size: 0.9em;
321
+ }
322
+
323
+ .health-result-card {
324
+ background: var(--section-background-color);
325
+ border-radius: 10px;
326
+ padding: 1.5em;
327
+ margin-top: 1em;
328
+ }
329
+ .health-result-card h3 { margin-top: 0; }
330
+ .health-result-row {
331
+ display: flex; justify-content: space-between; padding: 0.4em 0;
332
+ border-bottom: 1px solid #444;
333
+ }
334
+ .health-result-row:last-child { border-bottom: none; }
335
+
336
+ .confirm-overlay {
337
+ position: fixed; top: 0; left: 0; right: 0; bottom: 0;
338
+ background: rgba(0,0,0,0.6); z-index: 9998;
339
+ display: flex; align-items: center; justify-content: center;
340
+ }
341
+ .confirm-dialog {
342
+ background: #2a2a2a; border-radius: 12px; padding: 2em;
343
+ max-width: 420px; width: 90%;
344
+ }
345
+ .confirm-dialog h3 { margin-top: 0; }
346
+ .confirm-dialog .actions { display: flex; gap: 0.5em; justify-content: flex-end; margin-top: 1.5em; }
347
+
348
+ .badge {
349
+ display: inline-block;
350
+ padding: 0.15em 0.5em;
351
+ border-radius: 4px;
352
+ font-size: 0.75em;
353
+ font-weight: 600;
354
+ }
355
+ .badge-domain { background: #1e40af; color: white; }
356
+ .badge-outpoint { background: #7c3aed; color: white; }
357
+
358
+ @media screen and (max-width: 850px) {
359
+ .main { flex-direction: column; }
360
+ .column_left { max-height: 30vh; min-width: unset; }
361
+ .column_left, .column_right { width: 90%; margin: 0; padding: 0 5%; }
362
+ #documentation_container, .admin-panel, .admin-login { margin: 0; padding: 0; }
363
+ .stats-grid { grid-template-columns: repeat(2, 1fr); }
206
364
  }
207
365
 
208
366
  ${additionalStyles}
@@ -212,11 +370,15 @@ export default (config = {}) => {
212
370
  <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js"></script>
213
371
  <script>
214
372
  const faviconUrl = '${faviconUrl}';
373
+ const HOST = '${host}';
374
+ const CONFIGURED_ADMIN_IDENTITY_KEY = '${adminIdentityKey}';
215
375
 
376
+ /* ==========================================
377
+ MARKDOWN CONVERTER
378
+ ========================================== */
216
379
  const showdown = window.showdown;
217
380
  window.hljs.configure({ languages: ['typescript', 'javascript', 'json', 'html', 'css', 'bash', 'markdown'] });
218
381
 
219
-
220
382
  const Convert = (md) => {
221
383
  let converter = new showdown.Converter({
222
384
  ghCompatibleHeaderId: true,
@@ -228,23 +390,17 @@ export default (config = {}) => {
228
390
  parseImgDimensions: true,
229
391
  simplifiedAutoLink: true
230
392
  });
231
- // Set to use GitHub flavor markdown
232
393
  converter.setFlavor('github');
233
-
234
- // Set language detection for code blocks
235
394
  converter.setOption('ghCodeBlocks', true);
236
395
  converter.setOption('omitExtraWLInCodeBlocks', true);
237
396
  converter.setOption('literalMidWordUnderscores', true);
238
397
  converter.setOption('parseImgDimensions', true);
239
-
240
- // Add custom extension for adding language-specific class to code blocks
241
398
  const codeExtension = () => [
242
399
  {
243
400
  type: 'output',
244
401
  filter: function(text) {
245
- return text.replace(/<pre><code\s*class="([^"]*)">(.*?)<\\/code><\\/pre>/gs, function(match, language, content) {
402
+ return text.replace(/<pre><code\\s*class="([^"]*)">(.*?)<\\/code><\\/pre>/gs, function(match, language, content) {
246
403
  if (language) {
247
- // Clean up the language identifier
248
404
  const lang = language.replace('language-', '').trim();
249
405
  return \`<pre data-language="\${lang}"><code class="language-\${lang} hljs">\${content}</code></pre>\`;
250
406
  } else {
@@ -254,148 +410,666 @@ export default (config = {}) => {
254
410
  }
255
411
  }
256
412
  ];
257
-
258
- // Add the extension
259
413
  converter.addExtension(codeExtension());
260
- const html = converter.makeHtml(md);
261
-
262
- return html;
414
+ return converter.makeHtml(md);
263
415
  };
264
416
 
265
- window.returnHome = () => {
266
- if (!window.defaultHtml) {
267
- let newStuff = Convert(${defaultContent});
268
- window.defaultHtml = newStuff;
269
- }
270
- document.getElementById('documentation_container').innerHTML = window.defaultHtml;
271
- window.location.hash = '';
272
- document.querySelectorAll('.list-item a').forEach(item => {
273
- item.classList.remove('active');
274
- });
275
- };
276
-
277
- // Function to apply syntax highlighting after content is inserted
278
417
  const applyHighlighting = () => {
279
418
  document.querySelectorAll('pre code').forEach(block => {
280
- const blockElement = block;
281
-
282
- // Check for language class
283
- const classList = Array.from(blockElement.classList);
419
+ const classList = Array.from(block.classList);
284
420
  const langClass = classList.find(cls => cls.startsWith('language-'));
285
-
286
421
  if (langClass) {
287
422
  const language = langClass.replace('language-', '');
288
- // Set language label on the parent pre element
289
- const preElement = blockElement.parentElement;
290
- if (preElement) {
291
- preElement.setAttribute('data-language', language);
292
- }
293
- }
294
-
295
- // Apply highlighting to all code blocks
296
- try {
297
- // @ts-ignore - hljs is loaded from CDN
298
- window.hljs.highlightElement(blockElement);
299
- } catch (e) {
300
- console.error('Error highlighting code:', e);
423
+ const preElement = block.parentElement;
424
+ if (preElement) { preElement.setAttribute('data-language', language); }
301
425
  }
426
+ try { window.hljs.highlightElement(block); } catch (e) {}
302
427
  });
303
428
  };
304
429
 
430
+ /* ==========================================
431
+ DOCUMENTATION NAVIGATION
432
+ ========================================== */
305
433
  let managersData = {};
306
434
  let providersData = {};
307
435
 
308
- // Function to update URL hash and highlight selected item
436
+ window.returnHome = () => {
437
+ if (!window.defaultHtml) {
438
+ window.defaultHtml = Convert(${defaultContent});
439
+ }
440
+ document.getElementById('documentation_container').innerHTML = window.defaultHtml;
441
+ document.getElementById('documentation_container').style.display = '';
442
+ document.getElementById('admin_content').style.display = 'none';
443
+ window.location.hash = '';
444
+ document.querySelectorAll('.list-item a').forEach(item => item.classList.remove('active'));
445
+ };
446
+
309
447
  const updateSelectedItem = (type, id) => {
310
- // Update URL hash
311
448
  window.location.hash = \`\${type}/\${id}\`;
312
-
313
- // Remove active class from all list items
314
- document.querySelectorAll('.list-item a').forEach(item => {
315
- item.classList.remove('active');
316
- });
317
-
318
- // Add active class to selected item
449
+ document.querySelectorAll('.list-item a').forEach(item => item.classList.remove('active'));
319
450
  const selector = \`[data-\${type}="\${id}"]\`;
320
451
  const selectedItem = document.querySelector(selector);
321
- if (selectedItem) {
322
- selectedItem.classList.add('active');
323
- }
452
+ if (selectedItem) selectedItem.classList.add('active');
324
453
  };
325
454
 
326
- // @ts-ignore - Adding custom property to window
327
455
  window.managerDocumentation = async (manager) => {
328
456
  try {
329
- let res = await fetch(\`${host}/getDocumentationForTopicManager?manager=\${manager}\`);
457
+ document.getElementById('documentation_container').style.display = '';
458
+ document.getElementById('admin_content').style.display = 'none';
459
+ let res = await fetch(\`\${HOST}/getDocumentationForTopicManager?manager=\${manager}\`);
330
460
  let docs = await res.text();
331
- let managerReadme = Convert(docs);
332
-
333
- let managerData = managersData[manager];
334
- let iconURL = managerData.iconURL || faviconUrl;
335
-
336
- document.getElementById('documentation_container').innerHTML = managerReadme;
461
+ document.getElementById('documentation_container').innerHTML = Convert(docs);
337
462
  applyHighlighting();
338
-
339
- // Update active item and URL
340
463
  updateSelectedItem('manager', manager);
341
- } catch (error) {
342
- console.error('Error fetching manager documentation:', error);
343
- }
464
+ } catch (error) { console.error('Error fetching manager documentation:', error); }
344
465
  };
345
466
 
346
- // @ts-ignore - Adding custom property to window
347
467
  window.topicDocumentation = async (provider) => {
348
468
  try {
349
- let res = await fetch(\`${host}/getDocumentationForLookupServiceProvider?lookupService=\${provider}\`);
469
+ document.getElementById('documentation_container').style.display = '';
470
+ document.getElementById('admin_content').style.display = 'none';
471
+ let res = await fetch(\`\${HOST}/getDocumentationForLookupServiceProvider?lookupService=\${provider}\`);
350
472
  let docs = await res.text();
351
- let providerReadme = Convert(docs);
352
-
353
- let providerData = providersData[provider];
354
- let iconURL = providerData.iconURL || faviconUrl;
355
-
356
- document.getElementById('documentation_container').innerHTML = providerReadme;
473
+ document.getElementById('documentation_container').innerHTML = Convert(docs);
357
474
  applyHighlighting();
358
-
359
- // Update active item and URL
360
475
  updateSelectedItem('provider', provider);
361
- } catch (error) {
362
- console.error('Error fetching provider documentation:', error);
476
+ } catch (error) { console.error('Error fetching provider documentation:', error); }
477
+ };
478
+
479
+ /* ==========================================
480
+ TOAST NOTIFICATIONS
481
+ ========================================== */
482
+ function showToast(message, type = 'info') {
483
+ const container = document.getElementById('toast_container');
484
+ const toast = document.createElement('div');
485
+ toast.className = \`toast \${type}\`;
486
+ toast.textContent = message;
487
+ container.appendChild(toast);
488
+ setTimeout(() => { toast.style.opacity = '0'; setTimeout(() => toast.remove(), 300); }, 4000);
489
+ }
490
+
491
+ /* ==========================================
492
+ ADMIN DASHBOARD
493
+ ========================================== */
494
+ const Admin = {
495
+ token: null,
496
+ isAdmin: false,
497
+
498
+ walletAuthMode: false,
499
+ authFetch: null,
500
+
501
+ init() {
502
+ this.token = sessionStorage.getItem('adminToken');
503
+ if (this.token) {
504
+ this.isAdmin = true;
505
+ this.showAdminSection();
506
+ }
507
+ this.tryWalletDetection();
508
+ },
509
+
510
+ async tryWalletDetection() {
511
+ try {
512
+ // Dynamically import WalletClient from the BSV SDK
513
+ // This works when the user has a wallet extension installed
514
+ const { WalletClient } = await import('https://cdn.jsdelivr.net/npm/@bsv/sdk@2/+esm');
515
+ const wallet = new WalletClient('auto', window.location.origin);
516
+ const { publicKey } = await wallet.getPublicKey({ identityKey: true });
517
+
518
+ // Fetch the server's admin config to compare identity keys
519
+ const configRes = await fetch(HOST + '/admin/config');
520
+ const config = await configRes.json();
521
+
522
+ if (config.adminIdentityKey && publicKey === config.adminIdentityKey) {
523
+ // Identity matches the admin key - create AuthFetch for authenticated requests
524
+ const { AuthFetch } = await import('https://cdn.jsdelivr.net/npm/@bsv/sdk@2/+esm');
525
+ this.authFetch = new AuthFetch(wallet);
526
+ this.walletAuthMode = true;
527
+ this.isAdmin = true;
528
+ this.showAdminSection();
529
+ showToast('Wallet detected - admin access granted', 'success');
530
+ }
531
+ } catch (e) {
532
+ // Wallet not available or identity doesn't match - fall back to token auth
533
+ }
534
+ },
535
+
536
+ showAdminSection() {
537
+ document.getElementById('admin_section').classList.add('visible');
538
+ },
539
+
540
+ async login(token) {
541
+ // Verify token by making a test request
542
+ try {
543
+ const res = await fetch(\`\${HOST}/admin/stats\`, {
544
+ headers: { 'Authorization': \`Bearer \${token}\` }
545
+ });
546
+ if (res.ok) {
547
+ this.token = token;
548
+ this.isAdmin = true;
549
+ sessionStorage.setItem('adminToken', token);
550
+ this.showAdminSection();
551
+ showToast('Admin login successful', 'success');
552
+ return true;
553
+ } else {
554
+ showToast('Invalid admin token', 'error');
555
+ return false;
556
+ }
557
+ } catch (e) {
558
+ showToast('Connection error', 'error');
559
+ return false;
560
+ }
561
+ },
562
+
563
+ logout() {
564
+ this.token = null;
565
+ this.isAdmin = false;
566
+ this.walletAuthMode = false;
567
+ this.authFetch = null;
568
+ sessionStorage.removeItem('adminToken');
569
+ document.getElementById('admin_section').classList.remove('visible');
570
+ window.returnHome();
571
+ showToast('Logged out', 'info');
572
+ },
573
+
574
+ async api(method, path, body) {
575
+ if (!this.token && !this.walletAuthMode) { showToast('Not authenticated', 'error'); return null; }
576
+ try {
577
+ const url = \`\${HOST || window.location.origin}\${path}\`;
578
+
579
+ // Use AuthFetch (BSV mutual auth) when wallet auth is active
580
+ if (this.walletAuthMode && this.authFetch) {
581
+ const opts = { method, headers: { 'Content-Type': 'application/json' } };
582
+ if (body) opts.body = JSON.stringify(body);
583
+ const res = await this.authFetch.fetch(url, opts);
584
+ const data = await res.json();
585
+ if (data.status === 'error') { showToast(data.message, 'error'); }
586
+ return data;
587
+ }
588
+
589
+ // Fall back to Bearer token auth
590
+ const opts = {
591
+ method,
592
+ headers: {
593
+ 'Authorization': \`Bearer \${this.token}\`,
594
+ 'Content-Type': 'application/json'
595
+ }
596
+ };
597
+ if (body) opts.body = JSON.stringify(body);
598
+ const res = await fetch(url, opts);
599
+ const data = await res.json();
600
+ if (data.status === 'error') { showToast(data.message, 'error'); }
601
+ return data;
602
+ } catch (e) { showToast('Request failed: ' + e.message, 'error'); return null; }
603
+ },
604
+
605
+ /* ---------- Dashboard Overview ---------- */
606
+ async showOverview() {
607
+ switchToAdmin('admin-overview');
608
+ const container = document.getElementById('admin_content');
609
+ container.innerHTML = '<div class="loading">Loading dashboard...</div>';
610
+ const result = await this.api('GET', '/admin/stats');
611
+ if (!result || result.status !== 'success') return;
612
+ const d = result.data;
613
+ const uptime = d.uptime ? formatDuration(d.uptime) : 'N/A';
614
+ container.innerHTML = \`
615
+ <div class="admin-panel">
616
+ <h2>Dashboard Overview</h2>
617
+ <p class="subtitle">\${d.nodeName} on \${d.network}net &mdash; uptime: \${uptime}</p>
618
+ <div class="stats-grid">
619
+ <div class="stat-card"><div class="stat-label">SHIP Records</div><div class="stat-value info">\${d.shipRecordCount}</div></div>
620
+ <div class="stat-card"><div class="stat-label">SLAP Records</div><div class="stat-value info">\${d.slapRecordCount}</div></div>
621
+ <div class="stat-card"><div class="stat-label">Banned Domains</div><div class="stat-value \${d.bannedDomains > 0 ? 'warning' : 'success'}">\${d.bannedDomains}</div></div>
622
+ <div class="stat-card"><div class="stat-label">Banned Outpoints</div><div class="stat-value \${d.bannedOutpoints > 0 ? 'warning' : 'success'}">\${d.bannedOutpoints}</div></div>
623
+ <div class="stat-card"><div class="stat-label">Topic Managers</div><div class="stat-value">\${d.topicManagers.length}</div></div>
624
+ <div class="stat-card"><div class="stat-label">Lookup Services</div><div class="stat-value">\${d.lookupServices.length}</div></div>
625
+ </div>
626
+ <h3>Quick Actions</h3>
627
+ <div class="action-bar">
628
+ <button class="btn btn-primary" onclick="Admin.runJanitor()">Run Janitor</button>
629
+ <button class="btn btn-primary" onclick="Admin.syncAds()">Sync Advertisements</button>
630
+ \${d.gaspSyncEnabled ? '<button class="btn btn-primary" onclick="Admin.gaspSync()">GASP Sync</button>' : ''}
631
+ </div>
632
+ <h3>Hosted Topics</h3>
633
+ <p style="color:#999">\${d.topicManagers.join(', ')}</p>
634
+ <h3>Hosted Lookup Services</h3>
635
+ <p style="color:#999">\${d.lookupServices.join(', ')}</p>
636
+ </div>
637
+ \`;
638
+ },
639
+
640
+ /* ---------- SHIP Records ---------- */
641
+ shipPage: 1,
642
+ shipSearch: '',
643
+ async showShipRecords(page, search) {
644
+ switchToAdmin('admin-ship');
645
+ this.shipPage = page || 1;
646
+ this.shipSearch = typeof search === 'string' ? search : this.shipSearch;
647
+ const container = document.getElementById('admin_content');
648
+ container.innerHTML = '<div class="loading">Loading SHIP records...</div>';
649
+ const qs = \`?page=\${this.shipPage}&limit=30\${this.shipSearch ? '&search=' + encodeURIComponent(this.shipSearch) : ''}\`;
650
+ const result = await this.api('GET', '/admin/ship-records' + qs);
651
+ if (!result || result.status !== 'success') return;
652
+ const { records, total, page: pg, pages } = result.data;
653
+ container.innerHTML = \`
654
+ <div class="admin-panel">
655
+ <h2>SHIP Records</h2>
656
+ <p class="subtitle">Hosts advertising topic managers (\${total} total)</p>
657
+ <div class="search-bar">
658
+ <input type="text" id="ship_search" placeholder="Search by domain, topic, txid, or identity key..." value="\${escHtml(this.shipSearch)}" onkeydown="if(event.key==='Enter')Admin.showShipRecords(1,this.value)" />
659
+ <button class="btn btn-primary" onclick="Admin.showShipRecords(1,document.getElementById('ship_search').value)">Search</button>
660
+ </div>
661
+ \${records.length === 0 ? '<div class="empty-state"><p>No SHIP records found.</p></div>' : \`
662
+ <div style="overflow-x:auto">
663
+ <table class="data-table">
664
+ <thead>
665
+ <tr>
666
+ <th>Health</th>
667
+ <th>Domain</th>
668
+ <th>Topic</th>
669
+ <th>Identity Key</th>
670
+ <th>Outpoint</th>
671
+ <th>Created</th>
672
+ <th>Actions</th>
673
+ </tr>
674
+ </thead>
675
+ <tbody>
676
+ \${records.map(r => \`
677
+ <tr>
678
+ <td><span class="health-dot \${healthDotClass(r.down)}"></span>\${r.down ? 'Down: '+r.down : 'OK'}</td>
679
+ <td class="mono truncate" title="\${escHtml(r.domain)}">\${escHtml(r.domain)}</td>
680
+ <td>\${escHtml(r.topic)}</td>
681
+ <td class="mono truncate" title="\${escHtml(r.identityKey)}">\${escHtml((r.identityKey||'').substring(0,12))}...</td>
682
+ <td class="mono truncate" title="\${r.txid}.\${r.outputIndex}">\${r.txid.substring(0,8)}...\${r.outputIndex}</td>
683
+ <td>\${r.createdAt ? new Date(r.createdAt).toLocaleDateString() : 'N/A'}</td>
684
+ <td>
685
+ <button class="btn btn-sm btn-primary" onclick="Admin.healthCheck('\${escHtml(r.domain)}')">Ping</button>
686
+ <button class="btn btn-sm btn-danger" onclick="Admin.confirmRemoveToken('\${r.txid}', \${r.outputIndex}, '\${escHtml(r.domain)}')">Remove</button>
687
+ <button class="btn btn-sm btn-warning" onclick="Admin.confirmBanDomain('\${escHtml(r.domain)}')">Ban Host</button>
688
+ </td>
689
+ </tr>
690
+ \`).join('')}
691
+ </tbody>
692
+ </table>
693
+ </div>
694
+ <div class="pagination">
695
+ <button class="btn btn-sm btn-outline" \${pg <= 1 ? 'disabled' : ''} onclick="Admin.showShipRecords(\${pg - 1})">Prev</button>
696
+ <span class="page-info">Page \${pg} of \${pages}</span>
697
+ <button class="btn btn-sm btn-outline" \${pg >= pages ? 'disabled' : ''} onclick="Admin.showShipRecords(\${pg + 1})">Next</button>
698
+ </div>
699
+ \`}
700
+ </div>
701
+ \`;
702
+ },
703
+
704
+ /* ---------- SLAP Records ---------- */
705
+ slapPage: 1,
706
+ slapSearch: '',
707
+ async showSlapRecords(page, search) {
708
+ switchToAdmin('admin-slap');
709
+ this.slapPage = page || 1;
710
+ this.slapSearch = typeof search === 'string' ? search : this.slapSearch;
711
+ const container = document.getElementById('admin_content');
712
+ container.innerHTML = '<div class="loading">Loading SLAP records...</div>';
713
+ const qs = \`?page=\${this.slapPage}&limit=30\${this.slapSearch ? '&search=' + encodeURIComponent(this.slapSearch) : ''}\`;
714
+ const result = await this.api('GET', '/admin/slap-records' + qs);
715
+ if (!result || result.status !== 'success') return;
716
+ const { records, total, page: pg, pages } = result.data;
717
+ container.innerHTML = \`
718
+ <div class="admin-panel">
719
+ <h2>SLAP Records</h2>
720
+ <p class="subtitle">Hosts advertising lookup services (\${total} total)</p>
721
+ <div class="search-bar">
722
+ <input type="text" id="slap_search" placeholder="Search by domain, service, txid, or identity key..." value="\${escHtml(this.slapSearch)}" onkeydown="if(event.key==='Enter')Admin.showSlapRecords(1,this.value)" />
723
+ <button class="btn btn-primary" onclick="Admin.showSlapRecords(1,document.getElementById('slap_search').value)">Search</button>
724
+ </div>
725
+ \${records.length === 0 ? '<div class="empty-state"><p>No SLAP records found.</p></div>' : \`
726
+ <div style="overflow-x:auto">
727
+ <table class="data-table">
728
+ <thead>
729
+ <tr>
730
+ <th>Health</th>
731
+ <th>Domain</th>
732
+ <th>Service</th>
733
+ <th>Identity Key</th>
734
+ <th>Outpoint</th>
735
+ <th>Created</th>
736
+ <th>Actions</th>
737
+ </tr>
738
+ </thead>
739
+ <tbody>
740
+ \${records.map(r => \`
741
+ <tr>
742
+ <td><span class="health-dot \${healthDotClass(r.down)}"></span>\${r.down ? 'Down: '+r.down : 'OK'}</td>
743
+ <td class="mono truncate" title="\${escHtml(r.domain)}">\${escHtml(r.domain)}</td>
744
+ <td>\${escHtml(r.service)}</td>
745
+ <td class="mono truncate" title="\${escHtml(r.identityKey)}">\${escHtml((r.identityKey||'').substring(0,12))}...</td>
746
+ <td class="mono truncate" title="\${r.txid}.\${r.outputIndex}">\${r.txid.substring(0,8)}...\${r.outputIndex}</td>
747
+ <td>\${r.createdAt ? new Date(r.createdAt).toLocaleDateString() : 'N/A'}</td>
748
+ <td>
749
+ <button class="btn btn-sm btn-primary" onclick="Admin.healthCheck('\${escHtml(r.domain)}')">Ping</button>
750
+ <button class="btn btn-sm btn-danger" onclick="Admin.confirmRemoveToken('\${r.txid}', \${r.outputIndex}, '\${escHtml(r.domain)}')">Remove</button>
751
+ <button class="btn btn-sm btn-warning" onclick="Admin.confirmBanDomain('\${escHtml(r.domain)}')">Ban Host</button>
752
+ </td>
753
+ </tr>
754
+ \`).join('')}
755
+ </tbody>
756
+ </table>
757
+ </div>
758
+ <div class="pagination">
759
+ <button class="btn btn-sm btn-outline" \${pg <= 1 ? 'disabled' : ''} onclick="Admin.showSlapRecords(\${pg - 1})">Prev</button>
760
+ <span class="page-info">Page \${pg} of \${pages}</span>
761
+ <button class="btn btn-sm btn-outline" \${pg >= pages ? 'disabled' : ''} onclick="Admin.showSlapRecords(\${pg + 1})">Next</button>
762
+ </div>
763
+ \`}
764
+ </div>
765
+ \`;
766
+ },
767
+
768
+ /* ---------- Ban List ---------- */
769
+ async showBanList() {
770
+ switchToAdmin('admin-bans');
771
+ const container = document.getElementById('admin_content');
772
+ container.innerHTML = '<div class="loading">Loading ban list...</div>';
773
+ const result = await this.api('GET', '/admin/bans');
774
+ if (!result || result.status !== 'success') return;
775
+ const bans = result.data.bans || [];
776
+ const domainBans = bans.filter(b => b.type === 'domain');
777
+ const outpointBans = bans.filter(b => b.type === 'outpoint');
778
+ container.innerHTML = \`
779
+ <div class="admin-panel">
780
+ <h2>Ban List</h2>
781
+ <p class="subtitle">Banned domains and outpoints are blocked from being re-synced via GASP (\${bans.length} total)</p>
782
+ <h3>Add Ban</h3>
783
+ <div class="admin-form-row">
784
+ <select id="ban_type"><option value="domain">Domain</option><option value="outpoint">Outpoint</option></select>
785
+ <input type="text" id="ban_value" placeholder="e.g. https://dead-host.example.com or txid.outputIndex" style="flex:1" />
786
+ <input type="text" id="ban_reason" placeholder="Reason (optional)" style="width:200px" />
787
+ <button class="btn btn-danger" onclick="Admin.addBan()">Ban</button>
788
+ </div>
789
+ <h3>Banned Domains (\${domainBans.length})</h3>
790
+ \${domainBans.length === 0 ? '<p style="color:#777">No banned domains.</p>' : \`
791
+ <table class="data-table">
792
+ <thead><tr><th>Domain</th><th>Reason</th><th>Banned At</th><th>Actions</th></tr></thead>
793
+ <tbody>
794
+ \${domainBans.map(b => \`
795
+ <tr>
796
+ <td class="mono">\${escHtml(b.value)}</td>
797
+ <td>\${escHtml(b.reason || 'N/A')}</td>
798
+ <td>\${new Date(b.bannedAt).toLocaleString()}</td>
799
+ <td><button class="btn btn-sm btn-success" onclick="Admin.unban('domain','\${escHtml(b.value)}')">Unban</button></td>
800
+ </tr>
801
+ \`).join('')}
802
+ </tbody>
803
+ </table>\`}
804
+ <h3 style="margin-top:2em">Banned Outpoints (\${outpointBans.length})</h3>
805
+ \${outpointBans.length === 0 ? '<p style="color:#777">No banned outpoints.</p>' : \`
806
+ <table class="data-table">
807
+ <thead><tr><th>Outpoint</th><th>Domain</th><th>Reason</th><th>Banned At</th><th>Actions</th></tr></thead>
808
+ <tbody>
809
+ \${outpointBans.map(b => \`
810
+ <tr>
811
+ <td class="mono truncate" title="\${escHtml(b.value)}">\${escHtml(b.value.substring(0,20))}...</td>
812
+ <td class="mono">\${escHtml(b.domain || 'N/A')}</td>
813
+ <td>\${escHtml(b.reason || 'N/A')}</td>
814
+ <td>\${new Date(b.bannedAt).toLocaleString()}</td>
815
+ <td><button class="btn btn-sm btn-success" onclick="Admin.unban('outpoint','\${escHtml(b.value)}')">Unban</button></td>
816
+ </tr>
817
+ \`).join('')}
818
+ </tbody>
819
+ </table>\`}
820
+ </div>
821
+ \`;
822
+ },
823
+
824
+ /* ---------- Health Checker ---------- */
825
+ async showHealthChecker() {
826
+ switchToAdmin('admin-health');
827
+ const container = document.getElementById('admin_content');
828
+ container.innerHTML = \`
829
+ <div class="admin-panel">
830
+ <h2>Health Checker</h2>
831
+ <p class="subtitle">Ping a host's /health endpoint to verify it is online</p>
832
+ <div class="admin-form-row">
833
+ <input type="text" id="health_url" placeholder="https://overlay-host.example.com" style="flex:1" onkeydown="if(event.key==='Enter')Admin.healthCheck(this.value)" />
834
+ <button class="btn btn-primary" onclick="Admin.healthCheck(document.getElementById('health_url').value)">Check Health</button>
835
+ </div>
836
+ <div id="health_results"></div>
837
+ </div>
838
+ \`;
839
+ },
840
+
841
+ async healthCheck(url) {
842
+ if (!url) return;
843
+ showToast('Checking health of ' + url + '...', 'info');
844
+ const result = await this.api('POST', '/admin/health-check', { url });
845
+ if (!result || result.status !== 'success') return;
846
+ const d = result.data;
847
+ const resultsEl = document.getElementById('health_results');
848
+ if (resultsEl) {
849
+ resultsEl.innerHTML = \`
850
+ <div class="health-result-card">
851
+ <h3><span class="health-dot \${d.healthy ? 'green' : 'red'}"></span>\${d.healthy ? 'Healthy' : 'Unhealthy'}</h3>
852
+ <div class="health-result-row"><span>URL</span><span class="mono">\${escHtml(d.url)}</span></div>
853
+ <div class="health-result-row"><span>Response Time</span><span>\${d.responseTimeMs}ms</span></div>
854
+ \${d.statusCode ? \`<div class="health-result-row"><span>Status Code</span><span>\${d.statusCode}</span></div>\` : ''}
855
+ \${d.error ? \`<div class="health-result-row"><span>Error</span><span style="color:var(--danger-color)">\${escHtml(d.error)}</span></div>\` : ''}
856
+ </div>
857
+ \`;
858
+ } else {
859
+ showToast(url + ' is ' + (d.healthy ? 'HEALTHY' : 'UNHEALTHY') + ' (' + d.responseTimeMs + 'ms)', d.healthy ? 'success' : 'error');
860
+ }
861
+ },
862
+
863
+ /* ---------- Actions ---------- */
864
+ async runJanitor() {
865
+ showToast('Running janitor...', 'info');
866
+ const result = await this.api('POST', '/admin/janitor');
867
+ if (!result || result.status !== 'success') return;
868
+ const s = result.data?.summary;
869
+ if (s) {
870
+ showToast(\`Janitor complete: \${s.totalChecked} checked, \${s.healthy} healthy, \${s.unhealthy} unhealthy, \${s.removed} removed, \${s.banned} banned\`, 'success');
871
+ } else {
872
+ showToast('Janitor run completed', 'success');
873
+ }
874
+ },
875
+
876
+ async syncAds() {
877
+ showToast('Syncing advertisements...', 'info');
878
+ const result = await this.api('POST', '/admin/syncAdvertisements');
879
+ if (result && result.status === 'success') showToast('Advertisements synced', 'success');
880
+ },
881
+
882
+ async gaspSync() {
883
+ showToast('Starting GASP sync (this may take a while)...', 'info');
884
+ const result = await this.api('POST', '/admin/startGASPSync');
885
+ if (result && result.status === 'success') showToast('GASP sync completed', 'success');
886
+ },
887
+
888
+ async addBan() {
889
+ const type = document.getElementById('ban_type').value;
890
+ const value = document.getElementById('ban_value').value.trim();
891
+ const reason = document.getElementById('ban_reason').value.trim();
892
+ if (!value) { showToast('Value is required', 'error'); return; }
893
+ const result = await this.api('POST', '/admin/ban', { type, value, reason: reason || undefined });
894
+ if (result && result.status === 'success') {
895
+ showToast(result.message, 'success');
896
+ this.showBanList();
897
+ }
898
+ },
899
+
900
+ async unban(type, value) {
901
+ const result = await this.api('POST', '/admin/unban', { type, value });
902
+ if (result && result.status === 'success') {
903
+ showToast(result.message, 'success');
904
+ this.showBanList();
905
+ }
906
+ },
907
+
908
+ confirmRemoveToken(txid, outputIndex, domain) {
909
+ showConfirm(
910
+ 'Remove Token',
911
+ \`Remove token <code>\${txid.substring(0,12)}...\${outputIndex}</code> from \${escHtml(domain)}?\`,
912
+ [
913
+ { label: 'Remove Only', class: 'btn-danger', action: () => this.removeToken(txid, outputIndex, false, false) },
914
+ { label: 'Remove & Ban Outpoint', class: 'btn-warning', action: () => this.removeToken(txid, outputIndex, true, false) },
915
+ { label: 'Remove & Ban Domain', class: 'btn-warning', action: () => this.removeToken(txid, outputIndex, true, true) },
916
+ ]
917
+ );
918
+ },
919
+
920
+ confirmBanDomain(domain) {
921
+ showConfirm(
922
+ 'Ban Domain',
923
+ \`Ban <strong>\${escHtml(domain)}</strong>?<br><br>This will remove ALL SHIP and SLAP records for this domain and prevent GASP from re-syncing them.\`,
924
+ [
925
+ { label: 'Ban Domain', class: 'btn-danger', action: () => this.banDomain(domain) },
926
+ ]
927
+ );
928
+ },
929
+
930
+ async removeToken(txid, outputIndex, ban, banDomain) {
931
+ const result = await this.api('POST', '/admin/remove-token', { txid, outputIndex, ban, banDomain });
932
+ if (result && result.status === 'success') {
933
+ showToast(result.message, 'success');
934
+ // Refresh current view
935
+ const hash = window.location.hash.substring(1);
936
+ if (hash.startsWith('admin/ship')) this.showShipRecords(this.shipPage);
937
+ else if (hash.startsWith('admin/slap')) this.showSlapRecords(this.slapPage);
938
+ }
939
+ },
940
+
941
+ async banDomain(domain) {
942
+ const result = await this.api('POST', '/admin/ban', { type: 'domain', value: domain, reason: 'Manually banned by admin' });
943
+ if (result && result.status === 'success') {
944
+ showToast(result.message, 'success');
945
+ const hash = window.location.hash.substring(1);
946
+ if (hash.startsWith('admin/ship')) this.showShipRecords(this.shipPage);
947
+ else if (hash.startsWith('admin/slap')) this.showSlapRecords(this.slapPage);
948
+ else if (hash.startsWith('admin/ban')) this.showBanList();
949
+ }
363
950
  }
364
951
  };
365
952
 
366
- // Function to parse hash and load appropriate content
953
+ /* ==========================================
954
+ HELPERS
955
+ ========================================== */
956
+ function escHtml(str) {
957
+ if (!str) return '';
958
+ const div = document.createElement('div');
959
+ div.textContent = str;
960
+ return div.innerHTML;
961
+ }
962
+
963
+ function healthDotClass(downCount) {
964
+ if (!downCount || downCount === 0) return 'green';
965
+ if (downCount === 1) return 'yellow';
966
+ return 'red';
967
+ }
968
+
969
+ function formatDuration(ms) {
970
+ const s = Math.floor(ms / 1000);
971
+ const d = Math.floor(s / 86400);
972
+ const h = Math.floor((s % 86400) / 3600);
973
+ const m = Math.floor((s % 3600) / 60);
974
+ const parts = [];
975
+ if (d > 0) parts.push(d + 'd');
976
+ if (h > 0) parts.push(h + 'h');
977
+ parts.push(m + 'm');
978
+ return parts.join(' ');
979
+ }
980
+
981
+ function switchToAdmin(activeId) {
982
+ document.getElementById('documentation_container').style.display = 'none';
983
+ document.getElementById('admin_content').style.display = '';
984
+ document.querySelectorAll('.list-item a').forEach(item => item.classList.remove('active'));
985
+ const el = document.querySelector('[data-admin="' + activeId + '"]');
986
+ if (el) el.classList.add('active');
987
+ }
988
+
989
+ function showConfirm(title, message, buttons) {
990
+ const overlay = document.createElement('div');
991
+ overlay.className = 'confirm-overlay';
992
+ overlay.innerHTML = \`
993
+ <div class="confirm-dialog">
994
+ <h3>\${title}</h3>
995
+ <p>\${message}</p>
996
+ <div class="actions">
997
+ <button class="btn btn-outline" id="confirm_cancel">Cancel</button>
998
+ \${buttons.map((b, i) => \`<button class="btn \${b.class}" id="confirm_btn_\${i}">\${b.label}</button>\`).join('')}
999
+ </div>
1000
+ </div>
1001
+ \`;
1002
+ document.body.appendChild(overlay);
1003
+ document.getElementById('confirm_cancel').onclick = () => overlay.remove();
1004
+ buttons.forEach((b, i) => {
1005
+ document.getElementById('confirm_btn_' + i).onclick = () => { overlay.remove(); b.action(); };
1006
+ });
1007
+ }
1008
+
1009
+ /* ==========================================
1010
+ ADMIN LOGIN FROM DOCS VIEW
1011
+ ========================================== */
1012
+ window.showAdminLogin = () => {
1013
+ document.getElementById('documentation_container').style.display = 'none';
1014
+ document.getElementById('admin_content').style.display = '';
1015
+ document.querySelectorAll('.list-item a').forEach(item => item.classList.remove('active'));
1016
+ const loginEl = document.querySelector('[data-admin="admin-login"]');
1017
+ if (loginEl) loginEl.classList.add('active');
1018
+ document.getElementById('admin_content').innerHTML = \`
1019
+ <div class="admin-login">
1020
+ <h2>Admin Login</h2>
1021
+ <p>Authenticate with your BSV wallet (automatic if wallet extension is present and identity key matches), or enter the admin bearer token.</p>
1022
+ <div class="admin-login-form">
1023
+ <input type="password" id="admin_token_input" placeholder="Admin Bearer Token" onkeydown="if(event.key==='Enter')handleAdminLogin()" />
1024
+ <button class="btn btn-primary" onclick="handleAdminLogin()">Login with Token</button>
1025
+ </div>
1026
+ <p style="margin-top:1em;color:#777;font-size:0.85em">If you have a BSV wallet extension installed and your identity key matches the server admin key, you will be authenticated automatically via BSV mutual authentication.</p>
1027
+ </div>
1028
+ \`;
1029
+ };
1030
+
1031
+ async function handleAdminLogin() {
1032
+ const token = document.getElementById('admin_token_input').value.trim();
1033
+ if (!token) return;
1034
+ const success = await Admin.login(token);
1035
+ if (success) Admin.showOverview();
1036
+ }
1037
+
1038
+ /* ==========================================
1039
+ PAGE INITIALIZATION
1040
+ ========================================== */
367
1041
  const handleUrlHash = () => {
368
- const hash = window.location.hash.substring(1); // Remove the # character
369
- if (hash) {
370
- const [type, id] = hash.split('/');
371
- if (type && id) {
372
- if (type === 'manager') {
373
- // Check if managers data is loaded
374
- if (Object.keys(managersData).length > 0 && managersData[id]) {
375
- window.managerDocumentation(id);
376
- }
377
- } else if (type === 'provider') {
378
- // Check if providers data is loaded
379
- if (Object.keys(providersData).length > 0 && providersData[id]) {
380
- window.topicDocumentation(id);
381
- }
382
- }
1042
+ const hash = window.location.hash.substring(1);
1043
+ if (!hash) return;
1044
+ const [type, id] = hash.split('/');
1045
+ if (type === 'manager' && id && managersData[id]) {
1046
+ window.managerDocumentation(id);
1047
+ } else if (type === 'provider' && id && providersData[id]) {
1048
+ window.topicDocumentation(id);
1049
+ } else if (type === 'admin') {
1050
+ if (!Admin.isAdmin) { window.showAdminLogin(); return; }
1051
+ switch (id) {
1052
+ case 'overview': Admin.showOverview(); break;
1053
+ case 'ship': Admin.showShipRecords(1); break;
1054
+ case 'slap': Admin.showSlapRecords(1); break;
1055
+ case 'bans': Admin.showBanList(); break;
1056
+ case 'health': Admin.showHealthChecker(); break;
1057
+ default: Admin.showOverview(); break;
383
1058
  }
384
1059
  }
385
1060
  };
386
1061
 
387
1062
  document.addEventListener('DOMContentLoaded', () => {
1063
+ Admin.init();
1064
+
388
1065
  let managersLoaded = false;
389
1066
  let providersLoaded = false;
390
1067
 
391
- // Check if both managers and providers are loaded before handling hash
392
1068
  const checkAllLoaded = () => {
393
- if (managersLoaded && providersLoaded) {
394
- handleUrlHash();
395
- }
1069
+ if (managersLoaded && providersLoaded) { handleUrlHash(); }
396
1070
  };
397
1071
 
398
- fetch('${host}/listTopicManagers')
1072
+ fetch(HOST + '/listTopicManagers')
399
1073
  .then(res => res.json())
400
1074
  .then(managers => {
401
1075
  managersData = managers;
@@ -404,25 +1078,19 @@ export default (config = {}) => {
404
1078
  let managerData = managers[manager];
405
1079
  let li = document.createElement('li');
406
1080
  li.className = 'list-item';
407
- li.innerHTML = \`
408
- <a data-manager="\${manager}" onclick="window.managerDocumentation('\${manager}')">
409
- \${managerData.name}
410
- </a>
411
- \`;
1081
+ li.innerHTML = \`<a data-manager="\${manager}" onclick="window.managerDocumentation('\${manager}')">\${managerData.name}</a>\`;
412
1082
  managerList.appendChild(li);
413
1083
  });
414
1084
  managersLoaded = true;
415
1085
  checkAllLoaded();
416
1086
  })
417
1087
  .catch(() => {
418
- let message = document.createElement('h4');
419
- message.innerText = 'Something went wrong!';
420
- manager_list.insertBefore(message, manager_list.children[0]);
1088
+ document.getElementById('manager_list').innerHTML = '<li style="color:#999">Failed to load</li>';
421
1089
  managersLoaded = true;
422
1090
  checkAllLoaded();
423
1091
  });
424
1092
 
425
- fetch('${host}/listLookupServiceProviders')
1093
+ fetch(HOST + '/listLookupServiceProviders')
426
1094
  .then(res => res.json())
427
1095
  .then(providers => {
428
1096
  providersData = providers;
@@ -431,55 +1099,41 @@ export default (config = {}) => {
431
1099
  let providerData = providers[provider];
432
1100
  let li = document.createElement('li');
433
1101
  li.className = 'list-item';
434
- li.innerHTML = \`
435
- <a data-provider="\${provider}" onclick="window.topicDocumentation('\${provider}')">
436
- \${providerData.name}
437
- </a>
438
- \`;
1102
+ li.innerHTML = \`<a data-provider="\${provider}" onclick="window.topicDocumentation('\${provider}')">\${providerData.name}</a>\`;
439
1103
  providerList.appendChild(li);
440
1104
  });
441
1105
  providersLoaded = true;
442
1106
  checkAllLoaded();
443
1107
  })
444
1108
  .catch(() => {
445
- let message = document.createElement('h4');
446
- message.innerText = 'Something went wrong!';
447
- provider_list.insertBefore(message, provider_list.children[0]);
1109
+ document.getElementById('provider_list').innerHTML = '<li style="color:#999">Failed to load</li>';
448
1110
  providersLoaded = true;
449
1111
  checkAllLoaded();
450
1112
  });
451
1113
 
452
- // Check URL hash to see if we should load specific documentation
1114
+ // Check hash on initial load and listen for changes
453
1115
  const checkUrlHash = () => {
454
- const hash = window.location.hash.substring(1); // Remove the # symbol
1116
+ const hash = window.location.hash.substring(1);
455
1117
  if (hash) {
456
1118
  const parts = hash.split('/');
457
1119
  if (parts.length === 2) {
458
- const type = parts[0];
459
- const id = parts[1];
460
-
461
- if (type === 'manager' && id && managersData[id]) {
462
- window.managerDocumentation(id);
463
- } else if (type === 'provider' && id && providersData[id]) {
464
- window.topicDocumentation(id);
465
- }
1120
+ const [type, id] = parts;
1121
+ if (type === 'manager' && id && managersData[id]) { window.managerDocumentation(id); }
1122
+ else if (type === 'provider' && id && providersData[id]) { window.topicDocumentation(id); }
1123
+ else if (type === 'admin') { handleUrlHash(); }
466
1124
  }
467
1125
  } else {
468
- // Display default message when no manager or provider is selected
469
1126
  returnHome();
470
1127
  }
471
1128
  };
472
-
473
- // Listen for hash changes
474
1129
  window.addEventListener('hashchange', checkUrlHash);
475
-
476
- // Check hash on initial page load
477
1130
  checkUrlHash();
478
1131
  });
479
1132
  </script>
480
1133
  </head>
481
1134
 
482
1135
  <body>
1136
+ <div id="toast_container" class="toast-container"></div>
483
1137
  <div class="main">
484
1138
  <div class="column_left">
485
1139
  <div class="page_head">
@@ -494,16 +1148,34 @@ export default (config = {}) => {
494
1148
  <ul id="provider_list"></ul>
495
1149
  </div>
496
1150
  <div>
497
- <h3>External Links</h3>
1151
+ <h3>External Links</h3>
498
1152
  <ul id="external_list">
499
1153
  <li class="list-item"><a href="https://github.com/bsv-blockchain/overlay-services" target="_blank">Overlay Services GitHub</a></li>
500
1154
  <li class="list-item"><a href="https://bsv.brc.dev/transactions/0076" target="_blank">BRC-76 GASP</a></li>
501
1155
  <li class="list-item"><a href="https://fast.brc.dev" target="_blank">Quick Start for App Developers</a></li>
502
1156
  </ul>
503
1157
  </div>
1158
+ <div id="admin_section">
1159
+ <div class="admin-divider"></div>
1160
+ <h3>Admin Dashboard</h3>
1161
+ <ul id="admin_list">
1162
+ <li class="list-item"><a data-admin="admin-overview" onclick="Admin.showOverview()">Overview</a></li>
1163
+ <li class="list-item"><a data-admin="admin-ship" onclick="Admin.showShipRecords(1)">SHIP Records</a></li>
1164
+ <li class="list-item"><a data-admin="admin-slap" onclick="Admin.showSlapRecords(1)">SLAP Records</a></li>
1165
+ <li class="list-item"><a data-admin="admin-bans" onclick="Admin.showBanList()">Ban List</a></li>
1166
+ <li class="list-item"><a data-admin="admin-health" onclick="Admin.showHealthChecker()">Health Checker</a></li>
1167
+ <li class="list-item"><a onclick="Admin.logout()" style="color:var(--danger-color)">Logout</a></li>
1168
+ </ul>
1169
+ </div>
1170
+ <div id="admin_login_link" style="margin-top:1em">
1171
+ <ul style="list-style:none;padding:0">
1172
+ <li class="list-item"><a data-admin="admin-login" onclick="window.showAdminLogin()">Admin Login</a></li>
1173
+ </ul>
1174
+ </div>
504
1175
  </div>
505
1176
  <div class="column_right">
506
1177
  <div id="documentation_container"></div>
1178
+ <div id="admin_content" style="display:none"></div>
507
1179
  </div>
508
1180
  </div>
509
1181
  </body>