@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
@@ -0,0 +1,159 @@
1
+ // src/impls/posthog-reader.ts
2
+ class PosthogAnalyticsReader {
3
+ projectId;
4
+ client;
5
+ constructor(options) {
6
+ this.projectId = options.projectId;
7
+ this.client = options.client;
8
+ }
9
+ async queryHogQL(input) {
10
+ const projectId = resolveProjectId(undefined, this.projectId);
11
+ const response = await this.client.request({
12
+ method: "POST",
13
+ path: `/api/projects/${projectId}/query`,
14
+ body: {
15
+ query: {
16
+ kind: "HogQLQuery",
17
+ query: input.query,
18
+ values: input.values
19
+ }
20
+ }
21
+ });
22
+ return response.data;
23
+ }
24
+ async getEvents(input) {
25
+ const projectId = resolveProjectId(input.projectId, this.projectId);
26
+ const response = await this.client.request({
27
+ method: "GET",
28
+ path: `/api/projects/${projectId}/events/`,
29
+ query: {
30
+ event: input.event ?? resolveSingleEvent(input.events),
31
+ events: resolveEventList(input.events),
32
+ distinct_id: input.distinctId,
33
+ order_by: input.orderBy,
34
+ limit: input.limit,
35
+ offset: input.offset,
36
+ properties: input.properties ? JSON.stringify(input.properties) : undefined,
37
+ ...buildEventDateQuery(input.dateRange)
38
+ }
39
+ });
40
+ return response.data;
41
+ }
42
+ async getPersons(input) {
43
+ const projectId = resolveProjectId(input.projectId, this.projectId);
44
+ const response = await this.client.request({
45
+ method: "GET",
46
+ path: `/api/projects/${projectId}/persons/`,
47
+ query: {
48
+ cohort_id: input.cohortId,
49
+ search: input.search,
50
+ limit: input.limit,
51
+ offset: input.offset,
52
+ properties: input.properties ? JSON.stringify(input.properties) : undefined
53
+ }
54
+ });
55
+ return response.data;
56
+ }
57
+ async getInsights(input) {
58
+ const projectId = resolveProjectId(input.projectId, this.projectId);
59
+ const response = await this.client.request({
60
+ method: "GET",
61
+ path: `/api/projects/${projectId}/insights/`,
62
+ query: {
63
+ insight: input.insightType,
64
+ limit: input.limit,
65
+ offset: input.offset
66
+ }
67
+ });
68
+ return response.data;
69
+ }
70
+ async getInsightResult(input) {
71
+ const projectId = resolveProjectId(input.projectId, this.projectId);
72
+ const response = await this.client.request({
73
+ method: "GET",
74
+ path: `/api/projects/${projectId}/insights/${input.insightId}/`
75
+ });
76
+ return response.data;
77
+ }
78
+ async getCohorts(input) {
79
+ const projectId = resolveProjectId(input.projectId, this.projectId);
80
+ const response = await this.client.request({
81
+ method: "GET",
82
+ path: `/api/projects/${projectId}/cohorts/`,
83
+ query: {
84
+ limit: input.limit,
85
+ offset: input.offset
86
+ }
87
+ });
88
+ return response.data;
89
+ }
90
+ async getFeatureFlags(input) {
91
+ const projectId = resolveProjectId(input.projectId, this.projectId);
92
+ const response = await this.client.request({
93
+ method: "GET",
94
+ path: `/api/projects/${projectId}/feature_flags/`,
95
+ query: {
96
+ active: input.active,
97
+ limit: input.limit,
98
+ offset: input.offset
99
+ }
100
+ });
101
+ return response.data;
102
+ }
103
+ async getAnnotations(input) {
104
+ const projectId = resolveProjectId(input.projectId, this.projectId);
105
+ const response = await this.client.request({
106
+ method: "GET",
107
+ path: `/api/projects/${projectId}/annotations/`,
108
+ query: {
109
+ limit: input.limit,
110
+ offset: input.offset,
111
+ ...buildAnnotationDateQuery(input.dateRange)
112
+ }
113
+ });
114
+ return response.data;
115
+ }
116
+ }
117
+ function resolveProjectId(inputProjectId, defaultProjectId) {
118
+ const projectId = inputProjectId ?? defaultProjectId;
119
+ if (!projectId) {
120
+ throw new Error("PostHog projectId is required for API reads.");
121
+ }
122
+ return projectId;
123
+ }
124
+ function resolveSingleEvent(events) {
125
+ if (!events || events.length !== 1)
126
+ return;
127
+ return events[0];
128
+ }
129
+ function resolveEventList(events) {
130
+ if (!events || events.length <= 1)
131
+ return;
132
+ return events.join(",");
133
+ }
134
+ function buildEventDateQuery(range) {
135
+ const after = formatDate(range?.from);
136
+ const before = formatDate(range?.to);
137
+ return {
138
+ after,
139
+ before,
140
+ timezone: range?.timezone
141
+ };
142
+ }
143
+ function buildAnnotationDateQuery(range) {
144
+ const dateFrom = formatDate(range?.from);
145
+ const dateTo = formatDate(range?.to);
146
+ return {
147
+ date_from: dateFrom,
148
+ date_to: dateTo,
149
+ timezone: range?.timezone
150
+ };
151
+ }
152
+ function formatDate(value) {
153
+ if (!value)
154
+ return;
155
+ return typeof value === "string" ? value : value.toISOString();
156
+ }
157
+ export {
158
+ PosthogAnalyticsReader
159
+ };
@@ -0,0 +1,38 @@
1
+ // src/impls/posthog-utils.ts
2
+ function normalizeHost(host) {
3
+ return host.replace(/\/$/, "");
4
+ }
5
+ function buildUrl(host, path, query) {
6
+ if (/^https?:\/\//.test(path)) {
7
+ return appendQuery(path, query);
8
+ }
9
+ const normalizedPath = path.replace(/^\/+/, "");
10
+ return appendQuery(`${host}/${normalizedPath}`, query);
11
+ }
12
+ function appendQuery(url, query) {
13
+ if (!query)
14
+ return url;
15
+ const params = new URLSearchParams;
16
+ Object.entries(query).forEach(([key, value]) => {
17
+ if (value === undefined)
18
+ return;
19
+ params.set(key, String(value));
20
+ });
21
+ const suffix = params.toString();
22
+ return suffix ? `${url}?${suffix}` : url;
23
+ }
24
+ function parseJson(value) {
25
+ if (!value)
26
+ return {};
27
+ try {
28
+ return JSON.parse(value);
29
+ } catch {
30
+ return value;
31
+ }
32
+ }
33
+ export {
34
+ parseJson,
35
+ normalizeHost,
36
+ buildUrl,
37
+ appendQuery
38
+ };
@@ -0,0 +1,322 @@
1
+ // src/impls/posthog-reader.ts
2
+ class PosthogAnalyticsReader {
3
+ projectId;
4
+ client;
5
+ constructor(options) {
6
+ this.projectId = options.projectId;
7
+ this.client = options.client;
8
+ }
9
+ async queryHogQL(input) {
10
+ const projectId = resolveProjectId(undefined, this.projectId);
11
+ const response = await this.client.request({
12
+ method: "POST",
13
+ path: `/api/projects/${projectId}/query`,
14
+ body: {
15
+ query: {
16
+ kind: "HogQLQuery",
17
+ query: input.query,
18
+ values: input.values
19
+ }
20
+ }
21
+ });
22
+ return response.data;
23
+ }
24
+ async getEvents(input) {
25
+ const projectId = resolveProjectId(input.projectId, this.projectId);
26
+ const response = await this.client.request({
27
+ method: "GET",
28
+ path: `/api/projects/${projectId}/events/`,
29
+ query: {
30
+ event: input.event ?? resolveSingleEvent(input.events),
31
+ events: resolveEventList(input.events),
32
+ distinct_id: input.distinctId,
33
+ order_by: input.orderBy,
34
+ limit: input.limit,
35
+ offset: input.offset,
36
+ properties: input.properties ? JSON.stringify(input.properties) : undefined,
37
+ ...buildEventDateQuery(input.dateRange)
38
+ }
39
+ });
40
+ return response.data;
41
+ }
42
+ async getPersons(input) {
43
+ const projectId = resolveProjectId(input.projectId, this.projectId);
44
+ const response = await this.client.request({
45
+ method: "GET",
46
+ path: `/api/projects/${projectId}/persons/`,
47
+ query: {
48
+ cohort_id: input.cohortId,
49
+ search: input.search,
50
+ limit: input.limit,
51
+ offset: input.offset,
52
+ properties: input.properties ? JSON.stringify(input.properties) : undefined
53
+ }
54
+ });
55
+ return response.data;
56
+ }
57
+ async getInsights(input) {
58
+ const projectId = resolveProjectId(input.projectId, this.projectId);
59
+ const response = await this.client.request({
60
+ method: "GET",
61
+ path: `/api/projects/${projectId}/insights/`,
62
+ query: {
63
+ insight: input.insightType,
64
+ limit: input.limit,
65
+ offset: input.offset
66
+ }
67
+ });
68
+ return response.data;
69
+ }
70
+ async getInsightResult(input) {
71
+ const projectId = resolveProjectId(input.projectId, this.projectId);
72
+ const response = await this.client.request({
73
+ method: "GET",
74
+ path: `/api/projects/${projectId}/insights/${input.insightId}/`
75
+ });
76
+ return response.data;
77
+ }
78
+ async getCohorts(input) {
79
+ const projectId = resolveProjectId(input.projectId, this.projectId);
80
+ const response = await this.client.request({
81
+ method: "GET",
82
+ path: `/api/projects/${projectId}/cohorts/`,
83
+ query: {
84
+ limit: input.limit,
85
+ offset: input.offset
86
+ }
87
+ });
88
+ return response.data;
89
+ }
90
+ async getFeatureFlags(input) {
91
+ const projectId = resolveProjectId(input.projectId, this.projectId);
92
+ const response = await this.client.request({
93
+ method: "GET",
94
+ path: `/api/projects/${projectId}/feature_flags/`,
95
+ query: {
96
+ active: input.active,
97
+ limit: input.limit,
98
+ offset: input.offset
99
+ }
100
+ });
101
+ return response.data;
102
+ }
103
+ async getAnnotations(input) {
104
+ const projectId = resolveProjectId(input.projectId, this.projectId);
105
+ const response = await this.client.request({
106
+ method: "GET",
107
+ path: `/api/projects/${projectId}/annotations/`,
108
+ query: {
109
+ limit: input.limit,
110
+ offset: input.offset,
111
+ ...buildAnnotationDateQuery(input.dateRange)
112
+ }
113
+ });
114
+ return response.data;
115
+ }
116
+ }
117
+ function resolveProjectId(inputProjectId, defaultProjectId) {
118
+ const projectId = inputProjectId ?? defaultProjectId;
119
+ if (!projectId) {
120
+ throw new Error("PostHog projectId is required for API reads.");
121
+ }
122
+ return projectId;
123
+ }
124
+ function resolveSingleEvent(events) {
125
+ if (!events || events.length !== 1)
126
+ return;
127
+ return events[0];
128
+ }
129
+ function resolveEventList(events) {
130
+ if (!events || events.length <= 1)
131
+ return;
132
+ return events.join(",");
133
+ }
134
+ function buildEventDateQuery(range) {
135
+ const after = formatDate(range?.from);
136
+ const before = formatDate(range?.to);
137
+ return {
138
+ after,
139
+ before,
140
+ timezone: range?.timezone
141
+ };
142
+ }
143
+ function buildAnnotationDateQuery(range) {
144
+ const dateFrom = formatDate(range?.from);
145
+ const dateTo = formatDate(range?.to);
146
+ return {
147
+ date_from: dateFrom,
148
+ date_to: dateTo,
149
+ timezone: range?.timezone
150
+ };
151
+ }
152
+ function formatDate(value) {
153
+ if (!value)
154
+ return;
155
+ return typeof value === "string" ? value : value.toISOString();
156
+ }
157
+
158
+ // src/impls/posthog-utils.ts
159
+ function normalizeHost(host) {
160
+ return host.replace(/\/$/, "");
161
+ }
162
+ function buildUrl(host, path, query) {
163
+ if (/^https?:\/\//.test(path)) {
164
+ return appendQuery(path, query);
165
+ }
166
+ const normalizedPath = path.replace(/^\/+/, "");
167
+ return appendQuery(`${host}/${normalizedPath}`, query);
168
+ }
169
+ function appendQuery(url, query) {
170
+ if (!query)
171
+ return url;
172
+ const params = new URLSearchParams;
173
+ Object.entries(query).forEach(([key, value]) => {
174
+ if (value === undefined)
175
+ return;
176
+ params.set(key, String(value));
177
+ });
178
+ const suffix = params.toString();
179
+ return suffix ? `${url}?${suffix}` : url;
180
+ }
181
+ function parseJson(value) {
182
+ if (!value)
183
+ return {};
184
+ try {
185
+ return JSON.parse(value);
186
+ } catch {
187
+ return value;
188
+ }
189
+ }
190
+
191
+ // src/impls/posthog.ts
192
+ import { PostHog } from "posthog-node";
193
+ var DEFAULT_POSTHOG_HOST = "https://app.posthog.com";
194
+
195
+ class PosthogAnalyticsProvider {
196
+ host;
197
+ projectId;
198
+ projectApiKey;
199
+ personalApiKey;
200
+ mcpUrl;
201
+ fetchFn;
202
+ client;
203
+ reader;
204
+ constructor(options) {
205
+ this.host = normalizeHost(options.host ?? DEFAULT_POSTHOG_HOST);
206
+ this.projectId = options.projectId;
207
+ this.projectApiKey = options.projectApiKey;
208
+ this.personalApiKey = options.personalApiKey;
209
+ this.mcpUrl = options.mcpUrl;
210
+ this.fetchFn = options.fetch ?? fetch;
211
+ this.client = options.client ?? (options.projectApiKey ? new PostHog(options.projectApiKey, {
212
+ host: this.host,
213
+ requestTimeout: options.requestTimeoutMs ?? 1e4
214
+ }) : undefined);
215
+ this.reader = new PosthogAnalyticsReader({
216
+ projectId: this.projectId,
217
+ client: { request: this.request.bind(this) }
218
+ });
219
+ }
220
+ async capture(event) {
221
+ if (!this.client) {
222
+ throw new Error("PostHog projectApiKey is required for capture.");
223
+ }
224
+ await this.client.capture({
225
+ distinctId: event.distinctId,
226
+ event: event.event,
227
+ properties: event.properties,
228
+ timestamp: event.timestamp,
229
+ groups: event.groups
230
+ });
231
+ }
232
+ async identify(input) {
233
+ if (!this.client) {
234
+ throw new Error("PostHog projectApiKey is required for identify.");
235
+ }
236
+ await this.client.identify({
237
+ distinctId: input.distinctId,
238
+ properties: {
239
+ ...input.properties ? { $set: input.properties } : {},
240
+ ...input.setOnce ? { $set_once: input.setOnce } : {}
241
+ }
242
+ });
243
+ }
244
+ async queryHogQL(input) {
245
+ return this.reader.queryHogQL(input);
246
+ }
247
+ async getEvents(input) {
248
+ return this.reader.getEvents(input);
249
+ }
250
+ async getPersons(input) {
251
+ return this.reader.getPersons(input);
252
+ }
253
+ async getInsights(input) {
254
+ return this.reader.getInsights(input);
255
+ }
256
+ async getInsightResult(input) {
257
+ return this.reader.getInsightResult(input);
258
+ }
259
+ async getCohorts(input) {
260
+ return this.reader.getCohorts(input);
261
+ }
262
+ async getFeatureFlags(input) {
263
+ return this.reader.getFeatureFlags(input);
264
+ }
265
+ async getAnnotations(input) {
266
+ return this.reader.getAnnotations(input);
267
+ }
268
+ async request(request) {
269
+ if (!this.personalApiKey) {
270
+ throw new Error("PostHog personalApiKey is required for API requests.");
271
+ }
272
+ const url = buildUrl(this.host, request.path, request.query);
273
+ const response = await this.fetchFn(url, {
274
+ method: request.method,
275
+ headers: {
276
+ Authorization: `Bearer ${this.personalApiKey}`,
277
+ "Content-Type": "application/json",
278
+ ...request.headers ?? {}
279
+ },
280
+ body: request.body ? JSON.stringify(request.body) : undefined
281
+ });
282
+ const text = await response.text();
283
+ const data = parseJson(text);
284
+ return {
285
+ status: response.status,
286
+ data,
287
+ headers: Object.fromEntries(response.headers.entries())
288
+ };
289
+ }
290
+ async callMcpTool(call) {
291
+ if (!this.mcpUrl) {
292
+ throw new Error("PostHog MCP URL is not configured.");
293
+ }
294
+ const response = await this.fetchFn(this.mcpUrl, {
295
+ method: "POST",
296
+ headers: {
297
+ "Content-Type": "application/json"
298
+ },
299
+ body: JSON.stringify({
300
+ jsonrpc: "2.0",
301
+ id: 1,
302
+ method: "tools/call",
303
+ params: {
304
+ name: call.name,
305
+ arguments: call.arguments ?? {}
306
+ }
307
+ })
308
+ });
309
+ if (!response.ok) {
310
+ const body = await response.text();
311
+ throw new Error(`PostHog MCP error (${response.status}): ${body}`);
312
+ }
313
+ const result = await response.json();
314
+ if (result.error) {
315
+ throw new Error(result.error.message ?? "PostHog MCP error");
316
+ }
317
+ return result.result ?? null;
318
+ }
319
+ }
320
+ export {
321
+ PosthogAnalyticsProvider
322
+ };
@@ -0,0 +1,60 @@
1
+ // src/impls/postmark-email.ts
2
+ import { ServerClient } from "postmark";
3
+
4
+ class PostmarkEmailProvider {
5
+ client;
6
+ defaultFromEmail;
7
+ messageStream;
8
+ constructor(options) {
9
+ this.client = options.client ?? new ServerClient(options.serverToken, {
10
+ useHttps: true
11
+ });
12
+ this.defaultFromEmail = options.defaultFromEmail;
13
+ this.messageStream = options.messageStream;
14
+ }
15
+ async sendEmail(message) {
16
+ const request = {
17
+ From: formatAddress(message.from) ?? this.defaultFromEmail,
18
+ To: message.to.map((addr) => formatAddress(addr)).join(", "),
19
+ Cc: message.cc?.map((addr) => formatAddress(addr)).join(", ") || undefined,
20
+ Bcc: message.bcc?.map((addr) => formatAddress(addr)).join(", ") || undefined,
21
+ ReplyTo: message.replyTo ? formatAddress(message.replyTo) : undefined,
22
+ Subject: message.subject,
23
+ TextBody: message.textBody,
24
+ HtmlBody: message.htmlBody,
25
+ Headers: message.headers ? Object.entries(message.headers).map(([name, value]) => ({
26
+ Name: name,
27
+ Value: value
28
+ })) : undefined,
29
+ MessageStream: this.messageStream,
30
+ Attachments: buildAttachments(message)
31
+ };
32
+ const response = await this.client.sendEmail(request);
33
+ return {
34
+ id: response.MessageID,
35
+ providerMessageId: response.MessageID,
36
+ queuedAt: new Date(response.SubmittedAt ?? new Date().toISOString())
37
+ };
38
+ }
39
+ }
40
+ function formatAddress(address) {
41
+ if (address.name) {
42
+ return `"${address.name}" <${address.email}>`;
43
+ }
44
+ return address.email;
45
+ }
46
+ function buildAttachments(message) {
47
+ if (!message.attachments?.length)
48
+ return;
49
+ return message.attachments.filter((attachment) => attachment.data).map((attachment) => ({
50
+ Name: attachment.filename,
51
+ Content: Buffer.from(attachment.data ?? new Uint8Array).toString("base64"),
52
+ ContentType: attachment.contentType,
53
+ ContentID: null,
54
+ ContentLength: attachment.sizeBytes,
55
+ Disposition: "attachment"
56
+ }));
57
+ }
58
+ export {
59
+ PostmarkEmailProvider
60
+ };