@meistrari/vault-sdk 3.2.1 → 3.4.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.
- package/README.md +12 -482
- package/dist/index.cjs +297 -122
- package/dist/index.d.cts +262 -50
- package/dist/index.d.mts +262 -50
- package/dist/index.d.ts +262 -50
- package/dist/index.mjs +297 -124
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { GetUploadUrlResponseV2, GetDownloadUrlResponse } from '@meistrari/vault-shared/schemas';
|
|
1
|
+
import { CreateAssetUploadResponse, GetUploadUrlResponseV2, GetDownloadUrlResponse } from '@meistrari/vault-shared/schemas';
|
|
2
2
|
import { fileTypeFromBlob } from '@meistrari/file-type';
|
|
3
3
|
import { lookup } from 'mime-types';
|
|
4
4
|
import vaultUtils from '@meistrari/vault-shared/utils';
|
|
5
5
|
|
|
6
|
-
var __defProp$
|
|
7
|
-
var __defNormalProp$
|
|
8
|
-
var __publicField$
|
|
9
|
-
__defNormalProp$
|
|
6
|
+
var __defProp$3 = Object.defineProperty;
|
|
7
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __publicField$3 = (obj, key, value) => {
|
|
9
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
10
|
return value;
|
|
11
11
|
};
|
|
12
12
|
class DataTokenAuthStrategy {
|
|
13
13
|
constructor(dataToken) {
|
|
14
|
-
__publicField$
|
|
14
|
+
__publicField$3(this, "dataToken");
|
|
15
15
|
this.dataToken = dataToken;
|
|
16
16
|
}
|
|
17
17
|
getHeaders() {
|
|
@@ -22,7 +22,7 @@ class DataTokenAuthStrategy {
|
|
|
22
22
|
}
|
|
23
23
|
class APIKeyAuthStrategy {
|
|
24
24
|
constructor(apiKey) {
|
|
25
|
-
__publicField$
|
|
25
|
+
__publicField$3(this, "apiKey");
|
|
26
26
|
this.apiKey = apiKey;
|
|
27
27
|
}
|
|
28
28
|
getHeaders() {
|
|
@@ -62,116 +62,6 @@ function resolveConfig(config) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
var __defProp$1 = Object.defineProperty;
|
|
66
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
67
|
-
var __publicField$1 = (obj, key, value) => {
|
|
68
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
69
|
-
return value;
|
|
70
|
-
};
|
|
71
|
-
class Permalink {
|
|
72
|
-
constructor(vaultConfig, params) {
|
|
73
|
-
__publicField$1(this, "config");
|
|
74
|
-
__publicField$1(this, "id");
|
|
75
|
-
__publicField$1(this, "workspaceId");
|
|
76
|
-
__publicField$1(this, "createdAt");
|
|
77
|
-
__publicField$1(this, "createdBy");
|
|
78
|
-
__publicField$1(this, "expiresAt");
|
|
79
|
-
__publicField$1(this, "fileId");
|
|
80
|
-
__publicField$1(this, "baseUrl");
|
|
81
|
-
const config = resolveConfig(vaultConfig);
|
|
82
|
-
this.config = config;
|
|
83
|
-
this.id = params.id;
|
|
84
|
-
this.workspaceId = params.workspaceId;
|
|
85
|
-
this.createdAt = new Date(params.createdAt);
|
|
86
|
-
this.createdBy = params.createdBy;
|
|
87
|
-
this.expiresAt = params.expiresAt ? new Date(params.expiresAt) : null;
|
|
88
|
-
this.fileId = params.fileId;
|
|
89
|
-
this.baseUrl = config.vaultUrl;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* The URL for the permalink.
|
|
93
|
-
*/
|
|
94
|
-
get url() {
|
|
95
|
-
return new URL(`permalinks/${this.id}`, this.baseUrl);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get a new permalink instance from its ID.
|
|
99
|
-
*
|
|
100
|
-
* @param vaultConfig - The vault config.
|
|
101
|
-
* @param id - The permalink ID.
|
|
102
|
-
* @returns The permalink.
|
|
103
|
-
*/
|
|
104
|
-
static async fromId(vaultConfig, id) {
|
|
105
|
-
const config = resolveConfig(vaultConfig);
|
|
106
|
-
const response = await fetch(new URL(`permalinks/${id}/metadata`, config.vaultUrl), {
|
|
107
|
-
headers: config.authStrategy.getHeaders()
|
|
108
|
-
});
|
|
109
|
-
if (!response.ok) {
|
|
110
|
-
throw await FetchError.from(response.url, "GET", response);
|
|
111
|
-
}
|
|
112
|
-
const data = await response.json();
|
|
113
|
-
return new Permalink(config, data);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a new permalink.
|
|
117
|
-
*
|
|
118
|
-
* @param vaultConfig - The vault config.
|
|
119
|
-
* @param params - The parameters for the permalink.
|
|
120
|
-
* @param params.expiresIn - Time, in seconds, the permalink will be valid for.
|
|
121
|
-
* @param params.fileId - The ID of the file to create a permalink for.
|
|
122
|
-
* @param params.workspaceId - The ID of the workspace to create a permalink for.
|
|
123
|
-
*
|
|
124
|
-
* @param options - Additional options for the request.
|
|
125
|
-
* @param options.signal - The signal to abort the request.
|
|
126
|
-
*
|
|
127
|
-
* @returns The permalink.
|
|
128
|
-
*/
|
|
129
|
-
static async create(vaultConfig, params, options) {
|
|
130
|
-
const config = resolveConfig(vaultConfig);
|
|
131
|
-
const { expiresIn } = params;
|
|
132
|
-
const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : void 0;
|
|
133
|
-
const headers = config.authStrategy.getHeaders();
|
|
134
|
-
headers.append("x-compatibility-date", "2025-07-29");
|
|
135
|
-
headers.append("content-type", "application/json");
|
|
136
|
-
const body = expiresAt ? JSON.stringify({ expiresAt: expiresAt.toISOString() }) : "{}";
|
|
137
|
-
const response = await fetch(new URL(`files/${params.fileId}/permalinks`, config.vaultUrl), {
|
|
138
|
-
method: "POST",
|
|
139
|
-
signal: options?.signal,
|
|
140
|
-
headers,
|
|
141
|
-
body
|
|
142
|
-
});
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
throw await FetchError.from(response.url, "POST", response);
|
|
145
|
-
}
|
|
146
|
-
const data = await response.json();
|
|
147
|
-
return new Permalink(config, data);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Delete the permalink.
|
|
151
|
-
*
|
|
152
|
-
* @param options - Additional options for the request.
|
|
153
|
-
* @param options.signal - The signal to abort the request.
|
|
154
|
-
*/
|
|
155
|
-
async delete(options) {
|
|
156
|
-
const response = await fetch(new URL(`permalinks/${this.id}`, this.baseUrl), {
|
|
157
|
-
method: "DELETE",
|
|
158
|
-
signal: options?.signal,
|
|
159
|
-
headers: this.config.authStrategy.getHeaders()
|
|
160
|
-
});
|
|
161
|
-
if (!response.ok) {
|
|
162
|
-
throw await FetchError.from(response.url, "DELETE", response);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function blobToBase64(blob) {
|
|
168
|
-
const fileContent = new Uint8Array(await blob.arrayBuffer());
|
|
169
|
-
let content = "";
|
|
170
|
-
for (const part of fileContent)
|
|
171
|
-
content += String.fromCharCode(part);
|
|
172
|
-
return btoa(content);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
65
|
async function getFileHash(blob) {
|
|
176
66
|
const arrayBuffer = await blob.arrayBuffer();
|
|
177
67
|
const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);
|
|
@@ -181,7 +71,7 @@ async function getFileHash(blob) {
|
|
|
181
71
|
}
|
|
182
72
|
async function detectFileMimeType(blob) {
|
|
183
73
|
if (blob instanceof Blob && blob.type) {
|
|
184
|
-
return blob.type.split(";")[0]
|
|
74
|
+
return blob.type.split(";")[0]?.trim();
|
|
185
75
|
}
|
|
186
76
|
if ("name" in blob && typeof blob.name === "string") {
|
|
187
77
|
const extension = blob.name.split(".").pop()?.toLowerCase();
|
|
@@ -209,7 +99,7 @@ async function detectFileMimeType(blob) {
|
|
|
209
99
|
if (lines.length > 1) {
|
|
210
100
|
const commaCounts = lines.map((line) => (line.match(/,/g) || []).length);
|
|
211
101
|
const allSame = commaCounts.every((count) => count === commaCounts[0]);
|
|
212
|
-
if (allSame && commaCounts[0] > 0) {
|
|
102
|
+
if (allSame && (commaCounts[0] ?? 0) > 0) {
|
|
213
103
|
return "text/csv";
|
|
214
104
|
}
|
|
215
105
|
}
|
|
@@ -241,7 +131,7 @@ function getFileName(content) {
|
|
|
241
131
|
}
|
|
242
132
|
|
|
243
133
|
const name = "@meistrari/vault-sdk";
|
|
244
|
-
const version = "3.
|
|
134
|
+
const version = "3.4.0";
|
|
245
135
|
const license = "UNLICENSED";
|
|
246
136
|
const repository = {
|
|
247
137
|
type: "git",
|
|
@@ -269,13 +159,13 @@ const scripts = {
|
|
|
269
159
|
};
|
|
270
160
|
const dependencies = {
|
|
271
161
|
"@meistrari/file-type": "22.0.0",
|
|
272
|
-
"@meistrari/vault-shared": "0.
|
|
162
|
+
"@meistrari/vault-shared": "0.2.0",
|
|
273
163
|
"mime-types": "3.0.1",
|
|
274
164
|
ofetch: "1.4.1",
|
|
275
165
|
zod: "4.3.6"
|
|
276
166
|
};
|
|
277
167
|
const devDependencies = {
|
|
278
|
-
"@types/bun": "
|
|
168
|
+
"@types/bun": "1.3.14",
|
|
279
169
|
"@types/mime-types": "3.0.1",
|
|
280
170
|
msw: "2.6.8",
|
|
281
171
|
unbuild: "2.0.0",
|
|
@@ -306,6 +196,258 @@ const packageJson = {
|
|
|
306
196
|
const serviceName = typeof process !== "undefined" ? process?.env?.SERVICE_NAME : "";
|
|
307
197
|
const userAgent = `vault-js-sdk:${packageJson.version}${serviceName ? `@${serviceName}` : ""}`.trim();
|
|
308
198
|
|
|
199
|
+
var __defProp$2 = Object.defineProperty;
|
|
200
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
201
|
+
var __publicField$2 = (obj, key, value) => {
|
|
202
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
203
|
+
return value;
|
|
204
|
+
};
|
|
205
|
+
const compatibilityDate$1 = "2025-05-19";
|
|
206
|
+
async function wrappedFetch$1(url, requestInit) {
|
|
207
|
+
const request = new Request(url, requestInit);
|
|
208
|
+
request.headers.set("User-Agent", userAgent);
|
|
209
|
+
request.headers.set("x-compatibility-date", compatibilityDate$1);
|
|
210
|
+
const response = await fetch(request);
|
|
211
|
+
if (!response.ok) {
|
|
212
|
+
throw await FetchError.from(request.url, request.method, response);
|
|
213
|
+
}
|
|
214
|
+
return response;
|
|
215
|
+
}
|
|
216
|
+
class VaultAsset {
|
|
217
|
+
/**
|
|
218
|
+
* Constructs a VaultAsset instance from Vault response data.
|
|
219
|
+
*
|
|
220
|
+
* Direct usage of the constructor is not usually needed. Prefer
|
|
221
|
+
* {@link VaultAsset.create} or {@link VaultAsset.fromContent}.
|
|
222
|
+
*
|
|
223
|
+
* @param params - Values returned by Vault when creating an asset upload.
|
|
224
|
+
* @param params.assetId - Vault-assigned asset ID.
|
|
225
|
+
* @param params.assetUrl - Stable URL used to resolve or download the asset.
|
|
226
|
+
* @param params.uploadUrl - Presigned URL used to upload the asset content.
|
|
227
|
+
* @param params.expiresAt - Expiration time for the presigned upload URL.
|
|
228
|
+
* @param params.uploadHeaders - Headers required by the presigned upload URL.
|
|
229
|
+
* @param params.asset - Stored asset metadata returned by Vault.
|
|
230
|
+
*/
|
|
231
|
+
constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders, asset }) {
|
|
232
|
+
/** Vault-assigned asset ID. */
|
|
233
|
+
__publicField$2(this, "assetId");
|
|
234
|
+
/** Stable URL used to resolve or download the asset. */
|
|
235
|
+
__publicField$2(this, "assetUrl");
|
|
236
|
+
/** Presigned URL used to upload asset content. */
|
|
237
|
+
__publicField$2(this, "uploadUrl");
|
|
238
|
+
/** Expiration time for the presigned upload URL. */
|
|
239
|
+
__publicField$2(this, "expiresAt");
|
|
240
|
+
/** Headers that must be sent when uploading to {@link VaultAsset.uploadUrl}. */
|
|
241
|
+
__publicField$2(this, "uploadHeaders");
|
|
242
|
+
/** Stored asset metadata returned by Vault. */
|
|
243
|
+
__publicField$2(this, "asset");
|
|
244
|
+
this.assetId = assetId;
|
|
245
|
+
this.assetUrl = new URL(assetUrl);
|
|
246
|
+
this.uploadUrl = new URL(uploadUrl);
|
|
247
|
+
this.expiresAt = new Date(expiresAt);
|
|
248
|
+
this.uploadHeaders = uploadHeaders;
|
|
249
|
+
this.asset = asset;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Creates an asset upload URL without uploading content.
|
|
253
|
+
*
|
|
254
|
+
* Use {@link VaultAsset.upload} to upload content later, or use
|
|
255
|
+
* {@link VaultAsset.fromContent} with `upload: true` to create and upload in one call.
|
|
256
|
+
*
|
|
257
|
+
* @param vaultConfig - Vault client configuration.
|
|
258
|
+
* @param params - Parameters for the asset upload.
|
|
259
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
260
|
+
* @param params.subject - Opaque application-owned entity reference for lookup and cleanup. Use a stable namespaced value such as `user:user_123`; Vault does not interpret it or include it in the asset URL.
|
|
261
|
+
* @param params.mimeType - MIME type of the content that will be uploaded.
|
|
262
|
+
* @param params.size - Size of the content in bytes, when known.
|
|
263
|
+
* @param options - Additional options for the request.
|
|
264
|
+
* @param options.signal - Signal used to abort the request.
|
|
265
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
266
|
+
* @throws {FetchError} If Vault rejects the create request.
|
|
267
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
268
|
+
*/
|
|
269
|
+
static async create(vaultConfig, params, options) {
|
|
270
|
+
const config = resolveConfig(vaultConfig);
|
|
271
|
+
const headers = config.authStrategy.getHeaders();
|
|
272
|
+
headers.set("content-type", "application/json");
|
|
273
|
+
const response = await wrappedFetch$1(new URL("assets", config.vaultUrl), {
|
|
274
|
+
method: "POST",
|
|
275
|
+
signal: options?.signal,
|
|
276
|
+
headers,
|
|
277
|
+
body: JSON.stringify({
|
|
278
|
+
assetClass: params.assetClass,
|
|
279
|
+
subject: params.subject,
|
|
280
|
+
mimeType: params.mimeType,
|
|
281
|
+
size: params.size
|
|
282
|
+
})
|
|
283
|
+
}).then(async (response2) => await response2.json()).then((data) => CreateAssetUploadResponse.safeParse(data));
|
|
284
|
+
if (!response.success) {
|
|
285
|
+
throw new Error(`Invalid response from vault service. ${JSON.stringify(response.error)}`);
|
|
286
|
+
}
|
|
287
|
+
return new VaultAsset(response.data);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Creates an asset from Blob or File content.
|
|
291
|
+
*
|
|
292
|
+
* The SDK detects the MIME type when `params.mimeType` is omitted. Set
|
|
293
|
+
* `params.upload` to `true` to upload the content immediately.
|
|
294
|
+
*
|
|
295
|
+
* @param vaultConfig - Vault client configuration.
|
|
296
|
+
* @param content - Content to associate with the asset.
|
|
297
|
+
* @param params - Parameters for the asset.
|
|
298
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
299
|
+
* @param params.subject - Opaque application-owned entity reference for lookup and cleanup. Use a stable namespaced value such as `user:user_123`; Vault does not interpret it or include it in the asset URL.
|
|
300
|
+
* @param params.mimeType - MIME type override for the content.
|
|
301
|
+
* @param params.upload - Whether to upload the content immediately after creating the asset.
|
|
302
|
+
* @param options - Additional options for the create and upload requests.
|
|
303
|
+
* @param options.signal - Signal used to abort either request.
|
|
304
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
305
|
+
* @throws {FetchError} If Vault rejects the create request or the upload request fails.
|
|
306
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
307
|
+
*/
|
|
308
|
+
static async fromContent(vaultConfig, content, params, options) {
|
|
309
|
+
const mimeType = params.mimeType ?? await detectFileMimeType(content) ?? "application/octet-stream";
|
|
310
|
+
const asset = await VaultAsset.create(vaultConfig, {
|
|
311
|
+
assetClass: params.assetClass,
|
|
312
|
+
subject: params.subject,
|
|
313
|
+
mimeType,
|
|
314
|
+
size: content.size
|
|
315
|
+
}, options);
|
|
316
|
+
if (params.upload) {
|
|
317
|
+
await asset.upload(content, options);
|
|
318
|
+
}
|
|
319
|
+
return asset;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Uploads content to this asset's presigned upload URL.
|
|
323
|
+
*
|
|
324
|
+
* The upload request sends the headers returned by Vault when the asset was created.
|
|
325
|
+
*
|
|
326
|
+
* @param content - Content to upload.
|
|
327
|
+
* @param options - Additional options for the upload request.
|
|
328
|
+
* @param options.signal - Signal used to abort the upload.
|
|
329
|
+
* @throws {FetchError} If the upload endpoint returns an error response.
|
|
330
|
+
*/
|
|
331
|
+
async upload(content, options) {
|
|
332
|
+
await wrappedFetch$1(this.uploadUrl, {
|
|
333
|
+
method: "PUT",
|
|
334
|
+
signal: options?.signal,
|
|
335
|
+
headers: new Headers(this.uploadHeaders),
|
|
336
|
+
body: content
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
var __defProp$1 = Object.defineProperty;
|
|
342
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
343
|
+
var __publicField$1 = (obj, key, value) => {
|
|
344
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
345
|
+
return value;
|
|
346
|
+
};
|
|
347
|
+
class Permalink {
|
|
348
|
+
constructor(vaultConfig, params) {
|
|
349
|
+
__publicField$1(this, "config");
|
|
350
|
+
__publicField$1(this, "id");
|
|
351
|
+
__publicField$1(this, "workspaceId");
|
|
352
|
+
__publicField$1(this, "createdAt");
|
|
353
|
+
__publicField$1(this, "createdBy");
|
|
354
|
+
__publicField$1(this, "expiresAt");
|
|
355
|
+
__publicField$1(this, "fileId");
|
|
356
|
+
__publicField$1(this, "baseUrl");
|
|
357
|
+
const config = resolveConfig(vaultConfig);
|
|
358
|
+
this.config = config;
|
|
359
|
+
this.id = params.id;
|
|
360
|
+
this.workspaceId = params.workspaceId;
|
|
361
|
+
this.createdAt = new Date(params.createdAt);
|
|
362
|
+
this.createdBy = params.createdBy;
|
|
363
|
+
this.expiresAt = params.expiresAt ? new Date(params.expiresAt) : null;
|
|
364
|
+
this.fileId = params.fileId;
|
|
365
|
+
this.baseUrl = config.vaultUrl;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The URL for the permalink.
|
|
369
|
+
*/
|
|
370
|
+
get url() {
|
|
371
|
+
return new URL(`permalinks/${this.id}`, this.baseUrl);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get a new permalink instance from its ID.
|
|
375
|
+
*
|
|
376
|
+
* @param vaultConfig - The vault config.
|
|
377
|
+
* @param id - The permalink ID.
|
|
378
|
+
* @returns The permalink.
|
|
379
|
+
*/
|
|
380
|
+
static async fromId(vaultConfig, id) {
|
|
381
|
+
const config = resolveConfig(vaultConfig);
|
|
382
|
+
const response = await fetch(new URL(`permalinks/${id}/metadata`, config.vaultUrl), {
|
|
383
|
+
headers: config.authStrategy.getHeaders()
|
|
384
|
+
});
|
|
385
|
+
if (!response.ok) {
|
|
386
|
+
throw await FetchError.from(response.url, "GET", response);
|
|
387
|
+
}
|
|
388
|
+
const data = await response.json();
|
|
389
|
+
return new Permalink(config, data);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Create a new permalink.
|
|
393
|
+
*
|
|
394
|
+
* @param vaultConfig - The vault config.
|
|
395
|
+
* @param params - The parameters for the permalink.
|
|
396
|
+
* @param params.expiresIn - Time, in seconds, the permalink will be valid for.
|
|
397
|
+
* @param params.fileId - The ID of the file to create a permalink for.
|
|
398
|
+
* @param params.workspaceId - The ID of the workspace to create a permalink for.
|
|
399
|
+
*
|
|
400
|
+
* @param options - Additional options for the request.
|
|
401
|
+
* @param options.signal - The signal to abort the request.
|
|
402
|
+
*
|
|
403
|
+
* @returns The permalink.
|
|
404
|
+
*/
|
|
405
|
+
static async create(vaultConfig, params, options) {
|
|
406
|
+
const config = resolveConfig(vaultConfig);
|
|
407
|
+
const { expiresIn } = params;
|
|
408
|
+
const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : void 0;
|
|
409
|
+
const headers = config.authStrategy.getHeaders();
|
|
410
|
+
headers.append("x-compatibility-date", "2025-07-29");
|
|
411
|
+
headers.append("content-type", "application/json");
|
|
412
|
+
const body = expiresAt ? JSON.stringify({ expiresAt: expiresAt.toISOString() }) : "{}";
|
|
413
|
+
const response = await fetch(new URL(`files/${params.fileId}/permalinks`, config.vaultUrl), {
|
|
414
|
+
method: "POST",
|
|
415
|
+
signal: options?.signal,
|
|
416
|
+
headers,
|
|
417
|
+
body
|
|
418
|
+
});
|
|
419
|
+
if (!response.ok) {
|
|
420
|
+
throw await FetchError.from(response.url, "POST", response);
|
|
421
|
+
}
|
|
422
|
+
const data = await response.json();
|
|
423
|
+
return new Permalink(config, data);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Delete the permalink.
|
|
427
|
+
*
|
|
428
|
+
* @param options - Additional options for the request.
|
|
429
|
+
* @param options.signal - The signal to abort the request.
|
|
430
|
+
*/
|
|
431
|
+
async delete(options) {
|
|
432
|
+
const response = await fetch(new URL(`permalinks/${this.id}`, this.baseUrl), {
|
|
433
|
+
method: "DELETE",
|
|
434
|
+
signal: options?.signal,
|
|
435
|
+
headers: this.config.authStrategy.getHeaders()
|
|
436
|
+
});
|
|
437
|
+
if (!response.ok) {
|
|
438
|
+
throw await FetchError.from(response.url, "DELETE", response);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function blobToBase64(blob) {
|
|
444
|
+
const fileContent = new Uint8Array(await blob.arrayBuffer());
|
|
445
|
+
let content = "";
|
|
446
|
+
for (const part of fileContent)
|
|
447
|
+
content += String.fromCharCode(part);
|
|
448
|
+
return btoa(content);
|
|
449
|
+
}
|
|
450
|
+
|
|
309
451
|
var __defProp = Object.defineProperty;
|
|
310
452
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
311
453
|
var __publicField = (obj, key, value) => {
|
|
@@ -2018,7 +2160,38 @@ function vaultClient(vaultConfig) {
|
|
|
2018
2160
|
config
|
|
2019
2161
|
}, { signal: options?.signal });
|
|
2020
2162
|
}
|
|
2021
|
-
|
|
2163
|
+
const assets = {
|
|
2164
|
+
/**
|
|
2165
|
+
* Creates an asset upload URL without uploading content.
|
|
2166
|
+
*
|
|
2167
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
2168
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
2169
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
2170
|
+
*
|
|
2171
|
+
* @param params - Parameters for the asset upload.
|
|
2172
|
+
* @param options - Additional options for the request.
|
|
2173
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
2174
|
+
*/
|
|
2175
|
+
async create(params, options) {
|
|
2176
|
+
return await VaultAsset.create(config, params, { signal: options?.signal });
|
|
2177
|
+
},
|
|
2178
|
+
/**
|
|
2179
|
+
* Creates an asset from File or Blob content and optionally uploads it immediately.
|
|
2180
|
+
*
|
|
2181
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
2182
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
2183
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
2184
|
+
*
|
|
2185
|
+
* @param content - File or Blob content to associate with the asset.
|
|
2186
|
+
* @param params - Parameters for the asset.
|
|
2187
|
+
* @param options - Additional options for the create and upload requests.
|
|
2188
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
2189
|
+
*/
|
|
2190
|
+
async createFromContent(content, params, options) {
|
|
2191
|
+
return await VaultAsset.fromContent(config, content, params, { signal: options?.signal });
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2194
|
+
return { createFromContent, createFromReference, createFromStream, createFromContentBulk, createFromStreamBulk, assets };
|
|
2022
2195
|
}
|
|
2023
2196
|
|
|
2024
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
|
2197
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, Permalink, VaultAsset, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/vault-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@meistrari/file-type": "22.0.0",
|
|
31
|
-
"@meistrari/vault-shared": "0.
|
|
31
|
+
"@meistrari/vault-shared": "0.2.0",
|
|
32
32
|
"mime-types": "3.0.1",
|
|
33
33
|
"ofetch": "1.4.1",
|
|
34
34
|
"zod": "4.3.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/bun": "
|
|
37
|
+
"@types/bun": "1.3.14",
|
|
38
38
|
"@types/mime-types": "3.0.1",
|
|
39
39
|
"msw": "2.6.8",
|
|
40
40
|
"unbuild": "2.0.0",
|