@naylence/runtime 0.4.4 → 0.4.6

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.
@@ -525,12 +525,12 @@ async function ensureRuntimeFactoriesRegistered(registry = factory.Registry) {
525
525
  }
526
526
 
527
527
  // This file is auto-generated during build - do not edit manually
528
- // Generated from package.json version: 0.4.4
528
+ // Generated from package.json version: 0.4.6
529
529
  /**
530
530
  * The package version, injected at build time.
531
531
  * @internal
532
532
  */
533
- const VERSION = '0.4.4';
533
+ const VERSION = '0.4.6';
534
534
 
535
535
  let initialized = false;
536
536
  const runtimePlugin = {
@@ -21941,14 +21941,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
21941
21941
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
21942
21942
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
21943
21943
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
21944
- const DEFAULT_VERIFIER_CONFIG = {
21945
- type: 'JWKSJWTTokenVerifier',
21946
- jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21947
- issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21948
- };
21949
21944
  const DEFAULT_PROFILE = {
21950
21945
  type: 'DefaultAuthorizer',
21951
- verifier: DEFAULT_VERIFIER_CONFIG,
21946
+ verifier: {
21947
+ type: 'JWKSJWTTokenVerifier',
21948
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21949
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21950
+ },
21952
21951
  };
21953
21952
  const OAUTH2_PROFILE = {
21954
21953
  type: 'OAuth2Authorizer',
@@ -21993,6 +21992,11 @@ const OAUTH2_CALLBACK_PROFILE = {
21993
21992
  const NOOP_PROFILE$2 = {
21994
21993
  type: 'NoopAuthorizer',
21995
21994
  };
21995
+ const DEFAULT_VERIFIER_CONFIG = {
21996
+ type: 'JWKSJWTTokenVerifier',
21997
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21998
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21999
+ };
21996
22000
  const DEFAULT_POLICY_SOURCE = {
21997
22001
  type: 'LocalFileAuthorizationPolicySource',
21998
22002
  path: factory.Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -22044,13 +22048,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
22044
22048
  logger$K.debug('enabling_authorization_profile', {
22045
22049
  profile: normalized.profile,
22046
22050
  });
22047
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
22051
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
22052
+ const createOptions = extractCreateResourceOptions(factoryArgs);
22053
+ // Only evaluate expressions if we have env/config/variables available
22054
+ let evaluatedConfig = profileConfig;
22055
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
22056
+ if (hasContext) {
22057
+ // Build validation context from createOptions to evaluate expressions
22058
+ const validationContext = {
22059
+ env: createOptions.env,
22060
+ config: createOptions.config,
22061
+ variables: createOptions.variables,
22062
+ allowUnknownProperties: true,
22063
+ };
22064
+ // Evaluate expressions in the profile config
22065
+ const validationResult = factory.configValidator.validate(profileConfig, validationContext);
22066
+ if (!validationResult.valid) {
22067
+ const errorMessages = validationResult.errors
22068
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
22069
+ .join('; ');
22070
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
22071
+ }
22072
+ evaluatedConfig = validationResult.config ?? profileConfig;
22073
+ }
22074
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
22075
+ );
22048
22076
  if (!authorizer) {
22049
22077
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
22050
22078
  }
22051
22079
  return authorizer;
22052
22080
  }
22053
22081
  }
22082
+ /**
22083
+ * Extracts CreateResourceOptions from factoryArgs.
22084
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
22085
+ */
22086
+ function extractCreateResourceOptions(factoryArgs) {
22087
+ // Find the last object argument that looks like CreateResourceOptions
22088
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
22089
+ const arg = factoryArgs[i];
22090
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
22091
+ const candidate = arg;
22092
+ // Check if it has typical CreateResourceOptions properties
22093
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
22094
+ return candidate;
22095
+ }
22096
+ }
22097
+ }
22098
+ return {};
22099
+ }
22054
22100
  function normalizeConfig$w(config) {
22055
22101
  if (!config) {
22056
22102
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -37407,7 +37453,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37407
37453
  }
37408
37454
  if (!authorizer) {
37409
37455
  authorizer =
37410
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
37456
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
37411
37457
  }
37412
37458
  if (authorizer &&
37413
37459
  eventListeners &&
@@ -37638,14 +37684,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37638
37684
  }
37639
37685
  return null;
37640
37686
  }
37641
- static async createAuthorizerFromConfig(config, policy) {
37687
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
37642
37688
  let authorizerConfig = config.authorizer ?? null;
37643
37689
  if (!authorizerConfig) {
37644
37690
  authorizerConfig = config.authorizer_config ?? null;
37645
37691
  }
37646
37692
  if (authorizerConfig &&
37647
37693
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
37648
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
37694
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
37649
37695
  }
37650
37696
  try {
37651
37697
  const requirements = policy.requirements?.();
@@ -37661,6 +37707,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37661
37707
  }
37662
37708
  const tokenVerifier = new NoopTokenVerifier();
37663
37709
  return ((await AuthorizerFactory.createAuthorizer(null, {
37710
+ ...createOptions,
37664
37711
  factoryArgs: [tokenVerifier],
37665
37712
  })) ?? null);
37666
37713
  }
@@ -523,12 +523,12 @@ async function ensureRuntimeFactoriesRegistered(registry = Registry) {
523
523
  }
524
524
 
525
525
  // This file is auto-generated during build - do not edit manually
