@thirdweb-dev/service-utils 0.5.0-nightly-0f027069-20230828164852 → 0.5.0-nightly-6cf298a29-20240308012322

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 (37) hide show
  1. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +59 -27
  2. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +59 -27
  3. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +58 -27
  4. package/dist/declarations/src/cf-worker/index.d.ts +6 -3
  5. package/dist/declarations/src/cf-worker/index.d.ts.map +1 -1
  6. package/dist/declarations/src/cf-worker/usage.d.ts +75 -12
  7. package/dist/declarations/src/cf-worker/usage.d.ts.map +1 -1
  8. package/dist/declarations/src/core/api.d.ts +37 -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 +20 -0
  14. package/dist/declarations/src/core/rateLimit/index.d.ts.map +1 -0
  15. package/dist/declarations/src/core/rateLimit/types.d.ts +13 -0
  16. package/dist/declarations/src/core/rateLimit/types.d.ts.map +1 -0
  17. package/dist/declarations/src/core/services.d.ts +49 -1
  18. package/dist/declarations/src/core/services.d.ts.map +1 -1
  19. package/dist/declarations/src/core/usageLimit/index.d.ts +5 -0
  20. package/dist/declarations/src/core/usageLimit/index.d.ts.map +1 -0
  21. package/dist/declarations/src/core/usageLimit/types.d.ts +9 -0
  22. package/dist/declarations/src/core/usageLimit/types.d.ts.map +1 -0
  23. package/dist/declarations/src/node/index.d.ts +23 -3
  24. package/dist/declarations/src/node/index.d.ts.map +1 -1
  25. package/dist/{index-ffddf746.esm.js → index-3b9a0743.esm.js} +170 -20
  26. package/dist/{index-6e0ecc5f.cjs.prod.js → index-62b88cac.cjs.dev.js} +171 -19
  27. package/dist/{index-cd4f96ef.cjs.dev.js → index-aa324361.cjs.prod.js} +171 -19
  28. package/dist/{services-86283509.esm.js → services-2aecbda8.esm.js} +21 -0
  29. package/dist/{services-9e185105.cjs.prod.js → services-508322f3.cjs.dev.js} +21 -0
  30. package/dist/{services-a3f36057.cjs.dev.js → services-5c4d6977.cjs.prod.js} +21 -0
  31. package/dist/thirdweb-dev-service-utils.cjs.dev.js +1 -1
  32. package/dist/thirdweb-dev-service-utils.cjs.prod.js +1 -1
  33. package/dist/thirdweb-dev-service-utils.esm.js +1 -1
  34. package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +50 -24
  35. package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +50 -24
  36. package/node/dist/thirdweb-dev-service-utils-node.esm.js +49 -24
  37. package/package.json +9 -8
@@ -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-cd4f96ef.cjs.dev.js');
7
- var services = require('../../dist/services-a3f36057.cjs.dev.js');
6
+ var index = require('../../dist/index-62b88cac.cjs.dev.js');
7
+ var services = require('../../dist/services-508322f3.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 {
@@ -131,31 +148,40 @@ function logHttpRequest(_ref) {
131
148
  req,
132
149
  res,
133
150
  isAuthed,
134
- statusMessage
151
+ statusMessage,
152
+ latencyMs
135
153
  } = _ref;
136
- const authorizationData = extractAuthorizationData({
137
- req,
138
- clientId
139
- });
140
- const headers = req.headers;
141
- const _statusMessage = statusMessage ?? res.statusMessage;
142
- console.log(JSON.stringify({
143
- source,
144
- pathname: req.url,
145
- hasSecretKey: !!authorizationData.secretKey,
146
- hasClientId: !!authorizationData.clientId,
147
- hasJwt: !!authorizationData.jwt,
148
- clientId: authorizationData.clientId,
149
- isAuthed: !!isAuthed ?? null,
150
- status: res.statusCode,
151
- statusMessage: _statusMessage,
152
- sdkName: headers["x-sdk-name"] ?? "unknown",
153
- sdkVersion: headers["x-sdk-version"] ?? "unknown",
154
- platform: headers["x-sdk-platform"] ?? "unknown"
155
- }));
156
- console.log(`statusMessage=${_statusMessage}`);
154
+ try {
155
+ const authorizationData = extractAuthorizationData({
156
+ req,
157
+ clientId
158
+ });
159
+ const headers = req.headers;
160
+ const _statusMessage = statusMessage ?? res.statusMessage;
161
+ console.log(JSON.stringify({
162
+ source,
163
+ pathname: req.url,
164
+ hasSecretKey: !!authorizationData.secretKey,
165
+ hasClientId: !!authorizationData.clientId,
166
+ hasJwt: !!authorizationData.jwt,
167
+ clientId: authorizationData.clientId,
168
+ isAuthed: !!isAuthed ?? null,
169
+ status: res.statusCode,
170
+ statusMessage: _statusMessage,
171
+ sdkName: headers["x-sdk-name"] ?? "unknown",
172
+ sdkVersion: headers["x-sdk-version"] ?? "unknown",
173
+ platform: headers["x-sdk-platform"] ?? "unknown",
174
+ os: headers["x-sdk-os"] ?? "unknown",
175
+ latencyMs: latencyMs ?? null
176
+ }));
177
+ console.log(`statusMessage=${_statusMessage}`);
178
+ } catch (err) {
179
+ console.error("Failed to log HTTP request:", err);
180
+ }
157
181
  }
