@genesislcap/foundation-utils 15.50.3 → 15.51.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.
@@ -2,6 +2,7 @@ import { BehaviorSubject } from 'rxjs';
2
2
  import { Binding } from '@microsoft/fast-element';
3
3
  import { CaptureType } from '@microsoft/fast-element';
4
4
  import { ComposableStyles } from '@microsoft/fast-element';
5
+ import type { ConsolaReporter } from '@genesislcap/foundation-logger';
5
6
  import { Constructable } from '@microsoft/fast-element';
6
7
  import { Controller } from '@microsoft/fast-element';
7
8
  import { CSSDesignToken } from '@microsoft/fast-foundation';
@@ -153,6 +154,32 @@ export declare type ConversionType = 'string' | 'number' | 'time' | 'boolean';
153
154
  */
154
155
  export declare const createErrorMap: <TErrorDetailMap extends ErrorDetailMap>(logger: ErrorMapLogger) => ErrorMap<TErrorDetailMap>;
155
156
 
157
+ /**
158
+ * Creates a global log reporter that sends foundation logger output to a monitoring client.
159
+ *
160
+ * @remarks
161
+ * No logged data is sent: a report carries only the logger name, the level, the log's message (its
162
+ * first argument, when that is a string) and, for errors, the exception. Objects and any further
163
+ * arguments are left out, so credentials, personal or business data passed to a logger never
164
+ * reach the monitoring service. `error` and `fatal` logs become events: an exception when an
165
+ * `Error` was logged, with the message as `extra.message`, otherwise a message event. A logged
166
+ * `Error` with its own fields or a cause is sent as a copy that keeps only its name, message, stack
167
+ * and `Error` cause. Other logs become breadcrumbs unless `breadcrumbs` is `false`. A failing client
168
+ * never breaks logging.
169
+ *
170
+ * This covers only what the reporter sends. SDKs that record console calls, such as the Sentry
171
+ * browser SDKs by default, also record foundation logger output as console breadcrumbs with the
172
+ * logged arguments as data. When wiring a client by hand, drop those in the SDK's
173
+ * `beforeBreadcrumb` with {@link isFoundationLoggerConsoleBreadcrumb}.
174
+ *
175
+ * {@link setupErrorMonitoring} does both for you; use this directly to wire a client by hand.
176
+ *
177
+ * @param client - The monitoring client.
178
+ * @param options - Set `breadcrumbs: false` to skip breadcrumbs.
179
+ * @public
180
+ */
181
+ export declare const createErrorMonitoringReporter: (client: ErrorMonitoringClient, { breadcrumbs }?: Pick<ErrorMonitoringOptions, "breadcrumbs">) => ConsolaReporter;
182
+
156
183
  /**
157
184
  * Creates a logger with the given name and options.
158
185
  * @param name - The name to give the logger.
@@ -561,6 +588,107 @@ export declare interface ErrorMap<TErrorDetailMap extends ErrorDetailMap> extend
561
588
  */
562
589
  export declare type ErrorMapLogger = (...args: any[]) => void;
563
590
 
591
+ /**
592
+ * A breadcrumb: a record of something that happened before an event.
593
+ * @public
594
+ */
595
+ export declare interface ErrorMonitoringBreadcrumb {
596
+ category?: string;
597
+ level?: string;
598
+ message?: string;
599
+ data?: Record<string, unknown>;
600
+ }
601
+
602
+ /**
603
+ * Extra information an SDK passes with a breadcrumb, such as the DOM event or the console arguments.
604
+ * @public
605
+ */
606
+ export declare type ErrorMonitoringBreadcrumbHint = Record<string, unknown>;
607
+
608
+ /**
609
+ * An error-monitoring SDK, or an adapter for one. The method names and shapes match the Sentry
610
+ * browser SDKs, so `import * as Sentry from '@sentry/react'` can be passed as is.
611
+ * @public
612
+ */
613
+ export declare interface ErrorMonitoringClient {
614
+ captureException(error: unknown, context?: ErrorMonitoringContext): unknown;
615
+ captureMessage(message: string, context?: ErrorMonitoringContext): unknown;
616
+ addBreadcrumb?(breadcrumb: ErrorMonitoringBreadcrumb & {
617
+ level?: ErrorMonitoringLevel;
618
+ }): unknown;
619
+ init?(options: ErrorMonitoringInitOptions): unknown;
620
+ }
621
+
622
+ /**
623
+ * Context sent with a captured exception or message.
624
+ * @public
625
+ */
626
+ export declare interface ErrorMonitoringContext {
627
+ level?: ErrorMonitoringLevel;
628
+ tags?: Record<string, string>;
629
+ extra?: Record<string, unknown>;
630
+ }
631
+
632
+ /**
633
+ * Picks the monitoring environment from the page's location, or returns `undefined` to leave
634
+ * monitoring off.
635
+ * @public
636
+ */
637
+ export declare type ErrorMonitoringEnvironmentResolver = (location: Location) => string | undefined;
638
+
639
+ /**
640
+ * Extra options for the client's `init`, merged into what {@link setupErrorMonitoring} passes.
641
+ * @public
642
+ */
643
+ export declare interface ErrorMonitoringExtraInitOptions {
644
+ /** Runs after the built-in filter, for breadcrumbs it keeps, with the SDK's hint. */
645
+ beforeBreadcrumb?: (breadcrumb: ErrorMonitoringBreadcrumb, hint?: ErrorMonitoringBreadcrumbHint) => ErrorMonitoringBreadcrumb | null;
646
+ [key: string]: unknown;
647
+ }
648
+
649
+ /**
650
+ * Options {@link setupErrorMonitoring} passes to the client's `init`.
651
+ *
652
+ * @remarks
653
+ * The names match Sentry's `init` options. Any other keys from `initOptions` are passed through.
654
+ * @public
655
+ */
656
+ export declare interface ErrorMonitoringInitOptions {
657
+ dsn: string;
658
+ environment: string;
659
+ /** Drops the console breadcrumbs foundation loggers write; see {@link isFoundationLoggerConsoleBreadcrumb}. */
660
+ beforeBreadcrumb?: <B extends ErrorMonitoringBreadcrumb>(breadcrumb: B, hint?: ErrorMonitoringBreadcrumbHint) => B | null;
661
+ [key: string]: unknown;
662
+ }
663
+
664
+ /**
665
+ * Severity of a monitoring event or breadcrumb.
666
+ * @public
667
+ */
668
+ export declare type ErrorMonitoringLevel = 'fatal' | 'error' | 'warning' | 'info' | 'debug';
669
+
670
+ /**
671
+ * Options for {@link setupErrorMonitoring}.
672
+ * @public
673
+ */
674
+ export declare interface ErrorMonitoringOptions {
675
+ /** The DSN events are sent to. Without one, monitoring stays off. */
676
+ dsn: string | undefined;
677
+ /**
678
+ * The environment events are tagged with, or a function that picks it from the page's location.
679
+ * Defaults to the page's hostname, and leaves monitoring off on local hosts: `localhost`,
680
+ * `*.localhost`, `*.local`, `0.0.0.0`, `host.docker.internal`, and loopback, private, link-local
681
+ * and shared (`100.64.0.0/10`, as Tailscale uses) IP addresses, IPv4-mapped IPv6 included.
682
+ */
683
+ environment?: string | ErrorMonitoringEnvironmentResolver;
684
+ /** Extra options merged into what the client's `init` receives, e.g. Sentry's `dataCollection`. */
685
+ initOptions?: ErrorMonitoringExtraInitOptions;
686
+ /** Initialises the client in place of calling `client.init`. */
687
+ init?: (options: ErrorMonitoringInitOptions) => unknown;
688
+ /** Records non-error foundation logs as breadcrumbs. Defaults to `true`. */
689
+ breadcrumbs?: boolean;
690
+ }
691
+
564
692
  declare type EventListener_2<T = any> = (data: T) => void;
565
693
 
566
694
  /**
@@ -932,6 +1060,19 @@ export declare const isFeatureActivated: (feature: string) => boolean;
932
1060
  */
933
1061
  export declare const isFeatureActivatedInSearch: (search: string, feature: string) => boolean;
934
1062
 
