@genesislcap/foundation-utils 15.46.5 → 15.46.6-alpha-606571609.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/custom-elements.json +259 -11
- package/dist/dts/env/index.d.ts +1 -0
- package/dist/dts/env/index.d.ts.map +1 -1
- package/dist/dts/env/runtime-config.d.ts +29 -0
- package/dist/dts/env/runtime-config.d.ts.map +1 -0
- package/dist/dts/error-monitoring/error-monitoring.d.ts +147 -0
- package/dist/dts/error-monitoring/error-monitoring.d.ts.map +1 -0
- package/dist/dts/error-monitoring/format-log-args.d.ts +13 -0
- package/dist/dts/error-monitoring/format-log-args.d.ts.map +1 -0
- package/dist/dts/error-monitoring/index.d.ts +3 -0
- package/dist/dts/error-monitoring/index.d.ts.map +1 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/env/index.js +1 -0
- package/dist/esm/env/runtime-config.js +48 -0
- package/dist/esm/error-monitoring/error-monitoring.js +139 -0
- package/dist/esm/error-monitoring/format-log-args.js +52 -0
- package/dist/esm/error-monitoring/index.js +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/foundation-utils.api.json +1432 -36
- package/dist/foundation-utils.d.ts +199 -0
- package/package.json +9 -9
|
@@ -71,6 +71,14 @@
|
|
|
71
71
|
"package": "./error"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
+
{
|
|
75
|
+
"kind": "js",
|
|
76
|
+
"name": "*",
|
|
77
|
+
"declaration": {
|
|
78
|
+
"name": "*",
|
|
79
|
+
"package": "./error-monitoring"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
74
82
|
{
|
|
75
83
|
"kind": "js",
|
|
76
84
|
"name": "*",
|
|
@@ -673,6 +681,21 @@
|
|
|
673
681
|
}
|
|
674
682
|
]
|
|
675
683
|
},
|
|
684
|
+
{
|
|
685
|
+
"kind": "javascript-module",
|
|
686
|
+
"path": "src/encoding/index.ts",
|
|
687
|
+
"declarations": [],
|
|
688
|
+
"exports": [
|
|
689
|
+
{
|
|
690
|
+
"kind": "js",
|
|
691
|
+
"name": "*",
|
|
692
|
+
"declaration": {
|
|
693
|
+
"name": "*",
|
|
694
|
+
"package": "./base64"
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
]
|
|
698
|
+
},
|
|
676
699
|
{
|
|
677
700
|
"kind": "javascript-module",
|
|
678
701
|
"path": "src/decorators/index.ts",
|
|
@@ -728,7 +751,7 @@
|
|
|
728
751
|
},
|
|
729
752
|
{
|
|
730
753
|
"kind": "javascript-module",
|
|
731
|
-
"path": "src/
|
|
754
|
+
"path": "src/env/index.ts",
|
|
732
755
|
"declarations": [],
|
|
733
756
|
"exports": [
|
|
734
757
|
{
|
|
@@ -736,22 +759,15 @@
|
|
|
736
759
|
"name": "*",
|
|
737
760
|
"declaration": {
|
|
738
761
|
"name": "*",
|
|
739
|
-
"package": "./
|
|
762
|
+
"package": "./is-dev"
|
|
740
763
|
}
|
|
741
|
-
}
|
|
742
|
-
]
|
|
743
|
-
},
|
|
744
|
-
{
|
|
745
|
-
"kind": "javascript-module",
|
|
746
|
-
"path": "src/env/index.ts",
|
|
747
|
-
"declarations": [],
|
|
748
|
-
"exports": [
|
|
764
|
+
},
|
|
749
765
|
{
|
|
750
766
|
"kind": "js",
|
|
751
767
|
"name": "*",
|
|
752
768
|
"declaration": {
|
|
753
769
|
"name": "*",
|
|
754
|
-
"package": "./
|
|
770
|
+
"package": "./runtime-config"
|
|
755
771
|
}
|
|
756
772
|
},
|
|
757
773
|
{
|
|
@@ -786,6 +802,69 @@
|
|
|
786
802
|
}
|
|
787
803
|
]
|
|
788
804
|
},
|
|
805
|
+
{
|
|
806
|
+
"kind": "javascript-module",
|
|
807
|
+
"path": "src/env/runtime-config.ts",
|
|
808
|
+
"declarations": [
|
|
809
|
+
{
|
|
810
|
+
"kind": "variable",
|
|
811
|
+
"name": "DEFAULT_RUNTIME_CONFIG_URL",
|
|
812
|
+
"type": {
|
|
813
|
+
"text": "string"
|
|
814
|
+
},
|
|
815
|
+
"default": "'/env.json'",
|
|
816
|
+
"description": "The default URL fetchRuntimeConfig reads from.",
|
|
817
|
+
"privacy": "public"
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
"kind": "function",
|
|
821
|
+
"name": "fetchRuntimeConfig",
|
|
822
|
+
"return": {
|
|
823
|
+
"type": {
|
|
824
|
+
"text": ""
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
"parameters": [
|
|
828
|
+
{
|
|
829
|
+
"name": "url",
|
|
830
|
+
"default": "DEFAULT_RUNTIME_CONFIG_URL",
|
|
831
|
+
"type": {
|
|
832
|
+
"text": "string"
|
|
833
|
+
},
|
|
834
|
+
"description": "The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.\n * "
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
"name": "fallback",
|
|
838
|
+
"default": "{}",
|
|
839
|
+
"type": {
|
|
840
|
+
"text": "Partial<T>"
|
|
841
|
+
},
|
|
842
|
+
"description": "Values to use when the config can't be read, and defaults for keys it omits."
|
|
843
|
+
}
|
|
844
|
+
],
|
|
845
|
+
"description": "Fetches per-deployment JSON config, such as an error-monitoring DSN or environment name, that\ncan't be baked in at build time because the same image is promoted across environments.",
|
|
846
|
+
"privacy": "public"
|
|
847
|
+
}
|
|
848
|
+
],
|
|
849
|
+
"exports": [
|
|
850
|
+
{
|
|
851
|
+
"kind": "js",
|
|
852
|
+
"name": "DEFAULT_RUNTIME_CONFIG_URL",
|
|
853
|
+
"declaration": {
|
|
854
|
+
"name": "DEFAULT_RUNTIME_CONFIG_URL",
|
|
855
|
+
"module": "src/env/runtime-config.ts"
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
"kind": "js",
|
|
860
|
+
"name": "fetchRuntimeConfig",
|
|
861
|
+
"declaration": {
|
|
862
|
+
"name": "fetchRuntimeConfig",
|
|
863
|
+
"module": "src/env/runtime-config.ts"
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
]
|
|
867
|
+
},
|
|
789
868
|
{
|
|
790
869
|
"kind": "javascript-module",
|
|
791
870
|
"path": "src/env/variables.ts",
|
|
@@ -1439,6 +1518,175 @@
|
|
|
1439
1518
|
}
|
|
1440
1519
|
]
|
|
1441
1520
|
},
|
|
1521
|
+
{
|
|
1522
|
+
"kind": "javascript-module",
|
|
1523
|
+
"path": "src/error-monitoring/error-monitoring.ts",
|
|
1524
|
+
"declarations": [
|
|
1525
|
+
{
|
|
1526
|
+
"kind": "function",
|
|
1527
|
+
"name": "createErrorMonitoringReporter",
|
|
1528
|
+
"return": {
|
|
1529
|
+
"type": {
|
|
1530
|
+
"text": "ConsolaReporter"
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
"parameters": [
|
|
1534
|
+
{
|
|
1535
|
+
"name": "client",
|
|
1536
|
+
"type": {
|
|
1537
|
+
"text": "ErrorMonitoringClient"
|
|
1538
|
+
},
|
|
1539
|
+
"description": "The monitoring client."
|
|
1540
|
+
},
|
|
1541
|
+
{
|
|
1542
|
+
"name": "{ breadcrumbs = true }",
|
|
1543
|
+
"default": "{}",
|
|
1544
|
+
"type": {
|
|
1545
|
+
"text": "Pick<ErrorMonitoringOptions, 'breadcrumbs'>"
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
"description": "Set `breadcrumbs: false` to skip breadcrumbs.",
|
|
1550
|
+
"name": "options"
|
|
1551
|
+
}
|
|
1552
|
+
],
|
|
1553
|
+
"description": "Creates a global log reporter that sends foundation logger output to a monitoring client.",
|
|
1554
|
+
"privacy": "public"
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
"kind": "function",
|
|
1558
|
+
"name": "isFoundationLoggerConsoleBreadcrumb",
|
|
1559
|
+
"return": {
|
|
1560
|
+
"type": {
|
|
1561
|
+
"text": "boolean"
|
|
1562
|
+
}
|
|
1563
|
+
},
|
|
1564
|
+
"parameters": [
|
|
1565
|
+
{
|
|
1566
|
+
"name": "breadcrumb",
|
|
1567
|
+
"type": {
|
|
1568
|
+
"text": "ErrorMonitoringBreadcrumb"
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
],
|
|
1572
|
+
"description": "True for a console breadcrumb written by a foundation logger.",
|
|
1573
|
+
"privacy": "public"
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
"kind": "function",
|
|
1577
|
+
"name": "setupErrorMonitoring",
|
|
1578
|
+
"return": {
|
|
1579
|
+
"type": {
|
|
1580
|
+
"text": ""
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1583
|
+
"parameters": [
|
|
1584
|
+
{
|
|
1585
|
+
"name": "client",
|
|
1586
|
+
"type": {
|
|
1587
|
+
"text": "ErrorMonitoringClient"
|
|
1588
|
+
},
|
|
1589
|
+
"description": "The monitoring SDK (for example the Sentry namespace) or an adapter for one."
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
"name": "options",
|
|
1593
|
+
"default": "{}",
|
|
1594
|
+
"type": {
|
|
1595
|
+
"text": "ErrorMonitoringOptions"
|
|
1596
|
+
},
|
|
1597
|
+
"description": "Config location and keys, and extra init options."
|
|
1598
|
+
}
|
|
1599
|
+
],
|
|
1600
|
+
"description": "Sets up error monitoring for a Genesis app in one call.",
|
|
1601
|
+
"privacy": "public"
|
|
1602
|
+
}
|
|
1603
|
+
],
|
|
1604
|
+
"exports": [
|
|
1605
|
+
{
|
|
1606
|
+
"kind": "js",
|
|
1607
|
+
"name": "createErrorMonitoringReporter",
|
|
1608
|
+
"declaration": {
|
|
1609
|
+
"name": "createErrorMonitoringReporter",
|
|
1610
|
+
"module": "src/error-monitoring/error-monitoring.ts"
|
|
1611
|
+
}
|
|
1612
|
+
},
|
|
1613
|
+
{
|
|
1614
|
+
"kind": "js",
|
|
1615
|
+
"name": "isFoundationLoggerConsoleBreadcrumb",
|
|
1616
|
+
"declaration": {
|
|
1617
|
+
"name": "isFoundationLoggerConsoleBreadcrumb",
|
|
1618
|
+
"module": "src/error-monitoring/error-monitoring.ts"
|
|
1619
|
+
}
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
"kind": "js",
|
|
1623
|
+
"name": "setupErrorMonitoring",
|
|
1624
|
+
"declaration": {
|
|
1625
|
+
"name": "setupErrorMonitoring",
|
|
1626
|
+
"module": "src/error-monitoring/error-monitoring.ts"
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
]
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
"kind": "javascript-module",
|
|
1633
|
+
"path": "src/error-monitoring/format-log-args.ts",
|
|
1634
|
+
"declarations": [
|
|
1635
|
+
{
|
|
1636
|
+
"kind": "function",
|
|
1637
|
+
"name": "formatLogArgs",
|
|
1638
|
+
"return": {
|
|
1639
|
+
"type": {
|
|
1640
|
+
"text": "string"
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
"parameters": [
|
|
1644
|
+
{
|
|
1645
|
+
"name": "args",
|
|
1646
|
+
"type": {
|
|
1647
|
+
"text": "readonly unknown[]"
|
|
1648
|
+
},
|
|
1649
|
+
"description": "The arguments passed to the logger."
|
|
1650
|
+
}
|
|
1651
|
+
],
|
|
1652
|
+
"description": "Builds a readable one-line message from a log call's arguments.",
|
|
1653
|
+
"privacy": "public"
|
|
1654
|
+
}
|
|
1655
|
+
],
|
|
1656
|
+
"exports": [
|
|
1657
|
+
{
|
|
1658
|
+
"kind": "js",
|
|
1659
|
+
"name": "formatLogArgs",
|
|
1660
|
+
"declaration": {
|
|
1661
|
+
"name": "formatLogArgs",
|
|
1662
|
+
"module": "src/error-monitoring/format-log-args.ts"
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
]
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
"kind": "javascript-module",
|
|
1669
|
+
"path": "src/error-monitoring/index.ts",
|
|
1670
|
+
"declarations": [],
|
|
1671
|
+
"exports": [
|
|
1672
|
+
{
|
|
1673
|
+
"kind": "js",
|
|
1674
|
+
"name": "*",
|
|
1675
|
+
"declaration": {
|
|
1676
|
+
"name": "*",
|
|
1677
|
+
"package": "./error-monitoring"
|
|
1678
|
+
}
|
|
1679
|
+
},
|
|
1680
|
+
{
|
|
1681
|
+
"kind": "js",
|
|
1682
|
+
"name": "*",
|
|
1683
|
+
"declaration": {
|
|
1684
|
+
"name": "*",
|
|
1685
|
+
"package": "./format-log-args"
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
]
|
|
1689
|
+
},
|
|
1442
1690
|
{
|
|
1443
1691
|
"kind": "javascript-module",
|
|
1444
1692
|
"path": "src/feature-flags/featureFlags.ts",
|
package/dist/dts/env/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/env/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/env/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default URL {@link fetchRuntimeConfig} reads from.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_RUNTIME_CONFIG_URL = "/env.json";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches per-deployment JSON config, such as an error-monitoring DSN or environment name, that
|
|
8
|
+
* can't be baked in at build time because the same image is promoted across environments.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Never rejects. Resolves to `fallback` when the request fails (network error, non-2xx status
|
|
12
|
+
* such as a 404) or the body isn't a JSON object. The last case covers an SPA fallback that serves
|
|
13
|
+
* `index.html` with a 200 for unknown paths. On success, the fetched values are shallow-merged over
|
|
14
|
+
* `fallback`. The request bypasses the HTTP cache so a redeployed config is picked up on reload.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* type EnvConfig = { sentryDsn: string; environment: string };
|
|
19
|
+
* const { sentryDsn, environment = 'local' } = await fetchRuntimeConfig<EnvConfig>();
|
|
20
|
+
* if (sentryDsn) Sentry.init({ dsn: sentryDsn, environment });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param url - The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.
|
|
24
|
+
* @param fallback - Values to use when the config can't be read, and defaults for keys it omits.
|
|
25
|
+
* @returns The fetched config merged over `fallback`, or `fallback` alone.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function fetchRuntimeConfig<T extends object>(url?: string, fallback?: Partial<T>): Promise<Partial<T>>;
|
|
29
|
+
//# sourceMappingURL=runtime-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-config.d.ts","sourceRoot":"","sources":["../../../src/env/runtime-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,0BAA0B,cAAc,CAAC;AAKtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACvD,GAAG,GAAE,MAAmC,EACxC,QAAQ,GAAE,OAAO,CAAC,CAAC,CAAM,GACxB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAerB"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ConsolaReporter } from '@genesislcap/foundation-logger';
|
|
2
|
+
/**
|
|
3
|
+
* Severity of a monitoring event or breadcrumb.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type ErrorMonitoringLevel = 'fatal' | 'error' | 'warning' | 'info' | 'debug';
|
|
7
|
+
/**
|
|
8
|
+
* Context sent with a captured exception or message.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface ErrorMonitoringContext {
|
|
12
|
+
level?: ErrorMonitoringLevel;
|
|
13
|
+
tags?: Record<string, string>;
|
|
14
|
+
extra?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A breadcrumb: a record of something that happened before an event.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface ErrorMonitoringBreadcrumb {
|
|
21
|
+
category?: string;
|
|
22
|
+
level?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
data?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options {@link setupErrorMonitoring} passes to the client's `init`.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* The names match Sentry's `init` options. Any other keys from `initOptions` are passed through.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface ErrorMonitoringInitOptions {
|
|
34
|
+
dsn: string;
|
|
35
|
+
environment: string;
|
|
36
|
+
/** How deep logged objects are serialised. Defaults to 10, so nested Genesis NACK entries survive. */
|
|
37
|
+
normalizeDepth?: number;
|
|
38
|
+
/** Drops the console breadcrumbs foundation loggers write; see {@link isFoundationLoggerConsoleBreadcrumb}. */
|
|
39
|
+
beforeBreadcrumb?: <B extends ErrorMonitoringBreadcrumb>(breadcrumb: B) => B | null;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extra options for the client's `init`, merged into what {@link setupErrorMonitoring} passes.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export interface ErrorMonitoringExtraInitOptions {
|
|
47
|
+
normalizeDepth?: number;
|
|
48
|
+
/** Runs after the built-in filter, for breadcrumbs it keeps. */
|
|
49
|
+
beforeBreadcrumb?: (breadcrumb: ErrorMonitoringBreadcrumb) => ErrorMonitoringBreadcrumb | null;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* An error-monitoring SDK, or an adapter for one. The method names and shapes match the Sentry
|
|
54
|
+
* browser SDKs, so `import * as Sentry from '@sentry/react'` can be passed as is.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export interface ErrorMonitoringClient {
|
|
58
|
+
captureException(error: unknown, context?: ErrorMonitoringContext): unknown;
|
|
59
|
+
captureMessage(message: string, context?: ErrorMonitoringContext): unknown;
|
|
60
|
+
addBreadcrumb?(breadcrumb: ErrorMonitoringBreadcrumb & {
|
|
61
|
+
level?: ErrorMonitoringLevel;
|
|
62
|
+
}): unknown;
|
|
63
|
+
init?(options: ErrorMonitoringInitOptions): unknown;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for {@link setupErrorMonitoring}.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface ErrorMonitoringOptions {
|
|
70
|
+
/** Per-deployment JSON config holding the DSN and environment. Defaults to `/env.json`. */
|
|
71
|
+
configUrl?: string;
|
|
72
|
+
/** Config key holding the DSN. Defaults to `sentryDsn`. */
|
|
73
|
+
dsnKey?: string;
|
|
74
|
+
/** Config key holding the environment name. Defaults to `environmentType`. */
|
|
75
|
+
environmentKey?: string;
|
|
76
|
+
/** Environment used when the config doesn't name one. Defaults to `local`. */
|
|
77
|
+
defaultEnvironment?: string;
|
|
78
|
+
/** Extra options merged into what the client's `init` receives, e.g. Sentry's `dataCollection`. */
|
|
79
|
+
initOptions?: ErrorMonitoringExtraInitOptions;
|
|
80
|
+
/** Initialises the client in place of calling `client.init`. */
|
|
81
|
+
init?: (options: ErrorMonitoringInitOptions) => unknown;
|
|
82
|
+
/** Records non-error foundation logs as breadcrumbs. Defaults to `true`. */
|
|
83
|
+
breadcrumbs?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a global log reporter that sends foundation logger output to a monitoring client.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* `error` and `fatal` logs become events: an exception when an `Error` was logged, otherwise a
|
|
90
|
+
* message built with {@link formatLogArgs}. Each is tagged with the logger name, and plain-object
|
|
91
|
+
* arguments (such as an error boundary's reference ID and component stack) are merged into its
|
|
92
|
+
* extra data alongside the raw arguments. Other logs become breadcrumbs unless `breadcrumbs` is
|
|
93
|
+
* `false`. A failing client never breaks logging.
|
|
94
|
+
*
|
|
95
|
+
* {@link setupErrorMonitoring} registers this for you; use it directly to wire a client by hand.
|
|
96
|
+
*
|
|
97
|
+
* @param client - The monitoring client.
|
|
98
|
+
* @param options - Set `breadcrumbs: false` to skip breadcrumbs.
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export declare const createErrorMonitoringReporter: (client: ErrorMonitoringClient, { breadcrumbs }?: Pick<ErrorMonitoringOptions, "breadcrumbs">) => ConsolaReporter;
|
|
102
|
+
/**
|
|
103
|
+
* True for a console breadcrumb written by a foundation logger.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* consola's browser output starts with a `%c` badge, and SDKs that record console calls join the
|
|
107
|
+
* arguments with `String()`, so these breadcrumbs arrive as CSS and `[object Object]`. The
|
|
108
|
+
* reporter from {@link createErrorMonitoringReporter} records the same logs readably.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export declare const isFoundationLoggerConsoleBreadcrumb: (breadcrumb: ErrorMonitoringBreadcrumb) => boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Sets up error monitoring for a Genesis app in one call.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* Reads the DSN and environment from per-deployment config (`/env.json` by default) with
|
|
117
|
+
* {@link fetchRuntimeConfig}, so one image can be promoted across environments. Without a DSN it
|
|
118
|
+
* does nothing and resolves `false`, as in local development. Otherwise it:
|
|
119
|
+
*
|
|
120
|
+
* - initialises the client (`client.init`, or `options.init`) with the DSN, environment,
|
|
121
|
+
* `normalizeDepth: 10`, a `beforeBreadcrumb` that drops unreadable foundation logger console
|
|
122
|
+
* breadcrumbs, and any `initOptions`;
|
|
123
|
+
* - registers a global log reporter ({@link createErrorMonitoringReporter}), so errors logged by
|
|
124
|
+
* every foundation logger, including those Genesis packages create at import time, are reported
|
|
125
|
+
* with their structured arguments, and other logs become readable breadcrumbs.
|
|
126
|
+
*
|
|
127
|
+
* Errors caught by the foundation-react-utils `AppErrorBoundary` and `TileErrorBoundary` are logged
|
|
128
|
+
* with their reference ID and component stack, so they are reported too without an `onError`.
|
|
129
|
+
* Pair them with `onCaughtError` on the React root.
|
|
130
|
+
*
|
|
131
|
+
* Calling it again replaces the previous reporter, or removes it if the new call finds no DSN.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import * as Sentry from '@sentry/react';
|
|
136
|
+
* import { setupErrorMonitoring } from '@genesislcap/foundation-utils';
|
|
137
|
+
*
|
|
138
|
+
* setupErrorMonitoring(Sentry);
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @param client - The monitoring SDK (for example the Sentry namespace) or an adapter for one.
|
|
142
|
+
* @param options - Config location and keys, and extra init options.
|
|
143
|
+
* @returns Whether monitoring was enabled.
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export declare function setupErrorMonitoring(client: ErrorMonitoringClient, options?: ErrorMonitoringOptions): Promise<boolean>;
|
|
147
|
+
//# sourceMappingURL=error-monitoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-monitoring.d.ts","sourceRoot":"","sources":["../../../src/error-monitoring/error-monitoring.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a readable one-line message from a log call's arguments.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Objects, such as a Genesis NACK, are JSON-encoded rather than becoming `[object Object]`.
|
|
6
|
+
* Circular references are marked, functions and classes are named, errors contribute their message,
|
|
7
|
+
* and the result is capped at 2000 characters.
|
|
8
|
+
*
|
|
9
|
+
* @param args - The arguments passed to the logger.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare const formatLogArgs: (args: readonly unknown[]) => string;
|
|
13
|
+
//# sourceMappingURL=format-log-args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-log-args.d.ts","sourceRoot":"","sources":["../../../src/error-monitoring/format-log-args.ts"],"names":[],"mappings":"AAoCA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,OAAO,EAAE,KAAG,MAMxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error-monitoring/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
package/dist/dts/index.d.ts
CHANGED
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC"}
|
package/dist/esm/env/index.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* The default URL {@link fetchRuntimeConfig} reads from.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_RUNTIME_CONFIG_URL = '/env.json';
|
|
7
|
+
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
+
/**
|
|
9
|
+
* Fetches per-deployment JSON config, such as an error-monitoring DSN or environment name, that
|
|
10
|
+
* can't be baked in at build time because the same image is promoted across environments.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Never rejects. Resolves to `fallback` when the request fails (network error, non-2xx status
|
|
14
|
+
* such as a 404) or the body isn't a JSON object. The last case covers an SPA fallback that serves
|
|
15
|
+
* `index.html` with a 200 for unknown paths. On success, the fetched values are shallow-merged over
|
|
16
|
+
* `fallback`. The request bypasses the HTTP cache so a redeployed config is picked up on reload.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* type EnvConfig = { sentryDsn: string; environment: string };
|
|
21
|
+
* const { sentryDsn, environment = 'local' } = await fetchRuntimeConfig<EnvConfig>();
|
|
22
|
+
* if (sentryDsn) Sentry.init({ dsn: sentryDsn, environment });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param url - The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.
|
|
26
|
+
* @param fallback - Values to use when the config can't be read, and defaults for keys it omits.
|
|
27
|
+
* @returns The fetched config merged over `fallback`, or `fallback` alone.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function fetchRuntimeConfig() {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (url = DEFAULT_RUNTIME_CONFIG_URL, fallback = {}) {
|
|
32
|
+
try {
|
|
33
|
+
const response = yield fetch(url, {
|
|
34
|
+
cache: 'no-store',
|
|
35
|
+
headers: { Accept: 'application/json' },
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
// Parse the text rather than trusting Content-Type: an SPA fallback may answer with HTML.
|
|
41
|
+
const config = JSON.parse(yield response.text());
|
|
42
|
+
return isPlainObject(config) ? Object.assign(Object.assign({}, fallback), config) : fallback;
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|