@swan-admin/swan-ai-measurements 1.1.63 → 1.1.65

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.
@@ -12,7 +12,7 @@ export declare const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBS
12
12
  export declare const API_ENDPOINTS: {
13
13
  [key: string]: string;
14
14
  };
15
- export interface ObjMetaData {
15
+ export interface BodyScanObjMetaData {
16
16
  gender: string;
17
17
  scan_id?: string;
18
18
  email: string;
@@ -23,10 +23,21 @@ export interface ObjMetaData {
23
23
  scan_type?: string;
24
24
  callback_url: string;
25
25
  }
26
- type RequiredMetaDataKeys = keyof ObjMetaData;
26
+ export interface FaceScanObjMetaData {
27
+ gender: string;
28
+ face_scan_id: string;
29
+ email?: string;
30
+ focal_length: string;
31
+ height: string;
32
+ customer_store_url: string;
33
+ scan_type: string;
34
+ callback_url: string;
35
+ }
36
+ export type RequiredMetaDataKeys = "gender" | "focal_length" | "height" | "customer_store_url" | "callback_url" | "clothes_fit";
37
+ export type RequiredFaceScanMetaDataKeys = "gender" | "focal_length" | "customer_store_url" | "scan_type" | "callback_url" | "face_scan_id";
27
38
  export declare const requiredMetaData: RequiredMetaDataKeys[];
39
+ export declare const requiredFaceScanMetaData: RequiredFaceScanMetaDataKeys[];
28
40
  export declare const REQUIRED_MESSAGE: string;
29
41
  export declare const REQUIRED_MESSAGE_FOR_META_DATA: string;
30
42
  export declare const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
31
43
  export declare const CHUNK_SIZE: number;
32
- export {};
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CHUNK_SIZE = exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredMetaData = exports.API_ENDPOINTS = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_BASE_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.FILE_UPLOAD_ENDPOINT = exports.PROD_URL = exports.STAGING_URL = void 0;
3
+ exports.CHUNK_SIZE = exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredFaceScanMetaData = exports.requiredMetaData = exports.API_ENDPOINTS = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_BASE_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.FILE_UPLOAD_ENDPOINT = exports.PROD_URL = exports.STAGING_URL = void 0;
4
4
  exports.STAGING_URL = {
5
5
  APP_AUTH_BASE_URL: "https://staging.api.swanvision.ai",
6
6
  APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.swanvision.ai",
@@ -42,6 +42,7 @@ exports.API_ENDPOINTS = {
42
42
  TRY_ON_PRODUCT_IMAGE_ELIGIBILTY: "/tryon/product-image-eligibility"
43
43
  };
44
44
  exports.requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
45
+ exports.requiredFaceScanMetaData = ["gender", "focal_length", "customer_store_url", "scan_type", "callback_url", "face_scan_id"];
45
46
  exports.REQUIRED_MESSAGE = "Please verify required parameters";
46
47
  exports.REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
47
48
  exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
@@ -12,7 +12,7 @@ export declare const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBS
12
12
  export declare const API_ENDPOINTS: {
13
13
  [key: string]: string;
14
14
  };
15
- export interface ObjMetaData {
15
+ export interface BodyScanObjMetaData {
16
16
  gender: string;
17
17
  scan_id?: string;
18
18
  email: string;
@@ -23,10 +23,21 @@ export interface ObjMetaData {
23
23
  scan_type?: string;
24
24
  callback_url: string;
25
25
  }
26
- type RequiredMetaDataKeys = keyof ObjMetaData;
26
+ export interface FaceScanObjMetaData {
27
+ gender: string;
28
+ face_scan_id: string;
29
+ email?: string;
30
+ focal_length: string;
31
+ height: string;
32
+ customer_store_url: string;
33
+ scan_type: string;
34
+ callback_url: string;
35
+ }
36
+ export type RequiredMetaDataKeys = "gender" | "focal_length" | "height" | "customer_store_url" | "callback_url" | "clothes_fit";
37
+ export type RequiredFaceScanMetaDataKeys = "gender" | "focal_length" | "customer_store_url" | "scan_type" | "callback_url" | "face_scan_id";
27
38
  export declare const requiredMetaData: RequiredMetaDataKeys[];
39
+ export declare const requiredFaceScanMetaData: RequiredFaceScanMetaDataKeys[];
28
40
  export declare const REQUIRED_MESSAGE: string;
29
41
  export declare const REQUIRED_MESSAGE_FOR_META_DATA: string;
30
42
  export declare const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
31
43
  export declare const CHUNK_SIZE: number;
32
- export {};
@@ -39,6 +39,7 @@ export const API_ENDPOINTS = {
39
39
  TRY_ON_PRODUCT_IMAGE_ELIGIBILTY: "/tryon/product-image-eligibility"
40
40
  };
41
41
  export const requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
42
+ export const requiredFaceScanMetaData = ["gender", "focal_length", "customer_store_url", "scan_type", "callback_url", "face_scan_id"];
42
43
  export const REQUIRED_MESSAGE = "Please verify required parameters";
43
44
  export const REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
44
45
  export const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
@@ -1,14 +1,4 @@
1
- interface ObjMetaData {
2
- gender: string;
3
- scan_id?: string;
4
- email: string;
5
- focal_length: string;
6
- height: string;
7
- customer_store_url: string;
8
- clothes_fit: string;
9
- scan_type?: string;
10
- callback_url: string;
11
- }
1
+ import { BodyScanObjMetaData, FaceScanObjMetaData } from "./constants.js";
12
2
  interface SetDeviceInfo {
13
3
  detection?: string;
14
4
  model?: string;
@@ -20,23 +10,39 @@ interface SetDeviceInfo {
20
10
  }[];
21
11
  scanId: string;
22
12
  }
23
- interface UploadOptions {
13
+ interface BodyScanUploadOptions {
24
14
  file: File;
25
- arrayMetaData: Partial<ObjMetaData>[];
15
+ arrayMetaData: Partial<BodyScanObjMetaData>[];
26
16
  scanId: string;
27
17
  email: string;
28
18
  callBack?: (a: {
29
19
  eventName: string;
30
20
  message: string;
31
- scanId: string;
21
+ scanId?: string;
22
+ email?: string;
23
+ objectKey?: string;
24
+ }) => void;
25
+ }
26
+ interface FaceScanUploadOptions {
27
+ file: File;
28
+ arrayMetaData: Partial<FaceScanObjMetaData>[];
29
+ objectKey: string;
30
+ email: string;
31
+ contentType: string;
32
+ callBack?: (a: {
33
+ eventName: string;
34
+ message: string;
35
+ objectKey?: string;
32
36
  email?: string;
37
+ scanId?: string;
33
38
  }) => void;
34
39
  }
35
40
  export default class FileUpload {
36
41
  #private;
37
42
  constructor(accessKey: string, stagingUrl?: boolean);
38
- uploadFileFrontend({ file, arrayMetaData, scanId, email, callBack }: UploadOptions): Promise<unknown>;
39
- uploadFile({ file, arrayMetaData, scanId, email }: UploadOptions): Promise<unknown>;
43
+ uploadFileFrontend({ file, arrayMetaData, scanId, email, callBack }: BodyScanUploadOptions): Promise<unknown>;
44
+ faceScanFileUploader({ file, arrayMetaData, objectKey, email, callBack }: FaceScanUploadOptions): Promise<unknown>;
45
+ uploadFile({ file, arrayMetaData, scanId, email }: BodyScanUploadOptions): Promise<unknown>;
40
46
  setDeviceInfo(data: SetDeviceInfo): Promise<import("axios").AxiosResponse<any, any>>;
41
47
  }
42
48
  export {};
@@ -29,14 +29,15 @@ var __rest = (this && this.__rest) || function (s, e) {
29
29
  }
30
30
  return t;
31
31
  };
32
- var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
32
+ var _FileUpload_instances, _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl, _FileUpload_uppyFileUploader;
33
33
  import axios from "axios";
34
- import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, API_ENDPOINTS, CHUNK_SIZE } from "./constants.js";
35
- import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
34
+ import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, API_ENDPOINTS, CHUNK_SIZE, requiredFaceScanMetaData } from "./constants.js";
35
+ import { addScanType, checkMetaDataValue, checkParameters, checkValues, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
36
36
  import Uppy from "@uppy/core";
37
37
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
38
38
  class FileUpload {
39
39
  constructor(accessKey, stagingUrl = false) {
40
+ _FileUpload_instances.add(this);
40
41
  _FileUpload_uppyIns.set(this, void 0);
41
42
  _FileUpload_accessKey.set(this, void 0);
42
43
  _FileUpload_stagingUrl.set(this, void 0);
@@ -55,82 +56,175 @@ class FileUpload {
55
56
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
56
57
  }
57
58
  arrayMetaData = addScanType(arrayMetaData, scanId, email);
58
- return new Promise((resolve, reject) => {
59
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
60
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
61
- }
62
- __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
63
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
64
- limit: 10,
65
- retryDelays: [0, 1000, 3000, 5000],
66
- companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
67
- getChunkSize: () => CHUNK_SIZE,
68
- createMultipartUpload: (file) => {
69
- const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
70
- callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_start", message: `File ${file.name} will be divided into ${totalChunks} chunks`, scanId, email });
71
- const objectKey = `${scanId}.${file.extension}`;
72
- return fetchData({
73
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
74
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
75
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
76
- body: {
77
- objectKey,
78
- contentType: file.type,
79
- objectMetadata: arrayMetaData,
80
- },
81
- });
82
- },
83
- completeMultipartUpload: (file, { uploadId, key, parts }) => {
84
- callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_complete_start", message: `${parts.length} chunks of file, uploaded`, scanId, email });
85
- return fetchData({
86
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
87
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
88
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
89
- body: {
90
- uploadId,
91
- objectKey: key,
92
- parts,
93
- originalFileName: file.name,
94
- },
95
- }).then((response) => {
96
- callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_complete_end", message: `Multipart upload completed successfully`, scanId, email });
97
- return response;
98
- });
99
- },
100
- signPart: (file, partData) => fetchData({
101
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
102
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
103
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
104
- body: {
105
- objectKey: partData.key,
106
- uploadId: partData.uploadId,
107
- partNumber: partData.partNumber,
108
- },
109
- }),
110
- });
111
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
112
- source: "manual",
113
- name: file.name,
114
- type: file.type,
115
- data: file,
116
- });
117
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
118
- if (error.isNetworkError) {
119
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").retryUpload(file.id);
120
- }
121
- else {
122
- reject(error);
123
- }
124
- });
125
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
126
- resolve({ message: "file uploaded successfully" });
127
- });
128
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
129
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
130
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
131
- }
132
- });
133
- });
59
+ return __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_uppyFileUploader).call(this, { callBack, arrayMetaData, scanId, email, file });
60
+ // return new Promise((resolve, reject) => {
61
+ // if (this.#uppyIns) {
62
+ // this.#uppyIns.close();
63
+ // }
64
+ // this.#uppyIns = new Uppy({ autoProceed: true });
65
+ // this.#uppyIns.use(AwsS3Multipart, {
66
+ // limit: 10,
67
+ // retryDelays: [0, 1000, 3000, 5000],
68
+ // companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl }),
69
+ // getChunkSize: () => CHUNK_SIZE,
70
+ // createMultipartUpload: (file: any) => {
71
+ // const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
72
+ // callBack?.({eventName:"uploading_start",message:`File ${file.name} will be divided into ${totalChunks} chunks`,scanId,email})
73
+ // const objectKey = `${scanId}.${file.extension}`;
74
+ // return fetchData({
75
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
76
+ // apiKey: this.#accessKey,
77
+ // stagingUrl: this.#stagingUrl,
78
+ // body: {
79
+ // objectKey,
80
+ // contentType: file.type,
81
+ // objectMetadata: arrayMetaData,
82
+ // },
83
+ // });
84
+ // },
85
+ // completeMultipartUpload: (file: any, { uploadId, key, parts }: { uploadId: string | number; key: string | number; parts: any }) => {
86
+ // callBack?.({eventName:"uploading_complete_start",message:`${parts.length} chunks of file, uploaded`,scanId,email})
87
+ // return fetchData({
88
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
89
+ // apiKey: this.#accessKey,
90
+ // stagingUrl: this.#stagingUrl,
91
+ // body: {
92
+ // uploadId,
93
+ // objectKey: key,
94
+ // parts,
95
+ // originalFileName: file.name,
96
+ // },
97
+ // }).then((response) => {
98
+ // callBack?.({eventName:"uploading_complete_end",message:`Multipart upload completed successfully`,scanId,email})
99
+ // return response;
100
+ // });
101
+ // },
102
+ // signPart: (file: any, partData: any) =>
103
+ // fetchData({
104
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
105
+ // stagingUrl: this.#stagingUrl,
106
+ // apiKey: this.#accessKey,
107
+ // body: {
108
+ // objectKey: partData.key,
109
+ // uploadId: partData.uploadId,
110
+ // partNumber: partData.partNumber,
111
+ // },
112
+ // }),
113
+ // });
114
+ // this.#uppyIns.addFile({
115
+ // source: "manual",
116
+ // name: file.name,
117
+ // type: file.type,
118
+ // data: file,
119
+ // });
120
+ // this.#uppyIns.on("upload-error", (file: any, error: any, response: any) => {
121
+ // if (error.isNetworkError) {
122
+ // this.#uppyIns.retryUpload(file.id);
123
+ // }else{
124
+ // reject(error);
125
+ // }
126
+ // });
127
+ // this.#uppyIns.on("upload-success", () => {
128
+ // resolve({ message: "file uploaded successfully" });
129
+ // });
130
+ // this.#uppyIns.on("complete", (result: any) => {
131
+ // if (this.#uppyIns) {
132
+ // this.#uppyIns.close();
133
+ // }
134
+ // });
135
+ // });
136
+ });
137
+ }
138
+ faceScanFileUploader(_a) {
139
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, objectKey, email, callBack }) {
140
+ if (!checkParameters(file, arrayMetaData, objectKey, email)) {
141
+ throw new Error(REQUIRED_MESSAGE);
142
+ }
143
+ if (!isValidEmail(email.trim())) {
144
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
145
+ }
146
+ if (!checkValues(arrayMetaData, requiredFaceScanMetaData)) {
147
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
148
+ }
149
+ // arrayMetaData = addScanType(arrayMetaData, objectKey, email);
150
+ arrayMetaData.push({ email });
151
+ return __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_uppyFileUploader).call(this, { callBack, arrayMetaData, objectKey, email, file });
152
+ // return new Promise((resolve, reject) => {
153
+ // if (this.#uppyIns) {
154
+ // this.#uppyIns.close();
155
+ // }
156
+ // this.#uppyIns = new Uppy({ autoProceed: true });
157
+ // this.#uppyIns.use(AwsS3Multipart, {
158
+ // limit: 10,
159
+ // retryDelays: [0, 1000, 3000, 5000],
160
+ // companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl }),
161
+ // getChunkSize: () => CHUNK_SIZE,
162
+ // createMultipartUpload: (file: any) => {
163
+ // const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
164
+ // callBack?.({eventName:"uploading_start",message:`File ${file.name} will be divided into ${totalChunks} chunks`,scanId,email})
165
+ // const objectKey = `${scanId}.${file.extension}`;
166
+ // return fetchData({
167
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
168
+ // apiKey: this.#accessKey,
169
+ // stagingUrl: this.#stagingUrl,
170
+ // body: {
171
+ // objectKey,
172
+ // contentType: file.type,
173
+ // objectMetadata: arrayMetaData,
174
+ // },
175
+ // });
176
+ // },
177
+ // completeMultipartUpload: (file: any, { uploadId, key, parts }: { uploadId: string | number; key: string | number; parts: any }) => {
178
+ // callBack?.({eventName:"uploading_complete_start",message:`${parts.length} chunks of file, uploaded`,scanId,email})
179
+ // return fetchData({
180
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
181
+ // apiKey: this.#accessKey,
182
+ // stagingUrl: this.#stagingUrl,
183
+ // body: {
184
+ // uploadId,
185
+ // objectKey: key,
186
+ // parts,
187
+ // originalFileName: file.name,
188
+ // },
189
+ // }).then((response) => {
190
+ // callBack?.({eventName:"uploading_complete_end",message:`Multipart upload completed successfully`,scanId,email})
191
+ // return response;
192
+ // });
193
+ // },
194
+ // signPart: (file: any, partData: any) =>
195
+ // fetchData({
196
+ // path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
197
+ // stagingUrl: this.#stagingUrl,
198
+ // apiKey: this.#accessKey,
199
+ // body: {
200
+ // objectKey: partData.key,
201
+ // uploadId: partData.uploadId,
202
+ // partNumber: partData.partNumber,
203
+ // },
204
+ // }),
205
+ // });
206
+ // this.#uppyIns.addFile({
207
+ // source: "manual",
208
+ // name: file.name,
209
+ // type: file.type,
210
+ // data: file,
211
+ // });
212
+ // this.#uppyIns.on("upload-error", (file: any, error: any, response: any) => {
213
+ // if (error.isNetworkError) {
214
+ // this.#uppyIns.retryUpload(file.id);
215
+ // }else{
216
+ // reject(error);
217
+ // }
218
+ // });
219
+ // this.#uppyIns.on("upload-success", () => {
220
+ // resolve({ message: "file uploaded successfully" });
221
+ // });
222
+ // this.#uppyIns.on("complete", (result: any) => {
223
+ // if (this.#uppyIns) {
224
+ // this.#uppyIns.close();
225
+ // }
226
+ // });
227
+ // });
134
228
  });
