Skip to content

Commit

Permalink
⚡ fixed nodelinter issues, added credential test, replaced icon
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency committed Mar 30, 2022
1 parent 12bad78 commit 274b692
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Mocean/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from 'n8n-core';

import {
IDataObject, NodeApiError, NodeOperationError,
IDataObject, JsonObject, NodeApiError, NodeOperationError,
} from 'n8n-workflow';

/**
Expand Down Expand Up @@ -47,6 +47,6 @@ export async function moceanApiRequest(this: IHookFunctions | IExecuteFunctions,
try {
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
throw new NodeApiError(this.getNode(), (error as JsonObject));
}
}
55 changes: 49 additions & 6 deletions packages/nodes-base/nodes/Mocean/Mocean.node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { IExecuteFunctions } from 'n8n-core';
import {
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
INodeCredentialTestResult,
INodeExecutionData,
INodeType,
INodeTypeDescription,
JsonObject,
NodeOperationError,
} from 'n8n-workflow';
import { OptionsWithUri } from 'request';

import {moceanApiRequest} from './GenericFunctions';

Expand All @@ -14,7 +19,8 @@ export class Mocean implements INodeType {
description: INodeTypeDescription = {
displayName: 'Mocean',
name: 'mocean',
icon: 'file:mocean.png',
subtitle: `={{$parameter["operation"] + ": " + $parameter["resource"]}}`,
icon: 'file:mocean.svg',
group: ['transform'],
version: 1,
description: 'Send SMS and voice messages via Mocean',
Expand All @@ -27,6 +33,7 @@ export class Mocean implements INodeType {
{
name: 'moceanApi',
required: true,
testedBy: 'moceanApiTest',
},
],
properties: [
Expand All @@ -36,6 +43,7 @@ export class Mocean implements INodeType {
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options:[
{
name: 'SMS',
Expand All @@ -52,6 +60,7 @@ export class Mocean implements INodeType {
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
Expand All @@ -68,7 +77,7 @@ export class Mocean implements INodeType {
},
],
default: 'send',
description: 'The operation to perform.',
description: 'Operation to perform',
},
{
displayName: 'From',
Expand All @@ -88,7 +97,7 @@ export class Mocean implements INodeType {
],
},
},
description: 'The number to which to send the message',
description: 'Number to which to send the message',
},

{
Expand All @@ -109,7 +118,7 @@ export class Mocean implements INodeType {
],
},
},
description: 'The number from which to send the message',
description: 'Number from which to send the message',
},

{
Expand Down Expand Up @@ -169,7 +178,7 @@ export class Mocean implements INodeType {
],
},
},
description: 'The message to send',
description: 'Message to send',
},

{
Expand All @@ -192,7 +201,41 @@ export class Mocean implements INodeType {
description: 'Delivery report URL',
},
],
};

methods = {
credentialTest: {
async moceanApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
const credentials = credential.data;

const body: IDataObject = {};
body['mocean-api-key'] = credentials!['mocean-api-key'];
body['mocean-api-secret'] = credentials!['mocean-api-secret'];
body['mocean-to'] = '6012356789';
body['mocean-resp-format'] = 'JSON';

const options = {
method: 'POST',
form: body,
qs: {},
uri: `https://rest.moceanapi.com/rest/2/nl`,
json: true,
};

try {
await this.helpers.request!(options);
} catch (error) {
return {
status: 'Error',
message: `Connection details not valid: ${(error as JsonObject).message}`,
};
}
return {
status: 'OK',
message: 'Authentication successful!',
};
},
},
};


Expand Down Expand Up @@ -262,7 +305,7 @@ export class Mocean implements INodeType {
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
returnData.push({ error: (error as JsonObject).message });
continue;
}
throw error;
Expand Down
Binary file removed packages/nodes-base/nodes/Mocean/mocean.png
Binary file not shown.
24 changes: 24 additions & 0 deletions packages/nodes-base/nodes/Mocean/mocean.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 274b692

Please sign in to comment.