@cpzxrobot/sdk 1.2.64 → 1.2.65
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 +16 -1
- package/index.ts +16 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -111,7 +111,22 @@ class Cpzxrobot {
|
|
|
111
111
|
const instance = {
|
|
112
112
|
get: async (url, config) => {
|
|
113
113
|
if (config && config.params) {
|
|
114
|
-
|
|
114
|
+
const flattenParams = (params, prefix = '') => {
|
|
115
|
+
const result = {};
|
|
116
|
+
Object.keys(params).forEach(key => {
|
|
117
|
+
const value = params[key];
|
|
118
|
+
const fullKey = prefix ? `${prefix}[${key}]` : key;
|
|
119
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
120
|
+
Object.assign(result, flattenParams(value, fullKey));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
result[fullKey] = value.toString();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
const flattened = flattenParams(config.params);
|
|
129
|
+
url += "?" + new URLSearchParams(flattened).toString();
|
|
115
130
|
delete config.params;
|
|
116
131
|
}
|
|
117
132
|
const response = await fetchWithAuth(url, {
|
package/index.ts
CHANGED
|
@@ -129,7 +129,22 @@ export class Cpzxrobot {
|
|
|
129
129
|
const instance = {
|
|
130
130
|
get: async (url: string, config?: any) => {
|
|
131
131
|
if (config && config.params) {
|
|
132
|
-
|
|
132
|
+
const flattenParams = (params: any, prefix = '') => {
|
|
133
|
+
const result: Record<string, string> = {};
|
|
134
|
+
Object.keys(params).forEach(key => {
|
|
135
|
+
const value = params[key];
|
|
136
|
+
const fullKey = prefix ? `${prefix}[${key}]` : key;
|
|
137
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
138
|
+
Object.assign(result, flattenParams(value, fullKey));
|
|
139
|
+
} else {
|
|
140
|
+
result[fullKey] = value.toString();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return result;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const flattened = flattenParams(config.params);
|
|
147
|
+
url += "?" + new URLSearchParams(flattened).toString();
|
|
133
148
|
delete config.params;
|
|
134
149
|
}
|
|
135
150
|
const response = await fetchWithAuth(url, {
|