@shopify/hydrogen-react 0.0.0-next-ea3959b → 0.0.0-next-dada720
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/README.md +21 -21
- package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
- package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
- package/dist/browser-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-dev/CartCost.mjs +25 -0
- package/dist/browser-dev/CartCost.mjs.map +1 -0
- package/dist/browser-dev/CartLinePrice.mjs +18 -0
- package/dist/browser-dev/CartLinePrice.mjs.map +1 -0
- package/dist/browser-dev/CartLineProvider.mjs +19 -0
- package/dist/browser-dev/CartLineProvider.mjs.map +1 -0
- package/dist/browser-dev/CartProvider.mjs.map +1 -1
- package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
- package/dist/browser-dev/Image.mjs.map +1 -1
- package/dist/browser-dev/MediaFile.mjs.map +1 -1
- package/dist/browser-dev/ModelViewer.mjs.map +1 -1
- package/dist/browser-dev/ProductPrice.mjs.map +1 -1
- package/dist/browser-dev/ProductProvider.mjs.map +1 -1
- package/dist/browser-dev/ShopPayButton.mjs +10 -10
- package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
- package/dist/browser-dev/ShopifyProvider.mjs +9 -21
- package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-dev/analytics-constants.mjs +43 -0
- package/dist/browser-dev/analytics-constants.mjs.map +1 -0
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/browser-dev/analytics-utils.mjs +49 -0
- package/dist/browser-dev/analytics-utils.mjs.map +1 -0
- package/dist/browser-dev/analytics.mjs +159 -0
- package/dist/browser-dev/analytics.mjs.map +1 -0
- package/dist/browser-dev/cart-hooks.mjs +5 -7
- package/dist/browser-dev/cart-hooks.mjs.map +1 -1
- package/dist/browser-dev/cookies-utils.mjs +50 -0
- package/dist/browser-dev/cookies-utils.mjs.map +1 -0
- package/dist/browser-dev/index.mjs +20 -2
- package/dist/browser-dev/index.mjs.map +1 -1
- package/dist/browser-dev/parse-metafield.mjs.map +1 -1
- package/dist/browser-dev/storefront-client.mjs +13 -12
- package/dist/browser-dev/storefront-client.mjs.map +1 -1
- package/dist/browser-dev/useMoney.mjs +2 -1
- package/dist/browser-dev/useMoney.mjs.map +1 -1
- package/dist/browser-dev/useShopifyCookies.mjs +41 -0
- package/dist/browser-dev/useShopifyCookies.mjs.map +1 -0
- package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
- package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
- package/dist/browser-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-prod/CartCost.mjs +25 -0
- package/dist/browser-prod/CartCost.mjs.map +1 -0
- package/dist/browser-prod/CartLinePrice.mjs +18 -0
- package/dist/browser-prod/CartLinePrice.mjs.map +1 -0
- package/dist/browser-prod/CartLineProvider.mjs +19 -0
- package/dist/browser-prod/CartLineProvider.mjs.map +1 -0
- package/dist/browser-prod/CartProvider.mjs.map +1 -1
- package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
- package/dist/browser-prod/Image.mjs.map +1 -1
- package/dist/browser-prod/MediaFile.mjs.map +1 -1
- package/dist/browser-prod/ModelViewer.mjs.map +1 -1
- package/dist/browser-prod/ProductPrice.mjs.map +1 -1
- package/dist/browser-prod/ProductProvider.mjs.map +1 -1
- package/dist/browser-prod/ShopPayButton.mjs +10 -10
- package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
- package/dist/browser-prod/ShopifyProvider.mjs +9 -16
- package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-prod/analytics-constants.mjs +43 -0
- package/dist/browser-prod/analytics-constants.mjs.map +1 -0
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/browser-prod/analytics-utils.mjs +49 -0
- package/dist/browser-prod/analytics-utils.mjs.map +1 -0
- package/dist/browser-prod/analytics.mjs +158 -0
- package/dist/browser-prod/analytics.mjs.map +1 -0
- package/dist/browser-prod/cart-hooks.mjs +5 -7
- package/dist/browser-prod/cart-hooks.mjs.map +1 -1
- package/dist/browser-prod/cookies-utils.mjs +50 -0
- package/dist/browser-prod/cookies-utils.mjs.map +1 -0
- package/dist/browser-prod/index.mjs +20 -2
- package/dist/browser-prod/index.mjs.map +1 -1
- package/dist/browser-prod/parse-metafield.mjs.map +1 -1
- package/dist/browser-prod/storefront-client.mjs +13 -12
- package/dist/browser-prod/storefront-client.mjs.map +1 -1
- package/dist/browser-prod/useMoney.mjs +2 -1
- package/dist/browser-prod/useMoney.mjs.map +1 -1
- package/dist/browser-prod/useShopifyCookies.mjs +41 -0
- package/dist/browser-prod/useShopifyCookies.mjs.map +1 -0
- package/dist/node-dev/AddToCartButton.js.map +1 -1
- package/dist/node-dev/AddToCartButton.mjs.map +1 -1
- package/dist/node-dev/BuyNowButton.js.map +1 -1
- package/dist/node-dev/BuyNowButton.mjs.map +1 -1
- package/dist/node-dev/CartCheckoutButton.js.map +1 -1
- package/dist/node-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-dev/CartCost.js +25 -0
- package/dist/node-dev/CartCost.js.map +1 -0
- package/dist/node-dev/CartCost.mjs +25 -0
- package/dist/node-dev/CartCost.mjs.map +1 -0
- package/dist/node-dev/CartLinePrice.js +18 -0
- package/dist/node-dev/CartLinePrice.js.map +1 -0
- package/dist/node-dev/CartLinePrice.mjs +18 -0
- package/dist/node-dev/CartLinePrice.mjs.map +1 -0
- package/dist/node-dev/CartLineProvider.js +19 -0
- package/dist/node-dev/CartLineProvider.js.map +1 -0
- package/dist/node-dev/CartLineProvider.mjs +19 -0
- package/dist/node-dev/CartLineProvider.mjs.map +1 -0
- package/dist/node-dev/CartProvider.js.map +1 -1
- package/dist/node-dev/CartProvider.mjs.map +1 -1
- package/dist/node-dev/ExternalVideo.js.map +1 -1
- package/dist/node-dev/ExternalVideo.mjs.map +1 -1
- package/dist/node-dev/Image.js.map +1 -1
- package/dist/node-dev/Image.mjs.map +1 -1
- package/dist/node-dev/MediaFile.js.map +1 -1
- package/dist/node-dev/MediaFile.mjs.map +1 -1
- package/dist/node-dev/ModelViewer.js.map +1 -1
- package/dist/node-dev/ModelViewer.mjs.map +1 -1
- package/dist/node-dev/ProductPrice.js.map +1 -1
- package/dist/node-dev/ProductPrice.mjs.map +1 -1
- package/dist/node-dev/ProductProvider.js.map +1 -1
- package/dist/node-dev/ProductProvider.mjs.map +1 -1
- package/dist/node-dev/ShopPayButton.js +9 -9
- package/dist/node-dev/ShopPayButton.js.map +1 -1
- package/dist/node-dev/ShopPayButton.mjs +10 -10
- package/dist/node-dev/ShopPayButton.mjs.map +1 -1
- package/dist/node-dev/ShopifyProvider.js +9 -21
- package/dist/node-dev/ShopifyProvider.js.map +1 -1
- package/dist/node-dev/ShopifyProvider.mjs +9 -21
- package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/node-dev/analytics-constants.js +43 -0
- package/dist/node-dev/analytics-constants.js.map +1 -0
- package/dist/node-dev/analytics-constants.mjs +43 -0
- package/dist/node-dev/analytics-constants.mjs.map +1 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +145 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js +58 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/node-dev/analytics-utils.js +49 -0
- package/dist/node-dev/analytics-utils.js.map +1 -0
- package/dist/node-dev/analytics-utils.mjs +49 -0
- package/dist/node-dev/analytics-utils.mjs.map +1 -0
- package/dist/node-dev/analytics.js +159 -0
- package/dist/node-dev/analytics.js.map +1 -0
- package/dist/node-dev/analytics.mjs +159 -0
- package/dist/node-dev/analytics.mjs.map +1 -0
- package/dist/node-dev/cart-hooks.js +4 -6
- package/dist/node-dev/cart-hooks.js.map +1 -1
- package/dist/node-dev/cart-hooks.mjs +5 -7
- package/dist/node-dev/cart-hooks.mjs.map +1 -1
- package/dist/node-dev/cookies-utils.js +50 -0
- package/dist/node-dev/cookies-utils.js.map +1 -0
- package/dist/node-dev/cookies-utils.mjs +50 -0
- package/dist/node-dev/cookies-utils.mjs.map +1 -0
- package/dist/node-dev/index.js +20 -2
- package/dist/node-dev/index.js.map +1 -1
- package/dist/node-dev/index.mjs +20 -2
- package/dist/node-dev/index.mjs.map +1 -1
- package/dist/node-dev/parse-metafield.js.map +1 -1
- package/dist/node-dev/parse-metafield.mjs.map +1 -1
- package/dist/node-dev/storefront-client.js +13 -12
- package/dist/node-dev/storefront-client.js.map +1 -1
- package/dist/node-dev/storefront-client.mjs +13 -12
- package/dist/node-dev/storefront-client.mjs.map +1 -1
- package/dist/node-dev/useMoney.js +2 -1
- package/dist/node-dev/useMoney.js.map +1 -1
- package/dist/node-dev/useMoney.mjs +2 -1
- package/dist/node-dev/useMoney.mjs.map +1 -1
- package/dist/node-dev/useShopifyCookies.js +41 -0
- package/dist/node-dev/useShopifyCookies.js.map +1 -0
- package/dist/node-dev/useShopifyCookies.mjs +41 -0
- package/dist/node-dev/useShopifyCookies.mjs.map +1 -0
- package/dist/node-prod/AddToCartButton.js.map +1 -1
- package/dist/node-prod/AddToCartButton.mjs.map +1 -1
- package/dist/node-prod/BuyNowButton.js.map +1 -1
- package/dist/node-prod/BuyNowButton.mjs.map +1 -1
- package/dist/node-prod/CartCheckoutButton.js.map +1 -1
- package/dist/node-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-prod/CartCost.js +25 -0
- package/dist/node-prod/CartCost.js.map +1 -0
- package/dist/node-prod/CartCost.mjs +25 -0
- package/dist/node-prod/CartCost.mjs.map +1 -0
- package/dist/node-prod/CartLinePrice.js +18 -0
- package/dist/node-prod/CartLinePrice.js.map +1 -0
- package/dist/node-prod/CartLinePrice.mjs +18 -0
- package/dist/node-prod/CartLinePrice.mjs.map +1 -0
- package/dist/node-prod/CartLineProvider.js +19 -0
- package/dist/node-prod/CartLineProvider.js.map +1 -0
- package/dist/node-prod/CartLineProvider.mjs +19 -0
- package/dist/node-prod/CartLineProvider.mjs.map +1 -0
- package/dist/node-prod/CartProvider.js.map +1 -1
- package/dist/node-prod/CartProvider.mjs.map +1 -1
- package/dist/node-prod/ExternalVideo.js.map +1 -1
- package/dist/node-prod/ExternalVideo.mjs.map +1 -1
- package/dist/node-prod/Image.js.map +1 -1
- package/dist/node-prod/Image.mjs.map +1 -1
- package/dist/node-prod/MediaFile.js.map +1 -1
- package/dist/node-prod/MediaFile.mjs.map +1 -1
- package/dist/node-prod/ModelViewer.js.map +1 -1
- package/dist/node-prod/ModelViewer.mjs.map +1 -1
- package/dist/node-prod/ProductPrice.js.map +1 -1
- package/dist/node-prod/ProductPrice.mjs.map +1 -1
- package/dist/node-prod/ProductProvider.js.map +1 -1
- package/dist/node-prod/ProductProvider.mjs.map +1 -1
- package/dist/node-prod/ShopPayButton.js +9 -9
- package/dist/node-prod/ShopPayButton.js.map +1 -1
- package/dist/node-prod/ShopPayButton.mjs +10 -10
- package/dist/node-prod/ShopPayButton.mjs.map +1 -1
- package/dist/node-prod/ShopifyProvider.js +9 -16
- package/dist/node-prod/ShopifyProvider.js.map +1 -1
- package/dist/node-prod/ShopifyProvider.mjs +9 -16
- package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/node-prod/analytics-constants.js +43 -0
- package/dist/node-prod/analytics-constants.js.map +1 -0
- package/dist/node-prod/analytics-constants.mjs +43 -0
- package/dist/node-prod/analytics-constants.mjs.map +1 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +145 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +145 -0
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js +58 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js.map +1 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs +58 -0
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -0
- package/dist/node-prod/analytics-utils.js +49 -0
- package/dist/node-prod/analytics-utils.js.map +1 -0
- package/dist/node-prod/analytics-utils.mjs +49 -0
- package/dist/node-prod/analytics-utils.mjs.map +1 -0
- package/dist/node-prod/analytics.js +158 -0
- package/dist/node-prod/analytics.js.map +1 -0
- package/dist/node-prod/analytics.mjs +158 -0
- package/dist/node-prod/analytics.mjs.map +1 -0
- package/dist/node-prod/cart-hooks.js +4 -6
- package/dist/node-prod/cart-hooks.js.map +1 -1
- package/dist/node-prod/cart-hooks.mjs +5 -7
- package/dist/node-prod/cart-hooks.mjs.map +1 -1
- package/dist/node-prod/cookies-utils.js +50 -0
- package/dist/node-prod/cookies-utils.js.map +1 -0
- package/dist/node-prod/cookies-utils.mjs +50 -0
- package/dist/node-prod/cookies-utils.mjs.map +1 -0
- package/dist/node-prod/index.js +20 -2
- package/dist/node-prod/index.js.map +1 -1
- package/dist/node-prod/index.mjs +20 -2
- package/dist/node-prod/index.mjs.map +1 -1
- package/dist/node-prod/parse-metafield.js.map +1 -1
- package/dist/node-prod/parse-metafield.mjs.map +1 -1
- package/dist/node-prod/storefront-client.js +13 -12
- package/dist/node-prod/storefront-client.js.map +1 -1
- package/dist/node-prod/storefront-client.mjs +13 -12
- package/dist/node-prod/storefront-client.mjs.map +1 -1
- package/dist/node-prod/useMoney.js +2 -1
- package/dist/node-prod/useMoney.js.map +1 -1
- package/dist/node-prod/useMoney.mjs +2 -1
- package/dist/node-prod/useMoney.mjs.map +1 -1
- package/dist/node-prod/useShopifyCookies.js +41 -0
- package/dist/node-prod/useShopifyCookies.js.map +1 -0
- package/dist/node-prod/useShopifyCookies.mjs +41 -0
- package/dist/node-prod/useShopifyCookies.mjs.map +1 -0
- package/dist/types/AddToCartButton.d.ts +3 -2
- package/dist/types/BuyNowButton.d.ts +7 -3
- package/dist/types/CartCheckoutButton.d.ts +6 -5
- package/dist/types/CartCost.d.ts +7 -5
- package/dist/types/CartLinePrice.d.ts +4 -4
- package/dist/types/CartLineProvider.d.ts +8 -6
- package/dist/types/CartProvider.d.ts +12 -2
- package/dist/types/ExternalVideo.d.ts +1 -2
- package/dist/types/Image.d.ts +5 -3
- package/dist/types/MediaFile.d.ts +12 -11
- package/dist/types/ModelViewer.d.ts +2 -2
- package/dist/types/ProductPrice.d.ts +1 -1
- package/dist/types/ProductProvider.d.ts +1 -1
- package/dist/types/ShopPayButton.d.ts +10 -10
- package/dist/types/ShopifyProvider.d.ts +35 -39
- package/dist/types/analytics-constants.d.ts +48 -0
- package/dist/types/analytics-schema-custom-storefront-customer-tracking.d.ts +3 -0
- package/dist/types/analytics-schema-trekkie-storefront-page-view.d.ts +2 -0
- package/dist/types/analytics-types.d.ts +108 -0
- package/dist/types/analytics-utils.d.ts +36 -0
- package/dist/types/analytics.d.ts +9 -0
- package/dist/types/cookies-utils.d.ts +4 -0
- package/dist/types/index.d.cts +11 -3
- package/dist/types/index.d.ts +11 -3
- package/dist/types/parse-metafield.d.ts +1 -3
- package/dist/types/storefront-client.d.ts +14 -14
- package/dist/types/useShopifyCookies.d.ts +14 -0
- package/dist/umd/hydrogen-react.dev.js +704 -172
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +18 -16
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +12 -7
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require$$0 = require("react");
|
|
4
|
+
const cookie = require("worktop/cookie");
|
|
5
|
+
const cartConstants = require("./cart-constants.js");
|
|
6
|
+
const cookiesUtils = require("./cookies-utils.js");
|
|
7
|
+
const longTermLength = 60 * 60 * 24 * 360 * 1;
|
|
8
|
+
const shortTermLength = 60 * 30;
|
|
9
|
+
function useShopifyCookies(options) {
|
|
10
|
+
const { hasUserConsent = false, domain = "" } = options || {};
|
|
11
|
+
require$$0.useEffect(() => {
|
|
12
|
+
const cookies = cookiesUtils.getShopifyCookies(document.cookie);
|
|
13
|
+
if (hasUserConsent) {
|
|
14
|
+
setCookie(
|
|
15
|
+
cartConstants.SHOPIFY_Y,
|
|
16
|
+
cookies[cartConstants.SHOPIFY_Y] || cookiesUtils.buildUUID(),
|
|
17
|
+
longTermLength,
|
|
18
|
+
domain
|
|
19
|
+
);
|
|
20
|
+
setCookie(
|
|
21
|
+
cartConstants.SHOPIFY_S,
|
|
22
|
+
cookies[cartConstants.SHOPIFY_S] || cookiesUtils.buildUUID(),
|
|
23
|
+
shortTermLength,
|
|
24
|
+
domain
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
setCookie(cartConstants.SHOPIFY_Y, "", 0, domain);
|
|
28
|
+
setCookie(cartConstants.SHOPIFY_S, "", 0, domain);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function setCookie(name, value, maxage, domain) {
|
|
33
|
+
document.cookie = cookie.stringify(name, value, {
|
|
34
|
+
maxage,
|
|
35
|
+
domain,
|
|
36
|
+
samesite: "Lax",
|
|
37
|
+
path: "/"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.useShopifyCookies = useShopifyCookies;
|
|
41
|
+
//# sourceMappingURL=useShopifyCookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShopifyCookies.js","sources":["../../src/useShopifyCookies.tsx"],"sourcesContent":["import {useEffect} from 'react';\nimport {stringify} from 'worktop/cookie';\nimport {SHOPIFY_Y, SHOPIFY_S} from './cart-constants.js';\nimport {buildUUID, getShopifyCookies} from './cookies-utils.js';\n\nconst longTermLength = 60 * 60 * 24 * 360 * 1; // ~1 year expiry\nconst shortTermLength = 60 * 30; // 30 mins\n\ntype UseShopifyCookiesOptions = {\n /**\n * If set to `false`, Shopify cookies will be removed.\n * If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.\n * Defaults to false.\n **/\n hasUserConsent?: boolean;\n /**\n * The domain scope of the cookie. Defaults to empty string.\n **/\n domain?: string;\n};\n\nexport function useShopifyCookies(options?: UseShopifyCookiesOptions): void {\n const {hasUserConsent = false, domain = ''} = options || {};\n useEffect(() => {\n const cookies = getShopifyCookies(document.cookie);\n\n /**\n * Set user and session cookies and refresh the expiry time\n */\n if (hasUserConsent) {\n setCookie(\n SHOPIFY_Y,\n cookies[SHOPIFY_Y] || buildUUID(),\n longTermLength,\n domain\n );\n setCookie(\n SHOPIFY_S,\n cookies[SHOPIFY_S] || buildUUID(),\n shortTermLength,\n domain\n );\n } else {\n setCookie(SHOPIFY_Y, '', 0, domain);\n setCookie(SHOPIFY_S, '', 0, domain);\n }\n });\n}\n\nfunction setCookie(\n name: string,\n value: string,\n maxage: number,\n domain: string\n): void {\n document.cookie = stringify(name, value, {\n maxage,\n domain,\n samesite: 'Lax',\n path: '/',\n });\n}\n"],"names":["useEffect","getShopifyCookies","SHOPIFY_Y","buildUUID","SHOPIFY_S","stringify"],"mappings":";;;;;;AAKA,MAAM,iBAAiB,KAAK,KAAK,KAAK,MAAM;AAC5C,MAAM,kBAAkB,KAAK;AAetB,SAAS,kBAAkB,SAA0C;AAC1E,QAAM,EAAC,iBAAiB,OAAO,SAAS,GAAE,IAAI,WAAW;AACzDA,aAAAA,UAAU,MAAM;AACR,UAAA,UAAUC,aAAAA,kBAAkB,SAAS,MAAM;AAKjD,QAAI,gBAAgB;AAClB;AAAA,QACEC,cAAA;AAAA,QACA,QAAQA,cAAAA,SAAS,KAAKC,uBAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAEF;AAAA,QACEC,cAAA;AAAA,QACA,QAAQA,cAAAA,SAAS,KAAKD,uBAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAAA,IACF,OACK;AACK,gBAAAD,cAAAA,WAAW,IAAI,GAAG,MAAM;AACxB,gBAAAE,cAAAA,WAAW,IAAI,GAAG,MAAM;AAAA,IACpC;AAAA,EAAA,CACD;AACH;AAEA,SAAS,UACP,MACA,OACA,QACA,QACM;AACG,WAAA,SAASC,iBAAU,MAAM,OAAO;AAAA,IACvC;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EAAA,CACP;AACH;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { stringify } from "worktop/cookie";
|
|
3
|
+
import { SHOPIFY_Y, SHOPIFY_S } from "./cart-constants.mjs";
|
|
4
|
+
import { getShopifyCookies, buildUUID } from "./cookies-utils.mjs";
|
|
5
|
+
const longTermLength = 60 * 60 * 24 * 360 * 1;
|
|
6
|
+
const shortTermLength = 60 * 30;
|
|
7
|
+
function useShopifyCookies(options) {
|
|
8
|
+
const { hasUserConsent = false, domain = "" } = options || {};
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const cookies = getShopifyCookies(document.cookie);
|
|
11
|
+
if (hasUserConsent) {
|
|
12
|
+
setCookie(
|
|
13
|
+
SHOPIFY_Y,
|
|
14
|
+
cookies[SHOPIFY_Y] || buildUUID(),
|
|
15
|
+
longTermLength,
|
|
16
|
+
domain
|
|
17
|
+
);
|
|
18
|
+
setCookie(
|
|
19
|
+
SHOPIFY_S,
|
|
20
|
+
cookies[SHOPIFY_S] || buildUUID(),
|
|
21
|
+
shortTermLength,
|
|
22
|
+
domain
|
|
23
|
+
);
|
|
24
|
+
} else {
|
|
25
|
+
setCookie(SHOPIFY_Y, "", 0, domain);
|
|
26
|
+
setCookie(SHOPIFY_S, "", 0, domain);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function setCookie(name, value, maxage, domain) {
|
|
31
|
+
document.cookie = stringify(name, value, {
|
|
32
|
+
maxage,
|
|
33
|
+
domain,
|
|
34
|
+
samesite: "Lax",
|
|
35
|
+
path: "/"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
useShopifyCookies
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useShopifyCookies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShopifyCookies.mjs","sources":["../../src/useShopifyCookies.tsx"],"sourcesContent":["import {useEffect} from 'react';\nimport {stringify} from 'worktop/cookie';\nimport {SHOPIFY_Y, SHOPIFY_S} from './cart-constants.js';\nimport {buildUUID, getShopifyCookies} from './cookies-utils.js';\n\nconst longTermLength = 60 * 60 * 24 * 360 * 1; // ~1 year expiry\nconst shortTermLength = 60 * 30; // 30 mins\n\ntype UseShopifyCookiesOptions = {\n /**\n * If set to `false`, Shopify cookies will be removed.\n * If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.\n * Defaults to false.\n **/\n hasUserConsent?: boolean;\n /**\n * The domain scope of the cookie. Defaults to empty string.\n **/\n domain?: string;\n};\n\nexport function useShopifyCookies(options?: UseShopifyCookiesOptions): void {\n const {hasUserConsent = false, domain = ''} = options || {};\n useEffect(() => {\n const cookies = getShopifyCookies(document.cookie);\n\n /**\n * Set user and session cookies and refresh the expiry time\n */\n if (hasUserConsent) {\n setCookie(\n SHOPIFY_Y,\n cookies[SHOPIFY_Y] || buildUUID(),\n longTermLength,\n domain\n );\n setCookie(\n SHOPIFY_S,\n cookies[SHOPIFY_S] || buildUUID(),\n shortTermLength,\n domain\n );\n } else {\n setCookie(SHOPIFY_Y, '', 0, domain);\n setCookie(SHOPIFY_S, '', 0, domain);\n }\n });\n}\n\nfunction setCookie(\n name: string,\n value: string,\n maxage: number,\n domain: string\n): void {\n document.cookie = stringify(name, value, {\n maxage,\n domain,\n samesite: 'Lax',\n path: '/',\n });\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,iBAAiB,KAAK,KAAK,KAAK,MAAM;AAC5C,MAAM,kBAAkB,KAAK;AAetB,SAAS,kBAAkB,SAA0C;AAC1E,QAAM,EAAC,iBAAiB,OAAO,SAAS,GAAE,IAAI,WAAW;AACzD,YAAU,MAAM;AACR,UAAA,UAAU,kBAAkB,SAAS,MAAM;AAKjD,QAAI,gBAAgB;AAClB;AAAA,QACE;AAAA,QACA,QAAQ,SAAS,KAAK,UAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAEF;AAAA,QACE;AAAA,QACA,QAAQ,SAAS,KAAK,UAAU;AAAA,QAChC;AAAA,QACA;AAAA,MAAA;AAAA,IACF,OACK;AACK,gBAAA,WAAW,IAAI,GAAG,MAAM;AACxB,gBAAA,WAAW,IAAI,GAAG,MAAM;AAAA,IACpC;AAAA,EAAA,CACD;AACH;AAEA,SAAS,UACP,MACA,OACA,QACA,QACM;AACG,WAAA,SAAS,UAAU,MAAM,OAAO;AAAA,IACvC;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,MAAM;AAAA,EAAA,CACP;AACH;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseButtonProps } from './BaseButton.js';
|
|
2
|
-
export interface
|
|
2
|
+
export interface AddToCartButtonPropsBase {
|
|
3
3
|
/** An array of cart line attributes that belong to the item being added to the cart. */
|
|
4
4
|
attributes?: {
|
|
5
5
|
key: string;
|
|
@@ -14,8 +14,9 @@ export interface AddToCartButtonProps {
|
|
|
14
14
|
/** The selling plan ID of the subscription variant */
|
|
15
15
|
sellingPlanId?: string;
|
|
16
16
|
}
|
|
17
|
+
export type AddToCartButtonProps<AsType extends React.ElementType = 'button'> = AddToCartButtonPropsBase & BaseButtonProps<AsType>;
|
|
17
18
|
/**
|
|
18
19
|
* The `AddToCartButton` component renders a button that adds an item to the cart when pressed.
|
|
19
20
|
* It must be a descendent of the `CartProvider` component.
|
|
20
21
|
*/
|
|
21
|
-
export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps
|
|
22
|
+
export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps<AsType>): JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseButtonProps } from './BaseButton.js';
|
|
2
|
-
interface
|
|
2
|
+
interface BuyNowButtonPropsBase {
|
|
3
3
|
/** The item quantity. Defaults to 1. */
|
|
4
4
|
quantity?: number;
|
|
5
5
|
/** The ID of the variant. */
|
|
@@ -10,6 +10,10 @@ interface BuyNowButtonProps {
|
|
|
10
10
|
value: string;
|
|
11
11
|
}[];
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
type BuyNowButtonProps<AsType extends React.ElementType = 'button'> = BuyNowButtonPropsBase & BaseButtonProps<AsType>;
|
|
14
|
+
/**
|
|
15
|
+
* The `BuyNowButton` component renders a button that adds an item to the cart and redirects the customer to checkout.
|
|
16
|
+
* Must be a child of a `CartProvider` component.
|
|
17
|
+
*/
|
|
18
|
+
export declare function BuyNowButton<AsType extends React.ElementType = 'button'>(props: BuyNowButtonProps<AsType>): JSX.Element;
|
|
15
19
|
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { BaseButtonProps } from './BaseButton.js';
|
|
3
|
-
type
|
|
3
|
+
type ChildrenProps = {
|
|
4
|
+
/** A `ReactNode` element. */
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type CartCheckoutButtonProps = Omit<BaseButtonProps<'button'>, 'onClick'> & ChildrenProps;
|
|
4
8
|
/**
|
|
5
9
|
* The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.
|
|
6
10
|
* It must be a descendent of a `CartProvider` component.
|
|
7
11
|
*/
|
|
8
|
-
export declare function CartCheckoutButton(props:
|
|
9
|
-
/** A `ReactNode` element. */
|
|
10
|
-
children: ReactNode;
|
|
11
|
-
}): JSX.Element;
|
|
12
|
+
export declare function CartCheckoutButton(props: CartCheckoutButtonProps): JSX.Element;
|
|
12
13
|
export {};
|
package/dist/types/CartCost.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Money } from './Money.js';
|
|
2
|
-
|
|
2
|
+
interface CartCostPropsBase {
|
|
3
3
|
/** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */
|
|
4
4
|
amountType?: 'total' | 'subtotal' | 'tax' | 'duty';
|
|
5
5
|
/** Any `ReactNode` elements. */
|
|
6
6
|
children?: React.ReactNode;
|
|
7
7
|
}
|
|
8
|
+
type CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> & CartCostPropsBase;
|
|
8
9
|
/**
|
|
9
|
-
* The `CartCost` component renders a `Money` component with the
|
|
10
|
-
*
|
|
11
|
-
Depends on `useCart()` and must be a child of `<CartProvider/>`
|
|
10
|
+
* The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.
|
|
11
|
+
* If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
12
|
+
* Depends on `useCart()` and must be a child of `<CartProvider/>`
|
|
12
13
|
*/
|
|
13
|
-
export declare function CartCost(props:
|
|
14
|
+
export declare function CartCost(props: CartCostProps): JSX.Element | null;
|
|
15
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Money } from './Money.js';
|
|
2
2
|
import { CartLine } from './storefront-api-types.js';
|
|
3
3
|
import { PartialDeep } from 'type-fest';
|
|
4
|
-
interface
|
|
4
|
+
interface CartLinePricePropsBase {
|
|
5
5
|
/** A [CartLine object](https://shopify.dev/api/storefront/reference/objects/CartLine). */
|
|
6
6
|
data: PartialDeep<CartLine, {
|
|
7
7
|
recurseIntoArrays: true;
|
|
@@ -9,9 +9,9 @@ interface CartLinePriceProps {
|
|
|
9
9
|
/** The type of price. Valid values:`regular` (default) or `compareAt`. */
|
|
10
10
|
priceType?: 'regular' | 'compareAt';
|
|
11
11
|
}
|
|
12
|
+
type CartLinePriceProps = Omit<React.ComponentProps<typeof Money>, 'data'> & CartLinePricePropsBase;
|
|
12
13
|
/**
|
|
13
|
-
* The `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or
|
|
14
|
-
* compare at price.
|
|
14
|
+
* The `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or compare at price.
|
|
15
15
|
*/
|
|
16
|
-
export declare function CartLinePrice(props:
|
|
16
|
+
export declare function CartLinePrice(props: CartLinePriceProps): JSX.Element | null;
|
|
17
17
|
export {};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { CartLine } from './storefront-api-types.js';
|
|
2
|
+
import type { CartLine } from './storefront-api-types.js';
|
|
3
3
|
export declare const CartLineContext: import("react").Context<CartLine | null>;
|
|
4
4
|
/**
|
|
5
5
|
* The `useCartLine` hook provides access to the cart line object. It must be a descendent of a `CartProvider` component.
|
|
6
6
|
*/
|
|
7
7
|
export declare function useCartLine(): CartLine;
|
|
8
|
-
|
|
9
|
-
* The `CartLineProvider` component creates a context for using a cart line.
|
|
10
|
-
*/
|
|
11
|
-
export declare function CartLineProvider({ children, line, }: {
|
|
8
|
+
type CartLineProviderProps = {
|
|
12
9
|
/** Any `ReactNode` elements. */
|
|
13
10
|
children: ReactNode;
|
|
14
11
|
/** A cart line object. */
|
|
15
12
|
line: CartLine;
|
|
16
|
-
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The `CartLineProvider` component creates a context for using a cart line.
|
|
16
|
+
*/
|
|
17
|
+
export declare function CartLineProvider({ children, line }: CartLineProviderProps): JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -6,7 +6,7 @@ export declare const CartContext: import("react").Context<CartWithActions | null
|
|
|
6
6
|
* The `useCart` hook provides access to the cart object. It must be a descendent of a `CartProvider` component.
|
|
7
7
|
*/
|
|
8
8
|
export declare function useCart(): CartWithActions;
|
|
9
|
-
|
|
9
|
+
type CartProviderProps = {
|
|
10
10
|
/** Any `ReactNode` elements. */
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
/** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
|
|
@@ -53,8 +53,18 @@ export declare function CartProvider({ children, numCartLines, onCreate, onLineA
|
|
|
53
53
|
customerAccessToken?: CartBuyerIdentityInput['customerAccessToken'];
|
|
54
54
|
/** The ISO country code for i18n. */
|
|
55
55
|
countryCode?: CountryCode;
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The `CartProvider` component synchronizes the state of the Storefront API Cart and a customer's cart,
|
|
59
|
+
* and allows you to more easily manipulate the cart by adding, removing, and updating it.
|
|
60
|
+
* It could be placed at the root of your app so that your whole app is able to use the `useCart()` hook anywhere.
|
|
61
|
+
*
|
|
62
|
+
* There are props that trigger when a call to the Storefront API is made, such as `onLineAdd={}` when a line is added to the cart.
|
|
63
|
+
* There are also props that trigger when a call to the Storefront API is completed, such as `onLineAddComplete={}` when the fetch request for adding a line to the cart completes.
|
|
64
|
+
*/
|
|
65
|
+
export declare function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, onCreateComplete, onLineAddComplete, onLineRemoveComplete, onLineUpdateComplete, onNoteUpdateComplete, onBuyerIdentityUpdateComplete, onAttributesUpdateComplete, onDiscountCodesUpdateComplete, data: cart, cartFragment, customerAccessToken, countryCode, }: CartProviderProps): JSX.Element;
|
|
57
66
|
/** Check for storage availability funciton obtained from
|
|
58
67
|
* https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
|
|
59
68
|
*/
|
|
60
69
|
export declare function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean | undefined;
|
|
70
|
+
export {};
|
|
@@ -13,8 +13,7 @@ interface BaseProps {
|
|
|
13
13
|
*/
|
|
14
14
|
options?: YouTube | Vimeo;
|
|
15
15
|
}
|
|
16
|
-
type
|
|
17
|
-
export type ExternalVideoProps = Omit<JSX.IntrinsicElements['iframe'], PropsWeControl> & BaseProps;
|
|
16
|
+
export type ExternalVideoProps = Omit<JSX.IntrinsicElements['iframe'], 'src'> & BaseProps;
|
|
18
17
|
/**
|
|
19
18
|
* The `ExternalVideo` component renders an embedded video for the Storefront
|
|
20
19
|
* API's [ExternalVideo object](https://shopify.dev/api/storefront/reference/products/externalvideo).
|
package/dist/types/Image.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ export type ShopifyLoaderOptions = {
|
|
|
8
8
|
width?: HtmlImageProps['width'] | ImageType['width'];
|
|
9
9
|
height?: HtmlImageProps['height'] | ImageType['height'];
|
|
10
10
|
};
|
|
11
|
-
export type ShopifyLoaderParams = Simplify<ShopifyLoaderOptions &
|
|
11
|
+
export type ShopifyLoaderParams = Simplify<ShopifyLoaderOptions & ImageSrc>;
|
|
12
|
+
type ImageSrc = {
|
|
12
13
|
src: ImageType['url'];
|
|
13
|
-
}
|
|
14
|
-
export type ShopifyImageProps = Omit<HtmlImageProps, 'src'> &
|
|
14
|
+
};
|
|
15
|
+
export type ShopifyImageProps = Omit<HtmlImageProps, 'src'> & ShopifyImageBaseProps;
|
|
16
|
+
type ShopifyImageBaseProps = {
|
|
15
17
|
/** An object with fields that correspond to the Storefront API's
|
|
16
18
|
* [Image object](https://shopify.dev/api/storefront/reference/common-objects/image).
|
|
17
19
|
* The `data` prop is required.
|
|
@@ -11,18 +11,19 @@ export interface MediaFileProps extends BaseProps {
|
|
|
11
11
|
data: PartialDeep<MediaEdgeType['node'], {
|
|
12
12
|
recurseIntoArrays: true;
|
|
13
13
|
}>;
|
|
14
|
-
/** The options for the `Image`, `Video`, or `
|
|
15
|
-
mediaOptions?:
|
|
16
|
-
/** Props that will only apply when an `<Image />` is rendered */
|
|
17
|
-
image?: Omit<ShopifyImageProps, 'data'>;
|
|
18
|
-
/** Props that will only apply when a `<Video />` is rendered */
|
|
19
|
-
video?: Omit<React.ComponentProps<typeof Video>, 'data'>;
|
|
20
|
-
/** Props that will only apply when an `<ExternalVideo />` is rendered */
|
|
21
|
-
externalVideo?: Omit<React.ComponentProps<typeof ExternalVideo>['options'], 'data'>;
|
|
22
|
-
/** Props that will only apply when a `<ModelViewer />` is rendered */
|
|
23
|
-
modelViewer?: Omit<typeof ModelViewer, 'data'>;
|
|
24
|
-
};
|
|
14
|
+
/** The options for the `Image`, `Video`, `ExternalVideo`, or `ModelViewer` components. */
|
|
15
|
+
mediaOptions?: MediaOptions;
|
|
25
16
|
}
|
|
17
|
+
type MediaOptions = {
|
|
18
|
+
/** Props that will only apply when an `<Image />` is rendered */
|
|
19
|
+
image?: Omit<ShopifyImageProps, 'data'>;
|
|
20
|
+
/** Props that will only apply when a `<Video />` is rendered */
|
|
21
|
+
video?: Omit<React.ComponentProps<typeof Video>, 'data'>;
|
|
22
|
+
/** Props that will only apply when an `<ExternalVideo />` is rendered */
|
|
23
|
+
externalVideo?: Omit<React.ComponentProps<typeof ExternalVideo>['options'], 'data'>;
|
|
24
|
+
/** Props that will only apply when a `<ModelViewer />` is rendered */
|
|
25
|
+
modelViewer?: Omit<typeof ModelViewer, 'data'>;
|
|
26
|
+
};
|
|
26
27
|
/**
|
|
27
28
|
* The `MediaFile` component renders the media for the Storefront API's
|
|
28
29
|
* [Media object](https://shopify.dev/api/storefront/reference/products/media). It renders an `Image`, a
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Model3d } from './storefront-api-types.js';
|
|
2
2
|
import type { PartialDeep } from 'type-fest';
|
|
3
3
|
import type { ModelViewerElement } from '@google/model-viewer/lib/model-viewer.js';
|
|
4
|
-
type PropsWeControl = 'src';
|
|
5
4
|
declare global {
|
|
6
5
|
namespace JSX {
|
|
7
6
|
interface IntrinsicElements {
|
|
@@ -13,7 +12,8 @@ declare global {
|
|
|
13
12
|
}
|
|
14
13
|
type ModelViewerProps = Omit<PartialDeep<JSX.IntrinsicElements['model-viewer'], {
|
|
15
14
|
recurseIntoArrays: true;
|
|
16
|
-
}>,
|
|
15
|
+
}>, 'src'> & ModelViewerBaseProps;
|
|
16
|
+
type ModelViewerBaseProps = {
|
|
17
17
|
/** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/latest/objects/model3d). */
|
|
18
18
|
data: PartialDeep<Model3d, {
|
|
19
19
|
recurseIntoArrays: true;
|
|
@@ -2,7 +2,7 @@ import type { Product } from './storefront-api-types.js';
|
|
|
2
2
|
import { type MoneyProps } from './Money.js';
|
|
3
3
|
import type { PartialDeep } from 'type-fest';
|
|
4
4
|
export interface ProductPriceProps {
|
|
5
|
-
/** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
5
|
+
/** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
6
6
|
data: PartialDeep<Product, {
|
|
7
7
|
recurseIntoArrays: true;
|
|
8
8
|
}>;
|
|
@@ -2,7 +2,7 @@ import type { SelectedOption as SelectedOptionType, Product, ProductVariant as P
|
|
|
2
2
|
import type { PartialDeep } from 'type-fest';
|
|
3
3
|
type InitialVariantId = ProductVariantType['id'] | null;
|
|
4
4
|
interface ProductProviderProps {
|
|
5
|
-
/** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
5
|
+
/** A Storefront API [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
6
6
|
data: PartialDeep<Product, {
|
|
7
7
|
recurseIntoArrays: true;
|
|
8
8
|
}>;
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
type ShopPayButtonProps =
|
|
1
|
+
type ShopPayButtonProps = ShopPayButtonStyleProps & (ShopPayVariantIds | ShopPayVariantAndQuantities);
|
|
2
|
+
type ShopPayButtonStyleProps = {
|
|
2
3
|
/** A string of classes to apply to the `div` that wraps the Shop Pay button. */
|
|
3
4
|
className?: string;
|
|
4
5
|
/** A string that's applied to the [CSS custom property (variable)](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) `--shop-pay-button-width` for the [Buy with Shop Pay component](https://shopify.dev/custom-storefronts/tools/web-components#buy-with-shop-pay-component). */
|
|
5
6
|
width?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
7
|
+
};
|
|
8
|
+
type ShopPayVariantIds = {
|
|
9
|
+
/** An array of IDs of the variants to purchase with Shop Pay. This will only ever have a quantity of 1 for each variant. If you want to use other quantities, then use `variantIdsAndQuantities`. */
|
|
8
10
|
variantIds: string[];
|
|
9
11
|
/** An array of variant IDs and quantities to purchase with Shop Pay. */
|
|
10
12
|
variantIdsAndQuantities?: never;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
+
};
|
|
14
|
+
type ShopPayVariantAndQuantities = {
|
|
15
|
+
/** An array of IDs of the variants to purchase with Shop Pay. This will only ever have a quantity of 1 for each variant. If you want to use other quantities, then use `variantIdsAndQuantities`. */
|
|
13
16
|
variantIds?: never;
|
|
14
17
|
/** An array of variant IDs and quantities to purchase with Shop Pay. */
|
|
15
18
|
variantIdsAndQuantities: Array<{
|
|
16
19
|
id: string;
|
|
17
20
|
quantity: number;
|
|
18
21
|
}>;
|
|
19
|
-
}
|
|
22
|
+
};
|
|
20
23
|
declare global {
|
|
21
24
|
namespace JSX {
|
|
22
25
|
interface IntrinsicElements {
|
|
@@ -33,10 +36,7 @@ declare global {
|
|
|
33
36
|
* It relies on the `<ShopProvider>` context provider.
|
|
34
37
|
*/
|
|
35
38
|
export declare function ShopPayButton({ variantIds, className, variantIdsAndQuantities, width, }: ShopPayButtonProps): JSX.Element;
|
|
36
|
-
|
|
37
|
-
* Takes a string in the format of "gid://shopify/ProductVariant/41007289630776" and returns a string of the ID part at the end: "41007289630776"
|
|
38
|
-
*/
|
|
39
|
-
export declare function getIdFromGid(id?: string): string | undefined;
|
|
39
|
+
export declare const InvalidPropsErrorMessage = "You must pass in \"variantIds\" in the form of [\"gid://shopify/ProductVariant/1\"]";
|
|
40
40
|
export declare const MissingPropsErrorMessage = "You must pass in either \"variantIds\" or \"variantIdsAndQuantities\" to ShopPayButton";
|
|
41
41
|
export declare const DoublePropsErrorMessage = "You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component";
|
|
42
42
|
export {};
|
|
@@ -3,44 +3,36 @@ import type { LanguageCode, CountryCode } from './storefront-api-types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* The `<ShopifyProvider/>` component enables use of the `useShop()` hook. The component should wrap your app.
|
|
5
5
|
*/
|
|
6
|
-
export declare function ShopifyProvider({ children, shopifyConfig
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
shopifyConfig: ShopifyContextProps;
|
|
9
|
-
}): JSX.Element;
|
|
6
|
+
export declare function ShopifyProvider({ children, ...shopifyConfig }: ShopifyProviderProps): JSX.Element;
|
|
10
7
|
/**
|
|
11
8
|
* Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`.
|
|
12
9
|
*/
|
|
13
10
|
export declare function useShop(): ShopifyContextValue;
|
|
14
11
|
/**
|
|
15
|
-
* Shopify-specific values that are used in various Hydrogen
|
|
12
|
+
* Shopify-specific values that are used in various Hydrogen React components and hooks.
|
|
16
13
|
*/
|
|
17
|
-
export type
|
|
14
|
+
export type ShopifyProviderProps = {
|
|
18
15
|
/** The globally-unique identifier for the Shop */
|
|
19
16
|
storefrontId?: string;
|
|
20
17
|
/** The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). */
|
|
21
18
|
storeDomain: string;
|
|
22
19
|
/** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */
|
|
23
20
|
storefrontToken: string;
|
|
24
|
-
/** The Storefront API version. This should almost always be the same as the version Hydrogen
|
|
21
|
+
/** The Storefront API version. This should almost always be the same as the version Hydrogen React was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */
|
|
25
22
|
storefrontApiVersion: string;
|
|
26
|
-
country?: {
|
|
27
|
-
/**
|
|
28
|
-
* The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.
|
|
29
|
-
*/
|
|
30
|
-
isoCode: CountryCode;
|
|
31
|
-
};
|
|
32
|
-
language?: {
|
|
33
|
-
/**
|
|
34
|
-
* `ISO 369` language codes supported by Shopify.
|
|
35
|
-
*/
|
|
36
|
-
isoCode: LanguageCode;
|
|
37
|
-
};
|
|
38
23
|
/**
|
|
39
|
-
* The
|
|
24
|
+
* The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`.
|
|
40
25
|
*/
|
|
41
|
-
|
|
26
|
+
countryIsoCode: CountryCode;
|
|
27
|
+
/**
|
|
28
|
+
* `ISO 369` language codes supported by Shopify.
|
|
29
|
+
*/
|
|
30
|
+
languageIsoCode: LanguageCode;
|
|
31
|
+
/** React children to render. */
|
|
32
|
+
children?: ReactNode;
|
|
42
33
|
};
|
|
43
|
-
export type ShopifyContextValue =
|
|
34
|
+
export type ShopifyContextValue = Omit<ShopifyProviderProps, 'children'> & ShopifyContextReturn;
|
|
35
|
+
type ShopifyContextReturn = {
|
|
44
36
|
/**
|
|
45
37
|
* Creates the fully-qualified URL to your store's GraphQL endpoint.
|
|
46
38
|
*
|
|
@@ -49,12 +41,7 @@ export type ShopifyContextValue = ShopifyContextProps & {
|
|
|
49
41
|
* - `storeDomain`
|
|
50
42
|
* - `storefrontApiVersion`
|
|
51
43
|
*/
|
|
52
|
-
getStorefrontApiUrl: (props?:
|
|
53
|
-
/** The host name of the domain (eg: `{shop}.myshopify.com`). */
|
|
54
|
-
storeDomain?: string;
|
|
55
|
-
/** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */
|
|
56
|
-
storefrontApiVersion?: string;
|
|
57
|
-
}) => string;
|
|
44
|
+
getStorefrontApiUrl: (props?: GetStorefrontApiUrlProps) => string;
|
|
58
45
|
/**
|
|
59
46
|
* Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. This uses the public Storefront API token.
|
|
60
47
|
*
|
|
@@ -64,14 +51,7 @@ export type ShopifyContextValue = ShopifyContextProps & {
|
|
|
64
51
|
* - `storefrontToken`
|
|
65
52
|
*
|
|
66
53
|
*/
|
|
67
|
-
getPublicTokenHeaders: (props:
|
|
68
|
-
/**
|
|
69
|
-
* Customizes which `"content-type"` header is added when using `getPrivateTokenHeaders()` and `getPublicTokenHeaders()`. When fetching with a `JSON.stringify()`-ed `body`, use `"json"`. When fetching with a `body` that is a plain string, use `"graphql"`. Defaults to `"json"`
|
|
70
|
-
*/
|
|
71
|
-
contentType: 'json' | 'graphql';
|
|
72
|
-
/** The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */
|
|
73
|
-
storefrontToken?: string;
|
|
74
|
-
}) => Record<string, string>;
|
|
54
|
+
getPublicTokenHeaders: (props: GetPublicTokenHeadersProps) => Record<string, string>;
|
|
75
55
|
/**
|
|
76
56
|
* Creates the fully-qualified URL to your myshopify.com domain.
|
|
77
57
|
*
|
|
@@ -79,7 +59,23 @@ export type ShopifyContextValue = ShopifyContextProps & {
|
|
|
79
59
|
*
|
|
80
60
|
* - `storeDomain`
|
|
81
61
|
*/
|
|
82
|
-
getShopifyDomain: (props?:
|
|
83
|
-
|
|
84
|
-
|
|
62
|
+
getShopifyDomain: (props?: GetShopifyDomainProps) => string;
|
|
63
|
+
};
|
|
64
|
+
type GetStorefrontApiUrlProps = {
|
|
65
|
+
/** The host name of the domain (eg: `{shop}.myshopify.com`). */
|
|
66
|
+
storeDomain?: string;
|
|
67
|
+
/** The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. */
|
|
68
|
+
storefrontApiVersion?: string;
|
|
69
|
+
};
|
|
70
|
+
type GetPublicTokenHeadersProps = {
|
|
71
|
+
/**
|
|
72
|
+
* Customizes which `"content-type"` header is added when using `getPrivateTokenHeaders()` and `getPublicTokenHeaders()`. When fetching with a `JSON.stringify()`-ed `body`, use `"json"`. When fetching with a `body` that is a plain string, use `"graphql"`. Defaults to `"json"`
|
|
73
|
+
*/
|
|
74
|
+
contentType: 'json' | 'graphql';
|
|
75
|
+
/** The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */
|
|
76
|
+
storefrontToken?: string;
|
|
77
|
+
};
|
|
78
|
+
type GetShopifyDomainProps = {
|
|
79
|
+
storeDomain?: string;
|
|
85
80
|
};
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const AnalyticsEventName: AnalyticsEventName;
|
|
2
|
+
export declare const AnalyticsPageType: AnalyticsPageType;
|
|
3
|
+
export declare const ShopifySalesChannel: ShopifySalesChannel;
|
|
4
|
+
export declare const ShopifyAppId: {
|
|
5
|
+
readonly hydrogen: "6167201";
|
|
6
|
+
readonly headless: "12875497473";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* These duplicated interface declaration is so that we can generate proper documentation
|
|
10
|
+
* for these public facing constants
|
|
11
|
+
*/
|
|
12
|
+
interface AnalyticsEventName {
|
|
13
|
+
/** Page view */
|
|
14
|
+
PAGE_VIEW: 'PAGE_VIEW';
|
|
15
|
+
/** Add to cart */
|
|
16
|
+
ADD_TO_CART: 'ADD_TO_CART';
|
|
17
|
+
}
|
|
18
|
+
interface AnalyticsPageType {
|
|
19
|
+
article: 'article';
|
|
20
|
+
blog: 'blog';
|
|
21
|
+
captcha: 'captcha';
|
|
22
|
+
cart: 'cart';
|
|
23
|
+
collection: 'collection';
|
|
24
|
+
customersAccount: 'customers/account';
|
|
25
|
+
customersActivateAccount: 'customers/activate_account';
|
|
26
|
+
customersAddresses: 'customers/addresses';
|
|
27
|
+
customersLogin: 'customers/login';
|
|
28
|
+
customersOrder: 'customers/order';
|
|
29
|
+
customersRegister: 'customers/register';
|
|
30
|
+
customersResetPassword: 'customers/reset_password';
|
|
31
|
+
giftCard: 'gift_card';
|
|
32
|
+
home: 'index';
|
|
33
|
+
listCollections: 'list-collections';
|
|
34
|
+
forbidden: '403';
|
|
35
|
+
notFound: '404';
|
|
36
|
+
page: 'page';
|
|
37
|
+
password: 'password';
|
|
38
|
+
product: 'product';
|
|
39
|
+
policy: 'policy';
|
|
40
|
+
search: 'search';
|
|
41
|
+
}
|
|
42
|
+
interface ShopifySalesChannel {
|
|
43
|
+
/** Shopify Hydrogen sales channel */
|
|
44
|
+
hydrogen: 'hydrogen';
|
|
45
|
+
/** Shopify Headless sales channel */
|
|
46
|
+
headless: 'headless';
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ShopifyPageViewPayload, ShopifyAddToCartPayload, ShopifyMonorailEvent } from './analytics-types.js';
|
|
2
|
+
export declare function pageView(payload: ShopifyPageViewPayload): ShopifyMonorailEvent[];
|
|
3
|
+
export declare function addToCart(payload: ShopifyAddToCartPayload): ShopifyMonorailEvent[];
|