@swan-admin/swan-ai-measurements 1.1.21 → 1.1.23

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/Readme.md CHANGED
@@ -1,33 +1,33 @@
1
- ## SWAN Node.js Library
2
-
3
- Swan is an AI Fitting Room that lets shoppers size & try on clothes virtually. For clothing brands and online retailers, Swan powers completely personalised sales – increasing conversion & reducing expensive returns.
4
-
5
- ## Documentation
6
-
7
- See the <a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
8
-
9
- ## Requirements
10
-
11
- Node 20 or higher.
12
-
13
- ## Usage
14
-
15
- ##### Installation
16
-
17
- npm i @swan-admin/swan-ai-measurements
18
-
19
- ##### Create Customer
20
-
21
- swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
22
-
23
- ##### Upload file
24
-
25
- swan.fileUpload.uploadFile({ file, arrayMetaData, scanId })
26
-
27
- ##### Get measurements
28
-
29
- swan.measurement.getMeasurementResult(scanId)
30
-
31
- ## Support
32
-
33
- New features and bug fixes are released on the latest major version of the SWAN package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
1
+ ## SWAN Node.js Library
2
+
3
+ Swan is an AI Fitting Room that lets shoppers size & try on clothes virtually. For clothing brands and online retailers, Swan powers completely personalised sales – increasing conversion & reducing expensive returns.
4
+
5
+ ## Documentation
6
+
7
+ See the <a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
8
+
9
+ ## Requirements
10
+
11
+ Node 20 or higher.
12
+
13
+ ## Usage
14
+
15
+ ##### Installation
16
+
17
+ npm i @swan-admin/swan-ai-measurements
18
+
19
+ ##### Create Customer
20
+
21
+ swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
22
+
23
+ ##### Upload file
24
+
25
+ swan.fileUpload.uploadFile({ file, arrayMetaData, scanId })
26
+
27
+ ##### Get measurements
28
+
29
+ swan.measurement.getMeasurementResult(scanId)
30
+
31
+ ## Support
32
+
33
+ New features and bug fixes are released on the latest major version of the SWAN package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
package/dist/constants.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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;
4
4
  exports.STAGING_URL = {
5
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
6
- APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
5
+ APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
6
+ APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
7
7
  APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
8
8
  };
9
9
  exports.PROD_URL = {
@@ -1,6 +1,6 @@
1
1
  export const STAGING_URL = {
2
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
3
- APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
2
+ APP_AUTH_BASE_URL: "https://develop.api.getswan.co",
3
+ APP_BASE_WEBSOCKET_URL: "wss://develop.wsnotify.api.getswan.co",
4
4
  APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
5
5
  };
6
6
  export const PROD_URL = {
@@ -1,177 +1,221 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value);
9
+ });
10
+ }
3
11
  return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator["throw"](value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ }
26
+ function step(result) {
27
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
28
+ }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
30
  });
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
+ };
32
+ var __classPrivateFieldSet =
33
+ (this && this.__classPrivateFieldSet) ||
34
+ function (receiver, state, value, kind, f) {
11
35
  if (kind === "m") throw new TypeError("Private method is not writable");
12
36
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
37
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
38
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
+ return kind === "a" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;
40
+ };
41
+ var __classPrivateFieldGet =
42
+ (this && this.__classPrivateFieldGet) ||
43
+ function (receiver, state, kind, f) {
17
44
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
45
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
46
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
47
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
48
+ };
21
49
  var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
22
50
  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";
