Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/interfaces/get-option.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface GetOptions {
query?: Record<string, any>;
}
4 changes: 4 additions & 0 deletions src/common/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './get-option.interface';
export * from './list-option.interface';
export * from './post-option.interface';
export * from './put-option.interface';
4 changes: 4 additions & 0 deletions src/common/interfaces/list-option.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface List<T> {
readonly object: 'list';
data: T[];
}
3 changes: 3 additions & 0 deletions src/common/interfaces/post-option.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PostOptions {
query?: { [key: string]: any };
}
3 changes: 3 additions & 0 deletions src/common/interfaces/put-option.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PutOptions {
query?: { [key: string]: any };
}
56 changes: 55 additions & 1 deletion src/resend.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios, { AxiosInstance } from 'axios';
import axios, { AxiosInstance, AxiosResponse } from 'axios';
import { render } from '@react-email/render';
import {
SendEmailData,
SendEmailRequest,
SendEmailResponse,
} from './interfaces';
import { version } from '../package.json';
import { GetOptions, PostOptions, PutOptions } from './common/interfaces';

export class Resend {
readonly baseUrl: string;
Expand Down Expand Up @@ -54,6 +55,59 @@ export class Resend {
);
}

async post(
path: string,
entity?: any,
options?: PostOptions,
): Promise<AxiosResponse> {
const requestHeaders: any = {};
try {
return await this.request.post(path, entity, {
params: options?.query,
headers: requestHeaders,
});
} catch (error) {
throw error;
}
}

async get(path: string, options: GetOptions = {}): Promise<AxiosResponse> {
try {
return await this.request.get(path, {
params: options.query,
});
} catch (error) {
throw error;
}
}

async put(
path: string,
entity: any,
options: PutOptions = {},
): Promise<AxiosResponse> {
const requestHeaders: any = {};

try {
return await this.request.put(path, entity, {
params: options.query,
headers: requestHeaders,
});
} catch (error) {
throw error;
}
}

async delete(path: string, query?: any): Promise<AxiosResponse> {
try {
return await this.request.delete(path, {
params: query,
});
} catch (error) {
throw error;
}
}

async sendEmail(data: SendEmailData): Promise<SendEmailResponse> {
try {
const path = `${this.baseUrl}/email`;
Expand Down