forked from twilio/twilio-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: link to our API docs when you --help (twilio#283)
* Added help doc url for APIs and commands * Review comments changes * Adding some more test cases and minor tweaks
- Loading branch information
1 parent
0711e97
commit 37a857d
Showing
10 changed files
with
457 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{ | ||
"path": { | ||
"topics":{ | ||
"api":{ | ||
"accounts": "usage/api/account", | ||
"core": "usage/api", | ||
"bulkexports": "usage/bulkexport", | ||
"autopilot": "autopilot/api", | ||
"chat": "chat/api", | ||
"conversations": "conversations/api", | ||
"events": "events", | ||
"fax": "fax/api", | ||
"flex": "flex/developer", | ||
"frontline": "frontline/api", | ||
"insights": "voice/insights/api", | ||
"lookups": "lookup/api", | ||
"messaging": "sms", | ||
"monitor": "usage/monitor-alert", | ||
"notify": "notify/api", | ||
"numbers": "phone-numbers/api", | ||
"pricing": "voice/pricing", | ||
"proxy": "proxy/api", | ||
"serverless": "runtime", | ||
"studio": "studio", | ||
"supersim": "iot/supersim/api", | ||
"sync": "sync/api", | ||
"taskrouter": "taskrouter/api", | ||
"trunking": "sip-trunking/api", | ||
"trusthub": "trust-hub/trusthub-rest-api", | ||
"verify": "verify/api", | ||
"video": "video", | ||
"voice": "voice", | ||
"wireless": "iot/wireless/api" | ||
}, | ||
"debugger": "flex/end-user-guide/debugger", | ||
"email":"/email", | ||
"feedback": "twilio-cli/quickstart#send-us-feedback", | ||
"phone-numbers": "twilio-cli/quickstart#list-your-phone-numbers", | ||
"plugins": "twilio-cli/plugins", | ||
"profiles": "twilio-cli/general-usage#profiles" | ||
}, | ||
"commands":{ | ||
"autocomplete" : "twilio-cli/quickstart#install-cli-autocomplete-bash-or-zsh-only", | ||
"login": "twilio-cli/quickstart#login-to-your-twilio-account", | ||
"plugins": "twilio-cli/quickstart#explore-plugins" | ||
} | ||
}, | ||
"subpath":{ | ||
"chat/v2":{ | ||
"credentials": "/credential-resource", | ||
"services": "/service-resource", | ||
"services-channels" : "/channel-resource", | ||
"services-bindings": "/binding-resource" , | ||
"services-roles": "/role-resource", | ||
"services-users": "user-resource" | ||
}, | ||
"conversations/v1":{ | ||
"configuration": "/configuration-resource", | ||
"conversation": "/conversation-resource", | ||
"credentials": "/credential-resource", | ||
"participant": "/participant-conversation-resource", | ||
"roles" : "/role-resource", | ||
"services": "/service-resource", | ||
"users": "/user-resource" | ||
}, | ||
"events/v1": { | ||
"schemes": "/event-streams/schema-resource", | ||
"sinks": "/event-streams/sink-resource", | ||
"subscriptions": "/event-streams/subscription", | ||
"types": "/event-streams/event-type-resource" | ||
}, | ||
"fax/v1": { | ||
"faxes": "/fax-resource" | ||
}, | ||
"frontline/v1": { | ||
"users": "/user-resource" | ||
}, | ||
"notify/v1": { | ||
"credentials": "/credential-resource", | ||
"services": "/service-resource" | ||
}, | ||
"proxy/v1": { | ||
"services": "/service" | ||
}, | ||
"serverless/v1": { | ||
"services": "/functions-assets-api/api/service" | ||
}, | ||
"studio/v2": { | ||
"flows": "/rest-api/v2/flow" | ||
}, | ||
"supersim/v1": { | ||
"commands": "/command-resource", | ||
"fleets": "/fleet-resource", | ||
"network-access-profiles": "/networkaccessprofile-resource", | ||
"networks": "/network-resource", | ||
"sims": "/sim-resource", | ||
"sms-commands": "/smscommand-resource", | ||
"usage-records": "/usage-record-resource" | ||
}, | ||
"sync/v1": { | ||
"services": "/service" | ||
}, | ||
"taskrouter/v1": { | ||
"workspaces": "/workspace" | ||
}, | ||
"trunking/v1": { | ||
"trunks":"/trunk-resource" | ||
}, | ||
"verify/v2": { | ||
"services": "/service" | ||
}, | ||
"voice/v1": { | ||
"byoc-trunks": "/bring-your-own-carrier-byoc", | ||
"connection-policies": "/bring-your-own-carrier-byoc/api/connectionpolicy-resource", | ||
"dialing-permissions": "/api/dialingpermissions-settings-resource", | ||
"ip-records": "/bring-your-own-carrier-byoc/api/iprecord-resource", | ||
"source-ip-mappings": "/bring-your-own-carrier-byoc/api/sourceipmapping-resource" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const jsonMap = require('../api-doc-mapping.json'); | ||
// json structure = url: {path : {topics: {}, commands: {}}, subpath : {wherever applicable}} | ||
const urlMap = new Map(Object.entries(jsonMap)); | ||
|
||
const getSubroute = (cmdDetailsArr, subpathMap) => { | ||
const subdomain = cmdDetailsArr[3]; | ||
// apiName/version to locate sub url in json map | ||
const apiVersion = `${cmdDetailsArr[1]}/${cmdDetailsArr[2]}`; | ||
const subUrlArr = subpathMap.get(apiVersion); | ||
if (subUrlArr === undefined) { | ||
return ''; | ||
} | ||
const subUrlMap = new Map(Object.entries(subUrlArr)); | ||
const subUrl = subUrlMap.get(subdomain); | ||
return subUrl; | ||
}; | ||
|
||
const getRootPath = (cmdDetailsArr, subpathMap, topicsMap, commandsMap) => { | ||
const topicName = cmdDetailsArr[0]; | ||
const apiName = cmdDetailsArr[1]; | ||
let url = ''; | ||
|
||
if (topicName === 'api') { | ||
// get the array of apis and convert to a map | ||
const arrOfAllApis = topicsMap.get(topicName); | ||
if (!arrOfAllApis) { | ||
return ''; | ||
} | ||
const mapOfAPIs = new Map(Object.entries(arrOfAllApis)); | ||
url = mapOfAPIs.get(apiName); | ||
if (url === undefined) { | ||
return ''; | ||
} | ||
url += getSubroute(cmdDetailsArr, subpathMap) || ''; | ||
} else { | ||
// its a command or another topic | ||
url = topicsMap.get(topicName) || commandsMap.get(topicName); | ||
} | ||
|
||
return url; | ||
}; | ||
|
||
const getDocLink = (key) => { | ||
// key format : baseTopicName:topicName:actionName | ||
const pathMap = new Map(Object.entries(urlMap.get('path'))); | ||
const subpathMap = new Map(Object.entries(urlMap.get('subpath'))); | ||
const topicsMap = new Map(Object.entries(pathMap.get('topics'))); | ||
const commandsMap = new Map(Object.entries(pathMap.get('commands'))); | ||
|
||
const baseUrl = 'https://twilio.com/docs/'; | ||
let url = ''; | ||
const cmdDetailsArr = key.split(':'); // original command array | ||
const cmd = cmdDetailsArr[0]; | ||
if (topicsMap.has(cmd) || commandsMap.has(cmd)) { | ||
url = getRootPath(cmdDetailsArr, subpathMap, topicsMap, commandsMap); | ||
} else { | ||
url = 'api/'; | ||
} | ||
return baseUrl + (url || ''); | ||
}; | ||
|
||
module.exports = { | ||
getDocLink, | ||
getRootPath, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.