Skip to content

Commit a440db4

Browse files
Fix Shopify configuration to use @generated/docusaurus.config
1 parent 1d8ddc3 commit a440db4

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/lib/shopify.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88
* 1. Create a Shopify store at https://shopify.com
99
* 2. Go to Settings > Apps and sales channels > Develop apps
1010
* 3. Create a new app and get your Storefront API access token
11-
* 4. Add your credentials to docusaurus.config.ts customFields
12-
*
13-
* For development, add these to your docusaurus.config.ts:
14-
* customFields: {
15-
* SHOPIFY_STORE_DOMAIN: 'your-store.myshopify.com',
16-
* SHOPIFY_STOREFRONT_ACCESS_TOKEN: 'your-token-here',
17-
* }
11+
* 4. Credentials are configured in docusaurus.config.ts customFields
1812
*/
1913

20-
// Get credentials from Docusaurus customFields (configured in docusaurus.config.ts)
21-
// These are set at build time and won't expose credentials in the code
22-
const SHOPIFY_STORE_DOMAIN =
23-
(typeof window !== 'undefined' && (window as any).docusaurus?.siteConfig?.customFields?.SHOPIFY_STORE_DOMAIN as string) || '';
24-
const SHOPIFY_STOREFRONT_ACCESS_TOKEN =
25-
(typeof window !== 'undefined' && (window as any).docusaurus?.siteConfig?.customFields?.SHOPIFY_STOREFRONT_ACCESS_TOKEN as string) || '';
14+
import siteConfig from '@generated/docusaurus.config';
2615

27-
const SHOPIFY_GRAPHQL_URL = `https://${SHOPIFY_STORE_DOMAIN}/api/2024-01/graphql.json`;
16+
// Get credentials from Docusaurus customFields
17+
function getShopifyConfig() {
18+
const domain = (siteConfig.customFields?.SHOPIFY_STORE_DOMAIN as string) || '';
19+
const token = (siteConfig.customFields?.SHOPIFY_STOREFRONT_ACCESS_TOKEN as string) || '';
20+
21+
return { domain, token };
22+
}
23+
24+
const SHOPIFY_GRAPHQL_URL = (domain: string) => `https://${domain}/api/2024-01/graphql.json`;
2825

2926
interface ShopifyProduct {
3027
id: string;
@@ -97,16 +94,18 @@ interface ShopifyCheckout {
9794
* Make a request to Shopify's Storefront API
9895
*/
9996
async function shopifyFetch<T>(query: string, variables = {}): Promise<T> {
100-
if (!SHOPIFY_STORE_DOMAIN || !SHOPIFY_STOREFRONT_ACCESS_TOKEN) {
97+
const config = getShopifyConfig();
98+
99+
if (!config.domain || !config.token) {
101100
console.warn('Shopify credentials not configured. Using mock data.');
102101
throw new Error('Shopify not configured');
103102
}
104103

105-
const response = await fetch(SHOPIFY_GRAPHQL_URL, {
104+
const response = await fetch(SHOPIFY_GRAPHQL_URL(config.domain), {
106105
method: 'POST',
107106
headers: {
108107
'Content-Type': 'application/json',
109-
'X-Shopify-Storefront-Access-Token': SHOPIFY_STOREFRONT_ACCESS_TOKEN,
108+
'X-Shopify-Storefront-Access-Token': config.token,
110109
},
111110
body: JSON.stringify({ query, variables }),
112111
});
@@ -473,7 +472,8 @@ export async function removeFromCheckout(
473472
* Check if Shopify is configured
474473
*/
475474
export function isShopifyConfigured(): boolean {
476-
return Boolean(SHOPIFY_STORE_DOMAIN && SHOPIFY_STOREFRONT_ACCESS_TOKEN);
475+
const config = getShopifyConfig();
476+
return Boolean(config.domain && config.token);
477477
}
478478

479479
export type { ShopifyProduct, ShopifyCheckout };

0 commit comments

Comments
 (0)