n8n-nodes-base
Version:
Base nodes of n8n
38 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCredentialsType = void 0;
exports.requestApi = requestApi;
const getCredentialsType = (authentication) => {
let credentialType = '';
switch (authentication) {
case 'botToken':
credentialType = 'discordBotApi';
break;
case 'oAuth2':
credentialType = 'discordOAuth2Api';
break;
case 'webhook':
credentialType = 'discordWebhookApi';
break;
default:
credentialType = 'discordBotApi';
}
return credentialType;
};
exports.getCredentialsType = getCredentialsType;
async function requestApi(options, credentialType, endpoint) {
let response;
if (credentialType === 'discordOAuth2Api' && endpoint !== '/users/@me/guilds') {
const credentials = await this.getCredentials('discordOAuth2Api');
options.headers.Authorization = `Bot ${credentials.botToken}`;
response = await this.helpers.request({ ...options, resolveWithFullResponse: true });
}
else {
response = await this.helpers.requestWithAuthentication.call(this, credentialType, {
...options,
resolveWithFullResponse: true,
});
}
return response;
}
//# sourceMappingURL=helpers.js.map