@@ -4,14 +4,14 @@ import { config } from './config';
44const MoltinGateway = moltin . gateway ;
55
66export async function loadEnabledCurrencies ( ) : Promise < moltin . Currency [ ] > {
7- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
7+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
88 const response = await moltin . Currencies . All ( ) ;
99
1010 return response . data . filter ( c => c . enabled ) ;
1111}
1212
1313export async function loadCategoryTree ( ) : Promise < moltin . Category [ ] > {
14- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
14+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
1515 const result = await moltin . Categories . Tree ( ) ;
1616
1717 return result . data ;
@@ -28,7 +28,7 @@ function getProductCache(key: string, language: string, currency: string): molti
2828}
2929
3030export async function loadCategoryProducts ( categoryId : string , pageNum : number , language : string , currency : string ) : Promise < moltin . ResourcePage < moltin . Product > > {
31- const moltin = MoltinGateway ( { client_id : config . clientId , currency : currency } ) ;
31+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId , currency : currency } ) ;
3232
3333 const result = await moltin . Products
3434 . Offset ( ( pageNum - 1 ) * config . categoryPageSize )
@@ -67,7 +67,7 @@ export async function loadImageHref(imageId: string): Promise<string | undefined
6767 return imageHrefCache [ imageId ] ;
6868 }
6969
70- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
70+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
7171 const result = await moltin . Files . Get ( imageId ) ;
7272
7373 if ( imageMimeTypes . indexOf ( result . data . mime_type ) === - 1 ) {
@@ -86,7 +86,7 @@ export async function loadProductBySlug(productSlug: string, language: string, c
8686 return cachedProduct ;
8787 }
8888
89- const moltin = MoltinGateway ( { client_id : config . clientId , currency : currency } ) ;
89+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId , currency : currency } ) ;
9090
9191 const resultSlug = await moltin . Products
9292 . Limit ( 1 )
@@ -107,7 +107,7 @@ export async function loadProductBySlug(productSlug: string, language: string, c
107107}
108108
109109export async function register ( name : string , email : string , password : string ) : Promise < moltin . CustomerBase > {
110- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
110+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
111111 const { data } = await moltin . Customers . Create ( {
112112 type : 'customer' ,
113113 name,
@@ -119,53 +119,53 @@ export async function register(name: string, email: string, password: string): P
119119}
120120
121121export async function login ( email : string , password : string ) : Promise < moltin . CustomerToken > {
122- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
122+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
123123 const { data } = await moltin . Customers . Token ( email , password ) ;
124124
125125 return data ;
126126}
127127
128128export async function getCustomer ( id : string , token : string ) : Promise < moltin . CustomerBase > {
129- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
129+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
130130 const { data } = await moltin . Customers . Get ( id , token ) ;
131131
132132 return data ;
133133}
134134
135135export async function updateCustomer ( id : string , name : string , email : string , token : string ) : Promise < { data : moltin . Customer } > {
136- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
136+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
137137 // @ts -ignore
138138 const result = await moltin . Customers . Update ( id , { type : 'customer' , name, email, password : '' , } , token ) ;
139139
140140 return result ;
141141}
142142
143143export async function getAddresses ( customer : string , token : string ) : Promise < { data : moltin . Address [ ] } > {
144- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
144+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
145145 const result = await moltin . Addresses . All ( { customer, token } ) ;
146146
147147 return result ;
148148}
149149
150150export async function updateAddress ( customer : string , address : string , body : any , token : string ) : Promise < void > {
151- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
151+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
152152 await moltin . Addresses . Update ( { customer, address, body, token } ) ;
153153}
154154
155155export async function addNewAddress ( customer : string , body : any , token : string ) : Promise < { data : moltin . Address } > {
156- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
156+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
157157 const result = await moltin . Addresses . Create ( { customer, body, token } ) ;
158158
159159 return result ;
160160}
161161
162162export async function deleteAddress ( customer : string , address : any , token : string ) : Promise < void > {
163- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
163+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
164164 await moltin . Addresses . Delete ( { customer, address, token } ) ;
165165}
166166
167167export async function getAllOrders ( token : string ) : Promise < { data : moltin . Order [ ] } > {
168- const moltin = MoltinGateway ( { client_id : config . clientId } ) ;
168+ const moltin = MoltinGateway ( { host : config . endpointURL , client_id : config . clientId } ) ;
169169 const result = await moltin . Orders . Limit ( 100 ) . All ( token ) ;
170170 return result ;
171171}
0 commit comments