@meistrari/vault-sdk 1.4.3 → 1.6.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 +328 -11
- package/dist/index.d.cts +146 -6
- package/dist/index.d.mts +146 -6
- package/dist/index.d.ts +146 -6
- package/dist/index.mjs +325 -12
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -45,7 +45,7 @@ declare class Permalink {
|
|
|
45
45
|
/**
|
|
46
46
|
* Get a new permalink instance from its ID.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
48
|
+
* @param vaultConfig - The vault config.
|
|
49
49
|
* @param id - The permalink ID.
|
|
50
50
|
* @returns The permalink.
|
|
51
51
|
*/
|
|
@@ -53,7 +53,7 @@ declare class Permalink {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create a new permalink.
|
|
55
55
|
*
|
|
56
|
-
* @param
|
|
56
|
+
* @param vaultConfig - The vault config.
|
|
57
57
|
* @param params - The parameters for the permalink.
|
|
58
58
|
* @param params.expiresIn - Time, in seconds, the permalink will be valid for.
|
|
59
59
|
* @param params.fileId - The ID of the file to create a permalink for.
|
|
@@ -114,9 +114,11 @@ declare class VaultFile {
|
|
|
114
114
|
} | undefined;
|
|
115
115
|
private readonly baseUrl;
|
|
116
116
|
/**
|
|
117
|
-
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended
|
|
118
|
-
*
|
|
119
|
-
*
|
|
117
|
+
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended.
|
|
118
|
+
*
|
|
119
|
+
* Use the static methods {@link VaultFile.fromVaultReference} when dealing with an existing file in the vault,
|
|
120
|
+
* {@link VaultFile.fromContent} when preparing a new file for upload,
|
|
121
|
+
* or {@link VaultFile.fromStream} when preparing a new file for streaming upload.
|
|
120
122
|
*
|
|
121
123
|
* @param params - The parameters for the VaultFile constructor
|
|
122
124
|
* @param params.config - The configuration for the VaultFile
|
|
@@ -254,6 +256,46 @@ declare class VaultFile {
|
|
|
254
256
|
}, options?: {
|
|
255
257
|
signal?: AbortSignal;
|
|
256
258
|
}): Promise<VaultFile>;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a new VaultFile instance for streaming upload workflows.
|
|
261
|
+
* This method creates a VaultFile with placeholder content that's optimized for streaming uploads.
|
|
262
|
+
*
|
|
263
|
+
* @param params - The parameters for creating a VaultFile for streaming
|
|
264
|
+
* @param params.name - The name of the file
|
|
265
|
+
* @param params.contentLength - The size of the content in bytes
|
|
266
|
+
* @param params.config - The configuration for the VaultFile
|
|
267
|
+
* @param params.contentType - The MIME type of the content (optional)
|
|
268
|
+
* @param options - The options for the request
|
|
269
|
+
* @param options.signal - The signal to abort the request
|
|
270
|
+
*
|
|
271
|
+
* @returns A new VaultFile instance ready for streaming upload
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* // Create VaultFile for streaming
|
|
276
|
+
* const vaultFile = await VaultFile.fromStream({
|
|
277
|
+
* name: 'large-video.mp4',
|
|
278
|
+
* contentLength: 100 * 1024 * 1024, // 100MB
|
|
279
|
+
* contentType: 'video/mp4',
|
|
280
|
+
* config: { vaultUrl, authStrategy }
|
|
281
|
+
* })
|
|
282
|
+
*
|
|
283
|
+
* // Upload using a stream
|
|
284
|
+
* const fileStream = file.stream()
|
|
285
|
+
* await vaultFile.uploadStream(fileStream, {
|
|
286
|
+
* contentLength: file.size,
|
|
287
|
+
* contentType: file.type
|
|
288
|
+
* })
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
static fromStream(params: {
|
|
292
|
+
name: string;
|
|
293
|
+
contentLength: number;
|
|
294
|
+
config: VaultConfig;
|
|
295
|
+
contentType?: string;
|
|
296
|
+
}, options?: {
|
|
297
|
+
signal?: AbortSignal;
|
|
298
|
+
}): Promise<VaultFile>;
|
|
257
299
|
/**
|
|
258
300
|
* Populates the metadata of the file instance.
|
|
259
301
|
* @param options - The options for the request
|
|
@@ -364,6 +406,70 @@ declare class VaultFile {
|
|
|
364
406
|
download(responseType: 'base64', options?: {
|
|
365
407
|
signal?: AbortSignal;
|
|
366
408
|
}): Promise<string>;
|
|
409
|
+
/**
|
|
410
|
+
* Downloads a file from the vault as a stream for memory-efficient processing.
|
|
411
|
+
*
|
|
412
|
+
* @param options - The options for the request
|
|
413
|
+
* @param options.signal - The signal to abort the request
|
|
414
|
+
*
|
|
415
|
+
* @returns A ReadableStream that yields chunks of the file data
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* const vaultFile = await VaultFile.fromVaultReference('vault://1234567890', { vaultUrl, authStrategy })
|
|
420
|
+
* const stream = await vaultFile.downloadStream()
|
|
421
|
+
*
|
|
422
|
+
* // Process the stream chunk by chunk
|
|
423
|
+
* const reader = stream.getReader()
|
|
424
|
+
* try {
|
|
425
|
+
* while (true) {
|
|
426
|
+
* const { done, value } = await reader.read()
|
|
427
|
+
* if (done) break
|
|
428
|
+
* // Process the chunk (Uint8Array)
|
|
429
|
+
* console.log('Received chunk of size:', value.length)
|
|
430
|
+
* }
|
|
431
|
+
* } finally {
|
|
432
|
+
* reader.releaseLock()
|
|
433
|
+
* }
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
downloadStream(options?: {
|
|
437
|
+
signal?: AbortSignal;
|
|
438
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
439
|
+
/**
|
|
440
|
+
* Uploads a file to the vault using a stream for memory-efficient processing.
|
|
441
|
+
*
|
|
442
|
+
* @param stream - The readable stream of file data to upload
|
|
443
|
+
* @param options - The options for the request
|
|
444
|
+
* @param options.signal - The signal to abort the request
|
|
445
|
+
* @param options.contentLength - The total size of the content (required for S3 uploads)
|
|
446
|
+
* @param options.contentType - The MIME type of the content (will be detected if not provided)
|
|
447
|
+
*
|
|
448
|
+
* @throws {Error} If contentLength is not provided
|
|
449
|
+
* @throws {FetchError} If the upload fails
|
|
450
|
+
* @returns Promise that resolves when upload is complete
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* const file = new File(['content'], 'document.txt')
|
|
455
|
+
* const vaultFile = await VaultFile.fromStream('document.txt', file.size, {
|
|
456
|
+
* contentType: file.type,
|
|
457
|
+
* config: { vaultUrl, authStrategy }
|
|
458
|
+
* })
|
|
459
|
+
*
|
|
460
|
+
* // Upload using the stream directly
|
|
461
|
+
* const stream = file.stream()
|
|
462
|
+
* await vaultFile.uploadStream(stream, {
|
|
463
|
+
* contentLength: file.size,
|
|
464
|
+
* contentType: file.type
|
|
465
|
+
* })
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
uploadStream(stream: ReadableStream<Uint8Array>, options: {
|
|
469
|
+
signal?: AbortSignal;
|
|
470
|
+
contentLength: number;
|
|
471
|
+
contentType?: string;
|
|
472
|
+
}): Promise<void>;
|
|
367
473
|
/**
|
|
368
474
|
* Deletes the file from the vault.
|
|
369
475
|
* @param options - The options for the request
|
|
@@ -399,6 +505,36 @@ declare class VaultFile {
|
|
|
399
505
|
}): Promise<Permalink[]>;
|
|
400
506
|
}
|
|
401
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Checks if an Amazon S3 signed URL has expired
|
|
510
|
+
* @param url - The S3 URL to check for expiration
|
|
511
|
+
* @returns true if the URL is expired, false if it's still valid or not an S3 signed URL
|
|
512
|
+
* @example
|
|
513
|
+
* const expired = isS3UrlExpired('https://vault-prod.s3.amazonaws.com/file?X-Amz-Date=20240101T000000Z&X-Amz-Expires=3600')
|
|
514
|
+
*/
|
|
515
|
+
declare function isS3UrlExpired(url: string): boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Checks if a URL is a valid S3 vault URL
|
|
518
|
+
* @param url - The S3 URL to check
|
|
519
|
+
* @returns true if the URL is a valid S3 vault URL, false otherwise
|
|
520
|
+
*/
|
|
521
|
+
declare function isVaultFileS3Url(url: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Detects if a URL is an expired S3 vault URL and extracts the vault file ID
|
|
524
|
+
* Returns null if not a vault S3 URL, not expired, or extraction fails
|
|
525
|
+
*/
|
|
526
|
+
declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
527
|
+
/**
|
|
528
|
+
* Converts an S3 vault URL to a vault reference format
|
|
529
|
+
* Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
|
|
530
|
+
* @param url - The S3 vault URL to convert
|
|
531
|
+
* @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
|
|
532
|
+
* @example
|
|
533
|
+
* const ref = convertS3UrlToVaultReference('https://vault-prod.s3.amazonaws.com/workspace123/2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6?...')
|
|
534
|
+
* // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
|
|
535
|
+
*/
|
|
536
|
+
declare function convertS3UrlToVaultReference(url: string): string | null;
|
|
537
|
+
|
|
402
538
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
403
539
|
createFromContent: (name: string, content: Blob | File, options?: {
|
|
404
540
|
signal?: AbortSignal;
|
|
@@ -406,7 +542,11 @@ declare function vaultClient(vaultConfig: VaultConfig): {
|
|
|
406
542
|
createFromReference: (reference: string, options?: {
|
|
407
543
|
signal?: AbortSignal;
|
|
408
544
|
}) => Promise<VaultFile>;
|
|
545
|
+
createFromStream: (name: string, contentLength: number, options?: {
|
|
546
|
+
contentType?: string;
|
|
547
|
+
signal?: AbortSignal;
|
|
548
|
+
}) => Promise<VaultFile>;
|
|
409
549
|
};
|
|
410
550
|
|
|
411
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };
|
|
551
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, isS3UrlExpired, isVaultFileS3Url, vaultClient };
|
|
412
552
|
export type { AuthStrategy, VaultConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ declare class Permalink {
|
|
|
45
45
|
/**
|
|
46
46
|
* Get a new permalink instance from its ID.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
48
|
+
* @param vaultConfig - The vault config.
|
|
49
49
|
* @param id - The permalink ID.
|
|
50
50
|
* @returns The permalink.
|
|
51
51
|
*/
|
|
@@ -53,7 +53,7 @@ declare class Permalink {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create a new permalink.
|
|
55
55
|
*
|
|
56
|
-
* @param
|
|
56
|
+
* @param vaultConfig - The vault config.
|
|
57
57
|
* @param params - The parameters for the permalink.
|
|
58
58
|
* @param params.expiresIn - Time, in seconds, the permalink will be valid for.
|
|
59
59
|
* @param params.fileId - The ID of the file to create a permalink for.
|
|
@@ -114,9 +114,11 @@ declare class VaultFile {
|
|
|
114
114
|
} | undefined;
|
|
115
115
|
private readonly baseUrl;
|
|
116
116
|
/**
|
|
117
|
-
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended
|
|
118
|
-
*
|
|
119
|
-
*
|
|
117
|
+
* Constructs a new VaultFile instance. Direct usage of the constructor is not recommended.
|
|
118
|
+
*
|
|
119
|
+
* Use the static methods {@link VaultFile.fromVaultReference} when dealing with an existing file in the vault,
|
|
120
|
+
* {@link VaultFile.fromContent} when preparing a new file for upload,
|
|
121
|
+
* or {@link VaultFile.fromStream} when preparing a new file for streaming upload.
|
|
120
122
|
*
|
|
121
123
|
* @param params - The parameters for the VaultFile constructor
|
|
122
124
|
* @param params.config - The configuration for the VaultFile
|
|
@@ -254,6 +256,46 @@ declare class VaultFile {
|
|
|
254
256
|
}, options?: {
|
|
255
257
|
signal?: AbortSignal;
|
|
256
258
|
}): Promise<VaultFile>;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a new VaultFile instance for streaming upload workflows.
|
|
261
|
+
* This method creates a VaultFile with placeholder content that's optimized for streaming uploads.
|
|
262
|
+
*
|
|
263
|
+
* @param params - The parameters for creating a VaultFile for streaming
|
|
264
|
+
* @param params.name - The name of the file
|
|
265
|
+
* @param params.contentLength - The size of the content in bytes
|
|
266
|
+
* @param params.config - The configuration for the VaultFile
|
|
267
|
+
* @param params.contentType - The MIME type of the content (optional)
|
|
268
|
+
* @param options - The options for the request
|
|
269
|
+
* @param options.signal - The signal to abort the request
|
|
270
|
+
*
|
|
271
|
+
* @returns A new VaultFile instance ready for streaming upload
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* // Create VaultFile for streaming
|
|
276
|
+
* const vaultFile = await VaultFile.fromStream({
|
|
277
|
+
* name: 'large-video.mp4',
|
|
278
|
+
* contentLength: 100 * 1024 * 1024, // 100MB
|
|
279
|
+
* contentType: 'video/mp4',
|
|
280
|
+
* config: { vaultUrl, authStrategy }
|
|
281
|
+
* })
|
|
282
|
+
*
|
|
283
|
+
* // Upload using a stream
|
|
284
|
+
* const fileStream = file.stream()
|
|
285
|
+
* await vaultFile.uploadStream(fileStream, {
|
|
286
|
+
* contentLength: file.size,
|
|
287
|
+
* contentType: file.type
|
|
288
|
+
* })
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
static fromStream(params: {
|
|
292
|
+
name: string;
|
|
293
|
+
contentLength: number;
|
|
294
|
+
config: VaultConfig;
|
|
295
|
+
contentType?: string;
|
|
296
|
+
}, options?: {
|
|
297
|
+
signal?: AbortSignal;
|
|
298
|
+
}): Promise<VaultFile>;
|
|
257
299
|
/**
|
|
258
300
|
* Populates the metadata of the file instance.
|
|
259
301
|
* @param options - The options for the request
|
|
@@ -364,6 +406,70 @@ declare class VaultFile {
|
|
|
364
406
|
download(responseType: 'base64', options?: {
|
|
365
407
|
signal?: AbortSignal;
|
|
366
408
|
}): Promise<string>;
|
|
409
|
+
/**
|
|
410
|
+
* Downloads a file from the vault as a stream for memory-efficient processing.
|
|
411
|
+
*
|
|
412
|
+
* @param options - The options for the request
|
|
413
|
+
* @param options.signal - The signal to abort the request
|
|
414
|
+
*
|
|
415
|
+
* @returns A ReadableStream that yields chunks of the file data
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* const vaultFile = await VaultFile.fromVaultReference('vault://1234567890', { vaultUrl, authStrategy })
|
|
420
|
+
* const stream = await vaultFile.downloadStream()
|
|
421
|
+
*
|
|
422
|
+
* // Process the stream chunk by chunk
|
|
423
|
+
* const reader = stream.getReader()
|
|
424
|
+
* try {
|
|
425
|
+
* while (true) {
|
|
426
|
+
* const { done, value } = await reader.read()
|
|
427
|
+
* if (done) break
|
|
428
|
+
* // Process the chunk (Uint8Array)
|
|
429
|
+
* console.log('Received chunk of size:', value.length)
|
|
430
|
+
* }
|
|
431
|
+
* } finally {
|
|
432
|
+
* reader.releaseLock()
|
|
433
|
+
* }
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
downloadStream(options?: {
|
|
437
|
+
signal?: AbortSignal;
|
|
438
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
439
|
+
/**
|
|
440
|
+
* Uploads a file to the vault using a stream for memory-efficient processing.
|
|
441
|
+
*
|
|
442
|
+
* @param stream - The readable stream of file data to upload
|
|
443
|
+
* @param options - The options for the request
|
|
444
|
+
* @param options.signal - The signal to abort the request
|
|
445
|
+
* @param options.contentLength - The total size of the content (required for S3 uploads)
|
|
446
|
+
* @param options.contentType - The MIME type of the content (will be detected if not provided)
|
|
447
|
+
*
|
|
448
|
+
* @throws {Error} If contentLength is not provided
|
|
449
|
+
* @throws {FetchError} If the upload fails
|
|
450
|
+
* @returns Promise that resolves when upload is complete
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* const file = new File(['content'], 'document.txt')
|
|
455
|
+
* const vaultFile = await VaultFile.fromStream('document.txt', file.size, {
|
|
456
|
+
* contentType: file.type,
|
|
457
|
+
* config: { vaultUrl, authStrategy }
|
|
458
|
+
* })
|
|
459
|
+
*
|
|
460
|
+
* // Upload using the stream directly
|
|
461
|
+
* const stream = file.stream()
|
|
462
|
+
* await vaultFile.uploadStream(stream, {
|
|
463
|
+
* contentLength: file.size,
|
|
464
|
+
* contentType: file.type
|
|
465
|
+
* })
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
uploadStream(stream: ReadableStream<Uint8Array>, options: {
|
|
469
|
+
signal?: AbortSignal;
|
|
470
|
+
contentLength: number;
|
|
471
|
+
contentType?: string;
|
|
472
|
+
}): Promise<void>;
|
|
367
473
|
/**
|
|
368
474
|
* Deletes the file from the vault.
|
|
369
475
|
* @param options - The options for the request
|
|
@@ -399,6 +505,36 @@ declare class VaultFile {
|
|
|
399
505
|
}): Promise<Permalink[]>;
|
|
400
506
|
}
|
|
401
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Checks if an Amazon S3 signed URL has expired
|
|
510
|
+
* @param url - The S3 URL to check for expiration
|
|
511
|
+
* @returns true if the URL is expired, false if it's still valid or not an S3 signed URL
|
|
512
|
+
* @example
|
|
513
|
+
* const expired = isS3UrlExpired('https://vault-prod.s3.amazonaws.com/file?X-Amz-Date=20240101T000000Z&X-Amz-Expires=3600')
|
|
514
|
+
*/
|
|
515
|
+
declare function isS3UrlExpired(url: string): boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Checks if a URL is a valid S3 vault URL
|
|
518
|
+
* @param url - The S3 URL to check
|
|
519
|
+
* @returns true if the URL is a valid S3 vault URL, false otherwise
|
|
520
|
+
*/
|
|
521
|
+
declare function isVaultFileS3Url(url: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Detects if a URL is an expired S3 vault URL and extracts the vault file ID
|
|
524
|
+
* Returns null if not a vault S3 URL, not expired, or extraction fails
|
|
525
|
+
*/
|
|
526
|
+
declare function extractVaultFileIdFromS3Url(url: string): string | null;
|
|
527
|
+
/**
|
|
528
|
+
* Converts an S3 vault URL to a vault reference format
|
|
529
|
+
* Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
|
|
530
|
+
* @param url - The S3 vault URL to convert
|
|
531
|
+
* @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
|
|
532
|
+
* @example
|
|
533
|
+
* const ref = convertS3UrlToVaultReference('https://vault-prod.s3.amazonaws.com/workspace123/2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6?...')
|
|
534
|
+
* // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
|
|
535
|
+
*/
|
|
536
|
+
declare function convertS3UrlToVaultReference(url: string): string | null;
|
|
537
|
+
|
|
402
538
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
403
539
|
createFromContent: (name: string, content: Blob | File, options?: {
|
|
404
540
|
signal?: AbortSignal;
|
|
@@ -406,7 +542,11 @@ declare function vaultClient(vaultConfig: VaultConfig): {
|
|
|
406
542
|
createFromReference: (reference: string, options?: {
|
|
407
543
|
signal?: AbortSignal;
|
|
408
544
|
}) => Promise<VaultFile>;
|
|
545
|
+
createFromStream: (name: string, contentLength: number, options?: {
|
|
546
|
+
contentType?: string;
|
|
547
|
+
signal?: AbortSignal;
|
|
548
|
+
}) => Promise<VaultFile>;
|
|
409
549
|
};
|
|
410
550
|
|
|
411
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };
|
|
551
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, isS3UrlExpired, isVaultFileS3Url, vaultClient };
|
|
412
552
|
export type { AuthStrategy, VaultConfig };
|