Skip to content

Commit ff1d203

Browse files
merlinnotthechenky
authored andcommitted
Lay the groundwork for v3 (#450)
* Update dependencies to latest versions * Revert ordering alphabetically * Add `dom` library to `package.json` This is required by `@types/protobufjs`. * Update dependencies once more * Update dependencies again * Sort package.json using sort-package-json * Breaking changes to dependencies * Remove upgrade warning * Compile to ES2017 * Simplify test scripts * Remove class prototype overrides * Drop support for FIREBASE_PROJECT env variable * Add changelog entries * Adjust Travis config to run on Node.js 8 and Node.js 10 * Remove tests for FIREBASE_PROJECT env variable * Remove v1 migration entry from the readme * Specify keywords in a correct order * Revert adding a newline before an if statement * Remove an always truthy condition * Remove DOM library * Update dependency @types/lodash to ^4.14.133 * Add a changelog entry for FIREBASE_PROJECT * Add typeRoots to tsconfig.release.json * Require a version of firebase-tools that supports Node.js 10 * Adjust firebase-tools version in changelog entry * Remove firebase-tool peer dependency.
1 parent 18c01cb commit ff1d203

File tree

12 files changed

+94
-193
lines changed

12 files changed

+94
-193
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- '6.14.0'
4-
- '8'
5-
- stable
3+
- '8'
4+
- '10'
65
sudo: false

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ Here are some resources to get help:
1717

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

20-
*Please avoid double posting across multiple channels!*
21-
22-
## Migrating to v1
23-
24-
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).
20+
_Please avoid double posting across multiple channels!_
2521

2622
## Usage
2723

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- important - [breaking change] The Firebase Functions SDK no longer supports Node 6. Developers must use Node 8.13.0 or higher.
2+
- important - [breaking change] The Firebase Functions SDK no longer supports Firebase Tools SDK below version 6.8.0.
3+
- important - [breaking change] FIREBASE_PROJECT environment variable is no longer supported and has been supplanted by FIREBASE_CONFIG.

