@huaweidevtools/aishell-dsh-client-credentials 0.0.1-beta.5 → 0.0.1-beta.7
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 +705 -128
- package/lib/index.js +977 -5
- package/lib/types/client/CredentialRequestForm.d.ts +26 -0
- package/lib/types/client/locales.d.ts +22 -2
- package/lib/types/client/login-flow.d.ts +98 -0
- package/lib/types/client/spinner.d.ts +32 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/login-status.d.ts +62 -0
- package/lib/types/out-of-band/contract.d.ts +199 -0
- package/lib/types/out-of-band/flow.d.ts +82 -0
- package/lib/types/out-of-band/listener.d.ts +156 -0
- package/lib/types/out-of-band/login.d.ts +144 -0
- package/lib/types/out-of-band/routes.d.ts +108 -0
- package/lib/types/prefill.d.ts +78 -0
- package/package.json +2 -2
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 = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
146
|
+
const PLUGIN_ID$1 = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
147
147
|
/** Dedupe key for the one sheet this module owns. */
|
|
148
|
-
const CHIP_STYLE_KEY = `${PLUGIN_ID}/chip-hover`;
|
|
148
|
+
const CHIP_STYLE_KEY = `${PLUGIN_ID$1}/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$1;
|
|
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);
|
|
@@ -457,6 +457,184 @@ function AishellHeroChip(props) {
|
|
|
457
457
|
*/
|
|
458
458
|
const CREDENTIAL_URL = "https://console.huaweicloud.com/apiexplorer/#/openapi/IAM/doc?version=v3&api=CreateTemporaryAccessKeyByToken";
|
|
459
459
|
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/login-status.ts
|
|
462
|
+
/**
|
|
463
|
+
* Header the reachability probe sends, to force a CORS preflight.
|
|
464
|
+
*
|
|
465
|
+
* Any non-safelisted header would do it; this one names why. Declared here
|
|
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 its preflight answer,
|
|
468
|
+
* and a mismatch between the two is a probe that fails on a deployment that
|
|
469
|
+
* would actually work — the entry hidden for no reason.
|
|
470
|
+
*/
|
|
471
|
+
const PROBE_HEADER = "x-aishell-probe";
|
|
472
|
+
/**
|
|
473
|
+
* Read an outcome back out of the document.
|
|
474
|
+
*
|
|
475
|
+
* Anything unreadable reads as no outcome: a corrupt field should show
|
|
476
|
+
* nothing, not a spurious success.
|
|
477
|
+
*
|
|
478
|
+
* @param raw - the stored string, if any.
|
|
479
|
+
* @returns the outcome, or `undefined` when there is none usable.
|
|
480
|
+
*/
|
|
481
|
+
function decodeOutcome(raw) {
|
|
482
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
483
|
+
let parsed;
|
|
484
|
+
try {
|
|
485
|
+
parsed = JSON.parse(raw);
|
|
486
|
+
} catch {
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
489
|
+
if (parsed === null || typeof parsed !== "object") return void 0;
|
|
490
|
+
const candidate = parsed;
|
|
491
|
+
if (candidate.kind === "succeeded" && typeof candidate.accountName === "string") return {
|
|
492
|
+
kind: "succeeded",
|
|
493
|
+
accountName: candidate.accountName
|
|
494
|
+
};
|
|
495
|
+
if (candidate.kind === "failed" && typeof candidate.error === "string") return {
|
|
496
|
+
kind: "failed",
|
|
497
|
+
error: candidate.error
|
|
498
|
+
};
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/client/login-flow.ts
|
|
504
|
+
/**
|
|
505
|
+
* How long either half of the capability check may take.
|
|
506
|
+
*
|
|
507
|
+
* Short, because both are expected to be immediate: a loopback request that
|
|
508
|
+
* works answers in well under a millisecond. The bound exists so a deployment
|
|
509
|
+
* that cannot do this says so by falling through to the manual form rather
|
|
510
|
+
* than by leaving the card blank.
|
|
511
|
+
*/
|
|
512
|
+
const PROBE_TIMEOUT_MS = 3e3;
|
|
513
|
+
/** Routes the browser half drives a login through. */
|
|
514
|
+
const LOGIN_START_ROUTE = "api/aishell/credentials/login/start";
|
|
515
|
+
const LOGIN_CANCEL_ROUTE = "api/aishell/credentials/login/cancel";
|
|
516
|
+
/**
|
|
517
|
+
* Reachability check, then login.
|
|
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;
|
|
537
|
+
try {
|
|
538
|
+
const response = await fetch(LOGIN_START_ROUTE, {
|
|
539
|
+
method: "POST",
|
|
540
|
+
headers: { "content-type": "application/json" },
|
|
541
|
+
body: JSON.stringify({}),
|
|
542
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
|
|
543
|
+
});
|
|
544
|
+
started = await response.json();
|
|
545
|
+
} catch {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
if (started.ok !== true || started.loginUrl === void 0) return void 0;
|
|
549
|
+
const loginUrl = started.loginUrl;
|
|
550
|
+
const providerName = started.providerName ?? "";
|
|
551
|
+
const expiresInSeconds = started.expiresInSeconds ?? 0;
|
|
552
|
+
const cancel = () => {
|
|
553
|
+
fetch(LOGIN_CANCEL_ROUTE, { method: "POST" }).catch(() => {});
|
|
554
|
+
};
|
|
555
|
+
if (started.probeUrl === void 0 || started.probeUrl === "") {
|
|
556
|
+
cancel();
|
|
557
|
+
return void 0;
|
|
558
|
+
}
|
|
559
|
+
try {
|
|
560
|
+
const probe = await fetch(started.probeUrl, {
|
|
561
|
+
method: "GET",
|
|
562
|
+
headers: { [PROBE_HEADER]: "1" },
|
|
563
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
|
|
564
|
+
});
|
|
565
|
+
if (!probe.ok) {
|
|
566
|
+
cancel();
|
|
567
|
+
return void 0;
|
|
568
|
+
}
|
|
569
|
+
} catch (error) {
|
|
570
|
+
cancel();
|
|
571
|
+
return void 0;
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
loginUrl,
|
|
575
|
+
providerName,
|
|
576
|
+
expiresInSeconds,
|
|
577
|
+
cancel
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Open a login URL in a new tab.
|
|
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.
|
|
586
|
+
*
|
|
587
|
+
* ## Why `noopener` is set after opening, not passed in
|
|
588
|
+
*
|
|
589
|
+
* `window.open` returns `null` whenever `noopener` appears in its features
|
|
590
|
+
* string — by specification, not as a failure. Passing it there would make
|
|
591
|
+
* every successful open look blocked, so the tab is opened plainly and the
|
|
592
|
+
* opener reference is severed immediately afterwards, which is the same
|
|
593
|
+
* protection without losing the success signal.
|
|
594
|
+
*
|
|
595
|
+
* @param url - the URL the host returned.
|
|
596
|
+
* @returns whether the browser opened it; a popup blocker says no.
|
|
597
|
+
*/
|
|
598
|
+
function openLoginWindow(url) {
|
|
599
|
+
const opened = window.open(url, "_blank");
|
|
600
|
+
if (opened === null) return false;
|
|
601
|
+
try {
|
|
602
|
+
opened.opener = null;
|
|
603
|
+
} catch {}
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/client/spinner.ts
|
|
609
|
+
/** Class the waiting spinner carries. */
|
|
610
|
+
const SPINNER_CLASS = "aishell-spinner";
|
|
611
|
+
/** Marker identifying this sheet, so teardown sweeps exactly it. */
|
|
612
|
+
const SPINNER_STYLE_KEY = "aishell-credentials:spinner";
|
|
613
|
+
/** Plugin id the loader attributes the tag to. */
|
|
614
|
+
const PLUGIN_ID = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
615
|
+
/**
|
|
616
|
+
* Install the spinner keyframes for the lifetime of the plugin fiber.
|
|
617
|
+
*
|
|
618
|
+
* Respects `prefers-reduced-motion`: a continuous rotation is exactly the kind
|
|
619
|
+
* of motion that setting exists to suppress, and the countdown beside it still
|
|
620
|
+
* conveys that work is in progress.
|
|
621
|
+
*
|
|
622
|
+
* @param ctx - the client context, for `ctx.effect`.
|
|
623
|
+
*/
|
|
624
|
+
function installSpinnerStyles(ctx) {
|
|
625
|
+
if (typeof document === "undefined") return;
|
|
626
|
+
ctx.effect(() => {
|
|
627
|
+
const tag = document.createElement("style");
|
|
628
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
629
|
+
tag.dataset.pluginCss = SPINNER_STYLE_KEY;
|
|
630
|
+
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}}`;
|
|
631
|
+
document.head.appendChild(tag);
|
|
632
|
+
return () => {
|
|
633
|
+
tag.remove();
|
|
634
|
+
};
|
|
635
|
+
}, "aishell-credentials: spinner styles");
|
|
636
|
+
}
|
|
637
|
+
|
|
460
638
|
//#endregion
|
|
461
639
|
//#region src/client/CredentialRequestForm.tsx
|
|
462
640
|
/**
|
|
@@ -477,6 +655,147 @@ function CredentialRequestForm(props) {
|
|
|
477
655
|
const [saving, setSaving] = (0, react.useState)(false);
|
|
478
656
|
const [clearing, setClearing] = (0, react.useState)(false);
|
|
479
657
|
const [error, setError] = (0, react.useState)(void 0);
|
|
658
|
+
/**
|
|
659
|
+
* Whether the fields were seeded from the environment.
|
|
660
|
+
*
|
|
661
|
+
* Shown so the person knows where the values came from — a credential that
|
|
662
|
+
* silently appeared in a field is worse than an empty one, because they
|
|
663
|
+
* cannot tell whether to trust it.
|
|
664
|
+
*/
|
|
665
|
+
const [prefilled, setPrefilled] = (0, react.useState)(false);
|
|
666
|
+
/**
|
|
667
|
+
* The browser-login entry, once the host has started one and this page has
|
|
668
|
+
* proved it can reach the listener.
|
|
669
|
+
*
|
|
670
|
+
* `undefined` while that is still being decided, and `null` once it is
|
|
671
|
+
* decided against — the distinction matters, because "still checking" must
|
|
672
|
+
* not render the entry and "cannot" must not either, but only one of them
|
|
673
|
+
* resolves into it appearing.
|
|
674
|
+
*/
|
|
675
|
+
const [browserLogin, setBrowserLogin] = (0, react.useState)(void 0);
|
|
676
|
+
/**
|
|
677
|
+
* Which page the card is on.
|
|
678
|
+
*
|
|
679
|
+
* `choose` is the first page: the browser entry, if this deployment has one,
|
|
680
|
+
* and the way to the manual form. `manual` is the AK/SK form — what the card
|
|
681
|
+
* has always been. `waiting` is a browser login in flight.
|
|
682
|
+
*
|
|
683
|
+
* Starts on `manual`, which is what the card has always been, and moves to
|
|
684
|
+
* `choose` only once the probe has proved a browser login is possible here.
|
|
685
|
+
* The other order — opening on `choose` and falling back — would show a
|
|
686
|
+
* browser button that does nothing while the probe is in flight, and would
|
|
687
|
+
* land a deployment that cannot do this on a page it has no use for.
|
|
688
|
+
*/
|
|
689
|
+
const [page, setPage] = (0, react.useState)("manual");
|
|
690
|
+
/** Seconds left before the login can no longer complete; `undefined` when idle. */
|
|
691
|
+
const [secondsLeft, setSecondsLeft] = (0, react.useState)(void 0);
|
|
692
|
+
/**
|
|
693
|
+
* Whether the person has started filling the manual form.
|
|
694
|
+
*
|
|
695
|
+
* The probe is fast on the deployments this works on and slow on the ones it
|
|
696
|
+
* does not, so its answer can arrive after someone has begun typing. When it
|
|
697
|
+
* does, the choice page must not replace the form under their cursor.
|
|
698
|
+
*/
|
|
699
|
+
const interacted = (0, react.useRef)(false);
|
|
700
|
+
(0, react.useEffect)(() => {
|
|
701
|
+
let live = true;
|
|
702
|
+
props.readPrefill().then((prefill) => {
|
|
703
|
+
const { accessKeyId, secretAccessKey } = prefill;
|
|
704
|
+
if (!live || accessKeyId === void 0 || secretAccessKey === void 0) return;
|
|
705
|
+
setAk((current) => current === "" ? accessKeyId : current);
|
|
706
|
+
setSk((current) => current === "" ? secretAccessKey : current);
|
|
707
|
+
setToken((current) => current === "" ? prefill.securityToken ?? "" : current);
|
|
708
|
+
setPrefilled(true);
|
|
709
|
+
}).catch(() => {});
|
|
710
|
+
return () => {
|
|
711
|
+
live = false;
|
|
712
|
+
};
|
|
713
|
+
}, []);
|
|
714
|
+
(0, react.useEffect)(() => {
|
|
715
|
+
let live = true;
|
|
716
|
+
props.startBrowserLogin().then((handle) => {
|
|
717
|
+
if (!live) {
|
|
718
|
+
handle?.cancel();
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
setBrowserLogin(handle ?? null);
|
|
722
|
+
if (handle !== null && !interacted.current) setPage("choose");
|
|
723
|
+
}).catch(() => {
|
|
724
|
+
if (!live) return;
|
|
725
|
+
setBrowserLogin(null);
|
|
726
|
+
});
|
|
727
|
+
return () => {
|
|
728
|
+
live = false;
|
|
729
|
+
};
|
|
730
|
+
}, []);
|
|
731
|
+
(0, react.useEffect)(() => () => {
|
|
732
|
+
browserLogin?.cancel();
|
|
733
|
+
}, [browserLogin]);
|
|
734
|
+
(0, react.useEffect)(() => {
|
|
735
|
+
if (page !== "waiting" || secondsLeft === void 0) return;
|
|
736
|
+
const deadline = Date.now() + secondsLeft * 1e3;
|
|
737
|
+
const timer = window.setInterval(() => {
|
|
738
|
+
setSecondsLeft(Math.max(0, Math.round((deadline - Date.now()) / 1e3)));
|
|
739
|
+
}, 1e3);
|
|
740
|
+
return () => {
|
|
741
|
+
window.clearInterval(timer);
|
|
742
|
+
};
|
|
743
|
+
}, [page]);
|
|
744
|
+
const outcomeRaw = props.useLoginOutcome((snapshot) => snapshot);
|
|
745
|
+
/**
|
|
746
|
+
* The outcome already recorded when this form opened.
|
|
747
|
+
*
|
|
748
|
+
* The document keeps the last login's outcome, so a form opened later would
|
|
749
|
+
* otherwise react to a result that has nothing to do with it: after a
|
|
750
|
+
* successful login the next open would close itself on the spot, and after a
|
|
751
|
+
* failed one it would show that error before the person typed anything.
|
|
752
|
+
* Baselines are per mount, which is per open — the interaction's key changes
|
|
753
|
+
* on reopen, so the component remounts.
|
|
754
|
+
*/
|
|
755
|
+
const outcomeAtMount = (0, react.useRef)(null);
|
|
756
|
+
if (outcomeAtMount.current === null) outcomeAtMount.current = outcomeRaw;
|
|
757
|
+
(0, react.useEffect)(() => {
|
|
758
|
+
if (outcomeRaw === outcomeAtMount.current) return;
|
|
759
|
+
const outcome = decodeOutcome(outcomeRaw);
|
|
760
|
+
if (outcome === void 0) return;
|
|
761
|
+
if (outcome.kind === "succeeded") {
|
|
762
|
+
setAk("");
|
|
763
|
+
setSk("");
|
|
764
|
+
setToken("");
|
|
765
|
+
close();
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
setPage(browserLogin ? "choose" : "manual");
|
|
769
|
+
setSecondsLeft(void 0);
|
|
770
|
+
setError(outcome.kind === "failed" && outcome.error !== "" ? t("form.browser.failed") + outcome.error : void 0);
|
|
771
|
+
}, [outcomeRaw]);
|
|
772
|
+
const onBrowserLogin = () => {
|
|
773
|
+
if (browserLogin === null || browserLogin === void 0) return;
|
|
774
|
+
setError(void 0);
|
|
775
|
+
if (!openLoginWindow(browserLogin.loginUrl)) {
|
|
776
|
+
setError(t("form.browser.blocked"));
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
setPage("waiting");
|
|
780
|
+
setSecondsLeft(browserLogin.expiresInSeconds);
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Abandon the browser login.
|
|
784
|
+
*
|
|
785
|
+
* This is a cancel, not a dismissal: the card is up because a tool call is
|
|
786
|
+
* blocked on it, so closing it has to answer that call. `cancel` does both —
|
|
787
|
+
* it records the refusal against the request token (so the tool stops
|
|
788
|
+
* asking) and withdraws the interaction — and it releases the host's
|
|
789
|
+
* listener, whose URL is dead the moment this card goes away.
|
|
790
|
+
*/
|
|
791
|
+
const onCancelWaiting = () => {
|
|
792
|
+
onCancel();
|
|
793
|
+
};
|
|
794
|
+
/** Reopen the sign-in tab after the person closed it by accident. */
|
|
795
|
+
const onReopen = () => {
|
|
796
|
+
if (browserLogin === null || browserLogin === void 0) return;
|
|
797
|
+
if (!openLoginWindow(browserLogin.loginUrl)) setError(t("form.browser.blocked"));
|
|
798
|
+
};
|
|
480
799
|
const onSubmit = async (event) => {
|
|
481
800
|
event.preventDefault();
|
|
482
801
|
setSaving(true);
|
|
@@ -510,6 +829,7 @@ function CredentialRequestForm(props) {
|
|
|
510
829
|
}
|
|
511
830
|
};
|
|
512
831
|
const onCancel = () => {
|
|
832
|
+
browserLogin?.cancel();
|
|
513
833
|
cancel();
|
|
514
834
|
};
|
|
515
835
|
const fieldStyle = {
|
|
@@ -575,157 +895,359 @@ function CredentialRequestForm(props) {
|
|
|
575
895
|
gap: 12
|
|
576
896
|
},
|
|
577
897
|
children: [
|
|
578
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(
|
|
579
|
-
|
|
580
|
-
display: "flex",
|
|
581
|
-
flexDirection: "column",
|
|
582
|
-
gap: 4
|
|
583
|
-
},
|
|
584
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
898
|
+
page === "choose" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
899
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
585
900
|
style: {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
901
|
+
display: "flex",
|
|
902
|
+
flexDirection: "column",
|
|
903
|
+
gap: 4
|
|
589
904
|
},
|
|
590
|
-
children:
|
|
591
|
-
|
|
905
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
906
|
+
style: {
|
|
907
|
+
fontSize: 14,
|
|
908
|
+
fontWeight: 500,
|
|
909
|
+
lineHeight: "22px"
|
|
910
|
+
},
|
|
911
|
+
children: t("form.intro")
|
|
912
|
+
})
|
|
913
|
+
}),
|
|
914
|
+
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
592
915
|
style: {
|
|
916
|
+
margin: 0,
|
|
593
917
|
fontSize: 12,
|
|
594
918
|
lineHeight: "18px",
|
|
595
|
-
color: "var(--dsw-alias-label
|
|
919
|
+
color: "var(--dsw-alias-state-warn-label)"
|
|
920
|
+
},
|
|
921
|
+
children: error
|
|
922
|
+
}),
|
|
923
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
924
|
+
style: {
|
|
925
|
+
display: "flex",
|
|
926
|
+
gap: 8
|
|
927
|
+
},
|
|
928
|
+
children: [
|
|
929
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
930
|
+
type: "button",
|
|
931
|
+
onClick: () => {
|
|
932
|
+
onBrowserLogin();
|
|
933
|
+
},
|
|
934
|
+
style: {
|
|
935
|
+
...buttonStyle(false),
|
|
936
|
+
background: "var(--dsw-alias-button-primary-fill)",
|
|
937
|
+
color: "var(--dsw-alias-label-primary-foreground)"
|
|
938
|
+
},
|
|
939
|
+
children: t("form.browser.action")
|
|
940
|
+
}),
|
|
941
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
942
|
+
type: "button",
|
|
943
|
+
onClick: () => {
|
|
944
|
+
setPage("manual");
|
|
945
|
+
setError(void 0);
|
|
946
|
+
},
|
|
947
|
+
style: {
|
|
948
|
+
...buttonStyle(false),
|
|
949
|
+
background: "transparent",
|
|
950
|
+
color: "var(--dsw-alias-label-primary)",
|
|
951
|
+
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
952
|
+
},
|
|
953
|
+
children: t("form.browser.aksk")
|
|
954
|
+
}),
|
|
955
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
956
|
+
type: "button",
|
|
957
|
+
onClick: onCancel,
|
|
958
|
+
style: {
|
|
959
|
+
...buttonStyle(false),
|
|
960
|
+
background: "transparent",
|
|
961
|
+
color: "var(--dsw-alias-label-primary)",
|
|
962
|
+
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
963
|
+
marginLeft: "auto"
|
|
964
|
+
},
|
|
965
|
+
children: t("form.browser.decline")
|
|
966
|
+
})
|
|
967
|
+
]
|
|
968
|
+
})
|
|
969
|
+
] }),
|
|
970
|
+
page === "waiting" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
971
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
972
|
+
style: {
|
|
973
|
+
display: "flex",
|
|
974
|
+
flexDirection: "column",
|
|
975
|
+
alignItems: "center",
|
|
976
|
+
gap: 12,
|
|
977
|
+
padding: "8px 0"
|
|
596
978
|
},
|
|
597
979
|
children: [
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
980
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
981
|
+
role: "status",
|
|
982
|
+
style: {
|
|
983
|
+
fontSize: 14,
|
|
984
|
+
fontWeight: 500,
|
|
985
|
+
lineHeight: "22px"
|
|
986
|
+
},
|
|
987
|
+
children: t("form.browser.waiting")
|
|
988
|
+
}),
|
|
989
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
990
|
+
className: SPINNER_CLASS,
|
|
604
991
|
style: {
|
|
605
|
-
|
|
606
|
-
|
|
992
|
+
width: 28,
|
|
993
|
+
height: 28
|
|
607
994
|
},
|
|
608
|
-
|
|
995
|
+
"aria-hidden": true
|
|
609
996
|
}),
|
|
610
|
-
|
|
611
|
-
|
|
997
|
+
secondsLeft !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
998
|
+
style: {
|
|
999
|
+
fontSize: 13,
|
|
1000
|
+
fontVariantNumeric: "tabular-nums",
|
|
1001
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1002
|
+
},
|
|
1003
|
+
children: t("form.browser.countdown", { time: formatCountdown(secondsLeft) })
|
|
1004
|
+
})
|
|
612
1005
|
]
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
})]
|
|
630
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
631
|
-
type: "password",
|
|
632
|
-
value: ak,
|
|
633
|
-
onChange: (e) => setAk(e.target.value),
|
|
634
|
-
style: inputStyle,
|
|
635
|
-
placeholder: t("section.field.accessKey.placeholder"),
|
|
636
|
-
"aria-label": t("section.field.accessKey"),
|
|
637
|
-
autoComplete: "off",
|
|
638
|
-
autoFocus: true
|
|
639
|
-
})]
|
|
640
|
-
}),
|
|
641
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
642
|
-
style: fieldStyle,
|
|
643
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
644
|
-
style: labelStyle,
|
|
645
|
-
children: t("section.field.secretKey")
|
|
646
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
647
|
-
type: "password",
|
|
648
|
-
value: sk,
|
|
649
|
-
onChange: (e) => setSk(e.target.value),
|
|
650
|
-
style: inputStyle,
|
|
651
|
-
placeholder: t("section.field.secretKey.placeholder"),
|
|
652
|
-
"aria-label": t("section.field.secretKey"),
|
|
653
|
-
autoComplete: "off"
|
|
654
|
-
})]
|
|
655
|
-
}),
|
|
656
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
657
|
-
style: fieldStyle,
|
|
658
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
659
|
-
style: labelStyle,
|
|
660
|
-
children: t("section.field.token")
|
|
661
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
662
|
-
type: "password",
|
|
663
|
-
value: token,
|
|
664
|
-
onChange: (e) => setToken(e.target.value),
|
|
665
|
-
style: inputStyle,
|
|
666
|
-
placeholder: t("section.field.token.placeholder"),
|
|
667
|
-
"aria-label": t("section.field.token"),
|
|
668
|
-
autoComplete: "off"
|
|
669
|
-
})]
|
|
670
|
-
}),
|
|
671
|
-
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
672
|
-
style: {
|
|
673
|
-
margin: 0,
|
|
674
|
-
fontSize: 12,
|
|
675
|
-
lineHeight: "18px",
|
|
676
|
-
color: "var(--dsw-alias-state-warn-label)"
|
|
677
|
-
},
|
|
678
|
-
children: error
|
|
679
|
-
}),
|
|
680
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
681
|
-
style: {
|
|
682
|
-
display: "flex",
|
|
683
|
-
gap: 8
|
|
684
|
-
},
|
|
685
|
-
children: [
|
|
686
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
687
|
-
type: "submit",
|
|
688
|
-
disabled,
|
|
689
|
-
style: {
|
|
690
|
-
...buttonStyle(disabled),
|
|
691
|
-
background: "var(--dsw-alias-button-primary-fill)",
|
|
692
|
-
color: "var(--dsw-alias-label-primary-foreground)"
|
|
693
|
-
},
|
|
694
|
-
children: saving ? t("section.credentials.saving") : t("form.submit")
|
|
695
|
-
}),
|
|
696
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1006
|
+
}),
|
|
1007
|
+
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1008
|
+
style: {
|
|
1009
|
+
margin: 0,
|
|
1010
|
+
fontSize: 12,
|
|
1011
|
+
lineHeight: "18px",
|
|
1012
|
+
color: "var(--dsw-alias-state-warn-label)"
|
|
1013
|
+
},
|
|
1014
|
+
children: error
|
|
1015
|
+
}),
|
|
1016
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1017
|
+
style: {
|
|
1018
|
+
display: "flex",
|
|
1019
|
+
gap: 8
|
|
1020
|
+
},
|
|
1021
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
697
1022
|
type: "button",
|
|
698
|
-
onClick:
|
|
699
|
-
disabled: busy,
|
|
1023
|
+
onClick: onCancelWaiting,
|
|
700
1024
|
style: {
|
|
701
|
-
...buttonStyle(
|
|
1025
|
+
...buttonStyle(false),
|
|
702
1026
|
background: "transparent",
|
|
703
1027
|
color: "var(--dsw-alias-label-primary)",
|
|
704
1028
|
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
705
1029
|
},
|
|
706
1030
|
children: t("form.dismiss")
|
|
707
|
-
}),
|
|
708
|
-
hasCredentials && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1031
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
709
1032
|
type: "button",
|
|
710
|
-
onClick:
|
|
711
|
-
onClear();
|
|
712
|
-
},
|
|
713
|
-
disabled: busy,
|
|
1033
|
+
onClick: onReopen,
|
|
714
1034
|
style: {
|
|
715
|
-
...buttonStyle(
|
|
1035
|
+
...buttonStyle(false),
|
|
716
1036
|
background: "transparent",
|
|
717
1037
|
color: "var(--dsw-alias-label-primary)",
|
|
718
1038
|
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
719
1039
|
marginLeft: "auto"
|
|
720
1040
|
},
|
|
721
|
-
children:
|
|
722
|
-
})
|
|
723
|
-
|
|
724
|
-
})
|
|
1041
|
+
children: t("form.browser.reopen")
|
|
1042
|
+
})]
|
|
1043
|
+
})
|
|
1044
|
+
] }),
|
|
1045
|
+
page === "manual" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1046
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1047
|
+
style: {
|
|
1048
|
+
display: "flex",
|
|
1049
|
+
flexDirection: "column",
|
|
1050
|
+
gap: 4
|
|
1051
|
+
},
|
|
1052
|
+
children: [
|
|
1053
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1054
|
+
style: {
|
|
1055
|
+
fontSize: 14,
|
|
1056
|
+
fontWeight: 500,
|
|
1057
|
+
lineHeight: "22px"
|
|
1058
|
+
},
|
|
1059
|
+
children: t("form.title.manual")
|
|
1060
|
+
}),
|
|
1061
|
+
prefilled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1062
|
+
role: "note",
|
|
1063
|
+
style: {
|
|
1064
|
+
fontSize: 12,
|
|
1065
|
+
lineHeight: "18px",
|
|
1066
|
+
color: "var(--dsw-alias-state-warn-label)"
|
|
1067
|
+
},
|
|
1068
|
+
children: t("form.prefilledFromEnv")
|
|
1069
|
+
}),
|
|
1070
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1071
|
+
style: {
|
|
1072
|
+
fontSize: 12,
|
|
1073
|
+
lineHeight: "18px",
|
|
1074
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1075
|
+
},
|
|
1076
|
+
children: [
|
|
1077
|
+
t("section.credentials.hint.prefix"),
|
|
1078
|
+
" ",
|
|
1079
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1080
|
+
href: CREDENTIAL_URL,
|
|
1081
|
+
target: "_blank",
|
|
1082
|
+
rel: "noreferrer noopener",
|
|
1083
|
+
style: {
|
|
1084
|
+
color: "var(--dsw-alias-button-primary-fill)",
|
|
1085
|
+
textDecoration: "underline"
|
|
1086
|
+
},
|
|
1087
|
+
children: t("section.credentials.hint.link")
|
|
1088
|
+
}),
|
|
1089
|
+
" ",
|
|
1090
|
+
t("section.credentials.hint.suffix")
|
|
1091
|
+
]
|
|
1092
|
+
})
|
|
1093
|
+
]
|
|
1094
|
+
}),
|
|
1095
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1096
|
+
style: fieldStyle,
|
|
1097
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1098
|
+
style: labelStyle,
|
|
1099
|
+
children: [t("section.field.accessKey"), status.accessKeyIdHint && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1100
|
+
style: {
|
|
1101
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
1102
|
+
fontWeight: 400
|
|
1103
|
+
},
|
|
1104
|
+
children: [
|
|
1105
|
+
"(",
|
|
1106
|
+
status.accessKeyIdHint,
|
|
1107
|
+
")"
|
|
1108
|
+
]
|
|
1109
|
+
})]
|
|
1110
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1111
|
+
type: "password",
|
|
1112
|
+
value: ak,
|
|
1113
|
+
onChange: (e) => {
|
|
1114
|
+
interacted.current = true;
|
|
1115
|
+
setAk(e.target.value);
|
|
1116
|
+
},
|
|
1117
|
+
style: inputStyle,
|
|
1118
|
+
placeholder: t("section.field.accessKey.placeholder"),
|
|
1119
|
+
"aria-label": t("section.field.accessKey"),
|
|
1120
|
+
autoComplete: "off",
|
|
1121
|
+
autoFocus: true
|
|
1122
|
+
})]
|
|
1123
|
+
}),
|
|
1124
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1125
|
+
style: fieldStyle,
|
|
1126
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1127
|
+
style: labelStyle,
|
|
1128
|
+
children: t("section.field.secretKey")
|
|
1129
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1130
|
+
type: "password",
|
|
1131
|
+
value: sk,
|
|
1132
|
+
onChange: (e) => {
|
|
1133
|
+
interacted.current = true;
|
|
1134
|
+
setSk(e.target.value);
|
|
1135
|
+
},
|
|
1136
|
+
style: inputStyle,
|
|
1137
|
+
placeholder: t("section.field.secretKey.placeholder"),
|
|
1138
|
+
"aria-label": t("section.field.secretKey"),
|
|
1139
|
+
autoComplete: "off"
|
|
1140
|
+
})]
|
|
1141
|
+
}),
|
|
1142
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1143
|
+
style: fieldStyle,
|
|
1144
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1145
|
+
style: labelStyle,
|
|
1146
|
+
children: t("section.field.token")
|
|
1147
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1148
|
+
type: "password",
|
|
1149
|
+
value: token,
|
|
1150
|
+
onChange: (e) => {
|
|
1151
|
+
interacted.current = true;
|
|
1152
|
+
setToken(e.target.value);
|
|
1153
|
+
},
|
|
1154
|
+
style: inputStyle,
|
|
1155
|
+
placeholder: t("section.field.token.placeholder"),
|
|
1156
|
+
"aria-label": t("section.field.token"),
|
|
1157
|
+
autoComplete: "off"
|
|
1158
|
+
})]
|
|
1159
|
+
}),
|
|
1160
|
+
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1161
|
+
style: {
|
|
1162
|
+
margin: 0,
|
|
1163
|
+
fontSize: 12,
|
|
1164
|
+
lineHeight: "18px",
|
|
1165
|
+
color: "var(--dsw-alias-state-warn-label)"
|
|
1166
|
+
},
|
|
1167
|
+
children: error
|
|
1168
|
+
}),
|
|
1169
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1170
|
+
style: {
|
|
1171
|
+
display: "flex",
|
|
1172
|
+
gap: 8
|
|
1173
|
+
},
|
|
1174
|
+
children: [
|
|
1175
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1176
|
+
type: "submit",
|
|
1177
|
+
disabled,
|
|
1178
|
+
style: {
|
|
1179
|
+
...buttonStyle(disabled),
|
|
1180
|
+
background: "var(--dsw-alias-button-primary-fill)",
|
|
1181
|
+
color: "var(--dsw-alias-label-primary-foreground)"
|
|
1182
|
+
},
|
|
1183
|
+
children: saving ? t("section.credentials.saving") : t("form.submit")
|
|
1184
|
+
}),
|
|
1185
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1186
|
+
type: "button",
|
|
1187
|
+
onClick: onCancel,
|
|
1188
|
+
disabled: busy,
|
|
1189
|
+
style: {
|
|
1190
|
+
...buttonStyle(busy),
|
|
1191
|
+
background: "transparent",
|
|
1192
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1193
|
+
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1194
|
+
},
|
|
1195
|
+
children: t("form.dismiss")
|
|
1196
|
+
}),
|
|
1197
|
+
browserLogin !== null && browserLogin !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1198
|
+
type: "button",
|
|
1199
|
+
onClick: () => {
|
|
1200
|
+
setPage("choose");
|
|
1201
|
+
setError(void 0);
|
|
1202
|
+
},
|
|
1203
|
+
disabled: busy,
|
|
1204
|
+
style: {
|
|
1205
|
+
...buttonStyle(busy),
|
|
1206
|
+
background: "transparent",
|
|
1207
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1208
|
+
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
1209
|
+
},
|
|
1210
|
+
children: t("form.back")
|
|
1211
|
+
}),
|
|
1212
|
+
hasCredentials && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1213
|
+
type: "button",
|
|
1214
|
+
onClick: () => {
|
|
1215
|
+
onClear();
|
|
1216
|
+
},
|
|
1217
|
+
disabled: busy,
|
|
1218
|
+
style: {
|
|
1219
|
+
...buttonStyle(busy),
|
|
1220
|
+
background: "transparent",
|
|
1221
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1222
|
+
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
1223
|
+
marginLeft: "auto"
|
|
1224
|
+
},
|
|
1225
|
+
children: clearing ? t("form.clearing") : t("form.clear")
|
|
1226
|
+
})
|
|
1227
|
+
]
|
|
1228
|
+
})
|
|
1229
|
+
] })
|
|
725
1230
|
]
|
|
726
1231
|
})
|
|
727
1232
|
});
|
|
728
1233
|
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Render a countdown as `m:ss`.
|
|
1236
|
+
*
|
|
1237
|
+
* Language-neutral on purpose: the surrounding sentence is localised, and a
|
|
1238
|
+
* number plus a unit needs no translation to read — whereas spelling out
|
|
1239
|
+
* "minutes"/"分" would put a second copy of the same unit in both dictionaries
|
|
1240
|
+
* for no gain. Tabular figures are applied at the call site so the digits do
|
|
1241
|
+
* not jitter as they change.
|
|
1242
|
+
*
|
|
1243
|
+
* @param seconds - seconds remaining.
|
|
1244
|
+
*/
|
|
1245
|
+
function formatCountdown(seconds) {
|
|
1246
|
+
const whole = Math.max(0, Math.floor(seconds));
|
|
1247
|
+
const minutes = Math.floor(whole / 60);
|
|
1248
|
+
const rest = whole % 60;
|
|
1249
|
+
return `${String(minutes)}:${String(rest).padStart(2, "0")}`;
|
|
1250
|
+
}
|
|
729
1251
|
|
|
730
1252
|
//#endregion
|
|
731
1253
|
//#region src/client/CredentialFormInteraction.ts
|
|
@@ -844,8 +1366,8 @@ const zh = {
|
|
|
844
1366
|
"section.credentials.hint.link": "API Explorer",
|
|
845
1367
|
"section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
|
|
846
1368
|
"section.credentials.saving": "保存中…",
|
|
847
|
-
"form.title": "需要华为云凭据",
|
|
848
1369
|
"form.title.manual": "配置华为云凭据",
|
|
1370
|
+
"form.prefilledFromEnv": "检测到环境变量,已填入表单",
|
|
849
1371
|
"form.submit": "提交",
|
|
850
1372
|
"form.dismiss": "取消",
|
|
851
1373
|
"form.failed": "保存凭据失败",
|
|
@@ -853,6 +1375,16 @@ const zh = {
|
|
|
853
1375
|
"form.clearing": "清除中…",
|
|
854
1376
|
"form.clear.failed": "清除凭据失败",
|
|
855
1377
|
"error.unreachable": "无法连接宿主凭据服务:",
|
|
1378
|
+
"form.intro": "需要进行华为云 IAM 认证",
|
|
1379
|
+
"form.browser.action": "浏览器登录",
|
|
1380
|
+
"form.browser.aksk": "我有AK/SK",
|
|
1381
|
+
"form.browser.decline": "暂不认证",
|
|
1382
|
+
"form.browser.waiting": "正在等待浏览器完成登录…",
|
|
1383
|
+
"form.browser.countdown": "剩余 {time}",
|
|
1384
|
+
"form.browser.reopen": "重新打开",
|
|
1385
|
+
"form.back": "返回",
|
|
1386
|
+
"form.browser.blocked": "浏览器拦截了新标签页,请允许弹出窗口后重试。",
|
|
1387
|
+
"form.browser.failed": "浏览器登录未完成:",
|
|
856
1388
|
"section.field.accessKey": "Access Key",
|
|
857
1389
|
"section.field.accessKey.placeholder": "华为云 Access Key",
|
|
858
1390
|
"section.field.accessKey.hint": "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。",
|
|
@@ -878,8 +1410,8 @@ const en = {
|
|
|
878
1410
|
"section.credentials.hint.link": "API Explorer",
|
|
879
1411
|
"section.credentials.hint.suffix": "and avoid permanent ones.",
|
|
880
1412
|
"section.credentials.saving": "Saving…",
|
|
881
|
-
"form.title": "Huawei Cloud credentials required",
|
|
882
1413
|
"form.title.manual": "Configure Huawei Cloud credentials",
|
|
1414
|
+
"form.prefilledFromEnv": "Detected environment variables — filled in from them",
|
|
883
1415
|
"form.submit": "Submit",
|
|
884
1416
|
"form.dismiss": "Cancel",
|
|
885
1417
|
"form.failed": "Could not save credentials",
|
|
@@ -887,6 +1419,16 @@ const en = {
|
|
|
887
1419
|
"form.clearing": "Clearing…",
|
|
888
1420
|
"form.clear.failed": "Could not clear credentials",
|
|
889
1421
|
"error.unreachable": "Could not reach the host credential service: ",
|
|
1422
|
+
"form.intro": "Huawei Cloud IAM authentication is required",
|
|
1423
|
+
"form.browser.action": "Sign in with a browser",
|
|
1424
|
+
"form.browser.aksk": "I have one",
|
|
1425
|
+
"form.browser.decline": "Not now",
|
|
1426
|
+
"form.browser.waiting": "Waiting for the browser sign-in to finish…",
|
|
1427
|
+
"form.browser.countdown": "{time} left",
|
|
1428
|
+
"form.browser.reopen": "Reopen",
|
|
1429
|
+
"form.back": "Back",
|
|
1430
|
+
"form.browser.blocked": "The browser blocked the new tab. Allow pop-ups for this page, then try again.",
|
|
1431
|
+
"form.browser.failed": "The browser sign-in did not complete: ",
|
|
890
1432
|
"section.field.accessKey": "Access Key",
|
|
891
1433
|
"section.field.accessKey.placeholder": "Huawei Access Key",
|
|
892
1434
|
"section.field.accessKey.hint": "Access Key and Secret Key are stored as a pair; one without the other is not saved.",
|
|
@@ -913,6 +1455,8 @@ const CREDENTIALS_ROUTE = "api/aishell/credentials";
|
|
|
913
1455
|
const CLEAR_ROUTE = "api/aishell/credentials/clear";
|
|
914
1456
|
/** Cancel route; names the request token the person declined. */
|
|
915
1457
|
const CANCEL_ROUTE = "api/aishell/credentials/cancel";
|
|
1458
|
+
/** Prefill route; returns the values the host's environment already holds. */
|
|
1459
|
+
const PREFILL_ROUTE = "api/aishell/credentials/prefill";
|
|
916
1460
|
/**
|
|
917
1461
|
* POST one JSON body to a Host credential route and read back its verdict.
|
|
918
1462
|
* A non-JSON or unreadable body is reported as a transport failure rather than
|
|
@@ -969,6 +1513,29 @@ function saveCredential(t, accessKeyId, secretAccessKey, securityToken, requestT
|
|
|
969
1513
|
async function clearBothStores(t) {
|
|
970
1514
|
return postJson(CLEAR_ROUTE, t);
|
|
971
1515
|
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Read the credential prefills the host has in its environment.
|
|
1518
|
+
*
|
|
1519
|
+
* Failure is not an event: a host with nothing in its environment answers an
|
|
1520
|
+
* empty object, and a route that cannot be reached answers `{}` too, because a
|
|
1521
|
+
* form that starts empty is exactly the behaviour before this existed.
|
|
1522
|
+
*
|
|
1523
|
+
* @returns the prefills, or an empty object.
|
|
1524
|
+
*/
|
|
1525
|
+
async function readPrefill() {
|
|
1526
|
+
try {
|
|
1527
|
+
const response = await fetch(PREFILL_ROUTE, { headers: { accept: "application/json" } });
|
|
1528
|
+
if (!response.ok) return {};
|
|
1529
|
+
const body = await response.json();
|
|
1530
|
+
return typeof body.accessKeyId === "string" && body.accessKeyId !== "" && typeof body.secretAccessKey === "string" && body.secretAccessKey !== "" ? {
|
|
1531
|
+
accessKeyId: body.accessKeyId,
|
|
1532
|
+
secretAccessKey: body.secretAccessKey,
|
|
1533
|
+
...typeof body.securityToken === "string" && body.securityToken !== "" ? { securityToken: body.securityToken } : {}
|
|
1534
|
+
} : {};
|
|
1535
|
+
} catch {
|
|
1536
|
+
return {};
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
972
1539
|
/** Required services. */
|
|
973
1540
|
const inject = [
|
|
974
1541
|
"slots",
|
|
@@ -983,6 +1550,7 @@ function apply(ctx) {
|
|
|
983
1550
|
}), "aishell-credentials: dictionaries");
|
|
984
1551
|
const t = ctx.locale.bind(NS);
|
|
985
1552
|
installChipStyles(ctx);
|
|
1553
|
+
installSpinnerStyles(ctx);
|
|
986
1554
|
const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
|
|
987
1555
|
const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
988
1556
|
hasAccessKey: false,
|
|
@@ -1004,6 +1572,10 @@ function apply(ctx) {
|
|
|
1004
1572
|
};
|
|
1005
1573
|
ctx.effect(() => form.subscribe(derive), "aishell-credentials: credential presence");
|
|
1006
1574
|
derive();
|
|
1575
|
+
const loginOutcome = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)(form.getSnapshot().value?.loginOutcome ?? "");
|
|
1576
|
+
ctx.effect(() => form.subscribe(() => {
|
|
1577
|
+
loginOutcome.set(form.getSnapshot().value?.loginOutcome ?? "");
|
|
1578
|
+
}), "aishell-credentials: login outcome");
|
|
1007
1579
|
const publishCredentialForm = ctx.uiSession.registerPendingInteraction(() => 0);
|
|
1008
1580
|
const visibility = createCredentialFormVisibility((interaction) => publishCredentialForm(interaction, () => Promise.resolve()));
|
|
1009
1581
|
/** The last request the browser acted on, so a re-read is not a re-open. */
|
|
@@ -1078,8 +1650,13 @@ function apply(ctx) {
|
|
|
1078
1650
|
select: ({ pendingInteraction }) => isCredentialForm(pendingInteraction) ? pendingInteraction : null,
|
|
1079
1651
|
locale: NS,
|
|
1080
1652
|
inject: () => ({
|
|
1081
|
-
hooks: {
|
|
1653
|
+
hooks: {
|
|
1654
|
+
credentials: status,
|
|
1655
|
+
loginOutcome
|
|
1656
|
+
},
|
|
1082
1657
|
save: (ak, sk, token) => saveCredential(t, ak, sk, token, pendingRequestToken),
|
|
1658
|
+
readPrefill: () => readPrefill(),
|
|
1659
|
+
startBrowserLogin: () => startBrowserLogin(),
|
|
1083
1660
|
clear: () => clearBothStores(t),
|
|
1084
1661
|
close: () => {
|
|
1085
1662
|
visibility.close();
|