Skip to content

Pass 1: W3, W10 (C7), W11 (C8), W12, W14, W15 - #5

Merged
czypnt merged 10 commits into
mainfrom
pass1-cleanup
Nov 22, 2026
Merged

czypnt merged 10 commits into
mainfrom
pass1-cleanup

Conversation

@czypnt

@czypnt czypnt commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Based on main, not on #3 (FX-047), which edits the same file. Expect a small rebase conflict in src/index.ts / tests/test.ts for whichever merges second.

W3: drop warnings log once per client

  • What: the per-event console.warns ignored debug and printed on every dropped event. Each kind (invalid track() name, identify() / alias() without id, group() without groupId, trackPurchase() without a finite value, drop after max flush attempts) now logs once per client, then only with debug: true. onDrop / onError still fire for every event.
  • Where: src/index.ts new warnOnce(); call sites in track, identify, alias, group, trackPurchase, _flush (max attempts).
  • Test: tests/test.ts "W3" block: 2 events dropped after 10 failed cycles give 1 warning and 2 onDrop calls; 11 invalid calls of 5 kinds give 5 warnings and 11 onDrop calls; with debug: true every repeat is logged.

W12: shared exit listener, sk_ keys, Stripe example

  • (a) One process-level beforeExit listener for all live clients (was one per instance, so 11+ clients triggered MaxListenersExceededWarning). Each client is still flushed once on exit (same as the old process.once), and the listener is removed when the last client closes. Uses a Set, not WeakRef: an unclosed client is already held by its flush timer, so a weak reference would not free anything, and it avoids a tsconfig lib change. src/index.ts registerExitHook / flushAllOnExit / unregisterExitHook.
    Test: "W12a" block: 20 clients add at most 1 listener; closing them removes it; beforeExit flushes every live client's queue.
  • (b) The key-prefix warning accepts sk_ as well as dk_. Test: "W12b" block.
  • (c) examples/stripe-webhook.js: the Stripe customer id goes in externalIds: { stripe } instead of being used as userId; identify() runs only when the app's own user id is known. The trackPurchase() part of the example is in the C8 commit, because it needs C8.

W14: tests

tests/test.ts "W14" blocks: page() with a url, group() success, externalIds on track() (present when passed, absent otherwise), a fetch that throws (reaches onError, re-queued, sent on recovery), a hung request aborted at timeout, the exact context shape, and context.version / User-Agent equal to package.json version.

W15: CHANGELOG

Added 1.0.1–1.0.4 (from the registry; no source history exists for them, so the entries say so), 1.2.2 and 1.2.3 (from git log v1.2.1..v1.2.3), all marked "(entry added later)". Dates of 1.2.1, 1.2.0 (2026-01-01) and 1.1.0 (2025-09-04) set to the registry dates. New behaviour is listed under "Unreleased".

W10 / C7: page() stops copying name into properties.url

  • What: with no url passed, page() set properties.url = name, recording a page name as its URL. name now goes only in properties.name.
  • Where: src/index.ts page().
  • Test: "C7" assertion in the W14 block (page('u', 'Checkout') sends no url key).

W11 / C8: trackPurchase() accepts externalIds

  • What: opts.externalIds (same type as track()'s) is passed to track(), so it is sent the same way, only when passed.
  • Where: src/index.ts trackPurchase() options type and call.
  • Test: "C8" assertions in the 9.D.6 block (sent when passed; no key otherwise).

Changes to what the SDK sends

  • 3aac161 SEND CHANGE C7: page() no longer sends properties.url = page name when no url is passed.
  • f60a168 SEND CHANGE C8: trackPurchase() sends externalIds when the caller passes it.

Each is its own commit and can be reverted alone (C8 also carries the example's trackPurchase() line).

Not done

  • W14 Node 18/20 dist smoke test: needs a CI change (out of scope for this pass).
  • CHANGELOG: 1.0.0 is dated 2024-12 but the registry says 2025-08-18, and 1.3.2 says 2026-07-25 vs registry 2026-07-26 (UTC). Not in the W15 list, left as is.

🤖 Generated with Claude Code


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

czypnt and others added 7 commits November 22, 2026 14:24
Per-event warnings (validation drops in track/identify/alias/group/trackPurchase and the
max-flush-attempts drop) printed on every event and ignored debug. Log the first of each
kind once per instance, repeats only with debug: true. onDrop/onError unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uses externalIds

- One process-level beforeExit listener for all live clients (was one per instance);
  each client is still flushed once on exit; listener removed when the last client closes.
- Key-prefix warning also accepts sk_ (server key).
- examples/stripe-webhook.js: Stripe customer id goes in externalIds.stripe, not userId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… context and version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… for 1.1.0-1.2.1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
page() put the page name into properties.url when no url was passed, so a name like
"Pricing" was recorded as the page URL. name now goes only in properties.name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
trackPurchase() options take externalIds (same shape and handling as track()) and send it
on the envelope the same way, only when passed. The Stripe example passes the Stripe
customer id this way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inks provider ids only from the provider's own connection)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@czypnt

czypnt commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Reviews: A APPROVE (code; shared exit listener behaves as before in every traced case). B OK (server side: C8 externalIds on purchase is accepted and changes no revenue, dedup or postback; C7 changes only cosmetic page fields; Node $pageview rows are not in the page reports). Follow-up from B pushed: the Stripe example no longer claims DATALYR joins on externalIds.stripe (ingest refuses provider namespaces from non-provider sources, lib/person-contract.js namespaceRefusal). Rebase note if #3 merges first is in the SDK handoff. C7 and C8 need the owner's yes.

czypnt and others added 3 commits November 22, 2026 14:59
…SDK (comments and changelog only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Source resolutions:
- src/index.ts TrackOptions.externalIds JSDoc: this PR's rewrite.
- src/index.ts fields: main's retry/inFlight/drop-count fields kept; this PR's
  warnedKinds, exitFlushed and shared liveClients/exitListener kept; flushAttempts
  (gone in main) and exitHook (gone here) dropped.
- src/index.ts registerExitHook: this PR's shared beforeExit listener, calling
  main's startDrain() instead of flush(), as main's per-client hook did.
- src/index.ts _flush failure path: main's handleFailure; this PR's once-only
  "failed flush attempts" warning dropped in favour of main's per-cycle drop summary.
- tests/test.ts W3: the 10-cycle drop no longer exists; now two final-400 drops in
  one flush must give one summary line. W14 network-recovery test waits out the
  first backoff before re-flushing.
- CHANGELOG: one Unreleased; this PR's entries under main's Changed/Added, the
  warning entry no longer mentions failed-attempt drops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@czypnt
czypnt merged commit 272d58c into main Nov 22, 2026
2 checks passed
@czypnt
czypnt deleted the pass1-cleanup branch November 22, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant