{"version":3,"sources":["jsdelivr-header.js","/npm/github-deployment@0.0.2/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,OAAO,QAAU,iBAEjB,MAAM,KAAO,QAAQ,UAAU,WACzB,gBAAkB,0BAClB,YAAc,QAAQ,gBAU5B,SAAS,iBAAiB,GACtB,KAAK,OAAS,EAAS,OACvB,KAAK,KAAO,EAAS,KACrB,KAAK,OAAS,EAAS,MAC3B,CAMA,iBAAiB,UAAU,KAAO,WAC9B,OAAO,KAAK,UAAU,CAClB,OAAQ,KAAK,OACb,KAAM,KAAK,KACX,OAAQ,KAAK,QAErB,EASA,iBAAiB,YAAc,SAAS,EAAa,EAAW,GAC5D,IAAI,EACA,MAAM,IAAI,MAAM,mCAGpB,MAAM,EAAO,KAAK,MAAM,GAExB,IAAI,GAAwB,iBAAT,EACf,MAAM,IAAI,MAAM,mCAGpB,GAAI,EAEG,CACH,MAAM,EAAO,QAAU,KAAK,OAAQ,GAAQ,OAAO,GAAe,IAAI,OAAO,OAC7E,IAAI,YAAY,EAAM,GAElB,MADA,QAAQ,IAAI,YAAc,EAAY,UAAY,GAC5C,IAAI,MAAM,iBAExB,MAPI,QAAQ,IAAI,4EAShB,IAAI,EAAW,CACX,SAAU,EAAK,KAAO,IAAI,MAAM,kBAAoB,IAAI,GACxD,KAAO,EAAK,YAAc,EAAK,WAAW,UAAY,EAAK,WAAW,eAAY,EAClF,OAAQ,EAAK,OAGjB,IAAI,EAAS,SAAW,EAAS,OAAS,EAAS,QAAqC,iBAApB,EAAS,QAAgD,iBAAlB,EAAS,MAAgD,iBAApB,EAAS,OAErJ,MADA,QAAQ,IAAI,6BAA8B,GACpC,IAAI,MAAM,+CAGpB,OAAO,IAAI,iBAAiB,EAChC","file":"/npm/github-deployment@0.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/github-deployment@0.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\";\r\n\r\nmodule.exports = GitHubDeployment;\r\n\r\nconst hmac = require('crypto').createHmac;\r\nconst BRANCH_FROM_REF = /^refs\\/heads\\/([^\\/]+)$/;\r\nconst safeCompare = require('safe-compare');\r\n\r\n/**\r\n * Verify a GitHub webhook and return a new GitHubDeployment instance.\r\n * @class\r\n * @param {Object} settings - This must be information on the GitHub deployment you're interested in.\r\n * @param {string} settings.branch - This must be the GitHub branch you're interested in.\r\n * @param {string} settings.repo - This must be the GitHub repository you're interested in.\r\n * @param {string} settings.commit - This must be the GitHub commit you're interested in.\r\n */\r\nfunction GitHubDeployment(settings){\r\n    this.branch = settings.branch;\r\n    this.repo = settings.repo;\r\n    this.commit = settings.commit;\r\n}\r\n\r\n/**\r\n * Get a JSON-serializable object that represents this GitHub deployment.\r\n * @returns {Object}\r\n */\r\nGitHubDeployment.prototype.json = function(){\r\n    return JSON.stringify({\r\n        branch: this.branch,\r\n        repo: this.repo,\r\n        commit: this.commit\r\n    });\r\n};\r\n\r\n/**\r\n * Verify a GitHub webhook and return a new GitHubDeployment instance.\r\n * @param {string} body_string - This must be the body of the webhook exactly as you received it.\r\n * @param {string} [signature] - This must be the complete signature GitHub passed in the returned headers (HTTP_X_HUB_SIGNATURE). Not required if you do not pass a secret.\r\n * @param {string} [secret] - Optional: This must be the secret you supplied when you created the webhook on GitHub.\r\n * @returns {GitHubDeployment}\r\n */\r\nGitHubDeployment.fromWebhook = function(body_string, signature, secret){\r\n    if(!body_string){\r\n        throw new Error('Missing or invalid webhook body');\r\n    }\r\n    \r\n    const body = JSON.parse(body_string);\r\n    \r\n    if(!body || typeof body !== 'object'){\r\n        throw new Error('Webhook body must be an object.');\r\n    }\r\n    \r\n    if(!secret){\r\n        console.log(\"WARNING: Cannot verity authenticity of webhook request without a secret.\");\r\n    } else {\r\n        const hash = 'sha1=' + hmac('sha1', secret).update(body_string || \"\").digest('hex');\r\n        if(!safeCompare(hash, signature)){\r\n            console.log(\"Expected \" + signature + \" to be \" + hash);\r\n            throw new Error('Bad signature.');\r\n        }\r\n    }\r\n    \r\n    var settings = {\r\n        branch: ((body.ref || '').match(BRANCH_FROM_REF) || [])[1],\r\n        repo: (body.repository && body.repository.full_name ? body.repository.full_name : undefined),\r\n        commit: body.after\r\n    };\r\n    \r\n    if(!settings.branch || !settings.repo || !settings.commit || typeof settings.branch !== 'string' || typeof settings.repo !== 'string' || typeof settings.commit !== 'string'){\r\n        console.log(\"GitHubDeployment settings:\", settings);\r\n        throw new Error('Could not get repository data from webhook.');\r\n    }\r\n    \r\n    return new GitHubDeployment(settings);\r\n};"]}