@kernhq/module-hr 0.2.0 → 0.4.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.
- package/dist/contract/approvals.d.ts +281 -0
- package/dist/contract/approvals.d.ts.map +1 -0
- package/dist/contract/approvals.js +127 -0
- package/dist/contract/approvals.js.map +1 -0
- package/dist/contract/attendance.d.ts +240 -0
- package/dist/contract/attendance.d.ts.map +1 -0
- package/dist/contract/attendance.js +154 -0
- package/dist/contract/attendance.js.map +1 -0
- package/dist/contract/capabilities.d.ts +1 -1
- package/dist/contract/capabilities.d.ts.map +1 -1
- package/dist/contract/capabilities.js +80 -0
- package/dist/contract/capabilities.js.map +1 -1
- package/dist/contract/events.d.ts +60 -0
- package/dist/contract/events.d.ts.map +1 -1
- package/dist/contract/events.js +60 -0
- package/dist/contract/events.js.map +1 -1
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +3 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/leave.d.ts +168 -0
- package/dist/contract/leave.d.ts.map +1 -0
- package/dist/contract/leave.js +150 -0
- package/dist/contract/leave.js.map +1 -0
- package/dist/contract/permissions.d.ts +100 -0
- package/dist/contract/permissions.d.ts.map +1 -1
- package/dist/contract/permissions.js +119 -0
- package/dist/contract/permissions.js.map +1 -1
- package/dist/contract/router.d.ts +2440 -0
- package/dist/contract/router.d.ts.map +1 -1
- package/dist/contract/router.js +393 -0
- package/dist/contract/router.js.map +1 -1
- package/dist/policy/time.d.ts +48 -0
- package/dist/policy/time.d.ts.map +1 -0
- package/dist/policy/time.js +144 -0
- package/dist/policy/time.js.map +1 -0
- package/dist/policy/working-time.d.ts +98 -0
- package/dist/policy/working-time.d.ts.map +1 -0
- package/dist/policy/working-time.js +190 -0
- package/dist/policy/working-time.js.map +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs.d.ts +16 -0
- package/dist/server/jobs.d.ts.map +1 -0
- package/dist/server/jobs.js +166 -0
- package/dist/server/jobs.js.map +1 -0
- package/dist/server/router.d.ts +2731 -58
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/router.js +1306 -3
- package/dist/server/router.js.map +1 -1
- package/dist/server/schema.d.ts +3344 -1
- package/dist/server/schema.d.ts.map +1 -1
- package/dist/server/schema.js +325 -0
- package/dist/server/schema.js.map +1 -1
- package/dist/server/services/approvals.d.ts +163 -0
- package/dist/server/services/approvals.d.ts.map +1 -0
- package/dist/server/services/approvals.js +325 -0
- package/dist/server/services/approvals.js.map +1 -0
- package/dist/server/services/attendance.d.ts +150 -0
- package/dist/server/services/attendance.d.ts.map +1 -0
- package/dist/server/services/attendance.js +239 -0
- package/dist/server/services/attendance.js.map +1 -0
- package/dist/server/services/ledger.d.ts +135 -0
- package/dist/server/services/ledger.d.ts.map +1 -0
- package/dist/server/services/ledger.js +178 -0
- package/dist/server/services/ledger.js.map +1 -0
- package/dist/server/services/people.d.ts +3 -3
- package/migrations/0002_leave.sql +237 -0
- package/migrations/0003_attendance.sql +206 -0
- package/migrations/meta/0002_snapshot.json +3009 -0
- package/migrations/meta/0003_snapshot.json +3681 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +1 -1
- package/src/contract/approvals.ts +149 -0
- package/src/contract/attendance.ts +180 -0
- package/src/contract/capabilities.ts +80 -0
- package/src/contract/events.ts +81 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/leave.ts +171 -0
- package/src/contract/permissions.ts +122 -0
- package/src/contract/router.ts +481 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Timestamp, WorkspaceId } from '@kernhq/contracts'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { IsoDate } from './models.js'
|
|
4
|
+
|
|
5
|
+
const ws = { workspaceId: WorkspaceId }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Leave, and the one rule everything here follows: **a balance is a sum, never a stored number.**
|
|
9
|
+
*
|
|
10
|
+
* Every grant, accrual, consumption, reversal, expiry and adjustment is an append-only ledger entry.
|
|
11
|
+
* Cancelling approved leave inserts a reversal; it does not delete the consumption. That costs a
|
|
12
|
+
* little arithmetic and buys the only thing that matters when an employee and HR disagree about a
|
|
13
|
+
* balance: a list of what happened, in order, that nobody edited.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const LeaveUnit = z.enum(['day', 'half_day', 'hour'])
|
|
17
|
+
export type LeaveUnit = z.infer<typeof LeaveUnit>
|
|
18
|
+
|
|
19
|
+
export const LeaveType = z.object({
|
|
20
|
+
id: z.uuid(),
|
|
21
|
+
...ws,
|
|
22
|
+
key: z
|
|
23
|
+
.string()
|
|
24
|
+
.min(1)
|
|
25
|
+
.max(48)
|
|
26
|
+
.regex(/^[a-z][a-z0-9_]*$/),
|
|
27
|
+
name: z.string().min(1).max(120),
|
|
28
|
+
/** Unpaid leave still consumes calendar days; it just does not cost money. */
|
|
29
|
+
paid: z.boolean(),
|
|
30
|
+
unit: LeaveUnit,
|
|
31
|
+
color: z.string().max(32).nullable(),
|
|
32
|
+
icon: z.string().max(48).nullable(),
|
|
33
|
+
/** A sick note after N consecutive days. Null means never. */
|
|
34
|
+
requiresDocumentAfterDays: z.number().int().min(1).nullable(),
|
|
35
|
+
/** Weekends and public holidays inside a request do not consume balance. Almost always true. */
|
|
36
|
+
countsWorkingDaysOnly: z.boolean(),
|
|
37
|
+
allowNegative: z.boolean(),
|
|
38
|
+
/** How far below zero, in minutes. Only consulted when `allowNegative`. */
|
|
39
|
+
maxNegativeMinutes: z.number().int().min(0),
|
|
40
|
+
/** Sort order in pickers. */
|
|
41
|
+
order: z.number().int(),
|
|
42
|
+
archivedAt: Timestamp.nullable(),
|
|
43
|
+
})
|
|
44
|
+
export type LeaveType = z.infer<typeof LeaveType>
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Why a ledger entry exists. The set is closed on purpose — a new kind of movement is a decision,
|
|
48
|
+
* not a string somebody passes in.
|
|
49
|
+
*/
|
|
50
|
+
export const LedgerKind = z.enum([
|
|
51
|
+
/** An allowance handed out: the annual entitlement, a one-off award. */
|
|
52
|
+
'grant',
|
|
53
|
+
/** Earned over time by an accrual policy. */
|
|
54
|
+
'accrual',
|
|
55
|
+
/** Spent by an approved request. Negative. */
|
|
56
|
+
'consumption',
|
|
57
|
+
/** Undoes an earlier entry, cancellation or a retroactive correction. Points at what it reverses. */
|
|
58
|
+
'reversal',
|
|
59
|
+
/** Unused balance lapsing at a carry-forward deadline. Negative. */
|
|
60
|
+
'expiry',
|
|
61
|
+
/** A human decided. Always carries a reason. */
|
|
62
|
+
'adjustment',
|
|
63
|
+
'carry_in',
|
|
64
|
+
'carry_out',
|
|
65
|
+
/** Paid out instead of taken. Negative. */
|
|
66
|
+
'encashment',
|
|
67
|
+
])
|
|
68
|
+
export type LedgerKind = z.infer<typeof LedgerKind>
|
|
69
|
+
|
|
70
|
+
export const LeaveLedgerEntry = z.object({
|
|
71
|
+
id: z.uuid(),
|
|
72
|
+
...ws,
|
|
73
|
+
personId: z.uuid(),
|
|
74
|
+
leaveTypeId: z.uuid(),
|
|
75
|
+
kind: LedgerKind,
|
|
76
|
+
/**
|
|
77
|
+
* Signed, in minutes. Minutes rather than days because half-days, hourly leave and part-time
|
|
78
|
+
* fractions all divide a day, and a decimal day accumulates rounding error across a year of them.
|
|
79
|
+
*/
|
|
80
|
+
amountMinutes: z.number().int(),
|
|
81
|
+
effectiveOn: IsoDate,
|
|
82
|
+
/** Which entitlement year this belongs to. Carry-forward and expiry work on it. */
|
|
83
|
+
periodYear: z.number().int(),
|
|
84
|
+
requestId: z.uuid().nullable(),
|
|
85
|
+
reversesEntryId: z.uuid().nullable(),
|
|
86
|
+
/** Which policy version produced it, so a recomputation can tell what it was computed with. */
|
|
87
|
+
policyHash: z.string().max(64).nullable(),
|
|
88
|
+
reason: z.string().max(500).nullable(),
|
|
89
|
+
createdBy: z.uuid().nullable(),
|
|
90
|
+
createdAt: Timestamp,
|
|
91
|
+
})
|
|
92
|
+
export type LeaveLedgerEntry = z.infer<typeof LeaveLedgerEntry>
|
|
93
|
+
|
|
94
|
+
export const LeaveBalance = z.object({
|
|
95
|
+
personId: z.uuid(),
|
|
96
|
+
leaveTypeId: z.uuid(),
|
|
97
|
+
leaveTypeName: z.string(),
|
|
98
|
+
unit: LeaveUnit,
|
|
99
|
+
periodYear: z.number().int(),
|
|
100
|
+
/** The sum of every entry. Minutes. */
|
|
101
|
+
balanceMinutes: z.number().int(),
|
|
102
|
+
/** Approved but not yet taken — already spent, shown separately so "remaining" is not a surprise. */
|
|
103
|
+
bookedMinutes: z.number().int(),
|
|
104
|
+
/** Submitted and not yet decided. Not spent, but not available either. */
|
|
105
|
+
pendingMinutes: z.number().int(),
|
|
106
|
+
/** `balance - pending`. What a person can actually request today without going negative. */
|
|
107
|
+
availableMinutes: z.number().int(),
|
|
108
|
+
/** The same figures in whatever unit the type uses, for display. */
|
|
109
|
+
balance: z.number(),
|
|
110
|
+
available: z.number(),
|
|
111
|
+
})
|
|
112
|
+
export type LeaveBalance = z.infer<typeof LeaveBalance>
|
|
113
|
+
|
|
114
|
+
export const LeaveRequestStatus = z.enum([
|
|
115
|
+
'draft',
|
|
116
|
+
'pending',
|
|
117
|
+
'approved',
|
|
118
|
+
'rejected',
|
|
119
|
+
'cancelled',
|
|
120
|
+
/** Approved, then cancelled or corrected afterwards. The ledger carries a reversal. */
|
|
121
|
+
'withdrawn',
|
|
122
|
+
])
|
|
123
|
+
export type LeaveRequestStatus = z.infer<typeof LeaveRequestStatus>
|
|
124
|
+
|
|
125
|
+
/** Which half of a day a request starts or ends on. */
|
|
126
|
+
export const DayPart = z.enum(['full', 'morning', 'afternoon'])
|
|
127
|
+
export type DayPart = z.infer<typeof DayPart>
|
|
128
|
+
|
|
129
|
+
export const LeaveRequest = z.object({
|
|
130
|
+
id: z.uuid(),
|
|
131
|
+
...ws,
|
|
132
|
+
personId: z.uuid(),
|
|
133
|
+
leaveTypeId: z.uuid(),
|
|
134
|
+
startsOn: IsoDate,
|
|
135
|
+
endsOn: IsoDate,
|
|
136
|
+
startPart: DayPart,
|
|
137
|
+
endPart: DayPart,
|
|
138
|
+
/** For hourly leave. Null for day-based types. */
|
|
139
|
+
hours: z.number().min(0).max(24).nullable(),
|
|
140
|
+
/** Working days consumed, after the calendar is applied. Recomputed on approval. */
|
|
141
|
+
workingDays: z.number(),
|
|
142
|
+
minutes: z.number().int(),
|
|
143
|
+
status: LeaveRequestStatus,
|
|
144
|
+
reason: z.string().max(1000).nullable(),
|
|
145
|
+
documentFileId: z.uuid().nullable(),
|
|
146
|
+
approvalRequestId: z.uuid().nullable(),
|
|
147
|
+
decidedAt: Timestamp.nullable(),
|
|
148
|
+
createdAt: Timestamp,
|
|
149
|
+
updatedAt: Timestamp,
|
|
150
|
+
})
|
|
151
|
+
export type LeaveRequest = z.infer<typeof LeaveRequest>
|
|
152
|
+
|
|
153
|
+
/** What a request would cost, before anybody submits it. */
|
|
154
|
+
export const LeaveSimulation = z.object({
|
|
155
|
+
workingDays: z.number(),
|
|
156
|
+
minutes: z.number().int(),
|
|
157
|
+
/** Day by day, so somebody can see *why* a five-day request costs three. */
|
|
158
|
+
days: z.array(
|
|
159
|
+
z.object({
|
|
160
|
+
date: IsoDate,
|
|
161
|
+
fraction: z.number(),
|
|
162
|
+
counted: z.boolean(),
|
|
163
|
+
reason: z.string().nullable(),
|
|
164
|
+
}),
|
|
165
|
+
),
|
|
166
|
+
balanceBeforeMinutes: z.number().int(),
|
|
167
|
+
balanceAfterMinutes: z.number().int(),
|
|
168
|
+
/** Reasons this would be refused if submitted. Empty means it would go through. */
|
|
169
|
+
blockers: z.array(z.object({ code: z.string(), message: z.string() })),
|
|
170
|
+
})
|
|
171
|
+
export type LeaveSimulation = z.infer<typeof LeaveSimulation>
|
|
@@ -181,6 +181,114 @@ export const hrPermissions = definePermissions([
|
|
|
181
181
|
dangerous: true,
|
|
182
182
|
},
|
|
183
183
|
|
|
184
|
+
// ---------------------------------------------------------------- leave
|
|
185
|
+
{
|
|
186
|
+
key: 'hr.leave.request',
|
|
187
|
+
label: 'Request time off',
|
|
188
|
+
// Everybody. A permission an employee cannot lack is noise, but this one is genuinely revocable
|
|
189
|
+
// — a contractor who books time off through their agency should not have the button.
|
|
190
|
+
scope: 'workspace',
|
|
191
|
+
defaultRoles: ['owner', 'admin', 'member'],
|
|
192
|
+
dangerous: false,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: 'hr.leave.view',
|
|
196
|
+
label: 'View leave types and your own balance',
|
|
197
|
+
scope: 'workspace',
|
|
198
|
+
defaultRoles: ['owner', 'admin', 'member'],
|
|
199
|
+
dangerous: false,
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
key: 'hr.leave.view_team',
|
|
203
|
+
label: "View your team's leave and balances",
|
|
204
|
+
scope: 'object',
|
|
205
|
+
defaultRoles: ['owner', 'admin'],
|
|
206
|
+
dangerous: false,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
key: 'hr.leave.view_ledger',
|
|
210
|
+
label: "View the movements behind somebody's balance",
|
|
211
|
+
scope: 'workspace',
|
|
212
|
+
defaultRoles: ['owner', 'admin'],
|
|
213
|
+
dangerous: false,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'hr.leave.manage',
|
|
217
|
+
label: 'Configure leave types',
|
|
218
|
+
scope: 'workspace',
|
|
219
|
+
defaultRoles: ['owner', 'admin'],
|
|
220
|
+
dangerous: false,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: 'hr.leave.adjust',
|
|
224
|
+
label: "Change somebody's balance by hand",
|
|
225
|
+
description: 'Adds or removes leave directly. Every adjustment is recorded with its reason.',
|
|
226
|
+
scope: 'workspace',
|
|
227
|
+
defaultRoles: [],
|
|
228
|
+
dangerous: true,
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
// ---------------------------------------------------------------- attendance
|
|
232
|
+
{
|
|
233
|
+
key: 'hr.attendance.punch',
|
|
234
|
+
label: 'Clock yourself in and out',
|
|
235
|
+
scope: 'workspace',
|
|
236
|
+
defaultRoles: ['owner', 'admin', 'member'],
|
|
237
|
+
dangerous: false,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
key: 'hr.attendance.view',
|
|
241
|
+
label: 'View your own attendance',
|
|
242
|
+
scope: 'workspace',
|
|
243
|
+
defaultRoles: ['owner', 'admin', 'member'],
|
|
244
|
+
dangerous: false,
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
key: 'hr.attendance.view_team',
|
|
248
|
+
label: "View your team's attendance",
|
|
249
|
+
scope: 'object',
|
|
250
|
+
defaultRoles: ['owner', 'admin'],
|
|
251
|
+
dangerous: false,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
key: 'hr.attendance.manage',
|
|
255
|
+
label: 'Correct punches, schedules and day sheets',
|
|
256
|
+
description: 'Voids punches and recomputes days. Every change leaves the original visible.',
|
|
257
|
+
scope: 'workspace',
|
|
258
|
+
defaultRoles: ['owner', 'admin'],
|
|
259
|
+
dangerous: true,
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
key: 'hr.overtime.view',
|
|
263
|
+
label: 'View overtime',
|
|
264
|
+
scope: 'workspace',
|
|
265
|
+
defaultRoles: ['owner', 'admin'],
|
|
266
|
+
dangerous: false,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
key: 'hr.overtime.manage',
|
|
270
|
+
label: 'Approve and adjust overtime',
|
|
271
|
+
scope: 'workspace',
|
|
272
|
+
defaultRoles: ['owner', 'admin'],
|
|
273
|
+
dangerous: false,
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
// ---------------------------------------------------------------- approvals
|
|
277
|
+
{
|
|
278
|
+
key: 'hr.approval.manage',
|
|
279
|
+
label: 'Configure approval chains',
|
|
280
|
+
scope: 'workspace',
|
|
281
|
+
defaultRoles: ['owner', 'admin'],
|
|
282
|
+
dangerous: false,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
key: 'hr.approval.delegate',
|
|
286
|
+
label: 'Hand your approvals to somebody else while away',
|
|
287
|
+
scope: 'workspace',
|
|
288
|
+
defaultRoles: ['owner', 'admin', 'member'],
|
|
289
|
+
dangerous: false,
|
|
290
|
+
},
|
|
291
|
+
|
|
184
292
|
// ---------------------------------------------------------------- fields
|
|
185
293
|
{
|
|
186
294
|
key: 'hr.field.manage',
|
|
@@ -214,4 +322,18 @@ export const HR_PERMISSIONS = {
|
|
|
214
322
|
documentView: 'hr.document.view',
|
|
215
323
|
documentManage: 'hr.document.manage',
|
|
216
324
|
fieldManage: 'hr.field.manage',
|
|
325
|
+
leaveRequest: 'hr.leave.request',
|
|
326
|
+
leaveView: 'hr.leave.view',
|
|
327
|
+
leaveViewTeam: 'hr.leave.view_team',
|
|
328
|
+
leaveViewLedger: 'hr.leave.view_ledger',
|
|
329
|
+
leaveManage: 'hr.leave.manage',
|
|
330
|
+
leaveAdjust: 'hr.leave.adjust',
|
|
331
|
+
attendancePunch: 'hr.attendance.punch',
|
|
332
|
+
attendanceView: 'hr.attendance.view',
|
|
333
|
+
attendanceViewTeam: 'hr.attendance.view_team',
|
|
334
|
+
attendanceManage: 'hr.attendance.manage',
|
|
335
|
+
overtimeView: 'hr.overtime.view',
|
|
336
|
+
overtimeManage: 'hr.overtime.manage',
|
|
337
|
+
approvalManage: 'hr.approval.manage',
|
|
338
|
+
approvalDelegate: 'hr.approval.delegate',
|
|
217
339
|
} as const
|