@gadicc/loom 1.18.0 → 1.19.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/README.md +60 -2
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +10 -1
- package/esm/src/jobs/controller.d.ts +14 -1
- package/esm/src/jobs/controller.d.ts.map +1 -1
- package/esm/src/jobs/controller.js +54 -3
- package/esm/src/jobs/events.d.ts +9 -1
- package/esm/src/jobs/events.d.ts.map +1 -1
- package/esm/src/jobs/events.js +15 -2
- package/esm/src/jobs/mod.d.ts +1 -0
- package/esm/src/jobs/mod.d.ts.map +1 -1
- package/esm/src/jobs/mod.js +1 -0
- package/esm/src/jobs/run.d.ts +20 -1
- package/esm/src/jobs/run.d.ts.map +1 -1
- package/esm/src/jobs/run.js +29 -4
- package/esm/src/jobs/sanitize.d.ts +30 -0
- package/esm/src/jobs/sanitize.d.ts.map +1 -0
- package/esm/src/jobs/sanitize.js +91 -0
- package/esm/src/mail/postal.d.ts.map +1 -1
- package/esm/src/mail/postal.js +25 -20
- package/esm/src/mail/sender.d.ts +5 -0
- package/esm/src/mail/sender.d.ts.map +1 -0
- package/esm/src/mail/sender.js +48 -0
- package/esm/src/mail/service.d.ts.map +1 -1
- package/esm/src/mail/service.js +7 -5
- package/esm/src/next/jobs/route.d.ts.map +1 -1
- package/esm/src/next/jobs/route.js +1 -1
- package/package.json +2 -2
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +10 -1
- package/script/src/jobs/controller.d.ts +14 -1
- package/script/src/jobs/controller.d.ts.map +1 -1
- package/script/src/jobs/controller.js +54 -3
- package/script/src/jobs/events.d.ts +9 -1
- package/script/src/jobs/events.d.ts.map +1 -1
- package/script/src/jobs/events.js +15 -2
- package/script/src/jobs/mod.d.ts +1 -0
- package/script/src/jobs/mod.d.ts.map +1 -1
- package/script/src/jobs/mod.js +1 -0
- package/script/src/jobs/run.d.ts +20 -1
- package/script/src/jobs/run.d.ts.map +1 -1
- package/script/src/jobs/run.js +29 -4
- package/script/src/jobs/sanitize.d.ts +30 -0
- package/script/src/jobs/sanitize.d.ts.map +1 -0
- package/script/src/jobs/sanitize.js +97 -0
- package/script/src/mail/postal.d.ts.map +1 -1
- package/script/src/mail/postal.js +25 -20
- package/script/src/mail/sender.d.ts +5 -0
- package/script/src/mail/sender.d.ts.map +1 -0
- package/script/src/mail/sender.js +52 -0
- package/script/src/mail/service.d.ts.map +1 -1
- package/script/src/mail/service.js +7 -5
- package/script/src/next/jobs/route.d.ts.map +1 -1
- package/script/src/next/jobs/route.js +1 -1
- package/skills/loom/SKILL.md +4 -1
- package/skills/loom-jobs/SKILL.md +27 -0
- package/skills/loom-mail/SKILL.md +14 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Default literal used when a redaction rule has `true` as its replacement. */
|
|
2
|
+
export declare const DEFAULT_JOB_OUTPUT_REDACTION = "[REDACTED]";
|
|
3
|
+
/** Safe event text emitted when a configured output sanitizer cannot run. */
|
|
4
|
+
export declare const JOB_OUTPUT_SANITATION_FAILURE_MESSAGE = "Job output sanitation failed.";
|
|
5
|
+
/** Transform one string value before it enters a serialized job event. */
|
|
6
|
+
export type JobOutputSanitizer = (value: string) => string;
|
|
7
|
+
/** Ordered exact-string and regular-expression output redaction rules. */
|
|
8
|
+
export type JobOutputRedactionRules = ReadonlyMap<string | RegExp, true | string>;
|
|
9
|
+
/**
|
|
10
|
+
* Fixed, input-independent error raised when output sanitation fails.
|
|
11
|
+
*
|
|
12
|
+
* The original sanitizer error is deliberately not attached because its
|
|
13
|
+
* message or cause may include the value that was being sanitized.
|
|
14
|
+
*/
|
|
15
|
+
export declare class JobOutputSanitationError extends Error {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a deterministic string redactor from ordered exact and RegExp rules.
|
|
20
|
+
*
|
|
21
|
+
* Rules run in map insertion order and each rule receives the result of the
|
|
22
|
+
* previous rule. Exact strings are replaced everywhere. RegExp rules replace
|
|
23
|
+
* every match regardless of their original `g`, `y`, or `lastIndex` state.
|
|
24
|
+
* Replacement strings are always literal, so `$&`, `$1`, and `$$` have no
|
|
25
|
+
* special meaning. The rules are snapshotted when this function is called.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createJobOutputRedactor(rules: JobOutputRedactionRules): JobOutputSanitizer;
|
|
28
|
+
/** @internal Apply a sanitizer while replacing all failures with a safe error. */
|
|
29
|
+
export declare function sanitizeJobOutputString(sanitizer: JobOutputSanitizer, value: string): string;
|
|
30
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/src/jobs/sanitize.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,eAAO,MAAM,4BAA4B,eAAe,CAAC;AAEzD,6EAA6E;AAC7E,eAAO,MAAM,qCAAqC,kCACjB,CAAC;AAElC,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAC/C,MAAM,GAAG,MAAM,EACf,IAAI,GAAG,MAAM,CACd,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;;CAKlD;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,uBAAuB,GAC7B,kBAAkB,CA+DpB;AAED,kFAAkF;AAClF,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,kBAAkB,EAC7B,KAAK,EAAE,MAAM,GACZ,MAAM,CAUR"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JobOutputSanitationError = exports.JOB_OUTPUT_SANITATION_FAILURE_MESSAGE = exports.DEFAULT_JOB_OUTPUT_REDACTION = void 0;
|
|
4
|
+
exports.createJobOutputRedactor = createJobOutputRedactor;
|
|
5
|
+
exports.sanitizeJobOutputString = sanitizeJobOutputString;
|
|
6
|
+
/** Default literal used when a redaction rule has `true` as its replacement. */
|
|
7
|
+
exports.DEFAULT_JOB_OUTPUT_REDACTION = "[REDACTED]";
|
|
8
|
+
/** Safe event text emitted when a configured output sanitizer cannot run. */
|
|
9
|
+
exports.JOB_OUTPUT_SANITATION_FAILURE_MESSAGE = "Job output sanitation failed.";
|
|
10
|
+
/**
|
|
11
|
+
* Fixed, input-independent error raised when output sanitation fails.
|
|
12
|
+
*
|
|
13
|
+
* The original sanitizer error is deliberately not attached because its
|
|
14
|
+
* message or cause may include the value that was being sanitized.
|
|
15
|
+
*/
|
|
16
|
+
class JobOutputSanitationError extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(exports.JOB_OUTPUT_SANITATION_FAILURE_MESSAGE);
|
|
19
|
+
this.name = "JobOutputSanitationError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.JobOutputSanitationError = JobOutputSanitationError;
|
|
23
|
+
function compileRegExpFlags(flags) {
|
|
24
|
+
// A redaction rule always scans the full string. `lastIndex`, `g`, and `y`
|
|
25
|
+
// therefore cannot make matching depend on prior calls or an initial offset.
|
|
26
|
+
return `${flags.replaceAll("g", "").replaceAll("y", "")}g`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a deterministic string redactor from ordered exact and RegExp rules.
|
|
30
|
+
*
|
|
31
|
+
* Rules run in map insertion order and each rule receives the result of the
|
|
32
|
+
* previous rule. Exact strings are replaced everywhere. RegExp rules replace
|
|
33
|
+
* every match regardless of their original `g`, `y`, or `lastIndex` state.
|
|
34
|
+
* Replacement strings are always literal, so `$&`, `$1`, and `$$` have no
|
|
35
|
+
* special meaning. The rules are snapshotted when this function is called.
|
|
36
|
+
*/
|
|
37
|
+
function createJobOutputRedactor(rules) {
|
|
38
|
+
const compiled = [];
|
|
39
|
+
let index = 0;
|
|
40
|
+
for (const [matcher, configuredReplacement] of rules) {
|
|
41
|
+
index++;
|
|
42
|
+
const replacement = configuredReplacement === true
|
|
43
|
+
? exports.DEFAULT_JOB_OUTPUT_REDACTION
|
|
44
|
+
: configuredReplacement;
|
|
45
|
+
if (typeof replacement !== "string") {
|
|
46
|
+
throw new TypeError(`Job output redaction rule ${index} has an invalid replacement.`);
|
|
47
|
+
}
|
|
48
|
+
if (typeof matcher === "string") {
|
|
49
|
+
if (matcher.length === 0) {
|
|
50
|
+
throw new TypeError(`Job output redaction rule ${index} has an empty exact-string matcher.`);
|
|
51
|
+
}
|
|
52
|
+
compiled.push({ kind: "exact", replacement, search: matcher });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!(matcher instanceof RegExp)) {
|
|
56
|
+
throw new TypeError(`Job output redaction rule ${index} has an invalid matcher.`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
compiled.push({
|
|
60
|
+
flags: compileRegExpFlags(matcher.flags),
|
|
61
|
+
kind: "regexp",
|
|
62
|
+
replacement,
|
|
63
|
+
source: matcher.source,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new TypeError(`Job output redaction rule ${index} has an invalid regular expression.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return (value) => {
|
|
71
|
+
let sanitized = value;
|
|
72
|
+
for (const rule of compiled) {
|
|
73
|
+
if (rule.kind === "exact") {
|
|
74
|
+
sanitized = sanitized.split(rule.search).join(rule.replacement);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Create a fresh matcher per application so no RegExp state can cross
|
|
78
|
+
// values, rules, executions, or concurrent consumers.
|
|
79
|
+
const matcher = new RegExp(rule.source, rule.flags);
|
|
80
|
+
sanitized = sanitized.replace(matcher, () => rule.replacement);
|
|
81
|
+
}
|
|
82
|
+
return sanitized;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** @internal Apply a sanitizer while replacing all failures with a safe error. */
|
|
86
|
+
function sanitizeJobOutputString(sanitizer, value) {
|
|
87
|
+
try {
|
|
88
|
+
const sanitized = sanitizer(value);
|
|
89
|
+
if (typeof sanitized !== "string") {
|
|
90
|
+
throw new JobOutputSanitationError();
|
|
91
|
+
}
|
|
92
|
+
return sanitized;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new JobOutputSanitationError();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postal.d.ts","sourceRoot":"","sources":["../../../src/src/mail/postal.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"postal.d.ts","sourceRoot":"","sources":["../../../src/src/mail/postal.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAC;AAKpE,OAAO,KAAK,EAEV,qBAAqB,EACrB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE;QACL,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CACf,MAAM,EACN;YAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CACjE,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,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alWebhookSignature = verifyPostalWebhookSignature;
|
|
|
6
6
|
exports.parsePostalWebhook = parsePostalWebhook;
|
|
7
7
|
require("../../_dnt.polyfills.js");
|
|
8
8
|
const errors_js_1 = require("./errors.js");
|
|
9
|
+
const sender_js_1 = require("./sender.js");
|
|
9
10
|
class LoomPostalWebhookError extends errors_js_1.LoomMailError {
|
|
10
11
|
constructor(message, options) {
|
|
11
12
|
super(message, { code: options.code });
|
|
@@ -33,9 +34,12 @@ function postalBaseUrl(host) {
|
|
|
33
34
|
: `https://${normalized}`;
|
|
34
35
|
}
|
|
35
36
|
function fromAddress(message) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const email = (0, sender_js_1.normalizeLoomMailFromEmail)(message.fromEmail);
|
|
38
|
+
const name = (0, sender_js_1.normalizeLoomMailFromName)(message.fromName);
|
|
39
|
+
if (!name)
|
|
40
|
+
return email;
|
|
41
|
+
const quotedName = name.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
42
|
+
return `"${quotedName}" <${email}>`;
|
|
39
43
|
}
|
|
40
44
|
function retryableHttpStatus(status) {
|
|
41
45
|
return status === 408 || status === 429 || status >= 500;
|
|
@@ -74,26 +78,27 @@ function createPostalMailTransport(options) {
|
|
|
74
78
|
if (!options.apiKey.trim()) {
|
|
75
79
|
throw new errors_js_1.LoomMailTransportError("Postal API key is not configured.", { code: "postal_not_configured", retryable: false });
|
|
76
80
|
}
|
|
81
|
+
const requestBody = {
|
|
82
|
+
attachments: message.attachments.map((attachment) => ({
|
|
83
|
+
content_type: attachment.contentType ?? undefined,
|
|
84
|
+
data: attachment.data,
|
|
85
|
+
name: attachment.name,
|
|
86
|
+
})),
|
|
87
|
+
bcc: message.bcc,
|
|
88
|
+
cc: message.cc,
|
|
89
|
+
from: fromAddress(message),
|
|
90
|
+
headers: message.headers,
|
|
91
|
+
html_body: message.htmlBody ?? undefined,
|
|
92
|
+
plain_body: message.plainBody ?? undefined,
|
|
93
|
+
reply_to: message.replyTo ?? undefined,
|
|
94
|
+
subject: message.subject,
|
|
95
|
+
tag: message.tag ?? undefined,
|
|
96
|
+
to: message.to,
|
|
97
|
+
};
|
|
77
98
|
let response;
|
|
78
99
|
try {
|
|
79
100
|
response = await fetchImpl(new URL("/api/v1/send/message", postalBaseUrl(options.host)), {
|
|
80
|
-
body: JSON.stringify(
|
|
81
|
-
attachments: message.attachments.map((attachment) => ({
|
|
82
|
-
content_type: attachment.contentType ?? undefined,
|
|
83
|
-
data: attachment.data,
|
|
84
|
-
name: attachment.name,
|
|
85
|
-
})),
|
|
86
|
-
bcc: message.bcc,
|
|
87
|
-
cc: message.cc,
|
|
88
|
-
from: fromAddress(message),
|
|
89
|
-
headers: message.headers,
|
|
90
|
-
html_body: message.htmlBody ?? undefined,
|
|
91
|
-
plain_body: message.plainBody ?? undefined,
|
|
92
|
-
reply_to: message.replyTo ?? undefined,
|
|
93
|
-
subject: message.subject,
|
|
94
|
-
tag: message.tag ?? undefined,
|
|
95
|
-
to: message.to,
|
|
96
|
-
}),
|
|
101
|
+
body: JSON.stringify(requestBody),
|
|
97
102
|
headers: {
|
|
98
103
|
"Content-Type": "application/json",
|
|
99
104
|
"X-Server-API-Key": options.apiKey,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Normalizes a bare sender address without attempting full addr-spec parsing. */
|
|
2
|
+
export declare function normalizeLoomMailFromEmail(value: string): string;
|
|
3
|
+
/** Normalizes an optional sender display name and rejects header controls. */
|
|
4
|
+
export declare function normalizeLoomMailFromName(value?: string | null): string | null;
|
|
5
|
+
//# sourceMappingURL=sender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../src/src/mail/sender.ts"],"names":[],"mappings":"AAmCA,kFAAkF;AAClF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,UAYvD;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,iBAK9D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeLoomMailFromEmail = normalizeLoomMailFromEmail;
|
|
4
|
+
exports.normalizeLoomMailFromName = normalizeLoomMailFromName;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const CONTROL_CHARACTER = /\p{Cc}/u;
|
|
7
|
+
function assertNoHeaderControlCharacters(value, field) {
|
|
8
|
+
if (CONTROL_CHARACTER.test(value)) {
|
|
9
|
+
throw new errors_js_1.LoomMailValidationError(`${field} must not contain control characters.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function hasUnquotedAngleBracket(value) {
|
|
13
|
+
let escaped = false;
|
|
14
|
+
let quoted = false;
|
|
15
|
+
for (const character of value) {
|
|
16
|
+
if (quoted && escaped) {
|
|
17
|
+
escaped = false;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (quoted && character === "\\") {
|
|
21
|
+
escaped = true;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (character === '"') {
|
|
25
|
+
quoted = !quoted;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!quoted && (character === "<" || character === ">"))
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** Normalizes a bare sender address without attempting full addr-spec parsing. */
|
|
34
|
+
function normalizeLoomMailFromEmail(value) {
|
|
35
|
+
assertNoHeaderControlCharacters(value, "fromEmail");
|
|
36
|
+
const normalized = value.trim();
|
|
37
|
+
if (!normalized) {
|
|
38
|
+
throw new errors_js_1.LoomMailValidationError("A From address is required.");
|
|
39
|
+
}
|
|
40
|
+
if (hasUnquotedAngleBracket(normalized)) {
|
|
41
|
+
throw new errors_js_1.LoomMailValidationError("fromEmail must be a bare email address; pass the display name through fromName instead.");
|
|
42
|
+
}
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
/** Normalizes an optional sender display name and rejects header controls. */
|
|
46
|
+
function normalizeLoomMailFromName(value) {
|
|
47
|
+
if (value === undefined || value === null)
|
|
48
|
+
return null;
|
|
49
|
+
assertNoHeaderControlCharacters(value, "fromName");
|
|
50
|
+
const normalized = value.trim();
|
|
51
|
+
return normalized || null;
|
|
52
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/src/mail/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/src/mail/service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEV,oBAAoB,EAEpB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,4BAA4B,CAC3C,QAAQ,SAAS,qBAAqB,GAAG,qBAAqB;IAE9D,gBAAgB,CAAC,EAAE,MAAM,MAAM,CAAC;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,UAAU,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACzC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAmCD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE;IACR,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,GACA,oBAAoB,CA8BtB;AAWD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,SAAS,qBAAqB,GAAG,qBAAqB,EAC9D,OAAO,EAAE,4BAA4B,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CA2H5E"}
|
|
@@ -4,6 +4,7 @@ exports.normalizeLoomMailInput = normalizeLoomMailInput;
|
|
|
4
4
|
exports.createLoomMailService = createLoomMailService;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
const retry_js_1 = require("./retry.js");
|
|
7
|
+
const sender_js_1 = require("./sender.js");
|
|
7
8
|
function recipients(value) {
|
|
8
9
|
if (!value)
|
|
9
10
|
return [];
|
|
@@ -16,9 +17,6 @@ function nullableText(value) {
|
|
|
16
17
|
return normalized ? normalized : null;
|
|
17
18
|
}
|
|
18
19
|
function assertMailInput(input, normalized) {
|
|
19
|
-
if (!normalized.fromEmail) {
|
|
20
|
-
throw new errors_js_1.LoomMailValidationError("A From address is required.");
|
|
21
|
-
}
|
|
22
20
|
if (!input.subject.trim()) {
|
|
23
21
|
throw new errors_js_1.LoomMailValidationError("A subject is required.");
|
|
24
22
|
}
|
|
@@ -30,10 +28,14 @@ function assertMailInput(input, normalized) {
|
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
function normalizeLoomMailInput(input, defaults) {
|
|
31
|
+
const overrideFromEmail = input.fromEmail === undefined
|
|
32
|
+
? undefined
|
|
33
|
+
: (0, sender_js_1.normalizeLoomMailFromEmail)(input.fromEmail);
|
|
33
34
|
const normalized = {
|
|
34
35
|
bcc: recipients(input.bcc),
|
|
35
36
|
cc: recipients(input.cc),
|
|
36
|
-
fromEmail:
|
|
37
|
+
fromEmail: overrideFromEmail ||
|
|
38
|
+
(0, sender_js_1.normalizeLoomMailFromEmail)(defaults.fromEmail),
|
|
37
39
|
to: recipients(input.to),
|
|
38
40
|
};
|
|
39
41
|
assertMailInput(input, normalized);
|
|
@@ -44,7 +46,7 @@ function normalizeLoomMailInput(input, defaults) {
|
|
|
44
46
|
name: attachment.name,
|
|
45
47
|
})),
|
|
46
48
|
...normalized,
|
|
47
|
-
fromName:
|
|
49
|
+
fromName: (0, sender_js_1.normalizeLoomMailFromName)(input.fromName ?? defaults.fromName),
|
|
48
50
|
headers: { ...input.headers },
|
|
49
51
|
htmlBody: nullableText(input.htmlBody),
|
|
50
52
|
metadata: { ...input.metadata },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/src/next/jobs/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAG7B,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,EAErB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,cAAe,SAAQ,OAAO;IAC7C,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;CACJ;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAE/E,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,cAAc,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,2BAA2B,CAAC,cAAc;IACzD,aAAa,EAAE,cAAc,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,6BAA6B,CAC5C,IAAI,SAAS,aAAa,EAC1B,cAAc,GAAG,OAAO,CACxB,SAAQ,IAAI,CAAC,wBAAwB,EAAE,QAAQ,GAAG,k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AA2B,CAAC,cAAc,CAAC,KAC/C,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAC;IAChD,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,4BAA4B,CAC3C,IAAI,SAAS,aAAa,EAC1B,cAAc,GAAG,OAAO,CACxB,SACA,IAAI,CACF,6BAA6B,CAAC,IAAI,EAAE,cAAc,CAAC,EACnD,SAAS,CACV;IACD,0DAA0D;IAC1D,GAAG,EAAE,IAAI,CAAC;CACX;AAmBD,wBAAgB,sBAAsB,CACpC,IAAI,SAAS,aAAa,EAC1B,cAAc,GAAG,OAAO,EAExB,OAAO,EAAE,6BAA6B,CAAC,IAAI,EAAE,cAAc,CAAC,IAU1D,SAAS,cAAc,EACvB,SAAS,mBAAmB,kBAyF/B;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,SAAS,aAAa,EAC1B,cAAc,GAAG,OAAO,EAExB,OAAO,EAAE,4BAA4B,CAAC,IAAI,EAAE,cAAc,CAAC,IAQnD,SAAS,cAAc,kBAIhC"}
|
|
@@ -81,7 +81,7 @@ function createJobsRouteHandler(options) {
|
|
|
81
81
|
if (deferredTasks === "after" && options.after) {
|
|
82
82
|
options.after(async () => {
|
|
83
83
|
const result = await execution.result;
|
|
84
|
-
await result.controller.runDeferredTasks();
|
|
84
|
+
await result.controller.runDeferredTasks(options.deferredTaskErrorHandler);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
return await finishResponse(response);
|
package/skills/loom/SKILL.md
CHANGED
|
@@ -212,7 +212,10 @@ as more authoritative than a generic mapped error when deciding what failed.
|
|
|
212
212
|
|
|
213
213
|
## Commits
|
|
214
214
|
|
|
215
|
-
- Use conventional commits with scopes for title.
|
|
215
|
+
- Use conventional commits with scopes for the title. Limit the subject line to
|
|
216
|
+
50 characters, capitalize the first letter, do not end the subject line with a
|
|
217
|
+
period, use imperative mood (for example, `fix` instead of `fixed` or
|
|
218
|
+
`fixes`), and wrap the body at 72 characters.
|
|
216
219
|
- In the body, include the motivation, summary of changes, and anything else of
|
|
217
220
|
note.
|
|
218
221
|
- At bottom: "Co-authored with <Assistant> (<model>, reasoning <level>)"
|
|
@@ -99,6 +99,33 @@ Use this skill when working on the shared jobs feature from a consuming app.
|
|
|
99
99
|
- If the app has no always-on worker in the current environment, call out the
|
|
100
100
|
manual runner or admin route needed to drain queued work.
|
|
101
101
|
|
|
102
|
+
## Output sanitation and error disclosure
|
|
103
|
+
|
|
104
|
+
- Use `createJobOutputRedactor()` and pass the result as `outputSanitizer` on
|
|
105
|
+
the execution, response, or route-handler options. Do not implement redaction
|
|
106
|
+
only inside a text or HTML formatter; controller-level sanitation is what also
|
|
107
|
+
covers NDJSON, direct runners, HTTP output, and custom formatters.
|
|
108
|
+
- Redaction maps are ordered. Each exact-string or RegExp rule sees the prior
|
|
109
|
+
rule's result. Exact strings match every occurrence; RegExp rules replace
|
|
110
|
+
every match independent of `g`, `y`, or `lastIndex`. `true` means
|
|
111
|
+
`[REDACTED]`, and string replacements are literal rather than replacement
|
|
112
|
+
templates.
|
|
113
|
+
- Never add an empty exact-string rule. Loom rejects it without including
|
|
114
|
+
configured match or replacement values in the error.
|
|
115
|
+
- The policy recursively sanitizes string values from every controller log level
|
|
116
|
+
and `job.json()` without mutating caller-owned values. Sanitation failure
|
|
117
|
+
emits only the fixed `Job output sanitation failed.` event.
|
|
118
|
+
- Keep expected output, unexpected handler errors, and deferred-task errors as
|
|
119
|
+
distinct decisions. `handlerErrorMessage` opts into a generic literal while
|
|
120
|
+
omission preserves the legacy full stack. Use `deferredTaskErrorHandler`
|
|
121
|
+
separately and use `runDeferredTasksWithResult()` when a failure count affects
|
|
122
|
+
job or audit status; `runDeferredTasks()` keeps its legacy void result.
|
|
123
|
+
- Use `cancellationMessage: false` only when an app intentionally needs silent
|
|
124
|
+
cancellation while retaining the controller's cancellation flag.
|
|
125
|
+
- The boundary covers Loom job-event output, not `console.*`, provider logs,
|
|
126
|
+
audit metadata, URLs, thrown values retained in `execution.result`, external
|
|
127
|
+
log sinks, or object property names.
|
|
128
|
+
|
|
102
129
|
## Job Parameters and Validation
|
|
103
130
|
|
|
104
131
|
Loom supports declarative job parameter definitions on each job's `meta` object.
|
|
@@ -26,9 +26,18 @@ contract.
|
|
|
26
26
|
2. Run `loom add mail`.
|
|
27
27
|
3. Review the materialized schema and generate the app-local migration.
|
|
28
28
|
4. Replace the generated deny-all access function with the app's admin check.
|
|
29
|
-
5. Configure `POSTAL_API_KEY`, `POSTAL_HOST`, `POSTAL_FROM_EMAIL`,
|
|
30
|
-
`POSTAL_WEBHOOK_PUBLIC_KEYS`.
|
|
31
|
-
|
|
29
|
+
5. Configure `POSTAL_API_KEY`, `POSTAL_HOST`, `POSTAL_FROM_EMAIL`, optional
|
|
30
|
+
`POSTAL_FROM_NAME`, and `POSTAL_WEBHOOK_PUBLIC_KEYS`. Keep the sender values
|
|
31
|
+
structured:
|
|
32
|
+
|
|
33
|
+
```dotenv
|
|
34
|
+
POSTAL_FROM_EMAIL=noreply@example.com
|
|
35
|
+
POSTAL_FROM_NAME=Example App
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`POSTAL_FROM_EMAIL` must be a bare address, never `Name <address>`.
|
|
39
|
+
`POSTAL_FROM_NAME` is optional. The webhook value is a JSON array of RSA
|
|
40
|
+
public JWKs with `kid`; it is not a shared secret.
|
|
32
41
|
6. If jobs is active, register the generated `mail-drain` module in the app's
|
|
33
42
|
full and metadata catalogs and choose an app-owned schedule.
|
|
34
43
|
7. Configure Postal to POST signed events to the generated webhook route.
|
|
@@ -47,6 +56,8 @@ contract.
|
|
|
47
56
|
supports an idempotency key.
|
|
48
57
|
- Bound attachment size at the app/action boundary and never log attachment
|
|
49
58
|
bodies, API keys, or webhook key material.
|
|
59
|
+
- Keep purpose-specific sender selection in the consumer. Use per-message
|
|
60
|
+
`fromEmail` and `fromName` overrides instead of adding domain policy to Loom.
|
|
50
61
|
|
|
51
62
|
## Testing
|
|
52
63
|
|