@naylence/runtime 0.3.21 → 0.4.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.
Files changed (88) hide show
  1. package/dist/browser/index.cjs +3368 -1393
  2. package/dist/browser/index.mjs +3324 -1387
  3. package/dist/cjs/naylence/fame/factory-manifest.js +8 -0
  4. package/dist/cjs/naylence/fame/node/node-event-listener.js +4 -0
  5. package/dist/cjs/naylence/fame/security/auth/authorization-profile-factory.js +165 -0
  6. package/dist/cjs/naylence/fame/security/auth/default-policy-authorizer-factory.js +147 -0
  7. package/dist/cjs/naylence/fame/security/auth/default-policy-authorizer.js +291 -0
  8. package/dist/cjs/naylence/fame/security/auth/oauth2-authorizer-factory.js +7 -0
  9. package/dist/cjs/naylence/fame/security/auth/oauth2-authorizer.js +19 -4
  10. package/dist/cjs/naylence/fame/security/auth/policy/authorization-policy-definition.js +60 -0
  11. package/dist/cjs/naylence/fame/security/auth/policy/authorization-policy-factory.js +35 -0
  12. package/dist/cjs/naylence/fame/security/auth/policy/authorization-policy-source-factory.js +35 -0
  13. package/dist/cjs/naylence/fame/security/auth/policy/authorization-policy-source.js +2 -0
  14. package/dist/cjs/naylence/fame/security/auth/policy/authorization-policy.js +2 -0
  15. package/dist/cjs/naylence/fame/security/auth/policy/basic-authorization-policy-factory.js +99 -0
  16. package/dist/cjs/naylence/fame/security/auth/policy/basic-authorization-policy.js +449 -0
  17. package/dist/cjs/naylence/fame/security/auth/policy/index.js +40 -0
  18. package/dist/cjs/naylence/fame/security/auth/policy/local-file-authorization-policy-source-factory.js +101 -0
  19. package/dist/cjs/naylence/fame/security/auth/policy/local-file-authorization-policy-source.js +164 -0
  20. package/dist/cjs/naylence/fame/security/auth/policy/pattern-matcher.js +195 -0
  21. package/dist/cjs/naylence/fame/security/auth/policy/scope-matcher.js +169 -0
  22. package/dist/cjs/naylence/fame/security/auth/policy-authorizer.js +2 -0
  23. package/dist/cjs/naylence/fame/security/default-security-manager.js +94 -0
  24. package/dist/cjs/naylence/fame/security/index.js +22 -1
  25. package/dist/cjs/naylence/fame/security/node-security-profile-factory.js +15 -73
  26. package/dist/cjs/naylence/fame/sentinel/router.js +67 -1
  27. package/dist/cjs/naylence/fame/sentinel/sentinel.js +46 -2
  28. package/dist/cjs/naylence/fame/util/register-runtime-factories.js +2 -0
  29. package/dist/cjs/version.js +2 -2
  30. package/dist/esm/naylence/fame/factory-manifest.js +8 -0
  31. package/dist/esm/naylence/fame/node/node-event-listener.js +4 -0
  32. package/dist/esm/naylence/fame/security/auth/authorization-profile-factory.js +161 -0
  33. package/dist/esm/naylence/fame/security/auth/default-policy-authorizer-factory.js +110 -0
  34. package/dist/esm/naylence/fame/security/auth/default-policy-authorizer.js +287 -0
  35. package/dist/esm/naylence/fame/security/auth/oauth2-authorizer-factory.js +7 -0
  36. package/dist/esm/naylence/fame/security/auth/oauth2-authorizer.js +19 -4
  37. package/dist/esm/naylence/fame/security/auth/policy/authorization-policy-definition.js +57 -0
  38. package/dist/esm/naylence/fame/security/auth/policy/authorization-policy-factory.js +31 -0
  39. package/dist/esm/naylence/fame/security/auth/policy/authorization-policy-source-factory.js +31 -0
  40. package/dist/esm/naylence/fame/security/auth/policy/authorization-policy-source.js +1 -0
  41. package/dist/esm/naylence/fame/security/auth/policy/authorization-policy.js +1 -0
  42. package/dist/esm/naylence/fame/security/auth/policy/basic-authorization-policy-factory.js +62 -0
  43. package/dist/esm/naylence/fame/security/auth/policy/basic-authorization-policy.js +445 -0
  44. package/dist/esm/naylence/fame/security/auth/policy/index.js +20 -0
  45. package/dist/esm/naylence/fame/security/auth/policy/local-file-authorization-policy-source-factory.js +64 -0
  46. package/dist/esm/naylence/fame/security/auth/policy/local-file-authorization-policy-source.js +127 -0
  47. package/dist/esm/naylence/fame/security/auth/policy/pattern-matcher.js +185 -0
  48. package/dist/esm/naylence/fame/security/auth/policy/scope-matcher.js +162 -0
  49. package/dist/esm/naylence/fame/security/auth/policy-authorizer.js +1 -0
  50. package/dist/esm/naylence/fame/security/default-security-manager.js +94 -0
  51. package/dist/esm/naylence/fame/security/index.js +5 -1
  52. package/dist/esm/naylence/fame/security/node-security-profile-factory.js +14 -72
  53. package/dist/esm/naylence/fame/sentinel/router.js +64 -0
  54. package/dist/esm/naylence/fame/sentinel/sentinel.js +47 -3
  55. package/dist/esm/naylence/fame/util/register-runtime-factories.js +2 -0
  56. package/dist/esm/version.js +2 -2
  57. package/dist/node/index.cjs +3364 -1389
  58. package/dist/node/index.mjs +3324 -1387
  59. package/dist/node/node.cjs +3416 -1425
  60. package/dist/node/node.mjs +3376 -1423
  61. package/dist/types/naylence/fame/factory-manifest.d.ts +1 -1
  62. package/dist/types/naylence/fame/node/node-event-listener.d.ts +31 -0
  63. package/dist/types/naylence/fame/security/auth/authorization-profile-factory.d.ts +29 -0
  64. package/dist/types/naylence/fame/security/auth/authorizer.d.ts +37 -0
  65. package/dist/types/naylence/fame/security/auth/default-policy-authorizer-factory.d.ts +55 -0
  66. package/dist/types/naylence/fame/security/auth/default-policy-authorizer.d.ts +99 -0
  67. package/dist/types/naylence/fame/security/auth/oauth2-authorizer-factory.d.ts +2 -0
  68. package/dist/types/naylence/fame/security/auth/oauth2-authorizer.d.ts +2 -0
  69. package/dist/types/naylence/fame/security/auth/policy/authorization-policy-definition.d.ts +166 -0
  70. package/dist/types/naylence/fame/security/auth/policy/authorization-policy-factory.d.ts +38 -0
  71. package/dist/types/naylence/fame/security/auth/policy/authorization-policy-source-factory.d.ts +38 -0
  72. package/dist/types/naylence/fame/security/auth/policy/authorization-policy-source.d.ts +20 -0
  73. package/dist/types/naylence/fame/security/auth/policy/authorization-policy.d.ts +55 -0
  74. package/dist/types/naylence/fame/security/auth/policy/basic-authorization-policy-factory.d.ts +42 -0
  75. package/dist/types/naylence/fame/security/auth/policy/basic-authorization-policy.d.ts +78 -0
  76. package/dist/types/naylence/fame/security/auth/policy/index.d.ts +19 -0
  77. package/dist/types/naylence/fame/security/auth/policy/local-file-authorization-policy-source-factory.d.ts +51 -0
  78. package/dist/types/naylence/fame/security/auth/policy/local-file-authorization-policy-source.d.ts +67 -0
  79. package/dist/types/naylence/fame/security/auth/policy/pattern-matcher.d.ts +84 -0
  80. package/dist/types/naylence/fame/security/auth/policy/scope-matcher.d.ts +61 -0
  81. package/dist/types/naylence/fame/security/auth/policy-authorizer.d.ts +12 -0
  82. package/dist/types/naylence/fame/security/default-security-manager.d.ts +22 -0
  83. package/dist/types/naylence/fame/security/index.d.ts +5 -1
  84. package/dist/types/naylence/fame/security/node-security-profile-factory.d.ts +2 -0
  85. package/dist/types/naylence/fame/sentinel/router.d.ts +68 -0
  86. package/dist/types/naylence/fame/sentinel/sentinel.d.ts +16 -0
  87. package/dist/types/version.d.ts +1 -1
  88. package/package.json +1 -1
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Provides the list of runtime factory modules for registration.
6
6
  */
