Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This change migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder from the deprecated functions.config() API to the new params API.

The following changes were made:

  • Replaced functions.config() with defineString for non-sensitive configuration and defineSecret for sensitive values like API keys and passwords.
  • Updated function definitions to use runWith({secrets: [...]}) to grant them access to the defined secrets at runtime.
  • Refactored the code to move the initialization of API clients (e.g., for Stripe, PayPal, Algolia, Nodemailer) from the global scope into the function handlers. This is necessary because parameter values are only accessible at runtime.
  • Updated all relevant README.md files to replace firebase functions:config:set commands with the new instructions for either creating a .env file or using firebase functions:secrets:set.
  • Updated all code comments that referred to the old functions.config() variables.

PR created automatically by Jules for task 6616826145812791659 started by @jhuleatt

Migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder that use the functions.config API to the new params API.

This includes:
- Replacing `functions.config()` with `defineString` for non-sensitive data and `defineSecret` for sensitive data.
- Updating function definitions with `runWith({secrets: [...]})` where necessary.
- Moving API client initializations from the global scope into function handlers to ensure that parameter values are available at runtime.
- Updating all relevant README.md files and code comments to reflect the new configuration methods.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

Comment on lines 29 to 35
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: GMAIL_EMAIL.value(),
pass: GMAIL_PASSWORD.value(),
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this initialization global as it used to be. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

