@chainfuse/helpers 1.1.10 → 2.0.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.d.mts +1 -2
- package/dist/net.mjs +5 -7
- package/package.json +5 -5
package/dist/net.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { CustomLoging } from '@chainfuse/types';
|
|
2
|
-
import { Cloudflare } from 'cloudflare';
|
|
3
2
|
export declare class NetHelpers {
|
|
4
3
|
/**
|
|
5
4
|
* Removes the `body` property from a RequestInit object to reduce verbosity when logging.
|
|
@@ -10,7 +9,7 @@ export declare class NetHelpers {
|
|
|
10
9
|
*/
|
|
11
10
|
static initBodyTrimmer(init?: RequestInit): RequestInit;
|
|
12
11
|
static stripSensitiveHeaders(originalHeaders?: Headers): Headers;
|
|
13
|
-
static cfApi(apiKey: string, cacheTtl?: number, logger?: CustomLoging): Cloudflare
|
|
12
|
+
static cfApi<C extends CacheStorage>(apiKey: string, cacheStorageRef?: C, cacheTtl?: number, logger?: CustomLoging): Promise<import("cloudflare").Cloudflare>;
|
|
14
13
|
static loggingFetch(info: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1], body?: boolean, logger?: CustomLoging): Promise<Response>;
|
|
15
14
|
/**
|
|
16
15
|
* Parses the Server-Timing header and returns an object with the metrics.
|
package/dist/net.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Cloudflare } from 'cloudflare';
|
|
2
1
|
import { CryptoHelpers } from './crypto.mjs';
|
|
3
2
|
export class NetHelpers {
|
|
4
3
|
/**
|
|
@@ -19,8 +18,8 @@ export class NetHelpers {
|
|
|
19
18
|
originalHeaders.delete('Authorization');
|
|
20
19
|
return originalHeaders;
|
|
21
20
|
}
|
|
22
|
-
static cfApi(apiKey, cacheTtl, logger = false) {
|
|
23
|
-
return new Cloudflare({
|
|
21
|
+
static cfApi(apiKey, cacheStorageRef, cacheTtl, logger = false) {
|
|
22
|
+
return import('cloudflare').then(({ Cloudflare }) => new Cloudflare({
|
|
24
23
|
apiToken: apiKey,
|
|
25
24
|
fetch: (info, init) =>
|
|
26
25
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
@@ -39,9 +38,8 @@ export class NetHelpers {
|
|
|
39
38
|
else {
|
|
40
39
|
logger(`CF Fetch request ${cacheKey.url} ${JSON.stringify(this.initBodyTrimmer({ ...init, headers: Object.fromEntries(this.stripSensitiveHeaders(new Headers(init?.headers)).entries()) }), null, '\t')}`);
|
|
41
40
|
}
|
|
42
|
-
if (cacheTtl) {
|
|
43
|
-
const cfCacheRef = caches?.open('cfApi');
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
41
|
+
if (cacheStorageRef || cacheTtl) {
|
|
42
|
+
const cfCacheRef = (cacheStorageRef ?? caches)?.open('cfApi');
|
|
45
43
|
if (cfCacheRef) {
|
|
46
44
|
await cfCacheRef
|
|
47
45
|
.then((cfCache) => cfCache
|
|
@@ -202,7 +200,7 @@ export class NetHelpers {
|
|
|
202
200
|
resolve(this.loggingFetch(info, init, undefined, logger));
|
|
203
201
|
}
|
|
204
202
|
}),
|
|
205
|
-
});
|
|
203
|
+
}));
|
|
206
204
|
}
|
|
207
205
|
static loggingFetch(info, init, body = false, logger = false) {
|
|
208
206
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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": "^1.7.
|
|
58
|
-
"@cloudflare/workers-types": "^4.
|
|
59
|
-
"@types/node": "^22.13.
|
|
57
|
+
"@chainfuse/types": "^1.7.1",
|
|
58
|
+
"@cloudflare/workers-types": "^4.20250303.0",
|
|
59
|
+
"@types/node": "^22.13.9"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "2700804966fc2178ae0e79267f416f813b99ad7b"
|
|
62
62
|
}
|