doum
8 天以前 d5810177a4e77ea273971e51dd150bd84906de6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
export interface IErrorMessage {
    /** the error code */
    errorCode?: string;
    /** the error message */
    errorMessage?: string;
}
export interface ICallbackOption<S> {
    onSuccess?(data: S): void;
    onFail?(err: IErrorMessage): void;
    onCancel?(err: IErrorMessage): void;
}
export declare type IJSBridge = (method: string, params: any) => Promise<any>;
export declare type ICommonAPI<S, T> = (params: S & ICallbackOption<T>) => Promise<T>;
export interface IInvokeAPIConfigMap {
    [platform: string]: IAPIConfig | undefined;
}
export interface IAPIConfig {
    /** the minSupport version about the API */
    vs: string | {
        [platformSub: string]: string;
    };
    invokeName?: string;
    /**
     * 应返回新的转换后的参数,不应直接修改传入的变量
     */
    paramsDeal?: (params: any) => any | Promise<any>;
    /**
     * 应返回新的转换后的参数,不应直接修改传入的变量
     */
    resultDeal?: (res: any) => any;
}
export interface IJSBridgeMap {
    [platform: string]: IJSBridge | undefined;
}
export interface IInvokeAPIConfigMapByMethod {
    [method: string]: IInvokeAPIConfigMap | undefined;
}
export declare function isFunction(param: any): boolean;
/**
 * when origin >= target ,return true
 * 关于为什么没有跟otherApi保持一致,主要是当初因为otherApi里的方法是复制旧版jsapi的,有一定缺陷
 * 但是担心线上环境利用了缺陷来做逻辑,所以没有保持一致使用同一个方法
 * TODO: 但其实另起方法太冗余,以及丑陋,后续还是需要整个统一掉
 * @param origin
 * @param target
 */
export declare function compareVersion(origin: string, target: string): boolean;
/**
 * 客户端错误码
 */
export declare enum ERROR_CODE {
    cancel = "-1",
    not_exist = "1",
    no_permission = "7"
}
export declare enum ENV_ENUM {
    pc = "pc",
    android = "android",
    ios = "ios",
    gdtPc = "gdtPc",
    /**
     * gdt Android mpaas 容器
     */
    gdtAndroid = "gdtAndroid",
    /**
     * gdt Ios mpaas 容器
     */
    gdtIos = "gdtIos",
    /**
     * gdt Android 标准 容器
     */
    gdtStandardAndroid = "gdtStandardAndroid",
    /**
     * gdt Ios 标准 容器
     */
    gdtStandardIos = "gdtStandardIos",
    notInDingTalk = "notInDingTalk",
    windows = "windows",
    mac = "mac",
    harmony = "harmony"
}
export declare enum ENV_ENUM_SUB {
    mac = "mac",
    win = "win",
    noSub = "noSub"
}
export declare enum APP_TYPE {
    WEB = "WEB",
    MINI_APP = "MINI_APP",
    WEEX = "WEEX",
    WEBVIEW_IN_MINIAPP = "WEBVIEW_IN_MINIAPP",
    WEEX_WIDGET = "WEEX_WIDGET"
}
export interface IENV {
    /** current platform (iOS or Android or PC or NotInDingTalk) */
    platform: ENV_ENUM;
    /** current sub platform (support mac & win) */
    platformSub?: ENV_ENUM_SUB;
    /** current client version */
    version?: string;
    /** @deprecated recommend use navigator.language to get current language */
    language?: string;
    /** current appType (web or eapp or weex) */
    appType: APP_TYPE;
    [key: string]: any;
}
export interface IConfigParams {
    jsApiList?: string[];
    [key: string]: any;
}
export interface IDevConfigParams {
    /** 是否开启调试模式 */
    debug?: boolean;
    /** 是否校验Api是否支持等 */
    isAuthApi?: boolean;
    /** 废除兼容性处理 */
    isDisableDeal?: boolean;
    /** 部分接口废除兼容性处理 */
    disbaleDealApiWhiteList?: string[];
    /** 接口层面开启兼容性处理,优先级大于废除逻辑 */
    forceEnableDealApiFnMap?: {
        [apiName: string]: (params: any) => boolean;
    };
    onBeforeInvokeAPI?: (data: {
        invokeId: string;
        method: string;
        startTime: number;
        params: any;
    }) => void;
    onAfterInvokeAPI?: (data: {
        invokeId: string;
        method: string;
        params: any;
        payload: any;
        duration: number;
        startTime: number;
        isSuccess: boolean;
    }) => void;
    extraPlatform?: IPlatformConfig;
}
export interface IEvent {
    preventDefault: () => void;
}
export declare enum LogLevel {
    INFO = 1,
    WARNING = 2,
    ERROR = 3
}
export interface ILog {
    level: LogLevel;
    text: any[];
    time: Date;
}
export declare type ILogFn = (option: ILog) => void;
export interface IPlatformConfig {
    platform: string;
    authMethod: string;
    authParamsDeal?: (params: object) => object;
    bridgeInit: () => Promise<IJSBridge>;
    event?: {
        on: (type: string, handler: (e: IEvent) => void) => void;
        off: (type: string, handler: (e: IEvent) => void) => void;
    };
}
export interface ICheckJsApiParams {
    jsApiList?: string[];
}
export interface ICheckJsApiResult {
    [jsApi: string]: boolean;
}
export declare type ICheckJsApiFn = (params: ICheckJsApiParams) => Promise<ICheckJsApiResult>;
export interface IUNCore {
    /** 当config权限校验成功时触发readyCallback */
    ready: (readyCallback: () => void) => void;
    /** 当config权限校验成功时触发readyCallback */
    error: (callback: (err: any) => void) => void;
    /** 配置权限校验参数, 即可启动校验,启动校验成功后可以让本没有权限的接口获取权限,如果你的域名是白名单或者调用的接口不需要校验,可不用调用此接口 */
    config: (configParams: IConfigParams) => void;
    /** 配置开发选项 */
    devConfig: (devConfigParams: IDevConfigParams) => void;
    /** 推荐使用on绑定方法, 替代原本document的方式 */
    on: (methodName: string, listener: (e: IEvent | any) => void) => void;
    /** 推荐使用off解绑方法,替代document的方式 */
    off: (methodName: string, listener: (e: IEvent | any) => void) => void;
    /** 当前运行时的环境变量 */
    env: IENV;
    /**
     * 提供检测jsapi能力的接口
     * @description 本接口原理依赖于 JSAPI 的静态支持版本数据,故存在一定的误差
     * @deprecated 移动端上推荐使用 plugin/checkJsApi.ts 来检测真实环境下的支持情况
     */
    checkJsApi: ICheckJsApiFn;
    /** 直接通过method名调用jsapi,新的接口基本不存在多端不一致的问题,可以使用此接口代替。注意:但如果直接调用旧的jsapi接口,且没有引入对应接口库,将不会对入参出参进行兼容操作 */
    _invoke: (method: string, params?: any) => Promise<any>;
}
export interface IConfigCoreMap {
    [platform: string]: IPlatformConfig | undefined;
}
export interface IApiMiddlewareContext {
    method: string;
    params: any;
    isAuthApi: boolean;
    invokeName?: string;
    callParams?: any;
    JSBridge?: IJSBridge;
    apiConfig?: IAPIConfig;
}
export declare type IApiMiddlewareNextFn = () => Promise<any>;
export declare type IApiMiddlewareFn = (context: IApiMiddlewareContext, next: IApiMiddlewareNextFn) => Promise<any>;