@t0.labs/daxta 0.2.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 (49) hide show
  1. package/README.md +40 -0
  2. package/assets/favicon.png +0 -0
  3. package/assets/viewer.html +1835 -0
  4. package/bin/daxta.js +2 -0
  5. package/dist/build/build-spec.d.ts +28 -0
  6. package/dist/build/build-spec.js +704 -0
  7. package/dist/build/incremental.d.ts +12 -0
  8. package/dist/build/incremental.js +121 -0
  9. package/dist/call/index.d.ts +24 -0
  10. package/dist/call/index.js +204 -0
  11. package/dist/catalog/index.d.ts +27 -0
  12. package/dist/catalog/index.js +111 -0
  13. package/dist/cli/install.d.ts +6 -0
  14. package/dist/cli/install.js +333 -0
  15. package/dist/cli/main.d.ts +1 -0
  16. package/dist/cli/main.js +102 -0
  17. package/dist/config.d.ts +31 -0
  18. package/dist/config.js +106 -0
  19. package/dist/fields/dto-fields.d.ts +4 -0
  20. package/dist/fields/dto-fields.js +372 -0
  21. package/dist/fields/export-fields.d.ts +23 -0
  22. package/dist/fields/export-fields.js +218 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.js +42 -0
  25. package/dist/jest/global-setup.d.ts +1 -0
  26. package/dist/jest/global-setup.js +7 -0
  27. package/dist/jest/global-teardown.d.ts +1 -0
  28. package/dist/jest/global-teardown.js +20 -0
  29. package/dist/jest/reporter.d.ts +7 -0
  30. package/dist/jest/reporter.js +29 -0
  31. package/dist/path.util.d.ts +6 -0
  32. package/dist/path.util.js +108 -0
  33. package/dist/recorder/index.d.ts +15 -0
  34. package/dist/recorder/index.js +176 -0
  35. package/dist/register.d.ts +1 -0
  36. package/dist/register.js +27 -0
  37. package/dist/serve/index.d.ts +9 -0
  38. package/dist/serve/index.js +126 -0
  39. package/dist/serve/middleware.d.ts +38 -0
  40. package/dist/serve/middleware.js +131 -0
  41. package/dist/serve/paths.d.ts +7 -0
  42. package/dist/serve/paths.js +66 -0
  43. package/dist/serve/proxy.d.ts +16 -0
  44. package/dist/serve/proxy.js +52 -0
  45. package/dist/serve/spec-utils.d.ts +2 -0
  46. package/dist/serve/spec-utils.js +27 -0
  47. package/dist/setup.d.ts +1 -0
  48. package/dist/setup.js +7 -0
  49. package/package.json +75 -0
