Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/n8n-io/n8n into node-628-…
Browse files Browse the repository at this point in the history
…google-sheets-add-by-name-option-to-the-sheet-selector-not
  • Loading branch information
michael-radency committed Jan 10, 2024
2 parents 5d5ae5e + e796e7f commit 7b2b544
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 12 deletions.
6 changes: 6 additions & 0 deletions packages/@n8n/chat/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# n8n Chat
This is an embeddable Chat widget for n8n. It allows the execution of AI-Powered Workflows through a Chat window.

**Windowed Example**
![n8n Chat Windowed](https://raw.githubusercontent.com/n8n-io/n8n/master/packages/%40n8n/chat/resources/images/windowed.png)

**Fullscreen Example**
![n8n Chat Fullscreen](https://raw.githubusercontent.com/n8n-io/n8n/master/packages/%40n8n/chat/resources/images/fullscreen.png)

## Prerequisites
Create a n8n workflow which you want to execute via chat. The workflow has to be triggered using a **Chat Trigger** node.

Expand Down
8 changes: 4 additions & 4 deletions packages/@n8n/chat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@n8n/chat",
"version": "0.6.0",
"version": "0.6.1",
"scripts": {
"dev": "pnpm run storybook",
"build": "pnpm type-check && pnpm build:vite && pnpm run build:individual && npm run build:prepare",
Expand All @@ -21,13 +21,13 @@
"build:storybook": "storybook build",
"release": "pnpm run build:full && cd dist && pnpm publish"
},
"main": "./chat.umd.cjs",
"main": "./chat.umd.js",
"module": "./chat.es.js",
"types": "./types/index.d.ts",
"exports": {
".": {
"import": "./chat.es.js",
"require": "./chat.umd.cjs"
"import": "./index.mjs",
"require": "./index.js"
},
"./style.css": {
"import": "./style.css",
Expand Down
62 changes: 62 additions & 0 deletions packages/nodes-base/credentials/MongoDb.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,67 @@ export class MongoDb implements ICredentialType {
},
default: 27017,
},
{
displayName: 'Use TLS',
name: 'tls',
type: 'boolean',
default: false,
},
{
displayName: 'CA Certificate',
name: 'ca',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
tls: [true],
},
},
default: '',
},
{
displayName: 'Public Client Certificate',
name: 'cert',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
tls: [true],
},
},
default: '',
},
{
displayName: 'Private Client Key',
name: 'key',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
tls: [true],
},
},
default: '',
},
{
displayName: 'Passphrase',
name: 'passphrase',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
tls: [true],
},
},
default: '',
},
];
}
32 changes: 31 additions & 1 deletion packages/nodes-base/nodes/MongoDb/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { NodeOperationError } from 'n8n-workflow';

import get from 'lodash/get';
import set from 'lodash/set';
import { ObjectId } from 'mongodb';
import { MongoClient, ObjectId } from 'mongodb';
import type {
IMongoCredentials,
IMongoCredentialsType,
IMongoParametricCredentials,
} from './mongoDb.types';

import { createSecureContext } from 'tls';
import { formatPrivateKey } from '../../utils/utilities';

/**
* Standard way of building the MongoDB connection string, unless overridden with a provided string
*
Expand Down Expand Up @@ -140,3 +143,30 @@ export function stringifyObjectIDs(items: IDataObject[]) {
}
});
}

export async function connectMongoClient(connectionString: string, credentials: IDataObject = {}) {
let client: MongoClient;

if (credentials.tls) {
const ca = credentials.ca ? formatPrivateKey(credentials.ca as string) : undefined;
const cert = credentials.cert ? formatPrivateKey(credentials.cert as string) : undefined;
const key = credentials.key ? formatPrivateKey(credentials.key as string) : undefined;
const passphrase = (credentials.passphrase as string) || undefined;

const secureContext = createSecureContext({
ca,
cert,
key,
passphrase,
});

client = await MongoClient.connect(connectionString, {
tls: true,
secureContext,
});
} else {
client = await MongoClient.connect(connectionString);
}

return client;
}
13 changes: 6 additions & 7 deletions packages/nodes-base/nodes/MongoDb/MongoDb.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import type {
UpdateOptions,
Sort,
} from 'mongodb';
import { MongoClient, ObjectId } from 'mongodb';
import { ObjectId } from 'mongodb';
import { generatePairedItemData } from '../../utils/utilities';
import { nodeProperties } from './MongoDbProperties';

import {
buildParameterizedConnString,
connectMongoClient,
prepareFields,
prepareItems,
stringifyObjectIDs,
Expand Down Expand Up @@ -74,7 +75,7 @@ export class MongoDb implements INodeType {
);
}

const client: MongoClient = await MongoClient.connect(connectionString);
const client = await connectMongoClient(connectionString, credentials);

const { databases } = await client.db().admin().listDatabases();

Expand All @@ -100,12 +101,10 @@ export class MongoDb implements INodeType {
};

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const { database, connectionString } = validateAndResolveMongoCredentials(
this,
await this.getCredentials('mongoDb'),
);
const credentials = await this.getCredentials('mongoDb');
const { database, connectionString } = validateAndResolveMongoCredentials(this, credentials);

const client: MongoClient = await MongoClient.connect(connectionString);
const client = await connectMongoClient(connectionString, credentials);

const mdb = client.db(database);

Expand Down

0 comments on commit 7b2b544

Please sign in to comment.