158
182
 
183
+ exports.rateLimit = index.rateLimit;
184
+ exports.usageLimit = index.usageLimit;
159
185
  exports.SERVICES = services.SERVICES;
160
186
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
161
187
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
@@ -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-6e0ecc5f.cjs.prod.js');
7
- var services = require('../../dist/services-9e185105.cjs.prod.js');
6
+ var index = require('../../dist/index-aa324361.cjs.prod.js');
7
+ var services = require('../../dist/services-5c4d6977.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 {
@@ -131,31 +148,40 @@ function logHttpRequest(_ref) {
131
148
  req,
132
149
  res,
133
150
  isAuthed,
134
- statusMessage
151
+ statusMessage,
152
+ latencyMs
135
153
  } = _ref;
136
- const authorizationData = extractAuthorizationData({
137
- req,
138
- clientId
139
- });
140
- const headers = req.headers;
141
- const _statusMessage = statusMessage ?? res.statusMessage;
142
- console.log(JSON.stringify({
143
- source,
144
- pathname: req.url,
145
- hasSecretKey: !!authorizationData.secretKey,
146
- hasClientId: !!authorizationData.clientId,
147
- hasJwt: !!authorizationData.jwt,
148
- clientId: authorizationData.clientId,
149
- isAuthed: !!isAuthed ?? null,
150
- status: res.statusCode,
151
- statusMessage: _statusMessage,
152
- sdkName: headers["x-sdk-name"] ?? "unknown",
153
- sdkVersion: headers["x-sdk-version"] ?? "unknown",
154
- platform: headers["x-sdk-platform"] ?? "unknown"
155
- }));
156
- console.log(`statusMessage=${_statusMessage}`);
154
+ try {
155
+ const authorizationData = extractAuthorizationData({
156
+ req,
157
+ clientId
158
+ });
159
+ const headers = req.headers;
160
+ const _statusMessage = statusMessage ?? res.statusMessage;
161
+ console.log(JSON.stringify({
162
+ source,
163
+ pathname: req.url,
164
+ hasSecretKey: !!authorizationData.secretKey,
165
+ hasClientId: !!authorizationData.clientId,
166
+ hasJwt: !!authorizationData.jwt,
167
+ clientId: authorizationData.clientId,
168
+ isAuthed: !!isAuthed ?? null,
169
+ status: res.statusCode,
170
+ statusMessage: _statusMessage,
171
+ sdkName: headers["x-sdk-name"] ?? "unknown",
172
+ sdkVersion: headers["x-sdk-version"] ?? "unknown",
173
+ platform: headers["x-sdk-platform"] ?? "unknown",
174
+ os: headers["x-sdk-os"] ?? "unknown",
175
+ latencyMs: latencyMs ?? null
176
+ }));
177
+ console.log(`statusMessage=${_statusMessage}`);
178
+ } catch (err) {
179
+ console.error("Failed to log HTTP request:", err);
180
+ }
157
181
  }
158
182
 
183
+ exports.rateLimit = index.rateLimit;
184
+ exports.usageLimit = index.usageLimit;
159
185
  exports.SERVICES = services.SERVICES;
160
186
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
161
187
  exports.SERVICE_NAMES = services.SERVICE_NAMES;
@@ -1,7 +1,25 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { a as authorize } from '../../dist/index-ffddf746.esm.js';
3
- export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
2
+ import { a as authorize } from '../../dist/index-3b9a0743.esm.js';
3
+ export { r as rateLimit, u as usageLimit } from '../../dist/index-3b9a0743.esm.js';
4
+ export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-2aecbda8.esm.js';
4
5
 
