{"version":3,"file":"parseAttributesFromString-CYcxsS3n.mjs","names":[],"sources":["../src/lib/requests/parseAttributesFromString.ts"],"sourcesContent":["import colors from 'colors';\nimport * as t from 'io-ts';\n\nimport { logger } from '../../logger.js';\n\nexport const ParsedAttributeInput = t.type({\n  /** Attribute key */\n  key: t.string,\n  /** Attribute values */\n  values: t.array(t.string),\n});\n\n/** Type override */\nexport type ParsedAttributeInput = t.TypeOf<typeof ParsedAttributeInput>;\n\n/**\n * Parse out the extra attributes to apply to all requests uploaded\n *\n * @param attributes - input as string, e.g. ['key:value1;value2','key2:value3;value4']\n * @returns The parsed attributes\n */\nexport function parseAttributesFromString(attributes: string[]): ParsedAttributeInput[] {\n  // Parse out the extra attributes to apply to all requests uploaded\n  const parsedAttributes = attributes.map((attribute) => {\n    const [attributeKey, attributeValuesRaw] = attribute.trim().split(':');\n    if (!attributeValuesRaw) {\n      throw new Error('Expected attributes in key:value1;value2,key2:value3;value4');\n    }\n    const attributeValues = attributeValuesRaw.split(';');\n    return {\n      key: attributeKey,\n      values: attributeValues,\n    };\n  });\n  logger.info(colors.magenta('Attributes to apply to all requests:'));\n  logger.info(colors.magenta(JSON.stringify(parsedAttributes, null, 2)));\n  return parsedAttributes;\n}\n"],"mappings":"wFAKA,MAAa,EAAuB,EAAE,KAAK,CAEzC,IAAK,EAAE,OAEP,OAAQ,EAAE,MAAM,EAAE,OAAO,CAC1B,CAAC,CAWF,SAAgB,EAA0B,EAA8C,CAEtF,IAAM,EAAmB,EAAW,IAAK,GAAc,CACrD,GAAM,CAAC,EAAc,GAAsB,EAAU,MAAM,CAAC,MAAM,IAAI,CACtE,GAAI,CAAC,EACH,MAAU,MAAM,8DAA8D,CAGhF,MAAO,CACL,IAAK,EACL,OAHsB,EAAmB,MAAM,IAGxB,CACxB,EACD,CAGF,OAFA,EAAO,KAAK,EAAO,QAAQ,uCAAuC,CAAC,CACnE,EAAO,KAAK,EAAO,QAAQ,KAAK,UAAU,EAAkB,KAAM,EAAE,CAAC,CAAC,CAC/D"}