7
- export declare const MODULES: readonly ["./connector/broadcast-channel-connector-factory.js", "./connector/broadcast-channel-listener-factory.js", "./connector/http-listener-factory.js", "./connector/http-stateless-connector-factory.js", "./connector/inpage-connector-factory.js", "./connector/inpage-listener-factory.js", "./connector/websocket-connector-factory.js", "./connector/websocket-listener-factory.js", "./delivery/at-least-once-delivery-policy-factory.js", "./delivery/at-most-once-delivery-policy-factory.js", "./delivery/delivery-profile-factory.js", "./fabric/in-process-fame-fabric-factory.js", "./node/admission/admission-profile-factory.js", "./node/admission/direct-admission-client-factory.js", "./node/admission/noop-admission-client-factory.js", "./node/admission/welcome-service-client-factory.js", "./node/default-connection-retry-policy-factory.js", "./node/default-node-identity-policy-factory.js", "./node/node-factory.js", "./node/node-identity-policy-profile-factory.js", "./node/token-subject-node-identity-policy-factory.js", "./placement/static-node-placement-strategy-factory.js", "./security/auth/bearer-token-header-auth-injection-strategy-factory.js", "./security/auth/default-authorizer-factory.js", "./security/auth/jwks-jwt-token-verifier-factory.js", "./security/auth/jwt-token-issuer-factory.js", "./security/auth/jwt-token-verifier-factory.js", "./security/auth/no-auth-injection-strategy-factory.js", "./security/auth/none-token-provider-factory.js", "./security/auth/noop-authorizer-factory.js", "./security/auth/noop-token-issuer-factory.js", "./security/auth/noop-token-verifier-factory.js", "./security/auth/oauth2-authorizer-factory.js", "./security/auth/oauth2-client-credentials-token-provider-factory.js", "./security/auth/oauth2-pkce-token-provider-factory.js", "./security/auth/query-param-auth-injection-strategy-factory.js", "./security/auth/shared-secret-authorizer-factory.js", "./security/auth/shared-secret-token-provider-factory.js", "./security/auth/shared-secret-token-verifier-factory.js", "./security/auth/static-token-provider-factory.js", "./security/auth/websocket-subprotocol-auth-injection-strategy-factory.js", "./security/credential/dev-fixed-key-credential-provider-factory.js", "./security/credential/env-credential-provider-factory.js", "./security/credential/none-credential-provider-factory.js", "./security/credential/prompt-credential-provider-factory.js", "./security/credential/secret-store-credential-provider-factory.js", "./security/credential/session-key-credential-provider-factory.js", "./security/credential/static-credential-provider-factory.js", "./security/default-security-manager-factory.js", "./security/encryption/noop-encryption-manager-factory.js", "./security/encryption/noop-secure-channel-manager-factory.js", "./security/keys/default-key-manager-factory.js", "./security/keys/in-memory-key-store-factory.js", "./security/keys/noop-key-validator-factory.js", "./security/node-security-profile-factory.js", "./security/policy/default-security-policy-factory.js", "./security/policy/no-security-policy-factory.js", "./security/signing/eddsa-envelope-signer-factory.js", "./security/signing/eddsa-envelope-verifier-factory.js", "./security/trust-store/noop-trust-store-provider-factory.js", "./sentinel/capability-aware-routing-policy-factory.js", "./sentinel/composite-routing-policy-factory.js", "./sentinel/hybrid-path-routing-policy-factory.js", "./sentinel/load-balancing/composite-load-balancing-strategy-factory.js", "./sentinel/load-balancing/hrw-load-balancing-strategy-factory.js", "./sentinel/load-balancing/load-balancing-profile-factory.js", "./sentinel/load-balancing/random-load-balancing-strategy-factory.js", "./sentinel/load-balancing/round-robin-load-balancing-strategy-factory.js", "./sentinel/load-balancing/sticky-load-balancing-strategy-factory.js", "./sentinel/routing-profile-factory.js", "./sentinel/sentinel-factory.js", "./sentinel/store/route-store-factory.js", "./stickiness/simple-load-balancer-stickiness-manager-factory.js", "./telemetry/noop-trace-emitter-factory.js", "./telemetry/open-telemetry-trace-emitter-factory.js", "./telemetry/trace-emitter-profile-factory.js", "./welcome/default-welcome-service-factory.js"];
7
+ export declare const MODULES: readonly ["./connector/broadcast-channel-connector-factory.js", "./connector/broadcast-channel-listener-factory.js", "./connector/http-listener-factory.js", "./connector/http-stateless-connector-factory.js", "./connector/inpage-connector-factory.js", "./connector/inpage-listener-factory.js", "./connector/websocket-connector-factory.js", "./connector/websocket-listener-factory.js", "./delivery/at-least-once-delivery-policy-factory.js", "./delivery/at-most-once-delivery-policy-factory.js", "./delivery/delivery-profile-factory.js", "./fabric/in-process-fame-fabric-factory.js", "./node/admission/admission-profile-factory.js", "./node/admission/direct-admission-client-factory.js", "./node/admission/noop-admission-client-factory.js", "./node/admission/welcome-service-client-factory.js", "./node/default-connection-retry-policy-factory.js", "./node/default-node-identity-policy-factory.js", "./node/node-factory.js", "./node/node-identity-policy-profile-factory.js", "./node/token-subject-node-identity-policy-factory.js", "./placement/static-node-placement-strategy-factory.js", "./security/auth/authorization-profile-factory.js", "./security/auth/bearer-token-header-auth-injection-strategy-factory.js", "./security/auth/default-authorizer-factory.js", "./security/auth/default-policy-authorizer-factory.js", "./security/auth/jwks-jwt-token-verifier-factory.js", "./security/auth/jwt-token-issuer-factory.js", "./security/auth/jwt-token-verifier-factory.js", "./security/auth/no-auth-injection-strategy-factory.js", "./security/auth/none-token-provider-factory.js", "./security/auth/noop-authorizer-factory.js", "./security/auth/noop-token-issuer-factory.js", "./security/auth/noop-token-verifier-factory.js", "./security/auth/oauth2-authorizer-factory.js", "./security/auth/oauth2-client-credentials-token-provider-factory.js", "./security/auth/oauth2-pkce-token-provider-factory.js", "./security/auth/policy/basic-authorization-policy-factory.js", "./security/auth/policy/local-file-authorization-policy-source-factory.js", "./security/auth/query-param-auth-injection-strategy-factory.js", "./security/auth/shared-secret-authorizer-factory.js", "./security/auth/shared-secret-token-provider-factory.js", "./security/auth/shared-secret-token-verifier-factory.js", "./security/auth/static-token-provider-factory.js", "./security/auth/websocket-subprotocol-auth-injection-strategy-factory.js", "./security/credential/dev-fixed-key-credential-provider-factory.js", "./security/credential/env-credential-provider-factory.js", "./security/credential/none-credential-provider-factory.js", "./security/credential/prompt-credential-provider-factory.js", "./security/credential/secret-store-credential-provider-factory.js", "./security/credential/session-key-credential-provider-factory.js", "./security/credential/static-credential-provider-factory.js", "./security/default-security-manager-factory.js", "./security/encryption/noop-encryption-manager-factory.js", "./security/encryption/noop-secure-channel-manager-factory.js", "./security/keys/default-key-manager-factory.js", "./security/keys/in-memory-key-store-factory.js", "./security/keys/noop-key-validator-factory.js", "./security/node-security-profile-factory.js", "./security/policy/default-security-policy-factory.js", "./security/policy/no-security-policy-factory.js", "./security/signing/eddsa-envelope-signer-factory.js", "./security/signing/eddsa-envelope-verifier-factory.js", "./security/trust-store/noop-trust-store-provider-factory.js", "./sentinel/capability-aware-routing-policy-factory.js", "./sentinel/composite-routing-policy-factory.js", "./sentinel/hybrid-path-routing-policy-factory.js", "./sentinel/load-balancing/composite-load-balancing-strategy-factory.js", "./sentinel/load-balancing/hrw-load-balancing-strategy-factory.js", "./sentinel/load-balancing/load-balancing-profile-factory.js", "./sentinel/load-balancing/random-load-balancing-strategy-factory.js", "./sentinel/load-balancing/round-robin-load-balancing-strategy-factory.js", "./sentinel/load-balancing/sticky-load-balancing-strategy-factory.js", "./sentinel/routing-profile-factory.js", "./sentinel/sentinel-factory.js", "./sentinel/store/route-store-factory.js", "./stickiness/simple-load-balancer-stickiness-manager-factory.js", "./telemetry/noop-trace-emitter-factory.js", "./telemetry/open-telemetry-trace-emitter-factory.js", "./telemetry/trace-emitter-profile-factory.js", "./welcome/default-welcome-service-factory.js"];
8
8
  export type FactoryModuleSpec = (typeof MODULES)[number];
