@huaqiu/dsh-auth 0.6.23 → 0.6.25

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.d.mts CHANGED
@@ -46,6 +46,11 @@ interface HuaqiuAuthConfig {
46
46
  * `HQ_AI_ENV`. Absent → the browser half keeps its standalone PROD default.
47
47
  */
48
48
  subscriptionOrigin?: string;
49
+ /**
50
+ * Full「Go to profile」URL resolved by HQ Edge from the SAME `HQ_AI_ENV`.
51
+ * Absent → the browser half keeps its standalone PROD default.
52
+ */
53
+ profileUrl?: string;
49
54
  }
50
55
  //#endregion
51
56
  //#region src/validation.d.ts
@@ -167,6 +172,11 @@ interface HuaqiuAuthService {
167
172
  * or null when none was configured (standalone keeps its PROD default).
168
173
  */
169
174
  readonly subscriptionOrigin: string | null;
175
+ /**
176
+ * Full「Go to profile」URL injected by HQ Edge (`config.profileUrl`), or null
177
+ * when none was configured — the browser half then keeps its PROD default.
178
+ */
179
+ readonly profileUrl: string | null;
170
180
  }
171
181
  declare class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
172
182
  private current;
@@ -199,6 +209,8 @@ declare class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
199
209
  readonly subscriptionApiBaseUrl: string | null;
200
210
  /** Subscription origin resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
201
211
  readonly subscriptionOrigin: string | null;
212
+ /**「Go to profile」URL resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
213
+ readonly profileUrl: string | null;
202
214
  readonly auth: HuaqiuAuthApi;
203
215
  /**
204
216
  * Spec §6.2 resolution order: host → pushed → persisted → null.
package/lib/index.mjs CHANGED
@@ -55,6 +55,7 @@ function resolveHostConfig(config, env = process.env) {
55
55
  }
56
56
  const subscriptionBalancesUrl = (config?.subscriptionBalancesUrl ?? env.HQ_AI_SUBSCRIPTION_BALANCES_URL ?? "").trim();
57
57
  const subscriptionOrigin = (config?.subscriptionOrigin ?? env.HQ_AI_SUBSCRIPTION_ORIGIN ?? "").trim().replace(/\/+$/, "");
58
+ const profileUrl = (config?.profileUrl ?? env.HQ_AI_PROFILE_URL ?? "").trim();
58
59
  return {
59
60
  hqEdgeBaseUrl: baseUrl,
60
61
  hostAuthPath,
@@ -63,7 +64,8 @@ function resolveHostConfig(config, env = process.env) {
63
64
  hostSessionTtlSeconds: ttl,
64
65
  validationTtlSeconds,
65
66
  subscriptionBalancesUrl,
66
- subscriptionOrigin
67
+ subscriptionOrigin,
68
+ profileUrl
67
69
  };
68
70
  }
69
71
  /**
@@ -551,6 +553,7 @@ var InMemoryHuaqiuAuthService = class {
551
553
  this.subscriptionBalancesUrl = resolved.subscriptionBalancesUrl?.length ? resolved.subscriptionBalancesUrl : null;
552
554
  this.subscriptionApiBaseUrl = this.subscriptionBalancesUrl ? originOf(this.subscriptionBalancesUrl) : null;
553
555
  this.subscriptionOrigin = resolved.subscriptionOrigin?.length ? resolved.subscriptionOrigin : null;
556
+ this.profileUrl = resolved.profileUrl?.length ? resolved.profileUrl : null;
554
557
  this.log.info("auth service started", {
555
558
  hostMode: this.hostMode,
556
559
  hostAuthPath: resolved.hostAuthPath,
@@ -567,6 +570,8 @@ var InMemoryHuaqiuAuthService = class {
567
570
  subscriptionApiBaseUrl;
568
571
  /** Subscription origin resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
569
572
  subscriptionOrigin;
573
+ /**「Go to profile」URL resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
574
+ profileUrl;
570
575
  auth = {
571
576
  isAuthenticated: async () => {
572
577
  if (await this.resolve() === null) return false;
@@ -973,7 +978,8 @@ function createAuthHandler(service) {
973
978
  sendJson(res, 200, {
974
979
  hostMode: service.hostMode,
975
980
  subscriptionOrigin: service.subscriptionOrigin,
976
- subscriptionApiBaseUrl: service.subscriptionApiBaseUrl
981
+ subscriptionApiBaseUrl: service.subscriptionApiBaseUrl,
982
+ profileUrl: service.profileUrl
977
983
  });
978
984
  return;
979
985
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huaqiu/dsh-auth",
3
- "version": "0.6.23",
3
+ "version": "0.6.25",
4
4
  "type": "module",
5
5
  "main": "./lib/index.mjs",
6
6
  "types": "./lib/index.d.mts",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@deepseek-ai/dsh-home-paths": "^0.1.0-rc.0",
36
- "@huaqiu/dsh-plugin-log": "0.6.23"
36
+ "@huaqiu/dsh-plugin-log": "0.6.25"
37
37
  },
38
38
  "files": [
39
39
  "lib",
@@ -82,6 +82,12 @@ export interface AuthClient {
82
82
  * no credential / no configured origin.
83
83
  */
