@donotdev/functions 0.1.44 → 0.2.1

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 (325) hide show
  1. package/README.md +25 -14
  2. package/lib/chunks/chunk-3F4BWKQD.js +22 -0
  3. package/lib/chunks/chunk-3F4BWKQD.js.map +7 -0
  4. package/lib/chunks/chunk-5IPULSUX.js +22 -0
  5. package/lib/chunks/chunk-5IPULSUX.js.map +7 -0
  6. package/lib/chunks/chunk-6USHTJED.js +22 -0
  7. package/lib/chunks/chunk-6USHTJED.js.map +7 -0
  8. package/lib/chunks/chunk-AYY7UXNI.js +22 -0
  9. package/lib/chunks/chunk-AYY7UXNI.js.map +7 -0
  10. package/lib/chunks/chunk-CXBSROEW.js +23 -0
  11. package/lib/chunks/chunk-CXBSROEW.js.map +7 -0
  12. package/lib/chunks/chunk-GYTCWMXV.js +22 -0
  13. package/lib/chunks/chunk-GYTCWMXV.js.map +7 -0
  14. package/lib/chunks/chunk-HLNYUAZH.js +22 -0
  15. package/lib/chunks/chunk-HLNYUAZH.js.map +7 -0
  16. package/lib/chunks/chunk-LCDLG4VG.js +151 -0
  17. package/lib/chunks/chunk-LCDLG4VG.js.map +7 -0
  18. package/lib/chunks/chunk-MQANUSY3.js +22 -0
  19. package/lib/chunks/chunk-MQANUSY3.js.map +7 -0
  20. package/lib/chunks/chunk-OFQVO3FD.js +22 -0
  21. package/lib/chunks/chunk-OFQVO3FD.js.map +7 -0
  22. package/lib/chunks/chunk-PWAGW4R6.js +22 -0
  23. package/lib/chunks/chunk-PWAGW4R6.js.map +7 -0
  24. package/lib/chunks/chunk-US2VOP4S.js +22 -0
  25. package/lib/chunks/chunk-US2VOP4S.js.map +7 -0
  26. package/lib/chunks/chunk-YTKDNZNW.js +22 -0
  27. package/lib/chunks/chunk-YTKDNZNW.js.map +7 -0
  28. package/lib/chunks/monitoring-E7JBYBHQ.js +22 -0
  29. package/lib/chunks/monitoring-E7JBYBHQ.js.map +7 -0
  30. package/lib/chunks/rateLimiter-SQISLOP5.js +22 -0
  31. package/lib/chunks/rateLimiter-SQISLOP5.js.map +7 -0
  32. package/lib/chunks/server-IQ5JNJOM.js +22 -0
  33. package/lib/chunks/server-IQ5JNJOM.js.map +7 -0
  34. package/lib/firebase/auth/getCustomClaims.d.ts +1 -1
  35. package/lib/firebase/auth/getUserAuthStatus.d.ts +1 -1
  36. package/lib/firebase/auth/index.d.ts +0 -0
  37. package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
  38. package/lib/firebase/auth/setCustomClaims.d.ts +1 -1
  39. package/lib/firebase/baseFunction.d.ts +1 -1
  40. package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
  41. package/lib/firebase/billing/changePlan.d.ts +0 -0
  42. package/lib/firebase/billing/createCheckoutSession.d.ts +2 -2
  43. package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
  44. package/lib/firebase/billing/healthCheck.d.ts +0 -0
  45. package/lib/firebase/billing/index.d.ts +2 -1
  46. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -8
  47. package/lib/firebase/billing/webhookHandler.d.ts +17 -2
  48. package/lib/firebase/config/constants.d.ts +0 -0
  49. package/lib/firebase/config/index.d.ts +0 -0
  50. package/lib/firebase/config/secrets.d.ts +0 -0
  51. package/lib/firebase/crud/aggregate.d.ts +0 -9
  52. package/lib/firebase/crud/bulk.d.ts +2 -2
  53. package/lib/firebase/crud/create.d.ts +1 -1
  54. package/lib/firebase/crud/delete.d.ts +1 -1
  55. package/lib/firebase/crud/get.d.ts +1 -1
  56. package/lib/firebase/crud/index.d.ts +0 -0
  57. package/lib/firebase/crud/list.d.ts +1 -1
  58. package/lib/firebase/crud/update.d.ts +1 -9
  59. package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
  60. package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
  61. package/lib/firebase/helpers/index.d.ts +0 -0
  62. package/lib/firebase/index.d.ts +0 -0
  63. package/lib/firebase/index.js +1 -5
  64. package/lib/firebase/index.js.map +4 -4
  65. package/lib/firebase/oauth/disconnect.d.ts +0 -0
  66. package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
  67. package/lib/firebase/oauth/getConnections.d.ts +0 -0
  68. package/lib/firebase/oauth/githubAccess.d.ts +2 -2
  69. package/lib/firebase/oauth/index.d.ts +0 -0
  70. package/lib/firebase/oauth/refreshToken.d.ts +0 -0
  71. package/lib/firebase/registerCrudFunctions.d.ts +9 -1
  72. package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
  73. package/lib/firebase/scheduled/index.d.ts +0 -0
  74. package/lib/shared/ai/classifyAIError.d.ts +0 -0
  75. package/lib/shared/ai/costTracker.d.ts +0 -0
  76. package/lib/shared/ai/createAIRoute.d.ts +0 -0
  77. package/lib/shared/ai/index.d.ts +0 -0
  78. package/lib/shared/ai/resolveModelTier.d.ts +0 -0
  79. package/lib/shared/billing/apiVersion.d.ts +22 -0
  80. package/lib/shared/billing/checkoutPrice.d.ts +27 -0
  81. package/lib/shared/billing/checkoutValidation.d.ts +89 -0
  82. package/lib/shared/billing/createCheckout.d.ts +73 -24
  83. package/lib/shared/billing/firestoreIdempotency.d.ts +13 -0
  84. package/lib/shared/billing/helpers/index.d.ts +0 -1
  85. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +4 -4
  86. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -29
  87. package/lib/shared/billing/idempotency.d.ts +21 -10
  88. package/lib/shared/billing/idempotencyContract.d.ts +121 -0
  89. package/lib/shared/billing/index.d.ts +2 -0
  90. package/lib/shared/billing/orderWebhook.d.ts +75 -0
  91. package/lib/shared/billing/stripeClient.d.ts +45 -0
  92. package/lib/shared/billing/supabaseIdempotency.d.ts +32 -0
  93. package/lib/shared/billing/tierWebhookEvents.d.ts +54 -0
  94. package/lib/shared/billing/webhookHandler.d.ts +29 -20
  95. package/lib/shared/email/createEmailRoute.d.ts +0 -0
  96. package/lib/shared/email/index.d.ts +0 -0
  97. package/lib/shared/email/provider.d.ts +0 -0
  98. package/lib/shared/email/resendProvider.d.ts +0 -0
  99. package/lib/shared/errorHandling.d.ts +0 -0
  100. package/lib/shared/firebase.d.ts +0 -0
  101. package/lib/shared/github.d.ts +0 -0
  102. package/lib/shared/index.d.ts +0 -0
  103. package/lib/shared/index.js +1 -6
  104. package/lib/shared/index.js.map +4 -4
  105. package/lib/shared/logger.d.ts +0 -0
  106. package/lib/shared/metadata.d.ts +0 -0
  107. package/lib/shared/oauth/exchangeToken.d.ts +0 -0
  108. package/lib/shared/oauth/grantAccess.d.ts +0 -0
  109. package/lib/shared/oauth/index.d.ts +0 -0
  110. package/lib/shared/schema.d.ts +0 -0
  111. package/lib/shared/utils/detectFirestore.d.ts +0 -0
  112. package/lib/shared/utils/external/date.d.ts +0 -0
  113. package/lib/shared/utils/external/index.d.ts +0 -0
  114. package/lib/shared/utils/external/references.d.ts +0 -0
  115. package/lib/shared/utils/external/subscription.d.ts +0 -0
  116. package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
  117. package/lib/shared/utils/functionWrapper.d.ts +1 -1
  118. package/lib/shared/utils/index.d.ts +0 -0
  119. package/lib/shared/utils/internal/auth.d.ts +38 -1
  120. package/lib/shared/utils/internal/firebase.d.ts +0 -0
  121. package/lib/shared/utils/internal/idempotency.d.ts +0 -0
  122. package/lib/shared/utils/internal/index.d.ts +0 -0
  123. package/lib/shared/utils/internal/monitoring.d.ts +0 -0
  124. package/lib/shared/utils/internal/rateLimiter.d.ts +8 -0
  125. package/lib/shared/utils/internal/validation.d.ts +0 -8
  126. package/lib/shared/utils/schemaValidation.d.ts +1 -1
  127. package/lib/shared/utils/validation.d.ts +0 -0
  128. package/lib/shared/utils/vercelHelpers.d.ts +8 -0
  129. package/lib/shared/utils.d.ts +0 -56
  130. package/lib/shared/validation.d.ts +0 -0
  131. package/lib/supabase/ai/createAIFunction.d.ts +0 -0
  132. package/lib/supabase/auth/deleteAccount.d.ts +0 -0
  133. package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
  134. package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
  135. package/lib/supabase/auth/removeCustomClaims.d.ts +0 -0
  136. package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
  137. package/lib/supabase/baseFunction.d.ts +1 -1
  138. package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
  139. package/lib/supabase/billing/changePlan.d.ts +0 -0
  140. package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
  141. package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
  142. package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
  143. package/lib/supabase/billing/stripeWebhook.d.ts +34 -0
  144. package/lib/supabase/crud/aggregate.d.ts +0 -0
  145. package/lib/supabase/crud/bulk.d.ts +1 -1
  146. package/lib/supabase/crud/create.d.ts +0 -0
  147. package/lib/supabase/crud/delete.d.ts +0 -0
  148. package/lib/supabase/crud/entityStore.d.ts +71 -0
  149. package/lib/supabase/crud/get.d.ts +0 -0
  150. package/lib/supabase/crud/index.d.ts +2 -0
  151. package/lib/supabase/crud/list.d.ts +0 -8
  152. package/lib/supabase/crud/update.d.ts +0 -0
  153. package/lib/supabase/edgeFunction.d.ts +0 -0
  154. package/lib/supabase/email/createEmailFunction.d.ts +0 -0
  155. package/lib/supabase/helpers/authProvider.d.ts +5 -5
  156. package/lib/supabase/index.d.ts +11 -2
  157. package/lib/supabase/index.js +1 -3
  158. package/lib/supabase/index.js.map +4 -4
  159. package/lib/supabase/oauth/disconnect.d.ts +0 -0
  160. package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
  161. package/lib/supabase/oauth/getConnections.d.ts +0 -0
  162. package/lib/supabase/oauth/index.d.ts +0 -0
  163. package/lib/supabase/oauth/refreshToken.d.ts +0 -0
  164. package/lib/supabase/registerCrudFunctions.d.ts +0 -0
  165. package/lib/supabase/utils/idempotency.d.ts +0 -0
  166. package/lib/supabase/utils/monitoring.d.ts +0 -0
  167. package/lib/supabase/utils/rateLimiter.d.ts +1 -1
  168. package/lib/vercel/api/ai/chat.d.ts +0 -9
  169. package/lib/vercel/api/ai/index.d.ts +0 -0
  170. package/lib/vercel/api/auth/get-custom-claims.d.ts +8 -0
  171. package/lib/vercel/api/auth/get-user-auth-status.d.ts +8 -0
  172. package/lib/vercel/api/auth/index.d.ts +0 -0
  173. package/lib/vercel/api/auth/remove-custom-claims.d.ts +8 -0
  174. package/lib/vercel/api/auth/set-custom-claims.d.ts +8 -0
  175. package/lib/vercel/api/billing/backend.d.ts +39 -0
  176. package/lib/vercel/api/billing/cancel.d.ts +8 -0
  177. package/lib/vercel/api/billing/change-plan.d.ts +9 -1
  178. package/lib/vercel/api/billing/create-checkout-session.d.ts +25 -6
  179. package/lib/vercel/api/billing/customer-portal.d.ts +8 -0
  180. package/lib/vercel/api/billing/index.d.ts +4 -2
  181. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +19 -3
  182. package/lib/vercel/api/billing/webhook-handler.d.ts +25 -4
  183. package/lib/vercel/api/config/constants.d.ts +0 -0
  184. package/lib/vercel/api/config/firebase-admin.d.ts +8 -0
  185. package/lib/vercel/api/config/index.d.ts +0 -0
  186. package/lib/vercel/api/crud/bulk.d.ts +17 -0
  187. package/lib/vercel/api/crud/create.d.ts +8 -0
  188. package/lib/vercel/api/crud/delete.d.ts +8 -0
  189. package/lib/vercel/api/crud/get.d.ts +8 -0
  190. package/lib/vercel/api/crud/index.d.ts +0 -0
  191. package/lib/vercel/api/crud/list.d.ts +8 -0
  192. package/lib/vercel/api/crud/update.d.ts +8 -0
  193. package/lib/vercel/api/index.d.ts +0 -0
  194. package/lib/vercel/api/index.js +1 -3
  195. package/lib/vercel/api/index.js.map +4 -4
  196. package/lib/vercel/api/oauth/check-github-access.d.ts +8 -0
  197. package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
  198. package/lib/vercel/api/oauth/grant-github-access.d.ts +8 -0
  199. package/lib/vercel/api/oauth/index.d.ts +0 -0
  200. package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
  201. package/lib/vercel/api/utils/cors.d.ts +0 -0
  202. package/lib/vercel/baseFunction.d.ts +4 -1
  203. package/lib/vercel/supabaseAdmin.d.ts +22 -0
  204. package/package.json +25 -26
  205. package/src/firebase/auth/getCustomClaims.ts +4 -5
  206. package/src/firebase/auth/getUserAuthStatus.ts +4 -5
  207. package/src/firebase/auth/removeCustomClaims.ts +4 -5
  208. package/src/firebase/auth/setCustomClaims.ts +4 -5
  209. package/src/firebase/baseFunction.ts +4 -5
  210. package/src/firebase/billing/cancelSubscription.ts +2 -3
  211. package/src/firebase/billing/changePlan.ts +3 -8
  212. package/src/firebase/billing/createCheckoutSession.ts +31 -61
  213. package/src/firebase/billing/createCustomerPortal.ts +5 -6
  214. package/src/firebase/billing/healthCheck.ts +1 -1
  215. package/src/firebase/billing/index.ts +8 -1
  216. package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -4
  217. package/src/firebase/billing/webhookHandler.ts +21 -5
  218. package/src/firebase/crud/__tests__/bulk.test.ts +11 -1
  219. package/src/firebase/crud/aggregate.ts +1 -2
  220. package/src/firebase/crud/bulk.ts +5 -6
  221. package/src/firebase/crud/create.ts +5 -6
  222. package/src/firebase/crud/delete.ts +4 -5
  223. package/src/firebase/crud/get.ts +4 -5
  224. package/src/firebase/crud/list.ts +4 -5
  225. package/src/firebase/crud/update.ts +5 -6
  226. package/src/firebase/oauth/githubAccess.ts +2 -3
  227. package/src/firebase/registerCrudFunctions.ts +2 -2
  228. package/src/shared/__tests__/auth.test.ts +0 -3
  229. package/src/shared/__tests__/bulkCore.test.ts +3 -2
  230. package/src/shared/__tests__/errorHandling.test.ts +2 -2
  231. package/src/shared/__tests__/idempotency.test.ts +282 -55
  232. package/src/shared/__tests__/internalValidation.test.ts +3 -42
  233. package/src/shared/__tests__/logger.test.ts +31 -0
  234. package/src/shared/__tests__/rateLimiter.test.ts +2 -8
  235. package/src/shared/__tests__/schemaValidation.test.ts +1 -1
  236. package/src/shared/__tests__/utils.test.ts +3 -2
  237. package/src/shared/__tests__/validation-env.test.ts +0 -0
  238. package/src/shared/ai/createAIRoute.ts +53 -30
  239. package/src/shared/billing/__tests__/checkoutValidation.test.ts +219 -0
  240. package/src/shared/billing/__tests__/createCheckout.compat.test.ts +349 -0
  241. package/src/shared/billing/__tests__/createCheckout.test.ts +454 -411
  242. package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +92 -0
  243. package/src/shared/billing/__tests__/webhookCorrectness.test.ts +387 -0
  244. package/src/shared/billing/__tests__/webhookHandler.test.ts +370 -23
  245. package/src/shared/billing/apiVersion.ts +25 -0
  246. package/src/shared/billing/checkoutPrice.ts +125 -0
  247. package/src/shared/billing/checkoutValidation.ts +284 -0
  248. package/src/shared/billing/createCheckout.ts +332 -196
  249. package/src/shared/billing/firestoreIdempotency.ts +189 -0
  250. package/src/shared/billing/helpers/index.ts +0 -1
  251. package/src/shared/billing/helpers/subscriptionManagement.ts +8 -10
  252. package/src/shared/billing/helpers/updateUserSubscription.ts +3 -36
  253. package/src/shared/billing/idempotency.ts +104 -168
  254. package/src/shared/billing/idempotencyContract.ts +135 -0
  255. package/src/shared/billing/index.ts +2 -0
  256. package/src/shared/billing/orderWebhook.ts +269 -0
  257. package/src/shared/billing/stripeClient.ts +91 -0
  258. package/src/shared/billing/supabaseIdempotency.ts +228 -0
  259. package/src/shared/billing/tierWebhookEvents.ts +432 -0
  260. package/src/shared/billing/webhookHandler.ts +189 -386
  261. package/src/shared/logger.ts +4 -6
  262. package/src/shared/utils/external/subscription.ts +0 -0
  263. package/src/shared/utils/firebaseHelpers.ts +2 -3
  264. package/src/shared/utils/functionWrapper.ts +1 -2
  265. package/src/shared/utils/internal/auth.ts +55 -7
  266. package/src/shared/utils/internal/monitoring.ts +17 -9
  267. package/src/shared/utils/internal/rateLimiter.ts +14 -5
  268. package/src/shared/utils/internal/validation.ts +0 -18
  269. package/src/shared/utils/schemaValidation.ts +1 -2
  270. package/src/shared/utils/vercelHelpers.ts +3 -3
  271. package/src/shared/utils.ts +5 -99
  272. package/src/shared/validation.ts +1 -1
  273. package/src/supabase/__tests__/bulk.test.ts +3 -1
  274. package/src/supabase/__tests__/entityStore.test.ts +90 -0
  275. package/src/supabase/baseFunction.ts +1 -2
  276. package/src/supabase/billing/cancelSubscription.ts +1 -1
  277. package/src/supabase/billing/changePlan.ts +1 -1
  278. package/src/supabase/billing/createCheckoutSession.ts +11 -41
  279. package/src/supabase/billing/createCustomerPortal.ts +1 -1
  280. package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -7
  281. package/src/supabase/billing/stripeWebhook.ts +79 -0
  282. package/src/supabase/crud/aggregate.ts +1 -1
  283. package/src/supabase/crud/bulk.ts +3 -7
  284. package/src/supabase/crud/create.ts +1 -1
  285. package/src/supabase/crud/entityStore.ts +240 -0
  286. package/src/supabase/crud/index.ts +8 -0
  287. package/src/supabase/crud/list.ts +2 -0
  288. package/src/supabase/crud/update.ts +1 -1
  289. package/src/supabase/helpers/authProvider.ts +6 -5
  290. package/src/supabase/index.ts +26 -0
  291. package/src/supabase/utils/rateLimiter.ts +2 -2
  292. package/src/vercel/__tests__/bulk.test.ts +24 -21
  293. package/src/vercel/__tests__/firebaseOptional.test.ts +64 -0
  294. package/src/vercel/api/ai/chat.ts +2 -1
  295. package/src/vercel/api/auth/get-custom-claims.ts +2 -3
  296. package/src/vercel/api/auth/get-user-auth-status.ts +2 -3
  297. package/src/vercel/api/auth/remove-custom-claims.ts +2 -3
  298. package/src/vercel/api/auth/set-custom-claims.ts +3 -3
  299. package/src/vercel/api/billing/backend.ts +72 -0
  300. package/src/vercel/api/billing/cancel.ts +2 -4
  301. package/src/vercel/api/billing/change-plan.ts +4 -5
  302. package/src/vercel/api/billing/create-checkout-session.ts +43 -73
  303. package/src/vercel/api/billing/customer-portal.ts +3 -5
  304. package/src/vercel/api/billing/index.ts +4 -2
  305. package/src/vercel/api/billing/refresh-subscription-status.ts +22 -7
  306. package/src/vercel/api/billing/webhook-handler.ts +32 -26
  307. package/src/vercel/api/config/firebase-admin.ts +2 -2
  308. package/src/vercel/api/crud/bulk.ts +6 -9
  309. package/src/vercel/api/crud/create.ts +6 -5
  310. package/src/vercel/api/crud/delete.ts +4 -3
  311. package/src/vercel/api/crud/get.ts +6 -5
  312. package/src/vercel/api/crud/list.ts +6 -5
  313. package/src/vercel/api/crud/update.ts +6 -5
  314. package/src/vercel/api/oauth/check-github-access.ts +5 -5
  315. package/src/vercel/api/oauth/exchange-token.ts +3 -3
  316. package/src/vercel/api/oauth/grant-github-access.ts +5 -5
  317. package/src/vercel/api/oauth/revoke-github-access.ts +3 -4
  318. package/src/vercel/baseFunction.ts +23 -8
  319. package/src/vercel/supabaseAdmin.ts +45 -0
  320. package/lib/shared/ai/createAIHandler.d.ts +0 -39
  321. package/lib/shared/ai/providers/anthropic.d.ts +0 -12
  322. package/lib/shared/ai/providers/google.d.ts +0 -10
  323. package/lib/shared/ai/providers/index.d.ts +0 -23
  324. package/lib/shared/ai/providers/openai.d.ts +0 -10
  325. package/lib/shared/ai/utils/parseSSE.d.ts +0 -22
@@ -14,11 +14,8 @@ import type { StripeBackConfig } from '@donotdev/core/server';
14
14
  import type { CreateCheckoutSessionRequest } from '@donotdev/core/server';
15
15
 
16
16
  import { createCheckoutAlgorithm } from '../../shared/billing/createCheckout.js';
17
- import {
18
- initStripe,
19
- stripe,
20
- validateStripeEnvironment,
21
- } from '../../shared/utils.js';
17
+ import type { StripeSessionProvider } from '../../shared/billing/createCheckout.js';
18
+ import { initStripe, stripe, validateStripeEnvironment } from '../../shared/billing/stripeClient.js';
22
19
  import { createSupabaseHandler } from '../baseFunction.js';
23
20
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
24
21
 
@@ -45,48 +42,21 @@ export function createCheckoutSession(billingConfig: StripeBackConfig) {
45
42
 
46
43
  const authProvider = createSupabaseAuthProvider(ctx.supabaseAdmin);
47
44
 
48
- const stripeProvider = {
49
- async createCheckoutSession(params: {
50
- priceId?: string;
51
- unitAmount?: number;
52
- productName?: string;
53
- currency?: string;
54
- customerEmail?: string;
55
- metadata: Record<string, string>;
56
- allowPromotionCodes: boolean;
57
- successUrl: string;
58
- cancelUrl: string;
59
- mode?: 'payment' | 'subscription';
60
- }) {
61
- const session = await stripe.checkout.sessions.create({
62
- mode: params.mode || 'payment',
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
- ],
75
- customer_email: params.customerEmail || undefined,
76
- success_url: params.successUrl,
77
- cancel_url: params.cancelUrl,
78
- allow_promotion_codes: params.allowPromotionCodes,
79
- metadata: params.metadata,
80
- ...(params.mode === 'subscription' && {
81
- subscription_data: { metadata: params.metadata },
82
- }),
83
- });
45
+ const stripeProvider: StripeSessionProvider = {
46
+ async createStripeSession(params) {
47
+ const session = await stripe.checkout.sessions.create(params);
84
48
  return { id: session.id, url: session.url };
85
49
  },
50
+ async retrieveTaxRate(id) {
51
+ const rate = await stripe.taxRates.retrieve(id);
52
+ return { id: rate.id, inclusive: rate.inclusive };
53
+ },
86
54
  };
87
55
 
56
+ // userId comes from the verified JWT, never from the client
88
57
  return createCheckoutAlgorithm(
89
58
  data,
59
+ ctx.uid,
90
60
  stripeProvider,
91
61
  authProvider,
92
62
  billingConfig
@@ -12,7 +12,7 @@
12
12
  import * as v from 'valibot';
13
13
 
14
14
  import { createCustomerPortalSession } from '../../shared/billing/helpers/subscriptionManagement.js';
15
- import { initStripe } from '../../shared/utils.js';
15
+ import { initStripe } from '../../shared/billing/stripeClient.js';
16
16
  import { createSupabaseHandler } from '../baseFunction.js';
17
17
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
18
18
 
@@ -9,18 +9,13 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import type Stripe from 'stripe';
12
13
  import * as v from 'valibot';
13
14
 
14
- import {
15
- initStripe,
16
- stripe,
17
- validateStripeEnvironment,
18
- } from '../../shared/utils.js';
15
+ import { initStripe, stripe, validateStripeEnvironment } from '../../shared/billing/stripeClient.js';
19
16
  import { createSupabaseHandler } from '../baseFunction.js';
20
17
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
21
18
 
22
- import type Stripe from 'stripe';
23
-
24
19
  // =============================================================================
25
20
  // Schema
26
21
  // =============================================================================
@@ -0,0 +1,79 @@
1
+ // packages/functions/src/supabase/billing/stripeWebhook.ts
2
+
3
+ /**
4
+ * @fileoverview Stripe webhook Supabase Edge Function
5
+ * @description Verifies and routes Stripe webhook events through the shared
6
+ * processWebhook (SSOT). Idempotency is stored in Postgres (`webhook_events`).
7
+ *
8
+ * @version 0.2.0
9
+ * @since 0.2.0
10
+ * @author AMBROISE PARK Consulting
11
+ */
12
+
13
+ import type { StripeBackConfig } from '@donotdev/core/server';
14
+
15
+ import { updateUserSubscription } from '../../shared/billing/helpers/updateUserSubscription.js';
16
+ import { createSupabaseIdempotencyStore } from '../../shared/billing/supabaseIdempotency.js';
17
+ import { processWebhook } from '../../shared/billing/webhookHandler.js';
18
+ import { initStripe, stripe } from '../../shared/billing/stripeClient.js';
19
+ import { createEdgeFunction } from '../edgeFunction.js';
20
+ import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
21
+
22
+ declare const Deno:
23
+ | { env: { get(key: string): string | undefined } }
24
+ | undefined;
25
+
26
+ function getEnvOrThrow(key: string): string {
27
+ const value =
28
+ typeof Deno !== 'undefined' ? Deno.env.get(key) : process.env[key];
29
+ if (!value) throw new Error(`Missing ${key} environment variable`);
30
+ return value;
31
+ }
32
+
33
+ /**
34
+ * Create a Supabase Edge Function handler for Stripe webhooks.
35
+ * Requires the `webhook_events` migration (see `WEBHOOK_EVENTS_SQL`).
36
+ * Deploy with JWT verification disabled for this function: Stripe authenticates
37
+ * with its signature, not a Supabase JWT.
38
+ * Any failure answers non-2xx so Stripe retries the event.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // supabase/functions/stripe-webhook/index.ts
43
+ * import { createStripeWebhook } from '@donotdev/functions/supabase';
44
+ * import { billingConfig } from '../_shared/billingConfig.ts';
45
+ *
46
+ * Deno.serve(createStripeWebhook(billingConfig));
47
+ * ```
48
+ *
49
+ * @param billingConfig - App back config
50
+ * @returns `(req: Request) => Promise<Response>` handler
51
+ *
52
+ * @version 0.2.0
53
+ * @since 0.2.0
54
+ * @author AMBROISE PARK Consulting
55
+ */
56
+ export function createStripeWebhook(billingConfig: StripeBackConfig) {
57
+ return createEdgeFunction(
58
+ async (req, ctx) => {
59
+ const signature = req.headers.get('stripe-signature');
60
+ if (!signature) return ctx.error('Missing Stripe signature', 400);
61
+
62
+ initStripe(getEnvOrThrow('STRIPE_SECRET_KEY'));
63
+
64
+ const result = await processWebhook(
65
+ await req.text(),
66
+ signature,
67
+ getEnvOrThrow('STRIPE_WEBHOOK_SECRET'),
68
+ stripe,
69
+ billingConfig,
70
+ updateUserSubscription,
71
+ createSupabaseAuthProvider(ctx.supabaseAdmin),
72
+ createSupabaseIdempotencyStore(ctx.supabaseAdmin)
73
+ );
74
+
75
+ return ctx.json({ received: true, message: result.message });
76
+ },
77
+ { requireAuth: false, extraHeaders: ['stripe-signature'] }
78
+ );
79
+ }
@@ -89,7 +89,7 @@ export function createSupabaseAggregateEntities(
89
89
  const { supabaseAdmin } = ctx;
90
90
 
91
91
  const aggregateColumn = mapper.toBackendField(aggregate.field);
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic aggregate builder; Supabase types change across chained calls
92
+
93
93
  let query: any = supabaseAdmin.from(collection);
94
94
 
95
95
  for (const [field, operator, value] of where) {
@@ -17,7 +17,7 @@
17
17
  * @author AMBROISE PARK Consulting
18
18
  */
19
19
 
20
- import * as v from 'valibot';
20
+ import type * as v from 'valibot';
21
21
 
22
22
  import {
23
23
  BulkCollisionError,
@@ -32,11 +32,8 @@ import type {
32
32
  } from '@donotdev/core/server';
33
33
  import { defaultFieldMapper } from '@donotdev/supabase/server';
34
34
 
35
- import {
36
- createMetadata,
37
- executeBulk,
38
- updateMetadata,
39
- } from '../../shared/index.js';
35
+ import { executeBulk } from '../../shared/crud/bulkCore.js';
36
+ import { createMetadata, updateMetadata } from '../../shared/metadata.js';
40
37
  import { createSupabaseHandler } from '../baseFunction.js';
41
38
 
42
39
  // =============================================================================
@@ -78,7 +75,6 @@ function preparePatch(
78
75
  patch: Record<string, unknown>,
79
76
  uid: string
80
77
  ): Record<string, unknown> {
81
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
82
78
  const {
83
79
  createdAt,
84
80
  updatedAt,
@@ -15,7 +15,7 @@ import { filterVisibleFields } from '@donotdev/core/server';
15
15
  import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
16
16
  import { defaultFieldMapper } from '@donotdev/supabase/server';
17
17
 
18
- import { createMetadata } from '../../shared/index.js';
18
+ import { createMetadata } from '../../shared/metadata.js';
19
19
  import { DoNotDevError, validateDocument } from '../../shared/utils.js';
20
20
  import { createSupabaseHandler } from '../baseFunction.js';
21
21
  import { checkIdempotency, storeIdempotency } from '../utils/idempotency.js';
@@ -0,0 +1,240 @@
1
+ // packages/functions/src/supabase/crud/entityStore.ts
2
+
3
+ /**
4
+ * @fileoverview In-process, entity-aware CRUD for server code (Edge Functions, jobs).
5
+ * @description The HTTP CRUD handlers serve clients. Server code that already holds
6
+ * a Supabase client (usually the service role) reads and writes through this store
7
+ * instead of raw `.from()` queries: entity field names in and out (snake_case
8
+ * columns stay behind the field mapper), unknown fields rejected, and the
9
+ * publication filter applied by default (draft / deleted rows hidden, as the
10
+ * database policy hides them from non-admin users; the service role bypasses that
11
+ * policy, so the store re-applies it on reads).
12
+ *
13
+ * No role or visibility masking: the caller is trusted server code. Atomic
14
+ * multi-table writes stay in SQL functions (`client.rpc`).
15
+ *
16
+ * @version 0.1.0
17
+ * @since 0.5.0
18
+ * @author AMBROISE PARK Consulting
19
+ */
20
+
21
+ import type { SupabaseClient } from '@supabase/supabase-js';
22
+
23
+ import { HIDDEN_STATUSES } from '@donotdev/core/server';
24
+ import type { AnyEntity, InferEntityRow } from '@donotdev/core/server';
25
+ import { createEntityAwareMapper } from '@donotdev/supabase/server';
26
+
27
+ import { DoNotDevError } from '../../shared/utils.js';
28
+
29
+ /** Filter operators, same vocabulary as the list handler and the client CRUD. */
30
+ export type EntityStoreOperator =
31
+ | '=='
32
+ | '!='
33
+ | '>'
34
+ | '>='
35
+ | '<'
36
+ | '<='
37
+ | 'in'
38
+ | 'not-in'
39
+ | 'array-contains'
40
+ | 'array-contains-any';
41
+
42
+ /** `[field, operator, value]`; field is an entity field name. */
43
+ export type EntityStoreCondition = readonly [string, EntityStoreOperator, unknown];
44
+
45
+ /** Read options of {@link EntityStore.list} and {@link EntityStore.find}. */
46
+ export interface EntityStoreQuery {
47
+ where?: readonly EntityStoreCondition[];
48
+ /** Entity fields to read (default: every column). `id` is always read. */
49
+ select?: readonly string[];
50
+ orderBy?: readonly (readonly [string, 'asc' | 'desc'])[];
51
+ limit?: number;
52
+ /** Also return draft / deleted rows (default false). */
53
+ includeHidden?: boolean;
54
+ }
55
+
56
+ /** Values written to a row: any subset of its fields; `null` clears a nullable column. */
57
+ export type EntityStoreValues<Row> = { [K in keyof Row]?: Row[K] | null };
58
+
59
+ /** Entity-aware CRUD bound to one entity and one Supabase client. */
60
+ export interface EntityStore<Row> {
61
+ /** Rows matching the query. */
62
+ list(query?: EntityStoreQuery): Promise<Row[]>;
63
+ /** The single row matching the query, or null; more than one row is an error. */
64
+ find(query: EntityStoreQuery): Promise<Row | null>;
65
+ /** Row by id, or null (hidden rows only with `includeHidden`). */
66
+ get(id: string, options?: Pick<EntityStoreQuery, 'includeHidden' | 'select'>): Promise<Row | null>;
67
+ /** Inserts rows and returns them as stored (database defaults and triggers applied). */
68
+ insert(values: readonly EntityStoreValues<Row>[]): Promise<Row[]>;
69
+ /** Updates the rows matching `where` (hidden rows included) and returns them as stored. */
70
+ update(where: readonly EntityStoreCondition[], patch: EntityStoreValues<Row>): Promise<Row[]>;
71
+ }
72
+
73
+ const SAFE_FIELD_NAME = /^[a-zA-Z][a-zA-Z0-9_]*$/;
74
+
75
+ /** The PostgREST filter builder methods the store uses. */
76
+ interface Filterable {
77
+ eq(column: string, value: unknown): this;
78
+ neq(column: string, value: unknown): this;
79
+ gt(column: string, value: unknown): this;
80
+ gte(column: string, value: unknown): this;
81
+ lt(column: string, value: unknown): this;
82
+ lte(column: string, value: unknown): this;
83
+ in(column: string, values: readonly unknown[]): this;
84
+ not(column: string, operator: string, value: unknown): this;
85
+ contains(column: string, value: unknown): this;
86
+ overlaps(column: string, value: unknown): this;
87
+ }
88
+
89
+ /** Result of an awaited PostgREST query. */
90
+ interface QueryResult {
91
+ data: unknown;
92
+ error: { message: string } | null;
93
+ }
94
+
95
+ /**
96
+ * Untyped view of the PostgREST builder: the table name is only known at runtime,
97
+ * and the generic builder types instantiate too deeply for a dynamic table.
98
+ */
99
+ interface Query extends Filterable, PromiseLike<QueryResult> {
100
+ select(columns: string): Query;
101
+ order(column: string, options: { ascending: boolean }): Query;
102
+ limit(count: number): Query;
103
+ }
104
+
105
+ interface Table {
106
+ select(columns: string): Query;
107
+ insert(rows: Record<string, unknown>[]): Query;
108
+ update(values: Record<string, unknown>): Query;
109
+ }
110
+
111
+ /** PostgREST list literal for `not.in`: ("a","b"). */
112
+ function postgrestList(values: readonly unknown[]): string {
113
+ return `(${values.map((v) => JSON.stringify(String(v))).join(',')})`;
114
+ }
115
+
116
+ function applyCondition<Q extends Filterable>(query: Q, column: string, operator: EntityStoreOperator, value: unknown): Q {
117
+ const list = Array.isArray(value) ? value : [value];
118
+ switch (operator) {
119
+ case '==':
120
+ return query.eq(column, value);
121
+ case '!=':
122
+ return query.neq(column, value);
123
+ case '>':
124
+ return query.gt(column, value);
125
+ case '>=':
126
+ return query.gte(column, value);
127
+ case '<':
128
+ return query.lt(column, value);
129
+ case '<=':
130
+ return query.lte(column, value);
131
+ case 'in':
132
+ return query.in(column, list);
133
+ case 'not-in':
134
+ return query.not(column, 'in', postgrestList(list));
135
+ case 'array-contains':
136
+ return query.contains(column, [value]);
137
+ case 'array-contains-any':
138
+ // Postgres array columns only: PostgREST has no overlap operator for jsonb.
139
+ return query.overlaps(column, list);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Creates an entity-aware CRUD store for server code.
145
+ *
146
+ * @param client - Supabase client the store runs with (service role in Edge Functions)
147
+ * @param entity - Entity from `defineEntity()`; its collection is the table
148
+ * @returns Store whose rows use the entity field names
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * import { createEntityStore } from '@donotdev/functions/supabase';
153
+ * import { productEntity } from 'entities';
154
+ *
155
+ * const products = createEntityStore(supabaseAdmin, productEntity);
156
+ * // Published products only (draft / deleted hidden by default)
157
+ * const rows = await products.list({ where: [['id', 'in', ids]], select: ['name', 'sku'] });
158
+ * ```
159
+ *
160
+ * @version 0.1.0
161
+ * @since 0.5.0
162
+ */
163
+ export function createEntityStore<E extends AnyEntity>(client: SupabaseClient, entity: E): EntityStore<InferEntityRow<E>> {
164
+ type Row = InferEntityRow<E>;
165
+ const fieldNames = Object.keys(entity.fields);
166
+ const known = new Set(fieldNames);
167
+ const mapper = createEntityAwareMapper(fieldNames);
168
+ const table = entity.collection;
169
+ const hasStatus = known.has('status');
170
+ const from = (): Table => client.from(table) as unknown as Table;
171
+
172
+ const column = (field: string): string => {
173
+ if (!known.has(field) || !SAFE_FIELD_NAME.test(field)) {
174
+ throw new DoNotDevError(`${entity.name}: unknown field '${field}'`, 'invalid-argument');
175
+ }
176
+ return mapper.toBackendField(field);
177
+ };
178
+
179
+ const toColumns = (values: Record<string, unknown>): Record<string, unknown> => {
180
+ const out: Record<string, unknown> = {};
181
+ for (const [field, value] of Object.entries(values)) {
182
+ if (value === undefined) continue;
183
+ out[column(field)] = value;
184
+ }
185
+ return out;
186
+ };
187
+
188
+ const fromRows = (data: unknown): Row[] => ((data ?? []) as Record<string, unknown>[]).map((row) => mapper.fromBackendRow(row) as Row);
189
+
190
+ const fail = (operation: string, error: { message: string }): never => {
191
+ throw new DoNotDevError(`${operation} ${table}: ${error.message}`, 'internal');
192
+ };
193
+
194
+ const selectList = (select: readonly string[] | undefined): string =>
195
+ select && select.length > 0 ? [...new Set(['id', ...select])].map(column).join(', ') : '*';
196
+
197
+ const filtered = (query: Query, where: readonly EntityStoreCondition[], includeHidden: boolean | undefined): Query => {
198
+ let q = query;
199
+ for (const [field, operator, value] of where) q = applyCondition(q, column(field), operator, value);
200
+ if (hasStatus && !includeHidden) q = q.not('status', 'in', postgrestList(HIDDEN_STATUSES));
201
+ return q;
202
+ };
203
+
204
+ const list = async (query: EntityStoreQuery = {}): Promise<Row[]> => {
205
+ let q = filtered(from().select(selectList(query.select)), query.where ?? [], query.includeHidden);
206
+ for (const [field, direction] of query.orderBy ?? []) q = q.order(column(field), { ascending: direction === 'asc' });
207
+ if (query.limit !== undefined) q = q.limit(query.limit);
208
+ const { data, error } = await q;
209
+ if (error) fail('list', error);
210
+ return fromRows(data);
211
+ };
212
+
213
+ const find = async (query: EntityStoreQuery): Promise<Row | null> => {
214
+ const rows = await list({ ...query, limit: 2 });
215
+ if (rows.length > 1) throw new DoNotDevError(`${entity.name}: more than one row matches`, 'internal');
216
+ return rows[0] ?? null;
217
+ };
218
+
219
+ return {
220
+ list,
221
+ find,
222
+ get: (id, options) => find({ ...options, where: [['id', '==', id]] }),
223
+
224
+ async insert(values) {
225
+ if (values.length === 0) return [];
226
+ const { data, error } = await from()
227
+ .insert(values.map((v) => toColumns(v as Record<string, unknown>)))
228
+ .select('*');
229
+ if (error) fail('insert', error);
230
+ return fromRows(data);
231
+ },
232
+
233
+ async update(where, patch) {
234
+ if (where.length === 0) throw new DoNotDevError(`${entity.name}: update without a condition`, 'invalid-argument');
235
+ const { data, error } = await filtered(from().update(toColumns(patch as Record<string, unknown>)), where, true).select('*');
236
+ if (error) fail('update', error);
237
+ return fromRows(data);
238
+ },
239
+ };
240
+ }
@@ -16,6 +16,7 @@ export { createSupabaseDeleteEntity } from './delete.js';
16
16
  export { createSupabaseListEntities } from './list.js';
17
17
  export { createSupabaseAggregateEntities } from './aggregate.js';
18
18
  export { createSupabaseBulkEntity } from './bulk.js';
19
+ export { createEntityStore } from './entityStore.js';
19
20
 
20
21
  export type { GetEntityRequest } from './get.js';
21
22
  export type { CreateEntityRequest } from './create.js';
@@ -24,3 +25,10 @@ export type { DeleteEntityRequest, ReferenceMetadata } from './delete.js';
24
25
  export type { ListEntityRequest } from './list.js';
25
26
  export type { AggregateEntityRequest } from './aggregate.js';
26
27
  export type { BulkEntityRequest } from './bulk.js';
28
+ export type {
29
+ EntityStore,
30
+ EntityStoreCondition,
31
+ EntityStoreOperator,
32
+ EntityStoreQuery,
33
+ EntityStoreValues,
34
+ } from './entityStore.js';
@@ -9,6 +9,8 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import { Buffer } from 'node:buffer';
13
+
12
14
  import * as v from 'valibot';
13
15
 
14
16
  import {
@@ -14,7 +14,7 @@ import * as v from 'valibot';
14
14
  import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
15
15
  import { defaultFieldMapper } from '@donotdev/supabase/server';
16
16
 
17
- import { updateMetadata } from '../../shared/index.js';
17
+ import { updateMetadata } from '../../shared/metadata.js';
18
18
  import { DoNotDevError, validateDocument } from '../../shared/utils.js';
19
19
  import { createSupabaseHandler } from '../baseFunction.js';
20
20
  import { checkIdempotency, storeIdempotency } from '../utils/idempotency.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * @fileoverview Supabase Auth Provider for shared billing logic
5
- * @description Maps Supabase Admin auth to the shared `AuthProvider` interface,
5
+ * @description Maps Supabase Admin auth to the core `BillingAuthProvider` interface,
6
6
  * bridging `app_metadata` ↔ `customClaims`.
7
7
  *
8
8
  * @version 0.1.0
@@ -10,26 +10,27 @@
10
10
  * @author AMBROISE PARK Consulting
11
11
  */
12
12
 
13
- import type { AuthProvider } from '../../shared/billing/helpers/updateUserSubscription.js';
14
13
  import type { SupabaseClient } from '@supabase/supabase-js';
15
14
 
15
+ import type { BillingAuthProvider } from '@donotdev/core/server';
16
+
16
17
  // =============================================================================
17
18
  // Factory
18
19
  // =============================================================================
19
20
 
20
21
  /**
21
- * Create an AuthProvider backed by Supabase Admin.
22
+ * Create a BillingAuthProvider backed by Supabase Admin.
22
23
  * `app_metadata` is used as the equivalent of Firebase custom claims.
23
24
  *
24
25
  * @param supabaseAdmin - Supabase client created with the service role key
25
- * @returns AuthProvider compatible with shared billing helpers
26
+ * @returns BillingAuthProvider compatible with shared billing helpers
26
27
  *
27
28
  * @version 0.1.0
28
29
  * @since 0.5.0
29
30
  */
30
31
  export function createSupabaseAuthProvider(
31
32
  supabaseAdmin: SupabaseClient
32
- ): AuthProvider {
33
+ ): BillingAuthProvider {
33
34
  return {
34
35
  async getUser(userId: string) {
35
36
  const { data, error } =
@@ -31,6 +31,20 @@ export { createGetUserAuthStatus } from './auth/getUserAuthStatus.js';
31
31
 
32
32
  // Billing
33
33
  export { createCheckoutSession } from './billing/createCheckoutSession.js';
34
+ export { createStripeWebhook } from './billing/stripeWebhook.js';
35
+ export {
36
+ createSupabaseIdempotencyStore,
37
+ WEBHOOK_EVENTS_SQL,
38
+ } from '../shared/billing/supabaseIdempotency.js';
39
+ export { ReservationLostError } from '../shared/billing/idempotencyContract.js';
40
+ export type {
41
+ IdempotencyStore,
42
+ ReservationResult,
43
+ } from '../shared/billing/idempotencyContract.js';
44
+ // Custom StripeOrder entry points (app request shape, own StripeSessionProvider)
45
+ export { createCheckoutAlgorithm } from '../shared/billing/createCheckout.js';
46
+ export type { StripeSessionProvider } from '../shared/billing/createCheckout.js';
47
+ export { STRIPE_API_VERSION_PIN } from '../shared/billing/apiVersion.js';
34
48
  export { createCancelSubscription } from './billing/cancelSubscription.js';
35
49
  export { createChangePlan } from './billing/changePlan.js';
36
50
  export { createCustomerPortal } from './billing/createCustomerPortal.js';
@@ -58,6 +72,12 @@ export type {
58
72
 
59
73
  // Email
60
74
  export { createEmailFunction } from './email/createEmailFunction.js';
75
+ // Server-side sending from app functions (webhooks, jobs): same templates and provider
76
+ export {
77
+ handleEmailRequest,
78
+ createResendProvider,
79
+ } from '../shared/email/index.js';
80
+ export type { EmailProviderAdapter } from '../shared/email/index.js';
61
81
 
62
82
  // CRUD
63
83
  export {
@@ -67,6 +87,7 @@ export {
67
87
  createSupabaseDeleteEntity,
68
88
  createSupabaseListEntities,
69
89
  createSupabaseAggregateEntities,
90
+ createEntityStore,
70
91
  } from './crud/index.js';
71
92
  export { createSupabaseCrudFunctions } from './registerCrudFunctions.js';
72
93
  export type {
@@ -77,6 +98,11 @@ export type {
77
98
  ListEntityRequest,
78
99
  AggregateEntityRequest,
79
100
  ReferenceMetadata,
101
+ EntityStore,
102
+ EntityStoreCondition,
103
+ EntityStoreOperator,
104
+ EntityStoreQuery,
105
+ EntityStoreValues,
80
106
  } from './crud/index.js';
81
107
 
82
108
  // Utils
@@ -23,13 +23,13 @@
23
23
  * @author AMBROISE PARK Consulting
24
24
  */
25
25
 
26
+ import type { SupabaseClient } from '@supabase/supabase-js';
27
+
26
28
  import type {
27
29
  ServerRateLimitConfig as RateLimitConfig,
28
30
  ServerRateLimitResult as RateLimitResult,
29
31
  } from '@donotdev/core';
30
32
 
31
- import type { SupabaseClient } from '@supabase/supabase-js';
32
-
33
33
  export type { RateLimitConfig, RateLimitResult };
34
34
 
35
35
  /**