@jolibox/implement 1.1.48 → 1.1.50

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -9,3 +9,4 @@ import './ads';
9
9
  import './navigate';
10
10
  import './runtime';
11
11
  import './is-native-support';
12
+ import './call-host-method';
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.48 clean
3
+ > @jolibox/implement@1.1.50 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.48 build:esm
7
+ > @jolibox/implement@1.1.50 build:esm
8
8
  > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
9
9
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.48",
4
+ "version": "1.1.50",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.1.48",
10
- "@jolibox/types": "1.1.48",
11
- "@jolibox/native-bridge": "1.1.48",
12
- "@jolibox/ads": "1.1.48",
9
+ "@jolibox/common": "1.1.50",
10
+ "@jolibox/types": "1.1.50",
11
+ "@jolibox/native-bridge": "1.1.50",
12
+ "@jolibox/ads": "1.1.50",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"
@@ -100,7 +100,7 @@ export const createAPIFactory = (track: Track) => {
100
100
  };
101
101
  } finally {
102
102
  const duration = Date.now() - startTime;
103
- track('apiInvoked', { ...reportExtra, duration, status });
103
+ // track('apiInvoked', { ...reportExtra, duration, status });
104
104
  }
105
105
  };
106
106
  }
@@ -179,7 +179,7 @@ export const createAPIFactory = (track: Track) => {
179
179
  return res;
180
180
  } finally {
181
181
  const duration = Date.now() - startTime;
182
- track('apiInvoked', { ...reportExtra, duration, status });
182
+ // track('apiInvoked', { ...reportExtra, duration, status });
183
183
  }
184
184
  };
185
185
  }
@@ -3,14 +3,19 @@ import { ReportHandler, Track, TrackPerformance, CommonReportConfig } from './ty
3
3
  import { PerformanceType, TrackEvent } from '@jolibox/types';
4
4
  import { InternalGlobalJSError } from '@jolibox/common';
5
5
  import { reportError } from './errors/report';
6
+ import { context } from '@/common/context';
6
7
 
7
8
  // Track system event, wrap common config
8
9
  export function createTrack(reportHandler: ReportHandler, common: CommonReportConfig): Track {
9
- const track = (tag: TrackEvent, info: Record<string, unknown> | null, webviewId?: number): void => {
10
+ const track = (
11
+ tag: TrackEvent,
12
+ info: Record<string, unknown> | null,
13
+ originEventType?: EventType
14
+ ): void => {
10
15
  const { eventType, ...rest } = info ?? {};
11
16
  const data = {
12
17
  tag,
13
- eventType: (eventType ?? EventType.Other) as number,
18
+ eventType: originEventType ?? ((eventType ?? EventType.Other) as number),
14
19
  ...common,
15
20
  extra: {
16
21
  ...rest
@@ -19,7 +24,7 @@ export function createTrack(reportHandler: ReportHandler, common: CommonReportCo
19
24
  if (tag == 'globalJsError') {
20
25
  reportError(new InternalGlobalJSError(JSON.stringify(data))); // window.onerror, 白屏
21
26
  } else {
22
- reportHandler('systemLog', data, webviewId);
27
+ reportHandler('systemLog', data, context.webviewId);
23
28
  }
24
29
  };
25
30
 
@@ -10,6 +10,7 @@ import {
10
10
  DefaltLoginGuide
11
11
  } from './reward-emitter';
12
12
  import { StandardResponse } from '@jolibox/types';
13
+ import { hostEmitter } from '@jolibox/common';
13
14
 
14
15
  const priority = () => {
15
16
  return (a: RewardType, b: RewardType) => {
@@ -64,6 +65,10 @@ export const createRewardFrequencyConfigFetcher = (rewardsHelper: RewardsHelper)
64
65
  loginGuide: res.data?.loginGuide || DefaltLoginGuide
65
66
  });
66
67
 
68
+ hostEmitter.emit('onGlobalConfigChanged', {
69
+ globalConfig: res.data
70
+ });
71
+
67
72
  return {
68
73
  joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge,
69
74
  loginGuide: res.data?.loginGuide || DefaltLoginGuide
@@ -10,12 +10,13 @@ const onLevelFinished = createAPI('levelFinished', {
10
10
  levelId: t.or(t.string(), t.number()),
11
11
  duration: t.number().optional(),
12
12
  rating: t.number().optional(),
13
- score: t.number().optional()
13
+ score: t.number().optional(),
14
+ variation: t.string().optional()
14
15
  })
15
16
  ),
16
17
  implement: async (parmas) => {
17
- const { levelId, duration, rating, score } = parmas;
18
- logger.info(`onLevelFinished`, duration, rating, score);
18
+ const { levelId, duration, rating, score, variation } = parmas;
19
+ logger.info(`onLevelFinished`, duration, rating, score, variation);
19
20
  await Promise.all([
20
21
  taskTracker.reporter({
21
22
  event: 'COMPLETE_GAME_LEVEL'
@@ -24,7 +25,8 @@ const onLevelFinished = createAPI('levelFinished', {
24
25
  levelId,
25
26
  duration,
26
27
  rating,
27
- score
28
+ score,
29
+ variation
28
30
  })
29
31
  ]);
30
32
  }
@@ -35,16 +37,18 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
35
37
  t.object({
36
38
  duration: t.number().optional(),
37
39
  rating: t.number().optional(),
38
- score: t.number()
40
+ score: t.number(),
41
+ variation: t.string().optional()
39
42
  })
40
43
  ),
41
44
  implement: async (params) => {
42
- const { duration, rating, score } = params;
43
- logger.info(`onGamePlayEnded`, duration, rating, score);
45
+ const { duration, rating, score, variation } = params;
46
+ logger.info(`onGamePlayEnded`, duration, rating, score, variation);
44
47
  return taskTracker.tracker('GamePlayEnded', {
45
48
  duration,
46
49
  rating,
47
- score
50
+ score,
51
+ variation
48
52
  });
49
53
  }
50
54
  });
@@ -75,7 +79,8 @@ registerCanIUse('TaskTrackerSDK.onLevelFinished', {
75
79
  levelId: '1.1.25',
76
80
  duration: '1.1.25',
77
81
  rating: '1.1.25',
78
- score: '1.1.25'
82
+ score: '1.1.25',
83
+ variation: '1.1.50'
79
84
  }
80
85
  }
81
86
  });
@@ -86,7 +91,8 @@ registerCanIUse('TaskTrackerSDK.onGamePlayEnded', {
86
91
  params: {
87
92
  duration: '1.1.25',
88
93
  rating: '1.1.25',
89
- score: '1.1.25'
94
+ score: '1.1.25',
95
+ variation: '1.1.50'
90
96
  }
91
97
  }
92
98
  });
@@ -0,0 +1,64 @@
1
+ import { createAPI, registerCanIUse, t } from './base';
2
+ import { applyNative, invokeNative } from '@jolibox/native-bridge';
3
+ import { hostEmitter, UserCustomError } from '@jolibox/common';
4
+ import { createCommands } from '@jolibox/common';
5
+
6
+ const commands = createCommands();
7
+ let supportedMethods: string[] = [];
8
+ let isInitialized = false;
9
+
10
+ hostEmitter.on('onGlobalConfigChanged', (params) => {
11
+ supportedMethods = params.globalConfig.supportedHostMethods ?? [];
12
+ isInitialized = true;
13
+ });
14
+
15
+ const getSupportedMethods = (): Promise<string[]> => {
16
+ return new Promise((resolve) => {
17
+ if (isInitialized) {
18
+ resolve(supportedMethods);
19
+ } else {
20
+ const handler = (params: any) => {
21
+ supportedMethods = params.globalConfig.supportedHostMethods ?? [];
22
+ isInitialized = true;
23
+ hostEmitter.off('onGlobalConfigChanged', handler);
24
+ resolve(supportedMethods);
25
+ };
26
+ hostEmitter.on('onGlobalConfigChanged', handler);
27
+ }
28
+ });
29
+ };
30
+
31
+ const callHostMethodAsync = createAPI('callHostMethod', {
32
+ paramsSchema: t.tuple(
33
+ t.object({
34
+ method: t.string(),
35
+ params: t.object().optional().default({})
36
+ })
37
+ ),
38
+ implement: async ({ method, params }) => {
39
+ const supportedMethods = await getSupportedMethods();
40
+ if (!supportedMethods.includes(method)) {
41
+ throw new UserCustomError('Method not supported', 10001);
42
+ }
43
+ const { errNo, errMsg, data } = await invokeNative('callHostMethodAsync', {
44
+ method,
45
+ params: {
46
+ ...params
47
+ }
48
+ });
49
+ if (errNo !== 0) {
50
+ throw new UserCustomError(errMsg, errNo);
51
+ }
52
+
53
+ const { callHostMethodId, ...rest } = data;
54
+ return {
55
+ ...rest
56
+ };
57
+ }
58
+ });
59
+
60
+ commands.registerCommand('API.callHostMethod', callHostMethodAsync);
61
+
62
+ registerCanIUse('callHostMethod', {
63
+ version: '1.1.49'
64
+ });
@@ -9,3 +9,4 @@ import './ads';
9
9
  import './navigate';
10
10
  import './runtime';
11
11
  import './is-native-support';
12
+ import './call-host-method';
@@ -60,15 +60,12 @@ const navigateToNativePage = createSyncAPI('navigateToNativePage', {
60
60
  t.object()
61
61
  ),
62
62
  implement: (path, params) => {
63
- const { errNo, errMsg } = invokeNative('callHostMethodAsync', {
63
+ invokeNative('callHostMethodAsync', {
64
64
  method: path,
65
65
  params: {
66
66
  ...params
67
67
  }
68
68
  });
69
- if (errNo !== 0) {
70
- throw new UserCustomError(errMsg, errNo);
71
- }
72
69
  }
73
70
  });
74
71
 
@@ -49,7 +49,7 @@ const request = (_params: unknown) => {
49
49
  url: t.string(),
50
50
  method: t.string(),
51
51
  headers: t.object().optional(),
52
- data: t.object().optional(),
52
+ data: t.or(t.object(), t.array()).optional(),
53
53
  query: t.object().optional(),
54
54
  dataType: t.string().default('json'),
55
55
  responseType: t.string().default('text'),
@@ -10,18 +10,20 @@ const onLevelFinished = createAPI('levelFinished', {
10
10
  levelId: t.or(t.string(), t.number()),
11
11
  duration: t.number().optional(),
12
12
  rating: t.number().optional(),
13
- score: t.number().optional()
13
+ score: t.number().optional(),
14
+ variation: t.string().optional()
14
15
  })
15
16
  ),
16
17
  implement: async (parmas) => {
17
- const { levelId, duration, rating, score } = parmas;
18
+ const { levelId, duration, rating, score, variation } = parmas;
18
19
  const tasks = [];
19
20
  tasks.push(
20
21
  taskTracker.tracker('LevelFinished', {
21
22
  levelId,
22
23
  duration,
23
24
  rating,
24
- score
25
+ score,
26
+ variation
25
27
  })
26
28
  );
27
29
 
@@ -39,15 +41,17 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
39
41
  t.object({
40
42
  duration: t.number().optional(),
41
43
  rating: t.number().optional(),
42
- score: t.number()
44
+ score: t.number(),
45
+ variation: t.string().optional()
43
46
  })
44
47
  ),
45
48
  implement: async (params) => {
46
- const { duration, rating, score } = params;
49
+ const { duration, rating, score, variation } = params;
47
50
  return taskTracker.tracker('GamePlayEnded', {
48
51
  duration,
49
52
  rating,
50
- score
53
+ score,
54
+ variation
51
55
  });
52
56
  }
53
57
  });
