@donotdev/functions 0.2.0 → 0.2.2

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 (313) hide show
  1. package/README.md +1 -1
  2. package/lib/chunks/{chunk-JTAGPPPL.js → chunk-2A4FPYNB.js} +2 -2
  3. package/lib/chunks/chunk-2IFFIUFV.js +23 -0
  4. package/lib/chunks/{chunk-RM7DV6IQ.js.map → chunk-2IFFIUFV.js.map} +3 -3
  5. package/lib/chunks/chunk-FQSQGOBN.js +22 -0
  6. package/lib/chunks/chunk-FQSQGOBN.js.map +7 -0
  7. package/lib/chunks/chunk-G4FO76EA.js +22 -0
  8. package/lib/chunks/{chunk-5DTPEM64.js.map → chunk-G4FO76EA.js.map} +3 -3
  9. package/lib/chunks/{chunk-QJAU2MWV.js → chunk-LSM5Y2E5.js} +2 -2
  10. package/lib/chunks/{chunk-QJAU2MWV.js.map → chunk-LSM5Y2E5.js.map} +3 -3
  11. package/lib/chunks/{chunk-4U7QQWYG.js → chunk-M4JV2JCF.js} +2 -2
  12. package/lib/chunks/chunk-OZX5ZG44.js +22 -0
  13. package/lib/chunks/chunk-OZX5ZG44.js.map +7 -0
  14. package/lib/chunks/{chunk-IFOYVSPU.js → chunk-PJCJ5H2O.js} +2 -2
  15. package/lib/chunks/chunk-PWAGW4R6.js +22 -0
  16. package/lib/chunks/chunk-PWAGW4R6.js.map +7 -0
  17. package/lib/chunks/chunk-UYI56E6Q.js +151 -0
  18. package/lib/chunks/chunk-UYI56E6Q.js.map +7 -0
  19. package/lib/chunks/chunk-ZVHC2CAV.js +22 -0
  20. package/lib/chunks/chunk-ZVHC2CAV.js.map +7 -0
  21. package/lib/chunks/{monitoring-AGCSU3FI.js → monitoring-UIDJS2KA.js} +2 -2
  22. package/lib/chunks/{rateLimiter-6KO7AIZP.js → rateLimiter-WNWHI3B4.js} +2 -2
  23. package/lib/chunks/server-RYGEBS2B.js +22 -0
  24. package/lib/firebase/auth/getCustomClaims.d.ts +0 -0
  25. package/lib/firebase/auth/getUserAuthStatus.d.ts +0 -0
  26. package/lib/firebase/auth/index.d.ts +0 -0
  27. package/lib/firebase/auth/removeCustomClaims.d.ts +0 -0
  28. package/lib/firebase/auth/setCustomClaims.d.ts +0 -0
  29. package/lib/firebase/baseFunction.d.ts +0 -0
  30. package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
  31. package/lib/firebase/billing/changePlan.d.ts +0 -0
  32. package/lib/firebase/billing/createCheckoutSession.d.ts +0 -0
  33. package/lib/firebase/billing/createCustomerPortal.d.ts +0 -0
  34. package/lib/firebase/billing/healthCheck.d.ts +0 -0
  35. package/lib/firebase/billing/index.d.ts +2 -2
  36. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -0
  37. package/lib/firebase/billing/webhookHandler.d.ts +0 -0
  38. package/lib/firebase/config/constants.d.ts +0 -0
  39. package/lib/firebase/config/index.d.ts +0 -0
  40. package/lib/firebase/config/secrets.d.ts +0 -0
  41. package/lib/firebase/crud/aggregate.d.ts +0 -0
  42. package/lib/firebase/crud/create.d.ts +0 -0
  43. package/lib/firebase/crud/delete.d.ts +0 -0
  44. package/lib/firebase/crud/get.d.ts +0 -0
  45. package/lib/firebase/crud/index.d.ts +0 -0
  46. package/lib/firebase/crud/list.d.ts +0 -0
  47. package/lib/firebase/crud/update.d.ts +0 -0
  48. package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
  49. package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
  50. package/lib/firebase/helpers/index.d.ts +0 -0
  51. package/lib/firebase/index.d.ts +1 -1
  52. package/lib/firebase/index.js +1 -1
  53. package/lib/firebase/index.js.map +4 -4
  54. package/lib/firebase/oauth/disconnect.d.ts +0 -0
  55. package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
  56. package/lib/firebase/oauth/getConnections.d.ts +0 -0
  57. package/lib/firebase/oauth/githubAccess.d.ts +0 -0
  58. package/lib/firebase/oauth/index.d.ts +0 -0
  59. package/lib/firebase/oauth/refreshToken.d.ts +0 -0
  60. package/lib/firebase/registerCrudFunctions.d.ts +0 -5
  61. package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
  62. package/lib/firebase/scheduled/index.d.ts +0 -0
  63. package/lib/shared/ai/classifyAIError.d.ts +0 -0
  64. package/lib/shared/ai/costTracker.d.ts +0 -0
  65. package/lib/shared/ai/createAIRoute.d.ts +0 -0
  66. package/lib/shared/ai/index.d.ts +0 -0
  67. package/lib/shared/ai/resolveModelTier.d.ts +0 -0
  68. package/lib/shared/billing/checkoutPrice.d.ts +3 -6
  69. package/lib/shared/billing/createCheckout.d.ts +3 -3
  70. package/lib/shared/billing/firestoreIdempotency.d.ts +13 -0
  71. package/lib/shared/billing/helpers/index.d.ts +0 -0
  72. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +0 -0
  73. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +0 -0
  74. package/lib/shared/billing/idempotency.d.ts +4 -35
  75. package/lib/shared/billing/idempotencyContract.d.ts +0 -20
  76. package/lib/shared/billing/index.d.ts +0 -0
  77. package/lib/shared/billing/stripeClient.d.ts +45 -0
  78. package/lib/shared/billing/webhookHandler.d.ts +5 -4
  79. package/lib/shared/email/createEmailRoute.d.ts +0 -0
  80. package/lib/shared/email/index.d.ts +0 -0
  81. package/lib/shared/email/provider.d.ts +0 -0
  82. package/lib/shared/email/resendProvider.d.ts +0 -0
  83. package/lib/shared/errorHandling.d.ts +0 -0
  84. package/lib/shared/firebase.d.ts +0 -0
  85. package/lib/shared/github.d.ts +0 -0
  86. package/lib/shared/index.d.ts +0 -0
  87. package/lib/shared/index.js +1 -1
  88. package/lib/shared/index.js.map +0 -0
  89. package/lib/shared/logger.d.ts +0 -0
  90. package/lib/shared/metadata.d.ts +0 -0
  91. package/lib/shared/oauth/exchangeToken.d.ts +0 -0
  92. package/lib/shared/oauth/grantAccess.d.ts +0 -0
  93. package/lib/shared/oauth/index.d.ts +0 -0
  94. package/lib/shared/schema.d.ts +0 -0
  95. package/lib/shared/utils/detectFirestore.d.ts +0 -0
  96. package/lib/shared/utils/external/date.d.ts +0 -0
  97. package/lib/shared/utils/external/index.d.ts +0 -0
  98. package/lib/shared/utils/external/references.d.ts +0 -0
  99. package/lib/shared/utils/external/subscription.d.ts +0 -0
  100. package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
  101. package/lib/shared/utils/functionWrapper.d.ts +0 -0
  102. package/lib/shared/utils/index.d.ts +0 -0
  103. package/lib/shared/utils/internal/auth.d.ts +1 -5
  104. package/lib/shared/utils/internal/firebase.d.ts +0 -0
  105. package/lib/shared/utils/internal/idempotency.d.ts +0 -0
  106. package/lib/shared/utils/internal/index.d.ts +0 -0
  107. package/lib/shared/utils/internal/monitoring.d.ts +0 -0
  108. package/lib/shared/utils/internal/rateLimiter.d.ts +0 -0
  109. package/lib/shared/utils/internal/validation.d.ts +0 -8
  110. package/lib/shared/utils/schemaValidation.d.ts +0 -0
  111. package/lib/shared/utils/validation.d.ts +0 -0
  112. package/lib/shared/utils/vercelHelpers.d.ts +0 -0
  113. package/lib/shared/utils.d.ts +0 -126
  114. package/lib/shared/validation.d.ts +0 -0
  115. package/lib/supabase/ai/createAIFunction.d.ts +0 -0
  116. package/lib/supabase/auth/deleteAccount.d.ts +0 -0
  117. package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
  118. package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
  119. package/lib/supabase/auth/removeCustomClaims.d.ts +0 -0
  120. package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
  121. package/lib/supabase/baseFunction.d.ts +0 -0
  122. package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
  123. package/lib/supabase/billing/changePlan.d.ts +0 -0
  124. package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
  125. package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
  126. package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
  127. package/lib/supabase/crud/aggregate.d.ts +0 -0
  128. package/lib/supabase/crud/create.d.ts +0 -0
  129. package/lib/supabase/crud/delete.d.ts +0 -0
  130. package/lib/supabase/crud/get.d.ts +0 -0
  131. package/lib/supabase/crud/index.d.ts +0 -0
  132. package/lib/supabase/crud/list.d.ts +0 -8
  133. package/lib/supabase/crud/update.d.ts +0 -0
  134. package/lib/supabase/edgeFunction.d.ts +0 -0
  135. package/lib/supabase/email/createEmailFunction.d.ts +0 -0
  136. package/lib/supabase/helpers/authProvider.d.ts +0 -0
  137. package/lib/supabase/index.d.ts +3 -2
  138. package/lib/supabase/index.js +1 -1
  139. package/lib/supabase/index.js.map +3 -3
  140. package/lib/supabase/oauth/disconnect.d.ts +0 -0
  141. package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
  142. package/lib/supabase/oauth/getConnections.d.ts +0 -0
  143. package/lib/supabase/oauth/index.d.ts +0 -0
  144. package/lib/supabase/oauth/refreshToken.d.ts +0 -0
  145. package/lib/supabase/registerCrudFunctions.d.ts +0 -0
  146. package/lib/supabase/utils/idempotency.d.ts +0 -0
  147. package/lib/supabase/utils/monitoring.d.ts +0 -0
  148. package/lib/supabase/utils/rateLimiter.d.ts +0 -0
  149. package/lib/vercel/api/ai/chat.d.ts +0 -0
  150. package/lib/vercel/api/ai/index.d.ts +0 -0
  151. package/lib/vercel/api/auth/get-custom-claims.d.ts +0 -0
  152. package/lib/vercel/api/auth/get-user-auth-status.d.ts +0 -0
  153. package/lib/vercel/api/auth/index.d.ts +0 -0
  154. package/lib/vercel/api/auth/remove-custom-claims.d.ts +0 -0
  155. package/lib/vercel/api/auth/set-custom-claims.d.ts +0 -0
  156. package/lib/vercel/api/billing/cancel.d.ts +0 -0
  157. package/lib/vercel/api/billing/change-plan.d.ts +0 -0
  158. package/lib/vercel/api/billing/create-checkout-session.d.ts +0 -0
  159. package/lib/vercel/api/billing/customer-portal.d.ts +0 -0
  160. package/lib/vercel/api/billing/index.d.ts +0 -0
  161. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +0 -0
  162. package/lib/vercel/api/billing/webhook-handler.d.ts +0 -0
  163. package/lib/vercel/api/config/constants.d.ts +0 -0
  164. package/lib/vercel/api/config/firebase-admin.d.ts +0 -0
  165. package/lib/vercel/api/config/index.d.ts +0 -0
  166. package/lib/vercel/api/crud/create.d.ts +0 -0
  167. package/lib/vercel/api/crud/delete.d.ts +0 -0
  168. package/lib/vercel/api/crud/get.d.ts +0 -0
  169. package/lib/vercel/api/crud/index.d.ts +0 -0
  170. package/lib/vercel/api/crud/list.d.ts +0 -0
  171. package/lib/vercel/api/crud/update.d.ts +0 -0
  172. package/lib/vercel/api/index.d.ts +0 -0
  173. package/lib/vercel/api/index.js +1 -1
  174. package/lib/vercel/api/index.js.map +2 -2
  175. package/lib/vercel/api/oauth/check-github-access.d.ts +0 -0
  176. package/lib/vercel/api/oauth/exchange-token.d.ts +0 -0
  177. package/lib/vercel/api/oauth/grant-github-access.d.ts +0 -0
  178. package/lib/vercel/api/oauth/index.d.ts +0 -0
  179. package/lib/vercel/api/oauth/revoke-github-access.d.ts +0 -0
  180. package/lib/vercel/api/utils/cors.d.ts +0 -0
  181. package/lib/vercel/baseFunction.d.ts +0 -0
  182. package/package.json +2 -2
  183. package/src/firebase/baseFunction.ts +3 -2
  184. package/src/firebase/billing/cancelSubscription.ts +1 -1
  185. package/src/firebase/billing/changePlan.ts +1 -5
  186. package/src/firebase/billing/createCheckoutSession.ts +1 -5
  187. package/src/firebase/billing/createCustomerPortal.ts +1 -1
  188. package/src/firebase/billing/healthCheck.ts +1 -1
  189. package/src/firebase/billing/index.d.ts +0 -12
  190. package/src/firebase/billing/index.ts +0 -3
  191. package/src/firebase/billing/refreshSubscriptionStatus.ts +1 -1
  192. package/src/firebase/billing/webhookHandler.ts +2 -2
  193. package/src/firebase/index.ts +0 -1
  194. package/src/firebase/oauth/disconnect.ts +2 -2
  195. package/src/firebase/oauth/exchangeToken.ts +2 -2
  196. package/src/firebase/oauth/getConnections.ts +2 -2
  197. package/src/firebase/oauth/githubAccess.ts +4 -4
  198. package/src/firebase/oauth/refreshToken.ts +2 -2
  199. package/src/firebase/registerCrudFunctions.ts +0 -19
  200. package/src/shared/__tests__/idempotency.test.ts +0 -32
  201. package/src/shared/__tests__/internalValidation.test.ts +1 -40
  202. package/src/shared/__tests__/logger.test.ts +31 -0
  203. package/src/shared/__tests__/utils.test.ts +1 -26
  204. package/src/shared/billing/__tests__/createCheckout.compat.test.ts +4 -110
  205. package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -38
  206. package/src/shared/billing/checkoutPrice.ts +7 -42
  207. package/src/shared/billing/createCheckout.ts +3 -19
  208. package/src/shared/billing/firestoreIdempotency.ts +170 -0
  209. package/src/shared/billing/helpers/subscriptionManagement.ts +1 -1
  210. package/src/shared/billing/idempotency.ts +8 -225
  211. package/src/shared/billing/idempotencyContract.ts +0 -21
  212. package/src/shared/billing/stripeClient.ts +91 -0
  213. package/src/shared/billing/webhookHandler.ts +5 -5
  214. package/src/shared/logger.ts +4 -6
  215. package/src/shared/utils/internal/auth.ts +1 -6
  216. package/src/shared/utils/internal/validation.ts +0 -18
  217. package/src/shared/utils.ts +0 -208
  218. package/src/supabase/billing/cancelSubscription.ts +1 -1
  219. package/src/supabase/billing/changePlan.ts +1 -1
  220. package/src/supabase/billing/createCheckoutSession.ts +1 -5
  221. package/src/supabase/billing/createCustomerPortal.ts +1 -1
  222. package/src/supabase/billing/refreshSubscriptionStatus.ts +1 -5
  223. package/src/supabase/billing/stripeWebhook.ts +2 -2
  224. package/src/supabase/crud/list.ts +2 -0
  225. package/src/supabase/index.ts +3 -3
  226. package/src/vercel/api/billing/change-plan.ts +1 -1
  227. package/src/vercel/api/billing/create-checkout-session.ts +1 -5
  228. package/src/vercel/api/billing/customer-portal.ts +1 -1
  229. package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
  230. package/src/vercel/api/billing/webhook-handler.ts +1 -1
  231. package/lib/chunks/chunk-2JL3GDTO.js +0 -151
  232. package/lib/chunks/chunk-2JL3GDTO.js.map +0 -7
  233. package/lib/chunks/chunk-4TVLH2W2.js +0 -22
  234. package/lib/chunks/chunk-5DTPEM64.js +0 -22
  235. package/lib/chunks/chunk-6CQXHNVL.js +0 -22
  236. package/lib/chunks/chunk-6CQXHNVL.js.map +0 -7
  237. package/lib/chunks/chunk-6DSCPZC6.js +0 -22
  238. package/lib/chunks/chunk-6DSCPZC6.js.map +0 -7
  239. package/lib/chunks/chunk-7E6TGWHU.js +0 -22
  240. package/lib/chunks/chunk-7E6TGWHU.js.map +0 -7
  241. package/lib/chunks/chunk-7LT32OWE.js +0 -22
  242. package/lib/chunks/chunk-7VH2GJXT.js +0 -151
  243. package/lib/chunks/chunk-7VH2GJXT.js.map +0 -7
  244. package/lib/chunks/chunk-API5A4BV.js +0 -22
  245. package/lib/chunks/chunk-API5A4BV.js.map +0 -7
  246. package/lib/chunks/chunk-BUP7SXPV.js +0 -23
  247. package/lib/chunks/chunk-BUP7SXPV.js.map +0 -7
  248. package/lib/chunks/chunk-BXKRI3JJ.js +0 -22
  249. package/lib/chunks/chunk-BXKRI3JJ.js.map +0 -7
  250. package/lib/chunks/chunk-FSLGZD7A.js +0 -21
  251. package/lib/chunks/chunk-GVLSPWDD.js +0 -151
  252. package/lib/chunks/chunk-GVLSPWDD.js.map +0 -7
  253. package/lib/chunks/chunk-GXQVWEFT.js +0 -22
  254. package/lib/chunks/chunk-GXQVWEFT.js.map +0 -7
  255. package/lib/chunks/chunk-HB7EGXVI.js +0 -22
  256. package/lib/chunks/chunk-HB7EGXVI.js.map +0 -7
  257. package/lib/chunks/chunk-HM7XCMWW.js +0 -22
  258. package/lib/chunks/chunk-HM7XCMWW.js.map +0 -7
  259. package/lib/chunks/chunk-I7IOIL6U.js +0 -151
  260. package/lib/chunks/chunk-I7IOIL6U.js.map +0 -7
  261. package/lib/chunks/chunk-IFOYVSPU.js.map +0 -7
  262. package/lib/chunks/chunk-JTAGPPPL.js.map +0 -7
  263. package/lib/chunks/chunk-MZ232FUE.js +0 -22
  264. package/lib/chunks/chunk-MZ232FUE.js.map +0 -7
  265. package/lib/chunks/chunk-NE5ZTUUZ.js +0 -22
  266. package/lib/chunks/chunk-NE5ZTUUZ.js.map +0 -7
  267. package/lib/chunks/chunk-NP2AN2TV.js +0 -22
  268. package/lib/chunks/chunk-NP2AN2TV.js.map +0 -7
  269. package/lib/chunks/chunk-RM7DV6IQ.js +0 -23
  270. package/lib/chunks/chunk-RQZGIZHD.js +0 -151
  271. package/lib/chunks/chunk-RQZGIZHD.js.map +0 -7
  272. package/lib/chunks/chunk-TBEDQLOB.js +0 -23
  273. package/lib/chunks/chunk-TBEDQLOB.js.map +0 -7
  274. package/lib/chunks/chunk-TMHBP3HB.js +0 -22
  275. package/lib/chunks/chunk-TMHBP3HB.js.map +0 -7
  276. package/lib/chunks/chunk-UH4L3EF3.js +0 -151
  277. package/lib/chunks/chunk-UH4L3EF3.js.map +0 -7
  278. package/lib/chunks/chunk-UJBIU6TL.js +0 -22
  279. package/lib/chunks/chunk-UJBIU6TL.js.map +0 -7
  280. package/lib/chunks/chunk-VKEYW3NT.js +0 -22
  281. package/lib/chunks/chunk-VKEYW3NT.js.map +0 -7
  282. package/lib/chunks/chunk-XGXBMXJ6.js +0 -22
  283. package/lib/chunks/chunk-XGXBMXJ6.js.map +0 -7
  284. package/lib/chunks/chunk-Y44NEQQG.js +0 -22
  285. package/lib/chunks/chunk-Y44NEQQG.js.map +0 -7
  286. package/lib/chunks/chunk-ZVU3KPXI.js +0 -22
  287. package/lib/chunks/chunk-ZVU3KPXI.js.map +0 -7
  288. package/lib/chunks/monitoring-PVQMFL34.js +0 -22
  289. package/lib/chunks/monitoring-V7FZXTTW.js +0 -22
  290. package/lib/chunks/monitoring-V7FZXTTW.js.map +0 -7
  291. package/lib/chunks/rateLimiter-6KO7AIZP.js.map +0 -7
  292. package/lib/chunks/rateLimiter-OXVBFW5C.js +0 -22
  293. package/lib/chunks/rateLimiter-OXVBFW5C.js.map +0 -7
  294. package/lib/chunks/rateLimiter-U45OMTWR.js +0 -22
  295. package/lib/chunks/rateLimiter-U45OMTWR.js.map +0 -7
  296. package/lib/chunks/server-32A5RH4C.js +0 -22
  297. package/lib/chunks/server-32A5RH4C.js.map +0 -7
  298. package/lib/chunks/server-7HDAP5DL.js +0 -22
  299. package/lib/chunks/server-7HDAP5DL.js.map +0 -7
  300. package/lib/chunks/server-S2IMFOY7.js +0 -22
  301. package/lib/chunks/server-S2IMFOY7.js.map +0 -7
  302. package/lib/shared/ai/createAIHandler.d.ts +0 -39
  303. package/lib/shared/ai/providers/anthropic.d.ts +0 -12
  304. package/lib/shared/ai/providers/google.d.ts +0 -10
  305. package/lib/shared/ai/providers/index.d.ts +0 -23
  306. package/lib/shared/ai/providers/openai.d.ts +0 -10
  307. package/lib/shared/ai/utils/parseSSE.d.ts +0 -22
  308. /package/lib/chunks/{chunk-4TVLH2W2.js.map → chunk-2A4FPYNB.js.map} +0 -0
  309. /package/lib/chunks/{chunk-4U7QQWYG.js.map → chunk-M4JV2JCF.js.map} +0 -0
  310. /package/lib/chunks/{chunk-7LT32OWE.js.map → chunk-PJCJ5H2O.js.map} +0 -0
  311. /package/lib/chunks/{chunk-FSLGZD7A.js.map → monitoring-UIDJS2KA.js.map} +0 -0
  312. /package/lib/chunks/{monitoring-AGCSU3FI.js.map → rateLimiter-WNWHI3B4.js.map} +0 -0
  313. /package/lib/chunks/{monitoring-PVQMFL34.js.map → server-RYGEBS2B.js.map} +0 -0
