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C,OAtBA,EAAS,GAAK,EAAO,KAAK,aAAa,GAIvC,EAAS,OAAS,CAAC,EAAM,KACH,iBAAT,GAAsB,IAAM,EAAO,CAAC,GAC/C,EAAO,EAAO,KAAK,OAAO,EAAK,GAC/B,IAAI,EAAO,UAAU,EAAQ,GAK7B,OAJA,EAAK,GAAK,EAAO,KAAK,aAAa,GAC/B,IACF,EAAS,GAAQ,GAEZ,CAAI,EAMb,EAAS,IAAO,GACP,EAAS,IAAS,KAGpB,CACT,EACA,OAAO,QAAQ,WAAa","file":"/npm/thorin-plugin-queue-gcloud@1.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/thorin-plugin-queue-gcloud@1.0.1/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","'use strict';\nconst PubSub = require('@google-cloud/pubsub'),\n  path = require('path'),\n  fs = require('fs'),\n  initQueue = require('./lib/queue');\n/**\n * The queue system uses Google Cloud PubSub and exposes 3 functions:\n * - push(payload, _opt)\n * - pull(callbackFn, _opt)\n *\n * Notes:\n * - Functions are promisified\n * Example:\n *\n * const queueObj = thorin.plugin('queue');\n * await queueObj.push({\n *  my: 'data'\n * });\n *\n * await queueObj.pull(async (msg) => {\n *  console.log(\"message\", msg);\n *  msg.ack();  // on completed process\n * });\n *\n * NOTE:\n * Credentials can be provided as follow:\n *  - environment variable GOOGLE_APPLICATION_CREDENTIALS containing the JSON credentials (as string)\n *  - actual JSON content of the credentials.json file\n *  - absolute path of the credentials.json file\n *  - path relative to thorin.root of the credentials.json file.\n * */\nmodule.exports = function (thorin, opt, pluginName) {\n  const defaultOpt = {\n    logger: pluginName || 'queue',\n    topic: null,\n    projectId: null,\n    credentials: null,  // The credentials JSON containing the .json file\n    subscription: 'default',  // the subscription name to use\n    options: {\n      publisher: null, // additional options when creating publisher\n      subscription: null  // additional options when creating subscriber\n    },\n    messages: 1  // max number of messages to pull once.\n  };\n  opt = thorin.util.extend(defaultOpt, opt);\n  let logger = thorin.logger(opt.logger);\n  if (process.env.GOOGLE_APPLICATION_CREDENTIALS && (!opt.credentials || (typeof opt.credentials === 'object' && Object.keys(opt.credentials).length === 0))) {\n    opt.credentials = process.env.GOOGLE_APPLICATION_CREDENTIALS;\n  }\n  if (!opt.credentials) {\n    logger.fatal(`PubSub GCloud credentials are missing`);\n    throw thorin.error('QUEUE.CREDENTIALS', 'Invalid or missing credentials');\n  }\n  if (typeof opt.credentials === 'string' && opt.credentials) {\n    opt.credentials = opt.credentials.trim();\n    if (opt.credentials.charAt(0) === '{') {\n      try {\n        opt.credentials = JSON.parse(opt.credentials);\n      } catch (e) {\n        throw thorin.error('QUEUE.GCLOUD', 'Credentials could not be parsed');\n      }\n    } else {\n      let credPath = opt.credentials.charAt(0) === '/' ? path.normalize(opt.credentials) : path.normalize(thorin.root + '/' + opt.credentials);\n      try {\n        let creds = fs.readFileSync(credPath, {encoding: 'utf8'});\n        creds = JSON.parse(creds);\n        opt.credentials = creds;\n      } catch (e) {\n        throw thorin.error('QUEUE.GCLOUD', 'Credentials could not be read [' + credPath + ']');\n      }\n    }\n  }\n  if (!opt.topic) throw thorin.error('QUEUE.GCLOUD', 'The topic name is required');\n  let queueMap = {};\n  let queueObj = initQueue(thorin, opt);\n  queueObj.id = thorin.util.randomString(5);\n  /**\n   * Creates a new queue\n   * */\n  queueObj.create = (_opt, name) => {\n    if (typeof _opt !== 'object' || !_opt) _opt = {};\n    _opt = thorin.util.extend(opt, _opt);\n    let qObj = initQueue(thorin, _opt);\n    qObj.id = thorin.util.randomString(4);\n    if (name) {\n      queueMap[name] = qObj;\n    }\n    return qObj;\n  }\n\n  /**\n   * RETURN a previously created queue\n   * */\n  queueObj.get = (name) => {\n    return queueMap[name] || null;\n  };\n\n  return queueObj;\n};\nmodule.exports.publicName = 'queue';"]}