@yuuvis/client-core 2.3.1 → 2.3.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.
@@ -5,11 +5,11 @@ import { HttpErrorResponse, HttpClient, HttpHeaders, HttpParams, HttpRequest, Ht
5
5
  import * as i0 from '@angular/core';
6
6
  import { inject, Injectable, InjectionToken, Inject, Directive, Pipe, importProvidersFrom, provideAppInitializer } from '@angular/core';
7
7
  import { tap, finalize, shareReplay, catchError, map, switchMap, first, filter, scan, delay } from 'rxjs/operators';
8
- import { EMPTY, of, forkJoin, Observable, ReplaySubject, Subject, BehaviorSubject, tap as tap$1, map as map$1, merge, fromEvent, filter as filter$1, debounceTime, throwError, isObservable, switchMap as switchMap$1 } from 'rxjs';
8
+ import { EMPTY, of, forkJoin, Observable, ReplaySubject, Subject, fromEvent, BehaviorSubject, tap as tap$1, map as map$1, merge, filter as filter$1, debounceTime, throwError, isObservable, switchMap as switchMap$1 } from 'rxjs';
9
9
  import { StorageMap } from '@ngx-pwa/local-storage';
10
+ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
10
11
  import { __decorate, __param, __metadata } from 'tslib';
11
12
  import { coerceBooleanProperty } from '@angular/cdk/coercion';
12
- import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
13
13
  import { DeviceDetectorService } from 'ngx-device-detector';
14
14
  import { DOCUMENT, DecimalPipe, PercentPipe, CurrencyPipe, registerLocaleData } from '@angular/common';
15
15
  import { MatTabGroup } from '@angular/material/tabs';
@@ -2191,21 +2191,71 @@ var Direction;
2191
2191
  Direction["RTL"] = "rtl";
2192
2192
  })(Direction || (Direction = {}));
2193
2193
 
2194
+ /**
2195
+ * Mandatory Custom event prefix for all custom YUV events
2196
+ */
2197
+ const CUSTOM_EVENT_PREFIX = 'yuv.';
2198
+
2194
2199
  /**
2195
2200
  * Service for providing triggered events
2196
2201
  */
