@swan-admin/swan-ai-measurements 1.1.43 → 1.1.45
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 +2 -1
- package/dist/esm/tryOn.js +10 -8
- package/dist/tryOn.d.ts +2 -1
- package/dist/tryOn.js +10 -7
- package/package.json +2 -3
- package/src/auth.ts +2 -10
- package/src/measurement.ts +2 -8
- package/src/tryOn.ts +35 -36
package/dist/esm/tryOn.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AxiosResponse } from "axios";
|
|
|
2
2
|
interface UploadFileParams {
|
|
3
3
|
files: File[];
|
|
4
4
|
userEmail: string;
|
|
5
|
+
fileNoLimit?: number;
|
|
5
6
|
}
|
|
6
7
|
interface DeleteImageParams {
|
|
7
8
|
userEmail: string;
|
|
@@ -33,7 +34,7 @@ interface GetTryOnResultParams {
|
|
|
33
34
|
declare class TryOn {
|
|
34
35
|
#private;
|
|
35
36
|
constructor(accessKey: string, stagingUrl?: boolean);
|
|
36
|
-
uploadFile({ files, userEmail }: UploadFileParams): Promise<string>;
|
|
37
|
+
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
37
38
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
38
39
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
39
40
|
handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -128,25 +128,27 @@ class TryOn {
|
|
|
128
128
|
__classPrivateFieldSet(this, _TryOn_stagingUrl, stagingUrl, "f");
|
|
129
129
|
}
|
|
130
130
|
uploadFile(_a) {
|
|
131
|
-
return __awaiter(this, arguments, void 0, function* ({ files, userEmail }) {
|
|
132
|
-
var _b;
|
|
131
|
+
return __awaiter(this, arguments, void 0, function* ({ files, userEmail, fileNoLimit = 2 }) {
|
|
133
132
|
if (checkParameters(files, userEmail) === false) {
|
|
134
133
|
throw new Error(REQUIRED_MESSAGE);
|
|
135
134
|
}
|
|
136
135
|
if (!isValidEmail(userEmail.trim())) {
|
|
137
136
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
138
137
|
}
|
|
139
|
-
if (
|
|
140
|
-
throw new Error(
|
|
138
|
+
if (fileNoLimit <= 0) {
|
|
139
|
+
throw new Error(`Provide valid file number limit ${fileNoLimit}.`);
|
|
140
|
+
}
|
|
141
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > fileNoLimit) {
|
|
142
|
+
throw new Error(`Cannot allow more than ${fileNoLimit} files.`);
|
|
141
143
|
}
|
|
142
144
|
try {
|
|
143
145
|
const payload = {
|
|
144
146
|
userEmail,
|
|
145
|
-
userImages: [
|
|
147
|
+
userImages: [],
|
|
146
148
|
};
|
|
147
|
-
|
|
148
|
-
payload.userImages.push(
|
|
149
|
-
}
|
|
149
|
+
files === null || files === void 0 ? void 0 : files.forEach((file) => {
|
|
150
|
+
payload.userImages.push(file.name);
|
|
151
|
+
});
|
|
150
152
|
const signedUrlRes = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_getSignedUrl).call(this, payload);
|
|
151
153
|
for (const file of files) {
|
|
152
154
|
yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
|
package/dist/tryOn.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AxiosResponse } from "axios";
|
|
|
2
2
|
interface UploadFileParams {
|
|
3
3
|
files: File[];
|
|
4
4
|
userEmail: string;
|
|
5
|
+
fileNoLimit?: number;
|
|
5
6
|
}
|
|
6
7
|
interface DeleteImageParams {
|
|
7
8
|
userEmail: string;
|
|
@@ -33,7 +34,7 @@ interface GetTryOnResultParams {
|
|
|
33
34
|
declare class TryOn {
|
|
34
35
|
#private;
|
|
35
36
|
constructor(accessKey: string, stagingUrl?: boolean);
|
|
36
|
-
uploadFile({ files, userEmail }: UploadFileParams): Promise<string>;
|
|
37
|
+
uploadFile({ files, userEmail, fileNoLimit }: UploadFileParams): Promise<string>;
|
|
37
38
|
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
38
39
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
39
40
|
handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
package/dist/tryOn.js
CHANGED
|
@@ -23,24 +23,27 @@ class TryOn {
|
|
|
23
23
|
this.#accessKey = accessKey;
|
|
24
24
|
this.#stagingUrl = stagingUrl;
|
|
25
25
|
}
|
|
26
|
-
async uploadFile({ files, userEmail }) {
|
|
26
|
+
async uploadFile({ files, userEmail, fileNoLimit = 2 }) {
|
|
27
27
|
if ((0, utils_js_1.checkParameters)(files, userEmail) === false) {
|
|
28
28
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
29
29
|
}
|
|
30
30
|
if (!(0, utils_js_1.isValidEmail)(userEmail.trim())) {
|
|
31
31
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
32
32
|
}
|
|
33
|
-
if (
|
|
34
|
-
throw new Error(
|
|
33
|
+
if (fileNoLimit <= 0) {
|
|
34
|
+
throw new Error(`Provide valid file number limit ${fileNoLimit}.`);
|
|
35
|
+
}
|
|
36
|
+
if (files?.length > fileNoLimit) {
|
|
37
|
+
throw new Error(`Cannot allow more than ${fileNoLimit} files.`);
|
|
35
38
|
}
|
|
36
39
|
try {
|
|
37
40
|
const payload = {
|
|
38
41
|
userEmail,
|
|
39
|
-
userImages: [
|
|
42
|
+
userImages: [],
|
|
40
43
|
};
|
|
41
|
-
|
|
42
|
-
payload.userImages.push(
|
|
43
|
-
}
|
|
44
|
+
files?.forEach((file) => {
|
|
45
|
+
payload.userImages.push(file.name);
|
|
46
|
+
});
|
|
44
47
|
const signedUrlRes = await this.#getSignedUrl(payload);
|
|
45
48
|
for (const file of files) {
|
|
46
49
|
await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
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.45",
|
|
4
4
|
"description": "provides ai measurement suggestion",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"socket.io": "^4.7.5",
|
|
22
22
|
"socket.io-client": "^4.7.5",
|
|
23
23
|
"tslib": "^2.6.2",
|
|
24
|
-
"typescript": "^5.4.5"
|
|
25
|
-
"ws": "^8.18.0"
|
|
24
|
+
"typescript": "^5.4.5"
|
|
26
25
|
},
|
|
27
26
|
"scripts": {
|
|
28
27
|
"start": "nodemon dist/index.js",
|
package/src/auth.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
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
|
-
|
|
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
|
-
|
|
11
|
-
WebSocketClient = WS;
|
|
12
|
-
}
|
|
4
|
+
|
|
13
5
|
|
|
14
6
|
interface RegisterUserParams {
|
|
15
7
|
email: string;
|
|
@@ -101,7 +93,7 @@ export default class Auth {
|
|
|
101
93
|
}
|
|
102
94
|
if (this.#socketRef) this.#socketRef.close();
|
|
103
95
|
|
|
104
|
-
this.#socketRef = new
|
|
96
|
+
this.#socketRef = new WebSocket(`${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.AUTH}`);
|
|
105
97
|
const detailObj: AuthSocketDetail = { email, scanId };
|
|
106
98
|
if (this.#socketRef) {
|
|
107
99
|
this.#socketRef.onopen = () => {
|
package/src/measurement.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
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
|
-
import WS from "ws";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
8
|
-
WebSocketClient = window.WebSocket;
|
|
9
|
-
} else {
|
|
10
|
-
WebSocketClient = WS;
|
|
11
|
-
}
|
|
5
|
+
|
|
12
6
|
interface TryOnSocketOptions {
|
|
13
7
|
shopDomain: string;
|
|
14
8
|
scanId: string;
|
|
@@ -108,7 +102,7 @@ class Measurement {
|
|
|
108
102
|
urlName: APP_BASE_WEBSOCKET_URL,
|
|
109
103
|
stagingUrl: this.#stagingUrl,
|
|
110
104
|
})}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
111
|
-
this.#tryOnSocketRef = new
|
|
105
|
+
this.#tryOnSocketRef = new WebSocket(url);
|
|
112
106
|
if (this.#tryOnSocketRef) {
|
|
113
107
|
this.#tryOnSocketRef.onopen = () => {
|
|
114
108
|
onOpen?.();
|
package/src/tryOn.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
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
|
-
import WS from "ws";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
WebSocketClient = window.WebSocket;
|
|
9
|
-
} else {
|
|
10
|
-
WebSocketClient = WS;
|
|
11
|
-
}
|
|
5
|
+
|
|
6
|
+
|
|
12
7
|
|
|
13
8
|
interface UploadFileParams {
|
|
14
9
|
files: File[];
|
|
15
10
|
userEmail: string;
|
|
11
|
+
fileNoLimit?:number
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
interface DeleteImageParams {
|
|
19
15
|
userEmail: string;
|
|
20
16
|
fileName: string;
|
|
17
|
+
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
interface HandleTryOnWebSocketParams {
|
|
@@ -64,35 +61,37 @@ class TryOn {
|
|
|
64
61
|
this.#stagingUrl = stagingUrl;
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
async uploadFile({ files, userEmail }: UploadFileParams): Promise<string> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!isValidEmail(userEmail.trim())) {
|
|
73
|
-
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
74
|
-
}
|
|
64
|
+
async uploadFile({ files, userEmail,fileNoLimit=2 }: UploadFileParams): Promise<string> {
|
|
65
|
+
if (checkParameters(files, userEmail) === false) {
|
|
66
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
67
|
+
}
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
if (!isValidEmail(userEmail.trim())) {
|
|
70
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
71
|
+
}
|
|
72
|
+
if (fileNoLimit<=0) {
|
|
73
|
+
throw new Error(`Provide valid file number limit ${fileNoLimit}.`);
|
|
74
|
+
}
|
|
75
|
+
if (files?.length > fileNoLimit) {
|
|
76
|
+
throw new Error(`Cannot allow more than ${fileNoLimit} files.`);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const payload :{ userEmail: string; userImages: string[] } = {
|
|
80
|
+
userEmail,
|
|
81
|
+
userImages: [],
|
|
82
|
+
};
|
|
83
|
+
files?.forEach((file:File)=>{
|
|
84
|
+
payload.userImages.push(file.name)
|
|
85
|
+
})
|
|
86
|
+
const signedUrlRes = await this.#getSignedUrl(payload);
|
|
87
|
+
for (const file of files) {
|
|
88
|
+
await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
89
|
+
}
|
|
90
|
+
return `uploaded successfully!`;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
96
95
|
|
|
97
96
|
#getSignedUrl(payload: { userEmail: string; userImages: string[] }): Promise<AxiosResponse<any>> {
|
|
98
97
|
if (checkParameters(payload) === false) {
|
|
@@ -174,7 +173,7 @@ class TryOn {
|
|
|
174
173
|
}
|
|
175
174
|
this.#disconnectSocket();
|
|
176
175
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
177
|
-
this.#tryOnSocketRef = new
|
|
176
|
+
this.#tryOnSocketRef = new WebSocket(url);
|
|
178
177
|
if(this.#tryOnSocketRef){
|
|
179
178
|
this.#tryOnSocketRef.onopen = async () => {
|
|
180
179
|
onOpen?.();
|