526
- // Generated from package.json version: 0.4.4
526
+ // Generated from package.json version: 0.4.6
527
527
  /**
528
528
  * The package version, injected at build time.
529
529
  * @internal
530
530
  */
531
- const VERSION = '0.4.4';
531
+ const VERSION = '0.4.6';
532
532
 
533
533
  let initialized = false;
534
534
  const runtimePlugin = {
@@ -21939,14 +21939,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
21939
21939
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
21940
21940
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
21941
21941
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
21942
- const DEFAULT_VERIFIER_CONFIG = {
21943
- type: 'JWKSJWTTokenVerifier',
21944
- jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21945
- issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21946
- };
21947
21942
  const DEFAULT_PROFILE = {
21948
21943
  type: 'DefaultAuthorizer',
21949
- verifier: DEFAULT_VERIFIER_CONFIG,
21944
+ verifier: {
21945
+ type: 'JWKSJWTTokenVerifier',
21946
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21947
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21948
+ },
21950
21949
  };
21951
21950
  const OAUTH2_PROFILE = {
21952
21951
  type: 'OAuth2Authorizer',
@@ -21991,6 +21990,11 @@ const OAUTH2_CALLBACK_PROFILE = {
21991
21990
  const NOOP_PROFILE$2 = {
21992
21991
  type: 'NoopAuthorizer',
21993
21992
  };
21993
+ const DEFAULT_VERIFIER_CONFIG = {
21994
+ type: 'JWKSJWTTokenVerifier',
21995
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21996
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21997
+ };
21994
21998
  const DEFAULT_POLICY_SOURCE = {
21995
21999
  type: 'LocalFileAuthorizationPolicySource',
21996
22000
  path: Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -22042,13 +22046,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
22042
22046
  logger$K.debug('enabling_authorization_profile', {
22043
22047
  profile: normalized.profile,
22044
22048
  });
22045
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
22049
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
22050
+ const createOptions = extractCreateResourceOptions(factoryArgs);
22051
+ // Only evaluate expressions if we have env/config/variables available
22052
+ let evaluatedConfig = profileConfig;
22053
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
22054
+ if (hasContext) {
22055
+ // Build validation context from createOptions to evaluate expressions
22056
+ const validationContext = {
22057
+ env: createOptions.env,
22058
+ config: createOptions.config,
22059
+ variables: createOptions.variables,
22060
+ allowUnknownProperties: true,
22061
+ };
22062
+ // Evaluate expressions in the profile config
22063
+ const validationResult = configValidator.validate(profileConfig, validationContext);
22064
+ if (!validationResult.valid) {
22065
+ const errorMessages = validationResult.errors
22066
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
22067
+ .join('; ');
22068
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
22069
+ }
22070
+ evaluatedConfig = validationResult.config ?? profileConfig;
22071
+ }
22072
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
22073
+ );
22046
22074
  if (!authorizer) {
22047
22075
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
22048
22076
  }
22049
22077
  return authorizer;
22050
22078
  }
22051
22079
  }
22080
+ /**
22081
+ * Extracts CreateResourceOptions from factoryArgs.
22082
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
22083
+ */
22084
+ function extractCreateResourceOptions(factoryArgs) {
22085
+ // Find the last object argument that looks like CreateResourceOptions
22086
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
22087
+ const arg = factoryArgs[i];
22088
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
22089
+ const candidate = arg;
22090
+ // Check if it has typical CreateResourceOptions properties
22091
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
22092
+ return candidate;
22093
+ }
22094
+ }
22095
+ }
22096
+ return {};
22097
+ }
22052
22098
  function normalizeConfig$w(config) {
22053
22099
  if (!config) {
22054
22100
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -37405,7 +37451,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37405
37451
  }
37406
37452
  if (!authorizer) {
37407
37453
  authorizer =
37408
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
37454
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
37409
37455
  }
37410
37456
  if (authorizer &&
37411
37457
  eventListeners &&
@@ -37636,14 +37682,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37636
37682
  }
37637
37683
  return null;
37638
37684
  }
37639
- static async createAuthorizerFromConfig(config, policy) {
37685
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
37640
37686
  let authorizerConfig = config.authorizer ?? null;
37641
37687
  if (!authorizerConfig) {
37642
37688
  authorizerConfig = config.authorizer_config ?? null;
37643
37689
  }
37644
37690
  if (authorizerConfig &&
37645
37691
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
37646
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
37692
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
37647
37693
  }
37648
37694
  try {
37649
37695
  const requirements = policy.requirements?.();
@@ -37659,6 +37705,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37659
37705
  }
37660
37706
  const tokenVerifier = new NoopTokenVerifier();
37661
37707
  return ((await AuthorizerFactory.createAuthorizer(null, {
37708
+ ...createOptions,
37662
37709
  factoryArgs: [tokenVerifier],
37663
37710
  })) ?? null);
37664
37711
  }
@@ -24,14 +24,13 @@ exports.ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
24
24
  exports.ENV_VAR_HMAC_SECRET = 'FAME_HMAC_SECRET';
25
25
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
26
26
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
27
- const DEFAULT_VERIFIER_CONFIG = {
28
- type: 'JWKSJWTTokenVerifier',
29
- jwks_url: factory_1.Expressions.env(exports.ENV_VAR_JWKS_URL),
30
- issuer: factory_1.Expressions.env(exports.ENV_VAR_JWT_TRUSTED_ISSUER),
31
- };
32
27
  const DEFAULT_PROFILE = {
33
28
  type: 'DefaultAuthorizer',
34
- verifier: DEFAULT_VERIFIER_CONFIG,
29
+ verifier: {
30
+ type: 'JWKSJWTTokenVerifier',
31
+ jwks_url: factory_1.Expressions.env(exports.ENV_VAR_JWKS_URL),
32
+ issuer: factory_1.Expressions.env(exports.ENV_VAR_JWT_TRUSTED_ISSUER),
33
+ },
35
34
  };
