@chainfuse/helpers 2.3.2 → 2.4.0

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/dist/net.d.mts CHANGED
@@ -10,7 +10,7 @@ export declare class NetHelpers {
10
10
  static initBodyTrimmer(init?: RequestInit): RequestInit;
11
11
  static stripSensitiveHeaders(originalHeaders?: Headers): Headers;
12
12
  static cfApi(apiKey: string, logger?: CustomLoging): Promise<import("cloudflare").Cloudflare>;
13
- private static isRequestLike;
13
+ static isRequestLike(obj: Parameters<typeof fetch>[0]): obj is Request;
14
14
  static loggingFetch(info: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1], body?: boolean, logger?: CustomLoging): Promise<Response>;
15
15
  /**
16
16
  * Parses the Server-Timing header and returns an object with the metrics.
package/dist/net.mjs CHANGED
@@ -23,13 +23,26 @@ export class NetHelpers {
23
23
  apiToken: apiKey,
24
24
  fetch: async (info, init) => {
25
25
  if (typeof logger === 'boolean' && logger) {
26
- logger = (date, id, methodOrStatus, url, headers, ...rest) => {
26
+ logger = async (date, id, methodOrStatus, url, headers, ...rest) => {
27
27
  const customUrl = new URL(url);
28
28
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
29
29
  const loggingItems = ['CF Rest', date, id, methodOrStatus, `${customUrl.pathname}${customUrl.search}${customUrl.hash}`, ...rest];
30
30
  const customHeaders = new Headers(headers);
31
- if (customHeaders.has('cf-ray'))
32
- loggingItems.splice(3, 0, customHeaders.get('cf-ray'));
31
+ await import('chalk')
32
+ .then(({ Chalk }) => {
33
+ const chalk = new Chalk({ level: 2 });
34
+ // Replace with color
35
+ loggingItems.splice(0, 1, chalk.rgb(245, 130, 30)('CF Rest'));
36
+ // Add in with color
37
+ if (customHeaders.has('cf-ray'))
38
+ loggingItems.splice(3, 0, chalk.rgb(245, 130, 30)(customHeaders.get('cf-ray')));
39
+ })
40
+ .catch(() => {
41
+ // Add in ray id
42
+ if (customHeaders.has('cf-ray'))
43
+ loggingItems.splice(3, 0, customHeaders.get('cf-ray'));
44
+ });
45
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
33
46
  console.debug(...loggingItems);
34
47
  };
35
48
  }
@@ -54,21 +67,21 @@ export class NetHelpers {
54
67
  loggingItems.push(init.body);
55
68
  }
56
69
  }
70
+ await Promise.all([import('chalk'), import("./index.mjs")])
71
+ .then(([{ Chalk }, { Helpers }]) => {
72
+ const chalk = new Chalk({ level: 2 });
73
+ loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
74
+ })
75
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
76
+ .catch(() => { });
57
77
  if (typeof logger === 'boolean') {
58
78
  if (logger) {
59
- await Promise.all([import('chalk'), import("./index.mjs")])
60
- .then(([{ Chalk }, { Helpers }]) => {
61
- const chalk = new Chalk({ level: 1 });
62
- loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
63
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64
- console.debug(...loggingItems);
65
- })
66
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
67
- .catch(() => console.debug(...loggingItems));
79
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
80
+ console.debug(...loggingItems);
68
81
  }
69
82
  }
70
83
  else {
71
- logger(...loggingItems);
84
+ await logger(...loggingItems);
72
85
  }
73
86
  return id;
74
87
  })
@@ -86,21 +99,22 @@ export class NetHelpers {
86
99
  loggingItems.push(await loggingClone.text());
87
100
  }
88
101
  }
102
+ await Promise.all([import('chalk'), import("./index.mjs")])
103
+ .then(([{ Chalk }, { Helpers }]) => {
104
+ const chalk = new Chalk({ level: 2 });
105
+ loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
106
+ loggingItems.splice(2, 1, response.ok ? chalk.green(response.status) : chalk.red(response.status));
107
+ })
108
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
109
+ .catch(() => { });
89
110
  if (typeof logger === 'boolean') {
90
111
  if (logger) {
91
- await Promise.all([import('chalk'), import("./index.mjs")])
92
- .then(([{ Chalk }, { Helpers }]) => {
93
- const chalk = new Chalk({ level: 1 });
94
- loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
95
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
96
- console.debug(...loggingItems);
97
- })
98
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
99
- .catch(() => console.debug(...loggingItems));
112
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
113
+ console.debug(...loggingItems);
100
114
  }
101
115
  }
102
116
  else {
103
- logger(...loggingItems);
117
+ await logger(...loggingItems);
104
118
  }
105
119
  resolve(response);
106
120
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "2.3.2",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -54,9 +54,9 @@
54
54
  "uuid": "^11.1.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@chainfuse/types": "^2.6.0",
58
- "@cloudflare/workers-types": "^4.20250409.0",
57
+ "@chainfuse/types": "^2.10.0",
58
+ "@cloudflare/workers-types": "^4.20250410.0",
59
59
  "@types/node": "^22.14.0"
60
60
  },
61
- "gitHead": "8b75599be143be76f38c5ea7eae9b68625e6fca3"
61
+ "gitHead": "c480462d073b3d89c915eb003b0ba789fe79d414"
62
62
  }