@genesislcap/foundation-utils 15.46.5 → 15.46.6-alpha-6d1bd2f25.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.
@@ -754,6 +754,14 @@
754
754
  "package": "./is-dev"
755
755
  }
756
756
  },
757
+ {
758
+ "kind": "js",
759
+ "name": "*",
760
+ "declaration": {
761
+ "name": "*",
762
+ "package": "./runtime-config"
763
+ }
764
+ },
757
765
  {
758
766
  "kind": "js",
759
767
  "name": "*",
@@ -786,6 +794,69 @@
786
794
  }
787
795
  ]
788
796
  },
797
+ {
798
+ "kind": "javascript-module",
799
+ "path": "src/env/runtime-config.ts",
800
+ "declarations": [
801
+ {
802
+ "kind": "variable",
803
+ "name": "DEFAULT_RUNTIME_CONFIG_URL",
804
+ "type": {
805
+ "text": "string"
806
+ },
807
+ "default": "'/env.json'",
808
+ "description": "The default URL fetchRuntimeConfig reads from.",
809
+ "privacy": "public"
810
+ },
811
+ {
812
+ "kind": "function",
813
+ "name": "fetchRuntimeConfig",
814
+ "return": {
815
+ "type": {
816
+ "text": ""
817
+ }
818
+ },
819
+ "parameters": [
820
+ {
821
+ "name": "url",
822
+ "default": "DEFAULT_RUNTIME_CONFIG_URL",
823
+ "type": {
824
+ "text": "string"
825
+ },
826
+ "description": "The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.\n * "
827
+ },
828
+ {
829
+ "name": "fallback",
830
+ "default": "{}",
831
+ "type": {
832
+ "text": "Partial<T>"
833
+ },
834
+ "description": "Values to use when the config can't be read, and defaults for keys it omits."
835
+ }
836
+ ],
837
+ "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.",
838
+ "privacy": "public"
839
+ }
840
+ ],
841
+ "exports": [
842
+ {
843
+ "kind": "js",
844
+ "name": "DEFAULT_RUNTIME_CONFIG_URL",
845
+ "declaration": {
846
+ "name": "DEFAULT_RUNTIME_CONFIG_URL",
847
+ "module": "src/env/runtime-config.ts"
848
+ }
849
+ },
850
+ {
851
+ "kind": "js",
852
+ "name": "fetchRuntimeConfig",
853
+ "declaration": {
854
+ "name": "fetchRuntimeConfig",
855
+ "module": "src/env/runtime-config.ts"
856
+ }
857
+ }
858
+ ]
859
+ },
789
860
  {
790
861
  "kind": "javascript-module",
791
862
  "path": "src/env/variables.ts",
@@ -1,3 +1,4 @@
1
1
  export * from './is-dev';
2
+ export * from './runtime-config';
2
3
  export * from './variables';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,2 +1,3 @@
1
1
  export * from './is-dev';
2
+ export * from './runtime-config';
2
3
  export * from './variables';
@@ -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
+ }
@@ -2079,6 +2079,33 @@
2079
2079
  "endIndex": 2
2080
2080
  }
2081
2081
  },
2082
+ {
2083
+ "kind": "Variable",
2084
+ "canonicalReference": "@genesislcap/foundation-utils!DEFAULT_RUNTIME_CONFIG_URL:var",
2085
+ "docComment": "/**\n * The default URL {@link fetchRuntimeConfig} reads from.\n *\n * @public\n */\n",
2086
+ "excerptTokens": [
2087
+ {
2088
+ "kind": "Content",
2089
+ "text": "DEFAULT_RUNTIME_CONFIG_URL = "
2090
+ },
2091
+ {
2092
+ "kind": "Content",
2093
+ "text": "\"/env.json\""
2094
+ }
2095
+ ],
2096
+ "fileUrlPath": "src/env/runtime-config.ts",
2097
+ "initializerTokenRange": {
2098
+ "startIndex": 1,
2099
+ "endIndex": 2
2100
+ },
2101
+ "isReadonly": true,
2102
+ "releaseTag": "Public",
2103
+ "name": "DEFAULT_RUNTIME_CONFIG_URL",
2104
+ "variableTypeTokenRange": {
2105
+ "startIndex": 0,
2106
+ "endIndex": 0
2107
+ }
2108
+ },
2082
2109
  {
2083
2110
  "kind": "Variable",
2084
2111
  "canonicalReference": "@genesislcap/foundation-utils!DEFAULT_USER:var",
@@ -5086,6 +5113,107 @@
5086
5113
  "endIndex": 2
5087
5114
  }
