@huaqiu/dsh-auth 0.3.2 → 0.3.6

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
@@ -1,4 +1,5 @@
1
1
  import { Context } from "@deepseek-ai/cordis";
2
+ import { IncomingMessage, ServerResponse } from "node:http";
2
3
  //#region src/host.d.ts
3
4
  /**
4
5
  * HQ Edge host mode for `dsh-auth`.
@@ -126,6 +127,48 @@ interface HuaqiuAuthService {
126
127
  */
127
128
  readonly hostMode: boolean;
128
129
  }
130
+ declare class InMemoryHuaqiuAuthService implements HuaqiuAuthService {
131
+ private current;
132
+ private listeners;
133
+ private readonly host;
134
+ private readonly validator;
135
+ /**
136
+ * True once the current credential has been rejected (API 401) or explicitly
137
+ * invalidated. Keeps the credential for recovery but makes `isAuthenticated()`
138
+ * short-circuit to false and forces a fresh remote validation next time.
139
+ */
140
+ private stale;
141
+ constructor(config?: Partial<HuaqiuAuthConfig> | null, opts?: {
142
+ fetchImpl?: typeof fetch;
143
+ });
144
+ /** Host mode is active iff a host base URL was configured (see HostSessionResolver.enabled). */
145
+ readonly hostMode: boolean;
146
+ readonly auth: HuaqiuAuthApi;
147
+ /**
148
+ * Spec §6.2 resolution order: host → pushed → persisted → null.
149
+ *
150
+ * Host mode is STRICT: an enabled host is the single source of truth. If the
151
+ * host yields no credential, the operator is unauthenticated — we must NOT
152
+ * fall back to a pushed/persisted credential left behind by an earlier
153
+ * standalone (auth.eda.cn) login. Otherwise a stale `~/.dsh/auth/session.json`
154
+ * would let the DSH plugins keep calling the backend while hq-edge itself has
155
+ * no auth info. The standalone fallbacks only apply when no host is configured.
156
+ */
157
+ private resolve;
158
+ /** Spec §7: resolve → local expiry → remote validation → update state. */
159
+ private validateInternal;
160
+ /** Validation-scoped invalidation: keep the credential, drop cached validity. */
161
+ private markStale;
162
+ setCredentials(info: HuaqiuUserInfo): void;
163
+ invalidate(): void;
164
+ private on;
165
+ private emit;
166
+ }
167
+ //#endregion
168
+ //#region src/routes.d.ts
169
+ declare const AUTH_ROUTE_PREFIX = "/api/v1/huaqiu/auth";
170
+ type AuthHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void> | void;
171
+ declare function createAuthHandler(service: HuaqiuAuthService): AuthHandler;
129
172
  //#endregion
130
173
  //#region src/index.d.ts
131
174
  declare const name = "@huaqiu/dsh-auth";
@@ -145,4 +188,4 @@ declare module '@deepseek-ai/cordis' {
145
188
  */
146
189
  declare function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void;
147
190
  //#endregion
148
- export { type HuaqiuAuthApi, type HuaqiuAuthConfig, type HuaqiuAuthService, type HuaqiuUserInfo, apply, inject, name };
191
+ export { AUTH_ROUTE_PREFIX, type AuthHandler, type HuaqiuAuthApi, type HuaqiuAuthConfig, type HuaqiuAuthService, type HuaqiuUserInfo, InMemoryHuaqiuAuthService, apply, createAuthHandler, inject, name };
package/lib/index.mjs CHANGED
@@ -494,4 +494,4 @@ function apply(ctx, config) {
494
494
  }));
495
495
  }
496
496
  //#endregion
497
- export { apply, inject, name };
497
+ 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.2",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "main": "./lib/index.mjs",
6
6
  "types": "./lib/index.d.mts",
@@ -42,10 +42,10 @@
42
42
  "access": "public"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/react": "^19.2.18",
46
- "@types/react-dom": "^19.2.5",
47
- "react": "^19.2.8",
48
- "react-dom": "^19.2.8"
45
+ "@types/react": "~18.3.1",
46
+ "@types/react-dom": "^18.3.5",
47
+ "react": "^18.3.1",
48
+ "react-dom": "^18.3.1"
49
49
  },
50
50
  "scripts": {
51
51
  "typecheck": "tsc --noEmit",
package/src/index.ts CHANGED
@@ -11,6 +11,8 @@ import { AUTH_ROUTE_PREFIX, createAuthHandler } from './routes.js'
11
11
  import type { HuaqiuAuthConfig } from './host.js'
12
12
 
13
13
  export type { HuaqiuAuthApi, HuaqiuAuthService, HuaqiuUserInfo } from './service.js'
14
+ export { InMemoryHuaqiuAuthService } from './service.js'
15
+ export { AUTH_ROUTE_PREFIX, createAuthHandler, type AuthHandler } from './routes.js'
14
16
  export type { HuaqiuAuthConfig } from './host.js'
15
17
 
16
18
  export const name = '@huaqiu/dsh-auth'