Skip to content

Commit 07d3019

Browse files
committed
run prettier
1 parent 6757a45 commit 07d3019

File tree

4 files changed

+83
-52
lines changed

4 files changed

+83
-52
lines changed

.guides/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"args": ["-y", "firebase-tools@latest", "experimental:mcp"]
77
}
88
}
9-
}
9+
}

.guides/setup.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ This guide provides a step-by-step process for setting up a new Firebase Functio
77
Replace the contents of `src/index.ts` (or `index.js`) with the following code to create a simple, modern v2 HTTP endpoint.
88

99
```typescript
10-
import {onRequest} from "firebase-functions/https";
10+
import { onRequest } from "firebase-functions/https";
1111
import * as logger from "firebase-functions/logger";
12-
import {defineString} from "firebase-functions/params";
12+
import { defineString } from "firebase-functions/params";
1313

1414
// Define a configuration parameter for a greeting
15-
const greeting = defineString("GREETING", {default: "Hello"});
16-
17-
export const helloWorld = onRequest(
18-
{ maxInstances: 1 },
19-
async (request, response) => {
20-
logger.info("Request received!", { structuredData: true });
21-
response.send(`${greeting.value()} from Firebase!`);
22-
},
23-
);
15+
const greeting = defineString("GREETING", { default: "Hello" });
16+
17+
export const helloWorld = onRequest({ maxInstances: 1 }, async (request, response) => {
18+
logger.info("Request received!", { structuredData: true });
19+
response.send(`${greeting.value()} from Firebase!`);
20+
});
2421
```
2522

2623
**Key points for the agent:**
27-
* Always import from `firebase-functions/*` for new functions.
28-
* Use `logger` for structured logging.
29-
* Use `defineString`, `defineInt`, `defineSecret` for environment configuration instead of `functions.config()`.
24+
25+
- Always import from `firebase-functions/*` for new functions.
26+
- Use `logger` for structured logging.
27+
- Use `defineString`, `defineInt`, `defineSecret` for environment configuration instead of `functions.config()`.
3028

3129
## 2. Build TypeScript
3230

@@ -41,10 +39,12 @@ npm run build
4139
Use the Firebase Emulators to test your function locally before deploying.
4240

4341
Tell the user to run the following command in a separate terminal window to start the emulators:
42+
4443
```bash
4544
# Start the functions emulator
4645
firebase emulators:start --only functions
4746
```
47+
4848
The user can then interact with the function at the local URL provided by the emulator.
4949

5050
## 4. Deploy to Firebase
@@ -55,4 +55,5 @@ Once testing is complete, deploy the function to your Firebase project.
5555
# Deploy only the functions
5656
firebase deploy --only functions
5757
```
58+
5859
The agent will be prompted to set any parameters defined with `defineString` or other `define` functions that do not have a default value.

.guides/upgrade.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ This guide provides a step-by-step process for migrating a single Cloud Function
44

55
## 1. Identify a 1st-gen function to upgrade
66

7-
Find all 1st-gen functions in the directory. 1st-gen functions used a namespaced API like this:
7+
Find all 1st-gen functions in the directory. 1st-gen functions used a namespaced API like this:
88

99
**Before (1st Gen):**
10+
1011
```typescript
1112
import * as functions from "firebase-functions";
1213

@@ -28,15 +29,17 @@ Ensure your `firebase-functions` and `firebase-admin` SDKs are up-to-date, and y
2829
Update your import statements to use the top-level modules.
2930

3031
**After (2nd Gen):**
32+
3133
```typescript
32-
import {onRequest} from "firebase-functions/https";
34+
import { onRequest } from "firebase-functions/https";
3335
```
3436

3537
## 4. Update Trigger Definition
3638

3739
The SDK is now more modular. Update your trigger definition accordingly.
3840

3941
**After (2nd Gen):**
42+
4043
```typescript
4144
export const webhook = onRequest((request, response) => {
4245
// ...
@@ -48,15 +51,17 @@ Here are other examples of trigger changes:
4851
### Callable Triggers
4952

5053
**Before (1st Gen):**
54+
5155
```typescript
5256
export const getprofile = functions.https.onCall((data, context) => {
5357
// ...
5458
});
5559
```
5660

5761
**After (2nd Gen):**
62+
5863
```typescript
59-
import {onCall} from "firebase-functions/https";
64+
import { onCall } from "firebase-functions/https";
6065

