aurabase-js 0.3.0 → 0.5.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 +1 @@
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.2039,"total_duration_ms":1275166,"total_api_duration_ms":583368,"total_lines_added":202,"total_lines_removed":17},"context_window":{"total_input_tokens":66759,"total_output_tokens":12129,"context_window_size":200000,"current_usage":{"input_tokens":948,"output_tokens":71,"cache_creation_input_tokens":0,"cache_read_input_tokens":72000},"used_percentage":36,"remaining_percentage":64},"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.823248,"total_duration_ms":1638396,"total_api_duration_ms":797770,"total_lines_added":333,"total_lines_removed":70},"context_window":{"total_input_tokens":76386,"total_output_tokens":19574,"context_window_size":200000,"current_usage":{"input_tokens":160,"output_tokens":64,"cache_creation_input_tokens":0,"cache_read_input_tokens":82624},"used_percentage":41,"remaining_percentage":59},"exceeds_200k_tokens":false}
package/dist/cli.js CHANGED
@@ -29,7 +29,7 @@ var path = __toESM(require("path"));
29
29
  var TEMPLATES = {
30
30
  "lib/aurabase.ts": `import { createClient } from 'aurabase-js';
31
31
 
32
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
32
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
33
33
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
34
34
 
35
35
  export const aurabase = createClient({
@@ -37,24 +37,104 @@ export const aurabase = createClient({
37
37
  anonKey: AURABASE_ANON_KEY,
38
38
  });
39
39
  `,
40
- "lib/supabase.ts": `import { createClient } from 'aurabase-js';
40
+ "lib/api-client.ts": `import { NextRequest, NextResponse } from 'next/server';
41
41
 
42
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
42
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
43
43
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
44
44
 
45
- export const supabase = createClient({
46
- url: AURABASE_URL,
47
- anonKey: AURABASE_ANON_KEY,
48
- });
45
+ /**
46
+ * \uC11C\uBC84 \uC0AC\uC774\uB4DC API \uD504\uB85D\uC2DC \uC720\uD2F8\uB9AC\uD2F0
47
+ */
48
+ export async function proxyApiRequest(
49
+ req: NextRequest,
50
+ path: string
51
+ ): Promise<NextResponse> {
52
+ const accessToken = req.cookies.get('access_token')?.value;
53
+ const authToken = accessToken || AURABASE_ANON_KEY;
54
+
55
+ let body: string | undefined;
56
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
57
+ body = await req.text();
58
+ }
59
+
60
+ const headers: Record<string, string> = {
61
+ 'Content-Type': 'application/json',
62
+ };
63
+ if (authToken) {
64
+ headers['Authorization'] = \`Bearer \${authToken}\`;
65
+ }
66
+
67
+ const fetchOptions: RequestInit = {
68
+ method: req.method,
69
+ headers,
70
+ };
71
+ if (body) {
72
+ fetchOptions.body = body;
73
+ }
74
+
75
+ const res = await fetch(\`\${AURABASE_URL}\${path}\`, fetchOptions);
76
+ const data = await res.text();
77
+ return new NextResponse(data, {
78
+ status: res.status,
79
+ headers: { 'Content-Type': 'application/json' },
80
+ });
81
+ }
82
+
83
+ /**
84
+ * \uD074\uB77C\uC774\uC5B8\uD2B8\uC6A9 fetch \uB798\uD37C
85
+ */
86
+ export function createApiClient(baseUrl: string = '') {
87
+ return {
88
+ async get<T>(path: string): Promise<T> {
89
+ const res = await fetch(\`\${baseUrl}\${path}\`, { credentials: 'include' });
90
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
91
+ return res.json();
92
+ },
93
+
94
+ async post<T>(path: string, data?: unknown): Promise<T> {
95
+ const options: RequestInit = {
96
+ method: 'POST',
97
+ headers: { 'Content-Type': 'application/json' },
98
+ credentials: 'include',
99
+ };
100
+ if (data) options.body = JSON.stringify(data);
101
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
102
+ if (!res.ok) {
103
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
104
+ throw error;
105
+ }
106
+ return res.json();
107
+ },
49
108
 
50
- // Alias for backward compatibility
51
- export const aurabase = supabase;
109
+ async put<T>(path: string, data?: unknown): Promise<T> {
110
+ const options: RequestInit = {
111
+ method: 'PUT',
112
+ headers: { 'Content-Type': 'application/json' },
113
+ credentials: 'include',
114
+ };
115
+ if (data) options.body = JSON.stringify(data);
116
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
117
+ if (!res.ok) {
118
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
119
+ throw error;
120
+ }
121
+ return res.json();
122
+ },
123
+
124
+ async delete<T>(path: string): Promise<T> {
125
+ const res = await fetch(\`\${baseUrl}\${path}\`, {
126
+ method: 'DELETE',
127
+ credentials: 'include',
128
+ });
129
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
130
+ return res.json();
131
+ },
132
+ };
133
+ }
52
134
  `
53
135
  };
54
136
  var ENV_TEMPLATE = `
55
- # AuraBase Configuration
56
- # Add these to your .env.local file:
57
-
137
+ # AuraBase Configuration (.env.local)
58
138
  NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
59
139
  NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
60
140
  `;
@@ -68,20 +148,30 @@ function findProjectRoot() {
68
148
  }
69
149
  return process.cwd();
70
150
  }