36
35
  const OAUTH2_PROFILE = {
37
36
  type: 'OAuth2Authorizer',
@@ -76,6 +75,11 @@ const OAUTH2_CALLBACK_PROFILE = {
76
75
  const NOOP_PROFILE = {
77
76
  type: 'NoopAuthorizer',
78
77
  };
78
+ const DEFAULT_VERIFIER_CONFIG = {
79
+ type: 'JWKSJWTTokenVerifier',
80
+ jwks_url: factory_1.Expressions.env(exports.ENV_VAR_JWKS_URL),
81
+ issuer: factory_1.Expressions.env(exports.ENV_VAR_JWT_TRUSTED_ISSUER),
82
+ };
79
83
  const DEFAULT_POLICY_SOURCE = {
80
84
  type: 'LocalFileAuthorizationPolicySource',
81
85
  path: factory_1.Expressions.env(exports.ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -127,7 +131,31 @@ class AuthorizationProfileFactory extends authorizer_factory_js_1.AuthorizerFact
127
131
  logger.debug('enabling_authorization_profile', {
128
132
  profile: normalized.profile,
129
133
  });
130
- const authorizer = await authorizer_factory_js_1.AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
134
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
135
+ const createOptions = extractCreateResourceOptions(factoryArgs);
136
+ // Only evaluate expressions if we have env/config/variables available
137
+ let evaluatedConfig = profileConfig;
138
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
139
+ if (hasContext) {
140
+ // Build validation context from createOptions to evaluate expressions
141
+ const validationContext = {
142
+ env: createOptions.env,
143
+ config: createOptions.config,
144
+ variables: createOptions.variables,
145
+ allowUnknownProperties: true,
146
+ };
147
+ // Evaluate expressions in the profile config
148
+ const validationResult = factory_1.configValidator.validate(profileConfig, validationContext);
149
+ if (!validationResult.valid) {
150
+ const errorMessages = validationResult.errors
151
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
152
+ .join('; ');
153
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
154
+ }
155
+ evaluatedConfig = validationResult.config ?? profileConfig;
156
+ }
157
+ const authorizer = await authorizer_factory_js_1.AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
158
+ );
131
159
  if (!authorizer) {
132
160
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
133
161
  }
@@ -135,6 +163,24 @@ class AuthorizationProfileFactory extends authorizer_factory_js_1.AuthorizerFact
135
163
  }
136
164
  }
137
165
  exports.AuthorizationProfileFactory = AuthorizationProfileFactory;
166
+ /**
167
+ * Extracts CreateResourceOptions from factoryArgs.
168
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
169
+ */
170
+ function extractCreateResourceOptions(factoryArgs) {
171
+ // Find the last object argument that looks like CreateResourceOptions
172
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
173
+ const arg = factoryArgs[i];
174
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
175
+ const candidate = arg;
176
+ // Check if it has typical CreateResourceOptions properties
177
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
178
+ return candidate;
179
+ }
180
+ }
181
+ }
182
+ return {};
183
+ }
138
184
  function normalizeConfig(config) {
139
185
  if (!config) {
140
186
  return { profile: exports.PROFILE_NAME_OAUTH2 };
@@ -159,7 +159,7 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
159
159
  }
160
160
  if (!authorizer) {
161
161
  authorizer =
162
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
162
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
163
163
  }
164
164
  if (authorizer &&
165
165
  eventListeners &&
@@ -390,14 +390,14 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
390
390
  }
391
391
  return null;
392
392
  }
