corsair 0.0.2 → 0.1.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 (364) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/drizzle/index.d.ts +2 -0
  3. package/dist/adapters/drizzle/index.d.ts.map +1 -0
  4. package/dist/adapters/drizzle/index.js +1 -0
  5. package/dist/adapters/drizzle/postgres.d.ts +34 -0
  6. package/dist/adapters/drizzle/postgres.d.ts.map +1 -0
  7. package/dist/adapters/drizzle/postgres.js +193 -0
  8. package/dist/adapters/index.d.ts +6 -0
  9. package/dist/adapters/index.d.ts.map +1 -0
  10. package/dist/adapters/index.js +5 -0
  11. package/dist/adapters/kysely/index.d.ts +2 -0
  12. package/dist/adapters/kysely/index.d.ts.map +1 -0
  13. package/dist/adapters/kysely/index.js +1 -0
  14. package/dist/adapters/kysely/postgres.d.ts +19 -0
  15. package/dist/adapters/kysely/postgres.d.ts.map +1 -0
  16. package/dist/adapters/kysely/postgres.js +138 -0
  17. package/dist/adapters/prisma/index.d.ts +2 -0
  18. package/dist/adapters/prisma/index.d.ts.map +1 -0
  19. package/dist/adapters/prisma/index.js +1 -0
  20. package/dist/adapters/prisma/postgres.d.ts +17 -0
  21. package/dist/adapters/prisma/postgres.d.ts.map +1 -0
  22. package/dist/adapters/prisma/postgres.js +176 -0
  23. package/dist/adapters/tenant.d.ts +13 -0
  24. package/dist/adapters/tenant.d.ts.map +1 -0
  25. package/dist/adapters/tenant.js +95 -0
  26. package/dist/adapters/types.d.ts +160 -0
  27. package/dist/adapters/types.d.ts.map +1 -0
  28. package/dist/adapters/types.js +1 -0
  29. package/dist/async-core/ApiError.d.ts +21 -0
  30. package/dist/async-core/ApiError.d.ts.map +1 -0
  31. package/dist/async-core/ApiError.js +27 -0
  32. package/dist/async-core/ApiRequestOptions.d.ts +14 -0
  33. package/dist/async-core/ApiRequestOptions.d.ts.map +1 -0
  34. package/dist/async-core/ApiRequestOptions.js +1 -0
  35. package/dist/async-core/ApiResult.d.ts +8 -0
  36. package/dist/async-core/ApiResult.d.ts.map +1 -0
  37. package/dist/async-core/ApiResult.js +1 -0
  38. package/dist/async-core/CancelablePromise.d.ts +21 -0
  39. package/dist/async-core/CancelablePromise.d.ts.map +1 -0
  40. package/dist/async-core/CancelablePromise.js +95 -0
  41. package/dist/async-core/OpenAPI.d.ts +16 -0
  42. package/dist/async-core/OpenAPI.d.ts.map +1 -0
  43. package/dist/async-core/OpenAPI.js +1 -0
  44. package/dist/async-core/rate-limit.d.ts +25 -0
  45. package/dist/async-core/rate-limit.d.ts.map +1 -0
  46. package/dist/async-core/rate-limit.js +79 -0
  47. package/dist/async-core/request.d.ts +9 -0
  48. package/dist/async-core/request.d.ts.map +1 -0
  49. package/dist/async-core/request.js +313 -0
  50. package/dist/async-core/webhook-handler.d.ts +15 -0
  51. package/dist/async-core/webhook-handler.d.ts.map +1 -0
  52. package/dist/async-core/webhook-handler.js +40 -0
  53. package/dist/async-core/webhook-utils.d.ts +4 -0
  54. package/dist/async-core/webhook-utils.d.ts.map +1 -0
  55. package/dist/async-core/webhook-utils.js +57 -0
  56. package/dist/constants.d.ts +7 -0
  57. package/dist/constants.d.ts.map +1 -0
  58. package/dist/constants.js +9 -0
  59. package/dist/core/client/index.d.ts +61 -0
  60. package/dist/core/client/index.d.ts.map +1 -0
  61. package/dist/core/client/index.js +332 -0
  62. package/dist/core/constants.d.ts +6 -0
  63. package/dist/core/constants.d.ts.map +1 -0
  64. package/dist/core/constants.js +7 -0
  65. package/dist/core/endpoints/bind.d.ts +31 -0
  66. package/dist/core/endpoints/bind.d.ts.map +1 -0
  67. package/dist/core/endpoints/bind.js +117 -0
  68. package/dist/core/endpoints/index.d.ts +76 -0
  69. package/dist/core/endpoints/index.d.ts.map +1 -0
  70. package/dist/core/endpoints/index.js +1 -0
  71. package/dist/core/errors/handler.d.ts +11 -0
  72. package/dist/core/errors/handler.d.ts.map +1 -0
  73. package/dist/core/errors/handler.js +30 -0
  74. package/dist/core/errors/index.d.ts +30 -0
  75. package/dist/core/errors/index.d.ts.map +1 -0
  76. package/dist/core/errors/index.js +1 -0
  77. package/dist/core/index.d.ts +28 -0
  78. package/dist/core/index.d.ts.map +1 -0
  79. package/dist/core/index.js +20 -0
  80. package/dist/core/plugins/index.d.ts +180 -0
  81. package/dist/core/plugins/index.d.ts.map +1 -0
  82. package/dist/core/plugins/index.js +1 -0
  83. package/dist/core/utils.d.ts +29 -0
  84. package/dist/core/utils.d.ts.map +1 -0
  85. package/dist/core/utils.js +42 -0
  86. package/dist/core/webhooks/bind.d.ts +25 -0
  87. package/dist/core/webhooks/bind.d.ts.map +1 -0
  88. package/dist/core/webhooks/bind.js +65 -0
  89. package/dist/core/webhooks/index.d.ts +134 -0
  90. package/dist/core/webhooks/index.d.ts.map +1 -0
  91. package/dist/core/webhooks/index.js +1 -0
  92. package/dist/db/index.d.ts +100 -0
  93. package/dist/db/index.d.ts.map +1 -0
  94. package/dist/db/index.js +50 -0
  95. package/dist/db/orm.d.ts +320 -0
  96. package/dist/db/orm.d.ts.map +1 -0
  97. package/dist/db/orm.js +707 -0
  98. package/dist/index.d.ts +13 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +11 -0
  101. package/dist/plugins/gmail/client.d.ts +15 -0
  102. package/dist/plugins/gmail/client.d.ts.map +1 -0
  103. package/dist/plugins/gmail/client.js +95 -0
  104. package/dist/plugins/gmail/endpoints/drafts.d.ts +8 -0
  105. package/dist/plugins/gmail/endpoints/drafts.d.ts.map +1 -0
  106. package/dist/plugins/gmail/endpoints/drafts.js +147 -0
  107. package/dist/plugins/gmail/endpoints/index.d.ts +163 -0
  108. package/dist/plugins/gmail/endpoints/index.d.ts.map +1 -0
  109. package/dist/plugins/gmail/endpoints/index.js +38 -0
  110. package/dist/plugins/gmail/endpoints/labels.d.ts +7 -0
  111. package/dist/plugins/gmail/endpoints/labels.d.ts.map +1 -0
  112. package/dist/plugins/gmail/endpoints/labels.js +151 -0
  113. package/dist/plugins/gmail/endpoints/messages.d.ts +10 -0
  114. package/dist/plugins/gmail/endpoints/messages.d.ts.map +1 -0
  115. package/dist/plugins/gmail/endpoints/messages.js +294 -0
  116. package/dist/plugins/gmail/endpoints/threads.d.ts +8 -0
  117. package/dist/plugins/gmail/endpoints/threads.d.ts.map +1 -0
  118. package/dist/plugins/gmail/endpoints/threads.js +139 -0
  119. package/dist/plugins/gmail/endpoints/types.d.ts +30 -0
  120. package/dist/plugins/gmail/endpoints/types.d.ts.map +1 -0
  121. package/dist/plugins/gmail/endpoints/types.js +1 -0
  122. package/dist/plugins/gmail/index.d.ts +352 -0
  123. package/dist/plugins/gmail/index.d.ts.map +1 -0
  124. package/dist/plugins/gmail/index.js +58 -0
  125. package/dist/plugins/gmail/schema/database.d.ts +115 -0
  126. package/dist/plugins/gmail/schema/database.d.ts.map +1 -0
  127. package/dist/plugins/gmail/schema/database.js +59 -0
  128. package/dist/plugins/gmail/schema/index.d.ts +133 -0
  129. package/dist/plugins/gmail/schema/index.d.ts.map +1 -0
  130. package/dist/plugins/gmail/schema/index.js +17 -0
  131. package/dist/plugins/gmail/types.d.ts +119 -0
  132. package/dist/plugins/gmail/types.d.ts.map +1 -0
  133. package/dist/plugins/gmail/types.js +1 -0
  134. package/dist/plugins/gmail/webhooks/index.d.ts +52 -0
  135. package/dist/plugins/gmail/webhooks/index.d.ts.map +1 -0
  136. package/dist/plugins/gmail/webhooks/index.js +7 -0
  137. package/dist/plugins/gmail/webhooks/messages.d.ts +52 -0
  138. package/dist/plugins/gmail/webhooks/messages.d.ts.map +1 -0
  139. package/dist/plugins/gmail/webhooks/messages.js +520 -0
  140. package/dist/plugins/gmail/webhooks/types.d.ts +65 -0
  141. package/dist/plugins/gmail/webhooks/types.d.ts.map +1 -0
  142. package/dist/plugins/gmail/webhooks/types.js +1 -0
  143. package/dist/plugins/index.d.ts +6 -0
  144. package/dist/plugins/index.d.ts.map +1 -0
  145. package/dist/plugins/index.js +10 -0
  146. package/dist/plugins/linear/client.d.ts +32 -0
  147. package/dist/plugins/linear/client.d.ts.map +1 -0
  148. package/dist/plugins/linear/client.js +117 -0
  149. package/dist/plugins/linear/endpoints/comments.d.ts +6 -0
  150. package/dist/plugins/linear/endpoints/comments.d.ts.map +1 -0
  151. package/dist/plugins/linear/endpoints/comments.js +196 -0
  152. package/dist/plugins/linear/endpoints/index.d.ts +116 -0
  153. package/dist/plugins/linear/endpoints/index.d.ts.map +1 -0
  154. package/dist/plugins/linear/endpoints/index.js +29 -0
  155. package/dist/plugins/linear/endpoints/issues.d.ts +7 -0
  156. package/dist/plugins/linear/endpoints/issues.d.ts.map +1 -0
  157. package/dist/plugins/linear/endpoints/issues.js +447 -0
  158. package/dist/plugins/linear/endpoints/projects.d.ts +7 -0
  159. package/dist/plugins/linear/endpoints/projects.d.ts.map +1 -0
  160. package/dist/plugins/linear/endpoints/projects.js +277 -0
  161. package/dist/plugins/linear/endpoints/teams.d.ts +4 -0
  162. package/dist/plugins/linear/endpoints/teams.d.ts.map +1 -0
  163. package/dist/plugins/linear/endpoints/teams.js +95 -0
  164. package/dist/plugins/linear/endpoints/types.d.ts +295 -0
  165. package/dist/plugins/linear/endpoints/types.d.ts.map +1 -0
  166. package/dist/plugins/linear/endpoints/types.js +1 -0
  167. package/dist/plugins/linear/error-handlers.d.ts +46 -0
  168. package/dist/plugins/linear/error-handlers.d.ts.map +1 -0
  169. package/dist/plugins/linear/error-handlers.js +140 -0
  170. package/dist/plugins/linear/index.d.ts +1079 -0
  171. package/dist/plugins/linear/index.d.ts.map +1 -0
  172. package/dist/plugins/linear/index.js +62 -0
  173. package/dist/plugins/linear/schema/database.d.ts +234 -0
  174. package/dist/plugins/linear/schema/database.d.ts.map +1 -0
  175. package/dist/plugins/linear/schema/database.js +86 -0
  176. package/dist/plugins/linear/schema/index.d.ts +242 -0
  177. package/dist/plugins/linear/schema/index.d.ts.map +1 -0
  178. package/dist/plugins/linear/schema/index.js +15 -0
  179. package/dist/plugins/linear/webhooks/comments.d.ts +5 -0
  180. package/dist/plugins/linear/webhooks/comments.d.ts.map +1 -0
  181. package/dist/plugins/linear/webhooks/comments.js +103 -0
  182. package/dist/plugins/linear/webhooks/index.d.ts +44 -0
  183. package/dist/plugins/linear/webhooks/index.d.ts.map +1 -0
  184. package/dist/plugins/linear/webhooks/index.js +19 -0
  185. package/dist/plugins/linear/webhooks/issues.d.ts +5 -0
  186. package/dist/plugins/linear/webhooks/issues.d.ts.map +1 -0
  187. package/dist/plugins/linear/webhooks/issues.js +115 -0
  188. package/dist/plugins/linear/webhooks/projects.d.ts +5 -0
  189. package/dist/plugins/linear/webhooks/projects.d.ts.map +1 -0
  190. package/dist/plugins/linear/webhooks/projects.js +108 -0
  191. package/dist/plugins/linear/webhooks/types.d.ts +180 -0
  192. package/dist/plugins/linear/webhooks/types.d.ts.map +1 -0
  193. package/dist/plugins/linear/webhooks/types.js +16 -0
  194. package/dist/plugins/posthog/client.d.ts +36 -0
  195. package/dist/plugins/posthog/client.d.ts.map +1 -0
  196. package/dist/plugins/posthog/client.js +122 -0
  197. package/dist/plugins/posthog/endpoints/events.d.ts +7 -0
  198. package/dist/plugins/posthog/endpoints/events.d.ts.map +1 -0
  199. package/dist/plugins/posthog/endpoints/events.js +123 -0
  200. package/dist/plugins/posthog/endpoints/index.d.ts +33 -0
  201. package/dist/plugins/posthog/endpoints/index.d.ts.map +1 -0
  202. package/dist/plugins/posthog/endpoints/index.js +9 -0
  203. package/dist/plugins/posthog/endpoints/types.d.ts +28 -0
  204. package/dist/plugins/posthog/endpoints/types.d.ts.map +1 -0
  205. package/dist/plugins/posthog/endpoints/types.js +1 -0
  206. package/dist/plugins/posthog/index.d.ts +271 -0
  207. package/dist/plugins/posthog/index.d.ts.map +1 -0
  208. package/dist/plugins/posthog/index.js +32 -0
  209. package/dist/plugins/posthog/schema/database.d.ts +28 -0
  210. package/dist/plugins/posthog/schema/database.d.ts.map +1 -0
  211. package/dist/plugins/posthog/schema/database.js +10 -0
  212. package/dist/plugins/posthog/schema/index.d.ts +43 -0
  213. package/dist/plugins/posthog/schema/index.d.ts.map +1 -0
  214. package/dist/plugins/posthog/schema/index.js +12 -0
  215. package/dist/plugins/posthog/webhooks/events.d.ts +3 -0
  216. package/dist/plugins/posthog/webhooks/events.d.ts.map +1 -0
  217. package/dist/plugins/posthog/webhooks/events.js +33 -0
  218. package/dist/plugins/posthog/webhooks/index.d.ts +8 -0
  219. package/dist/plugins/posthog/webhooks/index.d.ts.map +1 -0
  220. package/dist/plugins/posthog/webhooks/index.js +5 -0
  221. package/dist/plugins/posthog/webhooks/types.d.ts +31 -0
  222. package/dist/plugins/posthog/webhooks/types.d.ts.map +1 -0
  223. package/dist/plugins/posthog/webhooks/types.js +12 -0
  224. package/dist/plugins/resend/client.d.ts +35 -0
  225. package/dist/plugins/resend/client.d.ts.map +1 -0
  226. package/dist/plugins/resend/client.js +101 -0
  227. package/dist/plugins/resend/endpoints/domains.d.ts +7 -0
  228. package/dist/plugins/resend/endpoints/domains.d.ts.map +1 -0
  229. package/dist/plugins/resend/endpoints/domains.js +115 -0
  230. package/dist/plugins/resend/endpoints/emails.d.ts +5 -0
  231. package/dist/plugins/resend/endpoints/emails.d.ts.map +1 -0
  232. package/dist/plugins/resend/endpoints/emails.js +96 -0
  233. package/dist/plugins/resend/endpoints/index.d.ts +50 -0
  234. package/dist/plugins/resend/endpoints/index.d.ts.map +1 -0
  235. package/dist/plugins/resend/endpoints/index.js +15 -0
  236. package/dist/plugins/resend/endpoints/types.d.ts +51 -0
  237. package/dist/plugins/resend/endpoints/types.d.ts.map +1 -0
  238. package/dist/plugins/resend/endpoints/types.js +1 -0
  239. package/dist/plugins/resend/index.d.ts +452 -0
  240. package/dist/plugins/resend/index.d.ts.map +1 -0
  241. package/dist/plugins/resend/index.js +48 -0
  242. package/dist/plugins/resend/schema/database.d.ts +42 -0
  243. package/dist/plugins/resend/schema/database.d.ts.map +1 -0
  244. package/dist/plugins/resend/schema/database.js +15 -0
  245. package/dist/plugins/resend/schema/index.d.ts +56 -0
  246. package/dist/plugins/resend/schema/index.d.ts.map +1 -0
  247. package/dist/plugins/resend/schema/index.js +13 -0
  248. package/dist/plugins/resend/webhooks/domains.d.ts +4 -0
  249. package/dist/plugins/resend/webhooks/domains.d.ts.map +1 -0
  250. package/dist/plugins/resend/webhooks/domains.js +57 -0
  251. package/dist/plugins/resend/webhooks/emails.d.ts +10 -0
  252. package/dist/plugins/resend/webhooks/emails.d.ts.map +1 -0
  253. package/dist/plugins/resend/webhooks/emails.js +138 -0
  254. package/dist/plugins/resend/webhooks/index.d.ts +46 -0
  255. package/dist/plugins/resend/webhooks/index.d.ts.map +1 -0
  256. package/dist/plugins/resend/webhooks/index.js +17 -0
  257. package/dist/plugins/resend/webhooks/types.d.ts +158 -0
  258. package/dist/plugins/resend/webhooks/types.d.ts.map +1 -0
  259. package/dist/plugins/resend/webhooks/types.js +9 -0
  260. package/dist/plugins/slack/client.d.ts +50 -0
  261. package/dist/plugins/slack/client.d.ts.map +1 -0
  262. package/dist/plugins/slack/client.js +127 -0
  263. package/dist/plugins/slack/endpoints/channels.d.ts +20 -0
  264. package/dist/plugins/slack/endpoints/channels.d.ts.map +1 -0
  265. package/dist/plugins/slack/endpoints/channels.js +417 -0
  266. package/dist/plugins/slack/endpoints/files.d.ts +5 -0
  267. package/dist/plugins/slack/endpoints/files.d.ts.map +1 -0
  268. package/dist/plugins/slack/endpoints/files.js +90 -0
  269. package/dist/plugins/slack/endpoints/index.d.ts +353 -0
  270. package/dist/plugins/slack/endpoints/index.d.ts.map +1 -0
  271. package/dist/plugins/slack/endpoints/index.js +64 -0
  272. package/dist/plugins/slack/endpoints/messages.d.ts +7 -0
  273. package/dist/plugins/slack/endpoints/messages.d.ts.map +1 -0
  274. package/dist/plugins/slack/endpoints/messages.js +143 -0
  275. package/dist/plugins/slack/endpoints/reactions.d.ts +8 -0
  276. package/dist/plugins/slack/endpoints/reactions.d.ts.map +1 -0
  277. package/dist/plugins/slack/endpoints/reactions.js +69 -0
  278. package/dist/plugins/slack/endpoints/stars.d.ts +5 -0
  279. package/dist/plugins/slack/endpoints/stars.d.ts.map +1 -0
  280. package/dist/plugins/slack/endpoints/stars.js +42 -0
  281. package/dist/plugins/slack/endpoints/types.d.ts +692 -0
  282. package/dist/plugins/slack/endpoints/types.d.ts.map +1 -0
  283. package/dist/plugins/slack/endpoints/types.js +1 -0
  284. package/dist/plugins/slack/endpoints/user-groups.d.ts +7 -0
  285. package/dist/plugins/slack/endpoints/user-groups.d.ts.map +1 -0
  286. package/dist/plugins/slack/endpoints/user-groups.js +138 -0
  287. package/dist/plugins/slack/endpoints/users.d.ts +7 -0
  288. package/dist/plugins/slack/endpoints/users.d.ts.map +1 -0
  289. package/dist/plugins/slack/endpoints/users.js +110 -0
  290. package/dist/plugins/slack/error-handlers.d.ts +40 -0
  291. package/dist/plugins/slack/error-handlers.d.ts.map +1 -0
  292. package/dist/plugins/slack/error-handlers.js +103 -0
  293. package/dist/plugins/slack/index.d.ts +2305 -0
  294. package/dist/plugins/slack/index.d.ts.map +1 -0
  295. package/dist/plugins/slack/index.js +110 -0
  296. package/dist/plugins/slack/schema/database.d.ts +346 -0
  297. package/dist/plugins/slack/schema/database.d.ts.map +1 -0
  298. package/dist/plugins/slack/schema/database.js +108 -0
  299. package/dist/plugins/slack/schema/index.d.ts +358 -0
  300. package/dist/plugins/slack/schema/index.d.ts.map +1 -0
  301. package/dist/plugins/slack/schema/index.js +17 -0
  302. package/dist/plugins/slack/webhooks/channels.d.ts +3 -0
  303. package/dist/plugins/slack/webhooks/channels.d.ts.map +1 -0
  304. package/dist/plugins/slack/webhooks/channels.js +44 -0
  305. package/dist/plugins/slack/webhooks/files.d.ts +5 -0
  306. package/dist/plugins/slack/webhooks/files.d.ts.map +1 -0
  307. package/dist/plugins/slack/webhooks/files.js +100 -0
  308. package/dist/plugins/slack/webhooks/index.d.ts +45 -0
  309. package/dist/plugins/slack/webhooks/index.d.ts.map +1 -0
  310. package/dist/plugins/slack/webhooks/index.js +25 -0
  311. package/dist/plugins/slack/webhooks/messages.d.ts +3 -0
  312. package/dist/plugins/slack/webhooks/messages.d.ts.map +1 -0
  313. package/dist/plugins/slack/webhooks/messages.js +40 -0
  314. package/dist/plugins/slack/webhooks/reactions.d.ts +3 -0
  315. package/dist/plugins/slack/webhooks/reactions.d.ts.map +1 -0
  316. package/dist/plugins/slack/webhooks/reactions.js +10 -0
  317. package/dist/plugins/slack/webhooks/types.d.ts +661 -0
  318. package/dist/plugins/slack/webhooks/types.d.ts.map +1 -0
  319. package/dist/plugins/slack/webhooks/types.js +22 -0
  320. package/dist/plugins/slack/webhooks/users.d.ts +4 -0
  321. package/dist/plugins/slack/webhooks/users.d.ts.map +1 -0
  322. package/dist/plugins/slack/webhooks/users.js +69 -0
  323. package/dist/plugins/utils/events.d.ts +31 -0
  324. package/dist/plugins/utils/events.d.ts.map +1 -0
  325. package/dist/plugins/utils/events.js +54 -0
  326. package/dist/tests/drizzle-adapter.test.d.ts +2 -0
  327. package/dist/tests/drizzle-adapter.test.d.ts.map +1 -0
  328. package/dist/tests/drizzle-adapter.test.js +534 -0
  329. package/dist/tests/error-handlers.test.d.ts +2 -0
  330. package/dist/tests/error-handlers.test.d.ts.map +1 -0
  331. package/dist/tests/error-handlers.test.js +454 -0
  332. package/dist/tests/hooks.test.d.ts +2 -0
  333. package/dist/tests/hooks.test.d.ts.map +1 -0
  334. package/dist/tests/hooks.test.js +372 -0
  335. package/dist/tests/multi-tenancy.test.d.ts +2 -0
  336. package/dist/tests/multi-tenancy.test.d.ts.map +1 -0
  337. package/dist/tests/multi-tenancy.test.js +279 -0
  338. package/dist/tests/setup-db.d.ts +7 -0
  339. package/dist/tests/setup-db.d.ts.map +1 -0
  340. package/dist/tests/setup-db.js +141 -0
  341. package/dist/tests/slack-rate-limit-integration.test.d.ts +2 -0
  342. package/dist/tests/slack-rate-limit-integration.test.d.ts.map +1 -0
  343. package/dist/tests/slack-rate-limit-integration.test.js +416 -0
  344. package/dist/tsup.config.d.ts +3 -0
  345. package/dist/tsup.config.d.ts.map +1 -0
  346. package/dist/tsup.config.js +26 -0
  347. package/dist/webhooks/index.d.ts +108 -0
  348. package/dist/webhooks/index.d.ts.map +1 -0
  349. package/dist/webhooks/index.js +195 -0
  350. package/package.json +141 -20
  351. package/.npmignore +0 -8
  352. package/README.md +0 -1
  353. package/index.js +0 -3
  354. package/lib/apigateway.js +0 -292
  355. package/lib/corsair.js +0 -236
  356. package/lib/deploy.js +0 -74
  357. package/lib/iam.js +0 -26
  358. package/lib/lambda.js +0 -104
  359. package/lib/platforms/awslambda.js +0 -46
  360. package/lib/platforms/http.js +0 -26
  361. package/lib/platforms/index.js +0 -29
  362. package/lib/request-templates.js +0 -47
  363. package/lib/response-templates.js +0 -22
  364. package/lib/statuses.json +0 -12
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 corsairdev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export { type DrizzleAdapterConfig, drizzleAdapter, } from './postgres';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../adapters/drizzle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,oBAAoB,EACzB,cAAc,GACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export { drizzleAdapter, } from './postgres';
@@ -0,0 +1,34 @@
1
+ import type { CorsairDbAdapter } from '../types';
2
+ export type DrizzleAdapterConfig = {
3
+ /**
4
+ * Corsair currently supports Postgres only.
5
+ */
6
+ provider: 'pg';
7
+ /**
8
+ * Optional Drizzle schema object. If omitted, we try `db._.fullSchema`.
9
+ */
10
+ schema?: Record<string, unknown> | undefined;
11
+ /**
12
+ * If your table objects are keyed differently in the schema.
13
+ */
14
+ tableNames?: {
15
+ integrations?: string | undefined;
16
+ accounts?: string | undefined;
17
+ entities?: string | undefined;
18
+ events?: string | undefined;
19
+ } | undefined;
20
+ adapterId?: string | undefined;
21
+ };
22
+ /**
23
+ * `drizzleAdapter(db, { provider: "pg" })`.
24
+ *
25
+ * Corsair currently supports Postgres only.
26
+ *
27
+ * Note on typing:
28
+ * - Drizzle's column/table types are schema-generic. Corsair does not own the user's schema types,
29
+ * so we accept `unknown` and do runtime validation.
30
+ * - We cast the schema columns into Drizzle expression helpers (`eq`, `inArray`, `ilike`) because
31
+ * those helpers require Drizzle's column types, which we cannot represent without the user's generics.
32
+ */
33
+ export declare function drizzleAdapter(db: unknown, config: DrizzleAdapterConfig): CorsairDbAdapter;
34
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../adapters/drizzle/postgres.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,gBAAgB,EAMhB,MAAM,UAAU,CAAC;AAyClB,MAAM,MAAM,oBAAoB,GAAG;IAClC;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7C;;OAEG;IACH,UAAU,CAAC,EACR;QACA,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAClC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B,GACD,SAAS,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAgIF;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC7B,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,oBAAoB,GAC1B,gBAAgB,CAiIlB"}
@@ -0,0 +1,193 @@
1
+ import { and, asc, count, desc, eq, ilike, inArray } from 'drizzle-orm';
2
+ function normalizeOperator(op) {
3
+ return op ?? '=';
4
+ }
5
+ function toArray(value) {
6
+ return Array.isArray(value) ? value : [value];
7
+ }
8
+ function getColumn(table, field) {
9
+ const col = table[field];
10
+ if (!col) {
11
+ throw new Error(`Drizzle adapter: column "${field}" was not found on the provided table.`);
12
+ }
13
+ return col;
14
+ }
15
+ function buildWhereExpr(tableObj, where) {
16
+ if (!where?.length)
17
+ return undefined;
18
+ const parts = [];
19
+ for (const w of where) {
20
+ const operator = normalizeOperator(w.operator);
21
+ const col = getColumn(tableObj, w.field);
22
+ if (operator === 'in') {
23
+ parts.push(inArray(col, toArray(w.value)));
24
+ }
25
+ else if (operator === 'like') {
26
+ // Postgres-only: use ILIKE for case-insensitive search.
27
+ parts.push(ilike(col, String(w.value)));
28
+ }
29
+ else {
30
+ parts.push(eq(col, w.value));
31
+ }
32
+ }
33
+ return parts.length === 1 ? parts[0] : and(...parts);
34
+ }
35
+ function buildSelect(tableObj, select) {
36
+ if (!select?.length)
37
+ return undefined;
38
+ const projection = {};
39
+ for (const field of select) {
40
+ projection[field] = getColumn(tableObj, field);
41
+ }
42
+ return projection;
43
+ }
44
+ function applySort(q, tableObj, sortBy) {
45
+ if (!sortBy)
46
+ return q;
47
+ const col = getColumn(tableObj, sortBy.field);
48
+ return q.orderBy(sortBy.direction === 'asc' ? asc(col) : desc(col));
49
+ }
50
+ function asDrizzleDBLike(db) {
51
+ // We intentionally use structural typing to accept any Drizzle db instance.
52
+ // Runtime failures will be clearer than over-constraining types we don't own.
53
+ return db;
54
+ }
55
+ function getSchema(db, config) {
56
+ const schema = config.schema ?? db._?.fullSchema;
57
+ if (!schema) {
58
+ throw new Error('Drizzle adapter failed to initialize. Schema not found. Provide `schema` or use a Drizzle db that exposes `db._.fullSchema`.');
59
+ }
60
+ return schema;
61
+ }
62
+ function getTableFromSchema(schema, key) {
63
+ const table = schema[key];
64
+ if (!table || typeof table !== 'object') {
65
+ throw new Error(`Drizzle adapter failed to initialize. Table "${key}" was not found in schema.`);
66
+ }
67
+ return table;
68
+ }
69
+ function getCorsairTable(schema, table, tableNames) {
70
+ switch (table) {
71
+ case 'corsair_integrations':
72
+ return getTableFromSchema(schema, tableNames?.integrations ?? 'corsair_integrations');
73
+ case 'corsair_accounts':
74
+ return getTableFromSchema(schema, tableNames?.accounts ?? 'corsair_accounts');
75
+ case 'corsair_entities':
76
+ return getTableFromSchema(schema, tableNames?.entities ?? 'corsair_entities');
77
+ case 'corsair_events':
78
+ return getTableFromSchema(schema, tableNames?.events ?? 'corsair_events');
79
+ default:
80
+ // Allow custom tables by looking them up directly in the schema
81
+ return getTableFromSchema(schema, table);
82
+ }
83
+ }
84
+ /**
85
+ * `drizzleAdapter(db, { provider: "pg" })`.
86
+ *
87
+ * Corsair currently supports Postgres only.
88
+ *
89
+ * Note on typing:
90
+ * - Drizzle's column/table types are schema-generic. Corsair does not own the user's schema types,
91
+ * so we accept `unknown` and do runtime validation.
92
+ * - We cast the schema columns into Drizzle expression helpers (`eq`, `inArray`, `ilike`) because
93
+ * those helpers require Drizzle's column types, which we cannot represent without the user's generics.
94
+ */
95
+ export function drizzleAdapter(db, config) {
96
+ if (config.provider !== 'pg') {
97
+ throw new Error(`Corsair Drizzle adapter only supports provider "pg" (got "${String(config.provider)}").`);
98
+ }
99
+ const drizzle = asDrizzleDBLike(db);
100
+ const schema = getSchema(drizzle, config);
101
+ const adapterId = config.adapterId ?? 'drizzle';
102
+ return {
103
+ id: adapterId,
104
+ async findOne(args) {
105
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
106
+ const whereExpr = buildWhereExpr(tableObj, args.where);
107
+ const projection = buildSelect(tableObj, args.select);
108
+ const q = projection
109
+ ? drizzle.select(projection).from(tableObj)
110
+ : drizzle.select().from(tableObj);
111
+ const res = whereExpr
112
+ ? await q.where(whereExpr).limit(1)
113
+ : await q.limit(1);
114
+ return (res?.[0] ?? null);
115
+ },
116
+ async findMany(args) {
117
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
118
+ const whereExpr = buildWhereExpr(tableObj, args.where);
119
+ const projection = buildSelect(tableObj, args.select);
120
+ let q = projection
121
+ ? drizzle.select(projection).from(tableObj)
122
+ : drizzle.select().from(tableObj);
123
+ if (whereExpr)
124
+ q = q.where(whereExpr);
125
+ q = applySort(q, tableObj, args.sortBy);
126
+ if (typeof args.limit === 'number')
127
+ q = q.limit(args.limit);
128
+ if (typeof args.offset === 'number')
129
+ q = q.offset(args.offset);
130
+ return (await q);
131
+ },
132
+ async insert(args) {
133
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
134
+ const projection = buildSelect(tableObj, args.select);
135
+ const q = drizzle.insert(tableObj).values(args.data);
136
+ const rows = projection
137
+ ? await q.returning(projection)
138
+ : await q.returning();
139
+ return (rows?.[0] ?? args.data);
140
+ },
141
+ async update(args) {
142
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
143
+ const whereExpr = buildWhereExpr(tableObj, args.where);
144
+ if (!whereExpr) {
145
+ throw new Error('Drizzle adapter: update requires a non-empty where clause.');
146
+ }
147
+ const projection = buildSelect(tableObj, args.select);
148
+ const q = drizzle.update(tableObj).set(args.data).where(whereExpr);
149
+ const rows = projection
150
+ ? await q.returning(projection)
151
+ : await q.returning();
152
+ return (rows?.[0] ?? null);
153
+ },
154
+ async deleteMany(args) {
155
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
156
+ const whereExpr = buildWhereExpr(tableObj, args.where);
157
+ if (!whereExpr)
158
+ return 0;
159
+ // Postgres-only: use returning to count deletes deterministically.
160
+ const rows = await drizzle
161
+ .delete(tableObj)
162
+ .where(whereExpr)
163
+ .returning({
164
+ id: getColumn(tableObj, 'id'),
165
+ });
166
+ return rows.length;
167
+ },
168
+ async count(args) {
169
+ const tableObj = getCorsairTable(schema, args.table, config.tableNames);
170
+ const whereExpr = buildWhereExpr(tableObj, args.where);
171
+ const q = drizzle.select({ count: count() }).from(tableObj);
172
+ const rows = whereExpr ? await q.where(whereExpr) : await q;
173
+ const c = rows?.[0]?.count;
174
+ if (typeof c === 'number')
175
+ return c;
176
+ if (typeof c === 'bigint')
177
+ return Number(c);
178
+ return Number.parseInt(String(c ?? 0), 10);
179
+ },
180
+ async transaction(fn) {
181
+ if (!drizzle.transaction)
182
+ return fn(this);
183
+ return drizzle.transaction(async (tx) => {
184
+ // Keep the exact same config/schema; only swap the db instance.
185
+ const trxAdapter = drizzleAdapter(tx, {
186
+ ...config,
187
+ adapterId: adapterId + ':trx',
188
+ });
189
+ return fn(trxAdapter);
190
+ });
191
+ },
192
+ };
193
+ }
@@ -0,0 +1,6 @@
1
+ export * from './drizzle';
2
+ export * from './kysely';
3
+ export * from './prisma';
4
+ export * from './tenant';
5
+ export * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAE1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './drizzle';
2
+ export * from './kysely';
3
+ export * from './prisma';
4
+ export * from './tenant';
5
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ export { type KyselyAdapterConfig, type KyselyPostgresAdapterConfig, kyselyAdapter, kyselyPostgresAdapter, } from './postgres';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../adapters/kysely/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,aAAa,EACb,qBAAqB,GACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export { kyselyAdapter, kyselyPostgresAdapter, } from './postgres';
@@ -0,0 +1,19 @@
1
+ import type { Kysely } from 'kysely';
2
+ import type { CorsairDbAdapter } from '../types';
3
+ export type KyselyPostgresAdapterConfig = {
4
+ adapterId?: string | undefined;
5
+ };
6
+ export type KyselyAdapterConfig = KyselyPostgresAdapterConfig & {
7
+ /**
8
+ * Corsair currently supports Postgres only.
9
+ */
10
+ provider: 'pg';
11
+ };
12
+ export declare function kyselyPostgresAdapter(db: Kysely<any>, config?: KyselyPostgresAdapterConfig): CorsairDbAdapter;
13
+ /**
14
+ * `kyselyAdapter(db, { provider: "pg" })`.
15
+ *
16
+ * Corsair currently supports Postgres only.
17
+ */
18
+ export declare function kyselyAdapter(db: Kysely<any>, config: KyselyAdapterConfig): CorsairDbAdapter;
19
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../adapters/kysely/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EACX,gBAAgB,EAKhB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,2BAA2B,GAAG;IACzC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,2BAA2B,GAAG;IAC/D;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;CACf,CAAC;AA2CF,wBAAgB,qBAAqB,CACpC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EACf,MAAM,GAAE,2BAAgC,GACtC,gBAAgB,CA+HlB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EACf,MAAM,EAAE,mBAAmB,GACzB,gBAAgB,CAWlB"}
@@ -0,0 +1,138 @@
1
+ function normalizeOperator(op) {
2
+ return op ?? '=';
3
+ }
4
+ function toArray(value) {
5
+ return Array.isArray(value) ? value : [value];
6
+ }
7
+ function applyWhere(q, where) {
8
+ if (!where?.length)
9
+ return q;
10
+ let next = q;
11
+ for (const w of where) {
12
+ const operator = normalizeOperator(w.operator);
13
+ if (operator === 'in') {
14
+ next = next.where(w.field, 'in', toArray(w.value));
15
+ }
16
+ else if (operator === 'like') {
17
+ next = next.where(w.field, 'like', w.value);
18
+ }
19
+ else {
20
+ next = next.where(w.field, '=', w.value);
21
+ }
22
+ }
23
+ return next;
24
+ }
25
+ function applySort(q, sortBy) {
26
+ if (!sortBy)
27
+ return q;
28
+ return q.orderBy(sortBy.field, sortBy.direction);
29
+ }
30
+ function selectArgs(select) {
31
+ return select?.length ? select : undefined;
32
+ }
33
+ export function kyselyPostgresAdapter(db, config = {}) {
34
+ const adapterId = config.adapterId ?? 'kysely-postgres';
35
+ const findOneImpl = async (args) => {
36
+ let q = db.selectFrom(args.table);
37
+ const cols = selectArgs(args.select);
38
+ q = cols ? q.select(cols) : q.selectAll();
39
+ q = applyWhere(q, args.where);
40
+ return (await q.executeTakeFirst());
41
+ };
42
+ return {
43
+ id: adapterId,
44
+ async findOne(args) {
45
+ return findOneImpl(args);
46
+ },
47
+ async findMany(args) {
48
+ let q = db.selectFrom(args.table);
49
+ const cols = selectArgs(args.select);
50
+ q = cols ? q.select(cols) : q.selectAll();
51
+ q = applyWhere(q, args.where);
52
+ q = applySort(q, args.sortBy);
53
+ if (typeof args.limit === 'number')
54
+ q = q.limit(args.limit);
55
+ if (typeof args.offset === 'number')
56
+ q = q.offset(args.offset);
57
+ return (await q.execute());
58
+ },
59
+ async insert(args) {
60
+ try {
61
+ // Postgres supports RETURNING.
62
+ const cols = selectArgs(args.select);
63
+ let q = db
64
+ .insertInto(args.table)
65
+ .values(args.data);
66
+ q = cols ? q.returning(cols) : q.returningAll();
67
+ const row = await q.executeTakeFirst();
68
+ return (row ?? args.data);
69
+ }
70
+ catch {
71
+ await db.insertInto(args.table).values(args.data).execute();
72
+ return args.data;
73
+ }
74
+ },
75
+ async update(args) {
76
+ try {
77
+ const cols = selectArgs(args.select);
78
+ let q = db.updateTable(args.table).set(args.data);
79
+ q = applyWhere(q, args.where);
80
+ q = cols ? q.returning(cols) : q.returningAll();
81
+ const row = await q.executeTakeFirst();
82
+ return (row ?? null);
83
+ }
84
+ catch {
85
+ await applyWhere(db.updateTable(args.table).set(args.data), args.where).execute();
86
+ // Best-effort: fetch one updated row.
87
+ return await findOneImpl({
88
+ table: args.table,
89
+ where: args.where,
90
+ select: args.select,
91
+ });
92
+ }
93
+ },
94
+ async deleteMany(args) {
95
+ const res = await applyWhere(db.deleteFrom(args.table), args.where).executeTakeFirst();
96
+ return Number(res?.numDeletedRows ?? 0);
97
+ },
98
+ async count(args) {
99
+ let q = db
100
+ .selectFrom(args.table)
101
+ .select((eb) => eb.fn.countAll().as('count'));
102
+ q = applyWhere(q, args.where);
103
+ const row = await q.executeTakeFirst();
104
+ const countVal = row?.count;
105
+ if (typeof countVal === 'number')
106
+ return countVal;
107
+ if (typeof countVal === 'bigint')
108
+ return Number(countVal);
109
+ return Number.parseInt(String(countVal ?? 0), 10);
110
+ },
111
+ async transaction(fn) {
112
+ // Kysely supports transactions via `db.transaction().execute(...)`.
113
+ // If a user passes a Kysely instance without transaction support, fall back to non-transactional execution.
114
+ const txFactory = db?.transaction?.bind(db);
115
+ if (!txFactory)
116
+ return fn(this);
117
+ return txFactory().execute(async (trx) => {
118
+ const trxAdapter = kyselyPostgresAdapter(trx, {
119
+ adapterId: adapterId + ':trx',
120
+ });
121
+ return fn(trxAdapter);
122
+ });
123
+ },
124
+ };
125
+ }
126
+ /**
127
+ * `kyselyAdapter(db, { provider: "pg" })`.
128
+ *
129
+ * Corsair currently supports Postgres only.
130
+ */
131
+ export function kyselyAdapter(db, config) {
132
+ if (config.provider !== 'pg') {
133
+ throw new Error(`Corsair Kysely adapter only supports provider "pg" (got "${String(config.provider)}").`);
134
+ }
135
+ // Strip provider before passing through.
136
+ const { provider: _provider, ...rest } = config;
137
+ return kyselyPostgresAdapter(db, rest);
138
+ }
@@ -0,0 +1,2 @@
1
+ export { type PrismaPostgresAdapterConfig, prismaPostgresAdapter, } from './postgres';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../adapters/prisma/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,2BAA2B,EAChC,qBAAqB,GACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export { prismaPostgresAdapter, } from './postgres';
@@ -0,0 +1,17 @@
1
+ import type { CorsairDbAdapter } from '../types';
2
+ export type PrismaPostgresAdapterConfig = {
3
+ adapterId?: string | undefined;
4
+ /**
5
+ * Prisma delegate keys on the Prisma client (e.g. `prisma.corsairEntity`).
6
+ *
7
+ * Since Prisma model names are user-defined, these are configurable.
8
+ */
9
+ models?: {
10
+ corsair_integrations?: string | undefined;
11
+ corsair_accounts?: string | undefined;
12
+ corsair_entities?: string | undefined;
13
+ corsair_events?: string | undefined;
14
+ } | undefined;
15
+ };
16
+ export declare function prismaPostgresAdapter(prisma: any, config?: PrismaPostgresAdapterConfig): CorsairDbAdapter;
17
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../adapters/prisma/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAKhB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,2BAA2B,GAAG;IACzC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B;;;;OAIG;IACH,MAAM,CAAC,EACJ;QACA,oBAAoB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACtC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACtC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACnC,GACD,SAAS,CAAC;CACb,CAAC;AA6GF,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,GAAG,EACX,MAAM,GAAE,2BAAgC,GACtC,gBAAgB,CAyHlB"}
@@ -0,0 +1,176 @@
1
+ function normalizeOperator(op) {
2
+ return op ?? '=';
3
+ }
4
+ function toArray(value) {
5
+ return Array.isArray(value) ? value : [value];
6
+ }
7
+ function buildSelect(select) {
8
+ if (!select?.length)
9
+ return undefined;
10
+ const s = {};
11
+ for (const f of select)
12
+ s[f] = true;
13
+ return s;
14
+ }
15
+ function parseLikePattern(pattern) {
16
+ // Handle common SQL LIKE patterns used by Corsair ORM.
17
+ if (pattern.startsWith('%') && pattern.endsWith('%') && pattern.length >= 2) {
18
+ return { kind: 'contains', value: pattern.slice(1, -1) };
19
+ }
20
+ if (pattern.endsWith('%') && pattern.length >= 1) {
21
+ return { kind: 'startsWith', value: pattern.slice(0, -1) };
22
+ }
23
+ if (pattern.startsWith('%') && pattern.length >= 1) {
24
+ return { kind: 'endsWith', value: pattern.slice(1) };
25
+ }
26
+ return { kind: 'equals', value: pattern };
27
+ }
28
+ function buildWhere(where) {
29
+ if (!where?.length)
30
+ return undefined;
31
+ const out = {};
32
+ for (const w of where) {
33
+ const operator = normalizeOperator(w.operator);
34
+ const field = w.field;
35
+ if (operator === 'in') {
36
+ out[field] = { in: toArray(w.value) };
37
+ continue;
38
+ }
39
+ if (operator === 'like') {
40
+ const parsed = parseLikePattern(String(w.value ?? ''));
41
+ if (parsed.kind === 'contains') {
42
+ out[field] = { contains: parsed.value, mode: 'insensitive' };
43
+ }
44
+ else if (parsed.kind === 'startsWith') {
45
+ out[field] = { startsWith: parsed.value, mode: 'insensitive' };
46
+ }
47
+ else if (parsed.kind === 'endsWith') {
48
+ out[field] = { endsWith: parsed.value, mode: 'insensitive' };
49
+ }
50
+ else {
51
+ out[field] = parsed.value;
52
+ }
53
+ continue;
54
+ }
55
+ out[field] = w.value;
56
+ }
57
+ return out;
58
+ }
59
+ function buildOrderBy(sortBy) {
60
+ if (!sortBy)
61
+ return undefined;
62
+ return { [sortBy.field]: sortBy.direction };
63
+ }
64
+ function getDelegate(prisma, table, config) {
65
+ const models = config.models ?? {};
66
+ let key;
67
+ switch (table) {
68
+ case 'corsair_integrations':
69
+ key = models.corsair_integrations ?? 'corsair_integrations';
70
+ break;
71
+ case 'corsair_accounts':
72
+ key = models.corsair_accounts ?? 'corsair_accounts';
73
+ break;
74
+ case 'corsair_entities':
75
+ key = models.corsair_entities ?? 'corsair_entities';
76
+ break;
77
+ case 'corsair_events':
78
+ key = models.corsair_events ?? 'corsair_events';
79
+ break;
80
+ default:
81
+ // Allow custom tables
82
+ key = table;
83
+ }
84
+ const delegate = prisma[key];
85
+ if (!delegate) {
86
+ throw new Error(`Prisma adapter: prisma["${key}"] was not found. Pass config.models to map Corsair table names to your Prisma delegate keys.`);
87
+ }
88
+ return delegate;
89
+ }
90
+ export function prismaPostgresAdapter(prisma, config = {}) {
91
+ const adapterId = config.adapterId ?? 'prisma-postgres';
92
+ return {
93
+ id: adapterId,
94
+ async findOne(args) {
95
+ const delegate = getDelegate(prisma, args.table, config);
96
+ const res = await delegate.findFirst({
97
+ where: buildWhere(args.where),
98
+ select: buildSelect(args.select),
99
+ });
100
+ return (res ?? null);
101
+ },
102
+ async findMany(args) {
103
+ const delegate = getDelegate(prisma, args.table, config);
104
+ const res = await delegate.findMany({
105
+ where: buildWhere(args.where),
106
+ take: typeof args.limit === 'number' ? args.limit : undefined,
107
+ skip: typeof args.offset === 'number' ? args.offset : undefined,
108
+ orderBy: buildOrderBy(args.sortBy),
109
+ select: buildSelect(args.select),
110
+ });
111
+ return res;
112
+ },
113
+ async insert(args) {
114
+ const delegate = getDelegate(prisma, args.table, config);
115
+ const res = await delegate.create({
116
+ data: args.data,
117
+ select: buildSelect(args.select),
118
+ });
119
+ return res;
120
+ },
121
+ async update(args) {
122
+ const delegate = getDelegate(prisma, args.table, config);
123
+ const whereObj = buildWhere(args.where);
124
+ const selectObj = buildSelect(args.select);
125
+ // Fast path: single-id update can use `update()` which returns the row.
126
+ const isSingleId = args.where.length === 1 &&
127
+ args.where[0]?.field === 'id' &&
128
+ normalizeOperator(args.where[0]?.operator) === '=';
129
+ if (isSingleId) {
130
+ const res = await delegate.update({
131
+ where: { id: args.where[0].value },
132
+ data: args.data,
133
+ select: selectObj,
134
+ });
135
+ return (res ?? null);
136
+ }
137
+ await delegate.updateMany({
138
+ where: whereObj,
139
+ data: args.data,
140
+ });
141
+ // Best-effort: fetch one updated row.
142
+ const res = await delegate.findFirst({
143
+ where: whereObj,
144
+ select: selectObj,
145
+ });
146
+ return (res ?? null);
147
+ },
148
+ async deleteMany(args) {
149
+ const delegate = getDelegate(prisma, args.table, config);
150
+ const res = await delegate.deleteMany({
151
+ where: buildWhere(args.where),
152
+ });
153
+ return Number(res?.count ?? 0);
154
+ },
155
+ async count(args) {
156
+ const delegate = getDelegate(prisma, args.table, config);
157
+ const res = await delegate.count({
158
+ where: buildWhere(args.where),
159
+ });
160
+ return Number(res ?? 0);
161
+ },
162
+ async transaction(fn) {
163
+ const txFn = prisma?.$transaction?.bind(prisma);
164
+ if (!txFn)
165
+ return fn(this);
166
+ // Interactive transaction if supported; otherwise falls back to batching.
167
+ return txFn(async (tx) => {
168
+ const trxAdapter = prismaPostgresAdapter(tx, {
169
+ ...config,
170
+ adapterId: adapterId + ':trx',
171
+ });
172
+ return fn(trxAdapter);
173
+ });
174
+ },
175
+ };
176
+ }