Skip to content

Commit

Permalink
feat(LoneScale Node): Add LoneScale node and Trigger node (#5146)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanYann authored May 23, 2023
1 parent ec393bc commit 4b85433
Show file tree
Hide file tree
Showing 9 changed files with 745 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/nodes-base/credentials/LoneScaleApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class LoneScaleApi implements ICredentialType {
name = 'loneScaleApi';

displayName = 'LoneScale API';

properties: INodeProperties[] = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string',
typeOptions: { password: true },
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://public-api.lonescale.com',
url: '/users',
},
};
}
46 changes: 46 additions & 0 deletions packages/nodes-base/nodes/LoneScale/GenericFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { OptionsWithUri } from 'request';

import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';

import type { IDataObject, IHookFunctions, IWebhookFunctions } from 'n8n-workflow';
import { BASE_URL } from './constants';

export async function lonescaleApiRequest(
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
body: IDataObject = {},
query: IDataObject = {},
uri?: string,
) {
const endpoint = `${BASE_URL}`;
const credentials = await this.getCredentials('loneScaleApi');
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
'X-API-KEY': credentials?.apiKey,
},
method,
body,
qs: query,
uri: uri || `${endpoint}${resource}`,
json: true,
};
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(query).length) {
delete options.qs;
}

try {
return await this.helpers.requestWithAuthentication.call(this, 'loneScaleApi', options);
} catch (error) {
if (error.response) {
const errorMessage =
error.response.body.message || error.response.body.description || error.message;
throw new Error(`Autopilot error response [${error.statusCode}]: ${errorMessage}`);
}
throw error;
}
}
18 changes: 18 additions & 0 deletions packages/nodes-base/nodes/LoneScale/LoneScale.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"node": "n8n-nodes-base.lonescale",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Sales"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/credentials/lonescale"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.lonescale/"
}
]
}
}
Loading

0 comments on commit 4b85433

Please sign in to comment.