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,77 @@
|
|
|
1
|
+
# `shopify.redirectOutOfApp()`
|
|
2
|
+
|
|
3
|
+
This function enables apps to redirect out of the app's host, regardless of how a request reached the app.
|
|
4
|
+
It covers the following scenarios:
|
|
5
|
+
|
|
6
|
+
- If the request came from an `authenticatedFetch` call, it'll return the right headers for App Bridge.
|
|
7
|
+
- If the request came from an app embedded in the Shopify Admin, it'll use `config.exitIframePath`.
|
|
8
|
+
- Otherwise, it will trigger a normal HTTP redirect.
|
|
9
|
+
|
|
10
|
+
## Parameters
|
|
11
|
+
|
|
12
|
+
This function takes in an object with the following properties:
|
|
13
|
+
|
|
14
|
+
### `req`
|
|
15
|
+
|
|
16
|
+
`express.Request`
|
|
17
|
+
|
|
18
|
+
The Express.js request object.
|
|
19
|
+
|
|
20
|
+
### `res`
|
|
21
|
+
|
|
22
|
+
`express.Response`
|
|
23
|
+
|
|
24
|
+
The Express.js response object.
|
|
25
|
+
|
|
26
|
+
### `redirectUri`
|
|
27
|
+
|
|
28
|
+
`string`
|
|
29
|
+
|
|
30
|
+
The URI to redirect to.
|
|
31
|
+
|
|
32
|
+
### `shop`
|
|
33
|
+
|
|
34
|
+
`string`
|
|
35
|
+
|
|
36
|
+
The shop for this request.
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
The following example shows how to redirect out of the app for requests that render HTML or return JSON data.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const shopify = shopifyApp({});
|
|
44
|
+
|
|
45
|
+
const redirectMiddleware = (req, res, next) => {
|
|
46
|
+
if (redirectRequired) {
|
|
47
|
+
shopify.redirectOutOfApp({
|
|
48
|
+
req,
|
|
49
|
+
res,
|
|
50
|
+
redirectUri: '/my-non-embedded-endpoint',
|
|
51
|
+
shop: shopify.api.utils.sanitizeShop(req.query.shop),
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
next();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
app.get(
|
|
59
|
+
'/api/endpoint-that-redirects',
|
|
60
|
+
shopify.validateAuthenticatedSession(),
|
|
61
|
+
// redirectOutOfApp will cause App Bridge to trigger the redirect
|
|
62
|
+
redirectMiddleware,
|
|
63
|
+
(req, res) => {
|
|
64
|
+
// Handle request as usual
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
app.get(
|
|
69
|
+
'/html-endpoint',
|
|
70
|
+
shopify.ensureInstalledOnShop(),
|
|
71
|
+
// redirectOutOfApp will cause the app to break out of the iframe
|
|
72
|
+
redirectMiddleware,
|
|
73
|
+
(req, res) => {
|
|
74
|
+
// Handle request as usual
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# `shopify.redirectToShopifyOrAppRoot`
|
|
2
|
+
|
|
3
|
+
This function creates an Express middleware that loads the app's root, and ensures that it loads in the appropriate location.
|
|
4
|
+
|
|
5
|
+
For instance, if this is an embedded app, it will redirect to the Shopify Admin and embed the app within it, but if the app is not embedded, it will load it at the browser's top level.
|
|
6
|
+
|
|
7
|
+
> **Note**: This middleware expects a session to be available in `res.locals.shopify.session`.
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const app = express();
|
|
13
|
+
|
|
14
|
+
// Once OAuth completes, return to the app root in the appropriate location.
|
|
15
|
+
app.get(
|
|
16
|
+
'/auth/callback',
|
|
17
|
+
shopify.auth.callback(),
|
|
18
|
+
shopify.redirectToShopifyOrAppRoot(),
|
|
19
|
+
);
|
|
20
|
+
```
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# `shopifyApp`
|
|
2
|
+
|
|
3
|
+
This function creates an object that contains everything an Express app needs to interact with Shopify.
|
|
4
|
+
|
|
5
|
+
## Parameters
|
|
6
|
+
|
|
7
|
+
### api
|
|
8
|
+
|
|
9
|
+
`ApiConfigParams` | :exclamation: required when not using the Shopify CLI
|
|
10
|
+
|
|
11
|
+
All values allowed by the `@shopify/shopify-api` package [when calling `shopifyApi`](https://github.com/Shopify/shopify-api-js/blob/main/packages/shopify-api/docs/reference/shopifyApi.md).
|
|
12
|
+
|
|
13
|
+
### auth
|
|
14
|
+
|
|
15
|
+
Configurations for OAuth using this package.
|
|
16
|
+
See below for the specific details.
|
|
17
|
+
|
|
18
|
+
#### path
|
|
19
|
+
|
|
20
|
+
`string` | :exclamation: required
|
|
21
|
+
|
|
22
|
+
The URL path used by the app to start the OAuth process.
|
|
23
|
+
This must match the path you use for the `shopify.auth.begin` route.
|
|
24
|
+
|
|
25
|
+
#### callbackPath
|
|
26
|
+
|
|
27
|
+
`string` | :exclamation: required
|
|
28
|
+
|
|
29
|
+
The URL path used by the app to complete the OAuth process.
|
|
30
|
+
It works in the same way as `path` above, and it must match the path of the route that uses `shopify.auth.callback`.
|
|
31
|
+
|
|
32
|
+
### webhooks
|
|
33
|
+
|
|
34
|
+
Configurations for Webhooks using this package.
|
|
35
|
+
|
|
36
|
+
#### path
|
|
37
|
+
|
|
38
|
+
`string` | :exclamation: required
|
|
39
|
+
|
|
40
|
+
The URL path used by the app to receive HTTP webhooks from Shopify.
|
|
41
|
+
This must match the path of the route that uses `shopify.processWebhooks`.
|
|
42
|
+
|
|
43
|
+
### useOnlineTokens
|
|
44
|
+
|
|
45
|
+
`boolean` | Defaults to `false`
|
|
46
|
+
|
|
47
|
+
Whether the OAuth process should produce online access tokens as well as offline ones (created by default).
|
|
48
|
+
Learn more about [access modes in Shopify APIs](https://shopify.dev/docs/apps/auth/oauth/access-modes).
|
|
49
|
+
|
|
50
|
+
### exitIframePath
|
|
51
|
+
|
|
52
|
+
`string` | Defaults to `"/exitiframe"`
|
|
53
|
+
|
|
54
|
+
The path your app's frontend uses to trigger an App Bridge redirect to leave the Shopify Admin before starting OAuth.
|
|
55
|
+
Since that page is in the app frontend, we don't include it in this package, but you can find [an example in our template](https://github.com/Shopify/shopify-frontend-template-react/blob/main/pages/ExitIframe.jsx).
|
|
56
|
+
|
|
57
|
+
## Return
|
|
58
|
+
|
|
59
|
+
Returns an object that contains everything an app needs to interact with Shopify:
|
|
60
|
+
|
|
61
|
+
### config
|
|
62
|
+
|
|
63
|
+
`{[key: string]: any}`
|
|
64
|
+
|
|
65
|
+
The configuration used to set up this object.
|
|
66
|
+
|
|
67
|
+
### api
|
|
68
|
+
|
|
69
|
+
The object created by the `@shopify/shopify-api` package. See [the API package documentation](https://github.com/Shopify/shopify-api-js#readme) for more details.
|
|
70
|
+
|
|
71
|
+
### [auth](./auth.md)
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
{begin: () => RequestHandler, callback: () => RequestHandler}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
An object containing both middlewares you'll need to authenticate with Shopify.
|
|
78
|
+
|
|
79
|
+
### [processWebhooks](./processWebhooks.md)
|
|
80
|
+
|
|
81
|
+
`(ProcessWebhooksMiddlewareParams) => RequestHandler`
|
|
82
|
+
|
|
83
|
+
A function that returns a middleware that processes Shopify webhook requests.
|
|
84
|
+
This _must_ be a `post` route.
|
|
85
|
+
|
|
86
|
+
### [validateAuthenticatedSession](./validateAuthenticatedSession.md)
|
|
87
|
+
|
|
88
|
+
`() => RequestHandler`
|
|
89
|
+
|
|
90
|
+
A function that returns an Express middleware that verifies that the request received is authenticated with a valid session for embedded apps.
|
|
91
|
+
|
|
92
|
+
### [ensureInstalledOnShop](./ensureInstalledOnShop.md)
|
|
93
|
+
|
|
94
|
+
`() => RequestHandler`
|
|
95
|
+
|
|
96
|
+
A function that returns an Express middleware that verifies that the request received is for a shop that has installed the app when rendering HTML.
|
|
97
|
+
|
|
98
|
+
### [redirectToShopifyOrAppRoot](./redirectToShopifyOrAppRoot.md)
|
|
99
|
+
|
|
100
|
+
`() => RequestHandler`
|
|
101
|
+
|
|
102
|
+
A function that returns an Express middleware that redirects the user to the app, embedding it into Shopify depending on `api.isEmbeddedApp`.
|
|
103
|
+
|
|
104
|
+
### [redirectOutOfApp](./redirectOutOfApp.md)
|
|
105
|
+
|
|
106
|
+
`(RedirectOutOfAppParams) => void`
|
|
107
|
+
|
|
108
|
+
A function that redirects to any URL at the browser's top level, regardless of where the request originated from.
|
|
109
|
+
|
|
110
|
+
## Example
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const shopify = shopifyApp({
|
|
114
|
+
api: {
|
|
115
|
+
apiKey: 'ApiKeyFromPartnersDashboard',
|
|
116
|
+
apiSecretKey: 'ApiSecretKeyFromPartnersDashboard',
|
|
117
|
+
scopes: ['your_scopes'],
|
|
118
|
+
hostScheme: 'http',
|
|
119
|
+
hostName: `localhost:${PORT}`,
|
|
120
|
+
billing: {
|
|
121
|
+
'My plan': {
|
|
122
|
+
amount: 10,
|
|
123
|
+
currencyCode: 'USD',
|
|
124
|
+
interval: BillingInterval.Every30Days,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
auth: {
|
|
129
|
+
path: '/auth',
|
|
130
|
+
callbackPath: '/auth/callback',
|
|
131
|
+
},
|
|
132
|
+
webhooks: {
|
|
133
|
+
path: '/webhooks',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// The paths to these routes must match the configured values above
|
|
138
|
+
app.get(shopify.config.auth.path, shopify.auth.begin());
|
|
139
|
+
app.get(
|
|
140
|
+
shopify.config.auth.callbackPath,
|
|
141
|
+
shopify.auth.callback(),
|
|
142
|
+
shopify.redirectToShopifyOrAppRoot(),
|
|
143
|
+
);
|
|
144
|
+
app.post(
|
|
145
|
+
shopify.config.webhooks.path,
|
|
146
|
+
shopify.processWebhooks({webhookHandlers}),
|
|
147
|
+
);
|
|
148
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# `shopify.validateAuthenticatedSession`
|
|
2
|
+
|
|
3
|
+
This function creates an Express middleware that ensures any request to that endpoint will have a valid session (i.e., not expired, access token available, scopes match).
|
|
4
|
+
|
|
5
|
+
This middleware behaves slightly differently depending on whether your app is embedded or not.
|
|
6
|
+
If the verification fails in either case, it will redirect the user to complete OAuth, thereby ensuring that a valid session is available to continue processing.
|
|
7
|
+
|
|
8
|
+
- When embedded, it will verify that the request received from the front-end originates from an App Bridge `authenticatedFetch`.
|
|
9
|
+
- When not embedded, it will verify that the request contains a valid session cookie set up during the OAuth process.
|
|
10
|
+
- XHR requests will return a `403 Forbidden` response with the `X-Shopify-Api-Request-Failure-Reauthorize-Url` header indicating where to redirect the user for authentication.
|
|
11
|
+
|
|
12
|
+
Please visit [our documentation](https://shopify.dev/docs/apps/auth/oauth/session-tokens) to learn more about session tokens and how they work.
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
const app = express();
|
|
18
|
+
|
|
19
|
+
app.get(
|
|
20
|
+
'/api/product/count',
|
|
21
|
+
shopify.validateAuthenticatedSession(),
|
|
22
|
+
async (res, req) => {
|
|
23
|
+
// because of shopify.validateAuthenticatedSession(), session is available
|
|
24
|
+
// in res.locals.shopify.session
|
|
25
|
+
const session = res.locals.shopify.session;
|
|
26
|
+
|
|
27
|
+
// Interact with the API
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {createPackage, createProjectPlugin} from '@shopify/loom';
|
|
2
|
+
import {buildLibrary} from '@shopify/loom-plugin-build-library';
|
|
3
|
+
|
|
4
|
+
export default createPackage((pkg) => {
|
|
5
|
+
pkg.entry({root: './src/index.ts'});
|
|
6
|
+
pkg.use(
|
|
7
|
+
buildLibrary({
|
|
8
|
+
// Required. A browserslist string for specifying your target output.
|
|
9
|
+
// Use browser targets (e.g. `'defaults'`) if your package targets the browser,
|
|
10
|
+
// node targets (e.g. `'node 12.22'`) if your package targets node
|
|
11
|
+
// or both (e.g.`'defaults, node 12.22'`) if your package targets both
|
|
12
|
+
targets: 'node 16',
|
|
13
|
+
// Optional. Defaults to false. Defines if commonjs outputs should be generated.
|
|
14
|
+
commonjs: true,
|
|
15
|
+
// Optional. Defaults to false. Defines if esmodules outputs should be generated.
|
|
16
|
+
esmodules: false,
|
|
17
|
+
// Optional. Defaults to false. Defines if esnext outputs should be generated.
|
|
18
|
+
esnext: false,
|
|
19
|
+
// Optional. Defaults to true. Defines if entrypoints should be written at
|
|
20
|
+
// the root of the repository. You can disable this if you have a single
|
|
21
|
+
// entrypoint or if your package uses the `exports` key in package.json
|
|
22
|
+
rootEntrypoints: false,
|
|
23
|
+
// Optional. Defaults to 'node'. Defines if the jest environment should be 'node' or 'jsdom'.
|
|
24
|
+
jestTestEnvironment: 'node',
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shopify/shopify-app-express",
|
|
3
|
+
"version": "4.1.2",
|
|
4
|
+
"description": "Shopify Express Middleware - to simplify the building of Shopify Apps with Express",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Shopify/shopify-app-express.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/Shopify/shopify-app-express/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Shopify/shopify-app-express/tree/main/packages/shopify-app-express",
|
|
13
|
+
"author": "Shopify Inc.",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"main": "./build/cjs/index.js",
|
|
16
|
+
"types": "./build/ts/index.d.ts",
|
|
17
|
+
"scripts": {},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"shopify",
|
|
23
|
+
"node",
|
|
24
|
+
"express",
|
|
25
|
+
"app",
|
|
26
|
+
"graphql",
|
|
27
|
+
"rest",
|
|
28
|
+
"webhook",
|
|
29
|
+
"Admin API",
|
|
30
|
+
"Storefront API"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@shopify/shopify-api": "^9.3.2",
|
|
34
|
+
"@shopify/shopify-app-session-storage": "^2.1.1",
|
|
35
|
+
"@shopify/shopify-app-session-storage-memory": "^3.0.1",
|
|
36
|
+
"cookie-parser": "^1.4.6",
|
|
37
|
+
"express": "^4.18.1",
|
|
38
|
+
"semver": "^7.6.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/compression": "^1.7.5",
|
|
42
|
+
"@types/cookie-parser": "^1.4.6",
|
|
43
|
+
"@types/express": "^4.17.21",
|
|
44
|
+
"@types/jsonwebtoken": "^9.0.5",
|
|
45
|
+
"jsonwebtoken": "^9.0.2",
|
|
46
|
+
"supertest": "^6.3.3"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"build/*",
|
|
50
|
+
"!bundle/*",
|
|
51
|
+
"!tsconfig.tsbuildinfo",
|
|
52
|
+
"!node_modules"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FeatureDeprecatedError,
|
|
3
|
+
LogSeverity,
|
|
4
|
+
ShopifyError,
|
|
5
|
+
} from '@shopify/shopify-api';
|
|
6
|
+
|
|
7
|
+
import {shopifyApp} from '../index';
|
|
8
|
+
import {SHOPIFY_EXPRESS_LIBRARY_VERSION} from '../version';
|
|
9
|
+
|
|
10
|
+
import {testConfig} from './test-helper';
|
|
11
|
+
|
|
12
|
+
describe('shopifyApp', () => {
|
|
13
|
+
/* eslint-disable no-process-env */
|
|
14
|
+
const oldEnv = process.env;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.resetModules();
|
|
18
|
+
process.env = {...oldEnv};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
process.env = oldEnv;
|
|
23
|
+
});
|
|
24
|
+
/* eslint-enable no-process-env */
|
|
25
|
+
|
|
26
|
+
it('can create an app object', () => {
|
|
27
|
+
const shopify = shopifyApp(testConfig);
|
|
28
|
+
|
|
29
|
+
expect(shopify).toBeDefined();
|
|
30
|
+
expect(shopify.api).toBeDefined();
|
|
31
|
+
expect(shopify.api.config.apiKey).toBe(testConfig.api.apiKey);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('fails with an invalid config', () => {
|
|
35
|
+
expect(() => shopifyApp({} as any)).toThrowError(ShopifyError);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('properly defaults missing configs based on env vars', () => {
|
|
39
|
+
/* eslint-disable no-process-env */
|
|
40
|
+
process.env.SHOPIFY_API_KEY = 'envKey';
|
|
41
|
+
process.env.SHOPIFY_API_SECRET = 'envSecret';
|
|
42
|
+
process.env.SCOPES = 'envScope1,envScope2';
|
|
43
|
+
process.env.HOST = 'https://envHost';
|
|
44
|
+
process.env.SHOP_CUSTOM_DOMAIN = '*.envCustomDomain';
|
|
45
|
+
|
|
46
|
+
const shopify = shopifyApp({
|
|
47
|
+
auth: testConfig.auth,
|
|
48
|
+
webhooks: testConfig.webhooks,
|
|
49
|
+
api: {
|
|
50
|
+
logger: testConfig.api.logger,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(shopify).toBeDefined();
|
|
55
|
+
expect(shopify.api.config.apiKey).toEqual('envKey');
|
|
56
|
+
expect(shopify.api.config.apiSecretKey).toEqual('envSecret');
|
|
57
|
+
expect(shopify.api.config.scopes.toString()).toEqual('envScope1,envScope2');
|
|
58
|
+
expect(shopify.api.config.hostName).toEqual('envHost');
|
|
59
|
+
expect(shopify.api.config.hostScheme).toEqual('https');
|
|
60
|
+
expect(shopify.api.config.customShopDomains).toEqual(['*.envCustomDomain']);
|
|
61
|
+
/* eslint-enable no-process-env */
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('properly sets the package in log calls', async () => {
|
|
65
|
+
const shopify = shopifyApp(testConfig);
|
|
66
|
+
|
|
67
|
+
shopify.config.logger.info('test');
|
|
68
|
+
|
|
69
|
+
expect(shopify.api.config.logger.log).toHaveBeenCalledWith(
|
|
70
|
+
LogSeverity.Info,
|
|
71
|
+
'[shopify-app/INFO] test',
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
shopify.config.logger.info('test', {extra: 'context'});
|
|
75
|
+
|
|
76
|
+
expect(shopify.api.config.logger.log).toHaveBeenCalledWith(
|
|
77
|
+
LogSeverity.Info,
|
|
78
|
+
'[shopify-app/INFO] test | {extra: context}',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('properly logs deprecation messages', async () => {
|
|
83
|
+
const shopify = shopifyApp(testConfig);
|
|
84
|
+
|
|
85
|
+
shopify.config.logger.deprecated('9999.0.0', 'test');
|
|
86
|
+
|
|
87
|
+
expect(shopify.api.config.logger.log).toHaveBeenCalledWith(
|
|
88
|
+
LogSeverity.Warning,
|
|
89
|
+
'[shopify-app/WARNING] [Deprecated | 9999.0.0] test',
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('throws when deprecation version is reached', async () => {
|
|
94
|
+
const shopify = shopifyApp(testConfig);
|
|
95
|
+
|
|
96
|
+
expect(() =>
|
|
97
|
+
shopify.config.logger.deprecated(SHOPIFY_EXPRESS_LIBRARY_VERSION, 'test'),
|
|
98
|
+
).toThrow(FeatureDeprecatedError);
|
|
99
|
+
});
|
|
100
|
+
});
|