@thirdweb-dev/service-utils 0.4.4-nightly-2088de1c-20230901183809 → 0.4.5-next-bc537e5a-20230919062653

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.
Files changed (29) hide show
  1. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +42 -24
  2. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +42 -24
  3. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +41 -25
  4. package/dist/declarations/src/cf-worker/index.d.ts +6 -2
  5. package/dist/declarations/src/cf-worker/index.d.ts.map +1 -1
  6. package/dist/declarations/src/cf-worker/usage.d.ts +14 -11
  7. package/dist/declarations/src/cf-worker/usage.d.ts.map +1 -1
  8. package/dist/declarations/src/core/api.d.ts +17 -1
  9. package/dist/declarations/src/core/api.d.ts.map +1 -1
  10. package/dist/declarations/src/core/authorize/client.d.ts.map +1 -1
  11. package/dist/declarations/src/core/authorize/index.d.ts.map +1 -1
  12. package/dist/declarations/src/core/authorize/service.d.ts.map +1 -1
  13. package/dist/declarations/src/core/rateLimit/index.d.ts +10 -0
  14. package/dist/declarations/src/core/rateLimit/index.d.ts.map +1 -0
  15. package/dist/declarations/src/core/rateLimit/types.d.ts +9 -0
  16. package/dist/declarations/src/core/rateLimit/types.d.ts.map +1 -0
  17. package/dist/declarations/src/core/usageLimit/index.d.ts +5 -0
  18. package/dist/declarations/src/core/usageLimit/index.d.ts.map +1 -0
  19. package/dist/declarations/src/core/usageLimit/types.d.ts +9 -0
  20. package/dist/declarations/src/core/usageLimit/types.d.ts.map +1 -0
  21. package/dist/declarations/src/node/index.d.ts +2 -0
  22. package/dist/declarations/src/node/index.d.ts.map +1 -1
  23. package/dist/{index-6e0ecc5f.cjs.prod.js → index-807f6a60.cjs.dev.js} +132 -6
  24. package/dist/{index-ffddf746.esm.js → index-bcf68113.esm.js} +131 -7
  25. package/dist/{index-cd4f96ef.cjs.dev.js → index-cfc8027b.cjs.prod.js} +132 -6
  26. package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +28 -22
  27. package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +28 -22
  28. package/node/dist/thirdweb-dev-service-utils-node.esm.js +27 -22
  29. package/package.json +2 -1
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-cd4f96ef.cjs.dev.js');
6
- var services = require('../../dist/services-a3f36057.cjs.dev.js');
5
+ var index = require('../../dist/index-807f6a60.cjs.dev.js');
7
6
  var aws4fetch = require('aws4fetch');
8
7
  var zod = require('zod');
8
+ var services = require('../../dist/services-a3f36057.cjs.dev.js');
9
9
 
10
10
  // Initialize a singleton for aws usage.
11
11
  let _aws;
