aurabase-js 0.5.0 → 0.7.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/.omc/state/hud-stdin-cache.json +1 -1
- package/dist/cli.js +39 -94
- package/dist/cli.mjs +39 -94
- package/package.json +1 -1
- package/src/cli.ts +39 -94
|
@@ -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":
|
|
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":3.3941639999999995,"total_duration_ms":2016455,"total_api_duration_ms":968316,"total_lines_added":378,"total_lines_removed":170},"context_window":{"total_input_tokens":84534,"total_output_tokens":25270,"context_window_size":200000,"current_usage":{"input_tokens":278,"output_tokens":64,"cache_creation_input_tokens":0,"cache_read_input_tokens":90368},"used_percentage":45,"remaining_percentage":55},"exceeds_200k_tokens":false}
|
package/dist/cli.js
CHANGED
|
@@ -27,116 +27,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var fs = __toESM(require("fs"));
|
|
28
28
|
var path = __toESM(require("path"));
|
|
29
29
|
var TEMPLATES = {
|
|
30
|
-
"lib/
|
|
30
|
+
"lib/client.ts": `import { createClient } from 'aurabase-js';
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export const aurabase = createClient({
|
|
36
|
-
url: AURABASE_URL,
|
|
37
|
-
anonKey: AURABASE_ANON_KEY,
|
|
32
|
+
export const client = createClient({
|
|
33
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
34
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
38
35
|
});
|
|
39
36
|
`,
|
|
40
|
-
"lib/
|
|
37
|
+
"lib/server.ts": `import { createClient } from 'aurabase-js';
|
|
38
|
+
import { cookies } from 'next/headers';
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
const
|
|
40
|
+
export async function server() {
|
|
41
|
+
const cookieStore = await cookies();
|
|
42
|
+
const accessToken = cookieStore.get('access_token')?.value;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
}
|
|
44
|
+
const client = createClient({
|
|
45
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
46
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
47
|
+
});
|
|
66
48
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
headers,
|
|
70
|
-
};
|
|
71
|
-
if (body) {
|
|
72
|
-
fetchOptions.body = body;
|
|
49
|
+
if (accessToken) {
|
|
50
|
+
client.setAccessToken(accessToken);
|
|
73
51
|
}
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
const data = await res.text();
|
|
77
|
-
return new NextResponse(data, {
|
|
78
|
-
status: res.status,
|
|
79
|
-
headers: { 'Content-Type': 'application/json' },
|
|
80
|
-
});
|
|
53
|
+
return client;
|
|
81
54
|
}
|
|
55
|
+
`,
|
|
56
|
+
"lib/admin.ts": `import { createClient } from 'aurabase-js';
|
|
82
57
|
|
|
83
58
|
/**
|
|
84
|
-
*
|
|
59
|
+
* Admin client with service_role key
|
|
60
|
+
* \u26A0\uFE0F ONLY use on server-side (API routes, server components)
|
|
61
|
+
* \u26A0\uFE0F Bypasses all RLS policies - use with caution!
|
|
85
62
|
*/
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
},
|
|
108
|
-
|
|
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
|
-
}
|
|
63
|
+
export const admin = createClient({
|
|
64
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
65
|
+
anonKey: process.env.AURABASE_SERVICE_ROLE_KEY || '',
|
|
66
|
+
});
|
|
134
67
|
`
|
|
135
68
|
};
|
|
136
69
|
var ENV_TEMPLATE = `
|
|
137
70
|
# AuraBase Configuration (.env.local)
|
|
71
|
+
|
|
72
|
+
# Public keys (client + server)
|
|
138
73
|
NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
|
|
139
74
|
NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
|
|
75
|
+
|
|
76
|
+
# Service role key (server only - bypasses RLS!)
|
|
77
|
+
# \u26A0\uFE0F NEVER expose this to the client!
|
|
78
|
+
AURABASE_SERVICE_ROLE_KEY=your-service-role-key-here
|
|
140
79
|
`;
|
|
141
80
|
function findProjectRoot() {
|
|
142
81
|
let dir = process.cwd();
|
|
@@ -170,8 +109,9 @@ function createFile(projectRoot, filename) {
|
|
|
170
109
|
function init() {
|
|
171
110
|
const projectRoot = findProjectRoot();
|
|
172
111
|
console.log("\x1B[1m\n\u{1F680} Initializing AuraBase...\x1B[0m\n");
|
|
173
|
-
createFile(projectRoot, "lib/
|
|
174
|
-
createFile(projectRoot, "lib/
|
|
112
|
+
createFile(projectRoot, "lib/client.ts");
|
|
113
|
+
createFile(projectRoot, "lib/server.ts");
|
|
114
|
+
createFile(projectRoot, "lib/admin.ts");
|
|
175
115
|
console.log("\x1B[36m%s\x1B[0m", ENV_TEMPLATE);
|
|
176
116
|
}
|
|
177
117
|
function showHelp() {
|
|
@@ -184,6 +124,11 @@ function showHelp() {
|
|
|
184
124
|
\x1B[1mOptions:\x1B[0m
|
|
185
125
|
-h, --help Show this help message
|
|
186
126
|
-v, --version Show version
|
|
127
|
+
|
|
128
|
+
\x1B[1mGenerated files:\x1B[0m
|
|
129
|
+
lib/client.ts Browser client (anon key)
|
|
130
|
+
lib/server.ts Server client (with cookie auth)
|
|
131
|
+
lib/admin.ts Admin client (service role, bypasses RLS)
|
|
187
132
|
`);
|
|
188
133
|
}
|
|
189
134
|
function showVersion() {
|
package/dist/cli.mjs
CHANGED
|
@@ -4,116 +4,55 @@
|
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
6
|
var TEMPLATES = {
|
|
7
|
-
"lib/
|
|
7
|
+
"lib/client.ts": `import { createClient } from 'aurabase-js';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const aurabase = createClient({
|
|
13
|
-
url: AURABASE_URL,
|
|
14
|
-
anonKey: AURABASE_ANON_KEY,
|
|
9
|
+
export const client = createClient({
|
|
10
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
11
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
15
12
|
});
|
|
16
13
|
`,
|
|
17
|
-
"lib/
|
|
14
|
+
"lib/server.ts": `import { createClient } from 'aurabase-js';
|
|
15
|
+
import { cookies } from 'next/headers';
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
const
|
|
17
|
+
export async function server() {
|
|
18
|
+
const cookieStore = await cookies();
|
|
19
|
+
const accessToken = cookieStore.get('access_token')?.value;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
}
|
|
21
|
+
const client = createClient({
|
|
22
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
23
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
24
|
+
});
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers,
|
|
47
|
-
};
|
|
48
|
-
if (body) {
|
|
49
|
-
fetchOptions.body = body;
|
|
26
|
+
if (accessToken) {
|
|
27
|
+
client.setAccessToken(accessToken);
|
|
50
28
|
}
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
const data = await res.text();
|
|
54
|
-
return new NextResponse(data, {
|
|
55
|
-
status: res.status,
|
|
56
|
-
headers: { 'Content-Type': 'application/json' },
|
|
57
|
-
});
|
|
30
|
+
return client;
|
|
58
31
|
}
|
|
32
|
+
`,
|
|
33
|
+
"lib/admin.ts": `import { createClient } from 'aurabase-js';
|
|
59
34
|
|
|
60
35
|
/**
|
|
61
|
-
*
|
|
36
|
+
* Admin client with service_role key
|
|
37
|
+
* \u26A0\uFE0F ONLY use on server-side (API routes, server components)
|
|
38
|
+
* \u26A0\uFE0F Bypasses all RLS policies - use with caution!
|
|
62
39
|
*/
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
40
|
+
export const admin = createClient({
|
|
41
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
42
|
+
anonKey: process.env.AURABASE_SERVICE_ROLE_KEY || '',
|
|
43
|
+
});
|
|
111
44
|
`
|
|
112
45
|
};
|
|
113
46
|
var ENV_TEMPLATE = `
|
|
114
47
|
# AuraBase Configuration (.env.local)
|
|
48
|
+
|
|
49
|
+
# Public keys (client + server)
|
|
115
50
|
NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
|
|
116
51
|
NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
|
|
52
|
+
|
|
53
|
+
# Service role key (server only - bypasses RLS!)
|
|
54
|
+
# \u26A0\uFE0F NEVER expose this to the client!
|
|
55
|
+
AURABASE_SERVICE_ROLE_KEY=your-service-role-key-here
|
|
117
56
|
`;
|
|
118
57
|
function findProjectRoot() {
|
|
119
58
|
let dir = process.cwd();
|
|
@@ -147,8 +86,9 @@ function createFile(projectRoot, filename) {
|
|
|
147
86
|
function init() {
|
|
148
87
|
const projectRoot = findProjectRoot();
|
|
149
88
|
console.log("\x1B[1m\n\u{1F680} Initializing AuraBase...\x1B[0m\n");
|
|
150
|
-
createFile(projectRoot, "lib/
|
|
151
|
-
createFile(projectRoot, "lib/
|
|
89
|
+
createFile(projectRoot, "lib/client.ts");
|
|
90
|
+
createFile(projectRoot, "lib/server.ts");
|
|
91
|
+
createFile(projectRoot, "lib/admin.ts");
|
|
152
92
|
console.log("\x1B[36m%s\x1B[0m", ENV_TEMPLATE);
|
|
153
93
|
}
|
|
154
94
|
function showHelp() {
|
|
@@ -161,6 +101,11 @@ function showHelp() {
|
|
|
161
101
|
\x1B[1mOptions:\x1B[0m
|
|
162
102
|
-h, --help Show this help message
|
|
163
103
|
-v, --version Show version
|
|
104
|
+
|
|
105
|
+
\x1B[1mGenerated files:\x1B[0m
|
|
106
|
+
lib/client.ts Browser client (anon key)
|
|
107
|
+
lib/server.ts Server client (with cookie auth)
|
|
108
|
+
lib/admin.ts Admin client (service role, bypasses RLS)
|
|
164
109
|
`);
|
|
165
110
|
}
|
|
166
111
|
function showVersion() {
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -4,117 +4,56 @@ import * as fs from 'fs';
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
|
|
6
6
|
const TEMPLATES = {
|
|
7
|
-
'lib/
|
|
7
|
+
'lib/client.ts': `import { createClient } from 'aurabase-js';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const aurabase = createClient({
|
|
13
|
-
url: AURABASE_URL,
|
|
14
|
-
anonKey: AURABASE_ANON_KEY,
|
|
9
|
+
export const client = createClient({
|
|
10
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
11
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
15
12
|
});
|
|
16
13
|
`,
|
|
17
|
-
'lib/
|
|
14
|
+
'lib/server.ts': `import { createClient } from 'aurabase-js';
|
|
15
|
+
import { cookies } from 'next/headers';
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
const
|
|
17
|
+
export async function server() {
|
|
18
|
+
const cookieStore = await cookies();
|
|
19
|
+
const accessToken = cookieStore.get('access_token')?.value;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
}
|
|
21
|
+
const client = createClient({
|
|
22
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
23
|
+
anonKey: process.env.NEXT_PUBLIC_AURABASE_ANON_KEY || '',
|
|
24
|
+
});
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers,
|
|
47
|
-
};
|
|
48
|
-
if (body) {
|
|
49
|
-
fetchOptions.body = body;
|
|
26
|
+
if (accessToken) {
|
|
27
|
+
client.setAccessToken(accessToken);
|
|
50
28
|
}
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
const data = await res.text();
|
|
54
|
-
return new NextResponse(data, {
|
|
55
|
-
status: res.status,
|
|
56
|
-
headers: { 'Content-Type': 'application/json' },
|
|
57
|
-
});
|
|
30
|
+
return client;
|
|
58
31
|
}
|
|
32
|
+
`,
|
|
33
|
+
'lib/admin.ts': `import { createClient } from 'aurabase-js';
|
|
59
34
|
|
|
60
35
|
/**
|
|
61
|
-
*
|
|
36
|
+
* Admin client with service_role key
|
|
37
|
+
* ⚠️ ONLY use on server-side (API routes, server components)
|
|
38
|
+
* ⚠️ Bypasses all RLS policies - use with caution!
|
|
62
39
|
*/
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
40
|
+
export const admin = createClient({
|
|
41
|
+
url: process.env.NEXT_PUBLIC_AURABASE_URL || '',
|
|
42
|
+
anonKey: process.env.AURABASE_SERVICE_ROLE_KEY || '',
|
|
43
|
+
});
|
|
111
44
|
`,
|
|
112
45
|
};
|
|
113
46
|
|
|
114
47
|
const ENV_TEMPLATE = `
|
|
115
48
|
# AuraBase Configuration (.env.local)
|
|
49
|
+
|
|
50
|
+
# Public keys (client + server)
|
|
116
51
|
NEXT_PUBLIC_AURABASE_URL=https://your-project.cloudfront.net
|
|
117
52
|
NEXT_PUBLIC_AURABASE_ANON_KEY=your-anon-key-here
|
|
53
|
+
|
|
54
|
+
# Service role key (server only - bypasses RLS!)
|
|
55
|
+
# ⚠️ NEVER expose this to the client!
|
|
56
|
+
AURABASE_SERVICE_ROLE_KEY=your-service-role-key-here
|
|
118
57
|
`;
|
|
119
58
|
|
|
120
59
|
function findProjectRoot(): string {
|
|
@@ -157,8 +96,9 @@ function init() {
|
|
|
157
96
|
|
|
158
97
|
console.log('\x1b[1m\n🚀 Initializing AuraBase...\x1b[0m\n');
|
|
159
98
|
|
|
160
|
-
createFile(projectRoot, 'lib/
|
|
161
|
-
createFile(projectRoot, 'lib/
|
|
99
|
+
createFile(projectRoot, 'lib/client.ts');
|
|
100
|
+
createFile(projectRoot, 'lib/server.ts');
|
|
101
|
+
createFile(projectRoot, 'lib/admin.ts');
|
|
162
102
|
|
|
163
103
|
console.log('\x1b[36m%s\x1b[0m', ENV_TEMPLATE);
|
|
164
104
|
}
|
|
@@ -173,6 +113,11 @@ function showHelp() {
|
|
|
173
113
|
\x1b[1mOptions:\x1b[0m
|
|
174
114
|
-h, --help Show this help message
|
|
175
115
|
-v, --version Show version
|
|
116
|
+
|
|
117
|
+
\x1b[1mGenerated files:\x1b[0m
|
|
118
|
+
lib/client.ts Browser client (anon key)
|
|
119
|
+
lib/server.ts Server client (with cookie auth)
|
|
120
|
+
lib/admin.ts Admin client (service role, bypasses RLS)
|
|
176
121
|
`);
|
|
177
122
|
}
|
|
178
123
|
|