Skip to content

Commit 81700d7

Browse files
authored
Update dependencies (firebase-functions v4 and others) (#1024)
1 parent 786d3cc commit 81700d7

File tree

102 files changed

+3328
-3315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3328
-3315
lines changed

2nd-gen/alerts-to-discord/functions/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
},
1616
"main": "index.js",
1717
"dependencies": {
18-
"firebase-admin": "^10.1.0",
19-
"firebase-functions": "^3.24.0",
18+
"firebase-admin": "^11.2.0",
19+
"firebase-functions": "^4.0.2",
2020
"node-fetch": "^2.6.7"
2121
},
2222
"devDependencies": {
23-
"@types/node": "^17.0.31",
24-
"eslint": "^8.9.0",
23+
"@types/node": "^17.0.45",
24+
"eslint": "^8.26.0",
2525
"eslint-config-google": "^0.14.0",
26-
"firebase-functions-test": "^0.2.0"
26+
"firebase-functions-test": "^3.0.0"
2727
},
2828
"private": true
2929
}

2nd-gen/auth-blocking-functions/functions/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
env: {
4-
es6: true,
4+
es2020: true,
55
node: true,
66
},
77
extends: [

2nd-gen/auth-blocking-functions/functions/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
const {beforeUserCreated, beforeUserSignedIn, HttpsError} = require("firebase-functions/v2/identity");
17+
const {
18+
beforeUserCreated,
19+
beforeUserSignedIn,
20+
HttpsError,
21+
} = require("firebase-functions/v2/identity");
1822
const {admin} = require("firebase-admin");
1923

2024
admin.initializeApp();
@@ -32,9 +36,9 @@ exports.validatenewuser = beforeUserCreated((event) => {
3236

3337
// [START v2domainHttpsError]
3438
// Only users of a specific domain can sign up.
35-
if (!user?.email?.includes('@acme.com')) {
36-
// Throwing an HttpsError so that the Auth service rejects the account creation.
37-
throw new HttpsError('invalid-argument', "Unauthorized email");
39+
if (!user?.email?.includes("@acme.com")) {
40+
// Throw an HttpsError so that Firebase Auth rejects the account creation.
41+
throw new HttpsError("invalid-argument", "Unauthorized email");
3842
}
3943
// [END v2domainHttpsError]
4044
});
@@ -58,8 +62,8 @@ exports.checkforban = beforeUserSignedIn(async (event) => {
5862
// [START v2bannedHttpsError]
5963
// Checking that the document exists for the email address.
6064
if (doc.exists) {
61-
// Throwing an HttpsError so that the Auth service rejects the account sign in.
62-
throw new HttpsError('invalid-argument', "Unauthorized email");
65+
// Throw an HttpsError so that Firebase Auth rejects the account sign in.
66+
throw new HttpsError("invalid-argument", "Unauthorized email");
6367
}
6468
// [END v2bannedHttpsError]
6569
});

2nd-gen/auth-blocking-functions/functions/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
},
1515
"main": "index.js",
1616
"dependencies": {
17-
"firebase-admin": "^10.1.0",
18-
"firebase-functions": "^3.22.0"
17+
"firebase-admin": "^10.3.0",
18+
"firebase-functions": "^3.24.1"
1919
},
2020
"devDependencies": {
21-
"eslint": "^8.9.0",
21+
"eslint": "^8.26.0",
2222
"eslint-config-google": "^0.14.0",
23-
"firebase-functions-test": "^0.2.0"
23+
"firebase-functions-test": "^0.2.3"
2424
},
2525
"private": true
2626
}

2nd-gen/callable-functions/functions/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
env: {
4-
es6: true,
4+
es2020: true,
55
node: true,
66
},
77
extends: [

2nd-gen/callable-functions/functions/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"dependencies": {
1919
"bad-words": "^3.0.4",
2020
"capitalize-sentence": "^0.1.5",
21-
"firebase-admin": "^10.0.2",
22-
"firebase-functions": "^3.18.0"
21+
"firebase-admin": "^11.2.0",
22+
"firebase-functions": "^4.0.2"
2323
},
2424
"devDependencies": {
25-
"eslint": "^8.9.0",
25+
"eslint": "^8.26.0",
2626
"eslint-config-google": "^0.14.0",
27-
"firebase-functions-test": "^0.2.0"
27+
"firebase-functions-test": "^3.0.0"
2828
},
2929
"private": true
3030
}

2nd-gen/custom-events/functions/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
env: {
4-
es6: true,
4+
es2020: true,
55
node: true,
66
},
77
extends: [

2nd-gen/custom-events/functions/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
},
1717
"main": "index.js",
1818
"dependencies": {
19-
"firebase-admin": "^10.0.0",
20-
"firebase-functions": "^3.20.1"
19+
"firebase-admin": "^11.2.0",
20+
"firebase-functions": "^4.0.2"
2121
},
2222
"devDependencies": {
23-
"eslint": "^8.9.0",
23+
"eslint": "^8.26.0",
2424
"eslint-config-google": "^0.14.0"
2525
},
2626
"private": true

