import { fetch } from "https://esm.town/v/std/fetch";
export async function ShopifyProductSearch(brokerId, first = 20) {
const url = "https://shop.app/web/api/graphql";
const query = `
query ShopProductSearch($brokerId: ID!, $first: Int!, $after: String, $filter: [SearchFilterV2!], $sortBy: ShopProductSearchSortByV2, $query: String) {
shopProductSearch(
brokerId: $brokerId
first: $first
after: $after
filter: $filter
sortBy: $sortBy
query: $query
) {
...ProductSearch
__typename
}
}
fragment ProductSearch on ProductSearchConnection {
nodes {
__typename
id
... on DiscoveryProduct {
id
...ShopWebRelatedProductFragment
__typename
}
}
productFilters {
...ProductFilter
__typename
}
pageInfo {
hasNextPage
endCursor
__typename
}
filter {
network
__typename
}
inferredCategoryFilters
totalCount
totalCountCapped
inferredQueryType
__typename
}
fragment ShopWebRelatedProductFragment on DiscoveryProduct {
id
price {
...MoneyV2Fragment
__typename
}
originalPrice {
...MoneyV2Fragment
__typename
}
title
url
images {
url
altText
sensitive
width
height
__typename
}
offers {
id
... on DiscountOffer {
...DiscountOffer
__typename
}
__typename
}
shopCashOffer {
id
offerHandle
boostMultiplier
totalCashDestinationAmount {
amount
currencyCode
__typename
}
__typename
}
defaultVariantId
inDefaultProductList
shop {
id
websiteUrl
name
defaultHandle
inAppVisibilityStatus
visualTheme {