@vinworld/vinmail 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +83 -2
- package/dist/cjs/attachments.js +151 -0
- package/dist/cjs/attachments.js.map +1 -0
- package/dist/cjs/client.js +175 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.js +21 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/attachments.d.ts +16 -0
- package/dist/esm/attachments.d.ts.map +1 -0
- package/dist/esm/attachments.js +114 -0
- package/dist/esm/attachments.js.map +1 -0
- package/dist/esm/client.d.ts +30 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +170 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +10 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +17 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +84 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +53 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vinworld
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vinworld/vinmail
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official zero-dependency **Node.js & TypeScript SDK** for the [VinMail](https://vinmail.vinworlddev.com) transactional email API.
|
|
4
|
+
|
|
5
|
+
Works out of the box in **Node.js 18+**, **Next.js**, **NestJS**, **Express**, **Bun**, **Deno**, and **Cloudflare Workers**.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @vinworld/vinmail
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { VinMail, VinMailError } from '@vinworld/vinmail';
|
|
17
|
+
|
|
18
|
+
const vinmail = new VinMail(process.env.VINMAIL_API_KEY!);
|
|
19
|
+
|
|
20
|
+
const { id, status } = await vinmail.emails.send({
|
|
21
|
+
from: 'YourApp <no-reply@yourdomain.com>',
|
|
22
|
+
replyTo: 'contact@yourdomain.com',
|
|
23
|
+
to: 'customer@example.com',
|
|
24
|
+
subject: 'Your verification code',
|
|
25
|
+
html: '<p>Your code is <strong>482913</strong>.</p>',
|
|
26
|
+
text: 'Your code is 482913.',
|
|
27
|
+
idempotencyKey: 'otp-customer-482913',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log({ id, status }); // { id: '...', status: 'queued' }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Using Templates
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
await vinmail.emails.send({
|
|
37
|
+
to: 'customer@example.com',
|
|
38
|
+
template: 'otp', // built-in global templates: "otp", "notification", "notification-action"
|
|
39
|
+
variables: {
|
|
40
|
+
appName: 'YourApp',
|
|
41
|
+
code: '482913',
|
|
42
|
+
minutes: 10,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Business File Attachments
|
|
48
|
+
|
|
49
|
+
Pass either a local `path` (Node.js reads & base64-encodes automatically), a `Buffer`/`Uint8Array`, or a base64 string:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
await vinmail.emails.send({
|
|
53
|
+
from: 'Billing <billing@yourdomain.com>',
|
|
54
|
+
to: 'customer@example.com',
|
|
55
|
+
subject: 'Invoice #1042',
|
|
56
|
+
text: 'Please see your attached invoice.',
|
|
57
|
+
attachments: [
|
|
58
|
+
{ path: './invoices/invoice-1042.pdf' },
|
|
59
|
+
{ filename: 'receipt.png', content: receiptBuffer },
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Allowed business formats:** `PDF`, `DOC/DOCX`, `XLS/XLSX`, `CSV`, `PPT/PPTX`, `TXT`, `RTF`, `PNG`, `JPG/JPEG`, `WEBP`, `GIF`.
|
|
65
|
+
**Limits:** up to **5 files**, **5 MB** per file, **7.5 MB** combined per email.
|
|
66
|
+
|
|
67
|
+
## Check Delivery Status
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const email = await vinmail.emails.get('em_...');
|
|
71
|
+
console.log(email.status, email.events);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Error Handling
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
try {
|
|
78
|
+
await vinmail.emails.send({ /* ... */ });
|
|
79
|
+
} catch (err) {
|
|
80
|
+
if (err instanceof VinMailError) {
|
|
81
|
+
console.error(err.status, err.code, err.message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ALLOWED_BUSINESS_EXTENSIONS = exports.MAX_TOTAL_ATTACHMENTS_BYTES = exports.MAX_SINGLE_ATTACHMENT_BYTES = exports.MAX_ATTACHMENTS_PER_EMAIL = void 0;
|
|
37
|
+
exports.prepareAttachments = prepareAttachments;
|
|
38
|
+
const errors_js_1 = require("./errors.js");
|
|
39
|
+
exports.MAX_ATTACHMENTS_PER_EMAIL = 5;
|
|
40
|
+
exports.MAX_SINGLE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
41
|
+
exports.MAX_TOTAL_ATTACHMENTS_BYTES = Math.floor(7.5 * 1024 * 1024);
|
|
42
|
+
exports.ALLOWED_BUSINESS_EXTENSIONS = {
|
|
43
|
+
'.pdf': 'application/pdf',
|
|
44
|
+
'.doc': 'application/msword',
|
|
45
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
46
|
+
'.xls': 'application/vnd.ms-excel',
|
|
47
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
48
|
+
'.csv': 'text/csv',
|
|
49
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
50
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
51
|
+
'.txt': 'text/plain',
|
|
52
|
+
'.rtf': 'application/rtf',
|
|
53
|
+
'.png': 'image/png',
|
|
54
|
+
'.jpg': 'image/jpeg',
|
|
55
|
+
'.jpeg': 'image/jpeg',
|
|
56
|
+
'.webp': 'image/webp',
|
|
57
|
+
'.gif': 'image/gif',
|
|
58
|
+
};
|
|
59
|
+
function getExtension(filename) {
|
|
60
|
+
const idx = filename.lastIndexOf('.');
|
|
61
|
+
if (idx <= 0 || idx === filename.length - 1)
|
|
62
|
+
return '';
|
|
63
|
+
return filename.slice(idx).toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
function basenameOf(filePath) {
|
|
66
|
+
const cleaned = filePath.replace(/\\/g, '/');
|
|
67
|
+
const parts = cleaned.split('/');
|
|
68
|
+
return parts[parts.length - 1] ?? 'attachment';
|
|
69
|
+
}
|
|
70
|
+
function uint8ArrayToBase64(bytes) {
|
|
71
|
+
if (typeof Buffer !== 'undefined') {
|
|
72
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
|
|
73
|
+
}
|
|
74
|
+
let binary = '';
|
|
75
|
+
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
76
|
+
binary += String.fromCharCode(bytes[i]);
|
|
77
|
+
}
|
|
78
|
+
return btoa(binary);
|
|
79
|
+
}
|
|
80
|
+
function decodedByteLengthFromBase64(rawBase64) {
|
|
81
|
+
const trimmed = rawBase64.trim();
|
|
82
|
+
const dataUrlMatch = /^data:[^;]+;base64,(.+)$/is.exec(trimmed);
|
|
83
|
+
const clean = (dataUrlMatch ? dataUrlMatch[1] : trimmed).replace(/\s+/g, '');
|
|
84
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean) || clean.length % 4 !== 0) {
|
|
85
|
+
throw new errors_js_1.VinMailError('Attachment contains invalid base64 content.', 422, 'validation_error');
|
|
86
|
+
}
|
|
87
|
+
const padding = clean.endsWith('==') ? 2 : clean.endsWith('=') ? 1 : 0;
|
|
88
|
+
return { clean, byteLength: (clean.length / 4) * 3 - padding };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolves `path` / `Uint8Array` / base64 attachments into API payloads and
|
|
92
|
+
* enforces VinMail's strict business-only allowlist and size caps client-side.
|
|
93
|
+
*/
|
|
94
|
+
async function prepareAttachments(inputs) {
|
|
95
|
+
if (inputs.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
if (inputs.length > exports.MAX_ATTACHMENTS_PER_EMAIL) {
|
|
98
|
+
throw new errors_js_1.VinMailError(`At most ${exports.MAX_ATTACHMENTS_PER_EMAIL} file attachments are allowed per email.`, 422, 'validation_error');
|
|
99
|
+
}
|
|
100
|
+
let totalBytes = 0;
|
|
101
|
+
const out = [];
|
|
102
|
+
for (const item of inputs) {
|
|
103
|
+
let filename;
|
|
104
|
+
let base64Content;
|
|
105
|
+
let sizeBytes;
|
|
106
|
+
if ('path' in item) {
|
|
107
|
+
filename = (item.filename ?? basenameOf(item.path)).trim();
|
|
108
|
+
const fs = await Promise.resolve().then(() => __importStar(require('node:fs/promises')));
|
|
109
|
+
const fileBytes = await fs.readFile(item.path);
|
|
110
|
+
sizeBytes = fileBytes.byteLength;
|
|
111
|
+
base64Content = fileBytes.toString('base64');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
filename = item.filename.trim();
|
|
115
|
+
if (typeof item.content === 'string') {
|
|
116
|
+
const parsed = decodedByteLengthFromBase64(item.content);
|
|
117
|
+
base64Content = parsed.clean;
|
|
118
|
+
sizeBytes = parsed.byteLength;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
sizeBytes = item.content.byteLength;
|
|
122
|
+
base64Content = uint8ArrayToBase64(item.content);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!filename) {
|
|
126
|
+
throw new errors_js_1.VinMailError('Each attachment must include a valid filename.', 422, 'validation_error');
|
|
127
|
+
}
|
|
128
|
+
const ext = getExtension(filename);
|
|
129
|
+
const canonicalMime = exports.ALLOWED_BUSINESS_EXTENSIONS[ext];
|
|
130
|
+
if (!canonicalMime) {
|
|
131
|
+
throw new errors_js_1.VinMailError(`File "${filename}" is not permitted. Only business documents and images are allowed (PDF, DOC/DOCX, XLS/XLSX, CSV, PPT/PPTX, TXT, RTF, PNG, JPG, WEBP, GIF).`, 422, 'validation_error');
|
|
132
|
+
}
|
|
133
|
+
if (sizeBytes <= 0) {
|
|
134
|
+
throw new errors_js_1.VinMailError(`Attachment "${filename}" cannot be empty.`, 422, 'validation_error');
|
|
135
|
+
}
|
|
136
|
+
if (sizeBytes > exports.MAX_SINGLE_ATTACHMENT_BYTES) {
|
|
137
|
+
throw new errors_js_1.VinMailError(`Attachment "${filename}" exceeds the 5 MB per-file size limit.`, 422, 'validation_error');
|
|
138
|
+
}
|
|
139
|
+
totalBytes += sizeBytes;
|
|
140
|
+
if (totalBytes > exports.MAX_TOTAL_ATTACHMENTS_BYTES) {
|
|
141
|
+
throw new errors_js_1.VinMailError('Combined attachment size exceeds the 7.5 MB limit per email.', 422, 'validation_error');
|
|
142
|
+
}
|
|
143
|
+
out.push({
|
|
144
|
+
filename,
|
|
145
|
+
content: base64Content,
|
|
146
|
+
contentType: canonicalMime,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=attachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/attachments.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,gDAgFC;AAtJD,2CAA2C;AAG9B,QAAA,yBAAyB,GAAG,CAAC,CAAC;AAC9B,QAAA,2BAA2B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9C,QAAA,2BAA2B,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAE5D,QAAA,2BAA2B,GAAqC;IAC3E,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,oBAAoB;IAC5B,OAAO,EAAE,yEAAyE;IAClF,MAAM,EAAE,0BAA0B;IAClC,OAAO,EAAE,mEA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G,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,mCAA2B,CAAC,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,wBAAY,CACpB,SAAS,QAAQ,6IAA6I,EAC9J,GAAG,EACH,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAED,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,wBAAY,CAAC,eAAe,QAAQ,oBAAoB,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,SAAS,GAAG,mCAA2B,EAAE,CAAC;YAC5C,MAAM,IAAI,wBAAY,CACpB,eAAe,QAAQ,yCAAyC,EAChE,GAAG,EACH,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAED,UAAU,IAAI,SAAS,CAAC;QACxB,IAAI,UAAU,GAAG,mCAA2B,EAAE,CAAC;YAC7C,MAAM,IAAI,wBAAY,CACpB,8DAA8D,EAC9D,GAAG,EACH,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAED,GAAG,CAAC,IAAI,CAAC;YACP,QAAQ;YACR,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VinMail = exports.EmailsResource = exports.SDK_VERSION = exports.DEFAULT_BASE_URL = void 0;
|
|
4
|
+
const attachments_js_1 = require("./attachments.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
exports.DEFAULT_BASE_URL = 'https://vinmail-api.vinworlddev.com';
|
|
7
|
+
exports.SDK_VERSION = '0.1.0';
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
function parseRetryAfter(header) {
|
|
12
|
+
if (!header)
|
|
13
|
+
return undefined;
|
|
14
|
+
const seconds = Number(header);
|
|
15
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
16
|
+
return seconds;
|
|
17
|
+
const dateMs = Date.parse(header);
|
|
18
|
+
if (!Number.isNaN(dateMs)) {
|
|
19
|
+
return Math.max(0, Math.ceil((dateMs - Date.now()) / 1000));
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
class HttpTransport {
|
|
24
|
+
apiKey;
|
|
25
|
+
baseUrl;
|
|
26
|
+
timeoutMs;
|
|
27
|
+
maxRetries;
|
|
28
|
+
fetchImpl;
|
|
29
|
+
constructor(apiKey, options = {}) {
|
|
30
|
+
const trimmed = apiKey.trim();
|
|
31
|
+
if (!trimmed) {
|
|
32
|
+
throw new errors_js_1.VinMailError('A valid VinMail API key (vm_live_...) is required.', 401, 'missing_api_key');
|
|
33
|
+
}
|
|
34
|
+
this.apiKey = trimmed;
|
|
35
|
+
this.baseUrl = (options.baseUrl ?? exports.DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
36
|
+
this.timeoutMs = options.timeoutMs ?? 15_000;
|
|
37
|
+
this.maxRetries = Math.max(0, options.maxRetries ?? 2);
|
|
38
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
39
|
+
if (typeof this.fetchImpl !== 'function') {
|
|
40
|
+
throw new errors_js_1.VinMailError('No fetch implementation found. Use Node.js 18+ or pass options.fetch.', 0, 'missing_fetch');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async request(method, path, body, extraHeaders) {
|
|
44
|
+
const url = `${this.baseUrl}${path}`;
|
|
45
|
+
const headers = {
|
|
46
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
47
|
+
Accept: 'application/json',
|
|
48
|
+
'User-Agent': `vinmail-node/${exports.SDK_VERSION}`,
|
|
49
|
+
...extraHeaders,
|
|
50
|
+
};
|
|
51
|
+
let serializedBody;
|
|
52
|
+
if (body !== undefined) {
|
|
53
|
+
headers['Content-Type'] = 'application/json';
|
|
54
|
+
serializedBody = JSON.stringify(body);
|
|
55
|
+
}
|
|
56
|
+
let attempt = 0;
|
|
57
|
+
while (true) {
|
|
58
|
+
const controller = new AbortController();
|
|
59
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
60
|
+
try {
|
|
61
|
+
const response = await this.fetchImpl(url, {
|
|
62
|
+
method,
|
|
63
|
+
headers,
|
|
64
|
+
body: serializedBody,
|
|
65
|
+
signal: controller.signal,
|
|
66
|
+
});
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
const text = await response.text();
|
|
69
|
+
let parsed = undefined;
|
|
70
|
+
if (text) {
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(text);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
parsed = undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (response.ok) {
|
|
79
|
+
return parsed;
|
|
80
|
+
}
|
|
81
|
+
const retryAfter = parseRetryAfter(response.headers.get('retry-after'));
|
|
82
|
+
const shouldRetry = attempt < this.maxRetries && (response.status === 429 || response.status >= 500);
|
|
83
|
+
if (shouldRetry) {
|
|
84
|
+
const delayMs = retryAfter !== undefined
|
|
85
|
+
? Math.min(retryAfter * 1000, 10_000)
|
|
86
|
+
: Math.min(300 * 2 ** attempt, 5_000);
|
|
87
|
+
attempt += 1;
|
|
88
|
+
await sleep(delayMs);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const errEnvelope = parsed;
|
|
92
|
+
const code = errEnvelope?.error?.code ?? `http_${response.status}`;
|
|
93
|
+
const message = errEnvelope?.error?.message ??
|
|
94
|
+
(text ? text.slice(0, 300) : `VinMail request failed with HTTP ${response.status}.`);
|
|
95
|
+
throw new errors_js_1.VinMailError(message, response.status, code, retryAfter);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
if (err instanceof errors_js_1.VinMailError) {
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
if (attempt < this.maxRetries) {
|
|
103
|
+
attempt += 1;
|
|
104
|
+
await sleep(Math.min(300 * 2 ** attempt, 5_000));
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const isTimeout = err instanceof Error && err.name === 'AbortError';
|
|
108
|
+
throw new errors_js_1.VinMailError(isTimeout
|
|
109
|
+
? `VinMail request timed out after ${this.timeoutMs} ms.`
|
|
110
|
+
: `Network error contacting VinMail: ${err instanceof Error ? err.message : String(err)}`, 0, isTimeout ? 'timeout' : 'network_error');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class EmailsResource {
|
|
116
|
+
transport;
|
|
117
|
+
constructor(transport) {
|
|
118
|
+
this.transport = transport;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Queues a transactional email for immediate delivery (`POST /v1/emails`).
|
|
122
|
+
*/
|
|
123
|
+
async send(params, options) {
|
|
124
|
+
const idempotencyKey = (options?.idempotencyKey ?? params.idempotencyKey)?.trim();
|
|
125
|
+
const attachments = params.attachments && params.attachments.length > 0
|
|
126
|
+
? await (0, attachments_js_1.prepareAttachments)(params.attachments)
|
|
127
|
+
: undefined;
|
|
128
|
+
const payload = {
|
|
129
|
+
to: params.to,
|
|
130
|
+
};
|
|
131
|
+
if (params.from !== undefined)
|
|
132
|
+
payload.from = params.from;
|
|
133
|
+
if (params.replyTo !== undefined)
|
|
134
|
+
payload.replyTo = params.replyTo;
|
|
135
|
+
if (params.subject !== undefined)
|
|
136
|
+
payload.subject = params.subject;
|
|
137
|
+
if (params.html !== undefined)
|
|
138
|
+
payload.html = params.html;
|
|
139
|
+
if (params.text !== undefined)
|
|
140
|
+
payload.text = params.text;
|
|
141
|
+
if (params.template !== undefined)
|
|
142
|
+
payload.template = params.template;
|
|
143
|
+
if (params.variables !== undefined)
|
|
144
|
+
payload.variables = params.variables;
|
|
145
|
+
if (params.tags !== undefined)
|
|
146
|
+
payload.tags = params.tags;
|
|
147
|
+
if (attachments !== undefined)
|
|
148
|
+
payload.attachments = attachments;
|
|
149
|
+
const headers = {};
|
|
150
|
+
if (idempotencyKey) {
|
|
151
|
+
headers['Idempotency-Key'] = idempotencyKey;
|
|
152
|
+
}
|
|
153
|
+
return this.transport.request('POST', '/v1/emails', payload, headers);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Fetches delivery status and event timeline for an email (`GET /v1/emails/:id`).
|
|
157
|
+
*/
|
|
158
|
+
async get(id) {
|
|
159
|
+
const cleanId = id.trim();
|
|
160
|
+
if (!cleanId) {
|
|
161
|
+
throw new errors_js_1.VinMailError('Email id is required.', 422, 'validation_error');
|
|
162
|
+
}
|
|
163
|
+
return this.transport.request('GET', `/v1/emails/${encodeURIComponent(cleanId)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.EmailsResource = EmailsResource;
|
|
167
|
+
class VinMail {
|
|
168
|
+
emails;
|
|
169
|
+
constructor(apiKey, options = {}) {
|
|
170
|
+
const transport = new HttpTransport(apiKey, options);
|
|
171
|
+
this.emails = new EmailsResource(transport);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.VinMail = VinMail;
|
|
175
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,qDAAsD;AACtD,2CAA2C;AAS9B,QAAA,gBAAgB,GAAG,qCAAqC,CAAC;AACzD,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAA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GAAG,cAAc,CAAC;QAC9C,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAoB,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,wBAAY,CAAC,uBAAuB,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAC3B,KAAK,EACL,cAAc,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAC5C,CAAC;IACJ,CAAC;CACF;AA/CD,wCA+CC;AAED,MAAa,OAAO;IACF,MAAM,CAAiB;IAEvC,YAAY,MAAc,EAAE,UAA0B,EAAE;QACtD,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF;AAPD,0BAOC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VinMailError = void 0;
|
|
4
|
+
class VinMailError extends Error {
|
|
5
|
+
/** HTTP status code (0 for local validation or network errors). */
|
|
6
|
+
status;
|
|
7
|
+
/** Machine-readable VinMail error code (e.g. "invalid_api_key", "domain_not_verified"). */
|
|
8
|
+
code;
|
|
9
|
+
/** Optional Retry-After hint in seconds (present on 429 responses). */
|
|
10
|
+
retryAfter;
|
|
11
|
+
constructor(message, status, code, retryAfter) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'VinMailError';
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.retryAfter = retryAfter;
|
|
17
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.VinMailError = VinMailError;
|
|
21
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IACrC,mEAAmE;IACnD,MAAM,CAAS;IAC/B,2FAA2F;IAC3E,IAAI,CAAS;IAC7B,uEAAuE;IACvD,UAAU,CAAU;IAEpC,YAAY,OAAe,EAAE,MAAc,EAAE,IAAY,EAAE,UAAmB;QAC5E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAhBD,oCAgBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VinMailError = exports.VinMail = exports.SDK_VERSION = exports.EmailsResource = exports.DEFAULT_BASE_URL = exports.prepareAttachments = exports.MAX_TOTAL_ATTACHMENTS_BYTES = exports.MAX_SINGLE_ATTACHMENT_BYTES = exports.MAX_ATTACHMENTS_PER_EMAIL = exports.ALLOWED_BUSINESS_EXTENSIONS = void 0;
|
|
4
|
+
var attachments_js_1 = require("./attachments.js");
|
|
5
|
+
Object.defineProperty(exports, "ALLOWED_BUSINESS_EXTENSIONS", { enumerable: true, get: function () { return attachments_js_1.ALLOWED_BUSINESS_EXTENSIONS; } });
|
|
6
|
+
Object.defineProperty(exports, "MAX_ATTACHMENTS_PER_EMAIL", { enumerable: true, get: function () { return attachments_js_1.MAX_ATTACHMENTS_PER_EMAIL; } });
|
|
7
|
+
Object.defineProperty(exports, "MAX_SINGLE_ATTACHMENT_BYTES", { enumerable: true, get: function () { return attachments_js_1.MAX_SINGLE_ATTACHMENT_BYTES; } });
|
|
8
|
+
Object.defineProperty(exports, "MAX_TOTAL_ATTACHMENTS_BYTES", { enumerable: true, get: function () { return attachments_js_1.MAX_TOTAL_ATTACHMENTS_BYTES; } });
|
|
9
|
+
Object.defineProperty(exports, "prepareAttachments", { enumerable: true, get: function () { return attachments_js_1.prepareAttachments; } });
|
|
10
|
+
var client_js_1 = require("./client.js");
|
|
11
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return client_js_1.DEFAULT_BASE_URL; } });
|
|
12
|
+
Object.defineProperty(exports, "EmailsResource", { enumerable: true, get: function () { return client_js_1.EmailsResource; } });
|
|
13
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return client_js_1.SDK_VERSION; } });
|
|
14
|
+
Object.defineProperty(exports, "VinMail", { enumerable: true, get: function () { return client_js_1.VinMail; } });
|
|
15
|
+
var errors_js_1 = require("./errors.js");
|
|
16
|
+
Object.defineProperty(exports, "VinMailError", { enumerable: true, get: function () { return errors_js_1.VinMailError; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAM0B;AALxB,6HAAA,2BAA2B,OAAA;AAC3B,2HAAA,yBAAyB,OAAA;AACzB,6HAAA,2BAA2B,OAAA;AAC3B,6HAAA,2BAA2B,OAAA;AAC3B,oHAAA,kBAAkB,OAAA;AAGpB,yCAAqF;AAA5E,6GAAA,gBAAgB,OAAA;AAAE,2GAAA,cAAc,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,oGAAA,OAAO,OAAA;AAC/D,yCAA2C;AAAlC,yGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AttachmentInput } from './types.js';
|
|
2
|
+
export declare const MAX_ATTACHMENTS_PER_EMAIL = 5;
|
|
3
|
+
export declare const MAX_SINGLE_ATTACHMENT_BYTES: number;
|
|
4
|
+
export declare const MAX_TOTAL_ATTACHMENTS_BYTES: number;
|
|
5
|
+
export declare const ALLOWED_BUSINESS_EXTENSIONS: Readonly<Record<string, string>>;
|
|
6
|
+
export interface EncodedAttachmentPayload {
|
|
7
|
+
filename: string;
|
|
8
|
+
content: string;
|
|
9
|
+
contentType: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolves `path` / `Uint8Array` / base64 attachments into API payloads and
|
|
13
|
+
* enforces VinMail's strict business-only allowlist and size caps client-side.
|
|
14
|
+
*/
|
|
15
|
+
export declare function prepareAttachments(inputs: AttachmentInput[]): Promise<EncodedAttachmentPayload[]>;
|
|
16
|
+
//# sourceMappingURL=attachments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../src/attachments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,eAAO,MAAM,2BAA2B,QAAkB,CAAC;AAC3D,eAAO,MAAM,2BAA2B,QAAgC,CAAC;AAEzE,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxE,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAqCD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,eAAe,EAAE,GACxB,OAAO,CAAC,wBAAwB,EAAE,CAAC,CA8ErC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { VinMailError } from './errors.js';
|
|
2
|
+
export const MAX_ATTACHMENTS_PER_EMAIL = 5;
|
|
3
|
+
export const MAX_SINGLE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
4
|
+
export const MAX_TOTAL_ATTACHMENTS_BYTES = Math.floor(7.5 * 1024 * 1024);
|
|
5
|
+
export const ALLOWED_BUSINESS_EXTENSIONS = {
|
|
6
|
+
'.pdf': 'application/pdf',
|
|
7
|
+
'.doc': 'application/msword',
|
|
8
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
9
|
+
'.xls': 'application/vnd.ms-excel',
|
|
10
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
11
|
+
'.csv': 'text/csv',
|
|
12
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
13
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
14
|
+
'.txt': 'text/plain',
|
|
15
|
+
'.rtf': 'application/rtf',
|
|
16
|
+
'.png': 'image/png',
|
|
17
|
+
'.jpg': 'image/jpeg',
|
|
18
|
+
'.jpeg': 'image/jpeg',
|
|
19
|
+
'.webp': 'image/webp',
|
|
20
|
+
'.gif': 'image/gif',
|
|
21
|
+
};
|
|
22
|
+
function getExtension(filename) {
|
|
23
|
+
const idx = filename.lastIndexOf('.');
|
|
24
|
+
if (idx <= 0 || idx === filename.length - 1)
|
|
25
|
+
return '';
|
|
26
|
+
return filename.slice(idx).toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
function basenameOf(filePath) {
|
|
29
|
+
const cleaned = filePath.replace(/\\/g, '/');
|
|
30
|
+
const parts = cleaned.split('/');
|
|
31
|
+
return parts[parts.length - 1] ?? 'attachment';
|
|
32
|
+
}
|
|
33
|
+
function uint8ArrayToBase64(bytes) {
|
|
34
|
+
if (typeof Buffer !== 'undefined') {
|
|
35
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
|
|
36
|
+
}
|
|
37
|
+
let binary = '';
|
|
38
|
+
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
39
|
+
binary += String.fromCharCode(bytes[i]);
|
|
40
|
+
}
|
|
41
|
+
return btoa(binary);
|
|
42
|
+
}
|
|
43
|
+
function decodedByteLengthFromBase64(rawBase64) {
|
|
44
|
+
const trimmed = rawBase64.trim();
|
|
45
|
+
const dataUrlMatch = /^data:[^;]+;base64,(.+)$/is.exec(trimmed);
|
|
46
|
+
const clean = (dataUrlMatch ? dataUrlMatch[1] : trimmed).replace(/\s+/g, '');
|
|
47
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean) || clean.length % 4 !== 0) {
|
|
48
|
+
throw new VinMailError('Attachment contains invalid base64 content.', 422, 'validation_error');
|
|
49
|
+
}
|
|
50
|
+
const padding = clean.endsWith('==') ? 2 : clean.endsWith('=') ? 1 : 0;
|
|
51
|
+
return { clean, byteLength: (clean.length / 4) * 3 - padding };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves `path` / `Uint8Array` / base64 attachments into API payloads and
|
|
55
|
+
* enforces VinMail's strict business-only allowlist and size caps client-side.
|
|
56
|
+
*/
|
|
57
|
+
export async function prepareAttachments(inputs) {
|
|
58
|
+
if (inputs.length === 0)
|
|
59
|
+
return [];
|
|
60
|
+
if (inputs.length > MAX_ATTACHMENTS_PER_EMAIL) {
|
|
61
|
+
throw new VinMailError(`At most ${MAX_ATTACHMENTS_PER_EMAIL} file attachments are allowed per email.`, 422, 'validation_error');
|
|
62
|
+
}
|
|
63
|
+
let totalBytes = 0;
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const item of inputs) {
|
|
66
|
+
let filename;
|
|
67
|
+
let base64Content;
|
|
68
|
+
let sizeBytes;
|
|
69
|
+
if ('path' in item) {
|
|
70
|
+
filename = (item.filename ?? basenameOf(item.path)).trim();
|
|
71
|
+
const fs = await import('node:fs/promises');
|
|
72
|
+
const fileBytes = await fs.readFile(item.path);
|
|
73
|
+
sizeBytes = fileBytes.byteLength;
|
|
74
|
+
base64Content = fileBytes.toString('base64');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
filename = item.filename.trim();
|
|
78
|
+
if (typeof item.content === 'string') {
|
|
79
|
+
const parsed = decodedByteLengthFromBase64(item.content);
|
|
80
|
+
base64Content = parsed.clean;
|
|
81
|
+
sizeBytes = parsed.byteLength;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
sizeBytes = item.content.byteLength;
|
|
85
|
+
base64Content = uint8ArrayToBase64(item.content);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!filename) {
|
|
89
|
+
throw new VinMailError('Each attachment must include a valid filename.', 422, 'validation_error');
|
|
90
|
+
}
|
|
91
|
+
const ext = getExtension(filename);
|
|
92
|
+
const canonicalMime = ALLOWED_BUSINESS_EXTENSIONS[ext];
|
|
93
|
+
if (!canonicalMime) {
|
|
94
|
+
throw new VinMailError(`File "${filename}" is not permitted. Only business documents and images are allowed (PDF, DOC/DOCX, XLS/XLSX, CSV, PPT/PPTX, TXT, RTF, PNG, JPG, WEBP, GIF).`, 422, 'validation_error');
|
|
95
|
+
}
|
|
96
|
+
if (sizeBytes <= 0) {
|
|
97
|
+
throw new VinMailError(`Attachment "${filename}" cannot be empty.`, 422, 'validation_error');
|
|
98
|
+
}
|
|
99
|
+
if (sizeBytes > MAX_SINGLE_ATTACHMENT_BYTES) {
|
|
100
|
+
throw new VinMailError(`Attachment "${filename}" exceeds the 5 MB per-file size limit.`, 422, 'validation_error');
|
|
101
|
+
}
|
|
102
|
+
totalBytes += sizeBytes;
|
|
103
|
+
if (totalBytes > MAX_TOTAL_ATTACHMENTS_BYTES) {
|
|
104
|
+
throw new VinMailError('Combined attachment size exceeds the 7.5 MB limit per email.', 422, 'validation_error');
|
|
105
|
+
}
|
|
106
|
+
out.push({
|
|
107
|
+
filename,
|
|
108
|
+
content: base64Content,
|
|
109
|
+
contentType: canonicalMime,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=attachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3D,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAEzE,MAAM,CAAC,MAAM,2BAA2B,GAAqC;IAC3E,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,oBAAoB;IAC5B,OAAO,EAAE,yEAAyE;IAClF,MAAM,EAAE,0BAA0B;IAClC,OAAO,EAAE,mEAAmE;IAC5E,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,+BAA+B;IACvC,OAAO,EAAE,2EAA2E;IACpF,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC;AAQF,SAAS,YAAY,CAAC,QAAgB;IACpC,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACtC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kB,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,SAAS,GAAG,2BAA2B,EAAE,CAAC;YAC5C,MAAM,IAAI,YAAY,CACpB,eAAe,QAAQ,yCAAyC,EAChE,GAAG,EACH,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAED,UAAU,IAAI,SAAS,CAAC;QACxB,IAAI,UAAU,GAAG,2BAA2B,EAAE,CAAC;YAC7C,MAAM,IAAI,YAAY,CACpB,8DAA8D,EAC9D,GAAG,EACH,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAED,GAAG,CAAC,IAAI,CAAC;YACP,QAAQ;YACR,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EmailDetails, SendEmailOptions, SendEmailParams, SendEmailResponse, VinMailOptions } from './types.js';
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://vinmail-api.vinworlddev.com";
|
|
3
|
+
export declare const SDK_VERSION = "0.1.0";
|
|
4
|
+
declare class HttpTransport {
|
|
5
|
+
private readonly apiKey;
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
private readonly timeoutMs;
|
|
8
|
+
private readonly maxRetries;
|
|
9
|
+
private readonly fetchImpl;
|
|
10
|
+
constructor(apiKey: string, options?: VinMailOptions);
|
|
11
|
+
request<T>(method: 'GET' | 'POST', path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare class EmailsResource {
|
|
14
|
+
private readonly transport;
|
|
15
|
+
constructor(transport: HttpTransport);
|
|
16
|
+
/**
|
|
17
|
+
* Queues a transactional email for immediate delivery (`POST /v1/emails`).
|
|
18
|
+
*/
|
|
19
|
+
send(params: SendEmailParams, options?: SendEmailOptions): Promise<SendEmailResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Fetches delivery status and event timeline for an email (`GET /v1/emails/:id`).
|
|
22
|
+
*/
|
|
23
|
+
get(id: string): Promise<EmailDetails>;
|
|
24
|
+
}
|
|
25
|
+
export declare class VinMail {
|
|
26
|
+
readonly emails: EmailsResource;
|
|
27
|
+
constructor(apiKey: string, options?: VinMailOptions);
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gBAAgB,wCAAwC,CAAC;AACtE,eAAO,MAAM,WAAW,UAAU,CAAC;AAiBnC,cAAM,aAAa;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;gBAExC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAoBlD,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC;CAsFd;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAErD;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA4B3F;;OAEG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAU7C;AAED,qBAAa,OAAO;IAClB,SAAgB,MAAM,EAAE,cAAc,CAAC;gBAE3B,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;CAIzD"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { prepareAttachments } from './attachments.js';
|
|
2
|
+
import { VinMailError } from './errors.js';
|
|
3
|
+
export const DEFAULT_BASE_URL = 'https://vinmail-api.vinworlddev.com';
|
|
4
|
+
export const SDK_VERSION = '0.1.0';
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
}
|
|
8
|
+
function parseRetryAfter(header) {
|
|
9
|
+
if (!header)
|
|
10
|
+
return undefined;
|
|
11
|
+
const seconds = Number(header);
|
|
12
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
13
|
+
return seconds;
|
|
14
|
+
const dateMs = Date.parse(header);
|
|
15
|
+
if (!Number.isNaN(dateMs)) {
|
|
16
|
+
return Math.max(0, Math.ceil((dateMs - Date.now()) / 1000));
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
class HttpTransport {
|
|
21
|
+
apiKey;
|
|
22
|
+
baseUrl;
|
|
23
|
+
timeoutMs;
|
|
24
|
+
maxRetries;
|
|
25
|
+
fetchImpl;
|
|
26
|
+
constructor(apiKey, options = {}) {
|
|
27
|
+
const trimmed = apiKey.trim();
|
|
28
|
+
if (!trimmed) {
|
|
29
|
+
throw new VinMailError('A valid VinMail API key (vm_live_...) is required.', 401, 'missing_api_key');
|
|
30
|
+
}
|
|
31
|
+
this.apiKey = trimmed;
|
|
32
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
33
|
+
this.timeoutMs = options.timeoutMs ?? 15_000;
|
|
34
|
+
this.maxRetries = Math.max(0, options.maxRetries ?? 2);
|
|
35
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
36
|
+
if (typeof this.fetchImpl !== 'function') {
|
|
37
|
+
throw new VinMailError('No fetch implementation found. Use Node.js 18+ or pass options.fetch.', 0, 'missing_fetch');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async request(method, path, body, extraHeaders) {
|
|
41
|
+
const url = `${this.baseUrl}${path}`;
|
|
42
|
+
const headers = {
|
|
43
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
44
|
+
Accept: 'application/json',
|
|
45
|
+
'User-Agent': `vinmail-node/${SDK_VERSION}`,
|
|
46
|
+
...extraHeaders,
|
|
47
|
+
};
|
|
48
|
+
let serializedBody;
|
|
49
|
+
if (body !== undefined) {
|
|
50
|
+
headers['Content-Type'] = 'application/json';
|
|
51
|
+
serializedBody = JSON.stringify(body);
|
|
52
|
+
}
|
|
53
|
+
let attempt = 0;
|
|
54
|
+
while (true) {
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.fetchImpl(url, {
|
|
59
|
+
method,
|
|
60
|
+
headers,
|
|
61
|
+
body: serializedBody,
|
|
62
|
+
signal: controller.signal,
|
|
63
|
+
});
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
const text = await response.text();
|
|
66
|
+
let parsed = undefined;
|
|
67
|
+
if (text) {
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(text);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
parsed = undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
return parsed;
|
|
77
|
+
}
|
|
78
|
+
const retryAfter = parseRetryAfter(response.headers.get('retry-after'));
|
|
79
|
+
const shouldRetry = attempt < this.maxRetries && (response.status === 429 || response.status >= 500);
|
|
80
|
+
if (shouldRetry) {
|
|
81
|
+
const delayMs = retryAfter !== undefined
|
|
82
|
+
? Math.min(retryAfter * 1000, 10_000)
|
|
83
|
+
: Math.min(300 * 2 ** attempt, 5_000);
|
|
84
|
+
attempt += 1;
|
|
85
|
+
await sleep(delayMs);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const errEnvelope = parsed;
|
|
89
|
+
const code = errEnvelope?.error?.code ?? `http_${response.status}`;
|
|
90
|
+
const message = errEnvelope?.error?.message ??
|
|
91
|
+
(text ? text.slice(0, 300) : `VinMail request failed with HTTP ${response.status}.`);
|
|
92
|
+
throw new VinMailError(message, response.status, code, retryAfter);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
if (err instanceof VinMailError) {
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
if (attempt < this.maxRetries) {
|
|
100
|
+
attempt += 1;
|
|
101
|
+
await sleep(Math.min(300 * 2 ** attempt, 5_000));
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const isTimeout = err instanceof Error && err.name === 'AbortError';
|
|
105
|
+
throw new VinMailError(isTimeout
|
|
106
|
+
? `VinMail request timed out after ${this.timeoutMs} ms.`
|
|
107
|
+
: `Network error contacting VinMail: ${err instanceof Error ? err.message : String(err)}`, 0, isTimeout ? 'timeout' : 'network_error');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class EmailsResource {
|
|
113
|
+
transport;
|
|
114
|
+
constructor(transport) {
|
|
115
|
+
this.transport = transport;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Queues a transactional email for immediate delivery (`POST /v1/emails`).
|
|
119
|
+
*/
|
|
120
|
+
async send(params, options) {
|
|
121
|
+
const idempotencyKey = (options?.idempotencyKey ?? params.idempotencyKey)?.trim();
|
|
122
|
+
const attachments = params.attachments && params.attachments.length > 0
|
|
123
|
+
? await prepareAttachments(params.attachments)
|
|
124
|
+
: undefined;
|
|
125
|
+
const payload = {
|
|
126
|
+
to: params.to,
|
|
127
|
+
};
|
|
128
|
+
if (params.from !== undefined)
|
|
129
|
+
payload.from = params.from;
|
|
130
|
+
if (params.replyTo !== undefined)
|
|
131
|
+
payload.replyTo = params.replyTo;
|
|
132
|
+
if (params.subject !== undefined)
|
|
133
|
+
payload.subject = params.subject;
|
|
134
|
+
if (params.html !== undefined)
|
|
135
|
+
payload.html = params.html;
|
|
136
|
+
if (params.text !== undefined)
|
|
137
|
+
payload.text = params.text;
|
|
138
|
+
if (params.template !== undefined)
|
|
139
|
+
payload.template = params.template;
|
|
140
|
+
if (params.variables !== undefined)
|
|
141
|
+
payload.variables = params.variables;
|
|
142
|
+
if (params.tags !== undefined)
|
|
143
|
+
payload.tags = params.tags;
|
|
144
|
+
if (attachments !== undefined)
|
|
145
|
+
payload.attachments = attachments;
|
|
146
|
+
const headers = {};
|
|
147
|
+
if (idempotencyKey) {
|
|
148
|
+
headers['Idempotency-Key'] = idempotencyKey;
|
|
149
|
+
}
|
|
150
|
+
return this.transport.request('POST', '/v1/emails', payload, headers);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fetches delivery status and event timeline for an email (`GET /v1/emails/:id`).
|
|
154
|
+
*/
|
|
155
|
+
async get(id) {
|
|
156
|
+
const cleanId = id.trim();
|
|
157
|
+
if (!cleanId) {
|
|
158
|
+
throw new VinMailError('Email id is required.', 422, 'validation_error');
|
|
159
|
+
}
|
|
160
|
+
return this.transport.request('GET', `/v1/emails/${encodeURIComponent(cleanId)}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export class VinMail {
|
|
164
|
+
emails;
|
|
165
|
+
constructor(apiKey, options = {}) {
|
|
166
|
+
const transport = new HttpTransport(apiKey, options);
|
|
167
|
+
this.emails = new EmailsResource(transport);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@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
+
readonly status: number;
|
|
4
|
+
/** Machine-readable VinMail error code (e.g. "invalid_api_key", "domain_not_verified"). */
|
|
5
|
+
readonly code: string;
|
|
6
|
+
/** Optional Retry-After hint in seconds (present on 429 responses). */
|
|
7
|
+
readonly retryAfter?: number;
|
|
8
|
+
constructor(message: string, status: number, code: string, retryAfter?: number);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,mEAAmE;IACnE,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,2FAA2F;IAC3F,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,uEAAuE;IACvE,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAQ/E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class VinMailError extends Error {
|
|
2
|
+
/** HTTP status code (0 for local validation or network errors). */
|
|
3
|
+
status;
|
|
4
|
+
/** Machine-readable VinMail error code (e.g. "invalid_api_key", "domain_not_verified"). */
|
|
5
|
+
code;
|
|
6
|
+
/** Optional Retry-After hint in seconds (present on 429 responses). */
|
|
7
|
+
retryAfter;
|
|
8
|
+
constructor(message, status, code, retryAfter) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'VinMailError';
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.retryAfter = retryAfter;
|
|
14
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,mEAAmE;IACnD,MAAM,CAAS;IAC/B,2FAA2F;IAC3E,IAAI,CAAS;IAC7B,uEAAuE;IACvD,UAAU,CAAU;IAEpC,YAAY,OAAe,EAAE,MAAc,EAAE,IAAY,EAAE,UAAmB;QAC5E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ALLOWED_BUSINESS_EXTENSIONS, MAX_ATTACHMENTS_PER_EMAIL, MAX_SINGLE_ATTACHMENT_BYTES, MAX_TOTAL_ATTACHMENTS_BYTES, prepareAttachments, } from './attachments.js';
|
|
2
|
+
export type { EncodedAttachmentPayload } from './attachments.js';
|
|
3
|
+
export { DEFAULT_BASE_URL, EmailsResource, SDK_VERSION, VinMail } from './client.js';
|
|
4
|
+
export { VinMailError } from './errors.js';
|
|
5
|
+
export type { AttachmentContentInput, AttachmentInput, AttachmentPathInput, EmailDetails, EmailEvent, EmailStatus, SendEmailOptions, SendEmailParams, SendEmailResponse, VinMailOptions, } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ALLOWED_BUSINESS_EXTENSIONS, MAX_ATTACHMENTS_PER_EMAIL, MAX_SINGLE_ATTACHMENT_BYTES, MAX_TOTAL_ATTACHMENTS_BYTES, prepareAttachments, } from './attachments.js';
|
|
2
|
+
export { DEFAULT_BASE_URL, EmailsResource, SDK_VERSION, VinMail } from './client.js';
|
|
3
|
+
export { VinMailError } from './errors.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type EmailStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'bounced' | 'complained' | 'failed' | (string & {});
|
|
2
|
+
export interface VinMailOptions {
|
|
3
|
+
/** Override API base URL (defaults to https://vinmail-api.vinworlddev.com). */
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
/** Request timeout in milliseconds (defaults to 15000). */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
/** Maximum retries on 429 or 5xx responses (defaults to 2). */
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
/** Custom fetch implementation (defaults to globalThis.fetch). */
|
|
10
|
+
fetch?: typeof globalThis.fetch;
|
|
11
|
+
}
|
|
12
|
+
export interface AttachmentContentInput {
|
|
13
|
+
/** Filename including extension (e.g. "invoice-1042.pdf"). */
|
|
14
|
+
filename: string;
|
|
15
|
+
/** Raw bytes (Buffer/Uint8Array) or base64-encoded string. */
|
|
16
|
+
content: string | Uint8Array;
|
|
17
|
+
/** Optional MIME hint (VinMail always enforces the canonical MIME for the extension). */
|
|
18
|
+
contentType?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AttachmentPathInput {
|
|
21
|
+
/** Path to a local file on disk (Node.js only). */
|
|
22
|
+
path: string;
|
|
23
|
+
/** Optional override for the filename shown to the recipient (defaults to basename of path). */
|
|
24
|
+
filename?: string;
|
|
25
|
+
/** Optional MIME hint. */
|
|
26
|
+
contentType?: string;
|
|
27
|
+
}
|
|
28
|
+
export type AttachmentInput = AttachmentContentInput | AttachmentPathInput;
|
|
29
|
+
export interface SendEmailParams {
|
|
30
|
+
/** Verified sender address, e.g. "Acme <billing@acme.com>". Optional if project has a defaultFrom. */
|
|
31
|
+
from?: string;
|
|
32
|
+
/** One recipient email or an array of up to 50 email addresses (without display names). */
|
|
33
|
+
to: string | string[];
|
|
34
|
+
/** Optional Reply-To address ("email" or "Name <email>"). */
|
|
35
|
+
replyTo?: string;
|
|
36
|
+
/** Single-line subject (required unless using a template that defines one). */
|
|
37
|
+
subject?: string;
|
|
38
|
+
/** HTML body (up to 500 KB). */
|
|
39
|
+
html?: string;
|
|
40
|
+
/** Plain-text body (up to 500 KB). */
|
|
41
|
+
text?: string;
|
|
42
|
+
/** Template name (project template or built-in global template: "otp", "notification", "notification-action"). */
|
|
43
|
+
template?: string;
|
|
44
|
+
/** Template variables (never stored or logged by VinMail). */
|
|
45
|
+
variables?: Record<string, unknown>;
|
|
46
|
+
/** Up to 5 key/value tags attached to delivery events. */
|
|
47
|
+
tags?: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional business file attachments (max 5 files, 5 MB each, 7.5 MB combined).
|
|
50
|
+
* Allowed formats: PDF, DOC/DOCX, XLS/XLSX, CSV, PPT/PPTX, TXT, RTF, PNG, JPG, JPEG, WEBP, GIF.
|
|
51
|
+
*/
|
|
52
|
+
attachments?: AttachmentInput[];
|
|
53
|
+
/** Optional Idempotency-Key header to prevent duplicate sends on retry. */
|
|
54
|
+
idempotencyKey?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SendEmailOptions {
|
|
57
|
+
/** Overrides `params.idempotencyKey` if supplied. */
|
|
58
|
+
idempotencyKey?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface SendEmailResponse {
|
|
61
|
+
id: string;
|
|
62
|
+
status: EmailStatus;
|
|
63
|
+
/** Included only when one or more recipients were automatically dropped due to suppression. */
|
|
64
|
+
suppressed?: string[];
|
|
65
|
+
}
|
|
66
|
+
export interface EmailEvent {
|
|
67
|
+
type: string;
|
|
68
|
+
recipient: string | null;
|
|
69
|
+
detail: Record<string, unknown> | null;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
}
|
|
72
|
+
export interface EmailDetails {
|
|
73
|
+
id: string;
|
|
74
|
+
status: EmailStatus;
|
|
75
|
+
to: string[];
|
|
76
|
+
subject: string;
|
|
77
|
+
templateName: string | null;
|
|
78
|
+
recipientCount: number;
|
|
79
|
+
error: string | null;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
sentAt: string | null;
|
|
82
|
+
events: EmailEvent[];
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GACn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AM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;IAChC,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,WAAW,CAAC;IACpB,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,WAAW,CAAC;IACpB,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinworld/vinmail",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official Node.js and TypeScript SDK for VinMail transactional email API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vinmail",
|
|
7
|
+
"vinworld",
|
|
8
|
+
"email",
|
|
9
|
+
"transactional-email",
|
|
10
|
+
"ses",
|
|
11
|
+
"sdk"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Vinworld <dev@vinworlddev.com>",
|
|
15
|
+
"homepage": "https://vinmail.vinworlddev.com/docs",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/vinworld/vinmail-sdks.git",
|
|
19
|
+
"directory": "node"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/cjs/index.js",
|
|
23
|
+
"module": "./dist/esm/index.js",
|
|
24
|
+
"types": "./dist/esm/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/esm/index.d.ts",
|
|
28
|
+
"import": "./dist/esm/index.js",
|
|
29
|
+
"require": "./dist/cjs/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
45
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
46
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && node -e \"require('node:fs').writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }, null, 2))\"",
|
|
47
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
48
|
+
"test": "npm run build && node --test test/vinmail.test.mjs",
|
|
49
|
+
"prepublishOnly": "npm test"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^22.0.0",
|
|
53
|
+
"typescript": "^5.7.2"
|
|
54
|
+
}
|
|
55
|
+
}
|