2nd-gen/delete-unused-accounts-cron/functions/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
env: {
4-
es6: true,
4+
es2020: true,
55
node: true,
66
},
77
extends: [

2nd-gen/delete-unused-accounts-cron/functions/index.js

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,65 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
'use strict';
16+
"use strict";
1717

1818
// [START all]
1919
// [START import]
20-
// The Cloud Functions for Firebase SDK to create v2 Cloud Functions and set up triggers.
21-
const { onSchedule } = require('firebase-functions/v2/scheduler');
22-
const { logger } = require('firebase-functions');
20+
// The Cloud Functions for Firebase SDK to set up triggers and logging.
21+
const {onSchedule} = require("firebase-functions/v2/scheduler");
22+
const {logger} = require("firebase-functions");
2323

2424
// The Firebase Admin SDK to delete inactive users.
25-
const admin = require('firebase-admin');
25+
const admin = require("firebase-admin");
2626
admin.initializeApp();
2727

2828
// The es6-promise-pool to limit the concurrency of promises.
29-
const PromisePool = require('es6-promise-pool').default;
29+
const PromisePool = require("es6-promise-pool").default;
3030
// Maximum concurrent account deletions.
3131
const MAX_CONCURRENT = 3;
3232
// [END import]
3333

3434
// [START accountcleanup]
3535
// Run once a day at midnight, to clean up the users
3636
// Manually run the task here https://console.cloud.google.com/cloudscheduler
37-
exports.accountcleanup = onSchedule('every day 00:00', async (event) => {
37+
exports.accountcleanup = onSchedule("every day 00:00", async (event) => {
3838
// Fetch all user details.
3939
const inactiveUsers = await getInactiveUsers();
40+
4041
// Use a pool so that we delete maximum `MAX_CONCURRENT` users in parallel.
41-
const promisePool = new PromisePool(() => deleteInactiveUser(inactiveUsers), MAX_CONCURRENT);
42+
const promisePool = new PromisePool(
43+
() => deleteInactiveUser(inactiveUsers),
44+
MAX_CONCURRENT,
45+
);
4246
await promisePool.start();
43-
logger.log('User cleanup finished');
47+
48+
logger.log("User cleanup finished");
4449
});
4550
// [END accountcleanup]
4651

4752
// [START deleteInactiveUser]
48-
// Deletes one inactive user from the list.
53+
/**
54+
* Deletes one inactive user from the list.
55+
* @param {admin.auth.UserRecord[]} inactiveUsers
56+
* @return {null | Promise<void>}
57+
*/
4958
function deleteInactiveUser(inactiveUsers) {
5059
if (inactiveUsers.length > 0) {
5160
const userToDelete = inactiveUsers.pop();
52-
61+
5362
// Delete the inactive user.
5463
return admin.auth().deleteUser(userToDelete.uid).then(() => {
5564
return logger.log(
56-
'Deleted user account',
57-
userToDelete.uid,
58-
'because of inactivity'
65+
"Deleted user account",
66+
userToDelete.uid,
67+
"because of inactivity",
5968
);
6069
}).catch((error) => {
6170
return logger.error(
62-
'Deletion of inactive user account',
63-
userToDelete.uid,
64-
'failed:',
65-
error
71+
"Deletion of inactive user account",
72+
userToDelete.uid,
73+
"failed:",
74+
error,
6675
);
6776
});
6877
} else {
@@ -73,20 +82,31 @@ function deleteInactiveUser(inactiveUsers) {
7382

7483
// [START getInactiveUsers]
7584
// Returns the list of all inactive users.
85+
/**
86+
*
87+
* @param {admin.auth.UserRecord[]} [users] the current list of inactive users
88+
* @param {string} [nextPageToken]
89+
* @return {Promise<admin.auth.UserRecord[]>}
90+
*/
7691
async function getInactiveUsers(users = [], nextPageToken) {
7792
const result = await admin.auth().listUsers(1000, nextPageToken);
7893
// Find users that have not signed in in the last 30 days.
7994
const inactiveUsers = result.users.filter(
80-
user => Date.parse(user.metadata.lastRefreshTime || user.metadata.lastSignInTime) < (Date.now() - 30 * 24 * 60 * 60 * 1000));
81-
82-
// Concat with list of previously found inactive users if there was more than 1000 users.
95+
(user) =>
96+
Date.parse(
97+
user.metadata.lastRefreshTime || user.metadata.lastSignInTime,
98+
) <
99+
Date.now() - 30 * 24 * 60 * 60 * 1000,
100+
);
101+
102+
// Add to the list of previously found inactive users.
83103
users = users.concat(inactiveUsers);
84-
104+
85105
// If there are more users to fetch we fetch them.
86106
if (result.pageToken) {
87107
return getInactiveUsers(users, result.pageToken);
88108
}
89-
109+
90110
return users;
91111
}
92112
// [END getInactiveUsers]

0 commit comments

Comments
 (0)