@jolibox/implement 1.3.3-beta.1 → 1.3.3
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 +8 -5
- package/dist/h5/report/encrypt/index.d.ts +13 -0
- package/dist/h5/report/encrypt/public.d.ts +1 -0
- package/dist/index.js +26 -18
- package/dist/index.native.js +40 -40
- package/dist/native/api/base.d.ts +1 -1
- package/dist/native/report/task-tracker.d.ts +1 -0
- package/dist/native/utils/can-iuse-native.d.ts +1 -0
- package/implement.build.log +2 -2
- package/package.json +6 -6
- package/src/h5/report/encrypt/index.ts +102 -0
- package/src/h5/report/encrypt/public.ts +9 -0
- package/src/h5/report/task-tracker.ts +12 -3
- package/src/native/api/base.ts +1 -6
- package/src/native/api/rewards.ts +7 -7
- package/src/native/report/task-tracker.ts +25 -10
- package/src/native/utils/can-iuse-native.ts +7 -0
|
@@ -10,6 +10,6 @@ export declare const createAPI: <ParamsSchema extends import("@/common/api-facto
|
|
|
10
10
|
}) => (...inputs: Inputs) => import("@jolibox/types").StandardResponse<Return>;
|
|
11
11
|
export declare const registerCanIUse: (name: string, config: import("@jolibox/common").CanIUseInfo) => void;
|
|
12
12
|
import { t } from '@/common/api-factory/validator';
|
|
13
|
+
export { canIUseNative } from '@/native/utils/can-iuse-native';
|
|
13
14
|
export { t };
|
|
14
|
-
export declare const canIUseNative: (schema: string) => boolean;
|
|
15
15
|
export { convertVersionCodeToVString } from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const canIUseNative: (schema: string) => boolean;
|
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.3.3
|
|
3
|
+
> @jolibox/implement@1.3.3 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.3.3
|
|
7
|
+
> @jolibox/implement@1.3.3 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,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.3.3
|
|
4
|
+
"version": "1.3.3",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.3.3
|
|
10
|
-
"@jolibox/types": "1.3.3
|
|
11
|
-
"@jolibox/native-bridge": "1.3.3
|
|
12
|
-
"@jolibox/ads": "1.3.3
|
|
9
|
+
"@jolibox/common": "1.3.3",
|
|
10
|
+
"@jolibox/types": "1.3.3",
|
|
11
|
+
"@jolibox/native-bridge": "1.3.3",
|
|
12
|
+
"@jolibox/ads": "1.3.3",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
|
-
"@jolibox/ui": "1.3.3
|
|
14
|
+
"@jolibox/ui": "1.3.3",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { PUBLIC_KEY_PEM } from './public';
|
|
2
|
+
|
|
3
|
+
function arrayBufferToBase64(buffer: ArrayBuffer) {
|
|
4
|
+
let binary = '';
|
|
5
|
+
const bytes = new Uint8Array(buffer);
|
|
6
|
+
const len = bytes.byteLength;
|
|
7
|
+
for (let i = 0; i < len; i++) {
|
|
8
|
+
binary += String.fromCharCode(bytes[i]);
|
|
9
|
+
}
|
|
10
|
+
return window.btoa(binary);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function importPublicKeyFromString(pem: string) {
|
|
14
|
+
const pemHeader = '-----BEGIN PUBLIC KEY-----';
|
|
15
|
+
const pemFooter = '-----END PUBLIC KEY-----';
|
|
16
|
+
const pemContents = pem
|
|
17
|
+
.substring(pem.indexOf(pemHeader) + pemHeader.length, pem.indexOf(pemFooter))
|
|
18
|
+
.replace(/\s+/g, '');
|
|
19
|
+
|
|
20
|
+
const binaryDerString = window.atob(pemContents);
|
|
21
|
+
const binaryDer = new Uint8Array(binaryDerString.length);
|
|
22
|
+
for (let i = 0; i < binaryDerString.length; i++) {
|
|
23
|
+
binaryDer[i] = binaryDerString.charCodeAt(i);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return binaryDer.buffer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ReportBody {
|
|
30
|
+
eventType: string;
|
|
31
|
+
gameInfo: {
|
|
32
|
+
gameId: string;
|
|
33
|
+
sessionId: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function generateEncryptedPayload(payload: ReportBody) {
|
|
38
|
+
const crypto = window.crypto;
|
|
39
|
+
const subtle = crypto.subtle;
|
|
40
|
+
|
|
41
|
+
const keyBuffer = importPublicKeyFromString(PUBLIC_KEY_PEM);
|
|
42
|
+
|
|
43
|
+
const publicKey = await subtle.importKey(
|
|
44
|
+
'spki',
|
|
45
|
+
keyBuffer,
|
|
46
|
+
{
|
|
47
|
+
name: 'RSA-OAEP',
|
|
48
|
+
hash: 'SHA-1'
|
|
49
|
+
},
|
|
50
|
+
false,
|
|
51
|
+
['encrypt']
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const aesKeyRaw = crypto.getRandomValues(new Uint8Array(32));
|
|
55
|
+
const aesKeyObj = await subtle.importKey('raw', aesKeyRaw, 'AES-GCM', false, ['encrypt']);
|
|
56
|
+
|
|
57
|
+
const encryptedAesKeyBuffer = await subtle.encrypt(
|
|
58
|
+
{
|
|
59
|
+
name: 'RSA-OAEP'
|
|
60
|
+
},
|
|
61
|
+
publicKey,
|
|
62
|
+
aesKeyRaw
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const k = arrayBufferToBase64(encryptedAesKeyBuffer);
|
|
66
|
+
|
|
67
|
+
const timestamp = Date.now();
|
|
68
|
+
const payloadJson = {
|
|
69
|
+
timestamp,
|
|
70
|
+
data: payload
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const encoder = new TextEncoder();
|
|
74
|
+
const payloadBytes = encoder.encode(JSON.stringify(payloadJson));
|
|
75
|
+
|
|
76
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
77
|
+
|
|
78
|
+
const ciphertextWithTagBuffer = await subtle.encrypt(
|
|
79
|
+
{
|
|
80
|
+
name: 'AES-GCM',
|
|
81
|
+
iv: iv,
|
|
82
|
+
tagLength: 128
|
|
83
|
+
},
|
|
84
|
+
aesKeyObj,
|
|
85
|
+
payloadBytes
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const ciphertextWithTag = new Uint8Array(ciphertextWithTagBuffer);
|
|
89
|
+
const finalPayloadBuffer = new Uint8Array(iv.length + ciphertextWithTag.length);
|
|
90
|
+
|
|
91
|
+
finalPayloadBuffer.set(iv, 0); // 先放 IV
|
|
92
|
+
finalPayloadBuffer.set(ciphertextWithTag, iv.length); // 再放 Ciphertext + Tag
|
|
93
|
+
|
|
94
|
+
const encryptedPayload = arrayBufferToBase64(finalPayloadBuffer.buffer);
|
|
95
|
+
const data = {
|
|
96
|
+
k: k,
|
|
97
|
+
v: '1.0',
|
|
98
|
+
payload: encryptedPayload
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
2
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs29BUZPZdQwNDEYtXufp
|
|
3
|
+
IGF40RBoddFzoD2ixl6PjyKWFXF8kxGS++HNtLspxhLvWoE12IZvrP7+whSpgHcy
|
|
4
|
+
4ryuW86mOdHnP9iyeK69GosHz3lVhQjF9UdhJDXB7P/zdj3VlVzZIj0yL+YvZjO0
|
|
5
|
+
F9vHrK8GMr1/gf3HKAroVJUVmJlWjqhBGoQzb58mqbTSWSN0HkDdYwXHNh/Xc1le
|
|
6
|
+
DJDbBmfKOQdlBjABR9gb1wGz2LPFA40kzROV9mMiVePXpCOKNMy+b0UOW4RoF7pi
|
|
7
|
+
Rq0jHJ4fRrMWvf/GugT0mv8YyuU9DaXLqTGP+jOEVvzvgtkO84XtLW1vh5ggINPW
|
|
8
|
+
2wIDAQAB
|
|
9
|
+
-----END PUBLIC KEY-----`;
|
|
@@ -8,6 +8,7 @@ import { EventEmitter, logger } from '@jolibox/common';
|
|
|
8
8
|
import { httpClientManager } from '../http';
|
|
9
9
|
import type { Track } from '.';
|
|
10
10
|
import type { TrackEvent } from '@jolibox/types';
|
|
11
|
+
import { generateEncryptedPayload } from './encrypt';
|
|
11
12
|
|
|
12
13
|
export class H5TaskTracker extends TaskTracker {
|
|
13
14
|
private gameId: string;
|
|
@@ -35,9 +36,17 @@ export class H5TaskTracker extends TaskTracker {
|
|
|
35
36
|
if (extraParams) {
|
|
36
37
|
Object.assign(reportBody, extraParams);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const encryptedBody = await generateEncryptedPayload(reportBody);
|
|
42
|
+
await this.httpClient.post(`/api/base/app-event/v2`, {
|
|
43
|
+
data: encryptedBody
|
|
44
|
+
});
|
|
45
|
+
} catch (e) {
|
|
46
|
+
await this.httpClient.post(`/api/base/app-event`, {
|
|
47
|
+
data: reportBody
|
|
48
|
+
});
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
51
|
tracker(event: TrackEvent, info: Record<string, unknown> | null = null) {
|
|
43
52
|
this.track(event, info);
|
package/src/native/api/base.ts
CHANGED
|
@@ -5,12 +5,7 @@ export const { createAPI, createSyncAPI } = createAPIFactory(track);
|
|
|
5
5
|
|
|
6
6
|
export const registerCanIUse = registerCanIUseFactory('native');
|
|
7
7
|
import { t } from '@/common/api-factory/validator';
|
|
8
|
-
|
|
9
|
-
import { context } from '@/common/context';
|
|
8
|
+
export { canIUseNative } from '@/native/utils/can-iuse-native';
|
|
10
9
|
export { t };
|
|
11
10
|
|
|
12
|
-
export const { canIUseNative } = registerCanIUseContext(
|
|
13
|
-
() => context.sdkInfo.nativeSDKVersionCode,
|
|
14
|
-
() => context.platform
|
|
15
|
-
);
|
|
16
11
|
export { convertVersionCodeToVString } from './utils';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError,
|
|
1
|
+
import { BaseError, wrapUserFunction, createCommands } from '@jolibox/common';
|
|
2
2
|
import { canIUseNative, createAPI, registerCanIUse, t } from './base';
|
|
3
3
|
import { StandardResponse, ICoinDetailsData } from '@jolibox/types';
|
|
4
4
|
import { context } from '@/common/context';
|
|
@@ -10,12 +10,10 @@ const commands = createCommands();
|
|
|
10
10
|
const safeCallbackWrapper = wrapUserFunction(reportError as (err: Error | BaseError) => void);
|
|
11
11
|
|
|
12
12
|
const getCoinDetails = createAPI('getCoinDetails', {
|
|
13
|
-
paramsSchema: t.tuple(t.
|
|
14
|
-
implement: async (
|
|
15
|
-
onUpdate
|
|
16
|
-
|
|
17
|
-
onUpdate?: (data: ICoinDetailsData) => void | Promise<void>;
|
|
18
|
-
}): Promise<StandardResponse<ICoinDetailsData>> => {
|
|
13
|
+
paramsSchema: t.tuple(t.function().optional()),
|
|
14
|
+
implement: async (
|
|
15
|
+
onUpdate?: (data: ICoinDetailsData) => void | Promise<void>
|
|
16
|
+
): Promise<StandardResponse<ICoinDetailsData>> => {
|
|
19
17
|
try {
|
|
20
18
|
const currentType = context.mpType;
|
|
21
19
|
// check mp type
|
|
@@ -58,10 +56,12 @@ const getCoinDetails = createAPI('getCoinDetails', {
|
|
|
58
56
|
msg: errMsg
|
|
59
57
|
});
|
|
60
58
|
}
|
|
59
|
+
console.log('=====> sync data', data, errNo);
|
|
61
60
|
|
|
62
61
|
invokeNative('requestCoinDetailsAsync').then((res) => {
|
|
63
62
|
if (res.errNo == 0 && res.data) {
|
|
64
63
|
customOnUpdate(res.data);
|
|
64
|
+
console.log('=====> res.data', res.data);
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
return {
|
|
@@ -9,6 +9,7 @@ import { applyNative } from '@jolibox/native-bridge';
|
|
|
9
9
|
import type { Track } from '.';
|
|
10
10
|
import type { TrackEvent } from '@jolibox/types';
|
|
11
11
|
import { getGlobalStorage, setGlobalStorage } from '../api/storage';
|
|
12
|
+
import { canIUseNative } from '@/native/utils/can-iuse-native';
|
|
12
13
|
|
|
13
14
|
const REPORT_FIRST_OPEN_GAME = 'REPORT_FIRST_OPEN_GAME';
|
|
14
15
|
|
|
@@ -55,16 +56,7 @@ export class NativeTaskTracker extends TaskTracker {
|
|
|
55
56
|
Object.assign(reportBody, extraParams);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const reportTask =
|
|
59
|
-
context.platform === 'android'
|
|
60
|
-
? fetch(`/api/base/app-event`, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
data: reportBody
|
|
63
|
-
})
|
|
64
|
-
: applyNative('trackAppEventAsync', {
|
|
65
|
-
url: this.taskUrl,
|
|
66
|
-
body: JSON.stringify(reportBody)
|
|
67
|
-
});
|
|
59
|
+
const reportTask = this.createTask(reportBody);
|
|
68
60
|
await reportTask;
|
|
69
61
|
}
|
|
70
62
|
|
|
@@ -96,4 +88,27 @@ export class NativeTaskTracker extends TaskTracker {
|
|
|
96
88
|
setGlobalStorage(REPORT_FIRST_OPEN_GAME, true);
|
|
97
89
|
});
|
|
98
90
|
}
|
|
91
|
+
|
|
92
|
+
private createTask(reportBody: {
|
|
93
|
+
eventType: string;
|
|
94
|
+
gameInfo: {
|
|
95
|
+
gameId: string;
|
|
96
|
+
sessionId: string;
|
|
97
|
+
};
|
|
98
|
+
}) {
|
|
99
|
+
if (canIUseNative('sendServerEventAsync')) {
|
|
100
|
+
return applyNative('sendServerEventAsync', {
|
|
101
|
+
payload: reportBody
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return context.platform === 'android'
|
|
105
|
+
? fetch(`/api/base/app-event`, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
data: reportBody
|
|
108
|
+
})
|
|
109
|
+
: applyNative('trackAppEventAsync', {
|
|
110
|
+
url: this.taskUrl,
|
|
111
|
+
body: JSON.stringify(reportBody)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
99
114
|
}
|