@jolibox/implement 1.1.4-beta.15 → 1.1.4-beta.17

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 = () => {
@@ -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 {