@swan-admin/swan-ai-measurements 1.0.39 → 1.0.41
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 +29 -23
- package/constants.js +0 -1
- package/custom.js +10 -10
- package/fileUpload.js +8 -11
- package/index.js +6 -14
- package/measurement.js +44 -48
- package/package.json +1 -1
- package/poseDetection.js +15 -8
- package/tryOn.js +39 -25
package/auth.js
CHANGED
|
@@ -9,13 +9,10 @@ import {
|
|
|
9
9
|
import { checkParameters } from "./utils.js";
|
|
10
10
|
|
|
11
11
|
class Auth {
|
|
12
|
-
#accessKey;
|
|
13
12
|
#socketRef;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
registerUser({ email, appVerifyUrl, gender, height, username }) {
|
|
18
|
-
if (checkParameters(email, appVerifyUrl) === false) {
|
|
13
|
+
|
|
14
|
+
registerUser({ email, appVerifyUrl, gender, height, username, accessKey }) {
|
|
15
|
+
if (checkParameters(email, appVerifyUrl, accessKey) === false) {
|
|
19
16
|
throw new Error(REQUIRED_MESSAGE);
|
|
20
17
|
}
|
|
21
18
|
let body = {
|
|
@@ -26,40 +23,49 @@ class Auth {
|
|
|
26
23
|
if (gender && height) {
|
|
27
24
|
body = { ...body, attributes: { gender, height } };
|
|
28
25
|
}
|
|
29
|
-
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.REGISTER_USER}`, body
|
|
26
|
+
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
27
|
+
headers: { "X-Api-Key": accessKey },
|
|
28
|
+
});
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
verifyToken = (token) => {
|
|
33
|
-
if (
|
|
31
|
+
verifyToken = (token, accessKey) => {
|
|
32
|
+
if (checkParameters(token, accessKey) === false) {
|
|
34
33
|
throw new Error(REQUIRED_MESSAGE);
|
|
35
34
|
}
|
|
36
35
|
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
37
36
|
params: { token },
|
|
37
|
+
headers: { "X-Api-Key": accessKey },
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
addUser = ({ scanId, email, name, height, gender, offsetMarketingConsent }) => {
|
|
42
|
-
if (checkParameters(scanId, email, height, gender) === false) {
|
|
41
|
+
addUser = ({ scanId, email, name, height, gender, offsetMarketingConsent, accessKey }) => {
|
|
42
|
+
if (checkParameters(scanId, email, height, gender, accessKey) === false) {
|
|
43
43
|
throw new Error(REQUIRED_MESSAGE);
|
|
44
44
|
}
|
|
45
|
-
return axios.post(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
return axios.post(
|
|
46
|
+
`${APP_AUTH_BASE_URL}${API_ENDPOINTS.ADD_USER}`,
|
|
47
|
+
{
|
|
48
|
+
scan_id: scanId,
|
|
49
|
+
email,
|
|
50
|
+
name,
|
|
51
|
+
offsetMarketingConsent,
|
|
52
|
+
attributes: JSON.stringify({ height, gender }),
|
|
53
|
+
},
|
|
54
|
+
{ headers: { "X-Api-Key": accessKey } }
|
|
55
|
+
);
|
|
52
56
|
};
|
|
53
57
|
|
|
54
|
-
getUserDetail = (email) => {
|
|
55
|
-
if (
|
|
58
|
+
getUserDetail = (email, accessKey) => {
|
|
59
|
+
if (checkParameters(email, accessKey) === false) {
|
|
56
60
|
throw new Error(REQUIRED_MESSAGE);
|
|
57
61
|
}
|
|
58
|
-
return axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}
|
|
62
|
+
return axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
63
|
+
headers: { "X-Api-Key": accessKey },
|
|
64
|
+
});
|
|
59
65
|
};
|
|
60
66
|
|
|
61
|
-
handleAuthSocket = ({ email, scanId, onError, onSuccess, onClose, onOpen }) => {
|
|
62
|
-
if (checkParameters(email, scanId) === false) {
|
|
67
|
+
handleAuthSocket = ({ email, scanId, onError, onSuccess, onClose, onOpen, accessKey }) => {
|
|
68
|
+
if (checkParameters(email, scanId, accessKey) === false) {
|
|
63
69
|
throw new Error(REQUIRED_MESSAGE);
|
|
64
70
|
}
|
|
65
71
|
this.#socketRef?.close?.();
|
package/constants.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const FILE_UPLOAD_KEY = "7a8ccc86249849be911b0d7dbc20290e";
|
|
2
1
|
export const APP_BASE_URL = "https://fitview-server-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
|
|
3
2
|
export const APP_AUTH_BASE_URL = "https://staging.api.getswan.co";
|
|
4
3
|
export const APP_AUTH_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co";
|
package/custom.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters } from "./utils.js";
|
|
3
4
|
|
|
4
5
|
export default class Custom {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.#accessKey = key;
|
|
8
|
-
}
|
|
9
|
-
getCustomCustomerConfig = (store_url) => {
|
|
10
|
-
if (!store_url) {
|
|
6
|
+
getCustomCustomerConfig = (store_url, accessKey) => {
|
|
7
|
+
if (checkParameters(store_url, accessKey) === false) {
|
|
11
8
|
throw new Error(REQUIRED_MESSAGE);
|
|
12
9
|
}
|
|
13
|
-
return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
|
|
10
|
+
return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
|
|
11
|
+
params: { store_url },
|
|
12
|
+
headers: { "X-Api-Key": accessKey },
|
|
13
|
+
});
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
getModelUrl = (id) => {
|
|
17
|
-
if (
|
|
16
|
+
getModelUrl = (id, accessKey) => {
|
|
17
|
+
if (checkParameters(id, accessKey) === false) {
|
|
18
18
|
throw new Error(REQUIRED_MESSAGE);
|
|
19
19
|
}
|
|
20
|
-
return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.MODEL}/${id}
|
|
20
|
+
return axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.MODEL}/${id}`, { headers: { "X-Api-Key": accessKey } });
|
|
21
21
|
};
|
|
22
22
|
}
|
package/fileUpload.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
2
2
|
import Uppy from "@uppy/core";
|
|
3
|
-
import {
|
|
3
|
+
import { REQUIRED_MESSAGE, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
4
4
|
import { checkParameters, fetchData } from "./utils.js";
|
|
5
5
|
|
|
6
6
|
export default class FileUpload {
|
|
7
|
-
#accessKey;
|
|
8
7
|
#uppyIns;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
uploadFile({ file, objMetaData, scanId }) {
|
|
13
|
-
if (checkParameters(file, objMetaData, scanId) === false) {
|
|
8
|
+
|
|
9
|
+
uploadFile({ file, objMetaData, scanId, accessKey }) {
|
|
10
|
+
if (checkParameters(file, objMetaData, scanId, accessKey) === false) {
|
|
14
11
|
throw new Error(REQUIRED_MESSAGE);
|
|
15
12
|
}
|
|
16
13
|
return new Promise((resolve, reject) => {
|
|
@@ -26,7 +23,7 @@ export default class FileUpload {
|
|
|
26
23
|
const objectKey = `${scanId}.${file.extension}`;
|
|
27
24
|
return fetchData({
|
|
28
25
|
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
29
|
-
apiKey:
|
|
26
|
+
apiKey: accessKey,
|
|
30
27
|
body: {
|
|
31
28
|
objectKey,
|
|
32
29
|
contentType: file.type,
|
|
@@ -37,7 +34,7 @@ export default class FileUpload {
|
|
|
37
34
|
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
38
35
|
fetchData({
|
|
39
36
|
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
40
|
-
apiKey:
|
|
37
|
+
apiKey: accessKey,
|
|
41
38
|
body: {
|
|
42
39
|
uploadId,
|
|
43
40
|
objectKey: key,
|
|
@@ -49,7 +46,7 @@ export default class FileUpload {
|
|
|
49
46
|
signPart: (file, partData) =>
|
|
50
47
|
fetchData({
|
|
51
48
|
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
52
|
-
apiKey:
|
|
49
|
+
apiKey: accessKey,
|
|
53
50
|
body: {
|
|
54
51
|
objectKey: partData.key,
|
|
55
52
|
uploadId: partData.uploadId,
|
|
@@ -60,7 +57,7 @@ export default class FileUpload {
|
|
|
60
57
|
abortMultipartUpload: (file, { uploadId, key }) =>
|
|
61
58
|
fetchData({
|
|
62
59
|
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
63
|
-
apiKey:
|
|
60
|
+
apiKey: accessKey,
|
|
64
61
|
body: {
|
|
65
62
|
uploadId,
|
|
66
63
|
objectKey: key,
|
package/index.js
CHANGED
|
@@ -5,23 +5,15 @@ import Measurement from "./measurement.js";
|
|
|
5
5
|
import PoseDetection from "./poseDetection.js";
|
|
6
6
|
import TryOn from "./tryOn.js";
|
|
7
7
|
export default class Swan {
|
|
8
|
-
|
|
9
|
-
constructor(key) {
|
|
10
|
-
if (key !== 9876543210) {
|
|
11
|
-
throw new Error("wrong access key");
|
|
12
|
-
}
|
|
13
|
-
this.#accessKey = key;
|
|
14
|
-
}
|
|
8
|
+
auth = new Auth();
|
|
15
9
|
|
|
16
|
-
|
|
10
|
+
custom = new Custom();
|
|
17
11
|
|
|
18
|
-
|
|
12
|
+
fileUpload = new FileUpload();
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
measurement = new Measurement();
|
|
21
15
|
|
|
22
|
-
|
|
16
|
+
poseDetection = new PoseDetection();
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tryOn = new TryOn(this.#accessKey);
|
|
18
|
+
tryOn = new TryOn();
|
|
27
19
|
}
|
package/measurement.js
CHANGED
|
@@ -4,45 +4,39 @@ import {
|
|
|
4
4
|
APP_AUTH_BASE_URL,
|
|
5
5
|
APP_RECOMMENDATION_WEBSOCKET_URL,
|
|
6
6
|
APP_TRY_ON_WEBSOCKET_URL,
|
|
7
|
-
FILE_UPLOAD_KEY,
|
|
8
7
|
REQUIRED_MESSAGE,
|
|
9
8
|
} from "./constants.js";
|
|
10
9
|
import { checkParameters } from "./utils.js";
|
|
11
10
|
|
|
12
11
|
export default class Measurement {
|
|
13
|
-
#accessKey;
|
|
14
12
|
#tryOnSocketRef = null;
|
|
15
13
|
#measurementSocketRef = null;
|
|
16
14
|
#timerPollingRef = null;
|
|
17
15
|
#timerWaitingRef = null;
|
|
18
|
-
constructor(key) {
|
|
19
|
-
this.#accessKey = key;
|
|
20
|
-
}
|
|
21
16
|
|
|
22
|
-
getMeasurementStatus(scanId) {
|
|
23
|
-
if (
|
|
17
|
+
getMeasurementStatus(scanId, accessKey) {
|
|
18
|
+
if (checkParameters(scanId, accessKey) === false) {
|
|
24
19
|
throw new Error(REQUIRED_MESSAGE);
|
|
25
20
|
}
|
|
26
21
|
const url = `${APP_AUTH_BASE_URL}/measurements?scanId=${scanId}`;
|
|
27
22
|
return axios.get(url, {
|
|
28
|
-
headers: { "X-Api-Key":
|
|
23
|
+
headers: { "X-Api-Key": accessKey },
|
|
29
24
|
});
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
getTryOnMeasurements({ scanId, shopDomain, productName }) {
|
|
33
|
-
if (checkParameters(scanId, shopDomain, productName) === false) {
|
|
27
|
+
getTryOnMeasurements({ scanId, shopDomain, productName, accessKey }) {
|
|
28
|
+
if (checkParameters(scanId, shopDomain, productName, accessKey) === false) {
|
|
34
29
|
throw new Error(REQUIRED_MESSAGE);
|
|
35
30
|
}
|
|
36
31
|
const tryOnUrl = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_SCAN}/${scanId}/shop/${shopDomain}/product/${productName}`;
|
|
37
|
-
return axios.get(tryOnUrl);
|
|
32
|
+
return axios.get(tryOnUrl, { headers: { "X-Api-Key": accessKey } });
|
|
38
33
|
}
|
|
39
34
|
|
|
40
|
-
handleTryOnSocket({ shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen }) {
|
|
41
|
-
if (checkParameters(shopDomain, scanId, productName) === false) {
|
|
35
|
+
handleTryOnSocket({ shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen, accessKey }) {
|
|
36
|
+
if (checkParameters(shopDomain, scanId, productName, accessKey) === false) {
|
|
42
37
|
throw new Error(REQUIRED_MESSAGE);
|
|
43
38
|
}
|
|
44
39
|
this.#tryOnSocketRef?.close();
|
|
45
|
-
|
|
46
40
|
const url = `${APP_TRY_ON_WEBSOCKET_URL}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
47
41
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
48
42
|
|
|
@@ -68,9 +62,9 @@ export default class Measurement {
|
|
|
68
62
|
};
|
|
69
63
|
}
|
|
70
64
|
|
|
71
|
-
#getMeasurementsCheck = async (onSuccess, onError,
|
|
65
|
+
#getMeasurementsCheck = async ({ scanId, onSuccess, onError, accessKey }) => {
|
|
72
66
|
try {
|
|
73
|
-
const res = await this.getMeasurementStatus(scanId);
|
|
67
|
+
const res = await this.getMeasurementStatus(scanId, accessKey);
|
|
74
68
|
if (res?.data && res?.data?.[0]?.isMeasured === true) {
|
|
75
69
|
onSuccess?.(res?.data);
|
|
76
70
|
clearInterval(this.#timerPollingRef);
|
|
@@ -81,10 +75,10 @@ export default class Measurement {
|
|
|
81
75
|
}
|
|
82
76
|
};
|
|
83
77
|
|
|
84
|
-
#handlePolling(onSuccess, onError) {
|
|
78
|
+
#handlePolling({ scanId, onSuccess, onError, accessKey }) {
|
|
85
79
|
clearInterval(this.#timerPollingRef);
|
|
86
80
|
this.#timerPollingRef = setInterval(() => {
|
|
87
|
-
this.#getMeasurementsCheck(onSuccess, onError);
|
|
81
|
+
this.#getMeasurementsCheck({ scanId, onSuccess, onError, accessKey });
|
|
88
82
|
}, 5000);
|
|
89
83
|
}
|
|
90
84
|
|
|
@@ -93,42 +87,44 @@ export default class Measurement {
|
|
|
93
87
|
clearTimeout(this.#timerWaitingRef);
|
|
94
88
|
};
|
|
95
89
|
|
|
96
|
-
#handleTimeOut = (onSuccess, onError) => {
|
|
90
|
+
#handleTimeOut = ({ scanId, onSuccess, onError, accessKey }) => {
|
|
97
91
|
this.#timerWaitingRef = setTimeout(() => {
|
|
98
|
-
this.#handlePolling(onSuccess, onError);
|
|
92
|
+
this.#handlePolling({ scanId, onSuccess, onError, accessKey });
|
|
99
93
|
this.#disconnectSocket();
|
|
100
94
|
}, 2 * 60000);
|
|
101
95
|
};
|
|
102
96
|
|
|
103
|
-
handleMeasurementSocket = ({ scanId, onError, onSuccess, onClose, onOpen }) => {
|
|
104
|
-
if (
|
|
97
|
+
handleMeasurementSocket = ({ scanId, onError, onSuccess, onClose, onOpen, accessKey }) => {
|
|
98
|
+
if (checkParameters(scanId, accessKey) === false) {
|
|
105
99
|
throw new Error(REQUIRED_MESSAGE);
|
|
106
100
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
this.#disconnectSocket();
|
|
103
|
+
const url = `${APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
|
|
104
|
+
this.#measurementSocketRef = new WebSocket(url);
|
|
105
|
+
|
|
106
|
+
this.#measurementSocketRef.onopen = () => {
|
|
107
|
+
onOpen?.();
|
|
108
|
+
this.#handleTimeOut({ scanId, onSuccess, onError, accessKey });
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
this.#measurementSocketRef.onmessage = (event) => {
|
|
112
|
+
const data = JSON.parse(event.data);
|
|
113
|
+
if (data?.code === 200 && data?.scanStatus === "success") {
|
|
114
|
+
onSuccess?.(data);
|
|
115
|
+
} else {
|
|
116
|
+
onError?.(data);
|
|
117
|
+
}
|
|
118
|
+
clearTimeout(this.#timerWaitingRef);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
this.#measurementSocketRef.onclose = () => {
|
|
122
|
+
onClose?.();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
this.#measurementSocketRef.onerror = (event) => {
|
|
126
|
+
onError?.(event);
|
|
127
|
+
};
|
|
128
|
+
}, 5000);
|
|
133
129
|
};
|
|
134
130
|
}
|
package/package.json
CHANGED
package/poseDetection.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { APP_POSE_DETECTION_WEbSOCKET_URL } from "./constants.js";
|
|
1
|
+
import { APP_POSE_DETECTION_WEbSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
2
2
|
import { io } from "socket.io-client";
|
|
3
3
|
|
|
4
4
|
export default class PoseDetection {
|
|
5
5
|
#socketRef = null;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
|
|
7
|
+
connect(accessKey) {
|
|
8
|
+
if (!accessKey) {
|
|
9
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
10
|
+
}
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
12
12
|
this.#socketRef = io.connect(APP_POSE_DETECTION_WEbSOCKET_URL);
|
|
13
13
|
this.#socketRef?.on("connect", () => {
|
|
@@ -17,7 +17,11 @@ export default class PoseDetection {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
videoEmit({ image, scanId }) {
|
|
20
|
+
videoEmit({ image, scanId, accessKey }) {
|
|
21
|
+
if (!accessKey) {
|
|
22
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
if (!this.#socketRef) {
|
|
22
26
|
throw new Error("socket is not connected");
|
|
23
27
|
}
|
|
@@ -31,7 +35,10 @@ export default class PoseDetection {
|
|
|
31
35
|
this.#socketRef?.disconnect?.();
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
poseStatus(callBack) {
|
|
38
|
+
poseStatus(accessKey, callBack) {
|
|
39
|
+
if (!accessKey) {
|
|
40
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
41
|
+
}
|
|
35
42
|
if (!this.#socketRef) {
|
|
36
43
|
throw new Error("socket is not connected");
|
|
37
44
|
}
|
package/tryOn.js
CHANGED
|
@@ -3,14 +3,13 @@ import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, REQUIRED_MESS
|
|
|
3
3
|
import { checkParameters } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
class TryOn {
|
|
6
|
-
#accessKey = null;
|
|
7
6
|
#tryOnSocketRef = null;
|
|
8
7
|
#timerWaitingRef = null;
|
|
9
|
-
constructor(accessKey) {
|
|
10
|
-
this.#accessKey = accessKey;
|
|
11
|
-
}
|
|
12
8
|
|
|
13
|
-
uploadFile(files, userId) {
|
|
9
|
+
uploadFile(files, userId, accessKey) {
|
|
10
|
+
if (!accessKey) {
|
|
11
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
12
|
+
}
|
|
14
13
|
return new Promise(async (resolve, reject) => {
|
|
15
14
|
try {
|
|
16
15
|
const payload = {
|
|
@@ -31,10 +30,11 @@ class TryOn {
|
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
#getSignedUrl(payload) {
|
|
33
|
+
#getSignedUrl(payload, accessKey) {
|
|
35
34
|
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
|
|
36
35
|
headers: {
|
|
37
36
|
"Content-Type": "application/json",
|
|
37
|
+
"X-Api-Key": accessKey,
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -47,12 +47,22 @@ class TryOn {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
getUploadedFiles(userId) {
|
|
51
|
-
|
|
50
|
+
getUploadedFiles(userId, accessKey) {
|
|
51
|
+
if (checkParameters(userId, accessKey) === false) {
|
|
52
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
53
|
+
}
|
|
54
|
+
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}?userId=${userId}`, {
|
|
55
|
+
headers: { "X-Api-Key": accessKey },
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
deleteImage(userId,
|
|
55
|
-
|
|
59
|
+
deleteImage({ userId, fileName, accessKey }) {
|
|
60
|
+
if (checkParameters(userId, fileName, accessKey) === false) {
|
|
61
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
62
|
+
}
|
|
63
|
+
return axios.delete(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_IMAGE_URLS}?userId=${userId}&file=${fileName}`, {
|
|
64
|
+
headers: { "X-Api-Key": accessKey },
|
|
65
|
+
});
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
#disconnectSocket = () => {
|
|
@@ -60,15 +70,15 @@ class TryOn {
|
|
|
60
70
|
clearTimeout(this.#timerWaitingRef);
|
|
61
71
|
};
|
|
62
72
|
|
|
63
|
-
#handleTimeOut = ({ onSuccess, onError, shopDomain, userId, productName }) => {
|
|
73
|
+
#handleTimeOut = ({ onSuccess, onError, shopDomain, userId, productName, accessKey }) => {
|
|
64
74
|
this.#timerWaitingRef = setTimeout(() => {
|
|
65
|
-
this.#handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError });
|
|
75
|
+
this.#handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError, accessKey });
|
|
66
76
|
this.#disconnectSocket();
|
|
67
77
|
}, 78000);
|
|
68
78
|
};
|
|
69
79
|
|
|
70
|
-
handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
71
|
-
if (checkParameters(shopDomain, userId, productName) === false) {
|
|
80
|
+
handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen, accessKey }) => {
|
|
81
|
+
if (checkParameters(shopDomain, userId, productName, accessKey) === false) {
|
|
72
82
|
throw new Error(REQUIRED_MESSAGE);
|
|
73
83
|
}
|
|
74
84
|
this.#disconnectSocket();
|
|
@@ -76,9 +86,9 @@ class TryOn {
|
|
|
76
86
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
77
87
|
this.#tryOnSocketRef.onopen = async () => {
|
|
78
88
|
onOpen?.();
|
|
79
|
-
this.#handleTimeOut({ onSuccess, onError, shopDomain, userId, productName });
|
|
89
|
+
this.#handleTimeOut({ onSuccess, onError, shopDomain, userId, productName, accessKey });
|
|
80
90
|
try {
|
|
81
|
-
await this.handleForLatestImage({ shopDomain, userId, productName });
|
|
91
|
+
await this.handleForLatestImage({ shopDomain, userId, productName, accessKey });
|
|
82
92
|
} catch (error) {
|
|
83
93
|
onError?.(error);
|
|
84
94
|
}
|
|
@@ -86,7 +96,7 @@ class TryOn {
|
|
|
86
96
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
87
97
|
const data = JSON.parse(event.data);
|
|
88
98
|
if (data?.status === "success") {
|
|
89
|
-
this.#handleGetTryOnResult({ shopDomain, userId, productName, onError, onSuccess });
|
|
99
|
+
this.#handleGetTryOnResult({ shopDomain, userId, productName, onError, onSuccess, accessKey });
|
|
90
100
|
} else {
|
|
91
101
|
onError?.(data);
|
|
92
102
|
}
|
|
@@ -101,14 +111,16 @@ class TryOn {
|
|
|
101
111
|
};
|
|
102
112
|
};
|
|
103
113
|
|
|
104
|
-
handleForLatestImage = async ({ userId, shopDomain, productName, onError }) => {
|
|
105
|
-
if (checkParameters(shopDomain, userId, productName) === false) {
|
|
114
|
+
handleForLatestImage = async ({ userId, shopDomain, productName, onError, accessKey }) => {
|
|
115
|
+
if (checkParameters(shopDomain, userId, productName, accessKey) === false) {
|
|
106
116
|
throw new Error(REQUIRED_MESSAGE);
|
|
107
117
|
}
|
|
108
118
|
return new Promise(async (resolve, reject) => {
|
|
109
119
|
try {
|
|
110
120
|
const url = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON}/?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
|
|
111
|
-
const res = await axios.post(url
|
|
121
|
+
const res = await axios.post(url, {
|
|
122
|
+
headers: { "X-Api-Key": accessKey },
|
|
123
|
+
});
|
|
112
124
|
if (res?.data?.tryOnProcessStatus === "failed") {
|
|
113
125
|
this.#disconnectSocket();
|
|
114
126
|
reject(res?.data);
|
|
@@ -123,21 +135,23 @@ class TryOn {
|
|
|
123
135
|
});
|
|
124
136
|
};
|
|
125
137
|
|
|
126
|
-
#handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userId, productName }) => {
|
|
138
|
+
#handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userId, productName, accessKey }) => {
|
|
127
139
|
try {
|
|
128
|
-
const data = await this.getTryOnResult({ shopDomain, userId, productName });
|
|
140
|
+
const data = await this.getTryOnResult({ shopDomain, userId, productName, accessKey });
|
|
129
141
|
onSuccess?.(data?.data);
|
|
130
142
|
} catch (error) {
|
|
131
143
|
onError?.(error);
|
|
132
144
|
}
|
|
133
145
|
};
|
|
134
146
|
|
|
135
|
-
getTryOnResult = ({ userId, shopDomain, productName }) => {
|
|
136
|
-
if (checkParameters(shopDomain, userId, productName) === false) {
|
|
147
|
+
getTryOnResult = ({ userId, shopDomain, productName, accessKey }) => {
|
|
148
|
+
if (checkParameters(shopDomain, userId, productName, accessKey) === false) {
|
|
137
149
|
throw new Error(REQUIRED_MESSAGE);
|
|
138
150
|
}
|
|
139
151
|
const url = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
|
|
140
|
-
return axios.post(url
|
|
152
|
+
return axios.post(url, {
|
|
153
|
+
headers: { "X-Api-Key": accessKey },
|
|
154
|
+
});
|
|
141
155
|
};
|
|
142
156
|
}
|
|
143
157
|
|