@frigear-nu/shifts 0.1.1 → 0.1.3
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/README.md +2 -2
- package/dist/module.d.mts +7 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +61 -47
- package/dist/runtime/access.d.ts +1 -1
- package/dist/runtime/access.js +7 -0
- package/dist/runtime/app/components/ShiftCheckInCard.vue +2 -2
- package/dist/runtime/app/dashboard/NextShift.d.vue.ts +4 -1
- package/dist/runtime/app/dashboard/NextShift.vue +14 -5
- package/dist/runtime/app/dashboard/NextShift.vue.d.ts +4 -1
- package/dist/runtime/app/dashboard/OpenSwaps.vue +11 -5
- package/dist/runtime/app/dashboard/TeamOnNow.vue +12 -4
- package/dist/runtime/app/pages/lead.vue +3 -3
- package/dist/runtime/app/pages/shift-redirect.d.vue.ts +3 -0
- package/dist/runtime/app/pages/shift-redirect.vue +10 -0
- package/dist/runtime/app/pages/shift-redirect.vue.d.ts +3 -0
- package/dist/runtime/app/pages/shift.vue +285 -284
- package/dist/runtime/app/tabs/HomeShifts.vue +101 -94
- package/dist/runtime/app/tabs/HomeSwaps.vue +11 -5
- package/dist/runtime/i18n/lang/da.json +5 -3
- package/dist/runtime/i18n/lang/en.json +5 -3
- package/dist/runtime/server/routes/lead/check-in-any.post.d.ts +2 -0
- package/dist/runtime/server/routes/lead/check-in-any.post.js +12 -0
- package/dist/runtime/server/routes/lead/check-in.post.js +1 -1
- package/dist/runtime/server/utils/shifts-assign.d.ts +10 -5
- package/dist/runtime/server/utils/shifts-assign.js +3 -3
- package/dist/runtime/server/utils/shifts-station-key.d.ts +14 -4
- package/dist/runtime/server/utils/shifts-station-key.js +22 -7
- package/dist/runtime/server/utils/shifts-stations.js +4 -3
- package/dist/runtime/utils/api.d.ts +2 -0
- package/dist/runtime/utils/api.js +2 -0
- package/dist/runtime/utils/links.d.ts +2 -0
- package/dist/runtime/utils/links.js +1 -0
- package/dist/runtime/utils/station-key.d.ts +3 -2
- package/dist/runtime/utils/station-key.js +1 -1
- package/package.json +21 -21
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { shiftsApi } from "../../utils/api";
|
|
3
3
|
import { SHIFT_ASSIGNMENT_STATUS_LABELS, SHIFT_SWAP_STATUS_LABELS } from "../../utils/status";
|
|
4
4
|
import { dayKey } from "@frigear-nu/module-kit/time";
|
|
5
|
-
import { computed, errorMessage, navigateTo, ref, shallowRef, useAuthPages,
|
|
5
|
+
import { computed, errorMessage, navigateTo, ref, shallowRef, useAuthPages, useCachedFetch, useModuleT, useRoute, useShiftsActions, useShiftsFormat, useShiftsLinks, useShiftsTranslate, watch } from "#imports";
|
|
6
6
|
defineOptions({ name: "ShiftsHomeShiftsTab" });
|
|
7
7
|
defineProps({
|
|
8
8
|
standalone: { type: Boolean, required: false }
|
|
@@ -13,9 +13,10 @@ const format = useShiftsFormat();
|
|
|
13
13
|
const links = useShiftsLinks();
|
|
14
14
|
const actions = useShiftsActions();
|
|
15
15
|
const route = useRoute();
|
|
16
|
-
const { data
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
const { data: fetched, error, loading, refresh } = useCachedFetch(shiftsApi.me.shifts, { key: "shifts:me", ttl: 0, lazy: true });
|
|
17
|
+
const data = computed(() => fetched.value ?? []);
|
|
18
|
+
const { data: ledTeams } = useCachedFetch(shiftsApi.me.leads, { key: "shifts:leads", ttl: 0, lazy: true });
|
|
19
|
+
const led = computed(() => ledTeams.value ?? []);
|
|
19
20
|
watch(() => error.value?.statusCode, async (code) => {
|
|
20
21
|
if (code === 401) await navigateTo({ path: useAuthPages().login, query: { redirect: route.fullPath } });
|
|
21
22
|
}, { immediate: true });
|
|
@@ -89,106 +90,112 @@ const statusLabel = (item) => item.swap ? t(`swapStatuses.${item.swap.status}`,
|
|
|
89
90
|
:description="t('mine.emptyDescription', 'When a coordinator puts you on a shift, it shows up here.')"
|
|
90
91
|
:actions="[{ label: t('mine.openSwaps', 'Open swaps'), to: links.swaps(), icon: 'i-lucide-arrow-left-right', color: 'neutral', variant: 'outline' }]"
|
|
91
92
|
/>
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
<template v-else>
|
|
94
|
+
<!-- Offline or a failed refresh: the last data stays, with a quiet note. -->
|
|
95
|
+
<StaleDataNotice
|
|
96
|
+
:error="error"
|
|
97
|
+
:refresh="refresh"
|
|
98
|
+
/>
|
|
99
|
+
<div
|
|
100
|
+
class="grid items-start gap-4 lg:grid-cols-[20rem_1fr]"
|
|
101
|
+
data-shifts-mine
|
|
100
102
|
>
|
|
101
|
-
<template
|
|
102
|
-
v-if="picked"
|
|
103
|
-
#actions
|
|
104
|
-
>
|
|
105
|
-
<UButton
|
|
106
|
-
color="neutral"
|
|
107
|
-
variant="ghost"
|
|
108
|
-
size="xs"
|
|
109
|
-
icon="i-lucide-x"
|
|
110
|
-
:label="t('mine.showAll', 'Show all days')"
|
|
111
|
-
@click="picked = void 0"
|
|
112
|
-
/>
|
|
113
|
-
</template>
|
|
114
|
-
<UCalendar
|
|
115
|
-
v-model="picked"
|
|
116
|
-
:week-starts-on="1"
|
|
117
|
-
class="w-full"
|
|
118
|
-
>
|
|
119
|
-
<template #day="{ day }">
|
|
120
|
-
<UChip
|
|
121
|
-
:show="workDays.has(keyOf(day))"
|
|
122
|
-
size="2xs"
|
|
123
|
-
position="bottom-right"
|
|
124
|
-
>
|
|
125
|
-
{{ day.day }}
|
|
126
|
-
</UChip>
|
|
127
|
-
</template>
|
|
128
|
-
</UCalendar>
|
|
129
|
-
</SectionCard>
|
|
130
|
-
|
|
131
|
-
<div class="flex flex-col gap-4">
|
|
132
|
-
<SectionCard v-if="!groups.length">
|
|
133
|
-
<p class="text-muted text-sm">
|
|
134
|
-
{{ picked ? t("mine.noneThatDay", "No shifts on that day.") : t("mine.noneUpcoming", "No upcoming shifts.") }}
|
|
135
|
-
</p>
|
|
136
|
-
</SectionCard>
|
|
137
103
|
<SectionCard
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
:title="format.day(group.day)"
|
|
141
|
-
flush
|
|
104
|
+
:title="t('mine.calendar', 'Calendar')"
|
|
105
|
+
icon="i-lucide-calendar"
|
|
142
106
|
>
|
|
143
107
|
<template
|
|
144
|
-
v-if="
|
|
108
|
+
v-if="picked"
|
|
145
109
|
#actions
|
|
146
110
|
>
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
variant="
|
|
150
|
-
|
|
111
|
+
<UButton
|
|
112
|
+
color="neutral"
|
|
113
|
+
variant="ghost"
|
|
114
|
+
size="xs"
|
|
115
|
+
icon="i-lucide-x"
|
|
116
|
+
:label="t('mine.showAll', 'Show all days')"
|
|
117
|
+
@click="picked = void 0"
|
|
151
118
|
/>
|
|
152
119
|
</template>
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
120
|
+
<UCalendar
|
|
121
|
+
v-model="picked"
|
|
122
|
+
:week-starts-on="1"
|
|
123
|
+
class="w-full"
|
|
124
|
+
>
|
|
125
|
+
<template #day="{ day }">
|
|
126
|
+
<UChip
|
|
127
|
+
:show="workDays.has(keyOf(day))"
|
|
128
|
+
size="2xs"
|
|
129
|
+
position="bottom-right"
|
|
161
130
|
>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
</span>
|
|
167
|
-
</div>
|
|
168
|
-
<div class="flex shrink-0 items-center gap-2">
|
|
169
|
-
<StatusBadge
|
|
170
|
-
:status="item.swap ? item.swap.status : item.assignment.status"
|
|
171
|
-
:label="statusLabel(item)"
|
|
172
|
-
:colors="{ assigned: 'info', attended: 'success', no_show: 'error', open: 'warning', offered: 'warning', pending_approval: 'warning' }"
|
|
173
|
-
/>
|
|
174
|
-
<UIcon
|
|
175
|
-
name="i-lucide-chevron-right"
|
|
176
|
-
class="text-dimmed size-4"
|
|
177
|
-
/>
|
|
178
|
-
</div>
|
|
179
|
-
</ULink>
|
|
180
|
-
</li>
|
|
181
|
-
</ul>
|
|
131
|
+
{{ day.day }}
|
|
132
|
+
</UChip>
|
|
133
|
+
</template>
|
|
134
|
+
</UCalendar>
|
|
182
135
|
</SectionCard>
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
136
|
+
|
|
137
|
+
<div class="flex flex-col gap-4">
|
|
138
|
+
<SectionCard v-if="!groups.length">
|
|
139
|
+
<p class="text-muted text-sm">
|
|
140
|
+
{{ picked ? t("mine.noneThatDay", "No shifts on that day.") : t("mine.noneUpcoming", "No upcoming shifts.") }}
|
|
141
|
+
</p>
|
|
142
|
+
</SectionCard>
|
|
143
|
+
<SectionCard
|
|
144
|
+
v-for="group in groups"
|
|
145
|
+
:key="group.day"
|
|
146
|
+
:title="format.day(group.day)"
|
|
147
|
+
flush
|
|
148
|
+
>
|
|
149
|
+
<template
|
|
150
|
+
v-if="group.day === today"
|
|
151
|
+
#actions
|
|
152
|
+
>
|
|
153
|
+
<UBadge
|
|
154
|
+
size="sm"
|
|
155
|
+
variant="subtle"
|
|
156
|
+
:label="t('mine.today', 'Today')"
|
|
157
|
+
/>
|
|
158
|
+
</template>
|
|
159
|
+
<ul class="divide-default divide-y">
|
|
160
|
+
<li
|
|
161
|
+
v-for="item in group.items"
|
|
162
|
+
:key="item.assignment.id"
|
|
163
|
+
>
|
|
164
|
+
<ULink
|
|
165
|
+
:to="links.shift(item.assignment.id)"
|
|
166
|
+
class="hover:bg-elevated/50 flex items-center justify-between gap-3 px-4 py-3 transition"
|
|
167
|
+
>
|
|
168
|
+
<div class="flex min-w-0 flex-col">
|
|
169
|
+
<span class="text-highlighted font-medium tabular-nums">{{ format.time(item.shift.startsAt) }}–{{ format.time(item.shift.endsAt) }}</span>
|
|
170
|
+
<span class="text-muted truncate text-sm">
|
|
171
|
+
{{ tr(item.teamName) }}<template v-if="item.roleName"> · {{ tr(item.roleName) }}</template> · {{ tr(item.operationName) }}
|
|
172
|
+
</span>
|
|
173
|
+
</div>
|
|
174
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
175
|
+
<StatusBadge
|
|
176
|
+
:status="item.swap ? item.swap.status : item.assignment.status"
|
|
177
|
+
:label="statusLabel(item)"
|
|
178
|
+
:colors="{ assigned: 'info', attended: 'success', no_show: 'error', open: 'warning', offered: 'warning', pending_approval: 'warning' }"
|
|
179
|
+
/>
|
|
180
|
+
<UIcon
|
|
181
|
+
name="i-lucide-chevron-right"
|
|
182
|
+
class="text-dimmed size-4"
|
|
183
|
+
/>
|
|
184
|
+
</div>
|
|
185
|
+
</ULink>
|
|
186
|
+
</li>
|
|
187
|
+
</ul>
|
|
188
|
+
</SectionCard>
|
|
189
|
+
<UButton
|
|
190
|
+
v-if="!picked && pastCount"
|
|
191
|
+
color="neutral"
|
|
192
|
+
variant="ghost"
|
|
193
|
+
class="self-start"
|
|
194
|
+
:label="showPast ? t('mine.hidePast', 'Hide past shifts') : t('mine.showPast', 'Show {count} past shifts', { count: pastCount })"
|
|
195
|
+
@click="showPast = !showPast"
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
191
198
|
</div>
|
|
192
|
-
</
|
|
199
|
+
</template>
|
|
193
200
|
</div>
|
|
194
201
|
</template>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { shiftsApi } from "../../utils/api";
|
|
3
3
|
import { SHIFT_SWAP_OFFER_STATUS_LABELS } from "../../utils/status";
|
|
4
4
|
import { allowsSwapKind } from "../../utils/settings";
|
|
5
|
-
import { $fetch, computed, errorMessage, navigateTo, onMounted, reactive, ref, useAction, useAuthPages,
|
|
5
|
+
import { $fetch, computed, errorMessage, navigateTo, onMounted, reactive, ref, useAction, useAuthPages, useCachedFetch, useModuleT, useRoute, useShiftsFormat, useShiftsLinks, useShiftsTranslate, watch } from "#imports";
|
|
6
6
|
defineOptions({ name: "ShiftsHomeSwapsTab" });
|
|
7
7
|
const t = useModuleT("shifts");
|
|
8
8
|
const tr = useShiftsTranslate();
|
|
@@ -10,9 +10,10 @@ const format = useShiftsFormat();
|
|
|
10
10
|
const links = useShiftsLinks();
|
|
11
11
|
const { busy, run } = useAction();
|
|
12
12
|
const route = useRoute();
|
|
13
|
-
const { data:
|
|
14
|
-
const { data:
|
|
15
|
-
const
|
|
13
|
+
const { data: fetchedSwaps, error, loading, refresh } = useCachedFetch(shiftsApi.swaps, { key: "shifts:swaps", ttl: 0, lazy: true });
|
|
14
|
+
const { data: fetchedMine, refresh: refreshMine } = useCachedFetch(shiftsApi.me.shifts, { key: "shifts:me", ttl: 0, lazy: true });
|
|
15
|
+
const swaps = computed(() => fetchedSwaps.value ?? []);
|
|
16
|
+
const mine = computed(() => fetchedMine.value ?? []);
|
|
16
17
|
watch(() => error.value?.statusCode, async (code) => {
|
|
17
18
|
if (code === 401) await navigateTo({ path: useAuthPages().login, query: { redirect: route.fullPath } });
|
|
18
19
|
}, { immediate: true });
|
|
@@ -79,7 +80,7 @@ async function withdraw(swap) {
|
|
|
79
80
|
/>
|
|
80
81
|
</div>
|
|
81
82
|
<UEmpty
|
|
82
|
-
v-else-if="error && error.statusCode !== 401"
|
|
83
|
+
v-else-if="error && error.statusCode !== 401 && !swaps.length"
|
|
83
84
|
icon="i-lucide-circle-alert"
|
|
84
85
|
:title="t('swaps.loadFailed', 'The swaps could not be loaded')"
|
|
85
86
|
:description="errorMessage(error, '')"
|
|
@@ -96,6 +97,11 @@ async function withdraw(swap) {
|
|
|
96
97
|
class="flex flex-col gap-3"
|
|
97
98
|
data-shifts-swaps
|
|
98
99
|
>
|
|
100
|
+
<!-- Offline or a failed refresh: the last data stays, with a quiet note. -->
|
|
101
|
+
<StaleDataNotice
|
|
102
|
+
:error="error"
|
|
103
|
+
:refresh="refresh"
|
|
104
|
+
/>
|
|
99
105
|
<SectionCard
|
|
100
106
|
v-for="swap in swaps"
|
|
101
107
|
:key="swap.id"
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
"locationHelp": "Frivillige trykker \"Jeg er her\", og appen sender deres placering. Den kan forfalskes af en, der vil.",
|
|
267
267
|
"station": "Station",
|
|
268
268
|
"stationHelp": "Frivillige scanner den skiftende QR-kode på en af holdets stationer.",
|
|
269
|
-
"stationNeedsKey": "Kræver
|
|
269
|
+
"stationNeedsKey": "Kræver NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY) på serveren."
|
|
270
270
|
},
|
|
271
271
|
"modesHint": "Ud over at en leder scanner passet.",
|
|
272
272
|
"modesLabel": "Måder at tjekke ind",
|
|
@@ -279,8 +279,8 @@
|
|
|
279
279
|
"saved": "Gemte tjek ind for {name}",
|
|
280
280
|
"scanStation": "Scan stationens kode",
|
|
281
281
|
"stationKeyMissing": "Tjek ind ved station kræver en stationsnøgle",
|
|
282
|
-
"stationKeyMissingHint": "Sæt NUXT_SHIFTS_STATION_KEY på serveren for at bruge tjek ind ved station og stationsskærme. De andre tilstande virker uden den.",
|
|
283
|
-
"stationKeyMissingInUse": "Tjek ind ved station er slået til, men serveren har
|
|
282
|
+
"stationKeyMissingHint": "Sæt NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY) på serveren for at bruge tjek ind ved station og stationsskærme. De andre tilstande virker uden den.",
|
|
283
|
+
"stationKeyMissingInUse": "Tjek ind ved station er slået til, men serveren har hverken NUXT_APP_SECRET eller NUXT_SHIFTS_STATION_KEY: frivillige kan ikke tjekke ind ved en station, og stationsskærme åbner ikke. Sæt NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY), eller slå tilstanden fra. De andre tilstande virker.",
|
|
284
284
|
"stopScanning": "Stop scanning",
|
|
285
285
|
"title": "Sådan tjekker frivillige ind"
|
|
286
286
|
},
|
|
@@ -425,6 +425,8 @@
|
|
|
425
425
|
"attendDescription": "Tjek ind på dine egne vagter ved at scanne en stations kode eller med din placering.",
|
|
426
426
|
"broadcast": "Skriv til vagtholdene",
|
|
427
427
|
"broadcastDescription": "Send en mail (og en sms, med vilje) til medlemmerne af et events hold eller folkene på en vagt.",
|
|
428
|
+
"checkin": "Tjek folk ind på alle vagter",
|
|
429
|
+
"checkinDescription": "Tjek hvem som helst ind på enhver vagt ved at scanne deres QR-pas, på alle hold og events, uden at lede holdet.",
|
|
428
430
|
"feed": "Abonnér på dine vagter i en kalender",
|
|
429
431
|
"feedDescription": "Opret og træk det hemmelige kalenderabonnement (iCal) med dine egne vagter tilbage.",
|
|
430
432
|
"lead": "Led vagter",
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
"locationHelp": "Volunteers tap \"I'm here\" and the app sends their position. A determined person can fake it.",
|
|
267
267
|
"station": "Station",
|
|
268
268
|
"stationHelp": "Volunteers scan the rotating QR code of a station of their team.",
|
|
269
|
-
"stationNeedsKey": "Needs
|
|
269
|
+
"stationNeedsKey": "Needs NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server."
|
|
270
270
|
},
|
|
271
271
|
"modesHint": "Besides a lead scanning the pass.",
|
|
272
272
|
"modesLabel": "Check-in modes",
|
|
@@ -279,8 +279,8 @@
|
|
|
279
279
|
"saved": "Saved the check-in of {name}",
|
|
280
280
|
"scanStation": "Scan the station code",
|
|
281
281
|
"stationKeyMissing": "Station check-in needs a station key",
|
|
282
|
-
"stationKeyMissingHint": "Set NUXT_SHIFTS_STATION_KEY on the server to use station check-in and station screens. The other modes work without it.",
|
|
283
|
-
"stationKeyMissingInUse": "Station check-in is on, but the server has
|
|
282
|
+
"stationKeyMissingHint": "Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server to use station check-in and station screens. The other modes work without it.",
|
|
283
|
+
"stationKeyMissingInUse": "Station check-in is on, but the server has neither NUXT_APP_SECRET nor NUXT_SHIFTS_STATION_KEY: volunteers cannot check in by station and station screens do not open. Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY), or turn the mode off. The other modes work.",
|
|
284
284
|
"stopScanning": "Stop scanning",
|
|
285
285
|
"title": "How volunteers check in"
|
|
286
286
|
},
|
|
@@ -425,6 +425,8 @@
|
|
|
425
425
|
"attendDescription": "Check in on your own shifts by scanning a station's code or by your location.",
|
|
426
426
|
"broadcast": "Message shift teams",
|
|
427
427
|
"broadcastDescription": "Send an email (and an SMS, on purpose) to the members of an operation's teams or the people on a shift.",
|
|
428
|
+
"checkin": "Check people in on any shift",
|
|
429
|
+
"checkinDescription": "Check anyone in on any shift by scanning their QR pass, on every team and operation, without leading the team.",
|
|
428
430
|
"feed": "Subscribe to your shifts in a calendar",
|
|
429
431
|
"feedDescription": "Create and revoke the secret calendar feed (iCal) of your own shifts.",
|
|
430
432
|
"lead": "Lead shifts",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { notFound } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { shiftsAccess } from "../../../access.js";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const principal = await requireAuth(event);
|
|
5
|
+
const anyShift = await allows(event, shiftsAccess.permissions.checkin);
|
|
6
|
+
if (!anyShift) await authorize(event, shiftsAccess.permissions.lead);
|
|
7
|
+
const { code } = await readValidatedBody(event, shiftsCheckInInput.parse);
|
|
8
|
+
const entry = await shiftsAssignmentByCode(code);
|
|
9
|
+
if (!entry) throw notFound("Unknown check-in code.");
|
|
10
|
+
if (!anyShift && !await allows(event, shiftsAccess.permissions.lead, { teamId: entry.shift.teamId })) throw notFound("Unknown check-in code.");
|
|
11
|
+
return shiftsCheckIn(event, code, Number(principal.user.id), await allows(event, shiftsAccess.permissions.pii), { entry });
|
|
12
|
+
});
|
|
@@ -5,5 +5,5 @@ export default defineEventHandler(async (event) => {
|
|
|
5
5
|
const { teamId } = await getValidatedRouterParams(event, idParams("teamId").parse);
|
|
6
6
|
const { code } = await readValidatedBody(event, shiftsCheckInInput.parse);
|
|
7
7
|
await authorize(event, shiftsAccess.permissions.lead, { teamId });
|
|
8
|
-
return shiftsCheckIn(event,
|
|
8
|
+
return shiftsCheckIn(event, code, Number(principal.user.id), await allows(event, shiftsAccess.permissions.pii), { teamId });
|
|
9
9
|
});
|
|
@@ -61,12 +61,17 @@ export declare function shiftsDailyCascade(event: H3Event | undefined, first: Sh
|
|
|
61
61
|
/** The assignment (with its shift and schedule) a QR pass code belongs to, if any. */
|
|
62
62
|
export declare function shiftsAssignmentByCode(code: string): Promise<ShiftAssignmentEntry | undefined>;
|
|
63
63
|
/**
|
|
64
|
-
* Checks a person in with the code of their QR pass
|
|
65
|
-
* another team's shift
|
|
66
|
-
*
|
|
67
|
-
*
|
|
64
|
+
* Checks a person in with the code of their QR pass. With `teamId` (a team's scanner: a lead of it, or staff), a code of
|
|
65
|
+
* another team's shift is a 404 like an unknown one (a lead learns nothing about other teams); without it the caller has
|
|
66
|
+
* decided access already (`POST /api/shifts/check-in`). `entry` is the code's assignment when the caller resolved it
|
|
67
|
+
* already. A cancelled assignment is a 409 `assignment_cancelled`; outside the check-in window a 409 `outside_window`.
|
|
68
|
+
* Scanning twice is fine: the second scan reports `alreadyCheckedIn` with the first scan's time. Fires
|
|
69
|
+
* `shifts:attendance:marked` once.
|
|
68
70
|
*/
|
|
69
|
-
export declare function shiftsCheckIn(event: H3Event,
|
|
71
|
+
export declare function shiftsCheckIn(event: H3Event, code: string, by: number, pii: boolean, options?: {
|
|
72
|
+
teamId?: string;
|
|
73
|
+
entry?: ShiftAssignmentEntry;
|
|
74
|
+
}): Promise<ShiftCheckInDto>;
|
|
70
75
|
/**
|
|
71
76
|
* A volunteer checks in on one of their own shifts (`POST /api/shifts/me/:assignmentId/check-in`), by a mode the
|
|
72
77
|
* team's rule has on (409 `mode_disabled` otherwise):
|
|
@@ -175,9 +175,9 @@ export async function shiftsAssignmentByCode(code) {
|
|
|
175
175
|
const [found] = await db.select({ id: schema.shiftAssignments.id }).from(schema.shiftAssignments).where(eq(schema.shiftAssignments.checkInCode, code)).limit(1);
|
|
176
176
|
return found ? findShiftAssignmentEntry(found.id) : void 0;
|
|
177
177
|
}
|
|
178
|
-
export async function shiftsCheckIn(event,
|
|
179
|
-
const entry = await shiftsAssignmentByCode(code);
|
|
180
|
-
if (!entry || entry.shift.teamId !== teamId) throw notFound("Unknown check-in code.");
|
|
178
|
+
export async function shiftsCheckIn(event, code, by, pii, options = {}) {
|
|
179
|
+
const entry = options.entry ?? await shiftsAssignmentByCode(code);
|
|
180
|
+
if (!entry || options.teamId !== void 0 && entry.shift.teamId !== options.teamId) throw notFound("Unknown check-in code.");
|
|
181
181
|
const { assignment, shift, schedule } = entry;
|
|
182
182
|
if (assignment.status === "cancelled") throw apiError(409, "assignment_cancelled", "This assignment was cancelled.");
|
|
183
183
|
if (!await shiftsStillEligible(event, assignment, shift.teamId)) {
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The secret station tokens are signed with: `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`), else one derived from
|
|
4
|
+
* `appSecret` (`NUXT_APP_SECRET`); empty when neither is set, or when the station key is set but too short.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shiftsStationSecret(event?: H3Event): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Whether station check-in and station screens work: `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`) is set and long
|
|
9
|
+
* enough, or it is unset and `appSecret` (`NUXT_APP_SECRET`) is.
|
|
10
|
+
*/
|
|
5
11
|
export declare function shiftsStationKeyConfigured(event?: H3Event): boolean;
|
|
6
|
-
/** 501 `not_configured`
|
|
12
|
+
/** The 501 `not_configured` of station check-in without a station secret. */
|
|
13
|
+
export declare function shiftsStationKeyMissing(): import("h3").H3Error<{
|
|
14
|
+
code: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** 501 `not_configured` unless {@link shiftsStationKeyConfigured}. */
|
|
7
17
|
export declare function shiftsRequireStationKey(event?: H3Event): void;
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import { notConfigured } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { APP_SECRET_MIN_LENGTH, resolveSecret } from "@frigear-nu/module-kit/secret";
|
|
2
3
|
import { shiftsStationKeyIssue } from "../../utils/station-key.js";
|
|
4
|
+
const STATION_SECRET_PURPOSE = "@frigear-nu/shifts:station";
|
|
3
5
|
let reported;
|
|
4
|
-
|
|
6
|
+
function ownStationKey(event) {
|
|
5
7
|
const config = useRuntimeConfig(event);
|
|
6
8
|
const secret = config.shifts?.stationKey;
|
|
7
9
|
const issue = shiftsStationKeyIssue(secret);
|
|
8
10
|
if (issue) {
|
|
9
11
|
if (reported !== issue) console.error(issue);
|
|
10
12
|
reported = issue;
|
|
11
|
-
return "";
|
|
13
|
+
return { key: "", invalid: true };
|
|
12
14
|
}
|
|
13
|
-
return typeof secret === "string" ? secret.trim() : "";
|
|
15
|
+
return { key: typeof secret === "string" ? secret.trim() : "", invalid: false };
|
|
16
|
+
}
|
|
17
|
+
function appSecretSet(event) {
|
|
18
|
+
const root = useRuntimeConfig(event).appSecret;
|
|
19
|
+
return typeof root === "string" && root.length >= APP_SECRET_MIN_LENGTH;
|
|
20
|
+
}
|
|
21
|
+
export async function shiftsStationSecret(event) {
|
|
22
|
+
const own = ownStationKey(event);
|
|
23
|
+
if (own.invalid) return "";
|
|
24
|
+
if (!own.key && !appSecretSet(event)) return "";
|
|
25
|
+
return resolveSecret(STATION_SECRET_PURPOSE, own.key);
|
|
14
26
|
}
|
|
15
27
|
export function shiftsStationKeyConfigured(event) {
|
|
16
|
-
|
|
28
|
+
const own = ownStationKey(event);
|
|
29
|
+
if (own.invalid) return false;
|
|
30
|
+
return own.key !== "" || appSecretSet(event);
|
|
31
|
+
}
|
|
32
|
+
export function shiftsStationKeyMissing() {
|
|
33
|
+
return notConfigured("Station check-in is not set up: set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY, at least 32 characters) on the server.");
|
|
17
34
|
}
|
|
18
35
|
export function shiftsRequireStationKey(event) {
|
|
19
|
-
if (!shiftsStationKeyConfigured(event))
|
|
20
|
-
throw notConfigured("Station check-in is not set up: the server has no station key of at least 32 characters (NUXT_SHIFTS_STATION_KEY).");
|
|
21
|
-
}
|
|
36
|
+
if (!shiftsStationKeyConfigured(event)) throw shiftsStationKeyMissing();
|
|
22
37
|
}
|
|
@@ -7,12 +7,13 @@ import { newId } from "../../utils/index.js";
|
|
|
7
7
|
import { STATION_ROTATE_SECONDS, parseStationToken, stationTokenPayload, stationWindow, stationWindowAccepted } from "../../utils/checkin.js";
|
|
8
8
|
import { toShiftStationDto } from "./shifts-dto.js";
|
|
9
9
|
import { shiftsOperationTeamOr400 } from "./shifts-core.js";
|
|
10
|
-
import { shiftsRequireStationKey, shiftsStationSecret } from "./shifts-station-key.js";
|
|
10
|
+
import { shiftsRequireStationKey, shiftsStationKeyMissing, shiftsStationSecret } from "./shifts-station-key.js";
|
|
11
11
|
const encoder = new TextEncoder();
|
|
12
12
|
const stationKeys = /* @__PURE__ */ new Map();
|
|
13
|
-
function shiftsStationKey(event) {
|
|
13
|
+
async function shiftsStationKey(event) {
|
|
14
14
|
shiftsRequireStationKey(event);
|
|
15
|
-
const secret = shiftsStationSecret(event);
|
|
15
|
+
const secret = await shiftsStationSecret(event);
|
|
16
|
+
if (!secret) throw shiftsStationKeyMissing();
|
|
16
17
|
let key = stationKeys.get(secret);
|
|
17
18
|
if (!key) {
|
|
18
19
|
key = deriveHkdfKey(secret, { salt: "@frigear-nu/shifts", info: "shift_station_tokens" }, { name: "HMAC", hash: "SHA-256", length: 256 }, ["sign", "verify"]);
|
|
@@ -39,6 +39,8 @@ export declare const shiftsApi: {
|
|
|
39
39
|
readonly approveSwap: (swapId: string) => string;
|
|
40
40
|
/** `POST` (a lead of the team, or staff) to reject a swap waiting for approval: it is open again. */
|
|
41
41
|
readonly rejectSwap: (swapId: string) => string;
|
|
42
|
+
/** `POST` `{ code }` to check a person in with their QR pass on any shift (`shifts:checkin`, or a lead of the code's team). */
|
|
43
|
+
readonly checkIn: "/api/shifts/check-in";
|
|
42
44
|
readonly teams: {
|
|
43
45
|
/** `POST` `{ code }` to check a person in with their QR pass (a lead of the team, or staff). */
|
|
44
46
|
readonly checkIn: (teamId: string) => string;
|
|
@@ -42,6 +42,8 @@ export const shiftsApi = {
|
|
|
42
42
|
approveSwap: (swapId) => `${BASE}/swaps/${enc(swapId)}/approve`,
|
|
43
43
|
/** `POST` (a lead of the team, or staff) to reject a swap waiting for approval: it is open again. */
|
|
44
44
|
rejectSwap: (swapId) => `${BASE}/swaps/${enc(swapId)}/reject`,
|
|
45
|
+
/** `POST` `{ code }` to check a person in with their QR pass on any shift (`shifts:checkin`, or a lead of the code's team). */
|
|
46
|
+
checkIn: `${BASE}/check-in`,
|
|
45
47
|
teams: {
|
|
46
48
|
/** `POST` `{ code }` to check a person in with their QR pass (a lead of the team, or staff). */
|
|
47
49
|
checkIn: (teamId) => `${BASE}/teams/${enc(teamId)}/check-in`,
|
|
@@ -29,6 +29,8 @@ export declare const SHIFTS_DEFAULT_PAGES: {
|
|
|
29
29
|
readonly lead: "/shifts/lead/:teamId";
|
|
30
30
|
readonly station: "/shifts/station/:stationId";
|
|
31
31
|
};
|
|
32
|
+
/** Where one shift goes below the crew home when that home is in the signed-in hub (`/dashboard/crew/shifts/:assignmentId`). */
|
|
33
|
+
export declare const SHIFTS_HUB_SHIFT_SEGMENT = "shifts/:assignmentId";
|
|
32
34
|
/**
|
|
33
35
|
* Builds every link to a shifts page through `localize` (the active locale's prefix, see `useLocaleLink` of
|
|
34
36
|
* `@frigear-nu/ui`). My shifts and the swaps link to their tab of the crew home when they have no page. A page that is
|
|
@@ -9,6 +9,7 @@ export const SHIFTS_DEFAULT_PAGES = {
|
|
|
9
9
|
lead: "/shifts/lead/:teamId",
|
|
10
10
|
station: "/shifts/station/:stationId"
|
|
11
11
|
};
|
|
12
|
+
export const SHIFTS_HUB_SHIFT_SEGMENT = "shifts/:assignmentId";
|
|
12
13
|
export function createShiftsLinks(pages, localize) {
|
|
13
14
|
return {
|
|
14
15
|
shifts: () => localize(shiftsMinePath(pages) || SHIFTS_DEFAULT_PAGES.shifts),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/** The shortest station key shifts accepts: station codes are signed with a key derived from it. */
|
|
2
2
|
export declare const SHIFTS_STATION_KEY_MIN_LENGTH = 32;
|
|
3
3
|
/**
|
|
4
|
-
* Why `value` cannot be the station key, or `undefined` when it can. An empty key is allowed (
|
|
5
|
-
* off); a set key must be at least
|
|
4
|
+
* Why `value` cannot be the station key, or `undefined` when it can. An empty key is allowed (a key derived from
|
|
5
|
+
* `NUXT_APP_SECRET` stands in, else station check-in is off); a set key must be at least
|
|
6
|
+
* {@link SHIFTS_STATION_KEY_MIN_LENGTH} characters once trimmed.
|
|
6
7
|
*/
|
|
7
8
|
export declare function shiftsStationKeyIssue(value: unknown): string | undefined;
|
|
8
9
|
/** Throws the {@link shiftsStationKeyIssue} of `value`, if any. */
|
|
@@ -4,7 +4,7 @@ export function shiftsStationKeyIssue(value) {
|
|
|
4
4
|
if (typeof value !== "string") return "[shifts] NUXT_SHIFTS_STATION_KEY (`shifts.stationKey`) must be a string.";
|
|
5
5
|
const length = value.trim().length;
|
|
6
6
|
if (length === 0 || length >= SHIFTS_STATION_KEY_MIN_LENGTH) return void 0;
|
|
7
|
-
return `[shifts] NUXT_SHIFTS_STATION_KEY (\`shifts.stationKey\`) is ${length} characters long; it must be at least ${SHIFTS_STATION_KEY_MIN_LENGTH}. Use a long random value of its own, such as the output of \`openssl rand -base64 32\`, or leave it empty to
|
|
7
|
+
return `[shifts] NUXT_SHIFTS_STATION_KEY (\`shifts.stationKey\`) is ${length} characters long; it must be at least ${SHIFTS_STATION_KEY_MIN_LENGTH}. Use a long random value of its own, such as the output of \`openssl rand -base64 32\`, or leave it empty to derive one from NUXT_APP_SECRET.`;
|
|
8
8
|
}
|
|
9
9
|
export function assertShiftsStationKey(value) {
|
|
10
10
|
const issue = shiftsStationKeyIssue(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/shifts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Shifts for the frigear ecosystem: schedules, shift roles, assignment, swaps, QR check-in and who is on shift now, per operation, built on crew and teams.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/volunteering/shifts",
|
|
6
6
|
"repository": {
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"playground"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@frigear-nu/auth": "^0.6.
|
|
39
|
-
"@frigear-nu/crew": "^0.1.
|
|
40
|
-
"@frigear-nu/maps": "^0.0.
|
|
41
|
-
"@frigear-nu/module-kit": "^1.3.
|
|
42
|
-
"@frigear-nu/notify": "^0.
|
|
43
|
-
"@frigear-nu/operations": "^0.1.
|
|
44
|
-
"@frigear-nu/teams": "^0.1.
|
|
45
|
-
"@frigear-nu/ui": "^0.2.
|
|
46
|
-
"@frigear-nu/users": "^3.1.
|
|
38
|
+
"@frigear-nu/auth": "^0.6.8",
|
|
39
|
+
"@frigear-nu/crew": "^0.1.3",
|
|
40
|
+
"@frigear-nu/maps": "^0.0.3",
|
|
41
|
+
"@frigear-nu/module-kit": "^1.3.12",
|
|
42
|
+
"@frigear-nu/notify": "^0.3.1",
|
|
43
|
+
"@frigear-nu/operations": "^0.1.2",
|
|
44
|
+
"@frigear-nu/teams": "^0.1.3",
|
|
45
|
+
"@frigear-nu/ui": "^0.2.11",
|
|
46
|
+
"@frigear-nu/users": "^3.1.5",
|
|
47
47
|
"@libsql/client": "^0.18.0",
|
|
48
48
|
"@nuxt/kit": "^4.6.4",
|
|
49
49
|
"@vueuse/core": "^15.0.0",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@frigear-nu/admin": "^0.5.2",
|
|
59
|
-
"@frigear-nu/dashboard": "^0.1.
|
|
60
|
-
"@frigear-nu/email-templates": "^0.1.
|
|
59
|
+
"@frigear-nu/dashboard": "^0.1.3",
|
|
60
|
+
"@frigear-nu/email-templates": "^0.1.5",
|
|
61
61
|
"@frigear-nu/menu": "^0.4.1",
|
|
62
|
-
"@frigear-nu/mobile": "^0.6.
|
|
63
|
-
"@frigear-nu/widget": "^0.4.
|
|
62
|
+
"@frigear-nu/mobile": "^0.6.4",
|
|
63
|
+
"@frigear-nu/widget": "^0.4.3",
|
|
64
64
|
"@nuxt/ui": "^4.12.0",
|
|
65
65
|
"@nuxthub/core": "^0.10.12"
|
|
66
66
|
},
|
|
@@ -89,14 +89,14 @@
|
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@frigear-nu/admin": "^0.5.2",
|
|
92
|
-
"@frigear-nu/dashboard": "^0.1.
|
|
93
|
-
"@frigear-nu/email-templates": "^0.1.
|
|
94
|
-
"@frigear-nu/forms": "^0.5.
|
|
92
|
+
"@frigear-nu/dashboard": "^0.1.3",
|
|
93
|
+
"@frigear-nu/email-templates": "^0.1.5",
|
|
94
|
+
"@frigear-nu/forms": "^0.5.5",
|
|
95
95
|
"@frigear-nu/menu": "^0.4.1",
|
|
96
|
-
"@frigear-nu/mobile": "^0.6.
|
|
97
|
-
"@frigear-nu/preferences": "^0.3.
|
|
98
|
-
"@frigear-nu/push": "^0.1.
|
|
99
|
-
"@frigear-nu/widget": "^0.4.
|
|
96
|
+
"@frigear-nu/mobile": "^0.6.4",
|
|
97
|
+
"@frigear-nu/preferences": "^0.3.5",
|
|
98
|
+
"@frigear-nu/push": "^0.1.3",
|
|
99
|
+
"@frigear-nu/widget": "^0.4.3",
|
|
100
100
|
"@nuxt/devtools": "^4.2.0",
|
|
101
101
|
"@nuxt/eslint-config": "^1.17.0",
|
|
102
102
|
"@nuxt/module-builder": "^1.0.4",
|