@swan-admin/swan-ai-measurements 1.1.55 → 1.1.57
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/esm/tryOn.d.ts +11 -10
- package/dist/esm/tryOn.js +25 -25
- package/dist/tryOn.d.ts +11 -10
- package/dist/tryOn.js +25 -25
- package/package.json +1 -1
- package/src/tryOn.ts +47 -37
package/dist/esm/tryOn.d.ts
CHANGED
|
@@ -15,19 +15,22 @@ interface EligibiltyImageParams {
|
|
|
15
15
|
productDescription: string;
|
|
16
16
|
}
|
|
17
17
|
interface HandleTryOnWebSocketParams {
|
|
18
|
-
userEmail: string;
|
|
19
|
-
shopDomain: string;
|
|
20
18
|
tryonId: string;
|
|
21
|
-
productName: string;
|
|
22
19
|
onError?: (error: any) => void;
|
|
23
20
|
onSuccess?: (data: any) => void;
|
|
24
21
|
onClose?: () => void;
|
|
25
22
|
onOpen?: () => void;
|
|
26
23
|
}
|
|
24
|
+
interface Products {
|
|
25
|
+
productUrl: string;
|
|
26
|
+
productHandle: string;
|
|
27
|
+
openTryonId: string;
|
|
28
|
+
selectedProductImageUrl: string;
|
|
29
|
+
}
|
|
27
30
|
interface HandleForLatestImageParams {
|
|
28
31
|
shopDomain: string;
|
|
29
32
|
userEmail: string;
|
|
30
|
-
|
|
33
|
+
products: Products[];
|
|
31
34
|
selectedUserImages: string[];
|
|
32
35
|
requestSource?: string;
|
|
33
36
|
callbackUrl?: string;
|
|
@@ -35,9 +38,7 @@ interface HandleForLatestImageParams {
|
|
|
35
38
|
selectedProductImageUrl?: string;
|
|
36
39
|
}
|
|
37
40
|
interface GetTryOnResultParams {
|
|
38
|
-
|
|
39
|
-
userEmail: string;
|
|
40
|
-
productName: string;
|
|
41
|
+
tryonId: string;
|
|
41
42
|
}
|
|
42
43
|
declare class TryOn {
|
|
43
44
|
#private;
|
|
@@ -45,10 +46,10 @@ declare class TryOn {
|
|
|
45
46
|
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
46
47
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
47
48
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
48
|
-
handleTryOnWebSocket: ({
|
|
49
|
-
handleTryOnSubmit({ userEmail, shopDomain,
|
|
49
|
+
handleTryOnWebSocket: ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
50
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
50
51
|
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
51
|
-
getTryOnResult: ({
|
|
52
|
+
getTryOnResult: ({ tryonId }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
52
53
|
getProductImageEligibility({ storeUrl, productHandle, imageURL, productDescription }: EligibiltyImageParams): Promise<AxiosResponse<any, any>>;
|
|
53
54
|
}
|
|
54
55
|
export default TryOn;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -36,26 +36,26 @@ class TryOn {
|
|
|
36
36
|
clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
_TryOn_handleTimeOut.set(this, ({ onSuccess, onError,
|
|
39
|
+
_TryOn_handleTimeOut.set(this, ({ onSuccess, onError, tryonId }) => {
|
|
40
40
|
__classPrivateFieldSet(this, _TryOn_timerWaitingRef, setTimeout(() => {
|
|
41
|
-
__classPrivateFieldGet(this, _TryOn_handleGetTryOnResult, "f").call(this, {
|
|
41
|
+
__classPrivateFieldGet(this, _TryOn_handleGetTryOnResult, "f").call(this, { onSuccess, onError, tryonId });
|
|
42
42
|
__classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
|
|
43
43
|
}, 138000), "f");
|
|
44
44
|
});
|
|
45
|
-
this.handleTryOnWebSocket = ({
|
|
46
|
-
if (checkParameters(
|
|
45
|
+
this.handleTryOnWebSocket = ({ tryonId, onError, onSuccess, onClose, onOpen }) => {
|
|
46
|
+
if (checkParameters(tryonId) === false) {
|
|
47
47
|
throw new Error(REQUIRED_MESSAGE);
|
|
48
48
|
}
|
|
49
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
50
|
-
|
|
51
|
-
}
|
|
49
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
50
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
51
|
+
// }
|
|
52
52
|
__classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
|
|
53
53
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
54
54
|
__classPrivateFieldSet(this, _TryOn_tryOnSocketRef, new WebSocket(url), "f");
|
|
55
55
|
if (__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f")) {
|
|
56
56
|
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onopen = () => __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
58
|
-
__classPrivateFieldGet(this, _TryOn_handleTimeOut, "f").call(this, { onSuccess, onError,
|
|
58
|
+
__classPrivateFieldGet(this, _TryOn_handleTimeOut, "f").call(this, { onSuccess, onError, tryonId });
|
|
59
59
|
});
|
|
60
60
|
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onmessage = (event) => {
|
|
61
61
|
let data;
|
|
@@ -90,29 +90,29 @@ class TryOn {
|
|
|
90
90
|
console.log("no connection made for websocket");
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
-
_TryOn_handleGetTryOnResult.set(this, (_a) => __awaiter(this, [_a], void 0, function* ({ onSuccess, onError,
|
|
93
|
+
_TryOn_handleGetTryOnResult.set(this, (_a) => __awaiter(this, [_a], void 0, function* ({ onSuccess, onError, tryonId }) {
|
|
94
94
|
try {
|
|
95
|
-
const data = yield this.getTryOnResult({
|
|
95
|
+
const data = yield this.getTryOnResult({ tryonId });
|
|
96
96
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data.data);
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|
|
99
99
|
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
100
100
|
}
|
|
101
101
|
}));
|
|
102
|
-
this.getTryOnResult = ({
|
|
103
|
-
if (checkParameters(
|
|
102
|
+
this.getTryOnResult = ({ tryonId }) => {
|
|
103
|
+
if (checkParameters(tryonId) === false) {
|
|
104
104
|
throw new Error(REQUIRED_MESSAGE);
|
|
105
105
|
}
|
|
106
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
const payload = {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}`;
|
|
115
|
-
return axios.post(url,
|
|
106
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
107
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
108
|
+
// }
|
|
109
|
+
// const payload = {
|
|
110
|
+
// products,
|
|
111
|
+
// userEmail,
|
|
112
|
+
// customerStoreUrl: shopDomain,
|
|
113
|
+
// };
|
|
114
|
+
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}/${tryonId}`;
|
|
115
|
+
return axios.post(url, null, {
|
|
116
116
|
headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
|
|
117
117
|
});
|
|
118
118
|
};
|
|
@@ -182,8 +182,8 @@ class TryOn {
|
|
|
182
182
|
data: payload,
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
handleTryOnSubmit({ userEmail, shopDomain,
|
|
186
|
-
if (checkParameters(shopDomain, userEmail,
|
|
185
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }) {
|
|
186
|
+
if (checkParameters(shopDomain, userEmail, products, selectedUserImages) === false) {
|
|
187
187
|
throw new Error(REQUIRED_MESSAGE);
|
|
188
188
|
}
|
|
189
189
|
if (!selectedUserImages.length) {
|
|
@@ -192,7 +192,7 @@ class TryOn {
|
|
|
192
192
|
if (!isValidEmail(userEmail.trim())) {
|
|
193
193
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
194
194
|
}
|
|
195
|
-
const payload = Object.assign(Object.assign(Object.assign(Object.assign({
|
|
195
|
+
const payload = Object.assign(Object.assign(Object.assign(Object.assign({ products,
|
|
196
196
|
userEmail, customerStoreUrl: shopDomain, selectedUserImages }, (requestSource !== undefined && requestSource !== null && { requestSource })), (callbackUrl !== undefined && callbackUrl !== null && { callbackUrl })), (openTryonId !== undefined && openTryonId !== null && { openTryonId })), (selectedProductImageUrl !== undefined && selectedProductImageUrl !== null && { selectedProductImageUrl }));
|
|
197
197
|
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
|
|
198
198
|
return axios.post(url, payload, {
|
package/dist/tryOn.d.ts
CHANGED
|
@@ -15,19 +15,22 @@ interface EligibiltyImageParams {
|
|
|
15
15
|
productDescription: string;
|
|
16
16
|
}
|
|
17
17
|
interface HandleTryOnWebSocketParams {
|
|
18
|
-
userEmail: string;
|
|
19
|
-
shopDomain: string;
|
|
20
18
|
tryonId: string;
|
|
21
|
-
productName: string;
|
|
22
19
|
onError?: (error: any) => void;
|
|
23
20
|
onSuccess?: (data: any) => void;
|
|
24
21
|
onClose?: () => void;
|
|
25
22
|
onOpen?: () => void;
|
|
26
23
|
}
|
|
24
|
+
interface Products {
|
|
25
|
+
productUrl: string;
|
|
26
|
+
productHandle: string;
|
|
27
|
+
openTryonId: string;
|
|
28
|
+
selectedProductImageUrl: string;
|
|
29
|
+
}
|
|
27
30
|
interface HandleForLatestImageParams {
|
|
28
31
|
shopDomain: string;
|
|
29
32
|
userEmail: string;
|
|
30
|
-
|
|
33
|
+
products: Products[];
|
|
31
34
|
selectedUserImages: string[];
|
|
32
35
|
requestSource?: string;
|
|
33
36
|
callbackUrl?: string;
|
|
@@ -35,9 +38,7 @@ interface HandleForLatestImageParams {
|
|
|
35
38
|
selectedProductImageUrl?: string;
|
|
36
39
|
}
|
|
37
40
|
interface GetTryOnResultParams {
|
|
38
|
-
|
|
39
|
-
userEmail: string;
|
|
40
|
-
productName: string;
|
|
41
|
+
tryonId: string;
|
|
41
42
|
}
|
|
42
43
|
declare class TryOn {
|
|
43
44
|
#private;
|
|
@@ -45,10 +46,10 @@ declare class TryOn {
|
|
|
45
46
|
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
46
47
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
47
48
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
48
|
-
handleTryOnWebSocket: ({
|
|
49
|
-
handleTryOnSubmit({ userEmail, shopDomain,
|
|
49
|
+
handleTryOnWebSocket: ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
50
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
50
51
|
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
51
|
-
getTryOnResult: ({
|
|
52
|
+
getTryOnResult: ({ tryonId }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
52
53
|
getProductImageEligibility({ storeUrl, productHandle, imageURL, productDescription }: EligibiltyImageParams): Promise<AxiosResponse<any, any>>;
|
|
53
54
|
}
|
|
54
55
|
export default TryOn;
|
package/dist/tryOn.js
CHANGED
|
@@ -103,26 +103,26 @@ class TryOn {
|
|
|
103
103
|
clearTimeout(this.#timerWaitingRef);
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
|
-
#handleTimeOut = ({ onSuccess, onError,
|
|
106
|
+
#handleTimeOut = ({ onSuccess, onError, tryonId }) => {
|
|
107
107
|
this.#timerWaitingRef = setTimeout(() => {
|
|
108
|
-
this.#handleGetTryOnResult({
|
|
108
|
+
this.#handleGetTryOnResult({ onSuccess, onError, tryonId });
|
|
109
109
|
this.#disconnectSocket();
|
|
110
110
|
}, 138000);
|
|
111
111
|
};
|
|
112
|
-
handleTryOnWebSocket = ({
|
|
113
|
-
if ((0, utils_js_1.checkParameters)(
|
|
112
|
+
handleTryOnWebSocket = ({ tryonId, onError, onSuccess, onClose, onOpen }) => {
|
|
113
|
+
if ((0, utils_js_1.checkParameters)(tryonId) === false) {
|
|
114
114
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
115
115
|
}
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
}
|
|
116
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
117
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
118
|
+
// }
|
|
119
119
|
this.#disconnectSocket();
|
|
120
120
|
const url = `${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
121
121
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
122
122
|
if (this.#tryOnSocketRef) {
|
|
123
123
|
this.#tryOnSocketRef.onopen = async () => {
|
|
124
124
|
onOpen?.();
|
|
125
|
-
this.#handleTimeOut({ onSuccess, onError,
|
|
125
|
+
this.#handleTimeOut({ onSuccess, onError, tryonId });
|
|
126
126
|
};
|
|
127
127
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
128
128
|
let data;
|
|
@@ -157,8 +157,8 @@ class TryOn {
|
|
|
157
157
|
console.log("no connection made for websocket");
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
-
handleTryOnSubmit({ userEmail, shopDomain,
|
|
161
|
-
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail,
|
|
160
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }) {
|
|
161
|
+
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, products, selectedUserImages) === false) {
|
|
162
162
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
163
163
|
}
|
|
164
164
|
if (!selectedUserImages.length) {
|
|
@@ -168,7 +168,7 @@ class TryOn {
|
|
|
168
168
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
169
169
|
}
|
|
170
170
|
const payload = {
|
|
171
|
-
|
|
171
|
+
products,
|
|
172
172
|
userEmail,
|
|
173
173
|
customerStoreUrl: shopDomain,
|
|
174
174
|
selectedUserImages,
|
|
@@ -182,9 +182,9 @@ class TryOn {
|
|
|
182
182
|
headers: { "X-Api-Key": this.#accessKey },
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
#handleGetTryOnResult = async ({ onSuccess, onError,
|
|
185
|
+
#handleGetTryOnResult = async ({ onSuccess, onError, tryonId }) => {
|
|
186
186
|
try {
|
|
187
|
-
const data = await this.getTryOnResult({
|
|
187
|
+
const data = await this.getTryOnResult({ tryonId });
|
|
188
188
|
onSuccess?.(data.data);
|
|
189
189
|
}
|
|
190
190
|
catch (error) {
|
|
@@ -196,20 +196,20 @@ class TryOn {
|
|
|
196
196
|
headers: { "X-Api-Key": this.#accessKey },
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
|
-
getTryOnResult = ({
|
|
200
|
-
if ((0, utils_js_1.checkParameters)(
|
|
199
|
+
getTryOnResult = ({ tryonId }) => {
|
|
200
|
+
if ((0, utils_js_1.checkParameters)(tryonId) === false) {
|
|
201
201
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
202
202
|
}
|
|
203
|
-
if (!
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
const payload = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
};
|
|
211
|
-
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_RESULT_IMAGE_DOWNLOAD}`;
|
|
212
|
-
return axios_1.default.post(url,
|
|
203
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
204
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
205
|
+
// }
|
|
206
|
+
// const payload = {
|
|
207
|
+
// products,
|
|
208
|
+
// userEmail,
|
|
209
|
+
// customerStoreUrl: shopDomain,
|
|
210
|
+
// };
|
|
211
|
+
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_RESULT_IMAGE_DOWNLOAD}/${tryonId}`;
|
|
212
|
+
return axios_1.default.post(url, null, {
|
|
213
213
|
headers: { "X-Api-Key": this.#accessKey },
|
|
214
214
|
});
|
|
215
215
|
};
|
package/package.json
CHANGED
package/src/tryOn.ts
CHANGED
|
@@ -18,20 +18,28 @@ interface DeleteImageParams {
|
|
|
18
18
|
}
|
|
19
19
|
interface EligibiltyImageParams {storeUrl:string,productHandle:string,imageURL:string,productDescription:string}
|
|
20
20
|
interface HandleTryOnWebSocketParams {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
tryonId:string
|
|
22
|
+
// userEmail: string;
|
|
23
|
+
// shopDomain: string;
|
|
24
|
+
// tryonId: string;
|
|
25
|
+
// products: Products[];
|
|
25
26
|
onError?: (error: any) => void;
|
|
26
27
|
onSuccess?: (data: any) => void;
|
|
27
28
|
onClose?: () => void;
|
|
28
29
|
onOpen?: () => void;
|
|
29
30
|
}
|
|
31
|
+
interface Products
|
|
32
|
+
{
|
|
33
|
+
productUrl:string,
|
|
34
|
+
productHandle: string,
|
|
35
|
+
openTryonId: string,
|
|
36
|
+
selectedProductImageUrl:string
|
|
37
|
+
}
|
|
30
38
|
|
|
31
39
|
interface HandleForLatestImageParams {
|
|
32
40
|
shopDomain: string;
|
|
33
41
|
userEmail: string;
|
|
34
|
-
|
|
42
|
+
products:Products[];
|
|
35
43
|
selectedUserImages:string[];
|
|
36
44
|
requestSource?: string;
|
|
37
45
|
callbackUrl?: string;
|
|
@@ -42,15 +50,17 @@ interface HandleForLatestImageParams {
|
|
|
42
50
|
interface HandleTimeOutParams {
|
|
43
51
|
onSuccess?: (data: any) => void;
|
|
44
52
|
onError?: (error: any) => void;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
tryonId:string
|
|
54
|
+
// shopDomain: string;
|
|
55
|
+
// userEmail: string;
|
|
56
|
+
// products: Products[];
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
interface GetTryOnResultParams {
|
|
51
|
-
shopDomain: string;
|
|
52
|
-
userEmail: string;
|
|
53
|
-
|
|
60
|
+
// shopDomain: string;
|
|
61
|
+
// userEmail: string;
|
|
62
|
+
// products: Products[];
|
|
63
|
+
tryonId :string
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
class TryOn {
|
|
@@ -159,27 +169,27 @@ class TryOn {
|
|
|
159
169
|
}
|
|
160
170
|
};
|
|
161
171
|
|
|
162
|
-
#handleTimeOut = ({ onSuccess, onError,
|
|
172
|
+
#handleTimeOut = ({ onSuccess, onError,tryonId }: HandleTimeOutParams): void => {
|
|
163
173
|
this.#timerWaitingRef = setTimeout(() => {
|
|
164
|
-
this.#handleGetTryOnResult({
|
|
174
|
+
this.#handleGetTryOnResult({ onSuccess, onError,tryonId });
|
|
165
175
|
this.#disconnectSocket();
|
|
166
176
|
}, 138000);
|
|
167
177
|
};
|
|
168
178
|
|
|
169
|
-
handleTryOnWebSocket = ({
|
|
170
|
-
if (checkParameters(
|
|
179
|
+
handleTryOnWebSocket = ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams): void => {
|
|
180
|
+
if (checkParameters(tryonId) === false) {
|
|
171
181
|
throw new Error(REQUIRED_MESSAGE);
|
|
172
182
|
}
|
|
173
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
174
|
-
|
|
175
|
-
}
|
|
183
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
184
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
185
|
+
// }
|
|
176
186
|
this.#disconnectSocket();
|
|
177
187
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
178
188
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
179
189
|
if(this.#tryOnSocketRef){
|
|
180
190
|
this.#tryOnSocketRef.onopen = async () => {
|
|
181
191
|
onOpen?.();
|
|
182
|
-
this.#handleTimeOut({ onSuccess, onError,
|
|
192
|
+
this.#handleTimeOut({ onSuccess, onError, tryonId });
|
|
183
193
|
};
|
|
184
194
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
185
195
|
let data;
|
|
@@ -217,14 +227,14 @@ class TryOn {
|
|
|
217
227
|
handleTryOnSubmit({
|
|
218
228
|
userEmail,
|
|
219
229
|
shopDomain,
|
|
220
|
-
|
|
230
|
+
products,
|
|
221
231
|
selectedUserImages,
|
|
222
232
|
requestSource,
|
|
223
233
|
callbackUrl,
|
|
224
234
|
openTryonId,
|
|
225
235
|
selectedProductImageUrl
|
|
226
236
|
}: HandleForLatestImageParams): Promise<AxiosResponse<any>> {
|
|
227
|
-
if (checkParameters(shopDomain, userEmail,
|
|
237
|
+
if (checkParameters(shopDomain, userEmail, products,selectedUserImages) === false) {
|
|
228
238
|
throw new Error(REQUIRED_MESSAGE);
|
|
229
239
|
}
|
|
230
240
|
if (!selectedUserImages.length) {
|
|
@@ -234,9 +244,9 @@ class TryOn {
|
|
|
234
244
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
235
245
|
}
|
|
236
246
|
const payload = {
|
|
237
|
-
|
|
247
|
+
products,
|
|
238
248
|
userEmail,
|
|
239
|
-
customerStoreUrl:
|
|
249
|
+
customerStoreUrl:shopDomain,
|
|
240
250
|
selectedUserImages,
|
|
241
251
|
...(requestSource!==undefined && requestSource!==null &&{requestSource}),
|
|
242
252
|
...(callbackUrl!==undefined && callbackUrl!==null &&{callbackUrl}),
|
|
@@ -249,9 +259,9 @@ class TryOn {
|
|
|
249
259
|
});
|
|
250
260
|
}
|
|
251
261
|
|
|
252
|
-
#handleGetTryOnResult = async ({ onSuccess, onError,
|
|
262
|
+
#handleGetTryOnResult = async ({ onSuccess, onError, tryonId }: HandleTimeOutParams): Promise<void> => {
|
|
253
263
|
try {
|
|
254
|
-
const data = await this.getTryOnResult({
|
|
264
|
+
const data = await this.getTryOnResult({ tryonId });
|
|
255
265
|
onSuccess?.(data.data);
|
|
256
266
|
} catch (error) {
|
|
257
267
|
onError?.(error);
|
|
@@ -268,23 +278,23 @@ class TryOn {
|
|
|
268
278
|
);
|
|
269
279
|
}
|
|
270
280
|
|
|
271
|
-
getTryOnResult = ({
|
|
272
|
-
if (checkParameters(
|
|
281
|
+
getTryOnResult = ({tryonId }: GetTryOnResultParams): Promise<AxiosResponse<any>> => {
|
|
282
|
+
if (checkParameters(tryonId) === false) {
|
|
273
283
|
throw new Error(REQUIRED_MESSAGE);
|
|
274
284
|
}
|
|
275
285
|
|
|
276
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
277
|
-
|
|
278
|
-
}
|
|
286
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
287
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
288
|
+
// }
|
|
279
289
|
|
|
280
|
-
const payload = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
};
|
|
290
|
+
// const payload = {
|
|
291
|
+
// products,
|
|
292
|
+
// userEmail,
|
|
293
|
+
// customerStoreUrl: shopDomain,
|
|
294
|
+
// };
|
|
285
295
|
|
|
286
|
-
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}`;
|
|
287
|
-
return axios.post(url,
|
|
296
|
+
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}/${tryonId}`;
|
|
297
|
+
return axios.post(url, null,{
|
|
288
298
|
headers: { "X-Api-Key": this.#accessKey },
|
|
289
299
|
});
|
|
290
300
|
};
|