Skip to content

Commit 2ed8372

Browse files
author
markzegarelli
authored
Automate making Private -> Public destinations visible on site (#4515)
1 parent 65d5db6 commit 2ed8372

File tree

3 files changed

+92
-11
lines changed

3 files changed

+92
-11
lines changed

scripts/private-destination.js

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ require('dotenv').config();
1717
const PAPI_URL = "https://api.segmentapis.com"
1818

1919
const PRIVATE_DESTINATIONS = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/destinations_private.yml`)))
20+
const slugOverrides = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/slugs.yml`)))
21+
2022
const privateDests = PRIVATE_DESTINATIONS.items
2123
let private = []
2224
const getCatalog = async (url, page_token = "MA==") => {
@@ -37,25 +39,65 @@ const getCatalog = async (url, page_token = "MA==") => {
3739
return res.data
3840
} catch (err) {
3941
console.error("Error response:");
40-
console.error(err.response.data); // ***
41-
console.error(err.response.status); // ***
42+
console.error(err.response.data); // ***
43+
console.error(err.response.status); // ***
4244
console.error(err.response.headers); // ***
4345
} finally {
44-
46+
4547
}
4648
}
4749

50+
const slugify = (displayName) => {
51+
let slug = displayName
52+
.toLowerCase()
53+
.replace(/\s+/g, '-')
54+
.replace('-&-', '-')
55+
.replace('/', '-')
56+
.replace(/[\(\)]/g, '')
57+
.replace('.', '-')
58+
59+
for (key in slugOverrides) {
60+
let original = slugOverrides[key].original
61+
let override = slugOverrides[key].override
62+
63+
if (slug == original) {
64+
slug = override
65+
}
66+
}
67+
68+
return slug
69+
}
4870

4971
const checkDestinationStatus = async (id) => {
5072
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/${id}`)
5173
let destination = res.data.destinationMetadata
5274
return destination
5375
}
76+
77+
const makeDestinationPublic = async (itemURL) => {
78+
const catalogPath = path.resolve('src/', itemURL, 'index.md')
79+
const f = fm(fs.readFileSync(catalogPath, 'utf8'));
80+
const fmatter = f.attributes
81+
fmatter.private = false
82+
fmatter.hidden = false
83+
let new_fm = ""
84+
for (const property in fmatter) {
85+
if (property == "versions") {
86+
console.log(`Need to fix versions on this one`)
87+
}
88+
//console.log(`${property}: ${fmatter[property]}`);
89+
new_fm += `${property}: ${fmatter[property]}\n`
90+
}
91+
const attr = `---\n${new_fm}\n---\n`
92+
const body = f.body
93+
const content = attr + body
94+
fs.writeFileSync(catalogPath, content)
95+
}
5496
const getDestinationData = async (id) => {
5597
const res = await getCatalog(`${PAPI_URL}/catalog/destinations/${id}`)
5698
if (res == null) {
5799
return
58-
}
100+
}
59101
let destination = res.data.destinationMetadata
60102
let settings = destination.options
61103
settings.sort((a, b) => {
@@ -69,11 +111,13 @@ const getDestinationData = async (id) => {
69111
})
70112
let actions = destination.actions
71113
let presets = destination.presets
114+
let slug = slugify(destination.name)
115+
let url = `connections/destinations/catalog/${slug}`
72116

73117
// Force screen method into supportedMethods object
74118
destination.supportedMethods.screen = false
75119
// Set it true for LiveLike, per request
76-
if (destination.id == '63e42b47479274407b671071'){
120+
if (destination.id == '63e42b47479274407b671071') {
77121
destination.supportedMethods.screen = true
78122
}
79123

@@ -93,8 +137,9 @@ const getDestinationData = async (id) => {
93137
id: destination.id,
94138
display_name: destination.name,
95139
name: destination.name,
96-
slug: destination.slug,
140+
slug: slugify(destination.name),
97141
previous_names: destination.previousNames,
142+
url,
98143
website: destination.website,
99144
status: destination.status,
100145
logo: {
@@ -119,6 +164,7 @@ const getDestinationData = async (id) => {
119164
private.push(updatePrivateDest)
120165
} else {
121166
console.log(`${destination.name} is public and will be removed`)
167+
makeDestinationPublic(url)
122168
}
123169

124170
const options = {
@@ -148,12 +194,18 @@ const checkExistingStatus = async () => {
148194
let id = existingIds[i]
149195
let destination = await checkDestinationStatus(id)
150196
let status = destination.status
197+
let slug = slugify(destination.name)
198+
let url = `connections/destinations/catalog/${slug}`
199+
200+
201+
151202

152203
if (status === "PRIVATE_BETA") {
153204
// console.log(`${destination.name} is private`)
154205
newIds.push(id)
155206
} else {
156-
// console.log(`${destination.name}is public`)
207+
console.log(`src/connections/${destination.name}is public`)
208+
makeDestinationPublic(url)
157209
}
158210
}
159211
return newIds

src/_data/catalog/destinations_private.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT
2-
# destination data last updated 2023-03-30
2+
# destination data last updated 2023-03-31
33
items:
44
- id: 54521fd725e721e32a72eec1
55
display_name: HubSpot
66
name: HubSpot
77
slug: hubspot
88
previous_names:
99
- HubSpot
10+
url: connections/destinations/catalog/hubspot
1011
website: http://www.hubspot.com
1112
status: PRIVATE_BETA
1213
logo:
@@ -123,6 +124,7 @@ items:
123124
slug: intercom
124125
previous_names:
125126
- Intercom
127+
url: connections/destinations/catalog/intercom
126128
website: http://intercom.com
127129
status: PRIVATE_BETA
128130
logo:
@@ -231,6 +233,7 @@ items:
231233
slug: pardot
232234
previous_names:
233235
- Pardot
236+
url: connections/destinations/catalog/pardot
234237
website: http://pardot.com
235238
status: PRIVATE_BETA
236239
logo:
@@ -342,6 +345,7 @@ items:
342345
slug: salesforce
343346
previous_names:
344347
- Salesforce
348+
url: connections/destinations/catalog/salesforce
345349
website: http://salesforce.com
346350
status: PRIVATE_BETA
347351
logo:
@@ -472,6 +476,7 @@ items:
472476
slug: webhooks
473477
previous_names:
474478
- Webhooks
479+
url: connections/destinations/catalog/webhooks
475480
website: https://segment.com/docs/integrations/webhooks
476481
status: PRIVATE_BETA
477482
logo:
@@ -531,9 +536,10 @@ items:
531536
- id: 62b256147cbb49302d1486d0
532537
display_name: Heap Web (Actions)
533538
name: Heap Web (Actions)
534-
slug: actions-heap-web
539+
slug: actions-heap
535540
previous_names:
536541
- Heap Web (Actions)
542+
url: connections/destinations/catalog/actions-heap
537543
website: https://heap.io/
538544
status: PRIVATE_BETA
539545
logo:
@@ -735,6 +741,7 @@ items:
735741
slug: actions-iterate
736742
previous_names:
737743
- Iterate Web (Actions)
744+
url: connections/destinations/catalog/actions-iterate
738745
website: http://www.segment.com
739746
status: PRIVATE_BETA
740747
logo:
@@ -846,6 +853,7 @@ items:
846853
slug: actions-sabil
847854
previous_names:
848855
- Sabil
856+
url: connections/destinations/catalog/actions-sabil
849857
website: https://sabil.io
850858
status: PRIVATE_BETA
851859
logo:
@@ -923,6 +931,7 @@ items:
923931
slug: actions-saleswings
924932
previous_names:
925933
- Saleswings (Actions)
934+
url: connections/destinations/catalog/actions-saleswings
926935
website: >-
927936
https://www.saleswingsapp.com/lead-scoring-segment-com/?utm_campaign=segmentcatalogue&utm_medium=partnerlisting&utm_source=segment
928937
status: PRIVATE_BETA
@@ -1805,6 +1814,7 @@ items:
18051814
slug: actions-livelike-cloud
18061815
previous_names:
18071816
- LiveLike
1817+
url: connections/destinations/catalog/actions-livelike-cloud
18081818
website: https://livelike.com/
18091819
status: PRIVATE_BETA
18101820
logo:
@@ -2050,6 +2060,7 @@ items:
20502060
slug: actions-emarsys
20512061
previous_names:
20522062
- Emarsys (Actions)
2063+
url: connections/destinations/catalog/actions-emarsys
20532064
website: http://www.emarsys.com
20542065
status: PRIVATE_BETA
20552066
logo:
@@ -2350,9 +2361,10 @@ items:
23502361
- id: 63ff8bae963d5cb4fc79f097
23512362
display_name: Outfunnel
23522363
name: Outfunnel
2353-
slug: outfunnel
2364+
slug: actions-outfunnel
23542365
previous_names:
23552366
- Outfunnel
2367+
url: connections/destinations/catalog/actions-outfunnel
23562368
website: https://outfunnel.com/product-led-sales-platform/
23572369
status: PRIVATE_BETA
23582370
logo:
@@ -2822,6 +2834,7 @@ items:
28222834
slug: actions-toplyne-cloud
28232835
previous_names:
28242836
- Toplyne Cloud Mode (Actions)
2837+
url: connections/destinations/catalog/actions-toplyne-cloud
28252838
website: http://www.segment.com
28262839
status: PRIVATE_BETA
28272840
logo:

src/_data/catalog/slugs.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,20 @@
8383
- original: "qualtrics"
8484
override: "actions-qualtrics"
8585
- original: "tiktok-audiences"
86-
override: "actions-tiktok-audiences"
86+
override: "actions-tiktok-audiences"
87+
- original: "heap-web-actions"
88+
override: "actions-heap"
89+
- original: "iterate-web-actions"
90+
override: "actions-iterate"
91+
- original: "sabil"
92+
override: "actions-sabil"
93+
- original: "saleswings-actions"
94+
override: "actions-saleswings"
95+
- original: "livelike"
96+
override: "actions-livelike-cloud"
97+
- original: "emarsys-actions"
98+
override: "actions-emarsys"
99+
- original: "outfunnel"
100+
override: "actions-outfunnel"
101+
- original: "toplyne-cloud-mode-actions"
102+
override: "actions-toplyne-cloud"

0 commit comments

Comments
 (0)