@narrative.io/data-collaboration-sdk-ts 0.10.1 → 0.11.0
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.
|
@@ -58,6 +58,8 @@ interface SharedAccessRule {
|
|
|
58
58
|
schema: AccessRuleSchema;
|
|
59
59
|
price_cpm_usd: number;
|
|
60
60
|
metadata: AccessRuleMetadata;
|
|
61
|
+
created_at: string;
|
|
62
|
+
updated_at: string;
|
|
61
63
|
type: "shared";
|
|
62
64
|
}
|
|
63
65
|
interface OwnedAccessRule {
|
|
@@ -76,6 +78,8 @@ interface OwnedAccessRule {
|
|
|
76
78
|
collaborators: AccessRuleCollaborators;
|
|
77
79
|
price_cpm_usd: number;
|
|
78
80
|
metadata: AccessRuleMetadata;
|
|
81
|
+
created_at: string;
|
|
82
|
+
updated_at: string;
|
|
79
83
|
type: "owned";
|
|
80
84
|
}
|
|
81
85
|
export type AccessRuleV2 = OwnedAccessRule | SharedAccessRule;
|
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,51 @@ 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 (uploadInfo.expiry < new Date().toISOString()) {
|
|
48
|
+
throw new Error("Upload URL has expired");
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(uploadInfo.path, {
|
|
52
|
+
method: "PUT",
|
|
53
|
+
body: file,
|
|
54
|
+
headers: {
|
|
55
|
+
"Content-Type": file.type,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
// Check if the upload was successful
|
|
59
|
+
if (response.status === 200) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
24
70
|
}
|
|
25
71
|
export { UploadsApi };
|
package/build/uploads/types.d.ts
CHANGED