aurabase-js 0.2.1 → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  {
2
- "timestamp": "2026-03-09T11:49:17.080Z",
2
+ "timestamp": "2026-03-09T12:13:53.326Z",
3
3
  "backgroundTasks": [],
4
- "sessionStartTimestamp": "2026-03-09T11:37:51.558Z",
5
- "sessionId": "a7635597b80deb9e"
4
+ "sessionStartTimestamp": "2026-03-09T11:58:48.482Z",
5
+ "sessionId": "faa7b8297096020e"
6
6
  }
@@ -1 +1 @@
1
- {"session_id":"85311ae7-4e13-466c-9bb0-4bf05ada3ed1","transcript_path":"C:\\Users\\Jay\\.claude\\projects\\D--000-FrontEnd-242-dino-game\\85311ae7-4e13-466c-9bb0-4bf05ada3ed1.jsonl","cwd":"D:\\000.FrontEnd\\242.dino_game\\packages\\aurabase-js","model":{"id":"GLM-5","display_name":"GLM-5"},"workspace":{"current_dir":"D:\\000.FrontEnd\\242.dino_game\\packages\\aurabase-js","project_dir":"D:\\000.FrontEnd\\242.dino_game","added_dirs":[]},"version":"2.1.71","output_style":{"name":"default"},"cost":{"total_cost_usd":1.0113789999999998,"total_duration_ms":1112478,"total_api_duration_ms":476001,"total_lines_added":1354,"total_lines_removed":2},"context_window":{"total_input_tokens":32475,"total_output_tokens":11628,"context_window_size":200000,"current_usage":{"input_tokens":169,"output_tokens":104,"cache_creation_input_tokens":0,"cache_read_input_tokens":48768},"used_percentage":24,"remaining_percentage":76},"exceeds_200k_tokens":false}
1
+ {"session_id":"1c1e8df6-335a-4058-8bd4-4c0a67d996cd","transcript_path":"C:\\Users\\Jay\\.claude\\projects\\D--000-FrontEnd-242-dino-game\\1c1e8df6-335a-4058-8bd4-4c0a67d996cd.jsonl","cwd":"D:\\000.FrontEnd\\242.dino_game\\packages\\aurabase-js","model":{"id":"GLM-5","display_name":"GLM-5"},"workspace":{"current_dir":"D:\\000.FrontEnd\\242.dino_game\\packages\\aurabase-js","project_dir":"D:\\000.FrontEnd\\242.dino_game","added_dirs":[]},"version":"2.1.71","output_style":{"name":"default"},"cost":{"total_cost_usd":2.500432,"total_duration_ms":1462926,"total_api_duration_ms":692143,"total_lines_added":329,"total_lines_removed":37},"context_window":{"total_input_tokens":71095,"total_output_tokens":15653,"context_window_size":200000,"current_usage":{"input_tokens":126,"output_tokens":66,"cache_creation_input_tokens":0,"cache_read_input_tokens":77504},"used_percentage":39,"remaining_percentage":61},"exceeds_200k_tokens":false}
package/README.md CHANGED
@@ -12,74 +12,6 @@ yarn add aurabase-js
12
12
  pnpm add aurabase-js
