@swan-admin/swan-ai-measurements 1.0.65 → 1.0.66

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 CHANGED
@@ -1,28 +1,16 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
- var _Auth_socketRef, _Auth_accessKey;
17
5
  Object.defineProperty(exports, "__esModule", { value: true });
18
6
  const axios_1 = __importDefault(require("axios"));
19
7
  const constants_1 = require("./constants");
20
8
  const utils_1 = require("./utils");
21
9
  class Auth {
10
+ #socketRef;
11
+ #accessKey;
22
12
  constructor(accessKey) {
23
- _Auth_socketRef.set(this, void 0);
24
- _Auth_accessKey.set(this, void 0);
25
- __classPrivateFieldSet(this, _Auth_accessKey, accessKey, "f");
13
+ this.#accessKey = accessKey;
26
14
  }
27
15
  registerUser({ email, appVerifyUrl, gender, height, username }) {
28
16
  if (!(0, utils_1.checkParameters)(email, appVerifyUrl)) {
@@ -30,10 +18,10 @@ class Auth {
30
18
  }
31
19
  let body = { username, email, appVerifyUrl };
32
20
  if (gender && height) {
33
- body = Object.assign(Object.assign({}, body), { attributes: { gender, height } });
21
+ body = { ...body, attributes: { gender, height } };
34
22
  }
35
23
  return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.REGISTER_USER}`, body, {
36
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
24
+ headers: { "X-Api-Key": this.#accessKey },
37
25
  });
38
26
  }
39
27
  verifyToken(token) {
@@ -42,47 +30,45 @@ class Auth {
42
30
  }
43
31
  return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.VERIFY_USER}`, null, {
44
32
  params: { token },
45
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
33
+ headers: { "X-Api-Key": this.#accessKey },
46
34
  });
47
35
  }
48
36
  addUser({ scanId, email, name, height, gender, offsetMarketingConsent }) {
49
37
  if (!(0, utils_1.checkParameters)(scanId, email, height, gender)) {
50
38
  throw new Error(constants_1.REQUIRED_MESSAGE);
51
39
  }
52
- return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.ADD_USER}`, { scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) }, { headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") } });
40
+ return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.ADD_USER}`, { scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) }, { headers: { "X-Api-Key": this.#accessKey } });
53
41
  }
54
42
  getUserDetail(email) {
55
43
  if (!(0, utils_1.checkParameters)(email)) {
56
44
  throw new Error(constants_1.REQUIRED_MESSAGE);
57
45
  }
58
46
  return axios_1.default.get(`${constants_1.APP_BASE_URL}${constants_1.API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
59
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
47
+ headers: { "X-Api-Key": this.#accessKey },
60
48
  });
61
49
  }
62
50
  handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }) {
63
51
  if (!(0, utils_1.checkParameters)(email, scanId)) {
64
52
  throw new Error(constants_1.REQUIRED_MESSAGE);
65
53
  }
66
- if (__classPrivateFieldGet(this, _Auth_socketRef, "f"))
67
- __classPrivateFieldGet(this, _Auth_socketRef, "f").close();
68
- __classPrivateFieldSet(this, _Auth_socketRef, new WebSocket(`${constants_1.APP_AUTH_WEBSOCKET_URL}${constants_1.API_ENDPOINTS.AUTH}`), "f");
54
+ if (this.#socketRef)
55
+ this.#socketRef.close();
56
+ this.#socketRef = new WebSocket(`${constants_1.APP_AUTH_WEBSOCKET_URL}${constants_1.API_ENDPOINTS.AUTH}`);
69
57
  const detailObj = { email, scanId };
70
- __classPrivateFieldGet(this, _Auth_socketRef, "f").onopen = () => {
71
- var _a;
72
- (_a = __classPrivateFieldGet(this, _Auth_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(detailObj));
73
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
58
+ this.#socketRef.onopen = () => {
59
+ this.#socketRef?.send(JSON.stringify(detailObj));
60
+ onOpen?.();
74
61
  };
75
- __classPrivateFieldGet(this, _Auth_socketRef, "f").onmessage = (event) => {
62
+ this.#socketRef.onmessage = (event) => {
76
63
  const data = JSON.parse(event.data);
77
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
64
+ onSuccess?.(data);
78
65
  };
79
- __classPrivateFieldGet(this, _Auth_socketRef, "f").onclose = () => {
80
- onClose === null || onClose === void 0 ? void 0 : onClose();
66
+ this.#socketRef.onclose = () => {
67
+ onClose?.();
81
68
  };
82
- __classPrivateFieldGet(this, _Auth_socketRef, "f").onerror = (event) => {
83
- onError === null || onError === void 0 ? void 0 : onError(event);
69
+ this.#socketRef.onerror = (event) => {
70
+ onError?.(event);
84
71
  };
85
72
  }
86
73
  }
87
- _Auth_socketRef = new WeakMap(), _Auth_accessKey = new WeakMap();
88
74
  exports.default = Auth;
package/dist/custom.js CHANGED
@@ -1,43 +1,30 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
- var _Custom_accessKey;
17
5
  Object.defineProperty(exports, "__esModule", { value: true });
18
6
  const axios_1 = __importDefault(require("axios"));
19
7
  const constants_1 = require("./constants");
20
8
  const utils_1 = require("./utils");
21
9
  class Custom {
10
+ #accessKey;
22
11
  constructor(accessKey) {
23
- _Custom_accessKey.set(this, void 0);
24
- this.getCustomCustomerConfig = (store_url) => {
25
- if ((0, utils_1.checkParameters)(store_url) === false) {
26
- throw new Error(constants_1.REQUIRED_MESSAGE);
27
- }
28
- return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
29
- params: { store_url },
30
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _Custom_accessKey, "f") },
31
- });
32
- };
33
- this.getModelUrl = (id) => {
34
- if ((0, utils_1.checkParameters)(id) === false) {
35
- throw new Error(constants_1.REQUIRED_MESSAGE);
36
- }
37
- return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.MODEL}/${id}`, { headers: { "X-Api-Key": __classPrivateFieldGet(this, _Custom_accessKey, "f") } });
38
- };
39
- __classPrivateFieldSet(this, _Custom_accessKey, accessKey, "f");
12
+ this.#accessKey = accessKey;
40
13
  }
