@donotdev/functions 0.1.44 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +25 -14
  2. package/lib/chunks/chunk-2JL3GDTO.js +151 -0
  3. package/lib/chunks/chunk-2JL3GDTO.js.map +7 -0
  4. package/lib/chunks/chunk-4TVLH2W2.js +22 -0
  5. package/lib/chunks/chunk-4TVLH2W2.js.map +7 -0
  6. package/lib/chunks/chunk-4U7QQWYG.js +22 -0
  7. package/lib/chunks/chunk-4U7QQWYG.js.map +7 -0
  8. package/lib/chunks/chunk-5DTPEM64.js +22 -0
  9. package/lib/chunks/chunk-5DTPEM64.js.map +7 -0
  10. package/lib/chunks/chunk-6CQXHNVL.js +22 -0
  11. package/lib/chunks/chunk-6CQXHNVL.js.map +7 -0
  12. package/lib/chunks/chunk-6DSCPZC6.js +22 -0
  13. package/lib/chunks/chunk-6DSCPZC6.js.map +7 -0
  14. package/lib/chunks/chunk-7E6TGWHU.js +22 -0
  15. package/lib/chunks/chunk-7E6TGWHU.js.map +7 -0
  16. package/lib/chunks/chunk-7LT32OWE.js +22 -0
  17. package/lib/chunks/chunk-7LT32OWE.js.map +7 -0
  18. package/lib/chunks/chunk-7VH2GJXT.js +151 -0
  19. package/lib/chunks/chunk-7VH2GJXT.js.map +7 -0
  20. package/lib/chunks/chunk-API5A4BV.js +22 -0
  21. package/lib/chunks/chunk-API5A4BV.js.map +7 -0
  22. package/lib/chunks/chunk-AYY7UXNI.js +22 -0
  23. package/lib/chunks/chunk-AYY7UXNI.js.map +7 -0
  24. package/lib/chunks/chunk-BUP7SXPV.js +23 -0
  25. package/lib/chunks/chunk-BUP7SXPV.js.map +7 -0
  26. package/lib/chunks/chunk-BXKRI3JJ.js +22 -0
  27. package/lib/chunks/chunk-BXKRI3JJ.js.map +7 -0
  28. package/lib/chunks/chunk-FSLGZD7A.js +21 -0
  29. package/lib/chunks/chunk-FSLGZD7A.js.map +7 -0
  30. package/lib/chunks/chunk-GVLSPWDD.js +151 -0
  31. package/lib/chunks/chunk-GVLSPWDD.js.map +7 -0
  32. package/lib/chunks/chunk-GXQVWEFT.js +22 -0
  33. package/lib/chunks/chunk-GXQVWEFT.js.map +7 -0
  34. package/lib/chunks/chunk-HB7EGXVI.js +22 -0
  35. package/lib/chunks/chunk-HB7EGXVI.js.map +7 -0
  36. package/lib/chunks/chunk-HLNYUAZH.js +22 -0
  37. package/lib/chunks/chunk-HLNYUAZH.js.map +7 -0
  38. package/lib/chunks/chunk-HM7XCMWW.js +22 -0
  39. package/lib/chunks/chunk-HM7XCMWW.js.map +7 -0
  40. package/lib/chunks/chunk-I7IOIL6U.js +151 -0
  41. package/lib/chunks/chunk-I7IOIL6U.js.map +7 -0
  42. package/lib/chunks/chunk-IFOYVSPU.js +22 -0
  43. package/lib/chunks/chunk-IFOYVSPU.js.map +7 -0
  44. package/lib/chunks/chunk-JTAGPPPL.js +22 -0
  45. package/lib/chunks/chunk-JTAGPPPL.js.map +7 -0
  46. package/lib/chunks/chunk-MZ232FUE.js +22 -0
  47. package/lib/chunks/chunk-MZ232FUE.js.map +7 -0
  48. package/lib/chunks/chunk-NE5ZTUUZ.js +22 -0
  49. package/lib/chunks/chunk-NE5ZTUUZ.js.map +7 -0
  50. package/lib/chunks/chunk-NP2AN2TV.js +22 -0
  51. package/lib/chunks/chunk-NP2AN2TV.js.map +7 -0
  52. package/lib/chunks/chunk-QJAU2MWV.js +22 -0
  53. package/lib/chunks/chunk-QJAU2MWV.js.map +7 -0
  54. package/lib/chunks/chunk-RM7DV6IQ.js +23 -0
  55. package/lib/chunks/chunk-RM7DV6IQ.js.map +7 -0
  56. package/lib/chunks/chunk-RQZGIZHD.js +151 -0
  57. package/lib/chunks/chunk-RQZGIZHD.js.map +7 -0
  58. package/lib/chunks/chunk-TBEDQLOB.js +23 -0
  59. package/lib/chunks/chunk-TBEDQLOB.js.map +7 -0
  60. package/lib/chunks/chunk-TMHBP3HB.js +22 -0
  61. package/lib/chunks/chunk-TMHBP3HB.js.map +7 -0
  62. package/lib/chunks/chunk-UH4L3EF3.js +151 -0
  63. package/lib/chunks/chunk-UH4L3EF3.js.map +7 -0
  64. package/lib/chunks/chunk-UJBIU6TL.js +22 -0
  65. package/lib/chunks/chunk-UJBIU6TL.js.map +7 -0
  66. package/lib/chunks/chunk-VKEYW3NT.js +22 -0
  67. package/lib/chunks/chunk-VKEYW3NT.js.map +7 -0
  68. package/lib/chunks/chunk-XGXBMXJ6.js +22 -0
  69. package/lib/chunks/chunk-XGXBMXJ6.js.map +7 -0
  70. package/lib/chunks/chunk-Y44NEQQG.js +22 -0
  71. package/lib/chunks/chunk-Y44NEQQG.js.map +7 -0
  72. package/lib/chunks/chunk-ZVU3KPXI.js +22 -0
  73. package/lib/chunks/chunk-ZVU3KPXI.js.map +7 -0
  74. package/lib/chunks/monitoring-AGCSU3FI.js +22 -0
  75. package/lib/chunks/monitoring-AGCSU3FI.js.map +7 -0
  76. package/lib/chunks/monitoring-PVQMFL34.js +22 -0
  77. package/lib/chunks/monitoring-PVQMFL34.js.map +7 -0
  78. package/lib/chunks/monitoring-V7FZXTTW.js +22 -0
  79. package/lib/chunks/monitoring-V7FZXTTW.js.map +7 -0
  80. package/lib/chunks/rateLimiter-6KO7AIZP.js +22 -0
  81. package/lib/chunks/rateLimiter-6KO7AIZP.js.map +7 -0
  82. package/lib/chunks/rateLimiter-OXVBFW5C.js +22 -0
  83. package/lib/chunks/rateLimiter-OXVBFW5C.js.map +7 -0
  84. package/lib/chunks/rateLimiter-U45OMTWR.js +22 -0
  85. package/lib/chunks/rateLimiter-U45OMTWR.js.map +7 -0
  86. package/lib/chunks/server-32A5RH4C.js +22 -0
  87. package/lib/chunks/server-32A5RH4C.js.map +7 -0
  88. package/lib/chunks/server-7HDAP5DL.js +22 -0
  89. package/lib/chunks/server-7HDAP5DL.js.map +7 -0
  90. package/lib/chunks/server-S2IMFOY7.js +22 -0
  91. package/lib/chunks/server-S2IMFOY7.js.map +7 -0
  92. package/lib/firebase/auth/getCustomClaims.d.ts +1 -1
  93. package/lib/firebase/auth/getUserAuthStatus.d.ts +1 -1
  94. package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
  95. package/lib/firebase/auth/setCustomClaims.d.ts +1 -1
  96. package/lib/firebase/baseFunction.d.ts +1 -1
  97. package/lib/firebase/billing/createCheckoutSession.d.ts +2 -2
  98. package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
  99. package/lib/firebase/billing/index.d.ts +2 -1
  100. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -8
  101. package/lib/firebase/billing/webhookHandler.d.ts +17 -2
  102. package/lib/firebase/crud/aggregate.d.ts +0 -9
  103. package/lib/firebase/crud/bulk.d.ts +2 -2
  104. package/lib/firebase/crud/create.d.ts +1 -1
  105. package/lib/firebase/crud/delete.d.ts +1 -1
  106. package/lib/firebase/crud/get.d.ts +1 -1
  107. package/lib/firebase/crud/list.d.ts +1 -1
  108. package/lib/firebase/crud/update.d.ts +1 -9
  109. package/lib/firebase/index.js +1 -5
  110. package/lib/firebase/index.js.map +4 -4
  111. package/lib/firebase/oauth/githubAccess.d.ts +2 -2
  112. package/lib/firebase/registerCrudFunctions.d.ts +9 -1
  113. package/lib/shared/billing/apiVersion.d.ts +22 -0
  114. package/lib/shared/billing/checkoutPrice.d.ts +27 -0
  115. package/lib/shared/billing/checkoutValidation.d.ts +89 -0
  116. package/lib/shared/billing/createCheckout.d.ts +73 -24
  117. package/lib/shared/billing/helpers/index.d.ts +0 -1
  118. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +4 -4
  119. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -29
  120. package/lib/shared/billing/idempotency.d.ts +32 -10
  121. package/lib/shared/billing/idempotencyContract.d.ts +121 -0
  122. package/lib/shared/billing/index.d.ts +2 -0
  123. package/lib/shared/billing/orderWebhook.d.ts +75 -0
  124. package/lib/shared/billing/supabaseIdempotency.d.ts +32 -0
  125. package/lib/shared/billing/tierWebhookEvents.d.ts +54 -0
  126. package/lib/shared/billing/webhookHandler.d.ts +28 -20
  127. package/lib/shared/index.js +1 -6
  128. package/lib/shared/index.js.map +4 -4
  129. package/lib/shared/utils/functionWrapper.d.ts +1 -1
  130. package/lib/shared/utils/internal/auth.d.ts +38 -1
  131. package/lib/shared/utils/internal/rateLimiter.d.ts +8 -0
  132. package/lib/shared/utils/schemaValidation.d.ts +1 -1
  133. package/lib/shared/utils/vercelHelpers.d.ts +8 -0
  134. package/lib/shared/utils.d.ts +4 -17
  135. package/lib/supabase/baseFunction.d.ts +1 -1
  136. package/lib/supabase/billing/stripeWebhook.d.ts +34 -0
  137. package/lib/supabase/crud/bulk.d.ts +1 -1
  138. package/lib/supabase/crud/entityStore.d.ts +71 -0
  139. package/lib/supabase/crud/index.d.ts +2 -0
  140. package/lib/supabase/helpers/authProvider.d.ts +5 -5
  141. package/lib/supabase/index.d.ts +10 -2
  142. package/lib/supabase/index.js +1 -3
  143. package/lib/supabase/index.js.map +4 -4
  144. package/lib/supabase/utils/rateLimiter.d.ts +1 -1
  145. package/lib/vercel/api/ai/chat.d.ts +0 -9
  146. package/lib/vercel/api/auth/get-custom-claims.d.ts +8 -0
  147. package/lib/vercel/api/auth/get-user-auth-status.d.ts +8 -0
  148. package/lib/vercel/api/auth/remove-custom-claims.d.ts +8 -0
  149. package/lib/vercel/api/auth/set-custom-claims.d.ts +8 -0
  150. package/lib/vercel/api/billing/backend.d.ts +39 -0
  151. package/lib/vercel/api/billing/cancel.d.ts +8 -0
  152. package/lib/vercel/api/billing/change-plan.d.ts +9 -1
  153. package/lib/vercel/api/billing/create-checkout-session.d.ts +25 -6
  154. package/lib/vercel/api/billing/customer-portal.d.ts +8 -0
  155. package/lib/vercel/api/billing/index.d.ts +4 -2
  156. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +19 -3
  157. package/lib/vercel/api/billing/webhook-handler.d.ts +25 -4
  158. package/lib/vercel/api/config/firebase-admin.d.ts +8 -0
  159. package/lib/vercel/api/crud/bulk.d.ts +17 -0
  160. package/lib/vercel/api/crud/create.d.ts +8 -0
  161. package/lib/vercel/api/crud/delete.d.ts +8 -0
  162. package/lib/vercel/api/crud/get.d.ts +8 -0
  163. package/lib/vercel/api/crud/list.d.ts +8 -0
  164. package/lib/vercel/api/crud/update.d.ts +8 -0
  165. package/lib/vercel/api/index.js +1 -3
  166. package/lib/vercel/api/index.js.map +4 -4
  167. package/lib/vercel/api/oauth/check-github-access.d.ts +8 -0
  168. package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
  169. package/lib/vercel/api/oauth/grant-github-access.d.ts +8 -0
  170. package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
  171. package/lib/vercel/baseFunction.d.ts +4 -1
  172. package/lib/vercel/supabaseAdmin.d.ts +22 -0
  173. package/package.json +25 -26
  174. package/src/firebase/auth/getCustomClaims.ts +4 -5
  175. package/src/firebase/auth/getUserAuthStatus.ts +4 -5
  176. package/src/firebase/auth/removeCustomClaims.ts +4 -5
  177. package/src/firebase/auth/setCustomClaims.ts +4 -5
  178. package/src/firebase/baseFunction.ts +4 -5
  179. package/src/firebase/billing/cancelSubscription.ts +1 -2
  180. package/src/firebase/billing/changePlan.ts +2 -3
  181. package/src/firebase/billing/createCheckoutSession.ts +30 -56
  182. package/src/firebase/billing/createCustomerPortal.ts +4 -5
  183. package/src/firebase/billing/healthCheck.ts +0 -0
  184. package/src/firebase/billing/index.ts +8 -1
  185. package/src/firebase/billing/refreshSubscriptionStatus.ts +2 -3
  186. package/src/firebase/billing/webhookHandler.ts +20 -4
  187. package/src/firebase/crud/__tests__/bulk.test.ts +11 -1
  188. package/src/firebase/crud/aggregate.ts +1 -2
  189. package/src/firebase/crud/bulk.ts +5 -6
  190. package/src/firebase/crud/create.ts +5 -6
  191. package/src/firebase/crud/delete.ts +4 -5
  192. package/src/firebase/crud/get.ts +4 -5
  193. package/src/firebase/crud/list.ts +4 -5
  194. package/src/firebase/crud/update.ts +5 -6
  195. package/src/firebase/oauth/githubAccess.ts +2 -3
  196. package/src/firebase/registerCrudFunctions.ts +2 -2
  197. package/src/shared/__tests__/auth.test.ts +0 -3
  198. package/src/shared/__tests__/bulkCore.test.ts +3 -2
  199. package/src/shared/__tests__/errorHandling.test.ts +2 -2
  200. package/src/shared/__tests__/idempotency.test.ts +282 -55
  201. package/src/shared/__tests__/internalValidation.test.ts +3 -3
  202. package/src/shared/__tests__/rateLimiter.test.ts +2 -8
  203. package/src/shared/__tests__/schemaValidation.test.ts +1 -1
  204. package/src/shared/__tests__/utils.test.ts +2 -1
  205. package/src/shared/__tests__/validation-env.test.ts +0 -0
  206. package/src/shared/ai/createAIRoute.ts +53 -30
  207. package/src/shared/billing/__tests__/checkoutValidation.test.ts +219 -0
  208. package/src/shared/billing/__tests__/createCheckout.compat.test.ts +349 -0
  209. package/src/shared/billing/__tests__/createCheckout.test.ts +454 -411
  210. package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +92 -0
  211. package/src/shared/billing/__tests__/webhookCorrectness.test.ts +387 -0
  212. package/src/shared/billing/__tests__/webhookHandler.test.ts +407 -23
  213. package/src/shared/billing/apiVersion.ts +25 -0
  214. package/src/shared/billing/checkoutPrice.ts +125 -0
  215. package/src/shared/billing/checkoutValidation.ts +284 -0
  216. package/src/shared/billing/createCheckout.ts +332 -196
  217. package/src/shared/billing/helpers/index.ts +0 -1
  218. package/src/shared/billing/helpers/subscriptionManagement.ts +7 -9
  219. package/src/shared/billing/helpers/updateUserSubscription.ts +3 -36
  220. package/src/shared/billing/idempotency.ts +253 -150
  221. package/src/shared/billing/idempotencyContract.ts +135 -0
  222. package/src/shared/billing/index.ts +2 -0
  223. package/src/shared/billing/orderWebhook.ts +269 -0
  224. package/src/shared/billing/supabaseIdempotency.ts +228 -0
  225. package/src/shared/billing/tierWebhookEvents.ts +432 -0
  226. package/src/shared/billing/webhookHandler.ts +188 -385
  227. package/src/shared/utils/external/subscription.ts +0 -0
  228. package/src/shared/utils/firebaseHelpers.ts +2 -3
  229. package/src/shared/utils/functionWrapper.ts +1 -2
  230. package/src/shared/utils/internal/auth.ts +55 -7
  231. package/src/shared/utils/internal/monitoring.ts +17 -9
  232. package/src/shared/utils/internal/rateLimiter.ts +14 -5
  233. package/src/shared/utils/schemaValidation.ts +1 -2
  234. package/src/shared/utils/vercelHelpers.ts +3 -3
  235. package/src/shared/utils.ts +14 -31
  236. package/src/shared/validation.ts +1 -1
  237. package/src/supabase/__tests__/bulk.test.ts +3 -1
  238. package/src/supabase/__tests__/entityStore.test.ts +90 -0
  239. package/src/supabase/baseFunction.ts +1 -2
  240. package/src/supabase/billing/createCheckoutSession.ts +10 -36
  241. package/src/supabase/billing/refreshSubscriptionStatus.ts +1 -2
  242. package/src/supabase/billing/stripeWebhook.ts +79 -0
  243. package/src/supabase/crud/aggregate.ts +1 -1
  244. package/src/supabase/crud/bulk.ts +3 -7
  245. package/src/supabase/crud/create.ts +1 -1
  246. package/src/supabase/crud/entityStore.ts +240 -0
  247. package/src/supabase/crud/index.ts +8 -0
  248. package/src/supabase/crud/update.ts +1 -1
  249. package/src/supabase/helpers/authProvider.ts +6 -5
  250. package/src/supabase/index.ts +26 -0
  251. package/src/supabase/utils/rateLimiter.ts +2 -2
  252. package/src/vercel/__tests__/bulk.test.ts +24 -21
  253. package/src/vercel/__tests__/firebaseOptional.test.ts +64 -0
  254. package/src/vercel/api/ai/chat.ts +2 -1
  255. package/src/vercel/api/auth/get-custom-claims.ts +2 -3
  256. package/src/vercel/api/auth/get-user-auth-status.ts +2 -3
  257. package/src/vercel/api/auth/remove-custom-claims.ts +2 -3
  258. package/src/vercel/api/auth/set-custom-claims.ts +3 -3
  259. package/src/vercel/api/billing/backend.ts +72 -0
  260. package/src/vercel/api/billing/cancel.ts +2 -4
  261. package/src/vercel/api/billing/change-plan.ts +3 -4
  262. package/src/vercel/api/billing/create-checkout-session.ts +42 -68
  263. package/src/vercel/api/billing/customer-portal.ts +2 -4
  264. package/src/vercel/api/billing/index.ts +4 -2
  265. package/src/vercel/api/billing/refresh-subscription-status.ts +21 -6
  266. package/src/vercel/api/billing/webhook-handler.ts +31 -25
  267. package/src/vercel/api/config/firebase-admin.ts +2 -2
  268. package/src/vercel/api/crud/bulk.ts +6 -9
  269. package/src/vercel/api/crud/create.ts +6 -5
  270. package/src/vercel/api/crud/delete.ts +4 -3
  271. package/src/vercel/api/crud/get.ts +6 -5
  272. package/src/vercel/api/crud/list.ts +6 -5
  273. package/src/vercel/api/crud/update.ts +6 -5
  274. package/src/vercel/api/oauth/check-github-access.ts +5 -5
  275. package/src/vercel/api/oauth/exchange-token.ts +3 -3
  276. package/src/vercel/api/oauth/grant-github-access.ts +5 -5
  277. package/src/vercel/api/oauth/revoke-github-access.ts +3 -4
  278. package/src/vercel/baseFunction.ts +23 -8
  279. package/src/vercel/supabaseAdmin.ts +45 -0
