@swan-admin/swan-ai-measurements 1.0.29 → 1.0.30

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/auth.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import axios from "axios";
2
- import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL } from "./constants.js";
2
+ import {
3
+ API_ENDPOINTS,
4
+ APP_AUTH_BASE_URL,
5
+ APP_AUTH_WEBSOCKET_URL,
6
+ APP_BASE_URL,
7
+ REQUIRED_MESSAGE,
8
+ } from "./constants.js";
9
+ import { checkParameters } from "./utils.js";
3
10
  let socketRef;
4
11
 
5
12
  class Auth {
@@ -8,6 +15,9 @@ class Auth {
8
15
  Auth.accessKey = key;
9
16
  }
10
17
  registerUser({ email, appVerifyUrl, gender, height, username }) {
18
+ if (checkParameters(email, appVerifyUrl) === false) {
19
+ throw new Error(REQUIRED_MESSAGE);
20
+ }
11
21
  let body = {
12
22
  username,
13
23
  email,
@@ -19,23 +29,39 @@ class Auth {
19
29
  return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.REGISTER_USER}`, body);
20
30
  }
21
31
 
22
- verifyToken = (token) =>
23
- axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.VERIFY_USER}`, null, {
32
+ verifyToken = (token) => {
33
+ if (!token) {
34
+ throw new Error(REQUIRED_MESSAGE);
35
+ }
36
+ return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.VERIFY_USER}`, null, {
24
37
  params: { token },
25
38
  });
39
+ };
26
40
 
27
- addUser = ({ scanId, email, name, height, gender, offsetMarketingConsent }) =>
28
- axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.ADD_USER}`, {
41
+ addUser = ({ scanId, email, name, height, gender, offsetMarketingConsent }) => {
42
+ if (checkParameters(scanId, email, height, gender) === false) {
43
+ throw new Error(REQUIRED_MESSAGE);
44
+ }
45
+ return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.ADD_USER}`, {
29
46
  scan_id: scanId,
30
47
  email,
31
48
  name,
32
49
  offsetMarketingConsent,
33
50
  attributes: JSON.stringify({ height, gender }),
34
51
  });
52
+ };
35
53
 
36
- getUserDetail = (email) => axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`);
54
+ getUserDetail = (email) => {
55
+ if (!email) {
56
+ throw new Error(REQUIRED_MESSAGE);
57
+ }
58
+ return axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`);
59
+ };
37
60
 
38
61
  handleAuthSocket = ({ email, scanId, onError, onSuccess, onClose, onOpen }) => {
62
+ if (checkParameters(email, scanId) === false) {
63
+ throw new Error(REQUIRED_MESSAGE);
64
+ }
39
65
  socketRef?.close?.();
40
66
 
41
67
  socketRef = new WebSocket(APP_AUTH_WEBSOCKET_URL);
@@ -45,8 +71,8 @@ class Auth {
45
71
  };
46
72
 
47
73
  socketRef.onopen = () => {
48
- onOpen?.();
49
74
  socketRef.send(JSON.stringify(detailObj));
75
+ onOpen?.();
50
76
  };
51
77
 
52
78
  socketRef.onmessage = (event) => {
package/constants.js CHANGED
@@ -23,3 +23,5 @@ export const API_ENDPOINTS = {
23
23
  MODEL: "/model",
24
24
  TRY_ON: "/tryon/scan",
25
25
  };
26
+
27
+ export const REQUIRED_MESSAGE = "Please verify required parameters";
package/custom.js CHANGED
@@ -1,13 +1,22 @@
1
1
  import axios from "axios";
2
- import { API_ENDPOINTS, APP_AUTH_BASE_URL } from "./constants.js";
2
+ import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
3
3
 
4
4
  export default class Custom {
5
5
  static accessKey;
6
6
  constructor(key) {
7
7
  Custom.accessKey = key;
8
8
  }
9
- getCustomCustomerConfig = (store_url) =>
10
- axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.CUSTOM_CUSTOMER}`, { params: { store_url } });
9
+ getCustomCustomerConfig = (store_url) => {
10
+ if (!store_url) {
11
+ throw new Error(REQUIRED_MESSAGE);
12
+ }
13
+ return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.CUSTOM_CUSTOMER}`, { params: { store_url } });
14
+ };
11
15
 
12
- getModelUrl = (id) => axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.MODEL}/${id}`);
16
+ getModelUrl = (id) => {
17
+ if (!id) {
18
+ throw new Error(REQUIRED_MESSAGE);
19
+ }
20
+ return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.MODEL}/${id}`);
21
+ };
13
22
  }
package/fileUpload.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
2
2
  import Uppy from "@uppy/core";
3
- import { FILE_UPLOAD_KEY, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
4
- import { fetchData } from "./utils.js";
3
+ import { FILE_UPLOAD_KEY, REQUIRED_MESSAGE, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
4
+ import { checkParameters, fetchData } from "./utils.js";
5
5
 
6
6
  export default class FileUpload {
7
7
  static accessKey;
@@ -9,6 +9,9 @@ export default class FileUpload {
9
9
  FileUpload.accessKey = key;
10
10
  }
11
11
  uploadFile({ file, objMetaData, scanId }) {
12
+ if (checkParameters(file, objMetaData, scanId) === false) {
13
+ throw new Error(REQUIRED_MESSAGE);
14
+ }
12
15
  return new Promise((resolve, reject) => {
13
16
  const uppyIns = new Uppy({ autoProceed: true });
14
17
  uppyIns.use(AwsS3Multipart, {
package/measurement.js CHANGED
@@ -5,7 +5,9 @@ import {
5
5
  APP_RECOMMENDATION_WEBSOCKET_URL,
6
6
  APP_TRY_ON_WEBSOCKET_URL,
7
7
  FILE_UPLOAD_KEY,
8
+ REQUIRED_MESSAGE,
8
9
  } from "./constants.js";
10
+ import { checkParameters } from "./utils.js";
9
11
 
10
12
  export default class Measurement {
11
13
  static accessKey;
@@ -18,6 +20,9 @@ export default class Measurement {
18
20
  static timerWaitingRef = null;
19
21
 
20
22
  getMeasurementStatus(scanId) {
23
+ if (!scanId) {
24
+ throw new Error(REQUIRED_MESSAGE);
25
+ }
21
26
  const url = `${APP_AUTH_BASE_URL}/measurements?scanId=${scanId}`;
22
27
  return axios.get(url, {
23
28
  headers: { "X-Api-Key": FILE_UPLOAD_KEY },
@@ -25,11 +30,17 @@ export default class Measurement {
25
30
  }
26
31
 
27
32
  getTryOnMeasurements({ scanId, shopDomain, productName }) {
33
+ if (checkParameters(scanId, shopDomain, productName) === false) {
34
+ throw new Error(REQUIRED_MESSAGE);
35
+ }
28
36
  const tryOnUrl = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON}/${scanId}/shop/${shopDomain}/product/${productName}`;
29
37
  return axios.get(tryOnUrl);
30
38
  }
31
39
 
32
40
  handleTryOnSocket({ shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen }) {
41
+ if (checkParameters(shopDomain, scanId, productName) === false) {
42
+ throw new Error(REQUIRED_MESSAGE);
43
+ }
33
44
  Measurement.tryOnSocketRef?.close();
34
45
 
35
46
  const url = `${APP_TRY_ON_WEBSOCKET_URL}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
@@ -90,6 +101,9 @@ export default class Measurement {
90
101
  };
91
102
 
92
103
  handleMeasurementSocket = ({ scanId, onError, onSuccess, onClose, onOpen }) => {
104
+ if (!scanId) {
105
+ throw new Error(REQUIRED_MESSAGE);
106
+ }
93
107
  Measurement.disconnectSocket();
94
108
  const url = `${APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
95
109
  Measurement.measurementSocketRef = new WebSocket(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/poseDetection.js CHANGED
@@ -36,7 +36,7 @@ export default class PoseDetection {
36
36
  throw new Error("socket is not connected");
37
37
  }
38
38
  PoseDetection.socket.on("pose_status", (data) => {
39
- callBack(data);
39
+ callBack?.(data);
40
40
  });
41
41
  }
42
42
 
package/utils.js CHANGED
@@ -21,3 +21,12 @@ export async function fetchData({
21
21
  return {};
22
22
  }
23
23
  }
24
+
25
+ export const checkParameters = (...args) => {
26
+ for (const element of args) {
27
+ if (!element) {
28
+ return false;
29
+ }
30
+ }
31
+ return true;
32
+ };