@axiom-lattice/gateway 2.1.108 → 2.1.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2945,6 +2945,15 @@ async function completeTask(request, reply) {
2945
2945
  }
2946
2946
  }
2947
2947
 
2948
+ // src/controllers/middleware-types.ts
2949
+ import { PluginRegistry } from "@axiom-lattice/core";
2950
+ function middlewareTypesRoutes(fastify2) {
2951
+ fastify2.get("/api/middleware-types", async (_request, reply) => {
2952
+ const metas = PluginRegistry.listMeta();
2953
+ return reply.send(metas);
2954
+ });
2955
+ }
2956
+
2948
2957
  // src/schemas/data-query.ts
2949
2958
  var dataQuerySchema = {
2950
2959
  description: "Execute data query (semantic or SQL)",
@@ -5002,6 +5011,160 @@ function registerMetricsServerConfigRoutes(app2) {
5002
5011
  app2.post("/api/metrics-configs/test-datasources/:datasourceId/meta", testDatasourceMetrics);
5003
5012
  }
5004
5013
 
5014
+ // src/controllers/connections.ts
5015
+ import { ConnectionRegistry, PluginRegistry as PluginRegistry2 } from "@axiom-lattice/core";
5016
+ import { z } from "zod";
5017
+ var createBody = z.object({
5018
+ type: z.string().min(1),
5019
+ key: z.string().min(1),
5020
+ name: z.string().min(1),
5021
+ description: z.string().optional(),
5022
+ config: z.record(z.unknown())
5023
+ });
5024
+ var testOrDiscoverBody = z.object({
5025
+ key: z.string().optional(),
5026
+ config: z.record(z.unknown()).optional()
5027
+ });
5028
+ function getTenant(request) {
5029
+ return request.headers["x-tenant-id"] || "default";
5030
+ }
5031
+ function maskSecrets(config) {
5032
+ const sensitive = /* @__PURE__ */ new Set([
5033
+ "password",
5034
+ "secret",
5035
+ "token",
5036
+ "apikey",
5037
+ "api_key",
5038
+ "session",
5039
+ "privatekey",
5040
+ "private_key",
5041
+ "accesskey",
5042
+ "access_key"
5043
+ ]);
5044
+ const out = {};
5045
+ for (const [k, v] of Object.entries(config)) {
5046
+ out[k] = sensitive.has(k.toLowerCase()) ? "********" : v;
5047
+ }
5048
+ return out;
5049
+ }
5050
+ async function resolveConfig(type, body, tenantId) {
5051
+ if (body.key) {
5052
+ const entry = await ConnectionRegistry.get(type, body.key, tenantId);
5053
+ if (!entry) throw { status: 404, error: `Connection "${body.key}" not found` };
5054
+ return entry.config;
5055
+ }
5056
+ if (body.config) return body.config;
5057
+ throw { status: 400, error: "Either 'key' or 'config' is required" };
5058
+ }
5059
+ function connectionRoutes(fastify2) {
5060
+ fastify2.get("/api/connections", async (request, reply) => {
5061
+ const { type } = request.query;
5062
+ if (!type) return reply.status(400).send({ error: "query 'type' required" });
5063
+ const entries = await ConnectionRegistry.list(type, getTenant(request));
5064
+ return reply.send({
5065
+ success: true,
5066
+ data: { records: entries.map((e) => ({ ...e, config: maskSecrets(e.config) })), total: entries.length }
5067
+ });
5068
+ });
5069
+ fastify2.post("/api/connections", async (request, reply) => {
5070
+ const parsed = createBody.parse(request.body);
5071
+ const entry = await ConnectionRegistry.create({
5072
+ tenantId: getTenant(request),
5073
+ type: parsed.type,
5074
+ key: parsed.key,
5075
+ name: parsed.name,
5076
+ description: parsed.description,
5077
+ config: parsed.config
5078
+ });
5079
+ return reply.status(201).send({
5080
+ success: true,
5081
+ data: { ...entry, config: maskSecrets(entry.config) }
5082
+ });
5083
+ });
5084
+ fastify2.put("/api/connections/:key", async (request, reply) => {
5085
+ const { type } = request.query;
5086
+ if (!type) return reply.status(400).send({ error: "query 'type' required" });
5087
+ const { key } = request.params;
5088
+ const body = request.body;
5089
+ const tenantId = getTenant(request);
5090
+ const existing = await ConnectionRegistry.get(type, key, tenantId);
5091
+ if (!existing) return reply.status(404).send({ error: "not found" });
5092
+ const updates = {};
5093
+ if (body.name !== void 0) updates.name = body.name;
5094
+ if (body.description !== void 0) updates.description = body.description;
5095
+ if (body.config) {
5096
+ updates.config = { ...existing.config, ...body.config };
5097
+ }
5098
+ const entry = await ConnectionRegistry.update(tenantId, type, key, updates);
5099
+ return reply.send({
5100
+ success: true,
5101
+ data: { ...entry, config: maskSecrets(entry?.config ?? {}) }
5102
+ });
5103
+ });
5104
+ fastify2.delete("/api/connections/:key", async (request, reply) => {
5105
+ const { type } = request.query;
5106
+ if (!type) return reply.status(400).send({ error: "query 'type' required" });
5107
+ const { key } = request.params;
5108
+ const ok = await ConnectionRegistry.delete(getTenant(request), type, key);
5109
+ return reply.send({ success: ok });
5110
+ });
5111
+ fastify2.post("/api/connections/test", async (request, reply) => {
5112
+ const { type } = request.query;
5113
+ if (!type) return reply.status(400).send({ error: "query 'type' required" });
5114
+ const plugin = PluginRegistry2.get(type);
5115
+ if (!plugin?.connection?.test) {
5116
+ return reply.status(400).send({ error: "plugin does not support connection testing" });
5117
+ }
5118
+ try {
5119
+ const body = testOrDiscoverBody.parse(request.body);
5120
+ const targetConfig = await resolveConfig(type, body, getTenant(request));
5121
+ const result = await plugin.connection.test(targetConfig);
5122
+ return reply.send(result);
5123
+ } catch (err) {
5124
+ if (err?.status === 404) {
5125
+ return reply.status(404).send(err);
5126
+ }
5127
+ if (err?.status === 400) {
5128
+ return reply.status(400).send(err);
5129
+ }
5130
+ if (err instanceof z.ZodError) {
5131
+ return reply.status(400).send({ error: err.errors });
5132
+ }
5133
+ return reply.status(500).send({
5134
+ ok: false,
5135
+ message: err instanceof Error ? err.message : String(err)
5136
+ });
5137
+ }
5138
+ });
5139
+ fastify2.post("/api/connections/discover", async (request, reply) => {
5140
+ const { type } = request.query;
5141
+ if (!type) return reply.status(400).send({ error: "query 'type' required" });
5142
+ const plugin = PluginRegistry2.get(type);
5143
+ if (!plugin?.connection?.discover) {
5144
+ return reply.status(400).send({ error: "plugin does not support resource discovery" });
5145
+ }
5146
+ try {
5147
+ const body = testOrDiscoverBody.parse(request.body);
5148
+ const targetConfig = await resolveConfig(type, body, getTenant(request));
5149
+ const resources = await plugin.connection.discover(targetConfig);
5150
+ return reply.send({ resources });
5151
+ } catch (err) {
5152
+ if (err?.status === 404) {
5153
+ return reply.status(404).send(err);
5154
+ }
5155
+ if (err?.status === 400) {
5156
+ return reply.status(400).send(err);
5157
+ }
5158
+ if (err instanceof z.ZodError) {
5159
+ return reply.status(400).send({ error: err.errors });
5160
+ }
5161
+ return reply.status(500).send({
5162
+ error: err instanceof Error ? err.message : String(err)
5163
+ });
5164
+ }
5165
+ });
5166
+ }
5167
+
5005
5168
  // src/controllers/eval.ts
5006
5169
  import { getStoreLattice as getStoreLattice11 } from "@axiom-lattice/core";
5007
5170
  import { v4 as uuidv44 } from "uuid";
@@ -6125,7 +6288,7 @@ function registerAuthRoutes(app2, config) {
6125
6288
  }
6126
6289
 
6127
6290
  // src/channels/lark/LarkChannelAdapter.ts
6128
- import { z } from "zod";
6291
+ import { z as z2 } from "zod";
6129
6292
 
6130
6293
  // src/channels/lark/parser.ts
6131
6294
  function parseLarkMessageEvent(payload) {
@@ -6204,11 +6367,11 @@ function wsEventToInbound(event, installationId, tenantId) {
6204
6367
  }
6205
6368
  };
6206
6369
  }
