@thirdweb-dev/service-utils 0.0.0-dev-ea3157f-20230802203753 → 0.0.0-dev-bd971e7-20230807183752

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,8 +2,84 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-8a9496b0.cjs.dev.js');
5
+ var index = require('../../dist/index-e83fdf2d.cjs.dev.js');
6
6
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
7
+ var aws4fetch = require('aws4fetch');
8
+ var zod = require('zod');
9
+
10
+ // Initialize a singleton for aws usage.
11
+ let _aws;
12
+ function getAws(options) {
13
+ if (!_aws) {
14
+ _aws = new aws4fetch.AwsClient(options);
15
+ }
16
+ return _aws;
17
+ }
18
+
19
+ /**
20
+ * Types
21
+ */
22
+ zod.z.object({
23
+ source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
24
+ action: zod.z.string(),
25
+ accountId: zod.z.string(),
26
+ // Optional
27
+ apiKeyId: zod.z.string().optional(),
28
+ creatorWalletAddress: zod.z.string().optional(),
29
+ clientId: zod.z.string().optional(),
30
+ walletAddress: zod.z.string().optional(),
31
+ chainId: zod.z.number().int().positive().optional(),
32
+ provider: zod.z.string().optional(),
33
+ mimeType: zod.z.string().optional(),
34
+ fileSize: zod.z.number().int().nonnegative().optional(),
35
+ fileCid: zod.z.string().optional(),
36
+ transactionHash: zod.z.string().optional(),
37
+ gasLimit: zod.z.number().nonnegative().optional(),
38
+ gasPricePerUnit: zod.z.string().optional()
39
+ });
40
+ /**
41
+ * Publish usage events. Provide the relevant fields for your application.
42
+ *
43
+ * Usage in Cloudflare Workers:
44
+ * ctx.waitUntil(
45
+ * publishUsageEvents(
46
+ * [event1, event2],
47
+ * { queueUrl, accessKeyId, secretAccessKey },
48
+ * )
49
+ * )
50
+ *
51
+ * @param usageEvents
52
+ * @param config
53
+ */
54
+ async function publishUsageEvents(usageEvents, config) {
55
+ const {
56
+ queueUrl,
57
+ accessKeyId,
58
+ secretAccessKey,
59
+ region = "us-west-2"
60
+ } = config;
61
+ const entries = usageEvents.map(event => ({
62
+ Id: crypto.randomUUID(),
63
+ MessageBody: JSON.stringify(event)
64
+ }));
65
+ const aws = getAws({
66
+ accessKeyId,
67
+ secretAccessKey,
68
+ region
69
+ });
70
+ const res = await aws.fetch(`https://sqs.${region}.amazonaws.com`, {
71
+ headers: {
72
+ "X-Amz-Target": "AmazonSQS.SendMessageBatch",
73
+ "X-Amz-Date": new Date().toISOString(),
74
+ "Content-Type": "application/x-amz-json-1.0"
75
+ },
76
+ body: JSON.stringify({
77
+ QueueUrl: queueUrl,
78
+ Entries: entries
79
+ })
80
+ });
81
+ return await res.text();
82
+ }
7
83
 
8
84
  const DEFAULT_CACHE_TTL_SECONDS = 60;
