From a2088e8c6f5a60d5f9319a6630f176f787d0d938 Mon Sep 17 00:00:00 2001 From: Gustolandia Date: Sat, 28 Dec 2024 01:04:32 +0000 Subject: [PATCH] doc: Add instructions for setting up Firestore TTL policies for delivery.expireAt field --- firestore-send-email/CHANGELOG.md | 4 ++++ firestore-send-email/POSTINSTALL.md | 11 +++++++++++ firestore-send-email/PREINSTALL.md | 3 +++ firestore-send-email/README.md | 11 +++++++++++ firestore-send-email/functions/src/index.ts | 4 ++++ 5 files changed, 33 insertions(+) diff --git a/firestore-send-email/CHANGELOG.md b/firestore-send-email/CHANGELOG.md index a7bdfb84e..436164ff3 100644 --- a/firestore-send-email/CHANGELOG.md +++ b/firestore-send-email/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Version 0.1.36 + +docs - Added instructions for setting up Firestore TTL policies for the `delivery.expireAt` field. + ## Version 0.1.35 fixed - SendGrid "no-categories" issues (#2053) diff --git a/firestore-send-email/POSTINSTALL.md b/firestore-send-email/POSTINSTALL.md index 0d74032ed..fc8cc2018 100644 --- a/firestore-send-email/POSTINSTALL.md +++ b/firestore-send-email/POSTINSTALL.md @@ -36,6 +36,17 @@ admin .then(() => console.log("Queued email for delivery!")); ``` +#### **Automatic Deletion of Email Documents** + +The `delivery.expireAt` field is automatically populated by the extension if TTL is enabled. To ensure expired email documents are deleted: + +1. Confirm that Firestore TTL is enabled in the extension's `.env` file: + ``` + TTL_EXPIRE_TYPE=minutes + TTL_EXPIRE_VALUE=2 + ``` +2. Configure a Firestore TTL policy targeting the `delivery.expireAt` field (as described in the README). + ### Using this extension See the [official documentation](https://firebase.google.com/docs/extensions/official/firestore-send-email) for information on using this extension, including advanced use cases such as using Handlebars templates and managing email delivery status. diff --git a/firestore-send-email/PREINSTALL.md b/firestore-send-email/PREINSTALL.md index e1b500e97..43eff2617 100644 --- a/firestore-send-email/PREINSTALL.md +++ b/firestore-send-email/PREINSTALL.md @@ -43,6 +43,9 @@ To use your Outlook/Hotmail email account with this extension, you'll need to ha Before installing this extension, make sure that you've [set up a Cloud Firestore database](https://firebase.google.com/docs/firestore/quickstart) in your Firebase project. +#### **Prerequisites for TTL Deletion** +If you intend to use TTL deletion, ensure your Firestore database supports TTL policies. This requires project permissions to enable and configure Firestore TTL policies for the `delivery.expireAt` field. + #### Billing To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing) diff --git a/firestore-send-email/README.md b/firestore-send-email/README.md index b79e03103..91a2ff885 100644 --- a/firestore-send-email/README.md +++ b/firestore-send-email/README.md @@ -97,6 +97,17 @@ password) * TLS Options: A JSON value representing TLS options. For more information, see https://nodejs.org/api/tls.html#tls_class_tls_tlssocket +#### **Configuring Firestore TTL for Email Document Expiry** +If you enable the Firestore TTL feature in the extension's configuration, ensure that you also configure Firestore to delete expired email documents automatically. This requires setting up a TTL policy on the `delivery.expireAt` field. + +To configure Firestore TTL: + +1. Open the Firebase Console and navigate to your Firestore database. +2. In the **Settings** (gear icon) section, locate **Firestore TTL Policies**. +3. Add a new TTL policy targeting the field `delivery.expireAt`. Use dot notation if necessary. +4. Save the configuration. + + **Cloud Functions:** diff --git a/firestore-send-email/functions/src/index.ts b/firestore-send-email/functions/src/index.ts index 8e16dc2fb..2fad33a71 100644 --- a/firestore-send-email/functions/src/index.ts +++ b/firestore-send-email/functions/src/index.ts @@ -82,6 +82,10 @@ function getExpireAt(startTime: admin.firestore.Timestamp) { const now = startTime.toDate(); const value = config.TTLExpireValue; switch (config.TTLExpireType) { + case "minute": + case "minutes": // Add this to support plural + now.setMinutes(now.getMinutes() + value); + break; case "hour": now.setHours(now.getHours() + value); break;