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,101 @@
|
|
|
1
|
+
import '@shopify/shopify-api/adapters/web-api';
|
|
2
|
+
import '../adapters/node';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ConfigParams,
|
|
6
|
+
LATEST_API_VERSION,
|
|
7
|
+
LogSeverity,
|
|
8
|
+
shopifyApi,
|
|
9
|
+
} from '@shopify/shopify-api';
|
|
10
|
+
|
|
11
|
+
import {overrideLogger} from '../override-logger';
|
|
12
|
+
import {SHOPIFY_REMIX_LIBRARY_VERSION} from '../version';
|
|
13
|
+
|
|
14
|
+
const LOG_FN = jest.fn();
|
|
15
|
+
const VALID_API_CONFIG: ConfigParams = {
|
|
16
|
+
apiKey: 'test-key',
|
|
17
|
+
apiSecretKey: 'test-secret',
|
|
18
|
+
scopes: ['test-scope'],
|
|
19
|
+
apiVersion: LATEST_API_VERSION,
|
|
20
|
+
hostName: 'test-host',
|
|
21
|
+
isEmbeddedApp: true,
|
|
22
|
+
logger: {log: LOG_FN, level: LogSeverity.Debug},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('override logger', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.resetAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('overrides the package name in log messages', () => {
|
|
31
|
+
// GIVEN
|
|
32
|
+
const logger = overrideLogger(shopifyApi(VALID_API_CONFIG).logger);
|
|
33
|
+
|
|
34
|
+
// WHEN
|
|
35
|
+
logger.log(LogSeverity.Info, 'Test message');
|
|
36
|
+
|
|
37
|
+
// THEN
|
|
38
|
+
expect(LOG_FN).toHaveBeenCalledWith(
|
|
39
|
+
LogSeverity.Info,
|
|
40
|
+
'[shopify-app/INFO] Test message',
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('deprecate allows future versions to go through', () => {
|
|
45
|
+
// GIVEN
|
|
46
|
+
const logger = overrideLogger(shopifyApi(VALID_API_CONFIG).logger);
|
|
47
|
+
|
|
48
|
+
// WHEN
|
|
49
|
+
logger.deprecated('9999.0.0', 'Test deprecation message');
|
|
50
|
+
|
|
51
|
+
// THEN
|
|
52
|
+
expect(LOG_FN).toHaveBeenCalledWith(
|
|
53
|
+
LogSeverity.Warning,
|
|
54
|
+
'[shopify-app/WARNING] [Deprecated | 9999.0.0] Test deprecation message',
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('deprecate fails on the current version', () => {
|
|
59
|
+
// GIVEN
|
|
60
|
+
const logger = overrideLogger(shopifyApi(VALID_API_CONFIG).logger);
|
|
61
|
+
|
|
62
|
+
// THEN
|
|
63
|
+
expect(() =>
|
|
64
|
+
logger.deprecated(
|
|
65
|
+
SHOPIFY_REMIX_LIBRARY_VERSION,
|
|
66
|
+
'Test deprecation message',
|
|
67
|
+
),
|
|
68
|
+
).toThrowError(
|
|
69
|
+
`Feature was deprecated in version ${SHOPIFY_REMIX_LIBRARY_VERSION}`,
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each([
|
|
74
|
+
LogSeverity.Debug,
|
|
75
|
+
LogSeverity.Info,
|
|
76
|
+
LogSeverity.Warning,
|
|
77
|
+
LogSeverity.Error,
|
|
78
|
+
])('logs messages normally at level %s', (level) => {
|
|
79
|
+
// GIVEN
|
|
80
|
+
const logger = overrideLogger(shopifyApi(VALID_API_CONFIG).logger);
|
|
81
|
+
|
|
82
|
+
// WHEN
|
|
83
|
+
switch (level) {
|
|
84
|
+
case LogSeverity.Debug:
|
|
85
|
+
logger.debug('Test debug message');
|
|
86
|
+
break;
|
|
87
|
+
case LogSeverity.Info:
|
|
88
|
+
logger.info('Test info message');
|
|
89
|
+
break;
|
|
90
|
+
case LogSeverity.Warning:
|
|
91
|
+
logger.warning('Test warning message');
|
|
92
|
+
break;
|
|
93
|
+
case LogSeverity.Error:
|
|
94
|
+
logger.error('Test error message');
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// THEN
|
|
99
|
+
expect(LOG_FN).toHaveBeenCalledWith(level, expect.anything());
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {ShopifyError} from '@shopify/shopify-api';
|
|
2
|
+
import * as shopifyApiPackage from '@shopify/shopify-api';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
shopifyApp,
|
|
6
|
+
LATEST_API_VERSION as APP_LATEST_API_VERSION,
|
|
7
|
+
LogSeverity,
|
|
8
|
+
DeliveryMethod,
|
|
9
|
+
BillingInterval,
|
|
10
|
+
AppDistribution,
|
|
11
|
+
ApiVersion,
|
|
12
|
+
} from '../index';
|
|
13
|
+
import {testConfig} from '../__test-helpers';
|
|
14
|
+
|
|
15
|
+
describe('shopifyApp', () => {
|
|
16
|
+
/* eslint-disable no-process-env */
|
|
17
|
+
const oldEnv = process.env;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.resetModules();
|
|
21
|
+
process.env = {...oldEnv};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterAll(() => {
|
|
25
|
+
process.env = oldEnv;
|
|
26
|
+
});
|
|
27
|
+
/* eslint-enable no-process-env */
|
|
28
|
+
|
|
29
|
+
it('can create shopify object', () => {
|
|
30
|
+
// GIVEN
|
|
31
|
+
const shopify = shopifyApp(testConfig());
|
|
32
|
+
|
|
33
|
+
// THEN
|
|
34
|
+
expect(shopify).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('has login function when distribution is not ShopifyAdmin', () => {
|
|
38
|
+
// GIVEN
|
|
39
|
+
const shopify = shopifyApp(testConfig());
|
|
40
|
+
|
|
41
|
+
// THEN
|
|
42
|
+
expect(shopify.login).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('does not have login function when distribution is ShopifyAdmin', () => {
|
|
46
|
+
// GIVEN
|
|
47
|
+
const shopify = shopifyApp(
|
|
48
|
+
testConfig({
|
|
49
|
+
distribution: AppDistribution.ShopifyAdmin,
|
|
50
|
+
adminApiAccessToken: 'dummy_token',
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// THEN
|
|
55
|
+
expect(shopify).not.toHaveProperty('login');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('fails with an invalid config', () => {
|
|
59
|
+
expect(() => shopifyApp({} as any)).toThrowError(ShopifyError);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("fixes the port if it's not set", () => {
|
|
63
|
+
// GIVEN
|
|
64
|
+
jest.spyOn(shopifyApiPackage, 'shopifyApi');
|
|
65
|
+
// eslint-disable-next-line no-process-env
|
|
66
|
+
process.env.PORT = '1234';
|
|
67
|
+
|
|
68
|
+
// WHEN
|
|
69
|
+
shopifyApp(testConfig({appUrl: 'http://localhost'}));
|
|
70
|
+
|
|
71
|
+
// THEN
|
|
72
|
+
expect(shopifyApiPackage.shopifyApi).toHaveBeenCalledWith(
|
|
73
|
+
expect.objectContaining({
|
|
74
|
+
appUrl: 'http://localhost:1234',
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('applies user agent prefix', () => {
|
|
80
|
+
// GIVEN
|
|
81
|
+
jest.spyOn(shopifyApiPackage, 'shopifyApi');
|
|
82
|
+
const config = testConfig({
|
|
83
|
+
userAgentPrefix: 'test',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// WHEN
|
|
87
|
+
shopifyApp(config);
|
|
88
|
+
|
|
89
|
+
// THEN
|
|
90
|
+
const {userAgentPrefix} = (shopifyApiPackage.shopifyApi as any).mock
|
|
91
|
+
.calls[1][0];
|
|
92
|
+
|
|
93
|
+
expect(userAgentPrefix).toMatch(
|
|
94
|
+
/^test \| Shopify Remix Library v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9]+)?$/,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('properly re-exports required @shopify/shopify-api imports', () => {
|
|
99
|
+
// This test doesn't actually test anything, but it's here to make sure that we're actually importing the values
|
|
100
|
+
const imports = [
|
|
101
|
+
APP_LATEST_API_VERSION,
|
|
102
|
+
LogSeverity,
|
|
103
|
+
DeliveryMethod,
|
|
104
|
+
BillingInterval,
|
|
105
|
+
ApiVersion,
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
expect(imports).not.toContain(undefined);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('fails if no session storage is given', () => {
|
|
112
|
+
// GIVEN
|
|
113
|
+
const config = testConfig({sessionStorage: undefined});
|
|
114
|
+
delete (config as any).sessionStorage;
|
|
115
|
+
|
|
116
|
+
// THEN
|
|
117
|
+
expect(() => shopifyApp(config as any)).toThrowError(ShopifyError);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {APP_BRIDGE_URL} from '../../authenticate/const';
|
|
2
|
+
import {appBridgeUrl} from '../../authenticate/helpers';
|
|
3
|
+
|
|
4
|
+
describe('node setup import', () => {
|
|
5
|
+
/* eslint-disable no-process-env */
|
|
6
|
+
it('overwrites the App Bridge URL from the env var when present', async () => {
|
|
7
|
+
// GIVEN
|
|
8
|
+
expect(appBridgeUrl()).toEqual(APP_BRIDGE_URL);
|
|
9
|
+
process.env.APP_BRIDGE_URL = 'http://localhost:9876/app-bridge.js';
|
|
10
|
+
|
|
11
|
+
// WHEN
|
|
12
|
+
await require('../node/index');
|
|
13
|
+
|
|
14
|
+
// THEN
|
|
15
|
+
expect(appBridgeUrl()).toEqual(process.env.APP_BRIDGE_URL);
|
|
16
|
+
});
|
|
17
|
+
/* eslint-enable no-process-env */
|
|
18
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {setCrypto} from '@shopify/shopify-api/runtime';
|
|
2
|
+
|
|
3
|
+
describe('node setup import', () => {
|
|
4
|
+
let previousCrypto: any;
|
|
5
|
+
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
previousCrypto = require('@shopify/shopify-api/runtime').crypto;
|
|
9
|
+
setCrypto(undefined as any);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterAll(() => {
|
|
13
|
+
setCrypto(previousCrypto);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('sets up the crypto library only when the import is called', async () => {
|
|
17
|
+
// GIVEN
|
|
18
|
+
const cryptoBefore = (await require('@shopify/shopify-api/runtime')).crypto;
|
|
19
|
+
expect(cryptoBefore).toBeUndefined();
|
|
20
|
+
|
|
21
|
+
// WHEN
|
|
22
|
+
await require('../node');
|
|
23
|
+
|
|
24
|
+
// THEN
|
|
25
|
+
const cryptoAfter = (await require('@shopify/shopify-api/runtime')).crypto;
|
|
26
|
+
expect(cryptoAfter).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
setAbstractRuntimeString,
|
|
5
|
+
setCrypto,
|
|
6
|
+
} from '@shopify/shopify-api/runtime';
|
|
7
|
+
|
|
8
|
+
import {setAppBridgeUrlOverride} from '../../authenticate/helpers';
|
|
9
|
+
|
|
10
|
+
setCrypto(crypto as any);
|
|
11
|
+
|
|
12
|
+
setAbstractRuntimeString(() => {
|
|
13
|
+
return `Remix (Node)`;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/* eslint-disable no-process-env */
|
|
17
|
+
if (process.env.APP_BRIDGE_URL) {
|
|
18
|
+
setAppBridgeUrlOverride(process.env.APP_BRIDGE_URL);
|
|
19
|
+
}
|
|
20
|
+
/* eslint-enable no-process-env */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fetchMock from 'jest-fetch-mock';
|
|
2
|
+
import '@shopify/shopify-api/adapters/web-api';
|
|
3
|
+
import '..';
|
|
4
|
+
import {setAbstractFetchFunc} from '@shopify/shopify-api/runtime';
|
|
5
|
+
|
|
6
|
+
// Globally disable fetch requests so we don't risk making real ones
|
|
7
|
+
fetchMock.enableMocks();
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
fetchMock.mockReset();
|
|
11
|
+
});
|
|
12
|
+
setAbstractFetchFunc(fetch);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {setAbstractFetchFunc} from '@shopify/shopify-api/runtime';
|
|
2
|
+
import {installGlobals} from '@remix-run/node';
|
|
3
|
+
|
|
4
|
+
import '../node';
|
|
5
|
+
|
|
6
|
+
installGlobals();
|
|
7
|
+
|
|
8
|
+
const fetchFunc = fetch;
|
|
9
|
+
setAbstractFetchFunc(async (...args) => {
|
|
10
|
+
const response = await fetchFunc.apply(this, args);
|
|
11
|
+
|
|
12
|
+
return response;
|
|
13
|
+
});
|
package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/admin-client.test.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiVersion,
|
|
3
|
+
HttpMaxRetriesError,
|
|
4
|
+
LATEST_API_VERSION,
|
|
5
|
+
SESSION_COOKIE_NAME,
|
|
6
|
+
Session,
|
|
7
|
+
} from '@shopify/shopify-api';
|
|
8
|
+
import {restResources} from '@shopify/shopify-api/rest/admin/2023-04';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
APP_URL,
|
|
12
|
+
BASE64_HOST,
|
|
13
|
+
TEST_SHOP,
|
|
14
|
+
getJwt,
|
|
15
|
+
getThrownResponse,
|
|
16
|
+
setUpValidSession,
|
|
17
|
+
signRequestCookie,
|
|
18
|
+
testConfig,
|
|
19
|
+
mockExternalRequest,
|
|
20
|
+
expectAdminApiClient,
|
|
21
|
+
} from '../../../__test-helpers';
|
|
22
|
+
import {shopifyApp} from '../../..';
|
|
23
|
+
import {AdminApiContext} from '../../../clients';
|
|
24
|
+
|
|
25
|
+
describe('admin.authenticate context', () => {
|
|
26
|
+
expectAdminApiClient(async () => {
|
|
27
|
+
const {
|
|
28
|
+
admin,
|
|
29
|
+
expectedSession,
|
|
30
|
+
session: actualSession,
|
|
31
|
+
} = await setUpEmbeddedFlow();
|
|
32
|
+
|
|
33
|
+
return {admin, expectedSession, actualSession};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('re-throws errors other than HttpResponseErrors on GraphQL requests', async () => {
|
|
37
|
+
// GIVEN
|
|
38
|
+
const {admin} = await setUpEmbeddedFlow();
|
|
39
|
+
|
|
40
|
+
// WHEN
|
|
41
|
+
await mockGraphqlRequest()(429);
|
|
42
|
+
await mockGraphqlRequest()(429);
|
|
43
|
+
|
|
44
|
+
// THEN
|
|
45
|
+
await expect(async () =>
|
|
46
|
+
admin.graphql(
|
|
47
|
+
'mutation myMutation($ID: String!) { shop(ID: $ID) { name } }',
|
|
48
|
+
{variables: {ID: '123'}, tries: 2},
|
|
49
|
+
),
|
|
50
|
+
).rejects.toThrowError(HttpMaxRetriesError);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('re-throws errors other than HttpResponseErrors on REST requests', async () => {
|
|
54
|
+
// GIVEN
|
|
55
|
+
const {admin} = await setUpEmbeddedFlow();
|
|
56
|
+
|
|
57
|
+
// WHEN
|
|
58
|
+
await mockRestRequest(429);
|
|
59
|
+
await mockRestRequest(429);
|
|
60
|
+
|
|
61
|
+
// THEN
|
|
62
|
+
await expect(async () =>
|
|
63
|
+
admin.rest.get({path: '/customers.json', tries: 2}),
|
|
64
|
+
).rejects.toThrowError(HttpMaxRetriesError);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe.each([
|
|
68
|
+
{
|
|
69
|
+
testGroup: 'REST client',
|
|
70
|
+
mockRequest: mockRestRequest,
|
|
71
|
+
action: async (admin: AdminApiContext, _session: Session) =>
|
|
72
|
+
admin.rest.get({path: '/customers.json'}),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
testGroup: 'REST resources',
|
|
76
|
+
mockRequest: mockRestRequest,
|
|
77
|
+
action: async (admin: AdminApiContext, session: Session) =>
|
|
78
|
+
admin.rest.resources.Customer.all({session}),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
testGroup: 'GraphQL client',
|
|
82
|
+
mockRequest: mockGraphqlRequest(),
|
|
83
|
+
action: async (admin: AdminApiContext, _session: Session) =>
|
|
84
|
+
admin.graphql('{ shop { name } }'),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
testGroup: 'GraphQL client with options',
|
|
88
|
+
mockRequest: mockGraphqlRequest('2021-01' as ApiVersion),
|
|
89
|
+
action: async (admin: AdminApiContext, _session: Session) =>
|
|
90
|
+
admin.graphql(
|
|
91
|
+
'mutation myMutation($ID: String!) { shop(ID: $ID) { name } }',
|
|
92
|
+
{
|
|
93
|
+
variables: {ID: '123'},
|
|
94
|
+
apiVersion: '2021-01' as ApiVersion,
|
|
95
|
+
headers: {custom: 'header'},
|
|
96
|
+
tries: 2,
|
|
97
|
+
},
|
|
98
|
+
),
|
|
99
|
+
},
|
|
100
|
+
])(
|
|
101
|
+
'$testGroup re-authentication',
|
|
102
|
+
({testGroup: _testGroup, mockRequest, action}) => {
|
|
103
|
+
it('throws a response when request receives a non-401 response and not embedded', async () => {
|
|
104
|
+
// GIVEN
|
|
105
|
+
const {admin, session} = await setUpNonEmbeddedFlow();
|
|
106
|
+
const requestMock = await mockRequest(403);
|
|
107
|
+
|
|
108
|
+
// WHEN
|
|
109
|
+
const response = await getThrownResponse(
|
|
110
|
+
async () => action(admin, session),
|
|
111
|
+
requestMock,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// THEN
|
|
115
|
+
expect(response.status).toEqual(403);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
async function setUpEmbeddedFlow() {
|
|
122
|
+
const shopify = shopifyApp(testConfig({restResources}));
|
|
123
|
+
const expectedSession = await setUpValidSession(shopify.sessionStorage);
|
|
124
|
+
|
|
125
|
+
const {token} = getJwt();
|
|
126
|
+
const request = new Request(
|
|
127
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=${token}`,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
shopify,
|
|
132
|
+
expectedSession,
|
|
133
|
+
...(await shopify.authenticate.admin(request)),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function setUpNonEmbeddedFlow() {
|
|
138
|
+
const shopify = shopifyApp(testConfig({restResources, isEmbeddedApp: false}));
|
|
139
|
+
const session = await setUpValidSession(shopify.sessionStorage);
|
|
140
|
+
|
|
141
|
+
const request = new Request(`${APP_URL}?shop=${TEST_SHOP}`);
|
|
142
|
+
signRequestCookie({
|
|
143
|
+
request,
|
|
144
|
+
cookieName: SESSION_COOKIE_NAME,
|
|
145
|
+
cookieValue: session.id,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
shopify,
|
|
150
|
+
...(await shopify.authenticate.admin(request)),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function mockRestRequest(status) {
|
|
155
|
+
const requestMock = new Request(
|
|
156
|
+
`https://${TEST_SHOP}/admin/api/${LATEST_API_VERSION}/customers.json`,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
await mockExternalRequest({
|
|
160
|
+
request: requestMock,
|
|
161
|
+
response: new Response('{}', {status}),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return requestMock;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function mockGraphqlRequest(apiVersion = LATEST_API_VERSION) {
|
|
168
|
+
return async function (status) {
|
|
169
|
+
const requestMock = new Request(
|
|
170
|
+
`https://${TEST_SHOP}/admin/api/${apiVersion}/graphql.json`,
|
|
171
|
+
{method: 'POST'},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
await mockExternalRequest({
|
|
175
|
+
request: requestMock,
|
|
176
|
+
response: new Response(undefined, {status}),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return requestMock;
|
|
180
|
+
};
|
|
181
|
+
}
|
package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/doc-request-path.test.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {LogSeverity, SESSION_COOKIE_NAME, Session} from '@shopify/shopify-api';
|
|
2
|
+
|
|
3
|
+
import {shopifyApp} from '../../..';
|
|
4
|
+
import {
|
|
5
|
+
API_KEY,
|
|
6
|
+
APP_URL,
|
|
7
|
+
BASE64_HOST,
|
|
8
|
+
GRAPHQL_URL,
|
|
9
|
+
SHOPIFY_HOST,
|
|
10
|
+
TEST_SHOP,
|
|
11
|
+
expectBeginAuthRedirect,
|
|
12
|
+
expectExitIframeRedirect,
|
|
13
|
+
getJwt,
|
|
14
|
+
getThrownResponse,
|
|
15
|
+
setUpValidSession,
|
|
16
|
+
testConfig,
|
|
17
|
+
signRequestCookie,
|
|
18
|
+
expectLoginRedirect,
|
|
19
|
+
mockExternalRequest,
|
|
20
|
+
} from '../../../__test-helpers';
|
|
21
|
+
|
|
22
|
+
describe('authorize.admin doc request path', () => {
|
|
23
|
+
describe('errors', () => {
|
|
24
|
+
it.each([
|
|
25
|
+
{shop: TEST_SHOP, host: undefined},
|
|
26
|
+
{shop: TEST_SHOP, host: 'invalid-domain.test'},
|
|
27
|
+
{shop: undefined, host: BASE64_HOST},
|
|
28
|
+
{shop: 'invalid', host: BASE64_HOST},
|
|
29
|
+
])('throws when %s', async ({shop, host}) => {
|
|
30
|
+
// GIVEN
|
|
31
|
+
const shopify = shopifyApp(testConfig());
|
|
32
|
+
const searchParams = new URLSearchParams();
|
|
33
|
+
if (shop) searchParams.set('shop', shop);
|
|
34
|
+
if (host) searchParams.set('host', host);
|
|
35
|
+
|
|
36
|
+
// WHEN
|
|
37
|
+
const response = await getThrownResponse(
|
|
38
|
+
shopify.authenticate.admin,
|
|
39
|
+
new Request(`${APP_URL}?${searchParams.toString()}`),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// THEN
|
|
43
|
+
expectLoginRedirect(response);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('redirects to the bounce page URL if id_token search param is missing', async () => {
|
|
47
|
+
// GIVEN
|
|
48
|
+
const shopify = shopifyApp(testConfig());
|
|
49
|
+
await setUpValidSession(shopify.sessionStorage);
|
|
50
|
+
|
|
51
|
+
// WHEN
|
|
52
|
+
const response = await getThrownResponse(
|
|
53
|
+
shopify.authenticate.admin,
|
|
54
|
+
new Request(
|
|
55
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// THEN
|
|
60
|
+
const {pathname, searchParams} = new URL(
|
|
61
|
+
response.headers.get('location')!,
|
|
62
|
+
APP_URL,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(response.status).toBe(302);
|
|
66
|
+
expect(pathname).toBe('/auth/session-token');
|
|
67
|
+
expect(searchParams.get('shop')).toBe(TEST_SHOP);
|
|
68
|
+
expect(searchParams.get('host')).toBe(BASE64_HOST);
|
|
69
|
+
expect(searchParams.get('shopify-reload')).toBe(
|
|
70
|
+
`${APP_URL}/?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('always bounces to the app URL, regardless of request URL', async () => {
|
|
75
|
+
// GIVEN
|
|
76
|
+
const shopify = shopifyApp(testConfig());
|
|
77
|
+
await setUpValidSession(shopify.sessionStorage);
|
|
78
|
+
|
|
79
|
+
// WHEN
|
|
80
|
+
const response = await getThrownResponse(
|
|
81
|
+
shopify.authenticate.admin,
|
|
82
|
+
new Request(
|
|
83
|
+
`https://some-other-host.not.real?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// THEN
|
|
88
|
+
const {searchParams} = new URL(
|
|
89
|
+
response.headers.get('location')!,
|
|
90
|
+
APP_URL,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(response.status).toBe(302);
|
|
94
|
+
expect(searchParams.get('shopify-reload')).toBe(
|
|
95
|
+
`${APP_URL}/?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}`,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('throws a 401 if app is embedded and the id_token search param is invalid', async () => {
|
|
100
|
+
// GIVEN
|
|
101
|
+
const shopify = shopifyApp(testConfig());
|
|
102
|
+
await setUpValidSession(shopify.sessionStorage);
|
|
103
|
+
|
|
104
|
+
// WHEN
|
|
105
|
+
const response = await getThrownResponse(
|
|
106
|
+
shopify.authenticate.admin,
|
|
107
|
+
new Request(
|
|
108
|
+
`${APP_URL}?embedded=1&shop=${TEST_SHOP}&host=${BASE64_HOST}&id_token=invalid`,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// THEN
|
|
113
|
+
expect(response.status).toBe(401);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('returns a 400 response when no shop is available', async () => {
|
|
118
|
+
// GIVEN
|
|
119
|
+
const shopify = shopifyApp(testConfig({isEmbeddedApp: false}));
|
|
120
|
+
await setUpValidSession(shopify.sessionStorage);
|
|
121
|
+
|
|
122
|
+
// WHEN
|
|
123
|
+
const response = await getThrownResponse(
|
|
124
|
+
shopify.authenticate.admin,
|
|
125
|
+
new Request(APP_URL),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// THEN
|
|
129
|
+
expect(response.status).toBe(400);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("redirects to the embedded app URL if the app isn't embedded yet", async () => {
|
|
133
|
+
// GIVEN
|
|
134
|
+
const config = testConfig();
|
|
135
|
+
const shopify = shopifyApp(config);
|
|
136
|
+
await setUpValidSession(shopify.sessionStorage);
|
|
137
|
+
|
|
138
|
+
// WHEN
|
|
139
|
+
const response = await getThrownResponse(
|
|
140
|
+
shopify.authenticate.admin,
|
|
141
|
+
new Request(`${APP_URL}?shop=${TEST_SHOP}&host=${BASE64_HOST}`),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// THEN
|
|
145
|
+
const {hostname, pathname} = new URL(response.headers.get('location')!);
|
|
146
|
+
|
|
147
|
+
expect(response.status).toBe(302);
|
|
148
|
+
expect(hostname).toBe(SHOPIFY_HOST);
|
|
149
|
+
expect(pathname).toBe(`/apps/${API_KEY}`);
|
|
150
|
+
});
|
|
151
|
+
});
|