@uxland/primary-shell 8.2.4 → 8.3.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 (47) hide show
  1. package/dist/{component-DGPt9i3-.js → component-SjR4v7lM.js} +2 -2
  2. package/dist/{component-DGPt9i3-.js.map → component-SjR4v7lM.js.map} +1 -1
  3. package/dist/{index-C8RN2NKs.js → index-vk3Ud0yY.js} +84 -86
  4. package/dist/index-vk3Ud0yY.js.map +1 -0
  5. package/dist/index.js +18 -22
  6. package/dist/{plugin-MLG7cNJN.js → plugin-CiWzf-ag.js} +2 -2
  7. package/dist/{plugin-MLG7cNJN.js.map → plugin-CiWzf-ag.js.map} +1 -1
  8. package/dist/primary/shell/src/api/api.d.ts +15 -1
  9. package/dist/primary/shell/src/api/api.test.d.ts +1 -0
  10. package/dist/primary/shell/src/api/broker/factory.d.ts +11 -1
  11. package/dist/primary/shell/src/api/broker/primaria-broker.d.ts +0 -2
  12. package/dist/primary/shell/src/api/global-state/global-state.d.ts +0 -7
  13. package/dist/primary/shell/src/api/interaction-service/interaction-service-impl.d.ts +4 -0
  14. package/dist/primary/shell/src/api/interaction-service/interaction-service.d.ts +0 -1
  15. package/dist/primary/shell/src/api/quick-action-busy-manager/quick-action-busy-manager.d.ts +0 -2
  16. package/dist/primary/shell/src/api/region-manager/region-manager.d.ts +17 -2
  17. package/dist/primary/shell/src/api/token-manager/token-manager.d.ts +4 -12
  18. package/dist/primary/shell/src/bootstrapper.d.ts +12 -0
  19. package/dist/primary/shell/src/features/bootstrapper.d.ts +1 -1
  20. package/dist/primary/shell/src/handle-plugins.d.ts +7 -5
  21. package/dist/primary/shell/src/index.d.ts +4 -4
  22. package/package.json +1 -1
  23. package/src/api/api.test.ts +37 -0
  24. package/src/api/api.ts +37 -6
  25. package/src/api/broker/factory.test.ts +12 -7
  26. package/src/api/broker/factory.ts +23 -12
  27. package/src/api/broker/primaria-broker.ts +0 -2
  28. package/src/api/ecap-event-manager/ecap-event-manager.test.ts +0 -1
  29. package/src/api/global-state/global-state.test.ts +0 -8
  30. package/src/api/global-state/global-state.ts +1 -12
  31. package/src/api/http-client/http-client.test.ts +1 -1
  32. package/src/api/interaction-service/interaction-service-impl.tsx +4 -0
  33. package/src/api/interaction-service/interaction-service.ts +0 -1
  34. package/src/api/quick-action-busy-manager/quick-action-busy-manager.test.ts +0 -8
  35. package/src/api/quick-action-busy-manager/quick-action-busy-manager.ts +0 -5
  36. package/src/api/region-manager/region-manager.test.ts +8 -8
  37. package/src/api/region-manager/region-manager.ts +24 -28
  38. package/src/api/region-manager/remove-view-idempotency.test.ts +1 -1
  39. package/src/api/token-manager/token-manager.ts +4 -13
  40. package/src/bootstrapper.ts +23 -2
  41. package/src/disposer.ts +5 -3
  42. package/src/features/bootstrapper.ts +4 -4
  43. package/src/features/exit/handler.test.ts +11 -7
  44. package/src/features/exit/handler.ts +2 -2
  45. package/src/handle-plugins.ts +16 -6
  46. package/src/index.ts +15 -6
  47. package/dist/index-C8RN2NKs.js.map +0 -1
@@ -12,7 +12,7 @@ import { PrimariaRegionManager } from './region-manager/region-manager';
12
12
  import { TokenManager } from './token-manager/token-manager';
13
13
  import { UserManager } from './user-manager/user-manager';
14
14
  import { PrimariaImportDataManager } from './import-data-manager';
15
- import { PrimariaContextManager } from './context-manager/context-manager';
15
+ import { EcapContext, PrimariaContextManager } from './context-manager/context-manager';
16
16
  export interface PrimariaApi extends HarmonixApi {
17
17
  httpClient: HttpClient;
18
18
  interactionService: PrimariaInteractionService;
@@ -32,6 +32,20 @@ export interface PrimariaApi extends HarmonixApi {
32
32
  export declare const PrimariaRegionHost: any;
33
33
  export declare const activityMonitor: import('./activity-monitor/activity-monitor').ActivityMonitor;
34
34
  export declare const sessionRefreshTimer: import('./session-refresh-timer/session-refresh-timer').SessionRefreshTimer;
35
+ /**
36
+ * Operacions destructives o d'arrencada que només pot fer el shell. No surten de `index.ts` i cap
37
+ * no és a la `PrimariaApi`, així que cap plugin no les pot cridar.
38
+ */
39
+ export declare const shellInternals: {
40
+ /** Fixa els tokens inicials. Només funciona una vegada (`Token already initialized`). */
41
+ setInitialTokens: (accessToken: string, refreshToken: string) => void;
42
+ initializeContext: (context: EcapContext) => void;
43
+ /** Desmunta totes les vistes de totes les regions i espera que acabin. */
44
+ removeAllViews: () => Promise<void>;
45
+ destroyRegions: () => Promise<import('@uxland/harmonix').IRegionManager>;
46
+ clearBroker: () => void;
47
+ closeAllDialogs: () => void;
48
+ };
35
49
  /**
36
50
  * Factory function that creates a Primaria API instance.
37
51
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,12 @@
1
1
  import { PrimariaBroker } from './primaria-broker';
2
- export declare const createBroker: () => PrimariaBroker;
2
+ export interface BrokerHandle {
3
+ /** The broker every plugin receives. */
4
+ broker: PrimariaBroker;
5
+ /**
6
+ * Removes every registration. Used on shell teardown so a re-initialization
7
+ * starts from a clean registry (the broker is a module-level singleton).
8
+ * Host-only: it lives outside the broker so no plugin receives it.
9
+ */
10
+ clear: () => void;
11
+ }
12
+ export declare const createBroker: () => BrokerHandle;
@@ -6,8 +6,6 @@ export interface PrimariaBroker extends HarmonixBroker {
6
6
  events: BrokerEvents;
7
7
  /** Noms de les requests: `send` / `registerRequest`. */
8
8
  requests: BrokerRequests;
9
- /** Internal: removes every registration (shell teardown only). */
10
- _clear(): void;
11
9
  }
12
10
  export type { HarmonixBroker, IEvent, IEventClass, IRequest, IRequestClass, } from '@uxland/harmonix';
13
11
  export type { BrokerDisposableHandler } from '@uxland/harmonix';
@@ -2,7 +2,6 @@ import { PrimariaBroker } from '../broker/primaria-broker';
2
2
  export declare abstract class PrimariaGlobalStateManager {
3
3
  abstract setData<T>(key: string, value: T): void;
4
4
  abstract getData<T>(key: string): T | undefined;
5
- abstract clearData(): void;
6
5
  }
7
6
  declare class PrimariaGlobalStateManagerImpl implements PrimariaGlobalStateManager {
8
7
  broker: PrimariaBroker;
@@ -23,12 +22,6 @@ declare class PrimariaGlobalStateManagerImpl implements PrimariaGlobalStateManag
23
22
  * @return {T | undefined} The value associated with the specified key, or undefined if the key does not exist in the state object.
24
23
  */
25
24
  getData<T>(key: string): T | undefined;
26
- /**
27
- * Clears all data stored in the state object.
28
- *
29
- * @return {void} This function does not return anything.
30
- */
31
- clearData(): void;
32
25
  }
33
26
  export declare const createGlobalStateManager: (broker: PrimariaBroker) => PrimariaGlobalStateManagerImpl;
34
27
  export {};
@@ -3,5 +3,9 @@ export declare class PrimariaInteractionServiceImpl extends PrimariaInteractionS
3
3
  private readonly openDialogCancellers;
4
4
  confirm<TData = undefined, TResult = undefined>(data: TData | undefined, componentUI: ConfirmComponentUI<TData, TResult>, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult<TResult | undefined>>;
5
5
  confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
6
+ /**
7
+ * Tanca tots els diàlegs oberts, siguin del plugin que siguin. Host-only: no és al tipus
8
+ * `PrimariaInteractionService`, i els plugins reben una vista que no el porta.
9
+ */
6
10
  dispose(): void;
7
11
  }
@@ -37,5 +37,4 @@ export interface ConfirmComponentUI<TData = undefined, TResult = undefined> {
37
37
  export declare abstract class PrimariaInteractionService {
38
38
  abstract confirm<TData = undefined, TResult = undefined>(data: TData | undefined, componentUI: ConfirmComponentUI<TData, TResult>, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult<TResult | undefined>>;
39
39
  abstract confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
40
- abstract dispose(): void;
41
40
  }
@@ -5,7 +5,6 @@ export interface QuickActionTask {
5
5
  export declare abstract class QuickActionBusyManager {
6
6
  abstract addTask(task: QuickActionTask): void;
7
7
  abstract removeTask(taskId: string): void;
8
- abstract clearAll(): void;
9
8
  abstract isBusy(): boolean;
10
9
  }
11
10
  export declare class QuickActionBusyManagerImpl implements QuickActionBusyManager {
@@ -15,6 +14,5 @@ export declare class QuickActionBusyManagerImpl implements QuickActionBusyManage
15
14
  addTask(task: QuickActionTask): void;
16
15
  removeTask(taskId: string): void;
17
16
  isBusy(): boolean;
18
- clearAll(): void;
19
17
  private emitBusyChanged;
20
18
  }
@@ -21,9 +21,24 @@ export interface PrimariaRegionManager extends HarmonixRegionManager {
21
21
  activatePluginView(regionName: string, pluginId: string, viewId: string): Promise<void>;
22
22
  getCurrentMainViewActive(): string | undefined;
23
23
  getRegisteredMainViews(): RegisteredMainView[];
24
- _removeAllViews(): Promise<void>;
25
- _destroy(): Promise<void>;
26
24
  }
25
+ /**
26
+ * Desmunta totes les vistes de totes les regions, i espera que acabin.
27
+ *
28
+ * Es crida en tancar, ABANS de fer el `dispose` dels plugins: els cleanups dels `useEffect` que
29
+ * s'executen en desmuntar-se poden enviar comandes pel broker, i han de trobar el handler encara
30
+ * registrat. Cada plugin ja ho fa pel seu compte al `dispose`, però això només cobreix els
31
+ * plugins d'aquest repositori; els de tercers (econsulta, allergies…) no els controlem.
32
+ *
33
+ * Fa servir `unregisterViewFromRegion` i no `destroy()`/`clear()` del regionManager perquè
34
+ * aquests fan `forEach` amb crides asíncrones sense esperar-les, així que retornen abans que les
35
+ * vistes s'hagin desmuntat de debò.
36
+ *
37
+ * És idempotent: desregistrar una vista que ja no hi és no fa res.
38
+ *
39
+ * Host-only: és una funció i no un mètode del proxy perquè cap plugin la rebi amb la seva `api`.
40
+ */
41
+ export declare const removeAllViews: (regionManager: IRegionManager) => Promise<void>;
27
42
  /**
28
43
  * Creates a proxy for the region manager with the given plugin info and region manager instance.
29
44
  *
@@ -1,23 +1,15 @@
1
1
  import { PrimariaBroker } from '../broker/primaria-broker';
2
2
  /**
3
3
  * API pública de tokens disponible per als plugins via `api.tokenManager`.
4
- * Els plugins poden llegir el token actual o forçar-ne el refresc; NO han de
5
- * fixar els tokens inicials (això és una responsabilitat del host de bootstrap
6
- * — vegeu {@link InternalTokenManager}).
4
+ * Els plugins poden llegir el token actual o forçar-ne el refresc; NO poden
5
+ * fixar els tokens inicials: això ho fa el host amb `setInitialTokens`, que
6
+ * s'exporta com a funció i només funciona una vegada.
7
7
  */
8
8
  export interface TokenManager {
9
9
  getToken: () => string;
10
10
  refreshToken: () => Promise<string>;
11
11
  }
12
- /**
13
- * Extensió host-only de {@link TokenManager}. Només el host del shell
14
- * (`primary/app`) usa `setInitialTokens` durant el bootstrap; és deliberadament
15
- * absent del tipus `TokenManager` que veuen els plugins.
16
- */
17
- export interface InternalTokenManager extends TokenManager {
18
- setInitialTokens: (access_token: string, refresh_token: string) => void;
19
- }
20
- export declare class TokenManagerImpl implements InternalTokenManager {
12
+ export declare class TokenManagerImpl implements TokenManager {
21
13
  private readonly broker;
22
14
  constructor(broker: PrimariaBroker);
23
15
  getUrlParams: () => URLSearchParams;
@@ -1,2 +1,14 @@
1
1
  import { EcapContext } from './api/context-manager/context-manager';
2
+ /**
3
+ * Arrenca el shell. L'exporta el paquet perquè el host (`primary/app`, el sandbox) l'ha de cridar,
4
+ * i per això també el pot importar un plugin: només funciona una vegada, abans de carregar cap
5
+ * plugin, i no torna a funcionar fins que el shell s'ha desmuntat.
6
+ */
2
7
  export declare const initializeShell: (hostAppElement: HTMLElement, ecapContext?: EcapContext) => void;
8
+ /** Permet tornar a arrencar el shell un cop desmuntat. Només el crida `disposeShell`. */
9
+ export declare const resetShellInitialization: () => void;
10
+ /**
11
+ * Fixa els tokens inicials quan el host els rep d'ECAP en lloc de la URL. Només funciona una
12
+ * vegada: a partir del primer token, llegit o fixat, llança `Token already initialized`.
13
+ */
14
+ export declare const setInitialTokens: (accessToken: string, refreshToken: string) => void;
@@ -1,3 +1,3 @@
1
1
  import { PrimariaApi } from '../api/api';
2
2
  export declare const useFeatures: (api: PrimariaApi) => void;
3
- export declare const disposeFeatures: (api: PrimariaApi) => Promise<void>;
3
+ export declare const disposeFeatures: () => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { BootstrappedPlugin, PluginDefinition, Plugin as PluginType } from '@uxland/harmonix';
1
+ import { PluginDefinition, Plugin as PluginType } from '@uxland/harmonix';
2
2
  import { PrimariaApi } from './api/api';
3
3
  export type { PluginDefinition, PluginInfo } from '@uxland/harmonix';
4
4
  export interface PrimariaPlugin extends Plugin {
@@ -8,10 +8,12 @@ export interface PrimariaStartupPlugin {
8
8
  pluginId: string;
9
9
  params: any;
10
10
  }
11
- interface PrimariaBootstrappedPlugin extends BootstrappedPlugin<PrimariaApi> {
12
- importedPlugin: PrimariaPlugin;
13
- }
11
+ /**
12
+ * Carrega i inicialitza els plugins. L'exporta el paquet perquè el host l'ha de cridar, i per
13
+ * això també el pot importar un plugin: només funciona una vegada, i no torna a funcionar fins
14
+ * que `disposePlugins` els ha desmuntat. Així un plugin no pot carregar-ne d'altres amb la
15
+ * identitat que vulgui.
16
+ */
14
17
  export declare const bootstrapPlugins: (plugins: PluginDefinition[], startup?: PrimariaStartupPlugin) => Promise<void>;
15
- export declare const handleStartupPlugin: (plugins: PrimariaBootstrappedPlugin[], startupPlugin?: PrimariaStartupPlugin) => void;
16
18
  export declare const disposePlugins: () => Promise<void[]>;
17
19
  export type Plugin = PluginType<PrimariaApi>;
@@ -1,10 +1,10 @@
1
- export * from './bootstrapper';
2
- export * from './disposer';
1
+ export { initializeShell, setInitialTokens } from './bootstrapper';
3
2
  export type { RegisteredMainView } from './api/region-manager/region-manager';
4
- export * from './handle-plugins';
3
+ export { bootstrapPlugins } from './handle-plugins';
4
+ export type { Plugin, PluginDefinition, PluginInfo, PrimariaPlugin, PrimariaStartupPlugin, } from './handle-plugins';
5
5
  export type { PrimariaApi } from './api/api';
6
6
  export { PrimariaRegionHost, shellApi } from './api/api';
7
- export type { TokenManager, InternalTokenManager } from './api/token-manager/token-manager';
7
+ export type { TokenManager } from './api/token-manager/token-manager';
8
8
  export * from './api/broker/primaria-broker';
9
9
  export type { PrimariaContextManager, EcapContext } from './api/context-manager/context-manager';
10
10
  export type { PrimariaImportDataManager, ImportParams, ImportParamsDiagnostic, } from './api/import-data-manager/import-data-manager';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "8.2.4",
3
+ "version": "8.3.0",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { primariaApiFactory, shellApi } from "./api";
3
+
4
+ /**
5
+ * Contracte d'aïllament: l'objecte que rep un plugin no porta cap operació destructiva o
6
+ * d'arrencada del shell. Es comprova l'objecte en temps d'execució, no el tipus: un plugin de
7
+ * tercers no passa pel nostre TypeScript.
8
+ */
9
+ describe("PrimariaApi que rep un plugin", () => {
10
+ const hostOnly: [string, string][] = [
11
+ ["broker", "_clear"],
12
+ ["broker", "clear"],
13
+ ["regionManager", "_removeAllViews"],
14
+ ["regionManager", "_destroy"],
15
+ ["regionManager", "destroy"],
16
+ ["globalStateManager", "clearData"],
17
+ ["quickActionBusyManager", "clearAll"],
18
+ ["interactionService", "dispose"],
19
+ ["tokenManager", "setInitialTokens"],
20
+ ["contextManager", "initializeContext"],
21
+ ];
22
+
23
+ for (const api of [primariaApiFactory({ pluginId: "plugin-x" }), shellApi]) {
24
+ it.each(hostOnly)(`${api.pluginInfo.pluginId}: %s no exposa %s`, (manager, method) => {
25
+ expect(method in (api as any)[manager]).toBe(false);
26
+ });
27
+ }
28
+
29
+ it("conserva les operacions públiques", () => {
30
+ const api = primariaApiFactory({ pluginId: "plugin-x" });
31
+ expect(typeof api.tokenManager.getToken).toBe("function");
32
+ expect(typeof api.tokenManager.refreshToken).toBe("function");
33
+ expect(typeof api.contextManager.getContext).toBe("function");
34
+ expect(typeof api.interactionService.confirm).toBe("function");
35
+ expect(typeof api.interactionService.confirmMessage).toBe("function");
36
+ });
37
+ });
package/src/api/api.ts CHANGED
@@ -15,13 +15,13 @@ import { PrimariaNotificationService } from "./notification-service/notification
15
15
  import { PrimariaNotificationServiceImpl } from "./notification-service/notification.service-impl";
16
16
  import { PdfViewerManager, createPdfViewerManager } from "./pdf-viewer-manager/pdf-viewer-manager";
17
17
  import { QuickActionBusyManager, QuickActionBusyManagerImpl } from "./quick-action-busy-manager/quick-action-busy-manager";
18
- import { PrimariaRegionManager, createRegionManagerProxy } from "./region-manager/region-manager";
18
+ import { PrimariaRegionManager, createRegionManagerProxy, removeAllViews } from "./region-manager/region-manager";
19
19
  import { TokenManager, createTokenManager } from "./token-manager/token-manager";
20
20
  import { UserManager, createUserManager } from "./user-manager/user-manager";
21
21
  import { PrimariaImportDataManager, ImportDataManagerImpl } from "./import-data-manager";
22
- import { PrimariaContextManager, createContextManager } from "./context-manager/context-manager";
22
+ import { EcapContext, PrimariaContextManager, createContextManager } from "./context-manager/context-manager";
23
23
 
24
- const broker = createBroker();
24
+ const { broker, clear: clearBroker } = createBroker();
25
25
 
26
26
  export interface PrimariaApi extends HarmonixApi {
27
27
  httpClient: HttpClient;
@@ -56,6 +56,37 @@ const ecapEventManager = createEcapEventManager(globalStateManager);
56
56
  const pdfViewerManager = createPdfViewerManager(broker, notificationService);
57
57
  const importDataManager = new ImportDataManagerImpl(interactionService);
58
58
 
59
+ // Vistes del que reben els plugins. Els singletons de token, context i interacció tenen mètodes
60
+ // que només pot fer servir el host (fixar els tokens, fixar el context d'ECAP, tancar tots els
61
+ // diàlegs). Amagar-los al tipus no n'hi ha prou: un plugin de tercers no passa pel nostre
62
+ // TypeScript. Per això el plugin rep un objecte que no els porta.
63
+ const publicTokenManager: TokenManager = {
64
+ getToken: () => tokenManager.getToken(),
65
+ refreshToken: () => tokenManager.refreshToken(),
66
+ };
67
+ const publicContextManager: PrimariaContextManager = {
68
+ getContext: () => contextManager.getContext(),
69
+ };
70
+ const publicInteractionService: PrimariaInteractionService = {
71
+ confirm: (data, componentUI, options) => interactionService.confirm(data, componentUI, options),
72
+ confirmMessage: (message, options) => interactionService.confirmMessage(message, options),
73
+ };
74
+
75
+ /**
76
+ * Operacions destructives o d'arrencada que només pot fer el shell. No surten de `index.ts` i cap
77
+ * no és a la `PrimariaApi`, així que cap plugin no les pot cridar.
78
+ */
79
+ export const shellInternals = {
80
+ /** Fixa els tokens inicials. Només funciona una vegada (`Token already initialized`). */
81
+ setInitialTokens: (accessToken: string, refreshToken: string) => tokenManager.setInitialTokens(accessToken, refreshToken),
82
+ initializeContext: (context: EcapContext) => contextManager.initializeContext(context),
83
+ /** Desmunta totes les vistes de totes les regions i espera que acabin. */
84
+ removeAllViews: () => removeAllViews(regionManager),
85
+ destroyRegions: () => regionManager.destroy(),
86
+ clearBroker,
87
+ closeAllDialogs: () => interactionService.dispose(),
88
+ };
89
+
59
90
  /**
60
91
  * Factory function that creates a Primaria API instance.
61
92
  *
@@ -72,13 +103,13 @@ export const primariaApiFactory: ApiFactory<PrimariaApi> = (pluginInfo: PluginIn
72
103
  broker,
73
104
  createLocaleManager: createLocaleManager(pluginInfo.pluginId) as any,
74
105
  globalStateManager,
75
- contextManager,
76
- tokenManager,
106
+ contextManager: publicContextManager,
107
+ tokenManager: publicTokenManager,
77
108
  userManager,
78
109
  ecapEventManager,
79
110
  exitGuardManager,
80
111
  quickActionBusyManager,
81
- interactionService,
112
+ interactionService: publicInteractionService,
82
113
  notificationService,
83
114
  pdfViewerManager,
84
115
  importDataManager,
@@ -7,7 +7,7 @@ describe("Broker test", () => {
7
7
  let sut: PrimariaBroker;
8
8
 
9
9
  beforeEach(() => {
10
- sut = createBroker();
10
+ sut = createBroker().broker;
11
11
  });
12
12
 
13
13
  describe("Event bus test", () => {
@@ -212,14 +212,20 @@ describe("Broker test", () => {
212
212
  });
213
213
  });
214
214
 
215
- describe("_clear", () => {
215
+ describe("clear", () => {
216
216
  class MyRequest implements IRequest<string> {}
217
217
 
218
218
  it("removes all registrations so the registry can be reused cleanly", () => {
219
- sut.registerRequest(MyRequest, () => "x");
220
- sut._clear();
219
+ const { broker, clear } = createBroker();
220
+ broker.registerRequest(MyRequest, () => "x");
221
+ clear();
221
222
  // After a clear, registering the same request again must not throw.
222
- expect(() => sut.registerRequest(MyRequest, () => "y")).not.toThrow();
223
+ expect(() => broker.registerRequest(MyRequest, () => "y")).not.toThrow();
224
+ });
225
+
226
+ it("is not reachable from the broker plugins receive", () => {
227
+ expect("clear" in sut).toBe(false);
228
+ expect("_clear" in sut).toBe(false);
223
229
  });
224
230
  });
225
231
 
@@ -294,9 +300,8 @@ describe("Broker test", () => {
294
300
  });
295
301
 
296
302
  it("a subscriber that disposes itself during dispatch is still called that round but not the next", async () => {
297
- let disposable: ReturnType<typeof sut.subscribe>;
298
303
  const handler = vi.fn(() => disposable.dispose());
299
- disposable = sut.subscribe("evt", handler);
304
+ const disposable = sut.subscribe("evt", handler);
300
305
 
301
306
  await sut.publish("evt", {});
302
307
  await sut.publish("evt", {});
@@ -33,11 +33,12 @@ class Broker implements PrimariaBroker {
33
33
  public readonly events = BROKER_EVENTS;
34
34
  public readonly requests = BROKER_REQUESTS;
35
35
 
36
- /** One handler per request type (request/response). */
37
- private readonly requestHandlers = new Map<MessageKey, Handler>();
38
-
39
- /** Many subscribers per event type (publish/subscribe). */
40
- private readonly eventSubscribers = new Map<MessageKey, Set<Handler>>();
36
+ constructor(
37
+ /** One handler per request type (request/response). */
38
+ private readonly requestHandlers: Map<MessageKey, Handler>,
39
+ /** Many subscribers per event type (publish/subscribe). */
40
+ private readonly eventSubscribers: Map<MessageKey, Set<Handler>>,
41
+ ) {}
41
42
 
42
43
  // ---- Request / response ---------------------------------------------------
43
44
 
@@ -124,17 +125,27 @@ class Broker implements PrimariaBroker {
124
125
  },
125
126
  };
126
127
  }
128
+ }
127
129
 
128
- // ---- Lifecycle ------------------------------------------------------------
129
-
130
+ export interface BrokerHandle {
131
+ /** The broker every plugin receives. */
132
+ broker: PrimariaBroker;
130
133
  /**
131
134
  * Removes every registration. Used on shell teardown so a re-initialization
132
135
  * starts from a clean registry (the broker is a module-level singleton).
136
+ * Host-only: it lives outside the broker so no plugin receives it.
133
137
  */
134
- _clear(): void {
135
- this.requestHandlers.clear();
136
- this.eventSubscribers.clear();
137
- }
138
+ clear: () => void;
138
139
  }
139
140
 
140
- export const createBroker = (): PrimariaBroker => new Broker();
141
+ export const createBroker = (): BrokerHandle => {
142
+ const requestHandlers = new Map<MessageKey, Handler>();
143
+ const eventSubscribers = new Map<MessageKey, Set<Handler>>();
144
+ return {
145
+ broker: new Broker(requestHandlers, eventSubscribers),
146
+ clear: () => {
147
+ requestHandlers.clear();
148
+ eventSubscribers.clear();
149
+ },
150
+ };
151
+ };
@@ -7,8 +7,6 @@ export interface PrimariaBroker extends HarmonixBroker {
7
7
  events: BrokerEvents;
8
8
  /** Noms de les requests: `send` / `registerRequest`. */
9
9
  requests: BrokerRequests;
10
- /** Internal: removes every registration (shell teardown only). */
11
- _clear(): void;
12
10
  }
13
11
 
14
12
  export type {
@@ -6,7 +6,6 @@ const createMockGlobalStateManager = (data: Record<string, unknown> = {}) =>
6
6
  ({
7
7
  getData: vi.fn((key: string) => data[key]),
8
8
  setData: vi.fn(),
9
- clearData: vi.fn(),
10
9
  }) as any;
11
10
 
12
11
  /** `mock.calls[0][0]` és `unknown | undefined` amb `noUncheckedIndexedAccess`. */
@@ -42,12 +42,4 @@ describe("PrimariaGlobalStateManagerImpl", () => {
42
42
  const result = globalStateManager.getData("key1");
43
43
  expect(result).toBe("newValue");
44
44
  });
45
-
46
- it("should clear all data", () => {
47
- globalStateManager.setData("key1", "value1");
48
- globalStateManager.setData("key2", "value2");
49
- globalStateManager.clearData();
50
- expect(globalStateManager.getData("key1")).toBeUndefined();
51
- expect(globalStateManager.getData("key2")).toBeUndefined();
52
- });
53
45
  });
@@ -3,7 +3,6 @@ import { PrimariaBroker } from "../broker/primaria-broker";
3
3
  export abstract class PrimariaGlobalStateManager {
4
4
  abstract setData<T>(key: string, value: T): void;
5
5
  abstract getData<T>(key: string): T | undefined;
6
- abstract clearData(): void;
7
6
  }
8
7
 
9
8
  class PrimariaGlobalStateManagerImpl implements PrimariaGlobalStateManager {
@@ -34,16 +33,6 @@ class PrimariaGlobalStateManagerImpl implements PrimariaGlobalStateManager {
34
33
  getData<T>(key: string): T | undefined {
35
34
  return this.state[key] as T | undefined;
36
35
  }
37
-
38
- /**
39
- * Clears all data stored in the state object.
40
- *
41
- * @return {void} This function does not return anything.
42
- */
43
- public clearData(): void {
44
- this.state = {};
45
- }
46
36
  }
47
37
 
48
- export const createGlobalStateManager = (broker: PrimariaBroker) =>
49
- new PrimariaGlobalStateManagerImpl(broker);
38
+ export const createGlobalStateManager = (broker: PrimariaBroker) => new PrimariaGlobalStateManagerImpl(broker);
@@ -15,7 +15,7 @@ const newAccessToken =
15
15
  "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJidFZxNnRMWGpmcXdzbm5MR2FXMXdhdU9McDNiTmY4bWZ3Rm1SZ0lBS2VJIn0.eyJleHAiOjE3NDI5MTAzNzgsImlhdCI6MTc0MjkwOTQ3OCwianRpIjoiMTg4OTE3ZDYtNmM0OS00YWY0LTlhYjItZjEzYTM4MGY5OTgyIiwiaXNzIjoiaHR0cHM6Ly9wcmVwcm9kdWNjaW8ucGRzLmhlcy5jYXRzYWx1dC5nZW5jYXQuY2F0L2F1dGgvcmVhbG1zL0hFUyIsInN1YiI6Ijk1OGUyZWQ5LTJkNmUtNDZjOC1hOTE5LTU5MDQ0ZTYwMzVjMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImV0Yy1jY2YtcHJlIiwic2Vzc2lvbl9zdGF0ZSI6IjY5ODdhMzExLWM1NzQtNDc1Ni1hMzY0LWY1ZjQzZmViZjNhYiIsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLWhlcyIsIlJPTEVfSEVTX0VUQyIsIlJPTEVfSEVTX0xBTkRJTkciXX0sInNjb3BlIjoiIiwic2lkIjoiNjk4N2EzMTEtYzU3NC00NzU2LWEzNjQtZjVmNDNmZWJmM2FiIiwiY2xpZW50SG9zdCI6IjEwLjUzLjI1NC4xNTAiLCJhY2Nlc3NfcnVsZXMiOnt9LCJhY2Nlc3NfaW5mbyI6eyJtb2R1bGVfY29kZSI6IkEwMDEiLCJyb2xlX3R5cGUiOiJOT1JNIiwidHJhY2VfdXNlcl9pZCI6IlVzZXJfSUQiLCJjZW50ZXJfdHlwZSI6IkUiLCJtcGlfcGF0aWVudF9pZCI6IjVlYzc0YzdiLTVhYTUtNGE4NC1iM2I0LWYwMmVkZGZkZjZkYyIsInVwX2NvZGUiOiIwNzczMyIsInRyYWNlX3VzZXJfZ2l2ZW5fbmFtZSI6IkdpdmVuIE5hbWUiLCJ0cmFjZV91c2VyX2ZhbWlseV9uYW1lIjoiRmFtaWx5IE5hbWUiLCJ1c2VyX3R5cGUiOiJBRE0iLCJjZW50ZXJfY29kZSI6IkUwODU4Njk2MyIsInByb2Zlc3Npb25hbF9jYXRlZ29yeSI6IjMwOTM0MzAwNiIsInNlcnZpY2VfY29kZSI6IjVTMDg5IiwiZXBfY29kZSI6IjAyMDgiLCJpZGVudGlmaWVyIjpbeyJ0eXBlIjoiRE5JIiwidmFsdWUiOiI3MzI4ODIxOUEifSx7InR5cGUiOiJOVU1DT0wiLCJ2YWx1ZSI6IjIifV0sImFsdF9pZGVudGlmaWVyIjpbeyJ0eXBlIjoiTVBJIiwidmFsdWUiOiIwNjIxY2Y3ZC03ZDYzLTQ5ZWMtODAwNi04YzA1NjkyZWQzNzcifV19LCJjbGllbnRBZGRyZXNzIjoiMTAuNTMuMjU0LjE1MCIsImNsaWVudF9pZCI6ImV0Yy1jY2YtcHJlIn0.zPxoN5d8_uxdbxeH7ly9sQdlnDxNp8_eWDzNSzjzkUPsRVkLxgjQw_WcjZfns-LNgGr0FToS6uSDIC7uj2hPpKqD7HPWbI6UPa7g-43Jf9rh-KSOXEHJWhlASi2w0n3xQHFSxHDYBwhyXlvWQ_Tr1Vh37MroWmEL84fdwqhcfZHmD9Ek52EuRRrB-XkymCmN1ZvO2GPU04LbBvQxLVzdAaKRzr1cUqHTnsEdgRduyKShPcyth01L_X7m128SIwjJsa1lYxFE_DbSDKz8dPTsxoS1DgwRxeArrkMlIdTHyxmDRezZUGhamyLuWpXLDXJCFfrTUB8-j_JnVlILHeR6O";
16
16
 
17
17
  describe("HTTP Client", () => {
18
- const broker = createBroker();
18
+ const { broker } = createBroker();
19
19
  let tokenManager: TokenManager;
20
20
  let axiosInstance: AxiosInstance;
21
21
  let axiosMockInstance: AxiosMockAdapter;
@@ -248,6 +248,10 @@ export class PrimariaInteractionServiceImpl extends PrimariaInteractionService {
248
248
  return this.confirm(message, { component: ConfirmationMessage }, options);
249
249
  }
250
250
 
251
+ /**
252
+ * Tanca tots els diàlegs oberts, siguin del plugin que siguin. Host-only: no és al tipus
253
+ * `PrimariaInteractionService`, i els plugins reben una vista que no el porta.
254
+ */
251
255
  dispose(): void {
252
256
  for (const cancelDialog of [...this.openDialogCancellers]) {
253
257
  cancelDialog();
@@ -49,5 +49,4 @@ export abstract class PrimariaInteractionService {
49
49
  options?: ConfirmationOptions | undefined,
50
50
  ): Promise<ConfirmationResult<TResult | undefined>>;
51
51
  abstract confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
52
- abstract dispose(): void;
53
52
  }
@@ -58,12 +58,4 @@ describe("QuickActionBusyManagerImpl", () => {
58
58
  expect(manager.isBusy()).toBe(true);
59
59
  });
60
60
  });
61
-
62
- describe("clearAll", () => {
63
- it("should clear all tasks", () => {
64
- manager.addTask({ taskId: "qa1" });
65
- manager.clearAll();
66
- expect(manager.isBusy()).toBe(false);
67
- });
68
- });
69
61
  });
@@ -8,7 +8,6 @@ export interface QuickActionTask {
8
8
  export abstract class QuickActionBusyManager {
9
9
  abstract addTask(task: QuickActionTask): void;
10
10
  abstract removeTask(taskId: string): void;
11
- abstract clearAll(): void;
12
11
  abstract isBusy(): boolean;
13
12
  }
14
13
 
@@ -39,10 +38,6 @@ export class QuickActionBusyManagerImpl implements QuickActionBusyManager {
39
38
  return this.tasks.length > 0;
40
39
  }
41
40
 
42
- public clearAll(): void {
43
- this.tasks = [];
44
- }
45
-
46
41
  private emitBusyChanged(): void {
47
42
  const busy = this.isBusy();
48
43
  this.broker.publish(BROKER_EVENTS.shell.quickActionBusyChanged, { busy });
@@ -1,7 +1,7 @@
1
1
  // @vitest-environment happy-dom
2
2
  import { beforeEach, describe, expect, it, vi } from "vitest";
3
3
  import { BROKER_EVENTS } from "../broker/broker-events";
4
- import { createRegionManagerProxy } from "./region-manager";
4
+ import { createRegionManagerProxy, removeAllViews } from "./region-manager";
5
5
 
6
6
  const pluginId = "test-plugin";
7
7
  const mockView = { id: "view1", factory: () => Promise.resolve(document.createElement("div")) };
@@ -178,12 +178,12 @@ describe("RegionManagerProxy", () => {
178
178
  });
179
179
  });
180
180
 
181
- it("_destroy should call regionManager.destroy", () => {
182
- proxy._destroy();
183
- expect(regionManager.destroy).toHaveBeenCalled();
181
+ it("no exposa les operacions de tancament del shell", () => {
182
+ expect("_destroy" in proxy).toBe(false);
183
+ expect("_removeAllViews" in proxy).toBe(false);
184
184
  });
185
185
 
186
- describe("_removeAllViews", () => {
186
+ describe("removeAllViews", () => {
187
187
  /**
188
188
  * Es crida en tancar, abans del `dispose` dels plugins, perque els cleanups dels `useEffect`
189
189
  * trobin els handlers del broker encara registrats. Ha d'esperar cada desmuntatge: el
@@ -200,7 +200,7 @@ describe("RegionManagerProxy", () => {
200
200
  : [],
201
201
  );
202
202
 
203
- await proxy._removeAllViews();
203
+ await removeAllViews(regionManager);
204
204
 
205
205
  expect(regionManager.unregisterViewFromRegion).toHaveBeenCalledWith("main-region", "a::v1");
206
206
  expect(regionManager.unregisterViewFromRegion).toHaveBeenCalledWith("main-region", "b::v2");
@@ -223,7 +223,7 @@ describe("RegionManagerProxy", () => {
223
223
  order.push(`done:${key}`);
224
224
  });
225
225
 
226
- await proxy._removeAllViews();
226
+ await removeAllViews(regionManager);
227
227
 
228
228
  expect(order).toEqual(["start:a::v1", "done:a::v1", "start:b::v2", "done:b::v2"]);
229
229
  });
@@ -231,7 +231,7 @@ describe("RegionManagerProxy", () => {
231
231
  it("no fa res si cap regio te vistes", async () => {
232
232
  regionManager.getRegisteredViews = vi.fn().mockReturnValue([]);
233
233
 
234
- await proxy._removeAllViews();
234
+ await removeAllViews(regionManager);
235
235
 
236
236
  expect(regionManager.unregisterViewFromRegion).not.toHaveBeenCalled();
237
237
  });