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.

Files changed (424) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/.changeset/flat-clouds-camp.md +5 -0
  4. package/.eslintrc.js +36 -0
  5. package/.github/CODEOWNERS +1 -0
  6. package/.github/ISSUE_TEMPLATE/BUG_REPORT.md +36 -0
  7. package/.github/ISSUE_TEMPLATE/ENHANCEMENT.md +9 -0
  8. package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +9 -0
  9. package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
  10. package/.github/dependabot.yml +9 -0
  11. package/.github/workflows/changelog.yml +30 -0
  12. package/.github/workflows/ci.yml +22 -0
  13. package/.github/workflows/cla.yml +22 -0
  14. package/.github/workflows/close-waiting-for-response-issues.yml +20 -0
  15. package/.github/workflows/main-release.yml +36 -0
  16. package/.github/workflows/markdown_link_check.yml +14 -0
  17. package/.github/workflows/markdown_link_checker_config.json +9 -0
  18. package/.github/workflows/publish-experimental-build.yml +30 -0
  19. package/.github/workflows/release-candidate.yml +35 -0
  20. package/.github/workflows/remove-labels-on-activity.yml +16 -0
  21. package/.github/workflows/stale.yml +26 -0
  22. package/.prettierignore +5 -0
  23. package/.prettierrc +1 -0
  24. package/CODE_OF_CONDUCT.md +46 -0
  25. package/CONTRIBUTING.md +39 -0
  26. package/LICENSE.md +9 -0
  27. package/README.md +62 -3
  28. package/RELEASING.md +142 -0
  29. package/loom.config.ts +115 -0
  30. package/package.json +44 -3
  31. package/packages/.prettierrc +1 -0
  32. package/packages/shopify-app-express/CHANGELOG.md +316 -0
  33. package/packages/shopify-app-express/LICENSE.md +9 -0
  34. package/packages/shopify-app-express/README.md +93 -0
  35. package/packages/shopify-app-express/docs/reference/README.md +3 -0
  36. package/packages/shopify-app-express/docs/reference/auth.md +76 -0
  37. package/packages/shopify-app-express/docs/reference/cspHeaders.md +24 -0
  38. package/packages/shopify-app-express/docs/reference/ensureInstalledOnShop.md +17 -0
  39. package/packages/shopify-app-express/docs/reference/migrating-app-v6-api-lib-to-express-lib.md +345 -0
  40. package/packages/shopify-app-express/docs/reference/processWebhooks.md +67 -0
  41. package/packages/shopify-app-express/docs/reference/redirectOutOfApp.md +77 -0
  42. package/packages/shopify-app-express/docs/reference/redirectToShopifyOrAppRoot.md +20 -0
  43. package/packages/shopify-app-express/docs/reference/shopifyApp.md +148 -0
  44. package/packages/shopify-app-express/docs/reference/validateAuthenticatedSession.md +30 -0
  45. package/packages/shopify-app-express/loom.config.ts +27 -0
  46. package/packages/shopify-app-express/package.json +54 -0
  47. package/packages/shopify-app-express/src/__tests__/index.test.ts +100 -0
  48. package/packages/shopify-app-express/src/__tests__/integration/oauth.test.ts +445 -0
  49. package/packages/shopify-app-express/src/__tests__/integration/responses.ts +135 -0
  50. package/packages/shopify-app-express/src/__tests__/integration/types.ts +22 -0
  51. package/packages/shopify-app-express/src/__tests__/integration/utils.ts +68 -0
  52. package/packages/shopify-app-express/src/__tests__/integration/webhooks.test.ts +208 -0
  53. package/packages/shopify-app-express/src/__tests__/redirect-to-auth.test.ts +103 -0
  54. package/packages/shopify-app-express/src/__tests__/setup-jest.ts +8 -0
  55. package/packages/shopify-app-express/src/__tests__/test-helper.ts +204 -0
  56. package/packages/shopify-app-express/src/app-installations.ts +42 -0
  57. package/packages/shopify-app-express/src/auth/__tests__/auth.test.ts +303 -0
  58. package/packages/shopify-app-express/src/auth/auth-callback.ts +131 -0
  59. package/packages/shopify-app-express/src/auth/index.ts +32 -0
  60. package/packages/shopify-app-express/src/auth/types.ts +13 -0
  61. package/packages/shopify-app-express/src/config-types.ts +38 -0
  62. package/packages/shopify-app-express/src/error.ts +8 -0
  63. package/packages/shopify-app-express/src/index.ts +171 -0
  64. package/packages/shopify-app-express/src/middlewares/__tests__/csp-headers.test.ts +69 -0
  65. package/packages/shopify-app-express/src/middlewares/__tests__/ensure-installed-on-shop.test.ts +193 -0
  66. package/packages/shopify-app-express/src/middlewares/__tests__/redirect-to-shopify-or-app-root.test.ts +59 -0
  67. package/packages/shopify-app-express/src/middlewares/__tests__/validate-authenticated-session.test.ts +319 -0
  68. package/packages/shopify-app-express/src/middlewares/csp-headers.ts +31 -0
  69. package/packages/shopify-app-express/src/middlewares/ensure-installed-on-shop.ts +176 -0
  70. package/packages/shopify-app-express/src/middlewares/has-valid-access-token.ts +25 -0
  71. package/packages/shopify-app-express/src/middlewares/index.ts +15 -0
  72. package/packages/shopify-app-express/src/middlewares/redirect-to-shopify-or-app-root.ts +39 -0
  73. package/packages/shopify-app-express/src/middlewares/types.ts +6 -0
  74. package/packages/shopify-app-express/src/middlewares/validate-authenticated-session.ts +142 -0
  75. package/packages/shopify-app-express/src/redirect-out-of-app.ts +80 -0
  76. package/packages/shopify-app-express/src/redirect-to-auth.ts +70 -0
  77. package/packages/shopify-app-express/src/types.ts +26 -0
  78. package/packages/shopify-app-express/src/version.ts +1 -0
  79. package/packages/shopify-app-express/src/webhooks/__tests__/process.test.ts +138 -0
  80. package/packages/shopify-app-express/src/webhooks/index.ts +54 -0
  81. package/packages/shopify-app-express/src/webhooks/process.ts +22 -0
  82. package/packages/shopify-app-express/src/webhooks/types.ts +24 -0
  83. package/packages/shopify-app-express/tsconfig.json +10 -0
  84. package/packages/shopify-app-remix/.eslintrc.js +3 -0
  85. package/packages/shopify-app-remix/CHANGELOG.md +569 -0
  86. package/packages/shopify-app-remix/LICENSE.md +9 -0
  87. package/packages/shopify-app-remix/README.md +223 -0
  88. package/packages/shopify-app-remix/docs/build-docs.sh +11 -0
  89. package/packages/shopify-app-remix/docs/generated/generated_docs_data.json +18650 -0
  90. package/packages/shopify-app-remix/docs/generated/generated_static_pages.json +540 -0
  91. package/packages/shopify-app-remix/docs/staticPages/admin.doc.ts +130 -0
  92. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/auth-cors.example.tsx +11 -0
  93. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/auth.example.tsx +19 -0
  94. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/graphql.example.tsx +29 -0
  95. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/headers.example.tsx +10 -0
  96. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/rest-resources.example.tsx +9 -0
  97. package/packages/shopify-app-remix/docs/staticPages/examples/guides/admin/rest.example.tsx +17 -0
  98. package/packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/config.example.ts +8 -0
  99. package/packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/unstable.example.ts +9 -0
  100. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/.graphqlrc.ts +16 -0
  101. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.npm.example.sh +2 -0
  102. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.pnpm.example.sh +2 -0
  103. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/install.yarn.example.sh +2 -0
  104. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/package.json +5 -0
  105. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.npm.example.sh +1 -0
  106. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.pnpm.example.sh +1 -0
  107. package/packages/shopify-app-remix/docs/staticPages/examples/guides/graphql-types/run.yarn.example.sh +1 -0
  108. package/packages/shopify-app-remix/docs/staticPages/examples/guides/webhooks/config.example.ts +19 -0
  109. package/packages/shopify-app-remix/docs/staticPages/examples/guides/webhooks/endpoint.example.ts +24 -0
  110. package/packages/shopify-app-remix/docs/staticPages/examples/index/app-provider.example.ts +30 -0
  111. package/packages/shopify-app-remix/docs/staticPages/examples/index/boundaries.example.ts +9 -0
  112. package/packages/shopify-app-remix/docs/staticPages/examples/index/create.npm.example.sh +1 -0
  113. package/packages/shopify-app-remix/docs/staticPages/examples/index/create.pnpm.example.sh +1 -0
  114. package/packages/shopify-app-remix/docs/staticPages/examples/index/create.yarn.example.sh +1 -0
  115. package/packages/shopify-app-remix/docs/staticPages/examples/index/embedded-app-auth-strategy-config.example.ts +10 -0
  116. package/packages/shopify-app-remix/docs/staticPages/examples/index/entry-server.example.ts +12 -0
  117. package/packages/shopify-app-remix/docs/staticPages/examples/index/install.npm.example.sh +1 -0
  118. package/packages/shopify-app-remix/docs/staticPages/examples/index/install.pnpm.example.sh +1 -0
  119. package/packages/shopify-app-remix/docs/staticPages/examples/index/install.yarn.example.sh +1 -0
  120. package/packages/shopify-app-remix/docs/staticPages/examples/index/shopify-app.example.ts +14 -0
  121. package/packages/shopify-app-remix/docs/staticPages/examples/index/splat-route.example.ts +11 -0
  122. package/packages/shopify-app-remix/docs/staticPages/future-flags.doc.ts +94 -0
  123. package/packages/shopify-app-remix/docs/staticPages/graphql-types.doc.ts +148 -0
  124. package/packages/shopify-app-remix/docs/staticPages/index.doc.ts +227 -0
  125. package/packages/shopify-app-remix/docs/staticPages/webhooks.doc.ts +64 -0
  126. package/packages/shopify-app-remix/docs/tsconfig.docs.json +9 -0
  127. package/packages/shopify-app-remix/docs/typeOverride.json +1 -0
  128. package/packages/shopify-app-remix/docs/upcoming_changes.md +153 -0
  129. package/packages/shopify-app-remix/loom.config.ts +57 -0
  130. package/packages/shopify-app-remix/package.json +93 -0
  131. package/packages/shopify-app-remix/src/react/.eslintrc.js +16 -0
  132. package/packages/shopify-app-remix/src/react/__tests__/test-helper.ts +22 -0
  133. package/packages/shopify-app-remix/src/react/components/AppProvider/AppProvider.doc.ts +34 -0
  134. package/packages/shopify-app-remix/src/react/components/AppProvider/AppProvider.tsx +121 -0
  135. package/packages/shopify-app-remix/src/react/components/AppProvider/__tests__/AppProvider.test.tsx +68 -0
  136. package/packages/shopify-app-remix/src/react/components/AppProvider/index.ts +1 -0
  137. package/packages/shopify-app-remix/src/react/components/RemixPolarisLink.tsx +14 -0
  138. package/packages/shopify-app-remix/src/react/components/index.ts +1 -0
  139. package/packages/shopify-app-remix/src/react/const.ts +2 -0
  140. package/packages/shopify-app-remix/src/react/index.ts +1 -0
  141. package/packages/shopify-app-remix/src/server/.eslintrc.js +16 -0
  142. package/packages/shopify-app-remix/src/server/__test-helpers/__tests__/request-mock.test.ts +171 -0
  143. package/packages/shopify-app-remix/src/server/__test-helpers/const.ts +11 -0
  144. package/packages/shopify-app-remix/src/server/__test-helpers/expect-admin-api-client.ts +119 -0
  145. package/packages/shopify-app-remix/src/server/__test-helpers/expect-begin-auth-redirect.ts +22 -0
  146. package/packages/shopify-app-remix/src/server/__test-helpers/expect-document-request-headers.ts +25 -0
  147. package/packages/shopify-app-remix/src/server/__test-helpers/expect-exit-iframe.ts +37 -0
  148. package/packages/shopify-app-remix/src/server/__test-helpers/expect-login-redirect.ts +8 -0
  149. package/packages/shopify-app-remix/src/server/__test-helpers/expect-storefront-api-client.ts +50 -0
  150. package/packages/shopify-app-remix/src/server/__test-helpers/get-hmac.ts +10 -0
  151. package/packages/shopify-app-remix/src/server/__test-helpers/get-jwt.ts +31 -0
  152. package/packages/shopify-app-remix/src/server/__test-helpers/get-thrown-response.ts +17 -0
  153. package/packages/shopify-app-remix/src/server/__test-helpers/index.ts +14 -0
  154. package/packages/shopify-app-remix/src/server/__test-helpers/request-mock.ts +169 -0
  155. package/packages/shopify-app-remix/src/server/__test-helpers/setup-valid-session.ts +45 -0
  156. package/packages/shopify-app-remix/src/server/__test-helpers/sign-request-cookie.ts +21 -0
  157. package/packages/shopify-app-remix/src/server/__test-helpers/test-config.ts +112 -0
  158. package/packages/shopify-app-remix/src/server/__tests__/override-logger.test.ts +101 -0
  159. package/packages/shopify-app-remix/src/server/__tests__/shopify-app.test.ts +119 -0
  160. package/packages/shopify-app-remix/src/server/adapters/__tests__/node-app-bridge-url.test.ts +18 -0
  161. package/packages/shopify-app-remix/src/server/adapters/__tests__/node.test.ts +28 -0
  162. package/packages/shopify-app-remix/src/server/adapters/node/__tests__/setup-jest.ts +10 -0
  163. package/packages/shopify-app-remix/src/server/adapters/node/index.ts +20 -0
  164. package/packages/shopify-app-remix/src/server/adapters/vercel/__tests__/setup-jest.ts +12 -0
  165. package/packages/shopify-app-remix/src/server/adapters/vercel/index.ts +13 -0
  166. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/admin-client.test.ts +181 -0
  167. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/doc-request-path.test.ts +151 -0
  168. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/exit-i-frame-path.test.ts +99 -0
  169. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/patch-session-token-path.test.ts +58 -0
  170. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/reject-bot.test.ts +23 -0
  171. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/respond-to-options.test.ts +50 -0
  172. package/packages/shopify-app-remix/src/server/authenticate/admin/__tests__/session-token-header-path.test.ts +91 -0
  173. package/packages/shopify-app-remix/src/server/authenticate/admin/authenticate.admin.doc.ts +37 -0
  174. package/packages/shopify-app-remix/src/server/authenticate/admin/authenticate.ts +201 -0
  175. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/cancel.test.ts +258 -0
  176. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/check.test.ts +254 -0
  177. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/mock-responses.ts +65 -0
  178. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/request.test.ts +373 -0
  179. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/__tests__/require.test.ts +316 -0
  180. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/authenticate.admin.billing.doc.ts +28 -0
  181. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/cancel.ts +37 -0
  182. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/check.ts +38 -0
  183. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/index.ts +4 -0
  184. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/request.ts +101 -0
  185. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/require.ts +56 -0
  186. package/packages/shopify-app-remix/src/server/authenticate/admin/billing/types.ts +383 -0
  187. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/__tests__/redirect.test.ts +313 -0
  188. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/__tests__/validate-redirect-url.test.ts +84 -0
  189. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/begin-auth.ts +17 -0
  190. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/create-admin-api-context.ts +22 -0
  191. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/ensure-app-is-embedded-if-required.ts +18 -0
  192. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/ensure-session-token-search-param-if-required.ts +25 -0
  193. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/handle-client-error.ts +43 -0
  194. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/index.ts +14 -0
  195. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-auth-page.ts +28 -0
  196. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-bounce-page.ts +23 -0
  197. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-shopify-or-app-root.ts +21 -0
  198. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-with-app-bridge-headers.ts +13 -0
  199. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-with-exitiframe.ts +28 -0
  200. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect.ts +83 -0
  201. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/render-app-bridge.ts +46 -0
  202. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/trigger-after-auth-hook.ts +28 -0
  203. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/validate-redirect-url.ts +67 -0
  204. package/packages/shopify-app-remix/src/server/authenticate/admin/helpers/validate-shop-and-host-params.ts +28 -0
  205. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/admin-client.test.ts +222 -0
  206. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/auth-callback-path.test.ts +395 -0
  207. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/auth-path.test.ts +83 -0
  208. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/authenticate.test.ts +183 -0
  209. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/ensure-installed-on-shop.test.ts +234 -0
  210. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/auth-code-flow/session-token-header-path.test.ts +79 -0
  211. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/token-exchange/admin-client.test.ts +189 -0
  212. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/__tests__/token-exchange/authenticate.test.ts +310 -0
  213. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/auth-code-flow.ts +333 -0
  214. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/token-exchange.ts +169 -0
  215. package/packages/shopify-app-remix/src/server/authenticate/admin/strategies/types.ts +29 -0
  216. package/packages/shopify-app-remix/src/server/authenticate/admin/types.ts +199 -0
  217. package/packages/shopify-app-remix/src/server/authenticate/const.ts +15 -0
  218. package/packages/shopify-app-remix/src/server/authenticate/flow/__tests__/authenticate.test.ts +142 -0
  219. package/packages/shopify-app-remix/src/server/authenticate/flow/authenticate.flow.doc.ts +34 -0
  220. package/packages/shopify-app-remix/src/server/authenticate/flow/authenticate.ts +71 -0
  221. package/packages/shopify-app-remix/src/server/authenticate/flow/types.ts +90 -0
  222. package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/add-response-headers.test.ts +25 -0
  223. package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/app-bridge-url.test.ts +21 -0
  224. package/packages/shopify-app-remix/src/server/authenticate/helpers/__tests__/idempotent-promise-handler.test.ts +104 -0
  225. package/packages/shopify-app-remix/src/server/authenticate/helpers/add-response-headers.ts +43 -0
  226. package/packages/shopify-app-remix/src/server/authenticate/helpers/app-bridge-url.ts +10 -0
  227. package/packages/shopify-app-remix/src/server/authenticate/helpers/ensure-cors-headers.ts +38 -0
  228. package/packages/shopify-app-remix/src/server/authenticate/helpers/get-session-token-header.ts +11 -0
  229. package/packages/shopify-app-remix/src/server/authenticate/helpers/idempotent-promise-handler.ts +45 -0
  230. package/packages/shopify-app-remix/src/server/authenticate/helpers/index.ts +8 -0
  231. package/packages/shopify-app-remix/src/server/authenticate/helpers/reject-bot-request.ts +13 -0
  232. package/packages/shopify-app-remix/src/server/authenticate/helpers/respond-to-invalid-session-token.ts +29 -0
  233. package/packages/shopify-app-remix/src/server/authenticate/helpers/respond-to-options-request.ts +26 -0
  234. package/packages/shopify-app-remix/src/server/authenticate/helpers/validate-session-token.ts +32 -0
  235. package/packages/shopify-app-remix/src/server/authenticate/login/__tests__/login.test.ts +157 -0
  236. package/packages/shopify-app-remix/src/server/authenticate/login/login.ts +53 -0
  237. package/packages/shopify-app-remix/src/server/authenticate/public/__tests__/factory.test.ts +224 -0
  238. package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/__tests__/authenticate.test.ts +282 -0
  239. package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.ts +36 -0
  240. package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/authenticate.ts +90 -0
  241. package/packages/shopify-app-remix/src/server/authenticate/public/appProxy/types.ts +164 -0
  242. package/packages/shopify-app-remix/src/server/authenticate/public/checkout/__tests__/authenticate.test.ts +142 -0
  243. package/packages/shopify-app-remix/src/server/authenticate/public/checkout/authenticate.public.checkout.doc.ts +23 -0
  244. package/packages/shopify-app-remix/src/server/authenticate/public/checkout/authenticate.ts +45 -0
  245. package/packages/shopify-app-remix/src/server/authenticate/public/checkout/types.ts +65 -0
  246. package/packages/shopify-app-remix/src/server/authenticate/public/factory.ts +49 -0
  247. package/packages/shopify-app-remix/src/server/authenticate/public/index.ts +1 -0
  248. package/packages/shopify-app-remix/src/server/authenticate/public/types.ts +77 -0
  249. package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/authenticate.test.ts +207 -0
  250. package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/mock-responses.ts +45 -0
  251. package/packages/shopify-app-remix/src/server/authenticate/webhooks/__tests__/register.test.ts +210 -0
  252. package/packages/shopify-app-remix/src/server/authenticate/webhooks/authenticate.ts +113 -0
  253. package/packages/shopify-app-remix/src/server/authenticate/webhooks/authenticate.webhooks.doc.ts +28 -0
  254. package/packages/shopify-app-remix/src/server/authenticate/webhooks/index.ts +1 -0
  255. package/packages/shopify-app-remix/src/server/authenticate/webhooks/register.ts +48 -0
  256. package/packages/shopify-app-remix/src/server/authenticate/webhooks/types.ts +246 -0
  257. package/packages/shopify-app-remix/src/server/boundary/__tests__/error.test.tsx +36 -0
  258. package/packages/shopify-app-remix/src/server/boundary/__tests__/headers.test.ts +66 -0
  259. package/packages/shopify-app-remix/src/server/boundary/error.tsx +14 -0
  260. package/packages/shopify-app-remix/src/server/boundary/headers.ts +15 -0
  261. package/packages/shopify-app-remix/src/server/boundary/index.ts +39 -0
  262. package/packages/shopify-app-remix/src/server/boundary/types.ts +4 -0
  263. package/packages/shopify-app-remix/src/server/clients/admin/authenticate.admin.api.doc.ts +34 -0
  264. package/packages/shopify-app-remix/src/server/clients/admin/factory.ts +30 -0
  265. package/packages/shopify-app-remix/src/server/clients/admin/graphql.ts +39 -0
  266. package/packages/shopify-app-remix/src/server/clients/admin/index.ts +2 -0
  267. package/packages/shopify-app-remix/src/server/clients/admin/rest.ts +157 -0
  268. package/packages/shopify-app-remix/src/server/clients/admin/types.ts +178 -0
  269. package/packages/shopify-app-remix/src/server/clients/index.ts +2 -0
  270. package/packages/shopify-app-remix/src/server/clients/storefront/authenticate.storefront.api.doc.ts +34 -0
  271. package/packages/shopify-app-remix/src/server/clients/storefront/factory.ts +32 -0
  272. package/packages/shopify-app-remix/src/server/clients/storefront/index.ts +2 -0
  273. package/packages/shopify-app-remix/src/server/clients/storefront/types.ts +31 -0
  274. package/packages/shopify-app-remix/src/server/clients/types.ts +27 -0
  275. package/packages/shopify-app-remix/src/server/config-types.ts +293 -0
  276. package/packages/shopify-app-remix/src/server/errors.ts +3 -0
  277. package/packages/shopify-app-remix/src/server/future/flags.ts +57 -0
  278. package/packages/shopify-app-remix/src/server/index.ts +20 -0
  279. package/packages/shopify-app-remix/src/server/override-logger.ts +42 -0
  280. package/packages/shopify-app-remix/src/server/shopify-app.doc.ts +45 -0
  281. package/packages/shopify-app-remix/src/server/shopify-app.ts +198 -0
  282. package/packages/shopify-app-remix/src/server/types.ts +509 -0
  283. package/packages/shopify-app-remix/src/server/unauthenticated/admin/__tests__/factory.test.ts +30 -0
  284. package/packages/shopify-app-remix/src/server/unauthenticated/admin/factory.ts +29 -0
  285. package/packages/shopify-app-remix/src/server/unauthenticated/admin/index.ts +1 -0
  286. package/packages/shopify-app-remix/src/server/unauthenticated/admin/types.ts +117 -0
  287. package/packages/shopify-app-remix/src/server/unauthenticated/admin/unauthenticated.admin.doc.ts +40 -0
  288. package/packages/shopify-app-remix/src/server/unauthenticated/helpers/get-offline-session.ts +13 -0
  289. package/packages/shopify-app-remix/src/server/unauthenticated/helpers/index.ts +1 -0
  290. package/packages/shopify-app-remix/src/server/unauthenticated/storefront/__tests__/factory.test.ts +30 -0
  291. package/packages/shopify-app-remix/src/server/unauthenticated/storefront/factory.ts +28 -0
  292. package/packages/shopify-app-remix/src/server/unauthenticated/storefront/index.ts +1 -0
  293. package/packages/shopify-app-remix/src/server/unauthenticated/storefront/types.ts +39 -0
  294. package/packages/shopify-app-remix/src/server/unauthenticated/storefront/unauthenticated.storefront.doc.ts +40 -0
  295. package/packages/shopify-app-remix/src/server/unauthenticated/types.ts +68 -0
  296. package/packages/shopify-app-remix/src/server/version.ts +1 -0
  297. package/packages/shopify-app-remix/tsconfig.json +11 -0
  298. package/packages/shopify-app-session-storage/CHANGELOG.md +149 -0
  299. package/packages/shopify-app-session-storage/LICENSE.md +9 -0
  300. package/packages/shopify-app-session-storage/README.md +5 -0
  301. package/packages/shopify-app-session-storage/implementing-session-storage.md +214 -0
  302. package/packages/shopify-app-session-storage/loom.config.ts +45 -0
  303. package/packages/shopify-app-session-storage/package.json +44 -0
  304. package/packages/shopify-app-session-storage/src/__tests__/setup-jest.ts +8 -0
  305. package/packages/shopify-app-session-storage/src/abstract-migration-engine.ts +53 -0
  306. package/packages/shopify-app-session-storage/src/index.ts +3 -0
  307. package/packages/shopify-app-session-storage/src/rdbms-session-storage-migrator.ts +59 -0
  308. package/packages/shopify-app-session-storage/src/types.ts +174 -0
  309. package/packages/shopify-app-session-storage/tsconfig.json +10 -0
  310. package/packages/shopify-app-session-storage-dynamodb/CHANGELOG.md +150 -0
  311. package/packages/shopify-app-session-storage-dynamodb/LICENSE.md +9 -0
  312. package/packages/shopify-app-session-storage-dynamodb/README.md +75 -0
  313. package/packages/shopify-app-session-storage-dynamodb/loom.config.ts +27 -0
  314. package/packages/shopify-app-session-storage-dynamodb/package.json +51 -0
  315. package/packages/shopify-app-session-storage-dynamodb/src/__tests__/dynamodb.test.ts +93 -0
  316. package/packages/shopify-app-session-storage-dynamodb/src/__tests__/setup-jest.ts +8 -0
  317. package/packages/shopify-app-session-storage-dynamodb/src/dynamodb.ts +126 -0
  318. package/packages/shopify-app-session-storage-dynamodb/tsconfig.json +10 -0
  319. package/packages/shopify-app-session-storage-kv/CHANGELOG.md +204 -0
  320. package/packages/shopify-app-session-storage-kv/LICENSE.md +9 -0
  321. package/packages/shopify-app-session-storage-kv/README.md +41 -0
  322. package/packages/shopify-app-session-storage-kv/loom.config.ts +27 -0
  323. package/packages/shopify-app-session-storage-kv/package.json +52 -0
  324. package/packages/shopify-app-session-storage-kv/src/__tests__/kv-namespace-dummy-worker.ts +8 -0
  325. package/packages/shopify-app-session-storage-kv/src/__tests__/kv.test.ts +22 -0
  326. package/packages/shopify-app-session-storage-kv/src/__tests__/setup-jest.ts +8 -0
  327. package/packages/shopify-app-session-storage-kv/src/kv.ts +87 -0
  328. package/packages/shopify-app-session-storage-kv/tsconfig.json +11 -0
  329. package/packages/shopify-app-session-storage-memory/CHANGELOG.md +190 -0
  330. package/packages/shopify-app-session-storage-memory/LICENSE.md +9 -0
  331. package/packages/shopify-app-session-storage-memory/README.md +19 -0
  332. package/packages/shopify-app-session-storage-memory/loom.config.ts +27 -0
  333. package/packages/shopify-app-session-storage-memory/package.json +46 -0
  334. package/packages/shopify-app-session-storage-memory/src/__tests__/memory.test.ts +12 -0
  335. package/packages/shopify-app-session-storage-memory/src/__tests__/setup-jest.ts +8 -0
  336. package/packages/shopify-app-session-storage-memory/src/memory.ts +34 -0
  337. package/packages/shopify-app-session-storage-memory/tsconfig.json +10 -0
  338. package/packages/shopify-app-session-storage-mongodb/CHANGELOG.md +208 -0
  339. package/packages/shopify-app-session-storage-mongodb/LICENSE.md +9 -0
  340. package/packages/shopify-app-session-storage-mongodb/README.md +30 -0
  341. package/packages/shopify-app-session-storage-mongodb/loom.config.ts +27 -0
  342. package/packages/shopify-app-session-storage-mongodb/package.json +49 -0
  343. package/packages/shopify-app-session-storage-mongodb/src/__tests__/mongodb.test.ts +54 -0
  344. package/packages/shopify-app-session-storage-mongodb/src/__tests__/setup-jest.ts +8 -0
  345. package/packages/shopify-app-session-storage-mongodb/src/mongodb.ts +120 -0
  346. package/packages/shopify-app-session-storage-mongodb/tsconfig.json +10 -0
  347. package/packages/shopify-app-session-storage-mysql/CHANGELOG.md +220 -0
  348. package/packages/shopify-app-session-storage-mysql/LICENSE.md +9 -0
  349. package/packages/shopify-app-session-storage-mysql/README.md +41 -0
  350. package/packages/shopify-app-session-storage-mysql/loom.config.ts +27 -0
  351. package/packages/shopify-app-session-storage-mysql/package.json +50 -0
  352. package/packages/shopify-app-session-storage-mysql/src/__tests__/mysql.test.ts +137 -0
  353. package/packages/shopify-app-session-storage-mysql/src/__tests__/setup-jest.ts +8 -0
  354. package/packages/shopify-app-session-storage-mysql/src/migrations.ts +18 -0
  355. package/packages/shopify-app-session-storage-mysql/src/mysql-connection.ts +108 -0
  356. package/packages/shopify-app-session-storage-mysql/src/mysql-migrator.ts +53 -0
  357. package/packages/shopify-app-session-storage-mysql/src/mysql.ts +178 -0
  358. package/packages/shopify-app-session-storage-mysql/tsconfig.json +10 -0
  359. package/packages/shopify-app-session-storage-postgresql/CHANGELOG.md +210 -0
  360. package/packages/shopify-app-session-storage-postgresql/LICENSE.md +9 -0
  361. package/packages/shopify-app-session-storage-postgresql/README.md +39 -0
  362. package/packages/shopify-app-session-storage-postgresql/loom.config.ts +27 -0
  363. package/packages/shopify-app-session-storage-postgresql/package.json +52 -0
  364. package/packages/shopify-app-session-storage-postgresql/src/__tests__/migrate-to-case-sensitivity.test.ts +344 -0
  365. package/packages/shopify-app-session-storage-postgresql/src/__tests__/postgresql.test.ts +136 -0
  366. package/packages/shopify-app-session-storage-postgresql/src/__tests__/setup-jest.ts +8 -0
  367. package/packages/shopify-app-session-storage-postgresql/src/migrations.ts +70 -0
  368. package/packages/shopify-app-session-storage-postgresql/src/postgres-connection.ts +94 -0
  369. package/packages/shopify-app-session-storage-postgresql/src/postgres-migrator.ts +27 -0
  370. package/packages/shopify-app-session-storage-postgresql/src/postgresql.ts +178 -0
  371. package/packages/shopify-app-session-storage-postgresql/tsconfig.json +10 -0
  372. package/packages/shopify-app-session-storage-prisma/CHANGELOG.md +148 -0
  373. package/packages/shopify-app-session-storage-prisma/LICENSE.md +9 -0
  374. package/packages/shopify-app-session-storage-prisma/README.md +68 -0
  375. package/packages/shopify-app-session-storage-prisma/loom.config.ts +27 -0
  376. package/packages/shopify-app-session-storage-prisma/package.json +51 -0
  377. package/packages/shopify-app-session-storage-prisma/prisma/migrations/20230425184828_init/migration.sql +11 -0
  378. package/packages/shopify-app-session-storage-prisma/prisma/migrations/20230906155758_mySession/migration.sql +11 -0
  379. package/packages/shopify-app-session-storage-prisma/prisma/migrations/migration_lock.toml +3 -0
  380. package/packages/shopify-app-session-storage-prisma/prisma/schema.prisma +30 -0
  381. package/packages/shopify-app-session-storage-prisma/src/__tests__/prisma.test.ts +66 -0
  382. package/packages/shopify-app-session-storage-prisma/src/__tests__/setup-jest.ts +8 -0
  383. package/packages/shopify-app-session-storage-prisma/src/prisma.ts +145 -0
  384. package/packages/shopify-app-session-storage-prisma/tsconfig.json +10 -0
  385. package/packages/shopify-app-session-storage-redis/CHANGELOG.md +200 -0
  386. package/packages/shopify-app-session-storage-redis/LICENSE.md +9 -0
  387. package/packages/shopify-app-session-storage-redis/README.md +38 -0
  388. package/packages/shopify-app-session-storage-redis/loom.config.ts +27 -0
  389. package/packages/shopify-app-session-storage-redis/package.json +50 -0
  390. package/packages/shopify-app-session-storage-redis/src/__tests__/migration-test-data.ts +46 -0
  391. package/packages/shopify-app-session-storage-redis/src/__tests__/redis.conf +2 -0
  392. package/packages/shopify-app-session-storage-redis/src/__tests__/redis.test.ts +236 -0
  393. package/packages/shopify-app-session-storage-redis/src/__tests__/setup-jest.ts +8 -0
  394. package/packages/shopify-app-session-storage-redis/src/migrations.ts +36 -0
  395. package/packages/shopify-app-session-storage-redis/src/redis-connection.ts +64 -0
  396. package/packages/shopify-app-session-storage-redis/src/redis-migrator.ts +58 -0
  397. package/packages/shopify-app-session-storage-redis/src/redis.ts +167 -0
  398. package/packages/shopify-app-session-storage-redis/tsconfig.json +10 -0
  399. package/packages/shopify-app-session-storage-sqlite/CHANGELOG.md +202 -0
  400. package/packages/shopify-app-session-storage-sqlite/LICENSE.md +9 -0
  401. package/packages/shopify-app-session-storage-sqlite/README.md +25 -0
  402. package/packages/shopify-app-session-storage-sqlite/loom.config.ts +27 -0
  403. package/packages/shopify-app-session-storage-sqlite/package.json +51 -0
  404. package/packages/shopify-app-session-storage-sqlite/src/__tests__/setup-jest.ts +8 -0
  405. package/packages/shopify-app-session-storage-sqlite/src/__tests__/sqlite.test.ts +44 -0
  406. package/packages/shopify-app-session-storage-sqlite/src/migrations.ts +54 -0
  407. package/packages/shopify-app-session-storage-sqlite/src/sqlite-connection.ts +80 -0
  408. package/packages/shopify-app-session-storage-sqlite/src/sqlite-migrator.ts +34 -0
  409. package/packages/shopify-app-session-storage-sqlite/src/sqlite.ts +147 -0
  410. package/packages/shopify-app-session-storage-sqlite/tsconfig.json +10 -0
  411. package/packages/shopify-app-session-storage-test-utils/CHANGELOG.md +185 -0
  412. package/packages/shopify-app-session-storage-test-utils/LICENSE.md +9 -0
  413. package/packages/shopify-app-session-storage-test-utils/loom.config.ts +27 -0
  414. package/packages/shopify-app-session-storage-test-utils/package.json +48 -0
  415. package/packages/shopify-app-session-storage-test-utils/src/__tests__/session-test-utils.test.ts +273 -0
  416. package/packages/shopify-app-session-storage-test-utils/src/battery-of-tests.ts +250 -0
  417. package/packages/shopify-app-session-storage-test-utils/src/index.ts +2 -0
  418. package/packages/shopify-app-session-storage-test-utils/src/session-test-utils.ts +24 -0
  419. package/packages/shopify-app-session-storage-test-utils/src/utils.ts +71 -0
  420. package/packages/shopify-app-session-storage-test-utils/tsconfig.json +10 -0
  421. package/tests/setup/build.js +1 -0
  422. package/tests/setup/setup-jest.ts +8 -0
  423. package/tsconfig.base.json +41 -0
  424. package/tsconfig.json +19 -0