24
- import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
25
- import Uppy from "@uppy/core";
51
+ import {
52
+ REQUIRED_MESSAGE,
53
+ REQUIRED_MESSAGE_FOR_META_DATA,
54
+ FILE_UPLOAD_ENDPOINT,
55
+ APP_AUTH_BASE_URL,
56
+ REQUIRED_ERROR_MESSAGE_INVALID_EMAIL,
57
+ } from "./constants.js";
58
+ import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
59
+ import Uppy from "@uppy/core";
26
60
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
27
61
  class FileUpload {
28
- constructor(accessKey, stagingUrl = false) {
29
- _FileUpload_uppyIns.set(this, void 0);
30
- _FileUpload_accessKey.set(this, void 0);
31
- _FileUpload_stagingUrl.set(this, void 0);
32
- __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
33
- __classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
34
- }
35
- uploadFileFrontend(_a) {
36
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
37
- if (!checkParameters(file, arrayMetaData, scanId)) {
38
- throw new Error(REQUIRED_MESSAGE);
39
- }
40
- if (!checkMetaDataValue(arrayMetaData)) {
41
- throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
42
- }
43
- if (!email.trim()) {
44
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
45
- }
46
- arrayMetaData = addScanType(arrayMetaData, scanId, email);
47
- return new Promise((resolve, reject) => {
48
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
49
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
50
- }
51
- __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
52
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
53
- limit: 10,
54
- retryDelays: [0, 1000, 3000, 5000],
55
- companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
56
- getChunkSize: () => 5 * 1024 * 1024,
57
- createMultipartUpload: (file) => {
58
- const objectKey = `${scanId}.${file.extension}`;
59
- return fetchData({
60
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
61
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
62
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
63
- body: {
64
- objectKey,
65
- contentType: file.type,
66
- objectMetadata: arrayMetaData,
67
- },
68
- });
69
- },
70
- completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
71
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
72
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
73
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
74
- body: {
75
- uploadId,
76
- objectKey: key,
77
- parts,
78
- originalFileName: file.name,
79
- },
80
- }),
81
- signPart: (file, partData) => fetchData({
82
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
83
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
84
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
85
- body: {
86
- objectKey: partData.key,
87
- uploadId: partData.uploadId,
88
- partNumber: partData.partNumber,
89
- },
90
- }),
91
- });
92
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
93
- source: "manual",
94
- name: file.name,
95
- type: file.type,
96
- data: file,
97
- });
98
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
99
- reject(error);
100
- });
101
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
102
- resolve({ message: "file uploaded successfully" });
103
- });
104
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
105
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
106
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
107
- }
108
- });
62
+ constructor(accessKey, stagingUrl = false) {
63
+ _FileUpload_uppyIns.set(this, void 0);
64
+ _FileUpload_accessKey.set(this, void 0);
65
+ _FileUpload_stagingUrl.set(this, void 0);
66
+ __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
67
+ __classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
68
+ }
69
+ uploadFileFrontend(_a) {
70
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
71
+ email = email.trim();
72
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
73
+ throw new Error(REQUIRED_MESSAGE);
74
+ }
75
+ if (!isValidEmail(email)) {
76
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
77
+ }
78
+ if (!checkMetaDataValue(arrayMetaData)) {
79
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
80
+ }
81
+ arrayMetaData = addScanType(arrayMetaData, scanId, email);
82
+ return new Promise((resolve, reject) => {
83
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
84
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
85
+ }
86
+ __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
87
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
88
+ limit: 10,
89
+ retryDelays: [0, 1000, 3000, 5000],
90
+ companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
91
+ getChunkSize: () => 5 * 1024 * 1024,
92
+ createMultipartUpload: (file) => {
93
+ const objectKey = `${scanId}.${file.extension}`;
94
+ return fetchData({
95
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
96
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
97
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
98
+ body: {
99
+ objectKey,
100
+ contentType: file.type,
101
+ objectMetadata: arrayMetaData,
102
+ },
109
103
  });
104
+ },
105
+ completeMultipartUpload: (file, { uploadId, key, parts }) =>
106
+ fetchData({
107
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
108
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
109
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
110
+ body: {
111
+ uploadId,
112
+ objectKey: key,
113
+ parts,
114
+ originalFileName: file.name,
115
+ },
116
+ }),
117
+ signPart: (file, partData) =>
118
+ fetchData({
119
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
120
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
121
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
122
+ body: {
123
+ objectKey: partData.key,
124
+ uploadId: partData.uploadId,
125
+ partNumber: partData.partNumber,
126
+ },
127
+ }),
110
128
  });
