@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 +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +35 -35
- package/dist/index.mjs +35 -35
- package/package.json +1 -1
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
|
|
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:
|
|
90
|
-
appName: appRaw
|
|
91
|
-
version: appRaw
|
|
92
|
-
versionCode: appRaw
|
|
93
|
-
channel: appRaw
|
|
94
|
-
deviceId: deviceRaw
|
|
95
|
-
deviceType: deviceRaw
|
|
96
|
-
deviceOrientation: windowRaw
|
|
97
|
-
brand: deviceRaw
|
|
98
|
-
model: deviceRaw
|
|
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
|
|
102
|
-
screenWidth: windowRaw
|
|
103
|
-
screenHeight: windowRaw
|
|
104
|
-
windowWidth: windowRaw
|
|
105
|
-
windowHeight: windowRaw
|
|
106
|
-
statusBarHeight: windowRaw
|
|
107
|
-
sdkVersion: appRaw
|
|
108
|
-
hostName: appRaw
|
|
109
|
-
hostVersion: appRaw
|
|
110
|
-
hostLanguage: appRaw
|
|
111
|
-
hostTheme: appRaw
|
|
112
|
-
platform: deviceRaw
|
|
113
|
-
language: appRaw
|
|
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
|
|
116
|
-
theme: appRaw
|
|
117
|
-
fontSizeSetting: appRaw
|
|
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 ||
|
|
376
|
-
Signature: cred.Signature ||
|
|
377
|
-
success_action_status: cred.success_action_status ||
|
|
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
|
|
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
|
|
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:
|
|
33
|
-
appName: appRaw
|
|
34
|
-
version: appRaw
|
|
35
|
-
versionCode: appRaw
|
|
36
|
-
channel: appRaw
|
|
37
|
-
deviceId: deviceRaw
|
|
38
|
-
deviceType: deviceRaw
|
|
39
|
-
deviceOrientation: windowRaw
|
|
40
|
-
brand: deviceRaw
|
|
41
|
-
model: deviceRaw
|
|
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
|
|
45
|
-
screenWidth: windowRaw
|
|
46
|
-
screenHeight: windowRaw
|
|
47
|
-
windowWidth: windowRaw
|
|
48
|
-
windowHeight: windowRaw
|
|
49
|
-
statusBarHeight: windowRaw
|
|
50
|
-
sdkVersion: appRaw
|
|
51
|
-
hostName: appRaw
|
|
52
|
-
hostVersion: appRaw
|
|
53
|
-
hostLanguage: appRaw
|
|
54
|
-
hostTheme: appRaw
|
|
55
|
-
platform: deviceRaw
|
|
56
|
-
language: appRaw
|
|
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
|
|
59
|
-
theme: appRaw
|
|
60
|
-
fontSizeSetting: appRaw
|
|
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 ||
|
|
319
|
-
Signature: cred.Signature ||
|
|
320
|
-
success_action_status: cred.success_action_status ||
|
|
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
|
|
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