Skip to content

Commit

Permalink
Merge pull request #69 from raycharius/v2.1.2
Browse files Browse the repository at this point in the history
🐛 Fix type incompatibility with Slack Node SDK
  • Loading branch information
raycharius authored Sep 20, 2021
2 parents ce0f6d0 + ea70c9e commit bb44764
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-block-builder",
"version": "2.1.1",
"version": "2.1.2",
"description": "Maintainable code for interactive Slack messages, modals, home tabs, and workflow steps. A must-have for the Slack Block Kit framework.",
"author": {
"name": "Ray East",
Expand Down
23 changes: 21 additions & 2 deletions src/lib/slack-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { SurfaceType, BlockType, ElementType } from '../constants';

import type { ObjectLiteral } from '../types';
import type { PlainTextObject } from '../objects';

export enum Param {
actionId = 'action_id',
Expand Down Expand Up @@ -106,14 +107,32 @@ export class SlackMessageDto extends SlackDto {
public readonly attachments?: SlackDto[];
}

export class SlackViewDto extends SlackDto {
export class SlackHomeTabDto extends SlackDto {
public readonly type = SurfaceType.HomeTab;

// @ts-ignore -- Dynamically created class
public readonly blocks: SlackBlockDto[];
}

export class SlackModalDto extends SlackDto {
public readonly type = SurfaceType.Modal;

// @ts-ignore -- Dynamically created class
public readonly type: SurfaceType;
public readonly title: PlainTextObject;

// @ts-ignore -- Dynamically created class
public readonly blocks: SlackBlockDto[];
}

export class SlackWorkflowStepDto extends SlackDto {
public readonly type = SurfaceType.WorkflowStep;

// @ts-ignore -- Dynamically created class
public readonly blocks: SlackBlockDto[];
}

export type SlackViewDto = SlackModalDto | SlackWorkflowStepDto | SlackHomeTabDto;

export class SlackBlockDto extends SlackDto {
// @ts-ignore -- Dynamically created class
public readonly type: BlockType;
Expand Down
2 changes: 1 addition & 1 deletion src/objects/markdown-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CompositionObjectBase } from '../base';
import { ObjectType } from '../constants';

export class MarkdownObject extends CompositionObjectBase {
public type: ObjectType;
public type: ObjectType.Markdown;

public text: string;

Expand Down
2 changes: 1 addition & 1 deletion src/objects/plain-text-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CompositionObjectBase } from '../base';
import { ObjectType } from '../constants';

export class PlainTextObject extends CompositionObjectBase {
public type: ObjectType;
public type: ObjectType.Text;

public text: string;

Expand Down
8 changes: 4 additions & 4 deletions src/surfaces/home-tab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SurfaceBuilderBase } from '../base';
import { SlackViewDto } from '../lib';
import { SlackHomeTabDto } from '../lib';
import {
Blocks,
CallbackId,
Expand Down Expand Up @@ -28,7 +28,7 @@ export interface HomeTabBuilder extends Blocks<ViewBlockBuilder>,
ExternalId,
PrivateMetaData,
BuildToJSON,
BuildToObject<SlackViewDto>,
BuildToObject<SlackHomeTabDto>,
GetBlocks,
GetPreviewUrl,
PrintPreviewUrl {
Expand All @@ -42,8 +42,8 @@ export interface HomeTabBuilder extends Blocks<ViewBlockBuilder>,
export class HomeTabBuilder extends SurfaceBuilderBase {
/** @internal */

public build(): Readonly<SlackViewDto> {
return this.getResult(SlackViewDto, {
public build(): Readonly<SlackHomeTabDto> {
return this.getResult(SlackHomeTabDto, {
type: SurfaceType.HomeTab,
blocks: getBuilderResults<SlackBlockDto>(this.props.blocks),
});
Expand Down
8 changes: 4 additions & 4 deletions src/surfaces/modal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SurfaceBuilderBase } from '../base';
import { SlackViewDto } from '../lib';
import { SlackModalDto } from '../lib';
import {
Blocks,
CallbackId,
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface ModalBuilder extends Blocks<ViewBlockBuilder>,
Submit,
Title,
BuildToJSON,
BuildToObject<SlackViewDto>,
BuildToObject<SlackModalDto>,
GetBlocks,
GetPreviewUrl,
PrintPreviewUrl {
Expand All @@ -56,8 +56,8 @@ export interface ModalBuilder extends Blocks<ViewBlockBuilder>,
export class ModalBuilder extends SurfaceBuilderBase {
/** @internal */

public build(): Readonly<SlackViewDto> {
return this.getResult(SlackViewDto, {
public build(): Readonly<SlackModalDto> {
return this.getResult(SlackModalDto, {
type: SurfaceType.Modal,
title: getPlainTextObject(this.props.title),
blocks: getBuilderResults<SlackBlockDto>(this.props.blocks),
Expand Down
8 changes: 4 additions & 4 deletions src/surfaces/workflow-step.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SurfaceBuilderBase } from '../base';
import { SlackViewDto } from '../lib';
import { SlackWorkflowStepDto } from '../lib';
import {
Blocks,
CallbackId,
Expand Down Expand Up @@ -27,7 +27,7 @@ export interface WorkflowStepBuilder extends Blocks<ViewBlockBuilder>,
PrivateMetaData,
SubmitDisabled,
BuildToJSON,
BuildToObject<SlackViewDto>,
BuildToObject<SlackWorkflowStepDto>,
GetBlocks,
GetPreviewUrl,
PrintPreviewUrl {
Expand All @@ -41,8 +41,8 @@ export interface WorkflowStepBuilder extends Blocks<ViewBlockBuilder>,
export class WorkflowStepBuilder extends SurfaceBuilderBase {
/** @internal */

public build(): Readonly<SlackViewDto> {
return this.getResult(SlackViewDto, {
public build(): Readonly<SlackWorkflowStepDto> {
return this.getResult(SlackWorkflowStepDto, {
type: SurfaceType.WorkflowStep,
title: getPlainTextObject(this.props.title),
blocks: getBuilderResults<SlackBlockDto>(this.props.blocks),
Expand Down
2 changes: 1 addition & 1 deletion tests/surfaces/home-tab.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HomeTabBuilder as Class } from '../../src/surfaces/home-tab';
import { SlackViewDto as DtoClass } from '../../src/lib';
import { SlackHomeTabDto as DtoClass } from '../../src/lib';
import { params } from './mocks/home-tab.mock';
import * as methods from '../methods';
import { testCompositeBuilderClass } from '../test-composite-builder-class';
Expand Down
2 changes: 1 addition & 1 deletion tests/surfaces/modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModalBuilder as Class } from '../../src/surfaces/modal';
import { SlackViewDto as DtoClass } from '../../src/lib';
import { SlackModalDto as DtoClass } from '../../src/lib';
import { params } from './mocks/modal.mock';
import * as methods from '../methods';
import { testCompositeBuilderClass } from '../test-composite-builder-class';
Expand Down
2 changes: 1 addition & 1 deletion tests/surfaces/workflow-step.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WorkflowStepBuilder as Class } from '../../src/surfaces/workflow-step';
import { SlackViewDto as DtoClass } from '../../src/lib';
import { SlackWorkflowStepDto as DtoClass } from '../../src/lib';
import { params } from './mocks/workflow-step.mock';
import * as methods from '../methods';
import { testCompositeBuilderClass } from '../test-composite-builder-class';
Expand Down

0 comments on commit bb44764

Please sign in to comment.