111
- }
112
- uploadFile(_a) {
113
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
114
- if (!checkParameters(file, arrayMetaData, scanId)) {
115
- throw new Error(REQUIRED_MESSAGE);
116
- }
117
- if (!checkMetaDataValue(arrayMetaData)) {
118
- throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
119
- }
120
- if (!email.trim()) {
121
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
122
- }
123
- arrayMetaData = addScanType(arrayMetaData, scanId, email);
124
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
125
- var _b;
126
- try {
127
- const res = yield fetchData({
128
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
129
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
130
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
131
- body: {
132
- objectKey: file.name,
133
- contentType: file.type,
134
- objectMetadata: arrayMetaData,
135
- },
136
- throwError: true,
137
- });
138
- const totalChunks = getFileChunks(file);
139
- const parts = [];
140
- for (let i = 0; i < totalChunks.length; i++) {
141
- const data = yield fetchData({
142
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
143
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
144
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
145
- body: {
146
- objectKey: res === null || res === void 0 ? void 0 : res.key,
147
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
148
- partNumber: i + 1,
149
- },
150
- throwError: true,
151
- });
152
- const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") } });
153
- parts.push({ PartNumber: i + 1, ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag });
154
- }
155
- const completeValue = yield fetchData({
156
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
157
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
158
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
159
- body: {
160
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
161
- objectKey: res === null || res === void 0 ? void 0 : res.key,
162
- parts,
163
- originalFileName: file.name,
164
- },
165
- throwError: true,
166
- });
167
- resolve({ message: "successfully uploaded", data: completeValue });
168
- }
169
- catch (error) {
170
- reject(error);
171
- }
172
- }));
129
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
130
+ source: "manual",
131
+ name: file.name,
132
+ type: file.type,
133
+ data: file,
173
134
  });
174
- }
135
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
136
+ reject(error);
137
+ });
138
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
139
+ resolve({ message: "file uploaded successfully" });
140
+ });
141
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
142
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
143
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
144
+ }
145
+ });
146
+ });
147
+ });
148
+ }
149
+ uploadFile(_a) {
150
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
151
+ email = email.trim();
152
+ if (!checkParameters(file, arrayMetaData, scanId, email)) {
153
+ throw new Error(REQUIRED_MESSAGE);
154
+ }
155
+ if (!isValidEmail(email)) {
156
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
157
+ }
158
+ if (!checkMetaDataValue(arrayMetaData)) {
159
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
160
+ }
161
+ arrayMetaData = addScanType(arrayMetaData, scanId, email);
162
+ return new Promise((resolve, reject) =>
163
+ __awaiter(this, void 0, void 0, function* () {
164
+ var _b;
165
+ try {
166
+ const res = yield fetchData({
167
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
168
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
169
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
170
+ body: {
171
+ objectKey: file.name,
172
+ contentType: file.type,
173
+ objectMetadata: arrayMetaData,
174
+ },
175
+ throwError: true,
176
+ });
177
+ const totalChunks = getFileChunks(file);
178
+ const parts = [];
179
+ for (let i = 0; i < totalChunks.length; i++) {
180
+ const data = yield fetchData({
181
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
182
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
183
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
184
+ body: {
185
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
186
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
187
+ partNumber: i + 1,
188
+ },
189
+ throwError: true,
190
+ });
191
+ const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
192
+ headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
193
+ });
194
+ parts.push({
195
+ PartNumber: i + 1,
196
+ ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag,
197
+ });
198
+ }
199
+ const completeValue = yield fetchData({
200
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
201
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
202
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
203
+ body: {
204
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
205
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
206
+ parts,
207
+ originalFileName: file.name,
208
+ },
209
+ throwError: true,
210
+ });
211
+ resolve({ message: "successfully uploaded", data: completeValue });
212
+ } catch (error) {
213
+ reject(error);
214
+ }
215
+ })
216
+ );
217
+ });
218
+ }
175
219
  }
176
- _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
220
+ (_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap()), (_FileUpload_stagingUrl = new WeakMap());
177
221
  export default FileUpload;
@@ -37,7 +37,7 @@ declare class TryOn {
37
37
  getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
38
38
  deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
39
39
  handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
40
- handleSumbmitTryOn: ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }: HandleForLatestImageParams) => Promise<any>;
40
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
41
41
  getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
42
42
  }
43
43
  export default TryOn;
package/dist/esm/tryOn.js CHANGED
@@ -75,44 +75,7 @@ class TryOn {
75
75
  }
76
76
  };
77
77
  };
