Skip to content

Commit

Permalink
bugfix(admin): calling migrated functions (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkue authored Sep 30, 2023
1 parent 12536da commit 328f154
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion admin/src/actions/CreateDonationCertificatesAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<CreateDonationCertificatesFunctionProps, string>(
functions,
'createDonationCertificates',
Expand Down
3 changes: 2 additions & 1 deletion admin/src/actions/InviteWhatsappAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<TwilioOutgoingMessageFunctionProps, string>(
functions,
'twilioOutgoingMessage',
Expand Down
6 changes: 5 additions & 1 deletion admin/src/actions/PaymentProcessAction.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -35,7 +36,10 @@ export function PaymentProcessAction() {
};

const triggerFirebaseFunction = (task: PaymentProcessTaskType) => {
const runPaymentProcessTask = httpsCallable<PaymentProcessProps, string>(getFunctions(), 'runPaymentProcessTask');
const runPaymentProcessTask = httpsCallable<PaymentProcessProps, string>(
getFunctions(undefined, DEFAULT_REGION),
'runPaymentProcessTask',
);
setIsFunctionRunning(true);
runPaymentProcessTask({
type: task,
Expand Down
3 changes: 2 additions & 1 deletion admin/src/views/ScriptsView.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
1 change: 0 additions & 1 deletion functions/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
2 changes: 1 addition & 1 deletion functions/src/firestore/firestore-auditor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion functions/src/webhooks/admin/payment-process/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 2 additions & 1 deletion shared/src/firebase/client/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions shared/src/firebase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_REGION = 'europe-west6';
5 changes: 3 additions & 2 deletions shared/src/stripe/StripeWebhookHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion website/src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 328f154

Please sign in to comment.