UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

63 lines (62 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfig = exports.setConfig = void 0; const local_plugin_config_1 = require("../../../local-plugin-config"); const logger_1 = require("../../../utils/logger"); const validate_tools_1 = require("../../../utils/validate-tools"); const utils_1 = require("../../../v1/utils"); const KV_VALIDATOR = { pluginId: { validator: validate_tools_1.isValidPluginId, interceptor: undefined, }, pluginSecret: { validator: value => { return !!value; }, interceptor: { set: value => { return (0, utils_1.encrypt)(value); }, get: value => { return (0, utils_1.decrypt)(value); }, }, }, siteDomain: { validator: validate_tools_1.isValidURL, interceptor: undefined, }, }; async function setConfig(key, value) { var _a, _b; const supportedKeys = Object.keys(KV_VALIDATOR); if (!supportedKeys.includes(key)) { logger_1.logger.error(`Can't set ${key} by lpm config, only these keys(${supportedKeys.join(',')}) are supported.`); process.exit(1); } if (KV_VALIDATOR[key].validator && !KV_VALIDATOR[key].validator(value)) { logger_1.logger.error(`The ${value} of the ${key} is not valid.`); process.exit(1); } const finalValue = ((_a = KV_VALIDATOR[key].interceptor) === null || _a === void 0 ? void 0 : _a.set) ? (_b = KV_VALIDATOR[key].interceptor) === null || _b === void 0 ? void 0 : _b.set(value) : value; (0, local_plugin_config_1.setLocalPluginConfig)({ [key]: finalValue, }); console.log(`Set ${value} to ${key} successfully.`); } exports.setConfig = setConfig; async function getConfig(key) { const supportedKeys = Object.keys(KV_VALIDATOR); if (!supportedKeys.includes(key)) { logger_1.logger.error(`Can't get ${key} by lpm config, only these keys(${supportedKeys.join(',')}) are supported.`); process.exit(1); } const localPluginConfig = await (0, local_plugin_config_1.getLocalPluginConfig)(); const value = localPluginConfig[key]; console.log(value); return value; } exports.getConfig = getConfig;