@narrative.io/data-collaboration-sdk-ts 0.10.2 → 0.11.1
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/build/base-api.d.ts +1 -0
- package/build/base-api.js +21 -7
- package/build/uploads/index.d.ts +21 -2
- package/build/uploads/index.js +55 -0
- package/build/uploads/types.d.ts +3 -0
- package/package.json +1 -1
package/build/base-api.d.ts
CHANGED
package/build/base-api.js
CHANGED
|
@@ -15,20 +15,21 @@ export class BaseApi {
|
|
|
15
15
|
* @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
|
|
16
16
|
*/
|
|
17
17
|
constructor(config) {
|
|
18
|
-
this.verbose = config.verbose ?? false;
|
|
19
18
|
this.apiKey = config.apiKey;
|
|
20
19
|
this.environment = config.environment ?? "prod";
|
|
20
|
+
this.verbose = (config.verbose ?? false) || this.environment === "dev";
|
|
21
21
|
this.headers = config.headers ?? {};
|
|
22
22
|
this.base_api = mande(`${this.getBaseUrl()}`, {
|
|
23
23
|
headers: this.constructHeaders(),
|
|
24
24
|
});
|
|
25
|
+
this.drawLogo();
|
|
25
26
|
if (this.verbose) {
|
|
26
|
-
console.
|
|
27
|
-
console.
|
|
28
|
-
console.
|
|
29
|
-
console.
|
|
30
|
-
console.
|
|
31
|
-
console.
|
|
27
|
+
console.info(`Using environment: ${this.environment}`);
|
|
28
|
+
console.info(`Using API key: ${this.apiKey ?? "undefined"}`);
|
|
29
|
+
console.info(`Using headers: ${JSON.stringify(this.constructHeaders())}`);
|
|
30
|
+
console.info(`Using base URL: ${this.getBaseUrl()}`);
|
|
31
|
+
console.info(`Using base API: ${JSON.stringify(this.base_api)}`);
|
|
32
|
+
console.info(`This is us: ${JSON.stringify(this)}`);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
@@ -169,4 +170,17 @@ export class BaseApi {
|
|
|
169
170
|
}
|
|
170
171
|
return queryParameters.length > 0 ? `?${queryParameters.join("&")}` : "";
|
|
171
172
|
}
|
|
173
|
+
drawLogo() {
|
|
174
|
+
console.log(" ___ ___ ___ ___ ___ ___ ");
|
|
175
|
+
console.log(" /\\ \\ /\\ \\ /\\ \\ /\\ \\ /\\ \\ ___ /\\__\\ ");
|
|
176
|
+
console.log(" \\:\\ \\ /::\\ \\ /::\\ \\ /::\\ \\ /::\\ \\ ___ ___ /\\ \\ /:/ _/_ ");
|
|
177
|
+
console.log(" \\:\\ \\ /:/\\:\\ \\ /:/\\:\\__\\ /:/\\:\\__\\ /:/\\:\\ \\ /\\__\\ /\\__\\ \\:\\ \\ /:/ /\\__\\ ");
|
|
178
|
+
console.log(" _____\\:\\ \\ /:/ /::\\ \\ /:/ /:/ / /:/ /:/ / /:/ /::\\ \\ /:/ / /:/__/ \\:\\ \\ /:/ /:/ _/_ ");
|
|
179
|
+
console.log(" /::::::::\\__\\ /:/_/:/\\:\\__\\ /:/_/:/__/___ /:/_/:/__/___ /:/_/:/\\:\\__\\ /:/__/ /::\\ \\ ___ \\:\\__\\ /:/_/:/ /\\__\\");
|
|
180
|
+
console.log(" \\:\\~~\\~~\\/__/ \\:\\/:/ \\/__/ \\:\\/:::::/ / \\:\\/:::::/ / \\:\\/:/ \\/__/ /::\\ \\ \\/\\:\\ \\__ /\\ \\ |:| | \\:\\/:/ /:/ /");
|
|
181
|
+
console.log(" \\:\\ \\ \\::/__/ \\::/~~/~~~~ \\::/~~/~~~~ \\::/__/ /:/\\:\\ \\ ~~\\:\\/\\__\\ \\:\\ \\|:| | \\::/_/:/ / ");
|
|
182
|
+
console.log(" \\:\\ \\ \\:\\ \\ \\:\\~~\\ \\:\\~~\\ \\:\\ \\ \\/__\\:\\ \\ \\::/ / \\:\\__|:|__| \\:\\/:/ / ");
|
|
183
|
+
console.log(" \\:\\__\\ \\:\\__\\ \\:\\__\\ \\:\\__\\ \\:\\__\\ \\:\\__\\ /:/ / \\::::/__/ \\::/ / ");
|
|
184
|
+
console.log(" \\/__/ \\/__/ \\/__/ \\/__/ \\/__/ \\/__/ \\/__/ ~~~~ \\/__/ ");
|
|
185
|
+
}
|
|
172
186
|
}
|
package/build/uploads/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseApi } from "../base-api";
|
|
2
|
-
import { type UploadsResponse } from "./types";
|
|
2
|
+
import { type ConfirmDatasetUpload, type UploadsResponse } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* API class for handling file uploads.
|
|
5
5
|
* @extends BaseApi
|
|
@@ -13,5 +13,24 @@ declare class UploadsApi extends BaseApi {
|
|
|
13
13
|
* @returns {Promise<UploadsResponse>} - A Promise resolving to the response data.
|
|
14
14
|
*/
|
|
15
15
|
getUploadUrl(uploadPath: string): Promise<UploadsResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Confirms the completion of an upload process.
|
|
18
|
+
* This method should be called after a file has been uploaded to the provided URL to finalize the upload.
|
|
19
|
+
*
|
|
20
|
+
* @async
|
|
21
|
+
* @param {number} datasetId - The unique identifier of the dataset being uploaded.
|
|
22
|
+
* @param {string} uploadPath - The path where the file was uploaded.
|
|
23
|
+
* @returns {Promise<void>} A promise resolving when the upload confirmation is complete.
|
|
24
|
+
*/
|
|
25
|
+
confirmUpload(datasetId: number, uploadInfo: UploadsResponse): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Uploads a file to a given presigned S3 URL.
|
|
28
|
+
* The user selects a file from a form in the browser, and this function handles the upload to S3.
|
|
29
|
+
*
|
|
30
|
+
* @param {File} file - The file to be uploaded, typically obtained from a file input in the browser.
|
|
31
|
+
* @param {string} presignedUrl - The presigned URL to which the file should be uploaded.
|
|
32
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the file is successfully uploaded.
|
|
33
|
+
*/
|
|
34
|
+
uploadFileToS3(file: File, uploadInfo: UploadsResponse): Promise<boolean>;
|
|
16
35
|
}
|
|
17
|
-
export { type UploadsResponse, UploadsApi };
|
|
36
|
+
export { type UploadsResponse, type ConfirmDatasetUpload, UploadsApi };
|
package/build/uploads/index.js
CHANGED
|
@@ -21,5 +21,60 @@ class UploadsApi extends BaseApi {
|
|
|
21
21
|
async getUploadUrl(uploadPath) {
|
|
22
22
|
return await this.post(`${resourceName}/${uploadPath}`);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Confirms the completion of an upload process.
|
|
26
|
+
* This method should be called after a file has been uploaded to the provided URL to finalize the upload.
|
|
27
|
+
*
|
|
28
|
+
* @async
|
|
29
|
+
* @param {number} datasetId - The unique identifier of the dataset being uploaded.
|
|
30
|
+
* @param {string} uploadPath - The path where the file was uploaded.
|
|
31
|
+
* @returns {Promise<void>} A promise resolving when the upload confirmation is complete.
|
|
32
|
+
*/
|
|
33
|
+
async confirmUpload(datasetId, uploadInfo) {
|
|
34
|
+
await this.put(`${resourceName}/${datasetId}`, {
|
|
35
|
+
source_file: uploadInfo.path,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Uploads a file to a given presigned S3 URL.
|
|
40
|
+
* The user selects a file from a form in the browser, and this function handles the upload to S3.
|
|
41
|
+
*
|
|
42
|
+
* @param {File} file - The file to be uploaded, typically obtained from a file input in the browser.
|
|
43
|
+
* @param {string} presignedUrl - The presigned URL to which the file should be uploaded.
|
|
44
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the file is successfully uploaded.
|
|
45
|
+
*/
|
|
46
|
+
async uploadFileToS3(file, uploadInfo) {
|
|
47
|
+
if (this.verbose) {
|
|
48
|
+
console.info(`Uploading file to S3: ${file.name}`);
|
|
49
|
+
console.info(`Upload URL: ${uploadInfo.url}`);
|
|
50
|
+
console.info(`Upload path: ${uploadInfo.path}`);
|
|
51
|
+
console.info(`Upload expiry: ${uploadInfo.expiry}`);
|
|
52
|
+
console.info(`Upload file type: ${file.type}`);
|
|
53
|
+
console.info(`Upload file size: ${file.size}`);
|
|
54
|
+
}
|
|
55
|
+
if (uploadInfo.expiry < new Date().toISOString()) {
|
|
56
|
+
throw new Error("Upload URL has expired");
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(uploadInfo.url, {
|
|
60
|
+
method: "PUT",
|
|
61
|
+
body: file,
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": file.type,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
// Check if the upload was successful
|
|
67
|
+
if (response.status === 200) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error("Upload failed:", error);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
24
79
|
}
|
|
25
80
|
export { UploadsApi };
|
package/build/uploads/types.d.ts
CHANGED