@jolibox/implement 1.1.4-beta.16 → 1.1.4-beta.18

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.
@@ -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 { InternalContextError } from '@jolibox/common';
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 InternalContextError(JSON.stringify(data), 'P0')); // window.onerror, 白屏
18
+ reportError(new InternalGlobalJSError(JSON.stringify(data))); // window.onerror, 白屏
19
19
  } else {
20
20
  reportHandler('systemLog', data, webviewId);
21
21
  }
@@ -25,8 +25,7 @@ export class JoliboxHttpClient implements IHttpClient {
25
25
  private xua = xUserAgent();
26
26
 
27
27
  private getJoliSource = () => {
28
- const urlParams = new URLSearchParams(window.location.search);
29
- return urlParams.get('joliSource') ?? null;
28
+ return context.joliSource;
30
29
  };
31
30
 
32
31
  // private getApiBaseURL = () => {
@@ -41,24 +40,22 @@ 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 searchParams = new URLSearchParams(query);
55
- const search = searchParams.toString();
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
  );
@@ -73,26 +70,23 @@ export class JoliboxHttpClient implements IHttpClient {
73
70
 
74
71
  async post<T = any>(
75
72
  path: string,
76
- {
77
- data,
78
- query,
79
- headers,
80
- timeout
81
- }: {
73
+ configs?: {
82
74
  data?: any;
83
75
  query?: Record<string, string>;
84
76
  headers?: Record<string, string>;
85
77
  timeout?: number;
86
78
  }
87
79
  ) {
88
- const searchParams = new URLSearchParams(query);
89
- const search = searchParams.toString();
80
+ const { data, query, timeout } = configs ?? {};
81
+ let { headers } = configs ?? {};
82
+ const searchParams = query ? new URLSearchParams(query) : null;
83
+ const search = searchParams?.toString();
90
84
  const url = `${this.baseUrl}${path}${search ? `?${search}` : ''}`;
91
85
  const xua = this.xua;
92
86
  const joliSource = this.getJoliSource();
93
87
  headers = Object.assign(
94
88
  {},
95
- headers,
89
+ headers ?? {},
96
90
  { 'Content-Type': 'application/json' },
97
91
  xua ? { 'x-user-agent': xua } : {},
98
92
  joliSource ? { 'x-joli-source': joliSource } : {}
@@ -143,11 +137,7 @@ export class JoliboxHttpClient implements IHttpClient {
143
137
 
144
138
  async put<T>(
145
139
  path: string,
146
- {
147
- data,
148
- query,
149
- headers
150
- }: {
140
+ configs?: {
151
141
  data?: any;
152
142
  query?: Record<string, string>;
153
143
  headers?: Record<string, string>;
@@ -155,14 +145,16 @@ export class JoliboxHttpClient implements IHttpClient {
155
145
  }
156
146
  ) {
157
147
  try {
158
- const searchParams = new URLSearchParams(query);
159
- const search = searchParams.toString();
148
+ const { data, query, timeout } = configs ?? {};
149
+ let { headers } = configs ?? {};
150
+ const searchParams = query ? new URLSearchParams(query) : null;
151
+ const search = searchParams?.toString();
160
152
  const url = `${this.baseUrl}${path}${search ? `?${search}` : ''}`;
161
153
  const xua = this.xua;
162
154
  const joliSource = this.getJoliSource();
163
155
  headers = Object.assign(
164
156
  {},
165
- headers,
157
+ headers ?? {},
166
158
  { 'Content-Type': 'application/json' },
167
159
  xua ? { 'x-user-agent': xua } : {},
168
160
  joliSource ? { 'x-joli-source': joliSource } : {}
@@ -32,7 +32,7 @@ const { track, trackPerformance } = createTracks((...args) => {
32
32
  mp_id: (_data.mp_id as string) ?? '',
33
33
  mp_version: (_data.mp_version as string) ?? ''
34
34
  };
35
- //TODO: 根据上报重要性做聚合
35
+ //TODO: 根据上报重要性做采样
36
36
  const eventBody: IEvent = {
37
37
  name: data.tag,
38
38
  type: EventType.System,
@@ -7,8 +7,12 @@ import { IAdsInitParams, JoliboxAdsImpl, IAdConfigParams, IAdBreakParams, IAdUni
7
7
  import { track } from '../report';
8
8
 
9
9
  import { innerFetch as fetch } from '../network';
10
+ import { invokeNative } from '../bootstrap/bridge';
10
11
 
11
- // TODO: 从network中获取isOK
12
+ const checkNetworkStatus = () => {
13
+ const { data } = invokeNative('getNetworkStatusSync');
14
+ return !!data?.isConnected;
15
+ };
12
16
  const ads = new JoliboxAdsImpl(
13
17
  track,
14
18
  {
@@ -20,7 +24,7 @@ const ads = new JoliboxAdsImpl(
20
24
  ...options
21
25
  }).then((res) => res.response.data as T)
22
26
  },
23
- () => true
27
+ checkNetworkStatus
24
28
  );
25
29
 
26
30
  const adInit = createSyncAPI('adInit', {
@@ -5,11 +5,18 @@ import { context } from '@/common/context';
5
5
  /**
6
6
  * inner fetch
7
7
  */
8
+ const defaultHeaders: Record<string, string> = {
9
+ 'x-user-agent': xUserAgent()
10
+ };
11
+ if (context.hostUserInfo?.token) {
12
+ defaultHeaders['x-joli-token'] = context.hostUserInfo.token;
13
+ }
14
+ if (context.joliSource) {
15
+ defaultHeaders['x-joli-source'] = context.joliSource;
16
+ }
17
+
8
18
  export const innerFetch = createFetch('createRequestTaskSync', 'operateRequestTaskSync', {
9
19
  type: 'inner',
10
20
  baseUrl: context.testMode ? 'https://stg-api.jolibox.com' : 'https://api.jolibox.com',
11
- defaultHeaders: {
12
- 'x-user-agent': xUserAgent(),
13
- 'X-JOLI-TOKEN': context.hostUserInfo?.token ?? ''
14
- }
21
+ defaultHeaders
15
22
  });
@@ -237,6 +237,17 @@ declare global {
237
237
  realNameAuthenticationStatus?: 'uncertified' | 'certified';
238
238
  };
239
239
  }>;
240
+
241
+ getNetworkStatusSync: () => {
242
+ /** 错误消息 */
243
+ errMsg: string;
244
+ /** 错误码 */
245
+ errNo?: number;
246
+ data: {
247
+ isConnected: boolean;
248
+ networkType: 'wifi' | '4g' | '5g' | '3g' | '2g' | 'unknown';
249
+ };
250
+ };
240
251
  }
241
252
 
242
253
  interface NativeEventMap {