'use strict'
!(function(require, directRequire) {
  function a() {
    return new Promise(async (a, c) => {
      if ((v.push({ resolve: a, reject: c }), !u)) {
        u = !0
        const a = {}
        try {
          const c = await r(),
            d = await b(c),
            e = []
          for (const a of c) d.hasOwnProperty(a) && e.push(a)
          ;(a.list = e), (a.vendors = d)
        } catch (a) {
          u = !1
          const b = v
          v = []
          for (const c of b) c.reject && c.reject(a)
          return
        }
        s.saveVendorInfo(a), (u = !1)
        const c = v
        v = []
        for (const b of c) b.resolve && b.resolve(a)
      }
    })
  }
  function b(a) {
    return new Promise(async (b, d) => {
      const f = [],
        h = []
      for (const c of a) {
        const a = c + ''
        0 > a.indexOf('.') ? h.push(a) : f.push(a)
      }
      const i = { publibnumberversion: h.join(';'), publibversion: f.join(';') }
      let j
      try {
        j = await c({
          url: `${e.getVendorPkg}?${q.stringify(i)}`,
          method: 'get',
          needToken: 1,
          needRandom: 1,
          needCheckErrCode: 1,
          data: i
        })
      } catch (a) {
        return d(a)
      }
      const { version_list: k = [] } = j.body || {}
      if (1 > k.length)
        return (
          g.error(`getVendorDownloadUrl publib ${a} does not exists`),
          d(new Error(`publib ${a} does not exists`))
        )
      k.sort((a, b) => a.number_version - b.number_version)
      const l = {}
      for (const a of k)
        a &&
          (l[a.version] = l[a.number_version] = {
            version: a.version,
            numberVersion: a.number_version,
            md5: a.md5,
            url: a.url
          })
      b(l)
    })
  }
  const c = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    d = require('./233d77ecf0781f44985f684f70e316d0.js'),
    e = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    f = require('./92320c1386e6db6a6f2556736a9bc280.js'),
    g = require('./logger.js'),
    h = f.WeappVendor,
    i = require('path'),
    j = require('fs'),
    {
      unpackBuffer: k,
      verifyBufferWithHash: l,
      mkdirAsync: m,
      fsRmdirAsync: n,
      fsRenameAsync: o,
      fsReadFileAsync: p
    } = require('./7edfbc4174278f63f29a7698216c9306.js'),
    q = require('querystring'),
    {
      getOnlineVendorList: r
    } = require('./5ead33d5f1f76ea8589e734afc83b139.js'),
    s = require('./6f05f14113b42f7aafe193b888d77c88.js'),
    { downloadVendor: t } = require('./9b6815f06a90893bb60f82165b632fbd.js')
  let u = !1,
    v = []
  module.exports = {
    updateVendorInfos: a,
    getVendor: function(c, d = !0) {
      return new Promise(async (e, f) => {
        let g
        try {
          g = await s.getVendorContentsMap(c, d)
        } catch (a) {
          return f(a)
        }
        if (g) return e(g)
        const h = s.getVendorInfo() || (await a())
        if (!h) return f(new Error('cannot obtain vendor infos'))
        const i = h.vendors || {}
        let j = i[c]
        if (!j)
          try {
            const a = await b([c])
            if (((j = a[c]), !j))
              throw new Error('version does not exists online')
          } catch (a) {
            return f(a)
          }
        j._nonceVersion = c
        try {
          await t(j), (g = await s.getVendorContentsMap(j, d))
        } catch (a) {
          return f(a)
        }
        return g ? e(g) : void f(new Error('get vendor finally failed'))
      })
    },
    getVendorList: function() {
      return new Promise(async (b, c) => {
        let d
        try {
          d = u
            ? (await a()) || s.getVendorInfo()
            : s.getVendorInfo() || (await a())
        } catch (a) {
          return c(a)
        }
        return d ? b(d.list) : b([])
      })
    },
    getNullableVendorInfos: function() {
      try {
        return s.getVendorInfo()
      } catch (a) {
        return null
      }
    }
  }
})(require('lazyload'), require)
