sdkLib.d.ts 6.8 KB

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