Comment on lines 34 to 40
const client = new Client({
cloud: {
id: ELASTIC_ID.value(),
username: ELASTIC_USERNAME.value(),
password: ELASTIC_PASSWORD.value(),
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of elastic client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

// Update the search index every time a blog post is written.
exports.onNoteCreated = functions.firestore.document('notes/{noteId}').onCreate((snap, context) => {
exports.onNoteCreated = functions.runWith({secrets: ["ALGOLIA_ID", "ALGOLIA_ADMIN_KEY"]}).firestore.document('notes/{noteId}').onCreate((snap, context) => {
const client = algoliasearch(ALGOLIA_ID.value(), ALGOLIA_ADMIN_KEY.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

// Update the search index every time a blog post is written.
exports.onNoteWritten = functions.firestore.document('notes/{noteId}').onWrite(async (snap, context) => {
exports.onNoteWritten = functions.runWith({secrets: ["TYPESENSE_ADMIN_API_KEY"]}).firestore.document('notes/{noteId}').onWrite(async (snap, context) => {
const client = new Typesense.Client({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

exports.indexentry = functions.database.ref('/blog-posts/{blogid}/text').onWrite(
exports.indexentry = functions.runWith({secrets: ["ALGOLIA_APP_ID", "ALGOLIA_API_KEY"]}).database.ref('/blog-posts/{blogid}/text').onWrite(
async (data, context) => {
const client = algoliasearch(ALGOLIA_APP_ID.value(), ALGOLIA_API_KEY.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

// visit the URL for this Function to request tokens
exports.authgoogleapi = functions.https.onRequest((req, res) => {
exports.authgoogleapi = functions.runWith({secrets: ["GOOGLEAPI_CLIENT_ID", "GOOGLEAPI_CLIENT_SECRET"]}).https.onRequest((req, res) => {
const functionsOauthClient = new OAuth2Client(GOOGLEAPI_CLIENT_ID.value(), GOOGLEAPI_CLIENT_SECRET.value(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn


const accessToken = match[1];
try {
const oktaJwtVerifier = new OktaJwtVerifier({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

exports.pay = functions.https.onRequest((req, res) => {
exports.pay = functions.runWith({secrets: ["PAYPAL_CLIENT_ID", "PAYPAL_CLIENT_SECRET"]}).https.onRequest((req, res) => {
// Configure your environment
paypal.configure({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn


// Sends a welcome email to the given user.
async function sendWelcomeEmail(email, displayName) {
const mailTransport = nodemailer.createTransport({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

*/
exports.redirect = functions.https.onRequest((req, res) => {
exports.redirect = functions.runWith({secrets: ["SPOTIFY_CLIENT_ID", "SPOTIFY_CLIENT_SECRET"]}).https.onRequest((req, res) => {
const Spotify = new SpotifyWebApi({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

*/
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
exports.createStripeCustomer = functions.runWith({secrets: ["STRIPE_SECRET"]}).auth.user().onCreate(async (user) => {
const stripe = new Stripe(STRIPE_SECRET.value(), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

* Sends an email pointing to the Upgraded App survey.
*/
async function sendSurveyEmail(email, name) {
const mailTransport = nodemailer.createTransport(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

// Shorten URL written to /links/{linkID}.
exports.shortenUrl = functions.database.ref('/links/{linkID}').onCreate(async (snap) => {
exports.shortenUrl = functions.runWith({secrets: ["BITLY_ACCESS_TOKEN"]}).database.ref('/links/{linkID}').onCreate(async (snap) => {
const bitly = new BitlyClient(BITLY_ACCESS_TOKEN.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

exports.getChannelInfo = functions.https.onRequest(
exports.getChannelInfo = functions.runWith({secrets: ["YOUTUBE_KEY"]}).https.onRequest(
async (request, response) => {
const youtube = google.youtube({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn

Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API.

- Updates all instances of functions.config() to use defineString() or defineSecret().
- Moves client initializations that depend on params into the function bodies.
- Updates variable names to lowerCamelCase to follow the recommended style.
- Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set.
- Verifies that all 1st-gen samples compile successfully after the changes.
Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API.

- Updates all instances of functions.config() to use defineString() or defineSecret().
- Moves client initializations that depend on params into the function bodies.
- Updates variable names to lowerCamelCase to follow the recommended style.
- Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set.
- Verifies that all 1st-gen samples compile successfully after the changes.
- Corrects the `runWith` secrets configuration to pass the secret objects directly.
- Refactors all client initializations to use the `onInit` hook.
- Fixes the `google-sheet-sync` trigger.
- Fixes inconsistent naming in `okta-auth` and `testlab-to-slack`.
- Fixes inefficient `cors` initialization in `okta-auth`.
@jhuleatt jhuleatt marked this pull request as ready for review November 12, 2025 14:50
@jhuleatt jhuleatt merged commit eafb342 into functions-v7-test Nov 12, 2025
2 checks passed
jhuleatt added a commit that referenced this pull request Nov 12, 2025
* use the test build of functions v7

* use 7.0.0

* feat: Migrate Node-1st-gen samples from functions.config to params (#1229)

* feat: Migrate Node-1st-gen samples from functions.config to params

Migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder that use the functions.config API to the new params API.

This includes:
- Replacing `functions.config()` with `defineString` for non-sensitive data and `defineSecret` for sensitive data.
- Updating function definitions with `runWith({secrets: [...]})` where necessary.
- Moving API client initializations from the global scope into function handlers to ensure that parameter values are available at runtime.
- Updating all relevant README.md files and code comments to reflect the new configuration methods.

* feat(Node-1st-gen): Migrate functions.config to params

Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API.

- Updates all instances of functions.config() to use defineString() or defineSecret().
- Moves client initializations that depend on params into the function bodies.
- Updates variable names to lowerCamelCase to follow the recommended style.
- Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set.
- Verifies that all 1st-gen samples compile successfully after the changes.

* feat(Node-1st-gen): Migrate functions.config to params

Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API.

- Updates all instances of functions.config() to use defineString() or defineSecret().
- Moves client initializations that depend on params into the function bodies.
- Updates variable names to lowerCamelCase to follow the recommended style.
- Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set.
- Verifies that all 1st-gen samples compile successfully after the changes.
- Corrects the `runWith` secrets configuration to pass the secret objects directly.
- Refactors all client initializations to use the `onInit` hook.
- Fixes the `google-sheet-sync` trigger.
- Fixes inconsistent naming in `okta-auth` and `testlab-to-slack`.
- Fixes inefficient `cors` initialization in `okta-auth`.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant