feat(audience): add core types, utils, config, storage, and cookie#2812
Merged
feat(audience): add core types, utils, config, storage, and cookie#2812
Conversation
Add the foundational modules for @imtbl/audience-core: - types: message types matching the audience service API contract - utils: isBrowser, generateId (UUID v4), getTimestamp - config: environment URLs, endpoint paths, flush/cookie constants - storage: localStorage wrapper with prefix and graceful degradation - cookie: shared anonymous ID (imtbl_anon_id) for cross-surface stitching Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit 408f3c6
☁️ Nx Cloud last updated this comment at |
- storage.getItem returns unknown instead of casting to T, so callers validate the shape rather than trusting stale data - cookie sets the Secure flag when served over HTTPS Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bkbooth
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
The foundational modules for
@imtbl/audience-core. These are the building blocks that the transport/queue layer (SDK-34) and the web SDK (SDK-30) will import from.types.ts — Message types that match the audience service API contract. Covers all five event types:
track,page,screen,identify,alias. Each has its own typed interface so consumers get compile-time checks on which fields are required per type.utils.ts — Three small helpers:
isBrowser()for environment detection,generateId()usingcrypto.randomUUIDwith a fallback, andgetTimestamp()for ISO timestamps.config.ts — Environment URLs (dev/sandbox/prod), API endpoint paths, flush constants, and cookie settings. Single source of truth for all the magic strings.
storage.ts — Thin localStorage wrapper with a
__imtbl_audience_prefix. Gracefully degrades when storage is unavailable (private browsing, SSR).cookie.ts — Reads and writes the
imtbl_anon_idcookie that's shared between the web SDK and pixel. When a visitor hits a studio's website, the pixel sets this cookie. When they navigate to the storefront SPA, the SDK reads the same cookie. This is what makes pre-signup attribution work. Note: the cookie helper is intentionally consent-unaware — consent gating is handled at the web SDK layer in SDK-31.Tests
18 tests covering cookie lifecycle, storage round-tripping, ID generation uniqueness, and config URLs.
What's next
SDK-34 adds transport, queue, and context collection on top of these modules.
Linear: https://linear.app/imtbl/issue/SDK-33
🤖 Generated with Claude Code