@swan-admin/swan-ai-measurements 1.1.21 → 1.1.24

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/dist/constants.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredMetaData = exports.API_ENDPOINTS = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_BASE_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.FILE_UPLOAD_ENDPOINT = exports.PROD_URL = exports.STAGING_URL = void 0;
4
4
  exports.STAGING_URL = {
5
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
6
- APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
5
+ APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
6
+ APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
7
7
  APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
8
8
  };
9
9
  exports.PROD_URL = {
@@ -1,6 +1,6 @@
1
1
  export const STAGING_URL = {
2
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
3
- APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
2
+ APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
3
+ APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
4
4
  APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
5
5
  };
6
6
  export const PROD_URL = {
@@ -20,8 +20,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
20
20
  };
21
21
  var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
22
22
  import axios from "axios";
23
- import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL } from "./constants.js";
24
- import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
23
+ import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, } from "./constants.js";
24
+ import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
25
25
  import Uppy from "@uppy/core";
26
26
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
27
27
  class FileUpload {
@@ -34,15 +34,16 @@ class FileUpload {
34
34
  }
35
35
  uploadFileFrontend(_a) {
36
36
  return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
37
- if (!checkParameters(file, arrayMetaData, scanId)) {
37
+ email = email.trim();
38
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
38
39
  throw new Error(REQUIRED_MESSAGE);
39
40
  }
41
+ if (!isValidEmail(email)) {
42
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
43
+ }
40
44
  if (!checkMetaDataValue(arrayMetaData)) {
41
45
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
42
46
  }
43
- if (!email.trim()) {
44
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
45
- }
46
47
  arrayMetaData = addScanType(arrayMetaData, scanId, email);
47
48
  return new Promise((resolve, reject) => {
48
49
  if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
@@ -111,15 +112,16 @@ class FileUpload {
111
112
  }
112
113
  uploadFile(_a) {
113
114
  return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
114
- if (!checkParameters(file, arrayMetaData, scanId)) {
115
+ email = email.trim();
116
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
115
117
  throw new Error(REQUIRED_MESSAGE);
116
118
  }
119
+ if (!isValidEmail(email)) {
120
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
121
+ }
117
122
  if (!checkMetaDataValue(arrayMetaData)) {
118
123
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
119
124
  }
120
- if (!email.trim()) {
121
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
122
- }
123
125
  arrayMetaData = addScanType(arrayMetaData, scanId, email);
124
126
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
125
127
  var _b;
@@ -37,7 +37,7 @@ declare class TryOn {
37
37
  getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
38
38
  deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
39
39
  handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
40
- handleSumbmitTryOn: ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }: HandleForLatestImageParams) => Promise<any>;
40
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
41
41
  getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
42
42
  }
43
43
  export default TryOn;
package/dist/esm/tryOn.js CHANGED
@@ -75,44 +75,7 @@ class TryOn {
75
75
  }
76
76
  };
77
77
  };
78
- this.handleSumbmitTryOn = (_a) => __awaiter(this, [_a], void 0, function* ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }) {
79
- var _b;
80
- userEmail = userEmail.trim();
81
- if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
82
- throw new Error(REQUIRED_MESSAGE);
83
- }
84
- if (!isValidEmail(userEmail)) {
85
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
86
- }
87
- try {
88
- const payload = {
89
- productName,
90
- userEmail,
91
- customerStoreUrl: shopDomain,
92
- selectedUserImages: [
93
- firstImageName,
94
- secondImageName
95
- ]
96
- };
97
- const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
98
- const res = yield axios.post(url, payload, {
99
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
100
- });
101
- if (((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.tryOnProcessStatus) === "failed") {
102
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
103
- throw res.data;
104
- }
105
- else {
106
- return res.data;
107
- }
108
- }
109
- catch (error) {
110
- onError === null || onError === void 0 ? void 0 : onError(error);
111
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
112
- throw error;
113
- }
114
- });
115
- _TryOn_handleGetTryOnResult.set(this, (_c) => __awaiter(this, [_c], void 0, function* ({ onSuccess, onError, shopDomain, userEmail, productName }) {
78
+ _TryOn_handleGetTryOnResult.set(this, (_a) => __awaiter(this, [_a], void 0, function* ({ onSuccess, onError, shopDomain, userEmail, productName }) {
116
79
  try {
117
80
  const data = yield this.getTryOnResult({ shopDomain, userEmail, productName });
118
81
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data.data);
@@ -164,10 +127,11 @@ class TryOn {
164
127
  payload.userImages.push(files[1].name);
165
128
  }
166
129
  const signedUrlRes = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_getSignedUrl).call(this, payload);
130
+ let s3UploadResult;
167
131
  for (const file of files) {
168
- yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
132
+ s3UploadResult = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
169
133
  }
170
- return "uploaded successfully!";
134
+ return `uploaded successfully! and ${s3UploadResult}`;
171
135
  }
172
136
  catch (error) {
173
137
  throw error;
@@ -183,7 +147,7 @@ class TryOn {
183
147
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
184
148
  }
185
149
  const payload = {
186
- userEmail
150
+ userEmail,
187
151
  };
188
152
  return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}`, payload, {
189
153
  headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
@@ -199,11 +163,30 @@ class TryOn {
199
163
  }
200
164
  const payload = {
201
165
  userEmail,
202
- file: fileName
166
+ file: fileName,
203
167
  };
204
168
  return axios.delete(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_IMAGE_URLS}`, {
205
169
  headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
206
- data: payload
170
+ data: payload,
171
+ });
172
+ }
173
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }) {
174
+ userEmail = userEmail.trim();
175
+ if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
176
+ throw new Error(REQUIRED_MESSAGE);
177
+ }
178
+ if (!isValidEmail(userEmail)) {
179
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
180
+ }
181
+ const payload = {
182
+ productName,
183
+ userEmail,
184
+ customerStoreUrl: shopDomain,
185
+ selectedUserImages: [firstImageName, secondImageName],
186
+ };
187
+ const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
188
+ return axios.post(url, payload, {
189
+ headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
207
190
  });
