@dative-gpi/foundation-shared-services 1.0.26 → 1.0.28-remove-deprecated2

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.
@@ -1,4 +1,5 @@
1
1
  export * from "./useAppLanguageCode";
2
2
  export * from "./useAppLanguages";
3
3
  export * from "./useAppTimeZone";
4
- export * from "./useExtensionJwt";
4
+ export * from "./useAppAuthToken";
5
+ export * from "./useAppHost";
@@ -0,0 +1,17 @@
1
+ import { computed, ref } from "vue";
2
+
3
+ const authToken = ref<string | undefined>(undefined);
4
+
5
+ export const useAppAuthToken = () => {
6
+ const setAppAuthToken = (payload: string) => {
7
+ authToken.value = payload;
8
+ };
9
+
10
+ const ready = computed(() => authToken.value !== null);
11
+
12
+ return {
13
+ authToken,
14
+ ready,
15
+ setAppAuthToken
16
+ };
17
+ }
@@ -0,0 +1,17 @@
1
+ import { computed, ref } from "vue";
2
+
3
+ const host = ref<string | undefined>(undefined);
4
+
5
+ export const useAppHost = () => {
6
+ const setAppHost = (payload: string) => {
7
+ host.value = payload;
8
+ };
9
+
10
+ const ready = computed(() => host.value !== null);
11
+
12
+ return {
13
+ host,
14
+ ready,
15
+ setAppHost
16
+ };
17
+ }
@@ -1,170 +1,60 @@
1
- import { addMilliseconds, format, parse, subDays } from "date-fns";
2
1
  import { computed, ref } from "vue";
3
2
 
4
- import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui/composables";
5
- import { ISO_FORMAT, OPTIONS } from "@dative-gpi/foundation-shared-domain/tools";
6
-
7
- import { useAppLanguageCode } from "./useAppLanguageCode";
8
-
9
3
  const timeZone = ref<string | undefined>(undefined);
10
4
 
