@shopify/cli-hydrogen 5.0.2 → 5.1.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 (243) hide show
  1. package/dist/commands/hydrogen/build.js +16 -2
  2. package/dist/commands/hydrogen/codegen-unstable.js +13 -24
  3. package/dist/commands/hydrogen/dev.js +45 -39
  4. package/dist/commands/hydrogen/env/list.js +25 -24
  5. package/dist/commands/hydrogen/env/list.test.js +46 -43
  6. package/dist/commands/hydrogen/env/pull.js +53 -25
  7. package/dist/commands/hydrogen/env/pull.test.js +123 -42
  8. package/dist/commands/hydrogen/generate/route.js +31 -132
  9. package/dist/commands/hydrogen/generate/route.test.js +34 -126
  10. package/dist/commands/hydrogen/init.js +46 -127
  11. package/dist/commands/hydrogen/init.test.js +352 -100
  12. package/dist/commands/hydrogen/link.js +70 -69
  13. package/dist/commands/hydrogen/link.test.js +72 -107
  14. package/dist/commands/hydrogen/list.js +22 -12
  15. package/dist/commands/hydrogen/list.test.js +51 -48
  16. package/dist/commands/hydrogen/login.js +31 -0
  17. package/dist/commands/hydrogen/logout.js +21 -0
  18. package/dist/commands/hydrogen/setup/css.js +79 -0
  19. package/dist/commands/hydrogen/setup/markets.js +53 -0
  20. package/dist/commands/hydrogen/setup.js +133 -0
  21. package/dist/commands/hydrogen/shortcut.js +2 -45
  22. package/dist/commands/hydrogen/shortcut.test.js +10 -37
  23. package/dist/generator-templates/assets/css-modules/package.json +6 -0
  24. package/dist/generator-templates/assets/postcss/package.json +10 -0
  25. package/dist/generator-templates/assets/postcss/postcss.config.js +8 -0
  26. package/dist/generator-templates/assets/tailwind/package.json +13 -0
  27. package/dist/generator-templates/assets/tailwind/postcss.config.js +10 -0
  28. package/dist/generator-templates/assets/tailwind/tailwind.config.js +8 -0
  29. package/dist/generator-templates/assets/tailwind/tailwind.css +3 -0
  30. package/dist/generator-templates/assets/vanilla-extract/package.json +9 -0
  31. package/dist/generator-templates/starter/.eslintignore +5 -0
  32. package/dist/generator-templates/starter/.eslintrc.js +18 -0
  33. package/dist/generator-templates/starter/.graphqlrc.yml +1 -0
  34. package/dist/generator-templates/starter/README.md +40 -0
  35. package/dist/generator-templates/starter/app/components/Aside.tsx +47 -0
  36. package/dist/generator-templates/starter/app/components/Cart.tsx +340 -0
  37. package/dist/generator-templates/starter/app/components/Footer.tsx +99 -0
  38. package/dist/generator-templates/starter/app/components/Header.tsx +178 -0
  39. package/dist/generator-templates/starter/app/components/Layout.tsx +95 -0
  40. package/dist/generator-templates/starter/app/components/Search.tsx +480 -0
  41. package/dist/generator-templates/starter/app/entry.client.tsx +12 -0
  42. package/dist/generator-templates/starter/app/entry.server.tsx +33 -0
  43. package/dist/generator-templates/starter/app/root.tsx +270 -0
  44. package/dist/generator-templates/starter/app/routes/$.tsx +7 -0
  45. package/dist/generator-templates/{routes → starter/app/routes}/[robots.txt].tsx +47 -69
  46. package/dist/generator-templates/starter/app/routes/[sitemap.xml].tsx +174 -0
  47. package/dist/generator-templates/starter/app/routes/_index.tsx +145 -0
  48. package/dist/generator-templates/starter/app/routes/account.$.tsx +9 -0
  49. package/dist/generator-templates/starter/app/routes/account.addresses.tsx +563 -0
  50. package/dist/generator-templates/starter/app/routes/account.orders.$id.tsx +309 -0
  51. package/dist/generator-templates/starter/app/routes/account.orders._index.tsx +196 -0
  52. package/dist/generator-templates/starter/app/routes/account.profile.tsx +289 -0
  53. package/dist/generator-templates/starter/app/routes/account.tsx +203 -0
  54. package/dist/generator-templates/starter/app/routes/account_.activate.$id.$activationToken.tsx +157 -0
  55. package/dist/generator-templates/starter/app/routes/account_.login.tsx +143 -0
  56. package/dist/generator-templates/starter/app/routes/account_.logout.tsx +33 -0
  57. package/dist/generator-templates/starter/app/routes/account_.recover.tsx +124 -0
  58. package/dist/generator-templates/starter/app/routes/account_.register.tsx +207 -0
  59. package/dist/generator-templates/starter/app/routes/account_.reset.$id.$resetToken.tsx +136 -0
  60. package/dist/generator-templates/starter/app/routes/api.predictive-search.tsx +342 -0
  61. package/dist/generator-templates/starter/app/routes/blogs.$blogHandle.$articleHandle.tsx +88 -0
  62. package/dist/generator-templates/starter/app/routes/blogs.$blogHandle._index.tsx +162 -0
  63. package/dist/generator-templates/starter/app/routes/blogs._index.tsx +94 -0
  64. package/dist/generator-templates/starter/app/routes/cart.tsx +104 -0
  65. package/dist/generator-templates/starter/app/routes/collections.$handle.tsx +184 -0
  66. package/dist/generator-templates/starter/app/routes/collections._index.tsx +120 -0
  67. package/dist/generator-templates/starter/app/routes/pages.$handle.tsx +57 -0
  68. package/dist/generator-templates/starter/app/routes/policies.$handle.tsx +94 -0
  69. package/dist/generator-templates/starter/app/routes/policies._index.tsx +63 -0
  70. package/dist/generator-templates/starter/app/routes/products.$handle.tsx +418 -0
  71. package/dist/generator-templates/starter/app/routes/search.tsx +168 -0
  72. package/dist/generator-templates/starter/app/styles/app.css +473 -0
  73. package/dist/generator-templates/starter/app/styles/reset.css +129 -0
  74. package/dist/generator-templates/starter/app/utils.ts +46 -0
  75. package/dist/generator-templates/starter/package.json +43 -0
  76. package/dist/generator-templates/starter/public/favicon.svg +28 -0
  77. package/dist/generator-templates/starter/remix.config.js +26 -0
  78. package/dist/generator-templates/starter/remix.env.d.ts +39 -0
  79. package/dist/generator-templates/starter/server.ts +253 -0
  80. package/dist/generator-templates/starter/storefrontapi.generated.d.ts +1906 -0
  81. package/dist/generator-templates/starter/tsconfig.json +22 -0
  82. package/dist/lib/auth.js +123 -0
  83. package/dist/lib/auth.test.js +157 -0
  84. package/dist/lib/build.js +51 -0
  85. package/dist/lib/check-version.js +3 -3
  86. package/dist/lib/check-version.test.js +24 -0
  87. package/dist/lib/codegen.js +26 -17
  88. package/dist/lib/environment-variables.js +68 -0
  89. package/dist/lib/environment-variables.test.js +147 -0
  90. package/dist/lib/file.js +41 -0
  91. package/dist/lib/file.test.js +69 -0
  92. package/dist/lib/flags.js +39 -2
  93. package/dist/lib/format-code.js +26 -0
  94. package/dist/lib/gid.js +12 -0
  95. package/dist/lib/{graphql.test.js → gid.test.js} +1 -1
  96. package/dist/lib/graphql/admin/client.js +27 -0
  97. package/dist/lib/graphql/admin/client.test.js +51 -0
  98. package/dist/lib/graphql/admin/create-storefront.js +13 -15
  99. package/dist/lib/graphql/admin/create-storefront.test.js +64 -0
  100. package/dist/lib/graphql/admin/fetch-job.js +6 -15
  101. package/dist/lib/graphql/admin/link-storefront.js +7 -11
  102. package/dist/lib/graphql/admin/link-storefront.test.js +38 -0
  103. package/dist/lib/graphql/admin/list-environments.js +2 -2
  104. package/dist/lib/graphql/admin/list-environments.test.js +44 -0
  105. package/dist/lib/graphql/admin/list-storefronts.js +7 -11
  106. package/dist/lib/graphql/admin/list-storefronts.test.js +44 -0
  107. package/dist/lib/graphql/admin/pull-variables.js +3 -3
  108. package/dist/lib/graphql/admin/pull-variables.test.js +37 -0
  109. package/dist/lib/graphql/business-platform/user-account.js +83 -0
  110. package/dist/lib/graphql/business-platform/user-account.test.js +80 -0
  111. package/dist/lib/log.js +185 -9
  112. package/dist/lib/log.test.js +92 -0
  113. package/dist/lib/mini-oxygen.js +19 -9
  114. package/dist/lib/missing-routes.js +0 -2
  115. package/dist/lib/onboarding/common.js +456 -0
  116. package/dist/lib/onboarding/index.js +2 -0
  117. package/dist/lib/onboarding/local.js +229 -0
  118. package/dist/lib/onboarding/remote.js +89 -0
  119. package/dist/lib/remix-version-interop.js +5 -5
  120. package/dist/lib/remix-version-interop.test.js +11 -1
  121. package/dist/lib/render-errors.js +13 -11
  122. package/dist/lib/setups/css/assets.js +89 -0
  123. package/dist/lib/setups/css/css-modules.js +22 -0
  124. package/dist/lib/setups/css/index.js +44 -0
  125. package/dist/lib/setups/css/postcss.js +34 -0
  126. package/dist/lib/setups/css/replacers.js +137 -0
  127. package/dist/lib/setups/css/tailwind.js +54 -0
  128. package/dist/lib/setups/css/vanilla-extract.js +22 -0
  129. package/dist/lib/setups/i18n/domains.test.js +25 -0
  130. package/dist/lib/setups/i18n/index.js +46 -0
  131. package/dist/lib/setups/i18n/replacers.js +227 -0
  132. package/dist/lib/setups/i18n/subdomains.test.js +25 -0
  133. package/dist/lib/setups/i18n/subfolders.test.js +25 -0
  134. package/dist/lib/setups/i18n/templates/domains.js +14 -0
  135. package/dist/lib/setups/i18n/templates/domains.ts +25 -0
  136. package/dist/lib/setups/i18n/templates/subdomains.js +14 -0
  137. package/dist/lib/setups/i18n/templates/subdomains.ts +24 -0
  138. package/dist/lib/setups/i18n/templates/subfolders.js +14 -0
  139. package/dist/lib/setups/i18n/templates/subfolders.ts +28 -0
  140. package/dist/lib/setups/routes/generate.js +244 -0
  141. package/dist/lib/setups/routes/generate.test.js +313 -0
  142. package/dist/lib/shell.js +52 -5
  143. package/dist/lib/shell.test.js +42 -16
  144. package/dist/lib/shopify-config.js +23 -18
  145. package/dist/lib/shopify-config.test.js +63 -73
  146. package/dist/lib/template-downloader.js +9 -7
  147. package/dist/lib/transpile-ts.js +9 -29
  148. package/dist/virtual-routes/routes/index.jsx +40 -19
  149. package/oclif.manifest.json +710 -1
  150. package/package.json +16 -16
  151. package/dist/commands/hydrogen/build.d.ts +0 -23
  152. package/dist/commands/hydrogen/check.d.ts +0 -15
  153. package/dist/commands/hydrogen/codegen-unstable.d.ts +0 -15
  154. package/dist/commands/hydrogen/dev.d.ts +0 -21
  155. package/dist/commands/hydrogen/env/list.d.ts +0 -18
  156. package/dist/commands/hydrogen/env/pull.d.ts +0 -22
  157. package/dist/commands/hydrogen/g.d.ts +0 -10
  158. package/dist/commands/hydrogen/generate/route.d.ts +0 -32
  159. package/dist/commands/hydrogen/generate/route.test.d.ts +0 -1
  160. package/dist/commands/hydrogen/generate/routes.d.ts +0 -16
  161. package/dist/commands/hydrogen/init.d.ts +0 -24
  162. package/dist/commands/hydrogen/init.test.d.ts +0 -1
  163. package/dist/commands/hydrogen/link.d.ts +0 -23
  164. package/dist/commands/hydrogen/link.test.d.ts +0 -1
  165. package/dist/commands/hydrogen/list.d.ts +0 -21
  166. package/dist/commands/hydrogen/list.test.d.ts +0 -1
  167. package/dist/commands/hydrogen/preview.d.ts +0 -17
  168. package/dist/commands/hydrogen/shortcut.d.ts +0 -9
  169. package/dist/commands/hydrogen/shortcut.test.d.ts +0 -1
  170. package/dist/commands/hydrogen/unlink.d.ts +0 -16
  171. package/dist/commands/hydrogen/unlink.test.d.ts +0 -1
  172. package/dist/create-app.d.ts +0 -1
  173. package/dist/generator-templates/routes/[sitemap.xml].tsx +0 -235
  174. package/dist/generator-templates/routes/account/login.tsx +0 -103
  175. package/dist/generator-templates/routes/account/register.tsx +0 -103
  176. package/dist/generator-templates/routes/cart.tsx +0 -81
  177. package/dist/generator-templates/routes/collections/$collectionHandle.tsx +0 -104
  178. package/dist/generator-templates/routes/collections/index.tsx +0 -102
  179. package/dist/generator-templates/routes/graphiql.tsx +0 -10
  180. package/dist/generator-templates/routes/index.tsx +0 -40
  181. package/dist/generator-templates/routes/pages/$pageHandle.tsx +0 -112
  182. package/dist/generator-templates/routes/policies/$policyHandle.tsx +0 -140
  183. package/dist/generator-templates/routes/policies/index.tsx +0 -117
  184. package/dist/generator-templates/routes/products/$productHandle.tsx +0 -92
  185. package/dist/hooks/init.d.ts +0 -5
  186. package/dist/lib/admin-session.d.ts +0 -6
  187. package/dist/lib/admin-session.js +0 -16
  188. package/dist/lib/admin-session.test.d.ts +0 -1
  189. package/dist/lib/admin-session.test.js +0 -27
  190. package/dist/lib/admin-urls.d.ts +0 -8
  191. package/dist/lib/check-lockfile.d.ts +0 -3
  192. package/dist/lib/check-lockfile.test.d.ts +0 -1
  193. package/dist/lib/check-version.d.ts +0 -16
  194. package/dist/lib/check-version.test.d.ts +0 -1
  195. package/dist/lib/codegen.d.ts +0 -26
  196. package/dist/lib/combined-environment-variables.d.ts +0 -8
  197. package/dist/lib/combined-environment-variables.js +0 -57
  198. package/dist/lib/combined-environment-variables.test.d.ts +0 -1
  199. package/dist/lib/combined-environment-variables.test.js +0 -111
  200. package/dist/lib/config.d.ts +0 -20
  201. package/dist/lib/flags.d.ts +0 -27
  202. package/dist/lib/flags.test.d.ts +0 -1
  203. package/dist/lib/graphql/admin/create-storefront.d.ts +0 -17
  204. package/dist/lib/graphql/admin/fetch-job.d.ts +0 -23
  205. package/dist/lib/graphql/admin/link-storefront.d.ts +0 -14
  206. package/dist/lib/graphql/admin/list-environments.d.ts +0 -21
  207. package/dist/lib/graphql/admin/list-storefronts.d.ts +0 -25
  208. package/dist/lib/graphql/admin/pull-variables.d.ts +0 -21
  209. package/dist/lib/graphql.d.ts +0 -21
  210. package/dist/lib/graphql.js +0 -18
  211. package/dist/lib/graphql.test.d.ts +0 -1
  212. package/dist/lib/log.d.ts +0 -6
  213. package/dist/lib/mini-oxygen.d.ts +0 -22
  214. package/dist/lib/missing-routes.d.ts +0 -8
  215. package/dist/lib/missing-routes.test.d.ts +0 -1
  216. package/dist/lib/missing-storefronts.d.ts +0 -5
  217. package/dist/lib/missing-storefronts.js +0 -18
  218. package/dist/lib/process.d.ts +0 -6
  219. package/dist/lib/pull-environment-variables.d.ts +0 -20
  220. package/dist/lib/pull-environment-variables.js +0 -57
  221. package/dist/lib/pull-environment-variables.test.d.ts +0 -1
  222. package/dist/lib/pull-environment-variables.test.js +0 -174
  223. package/dist/lib/remix-version-interop.d.ts +0 -11
  224. package/dist/lib/remix-version-interop.test.d.ts +0 -1
  225. package/dist/lib/render-errors.d.ts +0 -16
  226. package/dist/lib/shell.d.ts +0 -11
  227. package/dist/lib/shell.test.d.ts +0 -1
  228. package/dist/lib/shop.d.ts +0 -7
  229. package/dist/lib/shop.js +0 -32
  230. package/dist/lib/shop.test.d.ts +0 -1
  231. package/dist/lib/shop.test.js +0 -78
  232. package/dist/lib/shopify-config.d.ts +0 -35
  233. package/dist/lib/shopify-config.test.d.ts +0 -1
  234. package/dist/lib/string.d.ts +0 -3
  235. package/dist/lib/string.test.d.ts +0 -1
  236. package/dist/lib/template-downloader.d.ts +0 -6
  237. package/dist/lib/transpile-ts.d.ts +0 -16
  238. package/dist/lib/user-errors.d.ts +0 -9
  239. package/dist/lib/user-errors.js +0 -11
  240. package/dist/lib/virtual-routes.d.ts +0 -7
  241. package/dist/lib/virtual-routes.test.d.ts +0 -1
  242. /package/dist/{commands/hydrogen/env/list.test.d.ts → lib/setups/css/common.js} +0 -0
  243. /package/dist/{commands/hydrogen/env/pull.test.d.ts → lib/setups/i18n/mock-i18n-types.js} +0 -0
