connectbase-client 0.11.0 → 0.12.1
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 +10 -20
- package/dist/connect-base.umd.js +3 -3
- package/dist/index.d.mts +3 -44
- package/dist/index.d.ts +3 -44
- package/dist/index.js +28 -78
- package/dist/index.mjs +28 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@ pnpm add connectbase-client
|
|
|
12
12
|
yarn add connectbase-client
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Key Types
|
|
16
16
|
|
|
17
|
-
Connect Base provides **two types** of
|
|
17
|
+
Connect Base provides **two types** of Keys. Use the right key for your use case:
|
|
18
18
|
|
|
19
19
|
| Type | Prefix | Use For | Permissions | Safe to Expose? |
|
|
20
20
|
|------|--------|---------|-------------|-----------------|
|
|
@@ -26,7 +26,7 @@ Connect Base provides **two types** of API Keys. Use the right key for your use
|
|
|
26
26
|
| Context | Key Type | Example |
|
|
27
27
|
|---------|----------|---------|
|
|
28
28
|
| Frontend SDK (`new ConnectBase()`) | **Public Key** (`cb_pk_`) | Web/app: DB queries, auth, file uploads |
|
|
29
|
-
| `.env` file (`
|
|
29
|
+
| `.env` file (`VITE_CONNECTBASE_PUBLIC_KEY`) | **Public Key** (`cb_pk_`) | React, Vue, etc. |
|
|
30
30
|
| CLI deploy (`.connectbaserc`) | **Public Key** (`cb_pk_`) | `npx connectbase deploy` |
|
|
31
31
|
| MCP server (AI tools) | **Secret Key** (`cb_sk_`) | Claude, Cursor, Windsurf |
|
|
32
32
|
| Server-side admin tasks | **Secret Key** (`cb_sk_`) | Backend full data access |
|
|
@@ -35,7 +35,7 @@ Connect Base provides **two types** of API Keys. Use the right key for your use
|
|
|
35
35
|
>
|
|
36
36
|
> ⚠️ **Never use Secret Keys in frontend code** — RLS is bypassed, exposing all data.
|
|
37
37
|
|
|
38
|
-
Create
|
|
38
|
+
Create Keys in the Console under **Settings > API tab**. Choose Public or Secret type when creating. The full key is shown **only once** at creation time.
|
|
39
39
|
|
|
40
40
|
## Quick Start
|
|
41
41
|
|
|
@@ -44,7 +44,7 @@ import ConnectBase from 'connectbase-client'
|
|
|
44
44
|
|
|
45
45
|
// Initialize the SDK — use a Public Key (cb_pk_)
|
|
46
46
|
const cb = new ConnectBase({
|
|
47
|
-
|
|
47
|
+
publicKey: 'cb_pk_your-public-key'
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
// Create a game room client
|
|
@@ -96,7 +96,7 @@ npm run deploy
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
The `init` command will:
|
|
99
|
-
- Ask for your
|
|
99
|
+
- Ask for your Public Key
|
|
100
100
|
- List existing web storages or create a new one automatically
|
|
101
101
|
- Create a `.connectbaserc` config file
|
|
102
102
|
- Add `.connectbaserc` to `.gitignore`
|
|
@@ -115,7 +115,7 @@ The `init` command will:
|
|
|
115
115
|
If you prefer not to use `init`, you can pass options directly:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
npx connectbase-client deploy ./dist -s <storage-id> -k <
|
|
118
|
+
npx connectbase-client deploy ./dist -s <storage-id> -k <public-key>
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
### Options
|
|
@@ -123,7 +123,7 @@ npx connectbase-client deploy ./dist -s <storage-id> -k <api-key>
|
|
|
123
123
|
| Option | Alias | Description |
|
|
124
124
|
|--------|-------|-------------|
|
|
125
125
|
| `--storage <id>` | `-s` | Storage ID |
|
|
126
|
-
| `--
|
|
126
|
+
| `--public-key <key>` | `-k` | API Key |
|
|
127
127
|
| `--base-url <url>` | `-u` | Custom server URL |
|
|
128
128
|
| `--timeout <sec>` | `-t` | Tunnel request timeout in seconds (tunnel only) |
|
|
129
129
|
| `--max-body <MB>` | | Tunnel max body size in MB (tunnel only) |
|
|
@@ -136,10 +136,10 @@ Expose a local server to the internet through a secure WebSocket tunnel. Useful
|
|
|
136
136
|
|
|
137
137
|
```bash
|
|
138
138
|
# Expose local port 8084 to the internet
|
|
139
|
-
npx connectbase-client tunnel 8084 -k <
|
|
139
|
+
npx connectbase-client tunnel 8084 -k <public-key>
|
|
140
140
|
|
|
141
141
|
# With environment variable
|
|
142
|
-
export
|
|
142
|
+
export CONNECTBASE_PUBLIC_KEY=your-public-key
|
|
143
143
|
npx connectbase-client tunnel 8084
|
|
144
144
|
|
|
145
145
|
# For GPU servers or long-running tasks (e.g., image generation)
|
|
@@ -170,7 +170,7 @@ The `init` command creates `.connectbaserc` automatically. You can also create i
|
|
|
170
170
|
|
|
171
171
|
```json
|
|
172
172
|
{
|
|
173
|
-
"
|
|
173
|
+
"publicKey": "your-public-key",
|
|
174
174
|
"storageId": "your-storage-id",
|
|
175
175
|
"deployDir": "./dist"
|
|
176
176
|
}
|
|
@@ -179,7 +179,7 @@ The `init` command creates `.connectbaserc` automatically. You can also create i
|
|
|
179
179
|
### Environment Variables
|
|
180
180
|
|
|
181
181
|
```bash
|
|
182
|
-
export
|
|
182
|
+
export CONNECTBASE_PUBLIC_KEY=your-public-key
|
|
183
183
|
export CONNECTBASE_STORAGE_ID=your-storage-id
|
|
184
184
|
npx connectbase-client deploy ./dist
|
|
185
185
|
```
|
|
@@ -780,7 +780,7 @@ await cb.push.unsubscribeFromTopic('news')
|
|
|
780
780
|
### WebRTC
|
|
781
781
|
|
|
782
782
|
```typescript
|
|
783
|
-
//
|
|
783
|
+
// Public Key/JWT 유효성 사전 검증
|
|
784
784
|
const result = await cb.webrtc.validate()
|
|
785
785
|
if (result.valid) {
|
|
786
786
|
console.log('인증 성공:', result.app_id)
|
|
@@ -939,7 +939,7 @@ setInterval(async () => {
|
|
|
939
939
|
```typescript
|
|
940
940
|
import ConnectBase from 'connectbase-client'
|
|
941
941
|
|
|
942
|
-
const cb = new ConnectBase({
|
|
942
|
+
const cb = new ConnectBase({ publicKey: 'your-public-key' })
|
|
943
943
|
const game = cb.game.createClient({ clientId: `player-${Date.now()}` })
|
|
944
944
|
|
|
945
945
|
// Local player state
|
package/dist/cli.js
CHANGED
|
@@ -113,9 +113,8 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
113
113
|
]);
|
|
114
114
|
function loadConfig() {
|
|
115
115
|
const config = {
|
|
116
|
-
publicKey: process.env.CONNECTBASE_PUBLIC_KEY
|
|
116
|
+
publicKey: process.env.CONNECTBASE_PUBLIC_KEY,
|
|
117
117
|
secretKey: process.env.CONNECTBASE_SECRET_KEY,
|
|
118
|
-
apiKey: process.env.CONNECTBASE_API_KEY,
|
|
119
118
|
storageId: process.env.CONNECTBASE_STORAGE_ID,
|
|
120
119
|
baseUrl: process.env.CONNECTBASE_BASE_URL || DEFAULT_BASE_URL
|
|
121
120
|
};
|
|
@@ -125,14 +124,6 @@ function loadConfig() {
|
|
|
125
124
|
const rcContent = JSON.parse(fs.readFileSync(rcPath, "utf-8"));
|
|
126
125
|
if (rcContent.publicKey) config.publicKey = rcContent.publicKey;
|
|
127
126
|
if (rcContent.secretKey) config.secretKey = rcContent.secretKey;
|
|
128
|
-
if (rcContent.apiKey && !config.publicKey && !config.secretKey) {
|
|
129
|
-
if (rcContent.apiKey.startsWith("cb_sk_")) {
|
|
130
|
-
config.secretKey = rcContent.apiKey;
|
|
131
|
-
} else {
|
|
132
|
-
config.publicKey = rcContent.apiKey;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (rcContent.apiKey) config.apiKey = rcContent.apiKey;
|
|
136
127
|
if (rcContent.storageId) config.storageId = rcContent.storageId;
|
|
137
128
|
if (rcContent.baseUrl) config.baseUrl = rcContent.baseUrl;
|
|
138
129
|
if (rcContent.deployDir) config.deployDir = rcContent.deployDir;
|
|
@@ -266,7 +257,7 @@ async function deploy(directory, config, isDev = false) {
|
|
|
266
257
|
url,
|
|
267
258
|
"POST",
|
|
268
259
|
{
|
|
269
|
-
"X-Public-Key": config.publicKey ?? config.
|
|
260
|
+
"X-Public-Key": config.publicKey ?? config.publicKey
|
|
270
261
|
},
|
|
271
262
|
JSON.stringify({
|
|
272
263
|
files: files.map((f) => ({
|
|
@@ -533,7 +524,7 @@ ${colors.blue}?${colors.reset} \uC120\uD0DD (\uBC88\uD638): `);
|
|
|
533
524
|
success(`\uC120\uD0DD\uB428: ${apps[num - 1].name}`);
|
|
534
525
|
info("Public Key \uC0DD\uC131 \uC911...");
|
|
535
526
|
const newKeyRes = await makeRequest(
|
|
536
|
-
`${DEFAULT_BASE_URL}/v1/public/cli/apps/${appId}/
|
|
527
|
+
`${DEFAULT_BASE_URL}/v1/public/cli/apps/${appId}/public-keys/public`,
|
|
537
528
|
"POST",
|
|
538
529
|
{ "X-Public-Key": secretKey },
|
|
539
530
|
JSON.stringify({})
|
|
@@ -1152,7 +1143,7 @@ ${colors.blue}?${colors.reset} \uC571 \uC120\uD0DD (\uBC88\uD638): `);
|
|
|
1152
1143
|
return createData.app_id;
|
|
1153
1144
|
}
|
|
1154
1145
|
async function startTunnel(port, config, tunnelOpts) {
|
|
1155
|
-
let tunnelKey = config.secretKey || (config.
|
|
1146
|
+
let tunnelKey = config.secretKey || (config.publicKey?.startsWith("cb_sk_") ? config.publicKey : "");
|
|
1156
1147
|
if (!tunnelKey) {
|
|
1157
1148
|
info("Secret Key\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uBE0C\uB77C\uC6B0\uC800 \uB85C\uADF8\uC778\uC73C\uB85C \uBC1C\uAE09\uD569\uB2C8\uB2E4...");
|
|
1158
1149
|
try {
|
|
@@ -1253,7 +1244,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
1253
1244
|
"Connection": "Upgrade",
|
|
1254
1245
|
"Sec-WebSocket-Key": wsKey,
|
|
1255
1246
|
"Sec-WebSocket-Version": "13",
|
|
1256
|
-
"Authorization": `Bearer ${config.secretKey ?? config.
|
|
1247
|
+
"Authorization": `Bearer ${config.secretKey ?? config.publicKey}`
|
|
1257
1248
|
}
|
|
1258
1249
|
};
|
|
1259
1250
|
const req = lib.request(reqOptions);
|
|
@@ -1498,7 +1489,7 @@ ${colors.yellow}\uCF54\uB4DC \uBD84\uC11D (MCP \uD1B5\uD574 \uC0AC\uC6A9):${colo
|
|
|
1498
1489
|
|
|
1499
1490
|
${colors.yellow}\uC635\uC158:${colors.reset}
|
|
1500
1491
|
-s, --storage <id> \uC2A4\uD1A0\uB9AC\uC9C0 ID
|
|
1501
|
-
-k, --
|
|
1492
|
+
-k, --public-key <key> API Key
|
|
1502
1493
|
-u, --base-url <url> \uC11C\uBC84 URL (\uAE30\uBCF8: ${DEFAULT_BASE_URL})
|
|
1503
1494
|
-t, --timeout <sec> \uD130\uB110 \uC694\uCCAD \uD0C0\uC784\uC544\uC6C3 (\uCD08, tunnel \uC804\uC6A9)
|
|
1504
1495
|
--max-body <MB> \uD130\uB110 \uCD5C\uB300 \uBC14\uB514 \uD06C\uAE30 (MB, tunnel \uC804\uC6A9)
|
|
@@ -1532,7 +1523,7 @@ ${colors.yellow}\uBE60\uB978 \uC2DC\uC791:${colors.reset}
|
|
|
1532
1523
|
${colors.yellow}\uD658\uACBD\uBCC0\uC218:${colors.reset}
|
|
1533
1524
|
CONNECTBASE_PUBLIC_KEY Public Key (cb_pk_*)
|
|
1534
1525
|
CONNECTBASE_SECRET_KEY Secret Key (cb_sk_*, \uD130\uB110\uC6A9)
|
|
1535
|
-
|
|
1526
|
+
CONNECTBASE_PUBLIC_KEY (deprecated) \uB808\uAC70\uC2DC \u2014 publicKey \uB610\uB294 secretKey \uB85C \uC0AC\uC6A9
|
|
1536
1527
|
CONNECTBASE_STORAGE_ID \uC2A4\uD1A0\uB9AC\uC9C0 ID
|
|
1537
1528
|
CONNECTBASE_BASE_URL \uC11C\uBC84 URL
|
|
1538
1529
|
|
|
@@ -1555,7 +1546,7 @@ function parseArgs(args) {
|
|
|
1555
1546
|
const arg = args[i];
|
|
1556
1547
|
if (arg === "-s" || arg === "--storage") {
|
|
1557
1548
|
result.options.storageId = args[++i];
|
|
1558
|
-
} else if (arg === "-k" || arg === "--public-key" || arg === "--
|
|
1549
|
+
} else if (arg === "-k" || arg === "--public-key" || arg === "--public-key") {
|
|
1559
1550
|
result.options.publicKey = args[++i];
|
|
1560
1551
|
} else if (arg === "--secret-key") {
|
|
1561
1552
|
result.options.secretKey = args[++i];
|
|
@@ -1598,14 +1589,13 @@ async function main() {
|
|
|
1598
1589
|
const config = {
|
|
1599
1590
|
publicKey: parsed.options.publicKey || fileConfig.publicKey,
|
|
1600
1591
|
secretKey: parsed.options.secretKey || fileConfig.secretKey,
|
|
1601
|
-
apiKey: fileConfig.apiKey,
|
|
1602
1592
|
storageId: parsed.options.storageId || fileConfig.storageId,
|
|
1603
1593
|
baseUrl: parsed.options.baseUrl || fileConfig.baseUrl || DEFAULT_BASE_URL
|
|
1604
1594
|
};
|
|
1605
1595
|
if (parsed.command === "init") {
|
|
1606
1596
|
await init();
|
|
1607
1597
|
} else if (parsed.command === "docs") {
|
|
1608
|
-
let docsPublicKey = config.publicKey ?? config.
|
|
1598
|
+
let docsPublicKey = config.publicKey ?? config.publicKey;
|
|
1609
1599
|
if (!docsPublicKey) {
|
|
1610
1600
|
docsPublicKey = await prompt(`${colors.blue}?${colors.reset} Public Key: `);
|
|
1611
1601
|
if (!docsPublicKey) {
|
|
@@ -1618,7 +1608,7 @@ async function main() {
|
|
|
1618
1608
|
await setupMcp();
|
|
1619
1609
|
} else if (parsed.command === "deploy") {
|
|
1620
1610
|
const directory = parsed.args[0] || fileConfig.deployDir || ".";
|
|
1621
|
-
if (!config.publicKey && !config.
|
|
1611
|
+
if (!config.publicKey && !config.publicKey) {
|
|
1622
1612
|
error('Public Key\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. "npx connectbase-client init"\uC73C\uB85C \uC124\uC815\uD558\uAC70\uB098 -k \uC635\uC158\uC744 \uC0AC\uC6A9\uD558\uC138\uC694');
|
|
1623
1613
|
process.exit(1);
|
|
1624
1614
|
}
|