14
+ getCustomCustomerConfig = (store_url) => {
15
+ if ((0, utils_1.checkParameters)(store_url) === false) {
16
+ throw new Error(constants_1.REQUIRED_MESSAGE);
17
+ }
18
+ return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
19
+ params: { store_url },
20
+ headers: { "X-Api-Key": this.#accessKey },
21
+ });
22
+ };
23
+ getModelUrl = (id) => {
24
+ if ((0, utils_1.checkParameters)(id) === false) {
25
+ throw new Error(constants_1.REQUIRED_MESSAGE);
26
+ }
27
+ return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.MODEL}/${id}`, { headers: { "X-Api-Key": this.#accessKey } });
28
+ };
41
29
  }
42
- _Custom_accessKey = new WeakMap();
43
30
  exports.default = Custom;
@@ -7,17 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
12
- 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");
13
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14
- };
15
10
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
16
11
  if (kind === "m") throw new TypeError("Private method is not writable");
17
12
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
18
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");
19
14
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
20
15
  };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ 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");
19
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
21
  var _FileUpload_instances, _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_Uppy, _FileUpload_AwsS3Multipart, _FileUpload_initializeModules;
22
22
  import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants";
23
23
  import { checkMetaDataValue, checkParameters, fetchData } from "./utils";
@@ -28,20 +28,17 @@ class FileUpload {
28
28
  _FileUpload_accessKey.set(this, void 0);
29
29
  _FileUpload_Uppy.set(this, void 0);
30
30
  _FileUpload_AwsS3Multipart.set(this, void 0);
31
- __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
32
31
  __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
33
32
  }
34
33
  uploadFile(_a) {
35
34
  return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
36
- if (checkParameters(file, arrayMetaData, scanId) === false) {
35
+ if (!checkParameters(file, arrayMetaData, scanId)) {
37
36
  throw new Error(REQUIRED_MESSAGE);
38
37
  }
39
- if (checkMetaDataValue(arrayMetaData) === false) {
38
+ if (!checkMetaDataValue(arrayMetaData)) {
40
39
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
41
40
  }
42
- if (!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f")) {
43
- yield __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
44
- }
41
+ yield __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
45
42
  return new Promise((resolve, reject) => {
46
43
  if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
47
44
  __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
@@ -115,8 +112,12 @@ class FileUpload {
115
112
  }
116
113
  _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_Uppy = new WeakMap(), _FileUpload_AwsS3Multipart = new WeakMap(), _FileUpload_instances = new WeakSet(), _FileUpload_initializeModules = function _FileUpload_initializeModules() {
117
114
  return __awaiter(this, void 0, void 0, function* () {
118
- __classPrivateFieldSet(this, _FileUpload_Uppy, (yield import("@uppy/core")).default, "f");
119
- __classPrivateFieldSet(this, _FileUpload_AwsS3Multipart, (yield import("@uppy/aws-s3-multipart")).default, "f");
115
+ if (!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f")) {
116
+ const { default: Uppy } = yield import("@uppy/core");
117
+ const { default: AwsS3Multipart } = yield import("@uppy/aws-s3-multipart");
118
+ __classPrivateFieldSet(this, _FileUpload_Uppy, Uppy, "f");
119
+ __classPrivateFieldSet(this, _FileUpload_AwsS3Multipart, AwsS3Multipart, "f");
120
+ }
120
121
  });
121
122
  };
122
123
  export default FileUpload;
@@ -22,126 +22,101 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
35
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
36
- 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");
37
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
- };
39
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
40
- if (kind === "m") throw new TypeError("Private method is not writable");
41
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
42
- 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");
43
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
44
- };
45
- var _FileUpload_instances, _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_Uppy, _FileUpload_AwsS3Multipart, _FileUpload_initializeModules;
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  const constants_1 = require("./constants");
48
27
  const utils_1 = require("./utils");
49
28
  class FileUpload {
29
+ #uppyIns;
30
+ #accessKey;
31
+ #Uppy;
32
+ #AwsS3Multipart;
50
33
  constructor(accessKey) {
51
- _FileUpload_instances.add(this);
52
- _FileUpload_uppyIns.set(this, void 0);
53
- _FileUpload_accessKey.set(this, void 0);
54
- _FileUpload_Uppy.set(this, void 0);
55
- _FileUpload_AwsS3Multipart.set(this, void 0);
56
- __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
57
- __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
34
+ this.#accessKey = accessKey;
58
35
  }
59
- uploadFile(_a) {
60
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
61
- if ((0, utils_1.checkParameters)(file, arrayMetaData, scanId) === false) {
62
- throw new Error(constants_1.REQUIRED_MESSAGE);
63
- }
64
- if ((0, utils_1.checkMetaDataValue)(arrayMetaData) === false) {
65
- throw new Error(constants_1.REQUIRED_MESSAGE_FOR_META_DATA);
66
- }
67
- if (!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f")) {
68
- yield __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
36
+ async #initializeModules() {
37
+ if (!this.#Uppy || !this.#AwsS3Multipart) {
38
+ const { default: Uppy } = await Promise.resolve().then(() => __importStar(require("@uppy/core")));
39
+ const { default: AwsS3Multipart } = await Promise.resolve().then(() => __importStar(require("@uppy/aws-s3-multipart")));
40
+ this.#Uppy = Uppy;
41
+ this.#AwsS3Multipart = AwsS3Multipart;
42
+ }
43
+ }
44
+ async uploadFile({ file, arrayMetaData, scanId }) {
45
+ if (!(0, utils_1.checkParameters)(file, arrayMetaData, scanId)) {
46
+ throw new Error(constants_1.REQUIRED_MESSAGE);
47
+ }
48
+ if (!(0, utils_1.checkMetaDataValue)(arrayMetaData)) {
49
+ throw new Error(constants_1.REQUIRED_MESSAGE_FOR_META_DATA);
50
+ }
51
+ await this.#initializeModules();
52
+ return new Promise((resolve, reject) => {
53
+ if (this.#uppyIns) {
54
+ this.#uppyIns.close();
69
55
  }
70
- return new Promise((resolve, reject) => {
71
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
72
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
73
- }
74
- __classPrivateFieldSet(this, _FileUpload_uppyIns, new (__classPrivateFieldGet(this, _FileUpload_Uppy, "f"))({ autoProceed: true }), "f");
75
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f"), {
76
- limit: 10,
77
- retryDelays: [0, 1000, 3000, 5000],
78
- getChunkSize: () => 5 * 1024 * 1024,
79
- createMultipartUpload: (file) => {
80
- const objectKey = `${scanId}.${file.extension}`;
81
- return (0, utils_1.fetchData)({
82
- path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
83
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
84
- body: {
85
- objectKey,
86
- contentType: file.type,
87
- objectMetadata: arrayMetaData,
88
- },
89
- });
90
- },
91
- completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_1.fetchData)({
92
- path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
93
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
56
+ this.#uppyIns = new this.#Uppy({ autoProceed: true });
57
+ this.#uppyIns.use(this.#AwsS3Multipart, {
58
+ limit: 10,
59
+ retryDelays: [0, 1000, 3000, 5000],
60
+ getChunkSize: () => 5 * 1024 * 1024,
61
+ createMultipartUpload: (file) => {
62
+ const objectKey = `${scanId}.${file.extension}`;
63
+ return (0, utils_1.fetchData)({
64
+ path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
65
+ apiKey: this.#accessKey,
94
66
  body: {
95
- uploadId,
96
- objectKey: key,
97
- parts,
98
- originalFileName: file.name,
67
+ objectKey,
68
+ contentType: file.type,
69
+ objectMetadata: arrayMetaData,
99
70
  },
100
- }),
101
- signPart: (file, partData) => (0, utils_1.fetchData)({
102
- path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
103
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
104
- body: {
105
- objectKey: partData.key,
106
- uploadId: partData.uploadId,
107
- partNumber: partData.partNumber,
108
- },
109
- }),
110
- abortMultipartUpload: (file, { uploadId, key }) => (0, utils_1.fetchData)({
111
- path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
112
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
113
- body: {
114
- uploadId,
115
- objectKey: key,
116
- originalFileName: file.name,
117
- },
118
- }),
119
- });
120
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
121
- source: "manual",
122
- name: file.name,
123
- type: file.type,
124
- data: file,
125
- });
126
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
127
- reject(error);
128
- });
129
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
130
- resolve({ message: "file uploaded successfully" });
131
- });
132
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
133
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
134
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
135
- }
136
- });
71
+ });
72
+ },
73
+ completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_1.fetchData)({
74
+ path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
75
+ apiKey: this.#accessKey,
76
+ body: {
77
+ uploadId,
78
+ objectKey: key,
79
+ parts,
80
+ originalFileName: file.name,
81
+ },
82
+ }),
83
+ signPart: (file, partData) => (0, utils_1.fetchData)({
84
+ path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
85
+ apiKey: this.#accessKey,
86
+ body: {
87
+ objectKey: partData.key,
88
+ uploadId: partData.uploadId,
89
+ partNumber: partData.partNumber,
90
+ },
91
+ }),
92
+ abortMultipartUpload: (file, { uploadId, key }) => (0, utils_1.fetchData)({
93
+ path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
94
+ apiKey: this.#accessKey,
95
+ body: {
96
+ uploadId,
97
+ objectKey: key,
98
+ originalFileName: file.name,
99
+ },
100
+ }),
101
+ });
102
+ this.#uppyIns.addFile({
103
+ source: "manual",
104
+ name: file.name,
105
+ type: file.type,
106
+ data: file,
107
+ });
108
+ this.#uppyIns.on("upload-error", (file, error, response) => {
109
+ reject(error);
110
+ });
111
+ this.#uppyIns.on("upload-success", () => {
112
+ resolve({ message: "file uploaded successfully" });
113
+ });
114
+ this.#uppyIns.on("complete", (result) => {
115
+ if (this.#uppyIns) {
116
+ this.#uppyIns.close();
117
+ }
137
118
  });
138
119
  });
139
120
  }
140
121
  }
141
- _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_Uppy = new WeakMap(), _FileUpload_AwsS3Multipart = new WeakMap(), _FileUpload_instances = new WeakSet(), _FileUpload_initializeModules = function _FileUpload_initializeModules() {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- __classPrivateFieldSet(this, _FileUpload_Uppy, (yield Promise.resolve().then(() => __importStar(require("@uppy/core")))).default, "f");
144
- __classPrivateFieldSet(this, _FileUpload_AwsS3Multipart, (yield Promise.resolve().then(() => __importStar(require("@uppy/aws-s3-multipart")))).default, "f");
145
- });
146
- };
147
122
  exports.default = FileUpload;
package/dist/index.js CHANGED
@@ -1,19 +1,7 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
- var _Swan_accessKey;
17
5
  Object.defineProperty(exports, "__esModule", { value: true });
18
6
  const auth_1 = __importDefault(require("./auth"));
19
7
  const custom_1 = __importDefault(require("./custom"));
@@ -22,16 +10,21 @@ const measurement_1 = __importDefault(require("./measurement"));
22
10
  const poseDetection_1 = __importDefault(require("./poseDetection"));
23
11
  const tryOn_1 = __importDefault(require("./tryOn"));
24
12
  class Swan {
13
+ #accessKey;
14
+ auth;
15
+ custom;
16
+ fileUpload;
17
+ measurement;
18
+ poseDetection;
19
+ tryOn;
25
20
  constructor(accessKey) {
26
- _Swan_accessKey.set(this, void 0);
27
- __classPrivateFieldSet(this, _Swan_accessKey, accessKey, "f");
28
- this.auth = new auth_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
29
- this.custom = new custom_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
30
- this.fileUpload = new fileUpload_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
31
- this.measurement = new measurement_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
32
- this.poseDetection = new poseDetection_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
33
- this.tryOn = new tryOn_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
21
+ this.#accessKey = accessKey;
22
+ this.auth = new auth_1.default(this.#accessKey);
23
+ this.custom = new custom_1.default(this.#accessKey);
24
+ this.fileUpload = new fileUpload_1.default(this.#accessKey);
25
+ this.measurement = new measurement_1.default(this.#accessKey);
26
+ this.poseDetection = new poseDetection_1.default(this.#accessKey);
27
+ this.tryOn = new tryOn_1.default(this.#accessKey);
34
28
  }
35
29
  }
36
- _Swan_accessKey = new WeakMap();
37
30
  exports.default = Swan;
@@ -1,42 +1,20 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- 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");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- 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");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
- var _Measurement_instances, _Measurement_tryOnSocketRef, _Measurement_measurementSocketRef, _Measurement_timerPollingRef, _Measurement_timerWaitingRef, _Measurement_count, _Measurement_accessKey, _Measurement_getMeasurementsCheck, _Measurement_handlePolling, _Measurement_disconnectSocket, _Measurement_handleTimeOut;
26
5
  Object.defineProperty(exports, "__esModule", { value: true });
27
6
  const axios_1 = __importDefault(require("axios"));
28
7
  const constants_1 = require("./constants");
29
8
  const utils_1 = require("./utils");
30
9
  class Measurement {
10
+ #tryOnSocketRef = null;
11
+ #measurementSocketRef = null;
12
+ #timerPollingRef = null;
13
+ #timerWaitingRef = null;
14
+ #count = 1;
15
+ #accessKey;
31
16
  constructor(accessKey) {
32
- _Measurement_instances.add(this);
33
- _Measurement_tryOnSocketRef.set(this, null);
34
- _Measurement_measurementSocketRef.set(this, null);
35
- _Measurement_timerPollingRef.set(this, null);
36
- _Measurement_timerWaitingRef.set(this, null);
37
- _Measurement_count.set(this, 1);
38
- _Measurement_accessKey.set(this, void 0);
39
- __classPrivateFieldSet(this, _Measurement_accessKey, accessKey, "f");
17
+ this.#accessKey = accessKey;
40
18
  }
41
19
  getMeasurementResult(scanId) {
42
20
  if (!(0, utils_1.checkParameters)(scanId)) {
@@ -44,7 +22,7 @@ class Measurement {
44
22
  }
45
23
  const url = `${constants_1.APP_AUTH_BASE_URL}/measurements?scanId=${scanId}`;
46
24
  return axios_1.default.get(url, {
47
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _Measurement_accessKey, "f") },
25
+ headers: { "X-Api-Key": this.#accessKey },
48
26
  });
49
27
  }
50
28
  getTryOnMeasurements({ scanId, shopDomain, productName }) {
@@ -52,124 +30,121 @@ class Measurement {
52
30
  throw new Error(constants_1.REQUIRED_MESSAGE);
53
31
  }
54
32
  const tryOnUrl = `${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_SCAN}/${scanId}/shop/${shopDomain}/product/${productName}`;
55
- return axios_1.default.get(tryOnUrl, { headers: { "X-Api-Key": __classPrivateFieldGet(this, _Measurement_accessKey, "f") } });
33
+ return axios_1.default.get(tryOnUrl, { headers: { "X-Api-Key": this.#accessKey } });
56
34
  }
57
35
  handleTryOnSocket(options) {
58
- var _a;
59
36
  const { shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen } = options;
60
37
  if (!(0, utils_1.checkParameters)(shopDomain, scanId, productName)) {
61
38
  throw new Error(constants_1.REQUIRED_MESSAGE);
62
39
  }
63
- (_a = __classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f")) === null || _a === void 0 ? void 0 : _a.close();
40
+ this.#tryOnSocketRef?.close();
64
41
  const url = `${constants_1.APP_TRY_ON_WEBSOCKET_URL}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
