@dative-gpi/foundation-shared-services 0.0.8 → 0.0.10

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 (41) hide show
  1. package/composables/index.ts +4 -1
  2. package/composables/services/index.ts +13 -0
  3. package/composables/services/useApplications.ts +50 -0
  4. package/composables/services/useAuthTokens.ts +11 -0
  5. package/composables/services/useFrequentlyAskedQuestions.ts +11 -0
  6. package/composables/services/useImages.ts +71 -0
  7. package/composables/services/useLandingPages.ts +50 -0
  8. package/composables/services/useLayoutPages.ts +50 -0
  9. package/composables/services/useLegalInformations.ts +50 -0
  10. package/composables/services/useOrganisations.ts +17 -0
  11. package/composables/services/useSecuritySettings.ts +50 -0
  12. package/composables/services/useTimeZones.ts +11 -0
  13. package/composables/services/useTranslations.ts +42 -0
  14. package/composables/services/useUserLegalInformations.ts +52 -0
  15. package/composables/services/useUsers.ts +88 -0
  16. package/composables/useLanguageCode.ts +1 -17
  17. package/composables/useShared.ts +32 -0
  18. package/composables/useTimeZone.ts +117 -19
  19. package/composables/useTranslationsProvider.ts +28 -0
  20. package/config/index.ts +1 -1
  21. package/config/urls/applications.ts +4 -0
  22. package/config/urls/authTokens.ts +3 -0
  23. package/config/urls/base.ts +1 -0
  24. package/config/urls/files.ts +4 -0
  25. package/config/urls/frequentlyAskedQuestions.ts +3 -0
  26. package/config/urls/images.ts +12 -0
  27. package/config/urls/index.ts +14 -0
  28. package/config/urls/landingPages.ts +4 -0
  29. package/config/urls/layoutPages.ts +4 -0
  30. package/config/urls/legalInformations.ts +4 -0
  31. package/config/urls/organisations.ts +4 -0
  32. package/config/urls/securitySettings.ts +4 -0
  33. package/config/urls/timeZones.ts +3 -0
  34. package/config/urls/translations.ts +4 -0
  35. package/config/urls/userLegalInformations.ts +4 -0
  36. package/config/urls/users.ts +4 -0
  37. package/index.ts +1 -0
  38. package/package.json +5 -4
  39. package/tools/datesTools.ts +15 -0
  40. package/tools/index.ts +1 -0
  41. package/config/literals/index.ts +0 -2
@@ -1,2 +1,5 @@
1
+ export * from "./services";
1
2
  export * from "./useLanguageCode";
