@donotdev/functions 0.1.1 → 0.1.44
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 +0 -0
- package/guidelines/VERCEL.md +27 -1
- 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 +0 -0
- 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 +0 -0
- package/lib/shared/ai/costTracker.d.ts +0 -0
- package/lib/shared/ai/createAIHandler.d.ts +39 -0
- package/lib/shared/ai/createAIRoute.d.ts +0 -0
- package/lib/shared/ai/index.d.ts +0 -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 +0 -0
- package/lib/shared/ai/utils/parseSSE.d.ts +22 -0
- package/lib/shared/billing/createCheckout.d.ts +0 -0
- 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 +0 -0
- package/lib/shared/email/index.d.ts +0 -0
- package/lib/shared/email/provider.d.ts +0 -0
- package/lib/shared/email/resendProvider.d.ts +0 -0
- package/lib/shared/errorHandling.d.ts +0 -0
- package/lib/shared/firebase.d.ts +0 -0
- package/lib/shared/github.d.ts +0 -0
- package/lib/shared/index.d.ts +1 -0
- package/lib/shared/index.js +4 -4
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +0 -0
- package/lib/shared/metadata.d.ts +6 -6
- package/lib/shared/oauth/exchangeToken.d.ts +0 -0
- package/lib/shared/oauth/grantAccess.d.ts +0 -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 +0 -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 +0 -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 +0 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
- package/lib/supabase/baseFunction.d.ts +0 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
- package/lib/supabase/billing/changePlan.d.ts +0 -0
- 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 +0 -0
- package/lib/supabase/crud/bulk.d.ts +63 -0
- package/lib/supabase/crud/create.d.ts +1 -1
- package/lib/supabase/crud/delete.d.ts +0 -0
- package/lib/supabase/crud/get.d.ts +0 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/crud/list.d.ts +0 -0
- package/lib/supabase/crud/update.d.ts +0 -0
- package/lib/supabase/edgeFunction.d.ts +0 -0
- package/lib/supabase/email/createEmailFunction.d.ts +0 -0
- package/lib/supabase/helpers/authProvider.d.ts +0 -0
- package/lib/supabase/index.d.ts +3 -3
- package/lib/supabase/index.js +3 -3
- 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 +0 -0
- package/lib/vercel/api/ai/index.d.ts +0 -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 +0 -0
- package/lib/vercel/api/index.js +3 -3
- 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 +6 -6
- 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 +5 -1
- 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 +0 -0
- 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 +0 -0
- 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 +25 -13
- package/src/shared/ai/classifyAIError.ts +26 -11
- package/src/shared/ai/costTracker.ts +0 -0
- package/src/shared/ai/createAIRoute.ts +11 -8
- package/src/shared/ai/index.ts +0 -0
- package/src/shared/ai/resolveModelTier.ts +5 -2
- 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 +24 -9
- package/src/shared/billing/helpers/index.ts +0 -0
- package/src/shared/billing/helpers/subscriptionManagement.ts +0 -0
- package/src/shared/billing/helpers/updateUserSubscription.ts +0 -0
- package/src/shared/billing/idempotency.ts +0 -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 +0 -0
- package/src/shared/email/index.ts +0 -0
- package/src/shared/email/provider.ts +0 -0
- package/src/shared/email/resendProvider.ts +1 -1
- package/src/shared/errorHandling.ts +0 -0
- package/src/shared/firebase.ts +0 -0
- package/src/shared/github.ts +0 -0
- package/src/shared/index.d.ts +9 -0
- package/src/shared/index.ts +1 -0
- package/src/shared/logger.ts +0 -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 +0 -0
- package/src/shared/oauth/grantAccess.ts +0 -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 +0 -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 +0 -0
- 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 +0 -0
- package/src/supabase/__tests__/bulk.test.ts +330 -0
- package/src/supabase/ai/createAIFunction.ts +17 -16
- 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 +0 -0
- package/src/supabase/auth/setCustomClaims.ts +1 -3
- package/src/supabase/baseFunction.ts +0 -0
- package/src/supabase/billing/cancelSubscription.ts +0 -0
- package/src/supabase/billing/changePlan.ts +1 -1
- package/src/supabase/billing/createCheckoutSession.ts +0 -0
- package/src/supabase/billing/createCustomerPortal.ts +0 -0
- package/src/supabase/billing/refreshSubscriptionStatus.ts +0 -0
- package/src/supabase/crud/aggregate.ts +0 -0
- package/src/supabase/crud/bulk.ts +244 -0
- package/src/supabase/crud/create.ts +15 -14
- package/src/supabase/crud/delete.ts +0 -0
- package/src/supabase/crud/get.ts +0 -0
- package/src/supabase/crud/index.ts +2 -0
- package/src/supabase/crud/list.ts +0 -0
- package/src/supabase/crud/update.ts +0 -0
- package/src/supabase/edgeFunction.ts +4 -3
- package/src/supabase/email/createEmailFunction.ts +9 -12
- package/src/supabase/helpers/authProvider.ts +0 -0
- package/src/supabase/index.ts +12 -3
- package/src/supabase/oauth/disconnect.ts +1 -2
- package/src/supabase/oauth/exchangeToken.ts +1 -3
- package/src/supabase/oauth/getConnections.ts +1 -4
- package/src/supabase/oauth/index.ts +0 -0
- package/src/supabase/oauth/refreshToken.ts +2 -7
- package/src/supabase/registerCrudFunctions.ts +38 -26
- package/src/supabase/utils/idempotency.ts +0 -0
- 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 +0 -0
- package/src/vercel/api/ai/index.ts +2 -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 +5 -1
- 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 +0 -0
- 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 +0 -0
- package/src/vercel/api/oauth/check-github-access.ts +0 -0
- package/src/vercel/api/oauth/exchange-token.ts +4 -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 +3 -1
- 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
|
|
File without changes
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
package/lib/shared/ai/index.d.ts
CHANGED
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
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';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/shared/firebase.d.ts
CHANGED
|
File without changes
|
package/lib/shared/github.d.ts
CHANGED
|
File without changes
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ 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';
|
|
14
15
|
export * from './ai/index.js';
|
|
15
16
|
export * from './billing/index.js';
|
|
16
17
|
export * from './email/index.js';
|