@mccaskie-labs/workbench-roster 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,34 @@
1
+ /** One CSS custom property the rules read, with its default. */
2
+ interface StyleVariable {
3
+ /** `--wb-<tool>-<what>`. */
4
+ name: string;
5
+ value: string;
6
+ about: string;
7
+ }
8
+ /** A rule for a class in another state, or for an element inside it. */
9
+ interface StyleState {
10
+ selector: string;
11
+ about: string;
12
+ css: string;
13
+ }
14
+ /** One class the tool puts on an element, with its default rule. */
15
+ interface StyleClass {
16
+ name: string;
17
+ element: string;
18
+ about: string;
19
+ css: string;
20
+ states?: readonly StyleState[];
21
+ }
22
+ /** Every class and variable the tool draws with. */
23
+ export interface ToolStyles {
24
+ format: 1;
25
+ tool: string;
26
+ package: string;
27
+ title: string;
28
+ prefix: string;
29
+ variables: readonly StyleVariable[];
30
+ classes: readonly StyleClass[];
31
+ }
32
+ /** The style hooks of the owner's week (renderWeek) and staff (renderStaff) pages and a person's own page (renderMyShifts). */
33
+ export declare const ROSTER_STYLES: ToolStyles;
34
+ export {};
package/dist/styles.js ADDED
@@ -0,0 +1,99 @@
1
+ // The look the roster's pages start with (docs/capabilities-manifest.md §10).
2
+ // Every element renderWeek, renderStaff and renderMyShifts draw carries one
3
+ // of these classes, and every class has a default rule here, so the pages
4
+ // look finished out of the box and a project restyles them from its own CSS
5
+ // by the same names. `npx workbench-ui styles` writes these into the
6
+ // project's public/styles/workbench.css inside `@layer workbench`. The names
7
+ // are public: renaming one is a breaking change.
8
+ const v = (name) => `var(--wb-roster-${name})`;
9
+ const focus = { selector: ":focus-visible", about: "Has focus", css: `outline:none;box-shadow:0 0 0 3px ${v("focus")}` };
10
+ const button = `display:inline-flex;align-items:center;justify-content:center;min-height:2.75rem;padding:0 1rem;font:inherit;font-weight:600;border-radius:${v("radius")};cursor:pointer;text-decoration:none`;
11
+ const input = `box-sizing:border-box;width:100%;min-height:2.75rem;padding:.5rem .75rem;font:inherit;color:${v("text")};background:${v("sunk")};border:1px solid ${v("line")};border-radius:${v("radius")}`;
12
+ const main = `${button};color:${v("on-accent")};background:${v("accent")};border:1px solid ${v("accent")}`;
13
+ const quiet = `${button};color:${v("text")};background:transparent;border:1px solid ${v("line")}`;
14
+ const panel = `display:grid;gap:1rem;color:${v("text")};background:${v("sunk")};padding:.75rem;border-radius:${v("radius")}`;
15
+ const small = `color:${v("muted")};font-size:.9rem`;
16
+ /** The style hooks of the owner's week (renderWeek) and staff (renderStaff) pages and a person's own page (renderMyShifts). */
17
+ export const ROSTER_STYLES = {
18
+ format: 1,
19
+ tool: "roster",
20
+ package: "@mccaskie-labs/workbench-roster",
21
+ title: "Staff roster",
22
+ prefix: "wb-roster-",
23
+ variables: [
24
+ { name: "--wb-roster-text", value: "#e8e8ec", about: "Text: names, times, labels" },
25
+ { name: "--wb-roster-muted", value: "#9a9aa6", about: "Quieter text: details, hints, an empty day" },
26
+ { name: "--wb-roster-surface", value: "#1b1b1f", about: "Background of each day, shift, person and form" },
27
+ { name: "--wb-roster-sunk", value: "#141417", about: "Background of the page's panels and of inputs" },
28
+ { name: "--wb-roster-line", value: "#33333b", about: "Borders" },
29
+ { name: "--wb-roster-accent", value: "#4c8dff", about: "Main buttons and links: Add shift, Publish" },
30
+ { name: "--wb-roster-on-accent", value: "#ffffff", about: "Text on a main button" },
31
+ { name: "--wb-roster-good", value: "#3fb27f", about: "Published, every time covered, a done message" },
32
+ { name: "--wb-roster-warn", value: "#f5a524", about: "A draft week, a gap, unsent changes, a person on leave" },
33
+ { name: "--wb-roster-danger", value: "#e5484d", about: "Take off the roster" },
34
+ { name: "--wb-roster-focus", value: "rgba(76,141,255,.4)", about: "The ring round a control with focus" },
35
+ { name: "--wb-roster-radius", value: "8px", about: "Corner rounding" },
36
+ ],
37
+ classes: [
38
+ { name: "wb-roster-week", element: "section", about: "The owner's week page", css: panel },
39
+ { name: "wb-roster-staff", element: "section", about: "The owner's staff page", css: panel },
40
+ { name: "wb-roster-mine", element: "article", about: "A person's own page of their shifts", css: panel },
41
+ { name: "wb-roster-title", element: "h2", about: "\"Roster: week of …\", \"Staff\", \"Sam's shifts\"", css: "margin:0;font-size:1.25rem;font-weight:600;overflow-wrap:anywhere" },
42
+ {
43
+ name: "wb-roster-status",
44
+ element: "p",
45
+ about: "Draft, Published, or Published with changes not sent (data-status)",
46
+ css: `margin:0;padding:.4rem .75rem;background:${v("surface")};border-left:4px solid ${v("good")};border-radius:${v("radius")}`,
47
+ states: [
48
+ { selector: "[data-status=draft]", about: "Not published: staff can't see it", css: `border-left-color:${v("warn")}` },
49
+ { selector: "[data-status=unsent]", about: "Changes staff haven't been told about", css: `border-left-color:${v("warn")}` },
50
+ ],
51
+ },
52
+ { name: "wb-roster-done", element: "p", about: "What just happened: Shift added", css: `margin:0;padding:.5rem .75rem;background:${v("surface")};border-left:4px solid ${v("good")};border-radius:${v("radius")}` },
53
+ { name: "wb-roster-nav", element: "nav", about: "Last week and Next week", css: "display:flex;flex-wrap:wrap;gap:.5rem;justify-content:space-between" },
54
+ { name: "wb-roster-nav-link", element: "a", about: "Last week, Next week", css: quiet, states: [focus] },
55
+ { name: "wb-roster-gaps", element: "section", about: "The gaps check", css: `display:grid;gap:.5rem;padding:.75rem;background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
56
+ { name: "wb-roster-heading", element: "h3", about: "\"Gaps\", \"Add a shift\", \"Leave\"", css: "margin:0;font-size:1rem;font-weight:600" },
57
+ { name: "wb-roster-gap-list", element: "ul", about: "The gaps and clashes", css: "margin:0;padding-left:1.25rem;display:grid;gap:.25rem" },
58
+ { name: "wb-roster-gap", element: "li", about: "One time with too few people on", css: `color:${v("warn")}` },
59
+ { name: "wb-roster-gap-clash", element: "li", about: "A shift its person can't work (on leave, or gone)", css: `color:${v("danger")}` },
60
+ { name: "wb-roster-ok", element: "p", about: "Every time that needs people has them", css: `margin:0;color:${v("good")}` },
61
+ { name: "wb-roster-days", element: "div", about: "The week's seven days", css: "display:grid;gap:.75rem;grid-template-columns:repeat(auto-fill,minmax(15rem,1fr))" },
62
+ { name: "wb-roster-day", element: "section", about: "One day and its shifts", css: `display:grid;gap:.5rem;align-content:start;padding:.75rem;background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
63
+ { name: "wb-roster-day-title", element: "h3", about: "The day: Saturday 6 December", css: "margin:0;font-size:1rem;font-weight:600" },
64
+ { name: "wb-roster-shifts", element: "ul", about: "A day's shifts, or a person's coming shifts", css: "list-style:none;margin:0;padding:0;display:grid;gap:.5rem" },
65
+ { name: "wb-roster-shift", element: "li", about: "One shift: who, when, doing what", css: `display:flex;flex-wrap:wrap;gap:.25rem .75rem;align-items:center;padding:.5rem 0;border-bottom:1px solid ${v("line")}` },
66
+ { name: "wb-roster-who", element: "span", about: "The person's name", css: "font-weight:600;overflow-wrap:anywhere" },
67
+ { name: "wb-roster-time", element: "span", about: "When: 9:00 am – 12:00 pm", css: "font-variant-numeric:tabular-nums" },
68
+ { name: "wb-roster-role", element: "span", about: "The role: Instructor", css: `padding:.05rem .5rem;font-size:.85rem;border:1px solid ${v("line")};border-radius:999px` },
69
+ { name: "wb-roster-break", element: "span", about: "The unpaid break", css: small },
70
+ { name: "wb-roster-note", element: "span", about: "The owner's note: Open up", css: `${small};font-style:italic;overflow-wrap:anywhere` },
71
+ { name: "wb-roster-flag", element: "span", about: "On leave, no longer on the roster, has their link", css: `font-size:.85rem;font-weight:600;color:${v("warn")}` },
72
+ { name: "wb-roster-inline", element: "form", about: "A form that is only a button: Remove, Publish", css: "display:inline-flex;margin:0" },
73
+ { name: "wb-roster-remove", element: "button", about: "Remove a shift or leave", css: `${quiet};min-height:2.75rem;padding:0 .75rem;font-weight:400`, states: [focus] },
74
+ { name: "wb-roster-empty", element: "p", about: "No shifts, no leave, nobody yet", css: `margin:0;color:${v("muted")}` },
75
+ { name: "wb-roster-form", element: "form", about: "Add a shift, Add leave, Add person", css: `display:grid;gap:.75rem;padding:.75rem;background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
76
+ { name: "wb-roster-field", element: "div", about: "One field: its label and input", css: "display:grid;gap:.25rem" },
77
+ { name: "wb-roster-label", element: "label", about: "A field's name", css: "font-size:.9rem;font-weight:600" },
78
+ { name: "wb-roster-select", element: "select", about: "Who, Day, Doing", css: input, states: [focus] },
79
+ { name: "wb-roster-option", element: "option", about: "One choice in a list", css: `color:${v("text")};background:${v("sunk")}` },
80
+ { name: "wb-roster-input", element: "input", about: "Times, dates, the break, the note, name and email", css: input, states: [focus] },
81
+ { name: "wb-roster-button", element: "button", about: "Add shift, Add person", css: `${main};justify-self:start`, states: [focus] },
82
+ { name: "wb-roster-actions", element: "div", about: "Publish, Copy last week, Download hours", css: "display:flex;flex-wrap:wrap;gap:.5rem" },
83
+ { name: "wb-roster-publish", element: "button", about: "Publish and email staff, or Send the changes now", css: main, states: [focus] },
84
+ { name: "wb-roster-secondary", element: "button", about: "Copy last week, Add leave, Email them their link", css: quiet, states: [focus] },
85
+ { name: "wb-roster-export", element: "a", about: "Download hours", css: quiet, states: [focus] },
86
+ { name: "wb-roster-people", element: "ul", about: "The people on the roster", css: "list-style:none;margin:0;padding:0;display:grid;gap:.75rem" },
87
+ { name: "wb-roster-person", element: "li", about: "One person, their leave and their buttons", css: `display:grid;gap:.5rem;padding:.75rem;background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
88
+ { name: "wb-roster-detail", element: "span", about: "Email, roles and bookings name", css: `${small};overflow-wrap:anywhere` },
89
+ { name: "wb-roster-leave-list", element: "ul", about: "A person's leave", css: "list-style:none;margin:0;padding:0;display:grid;gap:.25rem" },
90
+ { name: "wb-roster-leave", element: "li", about: "One stretch of leave", css: "display:flex;flex-wrap:wrap;gap:.5rem;align-items:center;justify-content:space-between" },
91
+ { name: "wb-roster-remove-form", element: "form", about: "Take off the roster, with its tick box", css: `display:grid;gap:.5rem;padding:.75rem;border:1px solid ${v("danger")};border-radius:${v("radius")}` },
92
+ { name: "wb-roster-confirm", element: "label", about: "A tick box and its words", css: "display:flex;gap:.5rem;align-items:center;min-height:2.75rem" },
93
+ { name: "wb-roster-check", element: "input", about: "A tick box: a role, or Yes, take them off", css: `width:1.25rem;height:1.25rem;accent-color:${v("accent")}`, states: [focus] },
94
+ { name: "wb-roster-danger", element: "button", about: "Take off the roster", css: `${button};justify-self:start;color:${v("on-accent")};background:${v("danger")};border:1px solid ${v("danger")}`, states: [focus] },
95
+ { name: "wb-roster-roles", element: "fieldset", about: "The roles a new person can work", css: "display:grid;gap:.25rem;margin:0;padding:0;border:0" },
96
+ { name: "wb-roster-hint", element: "p", about: "What a field is for; this page is yours", css: `margin:0;${small}` },
97
+ { name: "wb-roster-calendar", element: "a", about: "Add my shifts to my calendar", css: `${main};justify-self:start`, states: [focus] },
98
+ ],
99
+ };
package/dist/time.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** A duration in minutes, or null when it isn't one ("3d", "12h", "30m"). */
2
+ export declare function durationMinutes(text: unknown): number | null;
3
+ /** "21:00" in minutes after midnight, or null. */
4
+ export declare function clockMinutes(text: unknown): number | null;
5
+ export declare function validZone(tz: unknown): boolean;
6
+ /** Today in the zone, YYYY-MM-DD. */
7
+ export declare function todayIn(timeZone: string, at: Date): string;
8
+ /** A real calendar day, YYYY-MM-DD. */
9
+ export declare function validDate(text: unknown): text is string;
10
+ /** A calendar day plus `n` days. */
11
+ export declare function addDays(date: string, n: number): string;
12
+ /** The day of the week of a calendar day, 0 Monday to 6 Sunday. */
13
+ export declare function weekdayIndex(date: string): number;
14
+ /** The instant a local day and clock time ("09:30") happen in the zone. */
15
+ export declare function localInstant(date: string, clock: string, timeZone: string): Date;
16
+ /** The zone's clock at an instant, "09:30". */
17
+ export declare function clockIn(timeZone: string, at: Date): string;
18
+ /** The roster week a local day is in: the week_starts day on or before it. */
19
+ export declare function weekOf(date: string, weekStarts: number): string;
package/dist/time.js ADDED
@@ -0,0 +1,92 @@
1
+ // Time in the business's time zone: shifts and cover on the local clock
2
+ // (right across a daylight saving change), roster weeks, "today", and lengths
3
+ // such as "1h". Plain code, no AI. The zone helpers are workbench-bookings'
4
+ // own (tool packages don't import each other).
5
+ const DURATION = /^(0|[1-9][0-9]{0,3})([mhd])$/;
6
+ const CLOCK = /^([01][0-9]|2[0-3]):([0-5][0-9])$/;
7
+ /** A duration in minutes, or null when it isn't one ("3d", "12h", "30m"). */
8
+ export function durationMinutes(text) {
9
+ if (typeof text !== "string")
10
+ return null;
11
+ const m = DURATION.exec(text);
12
+ if (!m)
13
+ return null;
14
+ const n = Number(m[1]);
15
+ return m[2] === "m" ? n : m[2] === "h" ? n * 60 : n * 1440;
16
+ }
17
+ /** "21:00" in minutes after midnight, or null. */
18
+ export function clockMinutes(text) {
19
+ if (typeof text !== "string")
20
+ return null;
21
+ const m = CLOCK.exec(text);
22
+ return m ? Number(m[1]) * 60 + Number(m[2]) : null;
23
+ }
24
+ export function validZone(tz) {
25
+ if (typeof tz !== "string" || !tz)
26
+ return false;
27
+ try {
28
+ new Intl.DateTimeFormat("en", { timeZone: tz });
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ function localParts(at, timeZone) {
36
+ const p = Object.fromEntries(new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" })
37
+ .formatToParts(at)
38
+ .filter((x) => x.type !== "literal")
39
+ .map((x) => [x.type, Number(x.value)]));
40
+ return { year: p.year, month: p.month, day: p.day, hour: p.hour, minute: p.minute, second: p.second };
41
+ }
42
+ /** How far the zone's clock is ahead of UTC at an instant, in milliseconds. */
43
+ function offsetAt(at, timeZone) {
44
+ const p = localParts(at, timeZone);
45
+ return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - Math.floor(at.getTime() / 1000) * 1000;
46
+ }
47
+ /** The instant a local wall-clock time (given as if it were UTC) happens in the zone. */
48
+ function fromLocal(wall, timeZone) {
49
+ const guess = wall - offsetAt(new Date(wall), timeZone);
50
+ return new Date(wall - offsetAt(new Date(guess), timeZone));
51
+ }
52
+ /** Today in the zone, YYYY-MM-DD. */
53
+ export function todayIn(timeZone, at) {
54
+ const p = localParts(at, timeZone);
55
+ return `${p.year}-${String(p.month).padStart(2, "0")}-${String(p.day).padStart(2, "0")}`;
56
+ }
57
+ const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
58
+ /** A real calendar day, YYYY-MM-DD. */
59
+ export function validDate(text) {
60
+ if (typeof text !== "string")
61
+ return false;
62
+ const m = DATE.exec(text);
63
+ if (!m)
64
+ return false;
65
+ const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
66
+ return d.toISOString().slice(0, 10) === text;
67
+ }
68
+ /** A calendar day plus `n` days. */
69
+ export function addDays(date, n) {
70
+ const [y, m, d] = date.split("-").map(Number);
71
+ return new Date(Date.UTC(y, m - 1, d + n)).toISOString().slice(0, 10);
72
+ }
73
+ /** The day of the week of a calendar day, 0 Monday to 6 Sunday. */
74
+ export function weekdayIndex(date) {
75
+ const [y, m, d] = date.split("-").map(Number);
76
+ return (new Date(Date.UTC(y, m - 1, d)).getUTCDay() + 6) % 7;
77
+ }
78
+ /** The instant a local day and clock time ("09:30") happen in the zone. */
79
+ export function localInstant(date, clock, timeZone) {
80
+ const [y, m, d] = date.split("-").map(Number);
81
+ const mins = clockMinutes(clock) ?? 0;
82
+ return fromLocal(Date.UTC(y, m - 1, d, Math.floor(mins / 60), mins % 60, 0), timeZone);
83
+ }
84
+ /** The zone's clock at an instant, "09:30". */
85
+ export function clockIn(timeZone, at) {
86
+ const p = localParts(at, timeZone);
87
+ return `${String(p.hour).padStart(2, "0")}:${String(p.minute).padStart(2, "0")}`;
88
+ }
89
+ /** The roster week a local day is in: the week_starts day on or before it. */
90
+ export function weekOf(date, weekStarts) {
91
+ return addDays(date, -((weekdayIndex(date) - weekStarts + 7) % 7));
92
+ }
@@ -0,0 +1,156 @@
1
+ /** A day of the week, as roster.json names it. */
2
+ export type Weekday = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
3
+ export declare const WEEKDAYS: readonly Weekday[];
4
+ /** A length of time: a whole number and m (minutes), h (hours) or d (days), such as "1h". */
5
+ export type Duration = `${number}${"m" | "h" | "d"}`;
6
+ /** The words a page or email is in. */
7
+ export type Lang = "en" | "tl" | "taglish";
8
+ /** One kind of work a shift can be: an instructor, the front desk. */
9
+ export interface RosterRole {
10
+ /** What the owner and staff see: "Instructor". */
11
+ title: string;
12
+ }
13
+ /** Who must be on at a time each week: "Saturday 9 to 12, one instructor". */
14
+ export interface CoverRule {
15
+ /** "09:00", on the business's 24-hour clock. */
16
+ from: string;
17
+ /** "12:00". "00:00" or a time before from is the next day. */
18
+ to: string;
19
+ /** A role in roster.json's roles. Left out: anyone rostered counts. */
20
+ role?: string;
21
+ /** How many must be on, 1 to 50. Default 1. */
22
+ people?: number;
23
+ }
24
+ /** workbench/roster.json, checked. */
25
+ export interface RosterConfig {
26
+ format: 1;
27
+ /** Shifts, weeks, emails and the export are on this time zone's clock (IANA name). */
28
+ time_zone: string;
29
+ /** The day a roster week starts. Default mon. */
30
+ week_starts?: Weekday;
31
+ /** The kinds of work shifts are for, up to 30. Left out: shifts have no role. */
32
+ roles?: Readonly<Record<string, RosterRole>>;
33
+ /** Who must be on each week, by day, for the gaps check. Up to 10 rules a day. */
34
+ cover?: Readonly<Partial<Record<Weekday, readonly CoverRule[]>>>;
35
+ /** Days the business is closed (YYYY-MM-DD): cover doesn't apply on them. */
36
+ closed?: readonly string[];
37
+ /** Changes to a published week: "auto" emails the people they touch once the owner has stopped editing for `changes_after`; "manual" only when the owner presses Send changes. Default auto. */
38
+ changes?: "auto" | "manual";
39
+ /** With changes auto: how long after the last edit the emails go. Default 1h, 5m to 1d. */
40
+ changes_after?: Duration;
41
+ /** Shifts, leave and removed staff are deleted this many months after they end. Default 24, 1 to 84. */
42
+ retention_months?: number;
43
+ }
44
+ /** One person on the roster. Kept in the app's own database only. */
45
+ export interface Staff {
46
+ id: string;
47
+ account: string;
48
+ name: string;
49
+ email: string;
50
+ /** The roles they can work, from roster.json. */
51
+ roles: string[];
52
+ /** Their name in workbench/bookings.json's resources, when customers book them: hoursFor() answers by it. */
53
+ resource: string | null;
54
+ /** The app's signed-in user id for them, when they sign in to the app. */
55
+ member: string | null;
56
+ /** False once removed: their past shifts stay for the export until the clean-up. */
57
+ active: boolean;
58
+ /** Whether they have a link to their own page and calendar feed. */
59
+ has_link: boolean;
60
+ created_at: string;
61
+ }
62
+ /** One shift: a person, a time, and what they're doing. */
63
+ export interface Shift {
64
+ id: string;
65
+ account: string;
66
+ staff: string;
67
+ /** The person's name, for the pages. */
68
+ staff_name: string;
69
+ /** The person's bookings resource, or null. */
70
+ resource: string | null;
71
+ /** The roster week it is in: the week_starts day on or before its start, YYYY-MM-DD. */
72
+ week: string;
73
+ /** ISO 8601, UTC. */
74
+ starts_at: string;
75
+ ends_at: string;
76
+ /** A role in roster.json, or null. */
77
+ role: string | null;
78
+ /** Unpaid break minutes inside it, 0 to 240. */
79
+ break_minutes: number;
80
+ /** The owner's note to the person: "Open up". */
81
+ note: string | null;
82
+ /** Goes up each time it changes, for calendar apps. */
83
+ sequence: number;
84
+ }
85
+ /** Time a person is away. Days only, and no reason is kept (a reason can be health information). */
86
+ export interface Leave {
87
+ id: string;
88
+ account: string;
89
+ staff: string;
90
+ staff_name: string;
91
+ /** ISO 8601, UTC: the start of the first day away on the business's clock. */
92
+ starts_at: string;
93
+ /** The start of the day they're back. */
94
+ ends_at: string;
95
+ }
96
+ /** A roster week's state. */
97
+ export interface WeekState {
98
+ /** YYYY-MM-DD, a week_starts day. */
99
+ week: string;
100
+ /** draft until the owner publishes it; staff see published weeks only. */
101
+ status: "draft" | "published";
102
+ published_at: string | null;
103
+ /** The last change to its shifts. */
104
+ changed_at: string | null;
105
+ /** When the people its changes touched were last emailed. */
106
+ sent_at: string | null;
107
+ /** Published, with changes nobody has been emailed about yet. */
108
+ unsent: boolean;
109
+ }
110
+ /** Everything the owner's week page shows. */
111
+ export interface WeekView extends WeekState {
112
+ /** The seven days, YYYY-MM-DD. */
113
+ days: string[];
114
+ shifts: Shift[];
115
+ leave: Leave[];
116
+ staff: Staff[];
117
+ }
118
+ /** A time the cover rules (or a session the app passes) aren't met. */
119
+ export interface Gap {
120
+ start: string;
121
+ end: string;
122
+ /** The role short, or null for anyone. */
123
+ role: string | null;
124
+ needed: number;
125
+ rostered: number;
126
+ /** A session's own title, when the gap is for one. */
127
+ title?: string;
128
+ }
129
+ /** A shift its person can't work: they're on leave, or no longer on the roster. */
130
+ export interface Clash {
131
+ shift: Shift;
132
+ reason: "on_leave" | "removed";
133
+ }
134
+ /** A dated thing that needs people on: a session from workbench-bookings, an event. The app maps its own rows to this. */
135
+ export interface CoverNeed {
136
+ start: string | Date;
137
+ end: string | Date;
138
+ role?: string;
139
+ /** Default 1. */
140
+ people?: number;
141
+ /** "Harbour walk", for the gaps list. */
142
+ title?: string;
143
+ }
144
+ /** When a resource can be booked: the shape workbench-bookings' settings option takes for each resource (its ResourceTimes). */
145
+ export interface ResourceTimes {
146
+ /** The only spans it works: its published shifts. Empty means not bookable in the range. */
147
+ shifts: [string, string][];
148
+ /** Its leave. */
149
+ away: [string, string][];
150
+ }
151
+ export interface TickResult {
152
+ /** Weeks whose changes were sent. */
153
+ weeks: number;
154
+ /** Emails sent. */
155
+ emailed: number;
156
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ // The shapes of workbench/roster.json and of what the package answers
2
+ // (docs/capabilities/21-roster.md, "Interface" and "Config format").
3
+ export const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
package/dist/ui.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import { RosterError } from "./errors.ts";
2
+ import { type Words } from "./format.ts";
3
+ import type { Roster } from "./roster.ts";
4
+ import type { Clash, Gap, Lang, Leave, RosterConfig, Shift, Staff, WeekView } from "./types.ts";
5
+ interface Common {
6
+ /** roster.config: the time zone and the roles. */
7
+ config: RosterConfig;
8
+ t?: Words;
9
+ /** The words' language when `t` has none. Default en. */
10
+ lang?: Lang;
11
+ /** The locale dates are written in. Default en-AU for en, fil-PH otherwise. */
12
+ locale?: string;
13
+ }
14
+ /** What rosterAction just did, to show "Shift added." on the page. */
15
+ export type RosterDone = "add_shift" | "remove_shift" | "publish" | "copy" | "save_staff" | "remove_staff" | "send_link" | "add_leave" | "remove_leave";
16
+ export interface WeekOptions extends Common {
17
+ /** The project's route that hands the posted fields to rosterAction. */
18
+ endpoint: string;
19
+ /** The week page's own address for a week (Last week, Next week). */
20
+ weekUrl: (week: string) => string;
21
+ /** From roster.gaps(): shown above the days. Left out: no gaps section. */
22
+ gaps?: {
23
+ gaps: Gap[];
24
+ clashes: Clash[];
25
+ };
26
+ /** Where Download hours goes for this week (the app serves exportHours there). Left out: no link. */
27
+ exportUrl?: string;
28
+ done?: RosterDone;
29
+ }
30
+ export interface StaffOptions extends Common {
31
+ endpoint: string;
32
+ /** Upcoming leave, from roster.leave(). */
33
+ leave?: readonly Leave[];
34
+ done?: RosterDone;
35
+ }
36
+ export interface MineOptions extends Common {
37
+ /** The person's calendar feed (webcal:// or https://), for Add my shifts to my calendar. */
38
+ feedUrl?: string;
39
+ }
40
+ /** The owner's week: its state, Last and Next week, the gaps, each day's shifts with Remove, Add a shift, Publish or Send changes, Copy last week and Download hours. */
41
+ export declare function renderWeek(v: WeekView, o: WeekOptions): string;
42
+ /** The owner's staff page: each person with their leave, Email them their link, Add leave and Take off the roster; then Add person. */
43
+ export declare function renderStaff(staff: readonly Staff[], o: StaffOptions): string;
44
+ /** A person's own page, from roster.mine(token): their coming shifts, their leave, and Add my shifts to my calendar. */
45
+ export declare function renderMyShifts(v: {
46
+ staff: Staff;
47
+ shifts: readonly Shift[];
48
+ leave: readonly Leave[];
49
+ }, o: MineOptions): string;
50
+ export interface ActionResult {
51
+ status: number;
52
+ /** What to answer with, as JSON. It never holds the database's or the settings check's own words. */
53
+ body: {
54
+ ok: true;
55
+ action: string;
56
+ done: RosterDone;
57
+ week?: string;
58
+ copied?: number;
59
+ skipped?: number;
60
+ emailed?: number;
61
+ } | {
62
+ ok: false;
63
+ error: string;
64
+ message: string;
65
+ };
66
+ /** The error behind a refusal, for the app's own log. Never send it: for store_failed and bad_config its message is the database's or the settings check's. */
67
+ cause?: RosterError;
68
+ }
69
+ /**
70
+ * The project's endpoint (behind the owner's sign-in) hands the posted form
71
+ * fields here with the signed-in owner's account: add_shift, remove_shift,
72
+ * publish (also Send changes), copy_week, save_staff, remove_staff (needs
73
+ * confirm=yes), send_link, add_leave and remove_leave. Another account's
74
+ * shift or person is answered as unknown.
75
+ */
76
+ export declare function rosterAction(roster: Roster, body: Record<string, unknown>, account: string): Promise<ActionResult>;
77
+ export {};