-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
821 lines (783 loc) · 44 KB
/
dashboard.html
File metadata and controls
821 lines (783 loc) · 44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<title>Dashboard - InstaNode</title>
<meta name="description" content="Your provisioned databases and webhooks on instanode.dev.">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0a0a0a; color: #e0e0e0; line-height: 1.6; min-height: 100vh; }
a { color: #4af; text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 720px; margin: 0 auto; padding: 0 20px; }
nav.top { padding: 20px 0; border-bottom: 1px solid #1a1a1a; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 0.9rem; }
nav.top .brand { color: #fff; font-weight: 700; font-size: 1rem; }
nav.top .right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
nav.top .email { color: #888; font-size: 0.85rem; }
.ghost-btn { background: transparent; color: #888; border: 1px solid #222; padding: 6px 14px; border-radius: 6px; font-family: inherit; font-size: 0.82rem; cursor: pointer; transition: all 0.15s; }
.ghost-btn:hover { border-color: #4af; color: #4af; }
.banner { margin: 24px 0; padding: 18px 20px; border-radius: 10px; border: 1px solid #222; background: #111; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.banner .plan-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.banner .plan-tag { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; padding: 3px 10px; border-radius: 999px; font-weight: 700; }
.banner .plan-line { font-size: 1rem; font-weight: 600; color: #fff; }
.banner .plan-sub { font-size: 0.82rem; color: #888; margin-top: 2px; }
.banner.paid { border-color: #1d4a20; background: #0d1a0e; }
.banner.paid .plan-tag { background: #1d4a20; color: #cfe8d0; }
.banner.warn { border-color: #4a1818; background: #1a0d0d; }
.banner.warn .plan-tag { background: #4a1818; color: #f8a; }
.banner a { color: #4af; font-weight: 600; font-size: 0.9rem; }
.banner .skeleton { width: 180px; height: 14px; border-radius: 4px; background: linear-gradient(90deg,#1a1a1a,#222,#1a1a1a); background-size:200% 100%; animation: shine 1.2s linear infinite; }
@keyframes shine { 0% {background-position: 0 0} 100% {background-position: -200% 0} }
/* Free-tier upsell banner — visually richer so the upgrade path is obvious. */
.upsell { margin: 24px 0; padding: 22px 24px; border-radius: 12px; position: relative; overflow: hidden;
background: linear-gradient(135deg, rgba(74,175,255,0.08) 0%, rgba(88,105,255,0.12) 100%);
border: 1px solid rgba(74,175,255,0.3); }
.upsell::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 85% 0%, rgba(74,175,255,0.14), transparent 55%); pointer-events: none; }
.upsell-grid { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; position: relative; }
@media (max-width: 640px) { .upsell-grid { grid-template-columns: 1fr; } }
.upsell .tag { display: inline-block; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.14em; padding: 3px 10px; border-radius: 999px; font-weight: 700; background: rgba(250,190,100,0.15); color: #f5c87a; margin-bottom: 10px; }
.upsell h3 { color: #fff; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 6px; }
.upsell p { color: #b8c8d8; font-size: 0.88rem; margin: 0 0 12px; }
.upsell ul { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0; font-size: 0.82rem; color: #c8d4e0; }
.upsell ul li { position: relative; padding-left: 16px; }
.upsell ul li::before { content: '✓'; position: absolute; left: 0; color: #6bdf8e; font-weight: 700; }
.upsell-cta { text-align: right; min-width: 170px; }
@media (max-width: 640px) { .upsell-cta { text-align: left; } }
.upsell-price { font-size: 1.6rem; font-weight: 700; color: #fff; letter-spacing: -0.01em; line-height: 1; }
.upsell-price .per { font-size: 0.75rem; color: #8ca0b4; font-weight: 500; }
.upsell-annual { font-size: 0.78rem; color: #8ca0b4; margin: 4px 0 12px; }
.upsell-annual strong { color: #6bdf8e; }
.upsell-btn { display: inline-block; background: linear-gradient(135deg, #4af 0%, #58f 100%); color: #051022; font-weight: 700; padding: 10px 22px; border-radius: 8px; font-size: 0.9rem; letter-spacing: 0.01em; text-decoration: none; box-shadow: 0 4px 14px rgba(74,175,255,0.3); transition: transform 0.1s, box-shadow 0.1s; }
.upsell-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(74,175,255,0.45); text-decoration: none; }
h1 { font-size: 1.5rem; color: #fff; font-weight: 700; letter-spacing: -0.02em; margin: 24px 0 4px; }
.subtitle { color: #666; font-size: 0.85rem; margin-bottom: 20px; }
.group { margin-bottom: 28px; }
.group h2 { font-size: 0.72rem; color: #555; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 10px; }
.card { background: #111; border: 1px solid #222; border-radius: 8px; padding: 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.badge { background: #0d0d0d; border: 1px solid #222; color: #ccc; padding: 3px 10px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-family: "SF Mono", monospace; }
.badge.postgres { color: #6bf; border-color: #1a3048; }
.badge.redis { color: #f88; border-color: #4a1818; }
.badge.webhook { color: #efa; border-color: #3a3a10; }
.pill { font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; border: 1px solid #222; color: #888; background: #0d0d0d; text-transform: lowercase; }
.pill.paid { border-color: #1d4a20; color: #8ec590; background: #0d1a0e; }
.pill.anonymous { border-color: #2a2418; color: #caa46a; }
.pill.active { border-color: #1a3048; color: #6bf; }
.pill.expired, .pill.deleted { border-color: #4a1818; color: #f88; }
.meta { margin-left: auto; color: #666; font-size: 0.75rem; }
.url-row { display: flex; gap: 8px; align-items: stretch; margin-top: 4px; }
.url-row code { flex: 1; background: #0a0a0a; border: 1px solid #1a1a1a; border-radius: 6px; padding: 10px 12px; font-family: "SF Mono", "Fira Code", monospace; font-size: 0.78rem; color: #adf; overflow-x: auto; white-space: nowrap; }
.small-btn { background: #4af; color: #060a14; border: 1px solid #4af; padding: 0 14px; border-radius: 6px; font-family: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer; transition: background 0.15s; white-space: nowrap; }
.small-btn:hover { background: #66bfff; }
.small-btn.secondary { background: transparent; color: #888; border-color: #222; }
.small-btn.secondary:hover { border-color: #4af; color: #4af; background: transparent; }
.small-btn.copied { background: #4a4; border-color: #4a4; color: #e6ffe6; }
.small-btn.primary { padding: 8px 16px; font-size: 0.85rem; display: inline-flex; align-items: center; }
.small-btn.danger { background: transparent; color: #f88; border: 1px solid #4a1818; }
.small-btn.danger:hover:not(:disabled) { background: #2a1010; border-color: #6a2626; color: #fbb; }
.upgrade-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.upgrade-modal { background: #111; border: 1px solid #2a4a6a; border-radius: 10px; padding: 24px 28px; max-width: 420px; color: #e0e0e0; box-shadow: 0 10px 40px rgba(74,175,255,0.1); }
.upgrade-modal h3 { color: #fff; margin-bottom: 8px; }
.upgrade-modal p { color: #bbb; font-size: 0.92rem; margin-bottom: 18px; }
.upgrade-actions { display: flex; gap: 10px; justify-content: flex-end; }
.upgrade-actions a, .upgrade-actions button { text-decoration: none; }
.footer-row { margin-top: 10px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.75rem; color: #666; }
.empty, .error { background: #111; border: 1px solid #222; border-radius: 8px; padding: 32px 20px; text-align: center; color: #888; }
.empty code { display: block; margin-top: 12px; padding: 10px 14px; background: #0a0a0a; border: 1px solid #1a1a1a; border-radius: 6px; color: #adf; font-family: "SF Mono", monospace; font-size: 0.82rem; overflow-x: auto; }
.error .small-btn { margin-top: 12px; }
.claim-box { background: #0e1620; border: 1px solid #1a2a3a; border-radius: 8px; padding: 16px 18px; margin: 18px 0 24px; }
.claim-box h2 { font-size: 0.95rem; color: #fff; margin-bottom: 6px; }
.claim-box p { font-size: 0.85rem; color: #888; margin-bottom: 12px; }
.claim-box code { background: #0a0a0a; padding: 1px 6px; border-radius: 4px; color: #6bf; font-size: 0.8rem; }
.claim-box form { display: flex; gap: 8px; flex-wrap: wrap; }
.claim-box input { flex: 1 1 220px; min-width: 0; background: #0a0a0a; border: 1px solid #222; color: #e0e0e0; padding: 10px 12px; border-radius: 6px; font-family: "SF Mono", "Fira Code", monospace; font-size: 0.85rem; }
.claim-box input:focus { outline: 2px solid #4af; outline-offset: 2px; border-color: #4af; }
.claim-msg { margin-top: 10px; font-size: 0.85rem; min-height: 1.1em; }
.claim-msg.err { color: #f88; }
.claim-msg.ok { color: #4a4; }
.apikey-box { background: #130f1a; border: 1px solid #2a1a3a; border-radius: 8px; padding: 16px 18px; margin: 0 0 24px; }
.apikey-box h2 { font-size: 0.95rem; color: #fff; margin-bottom: 6px; }
.apikey-box p { font-size: 0.85rem; color: #888; margin-bottom: 12px; }
.apikey-box code { background: #0a0a0a; padding: 1px 6px; border-radius: 4px; color: #b9f; font-size: 0.8rem; }
.apikey-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.apikey-value { flex: 1 1 260px; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 10px 12px !important; font-family: "SF Mono", "Fira Code", monospace; }
.apikey-curl { margin-top: 12px; background: #0a0a0a; border: 1px solid #1a1a1a; padding: 12px 14px; border-radius: 6px; font-family: "SF Mono", "Fira Code", monospace; font-size: 0.78rem; color: #ccc; overflow-x: auto; }
.small-btn.secondary { background: transparent; color: #9dc; border: 1px solid #224; }
.small-btn.secondary:hover:not(:disabled) { background: #0e1620; border-color: #2a4a6a; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #0d1a0e; color: #cfe8d0; border: 1px solid #1d4a20; padding: 10px 18px; border-radius: 999px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; }
.toast.show { opacity: 1; }
.toast.err { background: #2a1010; color: #f88; border-color: #4a1818; }
footer { border-top: 1px solid #1a1a1a; padding: 24px 0; margin-top: 40px; text-align: center; color: #444; font-size: 0.8rem; }
footer a { color: #666; margin: 0 10px; }
footer a:hover { color: #4af; text-decoration: none; }
@media (max-width: 600px) {
h1 { font-size: 1.3rem; }
.meta { margin-left: 0; width: 100%; }
.url-row { flex-direction: column; }
.small-btn { padding: 10px 14px; }
}
</style>
</head>
<body>
<div class="container">
<nav class="top">
<a href="/" class="brand">instanode.dev</a>
<div class="right">
<span class="email" id="userEmail"></span>
<button class="ghost-btn" id="logoutBtn" type="button" hidden>Sign out</button>
</div>
</nav>
<h1>Your resources</h1>
<p class="subtitle" id="subtitle">Loading…</p>
<div id="banner"></div>
<section class="claim-box" id="claim-box" aria-labelledby="claim-heading">
<h2 id="claim-heading">Claim an existing token</h2>
<p>Paste a token you got from <code>curl /db/new</code> or <code>/webhook/new</code> to attach it to your account.</p>
<form id="claim-form" autocomplete="off">
<input id="claim-input" type="text" inputmode="text" pattern="[0-9a-fA-F-]{36}"
placeholder="00000000-0000-0000-0000-000000000000" aria-label="Token UUID" required>
<button type="submit" class="small-btn" id="claim-submit">Claim</button>
</form>
<div class="claim-msg" id="claim-msg" role="status" aria-live="polite"></div>
</section>
<section class="apikey-box" id="apikey-box" aria-labelledby="apikey-heading" hidden>
<h2 id="apikey-heading">API token for CLI / agent</h2>
<p>Paid-tier callers skip the free 5/day per-IP cap by passing this token. Treat it like a password; 30-day expiry; rotate by clicking "Regenerate".</p>
<div class="apikey-row">
<code id="apikey-value" class="apikey-value">•••••••• hidden</code>
<button type="button" class="small-btn secondary" id="apikey-reveal">Reveal</button>
<button type="button" class="small-btn" id="apikey-copy">Copy</button>
<button type="button" class="small-btn secondary" id="apikey-rotate">Regenerate</button>
</div>
<pre class="apikey-curl" id="apikey-curl">curl -X POST https://api.instanode.dev/db/new \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{"name":"my-project"}'</pre>
<div class="claim-msg" id="apikey-msg" role="status" aria-live="polite"></div>
</section>
<div id="content"></div>
<footer>
<a href="/">Home</a>
<a href="/about.html">About</a>
<a href="/pricing.html">Pricing</a>
<a href="/privacy.html">Privacy</a>
<a href="/terms.html">Terms</a>
<p style="margin-top:12px;">Questions or issues? <a href="mailto:contact@instanode.dev" style="color:#888;">contact@instanode.dev</a></p>
<p style="margin-top:4px;color:#444;">instanode.dev</p>
</footer>
</div>
<div id="toast" class="toast" role="alert" aria-live="assertive"></div>
<script>
(function () {
var API = window.INSTANT_API || 'https://api.instanode.dev';
var $toast = document.getElementById('toast');
var $content = document.getElementById('content');
var $banner = document.getElementById('banner');
var $subtitle = document.getElementById('subtitle');
var $email = document.getElementById('userEmail');
var params = new URLSearchParams(location.search);
var upgradedFlag = params.get('upgraded') === '1';
var claimToken = params.get('token');
function toast(text, kind) {
$toast.textContent = text;
$toast.className = 'toast show' + (kind === 'err' ? ' err' : '');
setTimeout(function () { $toast.className = 'toast' + (kind === 'err' ? ' err' : ''); }, 3500);
}
function esc(s) {
return String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
}
function goStart() {
var qs = [];
if (upgradedFlag) qs.push('upgraded=1');
if (claimToken) qs.push('token=' + encodeURIComponent(claimToken));
location.href = '/start' + (qs.length ? ('?' + qs.join('&')) : '');
}
function relTime(iso, fallback) {
if (!iso) return fallback || '';
var t = new Date(iso).getTime();
if (isNaN(t)) return '';
var diff = t - Date.now(), abs = Math.abs(diff), future = diff > 0, mins = Math.round(abs / 60000), out;
if (mins < 1) return 'just now';
if (mins < 60) out = mins + 'm';
else if (mins < 1440) out = Math.round(mins / 60) + 'h';
else out = Math.round(mins / 1440) + 'd';
return future ? ('in ' + out) : (out + ' ago');
}
function mask(url) {
if (!url) return '';
return url.replace(/^([a-z0-9+.-]+:\/\/[^:\/?#\s]+:)([^@\s]+)(@)/i, '$1\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022$3');
}
function buildUrl(r) {
if (r.connection_url) return r.connection_url;
var prefix = r.key_prefix || (r.token ? String(r.token).slice(0, 8) : 'xxxxxxxx');
var type = (r.resource_type || r.type || '').toLowerCase();
if (type === 'postgres') return 'postgres://usr_' + prefix + ':password@pg.instanode.dev:5432/db_' + prefix;
if (type === 'webhook') return API + '/webhook/' + (r.token || prefix);
return '';
}
function typeLabel(t) {
var s = (t || '').toLowerCase();
if (s === 'postgres') return 'Postgres';
if (s === 'webhook') return 'Webhook';
return t || 'Resource';
}
function groupKey(t) { var s = (t || '').toLowerCase(); return s || 'other'; }
function expires(r) { return r.expires_at ? relTime(r.expires_at, 'permanent') : 'permanent'; }
function renderCard(r) {
var type = (r.resource_type || r.type || '').toLowerCase();
var badge = (type === 'postgres' || type === 'webhook') ? type : 'other';
var url = buildUrl(r);
var id = esc(r.id || r.token || '');
var statusClass = esc((r.status || '').toLowerCase());
var tierClass = (r.tier || '').toLowerCase() === 'paid' ? 'paid' : 'anonymous';
var tokenAttr = esc(r.token || '');
return '<div class="card" data-id="' + id + '" data-token="' + tokenAttr + '">' +
'<div class="card-head">' +
'<span class="badge ' + badge + '">' + esc(typeLabel(type)) + '</span>' +
'<span class="pill ' + tierClass + '">' + esc(r.tier || 'unknown') + '</span>' +
'<span class="pill ' + statusClass + '">' + esc(r.status || 'unknown') + '</span>' +
'<span class="meta">' + esc(r.name || ('resource ' + String(r.id || r.token || '').slice(0, 8))) + '</span>' +
'</div>' +
'<div class="url-row">' +
'<code class="conn" data-full="' + esc(url) + '" data-masked="1">' + esc(mask(url) || '—') + '</code>' +
(url ? '<button type="button" class="small-btn secondary js-show">Show</button>' : '') +
(url ? '<button type="button" class="small-btn js-copy">Copy</button>' : '') +
'<button type="button" class="small-btn danger js-delete" aria-label="Delete resource">Delete</button>' +
'</div>' +
'<div class="footer-row">' +
'<span>Created ' + esc(relTime(r.created_at) || '—') + '</span>' +
'<span>Expires: ' + esc(expires(r)) + '</span>' +
'</div>' +
'</div>';
}
function wireCards() {
var cards = $content.querySelectorAll('.card');
for (var i = 0; i < cards.length; i++) (function (card) {
var code = card.querySelector('.conn');
var showBtn = card.querySelector('.js-show');
var copyBtn = card.querySelector('.js-copy');
if (showBtn) showBtn.addEventListener('click', function () {
var masked = code.getAttribute('data-masked') === '1';
var full = code.getAttribute('data-full') || '';
code.textContent = masked ? full : mask(full);
code.setAttribute('data-masked', masked ? '0' : '1');
showBtn.textContent = masked ? 'Hide' : 'Show';
});
if (copyBtn) copyBtn.addEventListener('click', function () {
var full = code.getAttribute('data-full') || '';
if (!full) return;
var done = function () {
copyBtn.textContent = 'Copied!';
copyBtn.classList.add('copied');
setTimeout(function () { copyBtn.textContent = 'Copy'; copyBtn.classList.remove('copied'); }, 1800);
};
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(full).then(done, function () { fallbackCopy(full); done(); });
} else { fallbackCopy(full); done(); }
});
var deleteBtn = card.querySelector('.js-delete');
if (deleteBtn) deleteBtn.addEventListener('click', function () {
var token = card.getAttribute('data-token');
if (!token) return;
if (!confirm('Permanently delete this resource? Any data inside is lost immediately.')) return;
deleteBtn.disabled = true;
deleteBtn.textContent = 'Deleting…';
fetch(API + '/api/me/resources/' + encodeURIComponent(token), {
method: 'DELETE',
credentials: 'include'
}).then(function (res) {
return res.json().then(function (body) { return { status: res.status, body: body }; });
}).then(function (r) {
if (r.status === 202 || r.status === 200) {
card.style.transition = 'opacity 0.2s';
card.style.opacity = '0';
setTimeout(function () { card.remove(); }, 220);
toast('Queued for deletion. Underlying DB is dropped within 5 minutes.');
} else if (r.status === 403 && r.body.error === 'paid_tier_only') {
deleteBtn.disabled = false;
deleteBtn.textContent = 'Delete';
showUpgradeModal(r.body.message || 'Upgrade to Developer to delete resources on demand.', r.body.upgrade_url || '/pricing.html');
} else {
deleteBtn.disabled = false;
deleteBtn.textContent = 'Delete';
toast(r.body.message || 'Delete failed.', 'err');
}
}).catch(function () {
deleteBtn.disabled = false;
deleteBtn.textContent = 'Delete';
toast('Network error — please retry.', 'err');
});
});
})(cards[i]);
}
function showUpgradeModal(msg, href) {
var overlay = document.createElement('div');
overlay.className = 'upgrade-overlay';
overlay.innerHTML =
'<div class="upgrade-modal" role="dialog" aria-modal="true">' +
' <h3>Upgrade to delete</h3>' +
' <p>' + esc(msg) + '</p>' +
' <div class="upgrade-actions">' +
' <a class="small-btn" href="' + esc(href) + '">See Developer plan</a>' +
' <button type="button" class="small-btn secondary js-close">Not now</button>' +
' </div>' +
'</div>';
document.body.appendChild(overlay);
overlay.querySelector('.js-close').addEventListener('click', function () { overlay.remove(); });
overlay.addEventListener('click', function (e) { if (e.target === overlay) overlay.remove(); });
}
function fallbackCopy(text) {
try {
var ta = document.createElement('textarea');
ta.value = text; ta.setAttribute('readonly', '');
ta.style.position = 'fixed'; ta.style.opacity = '0';
document.body.appendChild(ta); ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
} catch (e) {}
}
var currentUser = null;
function planLabel(u) {
if (!u || u.plan_tier !== 'paid') return null;
var period = (u.plan_period || 'monthly').toLowerCase();
return period === 'annual'
? { line: 'Developer Plan · Annual · $120/yr · resources are permanent.' }
: { line: 'Developer Plan · Monthly · $12/mo · resources are permanent.' };
}
function nextRenewal(u) {
if (!u || !u.plan_paid_at) return '';
var paidAt = new Date(u.plan_paid_at);
if (isNaN(paidAt.getTime())) return '';
var days = (u.plan_period === 'annual') ? 365 : 30;
var next = new Date(paidAt.getTime() + days * 86400000);
return ' · next renewal ' + next.toISOString().slice(0, 10);
}
function renderBannerLoading() {
$banner.innerHTML = '<div class="banner"><div><div class="skeleton"></div></div><div class="skeleton" style="width:90px;"></div></div>';
}
function renderBannerFromPlan(plan) {
if (!plan) { $banner.innerHTML = ''; return; }
var tier = (plan.plan_tier || 'free').toLowerCase();
var status = (plan.subscription_status || '').toLowerCase();
// Free-tier: richer upsell banner with pricing front-and-centre.
if (tier !== 'paid') {
$banner.innerHTML =
'<div class="upsell">' +
'<div class="upsell-grid">' +
'<div>' +
'<span class="tag">Free tier</span>' +
'<h3>Upgrade to Developer — keep everything you build</h3>' +
'<p>No more 24-hour expirations. No per-subnet provisioning cap. Priority support.</p>' +
'<ul>' +
'<li>Permanent resources</li>' +
'<li>500 MB storage per database</li>' +
'<li>5 concurrent connections</li>' +
'<li>Unlimited provisioning</li>' +
'</ul>' +
'</div>' +
'<div class="upsell-cta">' +
'<div class="upsell-price">$12<span class="per"> / month</span></div>' +
'<div class="upsell-annual">or <strong>$120 / year</strong> — 2 months free</div>' +
'<a href="/pricing.html" class="upsell-btn">Upgrade →</a>' +
'</div>' +
'</div>' +
'</div>';
return;
}
// Paid-tier banner is a tight utility strip. Cancellation is NOT a
// self-serve action in this product — the user revokes their auto-pay
// mandate at their bank or in Razorpay, Razorpay fires
// subscription.cancelled to us, our handler stores the cancellation
// along with current_period_end. We display the resulting state.
var variant = status === 'halted' ? 'warn' : 'paid';
var tagText = status === 'halted' ? 'PAYMENT HALTED' : (status === 'cancelled' ? 'CANCELLING' : 'ACTIVE');
// For 'cancelled', show the until-date prominently when we have it —
// matches what the cancellation email already says, so users see the
// same guarantee in-app and don't lose track of when free-tier kicks in.
var periodEndDate = '';
if (plan.current_period_end) {
var d = new Date(plan.current_period_end);
if (!isNaN(d.getTime())) {
periodEndDate = d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
}
}
var subText = status === 'cancelled'
? (periodEndDate
? 'Paid access continues until ' + periodEndDate + '. After that you\'re back on the free tier.'
: 'Cancellation is in progress.')
: (status === 'halted'
? 'Your card was declined. Update it and retry from the pricing page.'
: 'Your plan is active. Resources are permanent.');
// Plan switch (monthly ↔ annual) is feature-flagged server-side, so the
// pending_plan_change / pending_plan_effective_at fields only appear on
// the payload when the flag is on. That gates the switch UI naturally —
// if the fields are absent, the trigger button stays hidden.
var pending = plan.pending_plan_change || '';
var effAt = plan.pending_plan_effective_at || '';
var switchEnabled = (typeof plan.pending_plan_change !== 'undefined');
var currentPeriod = (plan.plan_period || 'monthly').toLowerCase();
var rightSide = '';
if (pending) {
// A switch is already scheduled — show an inline "keep current plan"
// action that calls DELETE /billing/change-plan.
var effectiveDate = effAt ? (new Date(effAt)).toISOString().slice(0, 10) : '';
subText = 'Switch to ' + (pending === 'annual' ? 'Annual' : 'Monthly') +
' scheduled' + (effectiveDate ? ' for ' + effectiveDate : '') + '.';
rightSide = '<a href="#" id="cancel-switch-btn" class="small-btn">Keep current plan</a>';
} else if (switchEnabled && status === 'active') {
// Offer the opposite-period switch. Annual users see "Switch to monthly";
// monthly users see "Switch to annual — save 2 months".
var target = currentPeriod === 'annual' ? 'monthly' : 'annual';
var label = target === 'annual' ? 'Switch to annual — save 2 months' : 'Switch to monthly';
rightSide = '<a href="#" id="change-plan-btn" data-target="' + target + '" class="small-btn">' + label + '</a>';
}
$banner.innerHTML =
'<div class="banner ' + variant + '">' +
'<div>' +
'<div class="plan-head"><span class="plan-tag">' + tagText + '</span></div>' +
'<div class="plan-line">' + (plan.human_label || '—') + '</div>' +
'<div class="plan-sub">' + subText + '</div>' +
'</div>' +
(rightSide ? '<div>' + rightSide + '</div>' : '') +
'</div>';
var switchBtn = document.getElementById('change-plan-btn');
if (switchBtn) switchBtn.addEventListener('click', onChangePlanClick);
var cancelBtn = document.getElementById('cancel-switch-btn');
if (cancelBtn) cancelBtn.addEventListener('click', onCancelSwitchClick);
}
function onChangePlanClick(e) {
e.preventDefault();
var target = e.currentTarget.getAttribute('data-target') || 'annual';
var human = target === 'annual' ? 'Annual ($120/yr)' : 'Monthly ($12/mo)';
if (!confirm('Schedule switch to ' + human + '? Takes effect at the end of your current billing period. No charge today.')) return;
fetch(API + '/billing/change-plan', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ to: target }),
})
.then(function (res) { return res.json().then(function (b) { return { ok: res.ok, body: b }; }); })
.then(function (r) {
if (r.ok) { loadPlan(); return; }
alert((r.body && r.body.message) || 'Could not schedule the switch. Please retry.');
})
.catch(function () { alert('Could not reach the billing service. Please retry.'); });
}
function onCancelSwitchClick(e) {
e.preventDefault();
if (!confirm('Cancel the scheduled plan switch? You\'ll stay on your current plan.')) return;
fetch(API + '/billing/change-plan', {
method: 'DELETE',
credentials: 'include',
})
.then(function (res) { return res.json().then(function (b) { return { ok: res.ok, body: b }; }); })
.then(function (r) {
if (r.ok) { loadPlan(); return; }
alert((r.body && r.body.message) || 'Could not cancel the switch. Please retry.');
})
.catch(function () { alert('Could not reach the billing service. Please retry.'); });
}
function loadPlan() {
renderBannerLoading();
return fetch(API + '/api/me/plan', { credentials: 'include' })
.then(function (res) {
if (res.status === 401) { goStart(); return null; }
if (!res.ok) throw new Error('plan HTTP ' + res.status);
return res.json();
})
.then(function (plan) {
if (plan) renderBannerFromPlan(plan);
return plan;
})
.catch(function () {
$banner.innerHTML = '<div class="banner warn"><div><strong>Could not load plan.</strong><div class="plan-sub">Refresh to retry.</div></div><a href="#" onclick="location.reload()">Retry</a></div>';
});
}
// Retained for any legacy caller; simply kicks off the plan fetch.
function renderBanner() { loadPlan(); }
function cancelSubscription(e) {
if (e) e.preventDefault();
if (!confirm('Cancel subscription? You\'ll keep paid access until the end of the current billing period.')) return;
fetch(API + '/billing/cancel-subscription', { method: 'POST', credentials: 'include' })
.then(function (res) { return res.json().then(function (b) { return { ok: res.ok, body: b }; }); })
.then(function (r) {
if (r.ok) {
alert('Subscription cancelled. You keep paid access until the current period ends.');
window.location.reload();
} else {
alert((r.body && r.body.message) || 'Could not cancel right now. Please retry in a moment.');
}
})
.catch(function () { alert('Could not reach the billing service. Please retry.'); });
}
function renderResources(list) {
if (!Array.isArray(list) || list.length === 0) {
$subtitle.textContent = 'Provision one with a single curl call.';
$content.innerHTML = '<div class="empty">No resources yet. Provision one:<code>curl -X POST ' + esc(API) + '/db/new</code></div>';
return;
}
$subtitle.textContent = list.length + ' resource' + (list.length === 1 ? '' : 's') + ' on your account.';
var groups = {};
list.forEach(function (r) {
var k = groupKey(r.resource_type || r.type);
(groups[k] = groups[k] || []).push(r);
});
var order = ['postgres', 'webhook'];
var keys = Object.keys(groups).sort(function (a, b) {
var ai = order.indexOf(a), bi = order.indexOf(b);
return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
});
var html = '';
keys.forEach(function (k) {
html += '<div class="group"><h2>' + esc(typeLabel(k)) + ' (' + groups[k].length + ')</h2>';
groups[k].forEach(function (r) { html += renderCard(r); });
html += '</div>';
});
$content.innerHTML = html;
wireCards();
}
function renderError(err) {
var detail = '';
if (err && err.name === 'AbortError') detail = ' (timed out after 10s)';
else if (err && err.message) detail = ' (' + err.message + ')';
$content.innerHTML = '<div class="error">Failed to load resources' + detail + ' — <button type="button" class="small-btn" id="retryBtn">Retry</button></div>';
document.getElementById('retryBtn').addEventListener('click', loadResources);
}
function wireApiKeyBox() {
var box = document.getElementById('apikey-box');
var valueEl = document.getElementById('apikey-value');
var curlEl = document.getElementById('apikey-curl');
var revealBtn = document.getElementById('apikey-reveal');
var copyBtn = document.getElementById('apikey-copy');
var rotateBtn = document.getElementById('apikey-rotate');
var msg = document.getElementById('apikey-msg');
if (!box) return;
var currentToken = null;
var revealed = false;
function mask(t) { return t ? t.slice(0, 12) + '…' + t.slice(-6) : ''; }
function show() {
if (!currentToken) {
valueEl.textContent = '•••••••• hidden';
return;
}
valueEl.textContent = revealed ? currentToken : mask(currentToken);
revealBtn.textContent = revealed ? 'Hide' : 'Reveal';
// Keep the curl block readable with the real token once revealed.
if (revealed) {
curlEl.textContent = 'curl -X POST ' + API + '/db/new \\\n -H "Authorization: Bearer ' + currentToken + '" \\\n -H \'Content-Type: application/json\' \\\n -d \'{"name":"my-project"}\'';
} else {
curlEl.textContent = 'curl -X POST ' + API + '/db/new \\\n -H \'Authorization: Bearer <token>\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{"name":"my-project"}\'';
}
}
function fetchToken(force) {
fetch(API + '/api/me/token', { credentials: 'include' })
.then(function (res) { return res.ok ? res.json() : null; })
.then(function (body) {
if (body && body.token) {
currentToken = body.token;
box.hidden = false;
// First load keeps it masked; rotation reveals so the user can
// copy the new value immediately.
if (force) revealed = true;
show();
if (force) msg.className = 'claim-msg ok';
if (force) msg.textContent = 'New token issued. Old token is still valid until JWT_SECRET is rotated.';
}
})
.catch(function () {});
}
revealBtn.addEventListener('click', function () { revealed = !revealed; show(); });
rotateBtn.addEventListener('click', function () { fetchToken(true); });
copyBtn.addEventListener('click', function () {
if (!currentToken) return;
(navigator.clipboard ? navigator.clipboard.writeText(currentToken) : Promise.reject())
.then(function () {
msg.className = 'claim-msg ok';
msg.textContent = 'Token copied to clipboard.';
})
.catch(function () {
var ta = document.createElement('textarea');
ta.value = currentToken;
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); msg.className = 'claim-msg ok'; msg.textContent = 'Token copied to clipboard.'; }
catch (e) { msg.className = 'claim-msg err'; msg.textContent = 'Could not copy — select the text manually.'; }
document.body.removeChild(ta);
});
});
fetchToken(false);
}
function wireClaimForm() {
var form = document.getElementById('claim-form');
var input = document.getElementById('claim-input');
var submit = document.getElementById('claim-submit');
var msg = document.getElementById('claim-msg');
if (!form) return;
form.addEventListener('submit', function (e) {
e.preventDefault();
var token = (input.value || '').trim();
if (!token) return;
msg.className = 'claim-msg';
msg.textContent = '';
submit.disabled = true;
submit.textContent = 'Claiming…';
fetch(API + '/api/me/claim', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: token })
}).then(function (res) {
return res.json().then(function (body) {
if (res.ok && body.ok) {
msg.className = 'claim-msg ok';
msg.textContent = 'Claimed. Reloading resources…';
input.value = '';
loadResources();
} else {
msg.className = 'claim-msg err';
msg.textContent = body.message || 'Could not claim the token.';
}
});
}).catch(function () {
msg.className = 'claim-msg err';
msg.textContent = 'Network error — please retry.';
}).finally(function () {
submit.disabled = false;
submit.textContent = 'Claim';
});
});
}
function loadResources() {
$content.innerHTML = '<p class="subtitle" style="text-align:center;padding:24px 0;">Loading resources…</p>';
// Hard 10s timeout so a stuck fetch never leaves the UI on "Loading…".
var controller = new AbortController();
var timer = setTimeout(function () { controller.abort(); }, 10000);
fetch(API + '/api/me/resources', { credentials: 'include', signal: controller.signal })
.then(function (res) {
clearTimeout(timer);
if (res.status === 401) { goStart(); return null; }
if (!res.ok) throw new Error('HTTP ' + res.status);
return res.json();
})
.then(function (data) {
if (data === null) return;
var list = Array.isArray(data) ? data : (data && Array.isArray(data.resources) ? data.resources : []);
renderResources(list);
})
.catch(function (err) { clearTimeout(timer); renderError(err); });
// Plan is loaded separately in the boot path; nothing to do here.
}
function migrate(tok) {
return fetch(API + '/billing/migrate?token=' + encodeURIComponent(tok), { method: 'POST', credentials: 'include' })
.then(function (res) {
if (res.status === 401) { goStart(); return false; }
return res.ok;
})
// Network failure here must not blow away the dashboard. The
// outer boot .catch() would render a full-page error otherwise;
// we just return false so the caller shows a toast.
.catch(function () { return false; });
}
document.getElementById('logoutBtn').addEventListener('click', function () {
// Top-level form POST so the browser follows the server's 302 + applies
// the clear-session Set-Cookie natively. Earlier fetch() + redirect:'manual'
// approach returned an opaque filtered response across origins, and
// browsers apply Set-Cookie on those inconsistently — the cookie often
// wasn't cleared, so after "Sign out" the user landed on / still
// authenticated and the Dashboard link reappeared.
var form = document.createElement('form');
form.method = 'POST';
form.action = API + '/auth/logout';
document.body.appendChild(form);
form.submit();
});
// Poll /auth/me a few times when the user just paid — the Razorpay
// webhook arrives a few seconds after the browser redirect here, so the
// first /auth/me call can still report plan_tier='free'. We retry until
// we see 'paid' or we give up (20s).
//
// AbortController with a 10s hard cap so a CORS-blocked or network-
// stalled request never leaves the page hanging on "Loading…" forever.
// On timeout or network error, we bounce to /start rather than show a
// half-rendered dashboard with a phantom "Sign out" button.
function fetchMe() {
var controller = new AbortController();
var timer = setTimeout(function () { controller.abort(); }, 10000);
return fetch(API + '/auth/me', { credentials: 'include', signal: controller.signal })
.then(function (res) {
clearTimeout(timer);
if (res.status === 401) { goStart(); return null; }
if (!res.ok) throw new Error('HTTP ' + res.status);
return res.json();
})
.catch(function (err) {
clearTimeout(timer);
// Network failure / CORS block / timeout — can't authenticate, so
// send the user through login rather than rendering a broken shell.
goStart();
return null;
});
}
function waitForPaid(maxMs) {
var deadline = Date.now() + maxMs;
return new Promise(function (resolve) {
function tick() {
fetchMe().then(function (user) {
if (!user) { resolve(null); return; }
if (user.plan_tier === 'paid' || Date.now() >= deadline) { resolve(user); return; }
setTimeout(tick, 2000);
}).catch(function () { resolve(null); });
}
tick();
});
}
// Boot
(upgradedFlag ? waitForPaid(20000) : fetchMe())
.then(function (user) {
if (!user) return;
// Only reveal the Sign-out button once we've confirmed the user is
// actually signed in — prevents the phantom logout UI on a failed
// auth fetch.
var logoutBtn = document.getElementById('logoutBtn');
if (logoutBtn) logoutBtn.hidden = false;
currentUser = user;
if (user.email) $email.textContent = user.email;
if (upgradedFlag) {
if (user.plan_tier === 'paid') {
var period = (user.plan_period || 'monthly').toLowerCase();
toast(period === 'annual'
? 'Welcome to Developer · Annual. Next renewal in 12 months.'
: 'Welcome to Developer · Monthly. Your resources are permanent.');
} else {
toast('Payment received. Tier will update shortly — refresh in a moment.', 'err');
}
}
// Plan loads first, independently of resources — the free-tier
// upgrade modal needs to decide whether to appear before the user
// sees anything else.
loadPlan();
var next = Promise.resolve();
if (claimToken) next = migrate(claimToken).then(function (ok) {
// Clear the token either way — stale localStorage would otherwise
// cause the next visitor on a shared device to try to re-claim
// somebody else's resource.
try { localStorage.removeItem('instanode_token'); } catch (e) {}
toast(ok ? 'Resource claimed to your account.' : 'Could not claim resource.', ok ? '' : 'err');
});
next.then(loadResources);
wireClaimForm();
wireApiKeyBox();
if ((upgradedFlag || claimToken) && history.replaceState) history.replaceState({}, '', '/dashboard');
})
.catch(function () {
$subtitle.textContent = '';
$content.innerHTML = '<div class="error">Couldn\'t reach the API. <button type="button" class="small-btn" onclick="location.reload()">Retry</button></div>';
});
})();
</script>
</body>
</html>