n8n-nodes-feishu-lark
Version:
n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.
61 lines • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const n8n_workflow_1 = require("n8n-workflow");
class RequestUtils {
static async originRequest(options, clearAccessToken = false) {
const authenticationMethod = this.getNodeParameter('authentication', 0, "larkApi");
const credentials = await this.getCredentials(authenticationMethod);
options.baseURL = credentials.baseUrl;
if (authenticationMethod === "larkApi") {
const additionalCredentialOptions = {
credentialsDecrypted: {
id: "33f755b6-3486-4507-9049-1407c6ddfc91",
name: "larkApi",
type: "lark",
data: {
...credentials,
accessToken: clearAccessToken ? '' : credentials.accessToken,
},
},
};
return this.helpers.httpRequestWithAuthentication.call(this, authenticationMethod, options, additionalCredentialOptions);
}
return this.helpers.httpRequestWithAuthentication.call(this, authenticationMethod, options);
}
static async request(options) {
if (options.json === undefined)
options.json = true;
return RequestUtils.originRequest
.call(this, options)
.then((res) => {
if (res.code !== 0) {
throw new Error(`Request Lark API Error: ${res.code}, ${res.msg}`);
}
return res;
})
.catch((error) => {
if (error.context && error.context.data) {
let errorData = {};
if (error.context.data.code) {
errorData = error.context.data;
}
else {
errorData = JSON.parse(Buffer.from(error.context.data).toString('utf-8'));
}
const { code, msg, error: larkError } = errorData;
if (code === 99991663) {
return RequestUtils.originRequest.call(this, options, true);
}
if (code !== 0) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
message: `Request Lark API Error: ${code}, ${msg}`,
description: (larkError === null || larkError === void 0 ? void 0 : larkError.troubleshooter) || '',
});
}
}
throw error;
});
}
}
exports.default = RequestUtils;
//# sourceMappingURL=RequestUtils.js.map