@supacloud/js 0.12.2 → 0.14.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 CHANGED
@@ -8,6 +8,7 @@ It does **not** replace [`@supabase/supabase-js`](https://www.npmjs.com/package/
8
8
  - task detail and list APIs
9
9
  - cancel / retry helpers
10
10
  - Realtime subscription with polling fallback
11
+ - project OAuth/OIDC migration and OAuth client management
11
12
 
12
13
  ## Install
13
14
 
@@ -58,6 +59,12 @@ The current package focuses on:
58
59
  - `tasks.retry`
59
60
  - `tasks.wait`
60
61
  - `tasks.subscribe`
62
+ - `auth.oauthServer.getStatus`
63
+ - `auth.oauthServer.migrateToOidc`
64
+ - `auth.oauthServer.getDiscovery`
65
+ - `auth.oauthServer.getJwks`
66
+ - `auth.oauthServer.buildAuthorizeUrl`
67
+ - `auth.oauthClients.list/create/get/update/delete/regenerateSecret`
61
68
 
62
69
  ## Status Subscription
63
70
 
@@ -67,3 +74,9 @@ The current package focuses on:
67
74
  2. if Realtime is unavailable, fall back to polling the management API
68
75
 
69
76
  This lets apps degrade gracefully when websocket or channel health is transient.
77
+
78
+ ## OAuth/OIDC Helpers
79
+
80
+ `client.auth.oauthServer` is the SupaCloud SDK surface for project-scoped OAuth 2.1 / OIDC migration and discovery.
81
+
82
+ It does **not** take a global account scope. The SDK always sends the normal Management API Bearer token and lets the server enforce project ownership.
package/dist/index.d.ts CHANGED
@@ -117,11 +117,73 @@ export type SupaCloudClientOptions<TClient extends SupabaseClient = SupabaseClie
117
117
  getAccessToken?: () => Promise<string | null> | string | null;
118
118
  pollingIntervalMs?: number;
119
119
  };
120
+ export type SupaCloudOAuthServerStatus = {
121
+ project_ref: string;
122
+ organization_id?: string;
123
+ account_isolated: boolean;
124
+ enabled: boolean;
125
+ allow_dynamic_registration: boolean;
126
+ issuer: string;
127
+ discovery_url: string;
128
+ oauth_authorization_server_metadata_url?: string;
129
+ jwks_url: string;
130
+ authorization_endpoint: string;
131
+ token_endpoint: string;
132
+ userinfo_endpoint?: string;
133
+ registration_endpoint?: string;
134
+ signing_alg?: string;
135
+ oidc_id_token_ready?: boolean;
136
+ migration_status?: string;
137
+ warnings?: string[];
138
+ };
139
+ export type SupaCloudOAuthClientType = "public" | "confidential";
140
+ export type SupaCloudOAuthClientAuthMethod = "none" | "client_secret_basic" | "client_secret_post";
141
+ export type SupaCloudOAuthClient = {
142
+ client_id: string;
143
+ client_secret?: string;
144
+ client_type?: SupaCloudOAuthClientType | string;
145
+ redirect_uris?: string[];
146
+ token_endpoint_auth_method?: SupaCloudOAuthClientAuthMethod | string;
147
+ grant_types?: string[];
148
+ response_types?: string[];
149
+ client_name?: string;
150
+ client_uri?: string;
151
+ logo_uri?: string;
152
+ registration_type?: string;
153
+ created_at?: string;
154
+ updated_at?: string;
155
+ [key: string]: unknown;
156
+ };
157
+ export type SupaCloudOAuthClientList = {
158
+ clients?: SupaCloudOAuthClient[];
159
+ [key: string]: unknown;
160
+ };
161
+ export type SupaCloudOAuthClientCreate = {
162
+ redirect_uris: string[];
163
+ client_type?: SupaCloudOAuthClientType;
164
+ token_endpoint_auth_method?: SupaCloudOAuthClientAuthMethod;
165
+ grant_types?: string[];
166
+ client_name?: string;
167
+ client_uri?: string;
168
+ logo_uri?: string;
169
+ };
170
+ export type SupaCloudOAuthClientUpdate = Partial<Omit<SupaCloudOAuthClientCreate, "client_type">>;
171
+ export type SupaCloudAuthorizeUrlOptions = {
172
+ clientId: string;
173
+ redirectUri: string;
174
+ scope?: string | string[];
175
+ state?: string;
176
+ codeChallenge?: string;
177
+ codeChallengeMethod?: "S256" | "plain";
178
+ nonce?: string;
179
+ responseType?: "code";
180
+ resource?: string;
181
+ };
120
182
  export declare class SupaCloudTaskSubmitError extends Error {
121
183
  readonly responseBody: unknown;
122
184
  constructor(message: string, responseBody: unknown);
123
185
  }
