Skip to content

Commit

Permalink
Update dependencies (firebase-functions v4 and others) (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuleatt authored Nov 9, 2022
1 parent 786d3cc commit 81700d7
Show file tree
Hide file tree
Showing 102 changed files with 3,328 additions and 3,315 deletions.
10 changes: 5 additions & 5 deletions 2nd-gen/alerts-to-discord/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.1.0",
"firebase-functions": "^3.24.0",
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.2",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/node": "^17.0.31",
"eslint": "^8.9.0",
"@types/node": "^17.0.45",
"eslint": "^8.26.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
"firebase-functions-test": "^3.0.0"
},
"private": true
}
2 changes: 1 addition & 1 deletion 2nd-gen/auth-blocking-functions/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
env: {
es6: true,
es2020: true,
node: true,
},
extends: [
Expand Down
16 changes: 10 additions & 6 deletions 2nd-gen/auth-blocking-functions/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

const {beforeUserCreated, beforeUserSignedIn, HttpsError} = require("firebase-functions/v2/identity");
const {
beforeUserCreated,
beforeUserSignedIn,
HttpsError,
} = require("firebase-functions/v2/identity");
const {admin} = require("firebase-admin");

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

// [START v2domainHttpsError]
// Only users of a specific domain can sign up.
if (!user?.email?.includes('@acme.com')) {
// Throwing an HttpsError so that the Auth service rejects the account creation.
throw new HttpsError('invalid-argument', "Unauthorized email");
if (!user?.email?.includes("@acme.com")) {
// Throw an HttpsError so that Firebase Auth rejects the account creation.
throw new HttpsError("invalid-argument", "Unauthorized email");
}
// [END v2domainHttpsError]
});
Expand All @@ -58,8 +62,8 @@ exports.checkforban = beforeUserSignedIn(async (event) => {
// [START v2bannedHttpsError]
// Checking that the document exists for the email address.
if (doc.exists) {
// Throwing an HttpsError so that the Auth service rejects the account sign in.
throw new HttpsError('invalid-argument', "Unauthorized email");
// Throw an HttpsError so that Firebase Auth rejects the account sign in.
throw new HttpsError("invalid-argument", "Unauthorized email");
}
// [END v2bannedHttpsError]
});
Expand Down
8 changes: 4 additions & 4 deletions 2nd-gen/auth-blocking-functions/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.1.0",
"firebase-functions": "^3.22.0"
"firebase-admin": "^10.3.0",
"firebase-functions": "^3.24.1"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint": "^8.26.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
"firebase-functions-test": "^0.2.3"
},
"private": true
}
2 changes: 1 addition & 1 deletion 2nd-gen/callable-functions/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
env: {
es6: true,
es2020: true,
node: true,
},
extends: [
Expand Down
8 changes: 4 additions & 4 deletions 2nd-gen/callable-functions/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"dependencies": {
"bad-words": "^3.0.4",
"capitalize-sentence": "^0.1.5",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.2"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint": "^8.26.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
"firebase-functions-test": "^3.0.0"
},
"private": true
}
2 changes: 1 addition & 1 deletion 2nd-gen/custom-events/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
env: {
es6: true,
es2020: true,
node: true,
},
extends: [
Expand Down
6 changes: 3 additions & 3 deletions 2nd-gen/custom-events/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.0.0",
"firebase-functions": "^3.20.1"
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.2"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint": "^8.26.0",
"eslint-config-google": "^0.14.0"
},
"private": true
Expand Down
2 changes: 1 addition & 1 deletion 2nd-gen/delete-unused-accounts-cron/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
env: {
es6: true,
es2020: true,
node: true,
},
extends: [
Expand Down
66 changes: 43 additions & 23 deletions 2nd-gen/delete-unused-accounts-cron/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,65 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
"use strict";

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

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

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

// [START accountcleanup]
// Run once a day at midnight, to clean up the users
// Manually run the task here https://console.cloud.google.com/cloudscheduler
exports.accountcleanup = onSchedule('every day 00:00', async (event) => {
exports.accountcleanup = onSchedule("every day 00:00", async (event) => {
// Fetch all user details.
const inactiveUsers = await getInactiveUsers();

// Use a pool so that we delete maximum `MAX_CONCURRENT` users in parallel.
const promisePool = new PromisePool(() => deleteInactiveUser(inactiveUsers), MAX_CONCURRENT);
const promisePool = new PromisePool(
() => deleteInactiveUser(inactiveUsers),
MAX_CONCURRENT,
);
await promisePool.start();
logger.log('User cleanup finished');

logger.log("User cleanup finished");
});
// [END accountcleanup]

// [START deleteInactiveUser]
// Deletes one inactive user from the list.
/**
* Deletes one inactive user from the list.
* @param {admin.auth.UserRecord[]} inactiveUsers
* @return {null | Promise<void>}
*/
function deleteInactiveUser(inactiveUsers) {
if (inactiveUsers.length > 0) {
const userToDelete = inactiveUsers.pop();

// Delete the inactive user.
return admin.auth().deleteUser(userToDelete.uid).then(() => {
return logger.log(
'Deleted user account',
userToDelete.uid,
'because of inactivity'
"Deleted user account",
userToDelete.uid,
"because of inactivity",
);
}).catch((error) => {
return logger.error(
'Deletion of inactive user account',
userToDelete.uid,
'failed:',
error
"Deletion of inactive user account",
userToDelete.uid,
"failed:",
error,
);
});
} else {
Expand All @@ -73,20 +82,31 @@ function deleteInactiveUser(inactiveUsers) {

// [START getInactiveUsers]
// Returns the list of all inactive users.
/**
*
* @param {admin.auth.UserRecord[]} [users] the current list of inactive users
* @param {string} [nextPageToken]
* @return {Promise<admin.auth.UserRecord[]>}
*/
async function getInactiveUsers(users = [], nextPageToken) {
const result = await admin.auth().listUsers(1000, nextPageToken);
// Find users that have not signed in in the last 30 days.
const inactiveUsers = result.users.filter(
user => Date.parse(user.metadata.lastRefreshTime || user.metadata.lastSignInTime) < (Date.now() - 30 * 24 * 60 * 60 * 1000));

// Concat with list of previously found inactive users if there was more than 1000 users.
(user) =>
Date.parse(
user.metadata.lastRefreshTime || user.metadata.lastSignInTime,
) <
Date.now() - 30 * 24 * 60 * 60 * 1000,
);

// Add to the list of previously found inactive users.
users = users.concat(inactiveUsers);

// If there are more users to fetch we fetch them.
if (result.pageToken) {
return getInactiveUsers(users, result.pageToken);
}

return users;
}
// [END getInactiveUsers]
Expand Down
8 changes: 4 additions & 4 deletions 2nd-gen/delete-unused-accounts-cron/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "Periodically delete unused Firebase accounts",
"dependencies": {
"es6-promise-pool": "^2.5.0",
"firebase-admin": "^10.2.0",
"firebase-functions": "^3.23.0"
"firebase-admin": "^10.3.0",
"firebase-functions": "^3.24.1"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-promise": "^4.2.1"
"eslint-plugin-promise": "^4.3.1"
},
"scripts": {
"lint": "./node_modules/.bin/eslint --max-warnings=0 .",
Expand All @@ -17,7 +17,7 @@
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"compile": "cp ../../tsconfig.template.json ./tsconfig-compile.json && tsc --project tsconfig-compile.json"
"compile": "cp ../../../tsconfig.template.json ./tsconfig-compile.json && tsc --project tsconfig-compile.json"
},
"engines": {
"node": "16"
Expand Down
14 changes: 14 additions & 0 deletions 2nd-gen/instrument-with-opentelemetry/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
env: {
es2020: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
Loading

0 comments on commit 81700d7

Please sign in to comment.