@jolibox/implement 1.1.4-beta.9 → 1.1.4
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/.rush/temp/package-deps_build.json +33 -33
- package/dist/{h5 → common}/ads/ads-action-detection.d.ts +3 -1
- package/dist/{h5 → common}/ads/anti-cheating.d.ts +2 -2
- package/dist/common/ads/channel-policy.d.ts +26 -0
- package/dist/{h5 → common}/ads/index.d.ts +12 -3
- package/dist/common/context/index.d.ts +2 -0
- package/dist/common/http/uuid.d.ts +2 -2
- package/dist/common/http/xua.d.ts +0 -15
- package/dist/common/report/base-tracker.d.ts +10 -1
- package/dist/common/report/errors/index.d.ts +2 -2
- package/dist/common/report/task-track/index.d.ts +3 -0
- package/dist/common/report/types.d.ts +1 -54
- package/dist/h5/api/index.d.ts +1 -0
- package/dist/h5/http/index.d.ts +3 -3
- package/dist/h5/report/index.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +3 -5033
- package/dist/index.native.js +3 -3750
- package/dist/native/api/keyboard.d.ts +9 -3
- package/dist/native/network/index.d.ts +0 -3
- package/esbuild.config.js +1 -1
- package/implement.build.log +0 -9
- package/implementation.build.log +9 -0
- package/package.json +3 -3
- package/src/{h5 → common}/ads/ads-action-detection.ts +4 -4
- package/src/{h5 → common}/ads/anti-cheating.ts +2 -4
- package/src/common/ads/channel-policy.ts +52 -0
- package/src/{h5 → common}/ads/index.ts +39 -45
- package/src/common/api-factory/index.ts +3 -3
- package/src/common/context/index.ts +20 -11
- package/src/common/http/uuid.ts +2 -10
- package/src/common/http/xua.ts +2 -69
- package/src/common/report/base-tracker.ts +40 -44
- package/src/common/report/errors/index.ts +3 -3
- package/src/common/report/errors/report/listeners.ts +0 -2
- package/src/common/report/task-track/index.ts +63 -14
- package/src/common/report/track.ts +2 -2
- package/src/common/report/types.ts +1 -63
- package/src/h5/api/ads.ts +24 -0
- package/src/h5/api/get-system-info.ts +5 -1
- package/src/h5/api/index.ts +1 -0
- package/src/h5/http/index.ts +24 -28
- package/src/h5/http/utils/__tests__/xua.test.ts +1 -1
- package/src/h5/http/utils/session.ts +1 -1
- package/src/h5/report/errors/index.ts +1 -1
- package/src/h5/report/event-tracker.ts +1 -1
- package/src/h5/report/index.ts +4 -2
- package/src/index.ts +0 -1
- package/src/native/api/ads.ts +32 -8
- package/src/native/api/get-system-info.ts +5 -2
- package/src/native/api/keyboard.ts +13 -13
- package/src/native/bootstrap/index.ts +0 -1
- package/src/native/network/index.ts +11 -4
- package/src/native/report/index.ts +2 -2
- package/src/native/types/native-method-map.d.ts +11 -0
- package/dist/common/report/errors/error-types.d.ts +0 -122
- package/src/common/report/errors/error-types.ts +0 -206
- package/src/h5/http/utils/__tests__/uuid.test.ts +0 -16
- /package/dist/h5/{http/utils/__tests__/uuid.test.d.ts → api/ads.d.ts} +0 -0
|
@@ -1,51 +1,18 @@
|
|
|
1
1
|
import { context } from '@/common/context';
|
|
2
2
|
import { logger } from '@jolibox/common';
|
|
3
|
-
import { IDevice, IPage, IEventPackage, IEvent, EProject } from '
|
|
3
|
+
import { IDevice, IPage, IEventPackage, IEvent, EProject, serializeEventPackage } from '@jolibox/common';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'appVersion',
|
|
11
|
-
'appId',
|
|
12
|
-
'model',
|
|
13
|
-
'brand',
|
|
14
|
-
'uuid',
|
|
15
|
-
'jsSdkVersion',
|
|
16
|
-
'extra'
|
|
17
|
-
];
|
|
18
|
-
function serializeObject<T>(obj: T, order: (keyof T)[]): any[] {
|
|
19
|
-
return order.map((key) => {
|
|
20
|
-
if (key === 'params' && obj[key]) {
|
|
21
|
-
const params = obj[key] as Record<string, any>;
|
|
22
|
-
return Object.keys(params).reduce((acc, k) => {
|
|
23
|
-
acc[k] = String(params[k]);
|
|
24
|
-
return acc;
|
|
25
|
-
}, {} as Record<string, any>);
|
|
26
|
-
}
|
|
27
|
-
return obj[key];
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function serializeEvent(event: IEvent): any[] {
|
|
32
|
-
const location = event.location ? serializeObject(event.location, keysOfPage) : null;
|
|
33
|
-
const target = event.target ? serializeObject(event.target, keysOfPage) : null;
|
|
34
|
-
|
|
35
|
-
// 定义IEvent的序列化顺序
|
|
36
|
-
return serializeObject({ ...event, location, target }, keysOfEvent);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function serializeEventPackage(eventPackage: IEventPackage): any[] {
|
|
40
|
-
// 序列化事件数组
|
|
41
|
-
const events = eventPackage.events.map((event) => serializeEvent(event));
|
|
42
|
-
|
|
43
|
-
// 定义IDevice的序列化顺序
|
|
44
|
-
const device = serializeObject(eventPackage.device, keysOfDevice);
|
|
45
|
-
|
|
46
|
-
return [eventPackage.protocolVersion, events, device, eventPackage.project];
|
|
5
|
+
interface ISamplesConfig {
|
|
6
|
+
samples: {
|
|
7
|
+
[sampleRate: number]: string[];
|
|
8
|
+
};
|
|
9
|
+
cluster: number;
|
|
47
10
|
}
|
|
48
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Base class for event tracker, all the event tracker should inherit from this class
|
|
13
|
+
* Send event to oss reporter
|
|
14
|
+
* @abstract
|
|
15
|
+
*/
|
|
49
16
|
export abstract class EventTracker {
|
|
50
17
|
deviceInfo: IDevice | null = null;
|
|
51
18
|
|
|
@@ -54,6 +21,7 @@ export abstract class EventTracker {
|
|
|
54
21
|
abstract doReport<T extends Record<string, unknown>>(event: unknown[], extra?: T): void;
|
|
55
22
|
|
|
56
23
|
private pastTrackings: boolean[] = [];
|
|
24
|
+
private samplesConfig: ISamplesConfig | null = null;
|
|
57
25
|
|
|
58
26
|
private pushPastTracking = (tracking: boolean) => {
|
|
59
27
|
this.pastTrackings.push(tracking);
|
|
@@ -62,6 +30,10 @@ export abstract class EventTracker {
|
|
|
62
30
|
}
|
|
63
31
|
};
|
|
64
32
|
|
|
33
|
+
constructor() {
|
|
34
|
+
this.fetchSamplesConfig();
|
|
35
|
+
}
|
|
36
|
+
|
|
65
37
|
public get networkIsOk() {
|
|
66
38
|
// in the past 10 trackings, at least 60% of them are successful
|
|
67
39
|
return (
|
|
@@ -70,6 +42,26 @@ export abstract class EventTracker {
|
|
|
70
42
|
);
|
|
71
43
|
}
|
|
72
44
|
|
|
45
|
+
private async fetchSamplesConfig() {
|
|
46
|
+
const host = context.testMode ? 'https://stg-api.jolibox.com' : 'https://api.jolibox.com';
|
|
47
|
+
const path = `${host}/api/fe-configs/js-sdk/samples-config`;
|
|
48
|
+
const samplesConfig = (await (await fetch(path)).json()) as ISamplesConfig;
|
|
49
|
+
this.samplesConfig = samplesConfig;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private checkIsSampled(event: IEvent) {
|
|
53
|
+
if (!this.samplesConfig) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const { samples } = this.samplesConfig;
|
|
57
|
+
for (const [sampleRate, events] of Object.entries(samples)) {
|
|
58
|
+
if (events.includes(event.name)) {
|
|
59
|
+
return Math.floor(Math.random() * 101) < parseFloat(sampleRate);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
73
65
|
getDevice(): IDevice {
|
|
74
66
|
const { nativeSDKVersion, jssdkVersion } = context.sdkInfo;
|
|
75
67
|
return {
|
|
@@ -98,6 +90,10 @@ export abstract class EventTracker {
|
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
async trackEvent(event: IEvent, project: EProject, extraInfo?: Record<string, unknown>) {
|
|
93
|
+
// check if the event is sampled
|
|
94
|
+
if (this.checkIsSampled(event)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
101
97
|
const location = event.location ? event.location : await this.getLocation();
|
|
102
98
|
const target = event.target || null;
|
|
103
99
|
const extra = event.extra || null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './report';
|
|
2
|
-
import { APIError,
|
|
2
|
+
import { APIError, UserValidateError } from '@jolibox/common';
|
|
3
3
|
|
|
4
4
|
export function formatErrorCode(method: string, code?: number) {
|
|
5
5
|
return `[${method}]:${code}`;
|
|
@@ -13,8 +13,8 @@ export const createAPIError = (
|
|
|
13
13
|
return new APIError(params?.errMsg ?? error.msg ?? '', error.code, error.type);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export const
|
|
17
|
-
return new
|
|
16
|
+
export const createUserValidateAPIError = (msg: string) => {
|
|
17
|
+
return new UserValidateError(msg);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export { errorReportEmitter, ErrorData } from './report';
|
|
@@ -30,8 +30,6 @@ const innerErrorReport = (
|
|
|
30
30
|
options: ErrorOptions | GlobalErrorOptions = {},
|
|
31
31
|
isFromUser: boolean
|
|
32
32
|
) => {
|
|
33
|
-
const priority = (error as BaseError).priority ?? 'P1';
|
|
34
|
-
|
|
35
33
|
const common = {
|
|
36
34
|
user_id: context.hostUserInfo?.uid ?? '',
|
|
37
35
|
device_id: context.deviceInfo.did ?? '',
|
|
@@ -22,15 +22,15 @@ export abstract class TaskTracker {
|
|
|
22
22
|
this.reporter({
|
|
23
23
|
event: 'PLAY_GAME',
|
|
24
24
|
params: {
|
|
25
|
-
duration
|
|
25
|
+
duration
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
this.tracker('PlayGame', { duration
|
|
28
|
+
this.tracker('PlayGame', { duration });
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
abstract reporter(point: TaskPoint): void;
|
|
32
32
|
abstract tracker(point: TrackEvent, info: Record<string, unknown> | null): void;
|
|
33
|
-
constructor(eventEmitter: EventEmitter<{ visible: [boolean] }>, interval?: number) {
|
|
33
|
+
constructor(readonly eventEmitter: EventEmitter<{ visible: [boolean] }>, interval?: number) {
|
|
34
34
|
this.interval = interval ?? 5 * 1000;
|
|
35
35
|
|
|
36
36
|
eventEmitter.on('visible', (visible) => {
|
|
@@ -43,10 +43,10 @@ export abstract class TaskTracker {
|
|
|
43
43
|
event: 'OPEN_GAME',
|
|
44
44
|
params: {
|
|
45
45
|
timestamp: Date.now(),
|
|
46
|
-
duration: duration ?? 0
|
|
46
|
+
duration: duration ?? 0
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
this.tracker('OpenGame', { duration: duration ?? 0
|
|
49
|
+
this.tracker('OpenGame', { duration: duration ?? 0 });
|
|
50
50
|
this.timer.start();
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -55,22 +55,24 @@ export abstract class TaskTracker {
|
|
|
55
55
|
event: 'CLOSE_GAME',
|
|
56
56
|
params: {
|
|
57
57
|
timestamp: Date.now(),
|
|
58
|
-
duration
|
|
58
|
+
duration
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
this.tracker('CloseGame', { duration
|
|
61
|
+
this.tracker('CloseGame', { duration });
|
|
62
62
|
this.timer.stop();
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
private createRAFTimer(callback: (duration: number) => void) {
|
|
66
|
-
let lastTime =
|
|
66
|
+
let lastTime = Date.now();
|
|
67
67
|
let rafId: number;
|
|
68
|
+
let intervalId: number;
|
|
68
69
|
let isRunning = false;
|
|
69
70
|
let totalTime = 0;
|
|
70
71
|
|
|
71
|
-
const tick = (
|
|
72
|
+
const tick = () => {
|
|
72
73
|
if (!isRunning) return;
|
|
73
74
|
|
|
75
|
+
const currentTime = Date.now();
|
|
74
76
|
const deltaTime = currentTime - lastTime;
|
|
75
77
|
if (deltaTime >= this.interval) {
|
|
76
78
|
if (this.visible) {
|
|
@@ -83,19 +85,66 @@ export abstract class TaskTracker {
|
|
|
83
85
|
rafId = requestAnimationFrame(tick);
|
|
84
86
|
};
|
|
85
87
|
|
|
88
|
+
const startInterval = () => {
|
|
89
|
+
stopRAF();
|
|
90
|
+
lastTime = Date.now();
|
|
91
|
+
intervalId = window.setInterval(() => {
|
|
92
|
+
if (!isRunning) return;
|
|
93
|
+
const currentTime = Date.now();
|
|
94
|
+
const deltaTime = currentTime - lastTime;
|
|
95
|
+
if (deltaTime >= this.interval) {
|
|
96
|
+
lastTime = currentTime;
|
|
97
|
+
}
|
|
98
|
+
}, this.interval) as unknown as number;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const startRAF = () => {
|
|
102
|
+
stopInterval();
|
|
103
|
+
lastTime = Date.now();
|
|
104
|
+
rafId = requestAnimationFrame(tick);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const stopRAF = () => {
|
|
108
|
+
if (rafId) {
|
|
109
|
+
cancelAnimationFrame(rafId);
|
|
110
|
+
rafId = 0;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const stopInterval = () => {
|
|
115
|
+
if (intervalId) {
|
|
116
|
+
clearInterval(intervalId);
|
|
117
|
+
intervalId = 0;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
this.eventEmitter.on('visible', (visible) => {
|
|
122
|
+
if (!isRunning) return;
|
|
123
|
+
|
|
124
|
+
console.log('visible', visible);
|
|
125
|
+
if (visible) {
|
|
126
|
+
startRAF();
|
|
127
|
+
} else {
|
|
128
|
+
startInterval();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const originVisible = this.visible;
|
|
86
133
|
return {
|
|
87
134
|
start() {
|
|
88
135
|
if (!isRunning) {
|
|
89
136
|
isRunning = true;
|
|
90
|
-
|
|
91
|
-
|
|
137
|
+
if (originVisible) {
|
|
138
|
+
startRAF();
|
|
139
|
+
} else {
|
|
140
|
+
startInterval();
|
|
141
|
+
}
|
|
92
142
|
}
|
|
93
143
|
},
|
|
94
144
|
stop() {
|
|
95
145
|
isRunning = false;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
146
|
+
stopRAF();
|
|
147
|
+
stopInterval();
|
|
99
148
|
}
|
|
100
149
|
};
|
|
101
150
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { debounce } from '@jolibox/common';
|
|
2
2
|
import { ReportHandler, Track, TrackPerformance, CommonReportConfig } from './types';
|
|
3
3
|
import { PerformanceType, TrackEvent } from '@jolibox/types';
|
|
4
|
-
import {
|
|
4
|
+
import { InternalGlobalJSError } from '@jolibox/common';
|
|
5
5
|
import { reportError } from './errors/report';
|
|
6
6
|
|
|
7
7
|
// Track system event, wrap common config
|
|
@@ -15,7 +15,7 @@ export function createTrack(reportHandler: ReportHandler, common: CommonReportCo
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
if (tag == 'globalJsError') {
|
|
18
|
-
reportError(new
|
|
18
|
+
reportError(new InternalGlobalJSError(JSON.stringify(data))); // window.onerror, 白屏
|
|
19
19
|
} else {
|
|
20
20
|
reportHandler('systemLog', data, webviewId);
|
|
21
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PerformanceType, TrackEvent } from '@jolibox/types';
|
|
2
|
+
import { EProject } from '@jolibox/common';
|
|
2
3
|
|
|
3
4
|
export interface Track {
|
|
4
5
|
(tag: TrackEvent, info: Record<string, unknown> | null): void;
|
|
@@ -25,66 +26,3 @@ export interface CommonReportConfig {
|
|
|
25
26
|
mp_version: string;
|
|
26
27
|
trace_id?: number;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
export enum EventType {
|
|
30
|
-
System = 1000, // used for web sdk
|
|
31
|
-
ErrorTrace = 1001, // used for web sdk
|
|
32
|
-
UserDefined = 1002 // used for web sdk
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface IPage {
|
|
36
|
-
name: string;
|
|
37
|
-
params: Record<string, string | boolean | number | null> | null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface IEvent {
|
|
41
|
-
name: string;
|
|
42
|
-
type: EventType; // use a higher ts version to get static analysis
|
|
43
|
-
location: IPage | null;
|
|
44
|
-
target: IPage | null;
|
|
45
|
-
extra: Record<string, string | boolean | number | null> | null;
|
|
46
|
-
timestamp: number; // in unix timestamp
|
|
47
|
-
userId: string | null; // 没登陆时为空
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export enum EProject {
|
|
51
|
-
MiniGame = 'mini-game',
|
|
52
|
-
MiniDrama = 'mini-drama',
|
|
53
|
-
App = 'app',
|
|
54
|
-
WebSDK = 'web-sdk',
|
|
55
|
-
AppSDK = 'app-sdk'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export enum EPlatform {
|
|
59
|
-
App = 0,
|
|
60
|
-
H5 = 1,
|
|
61
|
-
Weapp = 2,
|
|
62
|
-
Alipay = 3,
|
|
63
|
-
Gcash = 4,
|
|
64
|
-
Dana = 5,
|
|
65
|
-
Umma = 6,
|
|
66
|
-
|
|
67
|
-
WebSDK = 1000,
|
|
68
|
-
AppSDK = 1001,
|
|
69
|
-
|
|
70
|
-
Other = 9999
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface IDevice {
|
|
74
|
-
platform: EPlatform;
|
|
75
|
-
os: string; // for app: Android、iOS
|
|
76
|
-
appVersion: string;
|
|
77
|
-
appId: string; // for external SDK, "1 - game h5", "2 - drama h5", "3 - game h5 ant", "4 - drama h5 ant"
|
|
78
|
-
model: string;
|
|
79
|
-
brand: string;
|
|
80
|
-
uuid: string; // 前端生成的唯一标识,用来串整个埋点
|
|
81
|
-
jsSdkVersion: string | null;
|
|
82
|
-
extra: Record<string, string | boolean | number | null> | null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface IEventPackage {
|
|
86
|
-
protocolVersion: string;
|
|
87
|
-
events: IEvent[];
|
|
88
|
-
device: IDevice;
|
|
89
|
-
project: EProject;
|
|
90
|
-
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JoliboxAdsImpl } from '@/common/ads';
|
|
2
|
+
import { track } from '../report';
|
|
3
|
+
import { tracker as h5Tracker } from '../report/event-tracker';
|
|
4
|
+
import { createCommands } from '@jolibox/common';
|
|
5
|
+
import JoliboxHttpClient from '../http';
|
|
6
|
+
|
|
7
|
+
const commands = createCommands();
|
|
8
|
+
const ads = new JoliboxAdsImpl(track, new JoliboxHttpClient(), () => h5Tracker.networkIsOk);
|
|
9
|
+
|
|
10
|
+
commands.registerCommand('AdsSDK.init', (config) => {
|
|
11
|
+
ads.init(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
commands.registerCommand('AdsSDK.adConfig', (params) => {
|
|
15
|
+
ads.adConfig(params);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
commands.registerCommand('AdsSDK.adBreak', (params) => {
|
|
19
|
+
ads.adBreak(params);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
commands.registerCommand('AdsSDK.adUnit', (params) => {
|
|
23
|
+
ads.adUnit(params);
|
|
24
|
+
});
|
|
@@ -13,7 +13,11 @@ const getSystemInfo = () => {
|
|
|
13
13
|
system: context.deviceInfo.system,
|
|
14
14
|
platform: context.deviceInfo.platform,
|
|
15
15
|
brand: context.deviceInfo.brand,
|
|
16
|
-
pixelRatio: context.deviceInfo.pixelRatio
|
|
16
|
+
pixelRatio: context.deviceInfo.pixelRatio,
|
|
17
|
+
language: context.deviceInfo.lang,
|
|
18
|
+
version: context.sdkInfo.jssdkVersion,
|
|
19
|
+
appName: context.hostInfo?.appName,
|
|
20
|
+
SDKVersion: context.sdkInfo.nativeSDKVersion
|
|
17
21
|
} as ISystemInfo;
|
|
18
22
|
|
|
19
23
|
const version = context.hostInfo?.version;
|
package/src/h5/api/index.ts
CHANGED
package/src/h5/http/index.ts
CHANGED
|
@@ -25,8 +25,7 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
25
25
|
private xua = xUserAgent();
|
|
26
26
|
|
|
27
27
|
private getJoliSource = () => {
|
|
28
|
-
|
|
29
|
-
return urlParams.get('joliSource') ?? null;
|
|
28
|
+
return context.joliSource;
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
// private getApiBaseURL = () => {
|
|
@@ -41,30 +40,29 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
41
40
|
|
|
42
41
|
async get<T>(
|
|
43
42
|
path: string,
|
|
44
|
-
{
|
|
45
|
-
query,
|
|
46
|
-
headers,
|
|
47
|
-
timeout
|
|
48
|
-
}: {
|
|
43
|
+
configs?: {
|
|
49
44
|
query?: Record<string, string>;
|
|
50
45
|
headers?: Record<string, string>;
|
|
51
46
|
timeout?: number;
|
|
52
47
|
}
|
|
53
48
|
) {
|
|
54
|
-
const
|
|
55
|
-
|
|
49
|
+
const { query, timeout } = configs ?? {};
|
|
50
|
+
let { headers } = configs ?? {};
|
|
51
|
+
const searchParams = query ? new URLSearchParams(query) : null;
|
|
52
|
+
const search = searchParams?.toString();
|
|
56
53
|
const url = `${this.baseUrl}${path}${search ? `?${search}` : ''}`;
|
|
57
54
|
const xua = this.xua;
|
|
58
55
|
const joliSource = this.getJoliSource();
|
|
59
56
|
headers = Object.assign(
|
|
60
57
|
{},
|
|
61
|
-
headers,
|
|
58
|
+
headers ?? {},
|
|
62
59
|
xua ? { 'x-user-agent': xua } : {},
|
|
63
60
|
joliSource ? { 'x-joli-source': joliSource } : {}
|
|
64
61
|
);
|
|
65
62
|
const response = await fetch(url, {
|
|
66
63
|
method: 'GET',
|
|
67
64
|
headers,
|
|
65
|
+
credentials: 'include',
|
|
68
66
|
signal: timeoutFn(timeout ?? 30000)
|
|
69
67
|
});
|
|
70
68
|
return (await response.json()) as T;
|
|
@@ -72,26 +70,23 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
72
70
|
|
|
73
71
|
async post<T = any>(
|
|
74
72
|
path: string,
|
|
75
|
-
{
|
|
76
|
-
data,
|
|
77
|
-
query,
|
|
78
|
-
headers,
|
|
79
|
-
timeout
|
|
80
|
-
}: {
|
|
73
|
+
configs?: {
|
|
81
74
|
data?: any;
|
|
82
75
|
query?: Record<string, string>;
|
|
83
76
|
headers?: Record<string, string>;
|
|
84
77
|
timeout?: number;
|
|
85
78
|
}
|
|
86
79
|
) {
|
|
87
|
-
const
|
|
88
|
-
|
|
80
|
+
const { data, query, timeout } = configs ?? {};
|
|
81
|
+
let { headers } = configs ?? {};
|
|
82
|
+
const searchParams = query ? new URLSearchParams(query) : null;
|
|
83
|
+
const search = searchParams?.toString();
|
|
89
84
|
const url = `${this.baseUrl}${path}${search ? `?${search}` : ''}`;
|
|
90
85
|
const xua = this.xua;
|
|
91
86
|
const joliSource = this.getJoliSource();
|
|
92
87
|
headers = Object.assign(
|
|
93
88
|
{},
|
|
94
|
-
headers,
|
|
89
|
+
headers ?? {},
|
|
95
90
|
{ 'Content-Type': 'application/json' },
|
|
96
91
|
xua ? { 'x-user-agent': xua } : {},
|
|
97
92
|
joliSource ? { 'x-joli-source': joliSource } : {}
|
|
@@ -100,8 +95,10 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
100
95
|
method: 'POST',
|
|
101
96
|
headers,
|
|
102
97
|
body: JSON.stringify(data),
|
|
103
|
-
signal: timeoutFn(timeout ?? 30000)
|
|
98
|
+
signal: timeoutFn(timeout ?? 30000),
|
|
99
|
+
credentials: 'include'
|
|
104
100
|
});
|
|
101
|
+
|
|
105
102
|
const responseContentType = response.headers.get('content-type');
|
|
106
103
|
|
|
107
104
|
// return blob
|
|
@@ -140,11 +137,7 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
140
137
|
|
|
141
138
|
async put<T>(
|
|
142
139
|
path: string,
|
|
143
|
-
{
|
|
144
|
-
data,
|
|
145
|
-
query,
|
|
146
|
-
headers
|
|
147
|
-
}: {
|
|
140
|
+
configs?: {
|
|
148
141
|
data?: any;
|
|
149
142
|
query?: Record<string, string>;
|
|
150
143
|
headers?: Record<string, string>;
|
|
@@ -152,14 +145,16 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
152
145
|
}
|
|
153
146
|
) {
|
|
154
147
|
try {
|
|
155
|
-
const
|
|
156
|
-
|
|
148
|
+
const { data, query, timeout } = configs ?? {};
|
|
149
|
+
let { headers } = configs ?? {};
|
|
150
|
+
const searchParams = query ? new URLSearchParams(query) : null;
|
|
151
|
+
const search = searchParams?.toString();
|
|
157
152
|
const url = `${this.baseUrl}${path}${search ? `?${search}` : ''}`;
|
|
158
153
|
const xua = this.xua;
|
|
159
154
|
const joliSource = this.getJoliSource();
|
|
160
155
|
headers = Object.assign(
|
|
161
156
|
{},
|
|
162
|
-
headers,
|
|
157
|
+
headers ?? {},
|
|
163
158
|
{ 'Content-Type': 'application/json' },
|
|
164
159
|
xua ? { 'x-user-agent': xua } : {},
|
|
165
160
|
joliSource ? { 'x-joli-source': joliSource } : {}
|
|
@@ -167,6 +162,7 @@ export class JoliboxHttpClient implements IHttpClient {
|
|
|
167
162
|
const response = await fetch(url, {
|
|
168
163
|
method: 'PUT',
|
|
169
164
|
headers,
|
|
165
|
+
credentials: 'include',
|
|
170
166
|
body: JSON.stringify(data ?? {}) // 将数据转换为 JSON 字符串
|
|
171
167
|
});
|
|
172
168
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// import { expect, test } from 'jest';
|
|
2
2
|
import { xUserAgent, getAppVersion } from '../../../../common/http/xua';
|
|
3
|
-
import { isValidUUIDV4 } from '
|
|
3
|
+
import { isValidUUIDV4 } from '@jolibox/common';
|
|
4
4
|
|
|
5
5
|
describe('xua', () => {
|
|
6
6
|
it('test xua', () => {
|
|
@@ -5,7 +5,7 @@ import '@/common/report/errors/report/listeners';
|
|
|
5
5
|
import { BaseError, logger } from '@jolibox/common';
|
|
6
6
|
import { errorReportEmitter } from '@/common/report/errors';
|
|
7
7
|
import { ErrorData } from '@/common/report/errors/report';
|
|
8
|
-
import { IEvent, EventType, EProject } from '
|
|
8
|
+
import { IEvent, EventType, EProject } from '@jolibox/common';
|
|
9
9
|
import { tracker } from '../event-tracker';
|
|
10
10
|
import { context } from '@/common/context';
|
|
11
11
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { context } from '@/common/context';
|
|
2
2
|
import { logger } from '@jolibox/common';
|
|
3
|
-
import {
|
|
3
|
+
import { EventTracker } from '@/common/report';
|
|
4
4
|
import JoliboxHttpClient from '@/h5/http';
|
|
5
5
|
|
|
6
6
|
export class H5EventTracker extends EventTracker {
|
package/src/h5/report/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import './errors';
|
|
2
|
-
import { createCommands, EventEmitter,
|
|
3
|
-
import {
|
|
2
|
+
import { createCommands, EventEmitter, isObject, isString } from '@jolibox/common';
|
|
3
|
+
import { EProject, EventType, IEvent } from '@jolibox/common';
|
|
4
|
+
import { CommonReportConfig, createTracks } from '@/common/report';
|
|
4
5
|
import { tracker } from './event-tracker';
|
|
5
6
|
import { H5TaskTracker } from './task-tracker';
|
|
6
7
|
import { context } from '@/common/context';
|
|
@@ -31,6 +32,7 @@ const { track, trackPerformance } = createTracks((...args) => {
|
|
|
31
32
|
mp_id: (_data.mp_id as string) ?? '',
|
|
32
33
|
mp_version: (_data.mp_version as string) ?? ''
|
|
33
34
|
};
|
|
35
|
+
//TODO: 根据上报重要性做采样
|
|
34
36
|
const eventBody: IEvent = {
|
|
35
37
|
name: data.tag,
|
|
36
38
|
type: EventType.System,
|
package/src/index.ts
CHANGED
package/src/native/api/ads.ts
CHANGED
|
@@ -3,27 +3,51 @@ import { createSyncAPI, registerCanIUse } from './base';
|
|
|
3
3
|
|
|
4
4
|
const commands = createCommands();
|
|
5
5
|
|
|
6
|
+
import { IAdsInitParams, JoliboxAdsImpl, IAdConfigParams, IAdBreakParams, IAdUnitParams } from '@/common/ads';
|
|
7
|
+
import { track } from '../report';
|
|
8
|
+
|
|
9
|
+
import { innerFetch as fetch } from '../network';
|
|
10
|
+
import { invokeNative } from '../bootstrap/bridge';
|
|
11
|
+
|
|
12
|
+
const checkNetworkStatus = () => {
|
|
13
|
+
const { data } = invokeNative('getNetworkStatusSync');
|
|
14
|
+
return !!data?.isConnected;
|
|
15
|
+
};
|
|
16
|
+
const ads = new JoliboxAdsImpl(
|
|
17
|
+
track,
|
|
18
|
+
{
|
|
19
|
+
get: <T>(url: string, options?: any) =>
|
|
20
|
+
fetch<T>(url, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
responseType: 'json',
|
|
23
|
+
appendHostCookie: true,
|
|
24
|
+
...options
|
|
25
|
+
}).then((res) => res.response.data as T)
|
|
26
|
+
},
|
|
27
|
+
checkNetworkStatus
|
|
28
|
+
);
|
|
29
|
+
|
|
6
30
|
const adInit = createSyncAPI('adInit', {
|
|
7
|
-
implement: (config) => {
|
|
8
|
-
|
|
31
|
+
implement: (config?: IAdsInitParams) => {
|
|
32
|
+
ads.init(config);
|
|
9
33
|
}
|
|
10
34
|
});
|
|
11
35
|
|
|
12
36
|
const adConfig = createSyncAPI('adConfig', {
|
|
13
|
-
implement: (params) => {
|
|
14
|
-
|
|
37
|
+
implement: (params: IAdConfigParams) => {
|
|
38
|
+
ads.adConfig(params);
|
|
15
39
|
}
|
|
16
40
|
});
|
|
17
41
|
|
|
18
42
|
const adBreak = createSyncAPI('adBreak', {
|
|
19
|
-
implement: (params) => {
|
|
20
|
-
|
|
43
|
+
implement: (params: IAdBreakParams) => {
|
|
44
|
+
ads.adBreak(params);
|
|
21
45
|
}
|
|
22
46
|
});
|
|
23
47
|
|
|
24
48
|
const adUnit = createSyncAPI('adUnit', {
|
|
25
|
-
implement: (params) => {
|
|
26
|
-
|
|
49
|
+
implement: (params: IAdUnitParams) => {
|
|
50
|
+
ads.adUnit(params);
|
|
27
51
|
}
|
|
28
52
|
});
|
|
29
53
|
|