Minor Zulip-Node fixes

This commit is contained in:
Jan Oberhauser 2020-02-27 23:27:21 +01:00
parent a7845c92df
commit a46b050b15
3 changed files with 7 additions and 7 deletions

View file

@ -3,7 +3,6 @@ import { OptionsWithUri } from 'request';
import { import {
IExecuteFunctions, IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
BINARY_ENCODING
} from 'n8n-core'; } from 'n8n-core';
import { import {
@ -20,14 +19,15 @@ export async function zulipApiRequest(this: IExecuteFunctions | IWebhookFunction
throw new Error('No credentials got returned!'); throw new Error('No credentials got returned!');
} }
const base64Credentials = `${Buffer.from(`${credentials.email}:${credentials.apiKey}`).toString(BINARY_ENCODING)}`;
const endpoint = `${credentials.url}/api/v1`; const endpoint = `${credentials.url}/api/v1`;
let options: OptionsWithUri = { let options: OptionsWithUri = {
auth: {
user: credentials.email as string,
password: credentials.apiKey as string,
},
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${base64Credentials}`,
}, },
method, method,
form: body, form: body,
@ -46,7 +46,7 @@ export async function zulipApiRequest(this: IExecuteFunctions | IWebhookFunction
return await this.helpers.request!(options); return await this.helpers.request!(options);
} catch (error) { } catch (error) {
if (error.response) { if (error.response) {
let errorMessage = error.response.body.message || error.response.body.description || error.message; const errorMessage = error.response.body.message || error.response.body.description || error.message;
throw new Error(`Zulip error response [${error.statusCode}]: ${errorMessage}`); throw new Error(`Zulip error response [${error.statusCode}]: ${errorMessage}`);
} }
throw error; throw error;

View file

@ -1,6 +1,6 @@
export interface IMessage { export interface IMessage {
type?: string; type?: string;
to?: string, to?: string;
topic?: string; topic?: string;
content?: string; content?: string;
propagat_mode?: string; propagat_mode?: string;

View file

@ -195,7 +195,7 @@ export class Zulip implements INodeType {
contentType: items[i].binary[binaryProperty].mimeType, contentType: items[i].binary[binaryProperty].mimeType,
} }
} }
} };
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}`; responseData.uri = `${credentials!.url}${responseData.uri}`;
} }