gaoding-cli 1.0.0-alpha.11 → 1.0.0-alpha.13

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 安装
6
6
 
7
- 需要 Node.js 24 或更高版本。使用 npm 或 pnpm 全局安装:
7
+ 需要 Node.js 20 或更高版本。使用 npm 或 pnpm 全局安装:
8
8
 
9
9
  ```bash
10
10
  npm install --global --allow-scripts=gaoding-cli gaoding-cli
@@ -24,11 +24,11 @@ export function createSsoService(options) {
24
24
  const baseUrl = new URL(options.ssoApi);
25
25
  if (!baseUrl.pathname.endsWith("/"))
26
26
  baseUrl.pathname += "/";
27
- async function request(relativeUrl, signal) {
27
+ async function request(relativeUrl, signal, method = "POST") {
28
28
  signal.throwIfAborted();
29
29
  try {
30
30
  return await options.fetch(new URL(relativeUrl, baseUrl), {
31
- method: "POST",
31
+ method,
32
32
  headers: { Accept: "application/json" },
33
33
  signal: AbortSignal.any([
34
34
  signal,
@@ -98,6 +98,21 @@ export function createSsoService(options) {
98
98
  result.organizationId = organizationId;
99
99
  return result;
100
100
  },
101
+ async getIdentity(accessKey, signal) {
102
+ const query = new URLSearchParams({ ak: accessKey });
103
+ const response = await request(`oauth/device/identity?${query}`, signal, "GET");
104
+ if (!response.ok)
105
+ throw new SsoRequestError(response.status);
106
+ const body = await responseRecord(response);
107
+ const result = {};
108
+ const userId = identifier(body.userId);
109
+ if (userId)
110
+ result.account = { id: userId, name: userId };
111
+ const organizationId = identifier(body.orgId);
112
+ if (organizationId)
113
+ result.organizationId = organizationId;
114
+ return result;
115
+ },
101
116
  async bindOrganization(input, signal) {
102
117
  const timestamp = Math.floor(options.now().getTime() / 1000);
103
118
  const query = new URLSearchParams({
@@ -71,20 +71,33 @@ export function createAuthUseCases(dependencies) {
71
71
  interval += 5_000;
72
72
  continue;
73
73
  }
74
- const state = {
74
+ let state = {
75
75
  version: 1,
76
76
  credential: token.credential,
77
77
  ...(token.account ? { account: token.account } : {})
78
78
  };
79
79
  await dependencies.store.write(state);
80
- if (!token.organizationId) {
80
+ let organizationId = token.organizationId;
81
+ try {
82
+ const identity = await dependencies.sso.getIdentity(token.credential.accessKey, input.signal);
83
+ organizationId = identity.organizationId ?? organizationId;
84
+ if (!state.account && identity.account) {
85
+ state = { ...state, account: identity.account };
86
+ await dependencies.store.write(state);
87
+ }
88
+ }
89
+ catch {
90
+ if (input.signal.aborted)
91
+ throw input.signal.reason;
92
+ }
93
+ if (!organizationId) {
81
94
  input.interaction.warn("登录成功,请执行 gd-cli org switch 选择组织。");
82
95
  return { status: "logged_in", organizationSelected: false };
83
96
  }
84
97
  try {
85
98
  const organization = await dependencies.organizationBinder.bindAuthorizedOrganization({
86
99
  credential: token.credential,
87
- organizationId: token.organizationId,
100
+ organizationId,
88
101
  signal: input.signal
89
102
  });
90
103
  if (!organization) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaoding-cli",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.13",
4
4
  "description": "Gaoding command-line interface for agents and people.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "tag": "alpha"
11
11
  },
12
12
  "engines": {
13
- "node": ">=24"
13
+ "node": ">=20.0.0"
14
14
  },
15
15
  "bin": {
16
16
  "gd-cli": "dist/bin/gd-cli.js"
@@ -26,7 +26,7 @@
26
26
  "ajv": "8.20.0",
27
27
  "ajv-formats": "3.0.1",
28
28
  "ali-oss": "6.23.0",
29
- "commander": "15.0.0",
29
+ "commander": "14.0.3",
30
30
  "open": "11.0.0",
31
31
  "qrcode": "1.5.4",
32
32
  "semver": "7.8.5",