@onecx/accelerator 8.0.0-rc.9 → 9.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +0 -1
  2. package/dist/index.cjs +86 -80
  3. package/dist/index.mjs +86 -80
  4. package/package.json +1 -7
  5. package/src/lib/declarations.d.ts +40 -29
  6. package/src/lib/declarations.js +6 -8
  7. package/src/lib/declarations.js.map +1 -1
  8. package/src/lib/topic/message.d.ts +0 -5
  9. package/src/lib/topic/message.js +4 -3
  10. package/src/lib/topic/message.js.map +1 -1
  11. package/src/lib/topic/topic-publisher.js +11 -8
  12. package/src/lib/topic/topic-publisher.js.map +1 -1
  13. package/src/lib/topic/topic.d.ts +0 -1
  14. package/src/lib/topic/topic.js +18 -21
  15. package/src/lib/topic/topic.js.map +1 -1
  16. package/src/lib/utils/gatherer.d.ts +0 -1
  17. package/src/lib/utils/gatherer.js +10 -10
  18. package/src/lib/utils/gatherer.js.map +1 -1
  19. package/src/lib/utils/get-normalized-browser-locales.utils.js +3 -2
  20. package/src/lib/utils/get-normalized-browser-locales.utils.js.map +1 -1
  21. package/src/lib/utils/get-onecx-shared-recommendations.d.ts +8 -1
  22. package/src/lib/utils/get-onecx-shared-recommendations.js +8 -1
  23. package/src/lib/utils/get-onecx-shared-recommendations.js.map +1 -1
  24. package/src/lib/utils/is-test.utils.js.map +1 -1
  25. package/src/lib/utils/logs.utils.d.ts +0 -1
  26. package/src/lib/utils/logs.utils.js +8 -10
  27. package/src/lib/utils/logs.utils.js.map +1 -1
  28. package/src/lib/utils/path.utils.js +9 -4
  29. package/src/lib/utils/path.utils.js.map +1 -1
  30. package/src/version.d.ts +1 -1
  31. package/src/version.js +1 -1
  32. package/migrations/index.d.ts +0 -1
  33. package/migrations/index.js +0 -2
  34. package/migrations/index.js.map +0 -1
  35. package/migrations/v6/migrate-onecx-to-v6.d.ts +0 -2
  36. package/migrations/v6/migrate-onecx-to-v6.js +0 -5
  37. package/migrations/v6/migrate-onecx-to-v6.js.map +0 -1
  38. 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
@@ -52,25 +52,39 @@ module.exports = __toCommonJS(index_exports);
52
52
  var import_operators = require("rxjs/operators");
53
53
  var import_rxjs = require("rxjs");
54
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
+
55
73
  // libs/accelerator/src/lib/declarations.ts
56
- window["@onecx/accelerator"] ??= {};
57
- window["@onecx/accelerator"].gatherer ??= {};
58
- window["@onecx/accelerator"].gatherer.promises ??= {};
59
- window["@onecx/accelerator"].topic ??= {};
60
- window["@onecx/accelerator"].topic.useBroadcastChannel ??= "V2";
61
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
62
- 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));
63
78
 
64
79
  // libs/accelerator/src/lib/utils/logs.utils.ts
65
80
  function isStatsEnabled() {
66
- 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;
67
83
  }
