From ea95723f37849103d4a4074a39f05633d277d4b9 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 26 Aug 2026 12:35:11 +0800 Subject: [PATCH] Keep only standard environments configuration in Apifox --- package.json | 1 - scripts/sync-apifox-environments.ts | 75 ----------------------------- 2 files changed, 76 deletions(-) delete mode 100644 scripts/sync-apifox-environments.ts diff --git a/package.json b/package.json index ad37c4a..4f1a36f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "bump": "bun run scripts/bump-version.ts", "openapi:bundle": "bun run scripts/bundle-openapi.ts", "openapi:raw": "bun run scripts/generate-raw-openapi.ts", - "apifox:sync-env": "bun run scripts/sync-apifox-environments.ts", "test": "bun test" }, "dependencies": { diff --git a/scripts/sync-apifox-environments.ts b/scripts/sync-apifox-environments.ts deleted file mode 100644 index 74ba6b4..0000000 --- a/scripts/sync-apifox-environments.ts +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bun - -import { execSync } from "node:child_process"; -import { writeFileSync, unlinkSync } from "node:fs"; -import { loadCorpConfigs } from "../src/core/config/loader.js"; -import { defaultSealUrl } from "../src/core/auth/hose.js"; - -const projectId = process.env.APIFOX_PROJECT_ID || "8758920"; -const corps = loadCorpConfigs(); - -console.log(`Loading configurations for ${corps.length} enterprises...`); - -// 1. Get existing environments from Apifox -const envListRaw = execSync(`apifox environment list --project ${projectId}`, { encoding: "utf8" }); -const envList = JSON.parse(envListRaw).data || []; -const envMap = new Map(envList.map(e => [e.name, e])); - -for (const c of corps) { - const envName = `${c.name} (${c.id})`; - const sealUrl = defaultSealUrl(c, c.source); - const hoseBaseUrl = c.source?.baseUrl || "https://app.ekuaibao.com"; - const hoseApiKey = c.source?.key || c.source?.apiKey || ""; - const hoseApiSecret = c.source?.secret || c.source?.apiSecret || ""; - const hoseUserId = c.source?.uid || c.source?.userId || ""; - const sourceType = c.source?.type || "hose"; - - const payload = { - name: envName, - baseUrl: sealUrl, - baseUrls: { - default: sealUrl - }, - parameters: { - header: [ - { - name: "Authorization", - value: "Bearer {{sealToken}}", - enable: true, - description: "Seal AI 租户会话 Token (Bearer)" - } - ], - cookie: [], - query: [], - body: [] - }, - variables: [ - { name: "corpId", value: c.id, type: "string", description: "合思/Seal 企业租户 ID" }, - { name: "sourceType", value: sourceType, type: "string", description: "企业数据源类型 (hose / seal)" }, - { name: "hoseBaseUrl", value: hoseBaseUrl, type: "string", description: "合思系统域名" }, - { name: "hoseApiKey", value: hoseApiKey, type: "string", description: "合思 OpenAPI Key" }, - { name: "hoseApiSecret", value: hoseApiSecret, type: "string", description: "合思 OpenAPI Secret" }, - { name: "hoseUserId", value: hoseUserId, type: "string", description: "合思操作人员工 ID / StaffId" }, - { name: "sealToken", value: "", type: "string", description: "Seal AI 当前有效会话 Token" } - ] - }; - - const tmpFile = `/tmp/env-${c.id}.json`; - writeFileSync(tmpFile, JSON.stringify(payload, null, 2)); - - const existing = envMap.get(envName) || envList.find(e => e.name.includes(c.id)); - let envId = existing?.id; - - if (!envId) { - console.log(`Creating environment: ${envName}`); - const createRes = execSync(`apifox environment create "${envName}" --project ${projectId} --base-url "${sealUrl}"`, { encoding: "utf8" }); - const createData = JSON.parse(createRes).data; - envId = createData.id; - } - - console.log(`Updating environment variables & headers for: ${envName} (ID: ${envId})`); - execSync(`apifox environment update ${envId} --project ${projectId} --file ${tmpFile}`, { encoding: "utf8" }); - unlinkSync(tmpFile); -} - -console.log("All enterprise environments successfully synced to Apifox!");