@mccaskie-labs/workbench-roster 0.0.0-stage → 0.2.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,169 @@
1
+ import { type Words } from "./format.ts";
2
+ import { type Clash, type CoverNeed, type Gap, type Lang, type Leave, type ResourceTimes, type RosterConfig, type Shift, type Staff, type TickResult, type WeekState, type WeekView } from "./types.ts";
3
+ type DbError = {
4
+ message?: string;
5
+ code?: string;
6
+ details?: string;
7
+ } | null;
8
+ /** The part of a Supabase client the roster needs. Any supabase-js client fits; use the service client. */
9
+ export interface RosterClient {
10
+ rpc(fn: string, args: Record<string, unknown>): PromiseLike<{
11
+ data: unknown;
12
+ error: DbError;
13
+ }>;
14
+ }
15
+ /** The part of workbench-email's createMailer(...) the roster uses. */
16
+ export interface RosterMailer {
17
+ send(mail: {
18
+ to: string | string[];
19
+ subject: string;
20
+ text: string;
21
+ template: string;
22
+ replyTo?: string;
23
+ attachments?: {
24
+ filename: string;
25
+ mimeType: string;
26
+ bytes: Uint8Array;
27
+ }[];
28
+ idempotencyKey?: string;
29
+ }): Promise<unknown>;
30
+ }
31
+ export interface RosterOptions {
32
+ /** The service client. */
33
+ db: RosterClient;
34
+ /** workbench/roster.json, or ROSTER_CONFIG from src/roster.generated.ts. Checked here. */
35
+ config: unknown;
36
+ /** createMailer(...). Without it no email goes; the pages still work. */
37
+ mailer?: RosterMailer;
38
+ /** The business's name for emails and calendars. Default: the account. */
39
+ business?: (account: string) => Promise<{
40
+ name: string;
41
+ replyTo?: string;
42
+ }>;
43
+ /** A person's own page and calendar feed, from their secret. Needed for the links in emails. */
44
+ links?: {
45
+ mine?: (token: string) => string;
46
+ feed?: (token: string) => string;
47
+ };
48
+ /** The emails' language. Default en. */
49
+ lang?: Lang;
50
+ /** The project's strings lookup, for the emails' words. */
51
+ t?: Words;
52
+ /** For dates and times in emails. Default en-AU (fil-PH for Tagalog and Taglish). */
53
+ locale?: string;
54
+ /** An email that failed: the roster stands and the week is tried again on the next tick. Default: console.error with no address in it. */
55
+ onEmailError?: (error: unknown, what: string) => void;
56
+ /** How many weeks one tick sends at most. Default 50. */
57
+ batch?: number;
58
+ /** The clock, for tests. */
59
+ now?: () => Date;
60
+ }
61
+ export interface StaffInput {
62
+ /** Left out: a new person. */
63
+ id?: string;
64
+ name: string;
65
+ email: string;
66
+ /** Roles from roster.json they can work. */
67
+ roles?: readonly string[];
68
+ /** Their name in workbench/bookings.json's resources, when customers book them. */
69
+ resource?: string | null;
70
+ /** The app's signed-in user id for them. */
71
+ member?: string | null;
72
+ }
73
+ export interface ShiftInput {
74
+ staff: string;
75
+ start: string | Date;
76
+ end: string | Date;
77
+ role?: string | null;
78
+ /** Unpaid break minutes, 0 to 240. Default 0. */
79
+ break_minutes?: number;
80
+ note?: string | null;
81
+ }
82
+ export interface Roster {
83
+ /** The account's people, by name; all: include those taken off. */
84
+ staff(account: string, opts?: {
85
+ all?: boolean;
86
+ }): Promise<Staff[]>;
87
+ /** Adds a person, or changes one (with id). Refused with `taken` when someone on the roster has that email or resource. */
88
+ saveStaff(account: string, input: StaffInput): Promise<Staff>;
89
+ /** Takes a person off: their link stops, their shifts from now on and their leave go (and those weeks' changes are sent), their past shifts stay for the export. With a mailer, the person is emailed that they're off, with their cancelled shifts. */
90
+ removeStaff(account: string, id: string): Promise<boolean>;
91
+ /** Makes a person a new link secret (the old one stops) and emails them their page and calendar feed. */
92
+ sendLink(account: string, id: string): Promise<{
93
+ token: string;
94
+ emailed: number;
95
+ }>;
96
+ /** Everything the owner's page shows for a week (any day in it), with how many people Publish or Send the changes would email (`emailing`). */
97
+ week(account: string, week: string): Promise<WeekView>;
98
+ addShift(account: string, input: ShiftInput): Promise<Shift>;
99
+ updateShift(account: string, id: string, input: ShiftInput): Promise<Shift>;
100
+ removeShift(account: string, id: string): Promise<boolean>;
101
+ /** Copies one week's shifts into an empty week, on the same days and local times. People away or gone are skipped. */
102
+ copyWeek(account: string, from: string, to: string): Promise<{
103
+ copied: number;
104
+ skipped: number;
105
+ }>;
106
+ /** Publishes a week and emails everyone whose shifts in it they haven't been sent yet. Again later: Send changes. */
107
+ publish(account: string, week: string): Promise<{
108
+ week: WeekState;
109
+ emailed: number;
110
+ }>;
111
+ /** Times the cover rules (and the app's own needs, such as sessions) aren't met, and shifts their person can't work. */
112
+ gaps(account: string, week: string, opts?: {
113
+ needs?: readonly CoverNeed[];
114
+ closed?: readonly string[];
115
+ }): Promise<{
116
+ gaps: Gap[];
117
+ clashes: Clash[];
118
+ }>;
119
+ /** Adds days away (first and last day, YYYY-MM-DD, on the business's clock); answers the shifts it clashes with. */
120
+ addLeave(account: string, input: {
121
+ staff: string;
122
+ from: string;
123
+ to: string;
124
+ }): Promise<{
125
+ leave: Leave;
126
+ clashes: Shift[];
127
+ }>;
128
+ /** Removes days away. With a mailer, the person is emailed that their leave is off the roster. */
129
+ removeLeave(account: string, id: string): Promise<boolean>;
130
+ /** Leave overlapping a range (default from today for a year). */
131
+ leave(account: string, opts?: {
132
+ from?: string;
133
+ to?: string;
134
+ staff?: string;
135
+ }): Promise<Leave[]>;
136
+ /** For workbench-bookings' settings option: each bookable person's published shifts and leave, by their resource name. */
137
+ hoursFor(account: string, range?: {
138
+ from?: string | Date;
139
+ to?: string | Date;
140
+ }): Promise<Record<string, ResourceTimes>>;
141
+ /** A person's own page, from their secret: their upcoming published shifts and leave. Null for a wrong or replaced secret. */
142
+ mine(token: string): Promise<{
143
+ staff: Staff;
144
+ shifts: Shift[];
145
+ leave: Leave[];
146
+ } | null>;
147
+ /** A person's calendar feed (text/calendar), or null. */
148
+ feed(token: string): Promise<string | null>;
149
+ /** Published shifts from the first day to the last (YYYY-MM-DD), as a CSV for the owner's payroll. */
150
+ exportHours(account: string, range: {
151
+ from: string;
152
+ to: string;
153
+ lang?: Lang;
154
+ }): Promise<string>;
155
+ /** From the app's cron (every 15 minutes is plenty): emails changes to published weeks once the owner has stopped editing. */
156
+ tick(): Promise<TickResult>;
157
+ /** Once a day: deletes what is past retention_months. */
158
+ cleanup(): Promise<{
159
+ shifts: number;
160
+ leave: number;
161
+ weeks: number;
162
+ staff: number;
163
+ }>;
164
+ /** The business's local time for a day and clock ("09:00"), for building a shift from the page's fields. */
165
+ at(day: string, clock: string): Date;
166
+ readonly config: RosterConfig;
167
+ }
168
+ export declare function createRoster(opts: RosterOptions): Roster;
169
+ export {};