Skip to content

fix(delete-user-data): reject invalid select and regex param values at deploy - #3278

Merged
CorieW merged 9 commits into
kitsfrom
fix/kits-delete-user-data-validate-params
Oct 27, 2026
Merged

CorieW merged 9 commits into
kitsfrom
fix/kits-delete-user-data-validate-params

Conversation

@CorieW

@CorieW CorieW commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Rejects the .env values the extension refuses at install time, so the kit's deploy fails instead of deploying and quietly deleting less data. Values the extension accepts, its option labels included, still deploy and run as they did in the extension. Fixes #3258 (part of #3249).

Changes

Example error:

Error: Invalid parameter values: FIRESTORE_DELETE_MODE="RECURSIVE" must be one of: recursive, shallow. Fix them in this instance's .env or .env.<projectId> file, or remove the entries to use their defaults.

Testing

Deployed on a test project: the extension firebase/delete-user-data@0.1.30, the kit from kits and the fixed kit, each with its own Firestore database. Each had FIRESTORE_PATHS=users/{UID} and was seeded with users/<uid>, users/<uid>/sub/s1, things/t-<uid> {uid} and a control doc; then a test user was deleted.

Bad values (extension checked with the instances API validateOnly=true; kits with a real firebase deploy):

.env value Extension Kit before Kit after
FIRESTORE_DELETE_MODE=RECURSIVE / recursivex rejected deploys deploy fails
FIRESTORE_DELETE_MODE=Recursive (label) accepted deploys deploys¹
ENABLE_AUTO_DISCOVERY=true / YES rejected deploys deploy fails
SELECTED_DATABASE_LOCATION=us-east1 / US-CENTRAL1 rejected deploys deploy fails
SELECTED_DATABASE_INSTANCE=https://x.firebaseio.com rejected deploys deploy fails
CLOUD_STORAGE_BUCKET=gs://x / Upper_Case rejected deploys deploy fails
blank SELECTED_DATABASE_INSTANCE / SELECTED_DATABASE_LOCATION accepted deploys deploys

¹ The deploy run rejected labels; accepting them came later (32a478f) and is covered by unit tests, not a fresh deploy.

The kit before deployed with all five bad values in one .env; the runtime env held them as written.

User deletion (extension and fixed kit with recursive / yes, kit before with RECURSIVE / true):

Doc Extension Kit before Kit after
users/<uid> deleted deleted deleted
users/<uid>/sub/s1 deleted left behind deleted
things/t-<uid> (uid field, auto-discovery) deleted left behind deleted
control doc kept kept kept

The kit before logged firestoreDeleteMode: "RECURSIVE", enableAutoDiscovery: false and a non-recursive delete.

Unit tests: vitest run passes (16 files, 165 tests), including every option label being accepted and a blank required param plus an invalid value being reported in one error. Prettier passes on the changed files. tsc passes, but only with a temporarily available @types/node: on kits, pnpm build fails with TS2688: Cannot find type definition file for 'node' because @types/node isn't installed, which this change doesn't cause.

Other kits read .env the same way and probably have the same gap.

…t deploy

Values already in .env skip the CLI's prompt-time validation, so the kit deployed with values the extension refuses at install time and then quietly did less, e.g. FIRESTORE_DELETE_MODE=RECURSIVE ran as shallow and ENABLE_AUTO_DISCOVERY=true left auto-discovery off. Check every param's declared select options and validationRegex at module load, so discovery fails with the param, the bad value and the allowed values.

Fixes #3258

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces deploy-time validation for .env configuration parameters in the delete-user-data kit to prevent silent misconfigurations. It adds the assertValidParams function to validate parameter values against allowed options or regex patterns, calls this validation at module scope, updates the documentation and changelog, and includes comprehensive unit tests. The review feedback suggests a minor improvement in config.ts to avoid redundantly wrapping validationRegex in a new RegExp constructor if it is already a RegExp object.

Comment thread kits/delete-user-data/src/config.ts
Comment thread kits/delete-user-data/src/config.ts
Comment thread kits/delete-user-data/src/config.ts Outdated
Comment thread kits/delete-user-data/README.md Outdated
Comment thread kits/delete-user-data/tests/valid-params.test.ts
Comment thread kits/delete-user-data/src/config.ts
The extension only checks for `recursive` and `yes`, so `Shallow` and `No` ran exactly like their values. Only reject the labels it misread: `Recursive`, `Yes` and the location labels.
@CorieW
CorieW marked this pull request as ready for review October 27, 2026 12:53
Comment thread kits/delete-user-data/src/export-config.ts Outdated
Comment thread kits/delete-user-data/src/index.ts Outdated
Reverts the us-central1 default for a blank SELECTED_DATABASE_LOCATION. The extension skips RTDB paths when the location is blank, and the README documents that gate; defaulting it pointed EU instances at the US host.
assertRequiredParams() threw before assertValidParams() ran, so a .env with a blank required param and an invalid value needed two deploys to see both. assertParams() runs both checks and throws once with both messages.
…data-validate-params

# Conflicts:
#	kits/delete-user-data/CHANGELOG.md
#	kits/delete-user-data/tests/index.test.ts
The extension's installer accepted a select param's label as well as its value and ran it as-is, so Recursive deleted shallowly and Yes left auto-discovery off. The kit now accepts every label too and runs it the same way, rather than failing the deploy. The README warns what each label does.
Destructuring the optional label failed to type-check against the union of select option arrays, which broke the kit build.
@CorieW
CorieW merged commit 55b750b into kits Oct 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants