-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compat with vtex functions (#51)
Signed-off-by: Marcos Candeia <marrcooos@gmail.com>
- Loading branch information
Showing
14 changed files
with
365 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.