mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Beeminder Node): Remove unnecessary form data conversion for API token auth to work (#18133)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ export async function createDatapoint(
|
|||||||
) {
|
) {
|
||||||
const endpoint = `/users/me/goals/${data.goalName}/datapoints.json`;
|
const endpoint = `/users/me/goals/${data.goalName}/datapoints.json`;
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'POST', endpoint, data, {}, true);
|
return await beeminderApiRequest.call(this, 'POST', endpoint, data, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllDatapoints(
|
export async function getAllDatapoints(
|
||||||
@@ -55,7 +55,7 @@ export async function updateDatapoint(
|
|||||||
) {
|
) {
|
||||||
const endpoint = `/users/me/goals/${data.goalName}/datapoints/${data.datapointId}.json`;
|
const endpoint = `/users/me/goals/${data.goalName}/datapoints/${data.datapointId}.json`;
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'PUT', endpoint, data, {}, true);
|
return await beeminderApiRequest.call(this, 'PUT', endpoint, data, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteDatapoint(
|
export async function deleteDatapoint(
|
||||||
@@ -80,7 +80,7 @@ export async function createCharge(
|
|||||||
...(data.dryrun && { dryrun: data.dryrun }),
|
...(data.dryrun && { dryrun: data.dryrun }),
|
||||||
};
|
};
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'POST', endpoint, body, {}, true);
|
return await beeminderApiRequest.call(this, 'POST', endpoint, body, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uncleGoal(
|
export async function uncleGoal(
|
||||||
@@ -102,7 +102,7 @@ export async function createAllDatapoints(
|
|||||||
datapoints: data.datapoints,
|
datapoints: data.datapoints,
|
||||||
};
|
};
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'POST', endpoint, body, {}, true);
|
return await beeminderApiRequest.call(this, 'POST', endpoint, body, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSingleDatapoint(
|
export async function getSingleDatapoint(
|
||||||
@@ -162,7 +162,7 @@ export async function createGoal(
|
|||||||
) {
|
) {
|
||||||
const endpoint = '/users/me/goals.json';
|
const endpoint = '/users/me/goals.json';
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'POST', endpoint, data, {}, true);
|
return await beeminderApiRequest.call(this, 'POST', endpoint, data, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateGoal(
|
export async function updateGoal(
|
||||||
@@ -182,7 +182,7 @@ export async function updateGoal(
|
|||||||
) {
|
) {
|
||||||
const endpoint = `/users/me/goals/${data.goalName}.json`;
|
const endpoint = `/users/me/goals/${data.goalName}.json`;
|
||||||
|
|
||||||
return await beeminderApiRequest.call(this, 'PUT', endpoint, data, {}, true);
|
return await beeminderApiRequest.call(this, 'PUT', endpoint, data, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshGoal(
|
export async function refreshGoal(
|
||||||
|
|||||||
@@ -15,26 +15,6 @@ function isValidAuthenticationMethod(value: unknown): value is 'apiToken' | 'oAu
|
|||||||
return typeof value === 'string' && ['apiToken', 'oAuth2'].includes(value);
|
return typeof value === 'string' && ['apiToken', 'oAuth2'].includes(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToFormData(obj: any): Record<string, string> {
|
|
||||||
const result: Record<string, string> = {};
|
|
||||||
for (const [key, value] of Object.entries(obj)) {
|
|
||||||
if (value === null || value === undefined) {
|
|
||||||
// Skip null/undefined values
|
|
||||||
continue;
|
|
||||||
} else if (typeof value === 'boolean') {
|
|
||||||
result[key] = value.toString();
|
|
||||||
} else if (typeof value === 'number') {
|
|
||||||
result[key] = value.toString();
|
|
||||||
} else if (Array.isArray(value)) {
|
|
||||||
// Handle arrays - convert to JSON string for form data
|
|
||||||
result[key] = JSON.stringify(value);
|
|
||||||
} else {
|
|
||||||
result[key] = String(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function beeminderApiRequest(
|
export async function beeminderApiRequest(
|
||||||
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
||||||
method: IHttpRequestMethods,
|
method: IHttpRequestMethods,
|
||||||
@@ -42,7 +22,6 @@ export async function beeminderApiRequest(
|
|||||||
|
|
||||||
body: any = {},
|
body: any = {},
|
||||||
query: IDataObject = {},
|
query: IDataObject = {},
|
||||||
useFormData: boolean = false,
|
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'apiToken');
|
const authenticationMethod = this.getNodeParameter('authentication', 0, 'apiToken');
|
||||||
|
|
||||||
@@ -57,23 +36,14 @@ export async function beeminderApiRequest(
|
|||||||
|
|
||||||
const options: IRequestOptions = {
|
const options: IRequestOptions = {
|
||||||
method,
|
method,
|
||||||
|
body,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: `${BEEMINDER_URI}${endpoint}`,
|
uri: `${BEEMINDER_URI}${endpoint}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (useFormData) {
|
|
||||||
options.formData = convertToFormData(body);
|
|
||||||
} else {
|
|
||||||
options.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Object.keys(body as IDataObject).length) {
|
if (!Object.keys(body as IDataObject).length) {
|
||||||
if (useFormData) {
|
delete options.body;
|
||||||
delete options.formData;
|
|
||||||
} else {
|
|
||||||
delete options.body;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Object.keys(query).length) {
|
if (!Object.keys(query).length) {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal/datapoints.json',
|
'/users/me/goals/testgoal/datapoints.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -78,7 +77,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal/datapoints.json',
|
'/users/me/goals/testgoal/datapoints.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -160,7 +158,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal/datapoints/123.json',
|
'/users/me/goals/testgoal/datapoints/123.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -184,7 +181,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal/datapoints/123.json',
|
'/users/me/goals/testgoal/datapoints/123.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -232,7 +228,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal/datapoints/create_all.json',
|
'/users/me/goals/testgoal/datapoints/create_all.json',
|
||||||
{ datapoints },
|
{ datapoints },
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -387,7 +382,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals.json',
|
'/users/me/goals.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -419,7 +413,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals.json',
|
'/users/me/goals.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -442,7 +435,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal.json',
|
'/users/me/goals/testgoal.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -471,7 +463,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
'/users/me/goals/testgoal.json',
|
'/users/me/goals/testgoal.json',
|
||||||
data,
|
data,
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -564,7 +555,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
amount: 5,
|
amount: 5,
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -591,7 +581,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
dryrun: true,
|
dryrun: true,
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
@@ -616,7 +605,6 @@ describe('Beeminder Node Functions', () => {
|
|||||||
amount: 5,
|
amount: 5,
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
expect(result).toBe(mockResponse);
|
expect(result).toBe(mockResponse);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user