|
| 1 | +const path = require('path'); |
| 2 | +const fs = require('fs'); |
| 3 | +const yaml = require('js-yaml'); |
| 4 | +const { |
| 5 | + slugify, |
| 6 | + getCatalog, |
| 7 | + getConnectionModes, |
| 8 | + isCatalogItemHidden, |
| 9 | + sanitize, |
| 10 | + doesCatalogItemExist |
| 11 | +} = require('./utilities.js'); |
| 12 | + |
| 13 | +require('dotenv').config(); |
| 14 | + |
| 15 | +const PAPI_URL = "https://api.segmentapis.com"; |
| 16 | + |
| 17 | +const regionalSupport = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/regional-support.yml`))); |
| 18 | + |
| 19 | +// This file keeps a list of known test sources that show up in the system. |
| 20 | +// Because we don't have a status value for sources, they end up showing in our catalog. |
| 21 | +// We use this below to prevent them from being written to yaml. |
| 22 | +const testSources = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/test_sources.yml`))); |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +const updateWarehouses = async () => { |
| 27 | + let warehouses = []; |
| 28 | + let nextPageToken = "MA=="; |
| 29 | + let warehousesUpdated = []; |
| 30 | + |
| 31 | + while (nextPageToken !== undefined) { |
| 32 | + const res = await getCatalog(`${PAPI_URL}/catalog/warehouses/`, nextPageToken); |
| 33 | + warehouses = warehouses.concat(res.data.warehousesCatalog); |
| 34 | + nextPageToken = res.data.pagination.next; |
| 35 | + } |
| 36 | + |
| 37 | + warehouses.sort((a, b) => { |
| 38 | + if (a.name.toLowerCase() < b.name.toLowerCase()) { |
| 39 | + return -1; |
| 40 | + } |
| 41 | + if (a.name.toLowerCase() > b.name.toLowerCase()) { |
| 42 | + return 1; |
| 43 | + } |
| 44 | + return 0; |
| 45 | + }); |
| 46 | + |
| 47 | + const regionalWarehouseEndpoints = regionalSupport.warehouses.endpoint; |
| 48 | + const regionalWarehouseRegions = regionalSupport.warehouses.region; |
| 49 | + |
| 50 | + warehouses.forEach(warehouse => { |
| 51 | + let slug = slugify(warehouse.slug); |
| 52 | + let endpoints = ['us']; |
| 53 | + let regions = ['us']; |
| 54 | + let url = `connections/storage/catalog/${slug}`; |
| 55 | + |
| 56 | + if (regionalWarehouseEndpoints.includes(slug)) { |
| 57 | + endpoints.push('eu'); |
| 58 | + } |
| 59 | + |
| 60 | + if (regionalWarehouseRegions.includes(slug)) { |
| 61 | + regions.push('eu'); |
| 62 | + } |
| 63 | + |
| 64 | + let updatedWarehouse = { |
| 65 | + id: warehouse.id, |
| 66 | + display_name: warehouse.name, |
| 67 | + url, |
| 68 | + slug, |
| 69 | + endpoints, |
| 70 | + regions |
| 71 | + }; |
| 72 | + |
| 73 | + warehousesUpdated.push(updatedWarehouse); |
| 74 | + }); |
| 75 | + |
| 76 | + const options = { |
| 77 | + noArrayIndent: true |
| 78 | + }; |
| 79 | + const todayDate = new Date().toISOString().slice(0, 10); |
| 80 | + |
| 81 | + // Create regional support YAML file |
| 82 | + let output = "# AUTOGENERATED LIST OF CONNECTIONS THAT SUPPORT REGIONAL\n"; |
| 83 | + output += "# Last updated " + todayDate + " \n"; |
| 84 | + output += yaml.dump({ |
| 85 | + warehouses: warehousesUpdated |
| 86 | + }, options); |
| 87 | + fs.writeFileSync(path.resolve(__dirname, `../src/_data/catalog/regional-supported.yml`), output); |
| 88 | + |
| 89 | + console.log("warehouses done"); |
| 90 | +}; |
| 91 | + |
| 92 | +// Execute the update functions |
| 93 | +updateWarehouses(); |
| 94 | +updateSources(); |
| 95 | +updateDestinations(); |
0 commit comments