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,310 @@
|
|
|
1
|
+
import {Session} from '@shopify/shopify-api';
|
|
2
|
+
|
|
3
|
+
import {shopifyApp} from '../../../../..';
|
|
4
|
+
import {
|
|
5
|
+
API_KEY,
|
|
6
|
+
API_SECRET_KEY,
|
|
7
|
+
APP_URL,
|
|
8
|
+
BASE64_HOST,
|
|
9
|
+
TEST_SHOP,
|
|
10
|
+
getJwt,
|
|
11
|
+
getThrownResponse,
|
|
12
|
+
mockExternalRequest,
|
|
13
|
+
setUpValidSession,
|
|
14
|
+
testConfig,
|
|
15
|
+
} from '../../../../../__test-helpers';
|
|
16
|
+
|
|
17
|
+
const USER_ID = 902541635;
|
|
18
|
+
|
|
19
|
+
describe('authenticate', () => {
|
|
20
|
+
it('performs token exchange when there is no offline session', async () => {
|
|
21
|
+
// GIVEN
|
|
22
|
+
const config = testConfig();
|
|
23
|
+
const shopify = shopifyApp(config);
|
|
24
|
+
|
|
25
|
+
const {token} = getJwt();
|
|
26
|
+
await mockTokenExchangeRequest(token, 'offline');
|
|
27
|
+
|
|
28
|
+
// WHEN
|
|
29
|
+
const {session} = await shopify.authenticate.admin(
|
|
30
|
+
new Request(
|
|
31
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// THEN
|
|
36
|
+
const [persistedSession] =
|
|
37
|
+
await config.sessionStorage.findSessionsByShop(TEST_SHOP);
|
|
38
|
+
|
|
39
|
+
expect(persistedSession).toEqual(session);
|
|
40
|
+
expect(session).toMatchObject({
|
|
41
|
+
accessToken: '123abc-exchanged-from-session-token',
|
|
42
|
+
id: `offline_${TEST_SHOP}`,
|
|
43
|
+
isOnline: false,
|
|
44
|
+
scope: 'read_orders',
|
|
45
|
+
shop: TEST_SHOP,
|
|
46
|
+
state: '',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('performs token exchange when existing session is no longer valid', async () => {
|
|
51
|
+
// GIVEN
|
|
52
|
+
const config = testConfig({useOnlineTokens: true});
|
|
53
|
+
const shopify = shopifyApp(config);
|
|
54
|
+
const anHourAgo = new Date(Date.now() - 1000 * 3600);
|
|
55
|
+
await setUpValidSession(shopify.sessionStorage, {
|
|
56
|
+
isOnline: true,
|
|
57
|
+
expires: anHourAgo,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const {token} = getJwt();
|
|
61
|
+
await mockTokenExchangeRequest(token, 'offline');
|
|
62
|
+
await mockTokenExchangeRequest(token, 'online');
|
|
63
|
+
|
|
64
|
+
// WHEN
|
|
65
|
+
const {session} = await shopify.authenticate.admin(
|
|
66
|
+
new Request(
|
|
67
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// THEN
|
|
72
|
+
const [_, onlineSession] =
|
|
73
|
+
await config.sessionStorage.findSessionsByShop(TEST_SHOP);
|
|
74
|
+
|
|
75
|
+
expect(onlineSession).toEqual(session);
|
|
76
|
+
expect(session).toMatchObject({
|
|
77
|
+
accessToken: '123abc-exchanged-from-session-token',
|
|
78
|
+
id: `${TEST_SHOP}_${USER_ID}`,
|
|
79
|
+
isOnline: true,
|
|
80
|
+
scope: 'read_orders',
|
|
81
|
+
shop: TEST_SHOP,
|
|
82
|
+
state: '',
|
|
83
|
+
onlineAccessInfo: expect.any(Object),
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe.each([true, false])(
|
|
88
|
+
'existing sessions when isOnline: %s',
|
|
89
|
+
(isOnline) => {
|
|
90
|
+
it('returns the context if the session is valid', async () => {
|
|
91
|
+
// GIVEN
|
|
92
|
+
const shopify = shopifyApp(testConfig({useOnlineTokens: isOnline}));
|
|
93
|
+
|
|
94
|
+
let testSession: Session;
|
|
95
|
+
testSession = await setUpValidSession(shopify.sessionStorage);
|
|
96
|
+
if (isOnline) {
|
|
97
|
+
testSession = await setUpValidSession(shopify.sessionStorage, {
|
|
98
|
+
isOnline,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// WHEN
|
|
103
|
+
const {token} = getJwt();
|
|
104
|
+
const {admin, session} = await shopify.authenticate.admin(
|
|
105
|
+
new Request(
|
|
106
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// THEN
|
|
111
|
+
expect(session).toBe(testSession);
|
|
112
|
+
expect(admin.rest.session).toBe(testSession);
|
|
113
|
+
expect(session.isOnline).toEqual(isOnline);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
test('redirects to bounce page on document request when receiving an invalid subject token response from token exchange API', async () => {
|
|
119
|
+
// GIVEN
|
|
120
|
+
const config = testConfig();
|
|
121
|
+
const shopify = shopifyApp(config);
|
|
122
|
+
|
|
123
|
+
const {token} = getJwt();
|
|
124
|
+
await mockInvalidTokenExchangeRequest('invalid_subject_token');
|
|
125
|
+
|
|
126
|
+
// WHEN
|
|
127
|
+
const response = await getThrownResponse(
|
|
128
|
+
shopify.authenticate.admin,
|
|
129
|
+
new Request(
|
|
130
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
// THEN
|
|
135
|
+
const {pathname, searchParams} = new URL(
|
|
136
|
+
response.headers.get('location')!,
|
|
137
|
+
APP_URL,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(response.status).toBe(302);
|
|
141
|
+
expect(pathname).toBe('/auth/session-token');
|
|
142
|
+
expect(searchParams.get('shop')).toBe(TEST_SHOP);
|
|
143
|
+
expect(searchParams.get('host')).toBe(BASE64_HOST);
|
|
144
|
+
expect(searchParams.get('shopify-reload')).toBe(
|
|
145
|
+
`${APP_URL}/?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('throws 401 unauthorized on XHR request when receiving an invalid subject token response from token exchange API', async () => {
|
|
150
|
+
// GIVEN
|
|
151
|
+
const config = testConfig();
|
|
152
|
+
const shopify = shopifyApp(config);
|
|
153
|
+
|
|
154
|
+
const {token} = getJwt();
|
|
155
|
+
await mockInvalidTokenExchangeRequest('invalid_subject_token');
|
|
156
|
+
|
|
157
|
+
// WHEN
|
|
158
|
+
const response = await getThrownResponse(
|
|
159
|
+
shopify.authenticate.admin,
|
|
160
|
+
new Request(APP_URL, {
|
|
161
|
+
headers: {
|
|
162
|
+
Authorization: `Bearer ${token}`,
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// THEN
|
|
168
|
+
expect(response.status).toBe(401);
|
|
169
|
+
expect(
|
|
170
|
+
response.headers.get('X-Shopify-Retry-Invalid-Session-Request'),
|
|
171
|
+
).toEqual('1');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('throws 500 for any other error from token exchange API', async () => {
|
|
175
|
+
// GIVEN
|
|
176
|
+
const config = testConfig();
|
|
177
|
+
const shopify = shopifyApp(config);
|
|
178
|
+
|
|
179
|
+
const {token} = getJwt();
|
|
180
|
+
await mockInvalidTokenExchangeRequest('im_broke', 401);
|
|
181
|
+
|
|
182
|
+
// WHEN
|
|
183
|
+
const response = await getThrownResponse(
|
|
184
|
+
shopify.authenticate.admin,
|
|
185
|
+
new Request(APP_URL, {
|
|
186
|
+
headers: {
|
|
187
|
+
Authorization: `Bearer ${token}`,
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// THEN
|
|
193
|
+
expect(response.status).toBe(500);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('throws a 500 if afterAuth hook throws an error', async () => {
|
|
197
|
+
// GIVEN
|
|
198
|
+
const config = testConfig();
|
|
199
|
+
const shopify = shopifyApp({
|
|
200
|
+
...config,
|
|
201
|
+
hooks: {
|
|
202
|
+
afterAuth: () => {
|
|
203
|
+
throw new Error('test');
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const {token} = getJwt();
|
|
209
|
+
await mockTokenExchangeRequest(token, 'offline');
|
|
210
|
+
|
|
211
|
+
// WHEN
|
|
212
|
+
const response = await getThrownResponse(
|
|
213
|
+
shopify.authenticate.admin,
|
|
214
|
+
new Request(
|
|
215
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// THEN
|
|
220
|
+
expect(response.status).toBe(500);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('Runs the afterAuth hooks passing', async () => {
|
|
224
|
+
// GIVEN
|
|
225
|
+
const afterAuthMock = jest.fn();
|
|
226
|
+
const config = testConfig({
|
|
227
|
+
hooks: {
|
|
228
|
+
afterAuth: afterAuthMock,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
const shopify = shopifyApp(config);
|
|
232
|
+
|
|
233
|
+
const {token} = getJwt();
|
|
234
|
+
await mockTokenExchangeRequest(token, 'offline');
|
|
235
|
+
|
|
236
|
+
// WHEN
|
|
237
|
+
const {session} = await shopify.authenticate.admin(
|
|
238
|
+
new Request(
|
|
239
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// THEN
|
|
244
|
+
expect(session).toBeDefined();
|
|
245
|
+
expect(afterAuthMock).toHaveBeenCalledTimes(1);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
async function mockTokenExchangeRequest(
|
|
250
|
+
sessionToken,
|
|
251
|
+
tokenType: 'online' | 'offline' = 'offline',
|
|
252
|
+
) {
|
|
253
|
+
const responseBody = {
|
|
254
|
+
access_token: '123abc-exchanged-from-session-token',
|
|
255
|
+
scope: 'read_orders',
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
await mockExternalRequest({
|
|
259
|
+
request: new Request(`https://${TEST_SHOP}/admin/oauth/access_token`, {
|
|
260
|
+
method: 'POST',
|
|
261
|
+
body: JSON.stringify({
|
|
262
|
+
client_id: API_KEY,
|
|
263
|
+
client_secret: API_SECRET_KEY,
|
|
264
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
|
|
265
|
+
subject_token: sessionToken,
|
|
266
|
+
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token',
|
|
267
|
+
requested_token_type:
|
|
268
|
+
tokenType === 'offline'
|
|
269
|
+
? 'urn:shopify:params:oauth:token-type:offline-access-token'
|
|
270
|
+
: 'urn:shopify:params:oauth:token-type:online-access-token',
|
|
271
|
+
}),
|
|
272
|
+
}),
|
|
273
|
+
response:
|
|
274
|
+
tokenType === 'offline'
|
|
275
|
+
? new Response(JSON.stringify(responseBody))
|
|
276
|
+
: new Response(
|
|
277
|
+
JSON.stringify({
|
|
278
|
+
...responseBody,
|
|
279
|
+
expires_in: Math.trunc(Date.now() / 1000) + 3600,
|
|
280
|
+
associated_user_scope: 'read_orders',
|
|
281
|
+
associated_user: {
|
|
282
|
+
id: USER_ID,
|
|
283
|
+
first_name: 'John',
|
|
284
|
+
last_name: 'Smith',
|
|
285
|
+
email: 'john@example.com',
|
|
286
|
+
email_verified: true,
|
|
287
|
+
account_owner: true,
|
|
288
|
+
locale: 'en',
|
|
289
|
+
collaborator: false,
|
|
290
|
+
},
|
|
291
|
+
}),
|
|
292
|
+
),
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function mockInvalidTokenExchangeRequest(error: string, status = 400) {
|
|
297
|
+
await mockExternalRequest({
|
|
298
|
+
request: new Request(`https://${TEST_SHOP}/admin/oauth/access_token`, {
|
|
299
|
+
method: 'POST',
|
|
300
|
+
}),
|
|
301
|
+
response: new Response(
|
|
302
|
+
JSON.stringify({
|
|
303
|
+
error,
|
|
304
|
+
}),
|
|
305
|
+
{
|
|
306
|
+
status,
|
|
307
|
+
},
|
|
308
|
+
),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CookieNotFound,
|
|
3
|
+
GraphqlQueryError,
|
|
4
|
+
HttpResponseError,
|
|
5
|
+
InvalidHmacError,
|
|
6
|
+
InvalidOAuthError,
|
|
7
|
+
Session,
|
|
8
|
+
Shopify,
|
|
9
|
+
ShopifyRestResources,
|
|
10
|
+
} from '@shopify/shopify-api';
|
|
11
|
+
|
|
12
|
+
import type {BasicParams} from '../../../types';
|
|
13
|
+
import {
|
|
14
|
+
beginAuth,
|
|
15
|
+
handleClientErrorFactory,
|
|
16
|
+
redirectToAuthPage,
|
|
17
|
+
redirectToShopifyOrAppRoot,
|
|
18
|
+
redirectWithExitIframe,
|
|
19
|
+
triggerAfterAuthHook,
|
|
20
|
+
validateShopAndHostParams,
|
|
21
|
+
} from '../helpers';
|
|
22
|
+
import {AppConfig, AppConfigArg} from '../../../config-types';
|
|
23
|
+
import {getSessionTokenHeader} from '../../helpers';
|
|
24
|
+
import {HandleAdminClientError} from '../../../clients';
|
|
25
|
+
import type {
|
|
26
|
+
ApiConfigWithFutureFlags,
|
|
27
|
+
ApiFutureFlags,
|
|
28
|
+
} from '../../../future/flags';
|
|
29
|
+
|
|
30
|
+
import {AuthorizationStrategy, SessionContext, OnErrorOptions} from './types';
|
|
31
|
+
|
|
32
|
+
export class AuthCodeFlowStrategy<
|
|
33
|
+
Config extends AppConfigArg,
|
|
34
|
+
Resources extends ShopifyRestResources = ShopifyRestResources,
|
|
35
|
+
> implements AuthorizationStrategy
|
|
36
|
+
{
|
|
37
|
+
protected api: Shopify<
|
|
38
|
+
ApiConfigWithFutureFlags<Config['future']>,
|
|
39
|
+
ShopifyRestResources,
|
|
40
|
+
ApiFutureFlags<Config['future']>
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
protected config: AppConfig;
|
|
44
|
+
protected logger: Shopify['logger'];
|
|
45
|
+
|
|
46
|
+
public constructor({api, config, logger}: BasicParams) {
|
|
47
|
+
this.api = api;
|
|
48
|
+
this.config = config;
|
|
49
|
+
this.logger = logger;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async respondToOAuthRequests(request: Request): Promise<void | never> {
|
|
53
|
+
const {api, config} = this;
|
|
54
|
+
|
|
55
|
+
const url = new URL(request.url);
|
|
56
|
+
const isAuthRequest = url.pathname === config.auth.path;
|
|
57
|
+
const isAuthCallbackRequest = url.pathname === config.auth.callbackPath;
|
|
58
|
+
|
|
59
|
+
if (isAuthRequest || isAuthCallbackRequest) {
|
|
60
|
+
const shop = api.utils.sanitizeShop(url.searchParams.get('shop')!);
|
|
61
|
+
if (!shop) throw new Response('Shop param is invalid', {status: 400});
|
|
62
|
+
|
|
63
|
+
if (isAuthRequest) {
|
|
64
|
+
throw await this.handleAuthBeginRequest(request, shop);
|
|
65
|
+
} else {
|
|
66
|
+
throw await this.handleAuthCallbackRequest(request, shop);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!getSessionTokenHeader(request)) {
|
|
71
|
+
// This is a document request that doesn't contain a session token. We check if the app is installed.
|
|
72
|
+
// If the app isn't installed, we initiate the OAuth auth code flow.
|
|
73
|
+
// Requests with a header can only happen after the app is installed.
|
|
74
|
+
await this.ensureInstalledOnShop(request);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public async authenticate(
|
|
79
|
+
request: Request,
|
|
80
|
+
sessionContext: SessionContext,
|
|
81
|
+
): Promise<Session | never> {
|
|
82
|
+
const {api, config, logger} = this;
|
|
83
|
+
|
|
84
|
+
const {shop, session} = sessionContext;
|
|
85
|
+
|
|
86
|
+
if (!session) {
|
|
87
|
+
logger.debug('No session found, redirecting to OAuth', {shop});
|
|
88
|
+
await redirectToAuthPage({config, logger, api}, request, shop);
|
|
89
|
+
} else if (!session.isActive(config.scopes)) {
|
|
90
|
+
logger.debug(
|
|
91
|
+
'Found a session, but it has expired, redirecting to OAuth',
|
|
92
|
+
{shop},
|
|
93
|
+
);
|
|
94
|
+
await redirectToAuthPage({config, logger, api}, request, shop);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
logger.debug('Found a valid session', {shop});
|
|
98
|
+
|
|
99
|
+
return session!;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public handleClientError(request: Request): HandleAdminClientError {
|
|
103
|
+
const {api, config, logger} = this;
|
|
104
|
+
return handleClientErrorFactory({
|
|
105
|
+
request,
|
|
106
|
+
onError: async ({session, error}: OnErrorOptions) => {
|
|
107
|
+
if (error.response.code === 401) {
|
|
108
|
+
throw await redirectToAuthPage(
|
|
109
|
+
{api, config, logger},
|
|
110
|
+
request,
|
|
111
|
+
session.shop,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private async ensureInstalledOnShop(request: Request) {
|
|
119
|
+
const {api, config, logger} = this;
|
|
120
|
+
|
|
121
|
+
validateShopAndHostParams({api, config, logger}, request);
|
|
122
|
+
|
|
123
|
+
const url = new URL(request.url);
|
|
124
|
+
let shop = url.searchParams.get('shop');
|
|
125
|
+
|
|
126
|
+
// Ensure app is installed
|
|
127
|
+
logger.debug('Ensuring app is installed on shop', {shop});
|
|
128
|
+
|
|
129
|
+
if (!(await this.hasValidOfflineId(request))) {
|
|
130
|
+
logger.info("Could not find a shop, can't authenticate request");
|
|
131
|
+
throw new Response(undefined, {
|
|
132
|
+
status: 400,
|
|
133
|
+
statusText: 'Bad Request',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const offlineSession = await this.getOfflineSession(request);
|
|
138
|
+
const isEmbedded = url.searchParams.get('embedded') === '1';
|
|
139
|
+
|
|
140
|
+
if (!offlineSession) {
|
|
141
|
+
logger.info("Shop hasn't installed app yet, redirecting to OAuth", {
|
|
142
|
+
shop,
|
|
143
|
+
});
|
|
144
|
+
if (isEmbedded) {
|
|
145
|
+
redirectWithExitIframe({api, config, logger}, request, shop!);
|
|
146
|
+
} else {
|
|
147
|
+
throw await beginAuth({api, config, logger}, request, false, shop!);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
shop = shop || offlineSession.shop;
|
|
152
|
+
|
|
153
|
+
if (config.isEmbeddedApp && !isEmbedded) {
|
|
154
|
+
try {
|
|
155
|
+
logger.debug('Ensuring offline session is valid before embedding', {
|
|
156
|
+
shop,
|
|
157
|
+
});
|
|
158
|
+
await this.testSession(offlineSession);
|
|
159
|
+
|
|
160
|
+
logger.debug('Offline session is still valid, embedding app', {shop});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
await this.handleInvalidOfflineSession(error, request, shop);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private async handleAuthBeginRequest(
|
|
168
|
+
request: Request,
|
|
169
|
+
shop: string,
|
|
170
|
+
): Promise<never> {
|
|
171
|
+
const {api, config, logger} = this;
|
|
172
|
+
|
|
173
|
+
logger.info('Handling OAuth begin request', {shop});
|
|
174
|
+
|
|
175
|
+
// If we're loading from an iframe, we need to break out of it
|
|
176
|
+
if (
|
|
177
|
+
config.isEmbeddedApp &&
|
|
178
|
+
request.headers.get('Sec-Fetch-Dest') === 'iframe'
|
|
179
|
+
) {
|
|
180
|
+
logger.debug('Auth request in iframe detected, exiting iframe', {shop});
|
|
181
|
+
throw redirectWithExitIframe({api, config, logger}, request, shop);
|
|
182
|
+
} else {
|
|
183
|
+
throw await beginAuth({api, config, logger}, request, false, shop);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private async handleAuthCallbackRequest(
|
|
188
|
+
request: Request,
|
|
189
|
+
shop: string,
|
|
190
|
+
): Promise<never> {
|
|
191
|
+
const {api, config, logger} = this;
|
|
192
|
+
|
|
193
|
+
logger.info('Handling OAuth callback request');
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
const {session, headers: responseHeaders} = await api.auth.callback({
|
|
197
|
+
rawRequest: request,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
await config.sessionStorage.storeSession(session);
|
|
201
|
+
|
|
202
|
+
if (config.useOnlineTokens && !session.isOnline) {
|
|
203
|
+
logger.info('Requesting online access token for offline session');
|
|
204
|
+
await beginAuth({api, config, logger}, request, true, shop);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
await triggerAfterAuthHook<Resources>(
|
|
208
|
+
{api, config, logger},
|
|
209
|
+
session,
|
|
210
|
+
request,
|
|
211
|
+
this,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
throw await redirectToShopifyOrAppRoot(
|
|
215
|
+
request,
|
|
216
|
+
{api, config, logger},
|
|
217
|
+
responseHeaders,
|
|
218
|
+
);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
if (error instanceof Response) throw error;
|
|
221
|
+
|
|
222
|
+
throw await this.oauthCallbackError(error, request, shop);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private async getOfflineSession(
|
|
227
|
+
request: Request,
|
|
228
|
+
): Promise<Session | undefined> {
|
|
229
|
+
const offlineId = await this.getOfflineSessionId(request);
|
|
230
|
+
return this.config.sessionStorage.loadSession(offlineId!);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private async hasValidOfflineId(request: Request) {
|
|
234
|
+
return Boolean(await this.getOfflineSessionId(request));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private async getOfflineSessionId(
|
|
238
|
+
request: Request,
|
|
239
|
+
): Promise<string | undefined> {
|
|
240
|
+
const {api} = this;
|
|
241
|
+
const url = new URL(request.url);
|
|
242
|
+
const shop = url.searchParams.get('shop');
|
|
243
|
+
|
|
244
|
+
return shop
|
|
245
|
+
? api.session.getOfflineId(shop)
|
|
246
|
+
: api.session.getCurrentId({isOnline: false, rawRequest: request});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private async testSession(session: Session): Promise<void> {
|
|
250
|
+
const {api} = this;
|
|
251
|
+
|
|
252
|
+
const client = new api.clients.Graphql({
|
|
253
|
+
session,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
await client.request(`#graphql
|
|
257
|
+
query shopifyAppShopName {
|
|
258
|
+
shop {
|
|
259
|
+
name
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
`);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private async oauthCallbackError(
|
|
266
|
+
error: Error,
|
|
267
|
+
request: Request,
|
|
268
|
+
shop: string,
|
|
269
|
+
) {
|
|
270
|
+
const {logger} = this;
|
|
271
|
+
logger.error('Error during OAuth callback', {error: error.message});
|
|
272
|
+
|
|
273
|
+
if (error instanceof CookieNotFound) {
|
|
274
|
+
return this.handleAuthBeginRequest(request, shop);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (
|
|
278
|
+
error instanceof InvalidHmacError ||
|
|
279
|
+
error instanceof InvalidOAuthError
|
|
280
|
+
) {
|
|
281
|
+
return new Response(undefined, {
|
|
282
|
+
status: 400,
|
|
283
|
+
statusText: 'Invalid OAuth Request',
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return new Response(undefined, {
|
|
288
|
+
status: 500,
|
|
289
|
+
statusText: 'Internal Server Error',
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private async handleInvalidOfflineSession(
|
|
294
|
+
error: Error,
|
|
295
|
+
request: Request,
|
|
296
|
+
shop: string,
|
|
297
|
+
) {
|
|
298
|
+
const {api, logger, config} = this;
|
|
299
|
+
if (error instanceof HttpResponseError) {
|
|
300
|
+
if (error.response.code === 401) {
|
|
301
|
+
logger.info('Shop session is no longer valid, redirecting to OAuth', {
|
|
302
|
+
shop,
|
|
303
|
+
});
|
|
304
|
+
throw await beginAuth({api, config, logger}, request, false, shop);
|
|
305
|
+
} else {
|
|
306
|
+
const message = JSON.stringify(error.response.body, null, 2);
|
|
307
|
+
logger.error(`Unexpected error during session validation: ${message}`, {
|
|
308
|
+
shop,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
throw new Response(undefined, {
|
|
312
|
+
status: error.response.code,
|
|
313
|
+
statusText: error.response.statusText,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
} else if (error instanceof GraphqlQueryError) {
|
|
317
|
+
const context: Record<string, string> = {shop};
|
|
318
|
+
if (error.response) {
|
|
319
|
+
context.response = JSON.stringify(error.body);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
logger.error(
|
|
323
|
+
`Unexpected error during session validation: ${error.message}`,
|
|
324
|
+
context,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
throw new Response(undefined, {
|
|
328
|
+
status: 500,
|
|
329
|
+
statusText: 'Internal Server Error',
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|