Skip to content

Commit 6d104bb

Browse files
authored
Merge pull request #2500 from segmentio/develop
Release 22.7.1
2 parents 76c78cc + c9c6ab0 commit 6d104bb

35 files changed

+10038
-418
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ yarn-error.log
1818

1919
# VS COde stuff
2020
.vscode*
21+
22+
# Beta lists
23+
beta-destinations.csv
24+
beta-sources.csv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

.yarn/install-state.gz

8.77 KB
Binary file not shown.

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ catalog-papi: vendor/bundle
7979
papi: vendor/bundle
8080
@node scripts/catalog_papi.js
8181

82+
# make the list of beta connections
83+
.PHONY: beta
84+
beta: vendor/bundle
85+
@node scripts/beta.js
8286

8387
.PHONY: changelog
8488
changelog: vendor/bundle

package-lock.json

+8,240
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@
5050
"check-links": "^1.1.8",
5151
"clipboard": "^2.0.8",
5252
"dotenv": "^10.0.0",
53+
"fast-csv": "^4.3.6",
5354
"glightbox": "^3.1.0",
5455
"globby": "11.0.4",
5556
"handlebars": "^4.7.7",
5657
"ora": "5.4.1",
5758
"posthtml": "^0.16.5",
5859
"posthtml-urls": "^1.0.0",
5960
"search-insights": "^2.0.3",
61+
"semver": "^7.3.5",
6062
"tap-spot": "^1.1.1",
6163
"tippy.js": "5.2.0",
6264
"typewriter": "^7.4.1",

scripts/beta.js

