@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/CHANGELOG.md +21 -12
- package/README.md +128 -128
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.esm.js +45 -24
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +1 -1
- package/dist/browser.umd.js.map +1 -1
- package/dist/index.cjs +48 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.esm.js +48 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/node.cjs +48 -25
- package/dist/node.cjs.map +1 -1
- package/dist/node.esm.js +48 -26
- package/dist/node.esm.js.map +1 -1
- package/package.json +1 -1
- package/dist/index.js +0 -8517
- package/dist/index.js.map +0 -1
- package/dist/index.umd.js +0 -1180
- package/dist/index.umd.js.map +0 -1
- package/dist/index.umd.min.js +0 -2
- package/dist/index.umd.min.js.map +0 -1
package/dist/browser.esm.js
CHANGED
|
@@ -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:
|
|
651
|
-
maxRequestsPerSecond:
|
|
652
|
-
minRequestInterval:
|
|
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
|
-
|
|
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 ||
|
|
1307
|
-
maxRequestsPerSecond: config.rateLimiting?.maxRequestsPerSecond ||
|
|
1308
|
-
minRequestInterval: config.rateLimiting?.minRequestInterval ??
|
|
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
|
-
|
|
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();
|
|
@@ -1401,11 +1415,7 @@ class EtsyClient {
|
|
|
1401
1415
|
if (value === undefined || value === null)
|
|
1402
1416
|
continue;
|
|
1403
1417
|
if (Array.isArray(value)) {
|
|
1404
|
-
|
|
1405
|
-
if (item === undefined || item === null)
|
|
1406
|
-
continue;
|
|
1407
|
-
body.append(key, String(item));
|
|
1408
|
-
}
|
|
1418
|
+
body.append(key, value.filter(item => item !== undefined && item !== null).map(String).join(','));
|
|
1409
1419
|
}
|
|
1410
1420
|
else {
|
|
1411
1421
|
body.append(key, String(value));
|
|
@@ -2545,9 +2555,9 @@ class GlobalRequestQueue {
|
|
|
2545
2555
|
this.requestCount = 0;
|
|
2546
2556
|
this.dailyReset = new Date();
|
|
2547
2557
|
this.lastRequestTime = 0;
|
|
2548
|
-
this.maxRequestsPerDay =
|
|
2549
|
-
this.maxRequestsPerSecond =
|
|
2550
|
-
this.minRequestInterval =
|
|
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;
|
|
2551
2561
|
this.setNextDailyReset();
|
|
2552
2562
|
}
|
|
2553
2563
|
static getInstance() {
|
|
@@ -2632,11 +2642,12 @@ class GlobalRequestQueue {
|
|
|
2632
2642
|
try {
|
|
2633
2643
|
let result;
|
|
2634
2644
|
if (item.timeout) {
|
|
2635
|
-
const
|
|
2645
|
+
const timeout = item.timeout;
|
|
2646
|
+
const remainingTimeout = timeout - elapsed;
|
|
2636
2647
|
let timeoutId;
|
|
2637
2648
|
const timeoutPromise = new Promise((_, reject) => {
|
|
2638
2649
|
timeoutId = setTimeout(() => {
|
|
2639
|
-
reject(new Error(`Request timeout after ${
|
|
2650
|
+
reject(new Error(`Request timeout after ${timeout}ms (exceeded during execution)`));
|
|
2640
2651
|
}, remainingTimeout);
|
|
2641
2652
|
if (timeoutId && typeof timeoutId.unref === 'function') {
|
|
2642
2653
|
timeoutId.unref();
|
|
@@ -2945,7 +2956,18 @@ class EtsyWebhookHandler {
|
|
|
2945
2956
|
}
|
|
2946
2957
|
}
|
|
2947
2958
|
parseEvent(payload) {
|
|
2948
|
-
|
|
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
|
+
}
|
|
2949
2971
|
if (!data.type || !data.data) {
|
|
2950
2972
|
throw new Error('Invalid webhook event format');
|
|
2951
2973
|
}
|
|
@@ -3335,7 +3357,6 @@ function createCacheStorage(config = {}) {
|
|
|
3335
3357
|
case 'lfu':
|
|
3336
3358
|
return new LFUCache(config);
|
|
3337
3359
|
case 'ttl':
|
|
3338
|
-
return new LRUCache(config);
|
|
3339
3360
|
default:
|
|
3340
3361
|
return new LRUCache(config);
|
|
3341
3362
|
}
|
|
@@ -4032,7 +4053,7 @@ function createCachingPlugin(config = {}) {
|
|
|
4032
4053
|
};
|
|
4033
4054
|
}
|
|
4034
4055
|
function createRateLimitPlugin(config = {}) {
|
|
4035
|
-
const maxRequestsPerSecond = config.maxRequestsPerSecond ||
|
|
4056
|
+
const maxRequestsPerSecond = config.maxRequestsPerSecond || ETSY_RATE_LIMITS.MAX_REQUESTS_PER_SECOND;
|
|
4036
4057
|
const requests = [];
|
|
4037
4058
|
return {
|
|
4038
4059
|
name: 'rateLimit',
|
|
@@ -4086,5 +4107,5 @@ function getLibraryInfo() {
|
|
|
4086
4107
|
};
|
|
4087
4108
|
}
|
|
4088
4109
|
|
|
4089
|
-
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 };
|
|
4090
4111
|
//# sourceMappingURL=browser.esm.js.map
|