Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ jobs:
- run: pnpm typecheck
- run: pnpm test
- run: pnpm build

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: pnpm/action-setup@f40ffcd9367d9f12939873eb1018b921a783ffaa # v4.3.0
with:
version: 9
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
29 changes: 29 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100
},
"linter": {
"enabled": true,
"rules": {
"preset": "recommended",
"suspicious": {
"noExplicitAny": "error"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"semicolons": "always"
}
}
}
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
"type": "git",
"url": "git+https://github.com/MillionSend/millionsend-node.git"
},
"keywords": ["millionsend", "resend", "email", "ses", "sdk", "transactional", "broadcast"],
"keywords": [
"millionsend",
"resend",
"email",
"ses",
"sdk",
"transactional",
"broadcast"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand All @@ -20,17 +28,25 @@
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": ["dist", "README.md", "CHANGELOG.md", "LICENSE"],
"files": [
"dist",
"README.md",
"CHANGELOG.md",
"LICENSE"
],
"engines": {
"node": ">=18"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"lint": "biome check .",
"lint:fix": "biome check --write .",
"prepack": "pnpm build"
},
"devDependencies": {
"@biomejs/biome": "2.5.13",
"@types/node": "^22.20.1",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
Expand Down
95 changes: 95 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function toErrorResponse(body: unknown, status: number): ErrorResponse {
if (body && typeof body === "object") {
const b = body as Record<string, unknown>;
const name = typeof b.name === "string" ? b.name : "application_error";
const message = typeof b.message === "string" ? b.message : `Request failed with status ${status}`;
const message =
typeof b.message === "string" ? b.message : `Request failed with status ${status}`;
const statusCode = typeof b.statusCode === "number" ? b.statusCode : status;
return { name, message, statusCode };
}
Expand Down
9 changes: 5 additions & 4 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ export class HttpClient {

constructor(apiKey: string, options: MillionSendOptions = {}) {
this.#apiKey = apiKey;
this.baseUrl = (options.baseUrl ?? process.env.MILLIONSEND_BASE_URL ?? DEFAULT_BASE_URL).replace(
/\/+$/,
"",
);
this.baseUrl = (
options.baseUrl ??
process.env.MILLIONSEND_BASE_URL ??
DEFAULT_BASE_URL
).replace(/\/+$/, "");
if (!options.allowInsecureHttp && isInsecureHttpUrl(this.baseUrl)) {
throw new Error(
`Refusing to send the API key over plain http to ${this.baseUrl}. Use https, or set allowInsecureHttp: true.`,
Expand Down
8 changes: 6 additions & 2 deletions src/resources/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type {
CreateContactOptions,
CreateContactsBatchOptions,
List,
ListContactTopicsOptions,
ListContactsOptions,
ListContactTopicsOptions,
RemoveContactOptions,
RemoveContactResponse,
RemoveContactSegmentResponse,
Expand Down Expand Up @@ -162,7 +162,11 @@ export class Contacts {
}

update(options: UpdateContactOptions): Promise<Result<ContactId>> {
return this.http.request({ method: "PATCH", path: contactPath(options), body: updateBody(options) });
return this.http.request({
method: "PATCH",
path: contactPath(options),
body: updateBody(options),
});
}

/** DELETE /contacts/:id — `erase` also scrubs the address from email history (`?erase=true`). */
Expand Down
10 changes: 8 additions & 2 deletions src/resources/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export class Batch {
constructor(private readonly http: HttpClient) {}

/** POST /emails/batch — 1–100 emails in one call; supports an Idempotency-Key and `batchValidation`. */
send(payload: SendEmailOptions[], options: BatchRequestOptions = {}): Promise<Result<BatchResponse>> {
send(
payload: SendEmailOptions[],
options: BatchRequestOptions = {},
): Promise<Result<BatchResponse>> {
return this.http.request({
method: "POST",
path: "/emails/batch",
Expand All @@ -121,7 +124,10 @@ export class Batch {
}

/** Alias of {@link send}, mirroring Resend. */
create(payload: SendEmailOptions[], options: BatchRequestOptions = {}): Promise<Result<BatchResponse>> {
create(
payload: SendEmailOptions[],
options: BatchRequestOptions = {},
): Promise<Result<BatchResponse>> {
return this.send(payload, options);
}
}
5 changes: 4 additions & 1 deletion src/resources/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class Templates {
}

get(idOrAlias: string): Promise<Result<Template>> {
return this.http.request({ method: "GET", path: `/templates/${encodeURIComponent(idOrAlias)}` });
return this.http.request({
method: "GET",
path: `/templates/${encodeURIComponent(idOrAlias)}`,
});
}

/** PATCH /templates/:idOrAlias — `alias`/`subject`/`text: null` clear the field. */
Expand Down
6 changes: 5 additions & 1 deletion src/resources/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export class Topics {
return this.http.request({
method: "PATCH",
path: `/topics/${encodeURIComponent(id)}`,
body: { name: payload.name, description: payload.description, visibility: payload.visibility },
body: {
name: payload.name,
description: payload.description,
visibility: payload.visibility,
},
});
}

Expand Down
9 changes: 7 additions & 2 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ describe("construction", () => {
expect(() => new MillionSend("ms_test")).toThrow(/allowInsecureHttp/);
delete process.env.MILLIONSEND_BASE_URL;
expect(
() => new MillionSend("ms_test", { baseUrl: "http://mail.example.com", allowInsecureHttp: true }),
() =>
new MillionSend("ms_test", { baseUrl: "http://mail.example.com", allowInsecureHttp: true }),
).not.toThrow();
expect(() => new MillionSend("ms_test", { baseUrl: "http://localhost:3001" })).not.toThrow();
expect(() => new MillionSend("ms_test", { baseUrl: "http://127.0.0.1:3001" })).not.toThrow();
Expand Down Expand Up @@ -164,7 +165,11 @@ describe("request wiring", () => {
it("passes the all_recipients_suppressed 422 through by name", async () => {
const { ms } = makeClient({
status: 422,
body: { statusCode: 422, name: "all_recipients_suppressed", message: "All recipients are suppressed" },
body: {
statusCode: 422,
name: "all_recipients_suppressed",
message: "All recipients are suppressed",
},
});
const res = await ms.emails.send({ from: "a@x.dev", to: "b@x.dev", subject: "s", text: "t" });
expect(res.data).toBeNull();
Expand Down
Loading
Loading