Skip to content

Commit 2a30f8a

Browse files
committed
Update to use new node v10 firebase-admin syntax
1 parent d8483bb commit 2a30f8a

17 files changed

+73
-66
lines changed

components/db/useUpcoming.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @jest-environment node
3-
*/
4-
51
import { renderHook, waitFor } from "@testing-library/react"
62
import { terminateFirebase, testDb, testTimestamp } from "../../tests/testUtils"
73
import { useUpcomingBills } from "./useUpcomingBills"

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,
@@ -176,7 +176,7 @@ const extractAudioFromVideo = async (
176176
})
177177

178178
// Upload the audio file
179-
const bucket = admin.storage().bucket()
179+
const bucket = storage.bucket()
180180
const audioFileName = `hearing-${EventId}-${Date.now()}.m4a`
181181
const file = bucket.file(audioFileName)
182182

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)

functions/src/notifications/populateBillHistoryNotificationEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
// Import necessary Firebase modules
77
import * as functions from "firebase-functions"
8-
import * as admin from "firebase-admin"
8+
import { getFirestore } from "firebase-admin/firestore"
99
import { Timestamp } from "../firebase"
1010
import { BillHistoryUpdateNotification } from "./types"
1111

1212
// Get a reference to the Firestore database
13-
const db = admin.firestore()
13+
const db = getFirestore()
1414

1515
// Define the populateBillNotificationEvents function
1616
export const populateBillHistoryNotificationEvents = functions.firestore

functions/src/notifications/populateTestimonySubmissionNotificationEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
// Import necessary Firebase modules
77
import * as functions from "firebase-functions"
8-
import * as admin from "firebase-admin"
8+
import { getFirestore } from "firebase-admin/firestore"
99
import { Timestamp } from "../firebase"
1010
import { TestimonySubmissionNotification } from "./types"
1111

1212
// Get a reference to the Firestore database
13-
const db = admin.firestore()
13+
const db = getFirestore()
1414

1515
// Define the populateOrgNotificationEvents function
1616
export const populateTestimonySubmissionNotificationEvents = functions.firestore

functions/src/notifications/publishNotifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Import necessary Firebase modules
77
import * as functions from "firebase-functions"
8-
import * as admin from "firebase-admin"
8+
import { getFirestore } from "firebase-admin/firestore"
99
import { Timestamp } from "../firebase"
1010
import {
1111
BillHistoryUpdateNotification,
@@ -16,7 +16,7 @@ import {
1616
import { cloneDeep } from "lodash"
1717

1818
// Get a reference to the Firestore database
19-
const db = admin.firestore()
19+
const db = getFirestore()
2020

2121
const createNotificationFields = (
2222
entity: BillHistoryUpdateNotification | TestimonySubmissionNotification

functions/src/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import type * as firebase from "./firebase"
1+
import { auth, db } from "./firebase"
22
import type * as api from "./malegislature"
3+
import { app } from "./firebase"
34

4-
export type Database = typeof firebase.db
5-
export type Admin = typeof firebase.admin
6-
export type Auth = typeof firebase.auth
7-
export type Firebase = typeof firebase
5+
export type Database = typeof db
6+
export type Admin = typeof auth
7+
export type Auth = typeof auth
8+
export type Firebase = typeof app
89
export type Api = typeof api
910

1011
export type Context = {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"dompurify": "^2.3.10",
9292
"express": "^4.18.2",
9393
"firebase": "9.6.10",
94+
"firebase-admin": "^11.11.1",
9495
"fuse.js": "6.5.3",
9596
"handlebars": "^4.7.8",
9697
"i18next": "^23.5.1",
@@ -176,7 +177,6 @@
176177
"eslint-plugin-i18next": "^6.0.3",
177178
"eslint-plugin-jsx-a11y": "^6.9.0",
178179
"file-loader": "^6.2.0",
179-
"firebase-admin": "^11.11.1",
180180
"firebase-tools": "^13.23.0",
181181
"ini": "^1.3.5",
182182
"inquirer": "^6.5.1",
@@ -200,4 +200,4 @@
200200
"resolutions": {
201201
"jackspeak": "2.1.1"
202202
}
203-
}
203+
}

0 commit comments

Comments
 (0)