@ama-mfe/ng-utils 12.3.0-prerelease.3 → 12.3.0-prerelease.31

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/README.md CHANGED
@@ -254,3 +254,39 @@ export class CustomService implements MessageProducer<CustomMessageVersions> {
254
254
  }
255
255
  }
256
256
  ```
257
+ ### Host information
258
+
259
+ #### Host application
260
+
261
+ A host application can send information to the embedded applications using parameters in the URL.
262
+
263
+ ```html
264
+ <iframe [src]="'myModuleUrl' | hostInfo: 'host-app-id'"></iframe>
265
+ ```
266
+
267
+ This will add the `location.origin` and the application id of the host to the URL of the embedded application.
268
+
269
+ #### Embedded application
270
+
271
+ The embedded application can access the data sent in the previous section using an injection token:
272
+
273
+ ```typescript
274
+ import {inject} from '@angular/core';
275
+ import {getHostInfo, isEmbedded} from '@ama-mfe/ng-utils';
276
+
277
+ export class SomeClass {
278
+ private readonly hostInfo = getHostInfo();
279
+
280
+ doSomething() {
281
+ if (this.hostInfo.applicationId === 'app1') {
282
+ // Do something when embedded in app1
283
+ } else if (isEmbedded()) {
284
+ // Do something when embedded elsewhere
285
+ } else {
286
+ // Do something when standalone
287
+ }
288
+ }
289
+ }
290
+ ```
291
+
292
+ The host information is stored in session storage so it won't be lost when navigating inside the iframe.
@@ -1 +1 @@
1
- {"version":3,"file":"connect.providers.d.ts","sourceRoot":"","sources":["../../src/connect/connect.providers.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,gDAcnE"}
1
+ {"version":3,"file":"connect.providers.d.ts","sourceRoot":"","sources":["../../src/connect/connect.providers.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,gDAmBnE"}
@@ -1,7 +1,7 @@
1
1
  import { MessagePeerService, MESSAGE_PEER_CONFIG, MESSAGE_PEER_CONNECT_OPTIONS } from '@amadeus-it-group/microfrontends-angular';
2
2
  export { MessagePeerService as ConnectionService } from '@amadeus-it-group/microfrontends-angular';
3
3
  import * as i0 from '@angular/core';
4
- import { Injectable, inject, signal, effect, DestroyRef, afterNextRender, input, computed, ElementRef, Renderer2, Directive, untracked, SecurityContext, Pipe, HostBinding, makeEnvironmentProviders } from '@angular/core';
4
+ import { Injectable, inject, signal, effect, DestroyRef, afterNextRender, input, computed, ElementRef, Renderer2, Directive, SecurityContext, Pipe, untracked, HostBinding, makeEnvironmentProviders } from '@angular/core';
5
5
  import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
6
6
  import { LoggerService } from '@o3r/logger';
7
7
  import { RESIZE_MESSAGE_TYPE, NAVIGATION_MESSAGE_TYPE, THEME_MESSAGE_TYPE } from '@ama-mfe/messages';
@@ -78,10 +78,10 @@ class ProducerManagerService {
78
78
  }
79
79
  return handlersPresent;
80
80
  }
81
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ProducerManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
82
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ProducerManagerService, providedIn: 'root' }); }
81
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ProducerManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
82
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ProducerManagerService, providedIn: 'root' }); }
83
83
  }
84
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ProducerManagerService, decorators: [{
84
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ProducerManagerService, decorators: [{
85
85
  type: Injectable,
86
86
  args: [{
87
87
  providedIn: 'root'
@@ -173,10 +173,10 @@ class ConsumerManagerService {
173
173
  return consumers.filter((c) => c !== consumer);
174
174
  });
175
175
  }
176
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ConsumerManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
177
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ConsumerManagerService, providedIn: 'root' }); }
176
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ConsumerManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
177
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ConsumerManagerService, providedIn: 'root' }); }
178
178
  }
179
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ConsumerManagerService, decorators: [{
179
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ConsumerManagerService, decorators: [{
180
180
  type: Injectable,
181
181
  args: [{
182
182
  providedIn: 'root'
@@ -239,10 +239,10 @@ class ResizeConsumerService {
239
239
  stop() {
240
240
  this.consumerManagerService.unregister(this);
241
241
  }
242
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
243
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeConsumerService, providedIn: 'root' }); }
242
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
243
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeConsumerService, providedIn: 'root' }); }
244
244
  }
245
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeConsumerService, decorators: [{
245
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeConsumerService, decorators: [{
246
246
  type: Injectable,
247
247
  args: [{
248
248
  providedIn: 'root'
@@ -295,10 +295,10 @@ class ResizeService {
295
295
  });
296
296
  afterNextRender(() => this.resizeObserver?.observe(document.body));
297
297
  }
298
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
299
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeService, providedIn: 'root' }); }
298
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
299
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeService, providedIn: 'root' }); }
300
300
  }
301
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ResizeService, decorators: [{
301
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ResizeService, decorators: [{
302
302
  type: Injectable,
303
303
  args: [{
304
304
  providedIn: 'root'
@@ -342,10 +342,10 @@ class ScalableDirective {
342
342
  }
343
343
  });
344
344
  }
345
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ScalableDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
346
- /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: ScalableDirective, isStandalone: true, selector: "[scalable]", inputs: { connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: false, transformFunction: null }, scalable: { classPropertyName: "scalable", publicName: "scalable", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
345
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ScalableDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
346
+ /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.6", type: ScalableDirective, isStandalone: true, selector: "[scalable]", inputs: { connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: false, transformFunction: null }, scalable: { classPropertyName: "scalable", publicName: "scalable", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
347
347
  }
348
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ScalableDirective, decorators: [{
348
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ScalableDirective, decorators: [{
349
349
  type: Directive,
350
350
  args: [{
351
351
  selector: '[scalable]',
@@ -353,15 +353,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
353
353
  }]
354
354
  }], ctorParameters: () => [] });
355
355
 
356
- /**
357
- * A constant array of known message types and their versions.
358
- */
359
- const KNOWN_MESSAGES = [
360
- {
361
- type: ERROR_MESSAGE_TYPE,
362
- version: '1.0'
363
- }
364
- ];
356
+ const SESSION_STORAGE_KEY = 'ama-mfe-host-info';
365
357
  /**
366
358
  * Search parameter to add to the URL when embedding an iframe containing the URL of the host.
367
359
  * This is needed to support Firefox (on which {@link https://developer.mozilla.org/docs/Web/API/Location/ancestorOrigins | location.ancestorOrigins} is not currently supported)
@@ -369,24 +361,64 @@ const KNOWN_MESSAGES = [
369
361
  */
370
362
  const MFE_HOST_URL_PARAM = 'ama-mfe-host-url';
371
363
  /**
372
- * Returns the default options for starting a client endpoint peer connection.
373
- * As `origin`, it will take the parent origin and the `window` will be the parent window.
374
- * The parent origin will use the first found among:
364
+ * Search parameter to add to the URL to let a module know on which application it's embedded
365
+ */
366
+ const MFE_HOST_APPLICATION_ID_PARAM = 'ama-mfe-host-app-id';
367
+ /**
368
+ * Gather the host information from the url parameters
369
+ * The host url will use the first found among:
375
370
  * - look for the search parameter {@link MFE_HOST_URL_PARAM} in the URL of the iframe
376
371
  * - use the first item in `location.ancestorOrigins` (currently not supported on Firefox)
377
372
  * - use `document.referrer` (will only work if called before any redirection in the iframe)
373
+ * The application ID is taken from the search parameter {@link MFE_HOST_APPLICATION_ID_PARAM} in the URL of the iframe
378
374
  */
379
- function getDefaultClientEndpointStartOptions() {
375
+ function getHostInfo() {
380
376
  const searchParams = new URLSearchParams(location.search);
381
- const hostURL = searchParams.get(MFE_HOST_URL_PARAM) || location.ancestorOrigins?.[0] || document.referrer;
382
- if (hostURL) {
383
- return {
384
- origin: new URL(hostURL).origin,
385
- window: window.parent
386
- };
377
+ const storedHostInfo = JSON.parse(sessionStorage.getItem(SESSION_STORAGE_KEY) || '{}');
378
+ return {
379
+ hostURL: searchParams.get(MFE_HOST_URL_PARAM) || storedHostInfo.hostURL || location.ancestorOrigins?.[0] || document.referrer,
380
+ hostApplicationId: searchParams.get(MFE_HOST_APPLICATION_ID_PARAM) || storedHostInfo.hostApplicationId
381
+ };
382
+ }
383
+ /**
384
+ * Gather the host information from the url parameters and handle the persistence in session storage.
385
+ */
386
+ function persistHostInfo() {
387
+ const hostInfo = getHostInfo();
388
+ sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(hostInfo));
389
+ }
390
+
391
+ /**
392
+ * A pipe that adds the host information in the URL of an iframe,
393
+ */
394
+ class HostInfoPipe {
395
+ constructor() {
396
+ this.domSanitizer = inject(DomSanitizer);
387
397
  }
388
- return {};
398
+ transform(url, applicationId) {
399
+ const urlString = typeof url === 'string'
400
+ ? url
401
+ : this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url || null);
402
+ if (!url) {
403
+ return undefined;
404
+ }
405
+ if (urlString) {
406
+ const moduleUrl = new URL(urlString);
407
+ moduleUrl.searchParams.set(MFE_HOST_URL_PARAM, window.location.origin);
408
+ moduleUrl.searchParams.set(MFE_HOST_APPLICATION_ID_PARAM, applicationId);
409
+ const moduleUrlStringyfied = moduleUrl.toString();
410
+ return typeof url === 'string' ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
411
+ }
412
+ }
413
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: HostInfoPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
414
+ /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: HostInfoPipe, isStandalone: true, name: "hostInfo" }); }
389
415
  }
416
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: HostInfoPipe, decorators: [{
417
+ type: Pipe,
418
+ args: [{
419
+ name: 'hostInfo'
420
+ }]
421
+ }] });
390
422
 
391
423
  /**
392
424
  * A service that handles navigation messages and routing.
@@ -443,8 +475,8 @@ class NavigationConsumerService {
443
475
  */
444
476
  navigate(url, channelId) {
445
477
  const { paths, queryParams } = this.parseUrl(url);
446
- // No need to keep this in the URL
447
- delete queryParams[MFE_HOST_URL_PARAM];
478
+ // No need to keep these in the URL
479
+ [MFE_HOST_URL_PARAM, MFE_HOST_APPLICATION_ID_PARAM].forEach((key) => delete queryParams[key]);
448
480
  void this.router.navigate(paths, { relativeTo: this.activeRoute.children.at(-1), queryParams, state: { channelId }, replaceUrl: true });
449
481
  }
450
482
  /**
@@ -459,10 +491,10 @@ class NavigationConsumerService {
459
491
  stop() {
460
492
  this.consumerManagerService.unregister(this);
461
493
  }
462
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: NavigationConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
463
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: NavigationConsumerService, providedIn: 'root' }); }
494
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NavigationConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
495
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NavigationConsumerService, providedIn: 'root' }); }
464
496
  }
465
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: NavigationConsumerService, decorators: [{
497
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: NavigationConsumerService, decorators: [{
466
498
  type: Injectable,
467
499
  args: [{
468
500
  providedIn: 'root'
@@ -505,10 +537,10 @@ class RouteMemorizeService {
505
537
  getRoute(channelId) {
506
538
  return this.routeStack[channelId];
507
539
  }
508
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RouteMemorizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
509
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RouteMemorizeService, providedIn: 'root' }); }
540
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RouteMemorizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
541
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RouteMemorizeService, providedIn: 'root' }); }
510
542
  }
511
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RouteMemorizeService, decorators: [{
543
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RouteMemorizeService, decorators: [{
512
544
  type: Injectable,
513
545
  args: [{
514
546
  providedIn: 'root'
@@ -561,10 +593,10 @@ class RouteMemorizeDirective {
561
593
  }
562
594
  });
563
595
  }
564
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RouteMemorizeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
565
- /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: RouteMemorizeDirective, isStandalone: true, selector: "iframe[memorizeRoute]", inputs: { memorizeRoute: { classPropertyName: "memorizeRoute", publicName: "memorizeRoute", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteId: { classPropertyName: "memorizeRouteId", publicName: "memorizeRouteId", isSignal: true, isRequired: false, transformFunction: null }, memorizeMaxAge: { classPropertyName: "memorizeMaxAge", publicName: "memorizeMaxAge", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteMaxAge: { classPropertyName: "memorizeRouteMaxAge", publicName: "memorizeRouteMaxAge", isSignal: true, isRequired: false, transformFunction: null }, connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
596
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RouteMemorizeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
597
+ /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.6", type: RouteMemorizeDirective, isStandalone: true, selector: "iframe[memorizeRoute]", inputs: { memorizeRoute: { classPropertyName: "memorizeRoute", publicName: "memorizeRoute", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteId: { classPropertyName: "memorizeRouteId", publicName: "memorizeRouteId", isSignal: true, isRequired: false, transformFunction: null }, memorizeMaxAge: { classPropertyName: "memorizeMaxAge", publicName: "memorizeMaxAge", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteMaxAge: { classPropertyName: "memorizeRouteMaxAge", publicName: "memorizeRouteMaxAge", isSignal: true, isRequired: false, transformFunction: null }, connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
566
598
  }
567
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RouteMemorizeDirective, decorators: [{
599
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RouteMemorizeDirective, decorators: [{
568
600
  type: Directive,
569
601
  args: [{
570
602
  selector: 'iframe[memorizeRoute]',
@@ -572,6 +604,36 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
572
604
  }]
573
605
  }], ctorParameters: () => [] });
574
606
 
607
+ /**
608
+ * A constant array of known message types and their versions.
609
+ */
610
+ const KNOWN_MESSAGES = [
611
+ {
612
+ type: ERROR_MESSAGE_TYPE,
613
+ version: '1.0'
614
+ }
615
+ ];
616
+ /**
617
+ * Returns the default options for starting a client endpoint peer connection.
618
+ * As `origin`, it will take the hostURL from {@link getHostInfo} and the `window` will be the parent window.
619
+ */
620
+ function getDefaultClientEndpointStartOptions() {
621
+ const hostInfo = getHostInfo();
622
+ if (hostInfo.hostURL) {
623
+ return {
624
+ origin: new URL(hostInfo.hostURL).origin,
625
+ window: window.parent
626
+ };
627
+ }
628
+ return {};
629
+ }
630
+ /**
631
+ * Return `true` if embedded inside an iframe, `false` otherwise
632
+ */
633
+ function isEmbedded() {
634
+ return window.top !== window.self;
635
+ }
636
+
575
637
  /**
576
638
  * A service that handles routing and message production for navigation events.
577
639
  *
@@ -615,7 +677,10 @@ class RoutingService {
615
677
  url
616
678
  };
617
679
  // TODO: sendBest() is not implemented -- https://github.com/AmadeusITGroup/microfrontends/issues/11
618
- if (window.self === window.top) {
680
+ if (isEmbedded()) {
681
+ this.messageService.send(messageV10);
682
+ }
683
+ else {
619
684
  if (channelId === undefined) {
620
685
  this.logger.warn('No channelId provided for navigation message');
621
686
  }
@@ -628,15 +693,12 @@ class RoutingService {
628
693
  }
629
694
  }
630
695
  }
631
- else {
632
- this.messageService.send(messageV10);
633
- }
634
696
  });
635
697
  }
636
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RoutingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
637
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RoutingService, providedIn: 'root' }); }
698
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RoutingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
699
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RoutingService, providedIn: 'root' }); }
638
700
  }
639
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RoutingService, decorators: [{
701
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RoutingService, decorators: [{
640
702
  type: Injectable,
641
703
  args: [{
642
704
  providedIn: 'root'
@@ -683,10 +745,10 @@ class RestoreRoute {
683
745
  return typeof url === 'string' ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
684
746
  }
685
747
  }
686
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RestoreRoute, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
687
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: RestoreRoute, isStandalone: true, name: "restoreRoute" }); }
748
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RestoreRoute, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
749
+ /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: RestoreRoute, isStandalone: true, name: "restoreRoute" }); }
688
750
  }
689
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: RestoreRoute, decorators: [{
751
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: RestoreRoute, decorators: [{
690
752
  type: Pipe,
691
753
  args: [{
692
754
  name: 'restoreRoute'
@@ -753,8 +815,9 @@ async function applyInitialTheme(options) {
753
815
  if (theme) {
754
816
  const themeRequest = [];
755
817
  themeRequest.push(downloadApplicationThemeCss(theme, options).then((styleToApply) => applyTheme(styleToApply, false)));
756
- if (document.referrer) {
757
- const url = new URL(document.referrer);
818
+ const hostInfo = getHostInfo();
819
+ if (hostInfo.hostURL) {
820
+ const url = new URL(hostInfo.hostURL);
758
821
  url.pathname += `${url.pathname.endsWith('/') ? '' : '/'}${theme}`;
759
822
  themeRequest.unshift(getStyle(url.toString(), options).then((styleToApply) => applyTheme(styleToApply, false)));
760
823
  }
@@ -840,10 +903,10 @@ class ThemeProducerService {
840
903
  this.logger.error('Error in theme service message', message);
841
904
  this.revertToPreviousTheme();
842
905
  }
843
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeProducerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
844
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeProducerService, providedIn: 'root' }); }
906
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeProducerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
907
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeProducerService, providedIn: 'root' }); }
845
908
  }
846
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeProducerService, decorators: [{
909
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeProducerService, decorators: [{
847
910
  type: Injectable,
848
911
  args: [{
849
912
  providedIn: 'root'
@@ -876,10 +939,10 @@ class ApplyTheme {
876
939
  }
877
940
  return undefined;
878
941
  }
879
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ApplyTheme, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
880
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: ApplyTheme, isStandalone: true, name: "applyTheme" }); }
942
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ApplyTheme, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
943
+ /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: ApplyTheme, isStandalone: true, name: "applyTheme" }); }
881
944
  }
882
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ApplyTheme, decorators: [{
945
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ApplyTheme, decorators: [{
883
946
  type: Pipe,
884
947
  args: [{
885
948
  name: 'applyTheme'
@@ -935,10 +998,10 @@ class ThemeConsumerService {
935
998
  stop() {
936
999
  this.consumerManagerService.unregister(this);
937
1000
  }
938
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
939
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeConsumerService, providedIn: 'root' }); }
1001
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1002
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeConsumerService, providedIn: 'root' }); }
940
1003
  }
941
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ThemeConsumerService, decorators: [{
1004
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ThemeConsumerService, decorators: [{
942
1005
  type: Injectable,
943
1006
  args: [{
944
1007
  providedIn: 'root'
@@ -991,10 +1054,10 @@ class ConnectDirective {
991
1054
  // When the directive is destroyed clean up the connection too.
992
1055
  inject(DestroyRef).onDestroy(() => this.messageService.disconnect());
993
1056
  }
994
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ConnectDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
995
- /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.4", type: ConnectDirective, isStandalone: true, selector: "iframe[connect]", inputs: { connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: true, transformFunction: null }, src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "src": "this.srcAttr" } }, ngImport: i0 }); }
1057
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ConnectDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1058
+ /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.6", type: ConnectDirective, isStandalone: true, selector: "iframe[connect]", inputs: { connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: true, transformFunction: null }, src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "src": "this.srcAttr" } }, ngImport: i0 }); }
996
1059
  }
997
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ConnectDirective, decorators: [{
1060
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ConnectDirective, decorators: [{
998
1061
  type: Directive,
999
1062
  args: [{
1000
1063
  selector: 'iframe[connect]',
@@ -1010,7 +1073,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
1010
1073
  * @param connectionConfig The identifier of the application in the communication protocol ecosystem plus the types of messages able to exchange
1011
1074
  */
1012
1075
  function provideConnection(connectionConfig) {
1013
- const config = { id: connectionConfig.id, knownMessages: [...KNOWN_MESSAGES, ...(connectionConfig.knownMessages || [])] };
1076
+ persistHostInfo();
1077
+ const config = {
1078
+ id: connectionConfig.id,
1079
+ messageCheckStrategy: 'version',
1080
+ knownMessages: [...KNOWN_MESSAGES, ...(connectionConfig.knownMessages || [])]
1081
+ };
1014
1082
  return makeEnvironmentProviders([
1015
1083
  {
1016
1084
  provide: MESSAGE_PEER_CONFIG, useValue: config
@@ -1019,7 +1087,7 @@ function provideConnection(connectionConfig) {
1019
1087
  provide: MESSAGE_PEER_CONNECT_OPTIONS, useValue: getDefaultClientEndpointStartOptions()
1020
1088
  },
1021
1089
  {
1022
- // in the case of the ConnectionService will extends the base service 'useExisting' should be used
1090
+ // in the case of the ConnectionService will extend the base service 'useExisting' should be used
1023
1091
  provide: MessagePeerService, useClass: MessagePeerService, deps: [MESSAGE_PEER_CONFIG]
1024
1092
  }
1025
1093
  ]);
@@ -1029,5 +1097,5 @@ function provideConnection(connectionConfig) {
1029
1097
  * Generated bundle index. Do not edit.
1030
1098
  */
1031
1099
 
1032
- export { ApplyTheme, ConnectDirective, ConsumerManagerService, DELTA_RESIZE, ERROR_MESSAGE_TYPE, KNOWN_MESSAGES, MFE_HOST_URL_PARAM, NavigationConsumerService, ProducerManagerService, ResizeConsumerService, ResizeService, RestoreRoute, RouteMemorizeDirective, RouteMemorizeService, RoutingService, ScalableDirective, THEME_QUERY_PARAM_NAME, THEME_URL_SUFFIX, ThemeConsumerService, ThemeProducerService, applyInitialTheme, applyTheme, downloadApplicationThemeCss, getAvailableConsumers, getDefaultClientEndpointStartOptions, getStyle, isErrorMessage, provideConnection, registerProducer, sendError };
1100
+ export { ApplyTheme, ConnectDirective, ConsumerManagerService, DELTA_RESIZE, ERROR_MESSAGE_TYPE, HostInfoPipe, KNOWN_MESSAGES, MFE_HOST_APPLICATION_ID_PARAM, MFE_HOST_URL_PARAM, NavigationConsumerService, ProducerManagerService, ResizeConsumerService, ResizeService, RestoreRoute, RouteMemorizeDirective, RouteMemorizeService, RoutingService, ScalableDirective, THEME_QUERY_PARAM_NAME, THEME_URL_SUFFIX, ThemeConsumerService, ThemeProducerService, applyInitialTheme, applyTheme, downloadApplicationThemeCss, getAvailableConsumers, getDefaultClientEndpointStartOptions, getHostInfo, getStyle, isEmbedded, isErrorMessage, persistHostInfo, provideConnection, registerProducer, sendError };
1033
1101
  //# sourceMappingURL=ama-mfe-ng-utils.mjs.map