11import { input } from "@inquirer/prompts" ;
2- import { getDataV2 } from "@trustvc/trustvc" ;
2+ import { getDocumentData } from "@trustvc/trustvc" ;
33import { UnwrapOAInput } from "../../types" ;
4- import { documentsInDirectory , isDir , isFile , readOpenAttestationFile , writeFile } from "../../utils" ;
4+ import { documentsInDirectory , isDir , isDirectoryValid , isFile , readOpenAttestationFile , writeFile } from "../../utils" ;
55import signale from "signale" ;
66import path from "path" ;
7- import { mkdirSync } from "fs" ;
87
98export const command = 'oa-unwrap' ;
109export const describe = 'Unwrap wrapped OpenAttestation document(s) (Only for individual documents)' ;
@@ -50,10 +49,7 @@ export const promptForInputs = async (): Promise<UnwrapOAInput> => {
5049 default : '.' ,
5150 } ) ;
5251
53- if ( ! isDir ( pathToOutputDirectory ) ) {
54- signale . info ( `Directory not found; Creating new directory: ${ pathToOutputDirectory } ` ) ;
55- mkdirSync ( pathToOutputDirectory , { recursive : true } ) ;
56- }
52+ if ( ! isDirectoryValid ( pathToOutputDirectory ) ) throw new Error ( 'Output path is not valid' ) ;
5753
5854 return {
5955 docPaths,
@@ -68,7 +64,7 @@ export const unwrapOA = async ({
6864 for ( const doc of docPaths ) {
6965 const wrappedOADocument = readOpenAttestationFile ( doc ) ;
7066 try {
71- const unwrappedDocument = getDataV2 ( wrappedOADocument as any ) ; // Any to resolve the module resolution conflict for WrappedDocument between @trustvc /trustvc and @tradetrust -tt/tradetrust
67+ const unwrappedDocument = getDocumentData ( wrappedOADocument ) ;
7268 if ( ! unwrappedDocument ) throw new Error ( 'Invalid wrapped OpenAttestation document' ) ;
7369 const outFile = path . join ( pathToOutputDirectory , path . basename ( doc ) ) ;
7470 writeFile ( outFile , unwrappedDocument , true ) ;
0 commit comments