@contractspec/integration.providers-impls 1.57.0 → 1.59.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/analytics.d.ts +1 -8
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +3 -3
- package/dist/calendar.d.ts +1 -8
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +3 -3
- package/dist/database.d.ts +1 -8
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +3 -3
- package/dist/email.d.ts +1 -8
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3 -3
- package/dist/embedding.d.ts +1 -8
- package/dist/embedding.d.ts.map +1 -1
- package/dist/embedding.js +3 -3
- package/dist/impls/elevenlabs-voice.d.ts +14 -18
- package/dist/impls/elevenlabs-voice.d.ts.map +1 -1
- package/dist/impls/elevenlabs-voice.js +98 -88
- package/dist/impls/fal-voice.d.ts +22 -26
- package/dist/impls/fal-voice.d.ts.map +1 -1
- package/dist/impls/fal-voice.js +103 -78
- package/dist/impls/fathom-meeting-recorder.d.ts +35 -39
- package/dist/impls/fathom-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.js +285 -142
- package/dist/impls/fathom-meeting-recorder.mapper.d.ts +4 -8
- package/dist/impls/fathom-meeting-recorder.mapper.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.mapper.js +102 -38
- package/dist/impls/fathom-meeting-recorder.types.d.ts +16 -20
- package/dist/impls/fathom-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.types.js +1 -0
- package/dist/impls/fathom-meeting-recorder.utils.d.ts +10 -14
- package/dist/impls/fathom-meeting-recorder.utils.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.utils.js +58 -41
- package/dist/impls/fathom-meeting-recorder.webhooks.d.ts +3 -7
- package/dist/impls/fathom-meeting-recorder.webhooks.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.webhooks.js +25 -20
- package/dist/impls/fireflies-meeting-recorder.d.ts +21 -25
- package/dist/impls/fireflies-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.js +272 -149
- package/dist/impls/fireflies-meeting-recorder.queries.d.ts +3 -6
- package/dist/impls/fireflies-meeting-recorder.queries.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.queries.js +10 -8
- package/dist/impls/fireflies-meeting-recorder.types.d.ts +26 -29
- package/dist/impls/fireflies-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.types.js +1 -0
- package/dist/impls/fireflies-meeting-recorder.utils.d.ts +4 -7
- package/dist/impls/fireflies-meeting-recorder.utils.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.utils.js +34 -27
- package/dist/impls/gcs-storage.d.ts +18 -22
- package/dist/impls/gcs-storage.d.ts.map +1 -1
- package/dist/impls/gcs-storage.js +92 -84
- package/dist/impls/gmail-inbound.d.ts +20 -24
- package/dist/impls/gmail-inbound.d.ts.map +1 -1
- package/dist/impls/gmail-inbound.js +212 -185
- package/dist/impls/gmail-outbound.d.ts +12 -16
- package/dist/impls/gmail-outbound.d.ts.map +1 -1
- package/dist/impls/gmail-outbound.js +126 -92
- package/dist/impls/google-calendar.d.ts +17 -21
- package/dist/impls/google-calendar.d.ts.map +1 -1
- package/dist/impls/google-calendar.js +182 -145
- package/dist/impls/gradium-voice.d.ts +20 -22
- package/dist/impls/gradium-voice.d.ts.map +1 -1
- package/dist/impls/gradium-voice.js +85 -74
- package/dist/impls/granola-meeting-recorder.d.ts +31 -24
- package/dist/impls/granola-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/granola-meeting-recorder.js +511 -143
- package/dist/impls/granola-meeting-recorder.mcp.d.ts +25 -0
- package/dist/impls/granola-meeting-recorder.mcp.d.ts.map +1 -0
- package/dist/impls/granola-meeting-recorder.mcp.js +279 -0
- package/dist/impls/granola-meeting-recorder.types.d.ts +60 -49
- package/dist/impls/granola-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/granola-meeting-recorder.types.js +1 -0
- package/dist/impls/index.d.ts +28 -28
- package/dist/impls/index.d.ts.map +1 -0
- package/dist/impls/index.js +4659 -29
- package/dist/impls/jira.d.ts +18 -22
- package/dist/impls/jira.d.ts.map +1 -1
- package/dist/impls/jira.js +112 -101
- package/dist/impls/linear.d.ts +17 -21
- package/dist/impls/linear.d.ts.map +1 -1
- package/dist/impls/linear.js +78 -69
- package/dist/impls/mistral-embedding.d.ts +17 -21
- package/dist/impls/mistral-embedding.d.ts.map +1 -1
- package/dist/impls/mistral-embedding.js +41 -39
- package/dist/impls/mistral-llm.d.ts +25 -29
- package/dist/impls/mistral-llm.d.ts.map +1 -1
- package/dist/impls/mistral-llm.js +266 -244
- package/dist/impls/notion.d.ts +20 -24
- package/dist/impls/notion.d.ts.map +1 -1
- package/dist/impls/notion.js +145 -110
- package/dist/impls/posthog-reader.d.ts +18 -22
- package/dist/impls/posthog-reader.d.ts.map +1 -1
- package/dist/impls/posthog-reader.js +148 -129
- package/dist/impls/posthog-utils.d.ts +4 -7
- package/dist/impls/posthog-utils.d.ts.map +1 -1
- package/dist/impls/posthog-utils.js +31 -22
- package/dist/impls/posthog.d.ts +33 -37
- package/dist/impls/posthog.d.ts.map +1 -1
- package/dist/impls/posthog.js +320 -119
- package/dist/impls/postmark-email.d.ts +13 -17
- package/dist/impls/postmark-email.d.ts.map +1 -1
- package/dist/impls/postmark-email.js +55 -50
- package/dist/impls/powens-client.d.ts +111 -114
- package/dist/impls/powens-client.d.ts.map +1 -1
- package/dist/impls/powens-client.js +194 -170
- package/dist/impls/powens-openbanking.d.ts +22 -26
- package/dist/impls/powens-openbanking.d.ts.map +1 -1
- package/dist/impls/powens-openbanking.js +425 -217
- package/dist/impls/provider-factory.d.ts +29 -33
- package/dist/impls/provider-factory.d.ts.map +1 -1
- package/dist/impls/provider-factory.js +4072 -275
- package/dist/impls/qdrant-vector.d.ts +18 -22
- package/dist/impls/qdrant-vector.d.ts.map +1 -1
- package/dist/impls/qdrant-vector.js +76 -69
- package/dist/impls/stripe-payments.d.ts +22 -26
- package/dist/impls/stripe-payments.d.ts.map +1 -1
- package/dist/impls/stripe-payments.js +219 -193
- package/dist/impls/supabase-psql.d.ts +21 -25
- package/dist/impls/supabase-psql.d.ts.map +1 -1
- package/dist/impls/supabase-psql.js +138 -98
- package/dist/impls/supabase-vector.d.ts +29 -33
- package/dist/impls/supabase-vector.d.ts.map +1 -1
- package/dist/impls/supabase-vector.js +278 -103
- package/dist/impls/tldv-meeting-recorder.d.ts +18 -22
- package/dist/impls/tldv-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/tldv-meeting-recorder.js +142 -127
- package/dist/impls/twilio-sms.d.ts +14 -17
- package/dist/impls/twilio-sms.d.ts.map +1 -1
- package/dist/impls/twilio-sms.js +62 -55
- package/dist/index.d.ts +15 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4700 -107
- package/dist/llm.d.ts +1 -8
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +3 -3
- package/dist/meeting-recorder.d.ts +1 -8
- package/dist/meeting-recorder.d.ts.map +1 -1
- package/dist/meeting-recorder.js +3 -3
- package/dist/node/analytics.js +2 -0
- package/dist/node/calendar.js +2 -0
- package/dist/node/database.js +2 -0
- package/dist/node/email.js +2 -0
- package/dist/node/embedding.js +2 -0
- package/dist/node/impls/elevenlabs-voice.js +102 -0
- package/dist/node/impls/fal-voice.js +112 -0
- package/dist/node/impls/fathom-meeting-recorder.js +287 -0
- package/dist/node/impls/fathom-meeting-recorder.mapper.js +105 -0
- package/dist/node/impls/fathom-meeting-recorder.types.js +0 -0
- package/dist/node/impls/fathom-meeting-recorder.utils.js +72 -0
- package/dist/node/impls/fathom-meeting-recorder.webhooks.js +29 -0
- package/dist/node/impls/fireflies-meeting-recorder.js +274 -0
- package/dist/node/impls/fireflies-meeting-recorder.queries.js +85 -0
- package/dist/node/impls/fireflies-meeting-recorder.types.js +0 -0
- package/dist/node/impls/fireflies-meeting-recorder.utils.js +42 -0
- package/dist/node/impls/gcs-storage.js +97 -0
- package/dist/node/impls/gmail-inbound.js +227 -0
- package/dist/node/impls/gmail-outbound.js +139 -0
- package/dist/node/impls/google-calendar.js +191 -0
- package/dist/node/impls/gradium-voice.js +90 -0
- package/dist/node/impls/granola-meeting-recorder.js +512 -0
- package/dist/node/impls/granola-meeting-recorder.mcp.js +278 -0
- package/dist/node/impls/granola-meeting-recorder.types.js +0 -0
- package/dist/node/impls/index.js +4658 -0
- package/dist/node/impls/jira.js +124 -0
- package/dist/node/impls/linear.js +83 -0
- package/dist/node/impls/mistral-embedding.js +43 -0
- package/dist/node/impls/mistral-llm.js +269 -0
- package/dist/node/impls/notion.js +160 -0
- package/dist/node/impls/posthog-reader.js +159 -0
- package/dist/node/impls/posthog-utils.js +38 -0
- package/dist/node/impls/posthog.js +322 -0
- package/dist/node/impls/postmark-email.js +60 -0
- package/dist/node/impls/powens-client.js +195 -0
- package/dist/node/impls/powens-openbanking.js +426 -0
- package/dist/node/impls/provider-factory.js +4080 -0
- package/dist/node/impls/qdrant-vector.js +78 -0
- package/dist/node/impls/stripe-payments.js +228 -0
- package/dist/node/impls/supabase-psql.js +150 -0
- package/dist/node/impls/supabase-vector.js +323 -0
- package/dist/node/impls/tldv-meeting-recorder.js +145 -0
- package/dist/node/impls/twilio-sms.js +65 -0
- package/dist/node/index.js +4699 -0
- package/dist/node/llm.js +2 -0
- package/dist/node/meeting-recorder.js +2 -0
- package/dist/node/openbanking.js +2 -0
- package/dist/node/payments.js +2 -0
- package/dist/node/project-management.js +2 -0
- package/dist/node/runtime.js +0 -0
- package/dist/node/secrets/provider.js +11 -0
- package/dist/node/sms.js +2 -0
- package/dist/node/storage.js +2 -0
- package/dist/node/vector-store.js +2 -0
- package/dist/node/voice.js +2 -0
- package/dist/openbanking.d.ts +1 -8
- package/dist/openbanking.d.ts.map +1 -1
- package/dist/openbanking.js +3 -3
- package/dist/payments.d.ts +1 -8
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +3 -3
- package/dist/project-management.d.ts +1 -8
- package/dist/project-management.d.ts.map +1 -1
- package/dist/project-management.js +3 -3
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/secrets/provider.d.ts +3 -2
- package/dist/secrets/provider.d.ts.map +1 -0
- package/dist/secrets/provider.js +12 -3
- package/dist/sms.d.ts +1 -8
- package/dist/sms.d.ts.map +1 -1
- package/dist/sms.js +3 -3
- package/dist/storage.d.ts +1 -8
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +3 -3
- package/dist/vector-store.d.ts +1 -8
- package/dist/vector-store.d.ts.map +1 -1
- package/dist/vector-store.js +3 -3
- package/dist/voice.d.ts +1 -8
- package/dist/voice.d.ts.map +1 -1
- package/dist/voice.js +3 -3
- package/package.json +405 -114
- package/dist/_virtual/_rolldown/runtime.js +0 -36
- package/dist/impls/elevenlabs-voice.js.map +0 -1
- package/dist/impls/fal-voice.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.mapper.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.utils.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.webhooks.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.queries.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.utils.js.map +0 -1
- package/dist/impls/gcs-storage.js.map +0 -1
- package/dist/impls/gmail-inbound.js.map +0 -1
- package/dist/impls/gmail-outbound.js.map +0 -1
- package/dist/impls/google-calendar.js.map +0 -1
- package/dist/impls/gradium-voice.js.map +0 -1
- package/dist/impls/granola-meeting-recorder.js.map +0 -1
- package/dist/impls/jira.js.map +0 -1
- package/dist/impls/linear.js.map +0 -1
- package/dist/impls/mistral-embedding.js.map +0 -1
- package/dist/impls/mistral-llm.js.map +0 -1
- package/dist/impls/notion.js.map +0 -1
- package/dist/impls/posthog-reader.js.map +0 -1
- package/dist/impls/posthog-utils.js.map +0 -1
- package/dist/impls/posthog.js.map +0 -1
- package/dist/impls/postmark-email.js.map +0 -1
- package/dist/impls/powens-client.js.map +0 -1
- package/dist/impls/powens-openbanking.js.map +0 -1
- package/dist/impls/provider-factory.js.map +0 -1
- package/dist/impls/qdrant-vector.js.map +0 -1
- package/dist/impls/stripe-payments.js.map +0 -1
- package/dist/impls/supabase-psql.js.map +0 -1
- package/dist/impls/supabase-vector.js.map +0 -1
- package/dist/impls/tldv-meeting-recorder.js.map +0 -1
- package/dist/impls/twilio-sms.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,201 +1,228 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/impls/gmail-inbound.ts
|
|
1
3
|
import { google } from "googleapis";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
5
|
+
class GmailInboundProvider {
|
|
6
|
+
gmail;
|
|
7
|
+
userId;
|
|
8
|
+
includeSpamTrash;
|
|
9
|
+
auth;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.auth = options.auth;
|
|
12
|
+
this.gmail = options.gmail ?? google.gmail({
|
|
13
|
+
version: "v1",
|
|
14
|
+
auth: options.auth
|
|
15
|
+
});
|
|
16
|
+
this.userId = options.userId ?? "me";
|
|
17
|
+
this.includeSpamTrash = options.includeSpamTrash ?? false;
|
|
18
|
+
}
|
|
19
|
+
async listThreads(query) {
|
|
20
|
+
const response = await this.gmail.users.threads.list({
|
|
21
|
+
userId: this.userId,
|
|
22
|
+
maxResults: query?.pageSize,
|
|
23
|
+
pageToken: query?.pageToken,
|
|
24
|
+
q: query?.query,
|
|
25
|
+
labelIds: query?.label ? [query.label] : undefined,
|
|
26
|
+
includeSpamTrash: this.includeSpamTrash,
|
|
27
|
+
auth: this.auth
|
|
28
|
+
});
|
|
29
|
+
const threads = await Promise.all((response.data.threads ?? []).map(async (thread) => {
|
|
30
|
+
if (!thread.id)
|
|
31
|
+
return null;
|
|
32
|
+
return this.getThread(thread.id);
|
|
33
|
+
}));
|
|
34
|
+
return threads.filter((thread) => thread !== null);
|
|
35
|
+
}
|
|
36
|
+
async getThread(threadId) {
|
|
37
|
+
const response = await this.gmail.users.threads.get({
|
|
38
|
+
id: threadId,
|
|
39
|
+
userId: this.userId,
|
|
40
|
+
format: "full",
|
|
41
|
+
auth: this.auth
|
|
42
|
+
});
|
|
43
|
+
const thread = response.data;
|
|
44
|
+
if (!thread)
|
|
45
|
+
return null;
|
|
46
|
+
const messages = thread.messages?.map((message) => this.transformMessage(message)) ?? [];
|
|
47
|
+
const participants = dedupeAddresses(messages.flatMap((message) => [
|
|
48
|
+
message.from,
|
|
49
|
+
...message.to,
|
|
50
|
+
...message.cc ?? []
|
|
51
|
+
]));
|
|
52
|
+
const firstMessage = messages[0];
|
|
53
|
+
const lastMessage = messages[messages.length - 1];
|
|
54
|
+
const updatedAt = lastMessage?.receivedAt ?? lastMessage?.sentAt ?? firstMessage?.receivedAt ?? firstMessage?.sentAt ?? new Date;
|
|
55
|
+
const labels = Array.from(new Set(messages.flatMap((message) => {
|
|
56
|
+
const labelField = message.metadata?.labelIds;
|
|
57
|
+
if (!labelField)
|
|
58
|
+
return [];
|
|
59
|
+
return labelField.split(",").map((label) => label.trim());
|
|
60
|
+
}).filter((label) => Boolean(label))));
|
|
61
|
+
return {
|
|
62
|
+
id: thread.id ?? threadId,
|
|
63
|
+
subject: messages[0]?.subject,
|
|
64
|
+
snippet: thread.snippet ?? "",
|
|
65
|
+
participants,
|
|
66
|
+
messages,
|
|
67
|
+
updatedAt,
|
|
68
|
+
labels,
|
|
69
|
+
metadata: thread.historyId ? { historyId: thread.historyId } : undefined
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async listMessagesSince(query) {
|
|
73
|
+
const after = query.since ? Math.floor(query.since.getTime() / 1000) : undefined;
|
|
74
|
+
const q = [];
|
|
75
|
+
if (after) {
|
|
76
|
+
q.push(`after:${after}`);
|
|
77
|
+
}
|
|
78
|
+
const response = await this.gmail.users.messages.list({
|
|
79
|
+
userId: this.userId,
|
|
80
|
+
maxResults: query.pageSize,
|
|
81
|
+
pageToken: query.pageToken,
|
|
82
|
+
labelIds: query.label ? [query.label] : undefined,
|
|
83
|
+
q: q.join(" "),
|
|
84
|
+
includeSpamTrash: this.includeSpamTrash,
|
|
85
|
+
auth: this.auth
|
|
86
|
+
});
|
|
87
|
+
const messages = await Promise.all((response.data.messages ?? []).map(async (item) => {
|
|
88
|
+
if (!item.id)
|
|
89
|
+
return null;
|
|
90
|
+
const full = await this.gmail.users.messages.get({
|
|
91
|
+
userId: this.userId,
|
|
92
|
+
id: item.id,
|
|
93
|
+
format: "full",
|
|
94
|
+
auth: this.auth
|
|
95
|
+
});
|
|
96
|
+
if (!full.data)
|
|
97
|
+
return null;
|
|
98
|
+
return this.transformMessage(full.data);
|
|
99
|
+
}));
|
|
100
|
+
return {
|
|
101
|
+
messages: messages.filter((message) => message !== null),
|
|
102
|
+
nextPageToken: response.data.nextPageToken ?? undefined
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
transformMessage(message) {
|
|
106
|
+
const headers = message.payload?.headers ?? [];
|
|
107
|
+
const subject = headerValue(headers, "Subject") ?? "";
|
|
108
|
+
const from = parseAddress(headerValue(headers, "From")) ?? inferFallbackAddress("from", message.id);
|
|
109
|
+
const to = parseAddressList(headerValue(headers, "To"));
|
|
110
|
+
const cc = parseAddressList(headerValue(headers, "Cc"));
|
|
111
|
+
const bcc = parseAddressList(headerValue(headers, "Bcc"));
|
|
112
|
+
const replyTo = parseAddress(headerValue(headers, "Reply-To"));
|
|
113
|
+
const { text, html, attachments } = extractContent(message.payload);
|
|
114
|
+
const timestamp = message.internalDate ? new Date(Number(message.internalDate)) : new Date;
|
|
115
|
+
const metadata = {
|
|
116
|
+
...message.labelIds?.length ? { labelIds: message.labelIds.join(",") } : {},
|
|
117
|
+
...message.historyId ? { historyId: message.historyId } : {}
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
id: message.id ?? "",
|
|
121
|
+
threadId: message.threadId ?? "",
|
|
122
|
+
subject,
|
|
123
|
+
from,
|
|
124
|
+
to,
|
|
125
|
+
cc,
|
|
126
|
+
bcc,
|
|
127
|
+
replyTo: replyTo ?? undefined,
|
|
128
|
+
sentAt: timestamp,
|
|
129
|
+
receivedAt: timestamp,
|
|
130
|
+
textBody: text ?? undefined,
|
|
131
|
+
htmlBody: html ?? undefined,
|
|
132
|
+
attachments,
|
|
133
|
+
headers: Object.fromEntries(headers.map((header) => [header.name ?? "", header.value ?? ""])),
|
|
134
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
127
138
|
function headerValue(headers, name) {
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
const header = headers.find((candidate) => candidate.name?.toLowerCase() === name.toLowerCase());
|
|
140
|
+
const value = header?.value;
|
|
141
|
+
return typeof value === "string" ? value : undefined;
|
|
130
142
|
}
|
|
131
143
|
function parseAddress(header) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
const addresses = parseAddressList(header);
|
|
145
|
+
if (addresses.length === 0) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const firstAddress = addresses[0];
|
|
149
|
+
return firstAddress || null;
|
|
135
150
|
}
|
|
136
151
|
function inferFallbackAddress(field, messageId) {
|
|
137
|
-
|
|
152
|
+
const suffix = messageId ? messageId.replace(/[^\w]/g, "").slice(-8) || "unknown" : "unknown";
|
|
153
|
+
return {
|
|
154
|
+
email: `${field}-${suffix}@mail.local`
|
|
155
|
+
};
|
|
138
156
|
}
|
|
139
157
|
function parseAddressList(header) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
if (!header)
|
|
159
|
+
return [];
|
|
160
|
+
return header.split(",").map((part) => part.trim()).filter(Boolean).map((value) => {
|
|
161
|
+
const match = value.match(/^(?:"?([^"]*)"?\s)?<?([^<>]+)>?$/);
|
|
162
|
+
if (!match) {
|
|
163
|
+
return { email: value };
|
|
164
|
+
}
|
|
165
|
+
const name = match[1]?.trim();
|
|
166
|
+
const email = match[2]?.trim();
|
|
167
|
+
if (!email) {
|
|
168
|
+
return { email: value };
|
|
169
|
+
}
|
|
170
|
+
return name ? { email, name } : { email };
|
|
171
|
+
});
|
|
152
172
|
}
|
|
153
173
|
function dedupeAddresses(addresses) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
174
|
+
const map = new Map;
|
|
175
|
+
for (const address of addresses) {
|
|
176
|
+
if (!address)
|
|
177
|
+
continue;
|
|
178
|
+
map.set(address.email.toLowerCase(), address);
|
|
179
|
+
}
|
|
180
|
+
return Array.from(map.values());
|
|
160
181
|
}
|
|
161
182
|
function extractContent(payload) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
if (!payload) {
|
|
184
|
+
return { attachments: [] };
|
|
185
|
+
}
|
|
186
|
+
const attachments = [];
|
|
187
|
+
const visit = (part) => {
|
|
188
|
+
if (!part)
|
|
189
|
+
return {};
|
|
190
|
+
if (part.filename && part.body?.attachmentId) {
|
|
191
|
+
attachments.push({
|
|
192
|
+
id: part.body.attachmentId,
|
|
193
|
+
filename: part.filename,
|
|
194
|
+
contentType: part.mimeType ?? "application/octet-stream",
|
|
195
|
+
sizeBytes: part.body.size ?? undefined
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const mimeType = part.mimeType ?? "";
|
|
199
|
+
const data = part.body?.data;
|
|
200
|
+
if (mimeType === "text/plain" && data) {
|
|
201
|
+
return { text: decodeBase64Url(data) };
|
|
202
|
+
}
|
|
203
|
+
if (mimeType === "text/html" && data) {
|
|
204
|
+
return { html: decodeBase64Url(data) };
|
|
205
|
+
}
|
|
206
|
+
if (part.parts?.length) {
|
|
207
|
+
return part.parts.reduce((acc, nested) => {
|
|
208
|
+
const value = visit(nested);
|
|
209
|
+
return {
|
|
210
|
+
text: value.text ?? acc.text,
|
|
211
|
+
html: value.html ?? acc.html
|
|
212
|
+
};
|
|
213
|
+
}, {});
|
|
214
|
+
}
|
|
215
|
+
return {};
|
|
216
|
+
};
|
|
217
|
+
const { text, html } = visit(payload);
|
|
218
|
+
return { text, html, attachments };
|
|
191
219
|
}
|
|
192
220
|
function decodeBase64Url(data) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
221
|
+
const normalized = data.replace(/-/g, "+").replace(/_/g, "/");
|
|
222
|
+
const padding = normalized.length % 4;
|
|
223
|
+
const padded = padding === 0 ? normalized : normalized + "=".repeat(4 - padding);
|
|
224
|
+
return Buffer.from(padded, "base64").toString("utf-8");
|
|
197
225
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//# sourceMappingURL=gmail-inbound.js.map
|
|
226
|
+
export {
|
|
227
|
+
GmailInboundProvider
|
|
228
|
+
};
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
userId?: string;
|
|
8
|
-
gmail?: gmail_v1.Gmail;
|
|
1
|
+
import { type gmail_v1 } from 'googleapis';
|
|
2
|
+
import type { EmailOutboundMessage, EmailOutboundProvider, EmailOutboundResult } from '../email';
|
|
3
|
+
export interface GmailOutboundProviderOptions {
|
|
4
|
+
auth: gmail_v1.Options['auth'];
|
|
5
|
+
userId?: string;
|
|
6
|
+
gmail?: gmail_v1.Gmail;
|
|
9
7
|
}
|
|
10
|
-
declare class GmailOutboundProvider implements
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
export declare class GmailOutboundProvider implements EmailOutboundProvider {
|
|
9
|
+
private readonly gmail;
|
|
10
|
+
private readonly userId;
|
|
11
|
+
private readonly auth;
|
|
12
|
+
constructor(options: GmailOutboundProviderOptions);
|
|
13
|
+
sendEmail(message: EmailOutboundMessage): Promise<EmailOutboundResult>;
|
|
16
14
|
}
|
|
17
|
-
//#endregion
|
|
18
|
-
export { GmailOutboundProvider, GmailOutboundProviderOptions };
|
|
19
15
|
//# sourceMappingURL=gmail-outbound.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gmail-outbound.d.ts","
|
|
1
|
+
{"version":3,"file":"gmail-outbound.d.ts","sourceRoot":"","sources":["../../src/impls/gmail-outbound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAEV,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC;CACxB;AAED,qBAAa,qBAAsB,YAAW,qBAAqB;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;gBAEpC,OAAO,EAAE,4BAA4B;IAW3C,SAAS,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAiB7E"}
|