diff --git a/src/common/interfaces/get-option.interface.ts b/src/common/interfaces/get-option.interface.ts new file mode 100644 index 00000000..627e7241 --- /dev/null +++ b/src/common/interfaces/get-option.interface.ts @@ -0,0 +1,3 @@ +export interface GetOptions { + query?: Record; +} diff --git a/src/common/interfaces/index.ts b/src/common/interfaces/index.ts new file mode 100644 index 00000000..7da31d53 --- /dev/null +++ b/src/common/interfaces/index.ts @@ -0,0 +1,4 @@ +export * from './get-option.interface'; +export * from './list-option.interface'; +export * from './post-option.interface'; +export * from './put-option.interface'; diff --git a/src/common/interfaces/list-option.interface.ts b/src/common/interfaces/list-option.interface.ts new file mode 100644 index 00000000..e6756664 --- /dev/null +++ b/src/common/interfaces/list-option.interface.ts @@ -0,0 +1,4 @@ +export interface List { + readonly object: 'list'; + data: T[]; +} diff --git a/src/common/interfaces/post-option.interface.ts b/src/common/interfaces/post-option.interface.ts new file mode 100644 index 00000000..89a1ed08 --- /dev/null +++ b/src/common/interfaces/post-option.interface.ts @@ -0,0 +1,3 @@ +export interface PostOptions { + query?: { [key: string]: any }; +} diff --git a/src/common/interfaces/put-option.interface.ts b/src/common/interfaces/put-option.interface.ts new file mode 100644 index 00000000..866ebce3 --- /dev/null +++ b/src/common/interfaces/put-option.interface.ts @@ -0,0 +1,3 @@ +export interface PutOptions { + query?: { [key: string]: any }; +} diff --git a/src/resend.ts b/src/resend.ts index e514515b..3060f921 100644 --- a/src/resend.ts +++ b/src/resend.ts @@ -1,4 +1,4 @@ -import axios, { AxiosInstance } from 'axios'; +import axios, { AxiosInstance, AxiosResponse } from 'axios'; import { render } from '@react-email/render'; import { SendEmailData, @@ -6,6 +6,7 @@ import { SendEmailResponse, } from './interfaces'; import { version } from '../package.json'; +import { GetOptions, PostOptions, PutOptions } from './common/interfaces'; export class Resend { readonly baseUrl: string; @@ -54,6 +55,59 @@ export class Resend { ); } + async post( + path: string, + entity?: any, + options?: PostOptions, + ): Promise { + 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 { + try { + return await this.request.get(path, { + params: options.query, + }); + } catch (error) { + throw error; + } + } + + async put( + path: string, + entity: any, + options: PutOptions = {}, + ): Promise { + 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 { + try { + return await this.request.delete(path, { + params: query, + }); + } catch (error) { + throw error; + } + } + async sendEmail(data: SendEmailData): Promise { try { const path = `${this.baseUrl}/email`;