entity-server-client 0.2.4 → 0.2.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/README.md +0 -1
- package/build.mjs +4 -1
- package/dist/EntityServerClient.d.ts +709 -0
- package/dist/client/base.d.ts +59 -0
- package/dist/client/hmac.d.ts +8 -0
- package/dist/client/packet.d.ts +24 -0
- package/dist/client/request.d.ts +15 -0
- package/dist/client/utils.d.ts +8 -0
- package/dist/index.d.ts +3 -393
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/mixins/alimtalk.d.ts +56 -0
- package/dist/mixins/auth.d.ts +167 -0
- package/dist/mixins/email.d.ts +51 -0
- package/dist/mixins/entity.d.ts +119 -0
- package/dist/mixins/file.d.ts +78 -0
- package/dist/mixins/identity.d.ts +52 -0
- package/dist/mixins/pg.d.ts +63 -0
- package/dist/mixins/push.d.ts +110 -0
- package/dist/mixins/sms.d.ts +55 -0
- package/dist/mixins/smtp.d.ts +44 -0
- package/dist/mixins/utils.d.ts +70 -0
- package/dist/react.js +1 -1
- package/dist/react.js.map +4 -4
- package/dist/types.d.ts +329 -0
- package/docs/apis.md +5 -12
- package/docs/react.md +6 -7
- package/package.json +2 -1
- package/src/EntityServerClient.ts +54 -0
- package/src/client/base.ts +246 -0
- package/src/client/hmac.ts +41 -0
- package/src/client/packet.ts +100 -0
- package/src/client/request.ts +93 -0
- package/src/client/utils.ts +34 -0
- package/src/hooks/useEntityServer.ts +3 -4
- package/src/index.ts +3 -917
- package/src/mixins/alimtalk.ts +35 -0
- package/src/mixins/auth.ts +287 -0
- package/src/mixins/email.ts +46 -0
- package/src/mixins/entity.ts +205 -0
- package/src/mixins/file.ts +99 -0
- package/src/mixins/identity.ts +35 -0
- package/src/mixins/pg.ts +58 -0
- package/src/mixins/push.ts +132 -0
- package/src/mixins/sms.ts +46 -0
- package/src/mixins/smtp.ts +20 -0
- package/src/mixins/utils.ts +75 -0
- package/src/types.ts +388 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IdentityRequestOptions } from "../types";
|
|
2
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
3
|
+
|
|
4
|
+
export function IdentityMixin<
|
|
5
|
+
TBase extends GConstructor<EntityServerClientBase>,
|
|
6
|
+
>(Base: TBase) {
|
|
7
|
+
return class IdentityMixinClass extends Base {
|
|
8
|
+
// ─── 본인인증 ─────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/** 본인인증 요청을 생성합니다. */
|
|
11
|
+
identityRequest(
|
|
12
|
+
opts: IdentityRequestOptions,
|
|
13
|
+
): Promise<{ ok: boolean; data: Record<string, unknown> }> {
|
|
14
|
+
return this._request("POST", "/v1/identity/request", opts);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 본인인증 결과를 조회합니다. */
|
|
18
|
+
identityResult(requestId: string): Promise<{
|
|
19
|
+
ok: boolean;
|
|
20
|
+
data: Record<string, unknown>;
|
|
21
|
+
}> {
|
|
22
|
+
return this._request("GET", `/v1/identity/result/${requestId}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** CI 해시 중복 여부를 확인합니다. */
|
|
26
|
+
identityVerifyCI(ciHash: string): Promise<{
|
|
27
|
+
ok: boolean;
|
|
28
|
+
data: { exists: boolean; account_seq?: number };
|
|
29
|
+
}> {
|
|
30
|
+
return this._request("POST", "/v1/identity/verify-ci", {
|
|
31
|
+
ci_hash: ciHash,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/mixins/pg.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PgCreateOrderRequest,
|
|
3
|
+
PgConfirmPaymentRequest,
|
|
4
|
+
PgCancelPaymentRequest,
|
|
5
|
+
} from "../types";
|
|
6
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
7
|
+
|
|
8
|
+
export function PgMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
9
|
+
Base: TBase,
|
|
10
|
+
) {
|
|
11
|
+
return class PgMixinClass extends Base {
|
|
12
|
+
// ─── PG(결제 게이트웨이) ──────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
/** 결제 주문을 생성합니다. */
|
|
15
|
+
pgCreateOrder(
|
|
16
|
+
req: PgCreateOrderRequest,
|
|
17
|
+
): Promise<{ ok: boolean; data: Record<string, unknown> }> {
|
|
18
|
+
return this._request("POST", "/v1/pg/orders", req);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 주문 정보를 조회합니다. */
|
|
22
|
+
pgGetOrder(orderId: string): Promise<{
|
|
23
|
+
ok: boolean;
|
|
24
|
+
data: Record<string, unknown>;
|
|
25
|
+
}> {
|
|
26
|
+
return this._request("GET", `/v1/pg/orders/${orderId}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 결제를 승인합니다. */
|
|
30
|
+
pgConfirmPayment(
|
|
31
|
+
req: PgConfirmPaymentRequest,
|
|
32
|
+
): Promise<{ ok: boolean; data: Record<string, unknown> }> {
|
|
33
|
+
return this._request("POST", "/v1/pg/confirm", req);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 결제를 취소합니다. */
|
|
37
|
+
pgCancelPayment(
|
|
38
|
+
orderId: string,
|
|
39
|
+
req: PgCancelPaymentRequest,
|
|
40
|
+
): Promise<{ ok: boolean; data: Record<string, unknown> }> {
|
|
41
|
+
return this._request(
|
|
42
|
+
"POST",
|
|
43
|
+
`/v1/pg/orders/${orderId}/cancel`,
|
|
44
|
+
req,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 결제 상태를 외부 PG와 동기화합니다. */
|
|
49
|
+
pgSyncPayment(orderId: string): Promise<{ ok: boolean }> {
|
|
50
|
+
return this._request("POST", `/v1/pg/orders/${orderId}/sync`, {});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 클라이언트 SDK 설정을 반환합니다 (공개 API, 인증 불필요). */
|
|
54
|
+
pgConfig(): Promise<{ ok: boolean; data: Record<string, unknown> }> {
|
|
55
|
+
return this._request("GET", "/v1/pg/config", undefined, false);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntityListParams,
|
|
3
|
+
EntityListResult,
|
|
4
|
+
RegisterPushDeviceOptions,
|
|
5
|
+
PushSendRequest,
|
|
6
|
+
PushSendAllRequest,
|
|
7
|
+
} from "../types";
|
|
8
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
9
|
+
|
|
10
|
+
// entity submit을 가진 base 타입 (EntityMixin 적용 후)
|
|
11
|
+
type WithSubmit = EntityServerClientBase & {
|
|
12
|
+
submit(
|
|
13
|
+
entity: string,
|
|
14
|
+
data: Record<string, unknown>,
|
|
15
|
+
opts?: { transactionId?: string; skipHooks?: boolean },
|
|
16
|
+
): Promise<{ ok: boolean; seq: number }>;
|
|
17
|
+
list<T = unknown>(
|
|
18
|
+
entity: string,
|
|
19
|
+
params?: EntityListParams,
|
|
20
|
+
): Promise<{ ok: boolean; data: EntityListResult<T> }>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function PushMixin<TBase extends GConstructor<WithSubmit>>(Base: TBase) {
|
|
24
|
+
return class PushMixinClass extends Base {
|
|
25
|
+
// ─── 푸시 submit 래퍼 ────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 푸시 관련 엔티티로 payload를 전송(Submit)합니다.
|
|
29
|
+
* 내부적으로 `submit()` 메서드를 호출합니다.
|
|
30
|
+
*/
|
|
31
|
+
push(
|
|
32
|
+
pushEntity: string,
|
|
33
|
+
payload: Record<string, unknown>,
|
|
34
|
+
opts: { transactionId?: string } = {},
|
|
35
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
36
|
+
return this.submit(pushEntity, payload, opts);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ─── 푸시 디바이스 관리 ───────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
/** 푸시 로그 엔티티 목록을 조회합니다. */
|
|
42
|
+
pushLogList<T = unknown>(
|
|
43
|
+
params: EntityListParams = {},
|
|
44
|
+
): Promise<{ ok: boolean; data: EntityListResult<T> }> {
|
|
45
|
+
return this.list<T>("push_log", params);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 계정의 푸시 디바이스를 등록합니다. */
|
|
49
|
+
registerPushDevice(
|
|
50
|
+
accountSeq: number,
|
|
51
|
+
deviceId: string,
|
|
52
|
+
pushToken: string,
|
|
53
|
+
opts: RegisterPushDeviceOptions = {},
|
|
54
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
55
|
+
const {
|
|
56
|
+
platform,
|
|
57
|
+
deviceType,
|
|
58
|
+
browser,
|
|
59
|
+
browserVersion,
|
|
60
|
+
pushEnabled = true,
|
|
61
|
+
transactionId,
|
|
62
|
+
} = opts;
|
|
63
|
+
return this.submit(
|
|
64
|
+
"account_device",
|
|
65
|
+
{
|
|
66
|
+
id: deviceId,
|
|
67
|
+
account_seq: accountSeq,
|
|
68
|
+
push_token: pushToken,
|
|
69
|
+
push_enabled: pushEnabled,
|
|
70
|
+
...(platform ? { platform } : {}),
|
|
71
|
+
...(deviceType ? { device_type: deviceType } : {}),
|
|
72
|
+
...(browser ? { browser } : {}),
|
|
73
|
+
...(browserVersion
|
|
74
|
+
? { browser_version: browserVersion }
|
|
75
|
+
: {}),
|
|
76
|
+
},
|
|
77
|
+
{ transactionId },
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 디바이스 레코드의 푸시 토큰을 갱신합니다. */
|
|
82
|
+
updatePushDeviceToken(
|
|
83
|
+
deviceSeq: number,
|
|
84
|
+
pushToken: string,
|
|
85
|
+
opts: { pushEnabled?: boolean; transactionId?: string } = {},
|
|
86
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
87
|
+
const { pushEnabled = true, transactionId } = opts;
|
|
88
|
+
return this.submit(
|
|
89
|
+
"account_device",
|
|
90
|
+
{
|
|
91
|
+
seq: deviceSeq,
|
|
92
|
+
push_token: pushToken,
|
|
93
|
+
push_enabled: pushEnabled,
|
|
94
|
+
},
|
|
95
|
+
{ transactionId },
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 디바이스의 푸시 수신을 비활성화합니다. */
|
|
100
|
+
disablePushDevice(
|
|
101
|
+
deviceSeq: number,
|
|
102
|
+
opts: { transactionId?: string } = {},
|
|
103
|
+
): Promise<{ ok: boolean; seq: number }> {
|
|
104
|
+
return this.submit(
|
|
105
|
+
"account_device",
|
|
106
|
+
{ seq: deviceSeq, push_enabled: false },
|
|
107
|
+
{ transactionId: opts.transactionId },
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ─── 푸시 발송 API ────────────────────────────────────────────────────
|
|
112
|
+
|
|
113
|
+
/** 특정 계정에 푸시 알림을 발송합니다. */
|
|
114
|
+
pushSend(req: PushSendRequest): Promise<{ ok: boolean; seq: number }> {
|
|
115
|
+
return this._request("POST", "/v1/push/send", req);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** 전체 사용자에게 푸시 알림을 발송합니다. */
|
|
119
|
+
pushSendAll(req: PushSendAllRequest): Promise<{
|
|
120
|
+
ok: boolean;
|
|
121
|
+
sent: number;
|
|
122
|
+
failed: number;
|
|
123
|
+
}> {
|
|
124
|
+
return this._request("POST", "/v1/push/send-all", req);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 푸시 발송 상태를 조회합니다. */
|
|
128
|
+
pushStatus(seq: number): Promise<{ ok: boolean; status: string }> {
|
|
129
|
+
return this._request("POST", `/v1/push/status/${seq}`, {});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SmsSendRequest } from "../types";
|
|
2
|
+
import type { GConstructor, EntityServerClientBase } from "../client/base";
|
|
3
|
+
|
|
4
|
+
export function SmsMixin<TBase extends GConstructor<EntityServerClientBase>>(
|
|
5
|
+
Base: TBase,
|
|
6
|
+
) {
|
|
7
|
+
return class SmsMixinClass extends Base {
|
|
8
|
+
// ─── SMS 발송 / 인증 ──────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/** SMS를 발송합니다. */
|
|
11
|
+
smsSend(req: SmsSendRequest): Promise<{ ok: boolean; seq: number }> {
|
|
12
|
+
return this._request("POST", "/v1/sms/send", req);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** SMS 발송 상태를 조회합니다. */
|
|
16
|
+
smsStatus(seq: number): Promise<{ ok: boolean; status: string }> {
|
|
17
|
+
return this._request("GET", `/v1/sms/status/${seq}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** SMS 인증 코드를 발송합니다. */
|
|
21
|
+
smsVerificationSend(
|
|
22
|
+
phone: string,
|
|
23
|
+
opts: { purpose?: string } = {},
|
|
24
|
+
): Promise<{ ok: boolean }> {
|
|
25
|
+
return this._request(
|
|
26
|
+
"POST",
|
|
27
|
+
"/v1/sms/verification/send",
|
|
28
|
+
{ phone, ...opts },
|
|
29
|
+
false,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** SMS 인증 코드를 검증합니다. */
|
|
34
|
+
smsVerificationVerify(
|
|
35
|
+
phone: string,
|
|
36
|
+
code: string,
|
|
37
|
+
): Promise<{ ok: boolean; verified: boolean }> {
|
|
38
|
+
return this._request(
|
|
39
|
+
"POST",
|
|
40
|
+
"/v1/sms/verification/verify",
|
|
41
|
+
{ phone, code },
|
|
42
|
+
false,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -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,75 @@
|
|
|
1
|
+
import type { QRCodeOptions, BarcodeOptions } 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
|
+
}
|