@swan-admin/swan-ai-measurements 1.1.56 → 1.1.58
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 +6 -11
- package/dist/esm/tryOn.js +25 -27
- package/dist/tryOn.d.ts +6 -11
- package/dist/tryOn.js +25 -25
- package/package.json +1 -1
- package/src/tryOn.ts +40 -37
package/dist/esm/tryOn.d.ts
CHANGED
|
@@ -15,10 +15,7 @@ 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;
|
|
@@ -27,11 +24,11 @@ interface HandleTryOnWebSocketParams {
|
|
|
27
24
|
interface Products {
|
|
28
25
|
productUrl: string;
|
|
29
26
|
productHandle: string;
|
|
30
|
-
openTryonId
|
|
27
|
+
openTryonId?: string;
|
|
31
28
|
selectedProductImageUrl: string;
|
|
32
29
|
}
|
|
33
30
|
interface HandleForLatestImageParams {
|
|
34
|
-
|
|
31
|
+
shopDomain: string;
|
|
35
32
|
userEmail: string;
|
|
36
33
|
products: Products[];
|
|
37
34
|
selectedUserImages: string[];
|
|
@@ -41,9 +38,7 @@ interface HandleForLatestImageParams {
|
|
|
41
38
|
selectedProductImageUrl?: string;
|
|
42
39
|
}
|
|
43
40
|
interface GetTryOnResultParams {
|
|
44
|
-
|
|
45
|
-
userEmail: string;
|
|
46
|
-
productName: string;
|
|
41
|
+
tryonId: string;
|
|
47
42
|
}
|
|
48
43
|
declare class TryOn {
|
|
49
44
|
#private;
|
|
@@ -51,10 +46,10 @@ declare class TryOn {
|
|
|
51
46
|
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
52
47
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
53
48
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
54
|
-
handleTryOnWebSocket: ({
|
|
55
|
-
handleTryOnSubmit({ userEmail,
|
|
49
|
+
handleTryOnWebSocket: ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
50
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
56
51
|
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
57
|
-
getTryOnResult: ({
|
|
52
|
+
getTryOnResult: ({ tryonId }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
58
53
|
getProductImageEligibility({ storeUrl, productHandle, imageURL, productDescription }: EligibiltyImageParams): Promise<AxiosResponse<any, any>>;
|
|
59
54
|
}
|
|
60
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,
|
|
186
|
-
if (checkParameters(
|
|
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) {
|
|
@@ -193,9 +193,7 @@ class TryOn {
|
|
|
193
193
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
194
194
|
}
|
|
195
195
|
const payload = Object.assign(Object.assign(Object.assign(Object.assign({ products,
|
|
196
|
-
userEmail,
|
|
197
|
-
customerStoreUrl,
|
|
198
|
-
selectedUserImages }, (requestSource !== undefined && requestSource !== null && { requestSource })), (callbackUrl !== undefined && callbackUrl !== null && { callbackUrl })), (openTryonId !== undefined && openTryonId !== null && { openTryonId })), (selectedProductImageUrl !== undefined && selectedProductImageUrl !== null && { selectedProductImageUrl }));
|
|
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 }));
|
|
199
197
|
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
|
|
200
198
|
return axios.post(url, payload, {
|
|
201
199
|
headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
|
package/dist/tryOn.d.ts
CHANGED
|
@@ -15,10 +15,7 @@ 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;
|
|
@@ -27,11 +24,11 @@ interface HandleTryOnWebSocketParams {
|
|
|
27
24
|
interface Products {
|
|
28
25
|
productUrl: string;
|
|
29
26
|
productHandle: string;
|
|
30
|
-
openTryonId
|
|
27
|
+
openTryonId?: string;
|
|
31
28
|
selectedProductImageUrl: string;
|
|
32
29
|
}
|
|
33
30
|
interface HandleForLatestImageParams {
|
|
34
|
-
|
|
31
|
+
shopDomain: string;
|
|
35
32
|
userEmail: string;
|
|
36
33
|
products: Products[];
|
|
37
34
|
selectedUserImages: string[];
|
|
@@ -41,9 +38,7 @@ interface HandleForLatestImageParams {
|
|
|
41
38
|
selectedProductImageUrl?: string;
|
|
42
39
|
}
|
|
43
40
|
interface GetTryOnResultParams {
|
|
44
|
-
|
|
45
|
-
userEmail: string;
|
|
46
|
-
productName: string;
|
|
41
|
+
tryonId: string;
|
|
47
42
|
}
|
|
48
43
|
declare class TryOn {
|
|
49
44
|
#private;
|
|
@@ -51,10 +46,10 @@ declare class TryOn {
|
|
|
51
46
|
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
52
47
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
53
48
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
54
|
-
handleTryOnWebSocket: ({
|
|
55
|
-
handleTryOnSubmit({ userEmail,
|
|
49
|
+
handleTryOnWebSocket: ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
50
|
+
handleTryOnSubmit({ userEmail, shopDomain, products, selectedUserImages, requestSource, callbackUrl, openTryonId, selectedProductImageUrl }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
56
51
|
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
57
|
-
getTryOnResult: ({
|
|
52
|
+
getTryOnResult: ({ tryonId }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
58
53
|
getProductImageEligibility({ storeUrl, productHandle, imageURL, productDescription }: EligibiltyImageParams): Promise<AxiosResponse<any, any>>;
|
|
59
54
|
}
|
|
60
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,
|
|
161
|
-
if ((0, utils_js_1.checkParameters)(
|
|
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) {
|
|
@@ -170,7 +170,7 @@ class TryOn {
|
|
|
170
170
|
const payload = {
|
|
171
171
|
products,
|
|
172
172
|
userEmail,
|
|
173
|
-
customerStoreUrl,
|
|
173
|
+
customerStoreUrl: shopDomain,
|
|
174
174
|
selectedUserImages,
|
|
175
175
|
...(requestSource !== undefined && requestSource !== null && { requestSource }),
|
|
176
176
|
...(callbackUrl !== undefined && callbackUrl !== null && { callbackUrl }),
|
|
@@ -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,10 +18,11 @@ 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;
|
|
@@ -31,12 +32,12 @@ interface Products
|
|
|
31
32
|
{
|
|
32
33
|
productUrl:string,
|
|
33
34
|
productHandle: string,
|
|
34
|
-
openTryonId
|
|
35
|
+
openTryonId?: string,
|
|
35
36
|
selectedProductImageUrl:string
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
interface HandleForLatestImageParams {
|
|
39
|
-
|
|
40
|
+
shopDomain: string;
|
|
40
41
|
userEmail: string;
|
|
41
42
|
products:Products[];
|
|
42
43
|
selectedUserImages:string[];
|
|
@@ -49,15 +50,17 @@ interface HandleForLatestImageParams {
|
|
|
49
50
|
interface HandleTimeOutParams {
|
|
50
51
|
onSuccess?: (data: any) => void;
|
|
51
52
|
onError?: (error: any) => void;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
tryonId:string
|
|
54
|
+
// shopDomain: string;
|
|
55
|
+
// userEmail: string;
|
|
56
|
+
// products: Products[];
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
interface GetTryOnResultParams {
|
|
58
|
-
shopDomain: string;
|
|
59
|
-
userEmail: string;
|
|
60
|
-
|
|
60
|
+
// shopDomain: string;
|
|
61
|
+
// userEmail: string;
|
|
62
|
+
// products: Products[];
|
|
63
|
+
tryonId :string
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
class TryOn {
|
|
@@ -166,27 +169,27 @@ class TryOn {
|
|
|
166
169
|
}
|
|
167
170
|
};
|
|
168
171
|
|
|
169
|
-
#handleTimeOut = ({ onSuccess, onError,
|
|
172
|
+
#handleTimeOut = ({ onSuccess, onError,tryonId }: HandleTimeOutParams): void => {
|
|
170
173
|
this.#timerWaitingRef = setTimeout(() => {
|
|
171
|
-
this.#handleGetTryOnResult({
|
|
174
|
+
this.#handleGetTryOnResult({ onSuccess, onError,tryonId });
|
|
172
175
|
this.#disconnectSocket();
|
|
173
176
|
}, 138000);
|
|
174
177
|
};
|
|
175
178
|
|
|
176
|
-
handleTryOnWebSocket = ({
|
|
177
|
-
if (checkParameters(
|
|
179
|
+
handleTryOnWebSocket = ({ tryonId, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams): void => {
|
|
180
|
+
if (checkParameters(tryonId) === false) {
|
|
178
181
|
throw new Error(REQUIRED_MESSAGE);
|
|
179
182
|
}
|
|
180
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
184
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
185
|
+
// }
|
|
183
186
|
this.#disconnectSocket();
|
|
184
187
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
185
188
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
186
189
|
if(this.#tryOnSocketRef){
|
|
187
190
|
this.#tryOnSocketRef.onopen = async () => {
|
|
188
191
|
onOpen?.();
|
|
189
|
-
this.#handleTimeOut({ onSuccess, onError,
|
|
192
|
+
this.#handleTimeOut({ onSuccess, onError, tryonId });
|
|
190
193
|
};
|
|
191
194
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
192
195
|
let data;
|
|
@@ -223,7 +226,7 @@ class TryOn {
|
|
|
223
226
|
|
|
224
227
|
handleTryOnSubmit({
|
|
225
228
|
userEmail,
|
|
226
|
-
|
|
229
|
+
shopDomain,
|
|
227
230
|
products,
|
|
228
231
|
selectedUserImages,
|
|
229
232
|
requestSource,
|
|
@@ -231,7 +234,7 @@ class TryOn {
|
|
|
231
234
|
openTryonId,
|
|
232
235
|
selectedProductImageUrl
|
|
233
236
|
}: HandleForLatestImageParams): Promise<AxiosResponse<any>> {
|
|
234
|
-
if (checkParameters(
|
|
237
|
+
if (checkParameters(shopDomain, userEmail, products,selectedUserImages) === false) {
|
|
235
238
|
throw new Error(REQUIRED_MESSAGE);
|
|
236
239
|
}
|
|
237
240
|
if (!selectedUserImages.length) {
|
|
@@ -243,7 +246,7 @@ class TryOn {
|
|
|
243
246
|
const payload = {
|
|
244
247
|
products,
|
|
245
248
|
userEmail,
|
|
246
|
-
customerStoreUrl,
|
|
249
|
+
customerStoreUrl:shopDomain,
|
|
247
250
|
selectedUserImages,
|
|
248
251
|
...(requestSource!==undefined && requestSource!==null &&{requestSource}),
|
|
249
252
|
...(callbackUrl!==undefined && callbackUrl!==null &&{callbackUrl}),
|
|
@@ -256,9 +259,9 @@ class TryOn {
|
|
|
256
259
|
});
|
|
257
260
|
}
|
|
258
261
|
|
|
259
|
-
#handleGetTryOnResult = async ({ onSuccess, onError,
|
|
262
|
+
#handleGetTryOnResult = async ({ onSuccess, onError, tryonId }: HandleTimeOutParams): Promise<void> => {
|
|
260
263
|
try {
|
|
261
|
-
const data = await this.getTryOnResult({
|
|
264
|
+
const data = await this.getTryOnResult({ tryonId });
|
|
262
265
|
onSuccess?.(data.data);
|
|
263
266
|
} catch (error) {
|
|
264
267
|
onError?.(error);
|
|
@@ -275,23 +278,23 @@ class TryOn {
|
|
|
275
278
|
);
|
|
276
279
|
}
|
|
277
280
|
|
|
278
|
-
getTryOnResult = ({
|
|
279
|
-
if (checkParameters(
|
|
281
|
+
getTryOnResult = ({tryonId }: GetTryOnResultParams): Promise<AxiosResponse<any>> => {
|
|
282
|
+
if (checkParameters(tryonId) === false) {
|
|
280
283
|
throw new Error(REQUIRED_MESSAGE);
|
|
281
284
|
}
|
|
282
285
|
|
|
283
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
+
// if (!isValidEmail(userEmail.trim())) {
|
|
287
|
+
// throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
288
|
+
// }
|
|
286
289
|
|
|
287
|
-
const payload = {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
};
|
|
290
|
+
// const payload = {
|
|
291
|
+
// products,
|
|
292
|
+
// userEmail,
|
|
293
|
+
// customerStoreUrl: shopDomain,
|
|
294
|
+
// };
|
|
292
295
|
|
|
293
|
-
const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}`;
|
|
294
|
-
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,{
|
|
295
298
|
headers: { "X-Api-Key": this.#accessKey },
|
|
296
299
|
});
|
|
297
300
|
};
|