{"version":3,"sources":["jsdelivr-header.js","/npm/stock-market-news-api@1.0.2/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;ACJA,MAAM,GAAK,QAAQ,oBACb,OAAS,QAAQ,YACjB,OAAS,QAAQ,UACjB,MAAQ,QAAQ,SAEhB,MAAQ,CAAE,OAAQ,IAElB,UAAa,IACjB,MAAM,OAAS,CAAM,EAajB,QAAU,MAAO,EAAQ,CAAC,KAC9B,MAAM,EAAU,IAAK,EAAO,KAAM,kBAE5B,EAAU,CACd,OAAQ,OACR,IAAK,OAAO,SAAS,SACrB,QAAS,CAAE,cAAe,MAAM,QAChC,KAAM,GAGR,IAAI,KAAE,SAAe,MAAM,GAQ3B,OANA,EAAK,SAAW,EAAK,SAAS,KAC5B,EAAG,UAAS,aAAY,UAAS,UAAS,MAAW,IAChD,MAIA,CAAI,EAMP,eAAiB,CAAC,EAElB,WAAc,IAClB,MAAM,EAAM,OAAO,UAAU,SACvB,EAAS,CAAE,MAAO,CAAE,WAC1B,eAAe,OAAS,GAAG,EAAK,GAChC,eAAe,OAAO,GAAG,WAAW,IAClC,QAAQ,IAAI,sBAAuB,KAErC,eAAe,OAAO,GAAG,WAAY,mBACrC,eAAe,OAAO,GAAG,QAAS,QAAQ,MAAM,EAG5C,kBAAqB,IACzB,QAAQ,IAAI,GACZ,eAAe,aAAa,KAAK,WAAY,EAAS,EAGlD,MAAQ,KACR,eAAe,OAAO,OACxB,eAAe,OAAO,OACxB,EAGI,QAAW,IACf,UAAU,GACV,WAAW,GACX,eAAe,aAAe,IAAI,OAAO,aACzC,QAAQ,UAAU,GAAK,eAAe,aAAa,GAC5C,eAAe,cAMlB,QAAU,CACd,oBACA,SAAU,CACR,oBACA,iBAEF,UAAW,CACT,oBACA,gBACA,cAIJ,OAAO,QAAU","file":"/npm/stock-market-news-api@1.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/stock-market-news-api@1.0.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\nconst io = require('socket.io-client');\nconst config = require('./config');\nconst events = require('events');\nconst axios = require('axios');\n\nconst store = { apiKey: '' };\n\nconst setApiKey = (apiKey) => {\n  store.apiKey = apiKey;\n};\n\n/*\n * Query API\n */\n\n/**\n * Query news\n *\n * @param {String} query The query string\n * @returns {Object}     The response from the API\n */\nconst getNews = async (query = {}) => {\n  const payload = { ...query, type: 'filterArticles' };\n\n  const options = {\n    method: 'post',\n    url: config.queryApi.endpoint,\n    headers: { Authorization: store.apiKey },\n    data: payload,\n  };\n\n  let { data } = await axios(options);\n\n  data.articles = data.articles.map(\n    ({ markets, categories, content, meta, ...rest }) => ({\n      ...rest,\n    })\n  );\n\n  return data;\n};\n\n/*\n * Stream API\n */\nconst streamApiStore = {};\n\nconst initSocket = (apiKey) => {\n  const uri = config.streamApi.endpoint;\n  const params = { query: { apiKey } };\n  streamApiStore.socket = io(uri, params);\n  streamApiStore.socket.on('connect', () =>\n    console.log('Socket connected to', uri)\n  );\n  streamApiStore.socket.on('articles', handleNewArticles);\n  streamApiStore.socket.on('error', console.error);\n};\n\nconst handleNewArticles = (articles) => {\n  console.log(articles);\n  streamApiStore.eventEmitter.emit('articles', articles);\n};\n\nconst close = () => {\n  if (streamApiStore.socket.close) {\n    streamApiStore.socket.close();\n  }\n};\n\nconst connect = (apiKey) => {\n  setApiKey(apiKey);\n  initSocket(apiKey);\n  streamApiStore.eventEmitter = new events.EventEmitter();\n  modules.streamApi.on = streamApiStore.eventEmitter.on;\n  return streamApiStore.eventEmitter;\n};\n\n/**\n * Exports\n */\nconst modules = {\n  setApiKey,\n  queryApi: {\n    setApiKey,\n    getNews,\n  },\n  streamApi: {\n    setApiKey,\n    connect,\n    close,\n  },\n};\n\nmodule.exports = modules;\n"]}