shopify-app-js 0.0.1-security → 1.0.1
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.
Potentially problematic release.
This version of shopify-app-js might be problematic. Click here for more details.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +14 -0
- package/.changeset/flat-clouds-camp.md +5 -0
- package/.eslintrc.js +36 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/ISSUE_TEMPLATE/BUG_REPORT.md +36 -0
- package/.github/ISSUE_TEMPLATE/ENHANCEMENT.md +9 -0
- package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +9 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
- package/.github/dependabot.yml +9 -0
- package/.github/workflows/changelog.yml +30 -0
- package/.github/workflows/ci.yml +22 -0
- package/.github/workflows/cla.yml +22 -0
- package/.github/workflows/close-waiting-for-response-issues.yml +20 -0
- package/.github/workflows/main-release.yml +36 -0
- package/.github/workflows/markdown_link_check.yml +14 -0
- package/.github/workflows/markdown_link_checker_config.json +9 -0
- package/.github/workflows/publish-experimental-build.yml +30 -0
- package/.github/workflows/release-candidate.yml +35 -0
- package/.github/workflows/remove-labels-on-activity.yml +16 -0
- package/.github/workflows/stale.yml +26 -0
- package/.prettierignore +5 -0
- package/.prettierrc +1 -0
- package/CODE_OF_CONDUCT.md +46 -0
- package/CONTRIBUTING.md +39 -0
- package/LICENSE.md +9 -0
- package/README.md +62 -3
- package/RELEASING.md +142 -0
- package/loom.config.ts +115 -0
- package/package.json +44 -3
- package/packages/.prettierrc +1 -0
- package/packages/shopify-app-express/CHANGELOG.md +316 -0
- package/packages/shopify-app-express/LICENSE.md +9 -0
- package/packages/shopify-app-express/README.md +93 -0
- package/packages/shopify-app-express/docs/reference/README.md +3 -0
- package/packages/shopify-app-express/docs/reference/auth.md +76 -0
- package/packages/shopify-app-express/docs/reference/cspHeaders.md +24 -0
- package/packages/shopify-app-express/docs/reference/ensureInstalledOnShop.md +17 -0
- package/packages/shopify-app-express/docs/reference/migrating-app-v6-api-lib-to-express-lib.md +345 -0
- package/packages/shopify-app-express/docs/reference/processWebhooks.md +67 -0
- package/packages/shopify-app-express/docs/reference/redirectOutOfApp.md +77 -0
- package/packages/shopify-app-express/docs/reference/redirectToShopifyOrAppRoot.md +20 -0
- package/packages/shopify-app-express/docs/reference/shopifyApp.md +148 -0
- package/packages/shopify-app-express/docs/reference/validateAuthenticatedSession.md +30 -0
- package/packages/shopify-app-express/loom.config.ts +27 -0
- package/packages/shopify-app-express/package.json +54 -0
- package/packages/shopify-app-express/src/__tests__/index.test.ts +100 -0
- package/packages/shopify-app-express/src/__tests__/integration/oauth.test.ts +445 -0
- package/packages/shopify-app-express/src/__tests__/integration/responses.ts +135 -0
- package/packages/shopify-app-express/src/__tests__/integration/types.ts +22 -0
- package/packages/shopify-app-express/src/__tests__/integration/utils.ts +68 -0
- package/packages/shopify-app-express/src/__tests__/integration/webhooks.test.ts +208 -0
- package/packages/shopify-app-express/src/__tests__/redirect-to-auth.test.ts +103 -0
- package/packages/shopify-app-express/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-express/src/__tests__/test-helper.ts +204 -0
- package/packages/shopify-app-express/src/app-installations.ts +42 -0
- package/packages/shopify-app-express/src/auth/__tests__/auth.test.ts +303 -0
- package/packages/shopify-app-express/src/auth/auth-callback.ts +131 -0
- package/packages/shopify-app-express/src/auth/index.ts +32 -0
- package/packages/shopify-app-express/src/auth/types.ts +13 -0
- package/packages/shopify-app-express/src/config-types.ts +38 -0
- package/packages/shopify-app-express/src/error.ts +8 -0
- package/packages/shopify-app-express/src/index.ts +171 -0
- package/packages/shopify-app-express/src/middlewares/__tests__/csp-headers.test.ts +69 -0
- package/packages/shopify-app-express/src/middlewares/__tests__/ensure-installed-on-shop.test.ts +193 -0
- package/packages/shopify-app-express/src/middlewares/__tests__/redirect-to-shopify-or-app-root.test.ts +59 -0
- package/packages/shopify-app-express/src/middlewares/__tests__/validate-authenticated-session.test.ts +319 -0
- package/packages/shopify-app-express/src/middlewares/csp-headers.ts +31 -0
- package/packages/shopify-app-express/src/middlewares/ensure-installed-on-shop.ts +176 -0
- package/packages/shopify-app-express/src/middlewares/has-valid-access-token.ts +25 -0
- package/packages/shopify-app-express/src/middlewares/index.ts +15 -0
- package/packages/shopify-app-express/src/middlewares/redirect-to-shopify-or-app-root.ts +39 -0
- package/packages/shopify-app-express/src/middlewares/types.ts +6 -0
- package/packages/shopify-app-express/src/middlewares/validate-authenticated-session.ts +142 -0
- package/packages/shopify-app-express/src/redirect-out-of-app.ts +80 -0
- package/packages/shopify-app-express/src/redirect-to-auth.ts +70 -0
- package/packages/shopify-app-express/src/types.ts +26 -0
- package/packages/shopify-app-express/src/version.ts +1 -0
- package/packages/shopify-app-express/src/webhooks/__tests__/process.test.ts +138 -0
- package/packages/shopify-app-express/src/webhooks/index.ts +54 -0
- package/packages/shopify-app-express/src/webhooks/process.ts +22 -0
- package/packages/shopify-app-express/src/webhooks/types.ts +24 -0
- package/packages/shopify-app-express/tsconfig.json +10 -0
- package/packages/shopify-app-remix/.eslintrc.js +3 -0
- package/packages/shopify-app-remix/CHANGELOG.md +569 -0
- package/packages/shopify-app-remix/LICENSE.md +9 -0
- package/packages/shopify-app-remix/README.md +223 -0
- package/packages/shopify-app-remix/docs/build-docs.sh +11 -0
- package/packages/shopify-app-remix/docs/generated/generated_docs_data.json +18650 -0
- package/packages/shopify-app-remix/docs/generated/generated_static_pages.json +540 -0
- package/packages/shopify-app-remix/docs/staticPages/admin.doc.ts +130 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/auth-cors.example.tsx +11 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/auth.example.tsx +19 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/graphql.example.tsx +29 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/headers.example.tsx +10 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/rest-resources.example.tsx +9 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/rest.example.tsx +17 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/config.example.ts +8 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/unstable.example.ts +9 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/.graphqlrc.ts +16 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.npm.example.sh +2 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.pnpm.example.sh +2 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.yarn.example.sh +2 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/package.json +5 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.npm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.pnpm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.yarn.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/webhooks/config.example.ts +19 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/guides/webhooks/endpoint.example.ts +24 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/app-provider.example.ts +30 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/boundaries.example.ts +9 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/create.npm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/create.pnpm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/create.yarn.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/embedded-app-auth-strategy-config.example.ts +10 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/entry-server.example.ts +12 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/install.npm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/install.pnpm.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/install.yarn.example.sh +1 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/shopify-app.example.ts +14 -0
- package/packages/shopify-app-remix/docs/staticPages/examples/index/splat-route.example.ts +11 -0
- package/packages/shopify-app-remix/docs/staticPages/future-flags.doc.ts +94 -0
- package/packages/shopify-app-remix/docs/staticPages/graphql-types.doc.ts +148 -0
- package/packages/shopify-app-remix/docs/staticPages/index.doc.ts +227 -0
- package/packages/shopify-app-remix/docs/staticPages/webhooks.doc.ts +64 -0
- package/packages/shopify-app-remix/docs/tsconfig.docs.json +9 -0
- package/packages/shopify-app-remix/docs/typeOverride.json +1 -0
- package/packages/shopify-app-remix/docs/upcoming_changes.md +153 -0
- package/packages/shopify-app-remix/loom.config.ts +57 -0
- package/packages/shopify-app-remix/package.json +93 -0
- package/packages/shopify-app-remix/src/react/.eslintrc.js +16 -0
- package/packages/shopify-app-remix/src/react/__tests__/test-helper.ts +22 -0
- package/packages/shopify-app-remix/src/react/components/AppProvider/AppProvider.doc.ts +34 -0
- package/packages/shopify-app-remix/src/react/components/AppProvider/AppProvider.tsx +121 -0
- package/packages/shopify-app-remix/src/react/components/AppProvider/__tests__/AppProvider.test.tsx +68 -0
- package/packages/shopify-app-remix/src/react/components/AppProvider/index.ts +1 -0
- package/packages/shopify-app-remix/src/react/components/RemixPolarisLink.tsx +14 -0
- package/packages/shopify-app-remix/src/react/components/index.ts +1 -0
- package/packages/shopify-app-remix/src/react/const.ts +2 -0
- package/packages/shopify-app-remix/src/react/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/.eslintrc.js +16 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/__tests__/request-mock.test.ts +171 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/const.ts +11 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-admin-api-client.ts +119 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-begin-auth-redirect.ts +22 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-document-request-headers.ts +25 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-exit-iframe.ts +37 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-login-redirect.ts +8 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/expect-storefront-api-client.ts +50 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/get-hmac.ts +10 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/get-jwt.ts +31 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/get-thrown-response.ts +17 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/index.ts +14 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/request-mock.ts +169 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/setup-valid-session.ts +45 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/sign-request-cookie.ts +21 -0
- package/packages/shopify-app-remix/src/server/__test-helpers/test-config.ts +112 -0
- package/packages/shopify-app-remix/src/server/__tests__/override-logger.test.ts +101 -0
- package/packages/shopify-app-remix/src/server/__tests__/shopify-app.test.ts +119 -0
- package/packages/shopify-app-remix/src/server/adapters/__tests__/node-app-bridge-url.test.ts +18 -0
- package/packages/shopify-app-remix/src/server/adapters/__tests__/node.test.ts +28 -0
- package/packages/shopify-app-remix/src/server/adapters/node/__tests__/setup-jest.ts +10 -0
- package/packages/shopify-app-remix/src/server/adapters/node/index.ts +20 -0
- package/packages/shopify-app-remix/src/server/adapters/vercel/__tests__/setup-jest.ts +12 -0
- package/packages/shopify-app-remix/src/server/adapters/vercel/index.ts +13 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/admin-client.test.ts +181 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/doc-request-path.test.ts +151 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/exit-i-frame-path.test.ts +99 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/patch-session-token-path.test.ts +58 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/reject-bot.test.ts +23 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/respond-to-options.test.ts +50 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/session-token-header-path.test.ts +91 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/authenticate.admin.doc.ts +37 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/authenticate.ts +201 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/cancel.test.ts +258 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/check.test.ts +254 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/mock-responses.ts +65 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/request.test.ts +373 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/require.test.ts +316 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/authenticate.admin.billing.doc.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/cancel.ts +37 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/check.ts +38 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/index.ts +4 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/request.ts +101 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/require.ts +56 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/billing/types.ts +383 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/__tests__/redirect.test.ts +313 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/__tests__/validate-redirect-url.test.ts +84 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/begin-auth.ts +17 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/create-admin-api-context.ts +22 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/ensure-app-is-embedded-if-required.ts +18 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/ensure-session-token-search-param-if-required.ts +25 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/handle-client-error.ts +43 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/index.ts +14 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-auth-page.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-bounce-page.ts +23 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-shopify-or-app-root.ts +21 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-with-app-bridge-headers.ts +13 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-with-exitiframe.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect.ts +83 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/render-app-bridge.ts +46 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/trigger-after-auth-hook.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/validate-redirect-url.ts +67 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/validate-shop-and-host-params.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/admin-client.test.ts +222 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/auth-callback-path.test.ts +395 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/auth-path.test.ts +83 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/authenticate.test.ts +183 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/ensure-installed-on-shop.test.ts +234 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/session-token-header-path.test.ts +79 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/token-exchange/admin-client.test.ts +189 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/token-exchange/authenticate.test.ts +310 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/auth-code-flow.ts +333 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/token-exchange.ts +169 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/types.ts +29 -0
- package/packages/shopify-app-remix/src/server/authenticate/admin/types.ts +199 -0
- package/packages/shopify-app-remix/src/server/authenticate/const.ts +15 -0
- package/packages/shopify-app-remix/src/server/authenticate/flow/__tests__/authenticate.test.ts +142 -0
- package/packages/shopify-app-remix/src/server/authenticate/flow/authenticate.flow.doc.ts +34 -0
- package/packages/shopify-app-remix/src/server/authenticate/flow/authenticate.ts +71 -0
- package/packages/shopify-app-remix/src/server/authenticate/flow/types.ts +90 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/add-response-headers.test.ts +25 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/app-bridge-url.test.ts +21 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/idempotent-promise-handler.test.ts +104 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/add-response-headers.ts +43 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/app-bridge-url.ts +10 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/ensure-cors-headers.ts +38 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/get-session-token-header.ts +11 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/idempotent-promise-handler.ts +45 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/index.ts +8 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/reject-bot-request.ts +13 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/respond-to-invalid-session-token.ts +29 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/respond-to-options-request.ts +26 -0
- package/packages/shopify-app-remix/src/server/authenticate/helpers/validate-session-token.ts +32 -0
- package/packages/shopify-app-remix/src/server/authenticate/login/__tests__/login.test.ts +157 -0
- package/packages/shopify-app-remix/src/server/authenticate/login/login.ts +53 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/__tests__/factory.test.ts +224 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/__tests__/authenticate.test.ts +282 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.ts +36 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/authenticate.ts +90 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/types.ts +164 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/checkout/__tests__/authenticate.test.ts +142 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/checkout/authenticate.public.checkout.doc.ts +23 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/checkout/authenticate.ts +45 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/checkout/types.ts +65 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/factory.ts +49 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/authenticate/public/types.ts +77 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/authenticate.test.ts +207 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/mock-responses.ts +45 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/register.test.ts +210 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/authenticate.ts +113 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/authenticate.webhooks.doc.ts +28 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/register.ts +48 -0
- package/packages/shopify-app-remix/src/server/authenticate/webhooks/types.ts +246 -0
- package/packages/shopify-app-remix/src/server/boundary/__tests__/error.test.tsx +36 -0
- package/packages/shopify-app-remix/src/server/boundary/__tests__/headers.test.ts +66 -0
- package/packages/shopify-app-remix/src/server/boundary/error.tsx +14 -0
- package/packages/shopify-app-remix/src/server/boundary/headers.ts +15 -0
- package/packages/shopify-app-remix/src/server/boundary/index.ts +39 -0
- package/packages/shopify-app-remix/src/server/boundary/types.ts +4 -0
- package/packages/shopify-app-remix/src/server/clients/admin/authenticate.admin.api.doc.ts +34 -0
- package/packages/shopify-app-remix/src/server/clients/admin/factory.ts +30 -0
- package/packages/shopify-app-remix/src/server/clients/admin/graphql.ts +39 -0
- package/packages/shopify-app-remix/src/server/clients/admin/index.ts +2 -0
- package/packages/shopify-app-remix/src/server/clients/admin/rest.ts +157 -0
- package/packages/shopify-app-remix/src/server/clients/admin/types.ts +178 -0
- package/packages/shopify-app-remix/src/server/clients/index.ts +2 -0
- package/packages/shopify-app-remix/src/server/clients/storefront/authenticate.storefront.api.doc.ts +34 -0
- package/packages/shopify-app-remix/src/server/clients/storefront/factory.ts +32 -0
- package/packages/shopify-app-remix/src/server/clients/storefront/index.ts +2 -0
- package/packages/shopify-app-remix/src/server/clients/storefront/types.ts +31 -0
- package/packages/shopify-app-remix/src/server/clients/types.ts +27 -0
- package/packages/shopify-app-remix/src/server/config-types.ts +293 -0
- package/packages/shopify-app-remix/src/server/errors.ts +3 -0
- package/packages/shopify-app-remix/src/server/future/flags.ts +57 -0
- package/packages/shopify-app-remix/src/server/index.ts +20 -0
- package/packages/shopify-app-remix/src/server/override-logger.ts +42 -0
- package/packages/shopify-app-remix/src/server/shopify-app.doc.ts +45 -0
- package/packages/shopify-app-remix/src/server/shopify-app.ts +198 -0
- package/packages/shopify-app-remix/src/server/types.ts +509 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/admin/__tests__/factory.test.ts +30 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/admin/factory.ts +29 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/admin/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/admin/types.ts +117 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/admin/unauthenticated.admin.doc.ts +40 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/helpers/get-offline-session.ts +13 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/helpers/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/storefront/__tests__/factory.test.ts +30 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/storefront/factory.ts +28 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/storefront/index.ts +1 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/storefront/types.ts +39 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/storefront/unauthenticated.storefront.doc.ts +40 -0
- package/packages/shopify-app-remix/src/server/unauthenticated/types.ts +68 -0
- package/packages/shopify-app-remix/src/server/version.ts +1 -0
- package/packages/shopify-app-remix/tsconfig.json +11 -0
- package/packages/shopify-app-session-storage/CHANGELOG.md +149 -0
- package/packages/shopify-app-session-storage/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage/README.md +5 -0
- package/packages/shopify-app-session-storage/implementing-session-storage.md +214 -0
- package/packages/shopify-app-session-storage/loom.config.ts +45 -0
- package/packages/shopify-app-session-storage/package.json +44 -0
- package/packages/shopify-app-session-storage/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage/src/abstract-migration-engine.ts +53 -0
- package/packages/shopify-app-session-storage/src/index.ts +3 -0
- package/packages/shopify-app-session-storage/src/rdbms-session-storage-migrator.ts +59 -0
- package/packages/shopify-app-session-storage/src/types.ts +174 -0
- package/packages/shopify-app-session-storage/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-dynamodb/CHANGELOG.md +150 -0
- package/packages/shopify-app-session-storage-dynamodb/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-dynamodb/README.md +75 -0
- package/packages/shopify-app-session-storage-dynamodb/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-dynamodb/package.json +51 -0
- package/packages/shopify-app-session-storage-dynamodb/src/__tests__/dynamodb.test.ts +93 -0
- package/packages/shopify-app-session-storage-dynamodb/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-dynamodb/src/dynamodb.ts +126 -0
- package/packages/shopify-app-session-storage-dynamodb/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-kv/CHANGELOG.md +204 -0
- package/packages/shopify-app-session-storage-kv/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-kv/README.md +41 -0
- package/packages/shopify-app-session-storage-kv/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-kv/package.json +52 -0
- package/packages/shopify-app-session-storage-kv/src/__tests__/kv-namespace-dummy-worker.ts +8 -0
- package/packages/shopify-app-session-storage-kv/src/__tests__/kv.test.ts +22 -0
- package/packages/shopify-app-session-storage-kv/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-kv/src/kv.ts +87 -0
- package/packages/shopify-app-session-storage-kv/tsconfig.json +11 -0
- package/packages/shopify-app-session-storage-memory/CHANGELOG.md +190 -0
- package/packages/shopify-app-session-storage-memory/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-memory/README.md +19 -0
- package/packages/shopify-app-session-storage-memory/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-memory/package.json +46 -0
- package/packages/shopify-app-session-storage-memory/src/__tests__/memory.test.ts +12 -0
- package/packages/shopify-app-session-storage-memory/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-memory/src/memory.ts +34 -0
- package/packages/shopify-app-session-storage-memory/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-mongodb/CHANGELOG.md +208 -0
- package/packages/shopify-app-session-storage-mongodb/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-mongodb/README.md +30 -0
- package/packages/shopify-app-session-storage-mongodb/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-mongodb/package.json +49 -0
- package/packages/shopify-app-session-storage-mongodb/src/__tests__/mongodb.test.ts +54 -0
- package/packages/shopify-app-session-storage-mongodb/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-mongodb/src/mongodb.ts +120 -0
- package/packages/shopify-app-session-storage-mongodb/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-mysql/CHANGELOG.md +220 -0
- package/packages/shopify-app-session-storage-mysql/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-mysql/README.md +41 -0
- package/packages/shopify-app-session-storage-mysql/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-mysql/package.json +50 -0
- package/packages/shopify-app-session-storage-mysql/src/__tests__/mysql.test.ts +137 -0
- package/packages/shopify-app-session-storage-mysql/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-mysql/src/migrations.ts +18 -0
- package/packages/shopify-app-session-storage-mysql/src/mysql-connection.ts +108 -0
- package/packages/shopify-app-session-storage-mysql/src/mysql-migrator.ts +53 -0
- package/packages/shopify-app-session-storage-mysql/src/mysql.ts +178 -0
- package/packages/shopify-app-session-storage-mysql/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-postgresql/CHANGELOG.md +210 -0
- package/packages/shopify-app-session-storage-postgresql/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-postgresql/README.md +39 -0
- package/packages/shopify-app-session-storage-postgresql/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-postgresql/package.json +52 -0
- package/packages/shopify-app-session-storage-postgresql/src/__tests__/migrate-to-case-sensitivity.test.ts +344 -0
- package/packages/shopify-app-session-storage-postgresql/src/__tests__/postgresql.test.ts +136 -0
- package/packages/shopify-app-session-storage-postgresql/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-postgresql/src/migrations.ts +70 -0
- package/packages/shopify-app-session-storage-postgresql/src/postgres-connection.ts +94 -0
- package/packages/shopify-app-session-storage-postgresql/src/postgres-migrator.ts +27 -0
- package/packages/shopify-app-session-storage-postgresql/src/postgresql.ts +178 -0
- package/packages/shopify-app-session-storage-postgresql/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-prisma/CHANGELOG.md +148 -0
- package/packages/shopify-app-session-storage-prisma/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-prisma/README.md +68 -0
- package/packages/shopify-app-session-storage-prisma/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-prisma/package.json +51 -0
- package/packages/shopify-app-session-storage-prisma/prisma/migrations/20230425184828_init/migration.sql +11 -0
- package/packages/shopify-app-session-storage-prisma/prisma/migrations/20230906155758_mySession/migration.sql +11 -0
- package/packages/shopify-app-session-storage-prisma/prisma/migrations/migration_lock.toml +3 -0
- package/packages/shopify-app-session-storage-prisma/prisma/schema.prisma +30 -0
- package/packages/shopify-app-session-storage-prisma/src/__tests__/prisma.test.ts +66 -0
- package/packages/shopify-app-session-storage-prisma/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-prisma/src/prisma.ts +145 -0
- package/packages/shopify-app-session-storage-prisma/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-redis/CHANGELOG.md +200 -0
- package/packages/shopify-app-session-storage-redis/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-redis/README.md +38 -0
- package/packages/shopify-app-session-storage-redis/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-redis/package.json +50 -0
- package/packages/shopify-app-session-storage-redis/src/__tests__/migration-test-data.ts +46 -0
- package/packages/shopify-app-session-storage-redis/src/__tests__/redis.conf +2 -0
- package/packages/shopify-app-session-storage-redis/src/__tests__/redis.test.ts +236 -0
- package/packages/shopify-app-session-storage-redis/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-redis/src/migrations.ts +36 -0
- package/packages/shopify-app-session-storage-redis/src/redis-connection.ts +64 -0
- package/packages/shopify-app-session-storage-redis/src/redis-migrator.ts +58 -0
- package/packages/shopify-app-session-storage-redis/src/redis.ts +167 -0
- package/packages/shopify-app-session-storage-redis/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-sqlite/CHANGELOG.md +202 -0
- package/packages/shopify-app-session-storage-sqlite/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-sqlite/README.md +25 -0
- package/packages/shopify-app-session-storage-sqlite/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-sqlite/package.json +51 -0
- package/packages/shopify-app-session-storage-sqlite/src/__tests__/setup-jest.ts +8 -0
- package/packages/shopify-app-session-storage-sqlite/src/__tests__/sqlite.test.ts +44 -0
- package/packages/shopify-app-session-storage-sqlite/src/migrations.ts +54 -0
- package/packages/shopify-app-session-storage-sqlite/src/sqlite-connection.ts +80 -0
- package/packages/shopify-app-session-storage-sqlite/src/sqlite-migrator.ts +34 -0
- package/packages/shopify-app-session-storage-sqlite/src/sqlite.ts +147 -0
- package/packages/shopify-app-session-storage-sqlite/tsconfig.json +10 -0
- package/packages/shopify-app-session-storage-test-utils/CHANGELOG.md +185 -0
- package/packages/shopify-app-session-storage-test-utils/LICENSE.md +9 -0
- package/packages/shopify-app-session-storage-test-utils/loom.config.ts +27 -0
- package/packages/shopify-app-session-storage-test-utils/package.json +48 -0
- package/packages/shopify-app-session-storage-test-utils/src/__tests__/session-test-utils.test.ts +273 -0
- package/packages/shopify-app-session-storage-test-utils/src/battery-of-tests.ts +250 -0
- package/packages/shopify-app-session-storage-test-utils/src/index.ts +2 -0
- package/packages/shopify-app-session-storage-test-utils/src/session-test-utils.ts +24 -0
- package/packages/shopify-app-session-storage-test-utils/src/utils.ts +71 -0
- package/packages/shopify-app-session-storage-test-utils/tsconfig.json +10 -0
- package/tests/setup/build.js +1 -0
- package/tests/setup/setup-jest.ts +8 -0
- package/tsconfig.base.json +41 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import {Session} from '@shopify/shopify-api';
|
|
4
|
+
|
|
5
|
+
import {shopify, SHOPIFY_HOST, TEST_SHOP} from '../../__tests__/test-helper';
|
|
6
|
+
// import {ShopifyApp, shopifyApp} from '../../index';
|
|
7
|
+
|
|
8
|
+
const TESTS: {
|
|
9
|
+
isEmbeddedApp: boolean;
|
|
10
|
+
expectedCSP: string;
|
|
11
|
+
shop: any;
|
|
12
|
+
}[] = [];
|
|
13
|
+
|
|
14
|
+
[true, false].forEach((isEmbeddedApp) => {
|
|
15
|
+
[TEST_SHOP, 12345, undefined].forEach((shop) => {
|
|
16
|
+
let expectedCSP = `frame-ancestors 'none';`;
|
|
17
|
+
if (isEmbeddedApp && typeof shop === 'string') {
|
|
18
|
+
expectedCSP = `frame-ancestors https://${shop} https://admin.shopify.com https://*.spin.dev;`;
|
|
19
|
+
}
|
|
20
|
+
TESTS.push({shop, isEmbeddedApp, expectedCSP});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('cspHeaders', () => {
|
|
25
|
+
let session: Session;
|
|
26
|
+
let app: express.Express;
|
|
27
|
+
const htmlPage =
|
|
28
|
+
'<html><head></head><body><h1>Hello, World!</h1></body></html>';
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
app = express();
|
|
32
|
+
app.use('/*', shopify.cspHeaders());
|
|
33
|
+
app.get('/', async (_req, res) => {
|
|
34
|
+
res.send(htmlPage);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
session = new Session({
|
|
38
|
+
id: '123-this-is-a-session-id',
|
|
39
|
+
shop: TEST_SHOP,
|
|
40
|
+
state: '123-this-is-a-state',
|
|
41
|
+
isOnline: shopify.config.useOnlineTokens,
|
|
42
|
+
scope: shopify.api.config.scopes.toString(),
|
|
43
|
+
expires: undefined,
|
|
44
|
+
accessToken: 'totally-real-access-token',
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
TESTS.forEach((config) => {
|
|
49
|
+
it(`sets correct CSP header for ${JSON.stringify(config)}`, async () => {
|
|
50
|
+
shopify.api.config.isEmbeddedApp = config.isEmbeddedApp;
|
|
51
|
+
|
|
52
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
53
|
+
|
|
54
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
55
|
+
let shopParam = '';
|
|
56
|
+
if (config.shop) {
|
|
57
|
+
shopParam = `shop=${config.shop}`;
|
|
58
|
+
}
|
|
59
|
+
const response = await request(app)
|
|
60
|
+
.get(`/?${shopParam}&host=${encodedHost}&embedded=1`)
|
|
61
|
+
.expect(200);
|
|
62
|
+
|
|
63
|
+
expect(response.text).toEqual(htmlPage);
|
|
64
|
+
expect(response.headers['content-security-policy']).toEqual(
|
|
65
|
+
config.expectedCSP,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
package/packages/shopify-app-express/src/middlewares/__tests__/ensure-installed-on-shop.test.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import express, {Express} from 'express';
|
|
3
|
+
import {LATEST_API_VERSION, LogSeverity, Session} from '@shopify/shopify-api';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
createTestHmac,
|
|
7
|
+
mockShopifyResponse,
|
|
8
|
+
shopify,
|
|
9
|
+
SHOPIFY_HOST,
|
|
10
|
+
TEST_SHOP,
|
|
11
|
+
} from '../../__tests__/test-helper';
|
|
12
|
+
|
|
13
|
+
describe('ensureInstalledOnShop', () => {
|
|
14
|
+
let app: Express;
|
|
15
|
+
let session: Session;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
app = express();
|
|
19
|
+
app.use('/test/*', shopify.ensureInstalledOnShop());
|
|
20
|
+
app.get('/test/shop', async (req, res) => {
|
|
21
|
+
res.json({data: {shop: {name: req.query.shop}}});
|
|
22
|
+
});
|
|
23
|
+
session = new Session({
|
|
24
|
+
id: `offline_${TEST_SHOP}`,
|
|
25
|
+
shop: TEST_SHOP,
|
|
26
|
+
state: '123-this-is-a-state',
|
|
27
|
+
isOnline: false,
|
|
28
|
+
scope: shopify.api.config.scopes.toString(),
|
|
29
|
+
expires: undefined,
|
|
30
|
+
accessToken: 'totally-real-access-token',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('proceeds to process request if embedded app is installed', async () => {
|
|
35
|
+
mockShopifyResponse({data: {shop: {name: TEST_SHOP}}});
|
|
36
|
+
|
|
37
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
38
|
+
|
|
39
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
40
|
+
const response = await request(app)
|
|
41
|
+
.get(`/test/shop?shop=${TEST_SHOP}&host=${encodedHost}&embedded=1`)
|
|
42
|
+
.expect(200);
|
|
43
|
+
|
|
44
|
+
expect(response.body).toEqual({
|
|
45
|
+
data: {
|
|
46
|
+
shop: {
|
|
47
|
+
name: TEST_SHOP,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
expect(response.headers['content-security-policy']).toEqual(
|
|
52
|
+
`frame-ancestors https://${TEST_SHOP} https://admin.shopify.com https://*.spin.dev;`,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('returns 400 if no shop provided', async () => {
|
|
57
|
+
await request(app).get(`/test/shop`).expect(400);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns 422 if invalid shop provided', async () => {
|
|
61
|
+
await request(app).get(`/test/shop?shop=invalid-shop`).expect(422);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('returns 400 if no host provided', async () => {
|
|
65
|
+
mockShopifyResponse({data: {shop: {name: TEST_SHOP}}});
|
|
66
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
67
|
+
|
|
68
|
+
await request(app).get(`/test/shop?shop=${TEST_SHOP}`).expect(400);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('redirects to auth via exit iFrame if shop NOT installed', async () => {
|
|
72
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
73
|
+
const response = await request(app)
|
|
74
|
+
.get(`/test/shop?shop=${TEST_SHOP}&host=${encodedHost}&embedded=1`)
|
|
75
|
+
.expect(302);
|
|
76
|
+
|
|
77
|
+
const expectedRedirectUriStart = new URL(
|
|
78
|
+
shopify.config.auth.path,
|
|
79
|
+
`${shopify.api.config.hostScheme}://${shopify.api.config.hostName}`,
|
|
80
|
+
);
|
|
81
|
+
const location = new URL(response.header.location, 'https://example.com');
|
|
82
|
+
const locationParams = location.searchParams;
|
|
83
|
+
|
|
84
|
+
expect(location.pathname).toBe(shopify.config.exitIframePath);
|
|
85
|
+
expect(locationParams.get('shop')).toBe(TEST_SHOP);
|
|
86
|
+
expect(locationParams.get('host')).toBe(encodedHost);
|
|
87
|
+
expect(locationParams.get('redirectUri')).toEqual(
|
|
88
|
+
expect.stringMatching(expectedRedirectUriStart.href),
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('redirects to auth if not installed and not embedded', async () => {
|
|
93
|
+
mockShopifyResponse({data: {shop: {name: TEST_SHOP}}});
|
|
94
|
+
|
|
95
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
96
|
+
|
|
97
|
+
const missingShop = 'some-other-shop.myshopify.io';
|
|
98
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
99
|
+
const response = await request(app)
|
|
100
|
+
.get(`/test/shop?shop=${missingShop}&host=${encodedHost}`)
|
|
101
|
+
.expect(302);
|
|
102
|
+
|
|
103
|
+
const location = new URL(response.header.location);
|
|
104
|
+
|
|
105
|
+
expect(location.host).toBe(missingShop);
|
|
106
|
+
expect(location.pathname).toBe('/admin/oauth/authorize');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('redirects to auth if installed and not embedded, but token is invalid', async () => {
|
|
110
|
+
mockShopifyResponse({errors: 'Invalid token'}, {status: 401});
|
|
111
|
+
|
|
112
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
113
|
+
|
|
114
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
115
|
+
const response = await request(app)
|
|
116
|
+
.get(`/test/shop?shop=${TEST_SHOP}&host=${encodedHost}`)
|
|
117
|
+
.expect(302);
|
|
118
|
+
|
|
119
|
+
const location = new URL(response.header.location);
|
|
120
|
+
|
|
121
|
+
expect(location.host).toBe(TEST_SHOP);
|
|
122
|
+
expect(location.pathname).toBe('/admin/oauth/authorize');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('does NOT redirect to auth if shop NOT installed AND url is exit iFrame path', async () => {
|
|
126
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
127
|
+
app.use('/exitiframe', shopify.ensureInstalledOnShop());
|
|
128
|
+
app.get('/exitiframe', async (_req, res) => {
|
|
129
|
+
res.send('exit iFrame');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await request(app)
|
|
133
|
+
.get(`/exitiframe?shop=${TEST_SHOP}&host=${encodedHost}&embedded=1`)
|
|
134
|
+
.expect(200);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('redirects to embedded URL if shop is installed AND url is exit iFrame path AND embedded param missing', async () => {
|
|
138
|
+
mockShopifyResponse({data: {shop: {name: TEST_SHOP}}});
|
|
139
|
+
|
|
140
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
141
|
+
|
|
142
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
143
|
+
app.use('/exitiframe', shopify.ensureInstalledOnShop());
|
|
144
|
+
app.get('/exitiframe', async (_req, res) => {
|
|
145
|
+
res.send('exit iFrame');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const response = await request(app)
|
|
149
|
+
.get(`/exitiframe?shop=${TEST_SHOP}&host=${encodedHost}`)
|
|
150
|
+
.expect(302);
|
|
151
|
+
|
|
152
|
+
const location = new URL(response.header.location, 'https://example.com');
|
|
153
|
+
|
|
154
|
+
expect(location.hostname).toBe(SHOPIFY_HOST);
|
|
155
|
+
expect(location.pathname).toEqual(
|
|
156
|
+
expect.stringContaining(`apps/${shopify.api.config.apiKey}`),
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('calls validateAuthenticatedSession for non-embedded apps with a log', async () => {
|
|
161
|
+
shopify.api.config.isEmbeddedApp = false;
|
|
162
|
+
const validCookies = [
|
|
163
|
+
`shopify_app_session=${session.id}`,
|
|
164
|
+
`shopify_app_session.sig=${createTestHmac(
|
|
165
|
+
shopify.api.config.apiSecretKey,
|
|
166
|
+
session.id,
|
|
167
|
+
)}`,
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
mockShopifyResponse({
|
|
171
|
+
data: {},
|
|
172
|
+
extensions: {},
|
|
173
|
+
});
|
|
174
|
+
await shopify.config.sessionStorage.storeSession(session);
|
|
175
|
+
|
|
176
|
+
await request(app)
|
|
177
|
+
.get(`/test/shop`)
|
|
178
|
+
.set('Cookie', validCookies)
|
|
179
|
+
.expect(200);
|
|
180
|
+
|
|
181
|
+
expect({
|
|
182
|
+
method: 'POST',
|
|
183
|
+
url: `https://test-shop.myshopify.io/admin/api/${LATEST_API_VERSION}/graphql.json`,
|
|
184
|
+
}).toMatchMadeHttpRequest();
|
|
185
|
+
|
|
186
|
+
expect(shopify.api.config.logger.log).toHaveBeenCalledWith(
|
|
187
|
+
LogSeverity.Warning,
|
|
188
|
+
expect.stringContaining(
|
|
189
|
+
'ensureInstalledOnShop() should only be used in embedded apps; calling validateAuthenticatedSession() instead',
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {Session} from '@shopify/shopify-api';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
|
|
5
|
+
import {redirectToShopifyOrAppRoot} from '../redirect-to-shopify-or-app-root';
|
|
6
|
+
import {
|
|
7
|
+
BASE64_HOST,
|
|
8
|
+
shopify,
|
|
9
|
+
SHOPIFY_HOST,
|
|
10
|
+
TEST_SHOP,
|
|
11
|
+
} from '../../__tests__/test-helper';
|
|
12
|
+
|
|
13
|
+
describe('redirectToShopifyOrAppRoot', () => {
|
|
14
|
+
const session = new Session({
|
|
15
|
+
id: 'session-id',
|
|
16
|
+
accessToken: 'access-token',
|
|
17
|
+
shop: TEST_SHOP,
|
|
18
|
+
isOnline: false,
|
|
19
|
+
state: '1234',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
let app: express.Express;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
app = express();
|
|
25
|
+
app.get(
|
|
26
|
+
'/redirect-to-host',
|
|
27
|
+
// Make sure the session is available
|
|
28
|
+
(req, res, next) => {
|
|
29
|
+
res.locals.shopify = {session};
|
|
30
|
+
next();
|
|
31
|
+
},
|
|
32
|
+
redirectToShopifyOrAppRoot({api: shopify.api, config: shopify.config})(),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('redirects to Shopify when embedded', async () => {
|
|
37
|
+
const host = BASE64_HOST;
|
|
38
|
+
const response = await request(app)
|
|
39
|
+
.get(`/redirect-to-host?host=${host}&embedded=1`)
|
|
40
|
+
.expect(302);
|
|
41
|
+
|
|
42
|
+
const url = new URL(response.header.location);
|
|
43
|
+
expect(url.host).toBe(SHOPIFY_HOST);
|
|
44
|
+
expect(url.pathname).toBe(`/apps/${shopify.api.config.apiKey}`);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('redirects to app when not embedded', async () => {
|
|
48
|
+
shopify.api.config.isEmbeddedApp = false;
|
|
49
|
+
|
|
50
|
+
const host = BASE64_HOST;
|
|
51
|
+
const response = await request(app)
|
|
52
|
+
.get(`/redirect-to-host?host=${host}&embedded=1`)
|
|
53
|
+
.expect(302);
|
|
54
|
+
|
|
55
|
+
expect(response.header.location).toBe(
|
|
56
|
+
`/?shop=${TEST_SHOP}&host=${encodeURIComponent(host)}`,
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import express, {Express} from 'express';
|
|
3
|
+
import {LATEST_API_VERSION, Session} from '@shopify/shopify-api';
|
|
4
|
+
import jwt from 'jsonwebtoken';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
createTestHmac,
|
|
8
|
+
mockShopifyResponse,
|
|
9
|
+
shopify,
|
|
10
|
+
SHOPIFY_HOST,
|
|
11
|
+
} from '../../__tests__/test-helper';
|
|
12
|
+
|
|
13
|
+
describe('validateAuthenticatedSession', () => {
|
|
14
|
+
let app: Express;
|
|
15
|
+
let session: Session;
|
|
16
|
+
const shop = 'my-shop.myshopify.io';
|
|
17
|
+
const sessionId = `offline_${shop}`;
|
|
18
|
+
|
|
19
|
+
describe('for embedded apps', () => {
|
|
20
|
+
let validJWT: any;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
shopify.config.auth.path = '/api/auth';
|
|
24
|
+
shopify.config.auth.callbackPath = '/api/auth/callback';
|
|
25
|
+
shopify.api.config.isEmbeddedApp = true;
|
|
26
|
+
|
|
27
|
+
app = express();
|
|
28
|
+
// Use a short timeout since everything here should be pretty quick. If you see a `socket hang up` error,
|
|
29
|
+
// it's probably because the timeout is too short.
|
|
30
|
+
app.use('*', (_req, res, next) => {
|
|
31
|
+
res.setTimeout(100);
|
|
32
|
+
next();
|
|
33
|
+
});
|
|
34
|
+
app.use('/test/*', shopify.validateAuthenticatedSession());
|
|
35
|
+
app.get('/test/shop', async (req, res) => {
|
|
36
|
+
res.json({data: {shop: {name: req.query.shop}}});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
validJWT = jwt.sign(
|
|
40
|
+
{
|
|
41
|
+
dummy: 'data',
|
|
42
|
+
aud: shopify.api.config.apiKey,
|
|
43
|
+
dest: `https://${shop}`,
|
|
44
|
+
},
|
|
45
|
+
shopify.api.config.apiSecretKey,
|
|
46
|
+
{
|
|
47
|
+
algorithm: 'HS256',
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
session = new Session({
|
|
52
|
+
id: sessionId,
|
|
53
|
+
shop,
|
|
54
|
+
state: '123-this-is-a-state',
|
|
55
|
+
isOnline: shopify.config.useOnlineTokens,
|
|
56
|
+
scope: shopify.api.config.scopes.toString(),
|
|
57
|
+
expires: undefined,
|
|
58
|
+
accessToken: 'totally-real-access-token',
|
|
59
|
+
});
|
|
60
|
+
shopify.config.sessionStorage.storeSession(session);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('active and valid session does not redirect', async () => {
|
|
64
|
+
mockShopifyResponse({data: {shop: {name: shop}}});
|
|
65
|
+
|
|
66
|
+
const response = await request(app)
|
|
67
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
68
|
+
.set('Authorization', `Bearer ${validJWT}`)
|
|
69
|
+
.expect(200);
|
|
70
|
+
|
|
71
|
+
expect(response.body).toEqual({
|
|
72
|
+
data: {
|
|
73
|
+
shop: {
|
|
74
|
+
name: shop,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('inactive session with auth header returns 403 with correct headers', async () => {
|
|
81
|
+
session.expires = new Date('2020-12-31T00:00:00');
|
|
82
|
+
|
|
83
|
+
const response = await request(app)
|
|
84
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
85
|
+
.set({Authorization: `Bearer ${validJWT}`})
|
|
86
|
+
.expect(403);
|
|
87
|
+
|
|
88
|
+
expect(
|
|
89
|
+
response.headers['x-shopify-api-request-failure-reauthorize'],
|
|
90
|
+
).toBe('1');
|
|
91
|
+
expect(
|
|
92
|
+
response.headers['x-shopify-api-request-failure-reauthorize-url'],
|
|
93
|
+
).toBe(`/api/auth?shop=my-shop.myshopify.io`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('no session, with auth header returns 403 with correct headers', async () => {
|
|
97
|
+
jest
|
|
98
|
+
.spyOn(shopify.api.session, 'getCurrentId')
|
|
99
|
+
.mockResolvedValueOnce(undefined);
|
|
100
|
+
|
|
101
|
+
const response = await request(app)
|
|
102
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
103
|
+
.set({Authorization: `Bearer ${validJWT}`})
|
|
104
|
+
.expect(403);
|
|
105
|
+
|
|
106
|
+
expect(
|
|
107
|
+
response.headers['x-shopify-api-request-failure-reauthorize'],
|
|
108
|
+
).toBe('1');
|
|
109
|
+
expect(
|
|
110
|
+
response.headers['x-shopify-api-request-failure-reauthorize-url'],
|
|
111
|
+
).toBe(`/api/auth?shop=my-shop.myshopify.io`);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('no session, no shop param, with auth header, returns 403 with correct headers', async () => {
|
|
115
|
+
jest
|
|
116
|
+
.spyOn(shopify.api.session, 'getCurrentId')
|
|
117
|
+
.mockResolvedValueOnce(undefined);
|
|
118
|
+
|
|
119
|
+
const response = await request(app)
|
|
120
|
+
.get('/test/shop')
|
|
121
|
+
.set({Authorization: `Bearer ${validJWT}`})
|
|
122
|
+
.expect(403);
|
|
123
|
+
|
|
124
|
+
expect(
|
|
125
|
+
response.headers['x-shopify-api-request-failure-reauthorize'],
|
|
126
|
+
).toBe('1');
|
|
127
|
+
expect(
|
|
128
|
+
response.headers['x-shopify-api-request-failure-reauthorize-url'],
|
|
129
|
+
).toBe(`/api/auth?shop=my-shop.myshopify.io`);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('no session, without auth header redirects to auth', async () => {
|
|
133
|
+
const response = await request(app)
|
|
134
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
135
|
+
.expect(302);
|
|
136
|
+
|
|
137
|
+
expect(response.header.location).toBe(
|
|
138
|
+
`/api/auth?shop=my-shop.myshopify.io`,
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('redirect to exit iFrame if different shop, embedded param set to 1', async () => {
|
|
143
|
+
const encodedHost = Buffer.from(SHOPIFY_HOST, 'utf-8').toString('base64');
|
|
144
|
+
const response = await request(app)
|
|
145
|
+
.get(
|
|
146
|
+
`/test/shop?shop=other-shop.myshopify.io&host=${encodedHost}&embedded=1`,
|
|
147
|
+
)
|
|
148
|
+
.expect(302);
|
|
149
|
+
|
|
150
|
+
const location = new URL(response.header.location, 'https://example.com');
|
|
151
|
+
const locationParams = location.searchParams;
|
|
152
|
+
|
|
153
|
+
expect(location.pathname).toBe(shopify.config.exitIframePath);
|
|
154
|
+
expect(locationParams.get('shop')).toBe('other-shop.myshopify.io');
|
|
155
|
+
expect(locationParams.get('host')).toBe(encodedHost);
|
|
156
|
+
expect(locationParams.get('redirectUri')).toEqual(
|
|
157
|
+
expect.stringMatching(shopify.config.auth.path),
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('redirects to auth if different shop, no embedded param', async () => {
|
|
162
|
+
const response = await request(app)
|
|
163
|
+
.get('/test/shop?shop=other-shop.myshopify.io')
|
|
164
|
+
.set('Authorization', `Bearer ${validJWT}`)
|
|
165
|
+
.expect(302);
|
|
166
|
+
|
|
167
|
+
const expectedRedirectUriStart = new URL(
|
|
168
|
+
shopify.config.auth.callbackPath,
|
|
169
|
+
`${shopify.api.config.hostScheme}://${shopify.api.config.hostName}`,
|
|
170
|
+
);
|
|
171
|
+
const location = new URL(response.header.location);
|
|
172
|
+
const locationParams = location.searchParams;
|
|
173
|
+
|
|
174
|
+
expect(location.hostname).toBe('other-shop.myshopify.io');
|
|
175
|
+
expect(location.pathname).toBe('/admin/oauth/authorize');
|
|
176
|
+
expect(locationParams.get('client_id')).toBe(shopify.api.config.apiKey);
|
|
177
|
+
expect(locationParams.get('scope')).toBe(
|
|
178
|
+
shopify.api.config.scopes.toString(),
|
|
179
|
+
);
|
|
180
|
+
expect(locationParams.get('redirect_uri')).toEqual(
|
|
181
|
+
expect.stringMatching(expectedRedirectUriStart.href),
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('session found, shops match, scopes differ, with auth header', async () => {
|
|
186
|
+
session.scope = 'read_products,read_draft_orders';
|
|
187
|
+
|
|
188
|
+
const response = await request(app)
|
|
189
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
190
|
+
.set({Authorization: `Bearer ${validJWT}`})
|
|
191
|
+
.expect(403);
|
|
192
|
+
|
|
193
|
+
expect(
|
|
194
|
+
response.headers['x-shopify-api-request-failure-reauthorize'],
|
|
195
|
+
).toBe('1');
|
|
196
|
+
expect(
|
|
197
|
+
response.headers['x-shopify-api-request-failure-reauthorize-url'],
|
|
198
|
+
).toBe(`/api/auth?shop=my-shop.myshopify.io`);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('returns a 401 if the session token is invalid', async () => {
|
|
202
|
+
const invalidJWT = jwt.sign(
|
|
203
|
+
{
|
|
204
|
+
dummy: 'data',
|
|
205
|
+
aud: shopify.api.config.apiKey,
|
|
206
|
+
dest: `https://${shop}`,
|
|
207
|
+
},
|
|
208
|
+
'different-secret-key',
|
|
209
|
+
{algorithm: 'HS256'},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const response = await request(app)
|
|
213
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
214
|
+
.set({Authorization: `Bearer ${invalidJWT}`})
|
|
215
|
+
.expect(401);
|
|
216
|
+
|
|
217
|
+
expect((response.error as any).text).toMatch(
|
|
218
|
+
'Failed to parse session token',
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('returns a 500 if the storage throws an error', async () => {
|
|
223
|
+
jest
|
|
224
|
+
.spyOn(shopify.config.sessionStorage, 'loadSession')
|
|
225
|
+
.mockRejectedValueOnce(new Error('Storage error'));
|
|
226
|
+
|
|
227
|
+
const response = await request(app)
|
|
228
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
229
|
+
.set({Authorization: `Bearer ${validJWT}`})
|
|
230
|
+
.expect(500);
|
|
231
|
+
|
|
232
|
+
expect((response.error as any).text).toBe('Storage error');
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('for non-embedded apps', () => {
|
|
237
|
+
let validCookies: string[];
|
|
238
|
+
|
|
239
|
+
beforeEach(() => {
|
|
240
|
+
shopify.api.config.isEmbeddedApp = false;
|
|
241
|
+
|
|
242
|
+
app = express();
|
|
243
|
+
app.use('/test/*', shopify.validateAuthenticatedSession());
|
|
244
|
+
app.get('/test/shop', async (req, res) => {
|
|
245
|
+
res.json({data: {shop: {name: req.query.shop}}});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
validCookies = [
|
|
249
|
+
`shopify_app_session=${sessionId}`,
|
|
250
|
+
`shopify_app_session.sig=${createTestHmac(
|
|
251
|
+
shopify.api.config.apiSecretKey,
|
|
252
|
+
sessionId,
|
|
253
|
+
)}`,
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
session = new Session({
|
|
257
|
+
id: sessionId,
|
|
258
|
+
shop: 'my-shop.myshopify.io',
|
|
259
|
+
state: '123-this-is-a-state',
|
|
260
|
+
isOnline: shopify.config.useOnlineTokens,
|
|
261
|
+
scope: shopify.api.config.scopes.toString(),
|
|
262
|
+
expires: undefined,
|
|
263
|
+
accessToken: 'totally-real-access-token',
|
|
264
|
+
});
|
|
265
|
+
shopify.config.sessionStorage.storeSession(session);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('finds a session with the right cookie', async () => {
|
|
269
|
+
mockShopifyResponse({
|
|
270
|
+
data: {},
|
|
271
|
+
extensions: {},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const response = await request(app)
|
|
275
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
276
|
+
.set('Cookie', validCookies)
|
|
277
|
+
.expect(200);
|
|
278
|
+
|
|
279
|
+
expect({
|
|
280
|
+
method: 'POST',
|
|
281
|
+
url: `https://my-shop.myshopify.io/admin/api/${LATEST_API_VERSION}/graphql.json`,
|
|
282
|
+
}).toMatchMadeHttpRequest();
|
|
283
|
+
|
|
284
|
+
expect(response.body).toEqual({
|
|
285
|
+
data: {
|
|
286
|
+
shop: {
|
|
287
|
+
name: 'my-shop.myshopify.io',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('fails to find a session if there is no signature', async () => {
|
|
294
|
+
const response = await request(app)
|
|
295
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
296
|
+
.set('Cookie', [validCookies[0]])
|
|
297
|
+
.expect(302);
|
|
298
|
+
|
|
299
|
+
expect(response.header.location).toBe(`/auth?shop=my-shop.myshopify.io`);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('returns a 403 with the authentication header in XHR requests', async () => {
|
|
303
|
+
session.expires = new Date('2020-12-31T00:00:00');
|
|
304
|
+
|
|
305
|
+
const response = await request(app)
|
|
306
|
+
.get('/test/shop?shop=my-shop.myshopify.io')
|
|
307
|
+
.set('Cookie', validCookies)
|
|
308
|
+
.set('X-Requested-With', 'XMLHttpRequest')
|
|
309
|
+
.expect(403);
|
|
310
|
+
|
|
311
|
+
expect(
|
|
312
|
+
response.headers['x-shopify-api-request-failure-reauthorize'],
|
|
313
|
+
).toBe('1');
|
|
314
|
+
expect(
|
|
315
|
+
response.headers['x-shopify-api-request-failure-reauthorize-url'],
|
|
316
|
+
).toBe(`${shopify.config.auth.path}?shop=my-shop.myshopify.io`);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Request, Response, NextFunction} from 'express';
|
|
2
|
+
import {Shopify} from '@shopify/shopify-api';
|
|
3
|
+
|
|
4
|
+
import {CspHeadersMiddleware} from './types';
|
|
5
|
+
|
|
6
|
+
interface CspHeadersParams {
|
|
7
|
+
api: Shopify;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function cspHeaders({api}: CspHeadersParams): CspHeadersMiddleware {
|
|
11
|
+
return function cspHeaders() {
|
|
12
|
+
return async (req: Request, res: Response, next: NextFunction) => {
|
|
13
|
+
addCSPHeader(api, req, res);
|
|
14
|
+
next();
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function addCSPHeader(api: Shopify, req: Request, res: Response) {
|
|
20
|
+
const shop = api.utils.sanitizeShop(req.query.shop as string);
|
|
21
|
+
if (api.config.isEmbeddedApp && shop) {
|
|
22
|
+
res.setHeader(
|
|
23
|
+
'Content-Security-Policy',
|
|
24
|
+
`frame-ancestors https://${encodeURIComponent(
|
|
25
|
+
shop,
|
|
26
|
+
)} https://admin.shopify.com https://*.spin.dev;`,
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
res.setHeader('Content-Security-Policy', `frame-ancestors 'none';`);
|
|
30
|
+
}
|
|
31
|
+
}
|