@@ -75,7 +75,7 @@ async function getFirebaseAuth() {
75
75
  * @since 0.0.1
76
76
  * @author AMBROISE PARK Consulting
77
77
  */
78
- export function assertAuthenticated(uid: string): string {
78
+ export function assertAuthenticated(uid: string | undefined): string {
79
79
  // G62: Validate uid is a non-empty string — reject non-string values at runtime
80
80
  if (!uid || typeof uid !== 'string') {
81
81
  throw new Error('Authentication required');
@@ -258,8 +258,3 @@ export async function verifyAuthToken(
258
258
  const { uid } = await verifyToken(token, provider);
259
259
  return uid;
260
260
  }
261
-
262
- /**
263
- * @deprecated Use verifyAuthToken instead. Kept for backwards compatibility.
264
- */
265
- export const verifyFirebaseAuthToken = verifyAuthToken;
@@ -13,24 +13,6 @@ import * as v from 'valibot';
13
13
 
14
14
  import { DoNotDevError } from '@donotdev/core/server';
15
15
 
16
- /**
17
- * Validates environment variables required for Stripe
18
- *
19
- * @version 0.1.0
20
- * @since 0.0.1
21
- * @author AMBROISE PARK Consulting
22
- */
23
- export function validateStripeEnvironment(): void {
24
- const required = ['STRIPE_SECRET_KEY', 'STRIPE_WEBHOOK_SECRET'];
25
- const missing = required.filter((key) => !process.env[key]);
26
-
27
- if (missing.length > 0) {
28
- throw new Error(
29
- `Missing required environment variables: ${missing.join(', ')}`
30
- );
31
- }
32
- }
33
-
34
16
  /**
35
17
  * Safely parses JSON with error handling
36
18
  *
@@ -9,103 +9,14 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
- import Stripe from 'stripe';
13
12
  import * as v from 'valibot';
14
13
 
15
14
  import { DoNotDevError } from '@donotdev/core/server';
16
15
  import type { OAuthPartnerId, UserRole } from '@donotdev/core/server';
17
16
 
18
- import { STRIPE_API_VERSION_PIN } from './billing/apiVersion.js';
19
- import {
20
- assertAuthenticated as internalAssertAuthenticated,
21
- assertAdmin as internalAssertAdmin,
22
- } from './utils/internal/auth.js';
23
-
24
17
  // Re-export DoNotDevError for external use
25
18
  export { DoNotDevError };
26
19
 
27
- // Lazy initialization of Stripe
28
- let _stripe: Stripe | null = null;
29
-
30
- /**
31
- * Initialize Stripe explicitly (e.g. with a secret from defineSecret).
32
- * API version: `STRIPE_API_VERSION`, else {@link STRIPE_API_VERSION_PIN}.
33
- * @param apiKey - Stripe secret key
34
- *
35
- * @version 0.2.0
36
- * @since 0.0.1
37
- * @author AMBROISE PARK Consulting
38
- */
39
- export function initStripe(apiKey: string) {
40
- if (!apiKey) throw new Error('Stripe API key is required');
41
-
42
- // Unset: the framework pin (pre-basil fields are still read by subscription handlers)
43
- const apiVersion = process.env.STRIPE_API_VERSION || STRIPE_API_VERSION_PIN;
44
-
45
- _stripe = new Stripe(apiKey, {
46
- apiVersion: apiVersion as any,
47
- });
48
- return _stripe;
49
- }
50
-
51
- /**
52
- * Get Stripe instance with lazy initialization
53
- *
54
- * @version 0.1.0
55
- * @since 0.0.1
56
- * @author AMBROISE PARK Consulting
57
- */
58
- export function getStripe(): Stripe {
59
- if (!_stripe) {
60
- // Legacy/Vercel fallback: Try process.env
61
- const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
62
- if (STRIPE_SECRET_KEY) {
63
- initStripe(STRIPE_SECRET_KEY);
64
- } else {
65
- throw new Error(
66
- 'Stripe not initialized. Call initStripe() or set STRIPE_SECRET_KEY env var.'
67
- );
68
- }
69
- }
70
- // We know _stripe is set here or we threw
71
- return _stripe!;
72
- }
73
-
74
- /**
75
- * Lazy-initialized Stripe instance proxy
76
- *
77
- * @version 0.1.0
78
- * @since 0.0.1
79
- * @author AMBROISE PARK Consulting
80
- */
81
- export const stripe = new Proxy({} as Stripe, {
82
- get(target, prop) {
83
- return getStripe()[prop as keyof Stripe];
84
- },
85
- });
86
-
87
- /**
88
- * Assert that a user is authenticated from a Firebase callable auth context.
89
- *
90
- * @deprecated Import `assertAuthenticated` from `@donotdev/functions/shared/utils/internal/auth` instead.
91
- * This wrapper extracts uid from a Firebase callable auth context and delegates
92
- * to the canonical version.
93
- *
94
- * @param auth - Firebase callable request auth context (object with `.uid`)
95
- * @returns The authenticated user's uid
96
- *
97
- * @version 0.1.0
98
- * @since 0.0.1
99
- * @author AMBROISE PARK Consulting
100
- */
101
- export function assertAuthenticated(auth: any): string {
102
- const uid = auth?.uid;
103
- if (!uid) {
104
- throw new Error('User must be authenticated');
105
- }
106
- return internalAssertAuthenticated(uid);
107
- }
108
-
109
20
  /**
110
21
  * Get user role from Firebase auth context
111
22
  *
@@ -137,21 +48,6 @@ export function getUserRole(auth: any): UserRole {
137
48
  return 'user';
138
49
  }
139
50
 
140
- /**
141
- * Validates that required Stripe environment variables are set
142
- *
143
- * @version 0.1.0
144
- * @since 0.0.1
145
- * @author AMBROISE PARK Consulting
146
- */
147
- export function validateStripeEnvironment(): void {
148
- // Functions v2 automatically injects secrets as process.env when declared in config
149
- const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
150
- if (!STRIPE_SECRET_KEY) {
151
- throw new Error('Missing STRIPE_SECRET_KEY environment variable');
152
- }
153
- }
154
-
155
51
  /**
156
52
  * Creates a standardized success response
157
53
  *
@@ -211,110 +107,6 @@ export function createErrorResponse(error: unknown): {
211
107
  };
212
108
  }
213
109
 
214
- /**
215
- * Updates user subscription in Firebase.
216
- *
217
- * **Architecture decision — throwing stubs for billing functions:**
218
- * These subscription functions (`updateUserSubscription`, `getUserSubscription`,
219
- * `cancelUserSubscription`, `handleSubscriptionCancellation`) are intentional
220
- * placeholder implementations. They exist so the framework compiles and
221
- * type-checks out of the box, but throw at runtime to surface missing
222
- * integration early. Consumer apps replace them with their billing provider
223
- * integration (Stripe, Paddle, LemonSqueezy, etc.) via the documented
224
- * `shared/billing/helpers/` modules.
225
- *
226
- * C10: This was a silent no-op stub. It now throws to surface the missing
227
- * implementation at startup rather than silently dropping webhook events.
228
- * Use `updateUserSubscription` from `shared/billing/helpers/updateUserSubscription.ts`
229
- * (which requires an authProvider) instead.
230
- *
231
- * @deprecated Import `updateUserSubscription` from `@donotdev/functions/shared/billing/helpers/updateUserSubscription`.
232
- * @version 0.1.0
233
- * @since 0.0.1
234
- * @author AMBROISE PARK Consulting
235
- */
236
- export async function updateUserSubscription(
237
- _firebaseUid: string,
238
- _subscription: any
239
- ): Promise<void> {
240
- throw new DoNotDevError(
241
- 'updateUserSubscription stub called — import from shared/billing/helpers/updateUserSubscription.ts and supply an authProvider',
242
- 'unimplemented'
243
- );
244
- }
245
-
246
- /**
247
- * Gets user subscription from Firebase.
248
- *
249
- * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
250
- *
251
- * @deprecated Import from `@donotdev/functions/shared/billing/helpers` or implement directly using Firebase Admin SDK / Stripe API.
252
- * @version 0.1.0
253
- * @since 0.0.1
254
- * @author AMBROISE PARK Consulting
255
- */
256
- export async function getUserSubscription(_firebaseUid: string): Promise<any> {
257
- throw new DoNotDevError(
258
- 'getUserSubscription stub called — implement using Firebase Admin SDK or Stripe API',
259
- 'unimplemented'
260
- );
261
- }
262
-
263
- /**
264
- * Cancels user subscription.
265
- *
266
- * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
267
- *
268
- * @deprecated Import `cancelUserSubscription` from `@donotdev/functions/shared/billing/helpers/subscriptionManagement`.
269
- * @version 0.1.0
270
- * @since 0.0.1
271
- * @author AMBROISE PARK Consulting
272
- */
273
- export async function cancelUserSubscription(
274
- _firebaseUid: string,
275
- _subscription: any
276
- ): Promise<void> {
277
- throw new DoNotDevError(
278
- 'cancelUserSubscription stub called — import from shared/billing/helpers/subscriptionManagement.ts',
279
- 'unimplemented'
280
- );
281
- }
282
-
283
- /**
284
- * Handles subscription cancellation.
285
- *
286
- * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
287
- *
288
- * @deprecated Handle via Stripe webhook events. Use `processWebhook` from `@donotdev/functions/shared/billing/webhookHandler`.
289
- * @version 0.1.0
290
- * @since 0.0.1
291
- * @author AMBROISE PARK Consulting
292
- */
293
- export async function handleSubscriptionCancellation(
294
- _firebaseUid: string,
295
- _subscription: any
296
- ): Promise<void> {
297
- throw new DoNotDevError(
298
- 'handleSubscriptionCancellation stub called — handle via Stripe webhook events',
299
- 'unimplemented'
300
- );
301
- }
302
-
303
- /**
304
- * Asserts that a user has admin privileges
305
- * Uses role hierarchy: super > admin > user > guest
306
- *
307
- * @deprecated Import `assertAdmin` from `@donotdev/functions/shared/utils/internal/auth` instead.
308
- * This is a thin wrapper that delegates to the canonical provider-agnostic version.
309
- *
310
- * @version 0.1.0
311
- * @since 0.0.1
312
- * @author AMBROISE PARK Consulting
313
- */
314
- export async function assertAdmin(uid: string): Promise<string> {
315
- return internalAssertAdmin(uid);
316
- }
317
-
318
110
  /**
319
111
  * Validates document data
320
112
  *
@@ -12,7 +12,7 @@
12
12
  import * as v from 'valibot';
13
13
 
14
14
  import { cancelUserSubscription } 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
 
@@ -14,7 +14,7 @@ import * as v from 'valibot';
14
14
  import { hasRoleAccess, type StripeBackConfig } from '@donotdev/core/server';
15
15
 
16
16
  import { changeUserPlan } from '../../shared/billing/helpers/subscriptionManagement.js';
17
- import { initStripe } from '../../shared/utils.js';
17
+ import { initStripe } from '../../shared/billing/stripeClient.js';
18
18
  import { createSupabaseHandler } from '../baseFunction.js';
19
19
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
20
20
 
@@ -15,11 +15,7 @@ import type { CreateCheckoutSessionRequest } from '@donotdev/core/server';
15
15
 
16
16
  import { createCheckoutAlgorithm } from '../../shared/billing/createCheckout.js';
17
17
  import type { StripeSessionProvider } from '../../shared/billing/createCheckout.js';
18
- import {
19
- initStripe,
20
- stripe,
21
- validateStripeEnvironment,
22
- } from '../../shared/utils.js';
18
+ import { initStripe, stripe, validateStripeEnvironment } from '../../shared/billing/stripeClient.js';
23
19
  import { createSupabaseHandler } from '../baseFunction.js';
24
20
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
25
21
 
@@ -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
 
@@ -12,11 +12,7 @@
12
12
  import type Stripe from 'stripe';
13
13
  import * as v from 'valibot';
14
14
 
15
- import {
16
- initStripe,
17
- stripe,
18
- validateStripeEnvironment,
19
- } from '../../shared/utils.js';
15
+ import { initStripe, stripe, validateStripeEnvironment } from '../../shared/billing/stripeClient.js';
20
16
  import { createSupabaseHandler } from '../baseFunction.js';
21
17
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
22
18
 
@@ -13,9 +13,9 @@
13
13
  import type { StripeBackConfig } from '@donotdev/core/server';
14
14
 
15
15
  import { updateUserSubscription } from '../../shared/billing/helpers/updateUserSubscription.js';
16
- import { createSupabaseIdempotencyStore } from '../../shared/billing/idempotency.js';
16
+ import { createSupabaseIdempotencyStore } from '../../shared/billing/supabaseIdempotency.js';
17
17
  import { processWebhook } from '../../shared/billing/webhookHandler.js';
18
- import { initStripe, stripe } from '../../shared/utils.js';
18
+ import { initStripe, stripe } from '../../shared/billing/stripeClient.js';
19
19
  import { createEdgeFunction } from '../edgeFunction.js';
20
20
  import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
21
21
 
@@ -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 {
@@ -34,13 +34,13 @@ export { createCheckoutSession } from './billing/createCheckoutSession.js';
34
34
  export { createStripeWebhook } from './billing/stripeWebhook.js';
35
35
  export {
36
36
  createSupabaseIdempotencyStore,
37
- ReservationLostError,
38
37
  WEBHOOK_EVENTS_SQL,
39
- } from '../shared/billing/idempotency.js';
38
+ } from '../shared/billing/supabaseIdempotency.js';
39
+ export { ReservationLostError } from '../shared/billing/idempotencyContract.js';
40
40
  export type {
41
41
  IdempotencyStore,
42
42
  ReservationResult,
43
- } from '../shared/billing/idempotency.js';
43
+ } from '../shared/billing/idempotencyContract.js';
44
44
  // Custom StripeOrder entry points (app request shape, own StripeSessionProvider)
45
45
  export { createCheckoutAlgorithm } from '../shared/billing/createCheckout.js';
46
46
  export type { StripeSessionProvider } from '../shared/billing/createCheckout.js';
@@ -17,7 +17,7 @@ import type { StripeBackConfig } from '@donotdev/core/server';
17
17
 
18
18
  import { updateUserSubscription } from '../../../shared/billing/helpers/updateUserSubscription.js';
19
19
  import { handleError } from '../../../shared/errorHandling.js';
20
- import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
20
+ import { stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
21
21
  import { createVercelBaseFunction } from '../../baseFunction.js';
22
22
 
23
23
  const changePlanSchema = v.object({
@@ -22,11 +22,7 @@ import { resolveBillingBackend } from './backend.js';
22
22
  import type { VercelBillingOptions } from './backend.js';
23
23
  import { createCheckoutAlgorithm } from '../../../shared/billing/createCheckout.js';
24
24
  import type { StripeSessionProvider } from '../../../shared/billing/createCheckout.js';
25
- import {
26
- initStripe,
27
- stripe,
28
- validateStripeEnvironment,
29
- } from '../../../shared/utils.js';
25
+ import { initStripe, stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
30
26
  import { createVercelBaseFunction } from '../../baseFunction.js';
31
27
 
32
28
  /**
@@ -13,7 +13,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
13
13
  import * as v from 'valibot';
14
14
 
15
15
  import { handleError } from '../../../shared/errorHandling.js';
16
- import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
16
+ import { stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
17
17
  import { createVercelBaseFunction } from '../../baseFunction.js';
18
18
 
19
19
  const customerPortalSchema = v.object({
@@ -15,7 +15,7 @@ import * as v from 'valibot';
15
15
 
16
16
  import type { RefreshSubscriptionRequest } from '@donotdev/core/server';
17
17
 
18
- import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
18
+ import { stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
19
19
  import { createVercelBaseFunction } from '../../baseFunction.js';
20
20
 
21
21
  const refreshSubscriptionStatusSchema = v.object({
@@ -18,7 +18,7 @@ import type { VercelBillingOptions } from './backend.js';
18
18
  import { updateUserSubscription } from '../../../shared/billing/helpers/updateUserSubscription.js';
19
19
  import { processWebhook } from '../../../shared/billing/webhookHandler.js';
20
20
  import { logger } from '../../../shared/logger.js';
21
- import { stripe } from '../../../shared/utils.js';
21
+ import { stripe } from '../../../shared/billing/stripeClient.js';
22
22
 
23
23
  /**
24
24
  * Create Vercel webhook handler from billing config.