@shopify/shopify-app-remix 1.2.0 → 1.3.0

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.
Files changed (171) hide show
  1. package/README.md +6 -6
  2. package/build/cjs/react/components/AppProvider/AppProvider.js +35 -4
  3. package/build/cjs/server/authenticate/admin/billing/request.js +4 -2
  4. package/build/cjs/server/authenticate/public/appProxy/authenticate.js +7 -1
  5. package/build/cjs/server/boundary/index.js +6 -6
  6. package/build/cjs/server/clients/storefront/factory.js +35 -0
  7. package/build/cjs/server/shopify-app.js +7 -5
  8. package/build/cjs/server/types.js +1 -1
  9. package/build/cjs/server/unauthenticated/admin/factory.js +2 -2
  10. package/build/cjs/server/unauthenticated/helpers/get-offline-session.js +14 -0
  11. package/build/cjs/server/unauthenticated/storefront/factory.js +25 -0
  12. package/build/cjs/server/version.js +1 -1
  13. package/build/ts/react/components/AppProvider/AppProvider.d.ts +48 -8
  14. package/build/ts/react/components/AppProvider/AppProvider.d.ts.map +1 -1
  15. package/build/ts/react/components/AppProvider/AppProvider.doc.d.ts +4 -0
  16. package/build/ts/react/components/AppProvider/AppProvider.doc.d.ts.map +1 -0
  17. package/build/ts/react/components/AppProvider/AppProvider.doc.js +34 -0
  18. package/build/ts/react/components/AppProvider/AppProvider.doc.js.map +1 -0
  19. package/build/ts/react/components/AppProvider/AppProvider.js +35 -3
  20. package/build/ts/react/components/AppProvider/AppProvider.js.map +1 -1
  21. package/build/ts/server/__test-helpers/expect-admin-api-client.d.ts +1 -1
  22. package/build/ts/server/__test-helpers/expect-admin-api-client.d.ts.map +1 -1
  23. package/build/ts/server/__test-helpers/expect-storefront-api-client.d.ts +8 -0
  24. package/build/ts/server/__test-helpers/expect-storefront-api-client.d.ts.map +1 -0
  25. package/build/ts/server/__test-helpers/expect-storefront-api-client.js +57 -0
  26. package/build/ts/server/__test-helpers/expect-storefront-api-client.js.map +1 -0
  27. package/build/ts/server/__test-helpers/index.d.ts +1 -0
  28. package/build/ts/server/__test-helpers/index.d.ts.map +1 -1
  29. package/build/ts/server/__test-helpers/index.js +1 -0
  30. package/build/ts/server/__test-helpers/index.js.map +1 -1
  31. package/build/ts/server/authenticate/admin/authenticate.admin.doc.d.ts +4 -0
  32. package/build/ts/server/authenticate/admin/authenticate.admin.doc.d.ts.map +1 -0
  33. package/build/ts/server/authenticate/admin/authenticate.admin.doc.js +35 -0
  34. package/build/ts/server/authenticate/admin/authenticate.admin.doc.js.map +1 -0
  35. package/build/ts/server/authenticate/admin/authenticate.d.ts.map +1 -1
  36. package/build/ts/server/authenticate/admin/authenticate.js.map +1 -1
  37. package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.d.ts +4 -0
  38. package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.d.ts.map +1 -0
  39. package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.js +26 -0
  40. package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.js.map +1 -0
  41. package/build/ts/server/authenticate/admin/billing/request.d.ts +1 -1
  42. package/build/ts/server/authenticate/admin/billing/request.d.ts.map +1 -1
  43. package/build/ts/server/authenticate/admin/billing/request.js +2 -8
  44. package/build/ts/server/authenticate/admin/billing/request.js.map +1 -1
  45. package/build/ts/server/authenticate/admin/billing/types.d.ts +63 -55
  46. package/build/ts/server/authenticate/admin/billing/types.d.ts.map +1 -1
  47. package/build/ts/server/authenticate/admin/types.d.ts +66 -30
  48. package/build/ts/server/authenticate/admin/types.d.ts.map +1 -1
  49. package/build/ts/server/authenticate/helpers/add-response-headers.d.ts +2 -1
  50. package/build/ts/server/authenticate/helpers/add-response-headers.d.ts.map +1 -1
  51. package/build/ts/server/authenticate/helpers/add-response-headers.js.map +1 -1
  52. package/build/ts/server/authenticate/public/appProxy/authenticate.js +4 -2
  53. package/build/ts/server/authenticate/public/appProxy/authenticate.js.map +1 -1
  54. package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.d.ts +4 -0
  55. package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.d.ts.map +1 -0
  56. package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.js +32 -0
  57. package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.js.map +1 -0
  58. package/build/ts/server/authenticate/public/appProxy/types.d.ts +67 -11
  59. package/build/ts/server/authenticate/public/appProxy/types.d.ts.map +1 -1
  60. package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.d.ts +4 -0
  61. package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.d.ts.map +1 -0
  62. package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.js +21 -0
  63. package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.js.map +1 -0
  64. package/build/ts/server/authenticate/public/checkout/types.d.ts +15 -13
  65. package/build/ts/server/authenticate/public/checkout/types.d.ts.map +1 -1
  66. package/build/ts/server/authenticate/public/types.d.ts +19 -17
  67. package/build/ts/server/authenticate/public/types.d.ts.map +1 -1
  68. package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.d.ts +4 -0
  69. package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.d.ts.map +1 -0
  70. package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.js +20 -0
  71. package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.js.map +1 -0
  72. package/build/ts/server/authenticate/webhooks/types.d.ts +103 -0
  73. package/build/ts/server/authenticate/webhooks/types.d.ts.map +1 -1
  74. package/build/ts/server/boundary/index.d.ts +6 -6
  75. package/build/ts/server/boundary/index.js +6 -6
  76. package/build/ts/server/clients/admin/authenticate.admin.api.doc.d.ts +4 -0
  77. package/build/ts/server/clients/admin/authenticate.admin.api.doc.d.ts.map +1 -0
  78. package/build/ts/server/clients/admin/authenticate.admin.api.doc.js +32 -0
  79. package/build/ts/server/clients/admin/authenticate.admin.api.doc.js.map +1 -0
  80. package/build/ts/server/clients/admin/factory.d.ts +1 -1
  81. package/build/ts/server/clients/admin/factory.d.ts.map +1 -1
  82. package/build/ts/server/clients/admin/factory.js.map +1 -1
  83. package/build/ts/server/clients/admin/graphql.d.ts +3 -15
  84. package/build/ts/server/clients/admin/graphql.d.ts.map +1 -1
  85. package/build/ts/server/clients/admin/graphql.js.map +1 -1
  86. package/build/ts/server/clients/admin/index.d.ts +1 -0
  87. package/build/ts/server/clients/admin/index.d.ts.map +1 -1
  88. package/build/ts/server/clients/admin/index.js +1 -0
  89. package/build/ts/server/clients/admin/index.js.map +1 -1
  90. package/build/ts/server/clients/admin/rest.d.ts +1 -1
  91. package/build/ts/server/clients/admin/rest.d.ts.map +1 -1
  92. package/build/ts/server/clients/admin/types.d.ts +105 -1
  93. package/build/ts/server/clients/admin/types.d.ts.map +1 -1
  94. package/build/ts/server/clients/index.d.ts +3 -0
  95. package/build/ts/server/clients/index.d.ts.map +1 -0
  96. package/build/ts/server/clients/index.js +6 -0
  97. package/build/ts/server/clients/index.js.map +1 -0
  98. package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.d.ts +4 -0
  99. package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.d.ts.map +1 -0
  100. package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.js +32 -0
  101. package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.js.map +1 -0
  102. package/build/ts/server/clients/storefront/factory.d.ts +8 -0
  103. package/build/ts/server/clients/storefront/factory.d.ts.map +1 -0
  104. package/build/ts/server/clients/storefront/factory.js +39 -0
  105. package/build/ts/server/clients/storefront/factory.js.map +1 -0
  106. package/build/ts/server/clients/storefront/index.d.ts +3 -0
  107. package/build/ts/server/clients/storefront/index.d.ts.map +1 -0
  108. package/build/ts/server/clients/storefront/index.js +6 -0
  109. package/build/ts/server/clients/storefront/index.js.map +1 -0
  110. package/build/ts/server/clients/storefront/types.d.ts +29 -0
  111. package/build/ts/server/clients/storefront/types.d.ts.map +1 -0
  112. package/build/ts/server/clients/storefront/types.js +3 -0
  113. package/build/ts/server/clients/storefront/types.js.map +1 -0
  114. package/build/ts/server/clients/types.d.ts +15 -0
  115. package/build/ts/server/clients/types.d.ts.map +1 -0
  116. package/build/ts/server/clients/types.js +3 -0
  117. package/build/ts/server/clients/types.js.map +1 -0
  118. package/build/ts/server/config-types.d.ts +26 -117
  119. package/build/ts/server/config-types.d.ts.map +1 -1
  120. package/build/ts/server/shopify-app.d.ts +3 -3
  121. package/build/ts/server/shopify-app.d.ts.map +1 -1
  122. package/build/ts/server/shopify-app.doc.d.ts +4 -0
  123. package/build/ts/server/shopify-app.doc.d.ts.map +1 -0
  124. package/build/ts/server/shopify-app.doc.js +36 -0
  125. package/build/ts/server/shopify-app.doc.js.map +1 -0
  126. package/build/ts/server/shopify-app.js +6 -4
  127. package/build/ts/server/shopify-app.js.map +1 -1
  128. package/build/ts/server/types.d.ts +200 -168
  129. package/build/ts/server/types.d.ts.map +1 -1
  130. package/build/ts/server/types.js.map +1 -1
  131. package/build/ts/server/unauthenticated/admin/factory.d.ts.map +1 -1
  132. package/build/ts/server/unauthenticated/admin/factory.js +3 -4
  133. package/build/ts/server/unauthenticated/admin/factory.js.map +1 -1
  134. package/build/ts/server/unauthenticated/admin/types.d.ts +9 -7
  135. package/build/ts/server/unauthenticated/admin/types.d.ts.map +1 -1
  136. package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.d.ts +4 -0
  137. package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.d.ts.map +1 -0
  138. package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.js +29 -0
  139. package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.js.map +1 -0
  140. package/build/ts/server/unauthenticated/helpers/get-offline-session.d.ts +4 -0
  141. package/build/ts/server/unauthenticated/helpers/get-offline-session.d.ts.map +1 -0
  142. package/build/ts/server/unauthenticated/helpers/get-offline-session.js +22 -0
  143. package/build/ts/server/unauthenticated/helpers/get-offline-session.js.map +1 -0
  144. package/build/ts/server/unauthenticated/helpers/index.d.ts +2 -0
  145. package/build/ts/server/unauthenticated/helpers/index.d.ts.map +1 -0
  146. package/build/ts/server/unauthenticated/helpers/index.js +5 -0
  147. package/build/ts/server/unauthenticated/helpers/index.js.map +1 -0
  148. package/build/ts/server/unauthenticated/storefront/factory.d.ts +4 -0
  149. package/build/ts/server/unauthenticated/storefront/factory.d.ts.map +1 -0
  150. package/build/ts/server/unauthenticated/storefront/factory.js +29 -0
  151. package/build/ts/server/unauthenticated/storefront/factory.js.map +1 -0
  152. package/build/ts/server/unauthenticated/storefront/index.d.ts +2 -0
  153. package/build/ts/server/unauthenticated/storefront/index.d.ts.map +1 -0
  154. package/build/ts/server/unauthenticated/storefront/index.js +5 -0
  155. package/build/ts/server/unauthenticated/storefront/index.js.map +1 -0
  156. package/build/ts/server/unauthenticated/storefront/types.d.ts +34 -0
  157. package/build/ts/server/unauthenticated/storefront/types.d.ts.map +1 -0
  158. package/build/ts/server/unauthenticated/storefront/types.js +3 -0
  159. package/build/ts/server/unauthenticated/storefront/types.js.map +1 -0
  160. package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.d.ts +4 -0
  161. package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.d.ts.map +1 -0
  162. package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.js +29 -0
  163. package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.js.map +1 -0
  164. package/build/ts/server/unauthenticated/types.d.ts +66 -0
  165. package/build/ts/server/unauthenticated/types.d.ts.map +1 -0
  166. package/build/ts/server/unauthenticated/types.js +3 -0
  167. package/build/ts/server/unauthenticated/types.js.map +1 -0
  168. package/build/ts/server/version.d.ts +1 -1
  169. package/build/ts/server/version.js +1 -1
  170. package/build/tsconfig.tsbuildinfo +1 -1
  171. package/package.json +9 -4
