@hlw-uni-mp/request 1.0.0 → 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.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
@@ -58,42 +58,36 @@ 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 = uni.getDeviceInfo?.() || {};
85
- const windowRaw = uni.getWindowInfo?.() || {};
86
- const appRaw = uni.getAppBaseInfo?.() || {};
77
+ const deviceRaw = uni.getDeviceInfo();
78
+ const windowRaw = uni.getWindowInfo();
79
+ const appRaw = uni.getAppBaseInfo();
80
+ const accountRaw = uni.getAccountInfoSync();
87
81
  const system = deviceRaw.system || "";
88
82
  deviceCache = {
89
- appid: uni.getAccountInfoSync?.().miniProgram?.appId || "",
83
+ appid: accountRaw.miniProgram?.appId || "",
90
84
  appName: appRaw.appName || "",
91
85
  version: appRaw.appVersion || "",
92
86
  versionCode: appRaw.appVersionCode || "",
93
87
  channel: appRaw.appChannel || "",
94
88
  deviceId: deviceRaw.deviceId || "",
95
89
  deviceType: deviceRaw.deviceType || "",
96
- deviceOrientation: windowRaw.deviceOrientation || "portrait",
90
+ deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
97
91
  brand: deviceRaw.brand || "",
98
92
  model: deviceRaw.model || "",
99
93
  system,
@@ -110,7 +104,7 @@ function getDevice() {
110
104
  hostLanguage: appRaw.hostLanguage || "",
111
105
  hostTheme: appRaw.hostTheme || "",
112
106
  platform: deviceRaw.platform || "",
113
- language: appRaw.appLanguage || "",
107
+ language: appRaw.appLanguage || appRaw.language || "",
114
108
  networkType: currentNetworkType,
115
109
  benchmarkLevel: deviceRaw.benchmarkLevel || 0,
116
110
  theme: appRaw.theme || "light",
@@ -368,13 +362,12 @@ function buildFormData(cred) {
368
362
  return { key: cred.key };
369
363
  }
370
364
  if (cred.type === "alioss") {
371
- const anyCred = cred;
372
365
  return {
373
366
  key: cred.key,
374
367
  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"
368
+ OSSAccessKeyId: cred.OSSAccessKeyId || cred.oSSAccessKeyId || "",
369
+ Signature: cred.Signature || cred.signature || "",
370
+ success_action_status: cred.success_action_status || cred.successActionStatus || "200"
378
371
  };
379
372
  }
380
373
  return {
@@ -397,7 +390,7 @@ function buildHeader(cred, customHeader) {
397
390
  const opts = getHttpOptions();
398
391
  const devInfo = opts.getDevice?.() || getDevice();
399
392
  const token = opts.getToken?.() || "";
400
- const appid = devInfo?.appid || "";
393
+ const appid = "appid" in devInfo ? String(devInfo.appid || "") : "";
401
394
  const headers = { ...customHeader };
402
395
  if (cred.type === "local") {
403
396
  if (appid) headers["X-Appid"] = String(appid);
@@ -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,42 +1,36 @@
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 = uni.getDeviceInfo?.() || {};
28
- const windowRaw = uni.getWindowInfo?.() || {};
29
- const appRaw = uni.getAppBaseInfo?.() || {};
20
+ const deviceRaw = uni.getDeviceInfo();
21
+ const windowRaw = uni.getWindowInfo();
22
+ const appRaw = uni.getAppBaseInfo();
23
+ const accountRaw = uni.getAccountInfoSync();
30
24
  const system = deviceRaw.system || "";
31
25
  deviceCache = {
32
- appid: uni.getAccountInfoSync?.().miniProgram?.appId || "",
26
+ appid: accountRaw.miniProgram?.appId || "",
33
27
  appName: appRaw.appName || "",
34
28
  version: appRaw.appVersion || "",
35
29
  versionCode: appRaw.appVersionCode || "",
36
30
  channel: appRaw.appChannel || "",
37
31
  deviceId: deviceRaw.deviceId || "",
38
32
  deviceType: deviceRaw.deviceType || "",
39
- deviceOrientation: windowRaw.deviceOrientation || "portrait",
33
+ deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
40
34
  brand: deviceRaw.brand || "",
41
35
  model: deviceRaw.model || "",
42
36
  system,
@@ -53,7 +47,7 @@ function getDevice() {
53
47
  hostLanguage: appRaw.hostLanguage || "",
54
48
  hostTheme: appRaw.hostTheme || "",
55
49
  platform: deviceRaw.platform || "",
56
- language: appRaw.appLanguage || "",
50
+ language: appRaw.appLanguage || appRaw.language || "",
57
51
  networkType: currentNetworkType,
58
52
  benchmarkLevel: deviceRaw.benchmarkLevel || 0,
59
53
  theme: appRaw.theme || "light",
@@ -311,13 +305,12 @@ function buildFormData(cred) {
311
305
  return { key: cred.key };
312
306
  }
313
307
  if (cred.type === "alioss") {
314
- const anyCred = cred;
315
308
  return {
316
309
  key: cred.key,
317
310
  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"
311
+ OSSAccessKeyId: cred.OSSAccessKeyId || cred.oSSAccessKeyId || "",
312
+ Signature: cred.Signature || cred.signature || "",
313
+ success_action_status: cred.success_action_status || cred.successActionStatus || "200"
321
314
  };
322
315
  }
323
316
  return {
@@ -340,7 +333,7 @@ function buildHeader(cred, customHeader) {
340
333
  const opts = getHttpOptions();
341
334
  const devInfo = opts.getDevice?.() || getDevice();
342
335
  const token = opts.getToken?.() || "";
343
- const appid = devInfo?.appid || "";
336
+ const appid = "appid" in devInfo ? String(devInfo.appid || "") : "";
344
337
  const headers = { ...customHeader };
345
338
  if (cred.type === "local") {
346
339
  if (appid) headers["X-Appid"] = String(appid);
@@ -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.0",
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",