@swan-admin/swan-ai-measurements 1.0.91 → 1.0.93

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.
@@ -1,198 +1,160 @@
1
- var __awaiter =
2
- (this && this.__awaiter) ||
3
- function (thisArg, _arguments, P, generator) {
4
- function adopt(value) {
5
- return value instanceof P
6
- ? value
7
- : new P(function (resolve) {
8
- resolve(value);
9
- });
10
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
3
  return new (P || (P = Promise))(function (resolve, reject) {
12
- function fulfilled(value) {
13
- try {
14
- step(generator.next(value));
15
- } catch (e) {
16
- reject(e);
17
- }
18
- }
19
- function rejected(value) {
20
- try {
21
- step(generator["throw"](value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- }
26
- function step(result) {
27
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
28
- }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
8
  });
31
- };
32
- var __classPrivateFieldSet =
33
- (this && this.__classPrivateFieldSet) ||
34
- function (receiver, state, value, kind, f) {
9
+ };
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
35
11
  if (kind === "m") throw new TypeError("Private method is not writable");
36
12
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
38
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
- return kind === "a" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;
40
- };
41
- var __classPrivateFieldGet =
42
- (this && this.__classPrivateFieldGet) ||
43
- function (receiver, state, kind, f) {
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
44
17
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
45
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
46
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
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");
47
19
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
48
- };
20
+ };
49
21
  var _FileUpload_uppyIns, _FileUpload_accessKey;
50
22
  import axios from "axios";
51
23
  import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT } from "./constants.js";
52
24
  import { checkMetaDataValue, checkParameters, fetchData, getFileChunks } from "./utils.js";
53
- import Uppy from "@uppy/core";
54
- import AwsS3Multipart from "@uppy/aws-s3-multipart";
25
+ const Uppy = require("fix-esm").require("@uppy/core");
26
+ const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
55
27
  class FileUpload {
56
- constructor(accessKey) {
57
- _FileUpload_uppyIns.set(this, void 0);
58
- _FileUpload_accessKey.set(this, void 0);
59
- __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
60
- }
61
- uploadFileFrontend(_a) {
62
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
63
- if (!checkParameters(file, arrayMetaData, scanId)) {
64
- throw new Error(REQUIRED_MESSAGE);
65
- }
66
- if (!checkMetaDataValue(arrayMetaData)) {
67
- throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
68
- }
69
- return new Promise((resolve, reject) => {
70
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
71
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
72
- }
73
- __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
74
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
75
- limit: 10,
76
- retryDelays: [0, 1000, 3000, 5000],
77
- getChunkSize: () => 5 * 1024 * 1024,
78
- createMultipartUpload: (file) => {
79
- const objectKey = `${scanId}.${file.extension}`;
80
- return fetchData({
81
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
82
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
83
- body: {
84
- objectKey,
85
- contentType: file.type,
86
- objectMetadata: arrayMetaData,
87
- },
28
+ constructor(accessKey) {
29
+ _FileUpload_uppyIns.set(this, void 0);
30
+ _FileUpload_accessKey.set(this, void 0);
31
+ __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
32
+ }
33
+ uploadFileFrontend(_a) {
34
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
35
+ if (!checkParameters(file, arrayMetaData, scanId)) {
36
+ throw new Error(REQUIRED_MESSAGE);
37
+ }
38
+ if (!checkMetaDataValue(arrayMetaData)) {
39
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
40
+ }
41
+ return new Promise((resolve, reject) => {
42
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
43
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
44
+ }
45
+ __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy.default({ autoProceed: true }), "f");
46
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart.default, {
47
+ limit: 10,
48
+ retryDelays: [0, 1000, 3000, 5000],
49
+ getChunkSize: () => 5 * 1024 * 1024,
50
+ createMultipartUpload: (file) => {
51
+ const objectKey = `${scanId}.${file.extension}`;
52
+ return fetchData({
53
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
54
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
55
+ body: {
56
+ objectKey,
57
+ contentType: file.type,
58
+ objectMetadata: arrayMetaData,
59
+ },
60
+ });
61
+ },
62
+ completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
63
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
64
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
65
+ body: {
66
+ uploadId,
67
+ objectKey: key,
68
+ parts,
69
+ originalFileName: file.name,
70
+ },
71
+ }),
72
+ signPart: (file, partData) => fetchData({
73
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
74
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
75
+ body: {
76
+ objectKey: partData.key,
77
+ uploadId: partData.uploadId,
78
+ partNumber: partData.partNumber,
79
+ },
80
+ }),
81
+ });
82
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
83
+ source: "manual",
84
+ name: file.name,
85
+ type: file.type,
86
+ data: file,
87
+ });
88
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
89
+ reject(error);
90
+ });
91
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
92
+ resolve({ message: "file uploaded successfully" });
93
+ });
94
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
95
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
96
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
97
+ }
98
+ });
88
99
  });