@@ -0,0 +1,53 @@
1
+ import {redirect} from '@remix-run/server-runtime';
2
+
3
+ import {BasicParams, LoginError, LoginErrorType} from '../../types';
4
+
5
+ export function loginFactory(params: BasicParams) {
6
+ const {api, config, logger} = params;
7
+
8
+ return async function login(request: Request): Promise<LoginError | never> {
9
+ const url = new URL(request.url);
10
+ const shopParam = url.searchParams.get('shop');
11
+
12
+ if (request.method === 'GET' && !shopParam) {
13
+ return {};
14
+ }
15
+
16
+ const shop: string | null =
17
+ shopParam || ((await request.formData()).get('shop') as string);
18
+
19
+ if (!shop) {
20
+ logger.debug('Missing shop parameter', {shop});
21
+ return {shop: LoginErrorType.MissingShop};
22
+ }
23
+
24
+ const shopWithoutProtocol = shop
25
+ .replace(/^https?:\/\//, '')
26
+ .replace(/\/$/, '');
27
+ const shopWithDomain =
28
+ shop?.indexOf('.') === -1
29
+ ? `${shopWithoutProtocol}.myshopify.com`
30
+ : shopWithoutProtocol;
31
+ const sanitizedShop = api.utils.sanitizeShop(shopWithDomain);
32
+
33
+ if (!sanitizedShop) {
34
+ logger.debug('Invalid shop parameter', {shop});
35
+ return {shop: LoginErrorType.InvalidShop};
36
+ }
37
+
38
+ const authPath = `${config.appUrl}${config.auth.path}?shop=${sanitizedShop}`;
39
+
40
+ const adminPath = api.utils.legacyUrlToShopAdminUrl(sanitizedShop);
41
+ const installPath = `https://${adminPath}/oauth/install?client_id=${config.apiKey}`;
42
+
43
+ const shouldInstall =
44
+ config.isEmbeddedApp && config.future.unstable_newEmbeddedAuthStrategy;
45
+ const redirectUrl = shouldInstall ? installPath : authPath;
46
+
47
+ logger.info(`Redirecting login request to ${redirectUrl}`, {
48
+ shop: sanitizedShop,
49
+ });
50
+
51
+ throw redirect(redirectUrl);
52
+ };
53
+ }
@@ -0,0 +1,224 @@
1
+ import {shopifyApp} from '../../..';
2
+ import {
3
+ APP_URL,
4
+ getJwt,
5
+ getThrownResponse,
6
+ testConfig,
7
+ } from '../../../__test-helpers';
8
+
9
+ describe('Authenticate.public', () => {
10
+ describe('when v3_authenticatePublic is not set and authenticate.public() is called', () => {
11
+ it('logs that authenticate.public() is deprecated', async () => {
12
+ // GIVEN
13
+ const config = testConfig({
14
+ future: {
15
+ v3_authenticatePublic: false,
16
+ },
17
+ });
18
+ const shopify = shopifyApp(config);
19
+ const {token} = getJwt();
20
+
21
+ // WHEN
22
+ await shopify.authenticate.public(
23
+ new Request(APP_URL, {
24
+ headers: {
25
+ Authorization: `Bearer ${token}`,
26
+ },
27
+ }),
28
+ );
29
+
30
+ // THEN
31
+ expect(config.logger?.log).toHaveBeenCalledWith(
32
+ expect.any(Number),
33
+ expect.stringContaining(
34
+ 'authenticate.public() will be deprecated in v3. Use authenticate.public.checkout() instead.',
35
+ ),
36
+ );
37
+ });
38
+
39
+ it('returns token when successful', async () => {
40
+ // GIVEN
41
+ const shopify = shopifyApp(
42
+ testConfig({
43
+ future: {
44
+ v3_authenticatePublic: false,
45
+ },
46
+ }),
47
+ );
48
+ const {token, payload} = getJwt();
49
+
50
+ // WHEN
51
+ const {sessionToken} = await shopify.authenticate.public(
52
+ new Request(APP_URL, {
53
+ headers: {
54
+ Authorization: `Bearer ${token}`,
55
+ },
56
+ }),
57
+ );
58
+
59
+ // THEN
60
+ expect(sessionToken).toMatchObject(payload);
61
+ });
62
+
63
+ it('sets extra CORS allowed headers when requested from a different origin', async () => {
64
+ // GIVEN
65
+ const shopify = shopifyApp(
66
+ testConfig({
67
+ future: {
68
+ v3_authenticatePublic: false,
69
+ },
70
+ }),
71
+ );
72
+ const {token} = getJwt();
73
+
74
+ // WHEN
75
+ const {cors} = await shopify.authenticate.public(
76
+ new Request(APP_URL, {
77
+ headers: {
78
+ Origin: 'https://some-other.origin',
79
+ Authorization: `Bearer ${token}`,
80
+ },
81
+ }),
82
+ {corsHeaders: ['Content-Type', 'X-Extra-Header']},
83
+ );
84
+ const response = cors(new Response());
85
+
86
+ // THEN
87
+ expect(response.headers.get('Access-Control-Allow-Headers')).toBe(
88
+ 'Authorization, Content-Type, X-Extra-Header',
89
+ );
90
+ });
91
+
92
+ it('responds to preflight requests', async () => {
93
+ // GIVEN
94
+ const shopify = shopifyApp(
95
+ testConfig({
96
+ future: {
97
+ v3_authenticatePublic: false,
98
+ },
99
+ }),
100
+ );
101
+ const {token, payload} = getJwt();
102
+
103
+ // WHEN
104
+ const response = await getThrownResponse(
105
+ shopify.authenticate.public,
106
+ new Request(APP_URL, {
107
+ method: 'OPTIONS',
108
+ headers: {Authorization: `Bearer ${token}`},
109
+ }),
110
+ );
111
+
112
+ // THEN
113
+ expect(response.status).toBe(204);
114
+ });
115
+
116
+ it('responds to preflight requests from a different origin with extra CORS allowed headers', async () => {
117
+ // GIVEN
118
+ const shopify = shopifyApp(
119
+ testConfig({
120
+ future: {
121
+ v3_authenticatePublic: false,
122
+ },
123
+ }),
124
+ );
125
+ const {token} = getJwt();
126
+ const request = new Request(APP_URL, {
127
+ method: 'OPTIONS',
128
+ headers: {
129
+ Origin: 'https://some-other.origin',
130
+ Authorization: `Bearer ${token}`,
131
+ },
132
+ });
133
+
134
+ // WHEN
135
+ const response = await getThrownResponse(
136
+ async (request) =>
137
+ shopify.authenticate.public(request, {
138
+ corsHeaders: ['X-Extra-Header'],
139
+ }),
140
+ request,
141
+ );
142
+
143
+ // THEN
144
+ expect(response.status).toBe(204);
145
+ expect(response.headers.get('Access-Control-Allow-Headers')).toBe(
146
+ 'Authorization, Content-Type, X-Extra-Header',
147
+ );
148
+ });
149
+
150
+ it('throws a 401 on missing Authorization bearer token', async () => {
151
+ // GIVEN
152
+ const shopify = shopifyApp(
153
+ testConfig({
154
+ future: {
155
+ v3_authenticatePublic: false,
156
+ },
157
+ }),
158
+ );
159
+
160
+ // WHEN
161
+ const response = await getThrownResponse(
162
+ shopify.authenticate.public,
163
+ new Request(APP_URL),
164
+ );
165
+
166
+ // THEN
167
+ expect(response.status).toBe(401);
168
+ });
169
+
170
+ it('throws a 401 on invalid Authorization bearer token', async () => {
171
+ // GIVEN
172
+ const shopify = shopifyApp(
173
+ testConfig({
174
+ future: {
175
+ v3_authenticatePublic: false,
176
+ },
177
+ }),
178
+ );
179
+
180
+ // WHEN
181
+ const response = await getThrownResponse(
182
+ shopify.authenticate.public,
183
+ new Request(APP_URL, {
184
+ headers: {Authorization: `Bearer this_is_not_a_valid_token`},
185
+ }),
186
+ );
187
+
188
+ // THEN
189
+ expect(response.status).toBe(401);
190
+ });
191
+
192
+ it('rejects bot requests', async () => {
193
+ // GIVEN
194
+ const shopify = shopifyApp(
195
+ testConfig({
196
+ future: {
197
+ v3_authenticatePublic: false,
198
+ },
199
+ }),
200
+ );
201
+
202
+ // WHEN
203
+ const response = await getThrownResponse(
204
+ shopify.authenticate.public,
205
+ new Request(APP_URL, {
206
+ headers: {'User-Agent': 'Googlebot'},
207
+ }),
208
+ );
209
+
210
+ // THEN
211
+ expect(response.status).toBe(410);
212
+ });
213
+ });
214
+
215
+ describe('when v3_authenticatePublic is true', () => {
216
+ it('authenticate.public is an object not a function', async () => {
217
+ // GIVEN
218
+ const shopify = shopifyApp(testConfig());
219
+
220
+ // THEN
221
+ expect(typeof shopify.authenticate.public).toBe('object');
222
+ });
223
+ });
224
+ });
@@ -0,0 +1,282 @@
1
+ import {HashFormat, createSHA256HMAC} from '@shopify/shopify-api/runtime';
2
+
3
+ import {LATEST_API_VERSION, shopifyApp} from '../../../..';
4
+ import {
5
+ API_SECRET_KEY,
6
+ APP_URL,
7
+ TEST_SHOP,
8
+ expectAdminApiClient,
9
+ expectStorefrontApiClient,
10
+ getThrownResponse,
11
+ mockExternalRequest,
12
+ setUpValidSession,
13
+ testConfig,
14
+ } from '../../../../__test-helpers';
15
+
16
+ describe('authenticating app proxy requests', () => {
17
+ it('Throws a 400 response if there is no signature param', async () => {
18
+ // GIVEN
19
+ const shopify = shopifyApp(testConfig());
20
+
21
+ // WHEN
22
+ const url = new URL(APP_URL);
23
+ url.searchParams.set('shop', TEST_SHOP);
24
+ url.searchParams.set('timestamp', secondsInPast(10));
25
+
26
+ const response = await getThrownResponse(
27
+ shopify.authenticate.public.appProxy,
28
+ new Request(url.toString()),
29
+ );
30
+
31
+ // THEN
32
+ expect(response.status).toBe(400);
33
+ expect(response.statusText).toBe('Bad Request');
34
+ });
35
+
36
+ it('Throws a 400 response if the signature param is incorrect', async () => {
37
+ // GIVEN
38
+ const shopify = shopifyApp(testConfig());
39
+
40
+ // WHEN
41
+ const url = new URL(APP_URL);
42
+ url.searchParams.set('shop', TEST_SHOP);
43
+ url.searchParams.set('timestamp', secondsInPast(1));
44
+ url.searchParams.set('signature', 'not-the-right-signature');
45
+
46
+ const response = await getThrownResponse(
47
+ shopify.authenticate.public.appProxy,
48
+ new Request(url.toString()),
49
+ );
50
+
51
+ // THEN
52
+ expect(response.status).toBe(400);
53
+ expect(response.statusText).toBe('Bad Request');
54
+ });
55
+
56
+ it('Throws a 400 response if the timestamp is more than 90 seconds old', async () => {
57
+ // GIVEN
58
+ const shopify = shopifyApp(testConfig());
59
+
60
+ // WHEN
61
+ const url = new URL(APP_URL);
62
+ url.searchParams.set('shop', TEST_SHOP);
63
+ url.searchParams.set('timestamp', secondsInPast(100));
64
+ url.searchParams.set('signature', await createAppProxyHmac(url));
65
+
66
+ const response = await getThrownResponse(
67
+ shopify.authenticate.public.appProxy,
68
+ new Request(url.toString()),
69
+ );
70
+
71
+ // THEN
72
+ expect(response.status).toBe(400);
73
+ expect(response.statusText).toBe('Bad Request');
74
+ });
75
+
76
+ it('Throws a 400 response if the timestamp is more than 90 seconds in the future', async () => {
77
+ // GIVEN
78
+ const shopify = shopifyApp(testConfig());
79
+
80
+ // WHEN
81
+ const url = new URL(APP_URL);
82
+ url.searchParams.set('shop', TEST_SHOP);
83
+ url.searchParams.set('timestamp', secondsInFuture(100));
84
+ url.searchParams.set('signature', await createAppProxyHmac(url));
85
+
86
+ const response = await getThrownResponse(
87
+ shopify.authenticate.public.appProxy,
88
+ new Request(url.toString()),
89
+ );
90
+
91
+ // THEN
92
+ expect(response.status).toBe(400);
93
+ expect(response.statusText).toBe('Bad Request');
94
+ });
95
+
96
+ describe('Valid requests return a liquid helper', () => {
97
+ it('Returns a Response with Content-Type: application/liquid and status 200 by default', async () => {
98
+ // GIVEN
99
+ const config = testConfig();
100
+ const shopify = shopifyApp(config);
101
+
102
+ // WHEN
103
+ const {liquid} = await shopify.authenticate.public.appProxy(
104
+ await getValidRequest(),
105
+ );
106
+ const response = liquid('Liquid template {{shop.name}}');
107
+
108
+ // THEN
109
+ expect(response.status).toBe(200);
110
+ expect(await response.text()).toBe('Liquid template {{shop.name}}');
111
+ expect(response.headers.get('Content-Type')).toBe('application/liquid');
112
+ });
113
+
114
+ it('Returns a Response with status equal to init if init is number', async () => {
115
+ // GIVEN
116
+ const config = testConfig();
117
+ const shopify = shopifyApp(config);
118
+
119
+ // WHEN
120
+ const {liquid} = await shopify.authenticate.public.appProxy(
121
+ await getValidRequest(),
122
+ );
123
+ const response = liquid('Liquid template {{shop.name}}', 400);
124
+
125
+ // THEN
126
+ expect(response.status).toBe(400);
127
+ });
128
+
129
+ it('Returns a Response with properties from init in init is an object', async () => {
130
+ // GIVEN
131
+ const config = testConfig();
132
+ const shopify = shopifyApp(config);
133
+
134
+ // WHEN
135
+ const {liquid} = await shopify.authenticate.public.appProxy(
136
+ await getValidRequest(),
137
+ );
138
+ const response = liquid('Liquid template {{shop.name}}', {
139
+ headers: {
140
+ my: 'header',
141
+ },
142
+ status: 300,
143
+ statusText: 'Oops',
144
+ });
145
+
146
+ // THEN
147
+ expect(response.headers.get('my')).toBe('header');
148
+ expect(response.headers.get('Content-Type')).toBe('application/liquid');
149
+ expect(response.status).toBe(300);
150
+ expect(response.statusText).toBe('Oops');
151
+ });
152
+
153
+ it('Returns a Response body with layout {% layout none %} if layout is false', async () => {
154
+ // GIVEN
155
+ const config = testConfig();
156
+ const shopify = shopifyApp(config);
157
+
158
+ // WHEN
159
+ const {liquid} = await shopify.authenticate.public.appProxy(
160
+ await getValidRequest(),
161
+ );
162
+ const response = liquid('Liquid template {{shop.name}}', {
163
+ layout: false,
164
+ });
165
+
166
+ // THEN
167
+ expect(await response.text()).toBe(
168
+ '{% layout none %} Liquid template {{shop.name}}',
169
+ );
170
+ });
171
+
172
+ it('Returns a Response body combining layout and initOptions', async () => {
173
+ // GIVEN
174
+ const config = testConfig();
175
+ const shopify = shopifyApp(config);
176
+
177
+ // WHEN
178
+ const {liquid} = await shopify.authenticate.public.appProxy(
179
+ await getValidRequest(),
180
+ );
181
+ const response = liquid('Liquid template {{shop.name}}', {
182
+ status: 400,
183
+ layout: false,
184
+ });
185
+
186
+ // THEN
187
+ expect(response.status).toBe(400);
188
+ expect(await response.text()).toBe(
189
+ '{% layout none %} Liquid template {{shop.name}}',
190
+ );
191
+ });
192
+ });
193
+
194
+ describe('Valid requests with no session', () => {
195
+ it('Returns AppProxy Context ', async () => {
196
+ // GIVEN
197
+ const config = testConfig();
198
+ const shopify = shopifyApp(config);
199
+
200
+ // WHEN
201
+ const context = await shopify.authenticate.public.appProxy(
202
+ await getValidRequest(),
203
+ );
204
+
205
+ // THEN
206
+ expect(context).toStrictEqual({
207
+ session: undefined,
208
+ admin: undefined,
209
+ storefront: undefined,
210
+ liquid: expect.any(Function),
211
+ });
212
+ });
213
+ });
214
+
215
+ describe('Valid requests with a session return an admin API client', () => {
216
+ expectAdminApiClient(async () => {
217
+ const shopify = shopifyApp(testConfig());
218
+ const expectedSession = await setUpValidSession(shopify.sessionStorage, {
219
+ isOnline: false,
220
+ });
221
+
222
+ const {admin, session: actualSession} =
223
+ await shopify.authenticate.public.appProxy(await getValidRequest());
224
+
225
+ if (!admin) {
226
+ throw new Error('No admin client');
227
+ }
228
+
229
+ return {admin, expectedSession, actualSession};
230
+ });
231
+ });
232
+
233
+ describe('Valid requests with a session return a Storefront API client', () => {
234
+ expectStorefrontApiClient(async () => {
235
+ const shopify = shopifyApp(testConfig());
236
+ const expectedSession = await setUpValidSession(shopify.sessionStorage, {
237
+ isOnline: false,
238
+ });
239
+
240
+ const {storefront, session: actualSession} =
241
+ await shopify.authenticate.public.appProxy(await getValidRequest());
242
+
243
+ if (!storefront) {
244
+ throw new Error('No storefront client');
245
+ }
246
+
247
+ return {storefront, expectedSession, actualSession};
248
+ });
249
+ });
250
+ });
251
+
252
+ async function getValidRequest(): Promise<Request> {
253
+ const url = new URL(APP_URL);
254
+ url.searchParams.set('shop', TEST_SHOP);
255
+ url.searchParams.set('timestamp', secondsInPast(1));
256
+ url.searchParams.set('signature', await createAppProxyHmac(url));
257
+
258
+ return new Request(url.toString());
259
+ }
260
+
261
+ async function createAppProxyHmac(url: URL): Promise<string> {
262
+ const params = Object.fromEntries(url.searchParams.entries());
263
+ const string = Object.entries(params)
264
+ .sort(([val1], [val2]) => val1.localeCompare(val2))
265
+ .reduce((acc, [key, value]) => {
266
+ return `${acc}${key}=${Array.isArray(value) ? value.join(',') : value}`;
267
+ }, '');
268
+
269
+ return createSHA256HMAC(API_SECRET_KEY, string, HashFormat.Hex);
270
+ }
271
+
272
+ function secondsInPast(seconds: number): string {
273
+ const now = Math.trunc(Date.now() / 1000);
274
+
275
+ return String(now - seconds);
276
+ }
277
+
278
+ function secondsInFuture(seconds: number): string {
279
+ const now = Math.trunc(Date.now() / 1000);
280
+
281
+ return String(now + seconds);
282
+ }
@@ -0,0 +1,36 @@
1
+ import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
2
+
3
+ const data: ReferenceEntityTemplateSchema = {
4
+ name: 'App proxy',
5
+ description:
6
+ '[App proxies](/docs/apps/online-store/app-proxies) take requests to Shopify links, and redirect them to external links.' +
7
+ '\nThe `authenticate.public.appProxy` function validates requests made to app proxies, and returns a context to enable querying Shopify APIs.' +
8
+ '\n\n> Note: If the store has not installed the app, store-related properties such as `admin` or `storefront` will be `undefined`',
9
+ category: 'Authenticate',
10
+ subCategory: 'Public',
11
+ type: 'object',
12
+ isVisualComponent: false,
13
+ definitions: [
14
+ {
15
+ title: 'authenticate.public.appProxy',
16
+ description:
17
+ 'Authenticates requests coming to the app from Shopify app proxies.',
18
+ type: 'AuthenticateAppProxy',
19
+ },
20
+ ],
21
+ jsDocTypeExamples: ['AppProxyContextWithSession'],
22
+ related: [
23
+ {
24
+ name: 'Admin API context',
25
+ subtitle: 'Interact with the Admin API.',
26
+ url: '/docs/api/shopify-app-remix/apis/admin-api',
27
+ },
28
+ {
29
+ name: 'Storefront API context',
30
+ subtitle: 'Interact with the Storefront API.',
31
+ url: '/docs/api/shopify-app-remix/apis/storefront-api',
32
+ },
33
+ ],
34
+ };
35
+
36
+ export default data;
@@ -0,0 +1,90 @@
1
+ import {ShopifyRestResources} from '@shopify/shopify-api';
2
+
3
+ import {adminClientFactory, storefrontClientFactory} from '../../../clients';
4
+ import {BasicParams} from '../../../types';
5
+
6
+ import {
7
+ AppProxyContext,
8
+ AppProxyContextWithSession,
9
+ AuthenticateAppProxy,
10
+ LiquidResponseFunction,
11
+ } from './types';
12
+
13
+ export function authenticateAppProxyFactory<
14
+ Resources extends ShopifyRestResources,
15
+ >(params: BasicParams): AuthenticateAppProxy {
16
+ const {api, config, logger} = params;
17
+
18
+ return async function authenticate(
19
+ request,
20
+ ): Promise<AppProxyContext | AppProxyContextWithSession<Resources>> {
21
+ logger.info('Authenticating app proxy request');
22
+
23
+ const {searchParams} = new URL(request.url);
24
+ const query = Object.fromEntries(searchParams.entries());
25
+ let isValid = false;
26
+
27
+ try {
28
+ isValid = await api.utils.validateHmac(query, {
29
+ signator: 'appProxy',
30
+ });
31
+ } catch (error) {
32
+ logger.info(error.message);
33
+ throw new Response(undefined, {status: 400, statusText: 'Bad Request'});
34
+ }
35
+
36
+ if (!isValid) {
37
+ logger.info('App proxy request has invalid signature');
38
+ throw new Response(undefined, {
39
+ status: 400,
40
+ statusText: 'Bad Request',
41
+ });
42
+ }
43
+
44
+ const shop = searchParams.get('shop')!;
45
+ const sessionId = api.session.getOfflineId(shop);
46
+ const session = await config.sessionStorage.loadSession(sessionId);
47
+
48
+ if (!session) {
49
+ const context: AppProxyContext = {
50
+ liquid,
51
+ session: undefined,
52
+ admin: undefined,
53
+ storefront: undefined,
54
+ };
55
+
56
+ return context;
57
+ }
58
+
59
+ const context: AppProxyContextWithSession<Resources> = {
60
+ liquid,
61
+ session,
62
+ admin: adminClientFactory({params, session}),
63
+ storefront: storefrontClientFactory({params, session}),
64
+ };
65
+
66
+ return context;
67
+ };
68
+ }
69
+
70
+ const liquid: LiquidResponseFunction = (body, initAndOptions) => {
71
+ if (typeof initAndOptions !== 'object') {
72
+ return new Response(body, {
73
+ status: initAndOptions || 200,
74
+ headers: {
75
+ 'Content-Type': 'application/liquid',
76
+ },
77
+ });
78
+ }
79
+
80
+ const {layout, ...responseInit} = initAndOptions || {};
81
+ const responseBody = layout === false ? `{% layout none %} ${body}` : body;
82
+
83
+ const headers = new Headers(responseInit.headers);
84
+ headers.set('Content-Type', 'application/liquid');
85
+
86
+ return new Response(responseBody, {
87
+ ...responseInit,
88
+ headers,
89
+ });
90
+ };