@trypattern/sdk 0.1.20 → 0.1.21
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.
|
@@ -10,6 +10,7 @@ export type AuthService = {
|
|
|
10
10
|
export type OwnerNote = {
|
|
11
11
|
subject: string;
|
|
12
12
|
text: string;
|
|
13
|
+
replyTo?: string;
|
|
13
14
|
};
|
|
14
15
|
export declare function authServiceFor(env: ServerBindings): AuthService | undefined;
|
|
15
16
|
export declare function notifyOwner(env: ServerBindings, note: OwnerNote): Promise<boolean>;
|
|
@@ -3,10 +3,11 @@ import type { BookingRequest } from '../bookings.ts';
|
|
|
3
3
|
import type { ServerBlock, ServerEnv } from './env.ts';
|
|
4
4
|
export type BookingsOptions = {
|
|
5
5
|
timezone: string;
|
|
6
|
+
managePath?: string;
|
|
6
7
|
};
|
|
7
8
|
export type BookingEmail = {
|
|
8
9
|
kind: 'requested' | 'accepted' | 'declined';
|
|
9
10
|
request: BookingRequest;
|
|
10
11
|
};
|
|
11
12
|
export declare function sendBookingEmail(c: Context<ServerEnv>, email: BookingEmail): Promise<void>;
|
|
12
|
-
export declare function bookings({ timezone }: BookingsOptions): ServerBlock;
|
|
13
|
+
export declare function bookings({ timezone, managePath }: BookingsOptions): ServerBlock;
|
package/dist/server/bookings.js
CHANGED
|
@@ -10,9 +10,22 @@ export async function sendBookingEmail(c, email) {
|
|
|
10
10
|
const to = email.kind === 'requested' ? 'the owner' : email.request.email;
|
|
11
11
|
console.log(`Booking email (${email.kind}) to ${to} from ${new URL(c.req.url).host}: ${email.request.name}, ${email.request.date} ${email.request.window}`);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function clockOf(time) {
|
|
14
|
+
const [hours = 0, minutes = 0] = time.split(':').map(Number);
|
|
15
|
+
const hour = hours % 12 === 0 ? 12 : hours % 12;
|
|
16
|
+
const suffix = hours < 12 ? 'am' : 'pm';
|
|
17
|
+
return minutes === 0
|
|
18
|
+
? `${hour}${suffix}`
|
|
19
|
+
: `${hour}:${String(minutes).padStart(2, '0')}${suffix}`;
|
|
20
|
+
}
|
|
21
|
+
function whenOf(request, label) {
|
|
22
|
+
const day = new Date(`${request.date}T12:00:00Z`).toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', timeZone: 'UTC' });
|
|
23
|
+
const [start = '', end = ''] = request.window.split('-');
|
|
24
|
+
return `${day}, ${label} (${clockOf(start)}–${clockOf(end)})`;
|
|
25
|
+
}
|
|
26
|
+
function ownerNoteOf(request, label, manage) {
|
|
14
27
|
const lines = [
|
|
15
|
-
`${request.name} asked to book ${request.offering} on ${request
|
|
28
|
+
`${request.name} asked to book ${request.offering} on ${whenOf(request, label)}.`,
|
|
16
29
|
'',
|
|
17
30
|
`Email: ${request.email}`,
|
|
18
31
|
...(request.phone === '' ? [] : [`Phone: ${request.phone}`]),
|
|
@@ -20,12 +33,14 @@ function ownerNoteOf(request) {
|
|
|
20
33
|
...(request.notes === '' ? [] : ['', request.notes]),
|
|
21
34
|
'',
|
|
22
35
|
request.status === 'accepted'
|
|
23
|
-
?
|
|
24
|
-
:
|
|
36
|
+
? `It is booked: your booking rules accept requests on their own. See it at ${manage}`
|
|
37
|
+
: `Accept or decline it at ${manage}`,
|
|
38
|
+
`Reply to this email to write to ${request.name}.`
|
|
25
39
|
];
|
|
26
40
|
return {
|
|
27
41
|
subject: `New booking request from ${request.name}`,
|
|
28
|
-
text: lines.join('\n')
|
|
42
|
+
text: lines.join('\n'),
|
|
43
|
+
replyTo: request.email
|
|
29
44
|
};
|
|
30
45
|
}
|
|
31
46
|
function requireAdmin(c) {
|
|
@@ -84,7 +99,7 @@ async function decide(c, id, status) {
|
|
|
84
99
|
function monthRange(month) {
|
|
85
100
|
return { first: `${month}-01`, last: `${month}-31` };
|
|
86
101
|
}
|
|
87
|
-
export function bookings({ timezone }) {
|
|
102
|
+
export function bookings({ timezone, managePath = '/' }) {
|
|
88
103
|
if (!isValidTimezone(timezone)) {
|
|
89
104
|
throw new Error(`bookings({ timezone: '${timezone}' }) is not a time zone: use an IANA name such as 'America/Toronto'`);
|
|
90
105
|
}
|
|
@@ -116,7 +131,7 @@ export function bookings({ timezone }) {
|
|
|
116
131
|
const saved = await readRequest(c.env.DB, id);
|
|
117
132
|
if (saved === undefined)
|
|
118
133
|
throw new Error('The request was not saved');
|
|
119
|
-
await notifyOwner(c.env, ownerNoteOf(saved));
|
|
134
|
+
await notifyOwner(c.env, ownerNoteOf(saved, slot.label, new URL(managePath, c.req.url).href));
|
|
120
135
|
await sendBookingEmail(c, {
|
|
121
136
|
kind: status === 'accepted' ? 'accepted' : 'requested',
|
|
122
137
|
request: saved
|