mailpush 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # Mailpush
2
+
3
+ Official JavaScript/TypeScript SDK for [Mailpush](https://mailpush.app).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install mailpush
9
+ # or
10
+ bun add mailpush
11
+ # or
12
+ yarn add mailpush
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { Mailpush } from "mailpush";
19
+
20
+ const mailpush = new Mailpush("mp_live_xxx");
21
+
22
+ await mailpush.emails.send({
23
+ from: "hello@yourdomain.com",
24
+ to: "user@example.com",
25
+ subject: "Hello from Mailpush",
26
+ html: "<h1>Welcome!</h1><p>Your account is ready.</p>",
27
+ });
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Send an email
33
+
34
+ ```typescript
35
+ const { id, messageId } = await mailpush.emails.send({
36
+ from: "hello@yourdomain.com",
37
+ to: "user@example.com",
38
+ subject: "Welcome!",
39
+ html: "<h1>Hello</h1>",
40
+ text: "Hello",
41
+ });
42
+ ```
43
+
44
+ ### Send to multiple recipients
45
+
46
+ ```typescript
47
+ await mailpush.emails.send({
48
+ from: "hello@yourdomain.com",
49
+ to: ["user1@example.com", "user2@example.com"],
50
+ cc: "cc@example.com",
51
+ bcc: ["bcc1@example.com", "bcc2@example.com"],
52
+ subject: "Team Update",
53
+ html: "<p>Important update for the team.</p>",
54
+ });
55
+ ```
56
+
57
+ ### Send with a template
58
+
59
+ ```typescript
60
+ await mailpush.emails.send({
61
+ from: "hello@yourdomain.com",
62
+ to: "user@example.com",
63
+ templateId: "your-template-id",
64
+ variables: {
65
+ name: "John",
66
+ company: "Acme Inc",
67
+ },
68
+ });
69
+ ```
70
+
71
+ ### Send with attachments
72
+
73
+ ```typescript
74
+ import { readFileSync } from "fs";
75
+
76
+ await mailpush.emails.send({
77
+ from: "hello@yourdomain.com",
78
+ to: "user@example.com",
79
+ subject: "Your invoice",
80
+ html: "<p>Please find your invoice attached.</p>",
81
+ attachments: [
82
+ {
83
+ filename: "invoice.pdf",
84
+ content: readFileSync("invoice.pdf").toString("base64"),
85
+ contentType: "application/pdf",
86
+ },
87
+ ],
88
+ });
89
+ ```
90
+
91
+ ## Configuration
92
+
93
+ ```typescript
94
+ const mailpush = new Mailpush("mp_live_xxx", {
95
+ baseUrl: "https://api.mailpush.app", // default
96
+ });
97
+ ```
98
+
99
+ ## Error Handling
100
+
101
+ ```typescript
102
+ import {
103
+ Mailpush,
104
+ MailpushError,
105
+ AuthenticationError,
106
+ ValidationError,
107
+ RateLimitError,
108
+ } from "mailpush";
109
+
110
+ try {
111
+ await mailpush.emails.send({ ... });
112
+ } catch (error) {
113
+ if (error instanceof AuthenticationError) {
114
+ console.error("Invalid API key");
115
+ } else if (error instanceof ValidationError) {
116
+ console.error("Invalid request:", error.details);
117
+ } else if (error instanceof RateLimitError) {
118
+ console.error(`Rate limited. Retry after ${error.retryAfter}s`);
119
+ } else if (error instanceof MailpushError) {
120
+ console.error(`Error: ${error.message} (${error.code})`);
121
+ }
122
+ }
123
+ ```
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,58 @@
1
+ interface SendEmailRequest {
2
+ from: string;
3
+ to: string | string[];
4
+ cc?: string | string[];
5
+ bcc?: string | string[];
6
+ replyTo?: string;
7
+ subject?: string;
8
+ html?: string;
9
+ text?: string;
10
+ templateId?: string;
11
+ variables?: Record<string, string>;
12
+ attachments?: Attachment[];
13
+ }
14
+ interface Attachment {
15
+ filename: string;
16
+ content: string;
17
+ contentType: string;
18
+ }
19
+ interface SendEmailResponse {
20
+ id: string;
21
+ messageId: string;
22
+ status: "sent";
23
+ }
24
+
25
+ declare class Emails {
26
+ private request;
27
+ constructor(request: (path: string, options: RequestInit) => Promise<Response>);
28
+ send(data: SendEmailRequest): Promise<SendEmailResponse>;
29
+ }
30
+
31
+ interface MailpushConfig {
32
+ baseUrl?: string;
33
+ }
34
+ declare class Mailpush {
35
+ private apiKey;
36
+ private baseUrl;
37
+ readonly emails: Emails;
38
+ constructor(apiKey: string, config?: MailpushConfig);
39
+ private request;
40
+ }
41
+
42
+ declare class MailpushError extends Error {
43
+ code: string;
44
+ details?: unknown;
45
+ constructor(message: string, code: string, details?: unknown);
46
+ }
47
+ declare class AuthenticationError extends MailpushError {
48
+ constructor(message: string, code: string);
49
+ }
50
+ declare class ValidationError extends MailpushError {
51
+ constructor(message: string, code: string, details?: unknown);
52
+ }
53
+ declare class RateLimitError extends MailpushError {
54
+ retryAfter?: number;
55
+ constructor(message: string, retryAfter?: number);
56
+ }
57
+
58
+ export { type Attachment, AuthenticationError, Mailpush, type MailpushConfig, MailpushError, RateLimitError, type SendEmailRequest, type SendEmailResponse, ValidationError };
@@ -0,0 +1,58 @@
1
+ interface SendEmailRequest {
2
+ from: string;
3
+ to: string | string[];
4
+ cc?: string | string[];
5
+ bcc?: string | string[];
6
+ replyTo?: string;
7
+ subject?: string;
8
+ html?: string;
9
+ text?: string;
10
+ templateId?: string;
11
+ variables?: Record<string, string>;
12
+ attachments?: Attachment[];
13
+ }
14
+ interface Attachment {
15
+ filename: string;
16
+ content: string;
17
+ contentType: string;
18
+ }
19
+ interface SendEmailResponse {
20
+ id: string;
21
+ messageId: string;
22
+ status: "sent";
23
+ }
24
+
25
+ declare class Emails {
26
+ private request;
27
+ constructor(request: (path: string, options: RequestInit) => Promise<Response>);
28
+ send(data: SendEmailRequest): Promise<SendEmailResponse>;
29
+ }
30
+
31
+ interface MailpushConfig {
32
+ baseUrl?: string;
33
+ }
34
+ declare class Mailpush {
35
+ private apiKey;
36
+ private baseUrl;
37
+ readonly emails: Emails;
38
+ constructor(apiKey: string, config?: MailpushConfig);
39
+ private request;
40
+ }
41
+
42
+ declare class MailpushError extends Error {
43
+ code: string;
44
+ details?: unknown;
45
+ constructor(message: string, code: string, details?: unknown);
46
+ }
47
+ declare class AuthenticationError extends MailpushError {
48
+ constructor(message: string, code: string);
49
+ }
50
+ declare class ValidationError extends MailpushError {
51
+ constructor(message: string, code: string, details?: unknown);
52
+ }
53
+ declare class RateLimitError extends MailpushError {
54
+ retryAfter?: number;
55
+ constructor(message: string, retryAfter?: number);
56
+ }
57
+
58
+ export { type Attachment, AuthenticationError, Mailpush, type MailpushConfig, MailpushError, RateLimitError, type SendEmailRequest, type SendEmailResponse, ValidationError };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var w=(r,t)=>{for(var e in t)d(r,e,{get:t[e],enumerable:!0})},y=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of E(t))!R.call(r,n)&&n!==e&&d(r,n,{get:()=>t[n],enumerable:!(s=f(t,n))||s.enumerable});return r};var g=r=>y(d({},"__esModule",{value:!0}),r);var A={};w(A,{AuthenticationError:()=>o,Mailpush:()=>l,MailpushError:()=>i,RateLimitError:()=>p,ValidationError:()=>a});module.exports=g(A);var h=class{constructor(t){this.request=t}async send(t){return(await this.request("/v1/send",{method:"POST",body:JSON.stringify(t)})).json()}};var i=class extends Error{constructor(t,e,s){super(t),this.name="MailpushError",this.code=e,this.details=s}},o=class extends i{constructor(t,e){super(t,e),this.name="AuthenticationError"}},a=class extends i{constructor(t,e,s){super(t,e,s),this.name="ValidationError"}},p=class extends i{constructor(t,e){super(t,"RATE_LIMITED"),this.name="RateLimitError",this.retryAfter=e}};var l=class{constructor(t,e={}){if(!t)throw new Error("API key is required");if(!t.startsWith("mp_"))throw new Error("Invalid API key format");this.apiKey=t,this.baseUrl=e.baseUrl??"https://api.mailpush.app",this.emails=new h(this.request.bind(this))}async request(t,e){let s=await fetch(`${this.baseUrl}${t}`,{...e,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,...e.headers}});if(!s.ok){let n=await s.json().catch(()=>({})),{error:u,code:c,details:m}=n;throw s.status===401?new o(u||"Invalid API key",c||"INVALID_API_KEY"):s.status===429?new p(u||"Rate limited",m?.retryAfter):s.status===400?new a(u||"Validation error",c||"VALIDATION_ERROR",m):new i(u||"Request failed",c||"UNKNOWN_ERROR",m)}return s}};0&&(module.exports={AuthenticationError,Mailpush,MailpushError,RateLimitError,ValidationError});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var u=class{constructor(t){this.request=t}async send(t){return(await this.request("/v1/send",{method:"POST",body:JSON.stringify(t)})).json()}};var s=class extends Error{constructor(t,e,r){super(t),this.name="MailpushError",this.code=e,this.details=r}},n=class extends s{constructor(t,e){super(t,e),this.name="AuthenticationError"}},o=class extends s{constructor(t,e,r){super(t,e,r),this.name="ValidationError"}},a=class extends s{constructor(t,e){super(t,"RATE_LIMITED"),this.name="RateLimitError",this.retryAfter=e}};var c=class{constructor(t,e={}){if(!t)throw new Error("API key is required");if(!t.startsWith("mp_"))throw new Error("Invalid API key format");this.apiKey=t,this.baseUrl=e.baseUrl??"https://api.mailpush.app",this.emails=new u(this.request.bind(this))}async request(t,e){let r=await fetch(`${this.baseUrl}${t}`,{...e,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,...e.headers}});if(!r.ok){let m=await r.json().catch(()=>({})),{error:p,code:h,details:l}=m;throw r.status===401?new n(p||"Invalid API key",h||"INVALID_API_KEY"):r.status===429?new a(p||"Rate limited",l?.retryAfter):r.status===400?new o(p||"Validation error",h||"VALIDATION_ERROR",l):new s(p||"Request failed",h||"UNKNOWN_ERROR",l)}return r}};export{n as AuthenticationError,c as Mailpush,s as MailpushError,a as RateLimitError,o as ValidationError};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "mailpush",
3
+ "version": "0.1.0",
4
+ "description": "Official Mailpush SDK for JavaScript/TypeScript",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": ["dist"],
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "dev": "tsup --watch",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "keywords": ["email", "mailpush", "smtp", "transactional"],
22
+ "author": "Mailpush",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/mailpush/mailpush"
27
+ },
28
+ "homepage": "https://mailpush.app",
29
+ "devDependencies": {
30
+ "tsup": "^8.0.0",
31
+ "typescript": "^5.0.0"
32
+ }
33
+ }