5088
5115
  },
5116
+ {
5117
+ "kind": "Function",
5118
+ "canonicalReference": "@genesislcap/foundation-utils!fetchRuntimeConfig:function(1)",
5119
+ "docComment": "/**\n * Fetches per-deployment JSON config, such as an error-monitoring DSN or environment name, that can't be baked in at build time because the same image is promoted across environments.\n *\n * @remarks\n *\n * Never rejects. Resolves to `fallback` when the request fails (network error, non-2xx status such as a 404) or the body isn't a JSON object. The last case covers an SPA fallback that serves `index.html` with a 200 for unknown paths. On success, the fetched values are shallow-merged over `fallback`. The request bypasses the HTTP cache so a redeployed config is picked up on reload.\n *\n * @param url - The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.\n *\n * @param fallback - Values to use when the config can't be read, and defaults for keys it omits.\n *\n * @returns The fetched config merged over `fallback`, or `fallback` alone.\n *\n * @example\n * ```ts\n * type EnvConfig = { sentryDsn: string; environment: string };\n * const { sentryDsn, environment = 'local' } = await fetchRuntimeConfig<EnvConfig>();\n * if (sentryDsn) Sentry.init({ dsn: sentryDsn, environment });\n * ```\n *\n * @public\n */\n",
5120
+ "excerptTokens": [
5121
+ {
5122
+ "kind": "Content",
5123
+ "text": "export declare function fetchRuntimeConfig<T extends "
5124
+ },
5125
+ {
5126
+ "kind": "Content",
5127
+ "text": "object"
5128
+ },
5129
+ {
5130
+ "kind": "Content",
5131
+ "text": ">(url?: "
5132
+ },
5133
+ {
5134
+ "kind": "Content",
5135
+ "text": "string"
5136
+ },
5137
+ {
5138
+ "kind": "Content",
5139
+ "text": ", fallback?: "
5140
+ },
5141
+ {
5142
+ "kind": "Reference",
5143
+ "text": "Partial",
5144
+ "canonicalReference": "!Partial:type"
5145
+ },
5146
+ {
5147
+ "kind": "Content",
5148
+ "text": "<T>"
5149
+ },
5150
+ {
5151
+ "kind": "Content",
5152
+ "text": "): "
5153
+ },
5154
+ {
5155
+ "kind": "Reference",
5156
+ "text": "Promise",
5157
+ "canonicalReference": "!Promise:interface"
5158
+ },
5159
+ {
5160
+ "kind": "Content",
5161
+ "text": "<"
5162
+ },
5163
+ {
5164
+ "kind": "Reference",
5165
+ "text": "Partial",
5166
+ "canonicalReference": "!Partial:type"
5167
+ },
5168
+ {
5169
+ "kind": "Content",
5170
+ "text": "<T>>"
5171
+ },
5172
+ {
5173
+ "kind": "Content",
5174
+ "text": ";"
5175
+ }
5176
+ ],
5177
+ "fileUrlPath": "src/env/runtime-config.ts",
5178
+ "returnTypeTokenRange": {
5179
+ "startIndex": 8,
5180
+ "endIndex": 12
5181
+ },
5182
+ "releaseTag": "Public",
5183
+ "overloadIndex": 1,
5184
+ "parameters": [
5185
+ {
5186
+ "parameterName": "url",
5187
+ "parameterTypeTokenRange": {
5188
+ "startIndex": 3,
5189
+ "endIndex": 4
5190
+ },
5191
+ "isOptional": true
5192
+ },
5193
+ {
5194
+ "parameterName": "fallback",
5195
+ "parameterTypeTokenRange": {
5196
+ "startIndex": 5,
5197
+ "endIndex": 7
5198
+ },
5199
+ "isOptional": true
5200
+ }
5201
+ ],
5202
+ "typeParameters": [
5203
+ {
5204
+ "typeParameterName": "T",
5205
+ "constraintTokenRange": {
5206
+ "startIndex": 1,
5207
+ "endIndex": 2
5208
+ },
5209
+ "defaultTypeTokenRange": {
5210
+ "startIndex": 0,
5211
+ "endIndex": 0
5212
+ }
5213
+ }
5214
+ ],
5215
+ "name": "fetchRuntimeConfig"
5216
+ },
5089
5217
  {
5090
5218
  "kind": "Enum",
5091
5219
  "canonicalReference": "@genesislcap/foundation-utils!FontStyle:enum",
@@ -285,6 +285,12 @@ export declare let DEFAULT_ORGANISATION: string;
285
285
  */
286
286
  export declare let DEFAULT_PASSWORD: string;
287
287
 
288
+ /**
289
+ * The default URL {@link fetchRuntimeConfig} reads from.
290
+ * @public
291
+ */
292
+ export declare const DEFAULT_RUNTIME_CONFIG_URL = "/env.json";
293
+
288
294
  /**
289
295
  * The default Username value, used in auth/login flow [`genesislcap-foundation-auth`](https://link-to-docs).
290
296
  * @remarks Optional.
@@ -569,6 +575,30 @@ declare type EventListener_2<T = any> = (data: T) => void;
569
575
  */
570
576
  export declare type EventName = 'input' | 'change' | 'default';
571
577
 
578
+ /**
579
+ * Fetches per-deployment JSON config, such as an error-monitoring DSN or environment name, that
580
+ * can't be baked in at build time because the same image is promoted across environments.
581
+ *
582
+ * @remarks
583
+ * Never rejects. Resolves to `fallback` when the request fails (network error, non-2xx status
584
+ * such as a 404) or the body isn't a JSON object. The last case covers an SPA fallback that serves
585
+ * `index.html` with a 200 for unknown paths. On success, the fetched values are shallow-merged over
586
+ * `fallback`. The request bypasses the HTTP cache so a redeployed config is picked up on reload.
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * type EnvConfig = { sentryDsn: string; environment: string };
591
+ * const { sentryDsn, environment = 'local' } = await fetchRuntimeConfig<EnvConfig>();
592
+ * if (sentryDsn) Sentry.init({ dsn: sentryDsn, environment });
593
+ * ```
594
+ *
595
+ * @param url - The config URL. Defaults to {@link DEFAULT_RUNTIME_CONFIG_URL}.
596
+ * @param fallback - Values to use when the config can't be read, and defaults for keys it omits.
597
+ * @returns The fetched config merged over `fallback`, or `fallback` alone.
598
+ * @public
599
+ */
600
+ export declare function fetchRuntimeConfig<T extends object>(url?: string, fallback?: Partial<T>): Promise<Partial<T>>;
601
+
572
602
  /**
573
603
  * An enum of possible font styles.
574
604
  * @public
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.46.5",
4
+ "version": "15.46.6-alpha-6d1bd2f25.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.46.5",
33
- "@genesislcap/genx": "15.46.5",
34
- "@genesislcap/ts-builder": "15.46.5",
35
- "@genesislcap/uvu-playwright-builder": "15.46.5",
36
- "@genesislcap/vite-builder": "15.46.5",
37
- "@genesislcap/webpack-builder": "15.46.5",
32
+ "@genesislcap/foundation-testing": "15.46.6-alpha-6d1bd2f25.0",
33
+ "@genesislcap/genx": "15.46.6-alpha-6d1bd2f25.0",
34
+ "@genesislcap/ts-builder": "15.46.6-alpha-6d1bd2f25.0",
35
+ "@genesislcap/uvu-playwright-builder": "15.46.6-alpha-6d1bd2f25.0",
36
+ "@genesislcap/vite-builder": "15.46.6-alpha-6d1bd2f25.0",
37
+ "@genesislcap/webpack-builder": "15.46.6-alpha-6d1bd2f25.0",
38
38
  "@types/json-schema": "^7.0.11"
39
39
  },
40
40
  "dependencies": {
41
- "@genesislcap/expression-builder": "15.46.5",
42
- "@genesislcap/foundation-logger": "15.46.5",
41
+ "@genesislcap/expression-builder": "15.46.6-alpha-6d1bd2f25.0",
42
+ "@genesislcap/foundation-logger": "15.46.6-alpha-6d1bd2f25.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",