@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
137 lines • 5.93 kB
JavaScript
import { __awaiter } from "tslib";
import { SearchCandidate } from '../search/search-result';
import * as time from '../time';
import { DEFAULT_REFERENCES_TO_INCLUDE, } from './cms';
import { Asset, Button, Carousel, CommonFields, Custom, DateRangeContent, Document, Element, Handoff, Image, Input, Payload, Queue, ScheduleContent, StartUp, Text, Url, Video, } from './contents';
import { DEFAULT_CONTEXT } from './context';
/**
* Useful for mocking CMS, as ts-mockito does not allow mocking interfaces
*/
export class DummyCMS {
/**
*
* @param buttonCallbacks models which contain buttons will return one per each specified callback
*/
constructor(buttonCallbacks) {
this.buttonCallbacks = buttonCallbacks;
}
button(_id, _context) {
throw new Error('Method not implemented.');
}
element(_id, _context) {
throw new Error('Method not implemented.');
}
carousel(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
const elements = this.buttonCallbacks.map((callback, i) => this.createElement(String(i), callback));
return Promise.resolve(new Carousel(new CommonFields(id, id), elements));
});
}
document(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(new Document(new CommonFields(id, id), DummyCMS.PDF));
});
}
text(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(new Text(new CommonFields(id, id, { keywords: ['kw1', 'kw2'], shortText: id }), 'Dummy text for ' + id, this.buttons()));
});
}
handoff(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
const queue = new Queue(new CommonFields(id, id), id);
const message = new Text(new CommonFields(id, id), id, []);
const failMessage = new Text(new CommonFields(id, id), id, []);
return Promise.resolve(new Handoff(new CommonFields(id, id), this.buttonCallbacks[0], message, failMessage, queue));
});
}
input(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(new Input(new CommonFields(id, id), 'Dummy message', [], this.buttonCallbacks[0]));
});
}
custom(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(new Custom(id, id, {}));
});
}
chitchat(id, context = DEFAULT_CONTEXT) {
return this.text(id, context);
}
startUp(id, {} = DEFAULT_CONTEXT) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(new StartUp(new CommonFields(id, id), DummyCMS.IMG, 'Dummy text for ' + id, this.buttons()));
});
}
static buttonFromCallback(callback) {
const id = callback.payload || callback.url;
return new Button(id, id, 'button text for ' + id, callback);
}
createElement(id, callback) {
return new Element(id, [DummyCMS.buttonFromCallback(callback)], 'Title for ' + id, 'subtitle', DummyCMS.IMG);
}
url(id, {} = DEFAULT_CONTEXT) {
return Promise.resolve(new Url(new CommonFields(id, id, { shortText: 'button text for' + id }), `http://url.${id}`));
}
payload(id, {} = DEFAULT_CONTEXT) {
return Promise.resolve(new Payload(new CommonFields(id, id), 'Dummy payload for ' + id));
}
image(id, {} = DEFAULT_CONTEXT) {
return Promise.resolve(new Image(new CommonFields(id, id), DummyCMS.IMG));
}
video(id, {} = DEFAULT_CONTEXT) {
return Promise.resolve(new Video(new CommonFields(id, id), DummyCMS.VIDEO));
}
queue(id, {} = DEFAULT_CONTEXT) {
return Promise.resolve(new Queue(new CommonFields(id, id), id));
}
topContents(_model, _context, _filter, _paging) {
return Promise.resolve([]);
}
contentsWithKeywords({} = DEFAULT_CONTEXT, _paging) {
const contents = this.buttonCallbacks.map((cb, id) => {
const button = DummyCMS.buttonFromCallback(cb);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new SearchCandidate(cb.asContentId(), new CommonFields(String(id), button.name, {
shortText: button.text,
keywords: [
'keyword for ' + (button.callback.payload || button.callback.url),
],
}));
});
return Promise.resolve(contents);
}
schedule(id, _context) {
const schedule = new time.Schedule('Europe/Madrid');
return Promise.resolve(new ScheduleContent(new CommonFields(id, 'name'), schedule));
}
asset(id, _context) {
return Promise.resolve(new Asset(id, `http://url.${id}`, {
name: `${id} title`,
fileName: `${id} fileName`,
description: `${id} description`,
type: `${id} type`,
}));
}
dateRange(id, _context) {
const now = new Date();
const dateRange = new time.DateRange('daterange name', now, now);
return Promise.resolve(new DateRangeContent(new CommonFields(id, dateRange.name), dateRange));
}
buttons() {
return this.buttonCallbacks.map(DummyCMS.buttonFromCallback);
}
content(id, context = DEFAULT_CONTEXT, _referencesToInclude = DEFAULT_REFERENCES_TO_INCLUDE) {
return this.text(id, context);
}
contents(_contentType, _context, _paging) {
return Promise.resolve([]);
}
assets(_context) {
return Promise.resolve([]);
}
}
DummyCMS.IMG = 'this_image_does_not_exist.png';
DummyCMS.VIDEO = 'this_video_does_not_exist.mp4';
DummyCMS.PDF = 'this_doc_does_not_exist.pdf';
//# sourceMappingURL=cms-dummy.js.map