@supacloud/js 0.10.0 → 0.11.2
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 +3 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +2 -8
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -45,6 +45,9 @@ This SDK is intentionally thin:
|
|
|
45
45
|
- `supabase-js` still owns auth, storage, database, Realtime transport, and plain function invokes
|
|
46
46
|
- `@supacloud/js` owns SupaCloud platform semantics layered on top of that transport
|
|
47
47
|
|
|
48
|
+
`tasks.submit()` expects the target function path to be configured in `background_routes`.
|
|
49
|
+
That keeps frontend calls compatible with strict CORS deployments while preserving the same task receipt API.
|
|
50
|
+
|
|
48
51
|
The current package focuses on:
|
|
49
52
|
|
|
50
53
|
- `tasks.submit`
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
export type SupaCloudTaskStatus = "pending" | "leased" | "running" | "retry_scheduled" | "succeeded" | "failed" | "dead_lettered" | "cancelled" | "queued" | "processing" | "completed";
|
|
3
|
+
export type SupaCloudTaskLogEntry = {
|
|
4
|
+
timestamp: string;
|
|
5
|
+
stream: "stdout" | "stderr";
|
|
6
|
+
level: string;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type SupaCloudTaskAttempt = {
|
|
10
|
+
attempt_no: number;
|
|
11
|
+
status: string;
|
|
12
|
+
started_at: string | null;
|
|
13
|
+
completed_at: string | null;
|
|
14
|
+
duration_ms: number | null;
|
|
15
|
+
response_status: number | null;
|
|
16
|
+
error: string | null;
|
|
17
|
+
logs: SupaCloudTaskLogEntry[];
|
|
18
|
+
};
|
|
19
|
+
export type SupaCloudTaskDetail = {
|
|
20
|
+
id: string;
|
|
21
|
+
status: SupaCloudTaskStatus | string;
|
|
22
|
+
function_slug?: string | null;
|
|
23
|
+
function_version?: string | null;
|
|
24
|
+
attempt?: number | null;
|
|
25
|
+
max_attempts?: number | null;
|
|
26
|
+
progress?: number | null;
|
|
27
|
+
error?: string | null;
|
|
28
|
+
error_message?: string | null;
|
|
29
|
+
result?: unknown;
|
|
30
|
+
payload?: Record<string, unknown>;
|
|
31
|
+
attempts?: SupaCloudTaskAttempt[];
|
|
32
|
+
latest_logs?: SupaCloudTaskLogEntry[];
|
|
33
|
+
updated_at?: string | null;
|
|
34
|
+
created_at?: string | null;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
export type SupaCloudTaskSnapshot = {
|
|
38
|
+
id: string;
|
|
39
|
+
status: SupaCloudTaskStatus | string;
|
|
40
|
+
progress?: number | null;
|
|
41
|
+
error?: string | null;
|
|
42
|
+
updatedAt?: string | null;
|
|
43
|
+
raw: unknown;
|
|
44
|
+
};
|
|
45
|
+
export type SupaCloudTaskListFilters = {
|
|
46
|
+
status?: string | string[];
|
|
47
|
+
taskType?: string | string[];
|
|
48
|
+
functionSlug?: string;
|
|
49
|
+
dlq?: boolean;
|
|
50
|
+
limit?: number;
|
|
51
|
+
};
|
|
52
|
+
export type SupaCloudTaskSubmitOptions = {
|
|
53
|
+
body?: string | Blob | ArrayBuffer | FormData | File | ReadableStream<Uint8Array> | Record<string, unknown>;
|
|
54
|
+
headers?: Record<string, string>;
|
|
55
|
+
retries?: number;
|
|
56
|
+
timeoutSec?: number;
|
|
57
|
+
idempotencyKey?: string;
|
|
58
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
59
|
+
};
|
|
60
|
+
export type SupaCloudTaskWaitOptions = {
|
|
61
|
+
intervalMs?: number;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
};
|
|
64
|
+
export type SupaCloudTaskSubscribeState = "connecting" | "realtime" | "polling" | "closed";
|
|
65
|
+
export type SupaCloudTaskSubscribeOptions = {
|
|
66
|
+
pollingIntervalMs?: number;
|
|
67
|
+
onUpdate: (task: SupaCloudTaskSnapshot) => void;
|
|
68
|
+
onStateChange?: (state: SupaCloudTaskSubscribeState, details?: {
|
|
69
|
+
error?: unknown;
|
|
70
|
+
}) => void;
|
|
71
|
+
onError?: (error: unknown) => void;
|
|
72
|
+
stopOnTerminal?: boolean;
|
|
73
|
+
};
|
|
74
|
+
export type SupaCloudTaskReceipt = {
|
|
75
|
+
taskId: string;
|
|
76
|
+
status: string;
|
|
77
|
+
get: () => Promise<SupaCloudTaskDetail>;
|
|
78
|
+
wait: (options?: SupaCloudTaskWaitOptions) => Promise<SupaCloudTaskDetail>;
|
|
79
|
+
cancel: () => Promise<SupaCloudTaskDetail>;
|
|
80
|
+
retry: () => Promise<SupaCloudTaskDetail>;
|
|
81
|
+
subscribe: (options: SupaCloudTaskSubscribeOptions) => {
|
|
82
|
+
connectionState: SupaCloudTaskSubscribeState;
|
|
83
|
+
unsubscribe: () => void;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export type SupaCloudClientOptions<TClient extends SupabaseClient = SupabaseClient> = {
|
|
87
|
+
supabase: TClient;
|
|
88
|
+
managementApiUrl: string;
|
|
89
|
+
projectRef: string;
|
|
90
|
+
getAccessToken?: () => Promise<string | null> | string | null;
|
|
91
|
+
pollingIntervalMs?: number;
|
|
92
|
+
};
|
|
93
|
+
export declare class SupaCloudTaskSubmitError extends Error {
|
|
94
|
+
readonly responseBody: unknown;
|
|
95
|
+
constructor(message: string, responseBody: unknown);
|
|
96
|
+
}
|
|
97
|
+
declare class SupaCloudTasksClient<TClient extends SupabaseClient = SupabaseClient> {
|
|
98
|
+
private readonly options;
|
|
99
|
+
constructor(options: Required<SupaCloudClientOptions<TClient>>);
|
|
100
|
+
private resolveAccessToken;
|
|
101
|
+
private request;
|
|
102
|
+
private createReceipt;
|
|
103
|
+
submit(functionName: string, options?: SupaCloudTaskSubmitOptions): Promise<SupaCloudTaskReceipt>;
|
|
104
|
+
get(taskId: string): Promise<SupaCloudTaskDetail>;
|
|
105
|
+
list(filters?: SupaCloudTaskListFilters): Promise<SupaCloudTaskDetail[]>;
|
|
106
|
+
cancel(taskId: string): Promise<SupaCloudTaskDetail>;
|
|
107
|
+
retry(taskId: string): Promise<SupaCloudTaskDetail>;
|
|
108
|
+
listDlq(limit?: number): Promise<SupaCloudTaskDetail[]>;
|
|
109
|
+
wait(taskId: string, options?: SupaCloudTaskWaitOptions): Promise<SupaCloudTaskDetail>;
|
|
110
|
+
subscribe(taskId: string, options: SupaCloudTaskSubscribeOptions): {
|
|
111
|
+
readonly connectionState: SupaCloudTaskSubscribeState;
|
|
112
|
+
unsubscribe(): void;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudClientOptions<TClient>): {
|
|
116
|
+
supabase: TClient;
|
|
117
|
+
projectRef: string;
|
|
118
|
+
managementApiUrl: string;
|
|
119
|
+
tasks: SupaCloudTasksClient<TClient>;
|
|
120
|
+
functions: {
|
|
121
|
+
invokeBackground: (functionName: string, submitOptions?: SupaCloudTaskSubmitOptions) => Promise<SupaCloudTaskReceipt>;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -96,17 +96,11 @@ class SupaCloudTasksClient {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
async submit(functionName, options = {}) {
|
|
99
|
-
const { body, headers = {}, retries, timeoutSec, idempotencyKey, method } = options;
|
|
99
|
+
const { body, headers = {}, retries: _retries, timeoutSec: _timeoutSec, idempotencyKey: _idempotencyKey, method } = options;
|
|
100
100
|
const { data, error } = await this.options.supabase.functions.invoke(functionName, {
|
|
101
101
|
body,
|
|
102
102
|
method,
|
|
103
|
-
headers
|
|
104
|
-
...headers,
|
|
105
|
-
"x-supacloud-async": "true",
|
|
106
|
-
...retries !== undefined ? { "x-supacloud-retries": String(retries) } : {},
|
|
107
|
-
...timeoutSec !== undefined ? { "x-supacloud-timeout": String(timeoutSec) } : {},
|
|
108
|
-
...idempotencyKey ? { "x-supacloud-idempotency-key": idempotencyKey } : {}
|
|
109
|
-
}
|
|
103
|
+
headers
|
|
110
104
|
});
|
|
111
105
|
if (error)
|
|
112
106
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Platform SDK for SupaCloud, built on top of supabase-js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"files": [
|
|
10
17
|
"dist",
|
|
11
18
|
"README.md"
|
|
12
19
|
],
|
|
13
20
|
"scripts": {
|
|
14
|
-
"build": "bun build
|
|
15
|
-
"
|
|
21
|
+
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
22
|
+
"build:js": "bun build src/index.ts --outdir dist --target node",
|
|
23
|
+
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"prepublishOnly": "bun run build",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"typecheck:test": "tsc -p tsconfig.test.json --noEmit"
|
|
16
28
|
},
|
|
17
29
|
"keywords": [
|
|
18
30
|
"supacloud",
|
|
@@ -31,7 +43,8 @@
|
|
|
31
43
|
"@supabase/supabase-js": "^2.103.0"
|
|
32
44
|
},
|
|
33
45
|
"devDependencies": {
|
|
46
|
+
"@types/bun": "^1.3.9",
|
|
34
47
|
"@supabase/supabase-js": "^2.103.0",
|
|
35
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^6.0.0"
|
|
36
49
|
}
|
|
37
50
|
}
|