2
- export * from "./useTimeZone";
3
+ export * from "./useShared";
4
+ export * from "./useTimeZone";
5
+ export * from "./useTranslationsProvider";
@@ -0,0 +1,13 @@
1
+ export * from "./useApplications";
2
+ export * from "./useAuthTokens";
3
+ export * from "./useFrequentlyAskedQuestions";
4
+ export * from "./useImages";
5
+ export * from "./useLandingPages";
6
+ export * from "./useLayoutPages";
7
+ export * from "./useLegalInformations";
8
+ export * from "./useOrganisations";
9
+ export * from "./useSecuritySettings";
10
+ export * from "./useTimeZones";
11
+ export * from "./useTranslations";
12
+ export * from "./useUserLegalInformations";
13
+ export * from "./useUsers";
@@ -0,0 +1,50 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { ApplicationDetails, ApplicationDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { APPLICATION_CURRENT_URL } from "../../config/urls";
7
+
8
+ const ApplicationServiceFactory = new ServiceFactory<ApplicationDetailsDTO, ApplicationDetails>("application", ApplicationDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<ApplicationDetails> => {
11
+ const response = await ServiceFactory.http.get(APPLICATION_CURRENT_URL());
12
+ const result = new ApplicationDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ }
18
+ }))
19
+ ));
20
+
21
+ export const useCurrentApplication = () => {
22
+ const service = ApplicationServiceFactory();
23
+ const subscribersIds: number[] = [];
24
+
25
+ const fetching = ref(false);
26
+ const fetched = ref<ApplicationDetails | null>(null) as Ref<ApplicationDetails | null>;
27
+
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
33
+ const fetch = async () => {
34
+ fetching.value = true;
35
+ try {
36
+ fetched.value = await service.getCurrent();
37
+ }
38
+ finally {
39
+ fetching.value = false;
40
+ }
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
42
+ return readonly(fetched as Ref<ApplicationDetails>);
43
+ }
44
+
45
+ return {
46
+ fetching: readonly(fetching),
47
+ fetch,
48
+ fetched: readonly(fetched)
49
+ }
50
+ }
@@ -0,0 +1,11 @@
1
+ import { AuthTokenDetails, AuthTokenDetailsDTO, CreateAuthTokenDTO } from "@dative-gpi/foundation-shared-domain";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
+
4
+ import { AUTH_TOKENS_URL } from "../../config/urls";
5
+
6
+ const AuthTokenServiceFactory = new ServiceFactory<AuthTokenDetailsDTO, AuthTokenDetails>("authToken", AuthTokenDetails).create(factory => factory.build(
7
+ factory.addCreate<CreateAuthTokenDTO>(AUTH_TOKENS_URL),
8
+ factory.addNotify()
9
+ ));
10
+
11
+ export const useCreateAuthToken = ComposableFactory.create(AuthTokenServiceFactory);
@@ -0,0 +1,11 @@
1
+ import { FrequentlyAskedQuestionDetails, FrequentlyAskedQuestionDetailsDTO, FrequentlyAskedQuestionFilters, FrequentlyAskedQuestionInfos, FrequentlyAskedQuestionInfosDTO } from "@dative-gpi/foundation-shared-domain";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
+
4
+ import { FREQUENTLY_ASKED_QUESTIONS_URL } from "../../config/urls";
5
+
6
+ const FrequentlyAskedQuestionServiceFactory = new ServiceFactory<FrequentlyAskedQuestionDetailsDTO, FrequentlyAskedQuestionDetails>("frequentlyAskedQuestions", FrequentlyAskedQuestionDetails).create(factory => factory.build(
7
+ factory.addGetMany<FrequentlyAskedQuestionInfosDTO, FrequentlyAskedQuestionInfos, FrequentlyAskedQuestionFilters>(FREQUENTLY_ASKED_QUESTIONS_URL, FrequentlyAskedQuestionInfos),
8
+ factory.addNotify()
9
+ ));
10
+
11
+ export const useFrequentlyAskedQuestions = ComposableFactory.getMany(FrequentlyAskedQuestionServiceFactory);
@@ -0,0 +1,71 @@
1
+ import { Ref, readonly, ref } from "vue";
2
+
3
+ import { BlurHash } from "@dative-gpi/foundation-shared-domain";
4
+ import { ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { IMAGE_RAW_URL, IMAGE_BLURHASH_URL } from "../../config/urls";
7
+
8
+ const ImageServiceFactory = new ServiceFactory("image", BlurHash).create(factory => factory.build(
9
+ factory.addNotify(() => ({
10
+ getRaw: async (imageId: string): Promise<string> => {
11
+ const response = await ServiceFactory.http.get(IMAGE_RAW_URL(imageId));
12
+
13
+ return response.data;
14
+ },
15
+ getBlurHash: async (imageId: string): Promise<BlurHash> => {
16
+ const response = await ServiceFactory.http.get(IMAGE_BLURHASH_URL(imageId));
17
+ const result = new BlurHash(response.data);
18
+
19
+ return result;
20
+ }
21
+ }))
22
+ ));
23
+
24
+ export const useImageRaw = () => {
25
+ const service = ImageServiceFactory();
26
+
27
+ const fetching = ref(false);
28
+ const fetched = ref<string | null>(null) as Ref<string | null>;
29
+
30
+ const fetch = async (imageId: string) => {
31
+ fetching.value = true;
32
+ try {
33
+ fetched.value = await service.getRaw(imageId);
34
+ }
35
+ finally {
36
+ fetching.value = false;
37
+ }
38
+
39
+ return readonly(fetched as Ref<string>);
40
+ }
41
+
42
+ return {
43
+ fetching: readonly(fetching),
44
+ fetch,
45
+ fetched: readonly(fetched)
46
+ }
47
+ }
48
+ export const useImageBlurHash = () => {
49
+ const service = ImageServiceFactory();
50
+
51
+ const fetching = ref(false);
52
+ const fetched = ref<BlurHash | null>(null) as Ref<BlurHash | null>;
53
+
54
+ const fetch = async (imageId: string) => {
55
+ fetching.value = true;
56
+ try {
57
+ fetched.value = await service.getBlurHash(imageId);
58
+ }
59
+ finally {
60
+ fetching.value = false;
61
+ }
62
+
63
+ return readonly(fetched as Ref<BlurHash>);
64
+ }
65
+
66
+ return {
67
+ fetching: readonly(fetching),
68
+ fetch,
69
+ fetched: readonly(fetched)
70
+ }
71
+ }
@@ -0,0 +1,50 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { LandingPageDetails, LandingPageDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { LANDING_PAGE_CURRENT_URL } from "../../config/urls";
7
+
8
+ const LandingPageServiceFactory = new ServiceFactory<LandingPageDetailsDTO, LandingPageDetails>("landingPage", LandingPageDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<LandingPageDetails> => {
11
+ const response = await ServiceFactory.http.get(LANDING_PAGE_CURRENT_URL());
12
+ const result = new LandingPageDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ }
18
+ }))
19
+ ));
20
+
21
+ export const useCurrentLandingPage = () => {
22
+ const service = LandingPageServiceFactory();
23
+ const subscribersIds: number[] = [];
24
+
25
+ const fetching = ref(false);
26
+ const fetched = ref<LandingPageDetails | null>(null) as Ref<LandingPageDetails | null>;
27
+
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
33
+ const fetch = async () => {
34
+ fetching.value = true;
35
+ try {
36
+ fetched.value = await service.getCurrent();
37
+ }
38
+ finally {
39
+ fetching.value = false;
40
+ }
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
42
+ return readonly(fetched as Ref<LandingPageDetails>);
43
+ }
44
+
45
+ return {
46
+ fetching: readonly(fetching),
47
+ fetch,
48
+ fetched: readonly(fetched)
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { LayoutPageDetails, LayoutPageDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { LAYOUT_PAGE_CURRENT_URL } from "../../config/urls";
7
+
8
+ const LayoutPageServiceFactory = new ServiceFactory<LayoutPageDetailsDTO, LayoutPageDetails>("layoutPage", LayoutPageDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<LayoutPageDetails> => {
11
+ const response = await ServiceFactory.http.get(LAYOUT_PAGE_CURRENT_URL());
12
+ const result = new LayoutPageDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ }
18
+ }))
19
+ ));
20
+
21
+ export const useCurrentLayoutPage = () => {
22
+ const service = LayoutPageServiceFactory();
23
+ const subscribersIds: number[] = [];
24
+
25
+ const fetching = ref(false);
26
+ const fetched = ref<LayoutPageDetails | null>(null) as Ref<LayoutPageDetails | null>;
27
+
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
33
+ const fetch = async () => {
34
+ fetching.value = true;
35
+ try {
36
+ fetched.value = await service.getCurrent();
37
+ }
38
+ finally {
39
+ fetching.value = false;
40
+ }
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
42
+ return readonly(fetched as Ref<LayoutPageDetails>);
43
+ }
44
+
45
+ return {
46
+ fetching: readonly(fetching),
47
+ fetch,
48
+ fetched: readonly(fetched)
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { LegalInformationDetails, LegalInformationDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { LEGAL_INFORMATION_CURRENT_URL } from "../../config/urls";
7
+
8
+ const LegalInformationServiceFactory = new ServiceFactory<LegalInformationDetailsDTO, LegalInformationDetails>("legalInformation", LegalInformationDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<LegalInformationDetails> => {
11
+ const response = await ServiceFactory.http.get(LEGAL_INFORMATION_CURRENT_URL());
12
+ const result = new LegalInformationDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ }
18
+ }))
19
+ ));
20
+
21
+ export const useCurrentLegalInformation = () => {
22
+ const service = LegalInformationServiceFactory();
23
+ const subscribersIds: number[] = [];
24
+
25
+ const fetching = ref(false);
26
+ const fetched = ref<LegalInformationDetails | null>(null) as Ref<LegalInformationDetails | null>;
27
+
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
33
+ const fetch = async () => {
34
+ fetching.value = true;
35
+ try {
36
+ fetched.value = await service.getCurrent();
37
+ }
38
+ finally {
39
+ fetching.value = false;
40
+ }
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
42
+ return readonly(fetched as Ref<LegalInformationDetails>);
43
+ }
44
+
45
+ return {
46
+ fetching: readonly(fetching),
47
+ fetch,
48
+ fetched: readonly(fetched)
49
+ }
50
+ }
@@ -0,0 +1,17 @@
1
+ import { CreateOrganisationDTO, OrganisationDetails, OrganisationDetailsDTO, OrganisationFilters, OrganisationInfos, OrganisationInfosDTO, UpdateOrganisationDTO } from "@dative-gpi/foundation-shared-domain";
2
+ import { ComposableFactory , ServiceFactory } from "@dative-gpi/bones-ui";
3
+
4
+ import { ORGANISATIONS_URL, ORGANISATION_URL } from "../../config/urls";
5
+
6
+ const OrganisationServiceFactory = new ServiceFactory<OrganisationDetailsDTO, OrganisationDetails>("organisation", OrganisationDetails).create(factory => factory.build(
7
+ factory.addGet(ORGANISATION_URL),
8
+ factory.addGetMany<OrganisationInfosDTO, OrganisationInfos, OrganisationFilters>(ORGANISATIONS_URL, OrganisationInfos),
9
+ factory.addCreate<CreateOrganisationDTO>(ORGANISATIONS_URL),
10
+ factory.addUpdate<UpdateOrganisationDTO>(ORGANISATION_URL),
11
+ factory.addNotify()
12
+ ));
13
+
14
+ export const useOrganisation = ComposableFactory.get(OrganisationServiceFactory);
15
+ export const useOrganisations = ComposableFactory.getMany(OrganisationServiceFactory);
16
+ export const useCreateOrganisation = ComposableFactory.create(OrganisationServiceFactory);
17
+ export const useUpdateOrganisation = ComposableFactory.update(OrganisationServiceFactory);
@@ -0,0 +1,50 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { SecuritySettingDetails, SecuritySettingDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { SECURITY_SETTING_CURRENT_URL } from "../../config/urls";
7
+
8
+ const SecuritySettingServiceFactory = new ServiceFactory<SecuritySettingDetailsDTO, SecuritySettingDetails>("securitySetting", SecuritySettingDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<SecuritySettingDetails> => {
11
+ const response = await ServiceFactory.http.get(SECURITY_SETTING_CURRENT_URL());
12
+ const result = new SecuritySettingDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ }
18
+ }))
19
+ ));
20
+
21
+ export const useCurrentSecuritySettings = () => {
22
+ const service = SecuritySettingServiceFactory();
23
+ const subscribersIds: number[] = [];
24
+
25
+ const fetching = ref(false);
26
+ const fetched = ref<SecuritySettingDetails | null>(null) as Ref<SecuritySettingDetails | null>;
27
+
28
+ onUnmounted(() => {
29
+ subscribersIds.forEach(id => service.unsubscribe(id));
30
+ subscribersIds.length = 0;
31
+ });
32
+
33
+ const fetch = async () => {
34
+ fetching.value = true;
35
+ try {
36
+ fetched.value = await service.getCurrent();
37
+ }
38
+ finally {
39
+ fetching.value = false;
40
+ }
41
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
42
+ return readonly(fetched as Ref<SecuritySettingDetails>);
43
+ }
44
+
45
+ return {
46
+ fetching: readonly(fetching),
47
+ fetch,
48
+ fetched: readonly(fetched)
49
+ }
50
+ }
@@ -0,0 +1,11 @@
1
+ import { TimeZoneFilters, TimeZoneInfos, TimeZoneInfosDTO } from "@dative-gpi/foundation-shared-domain";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
+
4
+ import { TIME_ZONES_URL } from "../../config/urls";
5
+
6
+ const TimeZoneServiceFactory = new ServiceFactory<TimeZoneInfosDTO, TimeZoneInfos>("timeZone", TimeZoneInfos).create(factory => factory.build(
7
+ factory.addGetMany<TimeZoneInfosDTO, TimeZoneInfos, TimeZoneFilters>(TIME_ZONES_URL, TimeZoneInfos),
8
+ factory.addNotify()
9
+ ));
10
+
11
+ export const useTimeZones = ComposableFactory.getMany(TimeZoneServiceFactory);
@@ -0,0 +1,42 @@
1
+ import { Ref, readonly, ref } from "vue";
2
+
3
+ import { TranslationInfos, TranslationInfosDTO, TranslationDetails, TranslationDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { TRANSLATIONS_LANGUAGE_URL } from "../../config/urls";
7
+
8
+ const TranslationServiceFactory = new ServiceFactory<TranslationDetailsDTO, TranslationDetails>("translation", TranslationDetails).create(factory => factory.build(
9
+ factory.addNotify(() => ({
10
+ getMany: async (languageCode: string): Promise<TranslationInfos[]> => {
11
+ const response = await ServiceFactory.http.get(TRANSLATIONS_LANGUAGE_URL(languageCode));
12
+ const result = response.data.map((dto: TranslationInfosDTO) => new TranslationInfos(dto));
13
+
14
+ return result;
15
+ }
16
+ }))
17
+ ));
18
+
19
+ export const useTranslations = () => {
20
+ const service = TranslationServiceFactory();
21
+
22
+ const fetching = ref(false);
23
+ const fetched = ref<TranslationInfos[]>([]) as Ref<TranslationInfos[]>;
24
+
25
+ const fetch = async (languageCode: string) => {
26
+ fetching.value = true;
27
+ try {
28
+ fetched.value = await service.getMany(languageCode);
29
+ }
30
+ finally {
31
+ fetching.value = false;
32
+ }
33
+
34
+ return readonly(fetched as Ref<TranslationInfos[]>);
35
+ }
36
+
37
+ return {
38
+ fetching: readonly(fetching),
39
+ fetch,
40
+ fetched: readonly(fetched)
41
+ }
42
+ }
@@ -0,0 +1,52 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { CreateUserLegalInformationDTO, UserLegalInformationDetails, UserLegalInformationDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { ComposableFactory, onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { USER_LEGAL_INFORMATIONS_URL, USER_LEGAL_INFORMATION_CURRENT_URL } from "../../config/urls";
7
+
8
+ const UserLegalInformationServiceFactory = new ServiceFactory<UserLegalInformationDetailsDTO, UserLegalInformationDetails>("userLegalInformation", UserLegalInformationDetails).create(factory => factory.build(
9
+ factory.addCreate<CreateUserLegalInformationDTO>(USER_LEGAL_INFORMATIONS_URL),
10
+ factory.addNotify((notifyService) => ({
11
+ getCurrent: async (): Promise<UserLegalInformationDetails> => {
12
+ const response = await ServiceFactory.http.get(USER_LEGAL_INFORMATION_CURRENT_URL());
13
+ const result = new UserLegalInformationDetails(response.data);
14
+
15
+ notifyService.notify("update", result);
16
+
17
+ return result;
18
+ }
19
+ }))
20
+ ));
21
+
22
+ export const useCreateUserLegalInformation = ComposableFactory.create(UserLegalInformationServiceFactory);
23
+ export const useCurrentUserLegalInformation = () => {
24
+ const service = UserLegalInformationServiceFactory();
25
+ const subscribersIds: number[] = [];
26
+
27
+ const fetching = ref(false);
28
+ const fetched = ref<UserLegalInformationDetails | null>(null) as Ref<UserLegalInformationDetails | null>;
29
+
30
+ onUnmounted(() => {
31
+ subscribersIds.forEach(id => service.unsubscribe(id));
32
+ subscribersIds.length = 0;
33
+ });
34
+
35
+ const fetch = async () => {
36
+ fetching.value = true;
37
+ try {
38
+ fetched.value = await service.getCurrent();
39
+ }
40
+ finally {
41
+ fetching.value = false;
42
+ }
43
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
44
+ return readonly(fetched as Ref<UserLegalInformationDetails>);
45
+ }
46
+
47
+ return {
48
+ fetching: readonly(fetching),
49
+ fetch,
50
+ fetched: readonly(fetched)
51
+ }
52
+ }
@@ -0,0 +1,88 @@
1
+ import { Ref, onUnmounted, readonly, ref } from "vue";
2
+
3
+ import { UpdateUserDTO, UserDetails, UserDetailsDTO } from "@dative-gpi/foundation-shared-domain";
4
+ import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
5
+
6
+ import { USER_CURRENT_URL } from "../../config/urls";
7
+
8
+ const UserServiceFactory = new ServiceFactory<UserDetailsDTO, UserDetails>("user", UserDetails).create(factory => factory.build(
9
+ factory.addNotify((notifyService) => ({
10
+ getCurrent: async (): Promise<UserDetails> => {
11
+ const response = await ServiceFactory.http.get(USER_CURRENT_URL());
12
+ const result = new UserDetails(response.data);
13
+
14
+ notifyService.notify("update", result);
15
+
16
+ return result;
17
+ },
18
+ updateCurrent: async (payload: UpdateUserDTO): Promise<UserDetails> => {
19
+ const response = await ServiceFactory.http.post(USER_CURRENT_URL(), payload);
20
+ const result = new UserDetails(response.data);
21
+
22
+ notifyService.notify("update", result);
23
+
24
+ return result;
25
+ }
26
+ }))
27
+ ));
28
+
29
+ export const useCurrentUser = () => {
30
+ const service = UserServiceFactory();
31
+ const subscribersIds: number[] = [];
32
+
33
+ const fetching = ref(false);
34
+ const fetched = ref<UserDetails | null>(null) as Ref<UserDetails | null>;
35
+
36
+ onUnmounted(() => {
37
+ subscribersIds.forEach(id => service.unsubscribe(id));
38
+ subscribersIds.length = 0;
39
+ });
40
+
41
+ const fetch = async () => {
42
+ fetching.value = true;
43
+ try {
44
+ fetched.value = await service.getCurrent();
45
+ }
46
+ finally {
47
+ fetching.value = false;
48
+ }
49
+ subscribersIds.push(service.subscribe("all", onEntityChanged(fetched)));
50
+ return readonly(fetched as Ref<UserDetails>);
51
+ }
52
+
53
+ return {
54
+ fetching: readonly(fetching),
55
+ fetch,
56
+ fetched: readonly(fetched)
57
+ }
58
+ }
59
+ export const useUpdateCurrentUser = () => {
60
+ const service = UserServiceFactory();
61
+ const subscribersIds: number[] = [];
62
+
63
+ const updating = ref(false);
64
+ const updated = ref<UserDetails | null>(null) as Ref<UserDetails | null>;
65
+
66
+ onUnmounted(() => {
67
+ subscribersIds.forEach(id => service.unsubscribe(id));
68
+ subscribersIds.length = 0;
69
+ });
70
+
71
+ const update = async (payload: UpdateUserDTO) => {
72
+ updating.value = true;
73
+ try {
74
+ updated.value = await service.updateCurrent(payload);
75
+ }
76
+ finally {
77
+ updating.value = false;
78
+ }
79
+ subscribersIds.push(service.subscribe("all", onEntityChanged(updated)));
80
+ return readonly(updated as Ref<UserDetails>);
81
+ }
82
+
83
+ return {
84
+ updating: readonly(updating),
85
+ update,
86
+ updated: readonly(updated)
87
+ }
88
+ }
@@ -1,8 +1,4 @@
1
- import { onMounted, 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,18 +7,6 @@ export const useLanguageCode = () => {
11
7
  languageCode.value = payload;
12
8
  };
13
9
 
14
- if (!initialized) {
15
- provide(LANGUAGE_CODE, languageCode);
16
-
17
- onMounted(() => {
18
- if (languageCode.value) {
19
- return;
20
- }
21
- });
22
- }
23
-
24
- initialized = true;
25
-
26
10
  const ready = new Promise((resolve) => {
27
11
  if (languageCode.value) {
28
12
  resolve(languageCode.value);
@@ -0,0 +1,32 @@
1
+ import { onMounted, ref } from "vue";
2
+ import { useLanguageCode, useTimeZone, useTranslationsProvider } from "@dative-gpi/foundation-shared-services";
3
+
4
+ let called = false;
5
+
6
+ const ready = ref(false);
7
+
8
+ export function useShared() {
9
+ if (called) {
10
+ return {
11
+ ready
12
+ };
13
+ }
14
+
15
+ called = true;
16
+
17
+ const { ready: languageCodeReady } = useLanguageCode();
18
+ const { ready: timeZoneReady } = useTimeZone();
19
+
20
+ const { init: initTranslations } = useTranslationsProvider();
21
+
22
+ onMounted(async () => {
23
+ await languageCodeReady
24
+ await timeZoneReady;
25
+ await initTranslations();
26
+ ready.value = true;
27
+ });
28
+
29
+ return {
30
+ ready
31
+ };
32
+ }
@@ -1,14 +1,16 @@
1
- import { onMounted, provide, ref, watch } from "vue";
1
+ import { ref, watch } from "vue";
2
2
 
3
- import { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
3
+ import { enUS, enGB, fr, it, es, de, Locale } from "date-fns/locale";
4
+ import { format, subDays } from "date-fns";
4
5
 
5
- import { TIME_ZONE } from "../config/literals";
6
+ import { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
6
7
 
7
- let initialized = false;
8
+ import { useTranslationsProvider } from "./useTranslationsProvider";
9
+ import { useLanguageCode } from "./useLanguageCode";
8
10
 
9
11
  const timeZone = ref<TimeZoneInfos | null>({
10
- id: "UTC",
11
- offset: "UTC +03:00:00"
12
+ id: "Europe/Paris",
13
+ offset: "UTC +02:00:00"
12
14
  });
13
15
 
14
16
  export const useTimeZone = () => {
@@ -66,23 +68,111 @@ export const useTimeZone = () => {
66
68
  return 0;
67
69
  };
68
70
 
69
- if (!initialized) {
70
- provide(TIME_ZONE, timeZone);
71
+ const todayToEpoch = (resetHours: boolean): number => {
72
+ const today = new Date();
73
+ if (resetHours) {
74
+ today.setHours(0, 0, 0, 0);
75
+ }
76
+ return today.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
77
+ }
71
78
 
72
- onMounted(() => {
73
- if (timeZone.value) {
74
- return;
79
+ const pickerToEpoch = (value: Date): number => {
80
+ // FSCalendar is always in machine time zone, so we need to convert it to user time zone
81
+ return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
82
+ };
83
+
84
+ const epochToPicker = (value: number): Date => {
85
+ // Epoch is always without time zone, so we need to convert it to user time zone
86
+ const date = new Date(0);
87
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
88
+ return date;
89
+ };
90
+
91
+ const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
92
+ const date = new Date(0);
93
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
94
+ return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
95
+ };
96
+
97
+ const epochToLongDateFormat = (value: number): string => {
98
+ if (value == null || !isFinite(value)) {
99
+ return "";
100
+ }
101
+ const date = new Date(0);
102
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
103
+ return format(date, "EEEE dd LLLL yyyy", { locale: getLocale() });
104
+ };
105
+
106
+ const epochToLongTimeFormat = (value: number): string => {
107
+ if (value == null || !isFinite(value)) {
108
+ return "";
109
+ }
110
+ const date = new Date(0);
111
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
112
+ return format(date, overrideFormat(date, "EEEE dd LLLL yyyy HH:mm"), { locale: getLocale() })
113
+ };
114
+
115
+ const epochToShortDateFormat = (value: number): string => {
116
+ if (value == null || !isFinite(value)) {
117
+ return "";
118
+ }
119
+ const date = new Date(0);
120
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
121
+ switch (getLocale()) {
122
+ case enUS: {
123
+ return format(date, "MM/dd/yyyy", { locale: getLocale() });
75
124
  }
76
- else {
77
- setTimeZone(new TimeZoneInfos({
78
- id: Intl.DateTimeFormat().resolvedOptions().timeZone,
79
- offset: getMachineOffset()
80
- }));
125
+ default: {
126
+ return format(date, "dd/MM/yyyy", { locale: getLocale() });
81
127
  }
82
- });
128
+ }
129
+ };
130
+
131
+ const epochToShortTimeFormat = (value: number): string => {
132
+ if (value == null || !isFinite(value)) {
133
+ return "";
134
+ }
135
+ const date = new Date(0);
136
+ date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
137
+ switch (getLocale()) {
138
+ case enUS: {
139
+ return format(date, "MM/dd/yyyy HH:mm", { locale: getLocale() });
140
+ }
141
+ default: {
142
+ return format(date, "dd/MM/yyyy HH:mm", { locale: getLocale() });
143
+ }
144
+ }
145
+ };
146
+
147
+ const todayTimeFormat = (): string => {
148
+ return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replaceAll("'", "''")}' HH:mm:ss`;
149
+ }
150
+
151
+ const yesterdayTimeFormat = (): string => {
152
+ return `'${useTranslationsProvider().$tr("ui.time-zone.yesterday-at", "Yesterday at").replaceAll("'", "''")}' HH:mm:ss`;
153
+ }
154
+
155
+ const overrideFormat = (date: Date, askedFormat: string): string => {
156
+ let now = new Date();
157
+ if (date.toDateString() === now.toDateString()) {
158
+ return todayTimeFormat();
159
+ }
160
+ if (date.toDateString() === subDays(now, 1).toDateString()) {
161
+ return yesterdayTimeFormat();
162
+ }
163
+ return askedFormat;
83
164
  }
84
165
 
85
- initialized = true;
166
+ const getLocale = (): Locale => {
167
+ switch (useLanguageCode().languageCode.value) {
168
+ case "fr-FR": return fr;
169
+ case "es-ES": return es;
170
+ case "it-IT": return it;
171
+ case "en-GB": return enGB;
172
+ case "de-DE": return de;
173
+ default: return enUS;
174
+ }
175
+ }
86
176
 
87
177
  const ready = new Promise((resolve) => {
88
178
  if (timeZone.value) {
@@ -104,6 +194,14 @@ export const useTimeZone = () => {
104
194
  getUserOffset,
105
195
  getMachineOffset,
106
196
  getUserOffsetMillis,
107
- getMachineOffsetMillis
197
+ getMachineOffsetMillis,
198
+ todayToEpoch,
199
+ pickerToEpoch,
200
+ epochToPicker,
201
+ epochToPickerHeader,
202
+ epochToLongDateFormat,
203
+ epochToLongTimeFormat,
204
+ epochToShortDateFormat,
205
+ epochToShortTimeFormat
108
206
  };
109
207
  }
@@ -0,0 +1,28 @@
1
+ import { useLanguageCode, useTranslations } from "@dative-gpi/foundation-shared-services";
2
+
3
+ let initialized = false;
4
+
5
+ export const useTranslationsProvider = () => {
6
+ const $tr = (code: string, defaultValue: string, ...parameters: string[]): string => {
7
+ let translation = useTranslations().fetched.value.find(t => t.code === code)?.value ?? defaultValue;
8
+ if (translation && parameters.length) {
9
+ for (let p of parameters) {
10
+ translation = translation.replace(`{${parameters.indexOf(p)}}`, p.toString());
11
+ }
12
+ }
13
+ return translation;
14
+ };
15
+
16
+ const init = async () => {
17
+ if (!initialized) {
18
+ initialized = true;
19
+ await useLanguageCode().ready;
20
+ await useTranslations().fetch(useLanguageCode().languageCode.value!);
21
+ }
22
+ }
23
+
24
+ return {
25
+ $tr,
26
+ init
27
+ }
28
+ }
package/config/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./literals";
1
+ export * from "./urls";
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const APPLICATIONS_URL = () => `${GATEWAY_URL()}/applications`;
4
+ export const APPLICATION_CURRENT_URL = () => `${APPLICATIONS_URL()}/curent`;
@@ -0,0 +1,3 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const AUTH_TOKENS_URL = () => `${GATEWAY_URL()}/auth-tokens`;
@@ -0,0 +1 @@
1
+ export const GATEWAY_URL = () => "/api/shared/v1";
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const FILES_URL = () => `${GATEWAY_URL()}/files`;
4
+ export const FILE_URL = (fileId: string) => `${FILES_URL()}/${encodeURIComponent(fileId)}`;
@@ -0,0 +1,3 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const FREQUENTLY_ASKED_QUESTIONS_URL = () => `${GATEWAY_URL()}/frequently-asked-questions`;
@@ -0,0 +1,12 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const IMAGES_URL = () => `${GATEWAY_URL()}/images`;
4
+
5
+ export const IMAGES_RAW_URL = () => `${IMAGES_URL()}/raw`;
6
+ export const IMAGE_RAW_URL = (imageId: string) => `${IMAGES_RAW_URL()}/${encodeURIComponent(imageId)}`;
7
+
8
+ export const IMAGES_THUMBNAIL_URL = () => `${IMAGES_URL()}/thumbnail`;
9
+ export const IMAGE_THUMBNAIL_URL = (imageId: string) => `${IMAGES_THUMBNAIL_URL()}/${encodeURIComponent(imageId)}`;
10
+
11
+ export const IMAGES_BLURHASH_URL = () => `${IMAGES_URL()}/blurHash`;
12
+ export const IMAGE_BLURHASH_URL = (imageId: string) => `${IMAGES_BLURHASH_URL()}/${encodeURIComponent(imageId)}`;
@@ -0,0 +1,14 @@
1
+ export * from "./applications";
2
+ export * from "./authTokens";
3
+ export * from "./files";
4
+ export * from "./frequentlyAskedQuestions";
5
+ export * from "./images";
6
+ export * from "./landingPages";
7
+ export * from "./layoutPages";
8
+ export * from "./legalInformations";
9
+ export * from "./organisations";
10
+ export * from "./securitySettings";
11
+ export * from "./timeZones";
12
+ export * from "./translations";
13
+ export * from "./userLegalInformations";
14
+ export * from "./users";
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const LANDING_PAGES_URL = () => `${GATEWAY_URL()}/landing-pages`;
4
+ export const LANDING_PAGE_CURRENT_URL = () => `${LANDING_PAGES_URL()}/current`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const LAYOUT_PAGES_URL = () => `${GATEWAY_URL()}/layout-pages`;
4
+ export const LAYOUT_PAGE_CURRENT_URL = () => `${LAYOUT_PAGES_URL()}/current`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const LEGAL_INFORMATIONS_URL = () => `${GATEWAY_URL()}/legal-informations`;
4
+ export const LEGAL_INFORMATION_CURRENT_URL = () => `${LEGAL_INFORMATIONS_URL()}/current`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const ORGANISATIONS_URL = () => `${GATEWAY_URL()}/organisations`;
4
+ export const ORGANISATION_URL = (organisationId: string) => `${ORGANISATIONS_URL()}/${encodeURIComponent(organisationId)}`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const SECURITY_SETTINGS_URL = () => `${GATEWAY_URL()}/security-settings`;
4
+ export const SECURITY_SETTING_CURRENT_URL = () => `${SECURITY_SETTINGS_URL()}/current`;
@@ -0,0 +1,3 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const TIME_ZONES_URL = () => `${GATEWAY_URL()}/time-zones`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const TRANSLATIONS_URL = () => `${GATEWAY_URL()}/translations`;
4
+ export const TRANSLATIONS_LANGUAGE_URL = (languageCode: string) => `${TRANSLATIONS_URL()}/${encodeURIComponent(languageCode)}`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const USER_LEGAL_INFORMATIONS_URL = () => `${GATEWAY_URL()}/user-legal-informations`;
4
+ export const USER_LEGAL_INFORMATION_CURRENT_URL = () => `${USER_LEGAL_INFORMATIONS_URL()}/current`;
@@ -0,0 +1,4 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const USERS_URL = () => `${GATEWAY_URL()}/users`;
4
+ export const USER_CURRENT_URL = () => `${USERS_URL()}/current`;
package/index.ts CHANGED
@@ -0,0 +1 @@
1
+ export * from "./composables";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,11 +9,12 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@dative-gpi/bones-ui": "^0.0.50",
13
- "@dative-gpi/foundation-shared-domain": "0.0.8",
12
+ "@dative-gpi/bones-ui": "^0.0.60",
13
+ "@dative-gpi/foundation-shared-domain": "0.0.10",
14
14
  "@microsoft/signalr": "^8.0.0",
15
+ "date-fns": "^3.2.0",
15
16
  "vue": "^3.2.0",
16
17
  "vue-router": "^4.2.5"
17
18
  },
18
- "gitHead": "b3393ad0a66fda249e1b2d3582af86e961553453"
19
+ "gitHead": "765222a4eb6a5cdd690f64bc0ae3c5415081e0f0"
19
20
  }
@@ -0,0 +1,15 @@
1
+ import { parse } from "date-fns";
2
+
3
+ const removeArtifacts = (date: string): string => {
4
+ return date.substring(0, 19) + "Z";
5
+ };
6
+
7
+ const isoTimeFormat = (timeZone: boolean = false): string => {
8
+ return `yyyy-MM-dd'T'HH:mm:ss${timeZone ? "X" : ""}`;
9
+ };
10
+
11
+ export const DatesTools = {
12
+ utcToEpoch: (value: string): number => {
13
+ return parse(removeArtifacts(value), isoTimeFormat(true), new Date()).getTime();
14
+ }
15
+ };
package/tools/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./datesTools";
@@ -1,2 +0,0 @@
1
- export const TIME_ZONE = "timeZone";
2
- export const LANGUAGE_CODE = "languageCode";