Skip to content

Commit

Permalink
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Browse files Browse the repository at this point in the history
  • Loading branch information
decobot committed Oct 11, 2024
2 parents af2a955 + c6659cb commit 76b6520
Show file tree
Hide file tree
Showing 27 changed files with 28,582 additions and 27,587 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<hr/>

<a href="https://deco.cx/discord" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/985687648595243068?label=Discord&color=7289da" /></a>
&nbsp;
<a href="https://x.com/deco_frontend" target="_blank"><img src="https://img.shields.io/twitter/follow/deco_frontend" alt="Deco Twitter" /></a>
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"version": "0.60.2"
"version": "0.62.3"
}
12 changes: 10 additions & 2 deletions shopify/loaders/ProductDetailsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import type { RequestURLParam } from "../../website/functions/requestToParam.ts"
import {
GetProductQuery,
GetProductQueryVariables,
HasMetafieldsMetafieldsArgs,
} from "../utils/storefront/storefront.graphql.gen.ts";
import { GetProduct } from "../utils/storefront/queries.ts";
import { Metafield } from "../utils/types.ts";

export interface Props {
slug: RequestURLParam;
/**
* @title Metafields
* @description search for metafields
*/
metafields?: Metafield[];
}

/**
Expand All @@ -23,6 +30,7 @@ const loader = async (
): Promise<ProductDetailsPage | null> => {
const { storefront } = ctx;
const { slug } = props;
const metafields = props.metafields || [];

const splitted = slug?.split("-");
const maybeSkuId = Number(splitted[splitted.length - 1]);
Expand All @@ -31,9 +39,9 @@ const loader = async (

const data = await storefront.query<
GetProductQuery,
GetProductQueryVariables
GetProductQueryVariables & HasMetafieldsMetafieldsArgs
>({
variables: { handle },
variables: { handle, identifiers: metafields },
...GetProduct,
});

Expand Down
16 changes: 14 additions & 2 deletions shopify/loaders/ProductList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "../utils/storefront/queries.ts";
import {
CollectionProductsArgs,
HasMetafieldsMetafieldsArgs,
Product as ProductShopify,
ProductConnection,
QueryRoot,
Expand All @@ -20,6 +21,7 @@ import {
searchSortShopify,
sortShopify,
} from "../utils/utils.ts";
import { Metafield } from "../utils/types.ts";

export interface QueryProps {
/** @description search term to use on search */
Expand Down Expand Up @@ -63,6 +65,11 @@ export type Props = {
props: QueryProps | CollectionProps;

filters?: FilterProps;
/**
* @title Metafields
* @description search for metafields
*/
metafields?: Metafield[];
};

// deno-lint-ignore no-explicit-any
Expand All @@ -84,6 +91,7 @@ const loader = async (
(expandedProps as unknown as Props["props"]);

const count = props.count ?? 12;
const metafields = expandedProps.metafields || [];

let shopifyProducts:
| SearchResultItemConnection
Expand Down Expand Up @@ -113,12 +121,13 @@ const loader = async (
if (isQueryList(props)) {
const data = await storefront.query<
QueryRoot,
QueryRootSearchArgs
QueryRootSearchArgs & HasMetafieldsMetafieldsArgs
>({
variables: {
first: count,
query: props.query,
productFilters: filters,
identifiers: metafields,
...searchSortShopify[sort],
},
...SearchProducts,
Expand All @@ -127,12 +136,15 @@ const loader = async (
} else {
const data = await storefront.query<
QueryRoot,
QueryRootCollectionArgs & CollectionProductsArgs
& QueryRootCollectionArgs
& CollectionProductsArgs
& HasMetafieldsMetafieldsArgs
>({
variables: {
first: count,
handle: props.collection,
filters,
identifiers: metafields,
...sortShopify[sort],
},
...ProductsByCollection,
Expand Down
16 changes: 14 additions & 2 deletions shopify/loaders/ProductListingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "../utils/storefront/queries.ts";
import {
CollectionProductsArgs,
HasMetafieldsMetafieldsArgs,
Product,
ProductConnection,
QueryRoot,
Expand All @@ -14,6 +15,7 @@ import {
SearchResultItemConnection,
} from "../utils/storefront/storefront.graphql.gen.ts";
import { toFilter, toProduct } from "../utils/transform.ts";
import { Metafield } from "../utils/types.ts";
import {
getFiltersByUrl,
searchSortOptions,
Expand All @@ -37,6 +39,11 @@ export interface Props {
* @description number of products per page to display
*/
count: number;
/**
* @title Metafields
* @description search for metafields
*/
metafields?: Metafield[];
/**
* @hide
* @description it is hidden because only page prop is not sufficient, we need cursors
Expand Down Expand Up @@ -77,6 +84,7 @@ const loader = async (
const endCursor = props.endCursor || url.searchParams.get("endCursor") || "";
const startCursor = props.startCursor ||
url.searchParams.get("startCursor") || "";
const metafields = props.metafields || [];

const isSearch = Boolean(query);
let hasNextPage = false;
Expand All @@ -94,7 +102,7 @@ const loader = async (
if (isSearch) {
const data = await storefront.query<
QueryRoot,
QueryRootSearchArgs
QueryRootSearchArgs & HasMetafieldsMetafieldsArgs
>({
variables: {
...(!endCursor && { first: count }),
Expand All @@ -103,6 +111,7 @@ const loader = async (
...(endCursor && { before: endCursor }),
query: query,
productFilters: getFiltersByUrl(url),
identifiers: metafields,
...searchSortShopify[sort],
},
...SearchProducts,
Expand All @@ -122,13 +131,16 @@ const loader = async (

const data = await storefront.query<
QueryRoot,
QueryRootCollectionArgs & CollectionProductsArgs
& QueryRootCollectionArgs
& CollectionProductsArgs
& HasMetafieldsMetafieldsArgs
>({
variables: {
...(!endCursor && { first: count }),
...(endCursor && { last: count }),
...(startCursor && { after: startCursor }),
...(endCursor && { before: endCursor }),
identifiers: metafields,
handle: pathname,
filters: getFiltersByUrl(url),
...sortShopify[sort],
Expand Down
19 changes: 15 additions & 4 deletions shopify/loaders/RelatedProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
import {
GetProductQuery,
GetProductQueryVariables,
HasMetafieldsMetafieldsArgs,
ProductRecommendationsQuery,
ProductRecommendationsQueryVariables,
} from "../utils/storefront/storefront.graphql.gen.ts";
import { toProduct } from "../utils/transform.ts";
import { Metafield } from "../utils/types.ts";

export interface Props {
slug: RequestURLParam;
Expand All @@ -20,6 +22,11 @@ export interface Props {
* @default 10
*/
count: number;
/**
* @title Metafields
* @description search for metafields
*/
metafields?: Metafield[];
}

/**
Expand All @@ -37,12 +44,13 @@ const loader = async (
const splitted = slug?.split("-");
const maybeSkuId = Number(splitted[splitted.length - 1]);
const handle = splitted.slice(0, maybeSkuId ? -1 : undefined).join("-");
const metafields = props.metafields || [];

const query = await storefront.query<
GetProductQuery,
GetProductQueryVariables
GetProductQueryVariables & HasMetafieldsMetafieldsArgs
>({
variables: { handle },
variables: { handle, identifiers: metafields },
...GetProduct,
});

Expand All @@ -52,9 +60,12 @@ const loader = async (

const data = await storefront.query<
ProductRecommendationsQuery,
ProductRecommendationsQueryVariables
ProductRecommendationsQueryVariables & HasMetafieldsMetafieldsArgs
>({
variables: { productId: query.product.id },
variables: {
productId: query.product.id,
identifiers: metafields,
},
...ProductRecommendations,
});

Expand Down
10 changes: 6 additions & 4 deletions shopify/loaders/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const decoSiteMapUrl = "/sitemap/deco.xml";
const buildProxyRoutes = (
{
ctx,
ctx: { storeName },
ctx: { storeName, publicUrl },
extraPaths,
includeSiteMap,
generateDecoSiteMap,
Expand All @@ -40,11 +40,13 @@ const buildProxyRoutes = (
ctx: AppContext;
},
) => {
const publicUrl = new URL(`https://${storeName}.myshopify.com`);
const urlToUse = publicUrl ?
new URL(publicUrl.startsWith("http") ? publicUrl : `https://${publicUrl}`) :
new URL(`https://${storeName}.myshopify.com`);

try {
const hostname = publicUrl.hostname;
const hostname = urlToUse.hostname;

try {
// Rejects TLD mystore.com, keep this if Shopify doesn't support
if (!hostname || hostname.split(".").length <= 2) {
throw new Error(`Invalid hostname from '${publicUrl}'`);
Expand Down
5 changes: 5 additions & 0 deletions shopify/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface Props {
* @description Shopify store name.
*/
storeName: string;
/**
* @title Public store URL
* @description Domain that is registered on License Manager (e.g: www.mystore.com.br)
*/
publicUrl?: string;
/**
* @title Access Token
* @description Shopify storefront access token.
Expand Down
42 changes: 36 additions & 6 deletions shopify/utils/storefront/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ fragment Product on Product {
...Collection
}
}
metafields(identifiers: $identifiers) {
description
key
namespace
type
value
reference {
... on MediaImage {
image {
url
}
}
}
references(first: 250) {
edges {
node {
... on MediaImage {
image {
url
}
}
}
}
}
}
}
`;

Expand Down Expand Up @@ -234,14 +259,16 @@ export const GetCart = {

export const GetProduct = {
fragments: [Product, ProductVariant, Collection],
query: gql`query GetProduct($handle: String) {
query:
gql`query GetProduct($handle: String, $identifiers: [HasMetafieldsIdentifier!]!) {
product(handle: $handle) { ...Product }
}`,
};

export const ListProducts = {
fragments: [Product, ProductVariant, Collection],
query: gql`query ListProducts($first: Int, $after: String, $query: String) {
query:
gql`query ListProducts($first: Int, $after: String, $query: String, $identifiers: [HasMetafieldsIdentifier!]!) {
products(first: $first, after: $after, query: $query) {
nodes {
...Product
Expand All @@ -260,7 +287,8 @@ export const SearchProducts = {
$query: String!,
$productFilters: [ProductFilter!]
$sortKey: SearchSortKeys,
$reverse: Boolean
$reverse: Boolean,
$identifiers: [HasMetafieldsIdentifier!]!
){
search(
first: $first,
Expand All @@ -284,7 +312,7 @@ export const SearchProducts = {
...Filter
}
nodes {
...Product
...Product
}
}
}`,
Expand All @@ -300,7 +328,8 @@ export const ProductsByCollection = {
$handle: String,
$sortKey: ProductCollectionSortKeys,
$reverse: Boolean,
$filters: [ProductFilter!]
$filters: [ProductFilter!],
$identifiers: [HasMetafieldsIdentifier!]!
){
collection(handle: $handle) {
handle
Expand Down Expand Up @@ -332,7 +361,8 @@ export const ProductsByCollection = {

export const ProductRecommendations = {
fragments: [Product, ProductVariant, Collection],
query: gql`query productRecommendations($productId: ID!) {
query:
gql`query productRecommendations($productId: ID!, $identifiers: [HasMetafieldsIdentifier!]!) {
productRecommendations(productId: $productId) {
...Product
}
Expand Down
Loading

0 comments on commit 76b6520

Please sign in to comment.