6207
- var larkConfigSchema = z.object({
6208
- appId: z.string(),
6209
- appSecret: z.string(),
6210
- verificationToken: z.string().optional(),
6211
- encryptKey: z.string().optional()
6370
+ var larkConfigSchema = z2.object({
6371
+ appId: z2.string(),
6372
+ appSecret: z2.string(),
6373
+ verificationToken: z2.string().optional(),
6374
+ encryptKey: z2.string().optional()
6212
6375
  });
6213
6376
  var larkChannelAdapter = {
6214
6377
  channel: "lark",
@@ -7250,6 +7413,8 @@ var registerLatticeRoutes = (app2, channelDeps) => {
7250
7413
  registerWorkspaceRoutes(app2);
7251
7414
  registerDatabaseConfigRoutes(app2);
7252
7415
  registerMetricsServerConfigRoutes(app2);
7416
+ connectionRoutes(app2);
7417
+ middlewareTypesRoutes(app2);
7253
7418
  app2.post(
7254
7419
  "/api/data/query",
7255
7420
  { schema: dataQuerySchema },
@@ -7345,6 +7510,9 @@ var registerLatticeRoutes = (app2, channelDeps) => {
7345
7510
  function registerResourceRoutes(app2, controller) {
7346
7511
  app2.get("/s/:token", controller.resolveResource.bind(controller));
7347
7512
  app2.get("/s/:token/*", controller.resolveResource.bind(controller));
7513
+ app2.post("/s/:token/*", controller.resolveResource.bind(controller));
7514
+ app2.put("/s/:token/*", controller.resolveResource.bind(controller));
7515
+ app2.delete("/s/:token/*", controller.resolveResource.bind(controller));
7348
7516
  app2.post("/s/:token/unlock", controller.unlockShare.bind(controller));
7349
7517
  app2.options("/s/:token", async (_req, reply) => {
7350
7518
  reply.header("Access-Control-Allow-Origin", "*");
@@ -7352,6 +7520,12 @@ function registerResourceRoutes(app2, controller) {
7352
7520
  reply.header("Access-Control-Allow-Headers", "Content-Type");
7353
7521
  return reply.status(204).send();
7354
7522
  });
7523
+ const dirFile = controller.resolveDirectFile.bind(controller);
7524
+ app2.get("/f/:tid/:wid/:pid", dirFile);
7525
+ app2.get("/f/:tid/:wid/:pid/*", dirFile);
7526
+ app2.post("/f/:tid/:wid/:pid/*", dirFile);
7527
+ app2.put("/f/:tid/:wid/:pid/*", dirFile);
7528
+ app2.delete("/f/:tid/:wid/:pid/*", dirFile);
7355
7529
  app2.post("/api/resources/share", controller.createShare.bind(controller));
7356
7530
  app2.get("/api/resources/shares", controller.listShares.bind(controller));
7357
7531
  app2.patch("/api/resources/share/:token", controller.updateShare.bind(controller));
@@ -8196,9 +8370,7 @@ function initializeLogger(config) {
8196
8370
  }
8197
8371
  var app = fastify({
8198
8372
  logger: false,
8199
- // 禁用内置日志记录器
8200
8373
  bodyLimit: Number(process.env.BODY_LIMIT) || 50 * 1024 * 1024
8201
- // Default 50MB, configurable via BODY_LIMIT env var
8202
8374
  });
8203
8375
  app.addContentTypeParser("application/json", { parseAs: "string" }, function(request, body, done) {
8204
8376
  if (request.method === "DELETE" || !body || body.length === 0) {
@@ -8232,6 +8404,7 @@ app.addHook("preHandler", async (request, reply) => {
8232
8404
  if (request.url.startsWith("/s/")) return;
8233
8405
  const urlPath = request.url.split("?")[0];
8234
8406
  if (urlPath.includes("/viewfile") || urlPath.includes("/downloadfile") || urlPath.includes("/uploadfile")) return;
8407
+ if (urlPath.startsWith("/f/") || urlPath === "/f") return;
8235
8408
  return reply.status(401).send({
8236
8409
  success: false,
8237
8410
  error: "Unauthorized - Missing or invalid token"
@@ -8415,7 +8588,7 @@ var start = async (config) => {
8415
8588
  logger4.info("Registered sandbox manager from env configuration");
8416
8589
  }
8417
8590
  try {
8418
- const { ResourceController } = await import("./resources-P4XF764M.mjs");
8591
+ const { ResourceController } = await import("./resources-5POCLGXV.mjs");
8419
8592
  const sharedResourceStore = getStoreLattice16("default", "sharedResource").store;
8420
8593
  const cache = new TokenCache();
8421
8594
  const resourceController = new ResourceController({