@meistrari/vault-sdk 1.8.3 → 2.0.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 +244 -38
- package/dist/index.d.cts +174 -7
- package/dist/index.d.mts +174 -7
- package/dist/index.d.ts +174 -7
- package/dist/index.mjs +241 -38
- package/package.json +47 -47
package/dist/index.d.cts
CHANGED
|
@@ -88,6 +88,22 @@ type VaultFileParams = {
|
|
|
88
88
|
config: VaultConfig;
|
|
89
89
|
};
|
|
90
90
|
type OnMissingParent = 'error' | 'create-as-root';
|
|
91
|
+
type OnParentConflict = 'error' | 'update-parent-id' | 'ignore';
|
|
92
|
+
/**
|
|
93
|
+
* Parameters for updating metadata of a VaultFile.
|
|
94
|
+
*/
|
|
95
|
+
interface VaultFileUpdateMetadataParams {
|
|
96
|
+
/** The new name to assign to the file. If not provided, the name will not be changed. */
|
|
97
|
+
name?: string;
|
|
98
|
+
}
|
|
99
|
+
type BulkFileInput = {
|
|
100
|
+
content: Blob | File;
|
|
101
|
+
name?: string;
|
|
102
|
+
mimeType?: string;
|
|
103
|
+
parentId?: string;
|
|
104
|
+
onMissingParent?: OnMissingParent;
|
|
105
|
+
onParentConflict?: OnParentConflict;
|
|
106
|
+
};
|
|
91
107
|
/**
|
|
92
108
|
* Represents a file in the vault and allows interacting with it.
|
|
93
109
|
*
|
|
@@ -154,6 +170,7 @@ declare class VaultFile {
|
|
|
154
170
|
* @param metadata.mimeType - The mime type of the file
|
|
155
171
|
* @param metadata.parentId - The ID of the parent file for hierarchical file relationships
|
|
156
172
|
* @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
173
|
+
* @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
|
|
157
174
|
* @param options - The options for the request
|
|
158
175
|
* @param options.signal - The signal to abort the request
|
|
159
176
|
*
|
|
@@ -219,6 +236,7 @@ declare class VaultFile {
|
|
|
219
236
|
* @param params.upload - Whether to upload the file (default: false)
|
|
220
237
|
* @param params.parentId - The ID of the parent file for hierarchical file relationships
|
|
221
238
|
* @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
239
|
+
* @param params.onParentConflict - What to do if the file already exists as an active child of another file
|
|
222
240
|
* @param options - The options for the request
|
|
223
241
|
* @param options.signal - The signal to abort the request
|
|
224
242
|
*
|
|
@@ -278,6 +296,7 @@ declare class VaultFile {
|
|
|
278
296
|
upload?: boolean;
|
|
279
297
|
parentId?: string;
|
|
280
298
|
onMissingParent?: OnMissingParent;
|
|
299
|
+
onParentConflict?: OnParentConflict;
|
|
281
300
|
}, options?: {
|
|
282
301
|
signal?: AbortSignal;
|
|
283
302
|
}): Promise<VaultFile>;
|
|
@@ -292,6 +311,7 @@ declare class VaultFile {
|
|
|
292
311
|
* @param params.contentType - The MIME type of the content (optional)
|
|
293
312
|
* @param params.parentId - The ID of the parent file for hierarchical file relationships
|
|
294
313
|
* @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
314
|
+
* @param params.onParentConflict - What to do if the file already exists as an active child of another file
|
|
295
315
|
* @param options - The options for the request
|
|
296
316
|
* @param options.signal - The signal to abort the request
|
|
297
317
|
*
|
|
@@ -334,9 +354,41 @@ declare class VaultFile {
|
|
|
334
354
|
contentType?: string;
|
|
335
355
|
parentId?: string;
|
|
336
356
|
onMissingParent?: OnMissingParent;
|
|
357
|
+
onParentConflict?: OnParentConflict;
|
|
337
358
|
}, options?: {
|
|
338
359
|
signal?: AbortSignal;
|
|
339
360
|
}): Promise<VaultFile>;
|
|
361
|
+
/**
|
|
362
|
+
* Creates multiple VaultFile instances from given content in a single request.
|
|
363
|
+
*
|
|
364
|
+
* @param params - Parameters for creating VaultFiles from content
|
|
365
|
+
* @param params.files - Array of file inputs with content and optional metadata
|
|
366
|
+
* @param params.config - The configuration for the VaultFiles
|
|
367
|
+
* @param params.upload - Whether to upload all files (default: false)
|
|
368
|
+
* @param options - The options for the request
|
|
369
|
+
* @param options.signal - The signal to abort the request
|
|
370
|
+
*
|
|
371
|
+
* @returns Array of new VaultFile instances
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* const files = await VaultFile.fromContentBulk({
|
|
376
|
+
* files: [
|
|
377
|
+
* { content: blob1, name: 'file1.txt' },
|
|
378
|
+
* { content: blob2, name: 'file2.txt', parentId: 'parent-id' },
|
|
379
|
+
* ],
|
|
380
|
+
* config: { vaultUrl, authStrategy },
|
|
381
|
+
* upload: true
|
|
382
|
+
* })
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
static fromContentBulk(params: {
|
|
386
|
+
files: BulkFileInput[];
|
|
387
|
+
config: VaultConfig;
|
|
388
|
+
upload?: boolean;
|
|
389
|
+
}, options?: {
|
|
390
|
+
signal?: AbortSignal;
|
|
391
|
+
}): Promise<VaultFile[]>;
|
|
340
392
|
/**
|
|
341
393
|
* Fetches and populates the metadata fields for this VaultFile instance.
|
|
342
394
|
*
|
|
@@ -1104,6 +1156,61 @@ declare class VaultFile {
|
|
|
1104
1156
|
* ```
|
|
1105
1157
|
*/
|
|
1106
1158
|
createChildFromStream(params: Omit<Parameters<typeof VaultFile.fromStream>[0], 'config' | 'parentId'>, options?: Parameters<typeof VaultFile.fromStream>[1]): Promise<VaultFile>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Updates the metadata of this file in the vault.
|
|
1161
|
+
*
|
|
1162
|
+
* This method allows you to modify specific metadata properties of the file, such as renaming it.
|
|
1163
|
+
* The instance's metadata property is automatically updated with the response from the server.
|
|
1164
|
+
* Only the provided parameters will be updated; all other metadata remains unchanged.
|
|
1165
|
+
*
|
|
1166
|
+
* @param params - The metadata properties to update
|
|
1167
|
+
* @param params.name - The new name to assign to the file
|
|
1168
|
+
* @param options - Additional options for the request
|
|
1169
|
+
* @param options.signal - AbortSignal to cancel the request
|
|
1170
|
+
*
|
|
1171
|
+
* @returns A Promise that resolves when the update completes successfully
|
|
1172
|
+
* @throws {Error} If the file ID is not set
|
|
1173
|
+
* @throws {FetchError} If the update request fails
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```ts
|
|
1177
|
+
* // Rename a file
|
|
1178
|
+
* const vaultFile = await VaultFile.fromVaultReference({
|
|
1179
|
+
* reference: 'vault://file-id',
|
|
1180
|
+
* config: { vaultUrl, authStrategy }
|
|
1181
|
+
* })
|
|
1182
|
+
* await vaultFile.updateMetadata({ name: 'new-name.txt' })
|
|
1183
|
+
* console.log('File renamed to:', vaultFile.metadata?.originalFileName)
|
|
1184
|
+
* ```
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```ts
|
|
1188
|
+
* // Rename a file with abort signal
|
|
1189
|
+
* const controller = new AbortController()
|
|
1190
|
+
* await vaultFile.updateMetadata(
|
|
1191
|
+
* { name: 'document-v2.pdf' },
|
|
1192
|
+
* { signal: controller.signal }
|
|
1193
|
+
* )
|
|
1194
|
+
* // Later: controller.abort()
|
|
1195
|
+
* ```
|
|
1196
|
+
*
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```ts
|
|
1199
|
+
* // Rename after upload
|
|
1200
|
+
* const file = new File(['content'], 'temp.txt')
|
|
1201
|
+
* const vaultFile = await VaultFile.fromContent({
|
|
1202
|
+
* name: 'temp.txt',
|
|
1203
|
+
* content: file,
|
|
1204
|
+
* config: { vaultUrl, authStrategy },
|
|
1205
|
+
* upload: true
|
|
1206
|
+
* })
|
|
1207
|
+
* // Later, rename the file
|
|
1208
|
+
* await vaultFile.updateMetadata({ name: 'final-document.txt' })
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
updateMetadata(params: VaultFileUpdateMetadataParams, options?: {
|
|
1212
|
+
signal?: AbortSignal;
|
|
1213
|
+
}): Promise<void>;
|
|
1107
1214
|
}
|
|
1108
1215
|
|
|
1109
1216
|
/**
|
|
@@ -1115,19 +1222,41 @@ declare class VaultFile {
|
|
|
1115
1222
|
*/
|
|
1116
1223
|
declare function isS3UrlExpired(url: string): boolean;
|
|
1117
1224
|
/**
|
|
1118
|
-
* Checks if a URL is a valid
|
|
1119
|
-
* @param url - The
|
|
1120
|
-
* @returns true if the URL is a valid
|
|
1225
|
+
* Checks if a URL is a valid vault reference
|
|
1226
|
+
* @param url - The URL to check
|
|
1227
|
+
* @returns true if the URL is a valid vault reference, false otherwise
|
|
1228
|
+
*/
|
|
1229
|
+
declare function isVaultReference(url: string): boolean;
|
|
1230
|
+
/**
|
|
1231
|
+
* Checks if a URL seems like a valid presigned S3 URL, with no additional checks.
|
|
1232
|
+
*
|
|
1233
|
+
* For usage with legacy URLs only. For new URLs, use {@link isTaggedVaultPresignedUrl} instead,
|
|
1234
|
+
* since this function only checks if the URL is a valid S3 URL, not if it was generated by Vault.
|
|
1235
|
+
*
|
|
1236
|
+
* @param url - The URL to check
|
|
1237
|
+
* @returns true if the URL is a valid S3 URL, false otherwise
|
|
1121
1238
|
*/
|
|
1122
|
-
declare function
|
|
1239
|
+
declare function isPresignedS3Url(url: string): boolean;
|
|
1123
1240
|
/**
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1241
|
+
* Extracts the vault file ID from an S3 presigned URL.
|
|
1242
|
+
* Supports multiple URL formats: tagged vault URLs, vault references, and legacy URL formats.
|
|
1243
|
+
*
|
|
1244
|
+
* @param url - The S3 URL to extract the vault file ID from
|
|
1245
|
+
* @returns The vault file ID (UUID or SHA-256 hash) if extraction succeeds, null otherwise
|
|
1246
|
+
* @example
|
|
1247
|
+
* // Tagged vault URL
|
|
1248
|
+
* extractVaultFileIdFromS3Url('https://vault-prod.s3.amazonaws.com/file?vault-file-id=abc123...')
|
|
1249
|
+
* // Returns: 'abc123...'
|
|
1250
|
+
*
|
|
1251
|
+
* // Vault reference
|
|
1252
|
+
* extractVaultFileIdFromS3Url('vault://2fce5740-83da-49fe-3f10-b32205893ec0')
|
|
1253
|
+
* // Returns: '2fce5740-83da-49fe-3f10-b32205893ec0'
|
|
1126
1254
|
*/
|
|
1127
1255
|
declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
1128
1256
|
/**
|
|
1129
1257
|
* Converts an S3 vault URL to a vault reference format
|
|
1130
1258
|
* Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
|
|
1259
|
+
*
|
|
1131
1260
|
* @param url - The S3 vault URL to convert
|
|
1132
1261
|
* @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
|
|
1133
1262
|
* @example
|
|
@@ -1135,6 +1264,33 @@ declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
|
1135
1264
|
* // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
|
|
1136
1265
|
*/
|
|
1137
1266
|
declare function convertS3UrlToVaultReference(url: string): string | null;
|
|
1267
|
+
/**
|
|
1268
|
+
* Checks if a URL is a tagged vault presigned S3 URL.
|
|
1269
|
+
* Tagged URLs contain vault-specific query parameters (vault-workspace-id, vault-file-id)
|
|
1270
|
+
* that identify the vault workspace and file.
|
|
1271
|
+
*
|
|
1272
|
+
* @param url - The URL to check
|
|
1273
|
+
* @returns true if the URL is a tagged vault presigned URL with valid workspace and file IDs, false otherwise
|
|
1274
|
+
* @example
|
|
1275
|
+
* const isTagged = isTaggedVaultPresignedUrl('https://vault-prod.s3.amazonaws.com/file?vault-workspace-id=abc-123&vault-file-id=def456...')
|
|
1276
|
+
* // Returns: true
|
|
1277
|
+
*/
|
|
1278
|
+
declare function isTaggedVaultPresignedUrl(url: string): boolean;
|
|
1279
|
+
/**
|
|
1280
|
+
* Extracts vault-specific parameters from a tagged vault presigned S3 URL.
|
|
1281
|
+
* Returns workspace ID, file ID, and optional parent ID from the URL query parameters.
|
|
1282
|
+
*
|
|
1283
|
+
* @param url - The tagged vault S3 URL to parse
|
|
1284
|
+
* @returns An object containing fileId, workspaceId, and parentId (if present), or null if the URL is not a tagged vault URL
|
|
1285
|
+
* @example
|
|
1286
|
+
* const params = getVaultParamsFromS3Url('https://vault-prod.s3.amazonaws.com/file?vault-workspace-id=abc-123&vault-file-id=def456&vault-parent-id=parent789')
|
|
1287
|
+
* // Returns: { fileId: 'def456', workspaceId: 'abc-123', parentId: 'parent789' }
|
|
1288
|
+
*/
|
|
1289
|
+
declare function getVaultParamsFromS3Url(url: string): {
|
|
1290
|
+
fileId: string | null;
|
|
1291
|
+
workspaceId: string | null;
|
|
1292
|
+
parentId: string | null;
|
|
1293
|
+
} | null;
|
|
1138
1294
|
|
|
1139
1295
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
1140
1296
|
createFromContent: {
|
|
@@ -1165,7 +1321,18 @@ declare function vaultClient(vaultConfig: VaultConfig): {
|
|
|
1165
1321
|
signal?: AbortSignal;
|
|
1166
1322
|
parentId?: string;
|
|
1167
1323
|
}) => Promise<VaultFile>;
|
|
1324
|
+
createFromContentBulk: (files: Array<{
|
|
1325
|
+
content: Blob | File;
|
|
1326
|
+
name?: string;
|
|
1327
|
+
mimeType?: string;
|
|
1328
|
+
parentId?: string;
|
|
1329
|
+
onMissingParent?: "error" | "create-as-root";
|
|
1330
|
+
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1331
|
+
}>, options?: {
|
|
1332
|
+
upload?: boolean;
|
|
1333
|
+
signal?: AbortSignal;
|
|
1334
|
+
}) => Promise<VaultFile[]>;
|
|
1168
1335
|
};
|
|
1169
1336
|
|
|
1170
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, isS3UrlExpired, isVaultFileS3Url, vaultClient };
|
|
1337
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
|
1171
1338
|
export type { AuthStrategy, VaultConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,22 @@ type VaultFileParams = {
|
|
|
88
88
|
config: VaultConfig;
|
|
89
89
|
};
|
|
90
90
|
type OnMissingParent = 'error' | 'create-as-root';
|
|
91
|
+
type OnParentConflict = 'error' | 'update-parent-id' | 'ignore';
|
|
92
|
+
/**
|
|
93
|
+
* Parameters for updating metadata of a VaultFile.
|
|
94
|
+
*/
|
|
95
|
+
interface VaultFileUpdateMetadataParams {
|
|
96
|
+
/** The new name to assign to the file. If not provided, the name will not be changed. */
|
|
97
|
+
name?: string;
|
|
98
|
+
}
|
|
99
|
+
type BulkFileInput = {
|
|
100
|
+
content: Blob | File;
|
|
101
|
+
name?: string;
|
|
102
|
+
mimeType?: string;
|
|
103
|
+
parentId?: string;
|
|
104
|
+
onMissingParent?: OnMissingParent;
|
|
105
|
+
onParentConflict?: OnParentConflict;
|
|
106
|
+
};
|
|
91
107
|
/**
|
|
92
108
|
* Represents a file in the vault and allows interacting with it.
|
|
93
109
|
*
|
|
@@ -154,6 +170,7 @@ declare class VaultFile {
|
|
|
154
170
|
* @param metadata.mimeType - The mime type of the file
|
|
155
171
|
* @param metadata.parentId - The ID of the parent file for hierarchical file relationships
|
|
156
172
|
* @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
173
|
+
* @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
|
|
157
174
|
* @param options - The options for the request
|
|
158
175
|
* @param options.signal - The signal to abort the request
|
|
159
176
|
*
|
|
@@ -219,6 +236,7 @@ declare class VaultFile {
|
|
|
219
236
|
* @param params.upload - Whether to upload the file (default: false)
|
|
220
237
|
* @param params.parentId - The ID of the parent file for hierarchical file relationships
|
|
221
238
|
* @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
239
|
+
* @param params.onParentConflict - What to do if the file already exists as an active child of another file
|
|
222
240
|
* @param options - The options for the request
|
|
223
241
|
* @param options.signal - The signal to abort the request
|
|
224
242
|
*
|
|
@@ -278,6 +296,7 @@ declare class VaultFile {
|
|
|
278
296
|
upload?: boolean;
|
|
279
297
|
parentId?: string;
|
|
280
298
|
onMissingParent?: OnMissingParent;
|
|
299
|
+
onParentConflict?: OnParentConflict;
|
|
281
300
|
}, options?: {
|
|
282
301
|
signal?: AbortSignal;
|
|
283
302
|
}): Promise<VaultFile>;
|
|
@@ -292,6 +311,7 @@ declare class VaultFile {
|
|
|
292
311
|
* @param params.contentType - The MIME type of the content (optional)
|
|
293
312
|
* @param params.parentId - The ID of the parent file for hierarchical file relationships
|
|
294
313
|
* @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
|
|
314
|
+
* @param params.onParentConflict - What to do if the file already exists as an active child of another file
|
|
295
315
|
* @param options - The options for the request
|
|
296
316
|
* @param options.signal - The signal to abort the request
|
|
297
317
|
*
|
|
@@ -334,9 +354,41 @@ declare class VaultFile {
|
|
|
334
354
|
contentType?: string;
|
|
335
355
|
parentId?: string;
|
|
336
356
|
onMissingParent?: OnMissingParent;
|
|
357
|
+
onParentConflict?: OnParentConflict;
|
|
337
358
|
}, options?: {
|
|
338
359
|
signal?: AbortSignal;
|
|
339
360
|
}): Promise<VaultFile>;
|
|
361
|
+
/**
|
|
362
|
+
* Creates multiple VaultFile instances from given content in a single request.
|
|
363
|
+
*
|
|
364
|
+
* @param params - Parameters for creating VaultFiles from content
|
|
365
|
+
* @param params.files - Array of file inputs with content and optional metadata
|
|
366
|
+
* @param params.config - The configuration for the VaultFiles
|
|
367
|
+
* @param params.upload - Whether to upload all files (default: false)
|
|
368
|
+
* @param options - The options for the request
|
|
369
|
+
* @param options.signal - The signal to abort the request
|
|
370
|
+
*
|
|
371
|
+
* @returns Array of new VaultFile instances
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* const files = await VaultFile.fromContentBulk({
|
|
376
|
+
* files: [
|
|
377
|
+
* { content: blob1, name: 'file1.txt' },
|
|
378
|
+
* { content: blob2, name: 'file2.txt', parentId: 'parent-id' },
|
|
379
|
+
* ],
|
|
380
|
+
* config: { vaultUrl, authStrategy },
|
|
381
|
+
* upload: true
|
|
382
|
+
* })
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
static fromContentBulk(params: {
|
|
386
|
+
files: BulkFileInput[];
|
|
387
|
+
config: VaultConfig;
|
|
388
|
+
upload?: boolean;
|
|
389
|
+
}, options?: {
|
|
390
|
+
signal?: AbortSignal;
|
|
391
|
+
}): Promise<VaultFile[]>;
|
|
340
392
|
/**
|
|
341
393
|
* Fetches and populates the metadata fields for this VaultFile instance.
|
|
342
394
|
*
|
|
@@ -1104,6 +1156,61 @@ declare class VaultFile {
|
|
|
1104
1156
|
* ```
|
|
1105
1157
|
*/
|
|
1106
1158
|
createChildFromStream(params: Omit<Parameters<typeof VaultFile.fromStream>[0], 'config' | 'parentId'>, options?: Parameters<typeof VaultFile.fromStream>[1]): Promise<VaultFile>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Updates the metadata of this file in the vault.
|
|
1161
|
+
*
|
|
1162
|
+
* This method allows you to modify specific metadata properties of the file, such as renaming it.
|
|
1163
|
+
* The instance's metadata property is automatically updated with the response from the server.
|
|
1164
|
+
* Only the provided parameters will be updated; all other metadata remains unchanged.
|
|
1165
|
+
*
|
|
1166
|
+
* @param params - The metadata properties to update
|
|
1167
|
+
* @param params.name - The new name to assign to the file
|
|
1168
|
+
* @param options - Additional options for the request
|
|
1169
|
+
* @param options.signal - AbortSignal to cancel the request
|
|
1170
|
+
*
|
|
1171
|
+
* @returns A Promise that resolves when the update completes successfully
|
|
1172
|
+
* @throws {Error} If the file ID is not set
|
|
1173
|
+
* @throws {FetchError} If the update request fails
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```ts
|
|
1177
|
+
* // Rename a file
|
|
1178
|
+
* const vaultFile = await VaultFile.fromVaultReference({
|
|
1179
|
+
* reference: 'vault://file-id',
|
|
1180
|
+
* config: { vaultUrl, authStrategy }
|
|
1181
|
+
* })
|
|
1182
|
+
* await vaultFile.updateMetadata({ name: 'new-name.txt' })
|
|
1183
|
+
* console.log('File renamed to:', vaultFile.metadata?.originalFileName)
|
|
1184
|
+
* ```
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```ts
|
|
1188
|
+
* // Rename a file with abort signal
|
|
1189
|
+
* const controller = new AbortController()
|
|
1190
|
+
* await vaultFile.updateMetadata(
|
|
1191
|
+
* { name: 'document-v2.pdf' },
|
|
1192
|
+
* { signal: controller.signal }
|
|
1193
|
+
* )
|
|
1194
|
+
* // Later: controller.abort()
|
|
1195
|
+
* ```
|
|
1196
|
+
*
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```ts
|
|
1199
|
+
* // Rename after upload
|
|
1200
|
+
* const file = new File(['content'], 'temp.txt')
|
|
1201
|
+
* const vaultFile = await VaultFile.fromContent({
|
|
1202
|
+
* name: 'temp.txt',
|
|
1203
|
+
* content: file,
|
|
1204
|
+
* config: { vaultUrl, authStrategy },
|
|
1205
|
+
* upload: true
|
|
1206
|
+
* })
|
|
1207
|
+
* // Later, rename the file
|
|
1208
|
+
* await vaultFile.updateMetadata({ name: 'final-document.txt' })
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
updateMetadata(params: VaultFileUpdateMetadataParams, options?: {
|
|
1212
|
+
signal?: AbortSignal;
|
|
1213
|
+
}): Promise<void>;
|
|
1107
1214
|
}
|
|
1108
1215
|
|
|
1109
1216
|
/**
|
|
@@ -1115,19 +1222,41 @@ declare class VaultFile {
|
|
|
1115
1222
|
*/
|
|
1116
1223
|
declare function isS3UrlExpired(url: string): boolean;
|
|
1117
1224
|
/**
|
|
1118
|
-
* Checks if a URL is a valid
|
|
1119
|
-
* @param url - The
|
|
1120
|
-
* @returns true if the URL is a valid
|
|
1225
|
+
* Checks if a URL is a valid vault reference
|
|
1226
|
+
* @param url - The URL to check
|
|
1227
|
+
* @returns true if the URL is a valid vault reference, false otherwise
|
|
1228
|
+
*/
|
|
1229
|
+
declare function isVaultReference(url: string): boolean;
|
|
1230
|
+
/**
|
|
1231
|
+
* Checks if a URL seems like a valid presigned S3 URL, with no additional checks.
|
|
1232
|
+
*
|
|
1233
|
+
* For usage with legacy URLs only. For new URLs, use {@link isTaggedVaultPresignedUrl} instead,
|
|
1234
|
+
* since this function only checks if the URL is a valid S3 URL, not if it was generated by Vault.
|
|
1235
|
+
*
|
|
1236
|
+
* @param url - The URL to check
|
|
1237
|
+
* @returns true if the URL is a valid S3 URL, false otherwise
|
|
1121
1238
|
*/
|
|
1122
|
-
declare function
|
|
1239
|
+
declare function isPresignedS3Url(url: string): boolean;
|
|
1123
1240
|
/**
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1241
|
+
* Extracts the vault file ID from an S3 presigned URL.
|
|
1242
|
+
* Supports multiple URL formats: tagged vault URLs, vault references, and legacy URL formats.
|
|
1243
|
+
*
|
|
1244
|
+
* @param url - The S3 URL to extract the vault file ID from
|
|
1245
|
+
* @returns The vault file ID (UUID or SHA-256 hash) if extraction succeeds, null otherwise
|
|
1246
|
+
* @example
|
|
1247
|
+
* // Tagged vault URL
|
|
1248
|
+
* extractVaultFileIdFromS3Url('https://vault-prod.s3.amazonaws.com/file?vault-file-id=abc123...')
|
|
1249
|
+
* // Returns: 'abc123...'
|
|
1250
|
+
*
|
|
1251
|
+
* // Vault reference
|
|
1252
|
+
* extractVaultFileIdFromS3Url('vault://2fce5740-83da-49fe-3f10-b32205893ec0')
|
|
1253
|
+
* // Returns: '2fce5740-83da-49fe-3f10-b32205893ec0'
|
|
1126
1254
|
*/
|
|
1127
1255
|
declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
1128
1256
|
/**
|
|
1129
1257
|
* Converts an S3 vault URL to a vault reference format
|
|
1130
1258
|
* Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
|
|
1259
|
+
*
|
|
1131
1260
|
* @param url - The S3 vault URL to convert
|
|
1132
1261
|
* @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
|
|
1133
1262
|
* @example
|
|
@@ -1135,6 +1264,33 @@ declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
|
1135
1264
|
* // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
|
|
1136
1265
|
*/
|
|
1137
1266
|
declare function convertS3UrlToVaultReference(url: string): string | null;
|
|
1267
|
+
/**
|
|
1268
|
+
* Checks if a URL is a tagged vault presigned S3 URL.
|
|
1269
|
+
* Tagged URLs contain vault-specific query parameters (vault-workspace-id, vault-file-id)
|
|
1270
|
+
* that identify the vault workspace and file.
|
|
1271
|
+
*
|
|
1272
|
+
* @param url - The URL to check
|
|
1273
|
+
* @returns true if the URL is a tagged vault presigned URL with valid workspace and file IDs, false otherwise
|
|
1274
|
+
* @example
|
|
1275
|
+
* const isTagged = isTaggedVaultPresignedUrl('https://vault-prod.s3.amazonaws.com/file?vault-workspace-id=abc-123&vault-file-id=def456...')
|
|
1276
|
+
* // Returns: true
|
|
1277
|
+
*/
|
|
1278
|
+
declare function isTaggedVaultPresignedUrl(url: string): boolean;
|
|
1279
|
+
/**
|
|
1280
|
+
* Extracts vault-specific parameters from a tagged vault presigned S3 URL.
|
|
1281
|
+
* Returns workspace ID, file ID, and optional parent ID from the URL query parameters.
|
|
1282
|
+
*
|
|
1283
|
+
* @param url - The tagged vault S3 URL to parse
|
|
1284
|
+
* @returns An object containing fileId, workspaceId, and parentId (if present), or null if the URL is not a tagged vault URL
|
|
1285
|
+
* @example
|
|
1286
|
+
* const params = getVaultParamsFromS3Url('https://vault-prod.s3.amazonaws.com/file?vault-workspace-id=abc-123&vault-file-id=def456&vault-parent-id=parent789')
|
|
1287
|
+
* // Returns: { fileId: 'def456', workspaceId: 'abc-123', parentId: 'parent789' }
|
|
1288
|
+
*/
|
|
1289
|
+
declare function getVaultParamsFromS3Url(url: string): {
|
|
1290
|
+
fileId: string | null;
|
|
1291
|
+
workspaceId: string | null;
|
|
1292
|
+
parentId: string | null;
|
|
1293
|
+
} | null;
|
|
1138
1294
|
|
|
1139
1295
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
1140
1296
|
createFromContent: {
|
|
@@ -1165,7 +1321,18 @@ declare function vaultClient(vaultConfig: VaultConfig): {
|
|
|
1165
1321
|
signal?: AbortSignal;
|
|
1166
1322
|
parentId?: string;
|
|
1167
1323
|
}) => Promise<VaultFile>;
|
|
1324
|
+
createFromContentBulk: (files: Array<{
|
|
1325
|
+
content: Blob | File;
|
|
1326
|
+
name?: string;
|
|
1327
|
+
mimeType?: string;
|
|
1328
|
+
parentId?: string;
|
|
1329
|
+
onMissingParent?: "error" | "create-as-root";
|
|
1330
|
+
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1331
|
+
}>, options?: {
|
|
1332
|
+
upload?: boolean;
|
|
1333
|
+
signal?: AbortSignal;
|
|
1334
|
+
}) => Promise<VaultFile[]>;
|
|
1168
1335
|
};
|
|
1169
1336
|
|
|
1170
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, isS3UrlExpired, isVaultFileS3Url, vaultClient };
|
|
1337
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
|
1171
1338
|
export type { AuthStrategy, VaultConfig };
|