@@ -6,9 +6,9 @@
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
- import * as v from 'valibot';
10
9
  import type { CallableRequest } from 'firebase-functions/v2/https';
11
10
  import type { NextApiRequest, NextApiResponse } from 'next';
11
+ import * as v from 'valibot';
12
12
  /**
13
13
  * Simple wrapper that validates data against schema and calls the handler
14
14
  * This is the ONLY pattern needed for all functions
@@ -1,6 +1,43 @@
1
+ /**
2
+ * @fileoverview Authentication utility functions
3
+ * @description Provider-agnostic functions for user authentication and authorization.
4
+ * Uses IServerAuthAdapter from provider registry when configured, falls back to Firebase Admin SDK.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
1
10
  import type { NextApiRequest } from 'next';
11
+ import * as v from 'valibot';
12
+ /**
13
+ * Auth backends a server function can be explicitly configured with.
14
+ *
15
+ * @version 0.2.0
16
+ * @since 0.2.0
17
+ * @author AMBROISE PARK Consulting
18
+ */
19
+ export declare const AuthBackendSchema: v.PicklistSchema<["firebase", "supabase"], undefined>;
2
20
  /** Auth provider type for explicit configuration */
3
- export type AuthProvider = 'firebase' | 'supabase';
21
+ export type AuthProvider = v.InferOutput<typeof AuthBackendSchema>;
22
+ /**
23
+ * Validate an auth backend at runtime. Values typed as `AuthProvider` can
24
+ * still arrive as arbitrary strings from JS or env-driven config, and an
25
+ * unknown value must never silently run as Firebase.
26
+ *
27
+ * @param backend - Value to validate
28
+ * @returns The validated backend
29
+ * @throws DoNotDevError (`invalid-argument`) naming the allowed values
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const backend = parseAuthBackend(process.env.AUTH_BACKEND); // 'firebase' | 'supabase'
34
+ * ```
35
+ *
36
+ * @version 0.2.0
37
+ * @since 0.2.0
38
+ * @author AMBROISE PARK Consulting
39
+ */
40
+ export declare function parseAuthBackend(backend: unknown): AuthProvider;
4
41
  /**
5
42
  * Validates that user is authenticated
6
43
  *
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @fileoverview Server-side rate limiting utilities
3
+ * @description Rate limiting implementation for Firebase Functions and Vercel
4
+ *
5
+ * @version 0.1.0
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
1
9
  import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
2
10
  export type { RateLimitConfig, RateLimitResult };
3
11
  /**
@@ -6,9 +6,9 @@
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
- import * as v from 'valibot';
10
9
  import type { CallableRequest } from 'firebase-functions/v2/https';
11
10
  import type { NextApiRequest, NextApiResponse } from 'next';
11
+ import * as v from 'valibot';
12
12
  /**
13
13
  * Validates request data using a schema with custom override support
14
14
  *
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @fileoverview DRY helpers for Vercel API functions with schema validation
3
+ * @description Provides reusable patterns for Vercel API routes
4
+ *
5
+ * @version 0.1.0
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
1
9
  import type { NextApiRequest, NextApiResponse } from 'next';
2
10
  import type * as v from 'valibot';
3
11
  /**
@@ -11,27 +11,14 @@ import { DoNotDevError } from '@donotdev/core/server';
11
11
  import type { UserRole } from '@donotdev/core/server';
12
12
  export { DoNotDevError };
13
13
  /**
14
- * Get Firestore instance using @donotdev/firebase/server
15
- * Provider handles initialization and caching
16
- *
17
- * @version 0.1.0
18
- * @since 0.0.1
19
- * @author AMBROISE PARK Consulting
20
- */
21
- export declare function getFirestore(): FirebaseFirestore.Firestore;
22
- /**
23
- * Get Auth instance using @donotdev/firebase/server
24
- * Provider handles initialization and caching
14
+ * Initialize Stripe explicitly (e.g. with a secret from defineSecret).
15
+ * API version: `STRIPE_API_VERSION`, else {@link STRIPE_API_VERSION_PIN}.
16
+ * @param apiKey - Stripe secret key
25
17
  *
26
- * @version 0.1.0
18
+ * @version 0.2.0
27
19
  * @since 0.0.1
28
20
  * @author AMBROISE PARK Consulting
29
21
  */
