Skip to content

Commit 25fb1a8

Browse files
authored
Merge pull request #1848 from kiminkim724/1698-upgrade-node-20
Upgrade Firebase to Node 20
2 parents 3dab1ba + ed47017 commit 25fb1a8

25 files changed

+1106
-976
lines changed

.github/actions/setup-repo/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
node-version:
55
description: "Version used by actions/setup-node"
66
required: true
7-
default: "18"
7+
default: "20"
88
yarn-version:
99
description: "Version of Yarn used to install dependencies"
1010
required: true

components/ProfilePage/SelectLegislators.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const LegislatorForm: React.FC<
3636
<Form.Label>{t("legislator.representative")}</Form.Label>
3737
<Search
3838
placeholder={t("legislator.searchRepresentative")}
39-
index={index.representatives}
39+
index={index?.representatives}
4040
isLoading={profile.updatingRep}
4141
memberId={profile.profile?.representative?.id}
4242
update={profile.updateRep}
@@ -47,7 +47,7 @@ export const LegislatorForm: React.FC<
4747
<Form.Label>{t("legislator.senator")}</Form.Label>
4848
<Search
4949
placeholder={t("legislator.searchSenator")}
50-
index={index.senators}
50+
index={index?.senators}
5151
isLoading={profile.updatingSenator}
5252
memberId={profile.profile?.senator?.id}
5353
update={profile.updateSenator}

components/legislatorSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const useSearch = <T extends MemberSearchIndexItem, M extends boolean>(
7373
index: T[]
7474
) => {
7575
const byId = useMemo(
76-
() => Object.fromEntries(index.map(m => [m.MemberCode, m])),
76+
() => (index ? Object.fromEntries(index?.map(m => [m.MemberCode, m])) : {}),
7777
[index]
7878
)
7979

firebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"predeploy": ["yarn build:functions"],
1010
"source": "functions",
1111
"codebase": "maple",
12-
"runtime": "nodejs18",
12+
"runtime": "nodejs20",
1313
"runtimeConfig": ".runtimeconfig.json"
1414
},
1515
{

functions/jest.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
33
preset: "ts-jest",
4-
testEnvironment: "node"
4+
testEnvironment: "node",
5+
moduleNameMapper: {
6+
// This maps firebase-admin/auth to the correct location within node_modules
7+
"^firebase-admin/auth$":
8+
"<rootDir>/node_modules/firebase-admin/lib/auth/index.js",
9+
"^firebase-admin/app$":
10+
"<rootDir>/node_modules/firebase-admin/lib/app/index.js",
11+
"^firebase-admin/(.*)$": "<rootDir>/node_modules/firebase-admin/lib/$1"
12+
}
513
}

functions/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"assemblyai": "^4.9.0",
1919
"axios": "^0.25.0",
2020
"date-fns": "^2.30.0",
21-
"firebase-admin": "^10",
22-
"firebase-functions": "^3.22.0",
21+
"firebase-admin": "^11.11.1",
22+
"firebase-functions": "^5.1.1",
2323
"fluent-ffmpeg": "^2.1.3",
2424
"fuse.js": "6.5.3",
2525
"handlebars": "^4.7.8",
@@ -42,7 +42,7 @@
4242
"@types/object-hash": "^2.2.1",
4343
"copyfiles": "^2.4.1",
4444
"firebase-functions-test": "^0.3.3",
45-
"firebase-tools": "^11.16.0",
45+
"firebase-tools": "^12.4.0",
4646
"jest": "^27.5.1",
4747
"rimraf": "^3.0.2",
4848
"ts-jest": "^27.1.3",

functions/src/auth/setRole.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UserRecord } from "firebase-admin/lib/auth/user-record"
1+
import { UserRecord } from "firebase-admin/auth"
22
import { Undefined } from "runtypes"
33
import { Profile } from "../profile/types"
44
import { Auth, Database } from "../types"

functions/src/events/scrapeEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DateTime } from "luxon"
33
import { JSDOM } from "jsdom"
44
import { AssemblyAI } from "assemblyai"
55
import { logFetchError } from "../common"
6-
import { admin, db, Timestamp } from "../firebase"
6+
import { db, storage, Timestamp } from "../firebase"
77
import * as api from "../malegislature"
88
import {
99
BaseEvent,
@@ -182,7 +182,7 @@ const extractAudioFromVideo = async (
182182
})
183183

184184
// Upload the audio file
185-
const bucket = admin.storage().bucket()
185+
const bucket = storage.bucket()
186186
const audioFileName = `hearing-${EventId}-${Date.now()}.m4a`
187187
const file = bucket.file(audioFileName)
188188

functions/src/firebase.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
import * as admin from "firebase-admin"
1+
import { initializeApp, App } from "firebase-admin/app"
2+
import { getAuth } from "firebase-admin/auth"
3+
import {
4+
getFirestore,
5+
Timestamp,
6+
FieldValue,
7+
FieldPath,
8+
DocumentData,
9+
QueryDocumentSnapshot,
10+
DocumentSnapshot,
11+
QuerySnapshot
12+
} from "firebase-admin/firestore"
13+
import { getStorage } from "firebase-admin/storage"
14+
15+
export const app: App = initializeApp()
16+
export const db = getFirestore(app)
17+
export const storage = getStorage(app)
18+
export const auth = getAuth(app)
219

3-
admin.initializeApp()
4-
export const db = admin.firestore()
5-
export const storage = admin.storage()
6-
export const auth = admin.auth()
7-
export { admin }
820
// Gotta use the same Timestamp class as the admin package.
9-
export const Timestamp = admin.firestore.Timestamp
10-
export type Timestamp = admin.firestore.Timestamp
11-
export const FieldValue = admin.firestore.FieldValue
12-
export type FieldValue = admin.firestore.FieldValue
13-
export const FieldPath = admin.firestore.FieldPath
14-
export type FieldPath = admin.firestore.FieldPath
15-
export type DocumentData = admin.firestore.DocumentData
16-
export type QueryDocumentSnapshot = admin.firestore.QueryDocumentSnapshot
17-
export type DocumentSnapshot = admin.firestore.DocumentSnapshot
18-
export type QuerySnapshot = admin.firestore.QuerySnapshot
21+
export { Timestamp, FieldValue, FieldPath }
22+
export type {
23+
DocumentData,
24+
QueryDocumentSnapshot,
25+
DocumentSnapshot,
26+
QuerySnapshot
27+
}
1928

20-
// Extreme hack to extract the File type from the admin storage package. For
21-
// some reason admin.storage does not resolve the storage namespace, as
22-
// admin.firestore does.
29+
// Extreme hack to extract the File type from the admin storage package.
2330
export type File = ReturnType<
24-
ReturnType<ReturnType<typeof admin.storage>["bucket"]>["file"]
31+
ReturnType<ReturnType<typeof getStorage>["bucket"]>["file"]
2532
>

functions/src/notifications/cleanupNotifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as functions from "firebase-functions"
2-
import * as admin from "firebase-admin"
2+
import { getFirestore } from "firebase-admin/firestore"
33
import { Timestamp } from "../firebase"
44

55
const RETENTION_PERIOD_DAYS = 60
66

77
// Get a reference to the Firestore database
8-
const db = admin.firestore()
8+
const db = getFirestore()
99

1010
// TODO
1111
// 1.) Do we actually want to delete old notifications? (check with Matt V)

0 commit comments

Comments
 (0)