9
9
  export type FactoryModuleLoader = () => Promise<Record<string, unknown>>;
10
10
  export declare const MODULE_LOADERS: Record<FactoryModuleSpec, FactoryModuleLoader>;
@@ -4,6 +4,7 @@
4
4
  import type { FameAddress, FameConnector, FameDeliveryContext, FameEnvelope, NodeWelcomeFrame } from '@naylence/core';
5
5
  import type { AttachInfo } from './admission/node-attach-client.js';
6
6
  import type { NodeLike } from './node-like.js';
7
+ import type { RouterState, RoutingAction } from '../sentinel/router.js';
7
8
  /**
8
9
  * Protocol for components that need to respond to node lifecycle events.
9
10
  *
@@ -132,6 +133,35 @@ export interface NodeEventListener {
132
133
  * @returns Transformed envelope for continued processing, or null to halt delivery
133
134
  */
134
135
  onDeliver?(node: NodeLike, envelope: FameEnvelope, context?: FameDeliveryContext): Promise<FameEnvelope | null>;
136
+ /**
137
+ * Called after routing policy has selected a RoutingAction but before it executes.
138
+ *
139
+ * This hook provides a single, centralized entry point for route authorization.
140
+ * It is invoked AFTER `routingPolicy.decide(...)` returns a RoutingAction and
141
+ * BEFORE `action.execute(...)` is called.
142
+ *
143
+ * Components implementing this hook can:
144
+ * - Authorize the selected routing action (ForwardUpstream, ForwardDownstream, etc.)
145
+ * - Replace the action with a Deny/Drop action to block unauthorized routes
146
+ * - Apply route-level security policies
147
+ * - Log or audit routing decisions
148
+ *
149
+ * Return semantics:
150
+ * - Return the RoutingAction to execute (either the `selected` action or a replacement).
151
+ * - If the hook returns `null`, `undefined`, or throws, the router will execute a
152
+ * Drop action (envelope is dropped with NO_ROUTE nack).
153
+ *
154
+ * To allow the originally selected action, return `selected` directly.
155
+ * To deny/block, return a `Drop` or `Deny` action.
156
+ *
157
+ * @param node - The node performing the routing
158
+ * @param envelope - The envelope being routed
159
+ * @param selected - The RoutingAction selected by the routing policy
160
+ * @param state - The current router state (for context, not modification)
161
+ * @param context - Optional delivery context
162
+ * @returns The RoutingAction to execute (null/undefined/throw => Drop)
163
+ */
164
+ onRoutingActionSelected?(node: NodeLike, envelope: FameEnvelope, selected: RoutingAction, state: RouterState, context?: FameDeliveryContext | null): Promise<RoutingAction | null | undefined>;
135
165
  /**
136
166
  * Called when a node is about to forward an envelope upstream.
137
167
  *
@@ -325,6 +355,7 @@ export declare abstract class BaseNodeEventListener implements NodeEventListener
325
355
  onEnvelopeReceived?(_node: NodeLike, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
326
356
  onDeliverLocal?(_node: NodeLike, _address: FameAddress, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
327
357
  onDeliver?(_node: NodeLike, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
358
+ onRoutingActionSelected?(_node: NodeLike, _envelope: FameEnvelope, selected: RoutingAction, _state: RouterState, _context?: FameDeliveryContext | null): Promise<RoutingAction | null | undefined>;
328
359
  onForwardUpstream?(_node: NodeLike, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
329
360
  onForwardToRoute?(_node: NodeLike, _nextSegment: string, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
330
361
  onForwardToPeer?(_node: NodeLike, _peerSegment: string, envelope: FameEnvelope, _context?: FameDeliveryContext): Promise<FameEnvelope | null>;
@@ -0,0 +1,29 @@
1
+ import type { Authorizer } from './authorizer.js';
2
+ import { AuthorizerFactory, type AuthorizerConfig } from './authorizer-factory.js';
3
+ export interface AuthorizationProfileConfig extends AuthorizerConfig {
4
+ type: 'AuthorizationProfile';
5
+ profile?: string | null;
6
+ }
7
+ export declare const PROFILE_NAME_DEFAULT = "jwt";
8
+ export declare const PROFILE_NAME_OAUTH2 = "oauth2";
9
+ export declare const PROFILE_NAME_OAUTH2_GATED = "oauth2-gated";
10
+ export declare const PROFILE_NAME_OAUTH2_CALLBACK = "oauth2-callback";
11
+ export declare const PROFILE_NAME_NOOP = "noop";
12
+ export declare const ENV_VAR_JWT_TRUSTED_ISSUER = "FAME_JWT_TRUSTED_ISSUER";
13
+ export declare const ENV_VAR_JWT_ALGORITHM = "FAME_JWT_ALGORITHM";
14
+ export declare const ENV_VAR_JWT_AUDIENCE = "FAME_JWT_AUDIENCE";
15
+ export declare const ENV_VAR_JWKS_URL = "FAME_JWKS_URL";
16
+ export declare const ENV_VAR_ENFORCE_TOKEN_SUBJECT_NODE_IDENTITY = "FAME_ENFORCE_TOKEN_SUBJECT_NODE_IDENTITY";
17
+ export declare const ENV_VAR_TRUSTED_CLIENT_SCOPE = "FAME_TRUSTED_CLIENT_SCOPE";
18
+ export declare const ENV_VAR_JWT_REVERSE_AUTH_TRUSTED_ISSUER = "FAME_JWT_REVERSE_AUTH_TRUSTED_ISSUER";
19
+ export declare const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = "FAME_JWT_REVERSE_AUTH_AUDIENCE";
20
+ export declare const ENV_VAR_HMAC_SECRET = "FAME_HMAC_SECRET";
21
+ export declare const FACTORY_META: {
22
+ readonly base: "AuthorizerFactory";
23
+ readonly key: "AuthorizationProfile";
24
+ };
25
+ export declare class AuthorizationProfileFactory extends AuthorizerFactory<AuthorizationProfileConfig> {
26
+ readonly type = "AuthorizationProfile";
27
+ create(config?: AuthorizationProfileConfig | Record<string, unknown> | null, ...factoryArgs: unknown[]): Promise<Authorizer>;
28
+ }
29
+ export default AuthorizationProfileFactory;
@@ -1,7 +1,44 @@
1
1
  import type { AuthorizationContext, FameDeliveryContext, FameEnvelope } from '@naylence/core';
2
2
  import type { NodeLike } from '../../node/node-like.js';
3
+ import type { RuleAction } from './policy/authorization-policy-definition.js';
4
+ /**
5
+ * Route authorization result returned by authorizeRoute.
6
+ */
7
+ export interface RouteAuthorizationResult {
8
+ /**
9
+ * Whether the route action is authorized.
10
+ */
11
+ authorized: boolean;
12
+ /**
13
+ * The authorization context (if authorized).
14
+ */
15
+ authContext?: AuthorizationContext;
16
+ /**
17
+ * Reason for denial (for internal logging only, not for on-wire disclosure).
18
+ */
19
+ denialReason?: string;
20
+ /**
21
+ * Matched rule ID (for logging/audit).
22
+ */
23
+ matchedRule?: string;
24
+ }
3
25
  export interface Authorizer {
4
26
  authenticate(credentials: string | Uint8Array): Promise<AuthorizationContext | undefined>;
5
27
  authorize(node: NodeLike, envelope: FameEnvelope, context?: FameDeliveryContext): Promise<AuthorizationContext | undefined>;
28
+ /**
29
+ * Authorizes a routing action after the routing decision has been made.
30
+ *
31
+ * This method is called with the explicitly mapped action token from the
32
+ * routing decision (ForwardUpstream, ForwardDownstream, ForwardPeer,
33
+ * DeliverLocal). It does NOT receive RoutingAction objects to avoid
34
+ * coupling authorization logic to routing execution behavior.
35
+ *
36
+ * @param node - The node handling the request
37
+ * @param envelope - The FAME envelope being routed
38
+ * @param action - The authorization action token (route-oriented)
39
+ * @param context - Optional delivery context
40
+ * @returns RouteAuthorizationResult if implemented, or undefined to allow
41
+ */
42
+ authorizeRoute?(node: NodeLike, envelope: FameEnvelope, action: RuleAction, context?: FameDeliveryContext): Promise<RouteAuthorizationResult | undefined>;
6
43
  createReverseAuthorizationConfig?(node: NodeLike): Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
7
44
  }
