@servicetitan/standalone-root 1.1.0 → 1.2.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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/components/standalone-root-provider/standalone-root-provider.d.ts +7 -1
  3. package/dist/components/standalone-root-provider/standalone-root-provider.d.ts.map +1 -1
  4. package/dist/components/standalone-root-provider/standalone-root-provider.js +43 -9
  5. package/dist/components/standalone-root-provider/standalone-root-provider.js.map +1 -1
  6. package/dist/stores/standalone-root.store.d.ts +39 -7
  7. package/dist/stores/standalone-root.store.d.ts.map +1 -1
  8. package/dist/stores/standalone-root.store.js +297 -63
  9. package/dist/stores/standalone-root.store.js.map +1 -1
  10. package/dist/utils/constants.d.ts +4 -0
  11. package/dist/utils/constants.d.ts.map +1 -0
  12. package/dist/utils/constants.js +4 -0
  13. package/dist/utils/constants.js.map +1 -0
  14. package/dist/utils/event-emitter.d.ts +9 -0
  15. package/dist/utils/event-emitter.d.ts.map +1 -0
  16. package/dist/utils/event-emitter.js +30 -0
  17. package/dist/utils/event-emitter.js.map +1 -0
  18. package/dist/utils/events.d.ts +4 -0
  19. package/dist/utils/events.d.ts.map +1 -0
  20. package/dist/utils/events.js +5 -0
  21. package/dist/utils/events.js.map +1 -0
  22. package/dist/utils/storage-keys.d.ts +8 -0
  23. package/dist/utils/storage-keys.d.ts.map +1 -0
  24. package/dist/utils/storage-keys.js +9 -0
  25. package/dist/utils/storage-keys.js.map +1 -0
  26. package/dist/utils/symbols.d.ts +4 -0
  27. package/dist/utils/symbols.d.ts.map +1 -0
  28. package/dist/utils/symbols.js +6 -0
  29. package/dist/utils/symbols.js.map +1 -0
  30. package/package.json +2 -2
  31. package/src/components/standalone-root-provider/standalone-root-provider.tsx +77 -14
  32. package/src/stores/standalone-root.store.ts +226 -83
  33. package/src/utils/constants.ts +4 -0
  34. package/src/utils/event-emitter.ts +27 -0
  35. package/src/utils/events.ts +3 -0
  36. package/src/utils/storage-keys.ts +9 -0
  37. package/src/utils/symbols.ts +6 -0
  38. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v1.2.0 (Thu Jul 31 2025)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - Major improvements [#70](https://github.com/servicetitan/standalone-fe/pull/70) ([@dkhachatryan-st](https://github.com/dkhachatryan-st))
6
+
7
+ #### Authors: 1
8
+
9
+ - David Khachatryan ([@dkhachatryan-st](https://github.com/dkhachatryan-st))
10
+
11
+ ---
12
+
1
13
  # v1.1.0 (Thu Jul 24 2025)
2
14
 
3
15
  #### 🚀 Enhancement
@@ -1,3 +1,9 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
- export declare const StandaloneRootProvider: FC<PropsWithChildren>;
2
+ interface StandaloneRootProviderProps extends PropsWithChildren {
3
+ forceRefreshOnMount?: boolean;
4
+ refreshOnboardingOnMount?: boolean;
5
+ baseUrl?: string;
6
+ }
7
+ export declare const StandaloneRootProvider: FC<StandaloneRootProviderProps>;
8
+ export {};
3
9
  //# sourceMappingURL=standalone-root-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standalone-root-provider.d.ts","sourceRoot":"","sources":["../../../src/components/standalone-root-provider/standalone-root-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAU9C,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,iBAAiB,CAiBxD,CAAC"}
1
+ {"version":3,"file":"standalone-root-provider.d.ts","sourceRoot":"","sources":["../../../src/components/standalone-root-provider/standalone-root-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AA2BzD,UAAU,2BAA4B,SAAQ,iBAAiB;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA2CD,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAgBlE,CAAC"}
@@ -1,20 +1,54 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { provide, useDependencies } from '@servicetitan/react-ioc';
3
- import { TenantManagementApi } from '@servicetitan/standalone-tm-api';
2
+ import { useEffect } from 'react';
3
+ import { provide, Provider, useDependencies } from '@servicetitan/react-ioc';
4
+ import { BASE_URL_TOKEN_TenantManagementApi, TenantManagementApi, } from '@servicetitan/standalone-tm-api';
4
5
  import { StandaloneRootStore } from '../../stores';
5
6
  import { observer } from 'mobx-react';
6
- import { AppConfigApi } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
7
- import { CurrentUserClientApi } from '@servicetitan/marketing-services-api/identity';
7
+ import { AppConfigApi, BASE_URL_TOKEN_AppConfigApi, } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
8
+ import { CurrentUserClientApi, PartitionsClientApi, } from '@servicetitan/marketing-services-api/identity';
8
9
  import { CultureProvider } from '@servicetitan/culture';
9
- import { LoadStatus } from '@servicetitan/standalone-ui';
10
- export const StandaloneRootProvider = provide({
11
- singletons: [TenantManagementApi, AppConfigApi, CurrentUserClientApi, StandaloneRootStore],
12
- }, { loadingFallback: _jsx("div", {}) })(observer(({ children }) => {
13
- const [{ loadStatus, locale }] = useDependencies(StandaloneRootStore);
10
+ import { CenteredSpinner, LoadStatus } from '@servicetitan/standalone-ui';
11
+ import { BASE_URL_TOKEN_OnboardingApi, OnboardingApi, } from '@servicetitan/marketing-services-api/settings';
12
+ import { BASE_URL_TOKEN_CurrentUserClientApi, BASE_URL_TOKEN_PartitionsClientApi, } from '@servicetitan/marketing-services-api/dist/identity/partition.api';
13
+ const StandaloneRootProviderUnwrapped = provide({
14
+ singletons: [
15
+ TenantManagementApi,
16
+ AppConfigApi,
17
+ CurrentUserClientApi,
18
+ PartitionsClientApi,
19
+ StandaloneRootStore,
20
+ OnboardingApi,
21
+ ],
22
+ })(observer(({ children, forceRefreshOnMount, refreshOnboardingOnMount }) => {
23
+ const [{ initialize, loadStatus, locale, unregisterGlobalSyncListener }] = useDependencies(StandaloneRootStore);
24
+ useEffect(() => {
25
+ initialize(!!forceRefreshOnMount, !!refreshOnboardingOnMount);
26
+ return () => {
27
+ unregisterGlobalSyncListener();
28
+ };
29
+ }, [
30
+ initialize,
31
+ forceRefreshOnMount,
32
+ refreshOnboardingOnMount,
33
+ unregisterGlobalSyncListener,
34
+ ]);
35
+ if (loadStatus === LoadStatus.Loading) {
36
+ return _jsx(CenteredSpinner, { inFrame: true });
37
+ }
14
38
  if (loadStatus === LoadStatus.Ok) {
15
39
  const culture = { Name: locale };
16
40
  return _jsx(CultureProvider, { value: culture, children: children });
17
41
  }
18
42
  return null;
19
43
  }));
44
+ export const StandaloneRootProvider = props => {
45
+ const { baseUrl } = props;
46
+ return (_jsx(Provider, { singletons: [
47
+ { provide: BASE_URL_TOKEN_TenantManagementApi, useValue: baseUrl },
48
+ { provide: BASE_URL_TOKEN_OnboardingApi, useValue: baseUrl },
49
+ { provide: BASE_URL_TOKEN_AppConfigApi, useValue: baseUrl },
50
+ { provide: BASE_URL_TOKEN_CurrentUserClientApi, useValue: baseUrl },
51
+ { provide: BASE_URL_TOKEN_PartitionsClientApi, useValue: baseUrl },
52
+ ], children: _jsx(StandaloneRootProviderUnwrapped, { ...props }) }));
53
+ };
20
54
  //# sourceMappingURL=standalone-root-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"standalone-root-provider.js","sourceRoot":"","sources":["../../../src/components/standalone-root-provider/standalone-root-provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,qEAAqE,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAW,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,CAAC,MAAM,sBAAsB,GAA0B,OAAO,CAChE;IACI,UAAU,EAAE,CAAC,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,CAAC;CAC7F,EACD,EAAE,eAAe,EAAE,eAAO,EAAE,CAC/B,CACG,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtB,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,eAAe,CAAC,mBAAmB,CAAC,CAAC;IAEtE,IAAI,UAAU,KAAK,UAAU,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,MAAM,EAAa,CAAC;QAE5C,OAAO,KAAC,eAAe,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,GAAmB,CAAC;IACzE,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC,CACL,CAAC"}
1
+ {"version":3,"file":"standalone-root-provider.js","sourceRoot":"","sources":["../../../src/components/standalone-root-provider/standalone-root-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EACH,kCAAkC,EAClC,mBAAmB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC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E5C,OAAO,KAAC,eAAe,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,GAAmB,CAAC;IACzE,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC,CACL,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAoC,KAAK,CAAC,EAAE;IAC3E,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE1B,OAAO,CACH,KAAC,QAAQ,IACL,UAAU,EAAE;YACR,EAAE,OAAO,EAAE,kCAAkC,EAAE,QAAQ,EAAE,OAAO,EAAE;YAClE,EAAE,OAAO,EAAE,4BAA4B,EAAE,QAAQ,EAAE,OAAO,EAAE;YAC5D,EAAE,OAAO,EAAE,2BAA2B,EAAE,QAAQ,EAAE,OAAO,EAAE;YAC3D,EAAE,OAAO,EAAE,mCAAmC,EAAE,QAAQ,EAAE,OAAO,EAAE;YACnE,EAAE,OAAO,EAAE,kCAAkC,EAAE,QAAQ,EAAE,OAAO,EAAE;SACrE,YAED,KAAC,+BAA+B,OAAK,KAAK,GAAI,GACvC,CACd,CAAC;AACN,CAAC,CAAC"}
@@ -1,12 +1,14 @@
1
- import { Store } from '@servicetitan/react-ioc';
2
- import { TenantManagementApi, TenantModel } from '@servicetitan/standalone-tm-api';
3
- import { CurrentUserClientApi, UserDetails } from '@servicetitan/marketing-services-api/identity';
4
- import { AppConfigApi, AppSettings } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
1
+ import { CurrentUserClientApi, PartitionInfo, PartitionsClientApi, UserDetails } from '@servicetitan/marketing-services-api/identity';
5
2
  import { LoadStatus } from '@servicetitan/standalone-ui';
6
- export declare class StandaloneRootStore extends Store {
3
+ import { AppConfigApi, AppSettings } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
4
+ import { TenantManagementApi, TenantModel } from '@servicetitan/standalone-tm-api';
5
+ import { OnboardingApi, OnboardingResponse } from '@servicetitan/marketing-services-api/settings';
6
+ export declare class StandaloneRootStore {
7
7
  private readonly tenantManagementApi;
8
8
  private readonly appConfigApi;
9
9
  private readonly currentUserClientApi;
10
+ private readonly onboardingApi;
11
+ private partitionsApi;
10
12
  loadStatus: LoadStatus;
11
13
  tenant: TenantModel;
12
14
  tenantConfigs: {
@@ -14,9 +16,39 @@ export declare class StandaloneRootStore extends Store {
14
16
  };
15
17
  user: UserDetails;
16
18
  appSettings: AppSettings;
19
+ onboarding: OnboardingResponse;
20
+ partitions: PartitionInfo[];
17
21
  timezone: string;
18
22
  locale: string;
19
- constructor(tenantManagementApi: TenantManagementApi, appConfigApi: AppConfigApi, currentUserClientApi: CurrentUserClientApi);
20
- initialize: () => Promise<void>;
23
+ private eventEmitter;
24
+ constructor(tenantManagementApi: TenantManagementApi, appConfigApi: AppConfigApi, currentUserClientApi: CurrentUserClientApi, onboardingApi: OnboardingApi, partitionsApi: PartitionsClientApi);
25
+ initialize: (forceRefresh: boolean, refreshOnboarding: boolean) => Promise<void>;
26
+ refreshTenant: () => Promise<void>;
27
+ refreshTenantConfigs: () => Promise<void>;
28
+ refreshUser: () => Promise<void>;
29
+ refreshAppSettings: () => Promise<void>;
30
+ refreshOnboarding: () => Promise<void>;
31
+ refreshPartitions: () => Promise<void>;
32
+ get defaultMFEData(): {
33
+ timezone: string;
34
+ partnerId: string | undefined;
35
+ partnerTenantId: string;
36
+ currentPartitionId: string | undefined;
37
+ featureFlagClientId: string;
38
+ };
39
+ unregisterGlobalSyncListener: () => void;
40
+ private initializeEventEmitter;
41
+ private registerGlobalSyncListener;
42
+ private listenGlobalSync;
43
+ private emitGlobalSync;
44
+ private syncFromStorage;
45
+ private setIsInitialized;
46
+ private get isInitialized();
47
+ private fetchTenant;
48
+ private fetchTenantConfigs;
49
+ private fetchUser;
50
+ private fetchAppSettings;
51
+ private fetchOnboarding;
52
+ private fetchPartitions;
21
53
  }
22
54
  //# sourceMappingURL=standalone-root.store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standalone-root.store.d.ts","sourceRoot":"","sources":["../../src/stores/standalone-root.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAClG,OAAO,EACH,YAAY,EACZ,WAAW,EACd,MAAM,qEAAqE,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAczD,qBACa,mBAAoB,SAAQ,KAAK;IAUT,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAX3D,UAAU,aAAmB;IAC7B,MAAM,EAAG,WAAW,CAAC;IACrB,aAAa,EAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC1C,IAAI,EAAG,WAAW,CAAC;IACnB,WAAW,EAAG,WAAW,CAAC;IAC1B,QAAQ,SAAS;IACjB,MAAM,SAAW;gBAGqB,mBAAmB,EAAE,mBAAmB,EAC/C,YAAY,EAAE,YAAY,EAClB,oBAAoB,EAAE,oBAAoB;IAM7F,UAAU,sBAgHR;CACL"}
1
+ {"version":3,"file":"standalone-root.store.d.ts","sourceRoot":"","sources":["../../src/stores/standalone-root.store.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACd,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EACH,YAAY,EACZ,WAAW,EACd,MAAM,qEAAqE,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,+C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CAAC,SAAS,CAQf;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,eAAe,CAQrB;IAEF,OAAO,CAAC,eAAe,CAUrB;CACL"}
@@ -10,24 +10,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
- import { inject, injectable, Store } from '@servicetitan/react-ioc';
14
13
  import { makeObservable, observable, runInAction } from 'mobx';
15
- import { TenantManagementApi, TenantModel } from '@servicetitan/standalone-tm-api';
16
- import { CurrentUserClientApi, UserDetails } from '@servicetitan/marketing-services-api/identity';
17
- import { AppConfigApi, } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
14
+ import { CurrentUserClientApi, PartitionsClientApi, UserDetails, } from '@servicetitan/marketing-services-api/identity';
18
15
  import { LoadStatus } from '@servicetitan/standalone-ui';
19
- const symbolKey = 'standalone-root-symbol-key';
20
- const isInitializedSymbol = Symbol.for(symbolKey);
21
- const storageKey = 'standalone-root-cache';
22
- const storageKeyForTenant = `${storageKey}-tenant`;
23
- const storageKeyForConfig = `${storageKey}-config`;
24
- const storageKeyForUser = `${storageKey}-user`;
25
- const storageKeyForAppSettings = `${storageKey}-app-settings`;
26
- const storageKeyForLocale = `${storageKey}-locale`;
27
- const cultureKeyInCoreConfigs = 'Customers___Locations:Culture';
28
- let StandaloneRootStore = class StandaloneRootStore extends Store {
29
- constructor(tenantManagementApi, appConfigApi, currentUserClientApi) {
30
- super();
16
+ import { inject, injectable } from '@servicetitan/react-ioc';
17
+ import { AppConfigApi, } from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
18
+ import { TenantManagementApi, TenantModel } from '@servicetitan/standalone-tm-api';
19
+ import { OnboardingApi } from '@servicetitan/marketing-services-api/settings';
20
+ import { Events } from '../utils/events';
21
+ import { EventEmitter } from '../utils/event-emitter';
22
+ import { storageKeyForUser, storageKeyForLocale, storageKeyForTenant, storageKeyForOnboarding, storageKeyForPartitions, storageKeyForAppSettings, storageKeyForTenantConfigs, } from '../utils/storage-keys';
23
+ import { cultureKeyInCoreConfigs, defaultLocale, defaultTimezone } from '../utils/constants';
24
+ import { currentInstanceSymbol, eventEmitterSymbol, isInitializedSymbol } from '../utils/symbols';
25
+ let StandaloneRootStore = class StandaloneRootStore {
26
+ constructor(tenantManagementApi, appConfigApi, currentUserClientApi, onboardingApi, partitionsApi) {
31
27
  Object.defineProperty(this, "tenantManagementApi", {
32
28
  enumerable: true,
33
29
  configurable: true,
@@ -46,6 +42,18 @@ let StandaloneRootStore = class StandaloneRootStore extends Store {
46
42
  writable: true,
47
43
  value: currentUserClientApi
48
44
  });
45
+ Object.defineProperty(this, "onboardingApi", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: onboardingApi
50
+ });
51
+ Object.defineProperty(this, "partitionsApi", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: partitionsApi
56
+ });
49
57
  Object.defineProperty(this, "loadStatus", {
50
58
  enumerable: true,
51
59
  configurable: true,
@@ -76,46 +84,56 @@ let StandaloneRootStore = class StandaloneRootStore extends Store {
76
84
  writable: true,
77
85
  value: void 0
78
86
  });
87
+ Object.defineProperty(this, "onboarding", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ Object.defineProperty(this, "partitions", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
79
99
  Object.defineProperty(this, "timezone", {
80
100
  enumerable: true,
81
101
  configurable: true,
82
102
  writable: true,
83
- value: 'UTC'
103
+ value: defaultTimezone
84
104
  });
85
105
  Object.defineProperty(this, "locale", {
86
106
  enumerable: true,
87
107
  configurable: true,
88
108
  writable: true,
89
- value: 'en-US'
109
+ value: defaultLocale
110
+ });
111
+ Object.defineProperty(this, "eventEmitter", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: void 0
90
116
  });
91
117
  Object.defineProperty(this, "initialize", {
92
118
  enumerable: true,
93
119
  configurable: true,
94
120
  writable: true,
95
- value: async () => {
121
+ value: async (forceRefresh, refreshOnboarding) => {
96
122
  try {
97
123
  runInAction(() => {
98
124
  this.loadStatus = LoadStatus.Loading;
99
125
  });
100
- const fetchData = async () => {
101
- const [tenantFetched, tenantConfigFetched, { data: userFetched }, { data: appSettingsFetched },] = await Promise.all([
102
- this.tenantManagementApi.client.tenant(undefined),
103
- this.tenantManagementApi.client.config(undefined, undefined, undefined, undefined),
104
- this.currentUserClientApi.getUserName(),
105
- this.appConfigApi.getAppSettings(),
126
+ const fetchAll = async () => {
127
+ await Promise.all([
128
+ this.fetchTenant(),
129
+ this.fetchTenantConfigs(),
130
+ this.fetchUser(),
131
+ this.fetchAppSettings(),
132
+ this.fetchOnboarding(),
133
+ this.fetchPartitions(),
106
134
  ]);
107
- const coreConfigs = await this.tenantManagementApi.client.configs2(tenantFetched.id, tenantFetched.id, undefined, [cultureKeyInCoreConfigs]);
135
+ const coreConfigs = await this.tenantManagementApi.client.configs2(this.tenant.id, this.tenant.id, undefined, [cultureKeyInCoreConfigs]);
108
136
  const localeFetched = coreConfigs[cultureKeyInCoreConfigs];
109
- localStorage.setItem(storageKeyForTenant, JSON.stringify(tenantFetched));
110
- localStorage.setItem(storageKeyForConfig, JSON.stringify(tenantConfigFetched));
111
- localStorage.setItem(storageKeyForUser, JSON.stringify(userFetched));
112
- localStorage.setItem(storageKeyForAppSettings, JSON.stringify(appSettingsFetched));
113
- runInAction(() => {
114
- this.tenant = tenantFetched;
115
- this.tenantConfigs = tenantConfigFetched;
116
- this.user = userFetched;
117
- this.appSettings = appSettingsFetched;
118
- });
119
137
  if (localeFetched) {
120
138
  localStorage.setItem(storageKeyForLocale, JSON.stringify(localeFetched));
121
139
  runInAction(() => {
@@ -127,37 +145,20 @@ let StandaloneRootStore = class StandaloneRootStore extends Store {
127
145
  }
128
146
  };
129
147
  // checks if the root is initialized first time across the app
130
- if (window[isInitializedSymbol]) {
131
- const tenantCached = localStorage.getItem(storageKeyForTenant);
132
- const tenantConfigsCached = localStorage.getItem(storageKeyForConfig);
133
- const userCached = localStorage.getItem(storageKeyForUser);
134
- const appSettingsCached = localStorage.getItem(storageKeyForAppSettings);
135
- const localeCached = localStorage.getItem(storageKeyForLocale);
136
- if (tenantCached &&
137
- tenantConfigsCached &&
138
- userCached &&
139
- appSettingsCached &&
140
- localeCached) {
141
- const tenantCachedParsed = JSON.parse(tenantCached);
142
- const tenantConfigsCachedParsed = JSON.parse(tenantConfigsCached);
143
- const userCachedParsed = JSON.parse(userCached);
144
- const appSettingsCachedParsed = JSON.parse(appSettingsCached);
145
- const localeCachedParsed = JSON.parse(localeCached);
146
- runInAction(() => {
147
- this.tenant = tenantCachedParsed;
148
- this.tenantConfigs = tenantConfigsCachedParsed;
149
- this.user = userCachedParsed;
150
- this.appSettings = appSettingsCachedParsed;
151
- this.locale = localeCachedParsed;
152
- });
148
+ if (this.isInitialized && !forceRefresh) {
149
+ const isSuccess = this.syncFromStorage();
150
+ if (isSuccess) {
151
+ if (refreshOnboarding) {
152
+ await this.fetchOnboarding();
153
+ }
153
154
  }
154
155
  else {
155
- await fetchData();
156
+ await fetchAll();
156
157
  }
157
158
  }
158
159
  else {
159
- await fetchData();
160
- window[isInitializedSymbol] = true;
160
+ await fetchAll();
161
+ this.setIsInitialized(true);
161
162
  }
162
163
  const timezoneFetched = this.tenantConfigs.TimeZone;
163
164
  if (timezoneFetched) {
@@ -168,6 +169,7 @@ let StandaloneRootStore = class StandaloneRootStore extends Store {
168
169
  runInAction(() => {
169
170
  this.loadStatus = LoadStatus.Ok;
170
171
  });
172
+ this.registerGlobalSyncListener();
171
173
  }
172
174
  catch (_a) {
173
175
  runInAction(() => {
@@ -176,8 +178,228 @@ let StandaloneRootStore = class StandaloneRootStore extends Store {
176
178
  }
177
179
  }
178
180
  });
181
+ Object.defineProperty(this, "refreshTenant", {
182
+ enumerable: true,
183
+ configurable: true,
184
+ writable: true,
185
+ value: () => this.fetchTenant().then(this.emitGlobalSync)
186
+ });
187
+ Object.defineProperty(this, "refreshTenantConfigs", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: () => this.fetchTenantConfigs().then(this.emitGlobalSync)
192
+ });
193
+ Object.defineProperty(this, "refreshUser", {
194
+ enumerable: true,
195
+ configurable: true,
196
+ writable: true,
197
+ value: () => this.fetchUser().then(this.emitGlobalSync)
198
+ });
199
+ Object.defineProperty(this, "refreshAppSettings", {
200
+ enumerable: true,
201
+ configurable: true,
202
+ writable: true,
203
+ value: () => this.fetchAppSettings().then(this.emitGlobalSync)
204
+ });
205
+ Object.defineProperty(this, "refreshOnboarding", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: () => this.fetchOnboarding().then(this.emitGlobalSync)
210
+ });
211
+ Object.defineProperty(this, "refreshPartitions", {
212
+ enumerable: true,
213
+ configurable: true,
214
+ writable: true,
215
+ value: () => this.fetchPartitions().then(this.emitGlobalSync)
216
+ });
217
+ Object.defineProperty(this, "unregisterGlobalSyncListener", {
218
+ enumerable: true,
219
+ configurable: true,
220
+ writable: true,
221
+ value: () => {
222
+ this.eventEmitter.off(Events.SyncFromStorage, this.listenGlobalSync);
223
+ }
224
+ });
225
+ Object.defineProperty(this, "initializeEventEmitter", {
226
+ enumerable: true,
227
+ configurable: true,
228
+ writable: true,
229
+ value: () => {
230
+ const globalEventEmitter = window[eventEmitterSymbol];
231
+ if (globalEventEmitter) {
232
+ this.eventEmitter = globalEventEmitter;
233
+ }
234
+ else {
235
+ window[eventEmitterSymbol] = new EventEmitter();
236
+ this.eventEmitter = window[eventEmitterSymbol];
237
+ }
238
+ }
239
+ });
240
+ Object.defineProperty(this, "registerGlobalSyncListener", {
241
+ enumerable: true,
242
+ configurable: true,
243
+ writable: true,
244
+ value: () => {
245
+ this.eventEmitter.on(Events.SyncFromStorage, this.listenGlobalSync);
246
+ }
247
+ });
248
+ Object.defineProperty(this, "listenGlobalSync", {
249
+ enumerable: true,
250
+ configurable: true,
251
+ writable: true,
252
+ value: (instanceSymbol) => {
253
+ if (instanceSymbol !== currentInstanceSymbol) {
254
+ this.syncFromStorage();
255
+ }
256
+ }
257
+ });
258
+ Object.defineProperty(this, "emitGlobalSync", {
259
+ enumerable: true,
260
+ configurable: true,
261
+ writable: true,
262
+ value: () => {
263
+ this.eventEmitter.emit(Events.SyncFromStorage, currentInstanceSymbol);
264
+ }
265
+ });
266
+ Object.defineProperty(this, "syncFromStorage", {
267
+ enumerable: true,
268
+ configurable: true,
269
+ writable: true,
270
+ value: () => {
271
+ const tenantCached = localStorage.getItem(storageKeyForTenant);
272
+ const tenantConfigsCached = localStorage.getItem(storageKeyForTenantConfigs);
273
+ const userCached = localStorage.getItem(storageKeyForUser);
274
+ const appSettingsCached = localStorage.getItem(storageKeyForAppSettings);
275
+ const onboardingCached = localStorage.getItem(storageKeyForOnboarding);
276
+ const partitionsCached = localStorage.getItem(storageKeyForPartitions);
277
+ const localeCached = localStorage.getItem(storageKeyForLocale);
278
+ if (tenantCached &&
279
+ tenantConfigsCached &&
280
+ userCached &&
281
+ appSettingsCached &&
282
+ onboardingCached &&
283
+ partitionsCached &&
284
+ localeCached) {
285
+ const tenantCachedParsed = JSON.parse(tenantCached);
286
+ const tenantConfigsCachedParsed = JSON.parse(tenantConfigsCached);
287
+ const userCachedParsed = JSON.parse(userCached);
288
+ const appSettingsCachedParsed = JSON.parse(appSettingsCached);
289
+ const onboardingCachedParsed = JSON.parse(onboardingCached);
290
+ const partitionsCachedParsed = JSON.parse(partitionsCached);
291
+ const localeCachedParsed = JSON.parse(localeCached);
292
+ runInAction(() => {
293
+ this.tenant = tenantCachedParsed;
294
+ this.tenantConfigs = tenantConfigsCachedParsed;
295
+ this.user = userCachedParsed;
296
+ this.appSettings = appSettingsCachedParsed;
297
+ this.onboarding = onboardingCachedParsed;
298
+ this.partitions = partitionsCachedParsed;
299
+ this.locale = localeCachedParsed;
300
+ });
301
+ return true;
302
+ }
303
+ return false;
304
+ }
305
+ });
306
+ Object.defineProperty(this, "setIsInitialized", {
307
+ enumerable: true,
308
+ configurable: true,
309
+ writable: true,
310
+ value: (value) => {
311
+ window[isInitializedSymbol] = value;
312
+ }
313
+ });
314
+ Object.defineProperty(this, "fetchTenant", {
315
+ enumerable: true,
316
+ configurable: true,
317
+ writable: true,
318
+ value: async () => {
319
+ const tenantFetched = await this.tenantManagementApi.client.tenant(undefined);
320
+ localStorage.setItem(storageKeyForTenant, JSON.stringify(tenantFetched));
321
+ runInAction(() => {
322
+ this.tenant = tenantFetched;
323
+ });
324
+ }
325
+ });
326
+ Object.defineProperty(this, "fetchTenantConfigs", {
327
+ enumerable: true,
328
+ configurable: true,
329
+ writable: true,
330
+ value: async () => {
331
+ const tenantConfigsFetched = await this.tenantManagementApi.client.config(undefined, undefined, undefined, undefined);
332
+ localStorage.setItem(storageKeyForTenantConfigs, JSON.stringify(tenantConfigsFetched));
333
+ runInAction(() => {
334
+ this.tenantConfigs = tenantConfigsFetched;
335
+ });
336
+ }
337
+ });
338
+ Object.defineProperty(this, "fetchUser", {
339
+ enumerable: true,
340
+ configurable: true,
341
+ writable: true,
342
+ value: async () => {
343
+ const { data: userFetched } = await this.currentUserClientApi.getUserName();
344
+ localStorage.setItem(storageKeyForUser, JSON.stringify(userFetched));
345
+ runInAction(() => {
346
+ this.user = userFetched;
347
+ });
348
+ }
349
+ });
350
+ Object.defineProperty(this, "fetchAppSettings", {
351
+ enumerable: true,
352
+ configurable: true,
353
+ writable: true,
354
+ value: async () => {
355
+ const { data: appSettingsFetched } = await this.appConfigApi.getAppSettings();
356
+ localStorage.setItem(storageKeyForAppSettings, JSON.stringify(appSettingsFetched));
357
+ runInAction(() => {
358
+ this.appSettings = appSettingsFetched;
359
+ });
360
+ }
361
+ });
362
+ Object.defineProperty(this, "fetchOnboarding", {
363
+ enumerable: true,
364
+ configurable: true,
365
+ writable: true,
366
+ value: async () => {
367
+ const { data: onboardingFetched } = await this.onboardingApi.getStatus();
368
+ localStorage.setItem(storageKeyForOnboarding, JSON.stringify(onboardingFetched));
369
+ runInAction(() => {
370
+ this.onboarding = onboardingFetched;
371
+ });
372
+ }
373
+ });
374
+ Object.defineProperty(this, "fetchPartitions", {
375
+ enumerable: true,
376
+ configurable: true,
377
+ writable: true,
378
+ value: async () => {
379
+ const { data: partitionsFetchedUnfiltered } = await this.partitionsApi.userAssignedPartitions();
380
+ const partitionsFetched = partitionsFetchedUnfiltered.filter(Boolean);
381
+ localStorage.setItem(storageKeyForPartitions, JSON.stringify(partitionsFetched));
382
+ runInAction(() => {
383
+ this.partitions = partitionsFetched;
384
+ });
385
+ }
386
+ });
387
+ this.initializeEventEmitter();
179
388
  makeObservable(this);
180
389
  }
390
+ get defaultMFEData() {
391
+ const { tenant, appSettings, timezone } = this;
392
+ return {
393
+ timezone,
394
+ partnerId: tenant.parentId,
395
+ partnerTenantId: tenant.externalId,
396
+ currentPartitionId: tenant.currentPartitionId,
397
+ featureFlagClientId: appSettings.featureFlagClientId,
398
+ };
399
+ }
400
+ get isInitialized() {
401
+ return !!window[isInitializedSymbol];
402
+ }
181
403
  };
182
404
  __decorate([
183
405
  observable,
@@ -199,6 +421,14 @@ __decorate([
199
421
  observable,
200
422
  __metadata("design:type", Object)
201
423
  ], StandaloneRootStore.prototype, "appSettings", void 0);
424
+ __decorate([
425
+ observable,
426
+ __metadata("design:type", Object)
427
+ ], StandaloneRootStore.prototype, "onboarding", void 0);
428
+ __decorate([
429
+ observable,
430
+ __metadata("design:type", Array)
431
+ ], StandaloneRootStore.prototype, "partitions", void 0);
202
432
  __decorate([
203
433
  observable,
204
434
  __metadata("design:type", Object)
@@ -212,9 +442,13 @@ StandaloneRootStore = __decorate([
212
442
  __param(0, inject(TenantManagementApi)),
213
443
  __param(1, inject(AppConfigApi)),
214
444
  __param(2, inject(CurrentUserClientApi)),
445
+ __param(3, inject(OnboardingApi)),
446
+ __param(4, inject(PartitionsClientApi)),
215
447
  __metadata("design:paramtypes", [TenantManagementApi,
216
448
  AppConfigApi,
217
- CurrentUserClientApi])
449
+ CurrentUserClientApi,
450
+ OnboardingApi,
451
+ PartitionsClientApi])
218
452
  ], StandaloneRootStore);
219
453
  export { StandaloneRootStore };
220
454
  //# sourceMappingURL=standalone-root.store.js.map