@jolibox/implement 1.1.16-beta.2 → 1.1.16-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.
@@ -25,4 +25,11 @@ export declare function createFetch(createMethod: 'createRequestTaskSync', opera
25
25
  }): Fetch;
26
26
  export declare function parseJSON(data: string): any;
27
27
  export declare function normalizeData(data: unknown, contentType?: string): string | ArrayBuffer;
28
+ export declare const sendRequestBodyToNative: (data: unknown, contentType: string) => {
29
+ errMsg: string;
30
+ errNo?: number;
31
+ data: {
32
+ requestId: string;
33
+ };
34
+ };
28
35
  export {};
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.16-beta.2 clean
3
+ > @jolibox/implement@1.1.16-beta.4 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.16-beta.2 build:esm
7
+ > @jolibox/implement@1.1.16-beta.4 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.16-beta.2",
4
+ "version": "1.1.16-beta.4",
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.16-beta.2",
10
- "@jolibox/types": "1.1.16-beta.2",
11
- "@jolibox/native-bridge": "1.1.16-beta.2",
9
+ "@jolibox/common": "1.1.16-beta.4",
10
+ "@jolibox/types": "1.1.16-beta.4",
11
+ "@jolibox/native-bridge": "1.1.16-beta.4",
12
12
  "localforage": "1.10.0",
13
13
  "@jolibox/ui": "1.0.0",
14
14
  "web-vitals": "4.2.4"
@@ -43,8 +43,13 @@ const wrapContext = () => {
43
43
  const defaultGameID = urlParams.get('mpId') ?? urlParams.get('appId') ?? urlParams.get('gameId') ?? '';
44
44
  const sessionId =
45
45
  env.clientSessionId ?? payloadJson?.sessionId ?? urlParams.get('sessionId') ?? defaultSessionId;
46
- const testAdsMode = !!(payloadJson?.testAdsMode ?? urlParams.get('testAdsMode') === 'true');
47
- const joliboxEnv = payloadJson?.joliboxEnv ?? urlParams.get('joliboxEnv') ?? 'production';
46
+ const testAdsMode = !!(
47
+ payloadJson?.testAdsMode ??
48
+ payloadJson?.__testAdsMode ??
49
+ urlParams.get('testAdsMode') === 'true'
50
+ );
51
+ const joliboxEnv =
52
+ payloadJson?.joliboxEnv ?? payloadJson?.__joliboxEnv ?? urlParams.get('joliboxEnv') ?? 'production';
48
53
  const testMode = joliboxEnv === 'staging';
49
54
  const channel = headerJson?.channel;
50
55
 
@@ -10,8 +10,8 @@ interface HeaderJson {
10
10
 
11
11
  interface PayloadJson {
12
12
  id?: string;
13
- testAdsMode?: boolean;
14
- joliboxEnv?: 'staging' | 'production';
13
+ testAdsMode?: boolean; // deprecated
14
+ joliboxEnv?: 'staging' | 'production'; // deprecated
15
15
  sessionId?: string;
16
16
  __mpType?: 'game' | 'miniApp';
17
17
  __orientation?: 'HORIZONTAL' | 'VERTICAL';
@@ -20,6 +20,8 @@ interface PayloadJson {
20
20
  __showStatusBar?: boolean;
21
21
  __shouldInterupt?: boolean;
22
22
  __from?: number; // 从哪个小程序打开的
23
+ __testAdsMode?: boolean;
24
+ __joliboxEnv?: 'staging' | 'production';
23
25
  }
24
26
 
25
27
  interface Signature {
@@ -1,4 +1,4 @@
1
- import { isString, logger, Deferred, isObject, hostEmitter } from '@jolibox/common';
1
+ import { isString, logger, Deferred, isObject, hostEmitter, isUndefined } from '@jolibox/common';
2
2
  import { reportNetworkAPI } from './report';
3
3
  import { RequestFrom } from './types';
4
4
  import { FetchResponse, FetchOptions } from './types';
@@ -136,6 +136,7 @@ export function createFetch(
136
136
  if (timeout) {
137
137
  Object.assign(params, { timeout });
138
138
  }
139
+
139
140
  const {
140
141
  data: { requestTaskId }
141
142
  } = invokeNative(createMethod, params);
@@ -240,3 +241,49 @@ export function normalizeData(data: unknown, contentType = 'application/json') {
240
241
 
241
242
  return String(data);
242
243
  }
244
+
245
+ const normalizeRequestBody = (
246
+ data: unknown,
247
+ contentType = 'application/json'
248
+ ): {
249
+ body: JSON | string;
250
+ dataType: 'json' | 'text';
251
+ } => {
252
+ if (isUndefined(data) || data instanceof ArrayBuffer) {
253
+ return {
254
+ body: '{}',
255
+ dataType: 'json'
256
+ };
257
+ }
258
+
259
+ if (typeof data === 'string') {
260
+ return {
261
+ body: data,
262
+ dataType: 'text'
263
+ };
264
+ }
265
+
266
+ const type = contentType.toLowerCase();
267
+ if (
268
+ (type.includes('application/x-www-form-urlencoded') || type.includes('application/json')) &&
269
+ typeof data === 'object'
270
+ ) {
271
+ return {
272
+ body: JSON.parse(JSON.stringify(data)),
273
+ dataType: 'json'
274
+ };
275
+ }
276
+
277
+ return {
278
+ body: String(data),
279
+ dataType: 'text'
280
+ };
281
+ };
282
+
283
+ export const sendRequestBodyToNative = (data: unknown, contentType: string) => {
284
+ const { body, dataType } = normalizeRequestBody(data, contentType);
285
+ return invokeNative('sendRequestBodySync', {
286
+ body,
287
+ dataType
288
+ });
289
+ };