@@ -0,0 +1,55 @@
1
+ import type { Authorizer } from './authorizer.js';
2
+ import { AuthorizerFactory, type AuthorizerConfig } from './authorizer-factory.js';
3
+ import { type TokenVerifierConfig } from './token-verifier-factory.js';
4
+ import { type AuthorizationPolicySourceConfig } from './policy/authorization-policy-source-factory.js';
5
+ import { type AuthorizationPolicyConfig } from './policy/authorization-policy-factory.js';
6
+ /**
7
+ * Configuration for DefaultPolicyAuthorizer.
8
+ */
9
+ export interface DefaultPolicyAuthorizerConfig extends AuthorizerConfig {
10
+ type: 'PolicyAuthorizer';
11
+ /**
12
+ * Token verifier configuration.
13
+ */
14
+ verifier?: TokenVerifierConfig | Record<string, unknown> | null;
15
+ /**
16
+ * Authorization policy configuration.
17
+ * Either policy or policySource must be provided.
18
+ */
19
+ policy?: AuthorizationPolicyConfig | Record<string, unknown> | null;
20
+ /**
21
+ * Authorization policy source configuration.
22
+ * Either policy or policySource must be provided.
23
+ */
24
+ policySource?: AuthorizationPolicySourceConfig | Record<string, unknown> | null;
25
+ policy_source?: AuthorizationPolicySourceConfig | Record<string, unknown> | null;
26
+ }
27
+ /**
28
+ * Factory metadata for registration.
29
+ */
30
+ export declare const FACTORY_META: {
31
+ readonly base: "AuthorizerFactory";
32
+ readonly key: "PolicyAuthorizer";
33
+ };
34
+ /**
35
+ * Factory for creating DefaultPolicyAuthorizer instances.
36
+ *
37
+ * This factory uses lazy loading to avoid pulling in Node.js-specific
38
+ * code in browser environments.
39
+ */
40
+ export declare class DefaultPolicyAuthorizerFactory extends AuthorizerFactory<DefaultPolicyAuthorizerConfig> {
41
+ readonly type = "PolicyAuthorizer";
42
+ readonly isDefault = true;
43
+ /**
44
+ * Creates a DefaultPolicyAuthorizer from the given configuration.
45
+ *
46
+ * @param config - Configuration for the authorizer
47
+ * @param factoryArgs - Additional factory arguments:
48
+ * - TokenVerifier instance
49
+ * - AuthorizationPolicy instance
50
+ * - AuthorizationPolicySource instance
51
+ * @returns The created authorizer
52
+ */
53
+ create(config?: DefaultPolicyAuthorizerConfig | Record<string, unknown> | null, ...factoryArgs: unknown[]): Promise<Authorizer>;
54
+ }
55
+ export default DefaultPolicyAuthorizerFactory;
@@ -0,0 +1,99 @@
1
+ import type { AuthorizationContext, FameDeliveryContext, FameEnvelope } from '@naylence/core';
2
+ import type { NodeLike } from '../../node/node-like.js';
3
+ import type { PolicyAuthorizer } from './policy-authorizer.js';
4
+ import type { AuthorizationPolicy } from './policy/authorization-policy.js';
5
+ import type { AuthorizationPolicySource } from './policy/authorization-policy-source.js';
6
+ import type { TokenVerifier } from './token-verifier.js';
7
+ import type { TokenVerifierProvider } from './token-verifier-provider.js';
8
+ import type { RouteAuthorizationResult } from './authorizer.js';
9
+ import type { RuleAction } from './policy/authorization-policy-definition.js';
10
+ /**
11
+ * Options for creating a DefaultPolicyAuthorizer.
12
+ */
13
+ export interface DefaultPolicyAuthorizerOptions {
14
+ /**
15
+ * Token verifier for authenticating credentials.
16
+ */
17
+ tokenVerifier?: TokenVerifier;
18
+ token_verifier?: TokenVerifier;
19
+ /**
20
+ * The authorization policy to use for authorization decisions.
21
+ * Either policy or policySource must be provided.
22
+ */
23
+ policy?: AuthorizationPolicy;
24
+ /**
25
+ * A source to load the authorization policy from.
26
+ * Either policy or policySource must be provided.
27
+ */
28
+ policySource?: AuthorizationPolicySource;
29
+ policy_source?: AuthorizationPolicySource;
30
+ }
31
+ /**
32
+ * An authorizer that delegates authorization decisions to a pluggable policy.
33
+ *
34
+ * This authorizer combines token-based authentication with policy-based
35
+ * authorization. The token verifier handles authentication (validating
36
+ * credentials), while the authorization policy handles authorization
37
+ * decisions (allow/deny based on the request context).
38
+ */
39
+ export declare class DefaultPolicyAuthorizer implements PolicyAuthorizer, TokenVerifierProvider {
40
+ private tokenVerifierImpl?;
41
+ private policyImpl?;
42
+ private readonly policySource?;
43
+ private policyLoaded;
44
+ constructor(options?: DefaultPolicyAuthorizerOptions);
45
+ /**
46
+ * The currently active authorization policy.
47
+ */
48
+ get policy(): AuthorizationPolicy;
49
+ /**
50
+ * The token verifier used for authentication.
51
+ */
52
+ get tokenVerifier(): TokenVerifier;
53
+ set tokenVerifier(verifier: TokenVerifier);
54
+ /**
55
+ * Ensures the authorization policy is loaded.
56
+ * If using a policy source, loads the policy from it.
57
+ */
58
+ ensurePolicyLoaded(): Promise<void>;
59
+ /**
60
+ * Reloads the authorization policy from the policy source.
61
+ * Only works if a policy source was configured.
62
+ */
63
+ reloadPolicy(): Promise<void>;
64
+ /**
65
+ * Authenticates credentials and returns an authorization context.
66
+ *
67
+ * @param credentials - The credentials to authenticate (token string or bytes)
68
+ * @returns The authorization context if authentication succeeds, undefined otherwise
69
+ */
70
+ authenticate(credentials: string | Uint8Array): Promise<AuthorizationContext | undefined>;
71
+ /**
72
+ * Authorizes a request using the configured authorization policy.
73
+ *
74
+ * For NodeAttach frames, evaluates policy with action='Connect'.
75
+ * For other frames, this method performs basic authentication validation
76
+ * but does NOT infer send/receive actions. Route-level authorization
77
+ * is handled separately via authorizeRoute().
78
+ *
79
+ * @param node - The node handling the request
80
+ * @param envelope - The FAME envelope being authorized
81
+ * @param context - Optional delivery context
82
+ * @returns The authorization context if authorized, undefined if denied
83
+ */
84
+ authorize(node: NodeLike, envelope: FameEnvelope, context?: FameDeliveryContext): Promise<AuthorizationContext | undefined>;
85
+ /**
86
+ * Authorizes a routing action after the routing decision has been made.
87
+ *
88
+ * This method evaluates the authorization policy with the explicitly
89
+ * provided action token (ForwardUpstream, ForwardDownstream, ForwardPeer,
90
+ * DeliverLocal).
91
+ *
92
+ * @param node - The node handling the request
93
+ * @param envelope - The FAME envelope being routed
94
+ * @param action - The authorization action token from the routing decision
95
+ * @param context - Optional delivery context
96
+ * @returns RouteAuthorizationResult with authorization decision
97
+ */
98
+ authorizeRoute(node: NodeLike, envelope: FameEnvelope, action: RuleAction, context?: FameDeliveryContext): Promise<RouteAuthorizationResult | undefined>;
99
+ }
@@ -25,6 +25,8 @@ export interface OAuth2AuthorizerConfig extends AuthorizerConfig {
25
25
  reverse_auth_ttl_sec?: number;
26
26
  enforceTokenSubjectNodeIdentity?: boolean;
27
27
  enforce_token_subject_node_identity?: boolean;
28
+ trustedClientScope?: string;
29
+ trusted_client_scope?: string;
28
30
  }
