{
  "version": 3,
  "sources": ["../../src/utils/import.ts"],
  "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { readTextFile } from './file';\nimport type {\n\tParsedContent,\n\tPostType,\n\tReusableBlock,\n\tReusableBlockData,\n} from './types';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param file - File to import\n * @return Promise returning the imported reusable block\n */\nasync function importReusableBlock( file: File ): Promise< ReusableBlock > {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent: ParsedContent;\n\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t}\n\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst reusableBlock = await apiFetch< ReusableBlock >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t} satisfies ReusableBlockData,\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],
  "mappings": ";AAAA,OAAO,cAAc;AACrB,SAAS,oBAAoB;AAc7B,eAAe,oBAAqB,MAAuC;AAC1E,QAAM,cAAc,MAAM,aAAc,IAAK;AAC7C,MAAI;AAEJ,MAAI;AACH,oBAAgB,KAAK,MAAO,WAAY;AAAA,EACzC,QAAQ;AACP,UAAM,IAAI,MAAO,mBAAoB;AAAA,EACtC;AAEA,MACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UACpC;AACD,UAAM,IAAI,MAAO,2BAA4B;AAAA,EAC9C;AAEA,QAAM,WAAW,MAAM,SAAsB;AAAA,IAC5C,MAAM;AAAA,EACP,CAAE;AAEF,QAAM,gBAAgB,MAAM,SAA2B;AAAA,IACtD,MAAM,UAAW,SAAS,SAAU;AAAA,IACpC,MAAM;AAAA,MACL,OAAO,cAAc;AAAA,MACrB,SAAS,cAAc;AAAA,MACvB,QAAQ;AAAA,MACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACT,CAAE;AAEF,SAAO;AACR;AAEA,IAAO,iBAAQ;",
  "names": []
}