68
84
  function increaseMessageCount(topicName, messageType) {
69
- window["@onecx/accelerator"].topic ??= {};
70
- window["@onecx/accelerator"].topic.stats ??= {};
71
- window["@onecx/accelerator"].topic.stats.messagesPublished ??= {};
85
+ const g2 = ensureProperty(topicTabId, ["@onecx/accelerator", "topic", "stats", "messagesPublished"], {});
72
86
  if (isStatsEnabled()) {
73
- const messageStats = window["@onecx/accelerator"].topic.stats.messagesPublished;
87
+ const messageStats = g2["@onecx/accelerator"].topic.stats.messagesPublished;
74
88
  if (!messageStats[topicName]) {
75
89
  messageStats[topicName] = {
76
90
  TopicNext: 0,
@@ -82,11 +96,9 @@ function increaseMessageCount(topicName, messageType) {
82
96
  }
83
97
  }
84
98
  function increaseInstanceCount(topicName) {
85
- window["@onecx/accelerator"].topic ??= {};
86
- window["@onecx/accelerator"].topic.stats ??= {};
87
- window["@onecx/accelerator"].topic.stats.instancesCreated ??= {};
99
+ const g2 = ensureProperty(globalThis, ["@onecx/accelerator", "topic", "stats", "instancesCreated"], {});
88
100
  if (isStatsEnabled()) {
89
- const instanceStats = window["@onecx/accelerator"].topic.stats.instancesCreated;
101
+ const instanceStats = g2["@onecx/accelerator"].topic.stats.instancesCreated;
90
102
  if (!instanceStats[topicName]) {
91
103
  instanceStats[topicName] = 0;
92
104
  }
@@ -95,13 +107,13 @@ function increaseInstanceCount(topicName) {
95
107
  }
96
108
 
97
109
  // libs/accelerator/src/lib/topic/message.ts
98
- window["onecxMessageId"] ??= 1;
110
+ var g = ensureProperty(globalThis, ["onecxMessageId"], 1);
99
111
  var Message = class {
100
112
  // id can be undefined while used via old implementation
101
113
  constructor(type) {
102
114
  this.type = type;
103
- this.timestamp = window.performance.now();
104
- this.id = window["onecxMessageId"]++;
115
+ this.timestamp = globalThis.performance?.now?.() ?? Date.now();
116
+ this.id = g.onecxMessageId++;
105
117
  }
106
118
  timestamp;
107
119
  id;
@@ -183,26 +195,28 @@ var TopicPublisher = class {
183
195
  if (this.publishBroadcastChannel && this.publishBroadcastChannelV2) {
184
196
  return;
185
197
  }
186
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
198
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
187
199
  if (typeof BroadcastChannel === "undefined") {
188
200
  this.baseLogger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic publisher");
189
- window["@onecx/accelerator"] ??= {};
190
- window["@onecx/accelerator"].topic ??= {};
191
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
201
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
192
202
  } else {
193
203
  this.publishBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
194
- 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}`);
195
205
  }
196
206
  }
197
207
  }
198
208
  sendMessage(message) {
199
209
  this.createBroadcastChannel();
200
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel === "V2") {
210
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
201
211
  this.publishBroadcastChannelV2?.postMessage(message);
202
- } else if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
212
+ } else if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
203
213
  this.publishBroadcastChannel?.postMessage(message);
204
214
  } else {
205
- 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, "*");
206
220
  }
207
221
  }
208
222
  };
@@ -219,18 +233,13 @@ var Topic = class extends TopicPublisher {
219
233
  readBroadcastChannelV2;
220
234
  constructor(name, version, sendGetMessage = true) {
221
235
  super(name, version);
222
- window["@onecx/accelerator"] ??= {};
223
- window["@onecx/accelerator"].topic ??= {};
224
- window["@onecx/accelerator"].topic.initDate ??= Date.now();
225
- if (window["@onecx/accelerator"]?.topic?.useBroadcastChannel) {
236
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel) {
226
237
  if (typeof BroadcastChannel === "undefined") {
227
238
  this.logger.info("BroadcastChannel not supported. Disabling BroadcastChannel for topic");
228
- window["@onecx/accelerator"] ??= {};
229
- window["@onecx/accelerator"].topic ??= {};
230
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
239
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
231
240
  } else {
232
241
  this.readBroadcastChannel = new BroadcastChannel(`Topic-${this.name}|${this.version}`);
233
- 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}`);
234
243
  }
235
244
  }
236
245
  if (isStatsEnabled()) {
@@ -239,11 +248,14 @@ var Topic = class extends TopicPublisher {
239
248
  this.isInitializedPromise = new Promise((resolve) => {
240
249
  this.resolveInitPromise = resolve;
241
250
  });
242
- window.addEventListener("message", this.windowEventListener);
251
+ const addEventListener = globalThis.addEventListener;
252
+ if (typeof addEventListener === "function") {
253
+ addEventListener("message", this.windowEventListener);
254
+ }
243
255
  this.readBroadcastChannel?.addEventListener("message", (m) => this.onBroadcastChannelMessage(m));
244
256
  this.readBroadcastChannelV2?.addEventListener("message", (m) => this.onBroadcastChannelMessageV2(m));
245
257
  if (sendGetMessage) {
246
- 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) {
247
259
  setTimeout(() => {
248
260
  if (!this.isInit) {
249
261
  const message = new TopicMessage("TopicGet" /* TopicGet */, this.name, this.version);
@@ -302,7 +314,10 @@ var Topic = class extends TopicPublisher {
302
314
  return this.asObservable().toPromise();
303
315
  }
304
316
  destroy() {
305
- window.removeEventListener("message", this.windowEventListener, true);
317
+ const removeEventListener = globalThis.removeEventListener;
318
+ if (typeof removeEventListener === "function") {
319
+ removeEventListener("message", this.windowEventListener, true);
320
+ }
306
321
  this.readBroadcastChannel?.close();
307
322
  this.publishBroadcastChannel?.close();
308
323
  this.readBroadcastChannelV2?.close();
@@ -358,20 +373,16 @@ var Topic = class extends TopicPublisher {
358
373
  }
359
374
  }
360
375
  disableBroadcastChannel() {
361
- window["@onecx/accelerator"] ??= {};
362
- window["@onecx/accelerator"].topic ??= {};
363
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === true) {
376
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === true) {
364
377
  this.logger.info("Disabling BroadcastChannel for topic");
365
378
  }
366
- window["@onecx/accelerator"].topic.useBroadcastChannel = false;
379
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = false;
367
380
  }
368
381
  disableBroadcastChannelV2() {
369
- window["@onecx/accelerator"] ??= {};
370
- window["@onecx/accelerator"].topic ??= {};
371
- if (window["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
382
+ if (topicTabId["@onecx/accelerator"].topic.useBroadcastChannel === "V2") {
372
383
  this.logger.info("Disabling BroadcastChannel V2 for topic");
373
384
  }
374
- window["@onecx/accelerator"].topic.useBroadcastChannel = true;
385
+ topicTabId["@onecx/accelerator"].topic.useBroadcastChannel = true;
375
386
  }
376
387
  handleTopicResolveMessage(m) {
377
388
  const publishPromiseResolver = this.publishPromiseResolver[m.data.resolveId];
@@ -529,10 +540,15 @@ var SyncableTopic = class extends Topic {
529
540
 
530
541
  // libs/accelerator/src/lib/utils/path.utils.ts
531
542
  function getLocation() {
532
- const baseHref = document.getElementsByTagName("base")[0]?.href ?? window.location.origin + "/";
533
- const location = window.location;
534
- location.deploymentPath = baseHref.substring(window.location.origin.length);
535
- 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);
536
552
  return location;
537
553
  }
538
554
 
@@ -569,10 +585,11 @@ function normalizeLocales(locales) {
569
585
 
570
586
  // libs/accelerator/src/lib/utils/get-normalized-browser-locales.utils.ts
571
587
  function getNormalizedBrowserLocales() {
572
- if (typeof window === "undefined" || typeof window.navigator === "undefined") {
588
+ const navigator = globalThis.navigator;
589
+ if (!navigator) {
573
590
  return ["en"];
574
591
  }
575
- const langs = window.navigator.languages || [window.navigator.language];
592
+ const langs = navigator.languages || [navigator.language];
576
593
  return normalizeLocales(langs.filter(Boolean));
577
594
  }
578
595
 
@@ -590,14 +607,14 @@ var Gatherer = class _Gatherer {
590
607
  this.logger.debug(`Gatherer ${name}: ${version} created`);
591
608
  this.topic = new Topic(name, version, false);
592
609
  this.topicSub = this.topic.subscribe((m) => {
593
- if (!this.isOwnerOfRequest(m) && window["@onecx/accelerator"]?.gatherer?.promises) {
610
+ if (!this.isOwnerOfRequest(m) && topicTabId["@onecx/accelerator"].gatherer.promises) {
594
611
  this.logReceivedIfDebug(name, version, m);
595
- if (!window["@onecx/accelerator"].gatherer.promises[m.id]) {
612
+ if (!topicTabId["@onecx/accelerator"].gatherer.promises[m.id]) {
596
613
  this.logger.warn("Expected an array of promises to gather for id ", m.id, " but the id was not present");
597
614
  return;
598
615
  }
599
616
  let resolve;
600
- window["@onecx/accelerator"].gatherer.promises[m.id].push(
617
+ topicTabId["@onecx/accelerator"].gatherer.promises[m.id].push(
601
618
  new Promise((r) => {
602
619
  resolve = r;
603
620
  })
@@ -614,22 +631,22 @@ var Gatherer = class _Gatherer {
614
631
  this.topicSub?.unsubscribe();
615
632
  this.topic.destroy();
616
633
  for (const id of this.ownIds) {
617
- if (window["@onecx/accelerator"]?.gatherer?.promises?.[id]) {
618
- delete window["@onecx/accelerator"].gatherer.promises[id];
634
+ if (topicTabId["@onecx/accelerator"].gatherer.promises?.[id]) {
635
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
619
636
  }
620
637
  }
621
638
  }
622
639
  async gather(request) {
623
- if (!window["@onecx/accelerator"]?.gatherer?.promises) {
640
+ if (!topicTabId["@onecx/accelerator"].gatherer?.promises) {
624
641
  throw new Error("Gatherer is not initialized");
625
642
  }
626
643
  const id = _Gatherer.id++;
627
644
  this.ownIds.add(id);
628
- window["@onecx/accelerator"].gatherer.promises[id] = [];
645
+ topicTabId["@onecx/accelerator"].gatherer.promises[id] = [];
629
646
  const message = { id, request };
630
647
  await this.topic.publish(message);
631
- const promises = window["@onecx/accelerator"].gatherer.promises[id];
632
- delete window["@onecx/accelerator"].gatherer.promises[id];
648
+ const promises = topicTabId["@onecx/accelerator"].gatherer.promises[id];
649
+ delete topicTabId["@onecx/accelerator"].gatherer.promises[id];
633
650
  this.ownIds.delete(id);
634
651
  return Promise.all(promises).then((v) => {
635
652
  this.logger.debug("Finished gathering responses", v);
@@ -650,26 +667,15 @@ var Gatherer = class _Gatherer {
650
667
  }
651
668
  };
652
669
 
653
- // libs/accelerator/src/lib/utils/ensure-property.utils.ts
654
- function ensureProperty(obj, path, initialValue) {
655
- let current = obj;
656
- for (let i = 0; i < path.length - 1; i++) {
657
- const key = path[i];
658
- if (current[key] == null || typeof current[key] !== "object") {
659
- current[key] = {};
660
- }
661
- current = current[key];
662
- }
663
- const lastKey = path.at(-1);
664
- if (lastKey === void 0) {
665
- return obj;
666
- }
667
- current[lastKey] ??= initialValue;
668
- return obj;
669
- }
670
-
671
670
  // libs/accelerator/src/lib/utils/get-onecx-shared-recommendations.ts
672
- var sharedLibraryPatterns = [/^@angular.*$/, /^@onecx.*$/, /^rxjs.*$/, /^primeng.*$/, /^@ngx-translate.*$/];
671
+ var sharedLibraryPatterns = [
672
+ /^@angular.*$/,
673
+ /^@onecx.*$/,
674
+ /^rxjs.*$/,
675
+ /^primeng.*$/,
676
+ /^@ngx-translate.*$/,
677
+ /^@ngrx.*$/
678
+ ];
673
679
  function getOneCXSharedRecommendations(libraryName, sharedConfig) {
674
680
  if (!sharedLibraryPatterns.some((pattern) => pattern.test(libraryName))) {
675
681
  return false;
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,26 +619,15 @@ 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;
621
- }
622
-
623
622
  // libs/accelerator/src/lib/utils/get-onecx-shared-recommendations.ts
624
- var sharedLibraryPatterns = [/^@angular.*$/, /^@onecx.*$/, /^rxjs.*$/, /^primeng.*$/, /^@ngx-translate.*$/];
623
+ var sharedLibraryPatterns = [
624
+ /^@angular.*$/,
625
+ /^@onecx.*$/,
626
+ /^rxjs.*$/,
627
+ /^primeng.*$/,
628
+ /^@ngx-translate.*$/,
629
+ /^@ngrx.*$/
630
+ ];
625
631
  function getOneCXSharedRecommendations(libraryName, sharedConfig) {
626
632
  if (!sharedLibraryPatterns.some((pattern) => pattern.test(libraryName))) {
627
633
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onecx/accelerator",
3
- "version": "8.0.0-rc.9",
3
+ "version": "9.0.0-rc.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,9 +8,6 @@
8
8
  },
9
9
  "peerDependencies": {
10
10
  "rxjs": "^7.8.1",
11
- "@nx/devkit": "^22.0.2",
12
- "@nx/module-federation": "^22.3.3",
13
- "@onecx/nx-migration-utils": "^8.0.0-rc.9",
14
11
  "debug": "^4.4.3"
15
12
  },
16
13
  "type": "module",
@@ -29,8 +26,5 @@
29
26
  },
30
27
  "publishConfig": {
31
28
  "access": "public"
32
- },
33
- "nx-migrations": {
34
- "migrations": "./migrations.json"
35
29
  }
36
30
  }