@naylence/runtime 0.4.5 → 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.
- package/dist/browser/index.cjs +61 -22
- package/dist/browser/index.mjs +62 -23
- package/dist/cjs/naylence/fame/security/auth/authorization-profile-factory.js +55 -17
- package/dist/cjs/naylence/fame/security/default-security-manager-factory.js +4 -3
- package/dist/cjs/version.js +2 -2
- package/dist/esm/naylence/fame/security/auth/authorization-profile-factory.js +56 -18
- package/dist/esm/naylence/fame/security/default-security-manager-factory.js +4 -3
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +61 -22
- package/dist/node/index.mjs +62 -23
- package/dist/node/node.cjs +61 -22
- package/dist/node/node.mjs +62 -23
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/browser/index.cjs
CHANGED
|
@@ -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.
|
|
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.
|
|
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:
|
|
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
|
-
|
|
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 };
|
|
@@ -22062,21 +22108,13 @@ function normalizeConfig$w(config) {
|
|
|
22062
22108
|
return { profile: canonicalProfile };
|
|
22063
22109
|
}
|
|
22064
22110
|
function resolveProfileName$2(candidate) {
|
|
22065
|
-
|
|
22066
|
-
if (direct && factory.ExpressionEvaluator.isExpression(direct)) {
|
|
22067
|
-
const evaluated = factory.ExpressionEvaluator.evaluate(direct);
|
|
22068
|
-
direct = coerceProfileString$2(evaluated);
|
|
22069
|
-
}
|
|
22111
|
+
const direct = coerceProfileString$2(candidate.profile);
|
|
22070
22112
|
if (direct) {
|
|
22071
22113
|
return direct;
|
|
22072
22114
|
}
|
|
22073
22115
|
const legacyKeys = ['profile_name', 'profileName'];
|
|
22074
22116
|
for (const legacyKey of legacyKeys) {
|
|
22075
|
-
|
|
22076
|
-
if (legacyValue && factory.ExpressionEvaluator.isExpression(legacyValue)) {
|
|
22077
|
-
const evaluated = factory.ExpressionEvaluator.evaluate(legacyValue);
|
|
22078
|
-
legacyValue = coerceProfileString$2(evaluated);
|
|
22079
|
-
}
|
|
22117
|
+
const legacyValue = coerceProfileString$2(candidate[legacyKey]);
|
|
22080
22118
|
if (legacyValue) {
|
|
22081
22119
|
return legacyValue;
|
|
22082
22120
|
}
|
|
@@ -37415,7 +37453,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37415
37453
|
}
|
|
37416
37454
|
if (!authorizer) {
|
|
37417
37455
|
authorizer =
|
|
37418
|
-
await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
|
|
37456
|
+
await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
|
|
37419
37457
|
}
|
|
37420
37458
|
if (authorizer &&
|
|
37421
37459
|
eventListeners &&
|
|
@@ -37646,14 +37684,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37646
37684
|
}
|
|
37647
37685
|
return null;
|
|
37648
37686
|
}
|
|
37649
|
-
static async createAuthorizerFromConfig(config, policy) {
|
|
37687
|
+
static async createAuthorizerFromConfig(config, policy, createOptions) {
|
|
37650
37688
|
let authorizerConfig = config.authorizer ?? null;
|
|
37651
37689
|
if (!authorizerConfig) {
|
|
37652
37690
|
authorizerConfig = config.authorizer_config ?? null;
|
|
37653
37691
|
}
|
|
37654
37692
|
if (authorizerConfig &&
|
|
37655
37693
|
DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
|
|
37656
|
-
return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
|
|
37694
|
+
return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
|
|
37657
37695
|
}
|
|
37658
37696
|
try {
|
|
37659
37697
|
const requirements = policy.requirements?.();
|
|
@@ -37669,6 +37707,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37669
37707
|
}
|
|
37670
37708
|
const tokenVerifier = new NoopTokenVerifier();
|
|
37671
37709
|
return ((await AuthorizerFactory.createAuthorizer(null, {
|
|
37710
|
+
...createOptions,
|
|
37672
37711
|
factoryArgs: [tokenVerifier],
|
|
37673
37712
|
})) ?? null);
|
|
37674
37713
|
}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseAddressComponents, FlowFlags, FameAddress, DEFAULT_POLLING_TIMEOUT_MS, extractEnvelopeAndContext, createChannelMessage, generateId, createFameEnvelope, parseAddress, formatAddress, formatAddressFromComponents, FameResponseType, localDeliveryContext, Binding, DeliveryOriginType, makeResponse, isFameMessageResponse, parseRequest, makeRequest, DEFAULT_INVOKE_TIMEOUT_MILLIS, parseResponse, ConnectorState, ConnectorStateUtils, FameFabric, isFameMessageService, isFameRPCService, FameServiceProxy, generateIdAsync, snakeToCamelObject, getDefaultFameConfigResolver, setDefaultFameConfigResolver, SigningMaterial, AuthorizationContextSchema, FameDeliveryContextSchema, SecurityContextSchema, withFabric, FameEnvelopeSchema, deserializeEnvelope, FameChannelMessage, SINK_CAPABILITY, FameFabricFactory, serializeEnvelope, createAuthorizationContext } from '@naylence/core';
|
|
2
2
|
export * from '@naylence/core';
|
|
3
3
|
import { z, ZodError } from 'zod';
|
|
4
|
-
import { Registry, AbstractResourceFactory, createResource as createResource$1, createDefaultResource, registerFactory, Expressions, ExtensionManager, ExpressionEvaluationPolicy,
|
|
4
|
+
import { Registry, AbstractResourceFactory, createResource as createResource$1, createDefaultResource, registerFactory, Expressions, ExtensionManager, ExpressionEvaluationPolicy, configValidator } from '@naylence/factory';
|
|
5
5
|
import { sign, hashes, verify } from '@noble/ed25519';
|
|
6
6
|
import { sha256, sha512 } from '@noble/hashes/sha2.js';
|
|
7
7
|
import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
@@ -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.
|
|
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.
|
|
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:
|
|
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
|
-
|
|
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 };
|
|
@@ -22060,21 +22106,13 @@ function normalizeConfig$w(config) {
|
|
|
22060
22106
|
return { profile: canonicalProfile };
|
|
22061
22107
|
}
|
|
22062
22108
|
function resolveProfileName$2(candidate) {
|
|
22063
|
-
|
|
22064
|
-
if (direct && ExpressionEvaluator.isExpression(direct)) {
|
|
22065
|
-
const evaluated = ExpressionEvaluator.evaluate(direct);
|
|
22066
|
-
direct = coerceProfileString$2(evaluated);
|
|
22067
|
-
}
|
|
22109
|
+
const direct = coerceProfileString$2(candidate.profile);
|
|
22068
22110
|
if (direct) {
|
|
22069
22111
|
return direct;
|
|
22070
22112
|
}
|
|
22071
22113
|
const legacyKeys = ['profile_name', 'profileName'];
|
|
22072
22114
|
for (const legacyKey of legacyKeys) {
|
|
22073
|
-
|
|
22074
|
-
if (legacyValue && ExpressionEvaluator.isExpression(legacyValue)) {
|
|
22075
|
-
const evaluated = ExpressionEvaluator.evaluate(legacyValue);
|
|
22076
|
-
legacyValue = coerceProfileString$2(evaluated);
|
|
22077
|
-
}
|
|
22115
|
+
const legacyValue = coerceProfileString$2(candidate[legacyKey]);
|
|
22078
22116
|
if (legacyValue) {
|
|
22079
22117
|
return legacyValue;
|
|
22080
22118
|
}
|
|
@@ -37413,7 +37451,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37413
37451
|
}
|
|
37414
37452
|
if (!authorizer) {
|
|
37415
37453
|
authorizer =
|
|
37416
|
-
await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy);
|
|
37454
|
+
await DefaultSecurityManagerFactory.createAuthorizerFromConfig(config, policy, createOptions);
|
|
37417
37455
|
}
|
|
37418
37456
|
if (authorizer &&
|
|
37419
37457
|
eventListeners &&
|
|
@@ -37644,14 +37682,14 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37644
37682
|
}
|
|
37645
37683
|
return null;
|
|
37646
37684
|
}
|
|
37647
|
-
static async createAuthorizerFromConfig(config, policy) {
|
|
37685
|
+
static async createAuthorizerFromConfig(config, policy, createOptions) {
|
|
37648
37686
|
let authorizerConfig = config.authorizer ?? null;
|
|
37649
37687
|
if (!authorizerConfig) {
|
|
37650
37688
|
authorizerConfig = config.authorizer_config ?? null;
|
|
37651
37689
|
}
|
|
37652
37690
|
if (authorizerConfig &&
|
|
37653
37691
|
DefaultSecurityManagerFactory.isConfigLike(authorizerConfig)) {
|
|
37654
|
-
return ((await AuthorizerFactory.createAuthorizer(authorizerConfig)) ?? null);
|
|
37692
|
+
return ((await AuthorizerFactory.createAuthorizer(authorizerConfig, createOptions ?? undefined)) ?? null);
|
|
37655
37693
|
}
|
|
37656
37694
|
try {
|
|
37657
37695
|
const requirements = policy.requirements?.();
|
|
@@ -37667,6 +37705,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
|
|
|
37667
37705
|
}
|
|
37668
37706
|
const tokenVerifier = new NoopTokenVerifier();
|
|
37669
37707
|
return ((await AuthorizerFactory.createAuthorizer(null, {
|
|
37708
|
+
...createOptions,
|
|
37670
37709
|
factoryArgs: [tokenVerifier],
|
|
37671
37710
|
})) ?? null);
|
|
37672
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:
|
|
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
|
-
|
|
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 };
|
|
@@ -146,21 +192,13 @@ function normalizeConfig(config) {
|
|
|
146
192
|
return { profile: canonicalProfile };
|
|
147
193
|
}
|
|
148
194
|
function resolveProfileName(candidate) {
|
|
149
|
-
|
|
150
|
-
if (direct && factory_1.ExpressionEvaluator.isExpression(direct)) {
|
|
151
|
-
const evaluated = factory_1.ExpressionEvaluator.evaluate(direct);
|
|
152
|
-
direct = coerceProfileString(evaluated);
|
|
153
|
-
}
|
|
195
|
+
const direct = coerceProfileString(candidate.profile);
|
|
154
196
|
if (direct) {
|
|
155
197
|
return direct;
|
|
156
198
|
}
|
|
157
199
|
const legacyKeys = ['profile_name', 'profileName'];
|
|
158
200
|
for (const legacyKey of legacyKeys) {
|
|
159
|
-
|
|
160
|
-
if (legacyValue && factory_1.ExpressionEvaluator.isExpression(legacyValue)) {
|
|
161
|
-
const evaluated = factory_1.ExpressionEvaluator.evaluate(legacyValue);
|
|
162
|
-
legacyValue = coerceProfileString(evaluated);
|
|
163
|
-
}
|
|
201
|
+
const legacyValue = coerceProfileString(candidate[legacyKey]);
|
|
164
202
|
if (legacyValue) {
|
|
165
203
|
return legacyValue;
|
|
166
204
|
}
|
|
@@ -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
|
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -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.
|
|
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.
|
|
10
|
+
exports.VERSION = '0.4.6';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Expressions,
|
|
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:
|
|
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
|
-
|
|
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 };
|
|
@@ -142,21 +188,13 @@ function normalizeConfig(config) {
|
|
|
142
188
|
return { profile: canonicalProfile };
|
|
143
189
|
}
|
|
144
190
|
function resolveProfileName(candidate) {
|
|
145
|
-
|
|
146
|
-
if (direct && ExpressionEvaluator.isExpression(direct)) {
|
|
147
|
-
const evaluated = ExpressionEvaluator.evaluate(direct);
|
|
148
|
-
direct = coerceProfileString(evaluated);
|
|
149
|
-
}
|
|
191
|
+
const direct = coerceProfileString(candidate.profile);
|
|
150
192
|
if (direct) {
|
|
151
193
|
return direct;
|
|
152
194
|
}
|
|
153
195
|
const legacyKeys = ['profile_name', 'profileName'];
|
|
154
196
|
for (const legacyKey of legacyKeys) {
|
|
155
|
-
|
|
156
|
-
if (legacyValue && ExpressionEvaluator.isExpression(legacyValue)) {
|
|
157
|
-
const evaluated = ExpressionEvaluator.evaluate(legacyValue);
|
|
158
|
-
legacyValue = coerceProfileString(evaluated);
|
|
159
|
-
}
|
|
197
|
+
const legacyValue = coerceProfileString(candidate[legacyKey]);
|
|
160
198
|
if (legacyValue) {
|
|
161
199
|
return legacyValue;
|
|
162
200
|
}
|
|
@@ -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
|
}
|
package/dist/esm/version.js
CHANGED
|
@@ -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.
|
|
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.
|
|
7
|
+
export const VERSION = '0.4.6';
|