@ikas/storefront-api 4.0.0-alpha.37 → 4.0.0-alpha.39
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/package.json +5 -5
- package/src/api/file-upload/index.ts +35 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront-api",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.39",
|
|
4
4
|
"author": "Umut Ozan Yıldırım",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "API functions that returns models from the ikas-storefront-models package.",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
24
|
-
"@ikas/storefront-config": "^4.0.0-alpha.
|
|
25
|
-
"@ikas/storefront-models": "^4.0.0-alpha.
|
|
24
|
+
"@ikas/storefront-config": "^4.0.0-alpha.39",
|
|
25
|
+
"@ikas/storefront-models": "^4.0.0-alpha.39",
|
|
26
26
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
27
27
|
"prettier": "^2.2.1",
|
|
28
28
|
"rollup": "^2.75.6",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"axios": "^0.26.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@ikas/storefront-config": "^4.0.0-alpha.
|
|
39
|
-
"@ikas/storefront-models": "^4.0.0-alpha.
|
|
38
|
+
"@ikas/storefront-config": "^4.0.0-alpha.39",
|
|
39
|
+
"@ikas/storefront-models": "^4.0.0-alpha.39",
|
|
40
40
|
"axios": "^0.26.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,38 +1,44 @@
|
|
|
1
1
|
import { IkasProductOption } from "@ikas/storefront-models";
|
|
2
|
-
import {
|
|
2
|
+
import { QueryParams as GetProductOptionFileUrlQueryParams } from "../../__api/queries/getProductOptionFileUrl";
|
|
3
|
+
import { IkasProductOptionFileUrl } from "@ikas/storefront-models";
|
|
4
|
+
import { APIResponse } from "@ikas/fe-api-client";
|
|
5
|
+
import axios from "axios";
|
|
3
6
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
export type { GetProductOptionFileUrlQueryParams };
|
|
8
|
+
|
|
9
|
+
export async function getProductOptionFileUrl(
|
|
10
|
+
params: GetProductOptionFileUrlQueryParams,
|
|
11
|
+
file: File
|
|
7
12
|
) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
const _getProductOptionFileUrl = (
|
|
14
|
+
await import("../../__api/queries/getProductOptionFileUrl")
|
|
15
|
+
).default;
|
|
16
|
+
const response = await _getProductOptionFileUrl(params);
|
|
17
|
+
return new APIResponse(
|
|
18
|
+
response.data
|
|
19
|
+
? {
|
|
20
|
+
...(response.data as unknown as IkasProductOptionFileUrl),
|
|
21
|
+
file: file,
|
|
22
|
+
}
|
|
23
|
+
: null,
|
|
24
|
+
response.graphQLErrors
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function uploadFile(params: IkasProductOptionFileUrl, file: File) {
|
|
29
|
+
const config = {
|
|
11
30
|
headers: {
|
|
12
|
-
"
|
|
13
|
-
"x-sfid": IkasStorefrontConfig.getStorefrontId() || "",
|
|
14
|
-
"x-sfrid": IkasStorefrontConfig.getStorefrontRoutingId() || "",
|
|
15
|
-
"Content-Type": "application/json",
|
|
16
|
-
Accept: "application/json",
|
|
31
|
+
"Content-Type": "multipart/form-data",
|
|
17
32
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}),
|
|
33
|
+
};
|
|
34
|
+
const data = new FormData();
|
|
35
|
+
Object.entries(params.fields).forEach(([key, value]) => {
|
|
36
|
+
//@ts-ignore
|
|
37
|
+
data.append(key, value);
|
|
24
38
|
});
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return await response.text();
|
|
30
|
-
}
|
|
40
|
+
data.append("file", file);
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
const reader = new FileReader();
|
|
35
|
-
reader.addEventListener("load", () => resolve(reader.result as string));
|
|
36
|
-
reader.readAsDataURL(file);
|
|
37
|
-
});
|
|
42
|
+
const res = await axios.post(params.url, data, config);
|
|
43
|
+
return res.status === 200 || res.status === 204;
|
|
38
44
|
}
|