2197
2202
  class EventService {
2203
+ #eventSource;
2204
+ #allowedOrigins;
2198
2205
  constructor() {
2199
2206
  this.#eventSource = new Subject();
2200
2207
  this.event$ = this.#eventSource.asObservable();
2208
+ this.#allowedOrigins = [window.location.origin];
2209
+ this.#listenToWindowEvents();
2210
+ }
2211
+ #isYuvMessage(data) {
2212
+ return data && typeof data.type === 'string' && data.type.startsWith(CUSTOM_EVENT_PREFIX);
2213
+ }
2214
+ #isValidExternalMessage(event) {
2215
+ // Skip Angular DevTools and other framework messages
2216
+ if (event.data?.source?.startsWith('angular-devtools'))
2217
+ return false;
2218
+ if (event.data?.source?.startsWith('react-devtools'))
2219
+ return false;
2220
+ if (event.data?.source?.startsWith('webpack'))
2221
+ return false;
2222
+ if (event.data?.type?.startsWith('webpackOk'))
2223
+ return false;
2224
+ // Accept messages from trusted origins
2225
+ const trustedOrigins = [window.location.origin];
2226
+ const isFromTrustedOrigin = trustedOrigins.includes(event.origin);
2227
+ const hasValidStructure = event.data && (event.data.type || event.data.eventType) && typeof event.data === 'object';
2228
+ return isFromTrustedOrigin && hasValidStructure && this.#isYuvMessage(event.data);
2229
+ }
2230
+ #listenToWindowEvents() {
2231
+ fromEvent(window, 'message')
2232
+ .pipe(
2233
+ // TODO: Prevent message spam (necessary?)
2234
+ // debounceTime(500),
2235
+ filter((event) => this.#isValidExternalMessage(event)), takeUntilDestroyed())
2236
+ .subscribe((event) => this.trigger(event.data.type, event.data.data));
2237
+ }
2238
+ /**
2239
+ * Triggers a postMessage event that will be sent to the yuuvis global event Trigger
2240
+ * @param type Type/key of the event
2241
+ * @param data Data to be sent along with the event
2242
+ */
2243
+ triggerPostMessageEvent(type, data) {
2244
+ const targetOrigin = window.location.origin;
2245
+ const payload = {
2246
+ type,
2247
+ data,
2248
+ timestamp: Date.now()
2249
+ };
2250
+ window.postMessage(payload, targetOrigin);
2201
2251
  }
2202
- #eventSource;
2203
2252
  /**
2204
2253
  * Trigger an global event
2205
2254
  * @param type Type/key of the event
2206
2255
  * @param data Data to be send along with the event
2207
2256
  */
2208
2257
  trigger(type, data) {
2258
+ console.log(`EventService: trigger event ${type}`, data);
2209
2259
  this.#eventSource.next({ type, data });
2210
2260
  }
2211
2261
  /**
@@ -2223,7 +2273,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
2223
2273
  args: [{
2224
2274
  providedIn: 'root'
2225
2275
  }]
2226
- }] });
2276
+ }], ctorParameters: () => [] });
2227
2277
 
2228
2278
  /**
2229
2279
  * Events emitted by parts of the application
@@ -5425,5 +5475,5 @@ const provideYuvClientCore = (options = { translations: [] }) => {
5425
5475
  * Generated bundle index. Do not edit.
5426
5476
  */
5427
5477
 
5428
- export { AFO_STATE, AdministrationRoles, ApiBase, AppCacheService, AuditField, AuditService, AuthService, BackendService, BaseObjectTypeField, BpmService, CORE_CONFIG, CUSTOM_CONFIG, CatalogService, Classification, ClassificationPrefix, ClientDefaultsObjectTypeField, ClipboardService, ColumnConfigSkipFields, ConfigService, ConnectionService, ContentStreamAllowed, ContentStreamField, CoreConfig, DeviceScreenOrientation, DeviceService, DialogCloseGuard, Direction, DmsObject, DmsService, EventService, FileSizePipe, IdmService, InternalFieldType, KeysPipe, LocaleCurrencyPipe, LocaleDatePipe, LocaleDecimalPipe, LocaleNumberPipe, LocalePercentPipe, Logger, LoginStateName, NativeNotificationService, NotificationService, ObjectConfigService, ObjectFormControl, ObjectFormControlWrapper, ObjectFormGroup, ObjectTag, ObjectTypeClassification, ObjectTypePropertyClassification, Operator, OperatorLabel, ParentField, PendingChangesGuard, PendingChangesService, PredictionService, ProcessAction, RelationshipTypeField, RetentionField, RetentionService, SafeHtmlPipe, SafeUrlPipe, SearchService, SearchUtils, SecondaryObjectTypeClassification, SessionStorageService, Situation, Sort, SystemResult, SystemSOT, SystemService, SystemType, TENANT_HEADER, TabGuardDirective, ToastService, UploadService, UserRoles, UserService, UserStorageService, Utils, YUV_USER, YuvError, YuvEventType, YuvUser, init_moduleFnc, provideUser, provideYuvClientCore };
5478
+ export { AFO_STATE, AdministrationRoles, ApiBase, AppCacheService, AuditField, AuditService, AuthService, BackendService, BaseObjectTypeField, BpmService, CORE_CONFIG, CUSTOM_CONFIG, CUSTOM_EVENT_PREFIX, CatalogService, Classification, ClassificationPrefix, ClientDefaultsObjectTypeField, ClipboardService, ColumnConfigSkipFields, ConfigService, ConnectionService, ContentStreamAllowed, ContentStreamField, CoreConfig, DeviceScreenOrientation, DeviceService, DialogCloseGuard, Direction, DmsObject, DmsService, EventService, FileSizePipe, IdmService, InternalFieldType, KeysPipe, LocaleCurrencyPipe, LocaleDatePipe, LocaleDecimalPipe, LocaleNumberPipe, LocalePercentPipe, Logger, LoginStateName, NativeNotificationService, NotificationService, ObjectConfigService, ObjectFormControl, ObjectFormControlWrapper, ObjectFormGroup, ObjectTag, ObjectTypeClassification, ObjectTypePropertyClassification, Operator, OperatorLabel, ParentField, PendingChangesGuard, PendingChangesService, PredictionService, ProcessAction, RelationshipTypeField, RetentionField, RetentionService, SafeHtmlPipe, SafeUrlPipe, SearchService, SearchUtils, SecondaryObjectTypeClassification, SessionStorageService, Situation, Sort, SystemResult, SystemSOT, SystemService, SystemType, TENANT_HEADER, TabGuardDirective, ToastService, UploadService, UserRoles, UserService, UserStorageService, Utils, YUV_USER, YuvError, YuvEventType, YuvUser, init_moduleFnc, provideUser, provideYuvClientCore };
5429
5479
  //# sourceMappingURL=yuuvis-client-core.mjs.map