@hcmai/sdk 0.4.20 → 0.4.21
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/dist/index.d.ts +10 -0
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -677,6 +677,14 @@ declare class TokenStore {
|
|
|
677
677
|
*/
|
|
678
678
|
private storeToken;
|
|
679
679
|
getAccessToken(): Promise<string | null>;
|
|
680
|
+
/**
|
|
681
|
+
* 只读取这一个 store 持久化的 token,不接受 HCM_PAT/HCM_ACCESS_TOKEN 覆盖。
|
|
682
|
+
*
|
|
683
|
+
* `identity show <alias>` 要回答的是「这个 alias 到底是谁」;若沿用普通命令的环境变量
|
|
684
|
+
* 优先级,机器上临时设置的一枚 token 会让所有 alias 都显示成同一个人,正向角色验收
|
|
685
|
+
* 反而得到一份可信外观的错误证据。普通业务命令仍走 {@link getAccessToken},行为不变。
|
|
686
|
+
*/
|
|
687
|
+
getStoredAccessToken(): Promise<string | null>;
|
|
680
688
|
getRefreshToken(): Promise<string | null>;
|
|
681
689
|
clear(): Promise<void>;
|
|
682
690
|
private resolveRef;
|
|
@@ -699,6 +707,8 @@ declare class TokenStore {
|
|
|
699
707
|
* login 成功那行只回显前者,于是登错租户是静默的。
|
|
700
708
|
*/
|
|
701
709
|
interface Principal {
|
|
710
|
+
/** 服务端用户主键;登录响应使用 id,auth/info 使用 userId。 */
|
|
711
|
+
userId?: string;
|
|
702
712
|
/** 服务端认定的租户。ADR-177 之后新租户是 UUID,别按 int 处理。 */
|
|
703
713
|
tenantId?: string;
|
|
704
714
|
username?: string;
|
package/dist/index.js
CHANGED
|
@@ -214,8 +214,18 @@ var TokenStore = class _TokenStore {
|
|
|
214
214
|
async getAccessToken() {
|
|
215
215
|
if (process.env.HCM_PAT) return process.env.HCM_PAT;
|
|
216
216
|
if (process.env.HCM_ACCESS_TOKEN) return process.env.HCM_ACCESS_TOKEN;
|
|
217
|
+
return this.getStoredAccessToken();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* 只读取这一个 store 持久化的 token,不接受 HCM_PAT/HCM_ACCESS_TOKEN 覆盖。
|
|
221
|
+
*
|
|
222
|
+
* `identity show <alias>` 要回答的是「这个 alias 到底是谁」;若沿用普通命令的环境变量
|
|
223
|
+
* 优先级,机器上临时设置的一枚 token 会让所有 alias 都显示成同一个人,正向角色验收
|
|
224
|
+
* 反而得到一份可信外观的错误证据。普通业务命令仍走 {@link getAccessToken},行为不变。
|
|
225
|
+
*/
|
|
226
|
+
async getStoredAccessToken() {
|
|
217
227
|
const meta = await this.readMeta();
|
|
218
|
-
if (!meta) return null;
|
|
228
|
+
if (!meta?.accessTokenRef) return null;
|
|
219
229
|
return this.resolveRef(meta.accessTokenRef);
|
|
220
230
|
}
|
|
221
231
|
async getRefreshToken() {
|
|
@@ -294,6 +304,8 @@ function toPrincipal(raw) {
|
|
|
294
304
|
if (!raw || typeof raw !== "object") return void 0;
|
|
295
305
|
const o = raw;
|
|
296
306
|
const principal = {};
|
|
307
|
+
const rawUserId = o.userId ?? o.id;
|
|
308
|
+
if (rawUserId !== void 0 && rawUserId !== null) principal.userId = String(rawUserId);
|
|
297
309
|
if (o.tenantId !== void 0 && o.tenantId !== null) principal.tenantId = String(o.tenantId);
|
|
298
310
|
if (typeof o.username === "string" && o.username) principal.username = o.username;
|
|
299
311
|
if (Array.isArray(o.roles)) principal.roles = o.roles.map(String);
|