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