@forklaunch/core 0.17.2 → 0.18.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.
@@ -428,6 +428,11 @@ async function discriminateAuthMethod(auth, openTelemetryCollector) {
428
428
  return authMethod;
429
429
  }
430
430
 
431
+ // src/http/guards/hasFeatureChecks.ts
432
+ function hasFeatureChecks(maybeFeatureAuth) {
433
+ return typeof maybeFeatureAuth === "object" && maybeFeatureAuth !== null && "requiredFeatures" in maybeFeatureAuth && Array.isArray(maybeFeatureAuth.requiredFeatures) && maybeFeatureAuth.requiredFeatures.length > 0;
434
+ }
435
+
431
436
  // src/http/guards/hasPermissionChecks.ts
432
437
  function hasPermissionChecks(maybePermissionedAuth) {
433
438
  return typeof maybePermissionedAuth === "object" && maybePermissionedAuth !== null && ("allowedPermissions" in maybePermissionedAuth || "forbiddenPermissions" in maybePermissionedAuth);
@@ -443,6 +448,11 @@ function hasScopeChecks(maybePermissionedAuth) {
443
448
  return typeof maybePermissionedAuth === "object" && maybePermissionedAuth !== null && "requiredScope" in maybePermissionedAuth && maybePermissionedAuth.requiredScope != null;
444
449
  }
445
450
 
451
+ // src/http/guards/hasSubscriptionChecks.ts
452
+ function hasSubscriptionChecks(maybeSubscriptionAuth) {
453
+ return typeof maybeSubscriptionAuth === "object" && maybeSubscriptionAuth !== null && "requireActiveSubscription" in maybeSubscriptionAuth && maybeSubscriptionAuth.requireActiveSubscription === true;
454
+ }
455
+
446
456
  // src/http/telemetry/pinoLogger.ts
447
457
  import { isNever } from "@forklaunch/common";
448
458
  import { trace as trace2 } from "@opentelemetry/api";
@@ -625,6 +635,14 @@ var invalidAuthorizationTokenRoles = [
625
635
  403,
626
636
  "Invalid Authorization roles."
627
637
  ];
638
+ var invalidAuthorizationTokenFeatures = [
639
+ 403,
640
+ "Required features not available."
641
+ ];
642
+ var invalidAuthorizationSubscription = [
643
+ 403,
644
+ "Active subscription required."
645
+ ];
628
646
  var invalidAuthorizationToken = [
629
647
  403,
630
648
  "Invalid Authorization token."
@@ -832,6 +850,34 @@ async function checkAuthorizationToken(req, authorizationMethod, authorizationTo
832
850
  } else {
833
851
  return invalidAuthorizationMethod;
834
852
  }
853
+ if (hasSubscriptionChecks(collapsedAuthorizationMethod)) {
854
+ if (!collapsedAuthorizationMethod.surfaceSubscription) {
855
+ return [500, "No subscription surfacing function provided."];
856
+ }
857
+ const subscription = await collapsedAuthorizationMethod.surfaceSubscription(
858
+ sessionPayload,
859
+ req
860
+ );
861
+ if (!subscription) {
862
+ return invalidAuthorizationSubscription;
863
+ }
864
+ }
865
+ if (hasFeatureChecks(collapsedAuthorizationMethod)) {
866
+ if (!collapsedAuthorizationMethod.surfaceFeatures) {
867
+ return [500, "No features surfacing function provided."];
868
+ }
869
+ const availableFeatures = await collapsedAuthorizationMethod.surfaceFeatures(
870
+ sessionPayload,
871
+ req
872
+ );
873
+ const requiredFeatures = collapsedAuthorizationMethod.requiredFeatures ?? [];
874
+ const missingFeatures = requiredFeatures.filter(
875
+ (feature) => !availableFeatures.has(feature)
876
+ );
877
+ if (missingFeatures.length > 0) {
878
+ return invalidAuthorizationTokenFeatures;
879
+ }
880
+ }
835
881
  }
836
882
  async function parseRequestAuth(req, res, next) {
837
883
  const auth = req.contractDetails.auth;
@@ -1323,7 +1369,8 @@ function resolveRouteMiddlewares(params) {
1323
1369
  params.requestSchema,
1324
1370
  params.responseSchemas,
1325
1371
  params.openTelemetryCollector,
1326
- () => params.routerOptions
1372
+ // Use dynamic lookup from router instance instead of captured params
1373
+ () => params.router ? params.router.routerOptions : params.routerOptions
1327
1374
  ),
1328
1375
  ...params.postEnrichMiddleware,
1329
1376
  parse,
@@ -1599,7 +1646,8 @@ var ForklaunchExpressLikeRouter = class _ForklaunchExpressLikeRouter {
1599
1646
  routerOptions: this.routerOptions,
1600
1647
  postEnrichMiddleware: this.postEnrichMiddleware,
1601
1648
  includeCreateContext: false,
1602
- handlers
1649
+ handlers,
1650
+ router: this
1603
1651
  });
1604
1652
  registrationMethod.bind(this.internal)(
1605
1653
  path,