@yaagoub/federation-tools 0.0.1 → 1.0.1
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.
|
@@ -23,7 +23,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
23
23
|
* - value: parsed env.json for that remote
|
|
24
24
|
*/
|
|
25
25
|
const APP_CONFIG_ENV = new InjectionToken('env-settings');
|
|
26
|
-
class
|
|
26
|
+
class EnvService {
|
|
27
27
|
http = inject(HttpClient);
|
|
28
28
|
federation = inject(Federation);
|
|
29
29
|
envMap = inject(APP_CONFIG_ENV);
|
|
@@ -53,7 +53,17 @@ class Env {
|
|
|
53
53
|
throw new Error(`Failed to load environment configuration; cannot continue. ${e?.message ?? e}`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: EnvService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
57
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: EnvService, providedIn: 'root' });
|
|
58
|
+
}
|
|
59
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: EnvService, decorators: [{
|
|
60
|
+
type: Injectable,
|
|
61
|
+
args: [{ providedIn: 'root' }]
|
|
62
|
+
}] });
|
|
63
|
+
|
|
64
|
+
class Env {
|
|
65
|
+
envMap = inject(APP_CONFIG_ENV);
|
|
66
|
+
get(remoteName) {
|
|
57
67
|
const v = this.envMap.get(remoteName);
|
|
58
68
|
if (!v) {
|
|
59
69
|
throw new Error(`Env for "${remoteName}" not loaded. Did you register provideAppInitializer(() => env.load()) ?`);
|
|
@@ -65,14 +75,16 @@ class Env {
|
|
|
65
75
|
}
|
|
66
76
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: Env, decorators: [{
|
|
67
77
|
type: Injectable,
|
|
68
|
-
args: [{
|
|
78
|
+
args: [{
|
|
79
|
+
providedIn: 'root'
|
|
80
|
+
}]
|
|
69
81
|
}] });
|
|
70
82
|
|
|
71
83
|
function provideFederationEnv() {
|
|
72
84
|
return makeEnvironmentProviders([
|
|
73
|
-
|
|
85
|
+
EnvService, Federation, Env,
|
|
74
86
|
{ provide: APP_CONFIG_ENV, useValue: new Map() },
|
|
75
|
-
provideAppInitializer(() => inject(
|
|
87
|
+
provideAppInitializer(() => inject(EnvService).load()),
|
|
76
88
|
]);
|
|
77
89
|
}
|
|
78
90
|
|
|
@@ -80,5 +92,5 @@ function provideFederationEnv() {
|
|
|
80
92
|
* Generated bundle index. Do not edit.
|
|
81
93
|
*/
|
|
82
94
|
|
|
83
|
-
export { provideFederationEnv };
|
|
95
|
+
export { Env, provideFederationEnv };
|
|
84
96
|
//# sourceMappingURL=yaagoub-federation-tools.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaagoub-federation-tools.mjs","sources":["../../../projects/federation-tools/src/federation/federation.service.ts","../../../projects/federation-tools/src/env/env.service.ts","../../../projects/federation-tools/src/providers/provide.ts","../../../projects/federation-tools/src/yaagoub-federation-tools.ts"],"sourcesContent":["import { Injectable } from \"@angular/core\";\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class Federation {\r\n getShellOrigin(): string {\r\n return window.location.origin;\r\n }\r\n}\r\n","import { inject, Injectable } from '@angular/core';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { firstValueFrom } from 'rxjs';\r\nimport { InjectionToken } from '@angular/core';\r\nimport { Federation } from '../federation/federation.service';\r\n\r\nexport type EnvMap = Map<string, Record<string, any>>;\r\n\r\n/**\r\n * Holds all loaded env objects:\r\n * - key: remoteName (from env-manifest.json) + 'shell'\r\n * - value: parsed env.json for that remote\r\n */\r\nexport const APP_CONFIG_ENV = new InjectionToken<EnvMap>('env-settings');\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class
|
|
1
|
+
{"version":3,"file":"yaagoub-federation-tools.mjs","sources":["../../../projects/federation-tools/src/federation/federation.service.ts","../../../projects/federation-tools/src/env/env.service.ts","../../../projects/federation-tools/src/env/env.ts","../../../projects/federation-tools/src/providers/provide.ts","../../../projects/federation-tools/src/yaagoub-federation-tools.ts"],"sourcesContent":["import { Injectable } from \"@angular/core\";\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class Federation {\r\n getShellOrigin(): string {\r\n return window.location.origin;\r\n }\r\n}\r\n","import { inject, Injectable } from '@angular/core';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { firstValueFrom } from 'rxjs';\r\nimport { InjectionToken } from '@angular/core';\r\nimport { Federation } from '../federation/federation.service';\r\n\r\nexport type EnvMap = Map<string, Record<string, any>>;\r\n\r\n/**\r\n * Holds all loaded env objects:\r\n * - key: remoteName (from env-manifest.json) + 'shell'\r\n * - value: parsed env.json for that remote\r\n */\r\nexport const APP_CONFIG_ENV = new InjectionToken<EnvMap>('env-settings');\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class EnvService {\r\n private http = inject(HttpClient);\r\n private federation = inject(Federation);\r\n private envMap: EnvMap = inject(APP_CONFIG_ENV);\r\n\r\n private getManifestUrl(): string {\r\n return this.federation.getShellOrigin() + '/env-manifest.json';\r\n }\r\n\r\n private getShellEnvUrl(): string {\r\n return this.federation.getShellOrigin() + '/env.json';\r\n }\r\n\r\n private getRemoteEnvUrl(origin: string): string {\r\n return origin.replace(/\\/+$/, '') + '/env.json';\r\n }\r\n\r\n async load(): Promise<void> {\r\n try {\r\n const envManifest = await firstValueFrom(\r\n this.http.get<Record<string, string>>(this.getManifestUrl())\r\n );\r\n\r\n const remoteNames = Object.keys(envManifest);\r\n\r\n const remoteLoads = remoteNames.map(async (remoteName) => {\r\n const remoteOrigin = envManifest[remoteName];\r\n const env = await firstValueFrom(\r\n this.http.get<Record<string, any>>(this.getRemoteEnvUrl(remoteOrigin))\r\n );\r\n this.envMap.set(remoteName, env);\r\n });\r\n\r\n await Promise.all(remoteLoads);\r\n\r\n const shellEnv = await firstValueFrom(\r\n this.http.get<Record<string, any>>(this.getShellEnvUrl())\r\n );\r\n this.envMap.set('shell', shellEnv);\r\n\r\n } catch (e: any) {\r\n throw new Error(\r\n `Failed to load environment configuration; cannot continue. ${e?.message ?? e}`\r\n );\r\n }\r\n }\r\n}\r\n","import { inject, Injectable } from \"@angular/core\";\r\nimport { APP_CONFIG_ENV, EnvMap } from \"./env.service\";\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class Env {\r\n private envMap: EnvMap = inject(APP_CONFIG_ENV);\r\n\r\n get(remoteName: string): Record<string, any> {\r\n const v = this.envMap.get(remoteName);\r\n if (!v) {\r\n throw new Error(\r\n `Env for \"${remoteName}\" not loaded. Did you register provideAppInitializer(() => env.load()) ?`\r\n );\r\n }\r\n return v;\r\n }\r\n}","import { EnvironmentProviders, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { APP_CONFIG_ENV, EnvService, EnvMap } from '../env/env.service';\nimport { Federation } from '../federation/federation.service';\nimport { Env } from '../env/env';\n\nexport function provideFederationEnv(): EnvironmentProviders {\n return makeEnvironmentProviders([\n EnvService, Federation, Env,\n { provide: APP_CONFIG_ENV, useValue: new Map() as EnvMap },\n provideAppInitializer(() => inject(EnvService).load()),\n ]);\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAKa,UAAU,CAAA;IACrB,cAAc,GAAA;AACZ,QAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM;IAC/B;wGAHW,UAAU,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAV,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBA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A,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAH,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,GAAG,cAFA,MAAM,EAAA,CAAA;;4FAET,GAAG,EAAA,UAAA,EAAA,CAAA;kBAHf,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE;AACf,iBAAA;;;SCAe,oBAAoB,GAAA;AAClC,IAAA,OAAO,wBAAwB,CAAC;QAC9B,UAAU,EAAE,UAAU,EAAE,GAAG;QAC3B,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAY,EAAE;QAC1D,qBAAqB,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;AACvD,KAAA,CAAC;AACJ;;ACXA;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
1
2
|
import { EnvironmentProviders } from '@angular/core';
|
|
2
3
|
|
|
3
4
|
declare function provideFederationEnv(): EnvironmentProviders;
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
declare class Env {
|
|
7
|
+
private envMap;
|
|
8
|
+
get(remoteName: string): Record<string, any>;
|
|
9
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Env, never>;
|
|
10
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<Env>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { Env, provideFederationEnv };
|