@rxap/config 21.0.1-dev.1 → 22.0.0-dev.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/CHANGELOG.md +29 -0
- package/compodoc/changelog.html +27 -0
- package/compodoc/dependencies.html +5 -5
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +180 -180
- package/docs/html/classes/ConfigLoaderService.html +2 -2
- package/docs/html/classes/ConfigService.html +7 -7
- package/docs/html/classes/ConfigTestingService.html +2 -2
- package/docs/html/enums/ConfigLoadMethod.html +2 -2
- package/docs/html/enums/ConfigLoadingStrategy.html +2 -2
- package/docs/html/functions/ProvideConfig.html +1 -1
- package/docs/html/functions/defaultConfigLoadErrorHandler.html +2 -2
- package/docs/html/functions/dnsLookup.html +1 -1
- package/docs/html/functions/dnsResolver.html +1 -1
- package/docs/html/functions/fetchCidContent.html +1 -1
- package/docs/html/functions/fetchCidContentAsJson.html +1 -1
- package/docs/html/functions/fetchCidContentViaHttp.html +1 -1
- package/docs/html/functions/fetchContentViaHttp.html +1 -1
- package/docs/html/functions/localPathIpfsGateway.html +1 -1
- package/docs/html/functions/localSubDomainIpfsGateway.html +1 -1
- package/docs/html/functions/raceSuccess.html +2 -2
- package/docs/html/functions/showConfigLoadError.html +2 -2
- package/docs/html/functions/storachaIpfsGateway.html +1 -1
- package/docs/html/functions/w3sIpfsGateway.html +1 -1
- package/docs/html/hierarchy.html +1 -1
- package/docs/html/index.html +2 -2
- package/docs/html/interfaces/AppsNavigationConfig.html +2 -2
- package/docs/html/interfaces/Config.html +2 -2
- package/docs/html/interfaces/ConfigLoadError.html +4 -4
- package/docs/html/interfaces/ConfigLoadOptions.html +8 -8
- package/docs/html/interfaces/LogoConfig.html +2 -2
- package/docs/html/interfaces/NavigationConfig.html +2 -2
- package/docs/html/interfaces/Oauth2Config.html +2 -2
- package/docs/html/interfaces/i18nConfig.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/html/types/AnySchema.html +1 -1
- package/docs/html/types/ConfigLoadErrorHandler.html +2 -2
- package/docs/html/types/ConfigLoadErrorKind.html +2 -2
- package/docs/html/types/ConfigRequestOptions.html +1 -1
- package/docs/html/types/IpfsGatewayFunction.html +1 -1
- package/docs/html/types/Join.html +1 -1
- package/docs/html/types/LanguagesConfig.html +1 -1
- package/docs/html/types/Leaves.html +1 -1
- package/docs/html/types/NoInferType.html +1 -1
- package/docs/html/types/Paths.html +1 -1
- package/docs/html/variables/RXAP_CONFIG.html +1 -1
- package/docs/html/variables/defaultDnsServers.html +1 -1
- package/docs/html/variables/defaultIpfsGatewayServers.html +1 -1
- package/docs/markdown/README.md +1 -1
- package/docs/markdown/classes/ConfigLoaderService.md +6 -6
- package/docs/markdown/classes/ConfigService.md +23 -23
- package/docs/markdown/classes/ConfigTestingService.md +8 -8
- package/docs/markdown/enumerations/ConfigLoadMethod.md +6 -6
- package/docs/markdown/enumerations/ConfigLoadingStrategy.md +4 -4
- package/docs/markdown/functions/ProvideConfig.md +2 -2
- package/docs/markdown/functions/defaultConfigLoadErrorHandler.md +2 -2
- package/docs/markdown/functions/dnsLookup.md +2 -2
- package/docs/markdown/functions/dnsResolver.md +2 -2
- package/docs/markdown/functions/fetchCidContent.md +2 -2
- package/docs/markdown/functions/fetchCidContentAsJson.md +2 -2
- package/docs/markdown/functions/fetchCidContentViaHttp.md +2 -2
- package/docs/markdown/functions/fetchContentViaHttp.md +2 -2
- package/docs/markdown/functions/localPathIpfsGateway.md +2 -2
- package/docs/markdown/functions/localSubDomainIpfsGateway.md +2 -2
- package/docs/markdown/functions/raceSuccess.md +2 -2
- package/docs/markdown/functions/showConfigLoadError.md +2 -2
- package/docs/markdown/functions/storachaIpfsGateway.md +2 -2
- package/docs/markdown/functions/w3sIpfsGateway.md +2 -2
- package/docs/markdown/globals.md +2 -2
- package/docs/markdown/interfaces/AppsNavigationConfig.md +12 -12
- package/docs/markdown/interfaces/Config.md +6 -6
- package/docs/markdown/interfaces/ConfigLoadError.md +9 -9
- package/docs/markdown/interfaces/ConfigLoadOptions.md +17 -17
- package/docs/markdown/interfaces/LogoConfig.md +5 -5
- package/docs/markdown/interfaces/NavigationConfig.md +9 -9
- package/docs/markdown/interfaces/Oauth2Config.md +3 -3
- package/docs/markdown/interfaces/i18nConfig.md +4 -4
- package/docs/markdown/type-aliases/AnySchema.md +2 -2
- package/docs/markdown/type-aliases/ConfigLoadErrorHandler.md +2 -2
- package/docs/markdown/type-aliases/ConfigLoadErrorKind.md +2 -2
- package/docs/markdown/type-aliases/ConfigRequestOptions.md +2 -2
- package/docs/markdown/type-aliases/IpfsGatewayFunction.md +2 -2
- package/docs/markdown/type-aliases/Join.md +2 -2
- package/docs/markdown/type-aliases/LanguagesConfig.md +2 -2
- package/docs/markdown/type-aliases/Leaves.md +2 -2
- package/docs/markdown/type-aliases/NoInferType.md +2 -2
- package/docs/markdown/type-aliases/Paths.md +2 -2
- package/docs/markdown/variables/RXAP_CONFIG.md +2 -2
- package/docs/markdown/variables/defaultDnsServers.md +2 -2
- package/docs/markdown/variables/defaultIpfsGatewayServers.md +2 -2
- package/docs/wiki/Class.ConfigLoaderService.md +5 -5
- package/docs/wiki/Class.ConfigService.md +22 -22
- package/docs/wiki/Class.ConfigTestingService.md +7 -7
- package/docs/wiki/Enumeration.ConfigLoadMethod.md +5 -5
- package/docs/wiki/Enumeration.ConfigLoadingStrategy.md +3 -3
- package/docs/wiki/Function.ProvideConfig.md +1 -1
- package/docs/wiki/Function.defaultConfigLoadErrorHandler.md +1 -1
- package/docs/wiki/Function.dnsLookup.md +1 -1
- package/docs/wiki/Function.dnsResolver.md +1 -1
- package/docs/wiki/Function.fetchCidContent.md +1 -1
- package/docs/wiki/Function.fetchCidContentAsJson.md +1 -1
- package/docs/wiki/Function.fetchCidContentViaHttp.md +1 -1
- package/docs/wiki/Function.fetchContentViaHttp.md +1 -1
- package/docs/wiki/Function.localPathIpfsGateway.md +1 -1
- package/docs/wiki/Function.localSubDomainIpfsGateway.md +1 -1
- package/docs/wiki/Function.raceSuccess.md +1 -1
- package/docs/wiki/Function.showConfigLoadError.md +1 -1
- package/docs/wiki/Function.storachaIpfsGateway.md +1 -1
- package/docs/wiki/Function.w3sIpfsGateway.md +1 -1
- package/docs/wiki/Interface.AppsNavigationConfig.md +11 -11
- package/docs/wiki/Interface.Config.md +5 -5
- package/docs/wiki/Interface.ConfigLoadError.md +8 -8
- package/docs/wiki/Interface.ConfigLoadOptions.md +16 -16
- package/docs/wiki/Interface.LogoConfig.md +4 -4
- package/docs/wiki/Interface.NavigationConfig.md +8 -8
- package/docs/wiki/Interface.Oauth2Config.md +2 -2
- package/docs/wiki/Interface.i18nConfig.md +3 -3
- package/docs/wiki/TypeAlias.AnySchema.md +1 -1
- package/docs/wiki/TypeAlias.ConfigLoadErrorHandler.md +1 -1
- package/docs/wiki/TypeAlias.ConfigLoadErrorKind.md +1 -1
- package/docs/wiki/TypeAlias.ConfigRequestOptions.md +1 -1
- package/docs/wiki/TypeAlias.IpfsGatewayFunction.md +1 -1
- package/docs/wiki/TypeAlias.Join.md +1 -1
- package/docs/wiki/TypeAlias.LanguagesConfig.md +1 -1
- package/docs/wiki/TypeAlias.Leaves.md +1 -1
- package/docs/wiki/TypeAlias.NoInferType.md +1 -1
- package/docs/wiki/TypeAlias.Paths.md +1 -1
- package/docs/wiki/Variable.RXAP_CONFIG.md +1 -1
- package/docs/wiki/Variable.defaultDnsServers.md +1 -1
- package/docs/wiki/Variable.defaultIpfsGatewayServers.md +1 -1
- package/docs/wiki/globals.md +1 -1
- package/fesm2022/rxap-config.mjs +581 -713
- package/fesm2022/rxap-config.mjs.map +1 -1
- package/package.json +10 -10
- package/types/rxap-config.d.ts +223 -257
package/fesm2022/rxap-config.mjs
CHANGED
|
@@ -1,740 +1,608 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { HttpClient } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { log } from
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The default config load error handler. Shows the error message in an overlay and reloads the
|
|
11
|
-
* page after 30 s for required config urls. Logs a warning for optional config urls.
|
|
12
|
-
*
|
|
13
|
-
* Can be used as fallback in a custom error handler for error kinds it does not handle.
|
|
14
|
-
*/
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Inject, Injectable, InjectionToken, Optional, inject } from "@angular/core";
|
|
3
|
+
import { EMPTY, Observable, ReplaySubject, catchError, firstValueFrom, race } from "rxjs";
|
|
4
|
+
import { HttpClient } from "@angular/common/http";
|
|
5
|
+
import { finalize, share, tap } from "rxjs/operators";
|
|
6
|
+
import { CoercePrefix, JoinPath, SetObjectValue, SetToObject, coerceArray, deepMerge, getFromObject } from "@rxap/utilities";
|
|
7
|
+
import { log } from "@rxap/rxjs";
|
|
15
8
|
function defaultConfigLoadErrorHandler(error) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
console.warn(error.message);
|
|
21
|
-
}
|
|
9
|
+
if (error.required) showConfigLoadError(error.message);
|
|
10
|
+
else console.warn(error.message);
|
|
22
11
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Appends the message to the config error overlay and schedules a page reload in 30 s.
|
|
25
|
-
*/
|
|
26
12
|
function showConfigLoadError(message) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
setTimeout(() => location.reload(), 30000);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class ConfigLoaderService {
|
|
53
|
-
constructor() {
|
|
54
|
-
this.http = inject(HttpClient);
|
|
55
|
-
this.configs = new Map();
|
|
56
|
-
this.configLoading = new Map();
|
|
57
|
-
}
|
|
58
|
-
async load$(url) {
|
|
59
|
-
if (this.configs.has(url)) {
|
|
60
|
-
return this.configs.get(url);
|
|
61
|
-
}
|
|
62
|
-
if (this.configLoading.has(url)) {
|
|
63
|
-
return firstValueFrom(this.configLoading.get(url));
|
|
64
|
-
}
|
|
65
|
-
const loading$ = this.http.get(url).pipe(tap(config => this.configs.set(url, config)), finalize(() => this.configLoading.delete(url)), share());
|
|
66
|
-
this.configLoading.set(url, loading$);
|
|
67
|
-
return firstValueFrom(loading$);
|
|
68
|
-
}
|
|
69
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigLoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
70
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigLoaderService, providedIn: 'root' }); }
|
|
71
|
-
}
|
|
72
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigLoaderService, decorators: [{
|
|
73
|
-
type: Injectable,
|
|
74
|
-
args: [{ providedIn: 'root' }]
|
|
75
|
-
}] });
|
|
76
|
-
|
|
77
|
-
class ConfigTestingService {
|
|
78
|
-
constructor() {
|
|
79
|
-
this.config = {};
|
|
80
|
-
}
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
82
|
-
clearLocalConfig() {
|
|
83
|
-
}
|
|
84
|
-
set(propertyPath, value) {
|
|
85
|
-
SetToObject(this.config, propertyPath, value);
|
|
86
|
-
}
|
|
87
|
-
get(propertyPath, defaultValue) {
|
|
88
|
-
return getFromObject(this.config, propertyPath, defaultValue);
|
|
89
|
-
}
|
|
90
|
-
getOrThrow(propertyPath) {
|
|
91
|
-
const value = this.get(propertyPath);
|
|
92
|
-
if (value === undefined) {
|
|
93
|
-
throw new Error(`Could not find config in path '${propertyPath}'`);
|
|
94
|
-
}
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
98
|
-
setLocalConfig(config) {
|
|
99
|
-
}
|
|
100
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigTestingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
101
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigTestingService }); }
|
|
13
|
+
const hasUl = document.getElementById("rxap-config-error") !== null;
|
|
14
|
+
const ul = document.getElementById("rxap-config-error") ?? document.createElement("ul");
|
|
15
|
+
ul.id = "rxap-config-error";
|
|
16
|
+
ul.style.position = "fixed";
|
|
17
|
+
ul.style.bottom = "16px";
|
|
18
|
+
ul.style.right = "16px";
|
|
19
|
+
ul.style.backgroundColor = "white";
|
|
20
|
+
ul.style.padding = "32px";
|
|
21
|
+
ul.style.zIndex = "99999999";
|
|
22
|
+
ul.style.color = "black";
|
|
23
|
+
const messageLi = document.createElement("li");
|
|
24
|
+
messageLi.innerText = message;
|
|
25
|
+
ul.appendChild(messageLi);
|
|
26
|
+
const refreshHintLi = document.createElement("li");
|
|
27
|
+
refreshHintLi.innerText = "Please refresh the page to try again.";
|
|
28
|
+
ul.appendChild(refreshHintLi);
|
|
29
|
+
const autoRefreshHintLi = document.createElement("li");
|
|
30
|
+
autoRefreshHintLi.innerText = "The page will refresh automatically in 30 seconds.";
|
|
31
|
+
ul.appendChild(autoRefreshHintLi);
|
|
32
|
+
if (!hasUl) document.body.appendChild(ul);
|
|
33
|
+
setTimeout(() => location.reload(), 3e4);
|
|
102
34
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
35
|
+
var ConfigLoaderService = class ConfigLoaderService {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.http = inject(HttpClient);
|
|
38
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
39
|
+
this.configLoading = /* @__PURE__ */ new Map();
|
|
40
|
+
}
|
|
41
|
+
async load$(url) {
|
|
42
|
+
if (this.configs.has(url)) return this.configs.get(url);
|
|
43
|
+
if (this.configLoading.has(url)) return firstValueFrom(this.configLoading.get(url));
|
|
44
|
+
const loading$ = this.http.get(url).pipe(tap((config) => this.configs.set(url, config)), finalize(() => this.configLoading.delete(url)), share());
|
|
45
|
+
this.configLoading.set(url, loading$);
|
|
46
|
+
return firstValueFrom(loading$);
|
|
47
|
+
}
|
|
48
|
+
static {
|
|
49
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
50
|
+
minVersion: "12.0.0",
|
|
51
|
+
version: "22.3.0",
|
|
52
|
+
ngImport: i0,
|
|
53
|
+
type: ConfigLoaderService,
|
|
54
|
+
deps: [],
|
|
55
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static {
|
|
59
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
60
|
+
minVersion: "12.0.0",
|
|
61
|
+
version: "22.3.0",
|
|
62
|
+
ngImport: i0,
|
|
63
|
+
type: ConfigLoaderService,
|
|
64
|
+
providedIn: "root"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
69
|
+
minVersion: "12.0.0",
|
|
70
|
+
version: "22.3.0",
|
|
71
|
+
ngImport: i0,
|
|
72
|
+
type: ConfigLoaderService,
|
|
73
|
+
decorators: [{
|
|
74
|
+
type: Injectable,
|
|
75
|
+
args: [{ providedIn: "root" }]
|
|
76
|
+
}]
|
|
77
|
+
});
|
|
78
|
+
var ConfigTestingService = class ConfigTestingService {
|
|
79
|
+
constructor() {
|
|
80
|
+
this.config = {};
|
|
81
|
+
}
|
|
82
|
+
clearLocalConfig() {}
|
|
83
|
+
set(propertyPath, value) {
|
|
84
|
+
SetToObject(this.config, propertyPath, value);
|
|
85
|
+
}
|
|
86
|
+
get(propertyPath, defaultValue) {
|
|
87
|
+
return getFromObject(this.config, propertyPath, defaultValue);
|
|
88
|
+
}
|
|
89
|
+
getOrThrow(propertyPath) {
|
|
90
|
+
const value = this.get(propertyPath);
|
|
91
|
+
if (value === void 0) throw new Error(`Could not find config in path '${propertyPath}'`);
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
setLocalConfig(config) {}
|
|
95
|
+
static {
|
|
96
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
97
|
+
minVersion: "12.0.0",
|
|
98
|
+
version: "22.3.0",
|
|
99
|
+
ngImport: i0,
|
|
100
|
+
type: ConfigTestingService,
|
|
101
|
+
deps: [],
|
|
102
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static {
|
|
106
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
107
|
+
minVersion: "12.0.0",
|
|
108
|
+
version: "22.3.0",
|
|
109
|
+
ngImport: i0,
|
|
110
|
+
type: ConfigTestingService
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
115
|
+
minVersion: "12.0.0",
|
|
116
|
+
version: "22.3.0",
|
|
117
|
+
ngImport: i0,
|
|
118
|
+
type: ConfigTestingService,
|
|
119
|
+
decorators: [{ type: Injectable }]
|
|
120
|
+
});
|
|
121
|
+
const RXAP_CONFIG = new InjectionToken("rxap/config");
|
|
114
122
|
async function raceSuccess(promises) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (rejectionCount === promises.length) {
|
|
125
|
-
reject(new Error('All promises were rejected'));
|
|
126
|
-
}
|
|
127
|
-
// Otherwise continue waiting for other promises
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
let rejectionCount = 0;
|
|
125
|
+
promises.forEach((promise) => {
|
|
126
|
+
promise.then((value) => resolve(value), () => {
|
|
127
|
+
rejectionCount++;
|
|
128
|
+
if (rejectionCount === promises.length) reject(/* @__PURE__ */ new Error("All promises were rejected"));
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
131
132
|
}
|
|
132
133
|
async function dnsResolver(endpoint, name, type) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Basic validation of the response structure
|
|
147
|
-
if (!result || !Array.isArray(result.Answer) || result.Answer.length === 0 || !result.Answer[0].data) {
|
|
148
|
-
throw new Error(`Invalid DNS response structure from ${endpoint} for ${name} ${type}`);
|
|
149
|
-
}
|
|
150
|
-
const data = result.Answer[0].data;
|
|
151
|
-
// Remove surrounding quotes often found in TXT records
|
|
152
|
-
return data.replace(/^"(.*)"$/, '$1');
|
|
134
|
+
const response = await fetch(`${endpoint}?name=${name}&type=${type}`, {
|
|
135
|
+
method: "GET",
|
|
136
|
+
headers: {
|
|
137
|
+
"Accept": "application/dns-json",
|
|
138
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
139
|
+
"Pragma": "no-cache",
|
|
140
|
+
"Expires": "0"
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
if (!response.ok) throw new Error(`Failed to resolve DNS via ${endpoint} (${response.status}): ${response.statusText}`);
|
|
144
|
+
const result = await response.json();
|
|
145
|
+
if (!result || !Array.isArray(result.Answer) || result.Answer.length === 0 || !result.Answer[0].data) throw new Error(`Invalid DNS response structure from ${endpoint} for ${name} ${type}`);
|
|
146
|
+
return result.Answer[0].data.replace(/^"(.*)"$/, "$1");
|
|
153
147
|
}
|
|
154
|
-
const defaultDnsServers = [
|
|
155
|
-
'https://dns.google/resolve',
|
|
156
|
-
'https://cloudflare-dns.com/dns-query'
|
|
157
|
-
];
|
|
148
|
+
const defaultDnsServers = ["https://dns.google/resolve", "https://cloudflare-dns.com/dns-query"];
|
|
158
149
|
async function dnsLookup(name, type, dnsServers = defaultDnsServers) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.error(`Failed to resolve DNS TXT record for ${name} using any server: ${error.message}`);
|
|
170
|
-
throw new Error(`DNS lookup failed for ${name} (${type})`); // Re-throw a more specific error
|
|
171
|
-
}
|
|
150
|
+
if (!dnsServers.length) throw new Error("No DNS servers provided for lookup");
|
|
151
|
+
type = type.toUpperCase();
|
|
152
|
+
console.log(`Performing DNS lookup for ${type} record of ${name} using servers: ${dnsServers.join(", ")}`);
|
|
153
|
+
try {
|
|
154
|
+
return await raceSuccess(dnsServers.map((server) => dnsResolver(server, name, type)));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error(`Failed to resolve DNS TXT record for ${name} using any server: ${error.message}`);
|
|
157
|
+
throw new Error(`DNS lookup failed for ${name} (${type})`);
|
|
158
|
+
}
|
|
172
159
|
}
|
|
173
160
|
function fetchContentViaHttp(url) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
controller?.abort();
|
|
199
|
-
controller = null; // Release reference
|
|
200
|
-
};
|
|
201
|
-
}).pipe(catchError(error => {
|
|
202
|
-
// Log the error but return null to signal failure without stopping the race
|
|
203
|
-
console.error(`Fetch failed for ${url}: ${error.message}`);
|
|
204
|
-
return EMPTY; // Signal failure with null
|
|
205
|
-
}));
|
|
161
|
+
return new Observable((subscriber) => {
|
|
162
|
+
let controller = new AbortController();
|
|
163
|
+
fetch(url, { signal: controller.signal }).then((response) => {
|
|
164
|
+
if (!response.ok) throw new Error(`HTTP error ${response.status} for ${url}: ${response.statusText}`);
|
|
165
|
+
return response.blob();
|
|
166
|
+
}).then((blob) => {
|
|
167
|
+
if (!subscriber.closed) {
|
|
168
|
+
subscriber.next(blob);
|
|
169
|
+
subscriber.complete();
|
|
170
|
+
}
|
|
171
|
+
}).catch((error) => {
|
|
172
|
+
if (error.name !== "AbortError" && !subscriber.closed) {
|
|
173
|
+
console.warn(`Fetch error for ${url}:`, error);
|
|
174
|
+
subscriber.error(error);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return () => {
|
|
178
|
+
controller?.abort();
|
|
179
|
+
controller = null;
|
|
180
|
+
};
|
|
181
|
+
}).pipe(catchError((error) => {
|
|
182
|
+
console.error(`Fetch failed for ${url}: ${error.message}`);
|
|
183
|
+
return EMPTY;
|
|
184
|
+
}));
|
|
206
185
|
}
|
|
207
|
-
const w3sIpfsGateway = cid => `https://${cid}.ipfs.w3s.link`;
|
|
208
|
-
const storachaIpfsGateway = cid => `https://${cid}.ipfs.storacha.link`;
|
|
209
|
-
const localPathIpfsGateway = cid => `${location.origin}/ipfs/${cid}`;
|
|
210
|
-
const localSubDomainIpfsGateway = cid => `https://${cid}.ipfs.${location.hostname.split(
|
|
186
|
+
const w3sIpfsGateway = (cid) => `https://${cid}.ipfs.w3s.link`;
|
|
187
|
+
const storachaIpfsGateway = (cid) => `https://${cid}.ipfs.storacha.link`;
|
|
188
|
+
const localPathIpfsGateway = (cid) => `${location.origin}/ipfs/${cid}`;
|
|
189
|
+
const localSubDomainIpfsGateway = (cid) => `https://${cid}.ipfs.${location.hostname.split(".").slice(-2).join(".")}`;
|
|
211
190
|
const defaultIpfsGatewayServers = [
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
w3sIpfsGateway,
|
|
192
|
+
storachaIpfsGateway,
|
|
193
|
+
localPathIpfsGateway,
|
|
194
|
+
localSubDomainIpfsGateway
|
|
216
195
|
];
|
|
217
196
|
function fetchCidContentViaHttp(cid, path, ipfsGatewayServers = defaultIpfsGatewayServers) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
return race(...ipfsGatewayServers.map(fnc => fetchContentViaHttp(JoinPath(fnc(cid), path)).pipe(log(`fetch attempt for ${cid} via ${fnc.name} - ${fnc(cid)}`)))
|
|
222
|
-
// Add more sources here if needed
|
|
223
|
-
).pipe(log(`Race winner for ${cid}`));
|
|
197
|
+
if (!ipfsGatewayServers.length) throw new Error("No IPFS gateway servers provided for fetching content");
|
|
198
|
+
return race(...ipfsGatewayServers.map((fnc) => fetchContentViaHttp(JoinPath(fnc(cid), path)).pipe(log(`fetch attempt for ${cid} via ${fnc.name} - ${fnc(cid)}`)))).pipe(log(`Race winner for ${cid}`));
|
|
224
199
|
}
|
|
225
200
|
async function fetchCidContent(cid, path, ipfsGatewayServers = defaultIpfsGatewayServers) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
catch (error) {
|
|
234
|
-
console.error(`Error fetching or parsing content for CID ${cid}:`, error);
|
|
235
|
-
return null; // Return null on error
|
|
236
|
-
}
|
|
201
|
+
console.log(`Fetching content for CID: ${cid}`);
|
|
202
|
+
try {
|
|
203
|
+
return await firstValueFrom(race(fetchCidContentViaHttp(cid, path, ipfsGatewayServers)), { defaultValue: null });
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error(`Error fetching or parsing content for CID ${cid}:`, error);
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
237
208
|
}
|
|
238
209
|
async function fetchCidContentAsJson(cid, path, _fetchCidContent = fetchCidContent, ipfsGatewayServers = defaultIpfsGatewayServers) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
console.warn(`No blob available for CID ${cid}, cannot parse as JSON.`);
|
|
252
|
-
return null; // Return null if blob is not available
|
|
210
|
+
console.log(`Fetching JSON content for CID: ${cid}`);
|
|
211
|
+
const blob = await _fetchCidContent(cid, path, ipfsGatewayServers);
|
|
212
|
+
if (blob) try {
|
|
213
|
+
const text = await blob.text();
|
|
214
|
+
return JSON.parse(text);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error(`Error parsing JSON content for CID ${cid}:`, error);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
console.warn(`No blob available for CID ${cid}, cannot parse as JSON.`);
|
|
220
|
+
return null;
|
|
253
221
|
}
|
|
254
|
-
|
|
255
222
|
var ConfigLoadingStrategy;
|
|
256
|
-
(function
|
|
257
|
-
|
|
258
|
-
|
|
223
|
+
(function(ConfigLoadingStrategy) {
|
|
224
|
+
ConfigLoadingStrategy["DEFAULT"] = "default";
|
|
225
|
+
ConfigLoadingStrategy["FIFO"] = "fifo";
|
|
259
226
|
})(ConfigLoadingStrategy || (ConfigLoadingStrategy = {}));
|
|
260
227
|
var ConfigLoadMethod;
|
|
261
|
-
(function
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
228
|
+
(function(ConfigLoadMethod) {
|
|
229
|
+
ConfigLoadMethod["FROM_URLS"] = "fromUrls";
|
|
230
|
+
ConfigLoadMethod["FROM_LOCAL_STORAGE"] = "fromLocalStorage";
|
|
231
|
+
ConfigLoadMethod["FROM_URL_PARAM"] = "fromUrlParam";
|
|
232
|
+
ConfigLoadMethod["FROM_CID"] = "fromCid";
|
|
266
233
|
})(ConfigLoadMethod || (ConfigLoadMethod = {}));
|
|
267
|
-
class ConfigService {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const errorHandler = options.errorHandler ?? defaultConfigLoadErrorHandler;
|
|
634
|
-
try {
|
|
635
|
-
await errorHandler(error);
|
|
636
|
-
}
|
|
637
|
-
catch (e) {
|
|
638
|
-
console.error('Error in config load error handler', e);
|
|
639
|
-
}
|
|
640
|
-
if (error.required) {
|
|
641
|
-
throw new Error(error.message);
|
|
642
|
-
}
|
|
643
|
-
return null;
|
|
644
|
-
}
|
|
645
|
-
static LoadConfigDefaultFromUrlParam(param = 'config') {
|
|
646
|
-
const queryString = window.location.search;
|
|
647
|
-
const urlParams = new URLSearchParams(queryString);
|
|
648
|
-
const configFromParams = {};
|
|
649
|
-
for (const configParam of urlParams.getAll(param)) {
|
|
650
|
-
try {
|
|
651
|
-
const split = configParam.split(';');
|
|
652
|
-
if (split.length === 2) {
|
|
653
|
-
const keyPath = split[0];
|
|
654
|
-
const value = split[1];
|
|
655
|
-
SetObjectValue(configFromParams, keyPath, value);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
catch (e) {
|
|
659
|
-
console.warn(`Parsing of url config param failed for '${configParam}': ${e.message}`);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return configFromParams;
|
|
663
|
-
}
|
|
664
|
-
static async SideLoad(url, propertyPath, required, schema, options = this.RequestOptions) {
|
|
665
|
-
if (!this.Config) {
|
|
666
|
-
throw new Error('Config side load is only possible after the initial config load.');
|
|
667
|
-
}
|
|
668
|
-
const config = await this.loadConfig(url, required, schema, options);
|
|
669
|
-
SetObjectValue(this.Config, propertyPath, config);
|
|
670
|
-
console.debug(`Side loaded config for '${propertyPath}' successful`, this.Config);
|
|
671
|
-
}
|
|
672
|
-
static Get(path, defaultValue, config = this.Config) {
|
|
673
|
-
if (!config) {
|
|
674
|
-
throw new Error('config not loaded');
|
|
675
|
-
}
|
|
676
|
-
let configValue = config;
|
|
677
|
-
if (typeof path !== 'string') {
|
|
678
|
-
throw new Error('The config property path is not a string');
|
|
679
|
-
}
|
|
680
|
-
for (const fragment of path.split('.')) {
|
|
681
|
-
if (configValue && typeof configValue === 'object' && fragment in configValue) {
|
|
682
|
-
configValue = configValue[fragment];
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
if (defaultValue !== undefined) {
|
|
686
|
-
return defaultValue;
|
|
687
|
-
}
|
|
688
|
-
console.debug(`Config with path '${path}' not found`);
|
|
689
|
-
return undefined;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
return configValue;
|
|
693
|
-
}
|
|
694
|
-
setLocalConfig(config) {
|
|
695
|
-
localStorage.setItem(ConfigService.LocalStorageKey, JSON.stringify(config));
|
|
696
|
-
}
|
|
697
|
-
clearLocalConfig() {
|
|
698
|
-
localStorage.removeItem(ConfigService.LocalStorageKey);
|
|
699
|
-
}
|
|
700
|
-
get(propertyPath, defaultValue) {
|
|
701
|
-
return ConfigService.Get(propertyPath, defaultValue, this.config);
|
|
702
|
-
}
|
|
703
|
-
getOrThrow(propertyPath, defaultValue) {
|
|
704
|
-
const value = ConfigService.Get(propertyPath, defaultValue, this.config);
|
|
705
|
-
if (value === undefined) {
|
|
706
|
-
throw new Error(`Could not find config in path '${propertyPath}'`);
|
|
707
|
-
}
|
|
708
|
-
return value;
|
|
709
|
-
}
|
|
710
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigService, deps: [{ token: RXAP_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
711
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigService, providedIn: 'root' }); }
|
|
712
|
-
}
|
|
713
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ConfigService, decorators: [{
|
|
714
|
-
type: Injectable,
|
|
715
|
-
args: [{
|
|
716
|
-
providedIn: 'root',
|
|
717
|
-
}]
|
|
718
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
719
|
-
type: Optional
|
|
720
|
-
}, {
|
|
721
|
-
type: Inject,
|
|
722
|
-
args: [RXAP_CONFIG]
|
|
723
|
-
}] }] });
|
|
724
|
-
|
|
234
|
+
var ConfigService = class ConfigService {
|
|
235
|
+
static {
|
|
236
|
+
this.onError = new ReplaySubject(1);
|
|
237
|
+
}
|
|
238
|
+
static {
|
|
239
|
+
this.onRequestError = new ReplaySubject(1);
|
|
240
|
+
}
|
|
241
|
+
static {
|
|
242
|
+
this.onErrorFnc = [];
|
|
243
|
+
}
|
|
244
|
+
static {
|
|
245
|
+
this.onRequestErrorFnc = [];
|
|
246
|
+
}
|
|
247
|
+
static {
|
|
248
|
+
this.Config = null;
|
|
249
|
+
}
|
|
250
|
+
static {
|
|
251
|
+
this.Defaults = {};
|
|
252
|
+
}
|
|
253
|
+
static {
|
|
254
|
+
this.Overwrites = {};
|
|
255
|
+
}
|
|
256
|
+
static {
|
|
257
|
+
this.LocalStorageKey = "rxap/config/local-config";
|
|
258
|
+
}
|
|
259
|
+
static {
|
|
260
|
+
this.RequestOptions = {};
|
|
261
|
+
}
|
|
262
|
+
static {
|
|
263
|
+
this.Urls = [];
|
|
264
|
+
}
|
|
265
|
+
constructor(config = null) {
|
|
266
|
+
this.config = ConfigService.Config;
|
|
267
|
+
if (config) this.config = deepMerge(this.config ?? {}, config);
|
|
268
|
+
if (!this.config) throw new Error("config not available");
|
|
269
|
+
}
|
|
270
|
+
static async Load(options, environment) {
|
|
271
|
+
options ??= {};
|
|
272
|
+
this.RequestOptions = {
|
|
273
|
+
errorHandler: options.errorHandler,
|
|
274
|
+
requestInit: options.requestInit
|
|
275
|
+
};
|
|
276
|
+
let config = deepMerge(this.Defaults, {});
|
|
277
|
+
if (environment?.config) {
|
|
278
|
+
if (typeof environment.config === "string") options.url = environment.config;
|
|
279
|
+
else {
|
|
280
|
+
options.static = environment.config.static;
|
|
281
|
+
options.url = environment.config.url;
|
|
282
|
+
options.fromUrlParam = environment.config.fromUrlParam;
|
|
283
|
+
options.fromLocalStorage = environment.config.fromLocalStorage;
|
|
284
|
+
options.schema = environment.config.schema;
|
|
285
|
+
options.strategy = environment.config.strategy ?? options.strategy;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
config = deepMerge(config, options?.static ?? {});
|
|
289
|
+
const order = options.order ?? [
|
|
290
|
+
ConfigLoadMethod.FROM_URLS,
|
|
291
|
+
ConfigLoadMethod.FROM_LOCAL_STORAGE,
|
|
292
|
+
ConfigLoadMethod.FROM_URL_PARAM,
|
|
293
|
+
ConfigLoadMethod.FROM_CID
|
|
294
|
+
];
|
|
295
|
+
if (options.fromDns && order.includes(ConfigLoadMethod.FROM_CID) && !options.fromCid) await this.loadConfigFromDns(options);
|
|
296
|
+
let done = false;
|
|
297
|
+
for (const method of order) {
|
|
298
|
+
if (done) break;
|
|
299
|
+
if (!this.isSourceEnabled(options, method)) continue;
|
|
300
|
+
try {
|
|
301
|
+
const loadedConfig = await this.loadConfigFromMethod(method, options, environment);
|
|
302
|
+
if (loadedConfig) config = deepMerge(config, loadedConfig);
|
|
303
|
+
if (options.strategy === ConfigLoadingStrategy.FIFO) done = true;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
const methodName = this.getMethodName(method);
|
|
306
|
+
if (options.strategy !== ConfigLoadingStrategy.FIFO) {
|
|
307
|
+
console.error(`Could not load config from ${methodName}`, error);
|
|
308
|
+
throw error;
|
|
309
|
+
} else console.warn(`Could not load config from ${methodName}: ${error.message}. Will try next strategy.`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (!done && order.length > 0) console.warn("No config loading strategy succeeded. Using default config.");
|
|
313
|
+
config = deepMerge(config, this.Overwrites);
|
|
314
|
+
console.debug("app config", config);
|
|
315
|
+
this.Config = config;
|
|
316
|
+
}
|
|
317
|
+
static isSourceEnabled(options, method) {
|
|
318
|
+
switch (method) {
|
|
319
|
+
case ConfigLoadMethod.FROM_URLS: return options.fromUrls !== false;
|
|
320
|
+
case ConfigLoadMethod.FROM_LOCAL_STORAGE: return options.fromLocalStorage !== false;
|
|
321
|
+
case ConfigLoadMethod.FROM_URL_PARAM: return !!options.fromUrlParam;
|
|
322
|
+
case ConfigLoadMethod.FROM_CID: return !!options.fromCid;
|
|
323
|
+
default: return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
static async loadConfigFromMethod(method, options, environment) {
|
|
327
|
+
switch (method) {
|
|
328
|
+
case ConfigLoadMethod.FROM_URLS: return await this.loadConfigFromUrls(options, environment);
|
|
329
|
+
case ConfigLoadMethod.FROM_LOCAL_STORAGE: return this.loadConfigFromLocalStorage(options);
|
|
330
|
+
case ConfigLoadMethod.FROM_URL_PARAM: return this.loadConfigFromUrlParam(options);
|
|
331
|
+
case ConfigLoadMethod.FROM_CID: return await this.loadConfigFromCid(options);
|
|
332
|
+
default: return null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
static getMethodName(method) {
|
|
336
|
+
switch (method) {
|
|
337
|
+
case ConfigLoadMethod.FROM_URLS: return "urls";
|
|
338
|
+
case ConfigLoadMethod.FROM_LOCAL_STORAGE: return "local storage";
|
|
339
|
+
case ConfigLoadMethod.FROM_URL_PARAM: return "url param";
|
|
340
|
+
case ConfigLoadMethod.FROM_CID: return "cid";
|
|
341
|
+
default: return "unknown";
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
static loadConfigFromUrlParam(options) {
|
|
345
|
+
const param = typeof options.fromUrlParam === "string" ? options.fromUrlParam : "config";
|
|
346
|
+
return this.LoadConfigDefaultFromUrlParam(param);
|
|
347
|
+
}
|
|
348
|
+
static loadConfigFromLocalStorage(options) {
|
|
349
|
+
const localConfig = localStorage.getItem(ConfigService.LocalStorageKey);
|
|
350
|
+
if (localConfig) return JSON.parse(localConfig);
|
|
351
|
+
else return {};
|
|
352
|
+
}
|
|
353
|
+
static async loadConfigFromUrls(options, environment) {
|
|
354
|
+
let config = {};
|
|
355
|
+
const urls = (options?.url ? coerceArray(options.url) : ConfigService.Urls).map((url) => {
|
|
356
|
+
if (typeof url === "function") {
|
|
357
|
+
if (!environment) throw new Error("environment is required when url is a function");
|
|
358
|
+
return coerceArray(url(environment));
|
|
359
|
+
}
|
|
360
|
+
return coerceArray(url);
|
|
361
|
+
}).flat();
|
|
362
|
+
for (const url of urls) {
|
|
363
|
+
const loadedConfig = await this.loadConfig(url, true, options?.schema, options);
|
|
364
|
+
const match = url.match(/config\.([a-zA-Z0-9.\-_]+)\.json/);
|
|
365
|
+
if (match) SetToObject(config, match[1], loadedConfig);
|
|
366
|
+
else config = deepMerge(config, loadedConfig);
|
|
367
|
+
}
|
|
368
|
+
return config;
|
|
369
|
+
}
|
|
370
|
+
static async loadConfigFromCid(options) {
|
|
371
|
+
console.debug("Loading config from CID: ", options.fromCid);
|
|
372
|
+
const ipfsGatewayFunctions = options.ipfsGatewayServers ?? [];
|
|
373
|
+
if (!ipfsGatewayFunctions.length) {
|
|
374
|
+
console.warn("No IPFS gateway servers provided for fetching content from CID");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
const cidContent = await fetchCidContentAsJson(options.fromCid, void 0, options.fetchCidContent, ipfsGatewayFunctions);
|
|
379
|
+
if (cidContent && typeof cidContent === "object") {
|
|
380
|
+
console.log(`Merging configuration from CID ${options.fromCid}.`, cidContent);
|
|
381
|
+
console.log("Configuration merged successfully.");
|
|
382
|
+
return cidContent;
|
|
383
|
+
} else if (cidContent) console.warn(`Content fetched from CID ${options.fromCid} is not a mergeable object, skipping merge.`);
|
|
384
|
+
else console.warn(`No content fetched or content was null for CID ${options.fromCid}.`);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error(`Failed to fetch or process content for CID ${options.fromCid}: ${error.message}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
static async loadConfigFromDns(options) {
|
|
390
|
+
console.debug("Loading config from DNS");
|
|
391
|
+
const dnsServers = options.dnsServers ?? [];
|
|
392
|
+
if (!dnsServers.length) {
|
|
393
|
+
console.warn("No DNS servers provided for DNS lookup");
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
let domain = location.hostname;
|
|
397
|
+
if (typeof options.fromDns === "string") domain = options.fromDns;
|
|
398
|
+
domain = CoercePrefix(domain, "_config.");
|
|
399
|
+
try {
|
|
400
|
+
console.log(`Attempting DNS lookup for domain: ${domain}`);
|
|
401
|
+
const txtData = await dnsLookup(domain, "TXT", dnsServers);
|
|
402
|
+
console.log(`DNS TXT record data found: ${txtData}`);
|
|
403
|
+
const cidMatch = txtData.match(/(?:ipfs:\/\/|\/|^)([a-zA-Z0-9]{40,})$/);
|
|
404
|
+
if (cidMatch && cidMatch[1]) {
|
|
405
|
+
options.fromCid = cidMatch[1];
|
|
406
|
+
console.log(`Extracted CID from DNS: ${options.fromCid}`);
|
|
407
|
+
} else console.warn(`Could not extract a valid CID format from DNS TXT data: "${txtData}"`);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
console.error(`DNS lookup for ${domain} failed: ${error.message}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
static handleError(error) {
|
|
413
|
+
this.onError.next(error);
|
|
414
|
+
for (const fnc of this.onErrorFnc) try {
|
|
415
|
+
fnc(error);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
console.error("Error in onErrorFnc", e);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
static handleRequestError(response) {
|
|
421
|
+
this.onRequestError.next(response);
|
|
422
|
+
for (const fnc of this.onRequestErrorFnc) try {
|
|
423
|
+
fnc(response);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
console.error("Error in onRequestErrorFnc", e);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
static async loadConfig(url, required = false, schema, options = this.RequestOptions) {
|
|
429
|
+
let config;
|
|
430
|
+
let response;
|
|
431
|
+
try {
|
|
432
|
+
response = await fetch(url, options.requestInit);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
return this.handleLoadError({
|
|
435
|
+
kind: "network",
|
|
436
|
+
url,
|
|
437
|
+
required,
|
|
438
|
+
cause: error,
|
|
439
|
+
message: `Could not fetch config from '${url}': ${error.message}`
|
|
440
|
+
}, options);
|
|
441
|
+
}
|
|
442
|
+
if (response.type === "opaqueredirect") return this.handleLoadError({
|
|
443
|
+
kind: "redirect",
|
|
444
|
+
url,
|
|
445
|
+
required,
|
|
446
|
+
status: response.status,
|
|
447
|
+
response,
|
|
448
|
+
message: `Config request for '${url}' was redirected`
|
|
449
|
+
}, options);
|
|
450
|
+
if (!response.ok) {
|
|
451
|
+
let message = `Config request results in non ok response for '${url}': (${response.status}) ${response.statusText}`;
|
|
452
|
+
switch (response.status) {
|
|
453
|
+
case 404:
|
|
454
|
+
message = `Config not found at '${url}'`;
|
|
455
|
+
break;
|
|
456
|
+
case 405:
|
|
457
|
+
message = `Config service is not started yet. Wait 30s and try again.`;
|
|
458
|
+
break;
|
|
459
|
+
case 401: message = `Unauthorized to fetch config from '${url}'`;
|
|
460
|
+
}
|
|
461
|
+
return this.handleLoadError({
|
|
462
|
+
kind: "http",
|
|
463
|
+
url,
|
|
464
|
+
required,
|
|
465
|
+
status: response.status,
|
|
466
|
+
response,
|
|
467
|
+
message
|
|
468
|
+
}, options);
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
config = await response.json();
|
|
472
|
+
} catch (error) {
|
|
473
|
+
return this.handleLoadError({
|
|
474
|
+
kind: "parse",
|
|
475
|
+
url,
|
|
476
|
+
required,
|
|
477
|
+
status: response.status,
|
|
478
|
+
response,
|
|
479
|
+
cause: error,
|
|
480
|
+
message: `Could not parse config from '${url}' to a json object: ${error.message}`
|
|
481
|
+
}, options);
|
|
482
|
+
}
|
|
483
|
+
if (schema) try {
|
|
484
|
+
config = await schema.validateAsync(config);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
return this.handleLoadError({
|
|
487
|
+
kind: "schema",
|
|
488
|
+
url,
|
|
489
|
+
required,
|
|
490
|
+
status: response.status,
|
|
491
|
+
response,
|
|
492
|
+
cause: error,
|
|
493
|
+
message: `Config from '${url}' is not valid: ${error.message}`
|
|
494
|
+
}, options);
|
|
495
|
+
}
|
|
496
|
+
return config;
|
|
497
|
+
}
|
|
498
|
+
static async handleLoadError(error, options) {
|
|
499
|
+
if (error.required) {
|
|
500
|
+
if (error.response && (error.kind === "http" || error.kind === "redirect")) this.handleRequestError(error.response);
|
|
501
|
+
else this.handleError(error.cause);
|
|
502
|
+
}
|
|
503
|
+
const errorHandler = options.errorHandler ?? defaultConfigLoadErrorHandler;
|
|
504
|
+
try {
|
|
505
|
+
await errorHandler(error);
|
|
506
|
+
} catch (e) {
|
|
507
|
+
console.error("Error in config load error handler", e);
|
|
508
|
+
}
|
|
509
|
+
if (error.required) throw new Error(error.message);
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
static LoadConfigDefaultFromUrlParam(param = "config") {
|
|
513
|
+
const queryString = window.location.search;
|
|
514
|
+
const urlParams = new URLSearchParams(queryString);
|
|
515
|
+
const configFromParams = {};
|
|
516
|
+
for (const configParam of urlParams.getAll(param)) try {
|
|
517
|
+
const split = configParam.split(";");
|
|
518
|
+
if (split.length === 2) {
|
|
519
|
+
const keyPath = split[0];
|
|
520
|
+
const value = split[1];
|
|
521
|
+
SetObjectValue(configFromParams, keyPath, value);
|
|
522
|
+
}
|
|
523
|
+
} catch (e) {
|
|
524
|
+
console.warn(`Parsing of url config param failed for '${configParam}': ${e.message}`);
|
|
525
|
+
}
|
|
526
|
+
return configFromParams;
|
|
527
|
+
}
|
|
528
|
+
static async SideLoad(url, propertyPath, required, schema, options = this.RequestOptions) {
|
|
529
|
+
if (!this.Config) throw new Error("Config side load is only possible after the initial config load.");
|
|
530
|
+
const config = await this.loadConfig(url, required, schema, options);
|
|
531
|
+
SetObjectValue(this.Config, propertyPath, config);
|
|
532
|
+
console.debug(`Side loaded config for '${propertyPath}' successful`, this.Config);
|
|
533
|
+
}
|
|
534
|
+
static Get(path, defaultValue, config = this.Config) {
|
|
535
|
+
if (!config) throw new Error("config not loaded");
|
|
536
|
+
let configValue = config;
|
|
537
|
+
if (typeof path !== "string") throw new Error("The config property path is not a string");
|
|
538
|
+
for (const fragment of path.split(".")) if (configValue && typeof configValue === "object" && fragment in configValue) configValue = configValue[fragment];
|
|
539
|
+
else {
|
|
540
|
+
if (defaultValue !== void 0) return defaultValue;
|
|
541
|
+
console.debug(`Config with path '${path}' not found`);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
return configValue;
|
|
545
|
+
}
|
|
546
|
+
setLocalConfig(config) {
|
|
547
|
+
localStorage.setItem(ConfigService.LocalStorageKey, JSON.stringify(config));
|
|
548
|
+
}
|
|
549
|
+
clearLocalConfig() {
|
|
550
|
+
localStorage.removeItem(ConfigService.LocalStorageKey);
|
|
551
|
+
}
|
|
552
|
+
get(propertyPath, defaultValue) {
|
|
553
|
+
return ConfigService.Get(propertyPath, defaultValue, this.config);
|
|
554
|
+
}
|
|
555
|
+
getOrThrow(propertyPath, defaultValue) {
|
|
556
|
+
const value = ConfigService.Get(propertyPath, defaultValue, this.config);
|
|
557
|
+
if (value === void 0) throw new Error(`Could not find config in path '${propertyPath}'`);
|
|
558
|
+
return value;
|
|
559
|
+
}
|
|
560
|
+
static {
|
|
561
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
562
|
+
minVersion: "12.0.0",
|
|
563
|
+
version: "22.3.0",
|
|
564
|
+
ngImport: i0,
|
|
565
|
+
type: ConfigService,
|
|
566
|
+
deps: [{
|
|
567
|
+
token: RXAP_CONFIG,
|
|
568
|
+
optional: true
|
|
569
|
+
}],
|
|
570
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
static {
|
|
574
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
575
|
+
minVersion: "12.0.0",
|
|
576
|
+
version: "22.3.0",
|
|
577
|
+
ngImport: i0,
|
|
578
|
+
type: ConfigService,
|
|
579
|
+
providedIn: "root"
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
584
|
+
minVersion: "12.0.0",
|
|
585
|
+
version: "22.3.0",
|
|
586
|
+
ngImport: i0,
|
|
587
|
+
type: ConfigService,
|
|
588
|
+
decorators: [{
|
|
589
|
+
type: Injectable,
|
|
590
|
+
args: [{ providedIn: "root" }]
|
|
591
|
+
}],
|
|
592
|
+
ctorParameters: () => [{
|
|
593
|
+
type: void 0,
|
|
594
|
+
decorators: [{ type: Optional }, {
|
|
595
|
+
type: Inject,
|
|
596
|
+
args: [RXAP_CONFIG]
|
|
597
|
+
}]
|
|
598
|
+
}]
|
|
599
|
+
});
|
|
725
600
|
function ProvideConfig(config = {}) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
601
|
+
return {
|
|
602
|
+
provide: RXAP_CONFIG,
|
|
603
|
+
useValue: config
|
|
604
|
+
};
|
|
730
605
|
}
|
|
731
|
-
|
|
732
|
-
// region
|
|
733
|
-
// endregion
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* Generated bundle index. Do not edit.
|
|
737
|
-
*/
|
|
738
|
-
|
|
739
606
|
export { ConfigLoadMethod, ConfigLoaderService, ConfigLoadingStrategy, ConfigService, ConfigTestingService, ProvideConfig, RXAP_CONFIG, defaultConfigLoadErrorHandler, defaultDnsServers, defaultIpfsGatewayServers, dnsLookup, dnsResolver, fetchCidContent, fetchCidContentAsJson, fetchCidContentViaHttp, fetchContentViaHttp, localPathIpfsGateway, localSubDomainIpfsGateway, raceSuccess, showConfigLoadError, storachaIpfsGateway, w3sIpfsGateway };
|
|
740
|
-
|
|
607
|
+
|
|
608
|
+
//# sourceMappingURL=rxap-config.mjs.map
|