29
31
  export declare const FACTORY_META: {
30
32
  readonly base: "AuthorizerFactory";
@@ -15,6 +15,7 @@ export interface OAuth2AuthorizerOptions {
15
15
  maxTtlSec?: number;
16
16
  reverseAuthTtlSec?: number;
17
17
  enforceTokenSubjectNodeIdentity?: boolean;
18
+ trustedClientScope?: string;
18
19
  }
19
20
  export declare class OAuth2Authorizer implements Authorizer, TokenVerifierProvider, NodeEventListener {
20
21
  readonly priority = 1000;
@@ -25,6 +26,7 @@ export declare class OAuth2Authorizer implements Authorizer, TokenVerifierProvid
25
26
  private readonly requireScope;
26
27
  private readonly reverseAuthTtlSec;
27
28
  private readonly enforceTokenSubjectNodeIdentity;
29
+ private readonly trustedClientScope;
28
30
  private node?;
29
31
  constructor(rawOptions: OAuth2AuthorizerOptions | Record<string, unknown>);
30
32
  get tokenVerifier(): TokenVerifier;
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Authorization policy definition types.
3
+ *
4
+ * This module defines the schema for authorization policies that can be
5
+ * loaded from YAML/JSON files and evaluated at runtime.
6
+ */
7
+ /**
8
+ * The effect of an authorization rule.
9
+ */
10
+ export type RuleEffect = 'allow' | 'deny';
11
+ /**
12
+ * The action type a rule applies to (route-oriented, DX-friendly tokens).
13
+ *
14
+ * These tokens represent "what will happen next" in routing, not inferred send/receive:
15
+ * - Connect: NodeAttach connection handshake (pre-routing)
16
+ * - ForwardUpstream: Envelope will be forwarded to parent node
17
+ * - ForwardDownstream: Envelope will be forwarded to a child route
18
+ * - ForwardPeer: Envelope will be forwarded to a peer node
19
+ * - DeliverLocal: Envelope will be delivered to a local address handler
20
+ * - '*': Matches all actions (wildcard)
21
+ */
22
+ export type RuleAction = 'Connect' | 'ForwardUpstream' | 'ForwardDownstream' | 'ForwardPeer' | 'DeliverLocal' | '*';
23
+ /**
24
+ * Scope requirement using logical operators.
25
+ *
26
+ * Supports recursive nesting with a maximum depth enforced at parse time.
27
+ */
28
+ export type ScopeRequirement = string | {
29
+ any_of: ScopeRequirement[];
30
+ } | {
31
+ all_of: ScopeRequirement[];
32
+ } | {
33
+ none_of: ScopeRequirement[];
34
+ };
35
+ /**
36
+ * Normalized scope requirement with explicit type discriminator.
37
+ */
38
+ export type NormalizedScopeRequirement = {
39
+ type: 'pattern';
40
+ pattern: string;
41
+ } | {
42
+ type: 'any_of';
43
+ requirements: NormalizedScopeRequirement[];
44
+ } | {
45
+ type: 'all_of';
46
+ requirements: NormalizedScopeRequirement[];
47
+ } | {
48
+ type: 'none_of';
49
+ requirements: NormalizedScopeRequirement[];
50
+ };
51
+ /**
52
+ * An authorization rule definition.
53
+ */
54
+ export interface AuthorizationRuleDefinition {
55
+ /**
56
+ * Optional unique identifier for the rule.
57
+ * Used in decision traces for debugging.
58
+ */
59
+ id?: string;
60
+ /**
61
+ * Optional human-readable description of the rule.
62
+ */
63
+ description?: string;
64
+ /**
65
+ * The effect when this rule matches: allow or deny.
66
+ */
67
+ effect: RuleEffect;
68
+ /**
69
+ * The action type this rule applies to.
70
+ * Can be a single action or an array of actions (implicit any-of).
71
+ * @default '*' (all actions)
72
+ */
73
+ action?: RuleAction | RuleAction[];
74
+ /**
75
+ * Address pattern(s) to match using glob syntax.
76
+ * Can be a single pattern or an array (implicit any-of).
77
+ * If omitted, matches all addresses.
78
+ *
79
+ * Glob syntax:
80
+ * - `*` matches any characters except dots (single segment)
81
+ * - `**` matches any characters including dots (any depth)
82
+ * - `?` matches a single character (not a dot)
83
+ * - Other characters are matched literally
84
+ *
85
+ * Note: In OSS/basic policy, patterns are always treated as globs.
86
+ * Patterns starting with `^` are NOT interpreted as regex.
87
+ */
88
+ address?: string | string[];
89
+ /**
90
+ * Optional frame type gating.
91
+ * Can be a single frame type string or an array (implicit any-of).
92
+ * Matching is case-insensitive.
93
+ */
94
+ frame_type?: string | string[];
95
+ /**
96
+ * Optional delivery origin type gating.
97
+ * Can be a single origin type or an array (implicit any-of).
98
+ * Valid values: 'downstream', 'upstream', 'peer', 'local'.
99
+ * Matching is case-insensitive with whitespace trimmed.
100
+ * If omitted, matches any origin type.
101
+ * If specified but context.originType is undefined, rule does not match.
102
+ */
103
+ origin_type?: string | string[];
104
+ /**
105
+ * Scope requirement for the rule to match.
106
+ * If omitted, no scope check is performed.
107
+ */
108
+ scope?: ScopeRequirement;
109
+ /**
110
+ * Expression condition (reserved for advanced-security package).
111
+ * Basic policy parser ignores this field.
112
+ */
113
+ when?: string;
114
+ /**
115
+ * Allow additional fields for forward compatibility.
116
+ * Unknown fields are ignored with a warning.
117
+ */
118
+ [key: string]: unknown;
119
+ }
120
+ /**
121
+ * Authorization policy definition loaded from a file.
122
+ */
123
+ export interface AuthorizationPolicyDefinition {
124
+ /**
125
+ * Schema version for the policy format.
126
+ */
127
+ version: string;
128
+ /**
129
+ * Default effect when no rule matches.
130
+ */
131
+ default_effect: RuleEffect;
132
+ /**
133
+ * List of authorization rules, evaluated in order.
134
+ * First matching rule determines the outcome.
135
+ */
136
+ rules: AuthorizationRuleDefinition[];
137
+ /**
138
+ * Allow additional fields for forward compatibility.
139
+ */
140
+ [key: string]: unknown;
141
+ }
142
+ /**
143
+ * Maximum nesting depth for scope requirements.
144
+ */
145
+ export declare const MAX_SCOPE_NESTING_DEPTH = 5;
146
+ /**
147
+ * Known fields in AuthorizationPolicyDefinition.
148
+ */
149
+ export declare const KNOWN_POLICY_FIELDS: Set<string>;
150
+ /**
151
+ * Known fields in AuthorizationRuleDefinition.
152
+ * Fields not in this set trigger a warning.
153
+ */
154
+ export declare const KNOWN_RULE_FIELDS: Set<string>;
155
+ /**
156
+ * Valid action values.
157
+ */
158
+ export declare const VALID_ACTIONS: readonly RuleAction[];
159
+ /**
160
+ * Valid origin type values (lowercase, matching DeliveryOriginType string values).
161
+ */
162
+ export declare const VALID_ORIGIN_TYPES: readonly string[];
163
+ /**
164
+ * Valid effect values.
165
+ */
166
+ export declare const VALID_EFFECTS: readonly RuleEffect[];
@@ -0,0 +1,38 @@
1
+ import type { CreateResourceOptions, ResourceConfig } from '@naylence/factory';
2
+ import { AbstractResourceFactory } from '@naylence/factory';
3
+ import type { AuthorizationPolicy } from './authorization-policy.js';
4
+ /**
5
+ * Base type identifier for authorization policy factories.
6
+ */
7
+ export declare const AUTHORIZATION_POLICY_FACTORY_BASE_TYPE = "AuthorizationPolicyFactory";
8
+ /**
9
+ * Configuration for creating an authorization policy.
10
+ */
11
+ export interface AuthorizationPolicyConfig extends ResourceConfig {
12
+ type: string;
13
+ [key: string]: unknown;
14
+ }
15
+ /**
16
+ * Abstract factory base class for creating authorization policies.
17
+ *
18
+ * Implementations of this factory create specific types of authorization
19
+ * policies (e.g., expression-based, rule-based, etc.).
20
+ */
21
+ export declare abstract class AuthorizationPolicyFactory<C extends AuthorizationPolicyConfig = AuthorizationPolicyConfig> extends AbstractResourceFactory<AuthorizationPolicy, C> {
22
+ /**
23
+ * Creates an authorization policy from the given configuration.
24
+ *
25
+ * @param config - Configuration for the policy
26
+ * @param factoryArgs - Additional factory arguments
27
+ * @returns The created authorization policy
28
+ */
29
+ abstract create(config?: C | Record<string, unknown> | null, ...factoryArgs: unknown[]): Promise<AuthorizationPolicy>;
30
+ /**
31
+ * Static helper to create an authorization policy using the factory registry.
32
+ *
33
+ * @param config - Configuration for the policy
34
+ * @param options - Resource creation options
35
+ * @returns The created policy, or undefined if no factory matched
36
+ */
37
+ static createAuthorizationPolicy<C extends AuthorizationPolicyConfig = AuthorizationPolicyConfig>(config?: C | Record<string, unknown> | null, options?: CreateResourceOptions): Promise<AuthorizationPolicy | undefined>;
38
+ }
@@ -0,0 +1,38 @@
1
+ import type { CreateResourceOptions, ResourceConfig } from '@naylence/factory';
2
+ import { AbstractResourceFactory } from '@naylence/factory';
3
+ import type { AuthorizationPolicySource } from './authorization-policy-source.js';
4
+ /**
5
+ * Base type identifier for authorization policy source factories.
6
+ */
7
+ export declare const AUTHORIZATION_POLICY_SOURCE_FACTORY_BASE_TYPE = "AuthorizationPolicySourceFactory";
8
+ /**
9
+ * Configuration for creating an authorization policy source.
10
+ */
11
+ export interface AuthorizationPolicySourceConfig extends ResourceConfig {
12
+ type: string;
13
+ [key: string]: unknown;
14
+ }
15
+ /**
16
+ * Abstract factory base class for creating authorization policy sources.
17
+ *
18
+ * Implementations of this factory create specific types of policy sources
19
+ * (e.g., local file, remote store, in-memory, etc.).
20
+ */
21
+ export declare abstract class AuthorizationPolicySourceFactory<C extends AuthorizationPolicySourceConfig = AuthorizationPolicySourceConfig> extends AbstractResourceFactory<AuthorizationPolicySource, C> {
22
+ /**
23
+ * Creates an authorization policy source from the given configuration.
24
+ *
25
+ * @param config - Configuration for the policy source
26
+ * @param factoryArgs - Additional factory arguments
27
+ * @returns The created authorization policy source
28
+ */
29
+ abstract create(config?: C | Record<string, unknown> | null, ...factoryArgs: unknown[]): Promise<AuthorizationPolicySource>;
30
+ /**
31
+ * Static helper to create an authorization policy source using the factory registry.
32
+ *
33
+ * @param config - Configuration for the policy source
34
+ * @param options - Resource creation options
35
+ * @returns The created policy source, or undefined if no factory matched
36
+ */
37
+ static createAuthorizationPolicySource<C extends AuthorizationPolicySourceConfig = AuthorizationPolicySourceConfig>(config?: C | Record<string, unknown> | null, options?: CreateResourceOptions): Promise<AuthorizationPolicySource | undefined>;
38
+ }
@@ -0,0 +1,20 @@
1
+ import type { AuthorizationPolicy } from './authorization-policy.js';
2
+ /**
3
+ * Interface for sources that provide authorization policies.
4
+ *
5
+ * Policy sources abstract where the policy definition comes from,
6
+ * allowing policies to be loaded from local files, remote stores,
7
+ * or other sources.
8
+ */
9
+ export interface AuthorizationPolicySource {
10
+ /**
11
+ * Loads and returns the authorization policy.
12
+ *
13
+ * This method may be called multiple times, for example when
14
+ * reloading a policy after changes. Implementations should
15
+ * handle caching internally if needed.
16
+ *
17
+ * @returns The loaded authorization policy
18
+ */
19
+ loadPolicy(): Promise<AuthorizationPolicy>;
20
+ }
@@ -0,0 +1,55 @@
1
+ import type { FameDeliveryContext, FameEnvelope } from '@naylence/core';
2
+ import type { NodeLike } from '../../../node/node-like.js';
3
+ import type { RuleAction } from './authorization-policy-definition.js';
4
+ /**
5
+ * The effect of an authorization decision.
6
+ */
7
+ export type AuthorizationEffect = 'allow' | 'deny';
8
+ /**
9
+ * Represents a single step in the policy evaluation process.
10
+ * Useful for debugging and auditing authorization decisions.
11
+ */
12
+ export interface AuthorizationEvaluationStep {
13
+ /** Rule identifier that was evaluated */
14
+ ruleId: string;
15
+ /** Expression or condition that was evaluated */
16
+ expression?: string;
17
+ /** Result of the evaluation */
18
+ result: boolean;
19
+ /** Context values used in evaluation (for debugging) */
20
+ boundValues?: Record<string, unknown>;
21
+ }
22
+ /**
23
+ * The result of an authorization policy evaluation.
24
+ */
25
+ export interface AuthorizationDecision {
26
+ /** The authorization effect: allow or deny */
27
+ effect: AuthorizationEffect;
28
+ /** Human-readable reason for the decision */
29
+ reason?: string;
30
+ /** Identifier of the rule that matched (for debugging/audit) */
31
+ matchedRule?: string;
32
+ /** Evaluation trace for detailed debugging */
33
+ evaluationTrace?: AuthorizationEvaluationStep[];
34
+ }
35
+ /**
36
+ * Interface for authorization policies that evaluate whether a request
37
+ * should be allowed or denied.
38
+ *
39
+ * The policy receives the same parameters as `Authorizer.authorize`,
40
+ * giving it full access to the node, envelope, and delivery context
41
+ * for making authorization decisions.
42
+ */
43
+ export interface AuthorizationPolicy {
44
+ /**
45
+ * Evaluates an authorization request and returns a decision.
46
+ *
47
+ * @param node - The node handling the request
48
+ * @param envelope - The FAME envelope being authorized
49
+ * @param context - Optional delivery context with authorization info, origin, etc.
50
+ * @param action - Optional authorization action token (route-oriented: Connect,
51
+ * ForwardUpstream, ForwardDownstream, ForwardPeer, DeliverLocal, '*')
52
+ * @returns A decision indicating whether to allow or deny the request
53
+ */
54
+ evaluateRequest(node: NodeLike, envelope: FameEnvelope, context?: FameDeliveryContext, action?: RuleAction): Promise<AuthorizationDecision>;
55
+ }