@longzai-intelligence-auth/ws 0.1.0

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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @longzai-intelligence-auth/ws
2
+
3
+ Auth 项目的 WebSocket 传输认证包,为 WebSocket 升级握手场景提供握手级认证器,绑定认证核心的传输认证契约。
4
+
5
+ ## 定位
6
+
7
+ 位于 Auth 项目 transports 传输层,依赖 core 契约层与 credential 载体能力层。复用 credential 的共享认证编排,并提供 WS 特有的握手拒绝编排(失败响应构建与关闭码)。仅负责握手级认证,连接级生命周期属应用层。
8
+
9
+ ## 核心能力
10
+
11
+ 提供 WebSocket 传输认证器工厂;提供握手认证失败响应构建工具与关闭码;服务浏览器 WebSocket query parameter 凭证场景。
12
+
13
+ ## 实现情况
14
+
15
+ 已实现 WebSocket 传输认证器与失败响应工具并统一导出,承载单元与 e2e 测试(含真实 WS 握手验证),随传输协议扩展持续补充对应能力。
@@ -0,0 +1,33 @@
1
+ import { AuthOrchestrationOptions, TransportAuthResult, TransportAuthenticator } from "@longzai-intelligence-auth/core";
2
+ //#region src/index.d.ts
3
+ /**
4
+ * WebSocket 认证失败的常用关闭码
5
+ *
6
+ * 当握手认证启用且凭证无效或缺失时使用。
7
+ */
8
+ declare const WS_AUTH_CLOSE_CODE = 4001;
9
+ /**
10
+ * WebSocket 传输认证器配置
11
+ */
12
+ type WsAuthenticatorOptions = AuthOrchestrationOptions;
13
+ /**
14
+ * 构建 WebSocket 认证失败的 HTTP 响应
15
+ *
16
+ * 在 WS 升级握手阶段(beforeHandle)认证失败时,返回 HTTP 401 拒绝升级,
17
+ * 响应体携带关闭码与错误信息,供客户端识别认证失败。
18
+ *
19
+ * @param result - 认证失败结果
20
+ * @returns HTTP 401 响应(响应体含关闭码与错误信息)
21
+ */
22
+ declare function buildWsAuthFailureResponse(result: Extract<TransportAuthResult, {
23
+ success: false;
24
+ }>): Response;
25
+ /**
26
+ * 创建 WebSocket 传输认证器
27
+ *
28
+ * @param options - WebSocket 传输认证器配置
29
+ * @returns 实现 TransportAuthenticator 的 WS 认证器
30
+ */
31
+ declare function createWsAuthenticator(options: WsAuthenticatorOptions): TransportAuthenticator;
32
+ //#endregion
33
+ export { WS_AUTH_CLOSE_CODE, WsAuthenticatorOptions, buildWsAuthFailureResponse, createWsAuthenticator };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{orchestrateAuth as e}from"@longzai-intelligence-auth/core";const t=4001,n={missing:4001,invalid:4001,expired:4001,forbidden:4003};function r(e){let t=n[e.reason]??4001;return new Response(JSON.stringify({code:t,message:e.error}),{status:401,headers:{"Content-Type":`application/json`}})}function i(t){return{async authenticate(n){return e(n,t)}}}export{t as WS_AUTH_CLOSE_CODE,r as buildWsAuthFailureResponse,i as createWsAuthenticator};
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@longzai-intelligence-auth/ws",
3
+ "version": "0.1.0",
4
+ "license": "UNLICENSED",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "lzi-builder",
23
+ "build:prod": "NODE_ENV=production bun run build",
24
+ "prepublishOnly": "bun run build:prod",
25
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
26
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
27
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
28
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
29
+ "lint": "oxlint && oxfmt --check",
30
+ "lint:fix": "oxlint --fix && oxfmt",
31
+ "test": "bun test",
32
+ "test:watch": "bun test --watch",
33
+ "test:coverage": "bun test --coverage",
34
+ "test:unit": "bun test src/__tests__/unit/",
35
+ "test:integration": "bun test src/__tests__/integration/",
36
+ "clean": "lzi-dev-cli clean"
37
+ },
38
+ "dependencies": {
39
+ "@longzai-intelligence-auth/core": "0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@longzai-intelligence-auth/bearer-jwt-strategy": "0.1.0",
43
+ "@longzai-intelligence-auth/credential": "0.1.0",
44
+ "@longzai-intelligence-auth/jwt": "0.1.0"
45
+ }
46
+ }