30
- export declare function getAuth(): import("firebase-admin/auth").Auth;
31
- /**
32
- * Initialize Stripe explicitly (e.g. with a secret from defineSecret)
33
- * @param apiKey - Stripe secret key
34
- */
35
22
  export declare function initStripe(apiKey: string): Stripe;
36
23
  /**
37
24
  * Get Stripe instance with lazy initialization
@@ -1,6 +1,6 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
1
2
  import * as v from 'valibot';
2
3
  import type { UserRole, SecurityContext } from '@donotdev/core/server';
3
- import type { SupabaseClient } from '@supabase/supabase-js';
4
4
  /**
5
5
  * Context passed to Supabase Edge Function business logic
6
6
  *
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview Stripe webhook Supabase Edge Function
3
+ * @description Verifies and routes Stripe webhook events through the shared
4
+ * processWebhook (SSOT). Idempotency is stored in Postgres (`webhook_events`).
5
+ *
6
+ * @version 0.2.0
7
+ * @since 0.2.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { StripeBackConfig } from '@donotdev/core/server';
11
+ /**
12
+ * Create a Supabase Edge Function handler for Stripe webhooks.
13
+ * Requires the `webhook_events` migration (see `WEBHOOK_EVENTS_SQL`).
14
+ * Deploy with JWT verification disabled for this function: Stripe authenticates
15
+ * with its signature, not a Supabase JWT.
16
+ * Any failure answers non-2xx so Stripe retries the event.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // supabase/functions/stripe-webhook/index.ts
21
+ * import { createStripeWebhook } from '@donotdev/functions/supabase';
22
+ * import { billingConfig } from '../_shared/billingConfig.ts';
23
+ *
24
+ * Deno.serve(createStripeWebhook(billingConfig));
25
+ * ```
26
+ *
27
+ * @param billingConfig - App back config
28
+ * @returns `(req: Request) => Promise<Response>` handler
29
+ *
30
+ * @version 0.2.0
31
+ * @since 0.2.0
32
+ * @author AMBROISE PARK Consulting
33
+ */
34
+ export declare function createStripeWebhook(billingConfig: StripeBackConfig): (req: Request) => Promise<Response>;
@@ -14,7 +14,7 @@
14
14
  * @since 0.6.0
