@stackend/api
Version:
JS bindings to api.stackend.com
662 lines • 20.6 kB
TypeScript
import { Request } from '../request';
import { Thunk, XcapJsonResult } from '../api';
import ModerationStatus from '../api/ModerationStatus';
import Order from '../api/Order';
import { User } from '../user';
import { PaginatedCollection } from '../api/PaginatedCollection';
import { CurrentUserType } from '../login/loginReducer';
import { PrivilegeTypeIds } from '../user/privileges';
import { Image } from '../media';
import XcapObject from '../api/XcapObject';
import NameAware from '../api/NameAware';
import DescriptionAware from '../api/DescriptionAware';
import PermalinkAware from '../api/PermalinkAware';
import CreatorUserIdAware from '../api/CreatorUserIdAware';
import CreatedDateAware from '../api/CreatedDateAware';
import ModerationStatusAware from '../api/ModerationStatusAware';
import ExpirationDateAware from '../api/ExpirationDateAware';
/**
* Stackend API constants and methods.
*
* @since 20 apr 2017
*/
/**
* CommunityStatus
* @type {{VISIBLE: string, HIDDEN: string, REMOVED: string}}
*/
export declare enum CommunityStatus {
VISIBLE = "VISIBLE",
HIDDEN = "HIDDEN",
REMOVED = "REMOVED"
}
/**
* Xcap community name for stackend.
* @type {string}
*/
export declare const STACKEND_COMMUNITY = "stackend";
/**
* Commmunity permalink used for stackend.com news and examples
* @type {string}
*/
export declare const STACKEND_DOT_COM_COMMUNITY = "stackend-com";
/**
* Definition of a community
*/
export interface Community extends XcapObject, NameAware, DescriptionAware, PermalinkAware, CreatorUserIdAware, CreatedDateAware, ModerationStatusAware, ExpirationDateAware {
__type: 'se.josh.xcap.community.Community';
status: string /** CommunityStatus */;
logotype: Image | null;
domains: Array<string>;
adminUserIds: Array<number>;
adminsUserRef: Array<User>;
moderatorUserIds: Array<number>;
moderatorUserRef: Array<User>;
locale: string;
xcapCommunityName: string;
theme: string;
settings: any;
style: any;
defaultUserId: number;
openAIApiKey: string;
}
/**
* Community setting keys
*/
export declare const CommmunitySettings: {
LOGIN_ENABLED: string;
REGISTER_ENABLED: string;
TERMS_AND_CONDITIONS_LINK: string;
FACEBOOK_LOGIN: string;
GOOGLE_LOGIN: string;
OAUTH2_LOGIN: string;
};
/**
* A module / function
*/
export interface Module extends XcapObject, NameAware {
__type: 'se.josh.xcap.community.Module';
/** Community owning this module */
communityId: number;
/** If set to true, the module will be visible on site */
enabled: boolean;
/** XCAP community context for the component */
componentContext: string;
/** XCAP component class name */
componentClass: string;
/** Component name, for example "comments" */
componentName: string;
/**
* Does the module have categories?
*/
hasCategories: boolean;
/**
* Does the module have additional comments?
*/
hasComments: boolean;
obfuscatedReference: string;
/** Related object key, if any */
objectRef: null | string;
/** Rule type id used when applying rules */
ruleTypeId: number;
/**
* Additional module specific settings
*/
settings: {
[key: string]: any;
};
/**
* Additional style settings
*/
style: {
[key: string]: string;
};
}
export interface ModuleRule {
/** Create privilege */
createPrivilege: PrivilegeTypeIds;
moderationStatus: ModerationStatus;
postModerationTtlMinutes: number;
contentFiltering: boolean;
trustedUsers: Array<User>;
}
export interface ModuleStats {
numberOfMembers: number /** -1 for unknown */;
numberOfPosts: number /** -1 for unknown */;
numberOfComments: number /** -1 for unknown */;
}
export interface CommunityStats {
numberOfModules: number;
objectsAwaitingModeration: number;
numberOfUsers: number;
numberOfActiveUsers: number;
mediaFileSize: number;
numberOfPosts: number;
}
/**
* A community theme
*/
export declare const Theme: {
STACKEND: string;
};
/**
* Community search sort ordering
*/
export declare enum OrderBy {
NAME = "NAME",
CREATED_DATE = "CREATED_DATE"
}
/**
* Given a theme, get a human readable label
* @param theme
* @returns {string}
*/
export declare function getThemeLabel(theme: string): string;
/**
* CommunityManager context
* @type {string}
*/
export declare const COMMUNITY_MANAGER_CONTEXT = "community";
/**
* CommunityManager component class
* @type {string}
*/
export declare const COMPONENT_CLASS = "se.josh.xcap.community.CommunityManager";
/**
* Community permalink reserverd for news and documentation on stackend.com
* @type {string}
*/
export declare const STACKEND_COM_COMMUNITY_PERMALINK = "stackend-com";
export interface GetCommunityResult extends XcapJsonResult {
communityFromDomain: boolean;
stackendCommunity: Community | null;
/**
* Number of objects waiting for moderation. Available to admins only.
*/
objectsRequiringModeration: number;
}
/**
* Get a community.
* If no parameter is present, the domain is taken from the referer header.
*
* @param id {String}
* @param permalink {String}
* @param domain {String}
*
*/
export declare function getCommunity({ id, permalink, domain }: {
id?: number;
permalink?: string;
domain?: string;
}): Thunk<Promise<GetCommunityResult>>;
export interface ValidateCommunityPermalinkResult extends XcapJsonResult {
valid: boolean;
suggestions: Array<string>;
}
/**
* Validate a community permalink and get suggestions based on the permalink/name.
*
* @param permalink {String}
* @param name {String} generate permalink suggestions based on this name (Optional)
*
*/
export declare function validateCommunityPermalink({ permalink, name }: {
permalink: string;
name?: string;
}): Thunk<Promise<ValidateCommunityPermalinkResult>>;
/**
* Create, but do not store a new community object that can be used to store
* @param name
* @param permalink
*/
export declare function newCommunity(name: string, permalink: string): any;
export interface StoreCommunityResult extends XcapJsonResult {
storedCommunity: Community;
}
/**
* Edit/create a community.
*
* @param id {String} (optional, only when editing)
* @param permalink {String} Required
* @param name {String} Name
* @param description {String}
* @param status {CommunityStatus}
* @param locale {String} Locale (default: en_US)
* @param domains {string[]} List of valid domains
* @param settings {String} Implementation specific settings data (typically JS) for front end.
* @param logotypeId {number} Media id of logotype image
* @param admins {number[]} List of admin user ids
* @param moderators {number[]} List of moderator user ids
* @param theme {String} Name of theme to use
* @param style {String} Implementation specific style data (typically CSS) for front end.
* @param defaultUserId
* @param openAIApiKey
*/
export declare function storeCommunity({ id, permalink, name, description, status, locale, domains, settings, logotypeId, admins, moderators, theme, style, defaultUserId, openAIApiKey }: {
id?: number;
permalink?: string;
name?: string;
description?: string;
status?: any;
locale?: string;
domains?: Array<string>;
settings?: any;
logotypeId?: number;
admins?: Array<number>;
moderators?: Array<number>;
theme?: string;
style?: any;
defaultUserId?: number;
openAIApiKey?: string;
}): Thunk<Promise<StoreCommunityResult>>;
/**
* Set all community settings without affecting anything else.
*
* @param id {number}
* @param settings {any} Settings
*/
export declare function setCommunitySettings({ id, settings }: {
id: number;
settings: any;
}): Thunk<Promise<StoreCommunityResult>>;
/**
* Set a single community setting without affecting anything else.
*
* @param id {number}
* @param name {string}
* @param value {any}
*/
export declare function setCommunitySetting({ id, name, value }: {
id: number;
name: string;
value: any;
}): Thunk<Promise<StoreCommunityResult>>;
/**
* Set a single community setting without affecting anything else.
*
* @param id {number}
* @param theme StackendTheme
*/
export declare function storeCommunityTheme({ id, theme }: {
id: number;
theme: any;
}): Thunk<Promise<StoreCommunityResult>>;
export declare type GetCommunityPrivateSettingsResult = XcapJsonResult;
/**
* Get the community's private settings that are not exposed to the frontend
* @param key Get a specific setting
* @param prefix Get settings with a specific prefix ("" for all)
* @param community
*/
export declare function getCommunityPrivateSettings({ key, prefix, community }: {
key?: string | null;
prefix?: string | null;
community?: string | null;
}): Thunk<Promise<GetCommunityPrivateSettingsResult>>;
/**
* Store the communitys private settings that are not exposed to the frontend.
* Store a single key/value or a set of values.
* @param key
* @param value
* @param values
* @param community
* @returns {Thunk<XcapJsonResult>}
*/
export declare function storeCommunityPrivateSettings({ key, value, values, community }: {
key?: string | null;
value?: any | null;
values?: {
[name: string]: any;
};
community?: string | null;
}): Thunk<Promise<XcapJsonResult>>;
/**
* Set visible / hidden status of a community
*/
export declare function setCommunityStatus({ id, status }: {
id?: number;
status: CommunityStatus.VISIBLE | CommunityStatus.HIDDEN;
}): Thunk<Promise<StoreCommunityResult>>;
export interface RemoveCommunityResult extends XcapJsonResult {
dataRemoved: boolean;
}
/**
* Remove a community. If new or empty, the data will also be removed.
* You can force data to be removed by setting removeData. That requires back office access however.
*
* @param id {String}
* @param removeData {boolean} Remove the data, even if the community is not empty. Requires back office access.
*/
export declare function removeCommunity({ id, removeData }: {
id: number;
removeData: boolean;
}): Thunk<Promise<RemoveCommunityResult>>;
export interface SearchCommunityResult extends XcapJsonResult {
results: PaginatedCollection<Community>;
statistics: {
[id: string]: CommunityStats;
};
}
/**
* Search for a communities.
* @param myCommunities {boolean} Search the current users communities only
* @param creatorUserId {number} find communities created by this user only
* @param status
* @param q Search string
* @param p
* @param pageSize
* @param orderBy
* @param order
*/
export declare function searchCommunity({ myCommunities, creatorUserId, status, q, p, pageSize, orderBy, order }: {
myCommunities?: boolean;
creatorUserId?: number;
status?: any;
q?: number;
p?: number;
pageSize?: number;
orderBy?: OrderBy;
order?: Order;
}): Thunk<Promise<SearchCommunityResult>>;
/**
* Get the current user (with privileges from stackend rather than the current community)
*/
export declare function getCurrentStackendUser(): Thunk<Promise<XcapJsonResult>>;
/**
* In a list of communities, find the one that matches the permalink
* @return {Community} may return null,
*/
export declare function getCurrentCommunity(communities: Array<Community>): Thunk<Community | null>;
/**
* Check if the potential community url permalink is blocked.
* @param communityUrl
* @returns {boolean}
*/
export declare function isCommunityUrlBlocked(communityUrl: string): boolean;
/**
* From the request url try to get the communityPermalink
* @return {Community} may return null,
*/
export declare function _getCurrentCommunityPermalinkFromUrl(request: Request): any;
/**
* In a list of communities, find the one that matches the permalink
* @return {Community} may return null,
*/
export declare function _getCurrentCommunity(communities: Array<Community>, request: Request): Community | null;
/**
* Check if the user is a community moderator, but not admin
* @param community
* @param userId
* @returns {boolean}
*/
export declare function isCommunityModerator(community: Community | null, userId: number): boolean;
/**
* Check if a user is admin
* @param community
* @param userId
* @returns {boolean}
*/
export declare function isCommunityAdmin(community: Community | null, userId?: number | null): boolean;
/**
* Check if the user has stackend admin access (any community/stack).
* @param currentUser
* @returns {boolean}
*/
export declare function hasStackendAdminAccess(currentUser: CurrentUserType | User | null): boolean;
/**
* Check if there is any way a user may see the current community
* @param community
* @param currentUser
*/
export declare function hasCommunityAdminOrModeratorAccess(community: Community | null, currentUser: CurrentUserType): boolean;
/**
* Check if the current user has community admin access
* @param community
* @param currentUser
* @returns {boolean}
*/
export declare function hasCommunityAdminAccess(community: Community | null, currentUser: CurrentUserType): boolean;
/**
* Check if the user has stackend access and may create new stacks.
* @param currentUser
* @returns {boolean}
*/
export declare function hasStackendCreateAccess(currentUser: CurrentUserType): boolean;
export declare type SupportedModuleContext = {
context: string;
componentClass: string;
supportsMultipleModules: boolean;
};
export interface GetModulesResult extends XcapJsonResult {
modules: Array<Module>;
supportedModuleContexts: Array<SupportedModuleContext>;
stats: {
[id: string]: ModuleStats;
};
}
/**
* Get the modules of a community.
*
* @param communityId
* @returns {Promise}
*/
export declare function getModules({ communityId }: {
communityId: number;
}): Thunk<Promise<GetModulesResult>>;
export interface GetModuleResult extends XcapJsonResult {
module: Module | null;
rule: ModuleRule | null;
commentRule: ModuleRule | null;
stats: ModuleStats | null;
}
/**
* Get a module of a community.
*
* @param communityId
* @param moduleId
* @returns {Thunk<GetModuleResult>}
*/
export declare function getModule({ communityId, moduleId }: {
communityId: number;
moduleId: number;
}): Thunk<Promise<GetModuleResult>>;
/**
* Get a singleton module given it's component class
* @param communityId
* @param componentClass
* @param componentContext
* @returns {Thunk<GetModuleResult>}
*/
export declare function getSingletonModule({ communityId, componentClass, componentContext }: {
communityId: number;
componentClass: string;
componentContext: string;
}): Thunk<Promise<GetModuleResult>>;
/**
* Construct the object that can be passed to storeModule()
* @param communityId
* @param componentClass
* @param componentContext
* @param name
*/
export declare function newModule({ communityId, componentClass, componentContext, name }: {
communityId: number;
componentClass: string;
componentContext: string;
name: string;
}): any;
export interface StoreModuleResult extends XcapJsonResult {
module: Module | null;
}
/**
* Store a module of a community.
*
* When creating a new module, this will also set up the module data, for example the blog.
*
* @param id
* @param communityId
* @param name
* @param enabled
* @param componentClass
* @param componentContext
* @param ruleTypeId
* @param settings Implementation specific (js) string (Max 64KB)
* @param style Implementation specific (css) string (Max 64KB)
* @param extraData Component specific extra JSON data.
*
* Supported optional extra data:
* <dl>
* <dt>permalink</dt>
* <dt>description</dt>
* <dt>forumAnonymity</dt><dd>ForumAnonymityLevel</dd>
* <dt>groupVisibile</dt><dd>true/false</dd>
* <dt>groupContentVisibile</dt><dd>true/false</dd>
* <dt>body<dt>
* <dt>teaser</dt>
* <dl>
* @returns {Promise}
*/
export declare function storeModule({ id, communityId, name, enabled, componentClass, componentContext, ruleTypeId, settings, style, extraData }: {
id?: number;
communityId: number;
name?: string;
enabled?: boolean;
componentClass?: string;
componentContext?: string;
ruleTypeId?: number;
settings?: any;
style?: any;
extraData?: any;
}): Thunk<Promise<StoreModuleResult>>;
interface RuleSetup {
createPrivilege: PrivilegeTypeIds;
moderationStatus: ModerationStatus;
contentFiltering: boolean;
postModerationTtlMinutes: number;
}
/**
* Store rules for a module
* @param moduleId
* @param communityId
* @param rule
* @param commentRule
* @param trustedUsers
*/
export declare function storeModuleRules({ communityId, moduleId, rule, commentRule, trustedUsers }: {
communityId: number;
moduleId: number;
rule: RuleSetup;
commentRule: RuleSetup;
trustedUsers: Array<number>;
}): Thunk<Promise<XcapJsonResult>>;
/**
* Remove a module.
*
* @param id
* @param communityId
*/
export declare function removeModule({ id, communityId }: {
id: number;
communityId: number;
}): Thunk<Promise<XcapJsonResult>>;
/**
* Detect modules by inspecting existing data. Developer tool.
* @param communityId
*/
export declare function detectModules({ communityId }: {
communityId: number;
}): Thunk<Promise<XcapJsonResult>>;
/**
* Get a human readable component name
* @param componentClass class
*/
export declare function getComponentLabel(componentClass: string): string;
/**
* Get a component class
* @param moduleType
*/
export declare function getComponentClassFromModuleType(moduleType: string): string;
export interface ListAdminUsersResult extends XcapJsonResult {
users: Array<User>;
}
/**
* List users with stackend admin status.
* Requires stackend admin status.
* @param privilege {number} PrivilegeType
*/
export declare function listAdminUsers({ privilege }: {
privilege: number;
}): Thunk<Promise<ListAdminUsersResult>>;
/**
* Grant/revoke stackend admin status for a user.
* Requires stackend admin status.
* Any privilegeType lower than PrivilegeType.VERIFIED will remove the grants.
* @param userId {number} User id
* @param privilege {number} PrivilegeType
*/
export declare function setAdminStatus({ userId, privilege }: {
userId: number;
privilege: PrivilegeTypeIds;
}): Thunk<Promise<XcapJsonResult>>;
export interface SetCommunityAccessResult extends XcapJsonResult {
stackendCommunity: Community;
communityPrivilegeType: number;
communityId: number;
}
/**
* Make a user moderator or admin status from a community. Or remove that status
* @param communityId
* @param userId
* @param communityPrivilegeType Privilege: ADMIN for admins, TRUSTED for moderators. All other privs will revoke the access.
*/
export declare function setCommunityAccess({ communityId, userId, privilegeType }: {
communityId: number;
userId: number;
privilegeType: number;
}): Thunk<Promise<SetCommunityAccessResult>>;
/**
* Invite a user as administrator or moderator of this community.
* The user may or may not already be registered. If not, an email is sent inviting the user to manage the community.
*
* @param email Users email
* @param communityId Id of community
* @param communityPrivilegeType Privilege. Supports PrivilegeType.ADMIN (admin) and PrivilegeType.TRUSTED (moderator)
* @param message Optional welcome message
*/
export declare function inviteUserToCommunity({ email, communityId, communityPrivilegeType, message }: {
email: string;
communityId: number;
communityPrivilegeType: PrivilegeTypeIds;
message: string;
}): Thunk<Promise<XcapJsonResult>>;
/**
* Get the domain (excluding www) and path of an url.
* "http://www.josh.se/test" would return "josh.se/test"
* "/test" would return "/test"
* @param url
* @returns {*|string}
*/
export declare function getReferenceUrl(url: string): string;
/**
* Get the url to a stackend community and module
* @param request
* @param community
* @param module
* @param path
* @returns {string}
*/
export declare function getStackendUrl({ request, community, module, path }: {
request: Request;
community?: Community | null;
module?: Module | null;
path: string;
}): string;
/**
* Remove a user. Requires stackend admin status. Fails if the user has communities.
* @param userId
* @returns {Thunk<XcapJsonResult>}
*/
export declare function removeUser({ userId }: {
userId: number;
}): Thunk<Promise<XcapJsonResult>>;
export {};
//# sourceMappingURL=index.d.ts.map