@benshi.ai/js-sdk
Version:
Benshi SDK
311 lines (268 loc) • 6.19 kB
text/typescript
import { Country, Language, SearchFilter } from "../../core/commonTypes"
import { TypedItem } from "../ECommerce/typings"
export enum NavigationTypes {
App = "app",
Identify = "identify",
Media = "media",
NudgeResponse = 'nudge_response',
Page = "page",
Promo = "promo",
Rate = "rate",
Scroll = "scroll",
Search = "search",
Track = "track"
}
export enum ContentBlock {
Core = "core",
ELearning = "e-learning",
ECommerce = "e-commerce",
Social = "social",
Payment = "payment",
Loyalty = "loyalty"
}
export enum AppAction {
Background = "background",
Close = "close",
Open = "open",
Resume = "resume"
}
export enum IdentifyAction {
Login = "login",
Logout = "logout",
Register = "register"
}
export enum MediaActionForVideo {
Play = "play",
Pause = "pause",
Seek = "seek",
Finish = "finish"
}
export enum MediaActionForImage {
Play = "play",
}
export interface AppProperties {
action: AppAction,
start_time: number
}
export interface IdentifyProperties {
action: IdentifyAction,
}
export interface UserInfo extends IdentifyProperties {
user_props: UserProperties
}
export type ImageProperties = {
/**
* The block or module where the media is embedded. For example,
* 'e-elearning' if the media is included as an activity
* of the course
*
*/
contentBlock?: ContentBlock,
type: ImageType,
id: string,
action: MediaActionForImage,
time: number,
meta?: any
}
export enum ImageType {
Image = "image"
}
export enum AudioVideoType {
Audio = "audio",
Video = "video"
}
export type AudioVideoProperties = {
/**
* The block or module where the media is embedded. For example,
* 'e-elearning' if the the video or audio is included as an activity
* of the course
*
*/
contentBlock?: ContentBlock,
type: AudioVideoType,
id: string,
action: MediaActionForVideo,
time: number
meta?: any
}
export type MediaProperties = ImageProperties | AudioVideoProperties
/**
* @internal
*/
export type InternalMediaProperties = MediaProperties & {
id_source: string
}
export type MediaData = {
name?: string
length: string, // video length in milliseconds //uint32
description?: string,
resolution?: string,
language?: Language
}
/**
* @internal
*/
export type InternalMediaData = MediaData & {
id_source: string //testMediaId
id: string //(type)_(id_source) == video_testMediaId
type: AudioVideoType // <video, audio>
}
export enum PageType {
View = "view",
Completed = "completed"
}
export interface PageProperties {
// type: PageType,
path: string,
title?: string,
duration?: number
meta?: any
}
export enum NudgeAction {
Block = "block",
Discard = "discard",
Open = "open",
}
export enum NudgeResponseType {
Push = 'push_notification',
InApp = 'in_app_message'
}
export interface NudgeResponseProperties {
nudge_id: number,
type: NudgeResponseType,
response: {
action: NudgeAction
},
resolved_action: any
}
/**
* This interface represents the information related to
* a search
*/
export interface SearchProperties {
/**
* The block or module where the search was peformed. For example,
* 'e-commerce' if the user made a serch in the marketplace section,
* or 'e-elearning' is the search was performed in the courses/classes
* section
*/
contentBlock?: ContentBlock,
/**
* Free text introduced by the user to search
*/
query: string,
/**
* If the search results are shown paginaged, or with infinite scroll,
* this field represent the number of page/subset the current result_ids
* belongs to
*/
page: number,
/**
* Current list of items IDs obtained for this search and page.
* If the user have pressed in a new page number, of scroll down
* and the web automatically retrieved new item, include here only
* the new ones
*/
results_ids?: Array<string | TypedItem> // list of result ids
/**
* If the search engine allow to select specific value to search
* in a selectable list, include here an object whose keys are the
* attributes to search, and the values the actual values that must
* match
*/
filter?: SearchFilter
/**
* Any other additional information to be available in the logs
*/
meta?: any
}
/**
* @internal
*
* checkers do not support Omit, which will be usefull here to remove the result_ids list
*/
export interface InternalSearchProperties {
id: string,
results_list: Array<TypedItem>,
contentBlock?: ContentBlock,
query: string,
page: number,
filter?: SearchFilter
meta?: any
}
export enum EducationLevel {
Primary = "primary",
LowerSecondary = "lower_secondary",
UpperSecondary = "upper_secondary",
NonTertiary = "non_tertiary",
Tertiary = "tertiary",
Bachelors = "bachelors",
Masters = "masters",
Doctorate = "doctorate"
}
export interface UserProperties {
name?: string,
organization?: string,
experience?: string,
region_state?: string,
city?: string,
workplace?: string,
profession?: string,
zipcode?: string,
/**
* ISO 8601 string (ie.: +0200)
* Generated automatically by the SDK
*/
timezone?: string,
/**
* country which the user is, represented as
* two characters in ISO 3166
*/
country?: Country,
/**
* iSO 639-1
*/
language?: Language,
education_level?: EducationLevel
}
/**
* @internal
*/
export interface InternalUserProperties extends UserProperties {
id: string,
organization_id?: string,
organization_name?: string,
}
export enum TrackTypes {
ReferenceGuide = "reference_guide",
}
export enum TrackActions {
ViewList = 'view_list',
ViewItem = 'view_item',
ExternalLink = 'external_link'
}
export type TrackProperties = {
action: TrackActions.ViewList | TrackActions.ExternalLink,
meta?: any
} | {
action: TrackActions.ViewItem,
item_id: string,
meta?: any
}
/**
* @internal
*/
export type TrackPropertiesInternal = TrackProperties & {
type: TrackTypes,
}
export enum RateType {
App = "app",
Exam = "exam",
Media = "media",
Order = "order"
}
export interface RateProperties {
rate_value: number,
type: RateType,
subject_id: string
}