UNPKG

n8n-nodes-larkbase-v3

Version:

n8n node to connect with Larkbase API with UTF-8 support, date filtering, array filter values, text field processing, improved field type handling, pagination fixes, advanced data type conversion, proper date filtering with ExactDate format, updated node

55 lines 2.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccessToken = void 0; const axios_1 = __importDefault(require("axios")); const n8n_workflow_1 = require("n8n-workflow"); async function getAccessToken(credentials) { let appId; let appSecret; if (credentials && credentials.appId && credentials.appSecret) { appId = credentials.appId; appSecret = credentials.appSecret; } else { const creds = await this.getCredentials('larkbaseApi'); if (!creds) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Không tìm thấy credentials!'); } appId = creds.appId; appSecret = creds.appSecret; } if (!appId || !appSecret) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'App ID hoặc App Secret không được cung cấp!'); } const url = 'https://open.larksuite.com/open-apis/auth/v3/tenant_access_token/internal'; const data = { app_id: appId, app_secret: appSecret, }; try { const response = await axios_1.default.post(url, data, { headers: { 'Content-Type': 'application/json; charset=utf-8', }, }); if (response.data.code !== 0) { throw new Error(`Lỗi khi lấy access token: ${response.data.msg || 'Lỗi không xác định'}`); } const accessToken = response.data.tenant_access_token; if (!accessToken) { throw new Error('Không nhận được access token từ API'); } return accessToken; } catch (error) { if (axios_1.default.isAxiosError(error) && error.response) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Lỗi kết nối đến Larkbase API: ${error.message}`, { description: error.response.data.msg || error.message }); } throw error; } } exports.getAccessToken = getAccessToken; //# sourceMappingURL=auth.js.map