@donotdev/functions 0.1.0 → 0.1.42
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.
- package/LICENSE.md +21 -242
- package/README.md +4 -4
- package/guidelines/FUNCTIONS.md +9 -0
- package/guidelines/VERCEL.md +286 -0
- package/lib/firebase/auth/getCustomClaims.d.ts +0 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/firebase/auth/index.d.ts +0 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +0 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +0 -0
- package/lib/firebase/baseFunction.d.ts +0 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
- package/lib/firebase/billing/changePlan.d.ts +0 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +10 -13
- package/lib/firebase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/firebase/billing/healthCheck.d.ts +0 -0
- package/lib/firebase/billing/index.d.ts +0 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/firebase/billing/webhookHandler.d.ts +0 -0
- package/lib/firebase/config/constants.d.ts +0 -0
- package/lib/firebase/config/index.d.ts +0 -0
- package/lib/firebase/config/secrets.d.ts +0 -0
- package/lib/firebase/crud/aggregate.d.ts +0 -0
- package/lib/firebase/crud/bulk.d.ts +107 -0
- package/lib/firebase/crud/create.d.ts +1 -1
- package/lib/firebase/crud/delete.d.ts +0 -0
- package/lib/firebase/crud/get.d.ts +0 -0
- package/lib/firebase/crud/index.d.ts +1 -0
- package/lib/firebase/crud/list.d.ts +0 -0
- package/lib/firebase/crud/update.d.ts +0 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/index.d.ts +0 -0
- package/lib/firebase/index.d.ts +0 -0
- package/lib/firebase/index.js +3 -3
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +0 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
- package/lib/firebase/oauth/getConnections.d.ts +0 -0
- package/lib/firebase/oauth/githubAccess.d.ts +0 -0
- package/lib/firebase/oauth/index.d.ts +0 -0
- package/lib/firebase/oauth/refreshToken.d.ts +0 -0
- package/lib/firebase/registerCrudFunctions.d.ts +0 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
- package/lib/firebase/scheduled/index.d.ts +0 -0
- package/lib/shared/ai/classifyAIError.d.ts +35 -0
- package/lib/shared/ai/costTracker.d.ts +20 -0
- package/lib/shared/ai/createAIHandler.d.ts +39 -0
- package/lib/shared/ai/createAIRoute.d.ts +20 -0
- package/lib/shared/ai/index.d.ts +6 -0
- package/lib/shared/ai/providers/anthropic.d.ts +12 -0
- package/lib/shared/ai/providers/google.d.ts +10 -0
- package/lib/shared/ai/providers/index.d.ts +23 -0
- package/lib/shared/ai/providers/openai.d.ts +10 -0
- package/lib/shared/ai/resolveModelTier.d.ts +14 -0
- package/lib/shared/ai/utils/parseSSE.d.ts +22 -0
- package/lib/shared/billing/createCheckout.d.ts +8 -2
- package/lib/shared/billing/helpers/index.d.ts +0 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +0 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +0 -0
- package/lib/shared/billing/idempotency.d.ts +0 -0
- package/lib/shared/billing/index.d.ts +0 -0
- package/lib/shared/billing/webhookHandler.d.ts +0 -0
- package/lib/shared/crud/bulkCore.d.ts +211 -0
- package/lib/shared/crud/index.d.ts +13 -0
- package/lib/shared/email/createEmailRoute.d.ts +30 -0
- package/lib/shared/email/index.d.ts +3 -0
- package/lib/shared/email/provider.d.ts +30 -0
- package/lib/shared/email/resendProvider.d.ts +22 -0
- package/lib/shared/errorHandling.d.ts +0 -0
- package/lib/shared/firebase.d.ts +0 -0
- package/lib/shared/github.d.ts +5 -0
- package/lib/shared/index.d.ts +3 -0
- package/lib/shared/index.js +4 -3
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +2 -0
- package/lib/shared/metadata.d.ts +6 -6
- package/lib/shared/oauth/exchangeToken.d.ts +1 -0
- package/lib/shared/oauth/grantAccess.d.ts +1 -0
- package/lib/shared/oauth/index.d.ts +0 -0
- package/lib/shared/schema.d.ts +0 -0
- package/lib/shared/utils/detectFirestore.d.ts +0 -0
- package/lib/shared/utils/external/date.d.ts +0 -0
- package/lib/shared/utils/external/index.d.ts +0 -0
- package/lib/shared/utils/external/references.d.ts +0 -0
- package/lib/shared/utils/external/subscription.d.ts +0 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
- package/lib/shared/utils/functionWrapper.d.ts +0 -0
- package/lib/shared/utils/index.d.ts +0 -0
- package/lib/shared/utils/internal/auth.d.ts +0 -0
- package/lib/shared/utils/internal/firebase.d.ts +0 -0
- package/lib/shared/utils/internal/idempotency.d.ts +1 -0
- package/lib/shared/utils/internal/index.d.ts +0 -0
- package/lib/shared/utils/internal/monitoring.d.ts +0 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +0 -0
- package/lib/shared/utils/internal/validation.d.ts +0 -0
- package/lib/shared/utils/schemaValidation.d.ts +0 -0
- package/lib/shared/utils/validation.d.ts +0 -0
- package/lib/shared/utils/vercelHelpers.d.ts +0 -0
- package/lib/shared/utils.d.ts +0 -0
- package/lib/shared/validation.d.ts +0 -0
- package/lib/supabase/ai/createAIFunction.d.ts +30 -0
- package/lib/supabase/auth/deleteAccount.d.ts +0 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/supabase/auth/setCustomClaims.d.ts +12 -4
- package/lib/supabase/baseFunction.d.ts +0 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
- package/lib/supabase/billing/changePlan.d.ts +1 -1
- package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/supabase/crud/aggregate.d.ts +1 -0
- package/lib/supabase/crud/bulk.d.ts +63 -0
- package/lib/supabase/crud/create.d.ts +2 -1
- package/lib/supabase/crud/delete.d.ts +1 -0
- package/lib/supabase/crud/get.d.ts +1 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/crud/list.d.ts +1 -0
- package/lib/supabase/crud/update.d.ts +1 -0
- package/lib/supabase/edgeFunction.d.ts +56 -0
- package/lib/supabase/email/createEmailFunction.d.ts +31 -0
- package/lib/supabase/helpers/authProvider.d.ts +0 -0
- package/lib/supabase/index.d.ts +8 -0
- package/lib/supabase/index.js +3 -2
- package/lib/supabase/index.js.map +4 -4
- package/lib/supabase/oauth/disconnect.d.ts +0 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
- package/lib/supabase/oauth/getConnections.d.ts +0 -0
- package/lib/supabase/oauth/index.d.ts +0 -0
- package/lib/supabase/oauth/refreshToken.d.ts +0 -0
- package/lib/supabase/registerCrudFunctions.d.ts +0 -0
- package/lib/supabase/utils/idempotency.d.ts +0 -0
- package/lib/supabase/utils/monitoring.d.ts +0 -0
- package/lib/supabase/utils/rateLimiter.d.ts +0 -0
- package/lib/vercel/api/ai/chat.d.ts +29 -0
- package/lib/vercel/api/ai/index.d.ts +1 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +0 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +0 -0
- package/lib/vercel/api/auth/index.d.ts +0 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +0 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +0 -0
- package/lib/vercel/api/billing/cancel.d.ts +0 -0
- package/lib/vercel/api/billing/change-plan.d.ts +0 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +0 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +0 -0
- package/lib/vercel/api/billing/index.d.ts +0 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +0 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +0 -0
- package/lib/vercel/api/config/constants.d.ts +0 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +0 -0
- package/lib/vercel/api/config/index.d.ts +0 -0
- package/lib/vercel/api/crud/bulk.d.ts +31 -0
- package/lib/vercel/api/crud/create.d.ts +0 -0
- package/lib/vercel/api/crud/delete.d.ts +0 -0
- package/lib/vercel/api/crud/get.d.ts +0 -0
- package/lib/vercel/api/crud/index.d.ts +1 -0
- package/lib/vercel/api/crud/list.d.ts +0 -0
- package/lib/vercel/api/crud/update.d.ts +0 -0
- package/lib/vercel/api/index.d.ts +1 -0
- package/lib/vercel/api/index.js +3 -2
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +0 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +0 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +0 -0
- package/lib/vercel/api/oauth/index.d.ts +0 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +0 -0
- package/lib/vercel/api/utils/cors.d.ts +0 -0
- package/lib/vercel/baseFunction.d.ts +0 -0
- package/package.json +40 -7
- package/src/firebase/auth/getCustomClaims.ts +0 -0
- package/src/firebase/auth/getUserAuthStatus.ts +0 -0
- package/src/firebase/auth/index.ts +0 -0
- package/src/firebase/auth/removeCustomClaims.ts +0 -0
- package/src/firebase/auth/setCustomClaims.ts +0 -0
- package/src/firebase/baseFunction.ts +0 -0
- package/src/firebase/billing/cancelSubscription.ts +0 -0
- package/src/firebase/billing/changePlan.ts +0 -0
- package/src/firebase/billing/createCheckoutSession.ts +82 -186
- package/src/firebase/billing/createCustomerPortal.ts +0 -0
- package/src/firebase/billing/healthCheck.ts +0 -0
- package/src/firebase/billing/index.d.ts +0 -0
- package/src/firebase/billing/index.ts +0 -0
- package/src/firebase/billing/refreshSubscriptionStatus.ts +0 -0
- package/src/firebase/billing/webhookHandler.ts +0 -0
- package/src/firebase/config/constants.ts +0 -0
- package/src/firebase/config/index.ts +0 -0
- package/src/firebase/config/secrets.ts +0 -0
- package/src/firebase/crud/__tests__/bulk.test.ts +322 -0
- package/src/firebase/crud/aggregate.ts +0 -0
- package/src/firebase/crud/bulk.ts +272 -0
- package/src/firebase/crud/create.ts +20 -33
- package/src/firebase/crud/delete.ts +0 -0
- package/src/firebase/crud/get.ts +0 -0
- package/src/firebase/crud/index.ts +1 -0
- package/src/firebase/crud/list.ts +0 -0
- package/src/firebase/crud/update.ts +0 -0
- package/src/firebase/helpers/githubAccessHelper.ts +0 -0
- package/src/firebase/helpers/githubTeamAccessHelper.ts +0 -0
- package/src/firebase/helpers/index.ts +0 -0
- package/src/firebase/index.d.ts +0 -0
- package/src/firebase/index.ts +0 -0
- package/src/firebase/oauth/disconnect.ts +0 -0
- package/src/firebase/oauth/exchangeToken.ts +4 -4
- package/src/firebase/oauth/getConnections.ts +0 -0
- package/src/firebase/oauth/githubAccess.ts +0 -0
- package/src/firebase/oauth/index.ts +0 -0
- package/src/firebase/oauth/refreshToken.ts +4 -4
- package/src/firebase/registerCrudFunctions.ts +13 -0
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +0 -0
- package/src/firebase/scheduled/index.ts +0 -0
- package/src/shared/__tests__/auth.test.ts +0 -0
- package/src/shared/__tests__/bulkCore.test.ts +487 -0
- package/src/shared/__tests__/errorHandling.test.ts +0 -0
- package/src/shared/__tests__/firebase.test.ts +9 -3
- package/src/shared/__tests__/idempotency.test.ts +0 -0
- package/src/shared/__tests__/internalValidation.test.ts +9 -3
- package/src/shared/__tests__/metadata.test.ts +10 -10
- package/src/shared/__tests__/rateLimiter.test.ts +0 -0
- package/src/shared/__tests__/schema.test.ts +0 -0
- package/src/shared/__tests__/schemaValidation.test.ts +0 -0
- package/src/shared/__tests__/subscription.test.ts +0 -0
- package/src/shared/__tests__/utils.test.ts +10 -4
- package/src/shared/__tests__/validation-env.test.ts +9 -3
- package/src/shared/__tests__/validation.test.ts +0 -0
- package/src/shared/ai/__tests__/costTracker.test.ts +133 -0
- package/src/shared/ai/classifyAIError.ts +178 -0
- package/src/shared/ai/costTracker.ts +51 -0
- package/src/shared/ai/createAIRoute.ts +400 -0
- package/src/shared/ai/index.ts +8 -0
- package/src/shared/ai/resolveModelTier.ts +61 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +0 -0
- package/src/shared/billing/__tests__/webhookHandler.test.ts +0 -0
- package/src/shared/billing/createCheckout.ts +168 -8
- package/src/shared/billing/helpers/index.ts +0 -0
- package/src/shared/billing/helpers/subscriptionManagement.ts +9 -0
- package/src/shared/billing/helpers/updateUserSubscription.ts +0 -0
- package/src/shared/billing/idempotency.ts +5 -0
- package/src/shared/billing/index.ts +0 -0
- package/src/shared/billing/webhookHandler.ts +0 -0
- package/src/shared/crud/bulkCore.ts +483 -0
- package/src/shared/crud/index.ts +23 -0
- package/src/shared/email/createEmailRoute.ts +81 -0
- package/src/shared/email/index.ts +5 -0
- package/src/shared/email/provider.ts +31 -0
- package/src/shared/email/resendProvider.ts +56 -0
- package/src/shared/errorHandling.ts +10 -4
- package/src/shared/firebase.ts +0 -0
- package/src/shared/github.ts +38 -0
- package/src/shared/index.d.ts +9 -0
- package/src/shared/index.ts +3 -0
- package/src/shared/logger.ts +2 -0
- package/src/shared/metadata.ts +6 -6
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +0 -0
- package/src/shared/oauth/__tests__/grantAccess.test.ts +0 -0
- package/src/shared/oauth/exchangeToken.ts +1 -0
- package/src/shared/oauth/grantAccess.ts +1 -0
- package/src/shared/oauth/index.ts +0 -0
- package/src/shared/schema.ts +0 -0
- package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -0
- package/src/shared/utils/detectFirestore.ts +0 -0
- package/src/shared/utils/external/date.ts +0 -0
- package/src/shared/utils/external/index.ts +0 -0
- package/src/shared/utils/external/references.ts +0 -0
- package/src/shared/utils/external/subscription.ts +0 -0
- package/src/shared/utils/firebaseHelpers.ts +0 -0
- package/src/shared/utils/functionWrapper.ts +0 -0
- package/src/shared/utils/index.ts +0 -0
- package/src/shared/utils/internal/auth.ts +0 -0
- package/src/shared/utils/internal/firebase.ts +0 -0
- package/src/shared/utils/internal/idempotency.ts +1 -0
- package/src/shared/utils/internal/index.ts +0 -0
- package/src/shared/utils/internal/monitoring.ts +0 -0
- package/src/shared/utils/internal/rateLimiter.ts +6 -3
- package/src/shared/utils/internal/validation.ts +0 -0
- package/src/shared/utils/schemaValidation.ts +0 -0
- package/src/shared/utils/validation.ts +0 -0
- package/src/shared/utils/vercelHelpers.ts +0 -0
- package/src/shared/utils.ts +0 -0
- package/src/shared/validation.ts +1 -1
- package/src/supabase/__tests__/bulk.test.ts +330 -0
- package/src/supabase/ai/createAIFunction.ts +76 -0
- package/src/supabase/auth/deleteAccount.ts +0 -0
- package/src/supabase/auth/getCustomClaims.ts +0 -0
- package/src/supabase/auth/getUserAuthStatus.ts +0 -0
- package/src/supabase/auth/removeCustomClaims.ts +38 -2
- package/src/supabase/auth/setCustomClaims.ts +64 -5
- package/src/supabase/baseFunction.ts +26 -2
- package/src/supabase/billing/cancelSubscription.ts +0 -0
- package/src/supabase/billing/changePlan.ts +6 -1
- package/src/supabase/billing/createCheckoutSession.ts +16 -2
- package/src/supabase/billing/createCustomerPortal.ts +0 -0
- package/src/supabase/billing/refreshSubscriptionStatus.ts +0 -0
- package/src/supabase/crud/aggregate.ts +1 -0
- package/src/supabase/crud/bulk.ts +244 -0
- package/src/supabase/crud/create.ts +16 -14
- package/src/supabase/crud/delete.ts +1 -0
- package/src/supabase/crud/get.ts +1 -0
- package/src/supabase/crud/index.ts +2 -0
- package/src/supabase/crud/list.ts +1 -0
- package/src/supabase/crud/update.ts +1 -0
- package/src/supabase/edgeFunction.ts +196 -0
- package/src/supabase/email/createEmailFunction.ts +72 -0
- package/src/supabase/helpers/authProvider.ts +0 -0
- package/src/supabase/index.ts +21 -0
- package/src/supabase/oauth/disconnect.ts +1 -2
- package/src/supabase/oauth/exchangeToken.ts +39 -10
- package/src/supabase/oauth/getConnections.ts +1 -4
- package/src/supabase/oauth/index.ts +0 -0
- package/src/supabase/oauth/refreshToken.ts +6 -12
- package/src/supabase/registerCrudFunctions.ts +20 -20
- package/src/supabase/utils/idempotency.ts +6 -2
- package/src/supabase/utils/monitoring.ts +0 -0
- package/src/supabase/utils/rateLimiter.ts +0 -0
- package/src/vercel/__tests__/bulk.test.ts +301 -0
- package/src/vercel/api/ai/chat.ts +77 -0
- package/src/vercel/api/ai/index.ts +3 -0
- package/src/vercel/api/auth/get-custom-claims.ts +0 -0
- package/src/vercel/api/auth/get-user-auth-status.ts +0 -0
- package/src/vercel/api/auth/index.ts +0 -0
- package/src/vercel/api/auth/remove-custom-claims.ts +0 -0
- package/src/vercel/api/auth/set-custom-claims.ts +0 -0
- package/src/vercel/api/billing/cancel.ts +0 -0
- package/src/vercel/api/billing/change-plan.ts +0 -0
- package/src/vercel/api/billing/create-checkout-session.ts +31 -4
- package/src/vercel/api/billing/customer-portal.ts +0 -0
- package/src/vercel/api/billing/index.ts +0 -0
- package/src/vercel/api/billing/refresh-subscription-status.ts +0 -0
- package/src/vercel/api/billing/webhook-handler.ts +8 -1
- package/src/vercel/api/config/constants.ts +0 -0
- package/src/vercel/api/config/firebase-admin.ts +0 -0
- package/src/vercel/api/config/index.ts +0 -0
- package/src/vercel/api/crud/bulk.ts +216 -0
- package/src/vercel/api/crud/create.ts +10 -9
- package/src/vercel/api/crud/delete.ts +0 -0
- package/src/vercel/api/crud/get.ts +0 -0
- package/src/vercel/api/crud/index.ts +1 -0
- package/src/vercel/api/crud/list.ts +0 -0
- package/src/vercel/api/crud/update.ts +0 -0
- package/src/vercel/api/index.d.ts +0 -0
- package/src/vercel/api/index.ts +1 -0
- package/src/vercel/api/oauth/check-github-access.ts +0 -0
- package/src/vercel/api/oauth/exchange-token.ts +27 -1
- package/src/vercel/api/oauth/grant-github-access.ts +0 -0
- package/src/vercel/api/oauth/index.ts +0 -0
- package/src/vercel/api/oauth/revoke-github-access.ts +0 -0
- package/src/vercel/api/utils/cors.ts +8 -0
- package/src/vercel/baseFunction.ts +0 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview AI Handler Algorithm
|
|
3
|
+
* @description Platform-agnostic handler for AI chat requests.
|
|
4
|
+
* Validates, rate limits (Upstash), dispatches to provider adapter.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
import type {
|
|
11
|
+
AIChatRequest,
|
|
12
|
+
AIChatResponse,
|
|
13
|
+
AIProviderAdapter,
|
|
14
|
+
AIRateLimitConfig,
|
|
15
|
+
} from '@donotdev/core/server';
|
|
16
|
+
/**
|
|
17
|
+
* Handle an AI chat request (non-streaming).
|
|
18
|
+
* Returns the full response as JSON.
|
|
19
|
+
*/
|
|
20
|
+
export declare function handleAIChatRequest(
|
|
21
|
+
request: AIChatRequest,
|
|
22
|
+
adapter: AIProviderAdapter,
|
|
23
|
+
options: {
|
|
24
|
+
userId: string;
|
|
25
|
+
rateLimitConfig?: AIRateLimitConfig;
|
|
26
|
+
}
|
|
27
|
+
): Promise<AIChatResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Handle an AI chat request (streaming).
|
|
30
|
+
* Returns an SSE Response for direct use in edge functions.
|
|
31
|
+
*/
|
|
32
|
+
export declare function handleAIStreamRequest(
|
|
33
|
+
request: AIChatRequest,
|
|
34
|
+
adapter: AIProviderAdapter,
|
|
35
|
+
options: {
|
|
36
|
+
userId: string;
|
|
37
|
+
rateLimitConfig?: AIRateLimitConfig;
|
|
38
|
+
}
|
|
39
|
+
): Response;
|
|
@@ -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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Anthropic (Claude) Provider Adapter
|
|
3
|
+
* @description fetch-based, no SDK. Normalizes to framework types.
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { AIProviderAdapter } from '@donotdev/core/server';
|
|
10
|
+
export declare function createAnthropicAdapter(
|
|
11
|
+
apiKey: string
|
|
12
|
+
): AIProviderAdapter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Google (Gemini) Provider Adapter
|
|
3
|
+
* @description fetch-based, no SDK. Normalizes to framework types.
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { AIProviderAdapter } from '@donotdev/core/server';
|
|
10
|
+
export declare function createGoogleAdapter(apiKey: string): AIProviderAdapter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview AI Provider Factory
|
|
3
|
+
* @description Creates the right adapter based on provider name.
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { AIProvider, AIProviderAdapter } from '@donotdev/core/server';
|
|
10
|
+
/**
|
|
11
|
+
* Get the provider adapter for the given provider name.
|
|
12
|
+
*
|
|
13
|
+
* @param provider - The AI provider ('anthropic', 'openai', 'google')
|
|
14
|
+
* @param apiKey - The API key for the provider
|
|
15
|
+
* @returns The provider adapter
|
|
16
|
+
*/
|
|
17
|
+
export declare function getProviderAdapter(
|
|
18
|
+
provider: AIProvider,
|
|
19
|
+
apiKey: string
|
|
20
|
+
): AIProviderAdapter;
|
|
21
|
+
export { createAnthropicAdapter } from './anthropic.js';
|
|
22
|
+
export { createOpenAIAdapter } from './openai.js';
|
|
23
|
+
export { createGoogleAdapter } from './google.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenAI (GPT) Provider Adapter
|
|
3
|
+
* @description fetch-based, no SDK. Normalizes to framework types.
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { AIProviderAdapter } from '@donotdev/core/server';
|
|
10
|
+
export declare function createOpenAIAdapter(apiKey: string): AIProviderAdapter;
|
|
@@ -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;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared SSE Stream Parser
|
|
3
|
+
* @description Extracts data lines from an SSE response body.
|
|
4
|
+
* All provider adapters share the same reader loop - only event mapping differs.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.1.0
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Parse SSE data lines from a ReadableStream response body.
|
|
12
|
+
* Yields each parsed JSON object from `data:` lines.
|
|
13
|
+
* Skips `[DONE]` sentinel and malformed JSON.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseSSEStream(
|
|
16
|
+
body: ReadableStream<Uint8Array>
|
|
17
|
+
): AsyncGenerator<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Strip sensitive query parameters from a URL string.
|
|
20
|
+
* Used to prevent API key leakage in error messages.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sanitizeApiUrl(url: string): string;
|
|
@@ -16,7 +16,13 @@ import type { CreateCheckoutSessionRequest, CreateCheckoutSessionResponse, Strip
|
|
|
16
16
|
*/
|
|
17
17
|
export interface StripeCheckoutProvider {
|
|
18
18
|
createCheckoutSession(params: {
|
|
19
|
-
priceId
|
|
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;
|
|
@@ -43,7 +49,7 @@ export interface AuthCheckoutProvider {
|
|
|
43
49
|
/**
|
|
44
50
|
* Create checkout session algorithm
|
|
45
51
|
*
|
|
46
|
-
* @version 0.
|
|
52
|
+
* @version 0.2.0
|
|
47
53
|
* @since 0.0.1
|
|
48
54
|
* @author AMBROISE PARK Consulting
|
|
49
55
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared bulk CRUD orchestration core.
|
|
3
|
+
* @description Target-agnostic orchestrator that owns the bulk policy
|
|
4
|
+
* (wire validation, collision detection, per-bucket ACL, per-row schema
|
|
5
|
+
* validation, id minting, metadata stamping, audit, response validation).
|
|
6
|
+
* Target storage is delegated to a caller-supplied `transact` callback —
|
|
7
|
+
* this lets Firestore admin, Supabase RPC, Vercel firebase-admin, future
|
|
8
|
+
* GraphQL and future REST-CRUD server aids share one source of truth for
|
|
9
|
+
* correctness without pulling any platform-specific dependencies here.
|
|
10
|
+
*
|
|
11
|
+
* This module is server-only (`shared/` but never imported from `client/`
|
|
12
|
+
* or `common/`) and designed to stay portable across Node and Deno — it
|
|
13
|
+
* does not import `fs`, `net`, `firebase-admin`, `supabase-js`, etc.
|
|
14
|
+
*
|
|
15
|
+
* @version 0.1.0
|
|
16
|
+
* @since 0.7.0
|
|
17
|
+
* @author AMBROISE PARK Consulting
|
|
18
|
+
*/
|
|
19
|
+
import * as v from 'valibot';
|
|
20
|
+
import type { BulkRequest, BulkResponse, EntityAccessConfig, UserRole } from '@donotdev/core/server';
|
|
21
|
+
/**
|
|
22
|
+
* Valibot schema alias accepted by {@link executeBulk}. Kept loose (`any` on
|
|
23
|
+
* the parsed output) so callers can pass entity-specific schemas generated by
|
|
24
|
+
* `createSchemas()` without fighting variance.
|
|
25
|
+
*/
|
|
26
|
+
export type BulkRowSchema = v.BaseSchema<unknown, any, v.BaseIssue<unknown>>;
|
|
27
|
+
/**
|
|
28
|
+
* A prepared insert row passed to the caller-supplied `transact` callback.
|
|
29
|
+
* When {@link ExecuteBulkParams.mintInsertId} is provided, `id` is the minted
|
|
30
|
+
* value; otherwise it carries whatever id (if any) the client supplied and
|
|
31
|
+
* the storage layer is expected to mint its own.
|
|
32
|
+
*/
|
|
33
|
+
export interface PreparedInsert {
|
|
34
|
+
/** Minted insert id, or the empty string when the target mints its own. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Fully stamped row ready for storage. */
|
|
37
|
+
row: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A prepared update passed to `transact`.
|
|
41
|
+
*/
|
|
42
|
+
export interface PreparedUpdate {
|
|
43
|
+
/** Target row id. */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Fully stamped patch ready for storage. */
|
|
46
|
+
patch: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Payload handed to the caller-supplied `transact` callback. All three
|
|
50
|
+
* arrays preserve input order and only include non-empty buckets' work.
|
|
51
|
+
*/
|
|
52
|
+
export interface PreparedBulk {
|
|
53
|
+
inserts: PreparedInsert[];
|
|
54
|
+
updates: PreparedUpdate[];
|
|
55
|
+
deletes: string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parameters for {@link executeBulk}.
|
|
59
|
+
*
|
|
60
|
+
* @template TRow - Row type recorded for documentation; runtime is opaque.
|
|
61
|
+
*/
|
|
62
|
+
export interface ExecuteBulkParams<TRow = unknown> {
|
|
63
|
+
/** Collection / table name. Passed through to audit + transact as metadata. */
|
|
64
|
+
collection: string;
|
|
65
|
+
/** Raw wire payload to orchestrate. Parsed with {@link BulkRequestSchema}. */
|
|
66
|
+
ops: BulkRequest;
|
|
67
|
+
/** Valibot schema validating each insert row. */
|
|
68
|
+
createSchema: BulkRowSchema;
|
|
69
|
+
/** Valibot schema validating each insert row when status === 'draft'. */
|
|
70
|
+
draftCreateSchema?: BulkRowSchema;
|
|
71
|
+
/** Valibot schema validating each update patch. */
|
|
72
|
+
updateSchema: BulkRowSchema;
|
|
73
|
+
/** Per-bucket required roles. Missing entries are treated as "no bucket allowed". */
|
|
74
|
+
access: EntityAccessConfig;
|
|
75
|
+
/** Authenticated caller id (for metadata + audit). */
|
|
76
|
+
uid: string;
|
|
77
|
+
/** Caller's role (for per-bucket ACL). */
|
|
78
|
+
userRole: UserRole;
|
|
79
|
+
/**
|
|
80
|
+
* Target-specific storage. Invoked exactly once when the bulk carries at
|
|
81
|
+
* least one op. Must run all three buckets inside one atomic transaction
|
|
82
|
+
* (writeBatch, runTransaction, Postgres RPC wrapping BEGIN/COMMIT, etc.)
|
|
83
|
+
* and return ids per bucket in input order.
|
|
84
|
+
*
|
|
85
|
+
* The returned shape is validated against `BulkResponseSchema` before
|
|
86
|
+
* being returned to the caller.
|
|
87
|
+
*/
|
|
88
|
+
transact: (prepared: PreparedBulk) => Promise<BulkResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* Optional id minting. When provided, every insert is stamped with a
|
|
91
|
+
* freshly-minted id before `transact` runs. When omitted, `id` on each
|
|
92
|
+
* {@link PreparedInsert} is the empty string and the storage layer is
|
|
93
|
+
* expected to mint its own ids (Supabase RPC, GraphQL server, etc.).
|
|
94
|
+
*/
|
|
95
|
+
mintInsertId?: () => string;
|
|
96
|
+
/**
|
|
97
|
+
* Optional hook to stamp platform-specific metadata on every insert row
|
|
98
|
+
* (timestamps, createdById, defaults, field-name mapping). Called once per
|
|
99
|
+
* insert row, in input order.
|
|
100
|
+
*/
|
|
101
|
+
stampInsertMetadata?: (row: Record<string, unknown>, uid: string) => Record<string, unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional hook to stamp platform-specific metadata on every update patch.
|
|
104
|
+
*/
|
|
105
|
+
stampUpdateMetadata?: (patch: Record<string, unknown>, uid: string) => Record<string, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional audit hook. Fires exactly once when `transact` succeeds, with the
|
|
108
|
+
* three op counts. Never fires for empty bulks or rejected validations —
|
|
109
|
+
* matches the "one audit entry" contract from `BULK_CRUD_TODO.md` §4.
|
|
110
|
+
*/
|
|
111
|
+
audit?: (event: string, payload: {
|
|
112
|
+
counts: {
|
|
113
|
+
inserts: number;
|
|
114
|
+
updates: number;
|
|
115
|
+
deletes: number;
|
|
116
|
+
};
|
|
117
|
+
}) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Optional rate-limit bookkeeping key. `executeBulk` does NOT perform
|
|
120
|
+
* rate-limit enforcement itself — the surrounding base-function wrapper
|
|
121
|
+
* already charges one hit at entry. This field is forwarded to `audit()`
|
|
122
|
+
* callers that want to correlate telemetry.
|
|
123
|
+
*/
|
|
124
|
+
rateLimitKey?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Run a bulk CRUD operation against a caller-supplied storage target.
|
|
128
|
+
*
|
|
129
|
+
* **Order of operations** (every step fails loud — no fallbacks, no partial
|
|
130
|
+
* writes):
|
|
131
|
+
*
|
|
132
|
+
* 1. Parse `ops` with {@link BulkRequestSchema}. Invalid shape → throws.
|
|
133
|
+
* 2. Collision detection via {@link detectBulkCollisions}. Collision →
|
|
134
|
+
* throws {@link BulkCollisionError}.
|
|
135
|
+
* 3. Empty short-circuit — if no op carries work, returns a zeroed
|
|
136
|
+
* {@link BulkResponse} without invoking `transact` or `audit`.
|
|
137
|
+
* 4. Per-bucket ACL — for each populated bucket, asserts the caller's role
|
|
138
|
+
* clears the corresponding `access.{create|update|delete}`. A missing
|
|
139
|
+
* role on a populated bucket is a configuration error and is rejected.
|
|
140
|
+
* 5. Per-row validation — inserts against `createSchema`, updates against
|
|
141
|
+
* `updateSchema`. The first failure throws a `DoNotDevError` prefixed
|
|
142
|
+
* with `inserts[i]` or `updates[i]` so callers can pinpoint the row.
|
|
143
|
+
* 6. Id minting — if `mintInsertId` is supplied, every insert gets a fresh
|
|
144
|
+
* id stamped onto its {@link PreparedInsert}. Otherwise `id` is `""` and
|
|
145
|
+
* the storage layer mints its own.
|
|
146
|
+
* 7. Metadata stamping — `stampInsertMetadata` / `stampUpdateMetadata` run
|
|
147
|
+
* per row / per patch if provided.
|
|
148
|
+
* 8. `transact(prepared)` runs exactly once. Must be atomic. Throws
|
|
149
|
+
* propagate unchanged so the caller's error handler can classify them.
|
|
150
|
+
* 9. Response-shape validation via {@link BulkResponseSchema}. A non-conforming
|
|
151
|
+
* target response throws `DoNotDevError(internal)`.
|
|
152
|
+
* 10. `audit()` fires once with the three op counts.
|
|
153
|
+
*
|
|
154
|
+
* **Not this function's job:** rate-limiting, authentication, HTTP status
|
|
155
|
+
* mapping, target-specific connection pooling, retry policy. All of those
|
|
156
|
+
* belong to the surrounding handler wrapper.
|
|
157
|
+
*
|
|
158
|
+
* @template TRow - Row type (documentation only).
|
|
159
|
+
* @param params - See {@link ExecuteBulkParams}.
|
|
160
|
+
* @returns The validated {@link BulkResponse} from the target.
|
|
161
|
+
*
|
|
162
|
+
* @throws {BulkCollisionError} When the payload contains the same id in
|
|
163
|
+
* two mutually-exclusive buckets.
|
|
164
|
+
* @throws {DoNotDevError} `invalid-argument` on wire-schema failure, per-row
|
|
165
|
+
* validation failure, or collision (wrapped for callers that only rethrow
|
|
166
|
+
* `DoNotDevError`).
|
|
167
|
+
* @throws {DoNotDevError} `permission-denied` when the caller's role cannot
|
|
168
|
+
* satisfy a populated bucket's access requirement.
|
|
169
|
+
* @throws {DoNotDevError} `internal` when the `transact` return value fails
|
|
170
|
+
* {@link BulkResponseSchema}.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { executeBulk } from '@donotdev/functions/shared';
|
|
175
|
+
* import { BulkResponseSchema } from '@donotdev/core/server';
|
|
176
|
+
*
|
|
177
|
+
* const response = await executeBulk({
|
|
178
|
+
* collection: 'events',
|
|
179
|
+
* ops: req.body,
|
|
180
|
+
* createSchema,
|
|
181
|
+
* updateSchema,
|
|
182
|
+
* access,
|
|
183
|
+
* uid,
|
|
184
|
+
* userRole,
|
|
185
|
+
* mintInsertId: () => crypto.randomUUID(),
|
|
186
|
+
* stampInsertMetadata: (row, uid) => ({
|
|
187
|
+
* ...row,
|
|
188
|
+
* createdById: uid,
|
|
189
|
+
* createdAt: new Date().toISOString(),
|
|
190
|
+
* }),
|
|
191
|
+
* transact: async ({ inserts, updates, deletes }) => {
|
|
192
|
+
* return db.runTransaction(async (tx) => {
|
|
193
|
+
* for (const { id, row } of inserts) tx.set(col.doc(id), row);
|
|
194
|
+
* for (const { id, patch } of updates) tx.update(col.doc(id), patch);
|
|
195
|
+
* for (const id of deletes) tx.delete(col.doc(id));
|
|
196
|
+
* return {
|
|
197
|
+
* insertedIds: inserts.map((i) => i.id),
|
|
198
|
+
* updatedIds: updates.map((u) => u.id),
|
|
199
|
+
* deletedIds: deletes,
|
|
200
|
+
* };
|
|
201
|
+
* });
|
|
202
|
+
* },
|
|
203
|
+
* audit: (event, { counts }) => logger.info(event, counts),
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @version 0.1.0
|
|
208
|
+
* @since 0.7.0
|
|
209
|
+
* @author AMBROISE PARK Consulting
|
|
210
|
+
*/
|
|
211
|
+
export declare function executeBulk<TRow = unknown>(params: ExecuteBulkParams<TRow>): Promise<BulkResponse>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared CRUD orchestration primitives.
|
|
3
|
+
* @description Barrel for the target-agnostic CRUD cores that Firestore,
|
|
4
|
+
* Supabase, Vercel, GraphQL and REST-CRUD server aids all consume.
|
|
5
|
+
* Exported from `@donotdev/functions/shared` (and the root entry) so
|
|
6
|
+
* out-of-package consumers can build their own adapters without pulling
|
|
7
|
+
* a target-specific SDK.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.1.0
|
|
10
|
+
* @since 0.7.0
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
export { executeBulk, type ExecuteBulkParams, type PreparedBulk, type PreparedInsert, type PreparedUpdate, type BulkRowSchema, } from './bulkCore.js';
|
|
@@ -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,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;
|
|
File without changes
|
package/lib/shared/firebase.d.ts
CHANGED
|
File without changes
|
package/lib/shared/github.d.ts
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
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;
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export * from './github.js';
|
|
|
11
11
|
export * from './metadata.js';
|
|
12
12
|
export * from './schema.js';
|
|
13
13
|
export * from './utils/index.js';
|
|
14
|
+
export * from './crud/index.js';
|
|
15
|
+
export * from './ai/index.js';
|
|
14
16
|
export * from './billing/index.js';
|
|
17
|
+
export * from './email/index.js';
|
|
15
18
|
export * from './oauth/index.js';
|
|
16
19
|
export { createTimestamp, toTimestamp, isTimestamp, transformFirestoreData, prepareForFirestore, } from './firebase.js';
|