From b24f4e04a6b6b1f115800fc68f0bf82bc790419f Mon Sep 17 00:00:00 2001 From: "helpcode.ai" Date: Sun, 6 Dec 2026 17:55:43 +0100 Subject: [PATCH] Edit Etsy shop settings, sections and return policies (shops_w) --- packages/backend/src/adapters/intl/etsy.json | 280 +++++++++++++++++- .../src/adapters/intl/etsy.live.spec.ts | 8 +- .../adapters/intl/etsy.write-tools.spec.ts | 77 ++++- .../connectors/connectors.controller.spec.ts | 4 +- .../oauth-authorize-settings.spec.ts | 4 +- 5 files changed, 361 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/adapters/intl/etsy.json b/packages/backend/src/adapters/intl/etsy.json index b3cbcee2e..aeee34292 100644 --- a/packages/backend/src/adapters/intl/etsy.json +++ b/packages/backend/src/adapters/intl/etsy.json @@ -2,7 +2,7 @@ "slug": "etsy", "name": "Etsy", "description": "Run an Etsy shop from any AI agent: create draft listings, edit and publish them, add photos, videos and digital files, set price, stock, attributes and translations, add tracking to orders, and read listings, orders, receipts and reviews. OAuth2 with automatic refresh-token rotation + x-api-key dual auth.", - "instructions": "This connector uses the Etsy Open API v3 (developers.etsy.com). You authorize it once, in AnythingMCP; from then on the short-lived access token (1 hour) is renewed automatically, and the refresh token Etsy replaces on every renewal is stored for you.\n\n**Setup**:\n1. Create an app at Etsy. For your own shop that is a **seller app**: https://www.etsy.com/developers/register-seller-app (two fields; Etsy approves it automatically, usually within minutes, for an active shop that has no other app). When Etsy does not offer you one, register a personal app at https://www.etsy.com/developers/register instead, which Etsy reviews by hand (status *Pending Personal Approval*, usually about a day). Etsy lists the app on https://www.etsy.com/developers/your-apps under **Seller Apps** or **Personal Apps**. Leave **Developer Mode** in Etsy's developer settings switched off: it takes the shop out of Etsy's search, and only Etsy's support can switch it back.\n2. Copy the app's **Keystring** and **Shared Secret** (the eye icon next to it shows it) from that list into `ETSY_CLIENT_ID` and `ETSY_CLIENT_SECRET`, leave `ETSY_REFRESH_TOKEN` empty, and save. This works while the app is still pending.\n3. Wait until Etsy has approved the app: minutes for a seller app, about a day for a personal app (Etsy emails you). Until then Etsy refuses the keys with a 403 and the app's page does not open.\n4. Once the app is active, open it (click its name, or **Edit callback URLs** in the menu next to it) and add this **callback URL**: `https://cloud.anythingmcp.com/api/mcp-oauth/callback` on AnythingMCP Cloud, or `/api/mcp-oauth/callback` when you host AnythingMCP yourself. Etsy compares it character for character (https, upper/lower case, no trailing slash).\n5. Open the connector and click **Authorize with Provider**. Sign in to Etsy, approve, and you land back on the connector page with the tools ready. AnythingMCP runs Etsy's OAuth2 PKCE flow (S256) for you.\n\n**Scopes**: the connector asks for `email_r shops_r listings_r listings_w listings_d transactions_r transactions_w`: read your account, shops, listings and orders, edit listings, delete listings (the delete tool is installed switched off), and add tracking to orders. **Connectors authorized with an earlier scope list** (only the read scopes, or without `listings_d`) get the current list when you click **Authorize with Provider** again; until then Etsy answers \"Access token lacks scope\" to the tools that need the missing scope.\n\n**Already have a refresh token?** You can paste it into `ETSY_REFRESH_TOKEN` instead of step 5, if you obtained it yourself through Etsy's OAuth2 PKCE flow for the same app. Connectors set up that way keep working as they are; there is nothing to do. Clicking **Authorize with Provider** on one replaces its token with a new one, and needs the callback URL from step 4.\n\n**Authentication**: the connector attaches both headers on every request:\n - `Authorization: Bearer `\n - `x-api-key: ${ETSY_CLIENT_ID}:${ETSY_CLIENT_SECRET}`\n\nEtsy requires the API key on **every** request, OAuth or not, and it must carry the\nKeystring AND the Shared secret separated by a colon. The Keystring alone earns a\n`403 {\"error\":\"Invalid API key: should be in the format 'keystring:shared_secret'.\"}`\non every call.\n\nThe access token is kept in memory and written back, together with the rotated refresh token, into this connector's own encrypted configuration, so a restart does not lose it. Per Etsy's policy, **refresh tokens rotate on each use**; AnythingMCP stores the new one from every refresh response and re-uses it automatically.\n\n**If a call says the access token could not be renewed**: an Etsy refresh token works once and expires after 90 days unused. Click **Authorize with Provider** on the connector page to get a new one.\n\n**Shop ID**: every account has a shop_id. Get it from `etsy_get_authenticated_user` then `etsy_get_user_shops`.\n\n**Reading the shop**: `etsy_get_listings_by_shop` lists your own listings in any state (active, draft, inactive, sold out); `etsy_get_shop_listings_active` is the public view any visitor sees; `etsy_list_shop_sections` and `etsy_get_listings_by_shop_section` go by shop section; `etsy_get_shop_reviews` lists the reviews. `etsy_list_taxonomy_properties` gives the properties (size, colour, material) a category allows.\n\n**Orders and sales**: `etsy_get_shop_receipts` lists orders and `etsy_get_shop_receipt` reads one with its line items. `etsy_get_shop_transactions` lists the sold line items of the whole shop (listing, SKU, quantity, price, variations), the view for sales per product. `etsy_get_listings_by_ids` then reads up to 100 of the listings behind them in one call. `etsy_add_order_tracking` marks an order as shipped with its tracking code, and Etsy e-mails the buyer at once.\n\n**Attributes, translations and media**: `etsy_get_listing_properties` reads a listing's attributes (colour, material, size) and `etsy_set_listing_property` sets one, with ids from `etsy_list_taxonomy_properties`. `etsy_read_listing_translation`, `etsy_add_listing_translation` (new language) and `etsy_replace_listing_translation` (existing one) handle titles, descriptions and tags in de, en, es, fr, it, ja, nl, pl and pt. `etsy_list_listing_images` lists the photos; `etsy_list_listing_variation_images` and `etsy_assign_variation_images` link photos to variation values (the assign call replaces every link). `etsy_list_listing_videos` and `etsy_add_listing_video` handle the listing video (one per listing, 5 to 15 seconds); `etsy_list_listing_files` and `etsy_upload_listing_file` the files buyers download from a digital listing. Uploads take a public URL that AnythingMCP downloads, up to the server's upload limit (10 MB by default). `etsy_list_production_partners` gives the ids for production_partner_ids.\n\n**Beyond your shop**: `etsy_search_active_listings` searches every active listing on Etsy (keywords, category, price range) and `etsy_search_shops` finds shops by name.\n\n**Switched off at install**: `etsy_delete_listing_permanently` (deletes a listing for good; to hide one, set state=inactive with `etsy_edit_listing`), `etsy_delete_listing_image` and `etsy_delete_listing_property`. Turn them on under the connector's tools when you need them.\n\n**Pagination**: `?limit=N&offset=M` (limit max 100).\n\n**Rate limits**: 10k req/24h per app. On 429 back off.\n\n**Creating a listing** takes a few steps, in this order: find the category with `etsy_list_seller_taxonomy`; for a physical item get a shipping profile (`etsy_list_shipping_profiles`), a processing profile (`etsy_list_processing_profiles`) and, outside the EU, a return policy (`etsy_list_return_policies`); create the draft with `etsy_create_listing_draft`; add at least one photo with `etsy_add_listing_image`; publish with `etsy_edit_listing` and `state=active`. Change price or stock with `etsy_read_listing_inventory` then `etsy_set_listing_inventory`, which replaces the whole inventory. Etsy rejects titles with more than three words in capitals and tags longer than 20 characters; a shop on vacation cannot change listings.\n\n**Out of scope here**: shop settings and shop sections (they need the `shops_w` scope), payment account, billing, taxonomy edits.", + "instructions": "This connector uses the Etsy Open API v3 (developers.etsy.com). You authorize it once, in AnythingMCP; from then on the short-lived access token (1 hour) is renewed automatically, and the refresh token Etsy replaces on every renewal is stored for you.\n\n**Setup**:\n1. Create an app at Etsy. For your own shop that is a **seller app**: https://www.etsy.com/developers/register-seller-app (two fields; Etsy approves it automatically, usually within minutes, for an active shop that has no other app). When Etsy does not offer you one, register a personal app at https://www.etsy.com/developers/register instead, which Etsy reviews by hand (status *Pending Personal Approval*, usually about a day). Etsy lists the app on https://www.etsy.com/developers/your-apps under **Seller Apps** or **Personal Apps**. Leave **Developer Mode** in Etsy's developer settings switched off: it takes the shop out of Etsy's search, and only Etsy's support can switch it back.\n2. Copy the app's **Keystring** and **Shared Secret** (the eye icon next to it shows it) from that list into `ETSY_CLIENT_ID` and `ETSY_CLIENT_SECRET`, leave `ETSY_REFRESH_TOKEN` empty, and save. This works while the app is still pending.\n3. Wait until Etsy has approved the app: minutes for a seller app, about a day for a personal app (Etsy emails you). Until then Etsy refuses the keys with a 403 and the app's page does not open.\n4. Once the app is active, open it (click its name, or **Edit callback URLs** in the menu next to it) and add this **callback URL**: `https://cloud.anythingmcp.com/api/mcp-oauth/callback` on AnythingMCP Cloud, or `/api/mcp-oauth/callback` when you host AnythingMCP yourself. Etsy compares it character for character (https, upper/lower case, no trailing slash).\n5. Open the connector and click **Authorize with Provider**. Sign in to Etsy, approve, and you land back on the connector page with the tools ready. AnythingMCP runs Etsy's OAuth2 PKCE flow (S256) for you.\n\n**Scopes**: the connector asks for `email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w`: read your account, shops, listings and orders, edit the shop's settings, sections and return policies, edit listings, delete listings (the delete tools are installed switched off), and add tracking to orders. **Connectors authorized with an earlier scope list** (only the read scopes, or without `listings_d` or `shops_w`) get the current list when you click **Authorize with Provider** again; until then Etsy answers \"Access token lacks scope\" to the tools that need the missing scope.\n\n**Already have a refresh token?** You can paste it into `ETSY_REFRESH_TOKEN` instead of step 5, if you obtained it yourself through Etsy's OAuth2 PKCE flow for the same app. Connectors set up that way keep working as they are; there is nothing to do. Clicking **Authorize with Provider** on one replaces its token with a new one, and needs the callback URL from step 4.\n\n**Authentication**: the connector attaches both headers on every request:\n - `Authorization: Bearer `\n - `x-api-key: ${ETSY_CLIENT_ID}:${ETSY_CLIENT_SECRET}`\n\nEtsy requires the API key on **every** request, OAuth or not, and it must carry the\nKeystring AND the Shared secret separated by a colon. The Keystring alone earns a\n`403 {\"error\":\"Invalid API key: should be in the format 'keystring:shared_secret'.\"}`\non every call.\n\nThe access token is kept in memory and written back, together with the rotated refresh token, into this connector's own encrypted configuration, so a restart does not lose it. Per Etsy's policy, **refresh tokens rotate on each use**; AnythingMCP stores the new one from every refresh response and re-uses it automatically.\n\n**If a call says the access token could not be renewed**: an Etsy refresh token works once and expires after 90 days unused. Click **Authorize with Provider** on the connector page to get a new one.\n\n**Shop ID**: every account has a shop_id. Get it from `etsy_get_authenticated_user` then `etsy_get_user_shops`.\n\n**Reading the shop**: `etsy_get_listings_by_shop` lists your own listings in any state (active, draft, inactive, sold out); `etsy_get_shop_listings_active` is the public view any visitor sees; `etsy_list_shop_sections` and `etsy_get_listings_by_shop_section` go by shop section; `etsy_get_shop_reviews` lists the reviews. `etsy_list_taxonomy_properties` gives the properties (size, colour, material) a category allows.\n\n**Orders and sales**: `etsy_get_shop_receipts` lists orders and `etsy_get_shop_receipt` reads one with its line items. `etsy_get_shop_transactions` lists the sold line items of the whole shop (listing, SKU, quantity, price, variations), the view for sales per product. `etsy_get_listings_by_ids` then reads up to 100 of the listings behind them in one call. `etsy_add_order_tracking` marks an order as shipped with its tracking code, and Etsy e-mails the buyer at once.\n\n**Attributes, translations and media**: `etsy_get_listing_properties` reads a listing's attributes (colour, material, size) and `etsy_set_listing_property` sets one, with ids from `etsy_list_taxonomy_properties`. `etsy_read_listing_translation`, `etsy_add_listing_translation` (new language) and `etsy_replace_listing_translation` (existing one) handle titles, descriptions and tags in de, en, es, fr, it, ja, nl, pl and pt. `etsy_list_listing_images` lists the photos; `etsy_list_listing_variation_images` and `etsy_assign_variation_images` link photos to variation values (the assign call replaces every link). `etsy_list_listing_videos` and `etsy_add_listing_video` handle the listing video (one per listing, 5 to 15 seconds); `etsy_list_listing_files` and `etsy_upload_listing_file` the files buyers download from a digital listing. Uploads take a public URL that AnythingMCP downloads, up to the server's upload limit (10 MB by default). `etsy_list_production_partners` gives the ids for production_partner_ids.\n\n**Beyond your shop**: `etsy_search_active_listings` searches every active listing on Etsy (keywords, category, price range) and `etsy_search_shops` finds shops by name.\n\n**Switched off at install**: `etsy_delete_listing_permanently` (deletes a listing for good; to hide one, set state=inactive with `etsy_edit_listing`), `etsy_delete_listing_image`, `etsy_delete_listing_property`, `etsy_delete_shop_section` and `etsy_delete_return_policy`. Turn them on under the connector's tools when you need them.\n\n**Pagination**: `?limit=N&offset=M` (limit max 100).\n\n**Rate limits**: 10k req/24h per app. On 429 back off.\n\n**Creating a listing** takes a few steps, in this order: find the category with `etsy_list_seller_taxonomy`; for a physical item get a shipping profile (`etsy_list_shipping_profiles`), a processing profile (`etsy_list_processing_profiles`) and, outside the EU, a return policy (`etsy_list_return_policies`); create the draft with `etsy_create_listing_draft`; add at least one photo with `etsy_add_listing_image`; publish with `etsy_edit_listing` and `state=active`. Change price or stock with `etsy_read_listing_inventory` then `etsy_set_listing_inventory`, which replaces the whole inventory. Etsy rejects titles with more than three words in capitals and tags longer than 20 characters; a shop on vacation cannot change listings.\n\n**Shop settings**: `etsy_edit_shop` changes the shop title, announcement, sale messages and additional policies (`policy_additional` only for shops located in the EU: Etsy refuses it elsewhere). Sections (`etsy_add_shop_section`, `etsy_rename_shop_section`, `etsy_delete_shop_section`) and return policies (`etsy_add_return_policy`, `etsy_edit_return_policy`, `etsy_delete_return_policy`) have their own tools; a return policy can only be deleted when no listing uses it. These tools need the `shops_w` scope.\n\n**Out of scope here**: payment account, billing, shipping profile edits, taxonomy edits.", "region": "intl", "category": "e-commerce", "icon": "etsy", @@ -16,7 +16,8 @@ ], "previousOAuthScopes": [ "email_r shops_r listings_r transactions_r", - "email_r shops_r listings_r listings_w transactions_r transactions_w" + "email_r shops_r listings_r listings_w transactions_r transactions_w", + "email_r shops_r listings_r listings_w listings_d transactions_r transactions_w" ], "appRegistrationUrl": "https://www.etsy.com/developers/register-seller-app", "envVarMeta": { @@ -211,7 +212,7 @@ "grant": "refresh_token", "authorizationUrl": "https://www.etsy.com/oauth/connect", "tokenUrl": "https://api.etsy.com/v3/public/oauth/token", - "scopes": "email_r shops_r listings_r listings_w listings_d transactions_r transactions_w", + "scopes": "email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w", "clientId": "{{ETSY_CLIENT_ID}}", "clientSecret": "{{ETSY_CLIENT_SECRET}}", "refreshToken": "{{ETSY_REFRESH_TOKEN}}", @@ -797,6 +798,279 @@ "encodePathParams": true } }, + { + "name": "etsy_edit_shop", + "description": "Change the shop's settings: title (the heading on the shop page), announcement, the message sent after a purchase, the message sent after a digital purchase, and the additional policies text. Send only the fields to change, in the shop's primary language. policy_additional is accepted only for shops located in the EU. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "title": { + "type": "string", + "description": "Short heading shown on the shop's main page." + }, + "announcement": { + "type": "string", + "description": "Announcement shown to buyers on the shop's home page." + }, + "sale_message": { + "type": "string", + "description": "Message sent to buyers who complete a purchase." + }, + "digital_sale_message": { + "type": "string", + "description": "Message sent to buyers who purchase a digital item." + }, + "policy_additional": { + "type": "string", + "description": "Additional policies text (EU-based shops only; Etsy refuses it for other shops)." + } + }, + "required": [ + "shop_id" + ] + }, + "endpointMapping": { + "method": "PUT", + "path": "/shops/{shop_id}", + "encodePathParams": true, + "bodyEncoding": "form-urlencoded", + "bodyMapping": { + "title": "$title", + "announcement": "$announcement", + "sale_message": "$sale_message", + "digital_sale_message": "$digital_sale_message", + "policy_additional": "$policy_additional" + } + } + }, + { + "name": "etsy_add_shop_section", + "description": "Add a section to the shop (a heading listings can be filed under). Returns the new shop_section_id. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "title": { + "type": "string", + "description": "Section title." + } + }, + "required": [ + "shop_id", + "title" + ] + }, + "endpointMapping": { + "method": "POST", + "path": "/shops/{shop_id}/sections", + "encodePathParams": true, + "bodyEncoding": "form-urlencoded", + "bodyMapping": { + "title": "$title" + } + } + }, + { + "name": "etsy_rename_shop_section", + "description": "Change the title of a shop section. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "shop_section_id": { + "type": "integer", + "description": "Section ID (from etsy_list_shop_sections)." + }, + "title": { + "type": "string", + "description": "New section title." + } + }, + "required": [ + "shop_id", + "shop_section_id", + "title" + ] + }, + "endpointMapping": { + "method": "PUT", + "path": "/shops/{shop_id}/sections/{shop_section_id}", + "encodePathParams": true, + "bodyEncoding": "form-urlencoded", + "bodyMapping": { + "title": "$title" + } + } + }, + { + "name": "etsy_delete_shop_section", + "description": "Delete a shop section. Its listings stay in the shop, without a section. Cannot be undone: to bring it back, create it again and file the listings under it. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "shop_section_id": { + "type": "integer", + "description": "Section ID (from etsy_list_shop_sections)." + } + }, + "required": [ + "shop_id", + "shop_section_id" + ] + }, + "endpointMapping": { + "method": "DELETE", + "path": "/shops/{shop_id}/sections/{shop_section_id}", + "encodePathParams": true + }, + "enabled": false + }, + { + "name": "etsy_add_return_policy", + "description": "Add a return policy to the shop, to use as return_policy_id on listings. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "accepts_returns": { + "type": "boolean", + "description": "Whether returns are accepted." + }, + "accepts_exchanges": { + "type": "boolean", + "description": "Whether exchanges are accepted." + }, + "return_deadline": { + "type": "integer", + "enum": [ + 7, + 14, + 21, + 30, + 45, + 60, + 90 + ], + "description": "Days the buyer has to return or exchange: 7, 14, 21, 30, 45, 60 or 90. Required when accepts_returns or accepts_exchanges is true." + } + }, + "required": [ + "shop_id", + "accepts_returns", + "accepts_exchanges" + ] + }, + "endpointMapping": { + "method": "POST", + "path": "/shops/{shop_id}/policies/return", + "encodePathParams": true, + "bodyEncoding": "form-urlencoded", + "bodyMapping": { + "accepts_returns": "$accepts_returns", + "accepts_exchanges": "$accepts_exchanges", + "return_deadline": "$return_deadline" + } + } + }, + { + "name": "etsy_edit_return_policy", + "description": "Change a return policy; every listing that uses it changes too. Send accepts_returns and accepts_exchanges every time. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "return_policy_id": { + "type": "integer", + "description": "Return policy ID (from etsy_list_return_policies)." + }, + "accepts_returns": { + "type": "boolean", + "description": "Whether returns are accepted." + }, + "accepts_exchanges": { + "type": "boolean", + "description": "Whether exchanges are accepted." + }, + "return_deadline": { + "type": "integer", + "enum": [ + 7, + 14, + 21, + 30, + 45, + 60, + 90 + ], + "description": "Days the buyer has to return or exchange: 7, 14, 21, 30, 45, 60 or 90. Required when accepts_returns or accepts_exchanges is true." + } + }, + "required": [ + "shop_id", + "return_policy_id", + "accepts_returns", + "accepts_exchanges" + ] + }, + "endpointMapping": { + "method": "PUT", + "path": "/shops/{shop_id}/policies/return/{return_policy_id}", + "encodePathParams": true, + "bodyEncoding": "form-urlencoded", + "bodyMapping": { + "accepts_returns": "$accepts_returns", + "accepts_exchanges": "$accepts_exchanges", + "return_deadline": "$return_deadline" + } + } + }, + { + "name": "etsy_delete_return_policy", + "description": "Delete a return policy. Etsy allows it only when no listing uses the policy: move those listings to another policy first (etsy_edit_listing with return_policy_id). Cannot be undone. Needs the shops_w scope.", + "parameters": { + "type": "object", + "properties": { + "shop_id": { + "type": "integer", + "description": "Shop ID (from etsy_get_user_shops)." + }, + "return_policy_id": { + "type": "integer", + "description": "Return policy ID (from etsy_list_return_policies)." + } + }, + "required": [ + "shop_id", + "return_policy_id" + ] + }, + "endpointMapping": { + "method": "DELETE", + "path": "/shops/{shop_id}/policies/return/{return_policy_id}", + "encodePathParams": true + }, + "enabled": false + }, { "name": "etsy_read_listing_inventory", "description": "Products, prices, quantities and SKUs of a listing, per variation. Read this before etsy_set_listing_inventory: that call replaces the whole inventory.", diff --git a/packages/backend/src/adapters/intl/etsy.live.spec.ts b/packages/backend/src/adapters/intl/etsy.live.spec.ts index 450a36d90..3cb90dfa8 100644 --- a/packages/backend/src/adapters/intl/etsy.live.spec.ts +++ b/packages/backend/src/adapters/intl/etsy.live.spec.ts @@ -131,13 +131,15 @@ describe('etsy adapter — static spec conformance', () => { it('can be authorized in the browser, and still accepts a pasted refresh token', () => { const auth = a.connector.authConfig; expect(auth.authorizationUrl).toBe('https://www.etsy.com/oauth/connect'); - // Space-separated, as Etsy documents. Write scopes for the listing and - // tracking tools; listings_d for the delete tool, which installs off. - expect(auth.scopes).toBe('email_r shops_r listings_r listings_w listings_d transactions_r transactions_w'); + // Space-separated, as Etsy documents. Write scopes for the shop-settings, + // listing and tracking tools; listings_d for the delete tool, which + // installs off. + expect(auth.scopes).toBe('email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w'); // Rows holding an earlier list get the current one on re-authorization. expect((adapter as unknown as { previousOAuthScopes: string[] }).previousOAuthScopes).toEqual([ 'email_r shops_r listings_r transactions_r', 'email_r shops_r listings_r listings_w transactions_r transactions_w', + 'email_r shops_r listings_r listings_w listings_d transactions_r transactions_w', ]); // Etsy takes the client in the body (client_id, and the shared secret it // checks). Basic would change the refresh request of every Etsy row. diff --git a/packages/backend/src/adapters/intl/etsy.write-tools.spec.ts b/packages/backend/src/adapters/intl/etsy.write-tools.spec.ts index 7ff258563..07f5ff295 100644 --- a/packages/backend/src/adapters/intl/etsy.write-tools.spec.ts +++ b/packages/backend/src/adapters/intl/etsy.write-tools.spec.ts @@ -230,7 +230,13 @@ describe('etsy adapter: write tools', () => { expect(sent().method).toBe('DELETE'); expect(sent().url).toBe('https://openapi.etsy.com/v3/application/listings/456'); const off = (tools as Array).filter((t) => t.enabled === false).map((t) => t.name); - expect(off.sort()).toEqual(['etsy_delete_listing_image', 'etsy_delete_listing_permanently', 'etsy_delete_listing_property']); + expect(off.sort()).toEqual([ + 'etsy_delete_listing_image', + 'etsy_delete_listing_permanently', + 'etsy_delete_listing_property', + 'etsy_delete_return_policy', + 'etsy_delete_shop_section', + ]); for (const t of tools) { if (t.endpointMapping.method === 'DELETE') expect(off).toContain(t.name); } @@ -268,8 +274,75 @@ describe('etsy adapter: write tools', () => { } }); + /** + * Shop settings, sections and return policies (scope shops_w), asked for by + * a seller who edits the shop from Claude. Request shapes follow Etsy's + * OpenAPI spec: updateShop, createShopSection, updateShopSection, + * createShopReturnPolicy and updateShopReturnPolicy take form-urlencoded + * bodies. + */ + it('edits the shop settings with PUT and sends only the fields given', async () => { + await run('etsy_edit_shop', { shop_id: 123, announcement: 'Back from holiday on 2 January' }); + expect(sent().method).toBe('PUT'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123'); + expect(sent().headers['Content-Type']).toBe('application/x-www-form-urlencoded'); + expect(new URLSearchParams(sent().data).get('announcement')).toBe('Back from holiday on 2 January'); + expect(sent().data).toBe('announcement=Back+from+holiday+on+2+January'); + expect(tool('etsy_edit_shop').parameters.required).toEqual(['shop_id']); + }); + + it('adds and renames a shop section, form-urlencoded', async () => { + await run('etsy_add_shop_section', { shop_id: 123, title: 'Mugs' }); + expect(sent().method).toBe('POST'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/sections'); + expect(sent().data).toBe('title=Mugs'); + mockedAxios.mockClear(); + await run('etsy_rename_shop_section', { shop_id: 123, shop_section_id: 9, title: 'Cups' }); + expect(sent().method).toBe('PUT'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/sections/9'); + expect(sent().data).toBe('title=Cups'); + }); + + it('adds and edits a return policy with the deadlines Etsy accepts', async () => { + await run('etsy_add_return_policy', { shop_id: 123, accepts_returns: true, accepts_exchanges: false, return_deadline: 30 }); + expect(sent().method).toBe('POST'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/policies/return'); + const body = new URLSearchParams(sent().data); + expect(body.get('accepts_returns')).toBe('true'); + expect(body.get('accepts_exchanges')).toBe('false'); + expect(body.get('return_deadline')).toBe('30'); + mockedAxios.mockClear(); + await run('etsy_edit_return_policy', { shop_id: 123, return_policy_id: 5, accepts_returns: false, accepts_exchanges: false }); + expect(sent().method).toBe('PUT'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/policies/return/5'); + expect(new URLSearchParams(sent().data).has('return_deadline')).toBe(false); + for (const name of ['etsy_add_return_policy', 'etsy_edit_return_policy']) { + const deadline = tool(name).parameters.properties.return_deadline as { enum: number[] }; + expect(deadline.enum).toEqual([7, 14, 21, 30, 45, 60, 90]); + } + }); + + it('deletes sections and return policies on their own routes, with path ids encoded', async () => { + await run('etsy_delete_shop_section', { shop_id: 123, shop_section_id: 9 }); + expect(sent().method).toBe('DELETE'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/sections/9'); + mockedAxios.mockClear(); + await run('etsy_delete_return_policy', { shop_id: 123, return_policy_id: 5 }); + expect(sent().method).toBe('DELETE'); + expect(sent().url).toBe('https://openapi.etsy.com/v3/application/shops/123/policies/return/5'); + for (const name of [ + 'etsy_edit_shop', 'etsy_add_shop_section', 'etsy_rename_shop_section', 'etsy_delete_shop_section', + 'etsy_add_return_policy', 'etsy_edit_return_policy', 'etsy_delete_return_policy', + ]) { + expect(`${name}:${tool(name).endpointMapping.encodePathParams}`).toBe(`${name}:true`); + } + }); + it('does not reuse names customers gave their own Etsy tools', () => { - const taken = ['etsy_update_listing', 'etsy_create_draft_listing', 'etsy_update_listing_inventory', 'etsy_upload_listing_image', 'etsy_get_listing_inventory', 'etsy_get_seller_taxonomy']; + const taken = [ + 'etsy_update_listing', 'etsy_create_draft_listing', 'etsy_update_listing_inventory', 'etsy_upload_listing_image', + 'etsy_get_listing_inventory', 'etsy_get_seller_taxonomy', 'etsy_update_shop', 'etsy_create_shop_section', + ]; for (const name of taken) expect(tools.some((t) => t.name === name)).toBe(false); }); }); diff --git a/packages/backend/src/connectors/connectors.controller.spec.ts b/packages/backend/src/connectors/connectors.controller.spec.ts index 1fad6eaad..5cf73cc0a 100644 --- a/packages/backend/src/connectors/connectors.controller.spec.ts +++ b/packages/backend/src/connectors/connectors.controller.spec.ts @@ -1107,7 +1107,7 @@ describe('POST :id/oauth/authorize (REST)', () => { expect(url.origin + url.pathname).toBe('https://www.etsy.com/oauth/connect'); expect(url.searchParams.get('client_id')).toBe('keystring'); expect(url.searchParams.get('redirect_uri')).toBe(`${SERVER}/api/mcp-oauth/callback`); - expect(url.searchParams.get('scope')).toBe('email_r shops_r listings_r listings_w listings_d transactions_r transactions_w'); + expect(url.searchParams.get('scope')).toBe('email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w'); expect(url.searchParams.get('code_challenge_method')).toBe('S256'); const [state, flow] = store.mock.calls[0]; @@ -1124,7 +1124,7 @@ describe('POST :id/oauth/authorize (REST)', () => { tokenAuthMethod: undefined, persistAuthConfig: { authorizationUrl: 'https://www.etsy.com/oauth/connect', - scopes: 'email_r shops_r listings_r listings_w listings_d transactions_r transactions_w', + scopes: 'email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w', }, }); }); diff --git a/packages/backend/src/connectors/oauth-authorize-settings.spec.ts b/packages/backend/src/connectors/oauth-authorize-settings.spec.ts index f36539862..b0bf5abbf 100644 --- a/packages/backend/src/connectors/oauth-authorize-settings.spec.ts +++ b/packages/backend/src/connectors/oauth-authorize-settings.spec.ts @@ -123,13 +123,13 @@ describe('resolveRestAuthorizeSettings', () => { etsyCatalog, ); expect(settings.authorizationUrl).toBe('https://www.etsy.com/oauth/connect'); - expect(settings.scope).toBe('email_r shops_r listings_r listings_w listings_d transactions_r transactions_w'); + expect(settings.scope).toBe('email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w'); expect(settings.tokenUrl).toBe('https://api.etsy.com/v3/public/oauth/token'); // Etsy authenticates the client in the body: nothing to adopt there. expect(settings.tokenAuthMethod).toBeUndefined(); expect(settings.adopted).toEqual({ authorizationUrl: 'https://www.etsy.com/oauth/connect', - scopes: 'email_r shops_r listings_r listings_w listings_d transactions_r transactions_w', + scopes: 'email_r shops_r shops_w listings_r listings_w listings_d transactions_r transactions_w', }); });