add upsert and delete to contacts (#67)

This commit is contained in:
8x4
2024-09-05 01:18:21 +02:00
committed by GitHub
parent 48b2220ea3
commit 259937c60c
8 changed files with 436 additions and 105 deletions

View File

@@ -32,6 +32,22 @@ type UpdateContactResponse = {
error: ErrorResponse | null;
};
type UpsertContactPayload =
paths["/v1/contactBooks/{contactBookId}/contacts/{contactId}"]["put"]["requestBody"]["content"]["application/json"];
type UpsertContactResponseSuccess =
paths["/v1/contactBooks/{contactBookId}/contacts/{contactId}"]["put"]["responses"]["200"]["content"]["application/json"];
type UpsertContactResponse = {
data: UpsertContactResponseSuccess | null;
error: ErrorResponse | null;
};
type DeleteContactResponse = {
data: { success: boolean } | null;
error: ErrorResponse | null;
};
export class Contacts {
constructor(private readonly unsend: Unsend) {
this.unsend = unsend;
@@ -71,4 +87,28 @@ export class Contacts {
return data;
}
async upsert(
contactBookId: string,
contactId: string,
payload: UpsertContactPayload
): Promise<UpsertContactResponse> {
const data = await this.unsend.put<UpsertContactResponseSuccess>(
`/contactBooks/${contactBookId}/contacts/${contactId}`,
payload
);
return data;
}
async delete(
contactBookId: string,
contactId: string
): Promise<DeleteContactResponse> {
const data = await this.unsend.delete<{ success: boolean }>(
`/contactBooks/${contactBookId}/contacts/${contactId}`
);
return data;
}
}