9
85
  async function authorizeWorker(authInput, serviceConfig) {
@@ -118,6 +194,31 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
118
194
  function bufferToHex(buffer) {
119
195
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
120
196
  }
197
+ async function logHttpRequest(_ref) {
198
+ let {
199
+ source,
200
+ clientId,
201
+ req,
202
+ res,
203
+ isAuthed,
204
+ statusMessage
205
+ } = _ref;
206
+ const authorizationData = await extractAuthorizationData({
207
+ req,
208
+ clientId
209
+ });
210
+ console.log(JSON.stringify({
211
+ source,
212
+ pathname: req.url,
213
+ hasSecretKey: !!authorizationData.secretKey,
214
+ hasClientId: !!authorizationData.clientId,
215
+ hasJwt: !!authorizationData.jwt,
216
+ clientId: authorizationData.clientId,
217
+ isAuthed: !!isAuthed ?? null,
218
+ status: res.status
219
+ }));
220
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
221
+ }
121
222
 
122
223
  exports.SERVICES = services.SERVICES;
123
224
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -125,4 +226,7 @@ exports.SERVICE_NAMES = services.SERVICE_NAMES;
125
226
  exports.getServiceByName = services.getServiceByName;
126
227
  exports.authorizeWorker = authorizeWorker;
127
228
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
229
+ exports.extractAuthorizationData = extractAuthorizationData;
128
230
  exports.hashSecretKey = hashSecretKey;
231
+ exports.logHttpRequest = logHttpRequest;
232
+ exports.publishUsageEvents = publishUsageEvents;
@@ -2,8 +2,84 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-92289057.cjs.prod.js');
5
+ var index = require('../../dist/index-bb16a39e.cjs.prod.js');
6
6
  var services = require('../../dist/services-9e185105.cjs.prod.js');
7
+ var aws4fetch = require('aws4fetch');
8
+ var zod = require('zod');
9
+
10
+ // Initialize a singleton for aws usage.
11
+ let _aws;
12
+ function getAws(options) {
13
+ if (!_aws) {
14
+ _aws = new aws4fetch.AwsClient(options);
15
+ }
16
+ return _aws;
17
+ }
18
+
19
+ /**
20
+ * Types
21
+ */
22
+ zod.z.object({
23
+ source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
24
+ action: zod.z.string(),
25
+ accountId: zod.z.string(),
26
+ // Optional
27
+ apiKeyId: zod.z.string().optional(),
28
+ creatorWalletAddress: zod.z.string().optional(),
29
+ clientId: zod.z.string().optional(),
30
+ walletAddress: zod.z.string().optional(),
31
+ chainId: zod.z.number().int().positive().optional(),
32
+ provider: zod.z.string().optional(),
33
+ mimeType: zod.z.string().optional(),
34
+ fileSize: zod.z.number().int().nonnegative().optional(),
35
+ fileCid: zod.z.string().optional(),
36
+ transactionHash: zod.z.string().optional(),
37
+ gasLimit: zod.z.number().nonnegative().optional(),
38
+ gasPricePerUnit: zod.z.string().optional()
39
+ });
40
+ /**
41
+ * Publish usage events. Provide the relevant fields for your application.
42
+ *
43
+ * Usage in Cloudflare Workers:
44
+ * ctx.waitUntil(
45
+ * publishUsageEvents(
46
+ * [event1, event2],
47
+ * { queueUrl, accessKeyId, secretAccessKey },
48
+ * )
49
+ * )
50
+ *
51
+ * @param usageEvents
52
+ * @param config
53
+ */
54
+ async function publishUsageEvents(usageEvents, config) {
55
+ const {
56
+ queueUrl,
57
+ accessKeyId,
58
+ secretAccessKey,
59
+ region = "us-west-2"
60
+ } = config;
61
+ const entries = usageEvents.map(event => ({
62
+ Id: crypto.randomUUID(),
63
+ MessageBody: JSON.stringify(event)
64
+ }));
65
+ const aws = getAws({
66
+ accessKeyId,
67
+ secretAccessKey,
68
+ region
69
+ });
70
+ const res = await aws.fetch(`https://sqs.${region}.amazonaws.com`, {
71
+ headers: {
72
+ "X-Amz-Target": "AmazonSQS.SendMessageBatch",
73
+ "X-Amz-Date": new Date().toISOString(),
74
+ "Content-Type": "application/x-amz-json-1.0"
75
+ },
76
+ body: JSON.stringify({
77
+ QueueUrl: queueUrl,
78
+ Entries: entries
79
+ })
80
+ });
81
+ return await res.text();
82
+ }
7
83
 
8
84
  const DEFAULT_CACHE_TTL_SECONDS = 60;
9
85
  async function authorizeWorker(authInput, serviceConfig) {
@@ -118,6 +194,31 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
118
194
  function bufferToHex(buffer) {
119
195
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
120
196
  }
197
+ async function logHttpRequest(_ref) {
198
+ let {
199
+ source,
200
+ clientId,
201
+ req,
202
+ res,
203
+ isAuthed,
204
+ statusMessage
205
+ } = _ref;
206
+ const authorizationData = await extractAuthorizationData({
207
+ req,
208
+ clientId
209
+ });
210
+ console.log(JSON.stringify({
211
+ source,
212
+ pathname: req.url,
213
+ hasSecretKey: !!authorizationData.secretKey,
214
+ hasClientId: !!authorizationData.clientId,
215
+ hasJwt: !!authorizationData.jwt,
216
+ clientId: authorizationData.clientId,
217
+ isAuthed: !!isAuthed ?? null,
218
+ status: res.status
219
+ }));
220
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
221
+ }
121
222
 
122
223
  exports.SERVICES = services.SERVICES;
123
224
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -125,4 +226,7 @@ exports.SERVICE_NAMES = services.SERVICE_NAMES;
125
226
  exports.getServiceByName = services.getServiceByName;
126
227
  exports.authorizeWorker = authorizeWorker;
127
228
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
229
+ exports.extractAuthorizationData = extractAuthorizationData;
128
230
  exports.hashSecretKey = hashSecretKey;
231
+ exports.logHttpRequest = logHttpRequest;
232
+ exports.publishUsageEvents = publishUsageEvents;
@@ -1,5 +1,81 @@
1
- import { a as authorize } from '../../dist/index-3a529ebb.esm.js';
1
+ import { a as authorize } from '../../dist/index-60edcd2b.esm.js';
2
2
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
3
+ import { AwsClient } from 'aws4fetch';
4
+ import { z } from 'zod';
5
+
6
+ // Initialize a singleton for aws usage.
7
+ let _aws;
8
+ function getAws(options) {
9
+ if (!_aws) {
10
+ _aws = new AwsClient(options);
11
+ }
12
+ return _aws;
13
+ }
14
+
15
+ /**
16
+ * Types
17
+ */
18
+ z.object({
19
+ source: z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
20
+ action: z.string(),
21
+ accountId: z.string(),
22
+ // Optional
23
+ apiKeyId: z.string().optional(),
24
+ creatorWalletAddress: z.string().optional(),
25
+ clientId: z.string().optional(),
26
+ walletAddress: z.string().optional(),
27
+ chainId: z.number().int().positive().optional(),
28
+ provider: z.string().optional(),
29
+ mimeType: z.string().optional(),
30
+ fileSize: z.number().int().nonnegative().optional(),
31
+ fileCid: z.string().optional(),
32
+ transactionHash: z.string().optional(),
33
+ gasLimit: z.number().nonnegative().optional(),
34
+ gasPricePerUnit: z.string().optional()
35
+ });
36
+ /**
37
+ * Publish usage events. Provide the relevant fields for your application.
38
+ *
39
+ * Usage in Cloudflare Workers:
40
+ * ctx.waitUntil(
41
+ * publishUsageEvents(
42
+ * [event1, event2],
43
+ * { queueUrl, accessKeyId, secretAccessKey },
44
+ * )
45
+ * )
46
+ *
47
+ * @param usageEvents
48
+ * @param config
49
+ */
50
+ async function publishUsageEvents(usageEvents, config) {
51
+ const {
52
+ queueUrl,
53
+ accessKeyId,
54
+ secretAccessKey,
55
+ region = "us-west-2"
56
+ } = config;
57
+ const entries = usageEvents.map(event => ({
58
+ Id: crypto.randomUUID(),
59
+ MessageBody: JSON.stringify(event)
60
+ }));
61
+ const aws = getAws({
62
+ accessKeyId,
63
+ secretAccessKey,
64
+ region
65
+ });
66
+ const res = await aws.fetch(`https://sqs.${region}.amazonaws.com`, {
67
+ headers: {
68
+ "X-Amz-Target": "AmazonSQS.SendMessageBatch",
69
+ "X-Amz-Date": new Date().toISOString(),
70
+ "Content-Type": "application/x-amz-json-1.0"
71
+ },
72
+ body: JSON.stringify({
73
+ QueueUrl: queueUrl,
74
+ Entries: entries
75
+ })
76
+ });
77
+ return await res.text();
78
+ }
3
79
 
4
80
  const DEFAULT_CACHE_TTL_SECONDS = 60;
5
81
  async function authorizeWorker(authInput, serviceConfig) {
@@ -114,5 +190,30 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
114
190
  function bufferToHex(buffer) {
115
191
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
116
192
  }
193
+ async function logHttpRequest(_ref) {
194
+ let {
195
+ source,
196
+ clientId,
197
+ req,
198
+ res,
199
+ isAuthed,
200
+ statusMessage
201
+ } = _ref;
202
+ const authorizationData = await extractAuthorizationData({
203
+ req,
204
+ clientId
205
+ });
206
+ console.log(JSON.stringify({
207
+ source,
208
+ pathname: req.url,
209
+ hasSecretKey: !!authorizationData.secretKey,
210
+ hasClientId: !!authorizationData.clientId,
211
+ hasJwt: !!authorizationData.jwt,
212
+ clientId: authorizationData.clientId,
213
+ isAuthed: !!isAuthed ?? null,
214
+ status: res.status
215
+ }));
216
+ console.log(`statusMessage=${statusMessage ?? res.statusText}`);
217
+ }
117
218
 
118
- export { authorizeWorker, deriveClientIdFromSecretKeyHash, hashSecretKey };
219
+ export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents };
@@ -1,9 +1,11 @@
1
- import type { ExecutionContext, KVNamespace } from "@cloudflare/workers-types";
1
+ import type { ExecutionContext, KVNamespace, Response } from "@cloudflare/workers-types";
2
2
  import type { CoreServiceConfig } from "../core/api";
3
3
  import type { Request } from "@cloudflare/workers-types";
4
+ import type { AuthorizationInput } from "../core/authorize";
4
5
  import type { AuthorizationResult } from "../core/authorize/types";
5
6
  import type { CoreAuthInput } from "../core/types";
6
7
  export * from "../core/services";
8
+ export * from "./usage";
7
9
  type WorkerServiceConfig = CoreServiceConfig & {
8
10
  kvStore: KVNamespace;
9
11
  ctx: ExecutionContext;
@@ -13,6 +15,13 @@ type AuthInput = CoreAuthInput & {
13
15
  req: Request;
14
16
  };
15
17
  export declare function authorizeWorker(authInput: AuthInput, serviceConfig: WorkerServiceConfig): Promise<AuthorizationResult>;
18
+ export declare function extractAuthorizationData(authInput: AuthInput): Promise<AuthorizationInput>;
16
19
  export declare function hashSecretKey(secretKey: string): Promise<string>;
17
20
  export declare function deriveClientIdFromSecretKeyHash(secretKeyHash: string): string;
21
+ export declare function logHttpRequest({ source, clientId, req, res, isAuthed, statusMessage, }: AuthInput & {
22
+ source: string;
23
+ res: Response;
24
+ isAuthed?: boolean;
25
+ statusMessage?: Error | string;
26
+ }): Promise<void>;
18
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,cAAc,kBAAkB,CAAC;AAEjC,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,gBAAgB,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAsB,eAAe,CACnC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAiFD,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
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,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,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;AACjC,cAAc,SAAS,CAAC;AAExB,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,gBAAgB,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAsB,eAAe,CACnC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CA2E7B;AAED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE;AAQD,wBAAsB,cAAc,CAAC,EACnC,MAAM,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,iBAgBA"}
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- import { AwsCredentialIdentity } from "@smithy/types";
3
2
  /**
4
3
  * Types
5
4
  */
@@ -18,7 +17,7 @@ declare const usageEventSchema: z.ZodObject<{
18
17
  fileCid: z.ZodOptional<z.ZodString>;
19
18
  transactionHash: z.ZodOptional<z.ZodString>;
20
19
  gasLimit: z.ZodOptional<z.ZodNumber>;
21
- gasPricePerUnit: z.ZodOptional<z.ZodNumber>;
20
+ gasPricePerUnit: z.ZodOptional<z.ZodString>;
22
21
  }, "strip", z.ZodTypeAny, {
23
22
  source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
24
23
  action: string;
@@ -34,7 +33,7 @@ declare const usageEventSchema: z.ZodObject<{
34
33
  fileCid?: string | undefined;
35
34
  transactionHash?: string | undefined;
36
35
  gasLimit?: number | undefined;
37
- gasPricePerUnit?: number | undefined;
36
+ gasPricePerUnit?: string | undefined;
38
37
  }, {
39
38
  source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
40
39
  action: string;
@@ -50,19 +49,28 @@ declare const usageEventSchema: z.ZodObject<{
50
49
  fileCid?: string | undefined;
51
50
  transactionHash?: string | undefined;
52
51
  gasLimit?: number | undefined;
53
- gasPricePerUnit?: number | undefined;
52
+ gasPricePerUnit?: string | undefined;
54
53
  }>;
55
54
  export type UsageEvent = z.infer<typeof usageEventSchema>;
56
55
  /**
57
56
  * Publish usage events. Provide the relevant fields for your application.
58
57
  *
58
+ * Usage in Cloudflare Workers:
59
+ * ctx.waitUntil(
60
+ * publishUsageEvents(
61
+ * [event1, event2],
62
+ * { queueUrl, accessKeyId, secretAccessKey },
63
+ * )
64
+ * )
65
+ *
59
66
  * @param usageEvents
60
67
  * @param config
61
68
  */
62
69
  export declare function publishUsageEvents(usageEvents: UsageEvent[], config: {
63
70
  queueUrl: string;
71
+ accessKeyId: string;
72
+ secretAccessKey: string;
64
73
  region?: string;
65
- credentials?: AwsCredentialIdentity;
66
- }): Promise<void>;
74
+ }): Promise<string>;
67
75
  export {};
68
76
  //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBpB,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,MAAM,CAAC,CA8BjB"}
@@ -1 +1 @@
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,CAuGrB"}
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,CAwGrB"}
@@ -1,3 +1,2 @@
1
1
  export * from "./core/services";
2
- export * from "./core/usage";
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAGhC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC"}
@@ -4,6 +4,7 @@ import type { AuthorizationInput } from "../core/authorize";
4
4
  import type { CoreServiceConfig } from "../core/api";
5
5
  import type { AuthorizationResult } from "../core/authorize/types";
6
6
  import type { CoreAuthInput } from "../core/types";
7
+ import type { ServerResponse } from "http";
7
8
  export * from "../core/services";
8
9
  type NodeServiceConfig = CoreServiceConfig;
9
10
  export type AuthInput = CoreAuthInput & {
@@ -13,4 +14,10 @@ export declare function authorizeNode(authInput: AuthInput, serviceConfig: NodeS
13
14
  export declare function extractAuthorizationData(authInput: AuthInput): AuthorizationInput;
14
15
  export declare function hashSecretKey(secretKey: string): string;
15
16
  export declare function deriveClientIdFromSecretKeyHash(secretKeyHash: string): string;
17
+ export declare function logHttpRequest({ source, clientId, req, res, isAuthed, statusMessage, }: AuthInput & {
18
+ source: string;
19
+ res: ServerResponse;
20
+ isAuthed?: boolean;
21
+ statusMessage?: Error | string;
22
+ }): void;
16
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,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,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,CAoFpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,cAAc,kBAAkB,CAAC;AAEjC,KAAK,iBAAiB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,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,CAoFpB;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,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAChC,QAkBA"}
@@ -69,7 +69,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
69
69
  if (secretHash !== providedSecretHash) {
70
70
  return {
71
71
  authorized: false,
72
- errorMessage: "The secret is invalid. Please check you secret-key",
72
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
73
73
  errorCode: "SECRET_INVALID",
74
74
  status: 401
75
75
  };
@@ -108,7 +108,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
108
108
  }
109
109
  return {
110
110
  authorized: false,
111
- errorMessage: `The domain: ${origin}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
111
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
112
112
  errorCode: "ORIGIN_UNAUTHORIZED",
113
113
  status: 401
114
114
  };
@@ -128,7 +128,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
128
128
  }
129
129
  return {
130
130
  authorized: false,
131
- errorMessage: `The bundleId: ${bundleId}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
131
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
132
132
  errorCode: "BUNDLE_UNAUTHORIZED",
133
133
  status: 401
134
134
  };
@@ -150,7 +150,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
150
150
  if (!service) {
151
151
  return {
152
152
  authorized: false,
153
- errorMessage: `The service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
153
+ errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
154
154
  errorCode: "SERVICE_UNAUTHORIZED",
155
155
  status: 403
156
156
  };
@@ -162,7 +162,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
162
162
  if (!isActionAllowed) {
163
163
  return {
164
164
  authorized: false,
165
- errorMessage: `The service "${serviceConfig.serviceScope}" action "${serviceConfig.serviceAction}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
165
+ errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
166
166
  errorCode: "SERVICE_ACTION_UNAUTHORIZED",
167
167
  status: 403
168
168
  };
@@ -177,7 +177,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
177
177
  if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
178
178
  return {
179
179
  authorized: false,
180
- errorMessage: `The target address: ${checkedAddresses}, for service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
180
+ errorMessage: `Invalid request: Unauthorized address: ${serviceConfig.serviceScope} ${checkedAddresses}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
181
181
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
182
182
  status: 403
183
183
  };
@@ -270,7 +270,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
270
270
  return {
271
271
  authorized: false,
272
272
  status: 500,
273
- errorMessage: "Failed to account information.",
273
+ errorMessage: "Failed to get account information.",
274
274
  errorCode: "FAILED_TO_ACCOUNT"
275
275
  };
276
276
  }
@@ -71,7 +71,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
71
71
  if (secretHash !== providedSecretHash) {
72
72
  return {
73
73
  authorized: false,
74
- errorMessage: "The secret is invalid. Please check you secret-key",
74
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
75
75
  errorCode: "SECRET_INVALID",
76
76
  status: 401
77
77
  };
@@ -110,7 +110,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
110
110
  }
111
111
  return {
112
112
  authorized: false,
113
- errorMessage: `The domain: ${origin}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
113
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
114
114
  errorCode: "ORIGIN_UNAUTHORIZED",
115
115
  status: 401
116
116
  };
@@ -130,7 +130,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
130
130
  }
131
131
  return {
132
132
  authorized: false,
133
- errorMessage: `The bundleId: ${bundleId}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
133
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
134
134
  errorCode: "BUNDLE_UNAUTHORIZED",
135
135
  status: 401
136
136
  };
@@ -152,7 +152,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
152
152
  if (!service) {
153
153
  return {
154
154
  authorized: false,
155
- errorMessage: `The service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
155
+ errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
156
156
  errorCode: "SERVICE_UNAUTHORIZED",
157
157
  status: 403
158
158
  };
@@ -164,7 +164,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
164
164
  if (!isActionAllowed) {
165
165
  return {
166
166
  authorized: false,
167
- errorMessage: `The service "${serviceConfig.serviceScope}" action "${serviceConfig.serviceAction}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
167
+ errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
168
168
  errorCode: "SERVICE_ACTION_UNAUTHORIZED",
169
169
  status: 403
170
170
  };
@@ -179,7 +179,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
179
179
  if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
180
180
  return {
181
181
  authorized: false,
182
- errorMessage: `The target address: ${checkedAddresses}, for service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
182
+ errorMessage: `Invalid request: Unauthorized address: ${serviceConfig.serviceScope} ${checkedAddresses}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
183
183
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
184
184
  status: 403
185
185
  };
@@ -272,7 +272,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
272
272
  return {
273
273
  authorized: false,
274
274
  status: 500,
275
- errorMessage: "Failed to account information.",
275
+ errorMessage: "Failed to get account information.",
276
276
  errorCode: "FAILED_TO_ACCOUNT"
277
277
  };
278
278
  }
@@ -71,7 +71,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
71
71
  if (secretHash !== providedSecretHash) {
72
72
  return {
73
73
  authorized: false,
74
- errorMessage: "The secret is invalid. Please check you secret-key",
74
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
75
75
  errorCode: "SECRET_INVALID",
76
76
  status: 401
77
77
  };
@@ -110,7 +110,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
110
110
  }
111
111
  return {
112
112
  authorized: false,
113
- errorMessage: `The domain: ${origin}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
113
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
114
114
  errorCode: "ORIGIN_UNAUTHORIZED",
115
115
  status: 401
116
116
  };
@@ -130,7 +130,7 @@ function authorizeClient(authOptions, apiKeyMeta) {
130
130
  }
131
131
  return {
132
132
  authorized: false,
133
- errorMessage: `The bundleId: ${bundleId}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
133
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
134
134
  errorCode: "BUNDLE_UNAUTHORIZED",
135
135
  status: 401
136
136
  };
@@ -152,7 +152,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
152
152
  if (!service) {
153
153
  return {
154
154
  authorized: false,
155
- errorMessage: `The service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
155
+ errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
156
156
  errorCode: "SERVICE_UNAUTHORIZED",
157
157
  status: 403
158
158
  };
@@ -164,7 +164,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
164
164
  if (!isActionAllowed) {
165
165
  return {
166
166
  authorized: false,
167
- errorMessage: `The service "${serviceConfig.serviceScope}" action "${serviceConfig.serviceAction}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
167
+ errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
168
168
  errorCode: "SERVICE_ACTION_UNAUTHORIZED",
169
169
  status: 403
170
170
  };
@@ -179,7 +179,7 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
179
179
  if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
180
180
  return {
181
181
  authorized: false,
182
- errorMessage: `The target address: ${checkedAddresses}, for service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
182
+ errorMessage: `Invalid request: Unauthorized address: ${serviceConfig.serviceScope} ${checkedAddresses}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
183
183
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
184
184
  status: 403
185
185
  };
@@ -272,7 +272,7 @@ async function authorize(authData, serviceConfig, cacheOptions) {
272
272
  return {
273
273
  authorized: false,
274
274
  status: 500,
275
- errorMessage: "Failed to account information.",
275
+ errorMessage: "Failed to get account information.",
276
276
  errorCode: "FAILED_TO_ACCOUNT"
277
277
  };
278
278
  }
@@ -3,74 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var services = require('./services-a3f36057.cjs.dev.js');
6
- var zod = require('zod');
7
- var clientSqs = require('@aws-sdk/client-sqs');
8
- var crypto = require('crypto');
9
6
 
10
- let sqs;
11
- function getSqs(_ref) {
12
- let {
13
- region,
14
- credentials
15
- } = _ref;
16
- if (!sqs) {
17
- sqs = new clientSqs.SQSClient({
18
- region,
19
- credentials
20
- });
21
- }
22
- return sqs;
23
- }
24
7
 
25
- /**
26
- * Types
27
- */
28
- const usageEventSchema = zod.z.object({
29
- source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
30
- action: zod.z.string(),
31
- accountId: zod.z.string(),
32
- // Optional
33
- apiKeyId: zod.z.string().optional(),
34
- creatorWalletAddress: zod.z.string().optional(),
35
- clientId: zod.z.string().optional(),
36
- walletAddress: zod.z.string().optional(),
37
- chainId: zod.z.number().int().positive().optional(),
38
- provider: zod.z.string().optional(),
39
- mimeType: zod.z.string().optional(),
40
- fileSize: zod.z.number().int().nonnegative().optional(),
41
- fileCid: zod.z.string().optional(),
42
- transactionHash: zod.z.string().optional(),
43
- gasLimit: zod.z.number().nonnegative().optional(),
44
- gasPricePerUnit: zod.z.number().nonnegative().optional()
45
- });
46
- /**
47
- * Publish usage events. Provide the relevant fields for your application.
48
- *
49
- * @param usageEvents
50
- * @param config
51
- */
52
- async function publishUsageEvents(usageEvents, config) {
53
- const {
54
- queueUrl,
55
- region = "us-west-2",
56
- credentials
57
- } = config;
58
- const entries = usageEvents.map(event => ({
59
- Id: crypto.randomUUID(),
60
- MessageBody: JSON.stringify(usageEventSchema.parse(event))
61
- }));
62
- const input = new clientSqs.SendMessageBatchCommand({
63
- QueueUrl: queueUrl,
64
- Entries: entries
65
- });
66
- await getSqs({
67
- region,
68
- credentials
69
- }).send(input);
70
- }
71
8
 
72
9
  exports.SERVICES = services.SERVICES;
73
10
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
74
11
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
75
12
  exports.getServiceByName = services.getServiceByName;
76
- exports.publishUsageEvents = publishUsageEvents;
@@ -3,74 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var services = require('./services-9e185105.cjs.prod.js');
6
- var zod = require('zod');
7
- var clientSqs = require('@aws-sdk/client-sqs');
8
- var crypto = require('crypto');
9
6
 
10
- let sqs;
11
- function getSqs(_ref) {
12
- let {
13
- region,
14
- credentials
15
- } = _ref;
16
- if (!sqs) {
17
- sqs = new clientSqs.SQSClient({
18
- region,
19
- credentials
20
- });
21
- }
22
- return sqs;
23
- }
24
7
 
25
- /**
26
- * Types
27
- */
28
- const usageEventSchema = zod.z.object({
29
- source: zod.z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
30
- action: zod.z.string(),
31
- accountId: zod.z.string(),
32
- // Optional
33
- apiKeyId: zod.z.string().optional(),
34
- creatorWalletAddress: zod.z.string().optional(),
35
- clientId: zod.z.string().optional(),
36
- walletAddress: zod.z.string().optional(),
37
- chainId: zod.z.number().int().positive().optional(),
38
- provider: zod.z.string().optional(),
39
- mimeType: zod.z.string().optional(),
40
- fileSize: zod.z.number().int().nonnegative().optional(),
41
- fileCid: zod.z.string().optional(),
42
- transactionHash: zod.z.string().optional(),
43
- gasLimit: zod.z.number().nonnegative().optional(),
44
- gasPricePerUnit: zod.z.number().nonnegative().optional()
45
- });
46
- /**
47
- * Publish usage events. Provide the relevant fields for your application.
48
- *
49
- * @param usageEvents
50
- * @param config
51
- */
52
- async function publishUsageEvents(usageEvents, config) {
53
- const {
54
- queueUrl,
55
- region = "us-west-2",
56
- credentials
57
- } = config;
58
- const entries = usageEvents.map(event => ({
59
- Id: crypto.randomUUID(),
60
- MessageBody: JSON.stringify(usageEventSchema.parse(event))
61
- }));
62
- const input = new clientSqs.SendMessageBatchCommand({
63
- QueueUrl: queueUrl,
64
- Entries: entries
65
- });
66
- await getSqs({
67
- region,
68
- credentials
69
- }).send(input);
70
- }
71
8
 
72
9
  exports.SERVICES = services.SERVICES;
73
10
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
74
11
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
75
12
  exports.getServiceByName = services.getServiceByName;
76
- exports.publishUsageEvents = publishUsageEvents;
@@ -1,68 +1 @@
1
1
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from './services-86283509.esm.js';
2
- import { z } from 'zod';
3
- import { SendMessageBatchCommand, SQSClient } from '@aws-sdk/client-sqs';
4
- import { randomUUID } from 'crypto';
5
-
6
- let sqs;
7
- function getSqs(_ref) {
8
- let {
9
- region,
10
- credentials
11
- } = _ref;
12
- if (!sqs) {
13
- sqs = new SQSClient({
14
- region,
15
- credentials
16
- });
17
- }
18
- return sqs;
19
- }
20
-
21
- /**
22
- * Types
23
- */
24
- const usageEventSchema = z.object({
25
- source: z.enum(["wallet", "rpc", "storage", "bundler", "paymaster", "relayer"]),
26
- action: z.string(),
27
- accountId: z.string(),
28
- // Optional
29
- apiKeyId: z.string().optional(),
30
- creatorWalletAddress: z.string().optional(),
31
- clientId: z.string().optional(),
32
- walletAddress: z.string().optional(),
33
- chainId: z.number().int().positive().optional(),
34
- provider: z.string().optional(),
35
- mimeType: z.string().optional(),
36
- fileSize: z.number().int().nonnegative().optional(),
37
- fileCid: z.string().optional(),
38
- transactionHash: z.string().optional(),
39
- gasLimit: z.number().nonnegative().optional(),
40
- gasPricePerUnit: z.number().nonnegative().optional()
41
- });
42
- /**
43
- * Publish usage events. Provide the relevant fields for your application.
44
- *
45
- * @param usageEvents
46
- * @param config
47
- */
48
- async function publishUsageEvents(usageEvents, config) {
49
- const {
50
- queueUrl,
51
- region = "us-west-2",
52
- credentials
53
- } = config;
54
- const entries = usageEvents.map(event => ({
55
- Id: randomUUID(),
56
- MessageBody: JSON.stringify(usageEventSchema.parse(event))
57
- }));
58
- const input = new SendMessageBatchCommand({
59
- QueueUrl: queueUrl,
60
- Entries: entries
61
- });
62
- await getSqs({
63
- region,
64
- credentials
65
- }).send(input);
66
- }
67
-
68
- export { publishUsageEvents };
@@ -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-8a9496b0.cjs.dev.js');
6
+ var index = require('../../dist/index-e83fdf2d.cjs.dev.js');
7
7
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -117,6 +117,33 @@ function hashSecretKey(secretKey) {
117
117
  function deriveClientIdFromSecretKeyHash(secretKeyHash) {
118
118
  return secretKeyHash.slice(0, 32);
119
119
  }
120
+ function logHttpRequest(_ref) {
121
+ let {
122
+ source,
123
+ clientId,
124
+ req,
125
+ res,
126
+ isAuthed,
127
+ statusMessage
128
+ } = _ref;
129
+ const authorizationData = extractAuthorizationData({
130
+ req,
131
+ clientId
132
+ });
133
+ const _statusMessage = statusMessage ?? res.statusMessage;
134
+ console.log(JSON.stringify({
135
+ source,
136
+ pathname: req.url,
137
+ hasSecretKey: !!authorizationData.secretKey,
138
+ hasClientId: !!authorizationData.clientId,
139
+ hasJwt: !!authorizationData.jwt,
140
+ clientId: authorizationData.clientId,
141
+ isAuthed: !!isAuthed ?? null,
142
+ status: res.statusCode,
143
+ statusMessage: _statusMessage
144
+ }));
145
+ console.log(`statusMessage=${_statusMessage}`);
146
+ }
120
147
 
121
148
  exports.SERVICES = services.SERVICES;
122
149
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -126,3 +153,4 @@ exports.authorizeNode = authorizeNode;
126
153
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
127
154
  exports.extractAuthorizationData = extractAuthorizationData;
128
155
  exports.hashSecretKey = hashSecretKey;
156
+ exports.logHttpRequest = logHttpRequest;
@@ -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-92289057.cjs.prod.js');
6
+ var index = require('../../dist/index-bb16a39e.cjs.prod.js');
7
7
  var services = require('../../dist/services-9e185105.cjs.prod.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -117,6 +117,33 @@ function hashSecretKey(secretKey) {
117
117
  function deriveClientIdFromSecretKeyHash(secretKeyHash) {
118
118
  return secretKeyHash.slice(0, 32);
119
119
  }
120
+ function logHttpRequest(_ref) {
121
+ let {
122
+ source,
123
+ clientId,
124
+ req,
125
+ res,
126
+ isAuthed,
127
+ statusMessage
128
+ } = _ref;
129
+ const authorizationData = extractAuthorizationData({
130
+ req,
131
+ clientId
132
+ });
133
+ const _statusMessage = statusMessage ?? res.statusMessage;
134
+ console.log(JSON.stringify({
135
+ source,
136
+ pathname: req.url,
137
+ hasSecretKey: !!authorizationData.secretKey,
138
+ hasClientId: !!authorizationData.clientId,
139
+ hasJwt: !!authorizationData.jwt,
140
+ clientId: authorizationData.clientId,
141
+ isAuthed: !!isAuthed ?? null,
142
+ status: res.statusCode,
143
+ statusMessage: _statusMessage
144
+ }));
145
+ console.log(`statusMessage=${_statusMessage}`);
146
+ }
120
147
 
121
148
  exports.SERVICES = services.SERVICES;
122
149
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -126,3 +153,4 @@ exports.authorizeNode = authorizeNode;
126
153
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
127
154
  exports.extractAuthorizationData = extractAuthorizationData;
128
155
  exports.hashSecretKey = hashSecretKey;
156
+ exports.logHttpRequest = logHttpRequest;
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { a as authorize } from '../../dist/index-3a529ebb.esm.js';
2
+ import { a as authorize } from '../../dist/index-60edcd2b.esm.js';
3
3
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
4
4
 
5
5
  async function authorizeNode(authInput, serviceConfig) {
@@ -113,5 +113,32 @@ function hashSecretKey(secretKey) {
113
113
  function deriveClientIdFromSecretKeyHash(secretKeyHash) {
114
114
  return secretKeyHash.slice(0, 32);
115
115
  }
116
+ function logHttpRequest(_ref) {
117
+ let {
118
+ source,
119
+ clientId,
120
+ req,
121
+ res,
122
+ isAuthed,
123
+ statusMessage
124
+ } = _ref;
125
+ const authorizationData = extractAuthorizationData({
126
+ req,
127
+ clientId
128
+ });
129
+ const _statusMessage = statusMessage ?? res.statusMessage;
130
+ console.log(JSON.stringify({
131
+ source,
132
+ pathname: req.url,
133
+ hasSecretKey: !!authorizationData.secretKey,
134
+ hasClientId: !!authorizationData.clientId,
135
+ hasJwt: !!authorizationData.jwt,
136
+ clientId: authorizationData.clientId,
137
+ isAuthed: !!isAuthed ?? null,
138
+ status: res.statusCode,
139
+ statusMessage: _statusMessage
140
+ }));
141
+ console.log(`statusMessage=${_statusMessage}`);
142
+ }
116
143
 
117
- export { authorizeNode, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey };
144
+ export { authorizeNode, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.0.0-dev-ea3157f-20230802203753",
3
+ "version": "0.0.0-dev-bd971e7-20230807183752",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "typescript": "^5.1.6"
56
56
  },
57
57
  "dependencies": {
58
- "@aws-sdk/client-sqs": "^3.379.1",
58
+ "aws4fetch": "^1.0.17",
59
59
  "zod": "^3.20.2"
60
60
  },
61
61
  "scripts": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"usage.d.ts","sourceRoot":"../../../../src/core","sources":["usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAkBtD;;GAEG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBpB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE;IACN,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC,GACA,OAAO,CAAC,IAAI,CAAC,CAaf"}