84
84
  getSubscriptionQuota(productCode: string): Promise<SubscriptionQuota | null>
85
+ /**
86
+ *「Go to profile」URL resolved by HQ Edge from the same `HQ_AI_ENV` (node
87
+ * `/config`). Null in standalone → callers fall back to lib.ts's PROD
88
+ * default via {@link buildProfileUrl}.
89
+ */
90
+ getProfileUrl(): string | null
85
91
  /**
86
92
  * AI token usage for the signed-in account. Resolved by the NODE half
87
93
  * (`GET /api/v1/huaqiu/auth/ai-usage`) — the endpoint is served over plain
@@ -151,6 +157,11 @@ export function createAuthClient(deps: AuthClientDeps): AuthClient {
151
157
  * when no environment is configured → GEN/ERC quota calls are skipped.
152
158
  */
153
159
  let subscriptionApiBaseUrl: string | null = null
160
+ /**
161
+ *「Go to profile」URL resolved by HQ Edge from `HQ_AI_ENV`. Null in
162
+ * standalone → lib.ts keeps its PROD fallback.
163
+ */
164
+ let profileUrl: string | null = null
154
165
 
155
166
  const emit = (info: AuthTokenPayload | null): void => {
156
167
  for (const listener of listeners) listener(info)
@@ -285,6 +296,7 @@ export function createAuthClient(deps: AuthClientDeps): AuthClient {
285
296
  ...(subscriptionApiBaseUrl ? { baseUrl: subscriptionApiBaseUrl } : {}),
286
297
  })
287
298
  },
299
+ getProfileUrl: (): string | null => profileUrl,
288
300
  getAiTokenUsage: async (): Promise<AiUsage | null> => {
289
301
  if (hostMode && !hostSessionLoaded) await resolveHost()
290
302
  // Gate on a credential first: the node route resolves the token itself,
@@ -385,10 +397,12 @@ export function createAuthClient(deps: AuthClientDeps): AuthClient {
385
397
  mode = runtime.hostMode
386
398
  subscriptionOrigin = runtime.subscriptionOrigin
387
399
  subscriptionApiBaseUrl = runtime.subscriptionApiBaseUrl
400
+ profileUrl = runtime.profileUrl
388
401
  } catch {
389
402
  mode = false
390
403
  subscriptionOrigin = null
391
404
  subscriptionApiBaseUrl = null
405
+ profileUrl = null
392
406
  }
393
407
  hostMode = mode
394
408
  hostSessionLoaded = false
@@ -428,6 +442,7 @@ export function createAuthClient(deps: AuthClientDeps): AuthClient {
428
442
  hostSessionLoaded = false
429
443
  subscriptionOrigin = null
430
444
  subscriptionApiBaseUrl = null
445
+ profileUrl = null
431
446
  void trustedOrigin // referenced for clarity: the auth iframe URL comes from it
432
447
  },
433
448
  }
package/src/client/lib.ts CHANGED
@@ -21,7 +21,11 @@
21
21
 
22
22
  export const AUTH_ORIGIN = 'https://auth.eda.cn'
23
23
 
24
- /**「Go to profile」destination: the eda.cn account page. */
24
+ /** Standalone-DSH fallback for the「Go to profile」destination. Under HQ Edge the full URL is
25
+ * resolved ONCE from `HQ_AI_ENV` (PROD: `https://www.eda.cn/account/profile`,
26
+ * TEST: `http://www.fdatasheets.com/account`) and arrives via the node half's
27
+ * `/config` route; this constant is used only when nothing supplies one.
28
+ */
25
29
  export const PROFILE_URL = 'https://www.eda.cn/account/profile'
26
30
 
27
31
  // ── Subscription (quota + upgrade dialog) ────────────────────────────────────
