{"version":3,"file":"notifyPrivacyRequestsAdditionalTime-DflTzDRg.mjs","names":[],"sources":["../src/lib/requests/notifyPrivacyRequestsAdditionalTime.ts"],"sourcesContent":["import { RequestAction } from '@transcend-io/privacy-types';\nimport {\n  buildTranscendGraphQLClient,\n  fetchAllTemplates,\n  makeGraphQLRequest,\n} from '@transcend-io/sdk';\nimport { map } from '@transcend-io/utils';\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\n\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { NOTIFY_ADDITIONAL_TIME, fetchAllRequests } from '../graphql/index.js';\n\n/**\n * Mark a set of privacy requests to be in silent mode.\n * Note requests in silent mode are ignored\n *\n * @param options - Options\n * @returns The number of requests marked silent\n */\nexport async function notifyPrivacyRequestsAdditionalTime({\n  requestActions = Object.values(RequestAction),\n  auth,\n  requestIds,\n  createdAtBefore,\n  days = 45,\n  daysLeft = 10,\n  createdAtAfter,\n  updatedAtBefore,\n  updatedAtAfter,\n  emailTemplate = 'Additional Time Needed',\n  concurrency = 100,\n  transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n  /** The request actions that should be restarted */\n  requestActions?: RequestAction[];\n  /** Filter for requests created before this date */\n  createdAtBefore: Date;\n  /** Filter for requests created after this date */\n  createdAtAfter?: Date;\n  /** Filter for requests updated before this date */\n  updatedAtBefore?: Date;\n  /** Filter for requests updated after this date */\n  updatedAtAfter?: Date;\n  /** Email template */\n  emailTemplate?: string;\n  /** Transcend API key authentication */\n  auth: string;\n  /** Number of days to extend request by */\n  days?: number;\n  /**\n   * Only notify requests that have less than this number of days until they are considered expired.\n   * This allows for re-running the command without notifying the same users multiple times\n   */\n  daysLeft?: number;\n  /** Concurrency limit for approving */\n  concurrency?: number;\n  /** The set of privacy requests to notify */\n  requestIds?: string[];\n  /** API URL for Transcend backend */\n  transcendUrl?: string;\n}): Promise<number> {\n  // Find all requests made before createdAt that are in a removing data state\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n  // Time duration\n  const t0 = new Date().getTime();\n  // create a new progress bar instance and use shades_classic theme\n  const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);\n\n  // Grab the template with that title\n  const matchingTemplates = await fetchAllTemplates(client, {\n    logger,\n    filterBy: { title: emailTemplate },\n  });\n  const exactTemplateMatch = matchingTemplates.find((template) => template.title === emailTemplate);\n  if (!exactTemplateMatch) {\n    throw new Error(`Failed to find a template with title: \"${emailTemplate}\"`);\n  }\n\n  // Pull in the requests\n  let allRequests = await fetchAllRequests(client, {\n    actions: requestActions,\n    createdAtBefore,\n    createdAtAfter,\n    updatedAtBefore,\n    updatedAtAfter,\n    isSilent: false,\n    isClosed: false,\n    requestIds,\n  });\n\n  // Filter requests by daysLeft\n  allRequests = allRequests.filter(\n    (request) => typeof request.daysRemaining === 'number' && request.daysRemaining < daysLeft,\n  );\n\n  // Notify Transcend\n  logger.info(colors.magenta(`Notifying \"${allRequests.length}\" that more time is needed.`));\n\n  let total = 0;\n  progressBar.start(allRequests.length, 0);\n  await map(\n    allRequests,\n    async (requestToNotify) => {\n      await makeGraphQLRequest(client, NOTIFY_ADDITIONAL_TIME, {\n        variables: {\n          input: {\n            requestId: requestToNotify.id,\n            template: exactTemplateMatch.template.defaultMessage,\n            subject: exactTemplateMatch.subject.defaultMessage,\n            additionalTime: days,\n          },\n        },\n        logger,\n      });\n\n      total += 1;\n      progressBar.update(total);\n    },\n    { concurrency },\n  );\n\n  progressBar.stop();\n  const t1 = new Date().getTime();\n  const totalTime = t1 - t0;\n\n  logger.info(\n    colors.green(\n      `Successfully marked ${total} requests as silent mode in \"${totalTime / 1000}\" seconds!`,\n    ),\n  );\n  return allRequests.length;\n}\n"],"mappings":"mbAqBA,eAAsB,EAAoC,CACxD,iBAAiB,OAAO,OAAO,EAAc,CAC7C,OACA,aACA,kBACA,OAAO,GACP,WAAW,GACX,iBACA,kBACA,iBACA,gBAAgB,yBAChB,cAAc,IACd,eAAe,GA6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