Skip to content

Commit b7665af

Browse files
angular-robotjosephperrott
authored andcommitted
build: update dependency firebase-functions to v6 (#2304)
Closes #2302 as a pr takeover PR Close #2304
1 parent 711cc8d commit b7665af

File tree

10 files changed

+68
-52
lines changed

10 files changed

+68
-52
lines changed

apps/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ nodejs_binary(
4646
# Firebase function files
4747
"//apps/functions:functions_compiled",
4848
"//apps/functions:functions_files",
49+
50+
# Firebase hosted application files
51+
"//apps/code-of-conduct:application_files",
4952
],
5053
entry_point = "@npm//:node_modules/firebase-tools/lib/bin/firebase.js",
5154
templated_args = [

apps/functions/code-of-conduct/blockUser.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
import {RequestError} from '@octokit/request-error';
1010

1111
/** Blocks the requested user from Github for the prescribed amount of time. */
12-
export const blockUser = functions
13-
.runWith({
12+
export const blockUser = functions.https.onCall<BlockUserParams>(
13+
{
1414
secrets: ['ANGULAR_ROBOT_APP_PRIVATE_KEY', 'ANGULAR_ROBOT_APP_ID'],
15-
})
16-
.https.onCall(async ({comments, blockUntil, context, username}: BlockUserParams, request) => {
15+
},
16+
async (request) => {
17+
const {comments, blockUntil, context, username} = request.data;
1718
// Ensure that the request was authenticated.
1819
checkAuthenticationAndAccess(request);
1920

@@ -46,4 +47,5 @@ export const blockUser = functions
4647
blockedOn: new Date(),
4748
blockUntil: new Date(blockUntil),
4849
});
49-
});
50+
},
51+
);

apps/functions/code-of-conduct/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export interface BlockedUser extends admin.firestore.DocumentData {
5050
}
5151

5252
/** A CallableContext which is confirmed to already have an authorized user. */
53-
interface AuthenticatedCallableContext extends functions.https.CallableContext {
54-
auth: NonNullable<functions.https.CallableContext['auth']>;
53+
interface AuthenticatedCallableContext extends functions.https.CallableRequest {
54+
auth: NonNullable<functions.https.CallableRequest['auth']>;
5555
}
5656

5757
/** Verify that the incoming request is authenticated and authorized for access. */
5858
export function checkAuthenticationAndAccess(
59-
context: functions.https.CallableContext,
59+
context: functions.https.CallableRequest,
6060
): asserts context is AuthenticatedCallableContext {
6161
// Authentication is managed by firebase as this occurs within the Firebase functions context.
6262
// If the user is unauthenticted, the authorization object will be undefined.

apps/functions/code-of-conduct/syncUsers.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ import {
66
import * as functions from 'firebase-functions';
77

88
/** Runs the synchronization of blocked users from Github to the blocked users once per day. */
9-
export const dailySync = functions
10-
.runWith({
9+
export const dailySync = functions.scheduler.onSchedule(
10+
{
1111
secrets: ['ANGULAR_ROBOT_APP_PRIVATE_KEY', 'ANGULAR_ROBOT_APP_ID'],
12-
})
13-
.pubsub.schedule('every day 08:00')
14-
.timeZone('America/Los_Angeles')
15-
.onRun(syncUsers);
12+
schedule: 'every day 08:00',
13+
timeZone: 'America/Los_Angeles',
14+
},
15+
syncUsers,
16+
);
1617

1718
/** Runs the synchronization of blocked users from Github to the blocked users list on demand. */
18-
export const syncUsersFromGithub = functions
19-
.runWith({
19+
export const syncUsersFromGithub = functions.https.onCall(
20+
{
2021
secrets: ['ANGULAR_ROBOT_APP_PRIVATE_KEY', 'ANGULAR_ROBOT_APP_ID'],
21-
})
22-
.https.onCall(async (_: void, context) => {
23-
await checkAuthenticationAndAccess(context);
22+
},
23+
async (request) => {
24+
await checkAuthenticationAndAccess(request);
2425
await syncUsers();
25-
});
26+
},
27+
);
2628

2729
async function syncUsers() {
2830
/** The authenticated Github client for performing actions. */

apps/functions/code-of-conduct/unblockUser.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@ import * as admin from 'firebase-admin';
1010
import * as functions from 'firebase-functions';
1111

1212
/** Unblocks the provided user from Github, clearing their records from our listing. */
13-
export const unblockUser = functions
14-
.runWith({
13+
export const unblockUser = functions.https.onCall<UnblockUserParams>(
14+
{
1515
secrets: ['ANGULAR_ROBOT_APP_PRIVATE_KEY', 'ANGULAR_ROBOT_APP_ID'],
16-
})
17-
.https.onCall(async ({username}: UnblockUserParams, request) => {
16+
},
17+
async (request) => {
18+
const {username} = request.data;
1819
await checkAuthenticationAndAccess(request);
1920
/** The authenticated Github client for performing actions. */
2021
const github = await getAuthenticatedGithubClient();
2122
/** The Firestore record of the user to be unblocked */
2223
const doc = await blockedUsersCollection().doc(username).get();
2324

2425
await performUnblock(github, doc);
25-
});
26+
},
27+
);
2628

2729
/** Unblocks the all listed users who's block has expired, runs daily. */
28-
export const dailyUnblock = functions
29-
.runWith({
30+
export const dailyUnblock = functions.scheduler.onSchedule(
31+
{
32+
schedule: 'every day 08:00',
3033
secrets: ['ANGULAR_ROBOT_APP_PRIVATE_KEY', 'ANGULAR_ROBOT_APP_ID'],
31-
})
32-
.pubsub.schedule('every day 08:00')
33-
.timeZone('America/Los_Angeles')
34-
.onRun(async () => {
34+
timeZone: 'America/Los_Angeles',
35+
},
36+
async () => {
3537
/** The authenticated Github client for performing actions. */
3638
const github = await getAuthenticatedGithubClient();
3739
/** The Firestore records for all users who's block has expired. */
@@ -40,7 +42,8 @@ export const dailyUnblock = functions
4042
.get();
4143

4244
await Promise.all(usersToUnblock.docs.map(async (user) => performUnblock(github, user)));
43-
});
45+
},
46+
);
4447

4548
async function performUnblock(github: Octokit, doc: admin.firestore.DocumentSnapshot<BlockedUser>) {
4649
await github.orgs

apps/functions/dns-redirecting/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as functions from 'firebase-functions';
22

3-
export const dnsRedirecting = functions
4-
.runWith({
3+
export const dnsRedirecting = functions.https.onRequest(
4+
{
55
invoker: 'public',
66
timeoutSeconds: 5,
77
minInstances: 1,
88
maxInstances: 2,
9-
})
10-
.https.onRequest(async (request, response) => {
9+
},
10+
async (request, response) => {
1111
/** The type of redirect to use, defaulting to a 301 permanent redirect. */
1212
let redirectType = 301;
1313
/** The hostname that was used for the request. */
@@ -49,4 +49,5 @@ export const dnsRedirecting = functions
4949
response.send(
5050
`No redirect defined for ${request.protocol}://${request.hostname}${request.originalUrl}`,
5151
);
52-
});
52+
},
53+
);

apps/functions/githubWebhook/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {handleLabelEvent} from './label.js';
99
* webhook to ensure it is a valid request from Github, and then delegates processing of a payload
1010
* to one of the other githubWebhook functions.
1111
*/
12-
export const githubWebhook = functions
13-
.runWith({invoker: 'public', timeoutSeconds: 30, minInstances: 1})
14-
.https.onRequest(async (request, response) => {
12+
export const githubWebhook = functions.https.onRequest(
13+
{invoker: 'public', timeoutSeconds: 30, minInstances: 1},
14+
async (request, response) => {
1515
if (request.method !== 'POST') {
1616
response.status(405);
1717
response.send('Requests must be made using the POST method.');
@@ -51,4 +51,5 @@ export const githubWebhook = functions
5151
}
5252

5353
response.end();
54-
});
54+
},
55+
);

apps/functions/ng-dev/ng-dev-token.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import * as admin from 'firebase-admin';
44
* Request a short lived ng-dev token. If granted, we rely on session cookies as this token. The token
55
* is to be used for all requests to the ng-dev service.
66
*/
7-
export const ngDevTokenRequest = functions.https.onCall(
8-
async ({idToken}: {idToken: string}, context: functions.https.CallableContext) => {
9-
if (!context.auth) {
7+
export const ngDevTokenRequest = functions.https.onCall<{idToken: string}>(
8+
async (request: functions.https.CallableRequest) => {
9+
const {idToken} = request.data;
10+
if (!request.auth) {
1011
// Throwing an HttpsError so that the client gets the error details.
1112
throw new functions.https.HttpsError(
1213
'unauthenticated',
@@ -31,12 +32,15 @@ export const ngDevTokenRequest = functions.https.onCall(
3132
/**
3233
* Validate the provided token is still valid.
3334
*/
34-
export const ngDevTokenValidate = functions.https.onCall(validateToken);
35+
export const ngDevTokenValidate = functions.https.onCall<{token: string}>(async (request) => {
36+
return await validateToken(request.data);
37+
});
3538

3639
/**
3740
* Revokes the all tokens for the user of the provided token.
3841
*/
39-
export const ngDevRevokeToken = functions.https.onCall(async ({token}: {token: string}) => {
42+
export const ngDevRevokeToken = functions.https.onCall<{token: string}>(async (request) => {
43+
const {token} = request.data;
4044
await admin
4145
.auth()
4246
.verifySessionCookie(token)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"fast-glob": "^3.3.2",
125125
"firebase": "10.13.1",
126126
"firebase-admin": "12.4.0",
127-
"firebase-functions": "^5.0.0",
127+
"firebase-functions": "^6.0.0",
128128
"firebase-tools": "^13.0.0",
129129
"folder-hash": "^4.0.2",
130130
"font-color-contrast": "^11.1.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ __metadata:
324324
fast-glob: "npm:^3.3.2"
325325
firebase: "npm:10.13.1"
326326
firebase-admin: "npm:12.4.0"
327-
firebase-functions: "npm:^5.0.0"
327+
firebase-functions: "npm:^6.0.0"
328328
firebase-tools: "npm:^13.0.0"
329329
folder-hash: "npm:^4.0.2"
330330
font-color-contrast: "npm:^11.1.0"
@@ -7330,9 +7330,9 @@ __metadata:
73307330
languageName: node
73317331
linkType: hard
73327332

7333-
"firebase-functions@npm:^5.0.0":
7334-
version: 5.1.1
7335-
resolution: "firebase-functions@npm:5.1.1"
7333+
"firebase-functions@npm:^6.0.0":
7334+
version: 6.0.0
7335+
resolution: "firebase-functions@npm:6.0.0"
73367336
dependencies:
73377337
"@types/cors": "npm:^2.8.5"
73387338
"@types/express": "npm:4.17.3"
@@ -7343,7 +7343,7 @@ __metadata:
73437343
firebase-admin: ^11.10.0 || ^12.0.0
73447344
bin:
73457345
firebase-functions: lib/bin/firebase-functions.js
7346-
checksum: 10c0/7b2f9622ea034d5034311a4c5c142db9dd43526a21b6bc3947728bbc081c1378ad505c06e0954fb065bf419973ed513868888471eb63b1fa59c473e893075e44
7346+
checksum: 10c0/80e76db5c626fe60f7bd8f80177312785b38c24346dbec6021e7fec9277105a28e9817a4b5cfa34456f481a9b30426a7d71308e5e85bbc5d9eef4051a391b61a
73477347
languageName: node
73487348
linkType: hard
73497349

0 commit comments

Comments
 (0)