11
5
  export const useAppTimeZone = () => {
12
- const { $tr } = useTranslationsProvider();
13
-
14
6
  const setAppTimeZone = (payload: string) => {
15
7
  timeZone.value = payload;
16
8
  };
17
9
 
18
- const epochToShortDateFormat = (value: number | null | undefined): string => {
19
- if (value == null || !isFinite(value)) {
20
- return "";
21
- }
22
- const date = new Date(value);
23
- return date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value });
24
- };
25
-
26
- const epochToLongDateFormat = (value: number | null | undefined): string => {
27
- if (value == null || !isFinite(value)) {
28
- return "";
29
- }
30
- const date = new Date(value);
31
- const now = new Date();
32
- if (date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value }) === now.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })) {
33
- return $tr("ui.time-zone.today", "Today");
34
- }
35
- if (date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value }) === subDays(now, 1).toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })) {
36
- return $tr("ui.time-zone.yesterday", "Yesterday");
37
- }
38
- const dateString = date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.longDate, timeZone: timeZone.value });
39
- return dateString[0].toLocaleUpperCase() + dateString.slice(1);
40
- };
41
-
42
- const epochToShortTimeFormat = (value: number | null | undefined): string => {
43
- if (value == null || !isFinite(value)) {
44
- return "";
45
- }
46
- const date = new Date(value);
47
- return date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortTime, timeZone: timeZone.value });
48
- };
49
-
50
- const epochToLongTimeFormat = (value: number | null | undefined): string => {
51
- if (value == null || !isFinite(value)) {
52
- return "";
53
- }
54
- const date = new Date(value);
55
- const now = new Date();
56
- if (date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value }) === now.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })) {
57
- return `${$tr("ui.time-zone.today-at", "Today at")} ${date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value })}`;
58
- }
59
- if (date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value }) === subDays(now, 1).toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })) {
60
- return `${$tr("ui.time-zone.yesterday-at", "Yesterday at")} ${date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value })}`;
61
- }
62
- const dateString = date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.longTime, timeZone: timeZone.value });
63
- return dateString[0].toLocaleUpperCase() + dateString.slice(1);
64
- };
65
-
66
- const epochToTimeOnlyFormat = (value: number | null | undefined): string => {
67
- if (value == null || !isFinite(value)) {
68
- return "";
69
- }
70
- const date = new Date(value);
71
- return date.toLocaleString(useAppLanguageCode().languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value });
72
- };
73
-
74
- const getOffsetUser = (): number => {
75
- const offsetParts = (Intl.DateTimeFormat(undefined, {
76
- timeZone: timeZone.value,
77
- timeZoneName: "longOffset"
78
- }).formatToParts(new Date).pop()?.value.slice(3) || "+00:00").split(':');
79
- return (parseInt(offsetParts[0]) * 60 + parseInt(offsetParts[1])) * 60 * 1000;
80
- };
81
-
82
- const getOffsetUserChart = (withUTC: boolean = true): string => {
83
- const offsetPart = (Intl.DateTimeFormat(undefined, {
84
- timeZone: timeZone.value,
10
+ const getUserFormatter = (): Intl.DateTimeFormat => {
11
+ return new Intl.DateTimeFormat(undefined, {
12
+ timeZone: timeZone.value || Intl.DateTimeFormat().resolvedOptions().timeZone,
85
13
  timeZoneName: "longOffset"
86
- }).formatToParts(new Date).pop()?.value.slice(3) || "+00:00");
87
- return `${withUTC ? 'UTC ' : ''}${offsetPart}`;
14
+ });
88
15
  }
89
16
 
90
- const getOffsetMachine = (): number => {
91
- const offsetParts = (Intl.DateTimeFormat(undefined, {
17
+ const getMachineFormatter = (): Intl.DateTimeFormat => {
18
+ return new Intl.DateTimeFormat(undefined, {
92
19
  timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
93
20
  timeZoneName: "longOffset"
94
- }).formatToParts(new Date).pop()?.value.slice(3) || "+00:00").split(':');
95
- return (parseInt(offsetParts[0]) * 60 + parseInt(offsetParts[1])) * 60 * 1000;
96
- };
21
+ });
22
+ }
97
23
 
98
- const getOffsetMachineChart = (withUTC: boolean = true): string => {
99
- const offsetPart = (Intl.DateTimeFormat(undefined, {
100
- timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
101
- timeZoneName: "longOffset"
102
- }).formatToParts(new Date).pop()?.value.slice(3) || "+00:00");
103
- return `${withUTC ? 'UTC ' : ''}${offsetPart}`;
24
+ const getUserOffsetName = (epoch: number | null = null): string => {
25
+ const formatter = getUserFormatter();
26
+ const date = formatter.formatToParts(epoch ? new Date(epoch) : new Date());
27
+ const timeZoneName = date.find((part) => part.type === "timeZoneName")?.value || "UTC+00:00";
28
+ return timeZoneName
104
29
  }
105
30
 
106
- const getOffsetDifference = (): number => {
107
- if (timeZone.value == null) {
31
+ const getUserOffset = (epoch: number | null = null): number => {
32
+ const timeZoneName = getUserOffsetName(epoch);
33
+ const [hours, minutes] = timeZoneName.slice(3).split(':');
34
+ if (isNaN(parseInt(hours)) || isNaN(parseInt(minutes))) {
108
35
  return 0;
109
36
  }
110
- return getOffsetUser() - getOffsetMachine();
111
- };
112
-
113
- const todayToEpoch = (): number => {
114
- return (new Date().getTime() + getOffsetDifference());
115
- };
116
-
117
- const pickerToEpoch = (value: Date | null | undefined): number => {
118
- if (value != null) {
119
- return value.getTime() - getOffsetDifference();
120
- }
121
- return 0;
122
- };
123
-
124
- const epochToPicker = (value: number | null | undefined): Date => {
125
- if (value != null) {
126
- return new Date(value + getOffsetDifference());
127
- }
128
- return new Date(0);
37
+ return (parseInt(hours) * 60 + parseInt(minutes)) * 60 * 1000;
129
38
  };
130
39
 
131
- const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
132
- const date = epochToPicker(value);
133
- return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
40
+ const getMachineOffsetName = (epoch: number | null = null): string => {
41
+ const formatter = getMachineFormatter();
42
+ const date = formatter.formatToParts(epoch ? new Date(epoch) : new Date());
43
+ const timeZoneName = date.find((part) => part.type === "timeZoneName")?.value || "UTC+00:00";
44
+ return timeZoneName;
134
45
  };
135
46
 
136
- const todayToPicker = (): string => {
137
- const date = addMilliseconds(new Date(), -getOffsetMachine());
138
- date.setSeconds(0, 0);
139
- return format(date, ISO_FORMAT);
140
- };
141
-
142
- const yesterdayToPicker = (): string => {
143
- const date = addMilliseconds(subDays(new Date(), 1), -getOffsetMachine());
144
- date.setSeconds(0, 0);
145
- return format(date, ISO_FORMAT);
146
- };
147
-
148
- const parseForPicker = (value: string, dateFormat: string = ISO_FORMAT): number | null => {
149
- const date = addMilliseconds(parse(value, dateFormat, new Date()), getOffsetUser());
150
- if (!isFinite(date.getTime())) {
151
- return null;
152
- }
153
- return date.getTime();
154
- };
155
-
156
- const formatFromPicker = (date: number | null): string => {
157
- if (date != null) {
158
- return format(date - getOffsetMachine(), ISO_FORMAT);
47
+ const getMachineOffset = (epoch: number | null = null): number => {
48
+ const timeZoneName = getMachineOffsetName(epoch);
49
+ const [hours, minutes] = timeZoneName.slice(3).split(':');
50
+ if (isNaN(parseInt(hours)) || isNaN(parseInt(minutes))) {
51
+ return 0;
159
52
  }
160
- return "";
161
- };
53
+ return (parseInt(hours) * 60 + parseInt(minutes)) * 60 * 1000;
54
+ }
162
55
 
163
- const formatEpochToVariable = (epoch: number | undefined): string => {
164
- if (epoch == null || !isFinite(epoch)) {
165
- return "";
166
- }
167
- return format(epoch - getOffsetMachine(), ISO_FORMAT);
56
+ const getOffsetDifference = (): number => {
57
+ return getUserOffset() - getMachineOffset();
168
58
  };
169
59
 
170
60
  const ready = computed(() => timeZone.value !== null);
@@ -173,24 +63,10 @@ export const useAppTimeZone = () => {
173
63
  ready,
174
64
  timeZone,
175
65
  setAppTimeZone,
176
- todayToEpoch,
177
- pickerToEpoch,
178
- epochToPicker,
179
- epochToPickerHeader,
180
- epochToLongDateFormat,
181
- epochToLongTimeFormat,
182
- epochToShortDateFormat,
183
- epochToShortTimeFormat,
184
- epochToTimeOnlyFormat,
185
- parseForPicker,
186
- todayToPicker,
187
- yesterdayToPicker,
188
- formatFromPicker,
189
- formatEpochToVariable,
190
- getOffsetUser,
191
- getOffsetMachine,
66
+ getUserOffset,
67
+ getUserOffsetName,
68
+ getMachineOffset,
69
+ getMachineOffsetName,
192
70
  getOffsetDifference,
193
- getOffsetUserChart,
194
- getOffsetMachineChart
195
71
  };
196
72
  }
@@ -1,5 +1,7 @@
1
1
  export * from "./services";
2
2
  export * from "./app";
3
3
 
4
+ export * from "./useDateFormat";
4
5
  export * from "./useFiles";
5
- export * from "./useFoundationShared";
6
+ export * from "./useFoundationShared";
7
+ export * from "./useRouting";
@@ -1,8 +1,11 @@
1
1
  export * from "./useAuthTokens";
2
2
  export * from "./useImages";
3
3
  export * from "./useLanguages";
4
+ export * from "./useLegalInformations";
5
+ export * from "./useNotifications";
4
6
  export * from "./useOrganisations";
5
7
  export * from "./useTerminals";
6
8
  export * from "./useTimeZones";
7
9
  export * from "./useTranslations";
10
+ export * from "./useUserLegalInformations";
8
11
  export * from "./useUsers";
@@ -0,0 +1,10 @@
1
+ import { LegalInformationDetails, type LegalInformationDetailsDTO } from "@dative-gpi/foundation-shared-domain/models";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
+
4
+ import { LEGAL_INFORMATION_CURRENT_URL } from "../../config/urls";
5
+
6
+ const LegalInformationServiceFactory = {
7
+ ...ServiceFactory.addCustom("getCurrent", axios => axios.get(LEGAL_INFORMATION_CURRENT_URL()), (dto: LegalInformationDetailsDTO) => new LegalInformationDetails(dto))
8
+ };
9
+
10
+ export const useCurrentLegalInformation = ComposableFactory.custom(LegalInformationServiceFactory.getCurrent);
@@ -0,0 +1,41 @@
1
+ import { type NotificationDetailsDTO, type NotificationFilters, type NotificationInfosDTO } from "@dative-gpi/foundation-shared-domain/models";
2
+ import { NotificationDetails, NotificationInfos } from "@dative-gpi/foundation-shared-domain/models";
3
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
4
+
5
+ import { HUBS, NOTIFICATION_URL, NOTIFICATIONS_HUB_URL, NOTIFICATIONS_URL } from "../../config";
6
+ import { HubFactory } from "../../tools";
7
+
8
+ const NotificationServiceFactory = new ServiceFactory<NotificationDetailsDTO, NotificationDetails>("notification", NotificationDetails).create(factory => factory.build(
9
+ factory.addGet(NOTIFICATION_URL),
10
+ factory.addGetMany<NotificationInfosDTO, NotificationInfos, NotificationFilters>(NOTIFICATIONS_URL, NotificationInfos),
11
+ factory.addNotify(notifyService => ({
12
+ notifyCreate: (notification: NotificationDetails) => notifyService.notify("add", notification),
13
+ ...ServiceFactory.addCustom("acknowledge", (axios, notificationId: string) => axios.patch(NOTIFICATION_URL(notificationId)), (dto: NotificationDetailsDTO) => {
14
+ const result = new NotificationDetails(dto);
15
+ notifyService.notify("update", result);
16
+ return result;
17
+ })
18
+ }))
19
+ ));
20
+
21
+ const useNotificationsHub = HubFactory.create(NOTIFICATIONS_HUB_URL,
22
+ (connection, { hasWatchers }) => {
23
+ connection.on(HUBS.CREATE_NOTIFICATION, (notificationId: string) => hasWatchers()
24
+ ? NotificationServiceFactory.get(notificationId).then(NotificationServiceFactory.notifyCreate)
25
+ : null);
26
+ },
27
+ async (connection) => {
28
+ await connection.invoke(HUBS.SUBSCRIBE);
29
+ }
30
+ );
31
+
32
+ const useWatchNotifications = HubFactory.createWatcher(useNotificationsHub);
33
+
34
+
35
+ export const useNotifications = ComposableFactory.getMany(NotificationServiceFactory, () => {
36
+ const { watchMany } = useWatchNotifications();
37
+ return () => {
38
+ watchMany();
39
+ }
40
+ });
41
+ export const useAcknowledgeNotification = ComposableFactory.custom(NotificationServiceFactory.acknowledge);
@@ -0,0 +1,11 @@
1
+ import { type CreateUserLegalInformationDTO, UserLegalInformationDetails, type UserLegalInformationDetailsDTO } from "@dative-gpi/foundation-shared-domain/models";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
3
+
4
+ import { USER_LEGAL_INFORMATIONS_URL } from "../../config/urls";
5
+
6
+ const UserLegalInformationServiceFactory = new ServiceFactory<UserLegalInformationDetailsDTO, UserLegalInformationDetails>("userLegalInformation", UserLegalInformationDetails).create(factory => factory.build(
7
+ factory.addCreate<CreateUserLegalInformationDTO>(USER_LEGAL_INFORMATIONS_URL),
8
+ factory.addNotify()
9
+ ));
10
+
11
+ export const useCreateUserLegalInformation = ComposableFactory.create(UserLegalInformationServiceFactory);
@@ -0,0 +1,221 @@
1
+ import { addMilliseconds, format, parse, subDays } from "date-fns";
2
+
3
+ import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui/composables";
4
+ import { ISO_FORMAT, OPTIONS } from "@dative-gpi/foundation-shared-domain/tools";
5
+
6
+ import { useAppLanguageCode, useAppTimeZone } from "./app/";
7
+
8
+ export const useDateFormat = () => {
9
+ const { $tr } = useTranslationsProvider();
10
+
11
+ const { languageCode } = useAppLanguageCode();
12
+ const { timeZone, getOffsetDifference, getMachineOffset, getUserOffset } = useAppTimeZone();
13
+
14
+ const isEpochToday = (value: number | null | undefined): boolean => {
15
+ if (value == null || !isFinite(value)) {
16
+ return false;
17
+ }
18
+ const date = new Date(value);
19
+ const now = new Date();
20
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })
21
+ === now.toLocaleString(languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value });
22
+ }
23
+
24
+ const isEpochYesterday = (value: number | null | undefined): boolean => {
25
+ if (value == null || !isFinite(value)) {
26
+ return false;
27
+ }
28
+ const date = new Date(value);
29
+ const now = new Date();
30
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value })
31
+ === subDays(now, 1).toLocaleString(languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value });
32
+ }
33
+
34
+ const dayToMillisecond = (value: number): number => {
35
+ return value * 24 * 60 * 60 * 1000
36
+ }
37
+
38
+ const epochToDayMonthLongOnly = (value: number | null | undefined): string => {
39
+ if (value == null || !isFinite(value)) {
40
+ return "";
41
+ }
42
+ const date = new Date(value);
43
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.dayMonthLongOnly, timeZone: timeZone.value });
44
+ }
45
+
46
+ const epochToShortDateFormat = (value: number | null | undefined): string => {
47
+ if (value == null || !isFinite(value)) {
48
+ return "";
49
+ }
50
+ const date = new Date(value);
51
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.shortDate, timeZone: timeZone.value });
52
+ };
53
+
54
+ const epochToLongDateFormat = (value: number | null | undefined): string => {
55
+ if (value == null || !isFinite(value)) {
56
+ return "";
57
+ }
58
+ const date = new Date(value);
59
+ if (isEpochToday(value)) {
60
+ return $tr("ui.common.today", "Today");
61
+ }
62
+ if (isEpochYesterday(value)) {
63
+ return $tr("ui.common.yesterday", "Yesterday");
64
+ }
65
+ const dateString = date.toLocaleString(languageCode.value, { ...OPTIONS.longDate, timeZone: timeZone.value });
66
+ return dateString[0].toLocaleUpperCase() + dateString.slice(1);
67
+ };
68
+
69
+ const epochToShortTimeFormat = (value: number | null | undefined): string => {
70
+ if (value == null || !isFinite(value)) {
71
+ return "";
72
+ }
73
+ const date = new Date(value);
74
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.shortTime, timeZone: timeZone.value });
75
+ };
76
+
77
+ const epochToLocalDayStart = (value: number | null | undefined): number => {
78
+ if (value == null || !isFinite(value)) {
79
+ return 0;
80
+ }
81
+ const date = new Date(value);
82
+ return date.setHours(0, 0, 0, 0);
83
+ }
84
+
85
+ const epochToLocalDayEnd = (value: number | null | undefined): number => {
86
+ if (value == null || !isFinite(value)) {
87
+ return 0;
88
+ }
89
+ const date = new Date(value);
90
+ return date.setHours(23, 59, 59, 999);
91
+ }
92
+
93
+ const epochToLongTimeFormat = (value: number | null | undefined): string => {
94
+ if (value == null || !isFinite(value)) {
95
+ return "";
96
+ }
97
+ const date = new Date(value);
98
+ if (isEpochToday(value)) {
99
+ return `${$tr("ui.common.today-at", "Today at")} ${date.toLocaleString(languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value })}`;
100
+ }
101
+ if (isEpochYesterday(value)) {
102
+ return `${$tr("ui.common.yesterday-at", "Yesterday at")} ${date.toLocaleString(languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value })}`;
103
+ }
104
+ const dateString = date.toLocaleString(languageCode.value, { ...OPTIONS.longTime, timeZone: timeZone.value });
105
+ return dateString[0].toLocaleUpperCase() + dateString.slice(1);
106
+ };
107
+
108
+ const epochToMonthYearOnlyFormat = (value: number | null | undefined): string => {
109
+ if (value == null || !isFinite(value)) {
110
+ return "";
111
+ }
112
+ const date = new Date(value);
113
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.monthYearOnly, timeZone: timeZone.value });
114
+ }
115
+
116
+ const epochToTimeOnlyFormat = (value: number | null | undefined): string => {
117
+ if (value == null || !isFinite(value)) {
118
+ return "";
119
+ }
120
+ const date = new Date(value);
121
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.time, timeZone: timeZone.value });
122
+ };
123
+
124
+ const epochToShortTimeOnlyFormat = (value: number | null | undefined): string => {
125
+ if (value == null || !isFinite(value)) {
126
+ return "";
127
+ }
128
+ const date = new Date(value);
129
+ return date.toLocaleString(languageCode.value, { ...OPTIONS.shortTimeOnly, timeZone: timeZone.value });
130
+ }
131
+
132
+ const epochToWeekNumber = (value: number | null | undefined): string => {
133
+ if (value == null || !isFinite(value)) {
134
+ return "";
135
+ }
136
+ const date = new Date(value);
137
+ date.setHours(0, 0, 0, 0);
138
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
139
+ const week1 = new Date(date.getFullYear(), 0, 4);
140
+ return `${1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7)}`;
141
+ }
142
+
143
+ const todayToEpoch = (): number => {
144
+ return new Date().getTime() + getOffsetDifference();
145
+ };
146
+
147
+ const pickerToEpoch = (value: Date | null | undefined): number => {
148
+ if (value != null) {
149
+ return value.getTime() - getOffsetDifference();
150
+ }
151
+ return 0;
152
+ };
153
+
154
+ const epochToPicker = (value: number | null | undefined): Date => {
155
+ if (value != null) {
156
+ return new Date(value + getOffsetDifference());
157
+ }
158
+ return new Date(0);
159
+ };
160
+
161
+ const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
162
+ const date = epochToPicker(value);
163
+ return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
164
+ };
165
+
166
+ const millisecondToDay = (value: number): number => {
167
+ return value / 1000 / 60 / 60 / 24;
168
+ }
169
+
170
+ const todayToPicker = (): string => {
171
+ const date = addMilliseconds(new Date(), -getMachineOffset());
172
+ date.setSeconds(0, 0);
173
+ return format(date, ISO_FORMAT);
174
+ };
175
+
176
+ const yesterdayToPicker = (): string => {
177
+ const yesterday = subDays(new Date(), 1);
178
+ const date = addMilliseconds(yesterday, -getMachineOffset(yesterday.getTime()));
179
+ date.setSeconds(0, 0);
180
+ return format(date, ISO_FORMAT);
181
+ };
182
+
183
+ const parseForPicker = (value: string, dateFormat: string = ISO_FORMAT): number | null => {
184
+ const date = addMilliseconds(parse(value, dateFormat, new Date()), getUserOffset());
185
+ if (!isFinite(date.getTime())) {
186
+ return null;
187
+ }
188
+ return date.getTime();
189
+ };
190
+
191
+ const epochToISO = (epoch: number | null): string => {
192
+ if (epoch != null) {
193
+ return format(epoch - getMachineOffset(epoch), ISO_FORMAT);
194
+ }
195
+ return "";
196
+ };
197
+
198
+ return {
199
+ todayToEpoch,
200
+ pickerToEpoch,
201
+ dayToMillisecond,
202
+ epochToDayMonthLongOnly,
203
+ epochToPicker,
204
+ epochToPickerHeader,
205
+ epochToLocalDayStart,
206
+ epochToLocalDayEnd,
207
+ epochToLongDateFormat,
208
+ epochToLongTimeFormat,
209
+ epochToMonthYearOnlyFormat,
210
+ epochToShortDateFormat,
211
+ epochToShortTimeFormat,
212
+ epochToShortTimeOnlyFormat,
213
+ epochToTimeOnlyFormat,
214
+ epochToWeekNumber,
215
+ millisecondToDay,
216
+ parseForPicker,
217
+ todayToPicker,
218
+ yesterdayToPicker,
219
+ epochToISO
220
+ };
221
+ }
@@ -1,8 +1,13 @@
1
1
  import { FILE_URL } from "../config/urls";
2
2
 
3
+ import { useAppAuthToken, useRouting } from "@dative-gpi/foundation-shared-services/composables";
4
+
3
5
  export const useFiles = () => {
6
+ const { authToken } = useAppAuthToken();
7
+ const { openTab } = useRouting();
8
+
4
9
  const downloadFile = (id: string): void => {
5
- window.open(FILE_URL(id), "_blank");
10
+ openTab(FILE_URL(id, authToken.value));
6
11
  };
7
12
 
8
13
  const readFile = (file: File): Promise<string | ArrayBuffer | null> => {
@@ -0,0 +1,37 @@
1
+ import { type RouteLocation, useRouter } from "vue-router";
2
+
3
+ import { useAppHost } from "@dative-gpi/foundation-shared-services/composables";
4
+
5
+ export const useRouting = () => {
6
+ const { host } = useAppHost();
7
+ const router = useRouter();
8
+
9
+ const handleRoutingEvent = (event: MouseEvent, target: string | RouteLocation, handleDefaultBehavior: boolean = false): void => {
10
+ // If a redirection is requested, check if it comes from an extension and act accordingly
11
+ if (event.ctrlKey || event.metaKey || event.button === 1) {
12
+ event.preventDefault();
13
+ openTab(target);
14
+ }
15
+ else if (handleDefaultBehavior) {
16
+ router.push(target);
17
+ }
18
+ };
19
+
20
+ const openTab = (target: string | RouteLocation): void => {
21
+ // Check if target is a href (string) or a to (RouteLocation), get the absolute url in either case
22
+ const href = typeof target === "string" ? target : router.resolve(target).href;
23
+
24
+ // If the app is in an iframe, open the link in a new tab with the parent iframe host
25
+ if (window.top != window.self && host.value) {
26
+ window.open(host.value + href, "_blank");
27
+ }
28
+ else {
29
+ window.open(href, "_blank");
30
+ }
31
+ };
32
+
33
+ return {
34
+ handleRoutingEvent,
35
+ openTab
36
+ };
37
+ }
package/config/index.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from "./literals";
1
2
  export * from "./urls";
@@ -0,0 +1,16 @@
1
+ export const SUBSCRIBE = "Subscribe";
2
+ export const UNSUBSCRIBE = "Unsubscribe";
3
+
4
+ export const UPDATE_DEVICE_STATUS = "UpdateDeviceStatus";
5
+
6
+ export const UPDATE_DEVICE_CONNECTIVITY = "UpdateDeviceConnectivity";
7
+
8
+ export const CREATE_ALERT = "CreateAlert";
9
+ export const UPDATE_ALERT = "UpdateAlert";
10
+ export const REMOVE_ALERT = "RemoveAlert";
11
+
12
+ export const CREATE_CONNECTIVITY_ALERT = "CreateConnectivityAlert";
13
+ export const UPDATE_CONNECTIVITY_ALERT = "UpdateConnectivityAlert";
14
+ export const REMOVE_CONNECTIVITY_ALERT = "RemoveConnectivityAlert";
15
+
16
+ export const CREATE_NOTIFICATION = "CreateNotification";
@@ -0,0 +1 @@
1
+ export * as HUBS from "./hubs";
@@ -1 +1,3 @@
1
- export const GATEWAY_URL = () => "/api/foundation/shared/v1";
1
+ export const GATEWAY_URL = () => "/api/foundation/shared/v1";
2
+
3
+ export const HUBS_URL = () => "/api/foundation/hubs/v1";
@@ -1,4 +1,10 @@
1
1
  import { GATEWAY_URL } from "./base";
2
2
 
3
3
  export const FILES_URL = () => `${GATEWAY_URL()}/files`;
4
- export const FILE_URL = (fileId: string) => `${FILES_URL()}/${encodeURIComponent(fileId)}`;
4
+ export const FILE_URL = (fileId: string, accessToken?: string) => {
5
+ let url = `${FILES_URL()}/${encodeURIComponent(fileId)}`;
6
+ if (accessToken) {
7
+ url += `?access_token=${encodeURIComponent(accessToken)}`;
8
+ }
9
+ return url;
10
+ };
@@ -3,6 +3,17 @@ import { GATEWAY_URL } from "./base";
3
3
  export const IMAGES_URL = () => `${GATEWAY_URL()}/images`;
4
4
 
5
5
  export const IMAGE_URL = (imageId: string) => `${IMAGES_URL()}/${encodeURIComponent(imageId)}`;
6
- export const IMAGE_RAW_URL = (imageId: string) => `${IMAGE_URL(imageId)}/raw`;
7
-
8
- export const IMAGE_THUMBNAIL_URL = (imageId: string) => `${IMAGE_URL(imageId)}/thumbnail`;
6
+ export const IMAGE_RAW_URL = (imageId: string, accessToken?: string) => {
7
+ let url = `${IMAGE_URL(imageId)}/raw`;
8
+ if (accessToken) {
9
+ url += `?access_token=${encodeURIComponent(accessToken)}`;
10
+ }
11
+ return url;
12
+ };
13
+ export const IMAGE_THUMBNAIL_URL = (imageId: string, accessToken?: string) => {
14
+ let url = `${IMAGE_URL(imageId)}/thumbnail`;
15
+ if (accessToken) {
16
+ url += `?access_token=${encodeURIComponent(accessToken)}`;
17
+ }
18
+ return url;
19
+ };
@@ -2,8 +2,11 @@ export * from "./authTokens";
2
2
  export * from "./files";
3
3
  export * from "./images";
4
4
  export * from "./languages";
5
+ export * from "./legalInformations";
6
+ export * from "./notifications";
5
7
  export * from "./organisations";
6
8
  export * from "./terminals";
7
9
  export * from "./timeZones";
8
10
  export * from "./translations";
11
+ export * from "./userLegalInformations";
9
12
  export * from "./users";
@@ -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,6 @@
1
+ import { GATEWAY_URL, HUBS_URL } from "./base";
2
+
3
+ export const NOTIFICATIONS_URL = () => `${GATEWAY_URL()}/notifications`;
4
+ export const NOTIFICATION_URL = (notificationId: string) => `${GATEWAY_URL()}/notifications/${notificationId}`;
5
+
6
+ export const NOTIFICATIONS_HUB_URL = () => `${HUBS_URL()}/notifications`;
@@ -0,0 +1,3 @@
1
+ import { GATEWAY_URL } from "./base";
2
+
3
+ export const USER_LEGAL_INFORMATIONS_URL = () => `${GATEWAY_URL()}/user-legal-informations`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
3
  "sideEffects": false,
4
- "version": "1.0.26",
4
+ "version": "1.0.28-remove-deprecated2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,13 +10,13 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-shared-domain": "1.0.26"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.28-remove-deprecated2"
14
14
  },
15
15
  "peerDependencies": {
16
- "@dative-gpi/bones-ui": "^0.0.75",
16
+ "@dative-gpi/bones-ui": "^1.0.0",
17
17
  "@microsoft/signalr": "^8.0.0",
18
- "vue": "^3.4.29",
18
+ "vue": "^3.4.38",
19
19
  "vue-router": "^4.3.0"
20
20
  },
21
- "gitHead": "55c73ec6624ef58f78303ce68256236984c83ca9"
21
+ "gitHead": "65c182fd697939a07ad87c683a2f4c2fb765a7c7"
22
22
  }
@@ -28,7 +28,12 @@ export class HubFactory {
28
28
  })
29
29
  }
30
30
  if (connection.state !== signalR.HubConnectionState.Connected) {
31
- await connection.start();
31
+ try {
32
+ await connection.start();
33
+ }
34
+ catch {
35
+ return;
36
+ }
32
37
  }
33
38
  if (!subscribed) {
34
39
  await init(connection);
@@ -1,17 +0,0 @@
1
- import { computed, ref } from "vue";
2
-
3
- const jwt = ref<string | undefined>(undefined);
4
-
5
- export const useExtensionJwt = () => {
6
- const setExtensionJwt = (payload: string) => {
7
- jwt.value = payload;
8
- };
9
-
10
- const ready = computed(() => jwt.value !== null);
11
-
12
- return {
13
- jwt,
14
- ready,
15
- setExtensionJwt
16
- };
17
- }