@datafinder/embed-sdk
Version:
Embed SDK for DataFinder
387 lines (386 loc) • 10.6 kB
TypeScript
import { ALLOW_EMBED_PAGES } from '../constants';
export interface Payload {
type: string;
data?: any;
[key: string]: any;
}
/** 转发接口参数格式 */
export interface RequestPayload {
url: string;
method: string;
params?: Record<string, any>;
body?: Record<string, any>;
}
/**
* 比较关系
*/
export declare enum EAttrOp {
EQ = "=",
/**
* 不等于不含 null
*/
NE = "!=",
/**
* 不等于含 null
*/
NEQ_CONTAIN_NULL = "not_equal_contain_null",
/**
* 历史原因:string类型要新增一个 不等于不含null
* 不等于不含 null(analysis base string 的 != 是含null的,因此需要增加一个 not_equal_not_contain_null)
*/
NEQ_NOT_CONTAIN_NULL = "not_equal_not_contain_null",
GT = ">",
LT = "<",
GE = ">=",
LE = "<=",
/**
* 包含
*/
CONTAIN = "contain",
/**
* 自定义包含
*/
CUSTOM_CONTAIN = "custom_contain",
/**
* 不包含
* sass 中的语义是 不包含(含null)
* 私有化 中的语义是 不包含(不含null)
*/
NOT_CONTAIN = "not_contain",
/**
* 不包含不含null
* sass 环境
*/
NOT_CONTAIN_NOT_CONTAIN_NULL = "not_contain_not_contain_null",
/**
* 不包含含null
* 私有化环境,NOT_CONTAIN
*/
NOT_CONTAIN_CONTAIN_NULL = "not_contain_contain_null",
/**
* 包含
*/
LIST_CONTAIN = "list_contain",
/**
* 不包含
*/
LIST_NOT_CONTAIN = "list_not_contain",
/**
* 范围
*/
BETWEEN = "between",
/**
* 固定范围
*/
TIME_FIXED = "time_fixed",
/**
* 不在固定范围
*/
TIME_NOT_FIXED = "time_not_fixed",
/**
* 在当前时间
*/
TIME_RELATIVE_TO_TODAY = "time_relative_to_today",
/**
* 不在当前时间
*/
TIME_NOT_RELATIVE_TO_TODAY = "time_not_relative_to_today",
/**
* 在今天和
*/
TIME_WITH_TODAY = "time_with_today",
/**
* 不在今天和
*/
TIME_NOT_WITH_TODAY = "time_not_with_today",
/**
* 在事件发生(仅作为事件过滤条件时才有)
*/
TIME_RELATIVE_TO_EVENT = "time_relative_to_event",
/**
* 不在事件发生(仅作为事件过滤条件时才有)
*/
TIME_NOT_RELATIVE_TO_EVENT = "time_not_relative_to_event",
/**
* 为空
*/
IS_NULL = "is_null",
/**
* 不为空
*/
IS_NOT_NULL = "is_not_null",
/**
* 正则匹配
*/
MATCH = "match",
/**
* 正则不匹配
*/
NOT_MATCH = "not_match",
/**
* 时间
*/
TIME = "time"
}
/**
* 允许嵌出的页面
*/
export declare type EmbedPage = (typeof ALLOW_EMBED_PAGES)[number];
export declare type IndicatorType = 'events' | 'event_users' | 'events_per_user' | 'uv_per_au' | 'pv_per_au' | 'sum' | 'avg' | 'per_user' | 'pct' | 'sum_per_au' | 'min' | 'max' | 'distinct' | 'distinct_user_attr';
export declare enum MetaPropertyType {
/**
* 用户属性
*/
PROFILE = "profile",
/**
* 事件公共属性
*/
COMMON_PARAM = "common_param",
/**
* 事件一般属性
*/
EVENT_PARAM = "event_param",
/**
* 业务维度属性
*/
ITEM_PARAM = "item_param",
/**
* 用户标签
*/
USER_TAG = "user_tag",
/**
* CDP 的用户标签,私有化联合部署时用到。
* 对于调用方来说无感知,会和 user_tag 一起请求。
*/
CDP_TAG = "cdp_tag",
/**
* 用户分群。
* 注意,通常要和 CDP_COHORT 一起使用
*/
COHORT = "cohort",
/**
* 私有化的用户属性。
* 一个坑点。
* TODO:给它抹平干掉 @huangtianyu
*/
USER_PROFILE = "user_profile",
/**
* 脱离事件的属性
*/
PARAM = "param",
/**
* CDP 的用户分群,私有化联合部署时用到。
*/
CDP_COHORT = "cdp_cohort",
/**
* 自定义属性分组
*/
CUSTOM_PROPERTY_GROUP = "custom_property_group"
}
export declare enum MetaPropertyComposeType {
ORIGIN = "origin",
/**
* 表示是虚拟属性,虚拟属性在属性列表中需要加个 ICON 区分
*/
VIRTUAL = "virtual",
/**
* 仅 Tea-next 使用的
*/
PROFILE = "profile",
/**
* 仅维度表使用
*/
ITEM = "item"
}
export interface EmbedRenderOptions {
/**
* 渲染 Finder 应用的容器
*/
targetNode: HTMLElement;
/**
* 嵌入的 Finder 应用 ID
*/
appId?: number;
/**
* 嵌入的 Finder 查询快照 ID
*/
resultId?: string;
/**
* 嵌入的 Finder 项目 ID
*/
projectId?: number;
/**
* 引入页面的 Host
*
* 例如你需要接入 xxx.datarangers-onpremise.volces.com 提供的 Finder 页面,请传入 host: "//xxx.datarangers-onpremise.volces.com"
*
* ?: 如置空则默认为同域,并使用当前环境的 host
*/
host?: string;
/**
* Finder 应用的路径。默认是 `'/datafinder'`
*/
basePath?: string;
/**
* 嵌入页面是否跨域。默认会根据传入的 host 自动判断
*/
crossOrigin?: boolean;
/**
* 如传入了 dorToken,则会通过 dorToken 作为鉴权方式渲染页面
*/
dorToken?: string;
/**
* 接入方来源
*/
from?: string;
/**
* 是否需要 minibase 的重定向
*/
needsMinibaseRedirect?: boolean;
/**
* 嵌入页面中 Finder 请求代理的接口地址,在 crossOrigin 为 true 时使用
*/
proxyPath?: string;
/**
* 嵌入的 Finder 模块页面
*
* 如传入了 reportId,则默认为 report 页面。否则默认为 dashboard。
*/
page?: EmbedPage | string;
/**
* 看板 ID
*
* - 在看板相关页面中生效
*/
dashboardId?: string;
/**
* 图表 ID
*
* - 在图表相关页面中生效
*/
reportId?: string;
/**
* 筛选器 ID
*
* - 在看板相关页面中生效
*/
filterId?: number;
/**
* 自定义嵌入页面内请求的 headers
*/
customRequestHeaders?: Record<string, string>;
/**
* 嵌入页面的额外 query params
*/
embedQueryParams?: {
hideTitleAndOps?: boolean;
hideBelongTo?: boolean;
hideFilter?: boolean;
showPeriod?: boolean;
showFilterButton?: boolean;
[key: string]: any;
};
/**
* 渲染 iframe 节点时的自定义 attrs。
*
* 默认为 `{ width: '100%', height: '100%', frameBorder: '0' }`
*/
iframeOptions?: Omit<HTMLIFrameElement, 'src'>;
/**
* 嵌入页面渲染成功时的回调
*/
onSuccess?: () => void;
/**
* 嵌入页面渲染失败时的回调
*/
onError?: (reason: string) => void;
interfaceSetting?: {
/** 是否开启手动查询,不传则沿用租户的配置 */
manualCompute?: boolean;
/** 标题栏 */
analysisHeader?: {
/** 标题及右侧操作按钮 */
title?: IModuleStatus;
operators?: IModuleStatus;
} & IModuleStatus;
queryModules?: {
/** 查询配置区左上角操作按钮 */
leftOperators?: {
regionSelect?: IModuleStatus;
sceneSelect?: IModuleStatus;
sessionSelect?: IModuleStatus;
subjectSelect?: IModuleStatus;
analysisSubjectSelect?: IModuleStatus;
filterSampleSelect?: IModuleStatus;
} & IModuleStatus;
/** 查询配置区右上角刷新按钮 */
refreshButton?: IModuleStatus;
/** 事件选择区配置 */
event?: {
/** 配置的操作符将会被过滤掉 */
filterIndicators?: IndicatorType[];
/** 过滤特定属性分组,支持多个维度,只要命中一个规则,就会被禁用 */
filterAttrGroups?: {
/** 按属性类型过滤 */
property_type?: MetaPropertyType[];
/** 按名称过滤 */
property_compose_type?: MetaPropertyComposeType[];
/** 按名称过滤 */
name?: string[];
};
/** 禁用算子的提示文案 */
filterIndicatorsTooltip?: string;
/** 禁用属性分组的提示文案 */
filterAttrGroupsTooltip?: string;
/** 属性分组白名单,支持多个维度,只有命中规则才会可选 */
attrGroupsWhiteList?: {
/** 按属性类型过滤 */
property_type?: MetaPropertyType[];
/** 按名称过滤 */
property_compose_type?: MetaPropertyComposeType[];
/** 按名称过滤 */
name?: string[];
};
};
filters: {
readonly?: boolean;
tooltip?: string;
};
generalGroupBy: any;
};
analysisConfig?: {
/**
* 一般指标 + 组合指标个数上限
*/
MAX_EVENT_COUNT?: number;
/**
* 全局筛选个数上限
*/
MAX_GLOBAL_FILTER_COUNT?: number;
/**
* 属性分组个数上限
*/
MAX_GROUP_COUNT?: number;
};
};
/**
* 获得原始的链接,而不是展示嵌出链接
*/
showOriginUrl?: boolean;
locale: 'en_US' | 'zh_CN' | 'ja_JP';
}
export interface IModuleStatus<T = any> {
hide?: boolean;
disabled?: boolean;
value?: T;
}
export interface FilterType {
/** 本期只支持配置属性过滤 */
filter?: {
property_type: MetaPropertyType;
name: string;
preset?: boolean;
};
operation: EAttrOp;
operationValues: string[];
}