@profplum700/etsy-v3-api-client 2.5.2 → 2.5.4

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.
package/dist/index.d.ts CHANGED
@@ -1571,6 +1571,11 @@ declare class FileTokenStorage implements TokenStorage {
1571
1571
  private _deleteFile;
1572
1572
  }
1573
1573
 
1574
+ declare const ETSY_RATE_LIMITS: {
1575
+ readonly MAX_REQUESTS_PER_DAY: 5000;
1576
+ readonly MAX_REQUESTS_PER_SECOND: 5;
1577
+ readonly MIN_REQUEST_INTERVAL: 200;
1578
+ };
1574
1579
  declare class EtsyRateLimiter {
1575
1580
  private requestCount;
1576
1581
  private dailyReset;
@@ -2081,5 +2086,5 @@ declare function getLibraryInfo(): {
2081
2086
  homepage: string;
2082
2087
  };
2083
2088
 
2084
- export { AuthHelper, BatchQueryExecutor, BulkOperationManager, COMMON_SCOPE_COMBINATIONS, CacheWithInvalidation, CreateListingSchema, DEFAULT_RETRY_CONFIG, ETSY_SCOPES, EncryptedFileTokenStorage, EtsyApiError, EtsyAuthError, EtsyClient, EtsyRateLimitError, EtsyRateLimiter, EtsyWebhookHandler, FieldValidator, FileTokenStorage, GlobalRequestQueue, LFUCache, LIBRARY_NAME, LRUCache, ListingQueryBuilder, LocalStorageTokenStorage, MemoryTokenStorage, PaginatedResults, PluginManager, ReceiptQueryBuilder, RedisCacheStorage, RetryManager, SecureTokenStorage, SessionStorageTokenStorage, TokenManager, UpdateListingSchema, UpdateShopSchema, VERSION, ValidationException, Validator, WebhookSecurity, combineValidators, createAnalyticsPlugin, createAuthHelper, createBatchQuery, createBulkOperationManager, createCacheStorage, createCacheWithInvalidation, createCachingPlugin, createCodeChallenge, createDefaultTokenStorage, createEtsyClient, createListingQuery, createLoggingPlugin, createPaginatedResults, createRateLimitPlugin, createRateLimiter, createReceiptQuery, createRedisCacheStorage, createRetryPlugin, createTokenManager, createValidator, createWebhookHandler, createWebhookSecurity, decryptAES256GCM, EtsyClient as default, defaultRateLimiter, deriveKeyFromPassword, encryptAES256GCM, executeBulkOperation, field, generateCodeVerifier, generateEncryptionKey, generateRandomBase64Url, generateState, getAvailableStorage, getEnvironmentInfo, getGlobalQueue, getLibraryInfo, hasLocalStorage, hasSessionStorage, isBrowser, isNode, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
2089
+ export { AuthHelper, BatchQueryExecutor, BulkOperationManager, COMMON_SCOPE_COMBINATIONS, CacheWithInvalidation, CreateListingSchema, DEFAULT_RETRY_CONFIG, ETSY_RATE_LIMITS, ETSY_SCOPES, EncryptedFileTokenStorage, EtsyApiError, EtsyAuthError, EtsyClient, EtsyRateLimitError, EtsyRateLimiter, EtsyWebhookHandler, FieldValidator, FileTokenStorage, GlobalRequestQueue, LFUCache, LIBRARY_NAME, LRUCache, ListingQueryBuilder, LocalStorageTokenStorage, MemoryTokenStorage, PaginatedResults, PluginManager, ReceiptQueryBuilder, RedisCacheStorage, RetryManager, SecureTokenStorage, SessionStorageTokenStorage, TokenManager, UpdateListingSchema, UpdateShopSchema, VERSION, ValidationException, Validator, WebhookSecurity, combineValidators, createAnalyticsPlugin, createAuthHelper, createBatchQuery, createBulkOperationManager, createCacheStorage, createCacheWithInvalidation, createCachingPlugin, createCodeChallenge, createDefaultTokenStorage, createEtsyClient, createListingQuery, createLoggingPlugin, createPaginatedResults, createRateLimitPlugin, createRateLimiter, createReceiptQuery, createRedisCacheStorage, createRetryPlugin, createTokenManager, createValidator, createWebhookHandler, createWebhookSecurity, decryptAES256GCM, EtsyClient as default, defaultRateLimiter, deriveKeyFromPassword, encryptAES256GCM, executeBulkOperation, field, generateCodeVerifier, generateEncryptionKey, generateRandomBase64Url, generateState, getAvailableStorage, getEnvironmentInfo, getGlobalQueue, getLibraryInfo, hasLocalStorage, hasSessionStorage, isBrowser, isNode, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
2085
2090
  export type { AdvancedCachingConfig, AnalyticsPluginConfig, ApproachingLimitCallback, AuthHelperConfig, BulkImageUploadOperation, BulkOperationConfig, BulkOperationError, BulkOperationResult, BulkOperationSummary, BulkUpdateListingOperation, CacheEntry, CacheStats, CacheStorage, CacheStrategy, CachingPluginConfig, ConsolidateReturnPoliciesParams, CreateDraftListingParams, CreateListingTranslationParams, CreateReadinessStateParams, CreateReceiptShipmentParams, CreateReturnPolicyParams, CreateShippingProfileDestinationParams, CreateShippingProfileParams, CreateShippingProfileUpgradeParams, CreateShopSectionParams, EncryptedData, EncryptedStorageConfig, EtsyApiResponse, EtsyBuyerTaxonomyNode, EtsyBuyerTaxonomyProperty, EtsyBuyerTaxonomyPropertyScale, EtsyBuyerTaxonomyPropertyValue, EtsyClientConfig, EtsyClientWithQueryBuilder, EtsyErrorDetails, EtsyListing, EtsyListingFile, EtsyListingImage, EtsyListingInventory, EtsyListingOffering, EtsyListingProduct, EtsyListingProperty, EtsyListingPropertyScale, EtsyListingPropertyValue, EtsyListingTranslation, EtsyListingVariationImage, EtsyListingVideo, EtsyPagination, EtsyPayment, EtsyPaymentAccountLedgerEntry, EtsyPaymentAdjustment, EtsyPlugin, EtsyRateLimitHeaders, EtsyReview, EtsySellerTaxonomyNode, EtsyShippingCarrier, EtsyShippingCarrierMailClass, EtsyShippingProfile, EtsyShippingProfileDestination, EtsyShippingProfileUpgrade, EtsyShop, EtsyShopHolidayPreference, EtsyShopProcessingProfile, EtsyShopProductionPartner, EtsyShopReceipt, EtsyShopReceiptShipment, EtsyShopReceiptTransaction, EtsyShopRefund, EtsyShopReturnPolicy, EtsyShopSection, EtsyTokenResponse, EtsyTokens, EtsyTransactionVariation, EtsyUser, EtsyUserAddress, EtsyWebhookEvent, EtsyWebhookEventType, FindActiveListingsByShopParams, FindShopsParams, GetFeaturedListingsParams, GetLedgerEntryPaymentsParams, GetListingsByIdsParams, GetListingsByReturnPolicyParams, GetListingsBySectionParams, GetListingsByShopReceiptParams, GetPaymentAccountLedgerEntriesParams, GetReadinessStateParams, GetReviewsParams, GetShopReceiptsParams, GetTransactionsByListingParams, GetTransactionsByShopParams, ListingParams, ListingSortOn, ListingState, LoggerInterface, LoggingPluginConfig, PageFetcher, PaginationOptions, PluginRequestConfig, PluginResponse, QueueOptions, RateLimitConfig, RateLimitErrorType, RateLimitPluginConfig, RateLimitStatus, RedisClientLike, RedisConfig, RequestPriority, RetryConfig, RetryOptions, RetryPluginConfig, SearchParams, SecureTokenStorageConfig, SortOrder, TokenRefreshCallback, TokenRotationCallback, TokenRotationConfig, TokenScopesParams, TokenScopesResponse, TokenStorage, UpdateHolidayPreferencesParams, UpdateListingInventoryParams, UpdateListingParams, UpdateListingPropertyParams, UpdateListingTranslationParams, UpdateReadinessStateParams, UpdateReturnPolicyParams, UpdateShippingProfileDestinationParams, UpdateShippingProfileParams, UpdateShippingProfileUpgradeParams, UpdateShopParams, UpdateShopReceiptParams, UpdateShopSectionParams, UpdateVariationImagesParams, UploadListingFileParams, UploadListingImageParams, ValidationError, ValidationOptions, ValidationResult, ValidationSchema, ValidatorFunction, WebhookConfig, WebhookEventHandler, WebhookSecurityConfig };
package/dist/index.esm.js CHANGED
@@ -673,6 +673,11 @@ class FileTokenStorage {
673
673
  }
674
674
  }
675
675
 
676
+ const ETSY_RATE_LIMITS = {
677
+ MAX_REQUESTS_PER_DAY: 5000,
678
+ MAX_REQUESTS_PER_SECOND: 5,
679
+ MIN_REQUEST_INTERVAL: 200,
680
+ };
676
681
  class EtsyRateLimiter {
677
682
  constructor(config) {
678
683
  this.requestCount = 0;
@@ -681,9 +686,9 @@ class EtsyRateLimiter {
681
686
  this.isHeaderBasedLimiting = false;
682
687
  this.currentRetryCount = 0;
683
688
  this.config = {
684
- maxRequestsPerDay: 10000,
685
- maxRequestsPerSecond: 10,
686
- minRequestInterval: 100,
689
+ maxRequestsPerDay: ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY,
690
+ maxRequestsPerSecond: ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND,
691
+ minRequestInterval: ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL,
687
692
  maxRetries: 3,
688
693
  baseDelayMs: 1000,
689
694
  maxDelayMs: 30000,
@@ -738,7 +743,7 @@ class EtsyRateLimiter {
738
743
  if (value === null)
739
744
  return undefined;
740
745
  const num = parseInt(value, 10);
741
- return isNaN(num) ? undefined : num;
746
+ return Number.isNaN(num) ? undefined : num;
742
747
  };
743
748
  return {
744
749
  limitPerSecond: parseNumber(getHeader('x-limit-per-second')),
@@ -1079,7 +1084,7 @@ class FieldValidator {
1079
1084
  const value = data[this.field];
1080
1085
  if (value === undefined || value === null)
1081
1086
  return null;
1082
- if (typeof value !== 'number' || isNaN(value)) {
1087
+ if (typeof value !== 'number' || Number.isNaN(value)) {
1083
1088
  return {
1084
1089
  field: this.field,
1085
1090
  message: options.message || `${this.field} must be a number`,
@@ -1288,9 +1293,14 @@ function combineValidators(...validators) {
1288
1293
 
1289
1294
  class DefaultLogger {
1290
1295
  debug(message, ...args) {
1291
- const isDevelopment = isNode$1
1292
- ? process.env.NODE_ENV === 'development'
1293
- : window.location?.hostname === 'localhost' || window.location?.hostname === '127.0.0.1';
1296
+ let isDevelopment;
1297
+ if (isNode$1) {
1298
+ isDevelopment = process.env.NODE_ENV === 'development';
1299
+ }
1300
+ else {
1301
+ const host = window.location?.hostname;
1302
+ isDevelopment = host === 'localhost' || host === '127.0.0.1';
1303
+ }
1294
1304
  if (isDevelopment) {
1295
1305
  console.log(`[DEBUG] ${message}`, ...args);
1296
1306
  }
@@ -1339,9 +1349,9 @@ class EtsyClient {
1339
1349
  this.sharedSecret = config.sharedSecret;
1340
1350
  if (config.rateLimiting?.enabled !== false) {
1341
1351
  this.rateLimiter = new EtsyRateLimiter({
1342
- maxRequestsPerDay: config.rateLimiting?.maxRequestsPerDay || 10000,
1343
- maxRequestsPerSecond: config.rateLimiting?.maxRequestsPerSecond || 10,
1344
- minRequestInterval: config.rateLimiting?.minRequestInterval ?? 100,
1352
+ maxRequestsPerDay: config.rateLimiting?.maxRequestsPerDay || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY,
1353
+ maxRequestsPerSecond: config.rateLimiting?.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND,
1354
+ minRequestInterval: config.rateLimiting?.minRequestInterval ?? ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL,
1345
1355
  maxRetries: config.rateLimiting?.maxRetries,
1346
1356
  baseDelayMs: config.rateLimiting?.baseDelayMs,
1347
1357
  maxDelayMs: config.rateLimiting?.maxDelayMs,
@@ -1372,7 +1382,12 @@ class EtsyClient {
1372
1382
  if (useCache && this.cache && requestOptions.method === 'GET') {
1373
1383
  const cached = await this.cache.get(cacheKey);
1374
1384
  if (cached) {
1375
- return JSON.parse(cached);
1385
+ try {
1386
+ return JSON.parse(cached);
1387
+ }
1388
+ catch {
1389
+ await this.cache.delete(cacheKey);
1390
+ }
1376
1391
  }
1377
1392
  }
1378
1393
  await this.rateLimiter.waitForRateLimit();
@@ -1437,11 +1452,7 @@ class EtsyClient {
1437
1452
  if (value === undefined || value === null)
1438
1453
  continue;
1439
1454
  if (Array.isArray(value)) {
1440
- for (const item of value) {
1441
- if (item === undefined || item === null)
1442
- continue;
1443
- body.append(key, String(item));
1444
- }
1455
+ body.append(key, value.filter(item => item !== undefined && item !== null).map(String).join(','));
1445
1456
  }
1446
1457
  else {
1447
1458
  body.append(key, String(value));
@@ -2606,9 +2617,9 @@ class GlobalRequestQueue {
2606
2617
  this.requestCount = 0;
2607
2618
  this.dailyReset = new Date();
2608
2619
  this.lastRequestTime = 0;
2609
- this.maxRequestsPerDay = 10000;
2610
- this.maxRequestsPerSecond = 10;
2611
- this.minRequestInterval = 100;
2620
+ this.maxRequestsPerDay = ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY;
2621
+ this.maxRequestsPerSecond = ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
2622
+ this.minRequestInterval = ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL;
2612
2623
  this.setNextDailyReset();
2613
2624
  }
2614
2625
  static getInstance() {
@@ -2693,11 +2704,12 @@ class GlobalRequestQueue {
2693
2704
  try {
2694
2705
  let result;
2695
2706
  if (item.timeout) {
2696
- const remainingTimeout = item.timeout - elapsed;
2707
+ const timeout = item.timeout;
2708
+ const remainingTimeout = timeout - elapsed;
2697
2709
  let timeoutId;
2698
2710
  const timeoutPromise = new Promise((_, reject) => {
2699
2711
  timeoutId = setTimeout(() => {
2700
- reject(new Error(`Request timeout after ${item.timeout}ms (exceeded during execution)`));
2712
+ reject(new Error(`Request timeout after ${timeout}ms (exceeded during execution)`));
2701
2713
  }, remainingTimeout);
2702
2714
  if (timeoutId && typeof timeoutId.unref === 'function') {
2703
2715
  timeoutId.unref();
@@ -3014,7 +3026,18 @@ class EtsyWebhookHandler {
3014
3026
  }
3015
3027
  }
3016
3028
  parseEvent(payload) {
3017
- const data = typeof payload === 'string' ? JSON.parse(payload) : payload;
3029
+ let data;
3030
+ if (typeof payload === 'string') {
3031
+ try {
3032
+ data = JSON.parse(payload);
3033
+ }
3034
+ catch {
3035
+ throw new Error('Invalid webhook payload: malformed JSON');
3036
+ }
3037
+ }
3038
+ else {
3039
+ data = payload;
3040
+ }
3018
3041
  if (!data.type || !data.data) {
3019
3042
  throw new Error('Invalid webhook event format');
3020
3043
  }
@@ -3404,7 +3427,6 @@ function createCacheStorage(config = {}) {
3404
3427
  case 'lfu':
3405
3428
  return new LFUCache(config);
3406
3429
  case 'ttl':
3407
- return new LRUCache(config);
3408
3430
  default:
3409
3431
  return new LRUCache(config);
3410
3432
  }
@@ -4219,7 +4241,7 @@ function createCachingPlugin(config = {}) {
4219
4241
  };
4220
4242
  }
4221
4243
  function createRateLimitPlugin(config = {}) {
4222
- const maxRequestsPerSecond = config.maxRequestsPerSecond || 10;
4244
+ const maxRequestsPerSecond = config.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
4223
4245
  const requests = [];
4224
4246
  return {
4225
4247
  name: 'rateLimit',
@@ -4273,5 +4295,5 @@ function getLibraryInfo() {
4273
4295
  };
4274
4296
  }
4275
4297
 
4276
- export { AuthHelper, BatchQueryExecutor, BulkOperationManager, COMMON_SCOPE_COMBINATIONS, CacheWithInvalidation, CreateListingSchema, DEFAULT_RETRY_CONFIG, ETSY_SCOPES, EncryptedFileTokenStorage, EtsyApiError, EtsyAuthError, EtsyClient, EtsyRateLimitError, EtsyRateLimiter, EtsyWebhookHandler, FieldValidator, FileTokenStorage, GlobalRequestQueue, LFUCache, LIBRARY_NAME, LRUCache, ListingQueryBuilder, LocalStorageTokenStorage, MemoryTokenStorage, PaginatedResults, PluginManager, ReceiptQueryBuilder, RedisCacheStorage, RetryManager, SecureTokenStorage, SessionStorageTokenStorage, TokenManager, UpdateListingSchema, UpdateShopSchema, VERSION, ValidationException, Validator, WebhookSecurity, combineValidators, createAnalyticsPlugin, createAuthHelper, createBatchQuery, createBulkOperationManager, createCacheStorage, createCacheWithInvalidation, createCachingPlugin, createCodeChallenge, createDefaultTokenStorage, createEtsyClient, createListingQuery, createLoggingPlugin, createPaginatedResults, createRateLimitPlugin, createRateLimiter, createReceiptQuery, createRedisCacheStorage, createRetryPlugin, createTokenManager, createValidator, createWebhookHandler, createWebhookSecurity, decryptAES256GCM, EtsyClient as default, defaultRateLimiter, deriveKeyFromPassword, encryptAES256GCM, executeBulkOperation, field, generateCodeVerifier, generateEncryptionKey, generateRandomBase64Url, generateState, getAvailableStorage, getEnvironmentInfo, getGlobalQueue, getLibraryInfo, hasLocalStorage, hasSessionStorage, isBrowser$1 as isBrowser, isNode$1 as isNode, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
4298
+ export { AuthHelper, BatchQueryExecutor, BulkOperationManager, COMMON_SCOPE_COMBINATIONS, CacheWithInvalidation, CreateListingSchema, DEFAULT_RETRY_CONFIG, ETSY_RATE_LIMITS, ETSY_SCOPES, EncryptedFileTokenStorage, EtsyApiError, EtsyAuthError, EtsyClient, EtsyRateLimitError, EtsyRateLimiter, EtsyWebhookHandler, FieldValidator, FileTokenStorage, GlobalRequestQueue, LFUCache, LIBRARY_NAME, LRUCache, ListingQueryBuilder, LocalStorageTokenStorage, MemoryTokenStorage, PaginatedResults, PluginManager, ReceiptQueryBuilder, RedisCacheStorage, RetryManager, SecureTokenStorage, SessionStorageTokenStorage, TokenManager, UpdateListingSchema, UpdateShopSchema, VERSION, ValidationException, Validator, WebhookSecurity, combineValidators, createAnalyticsPlugin, createAuthHelper, createBatchQuery, createBulkOperationManager, createCacheStorage, createCacheWithInvalidation, createCachingPlugin, createCodeChallenge, createDefaultTokenStorage, createEtsyClient, createListingQuery, createLoggingPlugin, createPaginatedResults, createRateLimitPlugin, createRateLimiter, createReceiptQuery, createRedisCacheStorage, createRetryPlugin, createTokenManager, createValidator, createWebhookHandler, createWebhookSecurity, decryptAES256GCM, EtsyClient as default, defaultRateLimiter, deriveKeyFromPassword, encryptAES256GCM, executeBulkOperation, field, generateCodeVerifier, generateEncryptionKey, generateRandomBase64Url, generateState, getAvailableStorage, getEnvironmentInfo, getGlobalQueue, getLibraryInfo, hasLocalStorage, hasSessionStorage, isBrowser$1 as isBrowser, isNode$1 as isNode, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
4277
4299
  //# sourceMappingURL=index.esm.js.map