@stackend/api
Version:
JS bindings to api.stackend.com
430 lines • 14.1 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeGroup = exports.setGroupStyle = exports.setGroupBackgroundImage = exports.setGroupLogotypeImage = exports.checkGroupPermalink = exports.editGroup = exports.listMembers = exports.listMembershipRequests = exports.editMembership = exports.applyForMembership = exports.unsubscribe = exports.subscribe = exports.getGroup = exports.listGroupsByTag = exports.search = exports.listMyGroups = exports.getGroupType = exports.getCss = exports.getGroupSettingsUrl = exports.getGroupUrl = exports.getBlogPostUrl = exports.getBlogUrl = exports.getUrl = exports.MemberShipRequestType = exports.GroupMemberSortOrder = exports.SortBy = exports.COMPONENT_NAME = exports.COMPONENT_CLASS = exports.VisibilityId = exports.Visibility = exports.GROUP_TYPES_BY_ID = exports.GroupType = void 0;
var api_1 = require("../api");
var GroupType;
(function (GroupType) {
GroupType["OPEN"] = "OPEN";
GroupType["CLOSED"] = "CLOSED";
GroupType["BLOG"] = "BLOG";
GroupType["DISCUSSION"] = "DISCUSSION";
})(GroupType = exports.GroupType || (exports.GroupType = {}));
exports.GROUP_TYPES_BY_ID = {
'1': GroupType.CLOSED,
'2': GroupType.OPEN,
'3': GroupType.DISCUSSION,
'4': GroupType.BLOG
};
var Visibility;
(function (Visibility) {
Visibility["VISIBLE"] = "VISIBLE";
Visibility["HIDDEN"] = "HIDDEN";
})(Visibility = exports.Visibility || (exports.Visibility = {}));
exports.VisibilityId = (_a = {},
_a[Visibility.VISIBLE] = 1,
_a[Visibility.HIDDEN] = 2,
_a);
/**
* Component class (used to look up privileges, etc)
*/
exports.COMPONENT_CLASS = 'net.josh.community.group.GroupManager';
/**
* Component name
* @type {string}
*/
exports.COMPONENT_NAME = 'group';
/**
* Sort by for groups
*/
var SortBy;
(function (SortBy) {
/**
* Sort by number of members
*/
SortBy[SortBy["SIZE"] = 1] = "SIZE";
/**
* Sort alphabetically
*/
SortBy[SortBy["ALPHABETICAL"] = 2] = "ALPHABETICAL";
/**
* Sort by last activity date
*/
SortBy[SortBy["LAST_ACTIVITY_DATE"] = 3] = "LAST_ACTIVITY_DATE";
/**
* Sort by creation date.
*/
SortBy[SortBy["CREATION_DATE"] = 4] = "CREATION_DATE";
})(SortBy = exports.SortBy || (exports.SortBy = {}));
/**
* Sort order used when listing group members
*/
var GroupMemberSortOrder;
(function (GroupMemberSortOrder) {
GroupMemberSortOrder["JOIN_DATE_ASC"] = "JOIN_DATE_ASC";
GroupMemberSortOrder["JOIN_DATE_DESC"] = "JOIN_DATE_DESC";
})(GroupMemberSortOrder = exports.GroupMemberSortOrder || (exports.GroupMemberSortOrder = {}));
/**
* Membership actions
*/
var MemberShipRequestType;
(function (MemberShipRequestType) {
/**
* Add a member or approve a pending membership application (available to group admin only)
*/
MemberShipRequestType["ADD"] = "ADD";
/**
* Remove a member or pending membership application (available to group admin only)
*/
MemberShipRequestType["REMOVE"] = "REMOVE";
/**
* Apply for membership.
*/
MemberShipRequestType["APPLY"] = "APPLY";
//INVITE = "INVITE",
/**
* Toggle admin status (available to group admin only)
*/
MemberShipRequestType["TOGGLE_ADMIN"] = "TOGGLE_ADMIN";
})(MemberShipRequestType = exports.MemberShipRequestType || (exports.MemberShipRequestType = {}));
function getUrl(_a) {
var request = _a.request;
return (0, api_1.createCommunityUrl)({
request: request,
path: '/groups'
});
}
exports.getUrl = getUrl;
function getBlogUrl(_a) {
var request = _a.request;
return (0, api_1.createCommunityUrl)({
request: request,
path: '/blog'
});
}
exports.getBlogUrl = getBlogUrl;
/**
*
* Should be fixed so it doesn't only work for king
*/
function getBlogPostUrl(_a) {
var request = _a.request, blogPermalink = _a.blogPermalink, entryPermalink = _a.entryPermalink;
var u = '/blog/' + (blogPermalink ? blogPermalink : 'king');
if (entryPermalink) {
return (0, api_1.createCommunityUrl)({
request: request,
path: u + '/' + entryPermalink
});
}
return (0, api_1.createCommunityUrl)({
request: request,
path: u + '/posts'
});
}
exports.getBlogPostUrl = getBlogPostUrl;
/**
* Get the site link to a group
* @param request
* @param group
* @returns {string}
*/
function getGroupUrl(_a) {
var request = _a.request, group = _a.group;
return (0, api_1.createCommunityUrl)({
request: request,
path: '/' + group.permalink
});
}
exports.getGroupUrl = getGroupUrl;
function getGroupSettingsUrl(_a) {
var request = _a.request, group = _a.group;
return (0, api_1.createCommunityUrl)({
request: request,
path: '/' + group.permalink + '/settings'
});
}
exports.getGroupSettingsUrl = getGroupSettingsUrl;
/**
* Get CSS for a group.
* Specify groupId or groupPermalink.
* @param groupPermalink
* @param groupId
* @return {Promise}
*/
function getCss(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
throw Error('not implemented');
// FIXME: Returns text/css
//return xcapApi.getJson('/group/css', arguments);
}
exports.getCss = getCss;
/**
* Given an url, get the group type ("blog", "group", "discussion")
* @param request
* @param url
* @returns {string}
*/
function getGroupType(_a) {
var request = _a.request, url = _a.url;
try {
var groupsRegExp = new RegExp("".concat(request.communityUrl, "/([^/]*)"));
var r = url.match(groupsRegExp);
if (r) {
return r[1];
}
}
catch (e) {
// Ignored
}
console.error("Couldn't getGroupType: ", url);
return '';
}
exports.getGroupType = getGroupType;
/**
* List my groups
*/
function listMyGroups(_a) {
return (0, api_1.getJson)({ url: '/group/list/my', parameters: arguments });
}
exports.listMyGroups = listMyGroups;
/**
* List groups.
*
* @param q {string} Search expression. Optional.
* @param categoryId {number} Category id. Optional
* @param categoryPermaLink {string} Category permalink. Optional.
* @param memberUserId {number} Search for groups where this user is a member. Optional
* @param sortBy {sortBy} Sort by
* @param order {SortOrder} order
* @param pageSize {number} Page size
* @param p {number} Page number
* @return {Promise}
*/
function search(_a) {
var q = _a.q, categoryId = _a.categoryId, categoryPermaLink = _a.categoryPermaLink, memberUserId = _a.memberUserId, sortBy = _a.sortBy, order = _a.order, pageSize = _a.pageSize, _b = _a.p, p = _b === void 0 ? 1 : _b;
return (0, api_1.getJson)({ url: '/group/search', parameters: arguments });
}
exports.search = search;
/**
* List groups by tag.
*
* @param tag {string} Tag.
* @param pageSize {number} Page size
* @param p {number} Page number
*/
function listGroupsByTag(_a) {
var tag = _a.tag, pageSize = _a.pageSize, _b = _a.p, p = _b === void 0 ? 1 : _b;
return (0, api_1.getJson)({ url: '/group/list/by-tag', parameters: arguments });
}
exports.listGroupsByTag = listGroupsByTag;
/**
* Get a group and it's members.
* Specify groupId or groupPermalink.
*/
function getGroup(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
return (0, api_1.getJson)({ url: '/group/get', parameters: arguments });
}
exports.getGroup = getGroup;
/**
* Subscribe to a group
* @param groupPermalink
* @param groupId
*/
function subscribe(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
return (0, api_1.post)({ url: '/group/subscribe', parameters: arguments });
}
exports.subscribe = subscribe;
/**
* Unsubscribe from a group
* @param groupPermalink
* @param groupId
*/
function unsubscribe(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
return (0, api_1.post)({ url: '/group/unsubscribe', parameters: arguments });
}
exports.unsubscribe = unsubscribe;
/**
* Apply for membership in a group
* @param groupPermalink
* @param groupId
*/
function applyForMembership(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
return (0, api_1.post)({ url: '/group/applyForMembership', parameters: arguments });
}
exports.applyForMembership = applyForMembership;
/**
* Edit a group membership, membership request
*
* Specify groupId or groupPermalink.
*
* @param action {MemberShipRequestType} Required
* @param groupPermalink
* @param groupId
* @param userId {[number]} One or more user ids. Required
* @param privilegeType Optional. The privilege of the user (can be used to add and make a user admin in one request)
*/
function editMembership(_a) {
var action = _a.action, groupPermalink = _a.groupPermalink, groupId = _a.groupId, userId = _a.userId, privilegeType = _a.privilegeType;
return (0, api_1.post)({
url: '/group/edit-membership',
parameters: {
groupPermalink: groupPermalink,
groupId: groupId,
userId: userId,
memberShipRequestType: action,
privilegeType: privilegeType,
ignoreDuplicates: true
}
});
}
exports.editMembership = editMembership;
/**
* List pending group membership requests.
* Available to group admins only.
*
* @param groupPermalink
* @param groupId
*/
function listMembershipRequests(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId;
return (0, api_1.getJson)({ url: 'group/list/membership-requests', parameters: arguments });
}
exports.listMembershipRequests = listMembershipRequests;
/**
* List members of a group
*
* Specify groupId or groupPermalink.
* FIXME: No support for pagination
*/
function listMembers(_a) {
var groupPermalink = _a.groupPermalink, groupId = _a.groupId, groupMemberPrivilegeType = _a.groupMemberPrivilegeType, _b = _a.sortOrder, sortOrder = _b === void 0 ? GroupMemberSortOrder.JOIN_DATE_DESC : _b;
return (0, api_1.getJson)({ url: '/group/list/members', parameters: arguments });
}
exports.listMembers = listMembers;
/**
* Edit or create a group.
*
* Action will set all parameters, not just the supplied one.
*
* @param groupId Group id (Optional)
* @param groupPermalink Group permalink (Optional)
* @param name Name, required.
* @param headline
* @param description
* @param visibility
* @param contentVisibility
* @param isOpenForApplications
* @param categoryId Category id (Optional)
* @param tags Tags (Optional)
* @returns {Thunk<XcapJsonResult>}
*/
function editGroup(_a) {
var groupId = _a.groupId, groupPermalink = _a.groupPermalink, name = _a.name, headline = _a.headline, description = _a.description, visibility = _a.visibility, contentVisibility = _a.contentVisibility, isOpenForApplications = _a.isOpenForApplications, categoryId = _a.categoryId, tags = _a.tags;
return (0, api_1.post)({
url: '/group/edit',
parameters: arguments
});
}
exports.editGroup = editGroup;
/**
* Check if a group permalink is valid and available.
* @param groupPermalink
*/
function checkGroupPermalink(_a) {
var groupPermalink = _a.groupPermalink;
return (0, api_1.getJson)({
url: '/group/check-permalink',
parameters: arguments
});
}
exports.checkGroupPermalink = checkGroupPermalink;
/**
* Set the group logotype image.
*
* @param groupId
* @param imageId
*/
function setGroupLogotypeImage(_a) {
var groupId = _a.groupId, imageId = _a.imageId;
return (0, api_1.post)({
url: '/group/set-image',
parameters: {
groupId: groupId,
imageId: imageId,
type: 'LOGOTYPE'
}
});
}
exports.setGroupLogotypeImage = setGroupLogotypeImage;
/**
* Set the group background image.
*
* @param groupId
* @param imageId
*/
function setGroupBackgroundImage(_a) {
var groupId = _a.groupId, imageId = _a.imageId;
return (0, api_1.post)({
url: '/group/set-image',
parameters: {
groupId: groupId,
imageId: imageId,
type: 'BACKGROUND'
}
});
}
exports.setGroupBackgroundImage = setGroupBackgroundImage;
/**
* Set group styling.
*
* Application specific colors and fonts can be set by
* supplying extra parameters named *color* or *font*.
*
* Requires group admin.
*
* @param groupId Group id
* @param permalink Group permalink (optional)
* @param lightLogotypeId Image id of light logotype image
* @param darkLogotypeId Image id of dark logotype image
* @param backgroundImageId Image id of background image
* @param backgroundCropX Background crop position
* @param backgroundCropY Background crop position
* @param any
*/
function setGroupStyle(_a) {
var groupId = _a.groupId, permalink = _a.permalink, lightLogotypeId = _a.lightLogotypeId, darkLogotypeId = _a.darkLogotypeId, backgroundImageId = _a.backgroundImageId, backgroundCropX = _a.backgroundCropX, backgroundCropY = _a.backgroundCropY, any = __rest(_a, ["groupId", "permalink", "lightLogotypeId", "darkLogotypeId", "backgroundImageId", "backgroundCropX", "backgroundCropY"]);
return (0, api_1.post)({
url: '/group/set-style',
parameters: arguments
});
}
exports.setGroupStyle = setGroupStyle;
/**
* Remove a group.
*
* @param groupId Group id
*/
function removeGroup(_a) {
var groupId = _a.groupId;
return (0, api_1.post)({
url: '/group/remove',
parameters: arguments
});
}
exports.removeGroup = removeGroup;
//# sourceMappingURL=index.js.map