Skip to content

feat(email): add EmailClient for SDK email send preview#182

Draft
jcpsimmons wants to merge 1 commit into
mainfrom
feat/email-client-preview
Draft

feat(email): add EmailClient for SDK email send preview#182
jcpsimmons wants to merge 1 commit into
mainfrom
feat/email-client-preview

Conversation

@jcpsimmons
Copy link
Copy Markdown

What this is

Preview-grade addition of a small EmailClient surface to customerio-node. One constructor, one method (send), one input type. Calls POST /v1/send/email. Pairs with the gated path in the Edge PR below.

Files

  • lib/email.tsEmailClient class. Exports SDK_PREVIEW_USER_AGENT_MARKER so the marker stays in sync with the server.
  • lib/email-input.tsSendEmailInput type + runtime validator.
  • lib/request.tsCIORequest gains an optional third constructor arg, userAgentSuffix. When omitted (the default for TrackClient/APIClient), the User-Agent header is byte-identical to before. When provided (by EmailClient), it's appended.
  • test/email.ts — ava tests, 100% coverage on the new surface.
  • test/request.ts — two new test cases for the userAgentSuffix path.
  • examples/email-quickstart.ts — copy-paste demo.
  • package.json — version 4.4.0 → 4.5.0 (additive bump).
  • lib/version.ts — same version bump (kept in sync per existing test invariant).
  • README.md — new "Sending email (preview)" section.

How it's used

import { EmailClient } from 'customerio-node';

const cio = new EmailClient({ apiKey: process.env.CIO_API_KEY! });

const { delivery_id } = await cio.send({
  to: 'user@example.com',
  from: 'verified@yourdomain.com',
  subject: 'Hello',
  body: '<p>Hi there</p>',
});

Server-side gate

The SDK sets User-Agent: Customer.io Node Client/4.5.0 CioEmailSDK-Preview. The matching Edge gate (sister PR) treats this as the "I'm using the preview" signal and 403s unless the workspace has the sdk_email_send_preview flag enabled. Any existing key on an enrolled workspace will work — no new key minting required.

What this is NOT

  • Not a replacement for APIClient.sendEmail. That keeps working with the same User-Agent it always had.
  • Not a TrackClient change.
  • Not GA.

Sister PR

customerio/edge: feat(transactional): add gated User-Agent path for SDK email preview.

Tests

ava: 146 tests passed
coverage: 100% statements / 100% branches / 100% functions / 100% lines

Preview-grade. New EmailClient class with one method, `send`, calling
POST /v1/send/email. Identifies itself to the server via a
"CioEmailSDK-Preview" suffix on User-Agent so the matching Edge gate
can scope rollout per workspace.

- lib/email.ts: EmailClient class, exports SDK_PREVIEW_USER_AGENT_MARKER
- lib/email-input.ts: SendEmailInput type + runtime validator
- lib/request.ts: CIORequest gains optional userAgentSuffix constructor
  arg; defaults preserve existing User-Agent string exactly
- test/email.ts: ava suite covering constructor, region routing, all
  validator branches — 100% coverage maintained
- test/request.ts: two new test cases for the userAgentSuffix path
- examples/email-quickstart.ts: copy-paste demo
- README.md: "Sending email (preview)" section

Existing APIClient and TrackClient surfaces and HTTP behavior are
unchanged when no userAgentSuffix is provided (the default).
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