{"version":3,"sources":["jsdelivr-header.js","/npm/serverless-prune-plugin@2.0.2/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,MAAM,UAAY,QAAQ,YAE1B,MAAM,MACJ,WAAA,CAAY,EAAY,GAAS,IAAE,EAAG,SAAE,GAAa,CAAC,GACpD,KAAK,WAAa,EAClB,KAAK,QAAU,GAAW,CAAC,EAC3B,KAAK,SAAW,KAAK,WAAW,YAAY,OAC5C,KAAK,IAAM,GAAO,EAAW,IAAI,IAAI,KAAK,EAAW,KACrD,KAAK,SAAW,EAEhB,KAAK,aAAe,KAAK,WAAW,KAAK,WAAW,QAAQ,QAE5D,KAAK,SAAW,CACd,MAAO,CACL,MAAO,wEACP,gBAAiB,CAAC,SAClB,QAAS,CACP,OAAQ,CACN,MAAO,sCACP,SAAU,IACV,UAAU,EACV,KAAM,UAER,MAAO,CACL,MAAO,uBACP,SAAU,IACV,KAAM,UAER,OAAQ,CACN,MAAO,wBACP,SAAU,IACV,KAAM,UAER,SAAU,CACR,MAAO,0DACP,SAAU,IACV,UAAU,EACV,KAAM,UAER,MAAO,CACL,MAAO,2DACP,SAAU,IACV,UAAU,EACV,KAAM,UAER,cAAe,CACb,MAAO,uDACP,SAAU,IACV,UAAU,EACV,KAAM,WAER,OAAQ,CACN,MAAO,4HACP,SAAU,IACV,UAAU,EACV,KAAM,WAER,QAAS,CACP,MAAO,iDACP,UAAU,EACV,KAAM,cAMd,KAAK,MAAQ,CACX,cAAe,KAAK,SAAS,KAAK,MAClC,sBAAuB,KAAK,WAAW,KAAK,MAEhD,CAEA,SAAA,GACE,OAAO,KAAK,QAAQ,QAAU,KAAK,aAAa,MAClD,CAEA,UAAA,CAAW,GACT,MAAM,EAAe,CAAC,EACtB,GAAI,GAAU,EAAO,MAAO,CAE1B,GAA2B,MAAvB,EAAO,MAAM,OAAgB,CAC/B,MAAM,EAAS,SAAS,EAAO,MAAM,QAChC,MAAM,KAAS,EAAa,OAA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J,KAAI,GAAK,EAAE,UACX,MAAK,CAAC,EAAG,IAAM,SAAS,KAAO,SAAS,GAAK,EAAI,SAAS,GAAK,SAAS,IAAM,EAAI,IAClF,MAAM,KAAK,YAChB,CAEA,sBAAA,CAAuB,EAAM,GAC3B,EAAmB,SAAQ,GAAW,KAAK,QAAQ,GAAG,KAAQ,6BAChE,CAIA,OAAA,CAAQ,GACF,KAAK,IAAI,KAAM,KAAK,IAAI,KAAK,GAC5B,KAAK,IAAI,UAAU,IAC1B,CAEA,SAAA,CAAU,GACJ,KAAK,IAAI,OAAQ,KAAK,IAAI,OAAO,GAChC,KAAK,IAAI,UAAU,IAC1B,CAEA,UAAA,CAAW,GACL,KAAK,IAAI,QAAS,KAAK,IAAI,QAAQ,GAClC,KAAK,IAAI,UAAU,IAC1B,CAEA,UAAA,CAAW,GACL,KAAK,IAAI,QAAS,KAAK,IAAI,QAAQ,GAClC,KAAK,IAAI,UAAU,IAC1B,CAEA,cAAA,CAAe,EAAM,GACd,KAAK,SAGR,KAAK,SAAS,OAAO,CACnB,UACA,SAJF,KAAK,IAAI,UAAU,OAOvB,CAEA,cAAA,CAAe,EAAM,GACd,KAAK,SAGR,KAAK,SAAS,IAAI,GAAM,OAAO,GAF/B,KAAK,IAAI,UAAU,IAIvB,CAEA,aAAA,CAAc,GACR,KAAK,UACP,KAAK,SAAS,IAAI,GAAM,QAE5B,EAGF,OAAO,QAAU","file":"/npm/serverless-prune-plugin@2.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/serverless-prune-plugin@2.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","'use strict';\n\nconst BbPromise = require('bluebird');\n\nclass Prune {\n  constructor(serverless, options, { log, progress } = {}) {\n    this.serverless = serverless;\n    this.options = options || {};\n    this.provider = this.serverless.getProvider('aws');\n    this.log = log || serverless.cli.log.bind(serverless.cli);\n    this.progress = progress;\n\n    this.pluginCustom = this.loadCustom(this.serverless.service.custom);\n\n    this.commands = {\n      prune: {\n        usage: 'Clean up deployed functions and/or layers by deleting older versions.',\n        lifecycleEvents: ['prune'],\n        options: {\n          number: {\n            usage: 'Number of previous versions to keep',\n            shortcut: 'n',\n            required: true,\n            type: 'string'\n          },\n          stage: {\n            usage: 'Stage of the service',\n            shortcut: 's',\n            type: 'string'\n          },\n          region: {\n            usage: 'Region of the service',\n            shortcut: 'r',\n            type: 'string'\n          },\n          function: {\n            usage: 'Function name. Limits cleanup to the specified function',\n            shortcut: 'f',\n            required: false,\n            type: 'string'\n          },\n          layer: {\n            usage: 'Layer name. Limits cleanup to the specified Lambda layer',\n            shortcut: 'l',\n            required: false,\n            type: 'string'\n          },\n          includeLayers: {\n            usage: 'Boolean flag. Includes the pruning of Lambda layers.',\n            shortcut: 'i',\n            required: false,\n            type: 'boolean'\n          },\n          dryRun: {\n            usage: 'Simulate pruning without executing delete actions. Deletion candidates are logged when used in conjunction with --verbose',\n            shortcut: 'd',\n            required: false,\n            type: 'boolean'\n          },\n          verbose: {\n            usage: 'Enable detailed output during plugin execution',\n            required: false,\n            type: 'boolean'\n          }\n        }\n      },\n    };\n\n    this.hooks = {\n      'prune:prune': this.cliPrune.bind(this),\n      'after:deploy:deploy': this.postDeploy.bind(this)\n    };\n  }\n\n  getNumber() {\n    return this.options.number || this.pluginCustom.number;\n  }\n\n  loadCustom(custom) {\n    const pluginCustom = {};\n    if (custom && custom.prune) {\n\n      if (custom.prune.number != null) {\n        const number = parseInt(custom.prune.number);\n        if (!isNaN(number)) pluginCustom.number = number;\n      }\n\n      if (typeof custom.prune.automatic === 'boolean') {\n        pluginCustom.automatic = custom.prune.automatic;\n      }\n\n      if (typeof custom.prune.includeLayers === 'boolean') {\n        pluginCustom.includeLayers = custom.prune.includeLayers;\n      }\n    }\n\n    return pluginCustom;\n  }\n\n  cliPrune() {\n    if (this.options.dryRun) {\n      this.logNotice('Dry-run enabled, no pruning actions will be performed.');\n    }\n\n    if(this.options.includeLayers) {\n      return BbPromise.all([\n        this.pruneFunctions(),\n        this.pruneLayers()\n      ]);\n    }\n\n    if (this.options.layer && !this.options.function) {\n      return this.pruneLayers();\n    } else {\n      return this.pruneFunctions();\n    }\n  }\n\n  postDeploy() {\n    this.pluginCustom = this.loadCustom(this.serverless.service.custom);\n\n    if (this.options.noDeploy === true) {\n      return BbPromise.resolve();\n    }\n\n    if (this.pluginCustom.automatic &&\n      this.pluginCustom.number !== undefined && this.pluginCustom.number >= 0) {\n\n      if(this.pluginCustom.includeLayers) {\n        return BbPromise.all([\n          this.pruneFunctions(),\n          this.pruneLayers()\n        ]);\n      }\n\n      return this.pruneFunctions();\n    } else {\n      return BbPromise.resolve();\n    }\n  }\n\n  pruneLayers() {\n    const selectedLayers = this.options.layer ? [this.options.layer] : this.serverless.service.getAllLayers();\n    const layerNames = selectedLayers.map(key => this.serverless.service.getLayer(key).name || key);\n\n    this.createProgress(\n      'prune-plugin-prune-layers',\n      'Pruning layer versions'\n    );\n\n    return BbPromise.mapSeries(layerNames, layerName => {\n\n      return BbPromise.join(\n        this.listVersionsForLayer(layerName),\n        (versions) => ({ name: layerName, versions: versions })\n      );\n\n    }).each(({ name, versions }) => {\n      if (!versions.length) {\n        return BbPromise.resolve();\n      }\n\n      const deletionCandidates = this.selectPruneVersionsForLayer(versions);\n      if (deletionCandidates.length > 0) {\n        this.updateProgress('prune-plugin-prune-layers', `Pruning layer versions (${name})`);\n      }\n\n      if (this.options.dryRun) {\n        this.printPruningCandidates(name, deletionCandidates);\n        return BbPromise.resolve();\n      } else {\n        return this.deleteVersionsForLayer(name, deletionCandidates);\n      }\n    }).then(() => {\n      this.clearProgress('prune-plugin-prune-layers');\n      this.logSuccess('Pruning of layers complete');\n    });\n  }\n\n  pruneFunctions() {\n    const selectedFunctions = this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions();\n    const functionNames = selectedFunctions.map(key => this.serverless.service.getFunction(key).name);\n\n    this.createProgress(\n      'prune-plugin-prune-functions',\n      'Pruning function versions'\n    );\n\n    return BbPromise.mapSeries(functionNames, functionName => {\n\n      return BbPromise.join(\n        this.listVersionForFunction(functionName),\n        this.listAliasesForFunction(functionName),\n        (versions, aliases) => ( { name: functionName, versions: versions, aliases: aliases } )\n      );\n\n    }).each(({ name, versions, aliases }) => {\n      if (!versions.length) {\n        return BbPromise.resolve();\n      }\n\n      const deletionCandidates = this.selectPruneVersionsForFunction(versions, aliases);\n      if (deletionCandidates.length > 0) {\n        this.updateProgress('prune-plugin-prune-functions', `Pruning function versions (${name})`);\n      }\n\n      if (this.options.dryRun) {\n        this.printPruningCandidates(name, deletionCandidates);\n        return BbPromise.resolve();\n      } else {\n        return this.deleteVersionsForFunction(name, deletionCandidates);\n      }\n    }).then(() => {\n      this.clearProgress('prune-plugin-prune-functions');\n      this.logSuccess('Pruning of functions complete');\n    });\n  }\n\n  deleteVersionsForLayer(layerName, versions) {\n    return BbPromise.each(versions, version => {\n      this.logInfo(`Deleting layer version ${layerName}:${version}.`);\n\n      const params = {\n        LayerName: layerName,\n        VersionNumber: version\n      };\n\n      return BbPromise.resolve()\n        .then(() => this.provider.request('Lambda', 'deleteLayerVersion', params))\n        .catch(e => {\n          throw e;\n        });\n    });\n  }\n\n  deleteVersionsForFunction(functionName, versions) {\n    return BbPromise.each(versions, version => {\n      this.logInfo(`Deleting function version ${functionName}:${version}.`);\n\n      const params = {\n        FunctionName: functionName,\n        Qualifier: version\n      };\n\n      return BbPromise.resolve()\n        .then(() => this.provider.request('Lambda', 'deleteFunction', params))\n        .catch(e => {\n          //ignore if trying to delete replicated lambda edge function\n          if (e.providerError && e.providerError.statusCode === 400\n            && e.providerError.message.startsWith('Lambda was unable to delete')\n            && e.providerError.message.indexOf('because it is a replicated function.') > -1) {\n            this.logWarning(`Unable to delete replicated Lambda@Edge function version ${functionName}:${version}.`);\n          } else {\n            throw e;\n          }\n        });\n    });\n  }\n\n  listAliasesForFunction(functionName) {\n    const params = {\n      FunctionName: functionName\n    };\n\n    return this.makeLambdaRequest('listAliases', params, r => r.Aliases)\n      .catch(e => {\n        //ignore if function not deployed\n        if (e.providerError && e.providerError.statusCode === 404) return [];\n        else throw e;\n      });\n  }\n\n  listVersionForFunction(functionName) {\n    const params = {\n      FunctionName: functionName\n    };\n\n    return this.makeLambdaRequest('listVersionsByFunction', params, r => r.Versions)\n      .catch(e => {\n        //ignore if function not deployed\n        if (e.providerError && e.providerError.statusCode === 404) return [];\n        else throw e;\n      });\n  }\n\n  listVersionsForLayer(layerName) {\n    const params = {\n      LayerName: layerName\n    };\n\n    return this.makeLambdaRequest('listLayerVersions', params, r => r.LayerVersions)\n      .catch(e => {\n        // ignore if layer not deployed\n        if (e.providerError && e.providerError.statusCode === 404) return [];\n        else throw e;\n      });\n\n  }\n\n  makeLambdaRequest(action, params, responseMapping) {\n    const results = [];\n    const responseHandler = response => {\n      Array.prototype.push.apply(results, responseMapping(response));\n\n      if (response.NextMarker) {\n        return this.provider.request('Lambda', action, Object.assign({}, params, { Marker: response.NextMarker }))\n          .then(responseHandler);\n      } else {\n        return BbPromise.resolve(results);\n      }\n    };\n\n    return this.provider.request('Lambda', action, params)\n      .then(responseHandler);\n  }\n\n  selectPruneVersionsForFunction(versions, aliases) {\n    const aliasedVersion = aliases.map(a => a.FunctionVersion);\n\n    return versions\n      .map(f => f.Version)\n      .filter(v => v !== '$LATEST') //skip $LATEST\n      .filter(v => aliasedVersion.indexOf(v) === -1) //skip aliased versions\n      .sort((a, b) => parseInt(a) === parseInt(b) ? 0 : parseInt(a) > parseInt(b) ? -1 : 1)\n      .slice(this.getNumber());\n  }\n\n  selectPruneVersionsForLayer(versions) {\n    return versions\n      .map(f => f.Version)\n      .sort((a, b) => parseInt(a) === parseInt(b) ? 0 : parseInt(a) > parseInt(b) ? -1 : 1)\n      .slice(this.getNumber());\n  }\n\n  printPruningCandidates(name, deletionCandidates) {\n    deletionCandidates.forEach(version => this.logInfo(`${name}:${version} selected for deletion.`));\n  }\n\n  // -- Compatibility with both Framework 2.x and 3.x logging ---\n\n  logInfo(message) {\n    if (this.log.info) this.log.info(message);\n    else this.log(`Prune: ${message}`);\n  }\n\n  logNotice(message) {\n    if (this.log.notice) this.log.notice(message);\n    else this.log(`Prune: ${message}`);\n  }\n\n  logWarning(message) {\n    if (this.log.warning) this.log.warning(message);\n    else this.log(`Prune: ${message}`);\n  }\n\n  logSuccess(message) {\n    if (this.log.success) this.log.success(message);\n    else this.log(`Prune: ${message}`);\n  }\n\n  createProgress(name, message) {\n    if (!this.progress) {\n      this.log(`Prune: ${message}...`);\n    } else {\n      this.progress.create({\n        message,\n        name\n      });\n    }\n  }\n\n  updateProgress(name, message) {\n    if (!this.progress) {\n      this.log(`Prune: ${message}`);\n    } else {\n      this.progress.get(name).update(message);\n    }\n  }\n\n  clearProgress(name) {\n    if (this.progress) {\n      this.progress.get(name).remove();\n    }\n  }\n}\n\nmodule.exports = Prune;\n"]}