@ikas/storefront-api 4.0.0-alpha.36 → 4.0.0-alpha.38

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront-api",
3
- "version": "4.0.0-alpha.36",
3
+ "version": "4.0.0-alpha.38",
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.36",
25
- "@ikas/storefront-models": "^4.0.0-alpha.36",
24
+ "@ikas/storefront-config": "^4.0.0-alpha.38",
25
+ "@ikas/storefront-models": "^4.0.0-alpha.38",
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.36",
39
- "@ikas/storefront-models": "^4.0.0-alpha.36",
38
+ "@ikas/storefront-config": "^4.0.0-alpha.38",
39
+ "@ikas/storefront-models": "^4.0.0-alpha.38",
40
40
  "axios": "^0.26.0"
41
41
  }
42
42
  }
@@ -1,38 +1,44 @@
1
1
  import { IkasProductOption } from "@ikas/storefront-models";
2
- import { IkasStorefrontConfig } from "@ikas/storefront-config";
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 async function uploadProductOptionFile(
5
- file: File,
6
- option: IkasProductOption
7
+ export type { GetProductOptionFileUrlQueryParams };
8
+
9
+ export async function getProductOptionFileUrl(
10
+ params: GetProductOptionFileUrlQueryParams,
11
+ file: File
7
12
  ) {
8
- const URL = `${IkasStorefrontConfig.getAdminApiUrl()}/upload-product-option-file`;
9
- const response = await fetch(URL, {
10
- method: "POST",
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
- "x-api-key": IkasStorefrontConfig.getApiKey() || "",
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
- body: JSON.stringify({
19
- base64: await getBase64(file),
20
- fileName: file.name,
21
- productOptionSetId: option.productOptionSetId,
22
- productOptionId: option.id,
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
- if (!response.ok) {
27
- return null;
28
- }
29
- return await response.text();
30
- }
40
+ data.append("file", file);
31
41
 
32
- export function getBase64(file: File): Promise<string | null> {
33
- return new Promise((resolve) => {
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
  }