feat: add contactBooks to sdk, add delete campaign public endpoint (#352)

* feat: add contactBooks to sdk, add delete campaign public endpoint

* fix: pr review notes

* refactor: pr feedback

* feat: bulk delete/create contacts

* refactor: rename a few methods for consistency

* refactor: update openapi docs based on pr feedback

* refactor: update open api docs, based on pr feedback

* fix: delete campaign security issue

* refactor: delete campaign requires team id (from context)

* fix: enums
This commit is contained in:
Dave Stockley
2026-03-03 20:10:43 +00:00
committed by GitHub
parent 73416dc481
commit 7428a1fbfa
22 changed files with 1365 additions and 218 deletions
+43
View File
@@ -13,6 +13,19 @@ type CreateCampaignResponse = {
type CreateCampaignResponseSuccess =
paths["/v1/campaigns"]["post"]["responses"]["200"]["content"]["application/json"];
type GetAllCampaignsQuery = {
page?: string;
status?: NonNullable<paths["/v1/campaigns"]["get"]["parameters"]["query"]>["status"];
search?: string;
};
type GetAllCampaignsResponseSuccess = paths["/v1/campaigns"]["get"]["responses"]["200"]["content"]["application/json"];
type GetAllCampaignsResponse = {
data: GetAllCampaignsResponseSuccess | null;
error: ErrorResponse | null;
};
type GetCampaignResponseSuccess =
paths["/v1/campaigns/{campaignId}"]["get"]["responses"]["200"]["content"]["application/json"];
@@ -32,6 +45,14 @@ type ScheduleCampaignResponse = {
error: ErrorResponse | null;
};
type DeleteCampaignResponseSuccess =
paths["/v1/campaigns/{campaignId}"]["delete"]["responses"]["200"]["content"]["application/json"];
type DeleteCampaignResponse = {
data: DeleteCampaignResponseSuccess | null;
error: ErrorResponse | null;
};
type CampaignActionResponseSuccess = { success: boolean };
type CampaignActionResponse = {
@@ -55,6 +76,21 @@ export class Campaigns {
return data;
}
async getAll(
query?: GetAllCampaignsQuery,
): Promise<GetAllCampaignsResponse> {
const params = new URLSearchParams();
if (query?.page) params.set("page", query.page);
if (query?.status) params.set("status", query.status);
if (query?.search) params.set("search", query.search);
const queryString = params.toString();
const path = queryString ? `/campaigns?${queryString}` : `/campaigns`;
const data = await this.usesend.get<GetAllCampaignsResponseSuccess>(path);
return data;
}
async get(campaignId: string): Promise<GetCampaignResponse> {
const data = await this.usesend.get<GetCampaignResponseSuccess>(
`/campaigns/${campaignId}`,
@@ -91,4 +127,11 @@ export class Campaigns {
return data;
}
async delete(campaignId: string): Promise<DeleteCampaignResponse> {
const data = await this.usesend.delete<DeleteCampaignResponseSuccess>(
`/campaigns/${campaignId}`,
);
return data;
}
}
+46
View File
@@ -43,6 +43,28 @@ type UpsertContactResponse = {
error: ErrorResponse | null;
};
type BulkCreateContactsPayload =
paths["/v1/contactBooks/{contactBookId}/contacts/bulk"]["post"]["requestBody"]["content"]["application/json"];
type BulkCreateContactsResponseSuccess =
paths["/v1/contactBooks/{contactBookId}/contacts/bulk"]["post"]["responses"]["200"]["content"]["application/json"];
type BulkCreateContactsResponse = {
data: BulkCreateContactsResponseSuccess | null;
error: ErrorResponse | null;
};
type BulkDeleteContactsPayload =
paths["/v1/contactBooks/{contactBookId}/contacts/bulk"]["delete"]["requestBody"]["content"]["application/json"];
type BulkDeleteContactsResponseSuccess =
paths["/v1/contactBooks/{contactBookId}/contacts/bulk"]["delete"]["responses"]["200"]["content"]["application/json"];
type BulkDeleteContactsResponse = {
data: BulkDeleteContactsResponseSuccess | null;
error: ErrorResponse | null;
};
type DeleteContactResponse = {
data: { success: boolean } | null;
error: ErrorResponse | null;
@@ -101,6 +123,30 @@ export class Contacts {
return data;
}
async bulkCreate(
contactBookId: string,
payload: BulkCreateContactsPayload
): Promise<BulkCreateContactsResponse> {
const data = await this.usesend.post<BulkCreateContactsResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/bulk`,
payload
);
return data;
}
async bulkDelete(
contactBookId: string,
payload: BulkDeleteContactsPayload
): Promise<BulkDeleteContactsResponse> {
const data = await this.usesend.delete<BulkDeleteContactsResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/bulk`,
payload
);
return data;
}
async delete(
contactBookId: string,
contactId: string
+97
View File
@@ -0,0 +1,97 @@
import { UseSend } from "./usesend";
import { paths } from "../types/schema";
import { ErrorResponse } from "../types";
type GetAllContactBooksResponseSuccess =
paths["/v1/contactBooks"]["get"]["responses"]["200"]["content"]["application/json"];
type GetAllContactBooksResponse = {
data: GetAllContactBooksResponseSuccess | null;
error: ErrorResponse | null;
};
type CreateContactBookPayload =
paths["/v1/contactBooks"]["post"]["requestBody"]["content"]["application/json"];
type CreateContactBookResponseSuccess =
paths["/v1/contactBooks"]["post"]["responses"]["200"]["content"]["application/json"];
type CreateContactBookResponse = {
data: CreateContactBookResponseSuccess | null;
error: ErrorResponse | null;
};
type GetContactBookResponseSuccess =
paths["/v1/contactBooks/{contactBookId}"]["get"]["responses"]["200"]["content"]["application/json"];
type GetContactBookResponse = {
data: GetContactBookResponseSuccess | null;
error: ErrorResponse | null;
};
type UpdateContactBookPayload =
paths["/v1/contactBooks/{contactBookId}"]["patch"]["requestBody"]["content"]["application/json"];
type UpdateContactBookResponseSuccess =
paths["/v1/contactBooks/{contactBookId}"]["patch"]["responses"]["200"]["content"]["application/json"];
type UpdateContactBookResponse = {
data: UpdateContactBookResponseSuccess | null;
error: ErrorResponse | null;
};
type DeleteContactBookResponseSuccess =
paths["/v1/contactBooks/{contactBookId}"]["delete"]["responses"]["200"]["content"]["application/json"];
type DeleteContactBookResponse = {
data: DeleteContactBookResponseSuccess | null;
error: ErrorResponse | null;
};
export class ContactBooks {
constructor(private readonly usesend: UseSend) {
this.usesend = usesend;
}
async list(): Promise<GetAllContactBooksResponse> {
const data = await this.usesend.get<GetAllContactBooksResponseSuccess>(
`/contactBooks`,
);
return data;
}
async get(contactBookId: string): Promise<GetContactBookResponse> {
const data = await this.usesend.get<GetContactBookResponseSuccess>(
`/contactBooks/${contactBookId}`,
);
return data;
}
async create(
payload: CreateContactBookPayload,
): Promise<CreateContactBookResponse> {
const data = await this.usesend.post<CreateContactBookResponseSuccess>(
`/contactBooks`,
payload,
);
return data;
}
async update(
contactBookId: string,
payload: UpdateContactBookPayload,
): Promise<UpdateContactBookResponse> {
const data = await this.usesend.patch<UpdateContactBookResponseSuccess>(
`/contactBooks/${contactBookId}`,
payload,
);
return data;
}
async delete(contactBookId: string): Promise<DeleteContactBookResponse> {
const data = await this.usesend.delete<DeleteContactBookResponseSuccess>(
`/contactBooks/${contactBookId}`,
);
return data;
}
}
+2
View File
@@ -1,5 +1,6 @@
import { ErrorResponse } from "../types";
import { Contacts } from "./contact";
import { ContactBooks } from "./contactBook";
import { Emails } from "./email";
import { Domains } from "./domain";
import { Campaigns } from "./campaign";
@@ -23,6 +24,7 @@ export class UseSend {
readonly emails = new Emails(this);
readonly domains = new Domains(this);
readonly contacts = new Contacts(this);
readonly contactBooks = new ContactBooks(this);
readonly campaigns = new Campaigns(this);
url = baseUrl;