From c8c59e3d8cc451dfad25688c2a92c973fd8b1e80 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Wed, 24 Jan 2024 17:39:11 +0100 Subject: [PATCH 1/2] Add ALLOWED_DOMAIN_PATTERN env --- .changeset/itchy-bikes-smash.md | 5 +++++ src/lib/env.mjs | 2 ++ src/pages/api/register.ts | 24 ++++++++++++------------ 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 .changeset/itchy-bikes-smash.md diff --git a/.changeset/itchy-bikes-smash.md b/.changeset/itchy-bikes-smash.md new file mode 100644 index 0000000..8c3a892 --- /dev/null +++ b/.changeset/itchy-bikes-smash.md @@ -0,0 +1,5 @@ +--- +"saleor-app-payment-stripe": minor +--- + +Added "ALLOWED_DOMAIN_PATTERN" env that can be used to allow/disallow specific Saleor instances diff --git a/src/lib/env.mjs b/src/lib/env.mjs index 0af92ac..320e42e 100644 --- a/src/lib/env.mjs +++ b/src/lib/env.mjs @@ -24,6 +24,7 @@ export const env = createEnv({ UPSTASH_TOKEN: z.string().optional(), REST_APL_ENDPOINT: z.string().optional(), REST_APL_TOKEN: z.string().optional(), + ALLOWED_DOMAIN_PATTERN: z.string().optional() }, /* @@ -56,5 +57,6 @@ export const env = createEnv({ UPSTASH_TOKEN: process.env.UPSTASH_TOKEN, REST_APL_ENDPOINT: process.env.REST_APL_ENDPOINT, REST_APL_TOKEN: process.env.REST_APL_TOKEN, + ALLOWED_DOMAIN_PATTERN: process.env.ALLOWED_DOMAIN_PATTERN, }, }); diff --git a/src/pages/api/register.ts b/src/pages/api/register.ts index 796ec03..4d37e21 100644 --- a/src/pages/api/register.ts +++ b/src/pages/api/register.ts @@ -1,6 +1,9 @@ import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next"; import { saleorApp } from "../../saleor-app"; +import { env } from "@/lib/env.mjs"; + +const allowedUrlsPattern = env.ALLOWED_DOMAIN_PATTERN; /** * Required endpoint, called by Saleor to install app. @@ -9,17 +12,14 @@ import { saleorApp } from "../../saleor-app"; export default createAppRegisterHandler({ apl: saleorApp.apl, allowedSaleorUrls: [ - /** - * You may want your app to work only for certain Saleor instances. - * - * Your app can work for every Saleor that installs it, but you can - * limit it here - * - * By default, every url is allowed. - * - * URL should be a full graphQL address, usually starting with https:// and ending with /graphql/ - * - * Alternatively pass a function - */ + (url) => { + if (allowedUrlsPattern) { + const regex = new RegExp(allowedUrlsPattern); + + return regex.test(url); + } + + return true; + }, ], }); From 42c17024b2aa632e61a792d71a495d82466245b0 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Wed, 24 Jan 2024 17:44:33 +0100 Subject: [PATCH 2/2] fix prettier --- src/lib/env.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/env.mjs b/src/lib/env.mjs index 320e42e..5836240 100644 --- a/src/lib/env.mjs +++ b/src/lib/env.mjs @@ -24,7 +24,7 @@ export const env = createEnv({ UPSTASH_TOKEN: z.string().optional(), REST_APL_ENDPOINT: z.string().optional(), REST_APL_TOKEN: z.string().optional(), - ALLOWED_DOMAIN_PATTERN: z.string().optional() + ALLOWED_DOMAIN_PATTERN: z.string().optional(), }, /*