diff --git a/.vscode/launch.json b/.vscode/launch.json index ec13965..bcff123 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,9 @@ "type": "node", "request": "attach", "name": "Attach", + "skipFiles": [ + "/**" + ], "port": 9229 }, { @@ -15,6 +18,9 @@ "request": "launch", "name": "Mocha All", "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "skipFiles": [ + "/**" + ], "args": [ "--timeout", "999999", @@ -29,6 +35,9 @@ "request": "launch", "name": "Mocha Current File", "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "skipFiles": [ + "/**" + ], "args": [ "--timeout", "999999", @@ -37,15 +46,6 @@ ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" - }, - { - "type": "node", - "request": "launch", - "name": "Launch 'hlx up'", - "program": "${workspaceFolder}/index.js", - "args":[ - "up" - ] } ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a202143..5ca6f66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,18 @@ "eslint-config-airbnb-base": "14.2.0" } }, + "@adobe/helix-fetch": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@adobe/helix-fetch/-/helix-fetch-1.7.0.tgz", + "integrity": "sha512-ybttqM9zLoJtSFjayOJRbaxxBoKTKcmiibnUS7U8wtjFh/VwLiwWgbdINFXTgvpdr5WDPpqpiHwM6zmufE3s4g==", + "requires": { + "fetch-h2": "^2.4.3", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.3", + "lru-cache": "^5.1.1", + "object-sizeof": "^1.5.3" + } + }, "@babel/code-frame": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", @@ -1113,6 +1125,11 @@ "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", "dev": true }, + "@types/tough-cookie": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.7.tgz", + "integrity": "sha512-rMQbgMGxnLsdn8e9aPVyuN+zMQLrZ2QW8xlv7eWS1mydfGXN+tsTKffcIzd8rGCcLdmi3xvQw2MDaZI1bBNTaw==" + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -1164,6 +1181,7 @@ "version": "6.12.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.2.tgz", "integrity": "sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==", + "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -1171,6 +1189,14 @@ "uri-js": "^4.2.2" } }, + "already": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/already/-/already-1.13.0.tgz", + "integrity": "sha512-SU1OQaWOUzRv8+udz9QyPTeh6XFYf/bbxA2T2fl3z0FLZlYaYOivVvxHo+xGB/1gfeXQb4wQTG571FMKoNFZVA==", + "requires": { + "throat": "^5.0.0" + } + }, "ansi-colors": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz", @@ -1353,19 +1379,6 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, - "asn1": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", - "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", - "requires": { - "safer-buffer": "~2.1.0" - } - }, - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - }, "assign-symbols": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", @@ -1384,11 +1397,6 @@ "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", "dev": true }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, "at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", @@ -1400,16 +1408,6 @@ "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", "dev": true }, - "aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" - }, - "aws4": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", - "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" - }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -1635,13 +1633,10 @@ } } }, - "bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", - "requires": { - "tweetnacl": "^0.14.3" - } + "base64-js": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" }, "before-after-hook": { "version": "2.1.0", @@ -1711,6 +1706,15 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, "cache-base": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz", @@ -1786,6 +1790,11 @@ "caller-callsite": "^2.0.0" } }, + "callguard": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/callguard/-/callguard-1.2.1.tgz", + "integrity": "sha512-QTxtuE+QrPA/ZStfYEf/IL1RqyOEpg3CMKp35oTs4n91WveYjbnbPJ0O2ob+RxhPzOuvb0KgQvYwJzhZ6nswXQ==" + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -1819,11 +1828,6 @@ "redeyed": "~2.1.0" } }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" - }, "catharsis": { "version": "0.8.11", "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.11.tgz", @@ -2145,14 +2149,6 @@ "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=", "dev": true }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "~1.0.0" - } - }, "command-line-args": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.1.1.tgz", @@ -2602,14 +2598,6 @@ "word-wrap": "^1.0.3" } }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "requires": { - "assert-plus": "^1.0.0" - } - }, "date-format": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/date-format/-/date-format-0.0.2.tgz", @@ -2748,11 +2736,6 @@ } } }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, "deprecation": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", @@ -2850,15 +2833,6 @@ "readable-stream": "^2.0.2" } }, - "ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", - "requires": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" - } - }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", @@ -3603,11 +3577,6 @@ "homedir-polyfill": "^1.0.1" } }, - "extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" - }, "extend-shallow": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", @@ -3705,15 +3674,11 @@ } } }, - "extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" - }, "fast-deep-equal": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", - "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", + "dev": true }, "fast-glob": { "version": "3.2.2", @@ -3783,7 +3748,8 @@ "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "fast-levenshtein": { "version": "2.0.6", @@ -3800,6 +3766,32 @@ "reusify": "^1.0.4" } }, + "fetch-h2": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/fetch-h2/-/fetch-h2-2.4.5.tgz", + "integrity": "sha512-Nl6wvKqwHPBKlGbXQsnA55EgzI62p/pTb5ISrfxJEAb7ShwcrITEQHAVHKiuf9Z3ulMd64fkildG/bQB4J3qzw==", + "requires": { + "@types/tough-cookie": "^2.3.6", + "already": "^1.12.0", + "callguard": "^1.2.1", + "get-stream": "^5.1.0", + "through2": "^3.0.1", + "to-arraybuffer": "^1.0.1", + "tough-cookie": "^3.0.1" + }, + "dependencies": { + "tough-cookie": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz", + "integrity": "sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==", + "requires": { + "ip-regex": "^2.1.0", + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + } + } + }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", @@ -4115,21 +4107,6 @@ } } }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" - }, - "form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - } - }, "fragment-cache": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", @@ -4240,14 +4217,6 @@ "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=", "dev": true }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "requires": { - "assert-plus": "^1.0.0" - } - }, "git-log-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/git-log-parser/-/git-log-parser-1.2.0.tgz", @@ -4394,20 +4363,6 @@ } } }, - "har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" - }, - "har-validator": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", - "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", - "requires": { - "ajv": "^6.5.5", - "har-schema": "^2.0.0" - } - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -4535,6 +4490,11 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "http-cache-semantics": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", + "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + }, "http-proxy-agent": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", @@ -4546,16 +4506,6 @@ "debug": "4" } }, - "http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "requires": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" - } - }, "https-proxy-agent": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", @@ -4581,6 +4531,11 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "ieee754": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + }, "ignore": { "version": "5.1.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.6.tgz", @@ -4679,6 +4634,11 @@ "loose-envify": "^1.0.0" } }, + "ip-regex": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", + "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=" + }, "is-accessor-descriptor": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz", @@ -4935,7 +4895,8 @@ "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", + "dev": true }, "is-utf8": { "version": "0.2.1", @@ -4966,11 +4927,6 @@ "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "issue-parser": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/issue-parser/-/issue-parser-6.0.0.tgz", @@ -5257,11 +5213,6 @@ "xmlcreate": "^2.0.3" } }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" - }, "jsdoc": { "version": "3.6.4", "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.4.tgz", @@ -5368,15 +5319,11 @@ "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "dev": true }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -5387,7 +5334,8 @@ "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", + "dev": true }, "json5": { "version": "2.1.3", @@ -5413,17 +5361,6 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, - "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.2.3", - "verror": "1.10.0" - } - }, "junit-report-builder": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/junit-report-builder/-/junit-report-builder-2.0.0.tgz", @@ -5847,7 +5784,8 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true }, "lodash.camelcase": { "version": "4.3.0", @@ -6140,7 +6078,6 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", - "dev": true, "requires": { "yallist": "^3.0.2" } @@ -6374,19 +6311,6 @@ "integrity": "sha512-3hQhEUF027BuxZjQA3s7rIv/7VCQPa27hN9u9g87sEkWaKwQPuXOkVKtOeiyUrnWqTDiOs8Ed2rwg733mB0R5w==", "dev": true }, - "mime-db": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", - "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" - }, - "mime-types": { - "version": "2.1.26", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", - "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", - "requires": { - "mime-db": "1.43.0" - } - }, "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", @@ -10680,11 +10604,6 @@ } } }, - "oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" - }, "object-copy": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", @@ -10734,6 +10653,14 @@ "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", "dev": true }, + "object-sizeof": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/object-sizeof/-/object-sizeof-1.6.1.tgz", + "integrity": "sha512-gNKGcRnDRXwEpAdwUY3Ef+aVZIrcQVXozSaVzHz6Pv4JxysH8vf5F+nIgsqW5T/YNwZNveh0mIW7PEH1O2MrDw==", + "requires": { + "buffer": "^5.6.0" + } + }, "object-to-spawn-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/object-to-spawn-args/-/object-to-spawn-args-2.0.0.tgz", @@ -11012,11 +10939,6 @@ "pify": "^3.0.0" } }, - "performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" - }, "picomatch": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.0.7.tgz", @@ -11133,11 +11055,6 @@ "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", "dev": true }, - "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" - }, "quick-lru": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-1.1.0.tgz", @@ -11368,51 +11285,6 @@ "is-finite": "^1.0.0" } }, - "request": { - "version": "2.88.2", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", - "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", - "requires": { - "aws-sign2": "~0.7.0", - "aws4": "^1.8.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.6", - "extend": "~3.0.2", - "forever-agent": "~0.6.1", - "form-data": "~2.3.2", - "har-validator": "~5.1.3", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", - "performance-now": "^2.1.0", - "qs": "~6.5.2", - "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", - "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" - } - }, - "request-promise-core": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.3.tgz", - "integrity": "sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==", - "requires": { - "lodash": "^4.17.15" - } - }, - "request-promise-native": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.8.tgz", - "integrity": "sha512-dapwLGqkHtwL5AEbfenuzjTYg35Jd6KPytsC2/TLkVMz8rm+tNt72MGUWT1RP/aYawMpN6HqbNGBQaRcBtjQMQ==", - "requires": { - "request-promise-core": "1.1.3", - "stealthy-require": "^1.1.1", - "tough-cookie": "^2.3.3" - } - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -11550,7 +11422,8 @@ "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true }, "semantic-release": { "version": "17.1.1", @@ -12221,22 +12094,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "sshpk": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", - "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", - "requires": { - "asn1": "~0.2.3", - "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", - "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", - "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" - } - }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -12258,11 +12115,6 @@ } } }, - "stealthy-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", - "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" - }, "stream-combiner2": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/stream-combiner2/-/stream-combiner2-1.1.1.tgz", @@ -12646,6 +12498,11 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "throat": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/throat/-/throat-5.0.0.tgz", + "integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==" + }, "through": { "version": "2.3.8", "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -12656,7 +12513,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/through2/-/through2-3.0.1.tgz", "integrity": "sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==", - "dev": true, "requires": { "readable-stream": "2 || 3" } @@ -12670,6 +12526,11 @@ "os-tmpdir": "~1.0.2" } }, + "to-arraybuffer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", + "integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=" + }, "to-fast-properties": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", @@ -12718,15 +12579,6 @@ "repeat-string": "^1.6.1" } }, - "tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "requires": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - } - }, "traverse": { "version": "0.6.6", "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", @@ -12779,19 +12631,6 @@ "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "^5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" - }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -12946,6 +12785,7 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, "requires": { "punycode": "^2.1.0" } @@ -12982,7 +12822,8 @@ "uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" + "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", + "dev": true }, "v8-compile-cache": { "version": "2.1.1", @@ -13000,16 +12841,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "requires": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" - } - }, "walk-back": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/walk-back/-/walk-back-4.0.0.tgz", @@ -13229,8 +13060,7 @@ "yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", - "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", - "dev": true + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" }, "yaml": { "version": "1.10.0", diff --git a/package.json b/package.json index b721348..377b576 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,11 @@ }, "homepage": "https://github.com/adobe/helix-ops#readme", "dependencies": { + "@adobe/helix-fetch": "^1.7.0", "diff": "4.0.2", "fs-extra": "9.0.1", "get-stream": "5.1.0", "git-log-parser": "1.2.0", - "request": "2.88.2", - "request-promise-native": "1.0.8", "shelljs": "0.8.4", "yargs": "15.3.1" }, diff --git a/src/newrelic/alerts.js b/src/newrelic/alerts.js index 6169e1c..36e21a8 100644 --- a/src/newrelic/alerts.js +++ b/src/newrelic/alerts.js @@ -10,9 +10,13 @@ * governing permissions and limitations under the License. */ -const request = require('request-promise-native'); +const fetchAPI = require('@adobe/helix-fetch'); const { getIncubatorName } = require('../utils'); +const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1 + ? fetchAPI.context({ httpsProtocols: ['http1'] }) + : fetchAPI; + const CHANNEL_TYPE = 'email'; const INCIDENT_PREFERENCE = 'PER_POLICY'; const CONDITION_NAME = 'Location Failure'; @@ -23,13 +27,16 @@ const CONDITION_THRESHOLD = 2; async function getChannelInfo(auth, channelName, email) { try { - const response = await request.get('https://api.newrelic.com/v2/alerts_channels.json', { + const resp = await fetch('https://api.newrelic.com/v2/alerts_channels.json', { headers: { 'X-Api-Key': auth, }, - json: true, }); - const allChannels = response.channels || []; + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + const allChannels = body.channels || []; const channel = allChannels.find((c) => c.type === CHANNEL_TYPE && c.name === channelName && c.configuration.recipients === email); return { @@ -47,11 +54,16 @@ async function purgeIncubatorChannel(auth, name, allPolicies) { if (incubatorPolicy) { console.log('Removing incubator notification channel', incubatorPolicy.name); try { - await request.delete(`https://api.newrelic.com/v2/alerts_channels/${incubatorPolicy.id}.json`, { + const resp = await fetch(`https://api.newrelic.com/v2/alerts_channels/${incubatorPolicy.id}.json`, { + method: 'DELETE', headers: { 'X-Api-Key': auth, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to remove incubator notification channel', e.message); } @@ -70,12 +82,12 @@ async function reuseOrCreateChannel(auth, name, email, incubator) { console.log('Creating notification channel', channelName); try { - const response = await request.post('https://api.newrelic.com/v2/alerts_channels.json', { - json: true, + const resp = await fetch('https://api.newrelic.com/v2/alerts_channels.json', { + method: 'POST', headers: { 'X-Api-Key': auth, }, - body: { + json: { channel: { name: channelName, type: CHANNEL_TYPE, @@ -86,7 +98,11 @@ async function reuseOrCreateChannel(auth, name, email, incubator) { }, }, }); - [channel] = response.channels; + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + [channel] = body.channels || []; if (!incubator) { // delete same name incubator channel @@ -103,13 +119,16 @@ async function reuseOrCreateChannel(auth, name, email, incubator) { async function getConditions(auth, policy) { if (!policy || !policy.id) return []; try { - const response = await request.get(`https://api.newrelic.com/v2/alerts_location_failure_conditions/policies/${policy.id}.json`, { - json: true, + const resp = await fetch(`https://api.newrelic.com/v2/alerts_location_failure_conditions/policies/${policy.id}.json`, { headers: { 'X-Api-Key': auth, }, }); - const conds = response.location_failure_conditions; + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + const conds = body.location_failure_conditions || []; return conds.filter((condition) => condition.name === CONDITION_NAME); } catch (e) { console.error('Unable to retrieve conditions:', e.message); @@ -121,12 +140,12 @@ async function createCondition(auth, policy, monitorId) { if (!policy || !policy.id) return; console.log('Creating condition in alert policy'); try { - await request.post(`https://api.newrelic.com/v2/alerts_location_failure_conditions/policies/${policy.id}.json`, { - json: true, + const resp = await fetch(`https://api.newrelic.com/v2/alerts_location_failure_conditions/policies/${policy.id}.json`, { + method: 'POST', headers: { 'X-Api-Key': auth, }, - body: { + json: { location_failure_condition: { name: CONDITION_NAME, enabled: true, @@ -140,6 +159,10 @@ async function createCondition(auth, policy, monitorId) { }, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to add alert policy condition:', e.message); } @@ -152,15 +175,19 @@ async function updateCondition(auth, condition, monitorId) { } else { console.log('Updating alert policy condition'); condition.entities.push(monitorId); - await request.put(`https://api.newrelic.com/v2/alerts_location_failure_conditions/${condition.id}.json`, { - json: true, + const resp = await fetch(`https://api.newrelic.com/v2/alerts_location_failure_conditions/${condition.id}.json`, { + method: 'PUT', headers: { 'X-Api-Key': auth, }, - body: { + json: { location_failure_condition: condition, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } } catch (e) { console.error('Unable to update alert policy condition', e.message); @@ -169,15 +196,17 @@ async function updateCondition(auth, condition, monitorId) { async function getPolicyInfo(auth, policyName) { try { - const response = await request.get('https://api.newrelic.com/v2/alerts_policies.json', { + const resp = await fetch('https://api.newrelic.com/v2/alerts_policies.json', { headers: { 'X-Api-Key': auth, }, - json: true, }); - - const allPolicies = response.policies - ? response.policies.map(({ id, name }) => ({ id, name })) + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + const allPolicies = body.policies + ? body.policies.map(({ id, name }) => ({ id, name })) : []; return { policy: policyName ? allPolicies.find((pol) => pol.name === policyName) : null, @@ -192,19 +221,23 @@ async function getPolicyInfo(auth, policyName) { async function createPolicy(auth, name) { console.log('Creating alert policy', name); try { - const response = await request.post('https://api.newrelic.com/v2/alerts_policies.json', { - json: true, + const resp = await fetch('https://api.newrelic.com/v2/alerts_policies.json', { + method: 'POST', headers: { 'X-Api-Key': auth, }, - body: { + json: { policy: { name, incident_preference: INCIDENT_PREFERENCE, }, }, }); - return response.policy; + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + return body.policy; } catch (e) { console.error('Alert policy creation failed:', e.message); process.exit(1); @@ -217,15 +250,21 @@ async function updatePolicy(auth, policy, groupPolicy, monitorId, channelId, pol // add notification channel console.log('Linking notification channel to alert policy', policy.name); try { - await request.put('https://api.newrelic.com/v2/alerts_policy_channels.json', { + const resp = await fetch('https://api.newrelic.com/v2/alerts_policy_channels.json', { + method: 'PUT', headers: { 'X-Api-Key': auth, + 'Content-Type': 'application/x-www-form-urlencoded', }, - form: { + body: new URLSearchParams({ channel_ids: channelId, policy_id: policy.id, - }, + }).toString(), }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to add notification channel to alert policy', e.message); } @@ -264,11 +303,16 @@ async function purgeIncubatorPolicy(auth, name, allPolicies) { if (incubatorPolicy) { console.log('Removing incubator alert policy', incubatorPolicy.name); try { - await request.delete(`https://api.newrelic.com/v2/alerts_policies/${incubatorPolicy.id}.json`, { + const resp = await fetch(`https://api.newrelic.com/v2/alerts_policies/${incubatorPolicy.id}.json`, { + method: 'DELETE', headers: { 'X-Api-Key': auth, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to remove incubator alert policy', e.message); } diff --git a/src/newrelic/synthetics.js b/src/newrelic/synthetics.js index 1d776b0..0f258a6 100644 --- a/src/newrelic/synthetics.js +++ b/src/newrelic/synthetics.js @@ -10,10 +10,14 @@ * governing permissions and limitations under the License. */ -const request = require('request-promise-native'); +const fetchAPI = require('@adobe/helix-fetch'); const fs = require('fs'); const path = require('path'); +const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1 + ? fetchAPI.context({ httpsProtocols: ['http1'] }) + : fetchAPI; + const MONITOR_FREQUENCY = 15; const MONITOR_STATUS = 'ENABLED'; const MONITOR_THRESHOLD = 7; @@ -53,17 +57,21 @@ async function getMonitors(auth, monitorname) { let more = true; const loadedmonitors = []; while (more) { - // eslint-disable-next-line no-await-in-loop - const response = await request.get(`https://synthetics.newrelic.com/synthetics/api/v3/monitors?limit=100&offset=${loadedmonitors.length}`, { + /* eslint-disable no-await-in-loop */ + const resp = await fetch(`https://synthetics.newrelic.com/synthetics/api/v3/monitors?limit=100&offset=${loadedmonitors.length}`, { headers: { 'X-Api-Key': auth, }, - json: true, }); - if (response.count < 10) { + if (!resp.ok) { + throw new Error(await resp.text()); + } + const body = await resp.json(); + if (body.count < 10) { more = false; } - loadedmonitors.push(...response.monitors); + loadedmonitors.push(...body.monitors); + /* eslint-enable no-await-in-loop */ } const monitors = loadedmonitors.map(({ id, name }) => ({ id, name })); @@ -81,16 +89,20 @@ async function getMonitors(auth, monitorname) { async function updateMonitor(auth, monitor, url, script, locations, frequency) { console.log('Updating locations and frequency for monitor', monitor.name); try { - await request.patch(`https://synthetics.newrelic.com/synthetics/api/v3/monitors/${monitor.id}`, { - json: true, + const resp = await fetch(`https://synthetics.newrelic.com/synthetics/api/v3/monitors/${monitor.id}`, { + method: 'PATCH', headers: { 'X-Api-Key': auth, }, - body: { + json: { locations, frequency, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to update locations and frequency for monitor:', e.message); } @@ -104,15 +116,19 @@ async function updateMonitor(auth, monitor, url, script, locations, frequency) { .replace('$$$NS$$$', getNS(url))) .toString('base64'); try { - await request.put(`https://synthetics.newrelic.com/synthetics/api/v3/monitors/${monitor.id}/script`, { - json: true, + const resp = await fetch(`https://synthetics.newrelic.com/synthetics/api/v3/monitors/${monitor.id}/script`, { + method: 'PUT', headers: { 'X-Api-Key': auth, }, - body: { + json: { scriptText, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { console.error('Unable to update script for monitor:', e.message); } @@ -130,12 +146,12 @@ async function updateOrCreateMonitor(auth, name, url, script, monType, monLoc, m // create console.log('Creating monitor', name); try { - await request.post('https://synthetics.newrelic.com/synthetics/api/v3/monitors', { - json: true, + const resp = await fetch('https://synthetics.newrelic.com/synthetics/api/v3/monitors', { + method: 'POST', headers: { 'X-Api-Key': auth, }, - body: { + json: { name, type, frequency, @@ -144,6 +160,10 @@ async function updateOrCreateMonitor(auth, name, url, script, monType, monLoc, m slaThreshold: MONITOR_THRESHOLD, }, }); + const body = await resp.text(); + if (!resp.ok) { + throw new Error(body); + } return await updateOrCreateMonitor(auth, name, url, script, monType, monLoc, monFreq); } catch (e) { console.error('Monitor creation failed:', e.message); diff --git a/src/statuspage/cli.js b/src/statuspage/cli.js index c9ca3f9..47f4d90 100644 --- a/src/statuspage/cli.js +++ b/src/statuspage/cli.js @@ -12,9 +12,13 @@ const yargs = require('yargs'); const fs = require('fs'); -const request = require('request-promise-native'); +const fetchAPI = require('@adobe/helix-fetch'); const { getIncubatorName } = require('../utils'); +const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1 + ? fetchAPI.context({ httpsProtocols: ['http1'] }) + : fetchAPI; + function getIncubatorPageId(pageId, incubatorPageId) { return incubatorPageId || pageId; } @@ -62,13 +66,15 @@ class CLI { async function getComponentInfo(auth, pageid, group, name) { try { const result = {}; - result.allComps = await request.get(`https://api.statuspage.io/v1/pages/${pageid}/components`, { + const resp = await fetch(`https://api.statuspage.io/v1/pages/${pageid}/components`, { headers: { Authorization: auth, }, - json: true, }); - + if (!resp.ok) { + throw new Error(await resp.text()); + } + result.allComps = await resp.json(); result.component = result.allComps.find((comp) => comp.name === name); if (group) { @@ -98,15 +104,16 @@ class CLI { } logger.log(msg); try { - return await request.post(`https://api.statuspage.io/v1/pages/${pageid}/components`, { - json: true, + const resp = await fetch(`https://api.statuspage.io/v1/pages/${pageid}/components`, { + method: 'POST', headers: { Authorization: auth, }, - body: { + json: { component, }, }); + return await resp.json(); } catch (e) { logger.error('Component creation failed:', e.message); process.exit(1); @@ -125,15 +132,19 @@ class CLI { if (Object.keys(component).length > 0) { logger.log('Updating component', comp.name); try { - return await request.patch(`https://api.statuspage.io/v1/pages/${pageid}/components/${comp.id}`, { - json: true, + const resp = await fetch(`https://api.statuspage.io/v1/pages/${pageid}/components/${comp.id}`, { + method: 'PATCH', headers: { Authorization: auth, }, - body: { + json: { component, }, }); + if (!resp.ok) { + throw new Error(await resp.text()); + } + return await resp.json(); } catch (e) { logger.error('Component update failed:', e.message); } @@ -154,12 +165,17 @@ class CLI { if (component) { logger.log('Deleting incubator component', component.name); try { - await request.delete(`https://api.statuspage.io/v1/pages/${ipageid || pageid}/components/${component.id}`, { + const resp = await fetch(`https://api.statuspage.io/v1/pages/${ipageid || pageid}/components/${component.id}`, { json: true, + method: 'DELETE', headers: { Authorization: auth, }, }); + const body = await resp.json(); + if (!resp.ok) { + throw new Error(body); + } } catch (e) { logger.error('Unable to delete incubator component:', e.message); } diff --git a/test/newrelic/NewRelicAPI.js b/test/newrelic/NewRelicAPI.js index 644a81e..d5bb707 100644 --- a/test/newrelic/NewRelicAPI.js +++ b/test/newrelic/NewRelicAPI.js @@ -215,7 +215,7 @@ class NewRelicAPI extends AbstractAPI { const ctx = this; return (uri, req) => { ctx.emit(NewRelicAPI.UPDATE_POLICY, uri, req); - return ctx.reply(uri, req, ''); + return ctx.reply(''); }; } @@ -285,7 +285,7 @@ class NewRelicAPI extends AbstractAPI { const ctx = this; return (uri, req) => { ctx.emit(NewRelicAPI.UPDATE_CONDITION, uri, req); - return ctx.reply(uri, req, ''); + return ctx.reply(''); }; } diff --git a/test/testNewrelic.js b/test/testNewrelic.js index d991909..03e4066 100644 --- a/test/testNewrelic.js +++ b/test/testNewrelic.js @@ -18,6 +18,8 @@ const sinon = require('sinon'); const fs = require('fs'); const path = require('path'); +process.env.HELIX_FETCH_FORCE_HTTP1 = 'true'; + const NewRelic = require('../src/newrelic/cli'); const { MONITOR_FREQUENCY, @@ -326,7 +328,7 @@ describe('Testing newrelic', () => { })); assert.ok(await getTimedPromise(() => ok, 'Monitor not added to group alert policy')); api.stop(); - }); + }).timeout(5000); it('creates new monitor with custom script', async () => { let ok = false; @@ -344,7 +346,7 @@ describe('Testing newrelic', () => { })); assert.ok(await getTimedPromise(() => ok, 'Custom monitor script not used')); api.stop(); - }); + }).timeout(5000); it('updates existing monitor with custom script', async () => { let ok = false; @@ -395,7 +397,7 @@ describe('Testing newrelic', () => { getTimedPromise(() => test.ok2, 'Custom monitor script not used'), ])); api.stop(); - }); + }).timeout(5000); it('creates new monitor with custom locations and frequency', async () => { let ok = false; @@ -410,7 +412,7 @@ describe('Testing newrelic', () => { await run(cliConfig({ locations, frequency })); assert.ok(await getTimedPromise(() => ok, 'Custom locations or frequency not used')); api.stop(); - }); + }).timeout(5000); it('updates an existing monitor with custom locations and frequency', async () => { let ok = false; @@ -425,7 +427,7 @@ describe('Testing newrelic', () => { await run(cliConfig({ locations, frequency })); assert.ok(await getTimedPromise(() => ok, 'Custom locations or frequency not used')); api.stop(); - }); + }).timeout(5000); it('creates a new incubator monitoring setup', async () => { const incubatorChannel = { diff --git a/test/testStatuspage.js b/test/testStatuspage.js index 941011e..4176d98 100644 --- a/test/testStatuspage.js +++ b/test/testStatuspage.js @@ -16,6 +16,8 @@ const assert = require('assert'); const shell = require('shelljs'); const sinon = require('sinon'); +process.env.HELIX_FETCH_FORCE_HTTP1 = 'true'; + const Statuspage = require('../src/statuspage/cli'); const StatuspageAPI = require('./statuspage/StatuspageAPI'); const { getTimedPromise } = require('./utils'); diff --git a/test/utils.js b/test/utils.js index 3b26228..0629826 100644 --- a/test/utils.js +++ b/test/utils.js @@ -20,7 +20,7 @@ function getTimedPromise(fn, err, time) { } else { reject(new Error(err)); } - }, time || 1000); + }, time || 1500); }); }