runline 0.37.0 → 0.39.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/dist/credentials/broker.js +32 -16
- package/dist/credentials/cookies.d.ts +33 -0
- package/dist/credentials/cookies.js +151 -0
- package/dist/credentials/http.d.ts +28 -3
- package/dist/credentials/http.js +34 -10
- package/dist/credentials/plugin.d.ts +21 -2
- package/dist/credentials/plugin.js +8 -3
- package/dist/credentials/policy.js +2 -0
- package/dist/credentials/registry.d.ts +25 -0
- package/dist/credentials/registry.js +84 -0
- package/dist/credentials/transport.d.ts +24 -0
- package/dist/credentials/transport.js +222 -7
- package/dist/credentials/types.d.ts +74 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/plugins/_shared/attachments.js +97 -0
- package/dist/plugins/_shared/microsoftAuth.js +33 -4
- package/dist/plugins/_shared/schemas.js +8 -0
- package/dist/plugins/agentMail/src/drafts.js +2 -1
- package/dist/plugins/agentMail/src/inboxes.js +2 -1
- package/dist/plugins/agentMail/src/messages.js +2 -1
- package/dist/plugins/agentMail/src/schemas.js +4 -41
- package/dist/plugins/agentMail/src/shared.js +28 -50
- package/dist/plugins/agentMail/src/threads.js +2 -1
- package/dist/plugins/gmail/src/index.js +10 -22
- package/dist/plugins/microsoftCalendar/src/index.js +513 -17
- package/dist/plugins/microsoftFiles/src/index.js +3 -3
- package/dist/plugins/microsoftMail/src/index.js +305 -54
- package/dist/plugins/todoist/src/credentials.js +4 -11
- package/dist/plugins/todoist/src/index.js +390 -281
- package/dist/plugins/zohoMail/src/credentials.js +92 -0
- package/dist/plugins/zohoMail/src/index.js +241 -0
- package/package.json +1 -1
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import * as t from "typebox";
|
|
2
|
-
import {
|
|
2
|
+
import { attachmentMetadata, attachmentSources, } from "../../_shared/attachments.js";
|
|
3
3
|
export const STRICT = { additionalProperties: false };
|
|
4
4
|
export const MAX_REQUEST_BYTES = 6_000_000;
|
|
5
5
|
export const id = t.String({ minLength: 1, pattern: "\\S" });
|
|
6
|
-
/**
|
|
7
|
-
* At least one of `fields` must be given: "provide a change", "name a
|
|
8
|
-
* recipient". Keyed off the field record itself, so the rule cannot drift
|
|
9
|
-
* from the fields it governs.
|
|
10
|
-
*/
|
|
11
|
-
export function atLeastOne(fields) {
|
|
12
|
-
return { anyOf: Object.keys(fields).map((key) => ({ required: [key] })) };
|
|
13
|
-
}
|
|
14
6
|
export const inboxFields = {
|
|
15
7
|
inboxId: t.String({
|
|
16
8
|
...id,
|
|
@@ -82,40 +74,11 @@ export const sendFields = {
|
|
|
82
74
|
})),
|
|
83
75
|
};
|
|
84
76
|
/**
|
|
85
|
-
* Attachment bytes come one way each,
|
|
86
|
-
*
|
|
87
|
-
* AgentMail's own `url`. A googleDrive download result passes straight
|
|
88
|
-
* through as `contentBase64`.
|
|
77
|
+
* Attachment bytes come one way each, as every mail plugin takes them,
|
|
78
|
+
* plus AgentMail's own `url`, which AgentMail fetches itself.
|
|
89
79
|
*/
|
|
90
|
-
const attachmentMetadata = {
|
|
91
|
-
name: t.Optional(t.String({ ...id, description: "File name; defaults to the path's name." })),
|
|
92
|
-
mimeType: t.Optional(t.String({ ...id, description: "MIME type, e.g. application/pdf." })),
|
|
93
|
-
inline: t.Optional(t.Boolean({
|
|
94
|
-
description: "Embed in the HTML body, referenced as cid:<contentId>, instead of attaching.",
|
|
95
|
-
})),
|
|
96
|
-
contentId: t.Optional(t.String({ ...id, description: "Content-ID for inline images." })),
|
|
97
|
-
};
|
|
98
|
-
const SIZE_NOTE = "The entire serialized request is limited to 6 MB; use url for larger files.";
|
|
99
80
|
export const attachment = t.Union([
|
|
100
|
-
|
|
101
|
-
...attachmentMetadata,
|
|
102
|
-
contentBase64: t.Union([t.String(), DownloadedFile], {
|
|
103
|
-
description: `Base64 bytes (standard or base64url; padding and whitespace normalized), or a googleDrive.file.download result, whose name and mimeType are used when not given here. ${SIZE_NOTE}`,
|
|
104
|
-
}),
|
|
105
|
-
}, STRICT),
|
|
106
|
-
t.Object({
|
|
107
|
-
...attachmentMetadata,
|
|
108
|
-
contentPath: t.String({
|
|
109
|
-
...id,
|
|
110
|
-
description: `A regular file on the runline host, read at call time. ${SIZE_NOTE}`,
|
|
111
|
-
}),
|
|
112
|
-
}, STRICT),
|
|
113
|
-
t.Object({
|
|
114
|
-
...attachmentMetadata,
|
|
115
|
-
content: t.String({
|
|
116
|
-
description: `UTF-8 text content, e.g. a generated CSV. ${SIZE_NOTE}`,
|
|
117
|
-
}),
|
|
118
|
-
}, STRICT),
|
|
81
|
+
...attachmentSources("The entire serialized request is limited to 6 MB; use url for larger files."),
|
|
119
82
|
t.Object({
|
|
120
83
|
...attachmentMetadata,
|
|
121
84
|
url: t.String({
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { basename } from "node:path";
|
|
2
1
|
import { AuthError, credentialRequest, jsonAnswer, pathSegment, responseFailed, } from "runline";
|
|
3
2
|
import * as t from "typebox";
|
|
4
3
|
import { Check } from "typebox/value";
|
|
5
|
-
import {
|
|
6
|
-
import { readLocalFile } from "../../_shared/localFile.js";
|
|
4
|
+
import { attachmentFile } from "../../_shared/attachments.js";
|
|
7
5
|
import { obj } from "../../_shared/provider.js";
|
|
8
6
|
import { agentMailCredential } from "./credentials.js";
|
|
9
7
|
import { id, MAX_REQUEST_BYTES } from "./schemas.js";
|
|
@@ -32,59 +30,39 @@ function wireFields(fields) {
|
|
|
32
30
|
}
|
|
33
31
|
/** The bytes a request body can still hold once base64 inflates them by 4/3. */
|
|
34
32
|
const MAX_FILE_BYTES = Math.floor((MAX_REQUEST_BYTES * 3) / 4);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
33
|
+
/**
|
|
34
|
+
* One attachment as AgentMail's SendAttachment: its bytes as base64, or
|
|
35
|
+
* its URL for AgentMail to fetch.
|
|
36
|
+
*/
|
|
37
|
+
async function wireAttachment(input, index) {
|
|
38
|
+
let source;
|
|
39
|
+
let file;
|
|
40
|
+
if ("url" in input) {
|
|
41
|
+
try {
|
|
42
|
+
const url = new URL(input.url);
|
|
43
|
+
if (url.protocol !== "https:" || url.username || url.password)
|
|
44
|
+
throw new Error();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error(`agentMail: attachment ${index} url requires HTTPS without embedded credentials`);
|
|
48
|
+
}
|
|
49
|
+
source = { url: input.url };
|
|
50
|
+
file = { name: input.name, mimeType: input.mimeType };
|
|
48
51
|
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
+
else {
|
|
53
|
+
const resolved = await attachmentFile(input, index, {
|
|
54
|
+
plugin: "agentMail",
|
|
52
55
|
maxBytes: MAX_FILE_BYTES,
|
|
53
56
|
oversize: `agentMail: attachment ${index} exceeds the 6 MB request limit once encoded; use url`,
|
|
54
57
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const url = new URL(input.url);
|
|
61
|
-
if (url.protocol !== "https:" || url.username || url.password)
|
|
62
|
-
throw new Error();
|
|
58
|
+
if (!resolved.bytes.length)
|
|
59
|
+
throw new Error(`agentMail: attachment ${index} is empty`);
|
|
60
|
+
source = { content: resolved.bytes.toString("base64") };
|
|
61
|
+
file = resolved;
|
|
63
62
|
}
|
|
64
|
-
catch {
|
|
65
|
-
throw new Error(`agentMail: attachment ${index} url requires HTTPS without embedded credentials`);
|
|
66
|
-
}
|
|
67
|
-
return { url: input.url };
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* One attachment as AgentMail's SendAttachment. A download result passed
|
|
71
|
-
* as contentBase64 supplies the name and type the input leaves out; a
|
|
72
|
-
* local file is named for its path; text defaults to text/plain.
|
|
73
|
-
*/
|
|
74
|
-
async function wireAttachment(input, index) {
|
|
75
|
-
const source = await attachmentSource(input, index);
|
|
76
|
-
if ("content" in source && !source.content)
|
|
77
|
-
throw new Error(`agentMail: attachment ${index} is empty`);
|
|
78
|
-
const result = "contentBase64" in input && typeof input.contentBase64 !== "string"
|
|
79
|
-
? input.contentBase64
|
|
80
|
-
: undefined;
|
|
81
63
|
return Object.fromEntries(Object.entries({
|
|
82
|
-
filename:
|
|
83
|
-
|
|
84
|
-
("contentPath" in input ? basename(input.contentPath) : undefined),
|
|
85
|
-
content_type: input.mimeType ??
|
|
86
|
-
(result?.mimeType || undefined) ??
|
|
87
|
-
("content" in input ? "text/plain" : undefined),
|
|
64
|
+
filename: file.name,
|
|
65
|
+
content_type: file.mimeType,
|
|
88
66
|
content_disposition: input.inline === undefined
|
|
89
67
|
? undefined
|
|
90
68
|
: input.inline
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from "typebox";
|
|
2
|
-
import { atLeastOne
|
|
2
|
+
import { atLeastOne } from "../../_shared/schemas.js";
|
|
3
|
+
import { id, inboxFields, labelFields, mailListFields, pageFields, STRICT, searchFields, strings, threadFields, } from "./schemas.js";
|
|
3
4
|
import { attachmentPath, inboxPath, request, threadPath } from "./shared.js";
|
|
4
5
|
const list = t.Object({
|
|
5
6
|
...inboxFields,
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { pathSegment, } from "runline";
|
|
21
21
|
import * as t from "typebox";
|
|
22
|
-
import {
|
|
22
|
+
import { base64File } from "../../_shared/attachments.js";
|
|
23
|
+
import { DownloadedFile } from "../../_shared/base64.js";
|
|
23
24
|
import { renderEmailJsx } from "../../_shared/emailJsx.js";
|
|
24
25
|
import { googleCredential, googleJsonRequest, googleOAuth, } from "../../_shared/googleAuth.js";
|
|
25
26
|
import { GoogleTimestamp, Id, NonEmptyString, stringEnum, } from "../../_shared/googleSchemas.js";
|
|
@@ -111,30 +112,17 @@ function normalizeAttachment(input, index) {
|
|
|
111
112
|
throw new Error(`gmail: attachment ${index} must be an object`);
|
|
112
113
|
}
|
|
113
114
|
const content = input.contentBase64;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
typeof content
|
|
118
|
-
typeof content.contentBase64 === "string"
|
|
119
|
-
? content.contentBase64
|
|
120
|
-
: undefined;
|
|
121
|
-
if (typeof contentBase64 !== "string") {
|
|
115
|
+
if (typeof content !== "string" &&
|
|
116
|
+
(typeof content !== "object" ||
|
|
117
|
+
!content ||
|
|
118
|
+
typeof content.contentBase64 !== "string")) {
|
|
122
119
|
throw new Error(`gmail: attachment ${index} contentBase64 must be a base64 string`);
|
|
123
120
|
}
|
|
124
|
-
const
|
|
125
|
-
if (normalized === undefined) {
|
|
126
|
-
throw new Error(`gmail: attachment ${index} contentBase64 is not valid base64`);
|
|
127
|
-
}
|
|
128
|
-
// A download result passed as contentBase64 names its own file and type.
|
|
129
|
-
const result = typeof content === "object" && content ? content : {};
|
|
130
|
-
const named = (value) => typeof value === "string" && value ? value : undefined;
|
|
121
|
+
const file = base64File(content, `gmail: attachment ${index}`);
|
|
131
122
|
return {
|
|
132
|
-
name: input.name ??
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
`attachment-${index + 1}`,
|
|
136
|
-
mimeType: input.mimeType ?? named(result.mimeType) ?? "application/octet-stream",
|
|
137
|
-
contentBase64: normalized,
|
|
123
|
+
name: input.name ?? input.filename ?? file.name ?? `attachment-${index + 1}`,
|
|
124
|
+
mimeType: input.mimeType ?? file.mimeType ?? "application/octet-stream",
|
|
125
|
+
contentBase64: file.bytes.toString("base64"),
|
|
138
126
|
};
|
|
139
127
|
}
|
|
140
128
|
function attachmentPart(att) {
|