13
13
  ```
14
14
 
15
- 설치 후 아래 명령어 한 번으로 `lib/` 폴더와 환경변수 파일을 자동 생성합니다:
16
-
17
- ```bash
18
- npx aurabase-js init
19
- ```
20
-
21
- ```
22
- aurabase-js init
23
- ──────────────────────────────────
24
- ✔ lib/client.ts 생성
25
- ✔ lib/server.ts 생성
26
- ✔ lib/admin.ts 생성
27
-
28
- 📋 환경변수 설정
29
- ──────────────────────────────────
30
- ✔ .env.local 생성 — 아래 값을 채워주세요
31
-
32
- NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
33
- NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key
34
- NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY=your-service-role-key
35
-
36
- → AuraBase 대시보드 API Keys 메뉴에서 확인하세요.
37
- ```
38
-
39
- ---
40
-
41
- ## ⚙️ 환경변수 설정 (Next.js)
42
-
43
- 설치 후 프로젝트 루트에 `.env.local` 파일을 생성하고 아래 값을 입력하세요.
44
-
45
- ```env
46
- # AuraBase 프로젝트 URL
47
- NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
48
-
49
- # 일반 사용자용 키 (클라이언트 컴포넌트, RLS 적용)
50
- NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key
51
-
52
- # 관리자용 키 (서버 컴포넌트 / API Route 전용, RLS 우회)
53
- NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY=your-service-role-key
54
- ```
55
-
56
- > 위 값은 AuraBase 대시보드 → **API Keys** 메뉴에서 확인할 수 있습니다.
57
-
58
- ### `lib/client.ts` — 클라이언트 컴포넌트용
59
-
60
- ```typescript
61
- import { createClient } from 'aurabase-js'
62
-
63
- export const client = createClient({
64
- url: process.env.NEXT_PUBLIC_AURABASE_URL!,
65
- anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY!,
66
- })
67
- ```
68
-
69
- ### `lib/admin.ts` — 서버 전용 (API Route, Server Component)
70
-
71
- ```typescript
72
- import { createClient } from 'aurabase-js'
73
-
74
- // ⚠️ 절대 클라이언트 컴포넌트에서 사용 금지 — RLS를 우회합니다
75
- export const admin = createClient({
76
- url: process.env.NEXT_PUBLIC_AURABASE_URL!,
77
- anonKey: process.env.NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY!,
78
- })
79
- ```
80
-
81
- ---
82
-
83
15
  ## 사용법
84
16
 
85
17
  ### 클라이언트 생성
@@ -88,8 +20,8 @@ export const admin = createClient({
88
20
  import { createClient } from 'aurabase-js'
89
21
 
90
22
  const aurabase = createClient({
91
- url: process.env.NEXT_PUBLIC_AURABASE_URL!,
92
- anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY!,
23
+ url: 'http://localhost:8000', // 또는 배포된 URL
24
+ anonKey: 'your-anon-key'
93
25
  })
94
26
  ```
95
27
 
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js CHANGED
@@ -1,144 +1,239 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
-
4
- const fs = require('fs');
5
- const path = require('path');
6
-
7
- const args = process.argv.slice(2);
8
- const command = args[0];
9
-
10
- const BOLD = '\x1b[1m';
11
- const GREEN = '\x1b[32m';
12
- const YELLOW = '\x1b[33m';
13
- const CYAN = '\x1b[36m';
14
- const RESET = '\x1b[0m';
15
-
16
- function success(msg) { console.log(`${GREEN}✔${RESET} ${msg}`); }
17
- function warn(msg) { console.log(`${YELLOW}⚠${RESET} ${msg}`); }
18
- function info(msg) { console.log(`${CYAN}ℹ${RESET} ${msg}`); }
19
-
20
- // ─── 생성할 파일 내용 ──────────────────────────────────────────────────────────
21
-
22
- const CLIENT_TS = `import { createClient } from 'aurabase-js';
23
-
24
- export const client = createClient({
25
- url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
26
- anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var fs = __toESM(require("fs"));
28
+ var path = __toESM(require("path"));
29
+ var TEMPLATES = {
30
+ "lib/aurabase.ts": `import { createClient } from 'aurabase-js';
31
+
32
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
33
+ const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
34
+
35
+ export const aurabase = createClient({
36
+ url: AURABASE_URL,
37
+ anonKey: AURABASE_ANON_KEY,
27
38
  });
28
- `;
39
+ `,
40
+ "lib/api-client.ts": `import { NextRequest, NextResponse } from 'next/server';
29
41
 
30
- const SERVER_TS = `import { createClient } from 'aurabase-js';
31
- import { cookies } from 'next/headers';
42
+ const AURABASE_URL = process.env.AURABASE_URL || 'https://your-project.cloudfront.net';
43
+ const AURABASE_ANON_KEY = process.env.AURABASE_ANON_KEY || '';
32
44
 
