@kbapp/market-partner-sdk 0.0.1
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 +661 -0
- package/dist/core/index.d.ts +79 -0
- package/dist/core/lib/flutter-ds-bridge.d.ts +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.es.js +324 -0
- package/dist/index.umd.js +1 -0
- package/dist/lib/app-version-support.d.ts +37 -0
- package/dist/lib/auth-token.d.ts +58 -0
- package/dist/lib/bridge-code.d.ts +14 -0
- package/dist/lib/callback-options.d.ts +10 -0
- package/dist/lib/env.d.ts +2 -0
- package/dist/lib/get-app-base-info.d.ts +49 -0
- package/dist/lib/report-getui.d.ts +31 -0
- package/dist/lib/run-action.d.ts +22 -0
- package/dist/lib/share-image.d.ts +18 -0
- package/dist/lib/share-model.d.ts +171 -0
- package/dist/util/filter-undefined-properties.d.ts +8 -0
- package/dist/util/promise-cache.d.ts +10 -0
- package/examples/index.html +217 -0
- package/package.json +18 -0
- package/server.js +103 -0
- package/tsconfig.json +24 -0
- package/vite.config.ts +24 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BridgeCode } from '../lib/bridge-code';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 注册 提供给native端调用
|
|
5
|
+
*
|
|
6
|
+
* **示例代码**
|
|
7
|
+
```js
|
|
8
|
+
import { registerNativeApiHandler } from '@kbapp/market-partner-sdk';
|
|
9
|
+
|
|
10
|
+
registerNativeApiHandler({
|
|
11
|
+
name: 'CommonShare',
|
|
12
|
+
handler() {
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
```
|
|
16
|
+
*/
|
|
17
|
+
export declare const registerNativeApiHandler: (params: {
|
|
18
|
+
/** 任务名称 */
|
|
19
|
+
name: string;
|
|
20
|
+
/** 回调函数 */
|
|
21
|
+
handler: (...params: any[]) => any;
|
|
22
|
+
/** 注册函数成功 */
|
|
23
|
+
success?: () => void;
|
|
24
|
+
/** 注册函数失败 */
|
|
25
|
+
fail?: (error: BridgeCode) => void;
|
|
26
|
+
complete?: () => void;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @description 触发app桥接
|
|
31
|
+
*
|
|
32
|
+
* **示例代码**
|
|
33
|
+
```js
|
|
34
|
+
import { invokeNativeApiPromise } from '@kbapp/market-partner-sdk';
|
|
35
|
+
|
|
36
|
+
invokeNativeApi({
|
|
37
|
+
name: 'OpenActRequest',
|
|
38
|
+
params: {
|
|
39
|
+
type: 60001,
|
|
40
|
+
data: {},
|
|
41
|
+
},
|
|
42
|
+
success(result: Result) {
|
|
43
|
+
console.log(result)
|
|
44
|
+
},
|
|
45
|
+
fail(error: BridgeCode) {
|
|
46
|
+
console.error(error)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
invokeNativeApi({
|
|
51
|
+
name: 'OpenActRequest',
|
|
52
|
+
params: {
|
|
53
|
+
type: 60001,
|
|
54
|
+
data: {},
|
|
55
|
+
},
|
|
56
|
+
}).then((result: Result) => {
|
|
57
|
+
console.log(result)
|
|
58
|
+
}).catch((error: BridgeCode) => {
|
|
59
|
+
console.error(error)
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
*/
|
|
63
|
+
export declare function invokeNativeApi<Result = void>(params: {
|
|
64
|
+
/** 任务名称 */
|
|
65
|
+
name: string;
|
|
66
|
+
/** 任务参数 */
|
|
67
|
+
params: {
|
|
68
|
+
type: number;
|
|
69
|
+
data?: any;
|
|
70
|
+
};
|
|
71
|
+
/** 设置超时时间 */
|
|
72
|
+
timeout?: number;
|
|
73
|
+
/** 执行成功 */
|
|
74
|
+
success?: (result: Result) => void;
|
|
75
|
+
/** 执行失败 */
|
|
76
|
+
fail?: (error: BridgeCode) => void;
|
|
77
|
+
/** 同时触发 */
|
|
78
|
+
complete?: () => void;
|
|
79
|
+
}): Promise<Result>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './lib/env';
|
|
3
|
+
export * from './lib/bridge-code';
|
|
4
|
+
export * from './lib/get-app-base-info';
|
|
5
|
+
export * from './lib/report-getui';
|
|
6
|
+
export * from './lib/run-action';
|
|
7
|
+
export * from './lib/share-image';
|
|
8
|
+
export * from './lib/share-model';
|
|
9
|
+
export * from './lib/auth-token';
|
|
10
|
+
export { isAppVersionSupport } from './lib/app-version-support';
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
const u = class u {
|
|
2
|
+
constructor(n) {
|
|
3
|
+
this.errorCode = n.errorCode, this.errorMsg = n.errorMsg;
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
u.UNKNOWN = new u({
|
|
7
|
+
errorCode: 1e3,
|
|
8
|
+
errorMsg: "未知错误"
|
|
9
|
+
}), u.UNSUPPORTED_VERSION = new u({
|
|
10
|
+
errorCode: 1001,
|
|
11
|
+
errorMsg: "当前开吧版本不支持"
|
|
12
|
+
}), u.TIMEOUT = new u({
|
|
13
|
+
errorCode: 1002,
|
|
14
|
+
errorMsg: "执行超时"
|
|
15
|
+
}), u.UNSUPPORTED_BRIDGE_ENV = new u({
|
|
16
|
+
errorCode: 1003,
|
|
17
|
+
errorMsg: "请在开吧app内执行"
|
|
18
|
+
});
|
|
19
|
+
let l = u;
|
|
20
|
+
const T = () => {
|
|
21
|
+
const e = (r, s, t) => {
|
|
22
|
+
var a = "";
|
|
23
|
+
typeof s == "function" && (t = s, s = {});
|
|
24
|
+
var c = { data: s === void 0 ? null : s };
|
|
25
|
+
if (typeof t == "function") {
|
|
26
|
+
var v = "dscb" + window.dscb++;
|
|
27
|
+
window[v] = t, c._dscbstub = v;
|
|
28
|
+
}
|
|
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
|
+
return a;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(a || "{}").data;
|
|
33
|
+
} catch {
|
|
34
|
+
console.error("callHandle异常,JSON.parse错误");
|
|
35
|
+
}
|
|
36
|
+
}, n = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, i = (() => {
|
|
37
|
+
const r = [], s = setInterval(() => {
|
|
38
|
+
n() && (clearInterval(s), r.forEach((t) => {
|
|
39
|
+
e.apply(window, t);
|
|
40
|
+
}), r.length = 0);
|
|
41
|
+
}, 500);
|
|
42
|
+
return (...t) => {
|
|
43
|
+
r.push(t);
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var o = {
|
|
47
|
+
default: void 0,
|
|
48
|
+
// for typescript
|
|
49
|
+
callHandler: function(r, s, t) {
|
|
50
|
+
return n() ? e(r, s, t) : i(r, s, t);
|
|
51
|
+
},
|
|
52
|
+
register: function(r, s, t) {
|
|
53
|
+
var a = t ? window._dsaf : window._dsf;
|
|
54
|
+
window._dsInit || (window._dsInit = !0, setTimeout(function() {
|
|
55
|
+
o.callHandler("_dsb.dsinit");
|
|
56
|
+
}, 0)), typeof s == "object" ? a._obs[r] = s : a[r] = s;
|
|
57
|
+
},
|
|
58
|
+
registerHandler: function(r, s) {
|
|
59
|
+
this.register(r, s, !0);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return (function() {
|
|
63
|
+
if (!window._dsf) {
|
|
64
|
+
var r = {
|
|
65
|
+
//保存JS同步方法
|
|
66
|
+
_dsf: {
|
|
67
|
+
_obs: {}
|
|
68
|
+
},
|
|
69
|
+
//保存JS异步方法
|
|
70
|
+
_dsaf: {
|
|
71
|
+
_obs: {}
|
|
72
|
+
},
|
|
73
|
+
dscb: 0,
|
|
74
|
+
jsBridge: o,
|
|
75
|
+
_handleMessageFromNative: function(t) {
|
|
76
|
+
var a = JSON.parse(t.data), c = {
|
|
77
|
+
id: t.callbackId,
|
|
78
|
+
complete: !0
|
|
79
|
+
}, v = this._dsf[t.method], y = this._dsaf[t.method], N = function(E, S) {
|
|
80
|
+
c.data = E.apply(S, a), o.callHandler("_dsb.returnValue", c);
|
|
81
|
+
}, P = function(E, S) {
|
|
82
|
+
a.push(function(V, I) {
|
|
83
|
+
c.data = V, c.complete = I !== !1, o.callHandler("_dsb.returnValue", c);
|
|
84
|
+
}), E.apply(S, a);
|
|
85
|
+
};
|
|
86
|
+
if (v)
|
|
87
|
+
N(v, this._dsf);
|
|
88
|
+
else if (y)
|
|
89
|
+
P(y, this._dsaf);
|
|
90
|
+
else {
|
|
91
|
+
var A = t.method.split(".");
|
|
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, _);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (g = this._dsaf._obs, _ = g[O] || {}, f = _[m], f && typeof f == "function") {
|
|
99
|
+
P(f, _);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
for (var s in r)
|
|
106
|
+
window[s] = r[s];
|
|
107
|
+
}
|
|
108
|
+
})(), o;
|
|
109
|
+
}, b = ((e) => /(kb)/i.test(e) ? T() : {
|
|
110
|
+
registerHandler(n, i) {
|
|
111
|
+
throw l.UNSUPPORTED_BRIDGE_ENV;
|
|
112
|
+
},
|
|
113
|
+
callHandler(n, i, o) {
|
|
114
|
+
throw l.UNSUPPORTED_BRIDGE_ENV;
|
|
115
|
+
}
|
|
116
|
+
})(window?.navigator?.userAgent), k = (e) => new Promise((n, i) => {
|
|
117
|
+
try {
|
|
118
|
+
b.registerHandler(e.name, e.handler), e.success?.(), n();
|
|
119
|
+
} catch (o) {
|
|
120
|
+
e.fail?.(o), i(o);
|
|
121
|
+
} finally {
|
|
122
|
+
e.complete?.();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
function p(e) {
|
|
126
|
+
const n = (i) => {
|
|
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));
|
|
132
|
+
};
|
|
133
|
+
i.timeout && setTimeout(() => {
|
|
134
|
+
s(l.TIMEOUT);
|
|
135
|
+
}, i.timeout);
|
|
136
|
+
try {
|
|
137
|
+
b.callHandler(i.name, i.params, (t) => {
|
|
138
|
+
let a;
|
|
139
|
+
try {
|
|
140
|
+
a = typeof t == "string" ? JSON.parse(t.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : t;
|
|
141
|
+
} catch {
|
|
142
|
+
a = null;
|
|
143
|
+
}
|
|
144
|
+
r(a);
|
|
145
|
+
});
|
|
146
|
+
} catch (t) {
|
|
147
|
+
s(t);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return new Promise((i, o) => {
|
|
151
|
+
n({
|
|
152
|
+
name: e.name,
|
|
153
|
+
params: e.params,
|
|
154
|
+
timeout: e.timeout,
|
|
155
|
+
success: (r) => {
|
|
156
|
+
e.success?.(r), e.complete?.(), i(r);
|
|
157
|
+
},
|
|
158
|
+
fail: (r) => {
|
|
159
|
+
e.fail?.(r), e.complete?.(), o(r);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
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) {
|
|
166
|
+
return new Promise(async (i, o) => {
|
|
167
|
+
try {
|
|
168
|
+
const r = await n();
|
|
169
|
+
e.success?.(r), i(r);
|
|
170
|
+
} catch (r) {
|
|
171
|
+
const s = r?.errorCode ? r : new l({ errorCode: l.UNKNOWN.errorCode, errorMsg: String(r) });
|
|
172
|
+
e.fail?.(s), o(s);
|
|
173
|
+
} finally {
|
|
174
|
+
e.complete?.();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function R(e) {
|
|
179
|
+
let n;
|
|
180
|
+
return function(...i) {
|
|
181
|
+
return n || (n = e(...i), Promise.resolve(n).catch(() => {
|
|
182
|
+
n = void 0;
|
|
183
|
+
}), n);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const H = R(() => p({
|
|
187
|
+
name: "OpenActRequest",
|
|
188
|
+
params: {
|
|
189
|
+
// 这个函数只能使用35, 而不能使用新提供的60001, 这是因为写这个sdk的时候, 60001 也没有提供!!!
|
|
190
|
+
type: 35,
|
|
191
|
+
data: {}
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
function U(e) {
|
|
195
|
+
return d(e, async () => (await H()).vcode >= e.minVersion);
|
|
196
|
+
}
|
|
197
|
+
function w(e, n) {
|
|
198
|
+
return (...i) => U({
|
|
199
|
+
minVersion: e.minVersion
|
|
200
|
+
}).then((o) => o ? n(...i) : Promise.reject(new l({
|
|
201
|
+
errorCode: l.UNSUPPORTED_VERSION.errorCode,
|
|
202
|
+
errorMsg: `最低版本要求${e.minVersion}`
|
|
203
|
+
})));
|
|
204
|
+
}
|
|
205
|
+
class q {
|
|
206
|
+
}
|
|
207
|
+
const J = R((e) => d(
|
|
208
|
+
e || {},
|
|
209
|
+
w({ minVersion: 80801 }, () => p({
|
|
210
|
+
name: "OpenActRequest",
|
|
211
|
+
params: {
|
|
212
|
+
type: 60001,
|
|
213
|
+
data: {}
|
|
214
|
+
}
|
|
215
|
+
}))
|
|
216
|
+
));
|
|
217
|
+
function M(e) {
|
|
218
|
+
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
219
|
+
return {};
|
|
220
|
+
const n = {};
|
|
221
|
+
return Object.keys(e).forEach((i) => {
|
|
222
|
+
const o = e[i];
|
|
223
|
+
o !== void 0 && (n[i] = o);
|
|
224
|
+
}), n;
|
|
225
|
+
}
|
|
226
|
+
function B(e) {
|
|
227
|
+
return d(
|
|
228
|
+
e,
|
|
229
|
+
w({ minVersion: 80801 }, async () => p({
|
|
230
|
+
name: "OpenActRequest",
|
|
231
|
+
params: {
|
|
232
|
+
type: 60400,
|
|
233
|
+
data: M({
|
|
234
|
+
/** 事件名 */
|
|
235
|
+
eventId: e.eventName,
|
|
236
|
+
/** 上报值 */
|
|
237
|
+
trackParams: e.eventParams,
|
|
238
|
+
/** 开始结束类型传递 */
|
|
239
|
+
ExtEventType: e.eventType
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
}))
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
function G(e) {
|
|
246
|
+
return d(
|
|
247
|
+
{ ...e },
|
|
248
|
+
w({ minVersion: 80801 }, async () => p({
|
|
249
|
+
name: "OpenActRequest",
|
|
250
|
+
params: {
|
|
251
|
+
type: 60300,
|
|
252
|
+
data: e
|
|
253
|
+
}
|
|
254
|
+
}))
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const x = (e) => d(
|
|
258
|
+
e,
|
|
259
|
+
w({ minVersion: 80801 }, async () => p({
|
|
260
|
+
name: "OpenActRequest",
|
|
261
|
+
params: {
|
|
262
|
+
type: 60500,
|
|
263
|
+
data: e
|
|
264
|
+
}
|
|
265
|
+
}))
|
|
266
|
+
), h = "SHARE_EVENT_NAME";
|
|
267
|
+
class F {
|
|
268
|
+
}
|
|
269
|
+
function K(e) {
|
|
270
|
+
return d(e, async () => k({
|
|
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 });
|
|
274
|
+
}
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
function $(e) {
|
|
278
|
+
return d(
|
|
279
|
+
e,
|
|
280
|
+
w({ minVersion: 80801 }, async () => (window.dispatchEvent(new Event(h)), p({
|
|
281
|
+
name: "OpenActRequest",
|
|
282
|
+
params: {
|
|
283
|
+
type: 60500,
|
|
284
|
+
data: e
|
|
285
|
+
}
|
|
286
|
+
})))
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
function j(e) {
|
|
290
|
+
return window.addEventListener(h, e), () => {
|
|
291
|
+
window.removeEventListener(h, e);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
var C = /* @__PURE__ */ ((e) => (e.Silent = "silent", e.Force = "force", e))(C || {});
|
|
295
|
+
class L {
|
|
296
|
+
}
|
|
297
|
+
async function W(e) {
|
|
298
|
+
return d(
|
|
299
|
+
e || {},
|
|
300
|
+
w({ minVersion: 80801 }, async () => (await p({
|
|
301
|
+
name: "OpenActRequest",
|
|
302
|
+
params: { type: e.mode === "silent" ? 60100 : 60101 }
|
|
303
|
+
})).data || null)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
export {
|
|
307
|
+
q as AppBaseInfo,
|
|
308
|
+
F as AppShareModel,
|
|
309
|
+
C as AuthMode,
|
|
310
|
+
L as AuthToken,
|
|
311
|
+
l as BridgeCode,
|
|
312
|
+
D as IS_KB_APP_ENV,
|
|
313
|
+
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,
|
|
320
|
+
k as registerNativeApiHandler,
|
|
321
|
+
B as reportGetui,
|
|
322
|
+
G as runAction,
|
|
323
|
+
x as shareImage
|
|
324
|
+
};
|
|
@@ -0,0 +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"})}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CallbackOptions } from './callback-options';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 是否能用某个api(根据版本号来判断)
|
|
5
|
+
* 每个api都有一个当前app环境能使用的版本号要求
|
|
6
|
+
* @example
|
|
7
|
+
* **示例代码**
|
|
8
|
+
```js
|
|
9
|
+
import { isAppVersionSupport } from '@kbapp/market-partner-sdk';
|
|
10
|
+
|
|
11
|
+
isAppVersionSupport({
|
|
12
|
+
minVersion: 80711,
|
|
13
|
+
success(result: boolean) {
|
|
14
|
+
console.log('是否能使用', result)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
```
|
|
18
|
+
*/
|
|
19
|
+
export declare function isAppVersionSupport(params: {
|
|
20
|
+
minVersion: number;
|
|
21
|
+
} & CallbackOptions<boolean>): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @description 装饰器. 检查app版本是否支持某个api, 如果不支持, 则抛出错误
|
|
25
|
+
* @example
|
|
26
|
+
* **示例代码**
|
|
27
|
+
```js
|
|
28
|
+
import { decorateAppVersionSupport } from '@kbapp/market-partner-sdk';
|
|
29
|
+
|
|
30
|
+
const onTapLogin = decorateAppVersionSupport({ minVersion: 80711 }, () => {
|
|
31
|
+
console.log('当前版本号大于80711')
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
*/
|
|
35
|
+
export declare function decorateAppVersionSupport<Callback extends (...params: any[]) => any>(config: {
|
|
36
|
+
minVersion: number;
|
|
37
|
+
}, callback: Callback): (...params: Parameters<Callback>) => Promise<any>;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @description 登录信息
|
|
15
|
+
*/
|
|
16
|
+
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;
|
|
24
|
+
/** 登录凭证, 当 code === 0 的时候返回 */
|
|
25
|
+
token: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @description 获取开吧 登录授权凭证
|
|
30
|
+
* @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
|
|
31
|
+
* @example
|
|
32
|
+
* **示例代码**
|
|
33
|
+
```js
|
|
34
|
+
import { getAuthToken } from '@kbapp/market-partner-sdk';
|
|
35
|
+
|
|
36
|
+
getAuthToken({
|
|
37
|
+
mode: 'force',
|
|
38
|
+
success(authToken: AppAuthToken) {
|
|
39
|
+
if (authToken.code === 0) {
|
|
40
|
+
console.log(authToken.token)
|
|
41
|
+
} else {
|
|
42
|
+
console.log('未登录')
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const loginInfo: AppAuthToken = await getAppLoginUserInfo()
|
|
48
|
+
|
|
49
|
+
if (authToken.code === 0) {
|
|
50
|
+
console.log(authToken.token)
|
|
51
|
+
} else {
|
|
52
|
+
console.log('未登录')
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
*/
|
|
56
|
+
export declare function getAuthToken(params: {
|
|
57
|
+
mode: AuthMode;
|
|
58
|
+
} & CallbackOptions<AuthToken>): Promise<AuthToken>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class BridgeCode {
|
|
2
|
+
/** 错误码 */
|
|
3
|
+
errorCode: number;
|
|
4
|
+
/** 错误信息 */
|
|
5
|
+
errorMsg: string;
|
|
6
|
+
constructor(params: {
|
|
7
|
+
errorCode: number;
|
|
8
|
+
errorMsg: string;
|
|
9
|
+
});
|
|
10
|
+
static UNKNOWN: BridgeCode;
|
|
11
|
+
static UNSUPPORTED_VERSION: BridgeCode;
|
|
12
|
+
static TIMEOUT: BridgeCode;
|
|
13
|
+
static UNSUPPORTED_BRIDGE_ENV: BridgeCode;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BridgeCode } from './bridge-code';
|
|
2
|
+
export type CallbackOptions<Success = void, Fail = BridgeCode> = {
|
|
3
|
+
/** 成功回调 */
|
|
4
|
+
success?: (res: Success) => void;
|
|
5
|
+
/** 失败回调 */
|
|
6
|
+
fail?: (error: Fail) => void;
|
|
7
|
+
/** 同时触发 */
|
|
8
|
+
complete?: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function wrapCallbackPromise<T>(params: CallbackOptions<T>, executor: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CallbackOptions } from './callback-options';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 开吧app基础信息
|
|
5
|
+
*/
|
|
6
|
+
export declare class AppBaseInfo {
|
|
7
|
+
/** 例如iOS */
|
|
8
|
+
do: string;
|
|
9
|
+
/** 例如iPhone11,2 */
|
|
10
|
+
db: string;
|
|
11
|
+
/** 例如15.5 */
|
|
12
|
+
dv: string;
|
|
13
|
+
/** 版本号.例如69011 */
|
|
14
|
+
vcode: number;
|
|
15
|
+
/** 版本号.例如6.90.11 */
|
|
16
|
+
v: string;
|
|
17
|
+
/** 未知 */
|
|
18
|
+
source: number;
|
|
19
|
+
/** 电台id */
|
|
20
|
+
siteId: number;
|
|
21
|
+
/** 用户id.当登录时返回 */
|
|
22
|
+
userId?: number;
|
|
23
|
+
/** 未知 */
|
|
24
|
+
cid: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @description 获取开吧APP基础信息
|
|
29
|
+
* @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
|
|
30
|
+
* @example
|
|
31
|
+
* **示例代码**
|
|
32
|
+
```js
|
|
33
|
+
import { getAppBaseInfo, AppBaseInfo } from '@kbapp/market-partner-sdk';
|
|
34
|
+
|
|
35
|
+
getAppBaseInfo({
|
|
36
|
+
success(deviceInfo: AppBaseInfo) {
|
|
37
|
+
console.log(deviceInfo)
|
|
38
|
+
},
|
|
39
|
+
fail(error) {
|
|
40
|
+
console.error(error)
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
getAppBaseInfo().then((deviceInfo: AppBaseInfo) => {
|
|
45
|
+
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
*/
|
|
49
|
+
export declare const getAppBaseInfo: (params?: CallbackOptions<AppBaseInfo> | undefined) => Promise<AppBaseInfo>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CallbackOptions } from './callback-options';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 上报数据埋点到个推
|
|
5
|
+
* @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
|
|
6
|
+
* @example
|
|
7
|
+
* **示例代码**
|
|
8
|
+
```js
|
|
9
|
+
import { reportGetui } from '@kbapp/market-partner-sdk';
|
|
10
|
+
|
|
11
|
+
reportGetui({
|
|
12
|
+
eventName: 'event_name',
|
|
13
|
+
eventParams: {
|
|
14
|
+
test_param: 'test_value',
|
|
15
|
+
},
|
|
16
|
+
success() {
|
|
17
|
+
console.log('上报成功')
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
*/
|
|
22
|
+
export declare function reportGetui(params: {
|
|
23
|
+
/** 事件名 */
|
|
24
|
+
eventName: string;
|
|
25
|
+
/** 上报值 */
|
|
26
|
+
eventParams?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
/** 开始结束类型传递 */
|
|
30
|
+
eventType?: 'Begin' | 'End';
|
|
31
|
+
} & CallbackOptions<void>): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CallbackOptions } from './callback-options';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 执行统一跳转页面标准
|
|
5
|
+
* @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
|
|
6
|
+
* @example
|
|
7
|
+
* **示例代码**
|
|
8
|
+
```js
|
|
9
|
+
import { runAction } from '@kbapp/market-partner-sdk';
|
|
10
|
+
|
|
11
|
+
runAction({
|
|
12
|
+
action: 'pageWeb',
|
|
13
|
+
actionParams: {
|
|
14
|
+
url: 'https://www.baidu.com',
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
```
|
|
18
|
+
*/
|
|
19
|
+
export declare function runAction(params: {
|
|
20
|
+
action: string;
|
|
21
|
+
actionParams?: Record<string, any>;
|
|
22
|
+
} & CallbackOptions): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CallbackOptions } from './callback-options';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @description 分享图片
|
|
5
|
+
* @version 开吧APP:80801开始支持,低版本需开发者做兼容处理
|
|
6
|
+
* @example
|
|
7
|
+
* **示例代码**
|
|
8
|
+
```js
|
|
9
|
+
import { shareImage } from '@kbapp/market-partner-sdk';
|
|
10
|
+
|
|
11
|
+
shareImage({
|
|
12
|
+
imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png'
|
|
13
|
+
})
|
|
14
|
+
```
|
|
15
|
+
*/
|
|
16
|
+
export declare const shareImage: (params: {
|
|
17
|
+
imageUrl: string;
|
|
18
|
+
} & CallbackOptions<void>) => Promise<void>;
|