EQWorks / widget-studio

Widget-creating tool for charts, maps, tables, stats
https://eqworks.github.io/widget-studio/
2 stars 3 forks source link

[G2M] stories/sample-data - split and obfuscate sensitive data #204

Closed woozyking closed 1 year ago

woozyking commented 1 year ago

the following script is used to split out the large JS (manually converted to JSON) into data JSONs and a single index.js to load all (to stay compatible with all existing usages)

const fs = require('fs')

// used https://www.convertonline.io/convert/js-to-json to manually convert
const sampleData = require('./stories/sample-data.json')

const index = {}

const camelize = s => s.replace(/-./g, x=>x[1].toUpperCase())

// write split JSON data
Object.entries(sampleData).forEach(([k, v]) => {
  const fname = k.toLowerCase().replace(/\s/g, '-')
  const fpath = `./stories/sample-data/${fname}.json`
  fs.writeFileSync(fpath, JSON.stringify(v, null, 2))
  index[k] = {
    fname,
    obj: camelize(fname),
  }
})

// index.js content
let indexJS = ''
// import statements, consider the locations are the same as index.js
Object.values(index).forEach(({ fname, obj }) => {
  indexJS += `import ${obj} from './${fname}.json'\n`
})
// export statement
indexJS += '\nexport default {'
Object.entries(index).forEach(([k, { obj }]) => {
  indexJS += `\n  '${k}': ${obj},`
})
indexJS += '\n}\n'
// write index.js
fs.writeFileSync('./stories/sample-data/index.js', indexJS)

Another type of script (not as generic, case-by-case variations) to rename things, conceptually:

const savedQuery217 = require('./stories/sample-data/saved-query-217.json')

const { data: { results } } = savedQuery217
const index = Array.from(new Set(results.map((r) => r.poi_name)))

results.forEach((r) => {
  r.poi_name = `<BRAND ${index.findIndex((e) => e === r.poi_name) + 1}>`
})

// persist back results into original
github-actions[bot] commented 1 year ago

📚 Storybook preview (updated to 33a936dc59af88bac62a0142baf2ae6e65cf65a0)

geoerika commented 1 year ago

@woozyking These are the changes I would do:

  1. Remove queryHash & columnHash from the first part of the queries or change their values if you haven't already.
  2. execution-1591.json: remove "encrypted_consumer_id" column, also remove it from the query-> columns & columns key itself.
  3. saved-queries-217: I would remove address_line_1. same, remove as well from query-> columns & columns key itself. I think that should be all.
geoerika commented 1 year ago

@woozyking I just used this tool to clean up all the lines I wanted out of the sample data in react-maps: https://jqplay.org/


map(del(."address_label", ."address_line1", ."chain_id", ."address_line2", ."address_unit"))
woozyking commented 1 year ago

@woozyking I just used this tool to clean up all the lines I wanted out of the sample data in react-maps: https://jqplay.org/

map(del(."address_label", ."address_line1", ."chain_id", ."address_line2", ."address_unit"))

Awesome, and did the change as suggested.

geoerika commented 1 year ago

@woozyking I checked again. I would remove one more line. Should be ok with this! Thanks! execution-1519.json - account_name; also from columns & query.columns.