135
229
  }
136
230
  uploadFile(_a) {
@@ -208,5 +302,82 @@ class FileUpload {
208
302
  });
209
303
  }
210
304
  }
211
- _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
305
+ _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap(), _FileUpload_instances = new WeakSet(), _FileUpload_uppyFileUploader = function _FileUpload_uppyFileUploader({ callBack, arrayMetaData, scanId, email, file, objectKey }) {
306
+ return new Promise((resolve, reject) => {
307
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
308
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
309
+ }
310
+ __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
311
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
312
+ limit: 10,
313
+ retryDelays: [0, 1000, 3000, 5000],
314
+ companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
315
+ getChunkSize: () => CHUNK_SIZE,
316
+ createMultipartUpload: (file) => {
317
+ const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
318
+ callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_start", message: `File ${file.name} will be divided into ${totalChunks} chunks`, scanId, email, objectKey });
319
+ const ObjectKey = `${scanId || objectKey}.${file.extension}`;
320
+ return fetchData({
321
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
322
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
323
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
324
+ body: {
325
+ objectKey: ObjectKey,
326
+ contentType: file.type,
327
+ objectMetadata: arrayMetaData,
328
+ },
329
+ });
330
+ },
331
+ completeMultipartUpload: (file, { uploadId, key, parts }) => {
332
+ callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_complete_start", message: `${parts.length} chunks of file, uploaded`, scanId, email, objectKey });
333
+ return fetchData({
334
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
335
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
336
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
337
+ body: {
338
+ uploadId,
339
+ objectKey: key,
340
+ parts,
341
+ originalFileName: file.name,
342
+ },
343
+ }).then((response) => {
344
+ callBack === null || callBack === void 0 ? void 0 : callBack({ eventName: "uploading_complete_end", message: `Multipart upload completed successfully`, scanId, email, objectKey });
345
+ return response;
346
+ });
347
+ },
348
+ signPart: (file, partData) => fetchData({
349
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
350
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
351
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
352
+ body: {
353
+ objectKey: partData.key,
354
+ uploadId: partData.uploadId,
355
+ partNumber: partData.partNumber,
356
+ },
357
+ }),
358
+ });
359
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
360
+ source: "manual",
361
+ name: file.name,
362
+ type: file.type,
363
+ data: file,
364
+ });
365
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
366
+ if (error.isNetworkError) {
367
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").retryUpload(file.id);
368
+ }
369
+ else {
370
+ reject(error);
371
+ }
372
+ });
373
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
374
+ resolve({ message: "file uploaded successfully" });
375
+ });
376
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
377
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
378
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
379
+ }
380
+ });
381
+ });
382
+ };
212
383
  export default FileUpload;
