@meistrari/vault-sdk 0.0.8 → 0.0.10

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/index.d.mts CHANGED
@@ -30,12 +30,13 @@ declare class VaultFile {
30
30
  constructor(params: VaultParams);
31
31
  getVaultUrl(): string;
32
32
  removeVaultPrefix(url: string): string;
33
- getUploadUrl(): Promise<any>;
33
+ getUploadUrl(): Promise<URL>;
34
34
  getDownloadUrl(): Promise<URL>;
35
35
  refreshAuth(authStrategy: AuthStrategy): void;
36
36
  _fetch(params: FetchParams): Promise<any>;
37
37
  upload(file: Blob): Promise<void>;
38
- download(): Promise<Blob>;
38
+ download(responseType?: 'blob'): Promise<Blob>;
39
+ download(responseType: 'base64'): Promise<string>;
39
40
  }
40
41
 
41
42
  declare class FetchError extends Error {
package/dist/index.d.ts CHANGED
@@ -30,12 +30,13 @@ declare class VaultFile {
30
30
  constructor(params: VaultParams);
31
31
  getVaultUrl(): string;
32
32
  removeVaultPrefix(url: string): string;
33
- getUploadUrl(): Promise<any>;
33
+ getUploadUrl(): Promise<URL>;
34
34
  getDownloadUrl(): Promise<URL>;
35
35
  refreshAuth(authStrategy: AuthStrategy): void;
36
36
  _fetch(params: FetchParams): Promise<any>;
37
37
  upload(file: Blob): Promise<void>;
38
- download(): Promise<Blob>;
38
+ download(responseType?: 'blob'): Promise<Blob>;
39
+ download(responseType: 'base64'): Promise<string>;
39
40
  }
40
41
 
41
42
  declare class FetchError extends Error {
package/dist/index.mjs CHANGED
@@ -6,6 +6,14 @@ class FetchError extends Error {
6
6
  }
7
7
  }
8
8
 
9
+ async function blobToBase64(blob) {
10
+ const fileContent = new Uint8Array(await blob.arrayBuffer());
11
+ let content = "";
12
+ for (const part of fileContent)
13
+ content += String.fromCharCode(part);
14
+ return btoa(content);
15
+ }
16
+
9
17
  var __defProp$1 = Object.defineProperty;
10
18
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
19
  var __publicField$1 = (obj, key, value) => {
@@ -35,7 +43,7 @@ class VaultFile {
35
43
  method: "POST",
36
44
  path: `/v2/files/${this.removeVaultPrefix(this.name)}`
37
45
  });
38
- return response.url;
46
+ return new URL(response.url);
39
47
  }
40
48
  async getDownloadUrl() {
41
49
  const response = await this._fetch({
@@ -71,7 +79,7 @@ class VaultFile {
71
79
  throw new FetchError(`Error uploading file ${this.name}: ${response.status} ${response.statusText}`, response);
72
80
  }
73
81
  }
74
- async download() {
82
+ async download(responseType = "blob") {
75
83
  const downloadUrl = await this.getDownloadUrl();
76
84
  const response = await fetch(downloadUrl, {
77
85
  method: "GET"
@@ -79,7 +87,10 @@ class VaultFile {
79
87
  if (!response.ok) {
80
88
  throw new FetchError(`Error downloading file ${this.name}: ${response.status} ${response.statusText}`, response);
81
89
  }
82
- return response.blob();
90
+ const blob = await response.blob();
91
+ if (responseType === "blob")
92
+ return blob;
93
+ return await blobToBase64(blob);
83
94
  }
84
95
  }
85
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/vault-sdk",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "license": "UNLICENSED",
5
5
  "repository": {
6
6
  "type": "git",