4
0
forked from crowetic/commerce
Files
.vscode
assets
components
config
framework
bigcommerce
api
cart
catalog
customers
definitions
fragments
utils
concat-cookie.ts
create-api-handler.ts
errors.ts
fetch-graphql-api.ts
fetch-store-api.ts
fetch.ts
filter-edges.ts
get-cart-cookie.ts
is-allowed-method.ts
parse-item.ts
set-product-locale-meta.ts
types.ts
wishlist
checkout.ts
index.ts
auth
cart
common
customer
lib
product
scripts
wishlist
.env.template
README.md
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
commerce
shopify
swell
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
commerce/framework/bigcommerce/api/utils/set-product-locale-meta.ts
2021-01-17 12:53:34 -03:00

22 lines
555 B
TypeScript

import type { ProductNode } from '../../product/get-all-products'
import type { RecursivePartial } from './types'
export default function setProductLocaleMeta(
node: RecursivePartial<ProductNode>
) {
if (node.localeMeta?.edges) {
node.localeMeta.edges = node.localeMeta.edges.filter((edge) => {
const { key, value } = edge?.node ?? {}
if (key && key in node) {
;(node as any)[key] = value
return false
}
return true
})
if (!node.localeMeta.edges.length) {
delete node.localeMeta
}
}
}