@meistrari/vault-sdk 0.0.5 → 0.0.8

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
@@ -26,10 +26,13 @@ type VaultParams = {
26
26
  declare class VaultFile {
27
27
  readonly name: string;
28
28
  readonly vaultUrl: string;
29
- readonly headers: Headers;
29
+ headers: Headers;
30
30
  constructor(params: VaultParams);
31
+ getVaultUrl(): string;
32
+ removeVaultPrefix(url: string): string;
31
33
  getUploadUrl(): Promise<any>;
32
34
  getDownloadUrl(): Promise<URL>;
35
+ refreshAuth(authStrategy: AuthStrategy): void;
33
36
  _fetch(params: FetchParams): Promise<any>;
34
37
  upload(file: Blob): Promise<void>;
35
38
  download(): Promise<Blob>;
package/dist/index.d.ts CHANGED
@@ -26,10 +26,13 @@ type VaultParams = {
26
26
  declare class VaultFile {
27
27
  readonly name: string;
28
28
  readonly vaultUrl: string;
29
- readonly headers: Headers;
29
+ headers: Headers;
30
30
  constructor(params: VaultParams);
31
+ getVaultUrl(): string;
32
+ removeVaultPrefix(url: string): string;
31
33
  getUploadUrl(): Promise<any>;
32
34
  getDownloadUrl(): Promise<URL>;
35
+ refreshAuth(authStrategy: AuthStrategy): void;
33
36
  _fetch(params: FetchParams): Promise<any>;
34
37
  upload(file: Blob): Promise<void>;
35
38
  download(): Promise<Blob>;
package/dist/index.mjs CHANGED
@@ -21,20 +21,32 @@ class VaultFile {
21
21
  this.vaultUrl = params.vaultUrl;
22
22
  this.headers = params.authStrategy.getHeaders();
23
23
  }
24
+ getVaultUrl() {
25
+ if (this.name.includes("vault://")) {
26
+ return this.name;
27
+ }
28
+ return `vault://${this.name}`;
29
+ }
30
+ removeVaultPrefix(url) {
31
+ return url.replace("vault://", "");
32
+ }
24
33
  async getUploadUrl() {
25
34
  const response = await this._fetch({
26
35
  method: "POST",
27
- path: `/v2/files/${this.name}`
36
+ path: `/v2/files/${this.removeVaultPrefix(this.name)}`
28
37
  });
29
38
  return response.url;
30
39
  }
31
40
  async getDownloadUrl() {
32
41
  const response = await this._fetch({
33
42
  method: "GET",
34
- path: `/v2/files/${this.name}`
43
+ path: `/v2/files/${this.removeVaultPrefix(this.name)}`
35
44
  });
36
45
  return new URL(response.url);
37
46
  }
47
+ refreshAuth(authStrategy) {
48
+ this.headers = authStrategy.getHeaders();
49
+ }
38
50
  async _fetch(params) {
39
51
  const { method, path, body, ignoreHeaders } = params;
40
52
  const url = new URL(this.vaultUrl + path).toString();
@@ -53,8 +65,7 @@ class VaultFile {
53
65
  const uploadUrl = await this.getUploadUrl();
54
66
  const response = await fetch(uploadUrl, {
55
67
  method: "PUT",
56
- body: file,
57
- headers: this.headers
68
+ body: file
58
69
  });
59
70
  if (!response.ok) {
60
71
  throw new FetchError(`Error uploading file ${this.name}: ${response.status} ${response.statusText}`, response);
@@ -63,8 +74,7 @@ class VaultFile {
63
74
  async download() {
64
75
  const downloadUrl = await this.getDownloadUrl();
65
76
  const response = await fetch(downloadUrl, {
66
- method: "GET",
67
- headers: this.headers
77
+ method: "GET"
68
78
  });
69
79
  if (!response.ok) {
70
80
  throw new FetchError(`Error downloading file ${this.name}: ${response.status} ${response.statusText}`, response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/vault-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "license": "UNLICENSED",
5
5
  "repository": {
6
6
  "type": "git",