393
- static async createAuthorizerFromConfig(config, policy) {
393
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
394
394
  let authorizerConfig = config.authorizer ?? null;
395
395
  if (!authorizerConfig) {
396
396
  authorizerConfig = config.authorizer_config ?? null;
397
397
  }
398
398
  if (authorizerConfig &&
399
399
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
400
- return ((await authorizer_factory_js_1.AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
400
+ return ((await authorizer_factory_js_1.AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
401
401
  }
402
402
  try {
403
403
  const requirements = policy.requirements?.();
@@ -413,6 +413,7 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
413
413
  }
414
414
  const tokenVerifier = new noop_token_verifier_js_1.NoopTokenVerifier();
415
415
  return ((await authorizer_factory_js_1.AuthorizerFactory.createAuthorizer(null, {
416
+ ...createOptions,
416
417
  factoryArgs: [tokenVerifier],
417
418
  })) ?? null);
418
419
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  // This file is auto-generated during build - do not edit manually
3
- // Generated from package.json version: 0.4.4
3
+ // Generated from package.json version: 0.4.6
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.VERSION = void 0;
6
6
  /**
7
7
  * The package version, injected at build time.
8
8
  * @internal
9
9
  */
10
- exports.VERSION = '0.4.4';
10
+ exports.VERSION = '0.4.6';
@@ -1,4 +1,4 @@
1
- import { Expressions } from '@naylence/factory';
1
+ import { Expressions, configValidator } from '@naylence/factory';
2
2
  import { getLogger } from '../../util/logging.js';
3
3
  import { AUTHORIZER_FACTORY_BASE_TYPE, AuthorizerFactory, } from './authorizer-factory.js';
4
4
  const logger = getLogger('naylence.fame.security.auth.authorization_profile_factory');
@@ -21,14 +21,13 @@ export const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE = 'FAME_JWT_REVERSE_AUTH_AUDIENCE
21
21
  export const ENV_VAR_HMAC_SECRET = 'FAME_HMAC_SECRET';
22
22
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
23
23
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
24
- const DEFAULT_VERIFIER_CONFIG = {
25
- type: 'JWKSJWTTokenVerifier',
26
- jwks_url: Expressions.env(ENV_VAR_JWKS_URL),
27
- issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER),
28
- };
29
24
  const DEFAULT_PROFILE = {
30
25
  type: 'DefaultAuthorizer',
31
- verifier: DEFAULT_VERIFIER_CONFIG,
26
+ verifier: {
27
+ type: 'JWKSJWTTokenVerifier',
28
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL),
29
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER),
30
+ },
32
31
  };
33
32
  const OAUTH2_PROFILE = {
34
33
  type: 'OAuth2Authorizer',
@@ -73,6 +72,11 @@ const OAUTH2_CALLBACK_PROFILE = {
73
72
  const NOOP_PROFILE = {
74
73
  type: 'NoopAuthorizer',
75
74
  };
75
+ const DEFAULT_VERIFIER_CONFIG = {
76
+ type: 'JWKSJWTTokenVerifier',
77
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL),
78
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER),
79
+ };
76
80
  const DEFAULT_POLICY_SOURCE = {
77
81
  type: 'LocalFileAuthorizationPolicySource',
78
82
  path: Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -124,13 +128,55 @@ export class AuthorizationProfileFactory extends AuthorizerFactory {
124
128
  logger.debug('enabling_authorization_profile', {
125
129
  profile: normalized.profile,
126
130
  });
127
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
131
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
132
+ const createOptions = extractCreateResourceOptions(factoryArgs);
133
+ // Only evaluate expressions if we have env/config/variables available
134
+ let evaluatedConfig = profileConfig;
135
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
136
+ if (hasContext) {
137
+ // Build validation context from createOptions to evaluate expressions
138
+ const validationContext = {
139
+ env: createOptions.env,
140
+ config: createOptions.config,
141
+ variables: createOptions.variables,
142
+ allowUnknownProperties: true,
143
+ };
144
+ // Evaluate expressions in the profile config
145
+ const validationResult = configValidator.validate(profileConfig, validationContext);
146
+ if (!validationResult.valid) {
147
+ const errorMessages = validationResult.errors
148
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
149
+ .join('; ');
150
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
151
+ }
152
+ evaluatedConfig = validationResult.config ?? profileConfig;
153
+ }
154
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
155
+ );
128
156
  if (!authorizer) {
129
157
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
130
158
  }
131
159
  return authorizer;
132
160
  }
133
161
  }
162
+ /**
163
+ * Extracts CreateResourceOptions from factoryArgs.
164
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
165
+ */
166
+ function extractCreateResourceOptions(factoryArgs) {
167
+ // Find the last object argument that looks like CreateResourceOptions
168
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
169
+ const arg = factoryArgs[i];
170
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
171
+ const candidate = arg;
172
+ // Check if it has typical CreateResourceOptions properties
173
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
174
+ return candidate;
175
+ }
176
+ }
177
+ }
178
+ return {};
179
+ }
134
180
  function normalizeConfig(config) {
135
181
  if (!config) {
136
182
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -156,7 +156,7 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
156
156
  }
157
157
  if (!authorizer) {
158
158
  authorizer =
159
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
159
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
160
160
  }
161
161
  if (authorizer &&
162
162
  eventListeners &&
@@ -387,14 +387,14 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
387
387
  }
388
388
  return null;
389
389
  }
390
- static async createAuthorizerFromConfig(config, policy) {
390
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
391
391
  let authorizerConfig = config.authorizer ?? null;
392
392
  if (!authorizerConfig) {
393
393
  authorizerConfig = config.authorizer_config ?? null;
394
394
  }
395
395
  if (authorizerConfig &&
396
396
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
397
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
397
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
398
398
  }
399
399
  try {
400
400
  const requirements = policy.requirements?.();
@@ -410,6 +410,7 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
410
410
  }
411
411
  const tokenVerifier = new NoopTokenVerifier();
412
412
  return ((await AuthorizerFactory.createAuthorizer(null, {
413
+ ...createOptions,
413
414
  factoryArgs: [tokenVerifier],
414
415
  })) ?? null);
415
416
  }
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated during build - do not edit manually
2
- // Generated from package.json version: 0.4.4
2
+ // Generated from package.json version: 0.4.6
3
3
  /**
4
4
  * The package version, injected at build time.
5
5
  * @internal
6
6
  */
7
- export const VERSION = '0.4.4';
7
+ export const VERSION = '0.4.6';
@@ -14,12 +14,12 @@ var fastify = require('fastify');
14
14
  var websocketPlugin = require('@fastify/websocket');
15
15
 
16
16
  // This file is auto-generated during build - do not edit manually
17
- // Generated from package.json version: 0.4.4
17
+ // Generated from package.json version: 0.4.6
18
18
  /**
19
19
  * The package version, injected at build time.
20
20
  * @internal
21
21
  */
