@sanoma-ai/connector-supabase 0.4.12 → 0.11.22
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 +53 -18
- package/dist/authentication.d.ts +21 -0
- package/dist/authentication.js +87 -0
- package/dist/authentication.js.map +1 -0
- package/dist/connector.d.ts +23 -4
- package/dist/connector.js +19 -4
- package/dist/connector.js.map +1 -1
- package/dist/driver.d.ts +7 -14
- package/dist/driver.js +16 -23
- package/dist/driver.js.map +1 -1
- package/dist/fake.d.ts +2 -2
- package/dist/fake.js +17 -2
- package/dist/fake.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/management.d.ts +11 -5
- package/dist/management.js +17 -14
- package/dist/management.js.map +1 -1
- package/dist/resources.config.d.ts +1 -1
- package/dist/resources.config.js +1 -1
- package/dist/resources.d.ts +1 -1
- package/dist/resources.gen.d.ts +1 -1
- package/dist/vault.d.ts +1 -1
- package/dist/vault.js +2 -2
- package/dist/vault.js.map +1 -1
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @sanoma-ai/connector-supabase
|
|
2
2
|
|
|
3
|
-
Supabase projects for [
|
|
3
|
+
Supabase projects for [`sanoma/workflows`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/README.md), read through the [`supabase/supabase`](https://github.com/supabase/terraform-provider-supabase) OpenTofu provider (1.11.0) on [provider-bridge](https://github.com/Sanoma-AI/provider-bridge), which apply creates, changes and deletes, and the session pooler, health and database URL of a project from Supabase's [Management API](https://api.supabase.com/api/v1).
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -14,25 +14,26 @@ The one resource type is writable: `read` and `import` (effect `read`), and the
|
|
|
14
14
|
| --------- | ---------------------------------------------------------------------------- | ----------------------- |
|
|
15
15
|
| `project` | `supabase.project.read`, `.import`, `.plan`, `.create`, `.update`, `.delete` | `id`, the project's ref |
|
|
16
16
|
|
|
17
|
-
`import` takes `{ id }` and returns the project's `state`; `read` takes a state an earlier call returned, or just `{ id }`, and returns its fresh `state`, or `gone: true`. The change operations are [Resources](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#resources)' contract, through the provider's plan and apply. `create` first lists the projects the token can see and refuses (a `DriverError`, `vendorCode` `exists`, not retryable) when the organization has one of the declared name already: a create retried after Supabase made the project, but before the run recorded it, stops there rather than making a second project, and the error names the project's ref to bind. The provider waits for a new project to be `ACTIVE_HEALTHY` (five minutes at most).
|
|
17
|
+
`import` takes `{ id }` and returns the project's `state`; `read` takes a state an earlier call returned, or just `{ id }`, and returns its fresh `state`, or `gone: true`. The change operations are [Resources](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/README.md#resources)' contract, through the provider's plan and apply. `create` first lists the projects the token can see and refuses (a `DriverError`, `vendorCode` `exists`, not retryable) when the organization has one of the declared name already: a create retried after Supabase made the project, but before the run recorded it, stops there rather than making a second project, and the error names the project's ref to bind. The provider waits for a new project to be `ACTIVE_HEALTHY` (five minutes at most).
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Four more operations call the Management API, each but the organizations' with the project's ref as `target`:
|
|
20
20
|
|
|
21
21
|
| Operation | Effect | Input | Output |
|
|
22
22
|
| ---------------------------- | ------- | -------------------- | ---------------------------------------------------- |
|
|
23
|
+
| `supabase.organization.list` | `read` | `{}` | `{ organizations: [{ id, name }] }` |
|
|
23
24
|
| `supabase.pooler.get` | `read` | `{ ref }` | `{ host, port: 5432, user, database }` |
|
|
24
25
|
| `supabase.project.health` | `read` | `{ ref, services? }` | `{ healthy, services: [{ name, healthy, status }] }` |
|
|
25
26
|
| `supabase.database.storeUrl` | `write` | `{ ref, export }` | `{ secret }` |
|
|
26
27
|
|
|
27
28
|
`pooler.get` reads the primary database's entry of `GET /v1/projects/{ref}/config/database/pooler`. The provider's project has no host, and the pooler's (`aws-<n>-<region>.pooler.supabase.com`) is not derivable from the region, so it is read per project. The port is always 5432, the session pooler's: DBOS needs `LISTEN`/`NOTIFY`, which the transaction pooler (6543) does not carry, and the direct address is IPv6 only. `project.health` reads `GET /v1/projects/{ref}/health` for `services` (default `["db", "pooler"]`), healthy when every one is.
|
|
28
29
|
|
|
29
|
-
`database.storeUrl` builds `postgresql://<user>:<password>@<host>:5432/<database>?sslmode=require` from `pooler.get` and the stored secret `SUPABASE_DB_PASSWORD`, and stores it with the secrets store's `ensure` as `SANOMA_DATABASE_URL_<EXPORT>`, `<EXPORT>` the data file's export in upper snake case (`store` → `SANOMA_DATABASE_URL_STORE`). It returns the secret's name only: the URL is never in an output, the ledger or a log. The store only adds secrets, so when the secret holds another URL (the project was replaced, or its password or pooler changed), `storeUrl` fails (`vendorCode` `stale`), naming it: delete the secret, then store it again. A project being deleted (`GOING_DOWN`, `REMOVED`) does not stop a create of its name.
|
|
30
|
+
`database.storeUrl` builds `postgresql://<user>:<password>@<host>:5432/<database>?sslmode=require` from `pooler.get` and the stored secret `SUPABASE_DB_PASSWORD`, and stores it with the secrets store's `ensure` as `SANOMA_DATABASE_URL_<EXPORT>`, `<EXPORT>` the data file's export in upper snake case (`store` → `SANOMA_DATABASE_URL_STORE`). It returns the secret's name only: the URL is never in an output, the ledger or a log. The store only adds secrets, so when the secret holds another URL (the project was replaced, or its password or pooler changed), `storeUrl` fails (`vendorCode` `stale`), naming it: delete the secret, then store it again. A project being deleted (`GOING_DOWN`, `REMOVED`) does not stop a create of its name. A call as a named connection reaches only the secrets its operation is given, so the operation declares both, the password and the URL's secret (`createsSecrets`).
|
|
30
31
|
|
|
31
32
|
Apply calls two of them after it creates a project (the type's `afterCreate`): `project.health` until the database and pooler are healthy, then `database.storeUrl` with the data file's export, so a host can name the URL as `secret("SANOMA_DATABASE_URL_STORE")`.
|
|
32
33
|
|
|
33
|
-
The project type meets the [`Database` contract](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#databases) (`database`): it neither pauses nor branches (a paid project never pauses, and a branch starts empty), takes `region` from Supabase's regions (`database.regions`), and stores its URL with `database.storeUrl`. Going live chooses it when the config has no Neon project type.
|
|
34
|
+
The project type meets the [`Database` contract](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/README.md#databases) (`database`): it neither pauses nor branches (a paid project never pauses, and a branch starts empty), takes `region` from Supabase's regions (`database.regions`), and stores its URL with `database.storeUrl`. Going live chooses it when the config has no Neon project type.
|
|
34
35
|
|
|
35
|
-
A data file declares a project with the constructor in `@sanoma-ai/connector-supabase/resources`, without its ref, which Supabase sets: which project a declaration means is its binding, in the [lockfile](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#bindings), by its ref. A declaration with no binding is `absent` to a drift check.
|
|
36
|
+
A data file declares a project with the constructor in `@sanoma-ai/connector-supabase/resources`, without its ref, which Supabase sets: which project a declaration means is its binding, in the [lockfile](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/README.md#bindings), by its ref. A declaration with no binding is `absent` to a drift check.
|
|
36
37
|
|
|
37
38
|
```ts
|
|
38
39
|
import { supabase } from "@sanoma-ai/connector-supabase/resources";
|
|
@@ -52,13 +53,13 @@ The logo is Supabase's bolt from [Simple Icons](https://simpleicons.org/?q=supab
|
|
|
52
53
|
|
|
53
54
|
## Resource types
|
|
54
55
|
|
|
55
|
-
`src/resources.gen.ts` is generated from the provider's schema by `pnpm generate`, which runs [
|
|
56
|
+
`src/resources.gen.ts` is generated from the provider's schema by `pnpm generate`, which runs [`sanoma/internal/bridge/tfschema`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/bridge/src/tfschema/AGENTS.md) with `src/resources.config.ts`: the provider (its release, sha256 and recorded schema are `sanoma/internal/bridge`'s pin and fixture), the type, and the attributes whose change replaces the project (`organization_id` and `region`, which the provider's update refuses). It is checked in and never edited by hand; `pnpm generate` on a clean tree changes nothing. `src/connector.ts` is the rest, one `tfConnector` record from [`sanoma/internal/bridge/connector`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/bridge/README.md#connectors-for-opentofu-providers): the type's title (no identity: a project is found by its binding, its ref), when a state is no project, and Supabase's title and logo. The ref (`id`) is vendor-owned and a data file may not declare it.
|
|
56
57
|
|
|
57
|
-
The `database_password` is sensitive and the provider never reads it back: it is write-only, given as a [secret](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#secrets), never compared, and `null` in every state the driver returns. A project read by import has no password in its state, so applying a declaration to an imported project sets its password to the declared secret.
|
|
58
|
+
The `database_password` is sensitive and the provider never reads it back: it is write-only, given as a [secret](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/workflows/README.md#secrets), never compared, and `null` in every state the driver returns. A project read by import has no password in its state, so applying a declaration to an imported project sets its password to the declared secret.
|
|
58
59
|
|
|
59
60
|
## Driver
|
|
60
61
|
|
|
61
|
-
`@sanoma-ai/connector-supabase/driver` reads and changes projects through a provider bridge, and calls the Management API (`https://api.supabase.com`) with `fetch`. The `supabase` connector the package root exports carries it, made once per resolved config, and its fake (`withSetup` from
|
|
62
|
+
`@sanoma-ai/connector-supabase/driver` reads and changes projects through a provider bridge, and calls the Management API (`https://api.supabase.com`) with `fetch`. The `supabase` connector the package root exports carries it, made once per resolved config, and its fake (`withSetup` from `sanoma/workflows`), so a config names the connector alone and workflows never import the driver (the lint refuses that):
|
|
62
63
|
|
|
63
64
|
```ts
|
|
64
65
|
import { supabase } from "@sanoma-ai/connector-supabase";
|
|
@@ -68,19 +69,53 @@ export default defineConfig({ workflows, connectors: [supabase], policy });
|
|
|
68
69
|
|
|
69
70
|
`./driver` (`supabaseDriver`; `supabaseDriver({ bridge })` reads through a bridge of your own, `timeoutMs` bounds a Management API request, 30 seconds by default) and `./fake` (`fakeSupabase`) are internal entries, for tests.
|
|
70
71
|
|
|
71
|
-
Without `bridge`, it reads through the process's `defaultBridge()` from
|
|
72
|
+
Without `bridge`, it reads through the process's `defaultBridge()` from `sanoma/internal/bridge`, started on the first call with the binary `startBridge` finds. It configures the provider in a session of its own for each call, with `{ access_token }`, the selected connection's token.
|
|
72
73
|
|
|
73
74
|
The provider answers a project that does not exist (Supabase's 404) with the state it was given, not with none. So `read` always imports, from the ref alone, never refreshing the state it is given, and a project without a `name` is `gone`.
|
|
74
75
|
|
|
75
|
-
###
|
|
76
|
+
### Accounts
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
Every call runs as a named connection, declared in code: one marked `default: true`, or one a workflow selects. The driver takes that connection's token on each call and never reads the environment: `SUPABASE_ACCESS_TOKEN` is not read. Going live lists organizations and creates the project as the declared default. There are two methods:
|
|
78
79
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
| `
|
|
80
|
+
| Method | What the person does | Account |
|
|
81
|
+
| ------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------ |
|
|
82
|
+
| `oauth` | Approves access at Supabase (the company's own OAuth application, authorization code with PKCE) | The organization they choose |
|
|
83
|
+
| `accessToken` | Pastes a [personal access token](https://supabase.com/dashboard/account/tokens) on the connector page | Every organization of its user |
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
Both verify by `GET /v1/organizations`. The account is the organizations' IDs, sorted and joined with commas. Supabase attests no scopes, so none are claimed.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { supabase } from "@sanoma-ai/connector-supabase";
|
|
89
|
+
import { defineConfig, defineConnection } from "sanoma";
|
|
90
|
+
import { secret } from "sanoma/resources";
|
|
91
|
+
|
|
92
|
+
const infra = defineConnection(supabase, {
|
|
93
|
+
name: "infra",
|
|
94
|
+
method: "oauth",
|
|
95
|
+
credentials: secret("SUPABASE_INFRA"),
|
|
96
|
+
client: secret("SUPABASE_OAUTH_APP"),
|
|
97
|
+
default: true,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export default defineConfig({ workflows, connectors: [supabase], connections: [infra] });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
For `accessToken`, leave out `client`.
|
|
104
|
+
|
|
105
|
+
#### Registering the OAuth application
|
|
106
|
+
|
|
107
|
+
`oauth` uses an OAuth application your company registers in its own Supabase organization, never Sanoma's. In the [Supabase dashboard](https://supabase.com/dashboard), open the organization's settings, then **OAuth Apps**, and add an application:
|
|
108
|
+
|
|
109
|
+
- **Redirect URI:** `<the app's origin>/connect/supabase/callback`, such as `https://ops.example.com/connect/supabase/callback`. Register one for each origin the app is reached at, `http://localhost:<port>/connect/supabase/callback` for a local app included.
|
|
110
|
+
- **Scopes:** Supabase takes scopes from the application, not from the request, so this connector sends none. Grant at least Organizations read (verify and `organization.list`), Projects read and write (`project.*`, `project.health`, the create guard) and Database read (`pooler.get`, `database.storeUrl`). Changing them later needs everyone to authorize again (**Reconnect**).
|
|
111
|
+
|
|
112
|
+
Then on `/connectors/supabase`, **Connect account** asks for the application's client ID and secret. It stores them as the `client` secret, apart from the grant, and opens Supabase's consent in a new tab. The client ID and secret are never environment variables. The authorize endpoint is `https://api.supabase.com/v1/oauth/authorize` and the token endpoint `https://api.supabase.com/v1/oauth/token`, with the client's credentials in HTTP Basic.
|
|
113
|
+
|
|
114
|
+
A grant expires, and the runtime [renews it](../../packages/sanoma/workflows/README.md#renewal-reconnect-disconnect-and-revoke) with its refresh token at `https://api.supabase.com/v1/oauth/token`, on use: when a call finds it near its expiry, and when a Management API call answers 401 (`tokenRejected: [401]`, Supabase's guide says to handle 401 by refreshing). The connector declares no `refreshTokenLifetime`, since Supabase publishes none, so nothing is scheduled and an idle instance is never woken to renew a Supabase grant; one unused past its refresh token's life needs **Reconnect**. A call through the bridge carries no HTTP status, so it relies on the renewal near expiry. Supabase publishes no token lifetime: as of 2026-11-06 its [Management API reference](https://api.supabase.com/api/v1) requires `expires_in` in the token answer and states no value, and its [OAuth app guide](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration) says neither how long tokens last nor whether a refresh token is rotated. The runtime therefore renews from each answer's `expires_in` and treats every refresh token as single-use: a renewal sent whose answer was lost leaves the account `uncertain`, to **Reconnect**; one that never reached Supabase is tried again by the next call. A refresh token Supabase refuses (`invalid_grant`, as when someone revoked the application's access) marks the account revoked. The card shows when access is valid until and when it was last renewed.
|
|
115
|
+
|
|
116
|
+
**Revoke** posts the grant's refresh token with the application's client ID and secret, as JSON, to `https://api.supabase.com/v1/oauth/revoke` (answered 204; Supabase documents this endpoint as beta as of 2026-11-06, and it is not RFC 7009's form-encoded request), then deletes the grant. **Disconnect** deletes the grant without telling Supabase. Both keep the OAuth application (`SUPABASE_OAUTH_APP`) for the next account.
|
|
117
|
+
|
|
118
|
+
The bridge passes each call's token to the provider through its config only. The default bridge's binary comes with `sanoma/internal/bridge` or from `SANOMA_BRIDGE_BIN` (see [the bridge](https://github.com/Sanoma-AI/sanoma/blob/main/packages/sanoma/bridge/README.md#the-binary)), not a credential of the connector; it must trust Supabase's signing key, since the OpenTofu registry serves none for this provider.
|
|
84
119
|
|
|
85
120
|
### Errors and retries
|
|
86
121
|
|
|
@@ -162,7 +197,7 @@ Declare that path with `management: "external"`. The gateway independently refus
|
|
|
162
197
|
|
|
163
198
|
### Supabase plus Cloudflare
|
|
164
199
|
|
|
165
|
-
Supply the scoped login's Postgres URL as `SUPABASE_VAULT_DATABASE_URL` to the **Sanoma Node runtime**, with TLS certificate verification enabled for remote connections. `databaseUrlEnv` selects another bootstrap variable. Supply `SANOMA_SIGNING_KEY` independently, plus the application's database URL. Vault values do **not** need `SANOMA_SECRETS_KEY`.
|
|
200
|
+
Supply the scoped login's Postgres URL as `SUPABASE_VAULT_DATABASE_URL` to the **Sanoma Node runtime**, with TLS certificate verification enabled for remote connections. `databaseUrlEnv` selects another bootstrap variable. Supply `SANOMA_SIGNING_KEY` independently, plus the application's database URL. Vault values do **not** need `SANOMA_SECRETS_KEY`. On a Cloudflare host, bind the login with `host: true`, such as `VAULT_LOGIN: { env: "SUPABASE_VAULT_DATABASE_URL", host: true }`: apply gives the Worker it as a secret, and the container receives it in its environment at its start ([Cloudflare's setup](../cloudflare/README.md#setups)). This adapter connects with `pg`; it uses no Worker binding.
|
|
166
201
|
|
|
167
202
|
The adapter opens at most four connections lazily, releases idle connections after one second, and exposes `close()` for tools/tests. Keep SQL statement/parameter logging and tracing configured to exclude credential values; the adapter uses bound parameters and sanitized errors, but database administrators control database logs. Never log the bootstrap URL.
|
|
168
203
|
|
|
@@ -173,7 +208,7 @@ The adapter opens at most four connections lazily, releases idle connections aft
|
|
|
173
208
|
- Locking is project-wide: gateway reads can run concurrently, but gateway writes serialize across all Vault secrets, including unrelated namespaces. Reads block Vault writes while held; gateway writes also block gateway reads. Locks last until the transaction ends, so long transactions increase contention for other Vault users. This favors consistent versions and atomic compare-and-set over per-secret write concurrency.
|
|
174
209
|
- Deletion removes the active row. Database backups/PITR may retain older encrypted data according to the project's retention policy. It is not cryptographic erasure.
|
|
175
210
|
- The gateway detects ordinary direct Vault updates, but project administrators remain trusted: they control grants, functions, metadata, and encryption custody. Runtime scope is not protection against a compromised project administrator.
|
|
176
|
-
- Supabase manages the project encryption key. Preserve the gateway grant/mapping/revision tables with database backups. A raw dump moved to another project may not be decryptable without the original Vault key; use Supabase's documented restore/key-transfer route or an authorized decrypt-and-reencrypt migration.
|
|
211
|
+
- Supabase manages the project encryption key. Preserve the gateway grant/mapping/revision tables with database backups. A raw dump moved to another project may not be decryptable without the original Vault key; use Supabase's documented restore/key-transfer route or an authorized decrypt-and-reencrypt migration. To move the secrets into or out of Vault, name it (or the built-in store) under `secrets.stores` and run the `migrate-store` workflow ([Moving between stores](../../packages/sanoma/workflows/README.md#moving-between-stores)); its destination check writes in the `sanoma-move-check` and `sanoma-move-check-other` namespaces, so grant the login those too, as writable. This adapter does not export root keys.
|
|
177
212
|
|
|
178
213
|
See [Vault APIs and recovery](https://supabase.com/docs/guides/database/vault) and [Supabase's privilege constraints](https://supabase.com/kb/troubleshooting/revoking-privileges-on-storage-pg_cron-vault-and-extension-objects-has-no-effect). Tested with the actual Vault extension and standard administrator permissions in `supabase/postgres:17.6.1.136`; hosted-project permissions still depend on the project's installed grants/version.
|
|
179
214
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type OAuthAuthentication, type StoredAuthentication } from "sanoma/workflows";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Supabase's Management API, which both methods' tokens call. */
|
|
4
|
+
export declare const API = "https://api.supabase.com";
|
|
5
|
+
/**
|
|
6
|
+
* Supabase's OAuth (Management API, authorization code with PKCE): the company registers its
|
|
7
|
+
* own OAuth application in its Supabase organization (Settings, OAuth Apps) with the redirect URI
|
|
8
|
+
* `<app origin>/connect/supabase/callback`, and enters its client ID and secret on the connector
|
|
9
|
+
* page. Supabase takes scopes from the application, not the request, so none are sent. The grant
|
|
10
|
+
* carries an expiry (`expires_in`, which Supabase's API reference requires but does not fix), and
|
|
11
|
+
* the runtime renews it with its refresh token before then, and when the Management API answers
|
|
12
|
+
* 401 (Supabase's guide: "handle HTTP Unauthorized errors"). Revoke asks Supabase to end the
|
|
13
|
+
* application's authorization and its tokens (`POST /v1/oauth/revoke`, JSON, not RFC 7009's form).
|
|
14
|
+
*/
|
|
15
|
+
export declare const supabaseOAuth: OAuthAuthentication;
|
|
16
|
+
declare const accessTokenBundle: z.ZodObject<{
|
|
17
|
+
accessToken: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** A personal access token, pasted on the connector page: its user's organizations are the account. */
|
|
20
|
+
export declare const supabaseAccessToken: StoredAuthentication<typeof accessTokenBundle>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { AuthenticationError, defineAuthentication, } from "sanoma/workflows";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Supabase's Management API, which both methods' tokens call. */
|
|
4
|
+
export const API = "https://api.supabase.com";
|
|
5
|
+
/**
|
|
6
|
+
* The account a token authorizes, from Supabase: the organizations `GET /v1/organizations`
|
|
7
|
+
* lists, by id, sorted and joined with commas. An OAuth grant reaches the one organization the
|
|
8
|
+
* person chose at consent; a personal access token every organization of its user. Supabase
|
|
9
|
+
* attests no scopes to either, so none are claimed.
|
|
10
|
+
*/
|
|
11
|
+
async function organizationsOf(token) {
|
|
12
|
+
const res = await fetch(`${API}/v1/organizations`, {
|
|
13
|
+
headers: { authorization: `Bearer ${token}`, accept: "application/json" },
|
|
14
|
+
signal: AbortSignal.timeout(10_000),
|
|
15
|
+
});
|
|
16
|
+
if (res.status === 401 || res.status === 403)
|
|
17
|
+
throw new AuthenticationError("rejected");
|
|
18
|
+
if (!res.ok)
|
|
19
|
+
throw new AuthenticationError("unavailable");
|
|
20
|
+
const organizations = (await res.json());
|
|
21
|
+
const ids = Array.isArray(organizations)
|
|
22
|
+
? organizations.map((o) => o?.id).filter((id) => typeof id === "string")
|
|
23
|
+
: [];
|
|
24
|
+
if (!ids.length)
|
|
25
|
+
throw new AuthenticationError("rejected");
|
|
26
|
+
return { account: ids.toSorted().join(","), scopes: [] };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Supabase's OAuth (Management API, authorization code with PKCE): the company registers its
|
|
30
|
+
* own OAuth application in its Supabase organization (Settings, OAuth Apps) with the redirect URI
|
|
31
|
+
* `<app origin>/connect/supabase/callback`, and enters its client ID and secret on the connector
|
|
32
|
+
* page. Supabase takes scopes from the application, not the request, so none are sent. The grant
|
|
33
|
+
* carries an expiry (`expires_in`, which Supabase's API reference requires but does not fix), and
|
|
34
|
+
* the runtime renews it with its refresh token before then, and when the Management API answers
|
|
35
|
+
* 401 (Supabase's guide: "handle HTTP Unauthorized errors"). Revoke asks Supabase to end the
|
|
36
|
+
* application's authorization and its tokens (`POST /v1/oauth/revoke`, JSON, not RFC 7009's form).
|
|
37
|
+
*/
|
|
38
|
+
export const supabaseOAuth = defineAuthentication({
|
|
39
|
+
kind: "oauth2",
|
|
40
|
+
version: 1,
|
|
41
|
+
storage: { writable: true, conditionalWrites: true, maxBytes: 16_384 },
|
|
42
|
+
oauth: {
|
|
43
|
+
authorizeUrl: `${API}/v1/oauth/authorize`,
|
|
44
|
+
tokenUrl: `${API}/v1/oauth/token`,
|
|
45
|
+
scopes: [],
|
|
46
|
+
pkce: true,
|
|
47
|
+
clientAuthentication: "client_secret_basic",
|
|
48
|
+
refresh: "refresh_token",
|
|
49
|
+
tokenRejected: [401],
|
|
50
|
+
// No `refreshTokenLifetime`: Supabase publishes none (2026-11-06), so a grant renews on use only.
|
|
51
|
+
},
|
|
52
|
+
async verify(grant) {
|
|
53
|
+
const identity = await organizationsOf(grant.accessToken);
|
|
54
|
+
return grant.expiresAt === undefined ? identity : { ...identity, expiresAt: grant.expiresAt };
|
|
55
|
+
},
|
|
56
|
+
async revoke(grant, client) {
|
|
57
|
+
if (!grant.refreshToken)
|
|
58
|
+
throw new AuthenticationError("unsupported");
|
|
59
|
+
const res = await fetch(`${API}/v1/oauth/revoke`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
client_id: client.clientId,
|
|
64
|
+
client_secret: client.clientSecret,
|
|
65
|
+
refresh_token: grant.refreshToken,
|
|
66
|
+
}),
|
|
67
|
+
signal: AbortSignal.timeout(10_000),
|
|
68
|
+
});
|
|
69
|
+
if (!res.ok)
|
|
70
|
+
throw new AuthenticationError(res.status === 401 || res.status === 403 ? "rejected" : "unavailable");
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const accessTokenBundle = z.object({
|
|
74
|
+
accessToken: z
|
|
75
|
+
.string()
|
|
76
|
+
.min(1)
|
|
77
|
+
.describe("A personal access token from supabase.com/dashboard/account/tokens that can manage the projects"),
|
|
78
|
+
});
|
|
79
|
+
/** A personal access token, pasted on the connector page: its user's organizations are the account. */
|
|
80
|
+
export const supabaseAccessToken = defineAuthentication({
|
|
81
|
+
kind: "api-key",
|
|
82
|
+
version: 1,
|
|
83
|
+
schema: accessTokenBundle,
|
|
84
|
+
storage: { writable: false, conditionalWrites: false, maxBytes: 8192 },
|
|
85
|
+
verify: ({ accessToken }) => organizationsOf(accessToken),
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEnB,oBAAoB,GAGrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,kEAAkE;AAClE,MAAM,CAAC,MAAM,GAAG,GAAG,0BAA0B,CAAC;AAE9C;;;;;GAKG;AACH,KAAK,UAAU,eAAe,CAAC,KAAa;IAC1C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,mBAAmB,EAAE;QACjD,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;QACzE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;KACpC,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;QAAE,MAAM,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACxF,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAuB,CAAC;IAC/D,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;QACtC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC;QACxE,CAAC,CAAC,EAAE,CAAC;IACP,IAAI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AAM,EAAE,kBAAkB,EAAE;YAC3E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,SAAS,EAAE,MAAM,CAAC,QAAQ;gBAC1B,aAAa,EAAE,MAAM,CAAC,YAAY;gBAClC,aAAa,EAAE,KAAK,CAAC,YAAY;aAClC,CAAC;YACF,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;SACpC,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,mBAAmB,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IACpH,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,iGAAiG,CAAC;CAC/G,CAAC,CAAC;AAEH,uGAAuG;AACvG,MAAM,CAAC,MAAM,mBAAmB,GAAmD,oBAAoB,CAAC;IACtG,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,iBAAiB;IACzB,OAAO,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,WAAW,CAAC;CAC1D,CAAC,CAAC"}
|
package/dist/connector.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
* provider's driver come from this one record; `supabaseOps` adds the Management API operations,
|
|
9
9
|
* two of which apply calls after it creates a project.
|
|
10
10
|
*/
|
|
11
|
-
export declare const supabaseTf: import("
|
|
11
|
+
export declare const supabaseTf: import("sanoma/internal/bridge/connector").TfConnector<"supabase", {
|
|
12
12
|
readonly project: z.ZodObject<{
|
|
13
13
|
database_password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
14
|
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -25,6 +25,8 @@ export declare const supabaseTf: import("@sanoma-ai/bridge/connector").TfConnect
|
|
|
25
25
|
}, {}, {
|
|
26
26
|
readonly project: true;
|
|
27
27
|
}>;
|
|
28
|
+
/** The secret the project's declared `database_password` names, which the URL is built with. */
|
|
29
|
+
export declare const PASSWORD_SECRET = "SUPABASE_DB_PASSWORD";
|
|
28
30
|
declare const target: ({ ref }: {
|
|
29
31
|
ref: string;
|
|
30
32
|
}) => string;
|
|
@@ -33,7 +35,21 @@ declare const target: ({ ref }: {
|
|
|
33
35
|
* pooler's address, the project's health, and the database URL a worker connects with, which
|
|
34
36
|
* only the secrets store ever holds.
|
|
35
37
|
*/
|
|
36
|
-
declare const management: import("
|
|
38
|
+
declare const management: import("sanoma/workflows").Connector<"supabase", {
|
|
39
|
+
readonly organization: {
|
|
40
|
+
readonly list: {
|
|
41
|
+
readonly effect: "read";
|
|
42
|
+
readonly idempotent: true;
|
|
43
|
+
readonly description: "List the organizations the connection's token reaches: one for an OAuth grant";
|
|
44
|
+
readonly input: z.ZodObject<{}, z.core.$strip>;
|
|
45
|
+
readonly output: z.ZodObject<{
|
|
46
|
+
organizations: z.ZodArray<z.ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
name: z.ZodString;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
37
53
|
readonly pooler: {
|
|
38
54
|
readonly get: {
|
|
39
55
|
readonly effect: "read";
|
|
@@ -73,6 +89,9 @@ declare const management: import("@sanoma-ai/workflows").Connector<"supabase", {
|
|
|
73
89
|
};
|
|
74
90
|
readonly database: {
|
|
75
91
|
readonly storeUrl: {
|
|
92
|
+
readonly createsSecrets: ({ export: name }: {
|
|
93
|
+
export: string;
|
|
94
|
+
}) => string[];
|
|
76
95
|
readonly effect: "write";
|
|
77
96
|
readonly idempotent: true;
|
|
78
97
|
readonly description: "Store a project's database URL, through its session pooler with the password in SUPABASE_DB_PASSWORD, as the secret SANOMA_DATABASE_URL_<EXPORT>, never returned; refused when that secret holds another URL";
|
|
@@ -89,8 +108,8 @@ declare const management: import("@sanoma-ai/workflows").Connector<"supabase", {
|
|
|
89
108
|
}>;
|
|
90
109
|
/**
|
|
91
110
|
* The Supabase connector's operations: the project type's (`read`, `import`, `plan`, `create`,
|
|
92
|
-
* `update`, `delete`) and the Management API's (`
|
|
93
|
-
* `database.storeUrl`).
|
|
111
|
+
* `update`, `delete`) and the Management API's (`organization.list`, `project.health`,
|
|
112
|
+
* `pooler.get`, `database.storeUrl`).
|
|
94
113
|
*/
|
|
95
114
|
export declare const supabaseOps: SupabaseOps;
|
|
96
115
|
/** The Supabase connector's type: the provider's resource types with the Management API operations. */
|
package/dist/connector.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { tfConnector } from "
|
|
2
|
-
import { defineConnector, vendorInfo } from "
|
|
1
|
+
import { tfConnector } from "sanoma/internal/bridge/connector";
|
|
2
|
+
import { databaseUrlSecret, defineConnector, vendorInfo } from "sanoma/workflows";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { provider, supabase_project } from "./resources.gen.js";
|
|
5
5
|
/** Supabase's regions, as a project's `region` takes them. */
|
|
@@ -61,6 +61,8 @@ export const supabaseTf = tfConnector({
|
|
|
61
61
|
info: vendorInfo(import.meta.url),
|
|
62
62
|
});
|
|
63
63
|
const projectRef = z.string().min(1).describe("The project's ref");
|
|
64
|
+
/** The secret the project's declared `database_password` names, which the URL is built with. */
|
|
65
|
+
export const PASSWORD_SECRET = "SUPABASE_DB_PASSWORD";
|
|
64
66
|
const target = ({ ref }) => ref;
|
|
65
67
|
/**
|
|
66
68
|
* What the provider's project does not carry, from Supabase's Management API: the session
|
|
@@ -68,6 +70,15 @@ const target = ({ ref }) => ref;
|
|
|
68
70
|
* only the secrets store ever holds.
|
|
69
71
|
*/
|
|
70
72
|
const management = defineConnector("supabase", {
|
|
73
|
+
organization: {
|
|
74
|
+
list: {
|
|
75
|
+
effect: "read",
|
|
76
|
+
idempotent: true,
|
|
77
|
+
description: "List the organizations the connection's token reaches: one for an OAuth grant",
|
|
78
|
+
input: z.object({}),
|
|
79
|
+
output: z.object({ organizations: z.array(z.object({ id: z.string(), name: z.string() })) }),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
71
82
|
pooler: {
|
|
72
83
|
get: {
|
|
73
84
|
effect: "read",
|
|
@@ -93,6 +104,9 @@ const management = defineConnector("supabase", {
|
|
|
93
104
|
},
|
|
94
105
|
database: {
|
|
95
106
|
storeUrl: {
|
|
107
|
+
// The secrets a call as a named connection may reach, which its input names none of: the
|
|
108
|
+
// password it reads, and the URL it stores.
|
|
109
|
+
createsSecrets: ({ export: name }) => [PASSWORD_SECRET, databaseUrlSecret(name)],
|
|
96
110
|
effect: "write",
|
|
97
111
|
idempotent: true,
|
|
98
112
|
description: "Store a project's database URL, through its session pooler with the password in SUPABASE_DB_PASSWORD, as the secret SANOMA_DATABASE_URL_<EXPORT>, never returned; refused when that secret holds another URL",
|
|
@@ -110,12 +124,13 @@ const management = defineConnector("supabase", {
|
|
|
110
124
|
});
|
|
111
125
|
/**
|
|
112
126
|
* The Supabase connector's operations: the project type's (`read`, `import`, `plan`, `create`,
|
|
113
|
-
* `update`, `delete`) and the Management API's (`
|
|
114
|
-
* `database.storeUrl`).
|
|
127
|
+
* `update`, `delete`) and the Management API's (`organization.list`, `project.health`,
|
|
128
|
+
* `pooler.get`, `database.storeUrl`).
|
|
115
129
|
*/
|
|
116
130
|
export const supabaseOps = {
|
|
117
131
|
...supabaseTf.connector,
|
|
118
132
|
project: { ...supabaseTf.connector.project, ...management.project },
|
|
133
|
+
organization: management.organization,
|
|
119
134
|
pooler: management.pooler,
|
|
120
135
|
database: management.database,
|
|
121
136
|
};
|
package/dist/connector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,8DAA8D;AAC9D,MAAM,OAAO,GAAG;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,cAAc;IACd,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;CACR,CAAC;AAEX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC;IACpC,MAAM,EAAE,UAAU;IAClB,QAAQ;IACR,KAAK,EAAE;QACL,OAAO,EAAE;YACP,EAAE,EAAE,gBAAgB;YACpB,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI;YACrC,QAAQ,EAAE,IAAI;YACd,wFAAwF;YACxF,oGAAoG;YACpG,QAAQ,EAAE;gBACR,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;gBAC9C,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;gBAC5B,QA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,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;aAC5F,CAAC;YACF,MAAM;SACP;KACF;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE;YACR,yFAAyF;YACzF,4CAA4C;YAC5C,cAAc,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAsB,EAAE,EAAE,CAAC,CAAC,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACpG,MAAM,EAAE,OAAO;YACf,UAAU,EAAE,IAAI;YAChB,WAAW,EACT,8MAA8M;YAChN,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;gBACd,GAAG,EAAE,UAAU;gBACf,MAAM,EAAE,CAAC;qBACN,MAAM,EAAE;qBACR,KAAK,CAAC,0BAA0B,CAAC;qBACjC,QAAQ,CAAC,mEAAmE,CAAC;aACjF,CAAC;YACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC,EAAE,CAAC;YACpG,MAAM;SACP;KACF;CACF,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,UAAU,CAAC,SAAS;IACvB,OAAO,EAAE,EAAE,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE;IACnE,YAAY,EAAE,UAAU,CAAC,YAAY;IACrC,MAAM,EAAE,UAAU,CAAC,MAAM;IACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ;CACf,CAAC"}
|
package/dist/driver.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type ProviderClient } from "
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import { type ProviderClient } from "sanoma/internal/bridge";
|
|
3
2
|
export interface SupabaseDriverOptions {
|
|
4
3
|
/**
|
|
5
4
|
* The provider bridge to read through. Default: the process's `defaultBridge()`, started on the
|
|
6
|
-
* first call (`startBridge`'s binary).
|
|
5
|
+
* first call (`startBridge`'s binary). Each call's token is a provider session of its own.
|
|
7
6
|
*/
|
|
8
7
|
bridge?: ProviderClient;
|
|
9
8
|
/** How long a Management API request may take, in milliseconds. Default 30 seconds. */
|
|
@@ -11,15 +10,9 @@ export interface SupabaseDriverOptions {
|
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Supabase's projects through the `supabase/supabase` OpenTofu provider on `bridge` (the default
|
|
14
|
-
* bridge when none is given), and the pooler, health and database URL through the
|
|
15
|
-
* with the
|
|
16
|
-
*
|
|
13
|
+
* bridge when none is given), and the organizations, pooler, health and database URL through the
|
|
14
|
+
* Management API, each call with the selected connection's token: an OAuth grant's (`oauth`) or a
|
|
15
|
+
* personal access token (`accessToken`). The provider is configured per token, in a session of
|
|
16
|
+
* its own.
|
|
17
17
|
*/
|
|
18
|
-
export declare function supabaseDriver({ bridge, timeoutMs }?: SupabaseDriverOptions):
|
|
19
|
-
vendor: string;
|
|
20
|
-
ops: Readonly<Record<string, import("@sanoma-ai/workflows").DriverFn>>;
|
|
21
|
-
authentication?: readonly string[];
|
|
22
|
-
env: z.ZodObject<{
|
|
23
|
-
SUPABASE_ACCESS_TOKEN: z.ZodString;
|
|
24
|
-
}, z.core.$strip>;
|
|
25
|
-
}>;
|
|
18
|
+
export declare function supabaseDriver({ bridge, timeoutMs }?: SupabaseDriverOptions): import("sanoma/workflows").Driver;
|
package/dist/driver.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import { defaultBridge } from "
|
|
2
|
-
import { DriverError, retryableStatus } from "
|
|
3
|
-
import {
|
|
1
|
+
import { defaultBridge } from "sanoma/internal/bridge";
|
|
2
|
+
import { authenticationCredentials, DriverError, retryableStatus } from "sanoma/workflows";
|
|
3
|
+
import { API, supabaseAccessToken, supabaseOAuth } from "./authentication.js";
|
|
4
4
|
import { supabaseTf } from "./connector.js";
|
|
5
5
|
import { apiError, withManagement } from "./management.js";
|
|
6
|
-
/** The
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
const API = "https://api.supabase.com";
|
|
14
|
-
const accessToken = () => {
|
|
15
|
-
const value = process.env.SUPABASE_ACCESS_TOKEN;
|
|
16
|
-
if (!value)
|
|
17
|
-
throw new DriverError("supabase: SUPABASE_ACCESS_TOKEN is not set", { retryable: false });
|
|
18
|
-
return value;
|
|
19
|
-
};
|
|
6
|
+
/** The methods the driver takes a token from: an OAuth grant's, or a pasted personal access token. */
|
|
7
|
+
const METHODS = ["oauth", "accessToken"];
|
|
8
|
+
/** The selected connection's token for this call: never the environment. */
|
|
9
|
+
const accessToken = (call) => call.authentication?.method === "oauth"
|
|
10
|
+
? authenticationCredentials("oauth", supabaseOAuth, call).accessToken
|
|
11
|
+
: authenticationCredentials("accessToken", supabaseAccessToken, call).accessToken;
|
|
20
12
|
const project = (ref) => `/v1/projects/${encodeURIComponent(ref)}`;
|
|
21
13
|
/** The Management API with `token`: each request a GET, its failures `DriverError`s, retryable as the runtime's rule says. */
|
|
22
14
|
function managementApi(token, timeoutMs) {
|
|
@@ -48,6 +40,7 @@ function managementApi(token, timeoutMs) {
|
|
|
48
40
|
}
|
|
49
41
|
};
|
|
50
42
|
return {
|
|
43
|
+
organizations: () => get("/v1/organizations"),
|
|
51
44
|
projects: () => get("/v1/projects"),
|
|
52
45
|
pooler: (ref) => get(`${project(ref)}/config/database/pooler`),
|
|
53
46
|
health: (ref, services) => get(`${project(ref)}/health?services=${services.map(encodeURIComponent).join(",")}`),
|
|
@@ -55,13 +48,13 @@ function managementApi(token, timeoutMs) {
|
|
|
55
48
|
}
|
|
56
49
|
/**
|
|
57
50
|
* Supabase's projects through the `supabase/supabase` OpenTofu provider on `bridge` (the default
|
|
58
|
-
* bridge when none is given), and the pooler, health and database URL through the
|
|
59
|
-
* with the
|
|
60
|
-
*
|
|
51
|
+
* bridge when none is given), and the organizations, pooler, health and database URL through the
|
|
52
|
+
* Management API, each call with the selected connection's token: an OAuth grant's (`oauth`) or a
|
|
53
|
+
* personal access token (`accessToken`). The provider is configured per token, in a session of
|
|
54
|
+
* its own.
|
|
61
55
|
*/
|
|
62
56
|
export function supabaseDriver({ bridge = defaultBridge(), timeoutMs = 30_000 } = {}) {
|
|
63
|
-
const provider = supabaseTf.driver(bridge, () => ({ access_token: accessToken(), endpoint: null }));
|
|
64
|
-
|
|
65
|
-
return Object.freeze({ ...driver, env });
|
|
57
|
+
const provider = supabaseTf.driver(bridge, (call) => ({ access_token: accessToken(call), endpoint: null }), undefined, undefined, { authentication: METHODS });
|
|
58
|
+
return withManagement(provider, (call) => managementApi(accessToken(call), timeoutMs));
|
|
66
59
|
}
|
|
67
60
|
//# sourceMappingURL=driver.js.map
|
package/dist/driver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAoB,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC7G,OAAO,EAAE,GAAG,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAY/E,sGAAsG;AACtG,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAEzC,4EAA4E;AAC5E,MAAM,WAAW,GAAG,CAAC,IAAiB,EAAE,EAAE,C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CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC/D,SAAS,EACT,SAAS,EACT,EAAE,cAAc,EAAE,OAAO,EAAE,CAC5B,CAAC;IACF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
package/dist/fake.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TfFakeOptions, type TfFakeState } from "
|
|
1
|
+
import { type TfFakeOptions, type TfFakeState } from "sanoma/internal/bridge/fake";
|
|
2
2
|
export type FakeSupabaseState = TfFakeState;
|
|
3
3
|
export type FakeSupabaseOptions = TfFakeOptions;
|
|
4
4
|
/**
|
|
@@ -13,7 +13,7 @@ export type FakeSupabaseOptions = TfFakeOptions;
|
|
|
13
13
|
* `put` makes a project, `override` changes what the next read returns, as if someone edited
|
|
14
14
|
* the project in Supabase's dashboard, and `remove` deletes it, so the next read says it is gone.
|
|
15
15
|
*/
|
|
16
|
-
export declare function fakeSupabase(options?: FakeSupabaseOptions): import("
|
|
16
|
+
export declare function fakeSupabase(options?: FakeSupabaseOptions): import("sanoma/internal/bridge/fake").TfFake<"supabase", {
|
|
17
17
|
readonly project: import("zod").ZodObject<{
|
|
18
18
|
database_password: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
19
19
|
id: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
package/dist/fake.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { tfFake } from "
|
|
1
|
+
import { tfFake } from "sanoma/internal/bridge/fake";
|
|
2
2
|
import { supabaseOps, supabaseTf } from "./connector.js";
|
|
3
3
|
import { apiError, withManagement } from "./management.js";
|
|
4
4
|
/** The replies the fake serves, written by hand to the provider's schema: there is no Supabase recording yet. */
|
|
@@ -13,6 +13,11 @@ function fakeApi(state) {
|
|
|
13
13
|
return found;
|
|
14
14
|
};
|
|
15
15
|
return {
|
|
16
|
+
// The organizations of its projects, else one of its own: a token of the fake reaches them all.
|
|
17
|
+
organizations: async () => {
|
|
18
|
+
const ids = [...new Set(projects().map((p) => String(p.organization_id)))];
|
|
19
|
+
return (ids.length ? ids : ["sanoma-test-org"]).map((id) => ({ id, name: id }));
|
|
20
|
+
},
|
|
16
21
|
projects: async () => projects().map((p) => ({ id: String(p.id), name: String(p.name), organization_id: String(p.organization_id) })),
|
|
17
22
|
pooler: async (ref) => {
|
|
18
23
|
const { region } = project(ref, "/config/database/pooler");
|
|
@@ -47,7 +52,17 @@ export function fakeSupabase(options = {}) {
|
|
|
47
52
|
const fake = tfFake({
|
|
48
53
|
...supabaseTf,
|
|
49
54
|
connector: supabaseOps,
|
|
50
|
-
driver: (...args) =>
|
|
55
|
+
driver: (...args) => {
|
|
56
|
+
const driver = withManagement(supabaseTf.driver(...args), () => fakeApi(state));
|
|
57
|
+
// A connection's account is the fake's own: its calls go on without the connection's token.
|
|
58
|
+
return {
|
|
59
|
+
...driver,
|
|
60
|
+
ops: Object.fromEntries(Object.entries(driver.ops).map(([op, run]) => [
|
|
61
|
+
op,
|
|
62
|
+
(input, call) => run(input, { ...call, connection: undefined, authentication: undefined }),
|
|
63
|
+
])),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
51
66
|
}, { fixtures, ...options });
|
|
52
67
|
state = fake.state;
|
|
53
68
|
return fake;
|
package/dist/fake.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../src/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwC,MAAM,
|
|
1
|
+
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../src/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwC,MAAM,6BAA6B,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MA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IAAI,KAAyB,CAAC;IAC9B,MAAM,IAAI,GAAG,MAAM,CACjB;QACE,GAAG,UAAU;QACb,SAAS,EAAE,WAAW;QACtB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAU,EAAE;YAC1B,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAChF,4FAA4F;YAC5F,OAAO;gBACL,GAAG,MAAM;gBACT,GAAG,EAAE,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;oBAC5C,EAAE;oBACF,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;iBAC3F,CAAC,CACH;aACF,CAAC;QACJ,CAAC;KACF,EACD,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CACzB,CAAC;IACF,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACnB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supabase projects: `supabase.project.read` and `.import`, effect `read`, and the change
|
|
3
3
|
* operations apply calls (`plan`, `create`, `update`, `delete`), through the `supabase/supabase`
|
|
4
|
-
* OpenTofu provider; and from the Management API `supabase.
|
|
5
|
-
* `supabase.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* OpenTofu provider; and from the Management API `supabase.organization.list`,
|
|
5
|
+
* `supabase.project.health` and `supabase.pooler.get` (effect `read`) and
|
|
6
|
+
* `supabase.database.storeUrl` (effect `write`, to the secrets store). Calls run as a named
|
|
7
|
+
* connection, by OAuth consent (`oauth`) or a pasted personal access token (`accessToken`). It
|
|
8
|
+
* carries its live driver (`supabaseDriver`, on the default bridge) and its fake
|
|
9
|
+
* (`fakeSupabase`), of which each sandbox run makes its own.
|
|
8
10
|
*/
|
|
9
11
|
export declare const supabase: import("./connector.ts").SupabaseOps;
|
|
12
|
+
export { supabaseAccessToken, supabaseOAuth } from "./authentication.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { withSetup } from "
|
|
1
|
+
import { withSetup } from "sanoma/workflows";
|
|
2
|
+
import { supabaseAccessToken, supabaseOAuth } from "./authentication.js";
|
|
2
3
|
import { supabaseOps } from "./connector.js";
|
|
3
4
|
import { supabaseDriver } from "./driver.js";
|
|
4
5
|
import { fakeSupabase } from "./fake.js";
|
|
5
6
|
/**
|
|
6
7
|
* Supabase projects: `supabase.project.read` and `.import`, effect `read`, and the change
|
|
7
8
|
* operations apply calls (`plan`, `create`, `update`, `delete`), through the `supabase/supabase`
|
|
8
|
-
* OpenTofu provider; and from the Management API `supabase.
|
|
9
|
-
* `supabase.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* OpenTofu provider; and from the Management API `supabase.organization.list`,
|
|
10
|
+
* `supabase.project.health` and `supabase.pooler.get` (effect `read`) and
|
|
11
|
+
* `supabase.database.storeUrl` (effect `write`, to the secrets store). Calls run as a named
|
|
12
|
+
* connection, by OAuth consent (`oauth`) or a pasted personal access token (`accessToken`). It
|
|
13
|
+
* carries its live driver (`supabaseDriver`, on the default bridge) and its fake
|
|
14
|
+
* (`fakeSupabase`), of which each sandbox run makes its own.
|
|
12
15
|
*/
|
|
13
|
-
export const supabase = withSetup(supabaseOps, {
|
|
16
|
+
export const supabase = withSetup(supabaseOps, {
|
|
17
|
+
authentication: { oauth: supabaseOAuth, accessToken: supabaseAccessToken },
|
|
18
|
+
driver: supabaseDriver,
|
|
19
|
+
fake: fakeSupabase,
|
|
20
|
+
});
|
|
21
|
+
export { supabaseAccessToken, supabaseOAuth } from "./authentication.js";
|
|
14
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE;IAC7C,cAAc,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE;IAC1E,MAAM,EAAE,cAAc;IACtB,IAAI,EAAE,YAAY;CACnB,CAAC,CAAC;AAEH,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/management.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Driver, DriverError } from "
|
|
1
|
+
import { type CallContext, type Driver, DriverError } from "sanoma/workflows";
|
|
2
2
|
/** A project as `GET /v1/projects` lists it: the fields read here. */
|
|
3
3
|
export interface ApiProject {
|
|
4
4
|
id: string;
|
|
@@ -15,6 +15,11 @@ export interface ApiPooler {
|
|
|
15
15
|
db_user: string;
|
|
16
16
|
db_name: string;
|
|
17
17
|
}
|
|
18
|
+
/** An organization, as `GET /v1/organizations` lists it: the fields read here. */
|
|
19
|
+
export interface ApiOrganization {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
18
23
|
/** One service's health, as `GET /v1/projects/{ref}/health` lists them. */
|
|
19
24
|
export interface ApiHealth {
|
|
20
25
|
name: string;
|
|
@@ -23,15 +28,16 @@ export interface ApiHealth {
|
|
|
23
28
|
}
|
|
24
29
|
/** Supabase's Management API, its answers as it sends them. Each call fails with a `DriverError`. */
|
|
25
30
|
export interface ManagementApi {
|
|
31
|
+
organizations(): Promise<ApiOrganization[]>;
|
|
26
32
|
projects(): Promise<ApiProject[]>;
|
|
27
33
|
pooler(ref: string): Promise<ApiPooler[]>;
|
|
28
34
|
health(ref: string, services: readonly string[]): Promise<ApiHealth[]>;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
|
-
* `driver` (the provider's) with the Management API's operations over `api()`, made on each
|
|
32
|
-
*
|
|
33
|
-
* organization has a project of already.
|
|
37
|
+
* `driver` (the provider's) with the Management API's operations over `api(call)`, made on each
|
|
38
|
+
* call with that call's credentials: `organization.list`, `pooler.get`, `project.health`,
|
|
39
|
+
* `database.storeUrl`, and `project.create` refusing a name the organization has a project of already.
|
|
34
40
|
*/
|
|
35
|
-
export declare function withManagement(driver: Driver, api: () => ManagementApi): Driver;
|
|
41
|
+
export declare function withManagement(driver: Driver, api: (call: CallContext) => ManagementApi): Driver;
|
|
36
42
|
/** A `DriverError` for the Management API's answer `status` to `GET path`, retryable as the runtime's rule says. */
|
|
37
43
|
export declare function apiError(path: string, status: number, message: string, retryable: boolean): DriverError;
|
package/dist/management.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { DriverError, storeDatabaseUrl } from "
|
|
1
|
+
import { DriverError, storeDatabaseUrl } from "sanoma/workflows";
|
|
2
|
+
import { PASSWORD_SECRET } from "./connector.js";
|
|
2
3
|
/** The services `project.health` reads when none are named: what a worker needs. */
|
|
3
4
|
const HEALTH_SERVICES = ["db", "pooler"];
|
|
4
|
-
/** The secret the project's declared `database_password` names, which the URL is built with. */
|
|
5
|
-
const PASSWORD_SECRET = "SUPABASE_DB_PASSWORD";
|
|
6
5
|
/** A project's statuses while it is deleted, and after: not a twin of a new one. */
|
|
7
6
|
const GONE = new Set(["GOING_DOWN", "REMOVED"]);
|
|
8
7
|
/** The session pooler's port: the transaction pooler's (6543) does not carry LISTEN/NOTIFY, which DBOS needs. */
|
|
9
8
|
const SESSION_PORT = 5432;
|
|
10
9
|
/**
|
|
11
|
-
* `driver` (the provider's) with the Management API's operations over `api()`, made on each
|
|
12
|
-
*
|
|
13
|
-
* organization has a project of already.
|
|
10
|
+
* `driver` (the provider's) with the Management API's operations over `api(call)`, made on each
|
|
11
|
+
* call with that call's credentials: `organization.list`, `pooler.get`, `project.health`,
|
|
12
|
+
* `database.storeUrl`, and `project.create` refusing a name the organization has a project of already.
|
|
14
13
|
*/
|
|
15
14
|
export function withManagement(driver, api) {
|
|
16
15
|
const create = driver.ops["project.create"];
|
|
17
|
-
const pooler = async (ref) => {
|
|
18
|
-
const primary = (await api().pooler(ref)).find((p) => p.database_type === "PRIMARY");
|
|
16
|
+
const pooler = async (ref, call) => {
|
|
17
|
+
const primary = (await api(call).pooler(ref)).find((p) => p.database_type === "PRIMARY");
|
|
19
18
|
if (!primary)
|
|
20
19
|
throw new DriverError(`supabase: ${ref} has no primary database pooler`, { retryable: false });
|
|
21
20
|
return { host: primary.db_host, port: SESSION_PORT, user: primary.db_user, database: primary.db_name };
|
|
@@ -26,29 +25,33 @@ export function withManagement(driver, api) {
|
|
|
26
25
|
// it, finds it here and stops, rather than making a second one.
|
|
27
26
|
"project.create": async (input, call) => {
|
|
28
27
|
const { name, organization_id: org } = input.desired;
|
|
29
|
-
const twin = (await api().projects()).find((p) => p.name === name && (p.organization_id === org || p.organization_slug === org) && !GONE.has(p.status ?? ""));
|
|
28
|
+
const twin = (await api(call).projects()).find((p) => p.name === name && (p.organization_id === org || p.organization_slug === org) && !GONE.has(p.status ?? ""));
|
|
30
29
|
if (twin) {
|
|
31
30
|
throw new DriverError(`supabase: project.create: the organization ${org} has a project named ${name} already (${twin.ref ?? twin.id}); bind it instead`, { retryable: false, vendorCode: "exists" });
|
|
32
31
|
}
|
|
33
32
|
return create(input, call);
|
|
34
33
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
34
|
+
"organization.list": async (_input, call) => ({
|
|
35
|
+
organizations: (await api(call).organizations()).map(({ id, name }) => ({ id, name })),
|
|
36
|
+
}),
|
|
37
|
+
"project.health": async ({ ref, services = HEALTH_SERVICES }, call) => {
|
|
38
|
+
const answers = (await api(call).health(ref, services)).map(({ name, healthy, status }) => ({
|
|
37
39
|
name,
|
|
38
40
|
healthy,
|
|
39
41
|
status,
|
|
40
42
|
}));
|
|
41
43
|
return { healthy: answers.length > 0 && answers.every((s) => s.healthy), services: answers };
|
|
42
44
|
},
|
|
43
|
-
"pooler.get": ({ ref }) => pooler(ref),
|
|
44
|
-
"database.storeUrl": async ({ ref, export: name },
|
|
45
|
+
"pooler.get": ({ ref }, call) => pooler(ref, call),
|
|
46
|
+
"database.storeUrl": async ({ ref, export: name }, call) => {
|
|
47
|
+
const { secrets } = call;
|
|
45
48
|
const password = await secrets.get(PASSWORD_SECRET);
|
|
46
49
|
if (password === undefined) {
|
|
47
50
|
throw new DriverError(`supabase: database.storeUrl: the secret ${PASSWORD_SECRET} is not set`, {
|
|
48
51
|
retryable: false,
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
|
-
const { host, port, user, database } = await pooler(ref);
|
|
54
|
+
const { host, port, user, database } = await pooler(ref, call);
|
|
52
55
|
const url = `postgresql://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}/${encodeURIComponent(database)}?sslmode=require`;
|
|
53
56
|
return storeDatabaseUrl(secrets, name, url, {
|
|
54
57
|
where: "supabase: database.storeUrl",
|
package/dist/management.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.js","sourceRoot":"","sources":["../src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AAO,EAAE,IAAI,EAAE,GAAG,EAAE;gBAC1C,KAAK,EAAE,6BAA6B;gBACpC,MAAM,EAAE,qCAAqC;aAC9C,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAc,EAAE,OAAe,EAAE,SAAkB;IACxF,OAAO,IAAI,WAAW,CAAC,iBAAiB,IAAI,aAAa,MAAM,KAAK,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;AACxG,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Which of the Supabase provider's resource types `pnpm generate` writes into `resources.gen.ts`,
|
|
3
3
|
* and what its schema does not say. Hand-owned. The release and its sha256 are the pin in
|
|
4
|
-
*
|
|
4
|
+
* `sanoma/internal/bridge`'s `testdata/pins.json`.
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
provider: string;
|
package/dist/resources.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Which of the Supabase provider's resource types `pnpm generate` writes into `resources.gen.ts`,
|
|
3
3
|
* and what its schema does not say. Hand-owned. The release and its sha256 are the pin in
|
|
4
|
-
*
|
|
4
|
+
* `sanoma/internal/bridge`'s `testdata/pins.json`.
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
provider: "supabase/supabase",
|
package/dist/resources.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The constructors a data file declares Supabase projects with, without the ref Supabase sets:
|
|
3
3
|
* `export const store = supabase.project({ name: "acme-ops", organization_id: "acme", region: "us-east-1" })`.
|
|
4
4
|
*/
|
|
5
|
-
export declare const supabase: import("
|
|
5
|
+
export declare const supabase: import("sanoma/internal/bridge/connector").TfResources<"supabase", {
|
|
6
6
|
readonly project: import("zod").ZodObject<{
|
|
7
7
|
database_password: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
8
8
|
id: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
package/dist/resources.gen.d.ts
CHANGED
package/dist/vault.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SecretStore } from "
|
|
1
|
+
import { type SecretStore } from "sanoma/workflows";
|
|
2
2
|
export interface SupabaseVaultOptions {
|
|
3
3
|
/** Bootstrap environment variable containing the scoped login's Postgres URL. Never a service-role API key. */
|
|
4
4
|
databaseUrlEnv?: string;
|
package/dist/vault.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SecretStoreError } from "
|
|
2
|
-
import { databaseOn, pgCode } from "
|
|
1
|
+
import { SecretStoreError } from "sanoma/workflows";
|
|
2
|
+
import { databaseOn, pgCode } from "sanoma/workflows/db";
|
|
3
3
|
import { sql } from "drizzle-orm";
|
|
4
4
|
import { Pool } from "pg";
|
|
5
5
|
const decoded = (result) => {
|
package/dist/vault.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA0D,MAAM,
|
|
1
|
+
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA0D,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAW,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAS1B,MAAM,OAAO,GAAG,CAA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AAC,MAAM,CAAC,CAAC;QACvD,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE;YAC7D,OAAO,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,MAAM,IAAI,gBAAgB,CAAC,eAAe,CAAC,CAAC;YACtE,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM;gBAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;YACvF,OAAO,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE;YACvD,OAAO,EAAE,CAAC;YACV,MAAM,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,KAAK,CAAC,KAAK;YACT,MAAM,OAAO,GAAG,EAAE,CAAC;YACnB,EAAE,GAAG,SAAS,CAAC;YACf,MAAM,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanoma-ai/connector-supabase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.22",
|
|
4
4
|
"description": "Supabase projects for Sanoma, through the OpenTofu provider and the Management API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"connector",
|
|
@@ -62,15 +62,13 @@
|
|
|
62
62
|
"pg": "^8.23.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@sanoma-ai/bridge": "0.5.6",
|
|
66
|
-
"@sanoma-ai/workflows": "0.11.13",
|
|
67
65
|
"@types/pg": "^8.23.1",
|
|
68
66
|
"msw": "^3.0.3",
|
|
67
|
+
"sanoma": "0.11.22",
|
|
69
68
|
"zod": "^4.6.5"
|
|
70
69
|
},
|
|
71
70
|
"peerDependencies": {
|
|
72
|
-
"
|
|
73
|
-
"@sanoma-ai/workflows": "^0.11.13",
|
|
71
|
+
"sanoma": "0.11.22",
|
|
74
72
|
"zod": "^4"
|
|
75
73
|
},
|
|
76
74
|
"engines": {
|
|
@@ -83,7 +81,7 @@
|
|
|
83
81
|
"scripts": {
|
|
84
82
|
"build": "tsc -p tsconfig.build.json",
|
|
85
83
|
"clean": "rm -rf dist",
|
|
86
|
-
"generate": "node ../../packages/
|
|
84
|
+
"generate": "node --conditions=sanoma-source ../../packages/sanoma/src/cli.ts tfschema src/resources.config.ts src/resources.gen.ts && oxfmt src/resources.gen.ts",
|
|
87
85
|
"watch": "tsc -p tsconfig.build.json --watch --preserveWatchOutput"
|
|
88
86
|
}
|
|
89
87
|
}
|