@@ -171,15 +175,21 @@ export async function fetchSubscriptionQuota(options: {
171
175
  * in the query, mirroring `hq-eda-ai`'s `UserMenu`
172
176
  * (`/account/profile?token=…&phone=…`).
173
177
  *
174
- * The token is always attached: eda.cn consumes it to establish the session
175
- * and strips it from the address bar / history itself, so there is nothing to
176
- * leak beyond the target site. `encodeURIComponent` is required (not cosmetic):
177
- * tokens are base64-ish and may contain `+`, `/` or `=`, and a raw `+` in a
178
- * query string decodes to a space, which would corrupt the credential.
178
+ * `profileUrl` comes from the node half (HQ Edge → `HQ_AI_ENV`); omitted in
179
+ * standalone DSH, which keeps the {@link PROFILE_URL} PROD fallback. The
180
+ * injected value is a FULL URL (path included), because PROD and TEST do not
181
+ * share it (`/account/profile` vs `/account`); any existing query string on it
182
+ * is preserved and `token`/`phone` are appended.
179
183
  */
180
- export function buildProfileUrl(options: { token: string; phone?: string | number }): string {
184
+ export function buildProfileUrl(options: {
185
+ token: string
186
+ phone?: string | number
187
+ profileUrl?: string
188
+ }): string {
181
189
  const phone = options.phone === undefined || options.phone === null ? '' : String(options.phone)
182
- return `${PROFILE_URL}?token=${encodeURIComponent(options.token)}&phone=${encodeURIComponent(phone)}`
190
+ const base = options.profileUrl?.length ? options.profileUrl : PROFILE_URL
191
+ const sep = base.includes('?') ? '&' : '?'
192
+ return `${base}${sep}token=${encodeURIComponent(options.token)}&phone=${encodeURIComponent(phone)}`
183
193
  }
184
194
 
185
195
  /**
@@ -16,7 +16,9 @@ export interface AuthTransport {
16
16
  * - `subscriptionOrigin`: the SAME `HQ_AI_ENV`-resolved origin used for the
17
17
  * subscription dialog (null → standalone PROD fallback);
18
18
  * - `subscriptionApiBaseUrl`: origin of the resolved balances API, used for
19
- * the GEN/ERC active-subscription calls (null → quota unavailable).
19
+ * the GEN/ERC active-subscription calls (null → quota unavailable);
20
+ * - `profileUrl`: full「Go to profile」URL from the same resolution (null →
21
+ * standalone keeps lib.ts's PROD default).
20
22
  */
21
23
  fetchRuntimeConfig(): Promise<AuthRuntimeConfig>
22
24
  /**
@@ -67,10 +69,12 @@ export interface AuthRuntimeConfig {
67
69
  subscriptionOrigin: string | null
68
70
  /** Origin for GEN/ERC quota calls; null = no environment configured. */
69
71
  subscriptionApiBaseUrl: string | null
72
+ /** Full profile URL (path kept); null = standalone PROD fallback. */
73
+ profileUrl: string | null
70
74
  }
71
75
 
72
- /** Accept only an absolute http(s) origin; anything else → null. */
73
- function normalizeOrigin(value: unknown): string | null {
76
+ /** Accept only an absolute http(s) URL; anything else → null. A path is kept. */
77
+ function normalizeHttpUrl(value: unknown): string | null {
74
78
  if (typeof value !== 'string') return null
75
79
  const trimmed = value.trim().replace(/\/+$/, '')
76
80
  if (!trimmed) return null
@@ -133,17 +137,20 @@ export function createWebServerAuthTransport(
133
137
  hostMode: false,
134
138
  subscriptionOrigin: null,
135
139
  subscriptionApiBaseUrl: null,
140
+ profileUrl: null,
136
141
  }
137
142
  }
138
143
  const body = await res.json() as {
139
144
  hostMode?: unknown
140
145
  subscriptionOrigin?: unknown
141
146
  subscriptionApiBaseUrl?: unknown
147
+ profileUrl?: unknown
142
148
  }
143
149
  return {
144
150
  hostMode: body.hostMode === true,
145
- subscriptionOrigin: normalizeOrigin(body.subscriptionOrigin),
146
- subscriptionApiBaseUrl: normalizeOrigin(body.subscriptionApiBaseUrl),
151
+ subscriptionOrigin: normalizeHttpUrl(body.subscriptionOrigin),
152
+ subscriptionApiBaseUrl: normalizeHttpUrl(body.subscriptionApiBaseUrl),
153
+ profileUrl: normalizeHttpUrl(body.profileUrl),
147
154
  }
148
155
  } catch {
149
156
  // Offline/same-origin failure: fall back to standalone (show the login
@@ -153,6 +160,7 @@ export function createWebServerAuthTransport(
153
160
  hostMode: false,
154
161
  subscriptionOrigin: null,
155
162
  subscriptionApiBaseUrl: null,
163
+ profileUrl: null,
156
164
  }
157
165
  }
158
166
  },
@@ -859,7 +859,14 @@ export const HuaqiuAuthSidebarAction = memo(function HuaqiuAuthSidebarAction({ w
859
859
  .then((i) => (i ? { token: i.token, phone: i.phone } : null))
860
860
  .catch(() => null)
861
861
  if (!info?.token) return
862
- window.open(buildProfileUrl(info), '_blank', 'noopener,noreferrer')
862
+ // `profileUrl` is the HQ Edge-resolved full URL (`HQ_AI_ENV`); null in
863
+ // standalone, where buildProfileUrl keeps its PROD fallback.
864
+ const profileUrl = auth.getProfileUrl()
865
+ window.open(
866
+ buildProfileUrl({ ...info, ...(profileUrl ? { profileUrl } : {}) }),
867
+ '_blank',
868
+ 'noopener,noreferrer',
869
+ )
863
870
  })()
864
871
  }
865
872
 
package/src/host.ts CHANGED
@@ -56,6 +56,11 @@ export interface HuaqiuAuthConfig {
56
56
  * `HQ_AI_ENV`. Absent → the browser half keeps its standalone PROD default.
57
57
  */
58
58
  subscriptionOrigin?: string
59
+ /**
60
+ * Full「Go to profile」URL resolved by HQ Edge from the SAME `HQ_AI_ENV`.
61
+ * Absent → the browser half keeps its standalone PROD default.
62
+ */
63
+ profileUrl?: string
59
64
  }
60
65
 
61
66
  export const DEFAULT_HOST_AUTH_PATH = '/api/v1/auth/token'
@@ -112,6 +117,7 @@ export function resolveHostConfig(
112
117
  const subscriptionOrigin = (config?.subscriptionOrigin ?? env.HQ_AI_SUBSCRIPTION_ORIGIN ?? '')
113
118
  .trim()
114
119
  .replace(/\/+$/, '')
120
+ const profileUrl = (config?.profileUrl ?? env.HQ_AI_PROFILE_URL ?? '').trim()
115
121
  return {
116
122
  hqEdgeBaseUrl: baseUrl,
117
123
  hostAuthPath,
@@ -121,6 +127,7 @@ export function resolveHostConfig(
121
127
  validationTtlSeconds,
122
128
  subscriptionBalancesUrl,
123
129
  subscriptionOrigin,
130
+ profileUrl,
124
131
  }
125
132
  }
126
133
 
package/src/routes.ts CHANGED
@@ -240,6 +240,9 @@ export function createAuthHandler(service: HuaqiuAuthService): AuthHandler {
240
240
  // Origin of the resolved balances API — lets the browser build the
241
241
  // GEN/ERC active-subscription calls without hardcoding eda.cn.
242
242
  subscriptionApiBaseUrl: service.subscriptionApiBaseUrl,
243
+ // Full profile URL (path included) resolved from the same HQ_AI_ENV;
244
+ // null in standalone → the browser keeps lib.ts's PROD default.
245
+ profileUrl: service.profileUrl,
243
246
  })
244
247
  return
245
248
  }