15
15
  * @author AMBROISE PARK Consulting
16
16
  */
17
- import * as v from 'valibot';
17
+ import type * as v from 'valibot';
18
18
  import type { BulkRequest, EntityAccessConfig } from '@donotdev/core/server';
19
19
  /** Request payload accepted by the bulk handler — mirrors {@link BulkRequestSchema}. */
20
20
  export type BulkEntityRequest = BulkRequest;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @fileoverview In-process, entity-aware CRUD for server code (Edge Functions, jobs).
3
+ * @description The HTTP CRUD handlers serve clients. Server code that already holds
4
+ * a Supabase client (usually the service role) reads and writes through this store
5
+ * instead of raw `.from()` queries: entity field names in and out (snake_case
6
+ * columns stay behind the field mapper), unknown fields rejected, and the
7
+ * publication filter applied by default (draft / deleted rows hidden, as the
8
+ * database policy hides them from non-admin users; the service role bypasses that
9
+ * policy, so the store re-applies it on reads).
10
+ *
11
+ * No role or visibility masking: the caller is trusted server code. Atomic
12
+ * multi-table writes stay in SQL functions (`client.rpc`).
13
+ *
14
+ * @version 0.1.0
15
+ * @since 0.5.0
16
+ * @author AMBROISE PARK Consulting
17
+ */
18
+ import type { SupabaseClient } from '@supabase/supabase-js';
19
+ import type { AnyEntity, InferEntityRow } from '@donotdev/core/server';
20
+ /** Filter operators, same vocabulary as the list handler and the client CRUD. */
21
+ export type EntityStoreOperator = '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
22
+ /** `[field, operator, value]`; field is an entity field name. */
23
+ export type EntityStoreCondition = readonly [string, EntityStoreOperator, unknown];
24
+ /** Read options of {@link EntityStore.list} and {@link EntityStore.find}. */
25
+ export interface EntityStoreQuery {
26
+ where?: readonly EntityStoreCondition[];
27
+ /** Entity fields to read (default: every column). `id` is always read. */
28
+ select?: readonly string[];
29
+ orderBy?: readonly (readonly [string, 'asc' | 'desc'])[];
30
+ limit?: number;
31
+ /** Also return draft / deleted rows (default false). */
32
+ includeHidden?: boolean;
33
+ }
34
+ /** Values written to a row: any subset of its fields; `null` clears a nullable column. */
35
+ export type EntityStoreValues<Row> = {
36
+ [K in keyof Row]?: Row[K] | null;
37
+ };
38
+ /** Entity-aware CRUD bound to one entity and one Supabase client. */
39
+ export interface EntityStore<Row> {
40
+ /** Rows matching the query. */
41
+ list(query?: EntityStoreQuery): Promise<Row[]>;
42
+ /** The single row matching the query, or null; more than one row is an error. */
43
+ find(query: EntityStoreQuery): Promise<Row | null>;
44
+ /** Row by id, or null (hidden rows only with `includeHidden`). */
45
+ get(id: string, options?: Pick<EntityStoreQuery, 'includeHidden' | 'select'>): Promise<Row | null>;
46
+ /** Inserts rows and returns them as stored (database defaults and triggers applied). */
47
+ insert(values: readonly EntityStoreValues<Row>[]): Promise<Row[]>;
48
+ /** Updates the rows matching `where` (hidden rows included) and returns them as stored. */
49
+ update(where: readonly EntityStoreCondition[], patch: EntityStoreValues<Row>): Promise<Row[]>;
50
+ }
51
+ /**
52
+ * Creates an entity-aware CRUD store for server code.
53
+ *
54
+ * @param client - Supabase client the store runs with (service role in Edge Functions)
55
+ * @param entity - Entity from `defineEntity()`; its collection is the table
56
+ * @returns Store whose rows use the entity field names
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { createEntityStore } from '@donotdev/functions/supabase';
61
+ * import { productEntity } from 'entities';
62
+ *
63
+ * const products = createEntityStore(supabaseAdmin, productEntity);
64
+ * // Published products only (draft / deleted hidden by default)
65
+ * const rows = await products.list({ where: [['id', 'in', ids]], select: ['name', 'sku'] });
66
+ * ```
67
+ *
68
+ * @version 0.1.0
69
+ * @since 0.5.0
70
+ */
71
+ export declare function createEntityStore<E extends AnyEntity>(client: SupabaseClient, entity: E): EntityStore<InferEntityRow<E>>;
@@ -13,6 +13,7 @@ export { createSupabaseDeleteEntity } from './delete.js';
13
13
  export { createSupabaseListEntities } from './list.js';