22
- const VERSION = '0.4.4';
22
+ const VERSION = '0.4.6';
23
23
 
24
24
  /**
25
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -21828,14 +21828,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
21828
21828
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
21829
21829
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
21830
21830
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
21831
- const DEFAULT_VERIFIER_CONFIG = {
21832
- type: 'JWKSJWTTokenVerifier',
21833
- jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21834
- issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21835
- };
21836
21831
  const DEFAULT_PROFILE = {
21837
21832
  type: 'DefaultAuthorizer',
21838
- verifier: DEFAULT_VERIFIER_CONFIG,
21833
+ verifier: {
21834
+ type: 'JWKSJWTTokenVerifier',
21835
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21836
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21837
+ },
21839
21838
  };
21840
21839
  const OAUTH2_PROFILE = {
21841
21840
  type: 'OAuth2Authorizer',
@@ -21880,6 +21879,11 @@ const OAUTH2_CALLBACK_PROFILE = {
21880
21879
  const NOOP_PROFILE$2 = {
21881
21880
  type: 'NoopAuthorizer',
21882
21881
  };
21882
+ const DEFAULT_VERIFIER_CONFIG = {
21883
+ type: 'JWKSJWTTokenVerifier',
21884
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
21885
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21886
+ };
21883
21887
  const DEFAULT_POLICY_SOURCE = {
21884
21888
  type: 'LocalFileAuthorizationPolicySource',
21885
21889
  path: factory.Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -21931,13 +21935,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
21931
21935
  logger$K.debug('enabling_authorization_profile', {
21932
21936
  profile: normalized.profile,
21933
21937
  });
21934
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
21938
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
21939
+ const createOptions = extractCreateResourceOptions(factoryArgs);
21940
+ // Only evaluate expressions if we have env/config/variables available
21941
+ let evaluatedConfig = profileConfig;
21942
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
21943
+ if (hasContext) {
21944
+ // Build validation context from createOptions to evaluate expressions
21945
+ const validationContext = {
21946
+ env: createOptions.env,
21947
+ config: createOptions.config,
21948
+ variables: createOptions.variables,
21949
+ allowUnknownProperties: true,
21950
+ };
21951
+ // Evaluate expressions in the profile config
21952
+ const validationResult = factory.configValidator.validate(profileConfig, validationContext);
21953
+ if (!validationResult.valid) {
21954
+ const errorMessages = validationResult.errors
21955
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
21956
+ .join('; ');
21957
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
21958
+ }
21959
+ evaluatedConfig = validationResult.config ?? profileConfig;
21960
+ }
21961
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
21962
+ );
21935
21963
  if (!authorizer) {
21936
21964
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
21937
21965
  }
21938
21966
  return authorizer;
21939
21967
  }
21940
21968
  }
21969
+ /**
21970
+ * Extracts CreateResourceOptions from factoryArgs.
21971
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
21972
+ */
21973
+ function extractCreateResourceOptions(factoryArgs) {
21974
+ // Find the last object argument that looks like CreateResourceOptions
21975
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
21976
+ const arg = factoryArgs[i];
21977
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
21978
+ const candidate = arg;
21979
+ // Check if it has typical CreateResourceOptions properties
21980
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
21981
+ return candidate;
21982
+ }
21983
+ }
21984
+ }
21985
+ return {};
21986
+ }
21941
21987
  function normalizeConfig$w(config) {
21942
21988
  if (!config) {
21943
21989
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -35957,7 +36003,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35957
36003
  }
35958
36004
  if (!authorizer) {
35959
36005
  authorizer =
35960
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
36006
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
35961
36007
  }
35962
36008
  if (authorizer &&
35963
36009
  eventListeners &&
@@ -36188,14 +36234,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
36188
36234
  }
36189
36235
  return null;
36190
36236
  }
36191
- static async createAuthorizerFromConfig(config, policy) {
36237
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
36192
36238
  let authorizerConfig = config.authorizer ?? null;
36193
36239
  if (!authorizerConfig) {
36194
36240
  authorizerConfig = config.authorizer_config ?? null;
36195
36241
  }
36196
36242
  if (authorizerConfig &&
36197
36243
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
36198
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
36244
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
36199
36245
  }
36200
36246
  try {
36201
36247
  const requirements = policy.requirements?.();
@@ -36211,6 +36257,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
36211
36257
  }
36212
36258
  const tokenVerifier = new NoopTokenVerifier();
36213
36259
  return ((await AuthorizerFactory.createAuthorizer(null, {
36260
+ ...createOptions,
36214
36261
  factoryArgs: [tokenVerifier],
36215
36262
  })) ?? null);
36216
36263
  }
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.4.4
16
+ // Generated from package.json version: 0.4.6
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.4.4';
21
+ const VERSION = '0.4.6';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -21827,14 +21827,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
21827
21827
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
21828
21828
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
21829
21829
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
21830
- const DEFAULT_VERIFIER_CONFIG = {
21831
- type: 'JWKSJWTTokenVerifier',
21832
- jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21833
- issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21834
- };
21835
21830
  const DEFAULT_PROFILE = {
21836
21831
  type: 'DefaultAuthorizer',
21837
- verifier: DEFAULT_VERIFIER_CONFIG,
21832
+ verifier: {
21833
+ type: 'JWKSJWTTokenVerifier',
21834
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21835
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21836
+ },
21838
21837
  };
