sdkLib.d.ts 5.8 KB

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