@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
217 lines • 6.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputBuilder = exports.HandoffBuilder = exports.DocumentBuilder = exports.MediaBuilder = exports.StartUpBuilder = exports.CarouselBuilder = exports.ElementBuilder = exports.TextBuilder = exports.TopContentBuilder = void 0;
const cms_1 = require("../cms");
const contents_1 = require("../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;
}
}
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 contents_1.CommonFields(this.id, this.name, {
shortText: this.shortText,
keywords: this.keywords,
followUp: this.followUp,
});
}
}
exports.TopContentBuilder = TopContentBuilder;
class MessageContentBuilder extends TopContentBuilder {
withFollowUp(followUp) {
this.followUp = followUp;
return this;
}
}
class TextBuilder extends MessageContentBuilder {
constructor(id, name, text) {
super(id, name);
this.text = text;
this.buttons = [];
this.buttonsStyle = contents_1.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 contents_1.Text(this.buildCommonFields(), this.text, this.buttons, this.buttonsStyle);
}
}
exports.TextBuilder = TextBuilder;
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 contents_1.Element(this.id, this.buttons, this.title || '', this.subtitle, this.imgUrl);
}
}
exports.ElementBuilder = ElementBuilder;
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 contents_1.Carousel(this.buildCommonFields(), this.elements);
}
}
exports.CarouselBuilder = CarouselBuilder;
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 contents_1.StartUp(this.buildCommonFields(), this.imgUrl, this.text, this.buttons);
}
}
exports.StartUpBuilder = StartUpBuilder;
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 === cms_1.ContentType.IMAGE
? new contents_1.Image(this.buildCommonFields(), this.mediaUrl)
: new contents_1.Video(this.buildCommonFields(), this.mediaUrl);
}
}
exports.MediaBuilder = MediaBuilder;
class DocumentBuilder extends MessageContentBuilder {
constructor(id, name, docUrl) {
super(id, name);
this.docUrl = docUrl;
}
withUrl(url) {
this.docUrl = url;
return this;
}
build() {
return new contents_1.Document(this.buildCommonFields(), this.docUrl);
}
}
exports.DocumentBuilder = DocumentBuilder;
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 contents_1.Handoff(this.buildCommonFields(), this.onFinish, this.message, this.failMessage, this.queue, this.agent, this.shadowing);
}
}
exports.HandoffBuilder = HandoffBuilder;
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 contents_1.Input(this.buildCommonFields(), this.title, this.keywords, this.target);
}
}
exports.InputBuilder = InputBuilder;
//# sourceMappingURL=content-factories.js.map