UNPKG

n8n-nodes-feishu-lark

Version:

n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.

79 lines 3.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = __importDefault(require("crypto")); const aes_cipher_1 = require("../utils/aes-cipher"); const consts_1 = require("../consts"); class RequestHandle { constructor(params) { const { encryptKey, verificationToken, logger } = params; this.verificationToken = verificationToken; this.encryptKey = encryptKey; this.logger = logger; if (encryptKey) { this.aesCipher = new aes_cipher_1.AESCipher(encryptKey); } } parse(data) { var _a, _b; const targetData = (() => { var _a; const { encrypt, ...rest } = data || {}; if (encrypt) { try { return { ...JSON.parse((_a = this.aesCipher) === null || _a === void 0 ? void 0 : _a.decrypt(encrypt)), ...rest, }; } catch (e) { this.logger.error('parse encrypt data failed'); return {}; } } return rest; })(); if ('schema' in targetData) { const { header, event, ...rest } = targetData; return { [consts_1.CEventType]: (_a = targetData === null || targetData === void 0 ? void 0 : targetData.header) === null || _a === void 0 ? void 0 : _a.event_type, ...rest, ...header, ...event, }; } const { event, ...rest } = targetData; return { [consts_1.CEventType]: (_b = targetData === null || targetData === void 0 ? void 0 : targetData.event) === null || _b === void 0 ? void 0 : _b.type, ...event, ...rest, }; } checkIsCardEventValidated(data) { if ('encrypt' in data || 'schema' in data) { return this.checkIsEventValidated(data); } const { 'x-lark-request-timestamp': timestamp, 'x-lark-request-nonce': nonce, 'x-lark-signature': signature, } = data.headers; if (!this.verificationToken) { return true; } const computedSignature = crypto_1.default .createHash('sha1') .update(timestamp + nonce + this.verificationToken + JSON.stringify(data)) .digest('hex'); return computedSignature === signature; } checkIsEventValidated(data) { if (!this.encryptKey) { return true; } const { 'x-lark-request-timestamp': timestamp, 'x-lark-request-nonce': nonce, 'x-lark-signature': signature, } = data.headers; const content = timestamp + nonce + this.encryptKey + JSON.stringify(data); const computedSignature = crypto_1.default.createHash('sha256').update(content).digest('hex'); return computedSignature === signature; } } exports.default = RequestHandle; //# sourceMappingURL=request-handle.js.map