mailmark 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,67 @@
1
+ # mailmark
2
+
3
+ Official Node.js SDK for the [DevMail](https://mailmark.io) transactional email API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add mailmark
9
+ # or
10
+ npm install mailmark
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { Devmail } from 'mailmark';
17
+
18
+ const client = new Devmail('dm_live_your_api_key');
19
+
20
+ await client.send({
21
+ from: 'hello@yourdomain.com',
22
+ to: ['recipient@example.com'],
23
+ subject: 'Hello from DevMail',
24
+ html: '<h1>Hello!</h1><p>This email was sent via the DevMail API.</p>',
25
+ });
26
+ ```
27
+
28
+ ## API
29
+
30
+ ### `new Devmail(apiKey, options?)`
31
+
32
+ | Parameter | Type | Description |
33
+ |-----------|------|-------------|
34
+ | `apiKey` | `string` | Your API key from the DevMail Developer dashboard |
35
+ | `options.baseUrl` | `string` | Override the API base URL (for self-hosted) |
36
+
37
+ ### `client.send(options)`
38
+
39
+ | Field | Type | Required | Description |
40
+ |-------|------|----------|-------------|
41
+ | `from` | `string` | Yes | Sender address — must belong to the API key's domain |
42
+ | `to` | `string \| string[]` | Yes | Recipient address(es) |
43
+ | `subject` | `string` | Yes | Email subject |
44
+ | `html` | `string` | One of | HTML email body |
45
+ | `text` | `string` | One of | Plain-text body (used if html is omitted) |
46
+
47
+ Returns `Promise<{ messageId: string; status: "queued" }>`.
48
+
49
+ Throws `DevmailError` on API errors, with `.status` (HTTP status) and `.response` (parsed body).
50
+
51
+ ## cURL Equivalent
52
+
53
+ ```bash
54
+ curl -X POST https://harmless-armadillo-386.convex.site/v1/send \
55
+ -H "Authorization: Bearer dm_live_your_api_key" \
56
+ -H "Content-Type: application/json" \
57
+ -d '{
58
+ "from": "hello@yourdomain.com",
59
+ "to": ["recipient@example.com"],
60
+ "subject": "Hello",
61
+ "html": "<p>Hello!</p>"
62
+ }'
63
+ ```
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,33 @@
1
+ export interface SendEmailOptions {
2
+ /** Sender address — must be a mailbox on the API key's scoped domain. */
3
+ from: string;
4
+ /** One or more recipient addresses. */
5
+ to: string | string[];
6
+ /** Email subject line. */
7
+ subject: string;
8
+ /** HTML body. Either html or text (or both) is required. */
9
+ html?: string;
10
+ /** Plain-text body. Used if html is not provided. */
11
+ text?: string;
12
+ }
13
+ export interface SendEmailResult {
14
+ messageId: string;
15
+ status: "queued";
16
+ }
17
+ export interface DevmailOptions {
18
+ /** Override the default API base URL. Useful for self-hosted instances. */
19
+ baseUrl?: string;
20
+ }
21
+ export declare class DevmailError extends Error {
22
+ readonly status: number;
23
+ readonly response: unknown;
24
+ constructor(message: string, status: number, response: unknown);
25
+ }
26
+ export declare class Devmail {
27
+ private readonly apiKey;
28
+ private readonly baseUrl;
29
+ constructor(apiKey: string, options?: DevmailOptions);
30
+ send(options: SendEmailOptions): Promise<SendEmailResult>;
31
+ }
32
+ export default Devmail;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAa,SAAQ,KAAK;aAGnB,MAAM,EAAE,MAAM;aACd,QAAQ,EAAE,OAAO;gBAFjC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO;CAKpC;AAID,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAMlD,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CAqChE;AAED,eAAe,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/index.ts
30
+ var exports_src = {};
31
+ __export(exports_src, {
32
+ default: () => src_default,
33
+ DevmailError: () => DevmailError,
34
+ Devmail: () => Devmail
35
+ });
36
+ module.exports = __toCommonJS(exports_src);
37
+
38
+ class DevmailError extends Error {
39
+ status;
40
+ response;
41
+ constructor(message, status, response) {
42
+ super(message);
43
+ this.status = status;
44
+ this.response = response;
45
+ this.name = "DevmailError";
46
+ }
47
+ }
48
+ var DEFAULT_BASE_URL = "https://harmless-armadillo-386.convex.site";
49
+
50
+ class Devmail {
51
+ apiKey;
52
+ baseUrl;
53
+ constructor(apiKey, options = {}) {
54
+ if (!apiKey)
55
+ throw new Error("DevMail API key is required");
56
+ this.apiKey = apiKey;
57
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
58
+ }
59
+ async send(options) {
60
+ const { from, to, subject, html, text } = options;
61
+ if (!from)
62
+ throw new Error('"from" is required');
63
+ if (!to || Array.isArray(to) && to.length === 0)
64
+ throw new Error('"to" is required');
65
+ if (!subject)
66
+ throw new Error('"subject" is required');
67
+ if (!html && !text)
68
+ throw new Error('Either "html" or "text" is required');
69
+ const body = {
70
+ from,
71
+ to: Array.isArray(to) ? to : [to],
72
+ subject,
73
+ ...html ? { html } : {},
74
+ ...text ? { text } : {}
75
+ };
76
+ const res = await fetch(`${this.baseUrl}/v1/send`, {
77
+ method: "POST",
78
+ headers: {
79
+ Authorization: `Bearer ${this.apiKey}`,
80
+ "Content-Type": "application/json"
81
+ },
82
+ body: JSON.stringify(body)
83
+ });
84
+ const data = await res.json();
85
+ if (!res.ok) {
86
+ throw new DevmailError(data.error ?? `Request failed with status ${res.status}`, res.status, data);
87
+ }
88
+ return data;
89
+ }
90
+ }
91
+ var src_default = Devmail;
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
1
+ // src/index.ts
2
+ class DevmailError extends Error {
3
+ status;
4
+ response;
5
+ constructor(message, status, response) {
6
+ super(message);
7
+ this.status = status;
8
+ this.response = response;
9
+ this.name = "DevmailError";
10
+ }
11
+ }
12
+ var DEFAULT_BASE_URL = "https://harmless-armadillo-386.convex.site";
13
+
14
+ class Devmail {
15
+ apiKey;
16
+ baseUrl;
17
+ constructor(apiKey, options = {}) {
18
+ if (!apiKey)
19
+ throw new Error("DevMail API key is required");
20
+ this.apiKey = apiKey;
21
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
22
+ }
23
+ async send(options) {
24
+ const { from, to, subject, html, text } = options;
25
+ if (!from)
26
+ throw new Error('"from" is required');
27
+ if (!to || Array.isArray(to) && to.length === 0)
28
+ throw new Error('"to" is required');
29
+ if (!subject)
30
+ throw new Error('"subject" is required');
31
+ if (!html && !text)
32
+ throw new Error('Either "html" or "text" is required');
33
+ const body = {
34
+ from,
35
+ to: Array.isArray(to) ? to : [to],
36
+ subject,
37
+ ...html ? { html } : {},
38
+ ...text ? { text } : {}
39
+ };
40
+ const res = await fetch(`${this.baseUrl}/v1/send`, {
41
+ method: "POST",
42
+ headers: {
43
+ Authorization: `Bearer ${this.apiKey}`,
44
+ "Content-Type": "application/json"
45
+ },
46
+ body: JSON.stringify(body)
47
+ });
48
+ const data = await res.json();
49
+ if (!res.ok) {
50
+ throw new DevmailError(data.error ?? `Request failed with status ${res.status}`, res.status, data);
51
+ }
52
+ return data;
53
+ }
54
+ }
55
+ var src_default = Devmail;
56
+ export {
57
+ src_default as default,
58
+ DevmailError,
59
+ Devmail
60
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "mailmark",
3
+ "version": "0.1.0",
4
+ "description": "Official Node.js SDK for the DevMail transactional email API",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "bun run build.ts",
17
+ "dev": "bun --watch run build.ts",
18
+ "prepublishOnly": "bun run build"
19
+ },
20
+ "keywords": ["email", "transactional", "devmail", "sdk"],
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "typescript": "^5.0.0"
24
+ }
25
+ }