mirror of
https://github.com/vercel/commerce.git
synced 2025-05-11 20:27:51 +00:00
use proper env
This commit is contained in:
parent
30087c63c8
commit
27b11abe1e
@ -5,7 +5,7 @@ import { GridTileImage } from './grid/tile';
|
|||||||
export async function Carousel({currency}: {currency: string}) {
|
export async function Carousel({currency}: {currency: string}) {
|
||||||
// Collections that start with `hidden-*` are hidden from the search page.
|
// Collections that start with `hidden-*` are hidden from the search page.
|
||||||
const products = await getCollectionProducts({
|
const products = await getCollectionProducts({
|
||||||
collection: process.env.FW_COLLECTION || '',
|
collection: process.env.NEXT_PUBLIC_FW_COLLECTION || '',
|
||||||
currency,
|
currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ function ThreeItemGridItem({
|
|||||||
|
|
||||||
export async function ThreeItemGrid({currency}: { currency: string}) {
|
export async function ThreeItemGrid({currency}: { currency: string}) {
|
||||||
const homepageItems = await getCollectionProducts({
|
const homepageItems = await getCollectionProducts({
|
||||||
collection: process.env.FW_COLLECTION || '',
|
collection: process.env.NEXT_PUBLIC_FW_COLLECTION || '',
|
||||||
currency,
|
currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ import { Cart, Menu, Product } from "lib/shopify/types";
|
|||||||
import { reshapeCart, reshapeProduct, reshapeProducts } from "./reshape";
|
import { reshapeCart, reshapeProduct, reshapeProducts } from "./reshape";
|
||||||
import { FourthwallCart, FourthwallCheckout, FourthwallProduct } from "./types";
|
import { FourthwallCart, FourthwallCheckout, FourthwallProduct } from "./types";
|
||||||
|
|
||||||
const API_URL = process.env.FW_API_URL
|
const API_URL = process.env.NEXT_PUBLIC_FW_API_URL;
|
||||||
const API_SECRET = process.env.FW_SECRET
|
const FW_PUBLIC_TOKEN = process.env.NEXT_PUBLIC_FW_PUBLIC_TOKEN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers
|
* Helpers
|
||||||
@ -17,6 +17,7 @@ async function fourthwallGet<T>(url: string, options: RequestInit = {}): Promise
|
|||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
'X-FW-Public-Token': FW_PUBLIC_TOKEN || '',
|
||||||
...options.headers
|
...options.headers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,6 +44,7 @@ async function fourthwallPost<T>(url: string, data: any, options: RequestInit =
|
|||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
'X-FW-Public-Token': FW_PUBLIC_TOKEN || '',
|
||||||
...options.headers
|
...options.headers
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
@ -77,7 +79,7 @@ export async function getCollectionProducts({
|
|||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
sortKey?: string;
|
sortKey?: string;
|
||||||
}): Promise<Product[]> {
|
}): Promise<Product[]> {
|
||||||
const res = await fourthwallGet<{results: FourthwallProduct[]}>(`${API_URL}/api/public/v1.0/collections/${collection}/products?secret=${API_SECRET}¤cy=${currency}`, {
|
const res = await fourthwallGet<{results: FourthwallProduct[]}>(`${API_URL}/api/public/v1.0/collections/${collection}/products?¤cy=${currency}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
'X-ShopId': process.env.FW_SHOPID || ''
|
||||||
}
|
}
|
||||||
@ -97,11 +99,7 @@ export async function getCollectionProducts({
|
|||||||
*/
|
*/
|
||||||
export async function getProduct({ handle, currency } : { handle: string, currency: string }): Promise<Product | undefined> {
|
export async function getProduct({ handle, currency } : { handle: string, currency: string }): Promise<Product | undefined> {
|
||||||
// TODO: replace with real URL
|
// TODO: replace with real URL
|
||||||
const res = await fourthwallGet<FourthwallProduct>(`${API_URL}/api/public/v1.0/products/${handle}?secret=${API_SECRET}¤cy=${currency}`, {
|
const res = await fourthwallGet<FourthwallProduct>(`${API_URL}/api/public/v1.0/products/${handle}?¤cy=${currency}`);
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return reshapeProduct(res.body);
|
return reshapeProduct(res.body);
|
||||||
}
|
}
|
||||||
@ -119,7 +117,7 @@ export async function getCart(cartId: string | undefined, currency: string): Pro
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fourthwallGet<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}?secret=${API_SECRET}¤cy=${currency}`, {
|
const res = await fourthwallGet<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}?currency=${currency}`, {
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -127,12 +125,8 @@ export async function getCart(cartId: string | undefined, currency: string): Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createCart(): Promise<Cart> {
|
export async function createCart(): Promise<Cart> {
|
||||||
const res = await fourthwallPost<FourthwallCart>(`https://api.staging.fourthwall.com/api/public/v1.0/carts?secret=${API_SECRET}`, {
|
const res = await fourthwallPost<FourthwallCart>(`https://api.staging.fourthwall.com/api/public/v1.0/carts`, {
|
||||||
items: []
|
items: []
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return reshapeCart(res.body);
|
return reshapeCart(res.body);
|
||||||
@ -148,12 +142,9 @@ export async function addToCart(
|
|||||||
quantity: line.quantity
|
quantity: line.quantity
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/add?secret=${API_SECRET}`, {
|
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/add`, {
|
||||||
items,
|
items,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
},
|
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -165,12 +156,9 @@ export async function removeFromCart(cartId: string, lineIds: string[]): Promise
|
|||||||
variantId: id
|
variantId: id
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/remove?secret=${API_SECRET}`, {
|
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/remove`, {
|
||||||
items,
|
items,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
},
|
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -186,12 +174,9 @@ export async function updateCart(
|
|||||||
quantity: line.quantity
|
quantity: line.quantity
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/change?secret=${API_SECRET}`, {
|
const res = await fourthwallPost<FourthwallCart>(`${API_URL}/api/public/v1.0/carts/${cartId}/change`, {
|
||||||
items,
|
items,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
},
|
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -202,13 +187,9 @@ export async function createCheckout(
|
|||||||
cartId: string,
|
cartId: string,
|
||||||
cartCurrency: string
|
cartCurrency: string
|
||||||
): Promise<FourthwallCheckout> {
|
): Promise<FourthwallCheckout> {
|
||||||
const res = await fourthwallPost<{ id: string }>(`${API_URL}/api/public/v1.0/checkouts?secret=${API_SECRET}`, {
|
const res = await fourthwallPost<{ id: string }>(`${API_URL}/api/public/v1.0/checkouts`, {
|
||||||
cartId,
|
cartId,
|
||||||
cartCurrency
|
cartCurrency
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
'X-ShopId': process.env.FW_SHOPID || ''
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.body;
|
return res.body;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user