{"version":3,"file":"uploadCookiesFromCsv-DbQePRJ3.mjs","names":[],"sources":["../src/lib/consent-manager/uploadCookiesFromCsv.ts"],"sourcesContent":["import { ConsentTrackerStatus } from '@transcend-io/privacy-types';\nimport { buildTranscendGraphQLClient, syncCookies } from '@transcend-io/sdk';\nimport { splitCsvToList } from '@transcend-io/utils';\nimport colors from 'colors';\n\nimport { CookieInput, CookieCsvInput } from '../../codecs.js';\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { readCsv } from '../requests/readCsv.js';\n\nconst OMIT_COLUMNS = [\n  'ID',\n  'Activity',\n  'Encounters',\n  'Last Seen At',\n  'Has Native Do Not Sell/Share Support',\n  'IAB USP API Support',\n  'Service Description',\n  'Website URL',\n  'Categories of Recipients',\n];\n\n/**\n * Upload a set of cookies from CSV\n *\n * @param options - Options\n */\nexport async function uploadCookiesFromCsv({\n  auth,\n  trackerStatus,\n  file,\n  transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n  /** CSV file path */\n  file: string;\n  /** Transcend API key authentication */\n  auth: string;\n  /** Sombra API key authentication */\n  trackerStatus: ConsentTrackerStatus;\n  /** API URL for Transcend backend */\n  transcendUrl?: string;\n}): Promise<void> {\n  // Build a GraphQL client\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n  // Read from CSV the set of cookie inputs\n  logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n  const cookieInputs = readCsv(file, CookieCsvInput);\n\n  // Convert these  inputs into a format that the other function can use\n  const validatedCookieInputs = cookieInputs.map(\n    ({\n      'Is Regex?': isRegex,\n      Notes,\n      // TODO: https://transcend.height.app/T-26391 - export in CSV\n      // eslint-disable-next-line @typescript-eslint/no-unused-vars\n      Service,\n      Purpose,\n      Status,\n      Owners,\n      Teams,\n      Name,\n      ...rest\n    }): CookieInput => ({\n      ...(typeof isRegex === 'string' ? { isRegex: isRegex.toLowerCase() === 'true' } : {}),\n      name: Name,\n      description: Notes,\n      trackingPurposes: splitCsvToList(Purpose),\n      // TODO: https://transcend.height.app/T-26391\n      // service: Service,\n      // Apply the trackerStatus to all values in the CSV -> allows for customer to define tracker status\n      // on a row by row basis if needed\n      status: Status || trackerStatus,\n      owners: Owners ? splitCsvToList(Owners) : undefined,\n      teams: Teams ? splitCsvToList(Teams) : undefined,\n      // all remaining options are attribute\n      attributes: Object.entries(rest)\n        // filter out native columns that are exported from the admin dashboard\n        // but not custom attributes\n        .filter(([key]) => !OMIT_COLUMNS.includes(key))\n        .map(([key, value]) => ({\n          key,\n          values: splitCsvToList(value),\n        })),\n    }),\n  );\n\n  // Upload the cookies into Transcend dashboard\n  const syncedCookies = await syncCookies(client, validatedCookieInputs, { logger });\n\n  // Log errors\n  if (!syncedCookies) {\n    logger.error(\n      colors.red('Encountered error(s) syncing cookies from CSV, see logs above for more info. '),\n    );\n    process.exit(1);\n  }\n}\n"],"mappings":"mUAUA,MAAM,EAAe,CACnB,KACA,WACA,aACA,eACA,uCACA,sBACA,sBACA,cACA,2BACD,CAOD,eAAsB,EAAqB,CACzC,OACA,gBACA,OACA,eAAe,GAUC,CAEhB,IAAM,EAAS,EAA4B,EAAc,EAAK,CAG9D,EAAO,KAAK,EAAO,QAAQ,YAAY,EAAK,aAAa,CAAC,CA6CrD,MAHuB,EAAY,EAzCnB,EAAQ,EAAM,EAGO,CAAC,KACxC,CACC,YAAa,EACb,QAGA,UACA,UACA,SACA,SACA,QACA,OACA,GAAG,MACe,CAClB,GAAI,OAAO,GAAY,SAAW,CAAE,QAAS,EAAQ,aAAa,GAAK,OAAQ,CAAG,EAAE,CACpF,KAAM,EACN,YAAa,EACb,iBAAkB,EAAe,EAAQ,CAKzC,OAAQ,GAAU,EAClB,OAAQ,EAAS,EAAe,EAAO,CAAG,IAAA,GAC1C,MAAO,EAAQ,EAAe,EAAM,CAAG,IAAA,GAEvC,WAAY,OAAO,QAAQ,EAAK,CAG7B,QAAQ,CAAC,KAAS,CAAC,EAAa,SAAS,EAAI,CAAC,CAC9C,KAAK,CAAC,EAAK,MAAY,CACtB,MACA,OAAQ,EAAe,EAAM,CAC9B,EAAE,CACN,EAIkE,CAAE,CAAE,SAAQ,CAAC,GAIhF,EAAO,MACL,EAAO,IAAI,gFAAgF,CAC5F,CACD,QAAQ,KAAK,EAAE"}