Skip to content

Migrates entra user commands to Zod validation#7372

Merged
MartinM85 merged 4 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-entra-user-to-zod
Jun 17, 2026
Merged

Migrates entra user commands to Zod validation#7372
MartinM85 merged 4 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-entra-user-to-zod

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Member

Summary

Migrates all entra user commands 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-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

Changes

  • Replaced constructor-based option registration with z.strictObject() / z.looseObject() schemas
  • Commands with allowUnknownOptions (user-list, user-add, user-set) use z.looseObject() and zod.schemaToOptions(this.schema!) for unknown option detection
  • Updated 2 external dependents (group-member-remove.ts, group-set.ts) to work with the new typed Options export from user-get.ts
  • Updated all corresponding test files to use Zod parsing pattern

Results

  • ✅ Build passes
  • ✅ All 15,723 tests pass
  • ✅ 100% function coverage
  • Net -891 lines (1,026 added, 1,917 removed)

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]>

Copilot AI 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.

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/#initTypes logic with schema (+ getRefinedSchema for option sets) across the entra user commands.
  • Updated tests to use commandInfo.command.getSchemaToParse() and schema.parse/safeParse patterns 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.

Comment thread src/m365/spo/commands/group/group-set.ts
Comment thread src/m365/spo/commands/group/group-member-remove.ts
Comment thread src/m365/entra/commands/user/user-license-add.ts
@MartinM85 MartinM85 marked this pull request as draft June 3, 2026 05:40
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 5, 2026 11:17
@MartinM85 MartinM85 self-assigned this Jun 10, 2026

@MartinM85 MartinM85 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.

Hi @waldekmastykarz , I have a couple of small comments, great job otherwise. 👍

Comment thread src/m365/entra/commands/user/user-get.spec.ts
Comment thread src/m365/entra/commands/user/user-get.spec.ts
@MartinM85 MartinM85 marked this pull request as draft June 12, 2026 13:08
Adds commandOptionsSchema.parse() for @meid and @meusername
test cases that were incorrectly using raw objects.

Co-authored-by: Copilot <[email protected]>
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 17, 2026 11:17
waldekmastykarz and others added 2 commits June 17, 2026 13:25
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]>
@MartinM85 MartinM85 merged commit 2188c6b into pnp:main Jun 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate entra user commands to Zod

3 participants