@jolibox/implement 1.1.13-beta.9 → 1.1.14-beta.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/esbuild.config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const esbuild = require('esbuild');
2
2
  const fs = require('fs');
3
+ const path = require('path');
3
4
 
4
5
  function versionPlugin(version) {
5
6
  return {
@@ -21,14 +22,14 @@ function parseArgs() {
21
22
  const options = {
22
23
  format: 'esm', // 默认值
23
24
  };
24
-
25
+
25
26
  for (let i = 0; i < args.length; i++) {
26
27
  const arg = args[i];
27
28
 
28
- if (arg === '--format' || arg === '-f') {
29
- const format = args[i + 1];
30
- if (['esm', 'cjs', 'iife'].includes(format)) {
31
- options.format = format;
29
+ const [format, value] = arg.split("=");
30
+ if (format === '--format' || format === '-f') {
31
+ if (['esm', 'cjs', 'iife'].includes(value)) {
32
+ options.format = value;
32
33
  }
33
34
  i++;
34
35
  }
@@ -40,8 +41,25 @@ function parseArgs() {
40
41
  const options = parseArgs();
41
42
 
42
43
  function build(format) {
43
- return esbuild.build({
44
- entryPoints: ['src/index.native.ts', 'src/index.ts'],
44
+ // native场景支持代码分割
45
+ const nativeBuild = esbuild.build({
46
+ entryPoints: ['src/index.native.ts'],
47
+ bundle: true,
48
+ outdir: 'dist',
49
+ target: ['es2015', 'safari14'],
50
+ format: format,
51
+ minify: true,
52
+ loader: {
53
+ '.ts': 'ts',
54
+ '.tsx': 'tsx',
55
+ '.js': 'jsx'
56
+ },
57
+ plugins: [versionPlugin(process.env.BUILD_VERSION || '1.0.0')],
58
+ });
59
+
60
+ // h5 完整bundle
61
+ const webBuild = esbuild.build({
62
+ entryPoints: ['src/index.ts'],
45
63
  bundle: true,
46
64
  outdir: 'dist',
47
65
  target: ['es2015', 'safari14'],
@@ -53,7 +71,9 @@ function build(format) {
53
71
  '.js': 'jsx'
54
72
  },
55
73
  plugins: [versionPlugin(process.env.BUILD_VERSION || '1.0.0')],
56
- });
74
+ });
75
+
76
+ return Promise.all([nativeBuild, webBuild]);
57
77
  }
58
78
 
59
79
  (async ()=>{
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.13-beta.9 clean
3
+ > @jolibox/implement@1.1.14-beta.1 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.13-beta.9 build:esm
7
+ > @jolibox/implement@1.1.14-beta.1 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,14 +1,14 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.13-beta.9",
4
+ "version": "1.1.14-beta.1",
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.13-beta.9",
10
- "@jolibox/types": "1.1.13-beta.9",
11
- "@jolibox/native-bridge": "1.1.13-beta.9",
9
+ "@jolibox/common": "1.1.14-beta.1",
10
+ "@jolibox/types": "1.1.14-beta.1",
11
+ "@jolibox/native-bridge": "1.1.14-beta.1",
12
12
  "localforage": "1.10.0",
13
13
  "@jolibox/ui": "1.0.0",
14
14
  "web-vitals": "4.2.4"
@@ -13,21 +13,27 @@ const priority = () => {
13
13
 
14
14
  export const createRewardFetcher = (rewardsHelper: RewardsHelper) => {
15
15
  rewardsHelper.registerRewardsFetcher(async (httpClient: IHttpClient) => {
16
- const defaultRewards: RewardType[] = [];
17
- const res = await httpClient.post<IJolicoinRewardOption>('/api/games/unlock-options', {});
18
- if (res.code !== 'SUCCESS') {
19
- return defaultRewards;
20
- }
21
- unlockOptionsEmitter.emit(UnlockOptionsEventName, {
22
- options: res.data?.unlockOptions || [],
23
- userJoliCoin: res.extra?.joliCoin || {
24
- balance: 0,
25
- enableAutoDeduct: false
16
+ const defaultRewards: RewardType[] = ['ADS'];
17
+ try {
18
+ const res = await httpClient.post<IJolicoinRewardOption>('/api/games/unlock-options', {});
19
+ if (res.code !== 'SUCCESS') {
20
+ return defaultRewards;
26
21
  }
27
- });
22
+ unlockOptionsEmitter.emit(UnlockOptionsEventName, {
23
+ options: res.data?.unlockOptions || [],
24
+ userJoliCoin: res.extra?.joliCoin || {
25
+ balance: 0,
26
+ enableAutoDeduct: false
27
+ }
28
+ });
28
29
 
29
- const rewardsTypes = res.data?.unlockOptions?.map((option) => option.type) || Array.from(defaultRewards);
30
- // Sort reward types with JOLI_COIN having higher priority than ADS
31
- return rewardsTypes.sort(priority());
30
+ const rewardsTypes =
31
+ res.data?.unlockOptions?.map((option) => option.type) || Array.from(defaultRewards);
32
+ // Sort reward types with JOLI_COIN having higher priority than ADS
33
+ return rewardsTypes.sort(priority());
34
+ } catch (e) {
35
+ console.error('getRewardOptions error:', e);
36
+ return defaultRewards;
37
+ }
32
38
  });
33
39
  };
@@ -3,6 +3,7 @@ import { context } from '@/common/context';
3
3
  import { uuidv4 } from '@jolibox/common';
4
4
  import { canUseJolicoin } from './utils';
5
5
  import { unlockOptionsEmitter, UnlockOptionsEventName, IUnlockOptionsEvent } from '..';
6
+ import { IAdBreakParams } from '@/common/ads';
6
7
 
7
8
  interface IJolicoinUnlockRes {
8
9
  code: 'SUCCESS' | 'BALANCE_NOT_ENOUGH' | 'EPISODE_LOCK_JUMP' | 'EPISODE_UNLOCK_ALREADY';
@@ -14,7 +15,7 @@ interface IJolicoinUnlockRes {
14
15
  };
15
16
  }
16
17
 
17
- export type JolicoinRewardsHandler = () => Promise<boolean>;
18
+ export type JolicoinRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
18
19
  export const createJolicoinRewardHandler = (
19
20
  httpClient: IHttpClient,
20
21
  {
@@ -50,7 +51,7 @@ export const createJolicoinRewardHandler = (
50
51
  }
51
52
  });
52
53
 
53
- return async () => {
54
+ return async (params: IAdBreakParams) => {
54
55
  try {
55
56
  if (!unlockOptionsPromise) {
56
57
  createUnlockOptionsPromise();
@@ -72,6 +73,15 @@ export const createJolicoinRewardHandler = (
72
73
  }
73
74
  });
74
75
  if (unlockWithJolicoin.code == 'SUCCESS') {
76
+ params.adBreakDone?.({
77
+ breakType: params.type,
78
+ breakName: 'name' in params ? params.name ?? '' : '',
79
+ breakFormat: 'reward',
80
+ breakStatus: 'viewed'
81
+ });
82
+ if ('adViewed' in params) {
83
+ params.adViewed?.();
84
+ }
75
85
  onUnlockSuccess?.({
76
86
  quantity: unlockWithJolicoin.data.quantity,
77
87
  balance: unlockWithJolicoin.data.balance
package/src/h5/api/ads.ts CHANGED
@@ -18,7 +18,7 @@ rewardsHelper.registerRewardHandler(
18
18
  JOLI_COIN: params
19
19
  });
20
20
  }
21
- })
21
+ }) as unknown as (params?: unknown) => Promise<boolean>
22
22
  );
23
23
 
24
24
  adEventEmitter.on('isAdShowing', (isAdShowing) => {
@@ -54,7 +54,7 @@ rewardsHelper.registerRewardHandler(
54
54
  onUnlockFailed: () => {
55
55
  console.log('onUnlockFailed');
56
56
  }
57
- })
57
+ }) as unknown as (params?: unknown) => Promise<boolean>
58
58
  );
59
59
  const adInit = createSyncAPI('adInit', {
60
60
  implement: (config?: IAdsInitParams) => {