New logo, SDK with url support
This commit is contained in:
@@ -1 +1 @@
|
||||
export { Unsend } from "./src";
|
||||
export { Unsend } from "./src/unsend";
|
||||
|
@@ -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": "",
|
||||
|
@@ -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";
|
||||
|
||||
|
@@ -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,
|
Reference in New Issue
Block a user