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