[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lay the groundwork for v3 #450

Merged
merged 26 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
79f582f
Update dependencies to latest versions
merlinnot May 13, 2019
877d2cd
Revert ordering alphabetically
merlinnot May 24, 2019
33fd68a
Add `dom` library to `package.json`
merlinnot May 24, 2019
d7b1d92
Update dependencies once more
merlinnot May 24, 2019
f947927
Update dependencies again
merlinnot May 30, 2019
9161ebd
Sort package.json using sort-package-json
merlinnot May 30, 2019
b98bb68
Breaking changes to dependencies
merlinnot May 30, 2019
fa6b65b
Remove upgrade warning
merlinnot May 30, 2019
80d29fb
Compile to ES2017
merlinnot May 30, 2019
01be3ac
Simplify test scripts
merlinnot May 30, 2019
0fb3426
Remove class prototype overrides
merlinnot May 30, 2019
822ec67
Drop support for FIREBASE_PROJECT env variable
merlinnot May 30, 2019
98c4326
Add changelog entries
merlinnot May 30, 2019
065f470
Adjust Travis config to run on Node.js 8 and Node.js 10
merlinnot May 30, 2019
7713f06
Remove tests for FIREBASE_PROJECT env variable
merlinnot May 30, 2019
73a5b3c
Remove v1 migration entry from the readme
merlinnot May 30, 2019
06e0558
Specify keywords in a correct order
merlinnot May 30, 2019
3dc0129
Revert adding a newline before an if statement
merlinnot Jun 3, 2019
76ce309
Remove an always truthy condition
merlinnot Jun 3, 2019
8fd948b
Remove DOM library
merlinnot Jun 3, 2019
87dd7ba
Update dependency @types/lodash to ^4.14.133
merlinnot Jun 3, 2019
682e8c8
Add a changelog entry for FIREBASE_PROJECT
merlinnot Jun 5, 2019
d9d9fcb
Add typeRoots to tsconfig.release.json
merlinnot Jun 5, 2019
4abe9c0
Require a version of firebase-tools that supports Node.js 10
merlinnot Jun 6, 2019
31b2d9e
Adjust firebase-tools version in changelog entry
merlinnot Jun 6, 2019
68018f8
Remove firebase-tool peer dependency.
merlinnot Jun 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- '6.14.0'
- '8'
- stable
- '8'
- '10'
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
sudo: false
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ Here are some resources to get help:

If the official documentation doesn't help, try asking through our official support channels: https://firebase.google.com/support/

*Please avoid double posting across multiple channels!*

## Migrating to v1

To migrate from a beta version of firebase-functions to v1, please refer to the [migration guide](https://firebase.google.com/docs/functions/beta-v1-diff).
_Please avoid double posting across multiple channels!_

## Usage

Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- important - [breaking change] The Firebase Functions SDK no longer supports Node 6. Developers must use Node 8.13.0 or higher.
- important - [breaking change] The Firebase Functions SDK no longer supports Firebase Tools SDK below major version 5.
thechenky marked this conversation as resolved.
Show resolved Hide resolved
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
96 changes: 47 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,67 @@
"name": "firebase-functions",
"version": "2.3.1",
"description": "Firebase SDK for Cloud Functions",
"main": "lib/index.js",
"scripts": {
"build": "node_modules/.bin/tsc -p tsconfig.release.json",
"build:pack": "rm -rf lib && npm install && node_modules/.bin/tsc -p tsconfig.release.json && npm pack",
"build:release": "npm install --production && npm install typescript firebase-admin && node_modules/.bin/tsc -p tsconfig.release.json",
"format": "prettier --write '**/*.ts'",
"pretest": "node_modules/.bin/tsc && cp -r spec/fixtures .tmp/spec",
"test": "npm run mocha",
"mocha": "mocha .tmp/spec/index.spec.js",
"posttest": "npm run format && rm -rf .tmp",
"postinstall": "node ./upgrade-warning"
},
"repository": {
"type": "git",
"url": "git+https://github.com/firebase/firebase-functions.git"
},
"keywords": [
"firebase",
"functions",
"google",
"cloud"
],
"author": "Firebase Team",
"license": "MIT",
"homepage": "https://github.com/firebase/firebase-functions#readme",
"bugs": {
"url": "https://github.com/firebase/firebase-functions/issues"
},
"homepage": "https://github.com/firebase/firebase-functions#readme",
"devDependencies": {
"@types/chai": "^3.4.32",
"@types/chai-as-promised": "0.0.28",
"@types/mocha": "^5.2.5",
"@types/mock-require": "^1.3.3",
"@types/nock": "^0.54.32",
"@types/node": "^6.0.38",
"@types/sinon": "^1.16.29",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"firebase-admin": "^7.0.0",
"istanbul": "^0.4.2",
"mocha": "^5.2.0",
"mock-require": "^2.0.1",
"nock": "^9.0.0",
"prettier": "^1.13.7",
"sinon": "^1.17.4",
"ts-node": "^7.0.1",
"typescript": "~3.1.0"
"repository": {
"type": "git",
"url": "git+https://github.com/firebase/firebase-functions.git"
},
"peerDependencies": {
"firebase-admin": "^7.0.0"
"license": "MIT",
"author": "Firebase Team",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
"build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json",
"build": "tsc -p tsconfig.release.json",
"format": "prettier --write '**/*.ts'",
"posttest": "npm run format",
"test": "mocha -r ts-node/register ./spec/index.spec.ts"
},
"dependencies": {
"@types/cors": "^2.8.1",
"@types/express": "^4.11.1",
"@types/jsonwebtoken": "^7.2.6",
"@types/lodash": "^4.14.34",
"cors": "^2.8.4",
"express": "^4.16.2",
"jsonwebtoken": "^8.2.1",
"express": "^4.17.1",
"jsonwebtoken": "^8.3.2",
"lodash": "^4.6.1"
},
"engines": {
"node": ">=6.0.0"
"devDependencies": {
"@types/chai": "^4.1.7",
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
"@types/chai-as-promised": "^7.1.0",
"@types/cors": "^2.8.5",
"@types/express": "^4.11.1",
"@types/jsonwebtoken": "^8.3.2",
"@types/lodash": "^4.14.132",
"@types/mocha": "^5.2.7",
"@types/mock-require": "^2.0.0",
"@types/nock": "^10.0.2",
"@types/node": "^8.10.49",
"@types/sinon": "^7.0.12",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"firebase-admin": "^8.0.0",
"istanbul": "^0.4.2",
"mocha": "^6.1.4",
"mock-require": "^3.0.3",
"nock": "^10.0.6",
"prettier": "^1.17.1",
"sinon": "^7.3.2",
"ts-node": "^8.2.0",
"typescript": "^3.5.1"
},
"typings": "lib/index.d.ts"
"peerDependencies": {
"firebase-admin": "^8.0.0",
"firebase-tools": "^5.0.0"
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
},
"engines": {
"node": "^8.13.0 || >=10.10.0"
thechenky marked this conversation as resolved.
Show resolved Hide resolved
}
}
50 changes: 0 additions & 50 deletions spec/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('config()', () => {
mockRequire.stopAll();
delete config.singleton;
delete process.env.FIREBASE_CONFIG;
delete process.env.FIREBASE_PROJECT;
delete process.env.CLOUD_RUNTIME_CONFIG;
});

Expand All @@ -50,16 +49,6 @@ describe('config()', () => {
expect(firebaseConfig()).to.be.null;
});

it('loads Firebase configs from FIREBASE_PROJECT env variable', () => {
process.env.FIREBASE_PROJECT = JSON.stringify({
databaseURL: 'foo@firebaseio.com',
});
expect(firebaseConfig()).to.have.property(
'databaseURL',
'foo@firebaseio.com'
);
});

it('loads Firebase configs from FIREBASE_CONFIG env variable', () => {
process.env.FIREBASE_CONFIG = JSON.stringify({
databaseURL: 'foo@firebaseio.com',
Expand All @@ -70,33 +59,6 @@ describe('config()', () => {
);
});

it('prefers FIREBASE_CONFIG over FIREBASE_PROJECT', () => {
process.env.FIREBASE_CONFIG = JSON.stringify({
databaseURL: 'firebase_config',
});
process.env.FIREBASE_PROJECT = JSON.stringify({
databaseURL: 'firebase_project',
});
expect(firebaseConfig()).to.have.property('databaseURL', 'firebase_config');
});

it('behaves well when both FIREBASE_PROJECT and .runtimeconfig.json present', () => {
process.env.FIREBASE_PROJECT = JSON.stringify({
databaseURL: 'foo@firebaseio.com',
});
mockRequire('../../../.runtimeconfig.json', {
firebase: {
databaseURL: 'foo@firebaseio.com',
},
foo: 'bar',
});
expect(firebaseConfig()).to.have.property(
'databaseURL',
'foo@firebaseio.com'
);
expect(config()).to.have.property('foo', 'bar');
});

it('accepts alternative locations for config file', () => {
process.env.CLOUD_RUNTIME_CONFIG = 'another.json';
mockRequire('another.json', { foo: 'bar', firebase: {} });
Expand All @@ -112,16 +74,4 @@ describe('config()', () => {
expect(firebaseConfig()).to.not.be.null;
expect(config()).to.have.property('foo', 'bar');
});

it('behaves well when both env.CLOUD_RUNTIME_CONFIG and env.FIREBASE_PROJECT are set', () => {
process.env.CLOUD_RUNTIME_CONFIG = JSON.stringify({ foo: 'bar' });
process.env.FIREBASE_PROJECT = JSON.stringify({
databaseURL: 'foo@firebaseio.com',
});
expect(firebaseConfig()).to.have.property(
'databaseURL',
'foo@firebaseio.com'
);
expect(config()).to.have.property('foo', 'bar');
});
});
58 changes: 26 additions & 32 deletions spec/fixtures/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export function mockRCVariableFetch(
data: any,
token: string = 'thetoken'
): nock.Scope {
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').get(
let interceptor = nock('https://runtimeconfig.googleapis.com').get(
thechenky marked this conversation as resolved.
Show resolved Hide resolved
thechenky marked this conversation as resolved.
Show resolved Hide resolved
`/v1beta1/projects/${projectId}/configs/firebase/variables/${varName}`
);

if (token) {
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
interceptor = interceptor.matchHeader('Authorization', `Bearer ${token}`);
thechenky marked this conversation as resolved.
Show resolved Hide resolved
}

return mock.reply(200, { text: JSON.stringify(data) });
return interceptor.reply(200, { text: JSON.stringify(data) });
}

export function mockMetaVariableWatch(
Expand All @@ -56,60 +56,54 @@ export function mockMetaVariableWatch(
token: string = 'thetoken',
updateTime: string = new Date().toISOString()
): nock.Scope {
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').post(
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
);

if (token) {
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
}

return mock.reply(200, {
updateTime,
state: 'UPDATED',
text: JSON.stringify(data),
});
return nock('https://runtimeconfig.googleapis.com')
.post(
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
)
.matchHeader('Authorization', `Bearer ${token}`)
.reply(200, {
updateTime,
state: 'UPDATED',
text: JSON.stringify(data),
});
}

export function mockMetaVariableWatchTimeout(
projectId: string,
delay: number,
token?: string
): nock.Scope {
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').post(
let interceptor = nock('https://runtimeconfig.googleapis.com').post(
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
);

if (token) {
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
if (interceptor) {
interceptor = interceptor.matchHeader('Authorization', `Bearer ${token}`);
}

return mock.delay(delay).reply(502);
return interceptor.delay(delay).reply(502);
}

export function mockCreateToken(
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
): nock.Scope {
let mock: nock.Scope = nock('https://accounts.google.com').post(
'/o/oauth2/token'
);
return mock.reply(200, token);
return nock('https://accounts.google.com')
.post('/o/oauth2/token')
.reply(200, token);
}

export function mockRefreshToken(
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
): nock.Scope {
let mock: nock.Scope = nock('https://www.googleapis.com').post(
'/oauth2/v4/token'
);
return mock.reply(200, token);
return nock('https://www.googleapis.com')
.post('/oauth2/v4/token')
.reply(200, token);
}

export function mockMetadataServiceToken(
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
): nock.Scope {
let mock: nock.Scope = nock('http://metadata.google.internal').get(
'/computeMetadata/v1beta1/instance/service-accounts/default/token'
);
return mock.reply(200, token);
return nock('http://metadata.google.internal')
.get('/computeMetadata/v1beta1/instance/service-accounts/default/token')
.reply(200, token);
}
8 changes: 4 additions & 4 deletions spec/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ const expectedResponseHeaders = {
* verifying an id token.
*/
function mockFetchPublicKeys(): nock.Scope {
let mock: nock.Scope = nock('https://www.googleapis.com:443').get(
'/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'
);
const mockedResponse = { [mocks.key_id]: mocks.public_key };
const headers = {
'cache-control': 'public, max-age=1, must-revalidate, no-transform',
};
return mock.reply(200, mockedResponse, headers);

return nock('https://www.googleapis.com:443')
.get('/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com')
.reply(200, mockedResponse, headers);
thechenky marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ export namespace config {

/* @internal */
export function firebaseConfig(): firebase.AppOptions | null {
// The FIREBASE_PROJECT environment variable was introduced to help local emulation with `firebase-tools` 3.18
// Unfortunately, API review decided that the name should be FIREBASE_CONFIG to avoid confusions that Firebase has
// a separate project from Google Cloud. This accepts both versions, preferring the documented name.
const env = process.env.FIREBASE_CONFIG || process.env.FIREBASE_PROJECT;
const env = process.env.FIREBASE_CONFIG;

thechenky marked this conversation as resolved.
Show resolved Hide resolved
thechenky marked this conversation as resolved.
Show resolved Hide resolved
if (env) {
return JSON.parse(env);
}
Expand Down
9 changes: 2 additions & 7 deletions src/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,11 @@ export class HttpsError extends Error {
/**
* Extra data to be converted to JSON and included in the error response.
*/
readonly details?: any;
readonly details?: unknown;

constructor(code: FunctionsErrorCode, message: string, details?: any) {
constructor(code: FunctionsErrorCode, message: string, details?: unknown) {
super(message);

// This is a workaround for a bug in TypeScript when extending Error:
// tslint:disable-next-line
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, HttpsError.prototype);

if (!errorCodeMap[code]) {
throw new Error('Unknown error status: ' + code);
}
Expand Down
13 changes: 4 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"compilerOptions": {
"lib": ["es6"],
"lib": ["dom", "es2017"],
thechenky marked this conversation as resolved.
Show resolved Hide resolved
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
"module": "commonjs",
"noImplicitAny": false,
"outDir": ".tmp",
"resolveJsonModule": true,
thechenky marked this conversation as resolved.
Show resolved Hide resolved
"sourceMap": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
]
"target": "es2017"
},
"include": [
"src/**/*.ts",
"spec/**/*.ts"
]
"include": ["src/**/*.ts", "spec/**/*.ts"]
}
Loading