@meistrari/vault-sdk 1.4.0 → 1.4.2
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.cjs +40 -17
- package/dist/index.d.cts +6 -4
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +40 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,19 @@ ${text}`, url, method, response);
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
function resolveBaseUrl(baseUrl) {
|
|
54
|
+
if (baseUrl.endsWith("/")) {
|
|
55
|
+
return baseUrl;
|
|
56
|
+
}
|
|
57
|
+
return `${baseUrl}/`;
|
|
58
|
+
}
|
|
59
|
+
function resolveConfig(config) {
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
vaultUrl: resolveBaseUrl(config.vaultUrl)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
var __defProp$1 = Object.defineProperty;
|
|
54
67
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
55
68
|
var __publicField$1 = (obj, key, value) => {
|
|
@@ -57,7 +70,7 @@ var __publicField$1 = (obj, key, value) => {
|
|
|
57
70
|
return value;
|
|
58
71
|
};
|
|
59
72
|
class Permalink {
|
|
60
|
-
constructor(
|
|
73
|
+
constructor(vaultConfig, params) {
|
|
61
74
|
__publicField$1(this, "config");
|
|
62
75
|
__publicField$1(this, "id");
|
|
63
76
|
__publicField$1(this, "workspaceId");
|
|
@@ -65,6 +78,8 @@ class Permalink {
|
|
|
65
78
|
__publicField$1(this, "createdBy");
|
|
66
79
|
__publicField$1(this, "expiresAt");
|
|
67
80
|
__publicField$1(this, "fileId");
|
|
81
|
+
__publicField$1(this, "baseUrl");
|
|
82
|
+
const config = resolveConfig(vaultConfig);
|
|
68
83
|
this.config = config;
|
|
69
84
|
this.id = params.id;
|
|
70
85
|
this.workspaceId = params.workspaceId;
|
|
@@ -72,12 +87,13 @@ class Permalink {
|
|
|
72
87
|
this.createdBy = params.createdBy;
|
|
73
88
|
this.expiresAt = params.expiresAt ? new Date(params.expiresAt) : null;
|
|
74
89
|
this.fileId = params.fileId;
|
|
90
|
+
this.baseUrl = config.vaultUrl;
|
|
75
91
|
}
|
|
76
92
|
/**
|
|
77
93
|
* The URL for the permalink.
|
|
78
94
|
*/
|
|
79
95
|
get url() {
|
|
80
|
-
return new URL(
|
|
96
|
+
return new URL(`permalinks/${this.id}`, this.baseUrl);
|
|
81
97
|
}
|
|
82
98
|
/**
|
|
83
99
|
* Get a new permalink instance from its ID.
|
|
@@ -86,8 +102,9 @@ class Permalink {
|
|
|
86
102
|
* @param id - The permalink ID.
|
|
87
103
|
* @returns The permalink.
|
|
88
104
|
*/
|
|
89
|
-
static async fromId(
|
|
90
|
-
const
|
|
105
|
+
static async fromId(vaultConfig, id) {
|
|
106
|
+
const config = resolveConfig(vaultConfig);
|
|
107
|
+
const response = await fetch(new URL(`permalinks/${id}/metadata`, config.vaultUrl), {
|
|
91
108
|
headers: config.authStrategy.getHeaders()
|
|
92
109
|
});
|
|
93
110
|
if (!response.ok) {
|
|
@@ -110,14 +127,15 @@ class Permalink {
|
|
|
110
127
|
*
|
|
111
128
|
* @returns The permalink.
|
|
112
129
|
*/
|
|
113
|
-
static async create(
|
|
130
|
+
static async create(vaultConfig, params, options) {
|
|
131
|
+
const config = resolveConfig(vaultConfig);
|
|
114
132
|
const { expiresIn } = params;
|
|
115
133
|
const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : void 0;
|
|
116
134
|
const headers = config.authStrategy.getHeaders();
|
|
117
135
|
headers.append("x-compatibility-date", "2025-07-29");
|
|
118
136
|
headers.append("content-type", "application/json");
|
|
119
137
|
const body = expiresAt ? JSON.stringify({ expiresAt: expiresAt.toISOString() }) : "{}";
|
|
120
|
-
const response = await fetch(
|
|
138
|
+
const response = await fetch(new URL(`files/${params.fileId}/permalinks`, config.vaultUrl), {
|
|
121
139
|
method: "POST",
|
|
122
140
|
signal: options?.signal,
|
|
123
141
|
headers,
|
|
@@ -136,7 +154,7 @@ class Permalink {
|
|
|
136
154
|
* @param options.signal - The signal to abort the request.
|
|
137
155
|
*/
|
|
138
156
|
async delete(options) {
|
|
139
|
-
const response = await fetch(
|
|
157
|
+
const response = await fetch(new URL(`permalinks/${this.id}`, this.baseUrl), {
|
|
140
158
|
method: "DELETE",
|
|
141
159
|
signal: options?.signal,
|
|
142
160
|
headers: this.config.authStrategy.getHeaders()
|
|
@@ -221,11 +239,13 @@ class VaultFile {
|
|
|
221
239
|
__publicField(this, "content");
|
|
222
240
|
__publicField(this, "lastDownloadUrl");
|
|
223
241
|
__publicField(this, "lastUploadUrl");
|
|
224
|
-
this
|
|
242
|
+
__publicField(this, "baseUrl");
|
|
243
|
+
this.config = resolveConfig(config);
|
|
225
244
|
this.content = content;
|
|
226
245
|
this.id = id;
|
|
227
246
|
this.name = name;
|
|
228
247
|
this.metadata = metadata;
|
|
248
|
+
this.baseUrl = this.config.vaultUrl;
|
|
229
249
|
}
|
|
230
250
|
/**
|
|
231
251
|
* Gets the headers for the request based on the auth strategy.
|
|
@@ -248,7 +268,7 @@ class VaultFile {
|
|
|
248
268
|
*/
|
|
249
269
|
async _fetch(params) {
|
|
250
270
|
const { method, path, body, signal, query } = params;
|
|
251
|
-
const url = new URL(path, this.
|
|
271
|
+
const url = new URL(path, this.baseUrl);
|
|
252
272
|
const headers = new Headers(this.headers);
|
|
253
273
|
headers.set("x-compatibility-date", compatibilityDate);
|
|
254
274
|
if (query) {
|
|
@@ -293,7 +313,7 @@ class VaultFile {
|
|
|
293
313
|
}
|
|
294
314
|
this.id = response.data.id;
|
|
295
315
|
this.metadata = response.data.metadata;
|
|
296
|
-
this.name = response.data.metadata?.originalFileName;
|
|
316
|
+
this.name = response.data.metadata?.originalFileName ?? void 0;
|
|
297
317
|
return response.data;
|
|
298
318
|
}
|
|
299
319
|
/**
|
|
@@ -336,10 +356,11 @@ class VaultFile {
|
|
|
336
356
|
* ```
|
|
337
357
|
*/
|
|
338
358
|
static async fromVaultReference(params, options) {
|
|
339
|
-
const { reference, config, download = false } = params;
|
|
359
|
+
const { reference, config: vaultConfig, download = false } = params;
|
|
360
|
+
const config = resolveConfig(vaultConfig);
|
|
340
361
|
const { vaultUrl, authStrategy } = config;
|
|
341
362
|
const id = removeVaultPrefix(reference);
|
|
342
|
-
const url = new URL(`files/${id}`, vaultUrl);
|
|
363
|
+
const url = new URL(`files/${id}`, config.vaultUrl);
|
|
343
364
|
const response = await wrappedFetch(url, {
|
|
344
365
|
method: "GET",
|
|
345
366
|
headers: authStrategy.getHeaders(),
|
|
@@ -355,7 +376,7 @@ class VaultFile {
|
|
|
355
376
|
vaultUrl,
|
|
356
377
|
authStrategy
|
|
357
378
|
},
|
|
358
|
-
name: response.data.metadata?.originalFileName
|
|
379
|
+
name: response.data.metadata?.originalFileName ?? void 0
|
|
359
380
|
};
|
|
360
381
|
if (download) {
|
|
361
382
|
await wrappedFetch(response.data.url, { method: "GET", signal: options?.signal }).then((response2) => response2.blob()).then((blob) => fileParams.content = blob);
|
|
@@ -406,7 +427,8 @@ class VaultFile {
|
|
|
406
427
|
* ```
|
|
407
428
|
*/
|
|
408
429
|
static async fromContent(params, options) {
|
|
409
|
-
const { name, content, config, upload = false } = params;
|
|
430
|
+
const { name, content, config: vaultConfig, upload = false } = params;
|
|
431
|
+
const config = resolveConfig(vaultConfig);
|
|
410
432
|
const { vaultUrl, authStrategy } = config;
|
|
411
433
|
const sha256sum = await getFileHash(content);
|
|
412
434
|
const mimeType = await detectFileMimeType(content);
|
|
@@ -441,7 +463,7 @@ class VaultFile {
|
|
|
441
463
|
async populateMetadata(options) {
|
|
442
464
|
try {
|
|
443
465
|
this.metadata = await this.getFileMetadata({ signal: options?.signal });
|
|
444
|
-
this.name = this.metadata.originalFileName;
|
|
466
|
+
this.name = this.metadata.originalFileName ?? void 0;
|
|
445
467
|
this.id = this.metadata.id;
|
|
446
468
|
return this;
|
|
447
469
|
} catch (error) {
|
|
@@ -498,7 +520,7 @@ class VaultFile {
|
|
|
498
520
|
const createdFile = await this._createFile();
|
|
499
521
|
this.id = createdFile.id;
|
|
500
522
|
this.metadata = createdFile.metadata;
|
|
501
|
-
this.name = createdFile.metadata?.originalFileName;
|
|
523
|
+
this.name = createdFile.metadata?.originalFileName ?? void 0;
|
|
502
524
|
this.lastUploadUrl = { url: new URL(createdFile.uploadUrl), expiresAt: new Date(createdFile.expiresAt) };
|
|
503
525
|
return this.lastUploadUrl.url;
|
|
504
526
|
}
|
|
@@ -654,7 +676,8 @@ class VaultFile {
|
|
|
654
676
|
}
|
|
655
677
|
}
|
|
656
678
|
|
|
657
|
-
function vaultClient(
|
|
679
|
+
function vaultClient(vaultConfig) {
|
|
680
|
+
const config = resolveConfig(vaultConfig);
|
|
658
681
|
function createFromContent(name, content, options) {
|
|
659
682
|
return VaultFile.fromContent({
|
|
660
683
|
name,
|
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,8 @@ declare class Permalink {
|
|
|
36
36
|
readonly createdBy: string | null;
|
|
37
37
|
readonly expiresAt: Date | null;
|
|
38
38
|
readonly fileId: string;
|
|
39
|
-
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
constructor(vaultConfig: VaultConfig, params: SerializedPermalink);
|
|
40
41
|
/**
|
|
41
42
|
* The URL for the permalink.
|
|
42
43
|
*/
|
|
@@ -48,7 +49,7 @@ declare class Permalink {
|
|
|
48
49
|
* @param id - The permalink ID.
|
|
49
50
|
* @returns The permalink.
|
|
50
51
|
*/
|
|
51
|
-
static fromId(
|
|
52
|
+
static fromId(vaultConfig: VaultConfig, id: string): Promise<Permalink>;
|
|
52
53
|
/**
|
|
53
54
|
* Create a new permalink.
|
|
54
55
|
*
|
|
@@ -63,7 +64,7 @@ declare class Permalink {
|
|
|
63
64
|
*
|
|
64
65
|
* @returns The permalink.
|
|
65
66
|
*/
|
|
66
|
-
static create(
|
|
67
|
+
static create(vaultConfig: VaultConfig, params: Pick<SerializedPermalink, 'fileId' | 'workspaceId'> & {
|
|
67
68
|
expiresIn?: number;
|
|
68
69
|
}, options?: {
|
|
69
70
|
signal?: AbortSignal;
|
|
@@ -111,6 +112,7 @@ declare class VaultFile {
|
|
|
111
112
|
url: URL;
|
|
112
113
|
expiresAt: Date;
|
|
113
114
|
} | undefined;
|
|
115
|
+
private readonly baseUrl;
|
|
114
116
|
/**
|
|
115
117
|
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended,
|
|
116
118
|
* instead use the static methods {@link VaultFile.fromVaultReference} when dealing with an existing file in the vault,
|
|
@@ -397,7 +399,7 @@ declare class VaultFile {
|
|
|
397
399
|
}): Promise<Permalink[]>;
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
declare function vaultClient(
|
|
402
|
+
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
401
403
|
createFromContent: (name: string, content: Blob | File, options?: {
|
|
402
404
|
signal?: AbortSignal;
|
|
403
405
|
}) => Promise<VaultFile>;
|
package/dist/index.d.mts
CHANGED
|
@@ -36,7 +36,8 @@ declare class Permalink {
|
|
|
36
36
|
readonly createdBy: string | null;
|
|
37
37
|
readonly expiresAt: Date | null;
|
|
38
38
|
readonly fileId: string;
|
|
39
|
-
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
constructor(vaultConfig: VaultConfig, params: SerializedPermalink);
|
|
40
41
|
/**
|
|
41
42
|
* The URL for the permalink.
|
|
42
43
|
*/
|
|
@@ -48,7 +49,7 @@ declare class Permalink {
|
|
|
48
49
|
* @param id - The permalink ID.
|
|
49
50
|
* @returns The permalink.
|
|
50
51
|
*/
|
|
51
|
-
static fromId(
|
|
52
|
+
static fromId(vaultConfig: VaultConfig, id: string): Promise<Permalink>;
|
|
52
53
|
/**
|
|
53
54
|
* Create a new permalink.
|
|
54
55
|
*
|
|
@@ -63,7 +64,7 @@ declare class Permalink {
|
|
|
63
64
|
*
|
|
64
65
|
* @returns The permalink.
|
|
65
66
|
*/
|
|
66
|
-
static create(
|
|
67
|
+
static create(vaultConfig: VaultConfig, params: Pick<SerializedPermalink, 'fileId' | 'workspaceId'> & {
|
|
67
68
|
expiresIn?: number;
|
|
68
69
|
}, options?: {
|
|
69
70
|
signal?: AbortSignal;
|
|
@@ -111,6 +112,7 @@ declare class VaultFile {
|
|
|
111
112
|
url: URL;
|
|
112
113
|
expiresAt: Date;
|
|
113
114
|
} | undefined;
|
|
115
|
+
private readonly baseUrl;
|
|
114
116
|
/**
|
|
115
117
|
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended,
|
|
116
118
|
* instead use the static methods {@link VaultFile.fromVaultReference} when dealing with an existing file in the vault,
|
|
@@ -397,7 +399,7 @@ declare class VaultFile {
|
|
|
397
399
|
}): Promise<Permalink[]>;
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
declare function vaultClient(
|
|
402
|
+
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
401
403
|
createFromContent: (name: string, content: Blob | File, options?: {
|
|
402
404
|
signal?: AbortSignal;
|
|
403
405
|
}) => Promise<VaultFile>;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ declare class Permalink {
|
|
|
36
36
|
readonly createdBy: string | null;
|
|
37
37
|
readonly expiresAt: Date | null;
|
|
38
38
|
readonly fileId: string;
|
|
39
|
-
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
constructor(vaultConfig: VaultConfig, params: SerializedPermalink);
|
|
40
41
|
/**
|
|
41
42
|
* The URL for the permalink.
|
|
42
43
|
*/
|
|
@@ -48,7 +49,7 @@ declare class Permalink {
|
|
|
48
49
|
* @param id - The permalink ID.
|
|
49
50
|
* @returns The permalink.
|
|
50
51
|
*/
|
|
51
|
-
static fromId(
|
|
52
|
+
static fromId(vaultConfig: VaultConfig, id: string): Promise<Permalink>;
|
|
52
53
|
/**
|
|
53
54
|
* Create a new permalink.
|
|
54
55
|
*
|
|
@@ -63,7 +64,7 @@ declare class Permalink {
|
|
|
63
64
|
*
|
|
64
65
|
* @returns The permalink.
|
|
65
66
|
*/
|
|
66
|
-
static create(
|
|
67
|
+
static create(vaultConfig: VaultConfig, params: Pick<SerializedPermalink, 'fileId' | 'workspaceId'> & {
|
|
67
68
|
expiresIn?: number;
|
|
68
69
|
}, options?: {
|
|
69
70
|
signal?: AbortSignal;
|
|
@@ -111,6 +112,7 @@ declare class VaultFile {
|
|
|
111
112
|
url: URL;
|
|
112
113
|
expiresAt: Date;
|
|
113
114
|
} | undefined;
|
|
115
|
+
private readonly baseUrl;
|
|
114
116
|
/**
|
|
115
117
|
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended,
|
|
116
118
|
* instead use the static methods {@link VaultFile.fromVaultReference} when dealing with an existing file in the vault,
|
|
@@ -397,7 +399,7 @@ declare class VaultFile {
|
|
|
397
399
|
}): Promise<Permalink[]>;
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
declare function vaultClient(
|
|
402
|
+
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
401
403
|
createFromContent: (name: string, content: Blob | File, options?: {
|
|
402
404
|
signal?: AbortSignal;
|
|
403
405
|
}) => Promise<VaultFile>;
|
package/dist/index.mjs
CHANGED
|
@@ -48,6 +48,19 @@ ${text}`, url, method, response);
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function resolveBaseUrl(baseUrl) {
|
|
52
|
+
if (baseUrl.endsWith("/")) {
|
|
53
|
+
return baseUrl;
|
|
54
|
+
}
|
|
55
|
+
return `${baseUrl}/`;
|
|
56
|
+
}
|
|
57
|
+
function resolveConfig(config) {
|
|
58
|
+
return {
|
|
59
|
+
...config,
|
|
60
|
+
vaultUrl: resolveBaseUrl(config.vaultUrl)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
var __defProp$1 = Object.defineProperty;
|
|
52
65
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
66
|
var __publicField$1 = (obj, key, value) => {
|
|
@@ -55,7 +68,7 @@ var __publicField$1 = (obj, key, value) => {
|
|
|
55
68
|
return value;
|
|
56
69
|
};
|
|
57
70
|
class Permalink {
|
|
58
|
-
constructor(
|
|
71
|
+
constructor(vaultConfig, params) {
|
|
59
72
|
__publicField$1(this, "config");
|
|
60
73
|
__publicField$1(this, "id");
|
|
61
74
|
__publicField$1(this, "workspaceId");
|
|
@@ -63,6 +76,8 @@ class Permalink {
|
|
|
63
76
|
__publicField$1(this, "createdBy");
|
|
64
77
|
__publicField$1(this, "expiresAt");
|
|
65
78
|
__publicField$1(this, "fileId");
|
|
79
|
+
__publicField$1(this, "baseUrl");
|
|
80
|
+
const config = resolveConfig(vaultConfig);
|
|
66
81
|
this.config = config;
|
|
67
82
|
this.id = params.id;
|
|
68
83
|
this.workspaceId = params.workspaceId;
|
|
@@ -70,12 +85,13 @@ class Permalink {
|
|
|
70
85
|
this.createdBy = params.createdBy;
|
|
71
86
|
this.expiresAt = params.expiresAt ? new Date(params.expiresAt) : null;
|
|
72
87
|
this.fileId = params.fileId;
|
|
88
|
+
this.baseUrl = config.vaultUrl;
|
|
73
89
|
}
|
|
74
90
|
/**
|
|
75
91
|
* The URL for the permalink.
|
|
76
92
|
*/
|
|
77
93
|
get url() {
|
|
78
|
-
return new URL(
|
|
94
|
+
return new URL(`permalinks/${this.id}`, this.baseUrl);
|
|
79
95
|
}
|
|
80
96
|
/**
|
|
81
97
|
* Get a new permalink instance from its ID.
|
|
@@ -84,8 +100,9 @@ class Permalink {
|
|
|
84
100
|
* @param id - The permalink ID.
|
|
85
101
|
* @returns The permalink.
|
|
86
102
|
*/
|
|
87
|
-
static async fromId(
|
|
88
|
-
const
|
|
103
|
+
static async fromId(vaultConfig, id) {
|
|
104
|
+
const config = resolveConfig(vaultConfig);
|
|
105
|
+
const response = await fetch(new URL(`permalinks/${id}/metadata`, config.vaultUrl), {
|
|
89
106
|
headers: config.authStrategy.getHeaders()
|
|
90
107
|
});
|
|
91
108
|
if (!response.ok) {
|
|
@@ -108,14 +125,15 @@ class Permalink {
|
|
|
108
125
|
*
|
|
109
126
|
* @returns The permalink.
|
|
110
127
|
*/
|
|
111
|
-
static async create(
|
|
128
|
+
static async create(vaultConfig, params, options) {
|
|
129
|
+
const config = resolveConfig(vaultConfig);
|
|
112
130
|
const { expiresIn } = params;
|
|
113
131
|
const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : void 0;
|
|
114
132
|
const headers = config.authStrategy.getHeaders();
|
|
115
133
|
headers.append("x-compatibility-date", "2025-07-29");
|
|
116
134
|
headers.append("content-type", "application/json");
|
|
117
135
|
const body = expiresAt ? JSON.stringify({ expiresAt: expiresAt.toISOString() }) : "{}";
|
|
118
|
-
const response = await fetch(
|
|
136
|
+
const response = await fetch(new URL(`files/${params.fileId}/permalinks`, config.vaultUrl), {
|
|
119
137
|
method: "POST",
|
|
120
138
|
signal: options?.signal,
|
|
121
139
|
headers,
|
|
@@ -134,7 +152,7 @@ class Permalink {
|
|
|
134
152
|
* @param options.signal - The signal to abort the request.
|
|
135
153
|
*/
|
|
136
154
|
async delete(options) {
|
|
137
|
-
const response = await fetch(
|
|
155
|
+
const response = await fetch(new URL(`permalinks/${this.id}`, this.baseUrl), {
|
|
138
156
|
method: "DELETE",
|
|
139
157
|
signal: options?.signal,
|
|
140
158
|
headers: this.config.authStrategy.getHeaders()
|
|
@@ -219,11 +237,13 @@ class VaultFile {
|
|
|
219
237
|
__publicField(this, "content");
|
|
220
238
|
__publicField(this, "lastDownloadUrl");
|
|
221
239
|
__publicField(this, "lastUploadUrl");
|
|
222
|
-
this
|
|
240
|
+
__publicField(this, "baseUrl");
|
|
241
|
+
this.config = resolveConfig(config);
|
|
223
242
|
this.content = content;
|
|
224
243
|
this.id = id;
|
|
225
244
|
this.name = name;
|
|
226
245
|
this.metadata = metadata;
|
|
246
|
+
this.baseUrl = this.config.vaultUrl;
|
|
227
247
|
}
|
|
228
248
|
/**
|
|
229
249
|
* Gets the headers for the request based on the auth strategy.
|
|
@@ -246,7 +266,7 @@ class VaultFile {
|
|
|
246
266
|
*/
|
|
247
267
|
async _fetch(params) {
|
|
248
268
|
const { method, path, body, signal, query } = params;
|
|
249
|
-
const url = new URL(path, this.
|
|
269
|
+
const url = new URL(path, this.baseUrl);
|
|
250
270
|
const headers = new Headers(this.headers);
|
|
251
271
|
headers.set("x-compatibility-date", compatibilityDate);
|
|
252
272
|
if (query) {
|
|
@@ -291,7 +311,7 @@ class VaultFile {
|
|
|
291
311
|
}
|
|
292
312
|
this.id = response.data.id;
|
|
293
313
|
this.metadata = response.data.metadata;
|
|
294
|
-
this.name = response.data.metadata?.originalFileName;
|
|
314
|
+
this.name = response.data.metadata?.originalFileName ?? void 0;
|
|
295
315
|
return response.data;
|
|
296
316
|
}
|
|
297
317
|
/**
|
|
@@ -334,10 +354,11 @@ class VaultFile {
|
|
|
334
354
|
* ```
|
|
335
355
|
*/
|
|
336
356
|
static async fromVaultReference(params, options) {
|
|
337
|
-
const { reference, config, download = false } = params;
|
|
357
|
+
const { reference, config: vaultConfig, download = false } = params;
|
|
358
|
+
const config = resolveConfig(vaultConfig);
|
|
338
359
|
const { vaultUrl, authStrategy } = config;
|
|
339
360
|
const id = removeVaultPrefix(reference);
|
|
340
|
-
const url = new URL(`files/${id}`, vaultUrl);
|
|
361
|
+
const url = new URL(`files/${id}`, config.vaultUrl);
|
|
341
362
|
const response = await wrappedFetch(url, {
|
|
342
363
|
method: "GET",
|
|
343
364
|
headers: authStrategy.getHeaders(),
|
|
@@ -353,7 +374,7 @@ class VaultFile {
|
|
|
353
374
|
vaultUrl,
|
|
354
375
|
authStrategy
|
|
355
376
|
},
|
|
356
|
-
name: response.data.metadata?.originalFileName
|
|
377
|
+
name: response.data.metadata?.originalFileName ?? void 0
|
|
357
378
|
};
|
|
358
379
|
if (download) {
|
|
359
380
|
await wrappedFetch(response.data.url, { method: "GET", signal: options?.signal }).then((response2) => response2.blob()).then((blob) => fileParams.content = blob);
|
|
@@ -404,7 +425,8 @@ class VaultFile {
|
|
|
404
425
|
* ```
|
|
405
426
|
*/
|
|
406
427
|
static async fromContent(params, options) {
|
|
407
|
-
const { name, content, config, upload = false } = params;
|
|
428
|
+
const { name, content, config: vaultConfig, upload = false } = params;
|
|
429
|
+
const config = resolveConfig(vaultConfig);
|
|
408
430
|
const { vaultUrl, authStrategy } = config;
|
|
409
431
|
const sha256sum = await getFileHash(content);
|
|
410
432
|
const mimeType = await detectFileMimeType(content);
|
|
@@ -439,7 +461,7 @@ class VaultFile {
|
|
|
439
461
|
async populateMetadata(options) {
|
|
440
462
|
try {
|
|
441
463
|
this.metadata = await this.getFileMetadata({ signal: options?.signal });
|
|
442
|
-
this.name = this.metadata.originalFileName;
|
|
464
|
+
this.name = this.metadata.originalFileName ?? void 0;
|
|
443
465
|
this.id = this.metadata.id;
|
|
444
466
|
return this;
|
|
445
467
|
} catch (error) {
|
|
@@ -496,7 +518,7 @@ class VaultFile {
|
|
|
496
518
|
const createdFile = await this._createFile();
|
|
497
519
|
this.id = createdFile.id;
|
|
498
520
|
this.metadata = createdFile.metadata;
|
|
499
|
-
this.name = createdFile.metadata?.originalFileName;
|
|
521
|
+
this.name = createdFile.metadata?.originalFileName ?? void 0;
|
|
500
522
|
this.lastUploadUrl = { url: new URL(createdFile.uploadUrl), expiresAt: new Date(createdFile.expiresAt) };
|
|
501
523
|
return this.lastUploadUrl.url;
|
|
502
524
|
}
|
|
@@ -652,7 +674,8 @@ class VaultFile {
|
|
|
652
674
|
}
|
|
653
675
|
}
|
|
654
676
|
|
|
655
|
-
function vaultClient(
|
|
677
|
+
function vaultClient(vaultConfig) {
|
|
678
|
+
const config = resolveConfig(vaultConfig);
|
|
656
679
|
function createFromContent(name, content, options) {
|
|
657
680
|
return VaultFile.fromContent({
|
|
658
681
|
name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/vault-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"check": "bun run lint && bun tsc --noEmit"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@meistrari/vault-shared": "0.0.
|
|
30
|
+
"@meistrari/vault-shared": "0.0.5",
|
|
31
31
|
"file-type": "21.0.0",
|
|
32
32
|
"mime-types": "3.0.1",
|
|
33
33
|
"ofetch": "1.4.1",
|