Skip to content

Commit

Permalink
doc: Add instructions for setting up Firestore TTL policies for deliv…
Browse files Browse the repository at this point in the history
…ery.expireAt field
  • Loading branch information
Gustolandia committed Dec 30, 2024
1 parent 29da9a4 commit a2088e8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions firestore-send-email/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 11 additions & 0 deletions firestore-send-email/POSTINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions firestore-send-email/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions firestore-send-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
4 changes: 4 additions & 0 deletions firestore-send-email/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a2088e8

Please sign in to comment.