Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: firebase/firebase-functions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.8.0
Choose a base ref
...
head repository: firebase/firebase-functions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.9.0
Choose a head ref
  • 6 commits
  • 9 files changed
  • 3 contributors

Commits on Jul 14, 2020

  1. Copy the full SHA
    a07d6ef View commit details

Commits on Jul 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8bc84dd View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e4f2eba View commit details
  3. Fix onRequest handler return type to allow promises (async) (#705)

    Co-authored-by: Michael Bleigh <bleigh@google.com>
    p-young and mbleigh authored Jul 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0ae7c3c View commit details
  4. Update CHANGELOG.md (#751)

    mbleigh authored Jul 31, 2020
    Copy the full SHA
    78fb92f View commit details
  5. 3.9.0

    google-oss-bot committed Jul 31, 2020
    Copy the full SHA
    e91d16a View commit details
Showing with 36 additions and 35 deletions.
  1. +3 −12 CHANGELOG.md
  2. +1 −1 README.md
  3. +1 −1 package.json
  4. +2 −1 src/cloud-functions.ts
  5. +4 −1 src/function-builder.ts
  6. +3 −0 src/function-configuration.ts
  7. +1 −1 src/providers/crashlytics.ts
  8. +18 −16 src/providers/https.ts
  9. +3 −2 src/setup.ts
15 changes: 3 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
- Fixes error when last argument to logger methods is `null`. (#716)
- Adds eight new available regions:
- `us-west2`
- `us-west3`
- `us-west4`
- `europe-west6`
- `asia-northeast2`
- `northamerica-northeast1`
- `southamerica-east1`
- `australia-southeast1`
- No longer throw errors for unrecognized regions (deploy will error instead).
- Fixes error where `snap.ref` in database functions did not work when using the Emulator Suite (#726)
- Updates HTTP callable functions to use structured logging for Node 10+ environments.
- Adds type hints for new Cloud Functions regions `asia-northeast3`, `asia-south1`, and `asia-southeast2`.
- Updates type definition of `https.onRequest` to allow for promises (async functions).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ const notifyUsers = require('./notify-users');
exports.newPost = functions.database
.ref('/posts/{postId}')
.onCreate((snapshot, context) => {
console.log('Received new post with ID:', context.params.postId);
functions.logger.info('Received new post with ID:', context.params.postId);
return notifyUsers(snapshot.val());
});
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions",
"version": "3.8.0",
"version": "3.9.0",
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
3 changes: 2 additions & 1 deletion src/cloud-functions.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
import { Request, Response } from 'express';
import * as _ from 'lodash';
import { DeploymentOptions, Schedule } from './function-configuration';
import { warn } from './logger';
export { Request, Response };

/** @hidden */
@@ -379,7 +380,7 @@ export function makeCloudFunction<EventData>({
promise = handler(dataOrChange, context);
}
if (typeof promise === 'undefined') {
console.warn('Function returned undefined, expected Promise or value');
warn('Function returned undefined, expected Promise or value');
}
return Promise.resolve(promise)
.then((result) => {
5 changes: 4 additions & 1 deletion src/function-builder.ts
Original file line number Diff line number Diff line change
@@ -154,7 +154,10 @@ export class FunctionBuilder {
* same signature as an Express app.
*/
onRequest: (
handler: (req: https.Request, resp: express.Response) => void
handler: (
req: https.Request,
resp: express.Response
) => void | Promise<void>
) => https._onRequestWithOptions(handler, this.options),
/**
* Declares a callable method for clients to call using a Firebase SDK.
3 changes: 3 additions & 0 deletions src/function-configuration.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@ export const SUPPORTED_REGIONS = [
'asia-east2',
'asia-northeast1',
'asia-northeast2',
'asia-northeast3',
'asia-south1',
'asia-southeast2',
'northamerica-northeast1',
'southamerica-east1',
'australia-southeast1',
2 changes: 1 addition & 1 deletion src/providers/crashlytics.ts
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ export class IssueBuilder {
* const slackMessage = ` There's a new issue (${issueId}) ` +
* `in your app - ${issueTitle}`;
* return notifySlack(slackMessage).then(() => {
* console.log(`Posted new issue ${issueId} successfully to Slack`);
* functions.logger.info(`Posted new issue ${issueId} successfully to Slack`);
* });
* });
* ```
34 changes: 18 additions & 16 deletions src/providers/https.ts
Original file line number Diff line number Diff line change
@@ -24,9 +24,11 @@ import * as cors from 'cors';
import * as express from 'express';
import * as firebase from 'firebase-admin';
import * as _ from 'lodash';

import { apps } from '../apps';
import { HttpsFunction, optionsToTrigger, Runnable } from '../cloud-functions';
import { DeploymentOptions } from '../function-configuration';
import { warn, error } from '../logger';

/** @hidden */
export interface Request extends express.Request {
@@ -285,13 +287,13 @@ interface HttpResponseBody {
function isValidRequest(req: Request): req is HttpRequest {
// The body must not be empty.
if (!req.body) {
console.warn('Request is missing body.');
warn('Request is missing body.');
return false;
}

// Make sure it's a POST.
if (req.method !== 'POST') {
console.warn('Request has invalid method.', req.method);
warn('Request has invalid method.', req.method);
return false;
}

@@ -303,13 +305,13 @@ function isValidRequest(req: Request): req is HttpRequest {
contentType = contentType.substr(0, semiColon).trim();
}
if (contentType !== 'application/json') {
console.warn('Request has incorrect Content-Type.', contentType);
warn('Request has incorrect Content-Type.', contentType);
return false;
}

// The body must have data.
if (_.isUndefined(req.body.data)) {
console.warn('Request body is missing data.', req.body);
warn('Request body is missing data.', req.body);
return false;
}

@@ -318,7 +320,7 @@ function isValidRequest(req: Request): req is HttpRequest {
// Verify that the body does not have any extra fields.
const extras = _.omit(req.body, 'data');
if (!_.isEmpty(extras)) {
console.warn('Request body has extra fields.', extras);
warn('Request body has extra fields.', extras);
return false;
}
return true;
@@ -363,7 +365,7 @@ export function encode(data: any): any {
return _.mapValues(data, encode);
}
// If we got this far, the data is not encodable.
console.error('Data cannot be encoded in JSON.', data);
error('Data cannot be encoded in JSON.', data);
throw new Error('Data cannot be encoded in JSON: ' + data);
}

@@ -386,13 +388,13 @@ export function decode(data: any): any {
// worth all the extra code to detect that case.
const value = parseFloat(data.value);
if (_.isNaN(value)) {
console.error('Data cannot be decoded from JSON.', data);
error('Data cannot be decoded from JSON.', data);
throw new Error('Data cannot be decoded from JSON: ' + data);
}
return value;
}
default: {
console.error('Data cannot be decoded from JSON.', data);
error('Data cannot be decoded from JSON.', data);
throw new Error('Data cannot be decoded from JSON: ' + data);
}
}
@@ -420,7 +422,7 @@ export function _onCallWithOptions(
const func = async (req: Request, res: express.Response) => {
try {
if (!isValidRequest(req)) {
console.error('Invalid request', req);
error('Invalid request, unable to process.');
throw new HttpsError('invalid-argument', 'Bad Request');
}

@@ -441,7 +443,7 @@ export function _onCallWithOptions(
uid: authToken.uid,
token: authToken,
};
} catch (e) {
} catch (err) {
throw new HttpsError('unauthenticated', 'Unauthenticated');
}
}
@@ -464,15 +466,15 @@ export function _onCallWithOptions(
// If there was some result, encode it in the body.
const responseBody: HttpResponseBody = { result };
res.status(200).send(responseBody);
} catch (error) {
if (!(error instanceof HttpsError)) {
} catch (err) {
if (!(err instanceof HttpsError)) {
// This doesn't count as an 'explicit' error.
console.error('Unhandled error', error);
error = new HttpsError('internal', 'INTERNAL');
error('Unhandled error', error);
err = new HttpsError('internal', 'INTERNAL');
}

const { status } = error.httpErrorCode;
const body = { error: error.toJSON() };
const { status } = err.httpErrorCode;
const body = { error: err.toJSON() };

res.status(status).send(body);
}
5 changes: 3 additions & 2 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@

/** @hidden */
import { firebaseConfig } from './config';
import { warn } from './logger';

// Set up for config and vars
export function setup() {
@@ -45,7 +46,7 @@ export function setup() {
// If FIREBASE_CONFIG is still not found, try using GCLOUD_PROJECT to estimate
if (!process.env.FIREBASE_CONFIG) {
if (process.env.GCLOUD_PROJECT) {
console.warn(
warn(
'Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail'
);
process.env.FIREBASE_CONFIG = JSON.stringify({
@@ -58,7 +59,7 @@ export function setup() {
projectId: process.env.GCLOUD_PROJECT,
});
} else {
console.warn(
warn(
'Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail'
);
}