Skip to content

Commit fb59dea

Browse files
authored
feat(delete-user-data): add non-default firestore instance support (#2514)
2 parents efa7c8f + a60c344 commit fb59dea

File tree

12 files changed

+670
-601
lines changed

12 files changed

+670
-601
lines changed

delete-user-data/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Version 0.1.25
2+
3+
feat - add support for multiple Firestore databases via FIRESTORE_DATABASE_ID parameter
4+
5+
fix - run npm audit fix
6+
17
## Version 0.1.24
28

39
feat - move to Node.js 20 runtimes

delete-user-data/PREINSTALL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Depending on where you'd like to delete user data from, make sure that you've se
1414

1515
Also, make sure that you've set up [Firebase Authentication](https://firebase.google.com/docs/auth) to manage your users.
1616

17+
**Note about multiple Firestore databases:** This extension supports using non-default Firestore databases. During installation, you can specify which database to use via the `FIRESTORE_DATABASE_ID` parameter. Use "(default)" for the default database, or specify your named database ID.
18+
1719
#### Billing
1820
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
1921

delete-user-data/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Depending on where you'd like to delete user data from, make sure that you've se
2222

2323
Also, make sure that you've set up [Firebase Authentication](https://firebase.google.com/docs/auth) to manage your users.
2424

25+
**Note about multiple Firestore databases:** This extension supports using non-default Firestore databases. During installation, you can specify which database to use via the `FIRESTORE_DATABASE_ID` parameter. Use "(default)" for the default database, or specify your named database ID.
26+
2527
#### Billing
2628
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
2729

@@ -37,6 +39,8 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan
3739

3840
**Configuration Parameters:**
3941

42+
* Firestore Database ID: The ID of 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.
43+
4044
* Cloud Firestore paths: Which paths in your Cloud Firestore instance contain data keyed on a user ID? Leave empty if you don't use Cloud Firestore.
4145
Enter the full paths, separated by commas. Use `{UID}` as a placeholder for the user's UID.
4246
For example, if you have the collections `users` and `admins`, and each collection has documents with User ID as document IDs, then enter `users/{UID},admins/{UID}`.

delete-user-data/extension.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: delete-user-data
16-
version: 0.1.24
16+
version: 0.1.25
1717
specVersion: v1beta
1818

1919
displayName: Delete User Data
@@ -86,6 +86,16 @@ resources:
8686
resource: projects/${PROJECT_ID}/topics/ext-${EXT_INSTANCE_ID}-deletion
8787

8888
params:
89+
- param: FIRESTORE_DATABASE_ID
90+
label: Firestore Database ID
91+
description: >-
92+
The ID of the Firestore database to use. Use "(default)" for the default
93+
database. You can view your available Firestore databases at
94+
https://console.cloud.google.com/firestore/databases.
95+
type: string
96+
default: (default)
97+
required: true
98+
8999
- param: FIRESTORE_PATHS
90100
label: Cloud Firestore paths
91101
description: >-

delete-user-data/functions/__tests__/recursiveDelete.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("recursiveDelete", () => {
2020
foo: "bar",
2121
});
2222

23-
await recursiveDelete(ref);
23+
await recursiveDelete(ref, db);
2424

2525
const doc = db.doc(ref);
2626
await doc.get().then((doc) => {
@@ -34,7 +34,7 @@ describe("recursiveDelete", () => {
3434
foo: "bar",
3535
});
3636

37-
await recursiveDelete(ref);
37+
await recursiveDelete(ref, db);
3838

3939
const collection = db.collection(ref);
4040
await collection.get().then((collection) => {
@@ -49,7 +49,7 @@ describe("recursiveDelete", () => {
4949
foo: "bar",
5050
});
5151

52-
await recursiveDelete(parentRef);
52+
await recursiveDelete(parentRef, db);
5353

5454
const collection = db.collection(ref);
5555
await collection.get().then((collection) => {

delete-user-data/functions/__tests__/search.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("discovery", () => {
4444

4545
describe("searches on top level collections", () => {
4646
test("can delete is single collection named {uid}", async () => {
47-
await search(user.uid, 1);
47+
await search(user.uid, 1, db);
4848

4949
await waitForCollectionDeletion(rootCollection, 20_000);
5050
}, 60000);
@@ -53,7 +53,7 @@ describe("discovery", () => {
5353
describe("searches on top level collection documents", () => {
5454
test("can delete a document named {uid}", async () => {
5555
const document = await db.collection(generateRandomId()).doc(user.uid);
56-
await search(user.uid, 1);
56+
await search(user.uid, 1, db);
5757

5858
await waitForDocumentDeletion(document);
5959
}, 60000);
@@ -62,14 +62,14 @@ describe("discovery", () => {
6262
const document = await db
6363
.collection(generateRandomId())
6464
.add({ field1: user.uid });
65-
await search(user.uid, 1);
65+
await search(user.uid, 1, db);
6666

6767
await waitForDocumentDeletion(document, 60000);
6868
}, 60000);
6969

7070
test("can check a document without any field values", async () => {
7171
await db.collection(generateRandomId()).add({});
72-
await search(user.uid, 1);
72+
await search(user.uid, 1, db);
7373

7474
expect(true).toBeTruthy();
7575
}, 60000);
@@ -93,7 +93,7 @@ describe("discovery", () => {
9393

9494
expect(checkExists).toBe(true);
9595

96-
await search(user.uid, 1);
96+
await search(user.uid, 1, db);
9797

9898
await waitForCollectionDeletion(subcollection);
9999
}, 60000);
@@ -118,7 +118,7 @@ describe("discovery", () => {
118118

119119
expect(collectionPathCount).toBeGreaterThan(config.searchDepth);
120120

121-
await search(user.uid, 1);
121+
await search(user.uid, 1, db);
122122

123123
// /** Wait 10 seconds for the discovery to complete */
124124
await new Promise((resolve) => setTimeout(resolve, 20000));
@@ -149,7 +149,7 @@ describe("discovery", () => {
149149

150150
expect(collectionPathCount).toBeGreaterThan(config.searchDepth);
151151

152-
await search(user.uid, 1);
152+
await search(user.uid, 1, db);
153153

154154
// /** Wait 10 seconds for the discovery to complete */
155155
await new Promise((resolve) => setTimeout(resolve, 20000));
@@ -169,7 +169,7 @@ describe("discovery", () => {
169169
const collection = await db.collection(generateRandomId());
170170
const document = await collection.add({ testing: "should-not-delete" });
171171

172-
await search(collection.id, -1, document);
172+
await search(collection.id, -1, db, document);
173173

174174
/** Check document still exists */
175175
const checkExists = await document.get().then((doc) => doc.exists);
@@ -180,7 +180,7 @@ describe("discovery", () => {
180180
const document = await db
181181
.collection(generateRandomId())
182182
.add({ field1: "unknown" });
183-
await search(user.uid, 1);
183+
await search(user.uid, 1, db);
184184

185185
/** Wait 10 seconds */
186186
await new Promise((resolve) => setTimeout(resolve, 10000));

0 commit comments

Comments
 (0)