@hanzo/event 0.3.9 → 0.3.11

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.
@@ -100,14 +100,29 @@ interface AnalyticsConfig {
100
100
  /** Bearer token provider for token-auth apps. Omit for cookie/session apps
101
101
  * (the client then relies on same-origin credentials). */
102
102
  getToken?: () => string | undefined | null;
103
- /** Publishable ingest key (pk_…). When set, the client authenticates to the ONE
104
- * front door `/v1/event` with this key instead of a bearer/cookie: it rides
105
- * Authorization: Bearer pk_… on fetch and ?ingest_key=pk_… on a headerless
106
- * page-unload beacon, so anonymous traffic is accepted and unload beacons work
107
- * without a bearer. The key is write-only (cannot read) and safe to ship in a
108
- * bundle; mint one per org via POST /v1/ingest/keys. This authenticates the
109
- * EVENT STREAM only — the error plane authenticates independently with `dsn`,
110
- * and one does not stand in for the other. */
103
+ /** Publishable ingest key (pk-…). When set, the client attributes writes to the
104
+ * ONE front door `/v1/event` with this key instead of a bearer/cookie: it rides
105
+ * Authorization: Bearer pk-… on fetch and ?ingest_key=pk-… on a headerless
106
+ * page-unload beacon, so ANONYMOUS traffic is attributed and unload beacons work
107
+ * without a bearer. The key is write-only it attributes a write and never mints
108
+ * a reading principal so it is safe to ship in a bundle. Mint one per org with
109
+ * POST /v1/keys {"type":"publishable"}.
110
+ *
111
+ * Omit it and the client reads NEXT_PUBLIC_EVENT_INGEST_KEY from the inlined
112
+ * build env, the same way `dsn` falls back — so a surface declares BOTH planes
113
+ * in its build and neither needs code to switch on. That is the ONE spelling
114
+ * the fleet already carries: KMS holds deploy/EVENT_INGEST_KEY, and each
115
+ * Dockerfile takes EVENT_INGEST_KEY as a build-arg and re-exports it with the
116
+ * NEXT_PUBLIC_ prefix that makes Next inline it.
117
+ *
118
+ * A surface with no key at all still reports for whoever is SIGNED IN (the
119
+ * session credential attributes them), and drops every logged-out visitor: the
120
+ * door refuses an unattributable write rather than filing it where its owner
121
+ * cannot read it. That failure is invisible from the page, which is why the key
122
+ * belongs in the env next to the DSN and not in a checklist.
123
+ *
124
+ * This attributes the EVENT STREAM only — the error plane authenticates
125
+ * independently with `dsn`, and one does not stand in for the other. */
111
126
  ingestKey?: string;
112
127
  /** Max events buffered before an automatic flush. */
113
128
  batchSize?: number;
@@ -100,14 +100,29 @@ interface AnalyticsConfig {
100
100
  /** Bearer token provider for token-auth apps. Omit for cookie/session apps
101
101
  * (the client then relies on same-origin credentials). */
102
102
  getToken?: () => string | undefined | null;
103
- /** Publishable ingest key (pk_…). When set, the client authenticates to the ONE
104
- * front door `/v1/event` with this key instead of a bearer/cookie: it rides
105
- * Authorization: Bearer pk_… on fetch and ?ingest_key=pk_… on a headerless
106
- * page-unload beacon, so anonymous traffic is accepted and unload beacons work
107
- * without a bearer. The key is write-only (cannot read) and safe to ship in a
108
- * bundle; mint one per org via POST /v1/ingest/keys. This authenticates the
109
- * EVENT STREAM only — the error plane authenticates independently with `dsn`,
110
- * and one does not stand in for the other. */
103
+ /** Publishable ingest key (pk-…). When set, the client attributes writes to the
104
+ * ONE front door `/v1/event` with this key instead of a bearer/cookie: it rides
105
+ * Authorization: Bearer pk-… on fetch and ?ingest_key=pk-… on a headerless
106
+ * page-unload beacon, so ANONYMOUS traffic is attributed and unload beacons work
107
+ * without a bearer. The key is write-only it attributes a write and never mints
108
+ * a reading principal so it is safe to ship in a bundle. Mint one per org with
109
+ * POST /v1/keys {"type":"publishable"}.
110
+ *
111
+ * Omit it and the client reads NEXT_PUBLIC_EVENT_INGEST_KEY from the inlined
112
+ * build env, the same way `dsn` falls back — so a surface declares BOTH planes
113
+ * in its build and neither needs code to switch on. That is the ONE spelling
114
+ * the fleet already carries: KMS holds deploy/EVENT_INGEST_KEY, and each
115
+ * Dockerfile takes EVENT_INGEST_KEY as a build-arg and re-exports it with the
116
+ * NEXT_PUBLIC_ prefix that makes Next inline it.
117
+ *
118
+ * A surface with no key at all still reports for whoever is SIGNED IN (the
119
+ * session credential attributes them), and drops every logged-out visitor: the
120
+ * door refuses an unattributable write rather than filing it where its owner
121
+ * cannot read it. That failure is invisible from the page, which is why the key
122
+ * belongs in the env next to the DSN and not in a checklist.
123
+ *
124
+ * This attributes the EVENT STREAM only — the error plane authenticates
125
+ * independently with `dsn`, and one does not stand in for the other. */
111
126
  ingestKey?: string;
112
127
  /** Max events buffered before an automatic flush. */
113
128
  batchSize?: number;
package/dist/index.cjs CHANGED
@@ -246,7 +246,7 @@ function uuidv7Time(id) {
246
246
  }
247
247
 
248
248
  // src/version.ts
249
- var VERSION = "0.3.9";
249
+ var VERSION = "0.3.11";
250
250
 
251
251
  // src/sentry.ts
252
252
  var MAX_FRAMES = 50;
@@ -616,7 +616,23 @@ var Analytics = class {
616
616
  flushIntervalMs: 5e3,
617
617
  enabled: true,
618
618
  captureErrors: true,
619
- ...config
619
+ ...config,
620
+ // The publishable key resolves the SAME way the DSN below does: an explicit
621
+ // config wins, else the inlined build-time env.
622
+ //
623
+ // NEXT_PUBLIC_EVENT_INGEST_KEY is that env, and it is the name the fleet
624
+ // ALREADY carries end to end — KMS holds deploy/EVENT_INGEST_KEY, each
625
+ // Dockerfile takes it as the EVENT_INGEST_KEY build-arg and re-exports it
626
+ // with the NEXT_PUBLIC_ prefix Next needs to inline it. Reading anything
627
+ // else here would add a fourth spelling of one value.
628
+ //
629
+ // Without this the key was the one piece of wiring a surface could not
630
+ // declare the way it declares every other piece, so a surface that shipped
631
+ // without passing it in code sent its beacons unattributed — and an
632
+ // unattributed write is refused (401 ingest_key_required), which is silent
633
+ // in the page and invisible until you read the warehouse and find the host
634
+ // missing entirely.
635
+ ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_EVENT_INGEST_KEY")
620
636
  };
621
637
  this.transport = config.transport ?? new DefaultTransport();
622
638
  this.dsn = parseDsn(config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product));