@zap-wunschlachen/wl-shared-components 1.0.80 → 1.0.82

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-wunschlachen/wl-shared-components",
3
- "version": "1.0.80",
3
+ "version": "1.0.82",
4
4
  "type": "module",
5
5
  "module": "./src/index.ts",
6
6
  "scripts": {
@@ -2,52 +2,19 @@ import { ref, watch, type Ref, type ComputedRef } from 'vue';
2
2
  import type { ReleaseNote } from '../types';
3
3
 
4
4
  export function useReleaseNotes(options: {
5
- directusUrl: string;
6
5
  userId: Ref<string | null> | ComputedRef<string | null>;
6
+ checkIsEmployee: () => Promise<boolean>;
7
+ resolveAppId: () => Promise<string | null>;
8
+ fetchUnreadNotes: (appId: string, userId: string) => Promise<ReleaseNote[]>;
9
+ markNotesAsRead: (notes: ReleaseNote[], userId: string) => Promise<void>;
7
10
  }) {
8
- const { directusUrl, userId } = options;
11
+ const { userId, checkIsEmployee, resolveAppId, fetchUnreadNotes, markNotesAsRead } = options;
9
12
  const unreadNotes = ref<ReleaseNote[]>([]);
10
13
  const showModal = ref(false);
11
14
  const loading = ref(false);
12
15
  const markingAsRead = ref(false);
13
16
  const appId = ref<string | null>(null);
14
17
 
15
- async function checkIsEmployee(): Promise<boolean> {
16
- try {
17
- const res = await fetch(`${directusUrl}/secure-auth/is-employee`, {
18
- credentials: 'include',
19
- });
20
- if (!res.ok) return false;
21
- const data = await res.json();
22
- return data.is_employee === true;
23
- } catch {
24
- return false;
25
- }
26
- }
27
-
28
- async function resolveAppId(): Promise<string | null> {
29
- try {
30
- const res = await fetch(
31
- `${directusUrl}/secure-data/items/internal_apps?fields[]=id&fields[]=domain`,
32
- { credentials: 'include' },
33
- );
34
- if (!res.ok) return null;
35
- const data = await res.json();
36
- const apps: { id: string; domain: string }[] = data.data || data;
37
- const host = window.location.host;
38
- const match = apps.find(
39
- (app) => app.domain && host.includes(app.domain),
40
- );
41
- if (match) {
42
- appId.value = match.id;
43
- return match.id;
44
- }
45
- return null;
46
- } catch {
47
- return null;
48
- }
49
- }
50
-
51
18
  async function fetchUnread() {
52
19
  const currentUserId = userId.value;
53
20
  const currentAppId = appId.value;
@@ -55,30 +22,7 @@ export function useReleaseNotes(options: {
55
22
 
56
23
  loading.value = true;
57
24
  try {
58
- const params = new URLSearchParams();
59
- params.append('filter[app][_eq]', currentAppId);
60
- params.append('fields[]', 'id');
61
- params.append('fields[]', 'notes');
62
- params.append('fields[]', 'date_created');
63
- params.append('fields[]', 'notified_users.directus_users_id');
64
- params.append('sort[]', '-date_created');
65
-
66
- const res = await fetch(
67
- `${directusUrl}/secure-data/items/release_notes?${params.toString()}`,
68
- { credentials: 'include' },
69
- );
70
- if (!res.ok) return;
71
-
72
- const data = await res.json();
73
- const allNotes: ReleaseNote[] = data.data || data;
74
-
75
- unreadNotes.value = allNotes.filter((note) => {
76
- if (!note.notified_users || note.notified_users.length === 0) return true;
77
- return !note.notified_users.some(
78
- (entry) => entry.directus_users_id === currentUserId,
79
- );
80
- });
81
-
25
+ unreadNotes.value = await fetchUnreadNotes(currentAppId, currentUserId);
82
26
  if (unreadNotes.value.length > 0) {
83
27
  showModal.value = true;
84
28
  }
@@ -95,20 +39,7 @@ export function useReleaseNotes(options: {
95
39
 
96
40
  markingAsRead.value = true;
97
41
  try {
98
- for (const note of unreadNotes.value) {
99
- await fetch(
100
- `${directusUrl}/secure-data/items/release_notes_directus_users`,
101
- {
102
- method: 'POST',
103
- credentials: 'include',
104
- headers: { 'Content-Type': 'application/json' },
105
- body: JSON.stringify({
106
- release_notes_id: note.id,
107
- directus_users_id: currentUserId,
108
- }),
109
- },
110
- );
111
- }
42
+ await markNotesAsRead(unreadNotes.value, currentUserId);
112
43
  showModal.value = false;
113
44
  unreadNotes.value = [];
114
45
  } catch {
@@ -122,10 +53,17 @@ export function useReleaseNotes(options: {
122
53
  userId,
123
54
  async (id) => {
124
55
  if (!id) return;
125
- const isEmployee = await checkIsEmployee();
126
- if (!isEmployee) return;
127
- const resolved = await resolveAppId();
128
- if (resolved) await fetchUnread();
56
+ try {
57
+ const isEmployee = await checkIsEmployee();
58
+ if (!isEmployee) return;
59
+ const resolved = await resolveAppId();
60
+ if (resolved) {
61
+ appId.value = resolved;
62
+ await fetchUnread();
63
+ }
64
+ } catch {
65
+ // Silently fail — don't block the app
66
+ }
129
67
  },
130
68
  { immediate: true },
131
69
  );