@@ -1,140 +0,0 @@
1
- import {
2
- json,
3
- type MetaFunction,
4
- type LoaderArgs,
5
- type ErrorBoundaryComponent,
6
- } from '@shopify/remix-oxygen';
7
- import {
8
- useLoaderData,
9
- type V2_MetaFunction,
10
- useCatch,
11
- useRouteError,
12
- isRouteErrorResponse,
13
- } from '@remix-run/react';
14
- import {Shop} from '@shopify/hydrogen/storefront-api-types';
15
-
16
- export async function loader({params, context}: LoaderArgs) {
17
- const handle = params.policyHandle;
18
-
19
- if (!handle) {
20
- throw new Response('No handle was passed in', {status: 404});
21
- }
22
-
23
- const policyName = handle.replace(/-([a-z])/g, (_: unknown, m1: string) =>
24
- m1.toUpperCase(),
25
- ) as SelectedPolicies;
26
-
27
- const data = await context.storefront.query<{
28
- shop: Pick<Shop, SelectedPolicies>;
29
- }>(POLICY_CONTENT_QUERY, {
30
- variables: {
31
- privacyPolicy: false,
32
- shippingPolicy: false,
33
- termsOfService: false,
34
- refundPolicy: false,
35
- [policyName]: true,
36
- language: context.storefront.i18n?.language,
37
- },
38
- });
39
-
40
- const policy = data.shop?.[policyName];
41
-
42
- if (!policy) {
43
- throw new Response('Could not find the policy', {status: 404});
44
- }
45
-
46
- return json({policy});
47
- }
48
-
49
- export const metaV1: MetaFunction<typeof loader> = ({data}) => {
50
- const title = data?.policy?.title ?? 'Policies';
51
- return {title};
52
- };
53
-
54
- export const meta: V2_MetaFunction<typeof loader> = ({data}) => {
55
- const title = data?.policy?.title ?? 'Policies';
56
- return [{title}];
57
- };
58
-
59
- export default function Policies() {
60
- const {policy} = useLoaderData<typeof loader>();
61
-
62
- return (
63
- <>
64
- <h1>{policy.title}</h1>
65
- <div dangerouslySetInnerHTML={{__html: policy.body}} />
66
- </>
67
- );
68
- }
69
-
70
- export const ErrorBoundaryV1: ErrorBoundaryComponent = ({error}) => {
71
- console.error(error);
72
-
73
- return <div>There was an error.</div>;
74
- };
75
-
76
- export function CatchBoundary() {
77
- const caught = useCatch();
78
- console.error(caught);
79
-
80
- return (
81
- <div>
82
- There was an error. Status: {caught.status}. Message:{' '}
83
- {caught.data?.message}
84
- </div>
85
- );
86
- }
87
-
88
- export function ErrorBoundary() {
89
- const error = useRouteError();
90
-
91
- if (isRouteErrorResponse(error)) {
92
- console.error(error.status, error.statusText, error.data);
93
- return <div>Route Error</div>;
94
- } else {
95
- console.error((error as Error).message);
96
- return <div>Thrown Error</div>;
97
- }
98
- }
99
-
100
- const POLICY_CONTENT_QUERY = `#graphql
101
- fragment Policy on ShopPolicy {
102
- body
103
- handle
104
- id
105
- title
106
- url
107
- }
108
-
109
- query policy_query(
110
- $language: LanguageCode
111
- $privacyPolicy: Boolean!
112
- $shippingPolicy: Boolean!
113
- $termsOfService: Boolean!
114
- $refundPolicy: Boolean!
115
- ) @inContext(language: $language) {
116
- shop {
117
- privacyPolicy @include(if: $privacyPolicy) {
118
- ...Policy
119
- }
120
- shippingPolicy @include(if: $shippingPolicy) {
121
- ...Policy
122
- }
123
- termsOfService @include(if: $termsOfService) {
124
- ...Policy
125
- }
126
- refundPolicy @include(if: $refundPolicy) {
127
- ...Policy
128
- }
129
- }
130
- }
131
- `;
132
-
133
- const policies = [
134
- 'privacyPolicy',
135
- 'shippingPolicy',
136
- 'refundPolicy',
137
- 'termsOfService',
138
- ] as const;
139
-
140
- type SelectedPolicies = (typeof policies)[number];
@@ -1,117 +0,0 @@
1
- import {
2
- json,
3
- type LoaderArgs,
4
- type ErrorBoundaryComponent,
5
- } from '@shopify/remix-oxygen';
6
- import {
7
- useLoaderData,
8
- Link,
9
- useCatch,
10
- useRouteError,
11
- isRouteErrorResponse,
12
- } from '@remix-run/react';
13
- import type {Shop} from '@shopify/hydrogen/storefront-api-types';
14
-
15
- export async function loader({context: {storefront}}: LoaderArgs) {
16
- const data = await storefront.query<{
17
- shop: Pick<Shop, SelectedPolicies>;
18
- }>(POLICIES_QUERY);
19
-
20
- const policies = Object.values(data.shop || {});
21
-
22
- if (policies.length === 0) {
23
- throw new Response('Not found', {status: 404});
24
- }
25
-
26
- return json({
27
- policies,
28
- });
29
- }
30
-
31
- export default function Policies() {
32
- const {policies} = useLoaderData<typeof loader>();
33
-
34
- return (
35
- <>
36
- {policies.map((policy) => {
37
- return (
38
- policy && (
39
- <Link key={policy.id} to={`/policies/${policy.handle}`}>
40
- {policy.title}
41
- </Link>
42
- )
43
- );
44
- })}
45
- </>
46
- );
47
- }
48
-
49
- export const ErrorBoundaryV1: ErrorBoundaryComponent = ({error}) => {
50
- console.error(error);
51
-
52
- return <div>There was an error.</div>;
53
- };
54
-
55
- export function CatchBoundary() {
56
- const caught = useCatch();
57
- console.error(caught);
58
-
59
- return (
60
- <div>
61
- There was an error. Status: {caught.status}. Message:{' '}
62
- {caught.data?.message}
63
- </div>
64
- );
65
- }
66
-
67
- export function ErrorBoundary() {
68
- const error = useRouteError();
69
-
70
- if (isRouteErrorResponse(error)) {
71
- console.error(error.status, error.statusText, error.data);
72
- return <div>Route Error</div>;
73
- } else {
74
- console.error((error as Error).message);
75
- return <div>Thrown Error</div>;
76
- }
77
- }
78
-
79
- const POLICIES_QUERY = `#graphql
80
- fragment Policy on ShopPolicy {
81
- id
82
- title
83
- handle
84
- }
85
-
86
- query PoliciesQuery {
87
- shop {
88
- privacyPolicy {
89
- ...Policy
90
- }
91
- shippingPolicy {
92
- ...Policy
93
- }
94
- termsOfService {
95
- ...Policy
96
- }
97
- refundPolicy {
98
- ...Policy
99
- }
100
- subscriptionPolicy {
101
- id
102
- title
103
- handle
104
- }
105
- }
106
- }
107
- `;
108
-
109
- const policies = [
110
- 'privacyPolicy',
111
- 'shippingPolicy',
112
- 'refundPolicy',
113
- 'termsOfService',
114
- 'subscriptionPolicy',
115
- ] as const;
116
-
117
- type SelectedPolicies = (typeof policies)[number];
@@ -1,92 +0,0 @@
1
- import {
2
- defer,
3
- type LoaderArgs,
4
- type ErrorBoundaryComponent,
5
- } from '@shopify/remix-oxygen';
6
- import {
7
- useLoaderData,
8
- useCatch,
9
- useRouteError,
10
- isRouteErrorResponse,
11
- } from '@remix-run/react';
12
- import type {Product as ProductType} from '@shopify/hydrogen/storefront-api-types';
13
-
14
- export async function loader({params, context}: LoaderArgs) {
15
- const {productHandle} = params;
16
-
17
- const {product} = await context.storefront.query<{
18
- product: Pick<ProductType, 'id' | 'title' | 'descriptionHtml' | 'vendor'>;
19
- }>(PRODUCT_QUERY, {
20
- variables: {
21
- handle: productHandle,
22
- country: context.storefront.i18n?.country,
23
- language: context.storefront.i18n?.language,
24
- },
25
- });
26
-
27
- if (!product?.id) {
28
- throw new Response(null, {status: 404});
29
- }
30
-
31
- return defer({
32
- product,
33
- });
34
- }
35
-
36
- export default function Product() {
37
- const {product} = useLoaderData<typeof loader>();
38
- const {title, vendor, descriptionHtml} = product;
39
-
40
- return (
41
- <>
42
- <h1>{title}</h1>
43
- <h2>{vendor}</h2>
44
- <div dangerouslySetInnerHTML={{__html: descriptionHtml}} />
45
- </>
46
- );
47
- }
48
-
49
- export const ErrorBoundaryV1: ErrorBoundaryComponent = ({error}) => {
50
- console.error(error);
51
-
52
- return <div>There was an error.</div>;
53
- };
54
-
55
- export function CatchBoundary() {
56
- const caught = useCatch();
57
- console.error(caught);
58
-
59
- return (
60
- <div>
61
- There was an error. Status: {caught.status}. Message:{' '}
62
- {caught.data?.message}
63
- </div>
64
- );
65
- }
66
-
67
- export function ErrorBoundary() {
68
- const error = useRouteError();
69
-
70
- if (isRouteErrorResponse(error)) {
71
- console.error(error.status, error.statusText, error.data);
72
- return <div>Route Error</div>;
73
- } else {
74
- console.error((error as Error).message);
75
- return <div>Thrown Error</div>;
76
- }
77
- }
78
-
79
- const PRODUCT_QUERY = `#graphql
80
- query product_query(
81
- $country: CountryCode
82
- $language: LanguageCode
83
- $handle: String!
84
- ) @inContext(country: $country, language: $language) {
85
- product(handle: $handle) {
86
- id
87
- title
88
- descriptionHtml
89
- vendor
90
- }
91
- }
92
- `;
@@ -1,5 +0,0 @@
1
- import { Hook } from '@oclif/core';
2
-
3
- declare const hook: Hook<'init'>;
4
-
5
- export { hook as default };
@@ -1,6 +0,0 @@
1
- import { AdminSession } from '@shopify/cli-kit/node/session';
2
- export { AdminSession } from '@shopify/cli-kit/node/session';
3
-
4
- declare function getAdminSession(shop: string): Promise<AdminSession>;
5
-
6
- export { getAdminSession };
@@ -1,16 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { ensureAuthenticatedAdmin } from '@shopify/cli-kit/node/session';
3
-
4
- async function getAdminSession(shop) {
5
- let adminSession;
6
- try {
7
- adminSession = await ensureAuthenticatedAdmin(shop);
8
- } catch {
9
- throw new AbortError("Unable to authenticate with Shopify", void 0, [
10
- `Ensure the shop that you specified is correct (you are trying to use: ${shop})`
11
- ]);
12
- }
13
- return adminSession;
14
- }
15
-
16
- export { getAdminSession };
@@ -1 +0,0 @@
1
-
@@ -1,27 +0,0 @@
1
- import { describe, vi, afterEach, it, expect } from 'vitest';
2
- import { ensureAuthenticatedAdmin } from '@shopify/cli-kit/node/session';
3
- import { AbortError } from '@shopify/cli-kit/node/error';
4
- import { getAdminSession } from './admin-session.js';
5
-
6
- describe("list", () => {
7
- vi.mock("@shopify/cli-kit/node/session");
8
- const ADMIN_SESSION = {
9
- token: "abc123",
10
- storeFqdn: "my-shop"
11
- };
12
- afterEach(() => {
13
- vi.resetAllMocks();
14
- });
15
- it("returns the admin session", async () => {
16
- vi.mocked(ensureAuthenticatedAdmin).mockResolvedValue(ADMIN_SESSION);
17
- const adminSession = await getAdminSession("my-shop");
18
- expect(ensureAuthenticatedAdmin).toHaveBeenCalledWith("my-shop");
19
- expect(adminSession).toStrictEqual(ADMIN_SESSION);
20
- });
21
- describe("when it fails to authenticate", () => {
22
- it("throws an error", async () => {
23
- vi.mocked(ensureAuthenticatedAdmin).mockRejectedValue({});
24
- await expect(getAdminSession("my-shop")).rejects.toThrow(AbortError);
25
- });
26
- });
27
- });
@@ -1,8 +0,0 @@
1
- import { AdminSession } from '@shopify/cli-kit/node/session';
2
-
3
- declare function newHydrogenStorefrontUrl(session: AdminSession): string;
4
- declare function hydrogenStorefrontsUrl(session: AdminSession): string;
5
- declare function hydrogenStorefrontUrl(session: AdminSession, storefrontId: string): string;
6
- declare function hydrogenStorefrontSettingsUrl(session: AdminSession, storefrontId: string): string;
7
-
8
- export { hydrogenStorefrontSettingsUrl, hydrogenStorefrontUrl, hydrogenStorefrontsUrl, newHydrogenStorefrontUrl };
@@ -1,3 +0,0 @@
1
- declare function checkLockfileStatus(directory: string): Promise<void>;
2
-
3
- export { checkLockfileStatus };
@@ -1 +0,0 @@
1
-
@@ -1,16 +0,0 @@
1
- declare const PACKAGE_NAMES: {
2
- readonly main: "@shopify/hydrogen";
3
- readonly cli: "@shopify/cli-hydrogen";
4
- };
5
- /**
6
- *
7
- * @param resolveFrom Path to a directory to resolve from, or directly the path to a package.json file.
8
- * @param pkgKey Package to check for updates.
9
- * @returns A function to show the update information if any update is available.
10
- */
11
- declare function checkHydrogenVersion(resolveFrom: string, pkgKey?: keyof typeof PACKAGE_NAMES): Promise<((extraMessage?: string) => {
12
- currentVersion: string;
13
- newVersion: string;
14
- }) | undefined>;
15
-
16
- export { checkHydrogenVersion };
@@ -1 +0,0 @@
1
-
@@ -1,26 +0,0 @@
1
- import * as child_process from 'child_process';
2
- import * as stream from 'stream';
3
- export { patchGqlPluck } from '@shopify/hydrogen-codegen';
4
-
5
- declare function normalizeCodegenError(errorMessage: string, rootDirectory?: string): {
6
- message: string;
7
- details: string;
8
- };
9
- /**
10
- * Spawns a child process to run GraphlQL CLI Codegen.
11
- * Running on a separate process splits work from this processor
12
- * and also allows us to filter out logs.
13
- */
14
- declare function spawnCodegenProcess({ rootDirectory, appDirectory, configFilePath, }: CodegenOptions): child_process.ChildProcessByStdio<null, null, stream.Readable>;
15
- type ProjectDirs = {
16
- rootDirectory: string;
17
- appDirectory: string;
18
- };
19
- type CodegenOptions = ProjectDirs & {
20
- watch?: boolean;
21
- configFilePath?: string;
22
- forceSfapiVersion?: string;
23
- };
24
- declare function generateTypes({ watch, configFilePath, forceSfapiVersion, ...dirs }: CodegenOptions): Promise<string[]>;
25
-
26
- export { generateTypes, normalizeCodegenError, spawnCodegenProcess };
@@ -1,8 +0,0 @@
1
- interface Arguments {
2
- envBranch?: string;
3
- root: string;
4
- shop?: string;
5
- }
6
- declare function combinedEnvironmentVariables({ envBranch, root, shop, }: Arguments): Promise<{}>;
7
-
8
- export { combinedEnvironmentVariables };
@@ -1,57 +0,0 @@
1
- import { fileExists } from '@shopify/cli-kit/node/fs';
2
- import { resolvePath } from '@shopify/cli-kit/node/path';
3
- import { linesToColumns } from '@shopify/cli-kit/common/string';
4
- import { outputInfo } from '@shopify/cli-kit/node/output';
5
- import { readAndParseDotEnv } from '@shopify/cli-kit/node/dot-env';
6
- import colors from '@shopify/cli-kit/node/colors';
7
- import { pullRemoteEnvironmentVariables } from './pull-environment-variables.js';
8
-
9
- async function combinedEnvironmentVariables({
10
- envBranch,
11
- root,
12
- shop
13
- }) {
14
- const remoteEnvironmentVariables = await pullRemoteEnvironmentVariables({
15
- root,
16
- flagShop: shop,
17
- silent: true,
18
- envBranch
19
- });
20
- const formattedRemoteVariables = remoteEnvironmentVariables?.reduce(
21
- (a, v) => ({ ...a, [v.key]: v.value }),
22
- {}
23
- );
24
- const dotEnvPath = resolvePath(root, ".env");
25
- const localEnvironmentVariables = await fileExists(dotEnvPath) ? (await readAndParseDotEnv(dotEnvPath)).variables : {};
26
- const remoteKeys = new Set(
27
- remoteEnvironmentVariables.map((variable) => variable.key)
28
- );
29
- const localKeys = new Set(Object.keys(localEnvironmentVariables));
30
- if ([...remoteKeys, ...localKeys].length) {
31
- outputInfo("\nEnvironment variables injected into MiniOxygen:\n");
32
- }
33
- let rows = [];
34
- remoteEnvironmentVariables.filter(({ isSecret }) => !isSecret).forEach(({ key }) => {
35
- if (!localKeys.has(key)) {
36
- rows.push([key, "from Oxygen"]);
37
- }
38
- });
39
- localKeys.forEach((key) => {
40
- rows.push([key, "from local .env"]);
41
- });
42
- remoteEnvironmentVariables.filter(({ isSecret }) => isSecret).forEach(({ key }) => {
43
- if (!localKeys.has(key)) {
44
- rows.push([
45
- colors.dim(key),
46
- colors.dim(`from Oxygen (Marked as secret)`)
47
- ]);
48
- }
49
- });
50
- outputInfo(linesToColumns(rows));
51
- return {
52
- ...formattedRemoteVariables,
53
- ...localEnvironmentVariables
54
- };
55
- }
56
-
57
- export { combinedEnvironmentVariables };
@@ -1,111 +0,0 @@
1
- import { vi, describe, beforeEach, afterEach, test, expect } from 'vitest';
2
- import { inTemporaryDirectory, writeFile } from '@shopify/cli-kit/node/fs';
3
- import { joinPath } from '@shopify/cli-kit/node/path';
4
- import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output';
5
- import { combinedEnvironmentVariables } from './combined-environment-variables.js';
6
- import { pullRemoteEnvironmentVariables } from './pull-environment-variables.js';
7
- import { getConfig } from './shopify-config.js';
8
-
9
- vi.mock("./shopify-config.js");
10
- vi.mock("./pull-environment-variables.js");
11
- describe("combinedEnvironmentVariables()", () => {
12
- beforeEach(() => {
13
- vi.mocked(getConfig).mockResolvedValue({
14
- storefront: {
15
- id: "gid://shopify/HydrogenStorefront/1",
16
- title: "Hydrogen"
17
- }
18
- });
19
- vi.mocked(pullRemoteEnvironmentVariables).mockResolvedValue([
20
- {
21
- id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/1",
22
- key: "PUBLIC_API_TOKEN",
23
- value: "abc123",
24
- isSecret: false
25
- }
26
- ]);
27
- });
28
- afterEach(() => {
29
- vi.resetAllMocks();
30
- mockAndCaptureOutput().clear();
31
- });
32
- test("calls pullRemoteEnvironmentVariables", async () => {
33
- await inTemporaryDirectory(async (tmpDir) => {
34
- await combinedEnvironmentVariables({
35
- envBranch: "main",
36
- root: tmpDir,
37
- shop: "my-shop"
38
- });
39
- expect(pullRemoteEnvironmentVariables).toHaveBeenCalledWith({
40
- envBranch: "main",
41
- root: tmpDir,
42
- flagShop: "my-shop",
43
- silent: true
44
- });
45
- });
46
- });
47
- test("renders a message about injection", async () => {
48
- await inTemporaryDirectory(async (tmpDir) => {
49
- const outputMock = mockAndCaptureOutput();
50
- await combinedEnvironmentVariables({ root: tmpDir, shop: "my-shop" });
51
- expect(outputMock.info()).toMatch(
52
- /Environment variables injected into MiniOxygen:/
53
- );
54
- });
55
- });
56
- test("lists all of the variables being used", async () => {
57
- await inTemporaryDirectory(async (tmpDir) => {
58
- const outputMock = mockAndCaptureOutput();
59
- await combinedEnvironmentVariables({ root: tmpDir, shop: "my-shop" });
60
- expect(outputMock.info()).toMatch(/PUBLIC_API_TOKEN\s+from Oxygen/);
61
- });
62
- });
63
- describe("when one of the variables is a secret", () => {
64
- beforeEach(() => {
65
- vi.mocked(pullRemoteEnvironmentVariables).mockResolvedValue([
66
- {
67
- id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/1",
68
- key: "PUBLIC_API_TOKEN",
69
- value: "",
70
- isSecret: true
71
- }
72
- ]);
73
- });
74
- test("uses special messaging to alert the user", async () => {
75
- await inTemporaryDirectory(async (tmpDir) => {
76
- const outputMock = mockAndCaptureOutput();
77
- await combinedEnvironmentVariables({ root: tmpDir, shop: "my-shop" });
78
- expect(outputMock.info()).toMatch(
79
- /PUBLIC_API_TOKEN\s+from Oxygen \(Marked as secret\)/
80
- );
81
- });
82
- });
83
- });
84
- describe("when there are local variables", () => {
85
- test("includes local variables in the list", async () => {
86
- await inTemporaryDirectory(async (tmpDir) => {
87
- const filePath = joinPath(tmpDir, ".env");
88
- await writeFile(filePath, "LOCAL_TOKEN=1");
89
- const outputMock = mockAndCaptureOutput();
90
- await combinedEnvironmentVariables({ root: tmpDir });
91
- expect(outputMock.info()).toMatch(/LOCAL_TOKEN\s+from local \.env/);
92
- });
93
- });
94
- describe("and they overwrite remote variables", () => {
95
- test("uses special messaging to alert the user", async () => {
96
- await inTemporaryDirectory(async (tmpDir) => {
97
- const filePath = joinPath(tmpDir, ".env");
98
- await writeFile(filePath, "PUBLIC_API_TOKEN=abc");
99
- const outputMock = mockAndCaptureOutput();
100
- await combinedEnvironmentVariables({ root: tmpDir, shop: "my-shop" });
101
- expect(outputMock.info()).not.toMatch(
102
- /PUBLIC_API_TOKEN\s+from Oxygen/
103
- );
104
- expect(outputMock.info()).toMatch(
105
- /PUBLIC_API_TOKEN\s+from local \.env/
106
- );
107
- });
108
- });
109
- });
110
- });
111
- });
@@ -1,20 +0,0 @@
1
- import { ServerMode } from '@remix-run/dev/dist/config/serverModes.js';
2
- export { ServerMode } from '@remix-run/dev/dist/config/serverModes.js';
3
- import { RemixConfig } from '@remix-run/dev/dist/config.js';
4
- export { RemixConfig } from '@remix-run/dev/dist/config.js';
5
-
6
- declare function getProjectPaths(appPath?: string, entry?: string): {
7
- root: string;
8
- buildPath: string;
9
- buildPathClient: string;
10
- buildPathWorkerFile: string;
11
- publicPath: string;
12
- };
13
- declare function getRemixConfig(root: string, skipOxygenChecks?: boolean, mode?: ServerMode): Promise<RemixConfig & {
14
- serverConditions?: string[] | undefined;
15
- serverMainFields?: string[] | undefined;
16
- serverDependenciesToBundle?: string | undefined;
17
- }>;
18
- declare function assertEntryFileExists(root: string, fileRelative: string): Promise<void>;
19
-
20
- export { assertEntryFileExists, getProjectPaths, getRemixConfig };