diff --git a/README.md b/README.md index dfff2c0..17618ff 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Following actions are supported by this connector: 2. `getRecordById`: To fetch a record by id from an object. Objects supported are Addresses, Customers, Countries, Currencies, Devices, Locations, Products, Purchase Orders, Purchase Order Items, Sales Orders, Sales Order Items and Service Requests. 3. `createPurchaseOrder`: To create a new purchase order. 4. `createSalesOrder`: To create a new sales order. + 5. `createAddress`: To create a new address. ------------------------------ diff --git a/action/v1/create_address.js b/action/v1/create_address.js new file mode 100644 index 0000000..02fde1d --- /dev/null +++ b/action/v1/create_address.js @@ -0,0 +1,116 @@ +const services = require("../../services"); + +module.exports = { + + name: "create_address", + + title: "Create Address", + + description: "", + version: "v1", + + input: { + title: "createSalesOrder", + type: "object", + properties: { + "addressLine1": { + "title": "addressLine1", + "displayTitle": "Address Line 1", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + }, + "addressLine2": { + "title": "addressLine2", + "displayTitle": "Address Line 2", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + }, + "cityTown": { + "title": "cityTown", + "displayTitle": "City Town", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + }, + "postcodeZip": { + "title": "postcodeZip", + "displayTitle": "Postcode Zip", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + }, + "countyStateProvince": { + "title": "countyStateProvince", + "displayTitle": "County/State/Province", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + }, + "countryId": { + "title": "countryId", + "displayTitle": "Country Id", + "type": "string", + "description": "", + "required": true, + "minLength": 1 + } + } + }, + + output: { + title: "output", + type: "object", + properties: { + "output": { + "title": "Output", + "type": "object", + "properties": { + "id": { + "title": "id", + "displayTitle": "Id", + "type": "string", + "description": "" + } + } + } + } + }, + + mock_input: { + "addressLine1": "Software AG", + "addressLine2": "Darmstadt", + "cityTown": "Darmstadt", + "postcodeZip": "64297", + "countyStateProvince": "Germany", + "countryId": "REFCOUN-003" + }, + + execute: function (input, output) { + // to access auth info use input.auth , eg: input.auth.username + // and to return output use output callback like this output(null, { 'notice' : 'successful'}) + // var rootURL = input.auth.tenant + "addresses"; + var rootURL = input.auth.tenant; + var credentials = input.auth.username + ":" + input.auth.password; + var requestBody = + { + "input": { + "addressLine1": input.addressLine1, + "addressLine2": input.addressLine2, + "cityTown": input.cityTown, + "postcodeZip": input.postcodeZip, + "countyStateProvince": input.countyStateProvince, + "countryId": input.countryId + } + }; + var option = services.getOptionsForCreateRequest(rootURL, 'addresses', credentials, requestBody); //reusable function in services.js + services.makeHttpRequest(option, output); //reusable function in services.js + } + +} diff --git a/action/v1/create_purchase_order.js b/action/v1/create_purchase_order.js index c247024..81db8d9 100644 --- a/action/v1/create_purchase_order.js +++ b/action/v1/create_purchase_order.js @@ -4,7 +4,7 @@ module.exports = { name: "create_purchase_order", - title: "createPurchaseOrder", + title: "Create Purchase Order", description: "", version: "v1", @@ -77,7 +77,8 @@ module.exports = { execute: function (input, output) { // to access auth info use input.auth , eg: input.auth.username // and to return output use output callback like this output(null, { 'notice' : 'successful'}) - var rootURL = input.auth.tenant + "purchaseorders"; + // var rootURL = input.auth.tenant + "purchaseorders"; + var rootURL = input.auth.tenant; var credentials = input.auth.username + ":" + input.auth.password; var requestBody = { @@ -87,7 +88,7 @@ module.exports = { "products": input.products } }; - var option = services.getOptionsForCreateRequest(rootURL, credentials, requestBody); //reusable function in services.js + var option = services.getOptionsForCreateRequest(rootURL, 'purchaseorders', credentials, requestBody); //reusable function in services.js services.makeHttpRequest(option, output); //reusable function in services.js } diff --git a/action/v1/create_sales_order.js b/action/v1/create_sales_order.js index 51c4d15..c86670f 100644 --- a/action/v1/create_sales_order.js +++ b/action/v1/create_sales_order.js @@ -4,7 +4,7 @@ module.exports = { name: "create_sales_order", - title: "createSalesOrder", + title: "Create Sales Order", description: "", version: "v1", @@ -90,7 +90,8 @@ module.exports = { execute: function (input, output) { // to access auth info use input.auth , eg: input.auth.username // and to return output use output callback like this output(null, { 'notice' : 'successful'}) - var rootURL = input.auth.tenant + "salesorders"; + // var rootURL = input.auth.tenant + "salesorders"; + var rootURL = input.auth.tenant; var credentials = input.auth.username + ":" + input.auth.password; var requestBody = { @@ -103,7 +104,7 @@ module.exports = { "products": input.products } }; - var option = services.getOptionsForCreateRequest(rootURL, credentials, requestBody); //reusable function in services.js + var option = services.getOptionsForCreateRequest(rootURL, 'salesorders', credentials, requestBody); //reusable function in services.js services.makeHttpRequest(option, output); //reusable function in services.js } diff --git a/action/v1/get_record_by_id.js b/action/v1/get_record_by_id.js index 17d1118..bdaf703 100644 --- a/action/v1/get_record_by_id.js +++ b/action/v1/get_record_by_id.js @@ -5,13 +5,13 @@ module.exports = { name: "get_record_by_id", - title: "getRecordById", + title: "Get Record By Id", description: "", version: "v1", input: { - title: "getRecordById", + title: "Get Record By Id", type: "object", properties: { object: { @@ -46,9 +46,8 @@ module.exports = { execute: function (input, output) { var objectString = utils.removeSpacesAndLowerCase(input.object); //reusable function in utils.js var resource = utils.pluralizeNoun(objectString); //reusable function in utils.js - var rootURL = input.auth.tenant + resource + "/" + input.id; var credentials = input.auth.username + ":" + input.auth.password; - var option = services.getOptionsForGetRequest(rootURL, credentials); //reusable function in services.js + var option = services.getOptionsForGetRequest(input.auth.tenant, `${resource}/${input.id}`, credentials); //reusable function in services.js services.makeHttpRequest(option, output); //reusable function in services.js } diff --git a/action/v1/get_records.js b/action/v1/get_records.js index 81fc5a7..baf125d 100644 --- a/action/v1/get_records.js +++ b/action/v1/get_records.js @@ -5,13 +5,13 @@ module.exports = { name: "get_records", - title: "getRecords", + title: "Get Records", description: "", version: "v1", input: { - title: "getRecords", + title: "Get Records", type: "object", properties: { object: { @@ -53,9 +53,9 @@ module.exports = { // and to return output use output callback like this output(null, { 'notice' : 'successful'}) var objectString = utils.removeSpacesAndLowerCase(input.object); //reusable function in utils.js var resource = utils.pluralizeNoun(objectString); //reusable function in utils.js - var rootURL = input.auth.tenant + resource; var credentials = input.auth.username + ":" + input.auth.password; - var option = services.getOptionsForGetRequest(rootURL, credentials); //reusable function in services.js + var option = services.getOptionsForGetRequest(input.auth.tenant, resource, credentials); //reusable function in services.js + // var option = services.getOptionsForGetRequest(rootURL, credentials); //reusable function in services.js services.makeHttpRequest(option, output); //reusable function in services.js } diff --git a/authentication.js b/authentication.js index a2e9d7c..64084a4 100644 --- a/authentication.js +++ b/authentication.js @@ -1,8 +1,10 @@ -var request = require('request'); - module.exports = { label: 'Connect to Basic', - mock_input: {}, + mock_input: { + "tenant": "", + "username": "", + "password": "" + }, input: { type: "object", properties: { diff --git a/index.json b/index.json index 966c57a..c1483ee 100644 --- a/index.json +++ b/index.json @@ -6,9 +6,10 @@ "/v1/get_records", "/v1/get_record_by_id", "/v1/create_purchase_order", - "/v1/create_sales_order" + "/v1/create_sales_order", + "/v1/create_address" ], "version": 1, "auth_type": "custom", "doc_link": "" -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 004ca64..200985c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,392 +12,73 @@ "lodash": "4.17.15" } }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==" - }, - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA==" - }, - "asn1": { - "version": "0.1.11", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz", - "integrity": "sha512-Fh9zh3G2mZ8qM/kwsiKwL2U2FmXxVsboP4x1mXjnhKHv3SmzaBZoYvxEQJz/YS2gnCgd8xlAVWcZnQyC9qZBsA==" - }, - "assert-plus": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz", - "integrity": "sha512-brU24g7ryhRwGCI2y+1dGQmQXiZF7TtIj583S96y0jjdajIe6wn8BuXyELYhvD22dtIxDQVFk04YTJwwdwOYJw==" - }, - "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw==" - }, - "aws-sign2": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz", - "integrity": "sha512-oqUX0DM5j7aPWPCnpWebiyNIj2wiNI87ZxnOMoGv0aE4TGlBy2N+5iWc6dQ/NOKZaBD2W6PVz8jtOGkWzSC5EA==" - }, - "bl": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/bl/-/bl-0.9.5.tgz", - "integrity": "sha512-njlCs8XLBIK7LCChTWfzWuIAxkpmmLXcL7/igCofFT1B039Sz0IPnAmosN5QaO22lU4qr8LcUz2ojUlE6pLkRQ==", - "requires": { - "readable-stream": "~1.0.26" - } - }, - "bluebird": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.11.0.tgz", - "integrity": "sha512-UfFSr22dmHPQqPP9XWHRhq+gWnHCYguQGkXQlbyPtW5qTnhFWA8/iXg765tH0cAjy7l/zPJ1aBTO0g5XgA7kvQ==" - }, - "boom": { - "version": "2.10.1", - "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "integrity": "sha512-KbiZEa9/vofNcVJXGwdWWn25reQ3V3dHBWbS07FTF3/TOehLnm9GEhJV4T6ZvGPkShRpmUqYwnaCrkj0mRnP6Q==", - "requires": { - "hoek": "2.x.x" - } - }, - "caseless": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.9.0.tgz", - "integrity": "sha512-6msL6rlJApxKoPTh2QkZF+pn7/4fqQZAJb8s5noLh/GQxFGnGYfvFaz0JGNFOip/JBM3oP3RjCdwyc4uDXWJwQ==" - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A==", - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "combined-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", - "integrity": "sha512-qfexlmLp9MyrkajQVyjEDb0Vj+KhRgR/rxLiVhaihlT+ZkX0lReqtH6Ack40CvMDERR4b5eFp3CreskpBs1Pig==", - "requires": { - "delayed-stream": "0.0.5" - } - }, - "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" - }, - "core-util-is": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" - }, - "cryptiles": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "integrity": "sha512-FFN5KwpvvQTTS5hWPxrU8/QE4kQUc6uwZcrnlMBN82t1MgAtq8mnoDwINBly9Tdr02seeIIhtdF+UH1feBYGog==", - "requires": { - "boom": "2.x.x" - } - }, - "ctype": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz", - "integrity": "sha512-T6CEkoSV4q50zW3TlTHMbzy1E5+zlnNcY+yb7tWVYlTwPhx9LpnfAkd4wecpWknDyptp4k97LUZeInlf6jdzBg==" - }, - "delayed-stream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz", - "integrity": "sha512-v+7uBd1pqe5YtgPacIIbZ8HuHeLFVNe4mUEyFDXL6KiqzEykjbw+5mXZXpGFgNVasdL4jWKgaKIXrEHiynN1LA==" - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==" - }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==" - }, - "form-data": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-0.2.0.tgz", - "integrity": "sha512-LkinaG6JazVhYj2AKi67NOIAhqXcBOQACraT0WdhWW4ZO3kTiS0X7C1nJ1jFZf6wak4bVHIA/oOzWkh2ThAipg==", - "requires": { - "async": "~0.9.0", - "combined-stream": "~0.0.4", - "mime-types": "~2.0.3" - } - }, - "generate-function": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", - "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", - "requires": { - "is-property": "^1.0.2" - } - }, - "generate-object-property": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", - "integrity": "sha512-TuOwZWgJ2VAMEGJvAyPWvpqxSANF0LDpmyHauMjFYzaACvn+QTT/AZomvPCzVBV7yDN3OmwHQ5OvHaeLKre3JQ==", - "requires": { - "is-property": "^1.0.0" - } - }, - "har-validator": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-1.8.0.tgz", - "integrity": "sha512-0+M2lRG5aXVEFwZZ2tUeRVBZT5AxViug9y94qquvQaHHVoL9ydL86aJvI3K28rwoD+DL15DzAgWtPCXNhdTKAQ==", - "requires": { - "bluebird": "^2.9.30", - "chalk": "^1.0.0", - "commander": "^2.8.1", - "is-my-json-valid": "^2.12.0" - } - }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg==", - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "hawk": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/hawk/-/hawk-2.3.1.tgz", - "integrity": "sha512-Pnn5Bomr1ypnBHCwhsnj+5zhP3nel9ZPa9wdzFoanaN5+1/g5dtDfBZVVZR112sfYiAftUTFczmiWGkuG0SkSQ==", - "requires": { - "boom": "2.x.x", - "cryptiles": "2.x.x", - "hoek": "2.x.x", - "sntp": "1.x.x" - } - }, - "hoek": { - "version": "2.16.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "integrity": "sha512-V6Yw1rIcYV/4JsnggjBU0l4Kr+EXhpwqXRusENU1Xx6ro00IHPHYNynCuBTOZAPlr3AAmLvchH9I7N/VUdvOwQ==" - }, - "http-signature": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", - "integrity": "sha512-coK8uR5rq2IMj+Hen+sKPA5ldgbCc1/spPdKCL1Fw6h+D0s/2LzMcRK0Cqufs1h0ryx/niwBHGFu8HC3hwU+lA==", - "requires": { - "asn1": "0.1.11", - "assert-plus": "^0.1.5", - "ctype": "0.5.3" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "is-my-ip-valid": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-my-ip-valid/-/is-my-ip-valid-1.0.1.tgz", - "integrity": "sha512-jxc8cBcOWbNK2i2aTkCZP6i7wkHF1bqKFrwEHuN5Jtg5BSaZHUZQ/JTOJwoV41YvHnOaRyWWh72T/KvfNz9DJg==" - }, - "is-my-json-valid": { - "version": "2.20.6", - "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.20.6.tgz", - "integrity": "sha512-1JQwulVNjx8UqkPE/bqDaxtH4PXCe/2VRh/y3p99heOV87HG4Id5/VfDswd+YiAfHcRTfDlWgISycnHuhZq1aw==", - "requires": { - "generate-function": "^2.0.0", - "generate-object-property": "^1.1.0", - "is-my-ip-valid": "^1.0.0", - "jsonpointer": "^5.0.0", - "xtend": "^4.0.0" - } - }, - "is-property": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", - "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==" - }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==" - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==" - }, - "jsonpointer": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", - "integrity": "sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==" + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "axios": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.0.tgz", + "integrity": "sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + } + } + }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" }, "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, - "mime-db": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.12.0.tgz", - "integrity": "sha512-5aMAW7I4jZoZB27fXRuekqc4DVvJ7+hM8UcWrNj2mqibE54gXgPSonBYBdQW5hyaVNGmiYjY0ZMqn9fBefWYvA==" - }, - "mime-types": { - "version": "2.0.14", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.14.tgz", - "integrity": "sha512-2ZHUEstNkIf2oTWgtODr6X0Cc4Ns/RN/hktdozndiEhhAC2wxXejF1FH0XLHTEImE9h6gr/tcnr3YOnSGsxc7Q==", - "requires": { - "mime-db": "~1.12.0" - } - }, - "node-uuid": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz", - "integrity": "sha512-TkCET/3rr9mUuRp+CpO7qfgT++aAxfDRaalQhwPFzI9BY/2rCDn6OfpZOVggi1AXfTPpfkTrg5f5WQx5G1uLxA==" - }, - "oauth-sign": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.6.0.tgz", - "integrity": "sha512-E65G/AGfoCE6FILW9X+4cfJu27PNIi40brTmDmnrWIjOdPaaJSNti1XZ/+WzFkyIdMxYk0/WtwGNiQr6puZGWQ==" - }, - "psl": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", - "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" - }, - "punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==" - }, - "qs": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-2.4.2.tgz", - "integrity": "sha512-Ur2glV49dt6jknphzkWeLUNCy7pmwGxGaEJuuxVVBioSwQzT00cZPLEtRqr4cg/iO/6N+RbfB0lFD2EovyeEng==" - }, - "querystringify": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", - "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" - }, - "readable-stream": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", - "integrity": "sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - }, - "request": { - "version": "2.55.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.55.0.tgz", - "integrity": "sha512-tmHyusPYdblyvhGzDxPtDGOHWnP2h3dR9M5yO0UC5ndGGx0nRpOU+4c8bcv7utMxB7AakrE9p4B0CsqUBxYyyA==", - "requires": { - "aws-sign2": "~0.5.0", - "bl": "~0.9.0", - "caseless": "~0.9.0", - "combined-stream": "~0.0.5", - "forever-agent": "~0.6.0", - "form-data": "~0.2.0", - "har-validator": "^1.4.0", - "hawk": "~2.3.0", - "http-signature": "~0.10.0", - "isstream": "~0.1.1", - "json-stringify-safe": "~5.0.0", - "mime-types": "~2.0.1", - "node-uuid": "~1.4.0", - "oauth-sign": "~0.6.0", - "qs": "~2.4.0", - "stringstream": "~0.0.4", - "tough-cookie": ">=0.12.0", - "tunnel-agent": "~0.4.0" - } - }, - "requires-port": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" - }, - "sntp": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "integrity": "sha512-7bgVOAnPj3XjrKY577S+puCKGCRlUrcrEdsMeRXlg9Ghf5df/xNi6sONUa43WrHUd3TjJBF7O04jYoiY0FVa0A==", - "requires": { - "hoek": "2.x.x" - } - }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" - }, - "stringstream": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz", - "integrity": "sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA==" - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==" - }, - "tough-cookie": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", - "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", - "requires": { - "psl": "^1.1.33", - "punycode": "^2.1.1", - "universalify": "^0.2.0", - "url-parse": "^1.5.3" - } - }, - "tunnel-agent": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz", - "integrity": "sha512-e0IoVDWx8SDHc/hwFTqJDQ7CCDTEeGhmcT9jkWJjoGQSpgBz20nAMr80E3Tpk7PatJ1b37DQDgJR3CNSzcMOZQ==" - }, - "universalify": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", - "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==" - }, - "url-parse": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", - "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", - "requires": { - "querystringify": "^2.1.1", - "requires-port": "^1.0.0" - } - }, - "xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" } } } diff --git a/package.json b/package.json index bcfebb8..f02367a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "description": "ApplicationSimulator", "dependencies": { - "request": "2.55.0", - "@webmethodsio/cli-sdk": "*" + "@webmethodsio/cli-sdk": "*", + "axios": "^1.5.0" } } diff --git a/services.js b/services.js index fa77be7..658fc72 100644 --- a/services.js +++ b/services.js @@ -1,49 +1,53 @@ -function getOptionsForGetRequest(rootURL, credentials) { +function getOptionsForGetRequest(rootURL, resource, credentials) { // reusable function to return values required for making an HTTP GET request to Application Simulator return { - method: "GET", + method: 'GET', + baseURL: rootURL, + url: resource, headers: { "Content-Type": "application/json", Authorization: "Basic " + Buffer.from(credentials).toString("base64"), - }, - url: rootURL, - qs: {}, - }; + } + } } -function getOptionsForCreateRequest(rootURL, credentials, requestBody) { +function getOptionsForCreateRequest(rootURL, resource, credentials, requestBody) { // reusable function to return values required for making an HTTP GET request to Application Simulator return { - method: "POST", + method: 'POST', + baseURL: rootURL, + url: resource, headers: { "Content-Type": "application/json", Authorization: "Basic " + Buffer.from(credentials).toString("base64"), }, - - url: rootURL, - body: requestBody, - json: true, - qs: {}, - }; + data: requestBody + } } function makeHttpRequest(option, output) { // reusable function to make an HTTP Request - var request = require("request"); - request(option, function (error, response, body) { - if (error) { - output(error); - } - else if (response.statusCode == 401) { - output("Invalid credentials"); - } - else if (response.statusCode >= 200 || response.statusCode == 201) { - output(null, body); - } - else { - output("Something went wrong. Please check the input parameters or contact global presales team if the issue persists."); - } - }); + const axios = require('axios'); + try { + axios.request(option) + .then(function (response) { + if (response.status == 401) { + return output("Invalid credentials"); + } else if (response.status >= 200 || response.status == 201) { + return output(null, response.data); + } else { + return output({ + "message": "Something went wrong. Please check the input parameters or contact global presales team if the issue persists.", + 'text': response.text + }); + } + }) + .catch(function (error) { + return output({ "error": error }); + }); + } catch (error) { + return output({ "error": error }); + } }