mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
⚡ Fix issues on Strava-Node
This commit is contained in:
parent
95b33662c9
commit
3e56d5fc08
|
@ -1,7 +1,7 @@
|
|||
|
||||
import {
|
||||
INodeProperties,
|
||||
} from "n8n-workflow";
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const activityOperations = [
|
||||
{
|
||||
|
@ -37,9 +37,9 @@ export const activityOperations = [
|
|||
description: 'Get all activity comments',
|
||||
},
|
||||
{
|
||||
name: 'Get Kudoers',
|
||||
value: 'getKudoers',
|
||||
description: 'Get all activity kudoers',
|
||||
name: 'Get Kudos',
|
||||
value: 'getKudos',
|
||||
description: 'Get all activity kudos',
|
||||
},
|
||||
{
|
||||
name: 'Get Laps',
|
||||
|
@ -64,9 +64,9 @@ export const activityOperations = [
|
|||
|
||||
export const activityFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
|
@ -78,7 +78,7 @@ export const activityFields = [
|
|||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create'
|
||||
'create',
|
||||
]
|
||||
},
|
||||
},
|
||||
|
@ -96,7 +96,7 @@ export const activityFields = [
|
|||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create'
|
||||
'create',
|
||||
]
|
||||
},
|
||||
},
|
||||
|
@ -124,14 +124,14 @@ export const activityFields = [
|
|||
displayName: 'Elapsed Time (Seconds)',
|
||||
name: 'elapsedTime',
|
||||
type: 'number',
|
||||
required :true,
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create'
|
||||
'create',
|
||||
]
|
||||
},
|
||||
},
|
||||
|
@ -191,9 +191,10 @@ export const activityFields = [
|
|||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Activity ID',
|
||||
name: 'activityId',
|
||||
|
@ -273,9 +274,10 @@ export const activityFields = [
|
|||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Activity ID',
|
||||
name: 'activityId',
|
||||
|
@ -294,9 +296,10 @@ export const activityFields = [
|
|||
default: '',
|
||||
description: 'ID or email of activity',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Activity ID',
|
||||
name: 'activityId',
|
||||
|
@ -308,10 +311,10 @@ export const activityFields = [
|
|||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'comment',
|
||||
'lap',
|
||||
'kudo',
|
||||
'zone',
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -330,7 +333,7 @@ export const activityFields = [
|
|||
operation: [
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudoers',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
],
|
||||
},
|
||||
|
@ -350,7 +353,7 @@ export const activityFields = [
|
|||
operation: [
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudoers',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
],
|
||||
returnAll: [
|
||||
|
@ -365,9 +368,10 @@ export const activityFields = [
|
|||
default: 50,
|
||||
description: 'How many results to return.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
|
@ -89,4 +89,3 @@ export async function stravaApiRequestAllItems(this: IHookFunctions | ILoadOptio
|
|||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,13 +74,13 @@ export class Strava implements INodeType {
|
|||
if (resource === 'activity') {
|
||||
//https://developers.strava.com/docs/reference/#api-Activities-createActivity
|
||||
if (operation === 'create') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
|
||||
const type = this.getNodeParameter('type', i) as string;
|
||||
const type = this.getNodeParameter('type', i) as string;
|
||||
|
||||
const startDate = this.getNodeParameter('startDate', i) as string;
|
||||
const startDate = this.getNodeParameter('startDate', i) as string;
|
||||
|
||||
const elapsedTime = this.getNodeParameter('elapsedTime', i) as number;
|
||||
const elapsedTime = this.getNodeParameter('elapsedTime', i) as number;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
|
@ -105,33 +105,33 @@ export class Strava implements INodeType {
|
|||
}
|
||||
//https://developers.strava.com/docs/reference/#api-Activities-getActivityById
|
||||
if (operation === 'get') {
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}`);
|
||||
}
|
||||
if (['getLaps', 'getZones', 'getKudoers', 'getComments'].includes(operation)) {
|
||||
if (['getLaps', 'getZones', 'getKudos', 'getComments'].includes(operation)) {
|
||||
|
||||
const path: IDataObject = {
|
||||
'getComments': 'comments',
|
||||
'getZones': 'zones',
|
||||
'getKudoers': 'kudoers',
|
||||
'getKudos': 'kudos',
|
||||
'getLaps': 'laps',
|
||||
};
|
||||
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}/${path[operation]}`);
|
||||
|
||||
if (returnAll === false) {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
//https://developers.mailerlite.com/reference#subscribers
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
if (returnAll) {
|
||||
|
||||
|
@ -144,7 +144,7 @@ export class Strava implements INodeType {
|
|||
}
|
||||
//https://developers.strava.com/docs/reference/#api-Activities-updateActivityById
|
||||
if (operation === 'update') {
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
|
|
|
@ -161,30 +161,45 @@ export class StravaTrigger implements INodeType {
|
|||
try {
|
||||
responseData = await stravaApiRequest.call(this, 'POST', endpoint, body);
|
||||
} catch (error) {
|
||||
const errors = error.response.body.errors;
|
||||
for (error of errors) {
|
||||
// if there is a subscription already created
|
||||
if (error.resource === 'PushSubscription' && error.code === 'already exists') {
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
//get the current subscription
|
||||
const webhooks = await stravaApiRequest.call(this, 'GET', `/push_subscriptions`, {});
|
||||
if (error.response && error.response.body && error.response.body.errors) {
|
||||
const errors = error.response.body.errors;
|
||||
for (error of errors) {
|
||||
// if there is a subscription already created
|
||||
if (error.resource === 'PushSubscription' && error.code === 'already exists') {
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
//get the current subscription
|
||||
const webhooks = await stravaApiRequest.call(this, 'GET', `/push_subscriptions`, {});
|
||||
|
||||
if (options.deleteIfExist) {
|
||||
// delete the subscription
|
||||
await stravaApiRequest.call(this, 'DELETE', `/push_subscriptions/${webhooks[0].id}`);
|
||||
// now there is room create a subscription with the n8n data
|
||||
const body = {
|
||||
callback_url: webhookUrl,
|
||||
verify_token: randomBytes(20).toString('hex') as string,
|
||||
};
|
||||
if (options.deleteIfExist) {
|
||||
// delete the subscription
|
||||
await stravaApiRequest.call(this, 'DELETE', `/push_subscriptions/${webhooks[0].id}`);
|
||||
// now there is room create a subscription with the n8n data
|
||||
const body = {
|
||||
callback_url: webhookUrl,
|
||||
verify_token: randomBytes(20).toString('hex') as string,
|
||||
};
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'POST', `/push_subscriptions`, body);
|
||||
} else {
|
||||
throw new Error(`A subscription already exist [${webhooks[0].callback_url}].
|
||||
responseData = await stravaApiRequest.call(this, 'POST', `/push_subscriptions`, body);
|
||||
} else {
|
||||
throw new Error(`A subscription already exist [${webhooks[0].callback_url}].
|
||||
If you want to delete this subcription and create a new one with the current parameters please go to options and set delete if exist to true`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!responseData) {
|
||||
let errorMessage = '';
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
errorMessage = error.response.body.message;
|
||||
} else {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Strava error response [${error.statusCode}]: ${errorMessage}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (responseData.id === undefined) {
|
||||
|
|
Loading…
Reference in a new issue