@ordinatio/scheduling-api 0.6.0 → 0.7.0
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 +89 -1
- package/dist/agent/index.d.mts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +76 -0
- package/dist/agent/index.mjs +76 -0
- package/dist/{chunk-WZ5KO7IW.mjs → chunk-IW6AN5WE.mjs} +10 -1
- package/dist/index.d.mts +227 -5
- package/dist/index.d.ts +227 -5
- package/dist/index.js +864 -88
- package/dist/index.mjs +777 -25
- package/dist/{routes-CM-ezlv2.d.mts → routes-LaFljBCF.d.mts} +61 -2
- package/dist/{routes-CM-ezlv2.d.ts → routes-LaFljBCF.d.ts} +61 -2
- package/dist/schemas/index.d.mts +7 -1
- package/dist/schemas/index.d.ts +7 -1
- package/dist/schemas/index.js +10 -0
- package/dist/schemas/index.mjs +3 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (prepared 2026-11-17)
|
|
4
|
+
|
|
5
|
+
- **New route: `GET /admin/brand/sending-domain?domain=...`.** Admins get the record-by-record check of a sending domain (found, missing, wrong or unknown, with the exact name and a plain sentence for each) so a setup screen can show what to fix. It is rate limited as a settings action and has no agent tool (it makes the server look up names under a domain the caller chooses). The host turns it on with `brand.checkSendingDomain` (pass the verifier's `check`); without it the route answers 501. A value that is not a domain answers 400 before any lookup. It changes nothing.
|
|
6
|
+
- **New: check a business's sending domain.** `createSendingDomainVerifier({ records, resolver })` looks up the SPF, DKIM and DMARC records a mail provider asks for and reports each as `found`, `missing`, `wrong` or `unknown`, with a plain sentence to act on. `verifier.isSendingDomainVerified` fits the host's `brand.isSendingDomainVerified`, `verifier.check(domain)` feeds a setup screen, and `verifier.instructions(domain)` lists what to publish. `records` may be a function of the domain for providers that issue a token per domain. It works with any mail provider and any DNS lookup (`node:dns/promises` fits). `checkSendingDomain`, `normalizeSendingDomain` and the record and result types are exported too.
|
|
7
|
+
- **New: `createTextSettingsResolver`, so a business's saved text settings send real texts.** `createTextSettingsResolver({ db, telnyx?, twilio? })` returns the `resolve` function for `createPerBusinessSmsAdapter`: it reads the business's saved provider and number and builds a Telnyx or Twilio sender with the host's own account. A business with no settings, with texting paused (`enabled: false`), or that chose a provider the host gave no account for gets no sender, so its texts are skipped, never sent from another number. A missing or empty key, or a stored number the sender refuses, skips only that business and is logged. The router keeps each business's sender for `adapterTtlMs` (5 minutes by default), so **pausing texting or changing a number takes up to that long to reach every worker**: use a shorter `adapterTtlMs` where a pause must be quick, or call `forget(organizationId)` on the worker that handled the change. The host's keys are passed in once and never stored or logged by the package.
|
|
8
|
+
- **New: routes for a business's text-message settings.** `GET`, `PUT` and `DELETE /admin/text-settings` (admins) read, save and remove the provider (`TELNYX` or `TWILIO`) and sending number, with the agent tools `scheduling_get_text_settings`, `scheduling_save_text_settings` and `scheduling_remove_text_settings` (save and remove need approval). The host turns them on with `host.textMessages` (optionally listing the `providers` it has accounts for); without it they answer 501. A save that breaks a rule answers 400 with every problem at once. The activity log records the provider and whether texting is on, never the number. Needs the `OrganizationTextSettings` table from `@ordinatio/scheduling` 0.6.1.
|
|
9
|
+
- **New: a number and provider per business.** `createPerBusinessSmsAdapter({ resolve })` sends each text through the adapter you return for that business (build it with `createTelnyxSmsAdapter` or `createTwilioSmsAdapter`). A message only ever goes through its own business's adapter; one that names no business is skipped with a reason, never sent from another number. An adapter is reused for 5 minutes (`adapterTtlMs`) and a business with no number is rechecked after 1 minute (`noNumberTtlMs`), so a new number starts working soon in every worker; `forget(organizationId)` drops it at once. It needs `@ordinatio/scheduling` 0.6.1 or newer (now the required version) and the sender run with `processPendingNotifications(..., { organization: true })`.
|
|
10
|
+
- **New: a ready-made Twilio text-message adapter and webhook handler, so a business can use Twilio or Telnyx.** `createTwilioSmsAdapter({ accountSid, authToken, from, messagingServiceSid })` and `handleTwilioWebhook(rawBody, headers, { authToken, url })` behave exactly like the Telnyx ones: the adapter sends only the SMS channel, skips bad numbers, empty messages and opted-out recipients (Twilio code 21610), and throws `SmsSendError` (`retryable`, `outcomeUnknown`); the webhook handler checks Twilio's signature (the exact public `url` you gave Twilio is part of what is signed; Twilio sends no timestamp, so there is no age check) and returns the same events: `reply`, `opt-out`, `opt-in`, `delivery`, `ignored`. The shared parts are exported too: `SmsSendError` (`TelnyxSendError` is the same class; an error's `name` is now `SmsSendError`), `classifyReply`, and the `SmsInboundEvent` / `SmsWebhookResult` / `WebhookHeaders` types. Not yet tried against a live Twilio account.
|
|
11
|
+
- **New: incoming Telnyx webhooks.** `handleTelnyxWebhook(rawBody, headers, { publicKey })` checks the Ed25519 signature (and refuses a timestamp more than five minutes old), then returns one plain event: `reply` (a client texted back), `opt-out` (STOP, STOPALL, UNSUBSCRIBE, END, QUIT as the whole message; CANCEL and YES stay replies because clients use them about appointments), `opt-in` (START, UNSTOP), `delivery` (`delivered` or `failed`, with Telnyx's error code) or `ignored`. A bad signature answers `401`, a malformed event `400`. It stores nothing: the host saves replies and remembers opt-outs. Headers can be a plain object or a web `Headers`. Pass the raw body exactly as received; a re-serialized body fails the signature. `verifyTelnyxSignature` is exported too. Not yet tried against a live Telnyx account.
|
|
12
|
+
- **New: a ready-made Telnyx text-message adapter.** `createTelnyxSmsAdapter({ apiKey, from, messagingProfileId })` is a `NotificationAdapter` that sends the SMS channel through Telnyx and skips everything else, so it can sit beside an email adapter. Give it a sending number, a messaging profile, or both. Numbers are read in international format; ten US digits get +1. A number that cannot be valid, an empty message, and a recipient who has opted out are skipped (nothing is sent, retrying cannot help). A reply of 2xx counts as sent, with or without a message id. A timeout (including a stalled reply), network failure, rate limit or server error throws a `TelnyxSendError` with `retryable: true`; its `outcomeUnknown` is `true` when the text may already have been sent (timeout, network, server error), because Telnyx has no idempotency key and a retry can send it twice. Any other refusal throws it with `retryable: false`. The key is trimmed (a pasted trailing newline is the usual cause of "invalid key") and never appears in an error. It passes `checkNotificationContract`. Not yet tested against a live Telnyx account: the opt-out code (40300) and response shape follow Telnyx's documentation. `normalizePhoneNumber` and the `TelnyxSmsConfig` type are exported too.
|
|
13
|
+
- **New: a ready-made Microsoft Outlook calendar sync.** `createOutlookCalendarSync(config, hooks)` returns `{ adapter, pull }`. `adapter` is the `CalendarSyncAdapter` for `SchedulingHost.calendarSync`: it writes each appointment to the person's connected Outlook calendar (one event per appointment, updated when the appointment moves) and removes the event when the appointment is cancelled; an event already gone from Outlook counts as removed. `pull(calendarId)` reads changes made in Outlook back in, using Microsoft's delta query: an Outlook event that is not an appointment blocks that time as a "Blocked" appointment (never offered for booking), a moved appointment follows its event, and a deleted event cancels the appointment through your `hooks.cancelAppointment`. Run `pull` on a schedule for each connected calendar. `config` takes your Azure app's `clientId` and `clientSecret` and the database; access tokens are refreshed and the rotated refresh token is saved. A calendar whose refresh is refused is skipped until the person reconnects. An expired delta link starts one full sync; a second refusal on that fresh start is thrown, not retried. Also: the first pull of each month starts a new year-long window; a change your hooks could not handle stops the pull before its place is saved, so the next run sees it again (`onAppointmentMoved` can therefore run more than once for one change); a "Blocked" appointment is never written to or deleted from Outlook, because its event is the person's own; delta links are only followed when they point at Microsoft Graph; and run one pull at a time per calendar. `db` must be the database of the one organization whose calendars are synced: no organization check is made, so a host with a database per organization builds one sync per organization.
|
|
14
|
+
|
|
3
15
|
## 0.6.0 (prepared 2026-11-13)
|
|
4
16
|
|
|
5
17
|
- **New route: `GET /calendars/active`.** The active calendars the signed-in person may see, as a short list (`id`, `name`, `slug`, `staffName`) for pickers. Any member of the organization may ask, whatever their role, and the "scheduling is switched on" setting is not checked. Calendars outside the person's groups are left out, and the list never reaches beyond their organization. It is counted against the person under `admin-calendars-list`, the same name `GET /admin/calendars` uses. A host that served this list from its own route can serve it from here instead.
|
package/README.md
CHANGED
|
@@ -226,7 +226,7 @@ that your user can create databases in.
|
|
|
226
226
|
| `appUrl()` | The web address of your server. Booking needs it to build links in messages. | none: booking answers 500 |
|
|
227
227
|
| `staff` | Who is signed in. `createBearerStaffResolver` reads a bearer token; `createStaffContext` builds the person for your own sign-in. | nobody: staff routes answer 401 |
|
|
228
228
|
| `payments` | Charges, verifies and refunds payments. | none: a type that needs payment cannot be booked |
|
|
229
|
-
| `calendarSync` | Keeps Google or Outlook in step. | nothing is synced |
|
|
229
|
+
| `calendarSync` | Keeps Google or Outlook in step. `createOutlookCalendarSync` is ready-made for Outlook. | nothing is synced |
|
|
230
230
|
| `rateLimit` | Counts requests, by caller address. Return a response (normally 429) to stop one. Your server must set the address from the connection (see `createNodeListener`). | in-memory, per process |
|
|
231
231
|
| `secureCookies()` | Whether the short-lived sign-in cookies travel only over https. | yes: on plain http the cookies do not stick |
|
|
232
232
|
| `cache`, `availabilityCache` | Stored answers. | in-memory, per process |
|
|
@@ -260,6 +260,39 @@ README explains the retry schedule and how a receiver checks the signature. The
|
|
|
260
260
|
`appointment.rescheduled`, `appointment.cancelled`, `appointment.no_show` and `waitlist.offered`; `reminder.sent` is sent when
|
|
261
261
|
the worker that sends reminders passes `webhooks: true` to `processPendingNotifications`.
|
|
262
262
|
|
|
263
|
+
## Sending domain
|
|
264
|
+
|
|
265
|
+
A business can send booking emails from its own address (`fromEmail` in the brand) only after the domain is confirmed.
|
|
266
|
+
`createSendingDomainVerifier({ records, resolver })` does the confirming. Put its `isSendingDomainVerified` in the host's `brand` member. `records` lists what your mail provider asks a
|
|
267
|
+
business to publish at its domain host (SPF, DKIM, DMARC), or is a function of the domain when the provider issues a token per domain; `resolver` is any object with `resolveTxt` and `resolveCname`, and
|
|
268
|
+
`node:dns/promises` fits as it is.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
import { promises as dns } from 'node:dns';
|
|
272
|
+
import { createSendingDomainVerifier } from '@ordinatio/scheduling-api';
|
|
273
|
+
|
|
274
|
+
const verifier = createSendingDomainVerifier({
|
|
275
|
+
resolver: dns,
|
|
276
|
+
records: [
|
|
277
|
+
{ purpose: 'spf', type: 'TXT', name: '@', value: 'include:spf.mail.example', match: 'contains' },
|
|
278
|
+
{ purpose: 'dkim', type: 'CNAME', name: 's1._domainkey', value: 's1.dkim.mail.example' },
|
|
279
|
+
{ purpose: 'dmarc', type: 'TXT', name: '_dmarc', value: 'v=DMARC1; p=none', required: false },
|
|
280
|
+
],
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
verifier.instructions('mail.acme.example'); // each record with the full name to publish at
|
|
284
|
+
await verifier.check('mail.acme.example'); // { verified, records: [{ status, message, ... }] }
|
|
285
|
+
// In the host: brand: { isSendingDomainVerified: verifier.isSendingDomainVerified, checkSendingDomain: verifier.check }
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
With `checkSendingDomain` set, `GET /admin/brand/sending-domain?domain=mail.acme.example` (admins) returns `{ check }` for a setup screen. It is rate limited as a settings action and has no agent tool, because it makes your resolver look up names under a domain the caller chooses. It answers 400 for something that is not a domain and 501 when the host did not set `checkSendingDomain`.
|
|
289
|
+
|
|
290
|
+
Each record comes back `found`, `missing`, `wrong` or `unknown`, with a sentence a business owner can act on. A lookup that
|
|
291
|
+
fails is `unknown` and leaves the domain unverified; the check never throws. A record with `required: false` never blocks, and a
|
|
292
|
+
list with no required record never verifies. A `contains` match (for SPF) needs the wanted entry as a whole term. The package does not talk to any mail provider: the record values are the host's to supply.
|
|
293
|
+
Records that are the same for every domain prove only that the provider was set up at that domain, not who is claiming it; where several
|
|
294
|
+
businesses share one provider, use the function form with a token that belongs to the claiming organization.
|
|
295
|
+
|
|
263
296
|
## Waitlist
|
|
264
297
|
|
|
265
298
|
Set `waitlist: {}` on the host to let clients wait for a full slot or day. A cancelled, rejected or moved booking offers
|
|
@@ -344,6 +377,61 @@ does not end up in access logs.
|
|
|
344
377
|
A body that names nobody, names an invalid address, or carries other fields is a 400. Both actions are rate limited and written to
|
|
345
378
|
the host's activity feed with counts only. Without `privacy` on the host the routes answer 501.
|
|
346
379
|
|
|
380
|
+
## Text messages (Telnyx or Twilio)
|
|
381
|
+
|
|
382
|
+
Pick a provider per business: `createTelnyxSmsAdapter` or `createTwilioSmsAdapter` (same shape; Twilio takes `accountSid`, `authToken` and a `from` number or `messagingServiceSid`). Their webhook handlers, `handleTelnyxWebhook` and `handleTwilioWebhook`, return the same events. `createTelnyxSmsAdapter` sends the SMS channel through Telnyx. Pass your own key and sending number:
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
import { createTelnyxSmsAdapter } from '@ordinatio/scheduling-api';
|
|
386
|
+
|
|
387
|
+
const sms = createTelnyxSmsAdapter({
|
|
388
|
+
apiKey: process.env.TELNYX_API_KEY!,
|
|
389
|
+
from: '+13135550100', // your Telnyx number
|
|
390
|
+
// messagingProfileId: '...', // or use a profile instead of, or with, a number
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
It is a `NotificationAdapter`, so use it wherever the engine takes one. It skips email, bad numbers, empty messages and
|
|
395
|
+
people who opted out (STOP). A timeout, rate limit or server error throws a `TelnyxSendError` whose `retryable` is `true`;
|
|
396
|
+
when its `outcomeUnknown` is also `true` the text may already have gone out, so retrying can send it twice.
|
|
397
|
+
Your number must be registered for US text messaging (10DLC) before carriers will deliver.
|
|
398
|
+
|
|
399
|
+
Each business can choose its own provider and number. Switch it on with `host.textMessages: {}` (or `{ providers: ['TELNYX'] }` to offer fewer): admins then get `GET`, `PUT` and `DELETE /admin/text-settings`, with agent tools to read, save and remove. It stores only the provider and the number, never keys: your server holds the provider accounts. Run the engine's `OrganizationTextSettings` migration first. Without `host.textMessages` the routes answer 501.
|
|
400
|
+
|
|
401
|
+
To give each business its own number or provider, wrap the adapters in a router and run the sender with `organization: true`. A business with no number, and a message that names no business, are skipped (never sent from another number):
|
|
402
|
+
|
|
403
|
+
```ts
|
|
404
|
+
import { createPerBusinessSmsAdapter, createTextSettingsResolver } from '@ordinatio/scheduling-api';
|
|
405
|
+
|
|
406
|
+
const sms = createPerBusinessSmsAdapter({
|
|
407
|
+
// Looks up each business's saved provider and number and builds its sender with YOUR provider accounts.
|
|
408
|
+
resolve: createTextSettingsResolver({
|
|
409
|
+
db: (organizationId) => dbForOrganization(organizationId),
|
|
410
|
+
telnyx: { apiKey: process.env.TELNYX_API_KEY! },
|
|
411
|
+
twilio: { accountSid: process.env.TWILIO_ACCOUNT_SID!, authToken: process.env.TWILIO_AUTH_TOKEN! },
|
|
412
|
+
}),
|
|
413
|
+
});
|
|
414
|
+
// processPendingNotifications and adaptersToCallbacks come from '@ordinatio/scheduling'
|
|
415
|
+
const { sendNotification } = adaptersToCallbacks({ notifications: sms, payments: yourPaymentAdapter });
|
|
416
|
+
await processPendingNotifications(db, sendNotification!, { organization: true });
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
A business with no saved settings, with texting paused, or that chose a provider you gave no account for, sends nothing (its texts are skipped, not sent from another number). Leave out `telnyx` or `twilio` if you have no account with that provider. The router keeps each business's sender for 5 minutes (`adapterTtlMs`), so a pause or a new number takes up to that long to reach every worker; set a shorter `adapterTtlMs` where a pause must be quick.
|
|
420
|
+
|
|
421
|
+
Point your Telnyx messaging profile's webhook at a route of yours and pass the raw body to `handleTelnyxWebhook`:
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
// In a Fetch-style route: const rawBody = await request.text();
|
|
425
|
+
const result = handleTelnyxWebhook(rawBody, request.headers, { publicKey: process.env.TELNYX_PUBLIC_KEY! });
|
|
426
|
+
if (!result.ok) return new Response(result.reason, { status: result.status });
|
|
427
|
+
if (result.event.type === 'opt-out') await stopTexting(result.event.from); // you store it
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
It returns `reply`, `opt-out`, `opt-in`, `delivery` or `ignored`; saving them is up to you.
|
|
431
|
+
|
|
432
|
+
For Twilio, pass the raw form body, the headers and the exact address Twilio calls:
|
|
433
|
+
`handleTwilioWebhook(rawBody, request.headers, { authToken, url: 'https://your.app/hooks/sms' })`.
|
|
434
|
+
|
|
347
435
|
## Agent tools
|
|
348
436
|
|
|
349
437
|
An AI agent can run scheduling through the same routes. Import the tool descriptions and hand them to any agent runner:
|
package/dist/agent/index.d.mts
CHANGED
package/dist/agent/index.d.ts
CHANGED
package/dist/agent/index.js
CHANGED
|
@@ -1920,6 +1920,81 @@ var SETTINGS_TOOLS = [
|
|
|
1920
1920
|
reason: "Clients lose the custom name, colours and sender at once.",
|
|
1921
1921
|
prompt: "Remove the brand? Clients will see the default look."
|
|
1922
1922
|
}
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
name: "scheduling_get_text_settings",
|
|
1926
|
+
module: "scheduling",
|
|
1927
|
+
method: "GET",
|
|
1928
|
+
route: "/admin/text-settings",
|
|
1929
|
+
auth: "session_cookie",
|
|
1930
|
+
description: "Read which text-message provider and sending number the organization uses, and which providers the server offers.",
|
|
1931
|
+
params: [],
|
|
1932
|
+
example: {},
|
|
1933
|
+
responseShape: "{ settings: { provider, fromNumber, enabled, updatedAt } | null, providers: string[] }",
|
|
1934
|
+
whenToUse: "Before changing the text-message settings, or when the owner asks which number their texts come from.",
|
|
1935
|
+
pitfalls: [
|
|
1936
|
+
"settings is null when none has been saved; the organization then sends no texts of its own.",
|
|
1937
|
+
"The provider accounts belong to the server; this holds only the choice and the number.",
|
|
1938
|
+
"A server without text-message settings answers 501.",
|
|
1939
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1940
|
+
],
|
|
1941
|
+
dataSensitivity: "internal",
|
|
1942
|
+
risk: "observe"
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
name: "scheduling_save_text_settings",
|
|
1946
|
+
module: "scheduling",
|
|
1947
|
+
method: "PUT",
|
|
1948
|
+
route: "/admin/text-settings",
|
|
1949
|
+
auth: "session_cookie",
|
|
1950
|
+
description: "Save the organization's text-message provider and sending number. This replaces the whole setting: enabled you leave out becomes true.",
|
|
1951
|
+
params: [
|
|
1952
|
+
{ name: "provider", type: "string", required: true, description: "The text provider: one of the providers the server offers (TELNYX or TWILIO)" },
|
|
1953
|
+
{ name: "fromNumber", type: "string", required: true, description: "The number texts are sent from, such as +13135550100; ten US digits are read as a US number" },
|
|
1954
|
+
{ name: "enabled", type: "boolean", required: false, description: "False pauses texting without losing the number. Default true." }
|
|
1955
|
+
],
|
|
1956
|
+
example: { provider: "TELNYX", fromNumber: "+13135550100" },
|
|
1957
|
+
responseShape: "{ settings: { provider, fromNumber, enabled, updatedAt } }",
|
|
1958
|
+
whenToUse: "To set up or change the number clients are texted from. Read the settings first.",
|
|
1959
|
+
pitfalls: [
|
|
1960
|
+
"It replaces everything; send enabled again to keep texting paused.",
|
|
1961
|
+
"The number must be one the owner has with that provider; this does not buy or register a number.",
|
|
1962
|
+
"A save that breaks a rule is refused with 400 and every problem is listed at once in details; nothing is saved.",
|
|
1963
|
+
"A server without text-message settings answers 501.",
|
|
1964
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1965
|
+
],
|
|
1966
|
+
dataSensitivity: "internal",
|
|
1967
|
+
risk: "act",
|
|
1968
|
+
requiresApproval: {
|
|
1969
|
+
action: "Save the text-message settings",
|
|
1970
|
+
reason: "Clients are texted from this number from now on, and a number that is not set up with the provider means their reminders are not delivered.",
|
|
1971
|
+
prompt: "Save the text-message settings: send from {fromNumber} with {provider}?"
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
{
|
|
1975
|
+
name: "scheduling_remove_text_settings",
|
|
1976
|
+
module: "scheduling",
|
|
1977
|
+
method: "DELETE",
|
|
1978
|
+
route: "/admin/text-settings",
|
|
1979
|
+
auth: "session_cookie",
|
|
1980
|
+
description: "Remove the organization's text-message settings, so it sends no texts of its own.",
|
|
1981
|
+
params: [],
|
|
1982
|
+
example: {},
|
|
1983
|
+
responseShape: "{ removed }",
|
|
1984
|
+
whenToUse: "Only to stop texting from the organization's own number. To pause or change it, use scheduling_save_text_settings.",
|
|
1985
|
+
pitfalls: [
|
|
1986
|
+
"removed is false when there were no settings; that is not an error.",
|
|
1987
|
+
"Text reminders stop being sent until settings are saved again.",
|
|
1988
|
+
"A server without text-message settings answers 501.",
|
|
1989
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1990
|
+
],
|
|
1991
|
+
dataSensitivity: "internal",
|
|
1992
|
+
risk: "act",
|
|
1993
|
+
requiresApproval: {
|
|
1994
|
+
action: "Remove the text-message settings",
|
|
1995
|
+
reason: "Clients stop receiving text reminders and confirmations at once.",
|
|
1996
|
+
prompt: "Remove the text-message settings? Clients will no longer be texted."
|
|
1997
|
+
}
|
|
1923
1998
|
}
|
|
1924
1999
|
];
|
|
1925
2000
|
|
|
@@ -2296,6 +2371,7 @@ var SCHEDULING_AGENT_EXCLUDED = {
|
|
|
2296
2371
|
"GET /calendars": "Public booking-page data for visitors; the admin calendar tools cover this for staff.",
|
|
2297
2372
|
"GET /calendars/active": "A short calendar list for the pickers in a staff dashboard; the admin calendar list tool, for admin roles, returns every calendar with more detail, inactive ones too.",
|
|
2298
2373
|
"POST /payments/intent": "Creates a card payment in the visitor's own browser session; staff take payment with the collect-balance tool.",
|
|
2374
|
+
"GET /admin/brand/sending-domain": "Makes the server look up DNS names under a domain the caller chooses, with no approval step for a GET tool; an agent steered by injected text could use it to send data to a name server it controls. Admins use the dashboard setup screen.",
|
|
2299
2375
|
"GET /brand": "Public copy of the brand settings; the brand tool for staff returns the same data.",
|
|
2300
2376
|
"GET /routing-forms": "Public form shown to a visitor; staff read the whole form, rules and fallback included, with scheduling_get_routing_form.",
|
|
2301
2377
|
"POST /routing-forms/route": "Runs a visitor's own answers through a form; staff try sample answers with scheduling_test_routing_form.",
|
package/dist/agent/index.mjs
CHANGED
|
@@ -1891,6 +1891,81 @@ var SETTINGS_TOOLS = [
|
|
|
1891
1891
|
reason: "Clients lose the custom name, colours and sender at once.",
|
|
1892
1892
|
prompt: "Remove the brand? Clients will see the default look."
|
|
1893
1893
|
}
|
|
1894
|
+
},
|
|
1895
|
+
{
|
|
1896
|
+
name: "scheduling_get_text_settings",
|
|
1897
|
+
module: "scheduling",
|
|
1898
|
+
method: "GET",
|
|
1899
|
+
route: "/admin/text-settings",
|
|
1900
|
+
auth: "session_cookie",
|
|
1901
|
+
description: "Read which text-message provider and sending number the organization uses, and which providers the server offers.",
|
|
1902
|
+
params: [],
|
|
1903
|
+
example: {},
|
|
1904
|
+
responseShape: "{ settings: { provider, fromNumber, enabled, updatedAt } | null, providers: string[] }",
|
|
1905
|
+
whenToUse: "Before changing the text-message settings, or when the owner asks which number their texts come from.",
|
|
1906
|
+
pitfalls: [
|
|
1907
|
+
"settings is null when none has been saved; the organization then sends no texts of its own.",
|
|
1908
|
+
"The provider accounts belong to the server; this holds only the choice and the number.",
|
|
1909
|
+
"A server without text-message settings answers 501.",
|
|
1910
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1911
|
+
],
|
|
1912
|
+
dataSensitivity: "internal",
|
|
1913
|
+
risk: "observe"
|
|
1914
|
+
},
|
|
1915
|
+
{
|
|
1916
|
+
name: "scheduling_save_text_settings",
|
|
1917
|
+
module: "scheduling",
|
|
1918
|
+
method: "PUT",
|
|
1919
|
+
route: "/admin/text-settings",
|
|
1920
|
+
auth: "session_cookie",
|
|
1921
|
+
description: "Save the organization's text-message provider and sending number. This replaces the whole setting: enabled you leave out becomes true.",
|
|
1922
|
+
params: [
|
|
1923
|
+
{ name: "provider", type: "string", required: true, description: "The text provider: one of the providers the server offers (TELNYX or TWILIO)" },
|
|
1924
|
+
{ name: "fromNumber", type: "string", required: true, description: "The number texts are sent from, such as +13135550100; ten US digits are read as a US number" },
|
|
1925
|
+
{ name: "enabled", type: "boolean", required: false, description: "False pauses texting without losing the number. Default true." }
|
|
1926
|
+
],
|
|
1927
|
+
example: { provider: "TELNYX", fromNumber: "+13135550100" },
|
|
1928
|
+
responseShape: "{ settings: { provider, fromNumber, enabled, updatedAt } }",
|
|
1929
|
+
whenToUse: "To set up or change the number clients are texted from. Read the settings first.",
|
|
1930
|
+
pitfalls: [
|
|
1931
|
+
"It replaces everything; send enabled again to keep texting paused.",
|
|
1932
|
+
"The number must be one the owner has with that provider; this does not buy or register a number.",
|
|
1933
|
+
"A save that breaks a rule is refused with 400 and every problem is listed at once in details; nothing is saved.",
|
|
1934
|
+
"A server without text-message settings answers 501.",
|
|
1935
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1936
|
+
],
|
|
1937
|
+
dataSensitivity: "internal",
|
|
1938
|
+
risk: "act",
|
|
1939
|
+
requiresApproval: {
|
|
1940
|
+
action: "Save the text-message settings",
|
|
1941
|
+
reason: "Clients are texted from this number from now on, and a number that is not set up with the provider means their reminders are not delivered.",
|
|
1942
|
+
prompt: "Save the text-message settings: send from {fromNumber} with {provider}?"
|
|
1943
|
+
}
|
|
1944
|
+
},
|
|
1945
|
+
{
|
|
1946
|
+
name: "scheduling_remove_text_settings",
|
|
1947
|
+
module: "scheduling",
|
|
1948
|
+
method: "DELETE",
|
|
1949
|
+
route: "/admin/text-settings",
|
|
1950
|
+
auth: "session_cookie",
|
|
1951
|
+
description: "Remove the organization's text-message settings, so it sends no texts of its own.",
|
|
1952
|
+
params: [],
|
|
1953
|
+
example: {},
|
|
1954
|
+
responseShape: "{ removed }",
|
|
1955
|
+
whenToUse: "Only to stop texting from the organization's own number. To pause or change it, use scheduling_save_text_settings.",
|
|
1956
|
+
pitfalls: [
|
|
1957
|
+
"removed is false when there were no settings; that is not an error.",
|
|
1958
|
+
"Text reminders stop being sent until settings are saved again.",
|
|
1959
|
+
"A server without text-message settings answers 501.",
|
|
1960
|
+
"Needs the scheduling switch to be on for the organization."
|
|
1961
|
+
],
|
|
1962
|
+
dataSensitivity: "internal",
|
|
1963
|
+
risk: "act",
|
|
1964
|
+
requiresApproval: {
|
|
1965
|
+
action: "Remove the text-message settings",
|
|
1966
|
+
reason: "Clients stop receiving text reminders and confirmations at once.",
|
|
1967
|
+
prompt: "Remove the text-message settings? Clients will no longer be texted."
|
|
1968
|
+
}
|
|
1894
1969
|
}
|
|
1895
1970
|
];
|
|
1896
1971
|
|
|
@@ -2267,6 +2342,7 @@ var SCHEDULING_AGENT_EXCLUDED = {
|
|
|
2267
2342
|
"GET /calendars": "Public booking-page data for visitors; the admin calendar tools cover this for staff.",
|
|
2268
2343
|
"GET /calendars/active": "A short calendar list for the pickers in a staff dashboard; the admin calendar list tool, for admin roles, returns every calendar with more detail, inactive ones too.",
|
|
2269
2344
|
"POST /payments/intent": "Creates a card payment in the visitor's own browser session; staff take payment with the collect-balance tool.",
|
|
2345
|
+
"GET /admin/brand/sending-domain": "Makes the server look up DNS names under a domain the caller chooses, with no approval step for a GET tool; an agent steered by injected text could use it to send data to a name server it controls. Admins use the dashboard setup screen.",
|
|
2270
2346
|
"GET /brand": "Public copy of the brand settings; the brand tool for staff returns the same data.",
|
|
2271
2347
|
"GET /routing-forms": "Public form shown to a visitor; staff read the whole form, rules and fallback included, with scheduling_get_routing_form.",
|
|
2272
2348
|
"POST /routing-forms/route": "Runs a visitor's own answers through a form; staff try sample answers with scheduling_test_routing_form.",
|
|
@@ -429,6 +429,14 @@ var BrandSchema = z8.object({
|
|
|
429
429
|
fromEmail: optionalText(400)
|
|
430
430
|
}).strict();
|
|
431
431
|
|
|
432
|
+
// src/schemas/text-settings.schema.ts
|
|
433
|
+
import { z as z9 } from "zod";
|
|
434
|
+
var TextSettingsSchema = z9.object({
|
|
435
|
+
provider: z9.string().max(40),
|
|
436
|
+
fromNumber: z9.string().max(40),
|
|
437
|
+
enabled: z9.boolean().optional()
|
|
438
|
+
}).strict();
|
|
439
|
+
|
|
432
440
|
export {
|
|
433
441
|
IntakeFormFieldSchema,
|
|
434
442
|
CreateAppointmentTypeSchema,
|
|
@@ -467,5 +475,6 @@ export {
|
|
|
467
475
|
TestRoutingFormSchema,
|
|
468
476
|
PrivacySubjectSchema,
|
|
469
477
|
PrivacyEraseSchema,
|
|
470
|
-
BrandSchema
|
|
478
|
+
BrandSchema,
|
|
479
|
+
TextSettingsSchema
|
|
471
480
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
2
|
-
export {
|
|
3
|
-
import { SchedulingDb, PaymentAdapter, AppointmentStatus, CalendarSyncAdapter, CalendarEventRef, CalendarEvent } from '@ordinatio/scheduling';
|
|
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.mjs';
|
|
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 SendingDomainCheck, e as SendingDomainRecord, f as SendingDomainRecords, D as DnsResolver, g as StaffResolver, h as StaffContext } from './routes-LaFljBCF.mjs';
|
|
2
|
+
export { i as ActivityEntry, j as ActivityLog, k as AppointmentEventSink, l as BookingClientResolver, m as BookingPolicy, n as BrandSettings, C as CacheOptions, o as CalendarConnectOutcome, p as CalendarConnector, q as CalendarConnectors, r as CalendarVisibility, I as InternalAccess, N as NoShowPolicy, s as PrivacySettings, t as PublicBookingContext, u as PublicBookingKind, v as PublicOrganization, w as RecordCheck, x as RecordStatus, y as ResolvedHost, z as RouteContext, E as RouteHandler, F as RoutingFormSettings, G as StaffDirectory, W as WaitlistSettings, J as WebhookSettings, K as WorkerCommands, L as checkSendingDomain, M as normalizeSendingDomain } from './routes-LaFljBCF.mjs';
|
|
3
|
+
import { SchedulingDb, PaymentAdapter, NotificationAdapter, AppointmentStatus, CalendarSyncAdapter, CalendarEventRef, CalendarEvent } from '@ordinatio/scheduling';
|
|
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, TextSettingsSchema, UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, UpdateBookingPageInput, UpdateBookingPageSchema, UpdateCalendarInput, UpdateCalendarSchema, UpdateCouponCodeInput, UpdateCouponCodeSchema, UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, UpdateRoutingFormInput, UpdateRoutingFormSchema, UpdateServicePackageInput, UpdateServicePackageSchema } from './schemas/index.mjs';
|
|
5
5
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
@@ -133,6 +133,184 @@ declare function createStripePaymentAdapter(client: StripeLike): PaymentAdapter;
|
|
|
133
133
|
/** Returns the key when it is a Stripe test-mode secret key. A live key must never reach a script that creates and refunds payments. */
|
|
134
134
|
declare function assertStripeTestKey(raw: string | undefined): string;
|
|
135
135
|
|
|
136
|
+
interface SendingDomainVerifierConfig {
|
|
137
|
+
/**
|
|
138
|
+
* The records your mail provider asks for. Their values are provider-specific, so the host lists them. Records that are
|
|
139
|
+
* the same for every domain only prove the provider was set up at the domain, not who is claiming it: when your provider
|
|
140
|
+
* issues a token per domain or organization, pass a function that returns that domain's records.
|
|
141
|
+
*/
|
|
142
|
+
records: SendingDomainRecords;
|
|
143
|
+
resolver: DnsResolver;
|
|
144
|
+
}
|
|
145
|
+
interface SendingDomainVerifier {
|
|
146
|
+
/** Pass to `saveBrand`: true only when every required record is published. */
|
|
147
|
+
isSendingDomainVerified(domain: string): Promise<boolean>;
|
|
148
|
+
/** The same check with a status and a plain sentence for each record. */
|
|
149
|
+
check(domain: string): Promise<SendingDomainCheck>;
|
|
150
|
+
/** What a business must add at its domain host, with the full name for each record. Empty for something that is not a domain. */
|
|
151
|
+
instructions(domain: string): Array<{
|
|
152
|
+
record: SendingDomainRecord;
|
|
153
|
+
host: string;
|
|
154
|
+
}>;
|
|
155
|
+
}
|
|
156
|
+
declare function createSendingDomainVerifier(config: SendingDomainVerifierConfig): SendingDomainVerifier;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Thrown when a provider did not confirm the message. `retryable` is true when trying again may work.
|
|
160
|
+
* `outcomeUnknown` is true when the text may already have been sent (timeout, network failure, server error),
|
|
161
|
+
* so a retry can duplicate it.
|
|
162
|
+
*/
|
|
163
|
+
declare class SmsSendError extends Error {
|
|
164
|
+
readonly retryable: boolean;
|
|
165
|
+
readonly outcomeUnknown: boolean;
|
|
166
|
+
readonly status?: number | undefined;
|
|
167
|
+
readonly code?: string | undefined;
|
|
168
|
+
constructor(message: string, retryable: boolean, outcomeUnknown: boolean, status?: number | undefined, code?: string | undefined);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns the number in international format, or null when it cannot be one. Ten digits are read as a US
|
|
172
|
+
* number; anything else must already start with a plus and country code.
|
|
173
|
+
*/
|
|
174
|
+
declare function normalizePhoneNumber(raw: string): string | null;
|
|
175
|
+
/** What a provider's webhook means, in the same words for every provider. */
|
|
176
|
+
type SmsInboundEvent = {
|
|
177
|
+
type: 'reply';
|
|
178
|
+
id: string;
|
|
179
|
+
from: string;
|
|
180
|
+
to: string;
|
|
181
|
+
text: string;
|
|
182
|
+
} | {
|
|
183
|
+
type: 'opt-out';
|
|
184
|
+
id: string;
|
|
185
|
+
from: string;
|
|
186
|
+
to: string;
|
|
187
|
+
text: string;
|
|
188
|
+
} | {
|
|
189
|
+
type: 'opt-in';
|
|
190
|
+
id: string;
|
|
191
|
+
from: string;
|
|
192
|
+
to: string;
|
|
193
|
+
text: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: 'delivery';
|
|
196
|
+
id: string;
|
|
197
|
+
status: 'delivered' | 'failed';
|
|
198
|
+
to: string;
|
|
199
|
+
errorCode?: string;
|
|
200
|
+
} | {
|
|
201
|
+
type: 'ignored';
|
|
202
|
+
eventType: string;
|
|
203
|
+
};
|
|
204
|
+
type SmsWebhookResult = {
|
|
205
|
+
ok: true;
|
|
206
|
+
event: SmsInboundEvent;
|
|
207
|
+
} | {
|
|
208
|
+
ok: false;
|
|
209
|
+
status: 400 | 401;
|
|
210
|
+
reason: string;
|
|
211
|
+
};
|
|
212
|
+
/** Plain header record (Node, Express) or a web `Headers` object (Fetch-style routes). */
|
|
213
|
+
type WebhookHeaders = Record<string, string | string[] | undefined> | {
|
|
214
|
+
get(name: string): string | null;
|
|
215
|
+
};
|
|
216
|
+
/** A message that is only a stop or start word counts as an opt-out or opt-in; anything else is a reply. */
|
|
217
|
+
declare function classifyReply(text: string): 'reply' | 'opt-out' | 'opt-in';
|
|
218
|
+
|
|
219
|
+
interface TelnyxSmsConfig {
|
|
220
|
+
apiKey: string;
|
|
221
|
+
/** The sending number in international format, such as +13135550100. */
|
|
222
|
+
from?: string;
|
|
223
|
+
/** A Telnyx messaging profile id. Used when no sending number is given, or alongside one. */
|
|
224
|
+
messagingProfileId?: string;
|
|
225
|
+
/** Replaces the global fetch, for tests. */
|
|
226
|
+
fetch?: typeof fetch;
|
|
227
|
+
timeoutMs?: number;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare function createTelnyxSmsAdapter(config: TelnyxSmsConfig): NotificationAdapter;
|
|
231
|
+
|
|
232
|
+
type TelnyxInboundEvent = SmsInboundEvent;
|
|
233
|
+
type TelnyxWebhookResult = SmsWebhookResult;
|
|
234
|
+
interface TelnyxWebhookOptions {
|
|
235
|
+
/** The webhook public key from the Telnyx portal (base64). */
|
|
236
|
+
publicKey: string;
|
|
237
|
+
/** Replaces the clock, for tests. */
|
|
238
|
+
now?: () => Date;
|
|
239
|
+
toleranceSeconds?: number;
|
|
240
|
+
}
|
|
241
|
+
/** True when the body was signed by Telnyx's key and the timestamp is recent. */
|
|
242
|
+
declare function verifyTelnyxSignature(rawBody: string, headers: WebhookHeaders, options: TelnyxWebhookOptions): boolean;
|
|
243
|
+
/** Checks the signature and reads the event. Call it with the raw request body, exactly as received. */
|
|
244
|
+
declare function handleTelnyxWebhook(rawBody: string, headers: WebhookHeaders, options: TelnyxWebhookOptions): TelnyxWebhookResult;
|
|
245
|
+
|
|
246
|
+
interface TwilioSmsConfig {
|
|
247
|
+
accountSid: string;
|
|
248
|
+
authToken: string;
|
|
249
|
+
/** The sending number in international format, such as +13135550100. */
|
|
250
|
+
from?: string;
|
|
251
|
+
/** A Twilio messaging service SID. Used when no sending number is given. */
|
|
252
|
+
messagingServiceSid?: string;
|
|
253
|
+
/** Replaces the global fetch, for tests. */
|
|
254
|
+
fetch?: typeof fetch;
|
|
255
|
+
timeoutMs?: number;
|
|
256
|
+
}
|
|
257
|
+
declare function createTwilioSmsAdapter(config: TwilioSmsConfig): NotificationAdapter;
|
|
258
|
+
|
|
259
|
+
interface TwilioWebhookOptions {
|
|
260
|
+
/** The Twilio auth token of the account that sends the webhooks. */
|
|
261
|
+
authToken: string;
|
|
262
|
+
/** The exact public address Twilio was told to call, including https and any query string. */
|
|
263
|
+
url: string;
|
|
264
|
+
}
|
|
265
|
+
/** True when the form body was signed by Twilio for this address. Twilio sends no timestamp, so there is no age check. */
|
|
266
|
+
declare function verifyTwilioSignature(rawBody: string, headers: WebhookHeaders, options: TwilioWebhookOptions): boolean;
|
|
267
|
+
/** Checks the signature and reads the event. Pass the raw form body exactly as received. */
|
|
268
|
+
declare function handleTwilioWebhook(rawBody: string, headers: WebhookHeaders, options: TwilioWebhookOptions): SmsWebhookResult;
|
|
269
|
+
|
|
270
|
+
interface PerBusinessSmsOptions {
|
|
271
|
+
/**
|
|
272
|
+
* Returns the adapter for one business, or null when it has no text number. Build it with createTelnyxSmsAdapter or
|
|
273
|
+
* createTwilioSmsAdapter. The answer is reused until it expires, so a changed number is picked up within `adapterTtlMs`
|
|
274
|
+
* (or at once with `forget`) in every worker.
|
|
275
|
+
*/
|
|
276
|
+
resolve(organizationId: string): Promise<NotificationAdapter | null> | NotificationAdapter | null;
|
|
277
|
+
/** How long an adapter is reused. Default 5 minutes. */
|
|
278
|
+
adapterTtlMs?: number;
|
|
279
|
+
/** How long "no number" is reused, so a business that adds a number starts sending soon. Default 1 minute. */
|
|
280
|
+
noNumberTtlMs?: number;
|
|
281
|
+
/** Replaces the clock, for tests. */
|
|
282
|
+
now?: () => number;
|
|
283
|
+
}
|
|
284
|
+
interface PerBusinessSmsAdapter extends NotificationAdapter {
|
|
285
|
+
/** Drops the kept answer for a business, for when its number or provider changed. */
|
|
286
|
+
forget(organizationId: string): void;
|
|
287
|
+
}
|
|
288
|
+
declare function createPerBusinessSmsAdapter(options: PerBusinessSmsOptions): PerBusinessSmsAdapter;
|
|
289
|
+
|
|
290
|
+
interface TextSettingsResolverOptions {
|
|
291
|
+
/** The database that holds the organization's settings. */
|
|
292
|
+
db(organizationId: string): Promise<SchedulingDb> | SchedulingDb;
|
|
293
|
+
/** The host's Telnyx account. Leave out when the server has none: a business that chose Telnyx then sends nothing. */
|
|
294
|
+
telnyx?: {
|
|
295
|
+
apiKey: string;
|
|
296
|
+
messagingProfileId?: string;
|
|
297
|
+
};
|
|
298
|
+
/** The host's Twilio account. Leave out when the server has none. */
|
|
299
|
+
twilio?: {
|
|
300
|
+
accountSid: string;
|
|
301
|
+
authToken: string;
|
|
302
|
+
};
|
|
303
|
+
/** Replaces the global fetch, for tests. */
|
|
304
|
+
fetch?: typeof fetch;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Returns `resolve(organizationId)`: the adapter for the business's saved provider and number, or null when it has no
|
|
308
|
+
* settings, has paused texting, or chose a provider this server has no account for. Pass it to createPerBusinessSmsAdapter,
|
|
309
|
+
* which keeps each answer for `adapterTtlMs` (5 minutes by default): a pause or a changed number reaches every worker within
|
|
310
|
+
* that time, or at once for the worker where `forget(organizationId)` is called. Use a short `adapterTtlMs` where a pause must be quick.
|
|
311
|
+
*/
|
|
312
|
+
declare function createTextSettingsResolver(options: TextSettingsResolverOptions): (organizationId: string) => Promise<NotificationAdapter | null>;
|
|
313
|
+
|
|
136
314
|
/**
|
|
137
315
|
* Converts a Prisma Decimal (or anything Number() can coerce) to integer cents, rounded to the nearest cent.
|
|
138
316
|
* Throws SchedulingValidationError (SCHED_406) instead of returning NaN: a null or non-numeric value almost
|
|
@@ -280,6 +458,50 @@ declare const BALANCE_APPOINTMENT_SELECT: {
|
|
|
280
458
|
};
|
|
281
459
|
};
|
|
282
460
|
|
|
461
|
+
interface OutlookSyncConfig {
|
|
462
|
+
/**
|
|
463
|
+
* The database of the one organization whose calendars are synced. Appointments and calendars are found by id and
|
|
464
|
+
* no organization check is made, so a host with a database per organization builds one sync per organization.
|
|
465
|
+
*/
|
|
466
|
+
db: SchedulingDb;
|
|
467
|
+
/** The Azure app's id and secret. Surrounding whitespace is removed: a pasted dashboard value often carries a newline. */
|
|
468
|
+
clientId: string;
|
|
469
|
+
clientSecret: string;
|
|
470
|
+
/** Defaults to the global fetch. */
|
|
471
|
+
fetch?: typeof fetch;
|
|
472
|
+
now?: () => Date;
|
|
473
|
+
/** Receives anything that failed but was handled, so the host can log it. Nothing is logged by default. */
|
|
474
|
+
onProblem?: (message: string, context: Record<string, unknown>) => void;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
interface OutlookPullHooks {
|
|
478
|
+
/**
|
|
479
|
+
* Called when an appointment's Outlook event was deleted. Return true once the appointment is cancelled. If it
|
|
480
|
+
* throws or returns false, the pull stops without saving its place and the next run tries again.
|
|
481
|
+
*/
|
|
482
|
+
cancelAppointment(appointmentId: string): Promise<boolean>;
|
|
483
|
+
/**
|
|
484
|
+
* Called when an appointment's time was changed in Outlook, before the new time is saved. If it throws, the pull
|
|
485
|
+
* stops without saving its place and the next run calls it again, so it can be called more than once for one change.
|
|
486
|
+
*/
|
|
487
|
+
onAppointmentMoved?(change: {
|
|
488
|
+
appointmentId: string;
|
|
489
|
+
organizationId: string | null;
|
|
490
|
+
startTime: Date;
|
|
491
|
+
endTime: Date;
|
|
492
|
+
}): Promise<void>;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
interface OutlookCalendarSync {
|
|
496
|
+
/** Plug into SchedulingHost.calendarSync. */
|
|
497
|
+
adapter: CalendarSyncAdapter;
|
|
498
|
+
/** Run on a schedule for each connected calendar. */
|
|
499
|
+
pull(calendarId: string): Promise<{
|
|
500
|
+
synced: number;
|
|
501
|
+
}>;
|
|
502
|
+
}
|
|
503
|
+
declare function createOutlookCalendarSync(config: OutlookSyncConfig, hooks: OutlookPullHooks): OutlookCalendarSync;
|
|
504
|
+
|
|
283
505
|
type NonBlockingResult = {
|
|
284
506
|
queued: boolean;
|
|
285
507
|
ref?: string;
|
|
@@ -369,4 +591,4 @@ declare function createNodeListener(api: {
|
|
|
369
591
|
handle(request: Request): Promise<Response>;
|
|
370
592
|
}, options: NodeListenerOptions): (incoming: IncomingMessage, outgoing: ServerResponse) => void;
|
|
371
593
|
|
|
372
|
-
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, type StaffScope, type StripeLike, TERMINAL_SUCCESS_STATUSES, TOKEN_TTL_DAYS, UnverifiedPaymentError, assertStripeTestKey, attemptLegRefund, calendarVisibilityFilter, canSeeAppointmentInScope, canSeeCalendarInScope, createBalanceIntent, createBearerStaffResolver, createMemoryAvailabilityCache, createMemoryCache, createMemoryRateLimiter, createNoBalancePaymentControl, createNoPaymentAdapter, createNodeListener, createSchedulingApi, createScopedVisibility, createSingleOrganizationDirectory, createSingleOrganizationResolver, createStaffContext, createStripePaymentAdapter, decimalToCents, defaultCorsHeaders, getErrorCode, getErrorMessage, getErrorRef, isCalendarVisibleInScope, isSchedulingServiceError, isSupportedCurrency, isTokenExpired, parsePagination, persistRefundOutcome, recordBalanceIntent, runCalendarRemoveWithoutBlocking, runCalendarSyncWithoutBlocking, visibleCalendarIdsInScope };
|
|
594
|
+
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, DnsResolver, HttpMethod, type NodeListenerOptions, type OutlookCalendarSync, type OutlookPullHooks, type OutlookSyncConfig, type Pagination, type PerBusinessSmsAdapter, type PerBusinessSmsOptions, PublicBookingResolver, PublicOrganizationResolver, RETRYABLE_REFUND_STATUSES, RateLimitTier, RefundOutcomePersistenceError, Route, type SchedulingApi, type SchedulingApiConfig, SchedulingCache, SchedulingHost, type SchedulingServiceError, SendingDomainCheck, SendingDomainRecord, SendingDomainRecords, type SendingDomainVerifier, type SendingDomainVerifierConfig, type SignedInPerson, type SmsInboundEvent, SmsSendError, type SmsWebhookResult, StaffContext, type StaffContextInput, StaffResolver, type StaffScope, type StripeLike, TERMINAL_SUCCESS_STATUSES, TOKEN_TTL_DAYS, type TelnyxInboundEvent, SmsSendError as TelnyxSendError, type TelnyxSmsConfig, type TelnyxWebhookOptions, type TelnyxWebhookResult, type TextSettingsResolverOptions, type TwilioSmsConfig, type TwilioWebhookOptions, UnverifiedPaymentError, type WebhookHeaders, assertStripeTestKey, attemptLegRefund, calendarVisibilityFilter, canSeeAppointmentInScope, canSeeCalendarInScope, classifyReply, createBalanceIntent, createBearerStaffResolver, createMemoryAvailabilityCache, createMemoryCache, createMemoryRateLimiter, createNoBalancePaymentControl, createNoPaymentAdapter, createNodeListener, createOutlookCalendarSync, createPerBusinessSmsAdapter, createSchedulingApi, createScopedVisibility, createSendingDomainVerifier, createSingleOrganizationDirectory, createSingleOrganizationResolver, createStaffContext, createStripePaymentAdapter, createTelnyxSmsAdapter, createTextSettingsResolver, createTwilioSmsAdapter, decimalToCents, defaultCorsHeaders, getErrorCode, getErrorMessage, getErrorRef, handleTelnyxWebhook, handleTwilioWebhook, isCalendarVisibleInScope, isSchedulingServiceError, isSupportedCurrency, isTokenExpired, normalizePhoneNumber, parsePagination, persistRefundOutcome, recordBalanceIntent, runCalendarRemoveWithoutBlocking, runCalendarSyncWithoutBlocking, verifyTelnyxSignature, verifyTwilioSignature, visibleCalendarIdsInScope };
|