@@ -7,10 +7,25 @@ export type ProductHydrater = (
77 extraQuery ?: any ,
88 perProduct ?: ( item : string , index : number ) => any ,
99 perVariant ?: ( item : string , index : number ) => any ,
10- usePIMApi ?: boolean ,
1110) => Promise < any > ;
1211
13- function byPaths ( client : ClientInterface ) : ProductHydrater {
12+ export type ProductHydraterOptions = {
13+ useSyncApiForSKUs ?: boolean ;
14+ marketIdentifiers ?: string [ ] ;
15+ priceList ?: string ;
16+ priceForEveryone ?: boolean ;
17+ } ;
18+
19+ const priceListBlock = {
20+ startDate : true ,
21+ endDate : true ,
22+ price : true ,
23+ identifier : true ,
24+ modifier : true ,
25+ modifierType : true ,
26+ } ;
27+
28+ function byPaths ( client : ClientInterface , options ?: ProductHydraterOptions ) : ProductHydrater {
1429 return < T > (
1530 paths : string [ ] ,
1631 language : string ,
@@ -42,6 +57,25 @@ function byPaths(client: ClientInterface): ProductHydrater {
4257 price : true ,
4358 identifier : true ,
4459 currency : true ,
60+ ...( options ?. priceForEveryone === true
61+ ? {
62+ priceForEveryone : priceListBlock ,
63+ }
64+ : { } ) ,
65+ ...( options ?. priceList
66+ ? {
67+ priceList : {
68+ __args : { identifier : options . priceList } ,
69+ } ,
70+ }
71+ : { } ) ,
72+ ...( options ?. marketIdentifiers
73+ ? {
74+ priceFor : {
75+ __args : { marketIdentifiers : options . marketIdentifiers } ,
76+ } ,
77+ }
78+ : { } ) ,
4579 } ,
4680 ...( perVariant !== undefined ? perVariant ( path , index ) : { } ) ,
4781 } ,
@@ -61,7 +95,7 @@ function byPaths(client: ClientInterface): ProductHydrater {
6195 } ;
6296}
6397
64- function bySkus ( client : ClientInterface , options ?: { useSyncApiForSKUs ?: boolean } ) : ProductHydrater {
98+ function bySkus ( client : ClientInterface , options ?: ProductHydraterOptions ) : ProductHydrater {
6599 async function getPathForSkus ( skus : string [ ] , language : string ) : Promise < string [ ] > {
66100 const pathsSet = new Set < string > ( ) ;
67101
@@ -159,18 +193,13 @@ function bySkus(client: ClientInterface, options?: { useSyncApiForSKUs?: boolean
159193
160194 return empty as any ;
161195 }
162- return byPaths ( client ) ( paths , language , extraQuery , perProduct , perVariant ) ;
196+ return byPaths ( client , options ) ( paths , language , extraQuery , perProduct , perVariant ) ;
163197 } ;
164198}
165199
166- export function createProductHydrater (
167- client : ClientInterface ,
168- options ?: {
169- useSyncApiForSKUs ?: boolean ;
170- } ,
171- ) {
200+ export function createProductHydrater ( client : ClientInterface , options ?: ProductHydraterOptions ) {
172201 return {
173- byPaths : byPaths ( client ) ,
202+ byPaths : byPaths ( client , options ) ,
174203 bySkus : bySkus ( client , options ) ,
175204 } ;
176205}
0 commit comments