@forklaunch/core 0.17.3 → 0.18.1
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/lib/{contractDetails.types-BKkaBgAN.d.mts → apiDefinition.types-DnUkFmfT.d.mts} +905 -876
- package/lib/{contractDetails.types-BKkaBgAN.d.ts → apiDefinition.types-DnUkFmfT.d.ts} +905 -876
- package/lib/http/index.d.mts +2 -2
- package/lib/http/index.d.ts +2 -2
- package/lib/http/index.js +46 -0
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +46 -0
- package/lib/http/index.mjs.map +1 -1
- package/lib/ws/index.d.mts +2 -2
- package/lib/ws/index.d.ts +2 -2
- package/package.json +12 -12
package/lib/http/index.mjs
CHANGED
|
@@ -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;
|