6166
export const getprofile = onCall((request) => {
6267
// ...
@@ -66,15 +71,17 @@ export const getprofile = onCall((request) => {
6671
### Background Triggers (Pub/Sub)
6772

6873
**Before (1st Gen):**
74+
6975
```typescript
7076
export const hellopubsub = functions.pubsub.topic("topic-name").onPublish((message) => {
7177
// ...
7278
});
7379
```
7480

7581
**After (2nd Gen):**
82+
7683
```typescript
77-
import {onMessagePublished} from "firebase-functions/pubsub";
84+
import { onMessagePublished } from "firebase-functions/pubsub";
7885

7986
export const hellopubsub = onMessagePublished("topic-name", (event) => {
8087
// ...
@@ -86,14 +93,17 @@ export const hellopubsub = onMessagePublished("topic-name", (event) => {
8693
Migrate from `functions.config()` to the new `params` module for environment configuration.
8794

8895
**Before (`.runtimeconfig.json`):**
96+
8997
```json
9098
{
9199
"someservice": {
92100
"key": "somesecret"
93101
}
94102
}
95103
```
104+
96105
**And in code (1st Gen):**
106+
97107
```typescript
98108
const SKEY = functions.config().someservice.key;
99109
```
@@ -102,26 +112,31 @@ const SKEY = functions.config().someservice.key;
102112
Define params in your code and set their values during deployment.
103113

104114
**In `index.ts`:**
115+
105116
```typescript
106-
import {defineString} from "firebase-functions/params";
117+
import { defineString } from "firebase-functions/params";
107118

108119
const SOMESERVICE_KEY = defineString("SOMESERVICE_KEY");
109120
```
121+
110122
Use `SOMESERVICE_KEY.value()` to access the value. For secrets like API keys, use `defineSecret`.
111123

112124
**In `index.ts`:**
125+
113126
```typescript
114-
import {defineSecret} from "firebase-functions/params";
127+
import { defineSecret } from "firebase-functions/params";
115128

116129
const SOMESERVICE_KEY = defineSecret("SOMESERVICE_KEY");
117130
```
131+
118132
You will be prompted to set the value on deployment, which is stored securely in Cloud Secret Manager.
119133

120134
## 6. Update Runtime Options
121135

122136
Runtime options are now set directly within the function definition.
123137

124138
**Before (1st Gen):**
139+
125140
```typescript
126141
export const func = functions
127142
.runWith({
@@ -134,8 +149,9 @@ export const func = functions
134149
```
135150

136151
**After (2nd Gen):**
152+
137153
```typescript
138-
import {onRequest} from "firebase-functions/https";
154+
import { onRequest } from "firebase-functions/https";
139155

140156
export const func = onRequest(
141157
{
@@ -153,9 +169,10 @@ export const func = onRequest(
153169
Tell the user these steps to migrate safely:
154170

155171
> To migrate traffic safely:
172+
>
156173
> 1. Rename your new 2nd gen function with a different name.
157174
> 2. Comment out any existing `minInstances` or `maxInstances` config and instead set `maxInstances` to `1` while testing.
158175
> 3. Deploy it alongside the old 1st gen function.
159176
> 4. Gradually introduce traffic to the new function (e.g., via client-side changes or by calling it from the 1st gen function).
160177
> 5. Add back the original `minInstances` and `maxInstances` settings to the 2nd gen function.
161-
> 6. Once you are confident, you can delete the 1st gen function.
178+
> 6. Once you are confident, you can delete the 1st gen function.

.guides/usage.md

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,93 @@
11
## Key Guidelines
22

3-
* Always use 2nd-gen functions for new development.
4-
* Use v1 functions *only* for Analytics, basic Auth, and Test Lab triggers.
5-
* Use `firebase-functions` SDK version 6.0.0 and above
6-
* Use top-level imports (e.g., `firebase-functions/https`). These are 2nd gen by default.
3+
- Always use 2nd-gen functions for new development.
4+
- Use v1 functions _only_ for Analytics, basic Auth, and Test Lab triggers.
5+
- Use `firebase-functions` SDK version 6.0.0 and above
6+
- Use top-level imports (e.g., `firebase-functions/https`). These are 2nd gen by default.
77

88
## Configuration: Use Secret Params for API Keys
99

1010
For sensitive information like API keys (e.g., for LLMs, payment providers, etc.), **always** use `defineSecret`. This stores the value securely in Cloud Secret Manager.
1111

1212
```typescript
13-
import {onRequest} from 'firebase-functions/https';
14-
import {logger} from 'firebase-functions/logger';
15-
import {defineString, defineSecret} from 'firebase-functions/params';
13+
import { onRequest } from "firebase-functions/https";
14+
import { logger } from "firebase-functions/logger";
15+
import { defineString, defineSecret } from "firebase-functions/params";
1616

1717
// Securely define an LLM API key
18-
const LLM_API_KEY = defineSecret('LLM_API_KEY');
18+
const LLM_API_KEY = defineSecret("LLM_API_KEY");
1919

2020
// Example function that uses the secret
2121
export const callLlm = onRequest({ secrets: [LLM_API_KEY] }, async (req, res) => {
2222
const apiKey = LLM_API_KEY.value();
23-
23+
2424
// Use the apiKey to make a call to the LLM service
25-
logger.info('Calling LLM with API key.');
25+
logger.info("Calling LLM with API key.");
2626

2727
// insert code here to call LLM...
28-
29-
res.send('LLM API call initiated.');
28+
29+
res.send("LLM API call initiated.");
3030
});
3131
```
32+
3233
When you deploy a function with `secrets`, the CLI will prompt you to enter the secret's value.
3334

3435
## Use the Firebase Admin SDK
36+
3537
To interact with Firebase services like Firestore, Auth, or RTDB from within your functions, you need to initialize the Firebase Admin SDK. Call `initializeApp` without any arguments so that Application Default Credentials are used.
3638

3739
1. **Install the SDK:**
40+
3841
```bash
3942
npm i firebase-admin
4043
```
4144

4245
2. **Initialize in your code:**
46+
4347
```typescript
44-
import * as admin from 'firebase-admin';
48+
import * as admin from "firebase-admin";
4549
4650
admin.initializeApp();
4751
```
52+
4853
This should be done once at the top level of your `index.ts` file.
4954

5055
## Common Imports
56+
5157
```typescript
5258
// HTTPS, Firestore, RTDB, Scheduled, Storage, Pub/Sub, Auth, Logging, Config
53-
import {onRequest} from 'firebase-functions/https';
54-
import {onDocumentUpdated} from 'firebase-functions/firestore';
55-
import {onValueWritten} from 'firebase-functions/database';
56-
import {onSchedule} from 'firebase-functions/scheduler';
57-
import {onObjectFinalized} from 'firebase-functions/storage';
58-
import {onMessagePublished} from 'firebase-functions/pubsub';
59-
import {beforeUserSignedIn} from 'firebase-functions/identity';
60-
import {logger, onInit} from 'firebase-functions';
61-
import {defineString, defineSecret} from 'firebase-functions/params';
59+
import { onRequest } from "firebase-functions/https";
60+
import { onDocumentUpdated } from "firebase-functions/firestore";
61+
import { onValueWritten } from "firebase-functions/database";
62+
import { onSchedule } from "firebase-functions/scheduler";
63+
import { onObjectFinalized } from "firebase-functions/storage";
64+
import { onMessagePublished } from "firebase-functions/pubsub";
65+
import { beforeUserSignedIn } from "firebase-functions/identity";
66+
import { logger, onInit } from "firebase-functions";
67+
import { defineString, defineSecret } from "firebase-functions/params";
6268
```
6369
64-
## 1st-gen Functions (Legacy Triggers)**
70+
## 1st-gen Functions (Legacy Triggers)\*\*
71+
6572
Use the `firebase-functions/v1` import for Analytics and basic Auth triggers. These aren't supported in 2nd gen.
73+
6674
```typescript
67-
import * as functionsV1 from 'firebase-functions/v1';
75+
import * as functionsV1 from "firebase-functions/v1";
6876
6977
// v1 Analytics trigger
70-
export const onPurchase = functionsV1.analytics.event('purchase').onLog(async (event) => {
71-
logger.info('Purchase event', { value: event.params?.value });
78+
export const onPurchase = functionsV1.analytics.event("purchase").onLog(async (event) => {
79+
logger.info("Purchase event", { value: event.params?.value });
7280
});
7381
7482
// v1 Auth trigger
7583
export const onUserCreate = functionsV1.auth.user().onCreate(async (user) => {
76-
logger.info('User created', { uid: user.uid });
84+
logger.info("User created", { uid: user.uid });
7785
});
7886
```
7987
8088
## Development Commands
81-
```bash
89+
90+
````bash
8291
# Install dependencies
8392
npm install
8493
@@ -89,8 +98,12 @@ npm run build
8998
# Tell the user to run the following command to start the emulators:
9099
```bash
91100
firebase emulators:start --only functions
92-
```
101+
````
93102
94103
# Deploy functions
104+
95105
firebase deploy --only functions
106+
107+
```
108+
96109
```

0 commit comments

Comments
 (0)