From f6d8db7ee78103d09fe3ddb79521a82827d12bc8 Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Mon, 22 Feb 2021 15:35:10 -0800 Subject: [PATCH 1/3] chore: Added package.json files for all entry points --- app/package.json | 4 + auth/package.json | 4 + database/package.json | 4 + firestore/package.json | 4 + instance-id/package.json | 4 + machine-learning/package.json | 4 + messaging/package.json | 4 + package.json | 27 +++- project-management/package.json | 4 + remote-config/package.json | 4 + security-rules/package.json | 4 + storage/package.json | 4 + .../typescript/src/example-modular.test.ts | 127 ++++++++++++++++++ .../typescript/src/example.test.ts | 8 +- 14 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 app/package.json create mode 100644 auth/package.json create mode 100644 database/package.json create mode 100644 firestore/package.json create mode 100644 instance-id/package.json create mode 100644 machine-learning/package.json create mode 100644 messaging/package.json create mode 100644 project-management/package.json create mode 100644 remote-config/package.json create mode 100644 security-rules/package.json create mode 100644 storage/package.json create mode 100644 test/integration/typescript/src/example-modular.test.ts diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000000..64afe6e0b7 --- /dev/null +++ b/app/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/app/index.js", + "types": "../lib/app/index.d.ts" +} \ No newline at end of file diff --git a/auth/package.json b/auth/package.json new file mode 100644 index 0000000000..3c1d1a76d7 --- /dev/null +++ b/auth/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/auth/index.js", + "types": "../lib/auth/index.d.ts" +} \ No newline at end of file diff --git a/database/package.json b/database/package.json new file mode 100644 index 0000000000..65fe6a2fcf --- /dev/null +++ b/database/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/database/index.js", + "types": "../lib/database/index.d.ts" +} \ No newline at end of file diff --git a/firestore/package.json b/firestore/package.json new file mode 100644 index 0000000000..a4749c5968 --- /dev/null +++ b/firestore/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/firestore/index.js", + "types": "../lib/firestore/index.d.ts" +} \ No newline at end of file diff --git a/instance-id/package.json b/instance-id/package.json new file mode 100644 index 0000000000..974734b551 --- /dev/null +++ b/instance-id/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/instance-id/index.js", + "types": "../lib/instance-id/index.d.ts" +} \ No newline at end of file diff --git a/machine-learning/package.json b/machine-learning/package.json new file mode 100644 index 0000000000..975c2415a8 --- /dev/null +++ b/machine-learning/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/machine-learning/index.js", + "types": "../lib/machine-learning/index.d.ts" +} \ No newline at end of file diff --git a/messaging/package.json b/messaging/package.json new file mode 100644 index 0000000000..67a196d11f --- /dev/null +++ b/messaging/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/messaging/index.js", + "types": "../lib/messaging/index.d.ts" +} \ No newline at end of file diff --git a/package.json b/package.json index 1285586261..d72d13a047 100644 --- a/package.json +++ b/package.json @@ -52,9 +52,34 @@ "lib/", "LICENSE", "README.md", - "package.json" + "package.json", + "app/", + "auth/", + "database/", + "firestore/", + "instance-id/", + "machine-learning", + "messaging/", + "project-management/", + "remote-config/", + "security-rules/", + "storage/" ], "types": "./lib/index.d.ts", + "exports": { + ".": "./lib/index.js", + "./app": "./lib/app/index.js", + "./auth": "./lib/auth/index.js", + "./database": "./lib/database/index.js", + "./firestore": "./lib/firestore/index.js", + "./instance-id": "./lib/instance-id/index.js", + "./machine-learning": "./lib/machine-learning/index.js", + "./messaging": "./lib/messaging/index.js", + "./project-management": "./lib/project-management/index.js", + "./remote-config": "./lib/remote-config/index.js", + "./security-rules": "./lib/security-rules/index.js", + "./storage": "./lib/storage/index.js" + }, "dependencies": { "@firebase/database": "^0.8.1", "@firebase/database-types": "^0.6.1", diff --git a/project-management/package.json b/project-management/package.json new file mode 100644 index 0000000000..fb0a8ce015 --- /dev/null +++ b/project-management/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/project-management/index.js", + "types": "../lib/project-management/index.d.ts" +} \ No newline at end of file diff --git a/remote-config/package.json b/remote-config/package.json new file mode 100644 index 0000000000..437306a95d --- /dev/null +++ b/remote-config/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/remote-config/index.js", + "types": "../lib/remote-config/index.d.ts" +} \ No newline at end of file diff --git a/security-rules/package.json b/security-rules/package.json new file mode 100644 index 0000000000..aafdc49016 --- /dev/null +++ b/security-rules/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/security-rules/index.js", + "types": "../lib/security-rules/index.d.ts" +} \ No newline at end of file diff --git a/storage/package.json b/storage/package.json new file mode 100644 index 0000000000..738b3d96be --- /dev/null +++ b/storage/package.json @@ -0,0 +1,4 @@ +{ + "main": "../lib/storage/index.js", + "types": "../lib/storage/index.d.ts" +} \ No newline at end of file diff --git a/test/integration/typescript/src/example-modular.test.ts b/test/integration/typescript/src/example-modular.test.ts new file mode 100644 index 0000000000..8f607e448a --- /dev/null +++ b/test/integration/typescript/src/example-modular.test.ts @@ -0,0 +1,127 @@ +/*! + * @license + * Copyright 2021 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; + +import { cert, deleteApp, initializeApp, App } from 'firebase-admin/app'; +import { getAuth, Auth } from 'firebase-admin/auth'; +import { getDatabase, getDatabaseWithUrl, Database, ServerValue } from 'firebase-admin/database'; +import { getFirestore, DocumentReference, Firestore, FieldValue } from 'firebase-admin/firestore'; +import { getInstanceId, InstanceId } from 'firebase-admin/instance-id'; +import { getMachineLearning, MachineLearning } from 'firebase-admin/machine-learning'; +import { getMessaging, Messaging } from 'firebase-admin/messaging'; +import { getProjectManagement, ProjectManagement } from 'firebase-admin/project-management'; +import { getRemoteConfig, RemoteConfig } from 'firebase-admin/remote-config'; +import { getSecurityRules, SecurityRules } from 'firebase-admin/security-rules'; +import { getStorage, Storage } from 'firebase-admin/storage'; + +import { Bucket } from '@google-cloud/storage'; + + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const serviceAccount = require('../mock.key.json'); + +describe('Modular API', () => { + let app: App; + + before(() => { + app = initializeApp({ + credential: cert(serviceAccount), + databaseURL: 'https://mock.firebaseio.com' + }, 'TestApp'); + }); + + after(() => { + return deleteApp(app); + }); + + it('Should return an initialized App', () => { + expect(app.name).to.equal('TestApp'); + }); + + it('Should return an Auth client', () => { + const client = getAuth(app); + expect(client).to.be.instanceOf(Auth); + }); + + it('Should return a Messaging client', () => { + const client = getMessaging(app); + expect(client).to.be.instanceOf(Messaging); + }); + + it('Should return a ProjectManagement client', () => { + const client = getProjectManagement(app); + expect(client).to.be.instanceOf(ProjectManagement); + }); + + it('Should return a SecurityRules client', () => { + const client = getSecurityRules(app); + expect(client).to.be.instanceOf(SecurityRules); + }); + + it('Should return a Database client', () => { + const db: Database = getDatabase(app); + expect(db).to.be.not.undefined; + expect(typeof db.getRules).to.equal('function'); + }); + + it('Should return a Database client for URL', () => { + const db: Database = getDatabaseWithUrl('https://other-mock.firebaseio.com', app); + expect(db).to.be.not.undefined; + expect(typeof db.getRules).to.equal('function'); + }); + + it('Should return a Database ServerValue', () => { + expect(ServerValue.increment(1)).to.be.not.undefined; + }); + + it('Should return a Cloud Storage client', () => { + const storage = getStorage(app); + expect(storage).to.be.instanceOf(Storage) + const bucket: Bucket = storage.bucket('TestBucket'); + expect(bucket.name).to.equal('TestBucket'); + }); + + it('Should return a Firestore client', () => { + const firestore = getFirestore(app); + expect(firestore).to.be.instanceOf(Firestore); + }); + + it('Should return a Firestore FieldValue', () => { + expect(FieldValue.increment(1)).to.be.not.undefined; + }); + + it('Should return a DocumentReference', () => { + const ref = getFirestore(app).collection('test').doc(); + expect(ref).to.be.instanceOf(DocumentReference); + }); + + it('Should return an InstanceId client', () => { + const client = getInstanceId(app); + expect(client).to.be.instanceOf(InstanceId); + }); + + it('Should return a MachineLearning client', () => { + const client = getMachineLearning(app); + expect(client).to.be.instanceOf(MachineLearning); + }); + + it('Should return a RemoteConfig client', () => { + const client = getRemoteConfig(app); + expect(client).to.be.instanceOf(RemoteConfig); + }); +}); diff --git a/test/integration/typescript/src/example.test.ts b/test/integration/typescript/src/example.test.ts index 5aa63c083d..2d97196477 100644 --- a/test/integration/typescript/src/example.test.ts +++ b/test/integration/typescript/src/example.test.ts @@ -25,8 +25,12 @@ import * as admin from 'firebase-admin'; // eslint-disable-next-line @typescript-eslint/no-var-requires const serviceAccount = require('../mock.key.json'); -describe('Init App', () => { - const app: admin.app.App = initApp(serviceAccount, 'TestApp'); +describe('Legacy API', () => { + let app: admin.app.App; + + before(() => { + app = initApp(serviceAccount, 'TestApp'); + }); after(() => { return app.delete(); From 69368effd2e36de9bf8882eeb4720a1fccc25cc5 Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Mon, 22 Feb 2021 15:45:06 -0800 Subject: [PATCH 2/3] fix: Added newline at eof --- app/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firestore/package.json | 2 +- instance-id/package.json | 2 +- machine-learning/package.json | 2 +- messaging/package.json | 2 +- project-management/package.json | 2 +- remote-config/package.json | 2 +- security-rules/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/package.json b/app/package.json index 64afe6e0b7..f7a8a1d97b 100644 --- a/app/package.json +++ b/app/package.json @@ -1,4 +1,4 @@ { "main": "../lib/app/index.js", "types": "../lib/app/index.d.ts" -} \ No newline at end of file +} diff --git a/auth/package.json b/auth/package.json index 3c1d1a76d7..153078adc9 100644 --- a/auth/package.json +++ b/auth/package.json @@ -1,4 +1,4 @@ { "main": "../lib/auth/index.js", "types": "../lib/auth/index.d.ts" -} \ No newline at end of file +} diff --git a/database/package.json b/database/package.json index 65fe6a2fcf..e4d1abe910 100644 --- a/database/package.json +++ b/database/package.json @@ -1,4 +1,4 @@ { "main": "../lib/database/index.js", "types": "../lib/database/index.d.ts" -} \ No newline at end of file +} diff --git a/firestore/package.json b/firestore/package.json index a4749c5968..3a8bc3c82b 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -1,4 +1,4 @@ { "main": "../lib/firestore/index.js", "types": "../lib/firestore/index.d.ts" -} \ No newline at end of file +} diff --git a/instance-id/package.json b/instance-id/package.json index 974734b551..ae3d8c608d 100644 --- a/instance-id/package.json +++ b/instance-id/package.json @@ -1,4 +1,4 @@ { "main": "../lib/instance-id/index.js", "types": "../lib/instance-id/index.d.ts" -} \ No newline at end of file +} diff --git a/machine-learning/package.json b/machine-learning/package.json index 975c2415a8..c384af270c 100644 --- a/machine-learning/package.json +++ b/machine-learning/package.json @@ -1,4 +1,4 @@ { "main": "../lib/machine-learning/index.js", "types": "../lib/machine-learning/index.d.ts" -} \ No newline at end of file +} diff --git a/messaging/package.json b/messaging/package.json index 67a196d11f..d6ba4636f4 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -1,4 +1,4 @@ { "main": "../lib/messaging/index.js", "types": "../lib/messaging/index.d.ts" -} \ No newline at end of file +} diff --git a/project-management/package.json b/project-management/package.json index fb0a8ce015..9acb6a6019 100644 --- a/project-management/package.json +++ b/project-management/package.json @@ -1,4 +1,4 @@ { "main": "../lib/project-management/index.js", "types": "../lib/project-management/index.d.ts" -} \ No newline at end of file +} diff --git a/remote-config/package.json b/remote-config/package.json index 437306a95d..be6bf45057 100644 --- a/remote-config/package.json +++ b/remote-config/package.json @@ -1,4 +1,4 @@ { "main": "../lib/remote-config/index.js", "types": "../lib/remote-config/index.d.ts" -} \ No newline at end of file +} diff --git a/security-rules/package.json b/security-rules/package.json index aafdc49016..b1004cf41d 100644 --- a/security-rules/package.json +++ b/security-rules/package.json @@ -1,4 +1,4 @@ { "main": "../lib/security-rules/index.js", "types": "../lib/security-rules/index.d.ts" -} \ No newline at end of file +} diff --git a/storage/package.json b/storage/package.json index 738b3d96be..1185f2b43b 100644 --- a/storage/package.json +++ b/storage/package.json @@ -1,4 +1,4 @@ { "main": "../lib/storage/index.js", "types": "../lib/storage/index.d.ts" -} \ No newline at end of file +} From f33252b98a017de0e6d18f0d11cd178b3ad8644e Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Wed, 3 Mar 2021 14:34:44 -0800 Subject: [PATCH 3/3] chore: Bumped minimum Node version to 12; Added typeVersions workaround --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 4 ++-- app/package.json | 4 ---- auth/package.json | 4 ---- database/package.json | 4 ---- firestore/package.json | 4 ---- instance-id/package.json | 4 ---- machine-learning/package.json | 4 ---- messaging/package.json | 4 ---- package.json | 30 +++++++++++++++++------------- project-management/package.json | 4 ---- remote-config/package.json | 4 ---- security-rules/package.json | 4 ---- storage/package.json | 4 ---- 14 files changed, 20 insertions(+), 60 deletions(-) delete mode 100644 app/package.json delete mode 100644 auth/package.json delete mode 100644 database/package.json delete mode 100644 firestore/package.json delete mode 100644 instance-id/package.json delete mode 100644 machine-learning/package.json delete mode 100644 messaging/package.json delete mode 100644 project-management/package.json delete mode 100644 remote-config/package.json delete mode 100644 security-rules/package.json delete mode 100644 storage/package.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5810ed895..d5b8677630 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 14.x] + node-version: [12.x, 14.x] steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4740665e9c..7171414edc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x - name: Install and build run: | @@ -115,7 +115,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x - name: Publish preflight check id: preflight diff --git a/app/package.json b/app/package.json deleted file mode 100644 index f7a8a1d97b..0000000000 --- a/app/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/app/index.js", - "types": "../lib/app/index.d.ts" -} diff --git a/auth/package.json b/auth/package.json deleted file mode 100644 index 153078adc9..0000000000 --- a/auth/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/auth/index.js", - "types": "../lib/auth/index.d.ts" -} diff --git a/database/package.json b/database/package.json deleted file mode 100644 index e4d1abe910..0000000000 --- a/database/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/database/index.js", - "types": "../lib/database/index.d.ts" -} diff --git a/firestore/package.json b/firestore/package.json deleted file mode 100644 index 3a8bc3c82b..0000000000 --- a/firestore/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/firestore/index.js", - "types": "../lib/firestore/index.d.ts" -} diff --git a/instance-id/package.json b/instance-id/package.json deleted file mode 100644 index ae3d8c608d..0000000000 --- a/instance-id/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/instance-id/index.js", - "types": "../lib/instance-id/index.d.ts" -} diff --git a/machine-learning/package.json b/machine-learning/package.json deleted file mode 100644 index c384af270c..0000000000 --- a/machine-learning/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/machine-learning/index.js", - "types": "../lib/machine-learning/index.d.ts" -} diff --git a/messaging/package.json b/messaging/package.json deleted file mode 100644 index d6ba4636f4..0000000000 --- a/messaging/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/messaging/index.js", - "types": "../lib/messaging/index.d.ts" -} diff --git a/package.json b/package.json index d72d13a047..ea4731844d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "homepage": "https://firebase.google.com/", "engines": { - "node": ">=10.10.0" + "node": ">=12.7.0" }, "scripts": { "build": "gulp build", @@ -52,20 +52,24 @@ "lib/", "LICENSE", "README.md", - "package.json", - "app/", - "auth/", - "database/", - "firestore/", - "instance-id/", - "machine-learning", - "messaging/", - "project-management/", - "remote-config/", - "security-rules/", - "storage/" + "package.json" ], "types": "./lib/index.d.ts", + "typesVersions": { + "*": { + "app": ["lib/app"], + "auth": ["lib/auth"], + "database": ["lib/database"], + "firestore": ["lib/firestore"], + "instance-id": ["lib/instance-id"], + "machine-learning": ["lib/machine-learning"], + "messaging": ["lib/messaging"], + "project-management": ["lib/project-management"], + "remote-config": ["lib/remote-config"], + "security-rules": ["lib/security-rules"], + "storage": ["lib/storage"] + } + }, "exports": { ".": "./lib/index.js", "./app": "./lib/app/index.js", diff --git a/project-management/package.json b/project-management/package.json deleted file mode 100644 index 9acb6a6019..0000000000 --- a/project-management/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/project-management/index.js", - "types": "../lib/project-management/index.d.ts" -} diff --git a/remote-config/package.json b/remote-config/package.json deleted file mode 100644 index be6bf45057..0000000000 --- a/remote-config/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/remote-config/index.js", - "types": "../lib/remote-config/index.d.ts" -} diff --git a/security-rules/package.json b/security-rules/package.json deleted file mode 100644 index b1004cf41d..0000000000 --- a/security-rules/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/security-rules/index.js", - "types": "../lib/security-rules/index.d.ts" -} diff --git a/storage/package.json b/storage/package.json deleted file mode 100644 index 1185f2b43b..0000000000 --- a/storage/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main": "../lib/storage/index.js", - "types": "../lib/storage/index.d.ts" -}