@meistrari/vault-sdk 1.9.0 → 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.d.mts CHANGED
@@ -89,6 +89,21 @@ type VaultFileParams = {
89
89
  };
90
90
  type OnMissingParent = 'error' | 'create-as-root';
91
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
+ };
92
107
  /**
93
108
  * Represents a file in the vault and allows interacting with it.
94
109
  *
@@ -343,6 +358,37 @@ declare class VaultFile {
343
358
  }, options?: {
344
359
  signal?: AbortSignal;
345
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[]>;
346
392
  /**
347
393
  * Fetches and populates the metadata fields for this VaultFile instance.
348
394
  *
@@ -1110,6 +1156,61 @@ declare class VaultFile {
1110
1156
  * ```
1111
1157
  */
1112
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>;
1113
1214
  }
1114
1215
 
1115
1216
  /**
@@ -1121,19 +1222,41 @@ declare class VaultFile {
1121
1222
  */
1122
1223
  declare function isS3UrlExpired(url: string): boolean;
1123
1224
  /**
1124
- * Checks if a URL is a valid S3 vault URL
1125
- * @param url - The S3 URL to check
1126
- * @returns true if the URL is a valid S3 vault URL, false otherwise
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
1127
1238
  */
1128
- declare function isVaultFileS3Url(url: string): boolean;
1239
+ declare function isPresignedS3Url(url: string): boolean;
1129
1240
  /**
1130
- * Detects if a URL is an expired S3 vault URL and extracts the vault file ID
1131
- * Returns null if not a vault S3 URL, not expired, or extraction fails
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'
1132
1254
  */
1133
1255
  declare function extractVaultFileIdFromS3Url(url: string): string | null;
1134
1256
  /**
1135
1257
  * Converts an S3 vault URL to a vault reference format
1136
1258
  * Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
1259
+ *
1137
1260
  * @param url - The S3 vault URL to convert
1138
1261
  * @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
1139
1262
  * @example
@@ -1141,6 +1264,33 @@ declare function extractVaultFileIdFromS3Url(url: string): string | null;
1141
1264
  * // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
1142
1265
  */
1143
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;
1144
1294
 
1145
1295
  declare function vaultClient(vaultConfig: VaultConfig): {
1146
1296
  createFromContent: {
@@ -1171,7 +1321,18 @@ declare function vaultClient(vaultConfig: VaultConfig): {
1171
1321
  signal?: AbortSignal;
1172
1322
  parentId?: string;
1173
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[]>;
1174
1335
  };
1175
1336
 
1176
- 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 };
1177
1338
  export type { AuthStrategy, VaultConfig };
package/dist/index.d.ts CHANGED
@@ -89,6 +89,21 @@ type VaultFileParams = {
89
89
  };
90
90
  type OnMissingParent = 'error' | 'create-as-root';
91
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
+ };
92
107
  /**
93
108
  * Represents a file in the vault and allows interacting with it.
94
109
  *
@@ -343,6 +358,37 @@ declare class VaultFile {
343
358
  }, options?: {
344
359
  signal?: AbortSignal;
345
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[]>;
346
392
  /**
347
393
  * Fetches and populates the metadata fields for this VaultFile instance.
348
394
  *
@@ -1110,6 +1156,61 @@ declare class VaultFile {
1110
1156
  * ```
1111
1157
  */
1112
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>;
1113
1214
  }
1114
1215
 
1115
1216
  /**
@@ -1121,19 +1222,41 @@ declare class VaultFile {
1121
1222
  */
1122
1223
  declare function isS3UrlExpired(url: string): boolean;
1123
1224
  /**
1124
- * Checks if a URL is a valid S3 vault URL
1125
- * @param url - The S3 URL to check
1126
- * @returns true if the URL is a valid S3 vault URL, false otherwise
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
1127
1238
  */
1128
- declare function isVaultFileS3Url(url: string): boolean;
1239
+ declare function isPresignedS3Url(url: string): boolean;
1129
1240
  /**
1130
- * Detects if a URL is an expired S3 vault URL and extracts the vault file ID
1131
- * Returns null if not a vault S3 URL, not expired, or extraction fails
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'
1132
1254
  */
1133
1255
  declare function extractVaultFileIdFromS3Url(url: string): string | null;
1134
1256
  /**
1135
1257
  * Converts an S3 vault URL to a vault reference format
1136
1258
  * Extracts the vault file ID from the S3 URL path and formats it as vault://[fileId]
1259
+ *
1137
1260
  * @param url - The S3 vault URL to convert
1138
1261
  * @returns A vault reference string (vault://[fileId]) if successful, null if the URL is not a valid vault S3 URL
1139
1262
  * @example
@@ -1141,6 +1264,33 @@ declare function extractVaultFileIdFromS3Url(url: string): string | null;
1141
1264
  * // Returns: 'vault://2fce574083da49fe3f10b32205893ec0bb024fe1c7673fa54927fdfe1d0db9d6'
1142
1265
  */
1143
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;
1144
1294
 
1145
1295
  declare function vaultClient(vaultConfig: VaultConfig): {
1146
1296
  createFromContent: {
@@ -1171,7 +1321,18 @@ declare function vaultClient(vaultConfig: VaultConfig): {
1171
1321
  signal?: AbortSignal;
1172
1322
  parentId?: string;
1173
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[]>;
1174
1335
  };
1175
1336
 
1176
- 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 };
1177
1338
  export type { AuthStrategy, VaultConfig };