6
+ /**
7
+ *
8
+ * @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):
9
+ * - clientId: Checks header `x-client-id`, search param `clientId`
10
+ * - bundleId: Checks header `x-bundle-id`, search param `bundleId`
11
+ * - secretKey: Checks header `x-secret-key`
12
+ * - origin (the requesting domain): Checks header `origin`, `referer`
13
+ * @param {AuthInput['clientId']} authInput.clientId - Overrides any clientId found on the `req` object
14
+ * @param {AuthInput['targetAddress']} authInput.targetAddress - Only used in smart wallets to determine if the request is authorized to interact with the target address.
15
+ * @param {NodeServiceConfig['enforceAuth']} serviceConfig - Always `true` unless you need to turn auth off. Tells the service whether or not to enforce auth.
16
+ * @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
17
+ * @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.
18
+ * @param {NodeServiceConfig['serviceScope']} serviceConfig.serviceScope - The service that we are requesting authorization for. E.g. `relayer`, `rpc`, 'bundler', 'storage' etc.
19
+ * @param {NodeServiceConfig['serviceAction']} serviceConfig.serviceAction - Needed when the `serviceScope` is `storage`. Can be either `read` or `write`.
20
+ * @param {NodeServiceConfig['useWalletAuth']} serviceConfig.useWalletAuth - If true it pings the `wallet/me` or else, `account/me`. You most likely can leave this as false.
21
+ * @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.
22
+ */
5
23
  async function authorizeNode(authInput, serviceConfig) {
6
24
  let authData;
7
25
  try {
@@ -127,29 +145,36 @@ function logHttpRequest(_ref) {
127
145
  req,
128
146
  res,
129
147
  isAuthed,
130
- statusMessage
148
+ statusMessage,
149
+ latencyMs
131
150
  } = _ref;
132
- const authorizationData = extractAuthorizationData({
133
- req,
134
- clientId
135
- });
136
- const headers = req.headers;
137
- const _statusMessage = statusMessage ?? res.statusMessage;
138
- console.log(JSON.stringify({
139
- source,
140
- pathname: req.url,
141
- hasSecretKey: !!authorizationData.secretKey,
142
- hasClientId: !!authorizationData.clientId,
143
- hasJwt: !!authorizationData.jwt,
144
- clientId: authorizationData.clientId,
145
- isAuthed: !!isAuthed ?? null,
146
- status: res.statusCode,
147
- statusMessage: _statusMessage,
148
- sdkName: headers["x-sdk-name"] ?? "unknown",
149
- sdkVersion: headers["x-sdk-version"] ?? "unknown",
150
- platform: headers["x-sdk-platform"] ?? "unknown"
151
- }));
152
- console.log(`statusMessage=${_statusMessage}`);
151
+ try {
152
+ const authorizationData = extractAuthorizationData({
153
+ req,
154
+ clientId
155
+ });
156
+ const headers = req.headers;
157
+ const _statusMessage = statusMessage ?? res.statusMessage;
158
+ console.log(JSON.stringify({
159
+ source,
160
+ pathname: req.url,
161
+ hasSecretKey: !!authorizationData.secretKey,
162
+ hasClientId: !!authorizationData.clientId,
163
+ hasJwt: !!authorizationData.jwt,
164
+ clientId: authorizationData.clientId,
165
+ isAuthed: !!isAuthed ?? null,
166
+ status: res.statusCode,
167
+ statusMessage: _statusMessage,
168
+ sdkName: headers["x-sdk-name"] ?? "unknown",
169
+ sdkVersion: headers["x-sdk-version"] ?? "unknown",
170
+ platform: headers["x-sdk-platform"] ?? "unknown",
171
+ os: headers["x-sdk-os"] ?? "unknown",
172
+ latencyMs: latencyMs ?? null
173
+ }));
174
+ console.log(`statusMessage=${_statusMessage}`);
175
+ } catch (err) {
176
+ console.error("Failed to log HTTP request:", err);
177
+ }
153
178
  }
154
179
 
155
180
  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.5.0-nightly-0f027069-20230828164852",
3
+ "version": "0.5.0-nightly-6cf298a29-20240308012322",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {
@@ -46,21 +46,22 @@
46
46
  "@types/jest": "^29.5.3",
47
47
  "@types/node": "^18.17.1",
48
48
  "@typescript-eslint/eslint-plugin": "^6.2.0",
49
- "@typescript-eslint/parser": "^6.2.0",
50
- "eslint": "^8.45.0",
49
+ "@typescript-eslint/parser": "^6.19.1",
50
+ "eslint": "^8.56.0",
51
51
  "eslint-config-prettier": "^8.9.0",
52
- "eslint-config-thirdweb": "^0.1.6",
52
+ "eslint-config-thirdweb": "^0.1.7",
53
53
  "jest": "^29.6.2",
54
- "prettier": "^3.0.0",
55
- "typescript": "^5.1.6"
54
+ "prettier": "^3.1.1",
55
+ "ts-jest": "^29.1.1",
56
+ "typescript": "^5.3.3"
56
57
  },
57
58
  "dependencies": {
58
59
  "aws4fetch": "^1.0.17",
59
- "zod": "^3.20.2"
60
+ "zod": "^3.22.3"
60
61
  },
61
62
  "scripts": {
62
63
  "format": "prettier --write 'src/**/*'",
63
- "lint": "eslint src/",
64
+ "lint": "eslint src/ && bunx publint --strict --level warning",
64
65
  "fix": "eslint src/ --fix",
65
66
  "clean": "rm -rf dist/",
66
67
  "build": "tsc && preconstruct build",