@swan-admin/swan-ai-measurements 1.1.42 → 1.1.44
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 +2 -2
- package/dist/esm/auth.js +1 -1
- package/dist/esm/measurement.js +1 -2
- package/dist/esm/tryOn.d.ts +2 -1
- package/dist/esm/tryOn.js +11 -11
- package/dist/measurement.js +2 -3
- package/dist/tryOn.d.ts +2 -1
- package/dist/tryOn.js +12 -11
- package/package.json +1 -1
- package/src/auth.ts +2 -2
- package/src/measurement.ts +1 -2
- package/src/tryOn.ts +33 -31
- package/tsconfig.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -6,14 +6,14 @@ 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
|
+
const ws_1 = __importDefault(require("ws"));
|
|
9
10
|
// Conditionally import ws for Node.js
|
|
10
11
|
let WebSocketClient;
|
|
11
12
|
if (typeof window !== "undefined" && window.WebSocket) {
|
|
12
13
|
WebSocketClient = window.WebSocket;
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
15
|
-
|
|
16
|
-
WebSocketClient = WS;
|
|
16
|
+
WebSocketClient = ws_1.default;
|
|
17
17
|
}
|
|
18
18
|
class Auth {
|
|
19
19
|
#socketRef;
|
package/dist/esm/auth.js
CHANGED
|
@@ -13,13 +13,13 @@ 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
|
+
import WS from "ws";
|
|
16
17
|
// Conditionally import ws for Node.js
|
|
17
18
|
let WebSocketClient;
|
|
18
19
|
if (typeof window !== "undefined" && window.WebSocket) {
|
|
19
20
|
WebSocketClient = window.WebSocket;
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
|
-
const WS = require("ws");
|
|
23
23
|
WebSocketClient = WS;
|
|
24
24
|
}
|
|
25
25
|
class Auth {
|
package/dist/esm/measurement.js
CHANGED
|
@@ -22,13 +22,12 @@ 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
|
+
import WS from "ws";
|
|
25
26
|
let WebSocketClient;
|
|
26
27
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
27
28
|
WebSocketClient = window.WebSocket;
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
const WS = require('ws');
|
|
31
|
-
console.log(WS);
|
|
32
31
|
WebSocketClient = WS;
|
|
33
32
|
}
|
|
34
33
|
class Measurement {
|
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
|
@@ -22,14 +22,12 @@ 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
|
-
|
|
25
|
+
import WS from "ws";
|
|
26
26
|
let WebSocketClient;
|
|
27
27
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
28
28
|
WebSocketClient = window.WebSocket;
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
const WS = require('ws');
|
|
32
|
-
console.log(WS);
|
|
33
31
|
WebSocketClient = WS;
|
|
34
32
|
}
|
|
35
33
|
class TryOn {
|
|
@@ -130,25 +128,27 @@ class TryOn {
|
|
|
130
128
|
__classPrivateFieldSet(this, _TryOn_stagingUrl, stagingUrl, "f");
|
|
131
129
|
}
|
|
132
130
|
uploadFile(_a) {
|
|
133
|
-
return __awaiter(this, arguments, void 0, function* ({ files, userEmail }) {
|
|
134
|
-
var _b;
|
|
131
|
+
return __awaiter(this, arguments, void 0, function* ({ files, userEmail, fileNoLimit = 2 }) {
|
|
135
132
|
if (checkParameters(files, userEmail) === false) {
|
|
136
133
|
throw new Error(REQUIRED_MESSAGE);
|
|
137
134
|
}
|
|
138
135
|
if (!isValidEmail(userEmail.trim())) {
|
|
139
136
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
140
137
|
}
|
|
141
|
-
if (
|
|
142
|
-
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.`);
|
|
143
143
|
}
|
|
144
144
|
try {
|
|
145
145
|
const payload = {
|
|
146
146
|
userEmail,
|
|
147
|
-
userImages: [
|
|
147
|
+
userImages: [],
|
|
148
148
|
};
|
|
149
|
-
|
|
150
|
-
payload.userImages.push(
|
|
151
|
-
}
|
|
149
|
+
files === null || files === void 0 ? void 0 : files.forEach((file) => {
|
|
150
|
+
payload.userImages.push(file.name);
|
|
151
|
+
});
|
|
152
152
|
const signedUrlRes = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_getSignedUrl).call(this, payload);
|
|
153
153
|
for (const file of files) {
|
|
154
154
|
yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
|
package/dist/measurement.js
CHANGED
|
@@ -6,14 +6,13 @@ 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
|
+
const ws_1 = __importDefault(require("ws"));
|
|
9
10
|
let WebSocketClient;
|
|
10
11
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
11
12
|
WebSocketClient = window.WebSocket;
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
|
-
|
|
15
|
-
console.log(WS);
|
|
16
|
-
WebSocketClient = WS;
|
|
15
|
+
WebSocketClient = ws_1.default;
|
|
17
16
|
}
|
|
18
17
|
class Measurement {
|
|
19
18
|
#tryOnSocketRef = null;
|
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
|
@@ -6,15 +6,13 @@ 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
|
-
|
|
9
|
+
const ws_1 = __importDefault(require("ws"));
|
|
10
10
|
let WebSocketClient;
|
|
11
11
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
12
12
|
WebSocketClient = window.WebSocket;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
|
|
16
|
-
console.log(WS);
|
|
17
|
-
WebSocketClient = WS;
|
|
15
|
+
WebSocketClient = ws_1.default;
|
|
18
16
|
}
|
|
19
17
|
class TryOn {
|
|
20
18
|
#tryOnSocketRef = null;
|
|
@@ -25,24 +23,27 @@ class TryOn {
|
|
|
25
23
|
this.#accessKey = accessKey;
|
|
26
24
|
this.#stagingUrl = stagingUrl;
|
|
27
25
|
}
|
|
28
|
-
async uploadFile({ files, userEmail }) {
|
|
26
|
+
async uploadFile({ files, userEmail, fileNoLimit = 2 }) {
|
|
29
27
|
if ((0, utils_js_1.checkParameters)(files, userEmail) === false) {
|
|
30
28
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
31
29
|
}
|
|
32
30
|
if (!(0, utils_js_1.isValidEmail)(userEmail.trim())) {
|
|
33
31
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
34
32
|
}
|
|
35
|
-
if (
|
|
36
|
-
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.`);
|
|
37
38
|
}
|
|
38
39
|
try {
|
|
39
40
|
const payload = {
|
|
40
41
|
userEmail,
|
|
41
|
-
userImages: [
|
|
42
|
+
userImages: [],
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
-
payload.userImages.push(
|
|
45
|
-
}
|
|
44
|
+
files?.forEach((file) => {
|
|
45
|
+
payload.userImages.push(file.name);
|
|
46
|
+
});
|
|
46
47
|
const signedUrlRes = await this.#getSignedUrl(payload);
|
|
47
48
|
for (const file of files) {
|
|
48
49
|
await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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
|
-
|
|
4
|
+
import WS from "ws";
|
|
5
5
|
// Conditionally import ws for Node.js
|
|
6
6
|
let WebSocketClient: any;
|
|
7
7
|
if (typeof window !== "undefined" && window.WebSocket) {
|
|
8
8
|
WebSocketClient = window.WebSocket;
|
|
9
9
|
} else {
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
WebSocketClient = WS;
|
|
12
12
|
}
|
|
13
13
|
|
package/src/measurement.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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";
|
|
4
5
|
|
|
5
6
|
let WebSocketClient: any;
|
|
6
7
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
7
8
|
WebSocketClient = window.WebSocket;
|
|
8
9
|
} else {
|
|
9
|
-
const WS = require('ws');
|
|
10
|
-
console.log(WS);
|
|
11
10
|
WebSocketClient = WS;
|
|
12
11
|
}
|
|
13
12
|
interface TryOnSocketOptions {
|
package/src/tryOn.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
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";
|
|
4
5
|
|
|
5
|
-
// Conditionally import ws for Node.js
|
|
6
6
|
let WebSocketClient: any;
|
|
7
7
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
8
8
|
WebSocketClient = window.WebSocket;
|
|
9
9
|
} else {
|
|
10
|
-
const WS = require('ws');
|
|
11
|
-
console.log(WS);
|
|
12
10
|
WebSocketClient = WS;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
interface UploadFileParams {
|
|
16
14
|
files: File[];
|
|
17
15
|
userEmail: string;
|
|
16
|
+
fileNoLimit?:number
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
interface DeleteImageParams {
|
|
21
20
|
userEmail: string;
|
|
22
21
|
fileName: string;
|
|
22
|
+
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
interface HandleTryOnWebSocketParams {
|
|
@@ -66,35 +66,37 @@ class TryOn {
|
|
|
66
66
|
this.#stagingUrl = stagingUrl;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
async uploadFile({ files, userEmail }: UploadFileParams): Promise<string> {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
async uploadFile({ files, userEmail,fileNoLimit=2 }: UploadFileParams): Promise<string> {
|
|
70
|
+
if (checkParameters(files, userEmail) === false) {
|
|
71
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
72
|
+
}
|
|
73
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
|
-
|
|
74
|
+
if (!isValidEmail(userEmail.trim())) {
|
|
75
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
76
|
+
}
|
|
77
|
+
if (fileNoLimit<=0) {
|
|
78
|
+
throw new Error(`Provide valid file number limit ${fileNoLimit}.`);
|
|
79
|
+
}
|
|
80
|
+
if (files?.length > fileNoLimit) {
|
|
81
|
+
throw new Error(`Cannot allow more than ${fileNoLimit} files.`);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const payload :{ userEmail: string; userImages: string[] } = {
|
|
85
|
+
userEmail,
|
|
86
|
+
userImages: [],
|
|
87
|
+
};
|
|
88
|
+
files?.forEach((file:File)=>{
|
|
89
|
+
payload.userImages.push(file.name)
|
|
90
|
+
})
|
|
91
|
+
const signedUrlRes = await this.#getSignedUrl(payload);
|
|
92
|
+
for (const file of files) {
|
|
93
|
+
await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
94
|
+
}
|
|
95
|
+
return `uploaded successfully!`;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
98
100
|
|
|
99
101
|
#getSignedUrl(payload: { userEmail: string; userImages: string[] }): Promise<AxiosResponse<any>> {
|
|
100
102
|
if (checkParameters(payload) === false) {
|