@robinpath/supabase 0.1.0 → 0.1.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 +121 -121
- package/package.json +35 -7
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/index.js.map +0 -1
- package/dist/supabase.d.ts +0 -361
- package/dist/supabase.d.ts.map +0 -1
- package/dist/supabase.js +0 -723
- package/dist/supabase.js.map +0 -1
package/dist/supabase.js
DELETED
|
@@ -1,723 +0,0 @@
|
|
|
1
|
-
const credentials = new Map();
|
|
2
|
-
function getCreds(profile) {
|
|
3
|
-
const key = profile ?? "__default__";
|
|
4
|
-
const c = credentials.get(key);
|
|
5
|
-
if (!c)
|
|
6
|
-
throw new Error(`Supabase not configured. Call setCredentials() first${profile ? ` for profile "${profile}"` : ""}.`);
|
|
7
|
-
return c;
|
|
8
|
-
}
|
|
9
|
-
function baseHeaders(apiKey, accessToken) {
|
|
10
|
-
return {
|
|
11
|
-
apikey: apiKey,
|
|
12
|
-
Authorization: `Bearer ${accessToken ?? apiKey}`,
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
async function supaFetch(url, init) {
|
|
17
|
-
const res = await fetch(url, init);
|
|
18
|
-
const text = await res.text();
|
|
19
|
-
let body;
|
|
20
|
-
try {
|
|
21
|
-
body = JSON.parse(text);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
body = text;
|
|
25
|
-
}
|
|
26
|
-
if (!res.ok) {
|
|
27
|
-
const msg = typeof body === "object" && body !== null && "message" in body
|
|
28
|
-
? body.message
|
|
29
|
-
: typeof body === "object" && body !== null && "error_description" in body
|
|
30
|
-
? body.error_description
|
|
31
|
-
: text;
|
|
32
|
-
throw new Error(`Supabase ${res.status}: ${msg}`);
|
|
33
|
-
}
|
|
34
|
-
return body;
|
|
35
|
-
}
|
|
36
|
-
// ── helpers ─────────────────────────────────────────────────────────────────
|
|
37
|
-
function buildPostgrestQuery(baseUrl, table, options) {
|
|
38
|
-
let url = `${baseUrl}/rest/v1/${encodeURIComponent(table)}`;
|
|
39
|
-
if (!options)
|
|
40
|
-
return url;
|
|
41
|
-
const params = [];
|
|
42
|
-
// columns
|
|
43
|
-
if (options.columns)
|
|
44
|
-
params.push(`select=${encodeURIComponent(String(options.columns))}`);
|
|
45
|
-
// filters: eq, neq, gt, lt, gte, lte, like, ilike, in, is
|
|
46
|
-
const filterOps = ["eq", "neq", "gt", "lt", "gte", "lte", "like", "ilike", "in", "is"];
|
|
47
|
-
for (const op of filterOps) {
|
|
48
|
-
if (options[op] && typeof options[op] === "object") {
|
|
49
|
-
const filters = options[op];
|
|
50
|
-
for (const [col, val] of Object.entries(filters)) {
|
|
51
|
-
if (op === "in") {
|
|
52
|
-
const arr = Array.isArray(val) ? val : [val];
|
|
53
|
-
params.push(`${encodeURIComponent(col)}=in.(${arr.map((v) => encodeURIComponent(String(v))).join(",")})`);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
params.push(`${encodeURIComponent(col)}=${op}.${encodeURIComponent(String(val))}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// order
|
|
62
|
-
if (options.order) {
|
|
63
|
-
if (typeof options.order === "string") {
|
|
64
|
-
params.push(`order=${encodeURIComponent(options.order)}`);
|
|
65
|
-
}
|
|
66
|
-
else if (typeof options.order === "object" && !Array.isArray(options.order)) {
|
|
67
|
-
const o = options.order;
|
|
68
|
-
const col = o.column ?? o.col;
|
|
69
|
-
const dir = o.ascending === false || o.desc === true ? "desc" : "asc";
|
|
70
|
-
const nulls = o.nullsFirst ? ".nullsfirst" : "";
|
|
71
|
-
params.push(`order=${encodeURIComponent(String(col))}.${dir}${nulls}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// limit & offset
|
|
75
|
-
if (options.limit !== undefined)
|
|
76
|
-
params.push(`limit=${Number(options.limit)}`);
|
|
77
|
-
if (options.offset !== undefined)
|
|
78
|
-
params.push(`offset=${Number(options.offset)}`);
|
|
79
|
-
if (params.length > 0)
|
|
80
|
-
url += `?${params.join("&")}`;
|
|
81
|
-
return url;
|
|
82
|
-
}
|
|
83
|
-
function buildMatchParams(match) {
|
|
84
|
-
const parts = [];
|
|
85
|
-
for (const [col, val] of Object.entries(match)) {
|
|
86
|
-
parts.push(`${encodeURIComponent(col)}=eq.${encodeURIComponent(String(val))}`);
|
|
87
|
-
}
|
|
88
|
-
return parts.join("&");
|
|
89
|
-
}
|
|
90
|
-
// ── functions ───────────────────────────────────────────────────────────────
|
|
91
|
-
export const SupabaseFunctions = {
|
|
92
|
-
// ── credentials ─────────────────────────────────────────────────────────
|
|
93
|
-
setCredentials: (args) => {
|
|
94
|
-
const projectUrl = String(args[0]);
|
|
95
|
-
const apiKey = String(args[1]);
|
|
96
|
-
const profile = args[2] != null ? String(args[2]) : "__default__";
|
|
97
|
-
const url = projectUrl.replace(/\/+$/, "");
|
|
98
|
-
credentials.set(profile, { projectUrl: url, apiKey });
|
|
99
|
-
return { success: true, profile };
|
|
100
|
-
},
|
|
101
|
-
setServiceKey: (args) => {
|
|
102
|
-
const projectUrl = String(args[0]);
|
|
103
|
-
const serviceKey = String(args[1]);
|
|
104
|
-
const profile = args[2] != null ? String(args[2]) : "__default__";
|
|
105
|
-
const url = projectUrl.replace(/\/+$/, "");
|
|
106
|
-
const existing = credentials.get(profile);
|
|
107
|
-
if (existing) {
|
|
108
|
-
existing.serviceKey = serviceKey;
|
|
109
|
-
existing.projectUrl = url;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
credentials.set(profile, { projectUrl: url, apiKey: serviceKey, serviceKey });
|
|
113
|
-
}
|
|
114
|
-
return { success: true, profile };
|
|
115
|
-
},
|
|
116
|
-
// ── PostgREST (database) ───────────────────────────────────────────────
|
|
117
|
-
select: async (args) => {
|
|
118
|
-
const table = String(args[0]);
|
|
119
|
-
const columns = args[1] != null ? String(args[1]) : undefined;
|
|
120
|
-
const options = args[2] ?? {};
|
|
121
|
-
const creds = getCreds(options.profile);
|
|
122
|
-
const opts = { ...options };
|
|
123
|
-
if (columns)
|
|
124
|
-
opts.columns = columns;
|
|
125
|
-
const url = buildPostgrestQuery(creds.projectUrl, table, opts);
|
|
126
|
-
const headers = baseHeaders(creds.apiKey);
|
|
127
|
-
// range header
|
|
128
|
-
if (options.range && typeof options.range === "string") {
|
|
129
|
-
headers["Range"] = options.range;
|
|
130
|
-
headers["Range-Unit"] = "items";
|
|
131
|
-
}
|
|
132
|
-
return supaFetch(url, { method: "GET", headers });
|
|
133
|
-
},
|
|
134
|
-
insert: async (args) => {
|
|
135
|
-
const table = String(args[0]);
|
|
136
|
-
const data = args[1];
|
|
137
|
-
const options = args[2] ?? {};
|
|
138
|
-
const creds = getCreds(options.profile);
|
|
139
|
-
let url = `${creds.projectUrl}/rest/v1/${encodeURIComponent(table)}`;
|
|
140
|
-
if (options.columns)
|
|
141
|
-
url += `?columns=${encodeURIComponent(String(options.columns))}`;
|
|
142
|
-
const headers = baseHeaders(creds.apiKey);
|
|
143
|
-
if (options.returning !== false)
|
|
144
|
-
headers["Prefer"] = "return=representation";
|
|
145
|
-
if (options.onConflict) {
|
|
146
|
-
headers["Prefer"] = `return=representation,resolution=merge-duplicates`;
|
|
147
|
-
url += `${url.includes("?") ? "&" : "?"}on_conflict=${encodeURIComponent(String(options.onConflict))}`;
|
|
148
|
-
}
|
|
149
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(data) });
|
|
150
|
-
},
|
|
151
|
-
update: async (args) => {
|
|
152
|
-
const table = String(args[0]);
|
|
153
|
-
const data = args[1];
|
|
154
|
-
const match = args[2] ?? {};
|
|
155
|
-
const options = args[3] ?? {};
|
|
156
|
-
const creds = getCreds(options.profile);
|
|
157
|
-
const matchStr = buildMatchParams(match);
|
|
158
|
-
let url = `${creds.projectUrl}/rest/v1/${encodeURIComponent(table)}?${matchStr}`;
|
|
159
|
-
const headers = baseHeaders(creds.apiKey);
|
|
160
|
-
headers["Prefer"] = "return=representation";
|
|
161
|
-
return supaFetch(url, { method: "PATCH", headers, body: JSON.stringify(data) });
|
|
162
|
-
},
|
|
163
|
-
upsert: async (args) => {
|
|
164
|
-
const table = String(args[0]);
|
|
165
|
-
const data = args[1];
|
|
166
|
-
const options = args[2] ?? {};
|
|
167
|
-
const creds = getCreds(options.profile);
|
|
168
|
-
let url = `${creds.projectUrl}/rest/v1/${encodeURIComponent(table)}`;
|
|
169
|
-
const headers = baseHeaders(creds.apiKey);
|
|
170
|
-
headers["Prefer"] = "return=representation,resolution=merge-duplicates";
|
|
171
|
-
if (options.onConflict) {
|
|
172
|
-
url += `?on_conflict=${encodeURIComponent(String(options.onConflict))}`;
|
|
173
|
-
}
|
|
174
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(data) });
|
|
175
|
-
},
|
|
176
|
-
delete: async (args) => {
|
|
177
|
-
const table = String(args[0]);
|
|
178
|
-
const match = args[1] ?? {};
|
|
179
|
-
const options = args[2] ?? {};
|
|
180
|
-
const creds = getCreds(options.profile);
|
|
181
|
-
const matchStr = buildMatchParams(match);
|
|
182
|
-
let url = `${creds.projectUrl}/rest/v1/${encodeURIComponent(table)}?${matchStr}`;
|
|
183
|
-
const headers = baseHeaders(creds.apiKey);
|
|
184
|
-
headers["Prefer"] = "return=representation";
|
|
185
|
-
return supaFetch(url, { method: "DELETE", headers });
|
|
186
|
-
},
|
|
187
|
-
rpc: async (args) => {
|
|
188
|
-
const functionName = String(args[0]);
|
|
189
|
-
const params = args[1] ?? {};
|
|
190
|
-
const options = args[2] ?? {};
|
|
191
|
-
const creds = getCreds(options.profile);
|
|
192
|
-
const url = `${creds.projectUrl}/rest/v1/rpc/${encodeURIComponent(functionName)}`;
|
|
193
|
-
const headers = baseHeaders(creds.apiKey);
|
|
194
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(params) });
|
|
195
|
-
},
|
|
196
|
-
// ── Auth ────────────────────────────────────────────────────────────────
|
|
197
|
-
signUp: async (args) => {
|
|
198
|
-
const email = String(args[0]);
|
|
199
|
-
const password = String(args[1]);
|
|
200
|
-
const options = args[2] ?? {};
|
|
201
|
-
const creds = getCreds(options.profile);
|
|
202
|
-
const url = `${creds.projectUrl}/auth/v1/signup`;
|
|
203
|
-
const headers = baseHeaders(creds.apiKey);
|
|
204
|
-
const payload = { email, password };
|
|
205
|
-
if (options.data)
|
|
206
|
-
payload.data = options.data;
|
|
207
|
-
if (options.emailRedirectTo)
|
|
208
|
-
payload.gotrue_meta_security = { captcha_token: undefined };
|
|
209
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
|
|
210
|
-
},
|
|
211
|
-
signIn: async (args) => {
|
|
212
|
-
const email = String(args[0]);
|
|
213
|
-
const password = String(args[1]);
|
|
214
|
-
const options = args[2] ?? {};
|
|
215
|
-
const creds = getCreds(options.profile);
|
|
216
|
-
const url = `${creds.projectUrl}/auth/v1/token?grant_type=password`;
|
|
217
|
-
const headers = baseHeaders(creds.apiKey);
|
|
218
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify({ email, password }) });
|
|
219
|
-
},
|
|
220
|
-
signInWithOtp: async (args) => {
|
|
221
|
-
const email = String(args[0]);
|
|
222
|
-
const options = args[1] ?? {};
|
|
223
|
-
const creds = getCreds(options.profile);
|
|
224
|
-
const url = `${creds.projectUrl}/auth/v1/otp`;
|
|
225
|
-
const headers = baseHeaders(creds.apiKey);
|
|
226
|
-
const payload = { email };
|
|
227
|
-
if (options.emailRedirectTo)
|
|
228
|
-
payload.gotrue_meta_security = { captcha_token: undefined };
|
|
229
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
|
|
230
|
-
},
|
|
231
|
-
signOut: async (args) => {
|
|
232
|
-
const accessToken = String(args[0]);
|
|
233
|
-
const options = args[1] ?? {};
|
|
234
|
-
const creds = getCreds(options.profile);
|
|
235
|
-
const url = `${creds.projectUrl}/auth/v1/logout`;
|
|
236
|
-
const headers = baseHeaders(creds.apiKey, accessToken);
|
|
237
|
-
return supaFetch(url, { method: "POST", headers });
|
|
238
|
-
},
|
|
239
|
-
getUser: async (args) => {
|
|
240
|
-
const accessToken = String(args[0]);
|
|
241
|
-
const options = args[1] ?? {};
|
|
242
|
-
const creds = getCreds(options.profile);
|
|
243
|
-
const url = `${creds.projectUrl}/auth/v1/user`;
|
|
244
|
-
const headers = baseHeaders(creds.apiKey, accessToken);
|
|
245
|
-
return supaFetch(url, { method: "GET", headers });
|
|
246
|
-
},
|
|
247
|
-
updateUser: async (args) => {
|
|
248
|
-
const accessToken = String(args[0]);
|
|
249
|
-
const attributes = args[1];
|
|
250
|
-
const options = args[2] ?? {};
|
|
251
|
-
const creds = getCreds(options.profile);
|
|
252
|
-
const url = `${creds.projectUrl}/auth/v1/user`;
|
|
253
|
-
const headers = baseHeaders(creds.apiKey, accessToken);
|
|
254
|
-
return supaFetch(url, { method: "PUT", headers, body: JSON.stringify(attributes) });
|
|
255
|
-
},
|
|
256
|
-
listUsers: async (args) => {
|
|
257
|
-
const options = args[0] ?? {};
|
|
258
|
-
const creds = getCreds(options.profile);
|
|
259
|
-
const serviceKey = creds.serviceKey ?? creds.apiKey;
|
|
260
|
-
const params = [];
|
|
261
|
-
if (options.page !== undefined)
|
|
262
|
-
params.push(`page=${Number(options.page)}`);
|
|
263
|
-
if (options.perPage !== undefined)
|
|
264
|
-
params.push(`per_page=${Number(options.perPage)}`);
|
|
265
|
-
const qs = params.length > 0 ? `?${params.join("&")}` : "";
|
|
266
|
-
const url = `${creds.projectUrl}/auth/v1/admin/users${qs}`;
|
|
267
|
-
const headers = baseHeaders(serviceKey);
|
|
268
|
-
return supaFetch(url, { method: "GET", headers });
|
|
269
|
-
},
|
|
270
|
-
deleteUser: async (args) => {
|
|
271
|
-
const userId = String(args[0]);
|
|
272
|
-
const options = args[1] ?? {};
|
|
273
|
-
const creds = getCreds(options.profile);
|
|
274
|
-
const serviceKey = creds.serviceKey ?? creds.apiKey;
|
|
275
|
-
const url = `${creds.projectUrl}/auth/v1/admin/users/${encodeURIComponent(userId)}`;
|
|
276
|
-
const headers = baseHeaders(serviceKey);
|
|
277
|
-
return supaFetch(url, { method: "DELETE", headers });
|
|
278
|
-
},
|
|
279
|
-
inviteUser: async (args) => {
|
|
280
|
-
const email = String(args[0]);
|
|
281
|
-
const options = args[1] ?? {};
|
|
282
|
-
const creds = getCreds(options.profile);
|
|
283
|
-
const serviceKey = creds.serviceKey ?? creds.apiKey;
|
|
284
|
-
const url = `${creds.projectUrl}/auth/v1/invite`;
|
|
285
|
-
const headers = baseHeaders(serviceKey);
|
|
286
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify({ email }) });
|
|
287
|
-
},
|
|
288
|
-
// ── Storage ─────────────────────────────────────────────────────────────
|
|
289
|
-
listBuckets: async (args) => {
|
|
290
|
-
const options = args[0] ?? {};
|
|
291
|
-
const creds = getCreds(options.profile);
|
|
292
|
-
const url = `${creds.projectUrl}/storage/v1/bucket`;
|
|
293
|
-
const headers = baseHeaders(creds.apiKey);
|
|
294
|
-
return supaFetch(url, { method: "GET", headers });
|
|
295
|
-
},
|
|
296
|
-
createBucket: async (args) => {
|
|
297
|
-
const name = String(args[0]);
|
|
298
|
-
const options = args[1] ?? {};
|
|
299
|
-
const creds = getCreds(options.profile);
|
|
300
|
-
const url = `${creds.projectUrl}/storage/v1/bucket`;
|
|
301
|
-
const headers = baseHeaders(creds.apiKey);
|
|
302
|
-
const payload = { name, id: name };
|
|
303
|
-
if (options.public !== undefined)
|
|
304
|
-
payload.public = Boolean(options.public);
|
|
305
|
-
if (options.fileSizeLimit !== undefined)
|
|
306
|
-
payload.file_size_limit = Number(options.fileSizeLimit);
|
|
307
|
-
if (options.allowedMimeTypes)
|
|
308
|
-
payload.allowed_mime_types = options.allowedMimeTypes;
|
|
309
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
|
|
310
|
-
},
|
|
311
|
-
deleteBucket: async (args) => {
|
|
312
|
-
const bucketId = String(args[0]);
|
|
313
|
-
const options = args[1] ?? {};
|
|
314
|
-
const creds = getCreds(options.profile);
|
|
315
|
-
const url = `${creds.projectUrl}/storage/v1/bucket/${encodeURIComponent(bucketId)}`;
|
|
316
|
-
const headers = baseHeaders(creds.apiKey);
|
|
317
|
-
return supaFetch(url, { method: "DELETE", headers });
|
|
318
|
-
},
|
|
319
|
-
emptyBucket: async (args) => {
|
|
320
|
-
const bucketId = String(args[0]);
|
|
321
|
-
const options = args[1] ?? {};
|
|
322
|
-
const creds = getCreds(options.profile);
|
|
323
|
-
const url = `${creds.projectUrl}/storage/v1/bucket/${encodeURIComponent(bucketId)}/empty`;
|
|
324
|
-
const headers = baseHeaders(creds.apiKey);
|
|
325
|
-
return supaFetch(url, { method: "POST", headers });
|
|
326
|
-
},
|
|
327
|
-
listFiles: async (args) => {
|
|
328
|
-
const bucketId = String(args[0]);
|
|
329
|
-
const folderPath = args[1] != null ? String(args[1]) : "";
|
|
330
|
-
const options = args[2] ?? {};
|
|
331
|
-
const creds = getCreds(options.profile);
|
|
332
|
-
const url = `${creds.projectUrl}/storage/v1/object/list/${encodeURIComponent(bucketId)}`;
|
|
333
|
-
const headers = baseHeaders(creds.apiKey);
|
|
334
|
-
const payload = { prefix: folderPath };
|
|
335
|
-
if (options.limit !== undefined)
|
|
336
|
-
payload.limit = Number(options.limit);
|
|
337
|
-
if (options.offset !== undefined)
|
|
338
|
-
payload.offset = Number(options.offset);
|
|
339
|
-
if (options.sortBy)
|
|
340
|
-
payload.sortBy = options.sortBy;
|
|
341
|
-
if (options.search)
|
|
342
|
-
payload.search = String(options.search);
|
|
343
|
-
return supaFetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
|
|
344
|
-
},
|
|
345
|
-
uploadFile: async (args) => {
|
|
346
|
-
const bucketId = String(args[0]);
|
|
347
|
-
const filePath = String(args[1]);
|
|
348
|
-
const content = args[2];
|
|
349
|
-
const options = args[3] ?? {};
|
|
350
|
-
const creds = getCreds(options.profile);
|
|
351
|
-
const url = `${creds.projectUrl}/storage/v1/object/${encodeURIComponent(bucketId)}/${filePath}`;
|
|
352
|
-
const headers = {
|
|
353
|
-
apikey: creds.apiKey,
|
|
354
|
-
Authorization: `Bearer ${creds.apiKey}`,
|
|
355
|
-
};
|
|
356
|
-
if (options.contentType) {
|
|
357
|
-
headers["Content-Type"] = String(options.contentType);
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
headers["Content-Type"] = "application/octet-stream";
|
|
361
|
-
}
|
|
362
|
-
if (options.upsert) {
|
|
363
|
-
headers["x-upsert"] = "true";
|
|
364
|
-
}
|
|
365
|
-
const body = typeof content === "string" ? content : JSON.stringify(content);
|
|
366
|
-
return supaFetch(url, { method: "POST", headers, body });
|
|
367
|
-
},
|
|
368
|
-
downloadFile: async (args) => {
|
|
369
|
-
const bucketId = String(args[0]);
|
|
370
|
-
const filePath = String(args[1]);
|
|
371
|
-
const options = args[2] ?? {};
|
|
372
|
-
const creds = getCreds(options.profile);
|
|
373
|
-
const url = `${creds.projectUrl}/storage/v1/object/${encodeURIComponent(bucketId)}/${filePath}`;
|
|
374
|
-
const headers = {
|
|
375
|
-
apikey: creds.apiKey,
|
|
376
|
-
Authorization: `Bearer ${creds.apiKey}`,
|
|
377
|
-
};
|
|
378
|
-
const res = await fetch(url, { method: "GET", headers });
|
|
379
|
-
if (!res.ok) {
|
|
380
|
-
const text = await res.text();
|
|
381
|
-
throw new Error(`Supabase ${res.status}: ${text}`);
|
|
382
|
-
}
|
|
383
|
-
return await res.text();
|
|
384
|
-
},
|
|
385
|
-
deleteFile: async (args) => {
|
|
386
|
-
const bucketId = String(args[0]);
|
|
387
|
-
const paths = args[1];
|
|
388
|
-
const options = args[2] ?? {};
|
|
389
|
-
const creds = getCreds(options.profile);
|
|
390
|
-
const url = `${creds.projectUrl}/storage/v1/object/${encodeURIComponent(bucketId)}`;
|
|
391
|
-
const headers = baseHeaders(creds.apiKey);
|
|
392
|
-
return supaFetch(url, { method: "DELETE", headers, body: JSON.stringify({ prefixes: paths }) });
|
|
393
|
-
},
|
|
394
|
-
getPublicUrl: (args) => {
|
|
395
|
-
const bucketId = String(args[0]);
|
|
396
|
-
const filePath = String(args[1]);
|
|
397
|
-
const options = args[2] ?? {};
|
|
398
|
-
const creds = getCreds(options.profile);
|
|
399
|
-
const url = `${creds.projectUrl}/storage/v1/object/public/${encodeURIComponent(bucketId)}/${filePath}`;
|
|
400
|
-
return { publicUrl: url };
|
|
401
|
-
},
|
|
402
|
-
createSignedUrl: async (args) => {
|
|
403
|
-
const bucketId = String(args[0]);
|
|
404
|
-
const filePath = String(args[1]);
|
|
405
|
-
const expiresIn = Number(args[2]);
|
|
406
|
-
const options = args[3] ?? {};
|
|
407
|
-
const creds = getCreds(options.profile);
|
|
408
|
-
const url = `${creds.projectUrl}/storage/v1/object/sign/${encodeURIComponent(bucketId)}/${filePath}`;
|
|
409
|
-
const headers = baseHeaders(creds.apiKey);
|
|
410
|
-
const result = await supaFetch(url, {
|
|
411
|
-
method: "POST",
|
|
412
|
-
headers,
|
|
413
|
-
body: JSON.stringify({ expiresIn }),
|
|
414
|
-
});
|
|
415
|
-
const signedURL = result.signedURL ?? result.signedUrl ?? result.signed_url;
|
|
416
|
-
return {
|
|
417
|
-
signedUrl: signedURL ? `${creds.projectUrl}/storage/v1${signedURL}` : null,
|
|
418
|
-
expiresIn,
|
|
419
|
-
};
|
|
420
|
-
},
|
|
421
|
-
};
|
|
422
|
-
// ── function metadata ───────────────────────────────────────────────────────
|
|
423
|
-
export const SupabaseFunctionMetadata = {
|
|
424
|
-
// ── credentials ─────────────────────────────────────────────────────────
|
|
425
|
-
setCredentials: {
|
|
426
|
-
description: "Store Supabase project URL and anon/service API key",
|
|
427
|
-
parameters: [
|
|
428
|
-
{ name: "projectUrl", dataType: "string", description: "Supabase project URL (e.g. https://xyz.supabase.co)", formInputType: "text", required: true },
|
|
429
|
-
{ name: "apiKey", dataType: "string", description: "Supabase anon or service_role key", formInputType: "text", required: true },
|
|
430
|
-
{ name: "profile", dataType: "string", description: "Optional credential profile name", formInputType: "text", required: false },
|
|
431
|
-
],
|
|
432
|
-
returnType: "object",
|
|
433
|
-
returnDescription: "{ success, profile }",
|
|
434
|
-
example: 'supabase.setCredentials "https://xyz.supabase.co" "eyJhbGc..."',
|
|
435
|
-
},
|
|
436
|
-
setServiceKey: {
|
|
437
|
-
description: "Store a service role key for admin operations (Auth admin, etc.)",
|
|
438
|
-
parameters: [
|
|
439
|
-
{ name: "projectUrl", dataType: "string", description: "Supabase project URL", formInputType: "text", required: true },
|
|
440
|
-
{ name: "serviceKey", dataType: "string", description: "Supabase service_role key", formInputType: "text", required: true },
|
|
441
|
-
{ name: "profile", dataType: "string", description: "Optional credential profile name", formInputType: "text", required: false },
|
|
442
|
-
],
|
|
443
|
-
returnType: "object",
|
|
444
|
-
returnDescription: "{ success, profile }",
|
|
445
|
-
example: 'supabase.setServiceKey "https://xyz.supabase.co" "eyJhbGc..."',
|
|
446
|
-
},
|
|
447
|
-
// ── PostgREST (database) ───────────────────────────────────────────────
|
|
448
|
-
select: {
|
|
449
|
-
description: "Select rows from a table with optional filters, ordering, and pagination",
|
|
450
|
-
parameters: [
|
|
451
|
-
{ name: "table", dataType: "string", description: "Table name", formInputType: "text", required: true },
|
|
452
|
-
{ name: "columns", dataType: "string", description: "Comma-separated column names or * (default *)", formInputType: "text", required: false },
|
|
453
|
-
{ name: "options", dataType: "object", description: "Filters (eq, neq, gt, lt, gte, lte, like, ilike, in, is), order, limit, offset, range, profile", formInputType: "json", required: false },
|
|
454
|
-
],
|
|
455
|
-
returnType: "array",
|
|
456
|
-
returnDescription: "Array of matching rows",
|
|
457
|
-
example: 'supabase.select "users" "*" {"eq": {"status": "active"}, "limit": 10}',
|
|
458
|
-
},
|
|
459
|
-
insert: {
|
|
460
|
-
description: "Insert one or more rows into a table",
|
|
461
|
-
parameters: [
|
|
462
|
-
{ name: "table", dataType: "string", description: "Table name", formInputType: "text", required: true },
|
|
463
|
-
{ name: "data", dataType: "object", description: "Row object or array of row objects", formInputType: "json", required: true },
|
|
464
|
-
{ name: "options", dataType: "object", description: "Options: returning, onConflict (for upsert), columns, profile", formInputType: "json", required: false },
|
|
465
|
-
],
|
|
466
|
-
returnType: "array",
|
|
467
|
-
returnDescription: "Array of inserted rows (if returning enabled)",
|
|
468
|
-
example: 'supabase.insert "users" {"name": "Alice", "email": "alice@example.com"}',
|
|
469
|
-
},
|
|
470
|
-
update: {
|
|
471
|
-
description: "Update rows matching filters",
|
|
472
|
-
parameters: [
|
|
473
|
-
{ name: "table", dataType: "string", description: "Table name", formInputType: "text", required: true },
|
|
474
|
-
{ name: "data", dataType: "object", description: "Fields to update", formInputType: "json", required: true },
|
|
475
|
-
{ name: "match", dataType: "object", description: "Filter conditions to match rows (eq filters)", formInputType: "json", required: true },
|
|
476
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
477
|
-
],
|
|
478
|
-
returnType: "array",
|
|
479
|
-
returnDescription: "Array of updated rows",
|
|
480
|
-
example: 'supabase.update "users" {"status": "inactive"} {"id": 42}',
|
|
481
|
-
},
|
|
482
|
-
upsert: {
|
|
483
|
-
description: "Insert or update rows (merge on conflict)",
|
|
484
|
-
parameters: [
|
|
485
|
-
{ name: "table", dataType: "string", description: "Table name", formInputType: "text", required: true },
|
|
486
|
-
{ name: "data", dataType: "object", description: "Row object or array of row objects", formInputType: "json", required: true },
|
|
487
|
-
{ name: "options", dataType: "object", description: "Options: onConflict (conflict column), profile", formInputType: "json", required: false },
|
|
488
|
-
],
|
|
489
|
-
returnType: "array",
|
|
490
|
-
returnDescription: "Array of upserted rows",
|
|
491
|
-
example: 'supabase.upsert "users" {"id": 1, "name": "Alice"} {"onConflict": "id"}',
|
|
492
|
-
},
|
|
493
|
-
delete: {
|
|
494
|
-
description: "Delete rows matching filters",
|
|
495
|
-
parameters: [
|
|
496
|
-
{ name: "table", dataType: "string", description: "Table name", formInputType: "text", required: true },
|
|
497
|
-
{ name: "match", dataType: "object", description: "Filter conditions to match rows for deletion", formInputType: "json", required: true },
|
|
498
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
499
|
-
],
|
|
500
|
-
returnType: "array",
|
|
501
|
-
returnDescription: "Array of deleted rows",
|
|
502
|
-
example: 'supabase.delete "users" {"id": 42}',
|
|
503
|
-
},
|
|
504
|
-
rpc: {
|
|
505
|
-
description: "Call a Postgres function via RPC",
|
|
506
|
-
parameters: [
|
|
507
|
-
{ name: "functionName", dataType: "string", description: "Name of the Postgres function", formInputType: "text", required: true },
|
|
508
|
-
{ name: "params", dataType: "object", description: "Parameters to pass to the function", formInputType: "json", required: false },
|
|
509
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
510
|
-
],
|
|
511
|
-
returnType: "any",
|
|
512
|
-
returnDescription: "Function return value",
|
|
513
|
-
example: 'supabase.rpc "get_total_users" {"status": "active"}',
|
|
514
|
-
},
|
|
515
|
-
// ── Auth ────────────────────────────────────────────────────────────────
|
|
516
|
-
signUp: {
|
|
517
|
-
description: "Sign up a new user with email and password",
|
|
518
|
-
parameters: [
|
|
519
|
-
{ name: "email", dataType: "string", description: "User email address", formInputType: "text", required: true },
|
|
520
|
-
{ name: "password", dataType: "string", description: "User password", formInputType: "text", required: true },
|
|
521
|
-
{ name: "options", dataType: "object", description: "Options: data (user metadata), profile", formInputType: "json", required: false },
|
|
522
|
-
],
|
|
523
|
-
returnType: "object",
|
|
524
|
-
returnDescription: "Sign up response with user and session",
|
|
525
|
-
example: 'supabase.signUp "user@example.com" "securePassword123"',
|
|
526
|
-
},
|
|
527
|
-
signIn: {
|
|
528
|
-
description: "Sign in a user with email and password",
|
|
529
|
-
parameters: [
|
|
530
|
-
{ name: "email", dataType: "string", description: "User email address", formInputType: "text", required: true },
|
|
531
|
-
{ name: "password", dataType: "string", description: "User password", formInputType: "text", required: true },
|
|
532
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
533
|
-
],
|
|
534
|
-
returnType: "object",
|
|
535
|
-
returnDescription: "Auth token response with access_token, refresh_token, user",
|
|
536
|
-
example: 'supabase.signIn "user@example.com" "securePassword123"',
|
|
537
|
-
},
|
|
538
|
-
signInWithOtp: {
|
|
539
|
-
description: "Send a magic link to the user's email for passwordless sign in",
|
|
540
|
-
parameters: [
|
|
541
|
-
{ name: "email", dataType: "string", description: "User email address", formInputType: "text", required: true },
|
|
542
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
543
|
-
],
|
|
544
|
-
returnType: "object",
|
|
545
|
-
returnDescription: "OTP send confirmation",
|
|
546
|
-
example: 'supabase.signInWithOtp "user@example.com"',
|
|
547
|
-
},
|
|
548
|
-
signOut: {
|
|
549
|
-
description: "Sign out a user by invalidating their access token",
|
|
550
|
-
parameters: [
|
|
551
|
-
{ name: "accessToken", dataType: "string", description: "User's access token", formInputType: "text", required: true },
|
|
552
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
553
|
-
],
|
|
554
|
-
returnType: "object",
|
|
555
|
-
returnDescription: "Sign out confirmation",
|
|
556
|
-
example: 'supabase.signOut "eyJhbGc..."',
|
|
557
|
-
},
|
|
558
|
-
getUser: {
|
|
559
|
-
description: "Get the user object from a JWT access token",
|
|
560
|
-
parameters: [
|
|
561
|
-
{ name: "accessToken", dataType: "string", description: "User's access token", formInputType: "text", required: true },
|
|
562
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
563
|
-
],
|
|
564
|
-
returnType: "object",
|
|
565
|
-
returnDescription: "User object with id, email, metadata, etc.",
|
|
566
|
-
example: 'supabase.getUser "eyJhbGc..."',
|
|
567
|
-
},
|
|
568
|
-
updateUser: {
|
|
569
|
-
description: "Update user attributes (email, password, metadata)",
|
|
570
|
-
parameters: [
|
|
571
|
-
{ name: "accessToken", dataType: "string", description: "User's access token", formInputType: "text", required: true },
|
|
572
|
-
{ name: "attributes", dataType: "object", description: "Attributes to update: email, password, data (metadata)", formInputType: "json", required: true },
|
|
573
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
574
|
-
],
|
|
575
|
-
returnType: "object",
|
|
576
|
-
returnDescription: "Updated user object",
|
|
577
|
-
example: 'supabase.updateUser "eyJhbGc..." {"data": {"name": "New Name"}}',
|
|
578
|
-
},
|
|
579
|
-
listUsers: {
|
|
580
|
-
description: "Admin: List all users (requires service role key)",
|
|
581
|
-
parameters: [
|
|
582
|
-
{ name: "options", dataType: "object", description: "Options: page, perPage, profile", formInputType: "json", required: false },
|
|
583
|
-
],
|
|
584
|
-
returnType: "object",
|
|
585
|
-
returnDescription: "Paginated list of users",
|
|
586
|
-
example: 'supabase.listUsers {"page": 1, "perPage": 50}',
|
|
587
|
-
},
|
|
588
|
-
deleteUser: {
|
|
589
|
-
description: "Admin: Delete a user by ID (requires service role key)",
|
|
590
|
-
parameters: [
|
|
591
|
-
{ name: "userId", dataType: "string", description: "UUID of the user to delete", formInputType: "text", required: true },
|
|
592
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
593
|
-
],
|
|
594
|
-
returnType: "object",
|
|
595
|
-
returnDescription: "Deletion confirmation",
|
|
596
|
-
example: 'supabase.deleteUser "uuid-of-user"',
|
|
597
|
-
},
|
|
598
|
-
inviteUser: {
|
|
599
|
-
description: "Admin: Invite a user by email (requires service role key)",
|
|
600
|
-
parameters: [
|
|
601
|
-
{ name: "email", dataType: "string", description: "Email address to invite", formInputType: "text", required: true },
|
|
602
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
603
|
-
],
|
|
604
|
-
returnType: "object",
|
|
605
|
-
returnDescription: "Invite confirmation",
|
|
606
|
-
example: 'supabase.inviteUser "newuser@example.com"',
|
|
607
|
-
},
|
|
608
|
-
// ── Storage ─────────────────────────────────────────────────────────────
|
|
609
|
-
listBuckets: {
|
|
610
|
-
description: "List all storage buckets",
|
|
611
|
-
parameters: [
|
|
612
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
613
|
-
],
|
|
614
|
-
returnType: "array",
|
|
615
|
-
returnDescription: "Array of bucket objects",
|
|
616
|
-
example: 'supabase.listBuckets',
|
|
617
|
-
},
|
|
618
|
-
createBucket: {
|
|
619
|
-
description: "Create a new storage bucket",
|
|
620
|
-
parameters: [
|
|
621
|
-
{ name: "name", dataType: "string", description: "Bucket name", formInputType: "text", required: true },
|
|
622
|
-
{ name: "options", dataType: "object", description: "Options: public, fileSizeLimit, allowedMimeTypes, profile", formInputType: "json", required: false },
|
|
623
|
-
],
|
|
624
|
-
returnType: "object",
|
|
625
|
-
returnDescription: "Created bucket info",
|
|
626
|
-
example: 'supabase.createBucket "avatars" {"public": true}',
|
|
627
|
-
},
|
|
628
|
-
deleteBucket: {
|
|
629
|
-
description: "Delete a storage bucket (must be empty first)",
|
|
630
|
-
parameters: [
|
|
631
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
632
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
633
|
-
],
|
|
634
|
-
returnType: "object",
|
|
635
|
-
returnDescription: "Deletion confirmation",
|
|
636
|
-
example: 'supabase.deleteBucket "avatars"',
|
|
637
|
-
},
|
|
638
|
-
emptyBucket: {
|
|
639
|
-
description: "Remove all files from a storage bucket",
|
|
640
|
-
parameters: [
|
|
641
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
642
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
643
|
-
],
|
|
644
|
-
returnType: "object",
|
|
645
|
-
returnDescription: "Empty confirmation",
|
|
646
|
-
example: 'supabase.emptyBucket "avatars"',
|
|
647
|
-
},
|
|
648
|
-
listFiles: {
|
|
649
|
-
description: "List files in a storage bucket/folder",
|
|
650
|
-
parameters: [
|
|
651
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
652
|
-
{ name: "path", dataType: "string", description: "Folder path within bucket (default root)", formInputType: "text", required: false },
|
|
653
|
-
{ name: "options", dataType: "object", description: "Options: limit, offset, sortBy, search, profile", formInputType: "json", required: false },
|
|
654
|
-
],
|
|
655
|
-
returnType: "array",
|
|
656
|
-
returnDescription: "Array of file/folder objects",
|
|
657
|
-
example: 'supabase.listFiles "avatars" "users/"',
|
|
658
|
-
},
|
|
659
|
-
uploadFile: {
|
|
660
|
-
description: "Upload a file to a storage bucket",
|
|
661
|
-
parameters: [
|
|
662
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
663
|
-
{ name: "path", dataType: "string", description: "File path within bucket", formInputType: "text", required: true },
|
|
664
|
-
{ name: "content", dataType: "string", description: "File content (string or Buffer)", formInputType: "textarea", required: true },
|
|
665
|
-
{ name: "options", dataType: "object", description: "Options: contentType, upsert, profile", formInputType: "json", required: false },
|
|
666
|
-
],
|
|
667
|
-
returnType: "object",
|
|
668
|
-
returnDescription: "Upload result with key",
|
|
669
|
-
example: 'supabase.uploadFile "avatars" "user1.png" $fileContent {"contentType": "image/png"}',
|
|
670
|
-
},
|
|
671
|
-
downloadFile: {
|
|
672
|
-
description: "Download a file from a storage bucket",
|
|
673
|
-
parameters: [
|
|
674
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
675
|
-
{ name: "path", dataType: "string", description: "File path within bucket", formInputType: "text", required: true },
|
|
676
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
677
|
-
],
|
|
678
|
-
returnType: "string",
|
|
679
|
-
returnDescription: "File content as string",
|
|
680
|
-
example: 'supabase.downloadFile "documents" "report.txt"',
|
|
681
|
-
},
|
|
682
|
-
deleteFile: {
|
|
683
|
-
description: "Delete one or more files from a storage bucket",
|
|
684
|
-
parameters: [
|
|
685
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
686
|
-
{ name: "paths", dataType: "array", description: "Array of file paths to delete", formInputType: "json", required: true },
|
|
687
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
688
|
-
],
|
|
689
|
-
returnType: "object",
|
|
690
|
-
returnDescription: "Deletion result",
|
|
691
|
-
example: 'supabase.deleteFile "avatars" ["user1.png", "user2.png"]',
|
|
692
|
-
},
|
|
693
|
-
getPublicUrl: {
|
|
694
|
-
description: "Get the public URL for a file in a public bucket",
|
|
695
|
-
parameters: [
|
|
696
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
697
|
-
{ name: "path", dataType: "string", description: "File path within bucket", formInputType: "text", required: true },
|
|
698
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
699
|
-
],
|
|
700
|
-
returnType: "object",
|
|
701
|
-
returnDescription: "{ publicUrl }",
|
|
702
|
-
example: 'supabase.getPublicUrl "avatars" "user1.png"',
|
|
703
|
-
},
|
|
704
|
-
createSignedUrl: {
|
|
705
|
-
description: "Create a signed URL for temporary access to a private file",
|
|
706
|
-
parameters: [
|
|
707
|
-
{ name: "bucketId", dataType: "string", description: "Bucket ID/name", formInputType: "text", required: true },
|
|
708
|
-
{ name: "path", dataType: "string", description: "File path within bucket", formInputType: "text", required: true },
|
|
709
|
-
{ name: "expiresIn", dataType: "number", description: "Expiry time in seconds", formInputType: "number", required: true },
|
|
710
|
-
{ name: "options", dataType: "object", description: "Options: profile", formInputType: "json", required: false },
|
|
711
|
-
],
|
|
712
|
-
returnType: "object",
|
|
713
|
-
returnDescription: "{ signedUrl, expiresIn }",
|
|
714
|
-
example: 'supabase.createSignedUrl "documents" "report.pdf" 3600',
|
|
715
|
-
},
|
|
716
|
-
};
|
|
717
|
-
// ── module metadata ─────────────────────────────────────────────────────────
|
|
718
|
-
export const SupabaseModuleMetadata = {
|
|
719
|
-
description: "Supabase REST API client for PostgREST (database), Auth, and Storage operations.",
|
|
720
|
-
methods: Object.keys(SupabaseFunctions),
|
|
721
|
-
category: "cloud",
|
|
722
|
-
};
|
|
723
|
-
//# sourceMappingURL=supabase.js.map
|