14
14
  export { createSupabaseAggregateEntities } from './aggregate.js';
15
15
  export { createSupabaseBulkEntity } from './bulk.js';
16
+ export { createEntityStore } from './entityStore.js';
16
17
  export type { GetEntityRequest } from './get.js';
17
18
  export type { CreateEntityRequest } from './create.js';
18
19
  export type { UpdateEntityRequest } from './update.js';
@@ -20,3 +21,4 @@ export type { DeleteEntityRequest, ReferenceMetadata } from './delete.js';
20
21
  export type { ListEntityRequest } from './list.js';
21
22
  export type { AggregateEntityRequest } from './aggregate.js';
22
23
  export type { BulkEntityRequest } from './bulk.js';
24
+ export type { EntityStore, EntityStoreCondition, EntityStoreOperator, EntityStoreQuery, EntityStoreValues, } from './entityStore.js';
@@ -1,22 +1,22 @@
1
1
  /**
2
2
  * @fileoverview Supabase Auth Provider for shared billing logic
3
- * @description Maps Supabase Admin auth to the shared `AuthProvider` interface,
3
+ * @description Maps Supabase Admin auth to the core `BillingAuthProvider` interface,
4
4
  * bridging `app_metadata` ↔ `customClaims`.
5
5
  *
6
6
  * @version 0.1.0
7
7
  * @since 0.5.0
8
8
  * @author AMBROISE PARK Consulting
9
9
  */
