@meistrari/vault-sdk 3.3.0 → 3.4.1
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 +2 -2
- package/dist/index.cjs +102 -25
- package/dist/index.d.cts +224 -55
- package/dist/index.d.mts +224 -55
- package/dist/index.d.ts +224 -55
- package/dist/index.mjs +102 -25
- package/package.json +3 -11
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Vault SDK
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for interacting with the Vault file storage service. It supports file upload, download, streaming uploads, file hierarchies,
|
|
3
|
+
TypeScript SDK for interacting with the Vault file storage service. It supports file upload, download, streaming uploads, file hierarchies, assets, permalinks, and vault reference utilities.
|
|
4
4
|
|
|
5
|
-
Use the SDK when an application needs to store private files in Vault, publish stable
|
|
5
|
+
Use the SDK when an application needs to store private files in Vault, publish stable asset URLs such as avatars or logos, or keep durable `vault://` references instead of temporary presigned URLs.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const schemas = require('@meistrari/vault-shared/schemas');
|
|
4
4
|
const fileType = require('@meistrari/file-type');
|
|
5
5
|
const mimeTypes = require('mime-types');
|
|
6
|
-
const schemas = require('@meistrari/vault-shared/schemas');
|
|
7
6
|
const vaultUtils = require('@meistrari/vault-shared/utils');
|
|
8
7
|
|
|
9
8
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -78,7 +77,7 @@ async function getFileHash(blob) {
|
|
|
78
77
|
}
|
|
79
78
|
async function detectFileMimeType(blob) {
|
|
80
79
|
if (blob instanceof Blob && blob.type) {
|
|
81
|
-
return blob.type.split(";")[0]
|
|
80
|
+
return blob.type.split(";")[0]?.trim();
|
|
82
81
|
}
|
|
83
82
|
if ("name" in blob && typeof blob.name === "string") {
|
|
84
83
|
const extension = blob.name.split(".").pop()?.toLowerCase();
|
|
@@ -106,7 +105,7 @@ async function detectFileMimeType(blob) {
|
|
|
106
105
|
if (lines.length > 1) {
|
|
107
106
|
const commaCounts = lines.map((line) => (line.match(/,/g) || []).length);
|
|
108
107
|
const allSame = commaCounts.every((count) => count === commaCounts[0]);
|
|
109
|
-
if (allSame && commaCounts[0] > 0) {
|
|
108
|
+
if (allSame && (commaCounts[0] ?? 0) > 0) {
|
|
110
109
|
return "text/csv";
|
|
111
110
|
}
|
|
112
111
|
}
|
|
@@ -138,7 +137,7 @@ function getFileName(content) {
|
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
const name = "@meistrari/vault-sdk";
|
|
141
|
-
const version = "3.
|
|
140
|
+
const version = "3.4.1";
|
|
142
141
|
const license = "UNLICENSED";
|
|
143
142
|
const repository = {
|
|
144
143
|
type: "git",
|
|
@@ -156,17 +155,9 @@ const types = "dist/index.d.ts";
|
|
|
156
155
|
const files = [
|
|
157
156
|
"dist"
|
|
158
157
|
];
|
|
159
|
-
const scripts = {
|
|
160
|
-
test: "vitest --no-watch",
|
|
161
|
-
"test:watch": "vitest",
|
|
162
|
-
build: "unbuild",
|
|
163
|
-
lint: "eslint .",
|
|
164
|
-
"lint:fix": "eslint . --fix",
|
|
165
|
-
check: "bun run lint && bun tsc --noEmit"
|
|
166
|
-
};
|
|
167
158
|
const dependencies = {
|
|
168
|
-
"@meistrari/file-type": "22.0.0",
|
|
169
|
-
"@meistrari/vault-shared": "0.1
|
|
159
|
+
"@meistrari/file-type": "^22.0.0",
|
|
160
|
+
"@meistrari/vault-shared": "0.2.1",
|
|
170
161
|
"mime-types": "3.0.1",
|
|
171
162
|
ofetch: "1.4.1",
|
|
172
163
|
zod: "4.3.6"
|
|
@@ -193,7 +184,6 @@ const packageJson = {
|
|
|
193
184
|
main: main,
|
|
194
185
|
types: types,
|
|
195
186
|
files: files,
|
|
196
|
-
scripts: scripts,
|
|
197
187
|
dependencies: dependencies,
|
|
198
188
|
devDependencies: devDependencies,
|
|
199
189
|
peerDependencies: peerDependencies,
|
|
@@ -210,13 +200,6 @@ var __publicField$2 = (obj, key, value) => {
|
|
|
210
200
|
return value;
|
|
211
201
|
};
|
|
212
202
|
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
203
|
async function wrappedFetch$1(url, requestInit) {
|
|
221
204
|
const request = new Request(url, requestInit);
|
|
222
205
|
request.headers.set("User-Agent", userAgent);
|
|
@@ -228,18 +211,58 @@ async function wrappedFetch$1(url, requestInit) {
|
|
|
228
211
|
return response;
|
|
229
212
|
}
|
|
230
213
|
class VaultAsset {
|
|
231
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Constructs a VaultAsset instance from Vault response data.
|
|
216
|
+
*
|
|
217
|
+
* Direct usage of the constructor is not usually needed. Prefer
|
|
218
|
+
* {@link VaultAsset.create} or {@link VaultAsset.fromContent}.
|
|
219
|
+
*
|
|
220
|
+
* @param params - Values returned by Vault when creating an asset upload.
|
|
221
|
+
* @param params.assetId - Vault-assigned asset ID.
|
|
222
|
+
* @param params.assetUrl - Stable URL used to resolve or download the asset.
|
|
223
|
+
* @param params.uploadUrl - Presigned URL used to upload the asset content.
|
|
224
|
+
* @param params.expiresAt - Expiration time for the presigned upload URL.
|
|
225
|
+
* @param params.uploadHeaders - Headers required by the presigned upload URL.
|
|
226
|
+
* @param params.asset - Stored asset metadata returned by Vault.
|
|
227
|
+
*/
|
|
228
|
+
constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders, asset }) {
|
|
229
|
+
/** Vault-assigned asset ID. */
|
|
232
230
|
__publicField$2(this, "assetId");
|
|
231
|
+
/** Stable URL used to resolve or download the asset. */
|
|
233
232
|
__publicField$2(this, "assetUrl");
|
|
233
|
+
/** Presigned URL used to upload asset content. */
|
|
234
234
|
__publicField$2(this, "uploadUrl");
|
|
235
|
+
/** Expiration time for the presigned upload URL. */
|
|
235
236
|
__publicField$2(this, "expiresAt");
|
|
237
|
+
/** Headers that must be sent when uploading to {@link VaultAsset.uploadUrl}. */
|
|
236
238
|
__publicField$2(this, "uploadHeaders");
|
|
239
|
+
/** Stored asset metadata returned by Vault. */
|
|
240
|
+
__publicField$2(this, "asset");
|
|
237
241
|
this.assetId = assetId;
|
|
238
242
|
this.assetUrl = new URL(assetUrl);
|
|
239
243
|
this.uploadUrl = new URL(uploadUrl);
|
|
240
244
|
this.expiresAt = new Date(expiresAt);
|
|
241
245
|
this.uploadHeaders = uploadHeaders;
|
|
246
|
+
this.asset = asset;
|
|
242
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates an asset upload URL without uploading content.
|
|
250
|
+
*
|
|
251
|
+
* Use {@link VaultAsset.upload} to upload content later, or use
|
|
252
|
+
* {@link VaultAsset.fromContent} with `upload: true` to create and upload in one call.
|
|
253
|
+
*
|
|
254
|
+
* @param vaultConfig - Vault client configuration.
|
|
255
|
+
* @param params - Parameters for the asset upload.
|
|
256
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
257
|
+
* @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.
|
|
258
|
+
* @param params.mimeType - MIME type of the content that will be uploaded.
|
|
259
|
+
* @param params.size - Size of the content in bytes, when known.
|
|
260
|
+
* @param options - Additional options for the request.
|
|
261
|
+
* @param options.signal - Signal used to abort the request.
|
|
262
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
263
|
+
* @throws {FetchError} If Vault rejects the create request.
|
|
264
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
265
|
+
*/
|
|
243
266
|
static async create(vaultConfig, params, options) {
|
|
244
267
|
const config = resolveConfig(vaultConfig);
|
|
245
268
|
const headers = config.authStrategy.getHeaders();
|
|
@@ -250,19 +273,40 @@ class VaultAsset {
|
|
|
250
273
|
headers,
|
|
251
274
|
body: JSON.stringify({
|
|
252
275
|
assetClass: params.assetClass,
|
|
276
|
+
subject: params.subject,
|
|
253
277
|
mimeType: params.mimeType,
|
|
254
278
|
size: params.size
|
|
255
279
|
})
|
|
256
|
-
}).then(async (response2) => await response2.json()).then((data) =>
|
|
280
|
+
}).then(async (response2) => await response2.json()).then((data) => schemas.CreateAssetUploadResponse.safeParse(data));
|
|
257
281
|
if (!response.success) {
|
|
258
282
|
throw new Error(`Invalid response from vault service. ${JSON.stringify(response.error)}`);
|
|
259
283
|
}
|
|
260
284
|
return new VaultAsset(response.data);
|
|
261
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Creates an asset from Blob or File content.
|
|
288
|
+
*
|
|
289
|
+
* The SDK detects the MIME type when `params.mimeType` is omitted. Set
|
|
290
|
+
* `params.upload` to `true` to upload the content immediately.
|
|
291
|
+
*
|
|
292
|
+
* @param vaultConfig - Vault client configuration.
|
|
293
|
+
* @param content - Content to associate with the asset.
|
|
294
|
+
* @param params - Parameters for the asset.
|
|
295
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
296
|
+
* @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.
|
|
297
|
+
* @param params.mimeType - MIME type override for the content.
|
|
298
|
+
* @param params.upload - Whether to upload the content immediately after creating the asset.
|
|
299
|
+
* @param options - Additional options for the create and upload requests.
|
|
300
|
+
* @param options.signal - Signal used to abort either request.
|
|
301
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
302
|
+
* @throws {FetchError} If Vault rejects the create request or the upload request fails.
|
|
303
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
304
|
+
*/
|
|
262
305
|
static async fromContent(vaultConfig, content, params, options) {
|
|
263
306
|
const mimeType = params.mimeType ?? await detectFileMimeType(content) ?? "application/octet-stream";
|
|
264
307
|
const asset = await VaultAsset.create(vaultConfig, {
|
|
265
308
|
assetClass: params.assetClass,
|
|
309
|
+
subject: params.subject,
|
|
266
310
|
mimeType,
|
|
267
311
|
size: content.size
|
|
268
312
|
}, options);
|
|
@@ -271,6 +315,16 @@ class VaultAsset {
|
|
|
271
315
|
}
|
|
272
316
|
return asset;
|
|
273
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Uploads content to this asset's presigned upload URL.
|
|
320
|
+
*
|
|
321
|
+
* The upload request sends the headers returned by Vault when the asset was created.
|
|
322
|
+
*
|
|
323
|
+
* @param content - Content to upload.
|
|
324
|
+
* @param options - Additional options for the upload request.
|
|
325
|
+
* @param options.signal - Signal used to abort the upload.
|
|
326
|
+
* @throws {FetchError} If the upload endpoint returns an error response.
|
|
327
|
+
*/
|
|
274
328
|
async upload(content, options) {
|
|
275
329
|
await wrappedFetch$1(this.uploadUrl, {
|
|
276
330
|
method: "PUT",
|
|
@@ -2104,9 +2158,32 @@ function vaultClient(vaultConfig) {
|
|
|
2104
2158
|
}, { signal: options?.signal });
|
|
2105
2159
|
}
|
|
2106
2160
|
const assets = {
|
|
2161
|
+
/**
|
|
2162
|
+
* Creates an asset upload URL without uploading content.
|
|
2163
|
+
*
|
|
2164
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
2165
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
2166
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
2167
|
+
*
|
|
2168
|
+
* @param params - Parameters for the asset upload.
|
|
2169
|
+
* @param options - Additional options for the request.
|
|
2170
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
2171
|
+
*/
|
|
2107
2172
|
async create(params, options) {
|
|
2108
2173
|
return await VaultAsset.create(config, params, { signal: options?.signal });
|
|
2109
2174
|
},
|
|
2175
|
+
/**
|
|
2176
|
+
* Creates an asset from File or Blob content and optionally uploads it immediately.
|
|
2177
|
+
*
|
|
2178
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
2179
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
2180
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
2181
|
+
*
|
|
2182
|
+
* @param content - File or Blob content to associate with the asset.
|
|
2183
|
+
* @param params - Parameters for the asset.
|
|
2184
|
+
* @param options - Additional options for the create and upload requests.
|
|
2185
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
2186
|
+
*/
|
|
2110
2187
|
async createFromContent(content, params, options) {
|
|
2111
2188
|
return await VaultAsset.fromContent(config, content, params, { signal: options?.signal });
|
|
2112
2189
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SerializedPermalink, FileMetadata } from '@meistrari/vault-shared/schemas';
|
|
1
|
+
import { AssetMetadata, SerializedPermalink, FileMetadata } from '@meistrari/vault-shared/schemas';
|
|
2
|
+
export { AssetMetadata } from '@meistrari/vault-shared/schemas';
|
|
2
3
|
|
|
3
4
|
interface AuthStrategy {
|
|
4
5
|
getHeaders: () => Headers;
|
|
@@ -28,36 +29,145 @@ type VaultConfig = {
|
|
|
28
29
|
authStrategy: AuthStrategy;
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Parameters for creating an asset upload URL.
|
|
34
|
+
*/
|
|
31
35
|
type CreateAssetUploadParams = {
|
|
36
|
+
/** Application-defined class for grouping assets, such as `avatar` or `cover-image`. */
|
|
32
37
|
assetClass: string;
|
|
38
|
+
/**
|
|
39
|
+
* Opaque application-owned entity reference for this asset.
|
|
40
|
+
*
|
|
41
|
+
* Use a stable, namespaced value that points to the domain object the asset represents
|
|
42
|
+
* or belongs to, such as `user:user_123`, `organization:org_123`, or `app:app_123`.
|
|
43
|
+
* Vault stores this value for lookup and cleanup workflows but does not interpret it,
|
|
44
|
+
* enforce authorization from it, or include it in the stable asset URL.
|
|
45
|
+
*/
|
|
46
|
+
subject: string;
|
|
47
|
+
/** MIME type of the content that will be uploaded. */
|
|
33
48
|
mimeType: string;
|
|
49
|
+
/** Size of the content in bytes, when known. */
|
|
34
50
|
size?: number;
|
|
35
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Parameters for creating an asset from in-memory content.
|
|
54
|
+
*/
|
|
36
55
|
type CreateAssetFromContentParams = {
|
|
56
|
+
/** Application-defined class for grouping assets, such as `avatar` or `cover-image`. */
|
|
37
57
|
assetClass: string;
|
|
58
|
+
/**
|
|
59
|
+
* Opaque application-owned entity reference for this asset.
|
|
60
|
+
*
|
|
61
|
+
* Use a stable, namespaced value that points to the domain object the asset represents
|
|
62
|
+
* or belongs to, such as `user:user_123`, `organization:org_123`, or `app:app_123`.
|
|
63
|
+
* Vault stores this value for lookup and cleanup workflows but does not interpret it,
|
|
64
|
+
* enforce authorization from it, or include it in the stable asset URL.
|
|
65
|
+
*/
|
|
66
|
+
subject: string;
|
|
67
|
+
/** MIME type override. When omitted, the SDK attempts to detect the content type. */
|
|
38
68
|
mimeType?: string;
|
|
69
|
+
/** Whether to upload the content immediately after creating the asset. */
|
|
39
70
|
upload?: boolean;
|
|
40
71
|
};
|
|
72
|
+
/** Values required to construct a VaultAsset instance. */
|
|
41
73
|
type VaultAssetParams = {
|
|
74
|
+
/** Vault-assigned asset ID. */
|
|
42
75
|
assetId: string;
|
|
76
|
+
/** Stable URL used to resolve or download the asset. */
|
|
43
77
|
assetUrl: string | URL;
|
|
78
|
+
/** Presigned URL used to upload the asset content. */
|
|
44
79
|
uploadUrl: string | URL;
|
|
80
|
+
/** Expiration time for the presigned upload URL. */
|
|
45
81
|
expiresAt: string | Date;
|
|
82
|
+
/** Headers that must be sent with the presigned upload request. */
|
|
46
83
|
uploadHeaders: Record<string, string>;
|
|
84
|
+
/** Stored asset metadata returned by Vault. */
|
|
85
|
+
asset: AssetMetadata;
|
|
47
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Represents a Vault asset with a stable asset URL and a presigned upload URL.
|
|
89
|
+
*/
|
|
48
90
|
declare class VaultAsset {
|
|
91
|
+
/** Vault-assigned asset ID. */
|
|
49
92
|
readonly assetId: string;
|
|
93
|
+
/** Stable URL used to resolve or download the asset. */
|
|
50
94
|
readonly assetUrl: URL;
|
|
95
|
+
/** Presigned URL used to upload asset content. */
|
|
51
96
|
readonly uploadUrl: URL;
|
|
97
|
+
/** Expiration time for the presigned upload URL. */
|
|
52
98
|
readonly expiresAt: Date;
|
|
99
|
+
/** Headers that must be sent when uploading to {@link VaultAsset.uploadUrl}. */
|
|
53
100
|
readonly uploadHeaders: Record<string, string>;
|
|
54
|
-
|
|
101
|
+
/** Stored asset metadata returned by Vault. */
|
|
102
|
+
readonly asset: AssetMetadata;
|
|
103
|
+
/**
|
|
104
|
+
* Constructs a VaultAsset instance from Vault response data.
|
|
105
|
+
*
|
|
106
|
+
* Direct usage of the constructor is not usually needed. Prefer
|
|
107
|
+
* {@link VaultAsset.create} or {@link VaultAsset.fromContent}.
|
|
108
|
+
*
|
|
109
|
+
* @param params - Values returned by Vault when creating an asset upload.
|
|
110
|
+
* @param params.assetId - Vault-assigned asset ID.
|
|
111
|
+
* @param params.assetUrl - Stable URL used to resolve or download the asset.
|
|
112
|
+
* @param params.uploadUrl - Presigned URL used to upload the asset content.
|
|
113
|
+
* @param params.expiresAt - Expiration time for the presigned upload URL.
|
|
114
|
+
* @param params.uploadHeaders - Headers required by the presigned upload URL.
|
|
115
|
+
* @param params.asset - Stored asset metadata returned by Vault.
|
|
116
|
+
*/
|
|
117
|
+
constructor({ assetId, assetUrl, uploadUrl, expiresAt, uploadHeaders, asset }: VaultAssetParams);
|
|
118
|
+
/**
|
|
119
|
+
* Creates an asset upload URL without uploading content.
|
|
120
|
+
*
|
|
121
|
+
* Use {@link VaultAsset.upload} to upload content later, or use
|
|
122
|
+
* {@link VaultAsset.fromContent} with `upload: true` to create and upload in one call.
|
|
123
|
+
*
|
|
124
|
+
* @param vaultConfig - Vault client configuration.
|
|
125
|
+
* @param params - Parameters for the asset upload.
|
|
126
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
127
|
+
* @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.
|
|
128
|
+
* @param params.mimeType - MIME type of the content that will be uploaded.
|
|
129
|
+
* @param params.size - Size of the content in bytes, when known.
|
|
130
|
+
* @param options - Additional options for the request.
|
|
131
|
+
* @param options.signal - Signal used to abort the request.
|
|
132
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
133
|
+
* @throws {FetchError} If Vault rejects the create request.
|
|
134
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
135
|
+
*/
|
|
55
136
|
static create(vaultConfig: VaultConfig, params: CreateAssetUploadParams, options?: {
|
|
56
137
|
signal?: AbortSignal;
|
|
57
138
|
}): Promise<VaultAsset>;
|
|
139
|
+
/**
|
|
140
|
+
* Creates an asset from Blob or File content.
|
|
141
|
+
*
|
|
142
|
+
* The SDK detects the MIME type when `params.mimeType` is omitted. Set
|
|
143
|
+
* `params.upload` to `true` to upload the content immediately.
|
|
144
|
+
*
|
|
145
|
+
* @param vaultConfig - Vault client configuration.
|
|
146
|
+
* @param content - Content to associate with the asset.
|
|
147
|
+
* @param params - Parameters for the asset.
|
|
148
|
+
* @param params.assetClass - Application-defined class for grouping assets.
|
|
149
|
+
* @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.
|
|
150
|
+
* @param params.mimeType - MIME type override for the content.
|
|
151
|
+
* @param params.upload - Whether to upload the content immediately after creating the asset.
|
|
152
|
+
* @param options - Additional options for the create and upload requests.
|
|
153
|
+
* @param options.signal - Signal used to abort either request.
|
|
154
|
+
* @returns A VaultAsset containing the asset URL and presigned upload URL.
|
|
155
|
+
* @throws {FetchError} If Vault rejects the create request or the upload request fails.
|
|
156
|
+
* @throws {Error} If Vault returns a response that does not match the SDK schema.
|
|
157
|
+
*/
|
|
58
158
|
static fromContent(vaultConfig: VaultConfig, content: Blob | File, params: CreateAssetFromContentParams, options?: {
|
|
59
159
|
signal?: AbortSignal;
|
|
60
160
|
}): Promise<VaultAsset>;
|
|
161
|
+
/**
|
|
162
|
+
* Uploads content to this asset's presigned upload URL.
|
|
163
|
+
*
|
|
164
|
+
* The upload request sends the headers returned by Vault when the asset was created.
|
|
165
|
+
*
|
|
166
|
+
* @param content - Content to upload.
|
|
167
|
+
* @param options - Additional options for the upload request.
|
|
168
|
+
* @param options.signal - Signal used to abort the upload.
|
|
169
|
+
* @throws {FetchError} If the upload endpoint returns an error response.
|
|
170
|
+
*/
|
|
61
171
|
upload(content: Blob | File, options?: {
|
|
62
172
|
signal?: AbortSignal;
|
|
63
173
|
}): Promise<void>;
|
|
@@ -1384,63 +1494,122 @@ declare function getVaultParamsFromS3Url(url: string): {
|
|
|
1384
1494
|
parentId: string | null;
|
|
1385
1495
|
} | null;
|
|
1386
1496
|
|
|
1497
|
+
/** Options shared by content-based file creation overloads. */
|
|
1498
|
+
type CreateFromContentOptions = {
|
|
1499
|
+
/** Signal used to abort the request. */
|
|
1500
|
+
signal?: AbortSignal;
|
|
1501
|
+
/** Parent file ID for hierarchical file relationships. */
|
|
1502
|
+
parentId?: string;
|
|
1503
|
+
/** MIME type override for the uploaded content. */
|
|
1504
|
+
mimeType?: string;
|
|
1505
|
+
/** Whether to upload the content immediately after creating the file metadata. */
|
|
1506
|
+
upload?: boolean;
|
|
1507
|
+
};
|
|
1508
|
+
/** Options for fetching an existing Vault file by reference. */
|
|
1509
|
+
type CreateFromReferenceOptions = {
|
|
1510
|
+
/** Signal used to abort the request. */
|
|
1511
|
+
signal?: AbortSignal;
|
|
1512
|
+
};
|
|
1513
|
+
/** Options for stream-based file creation. */
|
|
1514
|
+
type CreateFromStreamOptions = {
|
|
1515
|
+
/** MIME type of the stream content. */
|
|
1516
|
+
contentType?: string;
|
|
1517
|
+
/** Signal used to abort the request. */
|
|
1518
|
+
signal?: AbortSignal;
|
|
1519
|
+
/** Parent file ID for hierarchical file relationships. */
|
|
1520
|
+
parentId?: string;
|
|
1521
|
+
};
|
|
1522
|
+
/** File input used by bulk content creation. */
|
|
1523
|
+
type CreateFromContentBulkFile = {
|
|
1524
|
+
/** File or Blob content to register and optionally upload. */
|
|
1525
|
+
content: Blob | File;
|
|
1526
|
+
/** File name override. */
|
|
1527
|
+
name?: string;
|
|
1528
|
+
/** MIME type override for the content. */
|
|
1529
|
+
mimeType?: string;
|
|
1530
|
+
/** Parent file ID for hierarchical file relationships. */
|
|
1531
|
+
parentId?: string;
|
|
1532
|
+
/** Behavior when the requested parent cannot be found. */
|
|
1533
|
+
onMissingParent?: 'error' | 'create-as-root';
|
|
1534
|
+
/** Behavior when the file already exists under a different parent. */
|
|
1535
|
+
onParentConflict?: 'error' | 'update-parent-id' | 'ignore';
|
|
1536
|
+
};
|
|
1537
|
+
/** Options for bulk content creation. */
|
|
1538
|
+
type CreateFromContentBulkOptions = {
|
|
1539
|
+
/** Whether to upload all created files immediately. */
|
|
1540
|
+
upload?: boolean;
|
|
1541
|
+
/** Signal used to abort the request. */
|
|
1542
|
+
signal?: AbortSignal;
|
|
1543
|
+
};
|
|
1544
|
+
/** File input used by bulk stream creation. */
|
|
1545
|
+
type CreateFromStreamBulkFile = {
|
|
1546
|
+
/** Name of the file represented by the stream. */
|
|
1547
|
+
name: string;
|
|
1548
|
+
/** Size of the stream content in bytes. */
|
|
1549
|
+
contentLength: number;
|
|
1550
|
+
/** MIME type of the stream content. */
|
|
1551
|
+
contentType?: string;
|
|
1552
|
+
/** Parent file ID for hierarchical file relationships. */
|
|
1553
|
+
parentId?: string;
|
|
1554
|
+
/** Behavior when the requested parent cannot be found. */
|
|
1555
|
+
onMissingParent?: 'error' | 'create-as-root';
|
|
1556
|
+
/** Behavior when the file already exists under a different parent. */
|
|
1557
|
+
onParentConflict?: 'error' | 'update-parent-id' | 'ignore';
|
|
1558
|
+
};
|
|
1559
|
+
/** Options for bulk stream creation. */
|
|
1560
|
+
type CreateFromStreamBulkOptions = {
|
|
1561
|
+
/** Signal used to abort the request. */
|
|
1562
|
+
signal?: AbortSignal;
|
|
1563
|
+
};
|
|
1564
|
+
/** Options shared by asset creation helpers. */
|
|
1565
|
+
type AssetRequestOptions = {
|
|
1566
|
+
/** Signal used to abort the request. */
|
|
1567
|
+
signal?: AbortSignal;
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Creates a Vault SDK client bound to a Vault URL and auth strategy.
|
|
1571
|
+
*
|
|
1572
|
+
* @param vaultConfig - Vault client configuration.
|
|
1573
|
+
* @param vaultConfig.vaultUrl - Base URL for the Vault API.
|
|
1574
|
+
* @param vaultConfig.authStrategy - Auth strategy used to sign Vault requests.
|
|
1575
|
+
* @returns Client helpers for files, streams, bulk creation, references, and assets.
|
|
1576
|
+
*/
|
|
1387
1577
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
1388
1578
|
createFromContent: {
|
|
1389
|
-
(name: string, content: Blob | File, options?:
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
mimeType?: string;
|
|
1393
|
-
upload?: boolean;
|
|
1394
|
-
}): Promise<VaultFile>;
|
|
1395
|
-
(content: Blob | File, name?: string, options?: {
|
|
1396
|
-
signal?: AbortSignal;
|
|
1397
|
-
parentId?: string;
|
|
1398
|
-
mimeType?: string;
|
|
1399
|
-
upload?: boolean;
|
|
1400
|
-
}): Promise<VaultFile>;
|
|
1401
|
-
(content: Blob | File, options: {
|
|
1402
|
-
signal?: AbortSignal;
|
|
1403
|
-
parentId?: string;
|
|
1404
|
-
mimeType?: string;
|
|
1405
|
-
upload?: boolean;
|
|
1406
|
-
}): Promise<VaultFile>;
|
|
1579
|
+
(name: string, content: Blob | File, options?: CreateFromContentOptions): Promise<VaultFile>;
|
|
1580
|
+
(content: Blob | File, name?: string, options?: CreateFromContentOptions): Promise<VaultFile>;
|
|
1581
|
+
(content: Blob | File, options: CreateFromContentOptions): Promise<VaultFile>;
|
|
1407
1582
|
};
|
|
1408
|
-
createFromReference: (reference: string, options?:
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
contentType?: string;
|
|
1413
|
-
signal?: AbortSignal;
|
|
1414
|
-
parentId?: string;
|
|
1415
|
-
}) => Promise<VaultFile>;
|
|
1416
|
-
createFromContentBulk: (files: Array<{
|
|
1417
|
-
content: Blob | File;
|
|
1418
|
-
name?: string;
|
|
1419
|
-
mimeType?: string;
|
|
1420
|
-
parentId?: string;
|
|
1421
|
-
onMissingParent?: "error" | "create-as-root";
|
|
1422
|
-
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1423
|
-
}>, options?: {
|
|
1424
|
-
upload?: boolean;
|
|
1425
|
-
signal?: AbortSignal;
|
|
1426
|
-
}) => Promise<VaultFile[]>;
|
|
1427
|
-
createFromStreamBulk: (files: Array<{
|
|
1428
|
-
name: string;
|
|
1429
|
-
contentLength: number;
|
|
1430
|
-
contentType?: string;
|
|
1431
|
-
parentId?: string;
|
|
1432
|
-
onMissingParent?: "error" | "create-as-root";
|
|
1433
|
-
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1434
|
-
}>, options?: {
|
|
1435
|
-
signal?: AbortSignal;
|
|
1436
|
-
}) => Promise<VaultFile[]>;
|
|
1583
|
+
createFromReference: (reference: string, options?: CreateFromReferenceOptions) => Promise<VaultFile>;
|
|
1584
|
+
createFromStream: (name: string, contentLength: number, options?: CreateFromStreamOptions) => Promise<VaultFile>;
|
|
1585
|
+
createFromContentBulk: (files: CreateFromContentBulkFile[], options?: CreateFromContentBulkOptions) => Promise<VaultFile[]>;
|
|
1586
|
+
createFromStreamBulk: (files: CreateFromStreamBulkFile[], options?: CreateFromStreamBulkOptions) => Promise<VaultFile[]>;
|
|
1437
1587
|
assets: {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1588
|
+
/**
|
|
1589
|
+
* Creates an asset upload URL without uploading content.
|
|
1590
|
+
*
|
|
1591
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
1592
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
1593
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
1594
|
+
*
|
|
1595
|
+
* @param params - Parameters for the asset upload.
|
|
1596
|
+
* @param options - Additional options for the request.
|
|
1597
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
1598
|
+
*/
|
|
1599
|
+
create(params: CreateAssetUploadParams, options?: AssetRequestOptions): Promise<VaultAsset>;
|
|
1600
|
+
/**
|
|
1601
|
+
* Creates an asset from File or Blob content and optionally uploads it immediately.
|
|
1602
|
+
*
|
|
1603
|
+
* `params.subject` should be a stable application-owned entity reference such as
|
|
1604
|
+
* `user:user_123` or `organization:org_123`. Vault stores it for lookup and cleanup,
|
|
1605
|
+
* but does not interpret it, enforce authorization from it, or include it in the asset URL.
|
|
1606
|
+
*
|
|
1607
|
+
* @param content - File or Blob content to associate with the asset.
|
|
1608
|
+
* @param params - Parameters for the asset.
|
|
1609
|
+
* @param options - Additional options for the create and upload requests.
|
|
1610
|
+
* @returns A VaultAsset with the stable asset URL and presigned upload URL.
|
|
1611
|
+
*/
|
|
1612
|
+
createFromContent(content: Blob | File, params: CreateAssetFromContentParams, options?: AssetRequestOptions): Promise<VaultAsset>;
|
|
1444
1613
|
};
|
|
1445
1614
|
};
|
|
1446
1615
|
|