UNPKG

@luka-cat-mimi/n8n-nodes-feishu-project

Version:

飞书项目 N8N 集成插件,支持附件管理等功能

116 lines 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeishuProjectApi = void 0; class FeishuProjectApi { constructor() { this.name = 'feishuProjectApi'; this.displayName = '飞书项目 API'; this.documentationUrl = 'https://project.feishu.cn/b/helpcenter/1p8d7djs/4bsmoql6'; this.icon = 'file:icon.svg'; this.properties = [ { displayName: '飞书项目host', name: 'baseUrl', type: 'string', default: 'project.feishu.cn', required: true, description: '飞书项目的基础host地址,只需要输入host,不需要输入https://', }, { displayName: '插件ID', name: 'pluginId', type: 'string', default: '', required: true, description: '飞书项目插件的ID', }, { displayName: '插件密钥', name: 'pluginSecret', type: 'string', typeOptions: { password: true, }, default: '', required: true, description: '飞书项目插件的密钥', }, { displayName: '用户ID', name: 'userId', type: 'string', default: '', required: true, description: '用户的唯一ID,用于X-USER-KEY头部', }, { displayName: '插件Token', name: 'pluginToken', type: 'hidden', default: '', typeOptions: { expirable: true, }, }, ]; this.authenticate = { type: 'generic', properties: { headers: { 'User-Agent': 'N8N-FeishuProject/1.0.0', 'X-USER-KEY': '={{$credentials.userId}}', 'X-PLUGIN-TOKEN': '={{$credentials.pluginToken}}', }, }, }; this.test = { request: { baseURL: '={{"https://" + $credentials.baseUrl}}', url: '/open_api/authen/plugin_token', method: 'POST', headers: { 'Content-Type': 'application/json', 'User-Agent': 'N8N-FeishuProject/1.0.0', }, body: { plugin_id: '={{$credentials.pluginId}}', plugin_secret: '={{$credentials.pluginSecret}}', }, json: true, }, rules: [ { type: 'responseSuccessBody', properties: { key: 'error.code', value: 10204, message: '飞书项目API认证失败,请检查插件ID和插件密钥', }, }, ], }; } async preAuthentication(credentials) { var _a, _b, _c; const res = (await this.helpers.httpRequest({ method: 'POST', baseURL: `https://${credentials.baseUrl}`, url: '/open_api/authen/plugin_token', headers: { 'Content-Type': 'application/json', 'User-Agent': 'N8N-FeishuProject/1.0.0', }, body: { plugin_id: credentials.pluginId, plugin_secret: credentials.pluginSecret, }, json: true, })); if (!((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.token)) { throw new Error(`授权失败:${((_b = res === null || res === void 0 ? void 0 : res.error) === null || _b === void 0 ? void 0 : _b.code) || 'UNKNOWN'}, ${((_c = res === null || res === void 0 ? void 0 : res.error) === null || _c === void 0 ? void 0 : _c.msg) || '未知错误'}`); } return { pluginToken: res.data.token }; } } exports.FeishuProjectApi = FeishuProjectApi; //# sourceMappingURL=FeishuProjectApi.credentials.js.map