Skip to content

feat(audience): add core types, utils, config, storage, and cookie#2812

Merged
nattb8 merged 2 commits intomainfrom
feat/sdk-33-core-types-utils-storage-cookie
Apr 1, 2026
Merged

feat(audience): add core types, utils, config, storage, and cookie#2812
nattb8 merged 2 commits intomainfrom
feat/sdk-33-core-types-utils-storage-cookie

Conversation

@nattb8
Copy link
Copy Markdown
Contributor

@nattb8 nattb8 commented Apr 1, 2026

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() using crypto.randomUUID with a fallback, and getTimestamp() 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_id cookie 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

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>
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 1, 2026

View your CI Pipeline Execution ↗ for commit 408f3c6

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 1s View ↗
nx affected -t build,lint,test ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-01 04:08:16 UTC

@nattb8 nattb8 changed the title feat: add core types, utils, config, storage, and cookie feat(audience): add core types, utils, config, storage, and cookie Apr 1, 2026
@nattb8 nattb8 marked this pull request as ready for review April 1, 2026 03:48
@nattb8 nattb8 requested a review from a team as a code owner April 1, 2026 03:49
- 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>
@nattb8 nattb8 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit f1a32d8 Apr 1, 2026
8 checks passed
@nattb8 nattb8 deleted the feat/sdk-33-core-types-utils-storage-cookie branch April 1, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants