@jini-ai/platform 0.7.1 → 0.7.3-next.1
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 +2 -2
- package/README.md +16 -4
- package/dist/asset-cache.d.ts +13 -3
- package/dist/asset-cache.js +163 -154
- package/dist/blob-storage.d.ts +3 -32
- package/dist/blob-storage.js +1 -9
- package/dist/child-environment.d.ts +0 -16
- package/dist/child-environment.js +0 -25
- package/dist/command.d.ts +6 -11
- package/dist/command.js +8 -54
- package/dist/download-lock.d.ts +4 -0
- package/dist/download-lock.js +82 -0
- package/dist/download-maintenance.d.ts +5 -0
- package/dist/download-maintenance.js +82 -0
- package/dist/download-state.d.ts +8 -0
- package/dist/download-state.js +126 -0
- package/dist/download-store.d.ts +22 -0
- package/dist/download-store.js +174 -0
- package/dist/download-target.d.ts +10 -0
- package/dist/download-target.js +102 -0
- package/dist/download-transfer.d.ts +12 -0
- package/dist/download-transfer.js +174 -0
- package/dist/download-types.d.ts +162 -0
- package/dist/download-types.js +31 -0
- package/dist/download.d.ts +1 -89
- package/dist/download.js +8 -738
- package/dist/fetch-with-timeout.d.ts +7 -32
- package/dist/fetch-with-timeout.js +1 -77
- package/dist/fs/app-data-root.d.ts +28 -0
- package/dist/fs/app-data-root.js +35 -0
- package/dist/fs/atomic-write.js +1 -1
- package/dist/fs/boot-identity.d.ts +1 -4
- package/dist/fs/directory-delete-guard.d.ts +93 -0
- package/dist/fs/directory-delete-guard.js +148 -0
- package/dist/fs/directory-registry.js +45 -35
- package/dist/fs/directory-relocation.d.ts +82 -0
- package/dist/fs/directory-relocation.js +99 -0
- package/dist/fs/directory-running-lock.d.ts +1 -1
- package/dist/fs/directory-running-lock.js +24 -21
- package/dist/fs/directory-sync.js +1 -1
- package/dist/fs/directory-user-config.js +30 -3
- package/dist/fs/directory-workspace.d.ts +34 -30
- package/dist/fs/directory-workspace.js +70 -29
- package/dist/fs/durable-json.d.ts +6 -15
- package/dist/fs/durable-json.js +38 -35
- package/dist/fs/errno.d.ts +12 -3
- package/dist/fs/errno.js +5 -3
- package/dist/fs/file-lock.d.ts +3 -87
- package/dist/fs/file-lock.js +16 -30
- package/dist/fs/guarded-reader.js +335 -315
- package/dist/fs/index.d.ts +5 -0
- package/dist/fs/index.js +5 -0
- package/dist/fs/recent-directories.d.ts +46 -0
- package/dist/fs/recent-directories.js +68 -0
- package/dist/fs/remove-directory-tree.d.ts +20 -0
- package/dist/fs/remove-directory-tree.js +28 -0
- package/dist/fs/user-data-directories.js +2 -2
- package/dist/fs/workspace-directory.js +2 -1
- package/dist/fs.d.ts +16 -4
- package/dist/fs.js +4 -4
- package/dist/home-expansion.d.ts +7 -2
- package/dist/home-expansion.js +3 -3
- package/dist/http/guarded/client.d.ts +1 -2
- package/dist/http/guarded/client.js +2 -1
- package/dist/http/guarded/index.d.ts +0 -3
- package/dist/http/guarded/node-ports.d.ts +1 -1
- package/dist/http/guarded/transport.fetch.d.ts +2 -3
- package/dist/http/guarded/transport.fetch.js +64 -58
- package/dist/http.d.ts +3 -1
- package/dist/http.js +2 -2
- package/dist/index.d.ts +10 -11
- package/dist/index.js +7 -6
- package/dist/mail/activity/activity.d.ts +136 -0
- package/dist/mail/activity/activity.js +172 -0
- package/dist/mail/activity/ports.d.ts +113 -0
- package/dist/mail/activity/suppressions.d.ts +82 -0
- package/dist/mail/activity/suppressions.js +119 -0
- package/dist/mail/activity/vocabulary.d.ts +10 -0
- package/dist/mail/activity/vocabulary.js +8 -0
- package/dist/mail/builtin-providers.d.ts +12 -6
- package/dist/mail/builtin-providers.js +14 -11
- package/dist/mail/delivery-wrapper.js +2 -1
- package/dist/mail/email-sender-registry.d.ts +1 -1
- package/dist/mail/email-sender-registry.js +1 -1
- package/dist/mail/email-template-operations.d.ts +186 -0
- package/dist/mail/email-template-operations.js +226 -0
- package/dist/mail/email-template.d.ts +120 -0
- package/dist/mail/email-template.js +243 -0
- package/dist/mail/index.d.ts +4 -0
- package/dist/mail/index.js +3 -0
- package/dist/mail/prepare-sender-email.d.ts +1 -10
- package/dist/mail/prepare-sender-email.js +1 -11
- package/dist/mail/resolve-mailer.d.ts +2 -1
- package/dist/mail/resolve-mailer.js +5 -2
- package/dist/mail/senders.d.ts +0 -1
- package/dist/mail/senders.js +0 -1
- package/dist/mail/smtp.d.ts +1 -31
- package/dist/net/address.d.ts +1 -8
- package/dist/net/address.js +1 -18
- package/dist/net/index.d.ts +1 -1
- package/dist/net/index.js +1 -1
- package/dist/net/local-http-probe.js +1 -1
- package/dist/net/local-http-request.js +1 -1
- package/dist/process-probes.d.ts +36 -0
- package/dist/process-probes.js +151 -0
- package/dist/process-top-footprint.d.ts +7 -0
- package/dist/process-top-footprint.js +30 -0
- package/dist/process.d.ts +29 -31
- package/dist/process.js +18 -196
- package/dist/proxy-env.d.ts +12 -3
- package/dist/proxy-env.js +9 -8
- package/dist/resource-paths.d.ts +15 -3
- package/dist/resource-paths.js +7 -5
- package/dist/sandbox-env.d.ts +26 -5
- package/dist/sandbox-env.js +7 -7
- package/dist/secrets/credential-sets/contracts.d.ts +0 -1
- package/dist/secrets/credential-sets/contracts.js +0 -1
- package/dist/secrets/credential-sets/index.d.ts +2 -3
- package/dist/secrets/credential-sets/index.js +1 -1
- package/dist/secrets/credential-sets/provider-matches.d.ts +1 -1
- package/dist/secrets/credential-sets/provider-matches.js +1 -1
- package/dist/secrets/credential-sets/vault-archive.d.ts +1 -1
- package/dist/secrets/credential-sets/vault-archive.js +14 -8
- package/dist/secrets/credential-sets/vault.aad.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.meta.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.meta.js +1 -1
- package/dist/secrets/credential-sets/vault.repo.memory.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.repo.memory.js +1 -1
- package/dist/secrets/credential-sets/vault.reseal-refused.d.ts +23 -0
- package/dist/secrets/credential-sets/vault.reseal-refused.js +36 -0
- package/dist/secrets/credential-sets/vault.service.d.ts +25 -5
- package/dist/secrets/credential-sets/vault.service.js +42 -8
- package/dist/secrets/index.d.ts +0 -3
- package/dist/secrets/index.js +5 -0
- package/dist/secrets/keyring.env.d.ts +1 -1
- package/dist/secrets/legacy-owner.d.ts +61 -0
- package/dist/secrets/legacy-owner.js +196 -0
- package/dist/secrets/root-key/decide.d.ts +89 -0
- package/dist/secrets/root-key/decide.js +60 -0
- package/dist/secrets/sealer-contract.d.ts +19 -0
- package/dist/secrets/sealer-contract.js +37 -0
- package/dist/secrets/secret-sealer.aesgcm.d.ts +1 -1
- package/dist/secrets/testing.d.ts +1 -0
- package/dist/secrets/testing.js +1 -0
- package/dist/shell.d.ts +4 -1
- package/dist/shell.js +1 -1
- package/dist/system.d.ts +6 -0
- package/dist/system.js +9 -0
- package/dist/terminal.d.ts +11 -96
- package/dist/terminal.js +80 -56
- package/dist/web/agent-tools.d.ts +107 -0
- package/dist/web/agent-tools.js +49 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/package.json +38 -12
- package/dist/http/guarded/ports.d.ts +0 -56
- package/dist/http/guarded/types.d.ts +0 -8
- package/dist/http/guarded/types.js +0 -2
- package/dist/mail/email-sender.d.ts +0 -109
- package/dist/mail/email-sender.js +0 -10
- package/dist/net/endpoint-policy.d.ts +0 -39
- package/dist/net/endpoint-policy.js +0 -218
- package/dist/secrets/credential-sets/vault.types.d.ts +0 -27
- package/dist/secrets/credential-sets/vault.types.js +0 -49
- /package/dist/{http/guarded → mail/activity}/ports.js +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { parse, serialize } from "parse5";
|
|
2
|
+
import { htmlToText, stripActiveHtml } from "../web/html-document.js";
|
|
3
|
+
/** The `<meta name>` a template declares its fill-in fields with. */
|
|
4
|
+
export const EMAIL_FIELDS_META_NAME = "email-fields";
|
|
5
|
+
/** `{{ name }}` — a field name is an identifier, optionally dotted or dashed. */
|
|
6
|
+
const PLACEHOLDER = /\{\{\s*([A-Za-z_][A-Za-z0-9_.-]*)\s*\}\}/g;
|
|
7
|
+
const FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
|
|
8
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
9
|
+
/** Tags a sent email never carries: embedded documents and plugins, on top of `stripActiveHtml`'s. */
|
|
10
|
+
const SEND_STRIPPED_TAGS = new Set(["iframe", "object", "embed", "frame", "frameset", "applet", "base", "form", "link"]);
|
|
11
|
+
/** Script-bearing URL schemes; tested after removing the whitespace/control characters a browser ignores. */
|
|
12
|
+
const ACTIVE_URL = /^(?:javascript|vbscript):/i;
|
|
13
|
+
/** The `{{field}}` names a string uses, de-duplicated in first-use order. */
|
|
14
|
+
export function placeholdersIn({ text }, _optional = {}) {
|
|
15
|
+
// PLACEHOLDER requires this capture; narrow it explicitly because indexed reads may be undefined.
|
|
16
|
+
const names = [...text.matchAll(PLACEHOLDER)].map((match) => match[1]).filter((name) => name !== undefined);
|
|
17
|
+
return [...new Set(names)];
|
|
18
|
+
}
|
|
19
|
+
/** Escapes a value for HTML text AND quoted-attribute context. */
|
|
20
|
+
export function escapeHtml({ value }, _optional = {}) {
|
|
21
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Replaces every `{{field}}` with its value. An unknown field renders empty — never the literal
|
|
25
|
+
* braces a recipient would see — and is reported so the caller can refuse or warn.
|
|
26
|
+
* @param required.escape - Applied to every value: {@link escapeHtml} for HTML, identity for a subject.
|
|
27
|
+
* @complexity O(n) in the text length.
|
|
28
|
+
*/
|
|
29
|
+
export function fillPlaceholders({ text, values, escape: escapeValue }, _optional = {}) {
|
|
30
|
+
const missing = new Set();
|
|
31
|
+
const filled = text.replace(PLACEHOLDER, (_match, name) => {
|
|
32
|
+
if (!Object.hasOwn(values, name)) {
|
|
33
|
+
missing.add(name);
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
// Own keys contain strings by contract; the default also makes the indexed read explicit.
|
|
37
|
+
return escapeValue({ value: values[name] ?? "" });
|
|
38
|
+
});
|
|
39
|
+
return { text: filled, missingFields: [...missing] };
|
|
40
|
+
}
|
|
41
|
+
/** One `name` or `name=sample` entry; `null` for a malformed name, which is ignored. */
|
|
42
|
+
function parseFieldEntry({ entry }, _options = {}) {
|
|
43
|
+
const separator = entry.indexOf("=");
|
|
44
|
+
const name = (separator === -1 ? entry : entry.slice(0, separator)).trim();
|
|
45
|
+
if (!FIELD_NAME.test(name))
|
|
46
|
+
return null;
|
|
47
|
+
if (separator === -1)
|
|
48
|
+
return { name };
|
|
49
|
+
return { name, sample: entry.slice(separator + 1).trim() };
|
|
50
|
+
}
|
|
51
|
+
/** The declared fields from a `content` attribute, first declaration of a name winning. */
|
|
52
|
+
export function parseFieldDeclarations({ content }, _optional = {}) {
|
|
53
|
+
const byName = new Map();
|
|
54
|
+
for (const entry of content.split(",")) {
|
|
55
|
+
const field = parseFieldEntry({ entry: entry });
|
|
56
|
+
if (field && !byName.has(field.name))
|
|
57
|
+
byName.set(field.name, field);
|
|
58
|
+
}
|
|
59
|
+
return [...byName.values()];
|
|
60
|
+
}
|
|
61
|
+
/** Writes a field list back into the `content` form {@link parseFieldDeclarations} reads. */
|
|
62
|
+
export function formatFieldDeclarations({ fields }, _optional = {}) {
|
|
63
|
+
return fields.map((field) => (field.sample === undefined ? field.name : `${field.name}=${field.sample}`)).join(", ");
|
|
64
|
+
}
|
|
65
|
+
function isElement(node) {
|
|
66
|
+
return "tagName" in node;
|
|
67
|
+
}
|
|
68
|
+
function attribute({ element, name }, _options = {}) {
|
|
69
|
+
return element.attrs.find((attr) => attr.name === name)?.value;
|
|
70
|
+
}
|
|
71
|
+
/** Every element under `root`, in document order (so "the first `<title>`" means the first one written). */
|
|
72
|
+
function* elementsIn(root, _options = {}) {
|
|
73
|
+
const pending = [root];
|
|
74
|
+
while (pending.length > 0) {
|
|
75
|
+
const node = pending.pop();
|
|
76
|
+
// Array length checks do not narrow pop() or indexed reads under the desktop config.
|
|
77
|
+
if (node === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
if (isElement(node))
|
|
80
|
+
yield node;
|
|
81
|
+
queueChildParents({ node, pending });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Reverse insertion preserves document order on the traversal's stack. */
|
|
85
|
+
function queueChildParents({ node, pending }, _options = {}) {
|
|
86
|
+
for (let i = node.childNodes.length - 1; i >= 0; i--) {
|
|
87
|
+
const child = node.childNodes[i];
|
|
88
|
+
if (child !== undefined && "childNodes" in child)
|
|
89
|
+
pending.push(child);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function textOf(element, _options = {}) {
|
|
93
|
+
return element.childNodes.map((child) => ("value" in child && child.nodeName === "#text" ? child.value : "")).join("");
|
|
94
|
+
}
|
|
95
|
+
function isFieldsMeta(element, _options = {}) {
|
|
96
|
+
return element.tagName === "meta" && attribute({ element: element, name: "name" })?.toLowerCase() === EMAIL_FIELDS_META_NAME;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads a template's subject (`<title>`) and declared fields (`<meta name="email-fields">`).
|
|
100
|
+
* @complexity O(nodes).
|
|
101
|
+
*/
|
|
102
|
+
export function readTemplateDeclarations({ html }, _optional = {}) {
|
|
103
|
+
let subject;
|
|
104
|
+
let fields = [];
|
|
105
|
+
let fieldsDeclared = false;
|
|
106
|
+
for (const element of elementsIn(parse(html))) {
|
|
107
|
+
// HTML namespace only: an inline `<svg><title>` is an image's tooltip, not the subject.
|
|
108
|
+
if (element.tagName === "title" && element.namespaceURI === HTML_NAMESPACE && subject === undefined)
|
|
109
|
+
subject = textOf(element).trim();
|
|
110
|
+
if (isFieldsMeta(element) && !fieldsDeclared) {
|
|
111
|
+
fieldsDeclared = true;
|
|
112
|
+
fields = parseFieldDeclarations({ content: attribute({ element: element, name: "content" }) ?? "" });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { subject: subject ?? "", fields };
|
|
116
|
+
}
|
|
117
|
+
/** Placeholders used in the HTML (subject included) that the template never declared. */
|
|
118
|
+
export function undeclaredFieldsIn({ html, declarations }, _optional = {}) {
|
|
119
|
+
const declared = new Set(declarations.fields.map((field) => field.name));
|
|
120
|
+
return placeholdersIn({ text: html }).filter((name) => !declared.has(name));
|
|
121
|
+
}
|
|
122
|
+
/** True when an attribute value would run script once a browser normalizes it as a URL. Tested on
|
|
123
|
+
* every attribute, not only `href`/`src`, the same breadth `stripActiveHtml` applies. */
|
|
124
|
+
function isActiveUrl({ value }, _options = {}) {
|
|
125
|
+
// Browsers drop ASCII tab/newline anywhere in a URL and leading C0 controls/space, so
|
|
126
|
+
// `java\nscript:` is still script; `stripActiveHtml`'s own test only trims leading whitespace.
|
|
127
|
+
const normalized = value.split("").filter(character => character.charCodeAt(0) > 0x20).join("");
|
|
128
|
+
return ACTIVE_URL.test(normalized) || (/^data:/i.test(normalized) && !/^data:image\/[^;,]+[;,]/i.test(normalized));
|
|
129
|
+
}
|
|
130
|
+
/** Static mail excludes navigation instructions, form submissions and external stylesheets. */
|
|
131
|
+
function stripMailElement({ child }, _optional = {}) {
|
|
132
|
+
if (!isElement(child))
|
|
133
|
+
return false;
|
|
134
|
+
if (SEND_STRIPPED_TAGS.has(child.tagName) || isFieldsMeta(child))
|
|
135
|
+
return true;
|
|
136
|
+
return child.tagName === "meta" && attribute({ element: child, name: "http-equiv" }) !== undefined;
|
|
137
|
+
}
|
|
138
|
+
/** Second, email-specific pass after `stripActiveHtml`: embeds, obfuscated script URLs, the fields meta. */
|
|
139
|
+
function stripForMail(root, _options = {}) {
|
|
140
|
+
for (const node of elementsIn(root)) {
|
|
141
|
+
node.childNodes = node.childNodes.filter((child) => !stripMailElement({ child }));
|
|
142
|
+
node.attrs = node.attrs.filter((attr) => !isActiveUrl({ value: attr.value }));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The static HTML a mail client receives: `<script>`/`<noscript>`/`<template>`, comments, inline
|
|
147
|
+
* `on*` handlers and `javascript:` URLs removed (the shared `stripActiveHtml` policy), then
|
|
148
|
+
* `<iframe>`/`<object>`/`<embed>` (and their legacy kin), obfuscated script URLs and the template's
|
|
149
|
+
* own field declarations. Navigation/form/link elements and non-image data URLs are removed.
|
|
150
|
+
* Inline styles and classes survive: email layout depends on them.
|
|
151
|
+
*
|
|
152
|
+
* Known cost: comments are removed, so Outlook `<!--[if mso]>` conditional blocks do not survive.
|
|
153
|
+
* @complexity O(nodes), two parses.
|
|
154
|
+
*/
|
|
155
|
+
export function sanitizeEmailHtml({ html }, _optional = {}) {
|
|
156
|
+
const document = parse(stripActiveHtml({ html }));
|
|
157
|
+
stripForMail(document);
|
|
158
|
+
return serialize(document);
|
|
159
|
+
}
|
|
160
|
+
/** A visible ` (url)` after a link whose text is not already its URL, so the text part keeps links. */
|
|
161
|
+
function annotateLinks(root, _options = {}) {
|
|
162
|
+
for (const element of elementsIn(root)) {
|
|
163
|
+
const href = element.tagName === "a" ? attribute({ element: element, name: "href" })?.trim() : undefined;
|
|
164
|
+
if (!href || !/^(?:https?:|mailto:)/i.test(href) || textOf(element).trim() === href)
|
|
165
|
+
continue;
|
|
166
|
+
element.childNodes.push({ nodeName: "#text", value: ` (${href.replace(/^mailto:/i, "")})`, parentNode: element });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The plain-text alternative: the shared `htmlToText` (one line per block; head, scripts and styles
|
|
171
|
+
* omitted), with each link's URL written after its text so a text-only reader can still follow it.
|
|
172
|
+
* @complexity O(nodes).
|
|
173
|
+
*/
|
|
174
|
+
export function emailHtmlToText({ html }, _optional = {}) {
|
|
175
|
+
const document = parse(html);
|
|
176
|
+
annotateLinks(document);
|
|
177
|
+
return htmlToText({ html: serialize(document) });
|
|
178
|
+
}
|
|
179
|
+
/** A subject is one header line: fill raw (it is not HTML) and fold any line break a value carried. */
|
|
180
|
+
function renderSubject({ subject, values }, _options = {}) {
|
|
181
|
+
const filled = fillPlaceholders({ text: subject, values, escape: ({ value }) => value });
|
|
182
|
+
return { text: filled.text.replace(/[\r\n]+/g, " ").trim(), missingFields: filled.missingFields };
|
|
183
|
+
}
|
|
184
|
+
function renderWith({ html, values }, _options = {}) {
|
|
185
|
+
const declarations = readTemplateDeclarations({ html });
|
|
186
|
+
const subject = renderSubject({ subject: declarations.subject, values: values });
|
|
187
|
+
const body = fillPlaceholders({ text: html, values, escape: escapeHtml });
|
|
188
|
+
return { subject: subject.text, html: body.text, missingFields: [...new Set([...subject.missingFields, ...body.missingFields])] };
|
|
189
|
+
}
|
|
190
|
+
/** The values a preview renders with: declared samples, overridden by whatever the caller gave. */
|
|
191
|
+
export function previewValues({ declarations, values }, _optional = {}) {
|
|
192
|
+
const samples = declarations.fields.flatMap((field) => (field.sample === undefined ? [] : [[field.name, field.sample]]));
|
|
193
|
+
return { ...Object.fromEntries(samples), ...values };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The preview render. Scripts are KEPT: show the result only in an iframe sandboxed without
|
|
197
|
+
* `allow-same-origin`, so they run in an opaque origin.
|
|
198
|
+
* @complexity O(n) in the template length.
|
|
199
|
+
*/
|
|
200
|
+
export function renderEmailPreview({ html, values }, _optional = {}) {
|
|
201
|
+
const declarations = readTemplateDeclarations({ html });
|
|
202
|
+
return renderWith({ html: html, values: previewValues({ declarations, values }) });
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Template + values -> the `subject`/`html`/`text` an `OutboundEmail` carries. Values are filled
|
|
206
|
+
* BEFORE sanitizing, so a value that smuggles a `javascript:` URL into an `href="{{url}}"` is
|
|
207
|
+
* removed with everything else. Samples are never used: a sent email shows only real values.
|
|
208
|
+
* @complexity O(n) in the template length.
|
|
209
|
+
*/
|
|
210
|
+
export function renderEmailForSend({ html, values }, _optional = {}) {
|
|
211
|
+
const rendered = renderWith({ html: html, values: values });
|
|
212
|
+
const safeHtml = sanitizeEmailHtml({ html: rendered.html });
|
|
213
|
+
return { subject: rendered.subject, html: safeHtml, text: emailHtmlToText({ html: safeHtml }), missingFields: rendered.missingFields };
|
|
214
|
+
}
|
|
215
|
+
/** The starter body a template is born with when its creator gives no HTML. */
|
|
216
|
+
export function emailTemplateSkeleton({ subject, fields }, _optional = {}) {
|
|
217
|
+
const meta = fields.length > 0 ? `\n<meta name="${EMAIL_FIELDS_META_NAME}" content="${escapeHtml({ value: formatFieldDeclarations({ fields }) })}">` : "";
|
|
218
|
+
// Guard the first field itself so an empty list keeps its plain greeting.
|
|
219
|
+
const firstField = fields[0];
|
|
220
|
+
const greeting = firstField === undefined ? "Hello," : `Hello {{${firstField.name}}},`;
|
|
221
|
+
return `<!doctype html>
|
|
222
|
+
<html>
|
|
223
|
+
<head>
|
|
224
|
+
<meta charset="utf-8">
|
|
225
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">${meta}
|
|
226
|
+
<title>${escapeHtml({ value: subject })}</title>
|
|
227
|
+
</head>
|
|
228
|
+
<body style="margin:0;padding:0;background:#f4f4f5;font-family:Arial,Helvetica,sans-serif;color:#18181b;">
|
|
229
|
+
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;">
|
|
230
|
+
<tr><td align="center" style="padding:24px;">
|
|
231
|
+
<table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:8px;">
|
|
232
|
+
<tr><td style="padding:32px;font-size:16px;line-height:1.5;">
|
|
233
|
+
<p>${greeting}</p>
|
|
234
|
+
<p></p>
|
|
235
|
+
</td></tr>
|
|
236
|
+
</table>
|
|
237
|
+
</td></tr>
|
|
238
|
+
</table>
|
|
239
|
+
</body>
|
|
240
|
+
</html>
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=email-template.js.map
|
package/dist/mail/index.d.ts
CHANGED
|
@@ -32,4 +32,8 @@ export * from "./senders.js";
|
|
|
32
32
|
export { defaultMailProviderSetup, parseMailProviderSetup, parseMailProviderSetupProperty } from "./provider-setup.js";
|
|
33
33
|
export * from "./plugin-abi.js";
|
|
34
34
|
export * from "./provider-mailer.js";
|
|
35
|
+
export * from "./activity/vocabulary.js";
|
|
36
|
+
export type * from "./activity/ports.js";
|
|
37
|
+
export * from "./activity/activity.js";
|
|
38
|
+
export * from "./activity/suppressions.js";
|
|
35
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mail/index.js
CHANGED
|
@@ -17,4 +17,7 @@ export * from "./senders.js";
|
|
|
17
17
|
export { defaultMailProviderSetup, parseMailProviderSetup, parseMailProviderSetupProperty } from "./provider-setup.js";
|
|
18
18
|
export * from "./plugin-abi.js";
|
|
19
19
|
export * from "./provider-mailer.js";
|
|
20
|
+
export * from "./activity/vocabulary.js";
|
|
21
|
+
export * from "./activity/activity.js";
|
|
22
|
+
export * from "./activity/suppressions.js";
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { type EmailSender, type EmailSourceDescription, type
|
|
1
|
+
import { type EmailSender, type EmailSourceDescription, type EmailSourceRequest, type EmailTemplatePort } from "@jini-ai/core/contracts/mail";
|
|
2
2
|
import type { EmailAddress } from "./types.js";
|
|
3
|
-
/** Refuses unsupported declarations and undeclared placeholders before activation or rendering.
|
|
4
|
-
* @complexity O(f + d + p) source fields, declarations and placeholders; no I/O. */
|
|
5
|
-
export declare function validateEmailSourceTemplate(required: {
|
|
6
|
-
readonly fields: readonly EmailSourceField[];
|
|
7
|
-
readonly template: {
|
|
8
|
-
readonly fields: readonly string[];
|
|
9
|
-
readonly placeholders: readonly string[];
|
|
10
|
-
};
|
|
11
|
-
}, _optional?: Record<string, never>): void;
|
|
12
3
|
/** A preparation result is suitable for freezing in the sender's existing job, never a new queue. */
|
|
13
4
|
export interface PreparedSenderEmail {
|
|
14
5
|
readonly bindingId: string;
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import { EmailSenderError } from "
|
|
2
|
-
/** Refuses unsupported declarations and undeclared placeholders before activation or rendering.
|
|
3
|
-
* @complexity O(f + d + p) source fields, declarations and placeholders; no I/O. */
|
|
4
|
-
export function validateEmailSourceTemplate(required, _optional = {}) {
|
|
5
|
-
const available = new Set(required.fields.map(field => field.token));
|
|
6
|
-
const declared = new Set(required.template.fields);
|
|
7
|
-
if (required.template.fields.some(token => !available.has(token)))
|
|
8
|
-
throw new EmailSenderError({ code: "incompatible" });
|
|
9
|
-
if (required.template.placeholders.some(token => !declared.has(token)))
|
|
10
|
-
throw new EmailSenderError({ code: "incompatible" });
|
|
11
|
-
}
|
|
1
|
+
import { EmailSenderError, validateEmailSourceTemplate } from "@jini-ai/core/contracts/mail";
|
|
12
2
|
/** Selects declared values, refusing missing required answers and warning on absent optional ones. */
|
|
13
3
|
function templateValues(required, _optional = {}) {
|
|
14
4
|
const fields = new Map(required.fields.map(field => [field.token, field]));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HttpClientPort, type Logger } from "@jini-ai/core/primitives";
|
|
2
2
|
import type { DomainRequirement } from "@jini-ai/core/provider-registry";
|
|
3
3
|
import type { MailAdapterCredential } from "./adapter-module.js";
|
|
4
4
|
import { type MailDomainReadCredentialPort } from "./domain-read.js";
|
|
@@ -48,6 +48,7 @@ export interface ResolveMailerOptions {
|
|
|
48
48
|
readSenderEmail?: () => Promise<string | undefined>;
|
|
49
49
|
resolveDomainReadCredential?: MailDomainReadCredentialPort;
|
|
50
50
|
warn?: (message: string) => void;
|
|
51
|
+
report?: Pick<Logger, 'error'>;
|
|
51
52
|
clock?: {
|
|
52
53
|
nowMs(): number;
|
|
53
54
|
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* sends always await their own lane. Invalidation detaches obsolete work without cancelling it.
|
|
7
7
|
*/
|
|
8
8
|
import { ToolInputError } from "@jini-ai/core";
|
|
9
|
+
import { createConsoleLogger } from "@jini-ai/core/primitives";
|
|
9
10
|
import { readMailDomain } from "./domain-read.js";
|
|
10
11
|
import { createTtlCache, MAIL_STATUS_TTL_MS } from "./mail-status-cache.js";
|
|
11
12
|
import { credentialSecrets, safeMailProviderText } from "./provider-error.js";
|
|
@@ -262,7 +263,9 @@ async function laneCredentials(required) {
|
|
|
262
263
|
/** Row-list faults affect presence facts but do not prevent independent key resolution. */
|
|
263
264
|
function statusCredentialFacts({ state, deps }) {
|
|
264
265
|
return deps.listCredentialFacts({}).catch((err) => {
|
|
265
|
-
|
|
266
|
+
const logger = state.options.report ?? createConsoleLogger({ prefix: '' });
|
|
267
|
+
logger.error({ message: '[mail] the saved mail credentials could not be listed' }, { error: err });
|
|
268
|
+
recordError({ state, error: { providerId: null, source: "check", message: 'The saved mail credentials could not be listed.' } });
|
|
266
269
|
return [];
|
|
267
270
|
});
|
|
268
271
|
}
|
|
@@ -326,7 +329,7 @@ function invalidate(state) {
|
|
|
326
329
|
*/
|
|
327
330
|
export function createResolvedMailer(required, optional = {}) {
|
|
328
331
|
const state = { deps: required, options: optional, nowMs: () => (optional.clock ?? { nowMs: () => Date.now() }).nowMs(),
|
|
329
|
-
warn: optional.warn ?? (message =>
|
|
332
|
+
warn: optional.warn ?? (message => createConsoleLogger({ prefix: '' }).warn({ message })),
|
|
330
333
|
wrap: optional.wrapProviderMailer ?? (({ mailer }) => mailer), resolved: new Map(), inFlight: new Map(), warned: new Set(), generation: 0,
|
|
331
334
|
initialization: undefined, lastTransactional: undefined, lastError: undefined };
|
|
332
335
|
const ready = forLane({ state, lane: "transactional" }).then(() => undefined);
|
package/dist/mail/senders.d.ts
CHANGED
package/dist/mail/senders.js
CHANGED
package/dist/mail/smtp.d.ts
CHANGED
|
@@ -1,38 +1,8 @@
|
|
|
1
1
|
/** SMTP adapter over an injected transport and clock; no SMTP vendor is loaded by core. */
|
|
2
2
|
import { type Clock as ClockPort } from "@jini-ai/core/primitives";
|
|
3
|
+
import type { SmtpTransport, SmtpMailPayload } from "@jini-ai/core/contracts/mail";
|
|
3
4
|
import type { MailerPort } from "./ports.js";
|
|
4
5
|
import type { MailerCapabilities, MailerSendResult, MailerSendRequired, MailerBatchRequired, MailerOptional } from "./types.js";
|
|
5
|
-
export interface SmtpTransport {
|
|
6
|
-
sendMail(required: {
|
|
7
|
-
mail: SmtpMailPayload;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
messageId: string;
|
|
10
|
-
}>;
|
|
11
|
-
}
|
|
12
|
-
export interface SmtpMailPayload {
|
|
13
|
-
from: {
|
|
14
|
-
name?: string;
|
|
15
|
-
address: string;
|
|
16
|
-
};
|
|
17
|
-
to: {
|
|
18
|
-
name?: string;
|
|
19
|
-
address: string;
|
|
20
|
-
};
|
|
21
|
-
replyTo?: {
|
|
22
|
-
name?: string;
|
|
23
|
-
address: string;
|
|
24
|
-
};
|
|
25
|
-
subject: string;
|
|
26
|
-
html?: string;
|
|
27
|
-
text?: string;
|
|
28
|
-
headers?: Readonly<Record<string, string>>;
|
|
29
|
-
attachments?: {
|
|
30
|
-
filename: string;
|
|
31
|
-
content: string;
|
|
32
|
-
encoding: "base64";
|
|
33
|
-
contentType: string;
|
|
34
|
-
}[];
|
|
35
|
-
}
|
|
36
6
|
export declare class SmtpMailerAdapter implements MailerPort {
|
|
37
7
|
private readonly clock;
|
|
38
8
|
private readonly transport;
|
package/dist/net/address.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { type AddressClass } from '
|
|
2
|
-
export { expandIpv6 } from './endpoint-policy.js';
|
|
3
|
-
export type { AddressClass } from './endpoint-policy.js';
|
|
1
|
+
import { type AddressClass } from '@jini-ai/core/net';
|
|
4
2
|
/** Strict Node peer classification; invalid literals fail closed to reserved. */
|
|
5
3
|
export declare function classifyIpAddress({ ip }: {
|
|
6
4
|
ip: string;
|
|
@@ -9,9 +7,4 @@ export declare function classifyIpAddress({ ip }: {
|
|
|
9
7
|
export declare function isPrivateAddress({ address }: {
|
|
10
8
|
address: string;
|
|
11
9
|
}): boolean;
|
|
12
|
-
export { isLoopbackApiHost, isBlockedExternalApiHostname } from './endpoint-policy.js';
|
|
13
|
-
/** True when `hostname` is `localhost`, an IPv6 loopback literal, or a `127.0.0.0/8` IPv4 literal. */
|
|
14
|
-
export declare function isLoopbackHostname({ hostname }: {
|
|
15
|
-
readonly hostname: unknown;
|
|
16
|
-
}, _optional?: Record<string, never>): boolean;
|
|
17
10
|
//# sourceMappingURL=address.d.ts.map
|
package/dist/net/address.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isIP } from 'node:net';
|
|
2
|
-
import { classifyAddressLiteral } from '
|
|
2
|
+
import { classifyAddressLiteral } from '@jini-ai/core/net';
|
|
3
3
|
// SSRF peer classification is distinct from core's browser-development LAN origin allow-list.
|
|
4
|
-
export { expandIpv6 } from './endpoint-policy.js';
|
|
5
4
|
/** Strict Node peer classification; invalid literals fail closed to reserved. */
|
|
6
5
|
export function classifyIpAddress({ ip }, _options = {}) {
|
|
7
6
|
// `net.isIP(ip) === 4` already guarantees `ip` is a syntactically
|
|
@@ -30,20 +29,4 @@ export function classifyIpAddress({ ip }, _options = {}) {
|
|
|
30
29
|
export function isPrivateAddress({ address }) {
|
|
31
30
|
return classifyIpAddress({ ip: address }) !== 'public';
|
|
32
31
|
}
|
|
33
|
-
// Preserve the Node entry's published names while sharing the literal-host owner with browser consumers.
|
|
34
|
-
export { isLoopbackApiHost, isBlockedExternalApiHostname } from './endpoint-policy.js';
|
|
35
|
-
/** True when `hostname` is `localhost`, an IPv6 loopback literal, or a `127.0.0.0/8` IPv4 literal. */
|
|
36
|
-
export function isLoopbackHostname({ hostname }, _optional = {}) {
|
|
37
|
-
const normalized = String(hostname || '')
|
|
38
|
-
.toLowerCase()
|
|
39
|
-
.replace(/^\[|\]$/g, '')
|
|
40
|
-
.replace(/\.$/, '');
|
|
41
|
-
if (normalized === 'localhost')
|
|
42
|
-
return true;
|
|
43
|
-
if (normalized === '::1' || normalized === '0:0:0:0:0:0:0:1')
|
|
44
|
-
return true;
|
|
45
|
-
if (isIP(normalized) === 4)
|
|
46
|
-
return normalized === '127.0.0.1' || normalized.startsWith('127.');
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
32
|
//# sourceMappingURL=address.js.map
|
package/dist/net/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { isPrivateAddress
|
|
1
|
+
export { isPrivateAddress } from "./address.js";
|
|
2
2
|
export { probeLoopbackHttp } from './local-http-probe.js';
|
|
3
3
|
export { requestLoopbackHttp } from './local-http-request.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/net/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { isPrivateAddress
|
|
1
|
+
export { isPrivateAddress } from "./address.js";
|
|
2
2
|
export { probeLoopbackHttp } from './local-http-probe.js';
|
|
3
3
|
export { requestLoopbackHttp } from './local-http-request.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { X509Certificate } from 'node:crypto';
|
|
2
2
|
import { get as httpGet } from 'node:http';
|
|
3
3
|
import { get as httpsGet } from 'node:https';
|
|
4
|
-
import { isLoopbackHostname } from '
|
|
4
|
+
import { isLoopbackHostname } from '@jini-ai/core/net';
|
|
5
5
|
/**
|
|
6
6
|
* Probe a loopback service once, accepting only HTTP 200 without following redirects.
|
|
7
7
|
* @param required Absolute HTTP(S) URL. Non-loopback targets are refused before connecting.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { X509Certificate } from 'node:crypto';
|
|
2
2
|
import { request as httpRequest } from 'node:http';
|
|
3
3
|
import { request as httpsRequest } from 'node:https';
|
|
4
|
-
import { isLoopbackHostname } from '
|
|
4
|
+
import { isLoopbackHostname } from '@jini-ai/core/net';
|
|
5
5
|
/** Bounded private local-control request, with the same pinned-leaf TLS policy as local probes.
|
|
6
6
|
* Never follows redirects, resolves DNS, logs payloads, or permits remote credentials.
|
|
7
7
|
* @returns Status, content type and bounded response bytes. Transport/size/deadline errors reject.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProcessSnapshot } from "@jini-ai/core/contracts/runtime";
|
|
2
|
+
import { execFileBuffered } from "./shell.js";
|
|
3
|
+
import type { ProcessUsage, ProcessUsagePorts, ProcessUsageOptions } from "./process.js";
|
|
4
|
+
/** @internal Enumerate process snapshots on POSIX via `ps`. */
|
|
5
|
+
export declare function listPosixProcessSnapshots(input: ProcessUsagePorts, options: ProcessUsageOptions & {
|
|
6
|
+
commandLines?: boolean;
|
|
7
|
+
}): Promise<ProcessSnapshot[]>;
|
|
8
|
+
/** @internal Enumerate process snapshots on Windows via `Get-CimInstance Win32_Process` JSON. */
|
|
9
|
+
export declare function listWindowsProcessSnapshots(input: ProcessUsagePorts, options: ProcessUsageOptions & {
|
|
10
|
+
commandLines?: boolean;
|
|
11
|
+
}): Promise<ProcessSnapshot[]>;
|
|
12
|
+
/** @internal Read only comm, never args/command, so credentials cannot enter the result. */
|
|
13
|
+
export declare function parsePsUsage(stdout: string): ProcessUsage[];
|
|
14
|
+
/** @internal Convert Windows 100ns CPU counters and retain nameless process rows. */
|
|
15
|
+
export declare function parseCimUsage(stdout: string): ProcessUsage[];
|
|
16
|
+
/** @internal Fixed executable and argv, invoked directly without a command shell. */
|
|
17
|
+
export declare function processUsageCommand(windows: boolean): {
|
|
18
|
+
command: string;
|
|
19
|
+
args: string[];
|
|
20
|
+
};
|
|
21
|
+
/** @internal One bounded read-only OS probe; partial output on failure is discarded. */
|
|
22
|
+
export declare function processProbeOutput(input: {
|
|
23
|
+
command: string;
|
|
24
|
+
args: string[];
|
|
25
|
+
run: typeof execFileBuffered;
|
|
26
|
+
}, options: ProcessUsageOptions): Promise<string | null>;
|
|
27
|
+
/** @internal Performance instance names can reorder (node, node#1); only IDProcess is identity. */
|
|
28
|
+
export declare function parsePrivateWorkingSets({ stdout }: {
|
|
29
|
+
stdout: string | null;
|
|
30
|
+
}): Map<number, number | null>;
|
|
31
|
+
/** @internal Reject invalid identities and oversized collections before making any OS calls. */
|
|
32
|
+
export declare function assertPrivateMemorySample({ pids, maxPids }: {
|
|
33
|
+
pids: number[];
|
|
34
|
+
maxPids: number;
|
|
35
|
+
}): void;
|
|
36
|
+
//# sourceMappingURL=process-probes.d.ts.map
|