@donotdev/functions 0.1.0 → 0.1.42

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 +9 -0
  4. package/guidelines/VERCEL.md +286 -0
  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 +10 -13
  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 +35 -0
  46. package/lib/shared/ai/costTracker.d.ts +20 -0
  47. package/lib/shared/ai/createAIHandler.d.ts +39 -0
  48. package/lib/shared/ai/createAIRoute.d.ts +20 -0
  49. package/lib/shared/ai/index.d.ts +6 -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 +14 -0
  55. package/lib/shared/ai/utils/parseSSE.d.ts +22 -0
  56. package/lib/shared/billing/createCheckout.d.ts +8 -2
  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 +30 -0
  66. package/lib/shared/email/index.d.ts +3 -0
  67. package/lib/shared/email/provider.d.ts +30 -0
  68. package/lib/shared/email/resendProvider.d.ts +22 -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 +5 -0
  72. package/lib/shared/index.d.ts +3 -0
  73. package/lib/shared/index.js +4 -3
  74. package/lib/shared/index.js.map +4 -4
  75. package/lib/shared/logger.d.ts +2 -0
  76. package/lib/shared/metadata.d.ts +6 -6
  77. package/lib/shared/oauth/exchangeToken.d.ts +1 -0
  78. package/lib/shared/oauth/grantAccess.d.ts +1 -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 +1 -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 +30 -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 +1 -1
  106. package/lib/supabase/auth/setCustomClaims.d.ts +12 -4
  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 +1 -1
  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 +1 -0
  114. package/lib/supabase/crud/bulk.d.ts +63 -0
  115. package/lib/supabase/crud/create.d.ts +2 -1
  116. package/lib/supabase/crud/delete.d.ts +1 -0
  117. package/lib/supabase/crud/get.d.ts +1 -0
  118. package/lib/supabase/crud/index.d.ts +2 -0
  119. package/lib/supabase/crud/list.d.ts +1 -0
  120. package/lib/supabase/crud/update.d.ts +1 -0
  121. package/lib/supabase/edgeFunction.d.ts +56 -0
  122. package/lib/supabase/email/createEmailFunction.d.ts +31 -0
  123. package/lib/supabase/helpers/authProvider.d.ts +0 -0
  124. package/lib/supabase/index.d.ts +8 -0
  125. package/lib/supabase/index.js +3 -2
  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 +29 -0
  137. package/lib/vercel/api/ai/index.d.ts +1 -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 +1 -0
  161. package/lib/vercel/api/index.js +3 -2
  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 +40 -7
  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 +82 -186
  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 +4 -4
  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 +4 -4
  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 +133 -0
  227. package/src/shared/ai/classifyAIError.ts +178 -0
  228. package/src/shared/ai/costTracker.ts +51 -0
  229. package/src/shared/ai/createAIRoute.ts +400 -0
  230. package/src/shared/ai/index.ts +8 -0
  231. package/src/shared/ai/resolveModelTier.ts +61 -0
  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 +168 -8
  235. package/src/shared/billing/helpers/index.ts +0 -0
  236. package/src/shared/billing/helpers/subscriptionManagement.ts +9 -0
  237. package/src/shared/billing/helpers/updateUserSubscription.ts +0 -0
  238. package/src/shared/billing/idempotency.ts +5 -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 +81 -0
  244. package/src/shared/email/index.ts +5 -0
  245. package/src/shared/email/provider.ts +31 -0
  246. package/src/shared/email/resendProvider.ts +56 -0
  247. package/src/shared/errorHandling.ts +10 -4
  248. package/src/shared/firebase.ts +0 -0
  249. package/src/shared/github.ts +38 -0
  250. package/src/shared/index.d.ts +9 -0
  251. package/src/shared/index.ts +3 -0
  252. package/src/shared/logger.ts +2 -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 +1 -0
  257. package/src/shared/oauth/grantAccess.ts +1 -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 +1 -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 +6 -3
  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 +1 -1
  281. package/src/supabase/__tests__/bulk.test.ts +330 -0
  282. package/src/supabase/ai/createAIFunction.ts +76 -0
  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 +38 -2
  287. package/src/supabase/auth/setCustomClaims.ts +64 -5
  288. package/src/supabase/baseFunction.ts +26 -2
  289. package/src/supabase/billing/cancelSubscription.ts +0 -0
  290. package/src/supabase/billing/changePlan.ts +6 -1
  291. package/src/supabase/billing/createCheckoutSession.ts +16 -2
  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 +1 -0
  295. package/src/supabase/crud/bulk.ts +244 -0
  296. package/src/supabase/crud/create.ts +16 -14
  297. package/src/supabase/crud/delete.ts +1 -0
  298. package/src/supabase/crud/get.ts +1 -0
  299. package/src/supabase/crud/index.ts +2 -0
  300. package/src/supabase/crud/list.ts +1 -0
  301. package/src/supabase/crud/update.ts +1 -0
  302. package/src/supabase/edgeFunction.ts +196 -0
  303. package/src/supabase/email/createEmailFunction.ts +72 -0
  304. package/src/supabase/helpers/authProvider.ts +0 -0
  305. package/src/supabase/index.ts +21 -0
  306. package/src/supabase/oauth/disconnect.ts +1 -2
  307. package/src/supabase/oauth/exchangeToken.ts +39 -10
  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 +6 -12
  311. package/src/supabase/registerCrudFunctions.ts +20 -20
  312. package/src/supabase/utils/idempotency.ts +6 -2
  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 +77 -0
  317. package/src/vercel/api/ai/index.ts +3 -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 +31 -4
  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 +8 -1
  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 +1 -0
  342. package/src/vercel/api/oauth/check-github-access.ts +0 -0
  343. package/src/vercel/api/oauth/exchange-token.ts +27 -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 +8 -0
  348. package/src/vercel/baseFunction.ts +0 -0
