@sanoma-ai/connector-supabase 0.0.0-stage → 0.4.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.
Files changed (34) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +115 -2
  3. package/dist/connector.d.ts +96 -0
  4. package/dist/connector.js +102 -0
  5. package/dist/connector.js.map +1 -0
  6. package/dist/driver.d.ts +24 -0
  7. package/dist/driver.js +67 -0
  8. package/dist/driver.js.map +1 -0
  9. package/dist/fake.d.ts +30 -0
  10. package/dist/fake.js +55 -0
  11. package/dist/fake.js.map +1 -0
  12. package/dist/index.d.ts +9 -0
  13. package/dist/index.js +14 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/management.d.ts +37 -0
  16. package/dist/management.js +69 -0
  17. package/dist/management.js.map +1 -0
  18. package/dist/resources.config.d.ts +13 -0
  19. package/dist/resources.config.js +15 -0
  20. package/dist/resources.config.js.map +1 -0
  21. package/dist/resources.d.ts +19 -0
  22. package/dist/resources.gen.d.ts +42 -0
  23. package/dist/resources.gen.js +69 -0
  24. package/dist/resources.gen.js.map +1 -0
  25. package/dist/resources.js +7 -0
  26. package/dist/resources.js.map +1 -0
  27. package/package.json +70 -3
  28. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanoma-apply-test/apply.json +30 -0
  29. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanoma-apply-test/plan.json +31 -0
  30. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanoma-apply-test-delete/apply.json +23 -0
  31. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanoma-apply-test-delete/plan.json +25 -0
  32. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanomamissingproject/import.json +27 -0
  33. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanomatestprojectref/import.json +27 -0
  34. package/testdata/replies/supabase_supabase_1.11.0/supabase_project/sanomatestprojectref/read.json +25 -0
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Sanoma-AI
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,116 @@
1
- # Temporary Holding Version
1
+ # @sanoma-ai/connector-supabase
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Supabase projects for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows), 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
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ npm install @sanoma-ai/connector-supabase
9
+ ```
10
+
11
+ The one resource type is writable: `read` and `import` (effect `read`), and the change operations only the apply workflow may call, `plan` (effect `read`), `create`, `update` and `delete` (effect `write`), with the project's ref as the policy's `target` (`new:supabase.project` for a create):
12
+
13
+ | Type | Operations | Import id |
14
+ | --------- | ---------------------------------------------------------------------------- | ----------------------- |
15
+ | `project` | `supabase.project.read`, `.import`, `.plan`, `.create`, `.update`, `.delete` | `id`, the project's ref |
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).
18
+
19
+ Three more operations call the Management API, each with the project's ref as `target`:
20
+
21
+ | Operation | Effect | Input | Output |
22
+ | ---------------------------- | ------- | -------------------- | ---------------------------------------------------- |
23
+ | `supabase.pooler.get` | `read` | `{ ref }` | `{ host, port: 5432, user, database }` |
24
+ | `supabase.project.health` | `read` | `{ ref, services? }` | `{ healthy, services: [{ name, healthy, status }] }` |
25
+ | `supabase.database.storeUrl` | `write` | `{ ref, export }` | `{ secret }` |
26
+
27
+ `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
+ `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
+
31
+ 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
+ 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.
34
+
35
+ ```ts
36
+ import { supabase } from "@sanoma-ai/connector-supabase/resources";
37
+ import { secret } from "sanoma/resources";
38
+
39
+ export const store = supabase.project({
40
+ name: "acme-ops",
41
+ organization_id: "acme",
42
+ region: "us-east-1",
43
+ database_password: secret("SUPABASE_DB_PASSWORD", { generate: true }),
44
+ });
45
+ ```
46
+
47
+ The fields are the provider's attributes, by their names: `organization_id` is the organization's slug. `secret("SUPABASE_DB_PASSWORD", { generate: true })` has apply generate the password and store it before the create; it is the name `database.storeUrl` reads. Only declared fields are compared for drift. The provider reads `instance_size` back only for a project with a compute add-on (`null` otherwise) and never reads `timeouts`, so declare neither unless that holds. The project's host, pooler and health are not attributes of the provider's project, so they are not here.
48
+
49
+ The logo is Supabase's bolt from [Simple Icons](https://simpleicons.org/?q=supabase) (CC0), there only to identify the service an operation calls.
50
+
51
+ ## Resource types
52
+
53
+ `src/resources.gen.ts` is generated from the provider's schema by `pnpm generate`, which runs [`@sanoma-ai/bridge/tfschema`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/bridge/src/tfschema/AGENTS.md) with `src/resources.config.ts`: the provider (its release, sha256 and recorded schema are `@sanoma-ai/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-ai/bridge/connector`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/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.
54
+
55
+ 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.
56
+
57
+ ## Driver
58
+
59
+ `@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-ai/workflows`), so a config names the connector alone and workflows never import the driver (the lint refuses that):
60
+
61
+ ```ts
62
+ import { supabase } from "@sanoma-ai/connector-supabase";
63
+
64
+ export default defineConfig({ workflows, connectors: [supabase], policy });
65
+ ```
66
+
67
+ `./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.
68
+
69
+ Without `bridge`, it reads through the process's `defaultBridge()` from `@sanoma-ai/bridge`, started on the first call with the binary `startBridge` finds. It configures the provider on the first call with `{ access_token }`, and again when the token changes, when the provider has exited, or when the bridge has forgotten it.
70
+
71
+ 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`.
72
+
73
+ ### Environment
74
+
75
+ Read on every call, never when the config loads:
76
+
77
+ | Variable | What it is |
78
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `SUPABASE_ACCESS_TOKEN` | A Supabase personal access token ([account tokens](https://supabase.com/dashboard/account/tokens)), for the provider and the Management API |
80
+
81
+ When the token is unset, a call fails, not retryable, naming it; the worker starts regardless, and the app's connector page shows and sets it. The bridge passes the token to the provider through its config only. The default bridge's binary comes with `@sanoma-ai/bridge` or from `SANOMA_BRIDGE_BIN` (see [the bridge](https://www.npmjs.com/package/@sanoma-ai/bridge#the-binary)), not a credential of the connector; it must trust Supabase's signing key, since the OpenTofu registry serves none for this provider.
82
+
83
+ ### Errors and retries
84
+
85
+ As for GitHub: the bridge's errors become `DriverError`s with its code as `vendorCode` and the provider's diagnostics in the message, retryable only on `unavailable`, after which the provider is configured again. A Supabase error other than a missing project (a bad token) comes back from the provider as a failed import (`failed_precondition`) with the status and Supabase's message. A Management API error is a `DriverError` with the HTTP `status` and Supabase's message, retryable on a timeout, a rate limit (429) or a server error.
86
+
87
+ ## Testing
88
+
89
+ `@sanoma-ai/connector-supabase/fake` serves the replies in `testdata/replies` (a project `sanomatestprojectref`, and the provider's answer for a missing one, `sanomamissingproject`) through the real driver over a `stateBridge` of them (`tfFake`), which creates, changes and deletes projects in memory. Its Management API answers from the same projects: each healthy, its pooler `aws-0-<region>.pooler.supabase.com`. Those replies are written by hand to the provider's schema and source, not recorded: no access token was at hand.
90
+
91
+ ```ts
92
+ import { fakeSupabase } from "@sanoma-ai/connector-supabase/fake";
93
+
94
+ const fake = fakeSupabase();
95
+ fake.override("project", "sanomatestprojectref", { name: "renamed" }); // drift: the next read returns it
96
+ ```
97
+
98
+ It has `put`, `remove` and the faults every fake has, like `fakeGithub`. Import it from `@sanoma-ai/connector-supabase/fake`.
99
+
100
+ ### Recording
101
+
102
+ The driver's tests replay hand-written fixtures in the recorders' formats until they are recorded. With a token and a throwaway organization (the free plan allows two active projects), record a project's create and delete from a provider-bridge checkout. The repo's own recorder refuses a plan whose config holds a sensitive value, so it is provider-bridge's `bridge-record`, which scrubs the password, also in the msgpack plan:
103
+
104
+ ```sh
105
+ SUPABASE_DB_PASSWORD="$(openssl rand -base64 24)" go run ./cmd/bridge-record \
106
+ --provider supabase/supabase --version 1.11.0 --config-env access_token=SUPABASE_ACCESS_TOKEN \
107
+ --change "supabase_project=sanoma-apply-test={\"name\":\"sanoma-apply-test\",\"organization_id\":\"$SUPABASE_TEST_ORG_ID\",\"region\":\"us-east-1\",\"database_password\":\"$SUPABASE_DB_PASSWORD\"}"
108
+ ```
109
+
110
+ It deletes the project at the end, also after a failed step. Copy `testdata/replies/supabase_supabase_1.11.0/supabase_project/sanoma-apply-test*` here, with the organization's slug replaced by `sanoma-test-org` and the project's ref by `sanomaapplytestrefab`. The Management API fixtures record against an existing project:
111
+
112
+ ```sh
113
+ SANOMA_LIVE=1 SANOMA_RECORD=1 SUPABASE_TEST_PROJECT_REF=<ref> pnpm vitest run connectors/supabase/test/management.test.ts
114
+ ```
115
+
116
+ License: FSL-1.1-ALv2.
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Supabase, through the `supabase/supabase` OpenTofu provider: the generated resource types, and
4
+ * who Supabase is. Supabase names its projects (a project's ref), so a declaration has no
5
+ * identity: its project is the one its binding names, by its ref. The provider answers a project
6
+ * that does not exist with the state it was given, so one without a name is gone. Apply creates,
7
+ * changes and deletes projects. The resource types, the data-file constructors and the
8
+ * provider's driver come from this one record; `supabaseOps` adds the Management API operations,
9
+ * two of which apply calls after it creates a project.
10
+ */
11
+ export declare const supabaseTf: import("@sanoma-ai/bridge/connector").TfConnector<"supabase", {
12
+ project: z.ZodObject<{
13
+ database_password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
15
+ instance_size: z.ZodOptional<z.ZodNullable<z.ZodString>>;
16
+ legacy_api_keys_enabled: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
17
+ name: z.ZodString;
18
+ organization_id: z.ZodString;
19
+ region: z.ZodString;
20
+ timeouts: z.ZodOptional<z.ZodNullable<z.ZodObject<{
21
+ create: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ update: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
+ }, z.core.$strip>>>;
24
+ }, z.core.$strip>;
25
+ }, {}>;
26
+ declare const target: ({ ref }: {
27
+ ref: string;
28
+ }) => string;
29
+ /**
30
+ * What the provider's project does not carry, from Supabase's Management API: the session
31
+ * pooler's address, the project's health, and the database URL a worker connects with, which
32
+ * only the secrets store ever holds.
33
+ */
34
+ declare const management: import("@sanoma-ai/workflows").Connector<"supabase", {
35
+ readonly pooler: {
36
+ readonly get: {
37
+ readonly effect: "read";
38
+ readonly idempotent: true;
39
+ readonly description: "Read the address of a project's session pooler (port 5432), which keeps LISTEN, unlike port 6543";
40
+ readonly input: z.ZodObject<{
41
+ ref: z.ZodString;
42
+ }, z.core.$strip>;
43
+ readonly output: z.ZodObject<{
44
+ host: z.ZodString;
45
+ port: z.ZodLiteral<5432>;
46
+ user: z.ZodString;
47
+ database: z.ZodString;
48
+ }, z.core.$strip>;
49
+ readonly target: typeof target;
50
+ };
51
+ };
52
+ readonly project: {
53
+ readonly health: {
54
+ readonly effect: "read";
55
+ readonly idempotent: true;
56
+ readonly description: "Read whether a project's services are healthy: its database and pooler unless others are named";
57
+ readonly input: z.ZodObject<{
58
+ ref: z.ZodString;
59
+ services: z.ZodOptional<z.ZodArray<z.ZodString>>;
60
+ }, z.core.$strip>;
61
+ readonly output: z.ZodObject<{
62
+ healthy: z.ZodBoolean;
63
+ services: z.ZodArray<z.ZodObject<{
64
+ name: z.ZodString;
65
+ healthy: z.ZodBoolean;
66
+ status: z.ZodString;
67
+ }, z.core.$strip>>;
68
+ }, z.core.$strip>;
69
+ readonly target: typeof target;
70
+ };
71
+ };
72
+ readonly database: {
73
+ readonly storeUrl: {
74
+ readonly effect: "write";
75
+ readonly idempotent: true;
76
+ 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";
77
+ readonly input: z.ZodObject<{
78
+ ref: z.ZodString;
79
+ export: z.ZodString;
80
+ }, z.core.$strip>;
81
+ readonly output: z.ZodObject<{
82
+ secret: z.ZodString;
83
+ }, z.core.$strip>;
84
+ readonly target: typeof target;
85
+ };
86
+ };
87
+ }>;
88
+ /**
89
+ * The Supabase connector's operations: the project type's (`read`, `import`, `plan`, `create`,
90
+ * `update`, `delete`) and the Management API's (`project.health`, `pooler.get`,
91
+ * `database.storeUrl`).
92
+ */
93
+ export declare const supabaseOps: SupabaseOps;
94
+ /** The Supabase connector's type: the provider's resource types with the Management API operations. */
95
+ export type SupabaseOps = typeof supabaseTf.connector & typeof management;
96
+ export {};
@@ -0,0 +1,102 @@
1
+ import { tfConnector } from "@sanoma-ai/bridge/connector";
2
+ import { defineConnector } from "@sanoma-ai/workflows";
3
+ import { z } from "zod";
4
+ import { provider, supabase_project } from "./resources.gen.js";
5
+ /**
6
+ * Supabase's bolt, from simple-icons (https://simpleicons.org/?q=supabase, CC0), in Supabase's
7
+ * green, which reads on light and dark backgrounds alike.
8
+ */
9
+ const bolt = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#3FCF8E" d="M11.9 1.036c-.015-.986-1.26-1.41-1.874-.637L.764 12.05C-.33 13.427.65 15.455 2.409 15.455h9.579l.113 7.51c.014.985 1.259 1.408 1.873.636l9.262-11.653c1.093-1.375.113-3.403-1.645-3.403h-9.642z"/></svg>`;
10
+ /**
11
+ * Supabase, through the `supabase/supabase` OpenTofu provider: the generated resource types, and
12
+ * who Supabase is. Supabase names its projects (a project's ref), so a declaration has no
13
+ * identity: its project is the one its binding names, by its ref. The provider answers a project
14
+ * that does not exist with the state it was given, so one without a name is gone. Apply creates,
15
+ * changes and deletes projects. The resource types, the data-file constructors and the
16
+ * provider's driver come from this one record; `supabaseOps` adds the Management API operations,
17
+ * two of which apply calls after it creates a project.
18
+ */
19
+ export const supabaseTf = tfConnector({
20
+ vendor: "supabase",
21
+ provider,
22
+ types: {
23
+ project: {
24
+ tf: supabase_project,
25
+ title: "Project",
26
+ exists: (state) => state.name != null,
27
+ writable: true,
28
+ // Once apply makes a project: its database and pooler healthy, then the URL a worker
29
+ // connects with stored as SANOMA_DATABASE_URL_<EXPORT>, which a host's secrets name.
30
+ afterCreate: [
31
+ { op: "supabase.project.health", input: ({ id }) => ({ ref: id }), until: (out) => out?.healthy === true },
32
+ { op: "supabase.database.storeUrl", input: ({ id, export: name }) => ({ ref: id, export: name }) },
33
+ ],
34
+ },
35
+ },
36
+ info: {
37
+ title: "Supabase",
38
+ logo: { svg: bolt },
39
+ package: "@sanoma-ai/connector-supabase",
40
+ homepage: "https://github.com/Sanoma-AI/sanoma/tree/main/connectors/supabase#readme",
41
+ },
42
+ });
43
+ const projectRef = z.string().min(1).describe("The project's ref");
44
+ const target = ({ ref }) => ref;
45
+ /**
46
+ * What the provider's project does not carry, from Supabase's Management API: the session
47
+ * pooler's address, the project's health, and the database URL a worker connects with, which
48
+ * only the secrets store ever holds.
49
+ */
50
+ const management = defineConnector("supabase", {
51
+ pooler: {
52
+ get: {
53
+ effect: "read",
54
+ idempotent: true,
55
+ description: "Read the address of a project's session pooler (port 5432), which keeps LISTEN, unlike port 6543",
56
+ input: z.object({ ref: projectRef }),
57
+ output: z.object({ host: z.string(), port: z.literal(5432), user: z.string(), database: z.string() }),
58
+ target,
59
+ },
60
+ },
61
+ project: {
62
+ health: {
63
+ effect: "read",
64
+ idempotent: true,
65
+ description: "Read whether a project's services are healthy: its database and pooler unless others are named",
66
+ input: z.object({ ref: projectRef, services: z.array(z.string().min(1)).min(1).optional() }),
67
+ output: z.object({
68
+ healthy: z.boolean(),
69
+ services: z.array(z.object({ name: z.string(), healthy: z.boolean(), status: z.string() })),
70
+ }),
71
+ target,
72
+ },
73
+ },
74
+ database: {
75
+ storeUrl: {
76
+ effect: "write",
77
+ idempotent: true,
78
+ 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",
79
+ input: z.object({
80
+ ref: projectRef,
81
+ export: z
82
+ .string()
83
+ .regex(/^[A-Za-z_][A-Za-z0-9_]*$/)
84
+ .describe("The data file's export that declares the project, such as `store`"),
85
+ }),
86
+ output: z.object({ secret: z.string().describe("The secret's name, SANOMA_DATABASE_URL_<EXPORT>") }),
87
+ target,
88
+ },
89
+ },
90
+ });
91
+ /**
92
+ * The Supabase connector's operations: the project type's (`read`, `import`, `plan`, `create`,
93
+ * `update`, `delete`) and the Management API's (`project.health`, `pooler.get`,
94
+ * `database.storeUrl`).
95
+ */
96
+ export const supabaseOps = {
97
+ ...supabaseTf.connector,
98
+ project: { ...supabaseTf.connector.project, ...management.project },
99
+ pooler: management.pooler,
100
+ database: management.database,
101
+ };
102
+ //# sourceMappingURL=connector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;GAGG;AACH,MAAM,IAAI,GAAG,8RAA8R,CAAC;AAE5S;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC;IACpC,MAAM,EAAE,UAAU;IAClB,QAAQ;IACR,KAAK,EAAE;QACL,OAAO,EAA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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,MAAM,EAAE,UAAU,CAAC,MAAM;IACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ;CACf,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type ProviderClient } from "@sanoma-ai/bridge";
2
+ import { z } from "zod";
3
+ export interface SupabaseDriverOptions {
4
+ /**
5
+ * The provider bridge to read through. Default: the process's `defaultBridge()`, started on the
6
+ * first call (`startBridge`'s binary). One per tenant: it holds the token once configured.
7
+ */
8
+ bridge?: ProviderClient;
9
+ /** How long a Management API request may take, in milliseconds. Default 30 seconds. */
10
+ timeoutMs?: number;
11
+ }
12
+ /**
13
+ * 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 Management API,
15
+ * with the access token in `SUPABASE_ACCESS_TOKEN`, read on every call. The provider is
16
+ * configured on the first call, and again when the token changes or the provider has exited.
17
+ */
18
+ export declare function supabaseDriver({ bridge, timeoutMs }?: SupabaseDriverOptions): Readonly<{
19
+ vendor: string;
20
+ ops: Readonly<Record<string, import("@sanoma-ai/workflows").DriverFn>>;
21
+ env: z.ZodObject<{
22
+ SUPABASE_ACCESS_TOKEN: z.ZodString;
23
+ }, z.core.$strip>;
24
+ }>;
package/dist/driver.js ADDED
@@ -0,0 +1,67 @@
1
+ import { defaultBridge } from "@sanoma-ai/bridge";
2
+ import { DriverError, retryableStatus } from "@sanoma-ai/workflows";
3
+ import { z } from "zod";
4
+ import { supabaseTf } from "./connector.js";
5
+ import { apiError, withManagement } from "./management.js";
6
+ /** The environment variables the driver reads, on every call. */
7
+ const env = z.object({
8
+ SUPABASE_ACCESS_TOKEN: z
9
+ .string()
10
+ .min(1)
11
+ .describe("a personal access token that can read, create and delete the projects the data files declare"),
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
+ };
20
+ const project = (ref) => `/v1/projects/${encodeURIComponent(ref)}`;
21
+ /** The Management API with `token`: each request a GET, its failures `DriverError`s, retryable as the runtime's rule says. */
22
+ function managementApi(token, timeoutMs) {
23
+ const get = async (path) => {
24
+ let res;
25
+ try {
26
+ res = await fetch(`${API}${path}`, {
27
+ headers: { authorization: `Bearer ${token}`, accept: "application/json" },
28
+ signal: AbortSignal.timeout(timeoutMs),
29
+ });
30
+ }
31
+ catch (e) {
32
+ throw new DriverError(`supabase: GET ${path} failed: ${e.message}`, { retryable: true, cause: e });
33
+ }
34
+ if (!res.ok) {
35
+ const text = await res.text().catch(() => "");
36
+ let message = text.slice(0, 200);
37
+ try {
38
+ message = String(JSON.parse(text).message ?? message);
39
+ }
40
+ catch { }
41
+ throw apiError(path, res.status, message || res.statusText, retryableStatus(res.status));
42
+ }
43
+ try {
44
+ return (await res.json());
45
+ }
46
+ catch (e) {
47
+ throw new DriverError(`supabase: GET ${path} answered ${res.status} without JSON`, { retryable: true, cause: e });
48
+ }
49
+ };
50
+ return {
51
+ projects: () => get("/v1/projects"),
52
+ pooler: (ref) => get(`${project(ref)}/config/database/pooler`),
53
+ health: (ref, services) => get(`${project(ref)}/health?services=${services.map(encodeURIComponent).join(",")}`),
54
+ };
55
+ }
56
+ /**
57
+ * 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 Management API,
59
+ * with the access token in `SUPABASE_ACCESS_TOKEN`, read on every call. The provider is
60
+ * configured on the first call, and again when the token changes or the provider has exited.
61
+ */
62
+ export function supabaseDriver({ bridge = defaultBridge(), timeoutMs = 30_000 } = {}) {
63
+ const provider = supabaseTf.driver(bridge, () => ({ access_token: accessToken(), endpoint: null }));
64
+ const driver = withManagement(provider, () => managementApi(accessToken(), timeoutMs));
65
+ return Object.freeze({ ...driver, env });
66
+ }
67
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAY/E,iEAAiE;AACjE,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,qBAAqB,EAAE,CAAC;SACrB,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,8FAA8F,CAAC;CAC5G,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,0BAA0B,CAAC;AAEvC,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,WAAW,CAAC,4CAA4C,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACtG,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,gBAAgB,kBAAkB,CAAC,GAAG,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fFakeState;
3
+ export type FakeSupabaseOptions = TfFakeOptions;
4
+ /**
5
+ * A Supabase that answers through the real driver over a bridge of the replies in `testdata/`, a
6
+ * project (`sanomatestprojectref`), and the answer for one that does not exist
7
+ * (`sanomamissingproject`). Those replies are written by hand to the provider's schema, not
8
+ * recorded: no access token was at hand. Its bridge creates, changes and deletes projects in
9
+ * memory (`stateBridge`); the Management API operations answer from the same projects, each
10
+ * healthy, its session pooler `aws-0-<region>.pooler.supabase.com`. Nothing reaches Supabase,
11
+ * and no token is read.
12
+ *
13
+ * `put` makes a project, `override` changes what the next read returns, as if someone edited
14
+ * the project in Supabase's dashboard, and `remove` deletes it, so the next read says it is gone.
15
+ */
16
+ export declare function fakeSupabase(options?: FakeSupabaseOptions): import("@sanoma-ai/bridge/fake").TfFake<"supabase", {
17
+ project: import("zod").ZodObject<{
18
+ database_password: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
19
+ id: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
20
+ instance_size: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
21
+ legacy_api_keys_enabled: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodBoolean>>;
22
+ name: import("zod").ZodString;
23
+ organization_id: import("zod").ZodString;
24
+ region: import("zod").ZodString;
25
+ timeouts: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodObject<{
26
+ create: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
27
+ update: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
28
+ }, import("zod/v4/core").$strip>>>;
29
+ }, import("zod/v4/core").$strip>;
30
+ }>;
package/dist/fake.js ADDED
@@ -0,0 +1,55 @@
1
+ import { tfFake } from "@sanoma-ai/bridge/fake";
2
+ import { supabaseOps, supabaseTf } from "./connector.js";
3
+ import { apiError, withManagement } from "./management.js";
4
+ /** The replies the fake serves, written by hand to the provider's schema: there is no Supabase recording yet. */
5
+ const fixtures = new URL("../testdata/", import.meta.url);
6
+ /** The Management API as the fake's projects answer it: every project healthy, its pooler in its region. */
7
+ function fakeApi(state) {
8
+ const projects = () => Object.values(state.objects).flatMap((o) => "error" in o || o.typeName !== "supabase_project" || o.state.name == null ? [] : [o.state]);
9
+ const project = (ref, path) => {
10
+ const found = projects().find((p) => p.id === ref);
11
+ if (!found)
12
+ throw apiError(`/v1/projects/${ref}${path}`, 404, "Project not found", false);
13
+ return found;
14
+ };
15
+ return {
16
+ projects: async () => projects().map((p) => ({ id: String(p.id), name: String(p.name), organization_id: String(p.organization_id) })),
17
+ pooler: async (ref) => {
18
+ const { region } = project(ref, "/config/database/pooler");
19
+ const at = {
20
+ db_host: `aws-0-${String(region)}.pooler.supabase.com`,
21
+ db_user: `postgres.${ref}`,
22
+ db_name: "postgres",
23
+ };
24
+ return [{ database_type: "PRIMARY", ...at }];
25
+ },
26
+ health: async (ref, services) => {
27
+ project(ref, "/health");
28
+ return services.map((name) => ({ name, healthy: true, status: "ACTIVE_HEALTHY" }));
29
+ },
30
+ };
31
+ }
32
+ /**
33
+ * A Supabase that answers through the real driver over a bridge of the replies in `testdata/`, a
34
+ * project (`sanomatestprojectref`), and the answer for one that does not exist
35
+ * (`sanomamissingproject`). Those replies are written by hand to the provider's schema, not
36
+ * recorded: no access token was at hand. Its bridge creates, changes and deletes projects in
37
+ * memory (`stateBridge`); the Management API operations answer from the same projects, each
38
+ * healthy, its session pooler `aws-0-<region>.pooler.supabase.com`. Nothing reaches Supabase,
39
+ * and no token is read.
40
+ *
41
+ * `put` makes a project, `override` changes what the next read returns, as if someone edited
42
+ * the project in Supabase's dashboard, and `remove` deletes it, so the next read says it is gone.
43
+ */
44
+ export function fakeSupabase(options = {}) {
45
+ // The fake's state, kept in place across `reset`: its bridge's projects.
46
+ let state;
47
+ const fake = tfFake({
48
+ ...supabaseTf,
49
+ connector: supabaseOps,
50
+ driver: (...args) => withManagement(supabaseTf.driver(...args), () => fakeApi(state)),
51
+ }, { fixtures, ...options });
52
+ state = fake.state;
53
+ return fake;
54
+ }
55
+ //# sourceMappingURL=fake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.js","sourceRoot":"","sources":["../src/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwC,MAAM,wBAAwB,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/E,iHAAiH;AACjH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAK1D,4GAA4G;AAC5G,SAAS,OAAO,CAAC,KAAwB;IACvC,MAAM,QAAQ,GAAG,GAAG,EAAE,CACpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CACzC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,kBAAkB,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAC3F,CAAC;IACJ,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK;YAAE,MAAM,QAAQ,CAAC,gBAAgB,GAAG,GAAG,IAAI,EAAE,EAAE,GAAG,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC1F,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,KAAK,IAAI,EAAE,CAC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AE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAC9F,EACD,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CACzB,CAAC;IACF,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACnB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Supabase projects: `supabase.project.read` and `.import`, effect `read`, and the change
3
+ * operations apply calls (`plan`, `create`, `update`, `delete`), through the `supabase/supabase`
4
+ * OpenTofu provider; and from the Management API `supabase.project.health` and
5
+ * `supabase.pooler.get` (effect `read`) and `supabase.database.storeUrl` (effect `write`, to the
6
+ * secrets store). It carries its live driver (`supabaseDriver`, on the default bridge) and its
7
+ * fake (`fakeSupabase`), of which each sandbox run makes its own.
8
+ */
9
+ export declare const supabase: import("./connector.ts").SupabaseOps;