@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
148 lines • 6.03 kB
JavaScript
;
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:../nodes/FeishuProject/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: '插件访问凭证类型',
name: 'tokenType',
type: 'options',
options: [
{
name: 'plugin_access_token',
value: 0,
},
{
name: 'virtual_plugin_token',
value: 1,
},
],
default: 0,
required: false,
description: '插件访问凭证类型,默认为 plugin_access_token,virtual_plugin_token是方便开发阶段调试使用',
},
{
displayName: '用户ID',
name: 'userId',
type: 'string',
default: '',
required: true,
description: '用户的唯一ID,当选择使用插件身份凭证时,需要选择指定接口调用的用户 user_key,user_key 可双击用户头像获取。',
},
{
displayName: '鉴权模式 (x-auth-mode)',
name: 'authMode',
type: 'options',
options: [
{
name: '兼容模式',
value: 0,
description: '使用插件访问凭证鉴权时,可能获取到 X-User-Key 对应用户无权限访问的内容',
},
{
name: '强制鉴权模式',
value: 1,
description: '严格使用 X-User-Key 中的用户身份进行权限校验,不会返回该用户没有读取权限的资源',
},
],
default: 1,
required: false,
description: '默认为强制鉴权模式,严格按 X-User-Key 用户身份进行权限校验;值为 0 则使用兼容模式',
},
{
displayName: '插件Token',
name: 'pluginToken',
type: 'hidden',
default: '',
typeOptions: {
expirable: true,
},
},
];
this.authenticate = {
type: 'generic',
properties: {
headers: {
'X-USER-KEY': '={{$credentials.userId}}',
'X-PLUGIN-TOKEN': '={{$credentials.pluginToken}}',
'x-auth-mode': '={{$credentials.authMode !== undefined ? $credentials.authMode : 1}}',
},
},
};
this.test = {
request: {
baseURL: '={{"https://" + $credentials.baseUrl}}',
url: '/open_api/authen/plugin_token',
method: 'POST',
body: {
plugin_id: '={{$credentials.pluginId}}',
plugin_secret: '={{$credentials.pluginSecret}}',
type: '={{$credentials.tokenType !== undefined ? $credentials.tokenType : 0}}',
},
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',
body: {
plugin_id: credentials.pluginId,
plugin_secret: credentials.pluginSecret,
type: credentials.tokenType !== undefined ? credentials.tokenType : 0,
},
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