@ordinatio/scheduling-api 0.3.1 → 0.4.1
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 +52 -0
- package/README.md +19 -0
- package/dist/agent/index.d.mts +55 -0
- package/dist/agent/index.d.ts +55 -0
- package/dist/agent/index.js +1070 -0
- package/dist/agent/index.mjs +1040 -0
- package/dist/{chunk-P6OR2DKC.mjs → chunk-WZ5KO7IW.mjs} +2 -2
- package/dist/index.d.mts +4 -385
- package/dist/index.d.ts +4 -385
- package/dist/index.js +83 -16
- package/dist/index.mjs +84 -17
- package/dist/routes-CM-ezlv2.d.mts +386 -0
- package/dist/routes-CM-ezlv2.d.ts +386 -0
- package/dist/schemas/index.js +2 -2
- package/dist/schemas/index.mjs +1 -1
- package/package.json +12 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,391 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as SchedulingHost, R as Route, H as HttpMethod, a as RateLimitTier, b as SchedulingCache, P as PublicBookingResolver, c as PublicOrganizationResolver, A as AvailabilityCache, B as BalancePaymentControl, d as StaffResolver, e as StaffContext } from './routes-CM-ezlv2.js';
|
|
2
|
+
export { f as ActivityEntry, g as ActivityLog, h as AppointmentEventSink, i as BookingClientResolver, j as BookingPolicy, k as BrandSettings, C as CacheOptions, l as CalendarConnectOutcome, m as CalendarConnector, n as CalendarConnectors, o as CalendarVisibility, I as InternalAccess, N as NoShowPolicy, p as PrivacySettings, q as PublicBookingContext, r as PublicBookingKind, s as PublicOrganization, t as ResolvedHost, u as RouteContext, v as RouteHandler, w as RoutingFormSettings, x as StaffDirectory, W as WaitlistSettings, y as WebhookSettings, z as WorkerCommands } from './routes-CM-ezlv2.js';
|
|
3
|
+
import { SchedulingDb, PaymentAdapter, AppointmentStatus, CalendarSyncAdapter, CalendarEventRef, CalendarEvent } from '@ordinatio/scheduling';
|
|
2
4
|
export { BookingPageConfig, BookingPageConfigSchema, BookingPageTheme, BookingPageThemeSchema, BrandSchema, CancelRecurringScopeSchema, CancelRecurringSeriesInput, CancelRecurringSeriesSchema, CreateAppointmentCategoryInput, CreateAppointmentCategorySchema, CreateAppointmentTypeInput, CreateAppointmentTypeSchema, CreateAvailabilityRuleInput, CreateAvailabilityRuleSchema, CreateCalendarInput, CreateCalendarSchema, CreateCouponCodeInput, CreateCouponCodeSchema, CreateNotificationTemplateInput, CreateNotificationTemplateSchema, CreatePackagePurchaseInput, CreatePackagePurchaseSchema, CreateRecurringSeriesInput, CreateRecurringSeriesSchema, CreateRoutingFormInput, CreateRoutingFormSchema, CreateServicePackageInput, CreateServicePackageSchema, CreateWebhookEndpointInput, CreateWebhookEndpointSchema, DEFAULT_CANCELLATION_POLICY, IntakeFormFieldSchema, NoShowPrevention, NoShowPreventionAction, NoShowPreventionActionSchema, NotificationChannelSchema, NotificationTriggerSchema, OrgCancellationPolicy, OrgCancellationPolicySchema, PrivacyEraseSchema, PrivacySubjectSchema, RecurringFrequencySchema, RouteClientSchema, SLOT_GRANULARITY_DEFAULT, SLOT_GRANULARITY_OPTIONS, SlotGranularityMinutes, TestRoutingFormSchema, UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, UpdateBookingPageInput, UpdateBookingPageSchema, UpdateCalendarInput, UpdateCalendarSchema, UpdateCouponCodeInput, UpdateCouponCodeSchema, UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, UpdateRoutingFormInput, UpdateRoutingFormSchema, UpdateServicePackageInput, UpdateServicePackageSchema } from './schemas/index.js';
|
|
3
5
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
6
|
import 'zod';
|
|
5
7
|
|
|
6
|
-
/** Named limits. A host that counts requests maps each name to its own numbers. */
|
|
7
|
-
type RateLimitTier = 'PUBLIC_BOOKING' | 'AVAILABILITY' | 'GENERAL' | 'CREATE' | 'UPDATE' | 'DELETE' | 'PAYMENT_INTENT' | 'RESOLVE_REFUND' | 'INTERNAL' | 'SETTINGS';
|
|
8
|
-
/** What a public booking page is looked up by: a calendar slug or an appointment type slug. */
|
|
9
|
-
type PublicBookingKind = 'CALENDAR' | 'APPOINTMENT_TYPE';
|
|
10
|
-
/** The organization a public request belongs to, and the database that holds its data. */
|
|
11
|
-
interface PublicBookingContext {
|
|
12
|
-
db: SchedulingDb;
|
|
13
|
-
organizationId: string;
|
|
14
|
-
}
|
|
15
|
-
interface PublicBookingResolver {
|
|
16
|
-
/**
|
|
17
|
-
* Finds the organization and database for a public booking page. `orgSlug` is the organization named in
|
|
18
|
-
* the page address, or null for an older address that names only the calendar or type. Returns null when
|
|
19
|
-
* there is no such page. A host with several organizations supplies this; the default assumes one.
|
|
20
|
-
*/
|
|
21
|
-
resolve(input: {
|
|
22
|
-
orgSlug: string | null;
|
|
23
|
-
slug: string;
|
|
24
|
-
kind: PublicBookingKind;
|
|
25
|
-
logPrefix: string;
|
|
26
|
-
}): Promise<PublicBookingContext | null>;
|
|
27
|
-
}
|
|
28
|
-
/** The organization a request names by its slug, and the database that holds its data. */
|
|
29
|
-
interface PublicOrganization {
|
|
30
|
-
db: SchedulingDb;
|
|
31
|
-
/** The organization id every read must be scoped by, or null when the host has one organization and nothing to scope. */
|
|
32
|
-
organizationId: string | null;
|
|
33
|
-
}
|
|
34
|
-
interface PublicOrganizationResolver {
|
|
35
|
-
/**
|
|
36
|
-
* Finds the organization named by `orgSlug`, for routes that are keyed by an id and not by a slug. Returns null
|
|
37
|
-
* when there is no such active organization. A host with several organizations supplies this; the default
|
|
38
|
-
* assumes one, so it returns the public database with no organization id and the reads are not scoped.
|
|
39
|
-
*/
|
|
40
|
-
resolve(input: {
|
|
41
|
-
orgSlug: string;
|
|
42
|
-
logPrefix: string;
|
|
43
|
-
}): Promise<PublicOrganization | null>;
|
|
44
|
-
}
|
|
45
|
-
/** Stored free-slot answers, one per calendar, day and duration. */
|
|
46
|
-
interface AvailabilityCache {
|
|
47
|
-
/** The stored answer, or null when there is none or it has expired. A rejection is treated as a miss. */
|
|
48
|
-
get(calendarId: string, day: string, duration: number): Promise<unknown | null>;
|
|
49
|
-
set(calendarId: string, day: string, duration: number, value: unknown): Promise<void>;
|
|
50
|
-
/** Drops every stored answer of the calendar. Called when a booking changes its free slots. */
|
|
51
|
-
invalidate(calendarId: string): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Tells the screens of an organization that an appointment changed, for example `appointment.cancelled`. It runs
|
|
55
|
-
* after the change is saved and must not throw: a rejection ends the request with a 500 although the change stands,
|
|
56
|
-
* and the steps after it are skipped.
|
|
57
|
-
*/
|
|
58
|
-
interface AppointmentEventSink {
|
|
59
|
-
emit(organizationId: string, type: string, data: Record<string, unknown>): Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
interface ActivityEntry {
|
|
62
|
-
action: string;
|
|
63
|
-
description: string;
|
|
64
|
-
metadata?: Record<string, unknown>;
|
|
65
|
-
/** A key that lets a later step find this entry again. */
|
|
66
|
-
externalRef?: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Writes entries to the activity feed that staff read. A self-service cancellation of a paid appointment tells staff
|
|
70
|
-
* to review the refund only through the entry `scheduling.appointment_refund_pending`, so a host that supplies no log
|
|
71
|
-
* sends no alert. It runs after the change is saved and must not throw: a rejection ends the request with a 500
|
|
72
|
-
* although the change stands, and the steps after it are skipped.
|
|
73
|
-
*/
|
|
74
|
-
interface ActivityLog {
|
|
75
|
-
log(db: SchedulingDb, entry: ActivityEntry): Promise<void>;
|
|
76
|
-
/** Whether an entry with this `externalRef` exists and has not been resolved. */
|
|
77
|
-
isOpen(db: SchedulingDb, externalRef: string): Promise<boolean>;
|
|
78
|
-
/** Marks the entry with this `externalRef` resolved by the person. Does nothing when there is none. */
|
|
79
|
-
resolve(db: SchedulingDb, externalRef: string, resolvedBy: string): Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
/** A filter on the calendar of an appointment, narrowing a list to the calendars a person may see. */
|
|
82
|
-
type CalendarVisibility = NonNullable<NonNullable<NonNullable<Parameters<SchedulingDb['appointment']['count']>[0]>['where']>['calendar']>;
|
|
83
|
-
/** What the balance flow needs from the payment provider beyond creating a payment. */
|
|
84
|
-
interface BalancePaymentControl {
|
|
85
|
-
/** Cancels an unpaid payment. Rejects when the provider refuses, for example because it is already paid or canceled. */
|
|
86
|
-
cancel(paymentId: string): Promise<void>;
|
|
87
|
-
/** The provider's own status word for the payment, such as "canceled" or "succeeded". Rejects when it cannot be read. */
|
|
88
|
-
statusOf(paymentId: string): Promise<string>;
|
|
89
|
-
}
|
|
90
|
-
/** A signed-in member of the organization, as the host knows them. */
|
|
91
|
-
interface StaffContext {
|
|
92
|
-
userId: string;
|
|
93
|
-
organizationId: string;
|
|
94
|
-
/** The person's role. It is only written into the error record of a refusal. */
|
|
95
|
-
role: string;
|
|
96
|
-
/** True when the role may manage scheduling for the whole organization (owner, admin, manager) and not only look up one client. */
|
|
97
|
-
isAdmin: boolean;
|
|
98
|
-
/** False when the organization has scheduling switched off; admin routes then answer 503. */
|
|
99
|
-
schedulingEnabled: boolean;
|
|
100
|
-
/** The database of the organization. */
|
|
101
|
-
db: SchedulingDb;
|
|
102
|
-
/** The calendars this person may see, or null when they may see them all. Asked only after the role check. */
|
|
103
|
-
visibleCalendars(): Promise<CalendarVisibility | null>;
|
|
104
|
-
/**
|
|
105
|
-
* The ids of the calendars this person may see, or undefined when they may see them all. Reports and group-session
|
|
106
|
-
* lists narrow to these ids, where `visibleCalendars` gives a filter for queries on appointments.
|
|
107
|
-
*/
|
|
108
|
-
visibleCalendarIds(): Promise<string[] | undefined>;
|
|
109
|
-
/** Whether this person may see one calendar. False also for a calendar that does not exist, so a hidden one looks missing. */
|
|
110
|
-
canSeeCalendar(calendarId: string): Promise<boolean>;
|
|
111
|
-
/** Whether this person may see one appointment, by the group visibility of its calendar. False also when it does not exist. */
|
|
112
|
-
canSeeAppointment(appointmentId: string): Promise<boolean>;
|
|
113
|
-
/**
|
|
114
|
-
* The place a client prefers to be seen at, or null when the client does not exist, has no preference, or is one
|
|
115
|
-
* this person may not see. A client outside the person's groups looks the same as a missing one.
|
|
116
|
-
*/
|
|
117
|
-
preferredLocationOf(clientId: string): Promise<string | null>;
|
|
118
|
-
}
|
|
119
|
-
interface StaffResolver {
|
|
120
|
-
/**
|
|
121
|
-
* The signed-in member who sent the request, or null when nobody is signed in (the route then answers 401).
|
|
122
|
-
* It may throw, for example when the person belongs to no organization; the route then answers 500.
|
|
123
|
-
*/
|
|
124
|
-
resolve(request: Request): Promise<StaffContext | null>;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Decides which client record a new booking belongs to. The booking endpoint is public, so `suppliedClientId` is
|
|
128
|
-
* untrusted: honor it only for a signed-in member of the organization who may see that client. It must not throw: a
|
|
129
|
-
* failure means the appointment is saved unlinked and can be linked later.
|
|
130
|
-
*/
|
|
131
|
-
interface BookingClientResolver {
|
|
132
|
-
resolve(request: Request, db: SchedulingDb, input: {
|
|
133
|
-
organizationId: string;
|
|
134
|
-
email: string;
|
|
135
|
-
suppliedClientId?: string;
|
|
136
|
-
}): Promise<string | null>;
|
|
137
|
-
/** Remembers the place a client prefers to be seen at. It may throw: the caller logs the failure and carries on. */
|
|
138
|
-
rememberLocation(db: SchedulingDb, clientId: string, location: string): Promise<void>;
|
|
139
|
-
}
|
|
140
|
-
/** What an organization does about a client who keeps missing appointments. */
|
|
141
|
-
interface NoShowPolicy {
|
|
142
|
-
enabled: boolean;
|
|
143
|
-
/** How many missed appointments trigger the action. */
|
|
144
|
-
threshold: number;
|
|
145
|
-
/** BLOCK_BOOKING refuses online booking; REQUIRE_APPROVAL books it as PENDING for staff to review. */
|
|
146
|
-
action: 'BLOCK_BOOKING' | 'REQUIRE_APPROVAL';
|
|
147
|
-
}
|
|
148
|
-
interface BookingPolicy {
|
|
149
|
-
/** The no-show policy of the organization, or null when it has none. */
|
|
150
|
-
noShowPrevention(organizationId: string): Promise<NoShowPolicy | null>;
|
|
151
|
-
}
|
|
152
|
-
/** Who works in the organization, for the staff picker on the calendar settings page. */
|
|
153
|
-
interface StaffDirectory {
|
|
154
|
-
/** Active members of the organization. Departed or deactivated accounts are left out so they cannot be newly linked. */
|
|
155
|
-
listActive(organizationId: string): Promise<Array<{
|
|
156
|
-
id: string;
|
|
157
|
-
name: string | null;
|
|
158
|
-
email: string;
|
|
159
|
-
}>>;
|
|
160
|
-
/** Whether the user is a member of the organization. Used before a calendar is linked to a staff member. */
|
|
161
|
-
isMember(organizationId: string, userId: string): Promise<boolean>;
|
|
162
|
-
}
|
|
163
|
-
/** A public booking page is reached by a bare slug. This index says which organization owns each slug. */
|
|
164
|
-
interface SlugDirectory {
|
|
165
|
-
/** Reserves `slug` for the organization. First claim wins. Never throws: a conflict or failure is `claimed: false` with a `ref`. */
|
|
166
|
-
claim(slug: string, kind: 'CALENDAR' | 'APPOINTMENT_TYPE', organizationId: string): Promise<{
|
|
167
|
-
claimed: boolean;
|
|
168
|
-
ref?: string;
|
|
169
|
-
}>;
|
|
170
|
-
/** Frees the slug if this organization holds it. Never throws. */
|
|
171
|
-
release(slug: string, kind: 'CALENDAR' | 'APPOINTMENT_TYPE', organizationId: string): Promise<void>;
|
|
172
|
-
}
|
|
173
|
-
interface CacheOptions {
|
|
174
|
-
/** Names the stored answer. It always contains the organization id, so two organizations never share one. */
|
|
175
|
-
key: string;
|
|
176
|
-
/** Names to drop the answer by when its data changes. */
|
|
177
|
-
tags: string[];
|
|
178
|
-
ttlSeconds: number;
|
|
179
|
-
}
|
|
180
|
-
interface SchedulingCache {
|
|
181
|
-
/** Returns the stored answer for `options.key`, or calls `load`, stores what it returns, and returns that. */
|
|
182
|
-
wrap<T>(options: CacheOptions, load: () => Promise<T>): Promise<T>;
|
|
183
|
-
/** Drops every stored answer that carries one of the tags. */
|
|
184
|
-
invalidate(tags: string[]): Promise<void>;
|
|
185
|
-
}
|
|
186
|
-
/** Decides whether a request comes from the host's own background worker and not from a person or the public. */
|
|
187
|
-
interface InternalAccess {
|
|
188
|
-
/** True only for a request that carries the worker's credential. Must be false when no credential is configured. */
|
|
189
|
-
isAuthorized(request: Request): boolean | Promise<boolean>;
|
|
190
|
-
}
|
|
191
|
-
/** Hands a command to the host's background worker, for example to remove an event from an outside calendar. */
|
|
192
|
-
interface WorkerCommands {
|
|
193
|
-
queue(action: string, data: Record<string, unknown>): Promise<void>;
|
|
194
|
-
}
|
|
195
|
-
/** What a provider's side of a calendar connection ended in. */
|
|
196
|
-
type CalendarConnectOutcome =
|
|
197
|
-
/** The connection failed; the person is sent back to the settings page with `?error=<failure>`. */
|
|
198
|
-
{
|
|
199
|
-
failure: string;
|
|
200
|
-
}
|
|
201
|
-
/** The fields to write on the connected calendar, or null when there is nothing to write. */
|
|
202
|
-
| {
|
|
203
|
-
link: Record<string, unknown> | null;
|
|
204
|
-
};
|
|
205
|
-
/** One outside calendar provider (Google, Outlook): where to send the person and what to do with the code they come back with. */
|
|
206
|
-
interface CalendarConnector {
|
|
207
|
-
/** The provider's sign-in address. `state` must be carried through unchanged. */
|
|
208
|
-
authorizationUrl(state: string): string;
|
|
209
|
-
/**
|
|
210
|
-
* Exchanges the code the provider sent back. It runs before the calendar being connected is known, so it may save
|
|
211
|
-
* account tokens of its own but must not touch the scheduling calendar. A rejection ends the connection with the
|
|
212
|
-
* provider's generic failure.
|
|
213
|
-
*/
|
|
214
|
-
exchange(code: string): Promise<CalendarConnectOutcome>;
|
|
215
|
-
}
|
|
216
|
-
interface CalendarConnectors {
|
|
217
|
-
google: CalendarConnector;
|
|
218
|
-
outlook: CalendarConnector;
|
|
219
|
-
}
|
|
220
|
-
/** Switches outbound webhooks on. A host that supplies none has them off: the routes answer 501 and nothing is queued. */
|
|
221
|
-
interface WebhookSettings {
|
|
222
|
-
/** Allows http addresses and addresses on a private network. For local development and tests only. Default: no. */
|
|
223
|
-
allowInsecureTargets?: boolean;
|
|
224
|
-
/** Sends one request. Default: Node's own http client, which refuses names that resolve to private addresses. */
|
|
225
|
-
transport?: WebhookTransport;
|
|
226
|
-
}
|
|
227
|
-
/** What the host does with a waitlist offer. Switching the waitlist on is what supplies this object. */
|
|
228
|
-
interface WaitlistSettings {
|
|
229
|
-
/** How long an offer lasts, in minutes, and never past the start of the slot. Default 30. */
|
|
230
|
-
offerMinutes?: number;
|
|
231
|
-
/**
|
|
232
|
-
* Tells the client that a slot is theirs to take: send `token` in a link to the page that calls
|
|
233
|
-
* `GET /waitlist/offer` and `POST /waitlist/offer/accept`. It runs inside the request that cancelled the booking, so it
|
|
234
|
-
* should only queue the message, not wait for it to be delivered. It must not throw; a rejection is logged and the offer
|
|
235
|
-
* stays open until it expires. Without it, only the `waitlist.offered` webhook announces the offer.
|
|
236
|
-
*/
|
|
237
|
-
notify?(offer: {
|
|
238
|
-
organizationId: string;
|
|
239
|
-
token: string;
|
|
240
|
-
clientName: string;
|
|
241
|
-
clientEmail: string;
|
|
242
|
-
clientPhone: string | null;
|
|
243
|
-
typeName: string;
|
|
244
|
-
calendarName: string;
|
|
245
|
-
startTime: Date;
|
|
246
|
-
timezone: string;
|
|
247
|
-
expiresAt: Date;
|
|
248
|
-
}): Promise<void>;
|
|
249
|
-
}
|
|
250
|
-
/** Switches routing forms on. A host that supplies none has them off: the routes answer 501. */
|
|
251
|
-
type RoutingFormSettings = Record<string, never>;
|
|
252
|
-
/**
|
|
253
|
-
* Switches organization branding on: a name, logo and colours for the booking page and messages, and a sender identity.
|
|
254
|
-
* A host that supplies none has it off: the routes answer 501 and no message carries a brand.
|
|
255
|
-
*/
|
|
256
|
-
interface BrandSettings {
|
|
257
|
-
/**
|
|
258
|
-
* Says whether the host may send mail from `domain` (lower case, such as "mail.acme.com"), usually because it has been
|
|
259
|
-
* verified with the mail provider. Without it no organization can set a sending address; it can still set a reply-to.
|
|
260
|
-
* A rejection counts as "no".
|
|
261
|
-
*/
|
|
262
|
-
isSendingDomainVerified?(domain: string, organizationId: string): boolean | Promise<boolean>;
|
|
263
|
-
}
|
|
264
|
-
/** Switches data export and erasure on. A host that supplies none has them off: the routes answer 501. */
|
|
265
|
-
type PrivacySettings = Record<string, never>;
|
|
266
|
-
interface SchedulingHost {
|
|
267
|
-
/**
|
|
268
|
-
* The database for routes that have no signed-in user. Such a route reads the system database before it knows
|
|
269
|
-
* which organization the request belongs to, for example to find the organization of a calendar by its id.
|
|
270
|
-
*/
|
|
271
|
-
publicDb(): Promise<SchedulingDb>;
|
|
272
|
-
/** Finds the organization and database of a public booking page. Default: one organization in `publicDb()`. */
|
|
273
|
-
publicBooking?: PublicBookingResolver;
|
|
274
|
-
/** The web address of the host, such as https://system.example.com, used in links inside files it hands out. Default: none. */
|
|
275
|
-
appUrl?(): string | null | undefined;
|
|
276
|
-
/** The business name used in messages when a calendar has no staff name. Default: none. */
|
|
277
|
-
appName?(): string | null | undefined;
|
|
278
|
-
/** Whether scheduling is switched on for an organization, asked by public routes that know only the organization id. Default: yes. */
|
|
279
|
-
schedulingEnabledFor?(organizationId: string): Promise<boolean>;
|
|
280
|
-
/** Whether booking analytics is switched on for this installation. Default: on. */
|
|
281
|
-
bookingAnalyticsEnabled?(): boolean;
|
|
282
|
-
/** Whether the payment provider can charge in this currency (lower case, such as "usd"). Default: any currency. */
|
|
283
|
-
canChargeCurrency?(currency: string): boolean;
|
|
284
|
-
/**
|
|
285
|
-
* The database of one organization, for routes that find the organization only after reading a row, such as a
|
|
286
|
-
* manage-link token. Returns null when it cannot be reached. Default: `publicDb()`, for one organization.
|
|
287
|
-
*/
|
|
288
|
-
tenantDb?(organizationId: string, logPrefix: string): Promise<SchedulingDb | null>;
|
|
289
|
-
/** Announces appointment changes to connected screens. Default: nothing is announced. */
|
|
290
|
-
events?: AppointmentEventSink;
|
|
291
|
-
/**
|
|
292
|
-
* Keeps an outside calendar in step with an appointment. Failures are caught and reported through the activity
|
|
293
|
-
* log, never thrown. Default: nothing is synced.
|
|
294
|
-
*/
|
|
295
|
-
calendarSync?: CalendarSyncAdapter;
|
|
296
|
-
/**
|
|
297
|
-
* Turns on outbound webhooks: booking changes are queued for the organization's endpoints, and the admin routes
|
|
298
|
-
* work. Queued deliveries are sent by `deliverDueWebhooks` (or `POST /internal/webhooks/deliver`), which the host
|
|
299
|
-
* runs on a timer. Needs the webhook tables. Default: off.
|
|
300
|
-
*/
|
|
301
|
-
webhooks?: WebhookSettings | null;
|
|
302
|
-
/**
|
|
303
|
-
* Turns on the waitlist: clients can wait for a full slot or day, and a cancelled or moved booking offers its slot
|
|
304
|
-
* to the first person in line. Needs the waitlist table. Default: off, so the routes answer 501.
|
|
305
|
-
*/
|
|
306
|
-
waitlist?: WaitlistSettings | null;
|
|
307
|
-
/**
|
|
308
|
-
* Turns on routing forms: an admin defines questions and rules, and a public route sends a client to the right
|
|
309
|
-
* appointment type or calendar. Needs the routing form table. Default: off, so the routes answer 501.
|
|
310
|
-
*/
|
|
311
|
-
routingForms?: RoutingFormSettings | null;
|
|
312
|
-
/**
|
|
313
|
-
* Turns on exporting and erasing one person's data (admin only, every request recorded). Needs the data request table.
|
|
314
|
-
* Default: off, so the routes answer 501.
|
|
315
|
-
*/
|
|
316
|
-
privacy?: PrivacySettings | null;
|
|
317
|
-
/**
|
|
318
|
-
* Turns on organization branding. Needs the brand table. Messages carry the brand only if the host's message sender
|
|
319
|
-
* also asks for it (see `processPendingNotifications`' `brand` option). Default: off, so the routes answer 501.
|
|
320
|
-
*/
|
|
321
|
-
brand?: BrandSettings | null;
|
|
322
|
-
/** The domain used after the "@" in calendar-file event ids. Keep it unchanged once calendars have subscribed. Default: ordinatio-scheduling. */
|
|
323
|
-
icalUidDomain?(): string | null | undefined;
|
|
324
|
-
/** Records what happened in the activity feed. Default: nothing is recorded. */
|
|
325
|
-
activity?: ActivityLog;
|
|
326
|
-
/** Finds the organization named by an `orgSlug` query value. Default: one organization, nothing scoped. */
|
|
327
|
-
organizations?: PublicOrganizationResolver;
|
|
328
|
-
/** Stores free-slot answers for a minute. Default: in this process's memory. */
|
|
329
|
-
availabilityCache?: AvailabilityCache;
|
|
330
|
-
/** Stores answers that rarely change. Default: in this process's memory. */
|
|
331
|
-
cache?: SchedulingCache;
|
|
332
|
-
/**
|
|
333
|
-
* Counts one request against `key`. Returns null to let the request through, or the response to send
|
|
334
|
-
* (normally a 429). Default: an in-memory counter, which counts per process only.
|
|
335
|
-
*/
|
|
336
|
-
rateLimit?(key: string, tier: RateLimitTier): Promise<Response | null>;
|
|
337
|
-
/** Finds the signed-in member of a request, for routes only staff may call. Default: nobody is signed in, so those routes answer 401. */
|
|
338
|
-
staff?: StaffResolver;
|
|
339
|
-
/** Lists the staff of an organization. Default: nobody, so the staff picker is empty. */
|
|
340
|
-
staffDirectory?: StaffDirectory;
|
|
341
|
-
/** Bare-slug booking links across organizations. Default: none, so every claim succeeds and nothing is recorded. */
|
|
342
|
-
slugDirectory?: SlugDirectory;
|
|
343
|
-
/** Finds the client record of a new booking. Default: none, so every booking is saved unlinked. */
|
|
344
|
-
clients?: BookingClientResolver;
|
|
345
|
-
/** Per-organization booking rules. Default: none, so nobody is ever held back for missed appointments. */
|
|
346
|
-
bookingPolicy?: BookingPolicy;
|
|
347
|
-
/**
|
|
348
|
-
* Charges, checks and refunds payments. Default: none. A booking for a type that requires payment is then
|
|
349
|
-
* refused, because no payment can be verified.
|
|
350
|
-
*/
|
|
351
|
-
payments?: PaymentAdapter;
|
|
352
|
-
/**
|
|
353
|
-
* Cancels a payment that was created and then lost a race, and reads its current state. Default: none, so a
|
|
354
|
-
* payment that must be cancelled is reported as still live and staff are told to cancel it by hand.
|
|
355
|
-
*/
|
|
356
|
-
balancePayments?: BalancePaymentControl;
|
|
357
|
-
/** Who counts as the background worker, for routes only it may call. Default: nobody, so those routes answer 401. */
|
|
358
|
-
internalAccess?: InternalAccess;
|
|
359
|
-
/** Commands for the background worker. Default: they are dropped. */
|
|
360
|
-
workerCommands?: WorkerCommands;
|
|
361
|
-
/** The Google and Outlook sign-in flows. Default: neither is configured, so starting a connection answers 500 and finishing one fails. */
|
|
362
|
-
calendarConnectors?: CalendarConnectors;
|
|
363
|
-
/** Whether the short-lived sign-in cookies may only travel over https. Default: yes. */
|
|
364
|
-
secureCookies?(): boolean;
|
|
365
|
-
/** The value that clears a JSON column. Default: null. A Prisma host returns `Prisma.DbNull`, because Prisma refuses a plain null there. */
|
|
366
|
-
jsonNull?(): unknown;
|
|
367
|
-
/** CORS headers for answers to the booking widget, which runs on other websites. Default: any origin, no cookies. */
|
|
368
|
-
cors?(request?: Request): Record<string, string>;
|
|
369
|
-
}
|
|
370
|
-
/** The host with every default filled in. Handlers receive this. */
|
|
371
|
-
type ResolvedHost = Required<SchedulingHost>;
|
|
372
|
-
|
|
373
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
374
|
-
interface RouteContext {
|
|
375
|
-
host: ResolvedHost;
|
|
376
|
-
/** Values of the `[name]` segments in the route path. */
|
|
377
|
-
params: Record<string, string>;
|
|
378
|
-
}
|
|
379
|
-
type RouteHandler = (request: Request, context: RouteContext) => Promise<Response> | Response;
|
|
380
|
-
interface Route {
|
|
381
|
-
method: HttpMethod;
|
|
382
|
-
/** Relative to the base path. A `[name]` segment matches any one segment. */
|
|
383
|
-
path: string;
|
|
384
|
-
/** A public route is called from other websites, so it also answers a CORS preflight. */
|
|
385
|
-
public: boolean;
|
|
386
|
-
handler: RouteHandler;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
8
|
interface SchedulingApiConfig {
|
|
390
9
|
host: SchedulingHost;
|
|
391
10
|
/** Where the API is mounted. Default: /api/scheduling. */
|
|
@@ -669,4 +288,4 @@ declare function createNodeListener(api: {
|
|
|
669
288
|
handle(request: Request): Promise<Response>;
|
|
670
289
|
}, options: NodeListenerOptions): (incoming: IncomingMessage, outgoing: ServerResponse) => void;
|
|
671
290
|
|
|
672
|
-
export { ALL_REFUND_STATUSES,
|
|
291
|
+
export { ALL_REFUND_STATUSES, AvailabilityCache, BALANCE_APPOINTMENT_SELECT, BALANCE_BLOCKED_APPOINTMENT_STATUS, BALANCE_REQUIRED_PAYMENT_STATUS, BALANCE_REQUIRED_REFUND_STATUS, BalanceIntentGenerationsExhaustedError, BalancePaymentControl, BalanceRequestInProgressError, type BearerStaffResolverInput, HttpMethod, type NodeListenerOptions, type Pagination, PublicBookingResolver, PublicOrganizationResolver, RETRYABLE_REFUND_STATUSES, RateLimitTier, RefundOutcomePersistenceError, Route, type SchedulingApi, type SchedulingApiConfig, SchedulingCache, SchedulingHost, type SchedulingServiceError, type SignedInPerson, StaffContext, type StaffContextInput, StaffResolver, TERMINAL_SUCCESS_STATUSES, TOKEN_TTL_DAYS, UnverifiedPaymentError, attemptLegRefund, createBalanceIntent, createBearerStaffResolver, createMemoryAvailabilityCache, createMemoryCache, createMemoryRateLimiter, createNoBalancePaymentControl, createNoPaymentAdapter, createNodeListener, createSchedulingApi, createSingleOrganizationDirectory, createSingleOrganizationResolver, createStaffContext, decimalToCents, defaultCorsHeaders, getErrorCode, getErrorMessage, getErrorRef, isSchedulingServiceError, isTokenExpired, parsePagination, persistRefundOutcome, recordBalanceIntent, runCalendarRemoveWithoutBlocking, runCalendarSyncWithoutBlocking };
|
package/dist/index.js
CHANGED
|
@@ -3095,12 +3095,12 @@ var BookingPageConfigSchema = import_zod8.z.object({
|
|
|
3095
3095
|
title: import_zod8.z.string().max(100).optional().nullable(),
|
|
3096
3096
|
description: import_zod8.z.string().max(500).optional().nullable(),
|
|
3097
3097
|
logoUrl: import_zod8.z.string().url().max(500).refine(
|
|
3098
|
-
(v) => /^https
|
|
3098
|
+
(v) => /^https:\/\//i.test(v),
|
|
3099
3099
|
{ message: "Logo URL must use https://" }
|
|
3100
3100
|
).optional().nullable(),
|
|
3101
3101
|
confirmationMessage: import_zod8.z.string().max(500).optional().nullable(),
|
|
3102
3102
|
redirectUrl: import_zod8.z.string().url().max(500).refine(
|
|
3103
|
-
(v) => /^https
|
|
3103
|
+
(v) => /^https:\/\//i.test(v),
|
|
3104
3104
|
{ message: "Redirect URL must use https://" }
|
|
3105
3105
|
).optional().nullable(),
|
|
3106
3106
|
redirectDelay: import_zod8.z.number().int().min(0).max(30).optional().default(5),
|
|
@@ -4643,6 +4643,42 @@ We look forward to seeing you!
|
|
|
4643
4643
|
|
|
4644
4644
|
// src/handlers/calendar-ownership.ts
|
|
4645
4645
|
var import_scheduling36 = require("@ordinatio/scheduling");
|
|
4646
|
+
var SAFE_CALENDAR_FIELDS = [
|
|
4647
|
+
"id",
|
|
4648
|
+
"organizationId",
|
|
4649
|
+
"name",
|
|
4650
|
+
"slug",
|
|
4651
|
+
"type",
|
|
4652
|
+
"timezone",
|
|
4653
|
+
"isActive",
|
|
4654
|
+
"googleCalendarId",
|
|
4655
|
+
"outlookCalendarId",
|
|
4656
|
+
"syncDirection",
|
|
4657
|
+
"lastSyncAt",
|
|
4658
|
+
"staffName",
|
|
4659
|
+
"staffEmail",
|
|
4660
|
+
"staffAvatar",
|
|
4661
|
+
"userId",
|
|
4662
|
+
"theme",
|
|
4663
|
+
"bookingPageConfig",
|
|
4664
|
+
"location",
|
|
4665
|
+
"slotGranularityMinutes",
|
|
4666
|
+
"createdAt",
|
|
4667
|
+
"updatedAt"
|
|
4668
|
+
];
|
|
4669
|
+
function toCalendarAnswer(calendar) {
|
|
4670
|
+
const row = calendar;
|
|
4671
|
+
return Object.fromEntries(SAFE_CALENDAR_FIELDS.filter((key) => key in row).map((key) => [key, row[key]]));
|
|
4672
|
+
}
|
|
4673
|
+
function lastActiveCalendarResponse(error, route) {
|
|
4674
|
+
if (getErrorCode(error) !== "SCHED_103") return null;
|
|
4675
|
+
const ref = getErrorRef(error);
|
|
4676
|
+
console.error(route, ref, error);
|
|
4677
|
+
return Response.json(
|
|
4678
|
+
{ error: "Cannot archive the last active calendar. Create another calendar first.", ...ref && { ref } },
|
|
4679
|
+
{ status: 409 }
|
|
4680
|
+
);
|
|
4681
|
+
}
|
|
4646
4682
|
async function getOwnedCalendarForRoute(db, id, organizationId) {
|
|
4647
4683
|
const calendar = await db.schedulingCalendar.findUnique({
|
|
4648
4684
|
where: { id },
|
|
@@ -4718,6 +4754,19 @@ async function releaseCalendarSlugIfStillInactive(host, db, calendarId, organiza
|
|
|
4718
4754
|
}
|
|
4719
4755
|
return false;
|
|
4720
4756
|
}
|
|
4757
|
+
async function undoArchive(host, db, calendarId, organizationId, slug) {
|
|
4758
|
+
try {
|
|
4759
|
+
await (0, import_scheduling36.updateCalendar)(db, calendarId, organizationId, { isActive: true });
|
|
4760
|
+
} catch (restoreError) {
|
|
4761
|
+
console.error("[calendar update] could not switch the calendar back on after a failed update", calendarId, restoreError);
|
|
4762
|
+
try {
|
|
4763
|
+
await releaseCalendarSlugIfStillInactive(host, db, calendarId, organizationId, slug);
|
|
4764
|
+
} catch (releaseError) {
|
|
4765
|
+
console.error("[calendar update] could not free the address of an archived calendar", calendarId, releaseError);
|
|
4766
|
+
}
|
|
4767
|
+
await bustCalendarCachesOnArchive(host, organizationId, slug, calendarId);
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4721
4770
|
|
|
4722
4771
|
// src/handlers/admin-calendars.ts
|
|
4723
4772
|
var CALENDARS_DEFAULT_LIMIT = 500;
|
|
@@ -4796,7 +4845,7 @@ async function createCalendar(request, { host }) {
|
|
|
4796
4845
|
metadata: { calendarId: calendar.id, calendarName: input.name, type: input.type }
|
|
4797
4846
|
});
|
|
4798
4847
|
const claim = await host.slugDirectory.claim(calendar.slug, "CALENDAR", organizationId);
|
|
4799
|
-
return Response.json({ calendar, directoryClaimed: claim.claimed }, { status: 201 });
|
|
4848
|
+
return Response.json({ calendar: toCalendarAnswer(calendar), directoryClaimed: claim.claimed }, { status: 201 });
|
|
4800
4849
|
} catch (error) {
|
|
4801
4850
|
if (getErrorCode(error) === "P2002") {
|
|
4802
4851
|
return Response.json({ error: "A calendar with this name already exists" }, { status: 409 });
|
|
@@ -4836,19 +4885,31 @@ async function putCalendar(request, { host, params }) {
|
|
|
4836
4885
|
const input = validation.data;
|
|
4837
4886
|
const linkError = input.userId === void 0 ? null : await validateStaffLink(host, input.userId, organizationId);
|
|
4838
4887
|
if (linkError) return linkError;
|
|
4839
|
-
const
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4888
|
+
const archiving = input.isActive === false && existing.isActive;
|
|
4889
|
+
let archived = false;
|
|
4890
|
+
let updated;
|
|
4891
|
+
try {
|
|
4892
|
+
if (archiving) {
|
|
4893
|
+
await (0, import_scheduling37.archiveCalendar)(db, id, organizationId);
|
|
4894
|
+
archived = true;
|
|
4895
|
+
}
|
|
4896
|
+
({ calendar: updated } = await (0, import_scheduling37.updateCalendar)(db, id, organizationId, buildCalendarUpdateData(input)));
|
|
4897
|
+
} catch (error) {
|
|
4898
|
+
if (archived) await undoArchive(host, db, id, organizationId, existing.slug);
|
|
4899
|
+
throw error;
|
|
4843
4900
|
}
|
|
4901
|
+
if (input.slotGranularityMinutes !== void 0) await host.availabilityCache.invalidate(id);
|
|
4902
|
+
if (archiving) await releaseCalendarSlugIfStillInactive(host, db, id, organizationId, existing.slug);
|
|
4844
4903
|
await bustCalendarCachesOnUpdate(host, organizationId, existing.slug, input, id);
|
|
4845
4904
|
await host.activity.log(db, {
|
|
4846
4905
|
action: "scheduling.calendar_updated",
|
|
4847
4906
|
description: `updated calendar "${existing.name}"`,
|
|
4848
4907
|
metadata: { calendarId: id, changes: input }
|
|
4849
4908
|
});
|
|
4850
|
-
return Response.json({ calendar: updated });
|
|
4909
|
+
return Response.json({ calendar: toCalendarAnswer(updated) });
|
|
4851
4910
|
} catch (error) {
|
|
4911
|
+
const lastActive = lastActiveCalendarResponse(error, "[PUT /admin/calendars]");
|
|
4912
|
+
if (lastActive) return lastActive;
|
|
4852
4913
|
return Response.json({ error: getErrorMessage(error, "Failed to update calendar") }, { status: 500 });
|
|
4853
4914
|
}
|
|
4854
4915
|
}
|
|
@@ -4871,14 +4932,8 @@ async function deleteCalendar(request, { host, params }) {
|
|
|
4871
4932
|
});
|
|
4872
4933
|
return Response.json({ success: true });
|
|
4873
4934
|
} catch (error) {
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
console.error("[DELETE /admin/calendars]", ref, error);
|
|
4877
|
-
return Response.json(
|
|
4878
|
-
{ error: "Cannot archive the last active calendar. Create another calendar first.", ...ref && { ref } },
|
|
4879
|
-
{ status: 409 }
|
|
4880
|
-
);
|
|
4881
|
-
}
|
|
4935
|
+
const lastActive = lastActiveCalendarResponse(error, "[DELETE /admin/calendars]");
|
|
4936
|
+
if (lastActive) return lastActive;
|
|
4882
4937
|
return Response.json({ error: getErrorMessage(error, "Failed to delete calendar") }, { status: 500 });
|
|
4883
4938
|
}
|
|
4884
4939
|
}
|
|
@@ -5086,6 +5141,15 @@ async function requireOwnedVisibleCalendar(staff, calendarId) {
|
|
|
5086
5141
|
return calendar ?? NOT_FOUND8();
|
|
5087
5142
|
}
|
|
5088
5143
|
|
|
5144
|
+
// src/availability/clear-availability-cache.ts
|
|
5145
|
+
async function clearAvailabilityCache(host, calendarId) {
|
|
5146
|
+
try {
|
|
5147
|
+
await host.availabilityCache.invalidate(calendarId);
|
|
5148
|
+
} catch (error) {
|
|
5149
|
+
console.warn("[availability-cache-clear-failed]", calendarId, error);
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5089
5153
|
// src/availability/validate-weekly-rules.ts
|
|
5090
5154
|
function validateWeeklyRules(rules) {
|
|
5091
5155
|
for (const rule of rules) {
|
|
@@ -5155,6 +5219,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5155
5219
|
const validationError = validateWeeklyRules(rules);
|
|
5156
5220
|
if (validationError) return Response.json({ error: validationError }, { status: 400 });
|
|
5157
5221
|
const created = await (0, import_scheduling39.setWeeklyAvailability)(db, calendarId, rules);
|
|
5222
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5158
5223
|
const activeDays = rules.map((r) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][r.dayOfWeek]).join(", ");
|
|
5159
5224
|
await host.activity.log(db, {
|
|
5160
5225
|
action: "scheduling.availability_updated",
|
|
@@ -5229,6 +5294,7 @@ async function addOverride(request, { host, params }) {
|
|
|
5229
5294
|
endTime: body.endTime
|
|
5230
5295
|
});
|
|
5231
5296
|
}
|
|
5297
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5232
5298
|
let overlapWarning;
|
|
5233
5299
|
if (isBlockedFlag && body.startTime && body.endTime) {
|
|
5234
5300
|
const dateStr = body.date.split("T")[0];
|
|
@@ -5275,6 +5341,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5275
5341
|
const { ruleId } = await request.json();
|
|
5276
5342
|
if (!ruleId) return Response.json({ error: "ruleId is required" }, { status: 400 });
|
|
5277
5343
|
const deletedRule = await (0, import_scheduling41.removeDateOverride)(db, calendarId, ruleId);
|
|
5344
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5278
5345
|
const deletedIsTimeBlock = deletedRule?.isBlocked && !(deletedRule.startTime === "00:00" && deletedRule.endTime === "00:00");
|
|
5279
5346
|
await host.activity.log(db, {
|
|
5280
5347
|
action: "scheduling.date_override_removed",
|