@kbapp/market-partner-sdk 0.0.1 → 0.0.2

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.
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const u = class u {
2
- constructor(n) {
3
- this.errorCode = n.errorCode, this.errorMsg = n.errorMsg;
2
+ constructor(t) {
3
+ this.errorCode = t.errorCode, this.errorMsg = t.errorMsg;
4
4
  }
5
5
  };
6
6
  u.UNKNOWN = new u({
@@ -18,13 +18,13 @@ u.UNKNOWN = new u({
18
18
  });
19
19
  let l = u;
20
20
  const T = () => {
21
- const e = (r, s, t) => {
21
+ const e = (r, s, n) => {
22
22
  var a = "";
23
- typeof s == "function" && (t = s, s = {});
23
+ typeof s == "function" && (n = s, s = {});
24
24
  var c = { data: s === void 0 ? null : s };
25
- if (typeof t == "function") {
25
+ if (typeof n == "function") {
26
26
  var v = "dscb" + window.dscb++;
27
- window[v] = t, c._dscbstub = v;
27
+ window[v] = n, c._dscbstub = v;
28
28
  }
29
29
  if (c = JSON.stringify(c), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" + r, c)) : (window._dswk || navigator.userAgent.indexOf("_dsbridge") != -1) && (a = prompt("_flutterDsbridge=" + r, c)), a instanceof Promise)
30
30
  return a;
@@ -33,24 +33,24 @@ const T = () => {
33
33
  } catch {
34
34
  console.error("callHandle异常,JSON.parse错误");
35
35
  }
36
- }, n = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, i = (() => {
36
+ }, t = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, i = (() => {
37
37
  const r = [], s = setInterval(() => {
38
- n() && (clearInterval(s), r.forEach((t) => {
39
- e.apply(window, t);
38
+ t() && (clearInterval(s), r.forEach((n) => {
39
+ e.apply(window, n);
40
40
  }), r.length = 0);
41
41
  }, 500);
42
- return (...t) => {
43
- r.push(t);
42
+ return (...n) => {
43
+ r.push(n);
44
44
  };
45
45
  })();
46
46
  var o = {
47
47
  default: void 0,
48
48
  // for typescript
49
- callHandler: function(r, s, t) {
50
- return n() ? e(r, s, t) : i(r, s, t);
49
+ callHandler: function(r, s, n) {
50
+ return t() ? e(r, s, n) : i(r, s, n);
51
51
  },
52
- register: function(r, s, t) {
53
- var a = t ? window._dsaf : window._dsf;
52
+ register: function(r, s, n) {
53
+ var a = n ? window._dsaf : window._dsf;
54
54
  window._dsInit || (window._dsInit = !0, setTimeout(function() {
55
55
  o.callHandler("_dsb.dsinit");
56
56
  }, 0)), typeof s == "object" ? a._obs[r] = s : a[r] = s;
@@ -72,13 +72,13 @@ const T = () => {
72
72
  },
73
73
  dscb: 0,
74
74
  jsBridge: o,
75
- _handleMessageFromNative: function(t) {
76
- var a = JSON.parse(t.data), c = {
77
- id: t.callbackId,
75
+ _handleMessageFromNative: function(n) {
76
+ var a = JSON.parse(n.data), c = {
77
+ id: n.callbackId,
78
78
  complete: !0
79
- }, v = this._dsf[t.method], y = this._dsaf[t.method], N = function(E, S) {
79
+ }, v = this._dsf[n.method], y = this._dsaf[n.method], N = function(E, S) {
80
80
  c.data = E.apply(S, a), o.callHandler("_dsb.returnValue", c);
81
- }, P = function(E, S) {
81
+ }, m = function(E, S) {
82
82
  a.push(function(V, I) {
83
83
  c.data = V, c.complete = I !== !1, o.callHandler("_dsb.returnValue", c);
84
84
  }), E.apply(S, a);
@@ -86,17 +86,17 @@ const T = () => {
86
86
  if (v)
87
87
  N(v, this._dsf);
88
88
  else if (y)
89
- P(y, this._dsaf);
89
+ m(y, this._dsaf);
90
90
  else {
91
- var A = t.method.split(".");
91
+ var A = n.method.split(".");
92
92
  if (A.length < 2) return;
93
- var m = A.pop(), O = A.join("."), g = this._dsf._obs, _ = g[O] || {}, f = _[m];
94
- if (f && typeof f == "function") {
95
- N(f, _);
93
+ var O = A.pop(), P = A.join("."), g = this._dsf._obs, h = g[P] || {}, p = h[O];
94
+ if (p && typeof p == "function") {
95
+ N(p, h);
96
96
  return;
97
97
  }
98
- if (g = this._dsaf._obs, _ = g[O] || {}, f = _[m], f && typeof f == "function") {
99
- P(f, _);
98
+ if (g = this._dsaf._obs, h = g[P] || {}, p = h[O], p && typeof p == "function") {
99
+ m(p, h);
100
100
  return;
101
101
  }
102
102
  }
@@ -107,48 +107,48 @@ const T = () => {
107
107
  }
108
108
  })(), o;
109
109
  }, b = ((e) => /(kb)/i.test(e) ? T() : {
110
- registerHandler(n, i) {
110
+ registerHandler(t, i) {
111
111
  throw l.UNSUPPORTED_BRIDGE_ENV;
112
112
  },
113
- callHandler(n, i, o) {
113
+ callHandler(t, i, o) {
114
114
  throw l.UNSUPPORTED_BRIDGE_ENV;
115
115
  }
116
- })(window?.navigator?.userAgent), k = (e) => new Promise((n, i) => {
116
+ })(window?.navigator?.userAgent), k = (e) => new Promise((t, i) => {
117
117
  try {
118
- b.registerHandler(e.name, e.handler), e.success?.(), n();
118
+ b.registerHandler(e.name, e.handler), e.success?.(), t();
119
119
  } catch (o) {
120
120
  e.fail?.(o), i(o);
121
121
  } finally {
122
122
  e.complete?.();
123
123
  }
124
124
  });
125
- function p(e) {
126
- const n = (i) => {
125
+ function f(e) {
126
+ const t = (i) => {
127
127
  let o;
128
- const r = (t) => {
129
- (!o || o === "success") && (o = "success", i.success?.(t));
130
- }, s = (t) => {
131
- (!o || o === "error") && (o = "error", i.fail?.(t));
128
+ const r = (n) => {
129
+ (!o || o === "success") && (o = "success", i.success?.(n));
130
+ }, s = (n) => {
131
+ (!o || o === "error") && (o = "error", i.fail?.(n));
132
132
  };
133
133
  i.timeout && setTimeout(() => {
134
134
  s(l.TIMEOUT);
135
135
  }, i.timeout);
136
136
  try {
137
- b.callHandler(i.name, i.params, (t) => {
137
+ b.callHandler(i.name, i.params, (n) => {
138
138
  let a;
139
139
  try {
140
- a = typeof t == "string" ? JSON.parse(t.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : t;
140
+ a = typeof n == "string" ? JSON.parse(n.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : n;
141
141
  } catch {
142
142
  a = null;
143
143
  }
144
144
  r(a);
145
145
  });
146
- } catch (t) {
147
- s(t);
146
+ } catch (n) {
147
+ s(n);
148
148
  }
149
149
  };
150
150
  return new Promise((i, o) => {
151
- n({
151
+ t({
152
152
  name: e.name,
153
153
  params: e.params,
154
154
  timeout: e.timeout,
@@ -161,11 +161,11 @@ function p(e) {
161
161
  });
162
162
  });
163
163
  }
164
- const D = /(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);
165
- function d(e, n) {
164
+ const C = /(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);
165
+ function d(e, t) {
166
166
  return new Promise(async (i, o) => {
167
167
  try {
168
- const r = await n();
168
+ const r = await t();
169
169
  e.success?.(r), i(r);
170
170
  } catch (r) {
171
171
  const s = r?.errorCode ? r : new l({ errorCode: l.UNKNOWN.errorCode, errorMsg: String(r) });
@@ -176,14 +176,14 @@ function d(e, n) {
176
176
  });
177
177
  }
178
178
  function R(e) {
179
- let n;
179
+ let t;
180
180
  return function(...i) {
181
- return n || (n = e(...i), Promise.resolve(n).catch(() => {
182
- n = void 0;
183
- }), n);
181
+ return t || (t = e(...i), Promise.resolve(t).catch(() => {
182
+ t = void 0;
183
+ }), t);
184
184
  };
185
185
  }
186
- const H = R(() => p({
186
+ const H = R(() => f({
187
187
  name: "OpenActRequest",
188
188
  params: {
189
189
  // 这个函数只能使用35, 而不能使用新提供的60001, 这是因为写这个sdk的时候, 60001 也没有提供!!!
@@ -191,22 +191,22 @@ const H = R(() => p({
191
191
  data: {}
192
192
  }
193
193
  }));
194
- function U(e) {
194
+ function M(e) {
195
195
  return d(e, async () => (await H()).vcode >= e.minVersion);
196
196
  }
197
- function w(e, n) {
198
- return (...i) => U({
197
+ function w(e, t) {
198
+ return (...i) => M({
199
199
  minVersion: e.minVersion
200
- }).then((o) => o ? n(...i) : Promise.reject(new l({
200
+ }).then((o) => o ? t(...i) : Promise.reject(new l({
201
201
  errorCode: l.UNSUPPORTED_VERSION.errorCode,
202
202
  errorMsg: `最低版本要求${e.minVersion}`
203
203
  })));
204
204
  }
205
- class q {
205
+ class D {
206
206
  }
207
- const J = R((e) => d(
207
+ const q = R((e) => d(
208
208
  e || {},
209
- w({ minVersion: 80801 }, () => p({
209
+ w({ minVersion: 80801 }, () => f({
210
210
  name: "OpenActRequest",
211
211
  params: {
212
212
  type: 60001,
@@ -214,23 +214,23 @@ const J = R((e) => d(
214
214
  }
215
215
  }))
216
216
  ));
217
- function M(e) {
217
+ function U(e) {
218
218
  if (typeof e != "object" || e === null || Array.isArray(e))
219
219
  return {};
220
- const n = {};
220
+ const t = {};
221
221
  return Object.keys(e).forEach((i) => {
222
222
  const o = e[i];
223
- o !== void 0 && (n[i] = o);
224
- }), n;
223
+ o !== void 0 && (t[i] = o);
224
+ }), t;
225
225
  }
226
- function B(e) {
226
+ function J(e) {
227
227
  return d(
228
228
  e,
229
- w({ minVersion: 80801 }, async () => p({
229
+ w({ minVersion: 80801 }, async () => f({
230
230
  name: "OpenActRequest",
231
231
  params: {
232
232
  type: 60400,
233
- data: M({
233
+ data: U({
234
234
  /** 事件名 */
235
235
  eventId: e.eventName,
236
236
  /** 上报值 */
@@ -242,10 +242,10 @@ function B(e) {
242
242
  }))
243
243
  );
244
244
  }
245
- function G(e) {
245
+ function B(e) {
246
246
  return d(
247
247
  { ...e },
248
- w({ minVersion: 80801 }, async () => p({
248
+ w({ minVersion: 80801 }, async () => f({
249
249
  name: "OpenActRequest",
250
250
  params: {
251
251
  type: 60300,
@@ -254,30 +254,30 @@ function G(e) {
254
254
  }))
255
255
  );
256
256
  }
257
- const x = (e) => d(
257
+ const G = (e) => d(
258
258
  e,
259
- w({ minVersion: 80801 }, async () => p({
259
+ w({ minVersion: 80801 }, async () => f({
260
260
  name: "OpenActRequest",
261
261
  params: {
262
262
  type: 60500,
263
263
  data: e
264
264
  }
265
265
  }))
266
- ), h = "SHARE_EVENT_NAME";
267
- class F {
266
+ ), _ = "SHARE_EVENT_NAME";
267
+ class x {
268
268
  }
269
269
  function K(e) {
270
270
  return d(e, async () => k({
271
271
  name: "CommonShare",
272
- handler(n, i) {
273
- window.dispatchEvent(new Event(h)), "onShareApp" in e && e.onShareApp ? i({ type: 12, data: e.onShareApp() }) : i({ type: 12, data: e });
272
+ handler(t, i) {
273
+ window.dispatchEvent(new Event(_)), "onShareApp" in e && e.onShareApp ? i({ type: 12, data: e.onShareApp() }) : i({ type: 12, data: e });
274
274
  }
275
275
  }));
276
276
  }
277
- function $(e) {
277
+ function W(e) {
278
278
  return d(
279
279
  e,
280
- w({ minVersion: 80801 }, async () => (window.dispatchEvent(new Event(h)), p({
280
+ w({ minVersion: 80801 }, async () => (window.dispatchEvent(new Event(_)), f({
281
281
  name: "OpenActRequest",
282
282
  params: {
283
283
  type: 60500,
@@ -286,39 +286,47 @@ function $(e) {
286
286
  })))
287
287
  );
288
288
  }
289
- function j(e) {
290
- return window.addEventListener(h, e), () => {
291
- window.removeEventListener(h, e);
289
+ function $(e) {
290
+ return window.addEventListener(_, e), () => {
291
+ window.removeEventListener(_, e);
292
292
  };
293
293
  }
294
- var C = /* @__PURE__ */ ((e) => (e.Silent = "silent", e.Force = "force", e))(C || {});
295
- class L {
294
+ class j {
295
+ }
296
+ async function F(e) {
297
+ return d(
298
+ e || {},
299
+ w({ minVersion: 80801 }, async () => (await f({
300
+ name: "OpenActRequest",
301
+ params: { type: 60101 }
302
+ })).data || null)
303
+ );
296
304
  }
297
- async function W(e) {
305
+ function L(e) {
298
306
  return d(
299
307
  e || {},
300
- w({ minVersion: 80801 }, async () => (await p({
308
+ w({ minVersion: 80801 }, async () => (await f({
301
309
  name: "OpenActRequest",
302
- params: { type: e.mode === "silent" ? 60100 : 60101 }
310
+ params: { type: 60100 }
303
311
  })).data || null)
304
312
  );
305
313
  }
306
314
  export {
307
- q as AppBaseInfo,
308
- F as AppShareModel,
309
- C as AuthMode,
310
- L as AuthToken,
315
+ D as AppBaseInfo,
316
+ x as AppShareModel,
317
+ j as AuthToken,
311
318
  l as BridgeCode,
312
- D as IS_KB_APP_ENV,
319
+ C as IS_KB_APP_ENV,
313
320
  K as defineAppShareModel,
314
- J as getAppBaseInfo,
315
- W as getAuthToken,
316
- p as invokeNativeApi,
317
- U as isAppVersionSupport,
318
- j as onAppSharePanelShow,
319
- $ as openAppSharePanel,
321
+ q as getAppBaseInfo,
322
+ F as getAuthToken,
323
+ L as getAuthTokenWithSilent,
324
+ f as invokeNativeApi,
325
+ M as isAppVersionSupport,
326
+ $ as onAppSharePanelShow,
327
+ W as openAppSharePanel,
320
328
  k as registerNativeApiHandler,
321
- B as reportGetui,
322
- G as runAction,
323
- x as shareImage
329
+ J as reportGetui,
330
+ B as runAction,
331
+ G as shareImage
324
332
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.kbMarket={}))})(this,(function(a){"use strict";const l=class l{constructor(r){this.errorCode=r.errorCode,this.errorMsg=r.errorMsg}};l.UNKNOWN=new l({errorCode:1e3,errorMsg:"未知错误"}),l.UNSUPPORTED_VERSION=new l({errorCode:1001,errorMsg:"当前开吧版本不支持"}),l.TIMEOUT=new l({errorCode:1002,errorMsg:"执行超时"}),l.UNSUPPORTED_BRIDGE_ENV=new l({errorCode:1003,errorMsg:"请在开吧app内执行"});let c=l;const M=()=>{const e=(n,s,t)=>{var u="";typeof s=="function"&&(t=s,s={});var d={data:s===void 0?null:s};if(typeof t=="function"){var v="dscb"+window.dscb++;window[v]=t,d._dscbstub=v}if(d=JSON.stringify(d),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+n,d)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+n,d)),u instanceof Promise)return u;try{return JSON.parse(u||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},r=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const n=[],s=setInterval(()=>{r()&&(clearInterval(s),n.forEach(t=>{e.apply(window,t)}),n.length=0)},500);return(...t)=>{n.push(t)}})();var o={default:void 0,callHandler:function(n,s,t){return r()?e(n,s,t):i(n,s,t)},register:function(n,s,t){var u=t?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof s=="object"?u._obs[n]=s:u[n]=s},registerHandler:function(n,s){this.register(n,s,!0)}};return(function(){if(!window._dsf){var n={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(t){var u=JSON.parse(t.data),d={id:t.callbackId,complete:!0},v=this._dsf[t.method],y=this._dsaf[t.method],V=function(E,N){d.data=E.apply(N,u),o.callHandler("_dsb.returnValue",d)},R=function(E,N){u.push(function(z,Q){d.data=z,d.complete=Q!==!1,o.callHandler("_dsb.returnValue",d)}),E.apply(N,u)};if(v)V(v,this._dsf);else if(y)R(y,this._dsaf);else{var g=t.method.split(".");if(g.length<2)return;var T=g.pop(),k=g.join("."),S=this._dsf._obs,_=S[k]||{},w=_[T];if(w&&typeof w=="function"){V(w,_);return}if(S=this._dsaf._obs,_=S[k]||{},w=_[T],w&&typeof w=="function"){R(w,_);return}}}};for(var s in n)window[s]=n[s]}})(),o},P=(e=>/(kb)/i.test(e)?M():{registerHandler(r,i){throw c.UNSUPPORTED_BRIDGE_ENV},callHandler(r,i,o){throw c.UNSUPPORTED_BRIDGE_ENV}})(window?.navigator?.userAgent),m=e=>new Promise((r,i)=>{try{P.registerHandler(e.name,e.handler),e.success?.(),r()}catch(o){e.fail?.(o),i(o)}finally{e.complete?.()}});function f(e){const r=i=>{let o;const n=t=>{(!o||o==="success")&&(o="success",i.success?.(t))},s=t=>{(!o||o==="error")&&(o="error",i.fail?.(t))};i.timeout&&setTimeout(()=>{s(c.TIMEOUT)},i.timeout);try{P.callHandler(i.name,i.params,t=>{let u;try{u=typeof t=="string"?JSON.parse(t.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):t}catch{u=null}n(u)})}catch(t){s(t)}};return new Promise((i,o)=>{r({name:e.name,params:e.params,timeout:e.timeout,success:n=>{e.success?.(n),e.complete?.(),i(n)},fail:n=>{e.fail?.(n),e.complete?.(),o(n)}})})}const H=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);function p(e,r){return new Promise(async(i,o)=>{try{const n=await r();e.success?.(n),i(n)}catch(n){const s=n?.errorCode?n:new c({errorCode:c.UNKNOWN.errorCode,errorMsg:String(n)});e.fail?.(s),o(s)}finally{e.complete?.()}})}function b(e){let r;return function(...i){return r||(r=e(...i),Promise.resolve(r).catch(()=>{r=void 0}),r)}}const U=b(()=>f({name:"OpenActRequest",params:{type:35,data:{}}}));function O(e){return p(e,async()=>(await U()).vcode>=e.minVersion)}function h(e,r){return(...i)=>O({minVersion:e.minVersion}).then(o=>o?r(...i):Promise.reject(new c({errorCode:c.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}class C{}const D=b(e=>p(e||{},h({minVersion:80801},()=>f({name:"OpenActRequest",params:{type:60001,data:{}}}))));function q(e){if(typeof e!="object"||e===null||Array.isArray(e))return{};const r={};return Object.keys(e).forEach(i=>{const o=e[i];o!==void 0&&(r[i]=o)}),r}function B(e){return p(e,h({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60400,data:q({eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType})}})))}function G(e){return p({...e},h({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60300,data:e}})))}const J=e=>p(e,h({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60500,data:e}}))),A="SHARE_EVENT_NAME";class j{}function K(e){return p(e,async()=>m({name:"CommonShare",handler(r,i){window.dispatchEvent(new Event(A)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}}))}function F(e){return p(e,h({minVersion:80801},async()=>(window.dispatchEvent(new Event(A)),f({name:"OpenActRequest",params:{type:60500,data:e}}))))}function $(e){return window.addEventListener(A,e),()=>{window.removeEventListener(A,e)}}var I=(e=>(e.Silent="silent",e.Force="force",e))(I||{});class L{}async function W(e){return p(e||{},h({minVersion:80801},async()=>(await f({name:"OpenActRequest",params:{type:e.mode==="silent"?60100:60101}})).data||null))}a.AppBaseInfo=C,a.AppShareModel=j,a.AuthMode=I,a.AuthToken=L,a.BridgeCode=c,a.IS_KB_APP_ENV=H,a.defineAppShareModel=K,a.getAppBaseInfo=D,a.getAuthToken=W,a.invokeNativeApi=f,a.isAppVersionSupport=O,a.onAppSharePanelShow=$,a.openAppSharePanel=F,a.registerNativeApiHandler=m,a.reportGetui=B,a.runAction=G,a.shareImage=J,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.kbMarket={}))})(this,(function(s){"use strict";const l=class l{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};l.UNKNOWN=new l({errorCode:1e3,errorMsg:"未知错误"}),l.UNSUPPORTED_VERSION=new l({errorCode:1001,errorMsg:"当前开吧版本不支持"}),l.TIMEOUT=new l({errorCode:1002,errorMsg:"执行超时"}),l.UNSUPPORTED_BRIDGE_ENV=new l({errorCode:1003,errorMsg:"请在开吧app内执行"});let c=l;const k=()=>{const e=(n,a,r)=>{var u="";typeof a=="function"&&(r=a,a={});var d={data:a===void 0?null:a};if(typeof r=="function"){var v="dscb"+window.dscb++;window[v]=r,d._dscbstub=v}if(d=JSON.stringify(d),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+n,d)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+n,d)),u instanceof Promise)return u;try{return JSON.parse(u||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const n=[],a=setInterval(()=>{t()&&(clearInterval(a),n.forEach(r=>{e.apply(window,r)}),n.length=0)},500);return(...r)=>{n.push(r)}})();var o={default:void 0,callHandler:function(n,a,r){return t()?e(n,a,r):i(n,a,r)},register:function(n,a,r){var u=r?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof a=="object"?u._obs[n]=a:u[n]=a},registerHandler:function(n,a){this.register(n,a,!0)}};return(function(){if(!window._dsf){var n={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(r){var u=JSON.parse(r.data),d={id:r.callbackId,complete:!0},v=this._dsf[r.method],y=this._dsaf[r.method],I=function(E,m){d.data=E.apply(m,u),o.callHandler("_dsb.returnValue",d)},V=function(E,m){u.push(function(z,Q){d.data=z,d.complete=Q!==!1,o.callHandler("_dsb.returnValue",d)}),E.apply(m,u)};if(v)I(v,this._dsf);else if(y)V(y,this._dsaf);else{var g=r.method.split(".");if(g.length<2)return;var R=g.pop(),T=g.join("."),S=this._dsf._obs,A=S[T]||{},h=A[R];if(h&&typeof h=="function"){I(h,A);return}if(S=this._dsaf._obs,A=S[T]||{},h=A[R],h&&typeof h=="function"){V(h,A);return}}}};for(var a in n)window[a]=n[a]}})(),o},N=(e=>/(kb)/i.test(e)?k():{registerHandler(t,i){throw c.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,o){throw c.UNSUPPORTED_BRIDGE_ENV}})(window?.navigator?.userAgent),P=e=>new Promise((t,i)=>{try{N.registerHandler(e.name,e.handler),e.success?.(),t()}catch(o){e.fail?.(o),i(o)}finally{e.complete?.()}});function f(e){const t=i=>{let o;const n=r=>{(!o||o==="success")&&(o="success",i.success?.(r))},a=r=>{(!o||o==="error")&&(o="error",i.fail?.(r))};i.timeout&&setTimeout(()=>{a(c.TIMEOUT)},i.timeout);try{N.callHandler(i.name,i.params,r=>{let u;try{u=typeof r=="string"?JSON.parse(r.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):r}catch{u=null}n(u)})}catch(r){a(r)}};return new Promise((i,o)=>{t({name:e.name,params:e.params,timeout:e.timeout,success:n=>{e.success?.(n),e.complete?.(),i(n)},fail:n=>{e.fail?.(n),e.complete?.(),o(n)}})})}const M=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);function p(e,t){return new Promise(async(i,o)=>{try{const n=await t();e.success?.(n),i(n)}catch(n){const a=n?.errorCode?n:new c({errorCode:c.UNKNOWN.errorCode,errorMsg:String(n)});e.fail?.(a),o(a)}finally{e.complete?.()}})}function b(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}const H=b(()=>f({name:"OpenActRequest",params:{type:35,data:{}}}));function O(e){return p(e,async()=>(await H()).vcode>=e.minVersion)}function w(e,t){return(...i)=>O({minVersion:e.minVersion}).then(o=>o?t(...i):Promise.reject(new c({errorCode:c.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}class U{}const C=b(e=>p(e||{},w({minVersion:80801},()=>f({name:"OpenActRequest",params:{type:60001,data:{}}}))));function D(e){if(typeof e!="object"||e===null||Array.isArray(e))return{};const t={};return Object.keys(e).forEach(i=>{const o=e[i];o!==void 0&&(t[i]=o)}),t}function q(e){return p(e,w({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60400,data:D({eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType})}})))}function B(e){return p({...e},w({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60300,data:e}})))}const G=e=>p(e,w({minVersion:80801},async()=>f({name:"OpenActRequest",params:{type:60500,data:e}}))),_="SHARE_EVENT_NAME";class J{}function j(e){return p(e,async()=>P({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})}}))}function K(e){return p(e,w({minVersion:80801},async()=>(window.dispatchEvent(new Event(_)),f({name:"OpenActRequest",params:{type:60500,data:e}}))))}function W(e){return window.addEventListener(_,e),()=>{window.removeEventListener(_,e)}}class ${}async function F(e){return p(e||{},w({minVersion:80801},async()=>(await f({name:"OpenActRequest",params:{type:60101}})).data||null))}function L(e){return p(e||{},w({minVersion:80801},async()=>(await f({name:"OpenActRequest",params:{type:60100}})).data||null))}s.AppBaseInfo=U,s.AppShareModel=J,s.AuthToken=$,s.BridgeCode=c,s.IS_KB_APP_ENV=M,s.defineAppShareModel=j,s.getAppBaseInfo=C,s.getAuthToken=F,s.getAuthTokenWithSilent=L,s.invokeNativeApi=f,s.isAppVersionSupport=O,s.onAppSharePanelShow=W,s.openAppSharePanel=K,s.registerNativeApiHandler=P,s.reportGetui=q,s.runAction=B,s.shareImage=G,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
@@ -1,32 +1,19 @@
1
1
  import { CallbackOptions } from './callback-options';
2
- /**
3
- *
4
- * @description 登录授权模式
5
- */
6
- export declare enum AuthMode {
7
- /** 静默登录, 若用户未登录则直接返回 */
8
- Silent = "silent",
9
- /** 强制登录, 若用户未登录弹窗引导登录 */
10
- Force = "force"
11
- }
12
2
  /**
13
3
  *
14
4
  * @description 登录信息
15
5
  */
16
6
  export declare class AuthToken {
17
- /**
18
- *
19
- * 状态码 0 成功, 1: 未登录
20
- * 当mode === force时, code可能为0, 如果用户点击取消, 将没有返回值
21
- * 当mode === silent时, code可能为0或者1
22
- */
23
- code: 0 | 1 | 2;
7
+ /** 状态码 0 成功, 1: 未登录, 2: 取消登录, 3: 获取token失败 */
8
+ code: 0 | 1 | 2 | 3;
24
9
  /** 登录凭证, 当 code === 0 的时候返回 */
25
10
  token: string;
26
11
  }
27
12
  /**
28
13
  *
29
- * @description 获取开吧 登录授权凭证
14
+ * @description 获取开吧 登录授权凭证, 当app未登录, 则会唤起登录, 登录成功后返回token
15
+ *
16
+ * ⚠️ **重要异常提示**:在用户取消登录的某些场景下,该函数可能出现「无任何回调」的情况(`success` 和 `fail` 回调均不会触发),请开发者做好兜底处理。
30
17
  * @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
31
18
  * @example
32
19
  * **示例代码**
@@ -53,6 +40,33 @@ if (authToken.code === 0) {
53
40
  }
54
41
  ```
55
42
  */
56
- export declare function getAuthToken(params: {
57
- mode: AuthMode;
58
- } & CallbackOptions<AuthToken>): Promise<AuthToken>;
43
+ export declare function getAuthToken(params?: CallbackOptions<AuthToken>): Promise<AuthToken>;
44
+ /**
45
+ *
46
+ * @description 静默获取开吧登录授权凭证:若 App 已登录则直接返回有效 AuthToken;未登录时不会唤起登录页,直接返回 code = 1 的结果。
47
+ * @returns {AuthToken}
48
+ * @example
49
+ *
50
+ * **示例代码**
51
+ ```js
52
+ import { getAuthTokenWithSilent } from '@kbapp/market-partner-sdk';
53
+
54
+ getAuthTokenWithSilent({
55
+ success(authToken: AppAuthToken) {
56
+ if (authToken.code === 0) {
57
+ // 获取成功
58
+ console.log(authToken.token)
59
+ }
60
+ },
61
+ })
62
+
63
+ const authToken: AppAuthToken = await getAuthTokenWithSilent()
64
+
65
+ if (authToken.code === 0) {
66
+ console.log(authToken.token)
67
+ } else {
68
+ console.log('未登录')
69
+ }
70
+ ```
71
+ */
72
+ export declare function getAuthTokenWithSilent(params?: CallbackOptions<AuthToken>): Promise<AuthToken>;
@@ -51,7 +51,7 @@
51
51
  </body>
52
52
  <script type="module">
53
53
  import { createApp, ref, reactive } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
54
- import { getAuthToken, runAction, defineAppShareModel, openAppSharePanel, reportGetui, getAppBaseInfo, shareImage } from 'https://unpkg.com/@kbapp/market-partner-sdk@latest/dist/index.es.js'
54
+ import { getAuthToken, getAuthTokenWithSilent, runAction, defineAppShareModel, openAppSharePanel, reportGetui, getAppBaseInfo, shareImage } from 'https://unpkg.com/@kbapp/market-partner-sdk@latest/dist/index.es.js'
55
55
 
56
56
  /**
57
57
  * 装饰器,用于处理done函数的调用
@@ -130,22 +130,18 @@
130
130
  buttonText: '执行',
131
131
  desc: `执行结果: 如果未登录则唤起登录, 登录成功后返回token`,
132
132
  done: decorateDone(async () => {
133
- const result = await getAuthToken({
134
- mode: 'force',
135
- })
133
+ const result = await getAuthToken()
136
134
 
137
135
  return result
138
136
  }),
139
137
  },
140
138
  {
141
- title: 'getAuthToken',
142
- subtitle: '静默登录 mode=silent',
139
+ title: 'getAuthTokenWithSilent',
140
+ subtitle: '静默登录',
143
141
  buttonText: '执行',
144
142
  desc: `执行结果: 如果未登录则返回code = 1, 已登录返回token`,
145
143
  done: decorateDone(async () => {
146
- const result = await getAuthToken({
147
- mode: 'silent',
148
- })
144
+ const result = await getAuthTokenWithSilent()
149
145
 
150
146
  return result
151
147
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbapp/market-partner-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "开吧商城接入jssdk",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/server.js DELETED
@@ -1,103 +0,0 @@
1
- // 简单的HTTP服务器,正确处理ES模块的MIME类型
2
- import http from 'http';
3
- import fs from 'fs';
4
- import path from 'path';
5
-
6
- const PORT = 8080;
7
- const BASE_DIR = process.cwd();
8
-
9
- const server = http.createServer((req, res) => {
10
- console.log(`请求路径: ${req.url}`);
11
- // 移除URL中的查询字符串
12
- const urlPath = req.url.split('?')[0];
13
-
14
- // 特殊路径重定向逻辑
15
- let redirectPath = null;
16
-
17
- // 重定向 /lib/bridge-code 到 /dist/lib/bridge-code
18
- if (urlPath === '/lib/bridge-code') {
19
- redirectPath = '/dist/lib/bridge-code';
20
- console.log(`重定向路径: ${urlPath} -\u003e ${redirectPath}`);
21
- }
22
- // 重定向 /dist/lib/flutter-ds-bridge 到 /dist/core/lib/flutter-ds-bridge
23
- else if (urlPath === '/dist/lib/flutter-ds-bridge') {
24
- redirectPath = '/dist/core/lib/flutter-ds-bridge';
25
- console.log(`重定向路径: ${urlPath} -\u003e ${redirectPath}`);
26
- }
27
-
28
- // 确定文件路径
29
- let filePath = path.join(BASE_DIR, redirectPath || urlPath);
30
-
31
- // 如果请求没有扩展名,尝试添加.js
32
- if (!path.extname(urlPath)) {
33
- console.log(`检测到无扩展名路径,尝试添加.js扩展名`);
34
- filePath = filePath + '.js';
35
- } else if (urlPath.endsWith('/')) {
36
- // 如果是目录,默认返回index.html
37
- filePath = path.join(filePath, 'index.html');
38
- }
39
-
40
- // 确定MIME类型
41
- const extname = path.extname(filePath);
42
- let contentType = 'text/html';
43
-
44
- switch (extname) {
45
- case '.js':
46
- contentType = 'application/javascript';
47
- break;
48
- case '.mjs':
49
- contentType = 'application/javascript';
50
- break;
51
- case '.css':
52
- contentType = 'text/css';
53
- break;
54
- case '.json':
55
- contentType = 'application/json';
56
- break;
57
- case '.png':
58
- contentType = 'image/png';
59
- break;
60
- case '.jpg':
61
- case '.jpeg':
62
- contentType = 'image/jpeg';
63
- break;
64
- }
65
-
66
- console.log(`尝试加载文件: ${filePath}`);
67
-
68
- // 读取并发送文件
69
- fs.readFile(filePath, (error, content) => {
70
- if (error) {
71
- console.error(`文件加载错误: ${error.message}`);
72
- if (error.code === 'ENOENT') {
73
- // 文件不存在,尝试备选路径/index.js
74
- const altFilePath = path.join(filePath.replace('.js', ''), 'index.js');
75
- console.log(`尝试备选路径: ${altFilePath}`);
76
- fs.readFile(altFilePath, (altError, altContent) => {
77
- if (altError) {
78
- res.writeHead(404);
79
- res.end(`文件不存在: ${filePath}`);
80
- } else {
81
- res.writeHead(200, { 'Content-Type': contentType });
82
- res.end(altContent, 'utf-8');
83
- }
84
- });
85
- return;
86
- }
87
-
88
- // 服务器错误
89
- res.writeHead(500);
90
- res.end('服务器错误: ' + error.code);
91
- } else {
92
- // 文件存在,发送内容
93
- res.writeHead(200, { 'Content-Type': contentType });
94
- res.end(content, 'utf-8');
95
- }
96
- });
97
- });
98
-
99
- server.listen(PORT, () => {
100
- console.log(`服务器运行在 http://localhost:${PORT}`);
101
- console.log(`当前工作目录: ${BASE_DIR}`);
102
- console.log(`访问示例: http://localhost:${PORT}/examples/index.html`);
103
- });