124
- type HttpMethod = "GET" | "POST" | "DELETE";
186
+ type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
125
187
  declare class SupaCloudManagementClient<TClient extends SupabaseClient = SupabaseClient> {
126
188
  protected readonly options: Required<SupaCloudClientOptions<TClient>>;
127
189
  constructor(options: Required<SupaCloudClientOptions<TClient>>);
@@ -156,10 +218,31 @@ declare class SupaCloudQueueClient<TClient extends SupabaseClient = SupabaseClie
156
218
  release(messageId: string, options?: SupaCloudQueueReleaseOptions): Promise<SupaCloudQueueMessage>;
157
219
  fail(messageId: string, options?: SupaCloudQueueFailOptions): Promise<SupaCloudQueueMessage>;
158
220
  }
221
+ declare class SupaCloudOAuthServerClient<TClient extends SupabaseClient = SupabaseClient> extends SupaCloudManagementClient<TClient> {
222
+ getStatus(): Promise<SupaCloudOAuthServerStatus>;
223
+ migrateToOidc(options?: {
224
+ allowDynamicRegistration?: boolean;
225
+ }): Promise<SupaCloudOAuthServerStatus>;
226
+ getDiscovery(): Promise<Record<string, unknown>>;
227
+ getJwks(): Promise<Record<string, unknown>>;
228
+ buildAuthorizeUrl(options: SupaCloudAuthorizeUrlOptions): Promise<string>;
229
+ }
230
+ declare class SupaCloudOAuthClientsClient<TClient extends SupabaseClient = SupabaseClient> extends SupaCloudManagementClient<TClient> {
231
+ list(): Promise<SupaCloudOAuthClientList>;
232
+ create(input: SupaCloudOAuthClientCreate): Promise<SupaCloudOAuthClient>;
233
+ get(clientId: string): Promise<SupaCloudOAuthClient>;
234
+ update(clientId: string, patch: SupaCloudOAuthClientUpdate): Promise<SupaCloudOAuthClient>;
235
+ delete(clientId: string): Promise<void>;
236
+ regenerateSecret(clientId: string): Promise<SupaCloudOAuthClient>;
237
+ }
159
238
  export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudClientOptions<TClient>): {
160
239
  supabase: TClient;
161
240
  projectRef: string;
162
241
  managementApiUrl: string;
242
+ auth: {
243
+ oauthServer: SupaCloudOAuthServerClient<TClient>;
244
+ oauthClients: SupaCloudOAuthClientsClient<TClient>;
245
+ };
163
246
  tasks: SupaCloudTasksClient<TClient>;
164
247
  queue: (name: string) => SupaCloudQueueClient<TClient>;
165
248
  functions: {
package/dist/index.js CHANGED
@@ -366,6 +366,71 @@ class SupaCloudQueueClient extends SupaCloudManagementClient {
366
366
  return this.request(`/v1/projects/${this.options.projectRef}/tasks/queues/${this.encodedName}/messages/${messageId}/fail`, "POST", options);
367
367
  }
368
368
  }
369
+
370
+ class SupaCloudOAuthServerClient extends SupaCloudManagementClient {
371
+ async getStatus() {
372
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-server`, "GET");
373
+ }
374
+ async migrateToOidc(options = {}) {
375
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-server/migrate`, "POST", { allow_dynamic_registration: options.allowDynamicRegistration === true });
376
+ }
377
+ async getDiscovery() {
378
+ const status = await this.getStatus();
379
+ const response = await fetch(status.discovery_url);
380
+ if (!response.ok)
381
+ throw new Error(`SupaCloud OIDC discovery failed (${response.status})`);
382
+ return await response.json();
383
+ }
384
+ async getJwks() {
385
+ const status = await this.getStatus();
386
+ const response = await fetch(status.jwks_url);
387
+ if (!response.ok)
388
+ throw new Error(`SupaCloud JWKS fetch failed (${response.status})`);
389
+ return await response.json();
390
+ }
391
+ async buildAuthorizeUrl(options) {
392
+ const status = await this.getStatus();
393
+ const url = new URL(status.authorization_endpoint);
394
+ url.searchParams.set("client_id", options.clientId);
395
+ url.searchParams.set("redirect_uri", options.redirectUri);
396
+ url.searchParams.set("response_type", options.responseType ?? "code");
397
+ const scope = Array.isArray(options.scope) ? options.scope.join(" ") : options.scope;
398
+ if (scope)
399
+ url.searchParams.set("scope", scope);
400
+ if (options.state)
401
+ url.searchParams.set("state", options.state);
402
+ if (options.codeChallenge)
403
+ url.searchParams.set("code_challenge", options.codeChallenge);
404
+ if (options.codeChallengeMethod)
405
+ url.searchParams.set("code_challenge_method", options.codeChallengeMethod);
406
+ if (options.nonce)
407
+ url.searchParams.set("nonce", options.nonce);
408
+ if (options.resource)
409
+ url.searchParams.set("resource", options.resource);
410
+ return url.toString();
411
+ }
412
+ }
413
+
414
+ class SupaCloudOAuthClientsClient extends SupaCloudManagementClient {
415
+ async list() {
416
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients`, "GET");
417
+ }
418
+ async create(input) {
419
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients`, "POST", input);
420
+ }
421
+ async get(clientId) {
422
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients/${encodeURIComponent(clientId)}`, "GET");
423
+ }
424
+ async update(clientId, patch) {
425
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients/${encodeURIComponent(clientId)}`, "PUT", patch);
426
+ }
427
+ async delete(clientId) {
428
+ await this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients/${encodeURIComponent(clientId)}`, "DELETE");
429
+ }
430
+ async regenerateSecret(clientId) {
431
+ return this.request(`/v1/projects/${this.options.projectRef}/auth/oauth-clients/${encodeURIComponent(clientId)}/regenerate-secret`, "POST");
432
+ }
433
+ }
369
434
  function createSupaCloudClient(options) {
370
435
  const normalized = {
371
436
  ...options,
@@ -374,10 +439,16 @@ function createSupaCloudClient(options) {
374
439
  getAccessToken: options.getAccessToken ?? (() => defaultAccessTokenResolver(options.supabase))
375
440
  };
376
441
  const tasks = new SupaCloudTasksClient(normalized);
442
+ const oauthServer = new SupaCloudOAuthServerClient(normalized);
443
+ const oauthClients = new SupaCloudOAuthClientsClient(normalized);
377
444
  return {
378
445
  supabase: options.supabase,
379
446
  projectRef: normalized.projectRef,
380
447
  managementApiUrl: normalized.managementApiUrl,
448
+ auth: {
449
+ oauthServer,
450
+ oauthClients
451
+ },
381
452
  tasks,
382
453
  queue: (name) => new SupaCloudQueueClient(normalized, name),
383
454
  functions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/js",
3
- "version": "0.12.2",
3
+ "version": "0.14.0",
4
4
  "description": "Platform SDK for SupaCloud, built on top of supabase-js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",