@mccaskie-labs/workbench-bookings 0.2.0 → 0.2.2
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/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/dist/bookings.js +2 -2
- package/dist/time.d.ts +6 -0
- package/dist/time.js +15 -0
- package/dist/ui.d.ts +4 -1
- package/dist/ui.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-bookings
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- A reminder given in days ("1d") is now counted on the business's local clock, the way workbench-messages and workbench-nudges count days: a day before a 10:00 booking is 10:00 the day before, also when daylight saving changes in between. It was 24 elapsed hours, so across a clock change the email reminder and a WhatsApp reminder for the same booking went an hour apart. Hours and minutes ("24h", "30m") are still elapsed time. `cancel_until`, `notice` and `hold` are unchanged.
|
|
8
|
+
|
|
9
|
+
## 0.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- `bookingAction` and `ownerBookingAction` no longer put the database's or the settings check's own words in the answer they hand back. For `store_failed` and `bad_config` the body's `message` is now a fixed line, so an app that sends `body` to the browser as JSON (the documented use) can't show a visitor a constraint name or a Postgres error code. The full error is on the new `ActionResult.cause`, for the app's own log. `text`, `error`, `field` and the status are unchanged.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ const tz = BOOKING_CONFIG.time_zone
|
|
|
56
56
|
renderSlotPicker(days, { endpoint: '/book/details', service: 'appointment', title: 'Appointment', timeZone: tz, more: '/book?from=2026-12-07' })
|
|
57
57
|
renderBookingForm({ endpoint: '/book', service, title, start, timeZone: tz, ask: BOOKING_CONFIG.ask, confirm: BOOKING_CONFIG.confirm })
|
|
58
58
|
const r = await bookingAction(bookings, fields, { account }) // after Turnstile; r.body.text and r.body.field when it didn't go through
|
|
59
|
+
// r.body is safe to send as JSON as it is. When r.cause is set, log it: for store_failed and bad_config the detail is only there.
|
|
59
60
|
renderBookingDone(r.body.booking, { title, timeZone: tz, manage: `/b/${r.body.token}`, ics: `/b/${r.body.token}.ics` })
|
|
60
61
|
renderBookingManage(booking, { endpoint: '/book', token, title, timeZone: tz, changeable: bookings.changeable(booking), move: `/b/${token}/move` })
|
|
61
62
|
// Behind the owner's sign-in:
|
package/dist/bookings.js
CHANGED
|
@@ -13,7 +13,7 @@ import { BookingsError } from "./errors.js";
|
|
|
13
13
|
import { DEFAULT_LOCALE, whenText, words } from "./format.js";
|
|
14
14
|
import { bookingIcs, feedIcs } from "./ical.js";
|
|
15
15
|
import { offered, openSlots, serviceOf } from "./slots.js";
|
|
16
|
-
import { addDays, durationMinutes, localInstant, todayIn, validDate } from "./time.js";
|
|
16
|
+
import { addDays, durationMinutes, localInstant, minusDuration, todayIn, validDate } from "./time.js";
|
|
17
17
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
18
|
const TOKEN = /^[A-Za-z0-9_-]{43}$/;
|
|
19
19
|
const EMAIL = /^[^\s@<>(),;:"[\]\\]+@[^\s@<>(),;:"[\]\\]+\.[^\s@<>(),;:"[\]\\]+$/;
|
|
@@ -78,7 +78,7 @@ export function customerOf(v, ask = {}) {
|
|
|
78
78
|
}
|
|
79
79
|
/** When the next reminder goes: the earliest reminder time after `after`, before the start. */
|
|
80
80
|
export function nextReminder(config, start, after) {
|
|
81
|
-
const times = (config.reminders ?? ["1d"]).map((d) => start.getTime()
|
|
81
|
+
const times = (config.reminders ?? ["1d"]).map((d) => minusDuration(start, d, config.time_zone).getTime()).filter((t) => t > after.getTime() && t < start.getTime());
|
|
82
82
|
return times.length ? new Date(Math.min(...times)) : null;
|
|
83
83
|
}
|
|
84
84
|
/** The Gateway's Idempotency-Key for one email: the same for a retry, and inside workbench-email's [A-Za-z0-9._:-]. */
|
package/dist/time.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ export declare function durationMinutes(text: unknown): number | null;
|
|
|
3
3
|
/** "21:00" in minutes after midnight, or null. */
|
|
4
4
|
export declare function clockMinutes(text: unknown): number | null;
|
|
5
5
|
export declare function validZone(tz: unknown): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* `at` minus a length: days on the local clock ("1d" before 10:00 is 10:00
|
|
8
|
+
* the day before, also across a daylight saving change, as workbench-messages
|
|
9
|
+
* and workbench-nudges count them), minutes and hours as elapsed time.
|
|
10
|
+
*/
|
|
11
|
+
export declare function minusDuration(at: Date, duration: string, timeZone: string): Date;
|
|
6
12
|
/** Today in the zone, YYYY-MM-DD. */
|
|
7
13
|
export declare function todayIn(timeZone: string, at: Date): string;
|
|
8
14
|
/** A real calendar day, YYYY-MM-DD. */
|
package/dist/time.js
CHANGED
|
@@ -48,6 +48,21 @@ function fromLocal(wall, timeZone) {
|
|
|
48
48
|
const guess = wall - offsetAt(new Date(wall), timeZone);
|
|
49
49
|
return new Date(wall - offsetAt(new Date(guess), timeZone));
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* `at` minus a length: days on the local clock ("1d" before 10:00 is 10:00
|
|
53
|
+
* the day before, also across a daylight saving change, as workbench-messages
|
|
54
|
+
* and workbench-nudges count them), minutes and hours as elapsed time.
|
|
55
|
+
*/
|
|
56
|
+
export function minusDuration(at, duration, timeZone) {
|
|
57
|
+
const minutes = durationMinutes(duration);
|
|
58
|
+
if (minutes === null)
|
|
59
|
+
throw new Error(`${duration} isn't a length such as 1d, 2h or 30m`);
|
|
60
|
+
if (!duration.endsWith("d"))
|
|
61
|
+
return new Date(at.getTime() - minutes * 60_000);
|
|
62
|
+
const p = localParts(at, timeZone);
|
|
63
|
+
const wall = Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) + (at.getTime() % 1000);
|
|
64
|
+
return fromLocal(wall - minutes * 60_000, timeZone);
|
|
65
|
+
}
|
|
51
66
|
/** Today in the zone, YYYY-MM-DD. */
|
|
52
67
|
export function todayIn(timeZone, at) {
|
|
53
68
|
const p = localParts(at, timeZone);
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Bookings } from "./bookings.ts";
|
|
2
|
-
import { type BookingsErrorCode } from "./errors.ts";
|
|
2
|
+
import { BookingsError, type BookingsErrorCode } from "./errors.ts";
|
|
3
3
|
import { type Words } from "./format.ts";
|
|
4
4
|
import type { Booking, BookingConfig, SlotDay } from "./types.ts";
|
|
5
5
|
interface Common {
|
|
@@ -94,6 +94,7 @@ export interface MineOptions extends Common {
|
|
|
94
94
|
export declare function renderMyBookings(bookings: readonly Booking[], o: MineOptions): string;
|
|
95
95
|
export interface ActionResult {
|
|
96
96
|
status: number;
|
|
97
|
+
/** What to answer with, as JSON. Safe to send as it is: it never holds the database's or the settings file's own words. */
|
|
97
98
|
body: {
|
|
98
99
|
ok: true;
|
|
99
100
|
action: string;
|
|
@@ -106,6 +107,8 @@ export interface ActionResult {
|
|
|
106
107
|
text: string;
|
|
107
108
|
field?: FormField;
|
|
108
109
|
};
|
|
110
|
+
/** The error behind a refusal, for the app's own log. Never send it: for store_failed and bad_config its message is the database's or the settings check's. */
|
|
111
|
+
cause?: BookingsError;
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
114
|
* The customer's posts, on the booking page: `book` (service, start, name,
|
package/dist/ui.js
CHANGED
|
@@ -120,6 +120,8 @@ export function renderMyBookings(bookings, o) {
|
|
|
120
120
|
};
|
|
121
121
|
return `<section class="wb-booking-mine">${head}<ul class="wb-booking-items">${bookings.map(item).join("")}</ul>${book}</section>`;
|
|
122
122
|
}
|
|
123
|
+
/** Failures whose message is the database's or the settings check's own words: for the app's log, never for the page. */
|
|
124
|
+
const INTERNAL = new Set(["store_failed", "bad_config"]);
|
|
123
125
|
const STATUS = {
|
|
124
126
|
bad_config: 500,
|
|
125
127
|
bad_input: 400,
|
|
@@ -144,7 +146,8 @@ function failed(e, o) {
|
|
|
144
146
|
: e.code === "too_many"
|
|
145
147
|
? say("error.too_many", { max: o.max ?? 3 })
|
|
146
148
|
: say("error.failed");
|
|
147
|
-
|
|
149
|
+
const message = INTERNAL.has(e.code) ? "bookings: it failed on the app's side (the detail is in ActionResult.cause, for the log)" : e.message;
|
|
150
|
+
return { status: STATUS[e.code], body: { ok: false, error: e.code, message, text, ...(field ? { field } : {}) }, cause: e };
|
|
148
151
|
}
|
|
149
152
|
const str = (v) => (typeof v === "string" ? v : "");
|
|
150
153
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-bookings",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A bookings calendar for Workbench apps: customers pick a free time, book it with their name and email, and get a confirmation email with a calendar file, reminders before it starts and a private link to change or cancel. The owner gets an email for each booking, a list in the app and a calendar feed. Stored in the app's own database, with tick() from the app's cron for reminders. No AI.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|