Skip to content

feat(web-api): add blocks.validate method - #2659

Merged
zimeg merged 9 commits into
mainfrom
blocks-validate
Aug 26, 2026
Merged

feat(web-api): add blocks.validate method#2659
zimeg merged 9 commits into
mainfrom
blocks-validate

Conversation

@zimeg

@zimeg zimeg commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Adds the blocks.validate method to @slack/web-api:

await client.blocks.validate({
  blocks: [{ type: 'section', text: { type: 'plain_text', text: 'Hello world' } }],
});

Validate a Block Kit payload against the Block Kit schema by passing exactly one of:

  • blocks — a typed (KnownBlock | Block)[]
  • message — a { blocks, attachments } payload
  • view — a View

blocks.validate is unauthenticated (no token or scopes). This brings Node to parity with the in-flight Python (slackapi/python-slack-sdk#1946) and Java (slackapi/java-slack-sdk#1622) additions.

Typed request arguments

Arguments accept typed Block Kit values (not JSON strings), matching chat.postMessage / views.open. The message shape intentionally omits text — the endpoint rejects it as an additional property (verified against the live API).

Typed errors[] response

On a failed validation the response returns errors[], each with pointer (a JSON pointer to the offending element), code, message, and a constraint. The constraint's expected/got are typed string | number | string[] because their shape is polymorphic across constraint types (a string array for enum, a number for min_length/max_length/max_items, or absent for all_of).

Testing

  • npm run build (tsc) is clean.
  • packages/web-api/test/types/methods/blocks.test-d.ts covers the typed blocks/message/view args and asserts the old JSON-string form is now a type error.

Note: the 6 pre-existing tsd failures in files.test-d.ts / rtm.test-d.ts (deprecated files.upload, rtm.start) are baseline on the branch and untouched by this change.

🤖 Generated with Claude Code

Add a typed blocks.validate method so callers can validate Block Kit
payloads via client.blocks.validate({ blocks }) instead of the untyped
client.apiCall('blocks.validate', ...) escape hatch. blocks, message, and
view arguments are all optional JSON-encoded strings; no scopes required.

The response type is a minimal placeholder covering the fields common to
all Web API responses; the errors[] array on a failed validation is left
to be generated from a real sample (no blocks.validate.json exists in the
upstream java-slack-sdk logs yet).

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a131e99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@slack/web-api Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.15%. Comparing base (4322e14) to head (a131e99).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2659   +/-   ##
=======================================
  Coverage   89.15%   89.15%           
=======================================
  Files          65       65           
  Lines       10383    10393   +10     
  Branches      473      473           
=======================================
+ Hits         9257     9266    +9     
- Misses       1095     1096    +1     
  Partials       31       31           
Flag Coverage Δ
cli-hooks 89.15% <100.00%> (+<0.01%) ⬆️
cli-test 89.15% <100.00%> (+<0.01%) ⬆️
logger 89.15% <100.00%> (+<0.01%) ⬆️
oauth 89.15% <100.00%> (+<0.01%) ⬆️
socket-mode 89.15% <100.00%> (+<0.01%) ⬆️
web-api 89.15% <100.00%> (+<0.01%) ⬆️
webhook 89.15% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Request args accept typed Block Kit values (blocks: (KnownBlock | Block)[],
  message: { blocks, attachments }, view: View) instead of JSON strings,
  matching chat.postMessage / views.open. The message shape omits text, which
  the endpoint rejects as an additional property.
- Response now types the errors[] returned on failed validation: each Error
  has pointer/code/message/constraint, where constraint.expected/got are a
  string|number|string[] union (polymorphic across enum vs length/count
  constraints). Removes the placeholder note that omitted errors[].

Verified: tsc build clean; the blocks.validate tsd type tests pass (the 6
remaining tsd errors are pre-existing in files/rtm test-d, untouched here).

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added enhancement M-T: A feature request for new functionality semver:minor pkg:web-api applies to `@slack/web-api` labels Aug 26, 2026
@zimeg zimeg self-assigned this Aug 26, 2026
@zimeg zimeg added the area:typescript issues that specifically impact using the package from typescript projects label Aug 26, 2026
@zimeg zimeg added this to the web-api@8.x milestone Aug 26, 2026
@zimeg zimeg modified the milestones: web-api@8.x, web-api@next Aug 26, 2026
zimeg and others added 4 commits August 26, 2026 09:16
…e form

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Generated from a blocks.validate sample covering both constraint shapes:
expected is string[] | number and got is number | string (enum vs
length/count constraints).

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
blocks.validate is unauthenticated (no token or scopes), so its arguments
should not offer a token override, matching api.test.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
blocks.validate is unauthenticated, so the type test constructs WebClient()
without a token, matching the example.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg marked this pull request as ready for review August 26, 2026 17:41
@zimeg
zimeg requested a review from a team as a code owner August 26, 2026 17:41
Regenerate BlocksValidateResponse from the recorded blocks.validate sample
via the standard type generator. constraint.expected/got are string[]/string
(the shape captured in the fixture) rather than the previously hand-edited
union, so the file matches what scripts/generate-web-api-types.sh produces.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

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

Nice addition, LGTM. 🚀

@zimeg

zimeg commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

@WilliamBergamin It's a cool method! Thanks for looking this over.

@zimeg
zimeg merged commit f5fd35a into main Aug 26, 2026
12 checks passed
@zimeg
zimeg deleted the blocks-validate branch August 26, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:typescript issues that specifically impact using the package from typescript projects enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants