@donotdev/functions 0.1.1 → 0.1.44

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 (348) hide show
  1. package/LICENSE.md +21 -242
  2. package/README.md +4 -4
  3. package/guidelines/FUNCTIONS.md +0 -0
  4. package/guidelines/VERCEL.md +27 -1
  5. package/lib/firebase/auth/getCustomClaims.d.ts +0 -0
  6. package/lib/firebase/auth/getUserAuthStatus.d.ts +0 -0
  7. package/lib/firebase/auth/index.d.ts +0 -0
  8. package/lib/firebase/auth/removeCustomClaims.d.ts +0 -0
  9. package/lib/firebase/auth/setCustomClaims.d.ts +0 -0
  10. package/lib/firebase/baseFunction.d.ts +0 -0
  11. package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
  12. package/lib/firebase/billing/changePlan.d.ts +0 -0
  13. package/lib/firebase/billing/createCheckoutSession.d.ts +0 -0
  14. package/lib/firebase/billing/createCustomerPortal.d.ts +0 -0
  15. package/lib/firebase/billing/healthCheck.d.ts +0 -0
  16. package/lib/firebase/billing/index.d.ts +0 -0
  17. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -0
  18. package/lib/firebase/billing/webhookHandler.d.ts +0 -0
  19. package/lib/firebase/config/constants.d.ts +0 -0
  20. package/lib/firebase/config/index.d.ts +0 -0
  21. package/lib/firebase/config/secrets.d.ts +0 -0
  22. package/lib/firebase/crud/aggregate.d.ts +0 -0
  23. package/lib/firebase/crud/bulk.d.ts +107 -0
  24. package/lib/firebase/crud/create.d.ts +1 -1
  25. package/lib/firebase/crud/delete.d.ts +0 -0
  26. package/lib/firebase/crud/get.d.ts +0 -0
  27. package/lib/firebase/crud/index.d.ts +1 -0
  28. package/lib/firebase/crud/list.d.ts +0 -0
  29. package/lib/firebase/crud/update.d.ts +0 -0
  30. package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
  31. package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
  32. package/lib/firebase/helpers/index.d.ts +0 -0
  33. package/lib/firebase/index.d.ts +0 -0
  34. package/lib/firebase/index.js +3 -3
  35. package/lib/firebase/index.js.map +4 -4
  36. package/lib/firebase/oauth/disconnect.d.ts +0 -0
  37. package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
  38. package/lib/firebase/oauth/getConnections.d.ts +0 -0
  39. package/lib/firebase/oauth/githubAccess.d.ts +0 -0
  40. package/lib/firebase/oauth/index.d.ts +0 -0
  41. package/lib/firebase/oauth/refreshToken.d.ts +0 -0
  42. package/lib/firebase/registerCrudFunctions.d.ts +0 -0
  43. package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
  44. package/lib/firebase/scheduled/index.d.ts +0 -0
  45. package/lib/shared/ai/classifyAIError.d.ts +0 -0
  46. package/lib/shared/ai/costTracker.d.ts +0 -0
  47. package/lib/shared/ai/createAIHandler.d.ts +39 -0
  48. package/lib/shared/ai/createAIRoute.d.ts +0 -0
  49. package/lib/shared/ai/index.d.ts +0 -0
  50. package/lib/shared/ai/providers/anthropic.d.ts +12 -0
  51. package/lib/shared/ai/providers/google.d.ts +10 -0
  52. package/lib/shared/ai/providers/index.d.ts +23 -0
  53. package/lib/shared/ai/providers/openai.d.ts +10 -0
  54. package/lib/shared/ai/resolveModelTier.d.ts +0 -0
  55. package/lib/shared/ai/utils/parseSSE.d.ts +22 -0
  56. package/lib/shared/billing/createCheckout.d.ts +0 -0
  57. package/lib/shared/billing/helpers/index.d.ts +0 -0
  58. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +0 -0
  59. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +0 -0
  60. package/lib/shared/billing/idempotency.d.ts +0 -0
  61. package/lib/shared/billing/index.d.ts +0 -0
  62. package/lib/shared/billing/webhookHandler.d.ts +0 -0
  63. package/lib/shared/crud/bulkCore.d.ts +211 -0
  64. package/lib/shared/crud/index.d.ts +13 -0
  65. package/lib/shared/email/createEmailRoute.d.ts +0 -0
  66. package/lib/shared/email/index.d.ts +0 -0
  67. package/lib/shared/email/provider.d.ts +0 -0
  68. package/lib/shared/email/resendProvider.d.ts +0 -0
  69. package/lib/shared/errorHandling.d.ts +0 -0
  70. package/lib/shared/firebase.d.ts +0 -0
  71. package/lib/shared/github.d.ts +0 -0
  72. package/lib/shared/index.d.ts +1 -0
  73. package/lib/shared/index.js +4 -4
  74. package/lib/shared/index.js.map +4 -4
  75. package/lib/shared/logger.d.ts +0 -0
  76. package/lib/shared/metadata.d.ts +6 -6
  77. package/lib/shared/oauth/exchangeToken.d.ts +0 -0
  78. package/lib/shared/oauth/grantAccess.d.ts +0 -0
  79. package/lib/shared/oauth/index.d.ts +0 -0
  80. package/lib/shared/schema.d.ts +0 -0
  81. package/lib/shared/utils/detectFirestore.d.ts +0 -0
  82. package/lib/shared/utils/external/date.d.ts +0 -0
  83. package/lib/shared/utils/external/index.d.ts +0 -0
  84. package/lib/shared/utils/external/references.d.ts +0 -0
  85. package/lib/shared/utils/external/subscription.d.ts +0 -0
  86. package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
  87. package/lib/shared/utils/functionWrapper.d.ts +0 -0
  88. package/lib/shared/utils/index.d.ts +0 -0
  89. package/lib/shared/utils/internal/auth.d.ts +0 -0
  90. package/lib/shared/utils/internal/firebase.d.ts +0 -0
  91. package/lib/shared/utils/internal/idempotency.d.ts +0 -0
  92. package/lib/shared/utils/internal/index.d.ts +0 -0
  93. package/lib/shared/utils/internal/monitoring.d.ts +0 -0
  94. package/lib/shared/utils/internal/rateLimiter.d.ts +0 -0
  95. package/lib/shared/utils/internal/validation.d.ts +0 -0
  96. package/lib/shared/utils/schemaValidation.d.ts +0 -0
  97. package/lib/shared/utils/validation.d.ts +0 -0
  98. package/lib/shared/utils/vercelHelpers.d.ts +0 -0
  99. package/lib/shared/utils.d.ts +0 -0
  100. package/lib/shared/validation.d.ts +0 -0
  101. package/lib/supabase/ai/createAIFunction.d.ts +0 -0
  102. package/lib/supabase/auth/deleteAccount.d.ts +0 -0
  103. package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
  104. package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
  105. package/lib/supabase/auth/removeCustomClaims.d.ts +0 -0
  106. package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
  107. package/lib/supabase/baseFunction.d.ts +0 -0
  108. package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
  109. package/lib/supabase/billing/changePlan.d.ts +0 -0
  110. package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
  111. package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
  112. package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
  113. package/lib/supabase/crud/aggregate.d.ts +0 -0
  114. package/lib/supabase/crud/bulk.d.ts +63 -0
  115. package/lib/supabase/crud/create.d.ts +1 -1
  116. package/lib/supabase/crud/delete.d.ts +0 -0
  117. package/lib/supabase/crud/get.d.ts +0 -0
  118. package/lib/supabase/crud/index.d.ts +2 -0
  119. package/lib/supabase/crud/list.d.ts +0 -0
  120. package/lib/supabase/crud/update.d.ts +0 -0
  121. package/lib/supabase/edgeFunction.d.ts +0 -0
  122. package/lib/supabase/email/createEmailFunction.d.ts +0 -0
  123. package/lib/supabase/helpers/authProvider.d.ts +0 -0
  124. package/lib/supabase/index.d.ts +3 -3
  125. package/lib/supabase/index.js +3 -3
  126. package/lib/supabase/index.js.map +4 -4
  127. package/lib/supabase/oauth/disconnect.d.ts +0 -0
  128. package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
  129. package/lib/supabase/oauth/getConnections.d.ts +0 -0
  130. package/lib/supabase/oauth/index.d.ts +0 -0
  131. package/lib/supabase/oauth/refreshToken.d.ts +0 -0
  132. package/lib/supabase/registerCrudFunctions.d.ts +0 -0
  133. package/lib/supabase/utils/idempotency.d.ts +0 -0
  134. package/lib/supabase/utils/monitoring.d.ts +0 -0
  135. package/lib/supabase/utils/rateLimiter.d.ts +0 -0
  136. package/lib/vercel/api/ai/chat.d.ts +0 -0
  137. package/lib/vercel/api/ai/index.d.ts +0 -0
  138. package/lib/vercel/api/auth/get-custom-claims.d.ts +0 -0
  139. package/lib/vercel/api/auth/get-user-auth-status.d.ts +0 -0
  140. package/lib/vercel/api/auth/index.d.ts +0 -0
  141. package/lib/vercel/api/auth/remove-custom-claims.d.ts +0 -0
  142. package/lib/vercel/api/auth/set-custom-claims.d.ts +0 -0
  143. package/lib/vercel/api/billing/cancel.d.ts +0 -0
  144. package/lib/vercel/api/billing/change-plan.d.ts +0 -0
  145. package/lib/vercel/api/billing/create-checkout-session.d.ts +0 -0
  146. package/lib/vercel/api/billing/customer-portal.d.ts +0 -0
  147. package/lib/vercel/api/billing/index.d.ts +0 -0
  148. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +0 -0
  149. package/lib/vercel/api/billing/webhook-handler.d.ts +0 -0
  150. package/lib/vercel/api/config/constants.d.ts +0 -0
  151. package/lib/vercel/api/config/firebase-admin.d.ts +0 -0
  152. package/lib/vercel/api/config/index.d.ts +0 -0
  153. package/lib/vercel/api/crud/bulk.d.ts +31 -0
  154. package/lib/vercel/api/crud/create.d.ts +0 -0
  155. package/lib/vercel/api/crud/delete.d.ts +0 -0
  156. package/lib/vercel/api/crud/get.d.ts +0 -0
  157. package/lib/vercel/api/crud/index.d.ts +1 -0
  158. package/lib/vercel/api/crud/list.d.ts +0 -0
  159. package/lib/vercel/api/crud/update.d.ts +0 -0
  160. package/lib/vercel/api/index.d.ts +0 -0
  161. package/lib/vercel/api/index.js +3 -3
  162. package/lib/vercel/api/index.js.map +4 -4
  163. package/lib/vercel/api/oauth/check-github-access.d.ts +0 -0
  164. package/lib/vercel/api/oauth/exchange-token.d.ts +0 -0
  165. package/lib/vercel/api/oauth/grant-github-access.d.ts +0 -0
  166. package/lib/vercel/api/oauth/index.d.ts +0 -0
  167. package/lib/vercel/api/oauth/revoke-github-access.d.ts +0 -0
  168. package/lib/vercel/api/utils/cors.d.ts +0 -0
  169. package/lib/vercel/baseFunction.d.ts +0 -0
  170. package/package.json +6 -6
  171. package/src/firebase/auth/getCustomClaims.ts +0 -0
  172. package/src/firebase/auth/getUserAuthStatus.ts +0 -0
  173. package/src/firebase/auth/index.ts +0 -0
  174. package/src/firebase/auth/removeCustomClaims.ts +0 -0
  175. package/src/firebase/auth/setCustomClaims.ts +0 -0
  176. package/src/firebase/baseFunction.ts +0 -0
  177. package/src/firebase/billing/cancelSubscription.ts +0 -0
  178. package/src/firebase/billing/changePlan.ts +0 -0
  179. package/src/firebase/billing/createCheckoutSession.ts +5 -1
  180. package/src/firebase/billing/createCustomerPortal.ts +0 -0
  181. package/src/firebase/billing/healthCheck.ts +0 -0
  182. package/src/firebase/billing/index.d.ts +0 -0
  183. package/src/firebase/billing/index.ts +0 -0
  184. package/src/firebase/billing/refreshSubscriptionStatus.ts +0 -0
  185. package/src/firebase/billing/webhookHandler.ts +0 -0
  186. package/src/firebase/config/constants.ts +0 -0
  187. package/src/firebase/config/index.ts +0 -0
  188. package/src/firebase/config/secrets.ts +0 -0
  189. package/src/firebase/crud/__tests__/bulk.test.ts +322 -0
  190. package/src/firebase/crud/aggregate.ts +0 -0
  191. package/src/firebase/crud/bulk.ts +272 -0
  192. package/src/firebase/crud/create.ts +20 -33
  193. package/src/firebase/crud/delete.ts +0 -0
  194. package/src/firebase/crud/get.ts +0 -0
  195. package/src/firebase/crud/index.ts +1 -0
  196. package/src/firebase/crud/list.ts +0 -0
  197. package/src/firebase/crud/update.ts +0 -0
  198. package/src/firebase/helpers/githubAccessHelper.ts +0 -0
  199. package/src/firebase/helpers/githubTeamAccessHelper.ts +0 -0
  200. package/src/firebase/helpers/index.ts +0 -0
  201. package/src/firebase/index.d.ts +0 -0
  202. package/src/firebase/index.ts +0 -0
  203. package/src/firebase/oauth/disconnect.ts +0 -0
  204. package/src/firebase/oauth/exchangeToken.ts +0 -0
  205. package/src/firebase/oauth/getConnections.ts +0 -0
  206. package/src/firebase/oauth/githubAccess.ts +0 -0
  207. package/src/firebase/oauth/index.ts +0 -0
  208. package/src/firebase/oauth/refreshToken.ts +0 -0
  209. package/src/firebase/registerCrudFunctions.ts +13 -0
  210. package/src/firebase/scheduled/checkExpiredSubscriptions.ts +0 -0
  211. package/src/firebase/scheduled/index.ts +0 -0
  212. package/src/shared/__tests__/auth.test.ts +0 -0
  213. package/src/shared/__tests__/bulkCore.test.ts +487 -0
  214. package/src/shared/__tests__/errorHandling.test.ts +0 -0
  215. package/src/shared/__tests__/firebase.test.ts +9 -3
  216. package/src/shared/__tests__/idempotency.test.ts +0 -0
  217. package/src/shared/__tests__/internalValidation.test.ts +9 -3
  218. package/src/shared/__tests__/metadata.test.ts +10 -10
  219. package/src/shared/__tests__/rateLimiter.test.ts +0 -0
  220. package/src/shared/__tests__/schema.test.ts +0 -0
  221. package/src/shared/__tests__/schemaValidation.test.ts +0 -0
  222. package/src/shared/__tests__/subscription.test.ts +0 -0
  223. package/src/shared/__tests__/utils.test.ts +10 -4
  224. package/src/shared/__tests__/validation-env.test.ts +9 -3
  225. package/src/shared/__tests__/validation.test.ts +0 -0
  226. package/src/shared/ai/__tests__/costTracker.test.ts +25 -13
  227. package/src/shared/ai/classifyAIError.ts +26 -11
  228. package/src/shared/ai/costTracker.ts +0 -0
  229. package/src/shared/ai/createAIRoute.ts +11 -8
  230. package/src/shared/ai/index.ts +0 -0
  231. package/src/shared/ai/resolveModelTier.ts +5 -2
  232. package/src/shared/billing/__tests__/createCheckout.test.ts +0 -0
  233. package/src/shared/billing/__tests__/webhookHandler.test.ts +0 -0
  234. package/src/shared/billing/createCheckout.ts +24 -9
  235. package/src/shared/billing/helpers/index.ts +0 -0
  236. package/src/shared/billing/helpers/subscriptionManagement.ts +0 -0
  237. package/src/shared/billing/helpers/updateUserSubscription.ts +0 -0
  238. package/src/shared/billing/idempotency.ts +0 -0
  239. package/src/shared/billing/index.ts +0 -0
  240. package/src/shared/billing/webhookHandler.ts +0 -0
  241. package/src/shared/crud/bulkCore.ts +483 -0
  242. package/src/shared/crud/index.ts +23 -0
  243. package/src/shared/email/createEmailRoute.ts +0 -0
  244. package/src/shared/email/index.ts +0 -0
  245. package/src/shared/email/provider.ts +0 -0
  246. package/src/shared/email/resendProvider.ts +1 -1
  247. package/src/shared/errorHandling.ts +0 -0
  248. package/src/shared/firebase.ts +0 -0
  249. package/src/shared/github.ts +0 -0
  250. package/src/shared/index.d.ts +9 -0
  251. package/src/shared/index.ts +1 -0
  252. package/src/shared/logger.ts +0 -0
  253. package/src/shared/metadata.ts +6 -6
  254. package/src/shared/oauth/__tests__/exchangeToken.test.ts +0 -0
  255. package/src/shared/oauth/__tests__/grantAccess.test.ts +0 -0
  256. package/src/shared/oauth/exchangeToken.ts +0 -0
  257. package/src/shared/oauth/grantAccess.ts +0 -0
  258. package/src/shared/oauth/index.ts +0 -0
  259. package/src/shared/schema.ts +0 -0
  260. package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -0
  261. package/src/shared/utils/detectFirestore.ts +0 -0
  262. package/src/shared/utils/external/date.ts +0 -0
  263. package/src/shared/utils/external/index.ts +0 -0
  264. package/src/shared/utils/external/references.ts +0 -0
  265. package/src/shared/utils/external/subscription.ts +0 -0
  266. package/src/shared/utils/firebaseHelpers.ts +0 -0
  267. package/src/shared/utils/functionWrapper.ts +0 -0
  268. package/src/shared/utils/index.ts +0 -0
  269. package/src/shared/utils/internal/auth.ts +0 -0
  270. package/src/shared/utils/internal/firebase.ts +0 -0
  271. package/src/shared/utils/internal/idempotency.ts +0 -0
  272. package/src/shared/utils/internal/index.ts +0 -0
  273. package/src/shared/utils/internal/monitoring.ts +0 -0
  274. package/src/shared/utils/internal/rateLimiter.ts +0 -0
  275. package/src/shared/utils/internal/validation.ts +0 -0
  276. package/src/shared/utils/schemaValidation.ts +0 -0
  277. package/src/shared/utils/validation.ts +0 -0
  278. package/src/shared/utils/vercelHelpers.ts +0 -0
  279. package/src/shared/utils.ts +0 -0
  280. package/src/shared/validation.ts +0 -0
  281. package/src/supabase/__tests__/bulk.test.ts +330 -0
  282. package/src/supabase/ai/createAIFunction.ts +17 -16
  283. package/src/supabase/auth/deleteAccount.ts +0 -0
  284. package/src/supabase/auth/getCustomClaims.ts +0 -0
  285. package/src/supabase/auth/getUserAuthStatus.ts +0 -0
  286. package/src/supabase/auth/removeCustomClaims.ts +0 -0
  287. package/src/supabase/auth/setCustomClaims.ts +1 -3
  288. package/src/supabase/baseFunction.ts +0 -0
  289. package/src/supabase/billing/cancelSubscription.ts +0 -0
  290. package/src/supabase/billing/changePlan.ts +1 -1
  291. package/src/supabase/billing/createCheckoutSession.ts +0 -0
  292. package/src/supabase/billing/createCustomerPortal.ts +0 -0
  293. package/src/supabase/billing/refreshSubscriptionStatus.ts +0 -0
  294. package/src/supabase/crud/aggregate.ts +0 -0
  295. package/src/supabase/crud/bulk.ts +244 -0
  296. package/src/supabase/crud/create.ts +15 -14
  297. package/src/supabase/crud/delete.ts +0 -0
  298. package/src/supabase/crud/get.ts +0 -0
  299. package/src/supabase/crud/index.ts +2 -0
  300. package/src/supabase/crud/list.ts +0 -0
  301. package/src/supabase/crud/update.ts +0 -0
  302. package/src/supabase/edgeFunction.ts +4 -3
  303. package/src/supabase/email/createEmailFunction.ts +9 -12
  304. package/src/supabase/helpers/authProvider.ts +0 -0
  305. package/src/supabase/index.ts +12 -3
  306. package/src/supabase/oauth/disconnect.ts +1 -2
  307. package/src/supabase/oauth/exchangeToken.ts +1 -3
  308. package/src/supabase/oauth/getConnections.ts +1 -4
  309. package/src/supabase/oauth/index.ts +0 -0
  310. package/src/supabase/oauth/refreshToken.ts +2 -7
  311. package/src/supabase/registerCrudFunctions.ts +38 -26
  312. package/src/supabase/utils/idempotency.ts +0 -0
  313. package/src/supabase/utils/monitoring.ts +0 -0
  314. package/src/supabase/utils/rateLimiter.ts +0 -0
  315. package/src/vercel/__tests__/bulk.test.ts +301 -0
  316. package/src/vercel/api/ai/chat.ts +0 -0
  317. package/src/vercel/api/ai/index.ts +2 -0
  318. package/src/vercel/api/auth/get-custom-claims.ts +0 -0
  319. package/src/vercel/api/auth/get-user-auth-status.ts +0 -0
  320. package/src/vercel/api/auth/index.ts +0 -0
  321. package/src/vercel/api/auth/remove-custom-claims.ts +0 -0
  322. package/src/vercel/api/auth/set-custom-claims.ts +0 -0
  323. package/src/vercel/api/billing/cancel.ts +0 -0
  324. package/src/vercel/api/billing/change-plan.ts +0 -0
  325. package/src/vercel/api/billing/create-checkout-session.ts +5 -1
  326. package/src/vercel/api/billing/customer-portal.ts +0 -0
  327. package/src/vercel/api/billing/index.ts +0 -0
  328. package/src/vercel/api/billing/refresh-subscription-status.ts +0 -0
  329. package/src/vercel/api/billing/webhook-handler.ts +0 -0
  330. package/src/vercel/api/config/constants.ts +0 -0
  331. package/src/vercel/api/config/firebase-admin.ts +0 -0
  332. package/src/vercel/api/config/index.ts +0 -0
  333. package/src/vercel/api/crud/bulk.ts +216 -0
  334. package/src/vercel/api/crud/create.ts +10 -9
  335. package/src/vercel/api/crud/delete.ts +0 -0
  336. package/src/vercel/api/crud/get.ts +0 -0
  337. package/src/vercel/api/crud/index.ts +1 -0
  338. package/src/vercel/api/crud/list.ts +0 -0
  339. package/src/vercel/api/crud/update.ts +0 -0
  340. package/src/vercel/api/index.d.ts +0 -0
  341. package/src/vercel/api/index.ts +0 -0
  342. package/src/vercel/api/oauth/check-github-access.ts +0 -0
  343. package/src/vercel/api/oauth/exchange-token.ts +4 -1
  344. package/src/vercel/api/oauth/grant-github-access.ts +0 -0
  345. package/src/vercel/api/oauth/index.ts +0 -0
  346. package/src/vercel/api/oauth/revoke-github-access.ts +0 -0
  347. package/src/vercel/api/utils/cors.ts +3 -1
  348. package/src/vercel/baseFunction.ts +0 -0
