@viewdo/dxp-story-cli
Version:
DXP Story Management CLI
344 lines • 16.2 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StoryConfiguration = void 0;
const class_transformer_1 = require("class-transformer");
const path = __importStar(require("path"));
const JSONAssetConverter_1 = require("../../services/JSONAssetConverter");
const AssetDefinition_1 = require("../AssetDefinition");
const EpisodeConfiguration_1 = require("./EpisodeConfiguration");
const EmailTemplate_1 = require("./support/EmailTemplate");
const TemplateMeta_1 = require("./support/TemplateMeta");
const Input_1 = require("./support/Input");
const StoryAction_1 = require("./support/StoryAction");
const StoryCustomKpi_1 = require("./support/StoryCustomKpi");
const StoryCustomLink_1 = require("./support/StoryCustomLink");
const StoryEvent_1 = require("./support/StoryEvent");
const StoryExternalEvent_1 = require("./support/StoryExternalEvent");
const StoryInputMap_1 = require("./support/StoryInputMap");
/**
* STORY CONFIG:
* -----------------------------------------------------
* This file defines configurable story settings hosted in the DXP platform.
*/
let StoryConfiguration = class StoryConfiguration {
constructor() {
/**
* DXP model-type (read-only)
*/
this.kind = "Story";
/**
* API version, model location (read-only)
*/
this.apiVersion = "api.view.do/v1";
/**
* The host-type this story is meant for.
* Hosted for NENT-based stories served from the platform, otherwise
* Website for stories served from a website.
*/
this.host = "Hosted";
/**
* A list of story milestones, in order.
* @items.pattern ^[A-Za-z0-9-_\s]{1,30}$
*/
this.milestones = [];
/**
* A list of story inputs, used to define the story database.
*/
this.inputs = [];
/**
* A list of story events that can be raised during the experience.
*/
this.events = [];
/**
* A list of external events that can be raised using our published web-hooks.
*/
this.externalEvents = [];
/**
* A list of alternative story data, css and js sets that have the same data inputs and contacts.
*/
this.episodes = [];
/**
* A list of story custom links to distribute trackable redirection URLs.
*/
this.customLinks = [];
/**
* A list of story KPIs counters that can be incremented with published web-hooks.
*/
this.customKpis = [];
/**
* Root directory where email templates are stored in Stripo.
*/
this.stripoRootDirectory = '{{org-key}}/production';
/**
* A list of story email templates, usable in Actions
*/
this.emailTemplates = [];
/**
* A list of story HTML templates that will be hosted and rendered using DXP tokens.
*/
this.htmlTemplates = [];
/**
* A list of story text templates usable in Actions or in the story as a URL reference.
*/
this.textTemplates = [];
/** A set of maps usable in actions or in the XAPI to translate input keys to external keys. */
this.inputMaps = [];
/**
* A list of configured actions that are triggered via events fired during the lifetime of an experience.
*
* These actions use services configured with the organization-configuration.
*/
this.actions = [];
/** @ignore */
this.workflow = [];
}
/** @ignore */
get api_root() {
return `/stories/${this.from_key || this.key}`;
}
/** @ignore */
get local_root() {
return this._local_root || `./stories/${this.key}`;
}
set local_root(local_root) {
this._local_root = local_root;
}
/** @ignore */
get assets_directory() {
return `${this.local_root}/assets`;
}
/** @ignore */
get cdn_root() {
return `${this.organizationKey}/${this.key}`;
}
getAssets(from_key, local_root) {
var _a, _b, _c, _d;
this.from_key = from_key;
if (local_root)
this.local_root = local_root;
const tokenValidationPath = `/tokens/story/${this.key}/validate`;
let assets = [
new AssetDefinition_1.AssetDefinition("html_file", "Html File", `${this.local_root}/default.output.html`, `${this.api_root}/html-file`, this.cdn_root, `/stories/${this.key}/html-file/validate`, null, `${this.local_root}/default.html`),
new AssetDefinition_1.AssetDefinition("intro_html_file", "Intro Html File", `${this.local_root}/story-intro.html`, `${this.api_root}/intro-html-file`, this.cdn_root, tokenValidationPath),
new AssetDefinition_1.AssetDefinition("json_file", "Default Data File", `${this.local_root}/default-data.yml`, `${this.api_root}/json-file`, this.cdn_root, `/stories/${this.key}/json-file/validate`, new JSONAssetConverter_1.JSONAssetConverter(this.cdn_root, this.local_root, `default-data`)),
new AssetDefinition_1.AssetDefinition("js_file", "Story Script File", `${this.local_root}/default.output.js`, `${this.api_root}/js-file`, this.cdn_root, null, null, `${this.local_root}/default.js`),
new AssetDefinition_1.AssetDefinition("css_file", "Story Styles File", `${this.local_root}/default.output.css`, `${this.api_root}/css-file`, this.cdn_root, tokenValidationPath, null, `${this.local_root}/default.scss`),
];
(_a = this.episodes) === null || _a === void 0 ? void 0 : _a.forEach((e, i) => {
assets.push(new AssetDefinition_1.AssetDefinition(this._getEpisodeAssetKey(i, "html_file"), `Episode ${e.name} HTML File`, `${this.local_root}/episode-${e.key}.output.html`, `${this.api_root}/episodes/${e.key}/html-file`, this.cdn_root, `/stories/${this.key}/html-file/validate`, null, `${this.local_root}/episode-${e.key}.html`));
assets.push(new AssetDefinition_1.AssetDefinition(this._getEpisodeAssetKey(i, "css_file"), `Episode ${e.name} Styles File`, `${this.local_root}/episode-${e.key}.output.css`, `${this.api_root}/episodes/${e.key}/css-file`, this.cdn_root, tokenValidationPath, null, `${this.local_root}/episode-${e.key}.scss`));
assets.push(new AssetDefinition_1.AssetDefinition(this._getEpisodeAssetKey(i, "json_file"), `Episode ${e.name} Data File`, `${this.local_root}/episode-${e.key}-data.yml`, `${this.api_root}/episodes/${e.key}/json-file`, this.cdn_root, `/stories/${this.key}/json-file/validate`, new JSONAssetConverter_1.JSONAssetConverter(this.cdn_root, this.local_root, `episode-${e.key}-data`)));
assets.push(new AssetDefinition_1.AssetDefinition(this._getEpisodeAssetKey(i, "js_file"), `Episode ${e.name} Script File`, `${this.local_root}/episode-${e.key}.output.js`, `${this.api_root}/episodes/${e.key}/js-file`, this.cdn_root, null, null, `${this.local_root}/episode-${e.key}.js`));
});
(_b = this.htmlTemplates) === null || _b === void 0 ? void 0 : _b.forEach((t) => {
assets.push(new AssetDefinition_1.AssetDefinition(`html_templates.${t.key}`, t.name, `${this.local_root}/` + path.join('html-templates', t.path, t.file), `${this.api_root}/html-templates/${t.key}/file`, this.cdn_root, tokenValidationPath));
});
(_c = this.emailTemplates) === null || _c === void 0 ? void 0 : _c.forEach((t) => {
assets.push(new AssetDefinition_1.AssetDefinition(`email_templates.${t.key}`, `${t.name}`, `${this.local_root}/` + path.join('email-templates', t.path, t.file), `${this.api_root}/email-templates/${t.key}/file`, this.cdn_root, tokenValidationPath));
});
(_d = this.textTemplates) === null || _d === void 0 ? void 0 : _d.forEach((t) => {
assets.push(new AssetDefinition_1.AssetDefinition(`text_templates.${t.key}`, `${t.name}`, `${this.local_root}/` + path.join('text-templates', t.path, t.file), `${this.api_root}/text-templates/${t.key}/file`, this.cdn_root, tokenValidationPath));
});
return assets;
}
getExportPath() {
return `${this.local_root}/story-export.json`;
}
getTemplateKey(dir, file) {
return `${dir ? dir.replace('/', '--') + '--' : ''}${path.basename(file, path.extname(file))}`;
}
getTemplateName(input) {
return input
.replace(/\$/g, ' ') // Replace all $ with spaces
.split(' ') // Split the string into words
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter of each word
.join(' '); // Join the words with spaces
}
_getEpisodeAssetKey(index, asset_key) {
return `episodes[${index}].${asset_key}`;
}
getAssetDefinition(key) {
return this.getAssets().find((a) => a.key == key);
}
convertFromModel(story) {
Object.assign(this, story);
this.actions = story.workflow;
return this;
}
/** @ignore */
get episode_keys() {
if (this.episodes)
return ["default", ...this.episodes.map((e) => e.key)];
return ["default"];
}
};
exports.StoryConfiguration = StoryConfiguration;
StoryConfiguration.file_name = "story-config.yml";
__decorate([
(0, class_transformer_1.Expose)({
toPlainOnly: true,
}),
__metadata("design:type", String)
], StoryConfiguration.prototype, "kind", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toPlainOnly: true,
}),
__metadata("design:type", String)
], StoryConfiguration.prototype, "apiVersion", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "key", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "publicKey", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "name", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "description", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "organizationKey", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", String)
], StoryConfiguration.prototype, "host", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toClassOnly: true,
}),
__metadata("design:type", String)
], StoryConfiguration.prototype, "url", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toClassOnly: true,
}),
__metadata("design:type", String)
], StoryConfiguration.prototype, "vanityUrl", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", Boolean)
], StoryConfiguration.prototype, "preventDuplicates", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "milestones", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => Input_1.Input),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "inputs", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryEvent_1.StoryEvent),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "events", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryExternalEvent_1.StoryExternalEvent),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "externalEvents", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => EpisodeConfiguration_1.EpisodeConfiguration),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "episodes", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryCustomLink_1.StoryCustomLink),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "customLinks", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryCustomKpi_1.StoryCustomKpi),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "customKpis", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
__metadata("design:type", Boolean)
], StoryConfiguration.prototype, "funnelEnabled", void 0);
__decorate([
(0, class_transformer_1.Expose)({ toClassOnly: true }),
__metadata("design:type", String)
], StoryConfiguration.prototype, "stripoRootDirectory", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toClassOnly: true
}),
(0, class_transformer_1.Type)(() => EmailTemplate_1.EmailTemplate),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "emailTemplates", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toClassOnly: true
}),
(0, class_transformer_1.Type)(() => TemplateMeta_1.TemplateMeta),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "htmlTemplates", void 0);
__decorate([
(0, class_transformer_1.Expose)({
toClassOnly: true
}),
(0, class_transformer_1.Type)(() => TemplateMeta_1.TemplateMeta),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "textTemplates", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryInputMap_1.StoryInputMap),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "inputMaps", void 0);
__decorate([
(0, class_transformer_1.Expose)(),
(0, class_transformer_1.Type)(() => StoryAction_1.StoryAction),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "actions", void 0);
__decorate([
(0, class_transformer_1.Exclude)({
toPlainOnly: true,
}),
(0, class_transformer_1.Type)(() => StoryAction_1.StoryAction),
__metadata("design:type", Array)
], StoryConfiguration.prototype, "workflow", void 0);
exports.StoryConfiguration = StoryConfiguration = __decorate([
(0, class_transformer_1.Exclude)()
], StoryConfiguration);
//# sourceMappingURL=StoryConfiguration.js.map