@huaweidevtools/aishell-dsh-client-credentials 0.0.16 → 0.0.17
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/index.js +62 -6
- package/lib/types/reconcile.d.ts +19 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -2242,7 +2242,7 @@ function readEnvPrefill(env) {
|
|
|
2242
2242
|
* mirror so reconcile never depends on config flow-back timing.
|
|
2243
2243
|
*/
|
|
2244
2244
|
function createCredentialReconciler(deps) {
|
|
2245
|
-
const { verify, recordStatus, readStored, readHint, readPair } = deps;
|
|
2245
|
+
const { verify, isRejection: isRejection$1, recordStatus, readStored, readHint, readPair, discard } = deps;
|
|
2246
2246
|
let lastVerifyFingerprint = "";
|
|
2247
2247
|
const materialFingerprint = (ak, sk, token) => `${ak}\n${sk}\n${token ?? ""}`;
|
|
2248
2248
|
return {
|
|
@@ -2276,7 +2276,21 @@ function createCredentialReconciler(deps) {
|
|
|
2276
2276
|
path: ["accessKeyIdHint"],
|
|
2277
2277
|
value: accountName
|
|
2278
2278
|
}]);
|
|
2279
|
-
}).catch(() => {
|
|
2279
|
+
}).catch((error) => {
|
|
2280
|
+
if (isRejection$1(error)) {
|
|
2281
|
+
discard();
|
|
2282
|
+
lastVerifyFingerprint = "";
|
|
2283
|
+
recordStatus([{
|
|
2284
|
+
op: "set",
|
|
2285
|
+
path: ["credentialsStored"],
|
|
2286
|
+
value: false
|
|
2287
|
+
}, {
|
|
2288
|
+
op: "unset",
|
|
2289
|
+
path: ["accessKeyIdHint"]
|
|
2290
|
+
}]);
|
|
2291
|
+
return;
|
|
2292
|
+
}
|
|
2293
|
+
});
|
|
2280
2294
|
},
|
|
2281
2295
|
resetVerifyBaseline: () => {
|
|
2282
2296
|
lastVerifyFingerprint = "";
|
|
@@ -2388,7 +2402,9 @@ const MAX_BODY_BYTES = 8 * 1024;
|
|
|
2388
2402
|
* elsewhere.
|
|
2389
2403
|
*
|
|
2390
2404
|
* @returns the account name (domain name), falling back to the account id.
|
|
2391
|
-
* @throws
|
|
2405
|
+
* @throws {CredentialRejectedError} when IAM refused the credential itself —
|
|
2406
|
+
* the only failure that says the stored pair is unusable.
|
|
2407
|
+
* @throws {Error} for every other failure, with a user-readable message.
|
|
2392
2408
|
*/
|
|
2393
2409
|
async function verifyCredentials$1(ak, sk, securityToken) {
|
|
2394
2410
|
const result = await verifyCredentials({
|
|
@@ -2396,10 +2412,45 @@ async function verifyCredentials$1(ak, sk, securityToken) {
|
|
|
2396
2412
|
sk,
|
|
2397
2413
|
...securityToken === void 0 ? {} : { securityToken }
|
|
2398
2414
|
}, { region: VERIFY_REGION });
|
|
2399
|
-
if (
|
|
2400
|
-
|
|
2415
|
+
if (result.ok) return result.account.name;
|
|
2416
|
+
if (isRejection(result.status)) throw new CredentialRejectedError(result.message);
|
|
2417
|
+
throw new Error(result.message);
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* Whether IAM's answer is about the credential rather than about the call.
|
|
2421
|
+
*
|
|
2422
|
+
* The distinction decides whether the stored pair is discarded, so it is drawn
|
|
2423
|
+
* narrowly. Only 401 and 403 mean "this credential is not usable":
|
|
2424
|
+
*
|
|
2425
|
+
* - `0` never reached IAM — a DNS failure, a proxy, a timeout. The credential
|
|
2426
|
+
* may be perfectly good, and clearing it would log the person out because
|
|
2427
|
+
* their network blipped.
|
|
2428
|
+
* - A 5xx is IAM failing rather than refusing. Same conclusion.
|
|
2429
|
+
* - A 200 that failed business validation (no visible project, projects from
|
|
2430
|
+
* two accounts) arrives with the credential ACCEPTED — the answer is about
|
|
2431
|
+
* authorisation or account shape, and re-entering the same pair changes
|
|
2432
|
+
* nothing.
|
|
2433
|
+
*
|
|
2434
|
+
* @param status - the HTTP status IAM answered with, or `0`.
|
|
2435
|
+
* @returns whether the credential was refused.
|
|
2436
|
+
*/
|
|
2437
|
+
function isRejection(status) {
|
|
2438
|
+
return status === 401 || status === 403;
|
|
2401
2439
|
}
|
|
2402
2440
|
/**
|
|
2441
|
+
* IAM refused the credential itself.
|
|
2442
|
+
*
|
|
2443
|
+
* A distinct type because the caller does something a plain failure must not
|
|
2444
|
+
* trigger: it discards what is stored. The type is what keeps that decision
|
|
2445
|
+
* from being re-derived, differently, at every call site.
|
|
2446
|
+
*/
|
|
2447
|
+
var CredentialRejectedError = class extends Error {
|
|
2448
|
+
constructor(..._args) {
|
|
2449
|
+
super(..._args);
|
|
2450
|
+
this.name = "CredentialRejectedError";
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
/**
|
|
2403
2454
|
* Region used to route the verification call.
|
|
2404
2455
|
*
|
|
2405
2456
|
* Not a setting: see {@link verifyCredentials}. Any region replica answers the
|
|
@@ -2678,10 +2729,15 @@ function apply(ctx, config) {
|
|
|
2678
2729
|
});
|
|
2679
2730
|
const reconciler = createCredentialReconciler({
|
|
2680
2731
|
verify: verifyCredentials$1,
|
|
2732
|
+
isRejection: (error) => error instanceof CredentialRejectedError,
|
|
2681
2733
|
recordStatus,
|
|
2682
2734
|
readStored: () => recordedStored,
|
|
2683
2735
|
readHint: () => recordedHint,
|
|
2684
|
-
readPair: () => readStoredPair(store)
|
|
2736
|
+
readPair: () => readStoredPair(store),
|
|
2737
|
+
discard: () => {
|
|
2738
|
+
clearCredentials(store);
|
|
2739
|
+
ctx.emit("aishell/credentials-updated");
|
|
2740
|
+
}
|
|
2685
2741
|
});
|
|
2686
2742
|
ctx.effect(() => ctx.connection.fetch.register({
|
|
2687
2743
|
path: CREDENTIALS_PATH,
|
package/lib/types/reconcile.d.ts
CHANGED
|
@@ -34,8 +34,17 @@ export type ReadStored = () => boolean;
|
|
|
34
34
|
export type ReadHint = () => string | null;
|
|
35
35
|
/** Collaborators the reconciler runs against; injected so they are testable. */
|
|
36
36
|
export interface CredentialReconcilerDeps {
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Verifies against IAM; resolves the account (domain) name.
|
|
39
|
+
*
|
|
40
|
+
* A rejection — IAM refusing the credential itself — must be distinguishable
|
|
41
|
+
* from a transient failure, because only a rejection discards what is stored.
|
|
42
|
+
* `isRejection` is how the caller says which it got; the reconciler never
|
|
43
|
+
* re-derives that judgement from a message.
|
|
44
|
+
*/
|
|
38
45
|
readonly verify: VerifyCredentials;
|
|
46
|
+
/** Whether a verify failure means the credential itself was refused. */
|
|
47
|
+
readonly isRejection: (error: unknown) => boolean;
|
|
39
48
|
/** Records the non-secret status the browser half reads. */
|
|
40
49
|
readonly recordStatus: RecordStatus;
|
|
41
50
|
/** Read the recorded `credentialsStored` mirror this plugin owns. */
|
|
@@ -44,6 +53,15 @@ export interface CredentialReconcilerDeps {
|
|
|
44
53
|
readonly readHint: ReadHint;
|
|
45
54
|
/** Reads the stored pair; the bundle entry is decoded inside it. */
|
|
46
55
|
readonly readPair: () => SignCredentials | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Discard the stored credentials.
|
|
58
|
+
*
|
|
59
|
+
* Called only when IAM refused them. A credential that IAM rejects cannot be
|
|
60
|
+
* used for anything this product does, so keeping it leaves the interface
|
|
61
|
+
* showing an account name beside a form asking the person to sign in — a
|
|
62
|
+
* state that states two opposite things at once.
|
|
63
|
+
*/
|
|
64
|
+
readonly discard: () => void;
|
|
47
65
|
}
|
|
48
66
|
/** The reconcile state machine; driven by a timer and the GET-route hook. */
|
|
49
67
|
export interface CredentialReconciler {
|
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.17",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.
|
|
45
|
+
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.17"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@deepseek-ai/cordis": "^4.0.4",
|