Skip to content

Commit 8d26db1

Browse files
committed
everything working
1 parent 8a51b5c commit 8d26db1

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/toolkits/toolkits/Etsy/server.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ export const etsyToolkitServer = createServerToolkit(
1919
throw new Error("No Etsy access token found");
2020
}
2121

22-
const etsy = new Etsy({
23-
apiKey: env.AUTH_ETSY_ID,
24-
// TODO:: workaround for ISecurityDataStorage
25-
});
26-
2722
return {
28-
[EtsyTools.getListing]: getListingServerConfig(etsy)
23+
[EtsyTools.getListing]: getListingServerConfig()
2924
};
3025
}
3126
);

src/toolkits/toolkits/Etsy/tools/getListing/base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const getListing = createBaseTool({
88
inputSchema: z.object({
99
}),
1010
outputSchema: z.object({
11-
listings: z.custom<IShopListingsWithAssociations>()
1211
})
1312
// outputSchema: z.object({
1413
// title: z.string().describe("The title of the Etsy listing"),

src/toolkits/toolkits/Etsy/tools/getListing/server.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { ServerToolConfig } from "@/toolkits/types";
22
import type { getListing } from "./base";
3-
import type { Etsy } from "etsy-ts";
43
import { api } from "@/trpc/server";
54

65

76
export const getListingServerConfig = (
8-
etsy: Etsy
7+
98
): ServerToolConfig<
109
typeof getListing.inputSchema.shape,
1110
typeof getListing.outputSchema.shape
@@ -16,16 +15,39 @@ export const getListingServerConfig = (
1615
const account = await api.accounts.getAccountByProvider("etsy");
1716
const userID = account?.providerAccountId;
1817
const etsyUserId = Number(userID);
18+
const apiKey = process.env.AUTH_ETSY_ID;
19+
if (!apiKey) throw new Error("Missing AUTH_ETSY_ID");
20+
const accessToken = account?.access_token;
21+
if (!accessToken) throw new Error("Missing Etsy access token");
22+
23+
24+
25+
const shopResponse = await fetch(
26+
`https://openapi.etsy.com/v3/application/users/${etsyUserId}/shops`,
27+
{
28+
headers: {
29+
"x-api-key": apiKey,
30+
Authorization: `Bearer ${accessToken}`,
31+
}
32+
},
33+
);
34+
35+
const shop = (await shopResponse.json());
36+
37+
const listingResponse = await fetch(
38+
`https://openapi.etsy.com/v3/application/shops/${shop.shop_id}/listings`,
39+
{
40+
headers: {
41+
"x-api-key": apiKey,
42+
Authorization: `Bearer ${accessToken}`,
43+
}
44+
},
45+
);
46+
const listings = (await listingResponse.json());
1947

2048

21-
const shop = await etsy.Shop.getShopByOwnerUserId(etsyUserId, {etsyUserId});
22-
const shopId = shop.data.shop_id;
23-
if (typeof shopId !== "number") {
24-
throw new Error("shop_id is undefined");
25-
}
26-
const listings = await etsy.ShopListing.getListingsByShop({ shopId: shopId }, { etsyUserId });
2749
return {
28-
listings: listings.data,
50+
listings: listings,
2951
};
3052
} catch (error) {
3153
console.error("Etsy API error:", error);

src/toolkits/toolkits/Etsy/wrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const EtsyWrapper: ClientToolkitWrapper = ({ Item }) => {
2828
return <Item isLoading={true} />;
2929
}
3030

31-
if (!hasAccount) {
31+
if (!hasAccount || true) {
3232
return (
3333
<>
3434
<Item

0 commit comments

Comments
 (0)