@shopify/cli-hydrogen 6.0.2 → 7.0.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 (108) hide show
  1. package/dist/commands/hydrogen/build.js +40 -78
  2. package/dist/commands/hydrogen/codegen.js +8 -3
  3. package/dist/commands/hydrogen/deploy.js +173 -37
  4. package/dist/commands/hydrogen/deploy.test.js +192 -20
  5. package/dist/commands/hydrogen/dev.js +56 -31
  6. package/dist/commands/hydrogen/init.js +1 -1
  7. package/dist/commands/hydrogen/init.test.js +155 -53
  8. package/dist/commands/hydrogen/link.js +5 -21
  9. package/dist/commands/hydrogen/link.test.js +10 -10
  10. package/dist/commands/hydrogen/preview.js +22 -11
  11. package/dist/commands/hydrogen/setup.js +0 -4
  12. package/dist/commands/hydrogen/setup.test.js +0 -1
  13. package/dist/commands/hydrogen/shortcut.js +1 -0
  14. package/dist/commands/hydrogen/upgrade.js +720 -0
  15. package/dist/commands/hydrogen/upgrade.test.js +786 -0
  16. package/dist/generator-templates/starter/.graphqlrc.yml +12 -1
  17. package/dist/generator-templates/starter/CHANGELOG.md +126 -0
  18. package/dist/generator-templates/starter/README.md +23 -0
  19. package/dist/generator-templates/starter/app/components/Cart.tsx +1 -1
  20. package/dist/generator-templates/starter/app/components/Footer.tsx +3 -1
  21. package/dist/generator-templates/starter/app/components/Header.tsx +5 -1
  22. package/dist/generator-templates/starter/app/components/Layout.tsx +14 -11
  23. package/dist/generator-templates/starter/app/components/Search.tsx +1 -1
  24. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerAddressMutations.ts +61 -0
  25. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerDetailsQuery.ts +39 -0
  26. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrderQuery.ts +87 -0
  27. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrdersQuery.ts +58 -0
  28. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerUpdateMutation.ts +24 -0
  29. package/dist/generator-templates/starter/app/lib/fragments.ts +102 -0
  30. package/dist/generator-templates/starter/app/lib/session.ts +67 -0
  31. package/dist/generator-templates/starter/app/root.tsx +11 -45
  32. package/dist/generator-templates/starter/app/routes/[robots.txt].tsx +0 -27
  33. package/dist/generator-templates/starter/app/routes/account.$.tsx +8 -4
  34. package/dist/generator-templates/starter/app/routes/account._index.tsx +5 -0
  35. package/dist/generator-templates/starter/app/routes/account.addresses.tsx +215 -206
  36. package/dist/generator-templates/starter/app/routes/account.orders.$id.tsx +56 -163
  37. package/dist/generator-templates/starter/app/routes/account.orders._index.tsx +32 -109
  38. package/dist/generator-templates/starter/app/routes/account.profile.tsx +40 -180
  39. package/dist/generator-templates/starter/app/routes/account.tsx +20 -135
  40. package/dist/generator-templates/starter/app/routes/account_.authorize.tsx +5 -0
  41. package/dist/generator-templates/starter/app/routes/account_.login.tsx +3 -140
  42. package/dist/generator-templates/starter/app/routes/account_.logout.tsx +5 -24
  43. package/dist/generator-templates/starter/app/routes/cart.tsx +7 -5
  44. package/dist/generator-templates/starter/app/routes/collections.$handle.tsx +1 -1
  45. package/dist/generator-templates/starter/app/routes/products.$handle.tsx +2 -2
  46. package/dist/generator-templates/starter/app/routes/search.tsx +1 -1
  47. package/dist/generator-templates/starter/customer-accountapi.generated.d.ts +506 -0
  48. package/dist/generator-templates/starter/package.json +11 -10
  49. package/dist/generator-templates/starter/remix.config.js +4 -0
  50. package/dist/generator-templates/starter/remix.env.d.ts +6 -11
  51. package/dist/generator-templates/starter/server.ts +24 -167
  52. package/dist/generator-templates/starter/storefrontapi.generated.d.ts +104 -881
  53. package/dist/hooks/init.js +4 -4
  54. package/dist/lib/auth.js +5 -10
  55. package/dist/lib/build.js +6 -1
  56. package/dist/lib/bundle/analyzer.js +36 -26
  57. package/dist/lib/check-lockfile.js +1 -0
  58. package/dist/lib/codegen.js +59 -18
  59. package/dist/lib/defer.js +12 -0
  60. package/dist/lib/file.js +52 -3
  61. package/dist/lib/flags.js +27 -9
  62. package/dist/lib/get-oxygen-deployment-data.test.js +4 -2
  63. package/dist/lib/graphql/admin/client.test.js +2 -2
  64. package/dist/lib/graphql/admin/get-oxygen-data.js +1 -0
  65. package/dist/lib/log.js +32 -14
  66. package/dist/lib/mini-oxygen/assets.js +118 -0
  67. package/dist/lib/mini-oxygen/common.js +2 -1
  68. package/dist/lib/mini-oxygen/index.js +7 -5
  69. package/dist/lib/mini-oxygen/mini-oxygen.test.js +214 -0
  70. package/dist/lib/mini-oxygen/node.js +19 -5
  71. package/dist/lib/mini-oxygen/workerd-inspector-logs.js +227 -0
  72. package/dist/lib/mini-oxygen/workerd-inspector-proxy.js +200 -0
  73. package/dist/lib/mini-oxygen/workerd-inspector.js +62 -235
  74. package/dist/lib/mini-oxygen/workerd.js +74 -50
  75. package/dist/lib/missing-routes.js +6 -3
  76. package/dist/lib/onboarding/common.js +40 -9
  77. package/dist/lib/onboarding/local.js +19 -11
  78. package/dist/lib/onboarding/remote.js +48 -28
  79. package/dist/lib/render-errors.js +2 -0
  80. package/dist/lib/request-events.js +65 -31
  81. package/dist/lib/setups/css/assets.js +1 -46
  82. package/dist/lib/setups/css/css-modules.js +3 -2
  83. package/dist/lib/setups/css/postcss.js +4 -2
  84. package/dist/lib/setups/css/tailwind.js +4 -2
  85. package/dist/lib/setups/css/vanilla-extract.js +3 -2
  86. package/dist/lib/setups/i18n/replacers.test.js +56 -38
  87. package/dist/lib/shell.js +1 -1
  88. package/dist/lib/template-diff.js +89 -0
  89. package/dist/lib/template-downloader.js +3 -2
  90. package/dist/lib/transpile/project.js +1 -1
  91. package/dist/virtual-routes/assets/debug-network.css +592 -0
  92. package/dist/virtual-routes/assets/favicon-dark.svg +20 -0
  93. package/dist/virtual-routes/components/FlameChartWrapper.jsx +8 -10
  94. package/dist/virtual-routes/components/IconClose.jsx +38 -0
  95. package/dist/virtual-routes/components/IconDiscard.jsx +44 -0
  96. package/dist/virtual-routes/components/RequestDetails.jsx +179 -0
  97. package/dist/virtual-routes/components/RequestTable.jsx +92 -0
  98. package/dist/virtual-routes/components/RequestWaterfall.jsx +151 -0
  99. package/dist/virtual-routes/lib/useDebugNetworkServer.jsx +176 -0
  100. package/dist/virtual-routes/routes/subrequest-profiler.jsx +243 -0
  101. package/oclif.manifest.json +134 -59
  102. package/package.json +18 -26
  103. package/dist/generator-templates/starter/app/routes/account_.activate.$id.$activationToken.tsx +0 -161
  104. package/dist/generator-templates/starter/app/routes/account_.recover.tsx +0 -129
  105. package/dist/generator-templates/starter/app/routes/account_.register.tsx +0 -207
  106. package/dist/generator-templates/starter/app/routes/account_.reset.$id.$resetToken.tsx +0 -136
  107. package/dist/virtual-routes/routes/debug-network.jsx +0 -289
  108. /package/dist/generator-templates/starter/app/{utils.ts → lib/variants.ts} +0 -0
