Skip to content

Commit 31d0841

Browse files
authored
Merge pull request #869 from PAIR-code/node-updates
Temporarily downgrade firebase-functions to v6 to avoid breaking platform
2 parents 1c3011b + 2317076 commit 31d0841

13 files changed

+34
-69
lines changed

functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@google/genai": "^1.30.0",
2828
"@sinclair/typebox": "^0.34.41",
2929
"firebase-admin": "^13.6.0",
30-
"firebase-functions": "^7.0.0",
30+
"firebase-functions": "^6.0.0",
3131
"openai": "^6.9.1",
3232
"unique-names-generator": "^4.7.1"
3333
},

functions/src/admin.endpoints.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* Admin endpoints for administrative tasks.
33
*/
44

5-
import {onCall} from 'firebase-functions/v2/https';
6-
import * as functions from 'firebase-functions';
5+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
76
import {app} from './app';
87
import {AuthGuard} from './utils/auth-guard';
98

@@ -91,9 +90,6 @@ export const normalizeAllowlistEmails = onCall(async (request) => {
9190
return result;
9291
} catch (error) {
9392
console.error('Error normalizing allowlist emails:', error);
94-
throw new functions.https.HttpsError(
95-
'internal',
96-
'Failed to normalize allowlist emails',
97-
);
93+
throw new HttpsError('internal', 'Failed to normalize allowlist emails');
9894
}
9995
});

functions/src/app.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/**
2-
* Import function triggers from their respective submodules:
3-
*
4-
* import {onCall} from "firebase-functions/v2/https";
5-
* import {onDocumentWritten} from "firebase-functions/v2/firestore";
6-
*
7-
* See a full list of supported triggers at https://firebase.google.com/docs/functions
8-
*/
9-
101
import {StageManager} from '@deliberation-lab/utils';
112
import * as admin from 'firebase-admin';
123

functions/src/cohort.endpoints.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
ParticipantStatus,
88
} from '@deliberation-lab/utils';
99

10-
import * as functions from 'firebase-functions';
11-
import {onCall} from 'firebase-functions/v2/https';
10+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
1211

1312
import {app} from './app';
1413
import {AuthGuard} from './utils/auth-guard';
@@ -66,7 +65,7 @@ function handleCohortCreationValidationErrors(data: any) {
6665
}
6766
}
6867

69-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
68+
throw new HttpsError('invalid-argument', 'Invalid data');
7069
}
7170

