entity-server-client 0.2.5 → 0.3.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 +32 -1
- package/build.mjs +11 -1
- package/docs/api/alimtalk.md +62 -0
- package/docs/api/auth.md +256 -0
- package/docs/api/email.md +37 -0
- package/docs/api/entity.md +273 -0
- package/docs/api/file.md +80 -0
- package/docs/api/health.md +41 -0
- package/docs/api/identity.md +32 -0
- package/docs/api/import.md +34 -0
- package/docs/api/packet.md +25 -0
- package/docs/api/pg.md +90 -0
- package/docs/api/push.md +107 -0
- package/docs/api/react.md +141 -0
- package/docs/api/setup.md +43 -0
- package/docs/api/sms.md +45 -0
- package/docs/api/smtp.md +33 -0
- package/docs/api/transaction.md +50 -0
- package/docs/api/utils.md +52 -0
- package/docs/apis.md +22 -787
- package/docs/react.md +64 -7
- package/package.json +7 -1
- package/src/EntityServerClient.ts +28 -546
- package/src/client/base.ts +305 -0
- package/src/client/packet.ts +16 -52
- package/src/client/request.ts +46 -9
- package/src/client/utils.ts +17 -2
- package/src/hooks/useEntityServer.ts +3 -4
- package/src/mixins/auth.ts +143 -0
- package/src/mixins/entity.ts +205 -0
- package/src/mixins/file.ts +99 -0
- package/src/mixins/push.ts +109 -0
- package/src/mixins/smtp.ts +20 -0
- package/src/mixins/utils.ts +106 -0
- package/src/packet.ts +84 -0
- package/src/types.ts +93 -1
- package/tests/packet.test.mjs +50 -0
- package/dist/EntityServerClient.d.ts +0 -203
- package/dist/client/hmac.d.ts +0 -8
- package/dist/client/packet.d.ts +0 -22
- package/dist/client/request.d.ts +0 -16
- package/dist/client/utils.d.ts +0 -4
- package/dist/hooks/useEntityServer.d.ts +0 -63
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -7
- package/dist/react.d.ts +0 -1
- package/dist/react.js +0 -2
- package/dist/react.js.map +0 -7
- package/dist/types.d.ts +0 -165
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
2
|
+
|
|
3
|
+
export function AuthMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
4
|
+
Base: TBase,
|
|
5
|
+
) {
|
|
6
|
+
return class AuthMixinClass extends Base {
|
|
7
|
+
// ─── 인증 ─────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 서버 헬스 체크를 수행하고 패킷 암호화 활성 여부를 자동으로 감지합니다.
|
|
11
|
+
*
|
|
12
|
+
* 서버가 `packet_encryption: true`를 응답하면 이후 모든 요청에 암호화가 자동 적용됩니다.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* await client.checkHealth();
|
|
16
|
+
* await client.login(email, password);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
async checkHealth(): Promise<{
|
|
20
|
+
ok: boolean;
|
|
21
|
+
packet_encryption?: boolean;
|
|
22
|
+
packet_mode?: string;
|
|
23
|
+
packet_token?: string;
|
|
24
|
+
}> {
|
|
25
|
+
const res = await fetch(`${this.baseUrl}/v1/health`, {
|
|
26
|
+
signal: AbortSignal.timeout(3000),
|
|
27
|
+
credentials: "include",
|
|
28
|
+
});
|
|
29
|
+
const data = (await res.json()) as {
|
|
30
|
+
ok: boolean;
|
|
31
|
+
packet_encryption?: boolean;
|
|
32
|
+
packet_mode?: string;
|
|
33
|
+
packet_token?: string;
|
|
34
|
+
};
|
|
35
|
+
if (data.packet_encryption) this.encryptRequests = true;
|
|
36
|
+
if (typeof data.packet_token === "string") {
|
|
37
|
+
this.anonymousPacketToken = data.packet_token;
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 로그인 후 `access_token`을 내부 상태에 저장합니다. */
|
|
43
|
+
async login(
|
|
44
|
+
email: string,
|
|
45
|
+
password: string,
|
|
46
|
+
): Promise<{
|
|
47
|
+
access_token: string;
|
|
48
|
+
refresh_token: string;
|
|
49
|
+
expires_in: number;
|
|
50
|
+
force_password_change?: boolean;
|
|
51
|
+
password_expired?: boolean;
|
|
52
|
+
password_expires_in_days?: number;
|
|
53
|
+
}> {
|
|
54
|
+
const data = await this._request<{
|
|
55
|
+
data: {
|
|
56
|
+
access_token: string;
|
|
57
|
+
refresh_token: string;
|
|
58
|
+
expires_in: number;
|
|
59
|
+
force_password_change?: boolean;
|
|
60
|
+
password_expired?: boolean;
|
|
61
|
+
password_expires_in_days?: number;
|
|
62
|
+
};
|
|
63
|
+
}>("POST", "/v1/auth/login", { email, passwd: password }, false);
|
|
64
|
+
this.token = data.data.access_token;
|
|
65
|
+
if (this.keepSession)
|
|
66
|
+
this._scheduleKeepSession(
|
|
67
|
+
data.data.refresh_token,
|
|
68
|
+
data.data.expires_in,
|
|
69
|
+
(rt) => this.refreshToken(rt),
|
|
70
|
+
);
|
|
71
|
+
return data.data;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Refresh Token으로 Access Token을 재발급받아 내부 토큰을 교체합니다. */
|
|
75
|
+
async refreshToken(
|
|
76
|
+
refreshToken: string,
|
|
77
|
+
): Promise<{ access_token: string; expires_in: number }> {
|
|
78
|
+
const data = await this._request<{
|
|
79
|
+
data: { access_token: string; expires_in: number };
|
|
80
|
+
}>(
|
|
81
|
+
"POST",
|
|
82
|
+
"/v1/auth/refresh",
|
|
83
|
+
{ refresh_token: refreshToken },
|
|
84
|
+
false,
|
|
85
|
+
);
|
|
86
|
+
this.token = data.data.access_token;
|
|
87
|
+
if (this.keepSession)
|
|
88
|
+
this._scheduleKeepSession(
|
|
89
|
+
refreshToken,
|
|
90
|
+
data.data.expires_in,
|
|
91
|
+
(rt) => this.refreshToken(rt),
|
|
92
|
+
);
|
|
93
|
+
return data.data;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 서버에 로그아웃을 요청하고 내부 토큰을 초기화합니다.
|
|
98
|
+
* refresh_token을 서버에 전달해 무효화합니다.
|
|
99
|
+
*/
|
|
100
|
+
async logout(refreshToken: string): Promise<{ ok: boolean }> {
|
|
101
|
+
this.stopKeepSession();
|
|
102
|
+
const data = await this._request<{ ok: boolean }>(
|
|
103
|
+
"POST",
|
|
104
|
+
"/v1/auth/logout",
|
|
105
|
+
{ refresh_token: refreshToken },
|
|
106
|
+
false,
|
|
107
|
+
);
|
|
108
|
+
this.token = "";
|
|
109
|
+
return data;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 현재 로그인된 사용자 정보를 반환합니다. */
|
|
113
|
+
me<T = Record<string, unknown>>(): Promise<{ ok: boolean; data: T }> {
|
|
114
|
+
return this._request("GET", "/v1/auth/me");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 회원 탈퇴를 요청합니다. */
|
|
118
|
+
withdraw(passwd?: string): Promise<{ ok: boolean }> {
|
|
119
|
+
return this._request(
|
|
120
|
+
"POST",
|
|
121
|
+
"/v1/auth/withdraw",
|
|
122
|
+
passwd ? { passwd } : {},
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 휴면 계정을 재활성화합니다.
|
|
128
|
+
* 비밀번호 또는 OAuth(provider + code)로 본인 확인합니다.
|
|
129
|
+
*/
|
|
130
|
+
reactivate(params: {
|
|
131
|
+
email: string;
|
|
132
|
+
passwd?: string;
|
|
133
|
+
provider?: string;
|
|
134
|
+
code?: string;
|
|
135
|
+
}): Promise<{
|
|
136
|
+
access_token: string;
|
|
137
|
+
refresh_token: string;
|
|
138
|
+
expires_in: number;
|
|
139
|
+
}> {
|
|
140
|
+
return this._request("POST", "/v1/auth/reactivate", params, false);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntityHistoryRecord,
|
|
3
|
+
EntityListParams,
|
|
4
|
+
EntityListResult,
|
|
5
|
+
EntityQueryRequest,
|
|
6
|
+
} from "../types";
|
|
7
|
+
import { buildQuery } from "../client/utils";
|
|
8
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
9
|
+
|
|
10
|
+
export function EntityMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
11
|
+
Base: TBase,
|
|
12
|
+
) {
|
|
13
|
+
return class EntityMixinClass extends Base {
|
|
14
|
+
// ─── 트랜잭션 ─────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
/** 트랜잭션을 시작하고 활성 트랜잭션 ID를 저장합니다. */
|
|
17
|
+
async transStart(): Promise<string> {
|
|
18
|
+
const res = await this._request<{
|
|
19
|
+
ok: boolean;
|
|
20
|
+
transaction_id: string;
|
|
21
|
+
}>("POST", "/v1/transaction/start", undefined, false);
|
|
22
|
+
this.activeTxId = res.transaction_id;
|
|
23
|
+
return this.activeTxId;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 활성 트랜잭션(또는 전달된 transactionId)을 롤백합니다. */
|
|
27
|
+
transRollback(transactionId?: string): Promise<{ ok: boolean }> {
|
|
28
|
+
const txId = transactionId ?? this.activeTxId;
|
|
29
|
+
if (!txId)
|
|
30
|
+
return Promise.reject(
|
|
31
|
+
new Error(
|
|
32
|
+
"No active transaction. Call transStart() first.",
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
this.activeTxId = null;
|
|
36
|
+
return this._request("POST", `/v1/transaction/rollback/${txId}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 활성 트랜잭션(또는 전달된 transactionId)을 커밋합니다.
|
|
41
|
+
*
|
|
42
|
+
* @returns `results` 배열: commit된 각 작업의 `entity`, `action`, `seq`
|
|
43
|
+
*/
|
|
44
|
+
transCommit(transactionId?: string): Promise<{
|
|
45
|
+
ok: boolean;
|
|
46
|
+
results: Array<{ entity: string; action: string; seq: number }>;
|
|
47
|
+
}> {
|
|
48
|
+
const txId = transactionId ?? this.activeTxId;
|
|
49
|
+
if (!txId)
|
|
50
|
+
return Promise.reject(
|
|
51
|
+
new Error(
|
|
52
|
+
"No active transaction. Call transStart() first.",
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
this.activeTxId = null;
|
|
56
|
+
return this._request("POST", `/v1/transaction/commit/${txId}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ─── 엔티티 CRUD ──────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/** 시퀀스 ID로 엔티티 단건을 조회합니다. */
|
|
62
|
+
get<T = unknown>(
|
|
63
|
+
entity: string,
|
|
64
|
+
seq: number,
|
|
65
|
+
opts: { skipHooks?: boolean } = {},
|
|
66
|
+
): Promise<{ ok: boolean; data: T }> {
|
|
67
|
+
const q = opts.skipHooks ? "?skipHooks=true" : "";
|
|
68
|
+
return this._request("GET", `/v1/entity/${entity}/${seq}${q}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 조건으로 엔티티 단건을 조회합니다. data 컬럼을 완전히 복호화하여 반환합니다. */
|
|
72
|
+
find<T = unknown>(
|
|
73
|
+
entity: string,
|
|
74
|
+
conditions?: Record<string, unknown>,
|
|
75
|
+
opts: { skipHooks?: boolean } = {},
|
|
76
|
+
): Promise<{ ok: boolean; data: T }> {
|
|
77
|
+
const q = opts.skipHooks ? "?skipHooks=true" : "";
|
|
78
|
+
return this._request(
|
|
79
|
+
"POST",
|
|
80
|
+
`/v1/entity/${entity}/find${q}`,
|
|
81
|
+
conditions ?? {},
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 페이지네이션/정렬/필터 조건으로 엔티티 목록을 조회합니다. */
|
|
86
|
+
list<T = unknown>(
|
|
87
|
+
entity: string,
|
|
88
|
+
params: EntityListParams = {},
|
|
89
|
+
): Promise<{ ok: boolean; data: EntityListResult<T> }> {
|
|
90
|
+
const { conditions, fields, orderDir, orderBy, ...rest } = params;
|
|
91
|
+
const queryObj: Record<string, unknown> = {
|
|
92
|
+
page: 1,
|
|
93
|
+
limit: 20,
|
|
94
|
+
...rest,
|
|
95
|
+
};
|
|
96
|
+
if (orderBy)
|
|
97
|
+
queryObj.orderBy =
|
|
98
|
+
orderDir === "DESC" ? `-${orderBy}` : orderBy;
|
|
99
|
+
if (fields?.length) queryObj.fields = fields.join(",");
|
|
100
|
+
return this._request(
|
|
101
|
+
"POST",
|
|
102
|
+
`/v1/entity/${entity}/list?${buildQuery(queryObj)}`,
|
|
103
|
+
conditions ?? {},
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 엔티티 총 건수를 조회합니다.
|
|
109
|
+
*
|
|
110
|
+
* @param conditions 필터 조건 (예: `{ status: "active" }`)
|
|
111
|
+
*/
|
|
112
|
+
count(
|
|
113
|
+
entity: string,
|
|
114
|
+
conditions?: Record<string, unknown>,
|
|
115
|
+
): Promise<{ ok: boolean; count: number }> {
|
|
116
|
+
return this._request(
|
|
117
|
+
"POST",
|
|
118
|
+
`/v1/entity/${entity}/count`,
|
|
119
|
+
conditions ?? {},
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 커스텀 SQL로 엔티티를 조회합니다.
|
|
125
|
+
*
|
|
126
|
+
* SELECT 전용이며 인덱스 테이블만 조회 가능합니다. JOIN 지원.
|
|
127
|
+
*/
|
|
128
|
+
query<T = unknown>(
|
|
129
|
+
entity: string,
|
|
130
|
+
req: EntityQueryRequest,
|
|
131
|
+
): Promise<{ ok: boolean; data: { items: T[]; count: number } }> {
|
|
132
|
+
return this._request("POST", `/v1/entity/${entity}/query`, req);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 엔티티 데이터를 생성/수정(Submit)합니다. `seq`가 없으면 INSERT, 있으면 UPDATE입니다. */
|
|
136
|
+
submit(
|
|
137
|
+
entity: string,
|
|
138
|
+
data: Record<string, unknown>,
|
|
139
|
+
opts: { transactionId?: string; skipHooks?: boolean } = {},
|
|
140
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
141
|
+
const txId = opts.transactionId ?? this.activeTxId;
|
|
142
|
+
const extraHeaders = txId
|
|
143
|
+
? { "X-Transaction-ID": txId }
|
|
144
|
+
: undefined;
|
|
145
|
+
const q = opts.skipHooks ? "?skipHooks=true" : "";
|
|
146
|
+
return this._request(
|
|
147
|
+
"POST",
|
|
148
|
+
`/v1/entity/${entity}/submit${q}`,
|
|
149
|
+
data,
|
|
150
|
+
true,
|
|
151
|
+
extraHeaders,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 시퀀스 ID로 엔티티를 삭제합니다(`hard=true`면 하드 삭제, 기본은 소프트 삭제). */
|
|
156
|
+
delete(
|
|
157
|
+
entity: string,
|
|
158
|
+
seq: number,
|
|
159
|
+
opts: {
|
|
160
|
+
transactionId?: string;
|
|
161
|
+
hard?: boolean;
|
|
162
|
+
skipHooks?: boolean;
|
|
163
|
+
} = {},
|
|
164
|
+
): Promise<{ ok: boolean; deleted: number }> {
|
|
165
|
+
const params = new URLSearchParams();
|
|
166
|
+
if (opts.hard) params.set("hard", "true");
|
|
167
|
+
if (opts.skipHooks) params.set("skipHooks", "true");
|
|
168
|
+
const q = params.size ? `?${params}` : "";
|
|
169
|
+
const txId = opts.transactionId ?? this.activeTxId;
|
|
170
|
+
const extraHeaders = txId
|
|
171
|
+
? { "X-Transaction-ID": txId }
|
|
172
|
+
: undefined;
|
|
173
|
+
return this._request(
|
|
174
|
+
"POST",
|
|
175
|
+
`/v1/entity/${entity}/delete/${seq}${q}`,
|
|
176
|
+
undefined,
|
|
177
|
+
true,
|
|
178
|
+
extraHeaders,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 엔티티 단건의 변경 이력을 조회합니다. */
|
|
183
|
+
history<T = unknown>(
|
|
184
|
+
entity: string,
|
|
185
|
+
seq: number,
|
|
186
|
+
params: Pick<EntityListParams, "page" | "limit"> = {},
|
|
187
|
+
): Promise<{
|
|
188
|
+
ok: boolean;
|
|
189
|
+
data: EntityListResult<EntityHistoryRecord<T>>;
|
|
190
|
+
}> {
|
|
191
|
+
return this._request(
|
|
192
|
+
"GET",
|
|
193
|
+
`/v1/entity/${entity}/history/${seq}?${buildQuery({ page: 1, limit: 50, ...params })}`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 특정 이력 시점으로 엔티티를 롤백합니다. */
|
|
198
|
+
rollback(entity: string, historySeq: number): Promise<{ ok: boolean }> {
|
|
199
|
+
return this._request(
|
|
200
|
+
"POST",
|
|
201
|
+
`/v1/entity/${entity}/rollback/${historySeq}`,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { FileMeta, FileUploadOptions } from "../types";
|
|
2
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
3
|
+
|
|
4
|
+
export function FileMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
5
|
+
Base: TBase,
|
|
6
|
+
) {
|
|
7
|
+
return class FileMixinClass extends Base {
|
|
8
|
+
// ─── 파일 관리 ────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 파일을 업로드합니다. (multipart/form-data)
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const input = document.querySelector('input[type="file"]');
|
|
15
|
+
* const result = await client.fileUpload("product", input.files[0]);
|
|
16
|
+
* console.log(result.data.uuid);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
async fileUpload(
|
|
20
|
+
entity: string,
|
|
21
|
+
file: File | Blob,
|
|
22
|
+
opts: FileUploadOptions = {},
|
|
23
|
+
): Promise<{ ok: boolean; uuid: string; data: FileMeta }> {
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
form.append(
|
|
26
|
+
"file",
|
|
27
|
+
file,
|
|
28
|
+
file instanceof File ? file.name : "upload",
|
|
29
|
+
);
|
|
30
|
+
if (opts.refSeq != null)
|
|
31
|
+
form.append("ref_seq", String(opts.refSeq));
|
|
32
|
+
if (opts.isPublic != null)
|
|
33
|
+
form.append("is_public", opts.isPublic ? "true" : "false");
|
|
34
|
+
return this._requestForm(
|
|
35
|
+
"POST",
|
|
36
|
+
`/v1/files/${entity}/upload`,
|
|
37
|
+
form,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 파일을 다운로드합니다. `ArrayBuffer`를 반환합니다. */
|
|
42
|
+
fileDownload(entity: string, uuid: string): Promise<ArrayBuffer> {
|
|
43
|
+
return this._requestBinary(
|
|
44
|
+
"POST",
|
|
45
|
+
`/v1/files/${entity}/download/${uuid}`,
|
|
46
|
+
{},
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 파일을 삭제합니다. */
|
|
51
|
+
fileDelete(
|
|
52
|
+
entity: string,
|
|
53
|
+
uuid: string,
|
|
54
|
+
): Promise<{ ok: boolean; uuid: string; deleted: boolean }> {
|
|
55
|
+
return this._request(
|
|
56
|
+
"POST",
|
|
57
|
+
`/v1/files/${entity}/delete/${uuid}`,
|
|
58
|
+
{},
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 엔티티에 연결된 파일 목록을 조회합니다. */
|
|
63
|
+
fileList(
|
|
64
|
+
entity: string,
|
|
65
|
+
opts: { refSeq?: number } = {},
|
|
66
|
+
): Promise<{
|
|
67
|
+
ok: boolean;
|
|
68
|
+
data: { items: FileMeta[]; total: number };
|
|
69
|
+
}> {
|
|
70
|
+
return this._request(
|
|
71
|
+
"POST",
|
|
72
|
+
`/v1/files/${entity}/list`,
|
|
73
|
+
opts.refSeq ? { ref_seq: opts.refSeq } : {},
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 파일 메타 정보를 조회합니다. */
|
|
78
|
+
fileMeta(
|
|
79
|
+
entity: string,
|
|
80
|
+
uuid: string,
|
|
81
|
+
): Promise<{ ok: boolean; data: FileMeta }> {
|
|
82
|
+
return this._request(
|
|
83
|
+
"POST",
|
|
84
|
+
`/v1/files/${entity}/meta/${uuid}`,
|
|
85
|
+
{},
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 임시 파일 접근 토큰을 발급합니다. */
|
|
90
|
+
fileToken(uuid: string): Promise<{ ok: boolean; token: string }> {
|
|
91
|
+
return this._request("POST", `/v1/files/token/${uuid}`, {});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 파일 인라인 뷰 URL을 반환합니다. (fetch 없음, URL 조합만) */
|
|
95
|
+
fileUrl(uuid: string): string {
|
|
96
|
+
return `${this.baseUrl}/v1/files/${uuid}`;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntityListParams,
|
|
3
|
+
EntityListResult,
|
|
4
|
+
RegisterPushDeviceOptions,
|
|
5
|
+
} from "../types";
|
|
6
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
7
|
+
|
|
8
|
+
// entity submit을 가진 base 타입 (EntityMixin 적용 후)
|
|
9
|
+
type WithSubmit = EntityServerClientBase & {
|
|
10
|
+
submit(
|
|
11
|
+
entity: string,
|
|
12
|
+
data: Record<string, unknown>,
|
|
13
|
+
opts?: { transactionId?: string; skipHooks?: boolean },
|
|
14
|
+
): Promise<{ ok: boolean; seq: number }>;
|
|
15
|
+
list<T = unknown>(
|
|
16
|
+
entity: string,
|
|
17
|
+
params?: EntityListParams,
|
|
18
|
+
): Promise<{ ok: boolean; data: EntityListResult<T> }>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function PushMixin<TBase extends GConstructor<WithSubmit>>(Base: TBase) {
|
|
22
|
+
return class PushMixinClass extends Base {
|
|
23
|
+
// ─── 푸시 submit 래퍼 ────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 푸시 관련 엔티티로 payload를 전송(Submit)합니다.
|
|
27
|
+
* 내부적으로 `submit()` 메서드를 호출합니다.
|
|
28
|
+
*/
|
|
29
|
+
push(
|
|
30
|
+
pushEntity: string,
|
|
31
|
+
payload: Record<string, unknown>,
|
|
32
|
+
opts: { transactionId?: string } = {},
|
|
33
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
34
|
+
return this.submit(pushEntity, payload, opts);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ─── 푸시 디바이스 관리 ───────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
/** 푸시 로그 엔티티 목록을 조회합니다. */
|
|
40
|
+
pushLogList<T = unknown>(
|
|
41
|
+
params: EntityListParams = {},
|
|
42
|
+
): Promise<{ ok: boolean; data: EntityListResult<T> }> {
|
|
43
|
+
return this.list<T>("push_log", params);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 계정의 푸시 디바이스를 등록합니다. */
|
|
47
|
+
registerPushDevice(
|
|
48
|
+
accountSeq: number,
|
|
49
|
+
deviceId: string,
|
|
50
|
+
pushToken: string,
|
|
51
|
+
opts: RegisterPushDeviceOptions = {},
|
|
52
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
53
|
+
const {
|
|
54
|
+
platform,
|
|
55
|
+
deviceType,
|
|
56
|
+
browser,
|
|
57
|
+
browserVersion,
|
|
58
|
+
pushEnabled = true,
|
|
59
|
+
transactionId,
|
|
60
|
+
} = opts;
|
|
61
|
+
return this.submit(
|
|
62
|
+
"account_device",
|
|
63
|
+
{
|
|
64
|
+
id: deviceId,
|
|
65
|
+
account_seq: accountSeq,
|
|
66
|
+
push_token: pushToken,
|
|
67
|
+
push_enabled: pushEnabled,
|
|
68
|
+
...(platform ? { platform } : {}),
|
|
69
|
+
...(deviceType ? { device_type: deviceType } : {}),
|
|
70
|
+
...(browser ? { browser } : {}),
|
|
71
|
+
...(browserVersion
|
|
72
|
+
? { browser_version: browserVersion }
|
|
73
|
+
: {}),
|
|
74
|
+
},
|
|
75
|
+
{ transactionId },
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 디바이스 레코드의 푸시 토큰을 갱신합니다. */
|
|
80
|
+
updatePushDeviceToken(
|
|
81
|
+
deviceSeq: number,
|
|
82
|
+
pushToken: string,
|
|
83
|
+
opts: { pushEnabled?: boolean; transactionId?: string } = {},
|
|
84
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
85
|
+
const { pushEnabled = true, transactionId } = opts;
|
|
86
|
+
return this.submit(
|
|
87
|
+
"account_device",
|
|
88
|
+
{
|
|
89
|
+
seq: deviceSeq,
|
|
90
|
+
push_token: pushToken,
|
|
91
|
+
push_enabled: pushEnabled,
|
|
92
|
+
},
|
|
93
|
+
{ transactionId },
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 디바이스의 푸시 수신을 비활성화합니다. */
|
|
98
|
+
disablePushDevice(
|
|
99
|
+
deviceSeq: number,
|
|
100
|
+
opts: { transactionId?: string } = {},
|
|
101
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
102
|
+
return this.submit(
|
|
103
|
+
"account_device",
|
|
104
|
+
{ seq: deviceSeq, push_enabled: false },
|
|
105
|
+
{ transactionId: opts.transactionId },
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SmtpSendRequest } from "../types";
|
|
2
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
3
|
+
|
|
4
|
+
export function SmtpMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
5
|
+
Base: TBase,
|
|
6
|
+
) {
|
|
7
|
+
return class SmtpMixinClass extends Base {
|
|
8
|
+
// ─── SMTP 메일 발송 ───────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/** SMTP로 메일을 발송합니다. */
|
|
11
|
+
smtpSend(req: SmtpSendRequest): Promise<{ ok: boolean; seq: number }> {
|
|
12
|
+
return this._request("POST", "/v1/smtp/send", req);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** SMTP 발송 상태를 조회합니다. */
|
|
16
|
+
smtpStatus(seq: number): Promise<{ ok: boolean; status: string }> {
|
|
17
|
+
return this._request("POST", `/v1/smtp/status/${seq}`, {});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { QRCodeOptions, BarcodeOptions, Pdf2PngOptions } from "../types";
|
|
2
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
3
|
+
|
|
4
|
+
export function UtilsMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
5
|
+
Base: TBase,
|
|
6
|
+
) {
|
|
7
|
+
return class UtilsMixinClass extends Base {
|
|
8
|
+
// ─── Utils (QR / 바코드) ──────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* QR 코드 PNG를 생성합니다. `ArrayBuffer`를 반환합니다.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const buf = await client.qrcode("https://example.com");
|
|
15
|
+
* const blob = new Blob([buf], { type: "image/png" });
|
|
16
|
+
* img.src = URL.createObjectURL(blob);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
qrcode(
|
|
20
|
+
content: string,
|
|
21
|
+
opts: QRCodeOptions = {},
|
|
22
|
+
): Promise<ArrayBuffer> {
|
|
23
|
+
return this._requestBinary("POST", "/v1/utils/qrcode", {
|
|
24
|
+
content,
|
|
25
|
+
...opts,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* QR 코드를 base64/data URI JSON으로 반환합니다.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const { data_uri } = await client.qrcodeBase64("https://example.com");
|
|
34
|
+
* img.src = data_uri;
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
qrcodeBase64(
|
|
38
|
+
content: string,
|
|
39
|
+
opts: QRCodeOptions = {},
|
|
40
|
+
): Promise<{ ok: boolean; data: string; data_uri: string }> {
|
|
41
|
+
return this._request("POST", "/v1/utils/qrcode/base64", {
|
|
42
|
+
content,
|
|
43
|
+
...opts,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** QR 코드를 ASCII 아트 텍스트로 반환합니다. */
|
|
48
|
+
qrcodeText(
|
|
49
|
+
content: string,
|
|
50
|
+
opts: QRCodeOptions = {},
|
|
51
|
+
): Promise<{ ok: boolean; text: string }> {
|
|
52
|
+
return this._request("POST", "/v1/utils/qrcode/text", {
|
|
53
|
+
content,
|
|
54
|
+
...opts,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 바코드 PNG를 생성합니다. `ArrayBuffer`를 반환합니다.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const buf = await client.barcode("1234567890128", { type: "ean13" });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
barcode(
|
|
66
|
+
content: string,
|
|
67
|
+
opts: BarcodeOptions = {},
|
|
68
|
+
): Promise<ArrayBuffer> {
|
|
69
|
+
return this._requestBinary("POST", "/v1/utils/barcode", {
|
|
70
|
+
content,
|
|
71
|
+
...opts,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* PDF를 PNG 이미지로 변환합니다.
|
|
77
|
+
*
|
|
78
|
+
* 단일 페이지 요청이면 `image/png` ArrayBuffer,
|
|
79
|
+
* 다중 페이지 요청이면 `application/zip` ArrayBuffer를 반환합니다.
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* const buf = await client.pdf2png(pdfArrayBuffer, { dpi: 200 });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
pdf2png(
|
|
86
|
+
pdfData: ArrayBuffer | Uint8Array<ArrayBuffer>,
|
|
87
|
+
opts: Pdf2PngOptions = {},
|
|
88
|
+
): Promise<ArrayBuffer> {
|
|
89
|
+
const form = new FormData();
|
|
90
|
+
form.append(
|
|
91
|
+
"file",
|
|
92
|
+
new Blob([pdfData], { type: "application/pdf" }),
|
|
93
|
+
"document.pdf",
|
|
94
|
+
);
|
|
95
|
+
const params = new URLSearchParams();
|
|
96
|
+
if (opts.dpi != null) params.set("dpi", String(opts.dpi));
|
|
97
|
+
if (opts.firstPage != null)
|
|
98
|
+
params.set("first_page", String(opts.firstPage));
|
|
99
|
+
if (opts.lastPage != null)
|
|
100
|
+
params.set("last_page", String(opts.lastPage));
|
|
101
|
+
const qs = params.toString();
|
|
102
|
+
const path = "/v1/utils/pdf2png" + (qs ? `?${qs}` : "");
|
|
103
|
+
return this._requestFormBinary("POST", path, form);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|