@ama-mfe/ng-utils 14.0.0-next.0 → 14.0.0-next.10

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/index.d.ts CHANGED
@@ -1,12 +1,61 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { PipeTransform } from '@angular/core';
3
- import { VersionedMessage, RoutedMessage, PeerConnectionOptions } from '@amadeus-it-group/microfrontends';
4
- import { MessagePeerServiceType, MessagePeerConfig } from '@amadeus-it-group/microfrontends-angular';
5
- export { MessagePeerConfig as ConnectionConfig, MessagePeerService as ConnectionService } from '@amadeus-it-group/microfrontends-angular';
6
- import { ResizeMessage, ResizeV1_0, NavigationMessage, NavigationV1_0, ThemeMessage, ThemeV1_0, ThemeStructure } from '@ama-mfe/messages';
7
- import * as rxjs from 'rxjs';
8
3
  import { SafeResourceUrl } from '@angular/platform-browser';
9
4
  import { Logger } from '@o3r/logger';
5
+ import { MessagePeerConfig, MessagePeerServiceType } from '@amadeus-it-group/microfrontends-angular';
6
+ export { MessagePeerConfig as ConnectionConfig, MessagePeerService as ConnectionService } from '@amadeus-it-group/microfrontends-angular';
7
+ import { UserActivityMessage, HistoryMessage, HistoryV1_0, NavigationMessage, NavigationV1_0, ResizeMessage, ResizeV1_0, ThemeMessage, ThemeV1_0, ThemeStructure, UserActivityEventType, UserActivityMessageV1_0 } from '@ama-mfe/messages';
8
+ import { VersionedMessage, RoutedMessage, PeerConnectionOptions } from '@amadeus-it-group/microfrontends';
9
+ import * as rxjs from 'rxjs';
10
+
11
+ declare class ConnectDirective {
12
+ /**
13
+ * The connection ID required for the message peer service.
14
+ */
15
+ connect: i0.InputSignal<string>;
16
+ /**
17
+ * The sanitized source URL for the iframe.
18
+ */
19
+ src: i0.InputSignal<SafeResourceUrl | undefined>;
20
+ /**
21
+ * Binds the `src` attribute of the iframe to the sanitized source URL.
22
+ */
23
+ get srcAttr(): SafeResourceUrl | undefined;
24
+ private readonly messageService;
25
+ private readonly domSanitizer;
26
+ private readonly iframeElement;
27
+ private readonly clientOrigin;
28
+ constructor();
29
+ static ɵfac: i0.ɵɵFactoryDeclaration<ConnectDirective, never>;
30
+ static ɵdir: i0.ɵɵDirectiveDeclaration<ConnectDirective, "iframe[connect]", never, { "connect": { "alias": "connect"; "required": true; "isSignal": true; }; "src": { "alias": "src"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
31
+ }
32
+
33
+ /** Options to configure the connection inside the communication protocol */
34
+ interface ConnectionConfigOptions extends Omit<MessagePeerConfig, 'id'> {
35
+ /** @inheritdoc */
36
+ id?: string;
37
+ /** Logger used to gather information */
38
+ logger?: Logger;
39
+ }
40
+ /**
41
+ * Provide the communication protocol connection configuration
42
+ * @param connectionConfigOptions The identifier of the application in the communication protocol ecosystem plus the types of messages able to exchange and a logger object
43
+ */
44
+ declare function provideConnection(connectionConfigOptions?: ConnectionConfigOptions): i0.EnvironmentProviders;
45
+
46
+ /**
47
+ * Gets the available consumers and formats them into a {@link DeclareMessages} object.
48
+ * @param consumers - The list of registered message consumers.
49
+ * @returns The formatted DeclareMessages object.
50
+ */
51
+ declare const getAvailableConsumers: (consumers: BasicMessageConsumer[]) => {
52
+ type: "declare_messages";
53
+ version: "1.0";
54
+ messages: {
55
+ type: string;
56
+ version: string;
57
+ }[];
58
+ };
10
59
 
11
60
  /** the error message type */
12
61
  declare const ERROR_MESSAGE_TYPE = "error";
@@ -51,18 +100,10 @@ declare const isErrorMessage: (message: any) => message is VersionedMessage & {
51
100
  } & ErrorContent;
52
101
 
53
102
  /**
54
- * Gets the available consumers and formats them into a {@see DeclareMessages} object.
55
- * @param consumers - The list of registered message consumers.
56
- * @returns The formatted DeclareMessages object.
103
+ * Type guard to check if a message is a user activity message
104
+ * @param message The message to check
57
105
  */
58
- declare const getAvailableConsumers: (consumers: BasicMessageConsumer[]) => {
59
- type: "declare_messages";
60
- version: "1.0";
61
- messages: {
62
- type: string;
63
- version: string;
64
- }[];
65
- };
106
+ declare function isUserActivityMessage(message: unknown): message is UserActivityMessage;
66
107
 
67
108
  /**
68
109
  * Use the message payload to execute an action based on message type
@@ -183,92 +224,120 @@ declare const registerProducer: (producer: MessageProducer) => void;
183
224
  declare const registerConsumer: (consumer: MessageConsumer) => void;
184
225
 
185
226
  /**
186
- * This service listens for resize messages and updates the height of elements based on the received messages.
227
+ * A service that handles history messages.
228
+ *
229
+ * This service listens for history messages and navigates accordingly.
187
230
  */
188
- declare class ResizeConsumerService implements MessageConsumer<ResizeMessage> {
189
- private readonly newHeight;
190
- /**
191
- * A readonly signal that provides the new height information from the channel.
192
- */
193
- readonly newHeightFromChannel: i0.Signal<{
194
- height: number;
195
- channelId: string;
196
- } | undefined>;
231
+ declare class HistoryConsumerService implements MessageConsumer<HistoryMessage> {
197
232
  /**
198
- * The type of messages this service handles ('resize').
233
+ * The type of messages this service handles.
199
234
  */
200
- readonly type = "resize";
235
+ readonly type = "history";
201
236
  /**
202
- * The supported versions of resize messages and their handlers.
237
+ * @inheritdoc
203
238
  */
204
- supportedVersions: {
239
+ readonly supportedVersions: {
205
240
  /**
206
- * Use the message paylod to compute a new height and emit it via the public signal
241
+ * Use the message payload to navigate in the history
207
242
  * @param message message to consume
208
243
  */
209
- '1.0': (message: RoutedMessage<ResizeV1_0>) => void;
244
+ '1.0': (message: RoutedMessage<HistoryV1_0>) => void;
210
245
  };
211
246
  private readonly consumerManagerService;
212
247
  constructor();
213
248
  /**
214
- * Starts the resize handler service by registering it into the consumer manager service.
249
+ * @inheritdoc
215
250
  */
216
251
  start(): void;
217
252
  /**
218
- * Stops the resize handler service by unregistering it from the consumer manager service.
253
+ * @inheritdoc
219
254
  */
220
255
  stop(): void;
221
- static ɵfac: i0.ɵɵFactoryDeclaration<ResizeConsumerService, never>;
222
- static ɵprov: i0.ɵɵInjectableDeclaration<ResizeConsumerService>;
256
+ static ɵfac: i0.ɵɵFactoryDeclaration<HistoryConsumerService, never>;
257
+ static ɵprov: i0.ɵɵInjectableDeclaration<HistoryConsumerService>;
223
258
  }
224
259
 
225
260
  /**
226
- * This service observe changes in the document's body height.
227
- * When the height changes, it sends a resize message with the new height, to the connected peers
261
+ * Provides necessary overrides to make the module navigation in history work in an embedded context :
262
+ * - Prevent pushing states to history, replace state instead
263
+ * - Handle history navigation via History messages to let the host manage the states
228
264
  */
229
- declare class ResizeService implements MessageProducer<ResizeMessage> {
230
- private actualHeight?;
231
- private readonly messageService;
232
- private resizeObserver?;
265
+ declare function provideHistoryOverrides(): i0.EnvironmentProviders;
266
+
267
+ /**
268
+ * Search parameter to add to the URL when embedding an iframe containing the URL of the host.
269
+ * This is needed to support Firefox (on which {@link https://developer.mozilla.org/docs/Web/API/Location/ancestorOrigins | location.ancestorOrigins} is not currently supported)
270
+ * in case of redirection inside the iframe.
271
+ */
272
+ declare const MFE_HOST_URL_PARAM = "ama-mfe-host-url";
273
+ /**
274
+ * Search parameter to add to the URL to let a module know on which application it's embedded
275
+ */
276
+ declare const MFE_HOST_APPLICATION_ID_PARAM = "ama-mfe-host-app-id";
277
+ /**
278
+ * Search parameter to add to the URL to identify the application in the network of peers in the communication protocol
279
+ */
280
+ declare const MFE_MODULE_APPLICATION_ID_PARAM = "ama-mfe-module-app-id";
281
+ /** The list of query parameters which can be set by the host */
282
+ declare const hostQueryParams: string[];
283
+ /**
284
+ * Information set up at host level to use in embedded context
285
+ */
286
+ interface MFEHostInformation {
233
287
  /**
234
- * @inheritdoc
288
+ * URL of the host application
235
289
  */
236
- readonly types = "resize";
237
- constructor();
290
+ hostURL?: string;
238
291
  /**
239
- * @inheritdoc
292
+ * ID of the host application
240
293
  */
241
- handleError(message: ErrorContent<ResizeMessage>): void;
294
+ hostApplicationId?: string;
242
295
  /**
243
- * This method sets up a `ResizeObserver` to observe changes in the document's body height.
244
- * When the height changes, it sends a resize message with the new height, to the connected peers
296
+ * ID of the module to embed defined at host level
245
297
  */
246
- startResizeObserver(): void;
247
- static ɵfac: i0.ɵɵFactoryDeclaration<ResizeService, never>;
248
- static ɵprov: i0.ɵɵInjectableDeclaration<ResizeService>;
298
+ moduleApplicationId?: string;
249
299
  }
300
+ /**
301
+ * Gather the host information from the url parameters
302
+ * The host url will use the first found among:
303
+ * - look for the search parameter {@link MFE_HOST_URL_PARAM} in the URL of the iframe
304
+ * - use the first item in `location.ancestorOrigins` (currently not supported on Firefox)
305
+ * - use `document.referrer` (will only work if called before any redirection in the iframe)
306
+ * The host application ID is taken from the search parameter {@link MFE_HOST_APPLICATION_ID_PARAM} in the URL of the iframe
307
+ * The module application ID is taken from the search parameter {@link MFE_APPLICATION_ID_PARAM} in the URL of the iframe
308
+ * @param locationParam - A {@link Location} object with information about the current location of the document. Defaults to global {@link location}.
309
+ */
310
+ declare function getHostInfo(locationParam?: Location): MFEHostInformation;
311
+ /**
312
+ * Gather the host information from the url parameters and handle the persistence in session storage.
313
+ */
314
+ declare function persistHostInfo(): void;
250
315
 
251
316
  /**
252
- * A directive that adjusts the height of an element based on resize messages from a specified channel.
317
+ * A pipe that adds the host information in the URL of an iframe,
253
318
  */
254
- declare class ScalableDirective {
255
- /**
256
- * The connection ID for the element, used as channel id backup
257
- */
258
- connect: i0.InputSignal<string | undefined>;
259
- /**
260
- * The channel id
261
- */
262
- scalable: i0.InputSignal<string | undefined>;
263
- private readonly resizeHandler;
319
+ declare class HostInfoPipe implements PipeTransform {
320
+ private readonly domSanitizer;
264
321
  /**
265
- * This signal checks if the current channel requesting the resize matches the channel ID from the resize handler.
266
- * If they match, it returns the new height information; otherwise, it returns undefined.
322
+ * Transforms the given URL or SafeResourceUrl by appending query parameters.
323
+ * @param url - The URL or SafeResourceUrl to be transformed.
324
+ * @param options - hostId and moduleId
325
+ * @returns - The transformed SafeResourceUrl or undefined if the input URL is invalid.
267
326
  */
268
- private readonly newHeightFromChannel;
269
- constructor();
270
- static ɵfac: i0.ɵɵFactoryDeclaration<ScalableDirective, never>;
271
- static ɵdir: i0.ɵɵDirectiveDeclaration<ScalableDirective, "[scalable]", never, { "connect": { "alias": "connect"; "required": false; "isSignal": true; }; "scalable": { "alias": "scalable"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
327
+ transform(url: string, options: {
328
+ hostId: string;
329
+ moduleId?: string;
330
+ }): string;
331
+ transform(url: SafeResourceUrl, options: {
332
+ hostId: string;
333
+ moduleId?: string;
334
+ }): SafeResourceUrl;
335
+ transform(url: undefined, options: {
336
+ hostId: string;
337
+ moduleId?: string;
338
+ }): undefined;
339
+ static ɵfac: i0.ɵɵFactoryDeclaration<HostInfoPipe, never>;
340
+ static ɵpipe: i0.ɵɵPipeDeclaration<HostInfoPipe, "hostInfo", true>;
272
341
  }
273
342
 
274
343
  /**
@@ -327,6 +396,48 @@ declare class NavigationConsumerService implements MessageConsumer<NavigationMes
327
396
  static ɵprov: i0.ɵɵInjectableDeclaration<NavigationConsumerService>;
328
397
  }
329
398
 
399
+ /**
400
+ * Options for restoring a route with optional query parameters and memory channel ID.
401
+ */
402
+ interface RestoreRouteOptions {
403
+ /**
404
+ * Whether to propagate query parameters from the top window to the module URL.
405
+ */
406
+ propagateQueryParams?: boolean;
407
+ /**
408
+ * Whether to override existing query parameters in the module URL with those from the top window.
409
+ */
410
+ overrideQueryParams?: boolean;
411
+ /**
412
+ * The memory channel ID used to retrieve the memorized route.
413
+ * If provided, the memorized route associated with this ID will be used.
414
+ */
415
+ memoryChannelId?: string;
416
+ }
417
+ /**
418
+ * A pipe that restores a route with optional query parameters and memory channel ID.
419
+ *
420
+ * This pipe is used to transform a URL or SafeResourceUrl by appending query parameters
421
+ * and adjusting the pathname based on the current active route and memorized route.
422
+ */
423
+ declare class RestoreRoute implements PipeTransform {
424
+ private readonly activeRoute;
425
+ private readonly domSanitizer;
426
+ private readonly routeMemorizeService;
427
+ private readonly window;
428
+ /**
429
+ * Transforms the given URL or SafeResourceUrl by appending query parameters and adjusting the pathname.
430
+ * @param url - The URL or SafeResourceUrl to be transformed.
431
+ * @param options - Optional parameters to control the transformation. {@link RestoreRouteOptions}
432
+ * @returns - The transformed SafeResourceUrl or undefined if the input URL is invalid.
433
+ */
434
+ transform(url: string, options?: Partial<RestoreRouteOptions>): string;
435
+ transform(url: SafeResourceUrl, options?: Partial<RestoreRouteOptions>): SafeResourceUrl;
436
+ transform(url: undefined, options?: Partial<RestoreRouteOptions>): undefined;
437
+ static ɵfac: i0.ɵɵFactoryDeclaration<RestoreRoute, never>;
438
+ static ɵpipe: i0.ɵɵPipeDeclaration<RestoreRoute, "restoreRoute", true>;
439
+ }
440
+
330
441
  declare class RouteMemorizeDirective {
331
442
  /**
332
443
  * Whether to memorize the route.
@@ -403,6 +514,7 @@ declare class RoutingService implements MessageProducer<NavigationMessage>, Mess
403
514
  private readonly activatedRoute;
404
515
  private readonly messageService;
405
516
  private readonly logger;
517
+ private readonly window;
406
518
  /**
407
519
  * @inheritdoc
408
520
  */
@@ -435,7 +547,7 @@ declare class RoutingService implements MessageProducer<NavigationMessage>, Mess
435
547
  * Handles embedded routing by listening to router events and sending navigation messages to the connected endpoints.
436
548
  * It can be a parent window or another iframe
437
549
  * @note - This method has to be called in an injection context
438
- * @param options - Optional parameters to control the routing behavior {@see RoutingServiceOptions}.
550
+ * @param options - Optional parameters to control the routing behavior {@link RoutingServiceOptions}.
439
551
  */
440
552
  handleEmbeddedRouting(options?: RoutingServiceOptions): void;
441
553
  static ɵfac: i0.ɵɵFactoryDeclaration<RoutingService, never>;
@@ -443,44 +555,92 @@ declare class RoutingService implements MessageProducer<NavigationMessage>, Mess
443
555
  }
444
556
 
445
557
  /**
446
- * Options for restoring a route with optional query parameters and memory channel ID.
558
+ * This service listens for resize messages and updates the height of elements based on the received messages.
447
559
  */
448
- interface RestoreRouteOptions {
560
+ declare class ResizeConsumerService implements MessageConsumer<ResizeMessage> {
561
+ private readonly newHeight;
449
562
  /**
450
- * Whether to propagate query parameters from the top window to the module URL.
563
+ * A readonly signal that provides the new height information from the channel.
451
564
  */
452
- propagateQueryParams?: boolean;
565
+ readonly newHeightFromChannel: i0.Signal<{
566
+ height: number;
567
+ channelId: string;
568
+ } | undefined>;
453
569
  /**
454
- * Whether to override existing query parameters in the module URL with those from the top window.
570
+ * The type of messages this service handles ('resize').
455
571
  */
456
- overrideQueryParams?: boolean;
572
+ readonly type = "resize";
457
573
  /**
458
- * The memory channel ID used to retrieve the memorized route.
459
- * If provided, the memorized route associated with this ID will be used.
574
+ * The supported versions of resize messages and their handlers.
460
575
  */
461
- memoryChannelId?: string;
462
- }
463
- /**
464
- * A pipe that restores a route with optional query parameters and memory channel ID.
465
- *
466
- * This pipe is used to transform a URL or SafeResourceUrl by appending query parameters
467
- * and adjusting the pathname based on the current active route and memorized route.
468
- */
469
- declare class RestoreRoute implements PipeTransform {
470
- private readonly activeRoute;
471
- private readonly domSanitizer;
472
- private readonly routeMemorizeService;
473
- /**
474
- * Transforms the given URL or SafeResourceUrl by appending query parameters and adjusting the pathname.
475
- * @param url - The URL or SafeResourceUrl to be transformed.
476
- * @param options - Optional parameters to control the transformation. {@see RestoreRouteOptions}
477
- * @returns - The transformed SafeResourceUrl or undefined if the input URL is invalid.
576
+ supportedVersions: {
577
+ /**
578
+ * Use the message paylod to compute a new height and emit it via the public signal
579
+ * @param message message to consume
580
+ */
581
+ '1.0': (message: RoutedMessage<ResizeV1_0>) => void;
582
+ };
583
+ private readonly consumerManagerService;
584
+ constructor();
585
+ /**
586
+ * Starts the resize handler service by registering it into the consumer manager service.
478
587
  */
479
- transform(url: string, options?: Partial<RestoreRouteOptions>): string;
480
- transform(url: SafeResourceUrl, options?: Partial<RestoreRouteOptions>): SafeResourceUrl;
481
- transform(url: undefined, options?: Partial<RestoreRouteOptions>): undefined;
482
- static ɵfac: i0.ɵɵFactoryDeclaration<RestoreRoute, never>;
483
- static ɵpipe: i0.ɵɵPipeDeclaration<RestoreRoute, "restoreRoute", true>;
588
+ start(): void;
589
+ /**
590
+ * Stops the resize handler service by unregistering it from the consumer manager service.
591
+ */
592
+ stop(): void;
593
+ static ɵfac: i0.ɵɵFactoryDeclaration<ResizeConsumerService, never>;
594
+ static ɵprov: i0.ɵɵInjectableDeclaration<ResizeConsumerService>;
595
+ }
596
+
597
+ /**
598
+ * This service observe changes in the document's body height.
599
+ * When the height changes, it sends a resize message with the new height, to the connected peers
600
+ */
601
+ declare class ResizeService implements MessageProducer<ResizeMessage> {
602
+ private actualHeight?;
603
+ private readonly messageService;
604
+ private resizeObserver?;
605
+ /**
606
+ * @inheritdoc
607
+ */
608
+ readonly types = "resize";
609
+ constructor();
610
+ /**
611
+ * @inheritdoc
612
+ */
613
+ handleError(message: ErrorContent<ResizeMessage>): void;
614
+ /**
615
+ * This method sets up a `ResizeObserver` to observe changes in the document's body height.
616
+ * When the height changes, it sends a resize message with the new height, to the connected peers
617
+ */
618
+ startResizeObserver(): void;
619
+ static ɵfac: i0.ɵɵFactoryDeclaration<ResizeService, never>;
620
+ static ɵprov: i0.ɵɵInjectableDeclaration<ResizeService>;
621
+ }
622
+
623
+ /**
624
+ * A directive that adjusts the height of an element based on resize messages from a specified channel.
625
+ */
626
+ declare class ScalableDirective {
627
+ /**
628
+ * The connection ID for the element, used as channel id backup
629
+ */
630
+ connect: i0.InputSignal<string | undefined>;
631
+ /**
632
+ * The channel id
633
+ */
634
+ scalable: i0.InputSignal<string | undefined>;
635
+ private readonly resizeHandler;
636
+ /**
637
+ * This signal checks if the current channel requesting the resize matches the channel ID from the resize handler.
638
+ * If they match, it returns the new height information; otherwise, it returns undefined.
639
+ */
640
+ private readonly newHeightFromChannel;
641
+ constructor();
642
+ static ɵfac: i0.ɵɵFactoryDeclaration<ScalableDirective, never>;
643
+ static ɵdir: i0.ɵɵDirectiveDeclaration<ScalableDirective, "[scalable]", never, { "connect": { "alias": "connect"; "required": false; "isSignal": true; }; "scalable": { "alias": "scalable"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
484
644
  }
485
645
 
486
646
  /**
@@ -581,6 +741,7 @@ declare class ThemeProducerService implements MessageProducer<ThemeMessage> {
581
741
  private readonly messageService;
582
742
  private readonly logger;
583
743
  private previousTheme;
744
+ private readonly window;
584
745
  private readonly currentThemeSelection;
585
746
  /** Current selected theme signal */
586
747
  readonly currentTheme: i0.Signal<ThemeStructure | undefined>;
@@ -606,133 +767,315 @@ declare class ThemeProducerService implements MessageProducer<ThemeMessage> {
606
767
  static ɵprov: i0.ɵɵInjectableDeclaration<ThemeProducerService>;
607
768
  }
608
769
 
609
- declare class ConnectDirective {
770
+ /**
771
+ * Information about user activity received from another context
772
+ */
773
+ interface ActivityInfo {
774
+ /** The channel ID (source ID) that sent the activity */
775
+ channelId: string;
776
+ /** The type of activity event */
777
+ eventType: string;
778
+ /** Timestamp when the activity occurred */
779
+ timestamp: number;
780
+ }
781
+ /**
782
+ * Configuration options for the activity producer service
783
+ */
784
+ interface ActivityProducerConfig {
610
785
  /**
611
- * The connection ID required for the message peer service.
786
+ * Minimum interval in milliseconds between activity messages sent to the consumer.
787
+ * When multiple events occur within this interval, only the first one triggers a message.
788
+ * This prevents flooding the communication channel with too many messages.
612
789
  */
613
- connect: i0.InputSignal<string>;
790
+ throttleMs: number;
614
791
  /**
615
- * The sanitized source URL for the iframe.
792
+ * Optional filter function to determine if an event should be broadcast to the host(shell) app.
793
+ * Return true to broadcast the event, false to ignore it.
794
+ * Useful for filtering out events that occur on specific elements (e.g., iframes handled separately).
795
+ * @param event The DOM event that triggered the activity
796
+ * @returns Whether the event should be broadcast
616
797
  */
617
- src: i0.InputSignal<SafeResourceUrl | undefined>;
798
+ shouldBroadcast?: (event: Event) => boolean;
618
799
  /**
619
- * Binds the `src` attribute of the iframe to the sanitized source URL.
800
+ * Enable tracking of nested iframes. When enabled, the service will detect when focus
801
+ * moves to an iframe within the document and send periodic activity signals while
802
+ * the iframe has focus. This is useful for modules that contain iframes whose content
803
+ * cannot be modified to include activity tracking.
620
804
  */
621
- get srcAttr(): SafeResourceUrl | undefined;
622
- private readonly messageService;
623
- private readonly domSanitizer;
624
- private readonly iframeElement;
625
- private readonly clientOrigin;
626
- constructor();
627
- static ɵfac: i0.ɵɵFactoryDeclaration<ConnectDirective, never>;
628
- static ɵdir: i0.ɵɵDirectiveDeclaration<ConnectDirective, "iframe[connect]", never, { "connect": { "alias": "connect"; "required": true; "isSignal": true; }; "src": { "alias": "src"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
629
- }
630
-
631
- /** Options to configure the connection inside the communication protocol */
632
- interface ConnectionConfigOptions extends Omit<MessagePeerConfig, 'id'> {
633
- /** @inheritdoc */
634
- id?: string;
635
- /** Logger used to gather information */
636
- logger?: Logger;
805
+ trackNestedIframes?: boolean;
806
+ /**
807
+ * Interval in milliseconds for polling document.activeElement to detect iframe focus.
808
+ * Only used when trackNestedIframes is true.
809
+ * @default 1000
810
+ */
811
+ nestedIframePollIntervalMs?: number;
812
+ /**
813
+ * Interval in milliseconds for sending activity signals to the host(shell) app while a nested iframe has focus.
814
+ * Only used when trackNestedIframes is true.
815
+ * @default 30000
816
+ */
817
+ nestedIframeActivityEmitIntervalMs?: number;
818
+ /**
819
+ * Throttle time in milliseconds for high-frequency events (scroll, mousemove).
820
+ * These events are throttled to avoid performance issues.
821
+ * @default 300
822
+ */
823
+ highFrequencyThrottleMs?: number;
637
824
  }
638
825
  /**
639
- * Provide the communication protocol connection configuration
640
- * @param connectionConfigOptions The identifier of the application in the communication protocol ecosystem plus the types of messages able to exchange and a logger object
826
+ * Configuration for the iframe activity tracker
641
827
  */
642
- declare function provideConnection(connectionConfigOptions?: ConnectionConfigOptions): i0.EnvironmentProviders;
828
+ interface IframeActivityTrackerConfig {
829
+ /**
830
+ * Interval in milliseconds for polling document.activeElement to detect iframe focus.
831
+ * @default 1000
832
+ */
833
+ pollIntervalMs?: number;
834
+ /**
835
+ * Interval in milliseconds for sending activity signals to the host(shell) app while an iframe has focus.
836
+ * @default 30000
837
+ */
838
+ activityIntervalMs?: number;
839
+ /**
840
+ * Callback to invoke when activity is detected
841
+ */
842
+ onActivity: () => void;
843
+ }
643
844
 
644
845
  /**
645
- * A constant array of known message types and their versions.
846
+ * DOM events that indicate user activity
646
847
  */
647
- declare const KNOWN_MESSAGES: [{
648
- readonly type: "error";
649
- readonly version: "1.0";
650
- }];
848
+ declare const ACTIVITY_EVENTS: readonly Exclude<UserActivityEventType, 'visibilitychange'>[];
651
849
  /**
652
- * Returns the default options for starting a client endpoint peer connection.
653
- * As `origin`, it will take the hostURL from {@link getHostInfo} and the `window` will be the parent window.
850
+ * Custom activity event type for iframe interactions.
851
+ * Emitted programmatically when an iframe gains focus, not from a DOM event listener.
654
852
  */
655
- declare function getDefaultClientEndpointStartOptions(): PeerConnectionOptions;
853
+ declare const IFRAME_INTERACTION_EVENT: UserActivityEventType;
656
854
  /**
657
- * Return `true` if embedded inside an iframe, `false` otherwise
855
+ * Custom activity event type for visibility changes.
856
+ * Emitted programmatically when the document becomes visible, not from a DOM event listener.
658
857
  */
659
- declare function isEmbedded(): boolean;
660
-
858
+ declare const VISIBILITY_CHANGE_EVENT: UserActivityEventType;
661
859
  /**
662
- * Search parameter to add to the URL when embedding an iframe containing the URL of the host.
663
- * This is needed to support Firefox (on which {@link https://developer.mozilla.org/docs/Web/API/Location/ancestorOrigins | location.ancestorOrigins} is not currently supported)
664
- * in case of redirection inside the iframe.
860
+ * High-frequency events that require throttling to avoid performance issues
665
861
  */
666
- declare const MFE_HOST_URL_PARAM = "ama-mfe-host-url";
862
+ declare const HIGH_FREQUENCY_EVENTS: readonly UserActivityEventType[];
667
863
  /**
668
- * Search parameter to add to the URL to let a module know on which application it's embedded
864
+ * Default configuration values for the ActivityProducerService
669
865
  */
670
- declare const MFE_HOST_APPLICATION_ID_PARAM = "ama-mfe-host-app-id";
671
- /**
672
- * Search parameter to add to the URL to identify the application in the network of peers in the communication protocol
673
- */
674
- declare const MFE_MODULE_APPLICATION_ID_PARAM = "ama-mfe-module-app-id";
675
- /** The list of query parameters which can be set by the host */
676
- declare const hostQueryParams: string[];
866
+ declare const DEFAULT_ACTIVITY_PRODUCER_CONFIG: Readonly<ActivityProducerConfig>;
867
+
677
868
  /**
678
- * Information set up at host level to use in embedded context
869
+ * Generic service that tracks user activity and sends messages.
870
+ * Can be configured for different contexts (cockpit or modules) via start() method parameter.
679
871
  */
680
- interface MFEHostInformation {
872
+ declare class ActivityProducerService implements MessageProducer<UserActivityMessage> {
873
+ private readonly messageService;
874
+ private readonly destroyRef;
875
+ private readonly iframeActivityTracker;
876
+ private readonly logger;
681
877
  /**
682
- * URL of the host application
878
+ * Timestamp of the last sent activity message
683
879
  */
684
- hostURL?: string;
880
+ private lastSentTimestamp;
685
881
  /**
686
- * ID of the host application
882
+ * Bound event listeners for cleanup
687
883
  */
688
- hostApplicationId?: string;
884
+ private readonly boundListeners;
689
885
  /**
690
- * ID of the module to embed defined at host level
886
+ * Last emission timestamps for throttled high-frequency events
691
887
  */
692
- moduleApplicationId?: string;
888
+ private readonly lastEmitTimestamps;
889
+ /**
890
+ * Whether the service has been started
891
+ */
892
+ private started;
893
+ /**
894
+ * Signal that emits local activity information.
895
+ * This allows consumers to react to activity detected by this producer.
896
+ */
897
+ private readonly localActivityWritable;
898
+ /**
899
+ * Read-only signal containing the latest local activity info.
900
+ * Use this signal to react to locally detected activity.
901
+ */
902
+ readonly localActivity: i0.Signal<ActivityInfo | undefined>;
903
+ /**
904
+ * @inheritdoc
905
+ */
906
+ readonly types = "user_activity";
907
+ constructor();
908
+ /**
909
+ * Handles high-frequency events by applying a per-eventType throttle before calling onActivity.
910
+ *
911
+ * Difference with onActivity:
912
+ * - onActivityThrottled limits how often a given high-frequency event type (e.g. scroll) is processed
913
+ * (based on highFrequencyThrottleMs and lastEmitTimestamps)
914
+ * - onActivity updates the local activity signal and applies the global message throttle
915
+ * (based on global throttleMs and lastSentTimestamp)
916
+ * @param eventType The type of activity event that occurred
917
+ * @param configObject
918
+ */
919
+ private onActivityThrottled;
920
+ /**
921
+ * Handles activity by sending a throttled message and emitting to local signal.
922
+ * @param eventType The type of activity event that occurred
923
+ * @param configObject
924
+ */
925
+ private onActivity;
926
+ /**
927
+ * Sends an activity message.
928
+ * @param eventType The type of activity event
929
+ * @param timestamp The timestamp of the event
930
+ */
931
+ private sendActivityMessage;
932
+ /**
933
+ * @inheritdoc
934
+ */
935
+ handleError(message: ErrorContent<UserActivityMessage>): void;
936
+ /**
937
+ * Starts observing user activity events.
938
+ * When activity is detected, it sends a throttled message.
939
+ * Event listeners are attached after the next render to ensure DOM is ready.
940
+ * @param config Configuration for the activity producer
941
+ */
942
+ start(config?: Partial<ActivityProducerConfig>): void;
943
+ /**
944
+ * Stops observing user activity events.
945
+ */
946
+ stop(): void;
947
+ static ɵfac: i0.ɵɵFactoryDeclaration<ActivityProducerService, never>;
948
+ static ɵprov: i0.ɵɵInjectableDeclaration<ActivityProducerService>;
693
949
  }
950
+
694
951
  /**
695
- * Gather the host information from the url parameters
696
- * The host url will use the first found among:
697
- * - look for the search parameter {@link MFE_HOST_URL_PARAM} in the URL of the iframe
698
- * - use the first item in `location.ancestorOrigins` (currently not supported on Firefox)
699
- * - use `document.referrer` (will only work if called before any redirection in the iframe)
700
- * The host application ID is taken from the search parameter {@link MFE_HOST_APPLICATION_ID_PARAM} in the URL of the iframe
701
- * The module application ID is taken from the search parameter {@link MFE_APPLICATION_ID_PARAM} in the URL of the iframe
702
- */
703
- declare function getHostInfo(): MFEHostInformation;
704
- /**
705
- * Gather the host information from the url parameters and handle the persistence in session storage.
952
+ * Generic service that consumes user activity messages.
953
+ * Can be used in both shell (to receive from modules) and modules (to receive from shell).
706
954
  */
707
- declare function persistHostInfo(): void;
955
+ declare class ActivityConsumerService implements BasicMessageConsumer<UserActivityMessageV1_0> {
956
+ private readonly consumerManagerService;
957
+ /**
958
+ * Signal containing the latest activity info
959
+ */
960
+ private readonly latestReceivedActivityWritable;
961
+ /**
962
+ * Read-only signal containing the latest activity info received from other peers via the message protocol.
963
+ * Access the timestamp via latestReceivedActivity()?.timestamp
964
+ */
965
+ readonly latestReceivedActivity: i0.Signal<ActivityInfo | undefined>;
966
+ /**
967
+ * @inheritdoc
968
+ */
969
+ readonly type = "user_activity";
970
+ /**
971
+ * @inheritdoc
972
+ */
973
+ readonly supportedVersions: Record<string, (message: RoutedMessage<UserActivityMessageV1_0>) => void>;
974
+ /**
975
+ * Starts the activity consumer service by registering it with the consumer manager.
976
+ */
977
+ start(): void;
978
+ /**
979
+ * Stops the activity consumer service by unregistering it from the consumer manager.
980
+ */
981
+ stop(): void;
982
+ static ɵfac: i0.ɵɵFactoryDeclaration<ActivityConsumerService, never>;
983
+ static ɵprov: i0.ɵɵInjectableDeclaration<ActivityConsumerService>;
984
+ }
708
985
 
709
986
  /**
710
- * A pipe that adds the host information in the URL of an iframe,
987
+ * Service that tracks user activity within nested iframes.
988
+ *
989
+ * Polls document.activeElement frequently to detect when an iframe has focus.
990
+ * When an iframe gains focus, emits immediately and then at the configured interval.
991
+ * When focus leaves the iframe, it stops emitting.
992
+ *
993
+ * This is needed because cross-origin iframes don't fire focus/blur events
994
+ * that bubble to the parent, and the regular activity tracker can't detect
995
+ * user interactions inside iframes.
711
996
  */
712
- declare class HostInfoPipe implements PipeTransform {
713
- private readonly domSanitizer;
997
+ declare class IframeActivityTrackerService {
714
998
  /**
715
- * Transforms the given URL or SafeResourceUrl by appending query parameters.
716
- * @param url - The URL or SafeResourceUrl to be transformed.
717
- * @param options - hostId and moduleId
718
- * @returns - The transformed SafeResourceUrl or undefined if the input URL is invalid.
999
+ * Interval ID for polling activeElement
719
1000
  */
720
- transform(url: string, options: {
721
- hostId: string;
722
- moduleId?: string;
723
- }): string;
724
- transform(url: SafeResourceUrl, options: {
725
- hostId: string;
726
- moduleId?: string;
727
- }): SafeResourceUrl;
728
- transform(url: undefined, options: {
729
- hostId: string;
730
- moduleId?: string;
731
- }): undefined;
732
- static ɵfac: i0.ɵɵFactoryDeclaration<HostInfoPipe, never>;
733
- static ɵpipe: i0.ɵɵPipeDeclaration<HostInfoPipe, "hostInfo", true>;
1001
+ private pollIntervalId?;
1002
+ /**
1003
+ * Interval ID for emitting activity at configured interval
1004
+ */
1005
+ private activityIntervalId?;
1006
+ /**
1007
+ * Current configuration
1008
+ */
1009
+ private config?;
1010
+ /**
1011
+ * Bound visibility change handler for cleanup
1012
+ */
1013
+ private readonly visibilityChangeHandler;
1014
+ /**
1015
+ * Whether the service has been started
1016
+ */
1017
+ private get started();
1018
+ /**
1019
+ * Whether we are currently tracking iframe activity (iframe had focus on last poll)
1020
+ */
1021
+ private get isTrackingIframeActivity();
1022
+ /**
1023
+ * Polls document.activeElement to detect iframe focus changes.
1024
+ * When iframe gains focus: emit immediately and start activity interval.
1025
+ * When iframe loses focus: stop activity interval.
1026
+ */
1027
+ private checkActiveElement;
1028
+ /**
1029
+ * Handles visibility change events to pause/resume polling when tab visibility changes.
1030
+ */
1031
+ private handleVisibilityChange;
1032
+ /**
1033
+ * Starts polling for active element changes.
1034
+ */
1035
+ private startPolling;
1036
+ /**
1037
+ * Stops polling for active element changes.
1038
+ */
1039
+ private stopPolling;
1040
+ /**
1041
+ * Starts the activity emission interval.
1042
+ */
1043
+ private startActivityInterval;
1044
+ /**
1045
+ * Stops the activity emission interval.
1046
+ */
1047
+ private stopActivityInterval;
1048
+ /**
1049
+ * Starts tracking nested iframes within the document.
1050
+ * @param config Configuration for the tracker
1051
+ */
1052
+ start(config: IframeActivityTrackerConfig): void;
1053
+ /**
1054
+ * Stops tracking nested iframes and cleans up resources.
1055
+ */
1056
+ stop(): void;
1057
+ static ɵfac: i0.ɵɵFactoryDeclaration<IframeActivityTrackerService, never>;
1058
+ static ɵprov: i0.ɵɵInjectableDeclaration<IframeActivityTrackerService>;
734
1059
  }
735
1060
 
736
- export { ApplyTheme, ConnectDirective, ConsumerManagerService, ERROR_MESSAGE_TYPE, HostInfoPipe, KNOWN_MESSAGES, MFE_HOST_APPLICATION_ID_PARAM, MFE_HOST_URL_PARAM, MFE_MODULE_APPLICATION_ID_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, hostQueryParams, isEmbedded, isErrorMessage, persistHostInfo, provideConnection, registerConsumer, registerProducer, sendError };
737
- export type { BasicMessageConsumer, ConnectionConfigOptions, ErrorContent, ErrorMessage, ErrorMessageV1_0, ErrorReason, MFEHostInformation, MessageCallback, MessageConsumer, MessageProducer, MessageVersions, RestoreRouteOptions, RoutingServiceOptions, StyleHelperOptions };
1061
+ /**
1062
+ * A constant array of known message types and their versions.
1063
+ */
1064
+ declare const KNOWN_MESSAGES: [{
1065
+ readonly type: "error";
1066
+ readonly version: "1.0";
1067
+ }];
1068
+ /**
1069
+ * Returns the default options for starting a client endpoint peer connection.
1070
+ * As `origin`, it will take the hostURL from {@link getHostInfo} and the `window` will be the parent window.
1071
+ */
1072
+ declare function getDefaultClientEndpointStartOptions(): PeerConnectionOptions;
1073
+ /**
1074
+ * Return `true` if embedded inside an iframe, `false` otherwise
1075
+ * @param windowParam - A {@link window} object with information about the current window of the document. Defaults to global {@link window}.
1076
+ */
1077
+ declare function isEmbedded(windowParam?: Window): boolean;
1078
+
1079
+ export { ACTIVITY_EVENTS, ActivityConsumerService, ActivityProducerService, ApplyTheme, ConnectDirective, ConsumerManagerService, DEFAULT_ACTIVITY_PRODUCER_CONFIG, ERROR_MESSAGE_TYPE, HIGH_FREQUENCY_EVENTS, HistoryConsumerService, HostInfoPipe, IFRAME_INTERACTION_EVENT, IframeActivityTrackerService, KNOWN_MESSAGES, MFE_HOST_APPLICATION_ID_PARAM, MFE_HOST_URL_PARAM, MFE_MODULE_APPLICATION_ID_PARAM, NavigationConsumerService, ProducerManagerService, ResizeConsumerService, ResizeService, RestoreRoute, RouteMemorizeDirective, RouteMemorizeService, RoutingService, ScalableDirective, THEME_QUERY_PARAM_NAME, THEME_URL_SUFFIX, ThemeConsumerService, ThemeProducerService, VISIBILITY_CHANGE_EVENT, applyInitialTheme, applyTheme, downloadApplicationThemeCss, getAvailableConsumers, getDefaultClientEndpointStartOptions, getHostInfo, getStyle, hostQueryParams, isEmbedded, isErrorMessage, isUserActivityMessage, persistHostInfo, provideConnection, provideHistoryOverrides, registerConsumer, registerProducer, sendError };
1080
+ export type { ActivityInfo, ActivityProducerConfig, BasicMessageConsumer, ConnectionConfigOptions, ErrorContent, ErrorMessage, ErrorMessageV1_0, ErrorReason, IframeActivityTrackerConfig, MFEHostInformation, MessageCallback, MessageConsumer, MessageProducer, MessageVersions, RestoreRouteOptions, RoutingServiceOptions, StyleHelperOptions };
738
1081
  //# sourceMappingURL=index.d.ts.map