Skip to content

Commit 72da4f7

Browse files
authored
Merge pull request #285 from segmentio/repo-sync
repo sync
2 parents 69528e3 + 13bd1bc commit 72da4f7

File tree

12 files changed

+418
-14
lines changed

12 files changed

+418
-14
lines changed

.github/Vocab/Docs/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
(?:U|u)rls?\b
1414
Adwords
1515
allowlist
16+
Amberflo
1617
Appboy
1718
blocklist
1819
boolean
Binary file not shown.
Binary file not shown.

.yarn/install-state.gz

1.54 KB
Binary file not shown.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ vendor/bundle:
154154
update:
155155
@node scripts/update.js
156156

157+
.PHONY: add-id
158+
add-id:
159+
@node scripts/add_id.js
160+
157161
.PHONY: lint
158162
lint: node_modules
159163
@echo "Checking yml files..."

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"babel-loader": "^8.2.2",
2727
"concurrently": "^6.2.1",
2828
"front-matter": "^4.0.2",
29-
"glob": "^7.1.7",
29+
"glob": "^7.2.0",
3030
"js-yaml": "^4.1.0",
3131
"remark": "^14.0.1",
3232
"remark-cli": "^10.0.0",
@@ -50,6 +50,7 @@
5050
"check-links": "^1.1.8",
5151
"clipboard": "^2.0.8",
5252
"dotenv": "^10.0.0",
53+
"enquirer": "^2.3.6",
5354
"fast-csv": "^4.3.6",
5455
"glightbox": "^3.1.0",
5556
"globby": "11.0.4",

scripts/add_id.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Purpose: Add id values to integrations that don't have them
2+
// Why it's important: We look up integration metadata by ID, rather than slug
3+
// Instructions: run `make add-id`, select the integration type, enter the slug
4+
// The script:
5+
// 1. Get's the list of public integrations from the API
6+
// 2. Checks the slug you entered for an id
7+
// 3. If there is no ID, it adds the ID retrieved from the API to the file.
8+
9+
10+
11+
const axios = require('axios');
12+
const path = require('path');
13+
const fs = require('fs');
14+
const fm = require('front-matter');
15+
const yaml = require('js-yaml');
16+
const {
17+
Select
18+
} = require('enquirer');
19+
const {
20+
AutoComplete
21+
} = require('enquirer');
22+
23+
const {
24+
type
25+
} = require('os');
26+
const {
27+
autocomplete
28+
} = require('@algolia/autocomplete-js');
29+
30+
require('dotenv').config();
31+
32+
// Here, global variables are set
33+
const PAPI_URL = "https://api.segmentapis.com"
34+
const slugOverrides = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/slugs.yml`)))
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+
for (key in slugOverrides) {
46+
let original = slugOverrides[key].original
47+
let override = slugOverrides[key].override
48+
49+
if (slug == original) {
50+
slug = override
51+
}
52+
}
53+
54+
return slug
55+
}
56+
57+
const getCatalog = async (url, page_token = "MA==") => {
58+
try {
59+
const res = await axios.get(url, {
60+
headers: {
61+
'Content-Type': 'application/json',
62+
'Authorization': `Bearer ${process.env.PAPI_TOKEN}`
63+
},
64+
data: {
65+
"pagination": {
66+
"count": 200,
67+
"cursor": page_token
68+
}
69+
}
70+
});
71+
72+
return res.data
73+
} catch (error) {
74+
console.log(error)
75+
}
76+
}
77+
78+
79+
const updateId = async () => {
80+
const type_select = new Select({
81+
name: 'int_type',
82+
message: 'What type of integration?',
83+
choices: ['sources', 'destinations']
84+
})
85+
86+
let int_type = await type_select.run()
87+
88+
89+
90+
let nextPageToken = "MA=="
91+
let integrations = []
92+
let paredIntegrations = []
93+
94+
while (nextPageToken !== undefined) {
95+
const res = await getCatalog(`${PAPI_URL}/catalog/${int_type}/`, nextPageToken)
96+
if (int_type == "sources") {
97+
integrations = integrations.concat(res.data.sourcesCatalog)
98+
} else {
99+
integrations = integrations.concat(res.data.destinationsCatalog)
100+
}
101+
nextPageToken = res.data.pagination.next
102+
}
103+
104+
105+
106+
integrations.forEach(integration => {
107+
108+
const urlParse = (slug, type) => {
109+
let url = ""
110+
if (type == "destinations") {
111+
url = `connections/destinations/catalog/${slug}`
112+
} else {
113+
const libraryCategories = [
114+
'server',
115+
'mobile',
116+
'ott',
117+
'roku',
118+
'website'
119+
]
120+
121+
let mainCategory = integration.categories[0] ? integration.categories[0].toLowerCase() : ''
122+
123+
if (libraryCategories.includes(mainCategory)) {
124+
url = `connections/sources/catalog/libraries/${mainCategory}/${slug}`
125+
} else {
126+
url = `connections/sources/catalog/cloud-apps/${slug}`
127+
mainCategory = 'cloud-app'
128+
}
129+
}
130+
131+
return url
132+
}
133+
let slug = slugify(integration.name)
134+
let url = urlParse(slug, int_type)
135+
136+
let updatedIntegration = {
137+
id: integration.id,
138+
slug,
139+
url
140+
}
141+
paredIntegrations.push(updatedIntegration)
142+
})
143+
144+
let integrationSlugs = paredIntegrations.map(a => a.slug)
145+
146+
const slug_select = new AutoComplete({
147+
name: "slug",
148+
message: "Enter the integration slug",
149+
limit: 10,
150+
initial: 2,
151+
choices: integrationSlugs
152+
153+
})
154+
155+
let slug_value = await slug_select.run()
156+
157+
let final = paredIntegrations.find(x => x.slug == slug_value)
158+
let itemURL = final.url
159+
160+
const catalogPath = path.resolve('src/', itemURL, 'index.md')
161+
if (fs.existsSync(catalogPath)) {
162+
const f = fm(fs.readFileSync(catalogPath, 'utf8'));
163+
const fmatter = f.frontmatter
164+
const re_id = new RegExp("(id: )\S*")
165+
if (!re_id.test(fmatter)) {
166+
const attr = `---\n${f.frontmatter}\nid: ${final.id}\n---\n`
167+
const body = f.body
168+
const content = attr + body
169+
fs.writeFileSync(catalogPath, content)
170+
console.log(`${final.slug} updated`)
171+
} else {
172+
console.log("integration already has an ID")
173+
}
174+
} else {
175+
console.log("can't find that integration")
176+
}
177+
}
178+
179+
updateId()

scripts/update.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ const slugify = (displayName) => {
5151
.replace(/[\(\)]/g, '')
5252
.replace('.', '-')
5353

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.
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.
5656
for (key in slugOverrides) {
5757
let original = slugOverrides[key].original
5858
let override = slugOverrides[key].override
5959

6060
if (slug == original) {
61-
console.log(original + " -> " + override)
61+
// console.log(original + " -> " + override)
6262
slug = override
6363
}
6464
}
@@ -76,11 +76,17 @@ const addIdToExisting = (integration) => {
7676
const catalogPath = path.resolve('src', itemURL, 'index.md')
7777
if (fs.existsSync(catalogPath)) {
7878
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)
79+
80+
const fmatter = f.frontmatter
81+
const re_id = new RegExp("(id: )\S*")
82+
if (!re_id.test(fmatter)) {
83+
const attr = `---\n${f.frontmatter}\nid: ${integration.id}\n---\n`
84+
const body = f.body
85+
const content = attr + body
86+
console.log(attr)
87+
fs.writeFileSync(catalogPath, content)
88+
}
89+
8490
}
8591
} catch (e) {
8692
console.log(error)
@@ -96,7 +102,7 @@ const updateSources = async () => {
96102
let sources = []
97103
let nextPageToken = "MA=="
98104

99-
while (nextPageToken !== null) {
105+
while (nextPageToken !== undefined) {
100106
const res = await getCatalog(`${PAPI_URL}/catalog/sources/`, nextPageToken)
101107
sources = sources.concat(res.data.sourcesCatalog)
102108
nextPageToken = res.data.pagination.next
@@ -119,7 +125,7 @@ const updateSources = async () => {
119125
url = `connections/sources/catalog/cloud-apps/${slug}`
120126
mainCategory = 'cloud-app'
121127
}
122-
// So, we retrieve and store only the id and the URL, which is defined in the if statement on line 116.
128+
// So, we retrieve and store only the id and the URL, which is defined in the if statement on line 116.
123129
let updatedSource = {
124130
id: source.id,
125131
url,
@@ -133,7 +139,7 @@ const updateDestinations = async () => {
133139
let destinations = []
134140
let nextPageToken = "MA=="
135141

136-
while (nextPageToken !== null) {
142+
while (nextPageToken !== undefined) {
137143
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/`, nextPageToken)
138144
destinations = destinations.concat(res.data.destinationsCatalog)
139145
nextPageToken = res.data.pagination.next

src/_includes/content/functions/runtime.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ The following dependencies are installed in the function environment by default.
2424
- [`@sendgrid/mail v7.4.7`](https://www.npmjs.com/package/@sendgrid/mail) exposed as `sendgrid.mail`
2525
- [`stripe v8.115.0`](https://www.npmjs.com/package/stripe) exposed as `stripe`
2626
- [`twilio v3.68.0`](https://www.npmjs.com/package/twilio) exposed as `twilio`
27+
- [`uuidv5 v1.0.0`](https://www.npmjs.com/package/uuidv5) exposed as `uuidv5`
2728
- [`xml v1.0.1`](https://www.npmjs.com/package/xml) exposed as `xml`
2829
- [`xml2js v0.4.23`](https://www.npmjs.com/package/xml2js) exposed as `xml2js`
30+
- [`zlib v1.0.5`](https://www.npmjs.com/package/zlib) exposed as `zlib`
2931

3032
Only the [`crypto` Node.js module](https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html ) is included (exposed as `crypto`). [Other built-in Node.js modules](https://nodejs.org/api/modules.html) are not available.
3133

0 commit comments

Comments
 (0)