@@ -82,7 +86,8 @@ registerCanIUse('TaskTrackerSDK.onLevelFinished', {
82
86
  levelId: '1.1.25',
83
87
  duration: '1.1.25',
84
88
  rating: '1.1.25',
85
- score: '1.1.25'
89
+ score: '1.1.25',
90
+ variation: '1.1.50'
86
91
  }
87
92
  }
88
93
  });
@@ -93,7 +98,8 @@ registerCanIUse('TaskTrackerSDK.onGamePlayEnded', {
93
98
  params: {
94
99
  duration: '1.1.25',
95
100
  rating: '1.1.25',
96
- score: '1.1.25'
101
+ score: '1.1.25',
102
+ variation: '1.1.50'
97
103
  }
98
104
  }
99
105
  });
@@ -48,7 +48,13 @@ rewardsEmitter.on(InvokeUnloginModalEventName, async (type: 'JOLI_COIN' | 'ADS-J
48
48
  return;
49
49
  }
50
50
 
51
- track('LoginGuideModal', {}, EventType.Expose);
51
+ track(
52
+ 'LoginGuideModal',
53
+ {
54
+ eventType: EventType.Expose
55
+ },
56
+ EventType.Expose
57
+ );
52
58
  const modal = createUnloginJolicoinModal({
53
59
  data: {
54
60
  rewardType: type,
@@ -58,14 +64,18 @@ rewardsEmitter.on(InvokeUnloginModalEventName, async (type: 'JOLI_COIN' | 'ADS-J
58
64
  confirm: {
59
65
  text: params.confirmButtonText,
60
66
  onPress: async () => {
61
- track('LoginGuideModal', { type: 'click_confirm' }, EventType.Click);
67
+ track('LoginGuideModal', { type: 'click_confirm', eventType: EventType.Click }, EventType.Click);
62
68
  const { isLogin, extra, isFirstLogin } = await loginImplement({}, true);
63
69
  if (!isLogin) {
64
70
  console.log('login failed');
65
71
  return;
66
72
  }
67
73
 
68
- track('LoginGuideModal', { type: 'click_confirm_login', isFirstLogin }, EventType.Click);
74
+ track(
75
+ 'LoginGuideModal',
76
+ { type: 'click_confirm_login', isFirstLogin, eventType: EventType.Click },
77
+ EventType.Click
78
+ );
69
79
  if (isFirstLogin && extra?.firstLogin?.reward) {
70
80
  const { rewardValue } = extra.firstLogin.reward;
71
81
  createToast(`{slot-i18ntran-loginGuide.rewardTips}`, {
@@ -94,10 +104,10 @@ rewardsEmitter.on(InvokeUnloginModalEventName, async (type: 'JOLI_COIN' | 'ADS-J
94
104
  cancel: {
95
105
  text: params.cancelButtonText,
96
106
  onPress: ({ type }) => {
97
- track('LoginGuideModal', {}, EventType.Hide);
107
+ track('LoginGuideModal', { eventType: EventType.Hide }, EventType.Hide);
98
108
 
99
109
  const trackType = type === 'CANCEL' ? 'click_close' : 'click_watch_ads';
100
- track('LoginGuideModal', { type: trackType }, EventType.Click);
110
+ track('LoginGuideModal', { type: trackType, eventType: EventType.Click }, EventType.Click);
101
111
  rewardsEmitter.emit(UseUnloginModalResultEventName, { result: 'FAILED' });
102
112
  modal.destroy();
103
113
  }