@jolibox/implement 1.1.4-beta.8 → 1.1.4

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.
Files changed (59) hide show
  1. package/.rush/temp/package-deps_build.json +33 -33
  2. package/dist/{h5 → common}/ads/ads-action-detection.d.ts +3 -1
  3. package/dist/{h5 → common}/ads/anti-cheating.d.ts +2 -2
  4. package/dist/common/ads/channel-policy.d.ts +26 -0
  5. package/dist/{h5 → common}/ads/index.d.ts +12 -3
  6. package/dist/common/context/index.d.ts +2 -0
  7. package/dist/common/http/uuid.d.ts +2 -2
  8. package/dist/common/http/xua.d.ts +0 -15
  9. package/dist/common/report/base-tracker.d.ts +10 -1
  10. package/dist/common/report/errors/index.d.ts +2 -2
  11. package/dist/common/report/task-track/index.d.ts +3 -0
  12. package/dist/common/report/types.d.ts +1 -54
  13. package/dist/h5/api/index.d.ts +1 -0
  14. package/dist/h5/http/index.d.ts +3 -3
  15. package/dist/h5/report/index.d.ts +1 -1
  16. package/dist/index.d.ts +0 -1
  17. package/dist/index.js +3 -5014
  18. package/dist/index.native.js +3 -3750
  19. package/dist/native/api/keyboard.d.ts +9 -3
  20. package/dist/native/network/index.d.ts +0 -3
  21. package/esbuild.config.js +1 -1
  22. package/implement.build.log +0 -9
  23. package/implementation.build.log +9 -0
  24. package/package.json +3 -3
  25. package/src/{h5 → common}/ads/ads-action-detection.ts +4 -4
  26. package/src/{h5 → common}/ads/anti-cheating.ts +2 -4
  27. package/src/common/ads/channel-policy.ts +52 -0
  28. package/src/{h5 → common}/ads/index.ts +72 -61
  29. package/src/common/api-factory/index.ts +3 -3
  30. package/src/common/context/index.ts +20 -11
  31. package/src/common/http/uuid.ts +2 -10
  32. package/src/common/http/xua.ts +2 -69
  33. package/src/common/report/base-tracker.ts +40 -44
  34. package/src/common/report/errors/index.ts +3 -3
  35. package/src/common/report/errors/report/listeners.ts +0 -2
  36. package/src/common/report/task-track/index.ts +63 -14
  37. package/src/common/report/track.ts +2 -2
  38. package/src/common/report/types.ts +1 -63
  39. package/src/h5/api/ads.ts +24 -0
  40. package/src/h5/api/get-system-info.ts +5 -1
  41. package/src/h5/api/index.ts +1 -0
  42. package/src/h5/http/index.ts +24 -28
  43. package/src/h5/http/utils/__tests__/xua.test.ts +1 -1
  44. package/src/h5/http/utils/session.ts +1 -1
  45. package/src/h5/report/errors/index.ts +1 -1
  46. package/src/h5/report/event-tracker.ts +1 -1
  47. package/src/h5/report/index.ts +4 -2
  48. package/src/index.ts +0 -1
  49. package/src/native/api/ads.ts +32 -8
  50. package/src/native/api/get-system-info.ts +5 -2
  51. package/src/native/api/keyboard.ts +13 -13
  52. package/src/native/bootstrap/index.ts +0 -1
  53. package/src/native/network/index.ts +11 -4
  54. package/src/native/report/index.ts +2 -2
  55. package/src/native/types/native-method-map.d.ts +11 -0
  56. package/dist/common/report/errors/error-types.d.ts +0 -122
  57. package/src/common/report/errors/error-types.ts +0 -206
  58. package/src/h5/http/utils/__tests__/uuid.test.ts +0 -16
  59. /package/dist/h5/{http/utils/__tests__/uuid.test.d.ts → api/ads.d.ts} +0 -0
@@ -13,10 +13,13 @@ const getSystemInfoSync = createSyncAPI(API_GET_SYSTEM_SYNC, {
13
13
  const { data } = res;
14
14
  return {
15
15
  system: data.deviceInfo.system,
16
- platform: data.platform,
16
+ platform: data.deviceInfo.platform,
17
17
  version: data.sdkInfo.jssdkVersion,
18
18
  pixelRatio: data.deviceInfo.pixelRatio,
19
- language: data.deviceInfo.lang
19
+ language: data.deviceInfo.lang,
20
+ brand: data.deviceInfo.brand,
21
+ appName: data.hostInfo?.appName,
22
+ SDKVersion: data.sdkInfo.jssdkVersion
20
23
  };
21
24
  }
22
25
  });
