UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

205 lines 5.52 kB
import { ContentType } from '../cms'; import { ButtonStyle, Carousel, CommonFields, Document, Element, Handoff, Image, Input, StartUp, Text, Video, } from '../contents'; /** * Builder for Contents (which are immutable) which allow: * - Setting the optional fields individually and in any order * - Easing the implementation of the RndXXXBuilder classes at src/cms/test-helpers/builders.ts */ class ContentBuilder { constructor(id, name) { this.id = id; this.name = name; } withId(id) { this.id = id; return this; } withName(name) { this.name = name; return this; } } export class TopContentBuilder extends ContentBuilder { constructor() { super(...arguments); this.keywords = []; } withShortText(shortText) { this.shortText = shortText; return this; } withKeywords(kw) { this.keywords = kw; return this; } buildCommonFields() { return new CommonFields(this.id, this.name, { shortText: this.shortText, keywords: this.keywords, followUp: this.followUp, }); } } class MessageContentBuilder extends TopContentBuilder { withFollowUp(followUp) { this.followUp = followUp; return this; } } export class TextBuilder extends MessageContentBuilder { constructor(id, name, text) { super(id, name); this.text = text; this.buttons = []; this.buttonsStyle = ButtonStyle.BUTTON; } withText(text) { this.text = text; return this; } withButtons(buttons) { this.buttons = buttons; return this; } withButtonStyle(style) { this.buttonsStyle = style; return this; } build() { return new Text(this.buildCommonFields(), this.text, this.buttons, this.buttonsStyle); } } export class ElementBuilder { constructor(id) { this.id = id; this.buttons = []; } withTitle(title) { this.title = title; return this; } withSubtitle(subtitle) { this.subtitle = subtitle; return this; } withImgUrl(imgUrl) { this.imgUrl = imgUrl; return this; } withButtons(buttons) { this.buttons = buttons; return this; } build() { return new Element(this.id, this.buttons, this.title || '', this.subtitle, this.imgUrl); } } export class CarouselBuilder extends MessageContentBuilder { constructor(id, name) { super(id, name); this.elements = []; } withElementBuilder(elementId) { if (!this.elementBuilder) { this.elementBuilder = new ElementBuilder(elementId); } return this.elementBuilder; } addElement() { if (!this.elementBuilder) { throw new Error('You need to previously call withElementBuilder'); } this.elements.push(this.elementBuilder.build()); return this; } build() { return new Carousel(this.buildCommonFields(), this.elements); } } export class StartUpBuilder extends MessageContentBuilder { constructor(id, name, text) { super(id, name); this.text = text; this.buttons = []; } withText(text) { this.text = text; return this; } withButtons(buttons) { this.buttons = buttons; return this; } build() { return new StartUp(this.buildCommonFields(), this.imgUrl, this.text, this.buttons); } } export class MediaBuilder extends MessageContentBuilder { constructor(id, name, mediaUrl) { super(id, name); this.mediaUrl = mediaUrl; } withUrl(url) { this.mediaUrl = url; return this; } build(contentType) { return contentType === ContentType.IMAGE ? new Image(this.buildCommonFields(), this.mediaUrl) : new Video(this.buildCommonFields(), this.mediaUrl); } } export class DocumentBuilder extends MessageContentBuilder { constructor(id, name, docUrl) { super(id, name); this.docUrl = docUrl; } withUrl(url) { this.docUrl = url; return this; } build() { return new Document(this.buildCommonFields(), this.docUrl); } } export class HandoffBuilder extends MessageContentBuilder { constructor(id, name, onFinish) { super(id, name); this.onFinish = onFinish; } withHandoffMessage(message) { this.message = message; return this; } withHandoffFailMessage(failMessage) { this.failMessage = failMessage; return this; } withQueue(queue) { this.queue = queue; return this; } withAgent(agent) { this.agent = agent; return this; } withShadowing(shadowing) { this.shadowing = shadowing; return this; } build() { return new Handoff(this.buildCommonFields(), this.onFinish, this.message, this.failMessage, this.queue, this.agent, this.shadowing); } } export class InputBuilder extends MessageContentBuilder { constructor(id, name, title, keywords, target) { super(id, name); this.title = title; this.keywords = keywords; this.target = target; } build() { return new Input(this.buildCommonFields(), this.title, this.keywords, this.target); } } //# sourceMappingURL=content-factories.js.map