Migrates entra user commands to Zod validation#7372
Merged
MartinM85 merged 4 commits intoJun 17, 2026
Merged
Conversation
Migrates all entra user commands to use Zod schemas for option validation, replacing the old pattern of constructor-based #initTelemetry, #initOptions, #initValidators, #initOptionSets, and #initTypes methods. Commands migrated: - user-add, user-get, user-set, user-list - user-remove, user-guest-add - user-license-add, user-license-list, user-license-remove - user-groupmembership-list, user-signin-list, user-hibp - user-password-validate - user-recyclebinitem-clear, user-recyclebinitem-remove, user-recyclebinitem-restore - user-registrationdetails-list Updates external dependents (group-member-remove, group-set) to work with the new Options type from user-get. Closes pnp#7301 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request migrates the entra user command set from the legacy constructor-based option/validator pattern to Zod schema-based option definition and validation, aligning these commands with the CLI’s newer schema-driven parsing/telemetry/validation flow.
Changes:
- Replaced per-command
#initOptions/#initValidators/#initOptionSets/#initTypeslogic withschema(+getRefinedSchemafor option sets) across theentra usercommands. - Updated tests to use
commandInfo.command.getSchemaToParse()andschema.parse/safeParsepatterns for validation and action invocation. - Adjusted a couple of SPO group commands to work with the new typed options export from
entra user get.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/m365/spo/commands/group/group-set.ts | Adjusts entra user get invocation option typing for schema-derived options. |
| src/m365/spo/commands/group/group-member-remove.ts | Adjusts entra user get invocation option typing for schema-derived options. |
| src/m365/entra/commands/user/user-signin-list.ts | Migrates sign-in list command options/validation to Zod schema + refined constraints. |
| src/m365/entra/commands/user/user-signin-list.spec.ts | Updates tests to validate/execute using the command’s schema parsing. |
| src/m365/entra/commands/user/user-set.ts | Migrates user update command to Zod schema, including refined option-set validation and unknown-option payload support. |
| src/m365/entra/commands/user/user-set.spec.ts | Updates tests to schema-based parsing/validation and adjusts related stubs. |
| src/m365/entra/commands/user/user-remove.ts | Migrates user remove command to Zod schema and refined option-set validation. |
| src/m365/entra/commands/user/user-remove.spec.ts | Updates tests to schema-based parsing and validation checks. |
| src/m365/entra/commands/user/user-registrationdetails-list.ts | Migrates registration details list command to Zod schema-based validation. |
| src/m365/entra/commands/user/user-registrationdetails-list.spec.ts | Updates tests to schema-based parsing and validation checks. |
| src/m365/entra/commands/user/user-recyclebinitem-restore.ts | Migrates recycle bin restore command to Zod schema-based validation. |
| src/m365/entra/commands/user/user-recyclebinitem-restore.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-recyclebinitem-remove.ts | Migrates recycle bin remove command to Zod schema-based validation. |
| src/m365/entra/commands/user/user-recyclebinitem-remove.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-recyclebinitem-clear.ts | Migrates recycle bin clear command to Zod schema-based validation. |
| src/m365/entra/commands/user/user-recyclebinitem-clear.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-password-validate.ts | Migrates password validation command to Zod schema-based option definition. |
| src/m365/entra/commands/user/user-password-validate.spec.ts | Updates tests to schema-based parsing. |
| src/m365/entra/commands/user/user-list.ts | Migrates user list command to Zod schema (loose schema to support unknown filter options) and schema-derived unknown-option detection. |
| src/m365/entra/commands/user/user-list.spec.ts | Updates tests to schema-based parsing, including loose-schema behavior. |
| src/m365/entra/commands/user/user-license-remove.ts | Migrates license remove command to Zod schema and refined option-set validation. |
| src/m365/entra/commands/user/user-license-remove.spec.ts | Updates tests to schema-based parsing/validation and request stubbing. |
| src/m365/entra/commands/user/user-license-list.ts | Migrates license list command to Zod schema and refined mutual-exclusion validation. |
| src/m365/entra/commands/user/user-license-list.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-license-add.ts | Migrates license add command to Zod schema and refined option-set validation. |
| src/m365/entra/commands/user/user-license-add.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-hibp.ts | Migrates HIBP command to Zod schema-based validation. |
| src/m365/entra/commands/user/user-hibp.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-guest-add.ts | Migrates guest invite command to Zod schema-based option definition. |
| src/m365/entra/commands/user/user-guest-add.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-groupmembership-list.ts | Migrates group membership list command to Zod schema and refined option-set validation. |
| src/m365/entra/commands/user/user-groupmembership-list.spec.ts | Updates tests to schema-based parsing/validation. |
| src/m365/entra/commands/user/user-get.ts | Migrates user get command to Zod schema, exports inferred Options type, and refines option-set validation. |
| src/m365/entra/commands/user/user-get.spec.ts | Updates tests to schema-based parsing/validation (with special-casing for @me* placeholders). |
| src/m365/entra/commands/user/user-add.ts | Migrates user add command to Zod schema (loose schema for unknown payload props) and refined option-set validation. |
| src/m365/entra/commands/user/user-add.spec.ts | Updates tests to schema-based parsing/validation. |
MartinM85
requested changes
Jun 12, 2026
MartinM85
left a comment
Contributor
There was a problem hiding this comment.
Hi @waldekmastykarz , I have a couple of small comments, great job otherwise. 👍
Adds commandOptionsSchema.parse() for @meid and @meusername test cases that were incorrectly using raw objects. Co-authored-by: Copilot <[email protected]>
These tokens are special values replaced by loadValuesFromAccessToken at runtime before commandAction runs. They bypass Zod schema validation intentionally, so tests must use 'as any' to simulate the pre-parsed state. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
MartinM85
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates all
entra usercommands to use Zod schemas for option validation, replacing the old constructor-based pattern (#initTelemetry,#initOptions,#initValidators,#initOptionSets,#initTypes).Closes #7301
Commands migrated (17 total)
user-add,user-get,user-set,user-listuser-remove,user-guest-adduser-license-add,user-license-list,user-license-removeuser-groupmembership-list,user-signin-list,user-hibpuser-password-validateuser-recyclebinitem-clear,user-recyclebinitem-remove,user-recyclebinitem-restoreuser-registrationdetails-listChanges
z.strictObject()/z.looseObject()schemasallowUnknownOptions(user-list,user-add,user-set) usez.looseObject()andzod.schemaToOptions(this.schema!)for unknown option detectiongroup-member-remove.ts,group-set.ts) to work with the new typedOptionsexport fromuser-get.tsResults