@@ -1,16 +1,16 @@
1
1
  import { createCommands } from '@jolibox/common';
2
- import { applyNative } from '../bootstrap/bridge';
3
- import { createAPI, registerCanIUse, t } from './base';
2
+ import { invokeNative } from '../bootstrap/bridge';
3
+ import { createSyncAPI, registerCanIUse, t } from './base';
4
4
 
5
- export const showKeyboard = createAPI('showKeyboard', {
5
+ export const showKeyboard = createSyncAPI('showKeyboard', {
6
6
  paramsSchema: t.tuple(
7
7
  t.object({
8
- defaultValue: t.string().default(''),
9
- multiple: t.boolean().default(false),
8
+ defaultValue: t.string().optional().default(''),
9
+ multiple: t.boolean().optional().default(false),
10
10
  maxLength: t.unknown().optional().default(100000)
11
11
  })
12
12
  ),
13
- async implement(params) {
13
+ implement(params) {
14
14
  const maxLength = Math.floor(Number(params.maxLength) ?? 100000);
15
15
  let { defaultValue } = params;
16
16
 
@@ -18,7 +18,7 @@ export const showKeyboard = createAPI('showKeyboard', {
18
18
  defaultValue = defaultValue.slice(0, maxLength);
19
19
  }
20
20
 
21
- applyNative('showKeyboardSync', { ...params, defaultValue, maxLength });
21
+ invokeNative('showKeyboardSync', { ...params, defaultValue, maxLength });
22
22
  }
23
23
  });
24
24
 
@@ -38,14 +38,14 @@ registerCanIUse('keyboard.showKeyboard', {
38
38
  }
39
39
  });
40
40
 
41
- export const updateKeyboard = createAPI('updateKeyboard', {
41
+ export const updateKeyboard = createSyncAPI('updateKeyboard', {
42
42
  paramsSchema: t.tuple(
43
43
  t.object({
44
44
  value: t.string()
45
45
  })
46
46
  ),
47
- async implement(params) {
48
- applyNative('updateKeyboardSync', params);
47
+ implement(params) {
48
+ invokeNative('updateKeyboardSync', params);
49
49
  }
50
50
  });
51
51
 
@@ -58,9 +58,9 @@ registerCanIUse('keyboard.updateKeyboard', {
58
58
  }
59
59
  });
60
60
 
61
- export const hideKeyboard = createAPI('hideKeyboard', {
62
- async implement() {
63
- applyNative('hideKeyboardSync');
61
+ export const hideKeyboard = createSyncAPI('hideKeyboard', {
62
+ implement() {
63
+ invokeNative('hideKeyboardSync');
64
64
  }
65
65
  });
66
66
 
@@ -1,6 +1,5 @@
1
1
  import { onNative, RuntimeLoader } from './bridge';
2
2
  import { joliboxJSCore } from '../js-core';
3
- import { HostUserInfo } from '@/common/context/types';
4
3
  import { context } from '@/common/context';
5
4
  import { hostEmitter } from '@jolibox/common';
6
5
  import { taskTracker, track } from '../report';
@@ -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
  });
@@ -1,7 +1,7 @@
1
1
  import './errors';
2
- import { createCommands, isObject, isString, EventEmitter } from '@jolibox/common';
2
+ import { createCommands, isObject, isString, EventEmitter, EProject } from '@jolibox/common';
3
3
  export * from '../../common/report/types';
4
- import { createTracks, EProject, ReportHandler } from '@/common/report';
4
+ import { createTracks, ReportHandler } from '@/common/report';
5
5
  import { context } from '@/common/context';
6
6
  import { NativeTaskTracker } from './task-tracker';
7
7
  import { invokeNative } from '../bootstrap/bridge';
@@ -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 {
@@ -1,122 +0,0 @@
1
- type InternalLifeCycleErrorName = 'INTERNAL_GAME_LAUNCH_ERROR';
2
- type InternalAPIErrorName = 'INTERNAL_API_ERROR';
3
- type InternalMetricErrorName = 'INTERNAL_METRIC_REPORT_ERROR';
4
- type InternalReporterErrorName = 'INTERNAL_REPORTER_ERROR';
5
- type InternalUtilErrorName = 'INTERNAL_BUFFER_ERROR' | 'INTERNAL_SCHEMA_PARSE_ERROR';
6
- type InternalInjectErrorName = 'INTERNAL_CONTEXT_ERROR' | 'INTERNAL_JSCORE_ERROR';
7
- type InternalBridgeErrorName = 'INTERNAL_INVOKE_NATIVE_ERROR' | 'INTERNAL_APPLY_NATIVE_ERROR' | 'INTERNAL_INVOKE_METHOD_ERROR';
8
- type UserErrorName = 'USER_VALIDATE_ERROR' | 'USER_GLOBAL_ERROR' | 'USER_FETCH_ERROR' | 'API_ERROR' | 'USER_CUSTOM_ERROR';
9
- export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | UserErrorName | InternalMetricErrorName;
10
- export type ErrorKind = 'INTERNAL_ERROR' | 'USER_ERROR' | 'API_ERROR';
11
- export type ErrorEnv = 'native' | 'h5';
12
- export type LoadScriptError = BaseError & {
13
- code?: number;
14
- };
15
- export declare enum LoadScriptCode {
16
- DEVELOPER_FILE_NOT_FOUND = 0,
17
- INTERNAL_IOS_CAN_NOT_FOUND_PKG = 1,
18
- USER_IOS_LOAD_TIMEOUT = 2,
19
- INTERNAL_IOS_PKG_LOAD_ERROR = 3,
20
- INTERNAL_IOS_PKG_PARSE_FAIL = 4,
21
- USER_IOS_GET_EMPTY_DATA = 5,
22
- USER_ANDROID_GET_PKG_FAIL = 6,
23
- DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE = 7
24
- }
25
- export declare abstract class BaseError extends Error {
26
- abstract kind: ErrorKind;
27
- abstract name: ErrorName;
28
- priority: 'P0' | 'P1';
29
- env?: ErrorEnv;
30
- raw?: Error;
31
- component?: string;
32
- constructor(error: string | Error);
33
- }
34
- export declare abstract class InternalError extends BaseError {
35
- readonly kind = "INTERNAL_ERROR";
36
- }
37
- export declare abstract class UserError extends BaseError {
38
- readonly kind = "USER_ERROR";
39
- }
40
- export declare class UserValidateError extends UserError {
41
- readonly name = "USER_VALIDATE_ERROR";
42
- }
43
- export declare class UserGlobalError extends UserError {
44
- readonly name = "USER_GLOBAL_ERROR";
45
- readonly priority = "P0";
46
- }
47
- export declare class UserCustomError extends UserError {
48
- readonly message: string;
49
- readonly errNo?: number | undefined;
50
- readonly name = "USER_CUSTOM_ERROR";
51
- errMsg: string;
52
- extra?: {
53
- [key: string]: unknown;
54
- };
55
- constructor(message: string, errNo?: number | undefined, extra?: {
56
- [key: string]: unknown;
57
- });
58
- }
59
- export declare class UserFetchError extends UserError {
60
- readonly message: string;
61
- readonly errNo?: number | undefined;
62
- readonly name = "USER_FETCH_ERROR";
63
- errMsg: string;
64
- extra?: {
65
- [key: string]: unknown;
66
- };
67
- constructor(message: string, errNo?: number | undefined, extra?: {
68
- [key: string]: unknown;
69
- });
70
- }
71
- export declare class InternalSchemaParseError extends InternalError {
72
- readonly name = "INTERNAL_SCHEMA_PARSE_ERROR";
73
- readonly priority = "P0";
74
- }
75
- export declare class InternalInvokeNativeError extends InternalError {
76
- readonly name = "INTERNAL_INVOKE_NATIVE_ERROR";
77
- }
78
- export declare class InternalApplyNativeError extends InternalError {
79
- readonly errNo?: number | undefined;
80
- readonly name = "INTERNAL_APPLY_NATIVE_ERROR";
81
- errorType?: string;
82
- errorCode?: number;
83
- constructor(message: string, errNo?: number | undefined, errorType?: string, errorCode?: number);
84
- }
85
- export declare class InternalInvokeMethodError extends InternalError {
86
- readonly name = "INTERNAL_INVOKE_METHOD_ERROR";
87
- }
88
- export declare class InternalJSCoreNotFoundError extends InternalError {
89
- readonly name = "INTERNAL_JSCORE_ERROR";
90
- }
91
- export declare class InternalBufferError extends InternalError {
92
- readonly name = "INTERNAL_BUFFER_ERROR";
93
- }
94
- export declare class InternalContextError extends InternalError {
95
- readonly message: string;
96
- readonly name = "INTERNAL_CONTEXT_ERROR";
97
- readonly property: string;
98
- constructor(message: string, property: string);
99
- }
100
- export declare class APIError extends BaseError {
101
- readonly message: string;
102
- readonly code: number;
103
- readonly kind = "API_ERROR";
104
- readonly name = "API_ERROR";
105
- extra?: Record<string, unknown>;
106
- errorType?: string;
107
- constructor(message: string, code: number, errorType?: string, stack?: string, priority?: 'P0' | 'P1');
108
- toJSON(): {
109
- message: string;
110
- stack: string | undefined;
111
- name: string;
112
- code: number;
113
- errorType: string | undefined;
114
- };
115
- }
116
- export declare class InternalMetricReportError extends InternalError {
117
- readonly name = "INTERNAL_METRIC_REPORT_ERROR";
118
- }
119
- export declare class InternalReporterError extends InternalError {
120
- readonly name = "INTERNAL_REPORTER_ERROR";
121
- }
122
- export {};
@@ -1,206 +0,0 @@
1
- type InternalLifeCycleErrorName = 'INTERNAL_GAME_LAUNCH_ERROR';
2
-
3
- // API
4
- type InternalAPIErrorName = 'INTERNAL_API_ERROR';
5
-
6
- // 前端埋点
7
- type InternalMetricErrorName = 'INTERNAL_METRIC_REPORT_ERROR';
8
-
9
- // reporter
10
- type InternalReporterErrorName = 'INTERNAL_REPORTER_ERROR';
11
-
12
- // 内部错误
13
- type InternalUtilErrorName = 'INTERNAL_BUFFER_ERROR' | 'INTERNAL_SCHEMA_PARSE_ERROR';
14
-
15
- // Native Inject Error
16
- type InternalInjectErrorName = 'INTERNAL_CONTEXT_ERROR' | 'INTERNAL_JSCORE_ERROR';
17
-
18
- type InternalBridgeErrorName =
19
- | 'INTERNAL_INVOKE_NATIVE_ERROR'
20
- | 'INTERNAL_APPLY_NATIVE_ERROR'
21
- | 'INTERNAL_INVOKE_METHOD_ERROR';
22
-
23
- // User
24
- type UserErrorName =
25
- | 'USER_VALIDATE_ERROR'
26
- | 'USER_GLOBAL_ERROR'
27
- | 'USER_FETCH_ERROR'
28
- | 'API_ERROR'
29
- | 'USER_CUSTOM_ERROR';
30
-
31
- export type ErrorName =
32
- | InternalLifeCycleErrorName
33
- | InternalInjectErrorName
34
- | InternalAPIErrorName
35
- | InternalBridgeErrorName
36
- | InternalUtilErrorName
37
- | InternalReporterErrorName
38
- | UserErrorName
39
- | InternalMetricErrorName;
40
-
41
- export type ErrorKind = 'INTERNAL_ERROR' | 'USER_ERROR' | 'API_ERROR';
42
- export type ErrorEnv = 'native' | 'h5';
43
- export type LoadScriptError = BaseError & { code?: number };
44
- export enum LoadScriptCode {
45
- DEVELOPER_FILE_NOT_FOUND = 0,
46
- INTERNAL_IOS_CAN_NOT_FOUND_PKG = 1,
47
- USER_IOS_LOAD_TIMEOUT = 2,
48
- INTERNAL_IOS_PKG_LOAD_ERROR = 3,
49
- INTERNAL_IOS_PKG_PARSE_FAIL = 4,
50
- USER_IOS_GET_EMPTY_DATA = 5,
51
- USER_ANDROID_GET_PKG_FAIL = 6,
52
- DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE = 7
53
- }
54
-
55
- export abstract class BaseError extends Error {
56
- abstract kind: ErrorKind;
57
- abstract name: ErrorName;
58
- priority: 'P0' | 'P1';
59
- env?: ErrorEnv;
60
- raw?: Error;
61
- component?: string;
62
- constructor(error: string | Error) {
63
- if (typeof error === 'string') {
64
- super(error);
65
- this.priority = 'P1';
66
- return;
67
- }
68
- super(error.message);
69
- this.priority = 'P1';
70
- this.stack = error.stack;
71
- this.raw = error;
72
- }
73
- }
74
-
75
- export abstract class InternalError extends BaseError {
76
- readonly kind = 'INTERNAL_ERROR';
77
- }
78
- export abstract class UserError extends BaseError {
79
- readonly kind = 'USER_ERROR';
80
- }
81
-
82
- export class UserValidateError extends UserError {
83
- readonly name = 'USER_VALIDATE_ERROR';
84
- }
85
-
86
- export class UserGlobalError extends UserError {
87
- readonly name = 'USER_GLOBAL_ERROR';
88
- readonly priority = 'P0';
89
- }
90
-
91
- export class UserCustomError extends UserError {
92
- readonly name = 'USER_CUSTOM_ERROR';
93
- errMsg: string;
94
- extra?: { [key: string]: unknown };
95
-
96
- constructor(readonly message: string, readonly errNo?: number, extra?: { [key: string]: unknown }) {
97
- super(message);
98
- this.errMsg = message;
99
-
100
- if (extra) {
101
- this.extra = Object.assign({}, this.extra, extra);
102
- }
103
- }
104
- }
105
-
106
- export class UserFetchError extends UserError {
107
- readonly name = 'USER_FETCH_ERROR';
108
- errMsg: string;
109
- extra?: { [key: string]: unknown };
110
-
111
- constructor(readonly message: string, readonly errNo?: number, extra?: { [key: string]: unknown }) {
112
- super(message);
113
- this.errMsg = message;
114
-
115
- if (extra) {
116
- this.extra = Object.assign({}, this.extra, extra);
117
- }
118
- }
119
- }
120
-
121
- export class InternalSchemaParseError extends InternalError {
122
- readonly name = 'INTERNAL_SCHEMA_PARSE_ERROR';
123
- readonly priority = 'P0';
124
- }
125
-
126
- export class InternalInvokeNativeError extends InternalError {
127
- readonly name = 'INTERNAL_INVOKE_NATIVE_ERROR';
128
- }
129
-
130
- export class InternalApplyNativeError extends InternalError {
131
- readonly name = 'INTERNAL_APPLY_NATIVE_ERROR';
132
- errorType?: string;
133
- errorCode?: number;
134
- constructor(message: string, readonly errNo?: number, errorType?: string, errorCode?: number) {
135
- super(message);
136
- this.errorType = errorType;
137
- this.errorCode = errorCode;
138
- }
139
- }
140
-
141
- export class InternalInvokeMethodError extends InternalError {
142
- readonly name = 'INTERNAL_INVOKE_METHOD_ERROR';
143
- }
144
-
145
- export class InternalJSCoreNotFoundError extends InternalError {
146
- readonly name = 'INTERNAL_JSCORE_ERROR';
147
- }
148
-
149
- export class InternalBufferError extends InternalError {
150
- readonly name = 'INTERNAL_BUFFER_ERROR';
151
- }
152
-
153
- export class InternalContextError extends InternalError {
154
- readonly name = 'INTERNAL_CONTEXT_ERROR';
155
- readonly property: string;
156
- constructor(readonly message: string, property: string) {
157
- super(message);
158
- this.property = property;
159
- }
160
- }
161
-
162
- export class APIError extends BaseError {
163
- readonly kind = 'API_ERROR';
164
- readonly name = 'API_ERROR';
165
- extra?: Record<string, unknown>;
166
- errorType?: string;
167
-
168
- constructor(
169
- readonly message: string,
170
- readonly code: number,
171
- errorType?: string,
172
- stack?: string,
173
- priority?: 'P0' | 'P1'
174
- ) {
175
- super(message);
176
-
177
- if (errorType) {
178
- this.errorType = errorType;
179
- }
180
-
181
- if (stack !== undefined) {
182
- this.stack = stack;
183
- }
184
- if (priority) {
185
- this.priority = priority;
186
- }
187
- }
188
-
189
- toJSON() {
190
- return {
191
- message: this.message,
192
- stack: this.stack,
193
- name: this.name,
194
- code: this.code,
195
- errorType: this.errorType
196
- };
197
- }
198
- }
199
-
200
- export class InternalMetricReportError extends InternalError {
201
- readonly name = 'INTERNAL_METRIC_REPORT_ERROR';
202
- }
203
-
204
- export class InternalReporterError extends InternalError {
205
- readonly name = 'INTERNAL_REPORTER_ERROR';
206
- }
@@ -1,16 +0,0 @@
1
- // import { expect, test } from "vitest";
2
- import { isValidUUIDV4, uuidv4 } from '../../../../common/http/uuid';
3
-
4
- describe('uuid', () => {
5
- it('test uuid', () => {
6
- const uuid = uuidv4();
7
- expect(uuid.length).toBe(36);
8
- expect(isValidUUIDV4(uuid)).toBe(true);
9
- });
10
-
11
- it('isValidUUIDV4', () => {
12
- const randomUUIDV4 = '5b1e0b7b-3b3b-4b4b-8b8b-9b9b0b1b2b3b';
13
- expect(isValidUUIDV4(randomUUIDV4)).toBe(true);
14
- expect(isValidUUIDV4('')).toBe(false);
15
- });
16
- });