@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
@@ -2,7 +2,7 @@ import type { OAuthPartnerId, OAuthPurpose } from '@donotdev/core/server';
2
2
  /**
3
3
  * Disconnect a provider
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
  */
@@ -2,7 +2,7 @@ import { type ExchangeTokenRequest } from '@donotdev/core/server';
2
2
  /**
3
3
  * Exchange OAuth authorization code for access token
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
  */
@@ -2,7 +2,7 @@ import type { OAuthPurpose } from '@donotdev/core/server';
2
2
  /**
3
3
  * Get a user's OAuth connections
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
  */
@@ -5,7 +5,7 @@ import type { CallableFunction } from 'firebase-functions/v2/https';
5
5
  /**
6
6
  * Grant GitHub repository access to a user
7
7
  *
8
- * @version 0.0.1
8
+ * @version 0.1.0
9
9
  * @since 0.0.1
10
10
  * @author AMBROISE PARK Consulting
11
11
  */
@@ -13,7 +13,7 @@ export declare const grantGitHubAccess: CallableFunction<GrantGitHubAccessReques
13
13
  /**
14
14
  * Grant GitHub repository access with custom validation schema
15
15
  *
16
- * @version 0.0.1
16
+ * @version 0.1.0
17
17
  * @since 0.0.1
18
18
  * @author AMBROISE PARK Consulting
19
19
  */
@@ -31,7 +31,7 @@ export declare function grantGitHubAccessWithSchema(request: CallableRequest<Gra
31
31
  /**
32
32
  * Revoke GitHub repository access from a user
33
33
  *
34
- * @version 0.0.1
34
+ * @version 0.1.0
35
35
  * @since 0.0.1
36
36
  * @author AMBROISE PARK Consulting
37
37
  */
@@ -39,7 +39,7 @@ export declare const revokeGitHubAccess: CallableFunction<RevokeGitHubAccessRequ
39
39
  /**
40
40
  * Revoke GitHub repository access with custom validation schema
41
41
  *
42
- * @version 0.0.1
42
+ * @version 0.1.0
43
43
  * @since 0.0.1
44
44
  * @author AMBROISE PARK Consulting
45
45
  */
@@ -56,7 +56,7 @@ export declare function revokeGitHubAccessWithSchema(request: CallableRequest<Re
56
56
  /**
57
57
  * Check GitHub repository access for a user
58
58
  *
59
- * @version 0.0.1
59
+ * @version 0.1.0
60
60
  * @since 0.0.1
61
61
  * @author AMBROISE PARK Consulting
62
62
  */
@@ -64,7 +64,7 @@ export declare const checkGitHubAccess: CallableFunction<CheckGitHubAccessReques
64
64
  /**
65
65
  * Check GitHub repository access with custom validation schema
66
66
  *
67
- * @version 0.0.1
67
+ * @version 0.1.0
68
68
  * @since 0.0.1
69
69
  * @author AMBROISE PARK Consulting
70
70
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Firebase OAuth functions barrel exports
3
3
  * @description Centralized exports for Firebase OAuth functions
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
  */
@@ -2,7 +2,7 @@ import { type OAuthRefreshRequest } from '@donotdev/core/server';
2
2
  /**
3
3
  * Refresh an OAuth token
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
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Firebase scheduled functions barrel exports
3
3
  * @description Centralized exports for Firebase scheduled functions
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
  */
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview AI Error Classifier
3
+ * @description Classifies Anthropic API errors into actionable categories
4
+ * for structured error responses in edge functions.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.6.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ /** Actionable error category for AI provider failures. */
11
+ export type AIErrorCode = 'rate_limited' | 'overloaded' | 'auth_error' | 'credits_exhausted' | 'network' | 'internal';
12
+ /** Result of classifying an AI provider error with retry and severity metadata. */
13
+ export interface ClassifiedAIError {
14
+ code: AIErrorCode;
15
+ retryable: boolean;
16
+ retryAfterMs?: number;
17
+ severity: 'transient' | 'critical';
18
+ }
19
+ /**
20
+ * Classify an error from an Anthropic API call into an actionable category.
21
+ *
22
+ * | HTTP/Error | Category | Retryable | Severity |
23
+ * |------------------|--------------------|-----------|------------|
24
+ * | 429 | rate_limited | yes | transient |
25
+ * | 529 / 503 | overloaded | yes | transient |
26
+ * | 401 | auth_error | no | critical |
27
+ * | 402 / credits | credits_exhausted | no | critical |
28
+ * | Network/timeout | network | yes | transient |
29
+ * | Other 5xx | internal | no | critical |
30
+ */
31
+ export declare function classifyAIError(err: unknown): ClassifiedAIError;
32
+ /**
33
+ * Map a classified error code to an HTTP status for the edge function response.
34
+ */
35
+ export declare function mapClassifiedToHTTP(code: AIErrorCode): number;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @fileoverview Server-Side Cost Calculator
3
+ * @description Calculate per-request AI costs using SSOT pricing from `@donotdev/core`.
4
+ * Cost records are written async by platform wrappers (Supabase, Vercel, Firebase).
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.1.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { AICostResult, AIUsage } from '@donotdev/core/server';
11
+ /**
12
+ * Calculate cost from token usage for a given model.
13
+ *
14
+ * @param usage - Token usage counts
15
+ * @param model - Model ID (must exist in AI_TOKEN_PRICING)
16
+ * @param markup - Markup multiplier (default: 4.0)
17
+ * @returns Cost breakdown with provider and billed amounts
18
+ * @throws Error if model is not in pricing table
19
+ */
20
+ export declare function calculateCost(usage: AIUsage, model: string, markup?: number): AICostResult;
@@ -0,0 +1,20 @@
1
+ import type { AIChatRequest, AICostRecord, AIRouteConfig } from '@donotdev/core/server';
2
+ /** Per-request options passed to the AI route handler. */
3
+ export interface AIRouteOptions {
4
+ /** Authenticated user ID */
5
+ userId: string;
6
+ /** Request ID for cost tracking */
7
+ requestId?: string;
8
+ /** Callback to persist cost record (platform-specific) */
9
+ onCostRecord?: (record: AICostRecord) => Promise<void>;
10
+ }
11
+ /**
12
+ * Handle an AI chat request using Vercel AI SDK.
13
+ * Supports both streaming (returns SSE Response) and non-streaming (returns JSON).
14
+ *
15
+ * @param request - Validated AI chat request
16
+ * @param config - Route configuration
17
+ * @param options - Per-request options (userId, cost callback)
18
+ * @returns Response (SSE stream or JSON)
19
+ */
20
+ export declare function handleAIRequest(request: AIChatRequest, config: AIRouteConfig, options: AIRouteOptions): Promise<Response>;
@@ -0,0 +1,6 @@
1
+ export { handleAIRequest } from './createAIRoute.js';
2
+ export type { AIRouteOptions } from './createAIRoute.js';
3
+ export { calculateCost } from './costTracker.js';
4
+ export { resolveModelForTier } from './resolveModelTier.js';
5
+ export { classifyAIError, mapClassifiedToHTTP } from './classifyAIError.js';
6
+ export type { AIErrorCode, ClassifiedAIError } from './classifyAIError.js';
@@ -0,0 +1,14 @@
1
+ import type { AITierId } from '@donotdev/core/server';
2
+ /**
3
+ * Resolve the AI model ID for a given tier.
4
+ *
5
+ * Resolution chain (first non-empty wins):
6
+ * 1. `AI_MODEL_<FUNCTION_NAME>` env var (per-function override)
7
+ * 2. `AI_TIER_<TIER>` env var (per-tier override)
8
+ * 3. `AI_TIERS.<TIER>.defaultModel` (static SSOT from constants)
9
+ *
10
+ * @param tier - The tier ID ('fast', 'standard', 'premium')
11
+ * @param functionName - Optional function name for per-function env var lookup
12
+ * @returns The resolved model ID string
13
+ */
14
+ export declare function resolveModelForTier(tier: AITierId, functionName?: string): string;
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Create Checkout Session Algorithm
3
3
  * @description Platform-agnostic algorithm for creating Stripe checkout sessions
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
  */
@@ -10,13 +10,19 @@ import type { CreateCheckoutSessionRequest, CreateCheckoutSessionResponse, Strip
10
10
  /**
11
11
  * Provider interface for Stripe checkout operations
12
12
  *
13
- * @version 0.0.1
13
+ * @version 0.1.0
14
14
  * @since 0.0.1
15
15
  * @author AMBROISE PARK Consulting
16
16
  */
17
17
  export interface StripeCheckoutProvider {
18
18
  createCheckoutSession(params: {
19
- priceId: string;
19
+ priceId?: string;
20
+ /** Amount in cents (dynamic pricing mode) */
21
+ unitAmount?: number;
22
+ /** Product name for Stripe checkout (dynamic pricing mode) */
23
+ productName?: string;
24
+ /** Currency code, defaults to 'eur' */
25
+ currency?: string;
20
26
  customerEmail?: string;
21
27
  metadata: Record<string, string>;
22
28
  allowPromotionCodes: boolean;
@@ -31,7 +37,7 @@ export interface StripeCheckoutProvider {
31
37
  /**
32
38
  * Provider interface for authentication operations
33
39
  *
34
- * @version 0.0.1
40
+ * @version 0.1.0
35
41
  * @since 0.0.1
36
42
  * @author AMBROISE PARK Consulting
37
43
  */
@@ -43,7 +49,7 @@ export interface AuthCheckoutProvider {
43
49
  /**
44
50
  * Create checkout session algorithm
45
51
  *
46
- * @version 0.0.1
52
+ * @version 0.2.0
47
53
  * @since 0.0.1
48
54
  * @author AMBROISE PARK Consulting
49
55
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Billing helpers barrel exports
3
3
  * @description Centralized exports for billing helper functions
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
  */
@@ -2,7 +2,7 @@ import { type AuthProvider } from './updateUserSubscription.js';
2
2
  /**
3
3
  * Cancel user subscription at period end
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
  */
@@ -13,7 +13,7 @@ export declare function cancelUserSubscription(userId: string, authProvider: Aut
13
13
  /**
14
14
  * Change user subscription plan
15
15
  *
16
- * @version 0.0.1
16
+ * @version 0.1.0
17
17
  * @since 0.0.1
18
18
  * @author AMBROISE PARK Consulting
19
19
  */
@@ -25,7 +25,7 @@ export declare function changeUserPlan(userId: string, newPriceId: string, billi
25
25
  /**
26
26
  * Create Stripe Customer Portal session
27
27
  *
28
- * @version 0.0.1
28
+ * @version 0.1.0
29
29
  * @since 0.0.1
30
30
  * @author AMBROISE PARK Consulting
31
31
  */
@@ -2,14 +2,14 @@
2
2
  * @fileoverview User subscription update utilities
3
3
  * @description Functions for updating user subscription data
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
  * Subscription data structure
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
  */
@@ -24,7 +24,7 @@ export interface SubscriptionData {
24
24
  /**
25
25
  * Platform-agnostic auth provider interface
26
26
  *
27
- * @version 0.0.1
27
+ * @version 0.1.0
28
28
  * @since 0.0.1
29
29
  * @author AMBROISE PARK Consulting
30
30
  */
@@ -38,7 +38,7 @@ export interface AuthProvider {
38
38
  * Platform-agnostic subscription update using dependency injection
39
39
  * Works on Firebase Functions, Vercel, AWS Lambda, etc.
40
40
  *
41
- * @version 0.0.1
41
+ * @version 0.1.0
42
42
  * @since 0.0.1
43
43
  * @author AMBROISE PARK Consulting
44
44
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Idempotency store interface
3
3
  *
4
- * @version 0.0.1
4
+ * @version 0.1.0
5
5
  * @since 0.0.1
6
6
  * @author AMBROISE PARK Consulting
7
7
  */
@@ -15,7 +15,7 @@ export declare function createIdempotencyStore(): IdempotencyStore;
15
15
  /**
16
16
  * Reset cached store (for testing only)
17
17
  *
18
- * @version 0.0.1
18
+ * @version 0.1.0
19
19
  * @since 0.0.1
20
20
  * @author AMBROISE PARK Consulting
21
21
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Billing utilities barrel exports
3
3
  * @description Centralized exports for billing-related functions
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
  */
@@ -23,7 +23,7 @@ export type UpdateSubscriptionFn = (userId: string, data: SubscriptionData, auth
23
23
  * @param billingConfig - Billing configuration
24
24
  * @param updateSubscription - Function to update user subscription
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
  */
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview Email Route Handler
3
+ * @description Platform-agnostic handler for email send requests.
4
+ * Validates request, resolves template, renders with locale, sends via provider.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.1.0
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { EmailRouteConfig, SendEmailRequest, SendEmailResponse } from '@donotdev/core/server';
11
+ import type { EmailProviderAdapter } from './provider.js';
12
+ /**
13
+ * Handle an email send request.
14
+ * Validates input, resolves the template from the registry, renders with locale, and sends.
15
+ *
16
+ * @param request - Email send request (templateId, to, data, locale)
17
+ * @param config - Email route configuration (provider, templates, defaultFrom)
18
+ * @param provider - Email provider adapter (Resend, etc.)
19
+ * @returns Send result with success status and messageId
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const result = await handleEmailRequest(
24
+ * { templateId: 'order-confirmation', to: 'user@example.com', data: { orderId: '123' }, locale: 'fr' },
25
+ * emailConfig,
26
+ * resendProvider
27
+ * );
28
+ * ```
29
+ */
30
+ export declare function handleEmailRequest(request: SendEmailRequest, config: EmailRouteConfig, provider: EmailProviderAdapter): Promise<SendEmailResponse>;
@@ -0,0 +1,3 @@
1
+ export { handleEmailRequest } from './createEmailRoute.js';
2
+ export type { EmailProviderAdapter } from './provider.js';
3
+ export { createResendProvider } from './resendProvider.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview Email Provider Adapter Interface
3
+ * @description Abstract interface for email sending. Providers implement this.
4
+ *
5
+ * @version 0.1.0
6
+ * @since 0.1.0
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ /**
10
+ * Email provider adapter interface.
11
+ * Each provider (Resend, SES, etc.) implements this single method.
12
+ */
13
+ export interface EmailProviderAdapter {
14
+ /**
15
+ * Send an email via the provider.
16
+ *
17
+ * @param params - Email parameters
18
+ * @returns Provider message ID for tracking
19
+ * @throws On provider error (network, auth, etc.)
20
+ */
21
+ send(params: {
22
+ from: string;
23
+ to: string;
24
+ subject: string;
25
+ html: string;
26
+ replyTo?: string;
27
+ }): Promise<{
28
+ messageId: string;
29
+ }>;
30
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Resend Email Provider
3
+ * @description Zero-dependency Resend implementation using raw fetch.
4
+ *
5
+ * @version 0.1.0
6
+ * @since 0.1.0
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import type { EmailProviderAdapter } from './provider.js';
10
+ /**
11
+ * Create a Resend email provider adapter.
12
+ *
13
+ * @param apiKey - Resend API key
14
+ * @returns EmailProviderAdapter implementation
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const provider = createResendProvider(Deno.env.get('RESEND_API_KEY')!);
19
+ * await provider.send({ from: 'noreply@app.com', to: 'user@example.com', subject: 'Hello', html: '<p>Hi</p>' });
20
+ * ```
21
+ */
22
+ export declare function createResendProvider(apiKey: string): EmailProviderAdapter;
@@ -7,7 +7,7 @@ export { DoNotDevError };
7
7
  * @param error - The error to handle
8
8
  * @throws DoNotDevError always
9
9
  *
10
- * @version 0.0.2
10
+ * @version 0.1.0
11
11
  * @since 0.0.1
12
12
  * @author AMBROISE PARK Consulting
13
13
  */
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Firebase data transformation utilities for functions
3
3
  * @description Server-safe functions for converting data between Firebase and application formats
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
  */
@@ -12,7 +12,7 @@ import type { FirestoreTimestamp } from '@donotdev/core/server';
12
12
  * @param date - The Date object to convert
13
13
  * @returns A representation of the timestamp
14
14
  *
15
- * @version 0.0.1
15
+ * @version 0.1.0
16
16
  * @since 0.0.1
17
17
  * @author AMBROISE PARK Consulting
18
18
  */
@@ -23,7 +23,7 @@ export declare function createTimestamp(date: Date): FirestoreTimestamp;
23
23
  * @returns The Firestore Timestamp
24
24
  * @throws Error if the date is invalid
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
  */
@@ -33,7 +33,7 @@ export declare function toTimestamp(date: string | Date): FirestoreTimestamp;
33
33
  * @param timestamp - The Firestore Timestamp
34
34
  * @returns The ISO string representation
35
35
  *
36
- * @version 0.0.1
36
+ * @version 0.1.0
37
37
  * @since 0.0.1
38
38
  * @author AMBROISE PARK Consulting
39
39
  */
@@ -43,7 +43,7 @@ export declare function toISOString(timestamp: FirestoreTimestamp): string;
43
43
  * @param value - The value to check
44
44
  * @returns True if the value is a Timestamp
45
45
  *
46
- * @version 0.0.1
46
+ * @version 0.1.0
47
47
  * @since 0.0.1
48
48
  * @author AMBROISE PARK Consulting
49
49
  */
@@ -54,7 +54,7 @@ export declare function isTimestamp(value: any): value is FirestoreTimestamp;
54
54
  * @param includeDocumentIds - Whether to include document IDs
55
55
  * @returns The transformed data
56
56
  *
57
- * @version 0.0.1
57
+ * @version 0.1.0
58
58
  * @since 0.0.1
59
59
  * @author AMBROISE PARK Consulting
60
60
  */
@@ -66,7 +66,7 @@ export declare function transformFirestoreData<T = any>(data: T, includeDocument
66
66
  * @param removeFields - Optional array of field names to remove
67
67
  * @returns The prepared data
68
68
  *
69
- * @version 0.0.1
69
+ * @version 0.1.0
70
70
  * @since 0.0.1
71
71
  * @author AMBROISE PARK Consulting
72
72
  */
@@ -2,14 +2,16 @@
2
2
  * @fileoverview GitHub API Service for functions
3
3
  * @description Server-safe GitHub API utilities for repository management
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
+ /** Configuration for authenticating with the GitHub API. */
9
10
  export interface GitHubApiConfig {
10
11
  accessToken: string;
11
12
  baseUrl?: string;
12
13
  }
14
+ /** GitHub user profile returned by the API. */
13
15
  export interface GitHubUser {
14
16
  id: number;
15
17
  login: string;
@@ -17,6 +19,7 @@ export interface GitHubUser {
17
19
  name?: string;
18
20
  avatar_url: string;
19
21
  }
22
+ /** GitHub repository metadata returned by the API. */
20
23
  export interface GitHubRepository {
21
24
  id: number;
22
25
  name: string;
@@ -27,12 +30,14 @@ export interface GitHubRepository {
27
30
  id: number;
28
31
  };
29
32
  }
33
+ /** Request payload for adding a collaborator to a GitHub repository. */
30
34
  export interface AddCollaboratorRequest {
31
35
  owner: string;
32
36
  repo: string;
33
37
  username: string;
34
38
  permission?: 'pull' | 'triage' | 'push' | 'maintain' | 'admin';
35
39
  }
40
+ /** Error response structure from the GitHub API. */
36
41
  export interface GitHubApiError {
37
42
  message: string;
38
43
  documentation_url?: string;
@@ -41,7 +46,7 @@ export interface GitHubApiError {
41
46
  /**
42
47
  * GitHub API Service for server-side operations
43
48
  *
44
- * @version 0.0.1
49
+ * @version 0.1.0
45
50
  * @since 0.0.1
46
51
  * @author AMBROISE PARK Consulting
47
52
  */
@@ -51,7 +56,7 @@ export declare class GitHubApiService {
51
56
  /**
52
57
  * Get the current authenticated user
53
58
  *
54
- * @version 0.0.1
59
+ * @version 0.1.0
55
60
  * @since 0.0.1
56
61
  * @author AMBROISE PARK Consulting
57
62
  */
@@ -59,7 +64,7 @@ export declare class GitHubApiService {
59
64
  /**
60
65
  * Get user repositories
61
66
  *
62
- * @version 0.0.1
67
+ * @version 0.1.0
63
68
  * @since 0.0.1
64
69
  * @author AMBROISE PARK Consulting
65
70
  */
@@ -67,7 +72,7 @@ export declare class GitHubApiService {
67
72
  /**
68
73
  * Add a collaborator to a repository
69
74
  *
70
- * @version 0.0.1
75
+ * @version 0.1.0
71
76
  * @since 0.0.1
72
77
  * @author AMBROISE PARK Consulting
73
78
  */
@@ -76,7 +81,7 @@ export declare class GitHubApiService {
76
81
  * Check if a user is a collaborator on a repository
77
82
  * Uses GitHub's direct API endpoint for efficiency
78
83
  *
79
- * @version 0.0.1
84
+ * @version 0.1.0
80
85
  * @since 0.0.1
81
86
  * @author AMBROISE PARK Consulting
82
87
  */
@@ -84,7 +89,7 @@ export declare class GitHubApiService {
84
89
  /**
85
90
  * Remove a collaborator from a repository
86
91
  *
87
- * @version 0.0.1
92
+ * @version 0.1.0
88
93
  * @since 0.0.1
89
94
  * @author AMBROISE PARK Consulting
90
95
  */
@@ -92,7 +97,7 @@ export declare class GitHubApiService {
92
97
  /**
93
98
  * Add a user to an organization team
94
99
  *
95
- * @version 0.0.1
100
+ * @version 0.1.0
96
101
  * @since 0.0.1
97
102
  * @author AMBROISE PARK Consulting
98
103
  */
@@ -100,7 +105,7 @@ export declare class GitHubApiService {
100
105
  /**
101
106
  * Remove a user from an organization team
102
107
  *
103
- * @version 0.0.1
108
+ * @version 0.1.0
104
109
  * @since 0.0.1
105
110
  * @author AMBROISE PARK Consulting
106
111
  */
@@ -108,7 +113,7 @@ export declare class GitHubApiService {
108
113
  /**
109
114
  * Check if a user is a member of an organization team
110
115
  *
111
- * @version 0.0.1
116
+ * @version 0.1.0
112
117
  * @since 0.0.1
113
118
  * @author AMBROISE PARK Consulting
114
119
  */
@@ -116,7 +121,7 @@ export declare class GitHubApiService {
116
121
  /**
117
122
  * Make an authenticated request to the GitHub API
118
123
  *
119
- * @version 0.0.1
124
+ * @version 0.1.0
120
125
  * @since 0.0.1
121
126
  * @author AMBROISE PARK Consulting
122
127
  */