@pgpm/supabase 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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/Makefile +7 -0
  3. package/README.md +37 -0
  4. package/__tests__/_realtime/_realtime-extensions.test.ts +129 -0
  5. package/__tests__/_realtime/_realtime-schema-migrations.test.ts +160 -0
  6. package/__tests__/_realtime/_realtime-tenants.test.ts +163 -0
  7. package/__tests__/auth/auth.audit-log-entries.test.ts +148 -0
  8. package/__tests__/auth/auth.flow-state.test.ts +114 -0
  9. package/__tests__/auth/auth.identities.test.ts +149 -0
  10. package/__tests__/auth/auth.instances.test.ts +134 -0
  11. package/__tests__/auth/auth.mfa-amr-claims.test.ts +142 -0
  12. package/__tests__/auth/auth.mfa-challenges.test.ts +117 -0
  13. package/__tests__/auth/auth.mfa-factors.test.ts +118 -0
  14. package/__tests__/auth/auth.oauth-authorizations.test.ts +123 -0
  15. package/__tests__/auth/auth.oauth-clients.test.ts +120 -0
  16. package/__tests__/auth/auth.oauth-consents.test.ts +122 -0
  17. package/__tests__/auth/auth.one-time-tokens.test.ts +194 -0
  18. package/__tests__/auth/auth.refresh-tokens.test.ts +134 -0
  19. package/__tests__/auth/auth.saml-providers.test.ts +154 -0
  20. package/__tests__/auth/auth.saml-relay-states.test.ts +145 -0
  21. package/__tests__/auth/auth.schema-migrations.test.ts +131 -0
  22. package/__tests__/auth/auth.sessions.test.ts +140 -0
  23. package/__tests__/auth/auth.sso-domains.test.ts +137 -0
  24. package/__tests__/auth/auth.sso-providers.test.ts +136 -0
  25. package/__tests__/auth/auth.users.test.ts +314 -0
  26. package/__tests__/conditional.test.ts +229 -0
  27. package/__tests__/functions.test.ts +252 -0
  28. package/__tests__/jsonb.test.ts +237 -0
  29. package/__tests__/net/net.http-request-queue.test.ts +159 -0
  30. package/__tests__/net/net.http-response.test.ts +163 -0
  31. package/__tests__/realtime/realtime.messages-2025-10-31.test.ts +168 -0
  32. package/__tests__/realtime/realtime.messages.test.ts +162 -0
  33. package/__tests__/realtime/realtime.schema-migrations.test.ts +139 -0
  34. package/__tests__/realtime/realtime.subscription.test.ts +159 -0
  35. package/__tests__/storage/storage.buckets-analytics.test.ts +134 -0
  36. package/__tests__/storage/storage.buckets.test.ts +146 -0
  37. package/__tests__/storage/storage.iceberg-namespaces.test.ts +132 -0
  38. package/__tests__/storage/storage.iceberg-tables.test.ts +142 -0
  39. package/__tests__/storage/storage.migrations.test.ts +133 -0
  40. package/__tests__/storage/storage.objects.test.ts +160 -0
  41. package/__tests__/storage/storage.prefixes.test.ts +138 -0
  42. package/__tests__/storage/storage.s3-multipart-uploads-parts.test.ts +133 -0
  43. package/__tests__/storage/storage.s3-multipart-uploads.test.ts +128 -0
  44. package/__tests__/supabase-functions/supabase.functions-hooks.test.ts +125 -0
  45. package/__tests__/supabase-functions/supabase.functions-migrations.test.ts +213 -0
  46. package/__tests__/temporal.test.ts +225 -0
  47. package/__tests__/vault-secrets.test.ts +145 -0
  48. package/deploy/LICENSE +9 -0
  49. package/deploy/supabase.sql +2271 -0
  50. package/jest.config.js +15 -0
  51. package/launchql.plan +4 -0
  52. package/package.json +23 -0
  53. package/revert/supabase.sql +3 -0
  54. package/sql/supabase--0.0.1.sql +1368 -0
  55. package/src/index.ts +3 -0
  56. package/supabase.control +7 -0
  57. package/verify/supabase.sql +3 -0
