@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/client.js +35 -14
- package/lib/client.js.map +1 -1
- package/lib/index.d.mts +12 -0
- package/lib/index.mjs +8 -2
- package/package.json +2 -2
- package/src/client/client.ts +15 -0
- package/src/client/lib.ts +18 -8
- package/src/client/transport.ts +13 -5
- package/src/client/ui/sidebar-action.tsx +8 -1
- package/src/host.ts +7 -0
- package/src/routes.ts +3 -0
- package/src/service.ts +8 -0
package/lib/client.js
CHANGED
|
@@ -36,8 +36,8 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/client/transport.ts
|
|
39
|
-
/** Accept only an absolute http(s)
|
|
40
|
-
function
|
|
39
|
+
/** Accept only an absolute http(s) URL; anything else → null. A path is kept. */
|
|
40
|
+
function normalizeHttpUrl(value) {
|
|
41
41
|
if (typeof value !== "string") return null;
|
|
42
42
|
const trimmed = value.trim().replace(/\/+$/, "");
|
|
43
43
|
if (!trimmed) return null;
|
|
@@ -83,19 +83,22 @@ window.__ModuleLoader__.load({
|
|
|
83
83
|
if (!res.ok) return {
|
|
84
84
|
hostMode: false,
|
|
85
85
|
subscriptionOrigin: null,
|
|
86
|
-
subscriptionApiBaseUrl: null
|
|
86
|
+
subscriptionApiBaseUrl: null,
|
|
87
|
+
profileUrl: null
|
|
87
88
|
};
|
|
88
89
|
const body = await res.json();
|
|
89
90
|
return {
|
|
90
91
|
hostMode: body.hostMode === true,
|
|
91
|
-
subscriptionOrigin:
|
|
92
|
-
subscriptionApiBaseUrl:
|
|
92
|
+
subscriptionOrigin: normalizeHttpUrl(body.subscriptionOrigin),
|
|
93
|
+
subscriptionApiBaseUrl: normalizeHttpUrl(body.subscriptionApiBaseUrl),
|
|
94
|
+
profileUrl: normalizeHttpUrl(body.profileUrl)
|
|
93
95
|
};
|
|
94
96
|
} catch {
|
|
95
97
|
return {
|
|
96
98
|
hostMode: false,
|
|
97
99
|
subscriptionOrigin: null,
|
|
98
|
-
subscriptionApiBaseUrl: null
|
|
100
|
+
subscriptionApiBaseUrl: null,
|
|
101
|
+
profileUrl: null
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
104
|
},
|
|
@@ -148,7 +151,11 @@ window.__ModuleLoader__.load({
|
|
|
148
151
|
}
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
|
-
|
|
154
|
+
/** Standalone-DSH fallback for the「Go to profile」destination. Under HQ Edge the full URL is
|
|
155
|
+
* resolved ONCE from `HQ_AI_ENV` (PROD: `https://www.eda.cn/account/profile`,
|
|
156
|
+
* TEST: `http://www.fdatasheets.com/account`) and arrives via the node half's
|
|
157
|
+
* `/config` route; this constant is used only when nothing supplies one.
|
|
158
|
+
*/
|
|
152
159
|
const PROFILE_URL = "https://www.eda.cn/account/profile";
|
|
153
160
|
const SUBSCRIPTION_PATH = "/subscription";
|
|
154
161
|
const SUBSCRIPTION_PREFERRED_SIZE = {
|
|
@@ -238,15 +245,16 @@ window.__ModuleLoader__.load({
|
|
|
238
245
|
* in the query, mirroring `hq-eda-ai`'s `UserMenu`
|
|
239
246
|
* (`/account/profile?token=…&phone=…`).
|
|
240
247
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
248
|
+
* `profileUrl` comes from the node half (HQ Edge → `HQ_AI_ENV`); omitted in
|
|
249
|
+
* standalone DSH, which keeps the {@link PROFILE_URL} PROD fallback. The
|
|
250
|
+
* injected value is a FULL URL (path included), because PROD and TEST do not
|
|
251
|
+
* share it (`/account/profile` vs `/account`); any existing query string on it
|
|
252
|
+
* is preserved and `token`/`phone` are appended.
|
|
246
253
|
*/
|
|
247
254
|
function buildProfileUrl(options) {
|
|
248
255
|
const phone = options.phone === void 0 || options.phone === null ? "" : String(options.phone);
|
|
249
|
-
|
|
256
|
+
const base = options.profileUrl?.length ? options.profileUrl : PROFILE_URL;
|
|
257
|
+
return `${base}${base.includes("?") ? "&" : "?"}token=${encodeURIComponent(options.token)}&phone=${encodeURIComponent(phone)}`;
|
|
250
258
|
}
|
|
251
259
|
/**
|
|
252
260
|
* Contract version of the auth.eda.cn embed, shared with the web app
|
|
@@ -1074,6 +1082,11 @@ window.__ModuleLoader__.load({
|
|
|
1074
1082
|
* when no environment is configured → GEN/ERC quota calls are skipped.
|
|
1075
1083
|
*/
|
|
1076
1084
|
let subscriptionApiBaseUrl = null;
|
|
1085
|
+
/**
|
|
1086
|
+
*「Go to profile」URL resolved by HQ Edge from `HQ_AI_ENV`. Null in
|
|
1087
|
+
* standalone → lib.ts keeps its PROD fallback.
|
|
1088
|
+
*/
|
|
1089
|
+
let profileUrl = null;
|
|
1077
1090
|
const emit = (info) => {
|
|
1078
1091
|
for (const listener of listeners) listener(info);
|
|
1079
1092
|
};
|
|
@@ -1171,6 +1184,7 @@ window.__ModuleLoader__.load({
|
|
|
1171
1184
|
...subscriptionApiBaseUrl ? { baseUrl: subscriptionApiBaseUrl } : {}
|
|
1172
1185
|
});
|
|
1173
1186
|
},
|
|
1187
|
+
getProfileUrl: () => profileUrl,
|
|
1174
1188
|
getAiTokenUsage: async () => {
|
|
1175
1189
|
if (hostMode && !hostSessionLoaded) await resolveHost();
|
|
1176
1190
|
if (!await auth.getAccessToken()) return null;
|
|
@@ -1255,10 +1269,12 @@ window.__ModuleLoader__.load({
|
|
|
1255
1269
|
mode = runtime.hostMode;
|
|
1256
1270
|
subscriptionOrigin = runtime.subscriptionOrigin;
|
|
1257
1271
|
subscriptionApiBaseUrl = runtime.subscriptionApiBaseUrl;
|
|
1272
|
+
profileUrl = runtime.profileUrl;
|
|
1258
1273
|
} catch {
|
|
1259
1274
|
mode = false;
|
|
1260
1275
|
subscriptionOrigin = null;
|
|
1261
1276
|
subscriptionApiBaseUrl = null;
|
|
1277
|
+
profileUrl = null;
|
|
1262
1278
|
}
|
|
1263
1279
|
hostMode = mode;
|
|
1264
1280
|
hostSessionLoaded = false;
|
|
@@ -1296,6 +1312,7 @@ window.__ModuleLoader__.load({
|
|
|
1296
1312
|
hostSessionLoaded = false;
|
|
1297
1313
|
subscriptionOrigin = null;
|
|
1298
1314
|
subscriptionApiBaseUrl = null;
|
|
1315
|
+
profileUrl = null;
|
|
1299
1316
|
}
|
|
1300
1317
|
};
|
|
1301
1318
|
}
|
|
@@ -2192,7 +2209,11 @@ window.__ModuleLoader__.load({
|
|
|
2192
2209
|
phone: i.phone
|
|
2193
2210
|
} : null).catch(() => null);
|
|
2194
2211
|
if (!info?.token) return;
|
|
2195
|
-
|
|
2212
|
+
const profileUrl = auth.getProfileUrl();
|
|
2213
|
+
window.open(buildProfileUrl({
|
|
2214
|
+
...info,
|
|
2215
|
+
...profileUrl ? { profileUrl } : {}
|
|
2216
|
+
}), "_blank", "noopener,noreferrer");
|
|
2196
2217
|
})();
|
|
2197
2218
|
};
|
|
2198
2219
|
const label = authenticated ? displayName ?? t("sidebar.account") : t("sidebar.login");
|