@onecx/accelerator 8.0.0-rc.8 → 8.0.0

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.
Files changed (42) hide show
  1. package/README.md +0 -1
  2. package/dist/index.cjs +96 -77
  3. package/dist/index.mjs +96 -77
  4. package/package.json +1 -6
  5. package/src/index.d.ts +1 -0
  6. package/src/index.js +1 -0
  7. package/src/index.js.map +1 -1
  8. package/src/lib/declarations.d.ts +40 -29
  9. package/src/lib/declarations.js +6 -8
  10. package/src/lib/declarations.js.map +1 -1
  11. package/src/lib/topic/message.d.ts +0 -5
  12. package/src/lib/topic/message.js +4 -3
  13. package/src/lib/topic/message.js.map +1 -1
  14. package/src/lib/topic/topic-publisher.js +11 -8
  15. package/src/lib/topic/topic-publisher.js.map +1 -1
  16. package/src/lib/topic/topic.d.ts +0 -1
  17. package/src/lib/topic/topic.js +18 -21
  18. package/src/lib/topic/topic.js.map +1 -1
  19. package/src/lib/utils/gatherer.d.ts +0 -1
  20. package/src/lib/utils/gatherer.js +10 -10
  21. package/src/lib/utils/gatherer.js.map +1 -1
  22. package/src/lib/utils/get-normalized-browser-locales.utils.js +3 -2
  23. package/src/lib/utils/get-normalized-browser-locales.utils.js.map +1 -1
  24. package/src/lib/utils/get-onecx-shared-recommendations.d.ts +9 -0
  25. package/src/lib/utils/get-onecx-shared-recommendations.js +18 -0
  26. package/src/lib/utils/get-onecx-shared-recommendations.js.map +1 -0
  27. package/src/lib/utils/is-test.utils.js.map +1 -1
  28. package/src/lib/utils/logs.utils.d.ts +0 -1
  29. package/src/lib/utils/logs.utils.js +8 -10
  30. package/src/lib/utils/logs.utils.js.map +1 -1
  31. package/src/lib/utils/path.utils.js +9 -4
  32. package/src/lib/utils/path.utils.js.map +1 -1
  33. package/src/version.d.ts +1 -1
  34. package/src/version.js +1 -1
  35. package/src/version.js.map +1 -1
  36. package/migrations/index.d.ts +0 -1
  37. package/migrations/index.js +0 -2
  38. package/migrations/index.js.map +0 -1
  39. package/migrations/v6/migrate-onecx-to-v6.d.ts +0 -2
  40. package/migrations/v6/migrate-onecx-to-v6.js +0 -5
  41. package/migrations/v6/migrate-onecx-to-v6.js.map +0 -1
  42. package/migrations.json +0 -34
package/README.md CHANGED
@@ -11,7 +11,6 @@ npm install @onecx/accelerator
11
11
 
12
12
  ## Additional Commands
13
13
  - `npx nx run accelerator:build` - Builds the library and outputs the result to the `dist` folder.
14
- - `npx nx run accelerator:build-migrations` - Builds the migration files for the library.
15
14
  - `npx nx run accelerator:test` - Runs the unit tests for the library.
16
15
  - `npx nx run accelerator:lint` - Lints the library's codebase.
17
16
  - `npx nx run accelerator:release` - Releases a new version of the library to npm, following semantic versioning guidelines.
package/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  ensureProperty: () => ensureProperty,
41
41
  getLocation: () => getLocation,
42
42
  getNormalizedBrowserLocales: () => getNormalizedBrowserLocales,
43
+ getOneCXSharedRecommendations: () => getOneCXSharedRecommendations,
43
44
  getUTCDateWithoutTimezoneIssues: () => getUTCDateWithoutTimezoneIssues,
44
45
  isTest: () => isTest,
45
46
  isValidDate: () => isValidDate,
@@ -51,25 +52,39 @@ module.exports = __toCommonJS(index_exports);
51
52
  var import_operators = require("rxjs/operators");
52
53
  var import_rxjs = require("rxjs");
53
54
 
55
+ // libs/accelerator/src/lib/utils/ensure-property.utils.ts
56
+ function ensureProperty(obj, path, initialValue) {
57
+ let current = obj;
58
+ for (let i = 0; i < path.length - 1; i++) {
59
+ const key = path[i];
60
+ if (current[key] == null || typeof current[key] !== "object") {
61
+ current[key] = {};
62
+ }
63
+ current = current[key];
64
+ }
65
+ const lastKey = path.at(-1);
66
+ if (lastKey === void 0) {
67
+ return obj;
68
+ }
69
+ current[lastKey] ??= initialValue;
70
+ return obj;
71
+ }
72
+
54
73
  // libs/accelerator/src/lib/declarations.ts
