@hlw-uni-mp/request 1.0.0 → 1.0.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/index.d.mts CHANGED
@@ -33,6 +33,22 @@ interface DeviceInfo {
33
33
  fontSizeSetting: number
34
34
  }
35
35
 
36
+ declare global {
37
+ namespace UniNamespace {
38
+ interface GetDeviceInfoResult {
39
+ benchmarkLevel?: number
40
+ }
41
+ interface GetAppBaseInfoResult {
42
+ appChannel?: string
43
+ appLanguage?: string
44
+ fontSizeSetting?: number
45
+ }
46
+ interface GetWindowInfoResult {
47
+ deviceOrientation?: 'portrait' | 'landscape'
48
+ }
49
+ }
50
+ }
51
+
36
52
  /**
37
53
  * SHA-256 哈希计算 (基于 crypto-js)
38
54
  */
package/dist/index.d.ts CHANGED
@@ -33,6 +33,22 @@ interface DeviceInfo {
33
33
  fontSizeSetting: number
34
34
  }
35
35
 
36
+ declare global {
37
+ namespace UniNamespace {
38
+ interface GetDeviceInfoResult {
39
+ benchmarkLevel?: number
40
+ }
41
+ interface GetAppBaseInfoResult {
42
+ appChannel?: string
43
+ appLanguage?: string
44
+ fontSizeSetting?: number
45
+ }
46
+ interface GetWindowInfoResult {
47
+ deviceOrientation?: 'portrait' | 'landscape'
48
+ }
49
+ }
50
+ }
51
+
36
52
  /**
37
53
  * SHA-256 哈希计算 (基于 crypto-js)
38
54
  */
package/dist/index.js CHANGED
@@ -81,40 +81,41 @@ try {
81
81
  }
82
82
  function getDevice() {
83
83
  if (deviceCache) return deviceCache;
84
- const deviceRaw = uni.getDeviceInfo?.() || {};
85
- const windowRaw = uni.getWindowInfo?.() || {};
86
- const appRaw = uni.getAppBaseInfo?.() || {};
87
- const system = deviceRaw.system || "";
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 || "";
88
89
  deviceCache = {
89
- appid: uni.getAccountInfoSync?.().miniProgram?.appId || "",
90
- appName: appRaw.appName || "",
91
- version: appRaw.appVersion || "",
92
- versionCode: appRaw.appVersionCode || "",
93
- channel: appRaw.appChannel || "",
94
- deviceId: deviceRaw.deviceId || "",
95
- deviceType: deviceRaw.deviceType || "",
96
- deviceOrientation: windowRaw.deviceOrientation || "portrait",
97
- brand: deviceRaw.brand || "",
98
- model: deviceRaw.model || "",
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 || "",
99
100
  system,
100
101
  os: system.split(" ")[0] || "",
101
- pixelRatio: windowRaw.pixelRatio || 0,
102
- screenWidth: windowRaw.screenWidth || 0,
103
- screenHeight: windowRaw.screenHeight || 0,
104
- windowWidth: windowRaw.windowWidth || 0,
105
- windowHeight: windowRaw.windowHeight || 0,
106
- statusBarHeight: windowRaw.statusBarHeight || 0,
107
- sdkVersion: appRaw.SDKVersion || "",
108
- hostName: appRaw.hostName || "",
109
- hostVersion: appRaw.hostVersion || "",
110
- hostLanguage: appRaw.hostLanguage || "",
111
- hostTheme: appRaw.hostTheme || "",
112
- platform: deviceRaw.platform || "",
113
- language: appRaw.appLanguage || "",
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 || "",
114
115
  networkType: currentNetworkType,
115
- benchmarkLevel: deviceRaw.benchmarkLevel || 0,
116
- theme: appRaw.theme || "light",
117
- fontSizeSetting: appRaw.fontSizeSetting || 16
116
+ benchmarkLevel: deviceRaw?.benchmarkLevel || 0,
117
+ theme: appRaw?.theme || "light",
118
+ fontSizeSetting: appRaw?.fontSizeSetting || 16
118
119
  };
119
120
  return deviceCache;
120
121
  }
@@ -368,13 +369,12 @@ function buildFormData(cred) {
368
369
  return { key: cred.key };
369
370
  }
370
371
  if (cred.type === "alioss") {
371
- const anyCred = cred;
372
372
  return {
373
373
  key: cred.key,
374
374
  policy: cred.policy,
375
- OSSAccessKeyId: cred.OSSAccessKeyId || anyCred.oSSAccessKeyId || anyCred.ossAccessKeyId || "",
376
- Signature: cred.Signature || anyCred.signature || "",
377
- success_action_status: cred.success_action_status || anyCred.successActionStatus || "200"
375
+ OSSAccessKeyId: cred.OSSAccessKeyId || cred.oSSAccessKeyId || "",
376
+ Signature: cred.Signature || cred.signature || "",
377
+ success_action_status: cred.success_action_status || cred.successActionStatus || "200"
378
378
  };
379
379
  }