package/README.md CHANGED
@@ -24,11 +24,11 @@ The easiest way to get started with developing Shopify apps is using the [Shopif
24
24
  It helps you set up your environment for developing and publishing your apps and extensions.
25
25
 
26
26
  We strongly recommend using the CLI to create and manage your Remix apps and extensions!
27
- See the [getting started documentation](https://shopify.dev/docs/apps/getting-started/create) to create your app using the Shopify CLI.
27
+ Refer to the [getting started documentation](https://shopify.dev/docs/apps/getting-started/create) to create your app using the Shopify CLI.
28
28
 
29
29
  ### Using a plain Remix app
30
30
 
31
- This package works with any Remix app. If you're starting an app from scratch, you can create a brand new Remix app that uses the indie-stack:
31
+ This package works with any Remix app. If you're starting an app from scratch, then you can create a brand new Remix app that uses the indie-stack:
32
32
 
33
33
  ```bash
34
34
  npx create-remix@latest --template remix-run/indie-stack
@@ -142,7 +142,7 @@ export default function App() {
142
142
  }
143
143
  ```
144
144
 
145
- This component will set up [Polaris](https://polaris.shopify.com/components/utilities/app-provider) and [App Bridge](https://shopify.dev/tools/app-bridge). If your app is not embedded, set the `isEmbeddedApp` prop to `false`.
145
+ This component will set up [Polaris](https://polaris.shopify.com/components/utilities/app-provider) and [App Bridge](https://shopify.dev/tools/app-bridge). If your app isn't embedded, set the `isEmbeddedApp` prop to `false`.
146
146
 
147
147
  Now that your app is ready to respond to requests, it will also need to add the required `Content-Security-Policy` header directives, as per [our documentation](https://shopify.dev/docs/apps/store/security/iframe-protection).
148
148
  To do that, this package provides the `shopify.addDocumentResponseHeaders` method.
@@ -179,7 +179,7 @@ import '@shopify/shopify-app-remix/server/adapters/node';
179
179
  ```
180
180
 
181
181
  before calling `shopifyApp`.
182
- If you're running on a runtime other than Node, you can simply omit that line.
182
+ If you're running on a runtime other than Node, then you can simply omit that line.
183
183
 
184
184
  ## Loading your app in admin
185
185
 
@@ -210,7 +210,7 @@ If there is no session for the user, the loader will throw the appropriate redir
210
210
 
211
211
  ## Authenticating cross-origin admin requests
212
212
 
213
- If your Remix server is authenticating an admin extension, a request from the extension to Remix will be cross-origin. Here `shopify.authenticate.admin` provides a cors function to add the required cross-origin headers:
213
+ If your Remix server is authenticating an admin extension, a request from the extension to Remix is cross-origin. Here `shopify.authenticate.admin` provides a cors function to add the required cross-origin headers:
214
214
 
215
215
  ```ts
216
216
  export const loader = async ({request}: LoaderArgs) => {
@@ -387,7 +387,7 @@ export const loader = async ({request}: LoaderArgs) => {
387
387
 
388
388
  This can be useful if your app exposes checkout or theme extensions and those extensions need to access data from your app.
389
389
 
390
- **Note:** These requests will be cross-origin. So you must use the cross-origin helper returned from `shopify.authenticate.public`.
390
+ **Note:** These requests are cross-origin, so you must use the cross-origin helper returned from `shopify.authenticate.public`.
391
391
 
392
392
  ## Session Storage
393
393
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('react');
6
5
  var polaris = require('@shopify/polaris');
7
6
  var englishI18n = require('@shopify/polaris/locales/en.json');
8
7
  var _const = require('../../const.js');
@@ -14,13 +13,18 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
13
  var englishI18n__default = /*#__PURE__*/_interopDefaultLegacy(englishI18n);
15
14
 
16
15
  /**
17
- * Sets up the Polaris AppProvider and injects the App Bridge script.
16
+ * Sets up the Polaris `AppProvider` and injects the App Bridge script.
17
+ *
18
+ * This component extends the [`AppProvider`](https://polaris.shopify.com/components/utilities/app-provider) component
19
+ * from Polaris, and accepts all of its props except for `linkComponent`, which is overridden to use the Remix `Link`
20
+ * component.
18
21
  *
19
22
  * {@link https://polaris.shopify.com/components/utilities/app-provider}
20
23
  * {@link https://shopify.dev/tools/app-bridge}
21
24
  *
22
25
  * @example
23
- * Wrap your app in the `AppProvider` component and pass in your API key.
26
+ * <caption>Set up AppProvider.</caption>
27
+ * <description>Wrap your app in the `AppProvider` component and pass in your API key.</description>
24
28
  * ```ts
25
29
  * import {authenticate} from '~/shopify.server';
26
30
  * import {AppProvider} from '@shopify/shopify-app-remix/react';
@@ -35,7 +39,34 @@ var englishI18n__default = /*#__PURE__*/_interopDefaultLegacy(englishI18n);
35
39
  * const { apiKey } = useLoaderData();
36
40
  *
37
41
  * return (
38
- * <AppProvider apiKey={apiKey}>
42
+ * <AppProvider isEmbeddedApp apiKey={apiKey}>
43
+ * <Outlet />
44
+ * </AppProvider>
45
+ * );
46
+ * }
47
+ * ```
48
+ *
49
+ * @example
50
+ * <caption>Localize Polaris components.</caption>
51
+ * <description>Pass in a different locale for Polaris to translate its components.</description>
52
+ * ```ts
53
+ * import {authenticate} from '~/shopify.server';
54
+ * import {AppProvider} from '@shopify/shopify-app-remix/react';
55
+ *
56
+ * export async function loader({ request }) {
57
+ * await authenticate.admin(request);
58
+ *
59
+ * return json({
60
+ * apiKey: process.env.SHOPIFY_API_KEY,
61
+ * polarisTranslations: require("@shopify/polaris/locales/fr.json"),
62
+ * });
63
+ * }
64
+ *
65
+ * export default function App() {
66
+ * const { apiKey, polarisTranslations } = useLoaderData();
67
+ *
68
+ * return (
69
+ * <AppProvider apiKey={apiKey} i18n={polarisTranslations}>
39
70
  * <Outlet />
40
71
  * </AppProvider>
41
72
  * );
@@ -11,7 +11,8 @@ function requestBillingFactory(params, request, session) {
11
11
  return async function requestBilling({
12
12
  plan,
13
13
  isTest,
14
- returnUrl
14
+ returnUrl,
15
+ ...overrides
15
16
  }) {
16
17
  const {
17
18
  api,
@@ -30,7 +31,8 @@ function requestBillingFactory(params, request, session) {
30
31
  session,
31
32
  isTest,
32
33
  returnUrl,
33
- returnObject: true
34
+ returnObject: true,
35
+ ...overrides
34
36
  });
35
37
  } catch (error) {
36
38
  if (error instanceof shopifyApi.HttpResponseError && error.response.code === 401) {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var factory = require('../../../clients/admin/factory.js');
6
+ var factory$1 = require('../../../clients/storefront/factory.js');
6
7
 
7
8
  function authenticateAppProxyFactory(params) {
8
9
  const {
@@ -42,7 +43,8 @@ function authenticateAppProxyFactory(params) {
42
43
  const context = {
43
44
  liquid,
44
45
  session: undefined,
45
- admin: undefined
46
+ admin: undefined,
47
+ storefront: undefined
46
48
  };
47
49
  return context;
48
50
  }
@@ -52,6 +54,10 @@ function authenticateAppProxyFactory(params) {
52
54
  admin: factory.adminClientFactory({
53
55
  params,
54
56
  session
57
+ }),
58
+ storefront: factory$1.storefrontClientFactory({
59
+ params,
60
+ session
55
61
  })
56
62
  };
57
63
  return context;
@@ -13,10 +13,10 @@ const boundary = {
13
13
  * A function that handles errors or thrown responses.
14
14
  *
15
15
  * @example
16
- * Catching errors in a route
16
+ * <caption>Catching errors in a route</caption>
17
17
  * ```ts
18
- * // app/routes/admin/widgets.ts
19
- * import { boundary } from "@shopify/shopify-app-remix";
18
+ * // /app/routes/admin/widgets.ts
19
+ * import { boundary } from "@shopify/shopify-app-remix/server";
20
20
  *
21
21
  * export function ErrorBoundary() {
22
22
  * return boundary.error(useRouteError());
@@ -28,10 +28,10 @@ const boundary = {
28
28
  * A function that sets the appropriate document repsonse headers.
29
29
  *
30
30
  * @example
31
- * Catching errors in a route
31
+ * <caption>Catching errors in a route</caption>
32
32
  * ```ts
33
- * // app/routes/admin/widgets.ts
34
- * import { boundary } from "@shopify/shopify-app-remix";
33
+ * // /app/routes/admin/widgets.ts
34
+ * import { boundary } from "@shopify/shopify-app-remix/server";
35
35
  *
36
36
  * export const headers = (headersArgs) => {
37
37
  * return boundary.headers(headersArgs);
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var runtime = require('@shopify/shopify-api/runtime');
6
+
7
+ function storefrontClientFactory({
8
+ params,
9
+ session
10
+ }) {
11
+ const {
12
+ api
13
+ } = params;
14
+ return {
15
+ graphql: async (query, options = {}) => {
16
+ const client = new api.clients.Storefront({
17
+ session,
18
+ apiVersion: options.apiVersion
19
+ });
20
+ const apiResponse = await client.query({
21
+ data: {
22
+ query,
23
+ variables: options === null || options === void 0 ? void 0 : options.variables
24
+ },
25
+ tries: options.tries,
26
+ extraHeaders: options.headers
27
+ });
28
+ return new Response(JSON.stringify(apiResponse.body), {
29
+ headers: runtime.flatHeaders(apiResponse.headers)
30
+ });
31
+ }
32
+ };
33
+ }
34
+
35
+ exports.storefrontClientFactory = storefrontClientFactory;
@@ -15,17 +15,18 @@ require('isbot');
15
15
  var login = require('./authenticate/login/login.js');
16
16
  var factory$1 = require('./unauthenticated/admin/factory.js');
17
17
  var factory = require('./authenticate/public/factory.js');
18
+ var factory$2 = require('./unauthenticated/storefront/factory.js');
18
19
 
19
20
  /**
20
21
  * Creates an object your app will use to interact with Shopify.
21
22
  *
22
- * @param appConfig Configuration options for your shopify app. For example, the scopes your app needs.
23
+ * @param appConfig Configuration options for your Shopify app, such as the scopes your app needs.
23
24
  * @returns `ShopifyApp` An object constructed using your appConfig. It has methods for interacting with Shopify.
24
25
  *
25
26
  * @example
26
- * The minimum viable configuration
27
+ * <caption>The minimum viable configuration</caption>
27
28
  * ```ts
28
- * import { shopifyApp } from "@shopify/shopify-app-remix";
29
+ * import { shopifyApp } from "@shopify/shopify-app-remix/server";
29
30
  *
30
31
  * const shopify = shopifyApp({
31
32
  * apiKey: process.env.SHOPIFY_API_KEY!,
@@ -59,7 +60,8 @@ function shopifyApp(appConfig) {
59
60
  webhook: authenticate.authenticateWebhookFactory(params)
60
61
  },
61
62
  unauthenticated: {
62
- admin: factory$1.unauthenticatedAdminContextFactory(params)
63
+ admin: factory$1.unauthenticatedAdminContextFactory(params),
64
+ storefront: factory$2.unauthenticatedStorefrontContextFactory(params)
63
65
  }
64
66
  };
65
67
  if (isAppStoreApp(shopify, appConfig) || isSingleMerchantApp(shopify, appConfig)) {
@@ -106,7 +108,7 @@ function deriveApi(appConfig) {
106
108
  function deriveConfig(appConfig, apiConfig) {
107
109
  var _appConfig$distributi, _appConfig$useOnlineT, _appConfig$hooks;
108
110
  if (!appConfig.sessionStorage) {
109
- throw new shopifyApi.ShopifyError('Please provide a valid session storage. See https://github.com/Shopify/shopify-app-js/blob/main/README.md#session-storage-options for options.');
111
+ throw new shopifyApi.ShopifyError('Please provide a valid session storage. Refer to https://github.com/Shopify/shopify-app-js/blob/main/README.md#session-storage-options for options.');
110
112
  }
111
113
  const authPathPrefix = appConfig.authPathPrefix || '/auth';
112
114
  appConfig.distribution = (_appConfig$distributi = appConfig.distribution) !== null && _appConfig$distributi !== void 0 ? _appConfig$distributi : types.AppDistribution.AppStore;
@@ -19,7 +19,7 @@ let LoginErrorType = /*#__PURE__*/function (LoginErrorType) {
19
19
  /**
20
20
  * An object your app can use to interact with Shopify.
21
21
  *
22
- * By default, the app's distribution will be AppStore.
22
+ * By default, the app's distribution is `AppStore`.
23
23
  */
24
24
 
25
25
  exports.AppDistribution = AppDistribution;
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var shopifyApi = require('@shopify/shopify-api');
6
6
  var factory = require('../../clients/admin/factory.js');
7
+ var getOfflineSession = require('../helpers/get-offline-session.js');
7
8
 
8
9
  function unauthenticatedAdminContextFactory(params) {
9
10
  return async shop => {
10
- const offlineSessionId = params.api.session.getOfflineId(shop);
11
- const session = await params.config.sessionStorage.loadSession(offlineSessionId);
11
+ const session = await getOfflineSession.getOfflineSession(shop, params);
12
12
  if (!session) {
13
13
  throw new shopifyApi.ShopifyError(`Could not find a session for shop ${shop} when creating unauthenticated admin context`);
14
14
  }
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ async function getOfflineSession(shop, {
6
+ api,
7
+ config
8
+ }) {
9
+ const offlineSessionId = api.session.getOfflineId(shop);
10
+ const session = await config.sessionStorage.loadSession(offlineSessionId);
11
+ return session;
12
+ }
13
+
14
+ exports.getOfflineSession = getOfflineSession;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var shopifyApi = require('@shopify/shopify-api');
6
+ var factory = require('../../clients/storefront/factory.js');
7
+ var getOfflineSession = require('../helpers/get-offline-session.js');
8
+
9
+ function unauthenticatedStorefrontContextFactory(params) {
10
+ return async shop => {
11
+ const session = await getOfflineSession.getOfflineSession(shop, params);
12
+ if (!session) {
13
+ throw new shopifyApi.ShopifyError(`Could not find a session for shop ${shop} when creating unauthenticated storefront context`);
14
+ }
15
+ return {
16
+ session,
17
+ storefront: factory.storefrontClientFactory({
18
+ params,
19
+ session
20
+ })
21
+ };
22
+ };
23
+ }
24
+
25
+ exports.unauthenticatedStorefrontContextFactory = unauthenticatedStorefrontContextFactory;
@@ -2,6 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const SHOPIFY_REMIX_LIBRARY_VERSION = '1.2.0';
5
+ const SHOPIFY_REMIX_LIBRARY_VERSION = '1.3.0';
6
6
 
7
7
  exports.SHOPIFY_REMIX_LIBRARY_VERSION = SHOPIFY_REMIX_LIBRARY_VERSION;
@@ -1,30 +1,43 @@
1
- import React from 'react';
2
1
  import { AppProviderProps as PolarisAppProviderProps } from '@shopify/polaris';
3
2
  export interface AppProviderProps extends Omit<PolarisAppProviderProps, 'linkComponent' | 'i18n'> {
4
- children: React.ReactNode;
5
3
  /**
6
- * The API key for your Shopify app.
4
+ * The API key for your Shopify app. This is the `Client ID` from the Partner Dashboard.
5
+ *
6
+ * When using the Shopify CLI, this is the `SHOPIFY_API_KEY` environment variable. If you're using the environment
7
+ * variable, then you need to pass it from the loader to the component.
7
8
  */
8
9
  apiKey: string;
9
10
  /**
10
- * Whether the app is embedded or not. Defaults to `true`.
11
+ * Whether the app is loaded inside the Shopify Admin. Default is `true`.
12
+ *
13
+ * {@link https://shopify.dev/docs/apps/admin/embedded-app-home}
11
14
  */
12
15
  isEmbeddedApp?: boolean;
13
16
  /**
14
- * The i18n configuration for your Polaris provider.
17
+ * The internationalization (i18n) configuration for your Polaris provider.
15
18
  *
16
19
  * {@link https://polaris.shopify.com/components/utilities/app-provider}
17
20
  */
18
21
  i18n?: PolarisAppProviderProps['i18n'];
22
+ /**
23
+ * Used internally by Shopify. You don't need to set this.
24
+ * @private
25
+ */
26
+ __APP_BRIDGE_URL?: string;
19
27
  }
20
28
  /**
21
- * Sets up the Polaris AppProvider and injects the App Bridge script.
29
+ * Sets up the Polaris `AppProvider` and injects the App Bridge script.
30
+ *
31
+ * This component extends the [`AppProvider`](https://polaris.shopify.com/components/utilities/app-provider) component
32
+ * from Polaris, and accepts all of its props except for `linkComponent`, which is overridden to use the Remix `Link`
33
+ * component.
22
34
  *
23
35
  * {@link https://polaris.shopify.com/components/utilities/app-provider}
24
36
  * {@link https://shopify.dev/tools/app-bridge}
25
37
  *
26
38
  * @example
27
- * Wrap your app in the `AppProvider` component and pass in your API key.
39
+ * <caption>Set up AppProvider.</caption>
40
+ * <description>Wrap your app in the `AppProvider` component and pass in your API key.</description>
28
41
  * ```ts
29
42
  * import {authenticate} from '~/shopify.server';
30
43
  * import {AppProvider} from '@shopify/shopify-app-remix/react';
@@ -39,7 +52,34 @@ export interface AppProviderProps extends Omit<PolarisAppProviderProps, 'linkCom
39
52
  * const { apiKey } = useLoaderData();
40
53
  *
41
54
  * return (
42
- * <AppProvider apiKey={apiKey}>
55
+ * <AppProvider isEmbeddedApp apiKey={apiKey}>
56
+ * <Outlet />
57
+ * </AppProvider>
58
+ * );
59
+ * }
60
+ * ```
61
+ *
62
+ * @example
63
+ * <caption>Localize Polaris components.</caption>
64
+ * <description>Pass in a different locale for Polaris to translate its components.</description>
65
+ * ```ts
66
+ * import {authenticate} from '~/shopify.server';
67
+ * import {AppProvider} from '@shopify/shopify-app-remix/react';
68
+ *
69
+ * export async function loader({ request }) {
70
+ * await authenticate.admin(request);
71
+ *
72
+ * return json({
73
+ * apiKey: process.env.SHOPIFY_API_KEY,
74
+ * polarisTranslations: require("@shopify/polaris/locales/fr.json"),
75
+ * });
76
+ * }
77
+ *
78
+ * export default function App() {
79
+ * const { apiKey, polarisTranslations } = useLoaderData();
80
+ *
81
+ * return (
82
+ * <AppProvider apiKey={apiKey} i18n={polarisTranslations}>
43
83
  * <Outlet />
44
84
  * </AppProvider>
45
85
  * );
@@ -1 +1 @@
1
- {"version":3,"file":"AppProvider.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,gBAAgB,IAAI,uBAAuB,EAC5C,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,uBAAuB,EAAE,eAAe,GAAG,MAAM,CAAC;IAC/D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC;CAMxC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAsBlD"}
1
+ {"version":3,"file":"AppProvider.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,IAAI,uBAAuB,EAC5C,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,uBAAuB,EAAE,eAAe,GAAG,MAAM,CAAC;IAC/D;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAsBlD"}
@@ -0,0 +1,4 @@
1
+ import { ReferenceEntityTemplateSchema } from '@shopify/generate-docs';
2
+ declare const data: ReferenceEntityTemplateSchema;
3
+ export default data;
4
+ //# sourceMappingURL=AppProvider.doc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppProvider.doc.d.ts","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.doc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAC,MAAM,wBAAwB,CAAC;AAErE,QAAA,MAAM,IAAI,EAAE,6BA6BX,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var data = {
4
+ name: 'AppProvider',
5
+ descriptionType: 'AppProviderGeneratedType',
6
+ description: '',
7
+ category: 'Entrypoints',
8
+ type: 'component',
9
+ isVisualComponent: false,
10
+ definitions: [
11
+ {
12
+ title: 'AppProviderProps',
13
+ description: 'Props for the `AppProvider` component.',
14
+ type: 'AppProviderProps',
15
+ },
16
+ ],
17
+ jsDocTypeExamples: ['AppProviderGeneratedType'],
18
+ related: [
19
+ {
20
+ name: 'App bridge',
21
+ subtitle: 'Learn more about App Bridge.',
22
+ url: '/docs/api/app-bridge-library',
23
+ type: 'shopify',
24
+ },
25
+ {
26
+ name: 'Polaris',
27
+ subtitle: 'Learn more about Polaris.',
28
+ url: '/docs/apps/tools/polaris',
29
+ type: 'shopify',
30
+ },
31
+ ],
32
+ };
33
+ exports.default = data;
34
+ //# sourceMappingURL=AppProvider.doc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppProvider.doc.js","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.doc.ts"],"names":[],"mappings":";;AAEA,IAAM,IAAI,GAAkC;IAC1C,IAAI,EAAE,aAAa;IACnB,eAAe,EAAE,0BAA0B;IAC3C,WAAW,EAAE,EAAE;IACf,QAAQ,EAAE,aAAa;IACvB,IAAI,EAAE,WAAW;IACjB,iBAAiB,EAAE,KAAK;IACxB,WAAW,EAAE;QACX;YACE,KAAK,EAAE,kBAAkB;YACzB,WAAW,EAAE,wCAAwC;YACrD,IAAI,EAAE,kBAAkB;SACzB;KACF;IACD,iBAAiB,EAAE,CAAC,0BAA0B,CAAC;IAC/C,OAAO,EAAE;QACP;YACE,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE,8BAA8B;YACxC,GAAG,EAAE,8BAA8B;YACnC,IAAI,EAAE,SAAS;SAChB;QACD;YACE,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,2BAA2B;YACrC,GAAG,EAAE,0BAA0B;YAC/B,IAAI,EAAE,SAAS;SAChB;KACF;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
@@ -8,13 +8,18 @@ var en_json_1 = tslib_1.__importDefault(require("@shopify/polaris/locales/en.jso
8
8
  var const_1 = require("../../const");
9
9
  var RemixPolarisLink_1 = require("../RemixPolarisLink");
10
10
  /**
11
- * Sets up the Polaris AppProvider and injects the App Bridge script.
11
+ * Sets up the Polaris `AppProvider` and injects the App Bridge script.
12
+ *
13
+ * This component extends the [`AppProvider`](https://polaris.shopify.com/components/utilities/app-provider) component
14
+ * from Polaris, and accepts all of its props except for `linkComponent`, which is overridden to use the Remix `Link`
15
+ * component.
12
16
  *
13
17
  * {@link https://polaris.shopify.com/components/utilities/app-provider}
14
18
  * {@link https://shopify.dev/tools/app-bridge}
15
19
  *
16
20
  * @example
17
- * Wrap your app in the `AppProvider` component and pass in your API key.
21
+ * <caption>Set up AppProvider.</caption>
22
+ * <description>Wrap your app in the `AppProvider` component and pass in your API key.</description>
18
23
  * ```ts
19
24
  * import {authenticate} from '~/shopify.server';
20
25
  * import {AppProvider} from '@shopify/shopify-app-remix/react';
@@ -29,7 +34,34 @@ var RemixPolarisLink_1 = require("../RemixPolarisLink");
29
34
  * const { apiKey } = useLoaderData();
30
35
  *
31
36
  * return (
32
- * <AppProvider apiKey={apiKey}>
37
+ * <AppProvider isEmbeddedApp apiKey={apiKey}>
38
+ * <Outlet />
39
+ * </AppProvider>
40
+ * );
41
+ * }
42
+ * ```
43
+ *
44
+ * @example
45
+ * <caption>Localize Polaris components.</caption>
46
+ * <description>Pass in a different locale for Polaris to translate its components.</description>
47
+ * ```ts
48
+ * import {authenticate} from '~/shopify.server';
49
+ * import {AppProvider} from '@shopify/shopify-app-remix/react';
50
+ *
51
+ * export async function loader({ request }) {
52
+ * await authenticate.admin(request);
53
+ *
54
+ * return json({
55
+ * apiKey: process.env.SHOPIFY_API_KEY,
56
+ * polarisTranslations: require("@shopify/polaris/locales/fr.json"),
57
+ * });
58
+ * }
59
+ *
60
+ * export default function App() {
61
+ * const { apiKey, polarisTranslations } = useLoaderData();
62
+ *
63
+ * return (
64
+ * <AppProvider apiKey={apiKey} i18n={polarisTranslations}>
33
65
  * <Outlet />
34
66
  * </AppProvider>
35
67
  * );
@@ -1 +1 @@
1
- {"version":3,"file":"AppProvider.js","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.tsx"],"names":[],"mappings":";;;;;AACA,4CAG0B;AAC1B,qFAA2D;AAE3D,qCAA2C;AAC3C,wDAAqD;AA0BrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,WAAW,CAAC,KAAuB;IAE/C,IAAA,QAAQ,GAMN,KAAK,SANC,EACR,MAAM,GAKJ,KAAK,OALD,EACN,IAAI,GAIF,KAAK,KAJH,EACJ,KAGE,KAAK,cAHa,EAApB,aAAa,mBAAG,IAAI,KAAA,EACpB,KAEE,KAAK,iBAF0B,EAAjC,gBAAgB,mBAAG,sBAAc,KAAA,EAC9B,YAAY,kBACb,KAAK,EAPH,mEAOL,CADgB,CACP;IAEV,OAAO,CACL,6DACG,aAAa,IAAI,mCAAQ,GAAG,EAAE,gBAAgB,kBAAgB,MAAM,GAAI,EACzE,uBAAC,qBAAkB,uBACb,YAAY,IAChB,aAAa,EAAE,mCAAgB,EAC/B,IAAI,EAAE,IAAI,IAAI,iBAAW,gBAExB,QAAQ,IACU,IACpB,CACJ,CAAC;AACJ,CAAC;AAtBD,kCAsBC"}
1
+ {"version":3,"file":"AppProvider.js","sourceRoot":"","sources":["../../../../../src/react/components/AppProvider/AppProvider.tsx"],"names":[],"mappings":";;;;;AAAA,4CAG0B;AAC1B,qFAA2D;AAE3D,qCAA2C;AAC3C,wDAAqD;AA8BrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,SAAgB,WAAW,CAAC,KAAuB;IAE/C,IAAA,QAAQ,GAMN,KAAK,SANC,EACR,MAAM,GAKJ,KAAK,OALD,EACN,IAAI,GAIF,KAAK,KAJH,EACJ,KAGE,KAAK,cAHa,EAApB,aAAa,mBAAG,IAAI,KAAA,EACpB,KAEE,KAAK,iBAF0B,EAAjC,gBAAgB,mBAAG,sBAAc,KAAA,EAC9B,YAAY,kBACb,KAAK,EAPH,mEAOL,CADgB,CACP;IAEV,OAAO,CACL,6DACG,aAAa,IAAI,mCAAQ,GAAG,EAAE,gBAAgB,kBAAgB,MAAM,GAAI,EACzE,uBAAC,qBAAkB,uBACb,YAAY,IAChB,aAAa,EAAE,mCAAgB,EAC/B,IAAI,EAAE,IAAI,IAAI,iBAAW,gBAExB,QAAQ,IACU,IACpB,CACJ,CAAC;AACJ,CAAC;AAtBD,kCAsBC"}
@@ -1,5 +1,5 @@
1
1
  import { Session } from '@shopify/shopify-api';
2
- import { AdminApiContext } from '../config-types';
2
+ import type { AdminApiContext } from '../clients';
3
3
  export declare function expectAdminApiClient(factory: () => Promise<{
4
4
  admin: AdminApiContext;
5
5
  expectedSession: Session;
@@ -1 +1 @@
1
- {"version":3,"file":"expect-admin-api-client.d.ts","sourceRoot":"","sources":["../../../../src/server/__test-helpers/expect-admin-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAG7C,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAOhD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,OAAO,CAAC;IACrB,KAAK,EAAE,eAAe,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC,QAqGH"}
1
+ {"version":3,"file":"expect-admin-api-client.d.ts","sourceRoot":"","sources":["../../../../src/server/__test-helpers/expect-admin-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAG7C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAOhD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,OAAO,CAAC;IACrB,KAAK,EAAE,eAAe,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC,QAqGH"}
@@ -0,0 +1,8 @@
1
+ import { Session } from '@shopify/shopify-api';
2
+ import type { StorefrontContext } from '../clients';
3
+ export declare function expectStorefrontApiClient(factory: () => Promise<{
4
+ storefront: StorefrontContext;
5
+ expectedSession: Session;
6
+ actualSession: Session;
7
+ }>): void;
8
+ //# sourceMappingURL=expect-storefront-api-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-storefront-api-client.d.ts","sourceRoot":"","sources":["../../../../src/server/__test-helpers/expect-storefront-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAG7C,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAKlD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,OAAO,CAAC;IACrB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC,QAoCH"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectStorefrontApiClient = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var __1 = require("..");
6
+ var request_mock_1 = require("./request-mock");
7
+ var const_1 = require("./const");
8
+ function expectStorefrontApiClient(factory) {
9
+ var _this = this;
10
+ it('Storefront client can perform GraphQL Requests', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
11
+ var _a, storefront, actualSession, apiResponse, response, _b;
12
+ return tslib_1.__generator(this, function (_c) {
13
+ switch (_c.label) {
14
+ case 0: return [4 /*yield*/, factory()];
15
+ case 1:
16
+ _a = _c.sent(), storefront = _a.storefront, actualSession = _a.actualSession;
17
+ apiResponse = { blogs: { nodes: [{ id: 1 }] } };
18
+ return [4 /*yield*/, (0, request_mock_1.mockExternalRequest)({
19
+ request: new Request("https://".concat(const_1.TEST_SHOP, "/api/").concat(__1.LATEST_API_VERSION, "/graphql.json"), {
20
+ method: 'POST',
21
+ headers: {
22
+ 'Shopify-Storefront-Private-Token': actualSession.accessToken,
23
+ },
24
+ }),
25
+ response: new Response(JSON.stringify(apiResponse)),
26
+ })];
27
+ case 2:
28
+ _c.sent();
29
+ return [4 /*yield*/, storefront.graphql('blogs(first: 1) { nodes { id }}')];
30
+ case 3:
31
+ response = _c.sent();
32
+ // THEN
33
+ expect(response.status).toEqual(200);
34
+ _b = expect;
35
+ return [4 /*yield*/, response.json()];
36
+ case 4:
37
+ _b.apply(void 0, [_c.sent()]).toEqual(apiResponse);
38
+ return [2 /*return*/];
39
+ }
40
+ });
41
+ }); });
42
+ it('Storefront client uses the correct session', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
43
+ var _a, expectedSession, actualSession;
44
+ return tslib_1.__generator(this, function (_b) {
45
+ switch (_b.label) {
46
+ case 0: return [4 /*yield*/, factory()];
47
+ case 1:
48
+ _a = _b.sent(), expectedSession = _a.expectedSession, actualSession = _a.actualSession;
49
+ // THEN
50
+ expect(expectedSession).toEqual(actualSession);
51
+ return [2 /*return*/];
52
+ }
53
+ });
54
+ }); });
55
+ }
56
+ exports.expectStorefrontApiClient = expectStorefrontApiClient;
57
+ //# sourceMappingURL=expect-storefront-api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-storefront-api-client.js","sourceRoot":"","sources":["../../../../src/server/__test-helpers/expect-storefront-api-client.ts"],"names":[],"mappings":";;;;AAEA,wBAAsC;AAGtC,+CAAmD;AACnD,iCAAkC;AAElC,SAAgB,yBAAyB,CACvC,OAIE;IALJ,iBAyCC;IAlCC,EAAE,CAAC,gDAAgD,EAAE;;;;wBAEf,qBAAM,OAAO,EAAE,EAAA;;oBAA7C,KAA8B,SAAe,EAA5C,UAAU,gBAAA,EAAE,aAAa,mBAAA;oBAC1B,WAAW,GAAG,EAAC,KAAK,EAAE,EAAC,KAAK,EAAE,CAAC,EAAC,EAAE,EAAE,CAAC,EAAC,CAAC,EAAC,EAAC,CAAC;oBAChD,qBAAM,IAAA,kCAAmB,EAAC;4BACxB,OAAO,EAAE,IAAI,OAAO,CAClB,kBAAW,iBAAS,kBAAQ,sBAAkB,kBAAe,EAC7D;gCACE,MAAM,EAAE,MAAM;gCACd,OAAO,EAAE;oCACP,kCAAkC,EAAE,aAAa,CAAC,WAAY;iCAC/D;6BACF,CACF;4BACD,QAAQ,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;yBACpD,CAAC,EAAA;;oBAXF,SAWE,CAAC;oBAGc,qBAAM,UAAU,CAAC,OAAO,CACvC,iCAAiC,CAClC,EAAA;;oBAFK,QAAQ,GAAG,SAEhB;oBAED,OAAO;oBACP,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;oBACrC,KAAA,MAAM,CAAA;oBAAC,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;oBAA5B,kBAAO,SAAqB,EAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;;;;SACpD,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE;;;;wBAEN,qBAAM,OAAO,EAAE,EAAA;;oBAAlD,KAAmC,SAAe,EAAjD,eAAe,qBAAA,EAAE,aAAa,mBAAA;oBAErC,OAAO;oBACP,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;;;;SAChD,CAAC,CAAC;AACL,CAAC;AAzCD,8DAyCC"}