@stackend/api
Version:
JS bindings to api.stackend.com
302 lines (298 loc) • 9.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCompositeBlogKey = exports.saveEntry = exports.setEntryStatus = exports.getEntry = exports.getRecommendedEntries = exports.getMostCommentedEntries = exports.getMostPopularEntries = exports.getMyEntries = exports.getEntries = exports.getBlog = exports.newBlogEntry = exports.getBlogEntryUrl = exports.getFirstSlideshowImageUrl = exports.BlogEntryStatus = exports.BLOG_ENTRY_CLASS = exports.COMPONENT_NAME = exports.COMPONENT_CLASS = exports.DEFAULT_CONTEXT = exports.DEFAULT_BLOG_KEY = void 0;
var api_1 = require("../api");
var tags_1 = require("../tags");
/**
* Xcap Blog api constants and methods.
*
* @since 6 feb 2017
*/
/**
* The default blog key
* @type {string}
*/
exports.DEFAULT_BLOG_KEY = 'news';
/**
* Default context for the blog
* @type {string}
*/
exports.DEFAULT_CONTEXT = 'news';
/**
* Component class (used to look up privileges, etc)
*/
exports.COMPONENT_CLASS = 'net.josh.community.blog.BlogManager';
/**
* Component name
* @type {string}
*/
exports.COMPONENT_NAME = 'blog';
/**
* Blog entry class name
*/
exports.BLOG_ENTRY_CLASS = 'net.josh.community.blog.BlogEntry';
/**
* Statuses of a blog entry
*/
var BlogEntryStatus;
(function (BlogEntryStatus) {
BlogEntryStatus["PUBLISHED"] = "PUBLISHED";
BlogEntryStatus["DRAFT"] = "DRAFT";
BlogEntryStatus["DELETED"] = "DELETED";
})(BlogEntryStatus = exports.BlogEntryStatus || (exports.BlogEntryStatus = {}));
/**
* Get the first image of the slideshow
* @param slideshow
* @returns {*}
*/
function getFirstSlideshowImageUrl(slideshow) {
if (typeof slideshow === undefined || slideshow === null || !slideshow.hasImageSlide) {
return null;
}
// FIXME: May be video
var x = slideshow.slides[0];
if (typeof x === 'string') {
return x;
}
return null;
}
exports.getFirstSlideshowImageUrl = getFirstSlideshowImageUrl;
/**
* returns the url to a specific Blog Entry
*/
function getBlogEntryUrl(_a) {
var request = _a.request, entry = _a.entry;
try {
var blogPermalink = entry.blogRef.groupRef ? entry.blogRef.groupRef.permalink : entry.blogRef.permalink;
return (0, api_1.createCommunityUrl)({
request: request,
path: '/' + blogPermalink + '/posts/' + entry.permalink
});
}
catch (e) {
api_1.logger.error(e, 'Could not find Entry url:' + JSON.stringify(entry));
return '';
}
}
exports.getBlogEntryUrl = getBlogEntryUrl;
/**
* Create a new blogEntry that is ok to save.
* @returns BlogEntry
*/
function newBlogEntry(blogKey) {
//FIXME: a lot of hardcoded stuff, not sure what is necessary
return {
id: 0,
__type: 'net.josh.community.blog.BlogEntry',
title: '',
description: '',
body: '',
publishDate: null,
blogKey: blogKey,
allowComments: true,
categories: [],
headerStyle: {
font: null,
fontSize: null,
fontStyle: null,
overlay: false,
fg: { color: '#000000', opacity: 1 },
bg: { color: '#EAEAEA', opacity: 0.9 },
autoHeaderColor: null,
autoStyle: false,
paletteColors: []
},
slideshow: {
frame: false,
shadow: false,
slides: [],
hasImageSlide: false,
hasVideoSlide: false,
empty: true
},
tags: [],
pageId: 0
};
}
exports.newBlogEntry = newBlogEntry;
/**
* Get a blog given blogId or blogKey
* @param parameters
*/
function getBlog(_a) {
var blogId = _a.blogId, blogKey = _a.blogKey;
return (0, api_1.getJson)({ url: '/blog/get', parameters: arguments });
}
exports.getBlog = getBlog;
/**
* List blog entries.
*
* @param q Search expression (optional)
* @param blogKey List entries from a specific blog (optional, default: all)
* @param blogId List entries from a specific blog (optional, default: all)
* @param creatorUserId List entries by a specific user (optional, default all)
* @param author List entries by a specific user alias (optional, default all)
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @param categoryPermaLink (optional)
* @param categoryId (optional)
* @param goToBlogEntry Start the pagination at the entry permalink (optional)
* @returns {Thunk}
*/
function getEntries(_a) {
var q = _a.q, blogKey = _a.blogKey, blogId = _a.blogId, creatorUserId = _a.creatorUserId, author = _a.author, p = _a.p, pageSize = _a.pageSize, categoryPermaLink = _a.categoryPermaLink, categoryId = _a.categoryId, goToBlogEntry = _a.goToBlogEntry, tags = _a.tags;
return (0, api_1.getJson)({
url: '/blog/entries/list',
parameters: arguments
});
}
exports.getEntries = getEntries;
/**
* List blog entries that the current user has written.
*
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Thunk}
*/
function getMyEntries(_a) {
var p = _a.p, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/blog/entries/my', parameters: arguments });
}
exports.getMyEntries = getMyEntries;
/**
* List the most popular blog entries.
*
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Promise}
*/
function getMostPopularEntries(_a) {
var p = _a.p, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/blog/entries/most-popular', parameters: arguments });
}
exports.getMostPopularEntries = getMostPopularEntries;
/**
* List the blog entries with most comments.
*
* Specify either daysBack or startDate and endDate.
*
* @param daysBack {Number} statistics interval (optional)
* @param startDate {Date} statistics interval (optional)
* @param endDate {Date} statistics interval (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Promise}
*/
function getMostCommentedEntries(_a) {
var _b = _a.daysBack, daysBack = _b === void 0 ? 0 : _b, _c = _a.startDate, startDate = _c === void 0 ? null : _c, _d = _a.endDate, endDate = _d === void 0 ? null : _d, _e = _a.p, p = _e === void 0 ? 1 : _e, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/blog/entries/most-commented', parameters: arguments });
}
exports.getMostCommentedEntries = getMostCommentedEntries;
/**
* List recommended blog entries.
*
* @param p Page number (optional)
* @param pageSize Page size (optional)
* @returns {Promise}
*/
function getRecommendedEntries(_a) {
var p = _a.p, pageSize = _a.pageSize;
return (0, api_1.getJson)({ url: '/blog/entries/recommended', parameters: arguments });
}
exports.getRecommendedEntries = getRecommendedEntries;
/**
* Get a blog entry.
*
* @param id Blog entry id (required)
* @param permalink
*/
function getEntry(_a) {
var id = _a.id, entryPermaLink = _a.entryPermaLink, blogKey = _a.blogKey, blogId = _a.blogId;
return (0, api_1.getJson)({ url: '/blog/entry/get', parameters: arguments });
}
exports.getEntry = getEntry;
/**
* Set the status of the blog entry.
*
* @param id
* @param blogKey
* @param status
* @returns {Promise}
*/
function setEntryStatus(_a) {
var blogKey = _a.blogKey, id = _a.id, status = _a.status;
return (0, api_1.post)({ url: '/blog/entry/set-status', parameters: arguments });
}
exports.setEntryStatus = setEntryStatus;
/**
* Save a blog entry.
* @param blogEntryJson
* @param type
* @param draftId
* @param blogKey
* @returns {Promise}
*/
function saveEntry(_a) {
var blogEntryInput = _a.blogEntryInput, type = _a.type, draftId = _a.draftId, blogKey = _a.blogKey;
return (0, api_1.post)({
url: '/blog/save-blog-entry',
parameters: {
blogEntryJson: JSON.stringify(blogEntryInput),
draftId: draftId,
type: type,
blogKey: blogKey
}
});
}
exports.saveEntry = saveEntry;
/**
* Get a composite blog key that consists of the normal blog key plus eventual tags in the form:
* groups/social/feed/tags/mytag
*
* Use this to fetch from redux whn using tags
*
* @param blogKey
* @param tags
*/
function getCompositeBlogKey(_a) {
var blogKey = _a.blogKey, tags = _a.tags;
var normalizedTags = (0, tags_1.normalizeTags)(tags);
var bk = blogKey;
if (normalizedTags.length) {
bk += '/tags/' + normalizedTags.join('/');
}
return bk;
}
exports.getCompositeBlogKey = getCompositeBlogKey;
/*
type GaTrackPost = {
blogEntry: BlogEntry
};
export function gaPostEventObject({ blogEntry }: GaTrackPost) {
return getEventObject('community_post', blogEntry);
}
export function gaEditPostEventObject({ blogEntry }: GaTrackPost) {
return getEventObject('edit_community_post', blogEntry);
}
export function getEventObject(eventAction: any, blogEntry: any) {
const { eventLabel, eventCategory } = getGALabels({ blogEntry });
return {
event_action: eventAction,
event_label: eventLabel,
event_category: eventCategory
};
}
function getGALabels({ blogEntry }: GaTrackPost) {
const objectType = `BlogEntry`;
const { groupName, groupType, groupTypeEnum } = group.getGAGroupData({ blog: blogEntry.blogRef });
const blogEntryName = !!blogEntry.permalink ? blogEntry.permalink : '';
const readableCategory = gaFunctions.getGaObjectName({
object: blogEntry.__type,
relatedToObject: groupType
});
const eventCategory = `${readableCategory}_(${objectType}_${groupTypeEnum})`;
const eventLabel = `${groupName}_${blogEntryName}_(${blogEntry.blogId}_${blogEntry.id})`;
return { eventLabel, eventCategory };
}
*/
//# sourceMappingURL=index.js.map