diff --git a/admin/src/actions/CreateDonationCertificatesAction.tsx b/admin/src/actions/CreateDonationCertificatesAction.tsx index 438fd76a5..c5bdf83da 100644 --- a/admin/src/actions/CreateDonationCertificatesAction.tsx +++ b/admin/src/actions/CreateDonationCertificatesAction.tsx @@ -15,6 +15,7 @@ import { CollectionActionsProps, useAuthController, useSnackbarController } from import _ from 'lodash'; import React from 'react'; import { CreateDonationCertificatesFunctionProps } from '../../../functions/src/webhooks/admin/donation-certificates/DonationCertificateHandler'; +import { DEFAULT_REGION } from '../../../shared/src/firebase'; import { User } from '../../../shared/src/types/User'; const style = { @@ -42,7 +43,7 @@ export function CreateDonationCertificatesAction({ selectionController }: Collec const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); - const functions = getFunctions(); + const functions = getFunctions(undefined, DEFAULT_REGION); const createDonationCertificatesFunction = httpsCallable( functions, 'createDonationCertificates', diff --git a/admin/src/actions/InviteWhatsappAction.tsx b/admin/src/actions/InviteWhatsappAction.tsx index 885f84bbd..a62206216 100644 --- a/admin/src/actions/InviteWhatsappAction.tsx +++ b/admin/src/actions/InviteWhatsappAction.tsx @@ -3,6 +3,7 @@ import { getFunctions, httpsCallable } from 'firebase/functions'; import { CollectionActionsProps, useAuthController, useSnackbarController } from 'firecms'; import React from 'react'; import { TwilioOutgoingMessageFunctionProps } from '../../../functions/src/webhooks/twilio/TwilioOutgoingMessageHandler'; +import { DEFAULT_REGION } from '../../../shared/src/firebase'; import { Recipient } from '../../../shared/src/types/Recipient'; const STYLE = { @@ -30,7 +31,7 @@ export function InviteWhatsappAction({ selectionController }: CollectionActionsP }; const handleClose = () => setOpen(false); - const functions = getFunctions(); + const functions = getFunctions(undefined, DEFAULT_REGION); const twilioOutgoingMessage = httpsCallable( functions, 'twilioOutgoingMessage', diff --git a/admin/src/actions/PaymentProcessAction.tsx b/admin/src/actions/PaymentProcessAction.tsx index 166d5ecc1..ae7c9ca10 100644 --- a/admin/src/actions/PaymentProcessAction.tsx +++ b/admin/src/actions/PaymentProcessAction.tsx @@ -1,5 +1,6 @@ import { Box, Button, CircularProgress, Modal, Tooltip, Typography } from '@mui/material'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; +import { DEFAULT_REGION } from '@socialincome/shared/src/firebase'; import { PaymentProcessTaskType } from '@socialincome/shared/src/types/Payment'; import { toPaymentDate } from '@socialincome/shared/src/types/Recipient'; import { downloadStringAsFile } from '@socialincome/shared/src/utils/html'; @@ -35,7 +36,10 @@ export function PaymentProcessAction() { }; const triggerFirebaseFunction = (task: PaymentProcessTaskType) => { - const runPaymentProcessTask = httpsCallable(getFunctions(), 'runPaymentProcessTask'); + const runPaymentProcessTask = httpsCallable( + getFunctions(undefined, DEFAULT_REGION), + 'runPaymentProcessTask', + ); setIsFunctionRunning(true); runPaymentProcessTask({ type: task, diff --git a/admin/src/views/ScriptsView.tsx b/admin/src/views/ScriptsView.tsx index 2b678508a..8c684ea1c 100644 --- a/admin/src/views/ScriptsView.tsx +++ b/admin/src/views/ScriptsView.tsx @@ -1,9 +1,10 @@ import { Box, Button, Card, CardActions, CardContent, Container, Grid, Typography } from '@mui/material'; +import { DEFAULT_REGION } from '@socialincome/shared/src/firebase'; import { getFunctions, httpsCallable } from 'firebase/functions'; import { useSnackbarController } from 'firecms'; export function ScriptsView() { - const functions = getFunctions(); + const functions = getFunctions(undefined, DEFAULT_REGION); const snackbarController = useSnackbarController(); const batchImportStripeCharges = () => { snackbarController.open({ diff --git a/functions/src/config.ts b/functions/src/config.ts index 52e8cb86a..32f77dd45 100644 --- a/functions/src/config.ts +++ b/functions/src/config.ts @@ -3,7 +3,6 @@ import 'dotenv/config'; import * as path from 'path'; export const ASSET_DIR = path.join(__dirname, '..', '..', 'shared', 'assets'); -export const DEFAULT_REGION = 'europe-west6'; // Env variables export const STRIPE_API_READ_KEY = process.env.STRIPE_API_READ_KEY!; diff --git a/functions/src/firestore/firestore-auditor/index.ts b/functions/src/firestore/firestore-auditor/index.ts index 46bbfb6e3..24df99df7 100644 --- a/functions/src/firestore/firestore-auditor/index.ts +++ b/functions/src/firestore/firestore-auditor/index.ts @@ -2,7 +2,7 @@ import { DocumentSnapshot } from '@google-cloud/firestore'; import * as functions from 'firebase-functions'; import { Change, EventContext } from 'firebase-functions'; import { DateTime } from 'luxon'; -import { DEFAULT_REGION } from '../../config'; +import { DEFAULT_REGION } from '../../../../shared/src/firebase'; import { FirestoreAuditor } from './FirestoreAuditor'; /** diff --git a/functions/src/index.ts b/functions/src/index.ts index ba3edd5b2..c284df669 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -1,5 +1,5 @@ import { setGlobalOptions } from 'firebase-functions/v2/options'; -import { DEFAULT_REGION } from './config'; +import { DEFAULT_REGION } from '../../shared/src/firebase'; setGlobalOptions({ maxInstances: 10, region: DEFAULT_REGION }); diff --git a/functions/src/webhooks/admin/payment-process/index.ts b/functions/src/webhooks/admin/payment-process/index.ts index 1f8eaf3c1..98d89bd46 100644 --- a/functions/src/webhooks/admin/payment-process/index.ts +++ b/functions/src/webhooks/admin/payment-process/index.ts @@ -1,9 +1,9 @@ import * as functions from 'firebase-functions'; import { DateTime } from 'luxon'; +import { DEFAULT_REGION } from '../../../../../shared/src/firebase'; import { FirestoreAdmin } from '../../../../../shared/src/firebase/admin/FirestoreAdmin'; import { PaymentProcessTaskType } from '../../../../../shared/src/types/Payment'; import { toPaymentDate } from '../../../../../shared/src/types/Recipient'; -import { DEFAULT_REGION } from '../../../config'; import { PaymentCSVTask } from './tasks/PaymentCSVTask'; import { PaymentTask } from './tasks/PaymentTask'; import { RegistrationCSVTask } from './tasks/RegistrationCSVTask'; diff --git a/shared/src/firebase/client/init.ts b/shared/src/firebase/client/init.ts index b46f588d0..91f45f180 100644 --- a/shared/src/firebase/client/init.ts +++ b/shared/src/firebase/client/init.ts @@ -3,6 +3,7 @@ import { connectAuthEmulator, getAuth } from 'firebase/auth'; import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore'; import { connectFunctionsEmulator, getFunctions } from 'firebase/functions'; import { connectStorageEmulator, getStorage } from 'firebase/storage'; +import { DEFAULT_REGION } from '../index'; import { getOrInitializeFirebaseClientApp } from './app'; interface InitializeFirebaseClientProps { @@ -28,7 +29,7 @@ export const initializeFirebaseClient = ({ }: InitializeFirebaseClientProps) => { const app = getOrInitializeFirebaseClientApp(firebaseConfig); const auth = getAuth(app); - const functions = getFunctions(app); + const functions = getFunctions(app, DEFAULT_REGION); const firestore = getFirestore(app); const storage = getStorage(app); diff --git a/shared/src/firebase/index.ts b/shared/src/firebase/index.ts new file mode 100644 index 000000000..2618b698c --- /dev/null +++ b/shared/src/firebase/index.ts @@ -0,0 +1 @@ +export const DEFAULT_REGION = 'europe-west6'; diff --git a/shared/src/stripe/StripeWebhookHandler.test.ts b/shared/src/stripe/StripeWebhookHandler.test.ts index efbfc62f9..f64d2a458 100644 --- a/shared/src/stripe/StripeWebhookHandler.test.ts +++ b/shared/src/stripe/StripeWebhookHandler.test.ts @@ -30,8 +30,9 @@ describe('stripeWebhook', () => { expect(contribution.data()).toEqual(expectedContribution); const createdUser = (await stripeWebhook.findUser(testCustomer))!.data(); - expect(Math.round(createdUser.payment_reference_id / 10000)).toEqual( - Math.round(expectedUser.payment_reference_id / 10000), + expect(Math.round(createdUser.payment_reference_id / 100000)).toEqual( + // rounded to 100 seconds + Math.round(expectedUser.payment_reference_id / 100000), ); expect(createdUser.personal).toEqual(expectedUser.personal); expect(createdUser.email).toEqual(expectedUser.email); diff --git a/website/src/app/providers.tsx b/website/src/app/providers.tsx index 13a17b4aa..7aff92134 100644 --- a/website/src/app/providers.tsx +++ b/website/src/app/providers.tsx @@ -1,5 +1,6 @@ 'use client'; +import { DEFAULT_REGION } from '@socialincome/shared/src/firebase'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { Analytics, getAnalytics, isSupported as isAnalyticsSupported } from 'firebase/analytics'; import { connectAuthEmulator, getAuth } from 'firebase/auth'; @@ -51,7 +52,7 @@ function FirebaseSDKProviders({ children }: PropsWithChildren) { const app = useFirebaseApp(); const auth = getAuth(app); const firestore = getFirestore(app); - const functions = getFunctions(app); + const functions = getFunctions(app, DEFAULT_REGION); const storage = getStorage(app); const authEmulatorUrl = process.env.NEXT_PUBLIC_FIREBASE_AUTH_EMULATOR_URL;