65
- __classPrivateFieldSet(this, _Measurement_tryOnSocketRef, new WebSocket(url), "f");
66
- __classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onopen = () => {
67
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
42
+ this.#tryOnSocketRef = new WebSocket(url);
43
+ this.#tryOnSocketRef.onopen = () => {
44
+ onOpen?.();
68
45
  };
69
- __classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onmessage = (event) => {
46
+ this.#tryOnSocketRef.onmessage = (event) => {
70
47
  const data = JSON.parse(event.data);
71
- if ((data === null || data === void 0 ? void 0 : data.tryOnProcessStatus) === "available") {
72
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
48
+ if (data?.tryOnProcessStatus === "available") {
49
+ onSuccess?.(data);
73
50
  }
74
51
  else {
75
- onError === null || onError === void 0 ? void 0 : onError({ message: "failed to get image urls" });
52
+ onError?.({ message: "failed to get image urls" });
76
53
  }
77
54
  };
78
- __classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onclose = () => {
79
- onClose === null || onClose === void 0 ? void 0 : onClose();
55
+ this.#tryOnSocketRef.onclose = () => {
56
+ onClose?.();
80
57
  };
81
- __classPrivateFieldGet(this, _Measurement_tryOnSocketRef, "f").onerror = (event) => {
82
- onError === null || onError === void 0 ? void 0 : onError(event);
58
+ this.#tryOnSocketRef.onerror = (event) => {
59
+ onError?.(event);
83
60
  };
84
61
  }
62
+ async #getMeasurementsCheck(options) {
63
+ const { scanId, onSuccess, onError } = options;
64
+ try {
65
+ const res = await this.getMeasurementResult(scanId);
66
+ if (res?.data && res?.data?.isMeasured === true) {
67
+ onSuccess?.(res.data);
68
+ if (this.#timerPollingRef) {
69
+ clearInterval(this.#timerPollingRef);
70
+ }
71
+ }
72
+ else {
73
+ if (this.#count < 8) {
74
+ this.#count++;
75
+ this.#handlePolling({ scanId, onSuccess, onError });
76
+ }
77
+ else {
78
+ this.#count = 1;
79
+ if (this.#timerPollingRef) {
80
+ clearInterval(this.#timerPollingRef);
81
+ }
82
+ onError?.({ scanStatus: "failed", message: "Scan not found", isMeasured: false });
83
+ }
84
+ }
85
+ }
86
+ catch (e) {
87
+ if (this.#timerPollingRef) {
88
+ clearInterval(this.#timerPollingRef);
89
+ }
90
+ onError?.(e);
91
+ }
92
+ }
93
+ #handlePolling(options) {
94
+ const { scanId, onSuccess, onError } = options;
95
+ if (this.#timerPollingRef) {
96
+ clearInterval(this.#timerPollingRef);
97
+ }
98
+ this.#timerPollingRef = setTimeout(() => {
99
+ this.#getMeasurementsCheck({ scanId, onSuccess, onError });
100
+ }, this.#count * 5000);
101
+ }
102
+ #disconnectSocket() {
103
+ this.#measurementSocketRef?.close();
104
+ if (this.#timerWaitingRef) {
105
+ clearTimeout(this.#timerWaitingRef);
106
+ }
107
+ }
108
+ #handleTimeOut(options) {
109
+ const { scanId, onSuccess, onError } = options;
110
+ this.#count = 1;
111
+ this.#timerWaitingRef = setTimeout(() => {
112
+ this.#handlePolling({ scanId, onSuccess, onError });
113
+ this.#disconnectSocket();
114
+ }, 2 * 60000);
115
+ }
85
116
  handleMeasurementSocket(options) {
86
117
  const { scanId, onError, onSuccess, onClose, onOpen } = options;
87
118
  if (!(0, utils_1.checkParameters)(scanId)) {
88
119
  throw new Error(constants_1.REQUIRED_MESSAGE);
89
120
  }
90
121
  setTimeout(() => {
91
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_disconnectSocket).call(this);
122
+ this.#disconnectSocket();
92
123
  const url = `${constants_1.APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
93
- __classPrivateFieldSet(this, _Measurement_measurementSocketRef, new WebSocket(url), "f");
94
- __classPrivateFieldGet(this, _Measurement_measurementSocketRef, "f").onopen = () => {
95
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
96
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_handleTimeOut).call(this, { scanId, onSuccess, onError });
124
+ this.#measurementSocketRef = new WebSocket(url);
125
+ this.#measurementSocketRef.onopen = () => {
126
+ onOpen?.();
127
+ this.#handleTimeOut({ scanId, onSuccess, onError });
97
128
  };
98
- __classPrivateFieldGet(this, _Measurement_measurementSocketRef, "f").onmessage = (event) => {
129
+ this.#measurementSocketRef.onmessage = (event) => {
99
130
  const data = JSON.parse(event.data);
100
- if ((data === null || data === void 0 ? void 0 : data.code) === 200 && (data === null || data === void 0 ? void 0 : data.scanStatus) === "success") {
101
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
131
+ if (data?.code === 200 && data?.scanStatus === "success") {
132
+ onSuccess?.(data);
102
133
  }
103
134
  else {
104
- onError === null || onError === void 0 ? void 0 : onError(data);
135
+ onError?.(data);
105
136
  }
106
- if (__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f")) {
107
- clearTimeout(__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f"));
137
+ if (this.#timerWaitingRef) {
138
+ clearTimeout(this.#timerWaitingRef);
108
139
  }
109
140
  };
110
- __classPrivateFieldGet(this, _Measurement_measurementSocketRef, "f").onclose = () => {
111
- onClose === null || onClose === void 0 ? void 0 : onClose();
141
+ this.#measurementSocketRef.onclose = () => {
142
+ onClose?.();
112
143
  };
113
- __classPrivateFieldGet(this, _Measurement_measurementSocketRef, "f").onerror = (event) => {
114
- onError === null || onError === void 0 ? void 0 : onError(event);
144
+ this.#measurementSocketRef.onerror = (event) => {
145
+ onError?.(event);
115
146
  };
116
147
  }, 5000);
117
148
  }
118
149
  }
119
- _Measurement_tryOnSocketRef = new WeakMap(), _Measurement_measurementSocketRef = new WeakMap(), _Measurement_timerPollingRef = new WeakMap(), _Measurement_timerWaitingRef = new WeakMap(), _Measurement_count = new WeakMap(), _Measurement_accessKey = new WeakMap(), _Measurement_instances = new WeakSet(), _Measurement_getMeasurementsCheck = function _Measurement_getMeasurementsCheck(options) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- var _a;
122
- var _b;
123
- const { scanId, onSuccess, onError } = options;
124
- try {
125
- const res = yield this.getMeasurementResult(scanId);
126
- if ((res === null || res === void 0 ? void 0 : res.data) && ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.isMeasured) === true) {
127
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(res.data);
128
- if (__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f")) {
129
- clearInterval(__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f"));
130
- }
131
- }
132
- else {
133
- if (__classPrivateFieldGet(this, _Measurement_count, "f") < 8) {
134
- __classPrivateFieldSet(this, _Measurement_count, (_b = __classPrivateFieldGet(this, _Measurement_count, "f"), _b++, _b), "f");
135
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_handlePolling).call(this, { scanId, onSuccess, onError });
136
- }
137
- else {
138
- __classPrivateFieldSet(this, _Measurement_count, 1, "f");
139
- if (__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f")) {
140
- clearInterval(__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f"));
141
- }
142
- onError === null || onError === void 0 ? void 0 : onError({ scanStatus: "failed", message: "Scan not found", isMeasured: false });
143
- }
144
- }
145
- }
146
- catch (e) {
147
- if (__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f")) {
148
- clearInterval(__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f"));
149
- }
150
- onError === null || onError === void 0 ? void 0 : onError(e);
151
- }
152
- });
153
- }, _Measurement_handlePolling = function _Measurement_handlePolling(options) {
154
- const { scanId, onSuccess, onError } = options;
155
- if (__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f")) {
156
- clearInterval(__classPrivateFieldGet(this, _Measurement_timerPollingRef, "f"));
157
- }
158
- __classPrivateFieldSet(this, _Measurement_timerPollingRef, setTimeout(() => {
159
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_getMeasurementsCheck).call(this, { scanId, onSuccess, onError });
160
- }, __classPrivateFieldGet(this, _Measurement_count, "f") * 5000), "f");
161
- }, _Measurement_disconnectSocket = function _Measurement_disconnectSocket() {
162
- var _a;
163
- (_a = __classPrivateFieldGet(this, _Measurement_measurementSocketRef, "f")) === null || _a === void 0 ? void 0 : _a.close();
164
- if (__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f")) {
165
- clearTimeout(__classPrivateFieldGet(this, _Measurement_timerWaitingRef, "f"));
166
- }
167
- }, _Measurement_handleTimeOut = function _Measurement_handleTimeOut(options) {
168
- const { scanId, onSuccess, onError } = options;
169
- __classPrivateFieldSet(this, _Measurement_count, 1, "f");
170
- __classPrivateFieldSet(this, _Measurement_timerWaitingRef, setTimeout(() => {
171
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_handlePolling).call(this, { scanId, onSuccess, onError });
172
- __classPrivateFieldGet(this, _Measurement_instances, "m", _Measurement_disconnectSocket).call(this);
173
- }, 2 * 60000), "f");
174
- };
175
150
  exports.default = Measurement;
@@ -1,35 +1,22 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- 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");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _PoseDetection_socketRef, _PoseDetection_accessKey;
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  const socket_io_client_1 = require("socket.io-client");
16
4
  const constants_1 = require("./constants");
17
5
  class PoseDetection {
6
+ #socketRef = null;
7
+ #accessKey;
18
8
  constructor(accessKey) {
19
- _PoseDetection_socketRef.set(this, null);
20
- _PoseDetection_accessKey.set(this, void 0);
21
- __classPrivateFieldSet(this, _PoseDetection_accessKey, accessKey, "f");
9
+ this.#accessKey = accessKey;
22
10
  }
23
11
  connect() {
24
12
  return new Promise((resolve, reject) => {
25
- __classPrivateFieldSet(this, _PoseDetection_socketRef, (0, socket_io_client_1.io)(constants_1.APP_POSE_DETECTION_WEBSOCKET_URL, {
13
+ this.#socketRef = (0, socket_io_client_1.io)(constants_1.APP_POSE_DETECTION_WEBSOCKET_URL, {
26
14
  auth: {
27
- token: __classPrivateFieldGet(this, _PoseDetection_accessKey, "f"),
15
+ token: this.#accessKey,
28
16
  },
29
- }), "f");
30
- __classPrivateFieldGet(this, _PoseDetection_socketRef, "f").on("connect", () => {
31
- var _a;
32
- const socketId = (_a = __classPrivateFieldGet(this, _PoseDetection_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.id;
17
+ });
18
+ this.#socketRef.on("connect", () => {
19
+ const socketId = this.#socketRef?.id;
33
20
  if (socketId) {
34
21
  resolve(socketId);
35
22
  }
@@ -37,36 +24,33 @@ class PoseDetection {
37
24
  reject(new Error("Failed to obtain socket ID."));
38
25
  }
39
26
  });
40
- __classPrivateFieldGet(this, _PoseDetection_socketRef, "f").on("connect_error", (err) => {
27
+ this.#socketRef.on("connect_error", (err) => {
41
28
  reject(err);
42
29
  });
43
30
  });
44
31
  }
45
32
  videoEmit({ image, scanId }) {
46
- if (!__classPrivateFieldGet(this, _PoseDetection_socketRef, "f")) {
33
+ if (!this.#socketRef) {
47
34
  throw new Error("Socket is not connected");
48
35
  }
49
- __classPrivateFieldGet(this, _PoseDetection_socketRef, "f").emit("video", {
36
+ this.#socketRef.emit("video", {
50
37
  image,
51
38
  user_unique_key: scanId,
52
39
  });
53
40
  }
54
41
  disconnect() {
55
- var _a;
56
- (_a = __classPrivateFieldGet(this, _PoseDetection_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.disconnect();
42
+ this.#socketRef?.disconnect();
57
43
  }
58
44
  poseStatus(callBack) {
59
- if (!__classPrivateFieldGet(this, _PoseDetection_socketRef, "f")) {
45
+ if (!this.#socketRef) {
60
46
  throw new Error("Socket is not connected");
61
47
  }
62
- __classPrivateFieldGet(this, _PoseDetection_socketRef, "f").on("pose_status", (data) => {
63
- callBack === null || callBack === void 0 ? void 0 : callBack(data);
48
+ this.#socketRef.on("pose_status", (data) => {
49
+ callBack?.(data);
64
50
  });
65
51
  }
66
52
  connected() {
67
- var _a;
68
- return !!((_a = __classPrivateFieldGet(this, _PoseDetection_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.connected);
53
+ return !!this.#socketRef?.connected;
69
54
  }
70
55
  }
71
- _PoseDetection_socketRef = new WeakMap(), _PoseDetection_accessKey = new WeakMap();
72
56
  exports.default = PoseDetection;
package/dist/tryOn.js CHANGED
@@ -1,154 +1,50 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- 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");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- 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");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
- var _TryOn_instances, _TryOn_tryOnSocketRef, _TryOn_timerWaitingRef, _TryOn_accessKey, _TryOn_getSignedUrl, _TryOn_s3Upload, _TryOn_disconnectSocket, _TryOn_handleTimeOut, _TryOn_handleGetTryOnResult;
26
5
  Object.defineProperty(exports, "__esModule", { value: true });
27
6
  const axios_1 = __importDefault(require("axios"));
28
7
  const constants_1 = require("./constants");
29
8
  const utils_1 = require("./utils");
30
9
  class TryOn {
10
+ #tryOnSocketRef = null;
11
+ #timerWaitingRef = null;
12
+ #accessKey;
31
13
  constructor(accessKey) {
32
- _TryOn_instances.add(this);
33
- _TryOn_tryOnSocketRef.set(this, null);
34
- _TryOn_timerWaitingRef.set(this, null);
35
- _TryOn_accessKey.set(this, void 0);
36
- _TryOn_disconnectSocket.set(this, () => {
37
- var _a;
38
- (_a = __classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f")) === null || _a === void 0 ? void 0 : _a.close();
39
- if (__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f")) {
40
- clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
41
- }
42
- });
43
- _TryOn_handleTimeOut.set(this, ({ onSuccess, onError, shopDomain, userId, productName }) => {
44
- __classPrivateFieldSet(this, _TryOn_timerWaitingRef, setTimeout(() => {
45
- __classPrivateFieldGet(this, _TryOn_handleGetTryOnResult, "f").call(this, { shopDomain, userId, productName, onSuccess, onError });
46
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
47
- }, 120000), "f");
48
- });
49
- this.handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
50
- if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
51
- throw new Error(constants_1.REQUIRED_MESSAGE);
52
- }
53
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
54
- const url = `${constants_1.APP_AUTH_WEBSOCKET_URL}${constants_1.API_ENDPOINTS.TRY_ON}/?store_url=${shopDomain}&product_name=${productName}&scan_id=${userId}`;
55
- __classPrivateFieldSet(this, _TryOn_tryOnSocketRef, new WebSocket(url), "f");
56
- __classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onopen = () => __awaiter(this, void 0, void 0, function* () {
57
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
58
- __classPrivateFieldGet(this, _TryOn_handleTimeOut, "f").call(this, { onSuccess, onError, shopDomain, userId, productName });
59
- try {
60
- yield this.handleForLatestImage({ shopDomain, userId, productName, onError });
61
- }
62
- catch (error) {
63
- onError === null || onError === void 0 ? void 0 : onError(error);
64
- }
65
- });
66
- __classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onmessage = (event) => {
67
- const data = JSON.parse(event.data);
68
- if ((data === null || data === void 0 ? void 0 : data.status) === "success") {
69
- __classPrivateFieldGet(this, _TryOn_handleGetTryOnResult, "f").call(this, { shopDomain, userId, productName, onError, onSuccess });
70
- }
71
- else {
72
- onError === null || onError === void 0 ? void 0 : onError(data);
73
- }
74
- if (__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f")) {
75
- clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
76
- }
77
- };
78
- __classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onclose = () => {
79
- onClose === null || onClose === void 0 ? void 0 : onClose();
80
- };
81
- __classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onerror = (event) => {
82
- onError === null || onError === void 0 ? void 0 : onError(event);
83
- if (__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f")) {
84
- clearTimeout(__classPrivateFieldGet(this, _TryOn_timerWaitingRef, "f"));
85
- }
14
+ this.#accessKey = accessKey;
15
+ }
16
+ async uploadFile({ files, userId }) {
17
+ try {
18
+ const payload = {
19
+ userId,
20
+ userImages: [files[0]?.name],
86
21
  };
87
- };
88
- this.handleForLatestImage = (_a) => __awaiter(this, [_a], void 0, function* ({ userId, shopDomain, productName, onError }) {
89
- var _b;
90
- if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
91
- throw new Error(constants_1.REQUIRED_MESSAGE);
22
+ if (files[1]) {
23
+ payload.userImages.push(files[1].name);
92
24
  }
93
- try {
94
- const url = `${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON}/?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
95
- const res = yield axios_1.default.post(url, null, {
96
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
97
- });
98
- if (((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.tryOnProcessStatus) === "failed") {
99
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
100
- throw res.data;
101
- }
102
- else {
103
- return res.data;
104
- }
105
- }
106
- catch (error) {
107
- onError === null || onError === void 0 ? void 0 : onError(error);
108
- __classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
109
- throw error;
25
+ const signedUrlRes = await this.#getSignedUrl(payload);
26
+ for (const file of files) {
27
+ await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
110
28
  }
29
+ return "uploaded successfully!";
30
+ }
31
+ catch (error) {
32
+ throw error;
33
+ }
34
+ }
35
+ #getSignedUrl(payload) {
36
+ return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
37
+ headers: {
38
+ "Content-Type": "application/json",
39
+ "X-Api-Key": this.#accessKey,
40
+ },
111
41
  });
