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