89
- },
90
- completeMultipartUpload: (file, { uploadId, key, parts }) =>
91
- fetchData({
92
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
93
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
94
- body: {
95
- uploadId,
96
- objectKey: key,
97
- parts,
98
- originalFileName: file.name,
99
- },
100
- }),
101
- signPart: (file, partData) =>
102
- fetchData({
103
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
104
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
105
- body: {
106
- objectKey: partData.key,
107
- uploadId: partData.uploadId,
108
- partNumber: partData.partNumber,
109
- },
110
- }),
111
- });
112
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
113
- source: "manual",
114
- name: file.name,
115
- type: file.type,
116
- data: file,
117
- });
118
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
119
- reject(error);
120
- });
121
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
122
- resolve({ message: "file uploaded successfully" });
123
- });
124
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
125
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
126
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
127
- }
128
100
  });
129
- });
130
- });
131
- }
132
- uploadFileBackend(_a) {
133
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
134
- if (!checkParameters(file, arrayMetaData, scanId)) {
135
- throw new Error(REQUIRED_MESSAGE);
136
- }
137
- if (!checkMetaDataValue(arrayMetaData)) {
138
- throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
139
- }
140
- return new Promise((resolve, reject) =>
141
- __awaiter(this, void 0, void 0, function* () {
142
- try {
143
- const res = yield fetchData({
144
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
145
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
146
- body: {
147
- objectKey: file.name,
148
- contentType: file.type,
149
- objectMetadata: arrayMetaData,
150
- },
151
- throwError: true,
152
- });
153
- console.log(res, "res for start");
154
- const totalChunks = getFileChunks(file);
155
- console.log(totalChunks, "total chunks");
156
- const parts = [];
157
- for (let i = 0; i < totalChunks.length; i++) {
158
- const data = yield fetchData({
159
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
160
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
161
- body: {
162
- objectKey: res === null || res === void 0 ? void 0 : res.key,
163
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
164
- partNumber: i + 1,
165
- },
166
- throwError: true,
167
- });
168
- console.log(data, "data for signed url");
169
- const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
170
- headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
171
- });
172
- parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
173
- console.log(val === null || val === void 0 ? void 0 : val.data, "after uploading");
101
+ }
102
+ uploadFileBackend(_a) {
103
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
104
+ if (!checkParameters(file, arrayMetaData, scanId)) {
105
+ throw new Error(REQUIRED_MESSAGE);
174
106
  }
175
- console.log(parts, "parts");
176
- const completeValue = yield fetchData({
177
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
178
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
179
- body: {
180
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
181
- objectKey: res === null || res === void 0 ? void 0 : res.key,
182
- parts,
183
- originalFileName: file.name,
184
- },
185
- throwError: true,
186
- });
187
- console.log(completeValue, "after complete");
188
- resolve({ message: "successfully uploaded", data: completeValue });
189
- } catch (error) {
190
- reject(error);
191
- }
192
- })
193
- );
194
- });
195
- }
107
+ if (!checkMetaDataValue(arrayMetaData)) {
108
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
109
+ }
110
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
111
+ try {
112
+ const res = yield fetchData({
113
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
114
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
115
+ body: {
116
+ objectKey: file.name,
117
+ contentType: file.type,
118
+ objectMetadata: arrayMetaData,
119
+ },
120
+ throwError: true,
121
+ });
122
+ const totalChunks = getFileChunks(file);
123
+ const parts = [];
124
+ for (let i = 0; i < totalChunks.length; i++) {
125
+ const data = yield fetchData({
126
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
127
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
128
+ body: {
129
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
130
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
131
+ partNumber: i + 1,
132
+ },
133
+ throwError: true,
134
+ });
135
+ const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") } });
136
+ parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
137
+ console.log(val === null || val === void 0 ? void 0 : val.headers, "after uploading");
138
+ }
139
+ const completeValue = yield fetchData({
140
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
141
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
142
+ body: {
143
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
144
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
145
+ parts,
146
+ originalFileName: file.name,
147
+ },
148
+ throwError: true,
149
+ });
150
+ resolve({ message: "successfully uploaded", data: completeValue });
151
+ }
152
+ catch (error) {
153
+ reject(error);
154
+ }
155
+ }));
156
+ });
157
+ }
196
158
  }