@@ -20,7 +20,7 @@ function getAws(options) {
20
20
  * Types
21
21
  */
22
22
  const usageEventSchema = zod.z.object({
23
- source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
23
+ source: zod.z.enum(["embeddedWallets", "rpc", "storage", "bundler", "paymaster", "relayer"]),
24
24
  action: zod.z.string(),
25
25
  accountId: zod.z.string(),
26
26
  // Optional
@@ -33,10 +33,11 @@ const usageEventSchema = zod.z.object({
33
33
  mimeType: zod.z.string().optional(),
34
34
  fileSize: zod.z.number().int().nonnegative().optional(),
35
35
  fileCid: zod.z.string().optional(),
36
- transactionHash: zod.z.string().optional(),
36
+ evmMethod: zod.z.string().optional(),
37
+ userOpHash: zod.z.string().optional(),
37
38
  gasLimit: zod.z.number().nonnegative().optional(),
38
39
  gasPricePerUnit: zod.z.string().optional(),
39
- userOpHash: zod.z.string().optional()
40
+ transactionHash: zod.z.string().optional()
40
41
  });
41
42
  /**
42
43
  * Publish usage events. Provide the relevant fields for your application.
@@ -86,6 +87,8 @@ async function publishUsageEvents(usageEvents, config) {
86
87
  }
87
88
 
88
89
  const DEFAULT_CACHE_TTL_SECONDS = 60;
90
+ // must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
91
+ const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
89
92
  async function authorizeWorker(authInput, serviceConfig) {
90
93
  let authData;
91
94
  try {
@@ -117,6 +120,14 @@ async function authorizeWorker(authInput, serviceConfig) {
117
120
  cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
118
121
  });
119
122
  }
123
+ async function rateLimitWorker(authzResult, serviceConfig) {
124
+ return await index.rateLimit(authzResult, serviceConfig, {
125
+ get: async bucketId => serviceConfig.kvStore.get(bucketId),
126
+ put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
127
+ expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
128
+ })
129
+ });
130
+ }
120
131
  async function extractAuthorizationData(authInput) {
121
132
  const requestUrl = new URL(authInput.req.url);
122
133
  const headers = authInput.req.headers;
@@ -207,27 +218,33 @@ async function logHttpRequest(_ref) {
207
218
  isAuthed,
208
219
  statusMessage
209
220
  } = _ref;
210
- const authorizationData = await extractAuthorizationData({
211
- req,
212
- clientId
213
- });
214
- const headers = req.headers;
215
- console.log(JSON.stringify({
216
- source,
217
- pathname: req.url,
218
- hasSecretKey: !!authorizationData.secretKey,
219
- hasClientId: !!authorizationData.clientId,
220
- hasJwt: !!authorizationData.jwt,
221
- clientId: authorizationData.clientId,
222
- isAuthed: !!isAuthed ?? null,
223
- status: res.status,
224
- sdkName: headers.get("x-sdk-name") ?? "unknown",
225
- sdkVersion: headers.get("x-sdk-version") ?? "unknown",
226
- platform: headers.get("x-sdk-platform") ?? "unknown"
227
- }));
228
- console.log(`statusMessage=${statusMessage ?? res.statusText}`);
221
+ try {
222
+ const authorizationData = await extractAuthorizationData({
223
+ req,
224
+ clientId
225
+ });
226
+ const headers = req.headers;
227
+ console.log(JSON.stringify({
228
+ source,
229
+ pathname: req.url,
230
+ hasSecretKey: !!authorizationData.secretKey,
231
+ hasClientId: !!authorizationData.clientId,
232
+ hasJwt: !!authorizationData.jwt,
233
+ clientId: authorizationData.clientId,
234
+ isAuthed: !!isAuthed ?? null,
235
+ status: res.status,
236
+ sdkName: headers.get("x-sdk-name") ?? "unknown",
237
+ sdkVersion: headers.get("x-sdk-version") ?? "unknown",
238
+ platform: headers.get("x-sdk-platform") ?? "unknown"
239
+ }));
240
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
241
+ } catch (err) {
242
+ console.error("Failed to log HTTP request:", err);
243
+ }
229
244
  }
230
245
 
246
+ exports.rateLimit = index.rateLimit;
247
+ exports.usageLimit = index.usageLimit;
231
248
  exports.SERVICES = services.SERVICES;
232
249
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
233
250
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
@@ -238,3 +255,4 @@ exports.extractAuthorizationData = extractAuthorizationData;
238
255
  exports.hashSecretKey = hashSecretKey;
239
256
  exports.logHttpRequest = logHttpRequest;
240
257
  exports.publishUsageEvents = publishUsageEvents;
258
+ exports.rateLimitWorker = rateLimitWorker;
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-6e0ecc5f.cjs.prod.js');
6
- var services = require('../../dist/services-9e185105.cjs.prod.js');
5
+ var index = require('../../dist/index-cfc8027b.cjs.prod.js');
7
6
  var aws4fetch = require('aws4fetch');
8
7
  var zod = require('zod');
8
+ var services = require('../../dist/services-9e185105.cjs.prod.js');
9
9
 
10
10
  // Initialize a singleton for aws usage.
11
11
  let _aws;
@@ -20,7 +20,7 @@ function getAws(options) {
20
20
  * Types
21
21
  */
22
22
  const usageEventSchema = zod.z.object({
23
- source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
23
+ source: zod.z.enum(["embeddedWallets", "rpc", "storage", "bundler", "paymaster", "relayer"]),
24
24
  action: zod.z.string(),
25
25
  accountId: zod.z.string(),
26
26
  // Optional
@@ -33,10 +33,11 @@ const usageEventSchema = zod.z.object({
33
33
  mimeType: zod.z.string().optional(),
34
34
  fileSize: zod.z.number().int().nonnegative().optional(),
35
35
  fileCid: zod.z.string().optional(),
36
- transactionHash: zod.z.string().optional(),
36
+ evmMethod: zod.z.string().optional(),
37
+ userOpHash: zod.z.string().optional(),
37
38
  gasLimit: zod.z.number().nonnegative().optional(),
38
39
  gasPricePerUnit: zod.z.string().optional(),
39
- userOpHash: zod.z.string().optional()
40
+ transactionHash: zod.z.string().optional()
40
41
  });
41
42
  /**
42
43
  * Publish usage events. Provide the relevant fields for your application.
@@ -86,6 +87,8 @@ async function publishUsageEvents(usageEvents, config) {
86
87
  }
87
88
 
88
89
  const DEFAULT_CACHE_TTL_SECONDS = 60;
90
+ // must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
91
+ const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
89
92
  async function authorizeWorker(authInput, serviceConfig) {
90
93
  let authData;
91
94
  try {
@@ -117,6 +120,14 @@ async function authorizeWorker(authInput, serviceConfig) {
117
120
  cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
118
121
  });
119
122
  }
123
+ async function rateLimitWorker(authzResult, serviceConfig) {
124
+ return await index.rateLimit(authzResult, serviceConfig, {
125
+ get: async bucketId => serviceConfig.kvStore.get(bucketId),
126
+ put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
127
+ expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
128
+ })
129
+ });
130
+ }
120
131
  async function extractAuthorizationData(authInput) {
121
132
  const requestUrl = new URL(authInput.req.url);
122
133
  const headers = authInput.req.headers;
@@ -207,27 +218,33 @@ async function logHttpRequest(_ref) {
207
218
  isAuthed,
208
219
  statusMessage
209
220
  } = _ref;
210
- const authorizationData = await extractAuthorizationData({
211
- req,
212
- clientId
213
- });
214
- const headers = req.headers;
215
- console.log(JSON.stringify({
216
- source,
217
- pathname: req.url,
218
- hasSecretKey: !!authorizationData.secretKey,
219
- hasClientId: !!authorizationData.clientId,
220
- hasJwt: !!authorizationData.jwt,
221
- clientId: authorizationData.clientId,
222
- isAuthed: !!isAuthed ?? null,
223
- status: res.status,
224
- sdkName: headers.get("x-sdk-name") ?? "unknown",
225
- sdkVersion: headers.get("x-sdk-version") ?? "unknown",
226
- platform: headers.get("x-sdk-platform") ?? "unknown"
227
- }));
228
- console.log(`statusMessage=${statusMessage ?? res.statusText}`);
221
+ try {
222
+ const authorizationData = await extractAuthorizationData({
223
+ req,
224
+ clientId
225
+ });
226
+ const headers = req.headers;
227
+ console.log(JSON.stringify({
228
+ source,
229
+ pathname: req.url,
230
+ hasSecretKey: !!authorizationData.secretKey,
231
+ hasClientId: !!authorizationData.clientId,
232
+ hasJwt: !!authorizationData.jwt,
233
+ clientId: authorizationData.clientId,
234
+ isAuthed: !!isAuthed ?? null,
235
+ status: res.status,
236
+ sdkName: headers.get("x-sdk-name") ?? "unknown",
237
+ sdkVersion: headers.get("x-sdk-version") ?? "unknown",
238
+ platform: headers.get("x-sdk-platform") ?? "unknown"
239
+ }));
240
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
241
+ } catch (err) {
242
+ console.error("Failed to log HTTP request:", err);
243
+ }
229
244
  }
230
245
 
246
+ exports.rateLimit = index.rateLimit;
247
+ exports.usageLimit = index.usageLimit;
231
248
  exports.SERVICES = services.SERVICES;
232
249
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
233
250
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
@@ -238,3 +255,4 @@ exports.extractAuthorizationData = extractAuthorizationData;
238
255
  exports.hashSecretKey = hashSecretKey;
239
256
  exports.logHttpRequest = logHttpRequest;
240
257
  exports.publishUsageEvents = publishUsageEvents;
258
+ exports.rateLimitWorker = rateLimitWorker;
@@ -1,7 +1,8 @@
1
- import { a as authorize } from '../../dist/index-ffddf746.esm.js';
2
- export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
1
+ import { a as authorize, r as rateLimit } from '../../dist/index-bcf68113.esm.js';
2
+ export { r as rateLimit, u as usageLimit } from '../../dist/index-bcf68113.esm.js';
3
3
  import { AwsClient } from 'aws4fetch';
4
4
  import { z } from 'zod';
5
+ export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
5
6
 
6
7
  // Initialize a singleton for aws usage.
7
8
  let _aws;
@@ -16,7 +17,7 @@ function getAws(options) {
16
17
  * Types
17
18
  */
18
19
  const usageEventSchema = z.object({
19
- source: z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
20
+ source: z.enum(["embeddedWallets", "rpc", "storage", "bundler", "paymaster", "relayer"]),
20
21
  action: z.string(),
21
22
  accountId: z.string(),
22
23
  // Optional
@@ -29,10 +30,11 @@ const usageEventSchema = z.object({
29
30
  mimeType: z.string().optional(),
30
31
  fileSize: z.number().int().nonnegative().optional(),
31
32
  fileCid: z.string().optional(),
32
- transactionHash: z.string().optional(),
33
+ evmMethod: z.string().optional(),
34
+ userOpHash: z.string().optional(),
33
35
  gasLimit: z.number().nonnegative().optional(),
34
36
  gasPricePerUnit: z.string().optional(),
35
- userOpHash: z.string().optional()
37
+ transactionHash: z.string().optional()
36
38
  });
37
39
  /**
38
40
  * Publish usage events. Provide the relevant fields for your application.
@@ -82,6 +84,8 @@ async function publishUsageEvents(usageEvents, config) {
82
84
  }
83
85
 
84
86
  const DEFAULT_CACHE_TTL_SECONDS = 60;
87
+ // must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
88
+ const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
85
89
  async function authorizeWorker(authInput, serviceConfig) {
86
90
  let authData;
87
91
  try {
@@ -113,6 +117,14 @@ async function authorizeWorker(authInput, serviceConfig) {
113
117
  cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
114
118
  });
115
119
  }
120
+ async function rateLimitWorker(authzResult, serviceConfig) {
121
+ return await rateLimit(authzResult, serviceConfig, {
122
+ get: async bucketId => serviceConfig.kvStore.get(bucketId),
123
+ put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
124
+ expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
125
+ })
126
+ });
127
+ }
116
128
  async function extractAuthorizationData(authInput) {
117
129
  const requestUrl = new URL(authInput.req.url);
118
130
  const headers = authInput.req.headers;
@@ -203,25 +215,29 @@ async function logHttpRequest(_ref) {
203
215
  isAuthed,
204
216
  statusMessage
205
217
  } = _ref;
206
- const authorizationData = await extractAuthorizationData({
207
- req,
208
- clientId
209
- });
210
- const headers = req.headers;
211
- console.log(JSON.stringify({
212
- source,
213
- pathname: req.url,
214
- hasSecretKey: !!authorizationData.secretKey,
215
- hasClientId: !!authorizationData.clientId,
216
- hasJwt: !!authorizationData.jwt,
217
- clientId: authorizationData.clientId,
218
- isAuthed: !!isAuthed ?? null,
219
- status: res.status,
220
- sdkName: headers.get("x-sdk-name") ?? "unknown",
221
- sdkVersion: headers.get("x-sdk-version") ?? "unknown",
222
- platform: headers.get("x-sdk-platform") ?? "unknown"
223
- }));
224
- console.log(`statusMessage=${statusMessage ?? res.statusText}`);
218
+ try {
219
+ const authorizationData = await extractAuthorizationData({
220
+ req,
221
+ clientId
222
+ });
223
+ const headers = req.headers;
224
+ console.log(JSON.stringify({
225
+ source,
226
+ pathname: req.url,
227
+ hasSecretKey: !!authorizationData.secretKey,
228
+ hasClientId: !!authorizationData.clientId,
229
+ hasJwt: !!authorizationData.jwt,
230
+ clientId: authorizationData.clientId,
231
+ isAuthed: !!isAuthed ?? null,
232
+ status: res.status,
233
+ sdkName: headers.get("x-sdk-name") ?? "unknown",
234
+ sdkVersion: headers.get("x-sdk-version") ?? "unknown",
235
+ platform: headers.get("x-sdk-platform") ?? "unknown"
236
+ }));
237
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
238
+ } catch (err) {
239
+ console.error("Failed to log HTTP request:", err);
240
+ }
225
241
  }
226
242
 
227
- export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents };
243
+ export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents, rateLimitWorker };
@@ -3,10 +3,13 @@ import type { CoreServiceConfig } from "../core/api";
3
3
  import type { Request } from "@cloudflare/workers-types";
4
4
  import type { AuthorizationInput } from "../core/authorize";
5
5
  import type { AuthorizationResult } from "../core/authorize/types";
6
+ import type { RateLimitResult } from "../core/rateLimit/types";
6
7
  import type { CoreAuthInput } from "../core/types";
7
- export * from "../core/services";
8
8
  export * from "./usage";
9
- type WorkerServiceConfig = CoreServiceConfig & {
9
+ export * from "../core/services";
10
+ export * from "../core/rateLimit";
11
+ export * from "../core/usageLimit";
12
+ export type WorkerServiceConfig = CoreServiceConfig & {
10
13
  kvStore: KVNamespace;
11
14
  ctx: ExecutionContext;
12
15
  cacheTtlSeconds?: number;
@@ -15,6 +18,7 @@ type AuthInput = CoreAuthInput & {
15
18
  req: Request;
16
19
  };
17
20
  export declare function authorizeWorker(authInput: AuthInput, serviceConfig: WorkerServiceConfig): Promise<AuthorizationResult>;
21
+ export declare function rateLimitWorker(authzResult: AuthorizationResult, serviceConfig: WorkerServiceConfig): Promise<RateLimitResult>;
18
22
  export declare function extractAuthorizationData(authInput: AuthInput): Promise<AuthorizationInput>;
19
23
  export declare function hashSecretKey(secretKey: string): Promise<string>;
20
24
  export declare function deriveClientIdFromSecretKeyHash(secretKeyHash: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACT,MAAM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M,EACN,QAAQ,EACR,GAAG,EACH,GAAG,EACH,QAAQ,EACR,aAAa,GACd,EAAE,SAAS,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,QAAQ,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAChC,iBAwBA"}
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  * Types
4
4
  */
5
5
  declare const usageEventSchema: z.ZodObject<{
6
- source: z.ZodEnum<["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]>;
6
+ source: z.ZodEnum<["embeddedWallets", "rpc", "storage", "bundler", "paymaster", "relayer"]>;
7
7
  action: z.ZodString;
8
8
  accountId: z.ZodString;
9
9
  apiKeyId: z.ZodOptional<z.ZodString>;
@@ -15,14 +15,15 @@ declare const usageEventSchema: z.ZodObject<{
15
15
  mimeType: z.ZodOptional<z.ZodString>;
16
16
  fileSize: z.ZodOptional<z.ZodNumber>;
17
17
  fileCid: z.ZodOptional<z.ZodString>;
18
- transactionHash: z.ZodOptional<z.ZodString>;
18
+ evmMethod: z.ZodOptional<z.ZodString>;
19
+ userOpHash: z.ZodOptional<z.ZodString>;
19
20
  gasLimit: z.ZodOptional<z.ZodNumber>;
20
21
  gasPricePerUnit: z.ZodOptional<z.ZodString>;
21
- userOpHash: z.ZodOptional<z.ZodString>;
22
+ transactionHash: z.ZodOptional<z.ZodString>;
22
23
  }, "strip", z.ZodTypeAny, {
23
- source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
24
- action: string;
24
+ source: "storage" | "rpc" | "bundler" | "relayer" | "embeddedWallets" | "paymaster";
25
25
  accountId: string;
26
+ action: string;
26
27
  apiKeyId?: string | undefined;
27
28
  creatorWalletAddress?: string | undefined;
28
29
  clientId?: string | undefined;
@@ -32,14 +33,15 @@ declare const usageEventSchema: z.ZodObject<{
32
33
  mimeType?: string | undefined;
33
34
  fileSize?: number | undefined;
34
35
  fileCid?: string | undefined;
35
- transactionHash?: string | undefined;
36
+ evmMethod?: string | undefined;
37
+ userOpHash?: string | undefined;
36
38
  gasLimit?: number | undefined;
37
39
  gasPricePerUnit?: string | undefined;
38
- userOpHash?: string | undefined;
40
+ transactionHash?: string | undefined;
39
41
  }, {
40
- source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
41
- action: string;
42
+ source: "storage" | "rpc" | "bundler" | "relayer" | "embeddedWallets" | "paymaster";
42
43
  accountId: string;
44
+ action: string;
43
45
  apiKeyId?: string | undefined;
44
46
  creatorWalletAddress?: string | undefined;
45
47
  clientId?: string | undefined;
@@ -49,10 +51,11 @@ declare const usageEventSchema: z.ZodObject<{
49
51
  mimeType?: string | undefined;
50
52
  fileSize?: number | undefined;
51
53
  fileCid?: string | undefined;
52
- transactionHash?: string | undefined;
54
+ evmMethod?: string | undefined;
55
+ userOpHash?: string | undefined;
53
56
  gasLimit?: number | undefined;
54
57
  gasPricePerUnit?: string | undefined;
55
- userOpHash?: string | undefined;
58
+ transactionHash?: string | undefined;
56
59
  }>;
57
60
  export type UsageEvent = z.infer<typeof usageEventSchema>;
58
61
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"usage.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;GAEG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BpB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE;IACN,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CAAC,IAAI,CAAC,CAiCf"}
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;GAEG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BpB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE;IACN,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CAAC,IAAI,CAAC,CAiCf"}
@@ -1,12 +1,20 @@
1
1
  import type { ServiceName } from "./services";
2
2
  export type CoreServiceConfig = {
3
- enforceAuth: boolean;
3
+ enforceAuth?: boolean;
4
4
  apiUrl: string;
5
5
  serviceScope: ServiceName;
6
6
  serviceApiKey: string;
7
7
  serviceAction?: string;
8
8
  useWalletAuth?: boolean;
9
9
  };
10
+ type Usage = {
11
+ storage?: {
12
+ sumFileSizeBytes: number;
13
+ };
14
+ embeddedWallets?: {
15
+ countWalletAddresses: number;
16
+ };
17
+ };
10
18
  export type ApiKeyMetadata = {
11
19
  id: string;
12
20
  key: string;
@@ -23,11 +31,17 @@ export type ApiKeyMetadata = {
23
31
  targetAddresses: string[];
24
32
  actions: string[];
25
33
  }[];
34
+ usage?: Usage;
35
+ limits: Partial<Record<ServiceName, number>>;
36
+ rateLimits: Partial<Record<ServiceName, number>>;
26
37
  };
27
38
  export type AccountMetadata = {
28
39
  id: string;
29
40
  name: string;
30
41
  creatorWalletAddress: string;
42
+ usage?: Usage;
43
+ limits: Partial<Record<ServiceName, number>>;
44
+ rateLimits: Partial<Record<ServiceName, number>>;
31
45
  };
32
46
  export type ApiResponse = {
33
47
  data: ApiKeyMetadata | null;
@@ -47,4 +61,6 @@ export type ApiAccountResponse = {
47
61
  };
48
62
  export declare function fetchKeyMetadataFromApi(clientId: string, config: CoreServiceConfig): Promise<ApiResponse>;
49
63
  export declare function fetchAccountFromApi(jwt: string, config: CoreServiceConfig, useWalletAuth: boolean): Promise<ApiAccountResponse>;
64
+ export declare function updateRateLimitedAt(apiKeyId: string, config: CoreServiceConfig): Promise<void>;
65
+ export {};
50
66
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"../../../../src/core","sources":["api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,WAAW,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,gBAAgB,CAAC;IAC9E,WAAW,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,S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AAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,cAAc,GACzB,mBAAmB,CAwGrB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,cAAc,GACzB,mBAAmB,CA2GrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EAGlB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAElC,aAAa,CAAC,EAAE,MAAM,G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;IAClD,GAAG,EAAE,CACH,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,GAAG,eAAe,KACnC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAgBF,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,kBAAkB,EAC5B,aAAa,EAAE,iBAAiB,EAChC,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAsN9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,2BAA2B,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhF,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,iBAAiB,EAChC,oBAAoB,CAAC,EAAE,2BAA2B,GACjD,mBAAmB,CA6DrB"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,2BAA2B,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhF,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,iBAAiB,EAChC,oBAAoB,CAAC,EAAE,2BAA2B,GACjD,mBAAmB,CAgErB"}
@@ -0,0 +1,10 @@
1
+ import { CoreServiceConfig } from "../api";
2
+ import { AuthorizationResult } from "../authorize/types";
3
+ import { RateLimitResult } from "./types";
4
+ type CacheOptions = {
5
+ get: (bucketId: string) => Promise<string | null>;
6
+ put: (bucketId: string, count: string) => Promise<void> | void;
7
+ };
8
+ export declare function rateLimit(authzResult: AuthorizationResult, serviceConfig: CoreServiceConfig, cacheOptions: CacheOptions): Promise<RateLimitResult>;
9
+ export {};
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAEzD,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,WAAW,EAAE,mBAAmB,EAChC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,eAAe,CAAC,CAuD1B"}
@@ -0,0 +1,9 @@
1
+ export type RateLimitResult = {
2
+ rateLimited: false;
3
+ } | {
4
+ rateLimited: true;
5
+ status: number;
6
+ errorMessage: string;
7
+ errorCode: string;
8
+ };
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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;CACpB,GACD;IACE,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { CoreServiceConfig } from "../api";
2
+ import { AuthorizationResult } from "../authorize/types";
3
+ import { UsageLimitResult } from "./types";
4
+ export declare function usageLimit(authzResult: AuthorizationResult, serviceConfig: CoreServiceConfig): Promise<UsageLimitResult>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/usageLimit","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAsB,UAAU,CAC9B,WAAW,EAAE,mBAAmB,EAChC,aAAa,EAAE,iBAAiB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAwC3B"}
@@ -0,0 +1,9 @@
1
+ export type UsageLimitResult = {
2
+ usageLimited: false;
3
+ } | {
4
+ usageLimited: true;
5
+ status: number;
6
+ errorMessage: string;
7
+ errorCode: string;
8
+ };
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"../../../../../src/core/usageLimit","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB;IACE,YAAY,EAAE,KAAK,CAAC;CACrB,GACD;IACE,YAAY,EAAE,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -6,6 +6,8 @@ import type { AuthorizationInput } from "../core/authorize";
6
6
  import type { AuthorizationResult } from "../core/authorize/types";
7
7
  import type { CoreAuthInput } from "../core/types";
8
8
  export * from "../core/services";
9
+ export * from "../core/rateLimit";
10
+ export * from "../core/usageLimit";
9
11
  type NodeServiceConfig = CoreServiceConfig;
10
12
  export type AuthInput = CoreAuthInput & {
11
13
  req: IncomingMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,cAAc,kBAAkB,CAAC;AAEjC,KAAK,iBAAiB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,iBAAiB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAaD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,GACnB,kBAAkB,CA2FpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE;AAED,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,GAAG,EACH,GAAG,EACH,QAAQ,EACR,aAAa,GACd,EAAE,SAAS,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,G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