@harlan-zw/nuxt-cloudflare 0.0.16 → 0.0.17

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.5.0 <5.0.0"
6
6
  },
7
- "version": "0.0.16",
7
+ "version": "0.0.17",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -15,9 +15,19 @@ import type { NitroApp } from 'nitropack/types';
15
15
  * quietly makes twenty serial primary round trips looks identical to a fast one
16
16
  * in every other log line; these counters are what separate them.
17
17
  *
18
- * Registered by the module only when `@harlan-zw/nuxt-wide-events` is present,
19
- * and the fields are declared through `addWideEventFields` at build time, so
20
- * the consuming application never hand-lists them and cannot drift from them.
18
+ * ── The single object literal is load-bearing ──
19
+ *
20
+ * `@harlan-zw/nuxt-wide-events` parses every server file at build time and
21
+ * REJECTS an `addWideEventFields` call whose argument is not an object literal:
22
+ * no variables, no spreads, no computed keys. That is the guarantee the whole
23
+ * module rests on — a reviewer can read the allowlist and know nothing else can
24
+ * reach an event.
25
+ *
26
+ * So this cannot build its payload conditionally. Every key is present on every
27
+ * call, `null` where the value is unavailable, and the whole thing is one
28
+ * literal. An earlier version assembled a `Record` and passed the variable; it
29
+ * failed the CONSUMING application's build, which is the worst place for a
30
+ * module's mistake to surface.
21
31
  */
22
32
  declare const _default: (nitroApp: NitroApp) => void;
23
33
  export default _default;
@@ -5,26 +5,23 @@ export default (nitroApp) => {
5
5
  recordCloudflareWideEventFields(event);
6
6
  });
7
7
  };
8
+ function stringOrNull(value) {
9
+ return typeof value === "string" ? value : null;
10
+ }
8
11
  export function recordCloudflareWideEventFields(event) {
9
- const fields = {};
10
12
  const cf = event.context.cloudflare?.request?.cf;
11
- if (cf) {
12
- if (typeof cf.colo === "string")
13
- fields["cf.colo"] = cf.colo;
14
- if (typeof cf.country === "string")
15
- fields["cf.country"] = cf.country;
16
- if (typeof cf.httpProtocol === "string")
17
- fields["cf.httpProtocol"] = cf.httpProtocol;
18
- }
19
13
  const d1 = readD1Stats(event.context);
20
- if (d1) {
21
- fields["d1.queries"] = d1.queries;
22
- fields["d1.primaryQueries"] = d1.primaryQueries;
23
- fields["d1.recoveries"] = d1.recoveries;
24
- fields["d1.unrecovered"] = d1.unrecovered;
25
- fields["d1.durationMs"] = Math.round(d1.durationMs);
26
- fields["d1.region"] = d1.region;
27
- }
28
- if (Object.keys(fields).length)
29
- addWideEventFields(event, fields);
14
+ if (!cf && !d1)
15
+ return;
16
+ addWideEventFields(event, {
17
+ "cf.colo": stringOrNull(cf?.colo),
18
+ "cf.country": stringOrNull(cf?.country),
19
+ "cf.httpProtocol": stringOrNull(cf?.httpProtocol),
20
+ "d1.queries": d1 ? d1.queries : null,
21
+ "d1.primaryQueries": d1 ? d1.primaryQueries : null,
22
+ "d1.recoveries": d1 ? d1.recoveries : null,
23
+ "d1.unrecovered": d1 ? d1.unrecovered : null,
24
+ "d1.durationMs": d1 ? Math.round(d1.durationMs) : null,
25
+ "d1.region": d1 ? d1.region : null
26
+ });
30
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@harlan-zw/nuxt-cloudflare",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.17",
5
5
  "description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -105,7 +105,8 @@
105
105
  "typescript": "^5.9.3",
106
106
  "unbuild": "^3.6.1",
107
107
  "vitest": "^4.1.10",
108
- "wrangler": "^4.120.1"
108
+ "wrangler": "^4.120.1",
109
+ "@harlan-zw/nuxt-wide-events": "0.0.3"
109
110
  },
110
111
  "scripts": {
111
112
  "build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",