Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,34 @@ export default async function(step: any, config) {
}
*/

export default async function(step: any, config) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
// see non-escaped chars
// this handles not encoding [!'()*]
function encodeReservedChars(str) {
return str.replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16)
})
}

export default async function(step: any, config, signConfig?) {
// XXX warn about mutating config object... or clone?
// OAuth1 request
if (signConfig) {
const {oauthSignerUri, token} = signConfig

// this handles encoding query string to make sure we match what we sign
const url = new URL(config.url)
url.search = encodeReservedChars(url.search.substr(1))
config.url = url.toString()

const payload = {
requestData: config,
token,
}
const oauthSignature = (await axios.post(oauthSignerUri, payload)).data
if (!config.headers) config.headers = {}
config.headers.Authorization = oauthSignature
}
for (const k in config.headers || {}) {
if (typeof config.headers[k] === "undefined") {
delete config.headers[k]
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@pipedreamhq/platform",
"version": "0.2.2",
"name": "@jsendo/platform",
"version": "0.2.3",
"description": "Pipedream platform globals (typing and runtime type checking)",
"homepage": "https://pipedream.com",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand All @@ -13,7 +12,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/PipedreamHQ/platform.git"
"url": "https://github.com/jsendo/platform.git"
},
"dependencies": {
"axios": "^0.19.0",
Expand Down