Skip to content

Commit 1ea253b

Browse files
author
markzegarelli
authored
private beta docs support (#3104)
* Ready to deploy * script updates * PB docs * snap conversions API
1 parent 689a06d commit 1ea253b

File tree

5 files changed

+1528
-2
lines changed

5 files changed

+1528
-2
lines changed

scripts/private-destination.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
const axios = require('axios');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const fm = require('front-matter');
5+
const yaml = require('js-yaml');
6+
const {
7+
prompt
8+
} = require('enquirer');
9+
10+
require('dotenv').config();
11+
12+
13+
// Here, global variables are set
14+
const PAPI_URL = "https://api.segmentapis.com"
15+
16+
const PRIVATE_DESTINATIONS = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/destinations_private.yml`)))
17+
const privateDests = PRIVATE_DESTINATIONS.items
18+
const getCatalog = async (url, page_token = "MA==") => {
19+
try {
20+
const res = await axios.get(url, {
21+
headers: {
22+
'Content-Type': 'application/json',
23+
'Authorization': `Bearer ${process.env.PAPI_TOKEN}`
24+
},
25+
data: {
26+
"pagination": {
27+
"count": 200,
28+
"cursor": page_token
29+
}
30+
}
31+
});
32+
33+
return res.data
34+
} catch (error) {
35+
console.log(error)
36+
}
37+
}
38+
39+
const addPrivateDestination = async () => {
40+
const DEST_ID = await prompt({
41+
type: 'input',
42+
name: 'id',
43+
message: 'Enter the destination ID'
44+
})
45+
46+
const privateIds = []
47+
for (let [key] of Object.entries(privateDests)) {
48+
privateIds.push(privateDests[key].id)
49+
}
50+
51+
if (privateIds.includes(DEST_ID.id)) {
52+
console.log("This destination is already captured.")
53+
return
54+
} else {
55+
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/${DEST_ID.id}`)
56+
destination = res.data.destinationMetadata
57+
let settings = destination.options
58+
59+
settings.sort((a, b) => {
60+
if (a.name.toLowerCase() < b.name.toLowerCase()) {
61+
return -1;
62+
}
63+
if (a.name.toLowerCase() > b.name.toLowerCase()) {
64+
return 1;
65+
}
66+
return 0;
67+
})
68+
let actions = destination.actions
69+
let presets = destination.presets
70+
71+
if (destination.status == "PRIVATE_BETA") {
72+
73+
let updatePrivateDest = {
74+
id: destination.id,
75+
display_name: destination.name,
76+
name: destination.name,
77+
slug: destination.slug,
78+
previous_names: destination.previousNames,
79+
website: destination.website,
80+
status: destination.status,
81+
logo: {
82+
url: destination.logos.default
83+
},
84+
mark: {
85+
url: destination.logos.mark
86+
},
87+
methods: destination.supportedMethods,
88+
platforms: destination.supportedPlatforms,
89+
components: destination.components,
90+
browserUnbundlingSupported: destination.supportedFeatures.browserUnbundling,
91+
browserUnbundlingPublic: destination.supportedFeatures.browserUnbundlingPublic,
92+
replay: destination.supportedFeatures.replay,
93+
settings,
94+
actions,
95+
presets
96+
}
97+
98+
privateDests.push(updatePrivateDest)
99+
const options = {
100+
noArrayIndent: false
101+
}
102+
103+
output = "# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT\n"
104+
var todayDate = new Date().toISOString().slice(0, 10);
105+
output += "# destination data last updated " + todayDate + " with " + destination.name + " \n";
106+
output += yaml.dump({
107+
items: privateDests
108+
}, options)
109+
//console.log(output)
110+
fs.writeFileSync(path.resolve(__dirname, `../src/_data/catalog/destinations_private.yml`), output);
111+
} else {
112+
console.log("This destination is already public")
113+
}
114+
}
115+
116+
}
117+
118+
119+
addPrivateDestination()

0 commit comments

Comments
 (0)