diff --git a/codegens/js-xhr/npm-shrinkwrap.json b/codegens/js-xhr/npm-shrinkwrap.json index 79d5e1865..730028dde 100644 --- a/codegens/js-xhr/npm-shrinkwrap.json +++ b/codegens/js-xhr/npm-shrinkwrap.json @@ -4,6 +4,53 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "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==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, + "form-data": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", + "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "mime-db": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", + "dev": true + }, + "mime-types": { + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "dev": true, + "requires": { + "mime-db": "1.44.0" + } + }, "xmlhttprequest": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", diff --git a/codegens/nodejs-native/npm-shrinkwrap.json b/codegens/nodejs-native/npm-shrinkwrap.json index e7b844e75..e3c959d43 100644 --- a/codegens/nodejs-native/npm-shrinkwrap.json +++ b/codegens/nodejs-native/npm-shrinkwrap.json @@ -4,11 +4,363 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=" + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "charset": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/charset/-/charset-1.0.1.tgz", + "integrity": "sha512-6dVyOOYjpfFcL1Y4qChrAoQLRHvj2ziyhcm0QJlhOcAhykL/k1kTUPbeo+87MNRTRdk2OIIsIXbuF3x2wi5EXg==" + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "dom-serializer": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", + "integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==", + "requires": { + "domelementtype": "^2.0.1", + "entities": "^2.0.0" + }, + "dependencies": { + "domelementtype": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.1.0.tgz", + "integrity": "sha512-LsTgx/L5VpD+Q8lmsXSHW2WpA+eBlZ9HPf3erD1IoPF00/3JKHZ3BknUVA2QGDNu69ZNmyFmCWBSO45XjYKC5w==" + }, + "entities": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", + "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==" + } + } + }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" + }, + "domhandler": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", + "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz", + "integrity": "sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==", + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "faker": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/faker/-/faker-5.1.0.tgz", + "integrity": "sha512-RrWKFSSA/aNLP0g3o2WW1Zez7/MnMr7xkiZmoCfAGZmdkDQZ6l2KtuXHN5XjdvpRjDl8+3vf+Rrtl06Z352+Mw==" + }, + "file-type": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" + }, "follow-redirects": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==", "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "htmlparser2": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", + "integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==", + "requires": { + "domelementtype": "^1.3.1", + "domhandler": "^2.3.0", + "domutils": "^1.5.1", + "entities": "^1.1.1", + "inherits": "^2.0.1", + "readable-stream": "^3.1.1" + } + }, + "http-reasons": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/http-reasons/-/http-reasons-0.1.0.tgz", + "integrity": "sha1-qVPKZwB4Zp3eFCzomUAbnW6F07Q=" + }, + "iconv-lite": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz", + "integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "liquid-json": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/liquid-json/-/liquid-json-0.3.1.tgz", + "integrity": "sha1-kVWhgTbYprJhXl8W+aJEira1Duo=" + }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" + }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, + "lodash.escaperegexp": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", + "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.mergewith": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", + "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==" + }, + "marked": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-1.2.0.tgz", + "integrity": "sha512-tiRxakgbNPBr301ihe/785NntvYyhxlqcL3YaC8CaxJQh7kiaEtrN9B/eK2I2943Yjkh5gw25chYFDQhOMCwMA==" + }, + "mime-db": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" + }, + "mime-format": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mime-format/-/mime-format-2.0.0.tgz", + "integrity": "sha1-4p+IkeKE14JwJG8AUNaDS9u+EzI=", + "requires": { + "charset": "^1.0.0" + } + }, + "mime-types": { + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "requires": { + "mime-db": "1.44.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "postcss": { + "version": "7.0.35", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.35.tgz", + "integrity": "sha512-3QT8bBJeX/S5zKTTjTCIjRF3If4avAT6kqxcASlTWEtAFCb9NH0OUxNDfgZSWdP5fJnBYCMEWkIFfWeugjzYMg==", + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + }, + "dependencies": { + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "postman-collection": { + "version": "3.6.8", + "resolved": "https://registry.npmjs.org/postman-collection/-/postman-collection-3.6.8.tgz", + "integrity": "sha512-TNPaK2dpVRhttUFo/WN0ReopXEtuSQMktwcvwJbQ0z8K+5hftvyx2ia40xgg9qFl/Ra78qoNTUmLL1s3lRqLMg==", + "requires": { + "escape-html": "1.0.3", + "faker": "5.1.0", + "file-type": "3.9.0", + "http-reasons": "0.1.0", + "iconv-lite": "0.6.2", + "liquid-json": "0.3.1", + "lodash": "4.17.20", + "marked": "1.2.0", + "mime-format": "2.0.0", + "mime-types": "2.1.27", + "postman-url-encoder": "3.0.0", + "sanitize-html": "1.20.1", + "semver": "7.3.2", + "uuid": "3.4.0" + } + }, + "postman-url-encoder": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postman-url-encoder/-/postman-url-encoder-3.0.0.tgz", + "integrity": "sha512-bk5wus5/5Ei9pbh+sQXaAxS5n4ZwiNAaIA8VBvRcXP6QyKcue2yF6xk1HqdtaZoH1G8+6509SVeOBojoFQ7nrA==", + "requires": { + "punycode": "^2.1.1" + } + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "sanitize-html": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-1.20.1.tgz", + "integrity": "sha512-txnH8TQjaQvg2Q0HY06G6CDJLVYCpbnxrdO0WN8gjCKaU5J0KbyGYhZxx5QJg3WLZ1lB7XU9kDkfrCXUozqptA==", + "requires": { + "chalk": "^2.4.1", + "htmlparser2": "^3.10.0", + "lodash.clonedeep": "^4.5.0", + "lodash.escaperegexp": "^4.1.2", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.mergewith": "^4.6.1", + "postcss": "^7.0.5", + "srcset": "^1.0.0", + "xtend": "^4.0.1" + } + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "srcset": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/srcset/-/srcset-1.0.0.tgz", + "integrity": "sha1-pWad4StC87HV6D7QPHEEb8SPQe8=", + "requires": { + "array-uniq": "^1.0.2", + "number-is-nan": "^1.0.0" + } + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + }, + "xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" } } } diff --git a/codegens/powershell-restmethod/npm-shrinkwrap.json b/codegens/powershell-restmethod/npm-shrinkwrap.json index eac67ebdb..72a079589 100644 --- a/codegens/powershell-restmethod/npm-shrinkwrap.json +++ b/codegens/powershell-restmethod/npm-shrinkwrap.json @@ -46,9 +46,9 @@ "dev": true }, "combined-stream": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", - "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dev": true, "requires": { "delayed-stream": "~1.0.0" @@ -67,13 +67,13 @@ "dev": true }, "form-data": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz", - "integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", "dev": true, "requires": { "asynckit": "^0.4.0", - "combined-stream": "1.0.6", + "combined-stream": "^1.0.6", "mime-types": "^2.1.12" } }, @@ -84,18 +84,18 @@ "dev": true }, "mime-db": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", - "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", "dev": true }, "mime-types": { - "version": "2.1.24", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", - "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", "dev": true, "requires": { - "mime-db": "1.40.0" + "mime-db": "1.44.0" } }, "nanoid": { diff --git a/codegens/qcobjects/.gitignore b/codegens/qcobjects/.gitignore new file mode 100644 index 000000000..2c7c686e6 --- /dev/null +++ b/codegens/qcobjects/.gitignore @@ -0,0 +1,41 @@ +.DS_Store +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Coverage directory used by tools like istanbul +.coverage + +# node-waf configuration +.lock-wscript + + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +out/ diff --git a/codegens/qcobjects/README.md b/codegens/qcobjects/README.md new file mode 100644 index 000000000..d40a6dbf4 --- /dev/null +++ b/codegens/qcobjects/README.md @@ -0,0 +1,42 @@ + +> Converts Postman-SDK Request into code snippet for [QCObjects](https://qcobjects.dev). + +#### Prerequisites +To run Code-Gen, ensure that you have NodeJS >= v8. A copy of the NodeJS installable can be downloaded from https://nodejs.org/en/download/package-manager. + +## Using the Module +The module will expose an object which will have property `convert` which is the function for converting the Postman-SDK request to swift code snippet. + +### convert function +Convert function takes three parameters + +* `request` - Postman-SDK Request Object + +* `options` - options is an object which hsa following properties + * `indentType` - String denoting type of indentation for code snippet. eg: 'Space', 'Tab' + * `indentCount` - The number of indentation characters to add per code level + * `trimRequestBody` - Whether or not request body fields should be trimmed + +* `callback` - callback function with first parameter as error and second parameter as string for code snippet + +##### Example: +```js +var request = new sdk.Request('www.google.com'), //using postman sdk to create request + options = { + indentCount: 3, + indentType: 'Space', + requestTimeout: 200, + trimRequestBody: true + }; +convert(request, options, function(error, snippet) { + if (error) { + // handle error + } + // handle snippet +}); +``` +### Guidelines for using generated snippet + +* Since Postman-SDK Request object doesn't provide complete path of the file, it needs to be manually inserted in case of uploading a file. + +* This module doesn't support cookies. diff --git a/codegens/qcobjects/index.js b/codegens/qcobjects/index.js new file mode 100644 index 000000000..bb0a047c4 --- /dev/null +++ b/codegens/qcobjects/index.js @@ -0,0 +1 @@ +module.exports = require('./lib'); diff --git a/codegens/qcobjects/lib/index.js b/codegens/qcobjects/lib/index.js new file mode 100644 index 000000000..339a79322 --- /dev/null +++ b/codegens/qcobjects/lib/index.js @@ -0,0 +1,4 @@ +module.exports = { + convert: require('./qcobjects').convert, + getOptions: require('./qcobjects').getOptions +}; diff --git a/codegens/qcobjects/lib/lodash.js b/codegens/qcobjects/lib/lodash.js new file mode 100644 index 000000000..f789d94f6 --- /dev/null +++ b/codegens/qcobjects/lib/lodash.js @@ -0,0 +1,456 @@ +/* istanbul ignore next */ +module.exports = { + + /** + * Checks if `value` is an empty object, array or string. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Values such as strings, arrays are considered empty if they have a `length` of `0`. + * + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * isEmpty(null) + * // => true + * + * isEmpty(true) + * // => true + * + * isEmpty(1) + * // => true + * + * isEmpty([1, 2, 3]) + * // => false + * + * isEmpty('abc') + * // => false + * + * isEmpty({ 'a': 1 }) + * // => false + */ + isEmpty: function (value) { + // eslint-disable-next-line lodash/prefer-is-nil + if (value === null || value === undefined) { + return true; + } + if (Array.isArray(value) || typeof value === 'string' || typeof value.splice === 'function') { + return !value.length; + } + + for (const key in value) { + if (Object.prototype.hasOwnProperty.call(value, key)) { + return false; + } + } + return true; + }, + + /** + * Checks if `value` is `undefined`. + * + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * isUndefined(void 0) + * // => true + * + * isUndefined(null) + * // => false + */ + isUndefined: function (value) { + return value === undefined; + }, + + /** + * Checks if `func` is classified as a `Function` object. + * + * @param {*} func The value to check. + * @returns {boolean} Returns `true` if `func` is a function, else `false`. + * @example + * + * isFunction(self.isEmpty) + * // => true + * + * isFunction(/abc/) + * // => false + */ + isFunction: function (func) { + return typeof func === 'function'; + }, + + /** + * Converts the first character of `string` to upper case and the remaining + * to lower case. + * + * @param {string} [string=''] The string to capitalize. + * @returns {string} Returns the capitalized string. + * @example + * + * capitalize('FRED') + * // => 'Fred' + * + * capitalize('john') + * // => 'John' + */ + + capitalize: function (string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); + }, + + /** + * Reduces `array` to a value which is the accumulated result of running + * each element in `array` thru `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not given, the first element of `array` is used as the initial + * value. The iteratee is invoked with four arguments: + * (accumulator, value, index|key, array). + * + * @param {Array} array The Array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @example + * + * reduce([1, 2], (sum, n) => sum + n, 0) + * // => 3 + * + */ + reduce: function (array, iteratee, accumulator) { + return array.reduce(iteratee, accumulator); + }, + + /** + * Iterates over elements of `array`, returning an array of all elements + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index, array). + * + * @param {Array} array The array to iterate over. + * @param {Function|object} predicate The function/object invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ] + * + * filter(users, ({ active }) => active) + * // => object for ['barney'] + */ + filter: function (array, predicate) { + if (typeof predicate === 'function') { + return array.filter(predicate); + } + var key = Object.keys(predicate), + val = predicate[key], + res = []; + array.forEach(function (item) { + if (item[key] && item[key] === val) { + res.push(item); + } + }); + return res; + }, + + /** + * The opposite of `filter` this method returns the elements of `array` + * that `predicate` does **not** return truthy for. + * + * @param {Array} array collection to iterate over. + * @param {String} predicate The String that needs to have truthy value, invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ] + * + * reject(users, 'active') + * // => object for ['fred'] + */ + reject: function (array, predicate) { + var res = []; + array.forEach((object) => { + if (!object[predicate]) { + res.push(object); + } + }); + return res; + }, + + /** + * Creates an array of values by running each element of `array` thru `iteratee`. + * The iteratee is invoked with three arguments: (value, index, array). + * + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + * @example + * + * function square(n) { + * return n * n + * } + * + * map([4, 8], square) + * // => [16, 64] + */ + map: function (array, iteratee) { + return array.map(iteratee); + }, + + /** + * Iterates over elements of `collection` and invokes `iteratee` for each element. + * The iteratee is invoked with three arguments: (value, index|key, collection). + * + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @example + * + * forEach([1, 2], value => console.log(value)) + * // => Logs `1` then `2`. + * + * forEach({ 'a': 1, 'b': 2 }, (value, key) => console.log(key)) + * // => Logs 'a' then 'b' + */ + + forEach: function (collection, iteratee) { + if (collection === null) { + return null; + } + + if (Array.isArray(collection)) { + return collection.forEach(iteratee); + } + const iterable = Object(collection), + props = Object.keys(collection); + var index = -1, + key, i; + + for (i = 0; i < props.length; i++) { + key = props[++index]; + iteratee(iterable[key], key, iterable); + } + return collection; + }, + + /** + * Checks if `value` is in `collection`. If `collection` is a string, it's + * checked for a substring of `value`, otherwise it checks if the `value` is present + * as a key in a `collection` object. + * + * @param {Array|Object|string} collection The collection to inspect. + * @param {*} value The value to search for. + * @returns {boolean} Returns `true` if `value` is found, else `false`. + * @example + * + * _.includes([1, 2, 3], 1); + * // => true + * + * _.includes({ 'a': 1, 'b': 2 }, 1); + * // => true + * + * _.includes('abcd', 'bc'); + * // => true + */ + includes: function (collection, value) { + if (Array.isArray(collection) || typeof collection === 'string') { + return collection.includes(value); + } + for (var key in collection) { + if (collection.hasOwnProperty(key)) { + if (collection[key] === value) { + return true; + } + } + } + return false; + }, + + /** + * Gets the size of `collection` by returning its length for array and strings. + * For objects it returns the number of enumerable string keyed + * properties. + * + * @param {Array|Object|string} collection The collection to inspect. + * @returns {number} Returns the collection size. + * @example + * + * size([1, 2, 3]) + * // => 3 + * + * size({ 'a': 1, 'b': 2 }) + * // => 2 + * + * size('pebbles') + * // => 7 + */ + size: function (collection) { + // eslint-disable-next-line lodash/prefer-is-nil + if (collection === null || collection === undefined) { + return 0; + } + if (Array.isArray(collection) || typeof collection === 'string') { + return collection.length; + } + + return Object.keys(collection).length; + }, + + /** + * Converts all elements in `array` into a string separated by `separator`. + * + * @param {Array} array The array to convert. + * @param {string} [separator=','] The element separator. + * @returns {string} Returns the joined string. + * @example + * + * _.join(['a', 'b', 'c'], '~'); + * // => 'a~b~c' + */ + join: function (array, separator) { + if (array === null) { + return ''; + } + return array.join(separator); + }, + + /** + * Removes trailing whitespace or specified characters from `string`. + * + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @returns {string} Returns the trimmed string. + * @example + * + * trimEnd(' abc ') + * // => ' abc' + * + * trimEnd('-_-abc-_-', '_-') + * // => '-_-abc' + */ + trimEnd: function (string, chars) { + if (!string) { + return ''; + } + if (string && !chars) { + return string.replace(/\s*$/, ''); + } + chars += '$'; + let regxp = `/${chars}/g`; + return string.replace(regxp, ''); + }, + + /** + * Returns the index of the first + * element `predicate` returns truthy for. + * + * @param {Array} array The array to inspect. + * @param {Object} predicate The exact object to be searched for in the array. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.findIndex(users, { 'user': 'fred', 'active': false }); + * // => 1 + * + * _.findIndex(users, {'active' : false}); + * // => 0 + * + */ + findIndex: function (array, predicate) { + var length = array === null ? 0 : array.length, + index = -1, + keys = Object.keys(predicate), + found, i; + if (!length) { + return -1; + } + for (i = 0; i < array.length; i++) { + found = true; + // eslint-disable-next-line no-loop-func + keys.forEach((key) => { + if (!(array[i][key] && array[i][key] === predicate[key])) { + found = false; + } + }); + if (found) { + index = i; + break; + } + } + return index; + }, + + /** + * Gets the value at `path` of `object`. If the resolved value is + * `undefined`, the `defaultValue` is returned in its place. + * + * @param {Object} object The object to query. + * @param {string} path The path of the property to get. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * const object = { a: {b : 'c'} } + * + * + * get(object, 'a.b.c', 'default') + * // => 'default' + * + * get(object, 'a.b', 'default') + * // => 'c' + */ + get: function (object, path, defaultValue) { + if (object === null) { + return undefined; + } + var arr = path.split('.'), + res = object, + i; + for (i = 0; i < arr.length; i++) { + res = res[arr[i]]; + if (res === undefined) { + return defaultValue; + } + } + return res; + }, + + /** + * Checks if `predicate` returns truthy for **all** elements of `array`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + * @example + * + * every([true, 1, null, 'yes'], Boolean) + * // => false + */ + every: function (array, predicate) { + var index = -1, + length = array === null ? 0 : array.length; + + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false; + } + } + return true; + } + +}; diff --git a/codegens/qcobjects/lib/parseRequest.js b/codegens/qcobjects/lib/parseRequest.js new file mode 100644 index 000000000..ea804e3c0 --- /dev/null +++ b/codegens/qcobjects/lib/parseRequest.js @@ -0,0 +1,245 @@ +/* eslint-env node, es6 */ +var _ = require('./lodash'), + + sanitize = require('./util').sanitize, + path = require('path'); + +/** + * parses body of request when type of the request body is formdata or urlencoded and + * returns code snippet for nodejs to add body + * + * @param {Array} dataArray - array containing body elements of request + * @param {String} indentString - string required for indentation + * @param {Boolean} trimBody - indicates whether to trim body or not + */ +function extractFormData (dataArray, indentString, trimBody) { + if (!dataArray) { + return ''; + } + var snippetString = _.reduce(dataArray, (accumalator, item) => { + if (item.disabled) { + return accumalator; + } + /* istanbul ignore next */ + if (item.type === 'file') { + /** + * creating snippet to send file in nodejs request + * for example: + * 'fieldname': { + * 'value': fs.createStream('filename.ext'), + * 'options': { + * 'filename': 'filename.ext', + * 'contentType: null + * } + * } + * } + */ + if (Array.isArray(item.src) && item.src.length) { + let fileSnippet = '', + fileArray = []; + _.forEach(item.src, (filePath) => { + fileArray.push(`${indentString.repeat(3)}fs.createReadStream('${sanitize(filePath, trimBody)}')`); + }); + if (fileArray.length) { + fileSnippet += `${indentString.repeat(2)}'${sanitize(item.key, trimBody)}': ` + + `[\n${fileArray.join(',\n')}\n${indentString.repeat(2)}]`; + accumalator.push(fileSnippet); + } + else { + return accumalator; + } + } + else if (typeof item.src !== 'string') { + accumalator.push([ + indentString.repeat(2) + `'${sanitize(item.key, trimBody)}': {`, + indentString.repeat(3) + '\'value\': fs.createReadStream(\'/path/to/file\'),', + indentString.repeat(3) + '\'options\': {', + indentString.repeat(4) + '\'filename\': \'filename\'', + indentString.repeat(4) + '\'contentType\': null', + indentString.repeat(3) + '}', + indentString.repeat(2) + '}' + ].join('\n')); + } + else { + var pathArray = item.src.split(path.sep), + fileName = pathArray[pathArray.length - 1]; + accumalator.push([ + indentString.repeat(2) + `'${sanitize(item.key, trimBody)}': {`, + indentString.repeat(3) + `'value': fs.createReadStream('${sanitize(item.src, trimBody)}'),`, + indentString.repeat(3) + '\'options\': {', + indentString.repeat(4) + `'filename': '${sanitize(fileName, trimBody)}',`, + indentString.repeat(4) + '\'contentType\': null', + indentString.repeat(3) + '}', + indentString.repeat(2) + '}' + ].join('\n')); + } + } + else { + accumalator.push( + indentString.repeat(2) + + `'${sanitize(item.key, trimBody)}': '${sanitize(item.value, trimBody)}'` + ); + } + return accumalator; + }, []); + return snippetString.join(',\n') + '\n'; +} + +/** + * Parses body object when requestbody.mode is raw + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBodyRaw (requestbody, indentString, trimBody, contentType) { + if (contentType === 'application/json') { + try { + let jsonBody = JSON.parse(requestbody[requestbody.mode]); + return `body: JSON.stringify(${JSON.stringify(jsonBody)})\n`; + } + catch (error) { + return `body: ${JSON.stringify(requestbody[requestbody.mode])}\n`; + } + } + return `body: ${JSON.stringify(requestbody[requestbody.mode])}\n`; +} + +/* eslint-disable no-unused-vars */ +/** + * Parses body object when requestbody.mode is graphql + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBodyGraphQL (requestbody, indentString, trimBody, contentType) { + let query = requestbody[requestbody.mode].query, + graphqlVariables; + try { + graphqlVariables = JSON.parse(requestbody[requestbody.mode].variables); + } + catch (e) { + graphqlVariables = {}; + } + return 'body: JSON.stringify({\n' + + `${indentString.repeat(2)}query: '${sanitize(query, trimBody)}',\n` + + `${indentString.repeat(2)}variables: ${JSON.stringify(graphqlVariables)}\n` + + `${indentString}})`; + +} + +/* eslint-disable no-unused-vars */ +/** + * Parses body object when requestbody.mode is formdata + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBodyFormdata (requestbody, indentString, trimBody, contentType) { + return `formData: {\n${extractFormData(requestbody[requestbody.mode], indentString, trimBody)}` + + indentString + '}'; +} + + +/* eslint-disable no-unused-vars */ +/** + * Parses body object when requestbody.mode is urlencoded + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBodyUrlEncoded (requestbody, indentString, trimBody, contentType) { + return `form: {\n${extractFormData(requestbody[requestbody.mode], indentString, trimBody)}` + + indentString + '}'; + +} + +/* eslint-disable no-unused-vars */ +/** + * Parses body object when requestbody.mode is file + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBodyFile (requestbody, indentString, trimBody, contentType) { + return 'body: ""\n'; +} + +/** + * Parses body object based on mode of body and returns code snippet + * + * @param {Object} requestbody - json object for body of request + * @param {String} indentString - string for indentation + * @param {Boolean} trimBody - indicates whether to trim body fields or not + * @param {String} contentType Content type of the body being sent + */ +function parseBody (requestbody, indentString, trimBody, contentType) { + if (requestbody) { + let parseBodyFunc = { + 'raw': parseBodyRaw, + 'graphql': parseBodyGraphQL, + 'formdata': parseBodyFormdata, + 'Formdata': parseBodyFormdata, + 'urlencoded': parseBodyUrlEncoded + }; + if (parseBodyFunc.hasOwnProperty(requestbody.mode)) { + return parseBodyFunc[requestbody.mode].call(null, requestbody, indentString, trimBody, contentType); + } + if (requestbody.mode === 'file') { + /* istanbul ignore next */ + parseFile(requestbody, indentString, trimBody, contentType); + } + + return ''; + } + return ''; +} + +/** + * parses header of request object and returns code snippet of nodejs request to add header + * + * @param {Object} request - Postman SDK request object + * @param {String} indentString - indentation required in code snippet + * @returns {String} - code snippet of nodejs request to add header + */ +function parseHeader (request, indentString) { + var headerObject = request.getHeaders({enabled: true}), + headerSnippet = indentString + '\'headers\': {\n'; + + if (!_.isEmpty(headerObject)) { + headerSnippet += _.reduce(Object.keys(headerObject), function (accumalator, key) { + if (Array.isArray(headerObject[key])) { + var headerValues = []; + _.forEach(headerObject[key], (value) => { + headerValues.push(`'${sanitize(value)}'`); + }); + accumalator.push( + indentString.repeat(2) + `'${sanitize(key, true)}': [${headerValues.join(', ')}]` + ); + } + else { + accumalator.push( + indentString.repeat(2) + `'${sanitize(key, true)}': '${sanitize(headerObject[key])}'` + ); + } + return accumalator; + }, []).join(',\n') + '\n'; + } + + headerSnippet += indentString + '}'; + return headerSnippet; +} + +module.exports = { + parseBody: parseBody, + parseHeader: parseHeader +}; diff --git a/codegens/qcobjects/lib/qcobjects.js b/codegens/qcobjects/lib/qcobjects.js new file mode 100644 index 000000000..880a7e127 --- /dev/null +++ b/codegens/qcobjects/lib/qcobjects.js @@ -0,0 +1,351 @@ +var _ = require('./lodash'), + sanitize = require('./util').sanitize, + sanitizeOptions = require('./util').sanitizeOptions, + getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject, + addFormParam = require('./util').addFormParam, + self; +global.URL = require('url').URL; + +/** + * Parses Raw data from request to fetch syntax + * + * @param {Object} body - Raw body data + * @param {String} mode - Request body type (i.e. raw, urlencoded, formdata, file) + * @param {boolean} trim - trim body option + * @returns {String} request body in the desired format + */ +function parseRawBody (body, mode, trim) { + if (_.isEmpty(body)) { + return ''; + } + var bodySnippet; + bodySnippet = `data:${sanitize(body, mode, trim)}`; + return bodySnippet; +} + +/** + * Parses graphql data from request to fetch syntax + * + * @param {Object} body - grqphql body data + * @param {String} mode - Request body type (i.e. raw, urlencoded, formdata, file) + * @param {boolean} trim - trim body option + * @returns {String} request body in the desired format + */ +function parseGraphQL (body, mode, trim) { + if (_.isEmpty(body)) { + return ''; + } + let query = body.query, + graphqlVariables, bodySnippet; + try { + graphqlVariables = JSON.parse(body.variables); + } + catch (e) { + graphqlVariables = {}; + } + bodySnippet = `data:${sanitize(JSON.stringify({ + query: query, + variables: graphqlVariables + }), mode, trim)}`; + return bodySnippet; +} + +/** + * Parses URLEncoded body from request to fetch syntax + * + * @param {Object} body - URLEncoded Body + * @param {String} mode - Request body type (i.e. raw, urlencoded, formdata, file) + * @param {boolean} trim - trim body option + * @returns {String} request body in the desired format + */ +function parseURLEncodedBody (body, mode, trim) { + if (_.isEmpty(body)) { + return ''; + } + var payload, bodySnippet; + payload = _.reduce(body, function (accumulator, data) { + if (!data.disabled) { + accumulator.push(`${sanitize(data.key, mode, trim)}=${sanitize(data.value, mode, trim)}`); + } + return accumulator; + }, []).join('&'); + + bodySnippet = `data:"${payload}"`; + return bodySnippet; +} + +/** + * Parses formData body from request to fetch syntax + * + * @param {Object} body - formData Body + * @param {String} mode - Request body type (i.e. raw, urlencoded, formdata, file) + * @param {boolean} trim - trim body option + * @param {String} indent - indentation string + * @returns {String} request body in the desired format + */ +function parseFormData (body, mode, trim, indent) { + var parameters = [], + parameter, + bodySnippet; + _.forEach(body, (data) => { + if (!(data.disabled)) { + parameter = ''; + parameter += `${indent}[\n${indent.repeat(2)}"key": "${sanitize(data.key, mode, trim)}",\n`; + if (data.type === 'file') { + parameter += `${indent.repeat(2)}"src": "${sanitize(data.src, mode, trim)}",\n`; + parameter += `${indent.repeat(2)}"type": "file"\n${indent}]`; + } + else { + parameter += `${indent.repeat(2)}"value": "${sanitize(data.value, mode, trim)}",\n`; + parameter += `${indent.repeat(2)}"type": "text"\n${indent}]`; + } + parameters.push(parameter); + } + }); + parameters = String('\n' + _.join(parameters, ',\n')); + parameters = parameters.replace(/^\s*$(?:\r\n?|\n)/gm, ''); + bodySnippet = `data:"${parameters}"`; + return bodySnippet; +} + +/* istanbul ignore next */ +/** + * Parses file body from the Request + * + * @returns {String} request body in the desired format + */ +function parseFile () { + var bodySnippet = '""'; + return bodySnippet; +} + +/** + * Parses Body from the Request using + * + * @param {Object} body - body object from request. + * @param {boolean} trim - trim body option + * @param {String} indent - indentation string + * @returns {String} utility function for getting request body in the desired format + */ +function parseBody (body, trim, indent) { + if (!_.isEmpty(body)) { + switch (body.mode) { + case 'urlencoded': + return parseURLEncodedBody(body.urlencoded, body.mode, trim); + case 'raw': + return parseRawBody(body.raw, body.mode, trim); + case 'graphql': + return parseGraphQL(body.graphql, 'raw', trim); + case 'formdata': + return parseFormData(body.formdata, body.mode, trim, indent); + /* istanbul ignore next */ + case 'file': + return parseFile(indent); + default: + return ''; + } + } + return ''; +} + +/** + * Parses headers from the request. + * + * @param {Object} headers - headers from the request. + * @param {String} mode - Request body type (i.e. raw, urlencoded, formdata, file) + * @returns {String} request headers in the desired format + */ +function parseHeaders (headers, mode) { + var headerSnippet = ''; + if (!_.isEmpty(headers)) { + headerSnippet = 'headers:{'; + headers = _.reject(headers, 'disabled'); + _.forEach(headers, function (header) { + headerSnippet += `"${sanitize(header.key, 'header', true).trim()}":`; + headerSnippet += `"${sanitize(header.value, 'header')}",\n`; + }); + + headerSnippet = headerSnippet.slice(0, -2) + '},'; + } + if (mode === 'formdata') { + // add Content-Type multipart/form-data + } + return headerSnippet; +} + +self = module.exports = { + /** + * Used in order to get additional options for generation of qcobjects code snippet + * + * @module getOptions + * + * @returns {Array} Additional options specific to generation of qcobjects-serviceLoader code snippet + */ + getOptions: function () { + return [{ + name: 'Set indentation count', + id: 'indentCount', + type: 'positiveInteger', + default: 4, + description: 'Set the number of indentation characters to add per code level' + }, + { + name: 'Set indentation type', + id: 'indentType', + type: 'enum', + availableOptions: ['Tab', 'Space'], + default: 'Space', + description: 'Select the character used to indent lines of code' + }, + { + name: 'Set request timeout', + id: 'requestTimeout', + type: 'positiveInteger', + default: 0, + description: 'Set number of milliseconds the request should wait for a response' + + ' before timing out (use 0 for infinity)' + }, + { + name: 'Trim request body fields', + id: 'trimRequestBody', + type: 'boolean', + default: false, + description: 'Remove white space and additional lines that may affect the server\'s response' + }, + { + name: 'Follow redirects', + id: 'followRedirect', + type: 'boolean', + default: true, + description: 'Automatically follow HTTP redirects' + } + ]; + }, + + /** + * Converts Postman sdk request object to qcobjects-serviceLoader code snippet + * + * @module convert + * + * @param {Object} request - Postman SDK-request object + * @param {Object} options - Options to tweak code snippet generated in qcobjects + * @param {String} options.indentType - type of indentation eg: Space / Tab (default: Space) + * @param {Number} options.indentCount - frequency of indent (default: 4 for indentType: Space, + default: 1 for indentType: Tab) + * @param {Number} options.requestTimeout - time in milli-seconds after which request will bail out + (default: 0 -> never bail out) + * @param {Boolean} options.trimRequestBody - whether to trim request body fields (default: false) + * @param {Boolean} options.followRedirect - whether to allow redirects of a request + * @param {Function} callback - Callback function with parameters (error, snippet) + * @returns {String} Generated swift snippet via callback + */ + convert: function (request, options, callback) { + + if (_.isFunction(options)) { + callback = options; + options = {}; + } + else if (!_.isFunction(callback)) { + throw new Error('qcobjects-Converter: callback is not valid function'); + } + options = sanitizeOptions(options, self.getOptions()); + var codeSnippet, indent, trim, finalUrl, // followRedirect,timeout + bodySnippet = '', + headerSnippet = '', + dataSnippet = '', + requestBody; + + indent = options.indentType === 'Tab' ? '\t' : ' '; + indent = indent.repeat(options.indentCount); + // timeout = options.requestTimeout; + // followRedirect = options.followRedirect; + trim = options.trimRequestBody; + finalUrl = getUrlStringfromUrlObject(request.url); + + // The following code handles multiple files in the same formdata param. + // It removes the form data params where the src property is an array of filepath strings + // Splits that array into different form data params with src set as a single filepath string + if (request.body && request.body.mode === 'formdata') { + let formdata = request.body.formdata, + formdataArray = []; + formdata.members.forEach((param) => { + let key = param.key, + type = param.type, + disabled = param.disabled, + contentType = param.contentType; + // check if type is file or text + if (type === 'file') { + // if src is not of type string we check for array(multiple files) + if (typeof param.src !== 'string') { + // if src is an array(not empty), iterate over it and add files as separate form fields + if (Array.isArray(param.src) && param.src.length) { + param.src.forEach((filePath) => { + addFormParam(formdataArray, key, param.type, filePath, disabled, contentType); + }); + } + // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case) + else { + addFormParam(formdataArray, key, param.type, '/path/to/file', disabled, contentType); + } + } + // if src is string, directly add the param with src as filepath + else { + addFormParam(formdataArray, key, param.type, param.src, disabled, contentType); + } + } + // if type is text, directly add it to formdata array + else { + addFormParam(formdataArray, key, param.type, param.value, disabled, contentType); + } + }); + request.body.update({ + mode: 'formdata', + formdata: formdataArray + }); + } + requestBody = (request.body ? request.body.toJSON() : {}); + bodySnippet = parseBody(requestBody, trim, indent); + + headerSnippet = parseHeaders(request.toJSON().header, (request.body ? request.body.mode : 'raw')); + if (bodySnippet !== '') { + dataSnippet = `${indent}${bodySnippet}`; + } + + dataSnippet = dataSnippet.replace(/^\s*$(?:\r\n?|\n)/gm, ''); + + codeSnippet = ''; + codeSnippet += `require('qcobjects');logger.infoEnabled=false; + ${indent}Class('MyTestService',Service,{ + ${indent.repeat(2)}name:'myservice', + ${indent.repeat(2)}external:true, + ${indent.repeat(2)}cached:false, + ${indent.repeat(2)}method:"${request.method}", + ${indent.repeat(2)}${headerSnippet} + ${indent.repeat(2)}url:"${finalUrl}", + ${indent.repeat(2)}withCredentials:false, + ${indent.repeat(2)}_new_:()=>{ + ${indent.repeat(3)}// service instantiated + ${indent.repeat(2)}}, + ${indent.repeat(2)}done:()=>{ + ${indent.repeat(3)}// service loaded + ${indent.repeat(2)}} + ${indent}}); + var service = serviceLoader(New(MyTestService,{ + ${dataSnippet} + })).then( + (successfulResponse)=>{ + ${indent.repeat(2)}// This will show the service response as a plain text + ${indent.repeat(2)}console.log(successfulResponse.service.template); + }, + (failedResponse)=>{ + ${indent.repeat(2)}// The service call failed + ${indent.repeat(2)}console.log('The service call failed'); + ${indent.repeat(2)}console.log(failedResponse); + }).catch((e)=>{ + ${indent.repeat(2)}// Something went wrong when calling the service + ${indent.repeat(2)}console.log('Something went wrong when calling the service'); + ${indent.repeat(2)}console.log(failedResponse); + });`; + return callback(null, codeSnippet); + } +}; diff --git a/codegens/qcobjects/lib/util.js b/codegens/qcobjects/lib/util.js new file mode 100644 index 000000000..7ef16e2b0 --- /dev/null +++ b/codegens/qcobjects/lib/util.js @@ -0,0 +1,182 @@ +/** + * Sanitizes input string by handling escape characters according to request body type + * + * @param {String} inputString - Input String to sanitize + * @param {String} escapeCharFor - Escape character for headers, body: raw, formdata etc. + * @param {Boolean} [inputTrim] - Indicates whether to trim string or not + * @returns {String} Sanitized String handling escape characters + */ +function sanitize (inputString, escapeCharFor, inputTrim) { + + if (typeof inputString !== 'string') { + return ''; + } + inputString = inputTrim && typeof inputTrim === 'boolean' ? inputString.trim() : inputString; + if (escapeCharFor && typeof escapeCharFor === 'string') { + switch (escapeCharFor) { + case 'raw': + return JSON.stringify(inputString); + case 'urlencoded': + return escape(inputString); + case 'formdata': + return inputString.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + /* istanbul ignore next */ + case 'file': + return inputString.replace(/{/g, '[').replace(/}/g, ']'); + case 'header': + return inputString.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + /* istanbul ignore next */ + default: + return inputString.replace(/"/g, '\\"'); + } + } + return inputString; +} + +/** + * sanitizes input options + * + * @param {Object} options - Options provided by the user + * @param {Array} optionsArray - options array received from getOptions function + * + * @returns {Object} - Sanitized options object + */ +function sanitizeOptions (options, optionsArray) { + var result = {}, + defaultOptions = {}, + id; + optionsArray.forEach((option) => { + defaultOptions[option.id] = { + default: option.default, + type: option.type + }; + if (option.type === 'enum') { + defaultOptions[option.id].availableOptions = option.availableOptions; + } + }); + + for (id in options) { + if (options.hasOwnProperty(id)) { + if (defaultOptions[id] === undefined) { + continue; + } + switch (defaultOptions[id].type) { + case 'boolean': + if (typeof options[id] !== 'boolean') { + result[id] = defaultOptions[id].default; + } + else { + result[id] = options[id]; + } + break; + case 'positiveInteger': + if (typeof options[id] !== 'number' || options[id] < 0) { + result[id] = defaultOptions[id].default; + } + else { + result[id] = options[id]; + } + break; + case 'enum': + if (!defaultOptions[id].availableOptions.includes(options[id])) { + result[id] = defaultOptions[id].default; + } + else { + result[id] = options[id]; + } + break; + default: + result[id] = options[id]; + } + } + } + + for (id in defaultOptions) { + if (defaultOptions.hasOwnProperty(id)) { + if (result[id] === undefined) { + result[id] = defaultOptions[id].default; + } + } + } + return result; +} + +/** + * + * @param {*} urlObject The request sdk request.url object + * @returns {String} The final string after parsing all the parameters of the url including + * protocol, auth, host, port, path, query, hash + * This will be used because the url.toString() method returned the URL with non encoded query string + * and hence a manual call is made to getQueryString() method with encode option set as true. + */ +function getUrlStringfromUrlObject (urlObject) { + var url = ''; + if (!urlObject) { + return url; + } + if (urlObject.protocol) { + url += (urlObject.protocol.endsWith('://') ? urlObject.protocol : urlObject.protocol + '://'); + } + if (urlObject.auth && urlObject.auth.user) { + url = url + ((urlObject.auth.password) ? + // ==> username:password@ + urlObject.auth.user + ':' + urlObject.auth.password : urlObject.auth.user) + '@'; + } + if (urlObject.host) { + url += urlObject.getHost(); + } + if (urlObject.port) { + url += ':' + urlObject.port.toString(); + } + if (urlObject.path) { + url += urlObject.getPath(); + } + if (urlObject.query && urlObject.query.count()) { + let queryString = urlObject.getQueryString({ ignoreDisabled: true, encode: true }); + queryString && (url += '?' + queryString); + } + if (urlObject.hash) { + url += '#' + urlObject.hash; + } + + return url; +} + +/** + * + * @param {Array} array - form data array + * @param {String} key - key of form data param + * @param {String} type - type of form data param(file/text) + * @param {String} val - value/src property of form data param + * @param {String} disabled - Boolean denoting whether the param is disabled or not + * @param {String} contentType - content type header of the param + * + * Appends a single param to form data array + */ +function addFormParam (array, key, type, val, disabled, contentType) { + if (type === 'file') { + array.push({ + key: key, + type: type, + src: val, + disabled: disabled, + contentType: contentType + }); + } + else { + array.push({ + key: key, + type: type, + value: val, + disabled: disabled, + contentType: contentType + }); + } +} + +module.exports = { + sanitize: sanitize, + sanitizeOptions: sanitizeOptions, + getUrlStringfromUrlObject: getUrlStringfromUrlObject, + addFormParam: addFormParam +}; diff --git a/codegens/qcobjects/npm/test-lint.js b/codegens/qcobjects/npm/test-lint.js new file mode 100644 index 000000000..646524c78 --- /dev/null +++ b/codegens/qcobjects/npm/test-lint.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +/* eslint-env node, es6 */ +require('shelljs/global'); + +var chalk = require('chalk'), + async = require('async'), + ESLintCLIEngine = require('eslint').CLIEngine, + + /** + * The list of source code files / directories to be linted. + * + * @type {Array} + */ + LINT_SOURCE_DIRS = [ + './lib', + './test', + './npm/*.js', + './index.js' + ]; + +module.exports = function (exit) { + // banner line + console.info(chalk.yellow.bold('\nLinting files using eslint...')); + + async.waterfall([ + + /** + * Instantiates an ESLint CLI engine and runs it in the scope defined within LINT_SOURCE_DIRS. + * + * @param {Function} next - The callback function whose invocation marks the end of the lint test run. + * @returns {*} + */ + function (next) { + next(null, (new ESLintCLIEngine()).executeOnFiles(LINT_SOURCE_DIRS)); + }, + + /** + * Processes a test report from the Lint test runner, and displays meaningful results. + * + * @param {Object} report - The overall test report for the current lint test. + * @param {Object} report.results - The set of test results for the current lint run. + * @param {Function} next - The callback whose invocation marks the completion of the post run tasks. + * @returns {*} + */ + function (report, next) { + var errorReport = ESLintCLIEngine.getErrorResults(report.results); + // log the result to CLI + console.info(ESLintCLIEngine.getFormatter()(report.results)); + // log the success of the parser if it has no errors + (errorReport && !errorReport.length) && console.info(chalk.green('eslint ok!')); + // ensure that the exit code is non zero in case there was an error + next(Number(errorReport && errorReport.length) || 0); + } + ], exit); +}; + +// ensure we run this script exports if this is a direct stdin.tty run +!module.parent && module.exports(exit); diff --git a/codegens/qcobjects/npm/test-newman.js b/codegens/qcobjects/npm/test-newman.js new file mode 100644 index 000000000..d2832d79f --- /dev/null +++ b/codegens/qcobjects/npm/test-newman.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node +/* eslint-env node, es6 */ +// --------------------------------------------------------------------------------------------------------------------- +// This script is intended to execute all unit tests. +// --------------------------------------------------------------------------------------------------------------------- + +require('shelljs/global'); + +// set directories and files for test and coverage report +var path = require('path'), + + NYC = require('nyc'), + chalk = require('chalk'), + recursive = require('recursive-readdir'), + + COV_REPORT_PATH = '.coverage', + SPEC_SOURCE_DIR = path.join(__dirname, '..', 'test', 'newman'); + +module.exports = function (exit) { + // banner line + console.info(chalk.yellow.bold('Running newman tests using mocha on node...')); + + test('-d', COV_REPORT_PATH) && rm('-rf', COV_REPORT_PATH); + mkdir('-p', COV_REPORT_PATH); + + var Mocha = require('mocha'), + nyc = new NYC({ + reportDir: COV_REPORT_PATH, + tempDirectory: COV_REPORT_PATH, + reporter: ['text', 'lcov', 'text-summary'], + exclude: ['config', 'test'], + hookRunInContext: true, + hookRunInThisContext: true + }); + + nyc.wrap(); + // add all spec files to mocha + recursive(SPEC_SOURCE_DIR, function (err, files) { + if (err) { console.error(err); return exit(1); } + + var mocha = new Mocha({ timeout: 1000 * 60 }); + + files.filter(function (file) { // extract all test files + return (file.substr(-8) === '.test.js'); + }).forEach(mocha.addFile.bind(mocha)); + + mocha.run(function (runError) { + runError && console.error(runError.stack || runError); + + nyc.reset(); + try { + nyc.writeCoverageFile(); + } + catch (e) { + console.log('It was not possible to write the coverage file ' + e.toString()); + } + nyc.report(); + exit(runError ? 1 : 0); + }); + }); +}; + +// ensure we run this script exports if this is a direct stdin.tty run +!module.parent && module.exports(exit); diff --git a/codegens/qcobjects/npm/test-unit.js b/codegens/qcobjects/npm/test-unit.js new file mode 100644 index 000000000..1bd787adb --- /dev/null +++ b/codegens/qcobjects/npm/test-unit.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node +/* eslint-env node, es6 */ +// --------------------------------------------------------------------------------------------------------------------- +// This script is intended to execute all unit tests. +// --------------------------------------------------------------------------------------------------------------------- + +require('shelljs/global'); + +// set directories and files for test and coverage report +var path = require('path'), + + NYC = require('nyc'), + chalk = require('chalk'), + recursive = require('recursive-readdir'), + + COV_REPORT_PATH = '.coverage', + SPEC_SOURCE_DIR = path.join(__dirname, '..', 'test', 'unit'); + +module.exports = function (exit) { + // banner line + console.info(chalk.yellow.bold('Running unit tests using mocha on node...')); + + test('-d', COV_REPORT_PATH) && rm('-rf', COV_REPORT_PATH); + mkdir('-p', COV_REPORT_PATH); + + var Mocha = require('mocha'), + nyc = new NYC({ + reportDir: COV_REPORT_PATH, + tempDirectory: COV_REPORT_PATH, + reporter: ['text', 'lcov', 'text-summary'], + exclude: ['config', 'test'], + hookRunInContext: true, + hookRunInThisContext: true + }); + + nyc.wrap(); + // add all spec files to mocha + recursive(SPEC_SOURCE_DIR, function (err, files) { + if (err) { console.error(err); return exit(1); } + + var mocha = new Mocha({ timeout: 1000 * 60 }); + + files.filter(function (file) { // extract all test files + return (file.substr(-8) === '.test.js'); + }).forEach(mocha.addFile.bind(mocha)); + + mocha.run(function (runError) { + runError && console.error(runError.stack || runError); + + nyc.reset(); + nyc.writeCoverageFile(); + nyc.report(); + exit(runError ? 1 : 0); + }); + }); +}; + +// ensure we run this script exports if this is a direct stdin.tty run +!module.parent && module.exports(exit); diff --git a/codegens/qcobjects/npm/test.js b/codegens/qcobjects/npm/test.js new file mode 100644 index 000000000..da2816f09 --- /dev/null +++ b/codegens/qcobjects/npm/test.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node +var chalk = require('chalk'), + exit = require('shelljs').exit, + prettyms = require('pretty-ms'), + startedAt = Date.now(), + name = require('../package.json').name; + +require('async').series([ + require('./test-lint'), + require('./test-newman'), + require('./test-unit') + // require('./test-browser') + // require('./test-integration') +], function (code) { + // eslint-disable-next-line max-len + console.info(chalk[code ? 'red' : 'green'](`\n${name}: duration ${prettyms(Date.now() - startedAt)}\n${name}: ${code ? 'not ok' : 'ok'}!`)); + exit(code && (typeof code === 'number' ? code : 1) || 0); +}); diff --git a/codegens/qcobjects/package.json b/codegens/qcobjects/package.json new file mode 100644 index 000000000..da3ebeb98 --- /dev/null +++ b/codegens/qcobjects/package.json @@ -0,0 +1,41 @@ +{ + "name": "@postman/codegen-qcobjects", + "version": "0.0.1", + "description": "Converts Postman SDK Requests to QCObjects code snippet", + "main": "index.js", + "com_postman_plugin": { + "type": "code_generator", + "lang": "qcobjects", + "variant": "serviceLoader", + "syntax_mode": "javascript" + }, + "directories": { + "lib": "lib", + "test": "test" + }, + "scripts": { + "test": "npm i && node npm/test.js", + "test-lint": "node npm/test-lint.js", + "test-newman": "node npm/test-newman.js" + }, + "repository": { + "type": "git", + "url": "" + }, + "author": "Postman Labs ", + "license": "Apache-2.0", + "homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/qcobjects", + "dependencies": { + "postman-collection": "3.6.9", + "url":"0.11.0", + "qcobjects-sdk":"2.3.30", + "qcobjects":"2.3.68", + "qcobjects-cli":"2.3.47" + }, + "devDependencies": { + "follow-redirects": "1.13.1" + }, + "engines": { + "node": ">=8" + } +} diff --git a/codegens/qcobjects/qcobjects-app.js b/codegens/qcobjects/qcobjects-app.js new file mode 100644 index 000000000..2a0191d7c --- /dev/null +++ b/codegens/qcobjects/qcobjects-app.js @@ -0,0 +1,33 @@ +/* eslint-disable */ +require('qcobjects');logger.infoEnabled=false; + Class('MyTestService',Service,{ + name:'myservice', + external:true, + cached:false, + method:"POST", + + url:"https://postman-echo.com/post", + withCredentials:false, + _new_:()=>{ + // service instantiated + }, + done:()=>{ + // service loaded + } + }); + var service = serviceLoader(New(MyTestService,{ + data:"" + })).then( + (successfulResponse)=>{ + // This will show the service response as a plain text + console.log(successfulResponse.service.template); + }, + (failedResponse)=>{ + // The service call failed + console.log('The service call failed'); + console.log(failedResponse); + }).catch((e)=>{ + // Something went wrong when calling the service + console.log('Something went wrong when calling the service'); + console.log(failedResponse); + }); \ No newline at end of file diff --git a/codegens/qcobjects/test/newman/newman.test.js b/codegens/qcobjects/test/newman/newman.test.js new file mode 100644 index 000000000..65cdf66bb --- /dev/null +++ b/codegens/qcobjects/test/newman/newman.test.js @@ -0,0 +1,25 @@ +var runNewmanTest = require('../../../../test/codegen/newman/newmanTestUtil').runNewmanTest, + convert = require('../../index').convert; +describe('qcobjects Converter', function () { + describe('convert for different request types', function () { + var options = { + indentType: 'Space', + indentCount: 4 + }, + testConfig = { + // filename along with the appropriate version of the file. This file will be used to run the snippet. + fileName: 'qcobjects-app.js', + // Run script required to run the generated code snippet + runScript: 'node qcobjects-app.js', + // Compile script required to compile the code snippet + compileScript: null, + // Array of name of collections for which newman tests has to be skipped. + skipCollections: ['basicCollection', 'sameNameHeadersCollection', + 'redirectCollection', 'formdataCollection', 'formdataFileCollection'], + + headerSnippet: '/* eslint-disable */\n' + }; + + runNewmanTest(convert, options, testConfig); + }); +}); diff --git a/codegens/qcobjects/test/unit/convert.test.js b/codegens/qcobjects/test/unit/convert.test.js new file mode 100644 index 000000000..4476ed57a --- /dev/null +++ b/codegens/qcobjects/test/unit/convert.test.js @@ -0,0 +1,290 @@ +var expect = require('chai').expect, + sdk = require('postman-collection'), + convert = require('../../index').convert, + sanitize = require('../../lib/util').sanitize, + getUrlStringfromUrlObject = require('../../lib/util').getUrlStringfromUrlObject, + getOptions = require('../../index').getOptions, + mainCollection = require('./fixtures/testcollection/collection.json'); + + +describe('QCObjects Converter', function () { + + describe('convert function', function () { + var request = new sdk.Request(mainCollection.item[0].request), + snippetArray; + + const SINGLE_SPACE = ' '; // default indent type with indent count of 2 + it('should generate snippet with default options given no options', function () { + convert(request, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + return; + } + snippetArray = snippet.split('\n'); + for (var i = 0; i < snippetArray.length; i++) { + if (snippetArray[i].startsWith('let task = URLSession.shared.dataTask')) { + expect(snippetArray[i + 1].charAt(0)).to.equal(SINGLE_SPACE); + expect(snippetArray[i + 1].charAt(1)).to.equal(SINGLE_SPACE); + } + } + }); + }); + + it('should generate snippet with Space as an indent type with default indent count', function () { + convert(request, { indentType: 'Space' }, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + return; + } + snippetArray = snippet.split('\n'); + for (var i = 0; i < snippetArray.length; i++) { + if (snippetArray[i].startsWith('let task = URLSession.shared.dataTask')) { + expect(snippetArray[i + 1].charAt(0)).to.equal(SINGLE_SPACE); + expect(snippetArray[i + 1].charAt(1)).to.equal(SINGLE_SPACE); + } + } + }); + }); + + + it('should not encode queryParam unresolved variables and ' + + 'leave it inside double parenthesis {{xyz}}', function () { + request = new sdk.Request({ + 'method': 'POST', + 'header': [], + 'url': { + 'raw': 'http://postman-echo.com/post?a={{xyz}}', + 'protocol': 'http', + 'host': [ + 'postman-echo', + 'com' + ], + 'path': [ + 'post' + ], + 'query': [ + { + 'key': 'a', + 'value': '{{xyz}}' + } + ] + } + }); + convert(request, {}, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + } + expect(snippet).to.be.a('string'); + expect(snippet).to.include('http://postman-echo.com/post?a={{xyz}}'); + expect(snippet).to.not.include('http://postman-echo.com/post?a=%7B%7Bxyz%7D%7D'); + }); + }); + + it('should encode queryParams other than unresolved variables', function () { + request = new sdk.Request({ + 'method': 'POST', + 'header': [], + 'url': { + 'raw': 'http://postman-echo.com/post?a=b c', + 'protocol': 'http', + 'host': [ + 'postman-echo', + 'com' + ], + 'path': [ + 'post' + ], + 'query': [ + { + 'key': 'a', + 'value': 'b c' + } + ] + } + }); + convert(request, {}, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + } + expect(snippet).to.be.a('string'); + expect(snippet).to.include('http://postman-echo.com/post?a=b%20c'); + expect(snippet).to.not.include('http://postman-echo.com/post?a=b c'); + }); + }); + + it('should generate snippets for no files in form data', function () { + var request = new sdk.Request({ + 'method': 'POST', + 'header': [], + 'body': { + 'mode': 'formdata', + 'formdata': [ + { + 'key': 'no file', + 'value': '', + 'type': 'file', + 'src': [] + }, + { + 'key': 'no src', + 'value': '', + 'type': 'file' + }, + { + 'key': 'invalid src', + 'value': '', + 'type': 'file', + 'src': {} + } + ] + }, + 'url': { + 'raw': 'https://postman-echo.com/post', + 'protocol': 'https', + 'host': [ + 'postman-echo', + 'com' + ], + 'path': [ + 'post' + ] + } + }); + convert(request, {}, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + } + expect(snippet).to.be.a('string'); + expect(snippet).to.include('"key": "no file"'); + expect(snippet).to.include('"src": "/path/to/file"'); + expect(snippet).to.include('"key": "no src"'); + expect(snippet).to.include('"key": "invalid src"'); + }); + }); + }); + + describe('getUrlStringfromUrlObject function', function () { + var rawUrl, urlObject, outputUrlString; + + it('should return empty string for an url object for an empty url or if no url object is passed', function () { + rawUrl = ''; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.be.empty; + outputUrlString = getUrlStringfromUrlObject(); + expect(outputUrlString).to.be.empty; + }); + + it('should add protocol if present in the url object', function () { + rawUrl = 'https://postman-echo.com'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + + it('should add the auth information if present in the url object', function () { + rawUrl = 'https://user:password@postman-echo.com'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + + it('should not add the auth information if user isn\'t present but' + + ' password is present in the url object', function () { + rawUrl = 'https://:password@postman-echo.com'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.not.include(':password'); + }); + + it('should add host if present in the url object', function () { + rawUrl = 'https://postman-echo.com'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + + it('should add port if present in the url object', function () { + rawUrl = 'https://postman-echo.com:8080'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + + it('should add path if present in the url object', function () { + rawUrl = 'https://postman-echo.com/get'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + + describe('queryParams', function () { + + it('should not encode unresolved query params', function () { + rawUrl = 'https://postman-echo.com/get?key={{value}}'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.not.include('key=%7B%7Bvalue%7B%7B'); + expect(outputUrlString).to.equal(rawUrl); + }); + + it('should encode query params other than unresolved variables', function () { + rawUrl = 'https://postman-echo.com/get?key=\'a b c\''; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.not.include('key=\'a b c\''); + expect(outputUrlString).to.equal('https://postman-echo.com/get?key=%27a%20b%20c%27'); + }); + + it('should not encode unresolved query params and ' + + 'encode every other query param, both present together', function () { + rawUrl = 'https://postman-echo.com/get?key1={{value}}&key2=\'a b c\''; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.not.include('key1=%7B%7Bvalue%7B%7B'); + expect(outputUrlString).to.not.include('key2=\'a b c\''); + expect(outputUrlString).to.equal('https://postman-echo.com/get?key1={{value}}&key2=%27a%20b%20c%27'); + }); + + it('should discard disabled query params', function () { + urlObject = new sdk.Url({ + protocol: 'https', + host: 'postman-echo.com', + query: [ + { key: 'foo', value: 'bar' }, + { key: 'alpha', value: 'beta', disabled: true } + ] + }); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal('https://postman-echo.com?foo=bar'); + }); + }); + + it('should add hash if present in the url object', function () { + rawUrl = 'https://postmanm-echo.com/get#hash'; + urlObject = new sdk.Url(rawUrl); + outputUrlString = getUrlStringfromUrlObject(urlObject); + expect(outputUrlString).to.equal(rawUrl); + }); + }); + + describe('getOptions function', function () { + it('should return array of options for swift-urlsession converter', function () { + expect(getOptions()).to.be.an('array'); + }); + + it('should return all the valid options', function () { + expect(getOptions()[0]).to.have.property('id', 'indentCount'); + expect(getOptions()[1]).to.have.property('id', 'indentType'); + expect(getOptions()[2]).to.have.property('id', 'requestTimeout'); + expect(getOptions()[3]).to.have.property('id', 'trimRequestBody'); + }); + }); + + describe('sanitize function', function () { + it('should handle invalid parameters', function () { + expect(sanitize(123, 'raw', false)).to.equal(''); + expect(sanitize('inputString', 123, true)).to.equal('inputString'); + }); + }); +}); diff --git a/codegens/qcobjects/test/unit/fixtures/testcollection/collection.json b/codegens/qcobjects/test/unit/fixtures/testcollection/collection.json new file mode 100644 index 000000000..ba436e23e --- /dev/null +++ b/codegens/qcobjects/test/unit/fixtures/testcollection/collection.json @@ -0,0 +1,1455 @@ +{ + "info": { + "_postman_id": "419b4611-01a1-42bb-8417-7a34a8c7de2c", + "name": "Code-Gen Test Cases", + "description": "This collection contains requests that will be used to test validity of plugin created to convert postman request into code snippet of particular language.", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Request Headers with disabled headers", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "try {", + " tests[\"Body contains headers\"] = responseBody.has(\"headers\");", + " responseJSON = JSON.parse(responseBody);", + " tests[\"Header contains host\"] = \"host\" in responseJSON.headers;", + " tests[\"Header contains test parameter sent as part of request header\"] = \"my-sample-header\" in responseJSON.headers;", + "}", + "catch (e) { }", + "", + "", + "", + "" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "my-sample-header", + "value": "Lorem ipsum dolor sit amet" + }, + { + "key": "not-disabled-header", + "value": "ENABLED" + }, + { + "key": "disabled header", + "value": "DISABLED", + "disabled": true + } + ], + "body": { + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "A `GET` request to this endpoint returns the list of all request headers as part of the response JSON.\nIn Postman, sending your own set of headers through the [Headers tab](https://www.getpostman.com/docs/requests#headers?source=echo-collection-app-onboarding) will reveal the headers as part of the response." + }, + "response": [] + }, + { + "name": "GET Request with disabled query", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "tests['response json contains headers'] = _.has(responseJSON, 'headers');", + "tests['response json contains args'] = _.has(responseJSON, 'args');", + "tests['response json contains url'] = _.has(responseJSON, 'url');", + "", + "tests['args key contains argument passed as url parameter'] = ('test' in responseJSON.args);", + "tests['args passed via request url params has value \"123\"'] = (_.get(responseJSON, 'args.test') === \"123\");" + ] + } + } + ], + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request?test=123&anotherone=232", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ], + "query": [ + { + "key": "test", + "value": "123" + }, + { + "key": "anotherone", + "value": "232" + }, + { + "key": "anotheroneone", + "value": "sdfsdf", + "disabled": true + } + ] + }, + "description": "The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested." + }, + "response": [] + }, + { + "name": "POST Raw Text", + "event": [ + { + "listen": "test", + "script": { + "id": "753f8a33-adb6-402f-8d19-386c1981ecb6", + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "\"'Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, \"id\" \"se\\\"mper\" sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.'\"" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST form data with file", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded", + "disabled": true + }, + { + "key": "content-type", + "value": "application/json", + "disabled": true + } + ], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "fdjks", + "value": "dsf", + "type": "text" + }, + { + "key": "&^%", + "value": "helo", + "type": "text" + }, + { + "key": "12", + "value": "\"23\"", + "type": "text" + }, + { + "key": "'123'", + "value": "'\"23\\\"4\\\"\"'", + "type": "text" + }, + { + "key": "", + "value": "", + "type": "text", + "disabled": true + } + ] + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST urlencoded data with disabled entries", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "1", + "value": "a", + "type": "text" + }, + { + "key": "2", + "value": "b", + "type": "text", + "disabled": true + }, + { + "key": "\"\"12\"\"", + "value": "\"23\"", + "type": "text" + }, + { + "key": "'1\"2\\\"\"3'", + "value": "'1\"23\"4'", + "type": "text" + } + ] + }, + "url": { + "raw": "https://mockbin.org/request?hardik=\"me\"", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ], + "query": [ + { + "key": "hardik", + "value": "\"me\"" + } + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST json with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"json\": \"Test-Test\"\n}" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [ + { + "name": "POST json with raw", + "originalRequest": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"json\": \"Test-Test\"\n}" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + } + }, + "status": "OK", + "code": 200, + "_postman_previewlanguage": "json", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "", + "name": "Access-Control-Allow-Credentials", + "description": "Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials." + }, + { + "key": "Access-Control-Allow-Headers", + "value": "", + "name": "Access-Control-Allow-Headers", + "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request." + }, + { + "key": "Access-Control-Allow-Methods", + "value": "", + "name": "Access-Control-Allow-Methods", + "description": "Specifies the method or methods allowed when accessing the resource. This is used in response to a preflight request." + }, + { + "key": "Access-Control-Allow-Origin", + "value": "", + "name": "Access-Control-Allow-Origin", + "description": "Specifies a URI that may access the resource. For requests without credentials, the server may specify '*' as a wildcard, thereby allowing any origin to access the resource." + }, + { + "key": "Access-Control-Expose-Headers", + "value": "", + "name": "Access-Control-Expose-Headers", + "description": "Lets a server whitelist headers that browsers are allowed to access." + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "Options that are desired for the connection" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "The type of encoding used on the data." + }, + { + "key": "Content-Length", + "value": "385", + "name": "Content-Length", + "description": "The length of the response body in octets (8-bit bytes)" + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "The mime type of this content" + }, + { + "key": "Date", + "value": "Wed, 07 Feb 2018 10:06:15 GMT", + "name": "Date", + "description": "The date and time that the message was sent" + }, + { + "key": "ETag", + "value": "W/\"215-u7EU1nFtauIn0/aVifjuXA\"", + "name": "ETag", + "description": "An identifier for a specific version of a resource, often a message digest" + }, + { + "key": "Server", + "value": "nginx", + "name": "Server", + "description": "A name for the server" + }, + { + "key": "Vary", + "value": "X-HTTP-Method-Override, Accept-Encoding", + "name": "Vary", + "description": "Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server." + }, + { + "key": "set-cookie", + "value": "sails.sid=s%3AxRBxgrc9M-jKK_l1mX3y3rM_ry8wYLz4.Of4qpOzd9hi6uO0sAQIj%2Bxs2VeppWxYjJa4OpIW3PKg; Path=/; HttpOnly", + "name": "set-cookie", + "description": "an HTTP cookie" + } + ], + "cookie": [ + { + "expires": "Invalid Date", + "httpOnly": true, + "domain": "postman-echo.com", + "path": "/", + "secure": false, + "value": "s%3AxRBxgrc9M-jKK_l1mX3y3rM_ry8wYLz4.Of4qpOzd9hi6uO0sAQIj%2Bxs2VeppWxYjJa4OpIW3PKg", + "key": "sails.sid" + } + ], + "body": "{\"args\":{},\"data\":\"{\\n \\\"json\\\": \\\"Test-Test\\\"\\n}\",\"files\":{},\"form\":{},\"headers\":{\"host\":\"postman-echo.com\",\"content-length\":\"25\",\"accept\":\"*/*\",\"accept-encoding\":\"gzip, deflate\",\"cache-control\":\"no-cache\",\"content-type\":\"text/plain\",\"cookie\":\"sails.sid=s%3AkOgtF1XmXtVFx-Eg3S7-37BKKaMqMDPe.hnwldNwyvsaASUiRR0Y0vcowadkMXO4HMegTeVIPgqo\",\"postman-token\":\"2ced782f-a141-428e-8af6-04ce954a77d5\",\"user-agent\":\"PostmanRuntime/7.1.1\",\"x-forwarded-port\":\"443\",\"x-forwarded-proto\":\"https\"},\"json\":null,\"url\":\"https://postman-echo.com/post\"}" + } + ] + }, + { + "name": "POST javascript with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/javascript" + } + ], + "body": { + "mode": "raw", + "raw": "var val = 6;\nconsole.log(val);" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST text/xml with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/xml" + } + ], + "body": { + "mode": "raw", + "raw": "\n Test Test\n" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST text/html with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/html" + } + ], + "body": { + "mode": "raw", + "raw": "\n Test Test\n" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "Resolve URL", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "raw", + "raw": "Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat." + }, + "url": { + "raw": "https://mockbin.org/request/:action", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request", + ":action" + ], + "variable": [ + { + "key": "action", + "value": "post" + } + ] + } + }, + "response": [] + }, + { + "name": "PUT Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "Etiam mi lacus, cursus vitae felis et, blandit pellentesque neque. Vestibulum eget nisi a tortor commodo dignissim.\nQuisque ipsum ligula, faucibus a felis a, commodo elementum nisl. Mauris vulputate sapien et tincidunt viverra. Donec vitae velit nec metus." + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `PUT` request method is similar to HTTP `POST`. It too is meant to \ntransfer data to a server (and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `PUT` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following \nraw HTTP request,\n\n> PUT /hi/there?hand=wave\n>\n> \n\n\n" + }, + "response": [] + }, + { + "name": "PATCH Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "Curabitur auctor, elit nec pulvinar porttitor, ex augue condimentum enim, eget suscipit urna felis quis neque.\nSuspendisse sit amet luctus massa, nec venenatis mi. Suspendisse tincidunt massa at nibh efficitur fringilla. Nam quis congue mi. Etiam volutpat." + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `PATCH` method is used to update resources on a server. The exact\nuse of `PATCH` requests depends on the server in question. There are a number\nof server implementations which handle `PATCH` differently. Technically, \n`PATCH` supports both Query String parameters and a Request Body.\n\nThis endpoint accepts an HTTP `PATCH` request and provides debug information\nsuch as the HTTP headers, Query String arguments, and the Request Body." + }, + "response": [] + }, + { + "name": "DELETE Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + }, + { + "key": "Content-Length", + "value": "1000", + "disabled": true + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "dsfs", + "value": "sfdds", + "type": "text" + }, + { + "key": "sfdsdf", + "value": "sdf", + "type": "text" + } + ] + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `DELETE` method is used to delete resources on a server. The exact\nuse of `DELETE` requests depends on the server implementation. In general, \n`DELETE` requests support both, Query String parameters as well as a Request \nBody.\n\nThis endpoint accepts an HTTP `DELETE` request and provides debug information\nsuch as the HTTP headers, Query String arguments, and the Request Body." + }, + "response": [] + }, + { + "name": "OPTIONS to postman echo", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "OPTIONS", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "HEAD request", + "request": { + "method": "HEAD", + "header": [ + { + "key": "hello", + "value": "helloagain", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "LINK request", + "request": { + "method": "LINK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "UNLINK request", + "request": { + "method": "UNLINK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "LOCK request", + "request": { + "method": "LOCK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "UNLOCK request", + "request": { + "method": "UNLOCK", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "PROFIND request", + "request": { + "method": "PROPFIND", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "VIEW request", + "request": { + "method": "VIEW", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [] + }, + { + "name": "PURGE Request", + "request": { + "method": "PURGE", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io", + "protocol": "https", + "host": [ + "9c76407d-5b8d-4b22-99fb-8c47a85d9848", + "mock", + "pstmn", + "io" + ] + } + }, + "response": [ + { + "name": "PURGE Request", + "originalRequest": { + "method": "PURGE", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io", + "protocol": "https", + "host": [ + "9c76407d-5b8d-4b22-99fb-8c47a85d9848", + "mock", + "pstmn", + "io" + ] + } + }, + "status": "Not Found", + "code": 404, + "_postman_previewlanguage": "text", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "", + "name": "Access-Control-Allow-Credentials", + "description": "" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "", + "name": "Access-Control-Allow-Headers", + "description": "" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "", + "name": "Access-Control-Allow-Methods", + "description": "" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*", + "name": "Access-Control-Allow-Origin", + "description": "" + }, + { + "key": "Access-Control-Expose-Headers", + "value": "", + "name": "Access-Control-Expose-Headers", + "description": "" + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "" + }, + { + "key": "Content-Length", + "value": "152", + "name": "Content-Length", + "description": "" + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "" + }, + { + "key": "Date", + "value": "Tue, 13 Feb 2018 13:58:56 GMT", + "name": "Date", + "description": "" + }, + { + "key": "ETag", + "value": "W/\"a7-kIxN5L9H0YwilUQPUUio9A\"", + "name": "ETag", + "description": "" + }, + { + "key": "Server", + "value": "nginx", + "name": "Server", + "description": "" + }, + { + "key": "Vary", + "value": "Accept-Encoding", + "name": "Vary", + "description": "" + } + ], + "cookie": [], + "body": "{\n \"args\": {},\n \"data\": \"Curabitur auctor, elit nec pulvinar porttitor, ex augue condimentum enim, eget suscipit urna felis quis neque.\\nSuspendisse sit amet luctus massa, nec venenatis mi. Suspendisse tincidunt massa at nibh efficitur fringilla. Nam quis congue mi. Etiam volutpat.\",\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"host\": \"postman-echo.com\",\n \"content-length\": \"256\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"content-type\": \"text/plain\",\n \"cookie\": \"sails.sid=s%3A1wOi4AdoZEbqBjGi6oSUC5Vlfje8wJvs.DHQfRLXfIBvZ%2Bv0KhLAThMDz%2FXvxh9gyxWYa0u1EZOU\",\n \"user-agent\": \"PostmanRuntime/7.1.1\",\n \"x-forwarded-port\": \"443\",\n \"x-forwarded-proto\": \"https\"\n },\n \"json\": null,\n \"url\": \"https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io\"\n}" + } + ] + }, + { + "name": "COPY Request", + "request": { + "method": "COPY", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "response": [ + { + "name": "COPY Request", + "originalRequest": { + "method": "COPY", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "status": "OK", + "code": 200, + "_postman_previewlanguage": "json", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "true", + "name": "Access-Control-Allow-Credentials", + "description": "Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials." + }, + { + "key": "Access-Control-Allow-Headers", + "value": "host,connection,accept-encoding,x-forwarded-for,cf-ray,x-forwarded-proto,cf-visitor,cache-control,postman-token,user-agent,accept,cookie,cf-connecting-ip,x-request-id,x-forwarded-port,via,connect-time,x-request-start,total-route-time,content-length", + "name": "Access-Control-Allow-Headers", + "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request." + }, + { + "key": "Access-Control-Allow-Methods", + "value": "COPY", + "name": "Access-Control-Allow-Methods", + "description": "Specifies the method or methods allowed when accessing the resource. This is used in response to a preflight request." + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*", + "name": "Access-Control-Allow-Origin", + "description": "Specifies a URI that may access the resource. For requests without credentials, the server may specify '*' as a wildcard, thereby allowing any origin to access the resource." + }, + { + "key": "CF-RAY", + "value": "3fb595d5facaa302-HKG", + "name": "CF-RAY", + "description": "Custom header" + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "Options that are desired for the connection" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "The type of encoding used on the data." + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "The mime type of this content" + }, + { + "key": "Date", + "value": "Wed, 14 Mar 2018 09:06:37 GMT", + "name": "Date", + "description": "The date and time that the message was sent" + }, + { + "key": "Etag", + "value": "W/\"4ac-YP9NIoQ5TiGJRPuQSZMKtA\"", + "name": "Etag", + "description": "An identifier for a specific version of a resource, often a message digest" + }, + { + "key": "Expect-CT", + "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", + "name": "Expect-CT", + "description": "Custom header" + }, + { + "key": "Server", + "value": "cloudflare", + "name": "Server", + "description": "A name for the server" + }, + { + "key": "Transfer-Encoding", + "value": "chunked", + "name": "Transfer-Encoding", + "description": "The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity." + }, + { + "key": "Vary", + "value": "Accept, Accept-Encoding", + "name": "Vary", + "description": "Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server." + }, + { + "key": "Via", + "value": "1.1 vegur", + "name": "Via", + "description": "Informs the client of proxies through which the response was sent." + }, + { + "key": "X-Powered-By", + "value": "mockbin", + "name": "X-Powered-By", + "description": "Specifies the technology (ASP.NET, PHP, JBoss, e.g.) supporting the web application (version details are often in X-Runtime, X-Version, or X-AspNet-Version)" + } + ], + "cookie": [ + { + "expires": "Invalid Date", + "httpOnly": true, + "domain": "mockbin.org", + "path": "/", + "secure": false, + "value": "dfb94a3e1f3f8a9956138e4896847caf21521013330", + "key": "__cfduid" + } + ], + "body": "{\n \"startedDateTime\": \"2018-03-14T09:06:37.443Z\",\n \"clientIPAddress\": \"106.51.70.154\",\n \"method\": \"COPY\",\n \"url\": \"https://mockbin.org/request\",\n \"httpVersion\": \"HTTP/1.1\",\n \"cookies\": {\n \"__cfduid\": \"dfb94a3e1f3f8a9956138e4896847caf21521013330\"\n },\n \"headers\": {\n \"host\": \"mockbin.org\",\n \"connection\": \"close\",\n \"accept-encoding\": \"gzip\",\n \"x-forwarded-for\": \"106.51.70.154, 172.68.255.127\",\n \"cf-ray\": \"3fb595d5facaa302-HKG\",\n \"x-forwarded-proto\": \"http\",\n \"cf-visitor\": \"{\\\"scheme\\\":\\\"https\\\"}\",\n \"cache-control\": \"no-cache\",\n \"postman-token\": \"8d5b9832-75df-432f-90a3-284dacef0478\",\n \"user-agent\": \"PostmanRuntime/7.1.1\",\n \"accept\": \"*/*\",\n \"cookie\": \"__cfduid=dfb94a3e1f3f8a9956138e4896847caf21521013330\",\n \"cf-connecting-ip\": \"106.51.70.154\",\n \"x-request-id\": \"0e41473d-5130-4a6e-968d-b2a16cda3364\",\n \"x-forwarded-port\": \"80\",\n \"via\": \"1.1 vegur\",\n \"connect-time\": \"2\",\n \"x-request-start\": \"1521018397437\",\n \"total-route-time\": \"0\",\n \"content-length\": \"0\"\n },\n \"queryString\": {},\n \"postData\": {\n \"mimeType\": \"application/octet-stream\",\n \"text\": \"\",\n \"params\": []\n },\n \"headersSize\": 637,\n \"bodySize\": 0\n}" + } + ] + } + ] +} \ No newline at end of file diff --git a/codegens/qcobjects/test/unit/validation.test.js b/codegens/qcobjects/test/unit/validation.test.js new file mode 100644 index 000000000..130dc9ca9 --- /dev/null +++ b/codegens/qcobjects/test/unit/validation.test.js @@ -0,0 +1,30 @@ +var expect = require('chai').expect, + path = require('path'), + + package = require(path.resolve('.', 'package.json')); + + +describe('package.json', function () { + it('should have com_postman_plugin object with valid properties', function () { + expect(package).to.have.property('com_postman_plugin'); + + expect(package.com_postman_plugin.type).to.equal('code_generator'); + expect(package.com_postman_plugin.lang).to.be.a('string'); + expect(package.com_postman_plugin.variant).to.be.a('string'); + expect(package.com_postman_plugin.syntax_mode).to.be.a('string'); + }); + it('should have main property with relative path to object with convert property', function () { + var languageModule; + + expect(package.main).to.be.a('string'); + + try { + languageModule = require(path.resolve('.', package.main)); + } + catch (error) { + console.error(error); + } + expect(languageModule).to.be.a('object'); + expect(languageModule.convert).to.be.a('function'); + }); +}); diff --git a/lib/assets/languageLabels.json b/lib/assets/languageLabels.json index 9709e331a..505adf823 100644 --- a/lib/assets/languageLabels.json +++ b/lib/assets/languageLabels.json @@ -16,6 +16,7 @@ "powershell": "PowerShell", "csharp": "C#", "nodejs": "NodeJs", + "qcobjects":"QCObjects", "ocaml": "OCaml", "shell": "Shell", "dart": "Dart" diff --git a/package-lock.json b/package-lock.json index 66b20281e..0293d0332 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5141,15 +5141,6 @@ "find-up": "^3.0.0" } }, - "plur": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/plur/-/plur-2.1.2.tgz", - "integrity": "sha1-dIJFLBoPUI4+NE6uwxLJHCncZVo=", - "dev": true, - "requires": { - "irregular-plurals": "^1.0.0" - } - }, "posix-character-classes": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", diff --git a/test/codegen/newman/fixtures/formdataFileCollection.json b/test/codegen/newman/fixtures/formdataFileCollection.json index e11ad193e..31f587280 100644 --- a/test/codegen/newman/fixtures/formdataFileCollection.json +++ b/test/codegen/newman/fixtures/formdataFileCollection.json @@ -1,44 +1,47 @@ { - "info": { - "_postman_id": "7da8f1cd-aeb0-420f-a989-d47db46b44b0", - "name": "Multipart/form-data FILE", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "Single/multiple file upload via form-data", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "formdata", - "formdata": [ - { + "info": { + "_postman_id": "7da8f1cd-aeb0-420f-a989-d47db46b44b0", + "name": "Multipart/form-data FILE", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Single/multiple file upload via form-data", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "formdata", + "formdata": [ + { "key": "single file", "value": "", "type": "file", - "src": "" - }, - { + "src": "/Users/jeanmachuca/Documents/postman-code-generators/dummyFile1.txt" + }, + { "key": "multiple files", "value": "", "type": "file", - "src": ["",""] + "src": [ + "/Users/jeanmachuca/Documents/postman-code-generators/dummyFile2.txt", + "/Users/jeanmachuca/Documents/postman-code-generators/dummyFile3.txt" + ] } - ] - }, - "url": { - "raw": "https://postman-echo.com/post", - "protocol": "https", - "host": [ - "postman-echo", - "com" - ], - "path": [ - "post" - ] - } - } + ] + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + } + } }, { "name": "Binary file upload via form-data", @@ -52,7 +55,7 @@ "key": "binary file", "value": "", "type": "file", - "src": "" + "src": "/Users/jeanmachuca/Documents/postman-code-generators/dummyBinaryFile" } ] }, @@ -69,5 +72,5 @@ } } } - ] + ] } \ No newline at end of file