@frigear-nu/shifts 0.0.0-stage → 0.0.1

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 (345) hide show
  1. package/README.md +53 -2
  2. package/dist/module.d.mts +716 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +272 -0
  5. package/dist/runtime/access.d.ts +2 -0
  6. package/dist/runtime/access.js +84 -0
  7. package/dist/runtime/app/components/ShiftBroadcastSlideover.d.vue.ts +19 -0
  8. package/dist/runtime/app/components/ShiftBroadcastSlideover.vue +142 -0
  9. package/dist/runtime/app/components/ShiftBroadcastSlideover.vue.d.ts +19 -0
  10. package/dist/runtime/app/components/ShiftBroadcastsCard.d.vue.ts +9 -0
  11. package/dist/runtime/app/components/ShiftBroadcastsCard.vue +74 -0
  12. package/dist/runtime/app/components/ShiftBroadcastsCard.vue.d.ts +9 -0
  13. package/dist/runtime/app/components/ShiftBulkSlideover.d.vue.ts +15 -0
  14. package/dist/runtime/app/components/ShiftBulkSlideover.vue +185 -0
  15. package/dist/runtime/app/components/ShiftBulkSlideover.vue.d.ts +15 -0
  16. package/dist/runtime/app/components/ShiftCheckInCard.d.vue.ts +13 -0
  17. package/dist/runtime/app/components/ShiftCheckInCard.vue +238 -0
  18. package/dist/runtime/app/components/ShiftCheckInCard.vue.d.ts +13 -0
  19. package/dist/runtime/app/components/ShiftCopySlideover.d.vue.ts +11 -0
  20. package/dist/runtime/app/components/ShiftCopySlideover.vue +71 -0
  21. package/dist/runtime/app/components/ShiftCopySlideover.vue.d.ts +11 -0
  22. package/dist/runtime/app/components/ShiftDayView.d.vue.ts +16 -0
  23. package/dist/runtime/app/components/ShiftDayView.vue +124 -0
  24. package/dist/runtime/app/components/ShiftDayView.vue.d.ts +16 -0
  25. package/dist/runtime/app/components/ShiftFeedSlideover.d.vue.ts +7 -0
  26. package/dist/runtime/app/components/ShiftFeedSlideover.vue +172 -0
  27. package/dist/runtime/app/components/ShiftFeedSlideover.vue.d.ts +7 -0
  28. package/dist/runtime/app/components/ShiftNowCard.d.vue.ts +6 -0
  29. package/dist/runtime/app/components/ShiftNowCard.vue +83 -0
  30. package/dist/runtime/app/components/ShiftNowCard.vue.d.ts +6 -0
  31. package/dist/runtime/app/components/ShiftPassFullscreen.d.vue.ts +13 -0
  32. package/dist/runtime/app/components/ShiftPassFullscreen.vue +79 -0
  33. package/dist/runtime/app/components/ShiftPassFullscreen.vue.d.ts +13 -0
  34. package/dist/runtime/app/components/ShiftPerkSlideover.d.vue.ts +14 -0
  35. package/dist/runtime/app/components/ShiftPerkSlideover.vue +103 -0
  36. package/dist/runtime/app/components/ShiftPerkSlideover.vue.d.ts +14 -0
  37. package/dist/runtime/app/components/ShiftPerksCard.d.vue.ts +8 -0
  38. package/dist/runtime/app/components/ShiftPerksCard.vue +66 -0
  39. package/dist/runtime/app/components/ShiftPerksCard.vue.d.ts +8 -0
  40. package/dist/runtime/app/components/ShiftQrScanner.d.vue.ts +10 -0
  41. package/dist/runtime/app/components/ShiftQrScanner.vue +44 -0
  42. package/dist/runtime/app/components/ShiftQrScanner.vue.d.ts +10 -0
  43. package/dist/runtime/app/components/ShiftRoleSlideover.d.vue.ts +15 -0
  44. package/dist/runtime/app/components/ShiftRoleSlideover.vue +88 -0
  45. package/dist/runtime/app/components/ShiftRoleSlideover.vue.d.ts +15 -0
  46. package/dist/runtime/app/components/ShiftScheduleSettingsFields.d.vue.ts +11 -0
  47. package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue +61 -0
  48. package/dist/runtime/app/components/ShiftScheduleSettingsFields.vue.d.ts +11 -0
  49. package/dist/runtime/app/components/ShiftScheduleSlideover.d.vue.ts +12 -0
  50. package/dist/runtime/app/components/ShiftScheduleSlideover.vue +129 -0
  51. package/dist/runtime/app/components/ShiftScheduleSlideover.vue.d.ts +12 -0
  52. package/dist/runtime/app/components/ShiftSlideover.d.vue.ts +13 -0
  53. package/dist/runtime/app/components/ShiftSlideover.vue +353 -0
  54. package/dist/runtime/app/components/ShiftSlideover.vue.d.ts +13 -0
  55. package/dist/runtime/app/components/ShiftStationSlideover.d.vue.ts +15 -0
  56. package/dist/runtime/app/components/ShiftStationSlideover.vue +92 -0
  57. package/dist/runtime/app/components/ShiftStationSlideover.vue.d.ts +15 -0
  58. package/dist/runtime/app/composables/index.d.ts +6 -0
  59. package/dist/runtime/app/composables/index.js +5 -0
  60. package/dist/runtime/app/composables/useShiftsActions.d.ts +61 -0
  61. package/dist/runtime/app/composables/useShiftsActions.js +224 -0
  62. package/dist/runtime/app/composables/useShiftsFormat.d.ts +12 -0
  63. package/dist/runtime/app/composables/useShiftsFormat.js +14 -0
  64. package/dist/runtime/app/composables/useShiftsLinks.d.ts +12 -0
  65. package/dist/runtime/app/composables/useShiftsLinks.js +6 -0
  66. package/dist/runtime/app/composables/useShiftsTranslate.d.ts +5 -0
  67. package/dist/runtime/app/composables/useShiftsTranslate.js +12 -0
  68. package/dist/runtime/app/composables/useShiftsVenueFeatures.d.ts +17 -0
  69. package/dist/runtime/app/composables/useShiftsVenueFeatures.js +18 -0
  70. package/dist/runtime/app/dashboard/NextShift.d.vue.ts +3 -0
  71. package/dist/runtime/app/dashboard/NextShift.vue +69 -0
  72. package/dist/runtime/app/dashboard/NextShift.vue.d.ts +3 -0
  73. package/dist/runtime/app/dashboard/OpenSwaps.d.vue.ts +3 -0
  74. package/dist/runtime/app/dashboard/OpenSwaps.vue +69 -0
  75. package/dist/runtime/app/dashboard/OpenSwaps.vue.d.ts +3 -0
  76. package/dist/runtime/app/dashboard/TeamOnNow.d.vue.ts +3 -0
  77. package/dist/runtime/app/dashboard/TeamOnNow.vue +72 -0
  78. package/dist/runtime/app/dashboard/TeamOnNow.vue.d.ts +3 -0
  79. package/dist/runtime/app/pages/check-in.d.vue.ts +3 -0
  80. package/dist/runtime/app/pages/check-in.vue +93 -0
  81. package/dist/runtime/app/pages/check-in.vue.d.ts +3 -0
  82. package/dist/runtime/app/pages/lead.d.vue.ts +3 -0
  83. package/dist/runtime/app/pages/lead.vue +300 -0
  84. package/dist/runtime/app/pages/lead.vue.d.ts +3 -0
  85. package/dist/runtime/app/pages/shift.d.vue.ts +3 -0
  86. package/dist/runtime/app/pages/shift.vue +482 -0
  87. package/dist/runtime/app/pages/shift.vue.d.ts +3 -0
  88. package/dist/runtime/app/pages/shifts.d.vue.ts +3 -0
  89. package/dist/runtime/app/pages/shifts.vue +21 -0
  90. package/dist/runtime/app/pages/shifts.vue.d.ts +3 -0
  91. package/dist/runtime/app/pages/station.d.vue.ts +3 -0
  92. package/dist/runtime/app/pages/station.vue +104 -0
  93. package/dist/runtime/app/pages/station.vue.d.ts +3 -0
  94. package/dist/runtime/app/pages/swaps.d.vue.ts +3 -0
  95. package/dist/runtime/app/pages/swaps.vue +32 -0
  96. package/dist/runtime/app/pages/swaps.vue.d.ts +3 -0
  97. package/dist/runtime/app/tabs/HomeShifts.d.vue.ts +6 -0
  98. package/dist/runtime/app/tabs/HomeShifts.vue +194 -0
  99. package/dist/runtime/app/tabs/HomeShifts.vue.d.ts +6 -0
  100. package/dist/runtime/app/tabs/HomeSwaps.d.vue.ts +3 -0
  101. package/dist/runtime/app/tabs/HomeSwaps.vue +188 -0
  102. package/dist/runtime/app/tabs/HomeSwaps.vue.d.ts +3 -0
  103. package/dist/runtime/app/tabs/Shifts.d.vue.ts +9 -0
  104. package/dist/runtime/app/tabs/Shifts.vue +487 -0
  105. package/dist/runtime/app/tabs/Shifts.vue.d.ts +9 -0
  106. package/dist/runtime/app/utils/admin-shifts.d.ts +42 -0
  107. package/dist/runtime/app/utils/admin-shifts.js +36 -0
  108. package/dist/runtime/dashboard.d.ts +8 -0
  109. package/dist/runtime/dashboard.js +30 -0
  110. package/dist/runtime/emails/shifts-broadcast.d.vue.ts +8 -0
  111. package/dist/runtime/emails/shifts-broadcast.vue +24 -0
  112. package/dist/runtime/emails/shifts-broadcast.vue.d.ts +8 -0
  113. package/dist/runtime/emails/shifts-reminder.d.vue.ts +12 -0
  114. package/dist/runtime/emails/shifts-reminder.vue +34 -0
  115. package/dist/runtime/emails/shifts-reminder.vue.d.ts +12 -0
  116. package/dist/runtime/emails/shifts-swap-accepted.d.vue.ts +11 -0
  117. package/dist/runtime/emails/shifts-swap-accepted.vue +32 -0
  118. package/dist/runtime/emails/shifts-swap-accepted.vue.d.ts +11 -0
  119. package/dist/runtime/emails/shifts-swap-completed.d.vue.ts +11 -0
  120. package/dist/runtime/emails/shifts-swap-completed.vue +32 -0
  121. package/dist/runtime/emails/shifts-swap-completed.vue.d.ts +11 -0
  122. package/dist/runtime/emails/shifts-swap-offered.d.vue.ts +11 -0
  123. package/dist/runtime/emails/shifts-swap-offered.vue +32 -0
  124. package/dist/runtime/emails/shifts-swap-offered.vue.d.ts +11 -0
  125. package/dist/runtime/emails/shifts-swap-pending.d.vue.ts +11 -0
  126. package/dist/runtime/emails/shifts-swap-pending.vue +32 -0
  127. package/dist/runtime/emails/shifts-swap-pending.vue.d.ts +11 -0
  128. package/dist/runtime/emails/shifts-swap-proposed.d.vue.ts +11 -0
  129. package/dist/runtime/emails/shifts-swap-proposed.vue +32 -0
  130. package/dist/runtime/emails/shifts-swap-proposed.vue.d.ts +11 -0
  131. package/dist/runtime/emails/shifts-swap-rejected.d.vue.ts +11 -0
  132. package/dist/runtime/emails/shifts-swap-rejected.vue +32 -0
  133. package/dist/runtime/emails/shifts-swap-rejected.vue.d.ts +11 -0
  134. package/dist/runtime/i18n/lang/da.json +627 -0
  135. package/dist/runtime/i18n/lang/en.json +627 -0
  136. package/dist/runtime/notifications.d.ts +9 -0
  137. package/dist/runtime/notifications.js +36 -0
  138. package/dist/runtime/server/db/schema.postgresql.d.ts +2151 -0
  139. package/dist/runtime/server/db/schema.postgresql.js +228 -0
  140. package/dist/runtime/server/db/schema.sqlite.d.ts +2263 -0
  141. package/dist/runtime/server/db/schema.sqlite.js +228 -0
  142. package/dist/runtime/server/digest-email.d.ts +17 -0
  143. package/dist/runtime/server/digest-email.js +42 -0
  144. package/dist/runtime/server/plugins/station-key.d.ts +2 -0
  145. package/dist/runtime/server/plugins/station-key.js +5 -0
  146. package/dist/runtime/server/plugins/teams.d.ts +2 -0
  147. package/dist/runtime/server/plugins/teams.js +19 -0
  148. package/dist/runtime/server/policies.d.ts +2 -0
  149. package/dist/runtime/server/policies.js +41 -0
  150. package/dist/runtime/server/reminder-email.d.ts +67 -0
  151. package/dist/runtime/server/reminder-email.js +109 -0
  152. package/dist/runtime/server/routes/admin/assignment.delete.d.ts +2 -0
  153. package/dist/runtime/server/routes/admin/assignment.delete.js +10 -0
  154. package/dist/runtime/server/routes/admin/assignments.post.d.ts +2 -0
  155. package/dist/runtime/server/routes/admin/assignments.post.js +11 -0
  156. package/dist/runtime/server/routes/admin/broadcasts.get.d.ts +2 -0
  157. package/dist/runtime/server/routes/admin/broadcasts.get.js +8 -0
  158. package/dist/runtime/server/routes/admin/broadcasts.post.d.ts +2 -0
  159. package/dist/runtime/server/routes/admin/broadcasts.post.js +9 -0
  160. package/dist/runtime/server/routes/admin/candidates.get.d.ts +2 -0
  161. package/dist/runtime/server/routes/admin/candidates.get.js +10 -0
  162. package/dist/runtime/server/routes/admin/operation-teams.get.d.ts +2 -0
  163. package/dist/runtime/server/routes/admin/operation-teams.get.js +9 -0
  164. package/dist/runtime/server/routes/admin/perk.delete.d.ts +2 -0
  165. package/dist/runtime/server/routes/admin/perk.delete.js +10 -0
  166. package/dist/runtime/server/routes/admin/perk.patch.d.ts +2 -0
  167. package/dist/runtime/server/routes/admin/perk.patch.js +10 -0
  168. package/dist/runtime/server/routes/admin/perks.get.d.ts +2 -0
  169. package/dist/runtime/server/routes/admin/perks.get.js +9 -0
  170. package/dist/runtime/server/routes/admin/perks.post.d.ts +2 -0
  171. package/dist/runtime/server/routes/admin/perks.post.js +10 -0
  172. package/dist/runtime/server/routes/admin/role.delete.d.ts +2 -0
  173. package/dist/runtime/server/routes/admin/role.delete.js +11 -0
  174. package/dist/runtime/server/routes/admin/role.patch.d.ts +2 -0
  175. package/dist/runtime/server/routes/admin/role.patch.js +11 -0
  176. package/dist/runtime/server/routes/admin/roles.get.d.ts +2 -0
  177. package/dist/runtime/server/routes/admin/roles.get.js +9 -0
  178. package/dist/runtime/server/routes/admin/roles.post.d.ts +2 -0
  179. package/dist/runtime/server/routes/admin/roles.post.js +10 -0
  180. package/dist/runtime/server/routes/admin/schedule-copy.post.d.ts +2 -0
  181. package/dist/runtime/server/routes/admin/schedule-copy.post.js +12 -0
  182. package/dist/runtime/server/routes/admin/schedule-publish.post.d.ts +2 -0
  183. package/dist/runtime/server/routes/admin/schedule-publish.post.js +9 -0
  184. package/dist/runtime/server/routes/admin/schedule.delete.d.ts +2 -0
  185. package/dist/runtime/server/routes/admin/schedule.delete.js +10 -0
  186. package/dist/runtime/server/routes/admin/schedule.get.d.ts +2 -0
  187. package/dist/runtime/server/routes/admin/schedule.get.js +9 -0
  188. package/dist/runtime/server/routes/admin/schedule.patch.d.ts +2 -0
  189. package/dist/runtime/server/routes/admin/schedule.patch.js +10 -0
  190. package/dist/runtime/server/routes/admin/schedules.get.d.ts +2 -0
  191. package/dist/runtime/server/routes/admin/schedules.get.js +10 -0
  192. package/dist/runtime/server/routes/admin/schedules.post.d.ts +2 -0
  193. package/dist/runtime/server/routes/admin/schedules.post.js +9 -0
  194. package/dist/runtime/server/routes/admin/shift.delete.d.ts +2 -0
  195. package/dist/runtime/server/routes/admin/shift.delete.js +10 -0
  196. package/dist/runtime/server/routes/admin/shift.patch.d.ts +2 -0
  197. package/dist/runtime/server/routes/admin/shift.patch.js +10 -0
  198. package/dist/runtime/server/routes/admin/shifts-bulk.post.d.ts +2 -0
  199. package/dist/runtime/server/routes/admin/shifts-bulk.post.js +10 -0
  200. package/dist/runtime/server/routes/admin/shifts.get.d.ts +2 -0
  201. package/dist/runtime/server/routes/admin/shifts.get.js +10 -0
  202. package/dist/runtime/server/routes/admin/station.delete.d.ts +2 -0
  203. package/dist/runtime/server/routes/admin/station.delete.js +11 -0
  204. package/dist/runtime/server/routes/admin/station.patch.d.ts +2 -0
  205. package/dist/runtime/server/routes/admin/station.patch.js +11 -0
  206. package/dist/runtime/server/routes/admin/stations.get.d.ts +2 -0
  207. package/dist/runtime/server/routes/admin/stations.get.js +9 -0
  208. package/dist/runtime/server/routes/admin/stations.post.d.ts +2 -0
  209. package/dist/runtime/server/routes/admin/stations.post.js +10 -0
  210. package/dist/runtime/server/routes/admin/swap-cancel.post.d.ts +2 -0
  211. package/dist/runtime/server/routes/admin/swap-cancel.post.js +10 -0
  212. package/dist/runtime/server/routes/admin/swaps.get.d.ts +2 -0
  213. package/dist/runtime/server/routes/admin/swaps.get.js +10 -0
  214. package/dist/runtime/server/routes/feed/feed.get.d.ts +2 -0
  215. package/dist/runtime/server/routes/feed/feed.get.js +9 -0
  216. package/dist/runtime/server/routes/lead/attended.post.d.ts +2 -0
  217. package/dist/runtime/server/routes/lead/attended.post.js +11 -0
  218. package/dist/runtime/server/routes/lead/broadcast.post.d.ts +2 -0
  219. package/dist/runtime/server/routes/lead/broadcast.post.js +12 -0
  220. package/dist/runtime/server/routes/lead/check-in.post.d.ts +2 -0
  221. package/dist/runtime/server/routes/lead/check-in.post.js +9 -0
  222. package/dist/runtime/server/routes/lead/exceptions.get.d.ts +2 -0
  223. package/dist/runtime/server/routes/lead/exceptions.get.js +8 -0
  224. package/dist/runtime/server/routes/lead/no-show.post.d.ts +2 -0
  225. package/dist/runtime/server/routes/lead/no-show.post.js +11 -0
  226. package/dist/runtime/server/routes/lead/now.get.d.ts +2 -0
  227. package/dist/runtime/server/routes/lead/now.get.js +9 -0
  228. package/dist/runtime/server/routes/lead/on-duty.get.d.ts +2 -0
  229. package/dist/runtime/server/routes/lead/on-duty.get.js +10 -0
  230. package/dist/runtime/server/routes/lead/stations.get.d.ts +2 -0
  231. package/dist/runtime/server/routes/lead/stations.get.js +8 -0
  232. package/dist/runtime/server/routes/lead/team-shifts.get.d.ts +2 -0
  233. package/dist/runtime/server/routes/lead/team-shifts.get.js +9 -0
  234. package/dist/runtime/server/routes/lead/team-swaps.get.d.ts +2 -0
  235. package/dist/runtime/server/routes/lead/team-swaps.get.js +9 -0
  236. package/dist/runtime/server/routes/me/check-in.post.d.ts +2 -0
  237. package/dist/runtime/server/routes/me/check-in.post.js +11 -0
  238. package/dist/runtime/server/routes/me/earned-perk-claim.post.d.ts +2 -0
  239. package/dist/runtime/server/routes/me/earned-perk-claim.post.js +10 -0
  240. package/dist/runtime/server/routes/me/earned-perks.get.d.ts +2 -0
  241. package/dist/runtime/server/routes/me/earned-perks.get.js +9 -0
  242. package/dist/runtime/server/routes/me/feed-token.delete.d.ts +2 -0
  243. package/dist/runtime/server/routes/me/feed-token.delete.js +7 -0
  244. package/dist/runtime/server/routes/me/feed-token.get.d.ts +2 -0
  245. package/dist/runtime/server/routes/me/feed-token.get.js +6 -0
  246. package/dist/runtime/server/routes/me/feed-token.post.d.ts +2 -0
  247. package/dist/runtime/server/routes/me/feed-token.post.js +7 -0
  248. package/dist/runtime/server/routes/me/leads.get.d.ts +2 -0
  249. package/dist/runtime/server/routes/me/leads.get.js +5 -0
  250. package/dist/runtime/server/routes/me/now.get.d.ts +2 -0
  251. package/dist/runtime/server/routes/me/now.get.js +5 -0
  252. package/dist/runtime/server/routes/me/pass.get.d.ts +2 -0
  253. package/dist/runtime/server/routes/me/pass.get.js +11 -0
  254. package/dist/runtime/server/routes/me/settle.post.d.ts +2 -0
  255. package/dist/runtime/server/routes/me/settle.post.js +14 -0
  256. package/dist/runtime/server/routes/me/shift.get.d.ts +2 -0
  257. package/dist/runtime/server/routes/me/shift.get.js +10 -0
  258. package/dist/runtime/server/routes/me/shifts.get.d.ts +2 -0
  259. package/dist/runtime/server/routes/me/shifts.get.js +6 -0
  260. package/dist/runtime/server/routes/me/swap.delete.d.ts +2 -0
  261. package/dist/runtime/server/routes/me/swap.delete.js +11 -0
  262. package/dist/runtime/server/routes/me/swap.post.d.ts +2 -0
  263. package/dist/runtime/server/routes/me/swap.post.js +11 -0
  264. package/dist/runtime/server/routes/stations/token.get.d.ts +2 -0
  265. package/dist/runtime/server/routes/stations/token.get.js +12 -0
  266. package/dist/runtime/server/routes/swaps/approve.post.d.ts +2 -0
  267. package/dist/runtime/server/routes/swaps/approve.post.js +9 -0
  268. package/dist/runtime/server/routes/swaps/list.get.d.ts +2 -0
  269. package/dist/runtime/server/routes/swaps/list.get.js +5 -0
  270. package/dist/runtime/server/routes/swaps/offer-accept.post.d.ts +2 -0
  271. package/dist/runtime/server/routes/swaps/offer-accept.post.js +9 -0
  272. package/dist/runtime/server/routes/swaps/offer-reject.post.d.ts +2 -0
  273. package/dist/runtime/server/routes/swaps/offer-reject.post.js +9 -0
  274. package/dist/runtime/server/routes/swaps/offer.delete.d.ts +2 -0
  275. package/dist/runtime/server/routes/swaps/offer.delete.js +11 -0
  276. package/dist/runtime/server/routes/swaps/offer.post.d.ts +2 -0
  277. package/dist/runtime/server/routes/swaps/offer.post.js +11 -0
  278. package/dist/runtime/server/routes/swaps/reject.post.d.ts +2 -0
  279. package/dist/runtime/server/routes/swaps/reject.post.js +9 -0
  280. package/dist/runtime/server/swap-email.d.ts +28 -0
  281. package/dist/runtime/server/swap-email.js +49 -0
  282. package/dist/runtime/server/tasks/close-shifts.d.ts +2 -0
  283. package/dist/runtime/server/tasks/close-shifts.js +9 -0
  284. package/dist/runtime/server/tasks/send-reminders.d.ts +2 -0
  285. package/dist/runtime/server/tasks/send-reminders.js +9 -0
  286. package/dist/runtime/server/utils/shifts-admin.d.ts +67 -0
  287. package/dist/runtime/server/utils/shifts-admin.js +312 -0
  288. package/dist/runtime/server/utils/shifts-assign.d.ts +89 -0
  289. package/dist/runtime/server/utils/shifts-assign.js +264 -0
  290. package/dist/runtime/server/utils/shifts-automation.d.ts +37 -0
  291. package/dist/runtime/server/utils/shifts-automation.js +171 -0
  292. package/dist/runtime/server/utils/shifts-broadcasts.d.ts +38 -0
  293. package/dist/runtime/server/utils/shifts-broadcasts.js +113 -0
  294. package/dist/runtime/server/utils/shifts-core.d.ts +78 -0
  295. package/dist/runtime/server/utils/shifts-core.js +142 -0
  296. package/dist/runtime/server/utils/shifts-dto.d.ts +32 -0
  297. package/dist/runtime/server/utils/shifts-dto.js +127 -0
  298. package/dist/runtime/server/utils/shifts-emails.d.ts +16 -0
  299. package/dist/runtime/server/utils/shifts-emails.js +44 -0
  300. package/dist/runtime/server/utils/shifts-exceptions.d.ts +7 -0
  301. package/dist/runtime/server/utils/shifts-exceptions.js +32 -0
  302. package/dist/runtime/server/utils/shifts-feed.d.ts +16 -0
  303. package/dist/runtime/server/utils/shifts-feed.js +73 -0
  304. package/dist/runtime/server/utils/shifts-notify.d.ts +40 -0
  305. package/dist/runtime/server/utils/shifts-notify.js +22 -0
  306. package/dist/runtime/server/utils/shifts-on-duty.d.ts +12 -0
  307. package/dist/runtime/server/utils/shifts-on-duty.js +37 -0
  308. package/dist/runtime/server/utils/shifts-perks.d.ts +46 -0
  309. package/dist/runtime/server/utils/shifts-perks.js +183 -0
  310. package/dist/runtime/server/utils/shifts-reminders.d.ts +30 -0
  311. package/dist/runtime/server/utils/shifts-reminders.js +102 -0
  312. package/dist/runtime/server/utils/shifts-schemas.d.ts +318 -0
  313. package/dist/runtime/server/utils/shifts-schemas.js +177 -0
  314. package/dist/runtime/server/utils/shifts-station-key.d.ts +7 -0
  315. package/dist/runtime/server/utils/shifts-station-key.js +22 -0
  316. package/dist/runtime/server/utils/shifts-stations.d.ts +28 -0
  317. package/dist/runtime/server/utils/shifts-stations.js +109 -0
  318. package/dist/runtime/server/utils/shifts-swaps.d.ts +114 -0
  319. package/dist/runtime/server/utils/shifts-swaps.js +559 -0
  320. package/dist/runtime/server/utils/shifts-views.d.ts +62 -0
  321. package/dist/runtime/server/utils/shifts-views.js +212 -0
  322. package/dist/runtime/utils/api.d.ts +108 -0
  323. package/dist/runtime/utils/api.js +111 -0
  324. package/dist/runtime/utils/checkin.d.ts +59 -0
  325. package/dist/runtime/utils/checkin.js +57 -0
  326. package/dist/runtime/utils/guards.d.ts +21 -0
  327. package/dist/runtime/utils/guards.js +36 -0
  328. package/dist/runtime/utils/ics.d.ts +32 -0
  329. package/dist/runtime/utils/ics.js +56 -0
  330. package/dist/runtime/utils/index.d.ts +16 -0
  331. package/dist/runtime/utils/index.js +15 -0
  332. package/dist/runtime/utils/links.d.ts +44 -0
  333. package/dist/runtime/utils/links.js +21 -0
  334. package/dist/runtime/utils/reminders.d.ts +27 -0
  335. package/dist/runtime/utils/reminders.js +28 -0
  336. package/dist/runtime/utils/settings.d.ts +28 -0
  337. package/dist/runtime/utils/settings.js +18 -0
  338. package/dist/runtime/utils/station-key.d.ts +9 -0
  339. package/dist/runtime/utils/station-key.js +12 -0
  340. package/dist/runtime/utils/status.d.ts +23 -0
  341. package/dist/runtime/utils/status.js +46 -0
  342. package/dist/runtime/utils/time.d.ts +22 -0
  343. package/dist/runtime/utils/time.js +14 -0
  344. package/dist/types.d.mts +5 -0
  345. package/package.json +131 -3
