@simplysm/service-server 13.0.95 → 13.0.96
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 +77 -7
- package/docs/builtin-services.md +22 -13
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -12,7 +12,14 @@ npm install @simplysm/service-server
|
|
|
12
12
|
|
|
13
13
|
**내부 의존성:** `@simplysm/core-common`, `@simplysm/core-node`, `@simplysm/orm-common`, `@simplysm/orm-node`, `@simplysm/service-common`
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## 문서
|
|
16
|
+
|
|
17
|
+
| 카테고리 | 설명 |
|
|
18
|
+
|---------|------|
|
|
19
|
+
| [내장 서비스](docs/builtin-services.md) | OrmService, AutoUpdateService, SmtpClientService 메서드 시그니처 |
|
|
20
|
+
| [전송 계층 및 프로토콜](docs/transport-protocol.md) | WebSocket 핸들러, ServiceSocket, HTTP 핸들러, 프로토콜 래퍼 |
|
|
21
|
+
|
|
22
|
+
## 빠른 시작
|
|
16
23
|
|
|
17
24
|
```typescript
|
|
18
25
|
import { createServiceServer, defineService, auth } from "@simplysm/service-server";
|
|
@@ -30,6 +37,8 @@ await server.listen();
|
|
|
30
37
|
await server.close();
|
|
31
38
|
```
|
|
32
39
|
|
|
40
|
+
## 서버 설정
|
|
41
|
+
|
|
33
42
|
### ServiceServerOptions
|
|
34
43
|
|
|
35
44
|
```typescript
|
|
@@ -47,6 +56,40 @@ interface ServiceServerOptions {
|
|
|
47
56
|
}
|
|
48
57
|
```
|
|
49
58
|
|
|
59
|
+
### ServiceServer
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
class ServiceServer<TAuthInfo = unknown> extends EventEmitter<{
|
|
63
|
+
ready: void;
|
|
64
|
+
close: void;
|
|
65
|
+
}> {
|
|
66
|
+
isOpen: boolean;
|
|
67
|
+
readonly fastify: FastifyInstance;
|
|
68
|
+
readonly options: ServiceServerOptions;
|
|
69
|
+
|
|
70
|
+
constructor(options: ServiceServerOptions);
|
|
71
|
+
async listen(): Promise<void>;
|
|
72
|
+
async close(): Promise<void>;
|
|
73
|
+
|
|
74
|
+
// 이벤트 브로드캐스트
|
|
75
|
+
async broadcastReload(clientName: string | undefined, changedFileSet: Set<string>): Promise<void>;
|
|
76
|
+
async emitEvent<TInfo, TData>(
|
|
77
|
+
eventDef: ServiceEventDef<TInfo, TData>,
|
|
78
|
+
infoSelector: (item: TInfo) => boolean,
|
|
79
|
+
data: TData,
|
|
80
|
+
): Promise<void>;
|
|
81
|
+
|
|
82
|
+
// JWT 인증
|
|
83
|
+
async signAuthToken(payload: AuthTokenPayload<TAuthInfo>): Promise<string>;
|
|
84
|
+
async verifyAuthToken(token: string): Promise<AuthTokenPayload<TAuthInfo>>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 팩토리 함수
|
|
88
|
+
function createServiceServer<TAuthInfo = unknown>(
|
|
89
|
+
options: ServiceServerOptions,
|
|
90
|
+
): ServiceServer<TAuthInfo>;
|
|
91
|
+
```
|
|
92
|
+
|
|
50
93
|
## 서비스 정의
|
|
51
94
|
|
|
52
95
|
`defineService`로 서비스를 정의하고, `auth`로 인증을 요구한다.
|
|
@@ -88,6 +131,38 @@ const MixedService = defineService("Mixed", (ctx) => ({
|
|
|
88
131
|
export type UserServiceType = ServiceMethods<typeof UserService>;
|
|
89
132
|
```
|
|
90
133
|
|
|
134
|
+
### defineService
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
function defineService<TMethods extends Record<string, (...args: any[]) => any>>(
|
|
138
|
+
name: string,
|
|
139
|
+
factory: (ctx: ServiceContext) => TMethods,
|
|
140
|
+
): ServiceDefinition<TMethods>;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### ServiceDefinition
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
interface ServiceDefinition<TMethods = Record<string, (...args: any[]) => any>> {
|
|
147
|
+
name: string;
|
|
148
|
+
factory: (ctx: ServiceContext) => TMethods;
|
|
149
|
+
authPermissions?: string[];
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### ServiceMethods (타입 유틸리티)
|
|
154
|
+
|
|
155
|
+
`ServiceDefinition`에서 메서드 시그니처를 추출하는 타입. 클라이언트-서버 간 타입 공유에 사용한다.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
type ServiceMethods<TDefinition> =
|
|
159
|
+
TDefinition extends ServiceDefinition<infer M> ? M : never;
|
|
160
|
+
|
|
161
|
+
// 사용 예시
|
|
162
|
+
export type UserServiceType = ServiceMethods<typeof UserService>;
|
|
163
|
+
// 클라이언트: client.getService<UserServiceType>("User");
|
|
164
|
+
```
|
|
165
|
+
|
|
91
166
|
### auth 래퍼
|
|
92
167
|
|
|
93
168
|
`auth` 함수는 서비스 팩토리 또는 개별 메서드에 적용할 수 있다.
|
|
@@ -272,7 +347,7 @@ import { SmtpClientService } from "@simplysm/service-server";
|
|
|
272
347
|
`rootPath/.config.json`에서 설정을 읽는다. LRU 캐시(1시간 만료, 10분 GC 주기)와 파일 감시로 자동 리로드된다.
|
|
273
348
|
|
|
274
349
|
```typescript
|
|
275
|
-
const dbConfig = await ctx.getConfig<DbConfig>("orm
|
|
350
|
+
const dbConfig = await ctx.getConfig<DbConfig>("orm");
|
|
276
351
|
```
|
|
277
352
|
|
|
278
353
|
클라이언트별 설정이 있으면 (`rootPath/www/{clientName}/.config.json`) 루트 설정에 머지된다.
|
|
@@ -287,8 +362,3 @@ server.on("close", () => { /* 서버 종료 완료 */ });
|
|
|
287
362
|
## Graceful Shutdown
|
|
288
363
|
|
|
289
364
|
SIGINT/SIGTERM 시그널 수신 시 자동으로 graceful shutdown을 수행한다. 10초 타임아웃 후 강제 종료.
|
|
290
|
-
|
|
291
|
-
## 상세 API 레퍼런스
|
|
292
|
-
|
|
293
|
-
- [내장 서비스 상세](docs/builtin-services.md) -- OrmService, AutoUpdateService, SmtpClientService 메서드 시그니처
|
|
294
|
-
- [전송 계층 및 프로토콜](docs/transport-protocol.md) -- WebSocket 핸들러, ServiceSocket, 프로토콜 래퍼
|
package/docs/builtin-services.md
CHANGED
|
@@ -155,18 +155,17 @@ async sendByConfig(configName: string, options: SmtpClientSendByDefaultOption):
|
|
|
155
155
|
```typescript
|
|
156
156
|
interface SmtpClientSendOption {
|
|
157
157
|
host: string;
|
|
158
|
-
port
|
|
158
|
+
port?: number;
|
|
159
159
|
secure?: boolean;
|
|
160
160
|
user?: string;
|
|
161
161
|
pass?: string;
|
|
162
162
|
from: string;
|
|
163
|
-
to: string
|
|
164
|
-
cc?: string
|
|
165
|
-
bcc?: string
|
|
163
|
+
to: string;
|
|
164
|
+
cc?: string;
|
|
165
|
+
bcc?: string;
|
|
166
166
|
subject: string;
|
|
167
|
-
html
|
|
168
|
-
|
|
169
|
-
attachments?: Array<{ filename: string; content: Uint8Array }>;
|
|
167
|
+
html: string;
|
|
168
|
+
attachments?: SmtpClientSendAttachment[];
|
|
170
169
|
}
|
|
171
170
|
```
|
|
172
171
|
|
|
@@ -174,13 +173,23 @@ interface SmtpClientSendOption {
|
|
|
174
173
|
|
|
175
174
|
```typescript
|
|
176
175
|
interface SmtpClientSendByDefaultOption {
|
|
177
|
-
to: string
|
|
178
|
-
cc?: string
|
|
179
|
-
bcc?: string
|
|
176
|
+
to: string;
|
|
177
|
+
cc?: string;
|
|
178
|
+
bcc?: string;
|
|
180
179
|
subject: string;
|
|
181
|
-
html
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
html: string;
|
|
181
|
+
attachments?: SmtpClientSendAttachment[];
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### SmtpClientSendAttachment
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
interface SmtpClientSendAttachment {
|
|
189
|
+
filename: string;
|
|
190
|
+
content?: string | Uint8Array;
|
|
191
|
+
path?: any;
|
|
192
|
+
contentType?: string;
|
|
184
193
|
}
|
|
185
194
|
```
|
|
186
195
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/service-server",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.96",
|
|
4
4
|
"description": "Simplysm package - service module (server)",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"semver": "^7.7.4",
|
|
37
37
|
"utf-8-validate": "^6.0.6",
|
|
38
38
|
"ws": "^8.19.0",
|
|
39
|
-
"@simplysm/
|
|
40
|
-
"@simplysm/core-common": "13.0.
|
|
41
|
-
"@simplysm/orm-
|
|
42
|
-
"@simplysm/
|
|
43
|
-
"@simplysm/service-common": "13.0.
|
|
39
|
+
"@simplysm/core-node": "13.0.96",
|
|
40
|
+
"@simplysm/core-common": "13.0.96",
|
|
41
|
+
"@simplysm/orm-node": "13.0.96",
|
|
42
|
+
"@simplysm/orm-common": "13.0.96",
|
|
43
|
+
"@simplysm/service-common": "13.0.96"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/nodemailer": "^7.0.11",
|