@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.
- package/dist/commands/hydrogen/build.js +40 -78
- package/dist/commands/hydrogen/codegen.js +8 -3
- package/dist/commands/hydrogen/deploy.js +173 -37
- package/dist/commands/hydrogen/deploy.test.js +192 -20
- package/dist/commands/hydrogen/dev.js +56 -31
- package/dist/commands/hydrogen/init.js +1 -1
- package/dist/commands/hydrogen/init.test.js +155 -53
- package/dist/commands/hydrogen/link.js +5 -21
- package/dist/commands/hydrogen/link.test.js +10 -10
- package/dist/commands/hydrogen/preview.js +22 -11
- package/dist/commands/hydrogen/setup.js +0 -4
- package/dist/commands/hydrogen/setup.test.js +0 -1
- package/dist/commands/hydrogen/shortcut.js +1 -0
- package/dist/commands/hydrogen/upgrade.js +720 -0
- package/dist/commands/hydrogen/upgrade.test.js +786 -0
- package/dist/generator-templates/starter/.graphqlrc.yml +12 -1
- package/dist/generator-templates/starter/CHANGELOG.md +126 -0
- package/dist/generator-templates/starter/README.md +23 -0
- package/dist/generator-templates/starter/app/components/Cart.tsx +1 -1
- package/dist/generator-templates/starter/app/components/Footer.tsx +3 -1
- package/dist/generator-templates/starter/app/components/Header.tsx +5 -1
- package/dist/generator-templates/starter/app/components/Layout.tsx +14 -11
- package/dist/generator-templates/starter/app/components/Search.tsx +1 -1
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerAddressMutations.ts +61 -0
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerDetailsQuery.ts +39 -0
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrderQuery.ts +87 -0
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerOrdersQuery.ts +58 -0
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerUpdateMutation.ts +24 -0
- package/dist/generator-templates/starter/app/lib/fragments.ts +102 -0
- package/dist/generator-templates/starter/app/lib/session.ts +67 -0
- package/dist/generator-templates/starter/app/root.tsx +11 -45
- package/dist/generator-templates/starter/app/routes/[robots.txt].tsx +0 -27
- package/dist/generator-templates/starter/app/routes/account.$.tsx +8 -4
- package/dist/generator-templates/starter/app/routes/account._index.tsx +5 -0
- package/dist/generator-templates/starter/app/routes/account.addresses.tsx +215 -206
- package/dist/generator-templates/starter/app/routes/account.orders.$id.tsx +56 -163
- package/dist/generator-templates/starter/app/routes/account.orders._index.tsx +32 -109
- package/dist/generator-templates/starter/app/routes/account.profile.tsx +40 -180
- package/dist/generator-templates/starter/app/routes/account.tsx +20 -135
- package/dist/generator-templates/starter/app/routes/account_.authorize.tsx +5 -0
- package/dist/generator-templates/starter/app/routes/account_.login.tsx +3 -140
- package/dist/generator-templates/starter/app/routes/account_.logout.tsx +5 -24
- package/dist/generator-templates/starter/app/routes/cart.tsx +7 -5
- package/dist/generator-templates/starter/app/routes/collections.$handle.tsx +1 -1
- package/dist/generator-templates/starter/app/routes/products.$handle.tsx +2 -2
- package/dist/generator-templates/starter/app/routes/search.tsx +1 -1
- package/dist/generator-templates/starter/customer-accountapi.generated.d.ts +506 -0
- package/dist/generator-templates/starter/package.json +11 -10
- package/dist/generator-templates/starter/remix.config.js +4 -0
- package/dist/generator-templates/starter/remix.env.d.ts +6 -11
- package/dist/generator-templates/starter/server.ts +24 -167
- package/dist/generator-templates/starter/storefrontapi.generated.d.ts +104 -881
- package/dist/hooks/init.js +4 -4
- package/dist/lib/auth.js +5 -10
- package/dist/lib/build.js +6 -1
- package/dist/lib/bundle/analyzer.js +36 -26
- package/dist/lib/check-lockfile.js +1 -0
- package/dist/lib/codegen.js +59 -18
- package/dist/lib/defer.js +12 -0
- package/dist/lib/file.js +52 -3
- package/dist/lib/flags.js +27 -9
- package/dist/lib/get-oxygen-deployment-data.test.js +4 -2
- package/dist/lib/graphql/admin/client.test.js +2 -2
- package/dist/lib/graphql/admin/get-oxygen-data.js +1 -0
- package/dist/lib/log.js +32 -14
- package/dist/lib/mini-oxygen/assets.js +118 -0
- package/dist/lib/mini-oxygen/common.js +2 -1
- package/dist/lib/mini-oxygen/index.js +7 -5
- package/dist/lib/mini-oxygen/mini-oxygen.test.js +214 -0
- package/dist/lib/mini-oxygen/node.js +19 -5
- package/dist/lib/mini-oxygen/workerd-inspector-logs.js +227 -0
- package/dist/lib/mini-oxygen/workerd-inspector-proxy.js +200 -0
- package/dist/lib/mini-oxygen/workerd-inspector.js +62 -235
- package/dist/lib/mini-oxygen/workerd.js +74 -50
- package/dist/lib/missing-routes.js +6 -3
- package/dist/lib/onboarding/common.js +40 -9
- package/dist/lib/onboarding/local.js +19 -11
- package/dist/lib/onboarding/remote.js +48 -28
- package/dist/lib/render-errors.js +2 -0
- package/dist/lib/request-events.js +65 -31
- package/dist/lib/setups/css/assets.js +1 -46
- package/dist/lib/setups/css/css-modules.js +3 -2
- package/dist/lib/setups/css/postcss.js +4 -2
- package/dist/lib/setups/css/tailwind.js +4 -2
- package/dist/lib/setups/css/vanilla-extract.js +3 -2
- package/dist/lib/setups/i18n/replacers.test.js +56 -38
- package/dist/lib/shell.js +1 -1
- package/dist/lib/template-diff.js +89 -0
- package/dist/lib/template-downloader.js +3 -2
- package/dist/lib/transpile/project.js +1 -1
- package/dist/virtual-routes/assets/debug-network.css +592 -0
- package/dist/virtual-routes/assets/favicon-dark.svg +20 -0
- package/dist/virtual-routes/components/FlameChartWrapper.jsx +8 -10
- package/dist/virtual-routes/components/IconClose.jsx +38 -0
- package/dist/virtual-routes/components/IconDiscard.jsx +44 -0
- package/dist/virtual-routes/components/RequestDetails.jsx +179 -0
- package/dist/virtual-routes/components/RequestTable.jsx +92 -0
- package/dist/virtual-routes/components/RequestWaterfall.jsx +151 -0
- package/dist/virtual-routes/lib/useDebugNetworkServer.jsx +176 -0
- package/dist/virtual-routes/routes/subrequest-profiler.jsx +243 -0
- package/oclif.manifest.json +134 -59
- package/package.json +18 -26
- package/dist/generator-templates/starter/app/routes/account_.activate.$id.$activationToken.tsx +0 -161
- package/dist/generator-templates/starter/app/routes/account_.recover.tsx +0 -129
- package/dist/generator-templates/starter/app/routes/account_.register.tsx +0 -207
- package/dist/generator-templates/starter/app/routes/account_.reset.$id.$resetToken.tsx +0 -136
- package/dist/virtual-routes/routes/debug-network.jsx +0 -289
- /package/dist/generator-templates/starter/app/{utils.ts → lib/variants.ts} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {HydrogenSession} from '@shopify/hydrogen';
|
|
2
|
+
import {
|
|
3
|
+
createCookieSessionStorage,
|
|
4
|
+
type SessionStorage,
|
|
5
|
+
type Session,
|
|
6
|
+
} from '@shopify/remix-oxygen';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is a custom session implementation for your Hydrogen shop.
|
|
10
|
+
* Feel free to customize it to your needs, add helper methods, or
|
|
11
|
+
* swap out the cookie-based implementation with something else!
|
|
12
|
+
*/
|
|
13
|
+
export class AppSession implements HydrogenSession {
|
|
14
|
+
#sessionStorage;
|
|
15
|
+
#session;
|
|
16
|
+
|
|
17
|
+
constructor(sessionStorage: SessionStorage, session: Session) {
|
|
18
|
+
this.#sessionStorage = sessionStorage;
|
|
19
|
+
this.#session = session;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static async init(request: Request, secrets: string[]) {
|
|
23
|
+
const storage = createCookieSessionStorage({
|
|
24
|
+
cookie: {
|
|
25
|
+
name: 'session',
|
|
26
|
+
httpOnly: true,
|
|
27
|
+
path: '/',
|
|
28
|
+
sameSite: 'lax',
|
|
29
|
+
secrets,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const session = await storage
|
|
34
|
+
.getSession(request.headers.get('Cookie'))
|
|
35
|
+
.catch(() => storage.getSession());
|
|
36
|
+
|
|
37
|
+
return new this(storage, session);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get has() {
|
|
41
|
+
return this.#session.has;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get get() {
|
|
45
|
+
return this.#session.get;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get flash() {
|
|
49
|
+
return this.#session.flash;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get unset() {
|
|
53
|
+
return this.#session.unset;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get set() {
|
|
57
|
+
return this.#session.set;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
destroy() {
|
|
61
|
+
return this.#sessionStorage.destroySession(this.#session);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
commit() {
|
|
65
|
+
return this.#sessionStorage.commitSession(this.#session);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -60,21 +60,19 @@ export function links() {
|
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Access the result of the root loader from a React component.
|
|
65
|
+
*/
|
|
63
66
|
export const useRootLoaderData = () => {
|
|
64
67
|
const [root] = useMatches();
|
|
65
68
|
return root?.data as SerializeFrom<typeof loader>;
|
|
66
69
|
};
|
|
67
70
|
|
|
68
71
|
export async function loader({context}: LoaderFunctionArgs) {
|
|
69
|
-
const {storefront,
|
|
70
|
-
const customerAccessToken = await session.get('customerAccessToken');
|
|
72
|
+
const {storefront, customerAccount, cart} = context;
|
|
71
73
|
const publicStoreDomain = context.env.PUBLIC_STORE_DOMAIN;
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
const {isLoggedIn, headers} = await validateCustomerAccessToken(
|
|
75
|
-
session,
|
|
76
|
-
customerAccessToken,
|
|
77
|
-
);
|
|
75
|
+
const isLoggedInPromise = customerAccount.isLoggedIn();
|
|
78
76
|
|
|
79
77
|
// defer the cart query by not awaiting it
|
|
80
78
|
const cartPromise = cart.get();
|
|
@@ -100,10 +98,14 @@ export async function loader({context}: LoaderFunctionArgs) {
|
|
|
100
98
|
cart: cartPromise,
|
|
101
99
|
footer: footerPromise,
|
|
102
100
|
header: await headerPromise,
|
|
103
|
-
isLoggedIn,
|
|
101
|
+
isLoggedIn: isLoggedInPromise,
|
|
104
102
|
publicStoreDomain,
|
|
105
103
|
},
|
|
106
|
-
{
|
|
104
|
+
{
|
|
105
|
+
headers: {
|
|
106
|
+
'Set-Cookie': await context.session.commit(),
|
|
107
|
+
},
|
|
108
|
+
},
|
|
107
109
|
);
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -173,42 +175,6 @@ export function ErrorBoundary() {
|
|
|
173
175
|
);
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
/**
|
|
177
|
-
* Validates the customer access token and returns a boolean and headers
|
|
178
|
-
* @see https://shopify.dev/docs/api/storefront/latest/objects/CustomerAccessToken
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```js
|
|
182
|
-
* const {isLoggedIn, headers} = await validateCustomerAccessToken(
|
|
183
|
-
* customerAccessToken,
|
|
184
|
-
* session,
|
|
185
|
-
* );
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
async function validateCustomerAccessToken(
|
|
189
|
-
session: LoaderFunctionArgs['context']['session'],
|
|
190
|
-
customerAccessToken?: CustomerAccessToken,
|
|
191
|
-
) {
|
|
192
|
-
let isLoggedIn = false;
|
|
193
|
-
const headers = new Headers();
|
|
194
|
-
if (!customerAccessToken?.accessToken || !customerAccessToken?.expiresAt) {
|
|
195
|
-
return {isLoggedIn, headers};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const expiresAt = new Date(customerAccessToken.expiresAt).getTime();
|
|
199
|
-
const dateNow = Date.now();
|
|
200
|
-
const customerAccessTokenExpired = expiresAt < dateNow;
|
|
201
|
-
|
|
202
|
-
if (customerAccessTokenExpired) {
|
|
203
|
-
session.unset('customerAccessToken');
|
|
204
|
-
headers.append('Set-Cookie', await session.commit());
|
|
205
|
-
} else {
|
|
206
|
-
isLoggedIn = true;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return {isLoggedIn, headers};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
178
|
const MENU_FRAGMENT = `#graphql
|
|
213
179
|
fragment MenuItem on MenuItem {
|
|
214
180
|
id
|
|
@@ -20,33 +20,6 @@ export async function loader({request, context}: LoaderFunctionArgs) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function ErrorBoundary() {
|
|
24
|
-
const error = useRouteError();
|
|
25
|
-
|
|
26
|
-
if (isRouteErrorResponse(error)) {
|
|
27
|
-
return (
|
|
28
|
-
<div>
|
|
29
|
-
<h1>Oops</h1>
|
|
30
|
-
<p>Status: {error.status}</p>
|
|
31
|
-
<p>{error.data.message}</p>
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let errorMessage = 'Unknown error';
|
|
37
|
-
if (error instanceof Error) {
|
|
38
|
-
errorMessage = error.message;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<div>
|
|
43
|
-
<h1>Uh oh ...</h1>
|
|
44
|
-
<p>Something went wrong.</p>
|
|
45
|
-
<pre>{errorMessage}</pre>
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
23
|
function robotsTxtData({url, shopId}: {shopId?: string; url?: string}) {
|
|
51
24
|
const sitemapUrl = url ? `${url}/sitemap.xml` : undefined;
|
|
52
25
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import {redirect, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
|
|
2
2
|
|
|
3
|
+
// fallback wild card for all unauthenticated routes in account section
|
|
3
4
|
export async function loader({context}: LoaderFunctionArgs) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
await context.customerAccount.handleAuthStatus();
|
|
6
|
+
|
|
7
|
+
return redirect('/account', {
|
|
8
|
+
headers: {
|
|
9
|
+
'Set-Cookie': await context.session.commit(),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
8
12
|
}
|