@supacloud/js 0.36.0 → 0.37.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/README.md +7 -0
- package/dist/api-fetch.d.cts +13 -0
- package/dist/api-fetch.d.mts +13 -0
- package/dist/index.cjs +98 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +98 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
`@supacloud/js` is the platform SDK for SupaCloud.
|
|
4
4
|
|
|
5
|
+
It serves frontend applications as well as trusted servers. Reuse one existing
|
|
6
|
+
Supabase client and its user session; do not create a second authentication
|
|
7
|
+
store. Frontend frameworks own UI state, routing and forms, while generated
|
|
8
|
+
application clients own business-specific contracts. See
|
|
9
|
+
[Frontend SDK Integration](../../docs/frontend-sdk-integration.md) for the
|
|
10
|
+
shared-session recipe and the browser/server capability boundary.
|
|
11
|
+
|
|
5
12
|
It does **not** replace [`@supabase/supabase-js`](https://www.npmjs.com/package/@supabase/supabase-js). Instead, it wraps a normal Supabase client and adds SupaCloud-specific capabilities such as:
|
|
6
13
|
|
|
7
14
|
- background task submission
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SupabaseClient } from "./supabase-types.cjs";
|
|
2
|
+
import type { FetchTransport } from "./bounded-rpc-fetch.cjs";
|
|
3
|
+
export interface SupaCloudApiFetchOptions<TClient extends SupabaseClient = SupabaseClient> {
|
|
4
|
+
/** The existing user-scoped Supabase client. It owns auth, apikey and session refresh. */
|
|
5
|
+
supabase: TClient;
|
|
6
|
+
/** The deployed Edge Function name that hosts the generated application routes. */
|
|
7
|
+
functionName: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adapts the generated application client to the official Supabase Function
|
|
11
|
+
* transport without creating a second auth/session implementation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createSupaCloudApiFetch<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudApiFetchOptions<TClient>): FetchTransport;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SupabaseClient } from "./supabase-types.mjs";
|
|
2
|
+
import type { FetchTransport } from "./bounded-rpc-fetch.mjs";
|
|
3
|
+
export interface SupaCloudApiFetchOptions<TClient extends SupabaseClient = SupabaseClient> {
|
|
4
|
+
/** The existing user-scoped Supabase client. It owns auth, apikey and session refresh. */
|
|
5
|
+
supabase: TClient;
|
|
6
|
+
/** The deployed Edge Function name that hosts the generated application routes. */
|
|
7
|
+
functionName: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adapts the generated application client to the official Supabase Function
|
|
11
|
+
* transport without creating a second auth/session implementation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createSupaCloudApiFetch<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudApiFetchOptions<TClient>): FetchTransport;
|
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(exports_src, {
|
|
|
68
68
|
SupaCloudWorkflowRetryError: () => SupaCloudWorkflowRetryError,
|
|
69
69
|
SupaCloudWorkflowStartError: () => SupaCloudWorkflowStartError,
|
|
70
70
|
SupaCloudWorkflowsClient: () => SupaCloudWorkflowsClient,
|
|
71
|
+
createSupaCloudApiFetch: () => createSupaCloudApiFetch,
|
|
71
72
|
createSupaCloudArtifactFetch: () => createSupaCloudArtifactFetch,
|
|
72
73
|
createSupaCloudClient: () => createSupaCloudClient,
|
|
73
74
|
createSupaCloudCommandFetch: () => createSupaCloudCommandFetch,
|
|
@@ -2487,6 +2488,103 @@ var artifactPath2 = /\/rpc\/supacloud_artifact_(?:register|get|link)$/;
|
|
|
2487
2488
|
function createSupaCloudArtifactFetch(options = {}) {
|
|
2488
2489
|
return createBoundedRpcFetch(artifactPath2, () => new Error("Artifact HTTP response could not be validated"), options.fetch);
|
|
2489
2490
|
}
|
|
2491
|
+
// src/api-fetch.ts
|
|
2492
|
+
function isRecord4(value) {
|
|
2493
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2494
|
+
}
|
|
2495
|
+
function errorMessage(error) {
|
|
2496
|
+
return isRecord4(error) && typeof error.message === "string" ? error.message : "Supabase Function invocation failed";
|
|
2497
|
+
}
|
|
2498
|
+
async function readRequestBody(request) {
|
|
2499
|
+
if (request.body === null)
|
|
2500
|
+
return;
|
|
2501
|
+
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
|
|
2502
|
+
if (contentType.includes("multipart/form-data"))
|
|
2503
|
+
return request.formData();
|
|
2504
|
+
if (!contentType.startsWith("text/") && !contentType.includes("application/json") && !contentType.includes("+json") && !contentType.includes("application/x-www-form-urlencoded")) {
|
|
2505
|
+
return request.blob();
|
|
2506
|
+
}
|
|
2507
|
+
const text = await request.text();
|
|
2508
|
+
if (text.length === 0)
|
|
2509
|
+
return;
|
|
2510
|
+
if (contentType.includes("application/json") || contentType.includes("+json")) {
|
|
2511
|
+
try {
|
|
2512
|
+
return JSON.parse(text);
|
|
2513
|
+
} catch {
|
|
2514
|
+
return text;
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
return text;
|
|
2518
|
+
}
|
|
2519
|
+
function responseFromData(data, source) {
|
|
2520
|
+
if (data instanceof Response)
|
|
2521
|
+
return data;
|
|
2522
|
+
const status = source?.status ?? (data === undefined ? 204 : 200);
|
|
2523
|
+
const headers = source?.headers;
|
|
2524
|
+
const init = {
|
|
2525
|
+
status,
|
|
2526
|
+
...source?.statusText === undefined ? {} : { statusText: source.statusText },
|
|
2527
|
+
...headers === undefined ? {} : { headers }
|
|
2528
|
+
};
|
|
2529
|
+
if ([204, 205, 304].includes(status))
|
|
2530
|
+
return new Response(null, init);
|
|
2531
|
+
if (data === undefined)
|
|
2532
|
+
return new Response(null, init);
|
|
2533
|
+
if (data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || data instanceof ReadableStream || data instanceof FormData || typeof data === "string") {
|
|
2534
|
+
return new Response(data, init);
|
|
2535
|
+
}
|
|
2536
|
+
if (headers?.get("content-type")?.includes("json")) {
|
|
2537
|
+
return new Response(JSON.stringify(data), init);
|
|
2538
|
+
}
|
|
2539
|
+
return new Response(JSON.stringify(data), {
|
|
2540
|
+
...init,
|
|
2541
|
+
headers: headers ?? { "content-type": "application/json" }
|
|
2542
|
+
});
|
|
2543
|
+
}
|
|
2544
|
+
function createSupaCloudApiFetch(options) {
|
|
2545
|
+
const functionName = options.functionName.trim();
|
|
2546
|
+
if (!/^[A-Za-z0-9._-]+$/.test(functionName)) {
|
|
2547
|
+
throw new TypeError("functionName must be a single Supabase Function name");
|
|
2548
|
+
}
|
|
2549
|
+
const invoke = options.supabase.functions.invoke.bind(options.supabase.functions);
|
|
2550
|
+
return async (input, init) => {
|
|
2551
|
+
const rawInput = input instanceof Request ? input.url : input.toString();
|
|
2552
|
+
const url = new URL(rawInput, "http://supacloud.local");
|
|
2553
|
+
const request = new Request(url, init);
|
|
2554
|
+
const method = request.method;
|
|
2555
|
+
if (!["GET", "POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
|
2556
|
+
throw new TypeError(`Supabase Function transport does not support ${request.method}`);
|
|
2557
|
+
}
|
|
2558
|
+
const headers = {};
|
|
2559
|
+
request.headers.forEach((value, key) => {
|
|
2560
|
+
const normalized = key.toLowerCase();
|
|
2561
|
+
if (normalized !== "authorization" && normalized !== "apikey" && normalized !== "content-length") {
|
|
2562
|
+
headers[key] = value;
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
const body = method === "GET" ? undefined : await readRequestBody(request);
|
|
2566
|
+
if ((request.headers.get("content-type") ?? "").toLowerCase().includes("multipart/form-data")) {
|
|
2567
|
+
for (const key of Object.keys(headers)) {
|
|
2568
|
+
if (key.toLowerCase() === "content-type")
|
|
2569
|
+
delete headers[key];
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
const invocation = await invoke(`${functionName}${url.pathname}${url.search}`, {
|
|
2573
|
+
...body === undefined ? {} : { body },
|
|
2574
|
+
...Object.keys(headers).length === 0 ? {} : { headers },
|
|
2575
|
+
method,
|
|
2576
|
+
signal: request.signal
|
|
2577
|
+
});
|
|
2578
|
+
if (invocation.error !== null && invocation.error !== undefined) {
|
|
2579
|
+
if (invocation.response instanceof Response)
|
|
2580
|
+
return invocation.response;
|
|
2581
|
+
if (invocation.error instanceof Error)
|
|
2582
|
+
throw invocation.error;
|
|
2583
|
+
throw new Error(errorMessage(invocation.error));
|
|
2584
|
+
}
|
|
2585
|
+
return responseFromData(invocation.data, invocation.response instanceof Response ? invocation.response : undefined);
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2490
2588
|
|
|
2491
2589
|
// src/index.ts
|
|
2492
2590
|
class SupaCloudTaskSubmitError extends Error {
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./workflows.cjs";
|
|
|
16
16
|
export { createSupaCloudWorkflowFetch, type SupaCloudWorkflowFetchOptions } from "./workflow-fetch.cjs";
|
|
17
17
|
export { createSupaCloudCommandFetch, type SupaCloudCommandFetchOptions } from "./command-fetch.cjs";
|
|
18
18
|
export { createSupaCloudArtifactFetch, type SupaCloudArtifactFetchOptions } from "./artifact-fetch.cjs";
|
|
19
|
+
export { createSupaCloudApiFetch, type SupaCloudApiFetchOptions } from "./api-fetch.cjs";
|
|
19
20
|
export * from "./commands.cjs";
|
|
20
21
|
export * from "./artifacts.cjs";
|
|
21
22
|
export type SupaCloudTaskStatus = "pending" | "leased" | "running" | "retry_scheduled" | "succeeded" | "failed" | "dead_lettered" | "cancelled" | "queued" | "processing" | "completed";
|
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./workflows.mjs";
|
|
|
16
16
|
export { createSupaCloudWorkflowFetch, type SupaCloudWorkflowFetchOptions } from "./workflow-fetch.mjs";
|
|
17
17
|
export { createSupaCloudCommandFetch, type SupaCloudCommandFetchOptions } from "./command-fetch.mjs";
|
|
18
18
|
export { createSupaCloudArtifactFetch, type SupaCloudArtifactFetchOptions } from "./artifact-fetch.mjs";
|
|
19
|
+
export { createSupaCloudApiFetch, type SupaCloudApiFetchOptions } from "./api-fetch.mjs";
|
|
19
20
|
export * from "./commands.mjs";
|
|
20
21
|
export * from "./artifacts.mjs";
|
|
21
22
|
export type SupaCloudTaskStatus = "pending" | "leased" | "running" | "retry_scheduled" | "succeeded" | "failed" | "dead_lettered" | "cancelled" | "queued" | "processing" | "completed";
|
package/dist/index.mjs
CHANGED
|
@@ -2410,6 +2410,103 @@ var artifactPath2 = /\/rpc\/supacloud_artifact_(?:register|get|link)$/;
|
|
|
2410
2410
|
function createSupaCloudArtifactFetch(options = {}) {
|
|
2411
2411
|
return createBoundedRpcFetch(artifactPath2, () => new Error("Artifact HTTP response could not be validated"), options.fetch);
|
|
2412
2412
|
}
|
|
2413
|
+
// src/api-fetch.ts
|
|
2414
|
+
function isRecord4(value) {
|
|
2415
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2416
|
+
}
|
|
2417
|
+
function errorMessage(error) {
|
|
2418
|
+
return isRecord4(error) && typeof error.message === "string" ? error.message : "Supabase Function invocation failed";
|
|
2419
|
+
}
|
|
2420
|
+
async function readRequestBody(request) {
|
|
2421
|
+
if (request.body === null)
|
|
2422
|
+
return;
|
|
2423
|
+
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
|
|
2424
|
+
if (contentType.includes("multipart/form-data"))
|
|
2425
|
+
return request.formData();
|
|
2426
|
+
if (!contentType.startsWith("text/") && !contentType.includes("application/json") && !contentType.includes("+json") && !contentType.includes("application/x-www-form-urlencoded")) {
|
|
2427
|
+
return request.blob();
|
|
2428
|
+
}
|
|
2429
|
+
const text = await request.text();
|
|
2430
|
+
if (text.length === 0)
|
|
2431
|
+
return;
|
|
2432
|
+
if (contentType.includes("application/json") || contentType.includes("+json")) {
|
|
2433
|
+
try {
|
|
2434
|
+
return JSON.parse(text);
|
|
2435
|
+
} catch {
|
|
2436
|
+
return text;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
return text;
|
|
2440
|
+
}
|
|
2441
|
+
function responseFromData(data, source) {
|
|
2442
|
+
if (data instanceof Response)
|
|
2443
|
+
return data;
|
|
2444
|
+
const status = source?.status ?? (data === undefined ? 204 : 200);
|
|
2445
|
+
const headers = source?.headers;
|
|
2446
|
+
const init = {
|
|
2447
|
+
status,
|
|
2448
|
+
...source?.statusText === undefined ? {} : { statusText: source.statusText },
|
|
2449
|
+
...headers === undefined ? {} : { headers }
|
|
2450
|
+
};
|
|
2451
|
+
if ([204, 205, 304].includes(status))
|
|
2452
|
+
return new Response(null, init);
|
|
2453
|
+
if (data === undefined)
|
|
2454
|
+
return new Response(null, init);
|
|
2455
|
+
if (data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || data instanceof ReadableStream || data instanceof FormData || typeof data === "string") {
|
|
2456
|
+
return new Response(data, init);
|
|
2457
|
+
}
|
|
2458
|
+
if (headers?.get("content-type")?.includes("json")) {
|
|
2459
|
+
return new Response(JSON.stringify(data), init);
|
|
2460
|
+
}
|
|
2461
|
+
return new Response(JSON.stringify(data), {
|
|
2462
|
+
...init,
|
|
2463
|
+
headers: headers ?? { "content-type": "application/json" }
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
function createSupaCloudApiFetch(options) {
|
|
2467
|
+
const functionName = options.functionName.trim();
|
|
2468
|
+
if (!/^[A-Za-z0-9._-]+$/.test(functionName)) {
|
|
2469
|
+
throw new TypeError("functionName must be a single Supabase Function name");
|
|
2470
|
+
}
|
|
2471
|
+
const invoke = options.supabase.functions.invoke.bind(options.supabase.functions);
|
|
2472
|
+
return async (input, init) => {
|
|
2473
|
+
const rawInput = input instanceof Request ? input.url : input.toString();
|
|
2474
|
+
const url = new URL(rawInput, "http://supacloud.local");
|
|
2475
|
+
const request = new Request(url, init);
|
|
2476
|
+
const method = request.method;
|
|
2477
|
+
if (!["GET", "POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
|
2478
|
+
throw new TypeError(`Supabase Function transport does not support ${request.method}`);
|
|
2479
|
+
}
|
|
2480
|
+
const headers = {};
|
|
2481
|
+
request.headers.forEach((value, key) => {
|
|
2482
|
+
const normalized = key.toLowerCase();
|
|
2483
|
+
if (normalized !== "authorization" && normalized !== "apikey" && normalized !== "content-length") {
|
|
2484
|
+
headers[key] = value;
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
const body = method === "GET" ? undefined : await readRequestBody(request);
|
|
2488
|
+
if ((request.headers.get("content-type") ?? "").toLowerCase().includes("multipart/form-data")) {
|
|
2489
|
+
for (const key of Object.keys(headers)) {
|
|
2490
|
+
if (key.toLowerCase() === "content-type")
|
|
2491
|
+
delete headers[key];
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
const invocation = await invoke(`${functionName}${url.pathname}${url.search}`, {
|
|
2495
|
+
...body === undefined ? {} : { body },
|
|
2496
|
+
...Object.keys(headers).length === 0 ? {} : { headers },
|
|
2497
|
+
method,
|
|
2498
|
+
signal: request.signal
|
|
2499
|
+
});
|
|
2500
|
+
if (invocation.error !== null && invocation.error !== undefined) {
|
|
2501
|
+
if (invocation.response instanceof Response)
|
|
2502
|
+
return invocation.response;
|
|
2503
|
+
if (invocation.error instanceof Error)
|
|
2504
|
+
throw invocation.error;
|
|
2505
|
+
throw new Error(errorMessage(invocation.error));
|
|
2506
|
+
}
|
|
2507
|
+
return responseFromData(invocation.data, invocation.response instanceof Response ? invocation.response : undefined);
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2413
2510
|
|
|
2414
2511
|
// src/index.ts
|
|
2415
2512
|
class SupaCloudTaskSubmitError extends Error {
|
|
@@ -3683,6 +3780,7 @@ export {
|
|
|
3683
3780
|
SupaCloudWorkflowRetryError,
|
|
3684
3781
|
SupaCloudWorkflowStartError,
|
|
3685
3782
|
SupaCloudWorkflowsClient,
|
|
3783
|
+
createSupaCloudApiFetch,
|
|
3686
3784
|
createSupaCloudArtifactFetch,
|
|
3687
3785
|
createSupaCloudClient,
|
|
3688
3786
|
createSupaCloudCommandFetch,
|