@naylence/runtime 0.3.5-test.930 → 0.3.5-test.933

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.
@@ -5385,12 +5385,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5385
5385
  }
5386
5386
 
5387
5387
  // This file is auto-generated during build - do not edit manually
5388
- // Generated from package.json version: 0.3.5-test.930
5388
+ // Generated from package.json version: 0.3.5-test.933
5389
5389
  /**
5390
5390
  * The package version, injected at build time.
5391
5391
  * @internal
5392
5392
  */
5393
- const VERSION = '0.3.5-test.930';
5393
+ const VERSION = '0.3.5-test.933';
5394
5394
 
5395
5395
  /**
5396
5396
  * Fame errors module - Fame protocol specific error classes
@@ -11430,6 +11430,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11430
11430
  this.ackDedupTtlMs = 30000;
11431
11431
  this.ackDedupMaxEntries = 4096;
11432
11432
  this.textDecoder = new TextDecoder();
11433
+ this.visibilityChangeListenerRegistered = false;
11433
11434
  this.channelName =
11434
11435
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
11435
11436
  ? config.channelName.trim()
@@ -11510,6 +11511,26 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11510
11511
  };
11511
11512
  this.channel.addEventListener('message', this.onMsg);
11512
11513
  this.listenerRegistered = true;
11514
+ // Setup visibility change monitoring
11515
+ this.visibilityChangeHandler = () => {
11516
+ const isHidden = document.hidden;
11517
+ logger$10.info('broadcast_channel_visibility_changed', {
11518
+ channel: this.channelName,
11519
+ connector_id: this.connectorId,
11520
+ visibility: isHidden ? 'hidden' : 'visible',
11521
+ timestamp: new Date().toISOString(),
11522
+ });
11523
+ };
11524
+ if (typeof document !== 'undefined') {
11525
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
11526
+ this.visibilityChangeListenerRegistered = true;
11527
+ // Log initial state
11528
+ logger$10.info('broadcast_channel_initial_visibility', {
11529
+ channel: this.channelName,
11530
+ connector_id: this.connectorId,
11531
+ visibility: document.hidden ? 'hidden' : 'visible',
11532
+ });
11533
+ }
11513
11534
  }
11514
11535
  async pushToReceive(rawOrEnvelope) {
11515
11536
  const item = this._normalizeInboxItem(rawOrEnvelope);
@@ -11558,6 +11579,11 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11558
11579
  this.channel.removeEventListener('message', this.onMsg);
11559
11580
  this.listenerRegistered = false;
11560
11581
  }
11582
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
11583
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
11584
+ this.visibilityChangeListenerRegistered = false;
11585
+ this.visibilityChangeHandler = undefined;
11586
+ }
11561
11587
  this.channel.close();
11562
11588
  const closeCode = typeof code === 'number' ? code : 1000;
11563
11589
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
@@ -14175,10 +14201,10 @@ class TraceEmitterFactory extends AbstractResourceFactory {
14175
14201
  return traceEmitter;
14176
14202
  }
14177
14203
  }
14178
- // Ensure default factories are registered lazily to avoid circular ESM initialization issues
14179
- void Promise.resolve().then(function () { return noopTraceEmitterFactory; });
14180
- void Promise.resolve().then(function () { return openTelemetryTraceEmitterFactory; });
14181
- void Promise.resolve().then(function () { return traceEmitterProfileFactory; });
14204
+ // // Ensure default factories are registered lazily to avoid circular ESM initialization issues
14205
+ // void import('./noop-trace-emitter-factory.js');
14206
+ // void import('./open-telemetry-trace-emitter-factory.js');
14207
+ // void import('./trace-emitter-profile-factory.js');
14182
14208
 
14183
14209
  const BINDING_STORE_NAMESPACE = '__binding_store';
14184
14210
  const logger$X = getLogger('naylence.fame.node.factory_commons');
@@ -34180,839 +34206,217 @@ async function main() {
34180
34206
  process.on('SIGTERM', () => shutdown('SIGTERM'));
34181
34207
  }
34182
34208
 
34183
- const telemetryLogger = getLogger('naylence.fame.telemetry.base_trace_emitter');
34184
- function logTelemetryFailure(event, error, context = {}) {
34185
- telemetryLogger.warning(event, {
34186
- ...context,
34187
- error: error instanceof Error ? error.message : String(error),
34188
- stack: error instanceof Error && error.stack ? error.stack : undefined,
34189
- });
34190
- }
34191
- function buildEnvelopeAttributes(envelope) {
34192
- return {
34193
- 'env.id': envelope.id,
34194
- 'env.trace_id': envelope.traceId,
34195
- 'env.corr_id': envelope.corrId,
34196
- 'env.flow_id': envelope.flowId,
34197
- 'env.seq_id': envelope.seqId,
34198
- 'env.to': envelope.to ?? null,
34199
- 'env.priority': envelope.priority ?? null,
34200
- 'env.sid': envelope.sid ?? null,
34201
- 'env.reply_to': envelope.replyTo ?? null,
34202
- 'env.ts': envelope.ts?.toISOString?.() ?? null,
34203
- 'env.frame_type': envelope.frame
34204
- ? (envelope.frame.type ?? null)
34205
- : null,
34206
- 'env.is_signed': Boolean(envelope.sec?.sig),
34207
- 'env.sign_kid': envelope.sec?.sig?.kid ?? null,
34208
- 'env.is_encrypted': Boolean(envelope.sec?.enc),
34209
- 'env.enc_kid': envelope.sec?.enc?.kid ?? null,
34210
- };
34209
+ /**
34210
+ * Base abstraction for message delivery policies.
34211
+ */
34212
+ class DeliveryPolicy {
34213
+ constructor(options = {}) {
34214
+ this.senderPolicy = options.senderRetryPolicy;
34215
+ this.receiverPolicy = options.receiverRetryPolicy;
34216
+ }
34217
+ /**
34218
+ * Determine if the policy requires an acknowledgement for the envelope.
34219
+ */
34220
+ isAckRequired(_envelope) {
34221
+ return false;
34222
+ }
34223
+ get senderRetryPolicy() {
34224
+ return this.senderPolicy;
34225
+ }
34226
+ get receiverRetryPolicy() {
34227
+ return this.receiverPolicy;
34228
+ }
34211
34229
  }
