@neat.is/core 0.10.3 → 0.10.4

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/cli.cjs CHANGED
@@ -51,6 +51,10 @@ function assertBindAuthority(host, token) {
51
51
  if (isLoopbackHost2(host)) return;
52
52
  throw new BindAuthorityError(host);
53
53
  }
54
+ function isBearerDelegated(req) {
55
+ const config = req.routeOptions?.config;
56
+ return config?.bearerDelegated === true;
57
+ }
54
58
  function mountBearerAuth(app, opts) {
55
59
  if (!opts.token || opts.token.length === 0) return;
56
60
  if (opts.trustProxy) return;
@@ -66,6 +70,10 @@ function mountBearerAuth(app, opts) {
66
70
  done();
67
71
  return;
68
72
  }
73
+ if (isBearerDelegated(req)) {
74
+ done();
75
+ return;
76
+ }
69
77
  if (publicRead && PUBLIC_READ_METHODS.has(req.method)) {
70
78
  done();
71
79
  return;
@@ -99,7 +107,7 @@ function readAuthEnv(env = process.env) {
99
107
  publicRead: parseBoolEnv(env.NEAT_PUBLIC_READ)
100
108
  };
101
109
  }
102
- var import_node_crypto, LOOPBACK_HOSTS, BindAuthorityError, PUBLIC_READ_METHODS, DEFAULT_UNAUTH_PATHS, PROJECT_SCOPED_UNAUTH_PATTERN;
110
+ var import_node_crypto, LOOPBACK_HOSTS, BindAuthorityError, PUBLIC_READ_METHODS, DEFAULT_UNAUTH_PATHS, PROJECT_SCOPED_UNAUTH_PATTERN, BEARER_DELEGATED;
103
111
  var init_auth = __esm({
104
112
  "src/auth.ts"() {
105
113
  "use strict";
@@ -129,6 +137,7 @@ var init_auth = __esm({
129
137
  PROJECT_SCOPED_UNAUTH_PATTERN = new RegExp(
130
138
  `^/projects/[^/]+/(?:${DEFAULT_UNAUTH_PATHS.map((p) => p.slice(1)).join("|")})$`
131
139
  );
140
+ BEARER_DELEGATED = { bearerDelegated: true };
132
141
  }
133
142
  });
134
143
 
@@ -24226,6 +24235,19 @@ function registerRoutes(scope, ctx) {
24226
24235
  });
24227
24236
  }
24228
24237
  });
24238
+ scope.post("/repo-sync", async (req, reply) => {
24239
+ const proj = resolveProject(registry, req, reply, ctx.bootstrap, ctx.singleProject);
24240
+ if (!proj) return;
24241
+ const syncNow = ctx.repoSync?.(proj.name);
24242
+ if (!syncNow) {
24243
+ return reply.code(404).send({
24244
+ error: "repo-sync is not running for this project",
24245
+ project: proj.name,
24246
+ hint: "Only a hosted daemon syncs bound repos. On a local daemon, POST /graph/scan re-extracts the project path."
24247
+ });
24248
+ }
24249
+ return reply.code(202).send({ project: proj.name, ...syncNow() });
24250
+ });
24229
24251
  scope.post("/graph/scan", async (req, reply) => {
24230
24252
  const proj = resolveProject(registry, req, reply, ctx.bootstrap, ctx.singleProject);
24231
24253
  if (!proj) return;
@@ -24473,6 +24495,39 @@ function registerRoutes(scope, ctx) {
24473
24495
  }
24474
24496
  });
24475
24497
  }
24498
+ var OTLP_BODY_LIMIT = 16 * 1024 * 1024;
24499
+ function otlpOnRest(getReceiver) {
24500
+ return async function plugin(scope) {
24501
+ scope.removeAllContentTypeParsers();
24502
+ scope.addContentTypeParser(
24503
+ "*",
24504
+ { parseAs: "buffer", bodyLimit: OTLP_BODY_LIMIT },
24505
+ (_req, body, done) => done(null, body)
24506
+ );
24507
+ const relay = async (req, reply) => {
24508
+ const receiver = getReceiver();
24509
+ if (!receiver) {
24510
+ return reply.code(503).header("retry-after", "1").send({ error: "OTLP receiver is starting" });
24511
+ }
24512
+ const headers = { ...req.headers };
24513
+ delete headers["content-length"];
24514
+ delete headers["transfer-encoding"];
24515
+ delete headers.connection;
24516
+ const res = await receiver.inject({
24517
+ method: "POST",
24518
+ url: req.url,
24519
+ headers,
24520
+ payload: req.body
24521
+ });
24522
+ const contentType = res.headers["content-type"];
24523
+ if (contentType !== void 0) void reply.header("content-type", contentType);
24524
+ return reply.code(res.statusCode).send(res.rawPayload);
24525
+ };
24526
+ const route = { config: BEARER_DELEGATED, bodyLimit: OTLP_BODY_LIMIT };
24527
+ scope.post("/v1/traces", route, relay);
24528
+ scope.post("/projects/:project/v1/traces", route, relay);
24529
+ };
24530
+ }
24476
24531
  async function buildApi(opts) {
24477
24532
  const app = (0, import_fastify2.default)({ logger: false, routerOptions: { maxParamLength: 1024 } });
24478
24533
  await app.register(import_cors.default, { origin: true });
@@ -24491,6 +24546,7 @@ async function buildApi(opts) {
24491
24546
  authProxy: trustProxy === true,
24492
24547
  requiresAuth
24493
24548
  }));
24549
+ if (opts.otlpReceiver) await app.register(otlpOnRest(opts.otlpReceiver));
24494
24550
  const startedAt = opts.startedAt ?? Date.now();
24495
24551
  const registry = buildLegacyRegistry(opts);
24496
24552
  const legacyErrorsExplicit = !opts.projects && opts.errorsPath !== void 0;
@@ -24521,6 +24577,7 @@ async function buildApi(opts) {
24521
24577
  bootstrap: opts.bootstrap,
24522
24578
  singleProject: opts.singleProject?.name,
24523
24579
  connectorsHome: opts.connectorsHome,
24580
+ repoSync: opts.repoSync,
24524
24581
  runPoll: opts.runPoll ?? runConnectorPoll
24525
24582
  };
24526
24583
  app.get("/health", async () => {