TypeScript SDK
The TypeScript SDK works in Node 18+ and browser-compatible runtimes with fetch.
Install
npm install @workonward/sdkRepository/local source:
cd SDK/typescript
npm install
npm run buildSend
import { Workonward } from "@workonward/sdk";
const client = new Workonward({
apiKey: process.env.WORKONWARD_API_KEY!,
});
const result = await client.send("user@example.com", {
attribs: { first_name: "Ada" },
});
console.log(result.messageId, result.engine);Batch Send
const batch = await client.sendBatch(
["ada@example.com", "grace@example.com"],
{ attribs: { campaign: "launch" } },
);
console.log(batch.accepted, batch.messageIds);Browser-Compatible Usage
const client = new Workonward({
apiKey: tokenFromYourBackend,
fetch: window.fetch.bind(window),
});Only expose scoped keys to browsers if your security model allows it. For most applications, send from your backend.
Options
const client = new Workonward({
apiKey: process.env.WORKONWARD_API_KEY!,
baseUrl: "https://mail.gitdate.ink/api",
timeoutMs: 10_000,
retryConfig: { maxRetries: 2 },
headers: { "X-Request-Source": "billing-service" },
});The SDK controls X-API-Key and other protected auth headers.
Error Handling
import {
AuthenticationError,
InvalidRecipientError,
WorkonwardError,
} from "@workonward/sdk";
try {
await client.send("user@example.com");
} catch (error) {
if (error instanceof InvalidRecipientError) {
console.error("Bad recipient", error.message);
} else if (error instanceof AuthenticationError) {
console.error("API key rejected", error.code);
} else if (error instanceof WorkonwardError) {
console.error(error.code, error.statusCode, error.message);
}
}