@fabriktor/fx 0.0.198 → 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.
@@ -3,7 +3,7 @@ import type { PollScheduler } from "../core/poll.js";
3
3
  import type { PreferencesFXOperator } from "./preferences.js";
4
4
  export declare const colorModes: readonly ["light", "dark"];
5
5
  export declare function isColorMode(value: unknown): value is ColorMode;
6
- export type AppPreferencesInput = Pick<InPrefApp, "color_mode" | "quiet_mode">;
6
+ export type AppPreferencesInput = Pick<InPrefApp, "color_mode" | "quiet_mode" | "skip_credit_confirmations">;
7
7
  export type AppPreferencesState = AppPreferencesInput & {
8
8
  readonly ready: boolean;
9
9
  readonly loading: boolean;
@@ -28,6 +28,7 @@ export class AppPreferencesController {
28
28
  return {
29
29
  color_mode: isColorMode(mode) ? mode : ColorModeDark,
30
30
  quiet_mode: quiet,
31
+ skip_credit_confirmations: this.current?.skip_credit_confirmations ?? false,
31
32
  ready: this.current !== undefined,
32
33
  loading: this.pending !== undefined,
33
34
  saving: this.saving,
@@ -6,7 +6,7 @@ export type GetPrefAppOptions = {
6
6
  signal?: AbortSignal;
7
7
  };
8
8
  export type SavePrefAppOptions = GetPrefAppOptions & {
9
- in: Partial<Pick<InPrefApp, "color_mode" | "quiet_mode">>;
9
+ in: Partial<Pick<InPrefApp, "color_mode" | "quiet_mode" | "skip_credit_confirmations">>;
10
10
  };
11
11
  export declare const PreferencesEvents: {
12
12
  readonly CompanySaved: import("../index.js").EventKey<PrefCompany>;
@@ -74,6 +74,13 @@ export class PreferencesFX {
74
74
  msg: "Quiet mode must be a boolean.",
75
75
  });
76
76
  }
77
+ if (opts.in.skip_credit_confirmations !== undefined &&
78
+ typeof opts.in.skip_credit_confirmations !== "boolean") {
79
+ throw errValidation({
80
+ field: "skip_credit_confirmations",
81
+ msg: "Credit confirmation preference must be a boolean.",
82
+ });
83
+ }
77
84
  let pref = await this.getPrefApp(opts);
78
85
  opts.signal?.throwIfAborted();
79
86
  // Patch only the requested fields; another device may change the other setting.
@@ -82,7 +89,11 @@ export class PreferencesFX {
82
89
  input.color_mode = opts.in.color_mode;
83
90
  if (opts.in.quiet_mode !== undefined)
84
91
  input.quiet_mode = opts.in.quiet_mode;
85
- if (opts.in.color_mode === undefined && opts.in.quiet_mode === undefined)
92
+ if (opts.in.skip_credit_confirmations !== undefined)
93
+ input.skip_credit_confirmations = opts.in.skip_credit_confirmations;
94
+ if (opts.in.color_mode === undefined &&
95
+ opts.in.quiet_mode === undefined &&
96
+ opts.in.skip_credit_confirmations === undefined)
86
97
  return pref;
87
98
  let id = pref.id;
88
99
  if (pref.is_default) {
@@ -92,6 +103,9 @@ export class PreferencesFX {
92
103
  is_default: false,
93
104
  color_mode: opts.in.color_mode ?? pref.color_mode,
94
105
  quiet_mode: opts.in.quiet_mode ?? pref.quiet_mode,
106
+ skip_credit_confirmations: opts.in.skip_credit_confirmations ??
107
+ pref.skip_credit_confirmations ??
108
+ false,
95
109
  },
96
110
  signal: opts.signal,
97
111
  });
@@ -1,4 +1,4 @@
1
- import type { ProcessesOperator, SpeechToTextOptions } from "@fabriktor/client";
1
+ import type { CorrectTextOptions, ProcessesOperator, SpeechToTextOptions } from "@fabriktor/client";
2
2
  import type { PrefLanguage } from "@fabriktor/schema";
3
3
  import type { PreferencesFXOperator } from "../preferences/preferences.js";
4
4
  export type SpeechToTextAndSaveSourceLanguageOptions = {
@@ -14,6 +14,7 @@ export type ProcessesFXOptions = {
14
14
  preferences_fx: PreferencesFXOperator;
15
15
  };
16
16
  export interface ProcessesFXOperator {
17
+ correctText(opts: CorrectTextOptions): Promise<string>;
17
18
  speechToText(opts: SpeechToTextOptions): Promise<string>;
18
19
  speechToTextAndSaveSourceLanguage(opts: SpeechToTextAndSaveSourceLanguageOptions): Promise<SpeechToTextAndSaveSourceLanguageResult>;
19
20
  }
@@ -21,6 +22,7 @@ export declare class ProcessesFX implements ProcessesFXOperator {
21
22
  private processes;
22
23
  private preferences_fx;
23
24
  constructor(opts: ProcessesFXOptions);
25
+ correctText(opts: CorrectTextOptions): Promise<string>;
24
26
  speechToText(opts: SpeechToTextOptions): Promise<string>;
25
27
  speechToTextAndSaveSourceLanguage(opts: SpeechToTextAndSaveSourceLanguageOptions): Promise<SpeechToTextAndSaveSourceLanguageResult>;
26
28
  }
@@ -1,4 +1,4 @@
1
- import { errResolveFailed } from "../core/err.js";
1
+ import { errRequired, errResolveFailed } from "../core/err.js";
2
2
  const resourceSpeechToTextTranscription = "speech_to_text_transcription";
3
3
  const msgSpeechToTextTranscriptionMissing = "Speech-to-text response did not include a transcription.";
4
4
  export class ProcessesFX {
@@ -8,6 +8,20 @@ export class ProcessesFX {
8
8
  this.processes = opts.processes;
9
9
  this.preferences_fx = opts.preferences_fx;
10
10
  }
11
+ async correctText(opts) {
12
+ if (opts.text.trim() === "") {
13
+ throw errRequired({ field: "text", msg: "Enter some text to correct." });
14
+ }
15
+ const out = await this.processes.correctText(opts);
16
+ const text = out.value?.text;
17
+ if (typeof text !== "string" || text.trim() === "") {
18
+ throw errResolveFailed({
19
+ resource: "corrected_text",
20
+ msg: "The correction was not returned.",
21
+ });
22
+ }
23
+ return text;
24
+ }
11
25
  async speechToText(opts) {
12
26
  const out = await this.processes.speechToText(opts);
13
27
  const transcription = out.value?.transcriptions.at(0)?.text.trim() ?? "";
@@ -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.198",
3
+ "version": "0.0.200",
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.120",
20
+ "@fabriktor/client": "0.0.121",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.90",
22
+ "@fabriktor/schema": "0.0.91",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }