Convert custom post metadata array to product attributes
@param { Array } metadata Array of post metadata
@returns { Object } properties extracted from the metadata, to be merged into the product object
function customPostMetadataToProductAttributes( metadata ) {
	const productAttributes = {};

	metadata.forEach( ( { key, value } ) => {
		const schemaKey = metaKeyToSchemaKeyMap[ key ];
		if ( ! schemaKey ) {
			return;
		}

		// If the property's type is marked as boolean in the schema,
		// convert the value from PHP-ish truthy/falsy numbers to a plain boolean.
		// Strings "0" and "" are converted to false, "1" is converted to true.
		if ( metadataSchema[ schemaKey ].type === 'boolean' ) {
			value = !! Number( value );
		}

		productAttributes[ schemaKey ] = value;
	} );

	return productAttributes;
}