34212
- function filterAttributes(attributes) {
34213
- const filtered = {};
34214
- for (const [key, value] of Object.entries(attributes)) {
34215
- if (value !== undefined && value !== null) {
34216
- filtered[key] = value;
34230
+
34231
+ /**
34232
+ * Message delivery policy that ensures envelopes are delivered at least once.
34233
+ */
34234
+ class AtLeastOnceDeliveryPolicy extends DeliveryPolicy {
34235
+ constructor(options = {}) {
34236
+ super(options);
34237
+ }
34238
+ isAckRequired(envelope) {
34239
+ const frame = envelope?.frame;
34240
+ const frameType = typeof frame?.type === 'string' ? frame.type : null;
34241
+ if (!frameType) {
34242
+ return false;
34217
34243
  }
34244
+ return frameType === 'Data' || frameType === 'DataFrame';
34218
34245
  }
34219
- return filtered;
34220
34246
  }
34221
- function extractContextValue(context, keys) {
34222
- if (!context) {
34223
- return undefined;
34247
+
34248
+ /**
34249
+ * Configuration and helper for retry backoff behaviour.
34250
+ */
34251
+ class RetryPolicy {
34252
+ constructor(options = {}) {
34253
+ this.maxRetries = Math.max(0, Math.trunc(options.maxRetries ?? 0));
34254
+ this.baseDelayMs = Math.max(0, Math.trunc(options.baseDelayMs ?? 200));
34255
+ this.maxDelayMs = Math.max(this.baseDelayMs, Math.trunc(options.maxDelayMs ?? 10000));
34256
+ this.jitterMs = Math.max(0, Math.trunc(options.jitterMs ?? 50));
34257
+ this.backoffFactor = Math.max(0, options.backoffFactor ?? 2.0);
34224
34258
  }
34225
- const source = context;
34226
- for (const key of keys) {
34227
- if (Object.prototype.hasOwnProperty.call(source, key)) {
34228
- const value = source[key];
34229
- if (value !== undefined) {
34230
- return value;
34231
- }
34232
- }
34259
+ /**
34260
+ * Calculate the next retry delay based on attempt number (0-indexed).
34261
+ */
34262
+ nextDelayMs(attempt) {
34263
+ const normalizedAttempt = Number.isFinite(attempt)
34264
+ ? Math.max(0, Math.trunc(attempt))
34265
+ : 0;
34266
+ const base = normalizedAttempt <= 0
34267
+ ? this.baseDelayMs
34268
+ : Math.round(this.baseDelayMs * this.backoffFactor ** normalizedAttempt);
34269
+ const jitter = this.jitterMs > 0
34270
+ ? Math.round((Math.random() * 2 - 1) * this.jitterMs)
34271
+ : 0;
34272
+ const withJitter = base + jitter;
34273
+ return Math.min(this.maxDelayMs, Math.max(0, withJitter));
34233
34274
  }
34234
- return undefined;
34235
34275
  }
34236
- class BaseTraceEmitter extends BaseNodeEventListener {
34276
+
34277
+ const LEGACY_POLICY_KEYS = {
34278
+ senderRetryPolicy: ['sender_retry_policy', 'sender_retryPolicy'],
34279
+ receiverRetryPolicy: ['receiver_retry_policy', 'receiver_retryPolicy'],
34280
+ };
34281
+ class AtLeastOnceDeliveryPolicyFactory extends DeliveryPolicyFactory {
34237
34282
  constructor() {
34238
34283
  super(...arguments);
34239
- this.node = null;
34240
- this.inflight = new Map();
34241
- this.priority = 10000;
34284
+ this.type = 'AtLeastOnceDeliveryPolicy';
34285
+ this.isDefault = true;
34242
34286
  }
34243
- getSpanKey(envelope, operationKey) {
34244
- return `${envelope.id}:${operationKey}`;
34287
+ async create(config) {
34288
+ const normalized = normalizeAtLeastOnceConfig(config);
34289
+ const options = {
34290
+ ...(normalized.senderRetryPolicy
34291
+ ? { senderRetryPolicy: normalized.senderRetryPolicy }
34292
+ : {}),
34293
+ ...(normalized.receiverRetryPolicy
34294
+ ? { receiverRetryPolicy: normalized.receiverRetryPolicy }
34295
+ : {}),
34296
+ };
34297
+ return new AtLeastOnceDeliveryPolicy(options);
34245
34298
  }
34246
- startEnvelopeOperationSpan(node, operationName, envelope, operationKey, additionalAttributes = null) {
34247
- try {
34248
- const key = this.getSpanKey(envelope, operationKey);
34249
- const previous = this.inflight.get(key);
34250
- if (previous) {
34251
- this.inflight.delete(key);
34252
- try {
34253
- previous.scope.exit();
34254
- }
34255
- catch (cleanupError) {
34256
- logTelemetryFailure('trace_span_scope_exit_failed', cleanupError, {
34257
- operation: operationName,
34258
- span_key: key,
34259
- });
34260
- }
34261
- }
34262
- const attributes = buildEnvelopeAttributes(envelope);
34263
- if (additionalAttributes) {
34264
- for (const [attrKey, attrValue] of Object.entries(additionalAttributes)) {
34265
- attributes[attrKey] = attrValue;
34266
- }
34267
- }
34268
- const effectiveNode = node ?? this.node;
34269
- if (effectiveNode) {
34270
- attributes['node.id'] = effectiveNode.id;
34271
- attributes['node.sid'] = effectiveNode.sid ?? null;
34272
- }
34273
- const scope = this.startSpan(operationName, {
34274
- attributes: filterAttributes(attributes),
34275
- });
34276
- const span = scope.enter();
34277
- this.inflight.set(key, { scope, span });
34278
- }
34279
- catch (error) {
34280
- logTelemetryFailure('trace_span_start_failed', error, {
34281
- operation: operationName,
34282
- envelope_id: envelope.id,
34283
- });
34284
- }
34285
- return envelope;
34299
+ }
34300
+ function normalizeAtLeastOnceConfig(config) {
34301
+ if (!config) {
34302
+ return {};
34286
34303
  }
34287
- completeEnvelopeOperationSpan(node, operationName, envelope, operationKey, _result = null, error = null, additionalAttributes = null) {
34288
- try {
34289
- const key = this.getSpanKey(envelope, operationKey);
34290
- let active = this.inflight.get(key);
34291
- if (!active) {
34292
- const attributes = buildEnvelopeAttributes(envelope);
34293
- if (additionalAttributes) {
34294
- for (const [attrKey, attrValue] of Object.entries(additionalAttributes)) {
34295
- attributes[attrKey] = attrValue;
34296
- }
34297
- }
34298
- const effectiveNode = node ?? this.node;
34299
- if (effectiveNode) {
34300
- attributes['node.id'] = effectiveNode.id;
34301
- attributes['node.sid'] = effectiveNode.sid ?? null;
34302
- }
34303
- const scope = this.startSpan(operationName, {
34304
- attributes: filterAttributes(attributes),
34305
- });
34306
- const span = scope.enter();
34307
- active = { scope, span };
34308
- }
34309
- else {
34310
- this.inflight.delete(key);
34311
- }
34312
- if (error !== null && error !== undefined) {
34313
- try {
34314
- active.span.recordException(error);
34315
- }
34316
- catch (recordError) {
34317
- logTelemetryFailure('trace_span_record_exception_failed', recordError, {
34318
- operation: operationName,
34319
- envelope_id: envelope.id,
34320
- });
34321
- }
34322
- try {
34323
- const description = error instanceof Error ? error.message : String(error);
34324
- active.span.setStatusError(description);
34325
- }
34326
- catch (statusError) {
34327
- logTelemetryFailure('trace_span_set_status_failed', statusError, {
34328
- operation: operationName,
34329
- envelope_id: envelope.id,
34330
- });
34331
- }
34332
- }
34333
- try {
34334
- active.scope.exit();
34335
- }
34336
- catch (exitError) {
34337
- logTelemetryFailure('trace_span_scope_exit_failed', exitError, {
34338
- operation: operationName,
34339
- envelope_id: envelope.id,
34340
- });
34341
- }
34342
- }
34343
- catch (error) {
34344
- logTelemetryFailure('trace_span_complete_failed', error, {
34345
- operation: operationName,
34346
- envelope_id: envelope.id,
34347
- });
34348
- }
34349
- return envelope;
34304
+ const candidate = config;
34305
+ const senderPolicyInput = getRetryPolicyInput(candidate, 'senderRetryPolicy');
34306
+ const receiverPolicyInput = getRetryPolicyInput(candidate, 'receiverRetryPolicy');
34307
+ return {
34308
+ senderRetryPolicy: resolveRetryPolicy(senderPolicyInput),
34309
+ receiverRetryPolicy: resolveRetryPolicy(receiverPolicyInput),
34310
+ };
34311
+ }
34312
+ function getRetryPolicyInput(candidate, key) {
34313
+ const camelKey = key;
34314
+ const primary = candidate[camelKey];
34315
+ if (primary !== undefined) {
34316
+ return primary;
34350
34317
  }
34351
- async onEnvelopeReceived(node, envelope, context) {
34352
- try {
34353
- const attributes = buildEnvelopeAttributes(envelope);
34354
- attributes['node.id'] = node.id;
34355
- attributes['node.sid'] = node.sid ?? null;
34356
- const fromNodeId = extractContextValue(context, [
34357
- 'fromSystemId',
34358
- 'from_system_id',
34359
- 'fromNodeId',
34360
- 'from_node_id',
34361
- ]);
34362
- if (fromNodeId !== undefined && fromNodeId !== null) {
34363
- attributes['from.node_id'] = String(fromNodeId);
34364
- }
34365
- const originType = extractContextValue(context, [
34366
- 'originType',
34367
- 'origin_type',
34368
- ]);
34369
- if (originType !== undefined && originType !== null) {
34370
- attributes['from.origin_type'] = String(originType);
34371
- }
34372
- const scope = this.startSpan('env.received', {
34373
- attributes: filterAttributes(attributes),
34374
- });
34375
- scope.enter();
34376
- scope.exit();
34377
- }
34378
- catch (error) {
34379
- logTelemetryFailure('trace_span_received_failed', error, {
34380
- envelope_id: envelope.id,
34381
- });
34318
+ const legacyKeys = LEGACY_POLICY_KEYS[key] ?? [];
34319
+ for (const legacyKey of legacyKeys) {
34320
+ const value = candidate[legacyKey];
34321
+ if (value !== undefined) {
34322
+ candidate[camelKey] = value;
34323
+ return value;
34382
34324
  }
34383
- return envelope;
34384
- }
34385
- async onForwardToRoute(node, nextSegment, envelope, _context) {
34386
- return this.startEnvelopeOperationSpan(node, 'env.fwd_to_route', envelope, nextSegment, {
34387
- 'route.segment': nextSegment,
34388
- });
34389
- }
34390
- async onForwardToRouteComplete(node, nextSegment, envelope, result, error, _context) {
34391
- return this.completeEnvelopeOperationSpan(node, 'env.fwd_to_route', envelope, nextSegment, result, error, {
34392
- 'route.segment': nextSegment,
34393
- });
34394
- }
34395
- async onForwardUpstream(node, envelope, _context) {
34396
- return this.startEnvelopeOperationSpan(node, 'env.fwd_upstream', envelope, 'upstream', {
34397
- direction: 'upstream',
34398
- });
34399
- }
34400
- async onForwardUpstreamComplete(node, envelope, result, error, _context) {
34401
- return this.completeEnvelopeOperationSpan(node, 'env.fwd_upstream', envelope, 'upstream', result, error, {
34402
- direction: 'upstream',
34403
- });
34404
- }
34405
- async onForwardToPeer(node, peerSegment, envelope, _context) {
34406
- return this.startEnvelopeOperationSpan(node, 'env.fwd_to_peer', envelope, peerSegment, {
34407
- 'peer.segment': peerSegment,
34408
- });
34409
- }
34410
- async onForwardToPeerComplete(node, peerSegment, envelope, result, error, _context) {
34411
- return this.completeEnvelopeOperationSpan(node, 'env.fwd_to_peer', envelope, peerSegment, result, error, {
34412
- 'peer.segment': peerSegment,
34413
- });
34414
34325
  }
34415
- async onDeliverLocal(node, address, envelope, _context) {
34416
- const addressKey = address ? String(address) : 'unknown';
34417
- return this.startEnvelopeOperationSpan(node, 'env.deliver_local', envelope, addressKey, {
34418
- 'delivery.address': addressKey,
34419
- 'delivery.type': 'local',
34420
- });
34421
- }
34422
- async onDeliverLocalComplete(node, address, envelope, _context) {
34423
- const addressKey = address ? String(address) : 'unknown';
34424
- return this.completeEnvelopeOperationSpan(node, 'env.deliver_local', envelope, addressKey, null, null, {
34425
- 'delivery.address': addressKey,
34426
- 'delivery.type': 'local',
34427
- });
34326
+ return undefined;
34327
+ }
34328
+ function resolveRetryPolicy(input) {
34329
+ if (!input) {
34330
+ return undefined;
34428
34331
  }
34429
- async onNodeInitialized(node) {
34430
- this.node = node;
34332
+ if (input instanceof RetryPolicy) {
34333
+ return input;
34431
34334
  }
34432
- async onNodeStopped(_node) {
34433
- try {
34434
- if (typeof this.flush === 'function') {
34435
- await this.flush();
34335
+ const record = input;
34336
+ const options = {
34337
+ ...(withOption(record, ['maxRetries', 'max_retries']) ?? {}),
34338
+ ...(withOption(record, ['baseDelayMs', 'base_delay_ms']) ?? {}),
34339
+ ...(withOption(record, ['maxDelayMs', 'max_delay_ms']) ?? {}),
34340
+ ...(withOption(record, ['jitterMs', 'jitter_ms']) ?? {}),
34341
+ ...(withOption(record, ['backoffFactor', 'backoff_factor']) ?? {}),
34342
+ };
34343
+ return new RetryPolicy(options);
34344
+ }
34345
+ function extractNumber(source, keys) {
34346
+ for (const key of keys) {
34347
+ if (key in source) {
34348
+ const value = source[key];
34349
+ if (typeof value === 'number' && Number.isFinite(value)) {
34350
+ return value;
34436
34351
  }
34437
- if (typeof this.shutdown === 'function') {
34438
- await this.shutdown();
34352
+ if (typeof value === 'string' && value.trim().length > 0) {
34353
+ const parsed = Number(value);
34354
+ if (!Number.isNaN(parsed)) {
34355
+ return parsed;
34356
+ }
34439
34357
  }
34440
34358
  }
34441
- catch (error) {
34442
- logTelemetryFailure('trace_span_shutdown_failed', error);
34443
- }
34444
- }
34445
- async flush() {
34446
- // Default implementation: no-op
34447
- }
34448
- async shutdown() {
34449
- // Default implementation: no-op
34450
- }
34451
- }
34452
-
34453
- class NoopTraceSpan {
34454
- setAttribute() { }
34455
- recordException() { }
34456
- setStatusError() { }
34457
- }
34458
- class NoopTraceSpanScope {
34459
- constructor(span) {
34460
- this.span = span;
34461
- }
34462
- enter() {
34463
- return this.span;
34464
34359
  }
34465
- exit() { }
34360
+ return undefined;
34466
34361
  }
34467
- class NoopTraceEmitter extends BaseTraceEmitter {
34468
- startSpan(_name, _options) {
34469
- void _options;
34470
- return new NoopTraceSpanScope(new NoopTraceSpan());
34362
+ function withOption(source, keys) {
34363
+ const value = extractNumber(source, keys);
34364
+ if (value === undefined) {
34365
+ return undefined;
34471
34366
  }
34367
+ const camelKey = keys[0];
34368
+ return {
34369
+ [camelKey]: value,
34370
+ };
34472
34371
  }
34473
-
34474
34372
  const FACTORY_META$R = {
34475
- base: TRACE_EMITTER_FACTORY_BASE_TYPE,
34476
- key: 'NoopTraceEmitter',
34373
+ base: DELIVERY_POLICY_FACTORY_BASE_TYPE,
34374
+ key: 'AtLeastOnceDeliveryPolicy',
34477
34375
  };
34478
- class NoopTraceEmitterFactory extends TraceEmitterFactory {
34479
- constructor() {
34480
- super(...arguments);
34481
- this.type = 'NoopTraceEmitter';
34482
- this.isDefault = true;
34483
- this.priority = 100;
34484
- }
34485
- async create() {
34486
- return new NoopTraceEmitter();
34487
- }
34488
- }
34489
34376
 
34490
- var noopTraceEmitterFactory = /*#__PURE__*/Object.freeze({
34377
+ var atLeastOnceDeliveryPolicyFactory = /*#__PURE__*/Object.freeze({
34491
34378
  __proto__: null,
34379
+ AtLeastOnceDeliveryPolicyFactory: AtLeastOnceDeliveryPolicyFactory,
34492
34380
  FACTORY_META: FACTORY_META$R,
34493
- NoopTraceEmitterFactory: NoopTraceEmitterFactory,
34494
- default: NoopTraceEmitterFactory
34381
+ default: AtLeastOnceDeliveryPolicyFactory
34495
34382
  });
34496
34383
 
34497
- let openTelemetryTraceEmitterModulePromise = null;
34498
- let otelApiModulePromise = null;
34499
- let otelSetupModulePromise = null;
34500
- const logger$h = getLogger('naylence.fame.telemetry.open_telemetry_trace_emitter_factory');
34501
- const MISSING_OTEL_HELP_MESSAGE = 'Missing optional OpenTelemetry dependency. Install @opentelemetry/api (and related packages) to enable trace emission.';
34502
- function getOpenTelemetryTraceEmitterModule() {
34503
- if (!openTelemetryTraceEmitterModulePromise) {
34504
- openTelemetryTraceEmitterModulePromise = safeImport(() => Promise.resolve().then(function () { return openTelemetryTraceEmitter; }), '@opentelemetry/api', {
34505
- helpMessage: MISSING_OTEL_HELP_MESSAGE,
34506
- });
34384
+ /**
34385
+ * Message delivery policy that ensures envelopes are delivered at most once.
34386
+ */
34387
+ class AtMostOnceDeliveryPolicy extends DeliveryPolicy {
34388
+ constructor() {
34389
+ super();
34507
34390
  }
34508
- return openTelemetryTraceEmitterModulePromise;
34509
- }
34510
- function getOtelApiModule() {
34511
- if (!otelApiModulePromise) {
34512
- otelApiModulePromise = safeImport(() => import('@opentelemetry/api'), '@opentelemetry/api', {
34513
- helpMessage: MISSING_OTEL_HELP_MESSAGE,
34514
- });
34391
+ isAckRequired(_envelope) {
34392
+ return false;
34515
34393
  }
34516
- return otelApiModulePromise;
34517
34394
  }
34518
- function getOtelSetupModule() {
34519
- if (!otelSetupModulePromise) {
34520
- otelSetupModulePromise = safeImport(() => Promise.resolve().then(function () { return otelSetup; }), '@opentelemetry/api', {
34521
- helpMessage: MISSING_OTEL_HELP_MESSAGE,
34522
- });
34395
+
34396
+ class AtMostOnceDeliveryPolicyFactory extends DeliveryPolicyFactory {
34397
+ constructor() {
34398
+ super(...arguments);
34399
+ this.type = 'AtMostOnceDeliveryPolicy';
34400
+ }
34401
+ async create(_config) {
34402
+ return new AtMostOnceDeliveryPolicy();
34523
34403
  }
34524
- return otelSetupModulePromise;
34525
34404
  }
34405
+ registerDeliveryPolicyFactory('AtMostOnceDeliveryPolicy', AtMostOnceDeliveryPolicyFactory);
34406
+ registerDeliveryPolicyFactory('AtMostOnceMessageDeliveryPolicy', AtMostOnceDeliveryPolicyFactory);
34526
34407
  const FACTORY_META$Q = {
34527
- base: TRACE_EMITTER_FACTORY_BASE_TYPE,
34528
- key: 'OpenTelemetryTraceEmitter',
34529
- };
34530
- class OpenTelemetryTraceEmitterFactory extends TraceEmitterFactory {
34531
- constructor() {
34532
- super(...arguments);
34533
- this.type = 'OpenTelemetryTraceEmitter';
34534
- }
34535
- async create(config, ...factoryArgs) {
34536
- const options = (factoryArgs[0] ??
34537
- {});
34538
- const normalized = normalizeConfig$n(config);
34539
- const mergedHeaders = {
34540
- ...normalized.headers,
34541
- ...(options.headers ?? {}),
34542
- };
34543
- let authStrategy = null;
34544
- if (normalized.auth) {
34545
- authStrategy =
34546
- await AuthInjectionStrategyFactory.createAuthInjectionStrategy(normalized.auth);
34547
- try {
34548
- await authStrategy.apply(mergedHeaders);
34549
- logger$h.info('trace_emitter_auth_applied', {
34550
- service_name: normalized.serviceName,
34551
- });
34552
- }
34553
- catch (error) {
34554
- try {
34555
- await authStrategy.cleanup();
34556
- }
34557
- catch {
34558
- // Ignore cleanup errors while propagating original failure
34559
- }
34560
- throw error;
34561
- }
34562
- }
34563
- let lifecycle = null;
34564
- try {
34565
- const { setupOtel } = await getOtelSetupModule();
34566
- lifecycle = await setupOtel({
34567
- serviceName: normalized.serviceName,
34568
- endpoint: normalized.endpoint,
34569
- environment: normalized.environment,
34570
- sampler: normalized.sampler,
34571
- headers: Object.keys(mergedHeaders).length > 0 ? mergedHeaders : undefined,
34572
- });
34573
- logger$h.debug('trace_emitter_lifecycle_acquired', {
34574
- service_name: normalized.serviceName,
34575
- lifecycle_available: Boolean(lifecycle),
34576
- });
34577
- }
34578
- catch (error) {
34579
- if (authStrategy) {
34580
- try {
34581
- await authStrategy.cleanup();
34582
- }
34583
- catch {
34584
- // Ignore cleanup errors while propagating original failure
34585
- }
34586
- }
34587
- throw error;
34588
- }
34589
- const [{ OpenTelemetryTraceEmitter }, otelModule] = await Promise.all([
34590
- getOpenTelemetryTraceEmitterModule(),
34591
- getOtelApiModule(),
34592
- ]);
34593
- const emitterOptions = {
34594
- serviceName: normalized.serviceName,
34595
- otelApi: {
34596
- trace: otelModule.trace,
34597
- SpanStatusCode: otelModule.SpanStatusCode,
34598
- },
34599
- };
34600
- if (options.tracer) {
34601
- emitterOptions.tracer = options.tracer;
34602
- }
34603
- if (lifecycle) {
34604
- emitterOptions.lifecycle = lifecycle;
34605
- }
34606
- if (authStrategy) {
34607
- emitterOptions.authStrategy = authStrategy;
34608
- }
34609
- try {
34610
- const emitter = new OpenTelemetryTraceEmitter(emitterOptions);
34611
- logger$h.debug('trace_emitter_created', {
34612
- service_name: normalized.serviceName,
34613
- has_lifecycle: Boolean(lifecycle),
34614
- has_auth_strategy: Boolean(authStrategy),
34615
- });
34616
- return emitter;
34617
- }
34618
- catch (error) {
34619
- if (authStrategy) {
34620
- try {
34621
- await authStrategy.cleanup();
34622
- }
34623
- catch {
34624
- // Best effort cleanup
34625
- }
34626
- }
34627
- throw error;
34628
- }
34629
- }
34630
- }
34631
- function normalizeConfig$n(config) {
34632
- if (!config) {
34633
- return {
34634
- serviceName: 'naylence-service',
34635
- endpoint: null,
34636
- environment: null,
34637
- sampler: null,
34638
- headers: {},
34639
- auth: null,
34640
- };
34641
- }
34642
- const candidate = config;
34643
- const serviceName = extractString(pickFirst$2(candidate, ['serviceName', 'service_name'])) ??
34644
- 'naylence-service';
34645
- const endpoint = extractString(pickFirst$2(candidate, ['endpoint', 'otlpEndpoint', 'otlp_endpoint'])) ?? null;
34646
- const environment = extractString(pickFirst$2(candidate, [
34647
- 'environment',
34648
- 'deploymentEnvironment',
34649
- 'deployment_environment',
34650
- ])) ?? null;
34651
- const sampler = extractString(pickFirst$2(candidate, ['sampler', 'samplingStrategy', 'sampling_strategy'])) ?? null;
34652
- const headersFromConfig = extractHeaders$1(pickFirst$2(candidate, ['headers', 'otlpHeaders', 'otlp_headers']));
34653
- const authConfig = pickFirst$2(candidate, [
34654
- 'auth',
34655
- ]);
34656
- return {
34657
- serviceName,
34658
- endpoint,
34659
- environment,
34660
- sampler,
34661
- headers: headersFromConfig ?? {},
34662
- auth: authConfig ?? null,
34663
- };
34664
- }
34665
- function extractString(value) {
34666
- if (typeof value === 'string' && value.trim().length > 0) {
34667
- return value;
34668
- }
34669
- return undefined;
34670
- }
34671
- function pickFirst$2(source, keys) {
34672
- for (const key of keys) {
34673
- if (Object.prototype.hasOwnProperty.call(source, key)) {
34674
- const value = source[key];
34675
- if (value !== undefined) {
34676
- return value;
34677
- }
34678
- }
34679
- }
34680
- return undefined;
34681
- }
34682
- function extractHeaders$1(value) {
34683
- if (!value || typeof value !== 'object') {
34684
- return null;
34685
- }
34686
- const headers = {};
34687
- for (const [key, raw] of Object.entries(value)) {
34688
- if (typeof raw === 'string') {
34689
- headers[key] = raw;
34690
- }
34691
- }
34692
- return Object.keys(headers).length > 0 ? headers : null;
34693
- }
34694
-
34695
- var openTelemetryTraceEmitterFactory = /*#__PURE__*/Object.freeze({
34696
- __proto__: null,
34697
- FACTORY_META: FACTORY_META$Q,
34698
- OpenTelemetryTraceEmitterFactory: OpenTelemetryTraceEmitterFactory,
34699
- default: OpenTelemetryTraceEmitterFactory
34700
- });
34701
-
34702
- const logger$g = getLogger('naylence.fame.telemetry.trace_emitter_profile_factory');
34703
- const PROFILE_NAME_NOOP$1 = 'noop';
34704
- const PROFILE_NAME_OPEN_TELEMETRY = 'open-telemetry';
34705
- const ENV_VAR_TELEMETRY_SERVICE_NAME = 'FAME_TELEMETRY_SERVICE_NAME';
34706
- const NOOP_PROFILE$1 = {
34707
- type: 'NoopTraceEmitter',
34708
- };
34709
- const OPEN_TELEMETRY_PROFILE = {
34710
- type: 'OpenTelemetryTraceEmitter',
34711
- serviceName: Expressions.env(ENV_VAR_TELEMETRY_SERVICE_NAME, 'naylence-service'),
34712
- headers: {},
34713
- };
34714
- const PROFILE_MAP$3 = {
34715
- [PROFILE_NAME_NOOP$1]: NOOP_PROFILE$1,
34716
- [PROFILE_NAME_OPEN_TELEMETRY]: OPEN_TELEMETRY_PROFILE,
34717
- };
34718
- const FACTORY_META$P = {
34719
- base: TRACE_EMITTER_FACTORY_BASE_TYPE,
34720
- key: 'TraceEmitterProfile',
34721
- };
34722
- class TraceEmitterProfileFactory extends TraceEmitterFactory {
34723
- constructor() {
34724
- super(...arguments);
34725
- this.type = 'TraceEmitterProfile';
34726
- }
34727
- async create(config, ...factoryArgs) {
34728
- const normalized = normalizeTraceEmitterProfileConfig(config);
34729
- const profileConfig = resolveProfileConfig$2(normalized.profile);
34730
- logger$g.debug('enabling_trace_emitter_profile', {
34731
- profile: normalized.profile,
34732
- });
34733
- const traceEmitter = await TraceEmitterFactory.createTraceEmitter(profileConfig, {
34734
- factoryArgs,
34735
- });
34736
- if (!traceEmitter) {
34737
- throw new Error(`Failed to instantiate trace emitter profile: ${normalized.profile}`);
34738
- }
34739
- return traceEmitter;
34740
- }
34741
- }
34742
- function normalizeTraceEmitterProfileConfig(config) {
34743
- if (!config) {
34744
- return { profile: PROFILE_NAME_NOOP$1 };
34745
- }
34746
- const candidate = config;
34747
- const profileValue = resolveProfileName$1(candidate);
34748
- const canonicalProfile = canonicalizeProfileName(profileValue);
34749
- candidate.profile = canonicalProfile;
34750
- return { profile: canonicalProfile };
34751
- }
34752
- function resolveProfileName$1(candidate) {
34753
- const direct = coerceProfileString$1(candidate.profile);
34754
- if (direct) {
34755
- return direct;
34756
- }
34757
- const legacyKeys = ['profile_name', 'profileName'];
34758
- for (const legacyKey of legacyKeys) {
34759
- const legacyValue = coerceProfileString$1(candidate[legacyKey]);
34760
- if (legacyValue) {
34761
- return legacyValue;
34762
- }
34763
- }
34764
- return PROFILE_NAME_NOOP$1;
34765
- }
34766
- function coerceProfileString$1(value) {
34767
- if (typeof value !== 'string') {
34768
- return null;
34769
- }
34770
- const trimmed = value.trim();
34771
- return trimmed.length > 0 ? trimmed : null;
34772
- }
34773
- const PROFILE_ALIASES = {
34774
- noop: PROFILE_NAME_NOOP$1,
34775
- 'no-op': PROFILE_NAME_NOOP$1,
34776
- no_op: PROFILE_NAME_NOOP$1,
34777
- 'open-telemetry': PROFILE_NAME_OPEN_TELEMETRY,
34778
- open_telemetry: PROFILE_NAME_OPEN_TELEMETRY,
34779
- opentelemetry: PROFILE_NAME_OPEN_TELEMETRY,
34780
- };
34781
- function canonicalizeProfileName(value) {
34782
- const normalized = value.replace(/[\s_]+/g, '-').toLowerCase();
34783
- return PROFILE_ALIASES[normalized] ?? normalized;
34784
- }
34785
- function resolveProfileConfig$2(profileName) {
34786
- const profile = PROFILE_MAP$3[profileName];
34787
- if (!profile) {
34788
- throw new Error(`Unknown trace emitter profile: ${profileName}`);
34789
- }
34790
- return deepClone$2(profile);
34791
- }
34792
- function deepClone$2(value) {
34793
- return JSON.parse(JSON.stringify(value));
34794
- }
34795
-
34796
- var traceEmitterProfileFactory = /*#__PURE__*/Object.freeze({
34797
- __proto__: null,
34798
- FACTORY_META: FACTORY_META$P,
34799
- PROFILE_NAME_NOOP: PROFILE_NAME_NOOP$1,
34800
- PROFILE_NAME_OPEN_TELEMETRY: PROFILE_NAME_OPEN_TELEMETRY,
34801
- TraceEmitterProfileFactory: TraceEmitterProfileFactory,
34802
- default: TraceEmitterProfileFactory
34803
- });
34804
-
34805
- /**
34806
- * Base abstraction for message delivery policies.
34807
- */
34808
- class DeliveryPolicy {
34809
- constructor(options = {}) {
34810
- this.senderPolicy = options.senderRetryPolicy;
34811
- this.receiverPolicy = options.receiverRetryPolicy;
34812
- }
34813
- /**
34814
- * Determine if the policy requires an acknowledgement for the envelope.
34815
- */
34816
- isAckRequired(_envelope) {
34817
- return false;
34818
- }
34819
- get senderRetryPolicy() {
34820
- return this.senderPolicy;
34821
- }
34822
- get receiverRetryPolicy() {
34823
- return this.receiverPolicy;
34824
- }
34825
- }
34826
-
34827
- /**
34828
- * Message delivery policy that ensures envelopes are delivered at least once.
34829
- */
34830
- class AtLeastOnceDeliveryPolicy extends DeliveryPolicy {
34831
- constructor(options = {}) {
34832
- super(options);
34833
- }
34834
- isAckRequired(envelope) {
34835
- const frame = envelope?.frame;
34836
- const frameType = typeof frame?.type === 'string' ? frame.type : null;
34837
- if (!frameType) {
34838
- return false;
34839
- }
34840
- return frameType === 'Data' || frameType === 'DataFrame';
34841
- }
34842
- }
34843
-
34844
- /**
34845
- * Configuration and helper for retry backoff behaviour.
34846
- */
34847
- class RetryPolicy {
34848
- constructor(options = {}) {
34849
- this.maxRetries = Math.max(0, Math.trunc(options.maxRetries ?? 0));
34850
- this.baseDelayMs = Math.max(0, Math.trunc(options.baseDelayMs ?? 200));
34851
- this.maxDelayMs = Math.max(this.baseDelayMs, Math.trunc(options.maxDelayMs ?? 10000));
34852
- this.jitterMs = Math.max(0, Math.trunc(options.jitterMs ?? 50));
34853
- this.backoffFactor = Math.max(0, options.backoffFactor ?? 2.0);
34854
- }
34855
- /**
34856
- * Calculate the next retry delay based on attempt number (0-indexed).
34857
- */
34858
- nextDelayMs(attempt) {
34859
- const normalizedAttempt = Number.isFinite(attempt)
34860
- ? Math.max(0, Math.trunc(attempt))
34861
- : 0;
34862
- const base = normalizedAttempt <= 0
34863
- ? this.baseDelayMs
34864
- : Math.round(this.baseDelayMs * this.backoffFactor ** normalizedAttempt);
34865
- const jitter = this.jitterMs > 0
34866
- ? Math.round((Math.random() * 2 - 1) * this.jitterMs)
34867
- : 0;
34868
- const withJitter = base + jitter;
34869
- return Math.min(this.maxDelayMs, Math.max(0, withJitter));
34870
- }
34871
- }
34872
-
34873
- const LEGACY_POLICY_KEYS = {
34874
- senderRetryPolicy: ['sender_retry_policy', 'sender_retryPolicy'],
34875
- receiverRetryPolicy: ['receiver_retry_policy', 'receiver_retryPolicy'],
34876
- };
34877
- class AtLeastOnceDeliveryPolicyFactory extends DeliveryPolicyFactory {
34878
- constructor() {
34879
- super(...arguments);
34880
- this.type = 'AtLeastOnceDeliveryPolicy';
34881
- this.isDefault = true;
34882
- }
34883
- async create(config) {
34884
- const normalized = normalizeAtLeastOnceConfig(config);
34885
- const options = {
34886
- ...(normalized.senderRetryPolicy
34887
- ? { senderRetryPolicy: normalized.senderRetryPolicy }
34888
- : {}),
34889
- ...(normalized.receiverRetryPolicy
34890
- ? { receiverRetryPolicy: normalized.receiverRetryPolicy }
34891
- : {}),
34892
- };
34893
- return new AtLeastOnceDeliveryPolicy(options);
34894
- }
34895
- }
34896
- function normalizeAtLeastOnceConfig(config) {
34897
- if (!config) {
34898
- return {};
34899
- }
34900
- const candidate = config;
34901
- const senderPolicyInput = getRetryPolicyInput(candidate, 'senderRetryPolicy');
34902
- const receiverPolicyInput = getRetryPolicyInput(candidate, 'receiverRetryPolicy');
34903
- return {
34904
- senderRetryPolicy: resolveRetryPolicy(senderPolicyInput),
34905
- receiverRetryPolicy: resolveRetryPolicy(receiverPolicyInput),
34906
- };
34907
- }
34908
- function getRetryPolicyInput(candidate, key) {
34909
- const camelKey = key;
34910
- const primary = candidate[camelKey];
34911
- if (primary !== undefined) {
34912
- return primary;
34913
- }
34914
- const legacyKeys = LEGACY_POLICY_KEYS[key] ?? [];
34915
- for (const legacyKey of legacyKeys) {
34916
- const value = candidate[legacyKey];
34917
- if (value !== undefined) {
34918
- candidate[camelKey] = value;
34919
- return value;
34920
- }
34921
- }
34922
- return undefined;
34923
- }
34924
- function resolveRetryPolicy(input) {
34925
- if (!input) {
34926
- return undefined;
34927
- }
34928
- if (input instanceof RetryPolicy) {
34929
- return input;
34930
- }
34931
- const record = input;
34932
- const options = {
34933
- ...(withOption(record, ['maxRetries', 'max_retries']) ?? {}),
34934
- ...(withOption(record, ['baseDelayMs', 'base_delay_ms']) ?? {}),
34935
- ...(withOption(record, ['maxDelayMs', 'max_delay_ms']) ?? {}),
34936
- ...(withOption(record, ['jitterMs', 'jitter_ms']) ?? {}),
34937
- ...(withOption(record, ['backoffFactor', 'backoff_factor']) ?? {}),
34938
- };
34939
- return new RetryPolicy(options);
34940
- }
34941
- function extractNumber(source, keys) {
34942
- for (const key of keys) {
34943
- if (key in source) {
34944
- const value = source[key];
34945
- if (typeof value === 'number' && Number.isFinite(value)) {
34946
- return value;
34947
- }
34948
- if (typeof value === 'string' && value.trim().length > 0) {
34949
- const parsed = Number(value);
34950
- if (!Number.isNaN(parsed)) {
34951
- return parsed;
34952
- }
34953
- }
34954
- }
34955
- }
34956
- return undefined;
34957
- }
34958
- function withOption(source, keys) {
34959
- const value = extractNumber(source, keys);
34960
- if (value === undefined) {
34961
- return undefined;
34962
- }
34963
- const camelKey = keys[0];
34964
- return {
34965
- [camelKey]: value,
34966
- };
34967
- }
34968
- const FACTORY_META$O = {
34969
- base: DELIVERY_POLICY_FACTORY_BASE_TYPE,
34970
- key: 'AtLeastOnceDeliveryPolicy',
34971
- };
34972
-
34973
- var atLeastOnceDeliveryPolicyFactory = /*#__PURE__*/Object.freeze({
34974
- __proto__: null,
34975
- AtLeastOnceDeliveryPolicyFactory: AtLeastOnceDeliveryPolicyFactory,
34976
- FACTORY_META: FACTORY_META$O,
34977
- default: AtLeastOnceDeliveryPolicyFactory
34978
- });
34979
-
34980
- /**
34981
- * Message delivery policy that ensures envelopes are delivered at most once.
34982
- */
34983
- class AtMostOnceDeliveryPolicy extends DeliveryPolicy {
34984
- constructor() {
34985
- super();
34986
- }
34987
- isAckRequired(_envelope) {
34988
- return false;
34989
- }
34990
- }
34991
-
34992
- class AtMostOnceDeliveryPolicyFactory extends DeliveryPolicyFactory {
34993
- constructor() {
34994
- super(...arguments);
34995
- this.type = 'AtMostOnceDeliveryPolicy';
34996
- }
34997
- async create(_config) {
34998
- return new AtMostOnceDeliveryPolicy();
34999
- }
35000
- }
35001
- registerDeliveryPolicyFactory('AtMostOnceDeliveryPolicy', AtMostOnceDeliveryPolicyFactory);
35002
- registerDeliveryPolicyFactory('AtMostOnceMessageDeliveryPolicy', AtMostOnceDeliveryPolicyFactory);
35003
- const FACTORY_META$N = {
35004
- base: DELIVERY_POLICY_FACTORY_BASE_TYPE,
35005
- key: 'AtMostOnceDeliveryPolicy',
34408
+ base: DELIVERY_POLICY_FACTORY_BASE_TYPE,
34409
+ key: 'AtMostOnceDeliveryPolicy',
35006
34410
  };
35007
34411
 
35008
34412
  var atMostOnceDeliveryPolicyFactory = /*#__PURE__*/Object.freeze({
35009
34413
  __proto__: null,
35010
34414
  AtMostOnceDeliveryPolicyFactory: AtMostOnceDeliveryPolicyFactory,
35011
- FACTORY_META: FACTORY_META$N,
34415
+ FACTORY_META: FACTORY_META$Q,
35012
34416
  default: AtMostOnceDeliveryPolicyFactory
35013
34417
  });
35014
34418
 
35015
- const logger$f = getLogger('naylence.fame.delivery.delivery_profile_factory');
34419
+ const logger$h = getLogger('naylence.fame.delivery.delivery_profile_factory');
35016
34420
  const PROFILE_NAME_AT_LEAST_ONCE = 'at-least-once';
35017
34421
  const PROFILE_NAME_AT_MOST_ONCE = 'at-most-once';
35018
34422
  const ENV_VAR_FAME_DELIVERY_MAX_RETRIES = 'FAME_DELIVERY_MAX_RETRIES';
@@ -35040,7 +34444,7 @@ const AT_LEAST_ONCE_PROFILE = {
35040
34444
  const AT_MOST_ONCE_PROFILE = {
35041
34445
  type: 'AtMostOnceDeliveryPolicy',
35042
34446
  };
35043
- const PROFILE_MAP$2 = {
34447
+ const PROFILE_MAP$3 = {
35044
34448
  [PROFILE_NAME_AT_LEAST_ONCE]: AT_LEAST_ONCE_PROFILE,
35045
34449
  [PROFILE_NAME_AT_MOST_ONCE]: AT_MOST_ONCE_PROFILE,
35046
34450
  };
@@ -35051,8 +34455,8 @@ class DeliveryProfileFactory extends DeliveryPolicyFactory {
35051
34455
  }
35052
34456
  async create(config) {
35053
34457
  const normalized = normalizeDeliveryProfileConfig(config);
35054
- const profileConfig = resolveProfileConfig$1(normalized.profile);
35055
- logger$f.debug('enabling_delivery_profile', { profile: normalized.profile });
34458
+ const profileConfig = resolveProfileConfig$2(normalized.profile);
34459
+ logger$h.debug('enabling_delivery_profile', { profile: normalized.profile });
35056
34460
  const policy = await DeliveryPolicyFactory.createDeliveryPolicy(profileConfig);
35057
34461
  if (!policy) {
35058
34462
  throw new Error(`Failed to create delivery policy for profile: ${normalized.profile}`);
@@ -35065,18 +34469,18 @@ function normalizeDeliveryProfileConfig(config) {
35065
34469
  return { profile: PROFILE_NAME_AT_LEAST_ONCE };
35066
34470
  }
35067
34471
  const candidate = config;
35068
- const profileValue = resolveProfileName(candidate);
34472
+ const profileValue = resolveProfileName$1(candidate);
35069
34473
  candidate.profile = profileValue;
35070
34474
  return { profile: profileValue.toLowerCase() };
35071
34475
  }
35072
- function resolveProfileName(candidate) {
35073
- const value = coerceProfileString(candidate.profile);
34476
+ function resolveProfileName$1(candidate) {
34477
+ const value = coerceProfileString$1(candidate.profile);
35074
34478
  if (value) {
35075
34479
  return value;
35076
34480
  }
35077
34481
  const legacyKeys = ['profile_name', 'profileName'];
35078
34482
  for (const legacyKey of legacyKeys) {
35079
- const legacyValue = coerceProfileString(candidate[legacyKey]);
34483
+ const legacyValue = coerceProfileString$1(candidate[legacyKey]);
35080
34484
  if (legacyValue) {
35081
34485
  candidate.profile = legacyValue;
35082
34486
  return legacyValue;
@@ -35084,24 +34488,24 @@ function resolveProfileName(candidate) {
35084
34488
  }
35085
34489
  return PROFILE_NAME_AT_LEAST_ONCE;
35086
34490
  }
35087
- function coerceProfileString(value) {
34491
+ function coerceProfileString$1(value) {
35088
34492
  if (typeof value !== 'string') {
35089
34493
  return null;
35090
34494
  }
35091
34495
  const trimmed = value.trim();
35092
34496
  return trimmed.length > 0 ? trimmed : null;
35093
34497
  }
35094
- function resolveProfileConfig$1(profileName) {
35095
- const profile = PROFILE_MAP$2[profileName];
34498
+ function resolveProfileConfig$2(profileName) {
34499
+ const profile = PROFILE_MAP$3[profileName];
35096
34500
  if (!profile) {
35097
34501
  throw new Error(`Unknown delivery profile: ${profileName}`);
35098
34502
  }
35099
- return deepClone$1(profile);
34503
+ return deepClone$2(profile);
35100
34504
  }
35101
- function deepClone$1(value) {
34505
+ function deepClone$2(value) {
35102
34506
  return JSON.parse(JSON.stringify(value));
35103
34507
  }
35104
- const FACTORY_META$M = {
34508
+ const FACTORY_META$P = {
35105
34509
  base: DELIVERY_POLICY_FACTORY_BASE_TYPE,
35106
34510
  key: 'DeliveryProfile',
35107
34511
  };
@@ -35109,13 +34513,13 @@ const FACTORY_META$M = {
35109
34513
  var deliveryProfileFactory = /*#__PURE__*/Object.freeze({
35110
34514
  __proto__: null,
35111
34515
  DeliveryProfileFactory: DeliveryProfileFactory,
35112
- FACTORY_META: FACTORY_META$M,
34516
+ FACTORY_META: FACTORY_META$P,
35113
34517
  PROFILE_NAME_AT_LEAST_ONCE: PROFILE_NAME_AT_LEAST_ONCE,
35114
34518
  PROFILE_NAME_AT_MOST_ONCE: PROFILE_NAME_AT_MOST_ONCE,
35115
34519
  default: DeliveryProfileFactory
35116
34520
  });
35117
34521
 
35118
- const logger$e = getLogger('naylence.fame.node.admission.admission_profile_factory');
34522
+ const logger$g = getLogger('naylence.fame.node.admission.admission_profile_factory');
35119
34523
  const ENV_VAR_IS_ROOT = 'FAME_ROOT';
35120
34524
  const ENV_VAR_JWT_AUDIENCE = 'FAME_JWT_AUDIENCE';
35121
34525
  const ENV_VAR_ADMISSION_TOKEN_URL = 'FAME_ADMISSION_TOKEN_URL';
@@ -35139,7 +34543,7 @@ const PROFILE_NAME_DIRECT_HTTP = 'direct-http';
35139
34543
  const PROFILE_NAME_DIRECT_INPAGE = 'direct-inpage';
35140
34544
  const PROFILE_NAME_DIRECT_PKCE = 'direct-pkce';
35141
34545
  const PROFILE_NAME_OPEN = 'open';
35142
- const PROFILE_NAME_NOOP = 'noop';
34546
+ const PROFILE_NAME_NOOP$1 = 'noop';
35143
34547
  const PROFILE_NAME_NONE = 'none';
35144
34548
  const PROFILE_NAME_DIRECT_INPAGE_ALIAS = 'direct_inpage';
35145
34549
  const PROFILE_NAME_DIRECT_PKCE_ALIAS = 'direct_pkce';
@@ -35319,12 +34723,12 @@ const OPEN_PROFILE = {
35319
34723
  },
35320
34724
  ],
35321
34725
  };
35322
- const NOOP_PROFILE = {
34726
+ const NOOP_PROFILE$1 = {
35323
34727
  type: 'NoopAdmissionClient',
35324
34728
  auto_accept_logicals: true,
35325
34729
  autoAcceptLogicals: true,
35326
34730
  };
35327
- const PROFILE_MAP$1 = {
34731
+ const PROFILE_MAP$2 = {
35328
34732
  [PROFILE_NAME_WELCOME]: WELCOME_SERVICE_PROFILE,
35329
34733
  [PROFILE_NAME_WELCOME_PKCE]: WELCOME_SERVICE_PKCE_PROFILE,
35330
34734
  [PROFILE_NAME_WELCOME_PKCE_ALIAS]: WELCOME_SERVICE_PKCE_PROFILE,
@@ -35335,10 +34739,10 @@ const PROFILE_MAP$1 = {
35335
34739
  [PROFILE_NAME_DIRECT_INPAGE]: DIRECT_INPAGE_PROFILE,
35336
34740
  [PROFILE_NAME_DIRECT_INPAGE_ALIAS]: DIRECT_INPAGE_PROFILE,
35337
34741
  [PROFILE_NAME_OPEN]: OPEN_PROFILE,
35338
- [PROFILE_NAME_NOOP]: NOOP_PROFILE,
35339
- [PROFILE_NAME_NONE]: NOOP_PROFILE,
34742
+ [PROFILE_NAME_NOOP$1]: NOOP_PROFILE$1,
34743
+ [PROFILE_NAME_NONE]: NOOP_PROFILE$1,
35340
34744
  };
35341
- const FACTORY_META$L = {
34745
+ const FACTORY_META$O = {
35342
34746
  base: ADMISSION_CLIENT_FACTORY_BASE_TYPE,
35343
34747
  key: 'AdmissionProfile',
35344
34748
  };
@@ -35348,13 +34752,13 @@ class AdmissionProfileFactory extends AdmissionClientFactory {
35348
34752
  this.type = 'AdmissionProfile';
35349
34753
  }
35350
34754
  async create(config) {
35351
- const normalized = normalizeConfig$m(config);
35352
- const profileConfig = resolveProfileConfig(normalized.profile);
35353
- logger$e.debug('enabling_admission_profile', { profile: normalized.profile });
34755
+ const normalized = normalizeConfig$n(config);
34756
+ const profileConfig = resolveProfileConfig$1(normalized.profile);
34757
+ logger$g.debug('enabling_admission_profile', { profile: normalized.profile });
35354
34758
  return AdmissionClientFactory.createAdmissionClient(profileConfig);
35355
34759
  }
35356
34760
  }
35357
- function normalizeConfig$m(config) {
34761
+ function normalizeConfig$n(config) {
35358
34762
  if (!config) {
35359
34763
  return { profile: PROFILE_NAME_DIRECT };
35360
34764
  }
@@ -35371,25 +34775,25 @@ function normalizeConfig$m(config) {
35371
34775
  const normalizedProfile = profileValue.trim().toLowerCase();
35372
34776
  return { profile: normalizedProfile };
35373
34777
  }
35374
- function resolveProfileConfig(profileName) {
35375
- const profile = PROFILE_MAP$1[profileName];
34778
+ function resolveProfileConfig$1(profileName) {
34779
+ const profile = PROFILE_MAP$2[profileName];
35376
34780
  if (!profile) {
35377
34781
  throw new Error(`Unknown admission profile: ${profileName}`);
35378
34782
  }
35379
- return deepClone(profile);
34783
+ return deepClone$1(profile);
35380
34784
  }
35381
- function deepClone(value) {
34785
+ function deepClone$1(value) {
35382
34786
  return JSON.parse(JSON.stringify(value));
35383
34787
  }
35384
34788
 
35385
34789
  var admissionProfileFactory = /*#__PURE__*/Object.freeze({
35386
34790
  __proto__: null,
35387
34791
  AdmissionProfileFactory: AdmissionProfileFactory,
35388
- FACTORY_META: FACTORY_META$L,
34792
+ FACTORY_META: FACTORY_META$O,
35389
34793
  default: AdmissionProfileFactory
35390
34794
  });
35391
34795
 
35392
- const logger$d = getLogger('naylence.fame.node.admission.direct_admission_client');
34796
+ const logger$f = getLogger('naylence.fame.node.admission.direct_admission_client');
35393
34797
  class DirectAdmissionClient {
35394
34798
  constructor(options) {
35395
34799
  this.hasUpstream = true;
@@ -35414,7 +34818,7 @@ class DirectAdmissionClient {
35414
34818
  }
35415
34819
  }
35416
34820
  async hello(systemId, instanceId, requestedLogicals) {
35417
- logger$d.debug('direct_admission_hello_start', {
34821
+ logger$f.debug('direct_admission_hello_start', {
35418
34822
  providedSystemId: systemId,
35419
34823
  instanceId,
35420
34824
  requestedLogicals,
@@ -35422,7 +34826,7 @@ class DirectAdmissionClient {
35422
34826
  const effectiveSystemId = systemId && systemId.trim().length > 0
35423
34827
  ? systemId
35424
34828
  : await generateIdAsync({ mode: 'fingerprint' }).catch(async () => {
35425
- logger$d.debug('direct_admission_fingerprint_generation_failed', {
34829
+ logger$f.debug('direct_admission_fingerprint_generation_failed', {
35426
34830
  reason: 'falling back to random id',
35427
34831
  });
35428
34832
  return generateIdAsync({ mode: 'random' });
@@ -35444,7 +34848,7 @@ class DirectAdmissionClient {
35444
34848
  const envelope = createFameEnvelope({
35445
34849
  frame: welcomeFrame,
35446
34850
  });
35447
- logger$d.debug('direct_admission_hello_success', {
34851
+ logger$f.debug('direct_admission_hello_success', {
35448
34852
  systemId: welcomeFrame.systemId,
35449
34853
  instanceId: welcomeFrame.instanceId,
35450
34854
  acceptedLogicals: welcomeFrame.acceptedLogicals,
@@ -35467,7 +34871,7 @@ function cloneGrant(grant) {
35467
34871
  return JSON.parse(JSON.stringify(grant));
35468
34872
  }
35469
34873
 
35470
- const FACTORY_META$K = {
34874
+ const FACTORY_META$N = {
35471
34875
  base: ADMISSION_CLIENT_FACTORY_BASE_TYPE,
35472
34876
  key: 'DirectAdmissionClient',
35473
34877
  };
@@ -35480,7 +34884,7 @@ class DirectAdmissionClientFactory extends AdmissionClientFactory {
35480
34884
  if (!config) {
35481
34885
  throw new Error('DirectAdmissionClient configuration is required');
35482
34886
  }
35483
- const normalized = normalizeConfig$l(config);
34887
+ const normalized = normalizeConfig$m(config);
35484
34888
  const evaluatedGrants = normalized.connectionGrants.map((grant) => {
35485
34889
  const evaluated = ConnectorFactory.evaluateGrant({
35486
34890
  ...grant,
@@ -35493,7 +34897,7 @@ class DirectAdmissionClientFactory extends AdmissionClientFactory {
35493
34897
  });
35494
34898
  }
35495
34899
  }
35496
- function normalizeConfig$l(config) {
34900
+ function normalizeConfig$m(config) {
35497
34901
  const source = config;
35498
34902
  const connectionGrantsRaw = source.connectionGrants ?? source.connection_grants;
35499
34903
  if (!Array.isArray(connectionGrantsRaw) || connectionGrantsRaw.length === 0) {
@@ -35519,11 +34923,11 @@ function normalizeConfig$l(config) {
35519
34923
  var directAdmissionClientFactory = /*#__PURE__*/Object.freeze({
35520
34924
  __proto__: null,
35521
34925
  DirectAdmissionClientFactory: DirectAdmissionClientFactory,
35522
- FACTORY_META: FACTORY_META$K,
34926
+ FACTORY_META: FACTORY_META$N,
35523
34927
  default: DirectAdmissionClientFactory
35524
34928
  });
35525
34929
 
35526
- const FACTORY_META$J = {
34930
+ const FACTORY_META$M = {
35527
34931
  base: ADMISSION_CLIENT_FACTORY_BASE_TYPE,
35528
34932
  key: 'NoopAdmissionClient',
35529
34933
  };
@@ -35535,11 +34939,11 @@ class NoopAdmissionClientFactory extends AdmissionClientFactory {
35535
34939
  this.priority = 0;
35536
34940
  }
35537
34941
  async create(config, ...factoryArgs) {
35538
- const resolved = normalizeConfig$k(config, factoryArgs);
34942
+ const resolved = normalizeConfig$l(config, factoryArgs);
35539
34943
  return new NoopAdmissionClient(resolved);
35540
34944
  }
35541
34945
  }
35542
- function normalizeConfig$k(config, factoryArgs) {
34946
+ function normalizeConfig$l(config, factoryArgs) {
35543
34947
  const fromArgs = factoryArgs[0] && typeof factoryArgs[0] === 'object'
35544
34948
  ? factoryArgs[0]
35545
34949
  : {};
@@ -35572,7 +34976,7 @@ function normalizeConfig$k(config, factoryArgs) {
35572
34976
 
35573
34977
  var noopAdmissionClientFactory = /*#__PURE__*/Object.freeze({
35574
34978
  __proto__: null,
35575
- FACTORY_META: FACTORY_META$J,
34979
+ FACTORY_META: FACTORY_META$M,
35576
34980
  NoopAdmissionClientFactory: NoopAdmissionClientFactory,
35577
34981
  default: NoopAdmissionClientFactory
35578
34982
  });
@@ -35587,7 +34991,7 @@ class NoAuthInjectionStrategy {
35587
34991
  }
35588
34992
  }
35589
34993
 
35590
- const FACTORY_META$I = {
34994
+ const FACTORY_META$L = {
35591
34995
  base: AUTH_INJECTION_STRATEGY_FACTORY_BASE_TYPE,
35592
34996
  key: 'NoAuth',
35593
34997
  };
@@ -35597,11 +35001,11 @@ class NoAuthInjectionStrategyFactory extends AuthInjectionStrategyFactory {
35597
35001
  this.type = 'NoAuth';
35598
35002
  }
35599
35003
  async create(config) {
35600
- const preparedConfig = normalizeConfig$j(config);
35004
+ const preparedConfig = normalizeConfig$k(config);
35601
35005
  return new NoAuthInjectionStrategy(preparedConfig);
35602
35006
  }
35603
35007
  }
35604
- function normalizeConfig$j(config) {
35008
+ function normalizeConfig$k(config) {
35605
35009
  const defaultConfig = { type: 'NoAuth' };
35606
35010
  if (!config) {
35607
35011
  return defaultConfig;
@@ -35616,12 +35020,12 @@ function normalizeConfig$j(config) {
35616
35020
 
35617
35021
  var noAuthInjectionStrategyFactory = /*#__PURE__*/Object.freeze({
35618
35022
  __proto__: null,
35619
- FACTORY_META: FACTORY_META$I,
35023
+ FACTORY_META: FACTORY_META$L,
35620
35024
  NoAuthInjectionStrategyFactory: NoAuthInjectionStrategyFactory,
35621
35025
  default: NoAuthInjectionStrategyFactory
35622
35026
  });
35623
35027
 
35624
- const logger$c = getLogger('naylence.fame.node.admission.welcome_service_client');
35028
+ const logger$e = getLogger('naylence.fame.node.admission.welcome_service_client');
35625
35029
  class WelcomeServiceClient {
35626
35030
  constructor(options) {
35627
35031
  this.hasUpstream = options.hasUpstream ?? options.has_upstream ?? false;
@@ -35670,7 +35074,7 @@ class WelcomeServiceClient {
35670
35074
  'Content-Type': 'application/json',
35671
35075
  ...authHeaders,
35672
35076
  };
35673
- logger$c.debug('welcome_service_hello_request', {
35077
+ logger$e.debug('welcome_service_hello_request', {
35674
35078
  url: this.url,
35675
35079
  systemId,
35676
35080
  instanceId,
@@ -35706,7 +35110,7 @@ class WelcomeServiceClient {
35706
35110
  parsedEnvelope.frame.type !== 'NodeWelcome') {
35707
35111
  throw new Error(`Unexpected frame type '${parsedEnvelope.frame?.type ?? 'unknown'}'`);
35708
35112
  }
35709
- logger$c.debug('welcome_service_hello_success', {
35113
+ logger$e.debug('welcome_service_hello_success', {
35710
35114
  systemId: parsedEnvelope.frame.systemId,
35711
35115
  targetSystemId: parsedEnvelope.frame.targetSystemId,
35712
35116
  assignedPath: parsedEnvelope.frame.assignedPath,
@@ -35765,7 +35169,7 @@ function convertKeysToCamelCase(value) {
35765
35169
  return result;
35766
35170
  }
35767
35171
 
35768
- const FACTORY_META$H = {
35172
+ const FACTORY_META$K = {
35769
35173
  base: ADMISSION_CLIENT_FACTORY_BASE_TYPE,
35770
35174
  key: 'WelcomeServiceClient',
35771
35175
  };
@@ -35778,7 +35182,7 @@ class WelcomeServiceClientFactory extends AdmissionClientFactory {
35778
35182
  if (!config) {
35779
35183
  throw new Error('WelcomeServiceClient configuration is required');
35780
35184
  }
35781
- const normalized = normalizeConfig$i(config);
35185
+ const normalized = normalizeConfig$j(config);
35782
35186
  const clientOptions = {
35783
35187
  hasUpstream: !normalized.isRoot,
35784
35188
  url: normalized.url,
@@ -35793,7 +35197,7 @@ class WelcomeServiceClientFactory extends AdmissionClientFactory {
35793
35197
  return new WelcomeServiceClient(clientOptions);
35794
35198
  }
35795
35199
  }
35796
- function normalizeConfig$i(config) {
35200
+ function normalizeConfig$j(config) {
35797
35201
  const source = config;
35798
35202
  const urlCandidate = typeof source.url === 'string' ? source.url.trim() : '';
35799
35203
  if (!urlCandidate) {
@@ -35835,7 +35239,7 @@ async function createAuthStrategy(config) {
35835
35239
 
35836
35240
  var welcomeServiceClientFactory = /*#__PURE__*/Object.freeze({
35837
35241
  __proto__: null,
35838
- FACTORY_META: FACTORY_META$H,
35242
+ FACTORY_META: FACTORY_META$K,
35839
35243
  WelcomeServiceClientFactory: WelcomeServiceClientFactory,
35840
35244
  default: WelcomeServiceClientFactory
35841
35245
  });
@@ -35911,7 +35315,7 @@ const staticNodePlacementConfigSchema = z
35911
35315
  .min(1, { message: 'targetPhysicalPath cannot be empty' }),
35912
35316
  })
35913
35317
  .passthrough();
35914
- function normalizeConfig$h(config) {
35318
+ function normalizeConfig$i(config) {
35915
35319
  const candidate = {
35916
35320
  ...config,
35917
35321
  };
@@ -35946,14 +35350,14 @@ class StaticNodePlacementStrategyFactory extends NodePlacementStrategyFactory {
35946
35350
  if (!config) {
35947
35351
  throw new Error('StaticNodePlacementStrategy requires configuration');
35948
35352
  }
35949
- const normalized = normalizeConfig$h(config);
35353
+ const normalized = normalizeConfig$i(config);
35950
35354
  return new StaticNodePlacementStrategy({
35951
35355
  targetSystemId: normalized.targetSystemId,
35952
35356
  targetPhysicalPath: normalized.targetPhysicalPath,
35953
35357
  });
35954
35358
  }
35955
35359
  }
35956
- const FACTORY_META$G = {
35360
+ const FACTORY_META$J = {
35957
35361
  base: NODE_PLACEMENT_STRATEGY_FACTORY_BASE_TYPE,
35958
35362
  key: 'StaticNodePlacementStrategy',
35959
35363
  };
@@ -35963,7 +35367,7 @@ registerNodePlacementStrategyFactory('StaticNodePlacementStrategy', StaticNodePl
35963
35367
 
35964
35368
  var staticNodePlacementStrategyFactory = /*#__PURE__*/Object.freeze({
35965
35369
  __proto__: null,
35966
- FACTORY_META: FACTORY_META$G,
35370
+ FACTORY_META: FACTORY_META$J,
35967
35371
  StaticNodePlacementStrategyFactory: StaticNodePlacementStrategyFactory,
35968
35372
  default: StaticNodePlacementStrategyFactory
35969
35373
  });
@@ -36122,7 +35526,7 @@ function connectorTypeName(connector) {
36122
35526
  return typeof connector;
36123
35527
  }
36124
35528
 
36125
- const FACTORY_META$F = {
35529
+ const FACTORY_META$I = {
36126
35530
  base: AUTH_INJECTION_STRATEGY_FACTORY_BASE_TYPE,
36127
35531
  key: 'BearerTokenHeaderAuth',
36128
35532
  };
@@ -36132,11 +35536,11 @@ class BearerTokenHeaderAuthInjectionStrategyFactory extends AuthInjectionStrateg
36132
35536
  this.type = 'BearerTokenHeaderAuth';
36133
35537
  }
36134
35538
  async create(config) {
36135
- const normalized = normalizeConfig$g(config);
35539
+ const normalized = normalizeConfig$h(config);
36136
35540
  return new BearerTokenHeaderAuthInjectionStrategy(normalized);
36137
35541
  }
36138
35542
  }
36139
- function normalizeConfig$g(config) {
35543
+ function normalizeConfig$h(config) {
36140
35544
  if (!config) {
36141
35545
  throw new Error('BearerTokenHeaderAuthInjectionStrategy requires configuration');
36142
35546
  }
@@ -36163,7 +35567,7 @@ function normalizeConfig$g(config) {
36163
35567
  var bearerTokenHeaderAuthInjectionStrategyFactory = /*#__PURE__*/Object.freeze({
36164
35568
  __proto__: null,
36165
35569
  BearerTokenHeaderAuthInjectionStrategyFactory: BearerTokenHeaderAuthInjectionStrategyFactory,
36166
- FACTORY_META: FACTORY_META$F,
35570
+ FACTORY_META: FACTORY_META$I,
36167
35571
  default: BearerTokenHeaderAuthInjectionStrategyFactory
36168
35572
  });
36169
35573
 
@@ -36174,7 +35578,7 @@ async function getDefaultAuthorizerModule() {
36174
35578
  }
36175
35579
  return defaultAuthorizerModulePromise;
36176
35580
  }
36177
- function normalizeConfig$f(config) {
35581
+ function normalizeConfig$g(config) {
36178
35582
  if (!config) {
36179
35583
  return {};
36180
35584
  }
@@ -36190,7 +35594,7 @@ function normalizeConfig$f(config) {
36190
35594
  function isTokenVerifier(candidate) {
36191
35595
  return Boolean(candidate && typeof candidate.verify === 'function');
36192
35596
  }
36193
- const FACTORY_META$E = {
35597
+ const FACTORY_META$H = {
36194
35598
  base: AUTHORIZER_FACTORY_BASE_TYPE,
36195
35599
  key: 'DefaultAuthorizer',
36196
35600
  };
@@ -36202,7 +35606,7 @@ class DefaultAuthorizerFactory extends AuthorizerFactory {
36202
35606
  }
36203
35607
  async create(config, ...factoryArgs) {
36204
35608
  let tokenVerifier = factoryArgs.find(isTokenVerifier);
36205
- const normalized = normalizeConfig$f(config);
35609
+ const normalized = normalizeConfig$g(config);
36206
35610
  if (!tokenVerifier) {
36207
35611
  if (!normalized.verifier) {
36208
35612
  throw new Error('DefaultAuthorizer requires a verifier configuration or instance');
@@ -36220,7 +35624,7 @@ class DefaultAuthorizerFactory extends AuthorizerFactory {
36220
35624
  var defaultAuthorizerFactory = /*#__PURE__*/Object.freeze({
36221
35625
  __proto__: null,
36222
35626
  DefaultAuthorizerFactory: DefaultAuthorizerFactory,
36223
- FACTORY_META: FACTORY_META$E,
35627
+ FACTORY_META: FACTORY_META$H,
36224
35628
  default: DefaultAuthorizerFactory
36225
35629
  });
36226
35630
 
@@ -36231,7 +35635,7 @@ function getJwksJwtTokenVerifierModule() {
36231
35635
  }
36232
35636
  return jwksJwtTokenVerifierModulePromise;
36233
35637
  }
36234
- const FACTORY_META$D = {
35638
+ const FACTORY_META$G = {
36235
35639
  base: TOKEN_VERIFIER_FACTORY_BASE_TYPE,
36236
35640
  key: 'JWKSJWTTokenVerifier',
36237
35641
  };
@@ -36244,7 +35648,7 @@ class JWKSTokenVerifierFactory extends TokenVerifierFactory {
36244
35648
  if (!config) {
36245
35649
  throw new Error('JWKSJWTTokenVerifier requires configuration');
36246
35650
  }
36247
- const normalized = normalizeConfig$e(config);
35651
+ const normalized = normalizeConfig$f(config);
36248
35652
  const cacheTtlCandidate = validateCacheTtlSec(normalized.cacheTtlSec);
36249
35653
  const cacheTtlSec = typeof cacheTtlCandidate === 'number'
36250
35654
  ? cacheTtlCandidate
@@ -36258,7 +35662,7 @@ class JWKSTokenVerifierFactory extends TokenVerifierFactory {
36258
35662
  });
36259
35663
  }
36260
35664
  }
36261
- function normalizeConfig$e(config) {
35665
+ function normalizeConfig$f(config) {
36262
35666
  const source = config;
36263
35667
  const issuer = typeof source.issuer === 'string' && source.issuer.trim().length > 0
36264
35668
  ? source.issuer
@@ -36293,12 +35697,12 @@ function normalizeConfig$e(config) {
36293
35697
 
36294
35698
  var jwksJwtTokenVerifierFactory = /*#__PURE__*/Object.freeze({
36295
35699
  __proto__: null,
36296
- FACTORY_META: FACTORY_META$D,
35700
+ FACTORY_META: FACTORY_META$G,
36297
35701
  JWKSTokenVerifierFactory: JWKSTokenVerifierFactory,
36298
35702
  default: JWKSTokenVerifierFactory
36299
35703
  });
36300
35704
 
36301
- const FACTORY_META$C = {
35705
+ const FACTORY_META$F = {
36302
35706
  base: TOKEN_ISSUER_FACTORY_BASE_TYPE,
36303
35707
  key: 'JWTTokenIssuer',
36304
35708
  };
@@ -36312,7 +35716,7 @@ class JWTTokenIssuerFactory extends TokenIssuerFactory {
36312
35716
  if (!config) {
36313
35717
  throw new Error('JWTTokenIssuerFactory requires configuration');
36314
35718
  }
36315
- const normalized = normalizeConfig$d(config);
35719
+ const normalized = normalizeConfig$e(config);
36316
35720
  // Extract crypto provider from factory args
36317
35721
  let cryptoProvider1 = null;
36318
35722
  for (const arg of factoryArgs) {
@@ -36369,7 +35773,7 @@ function getJwtTokenIssuerModule() {
36369
35773
  }
36370
35774
  return jwtTokenIssuerModulePromise;
36371
35775
  }
36372
- function normalizeConfig$d(config) {
35776
+ function normalizeConfig$e(config) {
36373
35777
  const source = config;
36374
35778
  const issuer = typeof source.issuer === 'string' && source.issuer.trim() !== ''
36375
35779
  ? source.issuer
@@ -36495,12 +35899,12 @@ function getProviderKeyId(provider) {
36495
35899
 
36496
35900
  var jwtTokenIssuerFactory = /*#__PURE__*/Object.freeze({
36497
35901
  __proto__: null,
36498
- FACTORY_META: FACTORY_META$C,
35902
+ FACTORY_META: FACTORY_META$F,
36499
35903
  JWTTokenIssuerFactory: JWTTokenIssuerFactory,
36500
35904
  default: JWTTokenIssuerFactory
36501
35905
  });
36502
35906
 
36503
- const FACTORY_META$B = {
35907
+ const FACTORY_META$E = {
36504
35908
  base: TOKEN_VERIFIER_FACTORY_BASE_TYPE,
36505
35909
  key: 'JWTTokenVerifier',
36506
35910
  };
@@ -36514,7 +35918,7 @@ class JWTTokenVerifierFactory extends TokenVerifierFactory {
36514
35918
  if (!config) {
36515
35919
  throw new Error('JWTTokenVerifierFactory requires configuration');
36516
35920
  }
36517
- const normalized = normalizeConfig$c(config);
35921
+ const normalized = normalizeConfig$d(config);
36518
35922
  const cryptoProvider1 = cryptoProvider ?? null;
36519
35923
  let verificationKey;
36520
35924
  if (normalized.hmacSecret !== undefined) {
@@ -36551,7 +35955,7 @@ function getJwtTokenVerifierModule() {
36551
35955
  }
36552
35956
  return jwtTokenVerifierModulePromise;
36553
35957
  }
36554
- function normalizeConfig$c(config) {
35958
+ function normalizeConfig$d(config) {
36555
35959
  const source = config;
36556
35960
  const issuer = typeof source.issuer === 'string' && source.issuer.trim() !== ''
36557
35961
  ? source.issuer
@@ -36668,7 +36072,7 @@ function getProviderVerificationKey(provider) {
36668
36072
 
36669
36073
  var jwtTokenVerifierFactory = /*#__PURE__*/Object.freeze({
36670
36074
  __proto__: null,
36671
- FACTORY_META: FACTORY_META$B,
36075
+ FACTORY_META: FACTORY_META$E,
36672
36076
  JWTTokenVerifierFactory: JWTTokenVerifierFactory,
36673
36077
  default: JWTTokenVerifierFactory
36674
36078
  });
@@ -36684,7 +36088,7 @@ class NoneTokenProvider {
36684
36088
  }
36685
36089
  }
36686
36090
 
36687
- const FACTORY_META$A = {
36091
+ const FACTORY_META$D = {
36688
36092
  base: TOKEN_PROVIDER_FACTORY_BASE_TYPE,
36689
36093
  key: 'NoneTokenProvider',
36690
36094
  };
@@ -36701,7 +36105,7 @@ class NoneTokenProviderFactory extends TokenProviderFactory {
36701
36105
 
36702
36106
  var noneTokenProviderFactory = /*#__PURE__*/Object.freeze({
36703
36107
  __proto__: null,
36704
- FACTORY_META: FACTORY_META$A,
36108
+ FACTORY_META: FACTORY_META$D,
36705
36109
  NoneTokenProviderFactory: NoneTokenProviderFactory,
36706
36110
  default: NoneTokenProviderFactory
36707
36111
  });
@@ -36753,7 +36157,7 @@ class NoopAuthorizer {
36753
36157
  }
36754
36158
  }
36755
36159
 
36756
- const FACTORY_META$z = {
36160
+ const FACTORY_META$C = {
36757
36161
  base: AUTHORIZER_FACTORY_BASE_TYPE,
36758
36162
  key: 'NoopAuthorizer',
36759
36163
  };
@@ -36769,7 +36173,7 @@ class NoopAuthorizerFactory extends AuthorizerFactory {
36769
36173
 
36770
36174
  var noopAuthorizerFactory = /*#__PURE__*/Object.freeze({
36771
36175
  __proto__: null,
36772
- FACTORY_META: FACTORY_META$z,
36176
+ FACTORY_META: FACTORY_META$C,
36773
36177
  NoopAuthorizerFactory: NoopAuthorizerFactory,
36774
36178
  default: NoopAuthorizerFactory
36775
36179
  });
@@ -36783,7 +36187,7 @@ class NoopTokenIssuer {
36783
36187
  }
36784
36188
  }
36785
36189
 
36786
- const FACTORY_META$y = {
36190
+ const FACTORY_META$B = {
36787
36191
  base: TOKEN_ISSUER_FACTORY_BASE_TYPE,
36788
36192
  key: 'NoopTokenIssuer',
36789
36193
  };
@@ -36799,7 +36203,7 @@ class NoopTokenIssuerFactory extends TokenIssuerFactory {
36799
36203
 
36800
36204
  var noopTokenIssuerFactory = /*#__PURE__*/Object.freeze({
36801
36205
  __proto__: null,
36802
- FACTORY_META: FACTORY_META$y,
36206
+ FACTORY_META: FACTORY_META$B,
36803
36207
  NoopTokenIssuerFactory: NoopTokenIssuerFactory,
36804
36208
  default: NoopTokenIssuerFactory
36805
36209
  });
@@ -36821,7 +36225,7 @@ class NoopTokenVerifier {
36821
36225
  }
36822
36226
  }
36823
36227
 
36824
- const FACTORY_META$x = {
36228
+ const FACTORY_META$A = {
36825
36229
  base: TOKEN_VERIFIER_FACTORY_BASE_TYPE,
36826
36230
  key: 'NoopTokenVerifier',
36827
36231
  };
@@ -36837,12 +36241,12 @@ class NoopTokenVerifierFactory extends TokenVerifierFactory {
36837
36241
 
36838
36242
  var noopTokenVerifierFactory = /*#__PURE__*/Object.freeze({
36839
36243
  __proto__: null,
36840
- FACTORY_META: FACTORY_META$x,
36244
+ FACTORY_META: FACTORY_META$A,
36841
36245
  NoopTokenVerifierFactory: NoopTokenVerifierFactory,
36842
36246
  default: NoopTokenVerifierFactory
36843
36247
  });
36844
36248
 
36845
- const logger$b = getLogger('naylence.fame.security.auth.oauth2_authorizer_factory');
36249
+ const logger$d = getLogger('naylence.fame.security.auth.oauth2_authorizer_factory');
36846
36250
  let oauth2AuthorizerModulePromise = null;
36847
36251
  function getOAuth2AuthorizerModule() {
36848
36252
  if (!oauth2AuthorizerModulePromise) {
@@ -36850,7 +36254,7 @@ function getOAuth2AuthorizerModule() {
36850
36254
  }
36851
36255
  return oauth2AuthorizerModulePromise;
36852
36256
  }
36853
- const FACTORY_META$w = {
36257
+ const FACTORY_META$z = {
36854
36258
  base: AUTHORIZER_FACTORY_BASE_TYPE,
36855
36259
  key: 'OAuth2Authorizer',
36856
36260
  };
@@ -36863,18 +36267,18 @@ class OAuth2AuthorizerFactory extends AuthorizerFactory {
36863
36267
  if (!config) {
36864
36268
  throw new Error('OAuth2Authorizer requires configuration');
36865
36269
  }
36866
- const normalized = normalizeConfig$b(config);
36270
+ const normalized = normalizeConfig$c(config);
36867
36271
  const tokenVerifier = await TokenVerifierFactory.createTokenVerifier(normalized.tokenVerifierConfig);
36868
36272
  let tokenIssuer;
36869
36273
  if (normalized.tokenIssuerConfig) {
36870
36274
  try {
36871
36275
  tokenIssuer = await TokenIssuerFactory.createTokenIssuer(normalized.tokenIssuerConfig);
36872
- logger$b.debug('token_issuer_created_for_reverse_auth', {
36276
+ logger$d.debug('token_issuer_created_for_reverse_auth', {
36873
36277
  issuer_type: normalized.tokenIssuerConfig.type,
36874
36278
  });
36875
36279
  }
36876
36280
  catch (error) {
36877
- logger$b.warning('failed_to_create_token_issuer_for_reverse_auth', {
36281
+ logger$d.warning('failed_to_create_token_issuer_for_reverse_auth', {
36878
36282
  error: error instanceof Error ? error.message : String(error),
36879
36283
  issuer_config: normalized.tokenIssuerConfig,
36880
36284
  });
@@ -36898,7 +36302,7 @@ class OAuth2AuthorizerFactory extends AuthorizerFactory {
36898
36302
  return new OAuth2Authorizer(authorizerOptions);
36899
36303
  }
36900
36304
  }
36901
- function normalizeConfig$b(config) {
36305
+ function normalizeConfig$c(config) {
36902
36306
  const source = config;
36903
36307
  const issuer = typeof source.issuer === 'string' && source.issuer.trim().length > 0
36904
36308
  ? source.issuer.trim()
@@ -36995,7 +36399,7 @@ function normalizeTokenVerifierConfig({ config, issuer, jwksUrl, algorithm, }) {
36995
36399
 
36996
36400
  var oauth2AuthorizerFactory = /*#__PURE__*/Object.freeze({
36997
36401
  __proto__: null,
36998
- FACTORY_META: FACTORY_META$w,
36402
+ FACTORY_META: FACTORY_META$z,
36999
36403
  OAuth2AuthorizerFactory: OAuth2AuthorizerFactory,
37000
36404
  default: OAuth2AuthorizerFactory
37001
36405
  });
@@ -37007,7 +36411,7 @@ async function getOAuth2ClientCredentialsTokenProviderModule() {
37007
36411
  }
37008
36412
  return oauth2ClientCredentialsTokenProviderModulePromise;
37009
36413
  }
37010
- function normalizeConfig$a(config) {
36414
+ function normalizeConfig$b(config) {
37011
36415
  if (!config) {
37012
36416
  throw new Error('OAuth2ClientCredentialsTokenProvider requires configuration');
37013
36417
  }
@@ -37035,7 +36439,7 @@ function normalizeConfig$a(config) {
37035
36439
  }
37036
36440
  return normalized;
37037
36441
  }
37038
- const FACTORY_META$v = {
36442
+ const FACTORY_META$y = {
37039
36443
  base: TOKEN_PROVIDER_FACTORY_BASE_TYPE,
37040
36444
  key: 'OAuth2ClientCredentialsTokenProvider',
37041
36445
  };
@@ -37045,7 +36449,7 @@ class OAuth2ClientCredentialsTokenProviderFactory extends TokenProviderFactory {
37045
36449
  this.type = 'OAuth2ClientCredentialsTokenProvider';
37046
36450
  }
37047
36451
  async create(config) {
37048
- const normalized = normalizeConfig$a(config);
36452
+ const normalized = normalizeConfig$b(config);
37049
36453
  const [clientIdProvider, clientSecretProvider] = await Promise.all([
37050
36454
  CredentialProviderFactory.createCredentialProvider(normalized.clientIdConfig),
37051
36455
  CredentialProviderFactory.createCredentialProvider(normalized.clientSecretConfig),
@@ -37066,7 +36470,7 @@ class OAuth2ClientCredentialsTokenProviderFactory extends TokenProviderFactory {
37066
36470
 
37067
36471
  var oauth2ClientCredentialsTokenProviderFactory = /*#__PURE__*/Object.freeze({
37068
36472
  __proto__: null,
37069
- FACTORY_META: FACTORY_META$v,
36473
+ FACTORY_META: FACTORY_META$y,
37070
36474
  OAuth2ClientCredentialsTokenProviderFactory: OAuth2ClientCredentialsTokenProviderFactory,
37071
36475
  default: OAuth2ClientCredentialsTokenProviderFactory
37072
36476
  });
@@ -37099,7 +36503,7 @@ function normalizeScopes$1(value) {
37099
36503
  }
37100
36504
  return [];
37101
36505
  }
37102
- function normalizeConfig$9(config) {
36506
+ function normalizeConfig$a(config) {
37103
36507
  if (!config) {
37104
36508
  throw new Error('OAuth2PkceTokenProvider requires configuration');
37105
36509
  }
@@ -37148,7 +36552,7 @@ function normalizeConfig$9(config) {
37148
36552
  }
37149
36553
  return normalized;
37150
36554
  }
37151
- const FACTORY_META$u = {
36555
+ const FACTORY_META$x = {
37152
36556
  base: TOKEN_PROVIDER_FACTORY_BASE_TYPE,
37153
36557
  key: 'OAuth2PkceTokenProvider',
37154
36558
  };
@@ -37158,7 +36562,7 @@ class OAuth2PkceTokenProviderFactory extends TokenProviderFactory {
37158
36562
  this.type = 'OAuth2PkceTokenProvider';
37159
36563
  }
37160
36564
  async create(config) {
37161
- const normalized = normalizeConfig$9(config);
36565
+ const normalized = normalizeConfig$a(config);
37162
36566
  const [usernameProvider, clientSecretProvider] = await Promise.all([
37163
36567
  normalized.usernameConfig
37164
36568
  ? CredentialProviderFactory.createCredentialProvider(normalized.usernameConfig)
@@ -37203,7 +36607,7 @@ class OAuth2PkceTokenProviderFactory extends TokenProviderFactory {
37203
36607
 
37204
36608
  var oauth2PkceTokenProviderFactory = /*#__PURE__*/Object.freeze({
37205
36609
  __proto__: null,
37206
- FACTORY_META: FACTORY_META$u,
36610
+ FACTORY_META: FACTORY_META$x,
37207
36611
  OAuth2PkceTokenProviderFactory: OAuth2PkceTokenProviderFactory,
37208
36612
  default: OAuth2PkceTokenProviderFactory
37209
36613
  });
@@ -37253,7 +36657,7 @@ class QueryParamAuthInjectionStrategy {
37253
36657
  }
37254
36658
  }
37255
36659
 
37256
- const FACTORY_META$t = {
36660
+ const FACTORY_META$w = {
37257
36661
  base: AUTH_INJECTION_STRATEGY_FACTORY_BASE_TYPE,
37258
36662
  key: 'QueryParamAuth',
37259
36663
  };
@@ -37263,11 +36667,11 @@ class QueryParamAuthInjectionStrategyFactory extends AuthInjectionStrategyFactor
37263
36667
  this.type = 'QueryParamAuth';
37264
36668
  }
37265
36669
  async create(config) {
37266
- const normalized = normalizeConfig$8(config);
36670
+ const normalized = normalizeConfig$9(config);
37267
36671
  return new QueryParamAuthInjectionStrategy(normalized);
37268
36672
  }
37269
36673
  }
37270
- function normalizeConfig$8(config) {
36674
+ function normalizeConfig$9(config) {
37271
36675
  if (!config) {
37272
36676
  throw new Error('QueryParamAuthInjectionStrategy requires configuration');
37273
36677
  }
@@ -37293,7 +36697,7 @@ function normalizeConfig$8(config) {
37293
36697
 
37294
36698
  var queryParamAuthInjectionStrategyFactory = /*#__PURE__*/Object.freeze({
37295
36699
  __proto__: null,
37296
- FACTORY_META: FACTORY_META$t,
36700
+ FACTORY_META: FACTORY_META$w,
37297
36701
  QueryParamAuthInjectionStrategyFactory: QueryParamAuthInjectionStrategyFactory,
37298
36702
  default: QueryParamAuthInjectionStrategyFactory
37299
36703
  });
@@ -37305,7 +36709,7 @@ async function getSharedSecretAuthorizerModule() {
37305
36709
  }
37306
36710
  return sharedSecretAuthorizerModulePromise;
37307
36711
  }
37308
- function normalizeConfig$7(config) {
36712
+ function normalizeConfig$8(config) {
37309
36713
  if (!config) {
37310
36714
  throw new Error('SharedSecretAuthorizer requires configuration');
37311
36715
  }
@@ -37329,7 +36733,7 @@ function normalizeConfig$7(config) {
37329
36733
  secretConfig: normalizeSecretSource(secretSource),
37330
36734
  };
37331
36735
  }
37332
- const FACTORY_META$s = {
36736
+ const FACTORY_META$v = {
37333
36737
  base: AUTHORIZER_FACTORY_BASE_TYPE,
37334
36738
  key: 'SharedSecretAuthorizer',
37335
36739
  };
@@ -37339,7 +36743,7 @@ class SharedSecretAuthorizerFactory extends AuthorizerFactory {
37339
36743
  this.type = 'SharedSecretAuthorizer';
37340
36744
  }
37341
36745
  async create(config) {
37342
- const normalized = normalizeConfig$7(config);
36746
+ const normalized = normalizeConfig$8(config);
37343
36747
  const credentialProvider = await CredentialProviderFactory.createCredentialProvider(normalized.secretConfig);
37344
36748
  const { SharedSecretAuthorizer } = await getSharedSecretAuthorizerModule();
37345
36749
  return new SharedSecretAuthorizer(credentialProvider);
@@ -37348,7 +36752,7 @@ class SharedSecretAuthorizerFactory extends AuthorizerFactory {
37348
36752
 
37349
36753
  var sharedSecretAuthorizerFactory = /*#__PURE__*/Object.freeze({
37350
36754
  __proto__: null,
37351
- FACTORY_META: FACTORY_META$s,
36755
+ FACTORY_META: FACTORY_META$v,
37352
36756
  SharedSecretAuthorizerFactory: SharedSecretAuthorizerFactory,
37353
36757
  default: SharedSecretAuthorizerFactory
37354
36758
  });
@@ -37360,7 +36764,7 @@ async function getSharedSecretTokenProviderModule() {
37360
36764
  }
37361
36765
  return sharedSecretTokenProviderModulePromise;
37362
36766
  }
37363
- function normalizeConfig$6(config) {
36767
+ function normalizeConfig$7(config) {
37364
36768
  if (!config) {
37365
36769
  throw new Error('SharedSecretTokenProvider requires configuration');
37366
36770
  }
@@ -37384,7 +36788,7 @@ function normalizeConfig$6(config) {
37384
36788
  secretConfig: normalizeSecretSource(secretSource),
37385
36789
  };
37386
36790
  }
37387
- const FACTORY_META$r = {
36791
+ const FACTORY_META$u = {
37388
36792
  base: TOKEN_PROVIDER_FACTORY_BASE_TYPE,
37389
36793
  key: 'SharedSecretTokenProvider',
37390
36794
  };
@@ -37394,7 +36798,7 @@ class SharedSecretTokenProviderFactory extends TokenProviderFactory {
37394
36798
  this.type = 'SharedSecretTokenProvider';
37395
36799
  }
37396
36800
  async create(config) {
37397
- const normalized = normalizeConfig$6(config);
36801
+ const normalized = normalizeConfig$7(config);
37398
36802
  const credentialProvider = await CredentialProviderFactory.createCredentialProvider(normalized.secretConfig);
37399
36803
  const { SharedSecretTokenProvider } = await getSharedSecretTokenProviderModule();
37400
36804
  return new SharedSecretTokenProvider(credentialProvider);
@@ -37403,7 +36807,7 @@ class SharedSecretTokenProviderFactory extends TokenProviderFactory {
37403
36807
 
37404
36808
  var sharedSecretTokenProviderFactory = /*#__PURE__*/Object.freeze({
37405
36809
  __proto__: null,
37406
- FACTORY_META: FACTORY_META$r,
36810
+ FACTORY_META: FACTORY_META$u,
37407
36811
  SharedSecretTokenProviderFactory: SharedSecretTokenProviderFactory,
37408
36812
  default: SharedSecretTokenProviderFactory
37409
36813
  });
@@ -37415,7 +36819,7 @@ async function getSharedSecretTokenVerifierModule() {
37415
36819
  }
37416
36820
  return sharedSecretTokenVerifierModulePromise;
37417
36821
  }
37418
- function normalizeConfig$5(config) {
36822
+ function normalizeConfig$6(config) {
37419
36823
  const candidate = (config ?? {});
37420
36824
  const record = candidate;
37421
36825
  let secretSource = candidate.secret;
@@ -37447,7 +36851,7 @@ function normalizeConfig$5(config) {
37447
36851
  }
37448
36852
  return normalized;
37449
36853
  }
37450
- const FACTORY_META$q = {
36854
+ const FACTORY_META$t = {
37451
36855
  base: TOKEN_VERIFIER_FACTORY_BASE_TYPE,
37452
36856
  key: 'SharedSecretTokenVerifier',
37453
36857
  };
@@ -37457,7 +36861,7 @@ class SharedSecretTokenVerifierFactory extends TokenVerifierFactory {
37457
36861
  this.type = 'SharedSecretTokenVerifier';
37458
36862
  }
37459
36863
  async create(config) {
37460
- const normalized = normalizeConfig$5(config);
36864
+ const normalized = normalizeConfig$6(config);
37461
36865
  const credentialProvider = (await CredentialProviderFactory.createCredentialProvider(normalized.secretConfig));
37462
36866
  const options = {
37463
36867
  credentialProvider,
@@ -37472,7 +36876,7 @@ class SharedSecretTokenVerifierFactory extends TokenVerifierFactory {
37472
36876
 
37473
36877
  var sharedSecretTokenVerifierFactory = /*#__PURE__*/Object.freeze({
37474
36878
  __proto__: null,
37475
- FACTORY_META: FACTORY_META$q,
36879
+ FACTORY_META: FACTORY_META$t,
37476
36880
  SharedSecretTokenVerifierFactory: SharedSecretTokenVerifierFactory,
37477
36881
  default: SharedSecretTokenVerifierFactory
37478
36882
  });
@@ -37562,7 +36966,7 @@ function normalizeOptions$8(input) {
37562
36966
  };
37563
36967
  }
37564
36968
 
37565
- function normalizeConfig$4(config) {
36969
+ function normalizeConfig$5(config) {
37566
36970
  if (!config) {
37567
36971
  throw new Error('StaticTokenProvider requires configuration');
37568
36972
  }
@@ -37587,7 +36991,7 @@ function normalizeConfig$4(config) {
37587
36991
  }
37588
36992
  return options;
37589
36993
  }
37590
- const FACTORY_META$p = {
36994
+ const FACTORY_META$s = {
37591
36995
  base: TOKEN_PROVIDER_FACTORY_BASE_TYPE,
37592
36996
  key: 'StaticTokenProvider',
37593
36997
  };
@@ -37597,14 +37001,14 @@ class StaticTokenProviderFactory extends TokenProviderFactory {
37597
37001
  this.type = 'StaticTokenProvider';
37598
37002
  }
37599
37003
  async create(config) {
37600
- const options = normalizeConfig$4(config);
37004
+ const options = normalizeConfig$5(config);
37601
37005
  return new StaticTokenProvider(options);
37602
37006
  }
37603
37007
  }
37604
37008
 
37605
37009
  var staticTokenProviderFactory = /*#__PURE__*/Object.freeze({
37606
37010
  __proto__: null,
37607
- FACTORY_META: FACTORY_META$p,
37011
+ FACTORY_META: FACTORY_META$s,
37608
37012
  StaticTokenProviderFactory: StaticTokenProviderFactory,
37609
37013
  default: StaticTokenProviderFactory
37610
37014
  });
@@ -37655,7 +37059,7 @@ class WebSocketSubprotocolAuthInjectionStrategy {
37655
37059
  }
37656
37060
  }
37657
37061
 
37658
- const FACTORY_META$o = {
37062
+ const FACTORY_META$r = {
37659
37063
  base: AUTH_INJECTION_STRATEGY_FACTORY_BASE_TYPE,
37660
37064
  key: 'WebSocketSubprotocolAuth',
37661
37065
  };
@@ -37665,11 +37069,11 @@ class WebSocketSubprotocolAuthInjectionStrategyFactory extends AuthInjectionStra
37665
37069
  this.type = 'WebSocketSubprotocolAuth';
37666
37070
  }
37667
37071
  async create(config) {
37668
- const normalized = normalizeConfig$3(config);
37072
+ const normalized = normalizeConfig$4(config);
37669
37073
  return new WebSocketSubprotocolAuthInjectionStrategy(normalized);
37670
37074
  }
37671
37075
  }
37672
- function normalizeConfig$3(config) {
37076
+ function normalizeConfig$4(config) {
37673
37077
  if (!config) {
37674
37078
  throw new Error('WebSocketSubprotocolAuthInjectionStrategy requires configuration');
37675
37079
  }
@@ -37697,7 +37101,7 @@ function normalizeConfig$3(config) {
37697
37101
 
37698
37102
  var websocketSubprotocolAuthInjectionStrategyFactory = /*#__PURE__*/Object.freeze({
37699
37103
  __proto__: null,
37700
- FACTORY_META: FACTORY_META$o,
37104
+ FACTORY_META: FACTORY_META$r,
37701
37105
  WebSocketSubprotocolAuthInjectionStrategyFactory: WebSocketSubprotocolAuthInjectionStrategyFactory,
37702
37106
  default: WebSocketSubprotocolAuthInjectionStrategyFactory
37703
37107
  });
@@ -37745,7 +37149,7 @@ class DevFixedKeyCredentialProviderFactory extends CredentialProviderFactory {
37745
37149
  throw new Error('DevFixedKeyCredentialProvider requires keyHex or keyBase64');
37746
37150
  }
37747
37151
  }
37748
- const FACTORY_META$n = {
37152
+ const FACTORY_META$q = {
37749
37153
  base: CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE,
37750
37154
  key: 'DevFixedKeyCredentialProvider',
37751
37155
  };
@@ -37753,7 +37157,7 @@ const FACTORY_META$n = {
37753
37157
  var devFixedKeyCredentialProviderFactory = /*#__PURE__*/Object.freeze({
37754
37158
  __proto__: null,
37755
37159
  DevFixedKeyCredentialProviderFactory: DevFixedKeyCredentialProviderFactory,
37756
- FACTORY_META: FACTORY_META$n,
37160
+ FACTORY_META: FACTORY_META$q,
37757
37161
  default: DevFixedKeyCredentialProviderFactory,
37758
37162
  normalizeDevFixedConfig: normalizeDevFixedConfig
37759
37163
  });
@@ -37769,14 +37173,14 @@ class NoneCredentialProviderFactory extends CredentialProviderFactory {
37769
37173
  return new NoneCredentialProvider();
37770
37174
  }
37771
37175
  }
37772
- const FACTORY_META$m = {
37176
+ const FACTORY_META$p = {
37773
37177
  base: CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE,
37774
37178
  key: 'NoneCredentialProvider',
37775
37179
  };
37776
37180
 
37777
37181
  var noneCredentialProviderFactory = /*#__PURE__*/Object.freeze({
37778
37182
  __proto__: null,
37779
- FACTORY_META: FACTORY_META$m,
37183
+ FACTORY_META: FACTORY_META$p,
37780
37184
  NoneCredentialProviderFactory: NoneCredentialProviderFactory,
37781
37185
  default: NoneCredentialProviderFactory
37782
37186
  });
@@ -37814,20 +37218,20 @@ class SessionKeyCredentialProviderFactory extends CredentialProviderFactory {
37814
37218
  return new SessionKeyCredentialProvider(resolved.length);
37815
37219
  }
37816
37220
  }
37817
- const FACTORY_META$l = {
37221
+ const FACTORY_META$o = {
37818
37222
  base: CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE,
37819
37223
  key: 'SessionKeyCredentialProvider',
37820
37224
  };
37821
37225
 
37822
37226
  var sessionKeyCredentialProviderFactory = /*#__PURE__*/Object.freeze({
37823
37227
  __proto__: null,
37824
- FACTORY_META: FACTORY_META$l,
37228
+ FACTORY_META: FACTORY_META$o,
37825
37229
  SessionKeyCredentialProviderFactory: SessionKeyCredentialProviderFactory,
37826
37230
  default: SessionKeyCredentialProviderFactory,
37827
37231
  normalizeSessionKeyConfig: normalizeSessionKeyConfig
37828
37232
  });
37829
37233
 
37830
- const logger$a = getLogger('naylence.fame.security.default_security_manager_factory');
37234
+ const logger$c = getLogger('naylence.fame.security.default_security_manager_factory');
37831
37235
  function normalizeDefaultSecurityManagerConfig(config) {
37832
37236
  if (!config) {
37833
37237
  return null;
@@ -37862,7 +37266,7 @@ function normalizeDefaultSecurityManagerConfig(config) {
37862
37266
  ensureAlias('trustStoreProvider', 'trust_store_provider');
37863
37267
  return normalized;
37864
37268
  }
37865
- const FACTORY_META$k = {
37269
+ const FACTORY_META$n = {
37866
37270
  base: SECURITY_MANAGER_FACTORY_BASE_TYPE,
37867
37271
  key: 'DefaultSecurityManager',
37868
37272
  };
@@ -37995,7 +37399,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
37995
37399
  return await KeyStoreFactory.createKeyStore(value, createOptions ?? undefined);
37996
37400
  }
37997
37401
  catch (error) {
37998
- logger$a.error('failed_to_create_key_store_from_config', {
37402
+ logger$c.error('failed_to_create_key_store_from_config', {
37999
37403
  error: error instanceof Error ? error.message : String(error),
38000
37404
  });
38001
37405
  return null;
@@ -38031,7 +37435,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38031
37435
  return null;
38032
37436
  }
38033
37437
  const cryptoProvider = cryptoProviderOverride ?? null;
38034
- logger$a.debug('auto_create_envelope_signer', {
37438
+ logger$c.debug('auto_create_envelope_signer', {
38035
37439
  has_crypto_override: Boolean(cryptoProviderOverride),
38036
37440
  override_constructor: cryptoProviderOverride
38037
37441
  ? (cryptoProviderOverride.constructor?.name ?? 'unknown')
@@ -38052,7 +37456,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38052
37456
  });
38053
37457
  }
38054
37458
  catch (error) {
38055
- logger$a.error('failed_to_auto_create_envelope_signer', {
37459
+ logger$c.error('failed_to_auto_create_envelope_signer', {
38056
37460
  error: error instanceof Error ? error.message : String(error),
38057
37461
  exc_info: true,
38058
37462
  });
@@ -38087,7 +37491,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38087
37491
  });
38088
37492
  }
38089
37493
  catch (error) {
38090
- logger$a.error('failed_to_auto_create_envelope_verifier', {
37494
+ logger$c.error('failed_to_auto_create_envelope_verifier', {
38091
37495
  error: error instanceof Error ? error.message : String(error),
38092
37496
  exc_info: true,
38093
37497
  });
@@ -38099,7 +37503,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38099
37503
  if (encryptionConfig &&
38100
37504
  DefaultSecurityManagerFactory.isConfigLike(encryptionConfig)) {
38101
37505
  if (!keyManager) {
38102
- logger$a.warning('encryption_manager_config_requires_key_manager');
37506
+ logger$c.warning('encryption_manager_config_requires_key_manager');
38103
37507
  return { encryptionManager: null, secureChannelManager };
38104
37508
  }
38105
37509
  const manager = await EncryptionManagerFactory.createEncryptionManager(encryptionConfig, {
@@ -38136,7 +37540,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38136
37540
  return { encryptionManager: manager, secureChannelManager };
38137
37541
  }
38138
37542
  catch (error) {
38139
- logger$a.error('failed_to_auto_create_encryption_manager', {
37543
+ logger$c.error('failed_to_auto_create_encryption_manager', {
38140
37544
  error: error instanceof Error ? error.message : String(error),
38141
37545
  exc_info: true,
38142
37546
  });
@@ -38179,7 +37583,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38179
37583
  });
38180
37584
  }
38181
37585
  catch (error) {
38182
- logger$a.error('failed_to_auto_create_key_manager', {
37586
+ logger$c.error('failed_to_auto_create_key_manager', {
38183
37587
  error: error instanceof Error ? error.message : String(error),
38184
37588
  exc_info: true,
38185
37589
  });
@@ -38228,7 +37632,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38228
37632
  })) ?? null);
38229
37633
  }
38230
37634
  catch (error) {
38231
- logger$a.error('failed_to_auto_create_authorizer', {
37635
+ logger$c.error('failed_to_auto_create_authorizer', {
38232
37636
  error: error instanceof Error ? error.message : String(error),
38233
37637
  exc_info: true,
38234
37638
  });
@@ -38257,7 +37661,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38257
37661
  });
38258
37662
  }
38259
37663
  catch (error) {
38260
- logger$a.error('failed_to_auto_create_certificate_manager', {
37664
+ logger$c.error('failed_to_auto_create_certificate_manager', {
38261
37665
  error: error instanceof Error ? error.message : String(error),
38262
37666
  exc_info: true,
38263
37667
  });
@@ -38328,11 +37732,11 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38328
37732
  var defaultSecurityManagerFactory = /*#__PURE__*/Object.freeze({
38329
37733
  __proto__: null,
38330
37734
  DefaultSecurityManagerFactory: DefaultSecurityManagerFactory,
38331
- FACTORY_META: FACTORY_META$k,
37735
+ FACTORY_META: FACTORY_META$n,
38332
37736
  default: DefaultSecurityManagerFactory
38333
37737
  });
38334
37738
 
38335
- const FACTORY_META$j = {
37739
+ const FACTORY_META$m = {
38336
37740
  base: ENCRYPTION_MANAGER_FACTORY_BASE_TYPE,
38337
37741
  key: 'NoopEncryptionManager',
38338
37742
  };
@@ -38389,7 +37793,7 @@ class NoopEncryptionManagerFactory extends EncryptionManagerFactory {
38389
37793
 
38390
37794
  var noopEncryptionManagerFactory = /*#__PURE__*/Object.freeze({
38391
37795
  __proto__: null,
38392
- FACTORY_META: FACTORY_META$j,
37796
+ FACTORY_META: FACTORY_META$m,
38393
37797
  NoopEncryptionManagerFactory: NoopEncryptionManagerFactory,
38394
37798
  default: NoopEncryptionManagerFactory
38395
37799
  });
@@ -38461,7 +37865,7 @@ class NoopSecureChannelManager {
38461
37865
  }
38462
37866
  }
38463
37867
 
38464
- const FACTORY_META$i = {
37868
+ const FACTORY_META$l = {
38465
37869
  base: SECURE_CHANNEL_MANAGER_FACTORY_BASE_TYPE,
38466
37870
  key: 'NoopSecureChannelManager',
38467
37871
  };
@@ -38478,12 +37882,12 @@ class NoopSecureChannelManagerFactory extends SecureChannelManagerFactory {
38478
37882
 
38479
37883
  var noopSecureChannelManagerFactory = /*#__PURE__*/Object.freeze({
38480
37884
  __proto__: null,
38481
- FACTORY_META: FACTORY_META$i,
37885
+ FACTORY_META: FACTORY_META$l,
38482
37886
  NoopSecureChannelManagerFactory: NoopSecureChannelManagerFactory,
38483
37887
  default: NoopSecureChannelManagerFactory
38484
37888
  });
38485
37889
 
38486
- const FACTORY_META$h = {
37890
+ const FACTORY_META$k = {
38487
37891
  base: KEY_MANAGER_FACTORY_BASE_TYPE,
38488
37892
  key: 'DefaultKeyManager',
38489
37893
  };
@@ -38512,11 +37916,11 @@ class DefaultKeyManagerFactory extends KeyManagerFactory {
38512
37916
  var defaultKeyManagerFactory = /*#__PURE__*/Object.freeze({
38513
37917
  __proto__: null,
38514
37918
  DefaultKeyManagerFactory: DefaultKeyManagerFactory,
38515
- FACTORY_META: FACTORY_META$h,
37919
+ FACTORY_META: FACTORY_META$k,
38516
37920
  default: DefaultKeyManagerFactory
38517
37921
  });
38518
37922
 
38519
- const logger$9 = getLogger('naylence.fame.security.keys.in_memory_key_store');
37923
+ const logger$b = getLogger('naylence.fame.security.keys.in_memory_key_store');
38520
37924
  class InMemoryKeyStore extends KeyStore {
38521
37925
  constructor(initialKeys = null) {
38522
37926
  super();
@@ -38538,7 +37942,7 @@ class InMemoryKeyStore extends KeyStore {
38538
37942
  }
38539
37943
  catch (error) {
38540
37944
  if (error instanceof JWKValidationError) {
38541
- logger$9.warning('rejected_invalid_jwk_individual', {
37945
+ logger$b.warning('rejected_invalid_jwk_individual', {
38542
37946
  kid,
38543
37947
  error: error.message,
38544
37948
  });
@@ -38582,7 +37986,7 @@ class InMemoryKeyStore extends KeyStore {
38582
37986
  }
38583
37987
  }
38584
37988
  if (staleKeys.length > 0) {
38585
- logger$9.debug('removing_stale_keys_before_adding_new_key', {
37989
+ logger$b.debug('removing_stale_keys_before_adding_new_key', {
38586
37990
  new_kid: kid,
38587
37991
  physical_path: physicalPath,
38588
37992
  base_path: basePath,
@@ -38610,7 +38014,7 @@ class InMemoryKeyStore extends KeyStore {
38610
38014
  }
38611
38015
  keysByPath[path].push(existingKid);
38612
38016
  }
38613
- logger$9.debug('key_lookup_failed', {
38017
+ logger$b.debug('key_lookup_failed', {
38614
38018
  missing_kid: kid,
38615
38019
  available_kids: Array.from(this.keys.keys()),
38616
38020
  keys_by_path: keysByPath,
@@ -38659,7 +38063,7 @@ class InMemoryKeyStore extends KeyStore {
38659
38063
  this.keys.delete(kid);
38660
38064
  }
38661
38065
  if (keysToRemove.length > 0) {
38662
- logger$9.debug('removed_keys_for_path', {
38066
+ logger$b.debug('removed_keys_for_path', {
38663
38067
  physical_path: physicalPath,
38664
38068
  removed_key_ids: keysToRemove,
38665
38069
  count: keysToRemove.length,
@@ -38670,7 +38074,7 @@ class InMemoryKeyStore extends KeyStore {
38670
38074
  async removeKey(kid) {
38671
38075
  const removed = this.keys.delete(kid);
38672
38076
  if (removed) {
38673
- logger$9.debug('removed_individual_key', { kid });
38077
+ logger$b.debug('removed_individual_key', { kid });
38674
38078
  }
38675
38079
  return removed;
38676
38080
  }
@@ -38697,7 +38101,7 @@ class InMemoryKeyStore extends KeyStore {
38697
38101
  }
38698
38102
  registerDefaultKeyStoreFactory(() => new InMemoryKeyStore());
38699
38103
 
38700
- const FACTORY_META$g = {
38104
+ const FACTORY_META$j = {
38701
38105
  base: KEY_STORE_FACTORY_BASE_TYPE,
38702
38106
  key: 'InMemoryKeyStore',
38703
38107
  };
@@ -38732,12 +38136,12 @@ class InMemoryKeyStoreFactory extends KeyStoreFactory {
38732
38136
 
38733
38137
  var inMemoryKeyStoreFactory = /*#__PURE__*/Object.freeze({
38734
38138
  __proto__: null,
38735
- FACTORY_META: FACTORY_META$g,
38139
+ FACTORY_META: FACTORY_META$j,
38736
38140
  InMemoryKeyStoreFactory: InMemoryKeyStoreFactory,
38737
38141
  default: InMemoryKeyStoreFactory
38738
38142
  });
38739
38143
 
38740
- const FACTORY_META$f = {
38144
+ const FACTORY_META$i = {
38741
38145
  base: ATTACHMENT_KEY_VALIDATOR_FACTORY_BASE_TYPE,
38742
38146
  key: 'NoopKeyValidator',
38743
38147
  };
@@ -38755,12 +38159,12 @@ class NoopKeyValidatorFactory extends AttachmentKeyValidatorFactory {
38755
38159
 
38756
38160
  var noopKeyValidatorFactory = /*#__PURE__*/Object.freeze({
38757
38161
  __proto__: null,
38758
- FACTORY_META: FACTORY_META$f,
38162
+ FACTORY_META: FACTORY_META$i,
38759
38163
  NoopKeyValidatorFactory: NoopKeyValidatorFactory,
38760
38164
  default: NoopKeyValidatorFactory
38761
38165
  });
38762
38166
 
38763
- const FACTORY_META$e = {
38167
+ const FACTORY_META$h = {
38764
38168
  base: SECURITY_POLICY_FACTORY_BASE_TYPE,
38765
38169
  key: 'DefaultSecurityPolicy',
38766
38170
  };
@@ -38778,7 +38182,7 @@ class DefaultSecurityPolicyFactory extends SecurityPolicyFactory {
38778
38182
  * - factoryArgs[0]: KeyProvider | null (optional) - Key provider for key lookups
38779
38183
  */
38780
38184
  async create(config, ...factoryArgs) {
38781
- const prepared = normalizeConfig$2(config);
38185
+ const prepared = normalizeConfig$3(config);
38782
38186
  const options = {};
38783
38187
  // Extract keyProvider from factoryArgs[0] (matches Python's key_provider kwarg)
38784
38188
  const keyProvider = factoryArgs[0];
@@ -38795,7 +38199,7 @@ class DefaultSecurityPolicyFactory extends SecurityPolicyFactory {
38795
38199
  return new DefaultSecurityPolicy(options);
38796
38200
  }
38797
38201
  }
38798
- function normalizeConfig$2(config) {
38202
+ function normalizeConfig$3(config) {
38799
38203
  if (!config) {
38800
38204
  return { type: 'DefaultSecurityPolicy' };
38801
38205
  }
@@ -38821,11 +38225,11 @@ function normalizeConfig$2(config) {
38821
38225
  var defaultSecurityPolicyFactory = /*#__PURE__*/Object.freeze({
38822
38226
  __proto__: null,
38823
38227
  DefaultSecurityPolicyFactory: DefaultSecurityPolicyFactory,
38824
- FACTORY_META: FACTORY_META$e,
38228
+ FACTORY_META: FACTORY_META$h,
38825
38229
  default: DefaultSecurityPolicyFactory
38826
38230
  });
38827
38231
 
38828
- const FACTORY_META$d = {
38232
+ const FACTORY_META$g = {
38829
38233
  base: SECURITY_POLICY_FACTORY_BASE_TYPE,
38830
38234
  key: 'NoSecurityPolicy',
38831
38235
  };
@@ -38835,11 +38239,11 @@ class NoSecurityPolicyFactory extends SecurityPolicyFactory {
38835
38239
  this.type = 'NoSecurityPolicy';
38836
38240
  }
38837
38241
  async create(config) {
38838
- void normalizeConfig$1(config);
38242
+ void normalizeConfig$2(config);
38839
38243
  return new NoSecurityPolicy();
38840
38244
  }
38841
38245
  }
38842
- function normalizeConfig$1(config) {
38246
+ function normalizeConfig$2(config) {
38843
38247
  if (!config) {
38844
38248
  return { type: 'NoSecurityPolicy' };
38845
38249
  }
@@ -38853,7 +38257,7 @@ function normalizeConfig$1(config) {
38853
38257
 
38854
38258
  var noSecurityPolicyFactory = /*#__PURE__*/Object.freeze({
38855
38259
  __proto__: null,
38856
- FACTORY_META: FACTORY_META$d,
38260
+ FACTORY_META: FACTORY_META$g,
38857
38261
  NoSecurityPolicyFactory: NoSecurityPolicyFactory,
38858
38262
  default: NoSecurityPolicyFactory
38859
38263
  });
@@ -38868,7 +38272,7 @@ async function getEdDSAEnvelopeSignerModule() {
38868
38272
  }
38869
38273
  return eddsaEnvelopeSignerModulePromise;
38870
38274
  }
38871
- const FACTORY_META$c = {
38275
+ const FACTORY_META$f = {
38872
38276
  base: ENVELOPE_SIGNER_FACTORY_BASE_TYPE,
38873
38277
  key: 'EdDSAEnvelopeSigner',
38874
38278
  };
@@ -38897,7 +38301,7 @@ class EdDSAEnvelopeSignerFactory extends EnvelopeSignerFactory {
38897
38301
  var eddsaEnvelopeSignerFactory = /*#__PURE__*/Object.freeze({
38898
38302
  __proto__: null,
38899
38303
  EdDSAEnvelopeSignerFactory: EdDSAEnvelopeSignerFactory,
38900
- FACTORY_META: FACTORY_META$c,
38304
+ FACTORY_META: FACTORY_META$f,
38901
38305
  default: EdDSAEnvelopeSignerFactory
38902
38306
  });
38903
38307
 
@@ -38911,7 +38315,7 @@ async function getEdDSAEnvelopeVerifierModule() {
38911
38315
  }
38912
38316
  return eddsaEnvelopeVerifierModulePromise;
38913
38317
  }
38914
- const FACTORY_META$b = {
38318
+ const FACTORY_META$e = {
38915
38319
  base: ENVELOPE_VERIFIER_FACTORY_BASE_TYPE,
38916
38320
  key: 'EdDSAEnvelopeVerifier',
38917
38321
  };
@@ -38937,11 +38341,11 @@ class EdDSAEnvelopeVerifierFactory extends EnvelopeVerifierFactory {
38937
38341
  var eddsaEnvelopeVerifierFactory = /*#__PURE__*/Object.freeze({
38938
38342
  __proto__: null,
38939
38343
  EdDSAEnvelopeVerifierFactory: EdDSAEnvelopeVerifierFactory,
38940
- FACTORY_META: FACTORY_META$b,
38344
+ FACTORY_META: FACTORY_META$e,
38941
38345
  default: EdDSAEnvelopeVerifierFactory
38942
38346
  });
38943
38347
 
38944
- const FACTORY_META$a = {
38348
+ const FACTORY_META$d = {
38945
38349
  base: TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE,
38946
38350
  key: "NoopTrustStoreProvider",
38947
38351
  isDefault: true,
@@ -38961,12 +38365,12 @@ class NoopTrustStoreProviderFactory extends TrustStoreProviderFactory {
38961
38365
 
38962
38366
  var noopTrustStoreProviderFactory = /*#__PURE__*/Object.freeze({
38963
38367
  __proto__: null,
38964
- FACTORY_META: FACTORY_META$a,
38368
+ FACTORY_META: FACTORY_META$d,
38965
38369
  NoopTrustStoreProviderFactory: NoopTrustStoreProviderFactory,
38966
38370
  default: NoopTrustStoreProviderFactory
38967
38371
  });
38968
38372
 
38969
- const FACTORY_META$9 = {
38373
+ const FACTORY_META$c = {
38970
38374
  base: ROUTING_POLICY_FACTORY_BASE,
38971
38375
  key: 'CapabilityAwareRoutingPolicy',
38972
38376
  };
@@ -39032,12 +38436,12 @@ class CapabilityAwareRoutingPolicyFactory extends RoutingPolicyFactory {
39032
38436
  var capabilityAwareRoutingPolicyFactory = /*#__PURE__*/Object.freeze({
39033
38437
  __proto__: null,
39034
38438
  CapabilityAwareRoutingPolicyFactory: CapabilityAwareRoutingPolicyFactory,
39035
- FACTORY_META: FACTORY_META$9,
38439
+ FACTORY_META: FACTORY_META$c,
39036
38440
  default: CapabilityAwareRoutingPolicyFactory
39037
38441
  });
39038
38442
 
39039
- const logger$8 = getLogger('naylence.fame.sentinel.composite_routing_policy_factory');
39040
- const FACTORY_META$8 = {
38443
+ const logger$a = getLogger('naylence.fame.sentinel.composite_routing_policy_factory');
38444
+ const FACTORY_META$b = {
39041
38445
  base: ROUTING_POLICY_FACTORY_BASE,
39042
38446
  key: 'CompositeRoutingPolicy',
39043
38447
  };
@@ -39062,13 +38466,13 @@ class CompositeRoutingPolicyFactory extends RoutingPolicyFactory {
39062
38466
  policies.push(policy);
39063
38467
  }
39064
38468
  else {
39065
- logger$8.warning('composite_policy_null_child', {
38469
+ logger$a.warning('composite_policy_null_child', {
39066
38470
  config: policyConfig,
39067
38471
  });
39068
38472
  }
39069
38473
  }
39070
38474
  catch (error) {
39071
- logger$8.warning('composite_policy_child_error', {
38475
+ logger$a.warning('composite_policy_child_error', {
39072
38476
  error: error instanceof Error ? error.message : String(error),
39073
38477
  config: policyConfig,
39074
38478
  });
@@ -39161,11 +38565,11 @@ function getFirstDefined(record, keys) {
39161
38565
  var compositeRoutingPolicyFactory = /*#__PURE__*/Object.freeze({
39162
38566
  __proto__: null,
39163
38567
  CompositeRoutingPolicyFactory: CompositeRoutingPolicyFactory,
39164
- FACTORY_META: FACTORY_META$8,
38568
+ FACTORY_META: FACTORY_META$b,
39165
38569
  default: CompositeRoutingPolicyFactory
39166
38570
  });
39167
38571
 
39168
- const FACTORY_META$7 = {
38572
+ const FACTORY_META$a = {
39169
38573
  base: ROUTING_POLICY_FACTORY_BASE,
39170
38574
  key: 'HybridPathRoutingPolicy',
39171
38575
  };
@@ -39227,12 +38631,12 @@ class HybridPathRoutingPolicyFactory extends RoutingPolicyFactory {
39227
38631
 
39228
38632
  var hybridPathRoutingPolicyFactory = /*#__PURE__*/Object.freeze({
39229
38633
  __proto__: null,
39230
- FACTORY_META: FACTORY_META$7,
38634
+ FACTORY_META: FACTORY_META$a,
39231
38635
  HybridPathRoutingPolicyFactory: HybridPathRoutingPolicyFactory,
39232
38636
  default: HybridPathRoutingPolicyFactory
39233
38637
  });
39234
38638
 
39235
- const FACTORY_META$6 = {
38639
+ const FACTORY_META$9 = {
39236
38640
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39237
38641
  key: 'CompositeLoadBalancingStrategy',
39238
38642
  };
@@ -39291,11 +38695,11 @@ class CompositeLoadBalancingStrategyFactory extends LoadBalancingStrategyFactory
39291
38695
  var compositeLoadBalancingStrategyFactory = /*#__PURE__*/Object.freeze({
39292
38696
  __proto__: null,
39293
38697
  CompositeLoadBalancingStrategyFactory: CompositeLoadBalancingStrategyFactory,
39294
- FACTORY_META: FACTORY_META$6,
38698
+ FACTORY_META: FACTORY_META$9,
39295
38699
  default: CompositeLoadBalancingStrategyFactory
39296
38700
  });
39297
38701
 
39298
- const FACTORY_META$5 = {
38702
+ const FACTORY_META$8 = {
39299
38703
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39300
38704
  key: 'HRWLoadBalancingStrategy',
39301
38705
  };
@@ -39358,13 +38762,13 @@ async function createDefaultHRWStrategy(config) {
39358
38762
 
39359
38763
  var hrwLoadBalancingStrategyFactory = /*#__PURE__*/Object.freeze({
39360
38764
  __proto__: null,
39361
- FACTORY_META: FACTORY_META$5,
38765
+ FACTORY_META: FACTORY_META$8,
39362
38766
  HRWLoadBalancingStrategyFactory: HRWLoadBalancingStrategyFactory,
39363
38767
  createDefaultHRWStrategy: createDefaultHRWStrategy,
39364
38768
  default: HRWLoadBalancingStrategyFactory
39365
38769
  });
39366
38770
 
39367
- const logger$7 = getLogger('naylence.fame.sentinel.load_balancing.load_balancing_profile_factory');
38771
+ const logger$9 = getLogger('naylence.fame.sentinel.load_balancing.load_balancing_profile_factory');
39368
38772
  const PROFILE_NAME_RANDOM = 'random';
39369
38773
  const PROFILE_NAME_ROUND_ROBIN = 'round_robin';
39370
38774
  const PROFILE_NAME_HRW = 'hrw';
@@ -39386,7 +38790,7 @@ const STICKY_HRW_PROFILE = {
39386
38790
  const DEVELOPMENT_PROFILE$1 = {
39387
38791
  type: 'RoundRobinLoadBalancingStrategy',
39388
38792
  };
39389
- const FACTORY_META$4 = {
38793
+ const FACTORY_META$7 = {
39390
38794
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39391
38795
  key: 'LoadBalancingProfile',
39392
38796
  };
@@ -39398,7 +38802,7 @@ class LoadBalancingProfileFactory extends LoadBalancingStrategyFactory {
39398
38802
  async create(config, ...factoryArgs) {
39399
38803
  const finalConfig = this.normalizeConfig(config);
39400
38804
  const profileName = finalConfig.profile ?? PROFILE_NAME_DEVELOPMENT$1;
39401
- logger$7.debug('enabling_load_balancing_profile', { profile: profileName });
38805
+ logger$9.debug('enabling_load_balancing_profile', { profile: profileName });
39402
38806
  const strategyConfig = this.resolveProfile(profileName);
39403
38807
  const strategy = await createResource$1(LOAD_BALANCING_STRATEGY_FACTORY_BASE, strategyConfig, { factoryArgs });
39404
38808
  if (!strategy) {
@@ -39459,7 +38863,7 @@ class LoadBalancingProfileFactory extends LoadBalancingStrategyFactory {
39459
38863
 
39460
38864
  var loadBalancingProfileFactory = /*#__PURE__*/Object.freeze({
39461
38865
  __proto__: null,
39462
- FACTORY_META: FACTORY_META$4,
38866
+ FACTORY_META: FACTORY_META$7,
39463
38867
  LoadBalancingProfileFactory: LoadBalancingProfileFactory,
39464
38868
  PROFILE_NAME_DEVELOPMENT: PROFILE_NAME_DEVELOPMENT$1,
39465
38869
  PROFILE_NAME_HRW: PROFILE_NAME_HRW,
@@ -39486,7 +38890,7 @@ class RandomLoadBalancingStrategy {
39486
38890
  }
39487
38891
  }
39488
38892
 
39489
- const FACTORY_META$3 = {
38893
+ const FACTORY_META$6 = {
39490
38894
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39491
38895
  key: 'RandomLoadBalancingStrategy',
39492
38896
  };
@@ -39502,7 +38906,7 @@ class RandomLoadBalancingStrategyFactory extends LoadBalancingStrategyFactory {
39502
38906
 
39503
38907
  var randomLoadBalancingStrategyFactory = /*#__PURE__*/Object.freeze({
39504
38908
  __proto__: null,
39505
- FACTORY_META: FACTORY_META$3,
38909
+ FACTORY_META: FACTORY_META$6,
39506
38910
  RandomLoadBalancingStrategyFactory: RandomLoadBalancingStrategyFactory,
39507
38911
  default: RandomLoadBalancingStrategyFactory
39508
38912
  });
@@ -39522,7 +38926,7 @@ class RoundRobinLoadBalancingStrategy {
39522
38926
  }
39523
38927
  }
39524
38928
 
39525
- const FACTORY_META$2 = {
38929
+ const FACTORY_META$5 = {
39526
38930
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39527
38931
  key: 'RoundRobinLoadBalancingStrategy',
39528
38932
  };
@@ -39538,12 +38942,12 @@ class RoundRobinLoadBalancingStrategyFactory extends LoadBalancingStrategyFactor
39538
38942
 
39539
38943
  var roundRobinLoadBalancingStrategyFactory = /*#__PURE__*/Object.freeze({
39540
38944
  __proto__: null,
39541
- FACTORY_META: FACTORY_META$2,
38945
+ FACTORY_META: FACTORY_META$5,
39542
38946
  RoundRobinLoadBalancingStrategyFactory: RoundRobinLoadBalancingStrategyFactory,
39543
38947
  default: RoundRobinLoadBalancingStrategyFactory
39544
38948
  });
39545
38949
 
39546
- const FACTORY_META$1 = {
38950
+ const FACTORY_META$4 = {
39547
38951
  base: LOAD_BALANCING_STRATEGY_FACTORY_BASE,
39548
38952
  key: 'StickyLoadBalancingStrategy',
39549
38953
  };
@@ -39584,12 +38988,12 @@ class StickyLoadBalancingStrategyFactory extends LoadBalancingStrategyFactory {
39584
38988
 
39585
38989
  var stickyLoadBalancingStrategyFactory = /*#__PURE__*/Object.freeze({
39586
38990
  __proto__: null,
39587
- FACTORY_META: FACTORY_META$1,
38991
+ FACTORY_META: FACTORY_META$4,
39588
38992
  StickyLoadBalancingStrategyFactory: StickyLoadBalancingStrategyFactory,
39589
38993
  default: StickyLoadBalancingStrategyFactory
39590
38994
  });
39591
38995
 
39592
- const logger$6 = getLogger('naylence.fame.sentinel.routing_profile_factory');
38996
+ const logger$8 = getLogger('naylence.fame.sentinel.routing_profile_factory');
39593
38997
  const PROFILE_NAME_DEVELOPMENT = 'development';
39594
38998
  const PROFILE_NAME_PRODUCTION = 'production';
39595
38999
  const PROFILE_NAME_BASIC = 'basic';
@@ -39622,14 +39026,14 @@ const HYBRID_ONLY_PROFILE = {
39622
39026
  type: 'HybridPathRoutingPolicy',
39623
39027
  loadBalancingStrategy: { type: 'HRWLoadBalancingStrategy' },
39624
39028
  };
39625
- const PROFILE_MAP = {
39029
+ const PROFILE_MAP$1 = {
39626
39030
  [PROFILE_NAME_DEVELOPMENT]: DEVELOPMENT_PROFILE,
39627
39031
  [PROFILE_NAME_PRODUCTION]: PRODUCTION_PROFILE,
39628
39032
  [PROFILE_NAME_BASIC]: BASIC_PROFILE,
39629
39033
  [PROFILE_NAME_CAPABILITY_AWARE]: CAPABILITY_AWARE_PROFILE,
39630
39034
  [PROFILE_NAME_HYBRID_ONLY]: HYBRID_ONLY_PROFILE,
39631
39035
  };
39632
- const FACTORY_META = {
39036
+ const FACTORY_META$3 = {
39633
39037
  base: ROUTING_POLICY_FACTORY_BASE,
39634
39038
  key: 'RoutingProfile',
39635
39039
  };
@@ -39640,7 +39044,7 @@ class RoutingProfileFactory extends RoutingPolicyFactory {
39640
39044
  }
39641
39045
  async create(config, ...kwargs) {
39642
39046
  const normalized = this.normalizeConfig(config);
39643
- logger$6.debug('enabling_routing_profile', { profile: normalized.profile });
39047
+ logger$8.debug('enabling_routing_profile', { profile: normalized.profile });
39644
39048
  const routingConfig = this.getProfileConfig(normalized.profile);
39645
39049
  const policy = await createResource$1(ROUTING_POLICY_FACTORY_BASE, routingConfig, {
39646
39050
  factoryArgs: kwargs,
@@ -39683,7 +39087,7 @@ class RoutingProfileFactory extends RoutingPolicyFactory {
39683
39087
  return undefined;
39684
39088
  }
39685
39089
  getProfileConfig(profile) {
39686
- const routingConfig = PROFILE_MAP[profile];
39090
+ const routingConfig = PROFILE_MAP$1[profile];
39687
39091
  if (!routingConfig) {
39688
39092
  throw new Error('Unknown routing profile');
39689
39093
  }
@@ -39693,7 +39097,7 @@ class RoutingProfileFactory extends RoutingPolicyFactory {
39693
39097
 
39694
39098
  var routingProfileFactory = /*#__PURE__*/Object.freeze({
39695
39099
  __proto__: null,
39696
- FACTORY_META: FACTORY_META,
39100
+ FACTORY_META: FACTORY_META$3,
39697
39101
  PROFILE_NAME_BASIC: PROFILE_NAME_BASIC,
39698
39102
  PROFILE_NAME_CAPABILITY_AWARE: PROFILE_NAME_CAPABILITY_AWARE,
39699
39103
  PROFILE_NAME_DEVELOPMENT: PROFILE_NAME_DEVELOPMENT,
@@ -39703,470 +39107,495 @@ var routingProfileFactory = /*#__PURE__*/Object.freeze({
39703
39107
  default: RoutingProfileFactory
39704
39108
  });
39705
39109
 
39706
- let initialized = false;
39707
- const runtimePlugin = {
39708
- name: 'naylence:runtime',
39709
- version: VERSION,
39710
- async register() {
39711
- // console.log('[naylence:runtime] register() called, initialized=', initialized);
39712
- if (initialized) {
39713
- // console.log('[naylence:runtime] already initialized, skipping');
39714
- return;
39715
- }
39716
- initialized = true;
39717
- // console.log('[naylence:runtime] registering runtime factories...');
39718
- // Register factories from manifest
39719
- await registerRuntimeFactories();
39720
- // Import modules with side-effect registrations (not in manifest)
39721
- await Promise.resolve().then(function () { return websocketTransportProvisioner; });
39722
- // console.log('[naylence:runtime] runtime factories registered');
39723
- },
39724
- };
39725
- const RUNTIME_PLUGIN_SPECIFIER = runtimePlugin.name;
39726
-
39727
- var plugin = /*#__PURE__*/Object.freeze({
39728
- __proto__: null,
39729
- RUNTIME_PLUGIN_SPECIFIER: RUNTIME_PLUGIN_SPECIFIER,
39730
- default: runtimePlugin
39731
- });
39732
-
39733
- let currentTraceId = null;
39734
- let currentSpanId = null;
39735
- function getOtelTraceId() {
39736
- return currentTraceId;
39737
- }
39738
- function getOtelSpanId() {
39739
- return currentSpanId;
39740
- }
39741
- function setOtelTraceId(traceId) {
39742
- const previous = currentTraceId;
39743
- currentTraceId = traceId;
39744
- return previous;
39110
+ const telemetryLogger = getLogger('naylence.fame.telemetry.base_trace_emitter');
39111
+ function logTelemetryFailure(event, error, context = {}) {
39112
+ telemetryLogger.warning(event, {
39113
+ ...context,
39114
+ error: error instanceof Error ? error.message : String(error),
39115
+ stack: error instanceof Error && error.stack ? error.stack : undefined,
39116
+ });
39745
39117
  }
39746
- function setOtelSpanId(spanId) {
39747
- const previous = currentSpanId;
39748
- currentSpanId = spanId;
39749
- return previous;
39118
+ function buildEnvelopeAttributes(envelope) {
39119
+ return {
39120
+ 'env.id': envelope.id,
39121
+ 'env.trace_id': envelope.traceId,
39122
+ 'env.corr_id': envelope.corrId,
39123
+ 'env.flow_id': envelope.flowId,
39124
+ 'env.seq_id': envelope.seqId,
39125
+ 'env.to': envelope.to ?? null,
39126
+ 'env.priority': envelope.priority ?? null,
39127
+ 'env.sid': envelope.sid ?? null,
39128
+ 'env.reply_to': envelope.replyTo ?? null,
39129
+ 'env.ts': envelope.ts?.toISOString?.() ?? null,
39130
+ 'env.frame_type': envelope.frame
39131
+ ? (envelope.frame.type ?? null)
39132
+ : null,
39133
+ 'env.is_signed': Boolean(envelope.sec?.sig),
39134
+ 'env.sign_kid': envelope.sec?.sig?.kid ?? null,
39135
+ 'env.is_encrypted': Boolean(envelope.sec?.enc),
39136
+ 'env.enc_kid': envelope.sec?.enc?.kid ?? null,
39137
+ };
39750
39138
  }
39751
- function resetOtelTraceId(previous) {
39752
- currentTraceId = previous;
39139
+ function filterAttributes(attributes) {
39140
+ const filtered = {};
39141
+ for (const [key, value] of Object.entries(attributes)) {
39142
+ if (value !== undefined && value !== null) {
39143
+ filtered[key] = value;
39144
+ }
39145
+ }
39146
+ return filtered;
39753
39147
  }
39754
- function resetOtelSpanId(previous) {
39755
- currentSpanId = previous;
39148
+ function extractContextValue(context, keys) {
39149
+ if (!context) {
39150
+ return undefined;
39151
+ }
39152
+ const source = context;
39153
+ for (const key of keys) {
39154
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
39155
+ const value = source[key];
39156
+ if (value !== undefined) {
39157
+ return value;
39158
+ }
39159
+ }
39160
+ }
39161
+ return undefined;
39756
39162
  }
39757
-
39758
- class OpenTelemetryTraceSpan {
39759
- constructor(span, api) {
39760
- this.span = span;
39761
- this.api = api;
39163
+ class BaseTraceEmitter extends BaseNodeEventListener {
39164
+ constructor() {
39165
+ super(...arguments);
39166
+ this.node = null;
39167
+ this.inflight = new Map();
39168
+ this.priority = 10000;
39762
39169
  }
39763
- setAttribute(key, value) {
39170
+ getSpanKey(envelope, operationKey) {
39171
+ return `${envelope.id}:${operationKey}`;
39172
+ }
39173
+ startEnvelopeOperationSpan(node, operationName, envelope, operationKey, additionalAttributes = null) {
39764
39174
  try {
39765
- this.span.setAttribute(key, normalizeAttributeValue(value));
39175
+ const key = this.getSpanKey(envelope, operationKey);
39176
+ const previous = this.inflight.get(key);
39177
+ if (previous) {
39178
+ this.inflight.delete(key);
39179
+ try {
39180
+ previous.scope.exit();
39181
+ }
39182
+ catch (cleanupError) {
39183
+ logTelemetryFailure('trace_span_scope_exit_failed', cleanupError, {
39184
+ operation: operationName,
39185
+ span_key: key,
39186
+ });
39187
+ }
39188
+ }
39189
+ const attributes = buildEnvelopeAttributes(envelope);
39190
+ if (additionalAttributes) {
39191
+ for (const [attrKey, attrValue] of Object.entries(additionalAttributes)) {
39192
+ attributes[attrKey] = attrValue;
39193
+ }
39194
+ }
39195
+ const effectiveNode = node ?? this.node;
39196
+ if (effectiveNode) {
39197
+ attributes['node.id'] = effectiveNode.id;
39198
+ attributes['node.sid'] = effectiveNode.sid ?? null;
39199
+ }
39200
+ const scope = this.startSpan(operationName, {
39201
+ attributes: filterAttributes(attributes),
39202
+ });
39203
+ const span = scope.enter();
39204
+ this.inflight.set(key, { scope, span });
39766
39205
  }
39767
- catch {
39768
- // Ignore telemetry attribute errors
39206
+ catch (error) {
39207
+ logTelemetryFailure('trace_span_start_failed', error, {
39208
+ operation: operationName,
39209
+ envelope_id: envelope.id,
39210
+ });
39769
39211
  }
39212
+ return envelope;
39770
39213
  }
39771
- recordException(error) {
39214
+ completeEnvelopeOperationSpan(node, operationName, envelope, operationKey, _result = null, error = null, additionalAttributes = null) {
39772
39215
  try {
39773
- if (error instanceof Error) {
39774
- this.span.recordException(error);
39216
+ const key = this.getSpanKey(envelope, operationKey);
39217
+ let active = this.inflight.get(key);
39218
+ if (!active) {
39219
+ const attributes = buildEnvelopeAttributes(envelope);
39220
+ if (additionalAttributes) {
39221
+ for (const [attrKey, attrValue] of Object.entries(additionalAttributes)) {
39222
+ attributes[attrKey] = attrValue;
39223
+ }
39224
+ }
39225
+ const effectiveNode = node ?? this.node;
39226
+ if (effectiveNode) {
39227
+ attributes['node.id'] = effectiveNode.id;
39228
+ attributes['node.sid'] = effectiveNode.sid ?? null;
39229
+ }
39230
+ const scope = this.startSpan(operationName, {
39231
+ attributes: filterAttributes(attributes),
39232
+ });
39233
+ const span = scope.enter();
39234
+ active = { scope, span };
39775
39235
  }
39776
39236
  else {
39777
- this.span.recordException(new Error(String(error)));
39237
+ this.inflight.delete(key);
39238
+ }
39239
+ if (error !== null && error !== undefined) {
39240
+ try {
39241
+ active.span.recordException(error);
39242
+ }
39243
+ catch (recordError) {
39244
+ logTelemetryFailure('trace_span_record_exception_failed', recordError, {
39245
+ operation: operationName,
39246
+ envelope_id: envelope.id,
39247
+ });
39248
+ }
39249
+ try {
39250
+ const description = error instanceof Error ? error.message : String(error);
39251
+ active.span.setStatusError(description);
39252
+ }
39253
+ catch (statusError) {
39254
+ logTelemetryFailure('trace_span_set_status_failed', statusError, {
39255
+ operation: operationName,
39256
+ envelope_id: envelope.id,
39257
+ });
39258
+ }
39259
+ }
39260
+ try {
39261
+ active.scope.exit();
39262
+ }
39263
+ catch (exitError) {
39264
+ logTelemetryFailure('trace_span_scope_exit_failed', exitError, {
39265
+ operation: operationName,
39266
+ envelope_id: envelope.id,
39267
+ });
39778
39268
  }
39779
39269
  }
39780
- catch {
39781
- // Ignore telemetry recording errors
39270
+ catch (error) {
39271
+ logTelemetryFailure('trace_span_complete_failed', error, {
39272
+ operation: operationName,
39273
+ envelope_id: envelope.id,
39274
+ });
39782
39275
  }
39276
+ return envelope;
39783
39277
  }
39784
- setStatusError(description) {
39278
+ async onEnvelopeReceived(node, envelope, context) {
39785
39279
  try {
39786
- const status = {
39787
- code: this.api.SpanStatusCode.ERROR,
39788
- };
39789
- if (description !== undefined) {
39790
- status.message = description;
39280
+ const attributes = buildEnvelopeAttributes(envelope);
39281
+ attributes['node.id'] = node.id;
39282
+ attributes['node.sid'] = node.sid ?? null;
39283
+ const fromNodeId = extractContextValue(context, [
39284
+ 'fromSystemId',
39285
+ 'from_system_id',
39286
+ 'fromNodeId',
39287
+ 'from_node_id',
39288
+ ]);
39289
+ if (fromNodeId !== undefined && fromNodeId !== null) {
39290
+ attributes['from.node_id'] = String(fromNodeId);
39791
39291
  }
39792
- this.span.setStatus(status);
39292
+ const originType = extractContextValue(context, [
39293
+ 'originType',
39294
+ 'origin_type',
39295
+ ]);
39296
+ if (originType !== undefined && originType !== null) {
39297
+ attributes['from.origin_type'] = String(originType);
39298
+ }
39299
+ const scope = this.startSpan('env.received', {
39300
+ attributes: filterAttributes(attributes),
39301
+ });
39302
+ scope.enter();
39303
+ scope.exit();
39793
39304
  }
39794
- catch {
39795
- // Ignore telemetry status errors
39305
+ catch (error) {
39306
+ logTelemetryFailure('trace_span_received_failed', error, {
39307
+ envelope_id: envelope.id,
39308
+ });
39796
39309
  }
39310
+ return envelope;
39797
39311
  }
39798
- }
39799
- class OpenTelemetrySpanScope {
39800
- constructor(span, api) {
39801
- this.span = span;
39802
- this.entered = false;
39803
- this.wrapper = new OpenTelemetryTraceSpan(span, api);
39312
+ async onForwardToRoute(node, nextSegment, envelope, _context) {
39313
+ return this.startEnvelopeOperationSpan(node, 'env.fwd_to_route', envelope, nextSegment, {
39314
+ 'route.segment': nextSegment,
39315
+ });
39804
39316
  }
39805
- enter() {
39806
- if (!this.entered) {
39807
- this.entered = true;
39808
- const spanContext = this.span.spanContext();
39809
- this.traceToken = setOtelTraceId(spanContext?.traceId ?? null);
39810
- this.spanToken = setOtelSpanId(spanContext?.spanId ?? null);
39811
- }
39812
- return this.wrapper;
39317
+ async onForwardToRouteComplete(node, nextSegment, envelope, result, error, _context) {
39318
+ return this.completeEnvelopeOperationSpan(node, 'env.fwd_to_route', envelope, nextSegment, result, error, {
39319
+ 'route.segment': nextSegment,
39320
+ });
39813
39321
  }
39814
- exit() {
39815
- try {
39816
- this.span.end();
39817
- }
39818
- catch {
39819
- // Ignore span termination errors
39820
- }
39821
- finally {
39822
- if (this.traceToken !== undefined) {
39823
- resetOtelTraceId(this.traceToken);
39824
- this.traceToken = undefined;
39825
- }
39826
- if (this.spanToken !== undefined) {
39827
- resetOtelSpanId(this.spanToken);
39828
- this.spanToken = undefined;
39829
- }
39830
- }
39322
+ async onForwardUpstream(node, envelope, _context) {
39323
+ return this.startEnvelopeOperationSpan(node, 'env.fwd_upstream', envelope, 'upstream', {
39324
+ direction: 'upstream',
39325
+ });
39831
39326
  }
39832
- }
39833
- class OpenTelemetryTraceEmitter extends BaseTraceEmitter {
39834
- constructor(options) {
39835
- super();
39836
- this.shutdownInvoked = false;
39837
- const normalized = normalizeOpenTelemetryTraceEmitterOptions(options);
39838
- this.otelApi = normalized.otelApi;
39839
- this.tracer =
39840
- normalized.tracer ?? this.otelApi.trace.getTracer(normalized.serviceName);
39841
- this.lifecycle = normalized.lifecycle ?? null;
39842
- this.authStrategy = normalized.authStrategy ?? null;
39327
+ async onForwardUpstreamComplete(node, envelope, result, error, _context) {
39328
+ return this.completeEnvelopeOperationSpan(node, 'env.fwd_upstream', envelope, 'upstream', result, error, {
39329
+ direction: 'upstream',
39330
+ });
39843
39331
  }
39844
- startSpan(name, options) {
39845
- const attributes = normalizeAttributes(options?.attributes);
39846
- const spanOptions = {};
39847
- if (attributes) {
39848
- spanOptions.attributes = attributes;
39849
- }
39850
- if (options?.links) {
39851
- spanOptions.links = options.links;
39852
- }
39853
- const span = this.tracer.startSpan(name, spanOptions);
39854
- const envelopeTraceId = options?.attributes?.['env.trace_id'];
39855
- if (typeof envelopeTraceId === 'string') {
39856
- this.applyEnvelopeTraceId(span, envelopeTraceId);
39857
- }
39858
- return new OpenTelemetrySpanScope(span, this.otelApi);
39332
+ async onForwardToPeer(node, peerSegment, envelope, _context) {
39333
+ return this.startEnvelopeOperationSpan(node, 'env.fwd_to_peer', envelope, peerSegment, {
39334
+ 'peer.segment': peerSegment,
39335
+ });
39859
39336
  }
39860
- async flush() {
39861
- if (this.lifecycle?.forceFlush) {
39862
- try {
39863
- await this.lifecycle.forceFlush();
39864
- return;
39865
- }
39866
- catch {
39867
- // fall through to global flush fallback
39868
- }
39869
- }
39870
- try {
39871
- const provider = this.otelApi.trace.getTracerProvider();
39872
- if (provider && typeof provider.forceFlush === 'function') {
39873
- await provider.forceFlush();
39874
- }
39875
- }
39876
- catch {
39877
- // Ignore flush errors
39878
- }
39337
+ async onForwardToPeerComplete(node, peerSegment, envelope, result, error, _context) {
39338
+ return this.completeEnvelopeOperationSpan(node, 'env.fwd_to_peer', envelope, peerSegment, result, error, {
39339
+ 'peer.segment': peerSegment,
39340
+ });
39879
39341
  }
39880
- async shutdown() {
39881
- if (this.shutdownInvoked) {
39882
- return;
39883
- }
39884
- this.shutdownInvoked = true;
39885
- const cleanupTasks = [];
39886
- const strategy = this.authStrategy;
39887
- if (strategy) {
39888
- this.authStrategy = null;
39889
- cleanupTasks.push(strategy.cleanup().catch(() => {
39890
- // Ignore auth cleanup failures
39891
- }));
39892
- }
39893
- if (this.lifecycle?.shutdown) {
39894
- try {
39895
- await this.lifecycle.shutdown();
39896
- this.lifecycle = null;
39897
- await Promise.all(cleanupTasks);
39898
- return;
39899
- }
39900
- catch {
39901
- // fall through to global shutdown fallback
39902
- this.lifecycle = null;
39903
- }
39904
- }
39905
- try {
39906
- const provider = this.otelApi.trace.getTracerProvider();
39907
- if (provider && typeof provider.shutdown === 'function') {
39908
- await provider.shutdown();
39909
- }
39910
- }
39911
- catch {
39912
- // Ignore shutdown errors
39913
- }
39914
- finally {
39915
- if (cleanupTasks.length > 0) {
39916
- await Promise.all(cleanupTasks);
39917
- }
39918
- }
39342
+ async onDeliverLocal(node, address, envelope, _context) {
39343
+ const addressKey = address ? String(address) : 'unknown';
39344
+ return this.startEnvelopeOperationSpan(node, 'env.deliver_local', envelope, addressKey, {
39345
+ 'delivery.address': addressKey,
39346
+ 'delivery.type': 'local',
39347
+ });
39919
39348
  }
39920
- applyEnvelopeTraceId(span, envelopeTraceId) {
39349
+ async onDeliverLocalComplete(node, address, envelope, _context) {
39350
+ const addressKey = address ? String(address) : 'unknown';
39351
+ return this.completeEnvelopeOperationSpan(node, 'env.deliver_local', envelope, addressKey, null, null, {
39352
+ 'delivery.address': addressKey,
39353
+ 'delivery.type': 'local',
39354
+ });
39355
+ }
39356
+ async onNodeInitialized(node) {
39357
+ this.node = node;
39358
+ }
39359
+ async onNodeStopped(_node) {
39921
39360
  try {
39922
- const targetTraceId = this.convertEnvTraceIdToOtel(envelopeTraceId);
39923
- const internalSpan = span;
39924
- if (internalSpan?._spanContext) {
39925
- internalSpan._spanContext.traceId = targetTraceId;
39361
+ if (typeof this.flush === 'function') {
39362
+ await this.flush();
39363
+ }
39364
+ if (typeof this.shutdown === 'function') {
39365
+ await this.shutdown();
39926
39366
  }
39927
39367
  }
39928
- catch {
39929
- // Ignore trace-id coercion errors
39368
+ catch (error) {
39369
+ logTelemetryFailure('trace_span_shutdown_failed', error);
39930
39370
  }
39931
39371
  }
39932
- convertEnvTraceIdToOtel(envTraceId) {
39933
- const normalized = envTraceId.slice(0, 16).padEnd(16, '0');
39934
- let hex = '';
39935
- for (let i = 0; i < 16; i += 1) {
39936
- const code = normalized.charCodeAt(i);
39937
- const byte = Number.isNaN(code) ? 0 : code & 0xff;
39938
- hex += byte.toString(16).padStart(2, '0');
39939
- }
39940
- return hex;
39372
+ async flush() {
39373
+ // Default implementation: no-op
39941
39374
  }
39942
- }
39943
- function normalizeOpenTelemetryTraceEmitterOptions(input) {
39944
- const source = (input ?? {});
39945
- const serviceName = extractNonEmptyString$1(pickFirst$1(source, ['serviceName', 'service_name'])) ?? 'naylence-service';
39946
- const tracer = pickFirst$1(source, ['tracer']);
39947
- const otelApi = pickFirst$1(source, [
39948
- 'otelApi',
39949
- 'otel_api',
39950
- ]);
39951
- if (!otelApi) {
39952
- throw new Error('OpenTelemetryTraceEmitter requires OpenTelemetry API bindings. Provide otelApi via options.');
39375
+ async shutdown() {
39376
+ // Default implementation: no-op
39953
39377
  }
39954
- const lifecycle = pickFirst$1(source, [
39955
- 'lifecycle',
39956
- 'lifeCycle',
39957
- 'life_cycle',
39958
- ]) ?? null;
39959
- const authStrategy = pickFirst$1(source, [
39960
- 'authStrategy',
39961
- 'auth_strategy',
39962
- ]) ?? null;
39963
- return {
39964
- serviceName,
39965
- tracer,
39966
- otelApi,
39967
- lifecycle,
39968
- authStrategy,
39969
- };
39970
39378
  }
39971
- function pickFirst$1(source, keys) {
39972
- for (const key of keys) {
39973
- if (Object.prototype.hasOwnProperty.call(source, key)) {
39974
- const value = source[key];
39975
- if (value !== undefined) {
39976
- return value;
39977
- }
39978
- }
39979
- }
39980
- return undefined;
39379
+
39380
+ class NoopTraceSpan {
39381
+ setAttribute() { }
39382
+ recordException() { }
39383
+ setStatusError() { }
39981
39384
  }
39982
- function extractNonEmptyString$1(value) {
39983
- if (typeof value === 'string') {
39984
- const trimmed = value.trim();
39985
- if (trimmed.length > 0) {
39986
- return trimmed;
39987
- }
39385
+ class NoopTraceSpanScope {
39386
+ constructor(span) {
39387
+ this.span = span;
39988
39388
  }
39989
- return undefined;
39990
- }
39991
- function normalizeAttributeValue(value) {
39992
- if (Array.isArray(value)) {
39993
- return value.map((item) => String(normalizePrimitiveAttribute(item, true)));
39389
+ enter() {
39390
+ return this.span;
39994
39391
  }
39995
- return normalizePrimitiveAttribute(value, false);
39392
+ exit() { }
39996
39393
  }
39997
- function normalizePrimitiveAttribute(value, forceString) {
39998
- if (!forceString) {
39999
- if (typeof value === 'string' ||
40000
- typeof value === 'number' ||
40001
- typeof value === 'boolean') {
40002
- return value;
40003
- }
40004
- if (value instanceof Date) {
40005
- return value.toISOString();
40006
- }
40007
- }
40008
- if (value instanceof Date) {
40009
- return value.toISOString();
40010
- }
40011
- if (typeof value === 'boolean') {
40012
- return value;
40013
- }
40014
- if (!forceString && typeof value === 'number') {
40015
- return value;
39394
+ class NoopTraceEmitter extends BaseTraceEmitter {
39395
+ startSpan(_name, _options) {
39396
+ void _options;
39397
+ return new NoopTraceSpanScope(new NoopTraceSpan());
40016
39398
  }
40017
- return String(value);
40018
39399
  }
40019
- function normalizeAttributes(source) {
40020
- if (!source) {
40021
- return undefined;
39400
+
39401
+ const FACTORY_META$2 = {
39402
+ base: TRACE_EMITTER_FACTORY_BASE_TYPE,
39403
+ key: 'NoopTraceEmitter',
39404
+ };
39405
+ class NoopTraceEmitterFactory extends TraceEmitterFactory {
39406
+ constructor() {
39407
+ super(...arguments);
39408
+ this.type = 'NoopTraceEmitter';
39409
+ this.isDefault = true;
39410
+ this.priority = 100;
40022
39411
  }
40023
- const entries = [];
40024
- for (const [key, raw] of Object.entries(source)) {
40025
- entries.push([key, normalizeAttributeValue(raw)]);
39412
+ async create() {
39413
+ return new NoopTraceEmitter();
40026
39414
  }
40027
- return entries.length > 0 ? Object.fromEntries(entries) : undefined;
40028
39415
  }
40029
39416
 
40030
- var openTelemetryTraceEmitter = /*#__PURE__*/Object.freeze({
39417
+ var noopTraceEmitterFactory = /*#__PURE__*/Object.freeze({
40031
39418
  __proto__: null,
40032
- OpenTelemetryTraceEmitter: OpenTelemetryTraceEmitter
39419
+ FACTORY_META: FACTORY_META$2,
39420
+ NoopTraceEmitterFactory: NoopTraceEmitterFactory,
39421
+ default: NoopTraceEmitterFactory
40033
39422
  });
40034
39423
 
40035
- const logger$5 = getLogger('naylence.fame.telemetry.otel_setup');
40036
- const stringFrom = (...codes) => String.fromCharCode(...codes);
40037
- const OTEL_PREFIX = `${stringFrom(64, 111, 112, 101, 110, 116, 101, 108, 101, 109, 101, 116, 114, 121)}${stringFrom(47)}`;
40038
- const OTEL_API_SPEC = `${OTEL_PREFIX}${stringFrom(97, 112, 105)}`;
40039
- const OTEL_RESOURCES_SPEC = `${OTEL_PREFIX}${stringFrom(114, 101, 115, 111, 117, 114, 99, 101, 115)}`;
40040
- const OTEL_TRACE_NODE_SPEC = `${OTEL_PREFIX}${stringFrom(115, 100, 107, 45, 116, 114, 97, 99, 101, 45, 110, 111, 100, 101)}`;
40041
- const OTEL_TRACE_BASE_SPEC = `${OTEL_PREFIX}${stringFrom(115, 100, 107, 45, 116, 114, 97, 99, 101, 45, 98, 97, 115, 101)}`;
40042
- const OTEL_EXPORTER_HTTP_SPEC = `${OTEL_PREFIX}${stringFrom(101, 120, 112, 111, 114, 116, 101, 114, 45, 116, 114, 97, 99, 101, 45, 111, 116, 108, 112, 45, 104, 116, 116, 112)}`;
40043
- let registeredOtel = null;
40044
- async function setupOtel(options) {
40045
- const normalized = normalizeSetupOtelOptions(options);
40046
- try {
40047
- if (registeredOtel) {
40048
- logger$5.debug('open_telemetry_reusing_provider', {
40049
- service_name: normalized.serviceName,
40050
- });
40051
- return registeredOtel.control;
40052
- }
40053
- const [apiModule, resourcesModule, nodeModule, traceBaseModule] = await Promise.all([
40054
- import(OTEL_API_SPEC),
40055
- import(OTEL_RESOURCES_SPEC),
40056
- import(OTEL_TRACE_NODE_SPEC),
40057
- import(OTEL_TRACE_BASE_SPEC),
40058
- ]);
40059
- const { trace } = apiModule;
40060
- const { defaultResource, resourceFromAttributes } = resourcesModule;
40061
- const { NodeTracerProvider } = nodeModule;
40062
- const { BatchSpanProcessor, ConsoleSpanExporter, ParentBasedSampler, AlwaysOnSampler, AlwaysOffSampler, TraceIdRatioBasedSampler, } = traceBaseModule;
40063
- const currentProvider = trace.getTracerProvider();
40064
- if (currentProvider && currentProvider instanceof NodeTracerProvider) {
40065
- return null;
40066
- }
40067
- if (currentProvider &&
40068
- currentProvider.constructor?.name === 'NodeTracerProvider') {
40069
- logger$5.debug('open_telemetry_existing_node_provider', {
40070
- service_name: normalized.serviceName,
40071
- });
40072
- return null;
40073
- }
40074
- logger$5.debug('open_telemetry_initializing', {
40075
- service_name: normalized.serviceName,
40076
- endpoint: normalized.endpoint ?? null,
40077
- environment: normalized.environment ?? null,
40078
- sampler: normalized.sampler ?? null,
40079
- headers_present: Boolean(normalized.headers && Object.keys(normalized.headers).length),
40080
- });
40081
- const sampler = resolveSampler(normalized.sampler, {
40082
- ParentBasedSampler,
40083
- AlwaysOnSampler,
40084
- AlwaysOffSampler,
40085
- TraceIdRatioBasedSampler,
40086
- });
40087
- const baseResource = defaultResource();
40088
- const mergedResource = resourceFromAttributes({
40089
- 'service.name': normalized.serviceName,
40090
- 'service.instance.id': generateInstanceId(),
40091
- 'deployment.environment': normalized.environment ?? 'dev',
39424
+ let openTelemetryTraceEmitterModulePromise = null;
39425
+ let otelApiModulePromise = null;
39426
+ let otelSetupModulePromise = null;
39427
+ const logger$7 = getLogger('naylence.fame.telemetry.open_telemetry_trace_emitter_factory');
39428
+ const MISSING_OTEL_HELP_MESSAGE = 'Missing optional OpenTelemetry dependency. Install @opentelemetry/api (and related packages) to enable trace emission.';
39429
+ function getOpenTelemetryTraceEmitterModule() {
39430
+ if (!openTelemetryTraceEmitterModulePromise) {
39431
+ openTelemetryTraceEmitterModulePromise = safeImport(() => Promise.resolve().then(function () { return openTelemetryTraceEmitter; }), '@opentelemetry/api', {
39432
+ helpMessage: MISSING_OTEL_HELP_MESSAGE,
40092
39433
  });
40093
- const resource = baseResource.merge(mergedResource);
40094
- const exporter = await resolveExporter(normalized.endpoint ?? undefined, normalized.headers, ConsoleSpanExporter);
40095
- const spanProcessor = new BatchSpanProcessor(exporter);
40096
- const provider = new NodeTracerProvider({
40097
- resource,
40098
- sampler,
40099
- spanProcessors: [spanProcessor],
39434
+ }
39435
+ return openTelemetryTraceEmitterModulePromise;
39436
+ }
39437
+ function getOtelApiModule() {
39438
+ if (!otelApiModulePromise) {
39439
+ otelApiModulePromise = safeImport(() => import('@opentelemetry/api'), '@opentelemetry/api', {
39440
+ helpMessage: MISSING_OTEL_HELP_MESSAGE,
40100
39441
  });
40101
- provider.register();
40102
- logger$5.debug('open_telemetry_initialized', {
40103
- service_name: normalized.serviceName,
40104
- exporter: exporter.constructor?.name ?? 'unknown_exporter',
39442
+ }
39443
+ return otelApiModulePromise;
39444
+ }
39445
+ function getOtelSetupModule() {
39446
+ if (!otelSetupModulePromise) {
39447
+ otelSetupModulePromise = safeImport(() => Promise.resolve().then(function () { return otelSetup; }), '@opentelemetry/api', {
39448
+ helpMessage: MISSING_OTEL_HELP_MESSAGE,
40105
39449
  });
40106
- const control = {
40107
- forceFlush: async () => {
39450
+ }
39451
+ return otelSetupModulePromise;
39452
+ }
39453
+ const FACTORY_META$1 = {
39454
+ base: TRACE_EMITTER_FACTORY_BASE_TYPE,
39455
+ key: 'OpenTelemetryTraceEmitter',
39456
+ };
39457
+ class OpenTelemetryTraceEmitterFactory extends TraceEmitterFactory {
39458
+ constructor() {
39459
+ super(...arguments);
39460
+ this.type = 'OpenTelemetryTraceEmitter';
39461
+ }
39462
+ async create(config, ...factoryArgs) {
39463
+ const options = (factoryArgs[0] ??
39464
+ {});
39465
+ const normalized = normalizeConfig$1(config);
39466
+ const mergedHeaders = {
39467
+ ...normalized.headers,
39468
+ ...(options.headers ?? {}),
39469
+ };
39470
+ let authStrategy = null;
39471
+ if (normalized.auth) {
39472
+ authStrategy =
39473
+ await AuthInjectionStrategyFactory.createAuthInjectionStrategy(normalized.auth);
39474
+ try {
39475
+ await authStrategy.apply(mergedHeaders);
39476
+ logger$7.info('trace_emitter_auth_applied', {
39477
+ service_name: normalized.serviceName,
39478
+ });
39479
+ }
39480
+ catch (error) {
40108
39481
  try {
40109
- await provider.forceFlush();
39482
+ await authStrategy.cleanup();
40110
39483
  }
40111
- catch (flushError) {
40112
- logger$5.warning('open_telemetry_force_flush_failed', {
40113
- error: flushError instanceof Error
40114
- ? flushError.message
40115
- : String(flushError),
40116
- });
39484
+ catch {
39485
+ // Ignore cleanup errors while propagating original failure
40117
39486
  }
40118
- },
40119
- shutdown: async () => {
39487
+ throw error;
39488
+ }
39489
+ }
39490
+ let lifecycle = null;
39491
+ try {
39492
+ const { setupOtel } = await getOtelSetupModule();
39493
+ lifecycle = await setupOtel({
39494
+ serviceName: normalized.serviceName,
39495
+ endpoint: normalized.endpoint,
39496
+ environment: normalized.environment,
39497
+ sampler: normalized.sampler,
39498
+ headers: Object.keys(mergedHeaders).length > 0 ? mergedHeaders : undefined,
39499
+ });
39500
+ logger$7.debug('trace_emitter_lifecycle_acquired', {
39501
+ service_name: normalized.serviceName,
39502
+ lifecycle_available: Boolean(lifecycle),
39503
+ });
39504
+ }
39505
+ catch (error) {
39506
+ if (authStrategy) {
40120
39507
  try {
40121
- await provider.shutdown();
40122
- }
40123
- catch (shutdownError) {
40124
- logger$5.warning('open_telemetry_shutdown_failed', {
40125
- error: shutdownError instanceof Error
40126
- ? shutdownError.message
40127
- : String(shutdownError),
40128
- });
39508
+ await authStrategy.cleanup();
40129
39509
  }
40130
- finally {
40131
- registeredOtel = null;
39510
+ catch {
39511
+ // Ignore cleanup errors while propagating original failure
40132
39512
  }
39513
+ }
39514
+ throw error;
39515
+ }
39516
+ const [{ OpenTelemetryTraceEmitter }, otelModule] = await Promise.all([
39517
+ getOpenTelemetryTraceEmitterModule(),
39518
+ getOtelApiModule(),
39519
+ ]);
39520
+ const emitterOptions = {
39521
+ serviceName: normalized.serviceName,
39522
+ otelApi: {
39523
+ trace: otelModule.trace,
39524
+ SpanStatusCode: otelModule.SpanStatusCode,
40133
39525
  },
40134
39526
  };
40135
- registeredOtel = {
40136
- provider,
40137
- control,
40138
- };
40139
- return control;
40140
- }
40141
- catch (error) {
40142
- logger$5.error('open_telemetry_not_available', {
40143
- error: error instanceof Error ? error.message : String(error),
40144
- stack: error instanceof Error && error.stack ? error.stack : undefined,
40145
- });
40146
- return null;
39527
+ if (options.tracer) {
39528
+ emitterOptions.tracer = options.tracer;
39529
+ }
39530
+ if (lifecycle) {
39531
+ emitterOptions.lifecycle = lifecycle;
39532
+ }
39533
+ if (authStrategy) {
39534
+ emitterOptions.authStrategy = authStrategy;
39535
+ }
39536
+ try {
39537
+ const emitter = new OpenTelemetryTraceEmitter(emitterOptions);
39538
+ logger$7.debug('trace_emitter_created', {
39539
+ service_name: normalized.serviceName,
39540
+ has_lifecycle: Boolean(lifecycle),
39541
+ has_auth_strategy: Boolean(authStrategy),
39542
+ });
39543
+ return emitter;
39544
+ }
39545
+ catch (error) {
39546
+ if (authStrategy) {
39547
+ try {
39548
+ await authStrategy.cleanup();
39549
+ }
39550
+ catch {
39551
+ // Best effort cleanup
39552
+ }
39553
+ }
39554
+ throw error;
39555
+ }
40147
39556
  }
40148
39557
  }
40149
- function normalizeSetupOtelOptions(options) {
40150
- const source = (options ?? {});
40151
- const serviceName = extractNonEmptyString(pickFirst(source, ['serviceName', 'service_name'])) ??
39558
+ function normalizeConfig$1(config) {
39559
+ if (!config) {
39560
+ return {
39561
+ serviceName: 'naylence-service',
39562
+ endpoint: null,
39563
+ environment: null,
39564
+ sampler: null,
39565
+ headers: {},
39566
+ auth: null,
39567
+ };
39568
+ }
39569
+ const candidate = config;
39570
+ const serviceName = extractString(pickFirst$2(candidate, ['serviceName', 'service_name'])) ??
40152
39571
  'naylence-service';
40153
- const endpoint = extractNonEmptyString(pickFirst(source, ['endpoint', 'otlpEndpoint', 'otlp_endpoint'])) ?? null;
40154
- const environment = extractNonEmptyString(pickFirst(source, [
39572
+ const endpoint = extractString(pickFirst$2(candidate, ['endpoint', 'otlpEndpoint', 'otlp_endpoint'])) ?? null;
39573
+ const environment = extractString(pickFirst$2(candidate, [
40155
39574
  'environment',
40156
39575
  'deploymentEnvironment',
40157
39576
  'deployment_environment',
40158
39577
  ])) ?? null;
40159
- const sampler = extractNonEmptyString(pickFirst(source, ['sampler', 'samplingStrategy', 'sampling_strategy'])) ?? null;
40160
- const headers = extractHeaders(pickFirst(source, ['headers', 'otlpHeaders', 'otlp_headers']));
39578
+ const sampler = extractString(pickFirst$2(candidate, ['sampler', 'samplingStrategy', 'sampling_strategy'])) ?? null;
39579
+ const headersFromConfig = extractHeaders$1(pickFirst$2(candidate, ['headers', 'otlpHeaders', 'otlp_headers']));
39580
+ const authConfig = pickFirst$2(candidate, [
39581
+ 'auth',
39582
+ ]);
40161
39583
  return {
40162
39584
  serviceName,
40163
39585
  endpoint,
40164
39586
  environment,
40165
39587
  sampler,
40166
- headers: headers ?? undefined,
39588
+ headers: headersFromConfig ?? {},
39589
+ auth: authConfig ?? null,
40167
39590
  };
40168
39591
  }
40169
- function pickFirst(source, keys) {
39592
+ function extractString(value) {
39593
+ if (typeof value === 'string' && value.trim().length > 0) {
39594
+ return value;
39595
+ }
39596
+ return undefined;
39597
+ }
39598
+ function pickFirst$2(source, keys) {
40170
39599
  for (const key of keys) {
40171
39600
  if (Object.prototype.hasOwnProperty.call(source, key)) {
40172
39601
  const value = source[key];
@@ -40177,16 +39606,7 @@ function pickFirst(source, keys) {
40177
39606
  }
40178
39607
  return undefined;
40179
39608
  }
40180
- function extractNonEmptyString(value) {
40181
- if (typeof value === 'string') {
40182
- const trimmed = value.trim();
40183
- if (trimmed.length > 0) {
40184
- return trimmed;
40185
- }
40186
- }
40187
- return undefined;
40188
- }
40189
- function extractHeaders(value) {
39609
+ function extractHeaders$1(value) {
40190
39610
  if (!value || typeof value !== 'object') {
40191
39611
  return null;
40192
39612
  }
@@ -40198,76 +39618,145 @@ function extractHeaders(value) {
40198
39618
  }
40199
39619
  return Object.keys(headers).length > 0 ? headers : null;
40200
39620
  }
40201
- function generateInstanceId() {
40202
- try {
40203
- if (typeof crypto !== 'undefined' &&
40204
- typeof crypto.randomUUID === 'function') {
40205
- return crypto.randomUUID().replace(/-/g, '');
40206
- }
39621
+
39622
+ var openTelemetryTraceEmitterFactory = /*#__PURE__*/Object.freeze({
39623
+ __proto__: null,
39624
+ FACTORY_META: FACTORY_META$1,
39625
+ OpenTelemetryTraceEmitterFactory: OpenTelemetryTraceEmitterFactory,
39626
+ default: OpenTelemetryTraceEmitterFactory
39627
+ });
39628
+
39629
+ const logger$6 = getLogger('naylence.fame.telemetry.trace_emitter_profile_factory');
39630
+ const PROFILE_NAME_NOOP = 'noop';
39631
+ const PROFILE_NAME_OPEN_TELEMETRY = 'open-telemetry';
39632
+ const ENV_VAR_TELEMETRY_SERVICE_NAME = 'FAME_TELEMETRY_SERVICE_NAME';
39633
+ const NOOP_PROFILE = {
39634
+ type: 'NoopTraceEmitter',
39635
+ };
39636
+ const OPEN_TELEMETRY_PROFILE = {
39637
+ type: 'OpenTelemetryTraceEmitter',
39638
+ serviceName: Expressions.env(ENV_VAR_TELEMETRY_SERVICE_NAME, 'naylence-service'),
39639
+ headers: {},
39640
+ };
39641
+ const PROFILE_MAP = {
39642
+ [PROFILE_NAME_NOOP]: NOOP_PROFILE,
39643
+ [PROFILE_NAME_OPEN_TELEMETRY]: OPEN_TELEMETRY_PROFILE,
39644
+ };
39645
+ const FACTORY_META = {
39646
+ base: TRACE_EMITTER_FACTORY_BASE_TYPE,
39647
+ key: 'TraceEmitterProfile',
39648
+ };
39649
+ class TraceEmitterProfileFactory extends TraceEmitterFactory {
39650
+ constructor() {
39651
+ super(...arguments);
39652
+ this.type = 'TraceEmitterProfile';
40207
39653
  }
40208
- catch {
40209
- // Ignore crypto availability errors
39654
+ async create(config, ...factoryArgs) {
39655
+ const normalized = normalizeTraceEmitterProfileConfig(config);
39656
+ const profileConfig = resolveProfileConfig(normalized.profile);
39657
+ logger$6.debug('enabling_trace_emitter_profile', {
39658
+ profile: normalized.profile,
39659
+ });
39660
+ const traceEmitter = await TraceEmitterFactory.createTraceEmitter(profileConfig, {
39661
+ factoryArgs,
39662
+ });
39663
+ if (!traceEmitter) {
39664
+ throw new Error(`Failed to instantiate trace emitter profile: ${normalized.profile}`);
39665
+ }
39666
+ return traceEmitter;
40210
39667
  }
40211
- const random = Math.random().toString(16).slice(2);
40212
- return random.padEnd(32, '0').slice(0, 32);
40213
39668
  }
40214
- function resolveSampler(samplerSetting, samplers) {
40215
- const normalized = (samplerSetting ?? 'parentbased_always_on').toLowerCase();
40216
- let base;
40217
- if (normalized === 'always_off') {
40218
- base = new samplers.AlwaysOffSampler();
39669
+ function normalizeTraceEmitterProfileConfig(config) {
39670
+ if (!config) {
39671
+ return { profile: PROFILE_NAME_NOOP };
40219
39672
  }
40220
- else if (normalized === 'always_on' ||
40221
- normalized === 'parentbased_always_on') {
40222
- base = new samplers.AlwaysOnSampler();
39673
+ const candidate = config;
39674
+ const profileValue = resolveProfileName(candidate);
39675
+ const canonicalProfile = canonicalizeProfileName(profileValue);
39676
+ candidate.profile = canonicalProfile;
39677
+ return { profile: canonicalProfile };
39678
+ }
39679
+ function resolveProfileName(candidate) {
39680
+ const direct = coerceProfileString(candidate.profile);
39681
+ if (direct) {
39682
+ return direct;
40223
39683
  }
40224
- else if (normalized.startsWith('ratio:')) {
40225
- const ratioValue = Number.parseFloat(normalized.slice('ratio:'.length));
40226
- const ratio = Number.isFinite(ratioValue)
40227
- ? Math.min(Math.max(ratioValue, 0), 1)
40228
- : 1;
40229
- base = new samplers.TraceIdRatioBasedSampler(ratio);
39684
+ const legacyKeys = ['profile_name', 'profileName'];
39685
+ for (const legacyKey of legacyKeys) {
39686
+ const legacyValue = coerceProfileString(candidate[legacyKey]);
39687
+ if (legacyValue) {
39688
+ return legacyValue;
39689
+ }
40230
39690
  }
40231
- else {
40232
- base = new samplers.AlwaysOnSampler();
39691
+ return PROFILE_NAME_NOOP;
39692
+ }
39693
+ function coerceProfileString(value) {
39694
+ if (typeof value !== 'string') {
39695
+ return null;
40233
39696
  }
40234
- return new samplers.ParentBasedSampler({ root: base });
39697
+ const trimmed = value.trim();
39698
+ return trimmed.length > 0 ? trimmed : null;
40235
39699
  }
40236
- async function resolveExporter(endpoint, headers, ConsoleSpanExporter) {
40237
- if (endpoint) {
40238
- try {
40239
- const exporterModule = await import(OTEL_EXPORTER_HTTP_SPEC);
40240
- if ('OTLPTraceExporter' in exporterModule) {
40241
- const { OTLPTraceExporter } = exporterModule;
40242
- const exporterOptions = {
40243
- url: endpoint,
40244
- };
40245
- if (headers && Object.keys(headers).length > 0) {
40246
- exporterOptions.headers = headers;
40247
- }
40248
- logger$5.debug('open_telemetry_using_otlp_http_exporter', {
40249
- endpoint,
40250
- headers_present: Boolean(headers && Object.keys(headers).length),
40251
- });
40252
- return new OTLPTraceExporter(exporterOptions);
40253
- }
40254
- }
40255
- catch (error) {
40256
- logger$5.error('open_telemetry_exporter_not_available', {
40257
- error: error instanceof Error ? error.message : String(error),
40258
- });
40259
- }
39700
+ const PROFILE_ALIASES = {
39701
+ noop: PROFILE_NAME_NOOP,
39702
+ 'no-op': PROFILE_NAME_NOOP,
39703
+ no_op: PROFILE_NAME_NOOP,
39704
+ 'open-telemetry': PROFILE_NAME_OPEN_TELEMETRY,
39705
+ open_telemetry: PROFILE_NAME_OPEN_TELEMETRY,
39706
+ opentelemetry: PROFILE_NAME_OPEN_TELEMETRY,
39707
+ };
39708
+ function canonicalizeProfileName(value) {
39709
+ const normalized = value.replace(/[\s_]+/g, '-').toLowerCase();
39710
+ return PROFILE_ALIASES[normalized] ?? normalized;
39711
+ }
39712
+ function resolveProfileConfig(profileName) {
39713
+ const profile = PROFILE_MAP[profileName];
39714
+ if (!profile) {
39715
+ throw new Error(`Unknown trace emitter profile: ${profileName}`);
40260
39716
  }
40261
- logger$5.warning('open_telemetry_falling_back_to_console_exporter');
40262
- return new ConsoleSpanExporter();
39717
+ return deepClone(profile);
39718
+ }
39719
+ function deepClone(value) {
39720
+ return JSON.parse(JSON.stringify(value));
40263
39721
  }
40264
39722
 
40265
- var otelSetup = /*#__PURE__*/Object.freeze({
39723
+ var traceEmitterProfileFactory = /*#__PURE__*/Object.freeze({
40266
39724
  __proto__: null,
40267
- setupOtel: setupOtel
39725
+ FACTORY_META: FACTORY_META,
39726
+ PROFILE_NAME_NOOP: PROFILE_NAME_NOOP,
39727
+ PROFILE_NAME_OPEN_TELEMETRY: PROFILE_NAME_OPEN_TELEMETRY,
39728
+ TraceEmitterProfileFactory: TraceEmitterProfileFactory,
39729
+ default: TraceEmitterProfileFactory
40268
39730
  });
40269
39731
 
40270
- const logger$4 = getLogger('naylence.fame.security.auth.default_authorizer');
39732
+ let initialized = false;
39733
+ const runtimePlugin = {
39734
+ name: 'naylence:runtime',
39735
+ version: VERSION,
39736
+ async register() {
39737
+ // console.log('[naylence:runtime] register() called, initialized=', initialized);
39738
+ if (initialized) {
39739
+ // console.log('[naylence:runtime] already initialized, skipping');
39740
+ return;
39741
+ }
39742
+ initialized = true;
39743
+ // console.log('[naylence:runtime] registering runtime factories...');
39744
+ // Register factories from manifest
39745
+ await registerRuntimeFactories();
39746
+ // Import modules with side-effect registrations (not in manifest)
39747
+ await Promise.resolve().then(function () { return websocketTransportProvisioner; });
39748
+ // console.log('[naylence:runtime] runtime factories registered');
39749
+ },
39750
+ };
39751
+ const RUNTIME_PLUGIN_SPECIFIER = runtimePlugin.name;
39752
+
39753
+ var plugin = /*#__PURE__*/Object.freeze({
39754
+ __proto__: null,
39755
+ RUNTIME_PLUGIN_SPECIFIER: RUNTIME_PLUGIN_SPECIFIER,
39756
+ default: runtimePlugin
39757
+ });
39758
+
39759
+ const logger$5 = getLogger('naylence.fame.security.auth.default_authorizer');
40271
39760
  function decodeCredentials$1(credentials) {
40272
39761
  if (typeof TextDecoder !== 'undefined') {
40273
39762
  return new TextDecoder().decode(credentials);
@@ -40401,7 +39890,7 @@ class DefaultAuthorizer {
40401
39890
  });
40402
39891
  }
40403
39892
  catch (error) {
40404
- logger$4.warning('token_verification_failed', {
39893
+ logger$5.warning('token_verification_failed', {
40405
39894
  error: error instanceof Error ? error.message : String(error),
40406
39895
  });
40407
39896
  return undefined;
@@ -40492,7 +39981,7 @@ var defaultAuthorizer = /*#__PURE__*/Object.freeze({
40492
39981
  DefaultAuthorizer: DefaultAuthorizer
40493
39982
  });
40494
39983
 
40495
- const logger$3 = getLogger('naylence.fame.security.auth.jwks_jwt_token_verifier');
39984
+ const logger$4 = getLogger('naylence.fame.security.auth.jwks_jwt_token_verifier');
40496
39985
  const DEFAULT_ALGORITHMS = ['RS256', 'ES256', 'EdDSA'];
40497
39986
  function normalizeOptions$5(options) {
40498
39987
  if (!options || typeof options !== 'object') {
@@ -40542,7 +40031,7 @@ class JWKSJWTTokenVerifier {
40542
40031
  this.algorithms = (normalized.algorithms && normalized.algorithms.length > 0
40543
40032
  ? normalized.algorithms
40544
40033
  : Array.from(DEFAULT_ALGORITHMS)).map((alg) => alg.toString().trim());
40545
- logger$3.debug('jwks_jwt_token_verifier_initialized', {
40034
+ logger$4.debug('jwks_jwt_token_verifier_initialized', {
40546
40035
  issuer: this.issuer,
40547
40036
  jwks_url: this.jwksUrl.toString(),
40548
40037
  cache_ttl_ms: this.cacheTtlMs,
@@ -40564,7 +40053,7 @@ class JWKSJWTTokenVerifier {
40564
40053
  return buildAuthorizationContext$1(payload, protectedHeader?.kid);
40565
40054
  }
40566
40055
  catch (error) {
40567
- logger$3.warning('jwks_jwt_token_verifier_failed', {
40056
+ logger$4.warning('jwks_jwt_token_verifier_failed', {
40568
40057
  error: error instanceof Error ? error.message : String(error),
40569
40058
  });
40570
40059
  throw this.normalizeJoseError(error);
@@ -40615,7 +40104,7 @@ var jwksJwtTokenVerifier = /*#__PURE__*/Object.freeze({
40615
40104
  JWKSJWTTokenVerifier: JWKSJWTTokenVerifier
40616
40105
  });
40617
40106
 
40618
- const logger$2 = getLogger('naylence.fame.security.auth.oauth2_authorizer');
40107
+ const logger$3 = getLogger('naylence.fame.security.auth.oauth2_authorizer');
40619
40108
  function normalizeOptions$4(raw) {
40620
40109
  const camel = raw;
40621
40110
  const snake = raw;
@@ -40680,12 +40169,12 @@ class OAuth2Authorizer {
40680
40169
  async authenticate(credentials) {
40681
40170
  const token = this.normalizeBearerToken(credentials);
40682
40171
  if (!token) {
40683
- logger$2.debug('oauth2_authenticate_missing_token');
40172
+ logger$3.debug('oauth2_authenticate_missing_token');
40684
40173
  return undefined;
40685
40174
  }
40686
40175
  try {
40687
40176
  const expectedAudience = this.audience ?? this.node?.physicalPath;
40688
- logger$2.debug('oauth2_authenticate_start', {
40177
+ logger$3.debug('oauth2_authenticate_start', {
40689
40178
  expected_audience: expectedAudience,
40690
40179
  });
40691
40180
  const context = expectedAudience !== undefined
@@ -40697,7 +40186,7 @@ class OAuth2Authorizer {
40697
40186
  if (this.requireScope &&
40698
40187
  this.requiredScopes.size > 0 &&
40699
40188
  !this.hasRequiredScope(grantedScopes)) {
40700
- logger$2.warning('oauth2_token_missing_required_scope', {
40189
+ logger$3.warning('oauth2_token_missing_required_scope', {
40701
40190
  required_scopes: Array.from(this.requiredScopes),
40702
40191
  token_scopes: Array.from(scopes),
40703
40192
  });
@@ -40711,13 +40200,13 @@ class OAuth2Authorizer {
40711
40200
  grantedScopes,
40712
40201
  authMethod: context.authMethod ?? 'oauth2_jwt',
40713
40202
  });
40714
- logger$2.debug('oauth2_authenticate_success', {
40203
+ logger$3.debug('oauth2_authenticate_success', {
40715
40204
  granted_scopes: Array.from(grantedScopes),
40716
40205
  });
40717
40206
  return normalized;
40718
40207
  }
40719
40208
  catch (error) {
40720
- logger$2.warning('oauth2_token_verification_failed', {
40209
+ logger$3.warning('oauth2_token_verification_failed', {
40721
40210
  error: error instanceof Error ? error.message : String(error),
40722
40211
  });
40723
40212
  return undefined;
@@ -40759,7 +40248,7 @@ class OAuth2Authorizer {
40759
40248
  instance_id: node.instanceId ?? null,
40760
40249
  capabilities: Array.from(this.requiredScopes),
40761
40250
  });
40762
- logger$2.debug('reverse_authorization_token_generated', {
40251
+ logger$3.debug('reverse_authorization_token_generated', {
40763
40252
  node_id: node.id,
40764
40253
  expires_at: expiresAt.toISOString(),
40765
40254
  capabilities: Array.from(this.requiredScopes),
@@ -40776,7 +40265,7 @@ class OAuth2Authorizer {
40776
40265
  return result;
40777
40266
  }
40778
40267
  catch (error) {
40779
- logger$2.warning('failed_to_generate_reverse_auth_token', {
40268
+ logger$3.warning('failed_to_generate_reverse_auth_token', {
40780
40269
  node_id: node.id,
40781
40270
  error: error instanceof Error ? error.message : String(error),
40782
40271
  });
@@ -40793,7 +40282,7 @@ class OAuth2Authorizer {
40793
40282
  if (this.requireScope &&
40794
40283
  this.requiredScopes.size > 0 &&
40795
40284
  !this.hasRequiredScope(grantedScopes)) {
40796
- logger$2.warning('oauth2_attach_missing_required_scope', {
40285
+ logger$3.warning('oauth2_attach_missing_required_scope', {
40797
40286
  required_scopes: Array.from(this.requiredScopes),
40798
40287
  token_scopes: Array.from(scopes),
40799
40288
  });
@@ -40883,7 +40372,7 @@ var oauth2Authorizer = /*#__PURE__*/Object.freeze({
40883
40372
  OAuth2Authorizer: OAuth2Authorizer
40884
40373
  });
40885
40374
 
40886
- const logger$1 = getLogger('naylence.fame.security.auth.oauth2_client_credentials_token_provider');
40375
+ const logger$2 = getLogger('naylence.fame.security.auth.oauth2_client_credentials_token_provider');
40887
40376
  function normalizeOptions$3(raw) {
40888
40377
  const camel = raw;
40889
40378
  const snake = raw;
@@ -40949,7 +40438,7 @@ class OAuth2ClientCredentialsTokenProvider {
40949
40438
  }
40950
40439
  async getToken() {
40951
40440
  if (this.cachedToken && this.isTokenFresh(this.cachedToken)) {
40952
- logger$1.debug('using_cached_oauth2_token', {
40441
+ logger$2.debug('using_cached_oauth2_token', {
40953
40442
  token_url: this.options.tokenUrl,
40954
40443
  });
40955
40444
  return { ...this.cachedToken };
@@ -41004,7 +40493,7 @@ class OAuth2ClientCredentialsTokenProvider {
41004
40493
  }
41005
40494
  const expiresInSeconds = this.resolveExpiresIn(payload);
41006
40495
  const expiresAt = Date.now() + expiresInSeconds * 1000;
41007
- logger$1.debug('oauth2_token_fetched', {
40496
+ logger$2.debug('oauth2_token_fetched', {
41008
40497
  token_url: this.options.tokenUrl,
41009
40498
  scopes: this.options.scopes,
41010
40499
  audience: this.options.audience,
@@ -41039,7 +40528,7 @@ var oauth2ClientCredentialsTokenProvider = /*#__PURE__*/Object.freeze({
41039
40528
  OAuth2ClientCredentialsTokenProvider: OAuth2ClientCredentialsTokenProvider
41040
40529
  });
41041
40530
 
41042
- const logger = getLogger('naylence.fame.security.auth.oauth2_pkce_token_provider');
40531
+ const logger$1 = getLogger('naylence.fame.security.auth.oauth2_pkce_token_provider');
41043
40532
  const DEFAULT_SCOPES = [];
41044
40533
  const DEFAULT_CLOCK_SKEW_SECONDS = 30;
41045
40534
  const DEFAULT_CODE_VERIFIER_LENGTH = 48; // bytes before base64url encoding
@@ -41214,7 +40703,7 @@ function readPendingAuthorization(clientId) {
41214
40703
  return parsed;
41215
40704
  }
41216
40705
  catch (error) {
41217
- logger.debug('pkce_storage_read_failed', {
40706
+ logger$1.debug('pkce_storage_read_failed', {
41218
40707
  error: error instanceof Error ? error.message : String(error),
41219
40708
  });
41220
40709
  return null;
@@ -41233,7 +40722,7 @@ function writePendingAuthorization(clientId, pending) {
41233
40722
  window.sessionStorage.setItem(key, JSON.stringify(pending));
41234
40723
  }
41235
40724
  catch (error) {
41236
- logger.debug('pkce_storage_write_failed', {
40725
+ logger$1.debug('pkce_storage_write_failed', {
41237
40726
  error: error instanceof Error ? error.message : String(error),
41238
40727
  });
41239
40728
  }
@@ -41279,7 +40768,7 @@ function clearOAuthParamsFromUrl(url) {
41279
40768
  window.history.replaceState(window.history.state, '', finalUrl);
41280
40769
  }
41281
40770
  catch (error) {
41282
- logger.debug('pkce_replace_state_failed', {
40771
+ logger$1.debug('pkce_replace_state_failed', {
41283
40772
  error: error instanceof Error ? error.message : String(error),
41284
40773
  });
41285
40774
  }
@@ -41320,7 +40809,7 @@ class OAuth2PkceTokenProvider {
41320
40809
  if (persisted) {
41321
40810
  if (this.isTokenCompatible(persisted.scopes, persisted.audience)) {
41322
40811
  if (!persisted.expiresAt || this.isTokenFresh(persisted)) {
41323
- logger.debug('using_persisted_oauth2_pkce_token', {
40812
+ logger$1.debug('using_persisted_oauth2_pkce_token', {
41324
40813
  authorize_url: this.options.authorizeUrl,
41325
40814
  });
41326
40815
  const cached = {
@@ -41341,7 +40830,7 @@ class OAuth2PkceTokenProvider {
41341
40830
  }
41342
40831
  }
41343
40832
  if (this.cachedToken && this.isTokenFresh(this.cachedToken)) {
41344
- logger.debug('using_cached_oauth2_pkce_token', {
40833
+ logger$1.debug('using_cached_oauth2_pkce_token', {
41345
40834
  authorize_url: this.options.authorizeUrl,
41346
40835
  });
41347
40836
  return { ...this.cachedToken };
@@ -41364,7 +40853,7 @@ class OAuth2PkceTokenProvider {
41364
40853
  async beginBrowserAuthorization() {
41365
40854
  const existing = readPendingAuthorization(this.options.clientId);
41366
40855
  if (existing) {
41367
- logger.debug('pkce_redirect_in_progress', {
40856
+ logger$1.debug('pkce_redirect_in_progress', {
41368
40857
  authorize_url: this.options.authorizeUrl,
41369
40858
  });
41370
40859
  this.navigate(existing.authorizeUrl);
@@ -41394,7 +40883,7 @@ class OAuth2PkceTokenProvider {
41394
40883
  };
41395
40884
  writePersistedToken(this.options.clientId, null);
41396
40885
  writePendingAuthorization(this.options.clientId, pending);
41397
- logger.debug('pkce_redirect_start', {
40886
+ logger$1.debug('pkce_redirect_start', {
41398
40887
  authorize_url: this.options.authorizeUrl,
41399
40888
  redirect_uri: this.options.redirectUri,
41400
40889
  });
@@ -41408,7 +40897,7 @@ class OAuth2PkceTokenProvider {
41408
40897
  window.location.assign(url);
41409
40898
  }
41410
40899
  catch (error) {
41411
- logger.error('pkce_navigation_failed', {
40900
+ logger$1.error('pkce_navigation_failed', {
41412
40901
  authorize_url: url,
41413
40902
  error: error instanceof Error ? error.message : String(error),
41414
40903
  });
@@ -41552,7 +41041,7 @@ class OAuth2PkceTokenProvider {
41552
41041
  value: accessToken,
41553
41042
  expiresAt: Date.now() + expiresInSeconds * 1000,
41554
41043
  };
41555
- logger.debug('oauth2_pkce_token_fetched', {
41044
+ logger$1.debug('oauth2_pkce_token_fetched', {
41556
41045
  authorize_url: this.options.authorizeUrl,
41557
41046
  token_url: this.options.tokenUrl,
41558
41047
  expires_in: expiresInSeconds,
@@ -41568,7 +41057,7 @@ class OAuth2PkceTokenProvider {
41568
41057
  clearToken() {
41569
41058
  this.cachedToken = undefined;
41570
41059
  writePersistedToken(this.options.clientId, null);
41571
- logger.debug('oauth2_pkce_token_cleared', {
41060
+ logger$1.debug('oauth2_pkce_token_cleared', {
41572
41061
  authorize_url: this.options.authorizeUrl,
41573
41062
  });
41574
41063
  }
@@ -41965,6 +41454,543 @@ var eddsaEnvelopeVerifier = /*#__PURE__*/Object.freeze({
41965
41454
  EdDSAEnvelopeVerifier: EdDSAEnvelopeVerifier
41966
41455
  });
41967
41456
 
41457
+ let currentTraceId = null;
41458
+ let currentSpanId = null;
41459
+ function getOtelTraceId() {
41460
+ return currentTraceId;
41461
+ }
41462
+ function getOtelSpanId() {
41463
+ return currentSpanId;
41464
+ }
41465
+ function setOtelTraceId(traceId) {
41466
+ const previous = currentTraceId;
41467
+ currentTraceId = traceId;
41468
+ return previous;
41469
+ }
41470
+ function setOtelSpanId(spanId) {
41471
+ const previous = currentSpanId;
41472
+ currentSpanId = spanId;
41473
+ return previous;
41474
+ }
41475
+ function resetOtelTraceId(previous) {
41476
+ currentTraceId = previous;
41477
+ }
41478
+ function resetOtelSpanId(previous) {
41479
+ currentSpanId = previous;
41480
+ }
41481
+
41482
+ class OpenTelemetryTraceSpan {
41483
+ constructor(span, api) {
41484
+ this.span = span;
41485
+ this.api = api;
41486
+ }
41487
+ setAttribute(key, value) {
41488
+ try {
41489
+ this.span.setAttribute(key, normalizeAttributeValue(value));
41490
+ }
41491
+ catch {
41492
+ // Ignore telemetry attribute errors
41493
+ }
41494
+ }
41495
+ recordException(error) {
41496
+ try {
41497
+ if (error instanceof Error) {
41498
+ this.span.recordException(error);
41499
+ }
41500
+ else {
41501
+ this.span.recordException(new Error(String(error)));
41502
+ }
41503
+ }
41504
+ catch {
41505
+ // Ignore telemetry recording errors
41506
+ }
41507
+ }
41508
+ setStatusError(description) {
41509
+ try {
41510
+ const status = {
41511
+ code: this.api.SpanStatusCode.ERROR,
41512
+ };
41513
+ if (description !== undefined) {
41514
+ status.message = description;
41515
+ }
41516
+ this.span.setStatus(status);
41517
+ }
41518
+ catch {
41519
+ // Ignore telemetry status errors
41520
+ }
41521
+ }
41522
+ }
41523
+ class OpenTelemetrySpanScope {
41524
+ constructor(span, api) {
41525
+ this.span = span;
41526
+ this.entered = false;
41527
+ this.wrapper = new OpenTelemetryTraceSpan(span, api);
41528
+ }
41529
+ enter() {
41530
+ if (!this.entered) {
41531
+ this.entered = true;
41532
+ const spanContext = this.span.spanContext();
41533
+ this.traceToken = setOtelTraceId(spanContext?.traceId ?? null);
41534
+ this.spanToken = setOtelSpanId(spanContext?.spanId ?? null);
41535
+ }
41536
+ return this.wrapper;
41537
+ }
41538
+ exit() {
41539
+ try {
41540
+ this.span.end();
41541
+ }
41542
+ catch {
41543
+ // Ignore span termination errors
41544
+ }
41545
+ finally {
41546
+ if (this.traceToken !== undefined) {
41547
+ resetOtelTraceId(this.traceToken);
41548
+ this.traceToken = undefined;
41549
+ }
41550
+ if (this.spanToken !== undefined) {
41551
+ resetOtelSpanId(this.spanToken);
41552
+ this.spanToken = undefined;
41553
+ }
41554
+ }
41555
+ }
41556
+ }
41557
+ class OpenTelemetryTraceEmitter extends BaseTraceEmitter {
41558
+ constructor(options) {
41559
+ super();
41560
+ this.shutdownInvoked = false;
41561
+ const normalized = normalizeOpenTelemetryTraceEmitterOptions(options);
41562
+ this.otelApi = normalized.otelApi;
41563
+ this.tracer =
41564
+ normalized.tracer ?? this.otelApi.trace.getTracer(normalized.serviceName);
41565
+ this.lifecycle = normalized.lifecycle ?? null;
41566
+ this.authStrategy = normalized.authStrategy ?? null;
41567
+ }
41568
+ startSpan(name, options) {
41569
+ const attributes = normalizeAttributes(options?.attributes);
41570
+ const spanOptions = {};
41571
+ if (attributes) {
41572
+ spanOptions.attributes = attributes;
41573
+ }
41574
+ if (options?.links) {
41575
+ spanOptions.links = options.links;
41576
+ }
41577
+ const span = this.tracer.startSpan(name, spanOptions);
41578
+ const envelopeTraceId = options?.attributes?.['env.trace_id'];
41579
+ if (typeof envelopeTraceId === 'string') {
41580
+ this.applyEnvelopeTraceId(span, envelopeTraceId);
41581
+ }
41582
+ return new OpenTelemetrySpanScope(span, this.otelApi);
41583
+ }
41584
+ async flush() {
41585
+ if (this.lifecycle?.forceFlush) {
41586
+ try {
41587
+ await this.lifecycle.forceFlush();
41588
+ return;
41589
+ }
41590
+ catch {
41591
+ // fall through to global flush fallback
41592
+ }
41593
+ }
41594
+ try {
41595
+ const provider = this.otelApi.trace.getTracerProvider();
41596
+ if (provider && typeof provider.forceFlush === 'function') {
41597
+ await provider.forceFlush();
41598
+ }
41599
+ }
41600
+ catch {
41601
+ // Ignore flush errors
41602
+ }
41603
+ }
41604
+ async shutdown() {
41605
+ if (this.shutdownInvoked) {
41606
+ return;
41607
+ }
41608
+ this.shutdownInvoked = true;
41609
+ const cleanupTasks = [];
41610
+ const strategy = this.authStrategy;
41611
+ if (strategy) {
41612
+ this.authStrategy = null;
41613
+ cleanupTasks.push(strategy.cleanup().catch(() => {
41614
+ // Ignore auth cleanup failures
41615
+ }));
41616
+ }
41617
+ if (this.lifecycle?.shutdown) {
41618
+ try {
41619
+ await this.lifecycle.shutdown();
41620
+ this.lifecycle = null;
41621
+ await Promise.all(cleanupTasks);
41622
+ return;
41623
+ }
41624
+ catch {
41625
+ // fall through to global shutdown fallback
41626
+ this.lifecycle = null;
41627
+ }
41628
+ }
41629
+ try {
41630
+ const provider = this.otelApi.trace.getTracerProvider();
41631
+ if (provider && typeof provider.shutdown === 'function') {
41632
+ await provider.shutdown();
41633
+ }
41634
+ }
41635
+ catch {
41636
+ // Ignore shutdown errors
41637
+ }
41638
+ finally {
41639
+ if (cleanupTasks.length > 0) {
41640
+ await Promise.all(cleanupTasks);
41641
+ }
41642
+ }
41643
+ }
41644
+ applyEnvelopeTraceId(span, envelopeTraceId) {
41645
+ try {
41646
+ const targetTraceId = this.convertEnvTraceIdToOtel(envelopeTraceId);
41647
+ const internalSpan = span;
41648
+ if (internalSpan?._spanContext) {
41649
+ internalSpan._spanContext.traceId = targetTraceId;
41650
+ }
41651
+ }
41652
+ catch {
41653
+ // Ignore trace-id coercion errors
41654
+ }
41655
+ }
41656
+ convertEnvTraceIdToOtel(envTraceId) {
41657
+ const normalized = envTraceId.slice(0, 16).padEnd(16, '0');
41658
+ let hex = '';
41659
+ for (let i = 0; i < 16; i += 1) {
41660
+ const code = normalized.charCodeAt(i);
41661
+ const byte = Number.isNaN(code) ? 0 : code & 0xff;
41662
+ hex += byte.toString(16).padStart(2, '0');
41663
+ }
41664
+ return hex;
41665
+ }
41666
+ }
41667
+ function normalizeOpenTelemetryTraceEmitterOptions(input) {
41668
+ const source = (input ?? {});
41669
+ const serviceName = extractNonEmptyString$1(pickFirst$1(source, ['serviceName', 'service_name'])) ?? 'naylence-service';
41670
+ const tracer = pickFirst$1(source, ['tracer']);
41671
+ const otelApi = pickFirst$1(source, [
41672
+ 'otelApi',
41673
+ 'otel_api',
41674
+ ]);
41675
+ if (!otelApi) {
41676
+ throw new Error('OpenTelemetryTraceEmitter requires OpenTelemetry API bindings. Provide otelApi via options.');
41677
+ }
41678
+ const lifecycle = pickFirst$1(source, [
41679
+ 'lifecycle',
41680
+ 'lifeCycle',
41681
+ 'life_cycle',
41682
+ ]) ?? null;
41683
+ const authStrategy = pickFirst$1(source, [
41684
+ 'authStrategy',
41685
+ 'auth_strategy',
41686
+ ]) ?? null;
41687
+ return {
41688
+ serviceName,
41689
+ tracer,
41690
+ otelApi,
41691
+ lifecycle,
41692
+ authStrategy,
41693
+ };
41694
+ }
41695
+ function pickFirst$1(source, keys) {
41696
+ for (const key of keys) {
41697
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
41698
+ const value = source[key];
41699
+ if (value !== undefined) {
41700
+ return value;
41701
+ }
41702
+ }
41703
+ }
41704
+ return undefined;
41705
+ }
41706
+ function extractNonEmptyString$1(value) {
41707
+ if (typeof value === 'string') {
41708
+ const trimmed = value.trim();
41709
+ if (trimmed.length > 0) {
41710
+ return trimmed;
41711
+ }
41712
+ }
41713
+ return undefined;
41714
+ }
41715
+ function normalizeAttributeValue(value) {
41716
+ if (Array.isArray(value)) {
41717
+ return value.map((item) => String(normalizePrimitiveAttribute(item, true)));
41718
+ }
41719
+ return normalizePrimitiveAttribute(value, false);
41720
+ }
41721
+ function normalizePrimitiveAttribute(value, forceString) {
41722
+ if (!forceString) {
41723
+ if (typeof value === 'string' ||
41724
+ typeof value === 'number' ||
41725
+ typeof value === 'boolean') {
41726
+ return value;
41727
+ }
41728
+ if (value instanceof Date) {
41729
+ return value.toISOString();
41730
+ }
41731
+ }
41732
+ if (value instanceof Date) {
41733
+ return value.toISOString();
41734
+ }
41735
+ if (typeof value === 'boolean') {
41736
+ return value;
41737
+ }
41738
+ if (!forceString && typeof value === 'number') {
41739
+ return value;
41740
+ }
41741
+ return String(value);
41742
+ }
41743
+ function normalizeAttributes(source) {
41744
+ if (!source) {
41745
+ return undefined;
41746
+ }
41747
+ const entries = [];
41748
+ for (const [key, raw] of Object.entries(source)) {
41749
+ entries.push([key, normalizeAttributeValue(raw)]);
41750
+ }
41751
+ return entries.length > 0 ? Object.fromEntries(entries) : undefined;
41752
+ }
41753
+
41754
+ var openTelemetryTraceEmitter = /*#__PURE__*/Object.freeze({
41755
+ __proto__: null,
41756
+ OpenTelemetryTraceEmitter: OpenTelemetryTraceEmitter
41757
+ });
41758
+
41759
+ const logger = getLogger('naylence.fame.telemetry.otel_setup');
41760
+ const stringFrom = (...codes) => String.fromCharCode(...codes);
41761
+ const OTEL_PREFIX = `${stringFrom(64, 111, 112, 101, 110, 116, 101, 108, 101, 109, 101, 116, 114, 121)}${stringFrom(47)}`;
41762
+ const OTEL_API_SPEC = `${OTEL_PREFIX}${stringFrom(97, 112, 105)}`;
41763
+ const OTEL_RESOURCES_SPEC = `${OTEL_PREFIX}${stringFrom(114, 101, 115, 111, 117, 114, 99, 101, 115)}`;
41764
+ const OTEL_TRACE_NODE_SPEC = `${OTEL_PREFIX}${stringFrom(115, 100, 107, 45, 116, 114, 97, 99, 101, 45, 110, 111, 100, 101)}`;
41765
+ const OTEL_TRACE_BASE_SPEC = `${OTEL_PREFIX}${stringFrom(115, 100, 107, 45, 116, 114, 97, 99, 101, 45, 98, 97, 115, 101)}`;
41766
+ const OTEL_EXPORTER_HTTP_SPEC = `${OTEL_PREFIX}${stringFrom(101, 120, 112, 111, 114, 116, 101, 114, 45, 116, 114, 97, 99, 101, 45, 111, 116, 108, 112, 45, 104, 116, 116, 112)}`;
41767
+ let registeredOtel = null;
41768
+ async function setupOtel(options) {
41769
+ const normalized = normalizeSetupOtelOptions(options);
41770
+ try {
41771
+ if (registeredOtel) {
41772
+ logger.debug('open_telemetry_reusing_provider', {
41773
+ service_name: normalized.serviceName,
41774
+ });
41775
+ return registeredOtel.control;
41776
+ }
41777
+ const [apiModule, resourcesModule, nodeModule, traceBaseModule] = await Promise.all([
41778
+ import(OTEL_API_SPEC),
41779
+ import(OTEL_RESOURCES_SPEC),
41780
+ import(OTEL_TRACE_NODE_SPEC),
41781
+ import(OTEL_TRACE_BASE_SPEC),
41782
+ ]);
41783
+ const { trace } = apiModule;
41784
+ const { defaultResource, resourceFromAttributes } = resourcesModule;
41785
+ const { NodeTracerProvider } = nodeModule;
41786
+ const { BatchSpanProcessor, ConsoleSpanExporter, ParentBasedSampler, AlwaysOnSampler, AlwaysOffSampler, TraceIdRatioBasedSampler, } = traceBaseModule;
41787
+ const currentProvider = trace.getTracerProvider();
41788
+ if (currentProvider && currentProvider instanceof NodeTracerProvider) {
41789
+ return null;
41790
+ }
41791
+ if (currentProvider &&
41792
+ currentProvider.constructor?.name === 'NodeTracerProvider') {
41793
+ logger.debug('open_telemetry_existing_node_provider', {
41794
+ service_name: normalized.serviceName,
41795
+ });
41796
+ return null;
41797
+ }
41798
+ logger.debug('open_telemetry_initializing', {
41799
+ service_name: normalized.serviceName,
41800
+ endpoint: normalized.endpoint ?? null,
41801
+ environment: normalized.environment ?? null,
41802
+ sampler: normalized.sampler ?? null,
41803
+ headers_present: Boolean(normalized.headers && Object.keys(normalized.headers).length),
41804
+ });
41805
+ const sampler = resolveSampler(normalized.sampler, {
41806
+ ParentBasedSampler,
41807
+ AlwaysOnSampler,
41808
+ AlwaysOffSampler,
41809
+ TraceIdRatioBasedSampler,
41810
+ });
41811
+ const baseResource = defaultResource();
41812
+ const mergedResource = resourceFromAttributes({
41813
+ 'service.name': normalized.serviceName,
41814
+ 'service.instance.id': generateInstanceId(),
41815
+ 'deployment.environment': normalized.environment ?? 'dev',
41816
+ });
41817
+ const resource = baseResource.merge(mergedResource);
41818
+ const exporter = await resolveExporter(normalized.endpoint ?? undefined, normalized.headers, ConsoleSpanExporter);
41819
+ const spanProcessor = new BatchSpanProcessor(exporter);
41820
+ const provider = new NodeTracerProvider({
41821
+ resource,
41822
+ sampler,
41823
+ spanProcessors: [spanProcessor],
41824
+ });
41825
+ provider.register();
41826
+ logger.debug('open_telemetry_initialized', {
41827
+ service_name: normalized.serviceName,
41828
+ exporter: exporter.constructor?.name ?? 'unknown_exporter',
41829
+ });
41830
+ const control = {
41831
+ forceFlush: async () => {
41832
+ try {
41833
+ await provider.forceFlush();
41834
+ }
41835
+ catch (flushError) {
41836
+ logger.warning('open_telemetry_force_flush_failed', {
41837
+ error: flushError instanceof Error
41838
+ ? flushError.message
41839
+ : String(flushError),
41840
+ });
41841
+ }
41842
+ },
41843
+ shutdown: async () => {
41844
+ try {
41845
+ await provider.shutdown();
41846
+ }
41847
+ catch (shutdownError) {
41848
+ logger.warning('open_telemetry_shutdown_failed', {
41849
+ error: shutdownError instanceof Error
41850
+ ? shutdownError.message
41851
+ : String(shutdownError),
41852
+ });
41853
+ }
41854
+ finally {
41855
+ registeredOtel = null;
41856
+ }
41857
+ },
41858
+ };
41859
+ registeredOtel = {
41860
+ provider,
41861
+ control,
41862
+ };
41863
+ return control;
41864
+ }
41865
+ catch (error) {
41866
+ logger.error('open_telemetry_not_available', {
41867
+ error: error instanceof Error ? error.message : String(error),
41868
+ stack: error instanceof Error && error.stack ? error.stack : undefined,
41869
+ });
41870
+ return null;
41871
+ }
41872
+ }
41873
+ function normalizeSetupOtelOptions(options) {
41874
+ const source = (options ?? {});
41875
+ const serviceName = extractNonEmptyString(pickFirst(source, ['serviceName', 'service_name'])) ??
41876
+ 'naylence-service';
41877
+ const endpoint = extractNonEmptyString(pickFirst(source, ['endpoint', 'otlpEndpoint', 'otlp_endpoint'])) ?? null;
41878
+ const environment = extractNonEmptyString(pickFirst(source, [
41879
+ 'environment',
41880
+ 'deploymentEnvironment',
41881
+ 'deployment_environment',
41882
+ ])) ?? null;
41883
+ const sampler = extractNonEmptyString(pickFirst(source, ['sampler', 'samplingStrategy', 'sampling_strategy'])) ?? null;
41884
+ const headers = extractHeaders(pickFirst(source, ['headers', 'otlpHeaders', 'otlp_headers']));
41885
+ return {
41886
+ serviceName,
41887
+ endpoint,
41888
+ environment,
41889
+ sampler,
41890
+ headers: headers ?? undefined,
41891
+ };
41892
+ }
41893
+ function pickFirst(source, keys) {
41894
+ for (const key of keys) {
41895
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
41896
+ const value = source[key];
41897
+ if (value !== undefined) {
41898
+ return value;
41899
+ }
41900
+ }
41901
+ }
41902
+ return undefined;
41903
+ }
41904
+ function extractNonEmptyString(value) {
41905
+ if (typeof value === 'string') {
41906
+ const trimmed = value.trim();
41907
+ if (trimmed.length > 0) {
41908
+ return trimmed;
41909
+ }
41910
+ }
41911
+ return undefined;
41912
+ }
41913
+ function extractHeaders(value) {
41914
+ if (!value || typeof value !== 'object') {
41915
+ return null;
41916
+ }
41917
+ const headers = {};
41918
+ for (const [key, raw] of Object.entries(value)) {
41919
+ if (typeof raw === 'string') {
41920
+ headers[key] = raw;
41921
+ }
41922
+ }
41923
+ return Object.keys(headers).length > 0 ? headers : null;
41924
+ }
41925
+ function generateInstanceId() {
41926
+ try {
41927
+ if (typeof crypto !== 'undefined' &&
41928
+ typeof crypto.randomUUID === 'function') {
41929
+ return crypto.randomUUID().replace(/-/g, '');
41930
+ }
41931
+ }
41932
+ catch {
41933
+ // Ignore crypto availability errors
41934
+ }
41935
+ const random = Math.random().toString(16).slice(2);
41936
+ return random.padEnd(32, '0').slice(0, 32);
41937
+ }
41938
+ function resolveSampler(samplerSetting, samplers) {
41939
+ const normalized = (samplerSetting ?? 'parentbased_always_on').toLowerCase();
41940
+ let base;
41941
+ if (normalized === 'always_off') {
41942
+ base = new samplers.AlwaysOffSampler();
41943
+ }
41944
+ else if (normalized === 'always_on' ||
41945
+ normalized === 'parentbased_always_on') {
41946
+ base = new samplers.AlwaysOnSampler();
41947
+ }
41948
+ else if (normalized.startsWith('ratio:')) {
41949
+ const ratioValue = Number.parseFloat(normalized.slice('ratio:'.length));
41950
+ const ratio = Number.isFinite(ratioValue)
41951
+ ? Math.min(Math.max(ratioValue, 0), 1)
41952
+ : 1;
41953
+ base = new samplers.TraceIdRatioBasedSampler(ratio);
41954
+ }
41955
+ else {
41956
+ base = new samplers.AlwaysOnSampler();
41957
+ }
41958
+ return new samplers.ParentBasedSampler({ root: base });
41959
+ }
41960
+ async function resolveExporter(endpoint, headers, ConsoleSpanExporter) {
41961
+ if (endpoint) {
41962
+ try {
41963
+ const exporterModule = await import(OTEL_EXPORTER_HTTP_SPEC);
41964
+ if ('OTLPTraceExporter' in exporterModule) {
41965
+ const { OTLPTraceExporter } = exporterModule;
41966
+ const exporterOptions = {
41967
+ url: endpoint,
41968
+ };
41969
+ if (headers && Object.keys(headers).length > 0) {
41970
+ exporterOptions.headers = headers;
41971
+ }
41972
+ logger.debug('open_telemetry_using_otlp_http_exporter', {
41973
+ endpoint,
41974
+ headers_present: Boolean(headers && Object.keys(headers).length),
41975
+ });
41976
+ return new OTLPTraceExporter(exporterOptions);
41977
+ }
41978
+ }
41979
+ catch (error) {
41980
+ logger.error('open_telemetry_exporter_not_available', {
41981
+ error: error instanceof Error ? error.message : String(error),
41982
+ });
41983
+ }
41984
+ }
41985
+ logger.warning('open_telemetry_falling_back_to_console_exporter');
41986
+ return new ConsoleSpanExporter();
41987
+ }
41988
+
41989
+ var otelSetup = /*#__PURE__*/Object.freeze({
41990
+ __proto__: null,
41991
+ setupOtel: setupOtel
41992
+ });
41993
+
41968
41994
  class WebSocketTransportProvisioner {
41969
41995
  constructor(options) {
41970
41996
  this.url = options.url;