@thirdweb-dev/service-utils 0.0.0-dev-92be883-20230913130717 → 0.0.0-dev-2ae1b19-20230914085726
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/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +1 -1
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +1 -1
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +2 -2
- package/dist/declarations/src/core/rateLimit/index.d.ts.map +1 -1
- package/dist/{index-21ba31a2.cjs.prod.js → index-2a4bc395.cjs.prod.js} +15 -8
- package/dist/{index-524baaec.esm.js → index-79984a5a.esm.js} +15 -8
- package/dist/{index-4e1ffe00.cjs.dev.js → index-8be280f0.cjs.dev.js} +15 -8
- package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +1 -1
- package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +1 -1
- package/node/dist/thirdweb-dev-service-utils-node.esm.js +2 -2
- package/package.json +1 -1
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-8be280f0.cjs.dev.js');
|
6
6
|
var aws4fetch = require('aws4fetch');
|
7
7
|
var zod = require('zod');
|
8
8
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-2a4bc395.cjs.prod.js');
|
6
6
|
var aws4fetch = require('aws4fetch');
|
7
7
|
var zod = require('zod');
|
8
8
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { a as authorize, r as rateLimit } from '../../dist/index-
|
2
|
-
export { r as rateLimit, u as usageLimit } from '../../dist/index-
|
1
|
+
import { a as authorize, r as rateLimit } from '../../dist/index-79984a5a.esm.js';
|
2
|
+
export { r as rateLimit, u as usageLimit } from '../../dist/index-79984a5a.esm.js';
|
3
3
|
import { AwsClient } from 'aws4fetch';
|
4
4
|
import { z } from 'zod';
|
5
5
|
export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAuB,MAAM,QAAQ,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAuB,MAAM,QAAQ,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK1C,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClD,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAChE,CAAC;AAEF,wBAAsB,SAAS,CAC7B,UAAU,EAAE,cAAc,EAC1B,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,eAAe,CAAC,CA2C1B"}
|
@@ -441,6 +441,8 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
441
441
|
}
|
442
442
|
|
443
443
|
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
444
|
+
const HARD_LIMIT_MULTIPLE = 2; // 2x of allowed limit
|
445
|
+
|
444
446
|
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
445
447
|
const {
|
446
448
|
id,
|
@@ -465,15 +467,20 @@ async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
|
465
467
|
const current = value + 1;
|
466
468
|
|
467
469
|
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
468
|
-
|
470
|
+
const limitWindow = limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
471
|
+
if (current > limitWindow) {
|
469
472
|
// report rate limit hits
|
470
473
|
await updateRateLimitedAt(id, serviceConfig);
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
474
|
+
|
475
|
+
// actually rate limit only when reached hard limit
|
476
|
+
if (current > limitWindow * HARD_LIMIT_MULTIPLE) {
|
477
|
+
return {
|
478
|
+
rateLimited: true,
|
479
|
+
status: 429,
|
480
|
+
errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limit} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
|
481
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
482
|
+
};
|
483
|
+
}
|
477
484
|
} else {
|
478
485
|
await cacheOptions.put(key, current.toString());
|
479
486
|
}
|
@@ -500,7 +507,7 @@ async function usageLimit(apiKeyMeta, serviceConfig) {
|
|
500
507
|
if (serviceScope === "storage" && (usage.storage?.sumFileSizeBytes || 0) > limit) {
|
501
508
|
return {
|
502
509
|
usageLimited: true,
|
503
|
-
status:
|
510
|
+
status: 403,
|
504
511
|
errorMessage: `You've used all of your total usage limit for Storage Pinning. Please add your payment method at https://thirdweb.com/dashboard/settings/billing.`,
|
505
512
|
errorCode: "PAYMENT_METHOD_REQUIRED"
|
506
513
|
};
|
@@ -439,6 +439,8 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
439
439
|
}
|
440
440
|
|
441
441
|
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
442
|
+
const HARD_LIMIT_MULTIPLE = 2; // 2x of allowed limit
|
443
|
+
|
442
444
|
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
443
445
|
const {
|
444
446
|
id,
|
@@ -463,15 +465,20 @@ async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
|
463
465
|
const current = value + 1;
|
464
466
|
|
465
467
|
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
466
|
-
|
468
|
+
const limitWindow = limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
469
|
+
if (current > limitWindow) {
|
467
470
|
// report rate limit hits
|
468
471
|
await updateRateLimitedAt(id, serviceConfig);
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
472
|
+
|
473
|
+
// actually rate limit only when reached hard limit
|
474
|
+
if (current > limitWindow * HARD_LIMIT_MULTIPLE) {
|
475
|
+
return {
|
476
|
+
rateLimited: true,
|
477
|
+
status: 429,
|
478
|
+
errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limit} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
|
479
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
480
|
+
};
|
481
|
+
}
|
475
482
|
} else {
|
476
483
|
await cacheOptions.put(key, current.toString());
|
477
484
|
}
|
@@ -498,7 +505,7 @@ async function usageLimit(apiKeyMeta, serviceConfig) {
|
|
498
505
|
if (serviceScope === "storage" && (usage.storage?.sumFileSizeBytes || 0) > limit) {
|
499
506
|
return {
|
500
507
|
usageLimited: true,
|
501
|
-
status:
|
508
|
+
status: 403,
|
502
509
|
errorMessage: `You've used all of your total usage limit for Storage Pinning. Please add your payment method at https://thirdweb.com/dashboard/settings/billing.`,
|
503
510
|
errorCode: "PAYMENT_METHOD_REQUIRED"
|
504
511
|
};
|
@@ -441,6 +441,8 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
441
441
|
}
|
442
442
|
|
443
443
|
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
444
|
+
const HARD_LIMIT_MULTIPLE = 2; // 2x of allowed limit
|
445
|
+
|
444
446
|
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
445
447
|
const {
|
446
448
|
id,
|
@@ -465,15 +467,20 @@ async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
|
465
467
|
const current = value + 1;
|
466
468
|
|
467
469
|
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
468
|
-
|
470
|
+
const limitWindow = limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
471
|
+
if (current > limitWindow) {
|
469
472
|
// report rate limit hits
|
470
473
|
await updateRateLimitedAt(id, serviceConfig);
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
474
|
+
|
475
|
+
// actually rate limit only when reached hard limit
|
476
|
+
if (current > limitWindow * HARD_LIMIT_MULTIPLE) {
|
477
|
+
return {
|
478
|
+
rateLimited: true,
|
479
|
+
status: 429,
|
480
|
+
errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limit} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
|
481
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
482
|
+
};
|
483
|
+
}
|
477
484
|
} else {
|
478
485
|
await cacheOptions.put(key, current.toString());
|
479
486
|
}
|
@@ -500,7 +507,7 @@ async function usageLimit(apiKeyMeta, serviceConfig) {
|
|
500
507
|
if (serviceScope === "storage" && (usage.storage?.sumFileSizeBytes || 0) > limit) {
|
501
508
|
return {
|
502
509
|
usageLimited: true,
|
503
|
-
status:
|
510
|
+
status: 403,
|
504
511
|
errorMessage: `You've used all of your total usage limit for Storage Pinning. Please add your payment method at https://thirdweb.com/dashboard/settings/billing.`,
|
505
512
|
errorCode: "PAYMENT_METHOD_REQUIRED"
|
506
513
|
};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var node_crypto = require('node:crypto');
|
6
|
-
var index = require('../../dist/index-
|
6
|
+
var index = require('../../dist/index-8be280f0.cjs.dev.js');
|
7
7
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
8
8
|
|
9
9
|
/**
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var node_crypto = require('node:crypto');
|
6
|
-
var index = require('../../dist/index-
|
6
|
+
var index = require('../../dist/index-2a4bc395.cjs.prod.js');
|
7
7
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
8
8
|
|
9
9
|
/**
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createHash } from 'node:crypto';
|
2
|
-
import { a as authorize } from '../../dist/index-
|
3
|
-
export { r as rateLimit, u as usageLimit } from '../../dist/index-
|
2
|
+
import { a as authorize } from '../../dist/index-79984a5a.esm.js';
|
3
|
+
export { r as rateLimit, u as usageLimit } from '../../dist/index-79984a5a.esm.js';
|
4
4
|
export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
|
5
5
|
|
6
6
|
/**
|
package/package.json
CHANGED