@burdenoff/be-sdk 2026.1021.6 → 2026.1021.8

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.
@@ -1,6 +1,6 @@
1
- export { buildContextWhereClause, buildContextWhereConditions, checkDatabaseHealth, contextMatches, createContextFromSDK, createDatabaseClient, createDatabaseClientFromEnv, extractFieldsFromModel, getAllModelNames, getDatabaseManager, getDatabaseProductName, getDatabaseStats, getDatabaseVersion, getDb, getModelFields, hasModel, initializeDatabase, initializeDatabaseWithConfig, isDatabaseInitialized, loadGeneratedFields, mergeContext, parseContext, resetDatabaseManager, resolvePoolTuningFromEnv, testConnection, toContextJson } from '../chunk-DTE2MHKE.js';
2
- import '../chunk-OBBCR6WY.js';
1
+ export { buildContextWhereClause, buildContextWhereConditions, checkDatabaseHealth, contextMatches, createContextFromSDK, createDatabaseClient, createDatabaseClientFromEnv, extractFieldsFromModel, getAllModelNames, getDatabaseManager, getDatabaseProductName, getDatabaseStats, getDatabaseVersion, getDb, getModelFields, hasModel, initializeDatabase, initializeDatabaseWithConfig, isDatabaseInitialized, loadGeneratedFields, mergeContext, parseContext, resetDatabaseManager, resolvePoolTuningFromEnv, testConnection, toContextJson } from '../chunk-Y2ZUUZNU.js';
3
2
  export { addWorkspaceExtension, buildTransactionContextStatement, defaultWorkspaceExtensionConfig, getCallerTransaction, getWorkspaceContext, injectCreateFields, injectWhereWorkspaceId, maybeSetRlsGuc, maybeTagConnection, resetCallerTransactionStateForTests, runOperationInCallerTransaction, runOperationWithRlsGuc, setWorkspaceContext, withWorkspaceContext, withWorkspaceContextSync } from '../chunk-3Z2VRCT6.js';
3
+ import '../chunk-OBBCR6WY.js';
4
4
  export { PrismaClientWrapper, configurePrismaLogging, createConnectionPool, createPrismaAdapter, createPrismaClient, ensureServiceApplicationName, installAcquireRetry, isTransientAcquireError } from '../chunk-IZZ45AGA.js';
5
5
  import '../chunk-HEAQSZBX.js';
6
6
  import '../chunk-DNULGVN3.js';
@@ -1,5 +1,5 @@
1
- import { W as WorkspaceSecret, I as IActor, J as JWTPayload, S as ServerDefinition, a as ServerInstance, b as ITenant, G as GraphQLContext, Y as YogaPlugin } from '../types-C-6m9NoG.js';
2
- export { A as ActorProvenance, C as ConsentContext, E as ElysiaApp, c as IContextFilterInput, d as IOperationContext, e as IOrganization, f as IProduct, g as IProject, h as ITracking, i as IWorkspace, M as ModuleGraphConfig, P as PrismaClientConstructor, R as RESTEndpoint, j as ServerConfig, k as ServerI18nConfig, l as ServerInfo, V as VerifiedDelegationContext, m as WspaceGraphQLContext } from '../types-C-6m9NoG.js';
1
+ import { W as WorkspaceSecret, I as IActor, J as JWTPayload, S as ServerDefinition, a as ServerInstance, R as RESTEndpoint, b as ITenant, G as GraphQLContext, Y as YogaPlugin } from '../types-C-6m9NoG.js';
2
+ export { A as ActorProvenance, C as ConsentContext, E as ElysiaApp, c as IContextFilterInput, d as IOperationContext, e as IOrganization, f as IProduct, g as IProject, h as ITracking, i as IWorkspace, M as ModuleGraphConfig, P as PrismaClientConstructor, j as ServerConfig, k as ServerI18nConfig, l as ServerInfo, V as VerifiedDelegationContext, m as WspaceGraphQLContext } from '../types-C-6m9NoG.js';
3
3
  import * as jose from 'jose';
4
4
  import { VerifyOptions } from 'jsonwebtoken';
5
5
  import { I as I18n } from '../i18n-DrdPTann.js';
