Skip to content

Commit

Permalink
Add compat with vtex functions (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <marrcooos@gmail.com>
  • Loading branch information
mcandeia authored Sep 14, 2023
1 parent ce3b2de commit baea2de
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 20 deletions.
10 changes: 5 additions & 5 deletions compat/std/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type { ConfigShopify as ShopifyAccount } from "https://denopkg.com/deco-sites/std@1.22.0/commerce/shopify/client.ts";
export type { Manifest as StdManifest } from "https://denopkg.com/deco-sites/std@1.22.0/live.gen.ts";
export type { Account as VNDAAccount } from "https://denopkg.com/deco-sites/std@1.22.0/packs/vnda/accounts/vnda.ts";
export type { Account as VTEXAccount } from "https://denopkg.com/deco-sites/std@1.22.0/packs/vtex/accounts/vtex.ts";
export { default as VTEXCompat } from "https://denopkg.com/deco-sites/std@1.22.0/sections/VTEXPortalDataLayerCompatibility.tsx";
export type { ConfigShopify as ShopifyAccount } from "https://denopkg.com/deco-sites/std@1.22.9/commerce/shopify/client.ts";
export type { Manifest as StdManifest } from "https://denopkg.com/deco-sites/std@1.22.9/live.gen.ts";
export type { Account as VNDAAccount } from "https://denopkg.com/deco-sites/std@1.22.9/packs/vnda/accounts/vnda.ts";
export type { Account as VTEXAccount } from "https://denopkg.com/deco-sites/std@1.22.9/packs/vtex/accounts/vtex.ts";
export { default as VTEXCompat } from "https://denopkg.com/deco-sites/std@1.22.9/sections/VTEXPortalDataLayerCompatibility.tsx";
26 changes: 26 additions & 0 deletions compat/std/functions/vtexLegacyProductDetailsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LoaderFunction } from "deco/types.ts";
import type { ProductDetailsPage } from "../../../commerce/types.ts";
import type { AppContext } from "../mod.ts";