@@ -0,0 +1,330 @@
1
+ /**
2
+ * @fileoverview Unit tests for `createSupabaseBulkEntity`.
3
+ * @description Exercises happy-path, empty-bulk short-circuit, collision rejection,
4
+ * validation failure, ACL failure, and field-mapping preservation. The base
5
+ * handler wrapper (`createSupabaseHandler`) is stubbed so tests invoke the
6
+ * inner business logic directly without needing a mock Deno `Request`.
7
+ */
8
+
9
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
10
+ import * as v from 'valibot';
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Mocks
14
+ // ---------------------------------------------------------------------------
15
+
16
+ // Stub the wrapper so the factory returns `(data, ctx) => handler(...)` instead
17
+ // of a Request-based handler. This lets us call the business logic directly
18
+ // and assert on its behaviour without mocking a full Deno runtime.
19
+ vi.mock('../baseFunction.js', () => ({
20
+ createSupabaseHandler: vi.fn(
21
+ (_operationName: string, _schema: unknown, handler: any) => handler
22
+ ),
23
+ }));
24
+
25
+ // Field mapper stub — identity roundtrip is enough to prove mapping is invoked
26
+ // (we spy on the calls and verify snake_case output in the happy path).
27
+ vi.mock('@donotdev/supabase/server', () => ({
28
+ defaultFieldMapper: {
29
+ toBackendField: (f: string) => f,
30
+ toBackendKeys: (o: Record<string, unknown>) => {
31
+ // Convert camelCase → snake_case for the keys we stamp as metadata.
32
+ const out: Record<string, unknown> = {};
33
+ for (const [k, v] of Object.entries(o)) {
34
+ const snake = k.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
35
+ out[snake] = v;
36
+ }
37
+ return out;
38
+ },
39
+ fromBackendRow: (r: Record<string, unknown>) => r,
40
+ },
41
+ }));
42
+
43
+ // Import after mocks so the bulk module picks them up.
44
+ import { createSupabaseBulkEntity } from '../crud/bulk.js';
45
+
46
+ // ---------------------------------------------------------------------------
47
+ // Fixtures
48
+ // ---------------------------------------------------------------------------
49
+
50
+ const CreateSchema = v.object({
51
+ name: v.pipe(v.string(), v.minLength(1)),
52
+ });
53
+ const UpdateSchema = v.object({
54
+ name: v.optional(v.string()),
55
+ });
56
+
57
+ const access = {
58
+ create: 'user' as const,
59
+ read: 'user' as const,
60
+ update: 'user' as const,
61
+ delete: 'user' as const,
62
+ };
63
+
64
+ /** Build a bulk handler + a stubbed Supabase admin client. */
65
+ function setup(opts?: {
66
+ rpcResult?: unknown;
67
+ rpcError?: { message: string } | null;
68
+ }) {
69
+ const rpcSpy = vi.fn().mockResolvedValue({
70
+ data: opts?.rpcResult ?? {
71
+ insertedIds: [],
72
+ updatedIds: [],
73
+ deletedIds: [],
74
+ },
75
+ error: opts?.rpcError ?? null,
76
+ });
77
+ const supabaseAdmin = { rpc: rpcSpy } as unknown as any;
78
+
79
+ const inner = createSupabaseBulkEntity(
80
+ 'events',
81
+ CreateSchema,
82
+ UpdateSchema,
83
+ access
84
+ ) as unknown as (data: any, ctx: any) => Promise<any>;
85
+
86
+ return {
87
+ handler: inner,
88
+ rpcSpy,
89
+ ctx: {
90
+ uid: 'user-1',
91
+ userRole: 'user' as const,
92
+ supabaseAdmin,
93
+ },
94
+ };
95
+ }
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // Tests
99
+ // ---------------------------------------------------------------------------
100
+
101
+ describe('createSupabaseBulkEntity', () => {
102
+ beforeEach(() => {
103
+ vi.clearAllMocks();
104
+ });
105
+
106
+ it('happy path: 2 inserts + 1 update + 1 delete → calls RPC once, returns echoed ids in input order', async () => {
107
+ const rpcResult = {
108
+ insertedIds: ['new-1', 'new-2'],
109
+ updatedIds: ['u-1'],
110
+ deletedIds: ['d-1'],
111
+ };
112
+ const { handler, rpcSpy, ctx } = setup({ rpcResult });
113
+
114
+ const result = await handler(
115
+ {
116
+ inserts: [{ name: 'Alice' }, { name: 'Bob' }],
117
+ updates: [{ id: 'u-1', patch: { name: 'Updated' } }],
118
+ deletes: ['d-1'],
119
+ },
120
+ ctx
121
+ );
122
+
123
+ expect(rpcSpy).toHaveBeenCalledTimes(1);
124
+ expect(rpcSpy).toHaveBeenCalledWith(
125
+ 'crud_bulk',
126
+ expect.objectContaining({
127
+ p_collection: 'events',
128
+ p_inserts: expect.any(Array),
129
+ p_updates: expect.any(Array),
130
+ p_deletes: ['d-1'],
131
+ })
132
+ );
133
+ expect(result).toEqual(rpcResult);
134
+ });
135
+
136
+ it('empty bulk short-circuits: no RPC call, zeroed response', async () => {
137
+ const { handler, rpcSpy, ctx } = setup();
138
+
139
+ const result = await handler({}, ctx);
140
+
141
+ expect(rpcSpy).not.toHaveBeenCalled();
142
+ expect(result).toEqual({
143
+ insertedIds: [],
144
+ updatedIds: [],
145
+ deletedIds: [],
146
+ });
147
+ });
148
+
149
+ it('empty arrays also short-circuit (no RPC call)', async () => {
150
+ const { handler, rpcSpy, ctx } = setup();
151
+
152
+ const result = await handler(
153
+ { inserts: [], updates: [], deletes: [] },
154
+ ctx
155
+ );
156
+
157
+ expect(rpcSpy).not.toHaveBeenCalled();
158
+ expect(result).toEqual({
159
+ insertedIds: [],
160
+ updatedIds: [],
161
+ deletedIds: [],
162
+ });
163
+ });
164
+
165
+ it('collision rejection (updates + deletes): throws, no RPC', async () => {
166
+ const { handler, rpcSpy, ctx } = setup();
167
+
168
+ await expect(
169
+ handler(
170
+ {
171
+ updates: [{ id: 'a', patch: { name: 'X' } }],
172
+ deletes: ['a'],
173
+ },
174
+ ctx
175
+ )
176
+ ).rejects.toMatchObject({
177
+ code: 'invalid-argument',
178
+ message: expect.stringContaining('BulkCollisionError'),
179
+ details: expect.objectContaining({
180
+ collidingIds: ['a'],
181
+ where: 'updates-deletes',
182
+ }),
183
+ });
184
+ expect(rpcSpy).not.toHaveBeenCalled();
185
+ });
186
+
187
+ it('validation failure on insert: rejects before any RPC write', async () => {
188
+ const { handler, rpcSpy, ctx } = setup();
189
+
190
+ await expect(
191
+ handler(
192
+ {
193
+ inserts: [{ name: 'Alice' }, { name: '' }], // second one invalid
194
+ updates: [{ id: 'u-1', patch: { name: 'Ok' } }],
195
+ },
196
+ ctx
197
+ )
198
+ ).rejects.toMatchObject({
199
+ code: 'invalid-argument',
200
+ message: expect.stringContaining('inserts[1]'),
201
+ });
202
+
203
+ expect(rpcSpy).not.toHaveBeenCalled();
204
+ });
205
+
206
+ it('validation failure on update patch: rejects before any RPC write', async () => {
207
+ const { handler, rpcSpy, ctx } = setup();
208
+
209
+ await expect(
210
+ handler(
211
+ {
212
+ updates: [{ id: 'u-1', patch: { name: 123 as any } }], // number not string
213
+ },
214
+ ctx
215
+ )
216
+ ).rejects.toMatchObject({
217
+ code: 'invalid-argument',
218
+ message: expect.stringContaining('updates[0]'),
219
+ });
220
+ expect(rpcSpy).not.toHaveBeenCalled();
221
+ });
222
+
223
+ it('ACL failure: user lacks delete role → rejects, no RPC', async () => {
224
+ const rpcSpy = vi.fn();
225
+ const supabaseAdmin = { rpc: rpcSpy } as unknown as any;
226
+
227
+ const inner = createSupabaseBulkEntity(
228
+ 'events',
229
+ CreateSchema,
230
+ UpdateSchema,
231
+ { ...access, delete: 'admin' }
232
+ ) as unknown as (data: any, ctx: any) => Promise<any>;
233
+
234
+ await expect(
235
+ inner(
236
+ { deletes: ['a', 'b'] },
237
+ { uid: 'u', userRole: 'user', supabaseAdmin }
238
+ )
239
+ ).rejects.toMatchObject({
240
+ code: 'permission-denied',
241
+ message: expect.stringContaining('admin'),
242
+ });
243
+ expect(rpcSpy).not.toHaveBeenCalled();
244
+ });
245
+
246
+ it('field-mapping: inserts carry snake_case metadata (created_at, created_by_id) via toBackendKeys', async () => {
247
+ const rpcResult = {
248
+ insertedIds: ['n-1'],
249
+ updatedIds: [],
250
+ deletedIds: [],
251
+ };
252
+ const { handler, rpcSpy, ctx } = setup({ rpcResult });
253
+
254
+ await handler({ inserts: [{ name: 'Alice' }] }, ctx);
255
+
256
+ expect(rpcSpy).toHaveBeenCalledTimes(1);
257
+ const call = rpcSpy.mock.calls[0];
258
+ const args = call[1];
259
+ const firstInsert = args.p_inserts[0];
260
+
261
+ // Metadata keys came from createMetadata() and were snake-cased by our
262
+ // stubbed toBackendKeys.
263
+ expect(firstInsert).toMatchObject({
264
+ name: 'Alice',
265
+ created_by_id: 'user-1',
266
+ updated_by_id: 'user-1',
267
+ });
268
+ expect(firstInsert.created_at).toBeDefined();
269
+ expect(firstInsert.updated_at).toBeDefined();
270
+ });
271
+
272
+ it('field-mapping: updates carry snake_case metadata (updated_at, updated_by_id), no created_* leakage', async () => {
273
+ const rpcResult = {
274
+ insertedIds: [],
275
+ updatedIds: ['u-1'],
276
+ deletedIds: [],
277
+ };
278
+ const { handler, rpcSpy, ctx } = setup({ rpcResult });
279
+
280
+ await handler(
281
+ { updates: [{ id: 'u-1', patch: { name: 'Renamed' } }] },
282
+ ctx
283
+ );
284
+
285
+ const args = rpcSpy.mock.calls[0][1];
286
+ const firstPatch = args.p_updates[0].patch;
287
+
288
+ expect(firstPatch).toMatchObject({
289
+ name: 'Renamed',
290
+ updated_by_id: 'user-1',
291
+ });
292
+ expect(firstPatch.updated_at).toBeDefined();
293
+ expect(firstPatch.created_by_id).toBeUndefined();
294
+ expect(firstPatch.created_at).toBeUndefined();
295
+ });
296
+
297
+ it('RPC error surfaces as DoNotDevError (transaction-level failure)', async () => {
298
+ const { handler, ctx } = setup({
299
+ rpcError: { message: 'deadlock detected' },
300
+ });
301
+
302
+ await expect(handler({ deletes: ['a'] }, ctx)).rejects.toMatchObject({
303
+ code: 'internal',
304
+ message: expect.stringContaining('bulk'),
305
+ });
306
+ });
307
+
308
+ it('input order is preserved in RPC payload', async () => {
309
+ const rpcResult = {
310
+ insertedIds: ['n-1', 'n-2', 'n-3'],
311
+ updatedIds: ['u-1', 'u-2'],
312
+ deletedIds: ['d-1', 'd-2'],
313
+ };
314
+ const { handler, rpcSpy, ctx } = setup({ rpcResult });
315
+
316
+ const inserts = [{ name: 'A' }, { name: 'B' }, { name: 'C' }];
317
+ const updates = [
318
+ { id: 'u-1', patch: { name: 'X' } },
319
+ { id: 'u-2', patch: { name: 'Y' } },
320
+ ];
321
+ const deletes = ['d-1', 'd-2'];
322
+
323
+ await handler({ inserts, updates, deletes }, ctx);
324
+
325
+ const args = rpcSpy.mock.calls[0][1];
326
+ expect(args.p_inserts.map((r: any) => r.name)).toEqual(['A', 'B', 'C']);
327
+ expect(args.p_updates.map((u: any) => u.id)).toEqual(['u-1', 'u-2']);
328
+ expect(args.p_deletes).toEqual(['d-1', 'd-2']);
329
+ });
330
+ });
@@ -0,0 +1,76 @@
1
+ // packages/functions/src/supabase/ai/createAIFunction.ts
2
+
3
+ /**
4
+ * @fileoverview AI Chat - Supabase Edge Function Factory
5
+ * @description Wraps the shared AI route handler for Supabase Edge Functions.
6
+ * Uses Vercel AI SDK via createAIRoute for streaming and non-streaming.
7
+ *
8
+ * @version 0.1.0
9
+ * @since 0.1.0
10
+ * @author AMBROISE PARK Consulting
11
+ */
12
+
13
+ import type {
14
+ AIChatRequest,
15
+ AICostRecord,
16
+ AIRouteConfig,
17
+ } from '@donotdev/core/server';
18
+ import { AIChatRequestSchema } from '@donotdev/core/server';
19
+
20
+ import { handleAIRequest } from '../../shared/ai/index.js';
21
+ import { createSupabaseHandler } from '../baseFunction.js';
22
+
23
+ /**
24
+ * Create a Supabase Edge Function handler for AI chat.
25
+ *
26
+ * @param config - AI route configuration
27
+ * @returns `(req: Request) => Promise<Response>` handler
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // supabase/functions/ai-chat/index.ts
32
+ * import { createAIFunction } from '@donotdev/functions/supabase';
33
+ *
34
+ * const handler = createAIFunction({
35
+ * provider: 'anthropic',
36
+ * model: 'claude-sonnet-4-20250514',
37
+ * cost: { markup: 4.0, monthlyBudgetTokens: 500_000, showCostToUsers: false, displayCurrency: 'eur' },
38
+ * });
39
+ * Deno.serve(handler);
40
+ * ```
41
+ */
42
+ export function createAIFunction(config: AIRouteConfig) {
43
+ return createSupabaseHandler(
44
+ 'ai-chat',
45
+ AIChatRequestSchema,
46
+ async (data: AIChatRequest, ctx) => {
47
+ return handleAIRequest(data, config, {
48
+ userId: ctx.uid,
49
+ requestId: crypto.randomUUID(),
50
+ onCostRecord: async (record: AICostRecord) => {
51
+ // Write cost record to Supabase
52
+ const { error } = await ctx.supabaseAdmin.from('ai_usage').insert({
53
+ user_id: record.userId,
54
+ model: record.model,
55
+ provider: record.provider,
56
+ prompt_tokens: record.usage.promptTokens,
57
+ completion_tokens: record.usage.completionTokens,
58
+ total_tokens: record.usage.totalTokens,
59
+ provider_cost: record.providerCost,
60
+ billed_cost: record.billedCost,
61
+ markup: record.markup,
62
+ request_id: record.requestId,
63
+ created_at: record.timestamp,
64
+ });
65
+
66
+ if (error) {
67
+ console.error(
68
+ '[AI] Failed to record cost to Supabase:',
69
+ error.message
70
+ );
71
+ }
72
+ },
73
+ });
74
+ }
75
+ );
76
+ }
File without changes
File without changes
File without changes
@@ -3,8 +3,9 @@
3
3
  /**
4
4
  * @fileoverview Remove Custom Claims Supabase Edge Function
5
5
  * @description Removes specific keys from the user's app_metadata.
6
+ * Blocklist prevents removal of security-critical claims.
6
7
  *
7
- * @version 0.1.0
8
+ * @version 0.2.0
8
9
  * @since 0.6.0
9
10
  * @author AMBROISE PARK Consulting
10
11
  */
