UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

51 lines (50 loc) 2.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPluginPointSchema = void 0; const js_yaml_1 = __importDefault(require("js-yaml")); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const request_1 = require("./request"); const get_tool_auth_headers_1 = require("./get-tool-auth-headers"); const logger_1 = require("../utils/logger"); const env_1 = require("../utils/env"); // Fallback schema bundled with CLI — used when remote schema endpoint fails. // File is at `<pkgRoot>/schema/developer-plugin.yaml`; both `src/api` (dev) and // `lib/api` (built) sit two levels below the package root. function loadFallbackSchema() { const fallbackPath = path_1.default.resolve(__dirname, '../../schema/developer-plugin.yaml'); const content = fs_extra_1.default.readFileSync(fallbackPath, 'utf8'); return js_yaml_1.default.load(content); } async function getPluginPointSchema(siteDomain, appKey) { if (env_1.env.useLocalSchema) { logger_1.logger.warn('LPM_LOCAL_SCHEMA enabled — bypassing remote schema, using bundled schema/developer-plugin.yaml.'); return loadFallbackSchema(); } try { const authHeaders = await (0, get_tool_auth_headers_1.getToolAuthHeaders)(siteDomain); const schemaYaml = await (0, request_1.request)(`${siteDomain}/goapi/v5/app/development/config/schema?app_key=${appKey}`, { method: 'GET', headers: authHeaders, }); // Convert YAML string to JSON object // Wrap with "integrate_point_schema" key so $ref paths like // "#/integrate_point_schema/definitions/XXX" can resolve correctly in AJV const innerSchema = js_yaml_1.default.load(schemaYaml.integrate_point_schema); return { integrate_point_schema: innerSchema }; } catch (error) { try { const fallback = loadFallbackSchema(); logger_1.logger.warn(`Remote schema unavailable (${error.message}); using bundled fallback.`); return fallback; } catch (fallbackError) { throw new Error(`Failed to get plugin schema: ${error.message}; fallback failed: ${fallbackError.message}`); } } } exports.getPluginPointSchema = getPluginPointSchema;