112
- _TryOn_handleGetTryOnResult.set(this, (_c) => __awaiter(this, [_c], void 0, function* ({ onSuccess, onError, shopDomain, userId, productName }) {
113
- try {
114
- const data = yield this.getTryOnResult({ shopDomain, userId, productName });
115
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data.data);
116
- }
117
- catch (error) {
118
- onError === null || onError === void 0 ? void 0 : onError(error);
119
- }
120
- }));
121
- this.getTryOnResult = ({ userId, shopDomain, productName }) => {
122
- if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
123
- throw new Error(constants_1.REQUIRED_MESSAGE);
124
- }
125
- const url = `${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
126
- return axios_1.default.post(url, null, {
127
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
128
- });
129
- };
130
- __classPrivateFieldSet(this, _TryOn_accessKey, accessKey, "f");
131
42
  }
132
- uploadFile(_a) {
133
- return __awaiter(this, arguments, void 0, function* ({ files, userId }) {
134
- var _b;
135
- try {
136
- const payload = {
137
- userId,
138
- userImages: [(_b = files[0]) === null || _b === void 0 ? void 0 : _b.name],
139
- };
140
- if (files[1]) {
141
- payload.userImages.push(files[1].name);
142
- }
143
- const signedUrlRes = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_getSignedUrl).call(this, payload);
144
- for (const file of files) {
145
- yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
146
- }
147
- return "uploaded successfully!";
148
- }
149
- catch (error) {
150
- throw error;
151
- }
43
+ #s3Upload(url, file) {
44
+ return axios_1.default.put(url, file, {
45
+ headers: {
46
+ "Content-Type": file.type,
47
+ },
152
48
  });
153
49
  }
154
50
  getUploadedFiles(userId) {
@@ -156,7 +52,7 @@ class TryOn {
156
52
  throw new Error(constants_1.REQUIRED_MESSAGE);
157
53
  }
158
54
  return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}?userId=${userId}`, null, {
159
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
55
+ headers: { "X-Api-Key": this.#accessKey },
160
56
  });
