Skip to content

Migrate SPO user and web commands to Zod - #7555

Draft
waldekmastykarz wants to merge 4 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz-implement-issue-7345
Draft

Migrate SPO user and web commands to Zod#7555
waldekmastykarz wants to merge 4 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz-implement-issue-7345

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Member

Closes #7345

Changes

  • migrate spo user and spo userprofile commands to Zod schemas
  • migrate the targeted spo web commands to Zod schemas
  • preserve aliases, option-set validation, autocomplete, and unknown-property support for spo web set
  • update command tests to validate and parse through refined schemas

Validation

  • npm run build
  • 301 targeted tests passing
  • npm run lint

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d6c8be33-3d2b-441a-8903-6bd91286150e

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 PR migrates the targeted SharePoint Online (spo user, spo userprofile, and selected spo web) commands from the legacy initOptions/initValidators pattern to Zod-based schemas, aligning them with the CLI’s schema-driven parsing/validation pipeline while updating the associated unit tests to validate through the refined schemas.

Changes:

  • Introduces exported Zod options schemas (+ schema getters / getRefinedSchema where needed) across the listed spo user, spo userprofile, and spo web commands.
  • Updates unit tests to validate via commandInfo.command.getSchemaToParse() and to pass parsed options into command.action.
  • Preserves “unknown option passthrough” behavior for spo web set via a loose schema and zod-aware unknown-option payload handling.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/m365/spo/commands/web/web-set.ts Migrates spo web set to a loose Zod schema and zod-based unknown-option passthrough.
src/m365/spo/commands/web/web-set.spec.ts Updates tests to validate/parse via refined schema; keeps unknown-option acceptance coverage.
src/m365/spo/commands/web/web-roleinheritance-reset.ts Migrates spo web roleinheritance reset to strict Zod schema (+ aliases).
src/m365/spo/commands/web/web-roleinheritance-reset.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-roleinheritance-break.ts Migrates spo web roleinheritance break to strict Zod schema (+ aliases).
src/m365/spo/commands/web/web-roleinheritance-break.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-roleassignment-remove.ts Migrates spo web roleassignment remove to strict Zod schema and option-set refinement.
src/m365/spo/commands/web/web-roleassignment-remove.spec.ts Updates tests to validate/parse via refined schema; strengthens “request was called” assertions.
src/m365/spo/commands/web/web-roleassignment-add.ts Migrates spo web roleassignment add to strict Zod schema with two option-set refinements.
src/m365/spo/commands/web/web-roleassignment-add.spec.ts Updates tests to validate/parse via refined schema; strengthens “request was called” assertions.
src/m365/spo/commands/web/web-retentionlabel-list.ts Migrates spo web retentionlabel list to strict Zod schema (+ alias).
src/m365/spo/commands/web/web-retentionlabel-list.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-remove.ts Migrates spo web remove to strict Zod schema (+ aliases).
src/m365/spo/commands/web/web-remove.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-reindex.ts Migrates spo web reindex to strict Zod schema (+ alias).
src/m365/spo/commands/web/web-reindex.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-list.ts Migrates spo web list to strict Zod schema (+ alias).
src/m365/spo/commands/web/web-list.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-installedlanguage-list.ts Migrates spo web installedlanguage list to strict Zod schema (+ alias).
src/m365/spo/commands/web/web-installedlanguage-list.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-get.ts Migrates spo web get to strict Zod schema for URL + boolean flags.
src/m365/spo/commands/web/web-get.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-clientsidewebpart-list.ts Migrates spo web clientsidewebpart list to strict Zod schema (+ alias).
src/m365/spo/commands/web/web-clientsidewebpart-list.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/web/web-add.ts Migrates spo web add to strict Zod schema (+ aliases) and aligns verbose message with schema option naming.
src/m365/spo/commands/web/web-add.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/userprofile/userprofile-set.ts Migrates spo userprofile set to strict Zod schema (+ aliases).
src/m365/spo/commands/userprofile/userprofile-set.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/userprofile/userprofile-get.ts Migrates spo userprofile get to strict Zod schema with UPN validation.
src/m365/spo/commands/userprofile/userprofile-get.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/user/user-remove.ts Migrates spo user remove to strict Zod schema + refined option-set validation.
src/m365/spo/commands/user/user-remove.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/user/user-list.ts Migrates spo user list to strict Zod schema (+ alias).
src/m365/spo/commands/user/user-list.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/user/user-get.ts Migrates spo user get to strict Zod schema + refined “at most one selector” validation.
src/m365/spo/commands/user/user-get.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.
src/m365/spo/commands/user/user-ensure.ts Migrates spo user ensure to strict Zod schema + refined “exactly one selector” validation.
src/m365/spo/commands/user/user-ensure.spec.ts Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/m365/spo/commands/web/web-roleassignment-add.ts
Comment thread src/m365/spo/commands/web/web-roleassignment-remove.ts
Comment thread src/m365/spo/commands/user/user-get.ts Outdated
Comment thread src/m365/spo/commands/user/user-remove.ts Outdated
Comment thread src/m365/spo/commands/web/web-roleassignment-remove.spec.ts
Comment thread src/m365/spo/commands/web/web-roleassignment-add.spec.ts
waldekmastykarz and others added 2 commits August 31, 2026 08:40
- Add principalId handling in web-roleassignment-add commandAction
- Add principalId handling in web-roleassignment-remove removeRoleAssignment
- Constrain id to positive integer in user-get and user-remove schemas
- Assert request.post stub called in roleassignment add/remove tests

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@MartinM85

Copy link
Copy Markdown
Contributor

Hi @waldekmastykarz, could you please resolve the conflicts? Thanks

- Accept upstream npm-shrinkwrap.json and regenerate
- Keep Zod migration changes in user-get.ts, add new id validation tests in Zod style
- Accept deletion of fsUtil.spec.ts (moved elsewhere in main)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@MartinM85 MartinM85 self-assigned this Sep 11, 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, great work 🚀.
I have a couple of small comments, nothing major.

export const options = z.strictObject({
...globalOptionsZod.shape,
webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, {
error: e => validation.isValidSharePointUrl(e.input as string).toString()

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.

I see an inconsistency here. For some commands, you return ${e.input} is not a valid SharePoint Online site URL., while other commands return validation.isValidSharePointUrl(e.input as string).toString().
I would prefer returning ${e.input} is not a valid SharePoint Online site URL. to avoid calling validation.isValidSharePointUrl twice.

export const options = z.strictObject({
...globalOptionsZod.shape,
webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, {
error: e => validation.isValidSharePointUrl(e.input as string).toString()

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.

Same as above

export const options = z.strictObject({
...globalOptionsZod.shape,
webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, {
error: e => validation.isValidSharePointUrl(e.input as string).toString()

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.

Same here

export const options = z.strictObject({
...globalOptionsZod.shape,
webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, {
error: e => validation.isValidSharePointUrl(e.input as string).toString()

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.

Same here

@MartinM85
MartinM85 marked this pull request as draft September 11, 2026 14:27
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.

Migrate spo user, spo userprofile, and spo web commands to Zod

3 participants