380
380
  return {
@@ -397,7 +397,7 @@ function buildHeader(cred, customHeader) {
397
397
  const opts = getHttpOptions();
398
398
  const devInfo = opts.getDevice?.() || getDevice();
399
399
  const token = opts.getToken?.() || "";
400
- const appid = devInfo?.appid || "";
400
+ const appid = "appid" in devInfo ? String(devInfo.appid || "") : "";
401
401
  const headers = { ...customHeader };
402
402
  if (cred.type === "local") {
403
403
  if (appid) headers["X-Appid"] = String(appid);
package/dist/index.mjs CHANGED
@@ -24,40 +24,41 @@ try {
24
24
  }
25
25
  function getDevice() {
26
26
  if (deviceCache) return deviceCache;
27
- const deviceRaw = uni.getDeviceInfo?.() || {};
28
- const windowRaw = uni.getWindowInfo?.() || {};
29
- const appRaw = uni.getAppBaseInfo?.() || {};
30
- const system = deviceRaw.system || "";
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 || "";
31
32
  deviceCache = {
32
- appid: uni.getAccountInfoSync?.().miniProgram?.appId || "",
33
- appName: appRaw.appName || "",
34
- version: appRaw.appVersion || "",
35
- versionCode: appRaw.appVersionCode || "",
36
- channel: appRaw.appChannel || "",
37
- deviceId: deviceRaw.deviceId || "",
38
- deviceType: deviceRaw.deviceType || "",
39
- deviceOrientation: windowRaw.deviceOrientation || "portrait",
40
- brand: deviceRaw.brand || "",
41
- model: deviceRaw.model || "",
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 || "",
42
43
  system,
43
44
  os: system.split(" ")[0] || "",
44
- pixelRatio: windowRaw.pixelRatio || 0,
45
- screenWidth: windowRaw.screenWidth || 0,
46
- screenHeight: windowRaw.screenHeight || 0,
47
- windowWidth: windowRaw.windowWidth || 0,
48
- windowHeight: windowRaw.windowHeight || 0,
49
- statusBarHeight: windowRaw.statusBarHeight || 0,
50
- sdkVersion: appRaw.SDKVersion || "",
51
- hostName: appRaw.hostName || "",
52
- hostVersion: appRaw.hostVersion || "",
53
- hostLanguage: appRaw.hostLanguage || "",
54
- hostTheme: appRaw.hostTheme || "",
55
- platform: deviceRaw.platform || "",
56
- language: appRaw.appLanguage || "",
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 || "",
57
58
  networkType: currentNetworkType,
58
- benchmarkLevel: deviceRaw.benchmarkLevel || 0,
59
- theme: appRaw.theme || "light",
60
- fontSizeSetting: appRaw.fontSizeSetting || 16
59
+ benchmarkLevel: deviceRaw?.benchmarkLevel || 0,
60
+ theme: appRaw?.theme || "light",
61
+ fontSizeSetting: appRaw?.fontSizeSetting || 16
61
62
  };
62
63
  return deviceCache;
63
64
  }
@@ -311,13 +312,12 @@ function buildFormData(cred) {
311
312
  return { key: cred.key };
312
313
  }
313
314
  if (cred.type === "alioss") {
314
- const anyCred = cred;
315
315
  return {
316
316
  key: cred.key,
317
317
  policy: cred.policy,
318
- OSSAccessKeyId: cred.OSSAccessKeyId || anyCred.oSSAccessKeyId || anyCred.ossAccessKeyId || "",
319
- Signature: cred.Signature || anyCred.signature || "",
320
- success_action_status: cred.success_action_status || anyCred.successActionStatus || "200"
318
+ OSSAccessKeyId: cred.OSSAccessKeyId || cred.oSSAccessKeyId || "",
319
+ Signature: cred.Signature || cred.signature || "",
320
+ success_action_status: cred.success_action_status || cred.successActionStatus || "200"
321
321
  };
322
322
  }
323
323
  return {
@@ -340,7 +340,7 @@ function buildHeader(cred, customHeader) {
340
340
  const opts = getHttpOptions();
341
341
  const devInfo = opts.getDevice?.() || getDevice();
342
342
  const token = opts.getToken?.() || "";
343
- const appid = devInfo?.appid || "";
343
+ const appid = "appid" in devInfo ? String(devInfo.appid || "") : "";
344
344
  const headers = { ...customHeader };
345
345
  if (cred.type === "local") {
346
346
  if (appid) headers["X-Appid"] = String(appid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni-mp/request",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",