@@ -24,6 +25,31 @@ const removeCustomClaimsSchema = v.object({
24
25
  ),
25
26
  });
26
27
 
28
+ /**
29
+ * Claim keys that must NEVER be removed by users - privilege/integrity vectors.
30
+ * Matches BLOCKED_CLAIM_KEYS in setCustomClaims.ts.
31
+ */
32
+ const BLOCKED_CLAIM_KEYS = new Set([
33
+ 'admin',
34
+ 'isAdmin',
35
+ 'isSuper',
36
+ 'isSuperAdmin',
37
+ 'role',
38
+ 'roles',
39
+ 'permissions',
40
+ 'superuser',
41
+ 'moderator',
42
+ 'staff',
43
+ 'elevated',
44
+ 'plan',
45
+ 'tier',
46
+ 'provider',
47
+ 'providers',
48
+ 'sub',
49
+ 'iss',
50
+ 'aud',
51
+ ]);
52
+
27
53
  // =============================================================================
28
54
  // Handler
29
55
  // =============================================================================
@@ -40,7 +66,7 @@ const removeCustomClaimsSchema = v.object({
40
66
  * Deno.serve(createRemoveCustomClaims());
41
67
  * ```
42
68
  *
43
- * @version 0.1.0
69
+ * @version 0.2.0
44
70
  * @since 0.6.0
45
71
  */
46
72
  export function createRemoveCustomClaims() {
@@ -48,6 +74,16 @@ export function createRemoveCustomClaims() {
48
74
  'remove-custom-claims',
49
75
  removeCustomClaimsSchema,
50
76
  async (data, ctx) => {
77
+ // Block removal of security-critical claims
78
+ const blocked = data.claimsToRemove.filter((k) =>
79
+ BLOCKED_CLAIM_KEYS.has(k)
80
+ );
81
+ if (blocked.length > 0) {
82
+ throw new Error(
83
+ `Protected claims cannot be removed: ${blocked.join(', ')}`
84
+ );
85
+ }
86
+
51
87
  // Get current app_metadata
52
88
  const {
53
89
  data: { user },
@@ -3,8 +3,10 @@
3
3
  /**
4
4
  * @fileoverview Set Custom Claims Supabase Edge Function
5
5
  * @description Merges custom claims into the user's app_metadata.
6
+ * Mirrors the Firebase pattern: consumer provides an explicit allowlist,
7
+ * framework enforces a blocklist as safety net.
6
8
  *
7
- * @version 0.1.0
9
+ * @version 0.2.0
8
10
  * @since 0.6.0
9
11
  * @author AMBROISE PARK Consulting
10
12
  */
@@ -22,6 +24,41 @@ const setCustomClaimsSchema = v.object({
22
24
  idempotencyKey: v.optional(v.string()),
23
25
  });
24
26
 
27
+ /**
28
+ * Claim keys that must NEVER be self-assignable - privilege escalation vectors.
29
+ * Matches Firebase `BLOCKED_CLAIM_KEYS`.
30
+ */
31
+ const BLOCKED_CLAIM_KEYS = new Set([
32
+ 'admin',
33
+ 'isAdmin',
34
+ 'isSuper',
35
+ 'isSuperAdmin',
36
+ 'role',
37
+ 'roles',
38
+ 'permissions',
39
+ 'superuser',
40
+ 'moderator',
41
+ 'staff',
42
+ 'elevated',
43
+ 'plan',
44
+ 'tier',
45
+ 'provider',
46
+ 'providers',
47
+ 'sub',
48
+ 'iss',
49
+ 'aud',
50
+ ]);
51
+
52
+ // =============================================================================
53
+ // Types
54
+ // =============================================================================
55
+
56
+ /** Options for the set-custom-claims edge function factory. */
57
+ export interface SetCustomClaimsOptions {
58
+ /** Explicit allowlist of claim keys users may set on themselves. Required. */
59
+ allowedClaimKeys: string[];
60
+ }
61
+
25
62
  // =============================================================================
26
63
  // Handler
27
64
  // =============================================================================
@@ -29,25 +66,47 @@ const setCustomClaimsSchema = v.object({
29
66
  /**
30
67
  * Create a Supabase Edge Function handler for setting custom claims (app_metadata).
31
68
  *
32
- * Merges provided claims into the user's existing app_metadata.
69
+ * Consumers MUST specify which claim keys are self-assignable.
70
+ * The framework enforces a blocklist as a safety net even if the consumer
71
+ * accidentally includes a privilege key.
33
72
  *
73
+ * @param options - Configuration with allowedClaimKeys
34
74
  * @returns `(req: Request) => Promise<Response>` handler
35
75
  *
36
76
  * @example
37
77
  * ```typescript
38
78
  * // supabase/functions/set-custom-claims/index.ts
39
79
  * import { createSetCustomClaims } from '@donotdev/functions/supabase';
40
- * Deno.serve(createSetCustomClaims());
80
+ * Deno.serve(createSetCustomClaims({ allowedClaimKeys: ['theme', 'locale'] }));
41
81
  * ```
42
82
  *
43
- * @version 0.1.0
83
+ * @version 0.2.0
44
84
  * @since 0.6.0
45
85
  */
46
- export function createSetCustomClaims() {
86
+ export function createSetCustomClaims(options: SetCustomClaimsOptions) {
87
+ const allowedKeys = new Set(options.allowedClaimKeys);
88
+
89
+ // Fail fast if consumer accidentally allows a privilege key
90
+ for (const key of allowedKeys) {
91
+ if (BLOCKED_CLAIM_KEYS.has(key)) {
92
+ throw new Error(
93
+ `Claim key "${key}" is blocked - it is a privilege-escalation vector and cannot be self-assigned.`
94
+ );
95
+ }
96
+ }
97
+
47
98
  return createSupabaseHandler(
48
99
  'set-custom-claims',
49
100
  setCustomClaimsSchema,
50
101
  async (data, ctx) => {
102
+ // Only allow keys from the consumer-provided allowlist
103
+ const disallowedKeys = Object.keys(data.customClaims).filter(
104
+ (k) => !allowedKeys.has(k)
105
+ );
106
+ if (disallowedKeys.length > 0) {
107
+ throw new Error(`Claim keys not allowed: ${disallowedKeys.join(', ')}`);
108
+ }
109
+
51
110
  // Get current app_metadata
52
111
  const {
53
112
  data: { user },
@@ -259,12 +259,36 @@ export function createSupabaseHandler<TReq, TRes>(
259
259
  }
260
260
  }
261
261
 
262
+ // Passthrough for streaming responses (e.g., AI SSE streams)
263
+ if (result instanceof Response) {
264
+ const headers = new Headers(result.headers);
265
+ headers.set('Access-Control-Allow-Origin', allowedOrigin);
266
+ return new Response(result.body, {
267
+ status: result.status,
268
+ statusText: result.statusText,
269
+ headers,
270
+ });
271
+ }
272
+
262
273
  return respond(result, 200);
263
274
  } catch (error) {
264
275
  console.error(`[${operationName}] Error:`, error);
265
- const message =
276
+ const rawMessage =
266
277
  error instanceof Error ? error.message : 'Internal server error';
267
- const status = getErrorStatus(message);
278
+ const errorCode = getErrorCode(rawMessage);
279
+ // Only pass through messages for known safe error codes.
280
+ // All other/unknown errors get a generic message to prevent information leaks.
281
+ const SAFE_ERROR_CODES = new Set([
282
+ 'rate-limit-exceeded',
283
+ 'not-found',
284
+ 'permission-denied',
285
+ 'invalid-argument',
286
+ 'already-exists',
287
+ ]);
288
+ const message = SAFE_ERROR_CODES.has(errorCode)
289
+ ? rawMessage
290
+ : 'Internal server error';
291
+ const status = getErrorStatus(rawMessage);
268
292
  // allowedOrigin may not be set if error occurred before that line; fall back to '*'
269
293
  const origin = getEnv('ALLOWED_ORIGIN', '*');
270
294
  return jsonResponse({ error: message }, status, origin);
File without changes
@@ -11,7 +11,7 @@
11
11
 
12
12
  import * as v from 'valibot';
13
13
 
14
- import type { StripeBackConfig } from '@donotdev/core/server';
14
+ import { hasRoleAccess, type StripeBackConfig } from '@donotdev/core/server';
15
15
 
16
16
  import { changeUserPlan } from '../../shared/billing/helpers/subscriptionManagement.js';
17
17
  import { initStripe } from '../../shared/utils.js';
@@ -49,6 +49,11 @@ export function createChangePlan(billingConfig: StripeBackConfig) {
49
49
  'change-plan',
50
50
  changePlanSchema,
51
51
  async (data, ctx) => {
52
+ // Non-admin users can only change their own plan
53
+ if (!hasRoleAccess(ctx.userRole, 'admin') && data.userId !== ctx.uid) {
54
+ throw new Error("Forbidden: cannot change another user's plan");
55
+ }
56
+
52
57
  initStripe(getStripeKey());
53
58
  const authProvider = createSupabaseAuthProvider(ctx.supabaseAdmin);
54
59
  return changeUserPlan(
@@ -47,7 +47,10 @@ export function createCheckoutSession(billingConfig: StripeBackConfig) {
47
47
 
48
48
  const stripeProvider = {
49
49
  async createCheckoutSession(params: {
50
- priceId: string;
50
+ priceId?: string;
51
+ unitAmount?: number;
52
+ productName?: string;
53
+ currency?: string;
51
54
  customerEmail?: string;
52
55
  metadata: Record<string, string>;
53
56
  allowPromotionCodes: boolean;
@@ -57,7 +60,18 @@ export function createCheckoutSession(billingConfig: StripeBackConfig) {
57
60
  }) {
58
61
  const session = await stripe.checkout.sessions.create({
59
62
  mode: params.mode || 'payment',
60
- line_items: [{ price: params.priceId, quantity: 1 }],
63
+ line_items: [
64
+ params.priceId
65
+ ? { price: params.priceId, quantity: 1 }
66
+ : {
67
+ price_data: {
68
+ currency: params.currency || 'eur',
69
+ unit_amount: params.unitAmount!,
70
+ product_data: { name: params.productName! },
71
+ },
72
+ quantity: 1,
73
+ },
74
+ ],
61
75
  customer_email: params.customerEmail || undefined,
62
76
  success_url: params.successUrl,
63
77
  cancel_url: params.cancelUrl,
File without changes
File without changes
@@ -19,6 +19,7 @@ import { createSupabaseHandler } from '../baseFunction.js';
19
19
 
20
20
  const mapper = defaultFieldMapper;
21
21
 
22
+ /** Request payload for aggregate operations (COUNT, SUM, AVG, MIN, MAX) on entities. */
22
23
  export type AggregateEntityRequest = {
23
24
  where?: Array<[string, any, any]>;
24
25
  aggregate: {