@huaqiu/dsh-auth 0.3.12 → 0.3.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/lib/index.mjs +19 -19
- package/package.json +2 -2
- package/src/host.ts +18 -7
- package/src/index.ts +8 -4
- package/src/routes.ts +4 -4
- package/src/service.ts +14 -7
package/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLogger } from "@huaqiu/dsh-plugin-log";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
|
|
@@ -26,7 +26,7 @@ import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
|
|
|
26
26
|
*/
|
|
27
27
|
let _log = null;
|
|
28
28
|
function log$1() {
|
|
29
|
-
if (_log === null) _log =
|
|
29
|
+
if (_log === null) _log = getLogger("dsh-auth");
|
|
30
30
|
return _log;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -102,10 +102,10 @@ var HostSessionResolver = class {
|
|
|
102
102
|
status = res.status;
|
|
103
103
|
if (res.ok) info = normalizeHostUser(await res.json());
|
|
104
104
|
} catch (err) {
|
|
105
|
-
log$1().warn({
|
|
105
|
+
log$1().warn("host session fetch failed", {
|
|
106
106
|
url,
|
|
107
107
|
error: String(err)
|
|
108
|
-
}
|
|
108
|
+
});
|
|
109
109
|
info = null;
|
|
110
110
|
}
|
|
111
111
|
if (info !== null && info.authenticated) {
|
|
@@ -113,22 +113,22 @@ var HostSessionResolver = class {
|
|
|
113
113
|
info,
|
|
114
114
|
fetchedAt: now
|
|
115
115
|
};
|
|
116
|
-
log$1().debug({
|
|
116
|
+
log$1().debug("host session resolved", {
|
|
117
117
|
url,
|
|
118
118
|
status,
|
|
119
119
|
userId: info.id,
|
|
120
120
|
version: info.version ?? null,
|
|
121
121
|
authenticated: info.authenticated
|
|
122
|
-
}
|
|
122
|
+
});
|
|
123
123
|
return info;
|
|
124
124
|
}
|
|
125
125
|
this.cache = null;
|
|
126
|
-
log$1().info({
|
|
126
|
+
log$1().info("no usable host session", {
|
|
127
127
|
url,
|
|
128
128
|
status,
|
|
129
129
|
parsed: info !== null,
|
|
130
130
|
hostAuthenticated: info?.authenticated ?? null
|
|
131
|
-
}
|
|
131
|
+
});
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
134
|
/** Drop the cached value so the next `resolve()` re-fetches (reactive invalidation). */
|
|
@@ -381,7 +381,7 @@ var InMemoryHuaqiuAuthService = class {
|
|
|
381
381
|
lastHostVersion = null;
|
|
382
382
|
_log = null;
|
|
383
383
|
get log() {
|
|
384
|
-
if (this._log === null) this._log =
|
|
384
|
+
if (this._log === null) this._log = getLogger("dsh-auth");
|
|
385
385
|
return this._log;
|
|
386
386
|
}
|
|
387
387
|
constructor(config, opts) {
|
|
@@ -395,11 +395,11 @@ var InMemoryHuaqiuAuthService = class {
|
|
|
395
395
|
fetchImpl: this.doFetch
|
|
396
396
|
});
|
|
397
397
|
this.hostMode = this.host.enabled;
|
|
398
|
-
this.log.info({
|
|
398
|
+
this.log.info("auth service started", {
|
|
399
399
|
hostMode: this.hostMode,
|
|
400
400
|
hostAuthPath: resolved.hostAuthPath,
|
|
401
401
|
hostSessionTtlSeconds: resolved.hostSessionTtlSeconds
|
|
402
|
-
}
|
|
402
|
+
});
|
|
403
403
|
}
|
|
404
404
|
/** Host mode is active iff a host base URL was configured (see HostSessionResolver.enabled). */
|
|
405
405
|
hostMode;
|
|
@@ -450,10 +450,10 @@ var InMemoryHuaqiuAuthService = class {
|
|
|
450
450
|
if (this.host.enabled) {
|
|
451
451
|
const host = await this.host.resolve();
|
|
452
452
|
if (!host || !host.authenticated) {
|
|
453
|
-
this.log.debug({
|
|
453
|
+
this.log.debug("host session unusable", {
|
|
454
454
|
hostReachable: host !== null,
|
|
455
455
|
hostAuthenticated: host?.authenticated ?? null
|
|
456
|
-
}
|
|
456
|
+
});
|
|
457
457
|
return null;
|
|
458
458
|
}
|
|
459
459
|
this.observeHostVersion(host.version);
|
|
@@ -476,7 +476,7 @@ var InMemoryHuaqiuAuthService = class {
|
|
|
476
476
|
if (this.lastHostVersion !== null && version !== this.lastHostVersion) {
|
|
477
477
|
this.stale = false;
|
|
478
478
|
this.validator.invalidate();
|
|
479
|
-
this.log.info(
|
|
479
|
+
this.log.info("host credential replaced — re-arming session", { version });
|
|
480
480
|
}
|
|
481
481
|
this.lastHostVersion = version;
|
|
482
482
|
}
|
|
@@ -656,7 +656,7 @@ function createAuthHandler(service) {
|
|
|
656
656
|
}
|
|
657
657
|
//#endregion
|
|
658
658
|
//#region src/index.ts
|
|
659
|
-
const log =
|
|
659
|
+
const log = getLogger("dsh-auth");
|
|
660
660
|
const name = "@huaqiu/dsh-auth";
|
|
661
661
|
const inject = ["webServer"];
|
|
662
662
|
/**
|
|
@@ -668,11 +668,11 @@ const inject = ["webServer"];
|
|
|
668
668
|
* without a supervisor (spec §6.4).
|
|
669
669
|
*/
|
|
670
670
|
function apply(ctx, config) {
|
|
671
|
-
log.info({
|
|
671
|
+
log.info("applying dsh-auth node half", {
|
|
672
672
|
hasConfig: config != null,
|
|
673
673
|
configKeys: config != null ? Object.keys(config) : [],
|
|
674
674
|
hqEdgeBaseUrl: config?.hqEdgeBaseUrl ?? null
|
|
675
|
-
}
|
|
675
|
+
});
|
|
676
676
|
const service = new InMemoryHuaqiuAuthService(config);
|
|
677
677
|
ctx.effect(() => ctx.provide("huaqiuAuth", service));
|
|
678
678
|
ctx.effect(() => ctx.webServer.register({
|
|
@@ -680,10 +680,10 @@ function apply(ctx, config) {
|
|
|
680
680
|
path: AUTH_ROUTE_PREFIX,
|
|
681
681
|
handler: createAuthHandler(service)
|
|
682
682
|
}));
|
|
683
|
-
log.info({
|
|
683
|
+
log.info("dsh-auth node half ready", {
|
|
684
684
|
routes: AUTH_ROUTE_PREFIX,
|
|
685
685
|
hostMode: service.hostMode
|
|
686
|
-
}
|
|
686
|
+
});
|
|
687
687
|
}
|
|
688
688
|
//#endregion
|
|
689
689
|
export { AUTH_ROUTE_PREFIX, InMemoryHuaqiuAuthService, apply, createAuthHandler, inject, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.mjs",
|
|
6
6
|
"types": "./lib/index.d.mts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.0",
|
|
35
|
-
"@
|
|
35
|
+
"@huaqiu/dsh-plugin-log": "0.3.13"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"lib",
|
package/src/host.ts
CHANGED
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
* 4. null → tools return needs_auth
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import { getLogger, type PluginLogger } from '@huaqiu/dsh-plugin-log'
|
|
24
24
|
|
|
25
25
|
// Lazy so test suites that `vi.mock('@deepseek-ai/dsh-home-paths', …)` before
|
|
26
26
|
// the test's TMP constant is initialised don't trigger `dshHomePath('logs')` at
|
|
27
27
|
// module-load time. Every site goes through `log()` instead of holding a module
|
|
28
28
|
// reference to the logger.
|
|
29
|
-
let _log:
|
|
30
|
-
function log():
|
|
31
|
-
if (_log === null) _log =
|
|
29
|
+
let _log: PluginLogger | null = null
|
|
30
|
+
function log(): PluginLogger {
|
|
31
|
+
if (_log === null) _log = getLogger('dsh-auth')
|
|
32
32
|
return _log
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -170,20 +170,31 @@ export class HostSessionResolver {
|
|
|
170
170
|
}
|
|
171
171
|
} catch (err) {
|
|
172
172
|
// Network error: nothing usable right now.
|
|
173
|
-
log().warn({ url, error: String(err) }
|
|
173
|
+
log().warn('host session fetch failed', { url, error: String(err) })
|
|
174
174
|
info = null
|
|
175
175
|
}
|
|
176
176
|
if (info !== null && info.authenticated) {
|
|
177
177
|
this.cache = { info, fetchedAt: now }
|
|
178
178
|
// Never log the credential itself — id/version are enough to correlate
|
|
179
179
|
// this plugin with the HQ Edge log line that served it.
|
|
180
|
-
log().debug(
|
|
180
|
+
log().debug('host session resolved', {
|
|
181
|
+
url,
|
|
182
|
+
status,
|
|
183
|
+
userId: info.id,
|
|
184
|
+
version: info.version ?? null,
|
|
185
|
+
authenticated: info.authenticated,
|
|
186
|
+
})
|
|
181
187
|
return info
|
|
182
188
|
}
|
|
183
189
|
// Unusable (unreachable, unparseable, or the host says it has no
|
|
184
190
|
// credential). Drop the cache so the very next call re-asks the host.
|
|
185
191
|
this.cache = null
|
|
186
|
-
log().info(
|
|
192
|
+
log().info('no usable host session', {
|
|
193
|
+
url,
|
|
194
|
+
status,
|
|
195
|
+
parsed: info !== null,
|
|
196
|
+
hostAuthenticated: info?.authenticated ?? null,
|
|
197
|
+
})
|
|
187
198
|
return null
|
|
188
199
|
}
|
|
189
200
|
|
package/src/index.ts
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Context } from '@deepseek-ai/cordis'
|
|
8
8
|
import type {} from '@deepseek-ai/dsh-host-webserver'
|
|
9
|
-
import {
|
|
9
|
+
import { getLogger } from '@huaqiu/dsh-plugin-log'
|
|
10
10
|
import { InMemoryHuaqiuAuthService, type HuaqiuAuthService } from './service.js'
|
|
11
11
|
import { AUTH_ROUTE_PREFIX, createAuthHandler } from './routes.js'
|
|
12
12
|
import type { HuaqiuAuthConfig } from './host.js'
|
|
13
13
|
|
|
14
|
-
const log =
|
|
14
|
+
const log = getLogger('dsh-auth')
|
|
15
15
|
|
|
16
16
|
export type { HuaqiuAuthApi, HuaqiuAuthService, HuaqiuUserInfo } from './service.js'
|
|
17
17
|
export { InMemoryHuaqiuAuthService } from './service.js'
|
|
@@ -40,7 +40,11 @@ export function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void {
|
|
|
40
40
|
// it proves whether the overlay `config` still reached `apply(ctx, config)`.
|
|
41
41
|
// When `hostMode` is false under HQ Edge, the endpoint was not delivered and
|
|
42
42
|
// every tool will report `needs_auth` no matter what the browser does.
|
|
43
|
-
log.info(
|
|
43
|
+
log.info('applying dsh-auth node half', {
|
|
44
|
+
hasConfig: config != null,
|
|
45
|
+
configKeys: config != null ? Object.keys(config) : [],
|
|
46
|
+
hqEdgeBaseUrl: config?.hqEdgeBaseUrl ?? null,
|
|
47
|
+
})
|
|
44
48
|
|
|
45
49
|
const service = new InMemoryHuaqiuAuthService(config)
|
|
46
50
|
ctx.effect(() => ctx.provide('huaqiuAuth', service))
|
|
@@ -51,5 +55,5 @@ export function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void {
|
|
|
51
55
|
handler: createAuthHandler(service),
|
|
52
56
|
}))
|
|
53
57
|
|
|
54
|
-
log.info({ routes: AUTH_ROUTE_PREFIX, hostMode: service.hostMode }
|
|
58
|
+
log.info('dsh-auth node half ready', { routes: AUTH_ROUTE_PREFIX, hostMode: service.hostMode })
|
|
55
59
|
}
|
package/src/routes.ts
CHANGED
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
* the documented channel).
|
|
16
16
|
*/
|
|
17
17
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
18
|
-
import {
|
|
18
|
+
import { getLogger, type PluginLogger } from '@huaqiu/dsh-plugin-log'
|
|
19
19
|
import type { HuaqiuAuthService, HuaqiuUserInfo } from './service.js'
|
|
20
20
|
|
|
21
21
|
// Lazy so test suites that `vi.mock('@deepseek-ai/dsh-home-paths', …)` before
|
|
22
22
|
// their TMP constant is initialised don't trigger `dshHomePath('logs')` at
|
|
23
23
|
// module-load time.
|
|
24
|
-
let _log:
|
|
25
|
-
function log():
|
|
26
|
-
if (_log === null) _log =
|
|
24
|
+
let _log: PluginLogger | null = null
|
|
25
|
+
function log(): PluginLogger {
|
|
26
|
+
if (_log === null) _log = getLogger('dsh-auth')
|
|
27
27
|
return _log
|
|
28
28
|
}
|
|
29
29
|
|
package/src/service.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
24
24
|
import { join } from 'node:path'
|
|
25
25
|
import { dshHomePath } from '@deepseek-ai/dsh-home-paths'
|
|
26
|
-
import {
|
|
26
|
+
import { getLogger, type PluginLogger } from '@huaqiu/dsh-plugin-log'
|
|
27
27
|
import {
|
|
28
28
|
HostSessionResolver,
|
|
29
29
|
resolveHostConfig,
|
|
@@ -159,9 +159,9 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
159
159
|
private stale = false
|
|
160
160
|
/** Last host credential version seen; see `observeHostVersion`. */
|
|
161
161
|
private lastHostVersion: number | null = null
|
|
162
|
-
private _log:
|
|
163
|
-
private get log():
|
|
164
|
-
if (this._log === null) this._log =
|
|
162
|
+
private _log: PluginLogger | null = null
|
|
163
|
+
private get log(): PluginLogger {
|
|
164
|
+
if (this._log === null) this._log = getLogger('dsh-auth')
|
|
165
165
|
return this._log
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -184,7 +184,11 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
184
184
|
fetchImpl: this.doFetch,
|
|
185
185
|
})
|
|
186
186
|
this.hostMode = this.host.enabled
|
|
187
|
-
this.log.info(
|
|
187
|
+
this.log.info('auth service started', {
|
|
188
|
+
hostMode: this.hostMode,
|
|
189
|
+
hostAuthPath: resolved.hostAuthPath,
|
|
190
|
+
hostSessionTtlSeconds: resolved.hostSessionTtlSeconds,
|
|
191
|
+
})
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
/** Host mode is active iff a host base URL was configured (see HostSessionResolver.enabled). */
|
|
@@ -254,7 +258,10 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
254
258
|
if (this.host.enabled) {
|
|
255
259
|
const host = await this.host.resolve()
|
|
256
260
|
if (!host || !host.authenticated) {
|
|
257
|
-
this.log.debug(
|
|
261
|
+
this.log.debug('host session unusable', {
|
|
262
|
+
hostReachable: host !== null,
|
|
263
|
+
hostAuthenticated: host?.authenticated ?? null,
|
|
264
|
+
})
|
|
258
265
|
return null
|
|
259
266
|
}
|
|
260
267
|
this.observeHostVersion(host.version)
|
|
@@ -278,7 +285,7 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
278
285
|
if (this.lastHostVersion !== null && version !== this.lastHostVersion) {
|
|
279
286
|
this.stale = false
|
|
280
287
|
this.validator.invalidate()
|
|
281
|
-
this.log.info(
|
|
288
|
+
this.log.info('host credential replaced — re-arming session', { version })
|
|
282
289
|
}
|
|
283
290
|
this.lastHostVersion = version
|
|
284
291
|
}
|