nsend-email 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.
@@ -0,0 +1,194 @@
1
+ interface NSendConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface SendEmailParams {
6
+ from: string;
7
+ to: string | string[];
8
+ subject?: string;
9
+ html?: string;
10
+ text?: string;
11
+ cc?: string | string[];
12
+ bcc?: string | string[];
13
+ reply_to?: string | string[];
14
+ template_id?: string;
15
+ variables?: Record<string, string>;
16
+ metadata?: Record<string, string>;
17
+ }
18
+ interface SendEmailResult {
19
+ id: string;
20
+ status: string;
21
+ }
22
+ interface BatchResult {
23
+ data: Array<{
24
+ id?: string;
25
+ status?: string;
26
+ error?: string;
27
+ }>;
28
+ }
29
+ interface Email {
30
+ id: string;
31
+ from: string;
32
+ to: string[];
33
+ cc: string[];
34
+ bcc: string[];
35
+ subject: string;
36
+ status: string;
37
+ created_at: string;
38
+ sent_at: string | null;
39
+ }
40
+ interface Domain {
41
+ id: string;
42
+ name: string;
43
+ status: string;
44
+ dns_records?: Array<{
45
+ type: string;
46
+ name: string;
47
+ value: string;
48
+ purpose: string;
49
+ }>;
50
+ created_at: string;
51
+ }
52
+ interface ApiKey {
53
+ id: string;
54
+ name: string;
55
+ key?: string;
56
+ key_prefix: string;
57
+ last_used_at: string | null;
58
+ created_at: string;
59
+ }
60
+ interface Template {
61
+ id: string;
62
+ name: string;
63
+ subject: string;
64
+ html?: string;
65
+ text?: string;
66
+ variables: string[];
67
+ created_at: string;
68
+ updated_at: string;
69
+ }
70
+ interface InboundEmail {
71
+ id: string;
72
+ from: string;
73
+ to: string[];
74
+ cc: string[];
75
+ subject: string;
76
+ html: string | null;
77
+ text: string | null;
78
+ thread_id: string | null;
79
+ message_id: string | null;
80
+ headers: Record<string, string>;
81
+ received_at: string;
82
+ }
83
+ interface Thread {
84
+ id: string;
85
+ subject: string;
86
+ message_count: {
87
+ inbound: number;
88
+ outbound: number;
89
+ };
90
+ last_message_at: string;
91
+ created_at: string;
92
+ messages?: Array<{
93
+ id: string;
94
+ direction: "inbound" | "outbound";
95
+ from: string;
96
+ to: string[];
97
+ subject: string;
98
+ html: string | null;
99
+ text: string | null;
100
+ status?: string;
101
+ timestamp: string;
102
+ }>;
103
+ }
104
+ declare class ApiClient {
105
+ private baseUrl;
106
+ private apiKey;
107
+ constructor(baseUrl: string, apiKey: string);
108
+ request<T>(path: string, options?: RequestInit): Promise<T>;
109
+ }
110
+ declare class EmailsResource {
111
+ private client;
112
+ constructor(client: ApiClient);
113
+ send(params: SendEmailParams): Promise<SendEmailResult>;
114
+ batch(params: SendEmailParams[]): Promise<BatchResult>;
115
+ get(id: string): Promise<Email>;
116
+ }
117
+ declare class DomainsResource {
118
+ private client;
119
+ constructor(client: ApiClient);
120
+ create(name: string): Promise<Domain>;
121
+ list(): Promise<Domain[]>;
122
+ get(id: string): Promise<Domain>;
123
+ verify(id: string): Promise<Domain>;
124
+ delete(id: string): Promise<{
125
+ deleted: boolean;
126
+ }>;
127
+ }
128
+ declare class ApiKeysResource {
129
+ private client;
130
+ constructor(client: ApiClient);
131
+ create(name: string): Promise<ApiKey>;
132
+ list(): Promise<ApiKey[]>;
133
+ revoke(id: string): Promise<{
134
+ deleted: boolean;
135
+ }>;
136
+ }
137
+ declare class TemplatesResource {
138
+ private client;
139
+ constructor(client: ApiClient);
140
+ create(params: {
141
+ name: string;
142
+ subject: string;
143
+ html: string;
144
+ text?: string;
145
+ }): Promise<Template>;
146
+ list(): Promise<Template[]>;
147
+ get(id: string): Promise<Template>;
148
+ update(id: string, params: Partial<{
149
+ name: string;
150
+ subject: string;
151
+ html: string;
152
+ text: string;
153
+ }>): Promise<Template>;
154
+ delete(id: string): Promise<{
155
+ deleted: boolean;
156
+ }>;
157
+ }
158
+ declare class InboxResource {
159
+ private client;
160
+ constructor(client: ApiClient);
161
+ list(params?: {
162
+ limit?: number;
163
+ offset?: number;
164
+ }): Promise<InboundEmail[]>;
165
+ get(id: string): Promise<InboundEmail>;
166
+ }
167
+ declare class ThreadsResource {
168
+ private client;
169
+ constructor(client: ApiClient);
170
+ list(params?: {
171
+ limit?: number;
172
+ offset?: number;
173
+ }): Promise<Thread[]>;
174
+ get(id: string): Promise<Thread>;
175
+ reply(threadId: string, params: {
176
+ from: string;
177
+ html?: string;
178
+ text?: string;
179
+ cc?: string | string[];
180
+ }): Promise<SendEmailResult & {
181
+ thread_id: string;
182
+ }>;
183
+ }
184
+ declare class NSend {
185
+ readonly emails: EmailsResource;
186
+ readonly domains: DomainsResource;
187
+ readonly apiKeys: ApiKeysResource;
188
+ readonly templates: TemplatesResource;
189
+ readonly inbox: InboxResource;
190
+ readonly threads: ThreadsResource;
191
+ constructor(config: NSendConfig);
192
+ }
193
+
194
+ export { type ApiKey, type BatchResult, type Domain, type Email, type InboundEmail, NSend, type NSendConfig, type SendEmailParams, type SendEmailResult, type Template, type Thread, NSend as default };
package/dist/index.js ADDED
@@ -0,0 +1,191 @@
1
+ // src/index.ts
2
+ var NSendError = class extends Error {
3
+ constructor(message, status, body) {
4
+ super(message);
5
+ this.status = status;
6
+ this.body = body;
7
+ this.name = "NSendError";
8
+ }
9
+ status;
10
+ body;
11
+ };
12
+ var ApiClient = class {
13
+ constructor(baseUrl, apiKey) {
14
+ this.baseUrl = baseUrl;
15
+ this.apiKey = apiKey;
16
+ }
17
+ baseUrl;
18
+ apiKey;
19
+ async request(path, options = {}) {
20
+ const res = await fetch(`${this.baseUrl}${path}`, {
21
+ ...options,
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: `Bearer ${this.apiKey}`,
25
+ ...options.headers
26
+ }
27
+ });
28
+ const body = await res.json();
29
+ if (!res.ok) {
30
+ throw new NSendError(
31
+ body.error || `API error ${res.status}`,
32
+ res.status,
33
+ body
34
+ );
35
+ }
36
+ return body;
37
+ }
38
+ };
39
+ var EmailsResource = class {
40
+ constructor(client) {
41
+ this.client = client;
42
+ }
43
+ client;
44
+ async send(params) {
45
+ return this.client.request("/emails", {
46
+ method: "POST",
47
+ body: JSON.stringify(params)
48
+ });
49
+ }
50
+ async batch(params) {
51
+ return this.client.request("/emails/batch", {
52
+ method: "POST",
53
+ body: JSON.stringify(params)
54
+ });
55
+ }
56
+ async get(id) {
57
+ return this.client.request(`/emails/${id}`);
58
+ }
59
+ };
60
+ var DomainsResource = class {
61
+ constructor(client) {
62
+ this.client = client;
63
+ }
64
+ client;
65
+ async create(name) {
66
+ return this.client.request("/domains", {
67
+ method: "POST",
68
+ body: JSON.stringify({ name })
69
+ });
70
+ }
71
+ async list() {
72
+ return this.client.request("/domains");
73
+ }
74
+ async get(id) {
75
+ return this.client.request(`/domains/${id}`);
76
+ }
77
+ async verify(id) {
78
+ return this.client.request(`/domains/${id}/verify`, { method: "POST" });
79
+ }
80
+ async delete(id) {
81
+ return this.client.request(`/domains/${id}`, { method: "DELETE" });
82
+ }
83
+ };
84
+ var ApiKeysResource = class {
85
+ constructor(client) {
86
+ this.client = client;
87
+ }
88
+ client;
89
+ async create(name) {
90
+ return this.client.request("/api-keys", {
91
+ method: "POST",
92
+ body: JSON.stringify({ name })
93
+ });
94
+ }
95
+ async list() {
96
+ return this.client.request("/api-keys");
97
+ }
98
+ async revoke(id) {
99
+ return this.client.request(`/api-keys/${id}`, { method: "DELETE" });
100
+ }
101
+ };
102
+ var TemplatesResource = class {
103
+ constructor(client) {
104
+ this.client = client;
105
+ }
106
+ client;
107
+ async create(params) {
108
+ return this.client.request("/templates", {
109
+ method: "POST",
110
+ body: JSON.stringify(params)
111
+ });
112
+ }
113
+ async list() {
114
+ return this.client.request("/templates");
115
+ }
116
+ async get(id) {
117
+ return this.client.request(`/templates/${id}`);
118
+ }
119
+ async update(id, params) {
120
+ return this.client.request(`/templates/${id}`, {
121
+ method: "PATCH",
122
+ body: JSON.stringify(params)
123
+ });
124
+ }
125
+ async delete(id) {
126
+ return this.client.request(`/templates/${id}`, { method: "DELETE" });
127
+ }
128
+ };
129
+ var InboxResource = class {
130
+ constructor(client) {
131
+ this.client = client;
132
+ }
133
+ client;
134
+ async list(params) {
135
+ const query = new URLSearchParams();
136
+ if (params?.limit) query.set("limit", String(params.limit));
137
+ if (params?.offset) query.set("offset", String(params.offset));
138
+ const qs = query.toString();
139
+ return this.client.request(`/inbox${qs ? `?${qs}` : ""}`);
140
+ }
141
+ async get(id) {
142
+ return this.client.request(`/inbox/${id}`);
143
+ }
144
+ };
145
+ var ThreadsResource = class {
146
+ constructor(client) {
147
+ this.client = client;
148
+ }
149
+ client;
150
+ async list(params) {
151
+ const query = new URLSearchParams();
152
+ if (params?.limit) query.set("limit", String(params.limit));
153
+ if (params?.offset) query.set("offset", String(params.offset));
154
+ const qs = query.toString();
155
+ return this.client.request(`/threads${qs ? `?${qs}` : ""}`);
156
+ }
157
+ async get(id) {
158
+ return this.client.request(`/threads/${id}`);
159
+ }
160
+ async reply(threadId, params) {
161
+ return this.client.request(`/threads/${threadId}/reply`, {
162
+ method: "POST",
163
+ body: JSON.stringify(params)
164
+ });
165
+ }
166
+ };
167
+ var NSend = class {
168
+ emails;
169
+ domains;
170
+ apiKeys;
171
+ templates;
172
+ inbox;
173
+ threads;
174
+ constructor(config) {
175
+ const client = new ApiClient(
176
+ config.baseUrl || "http://localhost:3000",
177
+ config.apiKey
178
+ );
179
+ this.emails = new EmailsResource(client);
180
+ this.domains = new DomainsResource(client);
181
+ this.apiKeys = new ApiKeysResource(client);
182
+ this.templates = new TemplatesResource(client);
183
+ this.inbox = new InboxResource(client);
184
+ this.threads = new ThreadsResource(client);
185
+ }
186
+ };
187
+ var index_default = NSend;
188
+ export {
189
+ NSend,
190
+ index_default as default
191
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "nsend-email",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for NSend — email API for developers and agents",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "tsup": "^8.3.0",
19
+ "typescript": "^5.7.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format esm --dts",
23
+ "dev": "tsup src/index.ts --format esm --dts --watch"
24
+ }
25
+ }