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