@meistrari/vault-sdk 3.2.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -482
- package/dist/index.cjs +297 -122
- package/dist/index.d.cts +262 -50
- package/dist/index.d.mts +262 -50
- package/dist/index.d.ts +262 -50
- package/dist/index.mjs +297 -124
- package/package.json +3 -3
package/dist/index.d.ts
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,6 +29,150 @@ type VaultConfig = {
|
|
|
28
29
|
authStrategy: AuthStrategy;
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Parameters for creating an asset upload URL.
|
|
34
|
+
*/
|
|
35
|
+
type CreateAssetUploadParams = {
|
|
36
|
+
/** Application-defined class for grouping assets, such as `avatar` or `cover-image`. */
|
|
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. */
|
|
48
|
+
mimeType: string;
|
|
49
|
+
/** Size of the content in bytes, when known. */
|
|
50
|
+
size?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Parameters for creating an asset from in-memory content.
|
|
54
|
+
*/
|
|
55
|
+
type CreateAssetFromContentParams = {
|
|
56
|
+
/** Application-defined class for grouping assets, such as `avatar` or `cover-image`. */
|
|
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. */
|
|
68
|
+
mimeType?: string;
|
|
69
|
+
/** Whether to upload the content immediately after creating the asset. */
|
|
70
|
+
upload?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** Values required to construct a VaultAsset instance. */
|
|
73
|
+
type VaultAssetParams = {
|
|
74
|
+
/** Vault-assigned asset ID. */
|
|
75
|
+
assetId: string;
|
|
76
|
+
/** Stable URL used to resolve or download the asset. */
|
|
77
|
+
assetUrl: string | URL;
|
|
78
|
+
/** Presigned URL used to upload the asset content. */
|
|
79
|
+
uploadUrl: string | URL;
|
|
80
|
+
/** Expiration time for the presigned upload URL. */
|
|
81
|
+
expiresAt: string | Date;
|
|
82
|
+
/** Headers that must be sent with the presigned upload request. */
|
|
83
|
+
uploadHeaders: Record<string, string>;
|
|
84
|
+
/** Stored asset metadata returned by Vault. */
|
|
85
|
+
asset: AssetMetadata;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Represents a Vault asset with a stable asset URL and a presigned upload URL.
|
|
89
|
+
*/
|
|
90
|
+
declare class VaultAsset {
|
|
91
|
+
/** Vault-assigned asset ID. */
|
|
92
|
+
readonly assetId: string;
|
|
93
|
+
/** Stable URL used to resolve or download the asset. */
|
|
94
|
+
readonly assetUrl: URL;
|
|
95
|
+
/** Presigned URL used to upload asset content. */
|
|
96
|
+
readonly uploadUrl: URL;
|
|
97
|
+
/** Expiration time for the presigned upload URL. */
|
|
98
|
+
readonly expiresAt: Date;
|
|
99
|
+
/** Headers that must be sent when uploading to {@link VaultAsset.uploadUrl}. */
|
|
100
|
+
readonly uploadHeaders: Record<string, string>;
|
|
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
|
+
*/
|
|
136
|
+
static create(vaultConfig: VaultConfig, params: CreateAssetUploadParams, options?: {
|
|
137
|
+
signal?: AbortSignal;
|
|
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
|
+
*/
|
|
158
|
+
static fromContent(vaultConfig: VaultConfig, content: Blob | File, params: CreateAssetFromContentParams, options?: {
|
|
159
|
+
signal?: AbortSignal;
|
|
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
|
+
*/
|
|
171
|
+
upload(content: Blob | File, options?: {
|
|
172
|
+
signal?: AbortSignal;
|
|
173
|
+
}): Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
|
|
31
176
|
declare class Permalink {
|
|
32
177
|
private readonly config;
|
|
33
178
|
readonly id: string;
|
|
@@ -1349,57 +1494,124 @@ declare function getVaultParamsFromS3Url(url: string): {
|
|
|
1349
1494
|
parentId: string | null;
|
|
1350
1495
|
} | null;
|
|
1351
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
|
+
*/
|
|
1352
1577
|
declare function vaultClient(vaultConfig: VaultConfig): {
|
|
1353
1578
|
createFromContent: {
|
|
1354
|
-
(name: string, content: Blob | File, options?:
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
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>;
|
|
1582
|
+
};
|
|
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[]>;
|
|
1587
|
+
assets: {
|
|
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>;
|
|
1372
1613
|
};
|
|
1373
|
-
createFromReference: (reference: string, options?: {
|
|
1374
|
-
signal?: AbortSignal;
|
|
1375
|
-
}) => Promise<VaultFile>;
|
|
1376
|
-
createFromStream: (name: string, contentLength: number, options?: {
|
|
1377
|
-
contentType?: string;
|
|
1378
|
-
signal?: AbortSignal;
|
|
1379
|
-
parentId?: string;
|
|
1380
|
-
}) => Promise<VaultFile>;
|
|
1381
|
-
createFromContentBulk: (files: Array<{
|
|
1382
|
-
content: Blob | File;
|
|
1383
|
-
name?: string;
|
|
1384
|
-
mimeType?: string;
|
|
1385
|
-
parentId?: string;
|
|
1386
|
-
onMissingParent?: "error" | "create-as-root";
|
|
1387
|
-
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1388
|
-
}>, options?: {
|
|
1389
|
-
upload?: boolean;
|
|
1390
|
-
signal?: AbortSignal;
|
|
1391
|
-
}) => Promise<VaultFile[]>;
|
|
1392
|
-
createFromStreamBulk: (files: Array<{
|
|
1393
|
-
name: string;
|
|
1394
|
-
contentLength: number;
|
|
1395
|
-
contentType?: string;
|
|
1396
|
-
parentId?: string;
|
|
1397
|
-
onMissingParent?: "error" | "create-as-root";
|
|
1398
|
-
onParentConflict?: "error" | "update-parent-id" | "ignore";
|
|
1399
|
-
}>, options?: {
|
|
1400
|
-
signal?: AbortSignal;
|
|
1401
|
-
}) => Promise<VaultFile[]>;
|
|
1402
1614
|
};
|
|
1403
1615
|
|
|
1404
|
-
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
|
1405
|
-
export type { AuthStrategy, VaultConfig };
|
|
1616
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, Permalink, VaultAsset, VaultFile, convertS3UrlToVaultReference, extractVaultFileIdFromS3Url, extractVaultReferences, getVaultParamsFromS3Url, isS3UrlExpired, isTaggedVaultPresignedUrl, isPresignedS3Url as isVaultFileS3Url, isVaultReference, vaultClient };
|
|
1617
|
+
export type { AuthStrategy, CreateAssetFromContentParams, CreateAssetUploadParams, VaultConfig };
|