diff --git a/firestore-bigquery-export/scripts/gen-schema-view/package.json b/firestore-bigquery-export/scripts/gen-schema-view/package.json index ff751073c..3060cb803 100644 --- a/firestore-bigquery-export/scripts/gen-schema-view/package.json +++ b/firestore-bigquery-export/scripts/gen-schema-view/package.json @@ -1,6 +1,6 @@ { "name": "@firebaseextensions/fs-bq-schema-views", - "version": "0.4.5", + "version": "0.4.6", "description": "Generate strongly-typed BigQuery Views based on raw JSON", "main": "./lib/index.js", "repository": { @@ -55,4 +55,4 @@ "ts-node": "^7.0.1", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts index a47eebe46..6815f53cf 100644 --- a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts +++ b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts @@ -120,10 +120,12 @@ async function run(): Promise { process.env.GOOGLE_CLOUD_PROJECT = config.projectId; // Initialize Firebase - firebase.initializeApp({ - credential: firebase.credential.applicationDefault(), - databaseURL: `https://${config.projectId}.firebaseio.com`, - }); + if (!firebase.apps.length) { + firebase.initializeApp({ + credential: firebase.credential.applicationDefault(), + databaseURL: `https://${config.projectId}.firebaseio.com`, + }); + } // @ts-ignore string not assignable to enum if (Object.keys(config.schemas).length === 0) { diff --git a/firestore-bigquery-export/scripts/import/package.json b/firestore-bigquery-export/scripts/import/package.json index e142d4aaa..3f22df573 100644 --- a/firestore-bigquery-export/scripts/import/package.json +++ b/firestore-bigquery-export/scripts/import/package.json @@ -1,6 +1,6 @@ { "name": "@firebaseextensions/fs-bq-import-collection", - "version": "0.1.16", + "version": "0.1.17", "description": "Import a Firestore Collection into a BigQuery Changelog Table", "main": "./lib/index.js", "repository": { @@ -48,4 +48,4 @@ "ts-node": "^10.9.1", "typescript": "^4.2.4" } -} +} \ No newline at end of file diff --git a/firestore-bigquery-export/scripts/import/src/index.ts b/firestore-bigquery-export/scripts/import/src/index.ts index cd78d3d8a..ee9fd7821 100644 --- a/firestore-bigquery-export/scripts/import/src/index.ts +++ b/firestore-bigquery-export/scripts/import/src/index.ts @@ -121,11 +121,12 @@ const run = async (): Promise => { // Initialize Firebase // This uses applicationDefault to authenticate // Please see https://cloud.google.com/docs/authentication/production - firebase.initializeApp({ - credential: firebase.credential.applicationDefault(), - databaseURL: `https://${projectId}.firebaseio.com`, - }); - + if (!firebase.apps.length) { + firebase.initializeApp({ + credential: firebase.credential.applicationDefault(), + databaseURL: `https://${projectId}.firebaseio.com`, + }); + } // Set project ID, so it can be used in BigQuery initialization process.env.PROJECT_ID = projectId; process.env.GOOGLE_CLOUD_PROJECT = projectId; diff --git a/firestore-send-email/CHANGELOG.md b/firestore-send-email/CHANGELOG.md index d35cfdd77..fbc6534d0 100644 --- a/firestore-send-email/CHANGELOG.md +++ b/firestore-send-email/CHANGELOG.md @@ -1,3 +1,7 @@ +## Version 0.1.23 + +fixed - added template check when no message exists + ## Version 0.1.22 fixed - fix typo in extension diff --git a/firestore-send-email/extension.yaml b/firestore-send-email/extension.yaml index 66dfedc4a..cba4a218a 100644 --- a/firestore-send-email/extension.yaml +++ b/firestore-send-email/extension.yaml @@ -13,7 +13,7 @@ # limitations under the License. name: firestore-send-email -version: 0.1.22 +version: 0.1.23 specVersion: v1beta displayName: Trigger Email diff --git a/firestore-send-email/functions/__tests__/e2e.test.ts b/firestore-send-email/functions/__tests__/e2e.test.ts index 3b649c9c7..f964c741e 100644 --- a/firestore-send-email/functions/__tests__/e2e.test.ts +++ b/firestore-send-email/functions/__tests__/e2e.test.ts @@ -106,6 +106,42 @@ describe("e2e testing", () => { }); }, 8000); + test("should successfully send an email with a basic template", async (): Promise => { + /** create basic template */ + const template = await templatesCollection.add({ + subject: "@{{username}} is now following you!", + }); + + /** Add a record with the template and no message object */ + const record = { + to: "test-assertion@email.com", + template: { + name: template.id, + data: { + username: "ada", + }, + }, + }; + + /** Add a new mail document */ + const doc = await mailCollection.add(record); + + /** Check the email response */ + return new Promise((resolve, reject) => { + const unsubscribe = doc.onSnapshot((snapshot) => { + const document = snapshot.data(); + + if (document.delivery && document.delivery.info) { + expect(document.delivery.info.accepted[0]).toEqual(record.to); + expect(document.delivery.info.response).toContain("250 Accepted"); + + unsubscribe(); + resolve(); + } + }); + }); + }); + afterAll(() => { server.close(); }); diff --git a/firestore-send-email/functions/src/index.ts b/firestore-send-email/functions/src/index.ts index 3f539f21f..8332e0741 100644 --- a/firestore-send-email/functions/src/index.ts +++ b/firestore-send-email/functions/src/index.ts @@ -352,8 +352,8 @@ async function processWrite( const payload = snapshot.data(); // We expect the payload to contain a message object describing the email - // to be sent. If it doesn't, we can't do anything. - if (typeof payload.message !== "object") { + // to be sent. If it doesn't and is not a template, we can't do anything. + if (typeof payload.message !== "object" && !payload.template) { logs.invalidMessage(payload.message); return false; }