@chainfuse/helpers 1.1.10 → 2.0.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
@@ -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(apiKey: string, cacheStorageRef?: CacheStorage, 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 = caches, 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?.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": "1.1.10",
3
+ "version": "2.0.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": "^1.7.0",
58
- "@cloudflare/workers-types": "^4.20250224.0",
59
- "@types/node": "^22.13.5"
57
+ "@chainfuse/types": "^1.7.1",
58
+ "@cloudflare/workers-types": "^4.20250303.0",
59
+ "@types/node": "^22.13.9"
60
60
  },
61
- "gitHead": "b219058947b158ed7efbb31df536c543d0571acf"
61
+ "gitHead": "2b426f19f6708bee297c930b7bcffa33ddaf6e5e"
62
62
  }