@swan-admin/swan-ai-measurements 1.0.32 → 1.0.34

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
@@ -21,11 +21,12 @@ export const API_ENDPOINTS = {
21
21
  ADD_USER: "/user",
22
22
  CUSTOM_CUSTOMER: "/customers/custom",
23
23
  MODEL: "/model",
24
- TRY_ON: "/tryon/scan",
24
+ TRY_ON_SCAN: "/tryon/scan",
25
25
  TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
26
26
  TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
27
27
  TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
28
28
  TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
29
+ TRY_ON: "/tryon",
29
30
  };
30
31
 
31
32
  export const REQUIRED_MESSAGE = "Please verify required parameters";
package/index.js CHANGED
@@ -25,4 +25,3 @@ export default class Swan {
25
25
 
26
26
  tryOn = new TryOn(Swan.accessKey);
27
27
  }
28
- const a = new Swan(9876543210);
package/measurement.js CHANGED
@@ -33,7 +33,7 @@ export default class Measurement {
33
33
  if (checkParameters(scanId, shopDomain, productName) === false) {
34
34
  throw new Error(REQUIRED_MESSAGE);
35
35
  }
36
- const tryOnUrl = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON}/${scanId}/shop/${shopDomain}/product/${productName}`;
36
+ const tryOnUrl = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_SCAN}/${scanId}/shop/${shopDomain}/product/${productName}`;
37
37
  return axios.get(tryOnUrl);
38
38
  }
39
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/tryOn.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from "axios";
2
- import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants";
3
- import { checkParameters } from "./utils";
2
+ import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
3
+ import { checkParameters } from "./utils.js";
4
4
 
5
5
  class TryOn {
6
6
  static accessKey;
@@ -62,7 +62,7 @@ class TryOn {
62
62
 
63
63
  static handleTimeOut = ({ onSuccess, onError, shopDomain, userId, productName }) => {
64
64
  TryOn.timerWaitingRef = setTimeout(() => {
65
- this.getTryOnResult({ shopDomain, userId, productName });
65
+ TryOn.handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError });
66
66
  TryOn.disconnectSocket();
67
67
  }, 78000);
68
68
  };
@@ -85,14 +85,14 @@ class TryOn {
85
85
  TryOn.tryOnSocketRef.onmessage = (event) => {
86
86
  const data = JSON.parse(event.data);
87
87
  if (data?.status === "success") {
88
- this.getTryOnResult({ shopDomain, userId, productName });
88
+ TryOn.handleGetTryOnResult({ shopDomain, userId, productName, onError, onSuccess });
89
89
  } else {
90
90
  onError?.(data);
91
91
  }
92
92
  clearTimeout(TryOn.tryOnSocketRef);
93
93
  };
94
94
  TryOn.tryOnSocketRef.onclose = () => {
95
- onclose?.();
95
+ onClose?.();
96
96
  };
97
97
  TryOn.tryOnSocketRef.onerror = (event) => {
98
98
  onError?.(event);
@@ -106,7 +106,7 @@ class TryOn {
106
106
  }
107
107
  return new Promise(async (resolve, reject) => {
108
108
  try {
109
- const url = `${APP_AUTH_BASE_URL}/tryon/?scan_id=${id}&store_url=${shopDomain}&product_name=${productName}`;
109
+ const url = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON}/?scan_id=${id}&store_url=${shopDomain}&product_name=${productName}`;
110
110
  const res = await axios.post(url);
111
111
  if (res?.data?.tryOnProcessStatus === "failed") {
112
112
  TryOn.disconnectSocket();
@@ -122,7 +122,7 @@ class TryOn {
122
122
  });
123
123
  };
124
124
 
125
- handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userId, productName }) => {
125
+ static handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userId, productName }) => {
126
126
  try {
127
127
  const data = await this.getTryOnResult({ shopDomain, userId, productName });
128
128
  onSuccess?.(data?.data);