Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.
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
2 changes: 1 addition & 1 deletion dist/axios.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function (step: any, config: any): Promise<any>;
export default function (step: any, config: any, signConfig?: any): Promise<any>;
26 changes: 25 additions & 1 deletion dist/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,32 @@ export default async function(step: any, config) {
}
}
*/
async function default_1(step, 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);
});
}
async function default_1(step, 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_1.default.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
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
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedreamhq/platform",
"version": "0.2.2",
"version": "0.2.3",
"description": "Pipedream platform globals (typing and runtime type checking)",
"homepage": "https://pipedream.com",
"main": "dist/index.js",
Expand Down