New logo, SDK with url support

This commit is contained in:
KMKoushik
2024-05-25 18:46:41 +10:00
parent d081badd3d
commit 5b5fa74f32
23 changed files with 106 additions and 195 deletions

View File

@@ -1 +1 @@
export { Unsend } from "./src";
export { Unsend } from "./src/unsend";

View File

@@ -1,6 +1,6 @@
{
"name": "unsend",
"version": "0.0.4",
"version": "0.0.5",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
@@ -8,7 +8,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint . --max-warnings 0",
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts"
"build": "rm -rf dist && tsup index.ts --format esm,cjs --dts"
},
"keywords": [],
"author": "",

View File

@@ -1,6 +1,6 @@
import { renderAsync } from "@react-email/render";
import * as React from "react";
import { Unsend } from ".";
import { Unsend } from "./unsend";
import { paths } from "../types/schema";
import { ErrorResponse } from "../types";

View File

@@ -14,8 +14,12 @@ export class Unsend {
// readonly domains = new Domains(this);
readonly emails = new Emails(this);
url = baseUrl;
constructor(readonly key?: string) {
constructor(
readonly key?: string,
url?: string
) {
if (!key) {
if (typeof process !== "undefined" && process.env) {
this.key = process.env.UNSEND_API_KEY;
@@ -28,6 +32,10 @@ export class Unsend {
}
}
if (url) {
this.url = `${url}/api/v1`;
}
this.headers = new Headers({
Authorization: `Bearer ${this.key}`,
"Content-Type": "application/json",
@@ -38,7 +46,7 @@ export class Unsend {
path: string,
options = {}
): Promise<{ data: T | null; error: ErrorResponse | null }> {
const response = await fetch(`${baseUrl}${path}`, options);
const response = await fetch(`${this.url}${path}`, options);
const defaultError = {
code: "INTERNAL_SERVER_ERROR",
message: response.statusText,