@shopify/cli-hydrogen 6.1.1 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) 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 +311 -21
  4. package/dist/commands/hydrogen/deploy.test.js +410 -0
  5. package/dist/commands/hydrogen/dev.js +30 -15
  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 +7 -6
  11. package/dist/commands/hydrogen/setup.js +17 -23
  12. package/dist/commands/hydrogen/setup.test.js +0 -1
  13. package/dist/commands/hydrogen/upgrade.js +15 -0
  14. package/dist/generator-templates/starter/.graphqlrc.yml +12 -1
  15. package/dist/generator-templates/starter/CHANGELOG.md +66 -0
  16. package/dist/generator-templates/starter/README.md +23 -0
  17. package/dist/generator-templates/starter/app/components/Cart.tsx +1 -1
  18. package/dist/generator-templates/starter/app/components/Header.tsx +5 -1
  19. package/dist/generator-templates/starter/app/components/Layout.tsx +1 -1
  20. package/dist/generator-templates/starter/app/components/Search.tsx +1 -1
  21. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerAddressMutations.ts +61 -0
  22. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerDetailsQuery.ts +39 -0
  23. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrderQuery.ts +87 -0
  24. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrdersQuery.ts +58 -0
  25. package/dist/generator-templates/starter/app/graphql/customer-account/CustomerUpdateMutation.ts +24 -0
  26. package/dist/generator-templates/starter/app/lib/fragments.ts +102 -0
  27. package/dist/generator-templates/starter/app/lib/session.ts +67 -0
  28. package/dist/generator-templates/starter/app/root.tsx +11 -45
  29. package/dist/generator-templates/starter/app/routes/account.$.tsx +8 -4
  30. package/dist/generator-templates/starter/app/routes/account._index.tsx +5 -0
  31. package/dist/generator-templates/starter/app/routes/account.addresses.tsx +215 -206
  32. package/dist/generator-templates/starter/app/routes/account.orders.$id.tsx +56 -163
  33. package/dist/generator-templates/starter/app/routes/account.orders._index.tsx +32 -109
  34. package/dist/generator-templates/starter/app/routes/account.profile.tsx +40 -180
  35. package/dist/generator-templates/starter/app/routes/account.tsx +20 -135
  36. package/dist/generator-templates/starter/app/routes/account_.authorize.tsx +5 -0
  37. package/dist/generator-templates/starter/app/routes/account_.login.tsx +3 -140
  38. package/dist/generator-templates/starter/app/routes/account_.logout.tsx +5 -24
  39. package/dist/generator-templates/starter/app/routes/cart.tsx +7 -5
  40. package/dist/generator-templates/starter/app/routes/collections.$handle.tsx +1 -1
  41. package/dist/generator-templates/starter/app/routes/products.$handle.tsx +2 -2
  42. package/dist/generator-templates/starter/app/routes/search.tsx +1 -1
  43. package/dist/generator-templates/starter/customer-accountapi.generated.d.ts +506 -0
  44. package/dist/generator-templates/starter/package.json +11 -11
  45. package/dist/generator-templates/starter/remix.config.js +4 -0
  46. package/dist/generator-templates/starter/remix.env.d.ts +8 -11
  47. package/dist/generator-templates/starter/server.ts +24 -167
  48. package/dist/generator-templates/starter/storefrontapi.generated.d.ts +104 -881
  49. package/dist/hooks/init.js +4 -4
  50. package/dist/lib/auth.js +5 -10
  51. package/dist/lib/build.js +6 -1
  52. package/dist/lib/bundle/analyzer.js +36 -26
  53. package/dist/lib/codegen.js +59 -26
  54. package/dist/lib/defer.js +12 -0
  55. package/dist/lib/file.js +55 -3
  56. package/dist/lib/flags.js +15 -8
  57. package/dist/lib/get-oxygen-deployment-data.test.js +4 -2
  58. package/dist/lib/graphiql-url.js +3 -0
  59. package/dist/lib/graphql/admin/client.test.js +2 -2
  60. package/dist/lib/graphql/admin/get-oxygen-data.js +1 -0
  61. package/dist/lib/log.js +31 -14
  62. package/dist/lib/mini-oxygen/assets.js +17 -1
  63. package/dist/lib/mini-oxygen/index.js +4 -5
  64. package/dist/lib/mini-oxygen/mini-oxygen.test.js +214 -0
  65. package/dist/lib/mini-oxygen/node.js +4 -2
  66. package/dist/lib/mini-oxygen/workerd-inspector-logs.js +2 -2
  67. package/dist/lib/mini-oxygen/workerd.js +27 -10
  68. package/dist/lib/missing-routes.js +6 -3
  69. package/dist/lib/onboarding/common.js +44 -12
  70. package/dist/lib/onboarding/local.js +26 -18
  71. package/dist/lib/onboarding/remote.js +50 -29
  72. package/dist/lib/request-events.js +65 -31
  73. package/dist/lib/setups/css/assets.js +1 -46
  74. package/dist/lib/setups/css/css-modules.js +3 -2
  75. package/dist/lib/setups/css/postcss.js +4 -2
  76. package/dist/lib/setups/css/tailwind.js +4 -2
  77. package/dist/lib/setups/css/vanilla-extract.js +3 -2
  78. package/dist/lib/setups/i18n/replacers.test.js +54 -38
  79. package/dist/lib/shell.js +1 -1
  80. package/dist/lib/template-diff.js +99 -0
  81. package/dist/lib/template-downloader.js +3 -2
  82. package/dist/lib/transpile/project.js +1 -1
  83. package/dist/virtual-routes/assets/debug-network.css +592 -0
  84. package/dist/virtual-routes/assets/favicon-dark.svg +20 -0
  85. package/dist/virtual-routes/components/FlameChartWrapper.jsx +8 -10
  86. package/dist/virtual-routes/components/IconClose.jsx +38 -0
  87. package/dist/virtual-routes/components/IconDiscard.jsx +44 -0
  88. package/dist/virtual-routes/components/RequestDetails.jsx +179 -0
  89. package/dist/virtual-routes/components/RequestTable.jsx +92 -0
  90. package/dist/virtual-routes/components/RequestWaterfall.jsx +151 -0
  91. package/dist/virtual-routes/lib/useDebugNetworkServer.jsx +176 -0
  92. package/dist/virtual-routes/routes/subrequest-profiler.jsx +243 -0
  93. package/oclif.manifest.json +54 -61
  94. package/package.json +15 -12
  95. package/dist/generator-templates/starter/app/routes/account_.activate.$id.$activationToken.tsx +0 -161
  96. package/dist/generator-templates/starter/app/routes/account_.recover.tsx +0 -129
  97. package/dist/generator-templates/starter/app/routes/account_.register.tsx +0 -207
  98. package/dist/generator-templates/starter/app/routes/account_.reset.$id.$resetToken.tsx +0 -136
  99. package/dist/virtual-routes/routes/debug-network.jsx +0 -289
  100. /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;