@@ -0,0 +1,213 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ beforeAll(async () => {
8
+ ({ pg, db, teardown } = await getConnections());
9
+
10
+ // grant access to supabase_functions schema for testing
11
+ await pg.any(
12
+ `GRANT USAGE ON SCHEMA supabase_functions TO public;
13
+ GRANT SELECT ON ALL TABLES IN SCHEMA supabase_functions TO service_role;
14
+ GRANT SELECT ON ALL TABLES IN SCHEMA supabase_functions TO authenticated;
15
+ GRANT SELECT ON ALL TABLES IN SCHEMA supabase_functions TO anon;
16
+ ALTER DEFAULT PRIVILEGES IN SCHEMA supabase_functions GRANT SELECT ON TABLES TO service_role;
17
+ ALTER DEFAULT PRIVILEGES IN SCHEMA supabase_functions GRANT SELECT ON TABLES TO authenticated;
18
+ ALTER DEFAULT PRIVILEGES IN SCHEMA supabase_functions GRANT SELECT ON TABLES TO anon;`,
19
+ []
20
+ );
21
+ });
22
+
23
+ afterAll(async () => {
24
+ await teardown();
25
+ });
26
+
27
+ beforeEach(async () => {
28
+ await db.beforeEach();
29
+ });
30
+
31
+ afterEach(async () => {
32
+ await db.afterEach();
33
+ });
34
+
35
+ describe('tutorial: supabase_functions migrations table access', () => {
36
+ it('should verify migrations table exists and has correct structure', async () => {
37
+ db.setContext({ role: 'service_role' });
38
+
39
+ // verify table exists in information schema
40
+ const tableExists = await db.any(
41
+ `SELECT EXISTS (
42
+ SELECT FROM information_schema.tables
43
+ WHERE table_schema = 'supabase_functions' AND table_name = 'migrations'
44
+ ) as exists`
45
+ );
46
+ expect(tableExists[0].exists).toBe(true);
47
+
48
+ // verify table has expected columns
49
+ const columns = await db.any(
50
+ `SELECT column_name, data_type, is_nullable
51
+ FROM information_schema.columns
52
+ WHERE table_schema = 'supabase_functions' AND table_name = 'migrations'
53
+ ORDER BY ordinal_position`
54
+ );
55
+
56
+ expect(Array.isArray(columns)).toBe(true);
57
+ expect(columns.length).toBeGreaterThan(0);
58
+
59
+ // verify key columns exist (actual schema has version and inserted_at)
60
+ const columnNames = columns.map((c: any) => c.column_name);
61
+ expect(columnNames).toContain('version');
62
+ expect(columnNames).toContain('inserted_at');
63
+ });
64
+
65
+ it('should verify service_role can read migrations table', async () => {
66
+ db.setContext({ role: 'service_role' });
67
+
68
+ // service_role should be able to query migrations
69
+ const migrations = await db.any(
70
+ `SELECT version, inserted_at
71
+ FROM supabase_functions.migrations
72
+ ORDER BY inserted_at DESC
73
+ LIMIT 10`
74
+ );
75
+
76
+ expect(Array.isArray(migrations)).toBe(true);
77
+
78
+ // verify result structure if any rows exist
79
+ if (migrations.length > 0) {
80
+ expect(migrations[0]).toHaveProperty('version');
81
+ expect(migrations[0]).toHaveProperty('inserted_at');
82
+ }
83
+ });
84
+
85
+ it('should verify table has primary key constraint', async () => {
86
+ db.setContext({ role: 'service_role' });
87
+
88
+ // verify primary key constraint exists
89
+ const primaryKeys = await db.any(
90
+ `SELECT constraint_name
91
+ FROM information_schema.table_constraints
92
+ WHERE table_schema = 'supabase_functions'
93
+ AND table_name = 'migrations'
94
+ AND constraint_type = 'PRIMARY KEY'`
95
+ );
96
+
97
+ expect(Array.isArray(primaryKeys)).toBe(true);
98
+ expect(primaryKeys.length).toBeGreaterThan(0);
99
+ expect(primaryKeys[0].constraint_name).toBeDefined();
100
+ });
101
+
102
+ it('should verify rls status on migrations table', async () => {
103
+ db.setContext({ role: 'service_role' });
104
+
105
+ // verify rls status (may or may not be enabled depending on setup)
106
+ const rlsStatus = await db.any(
107
+ `SELECT relname, relrowsecurity
108
+ FROM pg_class c
109
+ JOIN pg_namespace n ON n.oid = c.relnamespace
110
+ WHERE n.nspname = 'supabase_functions'
111
+ AND c.relname = 'migrations'`
112
+ );
113
+
114
+ expect(Array.isArray(rlsStatus)).toBe(true);
115
+ expect(rlsStatus.length).toBeGreaterThan(0);
116
+ expect(typeof rlsStatus[0].relrowsecurity).toBe('boolean');
117
+ });
118
+
119
+ it('should verify authenticated users access to migrations based on rls', async () => {
120
+ // create a test user as admin
121
+ // using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
122
+ // use pg for auth.users insert since it requires superuser privileges
123
+ const user = await pg.one(
124
+ `INSERT INTO auth.users (id, email)
125
+ VALUES (gen_random_uuid(), $1)
126
+ RETURNING id`,
127
+ ['functions-migrations-test@example.com']
128
+ );
129
+
130
+ // set context to simulate authenticated user
131
+ db.setContext({
132
+ role: 'authenticated',
133
+ 'request.jwt.claim.sub': user.id
134
+ });
135
+
136
+ // check rls status first
137
+ db.setContext({ role: 'service_role' });
138
+ const rlsStatus = await db.any(
139
+ `SELECT relrowsecurity
140
+ FROM pg_class c
141
+ JOIN pg_namespace n ON n.oid = c.relnamespace
142
+ WHERE n.nspname = 'supabase_functions'
143
+ AND c.relname = 'migrations'`
144
+ );
145
+
146
+ // test as authenticated user
147
+ db.setContext({
148
+ role: 'authenticated',
149
+ 'request.jwt.claim.sub': user.id
150
+ });
151
+ const result = await db.any(
152
+ `SELECT * FROM supabase_functions.migrations LIMIT 1`
153
+ );
154
+
155
+ // if rls is enabled, result should be empty; if not, may have rows
156
+ expect(Array.isArray(result)).toBe(true);
157
+ if (rlsStatus[0]?.relrowsecurity === true) {
158
+ expect(result.length).toBe(0);
159
+ } else {
160
+ // rls not enabled, access may be granted based on grants
161
+ expect(Array.isArray(result)).toBe(true);
162
+ }
163
+ });
164
+
165
+ it('should verify anon access to migrations based on rls', async () => {
166
+ // check rls status first
167
+ db.setContext({ role: 'service_role' });
168
+ const rlsStatus = await db.any(
169
+ `SELECT relrowsecurity
170
+ FROM pg_class c
171
+ JOIN pg_namespace n ON n.oid = c.relnamespace
172
+ WHERE n.nspname = 'supabase_functions'
173
+ AND c.relname = 'migrations'`
174
+ );
175
+
176
+ // clear context to anon role
177
+ db.clearContext();
178
+
179
+ // anon access depends on rls and grants
180
+ const result = await db.any(
181
+ `SELECT * FROM supabase_functions.migrations LIMIT 1`
182
+ );
183
+
184
+ // if rls is enabled, result should be empty; if not, may have rows
185
+ expect(Array.isArray(result)).toBe(true);
186
+ if (rlsStatus[0]?.relrowsecurity === true) {
187
+ expect(result.length).toBe(0);
188
+ } else {
189
+ // rls not enabled, access may be granted based on grants
190
+ expect(Array.isArray(result)).toBe(true);
191
+ }
192
+ });
193
+
194
+ it('should verify migrations table has indexes', async () => {
195
+ db.setContext({ role: 'service_role' });
196
+
197
+ // verify indexes exist
198
+ const indexes = await db.any(
199
+ `SELECT indexname, indexdef
200
+ FROM pg_indexes
201
+ WHERE schemaname = 'supabase_functions'
202
+ AND tablename = 'migrations'`
203
+ );
204
+
205
+ expect(Array.isArray(indexes)).toBe(true);
206
+ // indexes may or may not exist, but structure should be valid
207
+ if (indexes.length > 0) {
208
+ expect(indexes[0].indexname).toBeDefined();
209
+ expect(indexes[0].indexdef).toBeDefined();
210
+ }
211
+ });
212
+ });
213
+
@@ -0,0 +1,225 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ let temporalTableExists = false;
8
+
9
+ beforeAll(async () => {
10
+
11
+
12
+ ({ pg, db, teardown } = await getConnections());
13
+
14
+ // verify storage schema exists
15
+ const storageSchemaExists = await pg.any(
16
+ `SELECT EXISTS (
17
+ SELECT FROM information_schema.schemata
18
+ WHERE schema_name = 'storage'
19
+ ) as exists`
20
+ );
21
+ expect(storageSchemaExists[0].exists).toBe(true);
22
+
23
+ // grant access to storage schema for testing
24
+ await pg.any(
25
+ `GRANT USAGE ON SCHEMA storage TO public;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
27
+ GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
28
+ GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
30
+ ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
31
+ []
32
+ );
33
+
34
+ // check if storage.objects table exists (using pg in beforeAll only)
35
+ const exists = await pg.any(
36
+ `SELECT EXISTS (
37
+ SELECT FROM information_schema.tables
38
+ WHERE table_schema = 'storage' AND table_name = 'objects'
39
+ ) as exists`
40
+ );
41
+ temporalTableExists = exists[0]?.exists === true;
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: rls with temporal columns on supabase tables', () => {
57
+
58
+ it('should verify storage.objects has temporal columns', async () => {
59
+ expect(temporalTableExists).toBe(true);
60
+
61
+ db.setContext({ role: 'service_role' });
62
+
63
+ const columns = await db.any(
64
+ `SELECT column_name, data_type
65
+ FROM information_schema.columns
66
+ WHERE table_schema = 'storage'
67
+ AND table_name = 'objects'
68
+ AND column_name IN ('created_at', 'updated_at', 'last_accessed_at')`
69
+ );
70
+
71
+ expect(Array.isArray(columns)).toBe(true);
72
+ // at least created_at should exist
73
+ const hasCreatedAt = columns.some((c: any) => c.column_name === 'created_at');
74
+ expect(hasCreatedAt).toBe(true);
75
+ });
76
+
77
+ it('should verify service_role can query temporal columns', async () => {
78
+ expect(temporalTableExists).toBe(true);
79
+
80
+ db.setContext({ role: 'service_role' });
81
+
82
+ const objects = await db.any(
83
+ `SELECT id, name, created_at, updated_at, last_accessed_at
84
+ FROM storage.objects
85
+ ORDER BY created_at DESC
86
+ LIMIT 10`
87
+ );
88
+
89
+ expect(Array.isArray(objects)).toBe(true);
90
+
91
+ if (objects.length > 0) {
92
+ expect(objects[0].created_at).toBeDefined();
93
+ }
94
+ });
95
+
96
+ it('should verify time-windowed queries work with rls', async () => {
97
+ expect(temporalTableExists).toBe(true);
98
+
99
+ db.setContext({ role: 'service_role' });
100
+
101
+ // query objects from last 30 days
102
+ const recentObjects = await db.any(
103
+ `SELECT id, name, created_at
104
+ FROM storage.objects
105
+ WHERE created_at >= NOW() - INTERVAL '30 days'
106
+ ORDER BY created_at DESC
107
+ LIMIT 10`
108
+ );
109
+
110
+ expect(Array.isArray(recentObjects)).toBe(true);
111
+ });
112
+
113
+ it('should verify date range filtering works with rls', async () => {
114
+ expect(temporalTableExists).toBe(true);
115
+
116
+ db.setContext({ role: 'service_role' });
117
+
118
+ // query objects created in last 7 days
119
+ const weekOldObjects = await db.any(
120
+ `SELECT id, name, created_at
121
+ FROM storage.objects
122
+ WHERE created_at >= NOW() - INTERVAL '7 days'
123
+ AND created_at < NOW()
124
+ ORDER BY created_at DESC
125
+ LIMIT 10`
126
+ );
127
+
128
+ expect(Array.isArray(weekOldObjects)).toBe(true);
129
+ });
130
+
131
+ it('should verify temporal aggregations work with rls', async () => {
132
+ expect(temporalTableExists).toBe(true);
133
+
134
+ db.setContext({ role: 'service_role' });
135
+
136
+ // aggregate objects by date
137
+ const dailyCounts = await db.any(
138
+ `SELECT DATE(created_at) as date, COUNT(*) as count
139
+ FROM storage.objects
140
+ WHERE created_at >= NOW() - INTERVAL '30 days'
141
+ GROUP BY DATE(created_at)
142
+ ORDER BY date DESC
143
+ LIMIT 10`
144
+ );
145
+
146
+ expect(Array.isArray(dailyCounts)).toBe(true);
147
+ });
148
+
149
+ it('should verify last_accessed_at queries work with rls', async () => {
150
+ expect(temporalTableExists).toBe(true);
151
+
152
+ db.setContext({ role: 'service_role' });
153
+
154
+ // query recently accessed objects
155
+ const accessedObjects = await db.any(
156
+ `SELECT id, name, last_accessed_at
157
+ FROM storage.objects
158
+ WHERE last_accessed_at >= NOW() - INTERVAL '7 days'
159
+ ORDER BY last_accessed_at DESC
160
+ LIMIT 10`
161
+ );
162
+
163
+ expect(Array.isArray(accessedObjects)).toBe(true);
164
+ });
165
+
166
+ it('should verify timezone-aware queries work with rls', async () => {
167
+ expect(temporalTableExists).toBe(true);
168
+
169
+ db.setContext({ role: 'service_role' });
170
+
171
+ // query with timezone conversion
172
+ const objects = await db.any(
173
+ `SELECT id, name,
174
+ created_at AT TIME ZONE 'UTC' as created_utc,
175
+ created_at AT TIME ZONE 'America/New_York' as created_ny
176
+ FROM storage.objects
177
+ ORDER BY created_at DESC
178
+ LIMIT 10`
179
+ );
180
+
181
+ expect(Array.isArray(objects)).toBe(true);
182
+ });
183
+
184
+ it('should verify anon cannot access temporal data', async () => {
185
+ expect(temporalTableExists).toBe(true);
186
+
187
+ db.setContext({ role: 'anon' });
188
+
189
+ const result = await db.any(
190
+ `SELECT id, created_at
191
+ FROM storage.objects
192
+ WHERE created_at >= NOW() - INTERVAL '30 days'
193
+ LIMIT 1`
194
+ );
195
+
196
+ // rls should block access
197
+ expect(result.length).toBe(0);
198
+ });
199
+
200
+ it('should verify temporal ordering works with rls', async () => {
201
+ expect(temporalTableExists).toBe(true);
202
+
203
+ db.setContext({ role: 'service_role' });
204
+
205
+ // order by multiple temporal columns
206
+ const objects = await db.any(
207
+ `SELECT id, name, created_at, updated_at
208
+ FROM storage.objects
209
+ ORDER BY created_at DESC, updated_at DESC
210
+ LIMIT 10`
211
+ );
212
+
213
+ expect(Array.isArray(objects)).toBe(true);
214
+
215
+ // verify ordering (if multiple results)
216
+ if (objects.length > 1) {
217
+ for (let i = 0; i < objects.length - 1; i++) {
218
+ const current = new Date(objects[i].created_at);
219
+ const next = new Date(objects[i + 1].created_at);
220
+ expect(current.getTime()).toBeGreaterThanOrEqual(next.getTime());
221
+ }
222
+ }
223
+ });
224
+ });
225
+
@@ -0,0 +1,145 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ // no hidden flags; fail fast and assert actual behavior
8
+
9
+ beforeAll(async () => {
10
+
11
+
12
+ ({ pg, db, teardown } = await getConnections());
13
+
14
+ // verify vault schema exists
15
+ const vaultSchemaExists = await pg.any(
16
+ `SELECT EXISTS (
17
+ SELECT FROM information_schema.schemata
18
+ WHERE schema_name = 'vault'
19
+ ) as exists`
20
+ );
21
+ expect(vaultSchemaExists[0].exists).toBe(true);
22
+
23
+ // grant access to vault schema for testing
24
+ await pg.any(
25
+ `GRANT USAGE ON SCHEMA vault TO public;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA vault TO service_role;
27
+ GRANT SELECT ON ALL TABLES IN SCHEMA vault TO anon;
28
+ GRANT SELECT ON ALL TABLES IN SCHEMA vault TO authenticated;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA vault GRANT SELECT ON TABLES TO anon;
30
+ ALTER DEFAULT PRIVILEGES IN SCHEMA vault GRANT SELECT ON TABLES TO authenticated;`,
31
+ []
32
+ );
33
+
34
+ // assert vault.secrets exists (fail fast)
35
+ const exists = await pg.any(
36
+ `SELECT EXISTS (
37
+ SELECT FROM information_schema.tables
38
+ WHERE table_schema = 'vault' AND table_name = 'secrets'
39
+ ) as exists`
40
+ );
41
+ expect(exists[0].exists).toBe(true);
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: vault secrets table access', () => {
57
+
58
+ it('should verify vault.secrets table exists', async () => {
59
+ db.setContext({ role: 'service_role' });
60
+ const exists = await db.any(
61
+ `SELECT EXISTS (
62
+ SELECT FROM information_schema.tables
63
+ WHERE table_schema = 'vault' AND table_name = 'secrets'
64
+ ) as exists`
65
+ );
66
+ expect(Array.isArray(exists)).toBe(true);
67
+ expect(exists[0].exists).toBe(true);
68
+ });
69
+
70
+ it('should verify service_role can query secrets structure', async () => {
71
+ db.setContext({ role: 'service_role' });
72
+ const columns = await db.any(
73
+ `SELECT column_name, data_type
74
+ FROM information_schema.columns
75
+ WHERE table_schema = 'vault' AND table_name = 'secrets'
76
+ ORDER BY ordinal_position`
77
+ );
78
+ expect(Array.isArray(columns)).toBe(true);
79
+ const names = columns.map((r: any) => r.column_name);
80
+ expect(names).toEqual(expect.arrayContaining([
81
+ 'id', 'name', 'description', 'secret', 'key_id', 'nonce', 'created_at', 'updated_at'
82
+ ]));
83
+ });
84
+
85
+ it('should verify unique index on name exists (partial)', async () => {
86
+ db.setContext({ role: 'service_role' });
87
+ const idx = await db.any(
88
+ `SELECT indexname, indexdef
89
+ FROM pg_indexes
90
+ WHERE schemaname = 'vault' AND tablename = 'secrets'`
91
+ );
92
+ expect(Array.isArray(idx)).toBe(true);
93
+ if (idx.length > 0) {
94
+ const defs = idx.map((r: any) => String(r.indexdef).toLowerCase()).join(' ');
95
+ expect(defs.includes('unique')).toBe(true);
96
+ expect(defs.includes('(name)')).toBe(true);
97
+ }
98
+ });
99
+
100
+ it('should verify relrowsecurity status on secrets', async () => {
101
+ db.setContext({ role: 'service_role' });
102
+ const rlsStatus = await db.any(
103
+ `SELECT c.relrowsecurity
104
+ FROM pg_class c
105
+ JOIN pg_namespace n ON n.oid = c.relnamespace
106
+ WHERE n.nspname = 'vault' AND c.relname = 'secrets'`
107
+ );
108
+ expect(Array.isArray(rlsStatus)).toBe(true);
109
+ expect(rlsStatus.length).toBeGreaterThan(0);
110
+ expect(typeof rlsStatus[0].relrowsecurity).toBe('boolean');
111
+ });
112
+
113
+ it('should verify anon access to secrets based on rls', async () => {
114
+ db.setContext({ role: 'service_role' });
115
+ const rlsStatus = await db.any(
116
+ `SELECT c.relrowsecurity
117
+ FROM pg_class c
118
+ JOIN pg_namespace n ON n.oid = c.relnamespace
119
+ WHERE n.nspname = 'vault' AND c.relname = 'secrets'`
120
+ );
121
+ db.clearContext();
122
+ const result = await db.any(`SELECT * FROM vault.secrets LIMIT 1`);
123
+ expect(Array.isArray(result)).toBe(true);
124
+ if (rlsStatus[0]?.relrowsecurity === true) {
125
+ expect(result.length).toBe(0);
126
+ }
127
+ });
128
+
129
+ it('should verify authenticated access to secrets based on rls', async () => {
130
+ db.setContext({ role: 'service_role' });
131
+ const rlsStatus = await db.any(
132
+ `SELECT c.relrowsecurity
133
+ FROM pg_class c
134
+ JOIN pg_namespace n ON n.oid = c.relnamespace
135
+ WHERE n.nspname = 'vault' AND c.relname = 'secrets'`
136
+ );
137
+ db.setContext({ role: 'authenticated' });
138
+ const result = await db.any(`SELECT * FROM vault.secrets LIMIT 1`);
139
+ expect(Array.isArray(result)).toBe(true);
140
+ if (rlsStatus[0]?.relrowsecurity === true) {
141
+ expect(result.length).toBe(0);
142
+ }
143
+ });
144
+ });
145
+
package/deploy/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The PostgreSQL License
2
+
3
+ Copyright (c) 2020, Supabase
4
+
5
+ Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
6
+
7
+ IN NO EVENT SHALL Supabase BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF Supabase HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8
+
9
+ Supabase SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND Supabase HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.