21839
21838
  const OAUTH2_PROFILE = {
21840
21839
  type: 'OAuth2Authorizer',
@@ -21879,6 +21878,11 @@ const OAUTH2_CALLBACK_PROFILE = {
21879
21878
  const NOOP_PROFILE$2 = {
21880
21879
  type: 'NoopAuthorizer',
21881
21880
  };
21881
+ const DEFAULT_VERIFIER_CONFIG = {
21882
+ type: 'JWKSJWTTokenVerifier',
21883
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
21884
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
21885
+ };
21882
21886
  const DEFAULT_POLICY_SOURCE = {
21883
21887
  type: 'LocalFileAuthorizationPolicySource',
21884
21888
  path: Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -21930,13 +21934,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
21930
21934
  logger$K.debug('enabling_authorization_profile', {
21931
21935
  profile: normalized.profile,
21932
21936
  });
21933
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
21937
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
21938
+ const createOptions = extractCreateResourceOptions(factoryArgs);
21939
+ // Only evaluate expressions if we have env/config/variables available
21940
+ let evaluatedConfig = profileConfig;
21941
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
21942
+ if (hasContext) {
21943
+ // Build validation context from createOptions to evaluate expressions
21944
+ const validationContext = {
21945
+ env: createOptions.env,
21946
+ config: createOptions.config,
21947
+ variables: createOptions.variables,
21948
+ allowUnknownProperties: true,
21949
+ };
21950
+ // Evaluate expressions in the profile config
21951
+ const validationResult = configValidator.validate(profileConfig, validationContext);
21952
+ if (!validationResult.valid) {
21953
+ const errorMessages = validationResult.errors
21954
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
21955
+ .join('; ');
21956
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
21957
+ }
21958
+ evaluatedConfig = validationResult.config ?? profileConfig;
21959
+ }
21960
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
21961
+ );
21934
21962
  if (!authorizer) {
21935
21963
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
21936
21964
  }
21937
21965
  return authorizer;
21938
21966
  }
21939
21967
  }
21968
+ /**
21969
+ * Extracts CreateResourceOptions from factoryArgs.
21970
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
21971
+ */
21972
+ function extractCreateResourceOptions(factoryArgs) {
21973
+ // Find the last object argument that looks like CreateResourceOptions
21974
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
21975
+ const arg = factoryArgs[i];
21976
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
21977
+ const candidate = arg;
21978
+ // Check if it has typical CreateResourceOptions properties
21979
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
21980
+ return candidate;
21981
+ }
21982
+ }
21983
+ }
21984
+ return {};
21985
+ }
21940
21986
  function normalizeConfig$w(config) {
21941
21987
  if (!config) {
21942
21988
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -35956,7 +36002,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35956
36002
  }
35957
36003
  if (!authorizer) {
35958
36004
  authorizer =
35959
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
36005
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
35960
36006
  }
35961
36007
  if (authorizer &&
35962
36008
  eventListeners &&
@@ -36187,14 +36233,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
36187
36233
  }
36188
36234
  return null;
36189
36235
  }
36190
- static async createAuthorizerFromConfig(config, policy) {
36236
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
36191
36237
  let authorizerConfig = config.authorizer ?? null;
36192
36238
  if (!authorizerConfig) {
36193
36239
  authorizerConfig = config.authorizer_config ?? null;
36194
36240
  }
36195
36241
  if (authorizerConfig &&
36196
36242
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
36197
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
36243
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
36198
36244
  }
36199
36245
  try {
36200
36246
  const requirements = policy.requirements?.();
@@ -36210,6 +36256,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
36210
36256
  }
36211
36257
  const tokenVerifier = new NoopTokenVerifier();
36212
36258
  return ((await AuthorizerFactory.createAuthorizer(null, {
36259
+ ...createOptions,
36213
36260
  factoryArgs: [tokenVerifier],
36214
36261
  })) ?? null);
36215
36262
  }
@@ -4436,12 +4436,12 @@ async function ensureRuntimeFactoriesRegistered(registry = factory.Registry) {
4436
4436
  }
4437
4437
 
4438
4438
  // This file is auto-generated during build - do not edit manually
4439
- // Generated from package.json version: 0.4.4
4439
+ // Generated from package.json version: 0.4.6
4440
4440
  /**
4441
4441
  * The package version, injected at build time.
4442
4442
  * @internal
4443
4443
  */
4444
- const VERSION = '0.4.4';
4444
+ const VERSION = '0.4.6';
4445
4445
 
4446
4446
  let initialized = false;
