@swan-admin/swan-ai-measurements 1.1.21 → 1.1.23
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/Readme.md +33 -33
- package/dist/constants.js +2 -2
- package/dist/esm/constants.js +2 -2
- package/dist/esm/fileUpload.js +206 -162
- package/dist/esm/tryOn.d.ts +1 -1
- package/dist/esm/tryOn.js +23 -41
- package/dist/fileUpload.js +10 -8
- package/dist/tryOn.d.ts +1 -1
- package/dist/tryOn.js +15 -32
- package/package.json +58 -58
- package/src/auth.ts +116 -116
- package/src/constants.ts +64 -64
- package/src/custom.ts +57 -57
- package/src/fileUpload.ts +183 -175
- package/src/index.ts +30 -30
- package/src/measurement.ts +209 -209
- package/src/poseDetection.ts +70 -70
- package/src/tryOn.ts +256 -277
- package/src/utils.ts +114 -114
- package/tsconfig.json +17 -17
package/dist/tryOn.js
CHANGED
|
@@ -74,7 +74,7 @@ class TryOn {
|
|
|
74
74
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
75
75
|
}
|
|
76
76
|
const payload = {
|
|
77
|
-
userEmail
|
|
77
|
+
userEmail,
|
|
78
78
|
};
|
|
79
79
|
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
80
|
headers: { "X-Api-Key": this.#accessKey },
|
|
@@ -90,11 +90,11 @@ class TryOn {
|
|
|
90
90
|
}
|
|
91
91
|
const payload = {
|
|
92
92
|
userEmail,
|
|
93
|
-
file: fileName
|
|
93
|
+
file: fileName,
|
|
94
94
|
};
|
|
95
95
|
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
96
|
headers: { "X-Api-Key": this.#accessKey },
|
|
97
|
-
data: payload
|
|
97
|
+
data: payload,
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
#disconnectSocket = () => {
|
|
@@ -142,7 +142,7 @@ class TryOn {
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
};
|
|
145
|
-
|
|
145
|
+
handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }) {
|
|
146
146
|
userEmail = userEmail.trim();
|
|
147
147
|
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
|
|
148
148
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
@@ -150,34 +150,17 @@ class TryOn {
|
|
|
150
150
|
if (!(0, utils_js_1.isValidEmail)(userEmail)) {
|
|
151
151
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
};
|
|
153
|
+
const payload = {
|
|
154
|
+
productName,
|
|
155
|
+
userEmail,
|
|
156
|
+
customerStoreUrl: shopDomain,
|
|
157
|
+
selectedUserImages: [firstImageName, secondImageName],
|
|
158
|
+
};
|
|
159
|
+
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}`;
|
|
160
|
+
return axios_1.default.post(url, payload, {
|
|
161
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
181
164
|
#handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userEmail, productName }) => {
|
|
182
165
|
try {
|
|
183
166
|
const data = await this.getTryOnResult({ shopDomain, userEmail, productName });
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "provides ai measurement suggestion",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/esm/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"require": "./dist/index.js",
|
|
11
|
-
"import": "./dist/esm/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@types/axios": "^0.14.0",
|
|
16
|
-
"@types/node": "^20.12.12",
|
|
17
|
-
"@uppy/aws-s3-multipart": "^3.11.1",
|
|
18
|
-
"@uppy/core": "^3.11.3",
|
|
19
|
-
"axios": "^1.6.7",
|
|
20
|
-
"socket.io": "^4.7.5",
|
|
21
|
-
"socket.io-client": "^4.7.5",
|
|
22
|
-
"tslib": "^2.6.2",
|
|
23
|
-
"typescript": "^5.4.5",
|
|
24
|
-
"fix-esm": "^1.0.1"
|
|
25
|
-
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"start": "nodemon dist/index.js",
|
|
28
|
-
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
29
|
-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
30
|
-
"start:dev": "nodemon src/index.ts",
|
|
31
|
-
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
32
|
-
"start:prod": "node dist/index.js",
|
|
33
|
-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
34
|
-
"test": "jest",
|
|
35
|
-
"test:watch": "jest --watch",
|
|
36
|
-
"test:cov": "jest --coverage",
|
|
37
|
-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
38
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
39
|
-
},
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "https://github.com/Syze/swan-ai-measurements.git"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"swan",
|
|
46
|
-
"ai",
|
|
47
|
-
"fitview"
|
|
48
|
-
],
|
|
49
|
-
"author": "paras",
|
|
50
|
-
"license": "ISC",
|
|
51
|
-
"bugs": {
|
|
52
|
-
"url": "https://github.com/Syze/swan-ai-measurements.git/issues"
|
|
53
|
-
},
|
|
54
|
-
"homepage": "https://github.com/Syze/swan-ai-measurements.git#readme",
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"nodemon": "^3.1.0"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
+
"version": "1.1.23",
|
|
4
|
+
"description": "provides ai measurement suggestion",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@types/axios": "^0.14.0",
|
|
16
|
+
"@types/node": "^20.12.12",
|
|
17
|
+
"@uppy/aws-s3-multipart": "^3.11.1",
|
|
18
|
+
"@uppy/core": "^3.11.3",
|
|
19
|
+
"axios": "^1.6.7",
|
|
20
|
+
"socket.io": "^4.7.5",
|
|
21
|
+
"socket.io-client": "^4.7.5",
|
|
22
|
+
"tslib": "^2.6.2",
|
|
23
|
+
"typescript": "^5.4.5",
|
|
24
|
+
"fix-esm": "^1.0.1"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "nodemon dist/index.js",
|
|
28
|
+
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
29
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
30
|
+
"start:dev": "nodemon src/index.ts",
|
|
31
|
+
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
32
|
+
"start:prod": "node dist/index.js",
|
|
33
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
34
|
+
"test": "jest",
|
|
35
|
+
"test:watch": "jest --watch",
|
|
36
|
+
"test:cov": "jest --coverage",
|
|
37
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
38
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/Syze/swan-ai-measurements.git"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"swan",
|
|
46
|
+
"ai",
|
|
47
|
+
"fitview"
|
|
48
|
+
],
|
|
49
|
+
"author": "paras",
|
|
50
|
+
"license": "ISC",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/Syze/swan-ai-measurements.git/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/Syze/swan-ai-measurements.git#readme",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"nodemon": "^3.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/auth.ts
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
-
import { checkParameters, getUrl } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
interface RegisterUserParams {
|
|
6
|
-
email: string;
|
|
7
|
-
appVerifyUrl: string;
|
|
8
|
-
gender?: string;
|
|
9
|
-
height?: number;
|
|
10
|
-
username?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface AddUserParams {
|
|
14
|
-
scanId: string;
|
|
15
|
-
email: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
height: number;
|
|
18
|
-
gender: string;
|
|
19
|
-
offsetMarketingConsent?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface AuthSocketParams {
|
|
23
|
-
email: string;
|
|
24
|
-
scanId: string;
|
|
25
|
-
onError?: (event: Event) => void;
|
|
26
|
-
onSuccess?: (data: any) => void;
|
|
27
|
-
onClose?: () => void;
|
|
28
|
-
onOpen?: () => void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface AuthSocketDetail {
|
|
32
|
-
email: string;
|
|
33
|
-
scanId: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default class Auth {
|
|
37
|
-
#socketRef?: WebSocket;
|
|
38
|
-
#accessKey: string;
|
|
39
|
-
#stagingUrl: boolean;
|
|
40
|
-
|
|
41
|
-
constructor(accessKey: string, stagingUrl = false) {
|
|
42
|
-
this.#accessKey = accessKey;
|
|
43
|
-
this.#stagingUrl = stagingUrl;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
registerUser({ email, appVerifyUrl, gender, height, username }: RegisterUserParams): Promise<AxiosResponse> {
|
|
47
|
-
if (!checkParameters(email, appVerifyUrl)) {
|
|
48
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
49
|
-
}
|
|
50
|
-
let body: Record<string, any> = { username, email, appVerifyUrl };
|
|
51
|
-
if (gender && height) {
|
|
52
|
-
body = { ...body, attributes: { gender, height } };
|
|
53
|
-
}
|
|
54
|
-
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
55
|
-
headers: { "X-Api-Key": this.#accessKey },
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
verifyToken(token: string): Promise<AxiosResponse> {
|
|
60
|
-
if (!checkParameters(token)) {
|
|
61
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
62
|
-
}
|
|
63
|
-
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
64
|
-
params: { token },
|
|
65
|
-
headers: { "X-Api-Key": this.#accessKey },
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }: AddUserParams): Promise<AxiosResponse> {
|
|
70
|
-
if (!checkParameters(scanId, email, height, gender)) {
|
|
71
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
72
|
-
}
|
|
73
|
-
return axios.post(
|
|
74
|
-
`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.ADD_USER}`,
|
|
75
|
-
{ scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) },
|
|
76
|
-
{ headers: { "X-Api-Key": this.#accessKey } }
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getUserDetail(email: string): Promise<AxiosResponse> {
|
|
81
|
-
if (!checkParameters(email)) {
|
|
82
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
83
|
-
}
|
|
84
|
-
return axios.get(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
85
|
-
headers: { "X-Api-Key": this.#accessKey },
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }: AuthSocketParams): void {
|
|
90
|
-
if (!checkParameters(email, scanId)) {
|
|
91
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
92
|
-
}
|
|
93
|
-
if (this.#socketRef) this.#socketRef.close();
|
|
94
|
-
|
|
95
|
-
this.#socketRef = new WebSocket(`${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.AUTH}`);
|
|
96
|
-
const detailObj: AuthSocketDetail = { email, scanId };
|
|
97
|
-
|
|
98
|
-
this.#socketRef.onopen = () => {
|
|
99
|
-
this.#socketRef?.send(JSON.stringify(detailObj));
|
|
100
|
-
onOpen?.();
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
this.#socketRef.onmessage = (event: MessageEvent) => {
|
|
104
|
-
const data = JSON.parse(event.data);
|
|
105
|
-
onSuccess?.(data);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
this.#socketRef.onclose = () => {
|
|
109
|
-
onClose?.();
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
this.#socketRef.onerror = (event: Event) => {
|
|
113
|
-
onError?.(event);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import axios, { AxiosResponse } from "axios";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters, getUrl } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
interface RegisterUserParams {
|
|
6
|
+
email: string;
|
|
7
|
+
appVerifyUrl: string;
|
|
8
|
+
gender?: string;
|
|
9
|
+
height?: number;
|
|
10
|
+
username?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface AddUserParams {
|
|
14
|
+
scanId: string;
|
|
15
|
+
email: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
height: number;
|
|
18
|
+
gender: string;
|
|
19
|
+
offsetMarketingConsent?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface AuthSocketParams {
|
|
23
|
+
email: string;
|
|
24
|
+
scanId: string;
|
|
25
|
+
onError?: (event: Event) => void;
|
|
26
|
+
onSuccess?: (data: any) => void;
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
onOpen?: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface AuthSocketDetail {
|
|
32
|
+
email: string;
|
|
33
|
+
scanId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class Auth {
|
|
37
|
+
#socketRef?: WebSocket;
|
|
38
|
+
#accessKey: string;
|
|
39
|
+
#stagingUrl: boolean;
|
|
40
|
+
|
|
41
|
+
constructor(accessKey: string, stagingUrl = false) {
|
|
42
|
+
this.#accessKey = accessKey;
|
|
43
|
+
this.#stagingUrl = stagingUrl;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
registerUser({ email, appVerifyUrl, gender, height, username }: RegisterUserParams): Promise<AxiosResponse> {
|
|
47
|
+
if (!checkParameters(email, appVerifyUrl)) {
|
|
48
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
49
|
+
}
|
|
50
|
+
let body: Record<string, any> = { username, email, appVerifyUrl };
|
|
51
|
+
if (gender && height) {
|
|
52
|
+
body = { ...body, attributes: { gender, height } };
|
|
53
|
+
}
|
|
54
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
55
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
verifyToken(token: string): Promise<AxiosResponse> {
|
|
60
|
+
if (!checkParameters(token)) {
|
|
61
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
62
|
+
}
|
|
63
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
64
|
+
params: { token },
|
|
65
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }: AddUserParams): Promise<AxiosResponse> {
|
|
70
|
+
if (!checkParameters(scanId, email, height, gender)) {
|
|
71
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
72
|
+
}
|
|
73
|
+
return axios.post(
|
|
74
|
+
`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.ADD_USER}`,
|
|
75
|
+
{ scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) },
|
|
76
|
+
{ headers: { "X-Api-Key": this.#accessKey } }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getUserDetail(email: string): Promise<AxiosResponse> {
|
|
81
|
+
if (!checkParameters(email)) {
|
|
82
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
83
|
+
}
|
|
84
|
+
return axios.get(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
85
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }: AuthSocketParams): void {
|
|
90
|
+
if (!checkParameters(email, scanId)) {
|
|
91
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
92
|
+
}
|
|
93
|
+
if (this.#socketRef) this.#socketRef.close();
|
|
94
|
+
|
|
95
|
+
this.#socketRef = new WebSocket(`${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.AUTH}`);
|
|
96
|
+
const detailObj: AuthSocketDetail = { email, scanId };
|
|
97
|
+
|
|
98
|
+
this.#socketRef.onopen = () => {
|
|
99
|
+
this.#socketRef?.send(JSON.stringify(detailObj));
|
|
100
|
+
onOpen?.();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
this.#socketRef.onmessage = (event: MessageEvent) => {
|
|
104
|
+
const data = JSON.parse(event.data);
|
|
105
|
+
onSuccess?.(data);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.#socketRef.onclose = () => {
|
|
109
|
+
onClose?.();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
this.#socketRef.onerror = (event: Event) => {
|
|
113
|
+
onError?.(event);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
export const STAGING_URL: Record<string, string> = {
|
|
2
|
-
APP_AUTH_BASE_URL: "https://
|
|
3
|
-
APP_BASE_WEBSOCKET_URL: "wss://
|
|
4
|
-
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const PROD_URL: Record<string, string> = {
|
|
8
|
-
APP_AUTH_BASE_URL: "https://api.getswan.co",
|
|
9
|
-
APP_BASE_WEBSOCKET_URL: "wss://wsnotify.api.getswan.co",
|
|
10
|
-
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service.uvcn97hn133d6.eu-west-1.cs.amazonlightsail.com",
|
|
11
|
-
};
|
|
12
|
-
export const FILE_UPLOAD_ENDPOINT: {
|
|
13
|
-
UPLOAD_START: string;
|
|
14
|
-
UPLOAD_COMPLETE: string;
|
|
15
|
-
UPLOAD_SIGN_PART: string;
|
|
16
|
-
UPLOAD_ABORT: string;
|
|
17
|
-
} = {
|
|
18
|
-
UPLOAD_START: "/upload/start",
|
|
19
|
-
UPLOAD_COMPLETE: "/upload/complete",
|
|
20
|
-
UPLOAD_SIGN_PART: "/upload/signpart",
|
|
21
|
-
UPLOAD_ABORT: "/upload/abort",
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const APP_AUTH_BASE_URL = "APP_AUTH_BASE_URL";
|
|
25
|
-
export const APP_BASE_WEBSOCKET_URL = "APP_BASE_WEBSOCKET_URL";
|
|
26
|
-
export const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBSOCKET_URL";
|
|
27
|
-
|
|
28
|
-
export const API_ENDPOINTS: {
|
|
29
|
-
[key: string]: string;
|
|
30
|
-
} = {
|
|
31
|
-
GET_USER_DETAIL: "/user",
|
|
32
|
-
REGISTER_USER: "/auth/register",
|
|
33
|
-
VERIFY_USER: "/auth/verify",
|
|
34
|
-
ADD_USER: "/user",
|
|
35
|
-
CUSTOM_CUSTOMER: "/customers/custom",
|
|
36
|
-
CREATE_CUSTOMER: "/customers",
|
|
37
|
-
MODEL: "/model",
|
|
38
|
-
TRY_ON_SCAN: "/tryon/scan",
|
|
39
|
-
TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
|
|
40
|
-
TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
|
|
41
|
-
TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
|
|
42
|
-
TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
|
|
43
|
-
TRY_ON: "/tryon",
|
|
44
|
-
AUTH: "/auth",
|
|
45
|
-
SCANNING: "/scanning",
|
|
46
|
-
};
|
|
47
|
-
export interface ObjMetaData {
|
|
48
|
-
gender: string;
|
|
49
|
-
scan_id?: string;
|
|
50
|
-
email: string;
|
|
51
|
-
focal_length: string;
|
|
52
|
-
height: string;
|
|
53
|
-
customer_store_url: string;
|
|
54
|
-
clothes_fit: string;
|
|
55
|
-
scan_type?: string;
|
|
56
|
-
callback_url: string;
|
|
57
|
-
}
|
|
58
|
-
type RequiredMetaDataKeys = keyof ObjMetaData;
|
|
59
|
-
|
|
60
|
-
export const requiredMetaData: RequiredMetaDataKeys[] = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
61
|
-
|
|
62
|
-
export const REQUIRED_MESSAGE: string = "Please verify required parameters";
|
|
63
|
-
export const REQUIRED_MESSAGE_FOR_META_DATA: string = "Please verify required parameters in meta data";
|
|
64
|
-
export const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|
|
1
|
+
export const STAGING_URL: Record<string, string> = {
|
|
2
|
+
APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
|
|
3
|
+
APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
|
|
4
|
+
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const PROD_URL: Record<string, string> = {
|
|
8
|
+
APP_AUTH_BASE_URL: "https://api.getswan.co",
|
|
9
|
+
APP_BASE_WEBSOCKET_URL: "wss://wsnotify.api.getswan.co",
|
|
10
|
+
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service.uvcn97hn133d6.eu-west-1.cs.amazonlightsail.com",
|
|
11
|
+
};
|
|
12
|
+
export const FILE_UPLOAD_ENDPOINT: {
|
|
13
|
+
UPLOAD_START: string;
|
|
14
|
+
UPLOAD_COMPLETE: string;
|
|
15
|
+
UPLOAD_SIGN_PART: string;
|
|
16
|
+
UPLOAD_ABORT: string;
|
|
17
|
+
} = {
|
|
18
|
+
UPLOAD_START: "/upload/start",
|
|
19
|
+
UPLOAD_COMPLETE: "/upload/complete",
|
|
20
|
+
UPLOAD_SIGN_PART: "/upload/signpart",
|
|
21
|
+
UPLOAD_ABORT: "/upload/abort",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const APP_AUTH_BASE_URL = "APP_AUTH_BASE_URL";
|
|
25
|
+
export const APP_BASE_WEBSOCKET_URL = "APP_BASE_WEBSOCKET_URL";
|
|
26
|
+
export const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBSOCKET_URL";
|
|
27
|
+
|
|
28
|
+
export const API_ENDPOINTS: {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
} = {
|
|
31
|
+
GET_USER_DETAIL: "/user",
|
|
32
|
+
REGISTER_USER: "/auth/register",
|
|
33
|
+
VERIFY_USER: "/auth/verify",
|
|
34
|
+
ADD_USER: "/user",
|
|
35
|
+
CUSTOM_CUSTOMER: "/customers/custom",
|
|
36
|
+
CREATE_CUSTOMER: "/customers",
|
|
37
|
+
MODEL: "/model",
|
|
38
|
+
TRY_ON_SCAN: "/tryon/scan",
|
|
39
|
+
TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
|
|
40
|
+
TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
|
|
41
|
+
TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
|
|
42
|
+
TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
|
|
43
|
+
TRY_ON: "/tryon",
|
|
44
|
+
AUTH: "/auth",
|
|
45
|
+
SCANNING: "/scanning",
|
|
46
|
+
};
|
|
47
|
+
export interface ObjMetaData {
|
|
48
|
+
gender: string;
|
|
49
|
+
scan_id?: string;
|
|
50
|
+
email: string;
|
|
51
|
+
focal_length: string;
|
|
52
|
+
height: string;
|
|
53
|
+
customer_store_url: string;
|
|
54
|
+
clothes_fit: string;
|
|
55
|
+
scan_type?: string;
|
|
56
|
+
callback_url: string;
|
|
57
|
+
}
|
|
58
|
+
type RequiredMetaDataKeys = keyof ObjMetaData;
|
|
59
|
+
|
|
60
|
+
export const requiredMetaData: RequiredMetaDataKeys[] = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
61
|
+
|
|
62
|
+
export const REQUIRED_MESSAGE: string = "Please verify required parameters";
|
|
63
|
+
export const REQUIRED_MESSAGE_FOR_META_DATA: string = "Please verify required parameters in meta data";
|
|
64
|
+
export const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|