@couleetech/n8n-nodes-enlightenedmsp
Version:
n8n node for EnlightenedMSP ticketing and workflow automation
57 lines (56 loc) • 1.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphqlBase = void 0;
const axios_1 = __importDefault(require("axios"));
class GraphqlBase {
constructor(endpoint, apiKey, userId) {
this.endpoint = endpoint;
this.apiKey = apiKey;
this.userId = userId;
const headers = {
'Content-Type': 'application/json',
'x-api-key': apiKey,
};
if (userId) {
headers['x-user-id'] = userId;
}
this.client = axios_1.default.create({
baseURL: endpoint,
headers,
});
}
async executeGraphql(query, variables) {
var _a, _b;
try {
const response = await this.client.post('', {
query,
variables,
});
if (response.data.errors) {
throw new Error(response.data.errors[0].message);
}
return response.data.data;
}
catch (error) {
if (error.response) {
throw new Error(`GraphQL request failed: ${((_b = (_a = error.response.data.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || error.message}`);
}
throw error;
}
}
static async getCredentials(executeFunctions) {
const credentials = await executeFunctions.getCredentials('enlightenedMspGraphql');
if (!credentials) {
throw new Error('No credentials provided');
}
return {
endpoint: credentials.endpoint,
apiKey: credentials.apiKey,
userId: credentials.userId,
};
}
}
exports.GraphqlBase = GraphqlBase;