@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
133 lines • 5.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RequestUtils_1 = __importDefault(require("../../../help/utils/RequestUtils"));
const sharedOptions_1 = require("../../../help/utils/sharedOptions");
const description_1 = require("../../../help/description");
const SpaceTeamsOperate = {
name: '获取空间下团队成员',
value: 'space:teams',
order: 50,
options: [
description_1.DESCRIPTIONS.PROJECT_KEY,
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 50,
typeOptions: {
minValue: 1,
maxValue: 300,
},
displayOptions: {
show: {
returnAll: [false],
},
},
description: 'Max number of results to return',
},
{
displayName: '获取所有用户详情',
name: 'fetchUserDetails',
type: 'boolean',
default: false,
description: 'Whether to automatically fetch details for all users, deduplicating user_keys across all teams and querying user info in bulk',
},
sharedOptions_1.timeoutOnlyOptions,
],
async call(index) {
const project_key = this.getNodeParameter('project_key', index, '', {
extractValue: true,
});
const returnAll = this.getNodeParameter('returnAll', index, false);
const limit = this.getNodeParameter('limit', index, 50);
const fetchUserDetails = this.getNodeParameter('fetchUserDetails', index, false);
const options = this.getNodeParameter('options', index, {});
const fetchPage = async (offset, pageLimit) => {
var _a;
const qs = {
offset,
limit: pageLimit,
};
const response = await RequestUtils_1.default.originRequest.call(this, {
method: 'GET',
url: `/open_api/${project_key}/teams/all`,
qs,
json: true,
timeout: options.timeout,
});
if ((response === null || response === void 0 ? void 0 : response.err_code) !== 0) {
throw new Error(`Feishu Project API Error: ${response === null || response === void 0 ? void 0 : response.err_code}, ${response === null || response === void 0 ? void 0 : response.err_msg}`);
}
return {
data: (response === null || response === void 0 ? void 0 : response.data) || [],
has_more: (_a = response === null || response === void 0 ? void 0 : response.has_more) !== null && _a !== void 0 ? _a : false,
};
};
let teamsData;
if (returnAll) {
teamsData = [];
let offset = 0;
const pageSize = 300;
while (true) {
const { data, has_more } = await fetchPage(offset, pageSize);
teamsData = teamsData.concat(data);
if (!has_more || data.length === 0) {
break;
}
offset++;
}
}
else {
const pageSize = Math.min(limit, 300);
const { data } = await fetchPage(0, pageSize);
teamsData = data.slice(0, limit);
}
if (!fetchUserDetails) {
return teamsData;
}
const allUserKeys = new Set();
for (const team of teamsData) {
if (Array.isArray(team.user_keys)) {
for (const key of team.user_keys) {
allUserKeys.add(key);
}
}
}
if (allUserKeys.size === 0) {
return teamsData;
}
const userKeysArray = Array.from(allUserKeys);
const userDetails = [];
for (let i = 0; i < userKeysArray.length; i += 100) {
const batch = userKeysArray.slice(i, i + 100);
const response = await RequestUtils_1.default.request.call(this, {
method: 'POST',
url: '/open_api/user/query',
body: { user_keys: batch },
timeout: options.timeout,
});
if (Array.isArray(response)) {
userDetails.push(...response);
}
else if (response === null || response === void 0 ? void 0 : response.data) {
userDetails.push(...response.data);
}
}
return {
teams: teamsData,
users: userDetails,
};
},
};
exports.default = SpaceTeamsOperate;
//# sourceMappingURL=SpaceTeamsOperate.js.map