dymo-api 1.0.49 → 1.0.50
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.
|
@@ -27,9 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getRandom = exports.sendEmail = exports.isValidData = void 0;
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
30
31
|
const axios_1 = __importDefault(require("axios"));
|
|
31
32
|
const react_1 = __importDefault(require("react"));
|
|
32
|
-
|
|
33
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
33
34
|
const { twi } = require("tw-to-css");
|
|
34
35
|
const config_1 = __importStar(require("../config"));
|
|
35
36
|
const render_1 = require("@react-email/render");
|
|
@@ -68,17 +69,17 @@ const isValidData = async (token, data) => {
|
|
|
68
69
|
};
|
|
69
70
|
exports.isValidData = isValidData;
|
|
70
71
|
/**
|
|
71
|
-
* Sends an email using
|
|
72
|
-
*
|
|
73
|
-
* This method requires a valid private token to be set.
|
|
72
|
+
* Sends an email using a secure sending endpoint.
|
|
74
73
|
*
|
|
75
74
|
* @param token - A string or null representing the authentication token. Must not be null.
|
|
76
75
|
* @param data - An object adhering to the SendEmail interface, containing the following fields:
|
|
77
|
-
* from, to, subject, html, and optionally
|
|
76
|
+
* 'from', 'to', 'subject', 'html' or 'react', and optionally 'attachments', 'options', 'priority', and 'composeTailwindClasses'.
|
|
78
77
|
*
|
|
79
|
-
* @returns A promise that resolves to the response from the
|
|
78
|
+
* @returns A promise that resolves to the response data from the sending endpoint.
|
|
80
79
|
*
|
|
81
|
-
* @throws Will throw an error if
|
|
80
|
+
* @throws Will throw an error if the token is null, if any of the required fields are missing,
|
|
81
|
+
* if the 'react' field is not a valid React element, if the 'attachments' field exceeds the maximum allowed size of 40 MB,
|
|
82
|
+
* or if an error occurs during the sending request.
|
|
82
83
|
*/
|
|
83
84
|
const sendEmail = async (token, data) => {
|
|
84
85
|
if (token === null)
|
|
@@ -108,6 +109,27 @@ const sendEmail = async (token, data) => {
|
|
|
108
109
|
throw customError(1500, `An error occurred while rendering your React component. Details: ${error}`);
|
|
109
110
|
}
|
|
110
111
|
try {
|
|
112
|
+
let totalSize = 0;
|
|
113
|
+
if (data.attachments && Array.isArray(data.attachments)) {
|
|
114
|
+
const processedAttachments = await Promise.all(data.attachments.map(async (attachment) => {
|
|
115
|
+
if ((attachment.path && attachment.content) || (!attachment.path && !attachment.content))
|
|
116
|
+
throw customError(1500, "You must provide either 'path' or 'content', not both.");
|
|
117
|
+
let contentBuffer;
|
|
118
|
+
if (attachment.path)
|
|
119
|
+
contentBuffer = await promises_1.default.readFile(path_1.default.resolve(attachment.path));
|
|
120
|
+
else if (attachment.content)
|
|
121
|
+
contentBuffer = attachment.content instanceof Buffer ? attachment.content : Buffer.from(attachment.content);
|
|
122
|
+
totalSize += Buffer.byteLength(contentBuffer);
|
|
123
|
+
if (totalSize > 40 * 1024 * 1024)
|
|
124
|
+
throw customError(1500, "Attachments exceed the maximum allowed size of 40 MB.");
|
|
125
|
+
return {
|
|
126
|
+
filename: attachment.filename || path_1.default.basename(attachment.path || ""),
|
|
127
|
+
content: contentBuffer,
|
|
128
|
+
cid: attachment.cid || attachment.filename
|
|
129
|
+
};
|
|
130
|
+
}));
|
|
131
|
+
data.attachments = processedAttachments;
|
|
132
|
+
}
|
|
111
133
|
const response = await axios_1.default.post(`${config_1.BASE_URL}/v1/private/sender/sendEmail`, data, { headers: { "Authorization": token } });
|
|
112
134
|
return response.data;
|
|
113
135
|
}
|
|
@@ -27,9 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getRandom = exports.sendEmail = exports.isValidData = void 0;
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
30
31
|
const axios_1 = __importDefault(require("axios"));
|
|
31
32
|
const react_1 = __importDefault(require("react"));
|
|
32
|
-
|
|
33
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
33
34
|
const { twi } = require("tw-to-css");
|
|
34
35
|
const config_1 = __importStar(require("../config"));
|
|
35
36
|
const render_1 = require("@react-email/render");
|
|
@@ -68,17 +69,17 @@ const isValidData = async (token, data) => {
|
|
|
68
69
|
};
|
|
69
70
|
exports.isValidData = isValidData;
|
|
70
71
|
/**
|
|
71
|
-
* Sends an email using
|
|
72
|
-
*
|
|
73
|
-
* This method requires a valid private token to be set.
|
|
72
|
+
* Sends an email using a secure sending endpoint.
|
|
74
73
|
*
|
|
75
74
|
* @param token - A string or null representing the authentication token. Must not be null.
|
|
76
75
|
* @param data - An object adhering to the SendEmail interface, containing the following fields:
|
|
77
|
-
* from, to, subject, html, and optionally
|
|
76
|
+
* 'from', 'to', 'subject', 'html' or 'react', and optionally 'attachments', 'options', 'priority', and 'composeTailwindClasses'.
|
|
78
77
|
*
|
|
79
|
-
* @returns A promise that resolves to the response from the
|
|
78
|
+
* @returns A promise that resolves to the response data from the sending endpoint.
|
|
80
79
|
*
|
|
81
|
-
* @throws Will throw an error if
|
|
80
|
+
* @throws Will throw an error if the token is null, if any of the required fields are missing,
|
|
81
|
+
* if the 'react' field is not a valid React element, if the 'attachments' field exceeds the maximum allowed size of 40 MB,
|
|
82
|
+
* or if an error occurs during the sending request.
|
|
82
83
|
*/
|
|
83
84
|
const sendEmail = async (token, data) => {
|
|
84
85
|
if (token === null)
|
|
@@ -108,6 +109,27 @@ const sendEmail = async (token, data) => {
|
|
|
108
109
|
throw customError(1500, `An error occurred while rendering your React component. Details: ${error}`);
|
|
109
110
|
}
|
|
110
111
|
try {
|
|
112
|
+
let totalSize = 0;
|
|
113
|
+
if (data.attachments && Array.isArray(data.attachments)) {
|
|
114
|
+
const processedAttachments = await Promise.all(data.attachments.map(async (attachment) => {
|
|
115
|
+
if ((attachment.path && attachment.content) || (!attachment.path && !attachment.content))
|
|
116
|
+
throw customError(1500, "You must provide either 'path' or 'content', not both.");
|
|
117
|
+
let contentBuffer;
|
|
118
|
+
if (attachment.path)
|
|
119
|
+
contentBuffer = await promises_1.default.readFile(path_1.default.resolve(attachment.path));
|
|
120
|
+
else if (attachment.content)
|
|
121
|
+
contentBuffer = attachment.content instanceof Buffer ? attachment.content : Buffer.from(attachment.content);
|
|
122
|
+
totalSize += Buffer.byteLength(contentBuffer);
|
|
123
|
+
if (totalSize > 40 * 1024 * 1024)
|
|
124
|
+
throw customError(1500, "Attachments exceed the maximum allowed size of 40 MB.");
|
|
125
|
+
return {
|
|
126
|
+
filename: attachment.filename || path_1.default.basename(attachment.path || ""),
|
|
127
|
+
content: contentBuffer,
|
|
128
|
+
cid: attachment.cid || attachment.filename
|
|
129
|
+
};
|
|
130
|
+
}));
|
|
131
|
+
data.attachments = processedAttachments;
|
|
132
|
+
}
|
|
111
133
|
const response = await axios_1.default.post(`${config_1.BASE_URL}/v1/private/sender/sendEmail`, data, { headers: { "Authorization": token } });
|
|
112
134
|
return response.data;
|
|
113
135
|
}
|
|
@@ -13,17 +13,17 @@ import * as Interfaces from "../lib/interfaces";
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const isValidData: (token: string | null, data: Interfaces.Validator) => Promise<any>;
|
|
15
15
|
/**
|
|
16
|
-
* Sends an email using
|
|
17
|
-
*
|
|
18
|
-
* This method requires a valid private token to be set.
|
|
16
|
+
* Sends an email using a secure sending endpoint.
|
|
19
17
|
*
|
|
20
18
|
* @param token - A string or null representing the authentication token. Must not be null.
|
|
21
19
|
* @param data - An object adhering to the SendEmail interface, containing the following fields:
|
|
22
|
-
* from, to, subject, html, and optionally
|
|
20
|
+
* 'from', 'to', 'subject', 'html' or 'react', and optionally 'attachments', 'options', 'priority', and 'composeTailwindClasses'.
|
|
23
21
|
*
|
|
24
|
-
* @returns A promise that resolves to the response from the
|
|
22
|
+
* @returns A promise that resolves to the response data from the sending endpoint.
|
|
25
23
|
*
|
|
26
|
-
* @throws Will throw an error if
|
|
24
|
+
* @throws Will throw an error if the token is null, if any of the required fields are missing,
|
|
25
|
+
* if the 'react' field is not a valid React element, if the 'attachments' field exceeds the maximum allowed size of 40 MB,
|
|
26
|
+
* or if an error occurs during the sending request.
|
|
27
27
|
*/
|
|
28
28
|
export declare const sendEmail: (token: string | null, data: Interfaces.SendEmail) => Promise<any>;
|
|
29
29
|
/**
|
|
@@ -21,6 +21,12 @@ export interface SRNG {
|
|
|
21
21
|
max: number;
|
|
22
22
|
quantity?: number;
|
|
23
23
|
}
|
|
24
|
+
export type Attachment = {
|
|
25
|
+
filename: string;
|
|
26
|
+
path?: string;
|
|
27
|
+
content?: string | Buffer;
|
|
28
|
+
cid?: string;
|
|
29
|
+
};
|
|
24
30
|
export interface SendEmail {
|
|
25
31
|
from: string;
|
|
26
32
|
to: string;
|
|
@@ -31,5 +37,6 @@ export interface SendEmail {
|
|
|
31
37
|
priority?: "high" | "normal" | "low" | undefined;
|
|
32
38
|
composeTailwindClasses?: boolean;
|
|
33
39
|
};
|
|
40
|
+
attachments?: Attachment[];
|
|
34
41
|
}
|
|
35
42
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dymo-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"description": "Flow system for Dymo API.",
|
|
5
5
|
"main": "dist/cjs/dymo-api.js",
|
|
6
6
|
"module": "dist/esm/dymo-api.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@react-email/render": "1.0.1",
|
|
43
43
|
"@types/react": "^18.3.5",
|
|
44
44
|
"axios": "^1.6.8",
|
|
45
|
+
"path": "^0.12.7",
|
|
45
46
|
"rimraf": "^6.0.1",
|
|
46
47
|
"tw-to-css": "0.0.12"
|
|
47
48
|
},
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
],
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/axios": "^0.9.36",
|
|
54
|
-
"@types/node": "^22.9.
|
|
55
|
+
"@types/node": "^22.9.3",
|
|
55
56
|
"ts-node": "^10.9.2",
|
|
56
57
|
"typescript": "^5.5.4"
|
|
57
58
|
}
|