@profplum700/etsy-v3-api-client 2.4.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1939,6 +1939,376 @@ class EtsyClient {
1939
1939
  const response = await this.makeRequest(`/shops/${shopId}/production-partners`);
1940
1940
  return response.results;
1941
1941
  }
1942
+ async createShopReadinessStateDefinition(shopId, params) {
1943
+ const body = this.buildFormBody(params);
1944
+ return this.makeRequest(`/shops/${shopId}/readiness-state-definitions`, {
1945
+ method: 'POST',
1946
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1947
+ body: body.toString()
1948
+ }, false);
1949
+ }
1950
+ async getShopReadinessStateDefinitions(shopId, params = {}) {
1951
+ const searchParams = new URLSearchParams();
1952
+ if (params.limit !== undefined)
1953
+ searchParams.set('limit', params.limit.toString());
1954
+ if (params.offset !== undefined)
1955
+ searchParams.set('offset', params.offset.toString());
1956
+ const query = searchParams.toString();
1957
+ const suffix = query ? `?${query}` : '';
1958
+ const response = await this.makeRequest(`/shops/${shopId}/readiness-state-definitions${suffix}`);
1959
+ return response.results;
1960
+ }
1961
+ async getShopReadinessStateDefinition(shopId, definitionId) {
1962
+ return this.makeRequest(`/shops/${shopId}/readiness-state-definitions/${definitionId}`);
1963
+ }
1964
+ async updateShopReadinessStateDefinition(shopId, definitionId, params) {
1965
+ const body = this.buildFormBody(params);
1966
+ return this.makeRequest(`/shops/${shopId}/readiness-state-definitions/${definitionId}`, {
1967
+ method: 'PUT',
1968
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1969
+ body: body.toString()
1970
+ }, false);
1971
+ }
1972
+ async deleteShopReadinessStateDefinition(shopId, definitionId) {
1973
+ await this.makeRequest(`/shops/${shopId}/readiness-state-definitions/${definitionId}`, { method: 'DELETE' }, false);
1974
+ }
1975
+ async createShopReturnPolicy(shopId, params) {
1976
+ const body = this.buildFormBody(params);
1977
+ return this.makeRequest(`/shops/${shopId}/policies/return`, {
1978
+ method: 'POST',
1979
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1980
+ body: body.toString()
1981
+ }, false);
1982
+ }
1983
+ async getShopReturnPolicies(shopId) {
1984
+ const response = await this.makeRequest(`/shops/${shopId}/policies/return`);
1985
+ return response.results;
1986
+ }
1987
+ async getShopReturnPolicy(shopId, returnPolicyId) {
1988
+ return this.makeRequest(`/shops/${shopId}/policies/return/${returnPolicyId}`);
1989
+ }
1990
+ async updateShopReturnPolicy(shopId, returnPolicyId, params) {
1991
+ const body = this.buildFormBody(params);
1992
+ return this.makeRequest(`/shops/${shopId}/policies/return/${returnPolicyId}`, {
1993
+ method: 'PUT',
1994
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1995
+ body: body.toString()
1996
+ }, false);
1997
+ }
1998
+ async deleteShopReturnPolicy(shopId, returnPolicyId) {
1999
+ await this.makeRequest(`/shops/${shopId}/policies/return/${returnPolicyId}`, { method: 'DELETE' }, false);
2000
+ }
2001
+ async consolidateShopReturnPolicies(shopId, params) {
2002
+ const body = this.buildFormBody(params);
2003
+ return this.makeRequest(`/shops/${shopId}/policies/return/consolidate`, {
2004
+ method: 'POST',
2005
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2006
+ body: body.toString()
2007
+ }, false);
2008
+ }
2009
+ async getHolidayPreferences(shopId) {
2010
+ const response = await this.makeRequest(`/shops/${shopId}/holiday-preferences`);
2011
+ return response.results;
2012
+ }
2013
+ async updateHolidayPreferences(shopId, holidayId, params) {
2014
+ const body = this.buildFormBody(params);
2015
+ return this.makeRequest(`/shops/${shopId}/holiday-preferences/${holidayId}`, {
2016
+ method: 'PUT',
2017
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2018
+ body: body.toString()
2019
+ }, false);
2020
+ }
2021
+ async uploadListingFile(shopId, listingId, fileData, params) {
2022
+ const formData = new FormData();
2023
+ formData.append('file', fileData);
2024
+ if (params?.name)
2025
+ formData.append('name', params.name);
2026
+ if (params?.rank !== undefined)
2027
+ formData.append('rank', params.rank.toString());
2028
+ if (params?.listing_file_id !== undefined)
2029
+ formData.append('listing_file_id', params.listing_file_id.toString());
2030
+ const url = `${this.baseUrl}/shops/${shopId}/listings/${listingId}/files`;
2031
+ await this.rateLimiter.waitForRateLimit();
2032
+ const accessToken = await this.tokenManager.getAccessToken();
2033
+ const response = await this.fetch(url, {
2034
+ method: 'POST',
2035
+ headers: {
2036
+ 'Authorization': `Bearer ${accessToken}`,
2037
+ 'x-api-key': this.getApiKey(),
2038
+ },
2039
+ body: formData
2040
+ });
2041
+ if (!response.ok) {
2042
+ const errorText = await response.text();
2043
+ throw new EtsyApiError(`Failed to upload file: ${response.status} ${response.statusText}`, response.status, errorText);
2044
+ }
2045
+ return response.json();
2046
+ }
2047
+ async getAllListingFiles(shopId, listingId) {
2048
+ const response = await this.makeRequest(`/shops/${shopId}/listings/${listingId}/files`);
2049
+ return response.results;
2050
+ }
2051
+ async getListingFile(shopId, listingId, fileId) {
2052
+ return this.makeRequest(`/shops/${shopId}/listings/${listingId}/files/${fileId}`);
2053
+ }
2054
+ async deleteListingFile(shopId, listingId, fileId) {
2055
+ await this.makeRequest(`/shops/${shopId}/listings/${listingId}/files/${fileId}`, { method: 'DELETE' }, false);
2056
+ }
2057
+ async uploadListingVideo(shopId, listingId, videoData, params) {
2058
+ const formData = new FormData();
2059
+ formData.append('video', videoData);
2060
+ if (params?.name)
2061
+ formData.append('name', params.name);
2062
+ if (params?.video_id !== undefined)
2063
+ formData.append('video_id', params.video_id.toString());
2064
+ const url = `${this.baseUrl}/shops/${shopId}/listings/${listingId}/videos`;
2065
+ await this.rateLimiter.waitForRateLimit();
2066
+ const accessToken = await this.tokenManager.getAccessToken();
2067
+ const response = await this.fetch(url, {
2068
+ method: 'POST',
2069
+ headers: {
2070
+ 'Authorization': `Bearer ${accessToken}`,
2071
+ 'x-api-key': this.getApiKey(),
2072
+ },
2073
+ body: formData
2074
+ });
2075
+ if (!response.ok) {
2076
+ const errorText = await response.text();
2077
+ throw new EtsyApiError(`Failed to upload video: ${response.status} ${response.statusText}`, response.status, errorText);
2078
+ }
2079
+ return response.json();
2080
+ }
2081
+ async getListingVideos(listingId) {
2082
+ const response = await this.makeRequest(`/listings/${listingId}/videos`);
2083
+ return response.results;
2084
+ }
2085
+ async getListingVideo(listingId, videoId) {
2086
+ return this.makeRequest(`/listings/${listingId}/videos/${videoId}`);
2087
+ }
2088
+ async deleteListingVideo(shopId, listingId, videoId) {
2089
+ await this.makeRequest(`/shops/${shopId}/listings/${listingId}/videos/${videoId}`, { method: 'DELETE' }, false);
2090
+ }
2091
+ async createListingTranslation(shopId, listingId, language, params) {
2092
+ const body = this.buildFormBody(params);
2093
+ return this.makeRequest(`/shops/${shopId}/listings/${listingId}/translations/${language}`, {
2094
+ method: 'POST',
2095
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2096
+ body: body.toString()
2097
+ }, false);
2098
+ }
2099
+ async getListingTranslation(shopId, listingId, language) {
2100
+ return this.makeRequest(`/shops/${shopId}/listings/${listingId}/translations/${language}`);
2101
+ }
2102
+ async updateListingTranslation(shopId, listingId, language, params) {
2103
+ const body = this.buildFormBody(params);
2104
+ return this.makeRequest(`/shops/${shopId}/listings/${listingId}/translations/${language}`, {
2105
+ method: 'PUT',
2106
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2107
+ body: body.toString()
2108
+ }, false);
2109
+ }
2110
+ async getListingVariationImages(shopId, listingId) {
2111
+ const response = await this.makeRequest(`/shops/${shopId}/listings/${listingId}/variation-images`);
2112
+ return response.results;
2113
+ }
2114
+ async updateVariationImages(shopId, listingId, params) {
2115
+ const response = await this.makeRequest(`/shops/${shopId}/listings/${listingId}/variation-images`, {
2116
+ method: 'POST',
2117
+ body: JSON.stringify(params)
2118
+ }, false);
2119
+ return response.results;
2120
+ }
2121
+ async findAllActiveListingsByShop(shopId, params = {}) {
2122
+ const searchParams = new URLSearchParams();
2123
+ if (params.limit !== undefined)
2124
+ searchParams.set('limit', params.limit.toString());
2125
+ if (params.offset !== undefined)
2126
+ searchParams.set('offset', params.offset.toString());
2127
+ if (params.sort_on)
2128
+ searchParams.set('sort_on', params.sort_on);
2129
+ if (params.sort_order)
2130
+ searchParams.set('sort_order', params.sort_order);
2131
+ if (params.keywords)
2132
+ searchParams.set('keywords', params.keywords);
2133
+ if (params.legacy !== undefined)
2134
+ searchParams.set('legacy', params.legacy.toString());
2135
+ const query = searchParams.toString();
2136
+ const suffix = query ? `?${query}` : '';
2137
+ const response = await this.makeRequest(`/shops/${shopId}/listings/active${suffix}`);
2138
+ return response.results;
2139
+ }
2140
+ async getFeaturedListingsByShop(shopId, params = {}) {
2141
+ const searchParams = new URLSearchParams();
2142
+ if (params.limit !== undefined)
2143
+ searchParams.set('limit', params.limit.toString());
2144
+ if (params.offset !== undefined)
2145
+ searchParams.set('offset', params.offset.toString());
2146
+ if (params.legacy !== undefined)
2147
+ searchParams.set('legacy', params.legacy.toString());
2148
+ const query = searchParams.toString();
2149
+ const suffix = query ? `?${query}` : '';
2150
+ const response = await this.makeRequest(`/shops/${shopId}/listings/featured${suffix}`);
2151
+ return response.results;
2152
+ }
2153
+ async getListingsByListingIds(params) {
2154
+ const searchParams = new URLSearchParams();
2155
+ searchParams.set('listing_ids', params.listing_ids.join(','));
2156
+ if (params.includes)
2157
+ searchParams.set('includes', params.includes.join(','));
2158
+ if (params.legacy !== undefined)
2159
+ searchParams.set('legacy', params.legacy.toString());
2160
+ const response = await this.makeRequest(`/listings/batch?${searchParams.toString()}`);
2161
+ return response.results;
2162
+ }
2163
+ async getListingsByShopReceipt(shopId, receiptId, params = {}) {
2164
+ const searchParams = new URLSearchParams();
2165
+ if (params.limit !== undefined)
2166
+ searchParams.set('limit', params.limit.toString());
2167
+ if (params.offset !== undefined)
2168
+ searchParams.set('offset', params.offset.toString());
2169
+ if (params.legacy !== undefined)
2170
+ searchParams.set('legacy', params.legacy.toString());
2171
+ const query = searchParams.toString();
2172
+ const suffix = query ? `?${query}` : '';
2173
+ const response = await this.makeRequest(`/shops/${shopId}/receipts/${receiptId}/listings${suffix}`);
2174
+ return response.results;
2175
+ }
2176
+ async getListingProperty(listingId, propertyId) {
2177
+ return this.makeRequest(`/listings/${listingId}/properties/${propertyId}`);
2178
+ }
2179
+ async deleteListingProperty(shopId, listingId, propertyId) {
2180
+ await this.makeRequest(`/shops/${shopId}/listings/${listingId}/properties/${propertyId}`, { method: 'DELETE' }, false);
2181
+ }
2182
+ async getListingProduct(listingId, productId) {
2183
+ return this.makeRequest(`/listings/${listingId}/inventory/products/${productId}`);
2184
+ }
2185
+ async getListingOffering(listingId, productId, offeringId) {
2186
+ return this.makeRequest(`/listings/${listingId}/products/${productId}/offerings/${offeringId}`);
2187
+ }
2188
+ async getListingsByShopSectionId(shopId, params) {
2189
+ const searchParams = new URLSearchParams();
2190
+ searchParams.set('shop_section_ids', params.shop_section_ids.join(','));
2191
+ if (params.limit !== undefined)
2192
+ searchParams.set('limit', params.limit.toString());
2193
+ if (params.offset !== undefined)
2194
+ searchParams.set('offset', params.offset.toString());
2195
+ if (params.sort_on)
2196
+ searchParams.set('sort_on', params.sort_on);
2197
+ if (params.sort_order)
2198
+ searchParams.set('sort_order', params.sort_order);
2199
+ if (params.legacy !== undefined)
2200
+ searchParams.set('legacy', params.legacy.toString());
2201
+ const response = await this.makeRequest(`/shops/${shopId}/shop-sections/listings?${searchParams.toString()}`);
2202
+ return response.results;
2203
+ }
2204
+ async getListingsByShopReturnPolicy(shopId, returnPolicyId, params = {}) {
2205
+ const searchParams = new URLSearchParams();
2206
+ if (params.legacy !== undefined)
2207
+ searchParams.set('legacy', params.legacy.toString());
2208
+ const query = searchParams.toString();
2209
+ const suffix = query ? `?${query}` : '';
2210
+ const response = await this.makeRequest(`/shops/${shopId}/policies/return/${returnPolicyId}/listings${suffix}`);
2211
+ return response.results;
2212
+ }
2213
+ async findShops(params) {
2214
+ const searchParams = new URLSearchParams();
2215
+ searchParams.set('shop_name', params.shop_name);
2216
+ if (params.limit !== undefined)
2217
+ searchParams.set('limit', params.limit.toString());
2218
+ if (params.offset !== undefined)
2219
+ searchParams.set('offset', params.offset.toString());
2220
+ const response = await this.makeRequest(`/shops?${searchParams.toString()}`);
2221
+ return response.results;
2222
+ }
2223
+ async createShopShippingProfileUpgrade(shopId, profileId, params) {
2224
+ const body = this.buildFormBody(params);
2225
+ return this.makeRequest(`/shops/${shopId}/shipping-profiles/${profileId}/upgrades`, {
2226
+ method: 'POST',
2227
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2228
+ body: body.toString()
2229
+ }, false);
2230
+ }
2231
+ async updateShopShippingProfileUpgrade(shopId, profileId, upgradeId, params) {
2232
+ const body = this.buildFormBody(params);
2233
+ return this.makeRequest(`/shops/${shopId}/shipping-profiles/${profileId}/upgrades/${upgradeId}`, {
2234
+ method: 'PUT',
2235
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2236
+ body: body.toString()
2237
+ }, false);
2238
+ }
2239
+ async deleteShopShippingProfileUpgrade(shopId, profileId, upgradeId) {
2240
+ await this.makeRequest(`/shops/${shopId}/shipping-profiles/${profileId}/upgrades/${upgradeId}`, { method: 'DELETE' }, false);
2241
+ }
2242
+ async getShippingCarriers(originCountryIso) {
2243
+ const searchParams = new URLSearchParams();
2244
+ searchParams.set('origin_country_iso', originCountryIso);
2245
+ const response = await this.makeRequest(`/shipping-carriers?${searchParams.toString()}`);
2246
+ return response.results;
2247
+ }
2248
+ async getShopReceiptTransactionsByListing(shopId, listingId, params = {}) {
2249
+ const searchParams = new URLSearchParams();
2250
+ if (params.limit !== undefined)
2251
+ searchParams.set('limit', params.limit.toString());
2252
+ if (params.offset !== undefined)
2253
+ searchParams.set('offset', params.offset.toString());
2254
+ if (params.legacy !== undefined)
2255
+ searchParams.set('legacy', params.legacy.toString());
2256
+ const query = searchParams.toString();
2257
+ const suffix = query ? `?${query}` : '';
2258
+ const response = await this.makeRequest(`/shops/${shopId}/listings/${listingId}/transactions${suffix}`);
2259
+ return response.results;
2260
+ }
2261
+ async getShopReceiptTransactionsByShop(shopId, params = {}) {
2262
+ const searchParams = new URLSearchParams();
2263
+ if (params.limit !== undefined)
2264
+ searchParams.set('limit', params.limit.toString());
2265
+ if (params.offset !== undefined)
2266
+ searchParams.set('offset', params.offset.toString());
2267
+ if (params.legacy !== undefined)
2268
+ searchParams.set('legacy', params.legacy.toString());
2269
+ const query = searchParams.toString();
2270
+ const suffix = query ? `?${query}` : '';
2271
+ const response = await this.makeRequest(`/shops/${shopId}/transactions${suffix}`);
2272
+ return response.results;
2273
+ }
2274
+ async getPaymentAccountLedgerEntryPayments(shopId, params) {
2275
+ const searchParams = new URLSearchParams();
2276
+ searchParams.set('ledger_entry_ids', params.ledger_entry_ids.join(','));
2277
+ const response = await this.makeRequest(`/shops/${shopId}/payment-account/ledger-entries/payments?${searchParams.toString()}`);
2278
+ return response.results;
2279
+ }
2280
+ async getShopPaymentByReceiptId(shopId, receiptId) {
2281
+ const response = await this.makeRequest(`/shops/${shopId}/receipts/${receiptId}/payments`);
2282
+ return response.results;
2283
+ }
2284
+ async getMe() {
2285
+ return this.makeRequest('/users/me');
2286
+ }
2287
+ async getUserAddresses() {
2288
+ const response = await this.makeRequest('/user/addresses');
2289
+ return response.results;
2290
+ }
2291
+ async getUserAddress(userAddressId) {
2292
+ return this.makeRequest(`/user/addresses/${userAddressId}`);
2293
+ }
2294
+ async deleteUserAddress(userAddressId) {
2295
+ await this.makeRequest(`/user/addresses/${userAddressId}`, { method: 'DELETE' }, false);
2296
+ }
2297
+ async getPropertiesByBuyerTaxonomyId(taxonomyId) {
2298
+ const response = await this.makeRequest(`/buyer-taxonomy/nodes/${taxonomyId}/properties`);
2299
+ return response.results;
2300
+ }
2301
+ async ping() {
2302
+ return this.makeRequest('/openapi-ping', {}, false);
2303
+ }
2304
+ async tokenScopes(params) {
2305
+ const body = this.buildFormBody(params);
2306
+ return this.makeRequest('/scopes', {
2307
+ method: 'POST',
2308
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2309
+ body: body.toString()
2310
+ }, false);
2311
+ }
1942
2312
  getRemainingRequests() {
1943
2313
  return this.rateLimiter.getRemainingRequests();
1944
2314
  }