@donotdev/functions 0.0.20 → 0.1.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 (303) hide show
  1. package/LICENSE.md +3 -3
  2. package/guidelines/FUNCTIONS.md +9 -0
  3. package/guidelines/VERCEL.md +260 -0
  4. package/lib/firebase/auth/getCustomClaims.d.ts +2 -2
  5. package/lib/firebase/auth/getUserAuthStatus.d.ts +2 -2
  6. package/lib/firebase/auth/index.d.ts +1 -1
  7. package/lib/firebase/auth/removeCustomClaims.d.ts +2 -2
  8. package/lib/firebase/auth/setCustomClaims.d.ts +2 -2
  9. package/lib/firebase/baseFunction.d.ts +1 -1
  10. package/lib/firebase/billing/cancelSubscription.d.ts +1 -1
  11. package/lib/firebase/billing/changePlan.d.ts +1 -1
  12. package/lib/firebase/billing/createCheckoutSession.d.ts +10 -13
  13. package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
  14. package/lib/firebase/billing/index.d.ts +1 -1
  15. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +2 -2
  16. package/lib/firebase/config/constants.d.ts +4 -4
  17. package/lib/firebase/config/index.d.ts +1 -1
  18. package/lib/firebase/crud/aggregate.d.ts +2 -2
  19. package/lib/firebase/crud/delete.d.ts +1 -1
  20. package/lib/firebase/crud/get.d.ts +1 -1
  21. package/lib/firebase/crud/index.d.ts +1 -1
  22. package/lib/firebase/crud/update.d.ts +1 -1
  23. package/lib/firebase/helpers/githubAccessHelper.d.ts +3 -3
  24. package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +2 -2
  25. package/lib/firebase/helpers/index.d.ts +1 -1
  26. package/lib/firebase/index.d.ts +1 -1
  27. package/lib/firebase/index.js +3 -3
  28. package/lib/firebase/index.js.map +4 -4
  29. package/lib/firebase/oauth/disconnect.d.ts +1 -1
  30. package/lib/firebase/oauth/exchangeToken.d.ts +1 -1
  31. package/lib/firebase/oauth/getConnections.d.ts +1 -1
  32. package/lib/firebase/oauth/githubAccess.d.ts +6 -6
  33. package/lib/firebase/oauth/index.d.ts +1 -1
  34. package/lib/firebase/oauth/refreshToken.d.ts +1 -1
  35. package/lib/firebase/scheduled/index.d.ts +1 -1
  36. package/lib/shared/ai/classifyAIError.d.ts +35 -0
  37. package/lib/shared/ai/costTracker.d.ts +20 -0
  38. package/lib/shared/ai/createAIRoute.d.ts +20 -0
  39. package/lib/shared/ai/index.d.ts +6 -0
  40. package/lib/shared/ai/resolveModelTier.d.ts +14 -0
  41. package/lib/shared/billing/createCheckout.d.ts +11 -5
  42. package/lib/shared/billing/helpers/index.d.ts +1 -1
  43. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +3 -3
  44. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +4 -4
  45. package/lib/shared/billing/idempotency.d.ts +2 -2
  46. package/lib/shared/billing/index.d.ts +1 -1
  47. package/lib/shared/billing/webhookHandler.d.ts +1 -1
  48. package/lib/shared/email/createEmailRoute.d.ts +30 -0
  49. package/lib/shared/email/index.d.ts +3 -0
  50. package/lib/shared/email/provider.d.ts +30 -0
  51. package/lib/shared/email/resendProvider.d.ts +22 -0
  52. package/lib/shared/errorHandling.d.ts +1 -1
  53. package/lib/shared/firebase.d.ts +7 -7
  54. package/lib/shared/github.d.ts +16 -11
  55. package/lib/shared/index.d.ts +3 -1
  56. package/lib/shared/index.js +4 -3
  57. package/lib/shared/index.js.map +4 -4
  58. package/lib/shared/logger.d.ts +8 -6
  59. package/lib/shared/metadata.d.ts +3 -3
  60. package/lib/shared/oauth/exchangeToken.d.ts +3 -2
  61. package/lib/shared/oauth/grantAccess.d.ts +3 -2
  62. package/lib/shared/oauth/index.d.ts +1 -1
  63. package/lib/shared/schema.d.ts +2 -2
  64. package/lib/shared/utils/detectFirestore.d.ts +3 -3
  65. package/lib/shared/utils/external/date.d.ts +2 -2
  66. package/lib/shared/utils/external/index.d.ts +1 -1
  67. package/lib/shared/utils/external/references.d.ts +1 -1
  68. package/lib/shared/utils/external/subscription.d.ts +5 -5
  69. package/lib/shared/utils/firebaseHelpers.d.ts +2 -2
  70. package/lib/shared/utils/functionWrapper.d.ts +4 -4
  71. package/lib/shared/utils/index.d.ts +1 -1
  72. package/lib/shared/utils/internal/auth.d.ts +4 -4
  73. package/lib/shared/utils/internal/idempotency.d.ts +3 -2
  74. package/lib/shared/utils/internal/index.d.ts +1 -1
  75. package/lib/shared/utils/internal/monitoring.d.ts +7 -7
  76. package/lib/shared/utils/internal/rateLimiter.d.ts +5 -5
  77. package/lib/shared/utils/internal/validation.d.ts +4 -4
  78. package/lib/shared/utils/schemaValidation.d.ts +6 -6
  79. package/lib/shared/utils/validation.d.ts +9 -9
  80. package/lib/shared/utils/vercelHelpers.d.ts +2 -2
  81. package/lib/shared/utils.d.ts +19 -19
  82. package/lib/shared/validation.d.ts +2 -2
  83. package/lib/supabase/ai/createAIFunction.d.ts +30 -0
  84. package/lib/supabase/auth/deleteAccount.d.ts +1 -1
  85. package/lib/supabase/auth/getCustomClaims.d.ts +1 -1
  86. package/lib/supabase/auth/getUserAuthStatus.d.ts +1 -1
  87. package/lib/supabase/auth/removeCustomClaims.d.ts +1 -1
  88. package/lib/supabase/auth/setCustomClaims.d.ts +12 -4
  89. package/lib/supabase/baseFunction.d.ts +2 -2
  90. package/lib/supabase/billing/cancelSubscription.d.ts +1 -1
  91. package/lib/supabase/billing/changePlan.d.ts +2 -2
  92. package/lib/supabase/billing/createCheckoutSession.d.ts +1 -1
  93. package/lib/supabase/billing/createCustomerPortal.d.ts +1 -1
  94. package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +1 -1
  95. package/lib/supabase/crud/aggregate.d.ts +2 -1
  96. package/lib/supabase/crud/create.d.ts +2 -1
  97. package/lib/supabase/crud/delete.d.ts +1 -0
  98. package/lib/supabase/crud/get.d.ts +2 -1
  99. package/lib/supabase/crud/index.d.ts +1 -1
  100. package/lib/supabase/crud/list.d.ts +2 -1
  101. package/lib/supabase/crud/update.d.ts +2 -1
  102. package/lib/supabase/edgeFunction.d.ts +56 -0
  103. package/lib/supabase/email/createEmailFunction.d.ts +31 -0
  104. package/lib/supabase/helpers/authProvider.d.ts +2 -2
  105. package/lib/supabase/index.d.ts +11 -2
  106. package/lib/supabase/index.js +3 -2
  107. package/lib/supabase/index.js.map +4 -4
  108. package/lib/supabase/oauth/disconnect.d.ts +13 -0
  109. package/lib/supabase/oauth/exchangeToken.d.ts +13 -0
  110. package/lib/supabase/oauth/getConnections.d.ts +13 -0
  111. package/lib/supabase/oauth/index.d.ts +12 -0
  112. package/lib/supabase/oauth/refreshToken.d.ts +13 -0
  113. package/lib/supabase/utils/idempotency.d.ts +1 -1
  114. package/lib/supabase/utils/monitoring.d.ts +1 -1
  115. package/lib/supabase/utils/rateLimiter.d.ts +1 -1
  116. package/lib/vercel/api/ai/chat.d.ts +29 -0
  117. package/lib/vercel/api/ai/index.d.ts +1 -0
  118. package/lib/vercel/api/auth/index.d.ts +1 -1
  119. package/lib/vercel/api/billing/cancel.d.ts +1 -1
  120. package/lib/vercel/api/billing/change-plan.d.ts +1 -1
  121. package/lib/vercel/api/billing/create-checkout-session.d.ts +1 -1
  122. package/lib/vercel/api/billing/index.d.ts +1 -1
  123. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +1 -1
  124. package/lib/vercel/api/billing/webhook-handler.d.ts +2 -2
  125. package/lib/vercel/api/config/constants.d.ts +9 -9
  126. package/lib/vercel/api/config/firebase-admin.d.ts +2 -2
  127. package/lib/vercel/api/config/index.d.ts +1 -1
  128. package/lib/vercel/api/crud/index.d.ts +1 -1
  129. package/lib/vercel/api/index.d.ts +2 -1
  130. package/lib/vercel/api/index.js +3 -2
  131. package/lib/vercel/api/index.js.map +4 -4
  132. package/lib/vercel/api/oauth/check-github-access.d.ts +1 -1
  133. package/lib/vercel/api/oauth/grant-github-access.d.ts +1 -1
  134. package/lib/vercel/api/oauth/index.d.ts +1 -1
  135. package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
  136. package/lib/vercel/api/utils/cors.d.ts +4 -4
  137. package/lib/vercel/baseFunction.d.ts +2 -2
  138. package/package.json +38 -5
  139. package/src/firebase/auth/getCustomClaims.ts +3 -3
  140. package/src/firebase/auth/getUserAuthStatus.ts +3 -3
  141. package/src/firebase/auth/index.ts +1 -1
  142. package/src/firebase/auth/removeCustomClaims.ts +3 -3
  143. package/src/firebase/auth/setCustomClaims.ts +70 -69
  144. package/src/firebase/baseFunction.ts +2 -2
  145. package/src/firebase/billing/cancelSubscription.ts +3 -3
  146. package/src/firebase/billing/changePlan.ts +3 -3
  147. package/src/firebase/billing/createCheckoutSession.ts +79 -187
  148. package/src/firebase/billing/createCustomerPortal.ts +1 -1
  149. package/src/firebase/billing/healthCheck.ts +1 -1
  150. package/src/firebase/billing/index.d.ts +11 -11
  151. package/src/firebase/billing/index.ts +1 -1
  152. package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -3
  153. package/src/firebase/billing/webhookHandler.ts +1 -1
  154. package/src/firebase/config/constants.ts +4 -4
  155. package/src/firebase/config/index.ts +1 -1
  156. package/src/firebase/config/secrets.ts +1 -1
  157. package/src/firebase/crud/aggregate.ts +2 -2
  158. package/src/firebase/crud/create.ts +2 -2
  159. package/src/firebase/crud/delete.ts +3 -3
  160. package/src/firebase/crud/get.ts +1 -1
  161. package/src/firebase/crud/index.ts +1 -1
  162. package/src/firebase/crud/list.ts +1 -1
  163. package/src/firebase/crud/update.ts +2 -2
  164. package/src/firebase/helpers/githubAccessHelper.ts +4 -4
  165. package/src/firebase/helpers/githubTeamAccessHelper.ts +3 -3
  166. package/src/firebase/helpers/index.ts +1 -1
  167. package/src/firebase/index.d.ts +9 -9
  168. package/src/firebase/index.ts +1 -1
  169. package/src/firebase/oauth/disconnect.ts +2 -2
  170. package/src/firebase/oauth/exchangeToken.ts +6 -6
  171. package/src/firebase/oauth/getConnections.ts +2 -2
  172. package/src/firebase/oauth/githubAccess.ts +10 -10
  173. package/src/firebase/oauth/index.ts +1 -1
  174. package/src/firebase/oauth/refreshToken.ts +6 -6
  175. package/src/firebase/registerCrudFunctions.ts +1 -1
  176. package/src/firebase/scheduled/checkExpiredSubscriptions.ts +1 -1
  177. package/src/firebase/scheduled/index.ts +1 -1
  178. package/src/shared/__tests__/auth.test.ts +46 -0
  179. package/src/shared/__tests__/errorHandling.test.ts +66 -1
  180. package/src/shared/__tests__/firebase.test.ts +293 -0
  181. package/src/shared/__tests__/internalValidation.test.ts +190 -0
  182. package/src/shared/__tests__/metadata.test.ts +66 -0
  183. package/src/shared/__tests__/schema.test.ts +219 -0
  184. package/src/shared/__tests__/schemaValidation.test.ts +72 -0
  185. package/src/shared/__tests__/subscription.test.ts +45 -0
  186. package/src/shared/__tests__/utils.test.ts +281 -0
  187. package/src/shared/__tests__/validation-env.test.ts +73 -0
  188. package/src/shared/ai/__tests__/costTracker.test.ts +121 -0
  189. package/src/shared/ai/classifyAIError.ts +163 -0
  190. package/src/shared/ai/costTracker.ts +51 -0
  191. package/src/shared/ai/createAIRoute.ts +397 -0
  192. package/src/shared/ai/index.ts +8 -0
  193. package/src/shared/ai/resolveModelTier.ts +58 -0
  194. package/src/shared/billing/__tests__/createCheckout.test.ts +1 -1
  195. package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -1
  196. package/src/shared/billing/createCheckout.ts +156 -11
  197. package/src/shared/billing/helpers/index.ts +1 -1
  198. package/src/shared/billing/helpers/subscriptionManagement.ts +13 -4
  199. package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
  200. package/src/shared/billing/idempotency.ts +9 -4
  201. package/src/shared/billing/index.ts +1 -1
  202. package/src/shared/billing/webhookHandler.ts +7 -7
  203. package/src/shared/email/createEmailRoute.ts +81 -0
  204. package/src/shared/email/index.ts +5 -0
  205. package/src/shared/email/provider.ts +31 -0
  206. package/src/shared/email/resendProvider.ts +56 -0
  207. package/src/shared/errorHandling.ts +12 -6
  208. package/src/shared/firebase.ts +7 -7
  209. package/src/shared/github.ts +49 -11
  210. package/src/shared/index.d.ts +9 -9
  211. package/src/shared/index.ts +3 -1
  212. package/src/shared/logger.ts +10 -8
  213. package/src/shared/metadata.ts +3 -3
  214. package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
  215. package/src/shared/oauth/exchangeToken.ts +3 -2
  216. package/src/shared/oauth/grantAccess.ts +3 -2
  217. package/src/shared/oauth/index.ts +1 -1
  218. package/src/shared/schema.ts +4 -4
  219. package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
  220. package/src/shared/utils/detectFirestore.ts +3 -3
  221. package/src/shared/utils/external/date.ts +5 -5
  222. package/src/shared/utils/external/index.ts +1 -1
  223. package/src/shared/utils/external/references.ts +2 -2
  224. package/src/shared/utils/external/subscription.ts +5 -5
  225. package/src/shared/utils/firebaseHelpers.ts +3 -3
  226. package/src/shared/utils/functionWrapper.ts +4 -4
  227. package/src/shared/utils/index.ts +1 -1
  228. package/src/shared/utils/internal/auth.ts +7 -7
  229. package/src/shared/utils/internal/firebase.ts +1 -1
  230. package/src/shared/utils/internal/idempotency.ts +4 -3
  231. package/src/shared/utils/internal/index.ts +1 -1
  232. package/src/shared/utils/internal/monitoring.ts +8 -8
  233. package/src/shared/utils/internal/rateLimiter.ts +12 -9
  234. package/src/shared/utils/internal/validation.ts +5 -5
  235. package/src/shared/utils/schemaValidation.ts +6 -6
  236. package/src/shared/utils/validation.ts +10 -10
  237. package/src/shared/utils/vercelHelpers.ts +3 -3
  238. package/src/shared/utils.ts +19 -19
  239. package/src/shared/validation.ts +3 -3
  240. package/src/supabase/ai/createAIFunction.ts +75 -0
  241. package/src/supabase/auth/deleteAccount.ts +2 -2
  242. package/src/supabase/auth/getCustomClaims.ts +2 -2
  243. package/src/supabase/auth/getUserAuthStatus.ts +2 -2
  244. package/src/supabase/auth/removeCustomClaims.ts +38 -2
  245. package/src/supabase/auth/setCustomClaims.ts +66 -5
  246. package/src/supabase/baseFunction.ts +29 -5
  247. package/src/supabase/billing/cancelSubscription.ts +2 -2
  248. package/src/supabase/billing/changePlan.ts +8 -3
  249. package/src/supabase/billing/createCheckoutSession.ts +18 -4
  250. package/src/supabase/billing/createCustomerPortal.ts +2 -2
  251. package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
  252. package/src/supabase/crud/aggregate.ts +2 -1
  253. package/src/supabase/crud/create.ts +2 -1
  254. package/src/supabase/crud/delete.ts +2 -1
  255. package/src/supabase/crud/get.ts +2 -1
  256. package/src/supabase/crud/index.ts +1 -1
  257. package/src/supabase/crud/list.ts +2 -1
  258. package/src/supabase/crud/update.ts +2 -1
  259. package/src/supabase/edgeFunction.ts +195 -0
  260. package/src/supabase/email/createEmailFunction.ts +75 -0
  261. package/src/supabase/helpers/authProvider.ts +2 -2
  262. package/src/supabase/index.ts +22 -2
  263. package/src/supabase/oauth/disconnect.ts +104 -0
  264. package/src/supabase/oauth/exchangeToken.ts +183 -0
  265. package/src/supabase/oauth/getConnections.ts +85 -0
  266. package/src/supabase/oauth/index.ts +15 -0
  267. package/src/supabase/oauth/refreshToken.ts +130 -0
  268. package/src/supabase/registerCrudFunctions.ts +30 -42
  269. package/src/supabase/utils/idempotency.ts +7 -3
  270. package/src/supabase/utils/monitoring.ts +1 -1
  271. package/src/supabase/utils/rateLimiter.ts +1 -1
  272. package/src/vercel/api/ai/chat.ts +77 -0
  273. package/src/vercel/api/ai/index.ts +1 -0
  274. package/src/vercel/api/auth/get-custom-claims.ts +1 -1
  275. package/src/vercel/api/auth/get-user-auth-status.ts +1 -1
  276. package/src/vercel/api/auth/index.ts +1 -1
  277. package/src/vercel/api/auth/remove-custom-claims.ts +1 -1
  278. package/src/vercel/api/auth/set-custom-claims.ts +2 -4
  279. package/src/vercel/api/billing/cancel.ts +3 -3
  280. package/src/vercel/api/billing/change-plan.ts +3 -3
  281. package/src/vercel/api/billing/create-checkout-session.ts +30 -7
  282. package/src/vercel/api/billing/customer-portal.ts +1 -1
  283. package/src/vercel/api/billing/index.ts +1 -1
  284. package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
  285. package/src/vercel/api/billing/webhook-handler.ts +11 -4
  286. package/src/vercel/api/config/constants.ts +9 -9
  287. package/src/vercel/api/config/firebase-admin.ts +3 -3
  288. package/src/vercel/api/config/index.ts +1 -1
  289. package/src/vercel/api/crud/create.ts +1 -1
  290. package/src/vercel/api/crud/delete.ts +1 -1
  291. package/src/vercel/api/crud/get.ts +1 -1
  292. package/src/vercel/api/crud/index.ts +1 -1
  293. package/src/vercel/api/crud/list.ts +1 -1
  294. package/src/vercel/api/crud/update.ts +1 -1
  295. package/src/vercel/api/index.d.ts +1 -1
  296. package/src/vercel/api/index.ts +2 -1
  297. package/src/vercel/api/oauth/check-github-access.ts +3 -3
  298. package/src/vercel/api/oauth/exchange-token.ts +25 -2
  299. package/src/vercel/api/oauth/grant-github-access.ts +3 -3
  300. package/src/vercel/api/oauth/index.ts +1 -1
  301. package/src/vercel/api/oauth/revoke-github-access.ts +1 -1
  302. package/src/vercel/api/utils/cors.ts +10 -4
  303. package/src/vercel/baseFunction.ts +2 -2
@@ -3,7 +3,7 @@ import type * as v from 'valibot';
3
3
  /**
4
4
  * Creates a Vercel API handler with schema validation
5
5
  *
6
- * @version 0.0.1
6
+ * @version 0.1.0
7
7
  * @since 0.0.1
8
8
  * @author AMBROISE PARK Consulting
9
9
  */
@@ -11,7 +11,7 @@ export declare function createVercelHandler<TRequest, TResponse>(defaultSchema:
11
11
  /**
12
12
  * Creates a Vercel API handler with method validation and schema validation
13
13
  *
14
- * @version 0.0.1
14
+ * @version 0.1.0
15
15
  * @since 0.0.1
16
16
  * @author AMBROISE PARK Consulting
17
17
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Shared utilities for Firebase and Vercel functions
3
3
  * @description Common utilities that can be used by both Firebase and Vercel function implementations
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
@@ -14,7 +14,7 @@ export { DoNotDevError };
14
14
  * Get Firestore instance using @donotdev/firebase/server
15
15
  * Provider handles initialization and caching
16
16
  *
17
- * @version 0.0.1
17
+ * @version 0.1.0
18
18
  * @since 0.0.1
19
19
  * @author AMBROISE PARK Consulting
20
20
  */
@@ -23,7 +23,7 @@ export declare function getFirestore(): FirebaseFirestore.Firestore;
23
23
  * Get Auth instance using @donotdev/firebase/server
24
24
  * Provider handles initialization and caching
25
25
  *
26
- * @version 0.0.1
26
+ * @version 0.1.0
27
27
  * @since 0.0.1
28
28
  * @author AMBROISE PARK Consulting
29
29
  */
@@ -36,7 +36,7 @@ export declare function initStripe(apiKey: string): Stripe;
36
36
  /**
37
37
  * Get Stripe instance with lazy initialization
38
38
  *
39
- * @version 0.0.1
39
+ * @version 0.1.0
40
40
  * @since 0.0.1
41
41
  * @author AMBROISE PARK Consulting
42
42
  */
@@ -44,7 +44,7 @@ export declare function getStripe(): Stripe;
44
44
  /**
45
45
  * Lazy-initialized Stripe instance proxy
46
46
  *
47
- * @version 0.0.1
47
+ * @version 0.1.0
48
48
  * @since 0.0.1
49
49
  * @author AMBROISE PARK Consulting
50
50
  */
@@ -59,7 +59,7 @@ export declare const stripe: Stripe;
59
59
  * @param auth - Firebase callable request auth context (object with `.uid`)
60
60
  * @returns The authenticated user's uid
61
61
  *
62
- * @version 0.0.3
62
+ * @version 0.1.0
63
63
  * @since 0.0.1
64
64
  * @author AMBROISE PARK Consulting
65
65
  */
@@ -76,7 +76,7 @@ export declare function assertAuthenticated(auth: any): string;
76
76
  * @param auth - Firebase auth context from callable function
77
77
  * @returns UserRole for visibility filtering
78
78
  *
79
- * @version 0.0.1
79
+ * @version 0.1.0
80
80
  * @since 0.0.1
81
81
  * @author AMBROISE PARK Consulting
82
82
  */
@@ -84,7 +84,7 @@ export declare function getUserRole(auth: any): UserRole;
84
84
  /**
85
85
  * Validates that required Stripe environment variables are set
86
86
  *
87
- * @version 0.0.1
87
+ * @version 0.1.0
88
88
  * @since 0.0.1
89
89
  * @author AMBROISE PARK Consulting
90
90
  */
@@ -92,7 +92,7 @@ export declare function validateStripeEnvironment(): void;
92
92
  /**
93
93
  * Creates a standardized success response
94
94
  *
95
- * @version 0.0.1
95
+ * @version 0.1.0
96
96
  * @since 0.0.1
97
97
  * @author AMBROISE PARK Consulting
98
98
  */
@@ -103,7 +103,7 @@ export declare function createSuccessResponse<T>(data: T): {
103
103
  /**
104
104
  * Creates a standardized error response
105
105
  *
106
- * @version 0.0.1
106
+ * @version 0.1.0
107
107
  * @since 0.0.1
108
108
  * @author AMBROISE PARK Consulting
109
109
  */
@@ -133,7 +133,7 @@ export declare function createErrorResponse(error: unknown): {
133
133
  * (which requires an authProvider) instead.
134
134
  *
135
135
  * @deprecated Import `updateUserSubscription` from `@donotdev/functions/shared/billing/helpers/updateUserSubscription`.
136
- * @version 0.0.2
136
+ * @version 0.1.0
137
137
  * @since 0.0.1
138
138
  * @author AMBROISE PARK Consulting
139
139
  */
@@ -144,7 +144,7 @@ export declare function updateUserSubscription(_firebaseUid: string, _subscripti
144
144
  * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
145
145
  *
146
146
  * @deprecated Import from `@donotdev/functions/shared/billing/helpers` or implement directly using Firebase Admin SDK / Stripe API.
147
- * @version 0.0.2
147
+ * @version 0.1.0
148
148
  * @since 0.0.1
149
149
  * @author AMBROISE PARK Consulting
150
150
  */
@@ -155,7 +155,7 @@ export declare function getUserSubscription(_firebaseUid: string): Promise<any>;
155
155
  * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
156
156
  *
157
157
  * @deprecated Import `cancelUserSubscription` from `@donotdev/functions/shared/billing/helpers/subscriptionManagement`.
158
- * @version 0.0.2
158
+ * @version 0.1.0
159
159
  * @since 0.0.1
160
160
  * @author AMBROISE PARK Consulting
161
161
  */
@@ -166,7 +166,7 @@ export declare function cancelUserSubscription(_firebaseUid: string, _subscripti
166
166
  * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
167
167
  *
168
168
  * @deprecated Handle via Stripe webhook events. Use `processWebhook` from `@donotdev/functions/shared/billing/webhookHandler`.
169
- * @version 0.0.2
169
+ * @version 0.1.0
170
170
  * @since 0.0.1
171
171
  * @author AMBROISE PARK Consulting
172
172
  */
@@ -178,7 +178,7 @@ export declare function handleSubscriptionCancellation(_firebaseUid: string, _su
178
178
  * @deprecated Import `assertAdmin` from `@donotdev/functions/shared/utils/internal/auth` instead.
179
179
  * This is a thin wrapper that delegates to the canonical provider-agnostic version.
180
180
  *
181
- * @version 0.0.3
181
+ * @version 0.1.0
182
182
  * @since 0.0.1
183
183
  * @author AMBROISE PARK Consulting
184
184
  */
@@ -186,7 +186,7 @@ export declare function assertAdmin(uid: string): Promise<string>;
186
186
  /**
187
187
  * Validates document data
188
188
  *
189
- * @version 0.0.1
189
+ * @version 0.1.0
190
190
  * @since 0.0.1
191
191
  * @author AMBROISE PARK Consulting
192
192
  */
@@ -202,7 +202,7 @@ export declare function validateDocument(data: any, schema?: any): void;
202
202
  * @param name - Collection name to validate
203
203
  * @throws Error if the name is unsafe
204
204
  *
205
- * @version 0.0.1
205
+ * @version 0.1.0
206
206
  * @since 0.0.1
207
207
  * @author AMBROISE PARK Consulting
208
208
  */
@@ -210,7 +210,7 @@ export declare function validateCollectionName(name: string): void;
210
210
  /**
211
211
  * Verifies Firebase auth token
212
212
  *
213
- * @version 0.0.1
213
+ * @version 0.1.0
214
214
  * @since 0.0.1
215
215
  * @author AMBROISE PARK Consulting
216
216
  */
@@ -218,7 +218,7 @@ export declare function verifyFirebaseAuthToken(token: string): Promise<string>;
218
218
  /**
219
219
  * Finds references to a document
220
220
  *
221
- * @version 0.0.1
221
+ * @version 0.1.0
222
222
  * @since 0.0.1
223
223
  * @author AMBROISE PARK Consulting
224
224
  */
@@ -2,14 +2,14 @@
2
2
  * @fileoverview Environment validation utilities
3
3
  * @description Validate required environment variables on module load
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  /**
10
10
  * Validates required environment variables
11
11
  *
12
- * @version 0.0.1
12
+ * @version 0.1.0
13
13
  * @since 0.0.1
14
14
  * @author AMBROISE PARK Consulting
15
15
  */
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview AI Chat - Supabase Edge Function Factory
3
+ * @description Wraps the shared AI route handler for Supabase Edge Functions.
4
+ * Uses Vercel AI SDK via createAIRoute for streaming and non-streaming.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.1.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { AIRouteConfig } from '@donotdev/core/server';
11
+ /**
12
+ * Create a Supabase Edge Function handler for AI chat.
13
+ *
14
+ * @param config - AI route configuration
15
+ * @returns `(req: Request) => Promise<Response>` handler
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // supabase/functions/ai-chat/index.ts
20
+ * import { createAIFunction } from '@donotdev/functions/supabase';
21
+ *
22
+ * const handler = createAIFunction({
23
+ * provider: 'anthropic',
24
+ * model: 'claude-sonnet-4-20250514',
25
+ * cost: { markup: 4.0, monthlyBudgetTokens: 500_000, showCostToUsers: false, displayCurrency: 'eur' },
26
+ * });
27
+ * Deno.serve(handler);
28
+ * ```
29
+ */
30
+ export declare function createAIFunction(config: AIRouteConfig): (req: Request) => Promise<Response>;
@@ -10,7 +10,7 @@
10
10
  * Deno.serve(createDeleteAccount());
11
11
  * ```
12
12
  *
13
- * @version 0.0.1
13
+ * @version 0.1.0
14
14
  * @since 0.5.0
15
15
  */
16
16
  export declare function createDeleteAccount(): (req: Request) => Promise<Response>;
@@ -10,7 +10,7 @@
10
10
  * Deno.serve(createGetCustomClaims());
11
11
  * ```
12
12
  *
13
- * @version 0.0.1
13
+ * @version 0.1.0
14
14
  * @since 0.6.0
15
15
  */
16
16
  export declare function createGetCustomClaims(): (req: Request) => Promise<Response>;
@@ -12,7 +12,7 @@
12
12
  * Deno.serve(createGetUserAuthStatus());
13
13
  * ```
14
14
  *
15
- * @version 0.0.1
15
+ * @version 0.1.0
16
16
  * @since 0.6.0
17
17
  */
18
18
  export declare function createGetUserAuthStatus(): (req: Request) => Promise<Response>;
@@ -10,7 +10,7 @@
10
10
  * Deno.serve(createRemoveCustomClaims());
11
11
  * ```
12
12
  *
13
- * @version 0.0.1
13
+ * @version 0.2.0
14
14
  * @since 0.6.0
15
15
  */
16
16
  export declare function createRemoveCustomClaims(): (req: Request) => Promise<Response>;
@@ -1,18 +1,26 @@
1
+ /** Options for the set-custom-claims edge function factory. */
2
+ export interface SetCustomClaimsOptions {
3
+ /** Explicit allowlist of claim keys users may set on themselves. Required. */
4
+ allowedClaimKeys: string[];
5
+ }
1
6
  /**
2
7
  * Create a Supabase Edge Function handler for setting custom claims (app_metadata).
3
8
  *
4
- * Merges provided claims into the user's existing app_metadata.
9
+ * Consumers MUST specify which claim keys are self-assignable.
10
+ * The framework enforces a blocklist as a safety net even if the consumer
11
+ * accidentally includes a privilege key.
5
12
  *
13
+ * @param options - Configuration with allowedClaimKeys
6
14
  * @returns `(req: Request) => Promise<Response>` handler
7
15
  *
8
16
  * @example
9
17
  * ```typescript
10
18
  * // supabase/functions/set-custom-claims/index.ts
11
19
  * import { createSetCustomClaims } from '@donotdev/functions/supabase';
12
- * Deno.serve(createSetCustomClaims());
20
+ * Deno.serve(createSetCustomClaims({ allowedClaimKeys: ['theme', 'locale'] }));
13
21
  * ```
14
22
  *
15
- * @version 0.0.1
23
+ * @version 0.2.0
16
24
  * @since 0.6.0
17
25
  */
18
- export declare function createSetCustomClaims(): (req: Request) => Promise<Response>;
26
+ export declare function createSetCustomClaims(options: SetCustomClaimsOptions): (req: Request) => Promise<Response>;
@@ -4,7 +4,7 @@ import type { SupabaseClient } from '@supabase/supabase-js';
4
4
  /**
5
5
  * Context passed to Supabase Edge Function business logic
6
6
  *
7
- * @version 0.0.1
7
+ * @version 0.1.0
8
8
  * @since 0.5.0
9
9
  */
10
10
  export interface SupabaseHandlerContext {
@@ -37,7 +37,7 @@ export interface SupabaseHandlerContext {
37
37
  * }, 'admin');
38
38
  * ```
39
39
  *
40
- * @version 0.0.1
40
+ * @version 0.1.0
41
41
  * @since 0.5.0
42
42
  */
43
43
  export declare function createSupabaseHandler<TReq, TRes>(operationName: string, schema: v.BaseSchema<unknown, TReq, v.BaseIssue<unknown>>, handler: (data: TReq, context: SupabaseHandlerContext) => Promise<TRes>, requiredRole?: UserRole, security?: SecurityContext): (req: Request) => Promise<Response>;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns `(req: Request) => Promise<Response>` handler
5
5
  *
6
- * @version 0.0.1
6
+ * @version 0.1.0
7
7
  * @since 0.5.0
8
8
  */
9
9
  export declare function createCancelSubscription(): (req: Request) => Promise<Response>;
@@ -1,11 +1,11 @@
1
- import type { StripeBackConfig } from '@donotdev/core/server';
1
+ import { type StripeBackConfig } from '@donotdev/core/server';
2
2
  /**
3
3
  * Create a Supabase Edge Function handler for plan changes.
4
4
  *
5
5
  * @param billingConfig - Billing configuration with product definitions
6
6
  * @returns `(req: Request) => Promise<Response>` handler
7
7
  *
8
- * @version 0.0.1
8
+ * @version 0.1.0
9
9
  * @since 0.5.0
10
10
  */
11
11
  export declare function createChangePlan(billingConfig: StripeBackConfig): (req: Request) => Promise<Response>;
@@ -5,7 +5,7 @@ import type { StripeBackConfig } from '@donotdev/core/server';
5
5
  * @param billingConfig - Billing configuration with product definitions
6
6
  * @returns `(req: Request) => Promise<Response>` handler
7
7
  *
8
- * @version 0.0.1
8
+ * @version 0.1.0
9
9
  * @since 0.5.0
10
10
  */
11
11
  export declare function createCheckoutSession(billingConfig: StripeBackConfig): (req: Request) => Promise<Response>;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns `(req: Request) => Promise<Response>` handler
5
5
  *
6
- * @version 0.0.1
6
+ * @version 0.1.0
7
7
  * @since 0.5.0
8
8
  */
9
9
  export declare function createCustomerPortal(): (req: Request) => Promise<Response>;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns `(req: Request) => Promise<Response>` handler
5
5
  *
6
- * @version 0.0.1
6
+ * @version 0.1.0
7
7
  * @since 0.5.0
8
8
  */
9
9
  export declare function createRefreshSubscriptionStatus(): (req: Request) => Promise<Response>;
@@ -2,12 +2,13 @@
2
2
  * @fileoverview Generic handler to aggregate entities in Supabase.
3
3
  * @description Provides aggregate operations (COUNT, SUM, AVG, MIN, MAX, GROUP BY) for PostgreSQL.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  import * as v from 'valibot';
10
10
  import type { UserRole } from '@donotdev/core/server';
11
+ /** Request payload for aggregate operations (COUNT, SUM, AVG, MIN, MAX) on entities. */
11
12
  export type AggregateEntityRequest = {
12
13
  where?: Array<[string, any, any]>;
13
14
  aggregate: {
@@ -2,12 +2,13 @@
2
2
  * @fileoverview Generic handler to create an entity in Supabase.
3
3
  * @description Provides a reusable implementation for creating documents in PostgreSQL with validation.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  import * as v from 'valibot';
10
10
  import type { UserRole } from '@donotdev/core/server';
11
+ /** Request payload for creating an entity with optional idempotency. */
11
12
  export type CreateEntityRequest = {
12
13
  payload: Record<string, any>;
13
14
  idempotencyKey?: string;
@@ -1,4 +1,5 @@
1
1
  import type { UserRole } from '@donotdev/core/server';
2
+ /** Request payload for deleting a single entity by ID. */
2
3
  export type DeleteEntityRequest = {
3
4
  id: string;
4
5
  };
@@ -2,12 +2,13 @@
2
2
  * @fileoverview Generic handler to retrieve a single entity from Supabase.
3
3
  * @description Provides a reusable implementation for retrieving documents from PostgreSQL with visibility filtering.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  import * as v from 'valibot';
10
10
  import type { EntityOwnershipConfig, UserRole } from '@donotdev/core/server';
11
+ /** Request payload for retrieving a single entity by ID. */
11
12
  export type GetEntityRequest = {
12
13
  id: string;
13
14
  };
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Supabase CRUD handlers barrel export
3
3
  * @description Exports all Supabase CRUD handler factories
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
@@ -2,12 +2,13 @@
2
2
  * @fileoverview Generic handler to list entities from Supabase with pagination, filtering, and sorting.
3
3
  * @description Provides a reusable implementation for listing documents from PostgreSQL with advanced query capabilities.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  import * as v from 'valibot';
10
10
  import type { EntityOwnershipConfig, UserRole } from '@donotdev/core/server';
11
+ /** Request payload for listing entities with filtering, sorting, and pagination. */
11
12
  export interface ListEntityRequest {
12
13
  where?: Array<[string, any, any]>;
13
14
  orderBy?: Array<[string, 'asc' | 'desc']>;
@@ -2,12 +2,13 @@
2
2
  * @fileoverview Generic handler to update an entity in Supabase.
3
3
  * @description Provides a reusable implementation for updating documents in PostgreSQL with validation.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  import * as v from 'valibot';
10
10
  import type { UserRole } from '@donotdev/core/server';
11
+ /** Request payload for updating an entity by ID with optional idempotency. */
11
12
  export type UpdateEntityRequest = {
12
13
  id: string;
13
14
  payload: Record<string, any>;
@@ -0,0 +1,56 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ /**
3
+ * Context passed to edge function handlers.
4
+ *
5
+ * @version 0.1.0
6
+ * @since 0.6.0
7
+ */
8
+ export interface EdgeFunctionContext {
9
+ /** Authenticated user (null if no valid JWT or requireAuth=false) */
10
+ user: {
11
+ id: string;
12
+ email?: string;
13
+ } | null;
14
+ /** Admin client (service role, bypasses RLS) - always available */
15
+ supabaseAdmin: SupabaseClient;
16
+ /** User-scoped client (RLS) - null if no valid JWT */
17
+ userClient: SupabaseClient | null;
18
+ /** JSON response with CORS headers */
19
+ json: (data: unknown, status?: number) => Response;
20
+ /** JSON error response: { error: message } with CORS headers */
21
+ error: (message: string, status?: number) => Response;
22
+ /** Raw response with CORS headers (for structured payloads) */
23
+ respond: (data: unknown, status: number) => Response;
24
+ }
25
+ /** Configuration options for edge function creation. */
26
+ export interface EdgeFunctionOptions {
27
+ /** Require JWT auth - returns 401 if missing/invalid (default: true) */
28
+ requireAuth?: boolean;
29
+ /** Extra CORS allowed headers (e.g., 'stripe-signature', 'x-build-secret') */
30
+ extraHeaders?: string[];
31
+ }
32
+ /**
33
+ * Create a Supabase Edge Function handler with CORS, optional auth, and response helpers.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Auth required (default)
38
+ * Deno.serve(createEdgeFunction(async (req, ctx) => {
39
+ * const body = await req.json();
40
+ * return ctx.json({ result: 'ok' });
41
+ * }));
42
+ *
43
+ * // No auth (public endpoint)
44
+ * Deno.serve(createEdgeFunction(async (req, ctx) => {
45
+ * return ctx.json({ public: true });
46
+ * }, { requireAuth: false }));
47
+ *
48
+ * // Custom auth (webhook)
49
+ * Deno.serve(createEdgeFunction(async (req, ctx) => {
50
+ * const sig = req.headers.get('stripe-signature');
51
+ * if (!sig) return ctx.error('Missing signature', 401);
52
+ * return ctx.json({ received: true });
53
+ * }, { requireAuth: false, extraHeaders: ['stripe-signature'] }));
54
+ * ```
55
+ */
56
+ export declare function createEdgeFunction(handler: (req: Request, ctx: EdgeFunctionContext) => Promise<Response>, options?: EdgeFunctionOptions): (req: Request) => Promise<Response>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @fileoverview Email Send - Supabase Edge Function Factory
3
+ * @description Wraps the shared email handler for Supabase Edge Functions.
4
+ * Resolves Resend provider from env, adds auth context.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.1.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { EmailRouteConfig } from '@donotdev/core/server';
11
+ /**
12
+ * Create a Supabase Edge Function handler for sending emails.
13
+ * Requires RESEND_API_KEY environment variable.
14
+ *
15
+ * @param config - Email route configuration (templates, defaultFrom)
16
+ * @returns `(req: Request) => Promise<Response>` handler
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // supabase/functions/send-email/index.ts
21
+ * import { createEmailFunction } from '@donotdev/functions/supabase';
22
+ *
23
+ * const handler = createEmailFunction({
24
+ * provider: 'resend',
25
+ * defaultFrom: 'Frabled <noreply@frabled.com>',
26
+ * templates: { 'order-confirmation': orderConfirmationTemplate },
27
+ * });
28
+ * Deno.serve(handler);
29
+ * ```
30
+ */
31
+ export declare function createEmailFunction(config: EmailRouteConfig): (req: Request) => Promise<Response>;
@@ -3,7 +3,7 @@
3
3
  * @description Maps Supabase Admin auth to the shared `AuthProvider` interface,
4
4
  * bridging `app_metadata` ↔ `customClaims`.
5
5
  *
6
- * @version 0.0.1
6
+ * @version 0.1.0
7
7
  * @since 0.5.0
8
8
  * @author AMBROISE PARK Consulting
9
9
  */
@@ -16,7 +16,7 @@ import type { SupabaseClient } from '@supabase/supabase-js';
16
16
  * @param supabaseAdmin - Supabase client created with the service role key
17
17
  * @returns AuthProvider compatible with shared billing helpers
18
18
  *
19
- * @version 0.0.1
19
+ * @version 0.1.0
20
20
  * @since 0.5.0
21
21
  */
22
22
  export declare function createSupabaseAuthProvider(supabaseAdmin: SupabaseClient): AuthProvider;
@@ -1,16 +1,19 @@
1
1
  /**
2
2
  * @fileoverview Supabase Edge Functions barrel exports
3
- * @description All Supabase Edge Function handlers for auth and billing.
3
+ * @description All Supabase Edge Function handlers for auth, billing, and OAuth.
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.1.0
6
6
  * @since 0.5.0
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  export { createSupabaseHandler } from './baseFunction.js';
10
10
  export type { SupabaseHandlerContext } from './baseFunction.js';
11
+ export { createEdgeFunction } from './edgeFunction.js';
12
+ export type { EdgeFunctionContext, EdgeFunctionOptions } from './edgeFunction.js';
11
13
  export { createSupabaseAuthProvider } from './helpers/authProvider.js';
12
14
  export { createDeleteAccount } from './auth/deleteAccount.js';
13
15
  export { createSetCustomClaims } from './auth/setCustomClaims.js';
16
+ export type { SetCustomClaimsOptions } from './auth/setCustomClaims.js';
14
17
  export { createGetCustomClaims } from './auth/getCustomClaims.js';
15
18
  export { createRemoveCustomClaims } from './auth/removeCustomClaims.js';
16
19
  export { createGetUserAuthStatus } from './auth/getUserAuthStatus.js';
@@ -19,6 +22,12 @@ export { createCancelSubscription } from './billing/cancelSubscription.js';
19
22
  export { createChangePlan } from './billing/changePlan.js';
20
23
  export { createCustomerPortal } from './billing/createCustomerPortal.js';
21
24
  export { createRefreshSubscriptionStatus } from './billing/refreshSubscriptionStatus.js';
25
+ export { createExchangeToken, createDisconnect, createRefreshToken, createGetConnections, } from './oauth/index.js';
26
+ export { createAIFunction } from './ai/createAIFunction.js';
27
+ export { resolveModelForTier } from '../shared/ai/resolveModelTier.js';
28
+ export { classifyAIError, mapClassifiedToHTTP } from '../shared/ai/classifyAIError.js';
29
+ export type { AIErrorCode, ClassifiedAIError } from '../shared/ai/classifyAIError.js';
30
+ export { createEmailFunction } from './email/createEmailFunction.js';
22
31
  export { createSupabaseGetEntity, createSupabaseCreateEntity, createSupabaseUpdateEntity, createSupabaseDeleteEntity, createSupabaseListEntities, createSupabaseAggregateEntities, } from './crud/index.js';
23
32
  export { createSupabaseCrudFunctions } from './registerCrudFunctions.js';
24
33
  export type { GetEntityRequest, CreateEntityRequest, UpdateEntityRequest, DeleteEntityRequest, ListEntityRequest, AggregateEntityRequest, ReferenceMetadata, } from './crud/index.js';