@@ -329,8 +329,6 @@ export interface ExportDataUnitsConfiguration {
329329 * Options for site archive export.
330330 */
331331export interface SiteArchiveExportOptions {
332- /** Keep archive on instance after download (default: false) */
333- keepArchive ?: boolean ;
334332 /** Wait options for job completion */
335333 waitOptions ?: WaitForJobOptions ;
336334}
@@ -343,10 +341,6 @@ export interface SiteArchiveExportResult {
343341 execution : JobExecution ;
344342 /** Archive filename on instance */
345343 archiveFilename : string ;
346- /** Archive content as buffer (if downloaded) */
347- data ?: Buffer ;
348- /** Whether archive was kept on instance */
349- archiveKept : boolean ;
350344}
351345
352346/**
@@ -384,13 +378,12 @@ export async function siteArchiveExport(
384378 options : SiteArchiveExportOptions = { } ,
385379) : Promise < SiteArchiveExportResult > {
386380 const logger = getLogger ( ) ;
387- const { keepArchive = false , waitOptions} = options ;
381+ const { waitOptions} = options ;
388382
389383 // Generate archive filename
390384 const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .- ] + / g, '' ) ;
391385 const archiveDirName = `${ timestamp } _export` ;
392386 const zipFilename = `${ archiveDirName } .zip` ;
393- const webdavPath = `Impex/src/instance/${ zipFilename } ` ;
394387
395388 logger . debug ( { jobId : EXPORT_JOB_ID , dataUnits} , `Executing ${ EXPORT_JOB_ID } job` ) ;
396389
@@ -450,32 +443,70 @@ export async function siteArchiveExport(
450443 throw error ;
451444 }
452445
453- // Download archive
446+ return {
447+ execution,
448+ archiveFilename : zipFilename ,
449+ } ;
450+ }
451+
452+ /**
453+ * Exports a site archive and downloads it to memory.
454+ *
455+ * Runs the export job on the instance, downloads the archive via WebDAV,
456+ * and returns the data as a Buffer. Optionally keeps the archive on the instance.
457+ *
458+ * @param instance - B2C instance to export from
459+ * @param dataUnits - Data units configuration specifying what to export
460+ * @param options - Export and download options
461+ * @returns Export result with archive data buffer
462+ *
463+ * @example
464+ * ```typescript
465+ * const result = await siteArchiveExportDownload(instance, {
466+ * global_data: { meta_data: true }
467+ * });
468+ * const zip = await JSZip.loadAsync(result.data);
469+ * ```
470+ */
471+ export async function siteArchiveExportToBuffer (
472+ instance : B2CInstance ,
473+ dataUnits : Partial < ExportDataUnitsConfiguration > ,
474+ options : SiteArchiveExportOptions & { keepArchive ?: boolean } = { } ,
475+ ) : Promise < SiteArchiveExportResult & { data : Buffer ; archiveKept : boolean } > {
476+ const logger = getLogger ( ) ;
477+ const { keepArchive = false , ...exportOptions } = options ;
478+
479+ const result = await siteArchiveExport ( instance , dataUnits , exportOptions ) ;
480+
481+ // Download archive from instance via WebDAV
482+ const webdavPath = `Impex/src/instance/${ result . archiveFilename } ` ;
454483 logger . debug ( { path : webdavPath } , `Downloading archive: ${ webdavPath } ` ) ;
455- const archiveData = await instance . webdav . get ( webdavPath ) ;
484+ const data = Buffer . from ( await instance . webdav . get ( webdavPath ) ) ;
456485
457- // Clean up if not keeping
486+ // Clean up from instance if not keeping
458487 if ( ! keepArchive ) {
459488 await instance . webdav . delete ( webdavPath ) ;
460489 logger . debug ( { path : webdavPath } , `Archive deleted: ${ webdavPath } ` ) ;
461490 }
462491
463492 return {
464- execution,
465- archiveFilename : zipFilename ,
466- data : Buffer . from ( archiveData ) ,
493+ ...result ,
494+ data,
467495 archiveKept : keepArchive ,
468496 } ;
469497}
470498
471499/**
472- * Exports a site archive and saves it to a local path.
500+ * Exports a site archive, downloads it, and saves it to a local path.
501+ *
502+ * Runs the export job on the instance, downloads the archive via WebDAV,
503+ * and saves it locally. Optionally keeps the archive on the instance.
473504 *
474505 * @param instance - B2C instance to export from
475506 * @param dataUnits - Data units configuration
476507 * @param outputPath - Local path to save the archive
477- * @param options - Export options
478- * @returns Export result
508+ * @param options - Export and download options
509+ * @returns Export result with local path
479510 *
480511 * @example
481512 * ```typescript
@@ -490,16 +521,12 @@ export async function siteArchiveExportToPath(
490521 instance : B2CInstance ,
491522 dataUnits : Partial < ExportDataUnitsConfiguration > ,
492523 outputPath : string ,
493- options : SiteArchiveExportOptions & { extractZip ?: boolean } = { } ,
494- ) : Promise < SiteArchiveExportResult & { localPath : string } > {
524+ options : SiteArchiveExportOptions & { keepArchive ?: boolean ; extractZip ?: boolean } = { } ,
525+ ) : Promise < SiteArchiveExportResult & { localPath : string ; archiveKept : boolean } > {
495526 const logger = getLogger ( ) ;
496- const { extractZip = true , ...exportOptions } = options ;
497-
498- const result = await siteArchiveExport ( instance , dataUnits , exportOptions ) ;
527+ const { extractZip = true , ...downloadOptions } = options ;
499528
500- if ( ! result . data ) {
501- throw new Error ( 'No archive data returned' ) ;
502- }
529+ const result = await siteArchiveExportToBuffer ( instance , dataUnits , downloadOptions ) ;
503530
504531 // Determine output handling
505532 const isZipPath = outputPath . endsWith ( '.zip' ) ;
0 commit comments