add upsert and delete to contacts (#67)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
126
packages/sdk/types/schema.d.ts
vendored
126
packages/sdk/types/schema.d.ts
vendored
@@ -12,35 +12,35 @@ export interface paths {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": ({
|
||||
/**
|
||||
* @description The ID of the domain
|
||||
* @example 1
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* @description The name of the domain
|
||||
* @example example.com
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description The ID of the team
|
||||
* @example 1
|
||||
*/
|
||||
teamId: number;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @default us-east-1 */
|
||||
region?: string;
|
||||
/** @default false */
|
||||
clickTracking?: boolean;
|
||||
/** @default false */
|
||||
openTracking?: boolean;
|
||||
publicKey: string;
|
||||
dkimStatus?: string | null;
|
||||
spfDetails?: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
})[];
|
||||
/**
|
||||
* @description The ID of the domain
|
||||
* @example 1
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* @description The name of the domain
|
||||
* @example example.com
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description The ID of the team
|
||||
* @example 1
|
||||
*/
|
||||
teamId: number;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @default us-east-1 */
|
||||
region?: string;
|
||||
/** @default false */
|
||||
clickTracking?: boolean;
|
||||
/** @default false */
|
||||
openTracking?: boolean;
|
||||
publicKey: string;
|
||||
dkimStatus?: string | null;
|
||||
spfDetails?: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
})[];
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -71,12 +71,12 @@ export interface paths {
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
emailEvents: ({
|
||||
emailId: string;
|
||||
/** @enum {string} */
|
||||
status: "SCHEDULED" | "QUEUED" | "SENT" | "DELIVERY_DELAYED" | "BOUNCED" | "REJECTED" | "RENDERING_FAILURE" | "DELIVERED" | "OPENED" | "CLICKED" | "COMPLAINED" | "FAILED" | "CANCELLED";
|
||||
createdAt: string;
|
||||
data?: unknown;
|
||||
})[];
|
||||
emailId: string;
|
||||
/** @enum {string} */
|
||||
status: "SCHEDULED" | "QUEUED" | "SENT" | "DELIVERY_DELAYED" | "BOUNCED" | "REJECTED" | "RENDERING_FAILURE" | "DELIVERED" | "OPENED" | "CLICKED" | "COMPLAINED" | "FAILED" | "CANCELLED";
|
||||
createdAt: string;
|
||||
data?: unknown;
|
||||
})[];
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -122,9 +122,9 @@ export interface paths {
|
||||
text?: string;
|
||||
html?: string;
|
||||
attachments?: {
|
||||
filename: string;
|
||||
content: string;
|
||||
}[];
|
||||
filename: string;
|
||||
content: string;
|
||||
}[];
|
||||
/** Format: date-time */
|
||||
scheduledAt?: string;
|
||||
};
|
||||
@@ -192,6 +192,7 @@ export interface paths {
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
"/v1/contactBooks/{contactBookId}/contacts/{contactId}": {
|
||||
get: {
|
||||
@@ -253,6 +254,55 @@ export interface paths {
|
||||
};
|
||||
};
|
||||
};
|
||||
put: {
|
||||
parameters: {
|
||||
path: {
|
||||
contactBookId: string;
|
||||
contactId: string;
|
||||
};
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
email: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
properties?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
subscribed?: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Contact upserted successfully */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
contactId: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
delete: {
|
||||
parameters: {
|
||||
path: {
|
||||
contactBookId: string;
|
||||
contactId: string;
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Contact deleted successfully */
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
success: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user