@jolibox/implement 1.1.4-beta.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.
- package/.eslintrc.js +3 -0
- package/.rush/temp/package-deps_build.json +104 -0
- package/.rush/temp/shrinkwrap-deps.json +79 -0
- package/README.md +1 -0
- package/dist/common/api-factory/index.d.ts +21 -0
- package/dist/common/api-factory/validator/__tests__/validate/any.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/array.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/arraybuffer.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/boolean.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/enum.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/function.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/literal.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/nullish.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/number.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/object.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/or.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/record.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/string.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/symbol.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/tuple.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/type-asserts.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/utils.test.d.ts +1 -0
- package/dist/common/api-factory/validator/index.d.ts +29 -0
- package/dist/common/api-factory/validator/validate.d.ts +119 -0
- package/dist/common/can-i-use.d.ts +2 -0
- package/dist/common/context/index.d.ts +16 -0
- package/dist/common/context/types.d.ts +5 -0
- package/dist/common/context/url-parse.d.ts +22 -0
- package/dist/common/http/index.d.ts +13 -0
- package/dist/common/http/uuid.d.ts +2 -0
- package/dist/common/http/xua.d.ts +17 -0
- package/dist/common/report/base-tracker.d.ts +13 -0
- package/dist/common/report/create-trace.d.ts +7 -0
- package/dist/common/report/errors/error-types.d.ts +122 -0
- package/dist/common/report/errors/index.d.ts +13 -0
- package/dist/common/report/errors/report/index.d.ts +51 -0
- package/dist/common/report/errors/report/listeners.d.ts +1 -0
- package/dist/common/report/index.d.ts +3 -0
- package/dist/common/report/task-track/index.d.ts +23 -0
- package/dist/common/report/track.d.ts +3 -0
- package/dist/common/report/types.d.ts +75 -0
- package/dist/h5/ads/ads-action-detection.d.ts +6 -0
- package/dist/h5/ads/anti-cheating.d.ts +61 -0
- package/dist/h5/ads/index.d.ts +275 -0
- package/dist/h5/api/base.d.ts +13 -0
- package/dist/h5/api/get-system-info.d.ts +1 -0
- package/dist/h5/api/index.d.ts +4 -0
- package/dist/h5/api/lifecycle.d.ts +1 -0
- package/dist/h5/api/storage.d.ts +27 -0
- package/dist/h5/api/task.d.ts +1 -0
- package/dist/h5/bootstrap/index.d.ts +1 -0
- package/dist/h5/http/index.d.ts +33 -0
- package/dist/h5/http/utils/__tests__/uuid.test.d.ts +1 -0
- package/dist/h5/http/utils/__tests__/xua.test.d.ts +1 -0
- package/dist/h5/http/utils/index.d.ts +14 -0
- package/dist/h5/http/utils/session.d.ts +1 -0
- package/dist/h5/report/errors/index.d.ts +4 -0
- package/dist/h5/report/event-tracker.d.ts +8 -0
- package/dist/h5/report/index.d.ts +10 -0
- package/dist/h5/report/task-tracker.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5026 -0
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +3743 -0
- package/dist/native/api/base.d.ts +13 -0
- package/dist/native/api/get-system-info.d.ts +1 -0
- package/dist/native/api/index.d.ts +7 -0
- package/dist/native/api/keyboard.d.ts +3 -0
- package/dist/native/api/lifecycle.d.ts +1 -0
- package/dist/native/api/login.d.ts +1 -0
- package/dist/native/api/request.d.ts +1 -0
- package/dist/native/api/storage.d.ts +25 -0
- package/dist/native/api/task.d.ts +1 -0
- package/dist/native/bootstrap/bridge.d.ts +4 -0
- package/dist/native/bootstrap/index.d.ts +1 -0
- package/dist/native/js-bridge/const.d.ts +5 -0
- package/dist/native/js-bridge/index.d.ts +2 -0
- package/dist/native/js-bridge/invoke.d.ts +21 -0
- package/dist/native/js-bridge/js-bridge.d.ts +6 -0
- package/dist/native/js-bridge/report.d.ts +63 -0
- package/dist/native/js-bridge/subscribe.d.ts +8 -0
- package/dist/native/js-bridge/types.d.ts +14 -0
- package/dist/native/js-bridge/utils.d.ts +17 -0
- package/dist/native/js-core/index.d.ts +3 -0
- package/dist/native/js-core/jolibox-js-core.d.ts +45 -0
- package/dist/native/js-core/message-port.d.ts +12 -0
- package/dist/native/js-core/utils.d.ts +7 -0
- package/dist/native/network/create-fetch.d.ts +27 -0
- package/dist/native/network/index.d.ts +11 -0
- package/dist/native/network/report.d.ts +15 -0
- package/dist/native/network/types.d.ts +61 -0
- package/dist/native/network/utils.d.ts +9 -0
- package/dist/native/report/errors/index.d.ts +4 -0
- package/dist/native/report/index.d.ts +10 -0
- package/dist/native/report/task-tracker.d.ts +20 -0
- package/dist/utils/index.d.ts +0 -0
- package/esbuild.config.js +66 -0
- package/implement.build.log +9 -0
- package/package.json +30 -0
- package/src/common/api-factory/index.ts +188 -0
- package/src/common/api-factory/validator/__tests__/validate/any.test.ts +68 -0
- package/src/common/api-factory/validator/__tests__/validate/array.test.ts +402 -0
- package/src/common/api-factory/validator/__tests__/validate/arraybuffer.test.ts +48 -0
- package/src/common/api-factory/validator/__tests__/validate/boolean.test.ts +27 -0
- package/src/common/api-factory/validator/__tests__/validate/enum.test.ts +106 -0
- package/src/common/api-factory/validator/__tests__/validate/function.test.ts +54 -0
- package/src/common/api-factory/validator/__tests__/validate/literal.test.ts +130 -0
- package/src/common/api-factory/validator/__tests__/validate/nullish.test.ts +41 -0
- package/src/common/api-factory/validator/__tests__/validate/number.test.ts +147 -0
- package/src/common/api-factory/validator/__tests__/validate/object.test.ts +131 -0
- package/src/common/api-factory/validator/__tests__/validate/or.test.ts +96 -0
- package/src/common/api-factory/validator/__tests__/validate/record.test.ts +274 -0
- package/src/common/api-factory/validator/__tests__/validate/string.test.ts +187 -0
- package/src/common/api-factory/validator/__tests__/validate/symbol.test.ts +23 -0
- package/src/common/api-factory/validator/__tests__/validate/tuple.test.ts +86 -0
- package/src/common/api-factory/validator/__tests__/validate/type-asserts.test.ts +13 -0
- package/src/common/api-factory/validator/__tests__/validate/utils.test.ts +44 -0
- package/src/common/api-factory/validator/index.ts +107 -0
- package/src/common/api-factory/validator/validate.ts +639 -0
- package/src/common/can-i-use.ts +19 -0
- package/src/common/context/index.ts +91 -0
- package/src/common/context/types.ts +5 -0
- package/src/common/context/url-parse.ts +63 -0
- package/src/common/http/index.ts +29 -0
- package/src/common/http/uuid.ts +11 -0
- package/src/common/http/xua.ts +79 -0
- package/src/common/report/base-tracker.ts +134 -0
- package/src/common/report/create-trace.ts +17 -0
- package/src/common/report/errors/error-types.ts +206 -0
- package/src/common/report/errors/index.ts +20 -0
- package/src/common/report/errors/report/index.ts +63 -0
- package/src/common/report/errors/report/listeners.ts +80 -0
- package/src/common/report/index.ts +3 -0
- package/src/common/report/task-track/index.ts +97 -0
- package/src/common/report/track.ts +49 -0
- package/src/common/report/types.ts +90 -0
- package/src/h5/ads/ads-action-detection.ts +31 -0
- package/src/h5/ads/anti-cheating.ts +244 -0
- package/src/h5/ads/index.ts +641 -0
- package/src/h5/api/base.ts +9 -0
- package/src/h5/api/get-system-info.ts +55 -0
- package/src/h5/api/index.ts +4 -0
- package/src/h5/api/lifecycle.ts +110 -0
- package/src/h5/api/storage.ts +173 -0
- package/src/h5/api/task.ts +197 -0
- package/src/h5/bootstrap/index.ts +16 -0
- package/src/h5/http/index.ts +189 -0
- package/src/h5/http/utils/__tests__/uuid.test.ts +16 -0
- package/src/h5/http/utils/__tests__/xua.test.ts +27 -0
- package/src/h5/http/utils/index.ts +19 -0
- package/src/h5/http/utils/session.ts +10 -0
- package/src/h5/report/errors/index.ts +40 -0
- package/src/h5/report/event-tracker.ts +40 -0
- package/src/h5/report/index.ts +56 -0
- package/src/h5/report/task-tracker.ts +35 -0
- package/src/index.native.ts +7 -0
- package/src/index.ts +9 -0
- package/src/native/api/base.ts +8 -0
- package/src/native/api/get-system-info.ts +41 -0
- package/src/native/api/index.ts +7 -0
- package/src/native/api/keyboard.ts +75 -0
- package/src/native/api/lifecycle.ts +76 -0
- package/src/native/api/login.ts +71 -0
- package/src/native/api/request.ts +154 -0
- package/src/native/api/storage.ts +287 -0
- package/src/native/api/task.ts +267 -0
- package/src/native/bootstrap/bridge.ts +59 -0
- package/src/native/bootstrap/index.ts +58 -0
- package/src/native/js-bridge/const.ts +11 -0
- package/src/native/js-bridge/index.ts +2 -0
- package/src/native/js-bridge/invoke.ts +210 -0
- package/src/native/js-bridge/js-bridge.ts +23 -0
- package/src/native/js-bridge/report.ts +311 -0
- package/src/native/js-bridge/subscribe.ts +50 -0
- package/src/native/js-bridge/types.ts +26 -0
- package/src/native/js-bridge/utils.ts +116 -0
- package/src/native/js-core/index.ts +4 -0
- package/src/native/js-core/jolibox-js-core.ts +188 -0
- package/src/native/js-core/message-port.ts +52 -0
- package/src/native/js-core/utils.ts +9 -0
- package/src/native/network/create-fetch.ts +237 -0
- package/src/native/network/index.ts +15 -0
- package/src/native/network/report.ts +58 -0
- package/src/native/network/types.ts +77 -0
- package/src/native/network/utils.ts +90 -0
- package/src/native/report/errors/index.ts +27 -0
- package/src/native/report/index.ts +51 -0
- package/src/native/report/task-tracker.ts +64 -0
- package/src/native/types/global.d.ts +26 -0
- package/src/native/types/native-method-map.d.ts +282 -0
- package/src/native/types/native-method.d.ts +30 -0
- package/src/utils/index.ts +0 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const createAPI: <ParamsSchema extends import("@/common/api-factory/validator").Validator<unknown[]>, Inputs extends import("@/common/api-factory/validator").Type<ParamsSchema> & unknown[], Return>(method: string, config: {
|
|
2
|
+
paramsSchema?: ParamsSchema;
|
|
3
|
+
implement: Inputs extends undefined ? () => Promise<Return | import("@jolibox/types").StandardResponse<Return>> : (...params: Inputs) => Promise<Return | import("@jolibox/types").StandardResponse<Return>>;
|
|
4
|
+
}) => (...inputs: unknown[]) => Promise<import("@jolibox/types").StandardResponse<Return>>, createSyncAPI: <ParamsSchema extends import("@/common/api-factory/validator").Validator<unknown[]>, Inputs extends import("@/common/api-factory/validator").Type<ParamsSchema> & unknown[], Return = void>(method: string, config: {
|
|
5
|
+
paramsSchema?: ParamsSchema;
|
|
6
|
+
implement: (...inputs: Inputs) => Return | {
|
|
7
|
+
code: import("@jolibox/types").ResponseType;
|
|
8
|
+
data: Return;
|
|
9
|
+
};
|
|
10
|
+
}) => (...inputs: Inputs) => import("@jolibox/types").StandardResponse<Return>;
|
|
11
|
+
export declare const registerCanIUse: (name: string, config: import("@jolibox/common").CanIUseInfo) => void;
|
|
12
|
+
import { t } from '@/common/api-factory/validator';
|
|
13
|
+
export { t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const showKeyboard: (...inputs: unknown[]) => Promise<import("@jolibox/types").StandardResponse<void>>;
|
|
2
|
+
export declare const updateKeyboard: (...inputs: unknown[]) => Promise<import("@jolibox/types").StandardResponse<void>>;
|
|
3
|
+
export declare const hideKeyboard: (...inputs: unknown[]) => Promise<import("@jolibox/types").StandardResponse<void>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StandardResponse } from '@jolibox/types';
|
|
2
|
+
/**
|
|
3
|
+
* 移除指定key
|
|
4
|
+
*/
|
|
5
|
+
export declare const removeStorage: (...inputs: unknown[]) => Promise<StandardResponse<void>>;
|
|
6
|
+
/**
|
|
7
|
+
* 异步获取当前storage的相关信息
|
|
8
|
+
*/
|
|
9
|
+
export declare const getStorageInfo: (...inputs: unknown[]) => Promise<StandardResponse<{
|
|
10
|
+
currentSize: number;
|
|
11
|
+
limitSize: number;
|
|
12
|
+
keys: string[];
|
|
13
|
+
}>>;
|
|
14
|
+
/**
|
|
15
|
+
* 同步获取当前storage的相关信息
|
|
16
|
+
*/
|
|
17
|
+
export declare const getStorageInfoSync: () => StandardResponse<{
|
|
18
|
+
errMsg: string;
|
|
19
|
+
errNo?: number;
|
|
20
|
+
data: {
|
|
21
|
+
currentSize: number;
|
|
22
|
+
limitSize: number;
|
|
23
|
+
keys: string[];
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { On } from '../js-bridge';
|
|
2
|
+
export declare const applyNative: jsb.service.ApplyNative, invokeNative: jsb.service.InvokeNative, onNative: jsb.service.OnNative, offNative: jsb.service.OnNative, subscribeHandler: import("../js-bridge").SubscribeHandler;
|
|
3
|
+
export declare const onNativeWithError: On;
|
|
4
|
+
export { RuntimeLoader } from '../js-core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function config(): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CUSTOM_EVENT_PREFIX = "custom_event_";
|
|
2
|
+
export declare const HOST_EVENT_PREFIX = "host_event_";
|
|
3
|
+
export declare const BUFFER_METHODS: string[];
|
|
4
|
+
export declare const BACKGROUND_FORBIDDEN_METHODS: string[];
|
|
5
|
+
export declare const SYNC_METHODS: string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InvokeHandler, On } from './types';
|
|
2
|
+
interface Invokes {
|
|
3
|
+
/** 暴露给宿主, 触发调用的方法 */
|
|
4
|
+
invokeHandler: InvokeHandler;
|
|
5
|
+
/** 基础库内部, 调用宿主的方法, 返回 native 返回对象 */
|
|
6
|
+
invokeNative: (method: string, args?: Record<string, unknown>, webviewId?: number) => any;
|
|
7
|
+
/** 基础库内部, 调用宿主的方法, 会根据 errMsg throwError */
|
|
8
|
+
applyNative: (method: string, args?: Record<string, unknown>, webviewId?: number) => any;
|
|
9
|
+
}
|
|
10
|
+
export declare function createInvoke(jsCore: jsb.JSCore, onNative: On): Invokes;
|
|
11
|
+
export declare function ifThrowError(method: string, res: {
|
|
12
|
+
errMsg?: string;
|
|
13
|
+
errNo?: number;
|
|
14
|
+
errorType?: string;
|
|
15
|
+
errorCode?: number;
|
|
16
|
+
}): {} | undefined;
|
|
17
|
+
export declare class ApplyNativeError extends Error {
|
|
18
|
+
readonly errNo?: number | undefined;
|
|
19
|
+
constructor(message: string, errNo?: number | undefined);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { On } from './types';
|
|
2
|
+
type MetricReporter = (points: unknown) => unknown;
|
|
3
|
+
interface MetricCache {
|
|
4
|
+
[props: string]: MetricCache | (number | string)[];
|
|
5
|
+
}
|
|
6
|
+
interface PVMetricCache {
|
|
7
|
+
[props: string]: PVMetricCache | number;
|
|
8
|
+
}
|
|
9
|
+
type MetricCacheType = MetricCache | PVMetricCache;
|
|
10
|
+
type MetricType = 'pv' | 'default';
|
|
11
|
+
type Prettier<T> = T extends Record<string, unknown> ? {
|
|
12
|
+
[K in keyof T]: T[K];
|
|
13
|
+
} : T;
|
|
14
|
+
type MetricPoint<Tag extends string, Name extends string> = Prettier<{
|
|
15
|
+
[k in Tag]: string;
|
|
16
|
+
} & {
|
|
17
|
+
[K in Name]: number | string;
|
|
18
|
+
}>;
|
|
19
|
+
interface PVPoint {
|
|
20
|
+
[props: string]: string | JSON;
|
|
21
|
+
}
|
|
22
|
+
interface MetricConfig<Tag extends string, Name extends string, Type extends string> {
|
|
23
|
+
reporter: MetricReporter;
|
|
24
|
+
interval?: number;
|
|
25
|
+
eventName: string;
|
|
26
|
+
tagNameOrder: Tag[];
|
|
27
|
+
metricName: Name;
|
|
28
|
+
type?: Type;
|
|
29
|
+
}
|
|
30
|
+
export declare class MetricsMonitor<Tag extends string, Name extends string, Type extends string> {
|
|
31
|
+
reporter: MetricReporter;
|
|
32
|
+
interval: number;
|
|
33
|
+
lastReportTime: number;
|
|
34
|
+
cache: MetricCacheType;
|
|
35
|
+
eventName: string;
|
|
36
|
+
tagNameOrder: Tag[];
|
|
37
|
+
metricName: Name;
|
|
38
|
+
type: MetricType;
|
|
39
|
+
constructor(config: MetricConfig<Tag, Name, Type>);
|
|
40
|
+
report(point: Type extends 'pv' ? PVPoint : MetricPoint<Tag, Name>): void;
|
|
41
|
+
flush(): void;
|
|
42
|
+
private tryReport;
|
|
43
|
+
private addPoint;
|
|
44
|
+
private addPVPoint;
|
|
45
|
+
private processPoints;
|
|
46
|
+
private clearPoints;
|
|
47
|
+
}
|
|
48
|
+
interface InvokeMetrics {
|
|
49
|
+
errMsg: string;
|
|
50
|
+
errNo?: number;
|
|
51
|
+
__timing?: {
|
|
52
|
+
receiveJSInvoke: number;
|
|
53
|
+
invokeCallback: number;
|
|
54
|
+
};
|
|
55
|
+
method: string;
|
|
56
|
+
startTime: number;
|
|
57
|
+
args?: Record<string, unknown>;
|
|
58
|
+
isForeground: string;
|
|
59
|
+
[prop: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
export type reportInvokeFn = (invokeMetrics: InvokeMetrics) => void;
|
|
62
|
+
export declare function createReportInvokeMetrics(jsCore: jsb.JSCore, onNative: On): reportInvokeFn;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Listener = (...args: any[]) => any;
|
|
2
|
+
export type On = <T extends string>(event: T, handler: Listener) => void;
|
|
3
|
+
export type Off = <T extends string>(event: T, handler: Listener) => void;
|
|
4
|
+
export type InvokeHandler = (callbackId: string | number, data: string | Record<string, unknown>) => void;
|
|
5
|
+
export type SubscribeHandler = (event: string, data: string | Record<string, unknown>, webviewId?: number) => void;
|
|
6
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
7
|
+
export interface JSBridge {
|
|
8
|
+
invokeHandler: InvokeHandler;
|
|
9
|
+
subscribeHandler: SubscribeHandler;
|
|
10
|
+
invokeNative: jsb.service.InvokeNative;
|
|
11
|
+
applyNative: jsb.service.ApplyNative;
|
|
12
|
+
onNative: jsb.service.OnNative;
|
|
13
|
+
offNative: jsb.service.OffNative;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface DataObj {
|
|
2
|
+
params?: Record<string, unknown>;
|
|
3
|
+
errorCode?: number;
|
|
4
|
+
__extra?: {
|
|
5
|
+
startTime: number;
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
__nativeBuffers__?: NativeBufferElement[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
interface NativeBufferElement {
|
|
11
|
+
key: string;
|
|
12
|
+
value?: ArrayBuffer;
|
|
13
|
+
base64?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function unpack(data: unknown): DataObj;
|
|
16
|
+
export declare function pack(_data?: {}, useArrayBuffer?: boolean): Record<string, unknown>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare let joliboxJSCore: jsb.JSCore | undefined;
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
JoliAndroidSDKBridge?: {
|
|
5
|
+
invoke: (invokeString: string) => void;
|
|
6
|
+
onDocumentReady: (paramsstr: string) => void;
|
|
7
|
+
doExit: (uuidString: string) => void;
|
|
8
|
+
};
|
|
9
|
+
webkit?: {
|
|
10
|
+
messageHandlers: {
|
|
11
|
+
invoke: {
|
|
12
|
+
postMessage: (params: {
|
|
13
|
+
event: string;
|
|
14
|
+
callbackId: number;
|
|
15
|
+
paramsString: string;
|
|
16
|
+
}) => void;
|
|
17
|
+
};
|
|
18
|
+
publish: {
|
|
19
|
+
postMessage: (params: {
|
|
20
|
+
event: string;
|
|
21
|
+
webviewIds: string;
|
|
22
|
+
paramsString: string;
|
|
23
|
+
}) => void;
|
|
24
|
+
};
|
|
25
|
+
onDocumentReady: {
|
|
26
|
+
postMessage: (params: {
|
|
27
|
+
path: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
};
|
|
30
|
+
doExit: {
|
|
31
|
+
postMessage: (params: {
|
|
32
|
+
uuid: string;
|
|
33
|
+
shouldInterrupt: boolean;
|
|
34
|
+
}) => void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export declare const RuntimeLoader: {
|
|
41
|
+
trigger(): void;
|
|
42
|
+
exit(): boolean;
|
|
43
|
+
onReady(fn: () => void): void;
|
|
44
|
+
doExit(fn: () => boolean): void;
|
|
45
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface MessageEvent {
|
|
2
|
+
data: string;
|
|
3
|
+
ports: MessagePort[];
|
|
4
|
+
}
|
|
5
|
+
interface MessagePort {
|
|
6
|
+
onmessage: (msg: MessageEvent) => void;
|
|
7
|
+
postMessage: (msg: string) => void;
|
|
8
|
+
publish: (event: string, data: Record<string, unknown>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare let messagePort: MessagePort | undefined;
|
|
11
|
+
export declare function initMessagePort(): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FetchResponse, FetchOptions } from './types';
|
|
2
|
+
type Fetch = <T>(url: string, innerOptions?: FetchOptions & {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}) => Promise<{
|
|
5
|
+
url: string;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
method: string;
|
|
8
|
+
response: FetchResponse<T>;
|
|
9
|
+
}>;
|
|
10
|
+
type PublicFetch = <T>(url: string, options?: FetchOptions) => Promise<{
|
|
11
|
+
url: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
method: string;
|
|
14
|
+
response: FetchResponse<T>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function createFetch(createMethod: 'createRequestTaskSync', operateMethod: 'operateRequestTaskSync', options?: {
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
type: 'public';
|
|
19
|
+
}): PublicFetch;
|
|
20
|
+
export declare function createFetch(createMethod: 'createRequestTaskSync', operateMethod: 'operateRequestTaskSync', options?: {
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
type: 'inner';
|
|
23
|
+
defaultHeaders?: Record<string, string>;
|
|
24
|
+
}): Fetch;
|
|
25
|
+
export declare function parseJSON(data: string): any;
|
|
26
|
+
export declare function normalizeData(data: unknown, contentType?: string): string | ArrayBuffer;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inner fetch
|
|
3
|
+
*/
|
|
4
|
+
export declare const innerFetch: <T>(url: string, innerOptions?: import("./types").FetchOptions & {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
url: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
method: string;
|
|
10
|
+
response: import("./types").FetchResponse<T>;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FetchResponse, DownLoadResponse, UpLoadResponse, RequestFrom } from './types';
|
|
2
|
+
type NetworkResponse = FetchResponse | DownLoadResponse | UpLoadResponse;
|
|
3
|
+
interface ReportNetworkOptions {
|
|
4
|
+
state: 'success' | 'fail';
|
|
5
|
+
params: Record<string, unknown>;
|
|
6
|
+
response: NetworkResponse;
|
|
7
|
+
startTime: number;
|
|
8
|
+
endTime: number;
|
|
9
|
+
callbackStartTime?: number;
|
|
10
|
+
callbackEndTime?: number;
|
|
11
|
+
requestId?: string;
|
|
12
|
+
requestFrom?: RequestFrom;
|
|
13
|
+
}
|
|
14
|
+
export declare function reportNetworkAPI(method: string, url: string, options: ReportNetworkOptions): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
interface Profile {
|
|
2
|
+
socketReused?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export interface DownLoadOptions {
|
|
5
|
+
url: string;
|
|
6
|
+
header: Record<string, unknown>;
|
|
7
|
+
filePath?: string;
|
|
8
|
+
appendHostCookie?: boolean;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface DownLoadResponse {
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
tempFilePath?: string;
|
|
14
|
+
errMsg?: string;
|
|
15
|
+
profile?: Profile;
|
|
16
|
+
filePath?: string;
|
|
17
|
+
header?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export type HTTPMethod = 'GET' | 'OPTIONS' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT' | 'PATCH';
|
|
20
|
+
export interface FetchOptions {
|
|
21
|
+
method?: HTTPMethod;
|
|
22
|
+
data?: Record<string, unknown> | string | ArrayBuffer;
|
|
23
|
+
query?: Record<string, string>;
|
|
24
|
+
header?: Record<string, string>;
|
|
25
|
+
dataType?: string;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
enableCache?: boolean;
|
|
28
|
+
responseType?: string;
|
|
29
|
+
appendHostCookie?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface FetchResponse<T = string | JSON | ArrayBuffer | undefined> {
|
|
32
|
+
header?: Record<string, string>;
|
|
33
|
+
code?: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
data: T;
|
|
36
|
+
errMsg?: string;
|
|
37
|
+
prefetchDetail?: number;
|
|
38
|
+
size?: number;
|
|
39
|
+
profile?: Profile;
|
|
40
|
+
}
|
|
41
|
+
export interface UpLoadOptions {
|
|
42
|
+
url: string;
|
|
43
|
+
filePath: string;
|
|
44
|
+
name: string;
|
|
45
|
+
header: Record<string, unknown>;
|
|
46
|
+
formData: Record<string, unknown>;
|
|
47
|
+
appendHostCookie?: boolean;
|
|
48
|
+
timeout?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface UpLoadResponse<T = string | Record<string, unknown> | ArrayBuffer | undefined> {
|
|
51
|
+
statusCode?: number;
|
|
52
|
+
data: T;
|
|
53
|
+
errMsg?: string;
|
|
54
|
+
progress?: number;
|
|
55
|
+
profile?: Profile;
|
|
56
|
+
}
|
|
57
|
+
export declare enum RequestFrom {
|
|
58
|
+
PUBLIC = "public",
|
|
59
|
+
INNER = "inner"
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type HTTPMethod = 'GET' | 'OPTIONS' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT' | 'PATCH';
|
|
2
|
+
export declare function normalizeHeader(header: unknown): Record<string, string>;
|
|
3
|
+
export declare function normalizeFormData(formData: unknown): Record<string, string>;
|
|
4
|
+
export declare function normalizeMethod(method?: string): HTTPMethod;
|
|
5
|
+
export declare function normalizeTimeout(time: number | undefined, unlimited?: boolean): number | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* modify url
|
|
8
|
+
*/
|
|
9
|
+
export declare function dirtyURL(url: string, method: HTTPMethod, data?: unknown): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './errors';
|
|
2
|
+
import { EventEmitter } from '@jolibox/common';
|
|
3
|
+
export * from '../../common/report/types';
|
|
4
|
+
import { NativeTaskTracker } from './task-tracker';
|
|
5
|
+
declare const track: import("@/common/report").Track, trackPerformance: import("@/common/report").TrackPerformance;
|
|
6
|
+
export { track, trackPerformance };
|
|
7
|
+
export declare const nativeTaskEmitter: EventEmitter<{
|
|
8
|
+
visible: [boolean];
|
|
9
|
+
}, "visible">;
|
|
10
|
+
export declare const taskTracker: NativeTaskTracker;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 任务上报
|
|
3
|
+
*/
|
|
4
|
+
import { TaskTracker, TaskPoint } from '@/common/report/task-track';
|
|
5
|
+
import { EventEmitter } from '@jolibox/common';
|
|
6
|
+
type NativeTaskPointEvent = 'OPEN_GAME' | 'CLOSE_GAME' | 'LEVEL_FINISHED' | 'TASK_FINISHED' | 'LEVEL_UPGRADE' | 'HISTORY_USER_LEVEL' | 'HISTORY_USER_SCORE' | 'TASK_PAYMENT' | 'TASK_EVENT';
|
|
7
|
+
export type NativeTaskPoint = {
|
|
8
|
+
event: NativeTaskPointEvent;
|
|
9
|
+
params: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export declare class NativeTaskTracker extends TaskTracker {
|
|
12
|
+
private gameId;
|
|
13
|
+
private sessionId;
|
|
14
|
+
constructor(eventEmitter: EventEmitter<{
|
|
15
|
+
visible: [boolean];
|
|
16
|
+
}>, interval?: number);
|
|
17
|
+
reporter(point: TaskPoint): Promise<void>;
|
|
18
|
+
reportToNative(point: NativeTaskPoint): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const esbuild = require('esbuild');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
function versionPlugin(version) {
|
|
5
|
+
return {
|
|
6
|
+
name: 'version',
|
|
7
|
+
setup(build) {
|
|
8
|
+
build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
|
|
9
|
+
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
10
|
+
return {
|
|
11
|
+
contents: contents.replace(/__JOLIBOX_LOCAL_SDK_VERSION__/g, version),
|
|
12
|
+
loader: args.path.endsWith('tsx') ? 'tsx' : 'ts'
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseArgs() {
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
const options = {
|
|
22
|
+
format: 'esm', // 默认值
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < args.length; i++) {
|
|
26
|
+
const arg = args[i];
|
|
27
|
+
|
|
28
|
+
if (arg === '--format' || arg === '-f') {
|
|
29
|
+
const format = args[i + 1];
|
|
30
|
+
if (['esm', 'cjs', 'iife'].includes(format)) {
|
|
31
|
+
options.format = format;
|
|
32
|
+
}
|
|
33
|
+
i++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const options = parseArgs();
|
|
41
|
+
|
|
42
|
+
function build(format) {
|
|
43
|
+
return esbuild.build({
|
|
44
|
+
entryPoints: ['src/index.native.ts', 'src/index.ts'],
|
|
45
|
+
bundle: true,
|
|
46
|
+
outdir: 'dist',
|
|
47
|
+
format: format,
|
|
48
|
+
// minify: true,
|
|
49
|
+
loader: {
|
|
50
|
+
'.ts': 'ts',
|
|
51
|
+
'.tsx': 'tsx',
|
|
52
|
+
'.js': 'jsx'
|
|
53
|
+
},
|
|
54
|
+
plugins: [versionPlugin(process.env.BUILD_VERSION || '1.0.0')],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
(async ()=>{
|
|
59
|
+
try{
|
|
60
|
+
await build(options.format);
|
|
61
|
+
}catch(e) {
|
|
62
|
+
console.error(e);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
})()
|
|
66
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
|
+
|
|
3
|
+
> @jolibox/implement@1.1.4-beta.4 clean
|
|
4
|
+
> rimraf ./dist
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> @jolibox/implement@1.1.4-beta.4 build:esm
|
|
8
|
+
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jolibox/implement",
|
|
3
|
+
"description": "This project is Jolibox JS-SDk implementation for Native && H5",
|
|
4
|
+
"version": "1.1.4-beta.4",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@jolibox/common": "1.1.4-beta.4",
|
|
10
|
+
"@jolibox/types": "1.1.4-beta.4",
|
|
11
|
+
"localforage": "1.10.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "5.7.3",
|
|
15
|
+
"@types/jest": "28.1.1",
|
|
16
|
+
"rimraf": "6.0.1",
|
|
17
|
+
"esbuild": "0.24.2",
|
|
18
|
+
"@jolibox/eslint-config": "1.0.0"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf ./dist",
|
|
22
|
+
"build": "npm run clean && npm run build:esm && tsc",
|
|
23
|
+
"build:esm": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=esm",
|
|
24
|
+
"build:iife": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=iife",
|
|
25
|
+
"build:cjs": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=cjs",
|
|
26
|
+
"dev": "tsc --watch",
|
|
27
|
+
"test": "jest"
|
|
28
|
+
},
|
|
29
|
+
"readme": "# Jolibox JSSDK Interface\n"
|
|
30
|
+
}
|