@supatype/client 0.1.0-alpha.6
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +7 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/dist/auth.d.ts +243 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +560 -0
- package/dist/auth.js.map +1 -0
- package/dist/error-codes-doc.d.ts +31 -0
- package/dist/error-codes-doc.d.ts.map +1 -0
- package/dist/error-codes-doc.js +294 -0
- package/dist/error-codes-doc.js.map +1 -0
- package/dist/errors.d.ts +197 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +162 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch-with-retry.d.ts +49 -0
- package/dist/fetch-with-retry.d.ts.map +1 -0
- package/dist/fetch-with-retry.js +150 -0
- package/dist/fetch-with-retry.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +225 -0
- package/dist/index.js.map +1 -0
- package/dist/query.d.ts +53 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +216 -0
- package/dist/query.js.map +1 -0
- package/dist/realtime.d.ts +69 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +279 -0
- package/dist/realtime.js.map +1 -0
- package/dist/retry.d.ts +24 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +25 -0
- package/dist/retry.js.map +1 -0
- package/dist/serverless-docs.d.ts +38 -0
- package/dist/serverless-docs.d.ts.map +1 -0
- package/dist/serverless-docs.js +83 -0
- package/dist/serverless-docs.js.map +1 -0
- package/dist/storage.d.ts +79 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +130 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +141 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/auth.ts +713 -0
- package/src/error-codes-doc.ts +315 -0
- package/src/errors.ts +201 -0
- package/src/fetch-with-retry.ts +200 -0
- package/src/index.ts +418 -0
- package/src/query.ts +280 -0
- package/src/realtime.ts +418 -0
- package/src/retry.ts +35 -0
- package/src/serverless-docs.ts +107 -0
- package/src/storage.ts +182 -0
- package/src/types.ts +184 -0
- package/tests/auth.test.ts +282 -0
- package/tests/mfa-totp-integration.test.ts +359 -0
- package/tests/query.test.ts +286 -0
- package/tests/rate-limit-integration.test.ts +185 -0
- package/tests/realtime-multi-tenant-integration.test.ts +372 -0
- package/tests/retry-integration.test.ts +212 -0
- package/tests/serverless.test.ts +115 -0
- package/tests/storage-quota-integration.test.ts +189 -0
- package/tests/storage-upload-limit-integration.test.ts +185 -0
- package/tests/types.test.ts +123 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration module.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the core fetchWithRetry and provides a factory that binds
|
|
5
|
+
* client-level retry/timeout options so callers don't repeat them.
|
|
6
|
+
*/
|
|
7
|
+
import { type FetchOptions } from "./fetch-with-retry.js";
|
|
8
|
+
export type { FetchOptions } from "./fetch-with-retry.js";
|
|
9
|
+
export interface RetryConfig {
|
|
10
|
+
/** Disable automatic retry. When false, no retries are attempted. */
|
|
11
|
+
retry?: boolean | undefined;
|
|
12
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
13
|
+
timeout?: number | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a fetch function pre-configured with client-level retry/timeout.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const doFetch = createRetryFetch({ retry: true, timeout: 10000 })
|
|
20
|
+
* const res = await doFetch('https://api.example.com/data', { method: 'GET' })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRetryFetch(config: RetryConfig): (url: string, init?: RequestInit & Partial<FetchOptions>) => Promise<Response>;
|
|
24
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEzE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,IAC1C,KAAK,MAAM,EAAE,OAAO,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,QAAQ,CAAC,CAOpF"}
|
package/dist/retry.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration module.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the core fetchWithRetry and provides a factory that binds
|
|
5
|
+
* client-level retry/timeout options so callers don't repeat them.
|
|
6
|
+
*/
|
|
7
|
+
import { fetchWithRetry } from "./fetch-with-retry.js";
|
|
8
|
+
/**
|
|
9
|
+
* Create a fetch function pre-configured with client-level retry/timeout.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const doFetch = createRetryFetch({ retry: true, timeout: 10000 })
|
|
13
|
+
* const res = await doFetch('https://api.example.com/data', { method: 'GET' })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function createRetryFetch(config) {
|
|
17
|
+
return (url, init) => {
|
|
18
|
+
return fetchWithRetry(url, {
|
|
19
|
+
...init,
|
|
20
|
+
retry: init?.retry ?? config.retry,
|
|
21
|
+
timeout: init?.timeout ?? config.timeout,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAqB,MAAM,uBAAuB,CAAA;AAWzE;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,OAAO,CAAC,GAAW,EAAE,IAA0C,EAAqB,EAAE;QACpF,OAAO,cAAc,CAAC,GAAG,EAAE;YACzB,GAAG,IAAI;YACP,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,MAAM,CAAC,KAAK;YAClC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,MAAM,CAAC,OAAO;SACzC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serverless connection documentation — Gap Appendices task 84
|
|
3
|
+
*
|
|
4
|
+
* Code-accessible documentation for connection modes.
|
|
5
|
+
* Rendered in Studio's getting-started view and available to CLI help output.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConnectionModeDoc {
|
|
8
|
+
/** Short label for this mode. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** When to use this mode (environment/context). */
|
|
11
|
+
recommended: string;
|
|
12
|
+
/** Whether this mode is safe in serverless contexts. */
|
|
13
|
+
serverlessSafe: boolean;
|
|
14
|
+
/** How it handles connection pooling. */
|
|
15
|
+
pooling: string;
|
|
16
|
+
/** Brief description. */
|
|
17
|
+
description: string;
|
|
18
|
+
/** Example code snippet (TypeScript). */
|
|
19
|
+
example: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Documents the two primary ways to connect to a Supatype project,
|
|
23
|
+
* with clear guidance on serverless vs. long-lived server environments.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CONNECTION_MODES: readonly ConnectionModeDoc[];
|
|
26
|
+
/**
|
|
27
|
+
* A short, actionable warning suitable for display in Studio banners,
|
|
28
|
+
* CLI output, and getting-started guides.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SERVERLESS_CONNECTION_WARNING: string;
|
|
31
|
+
/**
|
|
32
|
+
* Structured FAQ entries for the connection modes documentation.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CONNECTION_FAQ: ReadonlyArray<{
|
|
35
|
+
question: string;
|
|
36
|
+
answer: string;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=serverless-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverless-docs.d.ts","sourceRoot":"","sources":["../src/serverless-docs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,cAAc,EAAE,OAAO,CAAA;IACvB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,iBAAiB,EAuC/C,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAIwC,CAAA;AAElF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CA0B9E,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serverless connection documentation — Gap Appendices task 84
|
|
3
|
+
*
|
|
4
|
+
* Code-accessible documentation for connection modes.
|
|
5
|
+
* Rendered in Studio's getting-started view and available to CLI help output.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Documents the two primary ways to connect to a Supatype project,
|
|
9
|
+
* with clear guidance on serverless vs. long-lived server environments.
|
|
10
|
+
*/
|
|
11
|
+
export const CONNECTION_MODES = [
|
|
12
|
+
{
|
|
13
|
+
label: "Supatype SDK (via PostgREST)",
|
|
14
|
+
recommended: "Serverless environments: Next.js API routes, Vercel Edge Functions, AWS Lambda, Cloudflare Workers, Deno Deploy",
|
|
15
|
+
serverlessSafe: true,
|
|
16
|
+
pooling: "PostgREST maintains a persistent connection pool to Postgres. Each SDK request is an HTTP call that reuses an existing database connection from the pool.",
|
|
17
|
+
description: "Use the Supatype SDK in serverless environments. PostgREST handles connection pooling for you. " +
|
|
18
|
+
"Each serverless invocation makes an HTTP request to PostgREST, which maps it to a pre-established " +
|
|
19
|
+
"database connection. This avoids the connection-per-invocation problem entirely.",
|
|
20
|
+
example: [
|
|
21
|
+
'import { createClient } from "@supatype/client"',
|
|
22
|
+
"",
|
|
23
|
+
"const client = createClient(process.env.SUPATYPE_URL!, process.env.SUPATYPE_ANON_KEY!)",
|
|
24
|
+
"",
|
|
25
|
+
"// Safe in serverless — each call is an HTTP request, not a new DB connection",
|
|
26
|
+
"const users = await client.from(\"users\").select()",
|
|
27
|
+
].join("\n"),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: "Direct database connection",
|
|
31
|
+
recommended: "Long-lived servers: Express/Fastify/Hono on a VM or container, background workers, migration scripts, CLI tools",
|
|
32
|
+
serverlessSafe: false,
|
|
33
|
+
pooling: "Each new connection opens a TCP socket to Postgres. In serverless, each invocation creates a new connection that is never reused, exhausting the connection pool within seconds under load.",
|
|
34
|
+
description: "Do NOT use direct database connections from serverless environments. " +
|
|
35
|
+
"Each invocation opens a new connection, which will exhaust your connection pool " +
|
|
36
|
+
"within seconds under load. Direct connections are only appropriate for long-lived " +
|
|
37
|
+
"server processes that open a connection once and reuse it across many requests.",
|
|
38
|
+
example: [
|
|
39
|
+
'// ONLY for long-lived servers — NOT for serverless',
|
|
40
|
+
'import pg from "pg"',
|
|
41
|
+
"",
|
|
42
|
+
"const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })",
|
|
43
|
+
"",
|
|
44
|
+
"// Connection is reused across requests in a long-lived process",
|
|
45
|
+
"const result = await pool.query(\"SELECT * FROM users\")",
|
|
46
|
+
].join("\n"),
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* A short, actionable warning suitable for display in Studio banners,
|
|
51
|
+
* CLI output, and getting-started guides.
|
|
52
|
+
*/
|
|
53
|
+
export const SERVERLESS_CONNECTION_WARNING = "Use the Supatype SDK (via PostgREST) in serverless environments (Next.js API routes, " +
|
|
54
|
+
"Vercel Edge Functions, AWS Lambda). PostgREST handles connection pooling for you. " +
|
|
55
|
+
"Do NOT use direct database connections from serverless — each invocation opens a new " +
|
|
56
|
+
"connection, which will exhaust your connection pool within seconds under load.";
|
|
57
|
+
/**
|
|
58
|
+
* Structured FAQ entries for the connection modes documentation.
|
|
59
|
+
*/
|
|
60
|
+
export const CONNECTION_FAQ = [
|
|
61
|
+
{
|
|
62
|
+
question: "Can I use Prisma/Drizzle/Knex in serverless?",
|
|
63
|
+
answer: "These ORMs require a direct database connection. In serverless, use the Supatype SDK instead. " +
|
|
64
|
+
"If you must use an ORM, deploy it on a long-lived server (container, VM) or use a connection " +
|
|
65
|
+
"pooler like PgBouncer in transaction mode.",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
question: "What about Edge Functions?",
|
|
69
|
+
answer: "Edge Functions (Vercel Edge, Cloudflare Workers) are serverless. Use the Supatype SDK. " +
|
|
70
|
+
"Direct TCP connections are not available in most edge runtimes anyway.",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
question: "How many connections does PostgREST use?",
|
|
74
|
+
answer: "PostgREST maintains a configurable pool (default: 10 connections). All incoming HTTP requests " +
|
|
75
|
+
"share this pool, so even thousands of concurrent SDK requests only use 10 database connections.",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
question: "When should I use a direct connection?",
|
|
79
|
+
answer: "Use direct connections for: migration scripts, long-lived API servers (Express, Fastify), " +
|
|
80
|
+
"background job processors, and CLI tooling. These processes start once and reuse connections.",
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
//# sourceMappingURL=serverless-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverless-docs.js","sourceRoot":"","sources":["../src/serverless-docs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAiC;IAC5D;QACE,KAAK,EAAE,8BAA8B;QACrC,WAAW,EAAE,iHAAiH;QAC9H,cAAc,EAAE,IAAI;QACpB,OAAO,EAAE,2JAA2J;QACpK,WAAW,EACT,iGAAiG;YACjG,oGAAoG;YACpG,kFAAkF;QACpF,OAAO,EAAE;YACP,iDAAiD;YACjD,EAAE;YACF,wFAAwF;YACxF,EAAE;YACF,+EAA+E;YAC/E,qDAAqD;SACtD,CAAC,IAAI,CAAC,IAAI,CAAC;KACb;IACD;QACE,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,iHAAiH;QAC9H,cAAc,EAAE,KAAK;QACrB,OAAO,EAAE,6LAA6L;QACtM,WAAW,EACT,uEAAuE;YACvE,kFAAkF;YAClF,oFAAoF;YACpF,iFAAiF;QACnF,OAAO,EAAE;YACP,qDAAqD;YACrD,qBAAqB;YACrB,EAAE;YACF,0EAA0E;YAC1E,EAAE;YACF,iEAAiE;YACjE,0DAA0D;SAC3D,CAAC,IAAI,CAAC,IAAI,CAAC;KACb;CACO,CAAA;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GACxC,uFAAuF;IACvF,oFAAoF;IACpF,uFAAuF;IACvF,gFAAgF,CAAA;AAElF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwD;IACjF;QACE,QAAQ,EAAE,8CAA8C;QACxD,MAAM,EACJ,gGAAgG;YAChG,+FAA+F;YAC/F,4CAA4C;KAC/C;IACD;QACE,QAAQ,EAAE,4BAA4B;QACtC,MAAM,EACJ,yFAAyF;YACzF,wEAAwE;KAC3E;IACD;QACE,QAAQ,EAAE,0CAA0C;QACpD,MAAM,EACJ,gGAAgG;YAChG,iGAAiG;KACpG;IACD;QACE,QAAQ,EAAE,wCAAwC;QAClD,MAAM,EACJ,4FAA4F;YAC5F,+FAA+F;KAClG;CACF,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { SupatypeError } from "./types.js";
|
|
2
|
+
export interface StorageObject {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
bucket_id: string;
|
|
6
|
+
owner?: string | undefined;
|
|
7
|
+
created_at: string;
|
|
8
|
+
updated_at: string;
|
|
9
|
+
last_accessed_at: string;
|
|
10
|
+
metadata?: Record<string, unknown> | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface TransformOptions {
|
|
13
|
+
width?: number | undefined;
|
|
14
|
+
height?: number | undefined;
|
|
15
|
+
format?: "webp" | "avif" | "png" | "jpeg" | undefined;
|
|
16
|
+
quality?: number | undefined;
|
|
17
|
+
resize?: "cover" | "contain" | "fill" | "inside" | "outside" | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare class StorageClient {
|
|
20
|
+
private readonly url;
|
|
21
|
+
private readonly headers;
|
|
22
|
+
constructor(url: string, headers: Record<string, string>);
|
|
23
|
+
from(bucket: string): BucketClient;
|
|
24
|
+
}
|
|
25
|
+
export declare class BucketClient {
|
|
26
|
+
private readonly url;
|
|
27
|
+
private readonly bucket;
|
|
28
|
+
private readonly headers;
|
|
29
|
+
constructor(url: string, bucket: string, headers: Record<string, string>);
|
|
30
|
+
upload(path: string, file: Blob | File | ArrayBuffer, options?: {
|
|
31
|
+
contentType?: string | undefined;
|
|
32
|
+
upsert?: boolean | undefined;
|
|
33
|
+
} | undefined): Promise<{
|
|
34
|
+
data: {
|
|
35
|
+
path: string;
|
|
36
|
+
} | null;
|
|
37
|
+
error: SupatypeError | null;
|
|
38
|
+
}>;
|
|
39
|
+
download(path: string, options?: {
|
|
40
|
+
transform?: TransformOptions | undefined;
|
|
41
|
+
} | undefined): Promise<{
|
|
42
|
+
data: Blob | null;
|
|
43
|
+
error: SupatypeError | null;
|
|
44
|
+
}>;
|
|
45
|
+
getPublicUrl(path: string, options?: {
|
|
46
|
+
transform?: TransformOptions | undefined;
|
|
47
|
+
} | undefined): {
|
|
48
|
+
data: {
|
|
49
|
+
publicUrl: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
createSignedUrl(path: string, expiresIn: number): Promise<{
|
|
53
|
+
data: {
|
|
54
|
+
signedUrl: string;
|
|
55
|
+
} | null;
|
|
56
|
+
error: SupatypeError | null;
|
|
57
|
+
}>;
|
|
58
|
+
createSignedUrls(paths: string[], expiresIn: number): Promise<{
|
|
59
|
+
data: {
|
|
60
|
+
path: string;
|
|
61
|
+
signedUrl: string;
|
|
62
|
+
error: string | null;
|
|
63
|
+
}[] | null;
|
|
64
|
+
error: SupatypeError | null;
|
|
65
|
+
}>;
|
|
66
|
+
remove(paths: string[]): Promise<{
|
|
67
|
+
data: StorageObject[] | null;
|
|
68
|
+
error: SupatypeError | null;
|
|
69
|
+
}>;
|
|
70
|
+
list(prefix?: string | undefined, options?: {
|
|
71
|
+
limit?: number | undefined;
|
|
72
|
+
offset?: number | undefined;
|
|
73
|
+
} | undefined): Promise<{
|
|
74
|
+
data: StorageObject[] | null;
|
|
75
|
+
error: SupatypeError | null;
|
|
76
|
+
}>;
|
|
77
|
+
private buildObjectUrl;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,EAAE,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;KAAE,CAAC;IAa/G,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;KAAE,CAAC;IAc/F,IAAI,CACR,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,GAChF,OAAO,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;KAAE,CAAC;IAqBzE,OAAO,CAAC,cAAc;CAkBvB"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export class StorageClient {
|
|
2
|
+
url;
|
|
3
|
+
headers;
|
|
4
|
+
constructor(url, headers) {
|
|
5
|
+
this.url = url;
|
|
6
|
+
this.headers = headers;
|
|
7
|
+
}
|
|
8
|
+
from(bucket) {
|
|
9
|
+
return new BucketClient(this.url, bucket, this.headers);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class BucketClient {
|
|
13
|
+
url;
|
|
14
|
+
bucket;
|
|
15
|
+
headers;
|
|
16
|
+
constructor(url, bucket, headers) {
|
|
17
|
+
this.url = url;
|
|
18
|
+
this.bucket = bucket;
|
|
19
|
+
this.headers = headers;
|
|
20
|
+
}
|
|
21
|
+
async upload(path, file, options) {
|
|
22
|
+
const headers = {
|
|
23
|
+
...this.headers,
|
|
24
|
+
"Content-Type": options?.contentType ?? "application/octet-stream",
|
|
25
|
+
};
|
|
26
|
+
if (options?.upsert === true) {
|
|
27
|
+
headers["x-upsert"] = "true";
|
|
28
|
+
}
|
|
29
|
+
const res = await fetch(`${this.url}/object/${this.bucket}/${path}`, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers,
|
|
32
|
+
body: file,
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
const err = await res.json().catch(() => ({ message: "Upload failed" }));
|
|
36
|
+
return { data: null, error: { message: String(err["message"] ?? "Upload failed"), status: res.status } };
|
|
37
|
+
}
|
|
38
|
+
return { data: { path }, error: null };
|
|
39
|
+
}
|
|
40
|
+
async download(path, options) {
|
|
41
|
+
const url = this.buildObjectUrl("authenticated", path, options?.transform);
|
|
42
|
+
const res = await fetch(url, { headers: this.headers });
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
const err = await res.json().catch(() => ({ message: "Download failed" }));
|
|
45
|
+
return { data: null, error: { message: String(err["message"] ?? "Download failed"), status: res.status } };
|
|
46
|
+
}
|
|
47
|
+
const blob = await res.blob();
|
|
48
|
+
return { data: blob, error: null };
|
|
49
|
+
}
|
|
50
|
+
getPublicUrl(path, options) {
|
|
51
|
+
const publicUrl = this.buildObjectUrl("public", path, options?.transform);
|
|
52
|
+
return { data: { publicUrl } };
|
|
53
|
+
}
|
|
54
|
+
async createSignedUrl(path, expiresIn) {
|
|
55
|
+
const res = await fetch(`${this.url}/object/sign/${this.bucket}/${path}`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
58
|
+
body: JSON.stringify({ expiresIn }),
|
|
59
|
+
});
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const err = await res.json().catch(() => ({ message: "Failed to create signed URL" }));
|
|
62
|
+
return { data: null, error: { message: String(err["message"] ?? "Failed to create signed URL"), status: res.status } };
|
|
63
|
+
}
|
|
64
|
+
const json = await res.json();
|
|
65
|
+
return { data: { signedUrl: json.signedURL }, error: null };
|
|
66
|
+
}
|
|
67
|
+
async createSignedUrls(paths, expiresIn) {
|
|
68
|
+
const results = await Promise.all(paths.map(async (path) => {
|
|
69
|
+
const result = await this.createSignedUrl(path, expiresIn);
|
|
70
|
+
if (result.error) {
|
|
71
|
+
return { path, signedUrl: "", error: result.error.message };
|
|
72
|
+
}
|
|
73
|
+
return { path, signedUrl: result.data.signedUrl, error: null };
|
|
74
|
+
}));
|
|
75
|
+
return { data: results, error: null };
|
|
76
|
+
}
|
|
77
|
+
async remove(paths) {
|
|
78
|
+
const res = await fetch(`${this.url}/object/${this.bucket}`, {
|
|
79
|
+
method: "DELETE",
|
|
80
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
81
|
+
body: JSON.stringify({ prefixes: paths }),
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
const err = await res.json().catch(() => ({ message: "Delete failed" }));
|
|
85
|
+
return { data: null, error: { message: String(err["message"] ?? "Delete failed"), status: res.status } };
|
|
86
|
+
}
|
|
87
|
+
const json = await res.json();
|
|
88
|
+
return { data: json, error: null };
|
|
89
|
+
}
|
|
90
|
+
async list(prefix, options) {
|
|
91
|
+
const body = {
|
|
92
|
+
...(prefix !== undefined && { prefix }),
|
|
93
|
+
...(options?.limit !== undefined && { limit: options.limit }),
|
|
94
|
+
...(options?.offset !== undefined && { offset: options.offset }),
|
|
95
|
+
};
|
|
96
|
+
const res = await fetch(`${this.url}/object/list/${this.bucket}`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
99
|
+
body: JSON.stringify(body),
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const err = await res.json().catch(() => ({ message: "List failed" }));
|
|
103
|
+
return { data: null, error: { message: String(err["message"] ?? "List failed"), status: res.status } };
|
|
104
|
+
}
|
|
105
|
+
const json = await res.json();
|
|
106
|
+
return { data: json, error: null };
|
|
107
|
+
}
|
|
108
|
+
// ─── Internal ───────────────────────────────────────────────────────────────
|
|
109
|
+
buildObjectUrl(access, path, transform) {
|
|
110
|
+
let url = `${this.url}/object/${access}/${this.bucket}/${path}`;
|
|
111
|
+
if (transform) {
|
|
112
|
+
const params = new URLSearchParams();
|
|
113
|
+
if (transform.width !== undefined)
|
|
114
|
+
params.set("width", String(transform.width));
|
|
115
|
+
if (transform.height !== undefined)
|
|
116
|
+
params.set("height", String(transform.height));
|
|
117
|
+
if (transform.format !== undefined)
|
|
118
|
+
params.set("format", transform.format);
|
|
119
|
+
if (transform.quality !== undefined)
|
|
120
|
+
params.set("quality", String(transform.quality));
|
|
121
|
+
if (transform.resize !== undefined)
|
|
122
|
+
params.set("resize", transform.resize);
|
|
123
|
+
const qs = params.toString();
|
|
124
|
+
if (qs)
|
|
125
|
+
url += `?${qs}`;
|
|
126
|
+
}
|
|
127
|
+
return url;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,aAAa;IACP,GAAG,CAAQ;IACX,OAAO,CAAwB;IAEhD,YAAY,GAAW,EAAE,OAA+B;QACtD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAI,CAAC,MAAc;QACjB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;CACF;AAED,MAAM,OAAO,YAAY;IACN,GAAG,CAAQ;IACX,MAAM,CAAQ;IACd,OAAO,CAAwB;IAEhD,YAAY,GAAW,EAAE,MAAc,EAAE,OAA+B;QACtE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,MAAM,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A;YAClF,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;YAC1E,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;YACrF,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;YAC1E,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;YAC5B,IAAI,EAAE;gBAAE,GAAG,IAAI,IAAI,EAAE,EAAE,CAAA;QACzB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export interface UserIdentity {
|
|
2
|
+
id: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
identityData: Record<string, unknown>;
|
|
5
|
+
identityId: string;
|
|
6
|
+
provider: string;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
updatedAt: string;
|
|
9
|
+
lastSignInAt?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface Factor {
|
|
12
|
+
id: string;
|
|
13
|
+
friendlyName?: string | undefined;
|
|
14
|
+
factorType: "totp" | "phone" | "webauthn";
|
|
15
|
+
status: "verified" | "unverified";
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
phone?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface User {
|
|
21
|
+
id: string;
|
|
22
|
+
email?: string | undefined;
|
|
23
|
+
phone?: string | undefined;
|
|
24
|
+
role?: string | undefined;
|
|
25
|
+
appMetadata: Record<string, unknown>;
|
|
26
|
+
userMetadata: Record<string, unknown>;
|
|
27
|
+
identities?: UserIdentity[] | undefined;
|
|
28
|
+
factors?: Factor[] | undefined;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Session {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
tokenType: string;
|
|
35
|
+
expiresIn: number;
|
|
36
|
+
expiresAt?: number | undefined;
|
|
37
|
+
refreshToken: string;
|
|
38
|
+
user: User;
|
|
39
|
+
}
|
|
40
|
+
export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED" | "PASSWORD_RECOVERY" | "MFA_CHALLENGE_VERIFIED";
|
|
41
|
+
export interface AuthMFAEnrollResponse {
|
|
42
|
+
/** The MFA factor ID */
|
|
43
|
+
id: string;
|
|
44
|
+
/** Factor type: totp, phone, or webauthn */
|
|
45
|
+
type: string;
|
|
46
|
+
/** Friendly name for the factor */
|
|
47
|
+
friendlyName: string;
|
|
48
|
+
/** TOTP-specific data (only present for totp factor type) */
|
|
49
|
+
totp?: {
|
|
50
|
+
/** QR code SVG string */
|
|
51
|
+
qrCode: string;
|
|
52
|
+
/** TOTP secret */
|
|
53
|
+
secret: string;
|
|
54
|
+
/** TOTP URI for manual entry */
|
|
55
|
+
uri: string;
|
|
56
|
+
} | undefined;
|
|
57
|
+
/** Phone number (only present for phone factor type) */
|
|
58
|
+
phone?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
export interface AuthMFAChallengeResponse {
|
|
61
|
+
/** The challenge ID */
|
|
62
|
+
id: string;
|
|
63
|
+
/** Factor type */
|
|
64
|
+
type: string;
|
|
65
|
+
/** Challenge expiry timestamp (Unix epoch seconds) */
|
|
66
|
+
expiresAt: number;
|
|
67
|
+
}
|
|
68
|
+
export interface AuthMFAVerifyResponse {
|
|
69
|
+
/** Access token */
|
|
70
|
+
accessToken: string;
|
|
71
|
+
tokenType: string;
|
|
72
|
+
expiresIn: number;
|
|
73
|
+
expiresAt?: number | undefined;
|
|
74
|
+
refreshToken: string;
|
|
75
|
+
user: User;
|
|
76
|
+
}
|
|
77
|
+
export interface AuthMFAListFactorsResponse {
|
|
78
|
+
/** All factors including unverified */
|
|
79
|
+
all: Factor[];
|
|
80
|
+
/** Only verified TOTP factors */
|
|
81
|
+
totp: Factor[];
|
|
82
|
+
/** Only verified phone factors */
|
|
83
|
+
phone: Factor[];
|
|
84
|
+
}
|
|
85
|
+
export type OtpType = "signup" | "magiclink" | "recovery" | "invite" | "email_change" | "sms" | "phone_change" | "email";
|
|
86
|
+
export interface SupatypeError {
|
|
87
|
+
message: string;
|
|
88
|
+
status?: number | undefined;
|
|
89
|
+
code?: string | undefined;
|
|
90
|
+
}
|
|
91
|
+
export interface QueryResult<TData> {
|
|
92
|
+
data: TData | null;
|
|
93
|
+
error: SupatypeError | null;
|
|
94
|
+
count: number | null;
|
|
95
|
+
}
|
|
96
|
+
export interface RpcResult<TData> {
|
|
97
|
+
data: TData | null;
|
|
98
|
+
error: SupatypeError | null;
|
|
99
|
+
}
|
|
100
|
+
export interface TableDef {
|
|
101
|
+
Row: Record<string, unknown>;
|
|
102
|
+
Insert: Record<string, unknown>;
|
|
103
|
+
Update: Record<string, unknown>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Describes the shape of a Postgres function for typed `.rpc()` calls.
|
|
107
|
+
* Generated by the Supatype engine from detected Postgres functions.
|
|
108
|
+
*/
|
|
109
|
+
export interface FunctionDef {
|
|
110
|
+
Args: Record<string, unknown>;
|
|
111
|
+
Returns: unknown;
|
|
112
|
+
}
|
|
113
|
+
export interface AnyDatabase {
|
|
114
|
+
public: {
|
|
115
|
+
Tables: Record<string, TableDef>;
|
|
116
|
+
Functions?: Record<string, FunctionDef> | undefined;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export interface SupatypeClientConfig {
|
|
120
|
+
/** Base URL of the Supatype gateway (e.g. http://localhost:8000) */
|
|
121
|
+
url: string;
|
|
122
|
+
/** Anon JWT key */
|
|
123
|
+
anonKey: string;
|
|
124
|
+
auth?: {
|
|
125
|
+
/** Persist session across page reloads (browser only). Default: true */
|
|
126
|
+
persistSession?: boolean | undefined;
|
|
127
|
+
/** localStorage key to use for session storage. Default: "supatype.auth.session" */
|
|
128
|
+
storageKey?: string | undefined;
|
|
129
|
+
} | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Disable automatic retry for transient errors.
|
|
132
|
+
* Default: true (retries enabled).
|
|
133
|
+
*/
|
|
134
|
+
retry?: boolean | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Request timeout in milliseconds. Default: 30000 (30 seconds).
|
|
137
|
+
* Applied to every HTTP request made by the client.
|
|
138
|
+
*/
|
|
139
|
+
timeout?: number | undefined;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;IACzC,MAAM,EAAE,UAAU,GAAG,YAAY,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B;AAED,MA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,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAChC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,CAAA;KACpD,CAAA;CACF;AAID,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAA;IACX,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE;QACL,wEAAwE;QACxE,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpC,oFAAoF;QACpF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAChC,GAAG,SAAS,CAAA;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iFAAiF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@supatype/client",
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
|
+
"description": "Supatype client SDK — typed REST, auth, storage, realtime",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^22",
|
|
16
|
+
"typescript": "^5",
|
|
17
|
+
"vitest": "^4.0.18"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc --project tsconfig.json",
|
|
21
|
+
"dev": "tsc --project tsconfig.json --watch",
|
|
22
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
25
|
+
}
|
|
26
|
+
}
|