55
- window["@onecx/accelerator"] ??= {};
56
- window["@onecx/accelerator"].gatherer ??= {};
57
- window["@onecx/accelerator"].gatherer.promises ??= {};
58
- window["@onecx/accelerator"].topic ??= {};
59
- window["@onecx/accelerator"].topic.useBroadcastChannel ??= "V2";
60
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
61
- window["@onecx/accelerator"].topic.tabId ??= Math.ceil(globalThis.performance.now());
74
+ var gatherPromises = ensureProperty(globalThis, ["@onecx/accelerator", "gatherer", "promises"], {});
75
+ var topicUseBroadcastChannel = ensureProperty(gatherPromises, ["@onecx/accelerator", "topic", "useBroadcastChannel"], "V2");
76
+ var topicInitDate = ensureProperty(topicUseBroadcastChannel, ["@onecx/accelerator", "topic", "initDate"], Date.now());
77
+ var topicTabId = ensureProperty(topicInitDate, ["@onecx/accelerator", "topic", "tabId"], Math.ceil(globalThis.performance?.now?.() ?? 0));
62
78
 
63
79
  // libs/accelerator/src/lib/utils/logs.utils.ts
64
80
  function isStatsEnabled() {
65
- return window["@onecx/accelerator"]?.topic?.statsEnabled === true;
81
+ const g2 = ensureProperty(topicTabId, ["@onecx/accelerator", "topic", "statsEnabled"], false);
82
+ return g2["@onecx/accelerator"].topic.statsEnabled === true;
66
83
  }
67
84
  function increaseMessageCount(topicName, messageType) {
68
- window["@onecx/accelerator"].topic ??= {};
69
- window["@onecx/accelerator"].topic.stats ??= {};
70
- window["@onecx/accelerator"].topic.stats.messagesPublished ??= {};
85
+ const g2 = ensureProperty(topicTabId, ["@onecx/accelerator", "topic", "stats", "messagesPublished"], {});
71
86
  if (isStatsEnabled()) {
72
- const messageStats = window["@onecx/accelerator"].topic.stats.messagesPublished;
87
+ const messageStats = g2["@onecx/accelerator"].topic.stats.messagesPublished;
73
88
  if (!messageStats[topicName]) {
74
89
  messageStats[topicName] = {
75
90
  TopicNext: 0,
@@ -81,11 +96,9 @@ function increaseMessageCount(topicName, messageType) {
81
96
  }
82
97
  }
83
98
  function increaseInstanceCount(topicName) {
84
- window["@onecx/accelerator"].topic ??= {};
85
- window["@onecx/accelerator"].topic.stats ??= {};
86
- window["@onecx/accelerator"].topic.stats.instancesCreated ??= {};
99
+ const g2 = ensureProperty(globalThis, ["@onecx/accelerator", "topic", "stats", "instancesCreated"], {});
87
100
  if (isStatsEnabled()) {
88
- const instanceStats = window["@onecx/accelerator"].topic.stats.instancesCreated;
101
+ const instanceStats = g2["@onecx/accelerator"].topic.stats.instancesCreated;
89
102
  if (!instanceStats[topicName]) {
90
103
  instanceStats[topicName] = 0;
91
104
  }
@@ -94,13 +107,13 @@ function increaseInstanceCount(topicName) {
94
107
  }
95
108
 
96
109
  // libs/accelerator/src/lib/topic/message.ts
97
- window["onecxMessageId"] ??= 1;
110
+ var g = ensureProperty(globalThis, ["onecxMessageId"], 1);
98
111
  var Message = class {
99
112
  // id can be undefined while used via old implementation
100
113
  constructor(type) {
101
114
  this.type = type;
102
- this.timestamp = window.performance.now();
103
- this.id = window["onecxMessageId"]++;
115
+ this.timestamp = globalThis.performance?.now?.() ?? Date.now();
116
+ this.id = g.onecxMessageId++;
104
117
  }
105
118
  timestamp;
106
119
  id;
@@ -182,26 +195,28 @@ var TopicPublisher = class {
182
195
  if (this.publishBroadcastChannel && this.publishBroadcastChannelV2) {
183
196
  return;
184
197
  }
185
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
198
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
186
199
  if (typeof BroadcastChannel === "undefined") {
187
200
  this.baseLogger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic publisher");
188
- window["@onecx/accelerator"] ??= {};
189
- window["@onecx/accelerator"].topic ??= {};
190
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
201
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
191
202
  } else {
192
203
  this.publishBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
193
- this.publishBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${window["@onecx/accelerator"].topic.tabId}`);
204
+ this.publishBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${topicTabId["@onecx/accelerator"].topic.tabId}`);
194
205
  }
195
206
  }
196
207
  }
197
208
  sendMessage(message) {
198
209
  this.createBroadcastChannel();
199
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel === "V2") {
210
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
200
211
  this.publishBroadcastChannelV2?.postMessage(message);
201
- } else if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
212
+ } else if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
202
213
  this.publishBroadcastChannel?.postMessage(message);
203
214
  } else {
204
- window.postMessage(message, "*");
215
+ const postMessage = globalThis.postMessage;
216
+ if (typeof postMessage !== "function") {
217
+ throw new TypeError("postMessage is not available in this environment");
218
+ }
219
+ postMessage(message, "*");
205
220
  }
206
221
  }
207
222
  };
