Skip to content

Commit 8dabd89

Browse files
markzegarellistayseesongbot-docsteamkdaswaniKiara Daswani
authored
Hotfix (#2579)
* Update script ready * [netlify-build] * StratConn GA Launch Docs Updates (#2566) * StratConn GA Launch Docs Updates * Update src/connections/destinations/catalog/actions-google-enhanced-conversions/index.md * Update src/connections/destinations/catalog/facebook-pixel-server-side/index.md * Update src/connections/destinations/catalog/tiktok-conversions/index.md * Update src/connections/destinations/catalog/tiktok-conversions/index.md * Update src/connections/destinations/catalog/tiktok-conversions/index.md * Apply suggestions from code review Co-authored-by: rchinn-segment <[email protected]> * Add to tiktok doc * Update src/connections/destinations/catalog/tiktok-conversions/index.md Co-authored-by: Kiara Daswani <[email protected]> Co-authored-by: rchinn-segment <[email protected]> Co-authored-by: markzegarelli <[email protected]> * Removing date from docs (#2572) As per discussion in today's BigQuery EOL Monthly check-in! * Added clarity around what each icon means (#2574) * updates Co-authored-by: stayseesong <[email protected]> Co-authored-by: Segment Docs Robot <[email protected]> Co-authored-by: kdaswani <[email protected]> Co-authored-by: Kiara Daswani <[email protected]> Co-authored-by: rchinn-segment <[email protected]> Co-authored-by: forstisabella <[email protected]>
1 parent 0450a9f commit 8dabd89

File tree

421 files changed

+955
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+955
-693
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ vendor/bundle:
150150
@bundle config set --local path 'vendor/bundle'
151151
@bundle install
152152

153+
.PHONY: update
154+
update:
155+
@node scripts/update.js
153156

154157
.PHONY: lint
155158
lint: node_modules

scripts/catalog_papi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const doesCatalogItemExist = (item) => {
123123
if (item.status === 'PUBLIC_BETA') {
124124
betaFlag = 'beta: true\n'
125125
}
126-
content = `---\ntitle: '${item.display_name} Destination'\nhidden: true\npublished: false\n${betaFlag}---\n`
126+
content = `---\ntitle: '${item.display_name} Destination'\nhidden: true\nid: ${item.id}published: false\n${betaFlag}---\n`
127127
}
128128
fs.mkdirSync(docsPath)
129129
fs.writeFileSync(`${docsPath}/index.md`, content)
@@ -381,7 +381,7 @@ const updateDestinations = async () => {
381381
destination.supportedMethods = renameKey(destination.supportedMethods, 'pageview', 'page')
382382

383383
let updatedDestination = {
384-
destination_id: destination.id,
384+
id: destination.id,
385385
display_name: destination.name,
386386
name: destination.name,
387387
slug,

scripts/update.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// These lines are the required packages we need. These let us do things like make network requests to the Public API
2+
// and interact with the frontmatter
3+
const axios = require('axios');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const fm = require('front-matter');
7+
const yaml = require('js-yaml');
8+
const {
9+
type
10+
} = require('os');
11+
12+
require('dotenv').config();
13+
14+
// Here, global variables are set
15+
const PAPI_URL = "https://api.segmentapis.com"
16+
const slugOverrides = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/slugs.yml`)))
17+
18+
// This function connects with the Public API. It looks for the endpoint URL and a page token value.
19+
// The function is called in the updateSources and update Destination functions.
20+
// Functions let us reuse code easily. Instead of needing to write this out multiple times, I can define it once
21+
// and pass in the necessary details when I call it.
22+
const getCatalog = async (url, page_token = "MA==") => {
23+
try {
24+
const res = await axios.get(url, {
25+
headers: {
26+
'Content-Type': 'application/json',
27+
'Authorization': `Bearer ${process.env.PAPI_TOKEN}`
28+
},
29+
data: {
30+
"pagination": {
31+
"count": 200,
32+
"cursor": page_token
33+
}
34+
}
35+
});
36+
37+
return res.data
38+
} catch (error) {
39+
console.log(error)
40+
}
41+
}
42+
43+
// This function, again called by the two update functions, is what generates the slug values for each integration.
44+
// It takes the integration's Display Name and converts it to a slug.
45+
const slugify = (displayName) => {
46+
let slug = displayName
47+
.toLowerCase()
48+
.replace(/\s+/g, '-')
49+
.replace('-&-', '-')
50+
.replace('/', '-')
51+
.replace(/[\(\)]/g, '')
52+
.replace('.', '-')
53+
54+
// This is how we handle manual slug overrides right now.
55+
// If a slug appears in the slugOverrides file, we want to use the 'override' value instead.
56+
for (key in slugOverrides) {
57+
let original = slugOverrides[key].original
58+
let override = slugOverrides[key].override
59+
60+
if (slug == original) {
61+
console.log(original + " -> " + override)
62+
slug = override
63+
}
64+
}
65+
66+
return slug
67+
}
68+
69+
// This function does the actual work of adding the id value to the source and destination
70+
// Notice that the write to file step is commented out. This is to verify that the updated frontmatter
71+
// is correct before we write a whole bunch of files.
72+
// Uncomment that line and remove the line above it to run it for real.
73+
const addIdToExisting = (integration) => {
74+
let itemURL = integration.url
75+
try {
76+
const catalogPath = path.resolve('src', itemURL, 'index.md')
77+
if (fs.existsSync(catalogPath)) {
78+
const f = fm(fs.readFileSync(catalogPath, 'utf8'));
79+
const attr = `---\n${f.frontmatter}\nid: ${integration.id}\n---\n`
80+
const body = f.body
81+
const content = attr + body
82+
console.log(attr)
83+
fs.writeFileSync(catalogPath, content)
84+
}
85+
} catch (e) {
86+
console.log(error)
87+
return false
88+
}
89+
}
90+
91+
92+
// This is just a stripped down version of the updateSources() script from the catalog script.
93+
// We're retrieving less information overall, because all we care about here is the id.
94+
const updateSources = async () => {
95+
96+
let sources = []
97+
let nextPageToken = "MA=="
98+
99+
while (nextPageToken !== null) {
100+
const res = await getCatalog(`${PAPI_URL}/catalog/sources/`, nextPageToken)
101+
sources = sources.concat(res.data.sourcesCatalog)
102+
nextPageToken = res.data.pagination.next
103+
}
104+
105+
const libraryCategories = [
106+
'server',
107+
'mobile',
108+
'ott',
109+
'roku',
110+
'website'
111+
]
112+
sources.forEach(source => {
113+
let slug = slugify(source.name)
114+
let mainCategory = source.categories[0] ? source.categories[0].toLowerCase() : ''
115+
116+
if (libraryCategories.includes(mainCategory)) {
117+
url = `connections/sources/catalog/libraries/${mainCategory}/${slug}`
118+
} else {
119+
url = `connections/sources/catalog/cloud-apps/${slug}`
120+
mainCategory = 'cloud-app'
121+
}
122+
// So, we retrieve and store only the id and the URL, which is defined in the if statement on line 116.
123+
let updatedSource = {
124+
id: source.id,
125+
url,
126+
}
127+
addIdToExisting(updatedSource)
128+
})
129+
}
130+
131+
// Similar to the sources script, only for destinations.
132+
const updateDestinations = async () => {
133+
let destinations = []
134+
let nextPageToken = "MA=="
135+
136+
while (nextPageToken !== null) {
137+
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/`, nextPageToken)
138+
destinations = destinations.concat(res.data.destinationsCatalog)
139+
nextPageToken = res.data.pagination.next
140+
}
141+
142+
143+
destinations.forEach(destination => {
144+
let slug = slugify(destination.name)
145+
146+
let url = `connections/destinations/catalog/${slug}`
147+
148+
let updatedDestination = {
149+
id: destination.id,
150+
url
151+
}
152+
addIdToExisting(updatedDestination)
153+
154+
})
155+
156+
}
157+
updateDestinations()
158+
updateSources()

0 commit comments

Comments
 (0)