@@ -0,0 +1,487 @@
1
+ // packages/functions/src/shared/__tests__/bulkCore.test.ts
2
+
3
+ /**
4
+ * @fileoverview Unit tests for {@link executeBulk}.
5
+ * @description Exercises the shared orchestration contract directly with a
6
+ * mock `transact` callback — empty short-circuit, collision rejection,
7
+ * per-bucket ACL, per-row validation (inserts + updates), single-invocation
8
+ * transact with prepared payload, response-schema validation, and audit
9
+ * firing once with counts.
10
+ */
11
+
12
+ import { describe, it, expect, vi } from 'vitest';
13
+ import * as v from 'valibot';
14
+
15
+ import { executeBulk } from '../crud/bulkCore.js';
16
+ import { BulkCollisionError } from '@donotdev/core/server';
17
+ import { DoNotDevError } from '@donotdev/core/server';
18
+ import { DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // Fixtures
22
+ // ---------------------------------------------------------------------------
23
+
24
+ const createSchema = v.object({ name: v.pipe(v.string(), v.minLength(1)) });
25
+ const updateSchema = v.object({ name: v.optional(v.string()) });
26
+
27
+ const ACCESS = {
28
+ create: 'user' as const,
29
+ read: 'user' as const,
30
+ update: 'user' as const,
31
+ delete: 'user' as const,
32
+ };
33
+
34
+ /** Default response-shape returned by the mock transact. */
35
+ function okResponse(prepared: {
36
+ inserts: Array<{ id: string; row: Record<string, unknown> }>;
37
+ updates: Array<{ id: string; patch: Record<string, unknown> }>;
38
+ deletes: string[];
39
+ }) {
40
+ return {
41
+ insertedIds: prepared.inserts.map((i, idx) => i.id || `auto-${idx + 1}`),
42
+ updatedIds: prepared.updates.map((u) => u.id),
43
+ deletedIds: [...prepared.deletes],
44
+ };
45
+ }
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Tests
49
+ // ---------------------------------------------------------------------------
50
+
51
+ describe('executeBulk (shared CRUD core)', () => {
52
+ it('empty bulk short-circuits: no transact, no audit', async () => {
53
+ const transact = vi.fn();
54
+ const audit = vi.fn();
55
+
56
+ const result = await executeBulk({
57
+ collection: 'events',
58
+ ops: {},
59
+ createSchema,
60
+ updateSchema,
61
+ access: ACCESS,
62
+ uid: 'u1',
63
+ userRole: 'user',
64
+ transact,
65
+ audit,
66
+ });
67
+
68
+ expect(result).toEqual({
69
+ insertedIds: [],
70
+ updatedIds: [],
71
+ deletedIds: [],
72
+ });
73
+ expect(transact).not.toHaveBeenCalled();
74
+ expect(audit).not.toHaveBeenCalled();
75
+ });
76
+
77
+ it('empty arrays also short-circuit', async () => {
78
+ const transact = vi.fn();
79
+ const audit = vi.fn();
80
+
81
+ const result = await executeBulk({
82
+ collection: 'events',
83
+ ops: { inserts: [], updates: [], deletes: [] },
84
+ createSchema,
85
+ updateSchema,
86
+ access: ACCESS,
87
+ uid: 'u1',
88
+ userRole: 'user',
89
+ transact,
90
+ audit,
91
+ });
92
+
93
+ expect(result).toEqual({
94
+ insertedIds: [],
95
+ updatedIds: [],
96
+ deletedIds: [],
97
+ });
98
+ expect(transact).not.toHaveBeenCalled();
99
+ expect(audit).not.toHaveBeenCalled();
100
+ });
101
+
102
+ it('rejects with BulkCollisionError on updates/deletes collision, no transact', async () => {
103
+ const transact = vi.fn();
104
+ const audit = vi.fn();
105
+
106
+ await expect(
107
+ executeBulk({
108
+ collection: 'events',
109
+ ops: {
110
+ updates: [{ id: 'a', patch: { name: 'x' } }],
111
+ deletes: ['a'],
112
+ },
113
+ createSchema,
114
+ updateSchema,
115
+ access: ACCESS,
116
+ uid: 'u1',
117
+ userRole: 'user',
118
+ transact,
119
+ audit,
120
+ })
121
+ ).rejects.toBeInstanceOf(BulkCollisionError);
122
+
123
+ expect(transact).not.toHaveBeenCalled();
124
+ expect(audit).not.toHaveBeenCalled();
125
+ });
126
+
127
+ it('rejects with BulkCollisionError on inserts/updates id collision', async () => {
128
+ const transact = vi.fn();
129
+
130
+ await expect(
131
+ executeBulk({
132
+ collection: 'events',
133
+ ops: {
134
+ inserts: [{ id: 'shared', name: 'new' }],
135
+ updates: [{ id: 'shared', patch: { name: 'x' } }],
136
+ },
137
+ createSchema,
138
+ updateSchema,
139
+ access: ACCESS,
140
+ uid: 'u1',
141
+ userRole: 'user',
142
+ transact,
143
+ })
144
+ ).rejects.toMatchObject({
145
+ where: 'inserts-updates',
146
+ collidingIds: ['shared'],
147
+ });
148
+ expect(transact).not.toHaveBeenCalled();
149
+ });
150
+
151
+ it('per-bucket ACL: populated deletes bucket rejects when role insufficient', async () => {
152
+ const transact = vi.fn();
153
+
154
+ await expect(
155
+ executeBulk({
156
+ collection: 'events',
157
+ ops: { deletes: ['a', 'b'] },
158
+ createSchema,
159
+ updateSchema,
160
+ access: { ...ACCESS, delete: 'admin' },
161
+ uid: 'u1',
162
+ userRole: 'user',
163
+ transact,
164
+ })
165
+ ).rejects.toMatchObject({
166
+ code: 'permission-denied',
167
+ message: expect.stringContaining('admin'),
168
+ });
169
+
170
+ expect(transact).not.toHaveBeenCalled();
171
+ });
172
+
173
+ it('per-bucket ACL: populated bucket without configured role is a config error', async () => {
174
+ const transact = vi.fn();
175
+
176
+ await expect(
177
+ executeBulk({
178
+ collection: 'events',
179
+ ops: { inserts: [{ name: 'A' }] },
180
+ createSchema,
181
+ updateSchema,
182
+ access: { read: 'user' }, // no create role configured
183
+ uid: 'u1',
184
+ userRole: 'user',
185
+ transact,
186
+ })
187
+ ).rejects.toMatchObject({
188
+ code: 'permission-denied',
189
+ message: expect.stringContaining('no create role is configured'),
190
+ });
191
+
192
+ expect(transact).not.toHaveBeenCalled();
193
+ });
194
+
195
+ it('empty-bucket ACL: unpopulated buckets do not block execution', async () => {
196
+ // Only the update bucket carries work; a deletes-without-role config does
197
+ // NOT fail because the deletes bucket is empty.
198
+ const transact = vi.fn(okResponse);
199
+
200
+ const result = await executeBulk({
201
+ collection: 'events',
202
+ ops: { updates: [{ id: 'u1', patch: { name: 'x' } }] },
203
+ createSchema,
204
+ updateSchema,
205
+ access: { update: 'user' }, // no create/delete roles configured — fine
206
+ uid: 'u1',
207
+ userRole: 'user',
208
+ transact,
209
+ });
210
+
211
+ expect(transact).toHaveBeenCalledTimes(1);
212
+ expect(result.updatedIds).toEqual(['u1']);
213
+ });
214
+
215
+ it('validation failure on insert: prefixed with inserts[i], no transact', async () => {
216
+ const transact = vi.fn();
217
+
218
+ await expect(
219
+ executeBulk({
220
+ collection: 'events',
221
+ ops: {
222
+ inserts: [{ name: 'Alice' }, { name: '' }], // index 1 invalid
223
+ },
224
+ createSchema,
225
+ updateSchema,
226
+ access: ACCESS,
227
+ uid: 'u1',
228
+ userRole: 'user',
229
+ transact,
230
+ })
231
+ ).rejects.toMatchObject({
232
+ code: 'invalid-argument',
233
+ message: expect.stringContaining('inserts[1]'),
234
+ });
235
+
236
+ expect(transact).not.toHaveBeenCalled();
237
+ });
238
+
239
+ it('validation failure on update patch: prefixed with updates[i], no transact', async () => {
240
+ const transact = vi.fn();
241
+
242
+ await expect(
243
+ executeBulk({
244
+ collection: 'events',
245
+ ops: {
246
+ updates: [{ id: 'u1', patch: { name: 123 as any } }],
247
+ },
248
+ createSchema,
249
+ updateSchema,
250
+ access: ACCESS,
251
+ uid: 'u1',
252
+ userRole: 'user',
253
+ transact,
254
+ })
255
+ ).rejects.toMatchObject({
256
+ code: 'invalid-argument',
257
+ message: expect.stringContaining('updates[0]'),
258
+ });
259
+
260
+ expect(transact).not.toHaveBeenCalled();
261
+ });
262
+
263
+ it('wire-schema failure throws invalid-argument without calling transact', async () => {
264
+ const transact = vi.fn();
265
+
266
+ await expect(
267
+ executeBulk({
268
+ collection: 'events',
269
+ // Malformed: updates[0] missing `id`.
270
+ ops: { updates: [{ patch: { name: 'x' } } as any] },
271
+ createSchema,
272
+ updateSchema,
273
+ access: ACCESS,
274
+ uid: 'u1',
275
+ userRole: 'user',
276
+ transact,
277
+ })
278
+ ).rejects.toMatchObject({
279
+ code: 'invalid-argument',
280
+ message: expect.stringContaining('Bulk payload validation failed'),
281
+ });
282
+
283
+ expect(transact).not.toHaveBeenCalled();
284
+ });
285
+
286
+ it('transact called exactly once with prepared payload (minted ids + stamped metadata)', async () => {
287
+ let mintCounter = 0;
288
+ const transact = vi.fn(okResponse);
289
+ const audit = vi.fn();
290
+
291
+ const result = await executeBulk({
292
+ collection: 'events',
293
+ ops: {
294
+ inserts: [{ name: 'Alice' }, { name: 'Bob' }],
295
+ updates: [{ id: 'u1', patch: { name: 'Renamed' } }],
296
+ deletes: ['d1'],
297
+ },
298
+ createSchema,
299
+ updateSchema,
300
+ access: ACCESS,
301
+ uid: 'user-1',
302
+ userRole: 'user',
303
+ mintInsertId: () => `mint-${++mintCounter}`,
304
+ stampInsertMetadata: (row, uid) => ({ ...row, _uid: uid, _kind: 'ins' }),
305
+ stampUpdateMetadata: (patch, uid) => ({
306
+ ...patch,
307
+ _uid: uid,
308
+ _kind: 'upd',
309
+ }),
310
+ transact,
311
+ audit,
312
+ });
313
+
314
+ expect(transact).toHaveBeenCalledTimes(1);
315
+ const [prepared] = transact.mock.calls[0];
316
+ expect(prepared.inserts).toEqual([
317
+ {
318
+ id: 'mint-1',
319
+ row: {
320
+ name: 'Alice',
321
+ status: DEFAULT_STATUS_VALUE,
322
+ _uid: 'user-1',
323
+ _kind: 'ins',
324
+ },
325
+ },
326
+ {
327
+ id: 'mint-2',
328
+ row: {
329
+ name: 'Bob',
330
+ status: DEFAULT_STATUS_VALUE,
331
+ _uid: 'user-1',
332
+ _kind: 'ins',
333
+ },
334
+ },
335
+ ]);
336
+ expect(prepared.updates).toEqual([
337
+ {
338
+ id: 'u1',
339
+ patch: { name: 'Renamed', _uid: 'user-1', _kind: 'upd' },
340
+ },
341
+ ]);
342
+ expect(prepared.deletes).toEqual(['d1']);
343
+
344
+ // Response echoes input order.
345
+ expect(result.insertedIds).toEqual(['mint-1', 'mint-2']);
346
+ expect(result.updatedIds).toEqual(['u1']);
347
+ expect(result.deletedIds).toEqual(['d1']);
348
+ });
349
+
350
+ it('transact runs without mintInsertId: id is empty string, target mints its own', async () => {
351
+ const transact = vi.fn(() =>
352
+ // Target mints server-side and returns the ids.
353
+ Promise.resolve({
354
+ insertedIds: ['srv-1'],
355
+ updatedIds: [],
356
+ deletedIds: [],
357
+ })
358
+ );
359
+
360
+ const result = await executeBulk({
361
+ collection: 'events',
362
+ ops: { inserts: [{ name: 'Alice' }] },
363
+ createSchema,
364
+ updateSchema,
365
+ access: ACCESS,
366
+ uid: 'user-1',
367
+ userRole: 'user',
368
+ transact,
369
+ });
370
+
371
+ const [prepared] = transact.mock.calls[0];
372
+ expect(prepared.inserts).toEqual([
373
+ { id: '', row: { name: 'Alice', status: DEFAULT_STATUS_VALUE } },
374
+ ]);
375
+ expect(result.insertedIds).toEqual(['srv-1']);
376
+ });
377
+
378
+ it('response-schema validation rejects a malformed transact return', async () => {
379
+ const transact = vi.fn(() =>
380
+ Promise.resolve({
381
+ // Missing updatedIds + deletedIds — not a BulkResponse.
382
+ insertedIds: ['a'],
383
+ } as any)
384
+ );
385
+
386
+ await expect(
387
+ executeBulk({
388
+ collection: 'events',
389
+ ops: { inserts: [{ name: 'A' }] },
390
+ createSchema,
391
+ updateSchema,
392
+ access: ACCESS,
393
+ uid: 'u1',
394
+ userRole: 'user',
395
+ transact,
396
+ })
397
+ ).rejects.toMatchObject({
398
+ code: 'internal',
399
+ message: expect.stringContaining('unexpected shape'),
400
+ });
401
+ });
402
+
403
+ it('audit fires once with correct counts on success', async () => {
404
+ const transact = vi.fn(okResponse);
405
+ const audit = vi.fn();
406
+
407
+ await executeBulk({
408
+ collection: 'events',
409
+ ops: {
410
+ inserts: [{ name: 'A' }, { name: 'B' }, { name: 'C' }],
411
+ updates: [{ id: 'u1', patch: { name: 'x' } }],
412
+ deletes: ['d1', 'd2'],
413
+ },
414
+ createSchema,
415
+ updateSchema,
416
+ access: ACCESS,
417
+ uid: 'u1',
418
+ userRole: 'user',
419
+ transact,
420
+ audit,
421
+ });
422
+
423
+ expect(audit).toHaveBeenCalledTimes(1);
424
+ expect(audit).toHaveBeenCalledWith('crud.bulk.events', {
425
+ counts: { inserts: 3, updates: 1, deletes: 2 },
426
+ });
427
+ });
428
+
429
+ it('audit does NOT fire when transact throws', async () => {
430
+ const transact = vi.fn(() =>
431
+ Promise.reject(new Error('transaction aborted'))
432
+ );
433
+ const audit = vi.fn();
434
+
435
+ await expect(
436
+ executeBulk({
437
+ collection: 'events',
438
+ ops: { inserts: [{ name: 'A' }] },
439
+ createSchema,
440
+ updateSchema,
441
+ access: ACCESS,
442
+ uid: 'u1',
443
+ userRole: 'user',
444
+ transact,
445
+ audit,
446
+ })
447
+ ).rejects.toThrow('transaction aborted');
448
+
449
+ expect(audit).not.toHaveBeenCalled();
450
+ });
451
+
452
+ it('propagates non-DoNotDevError transact failures unchanged (for caller classification)', async () => {
453
+ const boom = new Error('deadlock');
454
+ const transact = vi.fn(() => Promise.reject(boom));
455
+
456
+ await expect(
457
+ executeBulk({
458
+ collection: 'events',
459
+ ops: { inserts: [{ name: 'A' }] },
460
+ createSchema,
461
+ updateSchema,
462
+ access: ACCESS,
463
+ uid: 'u1',
464
+ userRole: 'user',
465
+ transact,
466
+ })
467
+ ).rejects.toBe(boom);
468
+ });
469
+
470
+ it('DoNotDevError from transact propagates unchanged', async () => {
471
+ const boom = new DoNotDevError('rpc failure', 'internal');
472
+ const transact = vi.fn(() => Promise.reject(boom));
473
+
474
+ await expect(
475
+ executeBulk({
476
+ collection: 'events',
477
+ ops: { inserts: [{ name: 'A' }] },
478
+ createSchema,
479
+ updateSchema,
480
+ access: ACCESS,
481
+ uid: 'u1',
482
+ userRole: 'user',
483
+ transact,
484
+ })
485
+ ).rejects.toBe(boom);
486
+ });
487
+ });
File without changes
@@ -76,7 +76,9 @@ describe('toTimestamp', () => {
76
76
  it('converts ISO string to timestamp', () => {
77
77
  const ts = toTimestamp('2026-01-15T12:00:00.000Z');
78
78
 
79
- expect(ts.seconds).toBe(Math.floor(new Date('2026-01-15T12:00:00.000Z').getTime() / 1000));
79
+ expect(ts.seconds).toBe(
80
+ Math.floor(new Date('2026-01-15T12:00:00.000Z').getTime() / 1000)
81
+ );
80
82
  });
81
83
 
82
84
  it('converts Date object to timestamp', () => {
@@ -87,11 +89,15 @@ describe('toTimestamp', () => {
87
89
  });
88
90
 
89
91
  it('throws for invalid date string', () => {
90
- expect(() => toTimestamp('not-a-date')).toThrow('Failed to convert to timestamp');
92
+ expect(() => toTimestamp('not-a-date')).toThrow(
93
+ 'Failed to convert to timestamp'
94
+ );
91
95
  });
92
96
 
93
97
  it('throws for invalid Date object', () => {
94
- expect(() => toTimestamp(new Date('invalid'))).toThrow('Failed to convert to timestamp');
98
+ expect(() => toTimestamp(new Date('invalid'))).toThrow(
99
+ 'Failed to convert to timestamp'
100
+ );
95
101
  });
96
102
  });
97
103
 
File without changes
@@ -66,7 +66,9 @@ describe('validateCollectionName (internal)', () => {
66
66
  });
67
67
 
68
68
  it('rejects empty string', () => {
69
- expect(() => validateCollectionName('')).toThrow('Collection name is required');
69
+ expect(() => validateCollectionName('')).toThrow(
70
+ 'Collection name is required'
71
+ );
70
72
  });
71
73
 
72
74
  it('rejects non-string', () => {
@@ -79,11 +81,15 @@ describe('validateCollectionName (internal)', () => {
79
81
  });
80
82
 
81
83
  it('rejects path traversal with slash', () => {
82
- expect(() => validateCollectionName('a/b')).toThrow('Invalid collection name');
84
+ expect(() => validateCollectionName('a/b')).toThrow(
85
+ 'Invalid collection name'
86
+ );
83
87
  });
84
88
 
85
89
  it('rejects path traversal with double dots', () => {
86
- expect(() => validateCollectionName('a..b')).toThrow('Invalid collection name');
90
+ expect(() => validateCollectionName('a..b')).toThrow(
91
+ 'Invalid collection name'
92
+ );
87
93
  });
88
94
 
89
95
  it('rejects internal collections starting with underscore', () => {
@@ -16,23 +16,23 @@ describe('createMetadata', () => {
16
16
  const result = createMetadata('user-123');
17
17
 
18
18
  expect(result).toEqual({
19
- _createdAt: '2026-03-13T10:00:00.000Z',
20
- _updatedAt: '2026-03-13T10:00:00.000Z',
21
- _createdBy: 'user-123',
22
- _updatedBy: 'user-123',
19
+ createdAt: '2026-03-13T10:00:00.000Z',
20
+ updatedAt: '2026-03-13T10:00:00.000Z',
21
+ createdById: 'user-123',
22
+ updatedById: 'user-123',
23
23
  });
24
24
  });
25
25
 
26
26
  it('sets createdAt and updatedAt to the same value', () => {
27
27
  const result = createMetadata('any');
28
28
 
29
- expect(result._createdAt).toBe(result._updatedAt);
29
+ expect(result.createdAt).toBe(result.updatedAt);
30
30
  });
31
31
 
32
32
  it('uses ISO 8601 format', () => {
33
33
  const result = createMetadata('u');
34
34
 
35
- expect(result._createdAt).toMatch(
35
+ expect(result.createdAt).toMatch(
36
36
  /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
37
37
  );
38
38
  });
@@ -52,15 +52,15 @@ describe('updateMetadata', () => {
52
52
  const result = updateMetadata('user-456');
53
53
 
54
54
  expect(result).toEqual({
55
- _updatedAt: '2026-06-15T14:30:00.000Z',
56
- _updatedBy: 'user-456',
55
+ updatedAt: '2026-06-15T14:30:00.000Z',
56
+ updatedById: 'user-456',
57
57
  });
58
58
  });
59
59
 
60
60
  it('does not include creation fields', () => {
61
61
  const result = updateMetadata('u') as any;
62
62
 
63
- expect(result._createdAt).toBeUndefined();
64
- expect(result._createdBy).toBeUndefined();
63
+ expect(result.createdAt).toBeUndefined();
64
+ expect(result.createdById).toBeUndefined();
65
65
  });
66
66
  });
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,12 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';
1
+ import {
2
+ describe,
3
+ it,
4
+ expect,
5
+ vi,
6
+ beforeEach,
7
+ afterEach,
8
+ afterAll,
9
+ } from 'vitest';
2
10
 
3
11
  // Mock external dependencies that utils.ts imports at module level
4
12
  vi.mock('stripe', () => ({
@@ -240,9 +248,7 @@ describe('assertAuthenticated', () => {
240
248
  });
241
249
 
242
250
  it('throws when auth has no uid', () => {
243
- expect(() => assertAuthenticated({})).toThrow(
244
- 'User must be authenticated'
245
- );
251
+ expect(() => assertAuthenticated({})).toThrow('User must be authenticated');
246
252
  });
247
253
 
248
254
  it('throws when auth.uid is empty string', () => {
@@ -16,7 +16,9 @@ describe('validateEnvironment', () => {
16
16
  });
17
17
 
18
18
  it('throws listing all missing env vars', () => {
19
- expect(() => validateEnvironment()).toThrow('Missing required environment variables');
19
+ expect(() => validateEnvironment()).toThrow(
20
+ 'Missing required environment variables'
21
+ );
20
22
  expect(() => validateEnvironment()).toThrow('STRIPE_SECRET_KEY');
21
23
  expect(() => validateEnvironment()).toThrow('STRIPE_WEBHOOK_SECRET');
22
24
  expect(() => validateEnvironment()).toThrow('STRIPE_API_VERSION');
@@ -34,7 +36,9 @@ describe('validateEnvironment', () => {
34
36
  process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
35
37
  process.env.STRIPE_API_VERSION = 'bad-format';
36
38
 
37
- expect(() => validateEnvironment()).toThrow('Invalid STRIPE_API_VERSION format');
39
+ expect(() => validateEnvironment()).toThrow(
40
+ 'Invalid STRIPE_API_VERSION format'
41
+ );
38
42
  });
39
43
 
40
44
  it('throws for invalid STRIPE_SECRET_KEY format', () => {
@@ -42,7 +46,9 @@ describe('validateEnvironment', () => {
42
46
  process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
43
47
  process.env.STRIPE_API_VERSION = '2025-09-30.clover';
44
48
 
45
- expect(() => validateEnvironment()).toThrow('Invalid STRIPE_SECRET_KEY format');
49
+ expect(() => validateEnvironment()).toThrow(
50
+ 'Invalid STRIPE_SECRET_KEY format'
51
+ );
46
52
  });
47
53
 
48
54
  it('passes with all valid env vars', () => {
File without changes