ota-native-bridge 1.2.0 → 1.2.1
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/dist/cjs/index.js +2 -1
- package/dist/cjs/runtime.js +18 -1
- package/dist/cjs/version.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/native.d.ts +1 -1
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +17 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/USAGE.md +1 -1
- package/ota-native-bridge.js +16 -8
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Crypto = exports.postEncrypted = exports.encryptRequestBody = exports.isNativeBridgeAvailable = exports.getNativePostMessage = exports.invokeNative = exports.isNativePlatform = exports.getPlatform = exports.whenReady = exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.Browser = exports.Ota = exports.App = exports.Native = exports.SDK_VERSION = exports.PACKAGE_NAME = void 0;
|
|
17
|
+
exports.Crypto = exports.postEncrypted = exports.encryptRequestBody = exports.isNativeBridgeAvailable = exports.getNativePostMessage = exports.decodeBridgePayload = exports.invokeNative = exports.isNativePlatform = exports.getPlatform = exports.whenReady = exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.Browser = exports.Ota = exports.App = exports.Native = exports.SDK_VERSION = exports.PACKAGE_NAME = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
19
|
var version_1 = require("./version");
|
|
20
20
|
Object.defineProperty(exports, "PACKAGE_NAME", { enumerable: true, get: function () { return version_1.PACKAGE_NAME; } });
|
|
@@ -57,6 +57,7 @@ Object.defineProperty(exports, "whenReady", { enumerable: true, get: function ()
|
|
|
57
57
|
Object.defineProperty(exports, "getPlatform", { enumerable: true, get: function () { return runtime_1.getPlatform; } });
|
|
58
58
|
Object.defineProperty(exports, "isNativePlatform", { enumerable: true, get: function () { return runtime_1.isNativePlatform; } });
|
|
59
59
|
Object.defineProperty(exports, "invokeNative", { enumerable: true, get: function () { return runtime_1.invokeNative; } });
|
|
60
|
+
Object.defineProperty(exports, "decodeBridgePayload", { enumerable: true, get: function () { return runtime_1.decodeBridgePayload; } });
|
|
60
61
|
var native_messenger_1 = require("./native-messenger");
|
|
61
62
|
Object.defineProperty(exports, "getNativePostMessage", { enumerable: true, get: function () { return native_messenger_1.getNativePostMessage; } });
|
|
62
63
|
Object.defineProperty(exports, "isNativeBridgeAvailable", { enumerable: true, get: function () { return native_messenger_1.isNativeBridgeAvailable; } });
|
package/dist/cjs/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNativeBridgeAvailable = void 0;
|
|
4
|
+
exports.decodeBridgePayload = decodeBridgePayload;
|
|
4
5
|
exports.callNative = callNative;
|
|
5
6
|
exports.getPlatform = getPlatform;
|
|
6
7
|
exports.isNativePlatform = isNativePlatform;
|
|
@@ -13,6 +14,22 @@ const BRIDGE_READY_EVENT = 'nativebridgeready';
|
|
|
13
14
|
let seq = 0;
|
|
14
15
|
const pending = {};
|
|
15
16
|
let readyPromise = null;
|
|
17
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
18
|
+
function decodeBridgePayload(payload) {
|
|
19
|
+
if (payload == null || typeof payload !== 'string') {
|
|
20
|
+
return payload;
|
|
21
|
+
}
|
|
22
|
+
const trimmed = payload.trim();
|
|
23
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(payload);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return payload;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
16
33
|
function installNativeCallback() {
|
|
17
34
|
if (typeof window === 'undefined' || window.__nativeBridgeCallback) {
|
|
18
35
|
return;
|
|
@@ -23,7 +40,7 @@ function installNativeCallback() {
|
|
|
23
40
|
return;
|
|
24
41
|
}
|
|
25
42
|
delete pending[id];
|
|
26
|
-
const data =
|
|
43
|
+
const data = decodeBridgePayload(payload);
|
|
27
44
|
if (success) {
|
|
28
45
|
item.resolve(data);
|
|
29
46
|
}
|
package/dist/cjs/version.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './types';
|
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
3
|
export { Native, App, Ota, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
4
4
|
export type { NativeCallback, NativePlatform } from './runtime';
|
|
5
|
-
export { whenReady, getPlatform, isNativePlatform, invokeNative } from './runtime';
|
|
5
|
+
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
6
6
|
export { getNativePostMessage, isNativeBridgeAvailable, type NativePostMessage, } from './native-messenger';
|
|
7
7
|
export { encryptRequestBody, postEncrypted, type EncryptedEnvelope, } from './crypto';
|
|
8
8
|
export { Crypto } from './crypto-ns';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
3
|
export { Native, App, Ota, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
4
|
-
export { whenReady, getPlatform, isNativePlatform, invokeNative } from './runtime';
|
|
4
|
+
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
5
5
|
export { getNativePostMessage, isNativeBridgeAvailable, } from './native-messenger';
|
|
6
6
|
export { encryptRequestBody, postEncrypted, } from './crypto';
|
|
7
7
|
export { Crypto } from './crypto-ns';
|
package/dist/native.d.ts
CHANGED
|
@@ -207,7 +207,7 @@ export declare const Native: {
|
|
|
207
207
|
readonly Push: {
|
|
208
208
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
209
209
|
};
|
|
210
|
-
readonly sdkVersion: "1.2.
|
|
210
|
+
readonly sdkVersion: "1.2.1";
|
|
211
211
|
readonly getPlatform: typeof getPlatform;
|
|
212
212
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
213
213
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isNativeBridgeAvailable } from './native-messenger';
|
|
2
2
|
export type NativePlatform = 'android' | 'ios' | 'harmony' | 'web';
|
|
3
3
|
export type NativeCallback<T> = (result: T, error?: Error) => void;
|
|
4
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
5
|
+
export declare function decodeBridgePayload(payload: string | object | null | undefined): unknown;
|
|
4
6
|
export declare function callNative<T>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
5
7
|
export declare function getPlatform(): NativePlatform;
|
|
6
8
|
export declare function isNativePlatform(): boolean;
|
package/dist/runtime.js
CHANGED
|
@@ -3,6 +3,22 @@ const BRIDGE_READY_EVENT = 'nativebridgeready';
|
|
|
3
3
|
let seq = 0;
|
|
4
4
|
const pending = {};
|
|
5
5
|
let readyPromise = null;
|
|
6
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
7
|
+
export function decodeBridgePayload(payload) {
|
|
8
|
+
if (payload == null || typeof payload !== 'string') {
|
|
9
|
+
return payload;
|
|
10
|
+
}
|
|
11
|
+
const trimmed = payload.trim();
|
|
12
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(payload);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return payload;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
function installNativeCallback() {
|
|
7
23
|
if (typeof window === 'undefined' || window.__nativeBridgeCallback) {
|
|
8
24
|
return;
|
|
@@ -13,7 +29,7 @@ function installNativeCallback() {
|
|
|
13
29
|
return;
|
|
14
30
|
}
|
|
15
31
|
delete pending[id];
|
|
16
|
-
const data =
|
|
32
|
+
const data = decodeBridgePayload(payload);
|
|
17
33
|
if (success) {
|
|
18
34
|
item.resolve(data);
|
|
19
35
|
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/docs/USAGE.md
CHANGED
|
@@ -1481,6 +1481,6 @@ A:执行 `npm run build` 生成 `dist/*.d.ts`,或确认依赖版本已包含
|
|
|
1481
1481
|
|
|
1482
1482
|
## 11. 相关文档
|
|
1483
1483
|
|
|
1484
|
-
- [README.md](../README.md) —
|
|
1484
|
+
- [README.md](../README.md) — 包结构与快速上手
|
|
1485
1485
|
- 仓库 `AppUpgradeOTASystem` 根目录 `README.md` — OTA 系统整体说明
|
|
1486
1486
|
- 管理后台「公共接口」— REST / WebSocket 鉴权与端点列表
|
package/ota-native-bridge.js
CHANGED
|
@@ -38,15 +38,23 @@
|
|
|
38
38
|
var item = pending[id];
|
|
39
39
|
if (!item) return;
|
|
40
40
|
delete pending[id];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
var data = payload;
|
|
42
|
+
if (typeof payload === 'string') {
|
|
43
|
+
var trimmed = payload.replace(/^\s+|\s+$/g, '');
|
|
44
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
45
|
+
data = null;
|
|
46
|
+
} else {
|
|
47
|
+
try {
|
|
48
|
+
data = JSON.parse(payload);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
data = payload;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
53
|
+
}
|
|
54
|
+
if (success) {
|
|
55
|
+
item.resolve(data);
|
|
48
56
|
} else {
|
|
49
|
-
item.reject(new Error(
|
|
57
|
+
item.reject(new Error(String(data)));
|
|
50
58
|
}
|
|
51
59
|
};
|
|
52
60
|
|
|
@@ -357,7 +365,7 @@
|
|
|
357
365
|
};
|
|
358
366
|
|
|
359
367
|
global.Native = {
|
|
360
|
-
sdkVersion: '1.2.
|
|
368
|
+
sdkVersion: '1.2.1',
|
|
361
369
|
getPlatform: getPlatform,
|
|
362
370
|
isNativePlatform: isNativePlatform,
|
|
363
371
|
isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
|