@@ -0,0 +1,1835 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>DAxTA</title>
7
+ <link rel="icon" type="image/png" href="__FAVICON_DATA_URI__" />
8
+ <link rel="apple-touch-icon" href="__FAVICON_DATA_URI__" />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11
+ <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600&family=Geist:wght@400;500;600&display=swap" rel="stylesheet" />
12
+ <style>
13
+ :root {
14
+ --canvas: #e8e8e8;
15
+ --sidebar: #f2f2f2;
16
+ --nav: #f7f7f7;
17
+ --paper: #f4f4f4;
18
+ --white: #ffffff;
19
+ --inset: #f0f0f0;
20
+ --hairline: #d6d6d6;
21
+ --line: #c3c3c3;
22
+ --smoke: #7a7a7a;
23
+ --stone: #5c5c5c;
24
+ --charcoal: #333333;
25
+ --obsidian: #171717;
26
+ --sans: Geist, Inter, ui-sans-serif, system-ui, sans-serif;
27
+ --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
28
+ --radius: 6px;
29
+ --ring: 0 0 0 1px #cfcfcf;
30
+ --ghost: 0 0 0 1px #cfcfcf;
31
+ }
32
+ * { box-sizing: border-box; }
33
+ html, body { height: 100%; }
34
+ body {
35
+ margin: 0;
36
+ background: var(--canvas);
37
+ color: var(--obsidian);
38
+ font: 15px/1.55 var(--sans);
39
+ }
40
+ button, input { font: inherit; color: inherit; }
41
+
42
+ .topnav {
43
+ height: 56px;
44
+ display: grid;
45
+ grid-template-columns: 1fr auto 1fr;
46
+ align-items: center;
47
+ gap: 16px;
48
+ padding: 0 20px;
49
+ background: var(--nav);
50
+ border-bottom: 1px solid var(--hairline);
51
+ position: sticky;
52
+ top: 0;
53
+ z-index: 20;
54
+ }
55
+ body.searching .topnav { z-index: 30; }
56
+ .brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; justify-self: start; }
57
+ .workspace {
58
+ flex: none;
59
+ font: 500 11px/1 var(--mono);
60
+ letter-spacing: 0.06em;
61
+ text-transform: uppercase;
62
+ padding: 5px 8px;
63
+ border-radius: 9999px;
64
+ background: var(--obsidian);
65
+ color: var(--white);
66
+ }
67
+ .brand { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
68
+ .nav-tools { display: flex; align-items: center; gap: 8px; justify-self: end; }
69
+ .nav-tools .btn {
70
+ height: 36px;
71
+ padding: 0 12px;
72
+ font-size: 12px;
73
+ }
74
+ .nav-tools .btn.icon {
75
+ width: 36px;
76
+ height: 36px;
77
+ padding: 0;
78
+ }
79
+ .nav-tools .btn.icon svg { width: 16px; height: 16px; }
80
+ .btn[data-tip] { position: relative; }
81
+ .btn[data-tip]::after {
82
+ content: attr(data-tip);
83
+ position: absolute;
84
+ top: calc(100% + 8px);
85
+ left: 50%;
86
+ transform: translateX(-50%) translateY(4px);
87
+ background: var(--obsidian);
88
+ color: var(--white);
89
+ font-size: 11px;
90
+ font-weight: 500;
91
+ padding: 6px 8px;
92
+ border-radius: var(--radius);
93
+ white-space: nowrap;
94
+ opacity: 0;
95
+ pointer-events: none;
96
+ transition: opacity 0.12s ease, transform 0.12s ease;
97
+ z-index: 50;
98
+ }
99
+ .btn[data-tip]:hover::after {
100
+ opacity: 1;
101
+ transform: translateX(-50%) translateY(0);
102
+ }
103
+ .search-wrap {
104
+ justify-self: center;
105
+ position: relative;
106
+ width: min(420px, 46vw);
107
+ z-index: 30;
108
+ }
109
+ .search {
110
+ width: 100%;
111
+ height: 36px;
112
+ border: 0;
113
+ border-radius: var(--radius);
114
+ box-shadow: var(--ghost);
115
+ background: var(--white);
116
+ padding: 0 12px;
117
+ }
118
+ .search::placeholder { color: var(--smoke); }
119
+ .search-wrap.open .search {
120
+ box-shadow: 0 0 0 1px var(--obsidian);
121
+ border-radius: var(--radius) var(--radius) 0 0;
122
+ }
123
+ .search-backdrop {
124
+ display: none;
125
+ position: fixed;
126
+ inset: 0;
127
+ background: rgba(232, 232, 232, 0.72);
128
+ backdrop-filter: blur(2px);
129
+ z-index: 25;
130
+ }
131
+ body.searching .search-backdrop { display: block; }
132
+ .search-panel {
133
+ display: none;
134
+ position: absolute;
135
+ top: 100%;
136
+ left: 0;
137
+ right: 0;
138
+ max-height: min(420px, calc(100vh - 90px));
139
+ overflow: auto;
140
+ background: var(--white);
141
+ border-radius: 0 0 var(--radius) var(--radius);
142
+ box-shadow: 0 12px 36px rgba(0, 0, 0, 0.14), var(--ring);
143
+ z-index: 31;
144
+ padding: 6px;
145
+ }
146
+ .search-wrap.open .search-panel { display: block; }
147
+ .search-hit {
148
+ display: flex;
149
+ align-items: center;
150
+ gap: 10px;
151
+ width: 100%;
152
+ border: 0;
153
+ background: transparent;
154
+ text-align: left;
155
+ padding: 10px 10px;
156
+ border-radius: var(--radius);
157
+ cursor: pointer;
158
+ color: var(--charcoal);
159
+ }
160
+ .search-hit:hover,
161
+ .search-hit.active { background: var(--inset); }
162
+ .search-hit-path {
163
+ min-width: 0;
164
+ font: 12px/1.35 var(--mono);
165
+ color: var(--obsidian);
166
+ overflow: hidden;
167
+ text-overflow: ellipsis;
168
+ white-space: nowrap;
169
+ }
170
+ .search-hit mark {
171
+ background: transparent;
172
+ color: var(--obsidian);
173
+ font-weight: 600;
174
+ text-decoration: underline;
175
+ text-decoration-thickness: 1px;
176
+ text-underline-offset: 2px;
177
+ }
178
+ .search-empty {
179
+ padding: 18px 12px;
180
+ color: var(--stone);
181
+ font-size: 13px;
182
+ text-align: center;
183
+ }
184
+ .env-wrap { position: relative; flex: none; }
185
+ .env-wrap.open .env-pop { display: block; }
186
+ .env-trigger {
187
+ flex: none;
188
+ width: 220px;
189
+ height: 36px;
190
+ border: 0;
191
+ border-radius: var(--radius);
192
+ box-shadow: var(--ghost);
193
+ background: var(--white);
194
+ padding: 0 32px 0 12px;
195
+ font: 500 12px/1 var(--mono);
196
+ color: var(--obsidian);
197
+ cursor: pointer;
198
+ position: relative;
199
+ white-space: nowrap;
200
+ text-align: left;
201
+ overflow: hidden;
202
+ text-overflow: ellipsis;
203
+ }
204
+ .env-trigger::after {
205
+ content: "";
206
+ position: absolute;
207
+ right: 12px;
208
+ top: 50%;
209
+ width: 6px;
210
+ height: 6px;
211
+ border-right: 1px solid var(--obsidian);
212
+ border-bottom: 1px solid var(--obsidian);
213
+ transform: translateY(-70%) rotate(45deg);
214
+ }
215
+ .env-wrap.open .env-trigger::after { transform: translateY(-20%) rotate(225deg); }
216
+ .env-pop {
217
+ display: none;
218
+ position: absolute;
219
+ top: calc(100% + 6px);
220
+ right: 0;
221
+ width: min(420px, calc(100vw - 48px));
222
+ max-height: min(520px, calc(100vh - 120px));
223
+ overflow: auto;
224
+ background: var(--white);
225
+ border-radius: var(--radius);
226
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), var(--ring);
227
+ padding: 16px;
228
+ z-index: 40;
229
+ }
230
+ .env-block { margin-bottom: 20px; }
231
+ .env-block:last-child { margin-bottom: 0; }
232
+ .env-label {
233
+ font-family: var(--mono);
234
+ font-size: 11px;
235
+ letter-spacing: 0.08em;
236
+ text-transform: uppercase;
237
+ color: var(--stone);
238
+ margin-bottom: 8px;
239
+ }
240
+ .env-cell {
241
+ width: 100%;
242
+ min-width: 0;
243
+ height: 32px;
244
+ border: 0;
245
+ border-radius: var(--radius);
246
+ background: var(--inset);
247
+ padding: 0 10px;
248
+ font: 12px/1 var(--mono);
249
+ color: var(--obsidian);
250
+ }
251
+ .env-kv {
252
+ display: grid;
253
+ grid-template-columns: 1fr 1fr 28px;
254
+ gap: 6px;
255
+ margin-bottom: 6px;
256
+ }
257
+ .ghost-btn {
258
+ border: 0;
259
+ background: transparent;
260
+ color: var(--stone);
261
+ cursor: pointer;
262
+ width: 32px;
263
+ height: 32px;
264
+ padding: 0;
265
+ display: inline-flex;
266
+ align-items: center;
267
+ justify-content: center;
268
+ font-size: 16px;
269
+ line-height: 1;
270
+ }
271
+ .ghost-btn:hover { color: var(--obsidian); }
272
+ .ghost-btn:disabled { opacity: 0.35; cursor: default; }
273
+ .ghost-btn:disabled:hover { color: var(--stone); }
274
+ .chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
275
+ .chip-btn {
276
+ border: 0;
277
+ background: var(--inset);
278
+ box-shadow: var(--ghost);
279
+ border-radius: 9999px;
280
+ padding: 5px 10px;
281
+ cursor: pointer;
282
+ font-size: 12px;
283
+ color: var(--charcoal);
284
+ }
285
+ .chip-btn.on {
286
+ background: var(--obsidian);
287
+ color: var(--white);
288
+ box-shadow: none;
289
+ }
290
+ .env-add {
291
+ height: 32px;
292
+ padding: 0 10px;
293
+ font-size: 12px;
294
+ margin-top: 4px;
295
+ }
296
+ .btn.primary {
297
+ background: var(--obsidian);
298
+ color: var(--white);
299
+ box-shadow: none;
300
+ }
301
+ .btn.primary:hover { opacity: 0.92; color: var(--white); }
302
+ .btn.primary:disabled { opacity: 0.45; cursor: default; }
303
+ .live-err { color: #8a2e2e; font-size: 13px; padding: 8px 0; white-space: pre-wrap; }
304
+
305
+ .app {
306
+ display: grid;
307
+ grid-template-columns: 320px minmax(0, 1fr);
308
+ height: calc(100vh - 56px);
309
+ }
310
+ .sidebar, .workbench { height: 100%; overflow: auto; }
311
+ .sidebar {
312
+ padding: 16px 12px 48px;
313
+ background: var(--sidebar);
314
+ border-right: 1px solid var(--line);
315
+ font-size: 13px;
316
+ }
317
+ .tree-root { display: flex; flex-direction: column; gap: 2px; }
318
+ .tree-folder { display: flex; flex-direction: column; gap: 2px; }
319
+ .tree-folder-toggle {
320
+ display: flex;
321
+ align-items: center;
322
+ gap: 6px;
323
+ width: 100%;
324
+ border: 0;
325
+ background: transparent;
326
+ text-align: left;
327
+ padding: 6px 8px;
328
+ border-radius: var(--radius);
329
+ cursor: pointer;
330
+ color: var(--charcoal);
331
+ font: 500 12px/1.4 var(--mono);
332
+ }
333
+ .tree-folder-toggle:hover { background: var(--white); color: var(--obsidian); }
334
+ .tree-folder-toggle .chev {
335
+ width: 10px;
336
+ height: 10px;
337
+ flex: none;
338
+ position: relative;
339
+ opacity: 0.55;
340
+ }
341
+ .tree-folder-toggle .chev::before {
342
+ content: "";
343
+ position: absolute;
344
+ left: 2px;
345
+ top: 1px;
346
+ width: 5px;
347
+ height: 5px;
348
+ border-right: 1.5px solid currentColor;
349
+ border-bottom: 1.5px solid currentColor;
350
+ transform: rotate(-45deg);
351
+ transition: transform 0.15s ease;
352
+ }
353
+ .tree-folder.open > .tree-folder-toggle .chev::before { transform: rotate(45deg); top: 0; }
354
+ .tree-folder-name {
355
+ min-width: 0;
356
+ overflow: hidden;
357
+ text-overflow: ellipsis;
358
+ white-space: nowrap;
359
+ }
360
+ .tree-children {
361
+ display: none;
362
+ margin-left: 14px;
363
+ padding-left: 8px;
364
+ border-left: 1px solid var(--hairline);
365
+ }
366
+ .tree-folder.open > .tree-children { display: flex; flex-direction: column; gap: 2px; }
367
+ .tree-empty {
368
+ padding: 24px 12px;
369
+ color: var(--stone);
370
+ font-size: 13px;
371
+ text-align: center;
372
+ }
373
+ .nav-item {
374
+ display: flex;
375
+ align-items: center;
376
+ gap: 8px;
377
+ width: 100%;
378
+ border: 0;
379
+ background: transparent;
380
+ text-align: left;
381
+ padding: 7px 8px;
382
+ border-radius: var(--radius);
383
+ cursor: pointer;
384
+ }
385
+ .nav-item:hover { background: var(--white); }
386
+ .nav-item.active { background: var(--white); box-shadow: var(--ring); }
387
+ .nav-title {
388
+ font-size: 12px;
389
+ color: var(--charcoal);
390
+ min-width: 0;
391
+ overflow: hidden;
392
+ text-overflow: ellipsis;
393
+ white-space: nowrap;
394
+ }
395
+ .nav-item.active .nav-title { color: var(--obsidian); }
396
+
397
+ .method {
398
+ display: inline-flex;
399
+ align-items: center;
400
+ justify-content: center;
401
+ min-width: 48px;
402
+ height: 22px;
403
+ padding: 0 6px;
404
+ border-radius: 9999px;
405
+ font: 500 11px/1 var(--mono);
406
+ letter-spacing: 0.06em;
407
+ text-transform: uppercase;
408
+ box-shadow: var(--ghost);
409
+ background: var(--white);
410
+ }
411
+ .method.post, .method.put, .method.patch {
412
+ background: var(--obsidian);
413
+ color: var(--white);
414
+ box-shadow: none;
415
+ }
416
+ .method.get { background: var(--inset); color: var(--obsidian); }
417
+ .method.delete { background: var(--white); color: var(--charcoal); }
418
+
419
+ .workbench { padding: 28px 36px 96px; background: var(--paper); }
420
+ .head-row {
421
+ display: flex;
422
+ align-items: flex-start;
423
+ justify-content: space-between;
424
+ gap: 16px;
425
+ margin-bottom: 16px;
426
+ }
427
+ .title { font-size: 28px; letter-spacing: -1px; line-height: 1.15; margin: 0; font-weight: 400; min-width: 0; }
428
+ .meta-line { color: var(--stone); font: 12px/1.4 var(--mono); margin: 8px 0 0; }
429
+
430
+ .dd { position: relative; min-width: min(100%, 420px); }
431
+ .dd-toggle {
432
+ width: 100%;
433
+ min-height: 40px;
434
+ border: 0;
435
+ border-radius: var(--radius);
436
+ box-shadow: var(--ghost);
437
+ background: var(--white);
438
+ padding: 8px 36px 8px 12px;
439
+ text-align: left;
440
+ cursor: pointer;
441
+ font-size: 14px;
442
+ line-height: 1.4;
443
+ position: relative;
444
+ }
445
+ .dd-toggle::after {
446
+ content: "";
447
+ position: absolute;
448
+ right: 14px;
449
+ top: 50%;
450
+ width: 6px;
451
+ height: 6px;
452
+ border-right: 1px solid var(--obsidian);
453
+ border-bottom: 1px solid var(--obsidian);
454
+ transform: translateY(-70%) rotate(45deg);
455
+ }
456
+ .dd.open .dd-toggle::after { transform: translateY(-20%) rotate(225deg); }
457
+ .dd-menu {
458
+ display: none;
459
+ position: absolute;
460
+ z-index: 30;
461
+ top: calc(100% + 4px);
462
+ left: 0;
463
+ right: 0;
464
+ max-height: 320px;
465
+ overflow: auto;
466
+ background: var(--white);
467
+ border-radius: var(--radius);
468
+ box-shadow: var(--ring);
469
+ padding: 6px 0;
470
+ }
471
+ .dd.open .dd-menu { display: block; }
472
+ .dd-group {
473
+ font-family: var(--mono);
474
+ font-size: 11px;
475
+ letter-spacing: 0.08em;
476
+ text-transform: uppercase;
477
+ color: var(--stone);
478
+ padding: 10px 12px 6px;
479
+ }
480
+ .dd-item {
481
+ display: block;
482
+ width: 100%;
483
+ border: 0;
484
+ background: transparent;
485
+ text-align: left;
486
+ padding: 8px 12px;
487
+ font-size: 14px;
488
+ cursor: pointer;
489
+ }
490
+ .dd-item:hover, .dd-item.on { background: var(--inset); }
491
+
492
+ .urlbar {
493
+ display: flex;
494
+ gap: 8px;
495
+ align-items: stretch;
496
+ margin-bottom: 16px;
497
+ }
498
+ .url {
499
+ flex: 1;
500
+ min-width: 0;
501
+ display: flex;
502
+ align-items: center;
503
+ gap: 12px;
504
+ background: var(--white);
505
+ border-radius: var(--radius);
506
+ box-shadow: var(--ring);
507
+ padding: 10px 14px;
508
+ font-family: var(--mono);
509
+ font-size: 13px;
510
+ word-break: break-all;
511
+ }
512
+ .url .method { flex: none; }
513
+ .btn {
514
+ border: 0;
515
+ background: var(--white);
516
+ box-shadow: var(--ghost);
517
+ border-radius: var(--radius);
518
+ padding: 0 14px;
519
+ height: 44px;
520
+ cursor: pointer;
521
+ color: var(--charcoal);
522
+ white-space: nowrap;
523
+ }
524
+ .btn:hover { color: var(--obsidian); }
525
+ .btn.sm { height: 32px; padding: 0 10px; font-size: 12px; }
526
+ .btn.icon {
527
+ width: 32px;
528
+ height: 32px;
529
+ padding: 0;
530
+ display: inline-flex;
531
+ align-items: center;
532
+ justify-content: center;
533
+ color: var(--stone);
534
+ }
535
+ .btn.icon:hover:not(:disabled) { color: var(--obsidian); }
536
+ .btn.icon svg { width: 15px; height: 15px; display: block; }
537
+ .btn:disabled { opacity: 0.4; cursor: default; }
538
+
539
+ .toast {
540
+ position: fixed;
541
+ bottom: 24px;
542
+ left: 50%;
543
+ transform: translateX(-50%) translateY(12px);
544
+ background: var(--obsidian);
545
+ color: var(--white);
546
+ font-size: 13px;
547
+ padding: 10px 16px;
548
+ border-radius: var(--radius);
549
+ box-shadow: var(--ring);
550
+ opacity: 0;
551
+ pointer-events: none;
552
+ transition: opacity 0.18s ease, transform 0.18s ease;
553
+ z-index: 100;
554
+ }
555
+ .toast.show {
556
+ opacity: 1;
557
+ transform: translateX(-50%) translateY(0);
558
+ }
559
+
560
+ .pair {
561
+ display: grid;
562
+ grid-template-columns: 1fr 1fr;
563
+ gap: 16px;
564
+ margin-bottom: 24px;
565
+ align-items: start;
566
+ }
567
+ .card {
568
+ background: var(--white);
569
+ border-radius: var(--radius);
570
+ box-shadow: var(--ring);
571
+ min-width: 0;
572
+ display: flex;
573
+ flex-direction: column;
574
+ max-width: 100%;
575
+ }
576
+ .card.response-card {
577
+ overflow: hidden;
578
+ }
579
+ .card-head {
580
+ display: flex;
581
+ align-items: center;
582
+ justify-content: space-between;
583
+ gap: 12px;
584
+ padding: 14px 16px;
585
+ border-bottom: 1px solid var(--hairline);
586
+ flex: none;
587
+ }
588
+ .card-head h2 { margin: 0; font-size: 14px; font-weight: 500; }
589
+ .card-head-actions { display: flex; align-items: center; gap: 8px; }
590
+ .card-body {
591
+ padding: 0;
592
+ display: flex;
593
+ flex-direction: column;
594
+ min-height: 0;
595
+ }
596
+ #response-body {
597
+ overflow: auto;
598
+ }
599
+ #response-body pre {
600
+ max-height: none;
601
+ }
602
+ .meta-block {
603
+ padding: 14px 16px;
604
+ border-top: 1px solid var(--hairline);
605
+ }
606
+ .meta-block:first-child { border-top: 0; }
607
+ .meta-toolbar {
608
+ display: flex;
609
+ align-items: center;
610
+ justify-content: space-between;
611
+ gap: 8px;
612
+ margin-bottom: 10px;
613
+ }
614
+ .meta-label {
615
+ font: 600 11px/1 var(--mono);
616
+ letter-spacing: 0.08em;
617
+ text-transform: uppercase;
618
+ color: var(--obsidian);
619
+ }
620
+ .meta-source { color: var(--smoke); font: 11px/1 var(--mono); }
621
+ .meta-empty { color: var(--smoke); font-size: 12px; padding: 2px 0; }
622
+ .kv {
623
+ display: flex;
624
+ align-items: center;
625
+ gap: 12px;
626
+ margin-bottom: 8px;
627
+ font-size: 13px;
628
+ min-width: 0;
629
+ }
630
+ .kv:last-child { margin-bottom: 0; }
631
+ .kname {
632
+ flex: none;
633
+ width: 120px;
634
+ color: var(--stone);
635
+ font-family: var(--mono);
636
+ font-size: 11px;
637
+ letter-spacing: 0.04em;
638
+ white-space: nowrap;
639
+ overflow: hidden;
640
+ text-overflow: ellipsis;
641
+ }
642
+ .kval {
643
+ flex: 1;
644
+ min-width: 0;
645
+ font-family: var(--mono);
646
+ font-size: 12px;
647
+ color: var(--obsidian);
648
+ padding: 8px 10px;
649
+ background: var(--inset);
650
+ border-radius: var(--radius);
651
+ white-space: nowrap;
652
+ overflow: hidden;
653
+ text-overflow: ellipsis;
654
+ }
655
+ pre {
656
+ margin: 0;
657
+ padding: 12px;
658
+ background: var(--inset);
659
+ border-radius: var(--radius);
660
+ overflow: auto;
661
+ font: 12px/1.5 var(--mono);
662
+ }
663
+ .k { color: #1f4e79; }
664
+ .s { color: #2e6b2e; }
665
+ .n { color: #8a4b12; }
666
+ .p { color: #6b3fa0; }
667
+ .empty { color: var(--stone); font-size: 13px; padding: 8px 0; }
668
+ .code {
669
+ font: 500 12px/1 var(--mono);
670
+ padding: 4px 8px;
671
+ border-radius: 9999px;
672
+ background: var(--inset);
673
+ }
674
+ .code.ok { background: #e5f2e8; color: #297a3a; }
675
+ .code-text { color: var(--stone); font-size: 12px; }
676
+
677
+ .fields { margin-top: 16px; }
678
+ .fields > h2 {
679
+ font-size: 14px;
680
+ font-weight: 500;
681
+ margin: 0 0 4px;
682
+ color: var(--obsidian);
683
+ }
684
+ .fields-section { padding: 14px 0 2px; }
685
+ .fields-section-title {
686
+ font: 500 11px/1 var(--mono);
687
+ letter-spacing: 0.08em;
688
+ text-transform: uppercase;
689
+ color: var(--stone);
690
+ margin-bottom: 8px;
691
+ padding-bottom: 8px;
692
+ border-bottom: 1px solid var(--hairline);
693
+ }
694
+ .row {
695
+ display: grid;
696
+ grid-template-columns: 1.2fr 0.7fr 1fr;
697
+ gap: 12px;
698
+ padding: 8px 0;
699
+ font-size: 13px;
700
+ }
701
+ .row .name { font-family: var(--mono); font-size: 12px; color: var(--obsidian); }
702
+ .row .name.nested { color: var(--ink, var(--obsidian)); }
703
+ .row .type { color: var(--stone); font-family: var(--mono); font-size: 12px; }
704
+ .flag { margin-top: 4px; font-size: 11px; color: var(--smoke); }
705
+ .flag.req { color: #8a2e2e; }
706
+
707
+ @media (max-width: 960px) {
708
+ .app { grid-template-columns: 1fr; height: auto; }
709
+ .sidebar { max-height: 40vh; }
710
+ .pair { grid-template-columns: 1fr; }
711
+ .search-wrap { width: min(280px, 70vw); }
712
+ }
713
+ </style>
714
+ </head>
715
+ <body>
716
+ <header class="topnav">
717
+ <div class="brand-wrap">
718
+ <span class="workspace" id="workspace">workspace</span>
719
+ <div class="brand" id="brand">API Docs</div>
720
+ </div>
721
+ <div class="search-wrap" id="search-wrap">
722
+ <input class="search" id="search" placeholder="Search endpoints" autocomplete="off" spellcheck="false" />
723
+ <div class="search-panel" id="search-panel" role="listbox"></div>
724
+ </div>
725
+ <div class="nav-tools">
726
+ <button class="btn icon" id="export-openapi" type="button" data-tip="Export OpenAPI" aria-label="Export OpenAPI">
727
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
728
+ </button>
729
+ <div class="env-wrap" id="env-wrap">
730
+ <button class="env-trigger" id="env-trigger" type="button">local · —</button>
731
+ <div class="env-pop" id="env-pop"></div>
732
+ </div>
733
+ </div>
734
+ </header>
735
+ <div class="search-backdrop" id="search-backdrop"></div>
736
+ <div class="app">
737
+ <aside class="sidebar" id="nav"></aside>
738
+ <main class="workbench" id="main"></main>
739
+ </div>
740
+ <script>
741
+ window.__SPEC__ = __SPEC_JSON__;
742
+ </script>
743
+ <script>
744
+ const spec = window.__SPEC__ || {};
745
+ const viewer = spec["x-viewer"] || {};
746
+ const workspace = (spec.info && spec.info["x-workspace"]) || viewer.workspace || "";
747
+ const defaultBaseUrlFromSpec = String((viewer.baseUrl || (spec.servers && spec.servers[0] && spec.servers[0].url) || "http://localhost:3000")).replace(/\/$/, "");
748
+ const docsPathSuffix = String(viewer.docsPath || "/docs").replace(/\/$/, "") || "/docs";
749
+
750
+ const inferBaseUrlFromLocation = () => {
751
+ if (typeof location === "undefined") return null;
752
+ if (location.protocol !== "http:" && location.protocol !== "https:") return null;
753
+ let pathname = (location.pathname || "/").replace(/\/$/, "") || "";
754
+ if (pathname === docsPathSuffix) return location.origin.replace(/\/$/, "");
755
+ if (pathname.endsWith(docsPathSuffix)) {
756
+ const prefix = pathname.slice(0, -docsPathSuffix.length).replace(/\/$/, "");
757
+ return (location.origin + prefix).replace(/\/$/, "");
758
+ }
759
+ const idx = pathname.indexOf(docsPathSuffix + "/");
760
+ if (idx >= 0) {
761
+ const prefix = pathname.slice(0, idx).replace(/\/$/, "");
762
+ return (location.origin + prefix).replace(/\/$/, "");
763
+ }
764
+ return null;
765
+ };
766
+
767
+ const locationBaseUrl = inferBaseUrlFromLocation();
768
+ // Prefer the URL that is serving the viewer (strip /docs), else fall back to spec.
769
+ const defaultBaseUrl = locationBaseUrl || defaultBaseUrlFromSpec;
770
+ const title = (spec.info && spec.info.title) || "API Docs";
771
+ const STORE_KEY = "openapi-docs-env:" + (workspace || "default");
772
+
773
+ let liveResult = null;
774
+
775
+ const escapeAttr = (value) =>
776
+ String(value ?? "")
777
+ .replace(/&/g, "&amp;")
778
+ .replace(/"/g, "&quot;")
779
+ .replace(/</g, "&lt;");
780
+
781
+ const varNameFromHeader = (header) => {
782
+ const parts = String(header).replace(/^x-/, "").split("-").filter(Boolean);
783
+ if (!parts.length) return String(header).replace(/[^a-zA-Z0-9]/g, "");
784
+ return parts[0] + parts.slice(1).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
785
+ };
786
+
787
+ /** Pull try-it defaults from recorded success traffic + parameter examples. */
788
+ const collectDefaultHeaderValues = () => {
789
+ const byHeader = {};
790
+ const take = (header, value, prefer) => {
791
+ if (value == null || value === "") return;
792
+ const key = String(header).toLowerCase();
793
+ if (!byHeader[key] || prefer) byHeader[key] = String(value);
794
+ };
795
+ for (const pathItem of Object.values(spec.paths || {})) {
796
+ for (const op of Object.values(pathItem || {})) {
797
+ if (!op || typeof op !== "object") continue;
798
+ for (const param of op.parameters || []) {
799
+ if (param && param.in === "header" && param.name && param.example != null) {
800
+ take(param.name, param.example, false);
801
+ }
802
+ }
803
+ for (const scenario of op["x-scenarios"] || []) {
804
+ const success = scenario.status >= 200 && scenario.status < 300;
805
+ for (const [header, value] of Object.entries(scenario.headers || {})) {
806
+ if (!String(header).toLowerCase().startsWith("x-")) continue;
807
+ take(header, value, success);
808
+ }
809
+ }
810
+ }
811
+ }
812
+ return byHeader;
813
+ };
814
+
815
+ const defaultHeaderValues = collectDefaultHeaderValues();
816
+
817
+ const buildDefaultStore = () => {
818
+ const schemes = (spec.components && spec.components.securitySchemes) || {};
819
+ const variables = [{ key: "baseUrl", value: defaultBaseUrl }];
820
+ const varKeys = new Set(["baseUrl"]);
821
+ const headerGroups = {};
822
+ for (const [schemeId, scheme] of Object.entries(schemes)) {
823
+ if (!scheme || scheme.in !== "header" || !scheme.name) continue;
824
+ const header = scheme.name;
825
+ const varName = varNameFromHeader(header);
826
+ if (!varKeys.has(varName)) {
827
+ const seeded = defaultHeaderValues[String(header).toLowerCase()] || "";
828
+ variables.push({ key: varName, value: seeded });
829
+ varKeys.add(varName);
830
+ }
831
+ headerGroups[schemeId] = [
832
+ { key: header, value: "{{" + varName + "}}" },
833
+ { key: "content-type", value: "application/json" },
834
+ ];
835
+ }
836
+ const groupNames = Object.keys(headerGroups);
837
+ if (!groupNames.length) headerGroups.default = [{ key: "content-type", value: "application/json" }];
838
+ return {
839
+ activeEnv: "local",
840
+ activeGroup: groupNames[0] || "default",
841
+ envs: { local: { variables, headerGroups } },
842
+ };
843
+ };
844
+
845
+ const cloneDefaultEnv = () => JSON.parse(JSON.stringify(buildDefaultStore().envs.local));
846
+
847
+ const mergeStore = (saved) => {
848
+ const defaults = buildDefaultStore();
849
+ if (!saved || !saved.envs || typeof saved.envs !== "object") return defaults;
850
+ const envs = {};
851
+ for (const [name, env] of Object.entries(saved.envs)) {
852
+ const base = cloneDefaultEnv();
853
+ const variables = Array.isArray(env.variables) ? env.variables.map((row) => ({ key: String(row.key || ""), value: String(row.value ?? "") })) : base.variables.map((row) => ({ ...row }));
854
+ const known = new Set(variables.map((row) => row.key).filter(Boolean));
855
+ for (const row of base.variables) {
856
+ if (row.key && !known.has(row.key)) variables.push({ ...row });
857
+ }
858
+ // Backfill empty env values from recorded defaults so Try-it works out of the box.
859
+ const defaultsByKey = Object.fromEntries((base.variables || []).filter((row) => row.key).map((row) => [row.key, row.value ?? ""]));
860
+ for (const row of variables) {
861
+ if (!row.key) continue;
862
+ if (String(row.value ?? "").trim()) continue;
863
+ if (defaultsByKey[row.key]) row.value = defaultsByKey[row.key];
864
+ }
865
+ const headerGroups = { ...(env.headerGroups || {}) };
866
+ for (const [group, rows] of Object.entries(base.headerGroups)) {
867
+ if (!headerGroups[group]) headerGroups[group] = rows.map((row) => ({ ...row }));
868
+ }
869
+ if (!Object.keys(headerGroups).length) headerGroups.default = [{ key: "content-type", value: "application/json" }];
870
+ envs[name] = { variables, headerGroups };
871
+ }
872
+ if (!Object.keys(envs).length) return defaults;
873
+ const activeEnv = envs[saved.activeEnv] ? saved.activeEnv : Object.keys(envs)[0];
874
+ const groups = Object.keys(envs[activeEnv].headerGroups || {});
875
+ const activeGroup = groups.includes(saved.activeGroup) ? saved.activeGroup : groups[0] || "default";
876
+ return { activeEnv, activeGroup, envs };
877
+ };
878
+
879
+ const loadStore = () => {
880
+ try {
881
+ const raw = localStorage.getItem(STORE_KEY);
882
+ if (raw) return mergeStore(JSON.parse(raw));
883
+ } catch {}
884
+ return buildDefaultStore();
885
+ };
886
+
887
+ const applyServingBaseUrl = (state) => {
888
+ if (!locationBaseUrl || !state || !state.envs) return state;
889
+ for (const env of Object.values(state.envs)) {
890
+ const variables = env.variables || (env.variables = []);
891
+ const row = variables.find((entry) => entry.key === "baseUrl");
892
+ if (row) row.value = locationBaseUrl;
893
+ else variables.unshift({ key: "baseUrl", value: locationBaseUrl });
894
+ }
895
+ return state;
896
+ };
897
+
898
+ let store = applyServingBaseUrl(loadStore());
899
+
900
+ const persistStore = () => {
901
+ try {
902
+ localStorage.setItem(STORE_KEY, JSON.stringify(store));
903
+ } catch {}
904
+ };
905
+
906
+ const activeEnvConfig = () => store.envs[store.activeEnv] || store.envs[Object.keys(store.envs)[0]];
907
+
908
+ const varMap = () => {
909
+ const env = activeEnvConfig();
910
+ return Object.fromEntries((env.variables || []).filter((row) => row.key).map((row) => [row.key, row.value ?? ""]));
911
+ };
912
+
913
+ const interpolate = (value, vars, depth = 0) => {
914
+ if (value == null || depth > 8) return value;
915
+ if (typeof value === "object") {
916
+ if (Array.isArray(value)) return value.map((item) => interpolate(item, vars, depth));
917
+ return Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, interpolate(nested, vars, depth)]));
918
+ }
919
+ if (typeof value !== "string") return value;
920
+ return value.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_, key) => (key in vars ? String(interpolate(vars[key], vars, depth + 1)) : "{{" + key + "}}"));
921
+ };
922
+
923
+ const resolvedHeadersFromGroup = (groupName) => {
924
+ const env = activeEnvConfig();
925
+ const groups = env.headerGroups || {};
926
+ const group = groups[groupName] || groups[Object.keys(groups)[0]] || [];
927
+ const vars = varMap();
928
+ return Object.fromEntries(group.filter((row) => row.key).map((row) => [row.key, String(interpolate(row.value || "", vars))]));
929
+ };
930
+
931
+ const resolvedHeaders = () => resolvedHeadersFromGroup(store.activeGroup);
932
+
933
+ /** OpenAPI security requirement scheme ids for an operation (AND). */
934
+ const securitySchemeIds = (op) => {
935
+ const requirements = (op && op.security) || spec.security || [];
936
+ if (!Array.isArray(requirements) || !requirements.length) return [];
937
+ const ids = [];
938
+ for (const requirement of requirements) {
939
+ if (!requirement || typeof requirement !== "object") continue;
940
+ for (const id of Object.keys(requirement)) ids.push(id);
941
+ }
942
+ return [...new Set(ids)];
943
+ };
944
+
945
+ const headerGroupLabelForOp = (op) => {
946
+ const ids = securitySchemeIds(op);
947
+ if (!ids.length) return store.activeGroup || "default";
948
+ return ids.join(" + ");
949
+ };
950
+
951
+ const headersBadgeForOp = (op) => store.activeEnv + " · " + headerGroupLabelForOp(op);
952
+
953
+ /** Merge header rows from every security scheme this operation needs. */
954
+ const resolvedHeadersForOp = (op) => {
955
+ const ids = securitySchemeIds(op);
956
+ if (!ids.length) return resolvedHeaders();
957
+ const env = activeEnvConfig();
958
+ const groups = env.headerGroups || {};
959
+ const vars = varMap();
960
+ const merged = {};
961
+ for (const id of ids) {
962
+ const rows = groups[id] || [];
963
+ for (const row of rows) {
964
+ if (!row.key) continue;
965
+ merged[row.key] = String(interpolate(row.value || "", vars));
966
+ }
967
+ }
968
+ if (!Object.keys(merged).length) return resolvedHeaders();
969
+ return merged;
970
+ };
971
+
972
+ const syncHeaderGroupForOp = (op) => {
973
+ const ids = securitySchemeIds(op);
974
+ const groups = (activeEnvConfig().headerGroups) || {};
975
+ if (ids.length === 1 && groups[ids[0]]) {
976
+ if (store.activeGroup !== ids[0]) {
977
+ store.activeGroup = ids[0];
978
+ persistStore();
979
+ syncEnvTrigger();
980
+ if (document.getElementById("env-wrap")?.classList.contains("open")) renderEnvPop();
981
+ }
982
+ }
983
+ };
984
+
985
+ const currentBaseUrl = () => String(interpolate(varMap().baseUrl || defaultBaseUrl, varMap()) || defaultBaseUrl).replace(/\/$/, "");
986
+
987
+ const envLabel = () => store.activeEnv + " · " + store.activeGroup;
988
+
989
+ const syncEnvTrigger = () => {
990
+ const trigger = document.getElementById("env-trigger");
991
+ if (trigger) trigger.textContent = envLabel();
992
+ };
993
+
994
+ const renderEnvPop = () => {
995
+ const env = activeEnvConfig();
996
+ const envNames = Object.keys(store.envs);
997
+ const groups = Object.keys(env.headerGroups || {});
998
+ if (!groups.includes(store.activeGroup)) store.activeGroup = groups[0] || "default";
999
+ const groupRows = env.headerGroups[store.activeGroup] || [];
1000
+ const canRemoveEnv = envNames.length > 1;
1001
+ const canRemoveGroup = groups.length > 1;
1002
+
1003
+ document.getElementById("env-pop").innerHTML = `
1004
+ <div class="env-block">
1005
+ <div class="env-label">Env</div>
1006
+ <div class="chip-row">
1007
+ ${envNames
1008
+ .map((id) => `<button type="button" class="chip-btn ${id === store.activeEnv ? "on" : ""}" data-env="${escapeAttr(id)}">${escapeAttr(id)}</button>`)
1009
+ .join("")}
1010
+ <button type="button" class="ghost-btn" id="add-env" title="Add env">+</button>
1011
+ <button type="button" class="ghost-btn" id="remove-env" title="Remove env" ${canRemoveEnv ? "" : "disabled"}>Ă—</button>
1012
+ </div>
1013
+ </div>
1014
+ <div class="env-block">
1015
+ <div class="env-label">Variables</div>
1016
+ ${(env.variables || [])
1017
+ .map(
1018
+ (row, index) => `<div class="env-kv" data-var="${index}">
1019
+ <input class="env-cell" data-field="key" spellcheck="false" value="${escapeAttr(row.key)}" />
1020
+ <input class="env-cell" data-field="value" spellcheck="false" value="${escapeAttr(row.value)}" />
1021
+ <button type="button" class="ghost-btn" data-remove-var="${index}">Ă—</button>
1022
+ </div>`,
1023
+ )
1024
+ .join("")}
1025
+ <button type="button" class="btn env-add" id="add-var">Add variable</button>
1026
+ </div>
1027
+ <div class="env-block">
1028
+ <div class="env-label">Header group</div>
1029
+ <div class="chip-row">
1030
+ ${groups
1031
+ .map((group) => `<button type="button" class="chip-btn ${group === store.activeGroup ? "on" : ""}" data-group="${escapeAttr(group)}">${escapeAttr(group)}</button>`)
1032
+ .join("")}
1033
+ <button type="button" class="ghost-btn" id="add-group" title="Add header group">+</button>
1034
+ <button type="button" class="ghost-btn" id="remove-group" title="Remove header group" ${canRemoveGroup ? "" : "disabled"}>Ă—</button>
1035
+ </div>
1036
+ ${groupRows
1037
+ .map(
1038
+ (row, index) => `<div class="env-kv" data-hdr="${index}">
1039
+ <input class="env-cell" data-field="key" spellcheck="false" value="${escapeAttr(row.key)}" />
1040
+ <input class="env-cell" data-field="value" spellcheck="false" value="${escapeAttr(row.value)}" />
1041
+ <button type="button" class="ghost-btn" data-remove-hdr="${index}">Ă—</button>
1042
+ </div>`,
1043
+ )
1044
+ .join("")}
1045
+ <button type="button" class="btn env-add" id="add-hdr">Add header</button>
1046
+ </div>
1047
+ `;
1048
+
1049
+ syncEnvTrigger();
1050
+
1051
+ document.getElementById("env-pop").querySelectorAll("[data-env]").forEach((button) => {
1052
+ button.onclick = (event) => {
1053
+ event.stopPropagation();
1054
+ store.activeEnv = button.dataset.env;
1055
+ const nextGroups = Object.keys(activeEnvConfig().headerGroups || {});
1056
+ if (!nextGroups.includes(store.activeGroup)) store.activeGroup = nextGroups[0] || "default";
1057
+ persistStore();
1058
+ renderEnvPop();
1059
+ renderMain();
1060
+ };
1061
+ });
1062
+ document.getElementById("add-env").onclick = (event) => {
1063
+ event.stopPropagation();
1064
+ let name = "env";
1065
+ let n = 1;
1066
+ while (store.envs[name + n]) n += 1;
1067
+ name = name + n;
1068
+ store.envs[name] = cloneDefaultEnv();
1069
+ store.activeEnv = name;
1070
+ store.activeGroup = Object.keys(store.envs[name].headerGroups)[0] || "default";
1071
+ persistStore();
1072
+ renderEnvPop();
1073
+ renderMain();
1074
+ };
1075
+ document.getElementById("remove-env").onclick = (event) => {
1076
+ event.stopPropagation();
1077
+ const names = Object.keys(store.envs);
1078
+ if (names.length <= 1 || !store.envs[store.activeEnv]) return;
1079
+ delete store.envs[store.activeEnv];
1080
+ store.activeEnv = Object.keys(store.envs)[0];
1081
+ const nextGroups = Object.keys(activeEnvConfig().headerGroups || {});
1082
+ store.activeGroup = nextGroups.includes(store.activeGroup) ? store.activeGroup : nextGroups[0] || "default";
1083
+ persistStore();
1084
+ renderEnvPop();
1085
+ renderMain();
1086
+ };
1087
+ document.getElementById("env-pop").querySelectorAll("[data-group]").forEach((button) => {
1088
+ button.onclick = (event) => {
1089
+ event.stopPropagation();
1090
+ store.activeGroup = button.dataset.group;
1091
+ persistStore();
1092
+ renderEnvPop();
1093
+ renderMain();
1094
+ };
1095
+ });
1096
+ document.getElementById("add-group").onclick = (event) => {
1097
+ event.stopPropagation();
1098
+ let name = "group";
1099
+ let n = 1;
1100
+ const groupsMap = activeEnvConfig().headerGroups;
1101
+ while (groupsMap[name + n]) n += 1;
1102
+ name = name + n;
1103
+ groupsMap[name] = [{ key: "content-type", value: "application/json" }];
1104
+ store.activeGroup = name;
1105
+ persistStore();
1106
+ renderEnvPop();
1107
+ renderMain();
1108
+ };
1109
+ document.getElementById("remove-group").onclick = (event) => {
1110
+ event.stopPropagation();
1111
+ const groupsMap = activeEnvConfig().headerGroups;
1112
+ const names = Object.keys(groupsMap || {});
1113
+ if (names.length <= 1 || !groupsMap[store.activeGroup]) return;
1114
+ delete groupsMap[store.activeGroup];
1115
+ store.activeGroup = Object.keys(groupsMap)[0] || "default";
1116
+ persistStore();
1117
+ renderEnvPop();
1118
+ renderMain();
1119
+ };
1120
+ document.getElementById("env-pop").querySelectorAll("[data-var]").forEach((row) => {
1121
+ row.querySelectorAll("input").forEach((input) => {
1122
+ input.oninput = () => {
1123
+ const index = Number(row.dataset.var);
1124
+ const field = input.dataset.field;
1125
+ if (!activeEnvConfig().variables[index] || (field !== "key" && field !== "value")) return;
1126
+ activeEnvConfig().variables[index][field] = input.value;
1127
+ persistStore();
1128
+ syncEnvTrigger();
1129
+ if (field === "value" && activeEnvConfig().variables[index].key === "baseUrl") renderMain();
1130
+ };
1131
+ input.onchange = () => renderMain();
1132
+ });
1133
+ });
1134
+ document.getElementById("env-pop").querySelectorAll("[data-remove-var]").forEach((button) => {
1135
+ button.onclick = (event) => {
1136
+ event.stopPropagation();
1137
+ activeEnvConfig().variables.splice(Number(button.dataset.removeVar), 1);
1138
+ persistStore();
1139
+ renderEnvPop();
1140
+ renderMain();
1141
+ };
1142
+ });
1143
+ document.getElementById("add-var").onclick = (event) => {
1144
+ event.stopPropagation();
1145
+ activeEnvConfig().variables.push({ key: "", value: "" });
1146
+ persistStore();
1147
+ renderEnvPop();
1148
+ };
1149
+ document.getElementById("env-pop").querySelectorAll("[data-hdr]").forEach((row) => {
1150
+ row.querySelectorAll("input").forEach((input) => {
1151
+ input.oninput = () => {
1152
+ const index = Number(row.dataset.hdr);
1153
+ const field = input.dataset.field;
1154
+ const rows = activeEnvConfig().headerGroups[store.activeGroup] || [];
1155
+ if (!rows[index] || (field !== "key" && field !== "value")) return;
1156
+ rows[index][field] = input.value;
1157
+ persistStore();
1158
+ };
1159
+ input.onchange = () => renderMain();
1160
+ });
1161
+ });
1162
+ document.getElementById("env-pop").querySelectorAll("[data-remove-hdr]").forEach((button) => {
1163
+ button.onclick = (event) => {
1164
+ event.stopPropagation();
1165
+ (activeEnvConfig().headerGroups[store.activeGroup] || []).splice(Number(button.dataset.removeHdr), 1);
1166
+ persistStore();
1167
+ renderEnvPop();
1168
+ renderMain();
1169
+ };
1170
+ });
1171
+ document.getElementById("add-hdr").onclick = (event) => {
1172
+ event.stopPropagation();
1173
+ const groupsMap = activeEnvConfig().headerGroups;
1174
+ groupsMap[store.activeGroup] = groupsMap[store.activeGroup] || [];
1175
+ groupsMap[store.activeGroup].push({ key: "", value: "" });
1176
+ persistStore();
1177
+ renderEnvPop();
1178
+ };
1179
+ };
1180
+
1181
+ document.title = "DAxTA";
1182
+ const workspaceEl = document.getElementById("workspace");
1183
+ if (workspace) {
1184
+ workspaceEl.textContent = workspace;
1185
+ workspaceEl.hidden = false;
1186
+ } else {
1187
+ workspaceEl.hidden = true;
1188
+ }
1189
+ document.getElementById("brand").textContent = title;
1190
+
1191
+ const envWrap = document.getElementById("env-wrap");
1192
+ document.getElementById("env-trigger").addEventListener("click", (event) => {
1193
+ event.stopPropagation();
1194
+ envWrap.classList.toggle("open");
1195
+ if (envWrap.classList.contains("open")) renderEnvPop();
1196
+ });
1197
+ document.getElementById("env-pop").addEventListener("click", (event) => event.stopPropagation());
1198
+ renderEnvPop();
1199
+
1200
+ const VIEWER_EXTENSIONS = new Set(["x-viewer", "x-docs", "x-scenarios", "x-tree-segments", "x-workspace"]);
1201
+
1202
+ const toExportSpec = (source) => {
1203
+ const walk = (value) => {
1204
+ if (Array.isArray(value)) return value.map(walk);
1205
+ if (!value || typeof value !== "object") return value;
1206
+ const out = {};
1207
+ for (const [key, child] of Object.entries(value)) {
1208
+ if (VIEWER_EXTENSIONS.has(key)) continue;
1209
+ out[key] = walk(child);
1210
+ }
1211
+ return out;
1212
+ };
1213
+ const exported = walk(source);
1214
+ exported.openapi = exported.openapi || "3.0.3";
1215
+ if (!exported.info) exported.info = { title: title, version: "0.0.0" };
1216
+ if (!exported.paths) exported.paths = {};
1217
+ return exported;
1218
+ };
1219
+
1220
+ const downloadOpenApi = () => {
1221
+ const exported = toExportSpec(spec);
1222
+ const blob = new Blob([JSON.stringify(exported, null, 2) + "\n"], { type: "application/json" });
1223
+ const url = URL.createObjectURL(blob);
1224
+ const link = document.createElement("a");
1225
+ const safeName = String(workspace || title || "openapi")
1226
+ .toLowerCase()
1227
+ .replace(/[^a-z0-9]+/g, "-")
1228
+ .replace(/^-|-$/g, "") || "openapi";
1229
+ link.href = url;
1230
+ link.download = safeName + ".openapi.json";
1231
+ document.body.appendChild(link);
1232
+ link.click();
1233
+ link.remove();
1234
+ URL.revokeObjectURL(url);
1235
+ };
1236
+
1237
+ document.getElementById("export-openapi").addEventListener("click", downloadOpenApi);
1238
+
1239
+ const HTTP = ["get", "post", "put", "patch", "delete"];
1240
+ const STATUS = { 200: "OK", 201: "Created", 204: "No Content", 400: "Bad Request", 401: "Unauthorized", 404: "Not Found", 409: "Conflict", 422: "Unprocessable Entity" };
1241
+ const GROUP_ORDER = ["Success", "Business errors", "Invalid input", "Missing fields", "Auth", "Other"];
1242
+ const METHOD_ORDER = { get: 0, post: 1, put: 2, patch: 3, delete: 4 };
1243
+
1244
+ const ops = [];
1245
+ for (const [path, item] of Object.entries(spec.paths || {})) {
1246
+ for (const method of HTTP) {
1247
+ if (!item[method]) continue;
1248
+ ops.push({
1249
+ id: method + ":" + path,
1250
+ method,
1251
+ path,
1252
+ op: item[method],
1253
+ title: item[method].summary || path,
1254
+ docs: item[method]["x-docs"] || { fields: [] },
1255
+ scenarios: item[method]["x-scenarios"] || [],
1256
+ treeSegments: item[method]["x-tree-segments"] || path.split("/").filter(Boolean),
1257
+ });
1258
+ }
1259
+ }
1260
+
1261
+ const highlight = (value) => {
1262
+ if (value === undefined || value === null || value === "") return "";
1263
+ return JSON.stringify(value, null, 2)
1264
+ .replace(/&/g, "&amp;")
1265
+ .replace(/</g, "&lt;")
1266
+ .replace(/"([^"]+)":/g, '<span class="k">"$1"</span>:')
1267
+ .replace(/: "([^"]*)"/g, ': <span class="s">"$1"</span>')
1268
+ .replace(/: (-?\d+(?:\.\d+)?)/g, ': <span class="n">$1</span>')
1269
+ .replace(/: (true|false|null)/g, ': <span class="p">$1</span>');
1270
+ };
1271
+
1272
+ const copyBodyText = (value) => {
1273
+ if (value === undefined || value === "") return null;
1274
+ if (typeof value === "string") return value;
1275
+ return JSON.stringify(value, null, 2);
1276
+ };
1277
+
1278
+ const copyIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`;
1279
+
1280
+ const showToast = (message) => {
1281
+ let toast = document.getElementById("toast");
1282
+ if (!toast) {
1283
+ toast = document.createElement("div");
1284
+ toast.id = "toast";
1285
+ toast.className = "toast";
1286
+ document.body.appendChild(toast);
1287
+ }
1288
+ toast.textContent = message;
1289
+ toast.classList.add("show");
1290
+ clearTimeout(showToast._timer);
1291
+ showToast._timer = setTimeout(() => toast.classList.remove("show"), 1400);
1292
+ };
1293
+
1294
+ const copy = async (text, button, label) => {
1295
+ try {
1296
+ await navigator.clipboard.writeText(text);
1297
+ if (button && button.classList.contains("icon")) {
1298
+ showToast("Kopyalandı");
1299
+ return;
1300
+ }
1301
+ const previous = button.textContent;
1302
+ button.textContent = "Copied";
1303
+ setTimeout(() => (button.textContent = label || previous), 1200);
1304
+ } catch {}
1305
+ };
1306
+
1307
+ const resolvedUrl = (item, scenario) => {
1308
+ const vars = varMap();
1309
+ let path = item.path;
1310
+ for (const [name, value] of Object.entries(scenario.pathParams || {})) {
1311
+ const fromVar = vars[name] ? String(interpolate(vars[name], vars)) : value;
1312
+ path = path.replace("{" + name + "}", encodeURIComponent(fromVar ?? ""));
1313
+ }
1314
+ const query = { ...(scenario.query || {}) };
1315
+ for (const key of Object.keys(query)) {
1316
+ if (vars[key]) query[key] = String(interpolate(vars[key], vars));
1317
+ }
1318
+ const qs = new URLSearchParams(query).toString();
1319
+ return currentBaseUrl() + path + (qs ? "?" + qs : "");
1320
+ };
1321
+
1322
+ const toCurl = (item, scenario) => {
1323
+ const headers = resolvedHeadersForOp(item.op);
1324
+ const body = scenario.reqBody !== undefined ? interpolate(scenario.reqBody, varMap()) : undefined;
1325
+ const lines = ["curl -X " + item.method.toUpperCase() + " '" + resolvedUrl(item, scenario).replace(/'/g, "'\\''") + "'"];
1326
+ for (const [name, value] of Object.entries(headers)) {
1327
+ lines.push(" -H '" + name + ": " + String(value).replace(/'/g, "'\\''") + "'");
1328
+ }
1329
+ if (body !== undefined && item.method !== "get") {
1330
+ lines.push(" -d '" + JSON.stringify(body, null, 2).replace(/'/g, "'\\''") + "'");
1331
+ }
1332
+ return lines.join(" \\\n");
1333
+ };
1334
+
1335
+ const proxyUrl = (target) => {
1336
+ try {
1337
+ const absolute = new URL(target, location.href);
1338
+ if (absolute.origin === location.origin) return absolute.href;
1339
+ } catch {}
1340
+ if (location.protocol === "http:" || location.protocol === "https:") {
1341
+ return "/__proxy?target=" + encodeURIComponent(target);
1342
+ }
1343
+ return target;
1344
+ };
1345
+
1346
+ const sendRequest = async (item, scenario) => {
1347
+ const target = resolvedUrl(item, scenario);
1348
+ const headers = { ...resolvedHeadersForOp(item.op) };
1349
+ const body = scenario.reqBody !== undefined ? interpolate(scenario.reqBody, varMap()) : undefined;
1350
+ if (body !== undefined && !headers["content-type"] && !headers["Content-Type"]) {
1351
+ headers["content-type"] = "application/json";
1352
+ }
1353
+ const init = {
1354
+ method: item.method.toUpperCase(),
1355
+ headers,
1356
+ };
1357
+ if (body !== undefined && item.method !== "get" && item.method !== "head") {
1358
+ init.body = typeof body === "string" ? body : JSON.stringify(body);
1359
+ }
1360
+ const response = await fetch(proxyUrl(target), init);
1361
+ const text = await response.text();
1362
+ let parsed = text;
1363
+ try {
1364
+ parsed = text ? JSON.parse(text) : undefined;
1365
+ } catch {
1366
+ parsed = text;
1367
+ }
1368
+ return { status: response.status, body: parsed, ok: response.ok };
1369
+ };
1370
+
1371
+ const groupedDropdown = (scenarios, selected) => {
1372
+ const groups = {};
1373
+ scenarios.forEach((scenario, index) => {
1374
+ (groups[scenario.group] ||= []).push({ scenario, index });
1375
+ });
1376
+ const order = GROUP_ORDER.filter((name) => groups[name]).concat(Object.keys(groups).filter((name) => !GROUP_ORDER.includes(name)));
1377
+ const current = scenarios[selected];
1378
+ const label = current ? current.group + " · " + current.name : "Recorded call";
1379
+ return `<div class="dd" id="scenario-dd">
1380
+ <button type="button" class="dd-toggle" id="scenario-toggle">${label}</button>
1381
+ <div class="dd-menu">${order
1382
+ .map(
1383
+ (group) =>
1384
+ `<div class="dd-group">${group}</div>` +
1385
+ groups[group]
1386
+ .map(({ scenario, index }) => `<button type="button" class="dd-item ${index === selected ? "on" : ""}" data-index="${index}">${scenario.status} — ${scenario.name}</button>`)
1387
+ .join(""),
1388
+ )
1389
+ .join("")}</div>
1390
+ </div>`;
1391
+ };
1392
+
1393
+ let currentId = ops[0]?.id;
1394
+ let scenarioIndex = 0;
1395
+ const treePathSegments = (item) => item.treeSegments || item.path.split("/").filter(Boolean);
1396
+ const expandedFolders = new Set(
1397
+ [...new Set(ops.map((item) => treePathSegments(item)[0]).filter(Boolean))].map((version) => "/" + version),
1398
+ );
1399
+
1400
+ const kv = (label, value) => {
1401
+ if (value === undefined || value === "") return "";
1402
+ const shown = typeof value === "object" ? JSON.stringify(value) : String(value);
1403
+ return `<div class="kv" title="${escapeAttr(label)}: ${escapeAttr(shown)}"><div class="kname">${label}</div><div class="kval">${shown}</div></div>`;
1404
+ };
1405
+
1406
+ const metaBlock = (title, bodyHtml, source = "", { always = false } = {}) => {
1407
+ if (!always && !bodyHtml) return "";
1408
+ return `<div class="meta-block">
1409
+ <div class="meta-toolbar">
1410
+ <span class="meta-label">${title}</span>
1411
+ ${source ? `<span class="meta-source">${source}</span>` : ""}
1412
+ </div>
1413
+ ${bodyHtml || `<div class="meta-empty">—</div>`}
1414
+ </div>`;
1415
+ };
1416
+
1417
+ const buildPathTree = (items) => {
1418
+ const root = { children: {}, ops: [] };
1419
+ for (const item of items) {
1420
+ const parts = treePathSegments(item);
1421
+ let node = root;
1422
+ for (let index = 0; index < parts.length; index += 1) {
1423
+ const part = parts[index];
1424
+ node.children[part] ??= { children: {}, ops: [] };
1425
+ node = node.children[part];
1426
+ if (index === parts.length - 1) node.ops.push(item);
1427
+ }
1428
+ }
1429
+ return root;
1430
+ };
1431
+
1432
+ const expandPathToItem = (item) => {
1433
+ const parts = treePathSegments(item);
1434
+ let prefix = "";
1435
+ for (const part of parts) {
1436
+ prefix += "/" + part;
1437
+ expandedFolders.add(prefix);
1438
+ }
1439
+ };
1440
+
1441
+ const collectVisibleItems = (node) => {
1442
+ const items = [...node.ops];
1443
+ for (const child of Object.values(node.children)) items.push(...collectVisibleItems(child));
1444
+ return items;
1445
+ };
1446
+
1447
+ const renderTreeNode = (node, prefix = "", q = "") => {
1448
+ const opsHtml = [...node.ops]
1449
+ .sort((left, right) => (METHOD_ORDER[left.method] ?? 99) - (METHOD_ORDER[right.method] ?? 99))
1450
+ .map(
1451
+ (item) =>
1452
+ `<button class="nav-item ${item.id === currentId ? "active" : ""}" data-id="${item.id}" title="${item.path}">
1453
+ <span class="method ${item.method}">${item.method}</span>
1454
+ <span class="nav-title">${item.title}</span>
1455
+ </button>`,
1456
+ )
1457
+ .join("");
1458
+
1459
+ const foldersHtml = Object.entries(node.children)
1460
+ .sort(([left], [right]) => left.localeCompare(right))
1461
+ .map(([name, child]) => {
1462
+ const folderPath = (prefix ? prefix + "/" : "/") + name;
1463
+ const subtreeItems = collectVisibleItems(child);
1464
+ if (q && !subtreeItems.some((item) => (item.method + " " + item.path + " " + item.title).toLowerCase().includes(q))) return "";
1465
+ const open = q ? true : expandedFolders.has(folderPath);
1466
+ return `<div class="tree-folder ${open ? "open" : ""}" data-folder="${folderPath}">
1467
+ <button type="button" class="tree-folder-toggle" data-folder="${folderPath}">
1468
+ <span class="chev"></span>
1469
+ <span class="tree-folder-name">${name}</span>
1470
+ </button>
1471
+ <div class="tree-children">${renderTreeNode(child, folderPath, q)}</div>
1472
+ </div>`;
1473
+ })
1474
+ .join("");
1475
+
1476
+ return opsHtml + foldersHtml;
1477
+ };
1478
+
1479
+ const renderNav = () => {
1480
+ const nav = document.getElementById("nav");
1481
+ if (!ops.length) {
1482
+ nav.innerHTML = `<div class="tree-empty">No endpoints recorded</div>`;
1483
+ return;
1484
+ }
1485
+ if (currentId) {
1486
+ const active = ops.find((item) => item.id === currentId);
1487
+ if (active) expandPathToItem(active);
1488
+ }
1489
+ nav.innerHTML = `<div class="tree-root">${renderTreeNode(buildPathTree(ops), "", "")}</div>`;
1490
+ nav.querySelectorAll(".nav-item").forEach((button) => {
1491
+ button.onclick = () => select(button.dataset.id);
1492
+ });
1493
+ nav.querySelectorAll(".tree-folder-toggle").forEach((button) => {
1494
+ button.onclick = (event) => {
1495
+ event.stopPropagation();
1496
+ const folderPath = button.dataset.folder;
1497
+ const folder = button.closest(".tree-folder");
1498
+ if (expandedFolders.has(folderPath)) {
1499
+ expandedFolders.delete(folderPath);
1500
+ folder.classList.remove("open");
1501
+ } else {
1502
+ expandedFolders.add(folderPath);
1503
+ folder.classList.add("open");
1504
+ }
1505
+ };
1506
+ });
1507
+ };
1508
+
1509
+ const escapeHtml = (value) =>
1510
+ String(value ?? "")
1511
+ .replace(/&/g, "&amp;")
1512
+ .replace(/</g, "&lt;")
1513
+ .replace(/>/g, "&gt;")
1514
+ .replace(/"/g, "&quot;");
1515
+
1516
+ const highlightMatch = (text, query) => {
1517
+ const raw = String(text ?? "");
1518
+ const q = query.trim();
1519
+ if (!q) return escapeHtml(raw);
1520
+ const lower = raw.toLowerCase();
1521
+ const index = lower.indexOf(q.toLowerCase());
1522
+ if (index < 0) return escapeHtml(raw);
1523
+ return (
1524
+ escapeHtml(raw.slice(0, index)) +
1525
+ "<mark>" +
1526
+ escapeHtml(raw.slice(index, index + q.length)) +
1527
+ "</mark>" +
1528
+ escapeHtml(raw.slice(index + q.length))
1529
+ );
1530
+ };
1531
+
1532
+ let searchActiveIndex = 0;
1533
+
1534
+ const closeSearch = ({ clear = false } = {}) => {
1535
+ const wrap = document.getElementById("search-wrap");
1536
+ const input = document.getElementById("search");
1537
+ wrap.classList.remove("open");
1538
+ document.body.classList.remove("searching");
1539
+ searchActiveIndex = 0;
1540
+ if (clear) input.value = "";
1541
+ };
1542
+
1543
+ const openSearch = () => {
1544
+ document.getElementById("search-wrap").classList.add("open");
1545
+ document.body.classList.add("searching");
1546
+ };
1547
+
1548
+ const renderSearchPanel = (query = "") => {
1549
+ const q = query.trim().toLowerCase();
1550
+ const panel = document.getElementById("search-panel");
1551
+ if (!q) {
1552
+ closeSearch();
1553
+ panel.innerHTML = "";
1554
+ return;
1555
+ }
1556
+ openSearch();
1557
+ const matches = ops.filter((item) => (item.method + " " + item.path + " " + item.title).toLowerCase().includes(q));
1558
+ if (!matches.length) {
1559
+ panel.innerHTML = `<div class="search-empty">No matching endpoints</div>`;
1560
+ return;
1561
+ }
1562
+ if (searchActiveIndex >= matches.length) searchActiveIndex = 0;
1563
+ panel.innerHTML = matches
1564
+ .map(
1565
+ (item, index) => `<button type="button" class="search-hit ${index === searchActiveIndex ? "active" : ""}" data-id="${item.id}" role="option">
1566
+ <span class="method ${item.method}">${item.method}</span>
1567
+ <span class="search-hit-path">${highlightMatch(item.path, q)}</span>
1568
+ </button>`,
1569
+ )
1570
+ .join("");
1571
+ panel.querySelectorAll(".search-hit").forEach((button) => {
1572
+ button.onclick = (event) => {
1573
+ event.stopPropagation();
1574
+ select(button.dataset.id);
1575
+ closeSearch({ clear: true });
1576
+ };
1577
+ });
1578
+ };
1579
+
1580
+ const FIELD_SECTIONS = [
1581
+ { key: "header", title: "Headers" },
1582
+ { key: "path", title: "Path" },
1583
+ { key: "query", title: "Query" },
1584
+ { key: "body", title: "Body" },
1585
+ ];
1586
+
1587
+ const fieldDepth = (name) => {
1588
+ const parts = String(name || "")
1589
+ .replace(/\[\]/g, ".")
1590
+ .split(".")
1591
+ .filter(Boolean);
1592
+ return Math.max(0, parts.length - 1);
1593
+ };
1594
+
1595
+ const rows = (fields) => {
1596
+ if (!fields.length) return "";
1597
+ return fields
1598
+ .map((field) => {
1599
+ const depth = field.in === "body" ? fieldDepth(field.name) : 0;
1600
+ const pad = depth ? ` style="padding-left:${depth * 14}px"` : "";
1601
+ const nestClass = depth ? " nested" : "";
1602
+ return `<div class="row">
1603
+ <div class="name${nestClass}"${pad}>${field.name}</div>
1604
+ <div class="type">${field.in}</div>
1605
+ <div>
1606
+ <div class="type">${field.type}</div>
1607
+ ${field.required === true ? `<div class="flag req">Required</div>` : field.required === false ? `<div class="flag">Optional</div>` : ""}
1608
+ </div>
1609
+ </div>`;
1610
+ })
1611
+ .join("");
1612
+ };
1613
+
1614
+ const fieldsPanel = (fields) => {
1615
+ if (!fields.length) return "";
1616
+ const sections = FIELD_SECTIONS.map(({ key, title }) => {
1617
+ const group = fields.filter((field) => field.in === key);
1618
+ if (!group.length) return "";
1619
+ return `<div class="fields-section">
1620
+ <div class="fields-section-title">${title}</div>
1621
+ ${rows(group)}
1622
+ </div>`;
1623
+ }).join("");
1624
+ if (!sections) return "";
1625
+ return `<section class="fields"><h2>Fields</h2>${sections}</section>`;
1626
+ };
1627
+
1628
+ const renderMain = () => {
1629
+ const item = ops.find((entry) => entry.id === currentId);
1630
+ if (!item) {
1631
+ document.getElementById("main").innerHTML = `<div class="empty">No operations in this workspace yet. Run integration tests to generate docs.</div>`;
1632
+ return;
1633
+ }
1634
+ if (scenarioIndex >= item.scenarios.length) scenarioIndex = 0;
1635
+ const scenario = item.scenarios[scenarioIndex] || { status: 0, pathParams: {}, query: {}, headers: {}, name: "" };
1636
+ const fields = item.docs.fields || [];
1637
+ syncHeaderGroupForOp(item.op);
1638
+ const injectedHeaders = resolvedHeadersForOp(item.op);
1639
+ const recordedOk = scenario.status >= 200 && scenario.status < 300;
1640
+ const statusText = STATUS[scenario.status] || item.op.responses?.[String(scenario.status)]?.description || "";
1641
+ const emptyResponse = scenario.resBody === undefined || scenario.status === 204;
1642
+ const reqCopyText = scenario.reqBody !== undefined ? copyBodyText(scenario.reqBody) : null;
1643
+ const showingLive = liveResult && liveResult.id === item.id && liveResult.scenarioIndex === scenarioIndex;
1644
+ const displayStatus = showingLive ? liveResult.status : scenario.status;
1645
+ const displayBody = showingLive ? liveResult.body : scenario.resBody;
1646
+ const displayOk = showingLive ? liveResult.status >= 200 && liveResult.status < 300 : recordedOk;
1647
+ const displayStatusText = STATUS[displayStatus] || (showingLive ? "" : statusText);
1648
+ const displayEmpty = showingLive ? displayBody === undefined || displayBody === "" : emptyResponse;
1649
+ const resCopyText = displayEmpty ? null : copyBodyText(displayBody);
1650
+ const responseTitle = showingLive ? "Live response" : "Recorded response";
1651
+ const headersHtml = Object.keys(injectedHeaders).length
1652
+ ? Object.entries(injectedHeaders).map(([name, value]) => kv(name, value)).join("")
1653
+ : `<div class="meta-empty">No headers for this operation auth group - set values in the env panel.</div>`;
1654
+ const pathParamsHtml = Object.entries(scenario.pathParams || {})
1655
+ .map(([name, value]) => kv(name, value))
1656
+ .join("");
1657
+ const queryHtml = Object.entries(scenario.query || {})
1658
+ .map(([name, value]) => kv(name, value))
1659
+ .join("");
1660
+ const bodyHtml =
1661
+ scenario.reqBody !== undefined
1662
+ ? `<pre>${highlight(scenario.reqBody)}</pre>`
1663
+ : `<div class="meta-empty">No JSON body</div>`;
1664
+
1665
+ document.getElementById("main").innerHTML = `
1666
+ <div class="head-row">
1667
+ <div>
1668
+ <h1 class="title">${item.title}</h1>
1669
+ <p class="meta-line">${item.method.toUpperCase()} ${item.path}</p>
1670
+ </div>
1671
+ ${item.scenarios.length ? groupedDropdown(item.scenarios, scenarioIndex) : ""}
1672
+ </div>
1673
+ <div class="urlbar">
1674
+ <div class="url"><span class="method ${item.method}">${item.method}</span><span>${resolvedUrl(item, scenario)}</span></div>
1675
+ <button class="btn" id="copy-curl" type="button">Copy cURL</button>
1676
+ <button class="btn primary" id="send" type="button">Send</button>
1677
+ </div>
1678
+ <div class="pair">
1679
+ <section class="card" id="request-card">
1680
+ <div class="card-head">
1681
+ <h2>Request</h2>
1682
+ <div class="card-head-actions">
1683
+ <button class="btn sm icon" id="copy-req" type="button" title="Copy body" aria-label="Copy body" ${reqCopyText ? "" : "disabled"}>${copyIcon}</button>
1684
+ </div>
1685
+ </div>
1686
+ <div class="card-body">
1687
+ ${metaBlock("Headers", headersHtml, headersBadgeForOp(item.op), { always: true })}
1688
+ ${metaBlock("Path", pathParamsHtml)}
1689
+ ${metaBlock("Query", queryHtml)}
1690
+ ${metaBlock("Body", bodyHtml, "", { always: true })}
1691
+ </div>
1692
+ </section>
1693
+ <section class="card response-card" id="response-card">
1694
+ <div class="card-head">
1695
+ <h2>${responseTitle}</h2>
1696
+ <div class="card-head-actions">
1697
+ <button class="btn sm icon" id="copy-res" type="button" title="Copy body" aria-label="Copy body" ${resCopyText ? "" : "disabled"}>${copyIcon}</button>
1698
+ <span><span class="code ${displayOk ? "ok" : ""}">${displayStatus || ""}</span> <span class="code-text">${displayStatusText}</span></span>
1699
+ </div>
1700
+ </div>
1701
+ <div class="card-body" id="response-body">
1702
+ ${showingLive && liveResult.error ? `<div class="live-err">${String(liveResult.error).replace(/&/g, "&amp;").replace(/</g, "&lt;")}</div>` : displayEmpty ? `<div class="empty">Empty body</div>` : `<pre>${highlight(displayBody)}</pre>`}
1703
+ </div>
1704
+ </section>
1705
+ </div>
1706
+ ${fieldsPanel(fields)}
1707
+ `;
1708
+
1709
+ const scenarioToggle = document.getElementById("scenario-toggle");
1710
+ if (scenarioToggle) {
1711
+ const root = document.getElementById("scenario-dd");
1712
+ scenarioToggle.onclick = (event) => {
1713
+ event.stopPropagation();
1714
+ document.querySelectorAll(".dd.open").forEach((el) => {
1715
+ if (el !== root) el.classList.remove("open");
1716
+ });
1717
+ root.classList.toggle("open");
1718
+ };
1719
+ root.querySelectorAll(".dd-item").forEach((button) => {
1720
+ button.onclick = (event) => {
1721
+ event.stopPropagation();
1722
+ scenarioIndex = Number(button.dataset.index);
1723
+ liveResult = null;
1724
+ root.classList.remove("open");
1725
+ renderMain();
1726
+ };
1727
+ });
1728
+ }
1729
+
1730
+ const syncResponseHeight = () => {
1731
+ const requestCard = document.getElementById("request-card");
1732
+ const responseCard = document.getElementById("response-card");
1733
+ const responseBody = document.getElementById("response-body");
1734
+ if (!requestCard || !responseCard || !responseBody) return;
1735
+ responseCard.style.maxHeight = "";
1736
+ responseBody.style.maxHeight = "";
1737
+ const requestHeight = requestCard.offsetHeight;
1738
+ const head = responseCard.querySelector(".card-head");
1739
+ const headHeight = head ? head.offsetHeight : 0;
1740
+ const maxBody = Math.max(0, requestHeight - headHeight);
1741
+ responseCard.style.maxHeight = requestHeight + "px";
1742
+ responseBody.style.maxHeight = maxBody + "px";
1743
+ };
1744
+ syncResponseHeight();
1745
+ requestAnimationFrame(syncResponseHeight);
1746
+
1747
+ document.getElementById("copy-curl").onclick = (event) => copy(toCurl(item, scenario), event.currentTarget, "Copy cURL");
1748
+ const copyReq = document.getElementById("copy-req");
1749
+ if (copyReq && reqCopyText) copyReq.onclick = (event) => copy(reqCopyText, event.currentTarget, "Copy body");
1750
+ const copyRes = document.getElementById("copy-res");
1751
+ if (copyRes && resCopyText) copyRes.onclick = (event) => copy(resCopyText, event.currentTarget, "Copy body");
1752
+
1753
+ const sendBtn = document.getElementById("send");
1754
+ if (sendBtn) {
1755
+ sendBtn.onclick = async () => {
1756
+ sendBtn.disabled = true;
1757
+ sendBtn.textContent = "Sending…";
1758
+ try {
1759
+ const result = await sendRequest(item, scenario);
1760
+ liveResult = { id: item.id, scenarioIndex, status: result.status, body: result.body };
1761
+ } catch (error) {
1762
+ const message = error instanceof Error ? error.message : String(error);
1763
+ liveResult = {
1764
+ id: item.id,
1765
+ scenarioIndex,
1766
+ status: 0,
1767
+ body: undefined,
1768
+ error:
1769
+ message +
1770
+ "\n\nTip: open docs at the same app port: http://localhost:3000/docs",
1771
+ };
1772
+ }
1773
+ renderMain();
1774
+ };
1775
+ }
1776
+ };
1777
+
1778
+ const select = (id) => {
1779
+ currentId = id;
1780
+ scenarioIndex = 0;
1781
+ liveResult = null;
1782
+ const selected = ops.find((entry) => entry.id === id);
1783
+ if (selected) syncHeaderGroupForOp(selected.op);
1784
+ renderNav();
1785
+ renderMain();
1786
+ history.replaceState(null, "", "#" + encodeURIComponent(id));
1787
+ };
1788
+
1789
+ const searchInput = document.getElementById("search");
1790
+ searchInput.addEventListener("input", (event) => {
1791
+ searchActiveIndex = 0;
1792
+ renderSearchPanel(event.target.value);
1793
+ });
1794
+ searchInput.addEventListener("keydown", (event) => {
1795
+ const panel = document.getElementById("search-panel");
1796
+ const hits = [...panel.querySelectorAll(".search-hit")];
1797
+ if (event.key === "Escape") {
1798
+ closeSearch({ clear: true });
1799
+ searchInput.blur();
1800
+ return;
1801
+ }
1802
+ if (!hits.length) return;
1803
+ if (event.key === "ArrowDown") {
1804
+ event.preventDefault();
1805
+ searchActiveIndex = (searchActiveIndex + 1) % hits.length;
1806
+ renderSearchPanel(searchInput.value);
1807
+ document.querySelectorAll(".search-hit")[searchActiveIndex]?.scrollIntoView({ block: "nearest" });
1808
+ } else if (event.key === "ArrowUp") {
1809
+ event.preventDefault();
1810
+ searchActiveIndex = (searchActiveIndex - 1 + hits.length) % hits.length;
1811
+ renderSearchPanel(searchInput.value);
1812
+ document.querySelectorAll(".search-hit")[searchActiveIndex]?.scrollIntoView({ block: "nearest" });
1813
+ } else if (event.key === "Enter") {
1814
+ event.preventDefault();
1815
+ const target = hits[searchActiveIndex] || hits[0];
1816
+ if (target) {
1817
+ select(target.dataset.id);
1818
+ closeSearch({ clear: true });
1819
+ }
1820
+ }
1821
+ });
1822
+ document.getElementById("search-backdrop").addEventListener("click", () => closeSearch({ clear: true }));
1823
+ document.getElementById("search-wrap").addEventListener("click", (event) => event.stopPropagation());
1824
+
1825
+ document.addEventListener("click", () => {
1826
+ document.querySelectorAll(".dd.open").forEach((el) => el.classList.remove("open"));
1827
+ document.getElementById("env-wrap").classList.remove("open");
1828
+ if (document.body.classList.contains("searching")) closeSearch({ clear: true });
1829
+ });
1830
+
1831
+ const initial = decodeURIComponent(location.hash.replace(/^#/, "")) || ops[0]?.id;
1832
+ select(ops.some((item) => item.id === initial) ? initial : ops[0]?.id);
1833
+ </script>
1834
+ </body>
1835
+ </html>