@swan-admin/swan-ai-measurements 1.0.77 → 1.0.78

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/esm/utils.js CHANGED
@@ -7,21 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import axios from "axios";
11
10
  import { APP_AUTH_BASE_URL, requiredMetaData } from "./constants.js";
12
11
  export function fetchData(options) {
13
12
  return __awaiter(this, void 0, void 0, function* () {
14
- const { path, body, queryParams, baseUrl = APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, timeout = 5000, // Default timeout value in milliseconds (adjust as needed)
15
- } = options;
13
+ const { path, body, queryParams, baseUrl = APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
16
14
  console.log(body, "body", path, "path");
17
15
  const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
18
16
  try {
19
- const res = yield axios.post(apiUrl, body, { headers, timeout });
20
- if (res.status >= 200 && res.status < 300) {
21
- return res.data;
17
+ const response = yield fetch(apiUrl, {
18
+ method: "POST",
19
+ headers,
20
+ body: JSON.stringify(body),
21
+ });
22
+ if (!response.ok) {
23
+ throw new Error(`Error: Unexpected response status ${response.status}`);
22
24
  }
23
- console.error(`Error: Unexpected response status ${res.status}`);
24
- return {};
25
+ const data = yield response.json();
26
+ return data;
25
27
  }
26
28
  catch (error) {
27
29
  console.error(error, "while uploading");
@@ -5,89 +5,86 @@ const utils_js_1 = require("./utils.js");
5
5
  const Uppy = require("fix-esm").require("@uppy/core");
6
6
  const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
7
7
  class FileUpload {
8
- #uppyIns;
9
- #accessKey;
10
- constructor(accessKey) {
11
- this.#accessKey = accessKey;
12
- }
13
- async uploadFile({ file, arrayMetaData, scanId }) {
14
- if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
15
- throw new Error(constants_js_1.REQUIRED_MESSAGE);
8
+ #uppyIns;
9
+ #accessKey;
10
+ constructor(accessKey) {
11
+ this.#accessKey = accessKey;
16
12
  }
17
- if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
18
- throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
19
- }
20
- return new Promise((resolve, reject) => {
21
- if (this.#uppyIns) {
22
- this.#uppyIns.close();
23
- }
24
- this.#uppyIns = new Uppy.default({ autoProceed: true });
25
- this.#uppyIns.use(AwsS3Multipart.default, {
26
- limit: 10,
27
- retryDelays: [0, 1000, 3000, 5000],
28
- getChunkSize: () => 5 * 1024 * 1024,
29
- createMultipartUpload: (file) => {
30
- const objectKey = `${scanId}.${file.extension}`;
31
- return (0, utils_js_1.fetchData)({
32
- path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
33
- apiKey: this.#accessKey,
34
- body: {
35
- objectKey,
36
- contentType: file.type,
37
- objectMetadata: arrayMetaData,
38
- },
39
- });
40
- },
41
- completeMultipartUpload: (file, { uploadId, key, parts }) =>
42
- (0, utils_js_1.fetchData)({
43
- path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
44
- apiKey: this.#accessKey,
45
- body: {
46
- uploadId,
47
- objectKey: key,
48
- parts,
49
- originalFileName: file.name,
50
- },
51
- }),
52
- signPart: (file, partData) =>
53
- (0, utils_js_1.fetchData)({
54
- path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
55
- apiKey: this.#accessKey,
56
- body: {
57
- objectKey: partData.key,
58
- uploadId: partData.uploadId,
59
- partNumber: partData.partNumber,
60
- },
61
- }),
62
- abortMultipartUpload: (file, { uploadId, key }) =>
63
- (0, utils_js_1.fetchData)({
64
- path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
65
- apiKey: this.#accessKey,
66
- body: {
67
- uploadId,
68
- objectKey: key,
69
- originalFileName: file.name,
70
- },
71
- }),
72
- });
73
- this.#uppyIns.addFile({
74
- source: "manual",
75
- name: file.name,
76
- type: file.type,
77
- data: file,
78
- });
79
- this.#uppyIns.on("upload-error", (file, error, response) => {
80
- reject(error);
81
- });
82
- this.#uppyIns.on("upload-success", () => {
83
- resolve({ message: "file uploaded successfully" });
84
- });
85
- this.#uppyIns.on("complete", (result) => {
86
- if (this.#uppyIns) {
87
- this.#uppyIns.close();
13
+ async uploadFile({ file, arrayMetaData, scanId }) {
14
+ if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
15
+ throw new Error(constants_js_1.REQUIRED_MESSAGE);
16
+ }
17
+ if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
18
+ throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
88
19
  }
89
- });
90
- });
91
- }
20
+ return new Promise((resolve, reject) => {
21
+ if (this.#uppyIns) {
22
+ this.#uppyIns.close();
23
+ }
24
+ this.#uppyIns = new Uppy.default({ autoProceed: true });
25
+ this.#uppyIns.use(AwsS3Multipart.default, {
26
+ limit: 10,
27
+ retryDelays: [0, 1000, 3000, 5000],
28
+ getChunkSize: () => 5 * 1024 * 1024,
29
+ createMultipartUpload: (file) => {
30
+ const objectKey = `${scanId}.${file.extension}`;
31
+ return (0, utils_js_1.fetchData)({
32
+ path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
33
+ apiKey: this.#accessKey,
34
+ body: {
35
+ objectKey,
36
+ contentType: file.type,
37
+ objectMetadata: arrayMetaData,
38
+ },
39
+ });
40
+ },
41
+ completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_js_1.fetchData)({
42
+ path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
43
+ apiKey: this.#accessKey,
44
+ body: {
45
+ uploadId,
46
+ objectKey: key,
47
+ parts,
48
+ originalFileName: file.name,
49
+ },
50
+ }),
51
+ signPart: (file, partData) => (0, utils_js_1.fetchData)({
52
+ path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
53
+ apiKey: this.#accessKey,
54
+ body: {
55
+ objectKey: partData.key,
56
+ uploadId: partData.uploadId,
57
+ partNumber: partData.partNumber,
58
+ },
59
+ }),
60
+ abortMultipartUpload: (file, { uploadId, key }) => (0, utils_js_1.fetchData)({
61
+ path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
62
+ apiKey: this.#accessKey,
63
+ body: {
64
+ uploadId,
65
+ objectKey: key,
66
+ originalFileName: file.name,
67
+ },
68
+ }),
69
+ });
70
+ this.#uppyIns.addFile({
71
+ source: "manual",
72
+ name: file.name,
73
+ type: file.type,
74
+ data: file,
75
+ });
76
+ this.#uppyIns.on("upload-error", (file, error, response) => {
77
+ reject(error);
78
+ });
79
+ this.#uppyIns.on("upload-success", () => {
80
+ resolve({ message: "file uploaded successfully" });
81
+ });
82
+ this.#uppyIns.on("complete", (result) => {
83
+ if (this.#uppyIns) {
84
+ this.#uppyIns.close();
85
+ }
86
+ });
87
+ });
88
+ }
92
89
  }
