@shopify/hydrogen-react
Version:
React components, hooks, and utilities for creating custom Shopify storefronts
58 lines (57 loc) • 3.14 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const storefrontApiConstants = require("./storefront-api-constants.js");
function createStorefrontClient({
storeDomain,
privateStorefrontToken,
publicStorefrontToken,
storefrontApiVersion,
contentType
}) {
if (storefrontApiVersion !== storefrontApiConstants.SFAPI_VERSION) {
console.warn(
`StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen-UI is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${storefrontApiConstants.SFAPI_VERSION}"`
);
}
return {
getStorefrontApiUrl(overrideProps) {
var _a, _b;
return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : storefrontApiVersion}/graphql.json`;
},
getPrivateTokenHeaders(overrideProps) {
var _a, _b, _c;
if (!privateStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.privateStorefrontToken)) {
throw new Error(
`StorefrontClient: You did not pass in a 'privateStorefrontToken' while using 'getPrivateTokenHeaders()'`
);
}
const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
return {
"content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
"X-SDK-Variant": "hydrogen-ui",
"X-SDK-Variant-Source": "react",
"X-SDK-Version": storefrontApiVersion,
"Shopify-Storefront-Private-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) != null ? _b : privateStorefrontToken) != null ? _c : "",
...(overrideProps == null ? void 0 : overrideProps.buyerIp) ? { "Shopify-Storefront-Buyer-IP": overrideProps.buyerIp } : {}
};
},
getPublicTokenHeaders(overrideProps) {
var _a, _b, _c;
if (!publicStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.publicStorefrontToken)) {
throw new Error(
`StorefrontClient: You did not pass in a 'publicStorefrontToken' while using 'getPublicTokenHeaders()'`
);
}
const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
return {
"content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
"X-SDK-Variant": "hydrogen-ui",
"X-SDK-Variant-Source": "react",
"X-SDK-Version": storefrontApiVersion,
"X-Shopify-Storefront-Access-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) != null ? _b : publicStorefrontToken) != null ? _c : ""
};
}
};
}
exports.createStorefrontClient = createStorefrontClient;
//# sourceMappingURL=storefront-client.js.map