@swan-admin/swan-ai-measurements 1.0.55 → 1.0.57

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/constants.js ADDED
@@ -0,0 +1,46 @@
1
+ const APP_BASE_URL = "https://fitview-server-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
2
+ const APP_AUTH_BASE_URL = "https://staging.api.getswan.co";
3
+ const APP_AUTH_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co";
4
+ const APP_TRY_ON_WEBSOCKET_URL = "wss://bucbzczxjk.execute-api.ap-south-1.amazonaws.com";
5
+ const APP_RECOMMENDATION_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co/scanning";
6
+ const APP_POSE_DETECTION_WEbSOCKET_URL = "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
7
+
8
+ const UPPY_FILE_UPLOAD_ENDPOINT = {
9
+ UPLOAD_START: "/upload/start",
10
+ UPLOAD_COMPLETE: "/upload/complete",
11
+ UPLOAD_SIGN_PART: "/upload/signpart",
12
+ UPLOAD_ABORT: "/upload/abort",
13
+ };
14
+
15
+ const API_ENDPOINTS = {
16
+ GET_USER_DETAIL: "/api/user",
17
+ REGISTER_USER: "/auth/register",
18
+ VERIFY_USER: "/auth/verify",
19
+ ADD_USER: "/user",
20
+ CUSTOM_CUSTOMER: "/customers/custom",
21
+ MODEL: "/model",
22
+ TRY_ON_SCAN: "/tryon/scan",
23
+ TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
24
+ TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
25
+ TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
26
+ TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
27
+ TRY_ON: "/tryon",
28
+ AUTH: "/auth",
29
+ };
30
+ const requiredMetaData = ["gender", "scan_id", "email", "focal_length", "height", "customer_store_url", "scan_type", "callback_url", "clothes_fit"];
31
+ const REQUIRED_MESSAGE = "Please verify required parameters";
32
+ const REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
33
+
34
+ module.exports = {
35
+ APP_BASE_URL,
36
+ APP_AUTH_BASE_URL,
37
+ APP_AUTH_WEBSOCKET_URL,
38
+ APP_TRY_ON_WEBSOCKET_URL,
39
+ APP_RECOMMENDATION_WEBSOCKET_URL,
40
+ APP_POSE_DETECTION_WEbSOCKET_URL,
41
+ REQUIRED_MESSAGE_FOR_META_DATA,
42
+ REQUIRED_MESSAGE,
43
+ requiredMetaData,
44
+ API_ENDPOINTS,
45
+ UPPY_FILE_UPLOAD_ENDPOINT,
46
+ };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
7
7
  "files": [
8
8
  "index.js",
9
9
  "auth.js",
10
- "constant.js",
10
+ "constants.js",
11
11
  "custom.js",
12
12
  "fileUpload.js",
13
13
  "measurement.js",
package/types/auth.d.ts CHANGED
@@ -21,8 +21,8 @@ declare class Auth {
21
21
  registerUser({ email, appVerifyUrl, gender, height, username }: {
22
22
  email: string;
23
23
  appVerifyUrl: string;
24
- gender?: string;
25
- height?: string;
24
+ gender?: string | undefined;
25
+ height?: string | undefined;
26
26
  username: string;
27
27
  }): Promise<any>;
28
28
  /**
@@ -48,7 +48,7 @@ declare class Auth {
48
48
  name: string;
49
49
  height: string;
50
50
  gender: string;
51
- offsetMarketingConsent?: boolean;
51
+ offsetMarketingConsent?: boolean | undefined;
52
52
  }) => Promise<any>;
53
53
  /**
54
54
  * Get user details.
@@ -69,10 +69,10 @@ declare class Auth {
69
69
  handleAuthSocket: ({ email, scanId, onError, onSuccess, onClose, onOpen }: {
70
70
  email: string;
71
71
  scanId: string;
72
- onError?: Function;
73
- onSuccess?: Function;
74
- onClose?: Function;
75
- onOpen?: Function;
72
+ onError?: Function | undefined;
73
+ onSuccess?: Function | undefined;
74
+ onClose?: Function | undefined;
75
+ onOpen?: Function | undefined;
76
76
  }) => void;
77
77
  #private;
78
78
  }
package/types/auth.js ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14
+ if (kind === "m") throw new TypeError("Private method is not writable");
15
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
16
+ 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");
17
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
18
+ };
19
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
20
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
21
+ 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");
22
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
+ };
24
+ var _Auth_socketRef, _Auth_accessKey;
25
+ var axios = require("axios");
26
+ var _a = require("./constants.js"), API_ENDPOINTS = _a.API_ENDPOINTS, APP_AUTH_BASE_URL = _a.APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL = _a.APP_AUTH_WEBSOCKET_URL, APP_BASE_URL = _a.APP_BASE_URL, REQUIRED_MESSAGE = _a.REQUIRED_MESSAGE;
27
+ var checkParameters = require("./utils.js").checkParameters;
28
+ /**
29
+ * Represents a Auth class for handling authentication operations.
30
+ */
31
+ var Auth = /** @class */ (function () {
32
+ /**
33
+ * Constructs a new instance of the Auth class.
34
+ * @param {string} accessKey - The access key used for authentication.
35
+ */
36
+ function Auth(accessKey) {
37
+ var _this = this;
38
+ _Auth_socketRef.set(this, void 0);
39
+ /**
40
+ * The access key used for authentication.
41
+ * @type {string}
42
+ * @private
43
+ */
44
+ _Auth_accessKey.set(this, void 0);
45
+ /**
46
+ * Verify a user token.
47
+ * @param {string} token
48
+ * @returns {Promise}
49
+ */
50
+ this.verifyToken = function (token, accessKey) {
51
+ if (checkParameters(token) === false) {
52
+ throw new Error(REQUIRED_MESSAGE);
53
+ }
54
+ return axios.post("".concat(APP_AUTH_BASE_URL).concat(API_ENDPOINTS.VERIFY_USER), null, {
55
+ params: { token: token },
56
+ headers: { "X-Api-Key": __classPrivateFieldGet(_this, _Auth_accessKey, "f") },
57
+ });
58
+ };
59
+ /**
60
+ * Add a user.
61
+ * @param {Object} params
62
+ * @param {string} params.scanId - The scan ID.
63
+ * @param {string} params.email - The email of the user.
64
+ * @param {string} params.name - The name of the user.
65
+ * @param {string} params.height - The height of the user.
66
+ * @param {string} params.gender - The gender of the user.
67
+ * @param {boolean} [params.offsetMarketingConsent] - Optional. The marketing consent offset.
68
+ * @returns {Promise} - The axios response promise.
69
+ */
70
+ this.addUser = function (_a) {
71
+ var scanId = _a.scanId, email = _a.email, name = _a.name, height = _a.height, gender = _a.gender, offsetMarketingConsent = _a.offsetMarketingConsent;
72
+ if (checkParameters(scanId, email, height, gender) === false) {
73
+ throw new Error(REQUIRED_MESSAGE);
74
+ }
75
+ return axios.post("".concat(APP_AUTH_BASE_URL).concat(API_ENDPOINTS.ADD_USER), {
76
+ scan_id: scanId,
77
+ email: email,
78
+ name: name,
79
+ offsetMarketingConsent: offsetMarketingConsent,
80
+ attributes: JSON.stringify({ height: height, gender: gender }),
81
+ }, { headers: { "X-Api-Key": __classPrivateFieldGet(_this, _Auth_accessKey, "f") } });
82
+ };
83
+ /**
84
+ * Get user details.
85
+ * @param {string} email
86
+ * @returns {Promise}
87
+ */
88
+ this.getUserDetail = function (email) {
89
+ if (checkParameters(email) === false) {
90
+ throw new Error(REQUIRED_MESSAGE);
91
+ }
92
+ return axios.get("".concat(APP_BASE_URL).concat(API_ENDPOINTS.GET_USER_DETAIL, "/").concat(email), {
93
+ headers: { "X-Api-Key": __classPrivateFieldGet(_this, _Auth_accessKey, "f") },
94
+ });
95
+ };
96
+ /**
97
+ * Handle authentication via WebSocket.
98
+ * @param {Object} params
99
+ * @param {string} params.email - The email address of the user.
100
+ * @param {string} params.scanId - The scan ID associated with the user.
101
+ * @param {function} [params.onError] - Optional. Callback function to handle errors.
102
+ * @param {function} [params.onSuccess] - Optional. Callback function to handle successful authentication.
103
+ * @param {function} [params.onClose] - Optional. Callback function to handle the WebSocket close event.
104
+ * @param {function} [params.onOpen] - Optional. Callback function to handle the WebSocket open event.
105
+ */
106
+ this.handleAuthSocket = function (_a) {
107
+ var _b, _c;
108
+ var email = _a.email, scanId = _a.scanId, onError = _a.onError, onSuccess = _a.onSuccess, onClose = _a.onClose, onOpen = _a.onOpen;
109
+ if (checkParameters(email, scanId) === false) {
110
+ throw new Error(REQUIRED_MESSAGE);
111
+ }
112
+ (_c = (_b = __classPrivateFieldGet(_this, _Auth_socketRef, "f")) === null || _b === void 0 ? void 0 : _b.close) === null || _c === void 0 ? void 0 : _c.call(_b);
113
+ __classPrivateFieldSet(_this, _Auth_socketRef, new WebSocket("".concat(APP_AUTH_WEBSOCKET_URL).concat(API_ENDPOINTS.AUTH)), "f");
114
+ var detailObj = {
115
+ email: email,
116
+ scanId: scanId,
117
+ };
118
+ __classPrivateFieldGet(_this, _Auth_socketRef, "f").onopen = function () {
119
+ __classPrivateFieldGet(_this, _Auth_socketRef, "f").send(JSON.stringify(detailObj));
120
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
121
+ };
122
+ __classPrivateFieldGet(_this, _Auth_socketRef, "f").onmessage = function (event) {
123
+ var data = JSON.parse(event.data);
124
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
125
+ };
126
+ __classPrivateFieldGet(_this, _Auth_socketRef, "f").onclose = function () {
127
+ onClose === null || onClose === void 0 ? void 0 : onClose();
128
+ };
129
+ __classPrivateFieldGet(_this, _Auth_socketRef, "f").onerror = function (event) {
130
+ onError === null || onError === void 0 ? void 0 : onError(event);
131
+ };
132
+ };
133
+ __classPrivateFieldSet(this, _Auth_accessKey, accessKey, "f");
134
+ }
135
+ /**
136
+ * Register a new user.
137
+ * @param {Object} params - The parameters for user registration.
138
+ * @param {string} params.email - The email of the user.
139
+ * @param {string} params.appVerifyUrl - The verification URL.
140
+ * @param {string} [params.gender] - Optional. The gender of the user.
141
+ * @param {string} [params.height] - Optional. The height of the user.
142
+ * @param {string} params.username - Optional. The username of the user.
143
+ * @returns {Promise} - The axios response promise.
144
+ */
145
+ Auth.prototype.registerUser = function (_a) {
146
+ var email = _a.email, appVerifyUrl = _a.appVerifyUrl, gender = _a.gender, height = _a.height, username = _a.username;
147
+ if (checkParameters(email, appVerifyUrl) === false) {
148
+ throw new Error(REQUIRED_MESSAGE);
149
+ }
150
+ var body = {
151
+ username: username,
152
+ email: email,
153
+ appVerifyUrl: appVerifyUrl,
154
+ };
155
+ if (gender && height) {
156
+ body = __assign(__assign({}, body), { attributes: { gender: gender, height: height } });
157
+ }
158
+ return axios.post("".concat(APP_AUTH_BASE_URL).concat(API_ENDPOINTS.REGISTER_USER), body, {
159
+ headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
160
+ });
161
+ };
162
+ return Auth;
163
+ }());
164
+ _Auth_socketRef = new WeakMap(), _Auth_accessKey = new WeakMap();
165
+ module.exports = Auth;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var APP_BASE_URL = "https://fitview-server-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
3
+ var APP_AUTH_BASE_URL = "https://staging.api.getswan.co";
4
+ var APP_AUTH_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co";
5
+ var APP_TRY_ON_WEBSOCKET_URL = "wss://bucbzczxjk.execute-api.ap-south-1.amazonaws.com";
6
+ var APP_RECOMMENDATION_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co/scanning";
7
+ var APP_POSE_DETECTION_WEbSOCKET_URL = "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
8
+ var UPPY_FILE_UPLOAD_ENDPOINT = {
9
+ UPLOAD_START: "/upload/start",
10
+ UPLOAD_COMPLETE: "/upload/complete",
11
+ UPLOAD_SIGN_PART: "/upload/signpart",
12
+ UPLOAD_ABORT: "/upload/abort",
13
+ };
14
+ var API_ENDPOINTS = {
15
+ GET_USER_DETAIL: "/api/user",
16
+ REGISTER_USER: "/auth/register",
17
+ VERIFY_USER: "/auth/verify",
18
+ ADD_USER: "/user",
19
+ CUSTOM_CUSTOMER: "/customers/custom",
20
+ MODEL: "/model",
21
+ TRY_ON_SCAN: "/tryon/scan",
22
+ TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
23
+ TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
24
+ TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
25
+ TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
26
+ TRY_ON: "/tryon",
27
+ AUTH: "/auth",
28
+ };
29
+ var requiredMetaData = ["gender", "scan_id", "email", "focal_length", "height", "customer_store_url", "scan_type", "callback_url", "clothes_fit"];
30
+ var REQUIRED_MESSAGE = "Please verify required parameters";
31
+ var REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
32
+ module.exports = {
33
+ APP_BASE_URL: APP_BASE_URL,
34
+ APP_AUTH_BASE_URL: APP_AUTH_BASE_URL,
35
+ APP_AUTH_WEBSOCKET_URL: APP_AUTH_WEBSOCKET_URL,
36
+ APP_TRY_ON_WEBSOCKET_URL: APP_TRY_ON_WEBSOCKET_URL,
37
+ APP_RECOMMENDATION_WEBSOCKET_URL: APP_RECOMMENDATION_WEBSOCKET_URL,
38
+ APP_POSE_DETECTION_WEbSOCKET_URL: APP_POSE_DETECTION_WEbSOCKET_URL,
39
+ REQUIRED_MESSAGE_FOR_META_DATA: REQUIRED_MESSAGE_FOR_META_DATA,
40
+ REQUIRED_MESSAGE: REQUIRED_MESSAGE,
41
+ requiredMetaData: requiredMetaData,
42
+ API_ENDPOINTS: API_ENDPOINTS,
43
+ UPPY_FILE_UPLOAD_ENDPOINT: UPPY_FILE_UPLOAD_ENDPOINT,
44
+ };
@@ -0,0 +1,65 @@
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 _Custom_accessKey;
14
+ var axios = require("axios");
15
+ var _a = require("./constants.js"), API_ENDPOINTS = _a.API_ENDPOINTS, APP_AUTH_BASE_URL = _a.APP_AUTH_BASE_URL, REQUIRED_MESSAGE = _a.REQUIRED_MESSAGE;
16
+ var checkParameters = require("./utils.js").checkParameters;
17
+ /**
18
+ * Represents a Custom class for handling custom operations.
19
+ */
20
+ var Custom = /** @class */ (function () {
21
+ /**
22
+ * Constructs a new instance of the Custom class.
23
+ * @param {string} accessKey - The access key used for authentication.
24
+ */
25
+ function Custom(accessKey) {
26
+ var _this = this;
27
+ /**
28
+ * The access key used for authentication.
29
+ * @type {string}
30
+ * @private
31
+ */
32
+ _Custom_accessKey.set(this, void 0);
33
+ /**
34
+ * Retrieves custom customer configuration based on the store URL.
35
+ * @param {string} store_url - The URL of the store.
36
+ * @returns {Promise} - A promise that resolves with the custom customer configuration.
37
+ * @throws {Error} - If required parameters are missing.
38
+ */
39
+ this.getCustomCustomerConfig = function (store_url) {
40
+ if (checkParameters(store_url) === false) {
41
+ throw new Error(REQUIRED_MESSAGE);
42
+ }
43
+ return axios.get("".concat(APP_AUTH_BASE_URL).concat(API_ENDPOINTS.CUSTOM_CUSTOMER), {
44
+ params: { store_url: store_url },
45
+ headers: { "X-Api-Key": __classPrivateFieldGet(_this, _Custom_accessKey, "f") },
46
+ });
47
+ };
48
+ /**
49
+ * Retrieves the model URL based on the model ID.
50
+ * @param {string} id - The ID of the model.
51
+ * @returns {Promise} - A promise that resolves with the model URL.
52
+ * @throws {Error} - If required parameters are missing.
53
+ */
54
+ this.getModelUrl = function (id) {
55
+ if (checkParameters(id) === false) {
56
+ throw new Error(REQUIRED_MESSAGE);
57
+ }
58
+ return axios.get("".concat(APP_AUTH_BASE_URL).concat(API_ENDPOINTS.MODEL, "/").concat(id), { headers: { "X-Api-Key": __classPrivateFieldGet(_this, _Custom_accessKey, "f") } });
59
+ };
60
+ __classPrivateFieldSet(this, _Custom_accessKey, accessKey, "f");
61
+ }
62
+ return Custom;
63
+ }());
64
+ _Custom_accessKey = new WeakMap();
65
+ module.exports = Custom;
@@ -24,7 +24,7 @@ declare class FileUpload {
24
24
  */
25
25
  uploadFile({ file, objMetaData, scanId }: {
26
26
  file: File;
27
- objMetaData: any;
27
+ objMetaData: Object;
28
28
  scanId: string;
29
29
  }): Promise<any>;
30
30
  #private;
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
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 __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
62
+ if (kind === "m") throw new TypeError("Private method is not writable");
63
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
64
+ 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");
65
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
66
+ };
67
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
68
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
69
+ 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");
70
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
71
+ };
72
+ var _FileUpload_uppyIns, _FileUpload_Uppy, _FileUpload_AwsS3Multipart, _FileUpload_accessKey;
73
+ var _a = require("./constants.js"), REQUIRED_MESSAGE = _a.REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA = _a.REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT = _a.UPPY_FILE_UPLOAD_ENDPOINT;
74
+ var _b = require("./utils.js"), checkMetaDataValue = _b.checkMetaDataValue, checkParameters = _b.checkParameters, fetchData = _b.fetchData;
75
+ /**
76
+ * Class representing a file uploader using Uppy for multipart uploads.
77
+ */
78
+ var FileUpload = /** @class */ (function () {
79
+ /**
80
+ * Constructs a new instance of the FileUpload class.
81
+ * @param {string} accessKey - The access key used for authentication.
82
+ */
83
+ function FileUpload(accessKey) {
84
+ /**
85
+ * The Uppy instance.
86
+ * @type {Object}
87
+ * @private
88
+ */
89
+ _FileUpload_uppyIns.set(this, void 0);
90
+ /**
91
+ * Reference to the Uppy module.
92
+ * @type {Object}
93
+ * @private
94
+ */
95
+ _FileUpload_Uppy.set(this, void 0);
96
+ /**
97
+ * Reference to the AwsS3Multipart module.
98
+ * @type {Object}
99
+ * @private
100
+ */
101
+ _FileUpload_AwsS3Multipart.set(this, void 0);
102
+ /**
103
+ * The access key used for authentication.
104
+ * @type {string}
105
+ * @private
106
+ */
107
+ _FileUpload_accessKey.set(this, void 0);
108
+ this.initializeModules();
109
+ __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
110
+ }
111
+ /**
112
+ * Asynchronously initializes the Uppy and AwsS3Multipart modules.
113
+ * @private
114
+ */
115
+ FileUpload.prototype.initializeModules = function () {
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ var _a, _b;
118
+ return __generator(this, function (_c) {
119
+ switch (_c.label) {
120
+ case 0:
121
+ _a = [this, _FileUpload_Uppy];
122
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("@uppy/core")); })];
123
+ case 1:
124
+ __classPrivateFieldSet.apply(void 0, _a.concat([(_c.sent()).default, "f"]));
125
+ _b = [this, _FileUpload_AwsS3Multipart];
126
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("@uppy/aws-s3-multipart")); })];
127
+ case 2:
128
+ __classPrivateFieldSet.apply(void 0, _b.concat([(_c.sent()).default, "f"]));
129
+ return [2 /*return*/];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ /**
135
+ * Uploads a file with optional metadata and scan ID.
136
+ * @param {Object} params - The parameters for file upload.
137
+ * @param {File} params.file - The file to upload.
138
+ * @param {Object} params.objMetaData - Optional. Metadata associated with the file.
139
+ * @param {string} params.scanId - Optional. The ID of the scan.
140
+ * @returns {Promise} - A promise that resolves when the file is uploaded successfully.
141
+ * @throws {Error} - If required parameters are missing or metadata value is invalid.
142
+ */
143
+ FileUpload.prototype.uploadFile = function (_a) {
144
+ return __awaiter(this, arguments, void 0, function (_b) {
145
+ var _this = this;
146
+ var file = _b.file, objMetaData = _b.objMetaData, scanId = _b.scanId;
147
+ return __generator(this, function (_c) {
148
+ switch (_c.label) {
149
+ case 0:
150
+ if (checkParameters(file, objMetaData, scanId) === false) {
151
+ throw new Error(REQUIRED_MESSAGE);
152
+ }
153
+ if (checkMetaDataValue(objMetaData) === false) {
154
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
155
+ }
156
+ if (!(!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f"))) return [3 /*break*/, 2];
157
+ return [4 /*yield*/, this.initializeModules()];
158
+ case 1:
159
+ _c.sent();
160
+ _c.label = 2;
161
+ case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
162
+ if (__classPrivateFieldGet(_this, _FileUpload_uppyIns, "f")) {
163
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").close();
164
+ }
165
+ __classPrivateFieldSet(_this, _FileUpload_uppyIns, new (__classPrivateFieldGet(_this, _FileUpload_Uppy, "f"))({ autoProceed: true }), "f");
166
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").use(__classPrivateFieldGet(_this, _FileUpload_AwsS3Multipart, "f"), {
167
+ limit: 10,
168
+ retryDelays: [0, 1000, 3000, 5000],
169
+ getChunkSize: function () { return 5 * 1024 * 1024; },
170
+ createMultipartUpload: function (file) {
171
+ var objectKey = "".concat(scanId, ".").concat(file.extension);
172
+ return fetchData({
173
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
174
+ apiKey: __classPrivateFieldGet(_this, _FileUpload_accessKey, "f"),
175
+ body: {
176
+ objectKey: objectKey,
177
+ contentType: file.type,
178
+ objectMetadata: objMetaData,
179
+ },
180
+ });
181
+ },
182
+ completeMultipartUpload: function (file, _a) {
183
+ var uploadId = _a.uploadId, key = _a.key, parts = _a.parts;
184
+ return fetchData({
185
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
186
+ apiKey: __classPrivateFieldGet(_this, _FileUpload_accessKey, "f"),
187
+ body: {
188
+ uploadId: uploadId,
189
+ objectKey: key,
190
+ parts: parts,
191
+ originalFileName: file.name,
192
+ },
193
+ });
194
+ },
195
+ signPart: function (file, partData) {
196
+ return fetchData({
197
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
198
+ apiKey: __classPrivateFieldGet(_this, _FileUpload_accessKey, "f"),
199
+ body: {
200
+ objectKey: partData.key,
201
+ uploadId: partData.uploadId,
202
+ partNumber: partData.partNumber,
203
+ },
204
+ });
205
+ },
206
+ abortMultipartUpload: function (file, _a) {
207
+ var uploadId = _a.uploadId, key = _a.key;
208
+ return fetchData({
209
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
210
+ apiKey: __classPrivateFieldGet(_this, _FileUpload_accessKey, "f"),
211
+ body: {
212
+ uploadId: uploadId,
213
+ objectKey: key,
214
+ originalFileName: file.name,
215
+ },
216
+ });
217
+ },
218
+ });
219
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").addFile({
220
+ source: "manual",
221
+ name: file.name,
222
+ type: file.type,
223
+ data: file,
224
+ });
225
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").on("upload-error", function (file, error, response) {
226
+ reject(error);
227
+ });
228
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").on("upload-success", function () {
229
+ resolve({ message: "file uploaded successfully" });
230
+ });
231
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").on("complete", function (result) {
232
+ if (__classPrivateFieldGet(_this, _FileUpload_uppyIns, "f")) {
233
+ __classPrivateFieldGet(_this, _FileUpload_uppyIns, "f").close();
234
+ }
235
+ });
236
+ })];
237
+ }
238
+ });
239
+ });
240
+ };
241
+ return FileUpload;
242
+ }());
243
+ _FileUpload_uppyIns = new WeakMap(), _FileUpload_Uppy = new WeakMap(), _FileUpload_AwsS3Multipart = new WeakMap(), _FileUpload_accessKey = new WeakMap();
244
+ module.exports = FileUpload;