@fabriktor/fx 0.0.194 → 0.0.196

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.
@@ -39,7 +39,7 @@ export class RouteArrivalCue {
39
39
  }
40
40
  }
41
41
  export function routeHasActiveTransport(actor, route, vehicle_id, state, location_id) {
42
- // A prior-day start requires explicit recovery, not an inactive transport.
42
+ // A prior-day start still belongs to the same active transport.
43
43
  // Keep the cue tied to stored state; the punch workflow validates its finish.
44
44
  return (actor.active_mode === UserTypeEmployee &&
45
45
  routeCanTrack(actor, route, vehicle_id, actor.owner_id) &&
@@ -5,3 +5,14 @@ export type TimesheetDate = InDate & {
5
5
  export declare function timesheetDateChoices(value: InDate): SchemaDate[];
6
6
  export declare function timesheetDate(value: TimesheetDate): SchemaDate;
7
7
  export declare function timesheetDateTime(value: TimesheetDate): number;
8
+ export declare function timesheetPunchDeadline(start: TimesheetDate): number;
9
+ export declare function timesheetPunchExpired(start: TimesheetDate, now: Date): boolean;
10
+ export declare function timesheetPunchWindow(opts: {
11
+ start: TimesheetDate;
12
+ now: Date;
13
+ minimum?: TimesheetDate;
14
+ allow_equal?: boolean;
15
+ }): {
16
+ minimum: number;
17
+ maximum: number;
18
+ };
@@ -1,3 +1,4 @@
1
+ import { TimesheetMaxPunchHours } from "@fabriktor/schema";
1
2
  import { inDateAtTimestamp, isValidInputDate, isZeroDateTime, } from "../core/date.js";
2
3
  import { PreActionBlocked } from "../core/pre-action.js";
3
4
  const minuteMS = 60_000;
@@ -36,3 +37,16 @@ export function timesheetDate(value) {
36
37
  export function timesheetDateTime(value) {
37
38
  return Date.parse(timesheetDate(value).utc);
38
39
  }
40
+ export function timesheetPunchDeadline(start) {
41
+ return timesheetDateTime(start) + TimesheetMaxPunchHours * hourMS;
42
+ }
43
+ export function timesheetPunchExpired(start, now) {
44
+ return now.getTime() > timesheetPunchDeadline(start);
45
+ }
46
+ export function timesheetPunchWindow(opts) {
47
+ const start = timesheetDateTime(opts.start);
48
+ return {
49
+ minimum: Math.max(start + (opts.allow_equal ? 0 : minuteMS), opts.minimum ? timesheetDateTime(opts.minimum) : start),
50
+ maximum: Math.min(opts.now.getTime(), timesheetPunchDeadline(opts.start)),
51
+ };
52
+ }
@@ -54,6 +54,8 @@ export declare const TimesheetsBlock: {
54
54
  readonly Active: "timesheets_active";
55
55
  readonly InvalidDay: "timesheets_invalid_day";
56
56
  readonly FinishRequired: "timesheets_finish_required";
57
+ readonly Duration: "timesheets_duration";
58
+ readonly TimeUnavailable: "timesheets_time_unavailable";
57
59
  readonly InvalidSync: "timesheets_invalid_sync";
58
60
  readonly Unconfirmed: "timesheets_unconfirmed";
59
61
  };
@@ -1,7 +1,7 @@
1
1
  import { mergeQueryOptions, queryNestedParam, queryParams, } from "@fabriktor/client";
2
2
  import { PunchStatusApproved, PunchStatusPending, PunchStatusWorking, PunchTypeIn, PunchTypeOut, PunchTypeRideIn, PunchTypeRideOut, } from "@fabriktor/schema";
3
3
  import { inDateAtTimestamp } from "../core/date.js";
4
- import { timesheetDate, timesheetDateTime, } from "./time.js";
4
+ import { timesheetDate, timesheetDateTime, timesheetPunchDeadline, timesheetPunchExpired, } from "./time.js";
5
5
  import { errRequired } from "../core/err.js";
6
6
  import { PreActionBlocked } from "../core/pre-action.js";
7
7
  import { queryRecordParams, runOwnerScopeQuery, } from "../core/query.js";
@@ -12,6 +12,8 @@ export const TimesheetsBlock = {
12
12
  Active: "timesheets_active",
13
13
  InvalidDay: "timesheets_invalid_day",
14
14
  FinishRequired: "timesheets_finish_required",
15
+ Duration: "timesheets_duration",
16
+ TimeUnavailable: "timesheets_time_unavailable",
15
17
  InvalidSync: "timesheets_invalid_sync",
16
18
  Unconfirmed: "timesheets_unconfirmed",
17
19
  };
@@ -74,7 +76,9 @@ export class TimesheetsWorkspace {
74
76
  billable;
75
77
  now;
76
78
  punchPending = false;
77
- constructor(client, actions, billable, now = () => new Date()) {
79
+ constructor(client, actions, billable, now = () => {
80
+ throw new PreActionBlocked(TimesheetsBlock.TimeUnavailable);
81
+ }) {
78
82
  this.client = client;
79
83
  this.actions = actions;
80
84
  this.billable = billable;
@@ -218,7 +222,9 @@ export class TimesheetsWorkspace {
218
222
  : undefined,
219
223
  });
220
224
  requireState(timesheetStateKey(current) === timesheetStateKey(opts.expected), TimesheetsBlock.Changed);
221
- requireState(!current.stale_day || !!opts.date, TimesheetsBlock.FinishRequired);
225
+ requireState(!!opts.date ||
226
+ !current.punch ||
227
+ !timesheetPunchExpired(current.punch.punch_in_time, await this.now()), TimesheetsBlock.FinishRequired);
222
228
  requireState(opts.action === PunchTypeOut || (current.open_punches?.length ?? 0) <= 1, TimesheetsBlock.Active);
223
229
  requireState(!current.week_sheet || timesheetIsMutable(current.week_sheet), TimesheetsBlock.Locked);
224
230
  const controls = this.actions.punchControls(current);
@@ -240,6 +246,8 @@ export class TimesheetsWorkspace {
240
246
  timesheetDateTime(current.punch.punch_in_time)
241
247
  : timesheetDateTime(opts.date) >=
242
248
  timesheetDateTime(current.punch.punch_in_time), TimesheetsBlock.InvalidDay);
249
+ requireState(timesheetDateTime(opts.date) <=
250
+ timesheetPunchDeadline(current.punch.punch_in_time), TimesheetsBlock.Duration);
243
251
  }
244
252
  opts.before_request?.();
245
253
  const context = {
@@ -289,6 +297,7 @@ export class TimesheetsWorkspace {
289
297
  await this.validateDay(opts.start, opts.timezone);
290
298
  await this.validateDay(opts.end, opts.timezone);
291
299
  requireState(timesheetDateTime(opts.end) > timesheetDateTime(opts.start), TimesheetsBlock.InvalidDay);
300
+ requireState(timesheetDateTime(opts.end) <= timesheetPunchDeadline(opts.start), TimesheetsBlock.Duration);
292
301
  const matches = opts.replace
293
302
  ? [await this.week(opts.replace.id)]
294
303
  : await this.weeks({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.194",
3
+ "version": "0.0.196",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.118",
20
+ "@fabriktor/client": "0.0.119",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.88",
22
+ "@fabriktor/schema": "0.0.89",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }