UNPKG

refire-client

Version:

Refire Email API Client

59 lines (58 loc) 2.44 kB
"use strict"; // src/index.ts var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); class Refire { constructor(apiKey, apiUrl = "https://refire.email/api") { if (!apiKey) { throw new Error('API key is required'); } this.apiKey = apiKey; this.apiUrl = apiUrl; } sendEmail(params) { return __awaiter(this, void 0, void 0, function* () { const headers = { "Content-Type": "application/json", "x-api-key": this.apiKey, }; const response = yield fetch(`${this.apiUrl}/send-email`, { method: "POST", headers, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(`Failed to send email: ${response.statusText}`); } console.log("Email sent successfully:", yield response.json()); }); } sendEmailFromTemplate(params) { return __awaiter(this, void 0, void 0, function* () { const response = yield fetch(`${this.apiUrl}/send-email-from-template`, { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": this.apiKey, }, body: JSON.stringify({ templateId: params.templateId, to: params.to, }), }); if (!response.ok) { throw new Error(`Failed to send email from template: ${response.statusText}`); } console.log("Email from template sent successfully:", yield response.json()); }); } } exports.default = Refire;