Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add instructions for setting up Firestore TTL policies for delivery.expireAt field #2246

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.35

docs - Added instructions for setting up Firestore TTL policies for the `delivery.expireAt` field.

## Version 0.1.34

fixed - SendGrid v3 issues (#2020)
Expand Down
15 changes: 15 additions & 0 deletions firestore-send-email/POSTINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ admin
.then(() => console.log("Queued email for delivery!"));
```

### Automatic Deletion of Email Documents
To use Firestore's TTL feature for automatic deletion of expired email documents:

1. Enable Firestore TTL in your Firebase project settings.
2. Configure a TTL policy targeting the `delivery.expireAt` field:
- Open the Firebase Console.
- Navigate to the Firestore database settings (gear icon).
- Add a new TTL policy for `delivery.expireAt` (use dot notation for nested fields).
- Save the configuration.

3. Ensure your `.env` file is updated with:
```env
TTL_EXPIRE_TYPE=minutes
TTL_EXPIRE_VALUE=2

### 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
19 changes: 19 additions & 0 deletions firestore-send-email/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ 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**

To use Firestore's TTL feature for automatic deletion of expired email documents, follow these steps:

1. Enable Firestore TTL in your Firebase project settings.

2. Configure a TTL policy targeting the `delivery.expireAt` field in Firestore:
- Open the Firebase Console.
- Navigate to the Firestore database settings (gear icon).
- Add a new TTL policy for `delivery.expireAt` (use dot notation for nested fields).
- Save the configuration.

3. Update the `.env` file in your extension's configuration with:
```env
TTL_EXPIRE_TYPE=minutes
TTL_EXPIRE_VALUE=2


#### Billing
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)

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

To use Firestore's TTL feature for automatic deletion of expired email documents, follow these steps:

1. Enable Firestore TTL in your Firebase project settings.

2. Configure a TTL policy targeting the `delivery.expireAt` field in Firestore:
- Open the Firebase Console.
- Navigate to the Firestore database settings (gear icon).
- Add a new TTL policy for `delivery.expireAt` (use dot notation for nested fields).
- Save the configuration.

3. Update the `.env` file in your extension's configuration with:
```env
TTL_EXPIRE_TYPE=minutes
TTL_EXPIRE_VALUE=2


#### Billing
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)

Expand Down
2 changes: 1 addition & 1 deletion firestore-send-email/extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

name: firestore-send-email
version: 0.1.34
version: 0.1.35
specVersion: v1beta

displayName: Trigger Email from Firestore
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 @@ -85,6 +85,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
Loading