Skip to content
Open
5 changes: 5 additions & 0 deletions .changeset/web-api-blocks-validate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/web-api": minor
---

feat(web-api): add [`blocks.validate`](https://docs.slack.dev/reference/methods/blocks.validate) method
10 changes: 10 additions & 0 deletions packages/web-api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import type {
AuthRevokeArguments,
AuthTeamsListArguments,
AuthTestArguments,
BlocksValidateArguments,
BookmarksAddArguments,
BookmarksEditArguments,
BookmarksListArguments,
Expand Down Expand Up @@ -388,6 +389,7 @@ import type {
AuthRevokeResponse,
AuthTeamsListResponse,
AuthTestResponse,
BlocksValidateResponse,
BookmarksAddResponse,
BookmarksEditResponse,
BookmarksListResponse,
Expand Down Expand Up @@ -1546,6 +1548,14 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
remove: bindApiCall<BookmarksRemoveArguments, BookmarksRemoveResponse>(this, 'bookmarks.remove'),
};

public readonly blocks = {
/**
* @description Validates blocks, messages, and views Block Kit JSON payloads.
* @see {@link https://docs.slack.dev/reference/methods/blocks.validate `blocks.validate` API reference}.
*/
validate: bindApiCallWithOptionalArgument<BlocksValidateArguments, BlocksValidateResponse>(this, 'blocks.validate'),
};

public readonly bots = {
/**
* @description Gets information about a bot user.
Expand Down
16 changes: 16 additions & 0 deletions packages/web-api/src/types/request/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Block, KnownBlock, MessageAttachment, View } from '@slack/types';

import type { OptionalArgument } from '../helpers';

// https://docs.slack.dev/reference/methods/blocks.validate
export type BlocksValidateArguments = OptionalArgument<{
/** @description An array of blocks to validate. */
blocks?: (KnownBlock | Block)[];
/** @description A message payload to validate. */
message?: {
blocks?: (KnownBlock | Block)[];
attachments?: MessageAttachment[];
};
/** @description A view payload to validate. */
view?: View;
}>;
1 change: 1 addition & 0 deletions packages/web-api/src/types/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export type {
AuthTeamsListArguments,
AuthTestArguments,
} from './auth';
export type { BlocksValidateArguments } from './blocks';
export type {
BookmarksAddArguments,
BookmarksEditArguments,
Expand Down
37 changes: 37 additions & 0 deletions packages/web-api/src/types/response/BlocksValidateResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import type { WebAPICallResult } from '../../WebClient';

export type BlocksValidateResponse = WebAPICallResult & {
error?: string;
errors?: Error[];
needed?: string;
ok?: boolean;
provided?: string;
response_metadata?: ResponseMetadata;
warning?: string;
};

export interface Error {
code?: string;
constraint?: Constraint;
message?: string;
pointer?: string;
}

export interface Constraint {
expected?: string[];
got?: string;
type?: string;
}

export interface ResponseMetadata {
messages?: string[];
}
1 change: 1 addition & 0 deletions packages/web-api/src/types/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export { AssistantThreadsSetTitleResponse } from './AssistantThreadsSetTitleResp
export { AuthRevokeResponse } from './AuthRevokeResponse';
export { AuthTeamsListResponse } from './AuthTeamsListResponse';
export { AuthTestResponse } from './AuthTestResponse';
export { BlocksValidateResponse } from './BlocksValidateResponse';
export { BookmarksAddResponse } from './BookmarksAddResponse';
export { BookmarksEditResponse } from './BookmarksEditResponse';
export { BookmarksListResponse } from './BookmarksListResponse';
Expand Down
20 changes: 20 additions & 0 deletions packages/web-api/test/types/methods/blocks.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expectAssignable, expectError } from 'tsd';
import { WebClient } from '../../../src/WebClient';

const web = new WebClient();

// blocks.validate
// -- happy path
expectAssignable<Parameters<typeof web.blocks.validate>>([{}]); // all optional args
expectAssignable<Parameters<typeof web.blocks.validate>>([]); // no arg is fine
expectAssignable<Parameters<typeof web.blocks.validate>>([
{ blocks: [{ type: 'section', text: { type: 'plain_text', text: 'Hello world' } }] },
]);
expectAssignable<Parameters<typeof web.blocks.validate>>([
{ message: { blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }] } },
]);
expectAssignable<Parameters<typeof web.blocks.validate>>([
{ view: { type: 'modal', title: { type: 'plain_text', text: 'Title' }, blocks: [] } },
]);
// -- sad path
expectError<Parameters<typeof web.blocks.validate>>([{ blocks: '[]' }]); // must be typed blocks, not a string