n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
NodeApiError,
|
||||
NodeOperationError
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, JsonObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'serviceAccount') as string;
|
||||
export async function googleApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
headers: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const authenticationMethod = this.getNodeParameter(
|
||||
'authentication',
|
||||
0,
|
||||
'serviceAccount',
|
||||
) as string;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
@@ -64,8 +67,16 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
}
|
||||
}
|
||||
|
||||
export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function googleApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
@@ -75,41 +86,39 @@ export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOp
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, query);
|
||||
query.pageToken = responseData['pageToken'];
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
||||
responseData['pageToken'] !== undefined &&
|
||||
responseData['pageToken'] !== ''
|
||||
);
|
||||
} while (responseData['pageToken'] !== undefined && responseData['pageToken'] !== '');
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, credentials: IDataObject): Promise<IDataObject> {
|
||||
function getAccessToken(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
credentials: IDataObject,
|
||||
): Promise<IDataObject> {
|
||||
//https://developers.google.com/identity/protocols/oauth2/service-account#httprest
|
||||
|
||||
const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n').trim();
|
||||
|
||||
const scopes = [
|
||||
'https://www.googleapis.com/auth/bigquery',
|
||||
];
|
||||
const scopes = ['https://www.googleapis.com/auth/bigquery'];
|
||||
|
||||
const now = moment().unix();
|
||||
|
||||
const signature = jwt.sign(
|
||||
{
|
||||
'iss': credentials.email as string,
|
||||
'sub': credentials.delegatedEmail || credentials.email as string,
|
||||
'scope': scopes.join(' '),
|
||||
'aud': `https://oauth2.googleapis.com/token`,
|
||||
'iat': now,
|
||||
'exp': now + 3600,
|
||||
iss: credentials.email as string,
|
||||
sub: credentials.delegatedEmail || (credentials.email as string),
|
||||
scope: scopes.join(' '),
|
||||
aud: `https://oauth2.googleapis.com/token`,
|
||||
iat: now,
|
||||
exp: now + 3600,
|
||||
},
|
||||
privateKey,
|
||||
{
|
||||
algorithm: 'RS256',
|
||||
header: {
|
||||
'kid': privateKey,
|
||||
'typ': 'JWT',
|
||||
'alg': 'RS256',
|
||||
kid: privateKey,
|
||||
typ: 'JWT',
|
||||
alg: 'RS256',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -12,16 +10,9 @@ import {
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
googleApiRequest,
|
||||
googleApiRequestAllItems,
|
||||
simplify,
|
||||
} from './GenericFunctions';
|
||||
import { googleApiRequest, googleApiRequestAllItems, simplify } from './GenericFunctions';
|
||||
|
||||
import {
|
||||
recordFields,
|
||||
recordOperations,
|
||||
} from './RecordDescription';
|
||||
import { recordFields, recordOperations } from './RecordDescription';
|
||||
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
@@ -45,9 +36,7 @@ export class GoogleBigQuery implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'serviceAccount',
|
||||
],
|
||||
authentication: ['serviceAccount'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -56,9 +45,7 @@ export class GoogleBigQuery implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -101,15 +88,9 @@ export class GoogleBigQuery implements INodeType {
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getProjects(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { projects } = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/v2/projects',
|
||||
);
|
||||
const { projects } = await googleApiRequest.call(this, 'GET', '/v2/projects');
|
||||
for (const project of projects) {
|
||||
returnData.push({
|
||||
name: project.friendlyName as string,
|
||||
@@ -118,9 +99,7 @@ export class GoogleBigQuery implements INodeType {
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
async getDatasets(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getDatasets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const projectId = this.getCurrentNodeParameter('projectId');
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { datasets } = await googleApiRequest.call(
|
||||
@@ -136,9 +115,7 @@ export class GoogleBigQuery implements INodeType {
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
async getTables(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const projectId = this.getCurrentNodeParameter('projectId');
|
||||
const datasetId = this.getCurrentNodeParameter('datasetId');
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
@@ -168,13 +145,11 @@ export class GoogleBigQuery implements INodeType {
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (resource === 'record') {
|
||||
|
||||
// *********************************************************************
|
||||
// record
|
||||
// *********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------
|
||||
// record: create
|
||||
// ----------------------------------
|
||||
@@ -188,14 +163,13 @@ export class GoogleBigQuery implements INodeType {
|
||||
const body: IDataObject = {};
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
Object.assign(body, options);
|
||||
if (body.traceId === undefined) {
|
||||
body.traceId = uuid();
|
||||
}
|
||||
const columns = this.getNodeParameter('columns', i) as string;
|
||||
const columnList = columns.split(',').map(column => column.trim());
|
||||
const columnList = columns.split(',').map((column) => column.trim());
|
||||
const record: IDataObject = {};
|
||||
|
||||
for (const key of Object.keys(items[i].json)) {
|
||||
@@ -224,7 +198,6 @@ export class GoogleBigQuery implements INodeType {
|
||||
}
|
||||
}
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------
|
||||
// record: getAll
|
||||
// ----------------------------------
|
||||
@@ -273,7 +246,10 @@ export class GoogleBigQuery implements INodeType {
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
returnData.push.apply(returnData, (simple) ? simplify(responseData, fields) : responseData);
|
||||
returnData.push.apply(
|
||||
returnData,
|
||||
simple ? simplify(responseData, fields) : responseData,
|
||||
);
|
||||
} else {
|
||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await googleApiRequest.call(
|
||||
@@ -283,7 +259,10 @@ export class GoogleBigQuery implements INodeType {
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
returnData.push.apply(returnData, (simple) ? simplify(responseData.rows, fields) : responseData.rows);
|
||||
returnData.push.apply(
|
||||
returnData,
|
||||
simple ? simplify(responseData.rows, fields) : responseData.rows,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const recordOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -10,9 +8,7 @@ export const recordOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -47,16 +43,13 @@ export const recordFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['create'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the project to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the project to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Dataset Name or ID',
|
||||
@@ -64,23 +57,18 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getDatasets',
|
||||
loadOptionsDependsOn: [
|
||||
'projectId',
|
||||
],
|
||||
loadOptionsDependsOn: ['projectId'],
|
||||
},
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['create'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the dataset to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the dataset to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Table Name or ID',
|
||||
@@ -88,24 +76,18 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTables',
|
||||
loadOptionsDependsOn: [
|
||||
'projectId',
|
||||
'datasetId',
|
||||
],
|
||||
loadOptionsDependsOn: ['projectId', 'datasetId'],
|
||||
},
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['create'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the table to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the table to create the record in. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Columns',
|
||||
@@ -113,12 +95,8 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['record'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -134,12 +112,8 @@ export const recordFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['create'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -162,14 +136,16 @@ export const recordFields: INodeProperties[] = [
|
||||
name: 'templateSuffix',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Create a new table based on the destination table and insert rows into the new table. The new table will be named <code>{destinationTable}{templateSuffix}</code>',
|
||||
description:
|
||||
'Create a new table based on the destination table and insert rows into the new table. The new table will be named <code>{destinationTable}{templateSuffix}</code>',
|
||||
},
|
||||
{
|
||||
displayName: 'Trace ID',
|
||||
name: 'traceId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Unique ID for the request, for debugging only. It is case-sensitive, limited to up to 36 ASCII characters. A UUID is recommended.',
|
||||
description:
|
||||
'Unique ID for the request, for debugging only. It is case-sensitive, limited to up to 36 ASCII characters. A UUID is recommended.',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -187,16 +163,13 @@ export const recordFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the project to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the project to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Dataset Name or ID',
|
||||
@@ -204,23 +177,18 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getDatasets',
|
||||
loadOptionsDependsOn: [
|
||||
'projectId',
|
||||
],
|
||||
loadOptionsDependsOn: ['projectId'],
|
||||
},
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the dataset to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the dataset to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Table Name or ID',
|
||||
@@ -228,24 +196,18 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTables',
|
||||
loadOptionsDependsOn: [
|
||||
'projectId',
|
||||
'datasetId',
|
||||
],
|
||||
loadOptionsDependsOn: ['projectId', 'datasetId'],
|
||||
},
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the table to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'ID of the table to retrieve all rows from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
@@ -253,12 +215,8 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -270,15 +228,9 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -294,12 +246,8 @@ export const recordFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['record'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
@@ -313,12 +261,8 @@ export const recordFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'record',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['record'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -327,7 +271,8 @@ export const recordFields: INodeProperties[] = [
|
||||
name: 'selectedFields',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Subset of fields to return, supports select into sub fields. Example: <code>selectedFields = "a,e.d.f"</code>',
|
||||
description:
|
||||
'Subset of fields to return, supports select into sub fields. Example: <code>selectedFields = "a,e.d.f"</code>',
|
||||
},
|
||||
// {
|
||||
// displayName: 'Use Int64 Timestamp',
|
||||
|
||||
Reference in New Issue
Block a user