@fabriktor/fx 0.0.199 → 0.0.200

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.
@@ -48,6 +48,7 @@ export declare function availabilitySubmission(reference: AvailabilityReference,
48
48
  export declare function loadAvailabilityContext(readers: AvailabilityReaders, actor: RoutesActor, reference: AvailabilityReference, { request, signal }?: AvailabilityContextOptions): Promise<AvailabilityContext>;
49
49
  type AvailabilityWindow = Pick<InClientAvailability, "from" | "to" | "timezone">;
50
50
  export declare function isValidAvailabilityWindow(window: AvailabilityWindow): boolean;
51
+ export declare function availableClientVisitTimes(windows: readonly ClientAvailability[], now: Date): ClientAvailability[];
51
52
  export declare function availabilityWindowConflicts(inputs: readonly AvailabilityWindow[]): number[];
52
53
  export declare function validateAvailabilityWindows(inputs: readonly InClientAvailability[], context: AvailabilityContext, minimum?: number): void;
53
54
  export declare function loadAvailabilitySelection(readers: AvailabilityReaders & {
@@ -1,7 +1,7 @@
1
1
  import { UserTypeClient, UserTypeEmployer, } from "@fabriktor/schema";
2
2
  import { isFabriktorUser } from "../users/users.js";
3
3
  import { addressTimezone } from "../core/address.js";
4
- import { hoursPerDay, isValidInputDate, minutesOfDay, minutesPerHour, sameCalendarDay, } from "../core/date.js";
4
+ import { hoursPerDay, isValidInputDate, minutesOfDay, minutesPerHour, sameCalendarDay, timestampDate, } from "../core/date.js";
5
5
  import { errValidation } from "../core/err.js";
6
6
  import { normalizeIDs, resolvedID } from "../core/id.js";
7
7
  import { newChatData } from "../chat/data.js";
@@ -42,15 +42,16 @@ export const availabilityFormContextDefinition = {
42
42
  };
43
43
  },
44
44
  };
45
- const msgAvailabilityAccess = "This availability does not match the client and employer of the location.";
46
- const msgAvailabilityTimezone = "The location needs a valid saved address timezone.";
47
- const msgAvailabilityTimezoneChanged = "The location timezone has changed. Ask the sender to send a new form.";
48
- const msgAvailabilityHours = "The employer's working hours must form a valid same-day window.";
45
+ const msgAvailabilityAccess = "These visit times no longer match the client or company for this address. Ask the company to send a new request.";
46
+ const msgAvailabilityTimezone = "The visit address needs a time zone. Ask the company to update the address.";
47
+ const msgAvailabilityTimezoneChanged = "The visit address's time zone has changed. Ask the company to send a new request.";
48
+ const msgAvailabilityHours = "The company's working hours are incomplete. Ask the company to update them.";
49
49
  const msgAvailabilityMinimumWindows = "Choose at least {count} possible visit times.";
50
50
  const msgAvailabilityWindows = "Some visit times overlap. Choose another day or change their hours.";
51
51
  const msgAvailabilityOutsideHours = "Choose visit times within the working hours shown.";
52
52
  const msgAvailabilityClient = "Visit times can only be requested from clients with a Fabriktor account. Arrange external contacts’ visit times directly.";
53
- const msgAvailabilityData = "The availability request is invalid.";
53
+ const msgAvailabilityData = "This visit request cannot be opened. Ask the company to send a new request.";
54
+ const msgAvailabilityClock = "Unable to check which visit times are still available. Try again.";
54
55
  export function availabilityReference(data) {
55
56
  if (data.type !== RoutesChatDataType.AvailabilityRequest &&
56
57
  data.type !== RoutesChatDataType.AvailabilitySubmitted)
@@ -188,6 +189,27 @@ export function isValidAvailabilityWindow(window) {
188
189
  sameCalendarDay(window.from, window.to) &&
189
190
  minutesOfDay(window.from) < minutesOfDay(window.to));
190
191
  }
192
+ // Reply choices use saved UTC instants and server time. Historical route views
193
+ // continue to use the complete saved list in its existing order.
194
+ export function availableClientVisitTimes(windows, now) {
195
+ const instant = now.getTime();
196
+ if (!Number.isFinite(instant))
197
+ throw errValidation({ msg: msgAvailabilityClock });
198
+ return windows
199
+ .flatMap((window) => {
200
+ const start = timestampDate(window.from.utc)?.getTime();
201
+ const end = timestampDate(window.to.utc)?.getTime();
202
+ return isValidAvailabilityWindow(window) &&
203
+ start !== undefined &&
204
+ end !== undefined &&
205
+ start < end &&
206
+ end > instant
207
+ ? [{ window, start, end }]
208
+ : [];
209
+ })
210
+ .sort((a, b) => a.start - b.start || a.end - b.end)
211
+ .map(({ window }) => window);
212
+ }
191
213
  // Return every affected row, including duplicates. Incomplete rows are handled
192
214
  // by the inputs' required/date/time rules, not by the overlap rule.
193
215
  export function availabilityWindowConflicts(inputs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.199",
3
+ "version": "0.0.200",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {