@meistrari/vault-sdk 3.2.0 → 3.3.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/dist/index.cjs CHANGED
@@ -1,23 +1,24 @@
1
1
  'use strict';
2
2
 
3
- const schemas = require('@meistrari/vault-shared/schemas');
3
+ const zod = require('zod');
4
4
  const fileType = require('@meistrari/file-type');
5
5
  const mimeTypes = require('mime-types');
6
+ const schemas = require('@meistrari/vault-shared/schemas');
6
7
  const vaultUtils = require('@meistrari/vault-shared/utils');
7
8
 
8
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
10
 
10
11
  const vaultUtils__default = /*#__PURE__*/_interopDefaultCompat(vaultUtils);
11
12
 
12
- var __defProp$2 = Object.defineProperty;
13
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
- var __publicField$2 = (obj, key, value) => {
15
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+ var __defProp$3 = Object.defineProperty;
14
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __publicField$3 = (obj, key, value) => {
16
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
16
17
  return value;
17
18
  };
18
19
  class DataTokenAuthStrategy {
19
20
  constructor(dataToken) {
20
- __publicField$2(this, "dataToken");
21
+ __publicField$3(this, "dataToken");
21
22
  this.dataToken = dataToken;
22
23
  }
23
24
  getHeaders() {
@@ -28,7 +29,7 @@ class DataTokenAuthStrategy {
28
29
  }
29
30
  class APIKeyAuthStrategy {
30
31
  constructor(apiKey) {
31
- __publicField$2(this, "apiKey");
32
+ __publicField$3(this, "apiKey");
32
33
  this.apiKey = apiKey;
33
34
  }
34
35
  getHeaders() {
@@ -68,116 +69,6 @@ function resolveConfig(config) {
68
69
  };
69
70
  }
70
71
 
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
72
  async function getFileHash(blob) {
182
73
  const arrayBuffer = await blob.arrayBuffer();
183
74
  const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);
@@ -224,6 +115,16 @@ async function detectFileMimeType(blob) {
224
115
  }
225
116
  return void 0;
226
117
  }
118
+ function sanitizeFileName(name) {
119
+ if (!name.includes("\0"))
120
+ return name;
121
+ const sanitized = name.replace(/\0/g, "");
122
+ console.warn(
123
+ "[Vault SDK - WARNING] Null bytes found in file name and were removed.",
124
+ { original: name, sanitized }
125
+ );
126
+ return sanitized;
127
+ }
227
128
  function basename(name, separator = "/") {
228
129
  if (!name)
229
130
  return void 0;
@@ -237,7 +138,7 @@ function getFileName(content) {
237
138
  }
238
139
 
239
140
  const name = "@meistrari/vault-sdk";
240
- const version = "3.2.0";
141
+ const version = "3.3.0";
241
142
  const license = "UNLICENSED";
242
143
  const repository = {
243
144
  type: "git",
@@ -265,13 +166,13 @@ const scripts = {
265
166
  };
266
167
  const dependencies = {
267
168
  "@meistrari/file-type": "22.0.0",
268
- "@meistrari/vault-shared": "0.1.1",
169
+ "@meistrari/vault-shared": "0.1.2",
269
170
  "mime-types": "3.0.1",
270
171
  ofetch: "1.4.1",
271
172
  zod: "4.3.6"
272
173
  };
273
174
  const devDependencies = {
274
- "@types/bun": "latest",
175
+ "@types/bun": "1.3.14",
275
176
  "@types/mime-types": "3.0.1",
276
177
  msw: "2.6.8",
277
178
  unbuild: "2.0.0",
@@ -302,6 +203,194 @@ const packageJson = {
302
203
  const serviceName = typeof process !== "undefined" ? process?.env?.SERVICE_NAME : "";
303
204
  const userAgent = `vault-js-sdk:${packageJson.version}${serviceName ? `@${serviceName}` : ""}`.trim();
304
205
 
206
+ var __defProp$2 = Object.defineProperty;
207
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
208
+ var __publicField$2 = (obj, key, value) => {
209
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
210
+ return value;
211
+ };
212
+ const compatibilityDate$1 = "2025-05-19";
213
+ const PublicAssetUploadResponse = zod.z.object({
214
+ assetId: zod.z.string(),
215
+ assetUrl: zod.z.string().url(),
216
+ uploadUrl: zod.z.string().url(),
217
+ expiresAt: zod.z.string().datetime(),
218
+ uploadHeaders: zod.z.record(zod.z.string(), zod.z.string())
219
+ });
220
+ async function wrappedFetch$1(url, requestInit) {
221
+ const request = new Request(url, requestInit);
222
+ request.headers.set("User-Agent", userAgent);
223
+ request.headers.set("x-compatibility-date", compatibilityDate$1);
224
+ const response = await fetch(request);
225
+ if (!response.ok) {
226
+ throw await FetchError.from(request.url, request.method, response);
227
+ }
228
+ return response;
229
+ }
230
+ class VaultAsset {
231
+ constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders }) {
232
+ __publicField$2(this, "assetId");
233
+ __publicField$2(this, "assetUrl");
234
+ __publicField$2(this, "uploadUrl");
235
+ __publicField$2(this, "expiresAt");
236
+ __publicField$2(this, "uploadHeaders");
237
+ this.assetId = assetId;
238
+ this.assetUrl = new URL(assetUrl);
239
+ this.uploadUrl = new URL(uploadUrl);
240
+ this.expiresAt = new Date(expiresAt);
241
+ this.uploadHeaders = uploadHeaders;
242
+ }
243
+ static async create(vaultConfig, params, options) {
244
+ const config = resolveConfig(vaultConfig);
245
+ const headers = config.authStrategy.getHeaders();
246
+ headers.set("content-type", "application/json");
247
+ const response = await wrappedFetch$1(new URL("assets", config.vaultUrl), {
248
+ method: "POST",
249
+ signal: options?.signal,
250
+ headers,
251
+ body: JSON.stringify({
252
+ assetClass: params.assetClass,
253
+ mimeType: params.mimeType,
254
+ size: params.size
255
+ })
256
+ }).then(async (response2) => await response2.json()).then((data) => PublicAssetUploadResponse.safeParse(data));
257
+ if (!response.success) {
258
+ throw new Error(`Invalid response from vault service. ${JSON.stringify(response.error)}`);
259
+ }
260
+ return new VaultAsset(response.data);
261
+ }
262
+ static async fromContent(vaultConfig, content, params, options) {
263
+ const mimeType = params.mimeType ?? await detectFileMimeType(content) ?? "application/octet-stream";
264
+ const asset = await VaultAsset.create(vaultConfig, {
265
+ assetClass: params.assetClass,
266
+ mimeType,
267
+ size: content.size
268
+ }, options);
269
+ if (params.upload) {
270
+ await asset.upload(content, options);
271
+ }
272
+ return asset;
273
+ }
274
+ async upload(content, options) {
275
+ await wrappedFetch$1(this.uploadUrl, {
276
+ method: "PUT",
277
+ signal: options?.signal,
278
+ headers: new Headers(this.uploadHeaders),
279
+ body: content
280
+ });
281
+ }
282
+ }
283
+
284
+ var __defProp$1 = Object.defineProperty;
285
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
286
+ var __publicField$1 = (obj, key, value) => {
287
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
288
+ return value;
289
+ };
290
+ class Permalink {
291
+ constructor(vaultConfig, params) {
292
+ __publicField$1(this, "config");
293
+ __publicField$1(this, "id");
294
+ __publicField$1(this, "workspaceId");
295
+ __publicField$1(this, "createdAt");
296
+ __publicField$1(this, "createdBy");
297
+ __publicField$1(this, "expiresAt");
298
+ __publicField$1(this, "fileId");
299
+ __publicField$1(this, "baseUrl");
300
+ const config = resolveConfig(vaultConfig);
301
+ this.config = config;
302
+ this.id = params.id;
303
+ this.workspaceId = params.workspaceId;
304
+ this.createdAt = new Date(params.createdAt);
305
+ this.createdBy = params.createdBy;
306
+ this.expiresAt = params.expiresAt ? new Date(params.expiresAt) : null;
307
+ this.fileId = params.fileId;
308
+ this.baseUrl = config.vaultUrl;
309
+ }
310
+ /**
311
+ * The URL for the permalink.
312
+ */
313
+ get url() {
314
+ return new URL(`permalinks/${this.id}`, this.baseUrl);
315
+ }
316
+ /**
317
+ * Get a new permalink instance from its ID.
318
+ *
319
+ * @param vaultConfig - The vault config.
320
+ * @param id - The permalink ID.
321
+ * @returns The permalink.
322
+ */
323
+ static async fromId(vaultConfig, id) {
324
+ const config = resolveConfig(vaultConfig);
325
+ const response = await fetch(new URL(`permalinks/${id}/metadata`, config.vaultUrl), {
326
+ headers: config.authStrategy.getHeaders()
327
+ });
328
+ if (!response.ok) {
329
+ throw await FetchError.from(response.url, "GET", response);
330
+ }
331
+ const data = await response.json();
332
+ return new Permalink(config, data);
333
+ }
334
+ /**
335
+ * Create a new permalink.
336
+ *
337
+ * @param vaultConfig - The vault config.
338
+ * @param params - The parameters for the permalink.
339
+ * @param params.expiresIn - Time, in seconds, the permalink will be valid for.
340
+ * @param params.fileId - The ID of the file to create a permalink for.
341
+ * @param params.workspaceId - The ID of the workspace to create a permalink for.
342
+ *
343
+ * @param options - Additional options for the request.
344
+ * @param options.signal - The signal to abort the request.
345
+ *
346
+ * @returns The permalink.
347
+ */
348
+ static async create(vaultConfig, params, options) {
349
+ const config = resolveConfig(vaultConfig);
350
+ const { expiresIn } = params;
351
+ const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : void 0;
352
+ const headers = config.authStrategy.getHeaders();
353
+ headers.append("x-compatibility-date", "2025-07-29");
354
+ headers.append("content-type", "application/json");
355
+ const body = expiresAt ? JSON.stringify({ expiresAt: expiresAt.toISOString() }) : "{}";
356
+ const response = await fetch(new URL(`files/${params.fileId}/permalinks`, config.vaultUrl), {
357
+ method: "POST",
358
+ signal: options?.signal,
359
+ headers,
360
+ body
361
+ });
362
+ if (!response.ok) {
363
+ throw await FetchError.from(response.url, "POST", response);
364
+ }
365
+ const data = await response.json();
366
+ return new Permalink(config, data);
367
+ }
368
+ /**
369
+ * Delete the permalink.
370
+ *
371
+ * @param options - Additional options for the request.
372
+ * @param options.signal - The signal to abort the request.
373
+ */
374
+ async delete(options) {
375
+ const response = await fetch(new URL(`permalinks/${this.id}`, this.baseUrl), {
376
+ method: "DELETE",
377
+ signal: options?.signal,
378
+ headers: this.config.authStrategy.getHeaders()
379
+ });
380
+ if (!response.ok) {
381
+ throw await FetchError.from(response.url, "DELETE", response);
382
+ }
383
+ }
384
+ }
385
+
386
+ async function blobToBase64(blob) {
387
+ const fileContent = new Uint8Array(await blob.arrayBuffer());
388
+ let content = "";
389
+ for (const part of fileContent)
390
+ content += String.fromCharCode(part);
391
+ return btoa(content);
392
+ }
393
+
305
394
  var __defProp = Object.defineProperty;
306
395
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
307
396
  var __publicField = (obj, key, value) => {
@@ -603,7 +692,8 @@ class VaultFile {
603
692
  */
604
693
  static async fromContent(params, options) {
605
694
  const { content, config: vaultConfig, upload = false, parentId, onMissingParent, onParentConflict } = params;
606
- const name = basename(params.name) ?? getFileName(content);
695
+ const rawName = basename(params.name) ?? getFileName(content);
696
+ const name = rawName ? sanitizeFileName(rawName) : rawName;
607
697
  const config = resolveConfig(vaultConfig);
608
698
  const { vaultUrl, authStrategy } = config;
609
699
  const sha256sum = await getFileHash(content);
@@ -686,7 +776,8 @@ class VaultFile {
686
776
  onMissingParent,
687
777
  onParentConflict
688
778
  } = params;
689
- const name = basename(params.name);
779
+ const rawName = basename(params.name);
780
+ const name = rawName ? sanitizeFileName(rawName) : rawName;
690
781
  const config = resolveConfig(vaultConfig);
691
782
  const file = new VaultFile({ config, name });
692
783
  await file._createFile({
@@ -727,7 +818,8 @@ class VaultFile {
727
818
  const config = resolveConfig(vaultConfig);
728
819
  const preparedFiles = await Promise.all(
729
820
  fileInputs.map(async (input) => {
730
- const name = basename(input.name) ?? getFileName(input.content);
821
+ const rawName = basename(input.name) ?? getFileName(input.content);
822
+ const name = rawName ? sanitizeFileName(rawName) : rawName;
731
823
  const sha256sum = await getFileHash(input.content);
732
824
  const mimeType = input.mimeType ?? await detectFileMimeType(input.content);
733
825
  const size = input.content.size;
@@ -810,7 +902,8 @@ class VaultFile {
810
902
  const { files: fileInputs, config: vaultConfig } = params;
811
903
  const config = resolveConfig(vaultConfig);
812
904
  const preparedFiles = fileInputs.map((input) => {
813
- const name = basename(input.name);
905
+ const rawName = basename(input.name);
906
+ const name = rawName ? sanitizeFileName(rawName) : rawName;
814
907
  const mimeType = input.contentType || "application/octet-stream";
815
908
  const size = input.contentLength;
816
909
  return { ...input, name, mimeType, size };
@@ -2010,12 +2103,22 @@ function vaultClient(vaultConfig) {
2010
2103
  config
2011
2104
  }, { signal: options?.signal });
2012
2105
  }
2013
- return { createFromContent, createFromReference, createFromStream, createFromContentBulk, createFromStreamBulk };
2106
+ const assets = {
2107
+ async create(params, options) {
2108
+ return await VaultAsset.create(config, params, { signal: options?.signal });
2109
+ },
2110
+ async createFromContent(content, params, options) {
2111
+ return await VaultAsset.fromContent(config, content, params, { signal: options?.signal });
2112
+ }
2113
+ };
2114
+ return { createFromContent, createFromReference, createFromStream, createFromContentBulk, createFromStreamBulk, assets };
2014
2115
  }
2015
2116
 
2016
2117
  exports.APIKeyAuthStrategy = APIKeyAuthStrategy;
2017
2118
  exports.DataTokenAuthStrategy = DataTokenAuthStrategy;
2018
2119
  exports.FetchError = FetchError;
2120
+ exports.Permalink = Permalink;
2121
+ exports.VaultAsset = VaultAsset;
2019
2122
  exports.VaultFile = VaultFile;
2020
2123
  exports.convertS3UrlToVaultReference = convertS3UrlToVaultReference;
2021
2124
  exports.extractVaultFileIdFromS3Url = extractVaultFileIdFromS3Url;
package/dist/index.d.cts CHANGED
@@ -28,6 +28,41 @@ type VaultConfig = {
28
28
  authStrategy: AuthStrategy;
29
29
  };
30
30
 
31
+ type CreateAssetUploadParams = {
32
+ assetClass: string;
33
+ mimeType: string;
34
+ size?: number;
35
+ };
36
+ type CreateAssetFromContentParams = {
37
+ assetClass: string;
38
+ mimeType?: string;
39
+ upload?: boolean;
40
+ };
41
+ type VaultAssetParams = {
42
+ assetId: string;
43
+ assetUrl: string | URL;
44
+ uploadUrl: string | URL;
45
+ expiresAt: string | Date;
46
+ uploadHeaders: Record<string, string>;
47
+ };
48
+ declare class VaultAsset {
49
+ readonly assetId: string;
50
+ readonly assetUrl: URL;
51
+ readonly uploadUrl: URL;
52
+ readonly expiresAt: Date;
53
+ readonly uploadHeaders: Record<string, string>;
54
+ constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders }: VaultAssetParams);
55
+ static create(vaultConfig: VaultConfig, params: CreateAssetUploadParams, options?: {
56
+ signal?: AbortSignal;
57
+ }): Promise<VaultAsset>;
58
+ static fromContent(vaultConfig: VaultConfig, content: Blob | File, params: CreateAssetFromContentParams, options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<VaultAsset>;
61
+ upload(content: Blob | File, options?: {
62
+ signal?: AbortSignal;
63
+ }): Promise<void>;
64
+ }
65
+
31
66
  declare class Permalink {
32
67
  private readonly config;
33
68
  readonly id: string;
@@ -1399,7 +1434,15 @@ declare function vaultClient(vaultConfig: VaultConfig): {
1399
1434
  }>, options?: {
1400
1435
  signal?: AbortSignal;
1401
1436
  }) => Promise<VaultFile[]>;
1437
+ assets: {
1438
+ create(params: CreateAssetUploadParams, options?: {
1439
+ signal?: AbortSignal;
1440
+ }): Promise<VaultAsset>;
1441
+ createFromContent(content: Blob | File, params: CreateAssetFromContentParams, options?: {
1442
+ signal?: AbortSignal;
1443
+ }): Promise<VaultAsset>;
1444
+ };
1402
1445
  };
1403
1446
 
1404
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1405
- export type { AuthStrategy, VaultConfig };
1447
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, Permalink, VaultAsset, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1448
+ export type { AuthStrategy, CreateAssetFromContentParams, CreateAssetUploadParams, VaultConfig };
package/dist/index.d.mts CHANGED
@@ -28,6 +28,41 @@ type VaultConfig = {
28
28
  authStrategy: AuthStrategy;
29
29
  };
30
30
 
31
+ type CreateAssetUploadParams = {
32
+ assetClass: string;
33
+ mimeType: string;
34
+ size?: number;
35
+ };
36
+ type CreateAssetFromContentParams = {
37
+ assetClass: string;
38
+ mimeType?: string;
39
+ upload?: boolean;
40
+ };
41
+ type VaultAssetParams = {
42
+ assetId: string;
43
+ assetUrl: string | URL;
44
+ uploadUrl: string | URL;
45
+ expiresAt: string | Date;
46
+ uploadHeaders: Record<string, string>;
47
+ };
48
+ declare class VaultAsset {
49
+ readonly assetId: string;
50
+ readonly assetUrl: URL;
51
+ readonly uploadUrl: URL;
52
+ readonly expiresAt: Date;
53
+ readonly uploadHeaders: Record<string, string>;
54
+ constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders }: VaultAssetParams);
55
+ static create(vaultConfig: VaultConfig, params: CreateAssetUploadParams, options?: {
56
+ signal?: AbortSignal;
57
+ }): Promise<VaultAsset>;
58
+ static fromContent(vaultConfig: VaultConfig, content: Blob | File, params: CreateAssetFromContentParams, options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<VaultAsset>;
61
+ upload(content: Blob | File, options?: {
62
+ signal?: AbortSignal;
63
+ }): Promise<void>;
64
+ }
65
+
31
66
  declare class Permalink {
32
67
  private readonly config;
33
68
  readonly id: string;
@@ -1399,7 +1434,15 @@ declare function vaultClient(vaultConfig: VaultConfig): {
1399
1434
  }>, options?: {
1400
1435
  signal?: AbortSignal;
1401
1436
  }) => Promise<VaultFile[]>;
1437
+ assets: {
1438
+ create(params: CreateAssetUploadParams, options?: {
1439
+ signal?: AbortSignal;
1440
+ }): Promise<VaultAsset>;
1441
+ createFromContent(content: Blob | File, params: CreateAssetFromContentParams, options?: {
1442
+ signal?: AbortSignal;
1443
+ }): Promise<VaultAsset>;
1444
+ };
1402
1445
  };
1403
1446
 
1404
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1405
- export type { AuthStrategy, VaultConfig };
1447
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, Permalink, VaultAsset, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1448
+ export type { AuthStrategy, CreateAssetFromContentParams, CreateAssetUploadParams, VaultConfig };
package/dist/index.d.ts CHANGED
@@ -28,6 +28,41 @@ type VaultConfig = {
28
28
  authStrategy: AuthStrategy;
29
29
  };
30
30
 
31
+ type CreateAssetUploadParams = {
32
+ assetClass: string;
33
+ mimeType: string;
34
+ size?: number;
35
+ };
36
+ type CreateAssetFromContentParams = {
37
+ assetClass: string;
38
+ mimeType?: string;
39
+ upload?: boolean;
40
+ };
41
+ type VaultAssetParams = {
42
+ assetId: string;
43
+ assetUrl: string | URL;
44
+ uploadUrl: string | URL;
45
+ expiresAt: string | Date;
46
+ uploadHeaders: Record<string, string>;
47
+ };
48
+ declare class VaultAsset {
49
+ readonly assetId: string;
50
+ readonly assetUrl: URL;
51
+ readonly uploadUrl: URL;
52
+ readonly expiresAt: Date;
53
+ readonly uploadHeaders: Record<string, string>;
54
+ constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders }: VaultAssetParams);
55
+ static create(vaultConfig: VaultConfig, params: CreateAssetUploadParams, options?: {
56
+ signal?: AbortSignal;
57
+ }): Promise<VaultAsset>;
58
+ static fromContent(vaultConfig: VaultConfig, content: Blob | File, params: CreateAssetFromContentParams, options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<VaultAsset>;
61
+ upload(content: Blob | File, options?: {
62
+ signal?: AbortSignal;
63
+ }): Promise<void>;
64
+ }
65
+
31
66
  declare class Permalink {
32
67
  private readonly config;
33
68
  readonly id: string;
@@ -1399,7 +1434,15 @@ declare function vaultClient(vaultConfig: VaultConfig): {
1399
1434
  }>, options?: {
1400
1435
  signal?: AbortSignal;
1401
1436
  }) => Promise<VaultFile[]>;
1437
+ assets: {
1438
+ create(params: CreateAssetUploadParams, options?: {
1439
+ signal?: AbortSignal;
1440
+ }): Promise<VaultAsset>;
1441
+ createFromContent(content: Blob | File, params: CreateAssetFromContentParams, options?: {
1442
+ signal?: AbortSignal;
1443
+ }): Promise<VaultAsset>;
1444
+ };
1402
1445
  };
1403
1446
 
1404
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1405
- export type { AuthStrategy, VaultConfig };
1447
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, Permalink, VaultAsset, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
1448
+ export type { AuthStrategy, CreateAssetFromContentParams, CreateAssetUploadParams, VaultConfig };