10
- import type { AuthProvider } from '../../shared/billing/helpers/updateUserSubscription.js';
11
10
  import type { SupabaseClient } from '@supabase/supabase-js';
11
+ import type { BillingAuthProvider } from '@donotdev/core/server';
12
12
  /**
13
- * Create an AuthProvider backed by Supabase Admin.
13
+ * Create a BillingAuthProvider backed by Supabase Admin.
14
14
  * `app_metadata` is used as the equivalent of Firebase custom claims.
15
15
  *
16
16
  * @param supabaseAdmin - Supabase client created with the service role key
17
- * @returns AuthProvider compatible with shared billing helpers
17
+ * @returns BillingAuthProvider compatible with shared billing helpers
18
18
  *
19
19
  * @version 0.1.0
20
20
  * @since 0.5.0
21
21
  */
22
- export declare function createSupabaseAuthProvider(supabaseAdmin: SupabaseClient): AuthProvider;
22
+ export declare function createSupabaseAuthProvider(supabaseAdmin: SupabaseClient): BillingAuthProvider;
@@ -18,6 +18,12 @@ export { createGetCustomClaims } from './auth/getCustomClaims.js';
18
18
  export { createRemoveCustomClaims } from './auth/removeCustomClaims.js';
19
19
  export { createGetUserAuthStatus } from './auth/getUserAuthStatus.js';
