@huaqiu/dsh-auth 0.3.11 → 0.3.12
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 +7 -18
- package/src/index.ts +4 -8
- package/src/routes.ts +4 -4
- package/src/service.ts +7 -14
package/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLogger } from "@hqedge/logging";
|
|
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 = createLogger({ component: "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({
|
|
106
106
|
url,
|
|
107
107
|
error: String(err)
|
|
108
|
-
});
|
|
108
|
+
}, "host session fetch failed");
|
|
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({
|
|
117
117
|
url,
|
|
118
118
|
status,
|
|
119
119
|
userId: info.id,
|
|
120
120
|
version: info.version ?? null,
|
|
121
121
|
authenticated: info.authenticated
|
|
122
|
-
});
|
|
122
|
+
}, "host session resolved");
|
|
123
123
|
return info;
|
|
124
124
|
}
|
|
125
125
|
this.cache = null;
|
|
126
|
-
log$1().info(
|
|
126
|
+
log$1().info({
|
|
127
127
|
url,
|
|
128
128
|
status,
|
|
129
129
|
parsed: info !== null,
|
|
130
130
|
hostAuthenticated: info?.authenticated ?? null
|
|
131
|
-
});
|
|
131
|
+
}, "no usable host session");
|
|
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 = createLogger({ component: "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({
|
|
399
399
|
hostMode: this.hostMode,
|
|
400
400
|
hostAuthPath: resolved.hostAuthPath,
|
|
401
401
|
hostSessionTtlSeconds: resolved.hostSessionTtlSeconds
|
|
402
|
-
});
|
|
402
|
+
}, "auth service started");
|
|
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({
|
|
454
454
|
hostReachable: host !== null,
|
|
455
455
|
hostAuthenticated: host?.authenticated ?? null
|
|
456
|
-
});
|
|
456
|
+
}, "host session unusable");
|
|
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("host credential replaced — re-arming session"
|
|
479
|
+
this.log.info({ version }, "host credential replaced — re-arming session");
|
|
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 = createLogger({ component: "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({
|
|
672
672
|
hasConfig: config != null,
|
|
673
673
|
configKeys: config != null ? Object.keys(config) : [],
|
|
674
674
|
hqEdgeBaseUrl: config?.hqEdgeBaseUrl ?? null
|
|
675
|
-
});
|
|
675
|
+
}, "applying dsh-auth node half");
|
|
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({
|
|
684
684
|
routes: AUTH_ROUTE_PREFIX,
|
|
685
685
|
hostMode: service.hostMode
|
|
686
|
-
});
|
|
686
|
+
}, "dsh-auth node half ready");
|
|
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.12",
|
|
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
|
+
"@hqedge/logging": "^0.2.7"
|
|
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 { createLogger, type Logger } from '@hqedge/logging'
|
|
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: Logger | null = null
|
|
30
|
+
function log(): Logger {
|
|
31
|
+
if (_log === null) _log = createLogger({ component: 'dsh-auth' })
|
|
32
32
|
return _log
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -170,31 +170,20 @@ export class HostSessionResolver {
|
|
|
170
170
|
}
|
|
171
171
|
} catch (err) {
|
|
172
172
|
// Network error: nothing usable right now.
|
|
173
|
-
log().warn(
|
|
173
|
+
log().warn({ url, error: String(err) }, 'host session fetch failed')
|
|
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('host session resolved'
|
|
181
|
-
url,
|
|
182
|
-
status,
|
|
183
|
-
userId: info.id,
|
|
184
|
-
version: info.version ?? null,
|
|
185
|
-
authenticated: info.authenticated,
|
|
186
|
-
})
|
|
180
|
+
log().debug({ url, status, userId: info.id, version: info.version ?? null, authenticated: info.authenticated }, 'host session resolved')
|
|
187
181
|
return info
|
|
188
182
|
}
|
|
189
183
|
// Unusable (unreachable, unparseable, or the host says it has no
|
|
190
184
|
// credential). Drop the cache so the very next call re-asks the host.
|
|
191
185
|
this.cache = null
|
|
192
|
-
log().info('no usable host session'
|
|
193
|
-
url,
|
|
194
|
-
status,
|
|
195
|
-
parsed: info !== null,
|
|
196
|
-
hostAuthenticated: info?.authenticated ?? null,
|
|
197
|
-
})
|
|
186
|
+
log().info({ url, status, parsed: info !== null, hostAuthenticated: info?.authenticated ?? null }, 'no usable host session')
|
|
198
187
|
return null
|
|
199
188
|
}
|
|
200
189
|
|
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 { createLogger } from '@hqedge/logging'
|
|
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 = createLogger({ component: 'dsh-auth' })
|
|
15
15
|
|
|
16
16
|
export type { HuaqiuAuthApi, HuaqiuAuthService, HuaqiuUserInfo } from './service.js'
|
|
17
17
|
export { InMemoryHuaqiuAuthService } from './service.js'
|
|
@@ -40,11 +40,7 @@ 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('applying dsh-auth node half'
|
|
44
|
-
hasConfig: config != null,
|
|
45
|
-
configKeys: config != null ? Object.keys(config) : [],
|
|
46
|
-
hqEdgeBaseUrl: config?.hqEdgeBaseUrl ?? null,
|
|
47
|
-
})
|
|
43
|
+
log.info({ hasConfig: config != null, configKeys: config != null ? Object.keys(config) : [], hqEdgeBaseUrl: config?.hqEdgeBaseUrl ?? null }, 'applying dsh-auth node half')
|
|
48
44
|
|
|
49
45
|
const service = new InMemoryHuaqiuAuthService(config)
|
|
50
46
|
ctx.effect(() => ctx.provide('huaqiuAuth', service))
|
|
@@ -55,5 +51,5 @@ export function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void {
|
|
|
55
51
|
handler: createAuthHandler(service),
|
|
56
52
|
}))
|
|
57
53
|
|
|
58
|
-
log.info(
|
|
54
|
+
log.info({ routes: AUTH_ROUTE_PREFIX, hostMode: service.hostMode }, 'dsh-auth node half ready')
|
|
59
55
|
}
|
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 { createLogger, type Logger } from '@hqedge/logging'
|
|
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: Logger | null = null
|
|
25
|
+
function log(): Logger {
|
|
26
|
+
if (_log === null) _log = createLogger({ component: '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 { createLogger, type Logger } from '@hqedge/logging'
|
|
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: Logger | null = null
|
|
163
|
+
private get log(): Logger {
|
|
164
|
+
if (this._log === null) this._log = createLogger({ component: 'dsh-auth' })
|
|
165
165
|
return this._log
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -184,11 +184,7 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
184
184
|
fetchImpl: this.doFetch,
|
|
185
185
|
})
|
|
186
186
|
this.hostMode = this.host.enabled
|
|
187
|
-
this.log.info('auth service started'
|
|
188
|
-
hostMode: this.hostMode,
|
|
189
|
-
hostAuthPath: resolved.hostAuthPath,
|
|
190
|
-
hostSessionTtlSeconds: resolved.hostSessionTtlSeconds,
|
|
191
|
-
})
|
|
187
|
+
this.log.info({ hostMode: this.hostMode, hostAuthPath: resolved.hostAuthPath, hostSessionTtlSeconds: resolved.hostSessionTtlSeconds }, 'auth service started')
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
/** Host mode is active iff a host base URL was configured (see HostSessionResolver.enabled). */
|
|
@@ -258,10 +254,7 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
258
254
|
if (this.host.enabled) {
|
|
259
255
|
const host = await this.host.resolve()
|
|
260
256
|
if (!host || !host.authenticated) {
|
|
261
|
-
this.log.debug('host session unusable'
|
|
262
|
-
hostReachable: host !== null,
|
|
263
|
-
hostAuthenticated: host?.authenticated ?? null,
|
|
264
|
-
})
|
|
257
|
+
this.log.debug({ hostReachable: host !== null, hostAuthenticated: host?.authenticated ?? null }, 'host session unusable')
|
|
265
258
|
return null
|
|
266
259
|
}
|
|
267
260
|
this.observeHostVersion(host.version)
|
|
@@ -285,7 +278,7 @@ export class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
|
|
|
285
278
|
if (this.lastHostVersion !== null && version !== this.lastHostVersion) {
|
|
286
279
|
this.stale = false
|
|
287
280
|
this.validator.invalidate()
|
|
288
|
-
this.log.info('host credential replaced — re-arming session'
|
|
281
|
+
this.log.info({ version }, 'host credential replaced — re-arming session')
|
|
289
282
|
}
|
|
290
283
|
this.lastHostVersion = version
|
|
291
284
|
}
|