@shopify/hydrogen 1.3.2 → 1.4.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/esnext/components/CartProvider/CartActions.client.d.ts +60 -0
- package/dist/esnext/components/CartProvider/CartActions.client.js +232 -0
- package/dist/esnext/components/CartProvider/CartProviderV2.client.d.ts +44 -0
- package/dist/esnext/components/CartProvider/CartProviderV2.client.js +232 -0
- package/dist/esnext/components/CartProvider/hooks.client.js +1 -1
- package/dist/esnext/components/CartProvider/types.d.ts +149 -0
- package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.d.ts +16 -0
- package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.js +231 -0
- package/dist/esnext/entry-client.js +26 -8
- package/dist/esnext/experimental.d.ts +1 -0
- package/dist/esnext/experimental.js +1 -0
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +3 -2
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +1 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.client.d.ts +3 -3
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.d.ts +1 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +21 -6
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +5 -2
- package/dist/esnext/foundation/useShop/use-shop.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +1 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +0 -8
- package/dist/esnext/hooks/useDelay/useDelay.d.ts +1 -0
- package/dist/esnext/hooks/useDelay/useDelay.js +17 -0
- package/dist/esnext/hooks/useShopQuery/hooks.js +4 -2
- package/dist/esnext/index.d.ts +1 -0
- package/dist/esnext/index.js +1 -0
- package/dist/esnext/shared-types.d.ts +2 -1
- package/dist/esnext/utilities/apiRoutes.js +4 -2
- package/dist/esnext/utilities/object.d.ts +1 -1
- package/dist/esnext/utilities/storefrontApi.d.ts +4 -2
- package/dist/esnext/utilities/storefrontApi.js +27 -6
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +1 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +0 -8
- package/dist/node/shared-types.d.ts +2 -1
- package/package.json +3 -1
|
@@ -145,12 +145,14 @@ export function useShopQuery({ query, variables = {}, cache, preload = false, })
|
|
|
145
145
|
return data;
|
|
146
146
|
}
|
|
147
147
|
function useCreateShopRequest(body) {
|
|
148
|
-
const { storeDomain, storefrontToken, storefrontApiVersion } = useShop();
|
|
148
|
+
const { storeDomain, storefrontToken, storefrontApiVersion, storefrontId, privateStorefrontToken, } = useShop();
|
|
149
149
|
const request = useServerRequest();
|
|
150
150
|
const buyerIp = request.getBuyerIp();
|
|
151
151
|
const extraHeaders = getStorefrontApiRequestHeaders({
|
|
152
152
|
buyerIp,
|
|
153
|
-
storefrontToken,
|
|
153
|
+
publicStorefrontToken: storefrontToken,
|
|
154
|
+
privateStorefrontToken,
|
|
155
|
+
storefrontId,
|
|
154
156
|
});
|
|
155
157
|
return {
|
|
156
158
|
key: [storeDomain, storefrontApiVersion, body],
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export { ShopifyAnalytics } from './foundation/Analytics/connectors/Shopify/Shop
|
|
|
28
28
|
export { ShopifyAnalyticsConstants } from './foundation/Analytics/connectors/Shopify/const.js';
|
|
29
29
|
export { useSession } from './foundation/useSession/useSession.js';
|
|
30
30
|
export { Cookie } from './foundation/Cookie/Cookie.js';
|
|
31
|
+
export { useDelay } from './hooks/useDelay/useDelay.js';
|
|
31
32
|
/**
|
|
32
33
|
* Export server-only CartQuery here instead of `CartProvider.client` to prevent
|
|
33
34
|
* it from being bundled with other client components
|
package/dist/esnext/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export { ShopifyAnalytics } from './foundation/Analytics/connectors/Shopify/Shop
|
|
|
28
28
|
export { ShopifyAnalyticsConstants } from './foundation/Analytics/connectors/Shopify/const.js';
|
|
29
29
|
export { useSession } from './foundation/useSession/useSession.js';
|
|
30
30
|
export { Cookie } from './foundation/Cookie/Cookie.js';
|
|
31
|
+
export { useDelay } from './hooks/useDelay/useDelay.js';
|
|
31
32
|
/**
|
|
32
33
|
* Export server-only CartQuery here instead of `CartProvider.client` to prevent
|
|
33
34
|
* it from being bundled with other client components
|
|
@@ -81,11 +81,13 @@ function queryShopBuilder(shopifyConfigGetter, request) {
|
|
|
81
81
|
if (!shopifyConfig) {
|
|
82
82
|
throw new Error('Shopify connection info was not found in Hydrogen config');
|
|
83
83
|
}
|
|
84
|
-
const { storeDomain, storefrontApiVersion, storefrontToken } = shopifyConfig;
|
|
84
|
+
const { storeDomain, storefrontApiVersion, storefrontToken, privateStorefrontToken, storefrontId, } = shopifyConfig;
|
|
85
85
|
const buyerIp = request.getBuyerIp();
|
|
86
86
|
const extraHeaders = getStorefrontApiRequestHeaders({
|
|
87
87
|
buyerIp,
|
|
88
|
-
storefrontToken,
|
|
88
|
+
publicStorefrontToken: storefrontToken,
|
|
89
|
+
privateStorefrontToken,
|
|
90
|
+
storefrontId,
|
|
89
91
|
});
|
|
90
92
|
const fetcher = fetchBuilder(`https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`, {
|
|
91
93
|
method: 'POST',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare type Descriptor = Parameters<typeof Object.defineProperty>[2];
|
|
2
|
-
export declare function createObject<T = object>(properties: T, { prototype, ...descriptor }?: {
|
|
2
|
+
export declare function createObject<T extends {} = object>(properties: T, { prototype, ...descriptor }?: {
|
|
3
3
|
prototype?: any;
|
|
4
4
|
} & Exclude<Descriptor, 'value'>): T;
|
|
5
5
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export declare function getStorefrontApiRequestHeaders({ buyerIp,
|
|
1
|
+
export declare function getStorefrontApiRequestHeaders({ buyerIp, publicStorefrontToken, privateStorefrontToken, storefrontId, }: {
|
|
2
2
|
buyerIp?: string | null;
|
|
3
|
-
|
|
3
|
+
publicStorefrontToken: string;
|
|
4
|
+
privateStorefrontToken: string | undefined;
|
|
5
|
+
storefrontId: string | undefined;
|
|
4
6
|
}): Record<string, any>;
|
|
5
7
|
export declare function getOxygenVariable(key: string): any;
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
/* global Oxygen */
|
|
2
2
|
import { OXYGEN_SECRET_TOKEN_ENVIRONMENT_VARIABLE, STOREFRONT_API_SECRET_TOKEN_HEADER, STOREFRONT_API_PUBLIC_TOKEN_HEADER, STOREFRONT_API_BUYER_IP_HEADER, SHOPIFY_STOREFRONT_ID_VARIABLE, SHOPIFY_STOREFRONT_ID_HEADER, } from '../constants.js';
|
|
3
|
-
|
|
3
|
+
import { log } from './log/log.js';
|
|
4
|
+
let secretTokenWarned = false;
|
|
5
|
+
let storefrontIdWarned = false;
|
|
6
|
+
export function getStorefrontApiRequestHeaders({ buyerIp, publicStorefrontToken, privateStorefrontToken, storefrontId, }) {
|
|
4
7
|
const headers = {};
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
if (!privateStorefrontToken && !secretTokenWarned) {
|
|
9
|
+
secretTokenWarned = true;
|
|
10
|
+
privateStorefrontToken = getOxygenVariable(OXYGEN_SECRET_TOKEN_ENVIRONMENT_VARIABLE);
|
|
11
|
+
if (!privateStorefrontToken && !__HYDROGEN_DEV__) {
|
|
12
|
+
log.error('No secret Shopify storefront API token was defined. This means your app will be rate limited!\nSee how to add the token: ');
|
|
13
|
+
}
|
|
14
|
+
else if (privateStorefrontToken) {
|
|
15
|
+
log.warn('The private shopify storefront API token was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: ');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!storefrontId && !storefrontIdWarned) {
|
|
19
|
+
storefrontIdWarned = true;
|
|
20
|
+
storefrontId = getOxygenVariable(SHOPIFY_STOREFRONT_ID_VARIABLE);
|
|
21
|
+
if (!storefrontId && !__HYDROGEN_DEV__) {
|
|
22
|
+
log.warn('No storefrontId was defined. This means the analytics on your admin dashboard will be broken!\nSee how to fix it: ');
|
|
23
|
+
}
|
|
24
|
+
else if (storefrontId) {
|
|
25
|
+
log.warn('The storefrontId was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: ');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
7
28
|
/**
|
|
8
29
|
* Only pass one type of storefront token at a time.
|
|
9
30
|
*/
|
|
10
|
-
if (
|
|
11
|
-
headers[STOREFRONT_API_SECRET_TOKEN_HEADER] =
|
|
31
|
+
if (privateStorefrontToken) {
|
|
32
|
+
headers[STOREFRONT_API_SECRET_TOKEN_HEADER] = privateStorefrontToken;
|
|
12
33
|
}
|
|
13
34
|
else {
|
|
14
|
-
headers[STOREFRONT_API_PUBLIC_TOKEN_HEADER] =
|
|
35
|
+
headers[STOREFRONT_API_PUBLIC_TOKEN_HEADER] = publicStorefrontToken;
|
|
15
36
|
}
|
|
16
37
|
if (buyerIp) {
|
|
17
38
|
headers[STOREFRONT_API_BUYER_IP_HEADER] = buyerIp;
|
package/dist/esnext/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "1.
|
|
1
|
+
export declare const LIB_VERSION = "1.4.0";
|
package/dist/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = '1.
|
|
1
|
+
export const LIB_VERSION = '1.4.0';
|
|
@@ -62,13 +62,5 @@ exports.default = (pluginOptions) => {
|
|
|
62
62
|
};
|
|
63
63
|
async function polyfillOxygenEnv(config) {
|
|
64
64
|
const env = await (0, vite_1.loadEnv)(config.mode, config.root, '');
|
|
65
|
-
const publicPrefixes = Array.isArray(config.envPrefix)
|
|
66
|
-
? config.envPrefix
|
|
67
|
-
: [config.envPrefix || ''];
|
|
68
|
-
for (const key of Object.keys(env)) {
|
|
69
|
-
if (publicPrefixes.some((prefix) => key.startsWith(prefix))) {
|
|
70
|
-
delete env[key];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
65
|
globalThis.Oxygen = { env };
|
|
74
66
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=14"
|
|
9
9
|
},
|
|
10
|
-
"version": "1.
|
|
10
|
+
"version": "1.4.0",
|
|
11
11
|
"description": "Modern custom Shopify storefronts",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "dist/esnext/index.js",
|
|
@@ -134,6 +134,8 @@
|
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@vitejs/plugin-react": "^1.3.0",
|
|
137
|
+
"@xstate/fsm": "^2.0.0",
|
|
138
|
+
"@xstate/react": "^3.0.0",
|
|
137
139
|
"abort-controller": "^3.0.0",
|
|
138
140
|
"body-parser": "^1.20.0",
|
|
139
141
|
"compression": "^1.7.4",
|