@cobaltcore-dev/aurora 0.6.0 → 0.7.0

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.
@@ -27669,7 +27669,14 @@ var require_esm2 = __commonJS({
27669
27669
  // src/server/index.ts
27670
27670
  var server_exports = {};
27671
27671
  __export(server_exports, {
27672
- createServer: () => createServer
27672
+ auroraRouter: () => auroraRouter,
27673
+ createServer: () => createServer,
27674
+ domainScopedInputSchema: () => domainScopedInputSchema,
27675
+ domainScopedProcedure: () => domainScopedProcedure,
27676
+ projectScopedInputSchema: () => projectScopedInputSchema,
27677
+ projectScopedProcedure: () => projectScopedProcedure,
27678
+ protectedProcedure: () => protectedProcedure,
27679
+ publicProcedure: () => publicProcedure
27673
27680
  });
27674
27681
  module.exports = __toCommonJS(server_exports);
27675
27682
 
@@ -36961,7 +36968,11 @@ var serviceRouters = {
36961
36968
  };
36962
36969
 
36963
36970
  // src/server/routers.ts
36964
- var buildAppRouter = /* @__PURE__ */ __name((policyDir) => mergeRouters(auroraRouter(authRouters), auroraRouter(buildComputeRouters(policyDir)), auroraRouter(buildObjectStorageRouters(policyDir)), auroraRouter(projectRouters), auroraRouter(buildNetworkRouters(policyDir)), auroraRouter(serviceRouters)), "buildAppRouter");
36971
+ var buildBaseRouter = /* @__PURE__ */ __name((policyDir) => mergeRouters(auroraRouter(authRouters), auroraRouter(buildComputeRouters(policyDir)), auroraRouter(buildObjectStorageRouters(policyDir)), auroraRouter(projectRouters), auroraRouter(buildNetworkRouters(policyDir)), auroraRouter(serviceRouters)), "buildBaseRouter");
36972
+ var buildAppRouter = /* @__PURE__ */ __name((policyDir, extraRouters = []) => {
36973
+ if (extraRouters.length === 0) return buildBaseRouter(policyDir);
36974
+ return mergeRouters(buildBaseRouter(policyDir), ...extraRouters);
36975
+ }, "buildAppRouter");
36965
36976
 
36966
36977
  // src/server/context.ts
36967
36978
  var import_signal_openstack2 = __toESM(require_esm2());
@@ -37342,195 +37353,7 @@ var csrfProtection_default = (0, import_fastify_plugin.default)(csrfPlugin, {
37342
37353
  fastify: "5.x"
37343
37354
  });
37344
37355
 
37345
- // src/server/aurora-fastify-plugins/httpMetricsCollector.ts
37346
- var import_fastify_plugin2 = __toESM(require("fastify-plugin"));
37347
- var import_prom_client = require("prom-client");
37348
- var LABEL_NAMES = [
37349
- "status_code",
37350
- "method",
37351
- "route",
37352
- "endpoint_type",
37353
- "project_id"
37354
- ];
37355
- var EXCLUDE_PATHS = [
37356
- "/metrics"
37357
- ];
37358
- async function httpMetricsCollectorPlugin(fastify, options) {
37359
- const prefix = options.prefix || "aurora";
37360
- const excludePaths = options.excludePaths || EXCLUDE_PATHS;
37361
- const registry = options.registry || new import_prom_client.Registry();
37362
- const bffEndpoint = options.bffEndpoint || "/polaris-bff";
37363
- const requestsTotal = new import_prom_client.Counter({
37364
- name: `${prefix}_requests_total`,
37365
- help: "The total number of HTTP requests handled by the application",
37366
- labelNames: LABEL_NAMES,
37367
- registers: [
37368
- registry
37369
- ]
37370
- });
37371
- const requestDurationSeconds = new import_prom_client.Histogram({
37372
- name: `${prefix}_request_duration_seconds`,
37373
- help: "The HTTP response duration of the application",
37374
- labelNames: LABEL_NAMES,
37375
- registers: [
37376
- registry
37377
- ]
37378
- });
37379
- const exceptionsTotal = new import_prom_client.Counter({
37380
- name: `${prefix}_exceptions_total`,
37381
- help: "The total number of exceptions raised by the application",
37382
- labelNames: [
37383
- "exception"
37384
- ],
37385
- registers: [
37386
- registry
37387
- ]
37388
- });
37389
- fastify.addHook("onRequest", async (request) => {
37390
- request.metricsStartTime = process.hrtime.bigint();
37391
- });
37392
- fastify.addHook("onResponse", async (request, reply) => {
37393
- const path3 = request.url.split("?")[0];
37394
- if (excludePaths.some((excludePath) => path3.startsWith(excludePath))) {
37395
- return;
37396
- }
37397
- if (!request.metricsStartTime) {
37398
- fastify.log.debug({
37399
- url: request.url
37400
- }, "Metrics start time missing, skipping metric collection");
37401
- return;
37402
- }
37403
- const endTime = process.hrtime.bigint();
37404
- const duration = Number(endTime - request.metricsStartTime) / 1e9;
37405
- const labels = extractLabels(request, reply, bffEndpoint);
37406
- try {
37407
- requestsTotal.inc(labels);
37408
- requestDurationSeconds.observe(labels, duration);
37409
- } catch (error) {
37410
- fastify.log.error({
37411
- err: error
37412
- }, "Failed to record HTTP metrics");
37413
- }
37414
- });
37415
- fastify.addHook("onError", async (_request, _reply, error) => {
37416
- try {
37417
- exceptionsTotal.inc({
37418
- exception: error.constructor.name
37419
- });
37420
- } catch (err) {
37421
- fastify.log.error({
37422
- err
37423
- }, "Failed to record exception metric");
37424
- }
37425
- });
37426
- fastify.decorate("metricsRegistry", registry);
37427
- }
37428
- __name(httpMetricsCollectorPlugin, "httpMetricsCollectorPlugin");
37429
- function extractLabels(request, reply, bffEndpoint) {
37430
- const urlPath = request.url.split("?")[0];
37431
- let endpointType;
37432
- let route = urlPath;
37433
- let projectId = "";
37434
- if (urlPath.includes(bffEndpoint)) {
37435
- endpointType = "trpc";
37436
- const procedurePath = urlPath.split(bffEndpoint + "/")[1];
37437
- if (procedurePath) {
37438
- const cleanPath = procedurePath.split("?")[0];
37439
- const parts = cleanPath.split(".");
37440
- if (parts.length >= 2) {
37441
- const service = parts[0];
37442
- const action = parts.slice(1).join(".");
37443
- route = `${service}/${action}`;
37444
- } else {
37445
- route = cleanPath;
37446
- }
37447
- }
37448
- const url = new URL(request.url, "http://localhost");
37449
- const inputParam = url.searchParams.get("input");
37450
- if (inputParam) {
37451
- try {
37452
- const input = JSON.parse(inputParam);
37453
- if (input.project_id) {
37454
- projectId = input.project_id;
37455
- } else if (typeof input === "object") {
37456
- const firstKey = Object.keys(input)[0];
37457
- if (firstKey && input[firstKey]?.project_id) {
37458
- projectId = input[firstKey].project_id;
37459
- }
37460
- }
37461
- } catch {
37462
- }
37463
- }
37464
- } else if (urlPath.startsWith("/api/")) {
37465
- endpointType = "api";
37466
- route = normalizeApiPath(urlPath);
37467
- } else if (urlPath.startsWith("/@")) {
37468
- endpointType = "vite-dev";
37469
- route = "vite-dev";
37470
- } else if (urlPath.match(/\.(js|jsx|ts|tsx|mjs|css|json|map)$/)) {
37471
- endpointType = "module";
37472
- const ext = urlPath.split(".").pop() || "unknown";
37473
- route = `*.${ext}`;
37474
- } else if (urlPath.match(/\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot|ico|webp)$/)) {
37475
- endpointType = "asset";
37476
- const ext = urlPath.split(".").pop() || "unknown";
37477
- route = `*.${ext}`;
37478
- } else if (urlPath === "/" || urlPath === "/index.html") {
37479
- endpointType = "spa";
37480
- route = "/";
37481
- } else {
37482
- endpointType = "spa";
37483
- route = normalizeSpaRoute(urlPath);
37484
- const projectMatch = urlPath.match(/^\/projects\/([^/?]+)/);
37485
- if (projectMatch) {
37486
- projectId = projectMatch[1];
37487
- }
37488
- }
37489
- return {
37490
- status_code: reply.statusCode.toString(),
37491
- method: request.method.toLowerCase(),
37492
- route,
37493
- endpoint_type: endpointType,
37494
- project_id: projectId
37495
- };
37496
- }
37497
- __name(extractLabels, "extractLabels");
37498
- function normalizeSpaRoute(path3) {
37499
- const segments = path3.split("/").filter(Boolean);
37500
- if (segments[0] === "projects" && segments.length >= 3) {
37501
- const service = segments[2];
37502
- return `/projects/:id/${service}`;
37503
- }
37504
- if (segments[0] === "accounts" && segments.length >= 2) {
37505
- return "/accounts/:id";
37506
- }
37507
- return "/" + segments.map((segment) => {
37508
- if (segment.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)) {
37509
- return ":id";
37510
- }
37511
- if (segment.match(/^[a-zA-Z0-9_-]{20,}$/)) {
37512
- return ":id";
37513
- }
37514
- return segment;
37515
- }).join("/");
37516
- }
37517
- __name(normalizeSpaRoute, "normalizeSpaRoute");
37518
- function normalizeApiPath(path3) {
37519
- return path3.split("/").map((segment) => {
37520
- if (segment.match(/^\d+$/) || segment.match(/^[0-9a-f-]{36}$/i)) {
37521
- return ":id";
37522
- }
37523
- return segment;
37524
- }).join("/");
37525
- }
37526
- __name(normalizeApiPath, "normalizeApiPath");
37527
- var AuroraHttpMetricsCollector = (0, import_fastify_plugin2.default)(httpMetricsCollectorPlugin, {
37528
- name: "aurora-http-metrics-collector",
37529
- fastify: "5.x"
37530
- });
37531
-
37532
37356
  // src/server/server.ts
37533
- var import_prom_client2 = require("prom-client");
37534
37357
  async function createServer(config) {
37535
37358
  const isProduction = process.env.NODE_ENV === "production";
37536
37359
  const rawBffEndpoint = config.bffEndpoint ?? "/polaris-bff";
@@ -37546,7 +37369,7 @@ async function createServer(config) {
37546
37369
  crossDomainCookie: config.crossDomainCookie,
37547
37370
  insecureCookies: config.insecureCookies
37548
37371
  };
37549
- const appRouter = buildAppRouter(config.policyDir);
37372
+ const appRouter = buildAppRouter(config.policyDir, config.routers ?? []);
37550
37373
  const server = (0, import_fastify.default)({
37551
37374
  logger: true,
37552
37375
  bodyLimit: 1 * 1024 * 1024,
@@ -37559,19 +37382,6 @@ async function createServer(config) {
37559
37382
  server.register(import_cookie2.default, {
37560
37383
  secret: void 0
37561
37384
  });
37562
- const metricsRegistry = new import_prom_client2.Registry();
37563
- await server.register(AuroraHttpMetricsCollector, {
37564
- prefix: "aurora",
37565
- excludePaths: [
37566
- "/metrics"
37567
- ],
37568
- registry: metricsRegistry,
37569
- bffEndpoint
37570
- });
37571
- server.get("/metrics", async (_request, reply) => {
37572
- reply.header("Content-Type", metricsRegistry.contentType);
37573
- return reply.send(await metricsRegistry.metrics());
37574
- });
37575
37385
  await server.register(import_rate_limit.default, {
37576
37386
  max: 200,
37577
37387
  timeWindow: "1 minute"
@@ -37731,7 +37541,14 @@ async function createServer(config) {
37731
37541
  __name(createServer, "createServer");
37732
37542
  // Annotate the CommonJS export names for ESM import in node:
37733
37543
  0 && (module.exports = {
37734
- createServer
37544
+ auroraRouter,
37545
+ createServer,
37546
+ domainScopedInputSchema,
37547
+ domainScopedProcedure,
37548
+ projectScopedInputSchema,
37549
+ projectScopedProcedure,
37550
+ protectedProcedure,
37551
+ publicProcedure
37735
37552
  });
37736
37553
  /*! Bundled license information:
37737
37554
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltcore-dev/aurora",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "description": "Aurora OpenStack dashboard — server and client library",
6
6
  "license": "Apache-2.0",
@@ -64,7 +64,6 @@
64
64
  "fastify-plugin": "^5.1.0",
65
65
  "focus-trap-react": "^12.0.0",
66
66
  "node-fetch": "^3.3.2",
67
- "prom-client": "^15.1.3",
68
67
  "react-error-boundary": "^6.1.0",
69
68
  "react-icons": "^5.6.0",
70
69
  "tailwind-merge": "^3.2.0",