@thirdweb-dev/service-utils 0.3.1 → 0.4.0-nightly-0647f124-20230805003215

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.
@@ -194,6 +194,31 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
194
194
  function bufferToHex(buffer) {
195
195
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
196
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
+ }
197
222
 
198
223
  exports.SERVICES = services.SERVICES;
199
224
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -203,4 +228,5 @@ exports.authorizeWorker = authorizeWorker;
203
228
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
204
229
  exports.extractAuthorizationData = extractAuthorizationData;
205
230
  exports.hashSecretKey = hashSecretKey;
231
+ exports.logHttpRequest = logHttpRequest;
206
232
  exports.publishUsageEvents = publishUsageEvents;
@@ -194,6 +194,31 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
194
194
  function bufferToHex(buffer) {
195
195
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
196
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
+ }
197
222
 
198
223
  exports.SERVICES = services.SERVICES;
199
224
  exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
@@ -203,4 +228,5 @@ exports.authorizeWorker = authorizeWorker;
203
228
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
204
229
  exports.extractAuthorizationData = extractAuthorizationData;
205
230
  exports.hashSecretKey = hashSecretKey;
231
+ exports.logHttpRequest = logHttpRequest;
206
232
  exports.publishUsageEvents = publishUsageEvents;
@@ -190,5 +190,30 @@ function deriveClientIdFromSecretKeyHash(secretKeyHash) {
190
190
  function bufferToHex(buffer) {
191
191
  return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, "0")).join("");
192
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
+ }
193
218
 
194
- export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, publishUsageEvents };
219
+ export { authorizeWorker, deriveClientIdFromSecretKeyHash, extractAuthorizationData, hashSecretKey, logHttpRequest, publishUsageEvents };
@@ -1,4 +1,4 @@
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
4
  import type { AuthorizationInput } from "../core/authorize";
@@ -18,4 +18,10 @@ export declare function authorizeWorker(authInput: AuthInput, serviceConfig: Wor
18
18
  export declare function extractAuthorizationData(authInput: AuthInput): Promise<AuthorizationInput>;
19
19
  export declare function hashSecretKey(secretKey: string): Promise<string>;
20
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>;
21
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;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,WA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AS,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"}
@@ -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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AAS,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"}
@@ -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;
@@ -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;
@@ -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.3.1",
3
+ "version": "0.4.0-nightly-0647f124-20230805003215",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {