refactor: migrate away from querystring (#4180)

refactor: migrate away from querystring
This commit is contained in:
Michael Kret 2022-09-23 17:48:45 +03:00 committed by GitHub
parent 27e2ce0470
commit 7aa40bf95d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View file

@ -16,7 +16,6 @@ import {
IDataObject, IDataObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { resolve as pathResolve } from 'path'; import { resolve as pathResolve } from 'path';
import querystring from 'querystring';
import { Db, ICredentialsDb, ResponseHelper } from '..'; import { Db, ICredentialsDb, ResponseHelper } from '..';
import { RESPONSE_ERROR_MESSAGES } from '../constants'; import { RESPONSE_ERROR_MESSAGES } from '../constants';
@ -141,11 +140,14 @@ oauth2CredentialController.get(
// if scope uses comma, change it as the library always return then with spaces // if scope uses comma, change it as the library always return then with spaces
if ((get(oauthCredentials, 'scope') as string).includes(',')) { if ((get(oauthCredentials, 'scope') as string).includes(',')) {
const data = querystring.parse(returnUri.split('?')[1]); // const data = new URLSearchParams(returnUri.split('?')[1]);
data.scope = get(oauthCredentials, 'scope') as string; // data.set('scope', get(oauthCredentials, 'scope') as string);
returnUri = `${get(oauthCredentials, 'authUrl', '') as string}?${querystring.stringify( // returnUri = `${get(oauthCredentials, 'authUrl', '') as string}?${data.toString()}`;
data,
)}`; const data = returnUri.split('?')[1];
const scope = get(oauthCredentials, 'scope') as string;
const percentEncoded = [data, `scope=${encodeURIComponent(scope)}`].join('&');
returnUri = `${get(oauthCredentials, 'authUrl', '') as string}?${percentEncoded}`;
} }
if (authQueryParameters) { if (authQueryParameters) {

View file

@ -11,8 +11,6 @@ import {
import { allEvents, eventExists, getId, jiraSoftwareCloudApiRequest } from './GenericFunctions'; import { allEvents, eventExists, getId, jiraSoftwareCloudApiRequest } from './GenericFunctions';
import * as queryString from 'querystring';
export class JiraTrigger implements INodeType { export class JiraTrigger implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'Jira Trigger', displayName: 'Jira Trigger',
@ -450,7 +448,8 @@ export class JiraTrigger implements INodeType {
} }
if (Object.keys(parameters).length) { if (Object.keys(parameters).length) {
body.url = `${body.url}?${queryString.unescape(queryString.stringify(parameters))}`; const params = new URLSearchParams(parameters).toString();
body.url = `${body.url}?${decodeURIComponent(params)}`;
} }
const responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'POST', body); const responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'POST', body);

View file

@ -11,8 +11,6 @@ import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
import { get } from 'lodash'; import { get } from 'lodash';
import querystring from 'querystring';
export async function travisciApiRequest( export async function travisciApiRequest(
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string, method: string,
@ -71,7 +69,8 @@ export async function travisciApiRequestAllItems(
responseData = await travisciApiRequest.call(this, method, resource, body, query); responseData = await travisciApiRequest.call(this, method, resource, body, query);
const path = get(responseData, '@pagination.next.@href'); const path = get(responseData, '@pagination.next.@href');
if (path !== undefined) { if (path !== undefined) {
query = querystring.parse(path); const parsedPath = new URLSearchParams(path);
query = Object.fromEntries(parsedPath);
} }
returnData.push.apply(returnData, responseData[propertyName]); returnData.push.apply(returnData, responseData[propertyName]);
} while (responseData['@pagination']['is_last'] !== true); } while (responseData['@pagination']['is_last'] !== true);