@huaweidevtools/aishell-dsh-client-credentials 0.0.8 → 0.0.9
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/lib/client.js +665 -648
- package/lib/index.js +196 -71
- package/lib/types/client/CredentialRequestForm.d.ts +43 -49
- package/lib/types/client/card-state.d.ts +58 -0
- package/lib/types/client/locales.d.ts +40 -28
- package/lib/types/client/login-flow.d.ts +78 -42
- package/lib/types/login-status.d.ts +3 -3
- package/lib/types/out-of-band/flow.d.ts +20 -1
- package/lib/types/out-of-band/listener.d.ts +77 -0
- package/lib/types/out-of-band/login.d.ts +67 -88
- package/lib/types/out-of-band/routes.d.ts +61 -33
- package/package.json +2 -2
- package/lib/types/client/spinner.d.ts +0 -32
- package/lib/types/client/start-page.d.ts +0 -61
package/lib/client.js
CHANGED
|
@@ -143,9 +143,9 @@ const CHIP_CLASS = "aishell-account-hint";
|
|
|
143
143
|
* `style[data-plugin="<id>"]` on module teardown, so a tag written here is
|
|
144
144
|
* reachable by the same mechanism as the generated ones.
|
|
145
145
|
*/
|
|
146
|
-
const PLUGIN_ID
|
|
146
|
+
const PLUGIN_ID = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
147
147
|
/** Dedupe key for the one sheet this module owns. */
|
|
148
|
-
const CHIP_STYLE_KEY = `${PLUGIN_ID
|
|
148
|
+
const CHIP_STYLE_KEY = `${PLUGIN_ID}/chip-hover`;
|
|
149
149
|
/**
|
|
150
150
|
* Mount the chips' hover/focus rule for the owning plugin's lifetime.
|
|
151
151
|
*
|
|
@@ -169,7 +169,7 @@ function installChipStyles(ctx) {
|
|
|
169
169
|
if (typeof document === "undefined") return;
|
|
170
170
|
ctx.effect(() => {
|
|
171
171
|
const tag = document.createElement("style");
|
|
172
|
-
tag.dataset.plugin = PLUGIN_ID
|
|
172
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
173
173
|
tag.dataset.pluginCss = CHIP_STYLE_KEY;
|
|
174
174
|
tag.textContent = `.${CHIP_CLASS}:hover{background:var(--dsw-alias-interactive-bg-hover)}.${CHIP_CLASS}:focus-visible{outline:2px solid var(--dsw-alias-label-primary);outline-offset:-2px}`;
|
|
175
175
|
document.head.appendChild(tag);
|
|
@@ -464,9 +464,9 @@ const CREDENTIAL_URL = "https://console.huaweicloud.com/apiexplorer/#/openapi/IA
|
|
|
464
464
|
*
|
|
465
465
|
* Any non-safelisted header would do it; this one names why. Declared here
|
|
466
466
|
* because both halves need the same string and neither owns it: the browser
|
|
467
|
-
* half sends it, the host's listener must allow it in
|
|
468
|
-
* and a mismatch between the two is a probe that fails
|
|
469
|
-
* would actually work — the entry hidden for no reason.
|
|
467
|
+
* half sends it on the loopback fetch, the host's listener must allow it in
|
|
468
|
+
* its preflight answer, and a mismatch between the two is a probe that fails
|
|
469
|
+
* on a route that would actually work — the entry hidden for no reason.
|
|
470
470
|
*/
|
|
471
471
|
const PROBE_HEADER = "x-aishell-probe";
|
|
472
472
|
/**
|
|
@@ -502,185 +502,252 @@ function decodeOutcome(raw) {
|
|
|
502
502
|
//#endregion
|
|
503
503
|
//#region src/client/login-flow.ts
|
|
504
504
|
/**
|
|
505
|
-
*
|
|
505
|
+
* A signal that fires on the timeout, on the caller's abort, or not at all.
|
|
506
|
+
*
|
|
507
|
+
* `AbortSignal.timeout` alone would ignore the caller's signal, so a card
|
|
508
|
+
* closed mid-probe would leave its request running for the rest of the
|
|
509
|
+
* timeout. The two are combined rather than choosing one because both apply:
|
|
510
|
+
* the request may be abandoned, and it may also hang.
|
|
511
|
+
*
|
|
512
|
+
* @param ms - the timeout.
|
|
513
|
+
* @param caller - the caller's signal, if any.
|
|
514
|
+
*/
|
|
515
|
+
function withTimeout(ms, caller) {
|
|
516
|
+
const timeout = AbortSignal.timeout(ms);
|
|
517
|
+
if (caller === void 0) return timeout;
|
|
518
|
+
if (typeof AbortSignal.any !== "function") return timeout;
|
|
519
|
+
return AbortSignal.any([timeout, caller]);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* How long either call may take.
|
|
506
523
|
*
|
|
507
524
|
* Short, because both are expected to be immediate: a loopback request that
|
|
508
|
-
* works answers in well under a millisecond. The bound exists so
|
|
509
|
-
* that cannot do this says so
|
|
510
|
-
* than by leaving the card blank.
|
|
525
|
+
* works answers in well under a millisecond. The bound exists so an access
|
|
526
|
+
* route that cannot do this says so rather than leaving the card mid-check.
|
|
511
527
|
*/
|
|
512
|
-
const
|
|
528
|
+
const CALL_TIMEOUT_MS = 3e3;
|
|
513
529
|
/** Routes the browser half drives a login through. */
|
|
530
|
+
const LOGIN_PROBE_ROUTE = "api/aishell/credentials/login/probe";
|
|
514
531
|
const LOGIN_START_ROUTE = "api/aishell/credentials/login/start";
|
|
515
532
|
const LOGIN_CANCEL_ROUTE = "api/aishell/credentials/login/cancel";
|
|
516
|
-
/**
|
|
517
|
-
|
|
518
|
-
*
|
|
519
|
-
* Starts a login on the host and then proves this page can reach the listener
|
|
520
|
-
* it bound. The probe request goes from this browser to loopback, which is the
|
|
521
|
-
* same journey the cloud's callback will make.
|
|
522
|
-
*
|
|
523
|
-
* ## Why the probe is not a plain GET
|
|
524
|
-
*
|
|
525
|
-
* It carries a custom header, which makes it a non-simple request: the browser
|
|
526
|
-
* must send a CORS preflight first, and only proceeds if the answer is right.
|
|
527
|
-
* The cloud's callback is a JSON POST and therefore *always* preflights, so a
|
|
528
|
-
* plain GET would test a path the callback never takes — and could pass on a
|
|
529
|
-
* deployment where the real preflight fails (a missing Private Network Access
|
|
530
|
-
* allow header, say), which is the one wrong answer this check must not give.
|
|
531
|
-
*
|
|
532
|
-
* @returns a handle when the login is reachable, or `undefined` when it is
|
|
533
|
-
* not — the ordinary outcome on a deployment where the browser is elsewhere.
|
|
534
|
-
*/
|
|
535
|
-
async function startBrowserLogin() {
|
|
536
|
-
let started;
|
|
533
|
+
/** POST an empty body to a host route and read its JSON answer. */
|
|
534
|
+
async function post(route) {
|
|
537
535
|
try {
|
|
538
|
-
const response = await fetch(
|
|
536
|
+
const response = await fetch(route, {
|
|
539
537
|
method: "POST",
|
|
540
538
|
headers: { "content-type": "application/json" },
|
|
541
539
|
body: JSON.stringify({}),
|
|
542
|
-
signal: AbortSignal.timeout(
|
|
540
|
+
signal: AbortSignal.timeout(CALL_TIMEOUT_MS)
|
|
543
541
|
});
|
|
544
|
-
|
|
542
|
+
return await response.json();
|
|
545
543
|
} catch {
|
|
546
544
|
return void 0;
|
|
547
545
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* The probe's answer, for as long as this page lives.
|
|
549
|
+
*
|
|
550
|
+
* ## Why cached here
|
|
551
|
+
*
|
|
552
|
+
* The question is whether a browser on this machine can reach a socket on the
|
|
553
|
+
* host, and it is a property of how this page is reached rather than of any
|
|
554
|
+
* one card:
|
|
555
|
+
* closing the card and opening it again does not move either machine. Asking
|
|
556
|
+
* per card meant a bound port, a loopback request and a CORS preflight every
|
|
557
|
+
* time — for an answer that had not changed.
|
|
558
|
+
*
|
|
559
|
+
* ## Why a promise, not the boolean
|
|
560
|
+
*
|
|
561
|
+
* Stored as the in-flight promise so two cards opened in quick succession share
|
|
562
|
+
* one probe rather than racing two. The second caller joins the first's answer.
|
|
563
|
+
*
|
|
564
|
+
* ## Why it lives in the module and not the component
|
|
565
|
+
*
|
|
566
|
+
* The component remounts on every open — that is how a fresh card gets fresh
|
|
567
|
+
* state — so anything held in its state is re-derived each time. A module-level
|
|
568
|
+
* value survives that, which is the whole point.
|
|
569
|
+
*
|
|
570
|
+
* ## What invalidates it
|
|
571
|
+
*
|
|
572
|
+
* Nothing, for the life of the page. A person who sets up a tunnel to fix a
|
|
573
|
+
* failed probe reloads, and a reload is the natural boundary: it is the same
|
|
574
|
+
* act that re-establishes the page's connection to the host. A remembered
|
|
575
|
+
* "no" that could never be revisited would be worse than the repeated probe;
|
|
576
|
+
* a remembered "no" that lasts only until reload is not.
|
|
577
|
+
*
|
|
578
|
+
* ## The one thing not remembered
|
|
579
|
+
*
|
|
580
|
+
* A failure to reach the **host** at all. That is not an answer about the
|
|
581
|
+
* route — the host may be mid-reload — and caching it would leave the card
|
|
582
|
+
* saying "unsupported" for the rest of the page's life. So `runRouteProbe`
|
|
583
|
+
* reports it as `undefined`, and only real answers are kept.
|
|
584
|
+
*/
|
|
585
|
+
let routeProbe;
|
|
586
|
+
/**
|
|
587
|
+
* Ask whether a browser here can reach a loopback listener.
|
|
588
|
+
*
|
|
589
|
+
* ## What it tests, and why only this can
|
|
590
|
+
*
|
|
591
|
+
* The cloud posts a credential to `127.0.0.1` **as the browser's machine
|
|
592
|
+
* resolves it**, so the flow works only when that browser can reach a listener
|
|
593
|
+
* on this host. Neither side can tell by looking: an SSH-forwarded session
|
|
594
|
+
* makes a distant browser look local to the host, and a distant host look local
|
|
595
|
+
* to the page. So the host borrows a port, this page fetches it, and the fetch
|
|
596
|
+
* *is* the answer — resolving means a socket here was reached, rejecting means
|
|
597
|
+
* it was not.
|
|
598
|
+
*
|
|
599
|
+
* The port is released by the host as soon as it is reached, or after a short
|
|
600
|
+
* window. Nothing is kept for the login that may follow: that binds its own
|
|
601
|
+
* port, so a card read and abandoned holds nothing.
|
|
602
|
+
*
|
|
603
|
+
* ## Why the request carries a header
|
|
604
|
+
*
|
|
605
|
+
* The header makes it a non-simple request, so the browser sends a CORS
|
|
606
|
+
* preflight first and only proceeds if the answer is right. The cloud's
|
|
607
|
+
* callback is a JSON POST and therefore *always* preflights, so a plain GET
|
|
608
|
+
* would test a path the callback never takes — and could pass on a route where
|
|
609
|
+
* the real preflight fails, which is the one wrong answer this must not
|
|
610
|
+
* give.
|
|
611
|
+
*
|
|
612
|
+
* @returns whether the route works here. Answered once per page, except when
|
|
613
|
+
* the host could not be reached — see {@link routeProbe}.
|
|
614
|
+
*/
|
|
615
|
+
async function probeBrowserRoute(signal) {
|
|
616
|
+
routeProbe ??= runRouteProbe(signal);
|
|
617
|
+
const answer = await routeProbe;
|
|
618
|
+
if (answer === void 0) routeProbe = void 0;
|
|
619
|
+
return answer ?? false;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* One probe, from borrowing the port to reading the answer.
|
|
623
|
+
*
|
|
624
|
+
* @param signal - aborts the loopback request when the card that asked goes
|
|
625
|
+
* away. The host's port is not released by this — it never learns the page
|
|
626
|
+
* gave up — but the request stops, and the host's own window closes it. The
|
|
627
|
+
* result is still cached: the route did not change because a card closed.
|
|
628
|
+
*/
|
|
629
|
+
async function runRouteProbe(signal) {
|
|
630
|
+
const answer = await post(LOGIN_PROBE_ROUTE);
|
|
631
|
+
if (answer === void 0) return void 0;
|
|
632
|
+
if (answer.ok !== true || typeof answer.probeUrl !== "string" || answer.probeUrl === "") return false;
|
|
559
633
|
try {
|
|
560
|
-
const
|
|
634
|
+
const reached = await fetch(answer.probeUrl, {
|
|
561
635
|
method: "GET",
|
|
562
636
|
headers: { [PROBE_HEADER]: "1" },
|
|
563
|
-
signal:
|
|
637
|
+
signal: withTimeout(CALL_TIMEOUT_MS, signal)
|
|
564
638
|
});
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
} catch (error) {
|
|
570
|
-
cancel();
|
|
571
|
-
return void 0;
|
|
639
|
+
return reached.ok;
|
|
640
|
+
} catch {
|
|
641
|
+
if (signal?.aborted === true) return void 0;
|
|
642
|
+
return false;
|
|
572
643
|
}
|
|
573
|
-
return {
|
|
574
|
-
loginUrl,
|
|
575
|
-
providerName,
|
|
576
|
-
expiresInSeconds,
|
|
577
|
-
cancel
|
|
578
|
-
};
|
|
579
644
|
}
|
|
580
645
|
/**
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
* A separate tab rather than a redirect: the form has unsaved state and the
|
|
584
|
-
* person may come back to paste a key instead, and a login that navigated away
|
|
585
|
-
* from the conversation would lose it.
|
|
646
|
+
* Begin a login, now that the person has asked for one.
|
|
586
647
|
*
|
|
587
|
-
*
|
|
648
|
+
* Binds a port and fetches a URL projected for it at this moment, which is why
|
|
649
|
+
* the URL is not stale however long the card sat open before the click.
|
|
588
650
|
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
651
|
+
* @returns a handle for the login in flight, or `undefined` when the host
|
|
652
|
+
* could not start one.
|
|
653
|
+
*/
|
|
654
|
+
async function startBrowserLogin() {
|
|
655
|
+
const started = await post(LOGIN_START_ROUTE);
|
|
656
|
+
if (started?.ok !== true || typeof started.loginUrl !== "string" || started.loginUrl === "") return void 0;
|
|
657
|
+
return {
|
|
658
|
+
loginUrl: started.loginUrl,
|
|
659
|
+
providerName: started.providerName ?? "",
|
|
660
|
+
expiresInSeconds: started.expiresInSeconds ?? 0,
|
|
661
|
+
cancel: () => {
|
|
662
|
+
fetch(LOGIN_CANCEL_ROUTE, { method: "POST" }).catch(() => {});
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Open a blank tab, subject to the current user gesture.
|
|
594
668
|
*
|
|
595
|
-
* @
|
|
596
|
-
* @returns whether the browser opened it; a popup blocker says no.
|
|
669
|
+
* @returns the handle, or `undefined` when a blocker refused.
|
|
597
670
|
*/
|
|
598
|
-
function openLoginWindow(
|
|
599
|
-
const opened = window.open(
|
|
600
|
-
if (opened === null) return
|
|
671
|
+
function openLoginWindow() {
|
|
672
|
+
const opened = window.open("", "_blank");
|
|
673
|
+
if (opened === null) return void 0;
|
|
601
674
|
try {
|
|
602
675
|
opened.opener = null;
|
|
603
676
|
} catch {}
|
|
604
|
-
return
|
|
677
|
+
return {
|
|
678
|
+
navigate: (url) => {
|
|
679
|
+
try {
|
|
680
|
+
opened.location.href = url;
|
|
681
|
+
} catch {}
|
|
682
|
+
},
|
|
683
|
+
close: () => {
|
|
684
|
+
try {
|
|
685
|
+
opened.close();
|
|
686
|
+
} catch {}
|
|
687
|
+
}
|
|
688
|
+
};
|
|
605
689
|
}
|
|
606
690
|
|
|
607
691
|
//#endregion
|
|
608
|
-
//#region src/client/
|
|
692
|
+
//#region src/client/card-state.ts
|
|
609
693
|
/**
|
|
610
|
-
* The
|
|
611
|
-
*
|
|
612
|
-
* `undefined` means the probe has not answered yet, and is the honest value for
|
|
613
|
-
* that moment: rendering either page then is what makes the fields appear and
|
|
614
|
-
* get replaced a moment later.
|
|
694
|
+
* The button's label and enabled state.
|
|
615
695
|
*
|
|
616
|
-
* @param
|
|
617
|
-
* @param
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
696
|
+
* @param phase - the probe's answer and whether a login is in flight.
|
|
697
|
+
* @param hasCountdown - whether a countdown is being shown. Unused by the
|
|
698
|
+
* label, which names the action rather than the remaining time — the
|
|
699
|
+
* countdown sits above the button where it can be read without the label
|
|
700
|
+
* changing under the pointer. Kept in the signature so callers pass the same
|
|
701
|
+
* pair the render does, and so a future state that does depend on it has
|
|
702
|
+
* somewhere to say so.
|
|
703
|
+
* @returns the label key and whether the button is disabled.
|
|
621
704
|
*/
|
|
622
|
-
function
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
705
|
+
function browserButton(phase, hasCountdown) {
|
|
706
|
+
switch (phase) {
|
|
707
|
+
case "checking":
|
|
708
|
+
case "starting":
|
|
709
|
+
case "ready": return {
|
|
710
|
+
label: "form.browser.action",
|
|
711
|
+
disabled: phase !== "ready"
|
|
712
|
+
};
|
|
713
|
+
case "unsupported": return {
|
|
714
|
+
label: "form.browser.unsupportedLabel",
|
|
715
|
+
disabled: true
|
|
716
|
+
};
|
|
717
|
+
case "running": return {
|
|
718
|
+
label: "form.browser.cancelLabel",
|
|
719
|
+
disabled: false
|
|
720
|
+
};
|
|
721
|
+
default: return {
|
|
722
|
+
label: "form.browser.action",
|
|
723
|
+
disabled: false
|
|
724
|
+
};
|
|
725
|
+
}
|
|
642
726
|
}
|
|
643
|
-
|
|
644
|
-
//#endregion
|
|
645
|
-
//#region src/client/spinner.ts
|
|
646
|
-
/** Class the waiting spinner carries. */
|
|
647
|
-
const SPINNER_CLASS = "aishell-spinner";
|
|
648
|
-
/** Marker identifying this sheet, so teardown sweeps exactly it. */
|
|
649
|
-
const SPINNER_STYLE_KEY = "aishell-credentials:spinner";
|
|
650
|
-
/** Plugin id the loader attributes the tag to. */
|
|
651
|
-
const PLUGIN_ID = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
652
727
|
/**
|
|
653
|
-
*
|
|
728
|
+
* Render a countdown as `m:ss`.
|
|
654
729
|
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
730
|
+
* Language-neutral on purpose: the sentence around it is localised, and a
|
|
731
|
+
* number with a colon needs no translation — spelling out a unit would put a
|
|
732
|
+
* second copy of it in both dictionaries for no gain. Tabular figures are
|
|
733
|
+
* applied at the call site so the digits do not jitter as they change.
|
|
658
734
|
*
|
|
659
|
-
* @param
|
|
735
|
+
* @param seconds - seconds remaining; negative reads as zero.
|
|
660
736
|
*/
|
|
661
|
-
function
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
tag.dataset.pluginCss = SPINNER_STYLE_KEY;
|
|
667
|
-
tag.textContent = `@keyframes ${SPINNER_CLASS}-rotate{to{transform:rotate(360deg)}}.${SPINNER_CLASS}{display:inline-block;border-radius:50%;border:2px solid var(--dsw-alias-border-l4);border-top-color:var(--dsw-alias-label-secondary);animation:${SPINNER_CLASS}-rotate .8s linear infinite}@media (prefers-reduced-motion:reduce){.${SPINNER_CLASS}{animation:none}}`;
|
|
668
|
-
document.head.appendChild(tag);
|
|
669
|
-
return () => {
|
|
670
|
-
tag.remove();
|
|
671
|
-
};
|
|
672
|
-
}, "aishell-credentials: spinner styles");
|
|
737
|
+
function formatCountdown(seconds) {
|
|
738
|
+
const whole = Math.max(0, Math.floor(seconds));
|
|
739
|
+
const minutes = Math.floor(whole / 60);
|
|
740
|
+
const rest = whole % 60;
|
|
741
|
+
return `${String(minutes)}:${String(rest).padStart(2, "0")}`;
|
|
673
742
|
}
|
|
674
743
|
|
|
675
744
|
//#endregion
|
|
676
745
|
//#region src/client/CredentialRequestForm.tsx
|
|
677
746
|
/**
|
|
678
|
-
* The
|
|
747
|
+
* The credential card.
|
|
679
748
|
*
|
|
680
|
-
* Submitting saves through the Host route; the
|
|
681
|
-
* chip flipping to the account name is the feedback that it worked.
|
|
682
|
-
* request behind an open form — a chip opened it — so nothing else takes it
|
|
683
|
-
* down.
|
|
749
|
+
* Submitting saves through the Host route; the card then closes itself, and the
|
|
750
|
+
* chip flipping to the account name is the feedback that it worked.
|
|
684
751
|
*/
|
|
685
752
|
function CredentialRequestForm(props) {
|
|
686
753
|
const t = props.t;
|
|
@@ -691,58 +758,22 @@ function CredentialRequestForm(props) {
|
|
|
691
758
|
const [token, setToken] = (0, react.useState)("");
|
|
692
759
|
const [saving, setSaving] = (0, react.useState)(false);
|
|
693
760
|
const [clearing, setClearing] = (0, react.useState)(false);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
* Shown so the person knows where the values came from — a credential that
|
|
699
|
-
* silently appeared in a field is worse than an empty one, because they
|
|
700
|
-
* cannot tell whether to trust it.
|
|
701
|
-
*/
|
|
761
|
+
/** A failure of whichever route produced it; each section renders its own. */
|
|
762
|
+
const [browserError, setBrowserError] = (0, react.useState)(void 0);
|
|
763
|
+
const [manualError, setManualError] = (0, react.useState)(void 0);
|
|
764
|
+
/** Whether the fields were seeded from the environment, so the notice is honest. */
|
|
702
765
|
const [prefilled, setPrefilled] = (0, react.useState)(false);
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
* proved it can reach the listener.
|
|
706
|
-
*
|
|
707
|
-
* `undefined` while that is still being decided, and `null` once it is
|
|
708
|
-
* decided against — the distinction matters, because "still checking" must
|
|
709
|
-
* not render the entry and "cannot" must not either, but only one of them
|
|
710
|
-
* resolves into it appearing.
|
|
711
|
-
*/
|
|
712
|
-
const [browserLogin, setBrowserLogin] = (0, react.useState)(void 0);
|
|
713
|
-
/**
|
|
714
|
-
* Which page the card is on.
|
|
715
|
-
*
|
|
716
|
-
* `choose` is the first page: the browser entry, if this deployment has one,
|
|
717
|
-
* and the way to the manual form. `manual` is the AK/SK form. `waiting` is a
|
|
718
|
-
* browser login in flight.
|
|
719
|
-
*
|
|
720
|
-
* Where it opens depends on whether a credential is already stored — see
|
|
721
|
-
* {@link startPage}. `undefined` is "not decided yet", and renders the card's
|
|
722
|
-
* frame with neither page's body, which is what stops the fields appearing
|
|
723
|
-
* and being replaced a moment later.
|
|
724
|
-
*/
|
|
725
|
-
const [page, setPage] = (0, react.useState)(void 0);
|
|
726
|
-
/** Seconds left before the login can no longer complete; `undefined` when idle. */
|
|
766
|
+
const [login, setLogin] = (0, react.useState)(void 0);
|
|
767
|
+
const [phase, setPhase] = (0, react.useState)("checking");
|
|
727
768
|
const [secondsLeft, setSecondsLeft] = (0, react.useState)(void 0);
|
|
728
769
|
/**
|
|
729
|
-
* Whether a credential is
|
|
730
|
-
*
|
|
731
|
-
* Read from the status the chips read, so the card and the chip agree about
|
|
732
|
-
* whether there is anything to show. Captured by the probe effect below,
|
|
733
|
-
* whose empty dependency list makes it the value at mount — "was there a
|
|
734
|
-
* credential when this card opened", which is the question the first page
|
|
735
|
-
* answers.
|
|
736
|
-
*/
|
|
737
|
-
const hasCredentials = status.hasAccessKey || status.hasSecretKey;
|
|
738
|
-
/**
|
|
739
|
-
* Whether the person has started filling the manual form.
|
|
770
|
+
* Whether a credential is stored, read live rather than captured.
|
|
740
771
|
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
772
|
+
* Live because the card changes state under the person's hands: a successful
|
|
773
|
+
* save or login moves it to the signed-in view without a reopen, and a clear
|
|
774
|
+
* moves it back.
|
|
744
775
|
*/
|
|
745
|
-
const
|
|
776
|
+
const signedIn = status.hasAccessKey || status.hasSecretKey;
|
|
746
777
|
(0, react.useEffect)(() => {
|
|
747
778
|
let live = true;
|
|
748
779
|
props.readPrefill().then((prefill) => {
|
|
@@ -758,51 +789,65 @@ function CredentialRequestForm(props) {
|
|
|
758
789
|
};
|
|
759
790
|
}, []);
|
|
760
791
|
(0, react.useEffect)(() => {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
handle?.cancel();
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
setBrowserLogin(handle ?? null);
|
|
769
|
-
if (interacted.current) return;
|
|
770
|
-
setPage(startPage({
|
|
771
|
-
browserAvailable: handle !== null,
|
|
772
|
-
alreadyConfigured
|
|
773
|
-
}));
|
|
792
|
+
const controller = new AbortController();
|
|
793
|
+
props.probeBrowserRoute(controller.signal).then((reachable) => {
|
|
794
|
+
if (controller.signal.aborted) return;
|
|
795
|
+
setPhase(reachable ? "ready" : "unsupported");
|
|
774
796
|
}).catch(() => {
|
|
775
|
-
if (!
|
|
776
|
-
setBrowserLogin(null);
|
|
777
|
-
if (!interacted.current) setPage("manual");
|
|
797
|
+
if (!controller.signal.aborted) setPhase("unsupported");
|
|
778
798
|
});
|
|
779
799
|
return () => {
|
|
780
|
-
|
|
800
|
+
controller.abort();
|
|
781
801
|
};
|
|
782
802
|
}, []);
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
803
|
+
/**
|
|
804
|
+
* Whether this card is still on screen.
|
|
805
|
+
*
|
|
806
|
+
* A start that is in flight when the card closes must not be forgotten: the
|
|
807
|
+
* host binds its listener before it answers, so a request whose reply nobody
|
|
808
|
+
* reads leaves a port bound until the login's own deadline — ten minutes —
|
|
809
|
+
* expires. Read after the await, alongside the handle it carried.
|
|
810
|
+
*
|
|
811
|
+
* Re-armed in the effect body, not just set once. This effect is keyed on the
|
|
812
|
+
* handle, so it re-runs when a login starts or is cancelled; a flag only ever
|
|
813
|
+
* lowered in the cleanup would stay `false` after that re-run, and the next
|
|
814
|
+
* login would close its own tab and release its port on the spot.
|
|
815
|
+
*/
|
|
816
|
+
const mounted = (0, react.useRef)(true);
|
|
817
|
+
(0, react.useEffect)(() => {
|
|
818
|
+
mounted.current = true;
|
|
819
|
+
return () => {
|
|
820
|
+
mounted.current = false;
|
|
821
|
+
login?.cancel();
|
|
822
|
+
};
|
|
823
|
+
}, [login]);
|
|
786
824
|
(0, react.useEffect)(() => {
|
|
787
|
-
if (
|
|
825
|
+
if (phase !== "running" || secondsLeft === void 0) return;
|
|
788
826
|
const deadline = Date.now() + secondsLeft * 1e3;
|
|
789
827
|
const timer = window.setInterval(() => {
|
|
790
|
-
|
|
828
|
+
const left = Math.max(0, Math.round((deadline - Date.now()) / 1e3));
|
|
829
|
+
setSecondsLeft(left);
|
|
830
|
+
if (left === 0) {
|
|
831
|
+
window.clearInterval(timer);
|
|
832
|
+
setPhase("ready");
|
|
833
|
+
setBrowserError(t("form.browser.expired"));
|
|
834
|
+
}
|
|
791
835
|
}, 1e3);
|
|
792
836
|
return () => {
|
|
793
837
|
window.clearInterval(timer);
|
|
794
838
|
};
|
|
795
|
-
}, [
|
|
839
|
+
}, [phase]);
|
|
840
|
+
(0, react.useEffect)(() => {
|
|
841
|
+
if (phase !== "running") setSecondsLeft(void 0);
|
|
842
|
+
}, [phase]);
|
|
796
843
|
const outcomeRaw = props.useLoginOutcome((snapshot) => snapshot);
|
|
797
844
|
/**
|
|
798
|
-
* The outcome already recorded when this
|
|
845
|
+
* The outcome already recorded when this card opened.
|
|
799
846
|
*
|
|
800
|
-
* The document keeps the last login's outcome, so a
|
|
801
|
-
* otherwise react to a result that has nothing to do with it: after a
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* Baselines are per mount, which is per open — the interaction's key changes
|
|
805
|
-
* on reopen, so the component remounts.
|
|
847
|
+
* The document keeps the last login's outcome, so a card opened later would
|
|
848
|
+
* otherwise react to a result that has nothing to do with it: after a success
|
|
849
|
+
* the next open would close itself on the spot, and after a failure it would
|
|
850
|
+
* show that error before the person did anything.
|
|
806
851
|
*/
|
|
807
852
|
const outcomeAtMount = (0, react.useRef)(null);
|
|
808
853
|
if (outcomeAtMount.current === null) outcomeAtMount.current = outcomeRaw;
|
|
@@ -817,45 +862,79 @@ function CredentialRequestForm(props) {
|
|
|
817
862
|
close();
|
|
818
863
|
return;
|
|
819
864
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
setError(outcome.kind === "failed" && outcome.error !== "" ? t("form.browser.failed") + outcome.error : void 0);
|
|
865
|
+
setPhase("ready");
|
|
866
|
+
setBrowserError(outcome.error === "" ? t("form.browser.failed") : outcome.error);
|
|
823
867
|
}, [outcomeRaw]);
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
868
|
+
/**
|
|
869
|
+
* Start a sign-in, because the person asked for one.
|
|
870
|
+
*
|
|
871
|
+
* The URL is fetched now rather than when the card opened: it names the port
|
|
872
|
+
* this login binds, and the service only promises it for a window. A card
|
|
873
|
+
* that sat open for a while still offers a URL that works, which is the whole
|
|
874
|
+
* reason probe and start are separate.
|
|
875
|
+
*/
|
|
876
|
+
const onBrowserLogin = async () => {
|
|
877
|
+
if (phase === "running" || phase === "starting") return;
|
|
878
|
+
setBrowserError(void 0);
|
|
879
|
+
const tab = openLoginWindow();
|
|
880
|
+
if (tab === void 0) {
|
|
881
|
+
setBrowserError(t("form.browser.blocked"));
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
setPhase("starting");
|
|
885
|
+
const handle = await props.startBrowserLogin();
|
|
886
|
+
if (!mounted.current) {
|
|
887
|
+
tab.close();
|
|
888
|
+
handle?.cancel();
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (handle === void 0) {
|
|
892
|
+
tab.close();
|
|
893
|
+
setPhase("ready");
|
|
894
|
+
setBrowserError(t("form.browser.startFailed"));
|
|
829
895
|
return;
|
|
830
896
|
}
|
|
831
|
-
|
|
832
|
-
|
|
897
|
+
tab.navigate(handle.loginUrl);
|
|
898
|
+
setLogin(handle);
|
|
899
|
+
setPhase("running");
|
|
900
|
+
setSecondsLeft(handle.expiresInSeconds > 0 ? handle.expiresInSeconds : void 0);
|
|
833
901
|
};
|
|
834
902
|
/**
|
|
835
|
-
* Abandon the
|
|
903
|
+
* Abandon the login in flight.
|
|
836
904
|
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
* listener, whose URL is dead the moment this card goes away.
|
|
905
|
+
* Releases the host's listener — the URL on screen is dead from this moment —
|
|
906
|
+
* and returns the button, so the person can try again or fall back to pasting
|
|
907
|
+
* a key. Not a refusal of the card itself: `取消` does that, and it is a
|
|
908
|
+
* separate button below.
|
|
842
909
|
*/
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
910
|
+
const onCancelLogin = (0, react.useCallback)(() => {
|
|
911
|
+
login?.cancel();
|
|
912
|
+
setLogin(void 0);
|
|
913
|
+
setPhase("ready");
|
|
914
|
+
setBrowserError(void 0);
|
|
915
|
+
}, [login]);
|
|
916
|
+
/** Put the sign-in URL on the clipboard when the tab did not open. */
|
|
917
|
+
const onCopyLink = () => {
|
|
918
|
+
if (login === null || login === void 0) return;
|
|
919
|
+
navigator.clipboard.writeText(login.loginUrl).then(
|
|
920
|
+
() => {
|
|
921
|
+
setBrowserError(void 0);
|
|
922
|
+
},
|
|
923
|
+
// A denied clipboard — no permission, or an insecure origin — leaves the
|
|
924
|
+
// person with nothing, so say what happened rather than failing silently.
|
|
925
|
+
() => {
|
|
926
|
+
setBrowserError(t("form.browser.copyFailed"));
|
|
927
|
+
}
|
|
928
|
+
);
|
|
850
929
|
};
|
|
851
930
|
const onSubmit = async (event) => {
|
|
852
931
|
event.preventDefault();
|
|
853
932
|
setSaving(true);
|
|
854
|
-
|
|
933
|
+
setManualError(void 0);
|
|
855
934
|
try {
|
|
856
935
|
const verdict = await save(ak, sk, token === "" ? void 0 : token);
|
|
857
936
|
if (!verdict.ok) {
|
|
858
|
-
|
|
937
|
+
setManualError(verdict.error ?? t("form.failed"));
|
|
859
938
|
return;
|
|
860
939
|
}
|
|
861
940
|
setAk("");
|
|
@@ -863,29 +942,25 @@ function CredentialRequestForm(props) {
|
|
|
863
942
|
setToken("");
|
|
864
943
|
close();
|
|
865
944
|
} catch (err) {
|
|
866
|
-
|
|
945
|
+
setManualError(err instanceof Error ? err.message : String(err));
|
|
867
946
|
} finally {
|
|
868
947
|
setSaving(false);
|
|
869
948
|
}
|
|
870
949
|
};
|
|
871
950
|
const onClear = async () => {
|
|
872
951
|
setClearing(true);
|
|
873
|
-
|
|
952
|
+
setManualError(void 0);
|
|
874
953
|
try {
|
|
875
954
|
const verdict = await clear();
|
|
876
|
-
if (!verdict.ok)
|
|
877
|
-
setError(verdict.error ?? t("form.clear.failed"));
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
if (!interacted.current) setPage(afterClear({ browserAvailable: browserLogin !== null && browserLogin !== void 0 }));
|
|
955
|
+
if (!verdict.ok) setManualError(verdict.error ?? t("form.clear.failed"));
|
|
881
956
|
} catch (err) {
|
|
882
|
-
|
|
957
|
+
setManualError(err instanceof Error ? err.message : String(err));
|
|
883
958
|
} finally {
|
|
884
959
|
setClearing(false);
|
|
885
960
|
}
|
|
886
961
|
};
|
|
887
962
|
const onCancel = () => {
|
|
888
|
-
|
|
963
|
+
login?.cancel();
|
|
889
964
|
cancel();
|
|
890
965
|
};
|
|
891
966
|
const fieldStyle = {
|
|
@@ -894,18 +969,17 @@ function CredentialRequestForm(props) {
|
|
|
894
969
|
gap: 6
|
|
895
970
|
};
|
|
896
971
|
const labelStyle = {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
gap: 10,
|
|
900
|
-
fontSize: 12,
|
|
901
|
-
lineHeight: "18px",
|
|
972
|
+
fontSize: 11,
|
|
973
|
+
lineHeight: "16px",
|
|
902
974
|
fontWeight: 500,
|
|
903
|
-
|
|
975
|
+
letterSpacing: "0.04em",
|
|
976
|
+
textTransform: "uppercase",
|
|
977
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
904
978
|
};
|
|
905
|
-
const inputStyle = {
|
|
979
|
+
const inputStyle = (disabled) => ({
|
|
906
980
|
boxSizing: "border-box",
|
|
907
981
|
width: "100%",
|
|
908
|
-
height:
|
|
982
|
+
height: 34,
|
|
909
983
|
padding: "0 10px",
|
|
910
984
|
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
911
985
|
borderRadius: 8,
|
|
@@ -913,23 +987,62 @@ function CredentialRequestForm(props) {
|
|
|
913
987
|
fontSize: 14,
|
|
914
988
|
lineHeight: "22px",
|
|
915
989
|
background: "var(--dsw-alias-bg-layer-1)",
|
|
916
|
-
color: "var(--dsw-alias-label-primary)"
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
990
|
+
color: "var(--dsw-alias-label-primary)",
|
|
991
|
+
opacity: disabled ? .5 : 1,
|
|
992
|
+
cursor: disabled ? "not-allowed" : "text"
|
|
993
|
+
});
|
|
994
|
+
const buttonStyle = (disabled, kind = "secondary") => ({
|
|
995
|
+
height: 34,
|
|
996
|
+
padding: "0 16px",
|
|
922
997
|
borderRadius: 8,
|
|
923
998
|
font: "inherit",
|
|
924
999
|
fontSize: 14,
|
|
925
|
-
cursor: disabled
|
|
926
|
-
opacity: disabled
|
|
1000
|
+
cursor: disabled ? "default" : "pointer",
|
|
1001
|
+
opacity: disabled ? .45 : 1,
|
|
1002
|
+
border: kind === "primary" ? "none" : "0.5px solid var(--dsw-alias-border-l4)",
|
|
1003
|
+
background: kind === "primary" ? "var(--dsw-alias-button-primary-fill)" : kind === "quiet" ? "transparent" : "var(--dsw-alias-bg-layer-1)",
|
|
1004
|
+
color: kind === "primary" ? "var(--dsw-alias-label-primary-foreground)" : "var(--dsw-alias-label-primary)"
|
|
927
1005
|
});
|
|
1006
|
+
const divider = (text) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1007
|
+
style: {
|
|
1008
|
+
display: "flex",
|
|
1009
|
+
alignItems: "center",
|
|
1010
|
+
gap: 10
|
|
1011
|
+
},
|
|
1012
|
+
children: [
|
|
1013
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
|
|
1014
|
+
flex: 1,
|
|
1015
|
+
height: 1,
|
|
1016
|
+
background: "var(--dsw-alias-border-l4)"
|
|
1017
|
+
} }),
|
|
1018
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1019
|
+
style: {
|
|
1020
|
+
fontSize: 12,
|
|
1021
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1022
|
+
},
|
|
1023
|
+
children: text
|
|
1024
|
+
}),
|
|
1025
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
|
|
1026
|
+
flex: 1,
|
|
1027
|
+
height: 1,
|
|
1028
|
+
background: "var(--dsw-alias-border-l4)"
|
|
1029
|
+
} })
|
|
1030
|
+
]
|
|
1031
|
+
});
|
|
1032
|
+
const notice = {
|
|
1033
|
+
margin: 0,
|
|
1034
|
+
fontSize: 12,
|
|
1035
|
+
lineHeight: "18px",
|
|
1036
|
+
color: "var(--dsw-alias-state-warn-label)"
|
|
1037
|
+
};
|
|
928
1038
|
const busy = saving || clearing;
|
|
929
|
-
|
|
1039
|
+
/** While a login runs, the other route is disabled — both write one record. */
|
|
1040
|
+
const manualDisabled = busy || phase === "running";
|
|
1041
|
+
const submitDisabled = manualDisabled || !ak || !sk;
|
|
1042
|
+
const button = browserButton(phase, secondsLeft !== void 0);
|
|
930
1043
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
931
1044
|
role: "group",
|
|
932
|
-
"aria-label": t("form.title
|
|
1045
|
+
"aria-label": t("form.title"),
|
|
933
1046
|
style: {
|
|
934
1047
|
padding: "6px calc(var(--dsh-composer-side-clearance) + 16px) 10px",
|
|
935
1048
|
display: "flex",
|
|
@@ -947,385 +1060,261 @@ function CredentialRequestForm(props) {
|
|
|
947
1060
|
padding: "16px 20px",
|
|
948
1061
|
display: "flex",
|
|
949
1062
|
flexDirection: "column",
|
|
950
|
-
gap:
|
|
1063
|
+
gap: 14
|
|
951
1064
|
},
|
|
952
|
-
children: [
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
style: {
|
|
962
|
-
fontSize: 14,
|
|
963
|
-
fontWeight: 500,
|
|
964
|
-
lineHeight: "22px"
|
|
965
|
-
},
|
|
966
|
-
children: t("form.intro")
|
|
967
|
-
})
|
|
968
|
-
}),
|
|
969
|
-
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
970
|
-
style: {
|
|
971
|
-
margin: 0,
|
|
972
|
-
fontSize: 12,
|
|
973
|
-
lineHeight: "18px",
|
|
974
|
-
color: "var(--dsw-alias-state-warn-label)"
|
|
975
|
-
},
|
|
976
|
-
children: error
|
|
977
|
-
}),
|
|
978
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
979
|
-
style: {
|
|
980
|
-
display: "flex",
|
|
981
|
-
gap: 8
|
|
982
|
-
},
|
|
983
|
-
children: [
|
|
984
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
985
|
-
type: "button",
|
|
986
|
-
onClick: () => {
|
|
987
|
-
onBrowserLogin();
|
|
988
|
-
},
|
|
989
|
-
style: {
|
|
990
|
-
...buttonStyle(false),
|
|
991
|
-
background: "var(--dsw-alias-button-primary-fill)",
|
|
992
|
-
color: "var(--dsw-alias-label-primary-foreground)"
|
|
993
|
-
},
|
|
994
|
-
children: t("form.browser.action")
|
|
995
|
-
}),
|
|
996
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
997
|
-
type: "button",
|
|
998
|
-
onClick: () => {
|
|
999
|
-
setPage("manual");
|
|
1000
|
-
setError(void 0);
|
|
1001
|
-
},
|
|
1002
|
-
style: {
|
|
1003
|
-
...buttonStyle(false),
|
|
1004
|
-
background: "transparent",
|
|
1005
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1006
|
-
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1007
|
-
},
|
|
1008
|
-
children: t("form.browser.aksk")
|
|
1009
|
-
}),
|
|
1010
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1011
|
-
type: "button",
|
|
1012
|
-
onClick: onCancel,
|
|
1013
|
-
style: {
|
|
1014
|
-
...buttonStyle(false),
|
|
1015
|
-
background: "transparent",
|
|
1016
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1017
|
-
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
1018
|
-
marginLeft: "auto"
|
|
1019
|
-
},
|
|
1020
|
-
children: t("form.browser.decline")
|
|
1021
|
-
})
|
|
1022
|
-
]
|
|
1023
|
-
})
|
|
1024
|
-
] }),
|
|
1025
|
-
page === "waiting" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1026
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1027
|
-
style: {
|
|
1028
|
-
display: "flex",
|
|
1029
|
-
flexDirection: "column",
|
|
1030
|
-
alignItems: "center",
|
|
1031
|
-
gap: 12,
|
|
1032
|
-
padding: "8px 0"
|
|
1033
|
-
},
|
|
1034
|
-
children: [
|
|
1035
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1036
|
-
role: "status",
|
|
1037
|
-
style: {
|
|
1038
|
-
fontSize: 14,
|
|
1039
|
-
fontWeight: 500,
|
|
1040
|
-
lineHeight: "22px"
|
|
1041
|
-
},
|
|
1042
|
-
children: t("form.browser.waiting")
|
|
1043
|
-
}),
|
|
1044
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1045
|
-
className: SPINNER_CLASS,
|
|
1046
|
-
style: {
|
|
1047
|
-
width: 28,
|
|
1048
|
-
height: 28
|
|
1049
|
-
},
|
|
1050
|
-
"aria-hidden": true
|
|
1051
|
-
}),
|
|
1052
|
-
secondsLeft !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1053
|
-
style: {
|
|
1054
|
-
fontSize: 13,
|
|
1055
|
-
fontVariantNumeric: "tabular-nums",
|
|
1056
|
-
color: "var(--dsw-alias-label-tertiary)"
|
|
1057
|
-
},
|
|
1058
|
-
children: t("form.browser.countdown", { time: formatCountdown(secondsLeft) })
|
|
1059
|
-
})
|
|
1060
|
-
]
|
|
1061
|
-
}),
|
|
1062
|
-
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1063
|
-
style: {
|
|
1064
|
-
margin: 0,
|
|
1065
|
-
fontSize: 12,
|
|
1066
|
-
lineHeight: "18px",
|
|
1067
|
-
color: "var(--dsw-alias-state-warn-label)"
|
|
1068
|
-
},
|
|
1069
|
-
children: error
|
|
1070
|
-
}),
|
|
1071
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1072
|
-
style: {
|
|
1073
|
-
display: "flex",
|
|
1074
|
-
gap: 8
|
|
1075
|
-
},
|
|
1076
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1077
|
-
type: "button",
|
|
1078
|
-
onClick: onCancelWaiting,
|
|
1079
|
-
style: {
|
|
1080
|
-
...buttonStyle(false),
|
|
1081
|
-
background: "transparent",
|
|
1082
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1083
|
-
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1084
|
-
},
|
|
1085
|
-
children: t("form.dismiss")
|
|
1086
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1087
|
-
type: "button",
|
|
1088
|
-
onClick: onReopen,
|
|
1089
|
-
style: {
|
|
1090
|
-
...buttonStyle(false),
|
|
1091
|
-
background: "transparent",
|
|
1092
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1093
|
-
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
1094
|
-
marginLeft: "auto"
|
|
1095
|
-
},
|
|
1096
|
-
children: t("form.browser.reopen")
|
|
1097
|
-
})]
|
|
1098
|
-
})
|
|
1099
|
-
] }),
|
|
1100
|
-
page === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1065
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1066
|
+
style: {
|
|
1067
|
+
fontSize: 14,
|
|
1068
|
+
fontWeight: 600,
|
|
1069
|
+
lineHeight: "22px"
|
|
1070
|
+
},
|
|
1071
|
+
children: t("form.title")
|
|
1072
|
+
}), signedIn ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1073
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1101
1074
|
style: {
|
|
1102
1075
|
display: "flex",
|
|
1103
1076
|
alignItems: "center",
|
|
1104
|
-
gap:
|
|
1077
|
+
gap: 8
|
|
1105
1078
|
},
|
|
1106
1079
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1107
|
-
|
|
1080
|
+
"aria-hidden": true,
|
|
1108
1081
|
style: {
|
|
1109
|
-
width:
|
|
1110
|
-
height:
|
|
1111
|
-
|
|
1112
|
-
|
|
1082
|
+
width: 8,
|
|
1083
|
+
height: 8,
|
|
1084
|
+
borderRadius: "50%",
|
|
1085
|
+
background: "var(--dsw-alias-state-success-primary)",
|
|
1086
|
+
flex: "none"
|
|
1087
|
+
}
|
|
1113
1088
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1114
|
-
role: "status",
|
|
1115
1089
|
style: {
|
|
1116
1090
|
fontSize: 14,
|
|
1117
|
-
lineHeight: "22px"
|
|
1118
|
-
color: "var(--dsw-alias-label-secondary)"
|
|
1091
|
+
lineHeight: "22px"
|
|
1119
1092
|
},
|
|
1120
|
-
children: t("form.
|
|
1093
|
+
children: status.accessKeyIdHint === "" ? t("form.signedIn") : status.accessKeyIdHint
|
|
1121
1094
|
})]
|
|
1122
1095
|
}),
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1096
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1097
|
+
style: { display: "flex" },
|
|
1098
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1099
|
+
type: "button",
|
|
1100
|
+
onClick: () => {
|
|
1101
|
+
onClear();
|
|
1129
1102
|
},
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1103
|
+
disabled: busy,
|
|
1104
|
+
style: buttonStyle(busy),
|
|
1105
|
+
children: clearing ? t("form.clearing") : t("form.logout")
|
|
1106
|
+
})
|
|
1107
|
+
}),
|
|
1108
|
+
manualError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1109
|
+
style: notice,
|
|
1110
|
+
children: manualError
|
|
1111
|
+
})
|
|
1112
|
+
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1113
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1114
|
+
style: {
|
|
1115
|
+
display: "flex",
|
|
1116
|
+
flexDirection: "column",
|
|
1117
|
+
gap: 8
|
|
1118
|
+
},
|
|
1119
|
+
children: [
|
|
1120
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1121
|
+
style: {
|
|
1122
|
+
fontSize: 13,
|
|
1123
|
+
fontWeight: 500,
|
|
1124
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
1125
|
+
},
|
|
1126
|
+
children: t("form.browser.section")
|
|
1127
|
+
}),
|
|
1128
|
+
phase === "running" && secondsLeft !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1129
|
+
role: "status",
|
|
1130
|
+
style: {
|
|
1131
|
+
fontSize: 13,
|
|
1132
|
+
lineHeight: "20px",
|
|
1133
|
+
textAlign: "center"
|
|
1134
|
+
},
|
|
1135
|
+
children: t("form.browser.running", { time: formatCountdown(secondsLeft) })
|
|
1136
|
+
}),
|
|
1137
|
+
phase === "checking" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1138
|
+
style: {
|
|
1139
|
+
fontSize: 12,
|
|
1140
|
+
lineHeight: "18px",
|
|
1141
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1142
|
+
},
|
|
1143
|
+
children: t("form.browser.checking")
|
|
1144
|
+
}),
|
|
1145
|
+
phase === "unsupported" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1146
|
+
role: "status",
|
|
1147
|
+
style: notice,
|
|
1148
|
+
children: t("form.browser.unsupported")
|
|
1149
|
+
}),
|
|
1150
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1151
|
+
style: {
|
|
1152
|
+
display: "flex",
|
|
1153
|
+
alignItems: "center",
|
|
1154
|
+
gap: 8
|
|
1155
|
+
},
|
|
1156
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1157
|
+
type: "button",
|
|
1158
|
+
onClick: phase === "running" ? onCancelLogin : onBrowserLogin,
|
|
1159
|
+
disabled: button.disabled,
|
|
1149
1160
|
style: {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
color: "var(--dsw-alias-label-tertiary)"
|
|
1161
|
+
...buttonStyle(button.disabled, button.disabled ? "secondary" : "primary"),
|
|
1162
|
+
flex: 1
|
|
1153
1163
|
},
|
|
1154
|
-
children:
|
|
1155
|
-
t("section.credentials.hint.prefix"),
|
|
1156
|
-
" ",
|
|
1157
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1158
|
-
href: CREDENTIAL_URL,
|
|
1159
|
-
target: "_blank",
|
|
1160
|
-
rel: "noreferrer noopener",
|
|
1161
|
-
style: {
|
|
1162
|
-
color: "var(--dsw-alias-button-primary-fill)",
|
|
1163
|
-
textDecoration: "underline"
|
|
1164
|
-
},
|
|
1165
|
-
children: t("section.credentials.hint.link")
|
|
1166
|
-
}),
|
|
1167
|
-
" ",
|
|
1168
|
-
t("section.credentials.hint.suffix")
|
|
1169
|
-
]
|
|
1164
|
+
children: t(button.label)
|
|
1170
1165
|
})
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1166
|
+
}),
|
|
1167
|
+
phase === "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1168
|
+
style: {
|
|
1169
|
+
fontSize: 12,
|
|
1170
|
+
lineHeight: "18px",
|
|
1171
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1172
|
+
},
|
|
1173
|
+
children: [
|
|
1174
|
+
t("form.browser.notOpened"),
|
|
1175
|
+
" ",
|
|
1176
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1177
|
+
type: "button",
|
|
1178
|
+
onClick: onCopyLink,
|
|
1179
|
+
style: {
|
|
1180
|
+
border: "none",
|
|
1181
|
+
background: "none",
|
|
1182
|
+
padding: 0,
|
|
1183
|
+
font: "inherit",
|
|
1184
|
+
color: "var(--dsw-alias-button-primary-fill)",
|
|
1185
|
+
textDecoration: "underline",
|
|
1186
|
+
cursor: "pointer"
|
|
1187
|
+
},
|
|
1188
|
+
children: t("form.browser.copyLink")
|
|
1189
|
+
})
|
|
1190
|
+
]
|
|
1191
|
+
}),
|
|
1192
|
+
browserError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1193
|
+
style: notice,
|
|
1194
|
+
children: browserError
|
|
1195
|
+
})
|
|
1196
|
+
]
|
|
1197
|
+
}),
|
|
1198
|
+
divider(t("form.or")),
|
|
1199
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1200
|
+
style: {
|
|
1201
|
+
display: "flex",
|
|
1202
|
+
flexDirection: "column",
|
|
1203
|
+
gap: 10
|
|
1204
|
+
},
|
|
1205
|
+
children: [
|
|
1206
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1207
|
+
style: {
|
|
1208
|
+
fontSize: 13,
|
|
1209
|
+
fontWeight: 500,
|
|
1210
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
1194
1211
|
},
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
})
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
children: t("section.field.secretKey")
|
|
1207
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1208
|
-
type: "password",
|
|
1209
|
-
value: sk,
|
|
1210
|
-
onChange: (e) => {
|
|
1211
|
-
interacted.current = true;
|
|
1212
|
-
setSk(e.target.value);
|
|
1212
|
+
children: t("form.manual.section")
|
|
1213
|
+
}),
|
|
1214
|
+
prefilled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1215
|
+
style: notice,
|
|
1216
|
+
children: t("form.prefilledFromEnv")
|
|
1217
|
+
}),
|
|
1218
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1219
|
+
style: {
|
|
1220
|
+
fontSize: 12,
|
|
1221
|
+
lineHeight: "18px",
|
|
1222
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1213
1223
|
},
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1224
|
+
children: [
|
|
1225
|
+
t("section.credentials.hint.prefix"),
|
|
1226
|
+
" ",
|
|
1227
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1228
|
+
href: CREDENTIAL_URL,
|
|
1229
|
+
target: "_blank",
|
|
1230
|
+
rel: "noreferrer noopener",
|
|
1231
|
+
style: {
|
|
1232
|
+
color: "var(--dsw-alias-button-primary-fill)",
|
|
1233
|
+
textDecoration: "underline"
|
|
1234
|
+
},
|
|
1235
|
+
children: t("section.credentials.hint.link")
|
|
1236
|
+
}),
|
|
1237
|
+
" ",
|
|
1238
|
+
t("section.credentials.hint.suffix")
|
|
1239
|
+
]
|
|
1240
|
+
}),
|
|
1241
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1242
|
+
style: fieldStyle,
|
|
1243
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1244
|
+
style: labelStyle,
|
|
1245
|
+
children: t("section.field.accessKey")
|
|
1246
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1247
|
+
type: "password",
|
|
1248
|
+
value: ak,
|
|
1249
|
+
disabled: manualDisabled,
|
|
1250
|
+
onChange: (e) => setAk(e.target.value),
|
|
1251
|
+
style: inputStyle(manualDisabled),
|
|
1252
|
+
placeholder: t("section.field.accessKey.placeholder"),
|
|
1253
|
+
"aria-label": t("section.field.accessKey"),
|
|
1254
|
+
autoComplete: "off",
|
|
1255
|
+
autoFocus: true
|
|
1256
|
+
})]
|
|
1257
|
+
}),
|
|
1258
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1259
|
+
style: fieldStyle,
|
|
1260
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1261
|
+
style: labelStyle,
|
|
1262
|
+
children: t("section.field.secretKey")
|
|
1263
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1264
|
+
type: "password",
|
|
1265
|
+
value: sk,
|
|
1266
|
+
disabled: manualDisabled,
|
|
1267
|
+
onChange: (e) => setSk(e.target.value),
|
|
1268
|
+
style: inputStyle(manualDisabled),
|
|
1269
|
+
placeholder: t("section.field.secretKey.placeholder"),
|
|
1270
|
+
"aria-label": t("section.field.secretKey"),
|
|
1271
|
+
autoComplete: "off"
|
|
1272
|
+
})]
|
|
1273
|
+
}),
|
|
1274
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1275
|
+
style: fieldStyle,
|
|
1276
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1277
|
+
style: labelStyle,
|
|
1278
|
+
children: t("section.field.token")
|
|
1279
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1280
|
+
type: "password",
|
|
1281
|
+
value: token,
|
|
1282
|
+
disabled: manualDisabled,
|
|
1283
|
+
onChange: (e) => setToken(e.target.value),
|
|
1284
|
+
style: inputStyle(manualDisabled),
|
|
1285
|
+
placeholder: t("section.field.token.placeholder"),
|
|
1286
|
+
"aria-label": t("section.field.token"),
|
|
1287
|
+
autoComplete: "off"
|
|
1288
|
+
})]
|
|
1289
|
+
}),
|
|
1290
|
+
manualError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1291
|
+
style: notice,
|
|
1292
|
+
children: manualError
|
|
1293
|
+
}),
|
|
1294
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1295
|
+
style: {
|
|
1296
|
+
display: "flex",
|
|
1297
|
+
gap: 8
|
|
1231
1298
|
},
|
|
1232
|
-
|
|
1233
|
-
placeholder: t("section.field.token.placeholder"),
|
|
1234
|
-
"aria-label": t("section.field.token"),
|
|
1235
|
-
autoComplete: "off"
|
|
1236
|
-
})]
|
|
1237
|
-
}),
|
|
1238
|
-
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1239
|
-
style: {
|
|
1240
|
-
margin: 0,
|
|
1241
|
-
fontSize: 12,
|
|
1242
|
-
lineHeight: "18px",
|
|
1243
|
-
color: "var(--dsw-alias-state-warn-label)"
|
|
1244
|
-
},
|
|
1245
|
-
children: error
|
|
1246
|
-
}),
|
|
1247
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1248
|
-
style: {
|
|
1249
|
-
display: "flex",
|
|
1250
|
-
gap: 8
|
|
1251
|
-
},
|
|
1252
|
-
children: [
|
|
1253
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1299
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1254
1300
|
type: "submit",
|
|
1255
|
-
disabled,
|
|
1256
|
-
style:
|
|
1257
|
-
...buttonStyle(disabled),
|
|
1258
|
-
background: "var(--dsw-alias-button-primary-fill)",
|
|
1259
|
-
color: "var(--dsw-alias-label-primary-foreground)"
|
|
1260
|
-
},
|
|
1301
|
+
disabled: submitDisabled,
|
|
1302
|
+
style: buttonStyle(submitDisabled, "primary"),
|
|
1261
1303
|
children: saving ? t("section.credentials.saving") : t("form.submit")
|
|
1262
|
-
}),
|
|
1263
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1304
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1264
1305
|
type: "button",
|
|
1265
1306
|
onClick: onCancel,
|
|
1266
1307
|
disabled: busy,
|
|
1267
|
-
style:
|
|
1268
|
-
...buttonStyle(busy),
|
|
1269
|
-
background: "transparent",
|
|
1270
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1271
|
-
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1272
|
-
},
|
|
1308
|
+
style: buttonStyle(busy),
|
|
1273
1309
|
children: t("form.dismiss")
|
|
1274
|
-
})
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
setError(void 0);
|
|
1280
|
-
},
|
|
1281
|
-
disabled: busy,
|
|
1282
|
-
style: {
|
|
1283
|
-
...buttonStyle(busy),
|
|
1284
|
-
background: "transparent",
|
|
1285
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1286
|
-
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1287
|
-
},
|
|
1288
|
-
children: t("form.back")
|
|
1289
|
-
}),
|
|
1290
|
-
hasCredentials && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1291
|
-
type: "button",
|
|
1292
|
-
onClick: () => {
|
|
1293
|
-
onClear();
|
|
1294
|
-
},
|
|
1295
|
-
disabled: busy,
|
|
1296
|
-
style: {
|
|
1297
|
-
...buttonStyle(busy),
|
|
1298
|
-
background: "transparent",
|
|
1299
|
-
color: "var(--dsw-alias-label-primary)",
|
|
1300
|
-
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
1301
|
-
marginLeft: "auto"
|
|
1302
|
-
},
|
|
1303
|
-
children: clearing ? t("form.clearing") : t("form.clear")
|
|
1304
|
-
})
|
|
1305
|
-
]
|
|
1306
|
-
})
|
|
1307
|
-
] })
|
|
1308
|
-
]
|
|
1310
|
+
})]
|
|
1311
|
+
})
|
|
1312
|
+
]
|
|
1313
|
+
})
|
|
1314
|
+
] })]
|
|
1309
1315
|
})
|
|
1310
1316
|
});
|
|
1311
1317
|
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Render a countdown as `m:ss`.
|
|
1314
|
-
*
|
|
1315
|
-
* Language-neutral on purpose: the surrounding sentence is localised, and a
|
|
1316
|
-
* number plus a unit needs no translation to read — whereas spelling out
|
|
1317
|
-
* "minutes"/"分" would put a second copy of the same unit in both dictionaries
|
|
1318
|
-
* for no gain. Tabular figures are applied at the call site so the digits do
|
|
1319
|
-
* not jitter as they change.
|
|
1320
|
-
*
|
|
1321
|
-
* @param seconds - seconds remaining.
|
|
1322
|
-
*/
|
|
1323
|
-
function formatCountdown(seconds) {
|
|
1324
|
-
const whole = Math.max(0, Math.floor(seconds));
|
|
1325
|
-
const minutes = Math.floor(whole / 60);
|
|
1326
|
-
const rest = whole % 60;
|
|
1327
|
-
return `${String(minutes)}:${String(rest).padStart(2, "0")}`;
|
|
1328
|
-
}
|
|
1329
1318
|
|
|
1330
1319
|
//#endregion
|
|
1331
1320
|
//#region src/client/CredentialFormInteraction.ts
|
|
@@ -1444,26 +1433,32 @@ const zh = {
|
|
|
1444
1433
|
"section.credentials.hint.link": "API Explorer",
|
|
1445
1434
|
"section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
|
|
1446
1435
|
"section.credentials.saving": "保存中…",
|
|
1447
|
-
"form.title
|
|
1448
|
-
"form.
|
|
1436
|
+
"form.title": "华为云 IAM 认证",
|
|
1437
|
+
"form.or": "或者",
|
|
1438
|
+
"form.signedIn": "已登录",
|
|
1439
|
+
"form.logout": "退出",
|
|
1440
|
+
"form.browser.section": "选项一:浏览器登录",
|
|
1441
|
+
"form.browser.action": "登录",
|
|
1442
|
+
"form.browser.checking": "环境检测中…",
|
|
1443
|
+
"form.browser.unsupported": "当前环境不支持该方式。",
|
|
1444
|
+
"form.browser.unsupportedLabel": "不支持",
|
|
1445
|
+
"form.browser.cancelLabel": "取消登录",
|
|
1446
|
+
"form.browser.running": "登录中({time})",
|
|
1447
|
+
"form.browser.notOpened": "若浏览器未自动打开,请",
|
|
1448
|
+
"form.browser.copyLink": "手动复制链接到浏览器打开",
|
|
1449
|
+
"form.browser.blocked": "浏览器拦截了新标签页,请允许弹出窗口后重试。",
|
|
1450
|
+
"form.browser.copyFailed": "无法复制链接,请手动从浏览器地址栏重试。",
|
|
1451
|
+
"form.browser.failed": "浏览器登录未完成。",
|
|
1452
|
+
"form.browser.startFailed": "无法启动浏览器登录,请改用 AK/SK 或稍后重试。",
|
|
1453
|
+
"form.browser.expired": "登录超时,请重试。",
|
|
1454
|
+
"form.manual.section": "选项二:配置 AK/SK",
|
|
1455
|
+
"form.prefilledFromEnv": "已填入检测到的环境变量",
|
|
1449
1456
|
"form.submit": "提交",
|
|
1450
1457
|
"form.dismiss": "取消",
|
|
1451
1458
|
"form.failed": "保存凭据失败",
|
|
1452
|
-
"form.clear": "清除",
|
|
1453
1459
|
"form.clearing": "清除中…",
|
|
1454
1460
|
"form.clear.failed": "清除凭据失败",
|
|
1455
1461
|
"error.unreachable": "无法连接宿主凭据服务:",
|
|
1456
|
-
"form.intro": "需要进行华为云 IAM 认证",
|
|
1457
|
-
"form.checking": "正在检查登录方式…",
|
|
1458
|
-
"form.browser.action": "浏览器登录",
|
|
1459
|
-
"form.browser.aksk": "我有AK/SK",
|
|
1460
|
-
"form.browser.decline": "暂不认证",
|
|
1461
|
-
"form.browser.waiting": "正在等待浏览器完成登录…",
|
|
1462
|
-
"form.browser.countdown": "剩余 {time}",
|
|
1463
|
-
"form.browser.reopen": "重新打开",
|
|
1464
|
-
"form.back": "返回",
|
|
1465
|
-
"form.browser.blocked": "浏览器拦截了新标签页,请允许弹出窗口后重试。",
|
|
1466
|
-
"form.browser.failed": "浏览器登录未完成:",
|
|
1467
1462
|
"section.field.accessKey": "Access Key",
|
|
1468
1463
|
"section.field.accessKey.placeholder": "华为云 Access Key",
|
|
1469
1464
|
"section.field.accessKey.hint": "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。",
|
|
@@ -1489,26 +1484,32 @@ const en = {
|
|
|
1489
1484
|
"section.credentials.hint.link": "API Explorer",
|
|
1490
1485
|
"section.credentials.hint.suffix": "and avoid permanent ones.",
|
|
1491
1486
|
"section.credentials.saving": "Saving…",
|
|
1492
|
-
"form.title
|
|
1493
|
-
"form.
|
|
1487
|
+
"form.title": "Huawei Cloud IAM authentication",
|
|
1488
|
+
"form.or": "or",
|
|
1489
|
+
"form.signedIn": "Signed in",
|
|
1490
|
+
"form.logout": "Logout",
|
|
1491
|
+
"form.browser.section": "Option 1: sign in with a browser",
|
|
1492
|
+
"form.browser.action": "Sign in",
|
|
1493
|
+
"form.browser.checking": "Checking this environment…",
|
|
1494
|
+
"form.browser.unsupported": "This environment does not support that method.",
|
|
1495
|
+
"form.browser.unsupportedLabel": "Unsupported",
|
|
1496
|
+
"form.browser.cancelLabel": "Cancel sign-in",
|
|
1497
|
+
"form.browser.running": "Signing in ({time})",
|
|
1498
|
+
"form.browser.notOpened": "If the browser did not open,",
|
|
1499
|
+
"form.browser.copyLink": "copy the link into your browser",
|
|
1500
|
+
"form.browser.blocked": "The browser blocked the new tab. Allow pop-ups for this page, then try again.",
|
|
1501
|
+
"form.browser.copyFailed": "Could not copy the link. Try again from the browser address bar.",
|
|
1502
|
+
"form.browser.failed": "The browser sign-in did not complete.",
|
|
1503
|
+
"form.browser.startFailed": "Could not start the browser sign-in. Use an AK/SK instead, or try again.",
|
|
1504
|
+
"form.browser.expired": "The sign-in timed out. Try again.",
|
|
1505
|
+
"form.manual.section": "Option 2: configure an AK/SK",
|
|
1506
|
+
"form.prefilledFromEnv": "Filled in from detected environment variables",
|
|
1494
1507
|
"form.submit": "Submit",
|
|
1495
1508
|
"form.dismiss": "Cancel",
|
|
1496
1509
|
"form.failed": "Could not save credentials",
|
|
1497
|
-
"form.clear": "Clear",
|
|
1498
1510
|
"form.clearing": "Clearing…",
|
|
1499
1511
|
"form.clear.failed": "Could not clear credentials",
|
|
1500
1512
|
"error.unreachable": "Could not reach the host credential service: ",
|
|
1501
|
-
"form.intro": "Huawei Cloud IAM authentication is required",
|
|
1502
|
-
"form.checking": "Checking sign-in options…",
|
|
1503
|
-
"form.browser.action": "Sign in with a browser",
|
|
1504
|
-
"form.browser.aksk": "I have one",
|
|
1505
|
-
"form.browser.decline": "Not now",
|
|
1506
|
-
"form.browser.waiting": "Waiting for the browser sign-in to finish…",
|
|
1507
|
-
"form.browser.countdown": "{time} left",
|
|
1508
|
-
"form.browser.reopen": "Reopen",
|
|
1509
|
-
"form.back": "Back",
|
|
1510
|
-
"form.browser.blocked": "The browser blocked the new tab. Allow pop-ups for this page, then try again.",
|
|
1511
|
-
"form.browser.failed": "The browser sign-in did not complete: ",
|
|
1512
1513
|
"section.field.accessKey": "Access Key",
|
|
1513
1514
|
"section.field.accessKey.placeholder": "Huawei Access Key",
|
|
1514
1515
|
"section.field.accessKey.hint": "Access Key and Secret Key are stored as a pair; one without the other is not saved.",
|
|
@@ -1630,7 +1631,6 @@ function apply(ctx) {
|
|
|
1630
1631
|
}), "aishell-credentials: dictionaries");
|
|
1631
1632
|
const t = ctx.locale.bind(NS);
|
|
1632
1633
|
installChipStyles(ctx);
|
|
1633
|
-
installSpinnerStyles(ctx);
|
|
1634
1634
|
const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
|
|
1635
1635
|
const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
1636
1636
|
hasAccessKey: false,
|
|
@@ -1668,8 +1668,24 @@ function apply(ctx) {
|
|
|
1668
1668
|
* name.
|
|
1669
1669
|
*/
|
|
1670
1670
|
let pendingRequestToken;
|
|
1671
|
+
/**
|
|
1672
|
+
* Whether the first pass over the document has run.
|
|
1673
|
+
*
|
|
1674
|
+
* The document is persisted, so on a fresh page load it still holds whatever
|
|
1675
|
+
* request the previous session left there. Acting on that would open the form
|
|
1676
|
+
* for a question nobody is asking — the same bug the host clears the field
|
|
1677
|
+
* for at startup, and this half must not open it in the window before that
|
|
1678
|
+
* write lands. The first pass establishes the baseline: whatever is already
|
|
1679
|
+
* in the document when this page loads is not a request addressed to it.
|
|
1680
|
+
*/
|
|
1681
|
+
let primed = false;
|
|
1671
1682
|
const applyFormRequest = () => {
|
|
1672
1683
|
const request = decodeRequest(form.getSnapshot().value?.credentialFormRequest);
|
|
1684
|
+
if (!primed) {
|
|
1685
|
+
primed = true;
|
|
1686
|
+
lastRequestToken = request?.token;
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1673
1689
|
if (request === void 0 || request.token === lastRequestToken) return;
|
|
1674
1690
|
lastRequestToken = request.token;
|
|
1675
1691
|
pendingRequestToken = request.token;
|
|
@@ -1736,6 +1752,7 @@ function apply(ctx) {
|
|
|
1736
1752
|
},
|
|
1737
1753
|
save: (ak, sk, token) => saveCredential(t, ak, sk, token, pendingRequestToken),
|
|
1738
1754
|
readPrefill: () => readPrefill(),
|
|
1755
|
+
probeBrowserRoute: (signal) => probeBrowserRoute(signal),
|
|
1739
1756
|
startBrowserLogin: () => startBrowserLogin(),
|
|
1740
1757
|
clear: () => clearBothStores(t),
|
|
1741
1758
|
close: () => {
|