@stackend/api
Version:
JS bindings to api.stackend.com
555 lines • 17.2 kB
TypeScript
import { XcapJsonResult, Thunk, XcapOptionalParameters } from '../api';
import { Order } from '../api/Order';
import { Request } from '../request';
import { AuthenticationType } from '../login';
import { PaginatedCollection } from '../api/PaginatedCollection';
import { CurrentUserType } from '../login/loginReducer';
import { Community } from '../stackend';
import { AuthObject, PrivilegeTypeId, PrivilegeTypeIds } from './privileges';
import XcapObject from '../api/XcapObject';
import NameAware from '../api/NameAware';
import PermalinkAware from '../api/PermalinkAware';
import ReferenceAble from '../api/ReferenceAble';
import CreatedDateAware from '../api/CreatedDateAware';
export declare const TYPE_USER = "net.josh.community.user.backend.xcap.XcapUser";
/**
* Definition of a user
*/
export interface User extends XcapObject, NameAware, PermalinkAware, CreatedDateAware, ReferenceAble {
__type: 'net.josh.community.user.backend.xcap.XcapUser';
alias: string;
firstName: string;
lastName: string;
userName: string;
/** Full name, or the alias if not set */
nameOrAlias: string;
/** Birth date or null if not set*/
birthDate: number | null;
cityId: number;
/** City name, if set */
city: string | null;
online: boolean;
/** Profile image url, or null if not set */
profileImage: string | null;
/** Additional profile data */
profile: {
[key: string]: string;
};
/** Privileges. using the format: context,componentName,privilegeType */
privileges: Array<string>;
gender?: GenderType | null;
}
/**
* User fields only available to privileged users
*/
export interface UserPrivateDataType extends User {
email: string;
status?: StatusIdType;
zipCode?: string | null;
nrOfLogins?: number | null;
}
/**
* User status
* @type {{OK: number, NOT_VERIFIED: number, BLOCKED: number, DELETED_BY_USER: number, DELETED_BY_ADMIN: number}}
*/
export declare enum Status {
OK = 0,
NOT_VERIFIED = 5,
BLOCKED = 10,
DELETED_BY_USER = 15,
DELETED_BY_ADMIN = 20
}
/**
* Valid Statuses
*/
export declare type StatusIdType = 0 | 5 | 10 | 15 | 20;
/**
* Get a human readable form of the status
* @param statusId
* @returns string
*/
export declare function getStatusName(statusId: StatusIdType): string;
/**
* Gender
*/
export declare enum GenderId {
UNKNOWN = 0,
FEMALE = 1,
MALE = 2
}
export declare type GenderIdType = 0 | 1 | 2;
/**
* Gender constants
*/
export declare const Gender: any;
export declare type GenderType = 'FEMALE' | 'MALE' | 'UNKNOWN';
/**
* User context-type
* @type {string}
*/
export declare const CONTEXT = "members";
/**
* User Component name
* @type {string}
*/
export declare const COMPONENT_NAME = "user";
/**
* User manager component class
* @type {string}
*/
export declare const COMPONENT_CLASS = "net.josh.community.user.UserManager";
/**
* Sort order for user search
*/
export declare enum OrderBy {
ALIAS = "ALIAS",
CREATED = "CREATED",
CITY = "CITY",
AGE = "AGE",
LAST_LOGIN = "LAST_LOGIN",
GENDER = "GENDER",
LAST_MODIFIED = "LAST_MODIFIED",
STATUS = "STATUS"
}
export interface GetUserResult extends XcapJsonResult {
user: User | null;
}
/**
* Get the current user in the current community, or null if not authorized.
* This involves a server request.
* @see index.ts:getCurrentStackendUser()
* @return {Thunk}
*/
export declare function getCurrentUser(): Thunk<Promise<GetUserResult>>;
/**
* Construct a link to a users profile page.
* @param request
* @param userId
* @param userName
* @param absolute
*/
export declare function getProfilePageUrl({ request, userId, userName, absolute }: {
request: Request;
userId: number;
userName: string;
absolute?: boolean;
}): string;
/**
* Construct a link to a users profile page, supports remote profile links as well as local
* @param request
* @param user
* @param community
*/
export declare function getProfileLink(request: Request, user: User, community: Community | null): {
url: string;
isRemote: boolean;
};
/**
* Check if the current user has elevated privileges (does not include rules etc).
*
* @param currentUser
* @param componentContext {String} Context name, for example "members", "news", "cms"
* @param componentClass {String} Component, for example "net.josh.community.user.UserManager", "net.josh.community.blog.BlogManager",
* "se.josh.xcap.cms.CmsManager", "net.josh.community.forum.ForumManager"
* @param privilegeTypeId {number} Minimum required privilege
*/
export declare function hasElevatedPrivilege(currentUser: CurrentUserType | User | null, componentContext: string, componentClass: string, privilegeTypeId: PrivilegeTypeId): boolean;
/**
* Get a user.
* Use id, alias to look up a user.
*
* @param id User id (required)
* @param alias User alias (optional)
* @returns {Promise}
*/
export declare function getUser({ id, alias }: {
id?: number;
alias?: string;
} & XcapOptionalParameters): Thunk<Promise<GetUserResult>>;
export interface GetUsersResult extends XcapJsonResult {
users: Array<User>;
}
/**
* Get multiple users by id
* @param id
* @returns {Promise}
*/
export declare function getUsers({ id }: {
id: Array<number>;
} & XcapOptionalParameters): Thunk<Promise<GetUsersResult>>;
/**
* Transform into a mutable user data that is accepted by store user
* @param user
*/
export declare function getMutableUser(user: User): any;
export interface StoreUserResult extends XcapJsonResult {
user: User | null;
}
/**
* Store a user.
*
* All parameters except id are optional. If not present, they will not be changed.
*
* @param id
* @param alias
* @param email
* @param firstName
* @param lastName
* @param gender
* @param cityId
* @param birthYear
* @param birthMonth
* @param birthDay
* @param showBirthDay
* @param zipCode
* @param termsAccept Accept the terms and conditions
* @param profileEntries Other entries
*/
export declare function storeUser({ id, alias, email, firstName, lastName, gender, cityId, birthYear, birthMonth, birthDay, showBirthDay, zipCode, termsAccept, ...profileEntries }: {
id?: number;
alias?: string;
email?: string;
firstName?: string;
lastName?: string;
gender?: string;
cityId?: number;
birthYear?: number;
birthMonth?: number;
birthDay?: number;
showBirthDay?: boolean;
zipCode?: number;
termsAccept?: boolean;
profileEntries?: any;
} & XcapOptionalParameters): Thunk<Promise<StoreUserResult>>;
export interface GetUserPrivilegesResult extends XcapJsonResult {
auth: AuthObject;
privilegeType: PrivilegeTypeIds;
}
/**
* Get the current users privileges for a given component/context
* @param componentContext {String} Context name, for example "members", "news", "cms"
* @param componentClass {String} Component, for example "net.josh.community.user.UserManager", "net.josh.community.blog.BlogManager",
* "se.josh.xcap.cms.CmsManager", "net.josh.community.forum.ForumManager"
* @param externalTypeId {number}
* @returns {Promise}
*/
export declare function getUserPrivileges({ componentContext, componentClass, externalTypeId }: {
componentContext: string;
componentClass: string;
externalTypeId: number;
} & XcapOptionalParameters): Thunk<Promise<GetUserPrivilegesResult>>;
export interface SearchResult extends XcapJsonResult {
users: PaginatedCollection<User>;
}
/**
* Search for users.
*
* @param q Serch string
* @param allowEmptySearch Will empty searches be allowed and return all matches?
* @param excludeCurrentUser Should the current user be ignored?
* @param p Page number
* @param pageSie Page size
*/
export declare function search({ q, allowEmptySearch, excludeCurrentUser, p, pageSize, orderBy, order, community }: {
q?: any;
allowEmptySearch?: boolean;
excludeCurrentUser?: boolean;
p?: number;
pageSize?: number;
orderBy?: OrderBy | null;
order?: Order | null;
community?: string;
} & XcapOptionalParameters): Thunk<Promise<SearchResult>>;
export interface SetProfileImageResult extends XcapJsonResult {
imageId: number;
}
/**
* Set profile image of the current user
*
* @param imageId Image id (from the members context)
* @param community
* @returns {Promise}
*/
export declare function setProfileImage({ imageId, community }: {
imageId: number;
community?: string;
} & XcapOptionalParameters): Thunk<Promise<SetProfileImageResult>>;
/**
* Remove profile image of the current user
*
* @returns {Promise}
*/
export declare function removeProfileImage({ community }: {
community?: string;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
/**
* Get the url to a users feed.
* @param userId optional, defaults to current user
* @returns {String}
*/
export declare function getUserFeedUrl({ userId }: {
userId: number;
}): Thunk<string>;
export interface IsEmailFreeResult extends XcapJsonResult {
email: string | null;
isEmailFree: boolean;
}
/**
* Check if the email is free for registration
* @param email
*/
export declare function isEmailFree({ email }: {
email: string;
} & XcapOptionalParameters): Thunk<Promise<IsEmailFreeResult>>;
export interface IsAliasFreeResult extends XcapJsonResult {
alias: string | null;
isAliasFree: boolean;
}
/**
* Check if the alias is free for registration
* @param email
*/
export declare function isAliasFree({ alias }: {
alias: string;
} & XcapOptionalParameters): Thunk<Promise<IsAliasFreeResult>>;
export interface GetRegistrationDataResult extends XcapJsonResult {
/** Email, if available */
email: string | null;
/** Should the user be able to edit the email? */
isEmailEditable: boolean;
/** Unique alias (generated) */
alias: string | null;
/** Non unique user name */
username: string | null;
/** Should the user be able to edit the user name? */
isUsernameEditable: boolean;
/** Id in the remote system */
referenceId: number;
/** */
authenticationType: AuthenticationType;
cityId: number;
/** Gender */
gender: GenderIdType | null;
/** First name */
firstName: string | null;
/** Last name */
lastName: string | null;
/** Birth date, if available */
birthDate: number | null;
}
/**
* Get data needed to make a registration.
*
* @returns {Thunk<GetRegistrationDataResult>}
*/
export declare function getFacebookRegistrationData({}: XcapOptionalParameters): Thunk<Promise<GetRegistrationDataResult>>;
/**
* Submit additional information when registering a facebook user
*
* @param email
* @param username
* @param firstName
* @param lastName
* @param gender
* @param birthDate
* @param termsAccept
* @param returnUrl optional return url
* @returns {Thunk<XcapJsonResult>}
*/
export declare function registerFacebookUser({ email, username, firstName, lastName, gender, birthDate, termsAccept, returnUrl }: {
email?: string;
username?: string;
firstName?: string;
lastName?: string;
gender?: GenderIdType;
birthDate?: string;
termsAccept?: boolean;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
/**
* Remove a facebook login reference
* @param facebookId
* @returns {Thunk<XcapJsonResult>}
*/
export declare function removeFacebookReference({ facebookId }: {
facebookId?: string | null;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
/**
* Remove a Google login reference
* @param userReferenceId
* @returns {Thunk<XcapJsonResult>}
*/
export declare function removeGoogleReference({ userReferenceId }: {
userReferenceId?: string | null;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
/**
* Submit additional information when registering a google user
*
* @param email
* @param username
* @param firstName
* @param lastName
* @param gender
* @param birthDate
* @param termsAccept
* @param returnUrl optional return url
* @returns {Thunk<XcapJsonResult>}
*/
export declare function registerGoogleUser({ email, username, firstName, lastName, gender, birthDate, termsAccept, returnUrl }: {
email?: string;
username?: string;
firstName?: string;
lastName?: string;
gender?: GenderIdType;
birthDate?: string;
termsAccept?: boolean;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
/**
* Submit additional information when registering a OAuth2 user
*
* @param email
* @param username
* @param firstName
* @param lastName
* @param gender
* @param birthDate
* @param termsAccept
* @param returnUrl optional return url
* @returns {Thunk<XcapJsonResult>}
*/
export declare function registerOAuth2User({ email, username, firstName, lastName, gender, birthDate, termsAccept, returnUrl }: {
email?: string;
username?: string;
firstName?: string;
lastName?: string;
gender?: GenderIdType;
birthDate?: string;
termsAccept?: boolean;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
export interface VerifyEmailResult extends XcapJsonResult {
/** Was the validation successful? */
valid: boolean;
/** Does the user need to enter additional data? */
register: boolean;
returnUrl: string | null;
/** Permalink of the users first, automatically created community */
firstCommunityPermalink?: string | null;
}
/**
* Send an email with a verification code link.
* This is done to validate that this is an actual email address owned by the user.
*
* @param email
* @param authenticationType
* @param returnUrl optional returnUrl to include in the mail
* @returns {Thunk<VerifyEmailResult>}
* @see verifyEmail
*/
export declare function sendVerificationEmail({ email, authenticationType, returnUrl }: {
email: string;
authenticationType?: string;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<VerifyEmailResult>>;
/**
* Verify a user email by posting the code recieved in an email.
*
* @param email
* @param code
* @param login. Should the user be logged in on successufull verification?s
* @param returnUrl Optional return url
* @returns {Thunk<VerifyEmailResult>}
* @see sendVerificationEmail
*/
export declare function verifyEmail({ email, code, login, returnUrl }: {
email: string;
code: string;
login?: boolean;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<VerifyEmailResult>>;
export interface RegisterUserResult extends XcapJsonResult {
user: User;
}
/**
* Register a user using an email address.
*
* @param email
* @param username
* @param firstName
* @param lastName
* @param gender
* @param birthYear
* @param birthMonth
* @param birthDay
* @param showBirthDay
* @param termsAccept
* @param returnUrl optional return url
* @returns {Thunk<RegisterUserResult>}
*/
export declare function registerUser({ email, username, firstName, lastName, gender, birthYear, birthMonth, birthDay, showBirthDay, termsAccept, returnUrl }: {
email?: string;
username?: string;
firstName?: string;
lastName?: string;
gender?: GenderIdType;
birthYear?: number;
birthMonth?: number;
birthDay?: number;
showBirthDay?: boolean;
termsAccept?: boolean;
returnUrl?: string;
} & XcapOptionalParameters): Thunk<Promise<RegisterUserResult>>;
/**
* Activity statistics for a user. If any of the counts equals -1, that feature is disabled.
*/
export interface UserStatistics {
userId: number;
numberOfPosts: number;
numberOfComments: number;
numberOfForumEntries: number;
numberOfQuestions: number;
numberOfAnswers: number;
numberOfLikes: number;
}
export interface GetUserStatisticsResult extends XcapJsonResult {
user: User | null;
userStatistics: UserStatistics | null;
}
/**
* Get activity counters for a user
* @param id
* @returns {*}
*/
export declare function getStatistics({ id }: {
id: number;
} & XcapOptionalParameters): Thunk<Promise<GetUserStatisticsResult>>;
/**
* Check if a password is acceptable
* @param password
* @returns {string|boolean|(Array<string>&{index: number, input: string, groups})}
*/
export declare function isPasswordAcceptable(password: string | null): boolean;
export interface ListAuthenticationOptionsResult extends XcapJsonResult {
user: User | null;
availableOptions: Array<AuthenticationType>;
enabledOptions: Array<AuthenticationType>;
}
/**
* List available and enabled authentication options of the current user.
* @returns {Thunk<XcapJsonResult>}
*/
export declare function listAuthenticationOptions({}: XcapOptionalParameters): Thunk<Promise<ListAuthenticationOptionsResult>>;
/**
* Block/unblock a user. Requires stackend community admin status.
* @param id
* @param block
* @param comment
*/
export declare function setBlocked({ id, block, comment }: {
id: number;
block: boolean;
comment?: string | null;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
export declare function listOnline({}: XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
//# sourceMappingURL=index.d.ts.map