33
- export async function server() {
34
- const cookieStore = await cookies();
35
- const accessToken = cookieStore.get('access_token')?.value;
45
+ /**
46
+ * \uC11C\uBC84 \uC0AC\uC774\uB4DC API \uD504\uB85D\uC2DC \uC720\uD2F8\uB9AC\uD2F0
47
+ * - \uB85C\uADF8\uC778\uB428: \uCFE0\uD0A4\uC758 access_token \uC0AC\uC6A9
48
+ * - \uB85C\uADF8\uC778 \uC548 \uB428: AURABASE_ANON_KEY \uC0AC\uC6A9
49
+ */
50
+ export async function proxyApiRequest(
51
+ req: NextRequest,
52
+ path: string
53
+ ): Promise<NextResponse> {
54
+ const accessToken = req.cookies.get('access_token')?.value;
55
+ const authToken = accessToken || AURABASE_ANON_KEY;
56
+
57
+ let body: string | undefined;
58
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
59
+ body = await req.text();
60
+ }
36
61
 
37
- const client = createClient({
38
- url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
39
- anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
40
- });
62
+ const headers: Record<string, string> = {
63
+ 'Content-Type': 'application/json',
64
+ };
65
+ if (authToken) {
66
+ headers['Authorization'] = \`Bearer \${authToken}\`;
67
+ }
41
68
 
42
- if (accessToken) {
43
- client.setAccessToken(accessToken);
69
+ const fetchOptions: RequestInit = {
70
+ method: req.method,
71
+ headers,
72
+ };
73
+ if (body) {
74
+ fetchOptions.body = body;
44
75
  }
45
76
 
46
- return client;
77
+ const res = await fetch(\`\${AURABASE_URL}\${path}\`, fetchOptions);
78
+ const data = await res.text();
79
+ return new NextResponse(data, {
80
+ status: res.status,
81
+ headers: { 'Content-Type': 'application/json' },
82
+ });
47
83
  }
48
- `;
49
-
50
- const ADMIN_TS = `import { createClient } from 'aurabase-js';
51
84
 
52
85
  /**
53
- * Admin client with service_role key
54
- * ⚠️ ONLY use on server-side (API routes, server components)
55
- * ⚠️ Bypasses all RLS policies - use with caution!
86
+ * \uD074\uB77C\uC774\uC5B8\uD2B8\uC6A9 fetch \uB798\uD37C
56
87
  */
57
- export const admin = createClient({
58
- url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
59
- anonKey: process.env.NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY || '',
60
- });
61
- `;
88
+ export function createApiClient(baseUrl: string = '') {
89
+ return {
90
+ async get<T>(path: string): Promise<T> {
91
+ const res = await fetch(\`\${baseUrl}\${path}\`, { credentials: 'include' });
92
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
93
+ return res.json();
94
+ },
95
+
96
+ async post<T>(path: string, data?: unknown): Promise<T> {
97
+ const options: RequestInit = {
98
+ method: 'POST',
99
+ headers: { 'Content-Type': 'application/json' },
100
+ credentials: 'include',
101
+ };
102
+ if (data) options.body = JSON.stringify(data);
103
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
104
+ if (!res.ok) {
105
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
106
+ throw error;
107
+ }
108
+ return res.json();
109
+ },
110
+
111
+ async put<T>(path: string, data?: unknown): Promise<T> {
112
+ const options: RequestInit = {
113
+ method: 'PUT',
114
+ headers: { 'Content-Type': 'application/json' },
115
+ credentials: 'include',
116
+ };
117
+ if (data) options.body = JSON.stringify(data);
118
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
119
+ if (!res.ok) {
120
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
121
+ throw error;
122
+ }
123
+ return res.json();
124
+ },
125
+
126
+ async delete<T>(path: string): Promise<T> {
127
+ const res = await fetch(\`\${baseUrl}\${path}\`, {
128
+ method: 'DELETE',
129
+ credentials: 'include',
130
+ });
131
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
132
+ return res.json();
133
+ },
134
+ };
135
+ }
136
+ `,
137
+ "lib/supabase.ts": `import { createClient } from 'aurabase-js';
62
138
 
63
- const ENV_EXAMPLE = `# AuraBase
64
- NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
65
- NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key
66
- NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY=your-service-role-key
67
- `;
139
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
140
+ const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
68
141
 
69
- // ─── init ─────────────────────────────────────────────────────────────────────
142
+ export const supabase = createClient({
143
+ url: AURABASE_URL,
144
+ anonKey: AURABASE_ANON_KEY,
145
+ });
70
146
 
71
- function init() {
72
- const cwd = process.cwd();
73
- const libDir = path.join(cwd, 'lib');
74
-
75
- console.log('');
76
- console.log(`${BOLD}aurabase-js init${RESET}`);
77
- console.log('──────────────────────────────────');
78
-
79
- if (!fs.existsSync(libDir)) {
80
- fs.mkdirSync(libDir, { recursive: true });
81
- success('lib/ 폴더 생성');
82
- } else {
83
- info('lib/ 폴더가 이미 존재합니다');
84
- }
147
+ // Alias for backward compatibility
148
+ export const aurabase = supabase;
149
+ `
150
+ };
151
+ var ENV_TEMPLATE = `
152
+ # AuraBase Configuration (.env.local)
153
+
154
+ # \uD074\uB77C\uC774\uC5B8\uD2B8\uC6A9 (NEXT_PUBLIC_ \uD544\uC218)
155
+ NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
156
+ NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
85
157
 
86
- const files = [
87
- ['lib/client.ts', CLIENT_TS],
88
- ['lib/server.ts', SERVER_TS],
89
- ['lib/admin.ts', ADMIN_TS],
90
- ];
91
-
92
- for (const [relPath, content] of files) {
93
- const fullPath = path.join(cwd, relPath);
94
- if (fs.existsSync(fullPath)) {
95
- warn(`${relPath} 이미 존재 — 건너뜀`);
96
- } else {
97
- fs.writeFileSync(fullPath, content, 'utf8');
98
- success(`${relPath} 생성`);
158
+ # \uC11C\uBC84 \uC0AC\uC774\uB4DC\uC6A9
159
+ AURABASE_URL=https://your-project.cloudfront.net
160
+ AURABASE_ANON_KEY=your-anon-key-here
161
+ `;
162
+ function findProjectRoot() {
163
+ let dir = process.cwd();
164
+ while (dir !== path.dirname(dir)) {
165
+ if (fs.existsSync(path.join(dir, "package.json"))) {
166
+ return dir;
99
167
  }
168
+ dir = path.dirname(dir);
169
+ }
170
+ return process.cwd();
171
+ }
172
+ function createFile(projectRoot, filename) {
173
+ const filePath = path.join(projectRoot, filename);
174
+ const dir = path.dirname(filePath);
175
+ if (!fs.existsSync(dir)) {
176
+ fs.mkdirSync(dir, { recursive: true });
177
+ }
178
+ if (fs.existsSync(filePath)) {
179
+ console.log(`\x1B[33m \u26A0 ${filename} already exists. Skipping...\x1B[0m`);
180
+ return false;
181
+ }
182
+ const template = TEMPLATES[filename];
183
+ if (!template) {
184
+ console.log(`\x1B[31m \u2717 Unknown template: ${filename}\x1B[0m`);
185
+ return false;
100
186
  }
187
+ fs.writeFileSync(filePath, template.trim() + "\n");
188
+ console.log(`\x1B[32m \u2713 Created ${filename}\x1B[0m`);
189
+ return true;
190
+ }
191
+ function init() {
192
+ const projectRoot = findProjectRoot();
193
+ console.log("\x1B[1m\n\u{1F680} Initializing AuraBase...\x1B[0m\n");
194
+ createFile(projectRoot, "lib/aurabase.ts");
195
+ createFile(projectRoot, "lib/api-client.ts");
196
+ console.log("\x1B[36m%s\x1B[0m", ENV_TEMPLATE);
197
+ }
198
+ function showHelp() {
199
+ console.log(`
200
+ \x1B[1mAuraBase JS CLI\x1B[0m
101
201
 
102
- const envPath = path.join(cwd, '.env.local');
103
- console.log('');
104
- console.log(`${BOLD}📋 환경변수 설정${RESET}`);
105
- console.log('──────────────────────────────────');
202
+ \x1B[1mUsage:\x1B[0m
203
+ npx aurabase-js init
106
204
 
107
- if (!fs.existsSync(envPath)) {
108
- fs.writeFileSync(envPath, ENV_EXAMPLE, 'utf8');
109
- success('.env.local 생성 — 아래 값을 채워주세요');
110
- } else {
111
- info('.env.local 이미 존재 — 아래 항목이 있는지 확인하세요');
112
- }
205
+ \x1B[1mCommands:\x1B[0m
206
+ init Create lib/aurabase.ts and lib/api-client.ts
113
207
 
114
- console.log('');
115
- console.log(` ${CYAN}NEXT_PUBLIC_AURABASE_URL${RESET}=https://your-project.cloudfront.net`);
116
- console.log(` ${CYAN}NEXT_PUBLIC_AURABASE_ANON_KEY${RESET}=your-anon-key`);
117
- console.log(` ${CYAN}NEXT_PUBLIC_AURABASE_SERVICE_ROLE_KEY${RESET}=your-service-role-key`);
118
- console.log('');
119
- console.log(` → AuraBase 대시보드 ${BOLD}API Keys${RESET} 메뉴에서 확인하세요.`);
120
- console.log('');
121
- console.log(`${GREEN}✔ 완료!${RESET} 이제 아래처럼 사용할 수 있습니다:`);
122
- console.log('');
123
- console.log(` ${CYAN}// 클라이언트 컴포넌트${RESET}`);
124
- console.log(` import { client } from '@/lib/client'`);
125
- console.log(` const { data } = await client.from('todos').select('*')`);
126
- console.log('');
127
- console.log(` ${CYAN}// 서버 전용 (API Route, Server Component)${RESET}`);
128
- console.log(` import { admin } from '@/lib/admin'`);
129
- console.log(` const { data } = await admin.from('todos').select('*')`);
130
- console.log('');
131
- }
208
+ \x1B[1mOptions:\x1B[0m
209
+ -h, --help Show this help message
210
+ -v, --version Show version
132
211
 
133
- // ─── 진입점 ────────────────────────────────────────────────────────────────────
134
-
135
- if (command === 'init') {
136
- init();
137
- } else {
138
- console.log('');
139
- console.log(`${BOLD}aurabase-js CLI${RESET}`);
140
- console.log('');
141
- console.log('사용법:');
142
- console.log(` ${CYAN}npx aurabase-js init${RESET} lib/ 폴더 및 환경변수 파일 자동 생성`);
143
- console.log('');
212
+ \x1B[1mExamples:\x1B[0m
213
+ npx aurabase-js init
214
+ `);
215
+ }
216
+ function showVersion() {
217
+ const pkgPath = path.join(__dirname, "..", "package.json");
218
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
219
+ console.log(pkg.version);
220
+ }
221
+ function main() {
222
+ const args = process.argv.slice(2);
223
+ if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
224
+ showHelp();
225
+ return;
226
+ }
227
+ if (args.includes("-v") || args.includes("--version")) {
228
+ showVersion();
229
+ return;
230
+ }
231
+ if (args[0] === "init") {
232
+ init();
233
+ return;
234
+ }
235
+ console.log(`\x1B[31mUnknown command: ${args[0]}\x1B[0m`);
236
+ showHelp();
237
+ process.exit(1);
144
238
  }
239
+ main();