@simplysm/service-server 14.0.1 → 14.0.4
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 +109 -0
- package/dist/service-server.d.ts +0 -1
- package/dist/service-server.d.ts.map +1 -1
- package/dist/service-server.js +0 -4
- package/dist/service-server.js.map +1 -1
- package/dist/transport/socket/websocket-handler.d.ts +0 -4
- package/dist/transport/socket/websocket-handler.d.ts.map +1 -1
- package/dist/transport/socket/websocket-handler.js +0 -6
- package/dist/transport/socket/websocket-handler.js.map +1 -1
- package/docs/auth.md +71 -0
- package/docs/core.md +192 -0
- package/docs/legacy.md +21 -0
- package/docs/main.md +81 -0
- package/docs/protocol.md +31 -0
- package/docs/services.md +63 -0
- package/docs/transport.md +169 -0
- package/docs/types.md +31 -0
- package/docs/utilities.md +27 -0
- package/package.json +8 -7
- package/src/service-server.ts +0 -5
- package/src/transport/socket/websocket-handler.ts +0 -19
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @simplysm/service-server
|
|
2
|
+
|
|
3
|
+
Service server framework -- Fastify-based RPC server with WebSocket support, JWT authentication, service definitions, file upload/download, and built-in ORM/auto-update services.
|
|
4
|
+
|
|
5
|
+
Depends on `@simplysm/service-common` for shared protocol and types.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
| Export | Kind | Category | Docs |
|
|
10
|
+
|--------|------|----------|------|
|
|
11
|
+
| `ServiceServerOptions` | interface | Types | [docs/types.md](docs/types.md) |
|
|
12
|
+
| `AuthTokenPayload` | interface | Auth | [docs/auth.md](docs/auth.md) |
|
|
13
|
+
| `signJwt` | function | Auth | [docs/auth.md](docs/auth.md) |
|
|
14
|
+
| `verifyJwt` | function | Auth | [docs/auth.md](docs/auth.md) |
|
|
15
|
+
| `decodeJwt` | function | Auth | [docs/auth.md](docs/auth.md) |
|
|
16
|
+
| `ServiceContext` | interface | Core | [docs/core.md](docs/core.md) |
|
|
17
|
+
| `createServiceContext` | function | Core | [docs/core.md](docs/core.md) |
|
|
18
|
+
| `getServiceAuthPermissions` | function | Core | [docs/core.md](docs/core.md) |
|
|
19
|
+
| `auth` | function | Core | [docs/core.md](docs/core.md) |
|
|
20
|
+
| `ServiceDefinition` | interface | Core | [docs/core.md](docs/core.md) |
|
|
21
|
+
| `defineService` | function | Core | [docs/core.md](docs/core.md) |
|
|
22
|
+
| `ServiceMethods` | type | Core | [docs/core.md](docs/core.md) |
|
|
23
|
+
| `executeServiceMethod` | function | Core | [docs/core.md](docs/core.md) |
|
|
24
|
+
| `WebSocketHandler` | interface | Transport | [docs/transport.md](docs/transport.md) |
|
|
25
|
+
| `createWebSocketHandler` | function | Transport | [docs/transport.md](docs/transport.md) |
|
|
26
|
+
| `ServiceSocket` | interface | Transport | [docs/transport.md](docs/transport.md) |
|
|
27
|
+
| `createServiceSocket` | function | Transport | [docs/transport.md](docs/transport.md) |
|
|
28
|
+
| `handleHttpRequest` | function | Transport | [docs/transport.md](docs/transport.md) |
|
|
29
|
+
| `handleUpload` | function | Transport | [docs/transport.md](docs/transport.md) |
|
|
30
|
+
| `handleStaticFile` | function | Transport | [docs/transport.md](docs/transport.md) |
|
|
31
|
+
| `ServerProtocolWrapper` | interface | Protocol | [docs/protocol.md](docs/protocol.md) |
|
|
32
|
+
| `createServerProtocolWrapper` | function | Protocol | [docs/protocol.md](docs/protocol.md) |
|
|
33
|
+
| `OrmService` | const | Services | [docs/services.md](docs/services.md) |
|
|
34
|
+
| `OrmServiceType` | type | Services | [docs/services.md](docs/services.md) |
|
|
35
|
+
| `AutoUpdateService` | const | Services | [docs/services.md](docs/services.md) |
|
|
36
|
+
| `AutoUpdateServiceType` | type | Services | [docs/services.md](docs/services.md) |
|
|
37
|
+
| `getConfig` | function | Utilities | [docs/utilities.md](docs/utilities.md) |
|
|
38
|
+
| `handleV1Connection` | function | Legacy | [docs/legacy.md](docs/legacy.md) |
|
|
39
|
+
| `ServiceServer` | class | Main | [docs/main.md](docs/main.md) |
|
|
40
|
+
| `createServiceServer` | function | Main | [docs/main.md](docs/main.md) |
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Basic Server Setup
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createServiceServer, defineService, auth } from "@simplysm/service-server";
|
|
48
|
+
|
|
49
|
+
// Define a service
|
|
50
|
+
const GreetService = defineService("Greet", (ctx) => ({
|
|
51
|
+
hello(name: string) {
|
|
52
|
+
return `Hello, ${name}!`;
|
|
53
|
+
},
|
|
54
|
+
// Protected method requiring authentication
|
|
55
|
+
secret: auth(["admin"], (msg: string) => {
|
|
56
|
+
return `Secret for ${ctx.authInfo}: ${msg}`;
|
|
57
|
+
}),
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
// Create and start the server
|
|
61
|
+
const server = createServiceServer({
|
|
62
|
+
rootPath: process.cwd(),
|
|
63
|
+
port: 3000,
|
|
64
|
+
auth: { jwtSecret: "my-secret" },
|
|
65
|
+
services: [GreetService],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await server.listen();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### JWT Authentication
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { signJwt, verifyJwt } from "@simplysm/service-server";
|
|
75
|
+
|
|
76
|
+
// Sign a token
|
|
77
|
+
const token = await signJwt("my-secret", {
|
|
78
|
+
roles: ["admin"],
|
|
79
|
+
data: { userId: 1 },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Verify a token
|
|
83
|
+
const payload = await verifyJwt("my-secret", token);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Event Broadcasting
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { defineEvent } from "@simplysm/service-common";
|
|
90
|
+
|
|
91
|
+
const NotifyEvent = defineEvent<{ userId: number }, { text: string }>("Notify");
|
|
92
|
+
|
|
93
|
+
// Emit from server
|
|
94
|
+
await server.emitEvent(NotifyEvent, (info) => info.userId === 42, { text: "Hello!" });
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### ORM Service
|
|
98
|
+
|
|
99
|
+
The server includes a built-in `OrmService` for database operations. Include it in your service list:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { createServiceServer, OrmService } from "@simplysm/service-server";
|
|
103
|
+
|
|
104
|
+
const server = createServiceServer({
|
|
105
|
+
rootPath: process.cwd(),
|
|
106
|
+
port: 3000,
|
|
107
|
+
services: [OrmService],
|
|
108
|
+
});
|
|
109
|
+
```
|
package/dist/service-server.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class ServiceServer<TAuthInfo = unknown> extends EventEmitter<{
|
|
|
16
16
|
constructor(options: ServiceServerOptions);
|
|
17
17
|
listen(): Promise<void>;
|
|
18
18
|
close(): Promise<void>;
|
|
19
|
-
broadcastReload(clientName: string | undefined, changedFileSet: Set<string>): Promise<void>;
|
|
20
19
|
emitEvent<TInfo, TData>(eventDef: ServiceEventDef<TInfo, TData>, infoSelector: (item: TInfo) => boolean, data: TData): Promise<void>;
|
|
21
20
|
signAuthToken(payload: AuthTokenPayload<TAuthInfo>): Promise<string>;
|
|
22
21
|
verifyAuthToken(token: string): Promise<AuthTokenPayload<TAuthInfo>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-server.d.ts","sourceRoot":"","sources":["..\\src\\service-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,EAAQ,YAAY,EAAO,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,SAAS,CAAC;AAa/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAOnE,qBAAa,aAAa,CAAC,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AAI,OAAO,CAAC,IAAI,CAAC;IAsJvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,SAAS,CAAC,KAAK,EAAE,KAAK,EAC1B,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,EACtC,IAAI,EAAE,KAAK;IAKP,aAAa,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;IAKlD,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAK1E,OAAO,CAAC,yBAAyB;CA4BlC;AAED,wBAAgB,mBAAmB,CAAC,SAAS,GAAG,OAAO,EACrD,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAAC,SAAS,CAAC,CAE1B"}
|
package/dist/service-server.js
CHANGED
|
@@ -160,10 +160,6 @@ export class ServiceServer extends EventEmitter {
|
|
|
160
160
|
logger.debug("서버 종료됨");
|
|
161
161
|
this.emit("close");
|
|
162
162
|
}
|
|
163
|
-
async broadcastReload(clientName, changedFileSet) {
|
|
164
|
-
logger.debug("모든 서버 클라이언트에 RELOAD 브로드캐스팅");
|
|
165
|
-
await this._wsHandler.broadcastReload(clientName, changedFileSet);
|
|
166
|
-
}
|
|
167
163
|
async emitEvent(eventDef, infoSelector, data) {
|
|
168
164
|
await this._wsHandler.emit(eventDef, infoSelector, data);
|
|
169
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-server.js","sourceRoot":"","sources":["..\\src\\service-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE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CAAC;AAC/C,CAAC"}
|
|
@@ -17,10 +17,6 @@ export interface WebSocketHandler {
|
|
|
17
17
|
* 모든 활성 연결을 닫는다
|
|
18
18
|
*/
|
|
19
19
|
closeAll(): void;
|
|
20
|
-
/**
|
|
21
|
-
* 모든 클라이언트에 리로드 메시지를 브로드캐스트한다
|
|
22
|
-
*/
|
|
23
|
-
broadcastReload(clientName: string | undefined, changedFileSet: Set<string>): Promise<void>;
|
|
24
20
|
/**
|
|
25
21
|
* 매칭되는 클라이언트에 이벤트를 발생시킨다
|
|
26
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-handler.d.ts","sourceRoot":"","sources":["..\\..\\..\\src\\transport\\socket\\websocket-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAK9C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAElG;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;IAEjB;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"websocket-handler.d.ts","sourceRoot":"","sources":["..\\..\\..\\src\\transport\\socket\\websocket-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAK9C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAElG;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,KAAK,EACf,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,EACtC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,CAAC,GAAG,EAAE;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,KAAK,OAAO,CAAC,OAAO,CAAC,EACtB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,gBAAgB,CAmLlB"}
|
|
@@ -136,12 +136,6 @@ export function createWebSocketHandler(runMethod, jwtSecret) {
|
|
|
136
136
|
serviceSocket.close();
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
|
-
async broadcastReload(clientName, changedFileSet) {
|
|
140
|
-
await Promise.allSettled(Array.from(socketMap.values()).map((serviceSocket) => serviceSocket.send(Uuid.generate().toString(), {
|
|
141
|
-
name: "reload",
|
|
142
|
-
body: { clientName, changedFileSet },
|
|
143
|
-
})));
|
|
144
|
-
},
|
|
145
139
|
async emit(eventDef, infoSelector, data) {
|
|
146
140
|
const eventName = eventDef.eventName;
|
|
147
141
|
const targetKeys = Array.from(socketMap.values())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-handler.js","sourceRoot":"","sources":["..\\..\\..\\src\\transport\\socket\\websocket-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAsB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"websocket-handler.js","sourceRoot":"","sources":["..\\..\\..\\src\\transport\\socket\\websocket-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAsB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;AA6BlE;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAKsB,EACtB,SAA6B;IAE7B,sEAAsE;IACtE,KAAK;IACL,sEAAsE;IAEtE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEnD,sEAAsE;IACtE,KAAK;IACL,sEAAsE;IAEtE,KAAK,UAAU,cAAc,CAC3B,aAA4B,EAC5B,IAAY,EACZ,OAA6B;QAE7B,IAAI,CAAC;YACH,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,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E,CAAC,QAAQ,EAAE,EAAE;wBAC7C,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;qBACpC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/docs/auth.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Auth
|
|
2
|
+
|
|
3
|
+
JWT authentication utilities for signing, verifying, and decoding tokens.
|
|
4
|
+
|
|
5
|
+
## AuthTokenPayload\<TAuthInfo\>
|
|
6
|
+
|
|
7
|
+
JWT token payload extending the standard `JWTPayload` with role-based access and custom data.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
interface AuthTokenPayload<TAuthInfo = unknown> extends JWTPayload {
|
|
11
|
+
roles: string[];
|
|
12
|
+
data: TAuthInfo;
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Field | Type | Description |
|
|
17
|
+
|-------|------|-------------|
|
|
18
|
+
| `roles` | `string[]` | Role names for permission checking |
|
|
19
|
+
| `data` | `TAuthInfo` | Custom authentication data (e.g., user info) |
|
|
20
|
+
|
|
21
|
+
Inherits all standard JWT fields from `JWTPayload` (e.g., `iss`, `sub`, `aud`, `exp`, `nbf`, `iat`, `jti`).
|
|
22
|
+
|
|
23
|
+
## signJwt
|
|
24
|
+
|
|
25
|
+
Sign a JWT token with the given secret and payload.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
async function signJwt<TAuthInfo = unknown>(
|
|
29
|
+
jwtSecret: string,
|
|
30
|
+
payload: AuthTokenPayload<TAuthInfo>,
|
|
31
|
+
): Promise<string>;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Parameter | Type | Description |
|
|
35
|
+
|-----------|------|-------------|
|
|
36
|
+
| `jwtSecret` | `string` | Secret key for signing |
|
|
37
|
+
| `payload` | `AuthTokenPayload<TAuthInfo>` | Token payload with roles and data |
|
|
38
|
+
|
|
39
|
+
Returns the signed JWT string.
|
|
40
|
+
|
|
41
|
+
## verifyJwt
|
|
42
|
+
|
|
43
|
+
Verify a JWT token and return its payload. Throws if the token is invalid or expired.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
async function verifyJwt<TAuthInfo = unknown>(
|
|
47
|
+
jwtSecret: string,
|
|
48
|
+
token: string,
|
|
49
|
+
): Promise<AuthTokenPayload<TAuthInfo>>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
|-----------|------|-------------|
|
|
54
|
+
| `jwtSecret` | `string` | Secret key for verification |
|
|
55
|
+
| `token` | `string` | JWT token string |
|
|
56
|
+
|
|
57
|
+
Returns the decoded and verified `AuthTokenPayload`.
|
|
58
|
+
|
|
59
|
+
## decodeJwt
|
|
60
|
+
|
|
61
|
+
Decode a JWT token without verification. Useful for inspecting token contents without validating the signature.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
function decodeJwt<TAuthInfo = unknown>(token: string): AuthTokenPayload<TAuthInfo>;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
|-----------|------|-------------|
|
|
69
|
+
| `token` | `string` | JWT token string |
|
|
70
|
+
|
|
71
|
+
Returns the decoded `AuthTokenPayload` (unverified).
|
package/docs/core.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Core
|
|
2
|
+
|
|
3
|
+
Service definition, context, authentication wrapper, and method execution.
|
|
4
|
+
|
|
5
|
+
## ServiceContext\<TAuthInfo\>
|
|
6
|
+
|
|
7
|
+
Context object passed to service factory functions. Provides access to the server, socket, HTTP info, and authentication state.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
interface ServiceContext<TAuthInfo = unknown> {
|
|
11
|
+
server: ServiceServer<TAuthInfo>;
|
|
12
|
+
socket?: ServiceSocket;
|
|
13
|
+
http?: {
|
|
14
|
+
clientName: string;
|
|
15
|
+
authTokenPayload?: AuthTokenPayload<TAuthInfo>;
|
|
16
|
+
};
|
|
17
|
+
legacy?: {
|
|
18
|
+
clientName?: string;
|
|
19
|
+
};
|
|
20
|
+
get authInfo(): TAuthInfo | undefined;
|
|
21
|
+
get clientName(): string | undefined;
|
|
22
|
+
get clientPath(): string | undefined;
|
|
23
|
+
getConfig<T>(section: string): Promise<T>;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Member | Kind | Type | Description |
|
|
28
|
+
|--------|------|------|-------------|
|
|
29
|
+
| `server` | property | `ServiceServer<TAuthInfo>` | Reference to the server instance |
|
|
30
|
+
| `socket` | property | `ServiceSocket?` | WebSocket connection (present for WS calls) |
|
|
31
|
+
| `http` | property | `{ clientName; authTokenPayload? }?` | HTTP request info (present for HTTP calls) |
|
|
32
|
+
| `http.clientName` | field | `string` | Client identifier from HTTP header |
|
|
33
|
+
| `http.authTokenPayload` | field | `AuthTokenPayload<TAuthInfo>?` | Decoded auth token from HTTP request |
|
|
34
|
+
| `legacy` | property | `{ clientName? }?` | Legacy V1 connection info |
|
|
35
|
+
| `authInfo` | getter | `TAuthInfo \| undefined` | Authenticated user data (from socket or HTTP token) |
|
|
36
|
+
| `clientName` | getter | `string \| undefined` | Client name (from socket, HTTP, or legacy) |
|
|
37
|
+
| `clientPath` | getter | `string \| undefined` | Client path identifier |
|
|
38
|
+
| `getConfig` | method | `<T>(section: string) => Promise<T>` | Read a configuration section |
|
|
39
|
+
|
|
40
|
+
## createServiceContext
|
|
41
|
+
|
|
42
|
+
Create a `ServiceContext` instance.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
function createServiceContext<TAuthInfo = unknown>(
|
|
46
|
+
server: ServiceServer<TAuthInfo>,
|
|
47
|
+
socket?: ServiceSocket,
|
|
48
|
+
http?: { clientName: string; authTokenPayload?: AuthTokenPayload<TAuthInfo> },
|
|
49
|
+
legacy?: { clientName?: string },
|
|
50
|
+
): ServiceContext<TAuthInfo>;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Description |
|
|
54
|
+
|-----------|------|-------------|
|
|
55
|
+
| `server` | `ServiceServer<TAuthInfo>` | Server instance |
|
|
56
|
+
| `socket` | `ServiceSocket?` | WebSocket connection |
|
|
57
|
+
| `http` | `{ clientName; authTokenPayload? }?` | HTTP request context |
|
|
58
|
+
| `legacy` | `{ clientName? }?` | Legacy V1 context |
|
|
59
|
+
|
|
60
|
+
## auth
|
|
61
|
+
|
|
62
|
+
Authentication wrapper for service factories and methods. Marks a function as requiring authentication. Optionally restricts access to specific roles.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// No role restriction -- just requires authentication
|
|
66
|
+
function auth<TFunction extends (...args: any[]) => any>(fn: TFunction): TFunction;
|
|
67
|
+
|
|
68
|
+
// With role restriction
|
|
69
|
+
function auth<TFunction extends (...args: any[]) => any>(permissions: string[], fn: TFunction): TFunction;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Can be applied at the service level (wrapping the factory) or at individual method level.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const MyService = defineService("My", (ctx) => ({
|
|
76
|
+
// Public method -- no auth required
|
|
77
|
+
publicMethod() { return "open"; },
|
|
78
|
+
|
|
79
|
+
// Requires authentication (any role)
|
|
80
|
+
protectedMethod: auth(() => "protected"),
|
|
81
|
+
|
|
82
|
+
// Requires "admin" role
|
|
83
|
+
adminMethod: auth(["admin"], () => "admin only"),
|
|
84
|
+
}));
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## getServiceAuthPermissions
|
|
88
|
+
|
|
89
|
+
Read the authentication permissions from a function wrapped with `auth()`. Returns `undefined` if the function is not wrapped.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
function getServiceAuthPermissions(fn: Function): string[] | undefined;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
| Parameter | Type | Description |
|
|
96
|
+
|-----------|------|-------------|
|
|
97
|
+
| `fn` | `Function` | A potentially auth-wrapped function |
|
|
98
|
+
|
|
99
|
+
Returns `string[]` (role list, possibly empty for auth-only) or `undefined` (not wrapped).
|
|
100
|
+
|
|
101
|
+
## ServiceDefinition\<TMethods\>
|
|
102
|
+
|
|
103
|
+
A named service with a factory function and optional auth permissions.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
interface ServiceDefinition<TMethods = Record<string, (...args: any[]) => any>> {
|
|
107
|
+
name: string;
|
|
108
|
+
factory: (ctx: ServiceContext) => TMethods;
|
|
109
|
+
authPermissions?: string[];
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
| Field | Type | Description |
|
|
114
|
+
|-------|------|-------------|
|
|
115
|
+
| `name` | `string` | Service name used for RPC routing |
|
|
116
|
+
| `factory` | `(ctx: ServiceContext) => TMethods` | Factory function that creates service methods |
|
|
117
|
+
| `authPermissions` | `string[]?` | Service-level auth permissions (from `auth()` wrapper) |
|
|
118
|
+
|
|
119
|
+
## defineService
|
|
120
|
+
|
|
121
|
+
Define a named service from a factory function.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
function defineService<TMethods extends Record<string, (...args: any[]) => any>>(
|
|
125
|
+
name: string,
|
|
126
|
+
factory: (ctx: ServiceContext) => TMethods,
|
|
127
|
+
): ServiceDefinition<TMethods>;
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Parameter | Type | Description |
|
|
131
|
+
|-----------|------|-------------|
|
|
132
|
+
| `name` | `string` | Service name |
|
|
133
|
+
| `factory` | `(ctx: ServiceContext) => TMethods` | Factory that receives context and returns methods |
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const UserService = defineService("User", (ctx) => ({
|
|
137
|
+
async getUser(id: number) {
|
|
138
|
+
// ctx.authInfo, ctx.server, ctx.getConfig, etc.
|
|
139
|
+
return { id, name: "Alice" };
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## ServiceMethods\<TDefinition\>
|
|
145
|
+
|
|
146
|
+
Utility type that extracts method signatures from a `ServiceDefinition`. Useful for sharing types with the client.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
type ServiceMethods<TDefinition> = TDefinition extends ServiceDefinition<infer M> ? M : never;
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// Server
|
|
154
|
+
const UserService = defineService("User", (ctx) => ({
|
|
155
|
+
getUser(id: number) { return { id, name: "Alice" }; },
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
// Shared type for client
|
|
159
|
+
type UserServiceType = ServiceMethods<typeof UserService>;
|
|
160
|
+
|
|
161
|
+
// Client
|
|
162
|
+
const userSvc = client.getService<UserServiceType>("User");
|
|
163
|
+
const user = await userSvc.getUser(1); // typed as { id: number; name: string }
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## executeServiceMethod
|
|
167
|
+
|
|
168
|
+
Execute a service method by name. Used internally by the transport layer; can also be called directly for testing or custom routing.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
async function executeServiceMethod(
|
|
172
|
+
server: ServiceServer,
|
|
173
|
+
def: {
|
|
174
|
+
serviceName: string;
|
|
175
|
+
methodName: string;
|
|
176
|
+
params: unknown[];
|
|
177
|
+
socket?: ServiceSocket;
|
|
178
|
+
http?: { clientName: string; authTokenPayload?: AuthTokenPayload };
|
|
179
|
+
},
|
|
180
|
+
): Promise<unknown>;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
| Parameter | Type | Description |
|
|
184
|
+
|-----------|------|-------------|
|
|
185
|
+
| `server` | `ServiceServer` | Server instance containing registered services |
|
|
186
|
+
| `def.serviceName` | `string` | Name of the service to invoke |
|
|
187
|
+
| `def.methodName` | `string` | Method name within the service |
|
|
188
|
+
| `def.params` | `unknown[]` | Method arguments |
|
|
189
|
+
| `def.socket` | `ServiceSocket?` | WebSocket context (for WS calls) |
|
|
190
|
+
| `def.http` | `{ clientName; authTokenPayload? }?` | HTTP context (for HTTP calls) |
|
|
191
|
+
|
|
192
|
+
Returns the method return value.
|
package/docs/legacy.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Legacy
|
|
2
|
+
|
|
3
|
+
## handleV1Connection
|
|
4
|
+
|
|
5
|
+
V1 legacy client handler. Only supports auto-update requests; all other requests receive an upgrade-required error.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
function handleV1Connection(
|
|
9
|
+
socket: WebSocket,
|
|
10
|
+
autoUpdateMethods: { getLastVersion: (platform: string) => Promise<any> },
|
|
11
|
+
clientNameSetter?: (clientName: string | undefined) => void,
|
|
12
|
+
): void;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Parameter | Type | Description |
|
|
16
|
+
|-----------|------|-------------|
|
|
17
|
+
| `socket` | `WebSocket` | Raw WebSocket connection from the V1 client |
|
|
18
|
+
| `autoUpdateMethods` | `{ getLastVersion: (platform: string) => Promise<any> }` | Auto-update method implementation |
|
|
19
|
+
| `clientNameSetter` | `((clientName: string \| undefined) => void)?` | Optional callback invoked with the client name when connected (or `undefined` on disconnect) |
|
|
20
|
+
|
|
21
|
+
This handler is provided for backward compatibility with V1 protocol clients. New clients should use the V2 binary protocol.
|
package/docs/main.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Main
|
|
2
|
+
|
|
3
|
+
## ServiceServer\<TAuthInfo\>
|
|
4
|
+
|
|
5
|
+
Main server class. Extends `EventEmitter` with `ready` and `close` events. Manages Fastify, WebSocket connections, service routing, and event broadcasting.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
class ServiceServer<TAuthInfo = unknown> extends EventEmitter<{
|
|
9
|
+
ready: void;
|
|
10
|
+
close: void;
|
|
11
|
+
}> {
|
|
12
|
+
constructor(options: ServiceServerOptions);
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Events
|
|
17
|
+
|
|
18
|
+
| Event | Data Type | Description |
|
|
19
|
+
|-------|-----------|-------------|
|
|
20
|
+
| `ready` | `void` | Emitted when the server is listening and ready |
|
|
21
|
+
| `close` | `void` | Emitted when the server has shut down |
|
|
22
|
+
|
|
23
|
+
### Properties
|
|
24
|
+
|
|
25
|
+
| Property | Type | Description |
|
|
26
|
+
|----------|------|-------------|
|
|
27
|
+
| `isOpen` | `boolean` | Whether the server is currently listening |
|
|
28
|
+
| `fastify` | `FastifyInstance` | Underlying Fastify instance for advanced configuration |
|
|
29
|
+
| `options` | `ServiceServerOptions` | Server configuration options |
|
|
30
|
+
|
|
31
|
+
### Methods
|
|
32
|
+
|
|
33
|
+
| Method | Parameters | Return | Description |
|
|
34
|
+
|--------|-----------|--------|-------------|
|
|
35
|
+
| `listen` | -- | `Promise<void>` | Start the server and begin accepting connections |
|
|
36
|
+
| `close` | -- | `Promise<void>` | Gracefully shut down the server |
|
|
37
|
+
| `emitEvent` | `eventDef: ServiceEventDef<TInfo, TData>`, `infoSelector: (item: TInfo) => boolean`, `data: TData` | `Promise<void>` | Broadcast an event to matching listeners across all connected sockets |
|
|
38
|
+
| `signAuthToken` | `payload: AuthTokenPayload<TAuthInfo>` | `Promise<string>` | Sign a JWT token using the server's configured secret |
|
|
39
|
+
| `verifyAuthToken` | `token: string` | `Promise<AuthTokenPayload<TAuthInfo>>` | Verify and decode a JWT token |
|
|
40
|
+
|
|
41
|
+
### Usage
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createServiceServer, defineService } from "@simplysm/service-server";
|
|
45
|
+
|
|
46
|
+
const server = createServiceServer({
|
|
47
|
+
rootPath: process.cwd(),
|
|
48
|
+
port: 3000,
|
|
49
|
+
auth: { jwtSecret: "secret" },
|
|
50
|
+
services: [
|
|
51
|
+
defineService("Hello", () => ({
|
|
52
|
+
greet(name: string) { return `Hello, ${name}!`; },
|
|
53
|
+
})),
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
server.on("ready", () => {
|
|
58
|
+
// server is listening
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await server.listen();
|
|
62
|
+
|
|
63
|
+
// Later: shut down
|
|
64
|
+
await server.close();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## createServiceServer
|
|
68
|
+
|
|
69
|
+
Factory function to create a `ServiceServer` instance.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
function createServiceServer<TAuthInfo = unknown>(
|
|
73
|
+
options: ServiceServerOptions,
|
|
74
|
+
): ServiceServer<TAuthInfo>;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Parameter | Type | Description |
|
|
78
|
+
|-----------|------|-------------|
|
|
79
|
+
| `options` | `ServiceServerOptions` | Server configuration |
|
|
80
|
+
|
|
81
|
+
Returns a new `ServiceServer` instance. Call `listen()` to start accepting connections.
|
package/docs/protocol.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Protocol
|
|
2
|
+
|
|
3
|
+
Server-side protocol wrapper that automatically delegates heavy message encoding/decoding to worker threads.
|
|
4
|
+
|
|
5
|
+
## ServerProtocolWrapper
|
|
6
|
+
|
|
7
|
+
Protocol wrapper interface. Heavy messages are encoded/decoded in a worker thread; lightweight messages are processed on the main thread.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
interface ServerProtocolWrapper {
|
|
11
|
+
encode(uuid: string, message: ServiceMessage): Promise<{ chunks: Bytes[]; totalSize: number }>;
|
|
12
|
+
decode(bytes: Bytes): Promise<ServiceMessageDecodeResult<ServiceMessage>>;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
| Method | Parameters | Return | Description |
|
|
18
|
+
|--------|-----------|--------|-------------|
|
|
19
|
+
| `encode` | `uuid: string`, `message: ServiceMessage` | `Promise<{ chunks: Bytes[]; totalSize: number }>` | Encode a message into binary chunks |
|
|
20
|
+
| `decode` | `bytes: Bytes` | `Promise<ServiceMessageDecodeResult<ServiceMessage>>` | Decode received binary data |
|
|
21
|
+
| `dispose` | -- | `void` | Dispose the wrapper and terminate worker threads |
|
|
22
|
+
|
|
23
|
+
## createServerProtocolWrapper
|
|
24
|
+
|
|
25
|
+
Create a `ServerProtocolWrapper` instance.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
function createServerProtocolWrapper(): ServerProtocolWrapper;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Returns a new protocol wrapper with automatic worker thread delegation for heavy payloads.
|
package/docs/services.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Services
|
|
2
|
+
|
|
3
|
+
Built-in service definitions that can be included in `ServiceServerOptions.services`.
|
|
4
|
+
|
|
5
|
+
## OrmService
|
|
6
|
+
|
|
7
|
+
Built-in ORM service definition. Provides database connection management, transaction control, and query execution over the RPC layer. Supports MySQL, MSSQL, and PostgreSQL.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const OrmService: ServiceDefinition<{
|
|
11
|
+
getInfo(opt: DbConnOptions & { configName: string }): Promise<{ dialect: Dialect; database?: string; schema?: string }>;
|
|
12
|
+
connect(opt: DbConnOptions & { configName: string }): Promise<number>;
|
|
13
|
+
close(connId: number): Promise<void>;
|
|
14
|
+
beginTransaction(connId: number, isolationLevel?: IsolationLevel): Promise<void>;
|
|
15
|
+
commitTransaction(connId: number): Promise<void>;
|
|
16
|
+
rollbackTransaction(connId: number): Promise<void>;
|
|
17
|
+
executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
|
|
18
|
+
executeDefs(connId: number, defs: QueryDef[], options?: (ResultMeta | undefined)[]): Promise<unknown[][]>;
|
|
19
|
+
bulkInsert(connId: number, tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]): Promise<void>;
|
|
20
|
+
}>;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
| Method | Parameters | Return | Description |
|
|
24
|
+
|--------|-----------|--------|-------------|
|
|
25
|
+
| `getInfo` | `opt` | `Promise<{ dialect; database?; schema? }>` | Get database dialect and schema info |
|
|
26
|
+
| `connect` | `opt` | `Promise<number>` | Open a connection; returns connection ID |
|
|
27
|
+
| `close` | `connId` | `Promise<void>` | Close a connection |
|
|
28
|
+
| `beginTransaction` | `connId`, `isolationLevel?` | `Promise<void>` | Begin a transaction |
|
|
29
|
+
| `commitTransaction` | `connId` | `Promise<void>` | Commit the current transaction |
|
|
30
|
+
| `rollbackTransaction` | `connId` | `Promise<void>` | Rollback the current transaction |
|
|
31
|
+
| `executeParametrized` | `connId`, `query`, `params?` | `Promise<unknown[][]>` | Execute a parameterized SQL query |
|
|
32
|
+
| `executeDefs` | `connId`, `defs`, `options?` | `Promise<unknown[][]>` | Execute query definitions |
|
|
33
|
+
| `bulkInsert` | `connId`, `tableName`, `columnDefs`, `records` | `Promise<void>` | Bulk insert records into a table |
|
|
34
|
+
|
|
35
|
+
### OrmServiceType
|
|
36
|
+
|
|
37
|
+
Utility type for extracting ORM service method signatures.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
type OrmServiceType = ServiceMethods<typeof OrmService>;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## AutoUpdateService
|
|
44
|
+
|
|
45
|
+
Built-in auto-update service definition. Retrieves the latest version information for client applications by platform.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const AutoUpdateService: ServiceDefinition<{
|
|
49
|
+
getLastVersion(platform: string): Promise<{ version: string; downloadPath: string } | undefined>;
|
|
50
|
+
}>;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Method | Parameters | Return | Description |
|
|
54
|
+
|--------|-----------|--------|-------------|
|
|
55
|
+
| `getLastVersion` | `platform: string` | `Promise<{ version; downloadPath } \| undefined>` | Get latest version info for a platform |
|
|
56
|
+
|
|
57
|
+
### AutoUpdateServiceType
|
|
58
|
+
|
|
59
|
+
Utility type for extracting auto-update service method signatures.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
type AutoUpdateServiceType = ServiceMethods<typeof AutoUpdateService>;
|
|
63
|
+
```
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Transport
|
|
2
|
+
|
|
3
|
+
WebSocket and HTTP transport handlers for routing client messages to services.
|
|
4
|
+
|
|
5
|
+
## WebSocket Transport
|
|
6
|
+
|
|
7
|
+
### WebSocketHandler
|
|
8
|
+
|
|
9
|
+
Manages multiple WebSocket connections, routes messages to services, and handles event broadcasting.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface WebSocketHandler {
|
|
13
|
+
addSocket(socket: WebSocket, clientId: string, clientName: string, connReq: FastifyRequest): void;
|
|
14
|
+
closeAll(): void;
|
|
15
|
+
emit<TInfo, TData>(eventDef: ServiceEventDef<TInfo, TData>, infoSelector: (item: TInfo) => boolean, data: TData): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| Method | Parameters | Return | Description |
|
|
20
|
+
|--------|-----------|--------|-------------|
|
|
21
|
+
| `addSocket` | `socket: WebSocket`, `clientId: string`, `clientName: string`, `connReq: FastifyRequest` | `void` | Register a new WebSocket connection |
|
|
22
|
+
| `closeAll` | -- | `void` | Close all managed connections |
|
|
23
|
+
| `emit` | `eventDef`, `infoSelector`, `data` | `Promise<void>` | Broadcast an event to matching listeners across all sockets |
|
|
24
|
+
|
|
25
|
+
### createWebSocketHandler
|
|
26
|
+
|
|
27
|
+
Create a `WebSocketHandler` instance.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
function createWebSocketHandler(
|
|
31
|
+
runMethod: (def: {
|
|
32
|
+
serviceName: string;
|
|
33
|
+
methodName: string;
|
|
34
|
+
params: unknown[];
|
|
35
|
+
socket?: ServiceSocket;
|
|
36
|
+
}) => Promise<unknown>,
|
|
37
|
+
jwtSecret: string | undefined,
|
|
38
|
+
): WebSocketHandler;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Parameter | Type | Description |
|
|
42
|
+
|-----------|------|-------------|
|
|
43
|
+
| `runMethod` | `(def) => Promise<unknown>` | Callback to execute a service method |
|
|
44
|
+
| `jwtSecret` | `string \| undefined` | JWT secret for authenticating socket connections. `undefined` disables auth. |
|
|
45
|
+
|
|
46
|
+
### ServiceSocket
|
|
47
|
+
|
|
48
|
+
Represents a single WebSocket connection with protocol encoding/decoding, ping/pong keep-alive, and event listener tracking.
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
interface ServiceSocket {
|
|
52
|
+
readonly connectedAtDateTime: DateTime;
|
|
53
|
+
readonly clientName: string;
|
|
54
|
+
readonly connReq: FastifyRequest;
|
|
55
|
+
authTokenPayload?: AuthTokenPayload;
|
|
56
|
+
close(): void;
|
|
57
|
+
send(uuid: string, msg: ServiceServerMessage): Promise<number>;
|
|
58
|
+
addListener(key: string, eventName: string, info: unknown): void;
|
|
59
|
+
removeListener(key: string): void;
|
|
60
|
+
getEventListeners(eventName: string): Array<{ key: string; info: unknown }>;
|
|
61
|
+
filterEventTargetKeys(targetKeys: string[]): string[];
|
|
62
|
+
on(event: "error", handler: (err: Error) => void): void;
|
|
63
|
+
on(event: "close", handler: (code: number) => void): void;
|
|
64
|
+
on(event: "message", handler: (data: { uuid: string; msg: ServiceClientMessage }) => void): void;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Member | Kind | Type | Description |
|
|
69
|
+
|--------|------|------|-------------|
|
|
70
|
+
| `connectedAtDateTime` | property | `DateTime` | Connection timestamp |
|
|
71
|
+
| `clientName` | property | `string` | Client identifier |
|
|
72
|
+
| `connReq` | property | `FastifyRequest` | Original Fastify request |
|
|
73
|
+
| `authTokenPayload` | property | `AuthTokenPayload?` | Authenticated token payload (set after auth message) |
|
|
74
|
+
| `close` | method | `() => void` | Close the socket |
|
|
75
|
+
| `send` | method | `(uuid, msg) => Promise<number>` | Send a server message; returns number of bytes sent |
|
|
76
|
+
| `addListener` | method | `(key, eventName, info) => void` | Register an event listener on this socket |
|
|
77
|
+
| `removeListener` | method | `(key) => void` | Remove an event listener by key |
|
|
78
|
+
| `getEventListeners` | method | `(eventName) => Array<{ key; info }>` | Get all listeners for an event name |
|
|
79
|
+
| `filterEventTargetKeys` | method | `(targetKeys) => string[]` | Filter target keys to only those on this socket |
|
|
80
|
+
| `on("error")` | method | `(handler) => void` | Subscribe to error events |
|
|
81
|
+
| `on("close")` | method | `(handler) => void` | Subscribe to close events (with close code) |
|
|
82
|
+
| `on("message")` | method | `(handler) => void` | Subscribe to decoded message events |
|
|
83
|
+
|
|
84
|
+
### createServiceSocket
|
|
85
|
+
|
|
86
|
+
Create a `ServiceSocket` instance wrapping a raw WebSocket.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
function createServiceSocket(
|
|
90
|
+
socket: WebSocket,
|
|
91
|
+
clientId: string,
|
|
92
|
+
clientName: string,
|
|
93
|
+
connReq: FastifyRequest,
|
|
94
|
+
): ServiceSocket;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Parameter | Type | Description |
|
|
98
|
+
|-----------|------|-------------|
|
|
99
|
+
| `socket` | `WebSocket` | Raw WebSocket instance |
|
|
100
|
+
| `clientId` | `string` | Unique connection identifier |
|
|
101
|
+
| `clientName` | `string` | Client name |
|
|
102
|
+
| `connReq` | `FastifyRequest` | Fastify request that initiated the upgrade |
|
|
103
|
+
|
|
104
|
+
## HTTP Transport
|
|
105
|
+
|
|
106
|
+
### handleHttpRequest
|
|
107
|
+
|
|
108
|
+
Handle an HTTP RPC request. Parses the request body, verifies authentication, executes the service method, and sends the response.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
async function handleHttpRequest<TAuthInfo = unknown>(
|
|
112
|
+
req: FastifyRequest,
|
|
113
|
+
reply: FastifyReply,
|
|
114
|
+
jwtSecret: string | undefined,
|
|
115
|
+
runMethod: (def: {
|
|
116
|
+
serviceName: string;
|
|
117
|
+
methodName: string;
|
|
118
|
+
params: unknown[];
|
|
119
|
+
http: { clientName: string; authTokenPayload?: AuthTokenPayload<TAuthInfo> };
|
|
120
|
+
}) => Promise<unknown>,
|
|
121
|
+
): Promise<void>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
| Parameter | Type | Description |
|
|
125
|
+
|-----------|------|-------------|
|
|
126
|
+
| `req` | `FastifyRequest` | Fastify request |
|
|
127
|
+
| `reply` | `FastifyReply` | Fastify reply |
|
|
128
|
+
| `jwtSecret` | `string \| undefined` | JWT secret. `undefined` disables auth verification. |
|
|
129
|
+
| `runMethod` | `(def) => Promise<unknown>` | Callback to execute the service method |
|
|
130
|
+
|
|
131
|
+
### handleUpload
|
|
132
|
+
|
|
133
|
+
Handle a file upload request. Saves uploaded files to the server's root path and returns upload results.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
async function handleUpload(
|
|
137
|
+
req: FastifyRequest,
|
|
138
|
+
reply: FastifyReply,
|
|
139
|
+
rootPath: string,
|
|
140
|
+
jwtSecret: string | undefined,
|
|
141
|
+
): Promise<void>;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
| Parameter | Type | Description |
|
|
145
|
+
|-----------|------|-------------|
|
|
146
|
+
| `req` | `FastifyRequest` | Fastify request (multipart) |
|
|
147
|
+
| `reply` | `FastifyReply` | Fastify reply |
|
|
148
|
+
| `rootPath` | `string` | Server root path for file storage |
|
|
149
|
+
| `jwtSecret` | `string \| undefined` | JWT secret for auth verification |
|
|
150
|
+
|
|
151
|
+
### handleStaticFile
|
|
152
|
+
|
|
153
|
+
Serve a static file from the server's root path.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
async function handleStaticFile(
|
|
157
|
+
req: FastifyRequest,
|
|
158
|
+
reply: FastifyReply,
|
|
159
|
+
rootPath: string,
|
|
160
|
+
urlPath: string,
|
|
161
|
+
): Promise<void>;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
| Parameter | Type | Description |
|
|
165
|
+
|-----------|------|-------------|
|
|
166
|
+
| `req` | `FastifyRequest` | Fastify request |
|
|
167
|
+
| `reply` | `FastifyReply` | Fastify reply |
|
|
168
|
+
| `rootPath` | `string` | Server root directory |
|
|
169
|
+
| `urlPath` | `string` | URL path portion to resolve |
|
package/docs/types.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Types
|
|
2
|
+
|
|
3
|
+
## ServiceServerOptions
|
|
4
|
+
|
|
5
|
+
Server configuration options passed to `createServiceServer`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
interface ServiceServerOptions {
|
|
9
|
+
rootPath: string;
|
|
10
|
+
port: number;
|
|
11
|
+
ssl?: {
|
|
12
|
+
pfxBytes: Uint8Array;
|
|
13
|
+
passphrase: string;
|
|
14
|
+
};
|
|
15
|
+
auth?: {
|
|
16
|
+
jwtSecret: string;
|
|
17
|
+
} | false;
|
|
18
|
+
services: ServiceDefinition[];
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
| Field | Type | Description |
|
|
23
|
+
|-------|------|-------------|
|
|
24
|
+
| `rootPath` | `string` | Root directory path for static files and uploads |
|
|
25
|
+
| `port` | `number` | Server listening port |
|
|
26
|
+
| `ssl` | `{ pfxBytes: Uint8Array; passphrase: string }?` | SSL/TLS configuration using a PFX certificate |
|
|
27
|
+
| `ssl.pfxBytes` | `Uint8Array` | PFX certificate bytes |
|
|
28
|
+
| `ssl.passphrase` | `string` | PFX passphrase |
|
|
29
|
+
| `auth` | `{ jwtSecret: string } \| false` | JWT authentication configuration. Set to `false` to disable authentication. |
|
|
30
|
+
| `auth.jwtSecret` | `string` | Secret key for JWT signing and verification |
|
|
31
|
+
| `services` | `ServiceDefinition[]` | Array of service definitions to register |
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Utilities
|
|
2
|
+
|
|
3
|
+
## getConfig
|
|
4
|
+
|
|
5
|
+
Read a configuration section from a JSON file.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
async function getConfig<TConfig>(filePath: string): Promise<TConfig | undefined>;
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `filePath` | `string` | Path to the configuration JSON file |
|
|
14
|
+
|
|
15
|
+
Returns the parsed configuration object typed as `TConfig`, or `undefined` if the file does not exist.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { getConfig } from "@simplysm/service-server";
|
|
19
|
+
|
|
20
|
+
interface DbConfig {
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
database: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dbConfig = await getConfig<DbConfig>("config/db.json");
|
|
27
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/service-server",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.4",
|
|
4
4
|
"description": "심플리즘 패키지 - 서비스 (server)",
|
|
5
5
|
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"src"
|
|
17
|
+
"src",
|
|
18
|
+
"docs"
|
|
18
19
|
],
|
|
19
20
|
"sideEffects": false,
|
|
20
21
|
"dependencies": {
|
|
@@ -34,11 +35,11 @@
|
|
|
34
35
|
"semver": "^7.7.4",
|
|
35
36
|
"utf-8-validate": "^6.0.6",
|
|
36
37
|
"ws": "^8.20.0",
|
|
37
|
-
"@simplysm/
|
|
38
|
-
"@simplysm/
|
|
39
|
-
"@simplysm/
|
|
40
|
-
"@simplysm/
|
|
41
|
-
"@simplysm/
|
|
38
|
+
"@simplysm/core-common": "14.0.4",
|
|
39
|
+
"@simplysm/orm-common": "14.0.4",
|
|
40
|
+
"@simplysm/orm-node": "14.0.4",
|
|
41
|
+
"@simplysm/service-common": "14.0.4",
|
|
42
|
+
"@simplysm/core-node": "14.0.4"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/nodemailer": "^7.0.11",
|
package/src/service-server.ts
CHANGED
|
@@ -214,11 +214,6 @@ export class ServiceServer<TAuthInfo = unknown> extends EventEmitter<{
|
|
|
214
214
|
this.emit("close");
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
async broadcastReload(clientName: string | undefined, changedFileSet: Set<string>) {
|
|
218
|
-
logger.debug("모든 서버 클라이언트에 RELOAD 브로드캐스팅");
|
|
219
|
-
await this._wsHandler.broadcastReload(clientName, changedFileSet);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
217
|
async emitEvent<TInfo, TData>(
|
|
223
218
|
eventDef: ServiceEventDef<TInfo, TData>,
|
|
224
219
|
infoSelector: (item: TInfo) => boolean,
|
|
@@ -25,11 +25,6 @@ export interface WebSocketHandler {
|
|
|
25
25
|
*/
|
|
26
26
|
closeAll(): void;
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* 모든 클라이언트에 리로드 메시지를 브로드캐스트한다
|
|
30
|
-
*/
|
|
31
|
-
broadcastReload(clientName: string | undefined, changedFileSet: Set<string>): Promise<void>;
|
|
32
|
-
|
|
33
28
|
/**
|
|
34
29
|
* 매칭되는 클라이언트에 이벤트를 발생시킨다
|
|
35
30
|
*/
|
|
@@ -209,20 +204,6 @@ export function createWebSocketHandler(
|
|
|
209
204
|
}
|
|
210
205
|
},
|
|
211
206
|
|
|
212
|
-
async broadcastReload(
|
|
213
|
-
clientName: string | undefined,
|
|
214
|
-
changedFileSet: Set<string>,
|
|
215
|
-
): Promise<void> {
|
|
216
|
-
await Promise.allSettled(
|
|
217
|
-
Array.from(socketMap.values()).map((serviceSocket) =>
|
|
218
|
-
serviceSocket.send(Uuid.generate().toString(), {
|
|
219
|
-
name: "reload",
|
|
220
|
-
body: { clientName, changedFileSet },
|
|
221
|
-
}),
|
|
222
|
-
),
|
|
223
|
-
);
|
|
224
|
-
},
|
|
225
|
-
|
|
226
207
|
async emit<TInfo, TData>(
|
|
227
208
|
eventDef: ServiceEventDef<TInfo, TData>,
|
|
228
209
|
infoSelector: (item: TInfo) => boolean,
|