93
90
  exports.default = FileUpload;
package/dist/utils.js CHANGED
@@ -1,23 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.checkMetaDataValue = exports.checkParameters = exports.fetchData = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const constants_js_1 = require("./constants.js");
9
5
  async function fetchData(options) {
10
- const { path, body, queryParams, baseUrl = constants_js_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, timeout = 5000, // Default timeout value in milliseconds (adjust as needed)
11
- } = options;
6
+ const { path, body, queryParams, baseUrl = constants_js_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
12
7
  console.log(body, "body", path, "path");
13
8
  const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
14
9
  try {
15
- const res = await axios_1.default.post(apiUrl, body, { headers, timeout });
16
- if (res.status >= 200 && res.status < 300) {
17
- return res.data;
10
+ const response = await fetch(apiUrl, {
11
+ method: "POST",
12
+ headers,
13
+ body: JSON.stringify(body),
14
+ });
15
+ if (!response.ok) {
16
+ throw new Error(`Error: Unexpected response status ${response.status}`);
18
17
  }
19
- console.error(`Error: Unexpected response status ${res.status}`);
20
- return {};
18
+ const data = await response.json();
19
+ return data;
21
20
  }
22
21
  catch (error) {
23
22
  console.error(error, "while uploading");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/utils.ts CHANGED
@@ -19,19 +19,24 @@ export async function fetchData(options: FetchDataOptions): Promise<any> {
19
19
  baseUrl = APP_AUTH_BASE_URL,
20
20
  apiKey = "",
21
21
  headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" },
22
- timeout = 5000, // Default timeout value in milliseconds (adjust as needed)
23
22
  } = options;
24
23
 
25
24
  console.log(body, "body", path, "path");
26
25
 
27
26
  const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
28
27
  try {
29
- const res: AxiosResponse<any> = await axios.post(apiUrl, body, { headers, timeout });
30
- if (res.status >= 200 && res.status < 300) {
31
- return res.data;
28
+ const response = await fetch(apiUrl, {
29
+ method: "POST",
30
+ headers,
31
+ body: JSON.stringify(body),
32
+ });
33
+
34
+ if (!response.ok) {
35
+ throw new Error(`Error: Unexpected response status ${response.status}`);
32
36
  }
33
- console.error(`Error: Unexpected response status ${res.status}`);
34
- return {};
37
+
38
+ const data = await response.json();
39
+ return data;
35
40
  } catch (error) {
36
41
  console.error(error, "while uploading");
37
42
  return {};