@swan-admin/swan-ai-measurements 1.0.76 → 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/fileUpload.js +129 -98
- package/dist/esm/utils.js +10 -8
- package/dist/fileUpload.js +81 -84
- package/dist/utils.js +10 -11
- package/package.json +1 -1
- package/src/utils.ts +11 -6
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,112 +1,143 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
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
|
+
}
|
|
3
11
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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());
|
|
8
30
|
});
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldSet =
|
|
31
|
+
};
|
|
32
|
+
var __classPrivateFieldSet =
|
|
33
|
+
(this && this.__classPrivateFieldSet) ||
|
|
34
|
+
function (receiver, state, value, kind, f) {
|
|
11
35
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
36
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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) {
|
|
17
44
|
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))
|
|
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");
|
|
19
47
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
-
};
|
|
48
|
+
};
|
|
21
49
|
var _FileUpload_uppyIns, _FileUpload_accessKey;
|
|
22
50
|
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
23
51
|
import { checkMetaDataValue, checkParameters, fetchData } from "./utils.js";
|
|
24
|
-
|
|
25
|
-
|
|
52
|
+
import Uppy from "@uppy/core";
|
|
53
|
+
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
26
54
|
class FileUpload {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
|
|
62
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
63
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
64
|
-
body: {
|
|
65
|
-
uploadId,
|
|
66
|
-
objectKey: key,
|
|
67
|
-
parts,
|
|
68
|
-
originalFileName: file.name,
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
signPart: (file, partData) => fetchData({
|
|
72
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
73
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
74
|
-
body: {
|
|
75
|
-
objectKey: partData.key,
|
|
76
|
-
uploadId: partData.uploadId,
|
|
77
|
-
partNumber: partData.partNumber,
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
abortMultipartUpload: (file, { uploadId, key }) => fetchData({
|
|
81
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
82
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
83
|
-
body: {
|
|
84
|
-
uploadId,
|
|
85
|
-
objectKey: key,
|
|
86
|
-
originalFileName: file.name,
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
});
|
|
90
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
91
|
-
source: "manual",
|
|
92
|
-
name: file.name,
|
|
93
|
-
type: file.type,
|
|
94
|
-
data: file,
|
|
95
|
-
});
|
|
96
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
97
|
-
reject(error);
|
|
98
|
-
});
|
|
99
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
100
|
-
resolve({ message: "file uploaded successfully" });
|
|
101
|
-
});
|
|
102
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
103
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
104
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
55
|
+
constructor(accessKey) {
|
|
56
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
57
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
58
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
59
|
+
}
|
|
60
|
+
uploadFile(_a) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
62
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
63
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
64
|
+
}
|
|
65
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
66
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
67
|
+
}
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
70
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
71
|
+
}
|
|
72
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
|
|
73
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
74
|
+
limit: 10,
|
|
75
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
76
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
77
|
+
createMultipartUpload: (file) => {
|
|
78
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
79
|
+
return fetchData({
|
|
80
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
81
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
82
|
+
body: {
|
|
83
|
+
objectKey,
|
|
84
|
+
contentType: file.type,
|
|
85
|
+
objectMetadata: arrayMetaData,
|
|
86
|
+
},
|
|
107
87
|
});
|
|
88
|
+
},
|
|
89
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
90
|
+
fetchData({
|
|
91
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
92
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
93
|
+
body: {
|
|
94
|
+
uploadId,
|
|
95
|
+
objectKey: key,
|
|
96
|
+
parts,
|
|
97
|
+
originalFileName: file.name,
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
signPart: (file, partData) =>
|
|
101
|
+
fetchData({
|
|
102
|
+
path: 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 }) =>
|
|
111
|
+
fetchData({
|
|
112
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
113
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
114
|
+
body: {
|
|
115
|
+
uploadId,
|
|
116
|
+
objectKey: key,
|
|
117
|
+
originalFileName: file.name,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
108
120
|
});
|
|
109
|
-
|
|
121
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
122
|
+
source: "manual",
|
|
123
|
+
name: file.name,
|
|
124
|
+
type: file.type,
|
|
125
|
+
data: file,
|
|
126
|
+
});
|
|
127
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
128
|
+
reject(error);
|
|
129
|
+
});
|
|
130
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
131
|
+
resolve({ message: "file uploaded successfully" });
|
|
132
|
+
});
|
|
133
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
134
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
135
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
110
141
|
}
|
|
111
|
-
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap();
|
|
142
|
+
(_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap());
|
|
112
143
|
export default FileUpload;
|
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" },
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
return
|
|
25
|
+
const data = yield response.json();
|
|
26
|
+
return data;
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
29
|
console.error(error, "while uploading");
|
package/dist/fileUpload.js
CHANGED
|
@@ -2,92 +2,89 @@
|
|
|
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
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
6
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
7
7
|
class FileUpload {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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();
|
|
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" },
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
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
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
return data;
|
|
35
40
|
} catch (error) {
|
|
36
41
|
console.error(error, "while uploading");
|
|
37
42
|
return {};
|