package.json

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,66 @@
22
"name": "firebase-functions",
33
"version": "2.3.1",
44
"description": "Firebase SDK for Cloud Functions",
5-
"main": "lib/index.js",
6-
"scripts": {
7-
"build": "node_modules/.bin/tsc -p tsconfig.release.json",
8-
"build:pack": "rm -rf lib && npm install && node_modules/.bin/tsc -p tsconfig.release.json && npm pack",
9-
"build:release": "npm install --production && npm install typescript firebase-admin && node_modules/.bin/tsc -p tsconfig.release.json",
10-
"format": "prettier --write '**/*.ts'",
11-
"pretest": "node_modules/.bin/tsc && cp -r spec/fixtures .tmp/spec",
12-
"test": "npm run mocha",
13-
"mocha": "mocha .tmp/spec/index.spec.js",
14-
"posttest": "npm run format && rm -rf .tmp",
15-
"postinstall": "node ./upgrade-warning"
16-
},
17-
"repository": {
18-
"type": "git",
19-
"url": "git+https://github.com/firebase/firebase-functions.git"
20-
},
215
"keywords": [
226
"firebase",
237
"functions",
248
"google",
259
"cloud"
2610
],
27-
"author": "Firebase Team",
28-
"license": "MIT",
11+
"homepage": "https://github.com/firebase/firebase-functions#readme",
2912
"bugs": {
3013
"url": "https://github.com/firebase/firebase-functions/issues"
3114
},
32-
"homepage": "https://github.com/firebase/firebase-functions#readme",
33-
"devDependencies": {
34-
"@types/chai": "^3.4.32",
35-
"@types/chai-as-promised": "0.0.28",
36-
"@types/mocha": "^5.2.5",
37-
"@types/mock-require": "^1.3.3",
38-
"@types/nock": "^0.54.32",
39-
"@types/node": "^6.0.38",
40-
"@types/sinon": "^1.16.29",
41-
"chai": "^3.5.0",
42-
"chai-as-promised": "^5.2.0",
43-
"firebase-admin": "^7.0.0",
44-
"istanbul": "^0.4.2",
45-
"mocha": "^5.2.0",
46-
"mock-require": "^2.0.1",
47-
"nock": "^9.0.0",
48-
"prettier": "^1.13.7",
49-
"sinon": "^1.17.4",
50-
"ts-node": "^7.0.1",
51-
"typescript": "~3.1.0"
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/firebase/firebase-functions.git"
5218
},
53-
"peerDependencies": {
54-
"firebase-admin": "^7.0.0"
19+
"license": "MIT",
20+
"author": "Firebase Team",
21+
"main": "lib/index.js",
22+
"types": "lib/index.d.ts",
23+
"scripts": {
24+
"build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
25+
"build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json",
26+
"build": "tsc -p tsconfig.release.json",
27+
"format": "prettier --write '**/*.ts'",
28+
"posttest": "npm run format",
29+
"test": "mocha -r ts-node/register ./spec/index.spec.ts"
5530
},
5631
"dependencies": {
57-
"@types/cors": "^2.8.1",
58-
"@types/express": "^4.11.1",
59-
"@types/jsonwebtoken": "^7.2.6",
60-
"@types/lodash": "^4.14.34",
6132
"cors": "^2.8.4",
62-
"express": "^4.16.2",
63-
"jsonwebtoken": "^8.2.1",
33+
"express": "^4.17.1",
34+
"jsonwebtoken": "^8.3.2",
6435
"lodash": "^4.6.1"
6536
},
66-
"engines": {
67-
"node": ">=6.0.0"
37+
"devDependencies": {
38+
"@types/chai": "^4.1.7",
39+
"@types/chai-as-promised": "^7.1.0",
40+
"@types/cors": "^2.8.5",
41+
"@types/express": "^4.11.1",
42+
"@types/jsonwebtoken": "^8.3.2",
43+
"@types/lodash": "^4.14.133",
44+
"@types/mocha": "^5.2.7",
45+
"@types/mock-require": "^2.0.0",
46+
"@types/nock": "^10.0.2",
47+
"@types/node": "^8.10.49",
48+
"@types/sinon": "^7.0.12",
49+
"chai": "^4.2.0",
50+
"chai-as-promised": "^7.1.1",
51+
"firebase-admin": "^8.0.0",
52+
"istanbul": "^0.4.2",
53+
"mocha": "^6.1.4",
54+
"mock-require": "^3.0.3",
55+
"nock": "^10.0.6",
56+
"prettier": "^1.17.1",
57+
"sinon": "^7.3.2",
58+
"ts-node": "^8.2.0",
59+
"typescript": "^3.5.1"
6860
},
69-
"typings": "lib/index.d.ts"
61+
"peerDependencies": {
62+
"firebase-admin": "^8.0.0"
63+
},
64+
"engines": {
65+
"node": "^8.13.0 || >=10.10.0"
66+
}
7067
}

spec/config.spec.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe('config()', () => {
2929
mockRequire.stopAll();
3030
delete config.singleton;
3131
delete process.env.FIREBASE_CONFIG;
32-
delete process.env.FIREBASE_PROJECT;
3332
delete process.env.CLOUD_RUNTIME_CONFIG;
3433
});
3534

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

53-
it('loads Firebase configs from FIREBASE_PROJECT env variable', () => {
54-
process.env.FIREBASE_PROJECT = JSON.stringify({
55-
databaseURL: '[email protected]',
56-
});
57-
expect(firebaseConfig()).to.have.property(
58-
'databaseURL',
59-
60-
);
61-
});
62-
6352
it('loads Firebase configs from FIREBASE_CONFIG env variable', () => {
6453
process.env.FIREBASE_CONFIG = JSON.stringify({
6554
databaseURL: '[email protected]',
@@ -70,33 +59,6 @@ describe('config()', () => {
7059
);
7160
});
7261

73-
it('prefers FIREBASE_CONFIG over FIREBASE_PROJECT', () => {
74-
process.env.FIREBASE_CONFIG = JSON.stringify({
75-
databaseURL: 'firebase_config',
76-
});
77-
process.env.FIREBASE_PROJECT = JSON.stringify({
78-
databaseURL: 'firebase_project',
79-
});
80-
expect(firebaseConfig()).to.have.property('databaseURL', 'firebase_config');
81-
});
82-
83-
it('behaves well when both FIREBASE_PROJECT and .runtimeconfig.json present', () => {
84-
process.env.FIREBASE_PROJECT = JSON.stringify({
85-
databaseURL: '[email protected]',
86-
});
87-
mockRequire('../../../.runtimeconfig.json', {
88-
firebase: {
89-
databaseURL: '[email protected]',
90-
},
91-
foo: 'bar',
92-
});
93-
expect(firebaseConfig()).to.have.property(
94-
'databaseURL',
95-
96-
);
97-
expect(config()).to.have.property('foo', 'bar');
98-
});
99-
10062
it('accepts alternative locations for config file', () => {
10163
process.env.CLOUD_RUNTIME_CONFIG = 'another.json';
10264
mockRequire('another.json', { foo: 'bar', firebase: {} });
@@ -112,16 +74,4 @@ describe('config()', () => {
11274
expect(firebaseConfig()).to.not.be.null;
11375
expect(config()).to.have.property('foo', 'bar');
11476
});
115-
116-
it('behaves well when both env.CLOUD_RUNTIME_CONFIG and env.FIREBASE_PROJECT are set', () => {
117-
process.env.CLOUD_RUNTIME_CONFIG = JSON.stringify({ foo: 'bar' });
118-
process.env.FIREBASE_PROJECT = JSON.stringify({
119-
databaseURL: '[email protected]',
120-
});
121-
expect(firebaseConfig()).to.have.property(
122-
'databaseURL',
123-
124-
);
125-
expect(config()).to.have.property('foo', 'bar');
126-
});
12777
});

spec/fixtures/http.ts

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ export function mockRCVariableFetch(
3939
data: any,
4040
token: string = 'thetoken'
4141
): nock.Scope {
42-
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').get(
43-
`/v1beta1/projects/${projectId}/configs/firebase/variables/${varName}`
44-
);
45-
46-
if (token) {
47-
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
48-
}
49-
50-
return mock.reply(200, { text: JSON.stringify(data) });
42+
return nock('https://runtimeconfig.googleapis.com')
43+
.get(`/v1beta1/projects/${projectId}/configs/firebase/variables/${varName}`)
44+
.matchHeader('Authorization', `Bearer ${token}`)
45+
.reply(200, { text: JSON.stringify(data) });
5146
}
5247

5348
export function mockMetaVariableWatch(
@@ -56,60 +51,54 @@ export function mockMetaVariableWatch(
5651
token: string = 'thetoken',
5752
updateTime: string = new Date().toISOString()
5853
): nock.Scope {
59-
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').post(
60-
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
61-
);
62-
63-
if (token) {
64-
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
65-
}
66-
67-
return mock.reply(200, {
68-
updateTime,
69-
state: 'UPDATED',
70-
text: JSON.stringify(data),
71-
});
54+
return nock('https://runtimeconfig.googleapis.com')
55+
.post(
56+
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
57+
)
58+
.matchHeader('Authorization', `Bearer ${token}`)
59+
.reply(200, {
60+
updateTime,
61+
state: 'UPDATED',
62+
text: JSON.stringify(data),
63+
});
7264
}
7365

7466
export function mockMetaVariableWatchTimeout(
7567
projectId: string,
7668
delay: number,
7769
token?: string
7870
): nock.Scope {
79-
let mock: nock.Scope = nock('https://runtimeconfig.googleapis.com').post(
71+
let interceptor = nock('https://runtimeconfig.googleapis.com').post(
8072
`/v1beta1/projects/${projectId}/configs/firebase/variables/meta:watch`
8173
);
8274

83-
if (token) {
84-
mock = mock.matchHeader('Authorization', `Bearer ${token}`);
75+
if (interceptor) {
76+
interceptor = interceptor.matchHeader('Authorization', `Bearer ${token}`);
8577
}
8678

87-
return mock.delay(delay).reply(502);
79+
return interceptor.delay(delay).reply(502);
8880
}
8981

9082
export function mockCreateToken(
9183
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
9284
): nock.Scope {
93-
let mock: nock.Scope = nock('https://accounts.google.com').post(
94-
'/o/oauth2/token'
95-
);
96-
return mock.reply(200, token);
85+
return nock('https://accounts.google.com')
86+
.post('/o/oauth2/token')
87+
.reply(200, token);
9788
}
9889

9990
export function mockRefreshToken(
10091
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
10192
): nock.Scope {
102-
let mock: nock.Scope = nock('https://www.googleapis.com').post(
103-
'/oauth2/v4/token'
104-
);
105-
return mock.reply(200, token);
93+
return nock('https://www.googleapis.com')
94+
.post('/oauth2/v4/token')
95+
.reply(200, token);
10696
}
10797

10898
export function mockMetadataServiceToken(
10999
token: AccessToken = { access_token: 'aToken', expires_in: 3600 }
110100
): nock.Scope {
111-
let mock: nock.Scope = nock('http://metadata.google.internal').get(
112-
'/computeMetadata/v1beta1/instance/service-accounts/default/token'
113-
);
114-
return mock.reply(200, token);
101+
return nock('http://metadata.google.internal')
102+
.get('/computeMetadata/v1beta1/instance/service-accounts/default/token')
103+
.reply(200, token);
115104
}

spec/providers/https.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ const expectedResponseHeaders = {
213213
* verifying an id token.
214214
*/
215215
function mockFetchPublicKeys(): nock.Scope {
216-
let mock: nock.Scope = nock('https://www.googleapis.com:443').get(
217-
'/robot/v1/metadata/x509/[email protected]'
218-
);
219216
const mockedResponse = { [mocks.key_id]: mocks.public_key };
220217
const headers = {
221218
'cache-control': 'public, max-age=1, must-revalidate, no-transform',
222219
};
223-
return mock.reply(200, mockedResponse, headers);
220+
221+
return nock('https://www.googleapis.com:443')
222+
.get('/robot/v1/metadata/x509/[email protected]')
223+
.reply(200, mockedResponse, headers);
224224
}
225225

226226
/**

src/config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ export namespace config {
4040

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

src/providers/https.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,11 @@ export class HttpsError extends Error {
169169
/**
170170
* Extra data to be converted to JSON and included in the error response.
171171
*/
172-
readonly details?: any;
172+
readonly details?: unknown;
173173

174-
constructor(code: FunctionsErrorCode, message: string, details?: any) {
174+
constructor(code: FunctionsErrorCode, message: string, details?: unknown) {
175175
super(message);
176176

177-
// This is a workaround for a bug in TypeScript when extending Error:
178-
// tslint:disable-next-line
179-
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
180-
Object.setPrototypeOf(this, HttpsError.prototype);
181-
182177
if (!errorCodeMap[code]) {
183178
throw new Error('Unknown error status: ' + code);
184179
}

tsconfig.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
{
22
"compilerOptions": {
3-
"lib": ["es6"],
3+
"lib": ["es2017"],
44
"module": "commonjs",
55
"noImplicitAny": false,
66
"outDir": ".tmp",
7+
"resolveJsonModule": true,
78
"sourceMap": true,
8-
"target": "es6",
9-
"typeRoots": [
10-
"node_modules/@types"
11-
]
9+
"target": "es2017"
1210
},
13-
"include": [
14-
"src/**/*.ts",
15-
"spec/**/*.ts"
16-
]
11+
"include": ["src/**/*.ts", "spec/**/*.ts"]
1712
}

0 commit comments

Comments
 (0)