mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
🔀 Merge branch 'master' into oauth-support
This commit is contained in:
commit
f1f09d4a03
|
@ -192,7 +192,7 @@ class LoadNodesAndCredentialsClass {
|
|||
* @memberof N8nPackagesInformationClass
|
||||
*/
|
||||
async loadDataFromDirectory(setPackageName: string, directory: string): Promise<void> {
|
||||
const files = await glob(path.join(directory, '*\.@(node|credentials)\.js'));
|
||||
const files = await glob(path.join(directory, '**/*\.@(node|credentials)\.js'));
|
||||
|
||||
let fileName: string;
|
||||
let type: string;
|
||||
|
|
|
@ -19,7 +19,16 @@
|
|||
|
||||
<div class="header">
|
||||
<div class="title-text">
|
||||
<strong>Results: {{ dataCount }}</strong>
|
||||
<strong v-if="dataCount < this.MAX_DISPLAY_ITEMS_AUTO_ALL && dataSize < MAX_DISPLAY_DATA_SIZE">
|
||||
Results: {{ dataCount }}
|
||||
</strong>
|
||||
<strong v-else>Results:
|
||||
<el-select v-model="maxDisplayItems" @click.stop>
|
||||
<el-option v-for="option in maxDisplayItemsOptions" :label="option" :value="option" :key="option" />
|
||||
</el-select> /
|
||||
{{ dataCount }}
|
||||
</strong>
|
||||
|
||||
<el-popover
|
||||
v-if="runMetadata"
|
||||
placement="right"
|
||||
|
@ -184,6 +193,11 @@ import {
|
|||
ITableData,
|
||||
} from '@/Interface';
|
||||
|
||||
import {
|
||||
MAX_DISPLAY_DATA_SIZE,
|
||||
MAX_DISPLAY_ITEMS_AUTO_ALL,
|
||||
} from '@/constants';
|
||||
|
||||
import BinaryDataDisplay from '@/components/BinaryDataDisplay.vue';
|
||||
|
||||
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
||||
|
@ -211,8 +225,12 @@ export default mixins(
|
|||
runIndex: 0,
|
||||
showData: false,
|
||||
outputIndex: 0,
|
||||
maxDisplayItems: 25 as number | null,
|
||||
binaryDataDisplayVisible: false,
|
||||
binaryDataDisplayData: null as IBinaryDisplayData | null,
|
||||
|
||||
MAX_DISPLAY_DATA_SIZE,
|
||||
MAX_DISPLAY_ITEMS_AUTO_ALL,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -229,6 +247,9 @@ export default mixins(
|
|||
const executionData: IRunExecutionData = this.workflowExecution.data;
|
||||
return executionData.resultData.runData;
|
||||
},
|
||||
maxDisplayItemsOptions (): number[] {
|
||||
return [25, 50, 100, 250, 500, 1000, this.dataCount].filter(option => option <= this.dataCount);
|
||||
},
|
||||
node (): INodeUi | null {
|
||||
return this.$store.getters.activeNode;
|
||||
},
|
||||
|
@ -323,19 +344,27 @@ export default mixins(
|
|||
return 0;
|
||||
},
|
||||
jsonData (): IDataObject[] {
|
||||
const inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
let inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
if (inputData.length === 0 || !Array.isArray(inputData)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (this.maxDisplayItems !== null) {
|
||||
inputData = inputData.slice(0, this.maxDisplayItems);
|
||||
}
|
||||
|
||||
return this.convertToJson(inputData);
|
||||
},
|
||||
tableData (): ITableData | undefined {
|
||||
const inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
let inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
if (inputData.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (this.maxDisplayItems !== null) {
|
||||
inputData = inputData.slice(0,this.maxDisplayItems);
|
||||
}
|
||||
|
||||
return this.convertToTable(inputData);
|
||||
},
|
||||
binaryData (): IBinaryKeyData[] {
|
||||
|
@ -450,9 +479,12 @@ export default mixins(
|
|||
|
||||
// Check how much data there is to display
|
||||
const inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
this.dataSize = JSON.stringify(inputData).length;
|
||||
|
||||
if (this.dataSize < 204800) {
|
||||
const jsonItems = inputData.slice(0, this.maxDisplayItems || inputData.length).map(item => item.json);
|
||||
|
||||
this.dataSize = JSON.stringify(jsonItems).length;
|
||||
|
||||
if (this.dataSize < this.MAX_DISPLAY_DATA_SIZE) {
|
||||
// Data is reasonable small (< 200kb) so display it directly
|
||||
this.showData = true;
|
||||
}
|
||||
|
@ -466,6 +498,7 @@ export default mixins(
|
|||
node (newNode, oldNode) {
|
||||
// Reset the selected output index every time another node gets selected
|
||||
this.outputIndex = 0;
|
||||
this.maxDisplayItems = 25;
|
||||
this.refreshDataSize();
|
||||
},
|
||||
jsonData () {
|
||||
|
|
|
@ -65,6 +65,7 @@ export const nodeBase = mixins(nodeIndex).extend({
|
|||
'name',
|
||||
'nodeId',
|
||||
'instance',
|
||||
'isReadOnly',
|
||||
],
|
||||
methods: {
|
||||
__addNode (node: INodeUi) {
|
||||
|
@ -182,7 +183,7 @@ export const nodeBase = mixins(nodeIndex).extend({
|
|||
endpoint: inputData.endpoint,
|
||||
endpointStyle: inputData.endpointStyle,
|
||||
isSource: false,
|
||||
isTarget: true,
|
||||
isTarget: !this.isReadOnly,
|
||||
parameters: {
|
||||
nodeIndex: this.nodeIndex,
|
||||
type: inputName,
|
||||
|
@ -246,7 +247,7 @@ export const nodeBase = mixins(nodeIndex).extend({
|
|||
maxConnections: inputData.maxConnections,
|
||||
endpoint: inputData.endpoint,
|
||||
endpointStyle: inputData.endpointStyle,
|
||||
isSource: true,
|
||||
isSource: !this.isReadOnly,
|
||||
isTarget: false,
|
||||
parameters: {
|
||||
nodeIndex: this.nodeIndex,
|
||||
|
@ -275,61 +276,63 @@ export const nodeBase = mixins(nodeIndex).extend({
|
|||
this.instance.addEndpoint(this.nodeName, newEndpointData);
|
||||
});
|
||||
|
||||
// Make nodes draggable
|
||||
this.instance.draggable(this.nodeName, {
|
||||
grid: [10, 10],
|
||||
start: (params: { e: MouseEvent }) => {
|
||||
if (params.e && !this.$store.getters.isNodeSelected(this.data.name)) {
|
||||
// Only the node which gets dragged directly gets an event, for all others it is
|
||||
// undefined. So check if the currently dragged node is selected and if not clear
|
||||
// the drag-selection.
|
||||
this.instance.clearDragSelection();
|
||||
this.$store.commit('resetSelectedNodes');
|
||||
}
|
||||
|
||||
this.$store.commit('addActiveAction', 'dragActive');
|
||||
},
|
||||
stop: (params: { e: MouseEvent}) => {
|
||||
if (this.$store.getters.isActionActive('dragActive')) {
|
||||
const moveNodes = this.$store.getters.getSelectedNodes.slice();
|
||||
const selectedNodeNames = moveNodes.map((node: INodeUi) => node.name);
|
||||
if (!selectedNodeNames.includes(this.data.name)) {
|
||||
// If the current node is not in selected add it to the nodes which
|
||||
// got moved manually
|
||||
moveNodes.push(this.data);
|
||||
if (this.isReadOnly === false) {
|
||||
// Make nodes draggable
|
||||
this.instance.draggable(this.nodeName, {
|
||||
grid: [10, 10],
|
||||
start: (params: { e: MouseEvent }) => {
|
||||
if (params.e && !this.$store.getters.isNodeSelected(this.data.name)) {
|
||||
// Only the node which gets dragged directly gets an event, for all others it is
|
||||
// undefined. So check if the currently dragged node is selected and if not clear
|
||||
// the drag-selection.
|
||||
this.instance.clearDragSelection();
|
||||
this.$store.commit('resetSelectedNodes');
|
||||
}
|
||||
|
||||
// This does for some reason just get called once for the node that got clicked
|
||||
// even though "start" and "drag" gets called for all. So lets do for now
|
||||
// some dirty DOM query to get the new positions till I have more time to
|
||||
// create a proper solution
|
||||
let newNodePositon: XYPositon;
|
||||
moveNodes.forEach((node: INodeUi) => {
|
||||
const nodeElement = `node-${this.getNodeIndex(node.name)}`;
|
||||
const element = document.getElementById(nodeElement);
|
||||
if (element === null) {
|
||||
return;
|
||||
this.$store.commit('addActiveAction', 'dragActive');
|
||||
},
|
||||
stop: (params: { e: MouseEvent }) => {
|
||||
if (this.$store.getters.isActionActive('dragActive')) {
|
||||
const moveNodes = this.$store.getters.getSelectedNodes.slice();
|
||||
const selectedNodeNames = moveNodes.map((node: INodeUi) => node.name);
|
||||
if (!selectedNodeNames.includes(this.data.name)) {
|
||||
// If the current node is not in selected add it to the nodes which
|
||||
// got moved manually
|
||||
moveNodes.push(this.data);
|
||||
}
|
||||
|
||||
newNodePositon = [
|
||||
parseInt(element.style.left!.slice(0, -2), 10),
|
||||
parseInt(element.style.top!.slice(0, -2), 10),
|
||||
];
|
||||
// This does for some reason just get called once for the node that got clicked
|
||||
// even though "start" and "drag" gets called for all. So lets do for now
|
||||
// some dirty DOM query to get the new positions till I have more time to
|
||||
// create a proper solution
|
||||
let newNodePositon: XYPositon;
|
||||
moveNodes.forEach((node: INodeUi) => {
|
||||
const nodeElement = `node-${this.getNodeIndex(node.name)}`;
|
||||
const element = document.getElementById(nodeElement);
|
||||
if (element === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const updateInformation = {
|
||||
name: node.name,
|
||||
properties: {
|
||||
// @ts-ignore, draggable does not have definitions
|
||||
position: newNodePositon,
|
||||
},
|
||||
};
|
||||
newNodePositon = [
|
||||
parseInt(element.style.left!.slice(0, -2), 10),
|
||||
parseInt(element.style.top!.slice(0, -2), 10),
|
||||
];
|
||||
|
||||
this.$store.commit('updateNodeProperties', updateInformation);
|
||||
});
|
||||
}
|
||||
},
|
||||
filter: '.node-description, .node-description .node-name, .node-description .node-subtitle',
|
||||
});
|
||||
const updateInformation = {
|
||||
name: node.name,
|
||||
properties: {
|
||||
// @ts-ignore, draggable does not have definitions
|
||||
position: newNodePositon,
|
||||
},
|
||||
};
|
||||
|
||||
this.$store.commit('updateNodeProperties', updateInformation);
|
||||
});
|
||||
}
|
||||
},
|
||||
filter: '.node-description, .node-description .node-name, .node-description .node-subtitle',
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
isCtrlKeyPressed (e: MouseEvent | KeyboardEvent): boolean {
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
export const MAX_DISPLAY_DATA_SIZE = 204800;
|
||||
export const MAX_DISPLAY_ITEMS_AUTO_ALL = 250;
|
||||
export const NODE_NAME_PREFIX = 'node-';
|
||||
export const PLACEHOLDER_EMPTY_WORKFLOW_ID = '__EMPTY__';
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
:id="'node-' + getNodeIndex(nodeData.name)"
|
||||
:key="getNodeIndex(nodeData.name)"
|
||||
:name="nodeData.name"
|
||||
:isReadOnly="isReadOnly"
|
||||
:instance="instance"
|
||||
></node>
|
||||
</div>
|
||||
|
@ -102,6 +103,9 @@
|
|||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import {
|
||||
OverlaySpec,
|
||||
} from 'jsplumb';
|
||||
import { MessageBoxInputData } from 'element-ui/types/message-box';
|
||||
import { jsPlumb, Endpoint, OnConnectionBindInfo } from 'jsplumb';
|
||||
import { NODE_NAME_PREFIX, PLACEHOLDER_EMPTY_WORKFLOW_ID } from '@/constants';
|
||||
|
@ -1013,21 +1017,9 @@ export default mixins(
|
|||
}
|
||||
},
|
||||
initNodeView () {
|
||||
this.instance.importDefaults({
|
||||
// notice the 'curviness' argument to this Bezier curve.
|
||||
// the curves on this page are far smoother
|
||||
// than the curves on the first demo, which use the default curviness value.
|
||||
// Connector: ["Bezier", { curviness: 80 }],
|
||||
Connector: ['Bezier', { curviness: 40 }],
|
||||
// @ts-ignore
|
||||
Endpoint: ['Dot', { radius: 5 }],
|
||||
DragOptions: { cursor: 'pointer', zIndex: 5000 },
|
||||
PaintStyle: { strokeWidth: 2, stroke: '#334455' },
|
||||
EndpointStyle: { radius: 9, fill: '#acd', stroke: 'red' },
|
||||
// EndpointStyle: {},
|
||||
HoverPaintStyle: { stroke: '#ff6d5a', lineWidth: 4 },
|
||||
EndpointHoverStyle: { fill: '#ff6d5a', stroke: '#acd' },
|
||||
ConnectionOverlays: [
|
||||
const connectionOverlays: OverlaySpec[] = [];
|
||||
if (this.isReadOnly === false) {
|
||||
connectionOverlays.push.apply(connectionOverlays, [
|
||||
[
|
||||
'Arrow',
|
||||
{
|
||||
|
@ -1045,7 +1037,24 @@ export default mixins(
|
|||
location: 0.5,
|
||||
},
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
this.instance.importDefaults({
|
||||
// notice the 'curviness' argument to this Bezier curve.
|
||||
// the curves on this page are far smoother
|
||||
// than the curves on the first demo, which use the default curviness value.
|
||||
// Connector: ["Bezier", { curviness: 80 }],
|
||||
Connector: ['Bezier', { curviness: 40 }],
|
||||
// @ts-ignore
|
||||
Endpoint: ['Dot', { radius: 5 }],
|
||||
DragOptions: { cursor: 'pointer', zIndex: 5000 },
|
||||
PaintStyle: { strokeWidth: 2, stroke: '#334455' },
|
||||
EndpointStyle: { radius: 9, fill: '#acd', stroke: 'red' },
|
||||
// EndpointStyle: {},
|
||||
HoverPaintStyle: { stroke: '#ff6d5a', lineWidth: 4 },
|
||||
EndpointHoverStyle: { fill: '#ff6d5a', stroke: '#acd' },
|
||||
ConnectionOverlays: connectionOverlays,
|
||||
Container: '#node-view',
|
||||
});
|
||||
|
||||
|
@ -1100,41 +1109,43 @@ export default mixins(
|
|||
info.connection.setConnector(['Straight']);
|
||||
}
|
||||
|
||||
// Display the connection-delete button only on hover
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
info.connection.bind('mouseover', (connection: IConnection) => {
|
||||
if (timer !== undefined) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
const overlay = info.connection.getOverlay('remove-connection');
|
||||
overlay.setVisible(true);
|
||||
});
|
||||
info.connection.bind('mouseout', (connection: IConnection) => {
|
||||
timer = setTimeout(() => {
|
||||
const overlay = info.connection.getOverlay('remove-connection');
|
||||
overlay.setVisible(false);
|
||||
timer = undefined;
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
info.connection.removeOverlay('drop-add-node');
|
||||
|
||||
// @ts-ignore
|
||||
info.connection.addOverlay([
|
||||
'Label',
|
||||
{
|
||||
id: 'remove-connection',
|
||||
label: '<span class="delete-connection clickable" title="Delete Connection">x</span>',
|
||||
cssClass: 'remove-connection-label',
|
||||
visible: false,
|
||||
events: {
|
||||
mousedown: () => {
|
||||
this.__removeConnectionByConnectionInfo(info, true);
|
||||
if (this.isReadOnly === false) {
|
||||
// Display the connection-delete button only on hover
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
info.connection.bind('mouseover', (connection: IConnection) => {
|
||||
if (timer !== undefined) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
const overlay = info.connection.getOverlay('remove-connection');
|
||||
overlay.setVisible(true);
|
||||
});
|
||||
info.connection.bind('mouseout', (connection: IConnection) => {
|
||||
timer = setTimeout(() => {
|
||||
const overlay = info.connection.getOverlay('remove-connection');
|
||||
overlay.setVisible(false);
|
||||
timer = undefined;
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
info.connection.addOverlay([
|
||||
'Label',
|
||||
{
|
||||
id: 'remove-connection',
|
||||
label: '<span class="delete-connection clickable" title="Delete Connection">x</span>',
|
||||
cssClass: 'remove-connection-label',
|
||||
visible: false,
|
||||
events: {
|
||||
mousedown: () => {
|
||||
this.__removeConnectionByConnectionInfo(info, true);
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
]);
|
||||
}
|
||||
|
||||
// Display input names if they exist on connection
|
||||
const targetNodeTypeData: INodeTypeDescription = this.$store.getters.nodeType(targetNode.type);
|
||||
|
@ -1329,6 +1340,7 @@ export default mixins(
|
|||
// @ts-ignore
|
||||
this.instance.connect({
|
||||
uuids: uuid,
|
||||
detachable: !this.isReadOnly,
|
||||
});
|
||||
} else {
|
||||
// When nodes get connected it gets saved automatically to the storage
|
||||
|
|
|
@ -12,12 +12,20 @@ export class AgileCrmApi implements ICredentialType {
|
|||
name: 'email',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
displayName: 'API Key',
|
||||
name: 'apiKey',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Subdomain',
|
||||
name: 'subdomain',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
placeholder: 'example',
|
||||
description: 'If the domain is https://example.agilecrm.com "example" would have to be entered.',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
|
|||
username: credentials!.email as string,
|
||||
password: credentials!.apiKey as string
|
||||
},
|
||||
uri: uri || `https://n8nio.agilecrm.com/dev/${endpoint}`,
|
||||
uri: uri || `https://${credentials!.subdomain}.agilecrm.com/dev/${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
|
@ -45,8 +45,9 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
|
|||
}
|
||||
|
||||
export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const baseUri = 'https://n8nio.agilecrm.com/dev/';
|
||||
|
||||
const credentials = this.getCredentials('agileCrmApi');
|
||||
const baseUri = `https://${credentials!.subdomain}.agilecrm.com/dev/`;
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
headers: {
|
||||
|
|
|
@ -933,7 +933,7 @@ export class GoogleDrive implements INodeType {
|
|||
|
||||
let queryCorpora = '';
|
||||
if (options.corpora) {
|
||||
queryCorpora = (options.corpora as string[]).join(', ');
|
||||
queryCorpora = options.corpora as string;
|
||||
}
|
||||
|
||||
let driveId : string | undefined;
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions
|
||||
} from 'n8n-core';
|
||||
|
||||
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {} ,headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('mailchimpApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
|
@ -27,6 +33,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
|||
const options: OptionsWithUri = {
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
qs,
|
||||
uri: `https://${datacenter}.${host}${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
@ -34,19 +41,36 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
|||
if (Object.keys(body).length !== 0) {
|
||||
options.body = body;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
||||
|
||||
if (errorMessage !== undefined) {
|
||||
throw errorMessage;
|
||||
if (error.response.body && error.response.body.detail) {
|
||||
throw new Error(`Mailchimp Error response [${error.statusCode}]: ${error.response.body.detail}`);
|
||||
}
|
||||
throw error.response.body;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function mailchimpApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, endpoint: string, method: string, propertyName: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
|
||||
query.offset = 0;
|
||||
query.count = 500;
|
||||
|
||||
do {
|
||||
responseData = await mailchimpApiRequest.call(this, endpoint, method, body, query);
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
query.offset += query.count;
|
||||
} while (
|
||||
responseData[propertyName] && responseData[propertyName].length !== 0
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -98,9 +98,9 @@ export class Mattermost implements INodeType {
|
|||
description: 'Soft-deletes a channel',
|
||||
},
|
||||
{
|
||||
name: 'Members',
|
||||
name: 'Member',
|
||||
value: 'members',
|
||||
description: 'Returns the members of a channel.',
|
||||
description: 'Get a page of members for a channel.',
|
||||
},
|
||||
{
|
||||
name: 'Restore',
|
||||
|
@ -317,6 +317,23 @@ export class Mattermost implements INodeType {
|
|||
},
|
||||
description: 'The Mattermost Team.',
|
||||
},
|
||||
{
|
||||
displayName: 'Resolve Data',
|
||||
name: 'resolveData',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'channel',
|
||||
],
|
||||
operation: [
|
||||
'members',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description: 'By default the response only contain the ID of the user.<br />If this option gets activated it will resolve the user automatically.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
|
@ -950,6 +967,11 @@ export class Mattermost implements INodeType {
|
|||
value: 'getByEmail',
|
||||
description: 'Get a user by email',
|
||||
},
|
||||
{
|
||||
name: 'Get By ID',
|
||||
value: 'getById',
|
||||
description: 'Get a user by id',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The operation to perform.',
|
||||
|
@ -1113,6 +1135,54 @@ export class Mattermost implements INodeType {
|
|||
default: '',
|
||||
description: `User's email`,
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// user:getById
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'User IDs',
|
||||
name: 'userIds',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'getById',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: `User's ID`,
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'getById',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Since',
|
||||
name: 'since',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'Only return users that have been modified since the given Unix timestamp (in milliseconds).',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -1245,6 +1315,10 @@ export class Mattermost implements INodeType {
|
|||
let resource: string;
|
||||
let requestMethod = 'POST';
|
||||
let returnAll = false;
|
||||
let userIds: string[] = [];
|
||||
|
||||
resource = this.getNodeParameter('resource', 0) as string;
|
||||
operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
// For Post
|
||||
let body: IDataObject;
|
||||
|
@ -1256,9 +1330,6 @@ export class Mattermost implements INodeType {
|
|||
body = {};
|
||||
qs = {};
|
||||
|
||||
resource = this.getNodeParameter('resource', i) as string;
|
||||
operation = this.getNodeParameter('operation', i) as string;
|
||||
|
||||
if (resource === 'channel') {
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------
|
||||
|
@ -1509,6 +1580,25 @@ export class Mattermost implements INodeType {
|
|||
endpoint = `users/email/${email}`;
|
||||
}
|
||||
|
||||
if (operation === 'getById') {
|
||||
// ----------------------------------
|
||||
// user:getById
|
||||
// ----------------------------------
|
||||
userIds = (this.getNodeParameter('userIds', i) as string).split(',') as string[];
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.since) {
|
||||
qs.since = new Date(additionalFields.since as string).getTime();
|
||||
}
|
||||
|
||||
requestMethod = 'POST';
|
||||
|
||||
endpoint = 'users/ids';
|
||||
|
||||
//@ts-ignore
|
||||
body = userIds;
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error(`The resource "${resource}" is not known!`);
|
||||
|
@ -1519,6 +1609,18 @@ export class Mattermost implements INodeType {
|
|||
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
|
||||
} else {
|
||||
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
if (resource === 'channel' && operation === 'members') {
|
||||
const resolveData = this.getNodeParameter('resolveData', i) as boolean;
|
||||
if (resolveData) {
|
||||
const userIds: string[] = [];
|
||||
for (const data of responseData) {
|
||||
userIds.push(data.user_id);
|
||||
}
|
||||
if (userIds.length > 0) {
|
||||
responseData = await apiRequest.call(this, 'POST', 'users/ids', userIds , qs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData);
|
||||
|
|
|
@ -52,3 +52,13 @@ export async function zulipApiRequest(this: IExecuteFunctions | IWebhookFunction
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ export const messageOperations = [
|
|||
|
||||
export const messageFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:sendPrivate */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:sendPrivate */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'To',
|
||||
name: 'to',
|
||||
|
@ -96,9 +96,9 @@ export const messageFields = [
|
|||
},
|
||||
description: 'The content of the message.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:sendStream */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:sendStream */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Stream',
|
||||
name: 'stream',
|
||||
|
@ -163,9 +163,9 @@ export const messageFields = [
|
|||
},
|
||||
description: 'The content of the message.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Message ID',
|
||||
name: 'messageId',
|
||||
|
@ -241,9 +241,9 @@ export const messageFields = [
|
|||
},
|
||||
]
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Message ID',
|
||||
name: 'messageId',
|
||||
|
@ -262,9 +262,9 @@ export const messageFields = [
|
|||
},
|
||||
description: 'Unique identifier for the message.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Message ID',
|
||||
name: 'messageId',
|
||||
|
@ -283,9 +283,9 @@ export const messageFields = [
|
|||
},
|
||||
description: 'Unique identifier for the message.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:updateFile */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* message:updateFile */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Binary Property',
|
||||
name: 'dataBinaryProperty',
|
||||
|
|
496
packages/nodes-base/nodes/Zulip/StreamDescription.ts
Normal file
496
packages/nodes-base/nodes/Zulip/StreamDescription.ts
Normal file
|
@ -0,0 +1,496 @@
|
|||
import { INodeProperties } from "n8n-workflow";
|
||||
|
||||
export const streamOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a stream.',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a stream.',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Get all streams.',
|
||||
},
|
||||
{
|
||||
name: 'Get Subscribed',
|
||||
value: 'getSubscribed',
|
||||
description: 'Get subscribed streams.',
|
||||
},
|
||||
// {
|
||||
// name: 'Update',
|
||||
// value: 'update',
|
||||
// description: 'Update a stream.',
|
||||
// },
|
||||
],
|
||||
default: 'create',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const streamFields = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* stream:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: ' Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: `JSON format parameters for stream creation.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Subscriptions',
|
||||
name: 'subscriptions',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'A list of dictionaries containing the the key name and value specifying the name of the stream to subscribe. If the stream does not exist a new stream is created.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Subscription Properties',
|
||||
name: 'properties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Name of Subscription.',
|
||||
},
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Description of Subscription.',
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Announce',
|
||||
name: 'announce',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'If announce is True and one of the streams specified in subscriptions has to be created (i.e. doesnt exist to begin with), an announcement will be made notifying that a new stream was created.',
|
||||
},
|
||||
{
|
||||
displayName: 'Authorization Errors Fatal',
|
||||
name: 'authorizationErrorsFatal',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'A boolean specifying whether authorization errors (such as when the requesting user is not authorized to access a private stream) should be considered fatal or not. When True, an authorization error is reported as such. When set to False, the returned JSON payload indicates that there was an authorization error, but the response is still considered a successful one.',
|
||||
},
|
||||
{
|
||||
displayName: 'History Public to Subscribers',
|
||||
name: 'historyPublicToSubscribers',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the streams message history should be available to newly subscribed members, or users can only access messages they actually received while subscribed to the stream.',
|
||||
},
|
||||
{
|
||||
displayName: 'Invite Only',
|
||||
name: 'inviteOnly',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'A boolean specifying whether the streams specified in subscriptions are invite-only or not.',
|
||||
},
|
||||
{
|
||||
displayName: 'Principals',
|
||||
name: 'principals',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
description: 'A list of email addresses of the users that will be subscribed/unsubscribed to the streams specified in the subscriptions argument. If not provided, then the requesting user/bot is subscribed.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Principals Properties',
|
||||
name: 'properties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Principal Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Principal email address.',
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Stream Post Policy',
|
||||
name: 'streamPostPolicy',
|
||||
type: 'options',
|
||||
default: '',
|
||||
description: 'Policy for which users can post messages to the stream.',
|
||||
options: [
|
||||
{
|
||||
name: '1',
|
||||
value: 1,
|
||||
description: 'Any user can post.'
|
||||
},
|
||||
{
|
||||
name: '2',
|
||||
value: 2,
|
||||
description: 'Only administrators can post.'
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3,
|
||||
description: 'Only new members can post.'
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* stream:get all */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include All Active',
|
||||
name: 'includeAllActive',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Include all active streams. The user must have administrative privileges to use this parameter.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include Default',
|
||||
name: 'includeDefault',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Include all default streams for the users realm.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include Owner Subscribed',
|
||||
name: 'includeOwnersubscribed',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'If the user is a bot, include all streams that the bots owner is subscribed to.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include Public',
|
||||
name: 'includePublic',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Include all public streams.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include Subscribed',
|
||||
name: 'includeSubscribed',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Include all streams that the user is subscribed to.',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* stream:get subscribed */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'getSubscribed',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include Subscribers',
|
||||
name: 'includeSubscribers',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether each returned stream object should include a subscribers field containing a list of the user IDs of its subscribers.',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* stream:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Stream ID',
|
||||
name: 'streamId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'ID of stream to update.',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: ' Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
description: `JSON format parameters for stream creation.`,
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Announcement Only',
|
||||
name: 'isAnnouncementOnly',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the stream is limited to announcements.',
|
||||
},
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The new description for the stream.',
|
||||
placeholder: 'Place of discussion'
|
||||
},
|
||||
{
|
||||
displayName: 'Is Private',
|
||||
name: 'isPrivate',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Change whether the stream is a private stream.',
|
||||
},
|
||||
{
|
||||
displayName: 'History Public to Subscribers',
|
||||
name: 'historyPublicToSubscribers',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the streams message history should be available to newly subscribed members, or users can only access messages they actually received while subscribed to the stream.',
|
||||
},
|
||||
{
|
||||
displayName: 'New Name',
|
||||
name: 'newName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The new name for the stream.',
|
||||
placeholder: 'Italy'
|
||||
},
|
||||
{
|
||||
displayName: 'Stream Post Policy',
|
||||
name: 'streamPostPolicy',
|
||||
type: 'options',
|
||||
default: '',
|
||||
description: 'Policy for which users can post messages to the stream.',
|
||||
options: [
|
||||
{
|
||||
name: '1',
|
||||
value: 1,
|
||||
description: 'Any user can post.'
|
||||
},
|
||||
{
|
||||
name: '2',
|
||||
value: 2,
|
||||
description: 'Only administrators can post.'
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: 3,
|
||||
description: 'Only new members can post.'
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* stream:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Stream ID',
|
||||
name: 'streamId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'stream',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'ID of stream to delete.',
|
||||
},
|
||||
|
||||
] as INodeProperties[];
|
23
packages/nodes-base/nodes/Zulip/StreamInterface.ts
Normal file
23
packages/nodes-base/nodes/Zulip/StreamInterface.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
export interface IStream {
|
||||
subscriptions?: string;
|
||||
invite_only?: boolean;
|
||||
principals?: string;
|
||||
authorization_errors_fatal?: boolean;
|
||||
history_public_to_subscribers?: boolean;
|
||||
stream_post_policy?: number;
|
||||
announce?: boolean;
|
||||
include_public?: boolean;
|
||||
include_subscribed?: boolean;
|
||||
include_all_active?: boolean;
|
||||
include_default?: boolean;
|
||||
include_owner_subscribed?: boolean;
|
||||
include_subscribers?: boolean;
|
||||
description?: string;
|
||||
new_name?: string;
|
||||
is_private?: boolean;
|
||||
is_announcement_only?: boolean;
|
||||
}
|
||||
|
||||
export interface IPrincipal {
|
||||
email: string;
|
||||
}
|
295
packages/nodes-base/nodes/Zulip/UserDescription.ts
Normal file
295
packages/nodes-base/nodes/Zulip/UserDescription.ts
Normal file
|
@ -0,0 +1,295 @@
|
|||
import { INodeProperties } from "n8n-workflow";
|
||||
|
||||
export const userOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a user.',
|
||||
},
|
||||
{
|
||||
name: 'Deactivate',
|
||||
value: 'deactivate',
|
||||
description: 'Deactivate a user.',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a user.',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Get all users.',
|
||||
},
|
||||
// {
|
||||
// name: 'Update',
|
||||
// value: 'update',
|
||||
// description: 'Update a user.',
|
||||
// },
|
||||
],
|
||||
default: 'create',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const userFields = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The email address of the new user.',
|
||||
},
|
||||
{
|
||||
displayName: 'Full Name',
|
||||
name: 'fullName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The full name of the new user.',
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
name: 'password',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The password of the new user.',
|
||||
},
|
||||
{
|
||||
displayName: 'Short Name',
|
||||
name: 'shortName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The short name of the new user. Not user-visible.',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:get / getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'User ID',
|
||||
name: 'userId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The ID of user to get.',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'get', 'getAll'
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Client Gravatar',
|
||||
name: 'clientGravatar',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the client supports computing gravatars URLs. If enabled, avatar_url will be included in the response only if there is a Zulip avatar, and will be null for users who are using gravatar as their avatar.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Profile Fields',
|
||||
name: 'includeCustomProfileFields',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the client wants custom profile field data to be included in the response.',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'User ID',
|
||||
name: 'userId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The ID of user to update.',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'update'
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Full Name',
|
||||
name: 'fullName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The users full name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Is Admin',
|
||||
name: 'isAdmin',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the target user is an administrator.',
|
||||
},
|
||||
{
|
||||
displayName: 'Is Guest',
|
||||
name: 'isGuest',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the target user is a guest.',
|
||||
},
|
||||
{
|
||||
displayName: 'Profile Data',
|
||||
name: 'profileData',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
description: 'A dictionary containing the to be updated custom profile field data for the user.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Property',
|
||||
name: 'property',
|
||||
values: [
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Id of custom profile data value.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of custom profile data.',
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:deactivate */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'User ID',
|
||||
name: 'userId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'deactivate',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The ID of user to deactivate.',
|
||||
},
|
||||
] as INodeProperties[];
|
11
packages/nodes-base/nodes/Zulip/UserInterface.ts
Normal file
11
packages/nodes-base/nodes/Zulip/UserInterface.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export interface IUser {
|
||||
client_gravatar?: boolean;
|
||||
include_custom_profile_fields?: boolean;
|
||||
full_name?: string;
|
||||
is_admin?: boolean;
|
||||
is_guest?: boolean;
|
||||
profile_data?: [{}];
|
||||
email?: string;
|
||||
password?: string;
|
||||
short_name?: string;
|
||||
}
|
|
@ -21,6 +21,11 @@ import {
|
|||
IMessage,
|
||||
} from './MessageInterface';
|
||||
import { snakeCase } from 'change-case';
|
||||
import { streamFields, streamOperations } from './StreamDescription';
|
||||
import { userOperations, userFields } from './UserDescription';
|
||||
import { IStream, IPrincipal } from './StreamInterface';
|
||||
import { validateJSON } from './GenericFunctions';
|
||||
import { IUser } from './UserInterface';
|
||||
|
||||
export class Zulip implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -53,12 +58,30 @@ export class Zulip implements INodeType {
|
|||
name: 'Message',
|
||||
value: 'message',
|
||||
},
|
||||
{
|
||||
name: 'Stream',
|
||||
value: 'stream',
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
},
|
||||
],
|
||||
default: 'message',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
// MESSAGE
|
||||
...messageOperations,
|
||||
...messageFields,
|
||||
|
||||
// STREAM
|
||||
...streamOperations,
|
||||
...streamFields,
|
||||
|
||||
// USER
|
||||
...userOperations,
|
||||
...userFields
|
||||
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -196,10 +219,222 @@ export class Zulip implements INodeType {
|
|||
}
|
||||
}
|
||||
};
|
||||
responseData = await zulipApiRequest.call(this, 'POST', '/user_uploads', {}, {}, undefined, { formData } );
|
||||
responseData = await zulipApiRequest.call(this, 'POST', '/user_uploads', {}, {}, undefined, { formData });
|
||||
responseData.uri = `${credentials!.url}${responseData.uri}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'stream') {
|
||||
const body: IStream = {};
|
||||
|
||||
if (operation === 'getAll') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.includePublic) {
|
||||
body.include_public = additionalFields.includePublic as boolean;
|
||||
}
|
||||
if (additionalFields.includeSubscribed) {
|
||||
body.include_subscribed = additionalFields.includeSubscribed as boolean;
|
||||
}
|
||||
if (additionalFields.includeAllActive) {
|
||||
body.include_all_active = additionalFields.includeAllActive as boolean;
|
||||
}
|
||||
if (additionalFields.includeDefault) {
|
||||
body.include_default = additionalFields.includeDefault as boolean;
|
||||
}
|
||||
if (additionalFields.includeOwnersubscribed) {
|
||||
body.include_owner_subscribed = additionalFields.includeOwnersubscribed as boolean;
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'GET', `/streams`, body);
|
||||
responseData = responseData.streams;
|
||||
}
|
||||
|
||||
if (operation === 'getSubscribed') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.includeSubscribers) {
|
||||
body.include_subscribers = additionalFields.includeSubscribers as boolean;
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'GET', `/users/me/subscriptions`, body);
|
||||
responseData = responseData.subscriptions;
|
||||
}
|
||||
|
||||
if (operation === 'create') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
const subscriptions = this.getNodeParameter('subscriptions', i) as IDataObject;
|
||||
body.subscriptions = JSON.stringify(subscriptions.properties);
|
||||
|
||||
if (additionalFields.inviteOnly) {
|
||||
body.invite_only = additionalFields.inviteOnly as boolean;
|
||||
}
|
||||
if (additionalFields.principals) {
|
||||
const principals: string[] = [];
|
||||
//@ts-ignore
|
||||
additionalFields.principals.properties.map((principal: IPrincipal) => {
|
||||
principals.push(principal.email);
|
||||
});
|
||||
body.principals = JSON.stringify(principals);
|
||||
}
|
||||
if (additionalFields.authorizationErrorsFatal) {
|
||||
body.authorization_errors_fatal = additionalFields.authorizationErrorsFatal as boolean;
|
||||
}
|
||||
if (additionalFields.historyPublicToSubscribers) {
|
||||
body.history_public_to_subscribers = additionalFields.historyPublicToSubscribers as boolean;
|
||||
}
|
||||
if (additionalFields.streamPostPolicy) {
|
||||
body.stream_post_policy = additionalFields.streamPostPolicy as number;
|
||||
}
|
||||
if (additionalFields.announce) {
|
||||
body.announce = additionalFields.announce as boolean;
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'POST', `/users/me/subscriptions`, body);
|
||||
}
|
||||
|
||||
if (operation === 'delete') {
|
||||
const streamId = this.getNodeParameter('streamId', i) as string;
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'DELETE', `/streams/${streamId}`, {});
|
||||
}
|
||||
|
||||
if (operation === 'update') {
|
||||
const streamId = this.getNodeParameter('streamId', i) as string;
|
||||
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.description) {
|
||||
body.description = additionalFields.description as string;
|
||||
}
|
||||
if (additionalFields.newName) {
|
||||
body.new_name = additionalFields.newName as string;
|
||||
}
|
||||
if (additionalFields.isPrivate) {
|
||||
body.is_private = additionalFields.isPrivate as boolean;
|
||||
}
|
||||
if (additionalFields.isAnnouncementOnly) {
|
||||
body.is_announcement_only = additionalFields.isAnnouncementOnly as boolean;
|
||||
}
|
||||
if (additionalFields.streamPostPolicy) {
|
||||
body.stream_post_policy = additionalFields.streamPostPolicy as number;
|
||||
}
|
||||
if (additionalFields.historyPublicToSubscribers) {
|
||||
body.history_public_to_subscribers = additionalFields.historyPublicToSubscribers as boolean;
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'PATCH', `/streams/${streamId}`, body);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'user') {
|
||||
const body: IUser = {};
|
||||
|
||||
if (operation === 'get') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.clientGravatar) {
|
||||
body.client_gravatar = additionalFields.client_gravatar as boolean;
|
||||
}
|
||||
if (additionalFields.includeCustomProfileFields) {
|
||||
body.include_custom_profile_fields = additionalFields.includeCustomProfileFields as boolean;
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'GET', `/users/${userId}`, body);
|
||||
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.clientGravatar) {
|
||||
body.client_gravatar = additionalFields.client_gravatar as boolean;
|
||||
}
|
||||
if (additionalFields.includeCustomProfileFields) {
|
||||
body.include_custom_profile_fields = additionalFields.includeCustomProfileFields as boolean;
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'GET', `/users`, body);
|
||||
responseData = responseData.members;
|
||||
}
|
||||
|
||||
if (operation === 'create') {
|
||||
body.email = this.getNodeParameter('email', i) as string;
|
||||
body.password = this.getNodeParameter('password', i) as string;
|
||||
body.full_name = this.getNodeParameter('fullName', i) as string;
|
||||
body.short_name = this.getNodeParameter('shortName', i) as string;
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'POST', `/users`, body);
|
||||
}
|
||||
|
||||
if (operation === 'update') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.fullName) {
|
||||
body.full_name = additionalFields.fullName as string;
|
||||
}
|
||||
if (additionalFields.isAdmin) {
|
||||
body.is_admin = additionalFields.isAdmin as boolean;
|
||||
}
|
||||
if (additionalFields.isGuest) {
|
||||
body.is_guest = additionalFields.isGuest as boolean;
|
||||
}
|
||||
if (additionalFields.profileData) {
|
||||
//@ts-ignore
|
||||
body.profile_data = additionalFields.profileData.properties as [{}];
|
||||
}
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'PATCH', `/users/${userId}`, body);
|
||||
}
|
||||
|
||||
if (operation === 'deactivate') {
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
|
||||
responseData = await zulipApiRequest.call(this, 'DELETE', `/users/${userId}`, body);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue