@nr-connect/node-red 0.0.0-stage → 1.0.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.
package/index.html ADDED
@@ -0,0 +1,1939 @@
1
+ <style>
2
+ i.nrc-sidebar-icon,
3
+ i.red-ui-tab-icon.nrc-sidebar-icon {
4
+ display: inline-block;
5
+ width: 1.15em;
6
+ height: 1.15em;
7
+ vertical-align: -0.2em;
8
+ background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='6 2 52 60' fill='none'%3E%3Cpath d='M32 2.5 57 10.8V30C57 45.5 46.5 55.5 32 61.5 17.5 55.5 7 45.5 7 30V10.8Z' fill='%238F0000'/%3E%3Cpath d='M32 6.8 52.5 13.6V30C52.5 43 44 51.5 32 56.8 20 51.5 11.5 43 11.5 30V13.6Z' fill='%237A0000'/%3E%3Cpath d='M11.5 23V30C11.5 43 20 51.5 32 56.8Z' fill='%235E0000'/%3E%3Cpath d='M32 6.8 52.5 13.6V30C52.5 43 44 51.5 32 56.8 20 51.5 11.5 43 11.5 30V13.6Z' fill='none' stroke='%23FFFFFF' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M23 24C29 24 27 17.5 33 17.5M23 24C31 24 33 29.5 40 29.5' fill='none' stroke='%23FFFFFF' stroke-width='2.4' stroke-linecap='round'/%3E%3Cg fill='%238F0000' stroke='%23FFFFFF' stroke-width='2.4'%3E%3Crect x='11.5' y='21' width='11.5' height='6' rx='3'/%3E%3Crect x='33' y='14.5' width='15' height='6' rx='3'/%3E%3Crect x='40' y='26.5' width='9.5' height='6' rx='3'/%3E%3C/g%3E%3Cg stroke='%23FFFFFF' stroke-width='1.8'%3E%3Crect x='22.5' y='40.5' width='5.5' height='7' rx='1.6' fill='%231FB872'/%3E%3Crect x='29.5' y='34' width='6.5' height='19' rx='1.6' fill='%23F59A1B'/%3E%3Crect x='37.5' y='39.5' width='5.5' height='8' rx='1.6' fill='%233B3FC4'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
9
+ }
10
+
11
+ i.red-ui-tab-icon.nrc-sidebar-icon {
12
+ margin-right: 4px;
13
+ }
14
+
15
+ #nr-connect-sidebar {
16
+ box-sizing: border-box;
17
+ height: 100%;
18
+ overflow-y: auto;
19
+ padding: 12px;
20
+ display: flex;
21
+ flex-direction: column;
22
+ gap: 12px;
23
+ color: var(--red-ui-primary-text-color, #333333);
24
+ font-size: 13px;
25
+ line-height: 1.45;
26
+ }
27
+
28
+ #nr-connect-sidebar *,
29
+ #nr-connect-sidebar *::before,
30
+ #nr-connect-sidebar *::after {
31
+ box-sizing: border-box;
32
+ }
33
+
34
+ #nr-connect-sidebar .nrc-card {
35
+ background: var(--red-ui-secondary-background, #f7f7f7);
36
+ border: 1px solid var(--red-ui-secondary-border-color, #dddddd);
37
+ border-radius: 4px;
38
+ padding: 10px 12px;
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: 8px;
42
+ }
43
+
44
+ #nr-connect-sidebar .nrc-row-between {
45
+ display: flex;
46
+ align-items: flex-start;
47
+ justify-content: space-between;
48
+ gap: 8px;
49
+ }
50
+
51
+ #nr-connect-sidebar .nrc-section-label {
52
+ font-size: 11px;
53
+ font-weight: 600;
54
+ text-transform: uppercase;
55
+ letter-spacing: 0.04em;
56
+ color: var(--red-ui-secondary-text-color, #666666);
57
+ margin: 0;
58
+ }
59
+
60
+ #nr-connect-sidebar .nrc-muted {
61
+ margin: 0;
62
+ font-size: 12px;
63
+ color: var(--red-ui-secondary-text-color, #666666);
64
+ }
65
+
66
+ #nr-connect-sidebar .nrc-status-wrap {
67
+ display: flex;
68
+ flex-direction: column;
69
+ gap: 4px;
70
+ min-width: 0;
71
+ }
72
+
73
+ #nr-connect-sidebar .nrc-pill {
74
+ display: inline-flex;
75
+ align-items: center;
76
+ gap: 6px;
77
+ padding: 3px 8px;
78
+ border-radius: 999px;
79
+ font-size: 12px;
80
+ font-weight: 600;
81
+ border: 1px solid var(--red-ui-secondary-border-color, #cccccc);
82
+ background: var(--red-ui-primary-background, #ffffff);
83
+ width: fit-content;
84
+ max-width: 100%;
85
+ word-break: break-word;
86
+ }
87
+
88
+ #nr-connect-sidebar .nrc-dot {
89
+ width: 8px;
90
+ height: 8px;
91
+ border-radius: 50%;
92
+ flex: 0 0 auto;
93
+ background: var(--red-ui-node-status-colors-grey, #888888);
94
+ }
95
+
96
+ #nr-connect-sidebar .nrc-pill-success {
97
+ border-color: var(--red-ui-border-color-success, #30a46c);
98
+ color: var(--red-ui-text-color-success, #1f7a4c);
99
+ }
100
+
101
+ #nr-connect-sidebar .nrc-pill-success .nrc-dot {
102
+ background: var(--red-ui-node-status-colors-green, #30a46c);
103
+ }
104
+
105
+ #nr-connect-sidebar .nrc-pill-warning {
106
+ border-color: var(--red-ui-border-color-warning, #e2a336);
107
+ color: var(--red-ui-text-color-warning, #9a6700);
108
+ }
109
+
110
+ #nr-connect-sidebar .nrc-pill-warning .nrc-dot {
111
+ background: var(--red-ui-node-status-colors-yellow, #e2a336);
112
+ }
113
+
114
+ #nr-connect-sidebar .nrc-pill-error {
115
+ border-color: var(--red-ui-border-color-error, #e5484d);
116
+ color: var(--red-ui-text-color-error, #b91c1c);
117
+ }
118
+
119
+ #nr-connect-sidebar .nrc-pill-error .nrc-dot {
120
+ background: var(--red-ui-node-status-colors-red, #e5484d);
121
+ }
122
+
123
+ #nr-connect-sidebar .nrc-pill-neutral {
124
+ border-color: var(--red-ui-secondary-border-color, #bbbbbb);
125
+ color: var(--red-ui-secondary-text-color, #666666);
126
+ }
127
+
128
+ #nr-connect-sidebar .nrc-env-banner {
129
+ display: flex;
130
+ align-items: flex-start;
131
+ gap: 8px;
132
+ padding: 8px 10px;
133
+ border-radius: 4px;
134
+ background: var(--red-ui-secondary-background, #f3f3f3);
135
+ border: 1px solid var(--red-ui-primary-border-color, #cccccc);
136
+ font-size: 12px;
137
+ color: var(--red-ui-primary-text-color, #333333);
138
+ }
139
+
140
+ #nr-connect-sidebar .nrc-instance-name {
141
+ font-weight: 600;
142
+ font-size: 14px;
143
+ color: var(--red-ui-primary-text-color, #222222);
144
+ margin: 0;
145
+ word-break: break-word;
146
+ }
147
+
148
+ #nr-connect-sidebar .nrc-address-text {
149
+ font-family: var(--red-ui-monospace-font, monospace);
150
+ font-size: 12px;
151
+ color: var(--red-ui-secondary-text-color, #555555);
152
+ word-break: break-all;
153
+ overflow-wrap: anywhere;
154
+ }
155
+
156
+ #nr-connect-sidebar .nrc-actions {
157
+ display: flex;
158
+ flex-wrap: wrap;
159
+ align-items: center;
160
+ gap: 6px;
161
+ }
162
+
163
+ #nr-connect-sidebar .nrc-qr-panel {
164
+ margin-top: 4px;
165
+ padding: 12px;
166
+ border-radius: 6px;
167
+ border: 1px solid var(--red-ui-secondary-border-color, #dddddd);
168
+ background: var(--red-ui-primary-background, #ffffff);
169
+ display: flex;
170
+ flex-direction: column;
171
+ align-items: center;
172
+ gap: 10px;
173
+ }
174
+
175
+ #nr-connect-sidebar .nrc-qr-select {
176
+ width: 100%;
177
+ min-height: 28px;
178
+ padding: 4px 8px;
179
+ border-radius: 4px;
180
+ border: 1px solid var(--red-ui-form-input-border-color, #cccccc);
181
+ background: var(--red-ui-form-input-background, #ffffff);
182
+ color: var(--red-ui-form-text-color, #333333);
183
+ font-size: 12px;
184
+ }
185
+
186
+ #nr-connect-sidebar .nrc-qr-frame {
187
+ background: #ffffff;
188
+ padding: 10px;
189
+ border-radius: 10px;
190
+ border: 1px solid rgba(0, 0, 0, 0.08);
191
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
192
+ }
193
+
194
+ #nr-connect-sidebar .nrc-qr-img {
195
+ display: block;
196
+ width: 176px;
197
+ height: 176px;
198
+ max-width: 100%;
199
+ }
200
+
201
+ #nr-connect-sidebar .nrc-qr-caption {
202
+ margin: 0;
203
+ font-size: 11px;
204
+ color: var(--red-ui-secondary-text-color, #666666);
205
+ text-align: center;
206
+ word-break: break-all;
207
+ }
208
+
209
+ #nr-connect-sidebar .nrc-qr-actions {
210
+ display: flex;
211
+ flex-wrap: wrap;
212
+ justify-content: center;
213
+ gap: 6px;
214
+ width: 100%;
215
+ }
216
+
217
+ #nr-connect-sidebar .red-ui-button,
218
+ #nr-connect-sidebar a.red-ui-button {
219
+ display: inline-flex;
220
+ align-items: center;
221
+ justify-content: center;
222
+ gap: 6px;
223
+ min-width: 28px;
224
+ min-height: 28px;
225
+ height: auto;
226
+ line-height: 1.3;
227
+ padding: 4px 10px;
228
+ border: 1px solid var(--red-ui-form-input-border-color, #cccccc);
229
+ border-radius: 4px;
230
+ text-decoration: none;
231
+ white-space: nowrap;
232
+ font-size: 12px;
233
+ }
234
+
235
+ #nr-connect-sidebar .red-ui-button.primary {
236
+ border-color: var(--red-ui-workspace-button-background-primary, #aa4444);
237
+ background: var(--red-ui-workspace-button-background-primary, #aa4444);
238
+ color: var(--red-ui-workspace-button-color-primary, #ffffff) !important;
239
+ }
240
+
241
+ #nr-connect-sidebar .red-ui-button.primary:not(:disabled):hover {
242
+ border-color: var(--red-ui-workspace-button-background-primary-hover, #883333);
243
+ background: var(--red-ui-workspace-button-background-primary-hover, #883333);
244
+ color: var(--red-ui-workspace-button-color-primary, #ffffff) !important;
245
+ }
246
+
247
+ #nr-connect-sidebar .red-ui-button.nrc-btn-danger {
248
+ color: var(--red-ui-text-color-error, #b91c1c) !important;
249
+ border-color: var(--red-ui-border-color-error, #e5484d);
250
+ }
251
+
252
+ #nr-connect-sidebar .red-ui-button.nrc-btn-icon {
253
+ padding: 4px 8px;
254
+ flex: 0 0 auto;
255
+ }
256
+
257
+ #nr-connect-sidebar .red-ui-button:focus-visible,
258
+ #nr-connect-sidebar .nrc-link:focus-visible,
259
+ #nr-connect-sidebar .nrc-link-btn:focus-visible,
260
+ #nr-connect-sidebar .nrc-textarea:focus-visible {
261
+ outline: 2px solid var(--red-ui-form-input-focus-color, #4d90fe);
262
+ outline-offset: 2px;
263
+ }
264
+
265
+ #nr-connect-sidebar .nrc-link {
266
+ color: var(--red-ui-text-color-link, #2f6f9f);
267
+ text-decoration: underline;
268
+ font-size: 12px;
269
+ word-break: break-word;
270
+ }
271
+
272
+ #nr-connect-sidebar .nrc-link-btn {
273
+ background: none;
274
+ border: none;
275
+ padding: 2px 0;
276
+ margin: 0;
277
+ cursor: pointer;
278
+ color: var(--red-ui-text-color-link, #2f6f9f);
279
+ text-decoration: underline;
280
+ font-size: 12px;
281
+ font-family: inherit;
282
+ min-height: 24px;
283
+ display: inline-flex;
284
+ align-items: center;
285
+ gap: 4px;
286
+ text-align: left;
287
+ }
288
+
289
+ #nr-connect-sidebar .nrc-copy-wrap {
290
+ display: inline-flex;
291
+ align-items: center;
292
+ gap: 6px;
293
+ }
294
+
295
+ #nr-connect-sidebar .nrc-copy-status {
296
+ font-size: 12px;
297
+ font-weight: 600;
298
+ color: var(--red-ui-text-color-success, #1f7a4c);
299
+ opacity: 0;
300
+ transition: opacity 0.15s ease;
301
+ pointer-events: none;
302
+ }
303
+
304
+ #nr-connect-sidebar .nrc-copy-status.is-visible {
305
+ opacity: 1;
306
+ }
307
+
308
+ #nr-connect-sidebar .nrc-copy-status.is-error {
309
+ color: var(--red-ui-text-color-error, #b91c1c);
310
+ }
311
+
312
+ #nr-connect-sidebar .nrc-field {
313
+ display: flex;
314
+ flex-direction: column;
315
+ gap: 4px;
316
+ }
317
+
318
+ #nr-connect-sidebar .nrc-label {
319
+ font-weight: 600;
320
+ font-size: 13px;
321
+ margin: 0;
322
+ color: var(--red-ui-primary-text-color, #333333);
323
+ }
324
+
325
+ #nr-connect-sidebar .nrc-textarea {
326
+ width: 100%;
327
+ min-height: 88px;
328
+ resize: vertical;
329
+ padding: 8px;
330
+ border-radius: 4px;
331
+ border: 1px solid var(--red-ui-form-input-border-color, #cccccc);
332
+ background: var(--red-ui-form-input-background, #ffffff);
333
+ color: var(--red-ui-form-text-color, #333333);
334
+ font-family: var(--red-ui-monospace-font, monospace);
335
+ font-size: 12px;
336
+ line-height: 1.45;
337
+ }
338
+
339
+ #nr-connect-sidebar .nrc-textarea[aria-invalid="true"] {
340
+ border-color: var(--red-ui-border-color-error, #e5484d);
341
+ }
342
+
343
+ #nr-connect-sidebar .nrc-field-error {
344
+ margin: 2px 0 0;
345
+ font-size: 12px;
346
+ font-weight: 500;
347
+ color: var(--red-ui-text-color-error, #b91c1c);
348
+ }
349
+
350
+ #nr-connect-sidebar .nrc-secure-access-badge {
351
+ display: inline-flex;
352
+ align-items: center;
353
+ gap: 6px;
354
+ font-weight: 600;
355
+ font-size: 12px;
356
+ }
357
+
358
+ #nr-connect-sidebar .nrc-secure-access-badge.is-on {
359
+ color: var(--red-ui-text-color-success, #1f7a4c);
360
+ }
361
+
362
+ #nr-connect-sidebar .nrc-secure-access-badge.is-off {
363
+ color: var(--red-ui-secondary-text-color, #666666);
364
+ }
365
+
366
+ #nr-connect-sidebar .nrc-page-list {
367
+ list-style: none;
368
+ margin: 0;
369
+ padding: 0;
370
+ display: flex;
371
+ flex-direction: column;
372
+ gap: 6px;
373
+ }
374
+
375
+ #nr-connect-sidebar .nrc-page-item {
376
+ display: flex;
377
+ flex-direction: column;
378
+ gap: 1px;
379
+ padding: 6px 8px;
380
+ border-radius: 3px;
381
+ background: var(--red-ui-primary-background, #ffffff);
382
+ border: 1px solid var(--red-ui-secondary-border-color, #e0e0e0);
383
+ }
384
+
385
+ #nr-connect-sidebar .nrc-page-name {
386
+ font-weight: 500;
387
+ font-size: 12px;
388
+ color: var(--red-ui-primary-text-color, #333333);
389
+ word-break: break-word;
390
+ }
391
+
392
+ #nr-connect-sidebar .nrc-page-path {
393
+ font-family: var(--red-ui-monospace-font, monospace);
394
+ font-size: 11px;
395
+ color: var(--red-ui-text-color-link, #2f6f9f);
396
+ word-break: break-all;
397
+ }
398
+
399
+ #nr-connect-sidebar .nrc-version-row {
400
+ display: flex;
401
+ align-items: center;
402
+ justify-content: space-between;
403
+ gap: 8px;
404
+ font-size: 12px;
405
+ }
406
+
407
+ #nr-connect-sidebar .nrc-version-meta {
408
+ display: inline-flex;
409
+ align-items: center;
410
+ gap: 6px;
411
+ flex-wrap: wrap;
412
+ justify-content: flex-end;
413
+ }
414
+
415
+ #nr-connect-sidebar .nrc-version-code {
416
+ font-family: var(--red-ui-monospace-font, monospace);
417
+ font-size: 11px;
418
+ color: var(--red-ui-primary-text-color, #333333);
419
+ }
420
+
421
+ #nr-connect-sidebar .nrc-tag {
422
+ display: inline-flex;
423
+ align-items: center;
424
+ gap: 4px;
425
+ padding: 1px 6px;
426
+ border-radius: 999px;
427
+ font-size: 11px;
428
+ font-weight: 600;
429
+ border: 1px solid var(--red-ui-secondary-border-color, #cccccc);
430
+ background: var(--red-ui-primary-background, #ffffff);
431
+ }
432
+
433
+ #nr-connect-sidebar .nrc-tag-warning {
434
+ border-color: var(--red-ui-border-color-warning, #e2a336);
435
+ color: var(--red-ui-text-color-warning, #9a6700);
436
+ }
437
+
438
+ #nr-connect-sidebar .nrc-tag-error {
439
+ border-color: var(--red-ui-border-color-error, #e5484d);
440
+ color: var(--red-ui-text-color-error, #b91c1c);
441
+ }
442
+
443
+ #nr-connect-sidebar .nrc-footer {
444
+ margin-top: auto;
445
+ padding-top: 8px;
446
+ border-top: 1px solid var(--red-ui-secondary-border-color, #dddddd);
447
+ display: flex;
448
+ flex-direction: column;
449
+ gap: 8px;
450
+ }
451
+
452
+ #nr-connect-sidebar .nrc-footer-links {
453
+ display: flex;
454
+ flex-wrap: wrap;
455
+ align-items: center;
456
+ gap: 10px 14px;
457
+ }
458
+
459
+ #nr-connect-sidebar [hidden] {
460
+ display: none !important;
461
+ }
462
+
463
+ @media (prefers-reduced-motion: reduce) {
464
+ #nr-connect-sidebar .fa-spin {
465
+ animation: none !important;
466
+ }
467
+
468
+ #nr-connect-sidebar .nrc-copy-status {
469
+ transition: none;
470
+ }
471
+ }
472
+
473
+ @media (forced-colors: active) {
474
+
475
+ #nr-connect-sidebar .nrc-pill,
476
+ #nr-connect-sidebar .nrc-card,
477
+ #nr-connect-sidebar .nrc-page-item,
478
+ #nr-connect-sidebar .red-ui-button {
479
+ border: 1px solid CanvasText;
480
+ }
481
+
482
+ #nr-connect-sidebar .nrc-dot {
483
+ border: 1px solid CanvasText;
484
+ forced-color-adjust: none;
485
+ }
486
+
487
+ #nr-connect-sidebar .red-ui-button:focus-visible,
488
+ #nr-connect-sidebar .nrc-textarea:focus-visible,
489
+ #nr-connect-sidebar .nrc-link:focus-visible {
490
+ outline: 2px solid Highlight;
491
+ }
492
+
493
+ i.nrc-sidebar-icon,
494
+ i.red-ui-tab-icon.nrc-sidebar-icon {
495
+ forced-color-adjust: none;
496
+ }
497
+ }
498
+ </style>
499
+
500
+ <script type="text/javascript">
501
+ (function () {
502
+ "use strict";
503
+
504
+ const STATUS_TOPIC = "nr-connect/status";
505
+ const COPY_FEEDBACK_MS = 2000;
506
+ const QUICKSTART_DOCS_URL = "https://nr-connect.com/docs/quickstart";
507
+ const COMMUNITY_ISSUES_URL = "https://github.com/nr-connect/community/issues";
508
+ const STATUS_URL = "https://status.nr-connect.com";
509
+
510
+ const STRINGS = {
511
+ tabLabel: "NR Connect",
512
+ loadingText: "Checking connection status...",
513
+ envNote: "This connection is set by the server environment.",
514
+ notConnectedExplainer:
515
+ "Get a connection code from your NR Connect dashboard to give your team a secure address for this Node-RED.",
516
+ codeLabel: "Connection code",
517
+ codeHint: "Paste the full code generated for this instance.",
518
+ codePlaceholder: "Paste connection code here...",
519
+ codeRequiredError: "Paste your connection code before connecting.",
520
+ connectBtn: "Connect",
521
+ connectingBtn: "Connecting...",
522
+ useDifferentCancel: "Cancel",
523
+ statusNotConnected: "Not connected",
524
+ statusInvalid: "This code is no longer valid",
525
+ statusUnreachable: "Can't reach NR Connect",
526
+ statusFailed: "Connection failed",
527
+ statusReconnecting: "Reconnecting...",
528
+ statusConnecting: "Connecting...",
529
+ statusConnected: "Connected",
530
+ pasteNewCodeLink: "Paste a new code",
531
+ checkInNowTooltip: "Sync now",
532
+ checkInNever: "Not synced yet",
533
+ checkInJustNow: "Synced just now",
534
+ checkInLabelPrefix: "Last synced ",
535
+ checkInFailedToast: "Couldn't reach NR Connect right now.",
536
+ addressHeading: "Secure address",
537
+ copyBtn: "Copy",
538
+ copiedFeedback: "Copied",
539
+ copiedAnnouncement: "Copied secure address",
540
+ copyFailedAnnouncement: "Couldn't copy automatically",
541
+ openBtn: "Open",
542
+ qrBtn: "QR",
543
+ qrLoading: "Generating QR code...",
544
+ qrLoadFailed: "Couldn't generate QR code right now.",
545
+ qrTargetHome: "Instance home",
546
+ qrDownloadPngBtn: "Download PNG",
547
+ qrDownloadSvgBtn: "SVG",
548
+ qrScanHint: "Scan to open and sign in",
549
+ qrDownloadFailedToast: "Couldn't download QR code image.",
550
+ secureAccessHeading: "Require secure access",
551
+ secureAccessOn: "On",
552
+ secureAccessOff: "Off",
553
+ secureAccessChangeLink: "Change in NR Connect",
554
+ pagesHeading: "Dashboard pages",
555
+ pagesEmpty: "No dashboard pages found yet.",
556
+ pagesHint:
557
+ "Pages are shared automatically when you deploy. Manage who can see them in NR Connect.",
558
+ manageLink: "Manage in NR Connect",
559
+ useDifferentCodeBtn: "Use a different code",
560
+ disconnectBtn: "Disconnect",
561
+ disconnectingBtn: "Disconnecting...",
562
+ confirmDisconnectTitle: "Disconnect from NR Connect?",
563
+ confirmDisconnectBody:
564
+ "Your team won't be able to reach this Node-RED through NR Connect until you connect again.",
565
+ confirmReplaceTitle: "Use a different connection code?",
566
+ confirmReplaceBody:
567
+ "This will replace your current connection with a new code.",
568
+ confirmSelfLockoutWarning:
569
+ "You're using Node-RED through your secure address. Disconnecting will close this page, and you'll need local network access to get back in.",
570
+ confirmCancel: "Cancel",
571
+ confirmDisconnectProceed: "Disconnect",
572
+ confirmReplaceProceed: "Continue",
573
+ disconnectedToast: "Disconnected from NR Connect.",
574
+ versionsHeading: "Versions & updates",
575
+ pluginVersionLabel: "Plugin",
576
+ connectorVersionLabel: "Connector",
577
+ connectorSourceSystem: "Host-installed",
578
+ updateAvailableTag: "Update available",
579
+ updateRequiredTag: "Update required",
580
+ pluginUpdateGuidePalette:
581
+ "Update in Menu -> Manage palette, then restart Node-RED.",
582
+ pluginUpdateGuideEnv:
583
+ "Update the container image or runtime package, then restart Node-RED.",
584
+ connectorUpdateBtn: "Update connector",
585
+ connectorUpdatingBtn: "Updating...",
586
+ connectorSystemUpdateRequiredNote:
587
+ "Installed on the host. Update the host package or container image, then restart Node-RED.",
588
+ connectorSystemUpdateAvailableNote:
589
+ "Installed on the host. Update the host package or container image to upgrade.",
590
+ connectorUpdatedToast: "Connector updated.",
591
+ connectorUpdateFailedToast: "Couldn't update the connector right now.",
592
+ supportLink: "Support & docs",
593
+ setupGuideLink: "Setup guide",
594
+ reportIssueLink: "Report an issue",
595
+ statusLink: "System status",
596
+ copyDiagnosticsBtn: "Copy diagnostics",
597
+ copiedDiagnosticsToast: "Redacted diagnostics copied to clipboard.",
598
+ copyDiagnosticsFailedToast: "Couldn't copy diagnostics right now.",
599
+ genericError: "Something went wrong. Please try again.",
600
+ };
601
+
602
+ function safeHttpUrl(raw) {
603
+ if (typeof raw !== "string" || !raw.trim()) return null;
604
+ try {
605
+ const parsed = new URL(raw.trim());
606
+ if (parsed.protocol === "https:" || parsed.protocol === "http:") {
607
+ return parsed.href.replace(/\/+$/, "");
608
+ }
609
+ } catch {
610
+ return null;
611
+ }
612
+ return null;
613
+ }
614
+
615
+ function extractHost(url) {
616
+ if (!url) return null;
617
+ try {
618
+ return new URL(url).host;
619
+ } catch {
620
+ return null;
621
+ }
622
+ }
623
+
624
+ function buildManageUrl(status) {
625
+ const portalUrl = safeHttpUrl(status && status.portalUrl);
626
+ const id = status && typeof status.instanceId === "string" ? status.instanceId.trim() : "";
627
+ if (!portalUrl || !id) return null;
628
+ return portalUrl + "/instances/" + encodeURIComponent(id);
629
+ }
630
+
631
+ function buildSettingsUrl(status) {
632
+ const manageUrl = buildManageUrl(status);
633
+ return manageUrl ? manageUrl + "/settings" : null;
634
+ }
635
+
636
+ function buildSupportUrl(status) {
637
+ const portalUrl = safeHttpUrl(status && status.portalUrl);
638
+ if (portalUrl) return portalUrl + "/support";
639
+ return "https://nr-connect.com/support";
640
+ }
641
+
642
+ function isSelfLockoutRisk(status) {
643
+ const publicUrl = safeHttpUrl(status && status.url);
644
+ if (!publicUrl || !window.location || !window.location.hostname) return false;
645
+ try {
646
+ const targetHost = new URL(publicUrl).hostname.toLowerCase();
647
+ return window.location.hostname.toLowerCase() === targetHost;
648
+ } catch {
649
+ return false;
650
+ }
651
+ }
652
+
653
+ const rtf =
654
+ typeof Intl !== "undefined" && typeof Intl.RelativeTimeFormat === "function"
655
+ ? new Intl.RelativeTimeFormat("en", { numeric: "auto", style: "short" })
656
+ : null;
657
+
658
+ function formatRelativeCheckIn(isoString) {
659
+ if (!isoString) return STRINGS.checkInNever;
660
+ const ms = Date.parse(isoString);
661
+ if (!Number.isFinite(ms)) return STRINGS.checkInNever;
662
+
663
+ const diffSec = Math.max(0, Math.floor((Date.now() - ms) / 1000));
664
+ if (diffSec < 5) return STRINGS.checkInJustNow;
665
+
666
+ let value = -diffSec;
667
+ let unit = "second";
668
+ if (diffSec >= 86400) {
669
+ value = -Math.floor(diffSec / 86400);
670
+ unit = "day";
671
+ } else if (diffSec >= 3600) {
672
+ value = -Math.floor(diffSec / 3600);
673
+ unit = "hour";
674
+ } else if (diffSec >= 60) {
675
+ value = -Math.floor(diffSec / 60);
676
+ unit = "minute";
677
+ }
678
+
679
+ if (rtf) {
680
+ return STRINGS.checkInLabelPrefix + rtf.format(value, unit);
681
+ }
682
+ const abs = Math.abs(value);
683
+ const shortUnit = unit === "second" ? "s" : unit === "minute" ? "m" : unit === "hour" ? "h" : "d";
684
+ return STRINGS.checkInLabelPrefix + abs + " " + shortUnit + " ago";
685
+ }
686
+
687
+ function getStatusPresentation(status) {
688
+ if (!status || !status.connected) {
689
+ return {
690
+ tone: "neutral",
691
+ icon: "fa-circle-o",
692
+ text: STRINGS.statusNotConnected,
693
+ showPasteNewCode: false,
694
+ };
695
+ }
696
+
697
+ const checkInState = status.checkIn && status.checkIn.state ? status.checkIn.state : "never";
698
+ const connector = status.connector || "preparing";
699
+
700
+ if (checkInState === "invalid") {
701
+ return {
702
+ tone: "error",
703
+ icon: "fa-exclamation-circle",
704
+ text: STRINGS.statusInvalid,
705
+ showPasteNewCode: !status.managedByEnv,
706
+ };
707
+ }
708
+ if (checkInState === "unreachable") {
709
+ return {
710
+ tone: "error",
711
+ icon: "fa-exclamation-triangle",
712
+ text: STRINGS.statusUnreachable,
713
+ showPasteNewCode: false,
714
+ };
715
+ }
716
+ if (connector === "error" || connector === "stopped") {
717
+ return {
718
+ tone: "error",
719
+ icon: "fa-exclamation-circle",
720
+ text: STRINGS.statusFailed,
721
+ showPasteNewCode: false,
722
+ };
723
+ }
724
+ if (connector === "reconnecting") {
725
+ return {
726
+ tone: "warning",
727
+ icon: "fa-refresh fa-spin",
728
+ text: STRINGS.statusReconnecting,
729
+ showPasteNewCode: false,
730
+ };
731
+ }
732
+ if (connector === "preparing" || connector === "connecting" || checkInState === "never") {
733
+ return {
734
+ tone: "warning",
735
+ icon: "fa-circle-o-notch fa-spin",
736
+ text: STRINGS.statusConnecting,
737
+ showPasteNewCode: false,
738
+ };
739
+ }
740
+ return {
741
+ tone: "success",
742
+ icon: "fa-check-circle",
743
+ text: STRINGS.statusConnected,
744
+ showPasteNewCode: false,
745
+ };
746
+ }
747
+
748
+ function legacyCopyText(text) {
749
+ const helper = document.createElement("textarea");
750
+ helper.value = text;
751
+ helper.setAttribute("readonly", "");
752
+ helper.style.position = "fixed";
753
+ helper.style.top = "-9999px";
754
+ helper.style.left = "-9999px";
755
+ document.body.appendChild(helper);
756
+ helper.select();
757
+ let ok = false;
758
+ try {
759
+ ok = document.execCommand("copy");
760
+ } catch {
761
+ ok = false;
762
+ }
763
+ document.body.removeChild(helper);
764
+ return ok;
765
+ }
766
+
767
+ function copyTextToClipboard(text) {
768
+ if (window.isSecureContext && navigator.clipboard && navigator.clipboard.writeText) {
769
+ return navigator.clipboard.writeText(text).then(
770
+ function () {
771
+ return true;
772
+ },
773
+ function () {
774
+ return legacyCopyText(text);
775
+ }
776
+ );
777
+ }
778
+ return Promise.resolve(legacyCopyText(text));
779
+ }
780
+
781
+ function confirmWithNotify(options) {
782
+ if (!RED || typeof RED.notify !== "function") {
783
+ options.onConfirm();
784
+ return;
785
+ }
786
+
787
+ const $content = $("<div>");
788
+ $("<p>", { style: "margin: 0 0 8px; font-weight: 600;" }).text(options.title).appendTo($content);
789
+ $("<p>", { style: "margin: 0 0 8px;" }).text(options.body).appendTo($content);
790
+ if (options.lockoutWarning) {
791
+ $("<p>", {
792
+ style:
793
+ "margin: 0; padding: 8px; border-left: 3px solid var(--red-ui-border-color-warning, #e2a336); font-weight: 500;",
794
+ })
795
+ .text(options.lockoutWarning)
796
+ .appendTo($content);
797
+ }
798
+
799
+ let notification = null;
800
+ notification = RED.notify($content, {
801
+ type: "warning",
802
+ modal: true,
803
+ fixed: true,
804
+ buttons: [
805
+ {
806
+ text: STRINGS.confirmCancel,
807
+ click: function () {
808
+ notification.close();
809
+ },
810
+ },
811
+ {
812
+ text: options.proceedLabel,
813
+ class: "primary",
814
+ click: function () {
815
+ notification.close();
816
+ options.onConfirm();
817
+ },
818
+ },
819
+ ],
820
+ });
821
+ }
822
+
823
+ let cleanupPlugin = null;
824
+
825
+ RED.plugins.registerPlugin("nr-connect", {
826
+ onadd: function () {
827
+ const state = {
828
+ loaded: false,
829
+ status: {
830
+ connected: false,
831
+ managedByEnv: false,
832
+ instanceId: null,
833
+ portalUrl: null,
834
+ name: null,
835
+ url: null,
836
+ requireSecureAccess: false,
837
+ connector: "not_connected",
838
+ checkIn: { state: "never", at: null },
839
+ pages: [],
840
+ versions: { plugin: null, connector: null, connectorSource: null },
841
+ updates: null,
842
+ },
843
+ mode: "auto", // "auto" | "replace"
844
+ draftCode: "",
845
+ formError: null,
846
+ connecting: false,
847
+ checkingIn: false,
848
+ updatingConnector: false,
849
+ disconnecting: false,
850
+ copyResetTimer: null,
851
+ copyRepeatFlip: false,
852
+ qrOpen: false,
853
+ qrTargetPath: "",
854
+ qrLoading: false,
855
+ qrError: null,
856
+ qrData: null,
857
+ qrRequestSeq: 0,
858
+ };
859
+
860
+ const $container = $("<div>", { id: "nr-connect-sidebar" });
861
+ let currentViewKind = null;
862
+ let $formView = null;
863
+ let $connectedView = null;
864
+ let $formEnvBanner = null;
865
+ let $formInput = null;
866
+ let $formError = null;
867
+ let $formSubmitBtn = null;
868
+ let $formCancelBtn = null;
869
+
870
+ function applyCheckInTimestampText($target) {
871
+ if (!$target || !$target.length) return;
872
+ const at = state.status && state.status.checkIn ? state.status.checkIn.at : null;
873
+ $target.text(formatRelativeCheckIn(at));
874
+ }
875
+
876
+ function applyStatus(nextStatus) {
877
+ if (!nextStatus || typeof nextStatus !== "object") return;
878
+ const prevUrl = safeHttpUrl(state.status && state.status.url);
879
+ const nextUrl = safeHttpUrl(nextStatus.url);
880
+ state.loaded = true;
881
+ state.status = nextStatus;
882
+ if (!nextStatus.connected) {
883
+ if (state.mode === "replace") {
884
+ state.mode = "auto";
885
+ }
886
+ state.qrOpen = false;
887
+ state.qrTargetPath = "";
888
+ state.qrData = null;
889
+ state.qrError = null;
890
+ state.qrLoading = false;
891
+ } else if (prevUrl !== nextUrl) {
892
+ state.qrData = null;
893
+ if (state.qrOpen) {
894
+ fetchQrCode();
895
+ }
896
+ }
897
+ render();
898
+ }
899
+
900
+ function triggerBlobDownload(blob, filename) {
901
+ const objectUrl = URL.createObjectURL(blob);
902
+ const anchor = document.createElement("a");
903
+ anchor.href = objectUrl;
904
+ anchor.download = filename;
905
+ document.body.appendChild(anchor);
906
+ anchor.click();
907
+ document.body.removeChild(anchor);
908
+ setTimeout(function () {
909
+ URL.revokeObjectURL(objectUrl);
910
+ }, 1000);
911
+ }
912
+
913
+ function downloadQrSvg(qrData) {
914
+ if (!qrData || !qrData.svg) return;
915
+ try {
916
+ const blob = new Blob([qrData.svg], {
917
+ type: "image/svg+xml;charset=utf-8",
918
+ });
919
+ triggerBlobDownload(blob, (qrData.filenameBase || "instance-qr") + ".svg");
920
+ } catch {
921
+ RED.notify(STRINGS.qrDownloadFailedToast, "error");
922
+ }
923
+ }
924
+
925
+ function downloadQrPng(qrData) {
926
+ if (!qrData || !qrData.svg) return;
927
+ try {
928
+ const svgBlob = new Blob([qrData.svg], {
929
+ type: "image/svg+xml;charset=utf-8",
930
+ });
931
+ const svgUrl = URL.createObjectURL(svgBlob);
932
+ const img = new Image();
933
+ img.onload = function () {
934
+ try {
935
+ const canvas = document.createElement("canvas");
936
+ canvas.width = 1024;
937
+ canvas.height = 1024;
938
+ const ctx = canvas.getContext("2d");
939
+ if (!ctx) throw new Error("Canvas unavailable");
940
+ ctx.fillStyle = "#FFFFFF";
941
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
942
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
943
+ canvas.toBlob(function (pngBlob) {
944
+ URL.revokeObjectURL(svgUrl);
945
+ if (!pngBlob) {
946
+ RED.notify(STRINGS.qrDownloadFailedToast, "error");
947
+ return;
948
+ }
949
+ triggerBlobDownload(
950
+ pngBlob,
951
+ (qrData.filenameBase || "instance-qr") + ".png"
952
+ );
953
+ }, "image/png");
954
+ } catch {
955
+ URL.revokeObjectURL(svgUrl);
956
+ RED.notify(STRINGS.qrDownloadFailedToast, "error");
957
+ }
958
+ };
959
+ img.onerror = function () {
960
+ URL.revokeObjectURL(svgUrl);
961
+ RED.notify(STRINGS.qrDownloadFailedToast, "error");
962
+ };
963
+ img.src = svgUrl;
964
+ } catch {
965
+ RED.notify(STRINGS.qrDownloadFailedToast, "error");
966
+ }
967
+ }
968
+
969
+ function fetchQrCode() {
970
+ const seq = ++state.qrRequestSeq;
971
+ const targetPath = state.qrTargetPath || "";
972
+ state.qrLoading = true;
973
+ state.qrError = null;
974
+ render();
975
+
976
+ $.ajax({
977
+ url: targetPath
978
+ ? "nr-connect/qr?path=" + encodeURIComponent(targetPath)
979
+ : "nr-connect/qr",
980
+ method: "GET",
981
+ dataType: "json",
982
+ })
983
+ .done(function (data) {
984
+ if (seq !== state.qrRequestSeq) return;
985
+ state.qrLoading = false;
986
+ state.qrError = null;
987
+ state.qrData = {
988
+ url: data && data.url ? data.url : "",
989
+ title: data && data.title ? data.title : "",
990
+ filenameBase: data && data.filenameBase ? data.filenameBase : "instance-qr",
991
+ svg: data && data.svg ? data.svg : "",
992
+ targetPath: targetPath,
993
+ };
994
+ render();
995
+ })
996
+ .fail(function () {
997
+ if (seq !== state.qrRequestSeq) return;
998
+ state.qrLoading = false;
999
+ state.qrData = null;
1000
+ state.qrError = STRINGS.qrLoadFailed;
1001
+ render();
1002
+ });
1003
+ }
1004
+
1005
+ function fetchStatus() {
1006
+ $.ajax({
1007
+ url: "nr-connect/status",
1008
+ method: "GET",
1009
+ dataType: "json",
1010
+ })
1011
+ .done(function (data) {
1012
+ applyStatus(data);
1013
+ })
1014
+ .fail(function () {
1015
+ if (!state.loaded) {
1016
+ state.loaded = true;
1017
+ render();
1018
+ }
1019
+ });
1020
+ }
1021
+
1022
+ function ensureFormView() {
1023
+ if ($formView) return $formView;
1024
+
1025
+ $formView = $("<div>", { class: "nrc-card", id: "nrc-code-form-card" });
1026
+ $formEnvBanner = $("<div>", { class: "nrc-env-banner", hidden: true });
1027
+ $("<i>", { class: "fa fa-info-circle", "aria-hidden": "true" }).appendTo($formEnvBanner);
1028
+ $("<span>").text(STRINGS.envNote).appendTo($formEnvBanner);
1029
+ $formEnvBanner.appendTo($formView);
1030
+
1031
+ $("<p>", { class: "nrc-muted" }).text(STRINGS.notConnectedExplainer).appendTo($formView);
1032
+
1033
+ const $form = $("<form>", { novalidate: "novalidate", class: "nrc-field" });
1034
+ $("<label>", { class: "nrc-label", for: "nrc-code-input" })
1035
+ .text(STRINGS.codeLabel)
1036
+ .appendTo($form);
1037
+ $("<p>", { id: "nrc-code-hint", class: "nrc-muted" })
1038
+ .text(STRINGS.codeHint)
1039
+ .appendTo($form);
1040
+
1041
+ $formInput = $("<textarea>", {
1042
+ id: "nrc-code-input",
1043
+ class: "nrc-textarea",
1044
+ placeholder: STRINGS.codePlaceholder,
1045
+ autocorrect: "off",
1046
+ autocapitalize: "none",
1047
+ spellcheck: "false",
1048
+ "aria-invalid": "false",
1049
+ "aria-describedby": "nrc-code-hint",
1050
+ })
1051
+ .attr("autocomplete", "off")
1052
+ .appendTo($form);
1053
+
1054
+ $formError = $("<p>", {
1055
+ id: "nrc-code-error",
1056
+ class: "nrc-field-error",
1057
+ role: "alert",
1058
+ hidden: true,
1059
+ }).appendTo($form);
1060
+
1061
+ const $btnRow = $("<div>", { class: "nrc-actions", style: "margin-top: 4px;" }).appendTo($form);
1062
+ $formSubmitBtn = $("<button>", {
1063
+ type: "submit",
1064
+ id: "nrc-connect-btn",
1065
+ class: "red-ui-button primary",
1066
+ }).appendTo($btnRow);
1067
+
1068
+ $formCancelBtn = $("<button>", {
1069
+ type: "button",
1070
+ id: "nrc-replace-cancel-btn",
1071
+ class: "red-ui-button",
1072
+ hidden: true,
1073
+ })
1074
+ .text(STRINGS.useDifferentCancel)
1075
+ .appendTo($btnRow);
1076
+
1077
+ $formInput.on("input", function () {
1078
+ state.draftCode = $formInput.val();
1079
+ if (state.formError) {
1080
+ state.formError = null;
1081
+ updateFormState();
1082
+ }
1083
+ });
1084
+
1085
+ $formCancelBtn.on("click", function () {
1086
+ if (state.connecting) return;
1087
+ state.mode = "auto";
1088
+ state.formError = null;
1089
+ state.draftCode = "";
1090
+ render();
1091
+ });
1092
+
1093
+ $form.on("submit", function (evt) {
1094
+ evt.preventDefault();
1095
+ if (state.connecting || state.status.managedByEnv) return;
1096
+
1097
+ const trimmed = String($formInput.val() || "").trim();
1098
+ state.draftCode = $formInput.val();
1099
+ if (!trimmed) {
1100
+ state.formError = STRINGS.codeRequiredError;
1101
+ updateFormState();
1102
+ $formInput.trigger("focus");
1103
+ return;
1104
+ }
1105
+
1106
+ state.connecting = true;
1107
+ state.formError = null;
1108
+ updateFormState();
1109
+
1110
+ $.ajax({
1111
+ url: "nr-connect/connect",
1112
+ method: "POST",
1113
+ contentType: "application/json",
1114
+ data: JSON.stringify({ code: trimmed }),
1115
+ dataType: "json",
1116
+ })
1117
+ .done(function (data) {
1118
+ state.connecting = false;
1119
+ state.draftCode = "";
1120
+ state.formError = null;
1121
+ state.mode = "auto";
1122
+ applyStatus(data);
1123
+ })
1124
+ .fail(function (xhr) {
1125
+ state.connecting = false;
1126
+ const serverMsg =
1127
+ xhr && xhr.responseJSON && typeof xhr.responseJSON.error === "string"
1128
+ ? xhr.responseJSON.error
1129
+ : null;
1130
+ state.formError = serverMsg || STRINGS.genericError;
1131
+ updateFormState();
1132
+ $formInput.trigger("focus");
1133
+ });
1134
+ });
1135
+
1136
+ $form.appendTo($formView);
1137
+
1138
+ const $formFooter = $("<div>", { class: "nrc-footer" }).appendTo($formView);
1139
+ const $formLinks = $("<div>", { class: "nrc-footer-links" }).appendTo($formFooter);
1140
+
1141
+ $("<a>", {
1142
+ class: "nrc-link",
1143
+ href: QUICKSTART_DOCS_URL,
1144
+ target: "_blank",
1145
+ rel: "noopener noreferrer",
1146
+ })
1147
+ .text(STRINGS.setupGuideLink)
1148
+ .appendTo($formLinks);
1149
+
1150
+ $("<a>", {
1151
+ class: "nrc-link",
1152
+ href: buildSupportUrl(null),
1153
+ target: "_blank",
1154
+ rel: "noopener noreferrer",
1155
+ })
1156
+ .text(STRINGS.supportLink)
1157
+ .appendTo($formLinks);
1158
+
1159
+ $("<a>", {
1160
+ class: "nrc-link",
1161
+ href: COMMUNITY_ISSUES_URL,
1162
+ target: "_blank",
1163
+ rel: "noopener noreferrer",
1164
+ })
1165
+ .text(STRINGS.reportIssueLink)
1166
+ .appendTo($formLinks);
1167
+
1168
+ $("<a>", {
1169
+ class: "nrc-link",
1170
+ href: STATUS_URL,
1171
+ target: "_blank",
1172
+ rel: "noopener noreferrer",
1173
+ })
1174
+ .text(STRINGS.statusLink)
1175
+ .appendTo($formLinks);
1176
+
1177
+ $("<button>", {
1178
+ type: "button",
1179
+ id: "nrc-form-copy-diagnostics-btn",
1180
+ class: "nrc-link-btn",
1181
+ })
1182
+ .text(STRINGS.copyDiagnosticsBtn)
1183
+ .on("click", handleCopyDiagnosticsClick)
1184
+ .appendTo($formLinks);
1185
+
1186
+ return $formView;
1187
+ }
1188
+
1189
+ function updateFormState() {
1190
+ ensureFormView();
1191
+ const isReplace = state.mode === "replace" && state.status.connected;
1192
+ const envManaged = Boolean(state.status.managedByEnv);
1193
+
1194
+ if ($formInput.val() !== state.draftCode && document.activeElement !== $formInput[0]) {
1195
+ $formInput.val(state.draftCode);
1196
+ }
1197
+
1198
+ $formEnvBanner.prop("hidden", !envManaged);
1199
+ $formCancelBtn.prop("hidden", !isReplace);
1200
+
1201
+ if (state.formError) {
1202
+ $formError.text(state.formError).prop("hidden", false);
1203
+ $formInput.attr("aria-invalid", "true").attr("aria-describedby", "nrc-code-hint nrc-code-error");
1204
+ } else {
1205
+ $formError.text("").prop("hidden", true);
1206
+ $formInput.attr("aria-invalid", "false").attr("aria-describedby", "nrc-code-hint");
1207
+ }
1208
+
1209
+ $formSubmitBtn.prop("disabled", state.connecting || envManaged).empty();
1210
+ if (state.connecting) {
1211
+ $("<i>", { class: "fa fa-spinner fa-spin", "aria-hidden": "true" }).appendTo($formSubmitBtn);
1212
+ $("<span>").text(STRINGS.connectingBtn).appendTo($formSubmitBtn);
1213
+ } else {
1214
+ $formSubmitBtn.text(STRINGS.connectBtn);
1215
+ }
1216
+ }
1217
+
1218
+ function openReplaceCodeFlow() {
1219
+ if (state.status.managedByEnv || state.disconnecting) return;
1220
+ const lockoutWarning = isSelfLockoutRisk(state.status) ? STRINGS.confirmSelfLockoutWarning : "";
1221
+ confirmWithNotify({
1222
+ title: STRINGS.confirmReplaceTitle,
1223
+ body: STRINGS.confirmReplaceBody,
1224
+ lockoutWarning: lockoutWarning,
1225
+ proceedLabel: STRINGS.confirmReplaceProceed,
1226
+ onConfirm: function () {
1227
+ state.mode = "replace";
1228
+ state.formError = null;
1229
+ state.draftCode = "";
1230
+ render();
1231
+ if ($formInput) $formInput.trigger("focus");
1232
+ },
1233
+ });
1234
+ }
1235
+
1236
+ function handleCheckInClick() {
1237
+ if (state.checkingIn || !state.status.connected) return;
1238
+ state.checkingIn = true;
1239
+ render();
1240
+
1241
+ $.ajax({
1242
+ url: "nr-connect/check-in",
1243
+ method: "POST",
1244
+ dataType: "json",
1245
+ })
1246
+ .done(function (data) {
1247
+ state.checkingIn = false;
1248
+ if (data && data.checkIn && data.checkIn.state === "unreachable") {
1249
+ RED.notify(STRINGS.checkInFailedToast, "error");
1250
+ }
1251
+ applyStatus(data);
1252
+ })
1253
+ .fail(function (xhr) {
1254
+ state.checkingIn = false;
1255
+ const msg =
1256
+ xhr && xhr.responseJSON && typeof xhr.responseJSON.error === "string"
1257
+ ? xhr.responseJSON.error
1258
+ : STRINGS.checkInFailedToast;
1259
+ RED.notify(msg, "error");
1260
+ render();
1261
+ });
1262
+ }
1263
+
1264
+ function handleUpdateConnectorClick() {
1265
+ const updates = state.status && state.status.updates ? state.status.updates : null;
1266
+ const isUpdating = state.updatingConnector || Boolean(updates && updates.connector && updates.connector.updating);
1267
+ if (isUpdating || !state.status.connected) return;
1268
+
1269
+ state.updatingConnector = true;
1270
+ render();
1271
+
1272
+ $.ajax({
1273
+ url: "nr-connect/update-connector",
1274
+ method: "POST",
1275
+ dataType: "json",
1276
+ })
1277
+ .done(function (data) {
1278
+ state.updatingConnector = false;
1279
+ RED.notify(STRINGS.connectorUpdatedToast, "success");
1280
+ applyStatus(data);
1281
+ })
1282
+ .fail(function (xhr) {
1283
+ state.updatingConnector = false;
1284
+ const msg =
1285
+ xhr && xhr.responseJSON && typeof xhr.responseJSON.error === "string"
1286
+ ? xhr.responseJSON.error
1287
+ : STRINGS.connectorUpdateFailedToast;
1288
+ RED.notify(msg, "error");
1289
+ render();
1290
+ });
1291
+ }
1292
+
1293
+ function handleCopyDiagnosticsClick() {
1294
+ $.ajax({
1295
+ url: "nr-connect/diagnostics",
1296
+ method: "GET",
1297
+ dataType: "json",
1298
+ })
1299
+ .done(function (diag) {
1300
+ const formatted = "```json\n" + JSON.stringify(diag, null, 2) + "\n```";
1301
+ copyTextToClipboard(formatted).then(function (ok) {
1302
+ if (ok) {
1303
+ RED.notify(STRINGS.copiedDiagnosticsToast, "success");
1304
+ } else {
1305
+ RED.notify(STRINGS.copyDiagnosticsFailedToast, "error");
1306
+ }
1307
+ });
1308
+ })
1309
+ .fail(function () {
1310
+ RED.notify(STRINGS.copyDiagnosticsFailedToast, "error");
1311
+ });
1312
+ }
1313
+
1314
+ function handleDisconnectClick() {
1315
+ if (state.status.managedByEnv || state.disconnecting) return;
1316
+ const lockoutWarning = isSelfLockoutRisk(state.status) ? STRINGS.confirmSelfLockoutWarning : "";
1317
+ confirmWithNotify({
1318
+ title: STRINGS.confirmDisconnectTitle,
1319
+ body: STRINGS.confirmDisconnectBody,
1320
+ lockoutWarning: lockoutWarning,
1321
+ proceedLabel: STRINGS.confirmDisconnectProceed,
1322
+ onConfirm: function () {
1323
+ state.disconnecting = true;
1324
+ render();
1325
+
1326
+ $.ajax({
1327
+ url: "nr-connect/disconnect",
1328
+ method: "POST",
1329
+ dataType: "json",
1330
+ })
1331
+ .done(function (data) {
1332
+ state.disconnecting = false;
1333
+ state.mode = "auto";
1334
+ state.draftCode = "";
1335
+ state.formError = null;
1336
+ RED.notify(STRINGS.disconnectedToast, "success");
1337
+ applyStatus(data);
1338
+ })
1339
+ .fail(function (xhr) {
1340
+ state.disconnecting = false;
1341
+ const msg =
1342
+ xhr && xhr.responseJSON && typeof xhr.responseJSON.error === "string"
1343
+ ? xhr.responseJSON.error
1344
+ : STRINGS.genericError;
1345
+ RED.notify(msg, "error");
1346
+ render();
1347
+ });
1348
+ },
1349
+ });
1350
+ }
1351
+
1352
+ function buildConnectedView() {
1353
+ const s = state.status;
1354
+ const $root = $("<div>", {
1355
+ id: "nrc-connected-view",
1356
+ style: "display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto;",
1357
+ });
1358
+
1359
+ if (s.managedByEnv) {
1360
+ const $env = $("<div>", { class: "nrc-env-banner" });
1361
+ $("<i>", { class: "fa fa-info-circle", "aria-hidden": "true" }).appendTo($env);
1362
+ $("<span>").text(STRINGS.envNote).appendTo($env);
1363
+ $env.appendTo($root);
1364
+ }
1365
+
1366
+ // 1. Status pill + Last check-in + Check in now button
1367
+ const pres = getStatusPresentation(s);
1368
+ const $statusCard = $("<div>", { class: "nrc-card" }).appendTo($root);
1369
+ const $statusRow = $("<div>", { class: "nrc-row-between" }).appendTo($statusCard);
1370
+ const $statusWrap = $("<div>", { class: "nrc-status-wrap" }).appendTo($statusRow);
1371
+
1372
+ const $pill = $("<span>", {
1373
+ class: "nrc-pill nrc-pill-" + pres.tone,
1374
+ }).appendTo($statusWrap);
1375
+ $("<span>", { class: "nrc-dot", "aria-hidden": "true" }).appendTo($pill);
1376
+ $("<i>", { class: "fa " + pres.icon, "aria-hidden": "true" }).appendTo($pill);
1377
+ $("<span>").text(pres.text).appendTo($pill);
1378
+
1379
+ const $checkInText = $("<p>", {
1380
+ class: "nrc-muted",
1381
+ "data-nrc-checkin-time": "1",
1382
+ }).appendTo($statusWrap);
1383
+ applyCheckInTimestampText($checkInText);
1384
+
1385
+ const $checkInBtn = $("<button>", {
1386
+ type: "button",
1387
+ id: "nrc-checkin-btn",
1388
+ class: "red-ui-button nrc-btn-icon",
1389
+ "aria-label": STRINGS.checkInNowTooltip,
1390
+ }).appendTo($statusRow);
1391
+ $checkInBtn.prop("disabled", state.checkingIn);
1392
+ $("<i>", {
1393
+ class: "fa fa-refresh" + (state.checkingIn ? " fa-spin" : ""),
1394
+ "aria-hidden": "true",
1395
+ }).appendTo($checkInBtn);
1396
+ if (RED.popover && typeof RED.popover.tooltip === "function") {
1397
+ RED.popover.tooltip($checkInBtn, STRINGS.checkInNowTooltip);
1398
+ }
1399
+ $checkInBtn.on("click", handleCheckInClick);
1400
+
1401
+ if (pres.showPasteNewCode) {
1402
+ $("<button>", {
1403
+ type: "button",
1404
+ id: "nrc-paste-new-code-btn",
1405
+ class: "nrc-link-btn",
1406
+ })
1407
+ .text(STRINGS.pasteNewCodeLink)
1408
+ .on("click", openReplaceCodeFlow)
1409
+ .appendTo($statusCard);
1410
+ }
1411
+
1412
+ // 2. Instance name & secure address card (shown only when portal supplies name or url)
1413
+ const publicUrl = safeHttpUrl(s.url);
1414
+ const displayHost = extractHost(publicUrl);
1415
+ const instanceName = typeof s.name === "string" && s.name.trim() ? s.name.trim() : null;
1416
+
1417
+ if (instanceName || publicUrl) {
1418
+ const $addrCard = $("<div>", { class: "nrc-card" }).appendTo($root);
1419
+ $("<p>", { class: "nrc-section-label" }).text(STRINGS.addressHeading).appendTo($addrCard);
1420
+ if (instanceName) {
1421
+ $("<p>", { class: "nrc-instance-name" }).text(instanceName).appendTo($addrCard);
1422
+ }
1423
+ if (publicUrl) {
1424
+ $("<div>", { class: "nrc-address-text" }).text(displayHost || publicUrl).appendTo($addrCard);
1425
+
1426
+ const $addrActions = $("<div>", { class: "nrc-actions" }).appendTo($addrCard);
1427
+ const $copyWrap = $("<div>", { class: "nrc-copy-wrap" }).appendTo($addrActions);
1428
+ const $copyBtn = $("<button>", {
1429
+ type: "button",
1430
+ id: "nrc-copy-btn",
1431
+ class: "red-ui-button",
1432
+ }).appendTo($copyWrap);
1433
+ const $copyIcon = $("<i>", {
1434
+ class: "fa fa-clipboard",
1435
+ "aria-hidden": "true",
1436
+ }).appendTo($copyBtn);
1437
+ $("<span>").text(STRINGS.copyBtn).appendTo($copyBtn);
1438
+
1439
+ const $copyStatus = $("<span>", {
1440
+ id: "nrc-copy-status",
1441
+ class: "nrc-copy-status",
1442
+ role: "status",
1443
+ "aria-live": "polite",
1444
+ }).appendTo($copyWrap);
1445
+
1446
+ $copyBtn.on("click", function () {
1447
+ copyTextToClipboard(publicUrl).then(function (ok) {
1448
+ if (state.copyResetTimer) {
1449
+ clearTimeout(state.copyResetTimer);
1450
+ }
1451
+ state.copyRepeatFlip = !state.copyRepeatFlip;
1452
+ const suffix = state.copyRepeatFlip ? "" : "\u00A0";
1453
+
1454
+ if (ok) {
1455
+ $copyIcon.attr("class", "fa fa-check");
1456
+ $copyStatus
1457
+ .attr("class", "nrc-copy-status is-visible")
1458
+ .text(STRINGS.copiedFeedback + suffix);
1459
+ $copyBtn.attr("aria-label", STRINGS.copiedAnnouncement);
1460
+ } else {
1461
+ $copyStatus
1462
+ .attr("class", "nrc-copy-status is-visible is-error")
1463
+ .text(STRINGS.copyFailedAnnouncement + suffix);
1464
+ }
1465
+
1466
+ state.copyResetTimer = setTimeout(function () {
1467
+ $copyIcon.attr("class", "fa fa-clipboard");
1468
+ $copyStatus.removeClass("is-visible");
1469
+ $copyBtn.removeAttr("aria-label");
1470
+ }, COPY_FEEDBACK_MS);
1471
+ });
1472
+ });
1473
+
1474
+ const $openLink = $("<a>", {
1475
+ id: "nrc-open-btn",
1476
+ class: "red-ui-button",
1477
+ href: publicUrl,
1478
+ target: "_blank",
1479
+ rel: "noopener noreferrer",
1480
+ }).appendTo($addrActions);
1481
+ $("<span>").text(STRINGS.openBtn).appendTo($openLink);
1482
+ $("<i>", { class: "fa fa-external-link", "aria-hidden": "true" }).appendTo($openLink);
1483
+
1484
+ const $qrBtn = $("<button>", {
1485
+ type: "button",
1486
+ id: "nrc-qr-btn",
1487
+ class: "red-ui-button",
1488
+ "aria-expanded": state.qrOpen ? "true" : "false",
1489
+ "aria-controls": "nrc-qr-panel",
1490
+ }).appendTo($addrActions);
1491
+ $("<i>", { class: "fa fa-qrcode", "aria-hidden": "true" }).appendTo($qrBtn);
1492
+ $("<span>").text(STRINGS.qrBtn).appendTo($qrBtn);
1493
+ $qrBtn.on("click", function () {
1494
+ state.qrOpen = !state.qrOpen;
1495
+ if (
1496
+ state.qrOpen &&
1497
+ (!state.qrData || state.qrData.targetPath !== state.qrTargetPath)
1498
+ ) {
1499
+ fetchQrCode();
1500
+ } else {
1501
+ render();
1502
+ }
1503
+ });
1504
+
1505
+ if (state.qrOpen) {
1506
+ const $qrPanel = $("<div>", {
1507
+ id: "nrc-qr-panel",
1508
+ class: "nrc-qr-panel",
1509
+ }).appendTo($addrCard);
1510
+
1511
+ const qrPages = Array.isArray(s.pages) ? s.pages : [];
1512
+ if (qrPages.length > 0) {
1513
+ const $select = $("<select>", {
1514
+ id: "nrc-qr-target",
1515
+ class: "nrc-qr-select",
1516
+ "aria-label": "QR code destination",
1517
+ }).appendTo($qrPanel);
1518
+ $("<option>", { value: "" })
1519
+ .text(STRINGS.qrTargetHome)
1520
+ .appendTo($select);
1521
+ qrPages.forEach(function (page) {
1522
+ const rawP = typeof page.path === "string" ? page.path.trim() : "/";
1523
+ const cleanP = rawP.charAt(0) === "/" ? rawP : "/" + rawP;
1524
+ const label =
1525
+ typeof page.name === "string" && page.name.trim()
1526
+ ? "Dashboard: " + page.name.trim()
1527
+ : "Dashboard: " + cleanP;
1528
+ $("<option>", { value: cleanP }).text(label).appendTo($select);
1529
+ });
1530
+ $select.val(state.qrTargetPath);
1531
+ $select.on("change", function () {
1532
+ state.qrTargetPath = String($select.val() || "");
1533
+ fetchQrCode();
1534
+ });
1535
+ }
1536
+
1537
+ if (state.qrLoading) {
1538
+ $("<p>", { class: "nrc-muted" }).text(STRINGS.qrLoading).appendTo($qrPanel);
1539
+ } else if (state.qrError) {
1540
+ $("<p>", { class: "nrc-field-error", role: "alert" })
1541
+ .text(state.qrError)
1542
+ .appendTo($qrPanel);
1543
+ } else if (state.qrData && state.qrData.svg) {
1544
+ const $frame = $("<div>", { class: "nrc-qr-frame" }).appendTo($qrPanel);
1545
+ $("<img>", {
1546
+ id: "nrc-qr-image",
1547
+ class: "nrc-qr-img",
1548
+ src: "data:image/svg+xml;charset=utf-8," + encodeURIComponent(state.qrData.svg),
1549
+ alt: state.qrData.title || "Instance QR code",
1550
+ }).appendTo($frame);
1551
+
1552
+ $("<p>", { class: "nrc-qr-caption" })
1553
+ .text(
1554
+ (state.qrData.url || publicUrl).replace(/^https?:\/\//i, "") +
1555
+ " · " +
1556
+ STRINGS.qrScanHint
1557
+ )
1558
+ .appendTo($qrPanel);
1559
+
1560
+ const $qrActions = $("<div>", { class: "nrc-qr-actions" }).appendTo($qrPanel);
1561
+ const $pngBtn = $("<button>", {
1562
+ type: "button",
1563
+ id: "nrc-qr-download-png-btn",
1564
+ class: "red-ui-button",
1565
+ }).appendTo($qrActions);
1566
+ $("<i>", { class: "fa fa-download", "aria-hidden": "true" }).appendTo($pngBtn);
1567
+ $("<span>").text(STRINGS.qrDownloadPngBtn).appendTo($pngBtn);
1568
+ $pngBtn.on("click", function () {
1569
+ downloadQrPng(state.qrData);
1570
+ });
1571
+
1572
+ const $svgBtn = $("<button>", {
1573
+ type: "button",
1574
+ id: "nrc-qr-download-svg-btn",
1575
+ class: "red-ui-button",
1576
+ }).appendTo($qrActions);
1577
+ $("<i>", { class: "fa fa-download", "aria-hidden": "true" }).appendTo($svgBtn);
1578
+ $("<span>").text(STRINGS.qrDownloadSvgBtn).appendTo($svgBtn);
1579
+ $svgBtn.on("click", function () {
1580
+ downloadQrSvg(state.qrData);
1581
+ });
1582
+ }
1583
+ }
1584
+ }
1585
+ }
1586
+
1587
+ // 3. Require secure access (read-only) + link to portal settings
1588
+ const $secureCard = $("<div>", { class: "nrc-card" }).appendTo($root);
1589
+ const $secureHeader = $("<div>", { class: "nrc-row-between" }).appendTo($secureCard);
1590
+ $("<p>", { class: "nrc-section-label" }).text(STRINGS.secureAccessHeading).appendTo($secureHeader);
1591
+
1592
+ const secureOnly = Boolean(s.requireSecureAccess);
1593
+ const $secureBadge = $("<span>", {
1594
+ class: "nrc-secure-access-badge " + (secureOnly ? "is-on" : "is-off"),
1595
+ }).appendTo($secureHeader);
1596
+ $("<i>", {
1597
+ class: "fa " + (secureOnly ? "fa-lock" : "fa-unlock-alt"),
1598
+ "aria-hidden": "true",
1599
+ }).appendTo($secureBadge);
1600
+ $("<span>").text(secureOnly ? STRINGS.secureAccessOn : STRINGS.secureAccessOff).appendTo($secureBadge);
1601
+
1602
+ const settingsUrl = buildSettingsUrl(s);
1603
+ if (settingsUrl) {
1604
+ $("<a>", {
1605
+ class: "nrc-link",
1606
+ href: settingsUrl,
1607
+ target: "_blank",
1608
+ rel: "noopener noreferrer",
1609
+ })
1610
+ .text(STRINGS.secureAccessChangeLink)
1611
+ .appendTo($secureCard);
1612
+ }
1613
+
1614
+ // 4. Dashboard pages list + sharing hint
1615
+ const $pagesCard = $("<div>", { class: "nrc-card" }).appendTo($root);
1616
+ $("<p>", { class: "nrc-section-label" }).text(STRINGS.pagesHeading).appendTo($pagesCard);
1617
+
1618
+ const pages = Array.isArray(s.pages) ? s.pages : [];
1619
+ if (pages.length === 0) {
1620
+ $("<p>", { class: "nrc-muted" }).text(STRINGS.pagesEmpty).appendTo($pagesCard);
1621
+ } else {
1622
+ const $list = $("<ul>", { class: "nrc-page-list" }).appendTo($pagesCard);
1623
+ pages.forEach(function (page) {
1624
+ const $item = $("<li>", { class: "nrc-page-item" }).appendTo($list);
1625
+ const rawPath = typeof page.path === "string" ? page.path.trim() : "/";
1626
+ const cleanPath = rawPath.charAt(0) === "/" ? rawPath : "/" + rawPath;
1627
+ const pageName =
1628
+ typeof page.name === "string" && page.name.trim() ? page.name.trim() : cleanPath;
1629
+
1630
+ $("<span>", { class: "nrc-page-name" }).text(pageName).appendTo($item);
1631
+ if (publicUrl) {
1632
+ $("<a>", {
1633
+ class: "nrc-link nrc-page-path",
1634
+ href: publicUrl + cleanPath,
1635
+ target: "_blank",
1636
+ rel: "noopener noreferrer",
1637
+ })
1638
+ .text(cleanPath)
1639
+ .appendTo($item);
1640
+ } else {
1641
+ $("<span>", { class: "nrc-page-path" }).text(cleanPath).appendTo($item);
1642
+ }
1643
+ });
1644
+ }
1645
+
1646
+ $("<p>", { class: "nrc-muted" }).text(STRINGS.pagesHint).appendTo($pagesCard);
1647
+
1648
+ // 5. Versions & updates card
1649
+ const versions = s.versions || {};
1650
+ const updates = s.updates || {};
1651
+ const pluginInfo = updates.plugin || {};
1652
+ const connectorInfo = updates.connector || {};
1653
+
1654
+ function appendUpdateTag($meta, info) {
1655
+ if (!info || (!info.required && !info.available)) return;
1656
+ const isReq = Boolean(info.required);
1657
+ const $tag = $("<span>", {
1658
+ class: isReq ? "nrc-tag nrc-tag-error" : "nrc-tag nrc-tag-warning",
1659
+ }).appendTo($meta);
1660
+ $("<i>", {
1661
+ class: isReq ? "fa fa-exclamation-triangle" : "fa fa-arrow-circle-up",
1662
+ "aria-hidden": "true",
1663
+ }).appendTo($tag);
1664
+ $("<span>")
1665
+ .text(isReq ? STRINGS.updateRequiredTag : STRINGS.updateAvailableTag)
1666
+ .appendTo($tag);
1667
+ }
1668
+
1669
+ function formatUpdateTargetPrefix(info) {
1670
+ if (!info) return "";
1671
+ const min = typeof info.minimum === "string" ? info.minimum.trim().replace(/^v/i, "") : "";
1672
+ const latest = typeof info.latest === "string" ? info.latest.trim().replace(/^v/i, "") : "";
1673
+ if (info.required) {
1674
+ if (min && latest && min !== latest) {
1675
+ return "Requires v" + min + " or newer (latest v" + latest + "). ";
1676
+ }
1677
+ if (min || latest) {
1678
+ return "Requires v" + (min || latest) + " or newer. ";
1679
+ }
1680
+ return "";
1681
+ }
1682
+ if (info.available && latest) {
1683
+ return "v" + latest + " available. ";
1684
+ }
1685
+ return "";
1686
+ }
1687
+
1688
+ if (versions.plugin || versions.connector || connectorInfo.available || connectorInfo.required) {
1689
+ const $verCard = $("<div>", { class: "nrc-card", id: "nrc-versions-card" }).appendTo($root);
1690
+ $("<p>", { class: "nrc-section-label" }).text(STRINGS.versionsHeading).appendTo($verCard);
1691
+
1692
+ if (versions.plugin) {
1693
+ const $pRow = $("<div>", { class: "nrc-version-row" }).appendTo($verCard);
1694
+ $("<span>", { class: "nrc-muted" }).text(STRINGS.pluginVersionLabel).appendTo($pRow);
1695
+ const $pMeta = $("<span>", { class: "nrc-version-meta" }).appendTo($pRow);
1696
+ $("<span>", { class: "nrc-version-code" }).text("v" + versions.plugin).appendTo($pMeta);
1697
+ appendUpdateTag($pMeta, pluginInfo);
1698
+
1699
+ if (pluginInfo.available || pluginInfo.required) {
1700
+ const guide = s.managedByEnv
1701
+ ? STRINGS.pluginUpdateGuideEnv
1702
+ : STRINGS.pluginUpdateGuidePalette;
1703
+ $("<p>", { class: "nrc-muted" })
1704
+ .text(formatUpdateTargetPrefix(pluginInfo) + guide)
1705
+ .appendTo($verCard);
1706
+ }
1707
+ }
1708
+
1709
+ if (versions.connector || connectorInfo.available || connectorInfo.required) {
1710
+ const $cRow = $("<div>", { class: "nrc-version-row" }).appendTo($verCard);
1711
+ $("<span>", { class: "nrc-muted" }).text(STRINGS.connectorVersionLabel).appendTo($cRow);
1712
+ const $cMeta = $("<span>", { class: "nrc-version-meta" }).appendTo($cRow);
1713
+ if (versions.connector) {
1714
+ $("<span>", { class: "nrc-version-code" })
1715
+ .text("v" + versions.connector)
1716
+ .appendTo($cMeta);
1717
+ }
1718
+ if (versions.connectorSource === "system") {
1719
+ $("<span>", { class: "nrc-tag" })
1720
+ .text(STRINGS.connectorSourceSystem)
1721
+ .appendTo($cMeta);
1722
+ }
1723
+ appendUpdateTag($cMeta, connectorInfo);
1724
+
1725
+ const connectorUpdating = state.updatingConnector || Boolean(connectorInfo.updating);
1726
+ if (connectorInfo.canSelfUpdate && (connectorInfo.available || connectorInfo.required || connectorUpdating)) {
1727
+ if (connectorInfo.required) {
1728
+ const reqPrefix = formatUpdateTargetPrefix(connectorInfo).trim();
1729
+ if (reqPrefix) {
1730
+ $("<p>", { class: "nrc-muted" })
1731
+ .text(reqPrefix)
1732
+ .appendTo($verCard);
1733
+ }
1734
+ }
1735
+ const $cActions = $("<div>", { class: "nrc-actions" }).appendTo($verCard);
1736
+ const $updBtn = $("<button>", {
1737
+ type: "button",
1738
+ id: "nrc-update-connector-btn",
1739
+ class: "red-ui-button",
1740
+ })
1741
+ .prop("disabled", connectorUpdating)
1742
+ .on("click", handleUpdateConnectorClick)
1743
+ .appendTo($cActions);
1744
+ if (connectorUpdating) {
1745
+ $("<i>", { class: "fa fa-spinner fa-spin", "aria-hidden": "true" }).appendTo($updBtn);
1746
+ $("<span>").text(STRINGS.connectorUpdatingBtn).appendTo($updBtn);
1747
+ } else {
1748
+ const targetLabel = connectorInfo.latest
1749
+ ? STRINGS.connectorUpdateBtn + " (v" + connectorInfo.latest + ")"
1750
+ : STRINGS.connectorUpdateBtn;
1751
+ $updBtn.text(targetLabel);
1752
+ }
1753
+ } else if (
1754
+ versions.connectorSource === "system" &&
1755
+ (connectorInfo.available || connectorInfo.required)
1756
+ ) {
1757
+ const sysNote = connectorInfo.required
1758
+ ? STRINGS.connectorSystemUpdateRequiredNote
1759
+ : STRINGS.connectorSystemUpdateAvailableNote;
1760
+ $("<p>", { class: "nrc-muted" })
1761
+ .text(formatUpdateTargetPrefix(connectorInfo) + sysNote)
1762
+ .appendTo($verCard);
1763
+ }
1764
+
1765
+ if (connectorInfo.error) {
1766
+ $("<p>", { class: "nrc-field-error", role: "alert" })
1767
+ .text(connectorInfo.error)
1768
+ .appendTo($verCard);
1769
+ }
1770
+ }
1771
+ }
1772
+
1773
+ // 6. Footer links + Diagnostics + Disconnect
1774
+ const manageUrl = buildManageUrl(s);
1775
+ const supportUrl = buildSupportUrl(s);
1776
+ const $footer = $("<div>", { class: "nrc-footer" }).appendTo($root);
1777
+ const $links = $("<div>", { class: "nrc-footer-links" }).appendTo($footer);
1778
+
1779
+ if (manageUrl) {
1780
+ $("<a>", {
1781
+ class: "nrc-link",
1782
+ href: manageUrl,
1783
+ target: "_blank",
1784
+ rel: "noopener noreferrer",
1785
+ })
1786
+ .text(STRINGS.manageLink)
1787
+ .appendTo($links);
1788
+ }
1789
+
1790
+ $("<a>", {
1791
+ class: "nrc-link",
1792
+ href: supportUrl,
1793
+ target: "_blank",
1794
+ rel: "noopener noreferrer",
1795
+ })
1796
+ .text(STRINGS.supportLink)
1797
+ .appendTo($links);
1798
+
1799
+ $("<a>", {
1800
+ class: "nrc-link",
1801
+ href: COMMUNITY_ISSUES_URL,
1802
+ target: "_blank",
1803
+ rel: "noopener noreferrer",
1804
+ })
1805
+ .text(STRINGS.reportIssueLink)
1806
+ .appendTo($links);
1807
+
1808
+ $("<a>", {
1809
+ class: "nrc-link",
1810
+ href: STATUS_URL,
1811
+ target: "_blank",
1812
+ rel: "noopener noreferrer",
1813
+ })
1814
+ .text(STRINGS.statusLink)
1815
+ .appendTo($links);
1816
+
1817
+ $("<button>", {
1818
+ type: "button",
1819
+ id: "nrc-copy-diagnostics-btn",
1820
+ class: "nrc-link-btn",
1821
+ })
1822
+ .text(STRINGS.copyDiagnosticsBtn)
1823
+ .on("click", handleCopyDiagnosticsClick)
1824
+ .appendTo($links);
1825
+
1826
+ if (!s.managedByEnv) {
1827
+ $("<button>", {
1828
+ type: "button",
1829
+ id: "nrc-replace-btn",
1830
+ class: "nrc-link-btn",
1831
+ })
1832
+ .text(STRINGS.useDifferentCodeBtn)
1833
+ .on("click", openReplaceCodeFlow)
1834
+ .appendTo($links);
1835
+
1836
+ const $disconnectRow = $("<div>", { class: "nrc-actions" }).appendTo($footer);
1837
+ const $disconnectBtn = $("<button>", {
1838
+ type: "button",
1839
+ id: "nrc-disconnect-btn",
1840
+ class: "red-ui-button nrc-btn-danger",
1841
+ })
1842
+ .prop("disabled", state.disconnecting)
1843
+ .text(state.disconnecting ? STRINGS.disconnectingBtn : STRINGS.disconnectBtn)
1844
+ .on("click", handleDisconnectClick)
1845
+ .appendTo($disconnectRow);
1846
+ }
1847
+
1848
+ return $root;
1849
+ }
1850
+
1851
+ function render() {
1852
+ if (!state.loaded) {
1853
+ $container.empty();
1854
+ $("<p>", { class: "nrc-muted" }).text(STRINGS.loadingText).appendTo($container);
1855
+ currentViewKind = "loading";
1856
+ return;
1857
+ }
1858
+
1859
+ const showForm = !state.status.connected || state.mode === "replace";
1860
+ if (showForm) {
1861
+ if (currentViewKind !== "form") {
1862
+ $container.empty().append(ensureFormView());
1863
+ currentViewKind = "form";
1864
+ }
1865
+ updateFormState();
1866
+ return;
1867
+ }
1868
+
1869
+ const activeEl = document.activeElement;
1870
+ const focusId =
1871
+ activeEl && activeEl.id && $container[0] && $container[0].contains(activeEl)
1872
+ ? activeEl.id
1873
+ : null;
1874
+
1875
+ $connectedView = buildConnectedView();
1876
+ $container.empty().append($connectedView);
1877
+ currentViewKind = "connected";
1878
+
1879
+ if (focusId) {
1880
+ const restore = document.getElementById(focusId);
1881
+ if (restore && !restore.disabled && typeof restore.focus === "function") {
1882
+ restore.focus();
1883
+ }
1884
+ }
1885
+ }
1886
+
1887
+ const commsHandler = function (_topic, payload) {
1888
+ applyStatus(payload);
1889
+ };
1890
+ const commsReconnectHandler = function () {
1891
+ fetchStatus();
1892
+ };
1893
+
1894
+ const relativeTicker = setInterval(function () {
1895
+ if (!state.loaded || !state.status.connected || state.mode === "replace") return;
1896
+ applyCheckInTimestampText($container.find("[data-nrc-checkin-time]"));
1897
+ }, 1000);
1898
+
1899
+ RED.sidebar.addTab({
1900
+ id: "nr-connect",
1901
+ label: STRINGS.tabLabel,
1902
+ name: STRINGS.tabLabel,
1903
+ iconClass: "fa nrc-sidebar-icon",
1904
+ content: $container,
1905
+ });
1906
+
1907
+ if (RED.comms && typeof RED.comms.subscribe === "function") {
1908
+ RED.comms.subscribe(STATUS_TOPIC, commsHandler);
1909
+ if (typeof RED.comms.on === "function") {
1910
+ RED.comms.on("connect", commsReconnectHandler);
1911
+ }
1912
+ }
1913
+
1914
+ cleanupPlugin = function () {
1915
+ clearInterval(relativeTicker);
1916
+ if (state.copyResetTimer) clearTimeout(state.copyResetTimer);
1917
+ if (RED.comms && typeof RED.comms.unsubscribe === "function") {
1918
+ RED.comms.unsubscribe(STATUS_TOPIC, commsHandler);
1919
+ if (typeof RED.comms.off === "function") {
1920
+ RED.comms.off("connect", commsReconnectHandler);
1921
+ }
1922
+ }
1923
+ if (RED.sidebar && typeof RED.sidebar.removeTab === "function") {
1924
+ RED.sidebar.removeTab("nr-connect");
1925
+ }
1926
+ };
1927
+
1928
+ render();
1929
+ fetchStatus();
1930
+ },
1931
+ onremove: function () {
1932
+ if (typeof cleanupPlugin === "function") {
1933
+ cleanupPlugin();
1934
+ cleanupPlugin = null;
1935
+ }
1936
+ },
1937
+ });
1938
+ })();
1939
+ </script>