161
57
  }
162
58
  deleteImage({ userId, fileName }) {
@@ -164,22 +60,100 @@ class TryOn {
164
60
  throw new Error(constants_1.REQUIRED_MESSAGE);
165
61
  }
166
62
  return axios_1.default.delete(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_IMAGE_URLS}?userId=${userId}&file=${fileName}`, {
167
- headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
63
+ headers: { "X-Api-Key": this.#accessKey },
168
64
  });
169
65
  }
66
+ #disconnectSocket = () => {
67
+ this.#tryOnSocketRef?.close();
68
+ if (this.#timerWaitingRef) {
69
+ clearTimeout(this.#timerWaitingRef);
70
+ }
71
+ };
72
+ #handleTimeOut = ({ onSuccess, onError, shopDomain, userId, productName }) => {
73
+ this.#timerWaitingRef = setTimeout(() => {
74
+ this.#handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError });
75
+ this.#disconnectSocket();
76
+ }, 120000);
77
+ };
78
+ handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
79
+ if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
80
+ throw new Error(constants_1.REQUIRED_MESSAGE);
81
+ }
82
+ this.#disconnectSocket();
83
+ const url = `${constants_1.APP_AUTH_WEBSOCKET_URL}${constants_1.API_ENDPOINTS.TRY_ON}/?store_url=${shopDomain}&product_name=${productName}&scan_id=${userId}`;
84
+ this.#tryOnSocketRef = new WebSocket(url);
85
+ this.#tryOnSocketRef.onopen = async () => {
86
+ onOpen?.();
87
+ this.#handleTimeOut({ onSuccess, onError, shopDomain, userId, productName });
88
+ try {
89
+ await this.handleForLatestImage({ shopDomain, userId, productName, onError });
90
+ }
91
+ catch (error) {
92
+ onError?.(error);
93
+ }
94
+ };
95
+ this.#tryOnSocketRef.onmessage = (event) => {
96
+ const data = JSON.parse(event.data);
97
+ if (data?.status === "success") {
98
+ this.#handleGetTryOnResult({ shopDomain, userId, productName, onError, onSuccess });
99
+ }
100
+ else {
101
+ onError?.(data);
102
+ }
103
+ if (this.#timerWaitingRef) {
104
+ clearTimeout(this.#timerWaitingRef);
105
+ }
106
+ };
107
+ this.#tryOnSocketRef.onclose = () => {
108
+ onClose?.();
109
+ };
110
+ this.#tryOnSocketRef.onerror = (event) => {
111
+ onError?.(event);
112
+ if (this.#timerWaitingRef) {
113
+ clearTimeout(this.#timerWaitingRef);
114
+ }
115
+ };
116
+ };
117
+ handleForLatestImage = async ({ userId, shopDomain, productName, onError }) => {
118
+ if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
119
+ throw new Error(constants_1.REQUIRED_MESSAGE);
120
+ }
121
+ try {
122
+ const url = `${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON}/?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
123
+ const res = await axios_1.default.post(url, null, {
124
+ headers: { "X-Api-Key": this.#accessKey },
125
+ });
126
+ if (res?.data?.tryOnProcessStatus === "failed") {
127
+ this.#disconnectSocket();
128
+ throw res.data;
129
+ }
130
+ else {
131
+ return res.data;
132
+ }
133
+ }
134
+ catch (error) {
135
+ onError?.(error);
136
+ this.#disconnectSocket();
137
+ throw error;
138
+ }
139
+ };
140
+ #handleGetTryOnResult = async ({ onSuccess, onError, shopDomain, userId, productName }) => {
141
+ try {
142
+ const data = await this.getTryOnResult({ shopDomain, userId, productName });
143
+ onSuccess?.(data.data);
144
+ }
145
+ catch (error) {
146
+ onError?.(error);
147
+ }
148
+ };
149
+ getTryOnResult = ({ userId, shopDomain, productName }) => {
150
+ if ((0, utils_1.checkParameters)(shopDomain, userId, productName) === false) {
151
+ throw new Error(constants_1.REQUIRED_MESSAGE);
152
+ }
153
+ const url = `${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
154
+ return axios_1.default.post(url, null, {
155
+ headers: { "X-Api-Key": this.#accessKey },
156
+ });
157
+ };
170
158
  }
171
- _TryOn_tryOnSocketRef = new WeakMap(), _TryOn_timerWaitingRef = new WeakMap(), _TryOn_accessKey = new WeakMap(), _TryOn_disconnectSocket = new WeakMap(), _TryOn_handleTimeOut = new WeakMap(), _TryOn_handleGetTryOnResult = new WeakMap(), _TryOn_instances = new WeakSet(), _TryOn_getSignedUrl = function _TryOn_getSignedUrl(payload) {
172
- return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
173
- headers: {
174
- "Content-Type": "application/json",
175
- "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f"),
176
- },
177
- });
178
- }, _TryOn_s3Upload = function _TryOn_s3Upload(url, file) {
179
- return axios_1.default.put(url, file, {
180
- headers: {
181
- "Content-Type": file.type,
182
- },
183
- });
184
- };
185
159
  exports.default = TryOn;
package/dist/utils.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,23 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.checkMetaDataValue = exports.checkParameters = exports.fetchData = void 0;
16
7
  const axios_1 = __importDefault(require("axios"));
17
8
  const constants_1 = require("./constants");
18
- function fetchData(options) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const { path, body, queryParams, baseUrl = constants_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
21
- const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
22
- try {
23
- const res = yield axios_1.default.post(apiUrl, body, { headers });
24
- if (res.status >= 200 && res.status < 300) {
25
- return res.data;
26
- }
27
- console.error(`Error: Unexpected response status ${res.status}`);
28
- return {};
29
- }
30
- catch (error) {
31
- console.error(error, "while uploading");
32
- return {};
9
+ async function fetchData(options) {
10
+ const { path, body, queryParams, baseUrl = constants_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
11
+ const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
12
+ try {
13
+ const res = await axios_1.default.post(apiUrl, body, { headers });
14
+ if (res.status >= 200 && res.status < 300) {
15
+ return res.data;
33
16
  }
34
- });
17
+ console.error(`Error: Unexpected response status ${res.status}`);
18
+ return {};
19
+ }
20
+ catch (error) {
21
+ console.error(error, "while uploading");
22
+ return {};
23
+ }
35
24
  }
36
25
  exports.fetchData = fetchData;
37
26
  function checkParameters(...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.65",
3
+ "version": "1.0.66",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/fileUpload.ts CHANGED
@@ -24,25 +24,30 @@ export default class FileUpload {
24
24
  #accessKey: string;
25
25
  #Uppy: any;
26
26
  #AwsS3Multipart: any;
27
+
27
28
  constructor(accessKey: string) {
28
- this.#initializeModules();
29
29
  this.#accessKey = accessKey;
30
30
  }
31
+
31
32
  async #initializeModules() {
32
- this.#Uppy = (await import("@uppy/core")).default;
33
- this.#AwsS3Multipart = (await import("@uppy/aws-s3-multipart")).default;
33
+ if (!this.#Uppy || !this.#AwsS3Multipart) {
34
+ const { default: Uppy } = await import("@uppy/core");
35
+ const { default: AwsS3Multipart } = await import("@uppy/aws-s3-multipart");
36
+ this.#Uppy = Uppy;
37
+ this.#AwsS3Multipart = AwsS3Multipart;
38
+ }
34
39
  }
40
+
35
41
  async uploadFile({ file, arrayMetaData, scanId }: UploadOptions) {
36
- if (checkParameters(file, arrayMetaData, scanId) === false) {
42
+ if (!checkParameters(file, arrayMetaData, scanId)) {
37
43
  throw new Error(REQUIRED_MESSAGE);
38
44
  }
39
- if (checkMetaDataValue(arrayMetaData) === false) {
45
+ if (!checkMetaDataValue(arrayMetaData)) {
40
46
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
41
47
  }
42
48
 
43
- if (!this.#Uppy || !this.#AwsS3Multipart) {
44
- await this.#initializeModules();
45
- }
49
+ await this.#initializeModules();
50
+
46
51
  return new Promise((resolve, reject) => {
47
52
  if (this.#uppyIns) {
48
53
  this.#uppyIns.close();
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es6",
3
+ "target": "esnext", // Ensure ESNext to support dynamic imports
4
4
  "module": "commonjs",
5
5
  "moduleResolution": "node",
6
6
  "outDir": "./dist",