@donotdev/functions 0.0.19 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -3
- package/lib/firebase/auth/getCustomClaims.d.ts +25 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
- package/lib/firebase/auth/index.d.ts +12 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
- package/lib/firebase/baseFunction.d.ts +26 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
- package/lib/firebase/billing/changePlan.d.ts +13 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
- package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
- package/lib/firebase/billing/healthCheck.d.ts +5 -0
- package/lib/firebase/billing/index.d.ts +18 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
- package/lib/firebase/billing/webhookHandler.d.ts +6 -0
- package/lib/firebase/config/constants.d.ts +89 -0
- package/lib/firebase/config/index.d.ts +9 -0
- package/lib/firebase/config/secrets.d.ts +15 -0
- package/lib/firebase/crud/aggregate.d.ts +98 -0
- package/lib/firebase/crud/create.d.ts +16 -0
- package/lib/firebase/crud/delete.d.ts +20 -0
- package/lib/firebase/crud/get.d.ts +24 -0
- package/lib/firebase/crud/index.d.ts +14 -0
- package/lib/firebase/crud/list.d.ts +25 -0
- package/lib/firebase/crud/update.d.ts +25 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
- package/lib/firebase/helpers/index.d.ts +10 -0
- package/lib/firebase/index.d.ts +17 -0
- package/lib/firebase/index.js +25 -9110
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +12 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
- package/lib/firebase/oauth/getConnections.d.ts +11 -0
- package/lib/firebase/oauth/githubAccess.d.ts +83 -0
- package/lib/firebase/oauth/index.d.ts +13 -0
- package/lib/firebase/oauth/refreshToken.d.ts +9 -0
- package/lib/firebase/registerCrudFunctions.d.ts +32 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
- package/lib/firebase/scheduled/index.d.ts +9 -0
- package/lib/shared/billing/createCheckout.d.ts +50 -0
- package/lib/shared/billing/helpers/index.d.ts +10 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
- package/lib/shared/billing/idempotency.d.ts +22 -0
- package/lib/shared/billing/index.d.ts +11 -0
- package/lib/shared/billing/webhookHandler.d.ts +37 -0
- package/lib/shared/errorHandling.d.ts +14 -0
- package/lib/shared/firebase.d.ts +73 -0
- package/lib/shared/github.d.ts +128 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +25 -6927
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +133 -0
- package/lib/shared/metadata.d.ts +36 -0
- package/lib/shared/oauth/exchangeToken.d.ts +24 -0
- package/lib/shared/oauth/grantAccess.d.ts +30 -0
- package/lib/shared/oauth/index.d.ts +10 -0
- package/lib/shared/schema.d.ts +56 -0
- package/lib/shared/utils/detectFirestore.d.ts +31 -0
- package/lib/shared/utils/external/date.d.ts +36 -0
- package/lib/shared/utils/external/index.d.ts +11 -0
- package/lib/shared/utils/external/references.d.ts +12 -0
- package/lib/shared/utils/external/subscription.d.ts +41 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
- package/lib/shared/utils/functionWrapper.d.ts +36 -0
- package/lib/shared/utils/index.d.ts +14 -0
- package/lib/shared/utils/internal/auth.d.ts +57 -0
- package/lib/shared/utils/internal/firebase.d.ts +5 -0
- package/lib/shared/utils/internal/idempotency.d.ts +21 -0
- package/lib/shared/utils/internal/index.d.ts +14 -0
- package/lib/shared/utils/internal/monitoring.d.ts +80 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
- package/lib/shared/utils/internal/validation.d.ts +43 -0
- package/lib/shared/utils/schemaValidation.d.ts +60 -0
- package/lib/shared/utils/validation.d.ts +98 -0
- package/lib/shared/utils/vercelHelpers.d.ts +18 -0
- package/lib/shared/utils.d.ts +234 -0
- package/lib/shared/validation.d.ts +16 -0
- package/lib/supabase/auth/deleteAccount.d.ts +16 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
- package/lib/supabase/baseFunction.d.ts +43 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
- package/lib/supabase/billing/changePlan.d.ts +11 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
- package/lib/supabase/crud/aggregate.d.ts +27 -0
- package/lib/supabase/crud/create.d.ts +23 -0
- package/lib/supabase/crud/delete.d.ts +30 -0
- package/lib/supabase/crud/get.d.ts +23 -0
- package/lib/supabase/crud/index.d.ts +20 -0
- package/lib/supabase/crud/list.d.ts +33 -0
- package/lib/supabase/crud/update.d.ts +24 -0
- package/lib/supabase/helpers/authProvider.d.ts +22 -0
- package/lib/supabase/index.d.ts +30 -0
- package/lib/supabase/index.js +23 -0
- package/lib/supabase/index.js.map +7 -0
- package/lib/supabase/oauth/disconnect.d.ts +13 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +13 -0
- package/lib/supabase/oauth/getConnections.d.ts +13 -0
- package/lib/supabase/oauth/index.d.ts +12 -0
- package/lib/supabase/oauth/refreshToken.d.ts +13 -0
- package/lib/supabase/registerCrudFunctions.d.ts +24 -0
- package/lib/supabase/utils/idempotency.d.ts +36 -0
- package/lib/supabase/utils/monitoring.d.ts +59 -0
- package/lib/supabase/utils/rateLimiter.d.ts +56 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
- package/lib/vercel/api/auth/index.d.ts +12 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
- package/lib/vercel/api/billing/cancel.d.ts +10 -0
- package/lib/vercel/api/billing/change-plan.d.ts +11 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
- package/lib/vercel/api/billing/index.d.ts +14 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
- package/lib/vercel/api/config/constants.d.ts +103 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
- package/lib/vercel/api/config/index.d.ts +10 -0
- package/lib/vercel/api/crud/create.d.ts +2 -0
- package/lib/vercel/api/crud/delete.d.ts +2 -0
- package/lib/vercel/api/crud/get.d.ts +2 -0
- package/lib/vercel/api/crud/index.d.ts +13 -0
- package/lib/vercel/api/crud/list.d.ts +2 -0
- package/lib/vercel/api/crud/update.d.ts +2 -0
- package/lib/vercel/api/index.d.ts +13 -0
- package/lib/vercel/api/index.js +22 -4790
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/index.d.ts +12 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
- package/lib/vercel/api/utils/cors.d.ts +49 -0
- package/lib/vercel/baseFunction.d.ts +25 -0
- package/package.json +4 -4
- package/src/firebase/auth/getCustomClaims.ts +3 -3
- package/src/firebase/auth/getUserAuthStatus.ts +3 -3
- package/src/firebase/auth/index.ts +1 -1
- package/src/firebase/auth/removeCustomClaims.ts +3 -3
- package/src/firebase/auth/setCustomClaims.ts +130 -84
- package/src/firebase/baseFunction.ts +2 -2
- package/src/firebase/billing/cancelSubscription.ts +3 -3
- package/src/firebase/billing/changePlan.ts +3 -3
- package/src/firebase/billing/createCheckoutSession.ts +1 -1
- package/src/firebase/billing/createCustomerPortal.ts +1 -1
- package/src/firebase/billing/healthCheck.ts +8 -24
- package/src/firebase/billing/index.d.ts +11 -11
- package/src/firebase/billing/index.ts +1 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -3
- package/src/firebase/billing/webhookHandler.ts +1 -2
- package/src/firebase/config/constants.ts +4 -4
- package/src/firebase/config/index.ts +1 -1
- package/src/firebase/config/secrets.ts +1 -1
- package/src/firebase/crud/aggregate.ts +2 -2
- package/src/firebase/crud/create.ts +19 -4
- package/src/firebase/crud/delete.ts +3 -3
- package/src/firebase/crud/get.ts +1 -1
- package/src/firebase/crud/index.ts +1 -1
- package/src/firebase/crud/list.ts +1 -1
- package/src/firebase/crud/update.ts +2 -2
- package/src/firebase/helpers/githubAccessHelper.ts +4 -4
- package/src/firebase/helpers/githubTeamAccessHelper.ts +3 -3
- package/src/firebase/helpers/index.ts +1 -1
- package/src/firebase/index.d.ts +9 -9
- package/src/firebase/index.ts +1 -1
- package/src/firebase/oauth/disconnect.ts +2 -2
- package/src/firebase/oauth/exchangeToken.ts +7 -7
- package/src/firebase/oauth/getConnections.ts +2 -2
- package/src/firebase/oauth/githubAccess.ts +10 -10
- package/src/firebase/oauth/index.ts +1 -1
- package/src/firebase/oauth/refreshToken.ts +2 -2
- package/src/firebase/registerCrudFunctions.ts +1 -1
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +1 -1
- package/src/firebase/scheduled/index.ts +1 -1
- package/src/shared/__tests__/auth.test.ts +46 -0
- package/src/shared/__tests__/errorHandling.test.ts +66 -1
- package/src/shared/__tests__/firebase.test.ts +293 -0
- package/src/shared/__tests__/internalValidation.test.ts +190 -0
- package/src/shared/__tests__/metadata.test.ts +66 -0
- package/src/shared/__tests__/schema.test.ts +219 -0
- package/src/shared/__tests__/schemaValidation.test.ts +72 -0
- package/src/shared/__tests__/subscription.test.ts +45 -0
- package/src/shared/__tests__/utils.test.ts +281 -0
- package/src/shared/__tests__/validation-env.test.ts +73 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +1 -1
- package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -1
- package/src/shared/billing/createCheckout.ts +10 -5
- package/src/shared/billing/helpers/index.ts +1 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +4 -4
- package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
- package/src/shared/billing/idempotency.ts +4 -4
- package/src/shared/billing/index.ts +1 -1
- package/src/shared/billing/webhookHandler.ts +7 -7
- package/src/shared/errorHandling.ts +2 -2
- package/src/shared/firebase.ts +7 -7
- package/src/shared/github.ts +11 -11
- package/src/shared/index.d.ts +9 -9
- package/src/shared/index.ts +1 -1
- package/src/shared/logger.ts +8 -8
- package/src/shared/metadata.ts +3 -3
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
- package/src/shared/oauth/exchangeToken.ts +2 -2
- package/src/shared/oauth/grantAccess.ts +2 -2
- package/src/shared/oauth/index.ts +1 -1
- package/src/shared/schema.ts +4 -4
- package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
- package/src/shared/utils/detectFirestore.ts +3 -3
- package/src/shared/utils/external/date.ts +5 -5
- package/src/shared/utils/external/index.ts +1 -1
- package/src/shared/utils/external/references.ts +2 -2
- package/src/shared/utils/external/subscription.ts +5 -5
- package/src/shared/utils/firebaseHelpers.ts +3 -3
- package/src/shared/utils/functionWrapper.ts +4 -4
- package/src/shared/utils/index.ts +1 -1
- package/src/shared/utils/internal/auth.ts +7 -7
- package/src/shared/utils/internal/firebase.ts +1 -1
- package/src/shared/utils/internal/idempotency.ts +3 -3
- package/src/shared/utils/internal/index.ts +1 -1
- package/src/shared/utils/internal/monitoring.ts +8 -8
- package/src/shared/utils/internal/rateLimiter.ts +6 -6
- package/src/shared/utils/internal/validation.ts +6 -6
- package/src/shared/utils/schemaValidation.ts +6 -6
- package/src/shared/utils/validation.ts +10 -10
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +19 -19
- package/src/shared/validation.ts +2 -2
- package/src/supabase/auth/deleteAccount.ts +2 -2
- package/src/supabase/auth/getCustomClaims.ts +2 -2
- package/src/supabase/auth/getUserAuthStatus.ts +2 -2
- package/src/supabase/auth/removeCustomClaims.ts +2 -2
- package/src/supabase/auth/setCustomClaims.ts +2 -2
- package/src/supabase/baseFunction.ts +3 -3
- package/src/supabase/billing/cancelSubscription.ts +2 -2
- package/src/supabase/billing/changePlan.ts +2 -2
- package/src/supabase/billing/createCheckoutSession.ts +2 -2
- package/src/supabase/billing/createCustomerPortal.ts +2 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
- package/src/supabase/crud/aggregate.ts +11 -8
- package/src/supabase/crud/create.ts +2 -2
- package/src/supabase/crud/delete.ts +1 -1
- package/src/supabase/crud/get.ts +2 -2
- package/src/supabase/crud/index.ts +1 -1
- package/src/supabase/crud/list.ts +2 -2
- package/src/supabase/crud/update.ts +2 -2
- package/src/supabase/helpers/authProvider.ts +2 -2
- package/src/supabase/index.ts +10 -2
- package/src/supabase/oauth/disconnect.ts +104 -0
- package/src/supabase/oauth/exchangeToken.ts +152 -0
- package/src/supabase/oauth/getConnections.ts +85 -0
- package/src/supabase/oauth/index.ts +15 -0
- package/src/supabase/oauth/refreshToken.ts +131 -0
- package/src/supabase/registerCrudFunctions.ts +1 -1
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -1
- package/src/supabase/utils/rateLimiter.ts +1 -1
- package/src/vercel/api/auth/get-custom-claims.ts +1 -1
- package/src/vercel/api/auth/get-user-auth-status.ts +1 -1
- package/src/vercel/api/auth/index.ts +1 -1
- package/src/vercel/api/auth/remove-custom-claims.ts +1 -1
- package/src/vercel/api/auth/set-custom-claims.ts +69 -24
- package/src/vercel/api/billing/cancel.ts +3 -3
- package/src/vercel/api/billing/change-plan.ts +3 -3
- package/src/vercel/api/billing/create-checkout-session.ts +3 -3
- package/src/vercel/api/billing/customer-portal.ts +1 -1
- package/src/vercel/api/billing/index.ts +1 -1
- package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
- package/src/vercel/api/billing/webhook-handler.ts +3 -3
- package/src/vercel/api/config/constants.ts +9 -9
- package/src/vercel/api/config/firebase-admin.ts +3 -3
- package/src/vercel/api/config/index.ts +1 -1
- package/src/vercel/api/crud/create.ts +1 -1
- package/src/vercel/api/crud/delete.ts +1 -1
- package/src/vercel/api/crud/get.ts +1 -1
- package/src/vercel/api/crud/index.ts +1 -1
- package/src/vercel/api/crud/list.ts +1 -1
- package/src/vercel/api/crud/update.ts +1 -1
- package/src/vercel/api/index.d.ts +1 -1
- package/src/vercel/api/index.ts +1 -1
- package/src/vercel/api/oauth/check-github-access.ts +3 -3
- package/src/vercel/api/oauth/exchange-token.ts +1 -1
- package/src/vercel/api/oauth/grant-github-access.ts +3 -3
- package/src/vercel/api/oauth/index.ts +1 -1
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -1
- package/src/vercel/api/utils/cors.ts +4 -4
- package/src/vercel/baseFunction.ts +2 -2
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview GitHub access Firebase function
|
|
5
5
|
* @description Firebase callable function for managing GitHub access
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -40,7 +40,7 @@ const OAUTH_CONFIG = {
|
|
|
40
40
|
/**
|
|
41
41
|
* Internal function that accepts custom schema
|
|
42
42
|
*
|
|
43
|
-
* @version 0.0
|
|
43
|
+
* @version 0.1.0
|
|
44
44
|
* @since 0.0.1
|
|
45
45
|
* @author AMBROISE PARK Consulting
|
|
46
46
|
*/
|
|
@@ -146,7 +146,7 @@ async function grantGitHubAccessInternal(
|
|
|
146
146
|
/**
|
|
147
147
|
* Grant GitHub repository access to a user
|
|
148
148
|
*
|
|
149
|
-
* @version 0.0
|
|
149
|
+
* @version 0.1.0
|
|
150
150
|
* @since 0.0.1
|
|
151
151
|
* @author AMBROISE PARK Consulting
|
|
152
152
|
*/
|
|
@@ -163,7 +163,7 @@ export const grantGitHubAccess: CallableFunction<
|
|
|
163
163
|
/**
|
|
164
164
|
* Grant GitHub repository access with custom validation schema
|
|
165
165
|
*
|
|
166
|
-
* @version 0.0
|
|
166
|
+
* @version 0.1.0
|
|
167
167
|
* @since 0.0.1
|
|
168
168
|
* @author AMBROISE PARK Consulting
|
|
169
169
|
*/
|
|
@@ -181,7 +181,7 @@ export async function grantGitHubAccessWithSchema(
|
|
|
181
181
|
/**
|
|
182
182
|
* Revoke GitHub repository access from a user
|
|
183
183
|
*
|
|
184
|
-
* @version 0.0
|
|
184
|
+
* @version 0.1.0
|
|
185
185
|
* @since 0.0.1
|
|
186
186
|
* @author AMBROISE PARK Consulting
|
|
187
187
|
*/
|
|
@@ -277,7 +277,7 @@ async function revokeGitHubAccessInternal(
|
|
|
277
277
|
/**
|
|
278
278
|
* Revoke GitHub repository access from a user
|
|
279
279
|
*
|
|
280
|
-
* @version 0.0
|
|
280
|
+
* @version 0.1.0
|
|
281
281
|
* @since 0.0.1
|
|
282
282
|
* @author AMBROISE PARK Consulting
|
|
283
283
|
*/
|
|
@@ -294,7 +294,7 @@ export const revokeGitHubAccess: CallableFunction<
|
|
|
294
294
|
/**
|
|
295
295
|
* Revoke GitHub repository access with custom validation schema
|
|
296
296
|
*
|
|
297
|
-
* @version 0.0
|
|
297
|
+
* @version 0.1.0
|
|
298
298
|
* @since 0.0.1
|
|
299
299
|
* @author AMBROISE PARK Consulting
|
|
300
300
|
*/
|
|
@@ -312,7 +312,7 @@ export async function revokeGitHubAccessWithSchema(
|
|
|
312
312
|
/**
|
|
313
313
|
* Check GitHub repository access for a user
|
|
314
314
|
*
|
|
315
|
-
* @version 0.0
|
|
315
|
+
* @version 0.1.0
|
|
316
316
|
* @since 0.0.1
|
|
317
317
|
* @author AMBROISE PARK Consulting
|
|
318
318
|
*/
|
|
@@ -388,7 +388,7 @@ async function checkGitHubAccessInternal(
|
|
|
388
388
|
/**
|
|
389
389
|
* Check GitHub repository access for a user
|
|
390
390
|
*
|
|
391
|
-
* @version 0.0
|
|
391
|
+
* @version 0.1.0
|
|
392
392
|
* @since 0.0.1
|
|
393
393
|
* @author AMBROISE PARK Consulting
|
|
394
394
|
*/
|
|
@@ -405,7 +405,7 @@ export const checkGitHubAccess: CallableFunction<
|
|
|
405
405
|
/**
|
|
406
406
|
* Check GitHub repository access with custom validation schema
|
|
407
407
|
*
|
|
408
|
-
* @version 0.0
|
|
408
|
+
* @version 0.1.0
|
|
409
409
|
* @since 0.0.1
|
|
410
410
|
* @author AMBROISE PARK Consulting
|
|
411
411
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview OAuth token refresh Firebase function
|
|
5
5
|
* @description Firebase callable function for refreshing OAuth tokens
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ import { assertAuthenticated } from '../../shared/utils.js';
|
|
|
25
25
|
/**
|
|
26
26
|
* Refresh an OAuth token
|
|
27
27
|
*
|
|
28
|
-
* @version 0.0
|
|
28
|
+
* @version 0.1.0
|
|
29
29
|
* @since 0.0.1
|
|
30
30
|
* @author AMBROISE PARK Consulting
|
|
31
31
|
*/
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock the external dependencies used by auth.ts
|
|
4
|
+
vi.mock('@donotdev/core/server', () => ({
|
|
5
|
+
hasProvider: vi.fn(() => false),
|
|
6
|
+
getProvider: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
vi.mock('@donotdev/firebase/server', () => ({
|
|
9
|
+
getFirebaseAdminAuth: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import { assertAuthenticated } from '../utils/internal/auth';
|
|
13
|
+
|
|
14
|
+
describe('assertAuthenticated', () => {
|
|
15
|
+
it('returns uid for valid non-empty string', () => {
|
|
16
|
+
expect(assertAuthenticated('user-123')).toBe('user-123');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('throws for empty string', () => {
|
|
20
|
+
expect(() => assertAuthenticated('')).toThrow('Authentication required');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('throws for null', () => {
|
|
24
|
+
expect(() => assertAuthenticated(null as any)).toThrow(
|
|
25
|
+
'Authentication required'
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('throws for undefined', () => {
|
|
30
|
+
expect(() => assertAuthenticated(undefined as any)).toThrow(
|
|
31
|
+
'Authentication required'
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('throws for number (runtime type mismatch)', () => {
|
|
36
|
+
expect(() => assertAuthenticated(123 as any)).toThrow(
|
|
37
|
+
'Authentication required'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('throws for object (runtime type mismatch)', () => {
|
|
42
|
+
expect(() => assertAuthenticated({} as any)).toThrow(
|
|
43
|
+
'Authentication required'
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -90,7 +90,7 @@ describe('handleError', () => {
|
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
it('maps EntityHookError
|
|
93
|
+
it('maps EntityHookError PERMISSION_DENIED', () => {
|
|
94
94
|
const entityError = new Error('Permission denied');
|
|
95
95
|
(entityError as any).name = 'EntityHookError';
|
|
96
96
|
(entityError as any).type = 'PERMISSION_DENIED';
|
|
@@ -105,6 +105,71 @@ describe('handleError', () => {
|
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
+
it('maps EntityHookError NOT_FOUND', () => {
|
|
109
|
+
const entityError = new Error('Not found');
|
|
110
|
+
(entityError as any).name = 'EntityHookError';
|
|
111
|
+
(entityError as any).type = 'NOT_FOUND';
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
handleError(entityError);
|
|
115
|
+
expect.fail('should have thrown');
|
|
116
|
+
} catch (error) {
|
|
117
|
+
expect((error as DoNotDevError).code).toBe('not-found');
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('maps EntityHookError ALREADY_EXISTS', () => {
|
|
122
|
+
const entityError = new Error('Exists');
|
|
123
|
+
(entityError as any).name = 'EntityHookError';
|
|
124
|
+
(entityError as any).type = 'ALREADY_EXISTS';
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
handleError(entityError);
|
|
128
|
+
expect.fail('should have thrown');
|
|
129
|
+
} catch (error) {
|
|
130
|
+
expect((error as DoNotDevError).code).toBe('already-exists');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('maps EntityHookError VALIDATION_ERROR', () => {
|
|
135
|
+
const entityError = new Error('Invalid');
|
|
136
|
+
(entityError as any).name = 'EntityHookError';
|
|
137
|
+
(entityError as any).type = 'VALIDATION_ERROR';
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
handleError(entityError);
|
|
141
|
+
expect.fail('should have thrown');
|
|
142
|
+
} catch (error) {
|
|
143
|
+
expect((error as DoNotDevError).code).toBe('invalid-argument');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('maps EntityHookError NETWORK_ERROR', () => {
|
|
148
|
+
const entityError = new Error('Network');
|
|
149
|
+
(entityError as any).name = 'EntityHookError';
|
|
150
|
+
(entityError as any).type = 'NETWORK_ERROR';
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
handleError(entityError);
|
|
154
|
+
expect.fail('should have thrown');
|
|
155
|
+
} catch (error) {
|
|
156
|
+
expect((error as DoNotDevError).code).toBe('unavailable');
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('maps unknown EntityHookError type to internal', () => {
|
|
161
|
+
const entityError = new Error('Unknown');
|
|
162
|
+
(entityError as any).name = 'EntityHookError';
|
|
163
|
+
(entityError as any).type = 'SOME_FUTURE_TYPE';
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
handleError(entityError);
|
|
167
|
+
expect.fail('should have thrown');
|
|
168
|
+
} catch (error) {
|
|
169
|
+
expect((error as DoNotDevError).code).toBe('internal');
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
108
173
|
it('maps ValiError to invalid-argument with details', () => {
|
|
109
174
|
const valiError = new Error('Validation failed');
|
|
110
175
|
(valiError as any).name = 'ValiError';
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createTimestamp,
|
|
5
|
+
toTimestamp,
|
|
6
|
+
toISOString,
|
|
7
|
+
isTimestamp,
|
|
8
|
+
transformFirestoreData,
|
|
9
|
+
prepareForFirestore,
|
|
10
|
+
} from '../firebase';
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// createTimestamp
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
describe('createTimestamp', () => {
|
|
17
|
+
it('converts Date to timestamp with correct seconds and nanoseconds', () => {
|
|
18
|
+
const date = new Date('2026-01-15T12:00:00.500Z');
|
|
19
|
+
const ts = createTimestamp(date);
|
|
20
|
+
|
|
21
|
+
expect(ts.seconds).toBe(Math.floor(date.getTime() / 1000));
|
|
22
|
+
expect(ts.nanoseconds).toBe(500 * 1_000_000);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('toDate returns equivalent Date', () => {
|
|
26
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
27
|
+
const ts = createTimestamp(date);
|
|
28
|
+
|
|
29
|
+
expect(ts.toDate().getTime()).toBe(date.getTime());
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('toMillis returns epoch milliseconds', () => {
|
|
33
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
34
|
+
const ts = createTimestamp(date);
|
|
35
|
+
|
|
36
|
+
expect(ts.toMillis()).toBe(date.getTime());
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('isEqual returns true for identical timestamps', () => {
|
|
40
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
41
|
+
const ts1 = createTimestamp(date);
|
|
42
|
+
const ts2 = createTimestamp(date);
|
|
43
|
+
|
|
44
|
+
expect(ts1.isEqual(ts2)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('isEqual returns false for different timestamps', () => {
|
|
48
|
+
const ts1 = createTimestamp(new Date('2026-01-15T12:00:00.000Z'));
|
|
49
|
+
const ts2 = createTimestamp(new Date('2026-01-16T12:00:00.000Z'));
|
|
50
|
+
|
|
51
|
+
expect(ts1.isEqual(ts2)).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('valueOf returns formatted string', () => {
|
|
55
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
56
|
+
const ts = createTimestamp(date);
|
|
57
|
+
|
|
58
|
+
expect(ts.valueOf()).toContain('Timestamp(seconds=');
|
|
59
|
+
expect(ts.valueOf()).toContain('nanoseconds=');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('handles epoch zero', () => {
|
|
63
|
+
const date = new Date(0);
|
|
64
|
+
const ts = createTimestamp(date);
|
|
65
|
+
|
|
66
|
+
expect(ts.seconds).toBe(0);
|
|
67
|
+
expect(ts.nanoseconds).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// toTimestamp
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
describe('toTimestamp', () => {
|
|
76
|
+
it('converts ISO string to timestamp', () => {
|
|
77
|
+
const ts = toTimestamp('2026-01-15T12:00:00.000Z');
|
|
78
|
+
|
|
79
|
+
expect(ts.seconds).toBe(Math.floor(new Date('2026-01-15T12:00:00.000Z').getTime() / 1000));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('converts Date object to timestamp', () => {
|
|
83
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
84
|
+
const ts = toTimestamp(date);
|
|
85
|
+
|
|
86
|
+
expect(ts.toDate().getTime()).toBe(date.getTime());
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('throws for invalid date string', () => {
|
|
90
|
+
expect(() => toTimestamp('not-a-date')).toThrow('Failed to convert to timestamp');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('throws for invalid Date object', () => {
|
|
94
|
+
expect(() => toTimestamp(new Date('invalid'))).toThrow('Failed to convert to timestamp');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// toISOString
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
describe('toISOString', () => {
|
|
103
|
+
it('converts timestamp to ISO string', () => {
|
|
104
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
105
|
+
const ts = createTimestamp(date);
|
|
106
|
+
|
|
107
|
+
expect(toISOString(ts)).toBe('2026-01-15T12:00:00.000Z');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// isTimestamp
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
describe('isTimestamp', () => {
|
|
116
|
+
it('returns true for valid timestamp object', () => {
|
|
117
|
+
const ts = createTimestamp(new Date());
|
|
118
|
+
|
|
119
|
+
expect(isTimestamp(ts)).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('returns falsy for null', () => {
|
|
123
|
+
expect(isTimestamp(null)).toBeFalsy();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('returns falsy for undefined', () => {
|
|
127
|
+
expect(isTimestamp(undefined)).toBeFalsy();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('returns false for plain object', () => {
|
|
131
|
+
expect(isTimestamp({ seconds: 1, nanoseconds: 0 })).toBe(false);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns false for string', () => {
|
|
135
|
+
expect(isTimestamp('2026-01-01')).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('returns false for number', () => {
|
|
139
|
+
expect(isTimestamp(12345)).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// transformFirestoreData
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
describe('transformFirestoreData', () => {
|
|
148
|
+
it('returns falsy values unchanged', () => {
|
|
149
|
+
expect(transformFirestoreData(null)).toBe(null);
|
|
150
|
+
expect(transformFirestoreData(undefined)).toBe(undefined);
|
|
151
|
+
expect(transformFirestoreData(0)).toBe(0);
|
|
152
|
+
expect(transformFirestoreData('')).toBe('');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('returns primitive values unchanged', () => {
|
|
156
|
+
expect(transformFirestoreData('hello')).toBe('hello');
|
|
157
|
+
expect(transformFirestoreData(42)).toBe(42);
|
|
158
|
+
expect(transformFirestoreData(true)).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('converts timestamp fields to ISO strings', () => {
|
|
162
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
163
|
+
const data = {
|
|
164
|
+
name: 'test',
|
|
165
|
+
createdAt: createTimestamp(date),
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const result = transformFirestoreData(data);
|
|
169
|
+
|
|
170
|
+
expect(result.name).toBe('test');
|
|
171
|
+
expect(result.createdAt).toBe('2026-01-15T12:00:00.000Z');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('handles nested objects with timestamps', () => {
|
|
175
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
176
|
+
const data = {
|
|
177
|
+
user: {
|
|
178
|
+
profile: {
|
|
179
|
+
lastLogin: createTimestamp(date),
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const result = transformFirestoreData(data);
|
|
185
|
+
|
|
186
|
+
expect(result.user.profile.lastLogin).toBe('2026-01-15T12:00:00.000Z');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('handles arrays with timestamps', () => {
|
|
190
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
191
|
+
const data = [createTimestamp(date), 'plain'];
|
|
192
|
+
|
|
193
|
+
const result = transformFirestoreData(data);
|
|
194
|
+
|
|
195
|
+
expect(result[0]).toBe('2026-01-15T12:00:00.000Z');
|
|
196
|
+
expect(result[1]).toBe('plain');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('handles mixed nested structures', () => {
|
|
200
|
+
const date = new Date('2026-03-01T00:00:00.000Z');
|
|
201
|
+
const data = {
|
|
202
|
+
items: [
|
|
203
|
+
{ ts: createTimestamp(date), val: 1 },
|
|
204
|
+
{ ts: createTimestamp(date), val: 2 },
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const result = transformFirestoreData(data);
|
|
209
|
+
|
|
210
|
+
expect(result.items[0].ts).toBe('2026-03-01T00:00:00.000Z');
|
|
211
|
+
expect(result.items[0].val).toBe(1);
|
|
212
|
+
expect(result.items[1].ts).toBe('2026-03-01T00:00:00.000Z');
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
// prepareForFirestore
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
describe('prepareForFirestore', () => {
|
|
221
|
+
it('returns falsy values unchanged', () => {
|
|
222
|
+
expect(prepareForFirestore(null)).toBe(null);
|
|
223
|
+
expect(prepareForFirestore(undefined)).toBe(undefined);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('converts Date objects to ISO strings', () => {
|
|
227
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
228
|
+
const data = { createdAt: date, name: 'test' };
|
|
229
|
+
|
|
230
|
+
const result = prepareForFirestore(data);
|
|
231
|
+
|
|
232
|
+
expect(result.createdAt).toBe('2026-01-15T12:00:00.000Z');
|
|
233
|
+
expect(result.name).toBe('test');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('converts root-level Date to empty object (Date is object, enters object branch)', () => {
|
|
237
|
+
// Note: Date is typeof 'object', so it enters the object iteration branch
|
|
238
|
+
// before reaching the root-level Date check. This is a known source quirk.
|
|
239
|
+
const date = new Date('2026-01-15T12:00:00.000Z');
|
|
240
|
+
|
|
241
|
+
const result = prepareForFirestore(date);
|
|
242
|
+
|
|
243
|
+
expect(result).toEqual({});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('removes specified fields', () => {
|
|
247
|
+
const data = { keep: 'yes', remove: 'no', alsoKeep: 1 };
|
|
248
|
+
|
|
249
|
+
const result = prepareForFirestore(data, ['remove']);
|
|
250
|
+
|
|
251
|
+
expect(result).toEqual({ keep: 'yes', alsoKeep: 1 });
|
|
252
|
+
expect(result).not.toHaveProperty('remove');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('handles nested objects with Dates', () => {
|
|
256
|
+
const date = new Date('2026-06-01T00:00:00.000Z');
|
|
257
|
+
const data = {
|
|
258
|
+
user: {
|
|
259
|
+
lastLogin: date,
|
|
260
|
+
name: 'Alice',
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const result = prepareForFirestore(data);
|
|
265
|
+
|
|
266
|
+
expect(result.user.lastLogin).toBe('2026-06-01T00:00:00.000Z');
|
|
267
|
+
expect(result.user.name).toBe('Alice');
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('handles arrays with Dates', () => {
|
|
271
|
+
const date = new Date('2026-01-01T00:00:00.000Z');
|
|
272
|
+
const data = [{ ts: date }, { ts: date }];
|
|
273
|
+
|
|
274
|
+
const result = prepareForFirestore(data);
|
|
275
|
+
|
|
276
|
+
expect(result[0].ts).toBe('2026-01-01T00:00:00.000Z');
|
|
277
|
+
expect(result[1].ts).toBe('2026-01-01T00:00:00.000Z');
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('leaves strings as-is', () => {
|
|
281
|
+
const data = { iso: '2026-01-15T12:00:00.000Z', text: 'hello' };
|
|
282
|
+
|
|
283
|
+
const result = prepareForFirestore(data);
|
|
284
|
+
|
|
285
|
+
expect(result).toEqual(data);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('returns primitives unchanged', () => {
|
|
289
|
+
expect(prepareForFirestore(42)).toBe(42);
|
|
290
|
+
expect(prepareForFirestore('hello')).toBe('hello');
|
|
291
|
+
expect(prepareForFirestore(true)).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
});
|