@@ -11,7 +11,7 @@ import { join } from "path";
1111import { TEMPLATE_ENGINES } from "../engines" ;
1212import { TemplateEngineOptions , TemplatePreview , TemplatePreviews } from "../engines/types" ;
1313import Mailer from "../mailer/mailer" ;
14- import { CSVRecord , EmailString } from "../util/types" ;
14+ import { MappedCSVRecord , EmailString } from "../util/types" ;
1515import { SidecarData } from "./types" ;
1616
1717const PARTS_SEPARATOR = "__" ;
@@ -26,8 +26,8 @@ const logger = createLogger("docsoc.sidecar");
2626 * @returns
2727 */
2828export const getRecordPreviewPrefix = (
29- record : CSVRecord ,
30- fileNamer : ( record : CSVRecord ) => string ,
29+ record : MappedCSVRecord ,
30+ fileNamer : ( record : MappedCSVRecord ) => string ,
3131) => `${ fileNamer ( record ) } ` ;
3232
3333/**
@@ -40,8 +40,8 @@ export const getRecordPreviewPrefix = (
4040 * // => "file_1__nunjucks__preview1.txt"
4141 */
4242export const getRecordPreviewPrefixForIndividual = (
43- record : CSVRecord ,
44- fileNamer : ( record : CSVRecord ) => string ,
43+ record : MappedCSVRecord ,
44+ fileNamer : ( record : MappedCSVRecord ) => string ,
4545 templateEngine : string ,
4646 preview : TemplatePreview ,
4747) =>
@@ -58,16 +58,16 @@ export const getRecordPreviewPrefixForIndividual = (
5858 * // => "file_1-metadata.json"
5959 */
6060export const getRecordPreviewPrefixForMetadata = (
61- record : CSVRecord ,
62- fileNamer : ( record : CSVRecord ) => string ,
61+ record : MappedCSVRecord ,
62+ fileNamer : ( record : MappedCSVRecord ) => string ,
6363) => `${ getRecordPreviewPrefix ( record , fileNamer ) } ${ METADATA_FILE_SUFFIX } ` ;
6464
6565type ValidRecordReturn = { valid : false ; reason : string } | { valid : true } ;
6666/**
6767 * Check a record is valid for use in mailmerge - specifically, that it has a valid email address and a subject.
6868 * @param record __Mapped__ CSV Record to validate
6969 */
70- export const validateRecord = ( record : CSVRecord ) : ValidRecordReturn => {
70+ export const validateRecord = ( record : MappedCSVRecord ) : ValidRecordReturn => {
7171 if ( ! Mailer . validateEmail ( record [ "email" ] as string ) ) {
7272 return {
7373 valid : false ,
@@ -96,9 +96,9 @@ export const validateRecord = (record: CSVRecord): ValidRecordReturn => {
9696 * @returns
9797 */
9898export async function writeMetadata (
99- record : CSVRecord ,
99+ record : MappedCSVRecord ,
100100 sidecarData : SidecarData ,
101- fileNamer : ( record : CSVRecord ) => string ,
101+ fileNamer : ( record : MappedCSVRecord ) => string ,
102102 previewsRoot : string ,
103103) : Promise < void > {
104104 const recordState = validateRecord ( record ) ;
@@ -116,6 +116,9 @@ export async function writeMetadata(
116116 return Promise . resolve ( ) ;
117117}
118118
119+ const parseEmailList = ( emailList : string | undefined ) : EmailString [ ] =>
120+ emailList ? ( emailList . split ( / \s / ) as EmailString [ ] ) : [ ] ;
121+
119122/**
120123 * Generate sidecar metadata for a record & the previews generated from it.
121124 * It is recommended you then store this info alongside the preview, e.g. in a JSON file
@@ -130,8 +133,8 @@ export async function writeMetadata(
130133 * @returns Sidecar metadata
131134 */
132135export function getSidecarMetadata (
133- fileNamer : ( record : CSVRecord ) => string ,
134- record : CSVRecord ,
136+ fileNamer : ( record : MappedCSVRecord ) => string ,
137+ record : MappedCSVRecord ,
135138 templateEngine : TEMPLATE_ENGINES ,
136139 templateOptions : TemplateEngineOptions ,
137140 attachments : string [ ] ,
@@ -155,7 +158,9 @@ export function getSidecarMetadata(
155158 } ,
156159 } ) ) ,
157160 email : {
158- to : record [ "email" ] as EmailString ,
161+ to : parseEmailList ( record [ "email" ] as string ) ,
162+ cc : parseEmailList ( record [ "cc" ] as string ) ,
163+ bcc : parseEmailList ( record [ "bcc" ] as string ) ,
159164 subject : record [ "subject" ] as string ,
160165 } ,
161166 attachments,
0 commit comments