Skip to content

Commit 92d89ab

Browse files
CorieWcabljac
andauthored
feat(firestore-send-email): migrate to v2 cloud function (#2359)
* feat(firestore-send-email): migrate to v2 cloud function * chore(firestore-send-email): format * chore(firestore-send-email): generate readme and fix issue in extension.yaml * fix(firestore-send-email): sourceDirectory * fix(firestore-send-email): correct database being used * fix(firestore-send-email): fixing tests * chore(firestore-send-email): format * chore(firestore-send-email): rid of unnecessary files * fix(firestore-send-email): fixing tests * fix(firestore-send-email): fix extension.yaml * chore(firestore-send-email): generate readme and fix issue in extension.yaml * fix(firestore-send-email): correct database being used * chore(firestore-send-email): rid of unnecessary files * Apply suggestions from code review fix: add defaults to config.ts to make tests run --------- Co-authored-by: Jacob Cable <[email protected]>
1 parent b4cdf33 commit 92d89ab

File tree

11 files changed

+6533
-11537
lines changed

11 files changed

+6533
-11537
lines changed

Diff for: firestore-send-email/CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
## Version 0.1.38
1+
## Version 0.2.0
22

3-
fix: empty message property causing error when using SendGrid
3+
feat: use v2 firestore trigger
4+
5+
feat: allow non-(default) firestore instances
46

57
## Version 0.1.37
68

Diff for: firestore-send-email/POSTINSTALL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
You can test out this extension right away!
44

5-
1. Go to your [Cloud Firestore dashboard](https://console.firebase.google.com/project/${param:PROJECT_ID}/firestore/data) in the Firebase console.
5+
1. Go to your [Cloud Firestore dashboard](https://console.firebase.google.com/project/${param:PROJECT_ID}/firestore/data) in the Firebase console. Note that, if you have configured a non-default firestore database, you may have to view it via the [Google Cloud Console](https://console.cloud.google.com/firestore/databases/${param:DATABASE}).
66

77
1. If it doesn't already exist, create the collection you specified during installation: `${param:MAIL_COLLECTION}`.
88

Diff for: firestore-send-email/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ You can find more information about this extension in the following articles:
219219

220220
**Configuration Parameters:**
221221

222+
* Firestore Instance ID: The Firestore database to use. Use "(default)" for the default database. You can view your available Firestore databases at [https://console.cloud.google.com/firestore/databases](https://console.cloud.google.com/firestore/databases).
223+
224+
225+
* Firestore Instance Location: Where is the Firestore database located? You can check your current database location at [https://console.cloud.google.com/firestore/databases](https://console.cloud.google.com/firestore/databases).
226+
227+
222228
* Authentication Type: The authentication type to be used for the SMTP server (e.g., OAuth2, Username & Password.
223229

224230
* SMTP connection URI: A URI representing an SMTP server this extension can use to deliver email. Note that port 25 is blocked by Google Cloud Platform, so we recommend using port 587 for SMTP connections. If you're using the SMTPS protocol, we recommend using port 465. In order to keep passwords secure, it is recommended to omit the password from the connection string while using the `SMTP Password` field for entering secrets and passwords. Passwords and secrets should now be included in `SMTP password` field.
@@ -263,9 +269,9 @@ password)
263269

264270

265271

266-
**Cloud Functions:**
272+
**Other Resources**:
267273

268-
* **processQueue:** Processes document changes in the specified Cloud Firestore collection, delivers emails, and updates the document with delivery status information.
274+
* processQueue (firebaseextensions.v1beta.v2function)
269275

270276

271277

Diff for: firestore-send-email/extension.yaml

+141-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: firestore-send-email
16-
version: 0.1.38
16+
version: 0.2.0
1717
specVersion: v1beta
1818

1919
displayName: Trigger Email from Firestore
@@ -47,18 +47,154 @@ roles:
4747

4848
resources:
4949
- name: processQueue
50-
type: firebaseextensions.v1beta.function
50+
type: firebaseextensions.v1beta.v2function
5151
description:
5252
Processes document changes in the specified Cloud Firestore collection,
5353
delivers emails, and updates the document with delivery status
5454
information.
5555
properties:
56-
runtime: nodejs20
56+
sourceDirectory: functions
57+
buildConfig:
58+
runtime: nodejs22
59+
serviceConfig:
60+
timeoutSeconds: 120
5761
eventTrigger:
58-
eventType: providers/cloud.firestore/eventTypes/document.write
59-
resource: projects/${param:PROJECT_ID}/databases/(default)/documents/${param:MAIL_COLLECTION}/{id}
62+
eventType: google.cloud.firestore.document.v1.written
63+
triggerRegion: ${DATABASE_REGION}
64+
eventFilters:
65+
- attribute: database
66+
value: ${DATABASE}
67+
- attribute: document
68+
value: ${MAIL_COLLECTION}/{documentId}
69+
operator: match-path-pattern
6070

6171
params:
72+
- param: DATABASE
73+
label: Firestore Instance ID
74+
description: >
75+
The Firestore database to use. Use "(default)" for the default database.
76+
You can view your available Firestore databases at
77+
[https://console.cloud.google.com/firestore/databases](https://console.cloud.google.com/firestore/databases).
78+
example: (default)
79+
default: (default)
80+
required: true
81+
82+
- param: DATABASE_REGION
83+
label: Firestore Instance Location
84+
description: >
85+
Where is the Firestore database located? You can check your current
86+
database location at
87+
[https://console.cloud.google.com/firestore/databases](https://console.cloud.google.com/firestore/databases).
88+
type: select
89+
options:
90+
# Multi-region locations
91+
- label: Multi-region (Europe - Belgium and Netherlands)
92+
value: eur3
93+
- label: Multi-region (United States)
94+
value: nam5
95+
- label: Multi-region (Iowa, North Virginia, and Oklahoma)
96+
value: nam7
97+
98+
# North America
99+
- label: Iowa (us-central1)
100+
value: us-central1
101+
- label: Oregon (us-west1)
102+
value: us-west1
103+
- label: Los Angeles (us-west2)
104+
value: us-west2
105+
- label: Salt Lake City (us-west3)
106+
value: us-west3
107+
- label: Las Vegas (us-west4)
108+
value: us-west4
109+
- label: South Carolina (us-east1)
110+
value: us-east1
111+
- label: Northern Virginia (us-east4)
112+
value: us-east4
113+
- label: Columbus (us-east5)
114+
value: us-east5
115+
- label: Dallas (us-south1)
116+
value: us-south1
117+
- label: Montreal (northamerica-northeast1)
118+
value: northamerica-northeast1
119+
- label: Toronto (northamerica-northeast2)
120+
value: northamerica-northeast2
121+
- label: Queretaro (northamerica-south1)
122+
value: northamerica-south1
123+
124+
# South America
125+
- label: Sao Paulo (southamerica-east1)
126+
value: southamerica-east1
127+
- label: Santiago (southamerica-west1)
128+
value: southamerica-west1
129+
130+
# Europe
131+
- label: Belgium (europe-west1)
132+
value: europe-west1
133+
- label: London (europe-west2)
134+
value: europe-west2
135+
- label: Frankfurt (europe-west3)
136+
value: europe-west3
137+
- label: Netherlands (europe-west4)
138+
value: europe-west4
139+
- label: Zurich (europe-west6)
140+
value: europe-west6
141+
- label: Milan (europe-west8)
142+
value: europe-west8
143+
- label: Paris (europe-west9)
144+
value: europe-west9
145+
- label: Berlin (europe-west10)
146+
value: europe-west10
147+
- label: Turin (europe-west12)
148+
value: europe-west12
149+
- label: Madrid (europe-southwest1)
150+
value: europe-southwest1
151+
- label: Finland (europe-north1)
152+
value: europe-north1
153+
- label: Stockholm (europe-north2)
154+
value: europe-north2
155+
- label: Warsaw (europe-central2)
156+
value: europe-central2
157+
158+
# Middle East
159+
- label: Doha (me-central1)
160+
value: me-central1
161+
- label: Dammam (me-central2)
162+
value: me-central2
163+
- label: Tel Aviv (me-west1)
164+
value: me-west1
165+
166+
# Asia
167+
- label: Mumbai (asia-south1)
168+
value: asia-south1
169+
- label: Delhi (asia-south2)
170+
value: asia-south2
171+
- label: Singapore (asia-southeast1)
172+
value: asia-southeast1
173+
- label: Jakarta (asia-southeast2)
174+
value: asia-southeast2
175+
- label: Taiwan (asia-east1)
176+
value: asia-east1
177+
- label: Hong Kong (asia-east2)
178+
value: asia-east2
179+
- label: Tokyo (asia-northeast1)
180+
value: asia-northeast1
181+
- label: Osaka (asia-northeast2)
182+
value: asia-northeast2
183+
- label: Seoul (asia-northeast3)
184+
value: asia-northeast3
185+
186+
# Australia
187+
- label: Sydney (australia-southeast1)
188+
value: australia-southeast1
189+
- label: Melbourne (australia-southeast2)
190+
value: australia-southeast2
191+
192+
# Africa
193+
- label: Johannesburg (africa-south1)
194+
value: africa-south1
195+
required: true
196+
immutable: false
197+
62198
- param: AUTH_TYPE
63199
label: Authentication Type
64200
description: >-

Diff for: firestore-send-email/functions/__tests__/config.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ functionsTestInit();
1111

1212
const environment = {
1313
LOCATION: "us-central1",
14+
DATABASE: "fake-database",
15+
DATABASE_REGION: "us-central1",
1416
TEMPLATES_COLLECTION: "templates",
1517
MAIL_COLLECTION: "mail",
1618
SMTP_CONNECTION_URI:
@@ -41,6 +43,8 @@ describe("extensions config", () => {
4143
test("config loaded from environment variables", () => {
4244
const testConfig: Config = {
4345
location: process.env.LOCATION,
46+
database: process.env.DATABASE,
47+
databaseRegion: process.env.DATABASE_REGION,
4448
mailCollection: process.env.MAIL_COLLECTION,
4549
smtpConnectionUri: process.env.SMTP_CONNECTION_URI,
4650
smtpPassword: process.env.SMTP_PASSWORD,

Diff for: firestore-send-email/functions/__tests__/helpers.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const regex = new RegExp(
1414
describe("setSmtpCredentials function", () => {
1515
test("return smtpServerDomain credentials with new password", () => {
1616
const config: Config = {
17+
database: "fake-database",
18+
databaseRegion: "us-central1",
1719
smtpConnectionUri:
1820
1921
smtpPassword: "fakepassword",
@@ -35,6 +37,8 @@ describe("setSmtpCredentials function", () => {
3537

3638
test("return smtpServerDomain credentials with old password", () => {
3739
const config: Config = {
40+
database: "fake-database",
41+
databaseRegion: "us-central1",
3842
smtpConnectionUri:
3943
4044
location: "",
@@ -56,6 +60,8 @@ describe("setSmtpCredentials function", () => {
5660

5761
test("return smtpConnectionUri credentials without any password", () => {
5862
const config: Config = {
63+
database: "fake-database",
64+
databaseRegion: "us-central1",
5965
smtpConnectionUri: "smtps://[email protected]@smtp.gmail.com:465",
6066
location: "",
6167
mailCollection: "",
@@ -76,6 +82,8 @@ describe("setSmtpCredentials function", () => {
7682

7783
test("return smtpConnectionUri credentials without any password and username", () => {
7884
const config: Config = {
85+
database: "fake-database",
86+
databaseRegion: "us-central1",
7987
smtpConnectionUri: "smtp://smtp.gmail.com:465",
8088
location: "",
8189
mailCollection: "",
@@ -95,6 +103,8 @@ describe("setSmtpCredentials function", () => {
95103

96104
test("return smtpConnectionUri credentials with query params", () => {
97105
const config: Config = {
106+
database: "fake-database",
107+
databaseRegion: "us-central1",
98108
smtpConnectionUri:
99109
"smtp://[email protected]:[email protected]:465?pool=true&service=gmail",
100110
location: "",
@@ -118,6 +128,8 @@ describe("setSmtpCredentials function", () => {
118128

119129
test("return valid smtpConnectionUri credentials with valid special chars in password", () => {
120130
const config: Config = {
131+
database: "fake-database",
132+
databaseRegion: "us-central1",
121133
smtpConnectionUri:
122134
"smtp://[email protected]@smtp.gmail.com:465?pool=true&service=gmail",
123135
smtpPassword: "4,h?dhuNTbv9zMrP4&7&7%*3",
@@ -142,6 +154,8 @@ describe("setSmtpCredentials function", () => {
142154

143155
test("return valid smtpConnectionUri credentials with valid special chars in connectionUri password", () => {
144156
const config: Config = {
157+
database: "fake-database",
158+
databaseRegion: "us-central1",
145159
smtpConnectionUri:
146160
"smtp://[email protected]:4,hdhuNTbv9zMrP4&7&7%*[email protected]:465?pool=true&service=gmail",
147161
location: "",
@@ -166,6 +180,8 @@ describe("setSmtpCredentials function", () => {
166180

167181
test("throw error for invalid smtpConnectionUri", () => {
168182
const config: Config = {
183+
database: "fake-database",
184+
databaseRegion: "us-central1",
169185
smtpConnectionUri:
170186
"smtp://[email protected]:4,h?dhuNTbv9zMrP4&7&7%*[email protected]:465?pool=true&service=gmail",
171187
location: "",
@@ -184,6 +200,8 @@ describe("setSmtpCredentials function", () => {
184200
describe("isSendGrid function", () => {
185201
test("return true for SendGrid SMTP URI", () => {
186202
const config: Config = {
203+
database: "fake-database",
204+
databaseRegion: "us-central1",
187205
smtpConnectionUri: "smtps://[email protected]:465",
188206
location: "",
189207
mailCollection: "",
@@ -196,6 +214,8 @@ describe("isSendGrid function", () => {
196214

197215
test("return false for non-SendGrid SMTP URI", () => {
198216
const config: Config = {
217+
database: "fake-database",
218+
databaseRegion: "us-central1",
199219
smtpConnectionUri:
200220
201221
location: "",
@@ -210,6 +230,8 @@ describe("isSendGrid function", () => {
210230

211231
test("return invalid smtpConnectionUri credentials with invalid separator", () => {
212232
const config: Config = {
233+
database: "fake-database",
234+
databaseRegion: "us-central1",
213235
smtpConnectionUri:
214236
"smtp://[email protected]:4,h?dhuNTbv9zMrP4&7&7%*3:smtp.gmail.com:465?pool=true&service=gmail",
215237
location: "",
@@ -224,6 +246,8 @@ test("return invalid smtpConnectionUri credentials with invalid separator", () =
224246

225247
test("correctly detects SendGrid SMTP URI", () => {
226248
const config: Config = {
249+
database: "fake-database",
250+
databaseRegion: "us-central1",
227251
smtpConnectionUri: "smtps://[email protected]:465",
228252
location: "",
229253
mailCollection: "",
@@ -234,6 +258,8 @@ test("correctly detects SendGrid SMTP URI", () => {
234258
expect(isSendGrid(config)).toBe(true);
235259

236260
const invalidConfig: Config = {
261+
database: "fake-database",
262+
databaseRegion: "us-central1",
237263
smtpConnectionUri: "smtps://[email protected]:465",
238264
location: "",
239265
mailCollection: "",
@@ -246,6 +272,8 @@ test("correctly detects SendGrid SMTP URI", () => {
246272

247273
test("correctly uses oAuth credentials when provided", () => {
248274
const config: Config = {
275+
database: "fake-database",
276+
databaseRegion: "us-central1",
249277
smtpConnectionUri:
250278
251279
location: "",

0 commit comments

Comments
 (0)