@dative-gpi/foundation-shared-services 0.0.9 → 0.0.11

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.
@@ -20,10 +20,16 @@ const ApplicationServiceFactory = new ServiceFactory<ApplicationDetailsDTO, Appl
20
20
 
21
21
  export const useCurrentApplication = () => {
22
22
  const service = ApplicationServiceFactory();
23
+ const subscribersIds: number[] = [];
23
24
 
24
25
  const fetching = ref(false);
25
26
  const fetched = ref<ApplicationDetails | null>(null) as Ref<ApplicationDetails | null>;
26
27
 
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
27
33
  const fetch = async () => {
28
34
  fetching.value = true;
29
35
  try {
@@ -32,10 +38,7 @@ export const useCurrentApplication = () => {
32
38
  finally {
33
39
  fetching.value = false;
34
40
  }
35
-
36
- const subscriberId = service.subscribe("all", onEntityChanged(fetched));
37
- onUnmounted(() => service.unsubscribe(subscriberId));
38
-
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
39
42
  return readonly(fetched as Ref<ApplicationDetails>);
40
43
  }
41
44
 
@@ -1,4 +1,4 @@
1
- import { AuthTokenDetails, AuthTokenDetailsDTO, CreateAuthTokenDTO } from "@dative-gpi/foundation-core-domain";
1
+ import { AuthTokenDetails, AuthTokenDetailsDTO, CreateAuthTokenDTO } from "@dative-gpi/foundation-shared-domain";
2
2
  import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
3
 
4
4
  import { AUTH_TOKENS_URL } from "../../config/urls";
@@ -20,10 +20,16 @@ const LandingPageServiceFactory = new ServiceFactory<LandingPageDetailsDTO, Land
20
20
 
21
21
  export const useCurrentLandingPage = () => {
22
22
  const service = LandingPageServiceFactory();
23
+ const subscribersIds: number[] = [];
23
24
 
24
25
  const fetching = ref(false);
25
26
  const fetched = ref<LandingPageDetails | null>(null) as Ref<LandingPageDetails | null>;
26
27
 
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
27
33
  const fetch = async () => {
28
34
  fetching.value = true;
29
35
  try {
@@ -32,10 +38,7 @@ export const useCurrentLandingPage = () => {
32
38
  finally {
33
39
  fetching.value = false;
34
40
  }
35
-
36
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
37
- onUnmounted(() => service.unsubscribe(subscriberId));
38
-
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
39
42
  return readonly(fetched as Ref<LandingPageDetails>);
40
43
  }
41
44
 
@@ -20,10 +20,16 @@ const LayoutPageServiceFactory = new ServiceFactory<LayoutPageDetailsDTO, Layout
20
20
 
21
21
  export const useCurrentLayoutPage = () => {
22
22
  const service = LayoutPageServiceFactory();
23
+ const subscribersIds: number[] = [];
23
24
 
24
25
  const fetching = ref(false);
25
26
  const fetched = ref<LayoutPageDetails | null>(null) as Ref<LayoutPageDetails | null>;
26
27
 
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
27
33
  const fetch = async () => {
28
34
  fetching.value = true;
29
35
  try {
@@ -32,10 +38,7 @@ export const useCurrentLayoutPage = () => {
32
38
  finally {
33
39
  fetching.value = false;
34
40
  }
35
-
36
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
37
- onUnmounted(() => service.unsubscribe(subscriberId));
38
-
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
39
42
  return readonly(fetched as Ref<LayoutPageDetails>);
40
43
  }
41
44
 
@@ -20,10 +20,16 @@ const LegalInformationServiceFactory = new ServiceFactory<LegalInformationDetail
20
20
 
21
21
  export const useCurrentLegalInformation = () => {
22
22
  const service = LegalInformationServiceFactory();
23
+ const subscribersIds: number[] = [];
23
24
 
24
25
  const fetching = ref(false);
25
26
  const fetched = ref<LegalInformationDetails | null>(null) as Ref<LegalInformationDetails | null>;
26
27
 
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
27
33
  const fetch = async () => {
28
34
  fetching.value = true;
29
35
  try {
@@ -32,10 +38,7 @@ export const useCurrentLegalInformation = () => {
32
38
  finally {
33
39
  fetching.value = false;
34
40
  }
35
-
36
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
37
- onUnmounted(() => service.unsubscribe(subscriberId));
38
-
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
39
42
  return readonly(fetched as Ref<LegalInformationDetails>);
40
43
  }
41
44
 
@@ -20,10 +20,16 @@ const SecuritySettingServiceFactory = new ServiceFactory<SecuritySettingDetailsD
20
20
 
21
21
  export const useCurrentSecuritySettings = () => {
22
22
  const service = SecuritySettingServiceFactory();
23
+ const subscribersIds: number[] = [];
23
24
 
24
25
  const fetching = ref(false);
25
26
  const fetched = ref<SecuritySettingDetails | null>(null) as Ref<SecuritySettingDetails | null>;
26
27
 
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
27
33
  const fetch = async () => {
28
34
  fetching.value = true;
29
35
  try {
@@ -32,10 +38,7 @@ export const useCurrentSecuritySettings = () => {
32
38
  finally {
33
39
  fetching.value = false;
34
40
  }
35
-
36
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
37
- onUnmounted(() => service.unsubscribe(subscriberId));
38
-
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
39
42
  return readonly(fetched as Ref<SecuritySettingDetails>);
40
43
  }
41
44
 
@@ -22,10 +22,16 @@ const UserLegalInformationServiceFactory = new ServiceFactory<UserLegalInformati
22
22
  export const useCreateUserLegalInformation = ComposableFactory.create(UserLegalInformationServiceFactory);
23
23
  export const useCurrentUserLegalInformation = () => {
24
24
  const service = UserLegalInformationServiceFactory();
25
+ const subscribersIds: number[] = [];
25
26
 
26
27
  const fetching = ref(false);
27
28
  const fetched = ref<UserLegalInformationDetails | null>(null) as Ref<UserLegalInformationDetails | null>;
28
29
 
30
+ onUnmounted(() => {
31
+ subscribersIds.forEach(id => service.unsubscribe(id));
32
+ subscribersIds.length = 0;
33
+ });
34
+
29
35
  const fetch = async () => {
30
36
  fetching.value = true;
31
37
  try {
@@ -34,10 +40,7 @@ export const useCurrentUserLegalInformation = () => {
34
40
  finally {
35
41
  fetching.value = false;
36
42
  }
37
-
38
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
39
- onUnmounted(() => service.unsubscribe(subscriberId));
40
-
43
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
41
44
  return readonly(fetched as Ref<UserLegalInformationDetails>);
42
45
  }
43
46
 
@@ -28,10 +28,16 @@ const UserServiceFactory = new ServiceFactory<UserDetailsDTO, UserDetails>("user
28
28
 
29
29
  export const useCurrentUser = () => {
30
30
  const service = UserServiceFactory();
31
+ const subscribersIds: number[] = [];
31
32
 
32
33
  const fetching = ref(false);
33
34
  const fetched = ref<UserDetails | null>(null) as Ref<UserDetails | null>;
34
35
 
36
+ onUnmounted(() => {
37
+ subscribersIds.forEach(id => service.unsubscribe(id));
38
+ subscribersIds.length = 0;
39
+ });
40
+
35
41
  const fetch = async () => {
36
42
  fetching.value = true;
37
43
  try {
@@ -40,10 +46,7 @@ export const useCurrentUser = () => {
40
46
  finally {
41
47
  fetching.value = false;
42
48
  }
43
-
44
- const subscriberId = service.subscribe("all", onEntityChanged(fetched))
45
- onUnmounted(() => service.unsubscribe(subscriberId));
46
-
49
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
47
50
  return readonly(fetched as Ref<UserDetails>);
48
51
  }
49
52
 
@@ -55,10 +58,16 @@ export const useCurrentUser = () => {
55
58
  }
56
59
  export const useUpdateCurrentUser = () => {
57
60
  const service = UserServiceFactory();
61
+ const subscribersIds: number[] = [];
58
62
 
59
63
  const updating = ref(false);
60
64
  const updated = ref<UserDetails | null>(null) as Ref<UserDetails | null>;
61
65
 
66
+ onUnmounted(() => {
67
+ subscribersIds.forEach(id => service.unsubscribe(id));
68
+ subscribersIds.length = 0;
69
+ });
70
+
62
71
  const update = async (payload: UpdateUserDTO) => {
63
72
  updating.value = true;
64
73
  try {
@@ -67,10 +76,7 @@ export const useUpdateCurrentUser = () => {
67
76
  finally {
68
77
  updating.value = false;
69
78
  }
70
-
71
- const subscriberId = service.subscribe("all", onEntityChanged(updated))
72
- onUnmounted(() => service.unsubscribe(subscriberId));
73
-
79
+ subscribersIds.push(service.subscribe("all", onEntityChanged(updated)));
74
80
  return readonly(updated as Ref<UserDetails>);
75
81
  }
76
82
 
@@ -1,8 +1,4 @@
1
- import { provide, ref, watch } from "vue";
2
-
3
- import { LANGUAGE_CODE } from "../config/literals";
4
-
5
- let initialized = false;
1
+ import { ref, watch } from "vue";
6
2
 
7
3
  const languageCode = ref<string | null>("fr-FR");
8
4
 
@@ -11,12 +7,6 @@ export const useLanguageCode = () => {
11
7
  languageCode.value = payload;
12
8
  };
13
9
 
14
- if (!initialized) {
15
- provide(LANGUAGE_CODE, languageCode);
16
- }
17
-
18
- initialized = true;
19
-
20
10
  const ready = new Promise((resolve) => {
21
11
  if (languageCode.value) {
22
12
  resolve(languageCode.value);
@@ -1,4 +1,4 @@
1
- import { onMounted, provide, ref, watch } from "vue";
1
+ import { ref, watch } from "vue";
2
2
 
3
3
  import { enUS, enGB, fr, it, es, de, Locale } from "date-fns/locale";
4
4
  import { format, subDays } from "date-fns";
@@ -7,9 +7,6 @@ import { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
7
7
 
8
8
  import { useTranslationsProvider } from "./useTranslationsProvider";
9
9
  import { useLanguageCode } from "./useLanguageCode";
10
- import { TIME_ZONE } from "../config/literals";
11
-
12
- let initialized = false;
13
10
 
14
11
  const timeZone = ref<TimeZoneInfos | null>({
15
12
  id: "Europe/Paris",
@@ -17,9 +14,6 @@ const timeZone = ref<TimeZoneInfos | null>({
17
14
  });
18
15
 
19
16
  export const useTimeZone = () => {
20
- const { languageCode } = useLanguageCode();
21
- const { $tr } = useTranslationsProvider();
22
-
23
17
  const setTimeZone = (payload: TimeZoneInfos) => {
24
18
  timeZone.value = payload;
25
19
  };
@@ -151,11 +145,11 @@ export const useTimeZone = () => {
151
145
  };
152
146
 
153
147
  const todayTimeFormat = (): string => {
154
- return `'${$tr("ui.time-zone.today-at", "Today at")?.replaceAll("'", "''")}' HH:mm:ss`;
148
+ return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replaceAll("'", "''")}' HH:mm:ss`;
155
149
  }
156
150
 
157
151
  const yesterdayTimeFormat = (): string => {
158
- return `'${$tr("ui.time-zone.yesterday-at", "Yesterday at")?.replaceAll("'", "''")}' HH:mm:ss`;
152
+ return `'${useTranslationsProvider().$tr("ui.time-zone.yesterday-at", "Yesterday at").replaceAll("'", "''")}' HH:mm:ss`;
159
153
  }
160
154
 
161
155
  const overrideFormat = (date: Date, askedFormat: string): string => {
@@ -170,7 +164,7 @@ export const useTimeZone = () => {
170
164
  }
171
165
 
172
166
  const getLocale = (): Locale => {
173
- switch (languageCode.value) {
167
+ switch (useLanguageCode().languageCode.value) {
174
168
  case "fr-FR": return fr;
175
169
  case "es-ES": return es;
176
170
  case "it-IT": return it;
@@ -180,24 +174,6 @@ export const useTimeZone = () => {
180
174
  }
181
175
  }
182
176
 
183
- if (!initialized) {
184
- provide(TIME_ZONE, timeZone);
185
-
186
- onMounted(() => {
187
- if (timeZone.value) {
188
- return;
189
- }
190
- else {
191
- setTimeZone(new TimeZoneInfos({
192
- id: Intl.DateTimeFormat().resolvedOptions().timeZone,
193
- offset: getMachineOffset()
194
- }));
195
- }
196
- });
197
- }
198
-
199
- initialized = true;
200
-
201
177
  const ready = new Promise((resolve) => {
202
178
  if (timeZone.value) {
203
179
  resolve(timeZone.value);
@@ -1,13 +1,10 @@
1
1
  import { useLanguageCode, useTranslations } from "@dative-gpi/foundation-shared-services";
2
2
 
3
- const { fetch, fetched } = useTranslations()
4
- const { ready, languageCode } = useLanguageCode();
5
-
6
3
  let initialized = false;
7
4
 
8
5
  export const useTranslationsProvider = () => {
9
6
  const $tr = (code: string, defaultValue: string, ...parameters: string[]): string => {
10
- let translation = fetched.value.find(t => t.code === code)?.value ?? defaultValue;
7
+ let translation = useTranslations().fetched.value.find(t => t.code === code)?.value ?? defaultValue;
11
8
  if (translation && parameters.length) {
12
9
  for (let p of parameters) {
13
10
  translation = translation.replace(`{${parameters.indexOf(p)}}`, p.toString());
@@ -19,8 +16,8 @@ export const useTranslationsProvider = () => {
19
16
  const init = async () => {
20
17
  if (!initialized) {
21
18
  initialized = true;
22
- await ready;
23
- await fetch(languageCode.value!);
19
+ await useLanguageCode().ready;
20
+ await useTranslations().fetch(useLanguageCode().languageCode.value!);
24
21
  }
25
22
  }
26
23
 
package/config/index.ts CHANGED
@@ -1,2 +1 @@
1
- export * from "./literals";
2
1
  export * from "./urls";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,12 +9,12 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@dative-gpi/bones-ui": "^0.0.58",
13
- "@dative-gpi/foundation-shared-domain": "0.0.9",
12
+ "@dative-gpi/bones-ui": "^0.0.60",
13
+ "@dative-gpi/foundation-shared-domain": "0.0.11",
14
14
  "@microsoft/signalr": "^8.0.0",
15
15
  "date-fns": "^3.2.0",
16
16
  "vue": "^3.2.0",
17
17
  "vue-router": "^4.2.5"
18
18
  },
19
- "gitHead": "d079d93c7d8677f8269b97bc71820bc35dc46921"
19
+ "gitHead": "4f28939e7d42ab1ef8319c614fbc210b1291fd79"
20
20
  }
@@ -1,2 +0,0 @@
1
- export const TIME_ZONE = "timeZone";
2
- export const LANGUAGE_CODE = "languageCode";