diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index a98276c8..c056c252 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -1,4 +1,5 @@ const { gql } = require('apollo-server-express') +const converter = require('json-2-csv') const { GraphQLDateTime } = require('graphql-iso-date') const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json') const got = require('got') @@ -206,11 +207,14 @@ const typeDefs = gql` customers: [Customer] customer(customerId: ID!): Customer machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog] + machineLogsCsv(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): String funding: [CoinFunds] serverVersion: String! uptime: [ProcessStatus] serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog] + serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String transactions(from: Date, until: Date, limit: Int, offset: Int): [Transaction] + transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String accounts: JSONObject config: JSONObject } @@ -256,12 +260,18 @@ const resolvers = { funding: () => funding.getFunding(), machineLogs: (...[, { deviceId, from, until, limit, offset }]) => logs.simpleGetMachineLogs(deviceId, from, until, limit, offset), + machineLogsCsv: (...[, { deviceId, from, until, limit, offset }]) => + logs.simpleGetMachineLogs(deviceId, from, until, limit, offset).then(converter.json2csvAsync), serverVersion: () => serverVersion, uptime: () => supervisor.getAllProcessInfo(), serverLogs: (...[, { from, until, limit, offset }]) => serverLogs.getServerLogs(from, until, limit, offset), + serverLogsCsv: (...[, { from, until, limit, offset }]) => + serverLogs.getServerLogs(from, until, limit, offset).then(converter.json2csvAsync), transactions: (...[, { from, until, limit, offset }]) => transactions.batch(from, until, limit, offset), + transactionsCsv: (...[, { from, until, limit, offset }]) => + transactions.batch(from, until, limit, offset).then(converter.json2csvAsync), config: () => settingsLoader.loadLatestConfigOrNone(), accounts: () => settingsLoader.loadAccounts() }, diff --git a/new-lamassu-admin/src/components/LogsDownloaderPopper.js b/new-lamassu-admin/src/components/LogsDownloaderPopper.js index a5ee11f5..8e71bce8 100644 --- a/new-lamassu-admin/src/components/LogsDownloaderPopper.js +++ b/new-lamassu-admin/src/components/LogsDownloaderPopper.js @@ -185,8 +185,7 @@ const LogsDownloaderPopover = ({ name, query, args, title, getLogs }) => { return moment(date).format('YYYY-MM-DD_HH-mm') } - const text = logs.map(it => JSON.stringify(it)).join('\n') - const blob = new window.Blob([text], { + const blob = new window.Blob([logs], { type: 'text/plain;charset=utf-8' }) diff --git a/new-lamassu-admin/src/pages/MachineLogs.js b/new-lamassu-admin/src/pages/MachineLogs.js index a2a530fe..1815c141 100644 --- a/new-lamassu-admin/src/pages/MachineLogs.js +++ b/new-lamassu-admin/src/pages/MachineLogs.js @@ -33,6 +33,17 @@ const GET_MACHINES = gql` const NUM_LOG_RESULTS = 500 +const GET_MACHINE_LOGS_CSV = gql` + query MachineLogs($deviceId: ID!, $limit: Int, $from: Date, $until: Date) { + machineLogsCsv( + deviceId: $deviceId + limit: $limit + from: $from + until: $until + ) + } +` + const GET_MACHINE_LOGS = gql` query MachineLogs($deviceId: ID!, $limit: Int, $from: Date, $until: Date) { machineLogs( @@ -87,9 +98,9 @@ const Logs = () => { R.path(['machineLogs'])(logs)} + getLogs={logs => R.path(['machineLogsCsv'])(logs)} /> {saveMessage} diff --git a/new-lamassu-admin/src/pages/ServerLogs.js b/new-lamassu-admin/src/pages/ServerLogs.js index b25cc62a..1f12812f 100644 --- a/new-lamassu-admin/src/pages/ServerLogs.js +++ b/new-lamassu-admin/src/pages/ServerLogs.js @@ -59,6 +59,12 @@ const formatDate = date => { const NUM_LOG_RESULTS = 500 +const GET_CSV = gql` + query ServerData($limit: Int, $from: Date, $until: Date) { + serverLogsCsv(limit: $limit, from: $from, until: $until) + } +` + const GET_DATA = gql` query ServerData($limit: Int, $from: Date, $until: Date) { serverVersion @@ -118,9 +124,9 @@ const Logs = () => { R.path(['serverLogs'])(logs)} + getLogs={logs => R.path(['serverLogsCsv'])(logs)} /> {saveMessage} diff --git a/new-lamassu-admin/src/pages/Transactions/Transactions.js b/new-lamassu-admin/src/pages/Transactions/Transactions.js index 7e619b63..16363e28 100644 --- a/new-lamassu-admin/src/pages/Transactions/Transactions.js +++ b/new-lamassu-admin/src/pages/Transactions/Transactions.js @@ -21,6 +21,12 @@ const useStyles = makeStyles(mainStyles) const NUM_LOG_RESULTS = 1000 +const GET_TRANSACTIONS_CSV = gql` + query transactions($limit: Int, $from: Date, $until: Date) { + transactionsCsv(limit: $limit, from: $from, until: $until) + } +` + const GET_TRANSACTIONS = gql` query transactions($limit: Int, $from: Date, $until: Date) { transactions(limit: $limit, from: $from, until: $until) { @@ -142,8 +148,8 @@ const Transactions = () => { R.path(['transactions'])(logs)} + query={GET_TRANSACTIONS_CSV} + getLogs={logs => R.path(['transactionsCsv'])(logs)} /> )} diff --git a/package-lock.json b/package-lock.json index e65ab217..c2b615b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3265,6 +3265,11 @@ "mimic-response": "^1.0.0" } }, + "deeks": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/deeks/-/deeks-2.2.7.tgz", + "integrity": "sha512-pCKFxSqyY2LAQ3qKQ+y+wOG63Bb9uDmDiHUVnrTR10AP75BVo2QMlgm36G+oPpRDPrgAiw5p9d+lAxdsqOwOyA==" + }, "deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", @@ -3434,6 +3439,11 @@ "path-type": "^4.0.0" } }, + "doc-path": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/doc-path/-/doc-path-2.1.2.tgz", + "integrity": "sha512-saM17czrIb4jYLsS5728OKbCa/WQ3xVctkGiMixOHz3X1VYsRn/Q5xPMxE1A5WN+XHHLWak34mMMjmAKRgMLeA==" + }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -4985,7 +4995,7 @@ "got": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/got/-/got-7.1.0.tgz", - "integrity": "sha1-BUUP2ECU5rvqVvRRpDqcKJFmOFo=", + "integrity": "sha512-Y5WMo7xKKq1muPsxD+KmrR8DH5auG7fBdDVueZwETwV6VytKyU9OX/ddpq2/1hp1vIPvVb4T81dKQz3BivkNLw==", "requires": { "decompress-response": "^3.2.0", "duplexer3": "^0.1.4", @@ -5801,7 +5811,7 @@ "isurl": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isurl/-/isurl-1.0.0.tgz", - "integrity": "sha1-sn9PSfPNqj6kSgpbfzRi5u3DnWc=", + "integrity": "sha512-1P/yWsxPlDtn7QeRD+ULKQPaIaN6yF368GZ2vDfv0AL0NwpStafjWCDDdn0k8wgFMWpVAqG7oJhxHnlud42i9w==", "requires": { "has-to-string-tag-x": "^1.2.0", "is-object": "^1.0.1" @@ -5870,6 +5880,15 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, + "json-2-csv": { + "version": "3.7.8", + "resolved": "https://registry.npmjs.org/json-2-csv/-/json-2-csv-3.7.8.tgz", + "integrity": "sha512-2CDoU32s/RA9a9xPRVsLDgk7UMW5u2SzrdklsNDl8tmdHUWT7JN2+eUV1hn1TuxJyrJxQjEXM5K4kTTnpY5+Pw==", + "requires": { + "deeks": "2.2.7", + "doc-path": "2.1.2" + } + }, "json-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", @@ -6571,7 +6590,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "requires": { "brace-expansion": "^1.1.7" } @@ -6915,7 +6934,7 @@ "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "requires": { "are-we-there-yet": "~1.1.2", "console-control-strings": "~1.1.0", @@ -7216,7 +7235,7 @@ "p-cancelable": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz", - "integrity": "sha1-ueEjgAvOu3rBOkeb4ZW1B7mNMPo=" + "integrity": "sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw==" }, "p-defer": { "version": "1.0.0", diff --git a/package.json b/package.json index 6c50ab80..f49490ec 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "graphql-type-json": "^0.3.1", "helmet": "^3.8.1", "inquirer": "^5.2.0", + "json-2-csv": "^3.7.8", "kraken-api": "github:DeX3/npm-kraken-api", "libphonenumber-js": "^1.7.38", "lnd-async": "^1.8.0",