fix(email-sending): TypeScript send example omits required recipient and content

Open Beginner friendly
#2,821 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
nodejs, typescript
Domain
api, documentation

Research direction

The inline example for client.emailSending.send() lives in src/resources/email-sending/email-sending.ts and is mirrored in the generated resources/email-sending/email-sending.d.ts. Start by reading the example block and the send method's parameter types there, then run the reproduce.mjs script from the issue to see the failing body. Done means the example includes a recipient (to) and a message body (text or html), and the reproduction script's assertion passes.

Written by the indexing model from the issue text.

Description

Confirm this is a TypeScript library issue and not an underlying Cloudflare API issue
  • This is an issue with the TypeScript library
Describe the bug

The inline example for client.emailSending.send() in the TypeScript SDK omits both required groups of fields. Copying the example produces a request with a sender and subject but without a recipient or message body.

To Reproduce

In an empty directory with Node.js and npm, install the SDK version listed under Library version and download the Cloudflare API schema.

npm install --no-save [email protected] [email protected] [email protected]
curl -fsSLo openapi.json https://raw.githubusercontent.com/cloudflare/api-schemas/e8a594125422f0a4618aaec209c7cd49299c8b6f/openapi.json

Save the script as reproduce.mjs and run node reproduce.mjs. It captures the JSON that the SDK passes to an injected Fetch function and validates both the shipped example and a control against the request schema. A zero exit confirms the example fails validation and the control passes. No API credential or live request is needed.

Reproduction script: reproduce.mjs
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import Ajv from 'ajv-draft-04';
import Cloudflare from 'cloudflare';

const spec = JSON.parse(await readFile('openapi.json', 'utf8'));
const path = '/accounts/{account_id}/email/sending/send';
const request = spec.paths[path].post.requestBody.content['application/json'].schema;
const schemas = Object.fromEntries(Object.entries(spec.components.schemas).filter(([name]) => name.startsWith("email-sending_")));
const validate = new Ajv({ allErrors: true, strict: false, validateFormats: false })
  .compile({ ...request, components: { schemas } });
const calls = [];
const client = new Cloudflare({
  apiToken: 'offline-fixture',
  maxRetries: 0,
  fetch: async (url, init) => {
    assert.equal(new URL(url).pathname, '/client/v4/accounts/account_id/email/sending/send');
    const payload = JSON.parse(init.body);
    const valid = validate(payload);
    const missingGroups = validate.errors?.filter((error) => error.keyword === 'anyOf').length ?? 0;
    calls.push({ payload, valid, missingGroups });
    return Response.json({ success: true, errors: [], messages: [], result: {} });
  },
});

const example = {
  account_id: 'account_id',
  from: '[email protected]',
  subject: 'Monthly Report',
};
await client.emailSending.send(example);
await client.emailSending.send({ ...example, to: '[email protected]', text: 'Report ready.' });
console.log(JSON.stringify(calls, null, 2));
assert.deepEqual(calls.map(({ valid, missingGroups }) => [valid, missingGroups]), [[false, 2], [true, 0]]);

Expected behavior

The SDK example builds a request that satisfies the structured send API. The request needs at least one of to, cc, or bcc, and at least one of text or html.

Actual behavior

The example produced {"from":"[email protected]","subject":"Monthly Report"}. Cloudflare's published OpenAPI request schema rejected the request for missing both required groups. Adding a to address and a text body to the same call produced JSON that passed validation.

Evidence

  • Expected source: Cloudflare Send an email API reference and the pinned schema in the setup command, specifically the request body for POST /accounts/{account_id}/email/sending/send.
  • Failure source: The local mock Fetch captured the exact serialized body from the example shipped in resources/email-sending/email-sending.d.ts. The same example appears in the SDK source.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete
OS

Linux x64

Runtime version

Node.js v26.12.0

Library version

cloudflare 7.3.0 (npm). The linked SDK source is shared by the latest GitHub release, v7.4.0, and the default branch.

Restoration check

Run the example shipped with the SDK through the same Fetch capture and validate the JSON against the structured send schema. The copied example should pass alongside the valid control.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Developers copying the inline example for their first structured send get a request that fails the published schema before they can test sending.
  • Workaround status: available
  • Workaround basis: Supplying a recipient and message content in the SDK call produced valid request JSON in the offline control.
Dominant language
TypeScript
Stars
835
Forks
201
Avg merge
41m
Merged PRs (30d)
1

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/cloudflare-typescript

All issues in cloudflare/cloudflare-typescript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.