@kbapp/js-bridge 1.0.6-alpha.0 → 1.0.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ {
2
+ "enabledMcpjsonServers": [
3
+ "wechat"
4
+ ],
5
+ "enableAllProjectMcpServers": true
6
+ }
@@ -27,7 +27,7 @@ function B(e) {
27
27
  (!i || i === "success") && (i = "success", (l = n.success) == null || l.call(n, t));
28
28
  }, c = (t) => {
29
29
  var l;
30
- (!i || i === "error") && (i = "error", (l = n.fail) == null || l.call(n, t));
30
+ i || (i = "error", (l = n.fail) == null || l.call(n, t));
31
31
  };
32
32
  n.timeout && setTimeout(() => {
33
33
  c(d.TIMEOUT);
@@ -1,8 +1,9 @@
1
1
  import { wrapAsync as n } from "../utils/wrap-async.js";
2
2
  import { runBridgeApiResponse as r } from "../core/index.js";
3
3
  const m = n(async (t) => {
4
- const { kbKey: p, ...e } = t, { data: a } = await r({
4
+ const { kbKey: o, ...e } = t, { data: a } = await r({
5
5
  name: "OpenActRequest",
6
+ timeout: 5e3,
6
7
  params: {
7
8
  type: 51,
8
9
  data: e
@@ -1,11 +1,12 @@
1
1
  import { decorateCacheAsyncResult as e } from "../utils/promise-cache.js";
2
- import { runBridgeApiResponse as p } from "../core/index.js";
3
- import { wrapAsync as r } from "../utils/wrap-async.js";
2
+ import { runBridgeApiResponse as t } from "../core/index.js";
3
+ import { wrapAsync as p } from "../utils/wrap-async.js";
4
4
  class n {
5
5
  }
6
- const m = r(
7
- e(() => p({
6
+ const m = p(
7
+ e(() => t({
8
8
  name: "OpenActRequest",
9
+ timeout: 5e3,
9
10
  params: {
10
11
  type: 35,
11
12
  data: {}
@@ -1,24 +1,25 @@
1
- import { runBridgeApiResponse as c } from "../core/index.js";
1
+ import { runBridgeApiResponse as p, runBridgeApi as g } from "../core/index.js";
2
2
  import { wrapAsync as i } from "../utils/wrap-async.js";
3
- class d {
3
+ class l {
4
4
  }
5
- const g = i(async () => (await c({
5
+ const u = i(async () => (await p({
6
6
  name: "OpenActRequest",
7
+ timeout: 5e3,
7
8
  params: { type: 31, data: { requireLogin: !1 } }
8
- })).data || null), r = /* @__PURE__ */ (() => {
9
- const e = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ (() => {
9
+ })).data || null), a = /* @__PURE__ */ (() => {
10
+ const e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ (() => {
10
11
  let t;
11
- const n = (o) => {
12
+ const r = (o) => {
12
13
  t = setTimeout(async () => {
13
- const s = await g();
14
+ const s = await u();
14
15
  if (!s)
15
- return n(++o);
16
- e.forEach((p) => p(s)), e.clear();
16
+ return r(++o);
17
+ e.forEach((c) => c(s)), e.clear();
17
18
  }, ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(o));
18
19
  };
19
20
  return {
20
21
  start() {
21
- t && clearTimeout(t), e.size > 0 && n(0);
22
+ t && clearTimeout(t), e.size > 0 && r(0);
22
23
  },
23
24
  stop() {
24
25
  t && clearTimeout(t);
@@ -32,28 +33,24 @@ const g = i(async () => (await c({
32
33
  },
33
34
  /** 移除监听 */
34
35
  removeTask(t) {
35
- e.delete(t), e.size === 0 && a.stop();
36
+ e.delete(t), e.size === 0 && n.stop();
36
37
  },
37
38
  /** 触发定时检测是否登录成功任务 */
38
39
  triggerCheckTask() {
39
- a.start();
40
+ n.start();
40
41
  }
41
42
  };
42
- })(), l = i(async () => {
43
- r.triggerCheckTask(), c({
43
+ })(), m = i(async () => {
44
+ a.triggerCheckTask(), await g({
44
45
  name: "OpenActRequest",
45
- params: { type: 31, data: { requireLogin: !0 } },
46
- success(e) {
47
- var a;
48
- (a = e.data) != null && a.userId && r.triggerCheckTask();
49
- }
46
+ params: { type: 31, data: { requireLogin: !0 } }
50
47
  });
51
- }), m = (e) => (r.addTask(e), r.triggerCheckTask(), () => {
52
- r.removeTask(e);
48
+ }), f = (e) => (a.addTask(e), a.triggerCheckTask(), () => {
49
+ a.removeTask(e);
53
50
  });
54
51
  export {
55
- d as AppLoginInfo,
56
- g as getAppLoginInfo,
57
- m as onLoopCheckAppLogin,
58
- l as triggerAppLogin
52
+ l as AppLoginInfo,
53
+ u as getAppLoginInfo,
54
+ f as onLoopCheckAppLogin,
55
+ m as triggerAppLogin
59
56
  };
@@ -1,11 +1,15 @@
1
- function n(r) {
2
- let e;
3
- return function(...t) {
4
- return e || (e = r(...t), Promise.resolve(e).catch(() => {
5
- e = void 0;
6
- }), e);
1
+ function s(r) {
2
+ const e = /* @__PURE__ */ new Map();
3
+ return function(...c) {
4
+ const t = JSON.stringify(c);
5
+ if (e.has(t))
6
+ return e.get(t);
7
+ const n = r(...c);
8
+ return e.set(t, n), Promise.resolve(n).catch(() => {
9
+ e.delete(t);
10
+ }), n;
7
11
  };
8
12
  }
9
13
  export {
10
- n as decorateCacheAsyncResult
14
+ s as decorateCacheAsyncResult
11
15
  };
@@ -69,7 +69,7 @@ export declare function runBridgeApiResponse<Result = void>(params: {
69
69
  type: number;
70
70
  data?: any;
71
71
  };
72
- /** 设置超时时间 */
72
+ /** 设置超时时间, 单位毫秒 */
73
73
  timeout?: number;
74
74
  /** 执行成功 */
75
75
  success?: (result: Result) => void;
@@ -36,6 +36,6 @@ const onTapLogin = decorateAppVersionSupport({ minVersion: 80711 }, () => {
36
36
  })
37
37
  ```
38
38
  */
39
- export declare function decorateAppVersionSupport<Callback extends (...params: any[]) => any>(config: {
39
+ export declare function decorateAppVersionSupport<T extends (...args: any[]) => any>(config: {
40
40
  minVersion: number;
41
- }, callback: Callback): (...params: Parameters<Callback>) => Promise<any>;
41
+ }, callback: T): (...params: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
3
- * @description 缓存promise结果
2
+ * @description 缓存 Promise 结果(支持参数感知)
3
+ * 只有当参数完全一致时才返回缓存,参数变动则重新发起调用
4
4
  */
5
5
  export declare function decorateCacheAsyncResult<CB extends (...params: any[]) => any>(cb: CB): (...params: Parameters<CB>) => ReturnType<CB>;
package/dist/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var V;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const s=e[i];s!=null&&(t[i]=Object.prototype.toString.call(s)==="[object Object]"?A(s):s)}),t}const p=class p{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};p.UNKNOWN=new p({errorCode:1e3,errorMsg:"未知错误"}),p.UNSUPPORTED_VERSION=new p({errorCode:1001,errorMsg:"当前开吧版本不支持"}),p.TIMEOUT=new p({errorCode:1002,errorMsg:"执行超时"}),p.UNSUPPORTED_BRIDGE_ENV=new p({errorCode:1003,errorMsg:"请在开吧app内执行"});let f=p;const L=()=>{const e=(a,o,n)=>{var c="";typeof o=="function"&&(n=o,o={});var u={data:o===void 0?null:o};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],o=setInterval(()=>{t()&&(clearInterval(o),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var s={default:void 0,callHandler:function(a,o,n){return t()?e(a,o,n):i(a,o,n)},register:function(a,o,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){s.callHandler("_dsb.dsinit")},0)),typeof o=="object"?c._obs[a]=o:c[a]=o},registerHandler:function(a,o){this.register(a,o,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:s,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],E=this._dsaf[n.method],C=function(P,b){u.data=P.apply(b,c),s.callHandler("_dsb.returnValue",u)},U=function(P,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,s.callHandler("_dsb.returnValue",u)}),P.apply(b,c)};if(h)C(h,this._dsf);else if(E)U(E,this._dsaf);else{var O=n.method.split(".");if(O.length<2)return;var B=O.pop(),D=O.join("."),T=this._dsf._obs,v=T[D]||{},w=v[B];if(w&&typeof w=="function"){C(w,v);return}if(T=this._dsaf._obs,v=T[D]||{},w=v[B],w&&typeof w=="function"){U(w,v);return}}}};for(var o in a)window[o]=a[o]}}(),s},S=(e=>/(kb)/i.test(e)?L():{registerHandler(t,i){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,s){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((t,i)=>{var s,a,o;try{S.registerHandler(e.name,e.handler),(s=e.success)==null||s.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(o=e.complete)==null||o.call(e)}});function g(e){const t=i=>{let s;const a=n=>{var c;(!s||s==="success")&&(s="success",(c=i.success)==null||c.call(i,n))},o=n=>{var c;(!s||s==="error")&&(s="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{o(f.TIMEOUT)},i.timeout);try{S.callHandler(i.name,i.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}a(c)})}catch(n){o(n)}};return new Promise((i,s)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var o,n;(o=e.success)==null||o.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var o,n;(o=e.fail)==null||o.call(e,a),(n=e.complete)==null||n.call(e),s(a)}})})}function l(e){S.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const s=i[0]||{},{success:a,fail:o,complete:n,...c}=s;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new f({errorCode:f.UNKNOWN.errorCode,errorMsg:String(u)});throw o==null||o(h),h}finally{n==null||n()}}}function H(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class j{}const k=d(H(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),m=d(async e=>(await k()).vcode>=e.minVersion);function F(e,t){return(...i)=>m({minVersion:e.minVersion}).then(s=>s?t(...i):Promise.reject(new f({errorCode:f.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const W=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),J=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),I={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Q=d(e=>(Object.assign(I,e),R({name:"getPermissionUsage",handler(t,i){i(I[t.permission])}}))),G=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),K=d(async e=>{const{kbKey:t,...i}=e,{data:s}=await g({name:"OpenActRequest",params:{type:51,data:i}});return s});var N=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(N||{});class M{constructor(){this.textMin=0,this.textMax=1e3,this.imageMax=9,this.imageMin=0,this.audioRqr=1,this.videoRqr=1,this.mediaRqr=2,this.streetRqr=1}}function $(e){const t=new M;return e&&Object.keys(e).forEach(i=>{t[i]=e[i]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:t.audioRqr!==2,image:t.imageMax!==0,video:t.videoRqr!==2,address:t.streetRqr!==2,asset_video:t.mediaRqr!==2,audio_must:t.audioRqr===3,image_must:t.imageMin>0,asset_video_must:t.mediaRqr===3,max_image_count:t.imageMax,min_image_count:t.imageMin,video_must:t.videoRqr===3,text_must:t.textMin>0,content_max_length:t.textMax,content_min_length:t.textMin}}const z=d(async e=>g({name:"OpenActRequest",params:{type:13,data:(e==null?void 0:e.postRule)??{}}}).then(({data:t})=>{const{pic:i,...s}=t;return{images:i,...s}})),X=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),x=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),ee=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),te=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ie=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),_="SHARE_EVENT_NAME";class re{}const oe=d(e=>R({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(_)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),se=d(async e=>{window.dispatchEvent(new Event(_)),l({name:"OpenActRequest",params:{type:58,data:e}})});function ae(e){return window.addEventListener(_,e),()=>{window.removeEventListener(_,e)}}const ce=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),de=d(()=>g({name:"OpenActRequest",params:{type:72}})),ue=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class le{}const q=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const s=a=>{i=setTimeout(async()=>{const n=await q();if(!n)return s(++a);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(a))};return{start(){i&&clearTimeout(i),e.size>0&&s(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),fe=d(async()=>{y.triggerCheckTask(),g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}},success(e){var t;(t=e.data)!=null&&t.userId&&y.triggerCheckTask()}})}),pe=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=j,r.AppLoginInfo=le,r.AppShareModel=re,r.BridgeCode=f,r.IS_KB_APP_ENV=G,r.KbRequirement=N,r.NoteThreadPostRule=M,r.checkForNewVersion=W,r.closeWebView=J,r.decorateAppVersionSupport=F,r.defineAppShareModel=oe,r.defineAppSharePanelState=ce,r.defineBridgeCallback=R,r.definePermissionUsage=Q,r.generateKBSign=K,r.generatePostEditorParamsByThreadPostRule=$,r.getAppBaseInfo=k,r.getAppLoginInfo=q,r.getAppSubscribeNotifyStatus=de,r.isAppVersionSupport=m,r.onAppSharePanelShow=ae,r.onLoopCheckAppLogin=pe,r.openAppSharePanel=se,r.openAppSubscribeNotifySettings=ue,r.openPostEditor=z,r.reportDAEvent=X,r.runAction=Y,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=Z,r.saveVideoToLocal=x,r.scanQRCode=ee,r.setScreenOrientation=te,r.setWebViewTitle=ne,r.shareImage=ie,r.triggerAppLogin=fe,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var V;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const i={};return Object.keys(e).forEach(t=>{const o=e[t];o!=null&&(i[t]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),i}const p=class p{constructor(i){this.errorCode=i.errorCode,this.errorMsg=i.errorMsg}};p.UNKNOWN=new p({errorCode:1e3,errorMsg:"未知错误"}),p.UNSUPPORTED_VERSION=new p({errorCode:1001,errorMsg:"当前开吧版本不支持"}),p.TIMEOUT=new p({errorCode:1002,errorMsg:"执行超时"}),p.UNSUPPORTED_BRIDGE_ENV=new p({errorCode:1003,errorMsg:"请在开吧app内执行"});let f=p;const L=()=>{const e=(s,a,n)=>{var c="";typeof a=="function"&&(n=a,a={});var u={data:a===void 0?null:a};if(typeof n=="function"){var g="dscb"+window.dscb++;window[g]=n,u._dscbstub=g}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+s,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+s,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},i=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,t=(()=>{const s=[],a=setInterval(()=>{i()&&(clearInterval(a),s.forEach(n=>{e.apply(window,n)}),s.length=0)},500);return(...n)=>{s.push(n)}})();var o={default:void 0,callHandler:function(s,a,n){return i()?e(s,a,n):t(s,a,n)},register:function(s,a,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof a=="object"?c._obs[s]=a:c[s]=a},registerHandler:function(s,a){this.register(s,a,!0)}};return function(){if(!window._dsf){var s={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},g=this._dsf[n.method],E=this._dsaf[n.method],U=function(T,b){u.data=T.apply(b,c),o.callHandler("_dsb.returnValue",u)},B=function(T,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,o.callHandler("_dsb.returnValue",u)}),T.apply(b,c)};if(g)U(g,this._dsf);else if(E)B(E,this._dsaf);else{var O=n.method.split(".");if(O.length<2)return;var C=O.pop(),D=O.join("."),P=this._dsf._obs,y=P[D]||{},w=y[C];if(w&&typeof w=="function"){U(w,y);return}if(P=this._dsaf._obs,y=P[D]||{},w=y[C],w&&typeof w=="function"){B(w,y);return}}}};for(var a in s)window[a]=s[a]}}(),o},S=(e=>/(kb)/i.test(e)?L():{registerHandler(i,t){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(i,t,o){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((i,t)=>{var o,s,a;try{S.registerHandler(e.name,e.handler),(o=e.success)==null||o.call(e),i()}catch(n){(s=e.fail)==null||s.call(e,n),t(n)}finally{(a=e.complete)==null||a.call(e)}});function h(e){const i=t=>{let o;const s=n=>{var c;(!o||o==="success")&&(o="success",(c=t.success)==null||c.call(t,n))},a=n=>{var c;o||(o="error",(c=t.fail)==null||c.call(t,n))};t.timeout&&setTimeout(()=>{a(f.TIMEOUT)},t.timeout);try{S.callHandler(t.name,t.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}s(c)})}catch(n){a(n)}};return new Promise((t,o)=>{i({name:e.name,params:A(e.params),timeout:e.timeout,success:s=>{var a,n;(a=e.success)==null||a.call(e,s),(n=e.complete)==null||n.call(e),t(s)},fail:s=>{var a,n;(a=e.fail)==null||a.call(e,s),(n=e.complete)==null||n.call(e),o(s)}})})}function l(e){S.callHandler(e.name,e.params,i=>{})}function d(e){return async function(...t){const o=t[0]||{},{success:s,fail:a,complete:n,...c}=o;try{const u=await Promise.resolve(e(c));return s==null||s(u),u}catch(u){const g=u!=null&&u.errorCode?u:new f({errorCode:f.UNKNOWN.errorCode,errorMsg:String(u)});throw a==null||a(g),g}finally{n==null||n()}}}function H(e){const i=new Map;return function(...t){const o=JSON.stringify(t);if(i.has(o))return i.get(o);const s=e(...t);return i.set(o,s),Promise.resolve(s).catch(()=>{i.delete(o)}),s}}class j{}const m=d(H(()=>h({name:"OpenActRequest",timeout:5e3,params:{type:35,data:{}}}))),k=d(async e=>(await m()).vcode>=e.minVersion);function F(e,i){return(...t)=>k({minVersion:e.minVersion}).then(o=>o?i(...t):Promise.reject(new f({errorCode:f.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const J=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),W=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),I={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Q=d(e=>(Object.assign(I,e),R({name:"getPermissionUsage",handler(i,t){t(I[i.permission])}}))),G=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),K=d(async e=>{const{kbKey:i,...t}=e,{data:o}=await h({name:"OpenActRequest",timeout:5e3,params:{type:51,data:t}});return o});var N=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(N||{});class M{constructor(){this.textMin=0,this.textMax=1e3,this.imageMax=9,this.imageMin=0,this.audioRqr=1,this.videoRqr=1,this.mediaRqr=2,this.streetRqr=1}}function $(e){const i=new M;return e&&Object.keys(e).forEach(t=>{i[t]=e[t]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:i.audioRqr!==2,image:i.imageMax!==0,video:i.videoRqr!==2,address:i.streetRqr!==2,asset_video:i.mediaRqr!==2,audio_must:i.audioRqr===3,image_must:i.imageMin>0,asset_video_must:i.mediaRqr===3,max_image_count:i.imageMax,min_image_count:i.imageMin,video_must:i.videoRqr===3,text_must:i.textMin>0,content_max_length:i.textMax,content_min_length:i.textMin}}const z=d(async e=>h({name:"OpenActRequest",params:{type:13,data:(e==null?void 0:e.postRule)??{}}}).then(({data:i})=>{const{pic:t,...o}=i;return{images:t,...o}})),X=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),x=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),ee=d(()=>h({name:"OpenActRequest",params:{type:26,data:{}}})),te=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ie=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),v="SHARE_EVENT_NAME";class re{}const oe=d(e=>R({name:"CommonShare",handler(i,t){window.dispatchEvent(new Event(v)),"onShareApp"in e&&e.onShareApp?t({type:12,data:e.onShareApp()}):t({type:12,data:e})}})),se=d(async e=>{window.dispatchEvent(new Event(v)),l({name:"OpenActRequest",params:{type:58,data:e}})});function ae(e){return window.addEventListener(v,e),()=>{window.removeEventListener(v,e)}}const ce=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),de=d(()=>h({name:"OpenActRequest",params:{type:72}})),ue=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class le{}const q=d(async()=>(await h({name:"OpenActRequest",timeout:5e3,params:{type:31,data:{requireLogin:!1}}})).data||null),_=(()=>{const e=new Set,i=(()=>{let t;const o=s=>{t=setTimeout(async()=>{const n=await q();if(!n)return o(++s);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(s))};return{start(){t&&clearTimeout(t),e.size>0&&o(0)},stop(){t&&clearTimeout(t)}}})();return{addTask(t){e.add(t)},removeTask(t){e.delete(t),e.size===0&&i.stop()},triggerCheckTask(){i.start()}}})(),fe=d(async()=>{_.triggerCheckTask(),await l({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}}})}),pe=e=>(_.addTask(e),_.triggerCheckTask(),()=>{_.removeTask(e)});r.AppBaseInfo=j,r.AppLoginInfo=le,r.AppShareModel=re,r.BridgeCode=f,r.IS_KB_APP_ENV=G,r.KbRequirement=N,r.NoteThreadPostRule=M,r.checkForNewVersion=J,r.closeWebView=W,r.decorateAppVersionSupport=F,r.defineAppShareModel=oe,r.defineAppSharePanelState=ce,r.defineBridgeCallback=R,r.definePermissionUsage=Q,r.generateKBSign=K,r.generatePostEditorParamsByThreadPostRule=$,r.getAppBaseInfo=m,r.getAppLoginInfo=q,r.getAppSubscribeNotifyStatus=de,r.isAppVersionSupport=k,r.onAppSharePanelShow=ae,r.onLoopCheckAppLogin=pe,r.openAppSharePanel=se,r.openAppSubscribeNotifySettings=ue,r.openPostEditor=z,r.reportDAEvent=X,r.runAction=Y,r.runBridgeApi=l,r.runBridgeApiResponse=h,r.saveImageToLocal=Z,r.saveVideoToLocal=x,r.scanQRCode=ee,r.setScreenOrientation=te,r.setWebViewTitle=ne,r.shareImage=ie,r.triggerAppLogin=fe,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.6-alpha.0",
6
+ "version": "1.0.8-alpha.0",
7
7
  "description": "开吧客户端桥接",
8
8
  "author": "along",
9
9
  "main": "./dist/umd/index.js",
@@ -21,11 +21,15 @@
21
21
  "scripts": {
22
22
  "build": "rm -rf ./dist && vite build",
23
23
  "dev": "npm run build && vite",
24
- "publish": "npm run build && npm publish"
24
+ "publish": "npm run build && npm publish",
25
+ "test": "vitest"
25
26
  },
26
27
  "devDependencies": {
28
+ "@vitest/ui": "^4.1.2",
29
+ "jsdom": "^29.0.1",
27
30
  "typescript": "^5.0.0",
28
31
  "vite": "^5.0.0",
29
- "vite-plugin-dts": "^3.0.0"
32
+ "vite-plugin-dts": "^3.0.0",
33
+ "vitest": "^4.1.2"
30
34
  }
31
- }
35
+ }
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'vitest/config'
2
+ import { resolve } from 'path'
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'jsdom', // 因为代码依赖 window 对象
8
+ setupFiles: ['./test/setup.ts'], // 设置文件用于模拟环境
9
+ coverage: {
10
+ reporter: ['text', 'json', 'html'],
11
+ },
12
+ },
13
+ resolve: {
14
+ alias: {
15
+ '@': resolve(__dirname, './src'),
16
+ },
17
+ },
18
+ })