@huaweidevtools/aishell-dsh-client-credentials 0.0.10 → 0.0.12
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 +261 -72
- package/lib/index.js +38 -0
- package/lib/types/client/form-motion.d.ts +70 -0
- package/lib/types/client/locales.d.ts +7 -9
- 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);
|
|
@@ -711,7 +711,7 @@ function browserButton(phase, hasCountdown) {
|
|
|
711
711
|
disabled: phase !== "ready"
|
|
712
712
|
};
|
|
713
713
|
case "unsupported": return {
|
|
714
|
-
label: "form.browser.
|
|
714
|
+
label: "form.browser.action",
|
|
715
715
|
disabled: true
|
|
716
716
|
};
|
|
717
717
|
case "running": return {
|
|
@@ -741,6 +741,156 @@ function formatCountdown(seconds) {
|
|
|
741
741
|
return `${String(minutes)}:${String(rest).padStart(2, "0")}`;
|
|
742
742
|
}
|
|
743
743
|
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/client/form-motion.ts
|
|
746
|
+
/** Plugin id stamped on the tag, so the loader can sweep it on teardown. */
|
|
747
|
+
const PLUGIN_ID = "@huaweidevtools/aishell-dsh-client-credentials";
|
|
748
|
+
/** Dedupe key, as `shared/tsdown.client.ts` spells it for generated modules. */
|
|
749
|
+
const STYLE_KEY = "form-motion.css";
|
|
750
|
+
/** Class on the box the dot ring and the centre label share. */
|
|
751
|
+
const DIAL_CLASS = "aishell-cred-dial";
|
|
752
|
+
/** Class on the rotating ring itself. */
|
|
753
|
+
const DIAL_RING_CLASS = "aishell-cred-dial-ring";
|
|
754
|
+
/** Class on one dot. Carries `--i`, its position around the ring. */
|
|
755
|
+
const DIAL_DOT_CLASS = "aishell-cred-dial-dot";
|
|
756
|
+
/** Class on the label in the middle of the ring. */
|
|
757
|
+
const DIAL_LABEL_CLASS = "aishell-cred-dial-label";
|
|
758
|
+
/**
|
|
759
|
+
* How many dots the ring is drawn from.
|
|
760
|
+
*
|
|
761
|
+
* Twelve gives one dot every 30°, which reads as a continuous arc at this size.
|
|
762
|
+
* The component maps over this, so the ring and the CSS cannot disagree about
|
|
763
|
+
* its length.
|
|
764
|
+
*/
|
|
765
|
+
const DIAL_DOT_COUNT = 12;
|
|
766
|
+
/** Class on the progress line that drains the login window. */
|
|
767
|
+
const PROGRESS_CLASS = "aishell-cred-progress";
|
|
768
|
+
/** Class on the track the progress line sits in. */
|
|
769
|
+
const PROGRESS_TRACK_CLASS = "aishell-cred-progress-track";
|
|
770
|
+
/**
|
|
771
|
+
* The rules.
|
|
772
|
+
*
|
|
773
|
+
* Colours come from the theme's alias tokens wherever one exists, so the card
|
|
774
|
+
* follows light and dark the way every other surface does.
|
|
775
|
+
*/
|
|
776
|
+
const CSS = `
|
|
777
|
+
.${DIAL_CLASS} {
|
|
778
|
+
position: relative;
|
|
779
|
+
width: 104px;
|
|
780
|
+
height: 104px;
|
|
781
|
+
/* Centred in its column: the dial is the card's focal point while a login
|
|
782
|
+
runs, and the countdown beneath it lines up with the dial's own centre. */
|
|
783
|
+
margin: 0 auto;
|
|
784
|
+
display: grid;
|
|
785
|
+
place-items: center;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/* The ring is a fixed square centred inside the dial. \`inset: 0\` with
|
|
789
|
+
\`margin: auto\` is what centres it without touching \`transform\` — the
|
|
790
|
+
rotation owns that property, and a translate-based centring would be
|
|
791
|
+
overwritten by every frame of the animation. */
|
|
792
|
+
.${DIAL_RING_CLASS} {
|
|
793
|
+
position: absolute;
|
|
794
|
+
inset: 0;
|
|
795
|
+
margin: auto;
|
|
796
|
+
width: 78px;
|
|
797
|
+
height: 78px;
|
|
798
|
+
animation: aishell-cred-spin 1.8s linear infinite;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/* One dot. The box is the whole ring square and is rotated into place; the dot
|
|
802
|
+
itself is drawn by \`::before\` pinned to the box's top edge. Generating the
|
|
803
|
+
geometry in CSS from \`--i\` keeps twelve rules from having to be written out
|
|
804
|
+
and kept in step with the dot count. */
|
|
805
|
+
.${DIAL_DOT_CLASS} {
|
|
806
|
+
position: absolute;
|
|
807
|
+
inset: 0;
|
|
808
|
+
transform: rotate(calc(var(--i) * 30deg));
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
.${DIAL_DOT_CLASS}::before {
|
|
812
|
+
content: '';
|
|
813
|
+
position: absolute;
|
|
814
|
+
left: 50%;
|
|
815
|
+
top: 0;
|
|
816
|
+
/* 0 at the tail, 1 at the head: the ramp drives both the size and the
|
|
817
|
+
opacity, which is what makes the ring read as one sweeping arc. */
|
|
818
|
+
--t: calc(var(--i) / ${String(DIAL_DOT_COUNT - 1)});
|
|
819
|
+
width: calc(3px + var(--t) * 6px);
|
|
820
|
+
height: calc(3px + var(--t) * 6px);
|
|
821
|
+
border-radius: 50%;
|
|
822
|
+
background: var(--dsw-alias-button-primary-fill);
|
|
823
|
+
opacity: calc(0.15 + var(--t) * 0.85);
|
|
824
|
+
/* Half-translate so the dot is centred on the circle rather than hanging
|
|
825
|
+
inside it — and so a size change does not shift the dot's own centre. */
|
|
826
|
+
transform: translate(-50%, -50%);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
.${DIAL_LABEL_CLASS} {
|
|
830
|
+
position: relative;
|
|
831
|
+
font-size: 12px;
|
|
832
|
+
font-weight: 500;
|
|
833
|
+
line-height: 16px;
|
|
834
|
+
color: var(--dsw-alias-label-secondary);
|
|
835
|
+
text-align: center;
|
|
836
|
+
/* The longest label is two CJK glyphs; a little padding keeps the text off
|
|
837
|
+
the ring's inner edge without shrinking the ring. */
|
|
838
|
+
max-width: 62px;
|
|
839
|
+
text-wrap: balance;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
@keyframes aishell-cred-spin {
|
|
843
|
+
to { transform: rotate(360deg); }
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/* The track the draining line sits in. Narrower than the card so it reads as
|
|
847
|
+
part of the dial group above it rather than as a full-width rule. */
|
|
848
|
+
.${PROGRESS_TRACK_CLASS} {
|
|
849
|
+
display: block;
|
|
850
|
+
width: 168px;
|
|
851
|
+
height: 2px;
|
|
852
|
+
border-radius: 1px;
|
|
853
|
+
margin: 0 auto;
|
|
854
|
+
background: var(--dsw-alias-border-l4);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/* Width is set inline from the countdown — a CSS animation would drift out of
|
|
858
|
+
step with the wall-clock deadline the text shows, and the two disagreeing is
|
|
859
|
+
worse than no line at all. */
|
|
860
|
+
.${PROGRESS_CLASS} {
|
|
861
|
+
display: block;
|
|
862
|
+
height: 2px;
|
|
863
|
+
border-radius: 1px;
|
|
864
|
+
background: var(--dsw-alias-button-primary-fill);
|
|
865
|
+
transition: width 1s linear;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/* Decorative motion only. Both animations carry information that is already in
|
|
869
|
+
the text beside them, so removing them loses nothing. */
|
|
870
|
+
@media (prefers-reduced-motion: reduce) {
|
|
871
|
+
.${DIAL_RING_CLASS} { animation: none; }
|
|
872
|
+
.${PROGRESS_CLASS} { transition: none; }
|
|
873
|
+
}
|
|
874
|
+
`;
|
|
875
|
+
/**
|
|
876
|
+
* Install the stylesheet, once per plugin fiber.
|
|
877
|
+
*
|
|
878
|
+
* @param ctx - client context, for the effect that owns the tag.
|
|
879
|
+
*/
|
|
880
|
+
function installFormMotionStyles(ctx) {
|
|
881
|
+
if (typeof document === "undefined") return;
|
|
882
|
+
ctx.effect(() => {
|
|
883
|
+
const tag = document.createElement("style");
|
|
884
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
885
|
+
tag.dataset.pluginCss = STYLE_KEY;
|
|
886
|
+
tag.textContent = CSS;
|
|
887
|
+
document.head.appendChild(tag);
|
|
888
|
+
return () => {
|
|
889
|
+
tag.remove();
|
|
890
|
+
};
|
|
891
|
+
}, "aishell-credentials: form motion styles");
|
|
892
|
+
}
|
|
893
|
+
|
|
744
894
|
//#endregion
|
|
745
895
|
//#region src/client/CredentialRequestForm.tsx
|
|
746
896
|
/**
|
|
@@ -751,7 +901,7 @@ function formatCountdown(seconds) {
|
|
|
751
901
|
*/
|
|
752
902
|
function CredentialRequestForm(props) {
|
|
753
903
|
const t = props.t;
|
|
754
|
-
const { save, clear, close, cancel } = props;
|
|
904
|
+
const { save, clear, close, cancel, confirm } = props;
|
|
755
905
|
const status = props.useCredentials((snapshot) => snapshot);
|
|
756
906
|
const [ak, setAk] = (0, react.useState)("");
|
|
757
907
|
const [sk, setSk] = (0, react.useState)("");
|
|
@@ -767,6 +917,13 @@ function CredentialRequestForm(props) {
|
|
|
767
917
|
const [phase, setPhase] = (0, react.useState)("checking");
|
|
768
918
|
const [secondsLeft, setSecondsLeft] = (0, react.useState)(void 0);
|
|
769
919
|
/**
|
|
920
|
+
* The window this login started with, held so the progress line can compute
|
|
921
|
+
* its fraction. `secondsLeft` alone cannot: a fraction needs the denominator,
|
|
922
|
+
* and reading it back off the handle would give a value that changes when a
|
|
923
|
+
* later login replaces it — while an earlier one's line is still on screen.
|
|
924
|
+
*/
|
|
925
|
+
const [loginWindowSeconds, setLoginWindowSeconds] = (0, react.useState)(void 0);
|
|
926
|
+
/**
|
|
770
927
|
* Whether a credential is stored, read live rather than captured.
|
|
771
928
|
*
|
|
772
929
|
* Live because the card changes state under the person's hands: a successful
|
|
@@ -838,7 +995,10 @@ function CredentialRequestForm(props) {
|
|
|
838
995
|
};
|
|
839
996
|
}, [phase]);
|
|
840
997
|
(0, react.useEffect)(() => {
|
|
841
|
-
if (phase !== "running")
|
|
998
|
+
if (phase !== "running") {
|
|
999
|
+
setSecondsLeft(void 0);
|
|
1000
|
+
setLoginWindowSeconds(void 0);
|
|
1001
|
+
}
|
|
842
1002
|
}, [phase]);
|
|
843
1003
|
const outcomeRaw = props.useLoginOutcome((snapshot) => snapshot);
|
|
844
1004
|
/**
|
|
@@ -897,7 +1057,9 @@ function CredentialRequestForm(props) {
|
|
|
897
1057
|
tab.navigate(handle.loginUrl);
|
|
898
1058
|
setLogin(handle);
|
|
899
1059
|
setPhase("running");
|
|
900
|
-
|
|
1060
|
+
const window$1 = handle.expiresInSeconds > 0 ? handle.expiresInSeconds : void 0;
|
|
1061
|
+
setSecondsLeft(window$1);
|
|
1062
|
+
setLoginWindowSeconds(window$1);
|
|
901
1063
|
};
|
|
902
1064
|
/**
|
|
903
1065
|
* Abandon the login in flight.
|
|
@@ -913,20 +1075,6 @@ function CredentialRequestForm(props) {
|
|
|
913
1075
|
setPhase("ready");
|
|
914
1076
|
setBrowserError(void 0);
|
|
915
1077
|
}, [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
|
-
);
|
|
929
|
-
};
|
|
930
1078
|
const onSubmit = async (event) => {
|
|
931
1079
|
event.preventDefault();
|
|
932
1080
|
setSaving(true);
|
|
@@ -992,6 +1140,7 @@ function CredentialRequestForm(props) {
|
|
|
992
1140
|
cursor: disabled ? "not-allowed" : "text"
|
|
993
1141
|
});
|
|
994
1142
|
const buttonStyle = (disabled, kind = "secondary") => ({
|
|
1143
|
+
flex: 1,
|
|
995
1144
|
height: 34,
|
|
996
1145
|
padding: "0 16px",
|
|
997
1146
|
borderRadius: 8,
|
|
@@ -1093,9 +1242,18 @@ function CredentialRequestForm(props) {
|
|
|
1093
1242
|
children: status.accessKeyIdHint === "" ? t("form.signedIn") : status.accessKeyIdHint
|
|
1094
1243
|
})]
|
|
1095
1244
|
}),
|
|
1096
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1097
|
-
style: {
|
|
1098
|
-
|
|
1245
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1246
|
+
style: {
|
|
1247
|
+
display: "flex",
|
|
1248
|
+
gap: 12
|
|
1249
|
+
},
|
|
1250
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1251
|
+
type: "button",
|
|
1252
|
+
onClick: confirm,
|
|
1253
|
+
disabled: busy,
|
|
1254
|
+
style: buttonStyle(busy, "primary"),
|
|
1255
|
+
children: t("form.confirm")
|
|
1256
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1099
1257
|
type: "button",
|
|
1100
1258
|
onClick: () => {
|
|
1101
1259
|
onClear();
|
|
@@ -1103,7 +1261,7 @@ function CredentialRequestForm(props) {
|
|
|
1103
1261
|
disabled: busy,
|
|
1104
1262
|
style: buttonStyle(busy),
|
|
1105
1263
|
children: clearing ? t("form.clearing") : t("form.logout")
|
|
1106
|
-
})
|
|
1264
|
+
})]
|
|
1107
1265
|
}),
|
|
1108
1266
|
manualError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1109
1267
|
style: notice,
|
|
@@ -1117,7 +1275,42 @@ function CredentialRequestForm(props) {
|
|
|
1117
1275
|
gap: 8
|
|
1118
1276
|
},
|
|
1119
1277
|
children: [
|
|
1120
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1278
|
+
phase === "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1279
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1280
|
+
className: DIAL_CLASS,
|
|
1281
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1282
|
+
className: DIAL_RING_CLASS,
|
|
1283
|
+
"aria-hidden": true,
|
|
1284
|
+
children: Array.from({ length: DIAL_DOT_COUNT }, (_, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1285
|
+
className: DIAL_DOT_CLASS,
|
|
1286
|
+
style: { "--i": i }
|
|
1287
|
+
}, i))
|
|
1288
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1289
|
+
className: DIAL_LABEL_CLASS,
|
|
1290
|
+
children: t("form.browser.runningLabel")
|
|
1291
|
+
})]
|
|
1292
|
+
}),
|
|
1293
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1294
|
+
role: "status",
|
|
1295
|
+
style: {
|
|
1296
|
+
fontSize: 13,
|
|
1297
|
+
lineHeight: "20px",
|
|
1298
|
+
textAlign: "center",
|
|
1299
|
+
fontVariantNumeric: "tabular-nums",
|
|
1300
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1301
|
+
},
|
|
1302
|
+
children: secondsLeft === void 0 ? "" : formatCountdown(secondsLeft)
|
|
1303
|
+
}),
|
|
1304
|
+
secondsLeft !== void 0 && loginWindowSeconds !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1305
|
+
className: PROGRESS_TRACK_CLASS,
|
|
1306
|
+
"aria-hidden": true,
|
|
1307
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1308
|
+
className: PROGRESS_CLASS,
|
|
1309
|
+
style: { width: `${String(Math.round(secondsLeft / loginWindowSeconds * 100))}%` }
|
|
1310
|
+
})
|
|
1311
|
+
})
|
|
1312
|
+
] }),
|
|
1313
|
+
phase !== "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1121
1314
|
style: {
|
|
1122
1315
|
fontSize: 13,
|
|
1123
1316
|
fontWeight: 500,
|
|
@@ -1125,15 +1318,6 @@ function CredentialRequestForm(props) {
|
|
|
1125
1318
|
},
|
|
1126
1319
|
children: t("form.browser.section")
|
|
1127
1320
|
}),
|
|
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
1321
|
phase === "checking" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1138
1322
|
style: {
|
|
1139
1323
|
fontSize: 12,
|
|
@@ -1151,20 +1335,17 @@ function CredentialRequestForm(props) {
|
|
|
1151
1335
|
style: {
|
|
1152
1336
|
display: "flex",
|
|
1153
1337
|
alignItems: "center",
|
|
1154
|
-
gap:
|
|
1338
|
+
gap: 12
|
|
1155
1339
|
},
|
|
1156
1340
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1157
1341
|
type: "button",
|
|
1158
1342
|
onClick: phase === "running" ? onCancelLogin : onBrowserLogin,
|
|
1159
1343
|
disabled: button.disabled,
|
|
1160
|
-
style:
|
|
1161
|
-
...buttonStyle(button.disabled, button.disabled ? "secondary" : "primary"),
|
|
1162
|
-
flex: 1
|
|
1163
|
-
},
|
|
1344
|
+
style: buttonStyle(button.disabled, button.disabled ? "secondary" : "primary"),
|
|
1164
1345
|
children: t(button.label)
|
|
1165
1346
|
})
|
|
1166
1347
|
}),
|
|
1167
|
-
phase === "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1348
|
+
phase === "running" && login !== null && login !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1168
1349
|
style: {
|
|
1169
1350
|
fontSize: 12,
|
|
1170
1351
|
lineHeight: "18px",
|
|
@@ -1172,21 +1353,17 @@ function CredentialRequestForm(props) {
|
|
|
1172
1353
|
},
|
|
1173
1354
|
children: [
|
|
1174
1355
|
t("form.browser.notOpened"),
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1356
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1357
|
+
href: login.loginUrl,
|
|
1358
|
+
target: "_blank",
|
|
1359
|
+
rel: "noopener noreferrer",
|
|
1179
1360
|
style: {
|
|
1180
|
-
border: "none",
|
|
1181
|
-
background: "none",
|
|
1182
|
-
padding: 0,
|
|
1183
|
-
font: "inherit",
|
|
1184
1361
|
color: "var(--dsw-alias-button-primary-fill)",
|
|
1185
|
-
textDecoration: "underline"
|
|
1186
|
-
cursor: "pointer"
|
|
1362
|
+
textDecoration: "underline"
|
|
1187
1363
|
},
|
|
1188
|
-
children: t("form.browser.
|
|
1189
|
-
})
|
|
1364
|
+
children: t("form.browser.openHere")
|
|
1365
|
+
}),
|
|
1366
|
+
t("form.browser.openHereSuffix")
|
|
1190
1367
|
]
|
|
1191
1368
|
}),
|
|
1192
1369
|
browserError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -1294,7 +1471,7 @@ function CredentialRequestForm(props) {
|
|
|
1294
1471
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1295
1472
|
style: {
|
|
1296
1473
|
display: "flex",
|
|
1297
|
-
gap:
|
|
1474
|
+
gap: 12
|
|
1298
1475
|
},
|
|
1299
1476
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1300
1477
|
type: "submit",
|
|
@@ -1429,25 +1606,25 @@ const zh = {
|
|
|
1429
1606
|
"mode.unavailable.hint": "无法读取权限模式;切换按钮暂不可用",
|
|
1430
1607
|
"mode.switchToReadonly": "切换为只读模式",
|
|
1431
1608
|
"mode.switchToReadwrite": "切换为读写模式",
|
|
1432
|
-
"section.credentials.hint.prefix": "
|
|
1609
|
+
"section.credentials.hint.prefix": "建议从",
|
|
1433
1610
|
"section.credentials.hint.link": "API Explorer",
|
|
1434
1611
|
"section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
|
|
1435
1612
|
"section.credentials.saving": "保存中…",
|
|
1436
1613
|
"form.title": "华为云 IAM 认证",
|
|
1437
1614
|
"form.or": "或者",
|
|
1438
1615
|
"form.signedIn": "已登录",
|
|
1616
|
+
"form.confirm": "确认",
|
|
1439
1617
|
"form.logout": "退出",
|
|
1440
1618
|
"form.browser.section": "选项一:浏览器登录",
|
|
1441
1619
|
"form.browser.action": "登录",
|
|
1442
1620
|
"form.browser.checking": "环境检测中…",
|
|
1443
1621
|
"form.browser.unsupported": "当前环境不支持该方式。",
|
|
1444
|
-
"form.browser.unsupportedLabel": "不支持",
|
|
1445
1622
|
"form.browser.cancelLabel": "取消登录",
|
|
1446
|
-
"form.browser.
|
|
1623
|
+
"form.browser.runningLabel": "登录中",
|
|
1447
1624
|
"form.browser.notOpened": "若浏览器未自动打开,请",
|
|
1448
|
-
"form.browser.
|
|
1625
|
+
"form.browser.openHere": "点击此处",
|
|
1626
|
+
"form.browser.openHereSuffix": "打开。",
|
|
1449
1627
|
"form.browser.blocked": "浏览器拦截了新标签页,请允许弹出窗口后重试。",
|
|
1450
|
-
"form.browser.copyFailed": "无法复制链接,请手动从浏览器地址栏重试。",
|
|
1451
1628
|
"form.browser.failed": "浏览器登录未完成。",
|
|
1452
1629
|
"form.browser.startFailed": "无法启动浏览器登录,请改用 AK/SK 或稍后重试。",
|
|
1453
1630
|
"form.browser.expired": "登录超时,请重试。",
|
|
@@ -1480,25 +1657,25 @@ const en = {
|
|
|
1480
1657
|
"mode.unavailable.hint": "Could not read the permission mode; the toggle is unavailable",
|
|
1481
1658
|
"mode.switchToReadonly": "Switch to read-only mode",
|
|
1482
1659
|
"mode.switchToReadwrite": "Switch to read-write mode",
|
|
1483
|
-
"section.credentials.hint.prefix": "
|
|
1660
|
+
"section.credentials.hint.prefix": "Obtain temporary credentials from",
|
|
1484
1661
|
"section.credentials.hint.link": "API Explorer",
|
|
1485
1662
|
"section.credentials.hint.suffix": "and avoid permanent ones.",
|
|
1486
1663
|
"section.credentials.saving": "Saving…",
|
|
1487
1664
|
"form.title": "Huawei Cloud IAM authentication",
|
|
1488
1665
|
"form.or": "or",
|
|
1489
1666
|
"form.signedIn": "Signed in",
|
|
1667
|
+
"form.confirm": "Confirm",
|
|
1490
1668
|
"form.logout": "Logout",
|
|
1491
1669
|
"form.browser.section": "Option 1: sign in with a browser",
|
|
1492
1670
|
"form.browser.action": "Sign in",
|
|
1493
1671
|
"form.browser.checking": "Checking this environment…",
|
|
1494
|
-
"form.browser.unsupported": "This environment does not support
|
|
1495
|
-
"form.browser.unsupportedLabel": "Unsupported",
|
|
1672
|
+
"form.browser.unsupported": "This environment does not support this method.",
|
|
1496
1673
|
"form.browser.cancelLabel": "Cancel sign-in",
|
|
1497
|
-
"form.browser.
|
|
1498
|
-
"form.browser.notOpened": "If the browser did not open,",
|
|
1499
|
-
"form.browser.
|
|
1674
|
+
"form.browser.runningLabel": "Signing in",
|
|
1675
|
+
"form.browser.notOpened": "If the browser did not open, ",
|
|
1676
|
+
"form.browser.openHere": "click here",
|
|
1677
|
+
"form.browser.openHereSuffix": " to open it.",
|
|
1500
1678
|
"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
1679
|
"form.browser.failed": "The browser sign-in did not complete.",
|
|
1503
1680
|
"form.browser.startFailed": "Could not start the browser sign-in. Use an AK/SK instead, or try again.",
|
|
1504
1681
|
"form.browser.expired": "The sign-in timed out. Try again.",
|
|
@@ -1536,6 +1713,8 @@ const CREDENTIALS_ROUTE = "api/aishell/credentials";
|
|
|
1536
1713
|
const CLEAR_ROUTE = "api/aishell/credentials/clear";
|
|
1537
1714
|
/** Cancel route; names the request token the person declined. */
|
|
1538
1715
|
const CANCEL_ROUTE = "api/aishell/credentials/cancel";
|
|
1716
|
+
/** Confirm route; names the request token the person accepted as already stored. */
|
|
1717
|
+
const CONFIRM_ROUTE = "api/aishell/credentials/confirm";
|
|
1539
1718
|
/** Prefill route; returns the values the host's environment already holds. */
|
|
1540
1719
|
const PREFILL_ROUTE = "api/aishell/credentials/prefill";
|
|
1541
1720
|
/**
|
|
@@ -1631,6 +1810,7 @@ function apply(ctx) {
|
|
|
1631
1810
|
}), "aishell-credentials: dictionaries");
|
|
1632
1811
|
const t = ctx.locale.bind(NS);
|
|
1633
1812
|
installChipStyles(ctx);
|
|
1813
|
+
installFormMotionStyles(ctx);
|
|
1634
1814
|
const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
|
|
1635
1815
|
const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
1636
1816
|
hasAccessKey: false,
|
|
@@ -1697,17 +1877,22 @@ function apply(ctx) {
|
|
|
1697
1877
|
visibility.dispose();
|
|
1698
1878
|
}, "aishell-credentials: credential form teardown");
|
|
1699
1879
|
/**
|
|
1700
|
-
*
|
|
1880
|
+
* Answer the request this form is open for, if any.
|
|
1701
1881
|
*
|
|
1702
1882
|
* Only when this form was opened by a request: a chip-opened form has no
|
|
1703
|
-
* request behind it, and
|
|
1704
|
-
*
|
|
1883
|
+
* request behind it, and answering one would make the *next* `auth` call
|
|
1884
|
+
* believe the person had acted on a question nobody asked.
|
|
1885
|
+
*
|
|
1886
|
+
* The token is spent either way, so a second press cannot answer twice, and a
|
|
1887
|
+
* later request with the same token is not mistaken for this one.
|
|
1888
|
+
*
|
|
1889
|
+
* @param route - the cancel or confirm route to post to.
|
|
1705
1890
|
*/
|
|
1706
|
-
const
|
|
1891
|
+
const answerRequest = (route) => {
|
|
1707
1892
|
const token = pendingRequestToken;
|
|
1708
1893
|
pendingRequestToken = void 0;
|
|
1709
1894
|
if (token === void 0) return;
|
|
1710
|
-
fetch(
|
|
1895
|
+
fetch(route, {
|
|
1711
1896
|
method: "POST",
|
|
1712
1897
|
headers: { "content-type": "application/json" },
|
|
1713
1898
|
body: JSON.stringify({ token })
|
|
@@ -1759,7 +1944,11 @@ function apply(ctx) {
|
|
|
1759
1944
|
visibility.close();
|
|
1760
1945
|
},
|
|
1761
1946
|
cancel: () => {
|
|
1762
|
-
|
|
1947
|
+
answerRequest(CANCEL_ROUTE);
|
|
1948
|
+
visibility.close();
|
|
1949
|
+
},
|
|
1950
|
+
confirm: () => {
|
|
1951
|
+
answerRequest(CONFIRM_ROUTE);
|
|
1763
1952
|
visibility.close();
|
|
1764
1953
|
}
|
|
1765
1954
|
})
|
package/lib/index.js
CHANGED
|
@@ -2308,6 +2308,21 @@ const CLEAR_PATH = "/api/aishell/credentials/clear";
|
|
|
2308
2308
|
* unanswered request from a refused one and stop asking.
|
|
2309
2309
|
*/
|
|
2310
2310
|
const CANCEL_PATH = "/api/aishell/credentials/cancel";
|
|
2311
|
+
/**
|
|
2312
|
+
* Route the browser calls when the person confirms credentials already stored.
|
|
2313
|
+
*
|
|
2314
|
+
* The store is not touched, and nothing is verified: the card only offers this
|
|
2315
|
+
* when a credential is present, and the tool that asked re-reads and verifies
|
|
2316
|
+
* the store for itself. So this answers one question — "the person looked at
|
|
2317
|
+
* the account and is done" — and settles the request waiting on it.
|
|
2318
|
+
*
|
|
2319
|
+
* Why it has to exist at all: a signed-in person has no other way to answer a
|
|
2320
|
+
* blocked `aishell__auth`. The save route is the only other thing that settles
|
|
2321
|
+
* a request, and it needs a credential to post; without this, someone who was
|
|
2322
|
+
* already authenticated could only leave the card by logging out, which
|
|
2323
|
+
* destroys the credential the call was waiting to use.
|
|
2324
|
+
*/
|
|
2325
|
+
const CONFIRM_PATH = "/api/aishell/credentials/confirm";
|
|
2311
2326
|
/** Largest credential body accepted; a real payload is well under 1 KiB. */
|
|
2312
2327
|
const MAX_BODY_BYTES = 8 * 1024;
|
|
2313
2328
|
/**
|
|
@@ -2610,6 +2625,29 @@ function apply(ctx, config) {
|
|
|
2610
2625
|
return Response.json({ ok: true });
|
|
2611
2626
|
}
|
|
2612
2627
|
}), "aishell-credentials: cancel route");
|
|
2628
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
2629
|
+
path: CONFIRM_PATH,
|
|
2630
|
+
methods: ["POST"],
|
|
2631
|
+
requestBody: "buffered",
|
|
2632
|
+
fetch: async (request) => {
|
|
2633
|
+
let body;
|
|
2634
|
+
try {
|
|
2635
|
+
body = await request.json();
|
|
2636
|
+
} catch {
|
|
2637
|
+
return Response.json({
|
|
2638
|
+
ok: false,
|
|
2639
|
+
error: "Request body is not valid JSON."
|
|
2640
|
+
}, { status: 400 });
|
|
2641
|
+
}
|
|
2642
|
+
const token = body?.token;
|
|
2643
|
+
if (typeof token !== "string" || token === "") return Response.json({
|
|
2644
|
+
ok: false,
|
|
2645
|
+
error: "token is required."
|
|
2646
|
+
}, { status: 400 });
|
|
2647
|
+
if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind: "submitted" }, pendingForm);
|
|
2648
|
+
return Response.json({ ok: true });
|
|
2649
|
+
}
|
|
2650
|
+
}), "aishell-credentials: confirm route");
|
|
2613
2651
|
ctx.effect(() => ctx.connection.fetch.register({
|
|
2614
2652
|
path: PREFILL_PATH,
|
|
2615
2653
|
methods: ["GET"],
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The animation the credential card needs, as a stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* ## Why a style tag rather than inline styles
|
|
5
|
+
*
|
|
6
|
+
* `@keyframes` does not exist inline — there is no `style` property for it —
|
|
7
|
+
* and the running state's whole character is motion: a ring of dots that grows
|
|
8
|
+
* from faint to solid as it sweeps, and a progress line that drains as the
|
|
9
|
+
* login window closes. Both need a rule, so both live here. The card's static
|
|
10
|
+
* styling stays inline where it is, next to the markup it belongs to; only what
|
|
11
|
+
* CSS alone can express is in this file.
|
|
12
|
+
*
|
|
13
|
+
* ## The dial
|
|
14
|
+
*
|
|
15
|
+
* Twelve dots on one circle, each a little larger and more opaque than the one
|
|
16
|
+
* before it, so the ring reads as a single arc with a head and a tail rather
|
|
17
|
+
* than as twelve separate marks. The whole ring rotates; the label in the
|
|
18
|
+
* middle and the countdown below it do not.
|
|
19
|
+
*
|
|
20
|
+
* The sizes and the ramp are derived in CSS from one number per dot (`--i`,
|
|
21
|
+
* set inline by the component) rather than stamped out as twelve rules. That
|
|
22
|
+
* keeps {@link DIAL_DOT_COUNT} the only thing to change to re-space the ring,
|
|
23
|
+
* and it means the component holds no styling decision beyond the dot count.
|
|
24
|
+
*
|
|
25
|
+
* ## Why `prefers-reduced-motion` is handled here, not in React
|
|
26
|
+
*
|
|
27
|
+
* The brand package reads the query through `matchMedia` in a hook and stops
|
|
28
|
+
* its carousel from JavaScript. That is right for a carousel, where stopping
|
|
29
|
+
* means not advancing a timer at all. Here the motion is decorative: the ring
|
|
30
|
+
* and the line carry no information the text does not, so the media query can
|
|
31
|
+
* simply turn them off in CSS with no state for the component to hold. That
|
|
32
|
+
* also means it works on the first paint, before hydration.
|
|
33
|
+
*
|
|
34
|
+
* ## The dedupe key
|
|
35
|
+
*
|
|
36
|
+
* Stamped with the plugin id and a CSS-module-style key, matching
|
|
37
|
+
* `./huawei-mark.ts` and the build-time modules. The loader's
|
|
38
|
+
* `removeOwnedStyles` sweeps `style[data-plugin="<id>"]` on teardown, so a
|
|
39
|
+
* reload that re-registers this cannot leave two copies fighting.
|
|
40
|
+
*
|
|
41
|
+
* @module @huaweidevtools/aishell-dsh-client-credentials/client/form-motion
|
|
42
|
+
*/
|
|
43
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
44
|
+
/** Class on the box the dot ring and the centre label share. */
|
|
45
|
+
export declare const DIAL_CLASS = "aishell-cred-dial";
|
|
46
|
+
/** Class on the rotating ring itself. */
|
|
47
|
+
export declare const DIAL_RING_CLASS = "aishell-cred-dial-ring";
|
|
48
|
+
/** Class on one dot. Carries `--i`, its position around the ring. */
|
|
49
|
+
export declare const DIAL_DOT_CLASS = "aishell-cred-dial-dot";
|
|
50
|
+
/** Class on the label in the middle of the ring. */
|
|
51
|
+
export declare const DIAL_LABEL_CLASS = "aishell-cred-dial-label";
|
|
52
|
+
/**
|
|
53
|
+
* How many dots the ring is drawn from.
|
|
54
|
+
*
|
|
55
|
+
* Twelve gives one dot every 30°, which reads as a continuous arc at this size.
|
|
56
|
+
* The component maps over this, so the ring and the CSS cannot disagree about
|
|
57
|
+
* its length.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DIAL_DOT_COUNT = 12;
|
|
60
|
+
/** Class on the progress line that drains the login window. */
|
|
61
|
+
export declare const PROGRESS_CLASS = "aishell-cred-progress";
|
|
62
|
+
/** Class on the track the progress line sits in. */
|
|
63
|
+
export declare const PROGRESS_TRACK_CLASS = "aishell-cred-progress-track";
|
|
64
|
+
/**
|
|
65
|
+
* Install the stylesheet, once per plugin fiber.
|
|
66
|
+
*
|
|
67
|
+
* @param ctx - client context, for the effect that owns the tag.
|
|
68
|
+
*/
|
|
69
|
+
export declare function installFormMotionStyles(ctx: ClientContext): void;
|
|
70
|
+
//# sourceMappingURL=form-motion.d.ts.map
|
|
@@ -29,13 +29,12 @@ export declare const zh: {
|
|
|
29
29
|
readonly 'form.browser.action': "登录";
|
|
30
30
|
readonly 'form.browser.checking': "环境检测中…";
|
|
31
31
|
readonly 'form.browser.unsupported': "当前环境不支持该方式。";
|
|
32
|
-
readonly 'form.browser.unsupportedLabel': "不支持";
|
|
33
32
|
readonly 'form.browser.cancelLabel': "取消登录";
|
|
34
|
-
readonly 'form.browser.
|
|
33
|
+
readonly 'form.browser.runningLabel': "登录中";
|
|
35
34
|
readonly 'form.browser.notOpened': "若浏览器未自动打开,请";
|
|
36
|
-
readonly 'form.browser.
|
|
35
|
+
readonly 'form.browser.openHere': "点击此处";
|
|
36
|
+
readonly 'form.browser.openHereSuffix': "打开。";
|
|
37
37
|
readonly 'form.browser.blocked': "浏览器拦截了新标签页,请允许弹出窗口后重试。";
|
|
38
|
-
readonly 'form.browser.copyFailed': "无法复制链接,请手动从浏览器地址栏重试。";
|
|
39
38
|
readonly 'form.browser.failed': "浏览器登录未完成。";
|
|
40
39
|
readonly 'form.browser.startFailed': "无法启动浏览器登录,请改用 AK/SK 或稍后重试。";
|
|
41
40
|
readonly 'form.browser.expired': "登录超时,请重试。";
|
|
@@ -81,13 +80,12 @@ export declare const en: {
|
|
|
81
80
|
readonly 'form.browser.action': "Sign in";
|
|
82
81
|
readonly 'form.browser.checking': "Checking this environment…";
|
|
83
82
|
readonly 'form.browser.unsupported': "This environment does not support this method.";
|
|
84
|
-
readonly 'form.browser.unsupportedLabel': "Unsupported";
|
|
85
83
|
readonly 'form.browser.cancelLabel': "Cancel sign-in";
|
|
86
|
-
readonly 'form.browser.
|
|
87
|
-
readonly 'form.browser.notOpened': "If the browser did not open,";
|
|
88
|
-
readonly 'form.browser.
|
|
84
|
+
readonly 'form.browser.runningLabel': "Signing in";
|
|
85
|
+
readonly 'form.browser.notOpened': "If the browser did not open, ";
|
|
86
|
+
readonly 'form.browser.openHere': "click here";
|
|
87
|
+
readonly 'form.browser.openHereSuffix': " to open it.";
|
|
89
88
|
readonly 'form.browser.blocked': "The browser blocked the new tab. Allow pop-ups for this page, then try again.";
|
|
90
|
-
readonly 'form.browser.copyFailed': "Could not copy the link. Try again from the browser address bar.";
|
|
91
89
|
readonly 'form.browser.failed': "The browser sign-in did not complete.";
|
|
92
90
|
readonly 'form.browser.startFailed': "Could not start the browser sign-in. Use an AK/SK instead, or try again.";
|
|
93
91
|
readonly 'form.browser.expired': "The sign-in timed out. Try again.";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaweidevtools/aishell-dsh-client-credentials",
|
|
3
3
|
"description": "AI Shell credentials — chip-opened web form for storing Huawei Cloud AK/SK in the credential store",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.
|
|
44
|
+
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.12"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@deepseek-ai/cordis": "^4.0.4",
|