@huaweidevtools/aishell-dsh-client-credentials 0.0.9 → 0.0.11
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
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.
|
|
@@ -992,6 +1154,7 @@ function CredentialRequestForm(props) {
|
|
|
992
1154
|
cursor: disabled ? "not-allowed" : "text"
|
|
993
1155
|
});
|
|
994
1156
|
const buttonStyle = (disabled, kind = "secondary") => ({
|
|
1157
|
+
flex: 1,
|
|
995
1158
|
height: 34,
|
|
996
1159
|
padding: "0 16px",
|
|
997
1160
|
borderRadius: 8,
|
|
@@ -1093,9 +1256,18 @@ function CredentialRequestForm(props) {
|
|
|
1093
1256
|
children: status.accessKeyIdHint === "" ? t("form.signedIn") : status.accessKeyIdHint
|
|
1094
1257
|
})]
|
|
1095
1258
|
}),
|
|
1096
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1097
|
-
style: {
|
|
1098
|
-
|
|
1259
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1260
|
+
style: {
|
|
1261
|
+
display: "flex",
|
|
1262
|
+
gap: 12
|
|
1263
|
+
},
|
|
1264
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1265
|
+
type: "button",
|
|
1266
|
+
onClick: confirm,
|
|
1267
|
+
disabled: busy,
|
|
1268
|
+
style: buttonStyle(busy, "primary"),
|
|
1269
|
+
children: t("form.confirm")
|
|
1270
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1099
1271
|
type: "button",
|
|
1100
1272
|
onClick: () => {
|
|
1101
1273
|
onClear();
|
|
@@ -1103,7 +1275,7 @@ function CredentialRequestForm(props) {
|
|
|
1103
1275
|
disabled: busy,
|
|
1104
1276
|
style: buttonStyle(busy),
|
|
1105
1277
|
children: clearing ? t("form.clearing") : t("form.logout")
|
|
1106
|
-
})
|
|
1278
|
+
})]
|
|
1107
1279
|
}),
|
|
1108
1280
|
manualError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1109
1281
|
style: notice,
|
|
@@ -1125,14 +1297,48 @@ function CredentialRequestForm(props) {
|
|
|
1125
1297
|
},
|
|
1126
1298
|
children: t("form.browser.section")
|
|
1127
1299
|
}),
|
|
1128
|
-
phase === "running" &&
|
|
1129
|
-
|
|
1300
|
+
phase === "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1301
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1302
|
+
className: DIAL_CLASS,
|
|
1303
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1304
|
+
className: DIAL_RING_CLASS,
|
|
1305
|
+
"aria-hidden": true,
|
|
1306
|
+
children: Array.from({ length: DIAL_DOT_COUNT }, (_, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1307
|
+
className: DIAL_DOT_CLASS,
|
|
1308
|
+
style: { "--i": i }
|
|
1309
|
+
}, i))
|
|
1310
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1311
|
+
className: DIAL_LABEL_CLASS,
|
|
1312
|
+
children: t("form.browser.runningLabel")
|
|
1313
|
+
})]
|
|
1314
|
+
}),
|
|
1315
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1316
|
+
role: "status",
|
|
1317
|
+
style: {
|
|
1318
|
+
fontSize: 13,
|
|
1319
|
+
lineHeight: "20px",
|
|
1320
|
+
textAlign: "center",
|
|
1321
|
+
fontVariantNumeric: "tabular-nums",
|
|
1322
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
1323
|
+
},
|
|
1324
|
+
children: secondsLeft === void 0 ? "" : formatCountdown(secondsLeft)
|
|
1325
|
+
}),
|
|
1326
|
+
secondsLeft !== void 0 && loginWindowSeconds !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1327
|
+
className: PROGRESS_TRACK_CLASS,
|
|
1328
|
+
"aria-hidden": true,
|
|
1329
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1330
|
+
className: PROGRESS_CLASS,
|
|
1331
|
+
style: { width: `${String(Math.round(secondsLeft / loginWindowSeconds * 100))}%` }
|
|
1332
|
+
})
|
|
1333
|
+
})
|
|
1334
|
+
] }),
|
|
1335
|
+
phase !== "running" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1130
1336
|
style: {
|
|
1131
1337
|
fontSize: 13,
|
|
1132
|
-
|
|
1133
|
-
|
|
1338
|
+
fontWeight: 500,
|
|
1339
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
1134
1340
|
},
|
|
1135
|
-
children: t("form.browser.
|
|
1341
|
+
children: t("form.browser.section")
|
|
1136
1342
|
}),
|
|
1137
1343
|
phase === "checking" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1138
1344
|
style: {
|
|
@@ -1151,16 +1357,13 @@ function CredentialRequestForm(props) {
|
|
|
1151
1357
|
style: {
|
|
1152
1358
|
display: "flex",
|
|
1153
1359
|
alignItems: "center",
|
|
1154
|
-
gap:
|
|
1360
|
+
gap: 12
|
|
1155
1361
|
},
|
|
1156
1362
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1157
1363
|
type: "button",
|
|
1158
1364
|
onClick: phase === "running" ? onCancelLogin : onBrowserLogin,
|
|
1159
1365
|
disabled: button.disabled,
|
|
1160
|
-
style:
|
|
1161
|
-
...buttonStyle(button.disabled, button.disabled ? "secondary" : "primary"),
|
|
1162
|
-
flex: 1
|
|
1163
|
-
},
|
|
1366
|
+
style: buttonStyle(button.disabled, button.disabled ? "secondary" : "primary"),
|
|
1164
1367
|
children: t(button.label)
|
|
1165
1368
|
})
|
|
1166
1369
|
}),
|
|
@@ -1294,7 +1497,7 @@ function CredentialRequestForm(props) {
|
|
|
1294
1497
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1295
1498
|
style: {
|
|
1296
1499
|
display: "flex",
|
|
1297
|
-
gap:
|
|
1500
|
+
gap: 12
|
|
1298
1501
|
},
|
|
1299
1502
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1300
1503
|
type: "submit",
|
|
@@ -1429,21 +1632,21 @@ const zh = {
|
|
|
1429
1632
|
"mode.unavailable.hint": "无法读取权限模式;切换按钮暂不可用",
|
|
1430
1633
|
"mode.switchToReadonly": "切换为只读模式",
|
|
1431
1634
|
"mode.switchToReadwrite": "切换为读写模式",
|
|
1432
|
-
"section.credentials.hint.prefix": "
|
|
1635
|
+
"section.credentials.hint.prefix": "建议从",
|
|
1433
1636
|
"section.credentials.hint.link": "API Explorer",
|
|
1434
1637
|
"section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
|
|
1435
1638
|
"section.credentials.saving": "保存中…",
|
|
1436
1639
|
"form.title": "华为云 IAM 认证",
|
|
1437
1640
|
"form.or": "或者",
|
|
1438
1641
|
"form.signedIn": "已登录",
|
|
1642
|
+
"form.confirm": "确认",
|
|
1439
1643
|
"form.logout": "退出",
|
|
1440
1644
|
"form.browser.section": "选项一:浏览器登录",
|
|
1441
1645
|
"form.browser.action": "登录",
|
|
1442
1646
|
"form.browser.checking": "环境检测中…",
|
|
1443
1647
|
"form.browser.unsupported": "当前环境不支持该方式。",
|
|
1444
|
-
"form.browser.unsupportedLabel": "不支持",
|
|
1445
1648
|
"form.browser.cancelLabel": "取消登录",
|
|
1446
|
-
"form.browser.
|
|
1649
|
+
"form.browser.runningLabel": "登录中",
|
|
1447
1650
|
"form.browser.notOpened": "若浏览器未自动打开,请",
|
|
1448
1651
|
"form.browser.copyLink": "手动复制链接到浏览器打开",
|
|
1449
1652
|
"form.browser.blocked": "浏览器拦截了新标签页,请允许弹出窗口后重试。",
|
|
@@ -1480,21 +1683,21 @@ const en = {
|
|
|
1480
1683
|
"mode.unavailable.hint": "Could not read the permission mode; the toggle is unavailable",
|
|
1481
1684
|
"mode.switchToReadonly": "Switch to read-only mode",
|
|
1482
1685
|
"mode.switchToReadwrite": "Switch to read-write mode",
|
|
1483
|
-
"section.credentials.hint.prefix": "
|
|
1686
|
+
"section.credentials.hint.prefix": "Obtain temporary credentials from",
|
|
1484
1687
|
"section.credentials.hint.link": "API Explorer",
|
|
1485
1688
|
"section.credentials.hint.suffix": "and avoid permanent ones.",
|
|
1486
1689
|
"section.credentials.saving": "Saving…",
|
|
1487
1690
|
"form.title": "Huawei Cloud IAM authentication",
|
|
1488
1691
|
"form.or": "or",
|
|
1489
1692
|
"form.signedIn": "Signed in",
|
|
1693
|
+
"form.confirm": "Confirm",
|
|
1490
1694
|
"form.logout": "Logout",
|
|
1491
1695
|
"form.browser.section": "Option 1: sign in with a browser",
|
|
1492
1696
|
"form.browser.action": "Sign in",
|
|
1493
1697
|
"form.browser.checking": "Checking this environment…",
|
|
1494
|
-
"form.browser.unsupported": "This environment does not support
|
|
1495
|
-
"form.browser.unsupportedLabel": "Unsupported",
|
|
1698
|
+
"form.browser.unsupported": "This environment does not support this method.",
|
|
1496
1699
|
"form.browser.cancelLabel": "Cancel sign-in",
|
|
1497
|
-
"form.browser.
|
|
1700
|
+
"form.browser.runningLabel": "Signing in",
|
|
1498
1701
|
"form.browser.notOpened": "If the browser did not open,",
|
|
1499
1702
|
"form.browser.copyLink": "copy the link into your browser",
|
|
1500
1703
|
"form.browser.blocked": "The browser blocked the new tab. Allow pop-ups for this page, then try again.",
|
|
@@ -1536,6 +1739,8 @@ const CREDENTIALS_ROUTE = "api/aishell/credentials";
|
|
|
1536
1739
|
const CLEAR_ROUTE = "api/aishell/credentials/clear";
|
|
1537
1740
|
/** Cancel route; names the request token the person declined. */
|
|
1538
1741
|
const CANCEL_ROUTE = "api/aishell/credentials/cancel";
|
|
1742
|
+
/** Confirm route; names the request token the person accepted as already stored. */
|
|
1743
|
+
const CONFIRM_ROUTE = "api/aishell/credentials/confirm";
|
|
1539
1744
|
/** Prefill route; returns the values the host's environment already holds. */
|
|
1540
1745
|
const PREFILL_ROUTE = "api/aishell/credentials/prefill";
|
|
1541
1746
|
/**
|
|
@@ -1631,6 +1836,7 @@ function apply(ctx) {
|
|
|
1631
1836
|
}), "aishell-credentials: dictionaries");
|
|
1632
1837
|
const t = ctx.locale.bind(NS);
|
|
1633
1838
|
installChipStyles(ctx);
|
|
1839
|
+
installFormMotionStyles(ctx);
|
|
1634
1840
|
const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
|
|
1635
1841
|
const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
1636
1842
|
hasAccessKey: false,
|
|
@@ -1697,17 +1903,22 @@ function apply(ctx) {
|
|
|
1697
1903
|
visibility.dispose();
|
|
1698
1904
|
}, "aishell-credentials: credential form teardown");
|
|
1699
1905
|
/**
|
|
1700
|
-
*
|
|
1906
|
+
* Answer the request this form is open for, if any.
|
|
1701
1907
|
*
|
|
1702
1908
|
* Only when this form was opened by a request: a chip-opened form has no
|
|
1703
|
-
* request behind it, and
|
|
1704
|
-
*
|
|
1909
|
+
* request behind it, and answering one would make the *next* `auth` call
|
|
1910
|
+
* believe the person had acted on a question nobody asked.
|
|
1911
|
+
*
|
|
1912
|
+
* The token is spent either way, so a second press cannot answer twice, and a
|
|
1913
|
+
* later request with the same token is not mistaken for this one.
|
|
1914
|
+
*
|
|
1915
|
+
* @param route - the cancel or confirm route to post to.
|
|
1705
1916
|
*/
|
|
1706
|
-
const
|
|
1917
|
+
const answerRequest = (route) => {
|
|
1707
1918
|
const token = pendingRequestToken;
|
|
1708
1919
|
pendingRequestToken = void 0;
|
|
1709
1920
|
if (token === void 0) return;
|
|
1710
|
-
fetch(
|
|
1921
|
+
fetch(route, {
|
|
1711
1922
|
method: "POST",
|
|
1712
1923
|
headers: { "content-type": "application/json" },
|
|
1713
1924
|
body: JSON.stringify({ token })
|
|
@@ -1759,7 +1970,11 @@ function apply(ctx) {
|
|
|
1759
1970
|
visibility.close();
|
|
1760
1971
|
},
|
|
1761
1972
|
cancel: () => {
|
|
1762
|
-
|
|
1973
|
+
answerRequest(CANCEL_ROUTE);
|
|
1974
|
+
visibility.close();
|
|
1975
|
+
},
|
|
1976
|
+
confirm: () => {
|
|
1977
|
+
answerRequest(CONFIRM_ROUTE);
|
|
1763
1978
|
visibility.close();
|
|
1764
1979
|
}
|
|
1765
1980
|
})
|
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"],
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The card shows **one** of two things, and nothing else:
|
|
11
11
|
*
|
|
12
|
-
* - **Signed in** — the account name and a way out. No
|
|
13
|
-
* question a signed-in person has is "who am I and
|
|
14
|
-
* "what is your access key".
|
|
12
|
+
* - **Signed in** — the account name, a way to accept it, and a way out. No
|
|
13
|
+
* inputs, because the question a signed-in person has is "who am I, and am
|
|
14
|
+
* I done", not "what is your access key". `确认` answers a waiting
|
|
15
|
+
* `aishell__auth`; `退出` clears the credential.
|
|
15
16
|
* - **Not signed in** — both ways to obtain a credential, side by side.
|
|
16
17
|
*
|
|
17
18
|
* An earlier version spread this across four pages (`choose` / `manual` /
|
|
@@ -83,6 +84,17 @@ export interface CredentialRequestFormInjected {
|
|
|
83
84
|
clear: () => Promise<SaveVerdict>;
|
|
84
85
|
/** Withdraw the card after saving — restores the ordinary composer. */
|
|
85
86
|
close: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Accept the stored credentials and withdraw the card.
|
|
89
|
+
*
|
|
90
|
+
* The signed-in card's affirmative action: the person looked at the account
|
|
91
|
+
* and is done. Distinct from {@link close} because it also answers a waiting
|
|
92
|
+
* `aishell__auth` — without it, a blocked call could only be answered by
|
|
93
|
+
* logging out, which destroys the credential it was waiting to use.
|
|
94
|
+
*
|
|
95
|
+
* Writes nothing and verifies nothing; the caller re-reads the store.
|
|
96
|
+
*/
|
|
97
|
+
confirm: () => void;
|
|
86
98
|
/**
|
|
87
99
|
* Decline: withdraw the card and tell the host this request was refused.
|
|
88
100
|
*
|
|
@@ -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
|
|
@@ -16,21 +16,21 @@ export declare const zh: {
|
|
|
16
16
|
readonly 'mode.unavailable.hint': "无法读取权限模式;切换按钮暂不可用";
|
|
17
17
|
readonly 'mode.switchToReadonly': "切换为只读模式";
|
|
18
18
|
readonly 'mode.switchToReadwrite': "切换为读写模式";
|
|
19
|
-
readonly 'section.credentials.hint.prefix': "
|
|
19
|
+
readonly 'section.credentials.hint.prefix': "建议从";
|
|
20
20
|
readonly 'section.credentials.hint.link': "API Explorer";
|
|
21
21
|
readonly 'section.credentials.hint.suffix': "获取临时凭据,避免使用永久凭据。";
|
|
22
22
|
readonly 'section.credentials.saving': "保存中…";
|
|
23
23
|
readonly 'form.title': "华为云 IAM 认证";
|
|
24
24
|
readonly 'form.or': "或者";
|
|
25
25
|
readonly 'form.signedIn': "已登录";
|
|
26
|
+
readonly 'form.confirm': "确认";
|
|
26
27
|
readonly 'form.logout': "退出";
|
|
27
28
|
readonly 'form.browser.section': "选项一:浏览器登录";
|
|
28
29
|
readonly 'form.browser.action': "登录";
|
|
29
30
|
readonly 'form.browser.checking': "环境检测中…";
|
|
30
31
|
readonly 'form.browser.unsupported': "当前环境不支持该方式。";
|
|
31
|
-
readonly 'form.browser.unsupportedLabel': "不支持";
|
|
32
32
|
readonly 'form.browser.cancelLabel': "取消登录";
|
|
33
|
-
readonly 'form.browser.
|
|
33
|
+
readonly 'form.browser.runningLabel': "登录中";
|
|
34
34
|
readonly 'form.browser.notOpened': "若浏览器未自动打开,请";
|
|
35
35
|
readonly 'form.browser.copyLink': "手动复制链接到浏览器打开";
|
|
36
36
|
readonly 'form.browser.blocked': "浏览器拦截了新标签页,请允许弹出窗口后重试。";
|
|
@@ -67,21 +67,21 @@ export declare const en: {
|
|
|
67
67
|
readonly 'mode.unavailable.hint': "Could not read the permission mode; the toggle is unavailable";
|
|
68
68
|
readonly 'mode.switchToReadonly': "Switch to read-only mode";
|
|
69
69
|
readonly 'mode.switchToReadwrite': "Switch to read-write mode";
|
|
70
|
-
readonly 'section.credentials.hint.prefix': "
|
|
70
|
+
readonly 'section.credentials.hint.prefix': "Obtain temporary credentials from";
|
|
71
71
|
readonly 'section.credentials.hint.link': "API Explorer";
|
|
72
72
|
readonly 'section.credentials.hint.suffix': "and avoid permanent ones.";
|
|
73
73
|
readonly 'section.credentials.saving': "Saving…";
|
|
74
74
|
readonly 'form.title': "Huawei Cloud IAM authentication";
|
|
75
75
|
readonly 'form.or': "or";
|
|
76
76
|
readonly 'form.signedIn': "Signed in";
|
|
77
|
+
readonly 'form.confirm': "Confirm";
|
|
77
78
|
readonly 'form.logout': "Logout";
|
|
78
79
|
readonly 'form.browser.section': "Option 1: sign in with a browser";
|
|
79
80
|
readonly 'form.browser.action': "Sign in";
|
|
80
81
|
readonly 'form.browser.checking': "Checking this environment…";
|
|
81
|
-
readonly 'form.browser.unsupported': "This environment does not support
|
|
82
|
-
readonly 'form.browser.unsupportedLabel': "Unsupported";
|
|
82
|
+
readonly 'form.browser.unsupported': "This environment does not support this method.";
|
|
83
83
|
readonly 'form.browser.cancelLabel': "Cancel sign-in";
|
|
84
|
-
readonly 'form.browser.
|
|
84
|
+
readonly 'form.browser.runningLabel': "Signing in";
|
|
85
85
|
readonly 'form.browser.notOpened': "If the browser did not open,";
|
|
86
86
|
readonly 'form.browser.copyLink': "copy the link into your browser";
|
|
87
87
|
readonly 'form.browser.blocked': "The browser blocked the new tab. Allow pop-ups for this page, then 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.11",
|
|
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.11"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@deepseek-ai/cordis": "^4.0.4",
|