71
- function init(filename = "lib/aurabase.ts") {
72
- const projectRoot = findProjectRoot();
151
+ function createFile(projectRoot, filename) {
73
152
  const filePath = path.join(projectRoot, filename);
74
153
  const dir = path.dirname(filePath);
75
154
  if (!fs.existsSync(dir)) {
76
155
  fs.mkdirSync(dir, { recursive: true });
77
156
  }
78
157
  if (fs.existsSync(filePath)) {
79
- console.log(`\x1B[33m\u26A0 ${filename} already exists. Skipping...\x1B[0m`);
80
- return;
158
+ console.log(`\x1B[33m \u26A0 ${filename} already exists. Skipping...\x1B[0m`);
159
+ return false;
160
+ }
161
+ const template = TEMPLATES[filename];
162
+ if (!template) {
163
+ console.log(`\x1B[31m \u2717 Unknown template: ${filename}\x1B[0m`);
164
+ return false;
81
165
  }
82
- const template = TEMPLATES[filename] || TEMPLATES["lib/aurabase.ts"];
83
166
  fs.writeFileSync(filePath, template.trim() + "\n");
84
- console.log(`\x1B[32m\u2713 Created ${filename}\x1B[0m`);
167
+ console.log(`\x1B[32m \u2713 Created ${filename}\x1B[0m`);
168
+ return true;
169
+ }
170
+ function init() {
171
+ const projectRoot = findProjectRoot();
172
+ console.log("\x1B[1m\n\u{1F680} Initializing AuraBase...\x1B[0m\n");
173
+ createFile(projectRoot, "lib/aurabase.ts");
174
+ createFile(projectRoot, "lib/api-client.ts");
85
175
  console.log("\x1B[36m%s\x1B[0m", ENV_TEMPLATE);
86
176
  }
87
177
  function showHelp() {
@@ -89,19 +179,11 @@ function showHelp() {
89
179
  \x1B[1mAuraBase JS CLI\x1B[0m
90
180
 
91
181
  \x1B[1mUsage:\x1B[0m
92
- npx aurabase-js init [options]
93
-
94
- \x1B[1mCommands:\x1B[0m
95
- init Create lib/aurabase.ts file
96
- init --supabase Create lib/supabase.ts file (alias name)
182
+ npx aurabase-js init
97
183
 
98
184
  \x1B[1mOptions:\x1B[0m
99
185
  -h, --help Show this help message
100
186
  -v, --version Show version
101
-
102
- \x1B[1mExamples:\x1B[0m
103
- npx aurabase-js init
104
- npx aurabase-js init --supabase
105
187
  `);
106
188
  }
107
189
  function showVersion() {
@@ -120,9 +202,7 @@ function main() {
120
202
  return;
121
203
  }
122
204
  if (args[0] === "init") {
123
- const useSupabase = args.includes("--supabase");
124
- const filename = useSupabase ? "lib/supabase.ts" : "lib/aurabase.ts";
125
- init(filename);
205
+ init();
126
206
  return;
127
207
  }
128
208
  console.log(`\x1B[31mUnknown command: ${args[0]}\x1B[0m`);
package/dist/cli.mjs CHANGED
@@ -6,7 +6,7 @@ import * as path from "path";
6
6
  var TEMPLATES = {
7
7
  "lib/aurabase.ts": `import { createClient } from 'aurabase-js';
8
8
 
9
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
9
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
10
10
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
11
11
 
12
12
  export const aurabase = createClient({
@@ -14,24 +14,104 @@ export const aurabase = createClient({
14
14
  anonKey: AURABASE_ANON_KEY,
15
15
  });
16
16
  `,
17
- "lib/supabase.ts": `import { createClient } from 'aurabase-js';
17
+ "lib/api-client.ts": `import { NextRequest, NextResponse } from 'next/server';
18
18
 
19
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
19
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
20
20
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
21
21
 
22
- export const supabase = createClient({
23
- url: AURABASE_URL,
24
- anonKey: AURABASE_ANON_KEY,
25
- });
22
+ /**
23
+ * \uC11C\uBC84 \uC0AC\uC774\uB4DC API \uD504\uB85D\uC2DC \uC720\uD2F8\uB9AC\uD2F0
24
+ */
25
+ export async function proxyApiRequest(
26
+ req: NextRequest,
27
+ path: string
28
+ ): Promise<NextResponse> {
29
+ const accessToken = req.cookies.get('access_token')?.value;
30
+ const authToken = accessToken || AURABASE_ANON_KEY;
31
+
32
+ let body: string | undefined;
33
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
34
+ body = await req.text();
35
+ }
36
+
37
+ const headers: Record<string, string> = {
38
+ 'Content-Type': 'application/json',
39
+ };
40
+ if (authToken) {
41
+ headers['Authorization'] = \`Bearer \${authToken}\`;
42
+ }
43
+
44
+ const fetchOptions: RequestInit = {
45
+ method: req.method,
46
+ headers,
47
+ };
48
+ if (body) {
49
+ fetchOptions.body = body;
50
+ }
51
+
52
+ const res = await fetch(\`\${AURABASE_URL}\${path}\`, fetchOptions);
53
+ const data = await res.text();
54
+ return new NextResponse(data, {
55
+ status: res.status,
56
+ headers: { 'Content-Type': 'application/json' },
57
+ });
58
+ }
59
+
60
+ /**
61
+ * \uD074\uB77C\uC774\uC5B8\uD2B8\uC6A9 fetch \uB798\uD37C
62
+ */
63
+ export function createApiClient(baseUrl: string = '') {
64
+ return {
65
+ async get<T>(path: string): Promise<T> {
66
+ const res = await fetch(\`\${baseUrl}\${path}\`, { credentials: 'include' });
67
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
68
+ return res.json();
69
+ },
70
+
71
+ async post<T>(path: string, data?: unknown): Promise<T> {
72
+ const options: RequestInit = {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json' },
75
+ credentials: 'include',
76
+ };
77
+ if (data) options.body = JSON.stringify(data);
78
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
79
+ if (!res.ok) {
80
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
81
+ throw error;
82
+ }
83
+ return res.json();
84
+ },
26
85
 
27
- // Alias for backward compatibility
28
- export const aurabase = supabase;
86
+ async put<T>(path: string, data?: unknown): Promise<T> {
87
+ const options: RequestInit = {
88
+ method: 'PUT',
89
+ headers: { 'Content-Type': 'application/json' },
90
+ credentials: 'include',
91
+ };
92
+ if (data) options.body = JSON.stringify(data);
93
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
94
+ if (!res.ok) {
95
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
96
+ throw error;
97
+ }
98
+ return res.json();
99
+ },
100
+
101
+ async delete<T>(path: string): Promise<T> {
102
+ const res = await fetch(\`\${baseUrl}\${path}\`, {
103
+ method: 'DELETE',
104
+ credentials: 'include',
105
+ });
106
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
107
+ return res.json();
108
+ },
109
+ };
110
+ }
29
111
  `
30
112
  };
31
113
  var ENV_TEMPLATE = `
32
- # AuraBase Configuration
33
- # Add these to your .env.local file:
34
-
114
+ # AuraBase Configuration (.env.local)
35
115
  NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
36
116
  NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
37
117
  `;
@@ -45,20 +125,30 @@ function findProjectRoot() {
45
125
  }
46
126
  return process.cwd();
47
127
  }
48
- function init(filename = "lib/aurabase.ts") {
49
- const projectRoot = findProjectRoot();
128
+ function createFile(projectRoot, filename) {
50
129
  const filePath = path.join(projectRoot, filename);
51
130
  const dir = path.dirname(filePath);
52
131
  if (!fs.existsSync(dir)) {
53
132
  fs.mkdirSync(dir, { recursive: true });
54
133
  }
55
134
  if (fs.existsSync(filePath)) {
56
- console.log(`\x1B[33m\u26A0 ${filename} already exists. Skipping...\x1B[0m`);
57
- return;
135
+ console.log(`\x1B[33m \u26A0 ${filename} already exists. Skipping...\x1B[0m`);
136
+ return false;
137
+ }
138
+ const template = TEMPLATES[filename];
139
+ if (!template) {
140
+ console.log(`\x1B[31m \u2717 Unknown template: ${filename}\x1B[0m`);
141
+ return false;
58
142
  }
59
- const template = TEMPLATES[filename] || TEMPLATES["lib/aurabase.ts"];
60
143
  fs.writeFileSync(filePath, template.trim() + "\n");
61
- console.log(`\x1B[32m\u2713 Created ${filename}\x1B[0m`);
144
+ console.log(`\x1B[32m \u2713 Created ${filename}\x1B[0m`);
145
+ return true;
146
+ }
147
+ function init() {
148
+ const projectRoot = findProjectRoot();
149
+ console.log("\x1B[1m\n\u{1F680} Initializing AuraBase...\x1B[0m\n");
150
+ createFile(projectRoot, "lib/aurabase.ts");
151
+ createFile(projectRoot, "lib/api-client.ts");
62
152
  console.log("\x1B[36m%s\x1B[0m", ENV_TEMPLATE);
63
153
  }
64
154
  function showHelp() {
@@ -66,19 +156,11 @@ function showHelp() {
66
156
  \x1B[1mAuraBase JS CLI\x1B[0m
67
157
 
68
158
  \x1B[1mUsage:\x1B[0m
69
- npx aurabase-js init [options]
70
-
71
- \x1B[1mCommands:\x1B[0m
72
- init Create lib/aurabase.ts file
73
- init --supabase Create lib/supabase.ts file (alias name)
159
+ npx aurabase-js init
74
160
 
75
161
  \x1B[1mOptions:\x1B[0m
76
162
  -h, --help Show this help message
77
163
  -v, --version Show version
78
-
79
- \x1B[1mExamples:\x1B[0m
80
- npx aurabase-js init
81
- npx aurabase-js init --supabase
82
164
  `);
83
165
  }
84
166
  function showVersion() {
@@ -97,9 +179,7 @@ function main() {
97
179
  return;
98
180
  }
99
181
  if (args[0] === "init") {
100
- const useSupabase = args.includes("--supabase");
101
- const filename = useSupabase ? "lib/supabase.ts" : "lib/aurabase.ts";
102
- init(filename);
182
+ init();
103
183
  return;
104
184
  }
105
185
  console.log(`\x1B[31mUnknown command: ${args[0]}\x1B[0m`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aurabase-js",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "AuraBase client library - Supabase-style SDK for AuraBase",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/cli.ts CHANGED
@@ -6,7 +6,7 @@ import * as path from 'path';
6
6
  const TEMPLATES = {
7
7
  'lib/aurabase.ts': `import { createClient } from 'aurabase-js';
8
8
 
9
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
9
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
10
10
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
11
11
 
12
12
  export const aurabase = createClient({
@@ -14,25 +14,105 @@ export const aurabase = createClient({
14
14
  anonKey: AURABASE_ANON_KEY,
15
15
  });
16
16
  `,
17
- 'lib/supabase.ts': `import { createClient } from 'aurabase-js';
17
+ 'lib/api-client.ts': `import { NextRequest, NextResponse } from 'next/server';
18
18
 
19
- const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || 'https://your-project.cloudfront.net';
19
+ const AURABASE_URL = process.env.NEXT_PUBLIC_AURABASE_URL || '';
20
20
  const AURABASE_ANON_KEY = process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '';
21
21
 
22
- export const supabase = createClient({
23
- url: AURABASE_URL,
24
- anonKey: AURABASE_ANON_KEY,
25
- });
22
+ /**
23
+ * 서버 사이드 API 프록시 유틸리티
24
+ */
25
+ export async function proxyApiRequest(
26
+ req: NextRequest,
27
+ path: string
28
+ ): Promise<NextResponse> {
29
+ const accessToken = req.cookies.get('access_token')?.value;
30
+ const authToken = accessToken || AURABASE_ANON_KEY;
31
+
32
+ let body: string | undefined;
33
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
34
+ body = await req.text();
35
+ }
36
+
37
+ const headers: Record<string, string> = {
38
+ 'Content-Type': 'application/json',
39
+ };
40
+ if (authToken) {
41
+ headers['Authorization'] = \`Bearer \${authToken}\`;
42
+ }
26
43
 
27
- // Alias for backward compatibility
28
- export const aurabase = supabase;
44
+ const fetchOptions: RequestInit = {
45
+ method: req.method,
46
+ headers,
47
+ };
48
+ if (body) {
49
+ fetchOptions.body = body;
50
+ }
51
+
52
+ const res = await fetch(\`\${AURABASE_URL}\${path}\`, fetchOptions);
53
+ const data = await res.text();
54
+ return new NextResponse(data, {
55
+ status: res.status,
56
+ headers: { 'Content-Type': 'application/json' },
57
+ });
58
+ }
59
+
60
+ /**
61
+ * 클라이언트용 fetch 래퍼
62
+ */
63
+ export function createApiClient(baseUrl: string = '') {
64
+ return {
65
+ async get<T>(path: string): Promise<T> {
66
+ const res = await fetch(\`\${baseUrl}\${path}\`, { credentials: 'include' });
67
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
68
+ return res.json();
69
+ },
70
+
71
+ async post<T>(path: string, data?: unknown): Promise<T> {
72
+ const options: RequestInit = {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json' },
75
+ credentials: 'include',
76
+ };
77
+ if (data) options.body = JSON.stringify(data);
78
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
79
+ if (!res.ok) {
80
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
81
+ throw error;
82
+ }
83
+ return res.json();
84
+ },
85
+
86
+ async put<T>(path: string, data?: unknown): Promise<T> {
87
+ const options: RequestInit = {
88
+ method: 'PUT',
89
+ headers: { 'Content-Type': 'application/json' },
90
+ credentials: 'include',
91
+ };
92
+ if (data) options.body = JSON.stringify(data);
93
+ const res = await fetch(\`\${baseUrl}\${path}\`, options);
94
+ if (!res.ok) {
95
+ const error = await res.json().catch(() => ({ error: 'Unknown error' }));
96
+ throw error;
97
+ }
98
+ return res.json();
99
+ },
100
+
101
+ async delete<T>(path: string): Promise<T> {
102
+ const res = await fetch(\`\${baseUrl}\${path}\`, {
103
+ method: 'DELETE',
104
+ credentials: 'include',
105
+ });
106
+ if (!res.ok) throw new Error(\`API Error: \${res.status}\`);
107
+ return res.json();
108
+ },
109
+ };
110
+ }
29
111
  `,
30
112
  };
31
113
 
32
114
  const ENV_TEMPLATE = `
33
- # AuraBase Configuration
34
- # Add these to your .env.local file:
35
-
115
+ # AuraBase Configuration (.env.local)
36
116
  NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
37
117
  NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
38
118
  `;
@@ -48,30 +128,38 @@ function findProjectRoot(): string {
48
128
  return process.cwd();
49
129
  }
50
130
 
51
- function init(filename: string = 'lib/aurabase.ts') {
52
- const projectRoot = findProjectRoot();
131
+ function createFile(projectRoot: string, filename: string): boolean {
53
132
  const filePath = path.join(projectRoot, filename);
54
133
  const dir = path.dirname(filePath);
55
134
 
56
- // Create directory if it doesn't exist
57
135
  if (!fs.existsSync(dir)) {
58
136
  fs.mkdirSync(dir, { recursive: true });
59
137
  }
60
138
 
61
- // Check if file already exists
62
139
  if (fs.existsSync(filePath)) {
63
- console.log(`\x1b[33m⚠ ${filename} already exists. Skipping...\x1b[0m`);
64
- return;
140
+ console.log(`\x1b[33m ⚠ ${filename} already exists. Skipping...\x1b[0m`);
141
+ return false;
65
142
  }
66
143
 
67
- // Get template content
68
- const template = TEMPLATES[filename as keyof typeof TEMPLATES] || TEMPLATES['lib/aurabase.ts'];
144
+ const template = TEMPLATES[filename as keyof typeof TEMPLATES];
145
+ if (!template) {
146
+ console.log(`\x1b[31m ✗ Unknown template: ${filename}\x1b[0m`);
147
+ return false;
148
+ }
69
149
 
70
- // Write file
71
150
  fs.writeFileSync(filePath, template.trim() + '\n');
72
- console.log(`\x1b[32m✓ Created ${filename}\x1b[0m`);
151
+ console.log(`\x1b[32m ✓ Created ${filename}\x1b[0m`);
152
+ return true;
153
+ }
154
+
155
+ function init() {
156
+ const projectRoot = findProjectRoot();
157
+
158
+ console.log('\x1b[1m\n🚀 Initializing AuraBase...\x1b[0m\n');
159
+
160
+ createFile(projectRoot, 'lib/aurabase.ts');
161
+ createFile(projectRoot, 'lib/api-client.ts');
73
162
 
74
- // Show env template
75
163
  console.log('\x1b[36m%s\x1b[0m', ENV_TEMPLATE);
76
164
  }
77
165
 
@@ -80,19 +168,11 @@ function showHelp() {
80
168
  \x1b[1mAuraBase JS CLI\x1b[0m
81
169
 
82
170
  \x1b[1mUsage:\x1b[0m
83
- npx aurabase-js init [options]
84
-
85
- \x1b[1mCommands:\x1b[0m
86
- init Create lib/aurabase.ts file
87
- init --supabase Create lib/supabase.ts file (alias name)
171
+ npx aurabase-js init
88
172
 
89
173
  \x1b[1mOptions:\x1b[0m
90
174
  -h, --help Show this help message
91
175
  -v, --version Show version
92
-
93
- \x1b[1mExamples:\x1b[0m
94
- npx aurabase-js init
95
- npx aurabase-js init --supabase
96
176
  `);
97
177
  }
98
178
 
@@ -116,9 +196,7 @@ function main() {
116
196
  }
117
197
 
118
198
  if (args[0] === 'init') {
119
- const useSupabase = args.includes('--supabase');
120
- const filename = useSupabase ? 'lib/supabase.ts' : 'lib/aurabase.ts';
121
- init(filename);
199
+ init();
122
200
  return;
123
201
  }
124
202