@indice/ng-config 0.6.0-beta.1 → 0.6.0-beta.2
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.
|
@@ -1,151 +1,175 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import * as i1 from
|
|
4
|
-
import { HttpClient } from
|
|
5
|
-
import {
|
|
6
|
-
import cloneDeep from
|
|
7
|
-
import merge from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
isTemplate: false,
|
|
42
|
-
production: false,
|
|
43
|
-
version: ''
|
|
44
|
-
},
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Inject, Injectable, InjectionToken, Injector, computed, inject, isDevMode, makeEnvironmentProviders, provideAppInitializer, signal } from "@angular/core";
|
|
3
|
+
import * as i1 from "@angular/common/http";
|
|
4
|
+
import { HttpClient } from "@angular/common/http";
|
|
5
|
+
import { lastValueFrom, of } from "rxjs";
|
|
6
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
7
|
+
import merge from "lodash/merge";
|
|
8
|
+
import { catchError, map, tap } from "rxjs/operators";
|
|
9
|
+
const APP_SETTINGS = new InjectionToken("APP_SETTINGS");
|
|
10
|
+
const IAUTH_SETTINGS = new InjectionToken("IAUTH_SETTINGS");
|
|
11
|
+
const APP_ENVIRONMENT = new InjectionToken("APP_ENVIRONMENT");
|
|
12
|
+
const APP_PROVIDERS_ARRAY = new InjectionToken("APP_PROVIDERS_ARRAY");
|
|
13
|
+
const APP_SETTINGS_MANIFEST_URL = new InjectionToken("APP_SETTINGS_MANIFEST_URL");
|
|
14
|
+
var SettingsDataService = class SettingsDataService {
|
|
15
|
+
constructor(handler) {
|
|
16
|
+
this.APP_SETTINGS_MANIFEST_URL = inject(APP_SETTINGS_MANIFEST_URL);
|
|
17
|
+
this.http = new HttpClient(handler);
|
|
18
|
+
}
|
|
19
|
+
getAppSettings() {
|
|
20
|
+
return this.http.get(this.APP_SETTINGS_MANIFEST_URL);
|
|
21
|
+
}
|
|
22
|
+
static {
|
|
23
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
24
|
+
minVersion: "12.0.0",
|
|
25
|
+
version: "22.0.8",
|
|
26
|
+
ngImport: i0,
|
|
27
|
+
type: SettingsDataService,
|
|
28
|
+
deps: [{ token: i1.HttpBackend }],
|
|
29
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
34
|
+
minVersion: "12.0.0",
|
|
35
|
+
version: "22.0.8",
|
|
36
|
+
ngImport: i0,
|
|
37
|
+
type: SettingsDataService,
|
|
38
|
+
providedIn: "root"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
45
41
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
42
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
43
|
+
minVersion: "12.0.0",
|
|
44
|
+
version: "22.0.8",
|
|
45
|
+
ngImport: i0,
|
|
46
|
+
type: SettingsDataService,
|
|
47
|
+
decorators: [{
|
|
48
|
+
type: Injectable,
|
|
49
|
+
args: [{ providedIn: "root" }]
|
|
50
|
+
}],
|
|
51
|
+
ctorParameters: () => [{ type: i1.HttpBackend }]
|
|
52
|
+
});
|
|
53
|
+
const initialState = { settings: {
|
|
54
|
+
isServed: false,
|
|
55
|
+
api_url: "",
|
|
56
|
+
api_docs: "",
|
|
57
|
+
auth_settings: {},
|
|
58
|
+
culture: "",
|
|
59
|
+
isTemplate: false,
|
|
60
|
+
production: false,
|
|
61
|
+
version: ""
|
|
62
|
+
} };
|
|
63
|
+
var SettingsFacadeService = class SettingsFacadeService {
|
|
64
|
+
#settingsDataService;
|
|
65
|
+
#environment;
|
|
66
|
+
#state;
|
|
67
|
+
constructor(tokenAppsettings, appProvidersArray) {
|
|
68
|
+
this.tokenAppsettings = tokenAppsettings;
|
|
69
|
+
this.appProvidersArray = appProvidersArray;
|
|
70
|
+
this.#settingsDataService = inject(SettingsDataService);
|
|
71
|
+
this.#environment = inject(APP_ENVIRONMENT);
|
|
72
|
+
this.#state = signal(initialState, ...ngDevMode ? [{ debugName: "#state" }] : /* istanbul ignore next */ []);
|
|
73
|
+
this.settings = computed(() => this.#state().settings, ...ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []);
|
|
74
|
+
}
|
|
75
|
+
getAppDependencies() {
|
|
76
|
+
return this.appProvidersArray?.dependencies;
|
|
77
|
+
}
|
|
78
|
+
loadSettings() {
|
|
79
|
+
return this.#settingsDataService.getAppSettings().pipe(tap((settings) => {
|
|
80
|
+
if (isDevMode()) console.log(settings);
|
|
81
|
+
}), map((settings) => {
|
|
82
|
+
const runtimeSettings = merge(cloneDeep(this.#environment), settings);
|
|
83
|
+
Object.assign(this.tokenAppsettings, runtimeSettings);
|
|
84
|
+
this.#state.set({ settings: this.tokenAppsettings });
|
|
85
|
+
return true;
|
|
86
|
+
}), catchError((error) => {
|
|
87
|
+
console.error("Failed to load settings:", error);
|
|
88
|
+
return of(false);
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
static {
|
|
92
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
93
|
+
minVersion: "12.0.0",
|
|
94
|
+
version: "22.0.8",
|
|
95
|
+
ngImport: i0,
|
|
96
|
+
type: SettingsFacadeService,
|
|
97
|
+
deps: [{ token: APP_SETTINGS }, { token: APP_PROVIDERS_ARRAY }],
|
|
98
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
static {
|
|
102
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
103
|
+
minVersion: "12.0.0",
|
|
104
|
+
version: "22.0.8",
|
|
105
|
+
ngImport: i0,
|
|
106
|
+
type: SettingsFacadeService,
|
|
107
|
+
providedIn: "root"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
112
|
+
minVersion: "12.0.0",
|
|
113
|
+
version: "22.0.8",
|
|
114
|
+
ngImport: i0,
|
|
115
|
+
type: SettingsFacadeService,
|
|
116
|
+
decorators: [{
|
|
117
|
+
type: Injectable,
|
|
118
|
+
args: [{ providedIn: "root" }]
|
|
119
|
+
}],
|
|
120
|
+
ctorParameters: () => [{
|
|
121
|
+
type: void 0,
|
|
122
|
+
decorators: [{
|
|
123
|
+
type: Inject,
|
|
124
|
+
args: [APP_SETTINGS]
|
|
125
|
+
}]
|
|
126
|
+
}, {
|
|
127
|
+
type: void 0,
|
|
128
|
+
decorators: [{
|
|
129
|
+
type: Inject,
|
|
130
|
+
args: [APP_PROVIDERS_ARRAY]
|
|
131
|
+
}]
|
|
132
|
+
}]
|
|
133
|
+
});
|
|
97
134
|
function initializeAppSettings(appSettingsFacade) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
console.error('Failed to initialize app settings.');
|
|
108
|
-
throw new Error('App settings could not be loaded.');
|
|
109
|
-
}
|
|
110
|
-
};
|
|
135
|
+
return async () => {
|
|
136
|
+
if (await lastValueFrom(appSettingsFacade.loadSettings())) {
|
|
137
|
+
const dependencies = appSettingsFacade.getAppDependencies();
|
|
138
|
+
Injector.create({ providers: dependencies });
|
|
139
|
+
} else {
|
|
140
|
+
console.error("Failed to initialize app settings.");
|
|
141
|
+
throw new Error("App settings could not be loaded.");
|
|
142
|
+
}
|
|
143
|
+
};
|
|
111
144
|
}
|
|
112
145
|
function provideAppSettings(config = {}) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]);
|
|
146
|
+
return makeEnvironmentProviders([
|
|
147
|
+
{
|
|
148
|
+
provide: APP_SETTINGS_MANIFEST_URL,
|
|
149
|
+
useValue: "/app-settings.manifest.json"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
provide: APP_PROVIDERS_ARRAY,
|
|
153
|
+
useValue: config.dependencies || []
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
provide: APP_SETTINGS,
|
|
157
|
+
useValue: {}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
provide: APP_ENVIRONMENT,
|
|
161
|
+
useValue: {}
|
|
162
|
+
},
|
|
163
|
+
provideAppInitializer(() => {
|
|
164
|
+
return initializeAppSettings(inject(SettingsFacadeService))();
|
|
165
|
+
}),
|
|
166
|
+
{
|
|
167
|
+
provide: IAUTH_SETTINGS,
|
|
168
|
+
useFactory: (runtimeSettings) => runtimeSettings.auth_settings,
|
|
169
|
+
deps: [APP_SETTINGS]
|
|
170
|
+
}
|
|
171
|
+
]);
|
|
140
172
|
}
|
|
141
|
-
|
|
142
|
-
/*
|
|
143
|
-
* Public API Surface of ng-conf
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Generated bundle index. Do not edit.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
173
|
export { APP_ENVIRONMENT, APP_PROVIDERS_ARRAY, APP_SETTINGS, APP_SETTINGS_MANIFEST_URL, IAUTH_SETTINGS, SettingsDataService, SettingsFacadeService, initializeAppSettings, provideAppSettings };
|
|
151
|
-
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=indice-ng-config.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indice-ng-config.mjs","sources":["../../../projects/ng-config/src/lib/tokens.ts","../../../projects/ng-config/src/lib/settings.service.ts","../../../projects/ng-config/src/lib/settings-facade.service.ts","../../../projects/ng-config/src/lib/settings-initializer.ts","../../../projects/ng-config/src/public-api.ts","../../../projects/ng-config/src/indice-ng-config.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\nimport { IAppSettings, AppProvidersArray, IAuthSettings } from \"./types\";\n\nexport const APP_SETTINGS = new InjectionToken<IAppSettings>('APP_SETTINGS');\nexport const IAUTH_SETTINGS = new InjectionToken<IAuthSettings>('IAUTH_SETTINGS');\nexport const APP_ENVIRONMENT = new InjectionToken<any>('APP_ENVIRONMENT');\nexport const APP_PROVIDERS_ARRAY = new InjectionToken<AppProvidersArray>('APP_PROVIDERS_ARRAY');\nexport const APP_SETTINGS_MANIFEST_URL = new InjectionToken<string>('APP_SETTINGS_MANIFEST_URL');","import { Injectable, inject } from '@angular/core';\nimport { HttpBackend, HttpClient } from '@angular/common/http';\nimport { APP_SETTINGS_MANIFEST_URL } from './tokens';\nimport { IAppSettings } from './types';\n@Injectable({\n providedIn: 'root',\n})\nexport class SettingsDataService {\n private http: HttpClient;\n private APP_SETTINGS_MANIFEST_URL = inject(APP_SETTINGS_MANIFEST_URL);\n constructor(handler: HttpBackend) {\n this.http = new HttpClient(handler);\n }\n\n getAppSettings() {\n return this.http.get<IAppSettings>(this.APP_SETTINGS_MANIFEST_URL);\n }\n}\n\nexport interface AppSettingsState {\n settings: IAppSettings | null;\n}\n","import {\n computed,\n Inject,\n inject,\n Injectable,\n isDevMode,\n signal\n} from '@angular/core';\nimport cloneDeep from 'lodash/cloneDeep';\nimport merge from 'lodash/merge';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map, tap } from 'rxjs/operators';\nimport { AppSettingsState, SettingsDataService } from './settings.service';\nimport { IAppSettings, IAuthSettings, AppProvidersArray } from './types';\nimport { APP_ENVIRONMENT, APP_SETTINGS, APP_PROVIDERS_ARRAY, IAUTH_SETTINGS } from './tokens';\n\nconst initialState: Readonly<AppSettingsState> = {\n settings: {\n isServed: false,\n api_url: '',\n api_docs: '',\n auth_settings: {} as IAuthSettings,\n culture: '',\n isTemplate: false,\n production: false,\n version: ''\n },\n};\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SettingsFacadeService {\n readonly #settingsDataService = inject(SettingsDataService);\n readonly #environment = inject(APP_ENVIRONMENT);\n\n readonly #state = signal(initialState);\n readonly settings = computed(() => this.#state().settings);\n\n constructor(\n @Inject(APP_SETTINGS) private tokenAppsettings: IAppSettings,\n @Inject(APP_PROVIDERS_ARRAY) private appProvidersArray: AppProvidersArray) { }\n\n getAppDependencies() {\n return this.appProvidersArray?.dependencies;\n }\n\n\n loadSettings(): Observable<boolean> {\n return this.#settingsDataService.getAppSettings().pipe(\n tap((settings) => {\n if (isDevMode()) {\n console.log(settings);\n }\n }),\n map((settings) => {\n const runtimeSettings = merge(cloneDeep(this.#environment), settings);\n // Assign settings directly to the appSettings object\n Object.assign(this.tokenAppsettings, runtimeSettings);\n\n // Update the state\n this.#state.set({ settings: this.tokenAppsettings });\n\n return true; // Indicate successful loading\n }),\n catchError((error) => {\n // Log the error and provide fallback behavior\n console.error('Failed to load settings:', error);\n return of(false); // Return false to indicate failure\n })\n );\n }\n}\n","import {\n EnvironmentProviders,\n Injector,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer\n} from '@angular/core';\nimport { lastValueFrom } from 'rxjs';\nimport { SettingsFacadeService } from './settings-facade.service';\nimport { APP_ENVIRONMENT, APP_PROVIDERS_ARRAY, APP_SETTINGS, APP_SETTINGS_MANIFEST_URL, IAUTH_SETTINGS } from './tokens';\nimport { AppProvidersArray, IAppSettings } from './types';\n\nexport function initializeAppSettings(\n appSettingsFacade: SettingsFacadeService,\n) {\n return async () => {\n // Wait for settings to load\n const success = await lastValueFrom(appSettingsFacade.loadSettings());\n\n if (success) {\n const dependencies = appSettingsFacade.getAppDependencies() as any[];\n // Create a child injector with the dependencies\n Injector.create({ providers: dependencies });\n } else {\n console.error('Failed to initialize app settings.');\n throw new Error('App settings could not be loaded.');\n }\n };\n}\n\nexport function provideAppSettings(config: AppProvidersArray = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: APP_SETTINGS_MANIFEST_URL,\n useValue: '/app-settings.manifest.json'\n },\n {\n provide: APP_PROVIDERS_ARRAY,\n useValue: config.dependencies || []\n },\n {\n provide: APP_SETTINGS, \n useValue: {} // Provide an empty object initially\n },\n {\n provide: APP_ENVIRONMENT,\n useValue: {}\n },\n provideAppInitializer(() => {\n const appSettingsFacade = inject(SettingsFacadeService);\n return initializeAppSettings(appSettingsFacade)();\n }),\n {\n provide: IAUTH_SETTINGS,\n useFactory: (runtimeSettings: IAppSettings) => runtimeSettings.auth_settings,\n deps: [APP_SETTINGS],\n }\n ]);\n}","/*\n * Public API Surface of ng-conf\n */\n\nexport * from './lib/types';\nexport * from './lib/tokens';\nexport * from './lib/settings.service';\nexport * from './lib/settings-initializer';\nexport * from './lib/settings-facade.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;MAGa,YAAY,GAAG,IAAI,cAAc,CAAe,cAAc;MAC9D,cAAc,GAAG,IAAI,cAAc,CAAgB,gBAAgB;MACnE,eAAe,GAAG,IAAI,cAAc,CAAM,iBAAiB;MAC3D,mBAAmB,GAAG,IAAI,cAAc,CAAoB,qBAAqB;MACjF,yBAAyB,GAAG,IAAI,cAAc,CAAS,2BAA2B;;MCAlF,mBAAmB,CAAA;AAG5B,IAAA,WAAA,CAAY,OAAoB,EAAA;AADxB,QAAA,IAAA,CAAA,yBAAyB,GAAG,MAAM,CAAC,yBAAyB,CAAC;QAEjE,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC;IACvC;IAEA,cAAc,GAAA;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAe,IAAI,CAAC,yBAAyB,CAAC;IACtE;8GATS,mBAAmB,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAA,EAAA,CAAA,WAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAA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/tokens.ts","../../../projects/ng-config/src/lib/settings.service.ts","../../../projects/ng-config/src/lib/settings-facade.service.ts","../../../projects/ng-config/src/lib/settings-initializer.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\nimport { IAppSettings, AppProvidersArray, IAuthSettings } from \"./types\";\n\nexport const APP_SETTINGS = new InjectionToken<IAppSettings>('APP_SETTINGS');\nexport const IAUTH_SETTINGS = new InjectionToken<IAuthSettings>('IAUTH_SETTINGS');\nexport const APP_ENVIRONMENT = new InjectionToken<any>('APP_ENVIRONMENT');\nexport const APP_PROVIDERS_ARRAY = new InjectionToken<AppProvidersArray>('APP_PROVIDERS_ARRAY');\nexport const APP_SETTINGS_MANIFEST_URL = new InjectionToken<string>('APP_SETTINGS_MANIFEST_URL');","import { Injectable, inject } from '@angular/core';\nimport { HttpBackend, HttpClient } from '@angular/common/http';\nimport { APP_SETTINGS_MANIFEST_URL } from './tokens';\nimport { IAppSettings } from './types';\n@Injectable({\n providedIn: 'root',\n})\nexport class SettingsDataService {\n private http: HttpClient;\n private APP_SETTINGS_MANIFEST_URL = inject(APP_SETTINGS_MANIFEST_URL);\n constructor(handler: HttpBackend) {\n this.http = new HttpClient(handler);\n }\n\n getAppSettings() {\n return this.http.get<IAppSettings>(this.APP_SETTINGS_MANIFEST_URL);\n }\n}\n\nexport interface AppSettingsState {\n settings: IAppSettings | null;\n}\n","import {\n computed,\n Inject,\n inject,\n Injectable,\n isDevMode,\n signal\n} from '@angular/core';\nimport cloneDeep from 'lodash/cloneDeep';\nimport merge from 'lodash/merge';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map, tap } from 'rxjs/operators';\nimport { AppSettingsState, SettingsDataService } from './settings.service';\nimport { IAppSettings, IAuthSettings, AppProvidersArray } from './types';\nimport { APP_ENVIRONMENT, APP_SETTINGS, APP_PROVIDERS_ARRAY, IAUTH_SETTINGS } from './tokens';\n\nconst initialState: Readonly<AppSettingsState> = {\n settings: {\n isServed: false,\n api_url: '',\n api_docs: '',\n auth_settings: {} as IAuthSettings,\n culture: '',\n isTemplate: false,\n production: false,\n version: ''\n },\n};\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SettingsFacadeService {\n readonly #settingsDataService = inject(SettingsDataService);\n readonly #environment = inject(APP_ENVIRONMENT);\n\n readonly #state = signal(initialState);\n readonly settings = computed(() => this.#state().settings);\n\n constructor(\n @Inject(APP_SETTINGS) private tokenAppsettings: IAppSettings,\n @Inject(APP_PROVIDERS_ARRAY) private appProvidersArray: AppProvidersArray) { }\n\n getAppDependencies() {\n return this.appProvidersArray?.dependencies;\n }\n\n\n loadSettings(): Observable<boolean> {\n return this.#settingsDataService.getAppSettings().pipe(\n tap((settings) => {\n if (isDevMode()) {\n console.log(settings);\n }\n }),\n map((settings) => {\n const runtimeSettings = merge(cloneDeep(this.#environment), settings);\n // Assign settings directly to the appSettings object\n Object.assign(this.tokenAppsettings, runtimeSettings);\n\n // Update the state\n this.#state.set({ settings: this.tokenAppsettings });\n\n return true; // Indicate successful loading\n }),\n catchError((error) => {\n // Log the error and provide fallback behavior\n console.error('Failed to load settings:', error);\n return of(false); // Return false to indicate failure\n })\n );\n }\n}\n","import {\n EnvironmentProviders,\n Injector,\n inject,\n makeEnvironmentProviders,\n provideAppInitializer\n} from '@angular/core';\nimport { lastValueFrom } from 'rxjs';\nimport { SettingsFacadeService } from './settings-facade.service';\nimport { APP_ENVIRONMENT, APP_PROVIDERS_ARRAY, APP_SETTINGS, APP_SETTINGS_MANIFEST_URL, IAUTH_SETTINGS } from './tokens';\nimport { AppProvidersArray, IAppSettings } from './types';\n\nexport function initializeAppSettings(\n appSettingsFacade: SettingsFacadeService,\n) {\n return async () => {\n // Wait for settings to load\n const success = await lastValueFrom(appSettingsFacade.loadSettings());\n\n if (success) {\n const dependencies = appSettingsFacade.getAppDependencies() as any[];\n // Create a child injector with the dependencies\n Injector.create({ providers: dependencies });\n } else {\n console.error('Failed to initialize app settings.');\n throw new Error('App settings could not be loaded.');\n }\n };\n}\n\nexport function provideAppSettings(config: AppProvidersArray = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: APP_SETTINGS_MANIFEST_URL,\n useValue: '/app-settings.manifest.json'\n },\n {\n provide: APP_PROVIDERS_ARRAY,\n useValue: config.dependencies || []\n },\n {\n provide: APP_SETTINGS, \n useValue: {} // Provide an empty object initially\n },\n {\n provide: APP_ENVIRONMENT,\n useValue: {}\n },\n provideAppInitializer(() => {\n const appSettingsFacade = inject(SettingsFacadeService);\n return initializeAppSettings(appSettingsFacade)();\n }),\n {\n provide: IAUTH_SETTINGS,\n useFactory: (runtimeSettings: IAppSettings) => runtimeSettings.auth_settings,\n deps: [APP_SETTINGS],\n }\n ]);\n}"],"mappings":";;;;;;;;AAGA,MAAa,eAAe,IAAI,eAA6B,cAAc;AAC3E,MAAa,iBAAiB,IAAI,eAA8B,gBAAgB;AAChF,MAAa,kBAAkB,IAAI,eAAoB,iBAAiB;AACxE,MAAa,sBAAsB,IAAI,eAAkC,qBAAqB;AAC9F,MAAa,4BAA4B,IAAI,eAAuB,2BAA2B;ACA/F,IAAa,sBAAb,MAAa,oBAAmB;CAG5B,YAAY,SAAoB;EADxB,KAAA,4BAA4B,OAAO,yBAAyB;EAEhE,KAAK,OAAO,IAAI,WAAW,OAAO;CACtC;CAEA,iBAAc;EACV,OAAO,KAAK,KAAK,IAAkB,KAAK,yBAAyB;CACrE;CATS;EAAA,KAAA,OAAA,GAAA,mBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAmB,MAAA,CAAA,EAAA,OAAA,GAAA,YAAA,CAAA;GAAA,QAAA,GAAA,gBAAA;EAAA,CAAA;CAAA;CAAnB;EAAA,KAAA,QAAA,GAAA,sBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAmB,YAFhB;EAAM,CAAA;CAAA;;AAET,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAmB,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10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
version: string;
|
|
16
|
-
isServed: boolean;
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { EnvironmentProviders, InjectionToken } from "@angular/core";
|
|
3
|
+
import { HttpBackend } from "@angular/common/http";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
export interface IAppSettings {
|
|
6
|
+
[index: string]: any;
|
|
7
|
+
api_url: string;
|
|
8
|
+
api_docs: string;
|
|
9
|
+
auth_settings: IAuthSettings;
|
|
10
|
+
culture: string;
|
|
11
|
+
isTemplate: boolean;
|
|
12
|
+
production: boolean;
|
|
13
|
+
version: string;
|
|
14
|
+
isServed: boolean;
|
|
17
15
|
}
|
|
18
|
-
interface IAuthSettings {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
export interface IAuthSettings {
|
|
17
|
+
[index: string]: any;
|
|
18
|
+
authority: string;
|
|
19
|
+
client_id: string;
|
|
20
|
+
filterProtocolClaims: boolean;
|
|
21
|
+
loadUserInfo: boolean;
|
|
22
|
+
post_logout_redirect_uri: string;
|
|
23
|
+
redirect_uri: string;
|
|
24
|
+
response_type: string;
|
|
25
|
+
scope: string;
|
|
26
|
+
silent_redirect_uri: string;
|
|
27
|
+
revokeAccessTokenOnSignout: boolean;
|
|
28
|
+
accessTokenExpiringNotificationTime: number;
|
|
29
|
+
monitorSession: boolean;
|
|
30
|
+
automaticSilentRenew: boolean;
|
|
33
31
|
}
|
|
34
|
-
interface AppProvidersArray {
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
export interface AppProvidersArray {
|
|
33
|
+
dependencies?: any[];
|
|
34
|
+
manifestUrl?: string;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
declare const
|
|
40
|
-
declare const
|
|
41
|
-
declare const
|
|
42
|
-
declare const
|
|
43
|
-
declare
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<SettingsDataService, never>;
|
|
51
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<SettingsDataService>;
|
|
36
|
+
export declare const APP_SETTINGS: InjectionToken<IAppSettings>;
|
|
37
|
+
export declare const IAUTH_SETTINGS: InjectionToken<IAuthSettings>;
|
|
38
|
+
export declare const APP_ENVIRONMENT: InjectionToken<any>;
|
|
39
|
+
export declare const APP_PROVIDERS_ARRAY: InjectionToken<AppProvidersArray>;
|
|
40
|
+
export declare const APP_SETTINGS_MANIFEST_URL: InjectionToken<string>;
|
|
41
|
+
export declare class SettingsDataService {
|
|
42
|
+
private http;
|
|
43
|
+
private APP_SETTINGS_MANIFEST_URL;
|
|
44
|
+
constructor(handler: HttpBackend);
|
|
45
|
+
getAppSettings(): import("rxjs").Observable<IAppSettings>;
|
|
46
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SettingsDataService, never>;
|
|
47
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SettingsDataService>;
|
|
52
48
|
}
|
|
53
|
-
interface AppSettingsState {
|
|
54
|
-
|
|
49
|
+
export interface AppSettingsState {
|
|
50
|
+
settings: IAppSettings | null;
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<SettingsFacadeService>;
|
|
52
|
+
export declare class SettingsFacadeService {
|
|
53
|
+
#private;
|
|
54
|
+
private tokenAppsettings;
|
|
55
|
+
private appProvidersArray;
|
|
56
|
+
readonly settings: import("@angular/core").Signal<IAppSettings | null>;
|
|
57
|
+
constructor(tokenAppsettings: IAppSettings, appProvidersArray: AppProvidersArray);
|
|
58
|
+
getAppDependencies(): any[] | undefined;
|
|
59
|
+
loadSettings(): Observable<boolean>;
|
|
60
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SettingsFacadeService, never>;
|
|
61
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SettingsFacadeService>;
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
declare function
|
|
70
|
-
declare function provideAppSettings(config?: AppProvidersArray): EnvironmentProviders;
|
|
71
|
-
|
|
72
|
-
export { APP_ENVIRONMENT, APP_PROVIDERS_ARRAY, APP_SETTINGS, APP_SETTINGS_MANIFEST_URL, IAUTH_SETTINGS, SettingsDataService, SettingsFacadeService, initializeAppSettings, provideAppSettings };
|
|
73
|
-
export type { AppProvidersArray, AppSettingsState, IAppSettings, IAuthSettings };
|
|
63
|
+
export declare function initializeAppSettings(appSettingsFacade: SettingsFacadeService): () => Promise<void>;
|
|
64
|
+
export declare function provideAppSettings(config?: AppProvidersArray): EnvironmentProviders;
|