20
20
  export { createCheckoutSession } from './billing/createCheckoutSession.js';
21
+ export { createStripeWebhook } from './billing/stripeWebhook.js';
22
+ export { createSupabaseIdempotencyStore, ReservationLostError, WEBHOOK_EVENTS_SQL, } from '../shared/billing/idempotency.js';
23
+ export type { IdempotencyStore, ReservationResult, } from '../shared/billing/idempotency.js';
24
+ export { createCheckoutAlgorithm } from '../shared/billing/createCheckout.js';
25
+ export type { StripeSessionProvider } from '../shared/billing/createCheckout.js';
26
+ export { STRIPE_API_VERSION_PIN } from '../shared/billing/apiVersion.js';
21
27
  export { createCancelSubscription } from './billing/cancelSubscription.js';
22
28
  export { createChangePlan } from './billing/changePlan.js';
23
29
  export { createCustomerPortal } from './billing/createCustomerPortal.js';
@@ -28,9 +34,11 @@ export { resolveModelForTier } from '../shared/ai/resolveModelTier.js';
28
34
  export { classifyAIError, mapClassifiedToHTTP, } from '../shared/ai/classifyAIError.js';
29
35
  export type { AIErrorCode, ClassifiedAIError, } from '../shared/ai/classifyAIError.js';
