@hlw-uni-mp/request 1.0.1 → 1.0.2

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/index.js CHANGED
@@ -58,64 +58,57 @@ module.exports = __toCommonJS(index_exports);
58
58
  // src/device/index.ts
59
59
  var deviceCache = null;
60
60
  var currentNetworkType = "";
61
- try {
62
- if (typeof uni !== "undefined" && uni.getNetworkType) {
63
- uni.getNetworkType({
64
- success(res) {
65
- currentNetworkType = res.networkType || "";
66
- if (deviceCache) {
67
- deviceCache.networkType = currentNetworkType;
68
- }
69
- }
70
- });
71
- if (uni.onNetworkStatusChange) {
72
- uni.onNetworkStatusChange((res) => {
73
- currentNetworkType = res.networkType || "";
74
- if (deviceCache) {
75
- deviceCache.networkType = currentNetworkType;
76
- }
77
- });
61
+ uni.getNetworkType({
62
+ success(res) {
63
+ currentNetworkType = res.networkType || "";
64
+ if (deviceCache) {
65
+ deviceCache.networkType = currentNetworkType;
78
66
  }
79
67
  }
80
- } catch {
81
- }
68
+ });
69
+ uni.onNetworkStatusChange((res) => {
70
+ currentNetworkType = res.networkType || "";
71
+ if (deviceCache) {
72
+ deviceCache.networkType = currentNetworkType;
73
+ }
74
+ });
82
75
  function getDevice() {
83
76
  if (deviceCache) return deviceCache;
84
- const deviceRaw = typeof uni !== "undefined" ? uni.getDeviceInfo?.() : void 0;
85
- const windowRaw = typeof uni !== "undefined" ? uni.getWindowInfo?.() : void 0;
86
- const appRaw = typeof uni !== "undefined" ? uni.getAppBaseInfo?.() : void 0;
87
- const accountRaw = typeof uni !== "undefined" ? uni.getAccountInfoSync?.() : void 0;
88
- const system = deviceRaw?.system || "";
77
+ const deviceRaw = uni.getDeviceInfo();
78
+ const windowRaw = uni.getWindowInfo();
79
+ const appRaw = uni.getAppBaseInfo();
80
+ const accountRaw = uni.getAccountInfoSync();
81
+ const system = deviceRaw.system || "";
89
82
  deviceCache = {
90
- appid: accountRaw?.miniProgram?.appId || "",
91
- appName: appRaw?.appName || "",
92
- version: appRaw?.appVersion || "",
93
- versionCode: appRaw?.appVersionCode || "",
94
- channel: appRaw?.appChannel || "",
95
- deviceId: deviceRaw?.deviceId || "",
96
- deviceType: deviceRaw?.deviceType || "",
97
- deviceOrientation: deviceRaw?.deviceOrientation || windowRaw?.deviceOrientation || "portrait",
98
- brand: deviceRaw?.brand || "",
99
- model: deviceRaw?.model || "",
83
+ appid: accountRaw.miniProgram?.appId || "",
84
+ appName: appRaw.appName || "",
85
+ version: appRaw.appVersion || "",
86
+ versionCode: appRaw.appVersionCode || "",
87
+ channel: appRaw.appChannel || "",
88
+ deviceId: deviceRaw.deviceId || "",
89
+ deviceType: deviceRaw.deviceType || "",
90
+ deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
91
+ brand: deviceRaw.brand || "",
92
+ model: deviceRaw.model || "",
100
93
  system,
101
94
  os: system.split(" ")[0] || "",
102
- pixelRatio: windowRaw?.pixelRatio || 0,
103
- screenWidth: windowRaw?.screenWidth || 0,
104
- screenHeight: windowRaw?.screenHeight || 0,
105
- windowWidth: windowRaw?.windowWidth || 0,
106
- windowHeight: windowRaw?.windowHeight || 0,
107
- statusBarHeight: windowRaw?.statusBarHeight || 0,
108
- sdkVersion: appRaw?.SDKVersion || "",
109
- hostName: appRaw?.hostName || "",
110
- hostVersion: appRaw?.hostVersion || "",
111
- hostLanguage: appRaw?.hostLanguage || "",
112
- hostTheme: appRaw?.hostTheme || "",
113
- platform: deviceRaw?.platform || "",
114
- language: appRaw?.appLanguage || appRaw?.language || "",
95
+ pixelRatio: windowRaw.pixelRatio || 0,
96
+ screenWidth: windowRaw.screenWidth || 0,
97
+ screenHeight: windowRaw.screenHeight || 0,
98
+ windowWidth: windowRaw.windowWidth || 0,
99
+ windowHeight: windowRaw.windowHeight || 0,
100
+ statusBarHeight: windowRaw.statusBarHeight || 0,
101
+ sdkVersion: appRaw.SDKVersion || "",
102
+ hostName: appRaw.hostName || "",
103
+ hostVersion: appRaw.hostVersion || "",
104
+ hostLanguage: appRaw.hostLanguage || "",
105
+ hostTheme: appRaw.hostTheme || "",
106
+ platform: deviceRaw.platform || "",
107
+ language: appRaw.appLanguage || appRaw.language || "",
115
108
  networkType: currentNetworkType,
116
- benchmarkLevel: deviceRaw?.benchmarkLevel || 0,
117
- theme: appRaw?.theme || "light",
118
- fontSizeSetting: appRaw?.fontSizeSetting || 16
109
+ benchmarkLevel: deviceRaw.benchmarkLevel || 0,
110
+ theme: appRaw.theme || "light",
111
+ fontSizeSetting: appRaw.fontSizeSetting || 16
119
112
  };
120
113
  return deviceCache;
121
114
  }
@@ -577,9 +570,7 @@ function handleUnauthorized(message, callback) {
577
570
  const now = Date.now();
578
571
  if (now - lastToastTime > 3e3) {
579
572
  lastToastTime = now;
580
- if (typeof uni !== "undefined" && uni.showToast) {
581
- uni.showToast({ title: message, icon: "none" });
582
- }
573
+ uni.showToast({ title: message, icon: "none" });
583
574
  }
584
575
  if (callback) {
585
576
  callback(message);
package/dist/index.mjs CHANGED
@@ -1,64 +1,57 @@
1
1
  // src/device/index.ts
2
2
  var deviceCache = null;
3
3
  var currentNetworkType = "";
4
- try {
5
- if (typeof uni !== "undefined" && uni.getNetworkType) {
6
- uni.getNetworkType({
7
- success(res) {
8
- currentNetworkType = res.networkType || "";
9
- if (deviceCache) {
10
- deviceCache.networkType = currentNetworkType;
11
- }
12
- }
13
- });
14
- if (uni.onNetworkStatusChange) {
15
- uni.onNetworkStatusChange((res) => {
16
- currentNetworkType = res.networkType || "";
17
- if (deviceCache) {
18
- deviceCache.networkType = currentNetworkType;
19
- }
20
- });
4
+ uni.getNetworkType({
5
+ success(res) {
6
+ currentNetworkType = res.networkType || "";
7
+ if (deviceCache) {
8
+ deviceCache.networkType = currentNetworkType;
21
9
  }
22
10
  }
23
- } catch {
24
- }
11
+ });
12
+ uni.onNetworkStatusChange((res) => {
13
+ currentNetworkType = res.networkType || "";
14
+ if (deviceCache) {
15
+ deviceCache.networkType = currentNetworkType;
16
+ }
17
+ });
25
18
  function getDevice() {
26
19
  if (deviceCache) return deviceCache;
27
- const deviceRaw = typeof uni !== "undefined" ? uni.getDeviceInfo?.() : void 0;
28
- const windowRaw = typeof uni !== "undefined" ? uni.getWindowInfo?.() : void 0;
29
- const appRaw = typeof uni !== "undefined" ? uni.getAppBaseInfo?.() : void 0;
30
- const accountRaw = typeof uni !== "undefined" ? uni.getAccountInfoSync?.() : void 0;
31
- const system = deviceRaw?.system || "";
20
+ const deviceRaw = uni.getDeviceInfo();
21
+ const windowRaw = uni.getWindowInfo();
22
+ const appRaw = uni.getAppBaseInfo();
23
+ const accountRaw = uni.getAccountInfoSync();
24
+ const system = deviceRaw.system || "";
32
25
  deviceCache = {
33
- appid: accountRaw?.miniProgram?.appId || "",
34
- appName: appRaw?.appName || "",
35
- version: appRaw?.appVersion || "",
36
- versionCode: appRaw?.appVersionCode || "",
37
- channel: appRaw?.appChannel || "",
38
- deviceId: deviceRaw?.deviceId || "",
39
- deviceType: deviceRaw?.deviceType || "",
40
- deviceOrientation: deviceRaw?.deviceOrientation || windowRaw?.deviceOrientation || "portrait",
41
- brand: deviceRaw?.brand || "",
42
- model: deviceRaw?.model || "",
26
+ appid: accountRaw.miniProgram?.appId || "",
27
+ appName: appRaw.appName || "",
28
+ version: appRaw.appVersion || "",
29
+ versionCode: appRaw.appVersionCode || "",
30
+ channel: appRaw.appChannel || "",
31
+ deviceId: deviceRaw.deviceId || "",
32
+ deviceType: deviceRaw.deviceType || "",
33
+ deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
34
+ brand: deviceRaw.brand || "",
35
+ model: deviceRaw.model || "",
43
36
  system,
44
37
  os: system.split(" ")[0] || "",
45
- pixelRatio: windowRaw?.pixelRatio || 0,
46
- screenWidth: windowRaw?.screenWidth || 0,
47
- screenHeight: windowRaw?.screenHeight || 0,
48
- windowWidth: windowRaw?.windowWidth || 0,
49
- windowHeight: windowRaw?.windowHeight || 0,
50
- statusBarHeight: windowRaw?.statusBarHeight || 0,
51
- sdkVersion: appRaw?.SDKVersion || "",
52
- hostName: appRaw?.hostName || "",
53
- hostVersion: appRaw?.hostVersion || "",
54
- hostLanguage: appRaw?.hostLanguage || "",
55
- hostTheme: appRaw?.hostTheme || "",
56
- platform: deviceRaw?.platform || "",
57
- language: appRaw?.appLanguage || appRaw?.language || "",
38
+ pixelRatio: windowRaw.pixelRatio || 0,
39
+ screenWidth: windowRaw.screenWidth || 0,
40
+ screenHeight: windowRaw.screenHeight || 0,
41
+ windowWidth: windowRaw.windowWidth || 0,
42
+ windowHeight: windowRaw.windowHeight || 0,
43
+ statusBarHeight: windowRaw.statusBarHeight || 0,
44
+ sdkVersion: appRaw.SDKVersion || "",
45
+ hostName: appRaw.hostName || "",
46
+ hostVersion: appRaw.hostVersion || "",
47
+ hostLanguage: appRaw.hostLanguage || "",
48
+ hostTheme: appRaw.hostTheme || "",
49
+ platform: deviceRaw.platform || "",
50
+ language: appRaw.appLanguage || appRaw.language || "",
58
51
  networkType: currentNetworkType,
59
- benchmarkLevel: deviceRaw?.benchmarkLevel || 0,
60
- theme: appRaw?.theme || "light",
61
- fontSizeSetting: appRaw?.fontSizeSetting || 16
52
+ benchmarkLevel: deviceRaw.benchmarkLevel || 0,
53
+ theme: appRaw.theme || "light",
54
+ fontSizeSetting: appRaw.fontSizeSetting || 16
62
55
  };
63
56
  return deviceCache;
64
57
  }
@@ -520,9 +513,7 @@ function handleUnauthorized(message, callback) {
520
513
  const now = Date.now();
521
514
  if (now - lastToastTime > 3e3) {
522
515
  lastToastTime = now;
523
- if (typeof uni !== "undefined" && uni.showToast) {
524
- uni.showToast({ title: message, icon: "none" });
525
- }
516
+ uni.showToast({ title: message, icon: "none" });
526
517
  }
527
518
  if (callback) {
528
519
  callback(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni-mp/request",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Universal Uni-App HTTP and upload client with RSA encryption & sign verification",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",