@@ -6,14 +6,15 @@ import {
6
6
  createCartHandler,
7
7
  createStorefrontClient,
8
8
  storefrontRedirect,
9
+ createCustomerAccountClient,
9
10
  } from '@shopify/hydrogen';
10
11
  import {
11
12
  createRequestHandler,
12
13
  getStorefrontHeaders,
13
- createCookieSessionStorage,
14
- type SessionStorage,
15
- type Session,
14
+ type AppLoadContext,
16
15
  } from '@shopify/remix-oxygen';
16
+ import {AppSession} from '~/lib/session';
17
+ import {CART_QUERY_FRAGMENT} from '~/lib/fragments';
17
18
 
18
19
  /**
19
20
  * Export a fetch handler in module format.
@@ -35,7 +36,7 @@ export default {
35
36
  const waitUntil = executionContext.waitUntil.bind(executionContext);
36
37
  const [cache, session] = await Promise.all([
37
38
  caches.open('hydrogen'),
38
- HydrogenSession.init(request, [env.SESSION_SECRET]),
39
+ AppSession.init(request, [env.SESSION_SECRET]),
39
40
  ]);
40
41
 
41
42
  /**
@@ -52,6 +53,17 @@ export default {
52
53
  storefrontHeaders: getStorefrontHeaders(request),
53
54
  });
54
55
 
56
+ /**
57
+ * Create a client for Customer Account API.
58
+ */
59
+ const customerAccount = createCustomerAccountClient({
60
+ waitUntil,
61
+ request,
62
+ session,
63
+ customerAccountId: env.PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID,
64
+ customerAccountUrl: env.PUBLIC_CUSTOMER_ACCOUNT_API_URL,
65
+ });
66
+
55
67
  /*
56
68
  * Create a cart handler that will be used to
57
69
  * create and update the cart in the session.
@@ -70,7 +82,14 @@ export default {
70
82
  const handleRequest = createRequestHandler({
71
83
  build: remixBuild,
72
84
  mode: process.env.NODE_ENV,
73
- getLoadContext: () => ({session, storefront, cart, env, waitUntil}),
85
+ getLoadContext: (): AppLoadContext => ({
86
+ session,
87
+ storefront,
88
+ customerAccount,
89
+ cart,
90
+ env,
91
+ waitUntil,
92
+ }),
74
93
  });
75
94
 
76
95
  const response = await handleRequest(request);
@@ -92,165 +111,3 @@ export default {
92
111
  }
93
112
  },
94
113
  };
95
-
96
- /**
97
- * This is a custom session implementation for your Hydrogen shop.
98
- * Feel free to customize it to your needs, add helper methods, or
99
- * swap out the cookie-based implementation with something else!
100
- */
101
- export class HydrogenSession {
102
- #sessionStorage;
103
- #session;
104
-
105
- constructor(sessionStorage: SessionStorage, session: Session) {
106
- this.#sessionStorage = sessionStorage;
107
- this.#session = session;
108
- }
109
-
110
- static async init(request: Request, secrets: string[]) {
111
- const storage = createCookieSessionStorage({
112
- cookie: {
113
- name: 'session',
114
- httpOnly: true,
115
- path: '/',
116
- sameSite: 'lax',
117
- secrets,
118
- },
119
- });
120
-
121
- const session = await storage.getSession(request.headers.get('Cookie'));
122
-
123
- return new this(storage, session);
124
- }
125
-
126
- get has() {
127
- return this.#session.has;
128
- }
129
-
130
- get get() {
131
- return this.#session.get;
132
- }
133
-
134
- get flash() {
135
- return this.#session.flash;
136
- }
137
-
138
- get unset() {
139
- return this.#session.unset;
140
- }
141
-
142
- get set() {
143
- return this.#session.set;
144
- }
145
-
146
- destroy() {
147
- return this.#sessionStorage.destroySession(this.#session);
148
- }
149
-
150
- commit() {
151
- return this.#sessionStorage.commitSession(this.#session);
152
- }
153
- }
154
-
155
- // NOTE: https://shopify.dev/docs/api/storefront/latest/queries/cart
156
- const CART_QUERY_FRAGMENT = `#graphql
157
- fragment Money on MoneyV2 {
158
- currencyCode
159
- amount
160
- }
161
- fragment CartLine on CartLine {
162
- id
163
- quantity
164
- attributes {
165
- key
166
- value
167
- }
168
- cost {
169
- totalAmount {
170
- ...Money
171
- }
172
- amountPerQuantity {
173
- ...Money
174
- }
175
- compareAtAmountPerQuantity {
176
- ...Money
177
- }
178
- }
179
- merchandise {
180
- ... on ProductVariant {
181
- id
182
- availableForSale
183
- compareAtPrice {
184
- ...Money
185
- }
186
- price {
187
- ...Money
188
- }
189
- requiresShipping
190
- title
191
- image {
192
- id
193
- url
194
- altText
195
- width
196
- height
197
-
198
- }
199
- product {
200
- handle
201
- title
202
- id
203
- }
204
- selectedOptions {
205
- name
206
- value
207
- }
208
- }
209
- }
210
- }
211
- fragment CartApiQuery on Cart {
212
- id
213
- checkoutUrl
214
- totalQuantity
215
- buyerIdentity {
216
- countryCode
217
- customer {
218
- id
219
- email
220
- firstName
221
- lastName
222
- displayName
223
- }
224
- email
225
- phone
226
- }
227
- lines(first: $numCartLines) {
228
- nodes {
229
- ...CartLine
230
- }
231
- }
232
- cost {
233
- subtotalAmount {
234
- ...Money
235
- }
236
- totalAmount {
237
- ...Money
238
- }
239
- totalDutyAmount {
240
- ...Money
241
- }
242
- totalTaxAmount {
243
- ...Money
244
- }
245
- }
246
- note
247
- attributes {
248
- key
249
- value
250
- }
251
- discountCodes {
252
- code
253
- applicable
254
- }
255
- }
256
- ` as const;