@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.
package/dist/node.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();
@@ -2602,9 +2617,9 @@ class GlobalRequestQueue {
2602
2617
  this.requestCount = 0;
2603
2618
  this.dailyReset = new Date();
2604
2619
  this.lastRequestTime = 0;
2605
- this.maxRequestsPerDay = 10000;
2606
- this.maxRequestsPerSecond = 10;
2607
- 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;
2608
2623
  this.setNextDailyReset();
2609
2624
  }
2610
2625
  static getInstance() {
@@ -2689,11 +2704,12 @@ class GlobalRequestQueue {
2689
2704
  try {
2690
2705
  let result;
2691
2706
  if (item.timeout) {
2692
- const remainingTimeout = item.timeout - elapsed;
2707
+ const timeout = item.timeout;
2708
+ const remainingTimeout = timeout - elapsed;
2693
2709
  let timeoutId;
2694
2710
  const timeoutPromise = new Promise((_, reject) => {
2695
2711
  timeoutId = setTimeout(() => {
2696
- reject(new Error(`Request timeout after ${item.timeout}ms (exceeded during execution)`));
2712
+ reject(new Error(`Request timeout after ${timeout}ms (exceeded during execution)`));
2697
2713
  }, remainingTimeout);
2698
2714
  if (timeoutId && typeof timeoutId.unref === 'function') {
2699
2715
  timeoutId.unref();
@@ -3010,7 +3026,18 @@ class EtsyWebhookHandler {
3010
3026
  }
3011
3027
  }
3012
3028
  parseEvent(payload) {
3013
- 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
+ }
3014
3041
  if (!data.type || !data.data) {
3015
3042
  throw new Error('Invalid webhook event format');
3016
3043
  }
@@ -3400,7 +3427,6 @@ function createCacheStorage(config = {}) {
3400
3427
  case 'lfu':
3401
3428
  return new LFUCache(config);
3402
3429
  case 'ttl':
3403
- return new LRUCache(config);
3404
3430
  default:
3405
3431
  return new LRUCache(config);
3406
3432
  }
@@ -4215,7 +4241,7 @@ function createCachingPlugin(config = {}) {
4215
4241
  };
4216
4242
  }
4217
4243
  function createRateLimitPlugin(config = {}) {
4218
- const maxRequestsPerSecond = config.maxRequestsPerSecond || 10;
4244
+ const maxRequestsPerSecond = config.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
4219
4245
  const requests = [];
4220
4246
  return {
4221
4247
  name: 'rateLimit',
@@ -4269,5 +4295,5 @@ function getLibraryInfo() {
4269
4295
  };
4270
4296
  }
4271
4297
 
4272
- 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 };
4273
4299
  //# sourceMappingURL=node.esm.js.map