@postalsys/email-ai-tools 2.2.8 → 2.3.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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/cjs/index.d.ts +28 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/lib/api-request.d.ts +42 -0
- package/dist/cjs/lib/api-request.js +183 -0
- package/dist/cjs/lib/authentication.d.ts +46 -0
- package/{lib → dist/cjs/lib}/authentication.js +33 -44
- package/dist/cjs/lib/generate-summary.d.ts +143 -0
- package/dist/cjs/lib/generate-summary.js +562 -0
- package/dist/cjs/lib/get-api-url.d.ts +19 -0
- package/dist/cjs/lib/get-api-url.js +37 -0
- package/dist/cjs/lib/list-models.d.ts +46 -0
- package/dist/cjs/lib/list-models.js +125 -0
- package/dist/cjs/lib/signals.d.ts +72 -0
- package/dist/cjs/lib/signals.js +293 -0
- package/dist/cjs/lib/token-estimate.d.ts +46 -0
- package/{lib → dist/cjs/lib}/token-estimate.js +21 -50
- package/dist/cjs/lib/visible-text.d.ts +33 -0
- package/dist/cjs/lib/visible-text.js +182 -0
- package/dist/cjs/package-info.d.ts +2 -0
- package/dist/cjs/package-info.js +6 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.d.ts +28 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/lib/api-request.d.ts +42 -0
- package/{lib → dist/esm/lib}/api-request.js +20 -53
- package/dist/esm/lib/authentication.d.ts +46 -0
- package/dist/esm/lib/authentication.js +149 -0
- package/dist/esm/lib/generate-summary.d.ts +143 -0
- package/{lib → dist/esm/lib}/generate-summary.js +59 -155
- package/dist/esm/lib/get-api-url.d.ts +19 -0
- package/{lib → dist/esm/lib}/get-api-url.js +4 -13
- package/dist/esm/lib/list-models.d.ts +46 -0
- package/{lib → dist/esm/lib}/list-models.js +19 -50
- package/dist/esm/lib/signals.d.ts +72 -0
- package/{lib → dist/esm/lib}/signals.js +33 -79
- package/dist/esm/lib/token-estimate.d.ts +46 -0
- package/dist/esm/lib/token-estimate.js +108 -0
- package/dist/esm/lib/visible-text.d.ts +33 -0
- package/{lib → dist/esm/lib}/visible-text.js +14 -40
- package/dist/esm/package-info.d.ts +2 -0
- package/dist/esm/package-info.js +3 -0
- package/dist/esm/package.json +3 -0
- package/package.json +63 -10
- package/.github/VULNERABILITY_REPORT.yml +0 -75
- package/.github/workflows/release.yaml +0 -37
- package/.github/workflows/test.yaml +0 -35
- package/.ncurc.js +0 -23
- package/.prettierignore +0 -5
- package/.prettierrc.js +0 -10
- package/.release-please-manifest.json +0 -3
- package/CLAUDE.md +0 -185
- package/eslint.config.js +0 -70
- package/examples/fixtures/message-1.json +0 -74
- package/examples/list-models.js +0 -14
- package/examples/summary.js +0 -34
- package/index.js +0 -26
- package/release-please-config.json +0 -10
- package/test/api-request.test.js +0 -169
- package/test/authentication.test.js +0 -110
- package/test/commonjs-graph.test.js +0 -21
- package/test/dispatcher.test.js +0 -94
- package/test/generate-summary.test.js +0 -795
- package/test/get-api-url.test.js +0 -52
- package/test/helpers/mock-server.js +0 -120
- package/test/index.test.js +0 -57
- package/test/list-models.test.js +0 -302
- package/test/signals.test.js +0 -264
- package/test/token-estimate.test.js +0 -164
- package/test/visible-text.test.js +0 -144
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Token counts are estimated from characters instead of running a BPE tokenizer. The GPT-3
|
|
2
|
+
// tokenizer this library used to load does not match current model vocabularies anyway, costs
|
|
3
|
+
// ~15 MB of heap per instance, and is super-linear on long unbroken runs (a 64 KB CJK body took
|
|
4
|
+
// 25 s per encode). The estimate errs on the high side; the model's own context length error
|
|
5
|
+
// stays the backstop for the rare input that tokenizes worse than this.
|
|
6
|
+
// ASCII at 3 characters per token is below what English, code and base64-ish runs actually
|
|
7
|
+
// reach, every non-ASCII UTF-16 code unit counts as a whole token, and the margin goes on top
|
|
8
|
+
const CHARS_PER_TOKEN = 3;
|
|
9
|
+
const MARGIN = 1.1;
|
|
10
|
+
// Input text beyond this many characters is never sent, whatever the token budget
|
|
11
|
+
const MAX_ALLOWED_TEXT_LENGTH = 64 * 1024;
|
|
12
|
+
// Default prompt budget when the caller does not set maxTokens
|
|
13
|
+
const DEFAULT_MAX_ALLOWED_TOKENS = 30000;
|
|
14
|
+
// Cost of one UTF-16 code unit in "ASCII character" units. The text travels JSON encoded, so the
|
|
15
|
+
// characters that encoding escapes count double
|
|
16
|
+
function charUnits(code) {
|
|
17
|
+
if (code < 0x20 || code === 0x22 || code === 0x5c) {
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
if (code < 0x80) {
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
return CHARS_PER_TOKEN;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Estimates how many tokens a string takes
|
|
27
|
+
*
|
|
28
|
+
* @returns Estimated token count
|
|
29
|
+
*/
|
|
30
|
+
function estimateTokens(input) {
|
|
31
|
+
const str = (input || '').toString();
|
|
32
|
+
let units = 0;
|
|
33
|
+
for (let i = 0; i < str.length; i++) {
|
|
34
|
+
units += charUnits(str.charCodeAt(i));
|
|
35
|
+
}
|
|
36
|
+
// the epsilon keeps float noise (100 * 1.1 = 110.00000000000001) from adding a token
|
|
37
|
+
return Math.ceil((units / CHARS_PER_TOKEN) * MARGIN - 1e-9);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the length of the longest prefix of `str` that fits into `maxTokens` by the same
|
|
41
|
+
* estimate as estimateTokens(). Never ends between the two halves of a surrogate pair.
|
|
42
|
+
*
|
|
43
|
+
* @returns Prefix length in UTF-16 code units
|
|
44
|
+
*/
|
|
45
|
+
function fitLength(input, maxTokens) {
|
|
46
|
+
const str = (input || '').toString();
|
|
47
|
+
if (!(maxTokens > 0)) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
const maxUnits = Math.floor((maxTokens * CHARS_PER_TOKEN) / MARGIN);
|
|
51
|
+
let units = 0;
|
|
52
|
+
let i = 0;
|
|
53
|
+
for (; i < str.length; i++) {
|
|
54
|
+
const cost = charUnits(str.charCodeAt(i));
|
|
55
|
+
if (units + cost > maxUnits) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
units += cost;
|
|
59
|
+
}
|
|
60
|
+
return keepSurrogatePair(str, i);
|
|
61
|
+
}
|
|
62
|
+
// Moves a cut position back by one if it would separate a surrogate pair
|
|
63
|
+
function keepSurrogatePair(str, pos) {
|
|
64
|
+
if (pos > 0 && pos < str.length) {
|
|
65
|
+
const prev = str.charCodeAt(pos - 1);
|
|
66
|
+
if (prev >= 0xd800 && prev <= 0xdbff) {
|
|
67
|
+
return pos - 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return pos;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Cuts a string to at most `maxLength` UTF-16 code units, never between the halves of a
|
|
74
|
+
* surrogate pair
|
|
75
|
+
*/
|
|
76
|
+
function truncate(input, maxLength) {
|
|
77
|
+
const str = (input || '').toString();
|
|
78
|
+
return str.length > maxLength ? str.substring(0, keepSurrogatePair(str, maxLength)) : str;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Cuts `text` so that it fits into `maxTokens` estimated tokens next to the fixed parts of the
|
|
82
|
+
* prompt
|
|
83
|
+
*
|
|
84
|
+
* @throws Error with code PROMPT_TOO_LONG if the fixed parts alone do not fit
|
|
85
|
+
*/
|
|
86
|
+
function fitPrompt({ text, maxLength, maxTokens, overhead }) {
|
|
87
|
+
text = (text || '').toString();
|
|
88
|
+
maxLength = maxLength || MAX_ALLOWED_TEXT_LENGTH;
|
|
89
|
+
maxTokens = maxTokens || DEFAULT_MAX_ALLOWED_TOKENS;
|
|
90
|
+
const overheadTokens = []
|
|
91
|
+
.concat(overhead === undefined ? [] : overhead)
|
|
92
|
+
.reduce((sum, part) => sum + (typeof part === 'number' ? part : estimateTokens(part)), 0);
|
|
93
|
+
if (overheadTokens > maxTokens) {
|
|
94
|
+
const error = new Error(`Unable to fit email content within token limit of ${maxTokens}. ` +
|
|
95
|
+
`Original text length: ${text.length} characters. ` +
|
|
96
|
+
`The prompt without the email text is already estimated at ${overheadTokens} tokens. ` +
|
|
97
|
+
`Consider using a model with larger context window.`);
|
|
98
|
+
error.code = 'PROMPT_TOO_LONG';
|
|
99
|
+
error.originalLength = text.length;
|
|
100
|
+
error.charactersRemoved = text.length;
|
|
101
|
+
error.maxAllowedTokens = maxTokens;
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
let fitted = truncate(text, maxLength);
|
|
105
|
+
fitted = fitted.substring(0, fitLength(fitted, maxTokens - overheadTokens));
|
|
106
|
+
return { text: fitted, charactersRemoved: text.length - fitted.length };
|
|
107
|
+
}
|
|
108
|
+
export { estimateTokens, fitLength, fitPrompt, truncate, DEFAULT_MAX_ALLOWED_TOKENS };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** A link of the message: its target and the text a reader takes as its destination */
|
|
2
|
+
export interface MessageLink {
|
|
3
|
+
href: string;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
/** What visibleHtml() found */
|
|
7
|
+
export interface VisibleHtml {
|
|
8
|
+
/** Every link the HTML carries, hidden or not */
|
|
9
|
+
links: MessageLink[];
|
|
10
|
+
/** How many styled-away elements carrying text were dropped */
|
|
11
|
+
hiddenElements: number;
|
|
12
|
+
/** How many invisible characters were dropped */
|
|
13
|
+
invisibleCharacters: number;
|
|
14
|
+
/** The visible HTML, serialised only when asked for */
|
|
15
|
+
html: () => string;
|
|
16
|
+
}
|
|
17
|
+
declare const MAX_HTML_LENGTH: number;
|
|
18
|
+
declare const MAX_LINK_TEXT_LENGTH = 1024;
|
|
19
|
+
declare const INVISIBLE_CHARS: RegExp;
|
|
20
|
+
/**
|
|
21
|
+
* Parses an HTML message once: every link it carries, for the checks, and the document as the
|
|
22
|
+
* reader sees it, for the model
|
|
23
|
+
*/
|
|
24
|
+
declare function visibleHtml(html: string): VisibleHtml;
|
|
25
|
+
/**
|
|
26
|
+
* Removes the characters that take no space on screen
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
declare function visibleText(input: unknown): {
|
|
30
|
+
text: string;
|
|
31
|
+
invisibleCharacters: number;
|
|
32
|
+
};
|
|
33
|
+
export { visibleHtml, visibleText, INVISIBLE_CHARS, MAX_HTML_LENGTH, MAX_LINK_TEXT_LENGTH };
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { isTag, isText, isComment, hasChildren, textContent, findAll, findOne, prependChild, removeElement } = require('domutils');
|
|
6
|
-
const { truncate } = require('./token-estimate');
|
|
7
|
-
|
|
1
|
+
import { parseDocument } from 'htmlparser2';
|
|
2
|
+
import serialize from 'dom-serializer';
|
|
3
|
+
import { isTag, isText, isComment, hasChildren, textContent, findAll, findOne, prependChild, removeElement } from 'domutils';
|
|
4
|
+
import { truncate } from './token-estimate.js';
|
|
8
5
|
// What the reader never sees must not reach the model either: an email can carry instructions
|
|
9
6
|
// for an AI in text a mail client does not render, and the summary has to describe the message
|
|
10
7
|
// as it looks to the person it was sent to. The links are collected before anything is removed,
|
|
11
8
|
// because the checks run on them must see every link the message carries, hidden or not
|
|
12
|
-
|
|
13
9
|
// Elements whose content is never rendered as text
|
|
14
10
|
const HIDDEN_TAGS = new Set(['script', 'style', 'template', 'title', 'iframe', 'object', 'embed']);
|
|
15
|
-
|
|
16
11
|
// Comments and quoted strings inside a style attribute, which carry no declarations
|
|
17
12
|
const STYLE_NOISE = /\/\*[\s\S]*?\*\/|"[^"]*"|'[^']*'/g;
|
|
18
|
-
|
|
19
13
|
// Everything here runs synchronously in the process that called it, so how much of a message is
|
|
20
14
|
// read has to be this library's decision rather than the sender's. The HTML is cut before it is
|
|
21
15
|
// parsed; the text of a link is cut to what a reader could take in as its destination
|
|
22
16
|
const MAX_HTML_LENGTH = 1024 * 1024;
|
|
23
17
|
const MAX_LINK_TEXT_LENGTH = 1024;
|
|
24
|
-
|
|
25
18
|
// Outlook for Windows shows what a conditional comment wraps; the markers go, the content stays.
|
|
26
19
|
// The condition is bounded: an opening marker that never closes used to be scanned to the end
|
|
27
20
|
// of the document, once for every marker, which is quadratic
|
|
28
21
|
const CONDITIONAL_COMMENT = /<!--\[if [^\]]{0,200}\]>|<!\[endif\]-->/gi;
|
|
29
|
-
|
|
30
22
|
// Characters that take no space on screen: zero-width joiners and spaces, soft hyphens, the
|
|
31
23
|
// bidirectional controls and the word joiner. Removing them changes nothing the reader sees and
|
|
32
24
|
// stops them splitting words the model should recognise or reordering text it should read
|
|
33
25
|
const INVISIBLE_CHARS = /[\u00ad\u200b-\u200f\u2028-\u202e\u2060-\u2064\u2066-\u206f\ufeff]/g;
|
|
34
|
-
|
|
35
26
|
// Only what reliably hides text. Zero sizes of boxes and negative positions depend on other
|
|
36
27
|
// properties to hide anything, so they are left alone rather than dropping text the reader sees
|
|
37
|
-
function isHiddenStyle(
|
|
38
|
-
style = String(
|
|
28
|
+
function isHiddenStyle(input) {
|
|
29
|
+
const style = String(input ?? '').replace(STYLE_NOISE, ' ');
|
|
39
30
|
if (!style.trim()) {
|
|
40
31
|
return false;
|
|
41
32
|
}
|
|
@@ -78,7 +69,6 @@ function isHiddenStyle(style) {
|
|
|
78
69
|
}
|
|
79
70
|
return false;
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
function isHiddenElement(node) {
|
|
83
73
|
const attribs = node.attribs || {};
|
|
84
74
|
const style = attribs.style || '';
|
|
@@ -88,14 +78,12 @@ function isHiddenElement(node) {
|
|
|
88
78
|
}
|
|
89
79
|
return isHiddenStyle(style);
|
|
90
80
|
}
|
|
91
|
-
|
|
92
81
|
function hasText(node) {
|
|
93
82
|
if (isText(node)) {
|
|
94
83
|
return /\S/.test(node.data || '');
|
|
95
84
|
}
|
|
96
85
|
return hasChildren(node) && node.children.some(hasText);
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
function stripHidden(node, stats) {
|
|
100
88
|
if (!hasChildren(node)) {
|
|
101
89
|
return;
|
|
@@ -130,7 +118,6 @@ function stripHidden(node, stats) {
|
|
|
130
118
|
stripHidden(child, stats);
|
|
131
119
|
}
|
|
132
120
|
}
|
|
133
|
-
|
|
134
121
|
// What the reader takes as the link: its text, and the alt and title of an image standing in
|
|
135
122
|
// for it
|
|
136
123
|
function linkText(node) {
|
|
@@ -140,22 +127,10 @@ function linkText(node) {
|
|
|
140
127
|
}
|
|
141
128
|
return truncate(parts.join(' ').replace(/\s+/g, ' ').trim(), MAX_LINK_TEXT_LENGTH);
|
|
142
129
|
}
|
|
143
|
-
|
|
144
130
|
function collectLinks(document) {
|
|
145
|
-
const targets = findAll(
|
|
146
|
-
node => ((node.name === 'a' || node.name === 'area') && !!node.attribs.href) || (node.name === 'form' && !!node.attribs.action),
|
|
147
|
-
document.children
|
|
148
|
-
);
|
|
131
|
+
const targets = findAll(node => ((node.name === 'a' || node.name === 'area') && !!node.attribs.href) || (node.name === 'form' && !!node.attribs.action), document.children);
|
|
149
132
|
return targets.map(node => ({ href: node.attribs.href || node.attribs.action, text: linkText(node) }));
|
|
150
133
|
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Parses an HTML message once: every link it carries, for the checks, and the document as the
|
|
154
|
-
* reader sees it, for the model
|
|
155
|
-
*
|
|
156
|
-
* @param {string} html
|
|
157
|
-
* @returns {{links: Array<{href: string, text: string}>, hiddenElements: number, invisibleCharacters: number, html: Function}} The links, how many styled-away elements carrying text were dropped, how many invisible characters, and the visible HTML as a function, serialised only when asked for
|
|
158
|
-
*/
|
|
159
134
|
// A browser shows flow content a message put inside <head>, the converter reads only <body>:
|
|
160
135
|
// what is left of the head after the metadata went moves to the front of the body
|
|
161
136
|
function surfaceHead(document) {
|
|
@@ -173,7 +148,10 @@ function surfaceHead(document) {
|
|
|
173
148
|
}
|
|
174
149
|
removeElement(head);
|
|
175
150
|
}
|
|
176
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Parses an HTML message once: every link it carries, for the checks, and the document as the
|
|
153
|
+
* reader sees it, for the model
|
|
154
|
+
*/
|
|
177
155
|
function visibleHtml(html) {
|
|
178
156
|
const document = parseDocument(truncate(html, MAX_HTML_LENGTH).replace(CONDITIONAL_COMMENT, ''));
|
|
179
157
|
const links = collectLinks(document);
|
|
@@ -182,17 +160,13 @@ function visibleHtml(html) {
|
|
|
182
160
|
surfaceHead(document);
|
|
183
161
|
return { links, hiddenElements: stats.hiddenElements, invisibleCharacters: stats.invisibleCharacters, html: () => serialize(document) };
|
|
184
162
|
}
|
|
185
|
-
|
|
186
163
|
/**
|
|
187
164
|
* Removes the characters that take no space on screen
|
|
188
165
|
*
|
|
189
|
-
* @param {string} text
|
|
190
|
-
* @returns {{text: string, invisibleCharacters: number}}
|
|
191
166
|
*/
|
|
192
|
-
function visibleText(
|
|
193
|
-
text = String(
|
|
167
|
+
function visibleText(input) {
|
|
168
|
+
const text = String(input ?? '');
|
|
194
169
|
const matches = text.match(INVISIBLE_CHARS);
|
|
195
170
|
return { text: matches ? text.replace(INVISIBLE_CHARS, '') : text, invisibleCharacters: matches ? matches.length : 0 };
|
|
196
171
|
}
|
|
197
|
-
|
|
198
|
-
module.exports = { visibleHtml, visibleText, INVISIBLE_CHARS, MAX_HTML_LENGTH, MAX_LINK_TEXT_LENGTH };
|
|
172
|
+
export { visibleHtml, visibleText, INVISIBLE_CHARS, MAX_HTML_LENGTH, MAX_LINK_TEXT_LENGTH };
|
package/package.json
CHANGED
|
@@ -1,17 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postalsys/email-ai-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Summarize and risk-score email messages with an OpenAI-compatible chat model",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"types": "./dist/cjs/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
"*": {
|
|
10
|
+
"lib/*": [
|
|
11
|
+
"dist/cjs/lib/*"
|
|
12
|
+
],
|
|
13
|
+
"index": [
|
|
14
|
+
"dist/cjs/index.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"index.js": [
|
|
17
|
+
"dist/cjs/index.d.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/esm/index.js",
|
|
24
|
+
"require": "./dist/cjs/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./index": {
|
|
27
|
+
"import": "./dist/esm/index.js",
|
|
28
|
+
"require": "./dist/cjs/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./index.js": {
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"require": "./dist/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./lib/*.js": {
|
|
35
|
+
"import": "./dist/esm/lib/*.js",
|
|
36
|
+
"require": "./dist/cjs/lib/*.js"
|
|
37
|
+
},
|
|
38
|
+
"./lib/*": {
|
|
39
|
+
"import": "./dist/esm/lib/*.js",
|
|
40
|
+
"require": "./dist/cjs/lib/*.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"CHANGELOG.md",
|
|
49
|
+
"SECURITY.md"
|
|
50
|
+
],
|
|
6
51
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
52
|
+
"build": "node scripts/build.js",
|
|
53
|
+
"typecheck": "node scripts/build.js --generate-only && tsc -p tsconfig.json",
|
|
54
|
+
"pretest": "npm run build",
|
|
55
|
+
"test": "node --test test/*.test.cjs test/package/*.test.cjs test/package/*.test.mjs",
|
|
56
|
+
"pretest:coverage": "npm run build",
|
|
57
|
+
"test:coverage": "c8 node --test test/*.test.cjs test/package/*.test.cjs test/package/*.test.mjs",
|
|
58
|
+
"pretest:cjs": "npm run build",
|
|
59
|
+
"test:cjs": "NODE_OPTIONS=--no-experimental-require-module node --test test/*.test.cjs test/package/*.test.cjs",
|
|
60
|
+
"lint": "npm run typecheck && eslint .",
|
|
10
61
|
"lint:fix": "eslint . --fix",
|
|
11
62
|
"format": "prettier --write .",
|
|
12
63
|
"format:check": "prettier --check .",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
64
|
+
"prepare": "npm run build",
|
|
65
|
+
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
|
|
15
66
|
},
|
|
16
67
|
"repository": {
|
|
17
68
|
"type": "git",
|
|
@@ -25,16 +76,18 @@
|
|
|
25
76
|
},
|
|
26
77
|
"homepage": "https://github.com/postalsys/email-ai-tools#readme",
|
|
27
78
|
"devDependencies": {
|
|
28
|
-
"@
|
|
79
|
+
"@types/node": "20.19.43",
|
|
29
80
|
"c8": "12.0.0",
|
|
30
81
|
"eslint": "10.13.0",
|
|
31
82
|
"eslint-config-prettier": "10.1.8",
|
|
32
83
|
"globals": "17.13.0",
|
|
33
84
|
"mailparser": "3.9.47",
|
|
34
|
-
"prettier": "3.9.10"
|
|
85
|
+
"prettier": "3.9.10",
|
|
86
|
+
"typescript": "6.0.3",
|
|
87
|
+
"typescript-eslint": "8.71.2"
|
|
35
88
|
},
|
|
36
89
|
"dependencies": {
|
|
37
|
-
"@postalsys/email-text-tools": "2.
|
|
90
|
+
"@postalsys/email-text-tools": "2.5.0",
|
|
38
91
|
"dom-serializer": "2.0.0",
|
|
39
92
|
"domutils": "3.2.2",
|
|
40
93
|
"htmlparser2": "10.1.0",
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
name: '@postalsys/email-ai-tools security vulnerability report'
|
|
2
|
-
description: 'Report an exploitable security vulnerability in @postalsys/email-ai-tools'
|
|
3
|
-
|
|
4
|
-
body:
|
|
5
|
-
- type: markdown
|
|
6
|
-
attributes:
|
|
7
|
-
value: |
|
|
8
|
-
Before reporting, read our
|
|
9
|
-
[Security Policy](https://github.com/postalsys/email-ai-tools/security/policy).
|
|
10
|
-
|
|
11
|
-
Reports must demonstrate a credible security impact.
|
|
12
|
-
Technically valid bugs without a realistic attack
|
|
13
|
-
scenario belong in the regular issue tracker.
|
|
14
|
-
|
|
15
|
-
- type: textarea
|
|
16
|
-
id: summary
|
|
17
|
-
attributes:
|
|
18
|
-
label: Vulnerability summary
|
|
19
|
-
description: Describe the vulnerability and affected versions.
|
|
20
|
-
validations:
|
|
21
|
-
required: true
|
|
22
|
-
|
|
23
|
-
- type: textarea
|
|
24
|
-
id: attacker
|
|
25
|
-
attributes:
|
|
26
|
-
label: Attacker capabilities
|
|
27
|
-
description: |
|
|
28
|
-
What can an attacker control without already having
|
|
29
|
-
privileged access to the application or its configuration?
|
|
30
|
-
validations:
|
|
31
|
-
required: true
|
|
32
|
-
min_length: 100
|
|
33
|
-
|
|
34
|
-
- type: textarea
|
|
35
|
-
id: exploit
|
|
36
|
-
attributes:
|
|
37
|
-
label: Realistic exploitation scenario
|
|
38
|
-
description: |
|
|
39
|
-
Describe how this can be exploited in a real application.
|
|
40
|
-
Explain the prerequisites and security boundary crossed.
|
|
41
|
-
validations:
|
|
42
|
-
required: true
|
|
43
|
-
min_length: 150
|
|
44
|
-
|
|
45
|
-
- type: textarea
|
|
46
|
-
id: poc
|
|
47
|
-
attributes:
|
|
48
|
-
label: Proof of concept
|
|
49
|
-
description: Provide reproducible steps or working code.
|
|
50
|
-
validations:
|
|
51
|
-
required: true
|
|
52
|
-
|
|
53
|
-
- type: textarea
|
|
54
|
-
id: impact
|
|
55
|
-
attributes:
|
|
56
|
-
label: Security impact
|
|
57
|
-
description: |
|
|
58
|
-
What can the attacker achieve? Who is affected?
|
|
59
|
-
Explain why this is a security vulnerability rather
|
|
60
|
-
than an ordinary bug.
|
|
61
|
-
validations:
|
|
62
|
-
required: true
|
|
63
|
-
min_length: 100
|
|
64
|
-
|
|
65
|
-
- type: checkboxes
|
|
66
|
-
id: confirmation
|
|
67
|
-
attributes:
|
|
68
|
-
label: Reporting requirements
|
|
69
|
-
options:
|
|
70
|
-
- label: I have read the Security Policy.
|
|
71
|
-
required: true
|
|
72
|
-
- label: I have verified the finding against a supported version.
|
|
73
|
-
required: true
|
|
74
|
-
- label: I have described a credible attacker-controlled scenario.
|
|
75
|
-
required: true
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
on:
|
|
2
|
-
push:
|
|
3
|
-
branches:
|
|
4
|
-
- master
|
|
5
|
-
|
|
6
|
-
permissions:
|
|
7
|
-
contents: write
|
|
8
|
-
pull-requests: write
|
|
9
|
-
issues: write
|
|
10
|
-
id-token: write
|
|
11
|
-
|
|
12
|
-
name: release
|
|
13
|
-
jobs:
|
|
14
|
-
release-please:
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
outputs:
|
|
17
|
-
release_created: ${{ steps.release.outputs.release_created }}
|
|
18
|
-
steps:
|
|
19
|
-
- uses: googleapis/release-please-action@v5
|
|
20
|
-
id: release
|
|
21
|
-
|
|
22
|
-
publish:
|
|
23
|
-
needs: release-please
|
|
24
|
-
if: ${{ needs.release-please.outputs.release_created }}
|
|
25
|
-
runs-on: ubuntu-latest
|
|
26
|
-
permissions:
|
|
27
|
-
contents: read
|
|
28
|
-
id-token: write
|
|
29
|
-
steps:
|
|
30
|
-
- uses: actions/checkout@v7
|
|
31
|
-
- uses: actions/setup-node@v7
|
|
32
|
-
with:
|
|
33
|
-
node-version: 24
|
|
34
|
-
registry-url: 'https://registry.npmjs.org'
|
|
35
|
-
package-manager-cache: false
|
|
36
|
-
- run: npm ci
|
|
37
|
-
- run: npm publish --provenance --access public
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
name: Tests
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [master]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [master]
|
|
8
|
-
|
|
9
|
-
permissions:
|
|
10
|
-
contents: read
|
|
11
|
-
|
|
12
|
-
concurrency:
|
|
13
|
-
group: ${{ github.workflow }}-${{ github.ref }}
|
|
14
|
-
cancel-in-progress: true
|
|
15
|
-
|
|
16
|
-
jobs:
|
|
17
|
-
test:
|
|
18
|
-
runs-on: ubuntu-latest
|
|
19
|
-
timeout-minutes: 10
|
|
20
|
-
strategy:
|
|
21
|
-
matrix:
|
|
22
|
-
node-version: [20.x, 22.x, 24.x, latest]
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v7
|
|
25
|
-
- uses: actions/setup-node@v7
|
|
26
|
-
with:
|
|
27
|
-
node-version: ${{ matrix.node-version }}
|
|
28
|
-
cache: npm
|
|
29
|
-
- run: npm ci
|
|
30
|
-
- run: npm run lint
|
|
31
|
-
- run: npm run format:check
|
|
32
|
-
- run: npm test
|
|
33
|
-
- name: CommonJS dependency graph (require(esm) disabled)
|
|
34
|
-
if: matrix.node-version != '20.x'
|
|
35
|
-
run: npm run test:cjs
|
package/.ncurc.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
upgrade: true,
|
|
5
|
-
// undici 8.x requires Node 22.19+ and crashes at require() on Node 20; stay on
|
|
6
|
-
// the latest 7.x (CommonJS, Node 20+) so security patches still flow through.
|
|
7
|
-
target: name => (name === 'undici' ? 'minor' : 'latest'),
|
|
8
|
-
reject: [
|
|
9
|
-
// Block package upgrades that moved to ESM
|
|
10
|
-
'nanoid',
|
|
11
|
-
// htmlparser2 11+, domutils 4+ and dom-serializer 3+ are "type": "module" and load only
|
|
12
|
-
// through require(esm), which pkg cannot bundle and Node 20 does not have. The last
|
|
13
|
-
// CommonJS builds are 10.x, 3.x and 2.x
|
|
14
|
-
'htmlparser2',
|
|
15
|
-
'domutils',
|
|
16
|
-
'dom-serializer',
|
|
17
|
-
// @asamuzakjp/css-color >=4.1.2 pulls in @csstools/* which are pure ESM, so require(jsdom) fails
|
|
18
|
-
// without require(esm) (email-text-tools -> jsdom -> cssstyle -> @asamuzakjp/css-color). Held at
|
|
19
|
-
// 4.1.1 through package.json "overrides"; overrides do not propagate to consumers, EmailEngine
|
|
20
|
-
// carries its own.
|
|
21
|
-
'@asamuzakjp/css-color'
|
|
22
|
-
]
|
|
23
|
-
};
|
package/.prettierignore
DELETED
package/.prettierrc.js
DELETED