208
191
  }
209
192
  }
@@ -221,6 +204,7 @@ _TryOn_tryOnSocketRef = new WeakMap(), _TryOn_timerWaitingRef = new WeakMap(), _
221
204
  if (checkParameters(url, file) === false) {
222
205
  throw new Error(REQUIRED_MESSAGE);
223
206
  }
207
+ console.log("s3 being called========", url, file);
224
208
  return axios.put(url, file, {
225
209
  headers: {
226
210
  "Content-Type": file.type,
@@ -17,15 +17,16 @@ class FileUpload {
17
17
  this.#stagingUrl = stagingUrl;
18
18
  }
19
19
  async uploadFileFrontend({ file, arrayMetaData, scanId, email }) {
20
- if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
20
+ email = email.trim();
21
+ if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
21
22
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
22
23
  }
24
+ if (!(0, utils_js_1.isValidEmail)(email)) {
25
+ throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
26
+ }
23
27
  if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
24
28
  throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
25
29
  }
26
- if (!email.trim()) {
27
- throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
28
- }
29
30
  arrayMetaData = (0, utils_js_1.addScanType)(arrayMetaData, scanId, email);
30
31
  return new Promise((resolve, reject) => {
31
32
  if (this.#uppyIns) {
@@ -92,15 +93,16 @@ class FileUpload {
92
93
  });
93
94
  }
94
95
  async uploadFile({ file, arrayMetaData, scanId, email }) {
95
- if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
96
+ email = email.trim();
97
+ if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
96
98
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
97
99
  }
100
+ if (!(0, utils_js_1.isValidEmail)(email)) {
101
+ throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
102
+ }
98
103
  if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
99
104
  throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
100
105
  }
101
- if (!email.trim()) {
102
- throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
103
- }
104
106
  arrayMetaData = (0, utils_js_1.addScanType)(arrayMetaData, scanId, email);
105
107
  return new Promise(async (resolve, reject) => {
106
108
  try {
package/dist/tryOn.d.ts CHANGED
@@ -37,7 +37,7 @@ declare class TryOn {
37
37
  getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
38
38
  deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
39
39
  handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
40
- handleSumbmitTryOn: ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }: HandleForLatestImageParams) => Promise<any>;
40
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
41
41
  getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
42
42
  }
43
43
  export default TryOn;
package/dist/tryOn.js CHANGED
@@ -35,10 +35,11 @@ class TryOn {
35
35
  payload.userImages.push(files[1].name);
36
36
  }
37
37
  const signedUrlRes = await this.#getSignedUrl(payload);
38
+ let s3UploadResult;
38
39
  for (const file of files) {
39
- await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
40
+ s3UploadResult = await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
40
41
  }
41
- return "uploaded successfully!";
42
+ return `uploaded successfully! and ${s3UploadResult}`;
42
43
  }
43
44
  catch (error) {
44
45
  throw error;
@@ -59,6 +60,7 @@ class TryOn {
59
60
  if ((0, utils_js_1.checkParameters)(url, file) === false) {
60
61
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
61
62
  }
63
+ console.log("s3 being called========", url, file);
62
64
  return axios_1.default.put(url, file, {
63
65
  headers: {
64
66
  "Content-Type": file.type,
@@ -74,7 +76,7 @@ class TryOn {
74
76
  throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
75
77
  }
76
78
  const payload = {
77
- userEmail
79
+ userEmail,
78
80
  };
79
81
  return axios_1.default.post(`${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}`, payload, {
80
82
  headers: { "X-Api-Key": this.#accessKey },
@@ -90,11 +92,11 @@ class TryOn {
90
92
  }
91
93
  const payload = {
92
94
  userEmail,
93
- file: fileName
95
+ file: fileName,
94
96
  };
95
97
  return axios_1.default.delete(`${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_URLS}`, {
96
98
  headers: { "X-Api-Key": this.#accessKey },
97
- data: payload
99
+ data: payload,
98
100
  });
99
101
  }
100
102
  #disconnectSocket = () => {
@@ -142,7 +144,7 @@ class TryOn {
142
144
  }
143
145
  };
144
146
  };
145
- handleSumbmitTryOn = async ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }) => {
147
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }) {
146
148
  userEmail = userEmail.trim();
147
149
  if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
148
150
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
@@ -150,34 +152,17 @@ class TryOn {
150
152
  if (!(0, utils_js_1.isValidEmail)(userEmail)) {
151
153
  throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
152
154
  }
153
- try {
154
- const payload = {
155
- productName,
156
- userEmail,
157
- customerStoreUrl: shopDomain,
158
- selectedUserImages: [
159
- firstImageName,
160
- secondImageName
161
- ]
162
- };
163
- const url = `${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON}`;
164
- const res = await axios_1.default.post(url, payload, {
165
- headers: { "X-Api-Key": this.#accessKey },
166
- });
167
- if (res?.data?.tryOnProcessStatus === "failed") {
168
- this.#disconnectSocket();
169
- throw res.data;
170
- }
171
- else {
172
- return res.data;
173
- }
174
- }
175
- catch (error) {
176
- onError?.(error);
177
- this.#disconnectSocket();
178
- throw error;
179
- }
180
- };
155
+ const payload = {
156
+ productName,
157
+ userEmail,
158
+ customerStoreUrl: shopDomain,
159
+ selectedUserImages: [firstImageName, secondImageName],
160
+ };
161
+ const url = `${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON}`;
162
+ return axios_1.default.post(url, payload, {
163
+ headers: { "X-Api-Key": this.#accessKey },
164
+ });
165
+ }
181
166
  #handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userEmail, productName }) => {
182
167
  try {
183
168
  const data = await this.getTryOnResult({ shopDomain, userEmail, productName });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.1.21",
3
+ "version": "1.1.24",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/constants.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export const STAGING_URL: Record<string, string> = {
2
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
3
- APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
2
+ APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
3
+ APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
4
4
  APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
5
5
  };
6
6
 
package/src/fileUpload.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import axios from "axios";
2
- import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL } from "./constants.js";
3
- import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
2
+ import {
3
+ REQUIRED_MESSAGE,
4
+ REQUIRED_MESSAGE_FOR_META_DATA,
5
+ FILE_UPLOAD_ENDPOINT,
6
+ APP_AUTH_BASE_URL,
7
+ REQUIRED_ERROR_MESSAGE_INVALID_EMAIL,
8
+ } from "./constants.js";
9
+ import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
4
10
  const Uppy = require("fix-esm").require("@uppy/core");
5
11
  const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
6
12
  interface ObjMetaData {
@@ -33,15 +39,16 @@ export default class FileUpload {
33
39
  }
34
40
 
35
41
  async uploadFileFrontend({ file, arrayMetaData, scanId, email }: UploadOptions) {
36
- if (!checkParameters(file, arrayMetaData, scanId)) {
42
+ email = email.trim();
43
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
37
44
  throw new Error(REQUIRED_MESSAGE);
38
45
  }
46
+ if (!isValidEmail(email)) {
47
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
48
+ }
39
49
  if (!checkMetaDataValue(arrayMetaData)) {
40
50
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
41
51
  }
42
- if(!email.trim()){
43
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
44
- }
45
52
  arrayMetaData = addScanType(arrayMetaData, scanId, email);
46
53
  return new Promise((resolve, reject) => {
47
54
  if (this.#uppyIns) {
@@ -114,15 +121,16 @@ export default class FileUpload {
114
121
  }
115
122
 
116
123
  async uploadFile({ file, arrayMetaData, scanId, email }: UploadOptions) {
117
- if (!checkParameters(file, arrayMetaData, scanId)) {
124
+ email = email.trim();
125
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
118
126
  throw new Error(REQUIRED_MESSAGE);
119
127
  }
128
+ if (!isValidEmail(email)) {
129
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
130
+ }
120
131
  if (!checkMetaDataValue(arrayMetaData)) {
121
132
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
122
133
  }
123
- if(!email.trim()){
124
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
125
- }
126
134
  arrayMetaData = addScanType(arrayMetaData, scanId, email);
127
135
  return new Promise(async (resolve, reject) => {
128
136
  try {
package/src/tryOn.ts CHANGED
@@ -13,7 +13,7 @@ interface DeleteImageParams {
13
13
  }
14
14
 
15
15
  interface HandleTryOnWebSocketParams {
16
- userEmail : string;
16
+ userEmail: string;
17
17
  shopDomain: string;
18
18
  tryonId: string;
19
19
  productName: string;
@@ -27,8 +27,8 @@ interface HandleForLatestImageParams {
27
27
  shopDomain: string;
28
28
  userEmail: string;
29
29
  productName: string;
30
- firstImageName:string;
31
- secondImageName:string;
30
+ firstImageName: string;
31
+ secondImageName: string;
32
32
  onError?: (error: any) => void;
33
33
  }
34
34
 
@@ -62,7 +62,7 @@ class TryOn {
62
62
  throw new Error(REQUIRED_MESSAGE);
63
63
  }
64
64
 
65
- if(!isValidEmail(userEmail)){
65
+ if (!isValidEmail(userEmail)) {
66
66
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
67
67
  }
68
68
 
@@ -78,10 +78,11 @@ class TryOn {
78
78
  payload.userImages.push(files[1].name);
79
79
  }
80
80
  const signedUrlRes = await this.#getSignedUrl(payload);
81
+ let s3UploadResult;
81
82
  for (const file of files) {
82
- await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
83
+ s3UploadResult = await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
83
84
  }
84
- return "uploaded successfully!";
85
+ return `uploaded successfully! and ${s3UploadResult}`;
85
86
  } catch (error) {
86
87
  throw error;
87
88
  }
@@ -103,6 +104,7 @@ class TryOn {
103
104
  if (checkParameters(url, file) === false) {
104
105
  throw new Error(REQUIRED_MESSAGE);
105
106
  }
107
+ console.log("s3 being called========",url,file)
106
108
  return axios.put(url, file, {
107
109
  headers: {
108
110
  "Content-Type": file.type,
@@ -115,21 +117,17 @@ class TryOn {
115
117
  if (checkParameters(userEmail) === false) {
116
118
  throw new Error(REQUIRED_MESSAGE);
117
119
  }
118
- if(!isValidEmail(userEmail)){
120
+ if (!isValidEmail(userEmail)) {
119
121
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
120
122
  }
121
123
 
122
124
  const payload = {
123
- userEmail
125
+ userEmail,
124
126
  };
125
-
126
- return axios.post(
127
- `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}`,
128
- payload,
129
- {
130
- headers: { "X-Api-Key": this.#accessKey },
131
- }
132
- );
127
+
128
+ return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}`, payload, {
129
+ headers: { "X-Api-Key": this.#accessKey },
130
+ });
133
131
  }
134
132
 
135
133
  deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>> {
@@ -137,20 +135,17 @@ class TryOn {
137
135
  if (checkParameters(userEmail, fileName) === false) {
138
136
  throw new Error(REQUIRED_MESSAGE);
139
137
  }
140
- if(!isValidEmail(userEmail)){
138
+ if (!isValidEmail(userEmail)) {
141
139
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
142
140
  }
143
- const payload={
141
+ const payload = {
144
142
  userEmail,
145
- file : fileName
146
- }
147
- return axios.delete(
148
- `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_IMAGE_URLS}`,
149
- {
150
- headers: { "X-Api-Key": this.#accessKey },
151
- data: payload
152
- }
153
- );
143
+ file: fileName,
144
+ };
145
+ return axios.delete(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_IMAGE_URLS}`, {
146
+ headers: { "X-Api-Key": this.#accessKey },
147
+ data: payload,
148
+ });
154
149
  }
155
150
 
156
151
  #disconnectSocket = (): void => {
@@ -200,45 +195,33 @@ class TryOn {
200
195
  };
201
196
  };
202
197
 
203
- handleSumbmitTryOn = async ({ userEmail, shopDomain, productName, firstImageName,secondImageName, onError }: HandleForLatestImageParams): Promise<any> => {
198
+ handleTryOnSubmit({
199
+ userEmail,
200
+ shopDomain,
201
+ productName,
202
+ firstImageName,
203
+ secondImageName,
204
+ }: HandleForLatestImageParams): Promise<AxiosResponse<any>> {
204
205
  userEmail = userEmail.trim();
205
- if (checkParameters(shopDomain, userEmail, productName,firstImageName,secondImageName) === false) {
206
+ if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
206
207
  throw new Error(REQUIRED_MESSAGE);
207
208
  }
208
209
 
209
- if(!isValidEmail(userEmail)){
210
+ if (!isValidEmail(userEmail)) {
210
211
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
211
212
  }
213
+ const payload = {
214
+ productName,
215
+ userEmail,
216
+ customerStoreUrl: shopDomain,
217
+ selectedUserImages: [firstImageName, secondImageName],
218
+ };
212
219
 
213
- try {
214
- const payload = {
215
- productName,
216
- userEmail,
217
- customerStoreUrl : shopDomain,
218
- selectedUserImages: [
219
- firstImageName,
220
- secondImageName
221
- ]
222
- }
223
-
224
- const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${
225
- API_ENDPOINTS.TRY_ON
226
- }`;
227
- const res = await axios.post(url, payload, {
228
- headers: { "X-Api-Key": this.#accessKey },
229
- });
230
- if (res?.data?.tryOnProcessStatus === "failed") {
231
- this.#disconnectSocket();
232
- throw res.data;
233
- } else {
234
- return res.data;
235
- }
236
- } catch (error) {
237
- onError?.(error);
238
- this.#disconnectSocket();
239
- throw error;
240
- }
241
- };
220
+ const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON}`;
221
+ return axios.post(url, payload, {
222
+ headers: { "X-Api-Key": this.#accessKey },
223
+ });
224
+ }
242
225
 
243
226
  #handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userEmail, productName }: HandleTimeOutParams): Promise<void> => {
244
227
  try {
@@ -255,7 +238,7 @@ class TryOn {
255
238
  throw new Error(REQUIRED_MESSAGE);
256
239
  }
257
240
 
258
- if(!isValidEmail(userEmail)){
241
+ if (!isValidEmail(userEmail)) {
259
242
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
260
243
  }
261
244
 
@@ -263,11 +246,9 @@ class TryOn {
263
246
  productName,
264
247
  userEmail,
265
248
  customerStoreUrl: shopDomain,
266
- }
249
+ };
267
250
 
268
- const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${
269
- API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD
270
- }`;
251
+ const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}`;
271
252
  return axios.post(url, payload, {
272
253
  headers: { "X-Api-Key": this.#accessKey },
273
254
  });