rebrand to useSend (#210)

This commit is contained in:
KM Koushik
2025-09-03 08:21:55 +10:00
committed by GitHub
parent b1a59d2705
commit 07c53d3f58
219 changed files with 1349 additions and 2835 deletions

View File

@@ -1,4 +1,4 @@
import { Unsend } from "./unsend";
import { UseSend } from "./usesend";
import { paths } from "../types/schema";
import { ErrorResponse } from "../types";
@@ -49,15 +49,15 @@ type DeleteContactResponse = {
};
export class Contacts {
constructor(private readonly unsend: Unsend) {
this.unsend = unsend;
constructor(private readonly usesend: UseSend) {
this.usesend = usesend;
}
async create(
contactBookId: string,
payload: CreateContactPayload
): Promise<CreateContactResponse> {
const data = await this.unsend.post<CreateContactResponseSuccess>(
const data = await this.usesend.post<CreateContactResponseSuccess>(
`/contactBooks/${contactBookId}/contacts`,
payload
);
@@ -69,7 +69,7 @@ export class Contacts {
contactBookId: string,
contactId: string
): Promise<GetContactResponse> {
const data = await this.unsend.get<GetContactResponseSuccess>(
const data = await this.usesend.get<GetContactResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/${contactId}`
);
return data;
@@ -80,7 +80,7 @@ export class Contacts {
contactId: string,
payload: UpdateContactPayload
): Promise<UpdateContactResponse> {
const data = await this.unsend.patch<UpdateContactResponseSuccess>(
const data = await this.usesend.patch<UpdateContactResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/${contactId}`,
payload
);
@@ -93,7 +93,7 @@ export class Contacts {
contactId: string,
payload: UpsertContactPayload
): Promise<UpsertContactResponse> {
const data = await this.unsend.put<UpsertContactResponseSuccess>(
const data = await this.usesend.put<UpsertContactResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/${contactId}`,
payload
);
@@ -105,7 +105,7 @@ export class Contacts {
contactBookId: string,
contactId: string
): Promise<DeleteContactResponse> {
const data = await this.unsend.delete<{ success: boolean }>(
const data = await this.usesend.delete<{ success: boolean }>(
`/contactBooks/${contactBookId}/contacts/${contactId}`
);

View File

@@ -1,6 +1,6 @@
import { paths } from "../types/schema";
import { ErrorResponse } from "../types";
import { Unsend } from "./unsend";
import { UseSend } from "./usesend";
type CreateDomainPayload =
paths["/v1/domains"]["post"]["requestBody"]["content"]["application/json"];
@@ -30,17 +30,17 @@ type VerifyDomainResponseSuccess =
paths["/v1/domains/{id}/verify"]["put"]["responses"]["200"]["content"]["application/json"];
export class Domains {
constructor(private readonly unsend: Unsend) {
this.unsend = unsend;
constructor(private readonly usesend: UseSend) {
this.usesend = usesend;
}
async list(): Promise<GetDomainsResponse> {
const data = await this.unsend.get<GetDomainsResponseSuccess>("/domains");
const data = await this.usesend.get<GetDomainsResponseSuccess>("/domains");
return data;
}
async create(payload: CreateDomainPayload): Promise<CreateDomainResponse> {
const data = await this.unsend.post<CreateDomainResponseSuccess>(
const data = await this.usesend.post<CreateDomainResponseSuccess>(
"/domains",
payload
);
@@ -48,7 +48,7 @@ export class Domains {
}
async verify(id: number): Promise<VerifyDomainResponse> {
const data = await this.unsend.put<VerifyDomainResponseSuccess>(
const data = await this.usesend.put<VerifyDomainResponseSuccess>(
`/domains/${id}/verify`,
{}
);

View File

@@ -1,6 +1,6 @@
import { render } from "@react-email/render";
import * as React from "react";
import { Unsend } from "./unsend";
import { UseSend } from "./usesend";
import { paths } from "../types/schema";
import { ErrorResponse } from "../types";
@@ -68,8 +68,8 @@ type BatchEmailResponse = {
};
export class Emails {
constructor(private readonly unsend: Unsend) {
this.unsend = unsend;
constructor(private readonly usesend: UseSend) {
this.usesend = usesend;
}
async send(payload: SendEmailPayload) {
@@ -82,7 +82,7 @@ export class Emails {
delete payload.react;
}
const data = await this.unsend.post<CreateEmailResponseSuccess>(
const data = await this.usesend.post<CreateEmailResponseSuccess>(
"/emails",
payload
);
@@ -98,7 +98,7 @@ export class Emails {
*/
async batch(payload: BatchEmailPayload): Promise<BatchEmailResponse> {
// Note: React element rendering is not supported in batch mode.
const response = await this.unsend.post<BatchEmailResponseSuccess>(
const response = await this.usesend.post<BatchEmailResponseSuccess>(
"/emails/batch",
payload
);
@@ -109,7 +109,7 @@ export class Emails {
}
async get(id: string): Promise<GetEmailResponse> {
const data = await this.unsend.get<GetEmailResponseSuccess>(
const data = await this.usesend.get<GetEmailResponseSuccess>(
`/emails/${id}`
);
return data;
@@ -119,7 +119,7 @@ export class Emails {
id: string,
payload: UpdateEmailPayload
): Promise<UpdateEmailResponse> {
const data = await this.unsend.patch<UpdateEmailResponseSuccess>(
const data = await this.usesend.patch<UpdateEmailResponseSuccess>(
`/emails/${id}`,
payload
);
@@ -127,7 +127,7 @@ export class Emails {
}
async cancel(id: string): Promise<CancelEmailResponse> {
const data = await this.unsend.post<CancelEmailResponseSuccess>(
const data = await this.usesend.post<CancelEmailResponseSuccess>(
`/emails/${id}/cancel`,
{}
);

View File

@@ -2,15 +2,15 @@ import { ErrorResponse } from "../types";
import { Contacts } from "./contact";
import { Emails } from "./email";
const defaultBaseUrl = "https://app.unsend.dev";
const defaultBaseUrl = "https://app.usesend.com";
// eslint-disable-next-line turbo/no-undeclared-env-vars
const baseUrl = `${process?.env?.UNSEND_BASE_URL ?? defaultBaseUrl}/api/v1`;
const baseUrl = `${process?.env?.USESEND_BASE_URL ?? process?.env?.UNSEND_BASE_URL ?? defaultBaseUrl}/api/v1`;
function isUNSENDErrorResponse(error: { error: ErrorResponse }) {
function isUseSendErrorResponse(error: { error: ErrorResponse }) {
return error.error.code !== undefined;
}
export class Unsend {
export class UseSend {
private readonly headers: Headers;
// readonly domains = new Domains(this);
@@ -24,12 +24,12 @@ export class Unsend {
) {
if (!key) {
if (typeof process !== "undefined" && process.env) {
this.key = process.env.UNSEND_API_KEY;
this.key = process.env.USESEND_API_KEY ?? process.env.UNSEND_API_KEY;
}
if (!this.key) {
throw new Error(
'Missing API key. Pass it to the constructor `new Unsend("us_123")`'
'Missing API key. Pass it to the constructor `new UseSend("us_123")`'
);
}
}
@@ -57,7 +57,7 @@ export class Unsend {
if (!response.ok) {
try {
const resp = await response.json();
if (isUNSENDErrorResponse(resp)) {
if (isUseSendErrorResponse(resp)) {
return { data: null, error: resp };
}