@swan-admin/swan-ai-measurements 1.1.43 → 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.
@@ -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 ((files === null || files === void 0 ? void 0 : files.length) > 2) {
140
- throw new Error("Cannot allow more than 2 files.");
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: [(_b = files[0]) === null || _b === void 0 ? void 0 : _b.name],
147
+ userImages: [],
146
148
  };
147
- if (files[1]) {
148
- payload.userImages.push(files[1].name);
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 (files?.length > 2) {
34
- throw new Error("Cannot allow more than 2 files.");
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: [files[0]?.name],
42
+ userImages: [],
40
43
  };
41
- if (files[1]) {
42
- payload.userImages.push(files[1].name);
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.43",
3
+ "version": "1.1.44",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/tryOn.ts CHANGED
@@ -13,11 +13,13 @@ if (typeof window !== 'undefined' && window.WebSocket) {
13
13
  interface UploadFileParams {
14
14
  files: File[];
15
15
  userEmail: string;
16
+ fileNoLimit?:number
16
17
  }
17
18
 
18
19
  interface DeleteImageParams {
19
20
  userEmail: string;
20
21
  fileName: string;
22
+
21
23
  }
22
24
 
23
25
  interface HandleTryOnWebSocketParams {
@@ -64,35 +66,37 @@ class TryOn {
64
66
  this.#stagingUrl = stagingUrl;
65
67
  }
66
68
 
67
- async uploadFile({ files, userEmail }: UploadFileParams): Promise<string> {
68
- if (checkParameters(files, userEmail) === false) {
69
- throw new Error(REQUIRED_MESSAGE);
70
- }
69
+ async uploadFile({ files, userEmail,fileNoLimit=2 }: UploadFileParams): Promise<string> {
70
+ if (checkParameters(files, userEmail) === false) {
71
+ throw new Error(REQUIRED_MESSAGE);
72
+ }
71
73
 
72
- if (!isValidEmail(userEmail.trim())) {
73
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
74
- }
75
-
76
- if (files?.length > 2) {
77
- throw new Error("Cannot allow more than 2 files.");
78
- }
79
- try {
80
- const payload = {
81
- userEmail,
82
- userImages: [files[0]?.name],
83
- };
84
- if (files[1]) {
85
- payload.userImages.push(files[1].name);
86
- }
87
- const signedUrlRes = await this.#getSignedUrl(payload);
88
- for (const file of files) {
89
- await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
90
- }
91
- return `uploaded successfully!`;
92
- } catch (error) {
93
- throw error;
94
- }
95
- }
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
+ }
96
100
 
97
101
  #getSignedUrl(payload: { userEmail: string; userImages: string[] }): Promise<AxiosResponse<any>> {
98
102
  if (checkParameters(payload) === false) {