mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -20,15 +17,9 @@ import {
|
||||
upperFirst,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
documentFields,
|
||||
documentOperations,
|
||||
} from './DocumentDescription';
|
||||
import { documentFields, documentOperations } from './DocumentDescription';
|
||||
|
||||
import {
|
||||
IUpdateBody,
|
||||
IUpdateFields,
|
||||
} from './interfaces';
|
||||
import { IUpdateBody, IUpdateFields } from './interfaces';
|
||||
|
||||
export class GoogleDocs implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -50,9 +41,7 @@ export class GoogleDocs implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'serviceAccount',
|
||||
],
|
||||
authentication: ['serviceAccount'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -61,9 +50,7 @@ export class GoogleDocs implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -86,9 +73,7 @@ export class GoogleDocs implements INodeType {
|
||||
default: 'serviceAccount',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [
|
||||
1,
|
||||
],
|
||||
'@version': [1],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -109,9 +94,7 @@ export class GoogleDocs implements INodeType {
|
||||
default: 'oAuth2',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [
|
||||
2,
|
||||
],
|
||||
'@version': [2],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -149,7 +132,15 @@ export class GoogleDocs implements INodeType {
|
||||
];
|
||||
let drives;
|
||||
try {
|
||||
drives = await googleApiRequestAllItems.call(this, 'drives', 'GET', '', {}, {}, 'https://www.googleapis.com/drive/v3/drives');
|
||||
drives = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'drives',
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
{},
|
||||
'https://www.googleapis.com/drive/v3/drives',
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error, { message: 'Error in loading Drives' });
|
||||
}
|
||||
@@ -172,13 +163,23 @@ export class GoogleDocs implements INodeType {
|
||||
const driveId = this.getNodeParameter('driveId');
|
||||
|
||||
const qs = {
|
||||
q: `mimeType = \'application/vnd.google-apps.folder\' ${driveId === 'sharedWithMe' ? 'and sharedWithMe = true' : ' and \'root\' in parents'}`,
|
||||
...(driveId && driveId !== 'myDrive' && driveId !== 'sharedWithMe') ? { driveId } : {},
|
||||
q: `mimeType = \'application/vnd.google-apps.folder\' ${
|
||||
driveId === 'sharedWithMe' ? 'and sharedWithMe = true' : " and 'root' in parents"
|
||||
}`,
|
||||
...(driveId && driveId !== 'myDrive' && driveId !== 'sharedWithMe' ? { driveId } : {}),
|
||||
};
|
||||
let folders;
|
||||
|
||||
try {
|
||||
folders = await googleApiRequestAllItems.call(this, 'files', 'GET', '', {}, qs, 'https://www.googleapis.com/drive/v3/files');
|
||||
folders = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'files',
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
qs,
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error, { message: 'Error in loading Folders' });
|
||||
}
|
||||
@@ -204,13 +205,9 @@ export class GoogleDocs implements INodeType {
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
try {
|
||||
|
||||
if (resource === 'document') {
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// https://developers.google.com/docs/api/reference/rest/v1/documents/create
|
||||
|
||||
const folderId = this.getNodeParameter('folderId', i) as string;
|
||||
@@ -218,13 +215,18 @@ export class GoogleDocs implements INodeType {
|
||||
const body: IDataObject = {
|
||||
name: this.getNodeParameter('title', i) as string,
|
||||
mimeType: 'application/vnd.google-apps.document',
|
||||
...(folderId && folderId !== 'default') ? { parents: [folderId] } : {},
|
||||
...(folderId && folderId !== 'default' ? { parents: [folderId] } : {}),
|
||||
};
|
||||
|
||||
responseData = await googleApiRequest.call(this, 'POST', '', body, {}, 'https://www.googleapis.com/drive/v3/files');
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'',
|
||||
body,
|
||||
{},
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
);
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// https://developers.google.com/docs/api/reference/rest/v1/documents/get
|
||||
|
||||
const documentURL = this.getNodeParameter('documentURL', i) as string;
|
||||
@@ -236,16 +238,16 @@ export class GoogleDocs implements INodeType {
|
||||
}
|
||||
responseData = await googleApiRequest.call(this, 'GET', `/documents/${documentId}`);
|
||||
if (simple) {
|
||||
|
||||
const content = (responseData.body.content as IDataObject[])
|
||||
.reduce((arr: string[], contentItem) => {
|
||||
if (contentItem && contentItem.paragraph) {
|
||||
const texts = ((contentItem.paragraph as IDataObject).elements as IDataObject[])
|
||||
.map(element => {
|
||||
if (element && element.textRun) {
|
||||
return (element.textRun as IDataObject).content as string;
|
||||
}
|
||||
}) as string[];
|
||||
const texts = (
|
||||
(contentItem.paragraph as IDataObject).elements as IDataObject[]
|
||||
).map((element) => {
|
||||
if (element && element.textRun) {
|
||||
return (element.textRun as IDataObject).content as string;
|
||||
}
|
||||
}) as string[];
|
||||
arr = [...arr, ...texts];
|
||||
}
|
||||
return arr;
|
||||
@@ -256,20 +258,20 @@ export class GoogleDocs implements INodeType {
|
||||
documentId,
|
||||
content,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// https://developers.google.com/docs/api/reference/rest/v1/documents/batchUpdate
|
||||
|
||||
const documentURL = this.getNodeParameter('documentURL', i) as string;
|
||||
let documentId = extractID(documentURL);
|
||||
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||
const actionsUi = this.getNodeParameter('actionsUi', i) as {
|
||||
actionFields: IDataObject[]
|
||||
actionFields: IDataObject[];
|
||||
};
|
||||
const { writeControlObject } = this.getNodeParameter('updateFields', i) as IUpdateFields;
|
||||
const { writeControlObject } = this.getNodeParameter(
|
||||
'updateFields',
|
||||
i,
|
||||
) as IUpdateFields;
|
||||
|
||||
if (!documentId) {
|
||||
documentId = documentURL;
|
||||
@@ -287,9 +289,8 @@ export class GoogleDocs implements INodeType {
|
||||
}
|
||||
|
||||
if (actionsUi) {
|
||||
|
||||
let requestBody: IDataObject;
|
||||
actionsUi.actionFields.forEach(actionField => {
|
||||
actionsUi.actionFields.forEach((actionField) => {
|
||||
const { action, object } = actionField;
|
||||
if (object === 'positionedObject') {
|
||||
if (action === 'delete') {
|
||||
@@ -297,42 +298,37 @@ export class GoogleDocs implements INodeType {
|
||||
objectId: actionField.objectId,
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'pageBreak') {
|
||||
|
||||
if (action === 'insert') {
|
||||
const { insertSegment, segmentId, locationChoice, index } = actionField;
|
||||
requestBody = {
|
||||
[locationChoice as string]: {
|
||||
segmentId: (insertSegment !== 'body') ? segmentId : '',
|
||||
...(locationChoice === 'location') ? { index } : {},
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
...(locationChoice === 'location' ? { index } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'table') {
|
||||
|
||||
if (action === 'insert') {
|
||||
const { rows, columns, insertSegment, locationChoice, segmentId, index } = actionField;
|
||||
const { rows, columns, insertSegment, locationChoice, segmentId, index } =
|
||||
actionField;
|
||||
requestBody = {
|
||||
rows,
|
||||
columns,
|
||||
[locationChoice as string]: {
|
||||
segmentId: (insertSegment !== 'body') ? segmentId : '',
|
||||
...(locationChoice === 'location') ? { index } : {},
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
...(locationChoice === 'location' ? { index } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'footer') {
|
||||
|
||||
if (action === 'create') {
|
||||
const { insertSegment, locationChoice, segmentId, index } = actionField;
|
||||
requestBody = {
|
||||
type: 'DEFAULT',
|
||||
sectionBreakLocation: {
|
||||
segmentId: (insertSegment !== 'body') ? segmentId : '',
|
||||
...(locationChoice === 'location') ? { index } : {},
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
...(locationChoice === 'location' ? { index } : {}),
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
@@ -340,16 +336,14 @@ export class GoogleDocs implements INodeType {
|
||||
footerId: actionField.footerId,
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'header') {
|
||||
|
||||
if (action === 'create') {
|
||||
const { insertSegment, locationChoice, segmentId, index } = actionField;
|
||||
requestBody = {
|
||||
type: 'DEFAULT',
|
||||
sectionBreakLocation: {
|
||||
segmentId: (insertSegment !== 'body') ? segmentId : '',
|
||||
...(locationChoice === 'location') ? { index } : {},
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
...(locationChoice === 'location' ? { index } : {}),
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
@@ -357,17 +351,25 @@ export class GoogleDocs implements INodeType {
|
||||
headerId: actionField.headerId,
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'tableColumn') {
|
||||
|
||||
if (action === 'insert') {
|
||||
const { insertPosition, rowIndex, columnIndex, insertSegment, segmentId, index } = actionField;
|
||||
const {
|
||||
insertPosition,
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
insertSegment,
|
||||
segmentId,
|
||||
index,
|
||||
} = actionField;
|
||||
requestBody = {
|
||||
insertRight: insertPosition,
|
||||
tableCellLocation: {
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
tableStartLocation: { segmentId: (insertSegment !== 'body') ? segmentId : '', index, },
|
||||
tableStartLocation: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
index,
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
@@ -376,21 +378,32 @@ export class GoogleDocs implements INodeType {
|
||||
tableCellLocation: {
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
tableStartLocation: { segmentId: (insertSegment !== 'body') ? segmentId : '', index, },
|
||||
tableStartLocation: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
index,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'tableRow') {
|
||||
|
||||
if (action === 'insert') {
|
||||
const { insertPosition, rowIndex, columnIndex, insertSegment, segmentId, index } = actionField;
|
||||
const {
|
||||
insertPosition,
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
insertSegment,
|
||||
segmentId,
|
||||
index,
|
||||
} = actionField;
|
||||
requestBody = {
|
||||
insertBelow: insertPosition,
|
||||
tableCellLocation: {
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
tableStartLocation: { segmentId: (insertSegment !== 'body') ? segmentId : '', index, },
|
||||
tableStartLocation: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
index,
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
@@ -399,20 +412,21 @@ export class GoogleDocs implements INodeType {
|
||||
tableCellLocation: {
|
||||
rowIndex,
|
||||
columnIndex,
|
||||
tableStartLocation: { segmentId: (insertSegment !== 'body') ? segmentId : '', index, },
|
||||
tableStartLocation: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
index,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'text') {
|
||||
|
||||
if (action === 'insert') {
|
||||
const { text, locationChoice, insertSegment, segmentId, index } = actionField;
|
||||
requestBody = {
|
||||
text,
|
||||
[locationChoice as string]: {
|
||||
segmentId: (insertSegment !== 'body') ? segmentId : '',
|
||||
...(locationChoice === 'location') ? { index } : {},
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
...(locationChoice === 'location' ? { index } : {}),
|
||||
},
|
||||
};
|
||||
} else if (action === 'replaceAll') {
|
||||
@@ -422,18 +436,26 @@ export class GoogleDocs implements INodeType {
|
||||
containsText: { text, matchCase },
|
||||
};
|
||||
}
|
||||
|
||||
} else if (object === 'paragraphBullets') {
|
||||
if (action === 'create') {
|
||||
const { bulletPreset, startIndex, insertSegment, segmentId, endIndex } = actionField;
|
||||
const { bulletPreset, startIndex, insertSegment, segmentId, endIndex } =
|
||||
actionField;
|
||||
requestBody = {
|
||||
bulletPreset,
|
||||
range: { segmentId: (insertSegment !== 'body') ? segmentId : '', startIndex, endIndex },
|
||||
range: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
startIndex,
|
||||
endIndex,
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
const { startIndex, insertSegment, segmentId, endIndex } = actionField;
|
||||
requestBody = {
|
||||
range: { segmentId: (insertSegment !== 'body') ? segmentId : '', startIndex, endIndex },
|
||||
range: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
startIndex,
|
||||
endIndex,
|
||||
},
|
||||
};
|
||||
}
|
||||
} else if (object === 'namedRange') {
|
||||
@@ -441,7 +463,11 @@ export class GoogleDocs implements INodeType {
|
||||
const { name, insertSegment, segmentId, startIndex, endIndex } = actionField;
|
||||
requestBody = {
|
||||
name,
|
||||
range: { segmentId: (insertSegment !== 'body') ? segmentId : '', startIndex, endIndex },
|
||||
range: {
|
||||
segmentId: insertSegment !== 'body' ? segmentId : '',
|
||||
startIndex,
|
||||
endIndex,
|
||||
},
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
const { namedRangeReference, value } = actionField;
|
||||
@@ -454,11 +480,15 @@ export class GoogleDocs implements INodeType {
|
||||
body.requests.push({
|
||||
[`${action}${upperFirst(object as string)}`]: requestBody,
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
responseData = await googleApiRequest.call(this, 'POST', `/documents/${documentId}:batchUpdate`, body);
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/documents/${documentId}:batchUpdate`,
|
||||
body,
|
||||
);
|
||||
|
||||
if (simple === true) {
|
||||
if (Object.keys(responseData.replies[0]).length !== 0) {
|
||||
@@ -471,7 +501,6 @@ export class GoogleDocs implements INodeType {
|
||||
responseData.documentId = documentId;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
|
||||
Reference in New Issue
Block a user