Add contacts api to sdk (#52)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "unsend",
|
"name": "unsend",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
@@ -0,0 +1,74 @@
|
|||||||
|
import { Unsend } from "./unsend";
|
||||||
|
import { paths } from "../types/schema";
|
||||||
|
import { ErrorResponse } from "../types";
|
||||||
|
|
||||||
|
type CreateContactPayload =
|
||||||
|
paths["/v1/contactBooks/{contactBookId}/contacts"]["post"]["requestBody"]["content"]["application/json"];
|
||||||
|
|
||||||
|
type CreateContactResponse = {
|
||||||
|
data: CreateContactResponseSuccess | null;
|
||||||
|
error: ErrorResponse | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CreateContactResponseSuccess =
|
||||||
|
paths["/v1/contactBooks/{contactBookId}/contacts"]["post"]["responses"]["200"]["content"]["application/json"];
|
||||||
|
|
||||||
|
type GetContactResponseSuccess =
|
||||||
|
paths["/v1/contactBooks/{contactBookId}/contacts/{contactId}"]["get"]["responses"]["200"]["content"]["application/json"];
|
||||||
|
|
||||||
|
type GetContactResponse = {
|
||||||
|
data: GetContactResponseSuccess | null;
|
||||||
|
error: ErrorResponse | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UpdateContactPayload =
|
||||||
|
paths["/v1/contactBooks/{contactBookId}/contacts/{contactId}"]["patch"]["requestBody"]["content"]["application/json"];
|
||||||
|
|
||||||
|
type UpdateContactResponseSuccess =
|
||||||
|
paths["/v1/contactBooks/{contactBookId}/contacts/{contactId}"]["patch"]["responses"]["200"]["content"]["application/json"];
|
||||||
|
|
||||||
|
type UpdateContactResponse = {
|
||||||
|
data: UpdateContactResponseSuccess | null;
|
||||||
|
error: ErrorResponse | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class Contacts {
|
||||||
|
constructor(private readonly unsend: Unsend) {
|
||||||
|
this.unsend = unsend;
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
contactBookId: string,
|
||||||
|
payload: CreateContactPayload
|
||||||
|
): Promise<CreateContactResponse> {
|
||||||
|
const data = await this.unsend.post<CreateContactResponseSuccess>(
|
||||||
|
`/contactBooks/${contactBookId}/contacts`,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(
|
||||||
|
contactBookId: string,
|
||||||
|
contactId: string
|
||||||
|
): Promise<GetContactResponse> {
|
||||||
|
const data = await this.unsend.get<GetContactResponseSuccess>(
|
||||||
|
`/contactBooks/${contactBookId}/contacts/${contactId}`
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
contactBookId: string,
|
||||||
|
contactId: string,
|
||||||
|
payload: UpdateContactPayload
|
||||||
|
): Promise<UpdateContactResponse> {
|
||||||
|
const data = await this.unsend.patch<UpdateContactResponseSuccess>(
|
||||||
|
`/contactBooks/${contactBookId}/contacts/${contactId}`,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { ErrorResponse } from "../types";
|
import { ErrorResponse } from "../types";
|
||||||
|
import { Contacts } from "./contact";
|
||||||
import { Emails } from "./email";
|
import { Emails } from "./email";
|
||||||
|
|
||||||
const defaultBaseUrl = "https://app.unsend.dev";
|
const defaultBaseUrl = "https://app.unsend.dev";
|
||||||
@@ -14,6 +15,7 @@ export class Unsend {
|
|||||||
|
|
||||||
// readonly domains = new Domains(this);
|
// readonly domains = new Domains(this);
|
||||||
readonly emails = new Emails(this);
|
readonly emails = new Emails(this);
|
||||||
|
readonly contacts = new Contacts(this);
|
||||||
url = baseUrl;
|
url = baseUrl;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
Reference in New Issue
Block a user