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
package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/exit-i-frame-path.test.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {ShopifyError} from '@shopify/shopify-api';
|
|
2
|
+
|
|
3
|
+
import {shopifyApp} from '../../..';
|
|
4
|
+
import {
|
|
5
|
+
APP_URL,
|
|
6
|
+
TEST_SHOP,
|
|
7
|
+
expectDocumentRequestHeaders,
|
|
8
|
+
getThrownResponse,
|
|
9
|
+
testConfig,
|
|
10
|
+
} from '../../../__test-helpers';
|
|
11
|
+
import {APP_BRIDGE_URL} from '../../const';
|
|
12
|
+
|
|
13
|
+
describe('authorize.admin exit iframe path', () => {
|
|
14
|
+
test('Uses App Bridge to exit iFrame when the url matches auth.exitIframePath', async () => {
|
|
15
|
+
// GIVEN
|
|
16
|
+
const config = testConfig();
|
|
17
|
+
const shopify = shopifyApp(config);
|
|
18
|
+
|
|
19
|
+
// WHEN
|
|
20
|
+
const exitTo = encodeURIComponent(config.appUrl);
|
|
21
|
+
const url = `${APP_URL}/auth/exit-iframe?exitIframe=${exitTo}&shop=${TEST_SHOP}`;
|
|
22
|
+
const response = await getThrownResponse(
|
|
23
|
+
shopify.authenticate.admin,
|
|
24
|
+
new Request(url),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// THEN
|
|
28
|
+
const responseText = await response.text();
|
|
29
|
+
expect(response.status).toBe(200);
|
|
30
|
+
expect(response.headers.get('content-type')).toBe(
|
|
31
|
+
'text/html;charset=utf-8',
|
|
32
|
+
);
|
|
33
|
+
expect(responseText).toContain(
|
|
34
|
+
`<script data-api-key="${config.apiKey}" src="${APP_BRIDGE_URL}"></script>`,
|
|
35
|
+
);
|
|
36
|
+
expect(responseText).toContain(
|
|
37
|
+
`<script>window.open("${decodeURIComponent(exitTo)}/", "_top")</script>`,
|
|
38
|
+
);
|
|
39
|
+
expectDocumentRequestHeaders(response);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Uses App Bridge to exit iFrame when the url matches auth.exitIframePath and authPathPrefix is passed', async () => {
|
|
43
|
+
// GIVEN
|
|
44
|
+
const authPathPrefix = '/shopify';
|
|
45
|
+
const config = testConfig({authPathPrefix});
|
|
46
|
+
const shopify = shopifyApp(config);
|
|
47
|
+
|
|
48
|
+
// WHEN
|
|
49
|
+
const exitTo = encodeURIComponent(config.appUrl);
|
|
50
|
+
const url = `${APP_URL}${authPathPrefix}/exit-iframe?exitIframe=${exitTo}&shop=${TEST_SHOP}`;
|
|
51
|
+
const response = await getThrownResponse(
|
|
52
|
+
shopify.authenticate.admin,
|
|
53
|
+
new Request(url),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// THEN
|
|
57
|
+
const responseText = await response.text();
|
|
58
|
+
expect(response.status).toBe(200);
|
|
59
|
+
expect(response.headers.get('content-type')).toBe(
|
|
60
|
+
'text/html;charset=utf-8',
|
|
61
|
+
);
|
|
62
|
+
expect(responseText).toContain(
|
|
63
|
+
`<script data-api-key="${config.apiKey}" src="${APP_BRIDGE_URL}"></script>`,
|
|
64
|
+
);
|
|
65
|
+
expect(responseText).toContain(
|
|
66
|
+
`<script>window.open("${decodeURIComponent(exitTo)}/", "_top")</script>`,
|
|
67
|
+
);
|
|
68
|
+
expectDocumentRequestHeaders(response);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('Allows relative paths as exitIframe param', async () => {
|
|
72
|
+
// GIVEN
|
|
73
|
+
const shopify = shopifyApp(testConfig());
|
|
74
|
+
|
|
75
|
+
// WHEN
|
|
76
|
+
const exitTo = encodeURIComponent('/my-path');
|
|
77
|
+
const url = `${APP_URL}/auth/exit-iframe?exitIframe=${exitTo}&shop=${TEST_SHOP}`;
|
|
78
|
+
const response = await getThrownResponse(
|
|
79
|
+
shopify.authenticate.admin,
|
|
80
|
+
new Request(url),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// THEN
|
|
84
|
+
expect(response.status).toBe(200);
|
|
85
|
+
expectDocumentRequestHeaders(response);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('refuses to redirect to invalid URLs', async () => {
|
|
89
|
+
// GIVEN
|
|
90
|
+
const shopify = shopifyApp(testConfig());
|
|
91
|
+
const exitTo = encodeURIComponent('file:///not/allowed/path');
|
|
92
|
+
const url = `${APP_URL}/auth/exit-iframe?exitIframe=${exitTo}&shop=${TEST_SHOP}`;
|
|
93
|
+
|
|
94
|
+
// THEN
|
|
95
|
+
await expect(shopify.authenticate.admin(new Request(url))).rejects.toThrow(
|
|
96
|
+
ShopifyError,
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {shopifyApp} from '../../..';
|
|
2
|
+
import {APP_BRIDGE_URL} from '../../const';
|
|
3
|
+
import {
|
|
4
|
+
APP_URL,
|
|
5
|
+
TEST_SHOP,
|
|
6
|
+
expectDocumentRequestHeaders,
|
|
7
|
+
getThrownResponse,
|
|
8
|
+
testConfig,
|
|
9
|
+
} from '../../../__test-helpers';
|
|
10
|
+
|
|
11
|
+
describe('authorize.admin path session token path', () => {
|
|
12
|
+
test('Uses AppBridge to get a session token if the URL is for auth.patchSessionTokenPath', async () => {
|
|
13
|
+
// GIVEN
|
|
14
|
+
const config = testConfig();
|
|
15
|
+
const shopify = shopifyApp(config);
|
|
16
|
+
|
|
17
|
+
// WHEN
|
|
18
|
+
const url = `${APP_URL}/auth/session-token?shop=${TEST_SHOP}`;
|
|
19
|
+
const response = await getThrownResponse(
|
|
20
|
+
shopify.authenticate.admin,
|
|
21
|
+
new Request(url),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// THEN
|
|
25
|
+
expect(response.status).toBe(200);
|
|
26
|
+
expectDocumentRequestHeaders(response, config.isEmbeddedApp);
|
|
27
|
+
expect(response.headers.get('content-type')).toBe(
|
|
28
|
+
'text/html;charset=utf-8',
|
|
29
|
+
);
|
|
30
|
+
expect((await response.text()).trim()).toBe(
|
|
31
|
+
`<script data-api-key="${config.apiKey}" src="${APP_BRIDGE_URL}"></script>`,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('Uses AppBridge to get a session token if the URL is for auth.patchSessionTokenPath and authPathPrefix is configured', async () => {
|
|
36
|
+
// GIVEN
|
|
37
|
+
const authPathPrefix = '/shopify';
|
|
38
|
+
const config = testConfig({authPathPrefix});
|
|
39
|
+
const shopify = shopifyApp(config);
|
|
40
|
+
|
|
41
|
+
// WHEN
|
|
42
|
+
const url = `${APP_URL}${authPathPrefix}/session-token?shop=${TEST_SHOP}`;
|
|
43
|
+
const response = await getThrownResponse(
|
|
44
|
+
shopify.authenticate.admin,
|
|
45
|
+
new Request(url),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// THEN
|
|
49
|
+
expect(response.status).toBe(200);
|
|
50
|
+
expectDocumentRequestHeaders(response, config.isEmbeddedApp);
|
|
51
|
+
expect(response.headers.get('content-type')).toBe(
|
|
52
|
+
'text/html;charset=utf-8',
|
|
53
|
+
);
|
|
54
|
+
expect((await response.text()).trim()).toContain(
|
|
55
|
+
`<script data-api-key="${config.apiKey}" src="${APP_BRIDGE_URL}"></script>`,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {shopifyApp} from '../../..';
|
|
2
|
+
import {APP_URL, getThrownResponse, testConfig} from '../../../__test-helpers';
|
|
3
|
+
|
|
4
|
+
describe('authorize.admin', () => {
|
|
5
|
+
test('rejects bot requests', async () => {
|
|
6
|
+
// GIVEN
|
|
7
|
+
const shopify = shopifyApp(testConfig());
|
|
8
|
+
|
|
9
|
+
// WHEN
|
|
10
|
+
const response = await getThrownResponse(
|
|
11
|
+
shopify.authenticate.admin,
|
|
12
|
+
new Request(APP_URL, {
|
|
13
|
+
headers: {
|
|
14
|
+
'User-Agent': 'Googlebot',
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// THEN
|
|
20
|
+
expect(response.status).toBe(410);
|
|
21
|
+
expect(response.statusText).toBe('Gone');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {shopifyApp} from '../../..';
|
|
2
|
+
import {APP_URL, getThrownResponse, testConfig} from '../../../__test-helpers';
|
|
3
|
+
import {REAUTH_URL_HEADER} from '../../const';
|
|
4
|
+
|
|
5
|
+
describe('authorize.admin', () => {
|
|
6
|
+
test('Adds CORS headers if OPTIONS request and origin is not the app', async () => {
|
|
7
|
+
// GIVEN
|
|
8
|
+
const shopify = shopifyApp(testConfig());
|
|
9
|
+
|
|
10
|
+
// WHEN
|
|
11
|
+
const response = await getThrownResponse(
|
|
12
|
+
shopify.authenticate.admin,
|
|
13
|
+
new Request('http://cdn.shopify.com', {
|
|
14
|
+
method: 'OPTIONS',
|
|
15
|
+
headers: {Origin: 'http://cdn.shopify.com'},
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// THEN
|
|
20
|
+
expect(response.status).toBe(204);
|
|
21
|
+
expect(response.headers.get('Access-Control-Allow-Origin')).toBe('*');
|
|
22
|
+
expect(response.headers.get('Access-Control-Allow-Headers')).toBe(
|
|
23
|
+
'Authorization, Content-Type',
|
|
24
|
+
);
|
|
25
|
+
expect(response.headers.get('Access-Control-Expose-Headers')).toBe(
|
|
26
|
+
REAUTH_URL_HEADER,
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Does not add CORS headers if OPTIONS request and origin is the app', async () => {
|
|
31
|
+
// GIVEN
|
|
32
|
+
const shopify = shopifyApp(testConfig());
|
|
33
|
+
|
|
34
|
+
// WHEN
|
|
35
|
+
const response = await getThrownResponse(
|
|
36
|
+
shopify.authenticate.admin,
|
|
37
|
+
new Request(APP_URL, {method: 'OPTIONS'}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// THEN
|
|
41
|
+
expect(response.status).toBe(204);
|
|
42
|
+
expect(response.headers.get('Access-Control-Allow-Origin')).not.toBe('*');
|
|
43
|
+
expect(response.headers.get('Access-Control-Allow-Headers')).not.toBe(
|
|
44
|
+
'Authorization, Content-Type',
|
|
45
|
+
);
|
|
46
|
+
expect(response.headers.get('Access-Control-Expose-Headers')).not.toBe(
|
|
47
|
+
REAUTH_URL_HEADER,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {SESSION_COOKIE_NAME, Session} from '@shopify/shopify-api';
|
|
2
|
+
|
|
3
|
+
import {shopifyApp} from '../../..';
|
|
4
|
+
import {
|
|
5
|
+
APP_URL,
|
|
6
|
+
BASE64_HOST,
|
|
7
|
+
TEST_SHOP,
|
|
8
|
+
getJwt,
|
|
9
|
+
getThrownResponse,
|
|
10
|
+
setUpValidSession,
|
|
11
|
+
signRequestCookie,
|
|
12
|
+
testConfig,
|
|
13
|
+
} from '../../../__test-helpers';
|
|
14
|
+
import {REAUTH_URL_HEADER} from '../../const';
|
|
15
|
+
|
|
16
|
+
describe('authorize.session token header path', () => {
|
|
17
|
+
describe('errors', () => {
|
|
18
|
+
it('throws a 401 if the session token is invalid', async () => {
|
|
19
|
+
// GIVEN
|
|
20
|
+
const shopify = shopifyApp(testConfig());
|
|
21
|
+
|
|
22
|
+
// WHEN
|
|
23
|
+
const response = await getThrownResponse(
|
|
24
|
+
shopify.authenticate.admin,
|
|
25
|
+
new Request(`${APP_URL}?shop=${TEST_SHOP}&host=${BASE64_HOST}`, {
|
|
26
|
+
headers: {Authorization: 'Bearer im-a-valid-token-promise'},
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// THEN
|
|
31
|
+
expect(response.status).toBe(401);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe.each([true, false])(
|
|
36
|
+
'success cases when isOnline: %s',
|
|
37
|
+
(isOnline) => {
|
|
38
|
+
it('returns context when session exists for embedded apps', async () => {
|
|
39
|
+
// GIVEN
|
|
40
|
+
const shopify = shopifyApp(testConfig({useOnlineTokens: isOnline}));
|
|
41
|
+
|
|
42
|
+
const testSession = await setUpValidSession(shopify.sessionStorage, {
|
|
43
|
+
isOnline,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// WHEN
|
|
47
|
+
const {token, payload} = getJwt();
|
|
48
|
+
const {sessionToken, admin, session} = await shopify.authenticate.admin(
|
|
49
|
+
new Request(`${APP_URL}?shop=${TEST_SHOP}&host=${BASE64_HOST}`, {
|
|
50
|
+
headers: {Authorization: `Bearer ${token}`},
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// THEN
|
|
55
|
+
expect(sessionToken).toEqual(payload);
|
|
56
|
+
expect(session).toBe(testSession);
|
|
57
|
+
expect(admin.rest.session).toBe(testSession);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns context when session exists for non-embedded apps', async () => {
|
|
61
|
+
// GIVEN
|
|
62
|
+
const shopify = shopifyApp(
|
|
63
|
+
testConfig({isEmbeddedApp: false, useOnlineTokens: isOnline}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
let testSession: Session;
|
|
67
|
+
testSession = await setUpValidSession(shopify.sessionStorage);
|
|
68
|
+
if (isOnline) {
|
|
69
|
+
testSession = await setUpValidSession(shopify.sessionStorage, {
|
|
70
|
+
isOnline: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// WHEN
|
|
75
|
+
const request = new Request(
|
|
76
|
+
`${APP_URL}?shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
77
|
+
);
|
|
78
|
+
signRequestCookie({
|
|
79
|
+
request,
|
|
80
|
+
cookieName: SESSION_COOKIE_NAME,
|
|
81
|
+
cookieValue: testSession.id,
|
|
82
|
+
});
|
|
83
|
+
const {admin, session} = await shopify.authenticate.admin(request);
|
|
84
|
+
|
|
85
|
+
// THEN
|
|
86
|
+
expect(session).toBe(testSession);
|
|
87
|
+
expect(admin.rest.session).toBe(testSession);
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
|
|
2
|
+
|
|
3
|
+
const data: ReferenceEntityTemplateSchema = {
|
|
4
|
+
name: 'Admin',
|
|
5
|
+
description:
|
|
6
|
+
'Contains functions for authenticating and interacting with the Admin API.\n\nThis function can handle requests for apps embedded in the Admin, Admin extensions, or non-embedded apps.',
|
|
7
|
+
category: 'Authenticate',
|
|
8
|
+
type: 'object',
|
|
9
|
+
isVisualComponent: false,
|
|
10
|
+
definitions: [
|
|
11
|
+
{
|
|
12
|
+
title: 'authenticate.admin',
|
|
13
|
+
description:
|
|
14
|
+
'Authenticates requests coming from the Shopify admin.\n\nThe shape of the returned object changes depending on the `isEmbeddedApp` config.',
|
|
15
|
+
type: 'AuthenticateAdmin',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
jsDocTypeExamples: [
|
|
19
|
+
'EmbeddedAdminContext',
|
|
20
|
+
'AdminApiContext',
|
|
21
|
+
'BillingContext',
|
|
22
|
+
],
|
|
23
|
+
related: [
|
|
24
|
+
{
|
|
25
|
+
name: 'API context',
|
|
26
|
+
subtitle: 'Interact with the Admin API.',
|
|
27
|
+
url: '/docs/api/shopify-app-remix/apis/admin-api',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Billing context',
|
|
31
|
+
subtitle: 'Bill merchants for your app using the Admin API.',
|
|
32
|
+
url: '/docs/api/shopify-app-remix/apis/billing',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default data;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {JwtPayload, Session, ShopifyRestResources} from '@shopify/shopify-api';
|
|
2
|
+
|
|
3
|
+
import type {BasicParams} from '../../types';
|
|
4
|
+
import type {AppConfigArg} from '../../config-types';
|
|
5
|
+
import {
|
|
6
|
+
getSessionTokenHeader,
|
|
7
|
+
ensureCORSHeadersFactory,
|
|
8
|
+
getSessionTokenFromUrlParam,
|
|
9
|
+
respondToBotRequest,
|
|
10
|
+
respondToOptionsRequest,
|
|
11
|
+
validateSessionToken,
|
|
12
|
+
} from '../helpers';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
cancelBillingFactory,
|
|
16
|
+
requestBillingFactory,
|
|
17
|
+
requireBillingFactory,
|
|
18
|
+
checkBillingFactory,
|
|
19
|
+
} from './billing';
|
|
20
|
+
import type {
|
|
21
|
+
AdminContext,
|
|
22
|
+
AuthenticateAdmin,
|
|
23
|
+
EmbeddedAdminContext,
|
|
24
|
+
NonEmbeddedAdminContext,
|
|
25
|
+
} from './types';
|
|
26
|
+
import {
|
|
27
|
+
createAdminApiContext,
|
|
28
|
+
ensureAppIsEmbeddedIfRequired,
|
|
29
|
+
ensureSessionTokenSearchParamIfRequired,
|
|
30
|
+
redirectFactory,
|
|
31
|
+
renderAppBridge,
|
|
32
|
+
validateShopAndHostParams,
|
|
33
|
+
} from './helpers';
|
|
34
|
+
import {AuthorizationStrategy} from './strategies/types';
|
|
35
|
+
|
|
36
|
+
export interface SessionTokenContext {
|
|
37
|
+
shop: string;
|
|
38
|
+
sessionId?: string;
|
|
39
|
+
sessionToken?: string;
|
|
40
|
+
payload?: JwtPayload;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface AuthStrategyParams extends BasicParams {
|
|
44
|
+
strategy: AuthorizationStrategy;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function authStrategyFactory<
|
|
48
|
+
ConfigArg extends AppConfigArg,
|
|
49
|
+
Resources extends ShopifyRestResources = ShopifyRestResources,
|
|
50
|
+
>({
|
|
51
|
+
strategy,
|
|
52
|
+
...params
|
|
53
|
+
}: AuthStrategyParams): AuthenticateAdmin<ConfigArg, Resources> {
|
|
54
|
+
const {api, logger, config} = params;
|
|
55
|
+
|
|
56
|
+
async function respondToBouncePageRequest(request: Request) {
|
|
57
|
+
const url = new URL(request.url);
|
|
58
|
+
|
|
59
|
+
if (url.pathname === config.auth.patchSessionTokenPath) {
|
|
60
|
+
logger.debug('Rendering bounce page');
|
|
61
|
+
throw renderAppBridge({config, logger, api}, request);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function respondToExitIframeRequest(request: Request) {
|
|
66
|
+
const url = new URL(request.url);
|
|
67
|
+
|
|
68
|
+
if (url.pathname === config.auth.exitIframePath) {
|
|
69
|
+
const destination = url.searchParams.get('exitIframe')!;
|
|
70
|
+
|
|
71
|
+
logger.debug('Rendering exit iframe page', {destination});
|
|
72
|
+
throw renderAppBridge({config, logger, api}, request, {url: destination});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function createContext(
|
|
77
|
+
request: Request,
|
|
78
|
+
session: Session,
|
|
79
|
+
authStrategy: AuthorizationStrategy,
|
|
80
|
+
sessionToken?: JwtPayload,
|
|
81
|
+
): AdminContext<ConfigArg, Resources> {
|
|
82
|
+
const context:
|
|
83
|
+
| EmbeddedAdminContext<ConfigArg, Resources>
|
|
84
|
+
| NonEmbeddedAdminContext<ConfigArg, Resources> = {
|
|
85
|
+
admin: createAdminApiContext<Resources>(
|
|
86
|
+
session,
|
|
87
|
+
params,
|
|
88
|
+
authStrategy.handleClientError(request),
|
|
89
|
+
),
|
|
90
|
+
billing: {
|
|
91
|
+
require: requireBillingFactory(params, request, session),
|
|
92
|
+
check: checkBillingFactory(params, request, session),
|
|
93
|
+
request: requestBillingFactory(params, request, session),
|
|
94
|
+
cancel: cancelBillingFactory(params, request, session),
|
|
95
|
+
},
|
|
96
|
+
session,
|
|
97
|
+
cors: ensureCORSHeadersFactory(params, request),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (config.isEmbeddedApp) {
|
|
101
|
+
return {
|
|
102
|
+
...context,
|
|
103
|
+
sessionToken,
|
|
104
|
+
redirect: redirectFactory(params, request),
|
|
105
|
+
} as AdminContext<ConfigArg, Resources>;
|
|
106
|
+
} else {
|
|
107
|
+
return context as AdminContext<ConfigArg, Resources>;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return async function authenticateAdmin(request: Request) {
|
|
112
|
+
try {
|
|
113
|
+
respondToBotRequest(params, request);
|
|
114
|
+
respondToOptionsRequest(params, request);
|
|
115
|
+
await respondToBouncePageRequest(request);
|
|
116
|
+
await respondToExitIframeRequest(request);
|
|
117
|
+
await strategy.respondToOAuthRequests(request);
|
|
118
|
+
|
|
119
|
+
// If this is a valid request, but it doesn't have a session token header, this is a document request. We need to
|
|
120
|
+
// ensure we're embedded if needed and we have the information needed to load the session.
|
|
121
|
+
if (!getSessionTokenHeader(request)) {
|
|
122
|
+
validateShopAndHostParams(params, request);
|
|
123
|
+
await ensureAppIsEmbeddedIfRequired(params, request);
|
|
124
|
+
await ensureSessionTokenSearchParamIfRequired(params, request);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
logger.info('Authenticating admin request');
|
|
128
|
+
|
|
129
|
+
const {payload, shop, sessionId, sessionToken} =
|
|
130
|
+
await getSessionTokenContext(params, request);
|
|
131
|
+
|
|
132
|
+
logger.debug('Loading session from storage', {sessionId});
|
|
133
|
+
const existingSession = sessionId
|
|
134
|
+
? await config.sessionStorage.loadSession(sessionId)
|
|
135
|
+
: undefined;
|
|
136
|
+
|
|
137
|
+
const session = await strategy.authenticate(request, {
|
|
138
|
+
session: existingSession,
|
|
139
|
+
sessionToken,
|
|
140
|
+
shop,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
logger.debug('Request is valid, loaded session from session token', {
|
|
144
|
+
shop: session.shop,
|
|
145
|
+
isOnline: session.isOnline,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return createContext(request, session, strategy, payload);
|
|
149
|
+
} catch (errorOrResponse) {
|
|
150
|
+
if (errorOrResponse instanceof Response) {
|
|
151
|
+
ensureCORSHeadersFactory(params, request)(errorOrResponse);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw errorOrResponse;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function getSessionTokenContext(
|
|
160
|
+
params: BasicParams,
|
|
161
|
+
request: Request,
|
|
162
|
+
): Promise<SessionTokenContext> {
|
|
163
|
+
const {api, config, logger} = params;
|
|
164
|
+
|
|
165
|
+
const headerSessionToken = getSessionTokenHeader(request);
|
|
166
|
+
const searchParamSessionToken = getSessionTokenFromUrlParam(request);
|
|
167
|
+
const sessionToken = (headerSessionToken || searchParamSessionToken)!;
|
|
168
|
+
|
|
169
|
+
logger.debug('Attempting to authenticate session token', {
|
|
170
|
+
sessionToken: JSON.stringify({
|
|
171
|
+
header: headerSessionToken,
|
|
172
|
+
search: searchParamSessionToken,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (config.isEmbeddedApp) {
|
|
177
|
+
const payload = await validateSessionToken(
|
|
178
|
+
{config, logger, api},
|
|
179
|
+
sessionToken,
|
|
180
|
+
);
|
|
181
|
+
const dest = new URL(payload.dest);
|
|
182
|
+
const shop = dest.hostname;
|
|
183
|
+
|
|
184
|
+
logger.debug('Session token is valid', {shop, payload});
|
|
185
|
+
const sessionId = config.useOnlineTokens
|
|
186
|
+
? api.session.getJwtSessionId(shop, payload.sub)
|
|
187
|
+
: api.session.getOfflineId(shop);
|
|
188
|
+
|
|
189
|
+
return {shop, payload, sessionId, sessionToken};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const url = new URL(request.url);
|
|
193
|
+
const shop = url.searchParams.get('shop')!;
|
|
194
|
+
|
|
195
|
+
const sessionId = await api.session.getCurrentId({
|
|
196
|
+
isOnline: config.useOnlineTokens,
|
|
197
|
+
rawRequest: request,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
return {shop, sessionId, payload: undefined, sessionToken};
|
|
201
|
+
}
|