@jolibox/implement 1.1.16-beta.3 → 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.3 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.3 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.3",
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.3",
10
- "@jolibox/types": "1.1.16-beta.3",
11
- "@jolibox/native-bridge": "1.1.16-beta.3",
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"
@@ -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
+ };