@mastra/auth-okta 0.2.1-alpha.0 → 0.2.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -313,6 +313,46 @@ function getRequestHeader(request, name) {
313
313
  }
314
314
  //#endregion
315
315
  //#region ../../packages/_internal-core/dist/logger/index.js
316
+ /**
317
+ * Export a tracked exception through the adapter sink, mirroring the
318
+ * DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
319
+ * when present on a MastraError-like value). Never throws into the caller.
320
+ */
321
+ function exportTrackedException(ctx, error, metadata) {
322
+ if (!ctx?.options.export) return;
323
+ try {
324
+ const mastraError = error;
325
+ ctx.getLogSink()?.error(error.message, {
326
+ ...mastraError.id !== void 0 ? { errorId: mastraError.id } : {},
327
+ ...mastraError.domain !== void 0 ? { domain: mastraError.domain } : {},
328
+ ...mastraError.category !== void 0 ? { category: mastraError.category } : {},
329
+ ...mastraError.details !== void 0 ? { details: mastraError.details } : {},
330
+ ...error.cause instanceof Error ? { cause: error.cause.message } : {},
331
+ ...metadata
332
+ });
333
+ } catch {}
334
+ }
335
+ /**
336
+ * Adapt IMastraLogger's variadic args into the structured `data` payload of
337
+ * an exported log record. Extracts the first plain object as data,
338
+ * serializes an Error arg, and collects remaining primitives under `args`
339
+ * so the derived record preserves all context from the native call.
340
+ */
341
+ function buildLogRecordData(args) {
342
+ const objectData = args.find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg) && !(arg instanceof Error));
343
+ const errorArg = args.find((arg) => arg instanceof Error);
344
+ const extraArgs = args.filter((arg) => arg !== objectData && arg !== errorArg);
345
+ if (!objectData && !errorArg && extraArgs.length === 0) return void 0;
346
+ return {
347
+ ...objectData ?? {},
348
+ ...errorArg ? { error: {
349
+ name: errorArg.name,
350
+ message: errorArg.message,
351
+ stack: errorArg.stack
352
+ } } : {},
353
+ ...extraArgs.length > 0 ? { args: extraArgs } : {}
354
+ };
355
+ }
316
356
  const RegisteredLogger = {
317
357
  AGENT: "AGENT",
318
358
  OBSERVABILITY: "OBSERVABILITY",
@@ -399,19 +439,56 @@ var MastraLogger = class {
399
439
  var ConsoleLogger = class ConsoleLogger extends MastraLogger {
400
440
  component;
401
441
  filter;
442
+ #adapterContext;
402
443
  constructor(options = {}) {
403
444
  super(options);
404
445
  this.component = options.component;
405
446
  this.filter = options.filter;
406
447
  }
448
+ /**
449
+ * Adapter hook (see `AdaptableLogger`): enables native trace correlation
450
+ * (trace_id/span_id appended to console output) and observability export
451
+ * derived from the same record. Called by Mastra during setup.
452
+ */
453
+ __attachObservability(ctx) {
454
+ this.#adapterContext = ctx;
455
+ }
407
456
  child(componentOrBindings) {
408
457
  const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
409
- return new ConsoleLogger({
458
+ const child = new ConsoleLogger({
410
459
  name: this.name,
411
460
  level: this.level,
412
461
  component,
413
462
  filter: this.filter
414
463
  });
464
+ if (this.#adapterContext) child.__attachObservability(this.#adapterContext);
465
+ return child;
466
+ }
467
+ /**
468
+ * Native-record correlation: when a span is active, append the trace
469
+ * fields object to the console args so every destination sees them.
470
+ */
471
+ #correlate(args) {
472
+ const ctx = this.#adapterContext;
473
+ if (!ctx?.options.correlation) return args;
474
+ try {
475
+ const fields = ctx.resolveTraceFields();
476
+ return fields ? [...args, fields] : args;
477
+ } catch {
478
+ return args;
479
+ }
480
+ }
481
+ /**
482
+ * Export the record derived from the same native call to observability.
483
+ * Mirrors DualLogger semantics: export is independent of the console
484
+ * level filter, and never throws into the caller.
485
+ */
486
+ #export(level, message, args) {
487
+ const ctx = this.#adapterContext;
488
+ if (!ctx?.options.export) return;
489
+ try {
490
+ ctx.getLogSink()?.[level](message, buildLogRecordData(args));
491
+ } catch {}
415
492
  }
416
493
  shouldLog(level, message, args) {
417
494
  if (!this.filter) return true;
@@ -431,16 +508,23 @@ var ConsoleLogger = class ConsoleLogger extends MastraLogger {
431
508
  return this.component ? `[${this.component}] ` : "";
432
509
  }
433
510
  debug(message, ...args) {
434
- if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...args);
511
+ if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
512
+ this.#export("debug", message, args);
435
513
  }
436
514
  info(message, ...args) {
437
- if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...args);
515
+ if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
516
+ this.#export("info", message, args);
438
517
  }
439
518
  warn(message, ...args) {
440
- if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...args);
519
+ if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...this.#correlate(args));
520
+ this.#export("warn", message, args);
441
521
  }
442
522
  error(message, ...args) {
443
- if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...args);
523
+ if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...this.#correlate(args));
524
+ this.#export("error", message, args);
525
+ }
526
+ trackException(error, metadata) {
527
+ exportTrackedException(this.#adapterContext, error, metadata);
444
528
  }
445
529
  async listLogs(_transportId, _params) {
446
530
  return {