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,68 @@
1
+ # Session Storage Adapter for Prisma
2
+
3
+ This package implements the `SessionStorage` interface that works with an instance of Prisma.
4
+
5
+ Session storage for prisma requires a `schema.prisma` with a Session table with at-least the following columns:
6
+
7
+ ```prisma
8
+ model Session {
9
+ id String @id
10
+ shop String
11
+ state String
12
+ isOnline Boolean @default(false)
13
+ scope String?
14
+ expires DateTime?
15
+ accessToken String
16
+ userId BigInt?
17
+ }
18
+ ```
19
+
20
+ You can then instantiate and use `PrismaSessionStorage` like so:
21
+
22
+ ```js
23
+ import {shopifyApp} from '@shopify/shopify-app-express';
24
+ import {PrismaSessionStorage} from '@shopify/shopify-app-session-storage-prisma';
25
+ import {PrismaClient} from '@prisma/client';
26
+
27
+ const prisma = new PrismaClient();
28
+ const storage = new PrismaSessionStorage(prisma);
29
+
30
+ const shopify = shopifyApp({
31
+ sessionStorage: storage,
32
+ // ...
33
+ });
34
+ ```
35
+
36
+ > **Note**: If you use [SQLite](https://sqlite.com) with Prisma note that sqlite is a local, file-based SQL database. It persists all tables to a single file on your local disk. As such, it’s simple to set up and is a great choice for getting started with Shopify App development. However, it won’t work when your app getting scaled across multiple instances because they would each create their own database.
37
+
38
+ If you prefer to use your own implementation of a session storage mechanism that is compatible with the `@shopify/shopify-app-express` package, see the [implementing session storage guide](https://github.com/Shopify/shopify-app-js/blob/main/packages/shopify-app-session-storage/implementing-session-storage.md).
39
+
40
+ ## Options
41
+
42
+ You can also pass in some optional flags to tweak the behavior of the adapter.
43
+
44
+ ### Custom table name
45
+
46
+ You can pass in the `tableName` option if you want to use a different table name in your schema.
47
+ For example:
48
+
49
+ ```ts
50
+ const storage = new PrismaSessionStorage(prisma, {
51
+ tableName: 'MyCustomSession',
52
+ });
53
+ ```
54
+
55
+ ## Troubleshooting
56
+
57
+ If there is an issue with your schema that prevents it from finding the `Session` table, this package will throw a `MissingSessionTableError`.
58
+ Some common reasons for that are:
59
+
60
+ 1. The database was not migrated.
61
+ 1. The `Session` table above was not added to the schema.
62
+ 1. The table is in the schema, but isn't named `Session`.
63
+
64
+ Here are some possible solutions for this issue:
65
+
66
+ 1. Ensure you've run [the `migrate` command](https://www.prisma.io/docs/reference/api-reference/command-reference#prisma-migrate) to apply the schema.
67
+ 1. Ensure you've copied the schema above into your `prisma.schema` file.
68
+ 1. If you've made changes to the table, make sure it's still called `Session`.
@@ -0,0 +1,27 @@
1
+ import {createPackage, createProjectPlugin} from '@shopify/loom';
2
+ import {buildLibrary} from '@shopify/loom-plugin-build-library';
3
+
4
+ export default createPackage((pkg) => {
5
+ pkg.entry({root: './src/prisma.ts'});
6
+ pkg.use(
7
+ buildLibrary({
8
+ // Required. A browserslist string for specifying your target output.
9
+ // Use browser targets (e.g. `'defaults'`) if your package targets the browser,
10
+ // node targets (e.g. `'node 12.22'`) if your package targets node
11
+ // or both (e.g.`'defaults, node 12.22'`) if your package targets both
12
+ targets: 'node 16',
13
+ // Optional. Defaults to false. Defines if commonjs outputs should be generated.
14
+ commonjs: true,
15
+ // Optional. Defaults to false. Defines if esmodules outputs should be generated.
16
+ esmodules: false,
17
+ // Optional. Defaults to false. Defines if esnext outputs should be generated.
18
+ esnext: false,
19
+ // Optional. Defaults to true. Defines if entrypoints should be written at
20
+ // the root of the repository. You can disable this if you have a single
21
+ // entrypoint or if your package uses the `exports` key in package.json
22
+ rootEntrypoints: false,
23
+ // Optional. Defaults to 'node'. Defines if the jest environment should be 'node' or 'jsdom'.
24
+ jestTestEnvironment: 'node',
25
+ }),
26
+ );
27
+ });
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@shopify/shopify-app-session-storage-prisma",
3
+ "version": "4.0.1",
4
+ "description": "Shopify App Session Storage for Prisma",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Shopify/shopify-app-js.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/Shopify/shopify-app-js/issues"
11
+ },
12
+ "homepage": "https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-prisma",
13
+ "author": "Shopify Inc.",
14
+ "license": "MIT",
15
+ "main": "./build/cjs/prisma.js",
16
+ "types": "./build/ts/prisma.d.ts",
17
+ "scripts": {},
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "keywords": [
22
+ "shopify",
23
+ "node",
24
+ "app",
25
+ "graphql",
26
+ "rest",
27
+ "webhook",
28
+ "Admin API",
29
+ "Storefront API",
30
+ "session storage",
31
+ "Prisma"
32
+ ],
33
+ "dependencies": {},
34
+ "peerDependencies": {
35
+ "@prisma/client": "^5.9.1",
36
+ "@shopify/shopify-api": "^9.3.2",
37
+ "@shopify/shopify-app-session-storage": "^2.1.1",
38
+ "prisma": "^5.8.1"
39
+ },
40
+ "devDependencies": {
41
+ "@prisma/client": "^5.9.1",
42
+ "@shopify/shopify-app-session-storage-test-utils": "^2.0.1",
43
+ "prisma": "^5.8.1"
44
+ },
45
+ "files": [
46
+ "build/*",
47
+ "!bundle/*",
48
+ "!tsconfig.tsbuildinfo",
49
+ "!node_modules"
50
+ ]
51
+ }
@@ -0,0 +1,11 @@
1
+ -- CreateTable
2
+ CREATE TABLE "Session" (
3
+ "id" TEXT NOT NULL PRIMARY KEY,
4
+ "shop" TEXT NOT NULL,
5
+ "state" TEXT NOT NULL,
6
+ "isOnline" BOOLEAN NOT NULL DEFAULT false,
7
+ "scope" TEXT,
8
+ "expires" DATETIME,
9
+ "accessToken" TEXT NOT NULL,
10
+ "userId" BIGINT
11
+ );
@@ -0,0 +1,11 @@
1
+ -- CreateTable
2
+ CREATE TABLE "MySession" (
3
+ "id" TEXT NOT NULL PRIMARY KEY,
4
+ "shop" TEXT NOT NULL,
5
+ "state" TEXT NOT NULL,
6
+ "isOnline" BOOLEAN NOT NULL DEFAULT false,
7
+ "scope" TEXT,
8
+ "expires" DATETIME,
9
+ "accessToken" TEXT NOT NULL,
10
+ "userId" BIGINT
11
+ );
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (i.e. Git)
3
+ provider = "sqlite"
@@ -0,0 +1,30 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "sqlite"
7
+ url = "file:test.db"
8
+ }
9
+
10
+ model Session {
11
+ id String @id
12
+ shop String
13
+ state String
14
+ isOnline Boolean @default(false)
15
+ scope String?
16
+ expires DateTime?
17
+ accessToken String
18
+ userId BigInt?
19
+ }
20
+
21
+ model MySession {
22
+ id String @id
23
+ shop String
24
+ state String
25
+ isOnline Boolean @default(false)
26
+ scope String?
27
+ expires DateTime?
28
+ accessToken String
29
+ userId BigInt?
30
+ }
@@ -0,0 +1,66 @@
1
+ import fs from 'fs';
2
+ import {execSync} from 'child_process';
3
+
4
+ import {batteryOfTests} from '@shopify/shopify-app-session-storage-test-utils';
5
+ import {PrismaClient} from '@prisma/client';
6
+
7
+ import {MissingSessionTableError, PrismaSessionStorage} from '../prisma';
8
+
9
+ describe('PrismaSessionStorage', () => {
10
+ let prisma: PrismaClient;
11
+
12
+ beforeAll(async () => {
13
+ // Reset the database prior to the tests
14
+ clearTestDatabase();
15
+
16
+ execSync('npx prisma migrate dev --name init --preview-feature');
17
+
18
+ prisma = new PrismaClient();
19
+ });
20
+
21
+ afterAll(async () => {
22
+ await prisma.session.deleteMany();
23
+ await prisma.mySession.deleteMany();
24
+ });
25
+
26
+ // Using the default table name
27
+ batteryOfTests(async () => new PrismaSessionStorage<PrismaClient>(prisma));
28
+
29
+ // Using a custom table name
30
+ batteryOfTests(
31
+ async () =>
32
+ new PrismaSessionStorage<PrismaClient>(prisma, {tableName: 'mySession'}),
33
+ );
34
+ });
35
+
36
+ describe('PrismaSessionStorage when with no database set up', () => {
37
+ beforeAll(async () => {
38
+ clearTestDatabase();
39
+ });
40
+
41
+ it('throws an appropriate error when Prisma migrations were not run', async () => {
42
+ const prisma = new PrismaClient();
43
+ const storage = new PrismaSessionStorage<PrismaClient>(prisma);
44
+
45
+ try {
46
+ await storage.findSessionsByShop('shop.myshopify.com');
47
+
48
+ // This should never be reached
49
+ expect(true).toBe(false);
50
+ } catch (error) {
51
+ expect(error).toBeInstanceOf(MissingSessionTableError);
52
+
53
+ const {cause} = error;
54
+ expect(cause.message).toContain(
55
+ 'The table `main.Session` does not exist in the current database.',
56
+ );
57
+ }
58
+ });
59
+ });
60
+
61
+ function clearTestDatabase() {
62
+ const testDbPath = `${__dirname}/../../prisma/test.db`;
63
+ if (fs.existsSync(testDbPath)) {
64
+ fs.unlinkSync(testDbPath);
65
+ }
66
+ }
@@ -0,0 +1,8 @@
1
+ import fetchMock from 'jest-fetch-mock';
2
+
3
+ // Globally disable fetch requests so we don't risk making real ones
4
+ fetchMock.enableMocks();
5
+
6
+ beforeEach(() => {
7
+ fetchMock.mockReset();
8
+ });
@@ -0,0 +1,145 @@
1
+ import {Session} from '@shopify/shopify-api';
2
+ import {SessionStorage} from '@shopify/shopify-app-session-storage';
3
+ import type {PrismaClient, Session as Row} from '@prisma/client';
4
+
5
+ interface PrismaSessionStorageOptions {
6
+ tableName?: string;
7
+ }
8
+
9
+ export class PrismaSessionStorage<T extends PrismaClient>
10
+ implements SessionStorage
11
+ {
12
+ private ready: Promise<any>;
13
+ private readonly tableName: string = 'session';
14
+
15
+ constructor(
16
+ private prisma: T,
17
+ {tableName}: PrismaSessionStorageOptions = {},
18
+ ) {
19
+ if (tableName) {
20
+ this.tableName = tableName;
21
+ }
22
+
23
+ if (this.getSessionTable() === undefined) {
24
+ throw new Error(`PrismaClient does not have a ${this.tableName} table`);
25
+ }
26
+ this.ready = this.getSessionTable()
27
+ .count()
28
+ .catch((cause) => {
29
+ throw new MissingSessionTableError(
30
+ `Prisma ${this.tableName} table does not exist. This could happen for a few reasons, see https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage-prisma#troubleshooting for more information`,
31
+ {cause},
32
+ );
33
+ });
34
+ }
35
+
36
+ public async storeSession(session: Session): Promise<boolean> {
37
+ await this.ready;
38
+
39
+ const data = this.sessionToRow(session);
40
+
41
+ await this.getSessionTable().upsert({
42
+ where: {id: session.id},
43
+ update: data,
44
+ create: data,
45
+ });
46
+
47
+ return true;
48
+ }
49
+
50
+ public async loadSession(id: string): Promise<Session | undefined> {
51
+ await this.ready;
52
+
53
+ const row = await this.getSessionTable().findUnique({
54
+ where: {id},
55
+ });
56
+
57
+ if (!row) {
58
+ return undefined;
59
+ }
60
+
61
+ return this.rowToSession(row);
62
+ }
63
+
64
+ public async deleteSession(id: string): Promise<boolean> {
65
+ await this.ready;
66
+
67
+ try {
68
+ await this.getSessionTable().delete({where: {id}});
69
+ } catch {
70
+ return true;
71
+ }
72
+
73
+ return true;
74
+ }
75
+
76
+ public async deleteSessions(ids: string[]): Promise<boolean> {
77
+ await this.ready;
78
+
79
+ await this.getSessionTable().deleteMany({where: {id: {in: ids}}});
80
+
81
+ return true;
82
+ }
83
+
84
+ public async findSessionsByShop(shop: string): Promise<Session[]> {
85
+ await this.ready;
86
+
87
+ const sessions = await this.getSessionTable().findMany({
88
+ where: {shop},
89
+ take: 25,
90
+ orderBy: [{expires: 'desc'}],
91
+ });
92
+
93
+ return sessions.map((session) => this.rowToSession(session));
94
+ }
95
+
96
+ private sessionToRow(session: Session): Row {
97
+ const sessionParams = session.toObject();
98
+
99
+ return {
100
+ id: session.id,
101
+ shop: session.shop,
102
+ state: session.state,
103
+ isOnline: session.isOnline,
104
+ scope: session.scope || null,
105
+ expires: session.expires || null,
106
+ accessToken: session.accessToken || '',
107
+ userId:
108
+ (sessionParams.onlineAccessInfo?.associated_user
109
+ .id as unknown as bigint) || null,
110
+ };
111
+ }
112
+
113
+ private rowToSession(row: Row): Session {
114
+ const sessionParams: Record<string, boolean | string | number> = {
115
+ id: row.id,
116
+ shop: row.shop,
117
+ state: row.state,
118
+ isOnline: row.isOnline,
119
+ };
120
+
121
+ if (row.expires) {
122
+ sessionParams.expires = row.expires.getTime();
123
+ }
124
+
125
+ if (row.scope) {
126
+ sessionParams.scope = row.scope;
127
+ }
128
+
129
+ if (row.accessToken) {
130
+ sessionParams.accessToken = row.accessToken;
131
+ }
132
+
133
+ if (row.userId) {
134
+ sessionParams.onlineAccessInfo = String(row.userId);
135
+ }
136
+
137
+ return Session.fromPropertyArray(Object.entries(sessionParams));
138
+ }
139
+
140
+ private getSessionTable(): T['session'] {
141
+ return (this.prisma as any)[this.tableName];
142
+ }
143
+ }
144
+
145
+ export class MissingSessionTableError extends Error {}
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "outDir": "./build/ts",
6
+ "rootDir": "src"
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["**/*.test.ts", "**/*.test.tsx", "**/test/*", "**/__tests__/*"]
10
+ }
@@ -0,0 +1,200 @@
1
+ # @shopify/shopify-app-session-storage-redis
2
+
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 02a8341: Updated dependency on `@shopify/shopify-api` to 9.3.1
8
+ - 321d6a4: Update @shopify/shopify-api to 9.3.2
9
+ - Updated dependencies [02a8341]
10
+ - Updated dependencies [321d6a4]
11
+ - @shopify/shopify-app-session-storage@2.1.1
12
+
13
+ ## 3.0.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 64e0246: Update shopify-api version to 9.2.0
18
+
19
+ ### Patch Changes
20
+
21
+ - 106d459: Updates redis from 4.6.11 to 4.6.12.
22
+ - f5742c1: Updated dependency on `@shopify/shopify-api`
23
+ - Updated dependencies [f5742c1]
24
+ - Updated dependencies [64e0246]
25
+ - @shopify/shopify-app-session-storage@2.1.0
26
+
27
+ ## 2.0.4
28
+
29
+ ### Patch Changes
30
+
31
+ - b4eeb24: Improved and simplified package.json dependencies
32
+ - b998c30: Bump shopify-api version from 9.0.1 to 9.0.2
33
+ - Updated dependencies [b4eeb24]
34
+ - Updated dependencies [b998c30]
35
+ - @shopify/shopify-app-session-storage@2.0.4
36
+
37
+ ## 2.0.3
38
+
39
+ ### Patch Changes
40
+
41
+ - d3e4b5e: Updated the dependency on `@shopify/shopify-api`
42
+ - Updated dependencies [d3e4b5e]
43
+ - @shopify/shopify-app-session-storage@2.0.3
44
+
45
+ ## 2.0.2
46
+
47
+ ### Patch Changes
48
+
49
+ - 3685bd4: Bump shopify-api to ^8.1.1
50
+ - Updated dependencies [3685bd4]
51
+ - @shopify/shopify-app-session-storage@2.0.2
52
+
53
+ ## 2.0.1
54
+
55
+ ### Patch Changes
56
+
57
+ - 6d12840: Updating dependencies on @shopify/shopify-api
58
+ - Updated dependencies [6d12840]
59
+ - @shopify/shopify-app-session-storage@2.0.1
60
+
61
+ ## 2.0.0
62
+
63
+ ### Major Changes
64
+
65
+ - f837060: **Removed support for Node 14**
66
+
67
+ Node 14 has reached its [EOL](https://endoflife.date/nodejs), and dependencies to this package no longer work on Node 14.
68
+ Because of that, we can no longer support that version.
69
+
70
+ If your app is running on Node 14, you'll need to update to a more recent version before upgrading this package.
71
+
72
+ This upgrade does not require any code changes.
73
+
74
+ ### Patch Changes
75
+
76
+ - a69d6fc: Updating dependency on @shopify/shopify-api to v.8.0.1
77
+ - Updated dependencies [f837060]
78
+ - Updated dependencies [a69d6fc]
79
+ - @shopify/shopify-app-session-storage@2.0.0
80
+
81
+ ## 1.1.10
82
+
83
+ ### Patch Changes
84
+
85
+ - 616388d: Updating dependency on @shopify/shopify-api to 7.7.0
86
+ - Updated dependencies [616388d]
87
+ - @shopify/shopify-app-session-storage@1.1.10
88
+
89
+ ## 1.1.9
90
+
91
+ ### Patch Changes
92
+
93
+ - 5b862fe: Upgraded shopify-api dependency to 7.6.0
94
+ - Updated dependencies [5b862fe]
95
+ - @shopify/shopify-app-session-storage@1.1.9
96
+
97
+ ## 1.1.8
98
+
99
+ ### Patch Changes
100
+
101
+ - 346b623: Updating dependency on @shopify/shopify-api
102
+ - Updated dependencies [346b623]
103
+ - @shopify/shopify-app-session-storage@1.1.8
104
+
105
+ ## 1.1.7
106
+
107
+ ### Patch Changes
108
+
109
+ - 13b9048: Updating @shopify/shopify-api dependency to the latest version
110
+ - Updated dependencies [13b9048]
111
+ - @shopify/shopify-app-session-storage@1.1.7
112
+
113
+ ## 1.1.6
114
+
115
+ ### Patch Changes
116
+
117
+ - 32296d7: Update @shopify/shopify-api dependency to 7.5.0
118
+ - Updated dependencies [32296d7]
119
+ - @shopify/shopify-app-session-storage@1.1.6
120
+
121
+ ## 1.1.5
122
+
123
+ ### Patch Changes
124
+
125
+ - 93e9126: Updating @shopify/shopify-api dependency
126
+ - Updated dependencies [93e9126]
127
+ - @shopify/shopify-app-session-storage@1.1.5
128
+
129
+ ## 1.1.4
130
+
131
+ ### Patch Changes
132
+
133
+ - b3453ff: Bumping @shopify/shopify-api dependency to latest version
134
+ - Updated dependencies [b3453ff]
135
+ - @shopify/shopify-app-session-storage@1.1.4
136
+
137
+ ## 1.1.3
138
+
139
+ ### Patch Changes
140
+
141
+ - e1d4f4f: Add @shopify/shopify-api as a peerDependencies entry for each session-storage package, to avoid API library conflicts (e.g., scopesArray.map error). Should help avoid issues like #93
142
+ - de5fa79: Bumps [redis](https://github.com/redis/node-redis) from 4.6.5 to 4.6.6. See redis' [release](https://github.com/redis/node-redis/releases/tag/redis@4.6.6) for more details.
143
+ - 1d007e8: Bumps [@shopify/shopify-api](https://github.com/Shopify/shopify-api-js) from 7.0.0 to 7.1.0. See `@shopify/shopify-api`'s [changelog](https://github.com/Shopify/shopify-api-js/blob/main/packages/shopify-api/CHANGELOG.md) for more details.
144
+ - Updated dependencies [e1d4f4f]
145
+ - Updated dependencies [1d007e8]
146
+ - @shopify/shopify-app-session-storage@1.1.3
147
+
148
+ ## 1.1.2
149
+
150
+ ### Patch Changes
151
+
152
+ - c9804ae: Bump redis from 4.6.4 to 4.6.5. See redis [release note](https://github.com/redis/node-redis/releases/tag/redis@4.6.5) for more details.
153
+ - e4f3415: Bump @shopify/shopify-api from 6.2.0 to 7.0.0. See [changelog](https://github.com/Shopify/shopify-api-js/blob/main/packages/shopify-api/CHANGELOG.md) for details.
154
+ - 27467d8: Add event handlers to redis client to prevent crashing on disconnect event. Fixes #129, #160 (Thanks to @davidhollenbeckx for linking to issue and solution.)
155
+ - Updated dependencies [e4f3415]
156
+ - @shopify/shopify-app-session-storage@1.1.2
157
+
158
+ ## 1.1.1
159
+
160
+ ### Patch Changes
161
+
162
+ - 97346b3: Fix #132: mysql migrator was unable to detect already applied migrations
163
+ - Updated dependencies [97346b3]
164
+ - @shopify/shopify-app-session-storage@1.1.1
165
+
166
+ ## 1.1.0
167
+
168
+ ### Minor Changes
169
+
170
+ - becc305: Migrations capabilities that can handle persistence changes for all session storage implementations
171
+
172
+ ### Patch Changes
173
+
174
+ - b6501b0: Bump typescript to 4.9.5
175
+ - Updated dependencies [b6501b0]
176
+ - Updated dependencies [becc305]
177
+ - @shopify/shopify-app-session-storage@1.1.0
178
+
179
+ ## 1.0.2
180
+
181
+ ### Patch Changes
182
+
183
+ - 222b755: Updating @shopify/shopify-api to v6.1.0
184
+ - Updated dependencies [222b755]
185
+ - @shopify/shopify-app-session-storage@1.0.2
186
+
187
+ ## 1.0.1
188
+
189
+ ### Patch Changes
190
+
191
+ - 1eccbd6: Optimize findSessionsByShop with additional shop-based key, listing array of corresponding session ids
192
+ - 866b50c: Update dependencies on shopify-api v6.0.2
193
+ - Updated dependencies [866b50c]
194
+ - @shopify/shopify-app-session-storage@1.0.1
195
+
196
+ ## 1.0.0
197
+
198
+ ### Major Changes
199
+
200
+ - Initial public release of @shopify/shopify-app-session-storage-redis
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present, Shopify Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Session Storage Adapter for Redis
2
+
3
+ This package implements the `SessionStorage` interface that works with an instance of [Redis](https://redis.io/).
4
+
5
+ ```js
6
+ import {shopifyApp} from '@shopify/shopify-app-express';
7
+ import {RedisSessionStorage} from '@shopify/shopify-app-session-storage-redis';
8
+
9
+ const shopify = shopifyApp({
10
+ sessionStorage: new RedisSessionStorage(
11
+ 'redis://username:password@host/database',
12
+ ),
13
+ // ...
14
+ });
15
+
16
+ // OR
17
+
18
+ const shopify = shopifyApp({
19
+ sessionStorage: new RedisSessionStorage(
20
+ new URL('redis://username:password@host/database'),
21
+ ),
22
+ // ...
23
+ });
24
+
25
+ // OR
26
+
27
+ const shopify = shopifyApp({
28
+ sessionStorage: RedisSessionStorage.withCredentials(
29
+ 'host.com',
30
+ 'thedatabase',
31
+ 'username',
32
+ 'password',
33
+ ),
34
+ // ...
35
+ });
36
+ ```
37
+
38
+ If you prefer to use your own implementation of a session storage mechanism that is compatible with the `@shopify/shopify-app-express` package, see the [implementing session storage guide](https://github.com/Shopify/shopify-app-js/blob/main/packages/shopify-app-session-storage/implementing-session-storage.md).