@swan-admin/swan-ai-measurements 1.0.43 → 1.0.45

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/constants.js CHANGED
@@ -28,5 +28,15 @@ export const API_ENDPOINTS = {
28
28
  TRY_ON: "/tryon",
29
29
  AUTH: "/auth",
30
30
  };
31
-
31
+ export const requiredMetaData = [
32
+ "gender",
33
+ "scan_id",
34
+ "email",
35
+ "focal_length",
36
+ "height",
37
+ "customer_store_url",
38
+ "scan_type",
39
+ "callback_url",
40
+ ];
32
41
  export const REQUIRED_MESSAGE = "Please verify required parameters";
42
+ export const REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
package/fileUpload.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
2
2
  import Uppy from "@uppy/core";
3
- import { REQUIRED_MESSAGE, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
3
+ import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
4
4
  import { checkParameters, fetchData } from "./utils.js";
5
5
 
6
6
  export default class FileUpload {
@@ -10,6 +10,9 @@ export default class FileUpload {
10
10
  if (checkParameters(file, objMetaData, scanId, accessKey) === false) {
11
11
  throw new Error(REQUIRED_MESSAGE);
12
12
  }
13
+ if (checkMetaDataValue(objMetaData) === false) {
14
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
15
+ }
13
16
  return new Promise((resolve, reject) => {
14
17
  if (this.#uppyIns) {
15
18
  this.#uppyIns.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/tryOn.js CHANGED
@@ -51,7 +51,7 @@ class TryOn {
51
51
  if (checkParameters(userId, accessKey) === false) {
52
52
  throw new Error(REQUIRED_MESSAGE);
53
53
  }
54
- return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}?userId=${userId}`, {
54
+ return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}?userId=${userId}`, null, {
55
55
  headers: { "X-Api-Key": accessKey },
56
56
  });
57
57
  }
@@ -149,7 +149,7 @@ class TryOn {
149
149
  throw new Error(REQUIRED_MESSAGE);
150
150
  }
151
151
  const url = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
152
- return axios.post(url, {
152
+ return axios.post(url, null, {
153
153
  headers: { "X-Api-Key": accessKey },
154
154
  });
155
155
  };
package/utils.js CHANGED
@@ -30,3 +30,21 @@ export const checkParameters = (...args) => {
30
30
  }
31
31
  return true;
32
32
  };
33
+
34
+ export const checkMetaDataValue = (obj) => {
35
+ for (const key of requiredMetaData) {
36
+ if (
37
+ !obj.hasOwnProperty(key) ||
38
+ obj[key] === undefined ||
39
+ obj[key] === null ||
40
+ obj[key] === "" ||
41
+ typeof obj[key] === "number"
42
+ ) {
43
+ return false;
44
+ }
45
+ }
46
+ if (!obj.callback_url.startsWith("https")) {
47
+ return false;
48
+ }
49
+ return true;
50
+ };