@@ -68,9 +68,12 @@ class Measurement {
68
68
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
69
69
  }
70
70
  else {
71
+ if (__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f")) {
72
+ clearTimeout(__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f"));
73
+ }
71
74
  onError === null || onError === void 0 ? void 0 : onError(data);
72
75
  }
73
- if (__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f")) {
76
+ if (__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f") && (data === null || data === void 0 ? void 0 : data.code) === 200 && (data === null || data === void 0 ? void 0 : data.scanStatus) === "success" && (data === null || data === void 0 ? void 0 : data.resultType) === "final") {
74
77
  clearTimeout(__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f"));
75
78
  }
76
79
  };
package/dist/esm/tryOn.js CHANGED
@@ -100,14 +100,6 @@ class TryOn {
100
100
  if (checkParameters(tryonId) === false) {
101
101
  throw new Error(REQUIRED_MESSAGE);
102
102
  }
103
- // if (!isValidEmail(userEmail.trim())) {
104
- // throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
105
- // }
106
- // const payload = {
107
- // products,
108
- // userEmail,
109
- // customerStoreUrl: shopDomain,
110
- // };
111
103
  const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}/${tryonId}`;
112
104
  return axios.post(url, null, {
113
105
  headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
@@ -183,9 +175,6 @@ class TryOn {
183
175
  if (checkParameters(shopDomain, userEmail, products) === false) {
184
176
  throw new Error(REQUIRED_MESSAGE);
185
177
  }
186
- // if (!selectedUserImages.length) {
187
- // throw new Error("No user images found!");
188
- // }
189
178
  if (!isValidEmail(userEmail.trim())) {
190
179
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
191
180
  }
@@ -1,4 +1,4 @@
1
- import { ObjMetaData } from "./constants.js";
1
+ import { BodyScanObjMetaData } from "./constants.js";
2
2
  export interface FetchDataOptions {
3
3
  path: string;
4
4
  body?: any;
@@ -11,8 +11,9 @@ export interface FetchDataOptions {
11
11
  }
12
12
  export declare function fetchData(options: FetchDataOptions): Promise<any>;
13
13
  export declare function checkParameters(...args: any[]): boolean;
14
- export declare function checkMetaDataValue(arr: Partial<ObjMetaData>[]): boolean;
15
- export declare const addScanType: (arr: Partial<ObjMetaData>[], scan_id: string, email: string) => Partial<ObjMetaData>[];
14
+ export declare function checkMetaDataValue(arr: Partial<BodyScanObjMetaData>[]): boolean;
15
+ export declare const checkValues: (arr: any[], requiredMetaData: any) => boolean;
16
+ export declare const addScanType: (arr: Partial<BodyScanObjMetaData>[], scan_id: string, email: string) => Partial<BodyScanObjMetaData>[];
16
17
  export declare function getFileChunks(file: File, chunkSize?: number): Blob[];
17
18
  export declare const getUrl: ({ urlName, stagingUrl }: {
18
19
  urlName: string;
package/dist/esm/utils.js CHANGED
@@ -42,17 +42,8 @@ export function checkParameters(...args) {
42
42
  return true;
43
43
  }
44
44
  export function checkMetaDataValue(arr) {
45
- for (const key of requiredMetaData) {
46
- let hasRequiredKey = false;
47
- for (const obj of arr) {
48
- if (obj.hasOwnProperty(key) && obj[key] !== undefined && obj[key] !== null && obj[key] !== "" && typeof obj[key] !== "number") {
49
- hasRequiredKey = true;
50
- break;
51
- }
52
- }
53
- if (!hasRequiredKey) {
54
- return false;
55
- }
45
+ if (!checkValues(arr, requiredMetaData)) {
46
+ return false;
56
47
  }
57
48
  let correctFormat = false;
58
49
  for (const obj of arr) {
@@ -65,6 +56,25 @@ export function checkMetaDataValue(arr) {
65
56
  }
66
57
  return true;
67
58
  }
59
+ export const checkValues = (arr, requiredMetaData) => {
60
+ for (const key of requiredMetaData) {
61
+ let hasRequiredKey = false;
62
+ for (const obj of arr) {
63
+ if (Object.prototype.hasOwnProperty.call(obj, key) &&
64
+ obj[key] !== undefined &&
65
+ obj[key] !== null &&
66
+ obj[key] !== "" &&
67
+ typeof obj[key] !== "number") {
68
+ hasRequiredKey = true;
69
+ break;
70
+ }
71
+ }
72
+ if (!hasRequiredKey) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ };
68
78
  export const addScanType = (arr, scan_id, email) => {
69
79
  const scanType = arr.find((el) => el.scan_type);
70
80
  if (!scanType) {