@kbapp/market-partner-sdk 0.0.2 → 0.0.3
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/README.MD +1 -0
- package/dist/index.es.js +51 -51
- package/dist/index.umd.js +1 -1
- package/dist/lib/auth-token.d.ts +4 -4
- package/package.json +1 -1
package/README.MD
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const u = class u {
|
|
2
|
-
constructor(
|
|
3
|
-
this.errorCode =
|
|
2
|
+
constructor(r) {
|
|
3
|
+
this.errorCode = r.errorCode, this.errorMsg = r.errorMsg;
|
|
4
4
|
}
|
|
5
5
|
};
|
|
6
6
|
u.UNKNOWN = new u({
|
|
@@ -18,7 +18,7 @@ u.UNKNOWN = new u({
|
|
|
18
18
|
});
|
|
19
19
|
let l = u;
|
|
20
20
|
const T = () => {
|
|
21
|
-
const e = (
|
|
21
|
+
const e = (t, s, n) => {
|
|
22
22
|
var a = "";
|
|
23
23
|
typeof s == "function" && (n = s, s = {});
|
|
24
24
|
var c = { data: s === void 0 ? null : s };
|
|
@@ -26,42 +26,42 @@ const T = () => {
|
|
|
26
26
|
var v = "dscb" + window.dscb++;
|
|
27
27
|
window[v] = n, c._dscbstub = v;
|
|
28
28
|
}
|
|
29
|
-
if (c = JSON.stringify(c), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" +
|
|
29
|
+
if (c = JSON.stringify(c), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" + t, c)) : (window._dswk || navigator.userAgent.indexOf("_dsbridge") != -1) && (a = prompt("_flutterDsbridge=" + t, c)), a instanceof Promise)
|
|
30
30
|
return a;
|
|
31
31
|
try {
|
|
32
32
|
return JSON.parse(a || "{}").data;
|
|
33
33
|
} catch {
|
|
34
34
|
console.error("callHandle异常,JSON.parse错误");
|
|
35
35
|
}
|
|
36
|
-
},
|
|
37
|
-
const
|
|
38
|
-
|
|
36
|
+
}, r = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, i = (() => {
|
|
37
|
+
const t = [], s = setInterval(() => {
|
|
38
|
+
r() && (clearInterval(s), t.forEach((n) => {
|
|
39
39
|
e.apply(window, n);
|
|
40
|
-
}),
|
|
40
|
+
}), t.length = 0);
|
|
41
41
|
}, 500);
|
|
42
42
|
return (...n) => {
|
|
43
|
-
|
|
43
|
+
t.push(n);
|
|
44
44
|
};
|
|
45
45
|
})();
|
|
46
46
|
var o = {
|
|
47
47
|
default: void 0,
|
|
48
48
|
// for typescript
|
|
49
|
-
callHandler: function(
|
|
50
|
-
return
|
|
49
|
+
callHandler: function(t, s, n) {
|
|
50
|
+
return r() ? e(t, s, n) : i(t, s, n);
|
|
51
51
|
},
|
|
52
|
-
register: function(
|
|
52
|
+
register: function(t, s, n) {
|
|
53
53
|
var a = n ? window._dsaf : window._dsf;
|
|
54
54
|
window._dsInit || (window._dsInit = !0, setTimeout(function() {
|
|
55
55
|
o.callHandler("_dsb.dsinit");
|
|
56
|
-
}, 0)), typeof s == "object" ? a._obs[
|
|
56
|
+
}, 0)), typeof s == "object" ? a._obs[t] = s : a[t] = s;
|
|
57
57
|
},
|
|
58
|
-
registerHandler: function(
|
|
59
|
-
this.register(
|
|
58
|
+
registerHandler: function(t, s) {
|
|
59
|
+
this.register(t, s, !0);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
return (function() {
|
|
63
63
|
if (!window._dsf) {
|
|
64
|
-
var
|
|
64
|
+
var t = {
|
|
65
65
|
//保存JS同步方法
|
|
66
66
|
_dsf: {
|
|
67
67
|
_obs: {}
|
|
@@ -102,20 +102,20 @@ const T = () => {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
for (var s in
|
|
106
|
-
window[s] =
|
|
105
|
+
for (var s in t)
|
|
106
|
+
window[s] = t[s];
|
|
107
107
|
}
|
|
108
108
|
})(), o;
|
|
109
|
-
},
|
|
110
|
-
registerHandler(
|
|
109
|
+
}, R = ((e) => /(kb)/i.test(e) ? T() : {
|
|
110
|
+
registerHandler(r, i) {
|
|
111
111
|
throw l.UNSUPPORTED_BRIDGE_ENV;
|
|
112
112
|
},
|
|
113
|
-
callHandler(
|
|
113
|
+
callHandler(r, i, o) {
|
|
114
114
|
throw l.UNSUPPORTED_BRIDGE_ENV;
|
|
115
115
|
}
|
|
116
|
-
})(window?.navigator?.userAgent), k = (e) => new Promise((
|
|
116
|
+
})(window?.navigator?.userAgent), k = (e) => new Promise((r, i) => {
|
|
117
117
|
try {
|
|
118
|
-
|
|
118
|
+
R.registerHandler(e.name, e.handler), e.success?.(), r();
|
|
119
119
|
} catch (o) {
|
|
120
120
|
e.fail?.(o), i(o);
|
|
121
121
|
} finally {
|
|
@@ -123,9 +123,9 @@ const T = () => {
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
function f(e) {
|
|
126
|
-
const
|
|
126
|
+
const r = (i) => {
|
|
127
127
|
let o;
|
|
128
|
-
const
|
|
128
|
+
const t = (n) => {
|
|
129
129
|
(!o || o === "success") && (o = "success", i.success?.(n));
|
|
130
130
|
}, s = (n) => {
|
|
131
131
|
(!o || o === "error") && (o = "error", i.fail?.(n));
|
|
@@ -134,56 +134,56 @@ function f(e) {
|
|
|
134
134
|
s(l.TIMEOUT);
|
|
135
135
|
}, i.timeout);
|
|
136
136
|
try {
|
|
137
|
-
|
|
137
|
+
R.callHandler(i.name, i.params, (n) => {
|
|
138
138
|
let a;
|
|
139
139
|
try {
|
|
140
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
|
+
t(a);
|
|
145
145
|
});
|
|
146
146
|
} catch (n) {
|
|
147
147
|
s(n);
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
return new Promise((i, o) => {
|
|
151
|
-
|
|
151
|
+
r({
|
|
152
152
|
name: e.name,
|
|
153
153
|
params: e.params,
|
|
154
154
|
timeout: e.timeout,
|
|
155
|
-
success: (
|
|
156
|
-
e.success?.(
|
|
155
|
+
success: (t) => {
|
|
156
|
+
e.success?.(t), e.complete?.(), i(t);
|
|
157
157
|
},
|
|
158
|
-
fail: (
|
|
159
|
-
e.fail?.(
|
|
158
|
+
fail: (t) => {
|
|
159
|
+
e.fail?.(t), e.complete?.(), o(t);
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
const C = /(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);
|
|
165
|
-
function d(e,
|
|
165
|
+
function d(e, r) {
|
|
166
166
|
return new Promise(async (i, o) => {
|
|
167
167
|
try {
|
|
168
|
-
const
|
|
169
|
-
e.success?.(
|
|
170
|
-
} catch (
|
|
171
|
-
const s =
|
|
168
|
+
const t = await r();
|
|
169
|
+
e.success?.(t), i(t);
|
|
170
|
+
} catch (t) {
|
|
171
|
+
const s = t?.errorCode ? t : new l({ errorCode: l.UNKNOWN.errorCode, errorMsg: String(t) });
|
|
172
172
|
e.fail?.(s), o(s);
|
|
173
173
|
} finally {
|
|
174
174
|
e.complete?.();
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
let
|
|
178
|
+
function b(e) {
|
|
179
|
+
let r;
|
|
180
180
|
return function(...i) {
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
}),
|
|
181
|
+
return r || (r = e(...i), Promise.resolve(r).catch(() => {
|
|
182
|
+
r = void 0;
|
|
183
|
+
}), r);
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
|
-
const H =
|
|
186
|
+
const H = b(() => f({
|
|
187
187
|
name: "OpenActRequest",
|
|
188
188
|
params: {
|
|
189
189
|
// 这个函数只能使用35, 而不能使用新提供的60001, 这是因为写这个sdk的时候, 60001 也没有提供!!!
|
|
@@ -194,17 +194,17 @@ const H = R(() => f({
|
|
|
194
194
|
function M(e) {
|
|
195
195
|
return d(e, async () => (await H()).vcode >= e.minVersion);
|
|
196
196
|
}
|
|
197
|
-
function w(e,
|
|
197
|
+
function w(e, r) {
|
|
198
198
|
return (...i) => M({
|
|
199
199
|
minVersion: e.minVersion
|
|
200
|
-
}).then((o) => o ?
|
|
200
|
+
}).then((o) => o ? r(...i) : Promise.reject(new l({
|
|
201
201
|
errorCode: l.UNSUPPORTED_VERSION.errorCode,
|
|
202
202
|
errorMsg: `最低版本要求${e.minVersion}`
|
|
203
203
|
})));
|
|
204
204
|
}
|
|
205
205
|
class D {
|
|
206
206
|
}
|
|
207
|
-
const q =
|
|
207
|
+
const q = b((e) => d(
|
|
208
208
|
e || {},
|
|
209
209
|
w({ minVersion: 80801 }, () => f({
|
|
210
210
|
name: "OpenActRequest",
|
|
@@ -217,11 +217,11 @@ const q = R((e) => d(
|
|
|
217
217
|
function U(e) {
|
|
218
218
|
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
219
219
|
return {};
|
|
220
|
-
const
|
|
220
|
+
const r = {};
|
|
221
221
|
return Object.keys(e).forEach((i) => {
|
|
222
222
|
const o = e[i];
|
|
223
|
-
o !== void 0 && (
|
|
224
|
-
}),
|
|
223
|
+
o !== void 0 && (r[i] = o);
|
|
224
|
+
}), r;
|
|
225
225
|
}
|
|
226
226
|
function J(e) {
|
|
227
227
|
return d(
|
|
@@ -269,7 +269,7 @@ class x {
|
|
|
269
269
|
function K(e) {
|
|
270
270
|
return d(e, async () => k({
|
|
271
271
|
name: "CommonShare",
|
|
272
|
-
handler(
|
|
272
|
+
handler(r, i) {
|
|
273
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
|
}));
|
|
@@ -314,7 +314,7 @@ function L(e) {
|
|
|
314
314
|
export {
|
|
315
315
|
D as AppBaseInfo,
|
|
316
316
|
x as AppShareModel,
|
|
317
|
-
j as
|
|
317
|
+
j as AuthResult,
|
|
318
318
|
l as BridgeCode,
|
|
319
319
|
C as IS_KB_APP_ENV,
|
|
320
320
|
K as defineAppShareModel,
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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 d=class d{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};d.UNKNOWN=new d({errorCode:1e3,errorMsg:"未知错误"}),d.UNSUPPORTED_VERSION=new d({errorCode:1001,errorMsg:"当前开吧版本不支持"}),d.TIMEOUT=new d({errorCode:1002,errorMsg:"执行超时"}),d.UNSUPPORTED_BRIDGE_ENV=new d({errorCode:1003,errorMsg:"请在开吧app内执行"});let c=d;const k=()=>{const e=(n,s,r)=>{var u="";typeof s=="function"&&(r=s,s={});var l={data:s===void 0?null:s};if(typeof r=="function"){var v="dscb"+window.dscb++;window[v]=r,l._dscbstub=v}if(l=JSON.stringify(l),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+n,l)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+n,l)),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=[],s=setInterval(()=>{t()&&(clearInterval(s),n.forEach(r=>{e.apply(window,r)}),n.length=0)},500);return(...r)=>{n.push(r)}})();var o={default:void 0,callHandler:function(n,s,r){return t()?e(n,s,r):i(n,s,r)},register:function(n,s,r){var u=r?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(r){var u=JSON.parse(r.data),l={id:r.callbackId,complete:!0},v=this._dsf[r.method],y=this._dsaf[r.method],R=function(E,m){l.data=E.apply(m,u),o.callHandler("_dsb.returnValue",l)},I=function(E,m){u.push(function(z,Q){l.data=z,l.complete=Q!==!1,o.callHandler("_dsb.returnValue",l)}),E.apply(m,u)};if(v)R(v,this._dsf);else if(y)I(y,this._dsaf);else{var g=r.method.split(".");if(g.length<2)return;var V=g.pop(),T=g.join("."),S=this._dsf._obs,A=S[T]||{},h=A[V];if(h&&typeof h=="function"){R(h,A);return}if(S=this._dsaf._obs,A=S[T]||{},h=A[V],h&&typeof h=="function"){I(h,A);return}}}};for(var s in n)window[s]=n[s]}})(),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))},s=r=>{(!o||o==="error")&&(o="error",i.fail?.(r))};i.timeout&&setTimeout(()=>{s(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){s(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 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 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))}a.AppBaseInfo=U,a.AppShareModel=J,a.AuthResult=$,a.BridgeCode=c,a.IS_KB_APP_ENV=M,a.defineAppShareModel=j,a.getAppBaseInfo=C,a.getAuthToken=F,a.getAuthTokenWithSilent=L,a.invokeNativeApi=f,a.isAppVersionSupport=O,a.onAppSharePanelShow=W,a.openAppSharePanel=K,a.registerNativeApiHandler=P,a.reportGetui=q,a.runAction=B,a.shareImage=G,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/lib/auth-token.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CallbackOptions } from './callback-options';
|
|
|
3
3
|
*
|
|
4
4
|
* @description 登录信息
|
|
5
5
|
*/
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class AuthResult {
|
|
7
7
|
/** 状态码 0 成功, 1: 未登录, 2: 取消登录, 3: 获取token失败 */
|
|
8
8
|
code: 0 | 1 | 2 | 3;
|
|
9
9
|
/** 登录凭证, 当 code === 0 的时候返回 */
|
|
@@ -40,11 +40,11 @@ if (authToken.code === 0) {
|
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
*/
|
|
43
|
-
export declare function getAuthToken(params?: CallbackOptions<
|
|
43
|
+
export declare function getAuthToken(params?: CallbackOptions<AuthResult>): Promise<AuthResult>;
|
|
44
44
|
/**
|
|
45
45
|
*
|
|
46
46
|
* @description 静默获取开吧登录授权凭证:若 App 已登录则直接返回有效 AuthToken;未登录时不会唤起登录页,直接返回 code = 1 的结果。
|
|
47
|
-
* @returns {
|
|
47
|
+
* @returns {AuthResult}
|
|
48
48
|
* @example
|
|
49
49
|
*
|
|
50
50
|
* **示例代码**
|
|
@@ -69,4 +69,4 @@ if (authToken.code === 0) {
|
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
71
|
*/
|
|
72
|
-
export declare function getAuthTokenWithSilent(params?: CallbackOptions<
|
|
72
|
+
export declare function getAuthTokenWithSilent(params?: CallbackOptions<AuthResult>): Promise<AuthResult>;
|