@thirdweb-dev/service-utils 0.0.0-dev-c3925f3-20230905155015 → 0.0.0-dev-c57f450-20230913125903
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 +54 -1
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +54 -1
- package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +54 -2
- package/dist/declarations/src/cf-worker/index.d.ts +3 -1
- package/dist/declarations/src/cf-worker/index.d.ts.map +1 -1
- package/dist/declarations/src/cf-worker/usage.d.ts +2 -2
- package/dist/declarations/src/core/api.d.ts +16 -1
- package/dist/declarations/src/core/api.d.ts.map +1 -1
- package/dist/declarations/src/core/rateLimit/index.d.ts +9 -0
- package/dist/declarations/src/core/rateLimit/index.d.ts.map +1 -0
- package/dist/declarations/src/core/rateLimit/types.d.ts +9 -0
- package/dist/declarations/src/core/rateLimit/types.d.ts.map +1 -0
- package/dist/declarations/src/node/index.d.ts +19 -2
- package/dist/declarations/src/node/index.d.ts.map +1 -1
- package/dist/{index-ffddf746.esm.js → index-3f3d50f4.esm.js} +20 -1
- package/dist/{index-6e0ecc5f.cjs.prod.js → index-4b7b94ff.cjs.prod.js} +20 -0
- package/dist/{index-cd4f96ef.cjs.dev.js → index-e1d8f989.cjs.dev.js} +20 -0
- package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +18 -1
- package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +18 -1
- package/node/dist/thirdweb-dev-service-utils-node.esm.js +18 -1
- package/package.json +2 -1
@@ -2,11 +2,53 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-e1d8f989.cjs.dev.js');
|
6
6
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
7
7
|
var aws4fetch = require('aws4fetch');
|
8
8
|
var zod = require('zod');
|
9
9
|
|
10
|
+
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
11
|
+
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
12
|
+
const {
|
13
|
+
id,
|
14
|
+
rateLimits,
|
15
|
+
accountId
|
16
|
+
} = apiKeyMeta;
|
17
|
+
const {
|
18
|
+
serviceScope
|
19
|
+
} = serviceConfig;
|
20
|
+
const limit = rateLimits[serviceScope];
|
21
|
+
if (limit === undefined) {
|
22
|
+
// No rate limit is provided. Assume the request is not rate limited.
|
23
|
+
return {
|
24
|
+
rateLimited: false
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
// Floors the current time to the nearest DEFAULT_RATE_LIMIT_WINDOW_SECONDS.
|
29
|
+
const bucketId = Math.floor(Date.now() / (1000 * DEFAULT_RATE_LIMIT_WINDOW_SECONDS)) * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
30
|
+
const key = [serviceScope, accountId, bucketId].join(":");
|
31
|
+
const value = parseInt((await cacheOptions.get(key)) || "0");
|
32
|
+
const current = value + 1;
|
33
|
+
|
34
|
+
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
35
|
+
if (current > limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS) {
|
36
|
+
// report rate limit hits
|
37
|
+
await index.updateRateLimitedAt(id, serviceConfig);
|
38
|
+
return {
|
39
|
+
rateLimited: true,
|
40
|
+
status: 429,
|
41
|
+
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.`,
|
42
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
43
|
+
};
|
44
|
+
} else {
|
45
|
+
await cacheOptions.put(key, current.toString());
|
46
|
+
}
|
47
|
+
return {
|
48
|
+
rateLimited: false
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
10
52
|
// Initialize a singleton for aws usage.
|
11
53
|
let _aws;
|
12
54
|
function getAws(options) {
|
@@ -86,6 +128,8 @@ async function publishUsageEvents(usageEvents, config) {
|
|
86
128
|
}
|
87
129
|
|
88
130
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
131
|
+
// must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
132
|
+
const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
|
89
133
|
async function authorizeWorker(authInput, serviceConfig) {
|
90
134
|
let authData;
|
91
135
|
try {
|
@@ -117,6 +161,14 @@ async function authorizeWorker(authInput, serviceConfig) {
|
|
117
161
|
cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
|
118
162
|
});
|
119
163
|
}
|
164
|
+
async function rateLimitWorker(apiKeyMeta, serviceConfig) {
|
165
|
+
return await rateLimit(apiKeyMeta, serviceConfig, {
|
166
|
+
get: async bucketId => serviceConfig.kvStore.get(bucketId),
|
167
|
+
put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
|
168
|
+
expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
|
169
|
+
})
|
170
|
+
});
|
171
|
+
}
|
120
172
|
async function extractAuthorizationData(authInput) {
|
121
173
|
const requestUrl = new URL(authInput.req.url);
|
122
174
|
const headers = authInput.req.headers;
|
@@ -238,3 +290,4 @@ exports.extractAuthorizationData = extractAuthorizationData;
|
|
238
290
|
exports.hashSecretKey = hashSecretKey;
|
239
291
|
exports.logHttpRequest = logHttpRequest;
|
240
292
|
exports.publishUsageEvents = publishUsageEvents;
|
293
|
+
exports.rateLimitWorker = rateLimitWorker;
|
@@ -2,11 +2,53 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var index = require('../../dist/index-
|
5
|
+
var index = require('../../dist/index-4b7b94ff.cjs.prod.js');
|
6
6
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
7
7
|
var aws4fetch = require('aws4fetch');
|
8
8
|
var zod = require('zod');
|
9
9
|
|
10
|
+
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
11
|
+
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
12
|
+
const {
|
13
|
+
id,
|
14
|
+
rateLimits,
|
15
|
+
accountId
|
16
|
+
} = apiKeyMeta;
|
17
|
+
const {
|
18
|
+
serviceScope
|
19
|
+
} = serviceConfig;
|
20
|
+
const limit = rateLimits[serviceScope];
|
21
|
+
if (limit === undefined) {
|
22
|
+
// No rate limit is provided. Assume the request is not rate limited.
|
23
|
+
return {
|
24
|
+
rateLimited: false
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
// Floors the current time to the nearest DEFAULT_RATE_LIMIT_WINDOW_SECONDS.
|
29
|
+
const bucketId = Math.floor(Date.now() / (1000 * DEFAULT_RATE_LIMIT_WINDOW_SECONDS)) * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
30
|
+
const key = [serviceScope, accountId, bucketId].join(":");
|
31
|
+
const value = parseInt((await cacheOptions.get(key)) || "0");
|
32
|
+
const current = value + 1;
|
33
|
+
|
34
|
+
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
35
|
+
if (current > limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS) {
|
36
|
+
// report rate limit hits
|
37
|
+
await index.updateRateLimitedAt(id, serviceConfig);
|
38
|
+
return {
|
39
|
+
rateLimited: true,
|
40
|
+
status: 429,
|
41
|
+
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.`,
|
42
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
43
|
+
};
|
44
|
+
} else {
|
45
|
+
await cacheOptions.put(key, current.toString());
|
46
|
+
}
|
47
|
+
return {
|
48
|
+
rateLimited: false
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
10
52
|
// Initialize a singleton for aws usage.
|
11
53
|
let _aws;
|
12
54
|
function getAws(options) {
|
@@ -86,6 +128,8 @@ async function publishUsageEvents(usageEvents, config) {
|
|
86
128
|
}
|
87
129
|
|
88
130
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
131
|
+
// must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
132
|
+
const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
|
89
133
|
async function authorizeWorker(authInput, serviceConfig) {
|
90
134
|
let authData;
|
91
135
|
try {
|
@@ -117,6 +161,14 @@ async function authorizeWorker(authInput, serviceConfig) {
|
|
117
161
|
cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
|
118
162
|
});
|
119
163
|
}
|
164
|
+
async function rateLimitWorker(apiKeyMeta, serviceConfig) {
|
165
|
+
return await rateLimit(apiKeyMeta, serviceConfig, {
|
166
|
+
get: async bucketId => serviceConfig.kvStore.get(bucketId),
|
167
|
+
put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
|
168
|
+
expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
|
169
|
+
})
|
170
|
+
});
|
171
|
+
}
|
120
172
|
async function extractAuthorizationData(authInput) {
|
121
173
|
const requestUrl = new URL(authInput.req.url);
|
122
174
|
const headers = authInput.req.headers;
|
@@ -238,3 +290,4 @@ exports.extractAuthorizationData = extractAuthorizationData;
|
|
238
290
|
exports.hashSecretKey = hashSecretKey;
|
239
291
|
exports.logHttpRequest = logHttpRequest;
|
240
292
|
exports.publishUsageEvents = publishUsageEvents;
|
293
|
+
exports.rateLimitWorker = rateLimitWorker;
|
@@ -1,8 +1,50 @@
|
|
1
|
-
import { a as authorize } from '../../dist/index-
|
1
|
+
import { u as updateRateLimitedAt, a as authorize } from '../../dist/index-3f3d50f4.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
3
|
import { AwsClient } from 'aws4fetch';
|
4
4
|
import { z } from 'zod';
|
5
5
|
|
6
|
+
const DEFAULT_RATE_LIMIT_WINDOW_SECONDS = 10;
|
7
|
+
async function rateLimit(apiKeyMeta, serviceConfig, cacheOptions) {
|
8
|
+
const {
|
9
|
+
id,
|
10
|
+
rateLimits,
|
11
|
+
accountId
|
12
|
+
} = apiKeyMeta;
|
13
|
+
const {
|
14
|
+
serviceScope
|
15
|
+
} = serviceConfig;
|
16
|
+
const limit = rateLimits[serviceScope];
|
17
|
+
if (limit === undefined) {
|
18
|
+
// No rate limit is provided. Assume the request is not rate limited.
|
19
|
+
return {
|
20
|
+
rateLimited: false
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
// Floors the current time to the nearest DEFAULT_RATE_LIMIT_WINDOW_SECONDS.
|
25
|
+
const bucketId = Math.floor(Date.now() / (1000 * DEFAULT_RATE_LIMIT_WINDOW_SECONDS)) * DEFAULT_RATE_LIMIT_WINDOW_SECONDS;
|
26
|
+
const key = [serviceScope, accountId, bucketId].join(":");
|
27
|
+
const value = parseInt((await cacheOptions.get(key)) || "0");
|
28
|
+
const current = value + 1;
|
29
|
+
|
30
|
+
// limit is in seconds, but we need in DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
31
|
+
if (current > limit * DEFAULT_RATE_LIMIT_WINDOW_SECONDS) {
|
32
|
+
// report rate limit hits
|
33
|
+
await updateRateLimitedAt(id, serviceConfig);
|
34
|
+
return {
|
35
|
+
rateLimited: true,
|
36
|
+
status: 429,
|
37
|
+
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.`,
|
38
|
+
errorCode: "RATE_LIMIT_EXCEEDED"
|
39
|
+
};
|
40
|
+
} else {
|
41
|
+
await cacheOptions.put(key, current.toString());
|
42
|
+
}
|
43
|
+
return {
|
44
|
+
rateLimited: false
|
45
|
+
};
|
46
|
+
}
|
47
|
+
|
6
48
|
// Initialize a singleton for aws usage.
|
7
49
|
let _aws;
|
8
50
|
function getAws(options) {
|
@@ -82,6 +124,8 @@ async function publishUsageEvents(usageEvents, config) {
|
|
82
124
|
}
|
83
125
|
|
84
126
|
const DEFAULT_CACHE_TTL_SECONDS = 60;
|
127
|
+
// must be > DEFAULT_RATE_LIMIT_WINDOW_SECONDS
|
128
|
+
const DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS = 60;
|
85
129
|
async function authorizeWorker(authInput, serviceConfig) {
|
86
130
|
let authData;
|
87
131
|
try {
|
@@ -113,6 +157,14 @@ async function authorizeWorker(authInput, serviceConfig) {
|
|
113
157
|
cacheTtlSeconds: serviceConfig.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS
|
114
158
|
});
|
115
159
|
}
|
160
|
+
async function rateLimitWorker(apiKeyMeta, serviceConfig) {
|
161
|
+
return await rateLimit(apiKeyMeta, serviceConfig, {
|
162
|
+
get: async bucketId => serviceConfig.kvStore.get(bucketId),
|
163
|
+
put: (bucketId, count) => serviceConfig.kvStore.put(bucketId, count, {
|
164
|
+
expirationTtl: DEFAULT_RATE_LIMIT_CACHE_TTL_SECONDS
|
165
|
+
})
|
166
|
+
});
|
167
|
+
}
|
116
168
|
async function extractAuthorizationData(authInput) {
|
117
169
|
const requestUrl = new URL(authInput.req.url);
|
118
170
|
const headers = authInput.req.headers;
|
@@ -224,4 +276,4 @@ async function logHttpRequest(_ref) {
|
|
224
276
|
console.log(`statusMessage=${statusMessage ?? res.statusText}`);
|
225
277
|
}
|
226
278
|
|
227
|
-
export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents };
|
279
|
+
export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents, rateLimitWorker };
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import type { ExecutionContext, KVNamespace, Response } from "@cloudflare/workers-types";
|
2
|
-
import type { CoreServiceConfig } from "../core/api";
|
2
|
+
import type { ApiKeyMetadata, 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
8
|
export * from "../core/services";
|
8
9
|
export * from "./usage";
|
@@ -15,6 +16,7 @@ type AuthInput = CoreAuthInput & {
|
|
15
16
|
req: Request;
|
16
17
|
};
|
17
18
|
export declare function authorizeWorker(authInput: AuthInput, serviceConfig: WorkerServiceConfig): Promise<AuthorizationResult>;
|
19
|
+
export declare function rateLimitWorker(apiKeyMeta: ApiKeyMetadata, serviceConfig: WorkerServiceConfig): Promise<RateLimitResult>;
|
18
20
|
export declare function extractAuthorizationData(authInput: AuthInput): Promise<AuthorizationInput>;
|
19
21
|
export declare function hashSecretKey(secretKey: string): Promise<string>;
|
20
22
|
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,2BAA2B,CAAC;AACnC,OAAO,KAAK,
|
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,EACV,cAAc,EAEd,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,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,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;AAMF,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,eAAe,CACnC,UAAU,EAAE,cAAc,EAC1B,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,eAAe,CAAC,CAQ1B;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,iBAoBA"}
|
@@ -21,8 +21,8 @@ declare const usageEventSchema: z.ZodObject<{
|
|
21
21
|
userOpHash: z.ZodOptional<z.ZodString>;
|
22
22
|
}, "strip", z.ZodTypeAny, {
|
23
23
|
source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
|
24
|
-
action: string;
|
25
24
|
accountId: string;
|
25
|
+
action: string;
|
26
26
|
apiKeyId?: string | undefined;
|
27
27
|
creatorWalletAddress?: string | undefined;
|
28
28
|
clientId?: string | undefined;
|
@@ -38,8 +38,8 @@ declare const usageEventSchema: z.ZodObject<{
|
|
38
38
|
userOpHash?: string | undefined;
|
39
39
|
}, {
|
40
40
|
source: "storage" | "rpc" | "bundler" | "relayer" | "wallet" | "paymaster";
|
41
|
-
action: string;
|
42
41
|
accountId: string;
|
42
|
+
action: string;
|
43
43
|
apiKeyId?: string | undefined;
|
44
44
|
creatorWalletAddress?: string | undefined;
|
45
45
|
clientId?: string | undefined;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ServiceName } from "./services";
|
2
2
|
export type CoreServiceConfig = {
|
3
|
-
enforceAuth
|
3
|
+
enforceAuth?: boolean;
|
4
4
|
apiUrl: string;
|
5
5
|
serviceScope: ServiceName;
|
6
6
|
serviceApiKey: string;
|
@@ -23,6 +23,20 @@ export type ApiKeyMetadata = {
|
|
23
23
|
targetAddresses: string[];
|
24
24
|
actions: string[];
|
25
25
|
}[];
|
26
|
+
usage?: {
|
27
|
+
bundler?: {
|
28
|
+
chainId: number;
|
29
|
+
sumTransactionFee: number;
|
30
|
+
}[];
|
31
|
+
storage?: {
|
32
|
+
sumFileSizeBytes: number;
|
33
|
+
};
|
34
|
+
embeddedWallets?: {
|
35
|
+
countWalletAddresses: number;
|
36
|
+
};
|
37
|
+
};
|
38
|
+
limits: Partial<Record<ServiceName, number>>;
|
39
|
+
rateLimits: Partial<Record<ServiceName, number>>;
|
26
40
|
};
|
27
41
|
export type AccountMetadata = {
|
28
42
|
id: string;
|
@@ -47,4 +61,5 @@ 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>;
|
50
65
|
//# 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;AAE9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"../../../../src/core","sources":["api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,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,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,EAAE,CAAC;IACJ,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE;YACR,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,MAAM,CAAC;SAC3B,EAAE,CAAC;QACJ,OAAO,CAAC,EAAE;YACR,gBAAgB,EAAE,MAAM,CAAC;SAC1B,CAAC;QACF,eAAe,CAAC,EAAE;YAChB,oBAAoB,EAAE,MAAM,CAAC;SAC9B,CAAC;KACH,CAAC;IACF,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,WAAW,CAAC,CAqBtB;AAED,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,OAAO,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAwB7B;AAED,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ApiKeyMetadata, CoreServiceConfig } from "../api";
|
2
|
+
import { RateLimitResult } from "./types";
|
3
|
+
type CacheOptions = {
|
4
|
+
get: (bucketId: string) => Promise<string | null>;
|
5
|
+
put: (bucketId: string, count: string) => Promise<void> | void;
|
6
|
+
};
|
7
|
+
export declare function rateLimit(apiKeyMeta: ApiKeyMetadata, serviceConfig: CoreServiceConfig, cacheOptions: CacheOptions): Promise<RateLimitResult>;
|
8
|
+
export {};
|
9
|
+
//# 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,cAAc,EAAE,iBAAiB,EAAuB,MAAM,QAAQ,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI1C,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,CAsC1B"}
|
@@ -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"}
|
@@ -1,15 +1,32 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
+
import type { ServerResponse } from "http";
|
2
3
|
import type { IncomingMessage } from "node:http";
|
3
|
-
import type { AuthorizationInput } from "../core/authorize";
|
4
4
|
import type { CoreServiceConfig } from "../core/api";
|
5
|
+
import type { AuthorizationInput } from "../core/authorize";
|
5
6
|
import type { AuthorizationResult } from "../core/authorize/types";
|
6
7
|
import type { CoreAuthInput } from "../core/types";
|
7
|
-
import type { ServerResponse } from "http";
|
8
8
|
export * from "../core/services";
|
9
9
|
type NodeServiceConfig = CoreServiceConfig;
|
10
10
|
export type AuthInput = CoreAuthInput & {
|
11
11
|
req: IncomingMessage;
|
12
12
|
};
|
13
|
+
/**
|
14
|
+
*
|
15
|
+
* @param {AuthInput['req']} authInput.req - The incoming request from which information will be pulled from. These information includes (checks are in order and terminates on first match):
|
16
|
+
* - clientId: Checks header `x-client-id`, search param `clientId`
|
17
|
+
* - bundleId: Checks header `x-bundle-id`, search param `bundleId`
|
18
|
+
* - secretKey: Checks header `x-secret-key`
|
19
|
+
* - origin (the requesting domain): Checks header `origin`, `referer`
|
20
|
+
* @param {AuthInput['clientId']} authInput.clientId - Overrides any clientId found on the `req` object
|
21
|
+
* @param {AuthInput['targetAddress']} authInput.targetAddress - Only used in smart wallets to determine if the request is authorized to interact with the target address.
|
22
|
+
* @param {NodeServiceConfig['enforceAuth']} serviceConfig - Always `true` unless you need to turn auth off. Tells the service whether or not to enforce auth.
|
23
|
+
* @param {NodeServiceConfig['apiUrl']} serviceConfig.apiUrl - The url of the api server to fetch information for verification. `https://api.thirdweb.com` for production and `https://api.staging.thirdweb.com` for staging
|
24
|
+
* @param {NodeServiceConfig['serviceApiKey']} serviceConfig.serviceApiKey - secret key to be used authenticate the caller of the api-server. Check the api-server's env variable for the keys.
|
25
|
+
* @param {NodeServiceConfig['serviceScope']} serviceConfig.serviceScope - The service that we are requesting authorization for. E.g. `relayer`, `rpc`, 'bundler', 'storage' etc.
|
26
|
+
* @param {NodeServiceConfig['serviceAction']} serviceConfig.serviceAction - Needed when the `serviceScope` is `storage`. Can be either `read` or `write`.
|
27
|
+
* @param {NodeServiceConfig['useWalletAuth']} serviceConfig.useWalletAuth - If true it pings the `wallet/me` or else, `account/me`. You most likely can leave this as false.
|
28
|
+
* @returns {AuthorizationResult} authorizationResult - contains if the request is authorized, and information about the account if it is authorized. Otherwise, it contains the error message and status code.
|
29
|
+
*/
|
13
30
|
export declare function authorizeNode(authInput: AuthInput, serviceConfig: NodeServiceConfig): Promise<AuthorizationResult>;
|
14
31
|
export declare function extractAuthorizationData(authInput: AuthInput): AuthorizationInput;
|
15
32
|
export declare function hashSecretKey(secretKey: string): string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,
|
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,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAChC,QAsBA"}
|
@@ -42,6 +42,25 @@ async function fetchAccountFromApi(jwt, config, useWalletAuth) {
|
|
42
42
|
}
|
43
43
|
return json;
|
44
44
|
}
|
45
|
+
async function updateRateLimitedAt(apiKeyId, config) {
|
46
|
+
const {
|
47
|
+
apiUrl,
|
48
|
+
serviceScope: scope,
|
49
|
+
serviceApiKey
|
50
|
+
} = config;
|
51
|
+
const url = `${apiUrl}/usage/rateLimit`;
|
52
|
+
await fetch(url, {
|
53
|
+
method: "PUT",
|
54
|
+
headers: {
|
55
|
+
"x-service-api-key": serviceApiKey,
|
56
|
+
"content-type": "application/json"
|
57
|
+
},
|
58
|
+
body: JSON.stringify({
|
59
|
+
apiKeyId,
|
60
|
+
scope
|
61
|
+
})
|
62
|
+
});
|
63
|
+
}
|
45
64
|
|
46
65
|
function authorizeClient(authOptions, apiKeyMeta) {
|
47
66
|
const {
|
@@ -419,4 +438,4 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
419
438
|
};
|
420
439
|
}
|
421
440
|
|
422
|
-
export { authorize as a };
|
441
|
+
export { authorize as a, updateRateLimitedAt as u };
|
@@ -44,6 +44,25 @@ async function fetchAccountFromApi(jwt, config, useWalletAuth) {
|
|
44
44
|
}
|
45
45
|
return json;
|
46
46
|
}
|
47
|
+
async function updateRateLimitedAt(apiKeyId, config) {
|
48
|
+
const {
|
49
|
+
apiUrl,
|
50
|
+
serviceScope: scope,
|
51
|
+
serviceApiKey
|
52
|
+
} = config;
|
53
|
+
const url = `${apiUrl}/usage/rateLimit`;
|
54
|
+
await fetch(url, {
|
55
|
+
method: "PUT",
|
56
|
+
headers: {
|
57
|
+
"x-service-api-key": serviceApiKey,
|
58
|
+
"content-type": "application/json"
|
59
|
+
},
|
60
|
+
body: JSON.stringify({
|
61
|
+
apiKeyId,
|
62
|
+
scope
|
63
|
+
})
|
64
|
+
});
|
65
|
+
}
|
47
66
|
|
48
67
|
function authorizeClient(authOptions, apiKeyMeta) {
|
49
68
|
const {
|
@@ -422,3 +441,4 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
422
441
|
}
|
423
442
|
|
424
443
|
exports.authorize = authorize;
|
444
|
+
exports.updateRateLimitedAt = updateRateLimitedAt;
|
@@ -44,6 +44,25 @@ async function fetchAccountFromApi(jwt, config, useWalletAuth) {
|
|
44
44
|
}
|
45
45
|
return json;
|
46
46
|
}
|
47
|
+
async function updateRateLimitedAt(apiKeyId, config) {
|
48
|
+
const {
|
49
|
+
apiUrl,
|
50
|
+
serviceScope: scope,
|
51
|
+
serviceApiKey
|
52
|
+
} = config;
|
53
|
+
const url = `${apiUrl}/usage/rateLimit`;
|
54
|
+
await fetch(url, {
|
55
|
+
method: "PUT",
|
56
|
+
headers: {
|
57
|
+
"x-service-api-key": serviceApiKey,
|
58
|
+
"content-type": "application/json"
|
59
|
+
},
|
60
|
+
body: JSON.stringify({
|
61
|
+
apiKeyId,
|
62
|
+
scope
|
63
|
+
})
|
64
|
+
});
|
65
|
+
}
|
47
66
|
|
48
67
|
function authorizeClient(authOptions, apiKeyMeta) {
|
49
68
|
const {
|
@@ -422,3 +441,4 @@ async function authorize(authData, serviceConfig, cacheOptions) {
|
|
422
441
|
}
|
423
442
|
|
424
443
|
exports.authorize = authorize;
|
444
|
+
exports.updateRateLimitedAt = updateRateLimitedAt;
|
@@ -3,9 +3,26 @@
|
|
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-e1d8f989.cjs.dev.js');
|
7
7
|
var services = require('../../dist/services-a3f36057.cjs.dev.js');
|
8
8
|
|
9
|
+
/**
|
10
|
+
*
|
11
|
+
* @param {AuthInput['req']} authInput.req - The incoming request from which information will be pulled from. These information includes (checks are in order and terminates on first match):
|
12
|
+
* - clientId: Checks header `x-client-id`, search param `clientId`
|
13
|
+
* - bundleId: Checks header `x-bundle-id`, search param `bundleId`
|
14
|
+
* - secretKey: Checks header `x-secret-key`
|
15
|
+
* - origin (the requesting domain): Checks header `origin`, `referer`
|
16
|
+
* @param {AuthInput['clientId']} authInput.clientId - Overrides any clientId found on the `req` object
|
17
|
+
* @param {AuthInput['targetAddress']} authInput.targetAddress - Only used in smart wallets to determine if the request is authorized to interact with the target address.
|
18
|
+
* @param {NodeServiceConfig['enforceAuth']} serviceConfig - Always `true` unless you need to turn auth off. Tells the service whether or not to enforce auth.
|
19
|
+
* @param {NodeServiceConfig['apiUrl']} serviceConfig.apiUrl - The url of the api server to fetch information for verification. `https://api.thirdweb.com` for production and `https://api.staging.thirdweb.com` for staging
|
20
|
+
* @param {NodeServiceConfig['serviceApiKey']} serviceConfig.serviceApiKey - secret key to be used authenticate the caller of the api-server. Check the api-server's env variable for the keys.
|
21
|
+
* @param {NodeServiceConfig['serviceScope']} serviceConfig.serviceScope - The service that we are requesting authorization for. E.g. `relayer`, `rpc`, 'bundler', 'storage' etc.
|
22
|
+
* @param {NodeServiceConfig['serviceAction']} serviceConfig.serviceAction - Needed when the `serviceScope` is `storage`. Can be either `read` or `write`.
|
23
|
+
* @param {NodeServiceConfig['useWalletAuth']} serviceConfig.useWalletAuth - If true it pings the `wallet/me` or else, `account/me`. You most likely can leave this as false.
|
24
|
+
* @returns {AuthorizationResult} authorizationResult - contains if the request is authorized, and information about the account if it is authorized. Otherwise, it contains the error message and status code.
|
25
|
+
*/
|
9
26
|
async function authorizeNode(authInput, serviceConfig) {
|
10
27
|
let authData;
|
11
28
|
try {
|
@@ -3,9 +3,26 @@
|
|
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-4b7b94ff.cjs.prod.js');
|
7
7
|
var services = require('../../dist/services-9e185105.cjs.prod.js');
|
8
8
|
|
9
|
+
/**
|
10
|
+
*
|
11
|
+
* @param {AuthInput['req']} authInput.req - The incoming request from which information will be pulled from. These information includes (checks are in order and terminates on first match):
|
12
|
+
* - clientId: Checks header `x-client-id`, search param `clientId`
|
13
|
+
* - bundleId: Checks header `x-bundle-id`, search param `bundleId`
|
14
|
+
* - secretKey: Checks header `x-secret-key`
|
15
|
+
* - origin (the requesting domain): Checks header `origin`, `referer`
|
16
|
+
* @param {AuthInput['clientId']} authInput.clientId - Overrides any clientId found on the `req` object
|
17
|
+
* @param {AuthInput['targetAddress']} authInput.targetAddress - Only used in smart wallets to determine if the request is authorized to interact with the target address.
|
18
|
+
* @param {NodeServiceConfig['enforceAuth']} serviceConfig - Always `true` unless you need to turn auth off. Tells the service whether or not to enforce auth.
|
19
|
+
* @param {NodeServiceConfig['apiUrl']} serviceConfig.apiUrl - The url of the api server to fetch information for verification. `https://api.thirdweb.com` for production and `https://api.staging.thirdweb.com` for staging
|
20
|
+
* @param {NodeServiceConfig['serviceApiKey']} serviceConfig.serviceApiKey - secret key to be used authenticate the caller of the api-server. Check the api-server's env variable for the keys.
|
21
|
+
* @param {NodeServiceConfig['serviceScope']} serviceConfig.serviceScope - The service that we are requesting authorization for. E.g. `relayer`, `rpc`, 'bundler', 'storage' etc.
|
22
|
+
* @param {NodeServiceConfig['serviceAction']} serviceConfig.serviceAction - Needed when the `serviceScope` is `storage`. Can be either `read` or `write`.
|
23
|
+
* @param {NodeServiceConfig['useWalletAuth']} serviceConfig.useWalletAuth - If true it pings the `wallet/me` or else, `account/me`. You most likely can leave this as false.
|
24
|
+
* @returns {AuthorizationResult} authorizationResult - contains if the request is authorized, and information about the account if it is authorized. Otherwise, it contains the error message and status code.
|
25
|
+
*/
|
9
26
|
async function authorizeNode(authInput, serviceConfig) {
|
10
27
|
let authData;
|
11
28
|
try {
|
@@ -1,7 +1,24 @@
|
|
1
1
|
import { createHash } from 'node:crypto';
|
2
|
-
import { a as authorize } from '../../dist/index-
|
2
|
+
import { a as authorize } from '../../dist/index-3f3d50f4.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
|
+
/**
|
6
|
+
*
|
7
|
+
* @param {AuthInput['req']} authInput.req - The incoming request from which information will be pulled from. These information includes (checks are in order and terminates on first match):
|
8
|
+
* - clientId: Checks header `x-client-id`, search param `clientId`
|
9
|
+
* - bundleId: Checks header `x-bundle-id`, search param `bundleId`
|
10
|
+
* - secretKey: Checks header `x-secret-key`
|
11
|
+
* - origin (the requesting domain): Checks header `origin`, `referer`
|
12
|
+
* @param {AuthInput['clientId']} authInput.clientId - Overrides any clientId found on the `req` object
|
13
|
+
* @param {AuthInput['targetAddress']} authInput.targetAddress - Only used in smart wallets to determine if the request is authorized to interact with the target address.
|
14
|
+
* @param {NodeServiceConfig['enforceAuth']} serviceConfig - Always `true` unless you need to turn auth off. Tells the service whether or not to enforce auth.
|
15
|
+
* @param {NodeServiceConfig['apiUrl']} serviceConfig.apiUrl - The url of the api server to fetch information for verification. `https://api.thirdweb.com` for production and `https://api.staging.thirdweb.com` for staging
|
16
|
+
* @param {NodeServiceConfig['serviceApiKey']} serviceConfig.serviceApiKey - secret key to be used authenticate the caller of the api-server. Check the api-server's env variable for the keys.
|
17
|
+
* @param {NodeServiceConfig['serviceScope']} serviceConfig.serviceScope - The service that we are requesting authorization for. E.g. `relayer`, `rpc`, 'bundler', 'storage' etc.
|
18
|
+
* @param {NodeServiceConfig['serviceAction']} serviceConfig.serviceAction - Needed when the `serviceScope` is `storage`. Can be either `read` or `write`.
|
19
|
+
* @param {NodeServiceConfig['useWalletAuth']} serviceConfig.useWalletAuth - If true it pings the `wallet/me` or else, `account/me`. You most likely can leave this as false.
|
20
|
+
* @returns {AuthorizationResult} authorizationResult - contains if the request is authorized, and information about the account if it is authorized. Otherwise, it contains the error message and status code.
|
21
|
+
*/
|
5
22
|
async function authorizeNode(authInput, serviceConfig) {
|
6
23
|
let authData;
|
7
24
|
try {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thirdweb-dev/service-utils",
|
3
|
-
"version": "0.0.0-dev-
|
3
|
+
"version": "0.0.0-dev-c57f450-20230913125903",
|
4
4
|
"main": "dist/thirdweb-dev-service-utils.cjs.js",
|
5
5
|
"module": "dist/thirdweb-dev-service-utils.esm.js",
|
6
6
|
"exports": {
|
@@ -52,6 +52,7 @@
|
|
52
52
|
"eslint-config-thirdweb": "^0.1.6",
|
53
53
|
"jest": "^29.6.2",
|
54
54
|
"prettier": "^3.0.0",
|
55
|
+
"ts-jest": "^29.1.1",
|
55
56
|
"typescript": "^5.1.6"
|
56
57
|
},
|
57
58
|
"dependencies": {
|