30
36
  export { createEmailFunction } from './email/createEmailFunction.js';
31
- export { createSupabaseGetEntity, createSupabaseCreateEntity, createSupabaseUpdateEntity, createSupabaseDeleteEntity, createSupabaseListEntities, createSupabaseAggregateEntities, } from './crud/index.js';
37
+ export { handleEmailRequest, createResendProvider, } from '../shared/email/index.js';
38
+ export type { EmailProviderAdapter } from '../shared/email/index.js';
39
+ export { createSupabaseGetEntity, createSupabaseCreateEntity, createSupabaseUpdateEntity, createSupabaseDeleteEntity, createSupabaseListEntities, createSupabaseAggregateEntities, createEntityStore, } from './crud/index.js';
32
40
  export { createSupabaseCrudFunctions } from './registerCrudFunctions.js';
33
- export type { GetEntityRequest, CreateEntityRequest, UpdateEntityRequest, DeleteEntityRequest, ListEntityRequest, AggregateEntityRequest, ReferenceMetadata, } from './crud/index.js';
41
+ export type { GetEntityRequest, CreateEntityRequest, UpdateEntityRequest, DeleteEntityRequest, ListEntityRequest, AggregateEntityRequest, ReferenceMetadata, EntityStore, EntityStoreCondition, EntityStoreOperator, EntityStoreQuery, EntityStoreValues, } from './crud/index.js';
34
42
  export { checkIdempotency, storeIdempotency, cleanupExpiredIdempotency, } from './utils/idempotency.js';
35
43
  export { checkRateLimitWithPostgres, DEFAULT_RATE_LIMITS, } from './utils/rateLimiter.js';
36
44
  export type { RateLimitConfig, RateLimitResult } from './utils/rateLimiter.js';