package/src/service.ts CHANGED
@@ -112,6 +112,11 @@ export interface HuaqiuAuthService {
112
112
  * or null when none was configured (standalone keeps its PROD default).
113
113
  */
114
114
  readonly subscriptionOrigin: string | null
115
+ /**
116
+ * Full「Go to profile」URL injected by HQ Edge (`config.profileUrl`), or null
117
+ * when none was configured — the browser half then keeps its PROD default.
118
+ */
119
+ readonly profileUrl: string | null
115
120
  }
116
121
 
117
122
  const PERSIST_FILE = 'session.json'
@@ -246,6 +251,7 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
246
251
  this.subscriptionOrigin = resolved.subscriptionOrigin?.length
247
252
  ? resolved.subscriptionOrigin
248
253
  : null
254
+ this.profileUrl = resolved.profileUrl?.length ? resolved.profileUrl : null
249
255
  this.log.info('auth service started', {
250
256
  hostMode: this.hostMode,
251
257
  hostAuthPath: resolved.hostAuthPath,
@@ -266,6 +272,8 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
266
272
  readonly subscriptionApiBaseUrl: string | null
267
273
  /** Subscription origin resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
268
274
  readonly subscriptionOrigin: string | null
275
+ /**「Go to profile」URL resolved by HQ Edge (`HQ_AI_ENV`); null → standalone. */
276
+ readonly profileUrl: string | null
269
277
 
270
278
  readonly auth: HuaqiuAuthApi = {
271
279
  isAuthenticated: async () => {