@@ -61,6 +61,26 @@ declare function tenantCheck(context: {
61
61
  declare function createServer(definition: ServerDefinition): Promise<ServerInstance>;
62
62
  declare function configureServerAuth(fetchWorkspaceSecret: FetchWorkspaceSecretFn): void;
63
63
 
64
+ type RawBodyResolution = {
65
+ kind: 'endpoint';
66
+ endpoint: RESTEndpoint;
67
+ } | {
68
+ kind: 'method-not-allowed';
69
+ allowed: string[];
70
+ };
71
+ interface OrdinaryRoute {
72
+ method: string;
73
+ path: string;
74
+ }
75
+ interface RawBodyRouter {
76
+ readonly size: number;
77
+ hasPath(pathname: string): boolean;
78
+ resolve(pathname: string, method: string): RawBodyResolution | null;
79
+ }
80
+ declare function createRawBodyRouter(endpoints: readonly RESTEndpoint[], ordinaryRoutes?: () => readonly OrdinaryRoute[]): RawBodyRouter;
81
+ declare const MAX_IDLE_TIMEOUT_SECONDS = 255;
82
+ declare function extendRequestIdleTimeout(request: Request, seconds: number): boolean;
83
+
64
84
  interface ContextBuilderOptions {
65
85
  getDb: () => unknown;
66
86
  defaultTenant?: ITenant;
@@ -194,4 +214,4 @@ declare function createHumanReadableErrorPlugin(options?: ErrorNormalizationOpti
194
214
  declare function formatHttpError(error: unknown, options?: ErrorNormalizationOptions): HttpErrorResult;
195
215
  declare function createHttpErrorResponse(error: unknown, options?: ErrorNormalizationOptions): Response;
196
216
 
197
- export { type AuthConfig, type ContextBuilderOptions, type ErrorNormalizationOptions, type FetchWorkspaceSecretFn, GraphQLContext, type HttpErrorPayload, type HttpErrorResult, IActor, ITenant, JWTPayload, MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, type MutationAuditPluginOptions, type NormalizedErrorState, ServerDefinition, ServerInstance, type UserFacingErrorOptions, UserFacingGraphQLError, type WorkspaceGuardConfig, WorkspaceSecret, YogaPlugin, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createHttpErrorResponse, createHumanReadableErrorPlugin, createMutationAuditPlugin, createServer, createWorkspaceGuardPlugin, decodeJWT, fetchWorkspaceSecret, formatHttpError, generateSymmetricSecret, getContextOptions, getMutationFieldNames, normalizeError, normalizeExecutionResultErrors, normalizeGraphQLResponse, normalizeGraphQLResponsePayload, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, toUserFacingGraphQLError, verifyJWT, workspaceCheck };
217
+ export { type AuthConfig, type ContextBuilderOptions, type ErrorNormalizationOptions, type FetchWorkspaceSecretFn, GraphQLContext, type HttpErrorPayload, type HttpErrorResult, IActor, ITenant, JWTPayload, MAX_IDLE_TIMEOUT_SECONDS, MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, type MutationAuditPluginOptions, type NormalizedErrorState, type OrdinaryRoute, RESTEndpoint, type RawBodyResolution, type RawBodyRouter, ServerDefinition, ServerInstance, type UserFacingErrorOptions, UserFacingGraphQLError, type WorkspaceGuardConfig, WorkspaceSecret, YogaPlugin, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createHttpErrorResponse, createHumanReadableErrorPlugin, createMutationAuditPlugin, createRawBodyRouter, createServer, createWorkspaceGuardPlugin, decodeJWT, extendRequestIdleTimeout, fetchWorkspaceSecret, formatHttpError, generateSymmetricSecret, getContextOptions, getMutationFieldNames, normalizeError, normalizeExecutionResultErrors, normalizeGraphQLResponse, normalizeGraphQLResponsePayload, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, toUserFacingGraphQLError, verifyJWT, workspaceCheck };
@@ -4,9 +4,9 @@ import { getWorkspaceQuotaRegistry } from '../chunk-WTEHAVBX.js';
4
4
  import { trackOperation, createExplicitActivityScope, runInExplicitActivityScope } from '../chunk-GRGTUP44.js';
5
5
  export { suppressMutationAudit } from '../chunk-GRGTUP44.js';
6
6
  import { setWorkspaceContext, withWorkspaceContext } from '../chunk-3Z2VRCT6.js';
7
+ import { I18n } from '../chunk-EBDHIL7V.js';
7
8
  import { getMetricsRegistry } from '../chunk-AWPNRV3L.js';
8
9
  import { ContextManager } from '../chunk-RZOFS2BQ.js';
9
- import { I18n } from '../chunk-EBDHIL7V.js';
10
10
  import { logger } from '../chunk-RU266375.js';
11
11
  import { __name } from '../chunk-XE4OXN2W.js';
12
12
  import crypto from 'crypto';
@@ -652,6 +652,127 @@ function createQuotaGaugeRefresher(opts) {
652
652
  }
653
653
  __name(createQuotaGaugeRefresher, "createQuotaGaugeRefresher");
654
654
 
655
+ // src/server/raw-body-routes.ts
656
+ var REGEX_SPECIAL = /[.*+?^${}()|[\]\\]/g;
657
+ function compile(path) {
658
+ if (!path.includes(":") && !path.includes("*")) return {
659
+ exact: path,
660
+ regex: null
661
+ };
662
+ const pattern = path.split("/").map((segment) => {
663
+ if (segment === "*") return ".*";
664
+ if (segment.startsWith(":")) return "[^/]+";
665
+ return segment.replace(REGEX_SPECIAL, "\\$&");
666
+ }).join("/");
667
+ return {
668
+ exact: null,
669
+ regex: new RegExp(`^${pattern}$`)
670
+ };
671
+ }
672
+ __name(compile, "compile");
673
+ function matches(route, pathname) {
674
+ return route.exact !== null ? route.exact === pathname : route.regex?.test(pathname) ?? false;
675
+ }
676
+ __name(matches, "matches");
677
+ function keyOf(route) {
678
+ return route.exact ?? route.regex?.source ?? "";
679
+ }
680
+ __name(keyOf, "keyOf");
681
+ var METHOD_ORDER = [
682
+ "GET",
683
+ "HEAD",
684
+ "POST",
685
+ "PUT",
686
+ "PATCH",
687
+ "DELETE",
688
+ "OPTIONS"
689
+ ];
690
+ var rank = /* @__PURE__ */ __name((method) => {
691
+ const index = METHOD_ORDER.indexOf(method);
692
+ return index === -1 ? METHOD_ORDER.length : index;
693
+ }, "rank");
694
+ function createRawBodyRouter(endpoints, ordinaryRoutes = () => []) {
695
+ const routes = [];
696
+ for (const endpoint of endpoints.filter((ep) => ep.rawBody)) {
697
+ const method = endpoint.method.toUpperCase();
698
+ const compiled = compile(endpoint.path);
699
+ let route = routes.find((candidate) => keyOf(candidate) === keyOf(compiled));
700
+ if (!route) {
701
+ route = {
702
+ ...compiled,
703
+ byMethod: /* @__PURE__ */ new Map()
704
+ };
705
+ routes.push(route);
706
+ }
707
+ if (!route.byMethod.has(method)) route.byMethod.set(method, endpoint);
708
+ }
709
+ const ordinaryMatchers = /* @__PURE__ */ new Map();
710
+ const ordinaryVerbsOn = /* @__PURE__ */ __name((pathname) => {
711
+ const verbs = /* @__PURE__ */ new Set();
712
+ for (const route of ordinaryRoutes()) {
713
+ let matcher = ordinaryMatchers.get(route.path);
714
+ if (!matcher) {
715
+ matcher = compile(route.path);
716
+ ordinaryMatchers.set(route.path, matcher);
717
+ }
718
+ if (matches(matcher, pathname)) verbs.add(route.method.toUpperCase());
719
+ }
720
+ return verbs;
721
+ }, "ordinaryVerbsOn");
722
+ return {
723
+ size: routes.length,
724
+ hasPath(pathname) {
725
+ return routes.some((route) => matches(route, pathname));
726
+ },
727
+ resolve(pathname, rawMethod) {
728
+ const method = rawMethod.toUpperCase();
729
+ const candidates = [
730
+ ...routes.filter((route) => route.exact !== null && matches(route, pathname)),
731
+ ...routes.filter((route) => route.exact === null && matches(route, pathname))
732
+ ];
733
+ if (candidates.length === 0) return null;
734
+ for (const route of candidates) {
735
+ const endpoint = route.byMethod.get(method) ?? (method === "HEAD" ? route.byMethod.get("GET") : void 0);
736
+ if (endpoint) return {
737
+ kind: "endpoint",
738
+ endpoint
739
+ };
740
+ }
741
+ const ordinaryVerbs = ordinaryVerbsOn(pathname);
742
+ const servedElsewhere = ordinaryVerbs.has(method) || ordinaryVerbs.has("ALL") || method === "HEAD" && ordinaryVerbs.has("GET");
743
+ if (servedElsewhere) return null;
744
+ const allowed = new Set(ordinaryVerbs);
745
+ for (const route of candidates) for (const verb of route.byMethod.keys()) allowed.add(verb);
746
+ if (allowed.has("GET")) allowed.add("HEAD");
747
+ allowed.add("OPTIONS");
748
+ return {
749
+ kind: "method-not-allowed",
750
+ allowed: [
751
+ ...allowed
752
+ ].sort((a, b) => rank(a) - rank(b))
753
+ };
754
+ }
755
+ };
756
+ }
757
+ __name(createRawBodyRouter, "createRawBodyRouter");
758
+ var requestServers = /* @__PURE__ */ new WeakMap();
759
+ function canTimeout(server) {
760
+ return typeof server?.timeout === "function";
761
+ }
762
+ __name(canTimeout, "canTimeout");
763
+ function rememberRequestServer(request, server) {
764
+ if (canTimeout(server)) requestServers.set(request, server);
765
+ }
766
+ __name(rememberRequestServer, "rememberRequestServer");
767
+ var MAX_IDLE_TIMEOUT_SECONDS = 255;
768
+ function extendRequestIdleTimeout(request, seconds) {
769
+ const server = requestServers.get(request);
770
+ if (!server || !Number.isFinite(seconds) || seconds < 0) return false;
771
+ server.timeout(request, Math.min(Math.floor(seconds), MAX_IDLE_TIMEOUT_SECONDS));
772
+ return true;
773
+ }
774
+ __name(extendRequestIdleTimeout, "extendRequestIdleTimeout");
775
+
655
776
  // src/server/readiness.ts
656
777
  var READINESS_CACHE_MS = 1e3;
657
778
  var READINESS_PROBE_TIMEOUT_MS = 2e3;
@@ -936,34 +1057,8 @@ async function createServer(definition) {
936
1057
  "OPTIONS"
937
1058
  ]
938
1059
  }));
939
- const rawBodyEndpoints = (restEndpoints || []).filter((ep) => ep.rawBody);
940
- const rawBodyPaths = new Map(rawBodyEndpoints.map((ep) => [
941
- ep.path,
942
- ep
943
- ]));
944
- const rawBodyMatchers = rawBodyEndpoints.map((endpoint) => {
945
- const regexPattern = endpoint.path.replace(/:[^/]+/g, "[^/]+");
946
- return {
947
- endpoint,
948
- regexPattern,
949
- regex: new RegExp(`^${regexPattern}$`)
950
- };
951
- });
952
- const matchRawBodyEndpoint = /* @__PURE__ */ __name((pathname) => {
953
- const exactMatch = rawBodyPaths.get(pathname);
954
- if (exactMatch) return exactMatch;
955
- for (const { endpoint, regex, regexPattern } of rawBodyMatchers) {
956
- const isMatch = regex.test(pathname);
957
- logger.debug(`[Server] Checking ${pathname} against pattern ${endpoint.path} (regex: ${regexPattern}), match: ${isMatch}`);
958
- if (isMatch) {
959
- logger.debug(`[Server] Matched ${pathname} to pattern ${endpoint.path}`);
960
- return endpoint;
961
- }
962
- }
963
- logger.debug(`[Server] No raw body endpoint match for ${pathname}, rawBodyEndpoints: ${rawBodyEndpoints.length}`);
964
- return void 0;
965
- }, "matchRawBodyEndpoint");
966
- app.onRequest(async ({ request }) => {
1060
+ const rawBodyRouter = createRawBodyRouter(restEndpoints || [], () => app.routes);
1061
+ app.onRequest(async ({ request, server }) => {
967
1062
  const url = new URL(request.url);
968
1063
  const pathname = url.pathname;
969
1064
  logger.debug(`[Server] onRequest: ${request.method} ${pathname}`);
@@ -981,9 +1076,7 @@ async function createServer(definition) {
981
1076
  }
982
1077
  return headers;
983
1078
  }, "buildCorsHeaders");
984
- const rawBodyEndpoint = isHealthRoute ? void 0 : matchRawBodyEndpoint(pathname);
985
- if (rawBodyEndpoint) {
986
- logger.debug(`[Server] Matched raw body endpoint: ${pathname} -> ${rawBodyEndpoint.path}`);
1079
+ if (!isHealthRoute && rawBodyRouter.size > 0 && rawBodyRouter.hasPath(pathname)) {
987
1080
  const corsHeaders = buildCorsHeaders();
988
1081
  if (request.method === "OPTIONS") {
989
1082
  return new Response(null, {
@@ -991,9 +1084,25 @@ async function createServer(definition) {
991
1084
  headers: corsHeaders
992
1085
  });
993
1086
  }
994
- if (request.method !== rawBodyEndpoint.method) {
995
- return void 0;
1087
+ const resolution = rawBodyRouter.resolve(pathname, request.method);
1088
+ if (!resolution) return void 0;
1089
+ if (resolution.kind === "method-not-allowed") {
1090
+ return new Response(JSON.stringify({
1091
+ error: `Method ${request.method} is not allowed`,
1092
+ allowed: resolution.allowed
1093
+ }), {
1094
+ status: 405,
1095
+ headers: {
1096
+ "Content-Type": "application/json",
1097
+ Allow: resolution.allowed.join(", "),
1098
+ ...corsHeaders
1099
+ }
1100
+ });
996
1101
  }
1102
+ const rawBodyEndpoint = resolution.endpoint;
1103
+ logger.debug(`[Server] Matched raw body endpoint: ${request.method} ${pathname} -> ${rawBodyEndpoint.path}`);
1104
+ rememberRequestServer(request, server);
1105
+ const isHead = request.method === "HEAD";
997
1106
  try {
998
1107
  const rawBody = await request.text();
999
1108
  const context = await buildContext(request);
@@ -1003,7 +1112,7 @@ async function createServer(definition) {
1003
1112
  for (const [key, value] of Object.entries(corsHeaders)) {
1004
1113
  headers2.set(key, value);
1005
1114
  }
1006
- return new Response(result.body, {
1115
+ return new Response(isHead ? null : result.body, {
1007
1116
  status: result.status,
1008
1117
  statusText: result.statusText,
1009
1118
  headers: headers2
@@ -1013,7 +1122,7 @@ async function createServer(definition) {
1013
1122
  "Content-Type": "application/json",
1014
1123
  ...corsHeaders
1015
1124
  });
1016
- return new Response(JSON.stringify(result), {
1125
+ return new Response(isHead ? null : JSON.stringify(result), {
1017
1126
  status: 200,
1018
1127
  headers
1019
1128
  });
@@ -1024,7 +1133,7 @@ async function createServer(definition) {
1024
1133
  serviceName: config.serviceName,
1025
1134
  environment: config.environment
1026
1135
  });
1027
- return new Response(JSON.stringify(formatted.body), {
1136
+ return new Response(isHead ? null : JSON.stringify(formatted.body), {
1028
1137
  status: formatted.status,
1029
1138
  headers: {
1030
1139
  "Content-Type": "application/json",
@@ -1496,6 +1605,6 @@ function createMutationAuditPlugin(options) {
1496
1605
  }
1497
1606
  __name(createMutationAuditPlugin, "createMutationAuditPlugin");
1498
1607
 
1499
- export { MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createMutationAuditPlugin, createServer, decodeJWT, fetchWorkspaceSecret, generateSymmetricSecret, getContextOptions, getMutationFieldNames, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, verifyJWT, workspaceCheck };
1608
+ export { MAX_IDLE_TIMEOUT_SECONDS, MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createMutationAuditPlugin, createRawBodyRouter, createServer, decodeJWT, extendRequestIdleTimeout, fetchWorkspaceSecret, generateSymmetricSecret, getContextOptions, getMutationFieldNames, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, verifyJWT, workspaceCheck };
1500
1609
  //# sourceMappingURL=index.js.map
1501
1610
  //# sourceMappingURL=index.js.map