connectbase-client 0.10.14 → 0.12.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 +14 -14
- package/dist/cli.js +46 -38
- package/dist/connect-base.umd.js +3 -3
- package/dist/index.d.mts +106 -61
- package/dist/index.d.ts +106 -61
- package/dist/index.js +93 -58
- package/dist/index.mjs +93 -58
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ var HttpClient = class {
|
|
|
18
18
|
constructor(config) {
|
|
19
19
|
this.isRefreshing = false;
|
|
20
20
|
this.refreshPromise = null;
|
|
21
|
-
this.config = config;
|
|
21
|
+
this.config = { ...config };
|
|
22
22
|
}
|
|
23
23
|
updateConfig(config) {
|
|
24
24
|
this.config = { ...this.config, ...config };
|
|
@@ -32,16 +32,34 @@ var HttpClient = class {
|
|
|
32
32
|
this.config.refreshToken = void 0;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Public Key 가 설정되어 있는지 확인
|
|
36
|
+
*/
|
|
37
|
+
hasPublicKey() {
|
|
38
|
+
return !!this.config.publicKey;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Public Key 반환
|
|
36
42
|
*/
|
|
37
|
-
|
|
38
|
-
return
|
|
43
|
+
getPublicKey() {
|
|
44
|
+
return this.config.publicKey;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
47
|
+
* Secret Key 가 설정되어 있는지 확인
|
|
42
48
|
*/
|
|
43
|
-
|
|
44
|
-
return this.config.
|
|
49
|
+
hasSecretKey() {
|
|
50
|
+
return !!this.config.secretKey;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Secret Key 반환
|
|
54
|
+
*/
|
|
55
|
+
getSecretKey() {
|
|
56
|
+
return this.config.secretKey;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 현재 설정된 자격증명 (publicKey 또는 secretKey) 반환
|
|
60
|
+
*/
|
|
61
|
+
getCredential() {
|
|
62
|
+
return this.config.publicKey ?? this.config.secretKey;
|
|
45
63
|
}
|
|
46
64
|
/**
|
|
47
65
|
* Access Token 반환
|
|
@@ -112,8 +130,9 @@ var HttpClient = class {
|
|
|
112
130
|
async prepareHeaders(config) {
|
|
113
131
|
const headers = new Headers();
|
|
114
132
|
headers.set("Content-Type", "application/json");
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
const credential = this.getCredential();
|
|
134
|
+
if (credential) {
|
|
135
|
+
headers.set("X-Public-Key", credential);
|
|
117
136
|
}
|
|
118
137
|
if (!config?.skipAuth && this.config.accessToken) {
|
|
119
138
|
let token = this.config.accessToken;
|
|
@@ -452,11 +471,11 @@ var AuthAPI = class {
|
|
|
452
471
|
if (this.cachedGuestMemberTokenKey) {
|
|
453
472
|
return this.cachedGuestMemberTokenKey;
|
|
454
473
|
}
|
|
455
|
-
const
|
|
456
|
-
if (!
|
|
474
|
+
const credential = this.http.getCredential();
|
|
475
|
+
if (!credential) {
|
|
457
476
|
this.cachedGuestMemberTokenKey = `${GUEST_MEMBER_TOKEN_KEY_PREFIX}default`;
|
|
458
477
|
} else {
|
|
459
|
-
const keyHash = simpleHash(
|
|
478
|
+
const keyHash = simpleHash(credential);
|
|
460
479
|
this.cachedGuestMemberTokenKey = `${GUEST_MEMBER_TOKEN_KEY_PREFIX}${keyHash}`;
|
|
461
480
|
}
|
|
462
481
|
return this.cachedGuestMemberTokenKey;
|
|
@@ -497,7 +516,7 @@ var DatabaseAPI = class {
|
|
|
497
516
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
498
517
|
*/
|
|
499
518
|
getPublicPrefix() {
|
|
500
|
-
return this.http.
|
|
519
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
501
520
|
}
|
|
502
521
|
// ============ Table Methods ============
|
|
503
522
|
/**
|
|
@@ -1494,7 +1513,7 @@ var StorageAPI = class {
|
|
|
1494
1513
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
1495
1514
|
*/
|
|
1496
1515
|
getPublicPrefix() {
|
|
1497
|
-
return this.http.
|
|
1516
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
1498
1517
|
}
|
|
1499
1518
|
/**
|
|
1500
1519
|
* 파일 목록 조회
|
|
@@ -1817,46 +1836,46 @@ var StorageAPI = class {
|
|
|
1817
1836
|
}
|
|
1818
1837
|
};
|
|
1819
1838
|
|
|
1820
|
-
// src/api/
|
|
1821
|
-
var
|
|
1839
|
+
// src/api/public-key.ts
|
|
1840
|
+
var PublicKeyAPI = class {
|
|
1822
1841
|
constructor(http) {
|
|
1823
1842
|
this.http = http;
|
|
1824
1843
|
}
|
|
1825
1844
|
/**
|
|
1826
|
-
* 앱의
|
|
1845
|
+
* 앱의 Public Key 목록을 조회합니다
|
|
1827
1846
|
* @param appId 앱 ID
|
|
1828
1847
|
*/
|
|
1829
|
-
async
|
|
1830
|
-
return this.http.get(`/v1/apps/${appId}/
|
|
1848
|
+
async getPublicKeys(appId) {
|
|
1849
|
+
return this.http.get(`/v1/apps/${appId}/public-keys`);
|
|
1831
1850
|
}
|
|
1832
1851
|
/**
|
|
1833
|
-
* 새
|
|
1852
|
+
* 새 Public Key 를 생성합니다
|
|
1834
1853
|
*
|
|
1835
1854
|
* **중요**: 반환되는 `key` 값은 이 응답에서만 볼 수 있습니다.
|
|
1836
1855
|
* 안전한 곳에 저장하세요.
|
|
1837
1856
|
*
|
|
1838
1857
|
* @param appId 앱 ID
|
|
1839
|
-
* @param data 생성할
|
|
1858
|
+
* @param data 생성할 Public Key 정보
|
|
1840
1859
|
*/
|
|
1841
|
-
async
|
|
1842
|
-
return this.http.post(`/v1/apps/${appId}/
|
|
1860
|
+
async createPublicKey(appId, data) {
|
|
1861
|
+
return this.http.post(`/v1/apps/${appId}/public-keys`, data);
|
|
1843
1862
|
}
|
|
1844
1863
|
/**
|
|
1845
|
-
*
|
|
1864
|
+
* Public Key 를 수정합니다 (이름 변경, 활성화/비활성화)
|
|
1846
1865
|
* @param appId 앱 ID
|
|
1847
|
-
* @param keyId
|
|
1866
|
+
* @param keyId Public Key ID
|
|
1848
1867
|
* @param data 수정할 정보
|
|
1849
1868
|
*/
|
|
1850
|
-
async
|
|
1851
|
-
return this.http.patch(`/v1/apps/${appId}/
|
|
1869
|
+
async updatePublicKey(appId, keyId, data) {
|
|
1870
|
+
return this.http.patch(`/v1/apps/${appId}/public-keys/${keyId}`, data);
|
|
1852
1871
|
}
|
|
1853
1872
|
/**
|
|
1854
|
-
*
|
|
1873
|
+
* Public Key 를 삭제합니다
|
|
1855
1874
|
* @param appId 앱 ID
|
|
1856
|
-
* @param keyId
|
|
1875
|
+
* @param keyId Public Key ID
|
|
1857
1876
|
*/
|
|
1858
|
-
async
|
|
1859
|
-
await this.http.delete(`/v1/apps/${appId}/
|
|
1877
|
+
async deletePublicKey(appId, keyId) {
|
|
1878
|
+
await this.http.delete(`/v1/apps/${appId}/public-keys/${keyId}`);
|
|
1860
1879
|
}
|
|
1861
1880
|
};
|
|
1862
1881
|
|
|
@@ -1869,7 +1888,7 @@ var FunctionsAPI = class {
|
|
|
1869
1888
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
1870
1889
|
*/
|
|
1871
1890
|
getPublicPrefix() {
|
|
1872
|
-
return this.http.
|
|
1891
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
1873
1892
|
}
|
|
1874
1893
|
/**
|
|
1875
1894
|
* 서버리스 함수 실행
|
|
@@ -2599,14 +2618,14 @@ var RealtimeAPI = class {
|
|
|
2599
2618
|
url = `${wsUrl}/v1/realtime/auth?access_token=${encodeURIComponent(this.options.accessToken)}&client_id=${this.clientId}`;
|
|
2600
2619
|
this.log("Using accessToken authentication");
|
|
2601
2620
|
} else {
|
|
2602
|
-
const
|
|
2603
|
-
if (!
|
|
2621
|
+
const publicKey = this.http.getPublicKey();
|
|
2622
|
+
if (!publicKey) {
|
|
2604
2623
|
const error = new Error("API Key or accessToken is required for realtime connection");
|
|
2605
2624
|
this.log("Connection failed: no API Key or accessToken");
|
|
2606
2625
|
reject(error);
|
|
2607
2626
|
return;
|
|
2608
2627
|
}
|
|
2609
|
-
url = `${wsUrl}/v1/realtime/auth?
|
|
2628
|
+
url = `${wsUrl}/v1/realtime/auth?public_key=${encodeURIComponent(publicKey)}&client_id=${this.clientId}`;
|
|
2610
2629
|
this.log("Using API Key authentication");
|
|
2611
2630
|
}
|
|
2612
2631
|
if (this.userId) {
|
|
@@ -3120,13 +3139,13 @@ var WebRTCAPI = class {
|
|
|
3120
3139
|
}
|
|
3121
3140
|
buildWebSocketUrl() {
|
|
3122
3141
|
let wsBase = this.webrtcUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
3123
|
-
const
|
|
3142
|
+
const publicKey = this.http.getPublicKey();
|
|
3124
3143
|
const accessToken = this.http.getAccessToken();
|
|
3125
3144
|
let authParam = "";
|
|
3126
3145
|
if (accessToken) {
|
|
3127
3146
|
authParam = `access_token=${encodeURIComponent(accessToken)}`;
|
|
3128
|
-
} else if (
|
|
3129
|
-
authParam = `api_key=${encodeURIComponent(
|
|
3147
|
+
} else if (publicKey) {
|
|
3148
|
+
authParam = `api_key=${encodeURIComponent(publicKey)}`;
|
|
3130
3149
|
}
|
|
3131
3150
|
if (!this.appId) {
|
|
3132
3151
|
throw new Error("WebRTC \uC5F0\uACB0\uC5D0\uB294 appId\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. ConnectBase \uCD08\uAE30\uD654 \uC2DC appId\uB97C \uC124\uC815\uD558\uC138\uC694.");
|
|
@@ -3959,7 +3978,7 @@ var PaymentAPI = class {
|
|
|
3959
3978
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
3960
3979
|
*/
|
|
3961
3980
|
getPublicPrefix() {
|
|
3962
|
-
return this.http.
|
|
3981
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
3963
3982
|
}
|
|
3964
3983
|
/**
|
|
3965
3984
|
* 결제 준비
|
|
@@ -4085,7 +4104,7 @@ var SubscriptionAPI = class {
|
|
|
4085
4104
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
4086
4105
|
*/
|
|
4087
4106
|
getPublicPrefix() {
|
|
4088
|
-
return this.http.
|
|
4107
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
4089
4108
|
}
|
|
4090
4109
|
// =====================
|
|
4091
4110
|
// Billing Key APIs
|
|
@@ -4392,7 +4411,7 @@ var PushAPI = class {
|
|
|
4392
4411
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
4393
4412
|
*/
|
|
4394
4413
|
getPublicPrefix() {
|
|
4395
|
-
return this.http.
|
|
4414
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
4396
4415
|
}
|
|
4397
4416
|
// ============ Device Registration ============
|
|
4398
4417
|
/**
|
|
@@ -4774,13 +4793,13 @@ var VideoAPI = class {
|
|
|
4774
4793
|
return "https://video.connectbase.world";
|
|
4775
4794
|
}
|
|
4776
4795
|
getPublicPrefix() {
|
|
4777
|
-
return this.http.
|
|
4796
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
4778
4797
|
}
|
|
4779
4798
|
async videoFetch(method, path, body) {
|
|
4780
4799
|
const headers = {};
|
|
4781
|
-
const
|
|
4782
|
-
if (
|
|
4783
|
-
headers["X-
|
|
4800
|
+
const publicKey = this.http.getPublicKey();
|
|
4801
|
+
if (publicKey) {
|
|
4802
|
+
headers["X-Public-Key"] = publicKey;
|
|
4784
4803
|
}
|
|
4785
4804
|
const accessToken = this.http.getAccessToken();
|
|
4786
4805
|
if (accessToken) {
|
|
@@ -5551,8 +5570,8 @@ var GameRoom = class {
|
|
|
5551
5570
|
if (roomId) {
|
|
5552
5571
|
params.set("room_id", roomId);
|
|
5553
5572
|
}
|
|
5554
|
-
if (this.config.
|
|
5555
|
-
params.set("
|
|
5573
|
+
if (this.config.publicKey) {
|
|
5574
|
+
params.set("public_key", this.config.publicKey);
|
|
5556
5575
|
}
|
|
5557
5576
|
if (this.config.accessToken) {
|
|
5558
5577
|
params.set("token", this.config.accessToken);
|
|
@@ -5773,7 +5792,7 @@ var GameAPI = class {
|
|
|
5773
5792
|
...config,
|
|
5774
5793
|
gameServerUrl: this.gameServerUrl.replace(/^http/, "ws"),
|
|
5775
5794
|
appId: this.appId,
|
|
5776
|
-
|
|
5795
|
+
publicKey: this.http.getPublicKey(),
|
|
5777
5796
|
accessToken: this.http.getAccessToken()
|
|
5778
5797
|
});
|
|
5779
5798
|
}
|
|
@@ -6418,9 +6437,9 @@ var GameAPI = class {
|
|
|
6418
6437
|
}
|
|
6419
6438
|
getHeaders() {
|
|
6420
6439
|
const headers = {};
|
|
6421
|
-
const
|
|
6422
|
-
if (
|
|
6423
|
-
headers["X-
|
|
6440
|
+
const publicKey = this.http.getPublicKey();
|
|
6441
|
+
if (publicKey) {
|
|
6442
|
+
headers["X-Public-Key"] = publicKey;
|
|
6424
6443
|
}
|
|
6425
6444
|
const accessToken = this.http.getAccessToken();
|
|
6426
6445
|
if (accessToken) {
|
|
@@ -6439,7 +6458,7 @@ var AdsAPI = class {
|
|
|
6439
6458
|
* API Key 인증 시 /v1/public 접두사 반환
|
|
6440
6459
|
*/
|
|
6441
6460
|
getPublicPrefix() {
|
|
6442
|
-
return this.http.
|
|
6461
|
+
return this.http.hasPublicKey() ? "/v1/public" : "/v1";
|
|
6443
6462
|
}
|
|
6444
6463
|
/**
|
|
6445
6464
|
* AdSense 연결 상태 확인
|
|
@@ -7177,6 +7196,21 @@ var AIAPI = class {
|
|
|
7177
7196
|
callbacks.onSources?.(event.sources);
|
|
7178
7197
|
continue;
|
|
7179
7198
|
}
|
|
7199
|
+
if (event.type === "tool_start" || event.type === "tool_end") {
|
|
7200
|
+
callbacks.onToolEvent?.({
|
|
7201
|
+
type: event.type,
|
|
7202
|
+
name: event.name,
|
|
7203
|
+
toolCallId: event.toolCallId,
|
|
7204
|
+
arguments: event.arguments,
|
|
7205
|
+
result: event.result,
|
|
7206
|
+
success: event.success,
|
|
7207
|
+
durationMs: event.durationMs
|
|
7208
|
+
});
|
|
7209
|
+
continue;
|
|
7210
|
+
}
|
|
7211
|
+
if (event.type === "heartbeat" || event.type === "searching") {
|
|
7212
|
+
continue;
|
|
7213
|
+
}
|
|
7180
7214
|
if (event.content) callbacks.onToken?.(event.content);
|
|
7181
7215
|
if (event.done) {
|
|
7182
7216
|
callbacks.onDone?.();
|
|
@@ -7275,8 +7309,8 @@ var WebTransportTransport = class {
|
|
|
7275
7309
|
const httpsUrl = baseUrl.replace(/^ws/, "http").replace(/^http:/, "https:");
|
|
7276
7310
|
const params = new URLSearchParams();
|
|
7277
7311
|
params.set("client_id", this.config.clientId);
|
|
7278
|
-
if (this.config.
|
|
7279
|
-
params.set("
|
|
7312
|
+
if (this.config.publicKey) {
|
|
7313
|
+
params.set("public_key", this.config.publicKey);
|
|
7280
7314
|
}
|
|
7281
7315
|
if (this.config.accessToken) {
|
|
7282
7316
|
params.set("token", this.config.accessToken);
|
|
@@ -7400,8 +7434,8 @@ var WebSocketTransport = class {
|
|
|
7400
7434
|
const wsUrl = baseUrl.replace(/^http/, "ws");
|
|
7401
7435
|
const params = new URLSearchParams();
|
|
7402
7436
|
params.set("client_id", this.config.clientId);
|
|
7403
|
-
if (this.config.
|
|
7404
|
-
params.set("
|
|
7437
|
+
if (this.config.publicKey) {
|
|
7438
|
+
params.set("public_key", this.config.publicKey);
|
|
7405
7439
|
}
|
|
7406
7440
|
if (this.config.accessToken) {
|
|
7407
7441
|
params.set("token", this.config.accessToken);
|
|
@@ -7896,7 +7930,8 @@ var ConnectBase = class {
|
|
|
7896
7930
|
constructor(config = {}) {
|
|
7897
7931
|
const httpConfig = {
|
|
7898
7932
|
baseUrl: config.baseUrl || DEFAULT_BASE_URL,
|
|
7899
|
-
|
|
7933
|
+
publicKey: config.publicKey,
|
|
7934
|
+
secretKey: config.secretKey,
|
|
7900
7935
|
onTokenRefresh: config.onTokenRefresh,
|
|
7901
7936
|
onAuthError: config.onAuthError,
|
|
7902
7937
|
onTokenExpired: config.onTokenExpired
|
|
@@ -7905,7 +7940,7 @@ var ConnectBase = class {
|
|
|
7905
7940
|
this.auth = new AuthAPI(this.http);
|
|
7906
7941
|
this.database = new DatabaseAPI(this.http);
|
|
7907
7942
|
this.storage = new StorageAPI(this.http);
|
|
7908
|
-
this.
|
|
7943
|
+
this.publicKey = new PublicKeyAPI(this.http);
|
|
7909
7944
|
this.functions = new FunctionsAPI(this.http);
|
|
7910
7945
|
this.realtime = new RealtimeAPI(this.http, config.socketUrl || DEFAULT_SOCKET_URL);
|
|
7911
7946
|
this.webrtc = new WebRTCAPI(this.http, config.webrtcUrl || DEFAULT_WEBRTC_URL, config.appId);
|