@globalbrain/sefirot 4.38.0 → 4.38.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/lib/http/Http.ts +3 -40
- package/lib/support/Http.ts +42 -0
- package/package.json +2 -2
package/lib/http/Http.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { parse as parseCookie } from '@tinyhttp/cookie'
|
|
|
3
3
|
import FileSaver from 'file-saver'
|
|
4
4
|
import { FetchError, type FetchOptions, type FetchResponse } from 'ofetch'
|
|
5
5
|
import { stringify } from 'qs'
|
|
6
|
+
import { objectToFormData } from '../support/Http'
|
|
6
7
|
|
|
7
8
|
type Config = ReturnType<typeof import('../stores/HttpConfig').useHttpConfig>
|
|
8
9
|
|
|
@@ -87,7 +88,7 @@ export class Http {
|
|
|
87
88
|
})
|
|
88
89
|
|
|
89
90
|
if (hasFile) {
|
|
90
|
-
const formData =
|
|
91
|
+
const formData = objectToFormData(body, undefined, undefined, true)
|
|
91
92
|
formData.append(this.config.payloadKey, payload)
|
|
92
93
|
body = formData
|
|
93
94
|
} else {
|
|
@@ -111,7 +112,7 @@ export class Http {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
async upload<T = any>(url: string, body?: any, options?: FetchOptions): Promise<T> {
|
|
114
|
-
return this.post<T>(url,
|
|
115
|
+
return this.post<T>(url, objectToFormData(body), options)
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
async download(url: string, options?: FetchOptions): Promise<void> {
|
|
@@ -130,44 +131,6 @@ export class Http {
|
|
|
130
131
|
|
|
131
132
|
FileSaver.saveAs(blob, filename as string)
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
private objectToFormData(
|
|
135
|
-
obj: any,
|
|
136
|
-
form?: FormData,
|
|
137
|
-
namespace?: string,
|
|
138
|
-
onlyFiles = false
|
|
139
|
-
): FormData {
|
|
140
|
-
const fd = form || new FormData()
|
|
141
|
-
let formKey: string
|
|
142
|
-
|
|
143
|
-
Object.keys(obj).forEach((property) => {
|
|
144
|
-
if (namespace) {
|
|
145
|
-
formKey = `${namespace}[${property}]`
|
|
146
|
-
} else {
|
|
147
|
-
formKey = property
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (obj[property] === undefined) {
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
typeof obj[property] === 'object'
|
|
156
|
-
&& !(obj[property] instanceof Blob)
|
|
157
|
-
&& obj[property] !== null
|
|
158
|
-
) {
|
|
159
|
-
this.objectToFormData(obj[property], fd, property, onlyFiles)
|
|
160
|
-
} else {
|
|
161
|
-
const value = obj[property] === null ? '' : obj[property]
|
|
162
|
-
if (onlyFiles && !(value instanceof Blob)) {
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
fd.append(formKey, value)
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
return fd
|
|
170
|
-
}
|
|
171
134
|
}
|
|
172
135
|
|
|
173
136
|
export function isFetchError(e: unknown): e is FetchError {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function objectToFormData(
|
|
2
|
+
obj: any,
|
|
3
|
+
form?: FormData,
|
|
4
|
+
namespace?: string,
|
|
5
|
+
onlyFiles = false
|
|
6
|
+
): FormData {
|
|
7
|
+
const fd = form || new FormData()
|
|
8
|
+
|
|
9
|
+
if (obj == null) {
|
|
10
|
+
return fd
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let formKey: string
|
|
14
|
+
|
|
15
|
+
Object.keys(obj).forEach((property) => {
|
|
16
|
+
if (namespace) {
|
|
17
|
+
formKey = `${namespace}[${property}]`
|
|
18
|
+
} else {
|
|
19
|
+
formKey = property
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (obj[property] === undefined) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
typeof obj[property] === 'object'
|
|
28
|
+
&& !(obj[property] instanceof Blob)
|
|
29
|
+
&& obj[property] !== null
|
|
30
|
+
) {
|
|
31
|
+
objectToFormData(obj[property], fd, formKey, onlyFiles)
|
|
32
|
+
} else {
|
|
33
|
+
const value = obj[property] === null ? '' : obj[property]
|
|
34
|
+
if (onlyFiles && !(value instanceof Blob)) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
fd.append(formKey, value)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return fd
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalbrain/sefirot",
|
|
3
|
-
"version": "4.38.
|
|
3
|
+
"version": "4.38.1",
|
|
4
4
|
"description": "Vue Components for Global Brain Design System.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"coverage": "vitest run --coverage",
|
|
54
54
|
"test": "pnpm run type && pnpm run lint && pnpm run coverage",
|
|
55
55
|
"test:fail": "pnpm run type && pnpm run lint:fail && pnpm run coverage",
|
|
56
|
-
"release": "release-it"
|
|
56
|
+
"release": "pnpm whoami >/dev/null 2>&1 || pnpm login && release-it"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@iconify-json/ph": "^1.2.2",
|