78
- this.handleSumbmitTryOn = (_a) => __awaiter(this, [_a], void 0, function* ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }) {
79
- var _b;
80
- userEmail = userEmail.trim();
81
- if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
82
- throw new Error(REQUIRED_MESSAGE);
83
- }
84
- if (!isValidEmail(userEmail)) {
85
- throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
86
- }
87
- try {
88
- const payload = {
89
- productName,
90
- userEmail,
91
- customerStoreUrl: shopDomain,
92
- selectedUserImages: [
93
- firstImageName,
94
- secondImageName
95
- ]
96
- };
97
- const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
98
- const res = yield axios.post(url, payload, {
99
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
100
- });
101
- if (((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.tryOnProcessStatus) === "failed") {
102
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
103
- throw res.data;
104
- }
105
- else {
106
- return res.data;
107
- }
108
- }
109
- catch (error) {
110
- onError === null || onError === void 0 ? void 0 : onError(error);
111
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
112
- throw error;
113
- }
114
- });
115
- _TryOn_handleGetTryOnResult.set(this, (_c) => __awaiter(this, [_c], void 0, function* ({ onSuccess, onError, shopDomain, userEmail, productName }) {
78
+ _TryOn_handleGetTryOnResult.set(this, (_a) => __awaiter(this, [_a], void 0, function* ({ onSuccess, onError, shopDomain, userEmail, productName }) {
116
79
  try {
117
80
  const data = yield this.getTryOnResult({ shopDomain, userEmail, productName });
118
81
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data.data);
@@ -183,7 +146,7 @@ class TryOn {
183
146
  throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
184
147
  }
185
148
  const payload = {
186
- userEmail
149
+ userEmail,
187
150
  };
188
151
  return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}`, payload, {
189
152
  headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
@@ -199,11 +162,30 @@ class TryOn {
199
162
  }
200
163
  const payload = {
201
164
  userEmail,
202
- file: fileName
165
+ file: fileName,
203
166
  };
204
167
  return axios.delete(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_IMAGE_URLS}`, {
205
168
  headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
206
- data: payload
169
+ data: payload,
170
+ });
171
+ }
172
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }) {
173
+ userEmail = userEmail.trim();
174
+ if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
175
+ throw new Error(REQUIRED_MESSAGE);
176
+ }
177
+ if (!isValidEmail(userEmail)) {
178
+ throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
179
+ }
180
+ const payload = {
181
+ productName,
182
+ userEmail,
183
+ customerStoreUrl: shopDomain,
184
+ selectedUserImages: [firstImageName, secondImageName],
185
+ };
186
+ const url = `${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}`;
187
+ return axios.post(url, payload, {
188
+ headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
207
189
  });
208
190
  }
209
191
  }
@@ -17,15 +17,16 @@ class FileUpload {
17
17
  this.#stagingUrl = stagingUrl;
18
18
  }
19
19
  async uploadFileFrontend({ file, arrayMetaData, scanId, email }) {
20
- if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
20
+ email = email.trim();
21
+ if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
21
22
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
22
23
  }
24
+ if (!(0, utils_js_1.isValidEmail)(email)) {
25
+ throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
26
+ }
23
27
  if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
24
28
  throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
25
29
  }
26
- if (!email.trim()) {
27
- throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
28
- }
29
30
  arrayMetaData = (0, utils_js_1.addScanType)(arrayMetaData, scanId, email);
30
31
  return new Promise((resolve, reject) => {
31
32
  if (this.#uppyIns) {
@@ -92,15 +93,16 @@ class FileUpload {
92
93
  });
93
94
  }
94
95
  async uploadFile({ file, arrayMetaData, scanId, email }) {
95
- if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
96
+ email = email.trim();
97
+ if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
96
98
  throw new Error(constants_js_1.REQUIRED_MESSAGE);
97
99
  }
100
+ if (!(0, utils_js_1.isValidEmail)(email)) {
101
+ throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
102
+ }
98
103
  if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
99
104
  throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
100
105
  }
101
- if (!email.trim()) {
102
- throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
103
- }
104
106
  arrayMetaData = (0, utils_js_1.addScanType)(arrayMetaData, scanId, email);
105
107
  return new Promise(async (resolve, reject) => {
106
108
  try {
package/dist/tryOn.d.ts CHANGED
@@ -37,7 +37,7 @@ declare class TryOn {
37
37
  getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
38
38
  deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
39
39
  handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
40
- handleSumbmitTryOn: ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }: HandleForLatestImageParams) => Promise<any>;
40
+ handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
41
41
  getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
42
42
  }
43
43
  export default TryOn;