@chainfuse/helpers 2.3.3 → 2.4.1
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.mjs +63 -23
- package/package.json +3 -3
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
|
-
|
|
32
|
-
|
|
31
|
+
await import('chalk')
|
|
32
|
+
.then(({ Chalk }) => {
|
|
33
|
+
const chalk = new Chalk({ level: 3 });
|
|
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,46 @@ 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: 3 });
|
|
73
|
+
loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
|
|
74
|
+
const initMethod = loggingItems[2].toUpperCase();
|
|
75
|
+
/**
|
|
76
|
+
* @link https://github.com/swagger-api/swagger-ui/blob/master/src/style/_variables.scss#L48-L53
|
|
77
|
+
*/
|
|
78
|
+
switch (initMethod) {
|
|
79
|
+
case 'POST':
|
|
80
|
+
loggingItems.splice(2, 1, chalk.hex('#49cc90')(initMethod));
|
|
81
|
+
break;
|
|
82
|
+
case 'GET':
|
|
83
|
+
loggingItems.splice(2, 1, chalk.hex('#61affe')(initMethod));
|
|
84
|
+
break;
|
|
85
|
+
case 'PUT':
|
|
86
|
+
loggingItems.splice(2, 1, chalk.hex('#fca130')(initMethod));
|
|
87
|
+
break;
|
|
88
|
+
case 'DELETE':
|
|
89
|
+
loggingItems.splice(2, 1, chalk.hex('#f93e3e')(initMethod));
|
|
90
|
+
break;
|
|
91
|
+
case 'HEAD':
|
|
92
|
+
loggingItems.splice(2, 1, chalk.hex('#9012fe')(initMethod));
|
|
93
|
+
break;
|
|
94
|
+
case 'PATCH':
|
|
95
|
+
loggingItems.splice(2, 1, chalk.hex('#50e3c2')(initMethod));
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
100
|
+
.catch(() => { });
|
|
57
101
|
if (typeof logger === 'boolean') {
|
|
58
102
|
if (logger) {
|
|
59
|
-
|
|
60
|
-
|
|
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));
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
104
|
+
console.debug(...loggingItems);
|
|
68
105
|
}
|
|
69
106
|
}
|
|
70
107
|
else {
|
|
71
|
-
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
109
|
+
await logger(...loggingItems);
|
|
72
110
|
}
|
|
73
111
|
return id;
|
|
74
112
|
})
|
|
@@ -86,21 +124,23 @@ export class NetHelpers {
|
|
|
86
124
|
loggingItems.push(await loggingClone.text());
|
|
87
125
|
}
|
|
88
126
|
}
|
|
127
|
+
await Promise.all([import('chalk'), import("./index.mjs")])
|
|
128
|
+
.then(([{ Chalk }, { Helpers }]) => {
|
|
129
|
+
const chalk = new Chalk({ level: 3 });
|
|
130
|
+
loggingItems.splice(1, 1, chalk.rgb(...Helpers.uniqueIdColor(id))(`[${id}]`));
|
|
131
|
+
loggingItems.splice(2, 1, response.ok ? chalk.green(response.status) : chalk.red(response.status));
|
|
132
|
+
})
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
134
|
+
.catch(() => { });
|
|
89
135
|
if (typeof logger === 'boolean') {
|
|
90
136
|
if (logger) {
|
|
91
|
-
|
|
92
|
-
|
|
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));
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
138
|
+
console.debug(...loggingItems);
|
|
100
139
|
}
|
|
101
140
|
}
|
|
102
141
|
else {
|
|
103
|
-
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
143
|
+
await logger(...loggingItems);
|
|
104
144
|
}
|
|
105
145
|
resolve(response);
|
|
106
146
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
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.
|
|
57
|
+
"@chainfuse/types": "^2.10.0",
|
|
58
58
|
"@cloudflare/workers-types": "^4.20250410.0",
|
|
59
59
|
"@types/node": "^22.14.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "c131e6b181f7cd1f4c25732c8141b340e5d9a6d3"
|
|
62
62
|
}
|