From c4d56ba166312130b76a4956ddc502c1415576ec Mon Sep 17 00:00:00 2001 From: r-southworth Date: Mon, 19 Aug 2024 16:05:33 -0400 Subject: [PATCH] stripe wrapper working --- package-lock.json | 23 ++++++------- .../20240819181951_stripeWrapperKeys.sql | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 supabase/migrations/20240819181951_stripeWrapperKeys.sql diff --git a/package-lock.json b/package-lock.json index 0da81b02..c6e32301 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15081,9 +15081,9 @@ "dev": true }, "node_modules/rimraf": { - "version": "5.0.7", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.7.tgz", - "integrity": "sha512-nV6YcJo5wbLW77m+8KjH8aB/7/rxQy9SZ0HY5shnwULfS+9nmTtVXAJET5NdZmCzA4fPI/Hm1wo/Po/4mopOdg==", + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.10.tgz", + "integrity": "sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==", "dev": true, "dependencies": { "glob": "^10.3.7" @@ -15091,9 +15091,6 @@ "bin": { "rimraf": "dist/esm/bin.mjs" }, - "engines": { - "node": ">=14.18" - }, "funding": { "url": "https://github.com/sponsors/isaacs" } @@ -16091,16 +16088,16 @@ } }, "node_modules/supabase": { - "version": "1.178.2", - "resolved": "https://registry.npmjs.org/supabase/-/supabase-1.178.2.tgz", - "integrity": "sha512-JdjNY56cF5PbuhFdhgdYah5qXOPRsLQn0kXaY7uapTFopdIFX4tRiFXqKSig8S0SdznF/y/f6vLdq30Sek1ZZQ==", + "version": "1.190.0", + "resolved": "https://registry.npmjs.org/supabase/-/supabase-1.190.0.tgz", + "integrity": "sha512-Ez07pA+xhffXbfWAF9PfE2teW95vINFPFAbTlXUChMh4Jjm0CYO7cgg4qSxJjmnylSB3R0uo36WFEKm1wUeupA==", "dev": true, "hasInstallScript": true, "dependencies": { "bin-links": "^4.0.3", "https-proxy-agent": "^7.0.2", "node-fetch": "^3.3.2", - "tar": "7.4.0" + "tar": "7.4.3" }, "bin": { "supabase": "bin/supabase" @@ -16156,9 +16153,9 @@ } }, "node_modules/supabase/node_modules/tar": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.4.0.tgz", - "integrity": "sha512-XQs0S8fuAkQWuqhDeCdMlJXDX80D7EOVLDPVFkna9yQfzS+PHKgfxcei0jf6/+QAWcjqrnC8uM3fSAnrQl+XYg==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.4.3.tgz", + "integrity": "sha512-5S7Va8hKfV7W5U6g3aYxXmlPoZVAwUMy9AOKyF2fVuZa2UD3qZjg578OrLRt8PcNN1PleVaL/5/yYATNL0ICUw==", "dev": true, "dependencies": { "@isaacs/fs-minipass": "^4.0.0", diff --git a/supabase/migrations/20240819181951_stripeWrapperKeys.sql b/supabase/migrations/20240819181951_stripeWrapperKeys.sql new file mode 100644 index 00000000..32fba87f --- /dev/null +++ b/supabase/migrations/20240819181951_stripeWrapperKeys.sql @@ -0,0 +1,34 @@ +CREATE SERVER stripe_server FOREIGN DATA WRAPPER stripe_wrapper OPTIONS (api_key_id 'placeholder'); + +CREATE PROCEDURE install_stripe_secret_reference() AS $$ + DECLARE + vault_key_id TEXT; + BEGIN + SELECT key_id::TEXT FROM vault.secrets WHERE name='stripe' INTO vault_key_id; + IF vault_key_id IS NOT NULL THEN + EXECUTE 'ALTER SERVER stripe_server OPTIONS (SET api_key_id ' || quote_literal(vault_key_id) || ')'; + END IF; + END +$$ LANGUAGE PLPGSQL; +COMMENT ON PROCEDURE install_stripe_secret_reference() IS 'Look up the Stripe key_id from the vault and set it in the server wrapper'; + +REVOKE ALL ON PROCEDURE install_stripe_secret_reference FROM PUBLIC,authenticated,anon; + +CALL install_stripe_secret_reference(); + +create schema stripe; + +create foreign table stripe.prices ( + id text, + active bool, + currency text, + product text, + unit_amount bigint, + type text, + created timestamp, + attrs jsonb +) + server stripe_server + options ( + object 'prices' + ); \ No newline at end of file