@swan-admin/swan-ai-measurements 1.1.40 → 1.1.42
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/auth.js +34 -15
- package/dist/constants.js +1 -0
- package/dist/esm/auth.js +35 -16
- package/dist/esm/constants.js +1 -0
- package/dist/esm/fileUpload.d.ts +12 -10
- package/dist/esm/fileUpload.js +23 -1
- package/dist/esm/measurement.js +37 -19
- package/dist/esm/tryOn.js +48 -26
- package/dist/fileUpload.d.ts +12 -10
- package/dist/fileUpload.js +9 -0
- package/dist/measurement.js +37 -19
- package/dist/tryOn.js +48 -26
- package/package.json +4 -2
- package/src/auth.ts +116 -98
- package/src/constants.ts +1 -0
- package/src/fileUpload.ts +17 -2
- package/src/measurement.ts +39 -22
- package/src/tryOn.ts +47 -25
package/dist/auth.js
CHANGED
|
@@ -6,6 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const constants_js_1 = require("./constants.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
|
+
// Conditionally import ws for Node.js
|
|
10
|
+
let WebSocketClient;
|
|
11
|
+
if (typeof window !== "undefined" && window.WebSocket) {
|
|
12
|
+
WebSocketClient = window.WebSocket;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const WS = require("ws");
|
|
16
|
+
WebSocketClient = WS;
|
|
17
|
+
}
|
|
9
18
|
class Auth {
|
|
10
19
|
#socketRef;
|
|
11
20
|
#accessKey;
|
|
@@ -55,22 +64,32 @@ class Auth {
|
|
|
55
64
|
}
|
|
56
65
|
if (this.#socketRef)
|
|
57
66
|
this.#socketRef.close();
|
|
58
|
-
this.#socketRef = new
|
|
67
|
+
this.#socketRef = new WebSocketClient(`${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.AUTH}`);
|
|
59
68
|
const detailObj = { email, scanId };
|
|
60
|
-
this.#socketRef
|
|
61
|
-
this.#socketRef
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
if (this.#socketRef) {
|
|
70
|
+
this.#socketRef.onopen = () => {
|
|
71
|
+
this.#socketRef?.send(JSON.stringify(detailObj));
|
|
72
|
+
onOpen?.();
|
|
73
|
+
};
|
|
74
|
+
this.#socketRef.onmessage = (event) => {
|
|
75
|
+
let data;
|
|
76
|
+
try {
|
|
77
|
+
data = JSON.parse(event.data);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.log(data, error, "noy correct format for data");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
data = JSON.parse(event.data);
|
|
84
|
+
onSuccess?.(data);
|
|
85
|
+
};
|
|
86
|
+
this.#socketRef.onclose = () => {
|
|
87
|
+
onClose?.();
|
|
88
|
+
};
|
|
89
|
+
this.#socketRef.onerror = (event) => {
|
|
90
|
+
onError?.(event);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
exports.default = Auth;
|
package/dist/constants.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.API_ENDPOINTS = {
|
|
|
38
38
|
SCANNING: "/scanning",
|
|
39
39
|
RECOMMENDATION: "/recommendation",
|
|
40
40
|
TRY_ON_SHARE: "/tryon/share",
|
|
41
|
+
DEVICE_INFO: "/deviceinfo"
|
|
41
42
|
};
|
|
42
43
|
exports.requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
43
44
|
exports.REQUIRED_MESSAGE = "Please verify required parameters";
|
package/dist/esm/auth.js
CHANGED
|
@@ -13,6 +13,15 @@ var _Auth_socketRef, _Auth_accessKey, _Auth_stagingUrl;
|
|
|
13
13
|
import axios from "axios";
|
|
14
14
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
15
15
|
import { checkParameters, getUrl } from "./utils.js";
|
|
16
|
+
// Conditionally import ws for Node.js
|
|
17
|
+
let WebSocketClient;
|
|
18
|
+
if (typeof window !== "undefined" && window.WebSocket) {
|
|
19
|
+
WebSocketClient = window.WebSocket;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const WS = require("ws");
|
|
23
|
+
WebSocketClient = WS;
|
|
24
|
+
}
|
|
16
25
|
class Auth {
|
|
17
26
|
constructor(accessKey, stagingUrl = false) {
|
|
18
27
|
_Auth_socketRef.set(this, void 0);
|
|
@@ -62,23 +71,33 @@ class Auth {
|
|
|
62
71
|
}
|
|
63
72
|
if (__classPrivateFieldGet(this, _Auth_socketRef, "f"))
|
|
64
73
|
__classPrivateFieldGet(this, _Auth_socketRef, "f").close();
|
|
65
|
-
__classPrivateFieldSet(this, _Auth_socketRef, new
|
|
74
|
+
__classPrivateFieldSet(this, _Auth_socketRef, new WebSocketClient(`${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: __classPrivateFieldGet(this, _Auth_stagingUrl, "f") })}${API_ENDPOINTS.AUTH}`), "f");
|
|
66
75
|
const detailObj = { email, scanId };
|
|
67
|
-
__classPrivateFieldGet(this, _Auth_socketRef, "f")
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
if (__classPrivateFieldGet(this, _Auth_socketRef, "f")) {
|
|
77
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onopen = () => {
|
|
78
|
+
var _a;
|
|
79
|
+
(_a = __classPrivateFieldGet(this, _Auth_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(detailObj));
|
|
80
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
81
|
+
};
|
|
82
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onmessage = (event) => {
|
|
83
|
+
let data;
|
|
84
|
+
try {
|
|
85
|
+
data = JSON.parse(event.data);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.log(data, error, "noy correct format for data");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
data = JSON.parse(event.data);
|
|
92
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
93
|
+
};
|
|
94
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onclose = () => {
|
|
95
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
96
|
+
};
|
|
97
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onerror = (event) => {
|
|
98
|
+
onError === null || onError === void 0 ? void 0 : onError(event);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
}
|
|
84
103
|
_Auth_socketRef = new WeakMap(), _Auth_accessKey = new WeakMap(), _Auth_stagingUrl = new WeakMap();
|
package/dist/esm/constants.js
CHANGED
|
@@ -35,6 +35,7 @@ export const API_ENDPOINTS = {
|
|
|
35
35
|
SCANNING: "/scanning",
|
|
36
36
|
RECOMMENDATION: "/recommendation",
|
|
37
37
|
TRY_ON_SHARE: "/tryon/share",
|
|
38
|
+
DEVICE_INFO: "/deviceinfo"
|
|
38
39
|
};
|
|
39
40
|
export const requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
40
41
|
export const REQUIRED_MESSAGE = "Please verify required parameters";
|
package/dist/esm/fileUpload.d.ts
CHANGED
|
@@ -8,16 +8,17 @@ interface ObjMetaData {
|
|
|
8
8
|
clothes_fit: string;
|
|
9
9
|
scan_type?: string;
|
|
10
10
|
callback_url: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
11
|
+
}
|
|
12
|
+
interface SetDeviceInfo {
|
|
13
|
+
detection?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
gyro: {
|
|
16
|
+
alpha?: string;
|
|
17
|
+
gamma?: string;
|
|
18
|
+
beta?: string;
|
|
19
|
+
timestamp?: string;
|
|
20
|
+
}[];
|
|
21
|
+
scanId: string;
|
|
21
22
|
}
|
|
22
23
|
interface UploadOptions {
|
|
23
24
|
file: File;
|
|
@@ -30,5 +31,6 @@ export default class FileUpload {
|
|
|
30
31
|
constructor(accessKey: string, stagingUrl?: boolean);
|
|
31
32
|
uploadFileFrontend({ file, arrayMetaData, scanId, email }: UploadOptions): Promise<unknown>;
|
|
32
33
|
uploadFile({ file, arrayMetaData, scanId, email }: UploadOptions): Promise<unknown>;
|
|
34
|
+
setDeviceInfo(data: SetDeviceInfo): Promise<import("axios").AxiosResponse<any, any>>;
|
|
33
35
|
}
|
|
34
36
|
export {};
|
package/dist/esm/fileUpload.js
CHANGED
|
@@ -18,9 +18,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
20
|
};
|
|
21
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
21
32
|
var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
|
|
22
33
|
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";
|
|
34
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, API_ENDPOINTS, } from "./constants.js";
|
|
24
35
|
import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
|
|
25
36
|
import Uppy from "@uppy/core";
|
|
26
37
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
@@ -172,6 +183,17 @@ class FileUpload {
|
|
|
172
183
|
}));
|
|
173
184
|
});
|
|
174
185
|
}
|
|
186
|
+
setDeviceInfo(data) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const { scanId } = data, rest = __rest(data, ["scanId"]);
|
|
189
|
+
if (checkParameters(scanId) === false) {
|
|
190
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
191
|
+
}
|
|
192
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") })}${API_ENDPOINTS.DEVICE_INFO}/${scanId}`, { device_info: Object.assign({}, rest) }, {
|
|
193
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
175
197
|
}
|
|
176
198
|
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
|
|
177
199
|
export default FileUpload;
|
package/dist/esm/measurement.js
CHANGED
|
@@ -22,6 +22,15 @@ var _Measurement_instances, _Measurement_tryOnSocketRef, _Measurement_measuremen
|
|
|
22
22
|
import axios from "axios";
|
|
23
23
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
24
24
|
import { checkParameters, getUrl } from "./utils.js";
|
|
25
|
+
let WebSocketClient;
|
|
26
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
27
|
+
WebSocketClient = window.WebSocket;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const WS = require('ws');
|
|
31
|
+
console.log(WS);
|
|
32
|
+
WebSocketClient = WS;
|
|
33
|
+
}
|
|
25
34
|
class Measurement {
|
|
26
35
|
constructor(accessKey, stagingUrl = false) {
|
|
27
36
|
_Measurement_instances.add(this);
|
|
@@ -68,25 +77,34 @@ class Measurement {
|
|
|
68
77
|
urlName: APP_BASE_WEBSOCKET_URL,
|
|
69
78
|
stagingUrl: __classPrivateFieldGet(this, _Measurement_stagingUrl, "f"),
|
|
70
79
|
})}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
71
|
-
__classPrivateFieldSet(this, _Measurement_tryOnSocketRef, new
|
|
72
|
-
__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f")
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
__classPrivateFieldSet(this, _Measurement_tryOnSocketRef, new WebSocketClient(url), "f");
|
|
81
|
+
if (__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f")) {
|
|
82
|
+
__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onopen = () => {
|
|
83
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
84
|
+
};
|
|
85
|
+
__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onmessage = (event) => {
|
|
86
|
+
let data;
|
|
87
|
+
try {
|
|
88
|
+
data = JSON.parse(event.data);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.log(data, error, "noy correct format for data");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if ((data === null || data === void 0 ? void 0 : data.tryOnProcessStatus) === "available") {
|
|
95
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
onError === null || onError === void 0 ? void 0 : onError({ message: "failed to get image urls" });
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onclose = () => {
|
|
102
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
103
|
+
};
|
|
104
|
+
__classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onerror = (event) => {
|
|
105
|
+
onError === null || onError === void 0 ? void 0 : onError(event);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
90
108
|
}
|
|
91
109
|
handleMeasurementSocket(options) {
|
|
92
110
|
const { scanId, onError, onSuccess, onClose, onOpen } = options;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -22,6 +22,16 @@ var _TryOn_instances, _TryOn_tryOnSocketRef, _TryOn_timerWaitingRef, _TryOn_acce
|
|
|
22
22
|
import axios from "axios";
|
|
23
23
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, REQUIRED_MESSAGE } from "./constants.js";
|
|
24
24
|
import { checkParameters, getUrl, isValidEmail } from "./utils.js";
|
|
25
|
+
// Conditionally import ws for Node.js
|
|
26
|
+
let WebSocketClient;
|
|
27
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
28
|
+
WebSocketClient = window.WebSocket;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const WS = require('ws');
|
|
32
|
+
console.log(WS);
|
|
33
|
+
WebSocketClient = WS;
|
|
34
|
+
}
|
|
25
35
|
class TryOn {
|
|
26
36
|
constructor(accessKey, stagingUrl = false) {
|
|
27
37
|
_TryOn_instances.add(this);
|
|
@@ -51,32 +61,44 @@ class TryOn {
|
|
|
51
61
|
}
|
|
52
62
|
__classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
|
|
53
63
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
54
|
-
__classPrivateFieldSet(this, _TryOn_tryOnSocketRef, new
|
|
55
|
-
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
64
|
+
__classPrivateFieldSet(this, _TryOn_tryOnSocketRef, new WebSocketClient(url), "f");
|
|
65
|
+
if (__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f")) {
|
|
66
|
+
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onopen = () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
68
|
+
__classPrivateFieldGet(this, _TryOn_handleTimeOut, "f").call(this, { onSuccess, onError, shopDomain, userEmail, productName });
|
|
69
|
+
});
|
|
70
|
+
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onmessage = (event) => {
|
|
71
|
+
let data;
|
|
72
|
+
try {
|
|
73
|
+
data = JSON.parse(event.data);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.log(data, error, "noy correct format for data");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if ((data === null || data === void 0 ? void 0 : data.status) === "success") {
|
|
80
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
onError === null || onError === void 0 ? void 0 : onError(data);
|
|
84
|
+
}
|
|
85
|
+
if (__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f")) {
|
|
86
|
+
clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onclose = () => {
|
|
90
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
91
|
+
};
|
|
92
|
+
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onerror = (event) => {
|
|
93
|
+
onError === null || onError === void 0 ? void 0 : onError(event);
|
|
94
|
+
if (__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f")) {
|
|
95
|
+
clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.log("no connection made for websocket");
|
|
101
|
+
}
|
|
80
102
|
};
|
|
81
103
|
_TryOn_handleGetTryOnResult.set(this, (_a) => __awaiter(this, [_a], void 0, function* ({ onSuccess, onError, shopDomain, userEmail, productName }) {
|
|
82
104
|
try {
|
package/dist/fileUpload.d.ts
CHANGED
|
@@ -8,16 +8,17 @@ interface ObjMetaData {
|
|
|
8
8
|
clothes_fit: string;
|
|
9
9
|
scan_type?: string;
|
|
10
10
|
callback_url: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
11
|
+
}
|
|
12
|
+
interface SetDeviceInfo {
|
|
13
|
+
detection?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
gyro: {
|
|
16
|
+
alpha?: string;
|
|
17
|
+
gamma?: string;
|
|
18
|
+
beta?: string;
|
|
19
|
+
timestamp?: string;
|
|
20
|
+
}[];
|
|
21
|
+
scanId: string;
|
|
21
22
|
}
|
|
22
23
|
interface UploadOptions {
|
|
23
24
|
file: File;
|
|
@@ -30,5 +31,6 @@ export default class FileUpload {
|
|
|
30
31
|
constructor(accessKey: string, stagingUrl?: boolean);
|
|
31
32
|
uploadFileFrontend({ file, arrayMetaData, scanId, email }: UploadOptions): Promise<unknown>;
|
|
32
33
|
uploadFile({ file, arrayMetaData, scanId, email }: UploadOptions): Promise<unknown>;
|
|
34
|
+
setDeviceInfo(data: SetDeviceInfo): Promise<import("axios").AxiosResponse<any, any>>;
|
|
33
35
|
}
|
|
34
36
|
export {};
|
package/dist/fileUpload.js
CHANGED
|
@@ -151,5 +151,14 @@ class FileUpload {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
+
async setDeviceInfo(data) {
|
|
155
|
+
const { scanId, ...rest } = data;
|
|
156
|
+
if ((0, utils_js_1.checkParameters)(scanId) === false) {
|
|
157
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
158
|
+
}
|
|
159
|
+
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.DEVICE_INFO}/${scanId}`, { device_info: { ...rest } }, {
|
|
160
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
161
|
+
});
|
|
162
|
+
}
|
|
154
163
|
}
|
|
155
164
|
exports.default = FileUpload;
|
package/dist/measurement.js
CHANGED
|
@@ -6,6 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const constants_js_1 = require("./constants.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
|
+
let WebSocketClient;
|
|
10
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
11
|
+
WebSocketClient = window.WebSocket;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const WS = require('ws');
|
|
15
|
+
console.log(WS);
|
|
16
|
+
WebSocketClient = WS;
|
|
17
|
+
}
|
|
9
18
|
class Measurement {
|
|
10
19
|
#tryOnSocketRef = null;
|
|
11
20
|
#measurementSocketRef = null;
|
|
@@ -50,25 +59,34 @@ class Measurement {
|
|
|
50
59
|
urlName: constants_js_1.APP_BASE_WEBSOCKET_URL,
|
|
51
60
|
stagingUrl: this.#stagingUrl,
|
|
52
61
|
})}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
53
|
-
this.#tryOnSocketRef = new
|
|
54
|
-
this.#tryOnSocketRef
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
this.#tryOnSocketRef = new WebSocketClient(url);
|
|
63
|
+
if (this.#tryOnSocketRef) {
|
|
64
|
+
this.#tryOnSocketRef.onopen = () => {
|
|
65
|
+
onOpen?.();
|
|
66
|
+
};
|
|
67
|
+
this.#tryOnSocketRef.onmessage = (event) => {
|
|
68
|
+
let data;
|
|
69
|
+
try {
|
|
70
|
+
data = JSON.parse(event.data);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.log(data, error, "noy correct format for data");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (data?.tryOnProcessStatus === "available") {
|
|
77
|
+
onSuccess?.(data);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
onError?.({ message: "failed to get image urls" });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
this.#tryOnSocketRef.onclose = () => {
|
|
84
|
+
onClose?.();
|
|
85
|
+
};
|
|
86
|
+
this.#tryOnSocketRef.onerror = (event) => {
|
|
87
|
+
onError?.(event);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
72
90
|
}
|
|
73
91
|
async #getMeasurementsCheck(options) {
|
|
74
92
|
const { scanId, onSuccess, onError } = options;
|
package/dist/tryOn.js
CHANGED
|
@@ -6,6 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const constants_js_1 = require("./constants.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
|
+
// Conditionally import ws for Node.js
|
|
10
|
+
let WebSocketClient;
|
|
11
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
12
|
+
WebSocketClient = window.WebSocket;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const WS = require('ws');
|
|
16
|
+
console.log(WS);
|
|
17
|
+
WebSocketClient = WS;
|
|
18
|
+
}
|
|
9
19
|
class TryOn {
|
|
10
20
|
#tryOnSocketRef = null;
|
|
11
21
|
#timerWaitingRef = null;
|
|
@@ -115,32 +125,44 @@ class TryOn {
|
|
|
115
125
|
}
|
|
116
126
|
this.#disconnectSocket();
|
|
117
127
|
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}`;
|
|
118
|
-
this.#tryOnSocketRef = new
|
|
119
|
-
this.#tryOnSocketRef
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
128
|
+
this.#tryOnSocketRef = new WebSocketClient(url);
|
|
129
|
+
if (this.#tryOnSocketRef) {
|
|
130
|
+
this.#tryOnSocketRef.onopen = async () => {
|
|
131
|
+
onOpen?.();
|
|
132
|
+
this.#handleTimeOut({ onSuccess, onError, shopDomain, userEmail, productName });
|
|
133
|
+
};
|
|
134
|
+
this.#tryOnSocketRef.onmessage = (event) => {
|
|
135
|
+
let data;
|
|
136
|
+
try {
|
|
137
|
+
data = JSON.parse(event.data);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.log(data, error, "noy correct format for data");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (data?.status === "success") {
|
|
144
|
+
onSuccess?.(data);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
onError?.(data);
|
|
148
|
+
}
|
|
149
|
+
if (this.#timerWaitingRef) {
|
|
150
|
+
clearTimeout(this.#timerWaitingRef);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
this.#tryOnSocketRef.onclose = () => {
|
|
154
|
+
onClose?.();
|
|
155
|
+
};
|
|
156
|
+
this.#tryOnSocketRef.onerror = (event) => {
|
|
157
|
+
onError?.(event);
|
|
158
|
+
if (this.#timerWaitingRef) {
|
|
159
|
+
clearTimeout(this.#timerWaitingRef);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
console.log("no connection made for websocket");
|
|
165
|
+
}
|
|
144
166
|
};
|
|
145
167
|
handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }) {
|
|
146
168
|
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.42",
|
|
4
4
|
"description": "provides ai measurement suggestion",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"@uppy/aws-s3-multipart": "^3.11.1",
|
|
18
18
|
"@uppy/core": "^3.11.3",
|
|
19
19
|
"axios": "^1.6.7",
|
|
20
|
+
"fix-esm": "^1.0.1",
|
|
20
21
|
"socket.io": "^4.7.5",
|
|
21
22
|
"socket.io-client": "^4.7.5",
|
|
22
23
|
"tslib": "^2.6.2",
|
|
23
24
|
"typescript": "^5.4.5",
|
|
24
|
-
"
|
|
25
|
+
"ws": "^8.18.0"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"start": "nodemon dist/index.js",
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
},
|
|
54
55
|
"homepage": "https://github.com/Syze/swan-ai-measurements.git#readme",
|
|
55
56
|
"devDependencies": {
|
|
57
|
+
"@types/ws": "^8.5.12",
|
|
56
58
|
"nodemon": "^3.1.0"
|
|
57
59
|
}
|
|
58
60
|
}
|
package/src/auth.ts
CHANGED
|
@@ -2,115 +2,133 @@ import axios, { AxiosResponse } from "axios";
|
|
|
2
2
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
3
|
import { checkParameters, getUrl } from "./utils.js";
|
|
4
4
|
|
|
5
|
+
// Conditionally import ws for Node.js
|
|
6
|
+
let WebSocketClient: any;
|
|
7
|
+
if (typeof window !== "undefined" && window.WebSocket) {
|
|
8
|
+
WebSocketClient = window.WebSocket;
|
|
9
|
+
} else {
|
|
10
|
+
const WS = require("ws");
|
|
11
|
+
WebSocketClient = WS;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
interface RegisterUserParams {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
email: string;
|
|
16
|
+
appVerifyUrl: string;
|
|
17
|
+
gender?: string;
|
|
18
|
+
height?: number;
|
|
19
|
+
username?: string;
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
interface AddUserParams {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
scanId: string;
|
|
24
|
+
email: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
height: number;
|
|
27
|
+
gender: string;
|
|
28
|
+
offsetMarketingConsent?: boolean;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
interface AuthSocketParams {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
email: string;
|
|
33
|
+
scanId: string;
|
|
34
|
+
onError?: (event: Event) => void;
|
|
35
|
+
onSuccess?: (data: any) => void;
|
|
36
|
+
onClose?: () => void;
|
|
37
|
+
onOpen?: () => void;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
interface AuthSocketDetail {
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
email: string;
|
|
42
|
+
scanId: string;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
export default class Auth {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
46
|
+
#socketRef?: WebSocket;
|
|
47
|
+
#accessKey: string;
|
|
48
|
+
#stagingUrl: boolean;
|
|
49
|
+
|
|
50
|
+
constructor(accessKey: string, stagingUrl = false) {
|
|
51
|
+
this.#accessKey = accessKey;
|
|
52
|
+
this.#stagingUrl = stagingUrl;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerUser({ email, appVerifyUrl, gender, height, username }: RegisterUserParams): Promise<AxiosResponse> {
|
|
56
|
+
if (!checkParameters(email, appVerifyUrl)) {
|
|
57
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
58
|
+
}
|
|
59
|
+
let body: Record<string, any> = { username, email, appVerifyUrl };
|
|
60
|
+
if (gender && height) {
|
|
61
|
+
body = { ...body, attributes: { gender, height } };
|
|
62
|
+
}
|
|
63
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
64
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
verifyToken(token: string): Promise<AxiosResponse> {
|
|
69
|
+
if (!checkParameters(token)) {
|
|
70
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
71
|
+
}
|
|
72
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
73
|
+
params: { token },
|
|
74
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }: AddUserParams): Promise<AxiosResponse> {
|
|
79
|
+
if (!checkParameters(scanId, email, height, gender)) {
|
|
80
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
81
|
+
}
|
|
82
|
+
return axios.post(
|
|
83
|
+
`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.ADD_USER}`,
|
|
84
|
+
{ scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) },
|
|
85
|
+
{ headers: { "X-Api-Key": this.#accessKey } },
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getUserDetail(email: string): Promise<AxiosResponse> {
|
|
90
|
+
if (!checkParameters(email)) {
|
|
91
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
92
|
+
}
|
|
93
|
+
return axios.get(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
94
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }: AuthSocketParams): void {
|
|
99
|
+
if (!checkParameters(email, scanId)) {
|
|
100
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
101
|
+
}
|
|
102
|
+
if (this.#socketRef) this.#socketRef.close();
|
|
103
|
+
|
|
104
|
+
this.#socketRef = new WebSocketClient(`${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.AUTH}`);
|
|
105
|
+
const detailObj: AuthSocketDetail = { email, scanId };
|
|
106
|
+
if (this.#socketRef) {
|
|
107
|
+
this.#socketRef.onopen = () => {
|
|
108
|
+
this.#socketRef?.send(JSON.stringify(detailObj));
|
|
109
|
+
onOpen?.();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
this.#socketRef.onmessage = (event: MessageEvent) => {
|
|
113
|
+
let data;
|
|
114
|
+
try {
|
|
115
|
+
data = JSON.parse(event.data);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.log(data, error, "noy correct format for data");
|
|
118
|
+
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
data = JSON.parse(event.data);
|
|
122
|
+
onSuccess?.(data);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
this.#socketRef.onclose = () => {
|
|
126
|
+
onClose?.();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
this.#socketRef.onerror = (event: Event) => {
|
|
130
|
+
onError?.(event);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
116
134
|
}
|
package/src/constants.ts
CHANGED
package/src/fileUpload.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
FILE_UPLOAD_ENDPOINT,
|
|
6
6
|
APP_AUTH_BASE_URL,
|
|
7
7
|
REQUIRED_ERROR_MESSAGE_INVALID_EMAIL,
|
|
8
|
+
API_ENDPOINTS,
|
|
8
9
|
} from "./constants.js";
|
|
9
10
|
import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
|
|
10
11
|
import Uppy from "@uppy/core";
|
|
@@ -19,7 +20,13 @@ interface ObjMetaData {
|
|
|
19
20
|
clothes_fit: string;
|
|
20
21
|
scan_type?: string;
|
|
21
22
|
callback_url: string;
|
|
22
|
-
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface SetDeviceInfo {
|
|
26
|
+
detection?: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
gyro: { alpha?: string; gamma?: string; beta?: string; timestamp?: string }[];
|
|
29
|
+
scanId:string
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
interface UploadOptions {
|
|
@@ -119,7 +126,6 @@ export default class FileUpload {
|
|
|
119
126
|
});
|
|
120
127
|
});
|
|
121
128
|
}
|
|
122
|
-
|
|
123
129
|
async uploadFile({ file, arrayMetaData, scanId, email }: UploadOptions) {
|
|
124
130
|
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
125
131
|
throw new Error(REQUIRED_MESSAGE);
|
|
@@ -179,4 +185,13 @@ export default class FileUpload {
|
|
|
179
185
|
}
|
|
180
186
|
});
|
|
181
187
|
}
|
|
188
|
+
async setDeviceInfo(data:SetDeviceInfo) {
|
|
189
|
+
const {scanId,...rest} = data;
|
|
190
|
+
if (checkParameters(scanId) === false) {
|
|
191
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
192
|
+
}
|
|
193
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.DEVICE_INFO}/${scanId}`,{device_info:{...rest}} , {
|
|
194
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
195
|
+
});
|
|
196
|
+
}
|
|
182
197
|
}
|
package/src/measurement.ts
CHANGED
|
@@ -2,6 +2,14 @@ import axios, { AxiosResponse } from "axios";
|
|
|
2
2
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
3
|
import { checkParameters, getUrl } from "./utils.js";
|
|
4
4
|
|
|
5
|
+
let WebSocketClient: any;
|
|
6
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
7
|
+
WebSocketClient = window.WebSocket;
|
|
8
|
+
} else {
|
|
9
|
+
const WS = require('ws');
|
|
10
|
+
console.log(WS);
|
|
11
|
+
WebSocketClient = WS;
|
|
12
|
+
}
|
|
5
13
|
interface TryOnSocketOptions {
|
|
6
14
|
shopDomain: string;
|
|
7
15
|
scanId: string;
|
|
@@ -101,28 +109,37 @@ class Measurement {
|
|
|
101
109
|
urlName: APP_BASE_WEBSOCKET_URL,
|
|
102
110
|
stagingUrl: this.#stagingUrl,
|
|
103
111
|
})}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
104
|
-
this.#tryOnSocketRef = new
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
this.#tryOnSocketRef = new WebSocketClient(url);
|
|
113
|
+
if (this.#tryOnSocketRef) {
|
|
114
|
+
this.#tryOnSocketRef.onopen = () => {
|
|
115
|
+
onOpen?.();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
this.#tryOnSocketRef.onmessage = (event) => {
|
|
119
|
+
let data;
|
|
120
|
+
try {
|
|
121
|
+
data = JSON.parse(event.data);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.log(data, error, "noy correct format for data");
|
|
124
|
+
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (data?.tryOnProcessStatus === "available") {
|
|
128
|
+
onSuccess?.(data);
|
|
129
|
+
} else {
|
|
130
|
+
onError?.({ message: "failed to get image urls" });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
this.#tryOnSocketRef.onclose = () => {
|
|
135
|
+
onClose?.();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
this.#tryOnSocketRef.onerror = (event) => {
|
|
139
|
+
onError?.(event);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
async #getMeasurementsCheck(options: GetMeasurementsCheckOptions): Promise<void> {
|
package/src/tryOn.ts
CHANGED
|
@@ -2,6 +2,16 @@ import axios, { AxiosResponse } from "axios";
|
|
|
2
2
|
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_WEBSOCKET_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
3
|
import { checkParameters, getUrl, isValidEmail } from "./utils.js";
|
|
4
4
|
|
|
5
|
+
// Conditionally import ws for Node.js
|
|
6
|
+
let WebSocketClient: any;
|
|
7
|
+
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
8
|
+
WebSocketClient = window.WebSocket;
|
|
9
|
+
} else {
|
|
10
|
+
const WS = require('ws');
|
|
11
|
+
console.log(WS);
|
|
12
|
+
WebSocketClient = WS;
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
interface UploadFileParams {
|
|
6
16
|
files: File[];
|
|
7
17
|
userEmail: string;
|
|
@@ -166,31 +176,43 @@ class TryOn {
|
|
|
166
176
|
}
|
|
167
177
|
this.#disconnectSocket();
|
|
168
178
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
169
|
-
this.#tryOnSocketRef = new
|
|
170
|
-
this.#tryOnSocketRef
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
179
|
+
this.#tryOnSocketRef = new WebSocketClient(url);
|
|
180
|
+
if(this.#tryOnSocketRef){
|
|
181
|
+
this.#tryOnSocketRef.onopen = async () => {
|
|
182
|
+
onOpen?.();
|
|
183
|
+
this.#handleTimeOut({ onSuccess, onError, shopDomain, userEmail, productName });
|
|
184
|
+
};
|
|
185
|
+
this.#tryOnSocketRef.onmessage = (event) => {
|
|
186
|
+
let data;
|
|
187
|
+
try {
|
|
188
|
+
data = JSON.parse(event.data);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.log(data, error, "noy correct format for data");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (data?.status === "success") {
|
|
194
|
+
onSuccess?.(data);
|
|
195
|
+
} else {
|
|
196
|
+
onError?.(data);
|
|
197
|
+
}
|
|
198
|
+
if (this.#timerWaitingRef) {
|
|
199
|
+
clearTimeout(this.#timerWaitingRef);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
this.#tryOnSocketRef.onclose = () => {
|
|
203
|
+
onClose?.();
|
|
204
|
+
};
|
|
205
|
+
this.#tryOnSocketRef.onerror = (event) => {
|
|
206
|
+
onError?.(event);
|
|
207
|
+
if (this.#timerWaitingRef) {
|
|
208
|
+
clearTimeout(this.#timerWaitingRef);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}else{
|
|
212
|
+
console.log("no connection made for websocket");
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
194
216
|
};
|
|
195
217
|
|
|
196
218
|
handleTryOnSubmit({
|