@profplum700/etsy-v3-api-client 2.5.3 → 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.
@@ -639,6 +639,11 @@ class FileTokenStorage {
639
639
  }
640
640
  }
641
641
 
642
+ const ETSY_RATE_LIMITS = {
643
+ MAX_REQUESTS_PER_DAY: 5000,
644
+ MAX_REQUESTS_PER_SECOND: 5,
645
+ MIN_REQUEST_INTERVAL: 200,
646
+ };
642
647
  class EtsyRateLimiter {
643
648
  constructor(config) {
644
649
  this.requestCount = 0;
@@ -647,9 +652,9 @@ class EtsyRateLimiter {
647
652
  this.isHeaderBasedLimiting = false;
648
653
  this.currentRetryCount = 0;
649
654
  this.config = {
650
- maxRequestsPerDay: 10000,
651
- maxRequestsPerSecond: 10,
652
- minRequestInterval: 100,
655
+ maxRequestsPerDay: ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY,
656
+ maxRequestsPerSecond: ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND,
657
+ minRequestInterval: ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL,
653
658
  maxRetries: 3,
654
659
  baseDelayMs: 1000,
655
660
  maxDelayMs: 30000,
@@ -704,7 +709,7 @@ class EtsyRateLimiter {
704
709
  if (value === null)
705
710
  return undefined;
706
711
  const num = parseInt(value, 10);
707
- return isNaN(num) ? undefined : num;
712
+ return Number.isNaN(num) ? undefined : num;
708
713
  };
709
714
  return {
710
715
  limitPerSecond: parseNumber(getHeader('x-limit-per-second')),
@@ -1045,7 +1050,7 @@ class FieldValidator {
1045
1050
  const value = data[this.field];
1046
1051
  if (value === undefined || value === null)
1047
1052
  return null;
1048
- if (typeof value !== 'number' || isNaN(value)) {
1053
+ if (typeof value !== 'number' || Number.isNaN(value)) {
1049
1054
  return {
1050
1055
  field: this.field,
1051
1056
  message: options.message || `${this.field} must be a number`,
@@ -1254,7 +1259,11 @@ function combineValidators(...validators) {
1254
1259
 
1255
1260
  class DefaultLogger {
1256
1261
  debug(message, ...args) {
1257
- const isDevelopment = window.location?.hostname === 'localhost' || window.location?.hostname === '127.0.0.1';
1262
+ let isDevelopment;
1263
+ {
1264
+ const host = window.location?.hostname;
1265
+ isDevelopment = host === 'localhost' || host === '127.0.0.1';
1266
+ }
1258
1267
  if (isDevelopment) {
1259
1268
  console.log(`[DEBUG] ${message}`, ...args);
1260
1269
  }
@@ -1303,9 +1312,9 @@ class EtsyClient {
1303
1312
  this.sharedSecret = config.sharedSecret;
1304
1313
  if (config.rateLimiting?.enabled !== false) {
1305
1314
  this.rateLimiter = new EtsyRateLimiter({
1306
- maxRequestsPerDay: config.rateLimiting?.maxRequestsPerDay || 10000,
1307
- maxRequestsPerSecond: config.rateLimiting?.maxRequestsPerSecond || 10,
1308
- minRequestInterval: config.rateLimiting?.minRequestInterval ?? 100,
1315
+ maxRequestsPerDay: config.rateLimiting?.maxRequestsPerDay || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY,
1316
+ maxRequestsPerSecond: config.rateLimiting?.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND,
1317
+ minRequestInterval: config.rateLimiting?.minRequestInterval ?? ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL,
1309
1318
  maxRetries: config.rateLimiting?.maxRetries,
1310
1319
  baseDelayMs: config.rateLimiting?.baseDelayMs,
1311
1320
  maxDelayMs: config.rateLimiting?.maxDelayMs,
@@ -1336,7 +1345,12 @@ class EtsyClient {
1336
1345
  if (useCache && this.cache && requestOptions.method === 'GET') {
1337
1346
  const cached = await this.cache.get(cacheKey);
1338
1347
  if (cached) {
1339
- return JSON.parse(cached);
1348
+ try {
1349
+ return JSON.parse(cached);
1350
+ }
1351
+ catch {
1352
+ await this.cache.delete(cacheKey);
1353
+ }
1340
1354
  }
1341
1355
  }
1342
1356
  await this.rateLimiter.waitForRateLimit();
@@ -2541,9 +2555,9 @@ class GlobalRequestQueue {
2541
2555
  this.requestCount = 0;
2542
2556
  this.dailyReset = new Date();
2543
2557
  this.lastRequestTime = 0;
2544
- this.maxRequestsPerDay = 10000;
2545
- this.maxRequestsPerSecond = 10;
2546
- this.minRequestInterval = 100;
2558
+ this.maxRequestsPerDay = ETSY_RATE_LIMITS.MAX_REQUESTS_PER_DAY;
2559
+ this.maxRequestsPerSecond = ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
2560
+ this.minRequestInterval = ETSY_RATE_LIMITS.MIN_REQUEST_INTERVAL;
2547
2561
  this.setNextDailyReset();
2548
2562
  }
2549
2563
  static getInstance() {
@@ -2628,11 +2642,12 @@ class GlobalRequestQueue {
2628
2642
  try {
2629
2643
  let result;
2630
2644
  if (item.timeout) {
2631
- const remainingTimeout = item.timeout - elapsed;
2645
+ const timeout = item.timeout;
2646
+ const remainingTimeout = timeout - elapsed;
2632
2647
  let timeoutId;
2633
2648
  const timeoutPromise = new Promise((_, reject) => {
2634
2649
  timeoutId = setTimeout(() => {
2635
- reject(new Error(`Request timeout after ${item.timeout}ms (exceeded during execution)`));
2650
+ reject(new Error(`Request timeout after ${timeout}ms (exceeded during execution)`));
2636
2651
  }, remainingTimeout);
2637
2652
  if (timeoutId && typeof timeoutId.unref === 'function') {
2638
2653
  timeoutId.unref();
@@ -2941,7 +2956,18 @@ class EtsyWebhookHandler {
2941
2956
  }
2942
2957
  }
2943
2958
  parseEvent(payload) {
2944
- const data = typeof payload === 'string' ? JSON.parse(payload) : payload;
2959
+ let data;
2960
+ if (typeof payload === 'string') {
2961
+ try {
2962
+ data = JSON.parse(payload);
2963
+ }
2964
+ catch {
2965
+ throw new Error('Invalid webhook payload: malformed JSON');
2966
+ }
2967
+ }
2968
+ else {
2969
+ data = payload;
2970
+ }
2945
2971
  if (!data.type || !data.data) {
2946
2972
  throw new Error('Invalid webhook event format');
2947
2973
  }
@@ -3331,7 +3357,6 @@ function createCacheStorage(config = {}) {
3331
3357
  case 'lfu':
3332
3358
  return new LFUCache(config);
3333
3359
  case 'ttl':
3334
- return new LRUCache(config);
3335
3360
  default:
3336
3361
  return new LRUCache(config);
3337
3362
  }
@@ -4028,7 +4053,7 @@ function createCachingPlugin(config = {}) {
4028
4053
  };
4029
4054
  }
4030
4055
  function createRateLimitPlugin(config = {}) {
4031
- const maxRequestsPerSecond = config.maxRequestsPerSecond || 10;
4056
+ const maxRequestsPerSecond = config.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
4032
4057
  const requests = [];
4033
4058
  return {
4034
4059
  name: 'rateLimit',
@@ -4082,5 +4107,5 @@ function getLibraryInfo() {
4082
4107
  };
4083
4108
  }
4084
4109
 
4085
- 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, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
4110
+ 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, isSecureStorageSupported, sha256, sha256Base64Url, validate, validateEncryptionKey, validateOrThrow, withQueryBuilder, withQueue, withRetry };
4086
4111
  //# sourceMappingURL=browser.esm.js.map