@@ -218,18 +233,13 @@ var Topic = class extends TopicPublisher {
218
233
  readBroadcastChannelV2;
219
234
  constructor(name, version, sendGetMessage = true) {
220
235
  super(name, version);
221
- window["@onecx/accelerator"] ??= {};
222
- window["@onecx/accelerator"].topic ??= {};
223
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
224
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
236
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
225
237
  if (typeof BroadcastChannel === "undefined") {
226
238
  this.logger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic");
227
- window["@onecx/accelerator"] ??= {};
228
- window["@onecx/accelerator"].topic ??= {};
229
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
239
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
230
240
  } else {
231
241
  this.readBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
232
- this.readBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${window["@onecx/accelerator"].topic.tabId}`);
242
+ this.readBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${topicTabId["@onecx/accelerator"].topic.tabId}`);
233
243
  }
234
244
  }
235
245
  if (isStatsEnabled()) {
@@ -238,11 +248,14 @@ var Topic = class extends TopicPublisher {
238
248
  this.isInitializedPromise = new Promise((resolve) => {
239
249
  this.resolveInitPromise = resolve;
240
250
  });
241
- window.addEventListener("message", this.windowEventListener);
251
+ const addEventListener = globalThis.addEventListener;
252
+ if (typeof addEventListener === "function") {
253
+ addEventListener("message", this.windowEventListener);
254
+ }
242
255
  this.readBroadcastChannel?.addEventListener("message", (m) => this.onBroadcastChannelMessage(m));
243
256
  this.readBroadcastChannelV2?.addEventListener("message", (m) => this.onBroadcastChannelMessageV2(m));
244
257
  if (sendGetMessage) {
245
- if (window["@onecx/accelerator"].topic.initDate && Date.now() - window["@onecx/accelerator"].topic.initDate < 2e3) {
258
+ if (topicTabId["@onecx/accelerator"].topic.initDate && Date.now() - topicTabId["@onecx/accelerator"].topic.initDate < 2e3) {
246
259
  setTimeout(() => {
247
260
  if (!this.isInit) {
248
261
  const message = new TopicMessage("TopicGet" /* TopicGet */, this.name, this.version);
@@ -301,7 +314,10 @@ var Topic = class extends TopicPublisher {
301
314
  return this.asObservable().toPromise();
302
315
  }
303
316
  destroy() {
304
- window.removeEventListener("message", this.windowEventListener, true);
317
+ const removeEventListener = globalThis.removeEventListener;
318
+ if (typeof removeEventListener === "function") {
319
+ removeEventListener("message", this.windowEventListener, true);
320
+ }
305
321
  this.readBroadcastChannel?.close();
306
322
  this.publishBroadcastChannel?.close();
307
323
  this.readBroadcastChannelV2?.close();
@@ -357,20 +373,16 @@ var Topic = class extends TopicPublisher {
357
373
  }
358
374
  }
359
375
  disableBroadcastChannel() {
360
- window["@onecx/accelerator"] ??= {};
361
- window["@onecx/accelerator"].topic ??= {};
362
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === true) {
376
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === true) {
363
377
  this.logger.info("Disabling BroadcastChannel for topic");
364
378
  }
365
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
379
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
366
380
  }
367
381
  disableBroadcastChannelV2() {
368
- window["@onecx/accelerator"] ??= {};
369
- window["@onecx/accelerator"].topic ??= {};
370
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
382
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
371
383
  this.logger.info("Disabling BroadcastChannel V2 for topic");
372
384
  }
373
- window["@onecx/accelerator"].topic.useBroadcastChannel = true;
385
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = true;
374
386
  }
375
387
  handleTopicResolveMessage(m) {
376
388
  const publishPromiseResolver = this.publishPromiseResolver[m.data.resolveId];
@@ -528,10 +540,15 @@ var SyncableTopic = class extends Topic {
528
540
 
529
541
  // libs/accelerator/src/lib/utils/path.utils.ts
530
542
  function getLocation() {
531
- const baseHref = document.getElementsByTagName("base")[0]?.href ?? window.location.origin + "/";
532
- const location = window.location;
533
- location.deploymentPath = baseHref.substring(window.location.origin.length);
534
- location.applicationPath = window.location.href.substring(baseHref.length - 1);
543
+ const doc = globalThis.document;
544
+ const loc = globalThis.location;
545
+ if (!doc || !loc) {
546
+ throw new Error("getLocation() is only available in browser environments");
547
+ }
548
+ const baseHref = doc.getElementsByTagName("base")[0]?.href ?? loc.origin + "/";
549
+ const location = loc;
550
+ location.deploymentPath = baseHref.substring(loc.origin.length);
551
+ location.applicationPath = loc.href.substring(baseHref.length - 1);
535
552
  return location;
536
553
  }
537
554
 
@@ -568,10 +585,11 @@ function normalizeLocales(locales) {
568
585
 
569
586
  // libs/accelerator/src/lib/utils/get-normalized-browser-locales.utils.ts
570
587
  function getNormalizedBrowserLocales() {
571
- if (typeof window === "undefined" || typeof window.navigator === "undefined") {
588
+ const navigator = globalThis.navigator;
589
+ if (!navigator) {
572
590
  return ["en"];
573
591
  }
574
- const langs = window.navigator.languages || [window.navigator.language];
592
+ const langs = navigator.languages || [navigator.language];
575
593
  return normalizeLocales(langs.filter(Boolean));
576
594
  }
577
595
 
@@ -589,14 +607,14 @@ var Gatherer = class _Gatherer {
589
607
  this.logger.debug(`Gatherer ${name}: ${version} created`);
590
608
  this.topic = new Topic(name, version, false);
591
609
  this.topicSub = this.topic.subscribe((m) => {
592
- if (!this.isOwnerOfRequest(m) && window["@onecx/accelerator"]?.gatherer?.promises) {
610
+ if (!this.isOwnerOfRequest(m) && topicTabId["@onecx/accelerator"].gatherer.promises) {
593
611
  this.logReceivedIfDebug(name, version, m);
594
- if (!window["@onecx/accelerator"].gatherer.promises[m.id]) {
612
+ if (!topicTabId["@onecx/accelerator"].gatherer.promises[m.id]) {
595
613
  this.logger.warn("Expected an array of promises to gather for id ", m.id, " but the id was not present");
596
614
  return;
597
615
  }
598
616
  let resolve;
599
- window["@onecx/accelerator"].gatherer.promises[m.id].push(
617
+ topicTabId["@onecx/accelerator"].gatherer.promises[m.id].push(
600
618
  new Promise((r) => {
601
619
  resolve = r;
602
620
  })
@@ -613,22 +631,22 @@ var Gatherer = class _Gatherer {
613
631
  this.topicSub?.unsubscribe();
614
632
  this.topic.destroy();
615
633
  for (const id of this.ownIds) {
616
- if (window["@onecx/accelerator"]?.gatherer?.promises?.[id]) {
617
- delete window["@onecx/accelerator"].gatherer.promises[id];
634
+ if (topicTabId["@onecx/accelerator"].gatherer.promises?.[id]) {
635
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
618
636
  }
619
637
  }
620
638
  }
621
639
  async gather(request) {
622
- if (!window["@onecx/accelerator"]?.gatherer?.promises) {
640
+ if (!topicTabId["@onecx/accelerator"].gatherer?.promises) {
623
641
  throw new Error("Gatherer is not initialized");
624
642
  }
625
643
  const id = _Gatherer.id++;
626
644
  this.ownIds.add(id);
627
- window["@onecx/accelerator"].gatherer.promises[id] = [];
645
+ topicTabId["@onecx/accelerator"].gatherer.promises[id] = [];
628
646
  const message = { id, request };
629
647
  await this.topic.publish(message);
630
- const promises = window["@onecx/accelerator"].gatherer.promises[id];
631
- delete window["@onecx/accelerator"].gatherer.promises[id];
648
+ const promises = topicTabId["@onecx/accelerator"].gatherer.promises[id];
649
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
632
650
  this.ownIds.delete(id);
633
651
  return Promise.all(promises).then((v) => {
634
652
  this.logger.debug("Finished gathering responses", v);
@@ -649,20 +667,21 @@ var Gatherer = class _Gatherer {
649
667
  }
650
668
  };
651
669
 
652
- // libs/accelerator/src/lib/utils/ensure-property.utils.ts
653
- function ensureProperty(obj, path, initialValue) {
654
- let current = obj;
655
- for (let i = 0; i < path.length - 1; i++) {
656
- const key = path[i];
657
- if (current[key] == null || typeof current[key] !== "object") {
658
- current[key] = {};
659
- }
660
- current = current[key];
661
- }
662
- const lastKey = path.at(-1);
663
- if (lastKey === void 0) {
664
- return obj;
665
- }
666
- current[lastKey] ??= initialValue;
667
- return obj;
670
+ // libs/accelerator/src/lib/utils/get-onecx-shared-recommendations.ts
671
+ var sharedLibraryPatterns = [
672
+ /^@angular.*$/,
673
+ /^@onecx.*$/,
674
+ /^rxjs.*$/,
675
+ /^primeng.*$/,
676
+ /^@ngx-translate.*$/,
677
+ /^@ngrx.*$/
678
+ ];
679
+ function getOneCXSharedRecommendations(libraryName, sharedConfig) {
680
+ if (!sharedLibraryPatterns.some((pattern) => pattern.test(libraryName))) {
681
+ return false;
682
+ }
683
+ sharedConfig.singleton = false;
684
+ sharedConfig.strictVersion = false;
685
+ sharedConfig.eager = false;
686
+ return sharedConfig;
668
687
  }
package/dist/index.mjs CHANGED
@@ -4,25 +4,39 @@ import {
4
4
  BehaviorSubject
5
5
  } from "rxjs";
6
6
 
7
+ // libs/accelerator/src/lib/utils/ensure-property.utils.ts
8
+ function ensureProperty(obj, path, initialValue) {
9
+ let current = obj;
10
+ for (let i = 0; i < path.length - 1; i++) {
11
+ const key = path[i];
12
+ if (current[key] == null || typeof current[key] !== "object") {
13
+ current[key] = {};
14
+ }
15
+ current = current[key];
16
+ }
17
+ const lastKey = path.at(-1);
18
+ if (lastKey === void 0) {
19
+ return obj;
20
+ }
21
+ current[lastKey] ??= initialValue;
22
+ return obj;
23
+ }
24
+
7
25
  // libs/accelerator/src/lib/declarations.ts
8
- window["@onecx/accelerator"] ??= {};
9
- window["@onecx/accelerator"].gatherer ??= {};
10
- window["@onecx/accelerator"].gatherer.promises ??= {};
11
- window["@onecx/accelerator"].topic ??= {};
12
- window["@onecx/accelerator"].topic.useBroadcastChannel ??= "V2";
13
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
14
- window["@onecx/accelerator"].topic.tabId ??= Math.ceil(globalThis.performance.now());
26
+ var gatherPromises = ensureProperty(globalThis, ["@onecx/accelerator", "gatherer", "promises"], {});
27
+ var topicUseBroadcastChannel = ensureProperty(gatherPromises, ["@onecx/accelerator", "topic", "useBroadcastChannel"], "V2");
28
+ var topicInitDate = ensureProperty(topicUseBroadcastChannel, ["@onecx/accelerator", "topic", "initDate"], Date.now());
29
+ var topicTabId = ensureProperty(topicInitDate, ["@onecx/accelerator", "topic", "tabId"], Math.ceil(globalThis.performance?.now?.() ?? 0));
15
30
 
16
31
  // libs/accelerator/src/lib/utils/logs.utils.ts
17
32
  function isStatsEnabled() {
18
- return window["@onecx/accelerator"]?.topic?.statsEnabled === true;
33
+ const g2 = ensureProperty(topicTabId, ["@onecx/accelerator", "topic", "statsEnabled"], false);
34
+ return g2["@onecx/accelerator"].topic.statsEnabled === true;
19
35
  }
20
36
  function increaseMessageCount(topicName, messageType) {
21
- window["@onecx/accelerator"].topic ??= {};
22
- window["@onecx/accelerator"].topic.stats ??= {};
23
- window["@onecx/accelerator"].topic.stats.messagesPublished ??= {};
37
+ const g2 = ensureProperty(topicTabId, ["@onecx/accelerator", "topic", "stats", "messagesPublished"], {});
24
38
  if (isStatsEnabled()) {
25
- const messageStats = window["@onecx/accelerator"].topic.stats.messagesPublished;
39
+ const messageStats = g2["@onecx/accelerator"].topic.stats.messagesPublished;
26
40
  if (!messageStats[topicName]) {
27
41
  messageStats[topicName] = {
28
42
  TopicNext: 0,
@@ -34,11 +48,9 @@ function increaseMessageCount(topicName, messageType) {
34
48
  }
35
49
  }
36
50
  function increaseInstanceCount(topicName) {
37
- window["@onecx/accelerator"].topic ??= {};
38
- window["@onecx/accelerator"].topic.stats ??= {};
39
- window["@onecx/accelerator"].topic.stats.instancesCreated ??= {};
51
+ const g2 = ensureProperty(globalThis, ["@onecx/accelerator", "topic", "stats", "instancesCreated"], {});
40
52
  if (isStatsEnabled()) {
41
- const instanceStats = window["@onecx/accelerator"].topic.stats.instancesCreated;
53
+ const instanceStats = g2["@onecx/accelerator"].topic.stats.instancesCreated;
42
54
  if (!instanceStats[topicName]) {
43
55
  instanceStats[topicName] = 0;
44
56
  }
@@ -47,13 +59,13 @@ function increaseInstanceCount(topicName) {
47
59
  }
48
60
 
49
61
  // libs/accelerator/src/lib/topic/message.ts
50
- window["onecxMessageId"] ??= 1;
62
+ var g = ensureProperty(globalThis, ["onecxMessageId"], 1);
51
63
  var Message = class {
52
64
  // id can be undefined while used via old implementation
53
65
  constructor(type) {
54
66
  this.type = type;
55
- this.timestamp = window.performance.now();
56
- this.id = window["onecxMessageId"]++;
67
+ this.timestamp = globalThis.performance?.now?.() ?? Date.now();
68
+ this.id = g.onecxMessageId++;
57
69
  }
58
70
  timestamp;
59
71
  id;
@@ -135,26 +147,28 @@ var TopicPublisher = class {
135
147
  if (this.publishBroadcastChannel && this.publishBroadcastChannelV2) {
136
148
  return;
137
149
  }
138
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
150
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
139
151
  if (typeof BroadcastChannel === "undefined") {
140
152
  this.baseLogger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic publisher");
141
- window["@onecx/accelerator"] ??= {};
142
- window["@onecx/accelerator"].topic ??= {};
143
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
153
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
144
154
  } else {
145
155
  this.publishBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
146
- this.publishBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${window["@onecx/accelerator"].topic.tabId}`);
156
+ this.publishBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${topicTabId["@onecx/accelerator"].topic.tabId}`);
147
157
  }
148
158
  }
149
159
  }
150
160
  sendMessage(message) {
151
161
  this.createBroadcastChannel();
152
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel === "V2") {
162
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
153
163
  this.publishBroadcastChannelV2?.postMessage(message);
154
- } else if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
164
+ } else if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
155
165
  this.publishBroadcastChannel?.postMessage(message);
156
166
  } else {
157
- window.postMessage(message, "*");
167
+ const postMessage = globalThis.postMessage;
168
+ if (typeof postMessage !== "function") {
169
+ throw new TypeError("postMessage is not available in this environment");
170
+ }
171
+ postMessage(message, "*");
158
172
  }
159
173
  }
160
174
  };
@@ -171,18 +185,13 @@ var Topic = class extends TopicPublisher {
171
185
  readBroadcastChannelV2;
172
186
  constructor(name, version, sendGetMessage = true) {
173
187
  super(name, version);
174
- window["@onecx/accelerator"] ??= {};
175
- window["@onecx/accelerator"].topic ??= {};
176
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
177
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
188
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
178
189
  if (typeof BroadcastChannel === "undefined") {
179
190
  this.logger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic");
180
- window["@onecx/accelerator"] ??= {};
181
- window["@onecx/accelerator"].topic ??= {};
182
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
191
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
183
192
  } else {
184
193
  this.readBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
185
- this.readBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${window["@onecx/accelerator"].topic.tabId}`);
194
+ this.readBroadcastChannelV2 = new BroadcastChannel(`TopicV2-${this.name}|${this.version}-${topicTabId["@onecx/accelerator"].topic.tabId}`);
186
195
  }
187
196
  }
188
197
  if (isStatsEnabled()) {
@@ -191,11 +200,14 @@ var Topic = class extends TopicPublisher {
191
200
  this.isInitializedPromise = new Promise((resolve) => {
192
201
  this.resolveInitPromise = resolve;
193
202
  });
194
- window.addEventListener("message", this.windowEventListener);
203
+ const addEventListener = globalThis.addEventListener;
204
+ if (typeof addEventListener === "function") {
205
+ addEventListener("message", this.windowEventListener);
206
+ }
195
207
  this.readBroadcastChannel?.addEventListener("message", (m) => this.onBroadcastChannelMessage(m));
196
208
  this.readBroadcastChannelV2?.addEventListener("message", (m) => this.onBroadcastChannelMessageV2(m));
197
209
  if (sendGetMessage) {
198
- if (window["@onecx/accelerator"].topic.initDate && Date.now() - window["@onecx/accelerator"].topic.initDate < 2e3) {
210
+ if (topicTabId["@onecx/accelerator"].topic.initDate && Date.now() - topicTabId["@onecx/accelerator"].topic.initDate < 2e3) {
199
211
  setTimeout(() => {
200
212
  if (!this.isInit) {
201
213
  const message = new TopicMessage("TopicGet" /* TopicGet */, this.name, this.version);
@@ -254,7 +266,10 @@ var Topic = class extends TopicPublisher {
254
266
  return this.asObservable().toPromise();
255
267
  }
256
268
  destroy() {
257
- window.removeEventListener("message", this.windowEventListener, true);
269
+ const removeEventListener = globalThis.removeEventListener;
270
+ if (typeof removeEventListener === "function") {
271
+ removeEventListener("message", this.windowEventListener, true);
272
+ }
258
273
  this.readBroadcastChannel?.close();
259
274
  this.publishBroadcastChannel?.close();
260
275
  this.readBroadcastChannelV2?.close();
@@ -310,20 +325,16 @@ var Topic = class extends TopicPublisher {
310
325
  }
311
326
  }
312
327
  disableBroadcastChannel() {
313
- window["@onecx/accelerator"] ??= {};
314
- window["@onecx/accelerator"].topic ??= {};
315
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === true) {
328
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === true) {
316
329
  this.logger.info("Disabling BroadcastChannel for topic");
317
330
  }
318
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
331
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
319
332
  }
320
333
  disableBroadcastChannelV2() {
321
- window["@onecx/accelerator"] ??= {};
322
- window["@onecx/accelerator"].topic ??= {};
323
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
334
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
324
335
  this.logger.info("Disabling BroadcastChannel V2 for topic");
325
336
  }
326
- window["@onecx/accelerator"].topic.useBroadcastChannel = true;
337
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = true;
327
338
  }
328
339
  handleTopicResolveMessage(m) {
329
340
  const publishPromiseResolver = this.publishPromiseResolver[m.data.resolveId];
@@ -481,10 +492,15 @@ var SyncableTopic = class extends Topic {
481
492
 
482
493
  // libs/accelerator/src/lib/utils/path.utils.ts
483
494
  function getLocation() {
484
- const baseHref = document.getElementsByTagName("base")[0]?.href ?? window.location.origin + "/";
485
- const location = window.location;
486
- location.deploymentPath = baseHref.substring(window.location.origin.length);
487
- location.applicationPath = window.location.href.substring(baseHref.length - 1);
495
+ const doc = globalThis.document;
496
+ const loc = globalThis.location;
497
+ if (!doc || !loc) {
498
+ throw new Error("getLocation() is only available in browser environments");
499
+ }
500
+ const baseHref = doc.getElementsByTagName("base")[0]?.href ?? loc.origin + "/";
501
+ const location = loc;
502
+ location.deploymentPath = baseHref.substring(loc.origin.length);
503
+ location.applicationPath = loc.href.substring(baseHref.length - 1);
488
504
  return location;
489
505
  }
490
506
 
@@ -521,10 +537,11 @@ function normalizeLocales(locales) {
521
537
 
522
538
  // libs/accelerator/src/lib/utils/get-normalized-browser-locales.utils.ts
523
539
  function getNormalizedBrowserLocales() {
524
- if (typeof window === "undefined" || typeof window.navigator === "undefined") {
540
+ const navigator = globalThis.navigator;
541
+ if (!navigator) {
525
542
  return ["en"];
526
543
  }
527
- const langs = window.navigator.languages || [window.navigator.language];
544
+ const langs = navigator.languages || [navigator.language];
528
545
  return normalizeLocales(langs.filter(Boolean));
529
546
  }
530
547
 
@@ -542,14 +559,14 @@ var Gatherer = class _Gatherer {
542
559
  this.logger.debug(`Gatherer ${name}: ${version} created`);
543
560
  this.topic = new Topic(name, version, false);
544
561
  this.topicSub = this.topic.subscribe((m) => {
545
- if (!this.isOwnerOfRequest(m) && window["@onecx/accelerator"]?.gatherer?.promises) {
562
+ if (!this.isOwnerOfRequest(m) && topicTabId["@onecx/accelerator"].gatherer.promises) {
546
563
  this.logReceivedIfDebug(name, version, m);
547
- if (!window["@onecx/accelerator"].gatherer.promises[m.id]) {
564
+ if (!topicTabId["@onecx/accelerator"].gatherer.promises[m.id]) {
548
565
  this.logger.warn("Expected an array of promises to gather for id ", m.id, " but the id was not present");
549
566
  return;
550
567
  }
551
568
  let resolve;
552
- window["@onecx/accelerator"].gatherer.promises[m.id].push(
569
+ topicTabId["@onecx/accelerator"].gatherer.promises[m.id].push(
553
570
  new Promise((r) => {
554
571
  resolve = r;
555
572
  })
@@ -566,22 +583,22 @@ var Gatherer = class _Gatherer {
566
583
  this.topicSub?.unsubscribe();
567
584
  this.topic.destroy();
568
585
  for (const id of this.ownIds) {
569
- if (window["@onecx/accelerator"]?.gatherer?.promises?.[id]) {
570
- delete window["@onecx/accelerator"].gatherer.promises[id];
586
+ if (topicTabId["@onecx/accelerator"].gatherer.promises?.[id]) {
587
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
571
588
  }
572
589
  }
573
590
  }
574
591
  async gather(request) {
575
- if (!window["@onecx/accelerator"]?.gatherer?.promises) {
592
+ if (!topicTabId["@onecx/accelerator"].gatherer?.promises) {
576
593
  throw new Error("Gatherer is not initialized");
577
594
  }
578
595
  const id = _Gatherer.id++;
579
596
  this.ownIds.add(id);
580
- window["@onecx/accelerator"].gatherer.promises[id] = [];
597
+ topicTabId["@onecx/accelerator"].gatherer.promises[id] = [];
581
598
  const message = { id, request };
582
599
  await this.topic.publish(message);
583
- const promises = window["@onecx/accelerator"].gatherer.promises[id];
584
- delete window["@onecx/accelerator"].gatherer.promises[id];
600
+ const promises = topicTabId["@onecx/accelerator"].gatherer.promises[id];
601
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
585
602
  this.ownIds.delete(id);
586
603
  return Promise.all(promises).then((v) => {
587
604
  this.logger.debug("Finished gathering responses", v);
@@ -602,22 +619,23 @@ var Gatherer = class _Gatherer {
602
619
  }
603
620
  };
604
621
 
605
- // libs/accelerator/src/lib/utils/ensure-property.utils.ts
606
- function ensureProperty(obj, path, initialValue) {
607
- let current = obj;
608
- for (let i = 0; i < path.length - 1; i++) {
609
- const key = path[i];
610
- if (current[key] == null || typeof current[key] !== "object") {
611
- current[key] = {};
612
- }
613
- current = current[key];
614
- }
615
- const lastKey = path.at(-1);
616
- if (lastKey === void 0) {
617
- return obj;
618
- }
619
- current[lastKey] ??= initialValue;
620
- return obj;
622
+ // libs/accelerator/src/lib/utils/get-onecx-shared-recommendations.ts
623
+ var sharedLibraryPatterns = [
624
+ /^@angular.*$/,
625
+ /^@onecx.*$/,
626
+ /^rxjs.*$/,
627
+ /^primeng.*$/,
628
+ /^@ngx-translate.*$/,
629
+ /^@ngrx.*$/
630
+ ];
631
+ function getOneCXSharedRecommendations(libraryName, sharedConfig) {
632
+ if (!sharedLibraryPatterns.some((pattern) => pattern.test(libraryName))) {
633
+ return false;
634
+ }
635
+ sharedConfig.singleton = false;
636
+ sharedConfig.strictVersion = false;
637
+ sharedConfig.eager = false;
638
+ return sharedConfig;
621
639
  }
622
640
  export {
623
641
  BroadcastChannelMock,
@@ -630,6 +648,7 @@ export {
630
648
  ensureProperty,
631
649
  getLocation,
632
650
  getNormalizedBrowserLocales,
651
+ getOneCXSharedRecommendations,
633
652
  getUTCDateWithoutTimezoneIssues,
634
653
  isTest,
635
654
  isValidDate,