@@ -0,0 +1,78 @@
1
+ import type { H3Event } from 'h3';
2
+ import { schema } from '@nuxthub/db';
3
+ import type { NitroRuntimeHooks } from 'nitropack';
4
+ import type { ShiftAssigneeDto, ShiftsRuntimeConfig, ShiftWarning } from '../../../types.js';
5
+ import type { GuardShift } from '../../utils/guards.js';
6
+ import type { ShiftAssignmentRow, ShiftRoleRow, ShiftRow, ShiftScheduleRow, ShiftUserLite } from './shifts-dto.js';
7
+ export type ShiftTeamRow = typeof schema.teams.$inferSelect;
8
+ /** A shift with its schedule. */
9
+ export type ShiftEntry = {
10
+ shift: ShiftRow;
11
+ schedule: ShiftScheduleRow;
12
+ };
13
+ /** An assignment with its shift and schedule. */
14
+ export type ShiftAssignmentEntry = ShiftEntry & {
15
+ assignment: ShiftAssignmentRow;
16
+ };
17
+ /** The module options shifts reads at runtime: the time zone (resolved, see `resolveShiftsTimeZone`), when check-in opens and the reminders. */
18
+ export declare function shiftsConfig(event?: H3Event): ShiftsRuntimeConfig;
19
+ /** Calls a shifts hook. Listeners run after the change is written. */
20
+ export declare function shiftsFire<N extends keyof NitroRuntimeHooks>(name: N, ctx: Parameters<NitroRuntimeHooks[N]>[0]): Promise<void>;
21
+ export declare function findShiftSchedule(id: string): Promise<ShiftScheduleRow | undefined>;
22
+ export declare function getShiftScheduleOr404(id: string): Promise<ShiftScheduleRow>;
23
+ export declare function getShiftRoleOr404(id: string): Promise<ShiftRoleRow>;
24
+ export declare function findShiftEntry(id: string): Promise<ShiftEntry | undefined>;
25
+ export declare function getShiftEntryOr404(id: string): Promise<ShiftEntry>;
26
+ export declare function findShiftAssignmentEntry(id: string): Promise<ShiftAssignmentEntry | undefined>;
27
+ export declare function getShiftAssignmentEntryOr404(id: string): Promise<ShiftAssignmentEntry>;
28
+ /** The name, email, avatar and phone number of users, by id (`loadUserRefs` of `@frigear-nu/users`, in chunks). */
29
+ export declare function shiftsUsersById(ids: number[]): Promise<Map<number, ShiftUserLite>>;
30
+ /** Teams by id. */
31
+ export declare function shiftsTeamsById(ids: string[]): Promise<Map<string, ShiftTeamRow>>;
32
+ /** Shift roles by id (a lookup in chunks). */
33
+ export declare function shiftsRolesByIds(ids: Array<string | null | undefined>): Promise<Map<string, ShiftRoleRow>>;
34
+ /**
35
+ * The locale people get their shifts messages in, for many `{ userId, teamId }` pairs at once: the user's own language
36
+ * (`users.locale`), else the one stored on their crew row of the team (the language they applied in), else `en`. Keyed
37
+ * `<userId>:<teamId>`. Chunked lookups, so one run costs a few statements.
38
+ */
39
+ export declare function shiftsLocalesOfMany(pairs: Array<{
40
+ userId: number;
41
+ teamId: string;
42
+ }>): Promise<Map<string, string>>;
43
+ /** The team with this id when the operation owns it, else a 400 on `field`. */
44
+ export declare function shiftsOperationTeamOr400(operationId: string, teamId: string, field?: string): Promise<ShiftTeamRow>;
45
+ /** The shift role with this id when it belongs to the schedule and the team, else a 400. */
46
+ export declare function shiftsRoleOfOr400(scheduleId: string, teamId: string, roleId: string, field?: string): Promise<ShiftRoleRow>;
47
+ /** Why a person cannot hold a shift: `grant` (no explicit role on the team) or `role` (below the shift role's team role). */
48
+ export type ShiftsIneligibility = 'grant' | 'role';
49
+ /**
50
+ * Whether a person may hold an assignment on a team with a shift role: they hold an **explicit** active role on the team
51
+ * (approved crew, or a member staff added in Teams: `teamGrantOf` with `source: 'explicit'`) and, when the shift role
52
+ * sets a `teamRole`, at least that role on the team kind's ladder. People who hold the team role only through a mapping
53
+ * rule are not assignable.
54
+ */
55
+ export declare function shiftsEligibility(event: H3Event | undefined, userId: number, teamId: string, role: Pick<ShiftRoleRow, 'teamRole'> | null | undefined): Promise<{
56
+ eligible: boolean;
57
+ reason: ShiftsIneligibility | null;
58
+ role: string | null;
59
+ }>;
60
+ /** The shift role of an assignment or shift, or `null`. */
61
+ export declare function shiftsRoleById(id: string | null | undefined): Promise<ShiftRoleRow | null>;
62
+ /** The shifts a person holds a place on (`assigned` or `attended`), with the ones in `exclude` (assignment ids) left out. */
63
+ export declare function shiftsActiveShiftsOf(userId: number, exclude?: string[]): Promise<GuardShift[]>;
64
+ /** The guards a person breaks by holding `shift` (on top of their other shifts, `exclude` left out). */
65
+ export declare function shiftsGuardWarningsFor(event: H3Event, userId: number, entry: ShiftEntry, exclude?: string[]): Promise<ShiftWarning[]>;
66
+ /** How many people hold a place on a shift (`assigned` and `attended`). */
67
+ export declare function shiftsFilledCount(shiftId: string, except?: string): Promise<number>;
68
+ /** The person's active assignment on a shift, if any. */
69
+ export declare function shiftsActiveAssignmentOf(shiftId: string, userId: number): Promise<ShiftAssignmentRow | undefined>;
70
+ /** Assignments with their people; contact details only with `pii`. */
71
+ export declare function shiftsAssigneeDtos(rows: ShiftAssignmentRow[], pii: boolean): Promise<ShiftAssigneeDto[]>;
72
+ /** Whether a shift has not started yet. */
73
+ export declare const shiftsIsFuture: (shift: Pick<ShiftRow, "startsAt">, now?: Date) => boolean;
74
+ /**
75
+ * The locale a person gets their shifts emails in: their own language (`users.locale`), else the one stored on their crew
76
+ * row of the team, else `en`.
77
+ */
78
+ export declare function shiftsLocaleOf(userId: number, teamId: string): Promise<string>;
@@ -0,0 +1,142 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, count, eq, inArray, ne } from "drizzle-orm";
3
+ import { chunkParams, notFound, validationError } from "@frigear-nu/module-kit/server";
4
+ import { ladderKeys, roleAtLeast } from "@frigear-nu/teams/utils";
5
+ import { ACTIVE_ASSIGNMENT_STATUSES } from "../../utils/status.js";
6
+ import { shiftGuardWarnings } from "../../utils/guards.js";
7
+ import { resolveShiftsTimeZone } from "../../utils/time.js";
8
+ import { DEFAULT_AUTOMATION_BATCH, normalizeAutomationBatch } from "../../utils/checkin.js";
9
+ import { DEFAULT_REMINDER_BATCH, DEFAULT_REMINDER_OFFSETS, normalizeReminderBatch, normalizeReminderOffsets } from "../../utils/reminders.js";
10
+ import { toShiftAssignmentDto, toShiftPersonDto } from "./shifts-dto.js";
11
+ const DEFAULTS = { checkInOpensMinutes: 60, reminders: { offsets: [...DEFAULT_REMINDER_OFFSETS], sms: false, batchSize: DEFAULT_REMINDER_BATCH }, automation: { batchSize: DEFAULT_AUTOMATION_BATCH } };
12
+ export function shiftsConfig(event) {
13
+ const config = useRuntimeConfig(event).shifts ?? {};
14
+ return {
15
+ timeZone: resolveShiftsTimeZone(config.timeZone, useAppConfig(event)),
16
+ checkInOpensMinutes: config.checkInOpensMinutes ?? DEFAULTS.checkInOpensMinutes,
17
+ reminders: { offsets: normalizeReminderOffsets(config.reminders?.offsets), sms: config.reminders?.sms === true, batchSize: normalizeReminderBatch(config.reminders?.batchSize) },
18
+ automation: { batchSize: normalizeAutomationBatch(config.automation?.batchSize) }
19
+ };
20
+ }
21
+ export async function shiftsFire(name, ctx) {
22
+ await useNitroApp().hooks.callHook(name, ctx);
23
+ }
24
+ export async function findShiftSchedule(id) {
25
+ const [row] = await db.select().from(schema.shiftSchedules).where(eq(schema.shiftSchedules.id, id)).limit(1);
26
+ return row;
27
+ }
28
+ export async function getShiftScheduleOr404(id) {
29
+ const row = await findShiftSchedule(id);
30
+ if (!row) throw notFound("Schedule not found.");
31
+ return row;
32
+ }
33
+ export async function getShiftRoleOr404(id) {
34
+ const [row] = await db.select().from(schema.shiftRoles).where(eq(schema.shiftRoles.id, id)).limit(1);
35
+ if (!row) throw notFound("Shift role not found.");
36
+ return row;
37
+ }
38
+ export async function findShiftEntry(id) {
39
+ const [row] = await db.select({ shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shifts).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(eq(schema.shifts.id, id)).limit(1);
40
+ return row;
41
+ }
42
+ export async function getShiftEntryOr404(id) {
43
+ const row = await findShiftEntry(id);
44
+ if (!row) throw notFound("Shift not found.");
45
+ return row;
46
+ }
47
+ export async function findShiftAssignmentEntry(id) {
48
+ const [row] = await db.select({ assignment: schema.shiftAssignments, shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shiftAssignments).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(eq(schema.shiftAssignments.id, id)).limit(1);
49
+ return row;
50
+ }
51
+ export async function getShiftAssignmentEntryOr404(id) {
52
+ const row = await findShiftAssignmentEntry(id);
53
+ if (!row) throw notFound("Assignment not found.");
54
+ return row;
55
+ }
56
+ export async function shiftsUsersById(ids) {
57
+ return loadUserRefs(ids);
58
+ }
59
+ export async function shiftsTeamsById(ids) {
60
+ const unique = [...new Set(ids)];
61
+ if (!unique.length) return /* @__PURE__ */ new Map();
62
+ const rows = (await Promise.all(chunkParams(unique).map((part) => db.select().from(schema.teams).where(inArray(schema.teams.id, part))))).flat();
63
+ return new Map(rows.map((row) => [row.id, row]));
64
+ }
65
+ export async function shiftsRolesByIds(ids) {
66
+ const unique = [...new Set(ids.filter((id) => !!id))];
67
+ if (!unique.length) return /* @__PURE__ */ new Map();
68
+ const rows = (await Promise.all(chunkParams(unique).map((part) => db.select().from(schema.shiftRoles).where(inArray(schema.shiftRoles.id, part))))).flat();
69
+ return new Map(rows.map((row) => [row.id, row]));
70
+ }
71
+ export async function shiftsLocalesOfMany(pairs) {
72
+ const userIds = [...new Set(pairs.map((pair) => pair.userId))];
73
+ const [users, rows] = await Promise.all([
74
+ loadUserRefs(userIds),
75
+ Promise.all(chunkParams(userIds).map((part) => db.select({ teamId: schema.teamMembers.teamId, userId: schema.teamMembers.userId, locale: schema.teamMembers.locale }).from(schema.teamMembers).where(inArray(schema.teamMembers.userId, part)))).then((parts) => parts.flat())
76
+ ]);
77
+ const found = new Map(rows.map((row) => [`${row.userId}:${row.teamId}`, row.locale]));
78
+ return new Map(pairs.map((pair) => {
79
+ const key = `${pair.userId}:${pair.teamId}`;
80
+ return [key, users.get(pair.userId)?.locale || found.get(key) || "en"];
81
+ }));
82
+ }
83
+ export async function shiftsOperationTeamOr400(operationId, teamId, field = "teamId") {
84
+ const [team] = await db.select().from(schema.teams).where(eq(schema.teams.id, teamId)).limit(1);
85
+ if (!team || team.ownerType !== "operation" || team.ownerId !== operationId) {
86
+ throw validationError([{ path: [field], message: "The team must belong to the schedule's operation." }], "Unknown team");
87
+ }
88
+ return team;
89
+ }
90
+ export async function shiftsRoleOfOr400(scheduleId, teamId, roleId, field = "shiftRoleId") {
91
+ const [role] = await db.select().from(schema.shiftRoles).where(eq(schema.shiftRoles.id, roleId)).limit(1);
92
+ if (!role || role.scheduleId !== scheduleId || role.teamId !== teamId) {
93
+ throw validationError([{ path: [field], message: "The shift role must belong to the schedule and the shift's team." }], "Unknown shift role");
94
+ }
95
+ return role;
96
+ }
97
+ export async function shiftsEligibility(event, userId, teamId, role) {
98
+ const grant = await teamGrantOf(event, userId, teamId);
99
+ if (!grant || grant.source !== "explicit") return { eligible: false, reason: "grant", role: grant?.role ?? null };
100
+ if (role?.teamRole) {
101
+ const ladder = (await loadTeamLadders(event))[grant.kind];
102
+ if (!roleAtLeast(ladderKeys(ladder), grant.role, role.teamRole)) return { eligible: false, reason: "role", role: grant.role };
103
+ }
104
+ return { eligible: true, reason: null, role: grant.role };
105
+ }
106
+ export async function shiftsRoleById(id) {
107
+ if (!id) return null;
108
+ const [row] = await db.select().from(schema.shiftRoles).where(eq(schema.shiftRoles.id, id)).limit(1);
109
+ return row ?? null;
110
+ }
111
+ export async function shiftsActiveShiftsOf(userId, exclude = []) {
112
+ const rows = await db.select({ id: schema.shifts.id, startsAt: schema.shifts.startsAt, endsAt: schema.shifts.endsAt, assignmentId: schema.shiftAssignments.id }).from(schema.shiftAssignments).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).where(and(eq(schema.shiftAssignments.userId, userId), inArray(schema.shiftAssignments.status, [...ACTIVE_ASSIGNMENT_STATUSES])));
113
+ return rows.filter((row) => !exclude.includes(row.assignmentId)).map(({ id, startsAt, endsAt }) => ({ id, startsAt, endsAt }));
114
+ }
115
+ export async function shiftsGuardWarningsFor(event, userId, entry, exclude = []) {
116
+ const others = await shiftsActiveShiftsOf(userId, exclude);
117
+ return shiftGuardWarnings(entry.shift, others, entry.schedule.guards, shiftsConfig(event).timeZone);
118
+ }
119
+ export async function shiftsFilledCount(shiftId, except) {
120
+ const [row] = await db.select({ total: count() }).from(schema.shiftAssignments).where(and(
121
+ eq(schema.shiftAssignments.shiftId, shiftId),
122
+ inArray(schema.shiftAssignments.status, [...ACTIVE_ASSIGNMENT_STATUSES]),
123
+ except ? ne(schema.shiftAssignments.id, except) : void 0
124
+ ));
125
+ return Number(row?.total ?? 0);
126
+ }
127
+ export async function shiftsActiveAssignmentOf(shiftId, userId) {
128
+ const [row] = await db.select().from(schema.shiftAssignments).where(and(
129
+ eq(schema.shiftAssignments.shiftId, shiftId),
130
+ eq(schema.shiftAssignments.userId, userId),
131
+ inArray(schema.shiftAssignments.status, [...ACTIVE_ASSIGNMENT_STATUSES])
132
+ )).limit(1);
133
+ return row;
134
+ }
135
+ export async function shiftsAssigneeDtos(rows, pii) {
136
+ const users = await shiftsUsersById(rows.map((row) => row.userId));
137
+ return rows.map((row) => ({ ...toShiftAssignmentDto(row), person: toShiftPersonDto(row.userId, users.get(row.userId), pii) }));
138
+ }
139
+ export const shiftsIsFuture = (shift, now = /* @__PURE__ */ new Date()) => shift.startsAt.getTime() > now.getTime();
140
+ export async function shiftsLocaleOf(userId, teamId) {
141
+ return (await shiftsLocalesOfMany([{ userId, teamId }])).get(`${userId}:${teamId}`) ?? "en";
142
+ }
@@ -0,0 +1,32 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { schema } from '@nuxthub/db';
3
+ import type { ShiftAssignmentDto, ShiftBroadcastDto, ShiftDto, ShiftPerkDto, ShiftPersonDto, ShiftRoleDto, ShiftScheduleDto, ShiftStationDto, ShiftSwapOfferDto } from '../../../types.js';
4
+ export type ShiftScheduleRow = typeof schema.shiftSchedules.$inferSelect;
5
+ export type ShiftRoleRow = typeof schema.shiftRoles.$inferSelect;
6
+ export type ShiftRow = typeof schema.shifts.$inferSelect;
7
+ export type ShiftAssignmentRow = typeof schema.shiftAssignments.$inferSelect;
8
+ export type ShiftSwapRow = typeof schema.shiftSwaps.$inferSelect;
9
+ export type ShiftSwapOfferRow = typeof schema.shiftSwapOffers.$inferSelect;
10
+ /** The user fields shifts shows; `email` and `phone` are only copied with `pii`. */
11
+ export type ShiftUserLite = {
12
+ name: string | null;
13
+ email: string | null;
14
+ avatar: string | null;
15
+ phone: string | null;
16
+ };
17
+ /** `event` scopes the runtime config `stationKeyConfigured` is read from (the shared one without it). */
18
+ export declare function toShiftScheduleDto(row: ShiftScheduleRow, shiftCount?: number, event?: H3Event): ShiftScheduleDto;
19
+ export declare function toShiftRoleDto(row: ShiftRoleRow): ShiftRoleDto;
20
+ export declare function toShiftDto(row: ShiftRow, schedule: Pick<ShiftScheduleRow, 'operationId' | 'maxPerShift'>): ShiftDto;
21
+ /** An assignment, never with its check-in code (the pass route is the only place that shows it). */
22
+ export declare function toShiftAssignmentDto(row: ShiftAssignmentRow): ShiftAssignmentDto;
23
+ /** A person; the email and phone number only with `pii`. */
24
+ export declare function toShiftPersonDto(userId: number, user: ShiftUserLite | undefined, pii: boolean): ShiftPersonDto;
25
+ export type ShiftBroadcastRow = typeof schema.shiftBroadcasts.$inferSelect;
26
+ export type ShiftPerkRow = typeof schema.shiftPerks.$inferSelect;
27
+ export type ShiftEarnedPerkRow = typeof schema.shiftEarnedPerks.$inferSelect;
28
+ export type ShiftStationRow = typeof schema.shiftStations.$inferSelect;
29
+ export declare function toShiftBroadcastDto(row: ShiftBroadcastRow): ShiftBroadcastDto;
30
+ export declare function toShiftPerkDto(row: ShiftPerkRow, earned?: number): ShiftPerkDto;
31
+ export declare function toShiftStationDto(row: ShiftStationRow): ShiftStationDto;
32
+ export declare function toShiftSwapOfferDto(row: ShiftSwapOfferRow, extra?: Pick<ShiftSwapOfferDto, 'person' | 'offeredShift'>): ShiftSwapOfferDto;
@@ -0,0 +1,127 @@
1
+ import { isoDate } from "@frigear-nu/module-kit/server";
2
+ import { effectiveCapacity } from "../../utils/guards.js";
3
+ import { scheduleSettingsOf } from "../../utils/settings.js";
4
+ import { checkInSettingsOf } from "../../utils/checkin.js";
5
+ import { shiftsStationKeyConfigured } from "./shifts-station-key.js";
6
+ export function toShiftScheduleDto(row, shiftCount, event) {
7
+ return {
8
+ id: row.id,
9
+ operationId: row.operationId,
10
+ name: row.name,
11
+ status: row.status,
12
+ ...scheduleSettingsOf(row),
13
+ minPerShift: row.minPerShift ?? null,
14
+ maxPerShift: row.maxPerShift ?? null,
15
+ guards: row.guards ?? {},
16
+ checkIn: checkInSettingsOf(row.checkIn),
17
+ autoNoShow: !!row.autoNoShow,
18
+ autoNoShowMinutes: row.autoNoShowMinutes ?? 30,
19
+ stationKeyConfigured: shiftsStationKeyConfigured(event),
20
+ publishedAt: isoDate(row.publishedAt),
21
+ createdAt: isoDate(row.createdAt),
22
+ updatedAt: isoDate(row.updatedAt),
23
+ ...shiftCount === void 0 ? {} : { shiftCount }
24
+ };
25
+ }
26
+ export function toShiftRoleDto(row) {
27
+ return {
28
+ id: row.id,
29
+ scheduleId: row.scheduleId,
30
+ teamId: row.teamId,
31
+ teamRole: row.teamRole ?? null,
32
+ name: row.name,
33
+ createdAt: isoDate(row.createdAt)
34
+ };
35
+ }
36
+ export function toShiftDto(row, schedule) {
37
+ return {
38
+ id: row.id,
39
+ scheduleId: row.scheduleId,
40
+ operationId: schedule.operationId,
41
+ teamId: row.teamId,
42
+ shiftRoleId: row.shiftRoleId ?? null,
43
+ startsAt: isoDate(row.startsAt),
44
+ endsAt: isoDate(row.endsAt),
45
+ location: row.location ?? null,
46
+ capacity: row.capacity ?? null,
47
+ effectiveCapacity: effectiveCapacity({ capacity: row.capacity ?? null }, { maxPerShift: schedule.maxPerShift ?? null }),
48
+ notes: row.notes ?? null,
49
+ createdAt: isoDate(row.createdAt),
50
+ updatedAt: isoDate(row.updatedAt)
51
+ };
52
+ }
53
+ export function toShiftAssignmentDto(row) {
54
+ return {
55
+ id: row.id,
56
+ shiftId: row.shiftId,
57
+ userId: row.userId,
58
+ shiftRoleId: row.shiftRoleId ?? null,
59
+ status: row.status,
60
+ checkedInAt: isoDate(row.checkedInAt),
61
+ checkedInBy: row.checkedInBy ?? null,
62
+ checkInMethod: row.checkInMethod ?? null,
63
+ assignedBy: row.assignedBy ?? null,
64
+ createdAt: isoDate(row.createdAt),
65
+ updatedAt: isoDate(row.updatedAt)
66
+ };
67
+ }
68
+ export function toShiftPersonDto(userId, user, pii) {
69
+ return {
70
+ userId,
71
+ name: user?.name ?? null,
72
+ avatar: user?.avatar ?? null,
73
+ ...pii ? { email: user?.email ?? null, phone: user?.phone ?? null } : {}
74
+ };
75
+ }
76
+ export function toShiftBroadcastDto(row) {
77
+ return {
78
+ id: row.id,
79
+ operationId: row.operationId,
80
+ teamId: row.teamId ?? null,
81
+ shiftId: row.shiftId ?? null,
82
+ teamRole: row.teamRole ?? null,
83
+ channels: row.channels,
84
+ subject: row.subject,
85
+ message: row.message,
86
+ recipientCount: row.recipientCount,
87
+ sentBy: row.sentBy,
88
+ createdAt: isoDate(row.createdAt)
89
+ };
90
+ }
91
+ export function toShiftPerkDto(row, earned) {
92
+ return {
93
+ id: row.id,
94
+ operationId: row.operationId,
95
+ teamId: row.teamId ?? null,
96
+ name: row.name,
97
+ voucherType: row.voucherType,
98
+ quantity: row.quantity,
99
+ createdAt: isoDate(row.createdAt),
100
+ updatedAt: isoDate(row.updatedAt),
101
+ ...earned === void 0 ? {} : { earned }
102
+ };
103
+ }
104
+ export function toShiftStationDto(row) {
105
+ return {
106
+ id: row.id,
107
+ scheduleId: row.scheduleId,
108
+ teamId: row.teamId,
109
+ name: row.name,
110
+ featureId: row.featureId ?? null,
111
+ createdAt: isoDate(row.createdAt),
112
+ updatedAt: isoDate(row.updatedAt)
113
+ };
114
+ }
115
+ export function toShiftSwapOfferDto(row, extra = {}) {
116
+ return {
117
+ id: row.id,
118
+ swapId: row.swapId,
119
+ userId: row.userId,
120
+ offeredAssignmentId: row.offeredAssignmentId ?? null,
121
+ status: row.status,
122
+ decidedAt: isoDate(row.decidedAt),
123
+ approvedBy: row.approvedBy ?? null,
124
+ createdAt: isoDate(row.createdAt),
125
+ ...extra
126
+ };
127
+ }
@@ -0,0 +1,16 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { ShiftSwapDto, ShiftSwapOfferDto } from '../../../types.js';
3
+ import type { ShiftSwapEmailKind } from '../swap-email.js';
4
+ /**
5
+ * Emails one person about a swap (`shifts-swap-<kind>` template). A trade names both shifts: the owner's and the one
6
+ * given in return (the offer's, or the one a targeted trade wants). The link goes to the shift's page for the owner, to
7
+ * the lead page of `teamId` for a pending approval, to my shifts once completed, and to the marketplace otherwise. Links
8
+ * need a configured site origin (Auth's `configuredAuthSiteOrigin`); without one the email goes out without a link and a
9
+ * warning is logged once. A failing email never fails the swap: it is logged.
10
+ */
11
+ export declare function shiftsSendSwapEmail(event: H3Event, kind: ShiftSwapEmailKind, input: {
12
+ swap: ShiftSwapDto;
13
+ offer?: ShiftSwapOfferDto;
14
+ to: number;
15
+ teamId?: string;
16
+ }): Promise<void>;
@@ -0,0 +1,44 @@
1
+ import { shiftsMinePath, shiftsSwapsPath, translate } from "../../utils/index.js";
2
+ import { formatShiftWhen } from "../reminder-email.js";
3
+ import { buildShiftSwapEmail } from "../swap-email.js";
4
+ import { shiftsConfig, shiftsLocaleOf, shiftsUsersById } from "./shifts-core.js";
5
+ import { shiftsNotify } from "./shifts-notify.js";
6
+ import { SHIFTS_TOPICS } from "../../notifications.js";
7
+ let shiftsWarnedNoOrigin = false;
8
+ export async function shiftsSendSwapEmail(event, kind, input) {
9
+ try {
10
+ const { swap, offer, to } = input;
11
+ const back = offer?.offeredShift ?? (kind === "proposed" ? swap.wantedShift : null);
12
+ const offererId = offer?.userId ?? (kind === "proposed" ? to : void 0);
13
+ const users = await shiftsUsersById([to, swap.owner.userId, ...offererId === void 0 ? [] : [offererId]]);
14
+ const recipient = users.get(to);
15
+ const locale = await shiftsLocaleOf(to, swap.shift.teamId);
16
+ const { timeZone } = shiftsConfig(event);
17
+ const pages = useRuntimeConfig(event).public.shifts?.pages;
18
+ const origin = configuredAuthSiteOrigin(event);
19
+ if (!origin && !shiftsWarnedNoOrigin) {
20
+ shiftsWarnedNoOrigin = true;
21
+ console.warn("[shifts] no site origin is configured: swap emails go out without a link");
22
+ }
23
+ const path = kind === "pending" ? pages?.lead?.replace(":teamId", encodeURIComponent(input.teamId ?? swap.shift.teamId)) : to === swap.owner.userId && kind !== "completed" && pages?.shift ? pages.shift.replace(":assignmentId", encodeURIComponent(swap.assignmentId)) : kind === "completed" ? shiftsMinePath(pages) : shiftsSwapsPath(pages);
24
+ const notification = buildShiftSwapEmail({
25
+ kind,
26
+ email: recipient?.email ?? null,
27
+ trade: !!back,
28
+ variables: {
29
+ name: recipient?.name ?? "",
30
+ owner: users.get(swap.owner.userId)?.name ?? "",
31
+ offerer: offererId === void 0 ? "" : users.get(offererId)?.name ?? "",
32
+ team: translate(swap.shift.teamName, locale, "en"),
33
+ when: formatShiftWhen(new Date(swap.shift.startsAt), locale, timeZone),
34
+ backTeam: back ? translate(back.teamName, locale, "en") : "",
35
+ backWhen: back ? formatShiftWhen(new Date(back.startsAt), locale, timeZone) : ""
36
+ },
37
+ url: path && origin ? `${origin}${path}` : void 0,
38
+ locale
39
+ });
40
+ if (notification) await shiftsNotify(event, to, { topic: SHIFTS_TOPICS.swap, email: notification, label: `the "${kind}" swap message` });
41
+ } catch (error) {
42
+ console.error(`[shifts] the "${kind}" swap email could not be sent`, error);
43
+ }
44
+ }
@@ -0,0 +1,7 @@
1
+ import type { ShiftExceptionDto } from '../../../types.js';
2
+ /**
3
+ * The exceptions of a team's shifts that started and ended at most a day ago (published schedules): no-shows (flagged
4
+ * when an earned perk was claimed before the flip), people checked in late, and people still `assigned` after the start. Most
5
+ * recent shift first; contact details only with `pii`.
6
+ */
7
+ export declare function shiftsTeamExceptions(teamId: string, pii: boolean, now?: Date): Promise<ShiftExceptionDto[]>;
@@ -0,0 +1,32 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, eq, gte, inArray, lte, ne } from "drizzle-orm";
3
+ import { exceptionOf } from "../../utils/checkin.js";
4
+ import { toShiftDto } from "./shifts-dto.js";
5
+ import { shiftsAssigneeDtos } from "./shifts-core.js";
6
+ import { shiftsClaimedAssignmentIds } from "./shifts-perks.js";
7
+ import { chunkParams } from "@frigear-nu/module-kit/server";
8
+ const HOUR = 36e5;
9
+ export async function shiftsTeamExceptions(teamId, pii, now = /* @__PURE__ */ new Date()) {
10
+ const rows = await db.select({ shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shifts).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
11
+ eq(schema.shifts.teamId, teamId),
12
+ eq(schema.shiftSchedules.status, "published"),
13
+ lte(schema.shifts.startsAt, now),
14
+ gte(schema.shifts.endsAt, new Date(now.getTime() - 24 * HOUR))
15
+ )).orderBy(asc(schema.shifts.startsAt), asc(schema.shifts.id)).limit(200);
16
+ if (!rows.length) return [];
17
+ const byShift = new Map(rows.map((row) => [row.shift.id, row]));
18
+ const assignments = (await Promise.all(chunkParams([...byShift.keys()]).map((part) => db.select().from(schema.shiftAssignments).where(and(inArray(schema.shiftAssignments.shiftId, part), ne(schema.shiftAssignments.status, "cancelled")))))).flat();
19
+ const noShows = assignments.filter((row) => row.status === "no_show").map((row) => row.id);
20
+ const claimed = await shiftsClaimedAssignmentIds(noShows);
21
+ const found = assignments.flatMap((assignment) => {
22
+ const { shift } = byShift.get(assignment.shiftId);
23
+ const exception = exceptionOf(assignment, shift, now, { claimedPerk: claimed.has(assignment.id) });
24
+ return exception ? [{ assignment, exception }] : [];
25
+ });
26
+ const people = await shiftsAssigneeDtos(found.map((item) => item.assignment), pii);
27
+ const byId = new Map(people.map((person) => [person.id, person]));
28
+ return found.map(({ assignment, exception }) => {
29
+ const { shift, schedule } = byShift.get(assignment.shiftId);
30
+ return { kind: exception.kind, assignment: byId.get(assignment.id), shift: toShiftDto(shift, schedule), ...exception.lateMinutes === void 0 ? {} : { lateMinutes: exception.lateMinutes } };
31
+ }).sort((a, b) => b.shift.startsAt.localeCompare(a.shift.startsAt));
32
+ }
@@ -0,0 +1,16 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { ShiftFeedStatusDto, ShiftFeedTokenDto } from '../../../types.js';
3
+ /** Whether I have a live feed, and when it was made and last read. The secret itself is never shown again. */
4
+ export declare function shiftsFeedStatus(userId: number): Promise<ShiftFeedStatusDto>;
5
+ /**
6
+ * Mints my feed secret: any earlier one is revoked, so there is one live URL per person. The URL carries the token and
7
+ * is shown once (only its hash is stored). It points at the configured site origin, else the origin of this request.
8
+ *
9
+ * Earlier rows are revoked before the new one goes in, and every other live row again after it, so two mints at once (a
10
+ * double click) cannot leave two live URLs: at most one stays live.
11
+ */
12
+ export declare function shiftsMintFeedToken(event: H3Event, userId: number): Promise<ShiftFeedTokenDto>;
13
+ /** Revokes my live feed secret: its URL answers 404 from now on. */
14
+ export declare function shiftsRevokeFeedToken(userId: number): Promise<void>;
15
+ /** The `.ics` of the person a feed secret belongs to; `undefined` for an unknown or revoked one. An optional `.ics` suffix is ignored. */
16
+ export declare function shiftsFeedFor(event: H3Event, rawToken: string, now?: Date): Promise<string | undefined>;
@@ -0,0 +1,73 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, eq, gt, inArray, isNull, ne } from "drizzle-orm";
3
+ import { generateUserToken, hashToken, shouldTouchLastUsed } from "@frigear-nu/auth/utils";
4
+ import { isoDate } from "@frigear-nu/module-kit/server";
5
+ import { newId, translate } from "../../utils/index.js";
6
+ import { buildIcs } from "../../utils/ics.js";
7
+ import { shiftsLocaleOf, shiftsTeamsById } from "./shifts-core.js";
8
+ const FEED_TOKEN_PREFIX = "sfk_";
9
+ const FEED_BACKLOG_MS = 30 * 24 * 36e5;
10
+ export async function shiftsFeedStatus(userId) {
11
+ const [row] = await db.select().from(schema.shiftFeedTokens).where(and(eq(schema.shiftFeedTokens.userId, userId), isNull(schema.shiftFeedTokens.revokedAt))).limit(1);
12
+ return row ? { active: true, prefix: row.prefix, createdAt: isoDate(row.createdAt), lastUsedAt: isoDate(row.lastUsedAt) } : { active: false, prefix: null, createdAt: null, lastUsedAt: null };
13
+ }
14
+ export async function shiftsMintFeedToken(event, userId) {
15
+ const live = and(eq(schema.shiftFeedTokens.userId, userId), isNull(schema.shiftFeedTokens.revokedAt));
16
+ await db.update(schema.shiftFeedTokens).set({ revokedAt: /* @__PURE__ */ new Date() }).where(live);
17
+ const { token, tokenHash, prefix } = await generateUserToken(FEED_TOKEN_PREFIX);
18
+ const id = newId("sft");
19
+ await db.insert(schema.shiftFeedTokens).values({ id, userId, tokenHash, prefix });
20
+ await db.update(schema.shiftFeedTokens).set({ revokedAt: /* @__PURE__ */ new Date() }).where(and(live, ne(schema.shiftFeedTokens.id, id)));
21
+ const origin = configuredAuthSiteOrigin(event) ?? getRequestURL(event).origin;
22
+ const url = `${origin}/api/shifts/feed/${token}.ics`;
23
+ return { token, url, webcalUrl: url.replace(/^https?:\/\//, "webcal://") };
24
+ }
25
+ export async function shiftsRevokeFeedToken(userId) {
26
+ await db.update(schema.shiftFeedTokens).set({ revokedAt: /* @__PURE__ */ new Date() }).where(and(eq(schema.shiftFeedTokens.userId, userId), isNull(schema.shiftFeedTokens.revokedAt)));
27
+ }
28
+ export async function shiftsFeedFor(event, rawToken, now = /* @__PURE__ */ new Date()) {
29
+ const token = rawToken.replace(/\.ics$/i, "");
30
+ if (!token || token.length > 200) return void 0;
31
+ const [row] = await db.select().from(schema.shiftFeedTokens).where(and(eq(schema.shiftFeedTokens.tokenHash, await hashToken(token)), isNull(schema.shiftFeedTokens.revokedAt))).limit(1);
32
+ if (!row) return void 0;
33
+ if (shouldTouchLastUsed(row.lastUsedAt, now)) {
34
+ await db.update(schema.shiftFeedTokens).set({ lastUsedAt: now }).where(eq(schema.shiftFeedTokens.id, row.id));
35
+ }
36
+ const rows = await db.select({ assignment: schema.shiftAssignments, shift: schema.shifts, schedule: schema.shiftSchedules }).from(schema.shiftAssignments).innerJoin(schema.shifts, eq(schema.shifts.id, schema.shiftAssignments.shiftId)).innerJoin(schema.shiftSchedules, eq(schema.shiftSchedules.id, schema.shifts.scheduleId)).where(and(
37
+ eq(schema.shiftAssignments.userId, row.userId),
38
+ ne(schema.shiftAssignments.status, "cancelled"),
39
+ eq(schema.shiftSchedules.status, "published"),
40
+ gt(schema.shifts.endsAt, new Date(now.getTime() - FEED_BACKLOG_MS))
41
+ )).orderBy(asc(schema.shifts.startsAt), asc(schema.shiftAssignments.id)).limit(2e3);
42
+ const roleIds = [...new Set(rows.flatMap((item) => item.assignment.shiftRoleId ? [item.assignment.shiftRoleId] : []))];
43
+ const operationIds = [...new Set(rows.map((item) => item.schedule.operationId))];
44
+ const [teams, roles, operations] = await Promise.all([
45
+ shiftsTeamsById(rows.map((item) => item.shift.teamId)),
46
+ roleIds.length ? db.select().from(schema.shiftRoles).where(inArray(schema.shiftRoles.id, roleIds)) : Promise.resolve([]),
47
+ operationIds.length ? db.select({ id: schema.operations.id, name: schema.operations.name }).from(schema.operations).where(inArray(schema.operations.id, operationIds)) : Promise.resolve([])
48
+ ]);
49
+ const pagePath = useRuntimeConfig(event).public.shifts?.pages?.shift;
50
+ const origin = configuredAuthSiteOrigin(event) ?? getRequestURL(event).origin;
51
+ const locales = /* @__PURE__ */ new Map();
52
+ const events = [];
53
+ for (const { assignment, shift, schedule } of rows) {
54
+ let locale = locales.get(shift.teamId);
55
+ if (!locale) locales.set(shift.teamId, locale = await shiftsLocaleOf(row.userId, shift.teamId));
56
+ const team = translate(teams.get(shift.teamId)?.name ?? shift.teamId, locale, "en");
57
+ const role = roles.find((item) => item.id === assignment.shiftRoleId);
58
+ const operation = operations.find((item) => item.id === schedule.operationId);
59
+ const url = pagePath ? `${origin}${pagePath.replace(":assignmentId", encodeURIComponent(assignment.id))}` : void 0;
60
+ const notes = shift.notes ? translate(shift.notes, locale, "en") : "";
61
+ events.push({
62
+ uid: `${assignment.id}@shifts.frigear-nu`,
63
+ start: shift.startsAt,
64
+ end: shift.endsAt,
65
+ summary: role ? `${team} \xB7 ${translate(role.name, locale, "en")}` : team,
66
+ location: shift.location?.name ? translate(shift.location.name, locale, "en") : void 0,
67
+ description: [operation ? translate(operation.name, locale, "en") : "", notes, url ?? ""].filter(Boolean).join("\n"),
68
+ url,
69
+ stamp: new Date(Math.max(assignment.updatedAt.getTime(), shift.updatedAt.getTime()))
70
+ });
71
+ }
72
+ return buildIcs({ name: "My shifts", events, generatedAt: now });
73
+ }
@@ -0,0 +1,40 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { EmailNotification, SMSNotification } from '@frigear-nu/notify/types';
3
+ import type { ShiftChannel } from '../../../types.js';
4
+ import type { ShiftsTopic } from '../../notifications.js';
5
+ /** What `shiftsNotify` sends one person: the messages as built, and the topic they belong to. */
6
+ export type ShiftsNotification = {
7
+ topic: ShiftsTopic;
8
+ /** The email as built (its `to` is not used: `notifyUser` sends to the user's own address). `null` or left out: none. */
9
+ email?: EmailNotification | null;
10
+ /**
11
+ * The text as built. Leave it out when SMS was not asked for (`reminders.sms`, the broadcast's `sms` channel): the
12
+ * person's own choice for the topic decides on top of that.
13
+ */
14
+ sms?: SMSNotification | null;
15
+ /** What the push notification says. Left out, it is the email's subject and message. */
16
+ push?: {
17
+ title: string;
18
+ body: string;
19
+ url?: string;
20
+ };
21
+ /** What the notification is, for the log line of a failure ("the reminder of assignment sha_1"). */
22
+ label: string;
23
+ };
24
+ /** The channels that went out, and the ones that were tried and failed (a person who turned a channel off is neither). */
25
+ export type ShiftsNotifyResult = {
26
+ channels: ShiftChannel[];
27
+ failed: ShiftChannel[];
28
+ };
29
+ /** The push notification of an email: its subject, the template's message (else the subject) and its link. */
30
+ export declare function shiftsPushFromEmail(email: EmailNotification): {
31
+ title: string;
32
+ body: string;
33
+ url?: string;
34
+ };
35
+ /**
36
+ * Sends a notification to one person through notify's `notifyUser`: the channels the person chose for the topic (email
37
+ * and push by default, SMS only when they turned it on) and have an address, number or device for. Never throws: a
38
+ * failure is logged and leaves the channel out of the answer. `event` is `undefined` in the reminder task.
39
+ */
40
+ export declare function shiftsNotify(_event: H3Event | undefined, userId: number, notification: ShiftsNotification): Promise<ShiftsNotifyResult>;
@@ -0,0 +1,22 @@
1
+ export function shiftsPushFromEmail(email) {
2
+ const props = email.template?.props ?? {};
3
+ const message = typeof props.message === "string" && props.message ? props.message : email.subject;
4
+ const url = typeof props.url === "string" && props.url ? props.url : void 0;
5
+ return { title: email.subject, body: message.length > 200 ? `${message.slice(0, 197)}...` : message, ...url ? { url } : {} };
6
+ }
7
+ export async function shiftsNotify(_event, userId, notification) {
8
+ const { topic, email, sms, label } = notification;
9
+ const push = notification.push ?? (email ? shiftsPushFromEmail(email) : void 0);
10
+ try {
11
+ const result = await notifyUser(userId, {
12
+ topic,
13
+ ...email ? { email: { subject: email.subject, body: email.body, text: email.text, replyTo: email.replyTo, template: email.template, meta: email.meta } } : {},
14
+ ...sms ? { sms: { body: sms.body } } : {},
15
+ push
16
+ });
17
+ return { channels: result.channels, failed: Object.keys(result.skipped).filter((channel) => result.skipped[channel] === "failed") };
18
+ } catch (error) {
19
+ console.error(`[shifts] ${label} could not be sent`, error);
20
+ return { channels: [], failed: [email ? "email" : void 0, sms ? "sms" : void 0, push ? "push" : void 0].filter((channel) => !!channel) };
21
+ }
22
+ }