11import type { ServerToolConfig } from "@/toolkits/types" ;
22import type { getListings } from "./base" ;
33import { api } from "@/trpc/server" ;
4- import { refreshEtsyAccessToken } from "@/server/auth/custom-providers/etsy" ;
4+ import { refreshEtsyAccessToken } from "@/server/auth/custom-providers/etsy" ;
55
6-
7- export const getListingsServerConfig = (
8-
9- ) : ServerToolConfig <
6+ export const getListingsServerConfig = ( ) : ServerToolConfig <
107 typeof getListings . inputSchema . shape ,
118 typeof getListings . outputSchema . shape
129> => {
@@ -21,36 +18,40 @@ export const getListingsServerConfig = (
2118 const accessExpiry = account ?. expires_at ;
2219
2320 if ( ! apiKey ) throw new Error ( "Missing AUTH_ETSY_ID" ) ;
24- if ( accessExpiry && refreshToken && userID && ( accessExpiry < Date . now ( ) / 1000 ) ) {
21+ if (
22+ accessExpiry &&
23+ refreshToken &&
24+ userID &&
25+ accessExpiry < Date . now ( ) / 1000
26+ ) {
2527 await refreshEtsyAccessToken ( refreshToken , userID ) ;
2628 }
2729
2830 const accessToken = account ?. access_token ;
2931 if ( ! accessToken ) throw new Error ( "Missing Etsy access token" ) ;
3032
31-
3233 const shopResponse = await fetch (
3334 `https://openapi.etsy.com/v3/application/users/${ etsyUserId } /shops` ,
3435 {
3536 headers : {
3637 "x-api-key" : apiKey ,
3738 Authorization : `Bearer ${ accessToken } ` ,
38- }
39+ } ,
3940 } ,
4041 ) ;
4142
42- const shop = ( await shopResponse . json ( ) ) ;
43+ const shop = await shopResponse . json ( ) ;
4344
4445 const listingResponse = await fetch (
4546 `https://openapi.etsy.com/v3/application/shops/${ shop . shop_id } /listings` ,
4647 {
4748 headers : {
4849 "x-api-key" : apiKey ,
4950 Authorization : `Bearer ${ accessToken } ` ,
50- }
51+ } ,
5152 } ,
5253 ) ;
53- const listings = ( await listingResponse . json ( ) ) ;
54+ const listings = await listingResponse . json ( ) ;
5455
5556 // this is going to be very inefficient code for large shops, but let's do this for now. I can raise QPS ratelimits if needed
5657 // for each listing, fetch the images
@@ -62,14 +63,13 @@ export const getListingsServerConfig = (
6263 headers : {
6364 "x-api-key" : apiKey ,
6465 Authorization : `Bearer ${ accessToken } ` ,
65- }
66+ } ,
6667 } ,
6768 ) ;
68- const images = ( await imageResponse . json ( ) ) ;
69+ const images = await imageResponse . json ( ) ;
6970 listing . images = images . results ;
7071 }
7172
72-
7373 return {
7474 listings : listings ,
7575 } ;
@@ -82,4 +82,4 @@ export const getListingsServerConfig = (
8282 "Successfully retrieved the Etsy listing. The user is shown the responses in the UI. Do not reiterate them. " +
8383 "If you called this tool because the user asked a question, answer the question." ,
8484 } ;
85- } ;
85+ } ;
0 commit comments