197
- (_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap());
159
+ _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap();
198
160
  export default FileUpload;
@@ -100,9 +100,7 @@ class FileUpload {
100
100
  },
101
101
  throwError: true,
102
102
  });
103
- console.log(res, "res for start");
104
103
  const totalChunks = (0, utils_js_1.getFileChunks)(file);
105
- console.log(totalChunks, "total chunks");
106
104
  const parts = [];
107
105
  for (let i = 0; i < totalChunks.length; i++) {
108
106
  const data = await (0, utils_js_1.fetchData)({
@@ -115,12 +113,10 @@ class FileUpload {
115
113
  },
116
114
  throwError: true,
117
115
  });
118
- console.log(data, "data for signed url");
119
116
  const val = await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
120
117
  parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
121
- console.log(val?.data, "after uploading");
118
+ console.log(val?.headers, "after uploading");
122
119
  }
123
- console.log(parts, "parts");
124
120
  const completeValue = await (0, utils_js_1.fetchData)({
125
121
  path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
126
122
  apiKey: this.#accessKey,
@@ -132,7 +128,6 @@ class FileUpload {
132
128
  },
133
129
  throwError: true,
134
130
  });
135
- console.log(completeValue, "after complete");
136
131
  resolve({ message: "successfully uploaded", data: completeValue });
137
132
  }
138
133
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.91",
3
+ "version": "1.0.93",
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
@@ -122,9 +122,7 @@ export default class FileUpload {
122
122
  },
123
123
  throwError: true,
124
124
  });
125
- console.log(res, "res for start");
126
125
  const totalChunks = getFileChunks(file);
127
- console.log(totalChunks, "total chunks");
128
126
  const parts = [];
129
127
  for (let i = 0; i < totalChunks.length; i++) {
130
128
  const data: { url: string } = await fetchData({
@@ -137,12 +135,10 @@ export default class FileUpload {
137
135
  },
138
136
  throwError: true,
139
137
  });
140
- console.log(data, "data for signed url");
141
138
  const val = await axios.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
142
139
  parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
143
- console.log(val?.data, "after uploading");
140
+ console.log(val?.headers, "after uploading");
144
141
  }
145
- console.log(parts, "parts");
146
142
  const completeValue = await fetchData({
147
143
  path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
148
144
  apiKey: this.#accessKey,
@@ -154,8 +150,6 @@ export default class FileUpload {
154
150
  },
155
151
  throwError: true,
156
152
  });
157
- console.log(completeValue, "after complete");
158
-
159
153
  resolve({ message: "successfully uploaded", data: completeValue });
160
154
  } catch (error: any) {
161
155
  reject(error);