@thirdweb-dev/service-utils 0.0.0-dev-0231c73-20230926212531 → 0.0.0-dev-bf546b2-20230927015950

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-6a597a58.cjs.dev.js');
5
+ var index = require('../../dist/index-253f4888.cjs.dev.js');
6
6
  var aws4fetch = require('aws4fetch');
7
7
  var zod = require('zod');
8
8
  var services = require('../../dist/services-79b4664f.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-30f0f58c.cjs.prod.js');
5
+ var index = require('../../dist/index-209e3e52.cjs.prod.js');
6
6
  var aws4fetch = require('aws4fetch');
7
7
  var zod = require('zod');
8
8
  var services = require('../../dist/services-04997839.cjs.prod.js');
@@ -1,5 +1,5 @@
1
- import { a as authorize } from '../../dist/index-cd8f49a9.esm.js';
2
- export { r as rateLimit, u as usageLimit } from '../../dist/index-cd8f49a9.esm.js';
1
+ import { a as authorize } from '../../dist/index-25086ddf.esm.js';
2
+ export { r as rateLimit, u as usageLimit } from '../../dist/index-25086ddf.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-bc12a5f6.esm.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuB,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK1C,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7D,CAAC;AAEF,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,WAAW,EAAE,mBAAmB,CAAC;IACjC,aAAa,EAAE,iBAAiB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiE3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuB,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK1C,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7D,CAAC;AAEF,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,WAAW,EAAE,mBAAmB,CAAC;IACjC,aAAa,EAAE,iBAAiB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsE3B"}
@@ -1,9 +1,11 @@
1
1
  export type RateLimitResult = {
2
- requestCount: number;
3
2
  rateLimited: false;
4
- } | {
5
3
  requestCount: number;
4
+ rateLimit: number;
5
+ } | {
6
6
  rateLimited: true;
7
+ requestCount: number;
8
+ rateLimit: number;
7
9
  status: number;
8
10
  errorMessage: string;
9
11
  errorCode: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB;IACE,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;CACpB,GACD;IACE,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/rateLimit","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB;IACE,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,WAAW,EAAE,IAAI,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -460,11 +460,12 @@ async function rateLimit(args) {
460
460
  redis,
461
461
  sampleRate = 1.0
462
462
  } = args;
463
- const shouldCountRequest = Math.random() < sampleRate;
464
- if (!shouldCountRequest || !authzResult.authorized) {
463
+ const shouldSampleRequest = Math.random() < sampleRate;
464
+ if (!shouldSampleRequest || !authzResult.authorized) {
465
465
  return {
466
+ rateLimited: false,
466
467
  requestCount: 0,
467
- rateLimited: false
468
+ rateLimit: 0
468
469
  };
469
470
  }
470
471
  const {
@@ -475,15 +476,13 @@ async function rateLimit(args) {
475
476
  const {
476
477
  serviceScope
477
478
  } = serviceConfig;
478
- const {
479
- rateLimits
480
- } = apiKeyMeta || accountMeta || {};
481
- const limitPerSecond = rateLimits?.[serviceScope];
479
+ const limitPerSecond = apiKeyMeta?.rateLimits?.[serviceScope] ?? accountMeta?.rateLimits?.[serviceScope];
482
480
  if (!limitPerSecond) {
483
481
  // No rate limit is provided. Assume the request is not rate limited.
484
482
  return {
483
+ rateLimited: false,
485
484
  requestCount: 0,
486
- rateLimited: false
485
+ rateLimit: 0
487
486
  };
488
487
  }
489
488
 
@@ -509,8 +508,9 @@ async function rateLimit(args) {
509
508
  // Reject requests when they've exceeded 2x the rate limit.
510
509
  if (requestCount > 2 * limitPerWindow) {
511
510
  return {
512
- requestCount,
513
511
  rateLimited: true,
512
+ requestCount,
513
+ rateLimit: limitPerWindow,
514
514
  status: 429,
515
515
  errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limitPerSecond} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
516
516
  errorCode: "RATE_LIMIT_EXCEEDED"
@@ -518,8 +518,9 @@ async function rateLimit(args) {
518
518
  }
519
519
  }
520
520
  return {
521
+ rateLimited: false,
521
522
  requestCount,
522
- rateLimited: false
523
+ rateLimit: limitPerWindow
523
524
  };
524
525
  }
525
526
 
@@ -458,11 +458,12 @@ async function rateLimit(args) {
458
458
  redis,
459
459
  sampleRate = 1.0
460
460
  } = args;
461
- const shouldCountRequest = Math.random() < sampleRate;
462
- if (!shouldCountRequest || !authzResult.authorized) {
461
+ const shouldSampleRequest = Math.random() < sampleRate;
462
+ if (!shouldSampleRequest || !authzResult.authorized) {
463
463
  return {
464
+ rateLimited: false,
464
465
  requestCount: 0,
465
- rateLimited: false
466
+ rateLimit: 0
466
467
  };
467
468
  }
468
469
  const {
@@ -473,15 +474,13 @@ async function rateLimit(args) {
473
474
  const {
474
475
  serviceScope
475
476
  } = serviceConfig;
476
- const {
477
- rateLimits
478
- } = apiKeyMeta || accountMeta || {};
479
- const limitPerSecond = rateLimits?.[serviceScope];
477
+ const limitPerSecond = apiKeyMeta?.rateLimits?.[serviceScope] ?? accountMeta?.rateLimits?.[serviceScope];
480
478
  if (!limitPerSecond) {
481
479
  // No rate limit is provided. Assume the request is not rate limited.
482
480
  return {
481
+ rateLimited: false,
483
482
  requestCount: 0,
484
- rateLimited: false
483
+ rateLimit: 0
485
484
  };
486
485
  }
487
486
 
@@ -507,8 +506,9 @@ async function rateLimit(args) {
507
506
  // Reject requests when they've exceeded 2x the rate limit.
508
507
  if (requestCount > 2 * limitPerWindow) {
509
508
  return {
510
- requestCount,
511
509
  rateLimited: true,
510
+ requestCount,
511
+ rateLimit: limitPerWindow,
512
512
  status: 429,
513
513
  errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limitPerSecond} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
514
514
  errorCode: "RATE_LIMIT_EXCEEDED"
@@ -516,8 +516,9 @@ async function rateLimit(args) {
516
516
  }
517
517
  }
518
518
  return {
519
+ rateLimited: false,
519
520
  requestCount,
520
- rateLimited: false
521
+ rateLimit: limitPerWindow
521
522
  };
522
523
  }
523
524
 
@@ -460,11 +460,12 @@ async function rateLimit(args) {
460
460
  redis,
461
461
  sampleRate = 1.0
462
462
  } = args;
463
- const shouldCountRequest = Math.random() < sampleRate;
464
- if (!shouldCountRequest || !authzResult.authorized) {
463
+ const shouldSampleRequest = Math.random() < sampleRate;
464
+ if (!shouldSampleRequest || !authzResult.authorized) {
465
465
  return {
466
+ rateLimited: false,
466
467
  requestCount: 0,
467
- rateLimited: false
468
+ rateLimit: 0
468
469
  };
469
470
  }
470
471
  const {
@@ -475,15 +476,13 @@ async function rateLimit(args) {
475
476
  const {
476
477
  serviceScope
477
478
  } = serviceConfig;
478
- const {
479
- rateLimits
480
- } = apiKeyMeta || accountMeta || {};
481
- const limitPerSecond = rateLimits?.[serviceScope];
479
+ const limitPerSecond = apiKeyMeta?.rateLimits?.[serviceScope] ?? accountMeta?.rateLimits?.[serviceScope];
482
480
  if (!limitPerSecond) {
483
481
  // No rate limit is provided. Assume the request is not rate limited.
484
482
  return {
483
+ rateLimited: false,
485
484
  requestCount: 0,
486
- rateLimited: false
485
+ rateLimit: 0
487
486
  };
488
487
  }
489
488
 
@@ -509,8 +508,9 @@ async function rateLimit(args) {
509
508
  // Reject requests when they've exceeded 2x the rate limit.
510
509
  if (requestCount > 2 * limitPerWindow) {
511
510
  return {
512
- requestCount,
513
511
  rateLimited: true,
512
+ requestCount,
513
+ rateLimit: limitPerWindow,
514
514
  status: 429,
515
515
  errorMessage: `You've exceeded your ${serviceScope} rate limit at ${limitPerSecond} reqs/sec. To get higher rate limits, contact us at https://thirdweb.com/contact-us.`,
516
516
  errorCode: "RATE_LIMIT_EXCEEDED"
@@ -518,8 +518,9 @@ async function rateLimit(args) {
518
518
  }
519
519
  }
520
520
  return {
521
+ rateLimited: false,
521
522
  requestCount,
522
- rateLimited: false
523
+ rateLimit: limitPerWindow
523
524
  };
524
525
  }
525
526
 
@@ -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-6a597a58.cjs.dev.js');
6
+ var index = require('../../dist/index-253f4888.cjs.dev.js');
7
7
  var services = require('../../dist/services-79b4664f.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-30f0f58c.cjs.prod.js');
6
+ var index = require('../../dist/index-209e3e52.cjs.prod.js');
7
7
  var services = require('../../dist/services-04997839.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-cd8f49a9.esm.js';
3
- export { r as rateLimit, u as usageLimit } from '../../dist/index-cd8f49a9.esm.js';
2
+ import { a as authorize } from '../../dist/index-25086ddf.esm.js';
3
+ export { r as rateLimit, u as usageLimit } from '../../dist/index-25086ddf.esm.js';
4
4
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-bc12a5f6.esm.js';
5
5
 
6
6
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.0.0-dev-0231c73-20230926212531",
3
+ "version": "0.0.0-dev-bf546b2-20230927015950",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {