From 6a47536c6db94650f4447aec12eea16f48d033a5 Mon Sep 17 00:00:00 2001 From: lokey Date: Wed, 2 Jun 2021 06:42:00 +0530 Subject: [PATCH 1/5] Add endpoint for loading and saving config to the backend --- server/index.js | 52 +++++++++++++++++++++++++++++++++++++++++---- server/package.json | 1 + 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index 4f4975e..f8281bd 100644 --- a/server/index.js +++ b/server/index.js @@ -11,14 +11,11 @@ const app = express(); app.use(express.static(path.join(__dirname, '../build'))); -app.get('/*', function (req, res) { - res.sendFile(path.join(__dirname, '../build', 'index.html')); -}); - // app.use(basicAuth({ // users: { [adminUser]: adminPassword } // })) + app.use(express.json()) @@ -28,4 +25,51 @@ app.post('/saveToFile', function (req, res) { res.send('Saved to file'); }); +const loadJSONFile = (path) => { + if (fs.existsSync(path)) { + return JSON.parse(fs.readFileSync(path, 'utf8')); + } else { + return "{}"; + } +} + +app.get('/loadConnections', function(req, res) { + connections = loadJSONFile('./connections.json'); + res.send({connections}); +}); + +app.get('/loadSources', function(req, res) { + sources = loadJSONFile('./sources.json'); + res.send({sources}); +}); + +app.get('/loadDestinations', function(req, res) { + destinations = loadJSONFile('./destinations.json'); + res.send({destinations}); +}); + + +app.post('/saveConnections', function (req, res) { + const connectionsSavePath = './connections.json'; + fs.writeFileSync(connectionsSavePath, JSON.stringify(req.body.connections)); + res.send('Saved connections to file'); +}); + +app.post('/saveDestinations', function (req, res) { + const destinationsSavePath = './destinations.json'; + fs.writeFileSync(destinationsSavePath, JSON.stringify(req.body.destinations)); + res.send('Saved destinations to file'); +}); + +app.post('/saveSources', function (req, res) { + const sourcesSavePath = './sources.json'; + fs.writeFileSync(sourcesSavePath, JSON.stringify(req.body.sources)); + res.send('Saved sources to file'); +}); + + +app.get('/*', function (req, res) { + res.sendFile(path.join(__dirname, '../build', 'index.html')); +}); + app.listen(9000); \ No newline at end of file diff --git a/server/package.json b/server/package.json index 51a7522..04b793c 100644 --- a/server/package.json +++ b/server/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "start": "node index.js", + "start-dev": "nodemon index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", From e502898dc0466442befd7ddcfe56c17ac5c5384b Mon Sep 17 00:00:00 2001 From: lokey Date: Wed, 2 Jun 2021 06:42:32 +0530 Subject: [PATCH 2/5] Add support for file based persistence --- src/components/home.tsx | 6 +++--- src/components/icons/sourceIcon.tsx | 2 +- src/services/config.ts | 7 +++++++ src/stores/connections.ts | 26 +++++++++++++++++------ src/stores/destinationsList.ts | 32 +++++++++++++++++++++-------- src/stores/sourcesList.ts | 25 ++++++++++++++++------ 6 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 src/services/config.ts diff --git a/src/components/home.tsx b/src/components/home.tsx index 988b58a..37f5e7a 100644 --- a/src/components/home.tsx +++ b/src/components/home.tsx @@ -112,9 +112,9 @@ class Home extends Component { sourceDefinitionsListStore, destinationDefsListStore, } = this.props; - sourcesListStore.loadAndSave(); - destinationsListStore.loadAndSave(); - connectionsStore.loadAndSave(); + await sourcesListStore.loadAndSave(); + await destinationsListStore.loadAndSave(); + await connectionsStore.loadAndSave(); await Promise.all([ sourceDefinitionsListStore.getSourceDefinitions(), destinationDefsListStore.getDestinationDefs(), diff --git a/src/components/icons/sourceIcon.tsx b/src/components/icons/sourceIcon.tsx index 3d7359a..df4b884 100644 --- a/src/components/icons/sourceIcon.tsx +++ b/src/components/icons/sourceIcon.tsx @@ -7,7 +7,7 @@ import { ReactComponent as ClickHouse } from '@svg/clickhouse.svg'; import { ReactComponent as Extole } from '@svg/extole.svg'; import { ReactComponent as FacebookAds } from '@svg/facebook_ads.svg'; import { ReactComponent as Flutter } from '@svg/flutter.svg'; -import { ReactComponent as FreshDesk } from '@svg/freshDesk.svg'; +import { ReactComponent as FreshDesk } from '@svg/freshdesk.svg'; import { ReactComponent as GoogleAdwords } from '@svg/googleads.svg'; import { ReactComponent as GoogleAnalytics } from '@svg/googleanalytics.svg'; import { ReactComponent as GoogleSearchConsole } from '@svg/google_search_console.svg'; diff --git a/src/services/config.ts b/src/services/config.ts new file mode 100644 index 0000000..7e78e5a --- /dev/null +++ b/src/services/config.ts @@ -0,0 +1,7 @@ +export interface IConfig { + persistanceMode: string; +} + +export const config: IConfig = { + persistanceMode: process.env.REACT_APP_PERSISTANCE_MODE || 'localStorage' +} \ No newline at end of file diff --git a/src/stores/connections.ts b/src/stores/connections.ts index eb1f360..fe555a2 100644 --- a/src/stores/connections.ts +++ b/src/stores/connections.ts @@ -3,6 +3,8 @@ import { action, observable, trace, autorun, set, toJS } from 'mobx'; import { IRootStore } from '.'; import { ISourceStore } from './source'; import { IDestinationStore } from './destination'; +import { apiServerCaller } from '@services/apiCaller'; +import { config } from '@services/config'; export interface IConnectionsStore { connections: ISourceConnections; @@ -40,8 +42,8 @@ export class ConnectionsStore implements IConnectionsStore { this.loadAndSave(); } - public loadAndSave() { - this.load(); + public async loadAndSave() { + await this.load(); autoSave(this, this.save.bind(this)); } @@ -51,11 +53,19 @@ export class ConnectionsStore implements IConnectionsStore { return connectionsStore; } - public load() { - const connectionsStore = localStorage.getItem('connectionsStore'); - if (connectionsStore) { + public async load() { + let connectionsStore; + if (config.persistanceMode === 'file') { + const resp = await apiServerCaller().get('/loadConnections'); + connectionsStore = resp.data.connections; + console.log('connectionsStore', connectionsStore, resp.data); + } else { + connectionsStore = localStorage.getItem('connectionsStore'); + } + if (connectionsStore && connectionsStore !== '{}') { const store: IConnectionsStore = JSON.parse(connectionsStore); set(this, store); + console.log(toJS(this.rootStore)); } } @@ -64,7 +74,11 @@ export class ConnectionsStore implements IConnectionsStore { } public save(json: string) { - localStorage.setItem('connectionsStore', json); + if (config.persistanceMode === 'file') { + apiServerCaller().post('/saveConnections', { connections: json }); + } else { + localStorage.setItem('connectionsStore', json); + } } @action.bound diff --git a/src/stores/destinationsList.ts b/src/stores/destinationsList.ts index c9a49a2..da2372c 100644 --- a/src/stores/destinationsList.ts +++ b/src/stores/destinationsList.ts @@ -5,6 +5,8 @@ import { DestinationStore, IDestinationStore } from './destination'; import { ISourceStore } from './source'; import KSUID from 'ksuid'; import { RootStore } from './index'; +import { apiServerCaller } from '@services/apiCaller'; +import { config } from '@services/config'; export interface IDestinationsListStore { destinations: IDestinationStore[]; @@ -52,8 +54,8 @@ export class DestinationsListStore implements IDestinationsListStore { this.destinations = destinations; } - public loadAndSave() { - this.load(); + public async loadAndSave() { + await this.load(); autoSave(this, this.save.bind(this)); } @@ -68,13 +70,20 @@ export class DestinationsListStore implements IDestinationsListStore { return destinationsListStore; } - public load() { - const destinationsListStore = localStorage.getItem('destinationsListStore'); - if (destinationsListStore) { + public async load() { + let destinationsListStore; + if (config.persistanceMode === 'file') { + const resp = await apiServerCaller().get('/loadDestinations'); + destinationsListStore = resp.data.destinations; + } else { + destinationsListStore = localStorage.getItem('destinationsListStore'); + } + if (destinationsListStore && destinationsListStore !== '{}') { const store: IDestinationsListStore = JSON.parse(destinationsListStore); this.destinations = store.destinations.map( destination => new DestinationStore(destination, this.rootStore), ); + console.log(toJS(this.rootStore)); } } public loadImportedFile(destinations: any) { @@ -84,7 +93,11 @@ export class DestinationsListStore implements IDestinationsListStore { } public save(json: string) { - localStorage.setItem('destinationsListStore', json); + if (config.persistanceMode === 'file') { + apiServerCaller().post('/saveDestinations', { destinations: json }); + } else { + localStorage.setItem('destinationsListStore', json); + } } @action.bound @@ -99,9 +112,10 @@ export class DestinationsListStore implements IDestinationsListStore { config: dest.config, name: dest.name, enabled: true, - destinationDefinition: this.rootStore.destinationDefsListStore.getDestinationDef( - dest.destinationDefinitionId, - ), + destinationDefinition: + this.rootStore.destinationDefsListStore.getDestinationDef( + dest.destinationDefinitionId, + ), id: KSUID.randomSync().string, createdAt: Date(), updatedAt: Date(), diff --git a/src/stores/sourcesList.ts b/src/stores/sourcesList.ts index b7d17bd..2a8bbbd 100644 --- a/src/stores/sourcesList.ts +++ b/src/stores/sourcesList.ts @@ -2,6 +2,8 @@ import { IRootStore } from '@stores/index'; import { ISourceStore, SourceStore } from '@stores/source'; import { action, autorun, observable, set, toJS } from 'mobx'; import KSUID from 'ksuid'; +import { apiServerCaller } from '@services/apiCaller'; +import { config } from '@services/config'; export interface ISourcesListStore { sources: ISourceStore[]; @@ -41,8 +43,8 @@ export class SourcesListStore implements ISourcesListStore { this.rootStore = rootStore; } - public loadAndSave() { - this.load(); + public async loadAndSave() { + await this.load(); autoSave(this, this.save.bind(this)); } @@ -55,9 +57,16 @@ export class SourcesListStore implements ISourcesListStore { return sourcesListStore; } - public load() { - const sourcesListStore = localStorage.getItem('sourcesListStore'); - if (sourcesListStore) { + public async load() { + let sourcesListStore; + if (config.persistanceMode === 'file') { + const resp = await apiServerCaller().get('/loadSources'); + sourcesListStore = resp.data.sources; + } else { + sourcesListStore = localStorage.getItem('sourcesListStore'); + } + console.log('sourcesListStore', sourcesListStore); + if (sourcesListStore && sourcesListStore !== '{}') { const store: ISourcesListStore = JSON.parse(sourcesListStore); this.sources = store.sources.map( source => new SourceStore(source, this.rootStore), @@ -72,7 +81,11 @@ export class SourcesListStore implements ISourcesListStore { } public save(json: string) { - localStorage.setItem('sourcesListStore', json); + if (config.persistanceMode === 'file') { + apiServerCaller().post('/saveSources', { sources: json }); + } else { + localStorage.setItem('sourcesListStore', json); + } } @action.bound From 9005e4b017faacf7204a645eb696d05733d85f06 Mon Sep 17 00:00:00 2001 From: lokey Date: Thu, 10 Jun 2021 06:26:16 +0530 Subject: [PATCH 3/5] update dockerignore and gitignore --- .dockerignore | 13 +++++++++++++ .gitignore | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..715c26c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Items that don't need to be in a Docker image. +# Anything not used by the build system should go here. +Dockerfile +.dockerignore +.gitignore +README.md + +# Artifacts that will be built during image creation. +# This should contain all files created during `npm run build`. +build +node_modules +server/config/* +server/node_modules \ No newline at end of file diff --git a/.gitignore b/.gitignore index ba729ef..318af6e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ yarn-error.log* #amplify build/ dist/ -node_modules/ \ No newline at end of file +node_modules/ + +server/config/* \ No newline at end of file From 2828fc4d825ee49437af48e054ae100c41374b1f Mon Sep 17 00:00:00 2001 From: lokey Date: Thu, 10 Jun 2021 06:28:27 +0530 Subject: [PATCH 4/5] Add support for /sourceConfig --- server/index.js | 52 ++++++++++++++++++++------ server/package-lock.json | 42 +++++++++++++++++++++ server/package.json | 5 ++- src/components/connections/index.tsx | 11 +++++- src/components/sourceDetails/index.tsx | 34 +---------------- src/stores/source.ts | 37 ++++++++++++++++++ 6 files changed, 133 insertions(+), 48 deletions(-) diff --git a/server/index.js b/server/index.js index f8281bd..9a45901 100644 --- a/server/index.js +++ b/server/index.js @@ -1,13 +1,12 @@ const express = require('express'); const path = require('path'); const fs = require('fs'); -// const auth = require('koa-basic-auth'); -// const Router = require('koa-router'); +const fsExtra = require('fs-extra'); +const auth = require('basic-auth'); const app = express(); +require('dotenv').config() -// const basicAuth = require('express-basic-auth') -// const adminUser = process.env.ADMIN_USER || 'admin'; -// const adminPassword = process.env.ADMIN_PASSWORD || 'password'; +const CONFIG_FOLDER = process.env.CONFIG_FOLDER || '.'; app.use(express.static(path.join(__dirname, '../build'))); @@ -20,11 +19,40 @@ app.use(express.json()) app.post('/saveToFile', function (req, res) { - const configSavePath = process.env.REACT_APP_SAVE_TO_FILE_PATH || './config.json'; + const configSavePath = CONFIG_FOLDER + '/workspaceConfig.json'; fs.writeFileSync(configSavePath, JSON.stringify(req.body.workspaceConfig)); + Object.entries(req.body.sourcesConfig).forEach(([writeKey, config])=>{ + fsExtra.outputFileSync(`${CONFIG_FOLDER}/sources/${writeKey}.json`, JSON.stringify(config)); + }); res.send('Saved to file'); }); +app.get('/workspaceConfig', function (req, res) { + const configPath = CONFIG_FOLDER + '/workspaceConfig.json'; + if (fs.existsSync(configPath)) { + const workspaceConfig = JSON.parse(fs.readFileSync(configPath, 'utf8')); + res.send(workspaceConfig); + } else { + res.status(500); + res.send('Config not found'); + } +}); + + +app.get('/sourceConfig', function (req, res) { + const bearerHeader = req.headers.authorization; + const writeKey = auth.parse(bearerHeader) && auth.parse(bearerHeader).name; + + const configPath = `${CONFIG_FOLDER}/sources/${writeKey}.json`; + if (fs.existsSync(configPath)) { + const sourceConfig = JSON.parse(fs.readFileSync(configPath, 'utf8')); + res.send(sourceConfig); + } else { + res.status(500); + res.send('Config not found'); + } +}); + const loadJSONFile = (path) => { if (fs.existsSync(path)) { return JSON.parse(fs.readFileSync(path, 'utf8')); @@ -34,35 +62,35 @@ const loadJSONFile = (path) => { } app.get('/loadConnections', function(req, res) { - connections = loadJSONFile('./connections.json'); + const connections = loadJSONFile(CONFIG_FOLDER+'/connections.json'); res.send({connections}); }); app.get('/loadSources', function(req, res) { - sources = loadJSONFile('./sources.json'); + const sources = loadJSONFile(CONFIG_FOLDER+'/sources.json'); res.send({sources}); }); app.get('/loadDestinations', function(req, res) { - destinations = loadJSONFile('./destinations.json'); + const destinations = loadJSONFile(CONFIG_FOLDER+'/destinations.json'); res.send({destinations}); }); app.post('/saveConnections', function (req, res) { - const connectionsSavePath = './connections.json'; + const connectionsSavePath = CONFIG_FOLDER+'/connections.json'; fs.writeFileSync(connectionsSavePath, JSON.stringify(req.body.connections)); res.send('Saved connections to file'); }); app.post('/saveDestinations', function (req, res) { - const destinationsSavePath = './destinations.json'; + const destinationsSavePath = CONFIG_FOLDER+'/destinations.json'; fs.writeFileSync(destinationsSavePath, JSON.stringify(req.body.destinations)); res.send('Saved destinations to file'); }); app.post('/saveSources', function (req, res) { - const sourcesSavePath = './sources.json'; + const sourcesSavePath = CONFIG_FOLDER+'/sources.json'; fs.writeFileSync(sourcesSavePath, JSON.stringify(req.body.sources)); res.send('Saved sources to file'); }); diff --git a/server/package-lock.json b/server/package-lock.json index aba5322..ffbc230 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -18,6 +18,14 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "requires": { + "safe-buffer": "5.1.2" + } + }, "body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", @@ -81,6 +89,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -162,6 +175,21 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs-extra": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", + "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "graceful-fs": { + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" + }, "http-errors": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", @@ -192,6 +220,15 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -355,6 +392,11 @@ "mime-types": "~2.1.24" } }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/server/package.json b/server/package.json index 04b793c..ac1a331 100644 --- a/server/package.json +++ b/server/package.json @@ -11,6 +11,9 @@ "author": "", "license": "ISC", "dependencies": { - "express": "^4.17.1" + "basic-auth": "^2.0.1", + "dotenv": "^10.0.0", + "express": "^4.17.1", + "fs-extra": "^10.0.0" } } diff --git a/src/components/connections/index.tsx b/src/components/connections/index.tsx index 905d476..89d6314 100644 --- a/src/components/connections/index.tsx +++ b/src/components/connections/index.tsx @@ -5,6 +5,7 @@ import theme from '@css/theme'; import { IDestinationsListStore } from '@stores/destinationsList'; import { ISourceDefinitionsListStore } from '@stores/sourceDefinitionsList'; import { ISourcesListStore } from '@stores/sourcesList'; +import { ISourceStore } from '@stores/source'; import { IConnectionsStore } from '@stores/connections'; import { inject, observer } from 'mobx-react'; import React, { Component } from 'react'; @@ -93,7 +94,8 @@ class Connections extends Component { sources: [] as any, metadata: { sourceListStore: this.props.sourcesListStore.returnWithoutRootStore(), - destinationListStore: this.props.destinationsListStore.returnWithoutRootStore(), + destinationListStore: + this.props.destinationsListStore.returnWithoutRootStore(), connectionsStore: this.props.connectionsStore.returnWithoutRootStore(), version, }, @@ -137,8 +139,13 @@ class Connections extends Component { }; handleSaveWorkspaceConfig = () => { + const { sourcesListStore } = this.props; const workspaceConfig = this.buildWorkspaceConfig(); - apiServerCaller().post('/saveToFile', { workspaceConfig }); + let sourcesConfig: any = {}; + sourcesListStore.sources.forEach((source: ISourceStore) => { + sourcesConfig[source.writeKey] = source.configForSDK; + }); + apiServerCaller().post('/saveToFile', { workspaceConfig, sourcesConfig }); }; handleFileChosen = (event: any) => { diff --git a/src/components/sourceDetails/index.tsx b/src/components/sourceDetails/index.tsx index 1245d4c..38316c7 100644 --- a/src/components/sourceDetails/index.tsx +++ b/src/components/sourceDetails/index.tsx @@ -106,40 +106,8 @@ class SourceDetails extends Component { const { sources } = sourcesListStore; const source = sources.find(source => source.id === sourceId); if (source) { - const sourceConfig = { - source: { - config: source.config, - id: source.id, - name: source.name, - writeKey: source.writeKey, - enabled: source.enabled, - sourceDefinitionId: source.sourceDefinitionId, - deleted: false, - createdAt: Date(), - updatedAt: Date(), - sourceDefinition: source.sourceDef, - // Filter only useNativeSDK enabled destinations and - // includes only includeKeys (from definition) in the config - destinations: source.destinations - .filter(dest => { - return dest.config ? dest.config.useNativeSDK : false; - }) - .map(dest => { - return { - id: dest.id, - name: dest.name, - enabled: dest.enabled, - config: dest.filteredConfig(), // Very Very Important to use filterConfig instead of config - destinationDefinition: dest.destinationDefinition, - }; - }), - }, - metadata: { - version: version, - }, - }; fileDownload( - JSON.stringify(sourceConfig, null, 2), + JSON.stringify(source.configForSDK, null, 2), `${source.name}_Source_Config.json`, ); } diff --git a/src/stores/source.ts b/src/stores/source.ts index e28ff18..36c8310 100644 --- a/src/stores/source.ts +++ b/src/stores/source.ts @@ -1,3 +1,4 @@ +import { version } from '@services/version'; import { ISourceDefintion } from '@stores/sourceDefinitionsList'; import { action, computed, observable, reaction, trace } from 'mobx'; @@ -14,6 +15,7 @@ export interface ISourceStore { sourceDef: ISourceDefintion; rootStore: IRootStore; destinations: IDestinationStore[]; + configForSDK: any; setName(name: string): void; toggleEnabled(): void; } @@ -55,6 +57,41 @@ export class SourceStore implements ISourceStore { }); } + @computed get configForSDK() { + return { + source: { + config: this.config, + id: this.id, + name: this.name, + writeKey: this.writeKey, + enabled: this.enabled, + sourceDefinitionId: this.sourceDefinitionId, + deleted: false, + createdAt: Date(), + updatedAt: Date(), + sourceDefinition: this.sourceDef, + // Filter only useNativeSDK enabled destinations and + // includes only includeKeys (from definition) in the config + destinations: this.destinations + .filter(dest => { + return dest.config ? dest.config.useNativeSDK : false; + }) + .map(dest => { + return { + id: dest.id, + name: dest.name, + enabled: dest.enabled, + config: dest.filteredConfig(), // Very Very Important to use filterConfig instead of config + destinationDefinition: dest.destinationDefinition, + }; + }), + }, + metadata: { + version: version, + }, + }; + } + // useful for debugging /* reaction = reaction( () => this.rootStore.destinationsListStore.destinations, From af1a3f1d8cf7de42432e215edef418bba3be4afa Mon Sep 17 00:00:00 2001 From: lokey Date: Fri, 17 Sep 2021 17:48:45 +0530 Subject: [PATCH 5/5] Remove logs --- src/stores/connections.ts | 2 -- src/stores/destinationsList.ts | 1 - src/stores/sourcesList.ts | 1 - 3 files changed, 4 deletions(-) diff --git a/src/stores/connections.ts b/src/stores/connections.ts index fe555a2..b81444a 100644 --- a/src/stores/connections.ts +++ b/src/stores/connections.ts @@ -58,14 +58,12 @@ export class ConnectionsStore implements IConnectionsStore { if (config.persistanceMode === 'file') { const resp = await apiServerCaller().get('/loadConnections'); connectionsStore = resp.data.connections; - console.log('connectionsStore', connectionsStore, resp.data); } else { connectionsStore = localStorage.getItem('connectionsStore'); } if (connectionsStore && connectionsStore !== '{}') { const store: IConnectionsStore = JSON.parse(connectionsStore); set(this, store); - console.log(toJS(this.rootStore)); } } diff --git a/src/stores/destinationsList.ts b/src/stores/destinationsList.ts index da2372c..e33afd1 100644 --- a/src/stores/destinationsList.ts +++ b/src/stores/destinationsList.ts @@ -83,7 +83,6 @@ export class DestinationsListStore implements IDestinationsListStore { this.destinations = store.destinations.map( destination => new DestinationStore(destination, this.rootStore), ); - console.log(toJS(this.rootStore)); } } public loadImportedFile(destinations: any) { diff --git a/src/stores/sourcesList.ts b/src/stores/sourcesList.ts index 2a8bbbd..f632556 100644 --- a/src/stores/sourcesList.ts +++ b/src/stores/sourcesList.ts @@ -65,7 +65,6 @@ export class SourcesListStore implements ISourcesListStore { } else { sourcesListStore = localStorage.getItem('sourcesListStore'); } - console.log('sourcesListStore', sourcesListStore); if (sourcesListStore && sourcesListStore !== '{}') { const store: ISourcesListStore = JSON.parse(sourcesListStore); this.sources = store.sources.map(