/**
* @title VTEX Catalog - Product Details Page (deprecated)
* @description Works on routes of type /:slug/p
* @deprecated true
*/
const loaderV0: LoaderFunction<
null,
ProductDetailsPage | null,
AppContext
> = async (
_req,
ctx,
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.legacy
.productDetailsPage(
{ slug: ctx.params.slug },
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
41 changes: 41 additions & 0 deletions compat/std/functions/vtexLegacyProductList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { LoaderFunction } from "deco/types.ts";
import type { Product } from "../../../commerce/types.ts";
import type { AppContext } from "../mod.ts";

export interface Props {
/** @description total number of items to display */
count: number;
/** @description query to use on search */
query?: string;
/**
* @description Collection ID or (Product Cluster id). For more info: https://developers.vtex.com/docs/api-reference/search-api#get-/api/catalog_system/pub/products/search .
* @pattern \d*
*/
collection?: string[];
}

/**
* @title VTEX Legacy - Search Products (deprecated)
* @description Useful for shelves and static galleries.
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
Product[] | null,
AppContext
> = async (
_req,
ctx,
props,
) => {
const p = props.query
? { term: props.query, count: props.count }
: { collection: props.collection?.[0], count: props.count };

const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.legacy
.productList(p);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
31 changes: 31 additions & 0 deletions compat/std/functions/vtexLegacyProductListingPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { LoaderFunction } from "deco/types.ts";
import type { ProductListingPage } from "../../../commerce/types.ts";
import type { Props } from "../../../vtex/loaders/legacy/productListingPage.ts";
import type { AppContext } from "../mod.ts";

/**
* @title VTEX Catalog - Product Listing Page (deprecated)
* @description Useful for category, search, brand and collection pages.
* @deprecated
*/
const loaderV0: LoaderFunction<
Props,
ProductListingPage | null,
AppContext
> = async (
_req,
ctx,
props,
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.legacy
.productListingPage(
{
...props,
term: props.term || ctx.params["0"],
},
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
44 changes: 44 additions & 0 deletions compat/std/functions/vtexLegacyRelatedProductsLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { LoaderFunction } from "deco/types.ts";
import type { Product } from "../../../commerce/types.ts";
import type { CrossSellingType } from "../../../vtex/utils/types.ts";
import type { AppContext } from "../mod.ts";

export interface Props {
/**
* @title Related Products
* @description VTEX Cross Selling API. This loader only works on routes of type /:slug/p
*/
crossSelling: CrossSellingType;
/**
* @description: number of related products
*/
count?: number;
}

/**
* @title VTEX Catalog - Related Products (deprecated)
* @description Works on routes of type /:slug/p
* @deprecated
*/
const loaderV0: LoaderFunction<
Props,
Product[] | null,
AppContext
> = async (
_req,
ctx,
{ crossSelling, count },
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.legacy
.relatedProductsLoader(
{
slug: ctx.params.slug,
crossSelling,
count,
},
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
22 changes: 22 additions & 0 deletions compat/std/functions/vtexNavbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { LoaderFunction } from "deco/types.ts";
import type { Navbar } from "../../../commerce/types.ts";
import type { AppContext } from "../mod.ts";
import type { Props } from "../../../vtex/loaders/navbar.ts";

/**
* @title Navigation Bar
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
Navbar[] | null,
AppContext
> = async (_req, ctx, props) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.navbar(
props,
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
26 changes: 26 additions & 0 deletions compat/std/functions/vtexProductDetailsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LoaderFunction } from "deco/types.ts";
import type { ProductDetailsPage } from "../../../commerce/types.ts";
import type { AppContext } from "../mod.ts";

/**
* @title VTEX Intelligent Search - Product Details Page (deprecated)
* @description For routes of type /:slug/p
* @deprecated true
*/
const loaderV0: LoaderFunction<
null,
ProductDetailsPage | null,
AppContext
> = async (
_req,
ctx,
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex
.intelligentSearch.productDetailsPage(
{ slug: ctx.params.slug },
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
58 changes: 58 additions & 0 deletions compat/std/functions/vtexProductList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { LoaderFunction } from "deco/types.ts";
import type { Product } from "../../../commerce/types.ts";
import type { AppContext } from "../mod.ts";

export interface Props {
/** @description query to use on search */
query: string;
/** @description total number of items to display */
count: number;
//* @enumNames ["relevance", "greater discount", "arrivals", "name asc", "name desc", "most ordered", "price asc", "price desc"]
/**
* @description search sort parameter
*/
sort?:
| ""
| "price:desc"
| "price:asc"
| "orders:desc"
| "name:desc"
| "name:asc"
| "release:desc"
| "discount:desc";

// TODO: pattern property isn't being handled by RJSF
/**
* @title Collection ID
* @pattern \d*
*/
collection?: string[];
}

/**
* @title VTEX Intelligent Search - Search Products (deprecated)
* @description Use it in Shelves and static Galleries.
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
Product[] | null,
AppContext
> = async (
_req,
ctx,
props,
) => {
const { query, collection, count, sort } = props;
const p = query ? { query } : { collection: collection?.[0] };

const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex
.intelligentSearch.productList(
// deno-lint-ignore no-explicit-any
{ ...p, count, sort } as any,
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
30 changes: 30 additions & 0 deletions compat/std/functions/vtexProductListingPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { LoaderFunction } from "deco/types.ts";
import type { ProductListingPage } from "../../../commerce/types.ts";
import type {
Props,
} from "../../../vtex/loaders/intelligentSearch/productListingPage.ts";
import type { AppContext } from "../mod.ts";


/**
* @title VTEX Intelligent Search - Product Listing page (deprecated)
* @description Useful for category, search, brand and collection pages.
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
ProductListingPage | null,
AppContext
> = async (
_req,
ctx,
props,
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.intelligentSearch.productListingPage(
props,
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
22 changes: 22 additions & 0 deletions compat/std/functions/vtexSuggestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { LoaderFunction } from "deco/types.ts";
import type { Suggestion } from "../../../commerce/types.ts";
import type { Props } from "../../../vtex/loaders/intelligentSearch/suggestions.ts";
import type { AppContext } from "../mod.ts";

/**
* @title VTEX Intelligent Search - Search Suggestions (deprecated)
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
Suggestion | null,
AppContext
> = async (_req, ctx, props) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.intelligentSearch.suggestions(
props,
);

return { data, status: data ? 200 : 404 };
};

export default loaderV0;
35 changes: 35 additions & 0 deletions compat/std/functions/vtexWishlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { LoaderFunction } from "deco/types.ts";
import type { ProductListingPage } from "../../../commerce/types.ts";
import type { Props } from "../../../vtex/loaders/wishlist.ts";
import type { AppContext } from "../mod.ts";

/**
* @title VTEX - Load Wishlist
* @description Used with vtex.wish-list app
* @deprecated true
*/
const loaderV0: LoaderFunction<
Props,
ProductListingPage | null,
AppContext
> = async (
_req,
ctx,
props,
) => {
const data = await ctx.state.invoke["deco-sites/std"].loaders.vtex.wishlist(
props,
);

return {
data: await ctx.state.invoke["deco-sites/std"].loaders.vtex
.intelligentSearch.productListingPage(
{
query: `product:${data.map((p) => p.productId).join(";")}`,
count: props.count,
},
),
};
};

export default loaderV0;
24 changes: 22 additions & 2 deletions compat/std/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import * as $0 from "./functions/requestToParam.ts";
import * as $0 from "./functions/vtexProductListingPage.ts";
import * as $1 from "./functions/vtexLegacyProductDetailsPage.ts";
import * as $2 from "./functions/vtexSuggestions.ts";
import * as $3 from "./functions/vtexNavbar.ts";
import * as $4 from "./functions/vtexWishlist.ts";
import * as $5 from "./functions/vtexProductList.ts";
import * as $6 from "./functions/vtexLegacyProductListingPage.ts";
import * as $7 from "./functions/vtexProductDetailsPage.ts";
import * as $8 from "./functions/vtexLegacyProductList.ts";
import * as $9 from "./functions/vtexLegacyRelatedProductsLoader.ts";
import * as $10 from "./functions/requestToParam.ts";
import * as $$$0 from "./loaders/x/redirects.ts";
import * as $$$1 from "./loaders/x/font.ts";
import * as $$$$$$0 from "./sections/SEOPLP.tsx";
Expand All @@ -12,7 +22,17 @@ import * as $$$$$$3 from "./sections/SEOPDP.tsx";

const manifest = {
"functions": {
"deco-sites/std/functions/requestToParam.ts": $0,
"deco-sites/std/functions/requestToParam.ts": $10,
"deco-sites/std/functions/vtexLegacyProductDetailsPage.ts": $1,
"deco-sites/std/functions/vtexLegacyProductList.ts": $8,
"deco-sites/std/functions/vtexLegacyProductListingPage.ts": $6,
"deco-sites/std/functions/vtexLegacyRelatedProductsLoader.ts": $9,
"deco-sites/std/functions/vtexNavbar.ts": $3,
"deco-sites/std/functions/vtexProductDetailsPage.ts": $7,
"deco-sites/std/functions/vtexProductList.ts": $5,
"deco-sites/std/functions/vtexProductListingPage.ts": $0,
"deco-sites/std/functions/vtexSuggestions.ts": $2,
"deco-sites/std/functions/vtexWishlist.ts": $4,
},
"loaders": {
"deco-sites/std/loaders/x/font.ts": $$$1,
Expand Down
Loading

0 comments on commit baea2de

Please sign in to comment.