4447
4447
  const runtimePlugin = {
@@ -23033,14 +23033,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
23033
23033
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
23034
23034
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
23035
23035
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
23036
- const DEFAULT_VERIFIER_CONFIG = {
23037
- type: 'JWKSJWTTokenVerifier',
23038
- jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
23039
- issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23040
- };
23041
23036
  const DEFAULT_PROFILE = {
23042
23037
  type: 'DefaultAuthorizer',
23043
- verifier: DEFAULT_VERIFIER_CONFIG,
23038
+ verifier: {
23039
+ type: 'JWKSJWTTokenVerifier',
23040
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
23041
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23042
+ },
23044
23043
  };
23045
23044
  const OAUTH2_PROFILE = {
23046
23045
  type: 'OAuth2Authorizer',
@@ -23085,6 +23084,11 @@ const OAUTH2_CALLBACK_PROFILE = {
23085
23084
  const NOOP_PROFILE$2 = {
23086
23085
  type: 'NoopAuthorizer',
23087
23086
  };
23087
+ const DEFAULT_VERIFIER_CONFIG = {
23088
+ type: 'JWKSJWTTokenVerifier',
23089
+ jwks_url: factory.Expressions.env(ENV_VAR_JWKS_URL$1),
23090
+ issuer: factory.Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23091
+ };
23088
23092
  const DEFAULT_POLICY_SOURCE = {
23089
23093
  type: 'LocalFileAuthorizationPolicySource',
23090
23094
  path: factory.Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -23136,13 +23140,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
23136
23140
  logger$N.debug('enabling_authorization_profile', {
23137
23141
  profile: normalized.profile,
23138
23142
  });
23139
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
23143
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
23144
+ const createOptions = extractCreateResourceOptions(factoryArgs);
23145
+ // Only evaluate expressions if we have env/config/variables available
23146
+ let evaluatedConfig = profileConfig;
23147
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
23148
+ if (hasContext) {
23149
+ // Build validation context from createOptions to evaluate expressions
23150
+ const validationContext = {
23151
+ env: createOptions.env,
23152
+ config: createOptions.config,
23153
+ variables: createOptions.variables,
23154
+ allowUnknownProperties: true,
23155
+ };
23156
+ // Evaluate expressions in the profile config
23157
+ const validationResult = factory.configValidator.validate(profileConfig, validationContext);
23158
+ if (!validationResult.valid) {
23159
+ const errorMessages = validationResult.errors
23160
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
23161
+ .join('; ');
23162
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
23163
+ }
23164
+ evaluatedConfig = validationResult.config ?? profileConfig;
23165
+ }
23166
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
23167
+ );
23140
23168
  if (!authorizer) {
23141
23169
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
23142
23170
  }
23143
23171
  return authorizer;
23144
23172
  }
23145
23173
  }
23174
+ /**
23175
+ * Extracts CreateResourceOptions from factoryArgs.
23176
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
23177
+ */
23178
+ function extractCreateResourceOptions(factoryArgs) {
23179
+ // Find the last object argument that looks like CreateResourceOptions
23180
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
23181
+ const arg = factoryArgs[i];
23182
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
23183
+ const candidate = arg;
23184
+ // Check if it has typical CreateResourceOptions properties
23185
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
23186
+ return candidate;
23187
+ }
23188
+ }
23189
+ }
23190
+ return {};
23191
+ }
23146
23192
  function normalizeConfig$w(config) {
23147
23193
  if (!config) {
23148
23194
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -40714,7 +40760,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40714
40760
  }
40715
40761
  if (!authorizer) {
40716
40762
  authorizer =
40717
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
40763
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
40718
40764
  }
40719
40765
  if (authorizer &&
40720
40766
  eventListeners &&
@@ -40945,14 +40991,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40945
40991
  }
40946
40992
  return null;
40947
40993
  }
40948
- static async createAuthorizerFromConfig(config, policy) {
40994
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
40949
40995
  let authorizerConfig = config.authorizer ?? null;
40950
40996
  if (!authorizerConfig) {
40951
40997
  authorizerConfig = config.authorizer_config ?? null;
40952
40998
  }
40953
40999
  if (authorizerConfig &&
40954
41000
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
40955
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
41001
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
40956
41002
  }
40957
41003
  try {
40958
41004
  const requirements = policy.requirements?.();
@@ -40968,6 +41014,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40968
41014
  }
40969
41015
  const tokenVerifier = new NoopTokenVerifier();
40970
41016
  return ((await AuthorizerFactory.createAuthorizer(null, {
41017
+ ...createOptions,
40971
41018
  factoryArgs: [tokenVerifier],
40972
41019
  })) ?? null);
40973
41020
  }
@@ -4435,12 +4435,12 @@ async function ensureRuntimeFactoriesRegistered(registry = Registry) {
4435
4435
  }
4436
4436
 
4437
4437
  // This file is auto-generated during build - do not edit manually
4438
- // Generated from package.json version: 0.4.4
4438
+ // Generated from package.json version: 0.4.6
4439
4439
  /**
4440
4440
  * The package version, injected at build time.
4441
4441
  * @internal
4442
4442
  */
4443
- const VERSION = '0.4.4';
4443
+ const VERSION = '0.4.6';
4444
4444
 
4445
4445
  let initialized = false;