7271
// ************************************************************************* //
@@ -125,7 +124,7 @@ export const deleteCohort = onCall(async (request) => {
125124
// Validate input
126125
const validInput = Value.Check(CohortDeletionData, data);
127126
if (!validInput) {
128-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
127+
throw new HttpsError('invalid-argument', 'Invalid data');
129128
return {success: false};
130129
}
131130

@@ -134,7 +133,7 @@ export const deleteCohort = onCall(async (request) => {
134133
await app.firestore().collection('experiments').doc(data.experimentId).get()
135134
).data();
136135
if (!experiment) {
137-
throw new functions.https.HttpsError(
136+
throw new HttpsError(
138137
'not-found',
139138
`Experiment ${data.experimentId} not found`,
140139
);

functions/src/experiment.endpoints.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import {
1717
} from '@deliberation-lab/utils';
1818
import {getExperimentDownload} from './data';
1919

20-
import * as functions from 'firebase-functions';
21-
import {onCall} from 'firebase-functions/v2/https';
20+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
2221

2322
import {app} from './app';
2423
import {AuthGuard} from './utils/auth-guard';
@@ -194,7 +193,7 @@ export const deleteExperiment = onCall(async (request) => {
194193
// Validate input
195194
const validInput = Value.Check(ExperimentDeletionData, data);
196195
if (!validInput) {
197-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
196+
throw new HttpsError('invalid-argument', 'Invalid data');
198197
}
199198

200199
// Verify that experimenter is the creator before enabling delete
@@ -207,7 +206,7 @@ export const deleteExperiment = onCall(async (request) => {
207206
.get()
208207
).data();
209208
if (!experiment) {
210-
throw new functions.https.HttpsError(
209+
throw new HttpsError(
211210
'not-found',
212211
`Experiment ${data.experimentId} not found in collection ${data.collectionName}`,
213212
);
@@ -242,7 +241,7 @@ export const getExperimentTemplate = onCall(async (request) => {
242241
).data();
243242

244243
if (!experiment) {
245-
throw new functions.https.HttpsError(
244+
throw new HttpsError(
246245
'not-found',
247246
`Experiment ${data.experimentId} not found in collection ${data.collectionName}`,
248247
);

functions/src/mediator.endpoints.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import * as functions from 'firebase-functions';
21
import {Value} from '@sinclair/typebox/value';
32
import {
43
CreateMediatorData,
54
MediatorProfileExtended,
65
UpdateMediatorStatusData,
76
} from '@deliberation-lab/utils';
8-
import {onCall} from 'firebase-functions/v2/https';
7+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
98

109
import {app} from './app';
1110
import {AuthGuard} from './utils/auth-guard';
@@ -23,7 +22,7 @@ export const updateMediatorStatus = onCall(async (request) => {
2322
await AuthGuard.isExperimenter(request);
2423

2524
if (!Value.Check(UpdateMediatorStatusData, data)) {
26-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
25+
throw new HttpsError('invalid-argument', 'Invalid data');
2726
}
2827

2928
const mediatorDoc = app
@@ -36,7 +35,7 @@ export const updateMediatorStatus = onCall(async (request) => {
3635
await app.firestore().runTransaction(async (transaction) => {
3736
const snapshot = await mediatorDoc.get();
3837
if (!snapshot.exists) {
39-
throw new functions.https.HttpsError('not-found', 'Mediator not found');
38+
throw new HttpsError('not-found', 'Mediator not found');
4039
}
4140

4241
const mediator = snapshot.data() as MediatorProfileExtended;
@@ -59,7 +58,7 @@ export const createMediator = onCall(async (request) => {
5958
await AuthGuard.isExperimenter(request);
6059

6160
if (!Value.Check(CreateMediatorData, data)) {
62-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
61+
throw new HttpsError('invalid-argument', 'Invalid data');
6362
}
6463

6564
const mediatorsInCohort = (
@@ -77,7 +76,7 @@ export const createMediator = onCall(async (request) => {
7776
);
7877

7978
if (existingMediator) {
80-
throw new functions.https.HttpsError(
79+
throw new HttpsError(
8180
'already-exists',
8281
'Mediator already assigned to cohort',
8382
);
@@ -90,10 +89,7 @@ export const createMediator = onCall(async (request) => {
9089
);
9190

9291
if (!mediator) {
93-
throw new functions.https.HttpsError(
94-
'not-found',
95-
'Agent mediator persona not found',
96-
);
92+
throw new HttpsError('not-found', 'Agent mediator persona not found');
9793
}
9894

9995
const mediatorDoc = app

functions/src/participant.endpoints.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
handleAutomaticTransfer,
2525
} from './participant.utils';
2626

27-
import * as functions from 'firebase-functions';
28-
import {onCall} from 'firebase-functions/v2/https';
27+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
2928

3029
import {app} from './app';
3130
import {AuthGuard} from './utils/auth-guard';
@@ -152,7 +151,7 @@ function handleCreateParticipantValidationErrors(data: any) {
152151
}
153152
}
154153

155-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
154+
throw new HttpsError('invalid-argument', 'Invalid data');
156155
}
157156

158157
// ************************************************************************* //

functions/src/stages/asset_allocation.endpoints.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
} from '@deliberation-lab/utils';
66

77
import * as admin from 'firebase-admin';
8-
import * as functions from 'firebase-functions';
9-
import {onCall} from 'firebase-functions/v2/https';
8+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
109

1110
import {app} from '../app';
1211
import {
@@ -85,7 +84,7 @@ function handleUpdateAssetAllocationStageParticipantAnswerValidationErrors(
8584
}
8685
}
8786

88-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
87+
throw new HttpsError('invalid-argument', 'Invalid data');
8988
}
9089
/* eslint-enable @typescript-eslint/no-explicit-any */
9190

functions/src/stages/flipcard.endpoints.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as admin from 'firebase-admin';
2-
import * as functions from 'firebase-functions';
3-
import {onCall} from 'firebase-functions/v2/https';
2+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
43

54
import {app} from '../app';
65

@@ -25,10 +24,7 @@ export const updateFlipCardStageParticipantAnswer = onCall(async (request) => {
2524
!participantPrivateId ||
2625
!flipCardStageParticipantAnswer
2726
) {
28-
throw new functions.https.HttpsError(
29-
'invalid-argument',
30-
'Missing required fields',
31-
);
27+
throw new HttpsError('invalid-argument', 'Missing required fields');
3228
}
3329

3430
// Define participant answer document reference
@@ -53,7 +49,7 @@ export const updateFlipCardStageParticipantAnswer = onCall(async (request) => {
5349
return {success: true};
5450
} catch (error) {
5551
console.error('Error updating FlipCard stage participant answer:', error);
56-
throw new functions.https.HttpsError(
52+
throw new HttpsError(
5753
'internal',
5854
'Failed to update FlipCard stage participant answer',
5955
);

functions/src/stages/ranking.endpoints.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
UpdateRankingStageParticipantAnswerData,
66
} from '@deliberation-lab/utils';
77

8-
import * as functions from 'firebase-functions';
9-
import {onCall} from 'firebase-functions/v2/https';
8+
import {onCall, HttpsError} from 'firebase-functions/v2/https';
109

1110
import {app} from '../app';
1211
import {
@@ -73,5 +72,5 @@ function handleUpdateRankingStageParticipantAnswerValidationErrors(data: any) {
7372
}
7473
}
7574

76-
throw new functions.https.HttpsError('invalid-argument', 'Invalid data');
75+
throw new HttpsError('invalid-argument', 'Invalid data');
7776
}

0 commit comments

Comments
 (0)