1063
+ /**
1064
+ * True for a console breadcrumb written by a foundation logger.
1065
+ *
1066
+ * @remarks
1067
+ * consola's browser output starts with a `%c` badge (after a timestamp, when timestamps are on)
1068
+ * styled as a pill, and SDKs that record console calls join the arguments with `String()`, so these
1069
+ * breadcrumbs arrive as CSS and `[object Object]`, and they carry the logged arguments as data. The
1070
+ * reporter from {@link createErrorMonitoringReporter} records the same logs' messages without the
1071
+ * data. Other `%c`-styled console output doesn't match.
1072
+ * @public
1073
+ */
1074
+ export declare const isFoundationLoggerConsoleBreadcrumb: (breadcrumb: ErrorMonitoringBreadcrumb) => boolean;
1075
+
935
1076
  /**
936
1077
  * JSON replacer function.
937
1078
  * @param key - The object key.
@@ -2333,6 +2474,53 @@ export declare type SetActivatedFeaturesOptions = {
2333
2474
  reload?: boolean;
2334
2475
  };
2335
2476
 
2477
+ /**
2478
+ * Sets up error monitoring for a Genesis app in one call.
2479
+ *
2480
+ * @remarks
2481
+ * Without a DSN, or when no environment applies (by default on local hosts such as `localhost` or
2482
+ * a private IP address), it does nothing and resolves `false`. The environment defaults to the
2483
+ * page's hostname, so one image promoted across environments reports each under its own name; pass
2484
+ * a function to map hostnames to names such as `uat`. Otherwise it:
2485
+ *
2486
+ * - initialises the client (`client.init`, or `options.init`) with the DSN, environment, a
2487
+ * `beforeBreadcrumb` that drops the SDK's console breadcrumbs for foundation logger output (they
2488
+ * carry the logged arguments), and any `initOptions`;
2489
+ * - registers a global log reporter ({@link createErrorMonitoringReporter}), so errors logged by
2490
+ * every foundation logger, including those Genesis packages create at import time, are reported,
2491
+ * and other logs become breadcrumbs. Only log messages and exceptions are sent, never logged data.
2492
+ *
2493
+ * Logs written while an asynchronous `init` runs (the last 100) are reported once it finishes. If
2494
+ * `init` throws or rejects, for example when a lazily loaded SDK fails to download, it warns on the
2495
+ * console and resolves `false` rather than rejecting.
2496
+ *
2497
+ * Errors caught by the foundation-react-utils `AppErrorBoundary` and `TileErrorBoundary` are logged
2498
+ * with their reference ID and component stack in the message, so they are reported too without an
2499
+ * `onError`.
2500
+ * Pair them with `onCaughtError` on the React root.
2501
+ *
2502
+ * Calling it again replaces the previous reporter, or removes it if the new call has no DSN or
2503
+ * environment. When calls overlap, only the last one takes effect, and the earlier ones resolve
2504
+ * `false`.
2505
+ *
2506
+ * @example
2507
+ * ```ts
2508
+ * import * as Sentry from '@sentry/react';
2509
+ * import { setupErrorMonitoring } from '@genesislcap/foundation-utils';
2510
+ *
2511
+ * setupErrorMonitoring(Sentry, {
2512
+ * dsn: 'https://<key>@<org>.ingest.sentry.io/<project>',
2513
+ * environment: ({ hostname }) => ({ 'app-uat.example.com': 'uat', 'app.example.com': 'prod' })[hostname],
2514
+ * });
2515
+ * ```
2516
+ *
2517
+ * @param client - The monitoring SDK (for example the Sentry namespace) or an adapter for one.
2518
+ * @param options - The DSN, the environment, and extra init options.
2519
+ * @returns Whether this call enabled monitoring.
2520
+ * @public
2521
+ */
2522
+ export declare function setupErrorMonitoring(client: ErrorMonitoringClient, options: ErrorMonitoringOptions): Promise<boolean>;
2523
+
2336
2524
  export declare const SHORTCUT_BLOCKED_DEFAULT_MESSAGE = "This shortcut is currently unavailable in this context.";
2337
2525
 
2338
2526
  export declare const SHORTCUT_BLOCKED_DEFAULT_TITLE = "Shortcut blocked";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-utils",
3
3
  "description": "Genesis Foundation Utils",
4
- "version": "15.50.3",
4
+ "version": "15.51.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -29,17 +29,17 @@
29
29
  }
30
30
  },
31
31
  "devDependencies": {
32
- "@genesislcap/foundation-testing": "15.50.3",
33
- "@genesislcap/genx": "15.50.3",
34
- "@genesislcap/ts-builder": "15.50.3",
35
- "@genesislcap/uvu-playwright-builder": "15.50.3",
36
- "@genesislcap/vite-builder": "15.50.3",
37
- "@genesislcap/webpack-builder": "15.50.3",
32
+ "@genesislcap/foundation-testing": "15.51.0",
33
+ "@genesislcap/genx": "15.51.0",
34
+ "@genesislcap/ts-builder": "15.51.0",
35
+ "@genesislcap/uvu-playwright-builder": "15.51.0",
36
+ "@genesislcap/vite-builder": "15.51.0",
37
+ "@genesislcap/webpack-builder": "15.51.0",
38
38
  "@types/json-schema": "^7.0.11"
39
39
  },
40
40
  "dependencies": {
41
- "@genesislcap/expression-builder": "15.50.3",
42
- "@genesislcap/foundation-logger": "15.50.3",
41
+ "@genesislcap/expression-builder": "15.51.0",
42
+ "@genesislcap/foundation-logger": "15.51.0",
43
43
  "@microsoft/fast-components": "2.30.6",
44
44
  "@microsoft/fast-element": "1.14.0",
45
45
  "@microsoft/fast-foundation": "2.50.0",