4446
4446
  const runtimePlugin = {
@@ -23032,14 +23032,13 @@ const ENV_VAR_JWT_REVERSE_AUTH_AUDIENCE$1 = 'FAME_JWT_REVERSE_AUTH_AUDIENCE';
23032
23032
  const ENV_VAR_HMAC_SECRET$1 = 'FAME_HMAC_SECRET';
23033
23033
  const DEFAULT_REVERSE_AUTH_ISSUER = 'reverse-auth.naylence.ai';
23034
23034
  const DEFAULT_REVERSE_AUTH_AUDIENCE = 'dev.naylence.ai';
23035
- const DEFAULT_VERIFIER_CONFIG = {
23036
- type: 'JWKSJWTTokenVerifier',
23037
- jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
23038
- issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23039
- };
23040
23035
  const DEFAULT_PROFILE = {
23041
23036
  type: 'DefaultAuthorizer',
23042
- verifier: DEFAULT_VERIFIER_CONFIG,
23037
+ verifier: {
23038
+ type: 'JWKSJWTTokenVerifier',
23039
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
23040
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23041
+ },
23043
23042
  };
23044
23043
  const OAUTH2_PROFILE = {
23045
23044
  type: 'OAuth2Authorizer',
@@ -23084,6 +23083,11 @@ const OAUTH2_CALLBACK_PROFILE = {
23084
23083
  const NOOP_PROFILE$2 = {
23085
23084
  type: 'NoopAuthorizer',
23086
23085
  };
23086
+ const DEFAULT_VERIFIER_CONFIG = {
23087
+ type: 'JWKSJWTTokenVerifier',
23088
+ jwks_url: Expressions.env(ENV_VAR_JWKS_URL$1),
23089
+ issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER$1),
23090
+ };
23087
23091
  const DEFAULT_POLICY_SOURCE = {
23088
23092
  type: 'LocalFileAuthorizationPolicySource',
23089
23093
  path: Expressions.env(ENV_VAR_AUTH_POLICY_PATH, './auth-policy.yaml'),
@@ -23135,13 +23139,55 @@ class AuthorizationProfileFactory extends AuthorizerFactory {
23135
23139
  logger$N.debug('enabling_authorization_profile', {
23136
23140
  profile: normalized.profile,
23137
23141
  });
23138
- const authorizer = await AuthorizerFactory.createAuthorizer(profileConfig, { factoryArgs });
23142
+ // Extract CreateResourceOptions from factoryArgs - it's typically the last object with env/config/variables
23143
+ const createOptions = extractCreateResourceOptions(factoryArgs);
23144
+ // Only evaluate expressions if we have env/config/variables available
23145
+ let evaluatedConfig = profileConfig;
23146
+ const hasContext = createOptions.env || createOptions.config || createOptions.variables;
23147
+ if (hasContext) {
23148
+ // Build validation context from createOptions to evaluate expressions
23149
+ const validationContext = {
23150
+ env: createOptions.env,
23151
+ config: createOptions.config,
23152
+ variables: createOptions.variables,
23153
+ allowUnknownProperties: true,
23154
+ };
23155
+ // Evaluate expressions in the profile config
23156
+ const validationResult = configValidator.validate(profileConfig, validationContext);
23157
+ if (!validationResult.valid) {
23158
+ const errorMessages = validationResult.errors
23159
+ .map((error) => `${error.path || 'root'}: ${error.message}`)
23160
+ .join('; ');
23161
+ throw new Error(`Failed to evaluate authorization profile configuration: ${errorMessages}`);
23162
+ }
23163
+ evaluatedConfig = validationResult.config ?? profileConfig;
23164
+ }
23165
+ const authorizer = await AuthorizerFactory.createAuthorizer(evaluatedConfig, hasContext ? { validate: false } : { factoryArgs } // Pass factoryArgs if no validation was done
23166
+ );
23139
23167
  if (!authorizer) {
23140
23168
  throw new Error(`Failed to create authorizer for profile: ${normalized.profile}`);
23141
23169
  }
23142
23170
  return authorizer;
23143
23171
  }
23144
23172
  }
23173
+ /**
23174
+ * Extracts CreateResourceOptions from factoryArgs.
23175
+ * The factory system passes CreateResourceOptions as an object in factoryArgs.
23176
+ */
23177
+ function extractCreateResourceOptions(factoryArgs) {
23178
+ // Find the last object argument that looks like CreateResourceOptions
23179
+ for (let i = factoryArgs.length - 1; i >= 0; i--) {
23180
+ const arg = factoryArgs[i];
23181
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
23182
+ const candidate = arg;
23183
+ // Check if it has typical CreateResourceOptions properties
23184
+ if ('env' in candidate || 'config' in candidate || 'variables' in candidate || 'factoryArgs' in candidate) {
23185
+ return candidate;
23186
+ }
23187
+ }
23188
+ }
23189
+ return {};
23190
+ }
23145
23191
  function normalizeConfig$w(config) {
23146
23192
  if (!config) {
23147
23193
  return { profile: PROFILE_NAME_OAUTH2 };
@@ -40713,7 +40759,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40713
40759
  }
40714
40760
  if (!authorizer) {
40715
40761
  authorizer =
40716
- await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
40762
+ await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
40717
40763
  }
40718
40764
  if (authorizer &&
40719
40765
  eventListeners &&
@@ -40944,14 +40990,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40944
40990
  }
40945
40991
  return null;
40946
40992
  }
40947
- static async createAuthorizerFromConfig(config, policy) {
40993
+ static async createAuthorizerFromConfig(config, policy, createOptions) {
40948
40994
  let authorizerConfig = config.authorizer ?? null;
40949
40995
  if (!authorizerConfig) {
40950
40996
  authorizerConfig = config.authorizer_config ?? null;
40951
40997
  }
40952
40998
  if (authorizerConfig &&
40953
40999
  DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
40954
- return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
41000
+ return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
40955
41001
  }
40956
41002
  try {
40957
41003
  const requirements = policy.requirements?.();
@@ -40967,6 +41013,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
40967
41013
  }
40968
41014
  const tokenVerifier = new NoopTokenVerifier();
40969
41015
  return ((await AuthorizerFactory.createAuthorizer(null, {
41016
+ ...createOptions,
40970
41017
  factoryArgs: [tokenVerifier],
40971
41018
  })) ?? null);
40972
41019
  }
@@ -2,4 +2,4 @@
2
2
  * The package version, injected at build time.
3
3
  * @internal
4
4
  */
5
- export declare const VERSION = "0.4.4";
5
+ export declare const VERSION = "0.4.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",