+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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 fastcsv = require('fast-csv')
7+
const {
8+
type
9+
} = require('os');
10+
11+
require('dotenv').config();
12+
13+
PAPI_URL = "https://api.segmentapis.com"
14+
15+
const getCatalog = async (url, page_token = "MA==") => {
16+
try {
17+
const res = await axios.get(url, {
18+
headers: {
19+
'Content-Type': 'application/json',
20+
'Authorization': `Bearer ${process.env.PAPI_TOKEN}`
21+
},
22+
data: {
23+
"pagination": {
24+
"count": 200,
25+
"cursor": page_token
26+
}
27+
}
28+
});
29+
30+
return res.data
31+
} catch (error) {
32+
console.log(error)
33+
}
34+
}
35+
36+
const slugify = (displayName) => {
37+
let slug = displayName
38+
.toLowerCase()
39+
.replace(/\s+/g, '-')
40+
.replace('-&-', '-')
41+
.replace('/', '-')
42+
.replace(/[\(\)]/g, '')
43+
.replace('.', '-')
44+
45+
if (slug === '-net') slug = 'net'
46+
if (slug === 'talon-one') slug = 'talonone'
47+
if (slug === 'roku-alpha') slug = 'roku'
48+
if (slug === 'shopify-by-littledata') slug = 'shopify-littledata'
49+
if (slug === 'talon-one') slug = 'talonone'
50+
if (slug == 'google-adwords-remarketing-lists-customer-match') slug = 'adwords-remarketing-lists'
51+
if (slug == 'canny-classic') slug = 'canny'
52+
return slug
53+
}
54+
55+
56+
const isCatalogItemBeta = (itemURL) => {
57+
try {
58+
const catalogPath = path.resolve('src', itemURL, 'index.md')
59+
if (fs.existsSync(catalogPath)) {
60+
const f = fm(fs.readFileSync(catalogPath, 'utf8'));
61+
if (f.attributes.beta) return true
62+
}
63+
return false
64+
} catch (e) {
65+
console.log(error)
66+
return false
67+
}
68+
}
69+
70+
const getUpdateTime = (itemURL) => {
71+
try {
72+
const catalogPath = path.resolve('src', itemURL, 'index.md')
73+
if (fs.existsSync(catalogPath)) {
74+
75+
const stats = fs.statSync(catalogPath)
76+
const date = stats.mtime
77+
return date.toISOString().split('T')[0]
78+
}
79+
80+
} catch (e){
81+
console.log(error)
82+
}
83+
}
84+
85+
const getSources = async () => {
86+
let sources = []
87+
let sourcesUpdated = []
88+
//let regionalSourcesUpdated = []
89+
let nextPageToken = "MA=="
90+
//let categories = new Set()
91+
//let sourceCategories = []
92+
93+
while (nextPageToken !== null) {
94+
const res = await getCatalog(`${PAPI_URL}/catalog/sources/`, nextPageToken)
95+
sources = sources.concat(res.data.sourcesCatalog)
96+
nextPageToken = res.data.pagination.next
97+
}
98+
99+
sources.sort((a, b) => {
100+
if (a.name.toLowerCase() < b.name.toLowerCase()) {
101+
return -1;
102+
}
103+
if (a.name.toLowerCase() > b.name.toLowerCase()) {
104+
return 1;
105+
}
106+
return 0;
107+
})
108+
109+
const libraryCategories = [
110+
'server',
111+
'mobile',
112+
'ott',
113+
'roku',
114+
'website'
115+
]
116+
117+
sources.forEach(source => {
118+
let slug = slugify(source.name)
119+
let mainCategory = source.categories[0] ? source.categories[0].toLowerCase() : ''
120+
121+
// determine the doc url based on the source's main category
122+
if (libraryCategories.includes(mainCategory)) {
123+
url = `connections/sources/catalog/libraries/${mainCategory}/${slug}`
124+
} else {
125+
url = `connections/sources/catalog/cloud-apps/${slug}`
126+
mainCategory = 'cloud-app'
127+
}
128+
129+
let updateTime = getUpdateTime(url)
130+
131+
let updatedSource = {
132+
id: source.id,
133+
display_name: source.name,
134+
slug,
135+
url: "https://segment.com/docs/" + url,
136+
updateTime
137+
}
138+
139+
if (isCatalogItemBeta(url)) {
140+
sourcesUpdated.push(updatedSource)
141+
}
142+
})
143+
const ws = fs.createWriteStream("beta-sources.csv");
144+
fastcsv
145+
.write(sourcesUpdated, {
146+
headers: true
147+
})
148+
.on("finish", function () {
149+
console.log("Write to CSV successfully!");
150+
})
151+
.pipe(ws);
152+
153+
}
154+
155+
const getDestinations = async () => {
156+
let destinations = []
157+
let destinationsUpdated = []
158+
let regionalDestinationsUpdated = []
159+
let destinationCategories = []
160+
let categories = new Set()
161+
let nextPageToken = "MA=="
162+
163+
while (nextPageToken !== null) {
164+
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/`, nextPageToken)
165+
destinations = destinations.concat(res.data.destinationsCatalog)
166+
nextPageToken = res.data.pagination.next
167+
}
168+
169+
destinations.sort((a, b) => {
170+
if (a.name.toLowerCase() < b.name.toLowerCase()) {
171+
return -1;
172+
}
173+
if (a.name.toLowerCase() > b.name.toLowerCase()) {
174+
return 1;
175+
}
176+
return 0;
177+
})
178+
179+
destinations.forEach(destination => {
180+
// We need to be able to keep the system slug in some cases.
181+
const slugOverrides = ['actions-google-enhanced-conversions', 'actions-google-analytics-4', 'actions-facebook-conversions-api', 'actions-friendbuy-cloud', 'sprig-web']
182+
let slug = slugify(destination.name)
183+
if (slugOverrides.includes(destination.slug)) {
184+
slug = destination.slug
185+
}
186+
// Flip the slug of Actions destinations
187+
const actionsDests = [
188+
'amplitude-actions',
189+
'slack-actions',
190+
'fullstory-actions',
191+
'friendbuy-actions'
192+
]
193+
194+
if (actionsDests.includes(slug)) {
195+
const newSlug = slug.split('-')
196+
slug = newSlug[1] + '-' + newSlug[0]
197+
}
198+
let url = `connections/destinations/catalog/${slug}`
199+
let updateTime = getUpdateTime(url)
200+
201+
let updatedDestination = {
202+
destination_id: destination.id,
203+
display_name: destination.name,
204+
slug,
205+
url: "https://segment.com/docs/" + url,
206+
updateTime
207+
}
208+
if (destination.status == 'PUBLIC_BETA') {
209+
destinationsUpdated.push(updatedDestination)
210+
//console.log(destination.name)
211+
}
212+
})
213+
const ws = fs.createWriteStream("beta-destinations.csv");
214+
fastcsv
215+
.write(destinationsUpdated, {
216+
headers: true
217+
})
218+
.on("finish", function () {
219+
console.log("Write destinations to CSV successfully!");
220+
})
221+
.pipe(ws);
222+
}
223+
224+
225+
getSources()
226+
getDestinations()

scripts/catalog_papi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const updateDestinations = async () => {
330330
let regional = ['us-west']
331331

332332
// We need to be able to keep the system slug in some cases.
333-
const slugOverrides = ['actions-google-enhanced-conversions', 'actions-google-analytics-4', 'actions-facebook-conversions-api', 'actions-friendbuy-cloud', 'sprig-web']
333+
const slugOverrides = ['actions-google-enhanced-conversions', 'actions-google-analytics-4', 'actions-facebook-conversions-api', 'actions-friendbuy-cloud', 'sprig-web', 'google-analytics']
334334
let slug = slugify(destination.name)
335335
if (slugOverrides.includes(destination.slug)) {
336336
slug = destination.slug

src/_data/catalog/destination_categories.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT
2-
# destination categories last updated 2022-02-08
2+
# destination categories last updated 2022-02-14
33
items:
44
- display_name: A/B Testing
55
slug: a-b-testing

0 commit comments

Comments
 (0)