@ordinatio/scheduling-api 0.7.0 → 0.9.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 +8 -0
- package/README.md +16 -0
- package/dist/agent/index.d.mts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +159 -26
- package/dist/agent/index.mjs +159 -26
- package/dist/{chunk-IW6AN5WE.mjs → chunk-W3SY2DAU.mjs} +37 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +667 -364
- package/dist/index.mjs +341 -71
- package/dist/{routes-LaFljBCF.d.mts → routes-h90wEQuD.d.mts} +25 -1
- package/dist/{routes-LaFljBCF.d.ts → routes-h90wEQuD.d.ts} +25 -1
- package/dist/schemas/index.d.mts +29 -1
- package/dist/schemas/index.d.ts +29 -1
- package/dist/schemas/index.js +40 -0
- package/dist/schemas/index.mjs +9 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ALL_REFUND_STATUSES: () => ALL_REFUND_STATUSES,
|
|
34
|
+
ApiKeySchema: () => ApiKeySchema,
|
|
34
35
|
BALANCE_APPOINTMENT_SELECT: () => BALANCE_APPOINTMENT_SELECT,
|
|
35
36
|
BALANCE_BLOCKED_APPOINTMENT_STATUS: () => BALANCE_BLOCKED_APPOINTMENT_STATUS,
|
|
36
37
|
BALANCE_REQUIRED_PAYMENT_STATUS: () => BALANCE_REQUIRED_PAYMENT_STATUS,
|
|
@@ -54,6 +55,9 @@ __export(index_exports, {
|
|
|
54
55
|
CreateServicePackageSchema: () => CreateServicePackageSchema,
|
|
55
56
|
CreateWebhookEndpointSchema: () => CreateWebhookEndpointSchema,
|
|
56
57
|
DEFAULT_CANCELLATION_POLICY: () => DEFAULT_CANCELLATION_POLICY,
|
|
58
|
+
GiftCertificateCheckSchema: () => GiftCertificateCheckSchema,
|
|
59
|
+
GiftCertificateRestoreSchema: () => GiftCertificateRestoreSchema,
|
|
60
|
+
GiftCertificateSchema: () => GiftCertificateSchema,
|
|
57
61
|
IntakeFormFieldSchema: () => IntakeFormFieldSchema,
|
|
58
62
|
NoShowPreventionActionSchema: () => NoShowPreventionActionSchema,
|
|
59
63
|
NotificationChannelSchema: () => NotificationChannelSchema,
|
|
@@ -85,6 +89,7 @@ __export(index_exports, {
|
|
|
85
89
|
UpdateServicePackageSchema: () => UpdateServicePackageSchema,
|
|
86
90
|
assertStripeTestKey: () => assertStripeTestKey,
|
|
87
91
|
attemptLegRefund: () => attemptLegRefund,
|
|
92
|
+
bearerKeyOf: () => bearerKeyOf,
|
|
88
93
|
calendarVisibilityFilter: () => calendarVisibilityFilter,
|
|
89
94
|
canSeeAppointmentInScope: () => canSeeAppointmentInScope,
|
|
90
95
|
canSeeCalendarInScope: () => canSeeCalendarInScope,
|
|
@@ -148,6 +153,82 @@ function defaultCorsHeaders() {
|
|
|
148
153
|
};
|
|
149
154
|
}
|
|
150
155
|
|
|
156
|
+
// src/api-keys/api-key-host.ts
|
|
157
|
+
var import_scheduling = require("@ordinatio/scheduling");
|
|
158
|
+
|
|
159
|
+
// src/staff/simple-staff.ts
|
|
160
|
+
var DEFAULT_ADMIN_ROLES = ["OWNER", "ADMIN", "MANAGER"];
|
|
161
|
+
function createStaffContext(input) {
|
|
162
|
+
const adminRoles = (input.adminRoles ?? DEFAULT_ADMIN_ROLES).map((role) => role.toUpperCase());
|
|
163
|
+
const { db, organizationId } = input;
|
|
164
|
+
return {
|
|
165
|
+
userId: input.userId,
|
|
166
|
+
organizationId,
|
|
167
|
+
role: input.role,
|
|
168
|
+
isAdmin: adminRoles.includes(input.role.toUpperCase()),
|
|
169
|
+
schedulingEnabled: input.schedulingEnabled ?? true,
|
|
170
|
+
db,
|
|
171
|
+
visibleCalendars: async () => null,
|
|
172
|
+
visibleCalendarIds: async () => void 0,
|
|
173
|
+
canSeeCalendar: async (calendarId) => Boolean(await db.schedulingCalendar.findFirst({ where: { id: calendarId, organizationId }, select: { id: true } })),
|
|
174
|
+
canSeeAppointment: async (appointmentId) => Boolean(await db.appointment.findFirst({ where: { id: appointmentId, calendar: { organizationId } }, select: { id: true } })),
|
|
175
|
+
// The package has no client table, so there is no preference to read.
|
|
176
|
+
preferredLocationOf: async () => null
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
var BEARER = /^bearer\s+(\S+)$/i;
|
|
180
|
+
function createBearerStaffResolver(input) {
|
|
181
|
+
return {
|
|
182
|
+
async resolve(request) {
|
|
183
|
+
const token = BEARER.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
184
|
+
if (!token) return null;
|
|
185
|
+
const person = await input.authenticate(token, request);
|
|
186
|
+
if (!person) return null;
|
|
187
|
+
return createStaffContext({
|
|
188
|
+
...person,
|
|
189
|
+
db: await input.db(person),
|
|
190
|
+
adminRoles: input.adminRoles,
|
|
191
|
+
schedulingEnabled: input.schedulingEnabled ? await input.schedulingEnabled(person) : void 0
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/api-keys/api-key-host.ts
|
|
198
|
+
var API_KEY_ROLE_PREFIX = "API_KEY_";
|
|
199
|
+
var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
200
|
+
function bearerKeyOf(request) {
|
|
201
|
+
const header = request.headers.get("authorization");
|
|
202
|
+
if (!header) return null;
|
|
203
|
+
const match = /^[Bb][Ee][Aa][Rr][Ee][Rr]\s+(osk_\S+)$/.exec(header.trim());
|
|
204
|
+
return match ? match[1] : null;
|
|
205
|
+
}
|
|
206
|
+
function contextOf(key, db, schedulingEnabled) {
|
|
207
|
+
return createStaffContext({
|
|
208
|
+
// The key, not the person who made it, is what the rate limit counts.
|
|
209
|
+
userId: `api-key:${key.id}`,
|
|
210
|
+
organizationId: key.organizationId,
|
|
211
|
+
role: `${API_KEY_ROLE_PREFIX}${key.access}`,
|
|
212
|
+
adminRoles: [`${API_KEY_ROLE_PREFIX}READ`, `${API_KEY_ROLE_PREFIX}FULL`],
|
|
213
|
+
schedulingEnabled,
|
|
214
|
+
db
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async function hostForRequest(host, request, route) {
|
|
218
|
+
if (route.public || !host.apiKeys) return host;
|
|
219
|
+
const secret = bearerKeyOf(request);
|
|
220
|
+
if (secret === null) return host;
|
|
221
|
+
const db = await host.apiKeys.db();
|
|
222
|
+
const key = await (0, import_scheduling.verifyApiKey)(db, secret);
|
|
223
|
+
if (!key) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
224
|
+
if (route.personOnly) return Response.json({ error: "This needs a person signed in at a browser, not an API key" }, { status: 403 });
|
|
225
|
+
if (key.access === "READ" && !SAFE_METHODS.has(request.method.toUpperCase())) {
|
|
226
|
+
return Response.json({ error: "This API key is read-only" }, { status: 403 });
|
|
227
|
+
}
|
|
228
|
+
const context = contextOf(key, db, await host.schedulingEnabledFor(key.organizationId));
|
|
229
|
+
return { ...host, staff: { resolve: async () => context } };
|
|
230
|
+
}
|
|
231
|
+
|
|
151
232
|
// src/availability/memory-availability-cache.ts
|
|
152
233
|
var TTL_MS = 6e4;
|
|
153
234
|
var DEFAULT_MAX_ENTRIES = 2e3;
|
|
@@ -331,7 +412,7 @@ function createUnconfiguredConnector(provider) {
|
|
|
331
412
|
}
|
|
332
413
|
|
|
333
414
|
// src/webhooks/webhook-events.ts
|
|
334
|
-
var
|
|
415
|
+
var import_scheduling2 = require("@ordinatio/scheduling");
|
|
335
416
|
var WEBHOOK_EVENT_FOR = {
|
|
336
417
|
"appointment.created": "appointment.booked",
|
|
337
418
|
"appointment.updated": "appointment.rescheduled",
|
|
@@ -348,7 +429,7 @@ function withWebhooks(inner, host) {
|
|
|
348
429
|
if (host.webhooks && webhookType && typeof appointmentId === "string") {
|
|
349
430
|
try {
|
|
350
431
|
const db = await host.tenantDb(organizationId, "webhooks");
|
|
351
|
-
if (db) await (0,
|
|
432
|
+
if (db) await (0, import_scheduling2.enqueueAppointmentWebhook)(db, { organizationId, type: webhookType, appointmentId });
|
|
352
433
|
} catch (error) {
|
|
353
434
|
console.error("[scheduling-api] could not reach the database to queue a webhook:", error);
|
|
354
435
|
}
|
|
@@ -359,9 +440,9 @@ function withWebhooks(inner, host) {
|
|
|
359
440
|
}
|
|
360
441
|
|
|
361
442
|
// src/waitlist/announce-offer.ts
|
|
362
|
-
var
|
|
443
|
+
var import_scheduling3 = require("@ordinatio/scheduling");
|
|
363
444
|
async function offerAndAnnounce(host, settings, db, slot) {
|
|
364
|
-
const offer = await (0,
|
|
445
|
+
const offer = await (0, import_scheduling3.tryOfferFreedSlot)(db, { ...slot, offerMinutes: settings.offerMinutes });
|
|
365
446
|
if (!offer) return false;
|
|
366
447
|
const details = {
|
|
367
448
|
organizationId: slot.organizationId,
|
|
@@ -384,7 +465,7 @@ async function offerAndAnnounce(host, settings, db, slot) {
|
|
|
384
465
|
}
|
|
385
466
|
if (host.webhooks) {
|
|
386
467
|
try {
|
|
387
|
-
await (0,
|
|
468
|
+
await (0, import_scheduling3.enqueueWebhookEvent)(db, {
|
|
388
469
|
organizationId: slot.organizationId,
|
|
389
470
|
type: "waitlist.offered",
|
|
390
471
|
// Each offering has its own id, so offering the same slot to the same person again still reaches subscribers.
|
|
@@ -438,7 +519,7 @@ function withWaitlist(inner, host) {
|
|
|
438
519
|
}
|
|
439
520
|
|
|
440
521
|
// src/handlers/manage-cancel.ts
|
|
441
|
-
var
|
|
522
|
+
var import_scheduling7 = require("@ordinatio/scheduling");
|
|
442
523
|
|
|
443
524
|
// src/client-address.ts
|
|
444
525
|
function forwardedAddress(request) {
|
|
@@ -449,7 +530,7 @@ function clientAddress(request) {
|
|
|
449
530
|
}
|
|
450
531
|
|
|
451
532
|
// src/error-guards.ts
|
|
452
|
-
var
|
|
533
|
+
var import_scheduling4 = require("@ordinatio/scheduling");
|
|
453
534
|
function getErrorCode(error) {
|
|
454
535
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
455
536
|
const code = error.code;
|
|
@@ -476,20 +557,20 @@ function getErrorMessage(error, fallback) {
|
|
|
476
557
|
return fallback;
|
|
477
558
|
}
|
|
478
559
|
function schedErrorStatus(code) {
|
|
479
|
-
return
|
|
560
|
+
return import_scheduling4.SCHEDULING_ERRORS[code]?.httpStatus ?? 400;
|
|
480
561
|
}
|
|
481
562
|
|
|
482
563
|
// src/manage/cancel-via-token.ts
|
|
483
|
-
var
|
|
564
|
+
var import_scheduling6 = require("@ordinatio/scheduling");
|
|
484
565
|
|
|
485
566
|
// src/calendar-sync.ts
|
|
486
|
-
var
|
|
567
|
+
var import_scheduling5 = require("@ordinatio/scheduling");
|
|
487
568
|
async function runWithoutBlocking(code, appointmentId, step, recordFailure) {
|
|
488
569
|
try {
|
|
489
570
|
await step();
|
|
490
571
|
return { queued: true };
|
|
491
572
|
} catch (error) {
|
|
492
|
-
const diagnostic = (0,
|
|
573
|
+
const diagnostic = (0, import_scheduling5.schedError)(code, { error, appointmentId });
|
|
493
574
|
console.error("[calendar-sync]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
494
575
|
try {
|
|
495
576
|
await recordFailure?.(diagnostic.ref);
|
|
@@ -509,7 +590,7 @@ function runCalendarRemoveWithoutBlocking(sync, ref, recordFailure) {
|
|
|
509
590
|
// src/manage/cancel-via-token.ts
|
|
510
591
|
async function cancelViaToken(host, db, organizationId, appointment) {
|
|
511
592
|
const hasPayment = !!(appointment.paymentId && (appointment.paymentStatus === "PAID" || appointment.paymentStatus === "DEPOSIT_PAID"));
|
|
512
|
-
await (0,
|
|
593
|
+
await (0, import_scheduling6.cancelAppointment)(db, {
|
|
513
594
|
appointmentId: appointment.id,
|
|
514
595
|
cancelledBy: "client",
|
|
515
596
|
reason: "Cancelled via self-service link"
|
|
@@ -520,7 +601,7 @@ async function cancelViaToken(host, db, organizationId, appointment) {
|
|
|
520
601
|
data: { refundStatus: hasPayment ? "PENDING_REVIEW" : "NO_PAYMENT" }
|
|
521
602
|
});
|
|
522
603
|
} catch (refundStatusError) {
|
|
523
|
-
const diagnostic = (0,
|
|
604
|
+
const diagnostic = (0, import_scheduling6.schedError)("SCHED_602", {
|
|
524
605
|
error: refundStatusError,
|
|
525
606
|
appointmentId: appointment.id,
|
|
526
607
|
context: "refundStatus write failed after cancellation already committed",
|
|
@@ -565,9 +646,9 @@ async function cancelViaToken(host, db, organizationId, appointment) {
|
|
|
565
646
|
const baseUrl = host.appUrl();
|
|
566
647
|
if (baseUrl) {
|
|
567
648
|
try {
|
|
568
|
-
await (0,
|
|
649
|
+
await (0, import_scheduling6.queueStaffNotification)(db, appointment.id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
|
|
569
650
|
} catch (staffError) {
|
|
570
|
-
const diagnostic = (0,
|
|
651
|
+
const diagnostic = (0, import_scheduling6.schedError)("SCHED_607", { error: staffError, appointmentId: appointment.id });
|
|
571
652
|
console.error("[DELETE /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
|
|
572
653
|
}
|
|
573
654
|
}
|
|
@@ -641,14 +722,14 @@ async function cancelManagedAppointment(request, { host }) {
|
|
|
641
722
|
{ status: 409 }
|
|
642
723
|
);
|
|
643
724
|
}
|
|
644
|
-
const diagnostic = (0,
|
|
725
|
+
const diagnostic = (0, import_scheduling7.schedError)("SCHED_602", { error, token: token ?? "unknown", appointmentId });
|
|
645
726
|
console.error("[DELETE /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
646
727
|
return Response.json({ error: "Failed to cancel", ref: diagnostic.ref }, { status: 500 });
|
|
647
728
|
}
|
|
648
729
|
}
|
|
649
730
|
|
|
650
731
|
// src/handlers/manage-get.ts
|
|
651
|
-
var
|
|
732
|
+
var import_scheduling8 = require("@ordinatio/scheduling");
|
|
652
733
|
async function getManagedAppointment(request, { host }) {
|
|
653
734
|
let token = null;
|
|
654
735
|
try {
|
|
@@ -682,24 +763,24 @@ async function getManagedAppointment(request, { host }) {
|
|
|
682
763
|
staffName: appointment.calendar.staffName,
|
|
683
764
|
calendarId: appointment.calendarId,
|
|
684
765
|
allowReschedule: appointment.type.allowReschedule,
|
|
685
|
-
location: (0,
|
|
766
|
+
location: (0, import_scheduling8.resolveLocation)(appointment),
|
|
686
767
|
meetingUrl: appointment.meetingUrl ?? null,
|
|
687
768
|
theme: appointment.calendar.theme ?? null
|
|
688
769
|
});
|
|
689
770
|
} catch (error) {
|
|
690
|
-
const diagnostic = (0,
|
|
771
|
+
const diagnostic = (0, import_scheduling8.schedError)("SCHED_601", { error, token: token ?? "unknown" });
|
|
691
772
|
console.error("[GET /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
692
773
|
return Response.json({ error: "Failed to fetch appointment", ref: diagnostic.ref }, { status: 500 });
|
|
693
774
|
}
|
|
694
775
|
}
|
|
695
776
|
|
|
696
777
|
// src/handlers/manage-reschedule.ts
|
|
697
|
-
var
|
|
778
|
+
var import_scheduling10 = require("@ordinatio/scheduling");
|
|
698
779
|
|
|
699
780
|
// src/manage/reschedule-via-token.ts
|
|
700
|
-
var
|
|
781
|
+
var import_scheduling9 = require("@ordinatio/scheduling");
|
|
701
782
|
async function rescheduleViaToken(host, db, organizationId, appointment, newTime) {
|
|
702
|
-
const result = await (0,
|
|
783
|
+
const result = await (0, import_scheduling9.rescheduleAppointment)(db, {
|
|
703
784
|
appointmentId: appointment.id,
|
|
704
785
|
newStartTime: newTime,
|
|
705
786
|
reason: "Rescheduled via self-service link"
|
|
@@ -724,21 +805,21 @@ async function rescheduleViaToken(host, db, organizationId, appointment, newTime
|
|
|
724
805
|
);
|
|
725
806
|
const baseUrl = host.appUrl() ?? void 0;
|
|
726
807
|
if (baseUrl) {
|
|
727
|
-
await (0,
|
|
808
|
+
await (0, import_scheduling9.queueImmediateNotification)(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
728
809
|
} else {
|
|
729
810
|
console.warn("[manage] no appUrl \u2014 RESCHEDULE notification skipped");
|
|
730
811
|
}
|
|
731
812
|
try {
|
|
732
|
-
await (0,
|
|
813
|
+
await (0, import_scheduling9.scheduleNotifications)(db, appointment.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
733
814
|
} catch (error) {
|
|
734
|
-
const diagnostic = (0,
|
|
815
|
+
const diagnostic = (0, import_scheduling9.schedError)("SCHED_604", { error, appointmentId: appointment.id });
|
|
735
816
|
console.error("[PATCH /manage] scheduleNotifications failed (non-blocking):", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
736
817
|
}
|
|
737
818
|
if (baseUrl) {
|
|
738
819
|
try {
|
|
739
|
-
await (0,
|
|
820
|
+
await (0, import_scheduling9.queueStaffNotification)(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
740
821
|
} catch (staffError) {
|
|
741
|
-
const diagnostic = (0,
|
|
822
|
+
const diagnostic = (0, import_scheduling9.schedError)("SCHED_607", { error: staffError, appointmentId: appointment.id });
|
|
742
823
|
console.error("[PATCH /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
|
|
743
824
|
}
|
|
744
825
|
}
|
|
@@ -797,7 +878,7 @@ async function rescheduleManagedAppointment(request, { host }) {
|
|
|
797
878
|
if (target instanceof Response) return target;
|
|
798
879
|
return await rescheduleViaToken(host, target.db, target.organizationId, appointment, newTime);
|
|
799
880
|
} catch (error) {
|
|
800
|
-
if (error instanceof
|
|
881
|
+
if (error instanceof import_scheduling10.SchedulingValidationError) {
|
|
801
882
|
return Response.json({ error: error.message, ref: error.ref }, { status: 400 });
|
|
802
883
|
}
|
|
803
884
|
const code = getErrorCode(error);
|
|
@@ -816,14 +897,14 @@ async function rescheduleManagedAppointment(request, { host }) {
|
|
|
816
897
|
console.error("[PATCH /manage]", ref, "SCHED_306", error);
|
|
817
898
|
return Response.json({ error: "Appointment status prevents rescheduling", ...ref && { ref } }, { status: 400 });
|
|
818
899
|
}
|
|
819
|
-
const diagnostic = (0,
|
|
900
|
+
const diagnostic = (0, import_scheduling10.schedError)("SCHED_603", { error, token: token ?? "unknown", appointmentId });
|
|
820
901
|
console.error("[PATCH /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
821
902
|
return Response.json({ error: "Failed to reschedule", ref: diagnostic.ref }, { status: 500 });
|
|
822
903
|
}
|
|
823
904
|
}
|
|
824
905
|
|
|
825
906
|
// src/handlers/capacity.ts
|
|
826
|
-
var
|
|
907
|
+
var import_scheduling11 = require("@ordinatio/scheduling");
|
|
827
908
|
|
|
828
909
|
// src/respond.ts
|
|
829
910
|
var WIDGET_CACHE_HEADERS = {
|
|
@@ -870,7 +951,7 @@ async function getCapacity(request, { host }) {
|
|
|
870
951
|
select: { isGroup: true }
|
|
871
952
|
});
|
|
872
953
|
if (!type || !type.isGroup) return corsJson(cors, NOT_FOUND, { status: 404 });
|
|
873
|
-
return corsJson(cors, await (0,
|
|
954
|
+
return corsJson(cors, await (0, import_scheduling11.getGroupCapacity)(db, { typeId, calendarId, startTime }));
|
|
874
955
|
} catch (error) {
|
|
875
956
|
console.error("[group-capacity] unexpected error:", error instanceof Error ? error.message : error);
|
|
876
957
|
return corsJson(cors, { error: "Failed to fetch capacity" }, { status: 500 });
|
|
@@ -878,7 +959,7 @@ async function getCapacity(request, { host }) {
|
|
|
878
959
|
}
|
|
879
960
|
|
|
880
961
|
// src/handlers/payment-intent.ts
|
|
881
|
-
var
|
|
962
|
+
var import_scheduling12 = require("@ordinatio/scheduling");
|
|
882
963
|
var import_zod = require("zod");
|
|
883
964
|
|
|
884
965
|
// src/payments/create-payment-intent.ts
|
|
@@ -994,7 +1075,7 @@ async function createPaymentIntentRoute(request, { host }) {
|
|
|
994
1075
|
if (!result.ok) return corsJson(cors, { error: result.error }, { status: result.status });
|
|
995
1076
|
return corsJson(cors, result.body, { status: result.status });
|
|
996
1077
|
} catch (error) {
|
|
997
|
-
const err = (0,
|
|
1078
|
+
const err = (0, import_scheduling12.schedError)("SCHED_407", {
|
|
998
1079
|
typeId,
|
|
999
1080
|
calendarId,
|
|
1000
1081
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -1005,7 +1086,7 @@ async function createPaymentIntentRoute(request, { host }) {
|
|
|
1005
1086
|
}
|
|
1006
1087
|
|
|
1007
1088
|
// src/handlers/appointment-cancel.ts
|
|
1008
|
-
var
|
|
1089
|
+
var import_scheduling14 = require("@ordinatio/scheduling");
|
|
1009
1090
|
|
|
1010
1091
|
// src/appointments/owned-appointment.ts
|
|
1011
1092
|
async function verifyAppointmentOwnership(db, appointmentId, organizationId) {
|
|
@@ -1058,7 +1139,7 @@ async function writeRefundStatusAfterCancel(host, db, input) {
|
|
|
1058
1139
|
}
|
|
1059
1140
|
|
|
1060
1141
|
// src/staff/require-staff.ts
|
|
1061
|
-
var
|
|
1142
|
+
var import_scheduling13 = require("@ordinatio/scheduling");
|
|
1062
1143
|
async function requireAdminStaff(host, request, options) {
|
|
1063
1144
|
const staff = await host.staff.resolve(request);
|
|
1064
1145
|
if (!staff) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
@@ -1067,7 +1148,7 @@ async function requireAdminStaff(host, request, options) {
|
|
|
1067
1148
|
if (limited) return limited;
|
|
1068
1149
|
}
|
|
1069
1150
|
if (!staff.isAdmin && !options.allowAnyRole) {
|
|
1070
|
-
const err = (0,
|
|
1151
|
+
const err = (0, import_scheduling13.schedError)("SCHED_900", { userId: staff.userId, role: staff.role });
|
|
1071
1152
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
1072
1153
|
}
|
|
1073
1154
|
if (!staff.schedulingEnabled && !options.ignoreSchedulingSwitch) {
|
|
@@ -1110,7 +1191,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1110
1191
|
const appointment = await verifyAppointmentOwnership(db, id, organizationId);
|
|
1111
1192
|
if (!appointment) return Response.json({ error: "Appointment not found" }, { status: 404 });
|
|
1112
1193
|
const hasPayment = hasPendingPayment(appointment.paymentId, appointment.paymentStatus);
|
|
1113
|
-
const result = await (0,
|
|
1194
|
+
const result = await (0, import_scheduling14.cancelAppointment)(db, { appointmentId: id, cancelledBy: "staff", reason });
|
|
1114
1195
|
await writeRefundStatusAfterCancel(host, db, { appointmentId: id, hasPayment, clientName: appointment.clientName });
|
|
1115
1196
|
if (hasPayment) {
|
|
1116
1197
|
await host.activity.log(db, {
|
|
@@ -1130,7 +1211,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1130
1211
|
const baseUrl = host.appUrl();
|
|
1131
1212
|
if (baseUrl) {
|
|
1132
1213
|
try {
|
|
1133
|
-
await (0,
|
|
1214
|
+
await (0, import_scheduling14.queueStaffNotification)(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
|
|
1134
1215
|
} catch (error) {
|
|
1135
1216
|
await host.activity.log(db, {
|
|
1136
1217
|
action: "scheduling.staff_notification_failed",
|
|
@@ -1157,7 +1238,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1157
1238
|
});
|
|
1158
1239
|
return Response.json(withoutManageToken(result));
|
|
1159
1240
|
} catch (error) {
|
|
1160
|
-
if (error instanceof
|
|
1241
|
+
if (error instanceof import_scheduling14.SchedulingNotFoundError) {
|
|
1161
1242
|
return Response.json({ error: error.message, ref: error.ref }, { status: 404 });
|
|
1162
1243
|
}
|
|
1163
1244
|
const ref = getErrorRef(error);
|
|
@@ -1362,7 +1443,7 @@ function finishOutlookConnection(request, { host }) {
|
|
|
1362
1443
|
}
|
|
1363
1444
|
|
|
1364
1445
|
// src/handlers/appointment-cancel-sync.ts
|
|
1365
|
-
var
|
|
1446
|
+
var import_scheduling15 = require("@ordinatio/scheduling");
|
|
1366
1447
|
var import_zod2 = require("zod");
|
|
1367
1448
|
var Schema2 = import_zod2.z.object({
|
|
1368
1449
|
source: import_zod2.z.enum(["google", "outlook"]),
|
|
@@ -1405,13 +1486,13 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1405
1486
|
return Response.json({ error: "Appointment not available for sync" }, { status: 503 });
|
|
1406
1487
|
}
|
|
1407
1488
|
try {
|
|
1408
|
-
await (0,
|
|
1489
|
+
await (0, import_scheduling15.cancelAppointment)(db, {
|
|
1409
1490
|
appointmentId: id,
|
|
1410
1491
|
cancelledBy: "system",
|
|
1411
1492
|
reason: reason ?? `Cancelled via ${source === "google" ? "Google" : "Outlook"} Calendar`
|
|
1412
1493
|
});
|
|
1413
1494
|
} catch (error) {
|
|
1414
|
-
if (error instanceof
|
|
1495
|
+
if (error instanceof import_scheduling15.SchedulingNotFoundError) {
|
|
1415
1496
|
return Response.json({ error: "Appointment not found", ref: error.ref }, { status: 404 });
|
|
1416
1497
|
}
|
|
1417
1498
|
const ref = getErrorRef(error);
|
|
@@ -1445,7 +1526,7 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1445
1526
|
await host.workerCommands.queue(source === "google" ? "delete-from-outlook" : "delete-from-google", { appointmentId: id });
|
|
1446
1527
|
const baseUrl = host.appUrl();
|
|
1447
1528
|
if (baseUrl) {
|
|
1448
|
-
await (0,
|
|
1529
|
+
await (0, import_scheduling15.queueImmediateNotification)(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }).catch(
|
|
1449
1530
|
(err) => console.warn("[cancel-sync] Failed to queue cancellation notification:", id, err instanceof Error ? err.message : err)
|
|
1450
1531
|
);
|
|
1451
1532
|
}
|
|
@@ -1458,10 +1539,10 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1458
1539
|
}
|
|
1459
1540
|
|
|
1460
1541
|
// src/handlers/appointment-approve.ts
|
|
1461
|
-
var
|
|
1542
|
+
var import_scheduling16 = require("@ordinatio/scheduling");
|
|
1462
1543
|
async function rejectAppointment(host, db, organizationId, appointment, reason) {
|
|
1463
1544
|
const { id } = appointment;
|
|
1464
|
-
const result = await (0,
|
|
1545
|
+
const result = await (0, import_scheduling16.cancelAppointment)(db, {
|
|
1465
1546
|
appointmentId: id,
|
|
1466
1547
|
cancelledBy: "staff",
|
|
1467
1548
|
reason: reason || "Appointment request rejected"
|
|
@@ -1543,10 +1624,10 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1543
1624
|
if (confirmed.count === 0) {
|
|
1544
1625
|
return Response.json({ error: "Appointment was already processed by a concurrent request" }, { status: 409 });
|
|
1545
1626
|
}
|
|
1546
|
-
await (0,
|
|
1627
|
+
await (0, import_scheduling16.cancelPendingNotifications)(db, id);
|
|
1547
1628
|
const baseUrl = host.appUrl();
|
|
1548
1629
|
if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
|
|
1549
|
-
await (0,
|
|
1630
|
+
await (0, import_scheduling16.scheduleNotifications)(db, id, baseUrl, { brand: Boolean(host.brand) });
|
|
1550
1631
|
await host.availabilityCache.invalidate(appointment.calendarId);
|
|
1551
1632
|
await host.events.emit(organizationId, "appointment.confirmed", { appointmentId: id });
|
|
1552
1633
|
await host.activity.log(db, {
|
|
@@ -1554,7 +1635,7 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1554
1635
|
description: `approved ${appointment.clientName}'s appointment`,
|
|
1555
1636
|
metadata: { appointmentId: id, clientName: appointment.clientName }
|
|
1556
1637
|
});
|
|
1557
|
-
const confirmedAppointment = await (0,
|
|
1638
|
+
const confirmedAppointment = await (0, import_scheduling16.getAppointment)(db, id);
|
|
1558
1639
|
return Response.json({ success: true, status: "CONFIRMED", appointment: withoutManageToken(confirmedAppointment) });
|
|
1559
1640
|
} catch (error) {
|
|
1560
1641
|
if (getErrorCode(error) === "SCHED_306") {
|
|
@@ -1567,7 +1648,7 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1567
1648
|
}
|
|
1568
1649
|
|
|
1569
1650
|
// src/handlers/appointment-reschedule.ts
|
|
1570
|
-
var
|
|
1651
|
+
var import_scheduling17 = require("@ordinatio/scheduling");
|
|
1571
1652
|
var RESCHEDULE_BLOCKER_CODES = ["SCHED_301", "SCHED_307", "SCHED_309", "SCHED_802"];
|
|
1572
1653
|
async function rescheduleByStaff(request, { host, params }) {
|
|
1573
1654
|
try {
|
|
@@ -1595,21 +1676,21 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1595
1676
|
if (newTime < /* @__PURE__ */ new Date()) {
|
|
1596
1677
|
return Response.json({ error: "Cannot reschedule to a past time" }, { status: 400 });
|
|
1597
1678
|
}
|
|
1598
|
-
const result = await (0,
|
|
1679
|
+
const result = await (0, import_scheduling17.rescheduleAppointment)(db, {
|
|
1599
1680
|
appointmentId: id,
|
|
1600
1681
|
newStartTime: newTime,
|
|
1601
1682
|
reason: "Rescheduled via calendar drag"
|
|
1602
1683
|
});
|
|
1603
1684
|
const baseUrl = host.appUrl();
|
|
1604
1685
|
if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
|
|
1605
|
-
await (0,
|
|
1686
|
+
await (0, import_scheduling17.queueImmediateNotification)(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
1606
1687
|
try {
|
|
1607
|
-
await (0,
|
|
1688
|
+
await (0, import_scheduling17.scheduleNotifications)(db, id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
1608
1689
|
} catch (error) {
|
|
1609
1690
|
console.warn("[reschedule] scheduleNotifications failed:", error instanceof Error ? error.message : error);
|
|
1610
1691
|
}
|
|
1611
1692
|
try {
|
|
1612
|
-
await (0,
|
|
1693
|
+
await (0, import_scheduling17.queueStaffNotification)(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
1613
1694
|
} catch (error) {
|
|
1614
1695
|
await host.activity.log(db, {
|
|
1615
1696
|
action: "scheduling.staff_notification_failed",
|
|
@@ -1647,8 +1728,8 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1647
1728
|
});
|
|
1648
1729
|
return Response.json(withoutManageToken(result));
|
|
1649
1730
|
} catch (error) {
|
|
1650
|
-
if (error instanceof
|
|
1651
|
-
if (error instanceof
|
|
1731
|
+
if (error instanceof import_scheduling17.SchedulingValidationError) return Response.json({ error: error.message }, { status: 400 });
|
|
1732
|
+
if (error instanceof import_scheduling17.SchedulingNotFoundError) return Response.json({ error: error.message }, { status: 404 });
|
|
1652
1733
|
const errorCode = getErrorCode(error) ?? "";
|
|
1653
1734
|
const status = errorCode === "SCHED_306" ? 400 : RESCHEDULE_BLOCKER_CODES.includes(errorCode) ? 409 : 500;
|
|
1654
1735
|
return Response.json({ error: getErrorMessage(error, "Failed to reschedule") }, { status });
|
|
@@ -1656,7 +1737,7 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1656
1737
|
}
|
|
1657
1738
|
|
|
1658
1739
|
// src/handlers/appointment-reassign.ts
|
|
1659
|
-
var
|
|
1740
|
+
var import_scheduling18 = require("@ordinatio/scheduling");
|
|
1660
1741
|
var import_zod3 = require("zod");
|
|
1661
1742
|
var REASSIGNABLE_STATUSES = ["PENDING", "CONFIRMED"];
|
|
1662
1743
|
var REASSIGN_MAX_ATTEMPTS = 2;
|
|
@@ -1707,7 +1788,7 @@ async function reassignAppointment(request, { host, params }) {
|
|
|
1707
1788
|
if (!current || !REASSIGNABLE_STATUSES.includes(current.status)) {
|
|
1708
1789
|
return { outcome: "statusChanged", currentStatus: current?.status ?? "unknown" };
|
|
1709
1790
|
}
|
|
1710
|
-
const available = await (0,
|
|
1791
|
+
const available = await (0, import_scheduling18.isSlotAvailable)(txDb, calendarId, current.startTime, current.duration, id);
|
|
1711
1792
|
if (!available) return { outcome: "conflict" };
|
|
1712
1793
|
const updated2 = await tx.appointment.update({
|
|
1713
1794
|
where: { id, status: { in: [...REASSIGNABLE_STATUSES] } },
|
|
@@ -1733,14 +1814,14 @@ async function reassignAppointment(request, { host, params }) {
|
|
|
1733
1814
|
};
|
|
1734
1815
|
const result = await attemptReassign();
|
|
1735
1816
|
if (result.outcome === "statusChanged") {
|
|
1736
|
-
const diagnostic = (0,
|
|
1817
|
+
const diagnostic = (0, import_scheduling18.schedError)("SCHED_309", { appointmentId: id, calendarId, currentStatus: result.currentStatus });
|
|
1737
1818
|
return Response.json(
|
|
1738
1819
|
{ error: "Appointment status changed before the reassignment could commit", ref: diagnostic.ref },
|
|
1739
1820
|
{ status: 409 }
|
|
1740
1821
|
);
|
|
1741
1822
|
}
|
|
1742
1823
|
if (result.outcome === "conflict") {
|
|
1743
|
-
const diagnostic = (0,
|
|
1824
|
+
const diagnostic = (0, import_scheduling18.schedError)("SCHED_301", { appointmentId: id, calendarId });
|
|
1744
1825
|
return Response.json(
|
|
1745
1826
|
{ error: "Target calendar is not available at this appointment's time", ref: diagnostic.ref },
|
|
1746
1827
|
{ status: 409 }
|
|
@@ -1903,7 +1984,7 @@ async function listNotifications(request, { host, params }) {
|
|
|
1903
1984
|
}
|
|
1904
1985
|
|
|
1905
1986
|
// src/handlers/appointment-no-show.ts
|
|
1906
|
-
var
|
|
1987
|
+
var import_scheduling19 = require("@ordinatio/scheduling");
|
|
1907
1988
|
async function markAppointmentNoShow(request, { host, params }) {
|
|
1908
1989
|
try {
|
|
1909
1990
|
const staff = await requireAdminStaff(host, request, {
|
|
@@ -1920,7 +2001,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1920
2001
|
}
|
|
1921
2002
|
const appointment = await verifyAppointmentOwnership(db, id, organizationId);
|
|
1922
2003
|
if (!appointment) return Response.json({ error: "Appointment not found" }, { status: 404 });
|
|
1923
|
-
const result = await (0,
|
|
2004
|
+
const result = await (0, import_scheduling19.markNoShow)(db, { appointmentId: id });
|
|
1924
2005
|
await host.events.emit(organizationId, "appointment.no_show", { appointmentId: id });
|
|
1925
2006
|
await host.activity.log(db, {
|
|
1926
2007
|
action: "scheduling.appointment_no_show",
|
|
@@ -1929,7 +2010,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1929
2010
|
});
|
|
1930
2011
|
return Response.json(withoutManageToken(result));
|
|
1931
2012
|
} catch (error) {
|
|
1932
|
-
if (error instanceof
|
|
2013
|
+
if (error instanceof import_scheduling19.SchedulingNotFoundError) {
|
|
1933
2014
|
return Response.json({ error: error.message, ref: error.ref }, { status: 404 });
|
|
1934
2015
|
}
|
|
1935
2016
|
const ref = getErrorRef(error);
|
|
@@ -1939,7 +2020,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1939
2020
|
}
|
|
1940
2021
|
|
|
1941
2022
|
// src/handlers/appointment-collect-balance.ts
|
|
1942
|
-
var
|
|
2023
|
+
var import_scheduling22 = require("@ordinatio/scheduling");
|
|
1943
2024
|
|
|
1944
2025
|
// src/payments/balance/eligibility.ts
|
|
1945
2026
|
var BALANCE_BLOCKED_APPOINTMENT_STATUS = "CANCELLED";
|
|
@@ -2035,7 +2116,7 @@ function resolveBalanceEligibility(appointment, organizationId) {
|
|
|
2035
2116
|
}
|
|
2036
2117
|
|
|
2037
2118
|
// src/payments/balance/record-intent.ts
|
|
2038
|
-
var
|
|
2119
|
+
var import_scheduling20 = require("@ordinatio/scheduling");
|
|
2039
2120
|
var BALANCE_OUTCOME_TRACE = {
|
|
2040
2121
|
cancelled: {
|
|
2041
2122
|
action: "scheduling.balance_intent_cancelled",
|
|
@@ -2078,7 +2159,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2078
2159
|
data: { balancePaymentId: intentId }
|
|
2079
2160
|
});
|
|
2080
2161
|
} catch (writeError) {
|
|
2081
|
-
const diagnostic = (0,
|
|
2162
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2082
2163
|
error: writeError,
|
|
2083
2164
|
appointmentId,
|
|
2084
2165
|
paymentIntentId: intentId,
|
|
@@ -2100,7 +2181,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2100
2181
|
select: { balancePaymentId: true, status: true, refundStatus: true, paymentStatus: true }
|
|
2101
2182
|
});
|
|
2102
2183
|
} catch (rereadError) {
|
|
2103
|
-
const diagnostic = (0,
|
|
2184
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2104
2185
|
error: rereadError,
|
|
2105
2186
|
appointmentId,
|
|
2106
2187
|
paymentIntentId: intentId,
|
|
@@ -2117,7 +2198,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2117
2198
|
const stillEligible = current !== null && !isBalanceBlockedByStatus(current.status) && !hasBalanceRefundStarted(current.refundStatus);
|
|
2118
2199
|
if (current?.balancePaymentId === intentId) {
|
|
2119
2200
|
if (stillEligible) return { ok: true };
|
|
2120
|
-
const diagnostic = (0,
|
|
2201
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2121
2202
|
appointmentId,
|
|
2122
2203
|
paymentIntentId: intentId,
|
|
2123
2204
|
status: current.status,
|
|
@@ -2159,7 +2240,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2159
2240
|
outcome = "cancel-failed";
|
|
2160
2241
|
}
|
|
2161
2242
|
if (outcome !== cancelledOutcome) {
|
|
2162
|
-
const diagnostic = (0,
|
|
2243
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2163
2244
|
error: cancelError,
|
|
2164
2245
|
appointmentId,
|
|
2165
2246
|
paymentIntentId: intentId,
|
|
@@ -2207,7 +2288,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2207
2288
|
}
|
|
2208
2289
|
|
|
2209
2290
|
// src/payments/balance/create-intent.ts
|
|
2210
|
-
var
|
|
2291
|
+
var import_scheduling21 = require("@ordinatio/scheduling");
|
|
2211
2292
|
|
|
2212
2293
|
// src/payments/unverified-payment-error.ts
|
|
2213
2294
|
var UnverifiedPaymentError = class extends Error {
|
|
@@ -2253,7 +2334,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2253
2334
|
});
|
|
2254
2335
|
} catch (error) {
|
|
2255
2336
|
if (error instanceof UnverifiedPaymentError) {
|
|
2256
|
-
const diagnostic2 = (0,
|
|
2337
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2257
2338
|
error,
|
|
2258
2339
|
appointmentId,
|
|
2259
2340
|
paymentIntentId: error.paymentId,
|
|
@@ -2273,7 +2354,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2273
2354
|
return { paymentId: result.paymentId, clientSecret: result.clientSecret ?? null };
|
|
2274
2355
|
}
|
|
2275
2356
|
if (result.code === "IN_PROGRESS") {
|
|
2276
|
-
const diagnostic2 = (0,
|
|
2357
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2277
2358
|
error: result.error,
|
|
2278
2359
|
appointmentId,
|
|
2279
2360
|
key,
|
|
@@ -2283,7 +2364,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2283
2364
|
throw new BalanceRequestInProgressError(diagnostic2.ref);
|
|
2284
2365
|
}
|
|
2285
2366
|
if (result.code === "KEY_REUSED") {
|
|
2286
|
-
const diagnostic2 = (0,
|
|
2367
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2287
2368
|
error: result.error,
|
|
2288
2369
|
appointmentId,
|
|
2289
2370
|
abandonedKey: key,
|
|
@@ -2299,7 +2380,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2299
2380
|
if (result.code === "CANCELED") continue;
|
|
2300
2381
|
throw new Error(result.error ?? "The payment provider did not create the balance payment");
|
|
2301
2382
|
}
|
|
2302
|
-
const diagnostic = (0,
|
|
2383
|
+
const diagnostic = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2303
2384
|
appointmentId,
|
|
2304
2385
|
phase: "balance-key-generations-exhausted",
|
|
2305
2386
|
generations: MAX_KEY_GENERATIONS2
|
|
@@ -2391,7 +2472,7 @@ async function collectAppointmentBalance(request, { host, params }) {
|
|
|
2391
2472
|
if (error instanceof BalanceRequestInProgressError || error instanceof BalanceIntentGenerationsExhaustedError) {
|
|
2392
2473
|
return Response.json({ error: error.message, ref: error.ref }, { status: 409 });
|
|
2393
2474
|
}
|
|
2394
|
-
const diagnostic = (0,
|
|
2475
|
+
const diagnostic = (0, import_scheduling22.schedError)("SCHED_605", { error, appointmentId });
|
|
2395
2476
|
console.error("[POST /collect-balance]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
2396
2477
|
return Response.json({ error: "Failed to create balance payment", ref: diagnostic.ref }, { status: 500 });
|
|
2397
2478
|
}
|
|
@@ -2401,7 +2482,7 @@ async function collectAppointmentBalance(request, { host, params }) {
|
|
|
2401
2482
|
var import_zod6 = require("zod");
|
|
2402
2483
|
|
|
2403
2484
|
// src/payments/refund/refund-status.ts
|
|
2404
|
-
var
|
|
2485
|
+
var import_scheduling23 = require("@ordinatio/scheduling");
|
|
2405
2486
|
var REFUND_STATUS_BUCKET = {
|
|
2406
2487
|
PENDING_REVIEW: "retryable",
|
|
2407
2488
|
REFUND_FAILED: "retryable",
|
|
@@ -2423,7 +2504,7 @@ var CREDIT_REFUSED_NEXT_STEP = "Retry the refund to resolve the remaining balanc
|
|
|
2423
2504
|
var CREDIT_REFUSED_NO_AMOUNT_NEXT_STEP = "Check the refunded amount in Stripe, then retry the refund or resolve this manually before issuing a credit.";
|
|
2424
2505
|
function checkCreditGuard(action, refundAmount, refundStatus) {
|
|
2425
2506
|
if (refundStatus == null) {
|
|
2426
|
-
const diagnostic = (0,
|
|
2507
|
+
const diagnostic = (0, import_scheduling23.schedError)("SCHED_610", {
|
|
2427
2508
|
action,
|
|
2428
2509
|
refundAmount,
|
|
2429
2510
|
error: "checkCreditGuard was called without a refundStatus"
|
|
@@ -2469,10 +2550,10 @@ function checkCreditGuard(action, refundAmount, refundStatus) {
|
|
|
2469
2550
|
}
|
|
2470
2551
|
|
|
2471
2552
|
// src/money.ts
|
|
2472
|
-
var
|
|
2553
|
+
var import_scheduling24 = require("@ordinatio/scheduling");
|
|
2473
2554
|
function decimalToCents(value, field = "unknown") {
|
|
2474
2555
|
if (value === null || value === void 0) {
|
|
2475
|
-
throw new
|
|
2556
|
+
throw new import_scheduling24.SchedulingValidationError(
|
|
2476
2557
|
`Could not convert ${field} to cents \u2014 value is ${value}`,
|
|
2477
2558
|
"SCHED_406",
|
|
2478
2559
|
{ field, value }
|
|
@@ -2480,7 +2561,7 @@ function decimalToCents(value, field = "unknown") {
|
|
|
2480
2561
|
}
|
|
2481
2562
|
const cents = Math.round(Number(value) * 100);
|
|
2482
2563
|
if (!Number.isFinite(cents)) {
|
|
2483
|
-
throw new
|
|
2564
|
+
throw new import_scheduling24.SchedulingValidationError(
|
|
2484
2565
|
`Could not convert ${field} to cents \u2014 value is not numeric`,
|
|
2485
2566
|
"SCHED_406",
|
|
2486
2567
|
{ field, value }
|
|
@@ -2491,7 +2572,7 @@ function decimalToCents(value, field = "unknown") {
|
|
|
2491
2572
|
|
|
2492
2573
|
// src/payments/refund/refund-leg.ts
|
|
2493
2574
|
var import_node_crypto2 = require("crypto");
|
|
2494
|
-
var
|
|
2575
|
+
var import_scheduling25 = require("@ordinatio/scheduling");
|
|
2495
2576
|
async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix, appointmentId, errorCode, logLabel) {
|
|
2496
2577
|
const baseKey = `refund:${appointmentId}:${idempotencyKeySuffix}`;
|
|
2497
2578
|
let idempotencyKey = baseKey;
|
|
@@ -2524,7 +2605,7 @@ async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix,
|
|
|
2524
2605
|
return { succeeded: true, amountCents: null };
|
|
2525
2606
|
}
|
|
2526
2607
|
if (result.code === "IN_PROGRESS") {
|
|
2527
|
-
const inFlight = (0,
|
|
2608
|
+
const inFlight = (0, import_scheduling25.schedError)(errorCode, { error: result.error, appointmentId, paymentIntentId, kind: "idempotency_key_in_use" });
|
|
2528
2609
|
console.warn(
|
|
2529
2610
|
`[resolve-refund] ${logLabel} leg is already being refunded by another in-flight request (idempotency key in use) \u2014 its outcome is unknown, so this leg is recorded as retryable:`,
|
|
2530
2611
|
inFlight.ref,
|
|
@@ -2549,22 +2630,22 @@ async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix,
|
|
|
2549
2630
|
return failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay, { error: result.error, message: result.error ?? result.code ?? "no reason given", requestId: result.requestId });
|
|
2550
2631
|
}
|
|
2551
2632
|
}
|
|
2552
|
-
function failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay,
|
|
2553
|
-
const diagnostic = (0,
|
|
2633
|
+
function failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay, failure5) {
|
|
2634
|
+
const diagnostic = (0, import_scheduling25.schedError)(errorCode, { error: failure5.error, appointmentId, paymentIntentId });
|
|
2554
2635
|
console.error(
|
|
2555
2636
|
`[resolve-refund] ${logLabel} refund failed${retriedAfterReplay ? " (after a fresh-key re-attempt)" : ""} \u2014 manual refund may be required:`,
|
|
2556
2637
|
diagnostic.ref,
|
|
2557
2638
|
appointmentId,
|
|
2558
2639
|
paymentIntentId,
|
|
2559
|
-
`requestId=${
|
|
2640
|
+
`requestId=${failure5.requestId}`,
|
|
2560
2641
|
`idempotencyKey=${idempotencyKey}`,
|
|
2561
|
-
|
|
2642
|
+
failure5.message
|
|
2562
2643
|
);
|
|
2563
2644
|
return { succeeded: false, amountCents: null };
|
|
2564
2645
|
}
|
|
2565
2646
|
|
|
2566
2647
|
// src/payments/refund/persist-refund-outcome.ts
|
|
2567
|
-
var
|
|
2648
|
+
var import_scheduling26 = require("@ordinatio/scheduling");
|
|
2568
2649
|
var WEBHOOK_RACE_OUTCOMES = ["REFUNDED", "PARTIAL_REFUND"];
|
|
2569
2650
|
var SUCCESS_RANK = {
|
|
2570
2651
|
REFUND_FAILED: 0,
|
|
@@ -2609,7 +2690,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2609
2690
|
});
|
|
2610
2691
|
} catch (writeErr) {
|
|
2611
2692
|
const dbMessage = writeErr instanceof Error ? writeErr.message : String(writeErr);
|
|
2612
|
-
const diagnostic = (0,
|
|
2693
|
+
const diagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2613
2694
|
error: writeErr,
|
|
2614
2695
|
dbMessage,
|
|
2615
2696
|
appointmentId: id,
|
|
@@ -2633,7 +2714,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2633
2714
|
}
|
|
2634
2715
|
if (writeResult.count === 0) {
|
|
2635
2716
|
const buildLostRaceError = () => {
|
|
2636
|
-
const diagnostic = (0,
|
|
2717
|
+
const diagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2637
2718
|
appointmentId: id,
|
|
2638
2719
|
phase: "persist-cas-lost-race",
|
|
2639
2720
|
refundOutcome,
|
|
@@ -2672,7 +2753,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2672
2753
|
if (reconcileResult.count === 0) {
|
|
2673
2754
|
throw buildLostRaceError();
|
|
2674
2755
|
}
|
|
2675
|
-
const reconcileDiagnostic = (0,
|
|
2756
|
+
const reconcileDiagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2676
2757
|
appointmentId: id,
|
|
2677
2758
|
phase: "persist-cas-reconciled",
|
|
2678
2759
|
refundOutcome,
|
|
@@ -2771,7 +2852,7 @@ async function executeRefundLegs(db, id, preClaimSnapshot, payments) {
|
|
|
2771
2852
|
}
|
|
2772
2853
|
|
|
2773
2854
|
// src/payments/refund/refund-housekeeping.ts
|
|
2774
|
-
var
|
|
2855
|
+
var import_scheduling27 = require("@ordinatio/scheduling");
|
|
2775
2856
|
async function runHousekeeping(db, activity, appointment, id, action, newRefundStatus, userId) {
|
|
2776
2857
|
const isTerminalSuccess = TERMINAL_SUCCESS_STATUSES.includes(newRefundStatus);
|
|
2777
2858
|
try {
|
|
@@ -2787,7 +2868,7 @@ async function runHousekeeping(db, activity, appointment, id, action, newRefundS
|
|
|
2787
2868
|
});
|
|
2788
2869
|
return void 0;
|
|
2789
2870
|
} catch (err) {
|
|
2790
|
-
const diagnostic = (0,
|
|
2871
|
+
const diagnostic = (0, import_scheduling27.schedError)("SCHED_606", { error: err, appointmentId: id, phase: "housekeeping" });
|
|
2791
2872
|
console.error(
|
|
2792
2873
|
isTerminalSuccess ? "[resolve-refund] Sticky-activity resolution or audit log failed after a successful refund/credit:" : "[resolve-refund] Sticky-activity resolution or audit log failed after a non-terminal refund outcome (REFUND_FAILED/PARTIAL_REFUND):",
|
|
2793
2874
|
diagnostic.ref,
|
|
@@ -2872,9 +2953,9 @@ async function evaluatePreClaimState(input) {
|
|
|
2872
2953
|
}
|
|
2873
2954
|
|
|
2874
2955
|
// src/payments/refund/refund-failure-response.ts
|
|
2875
|
-
var
|
|
2956
|
+
var import_scheduling28 = require("@ordinatio/scheduling");
|
|
2876
2957
|
function refundFailureResponse({ error, id, stripeMayHaveMoved }) {
|
|
2877
|
-
const diagnostic = (0,
|
|
2958
|
+
const diagnostic = (0, import_scheduling28.schedError)("SCHED_610", { error, appointmentId: id, stripeMayHaveMoved });
|
|
2878
2959
|
console.error("[POST /resolve-refund]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
2879
2960
|
if (!stripeMayHaveMoved) {
|
|
2880
2961
|
return Response.json({ error: "Failed to resolve refund", ref: diagnostic.ref }, { status: 500 });
|
|
@@ -3412,6 +3493,38 @@ var TextSettingsSchema = import_zod15.z.object({
|
|
|
3412
3493
|
enabled: import_zod15.z.boolean().optional()
|
|
3413
3494
|
}).strict();
|
|
3414
3495
|
|
|
3496
|
+
// src/schemas/api-key.schema.ts
|
|
3497
|
+
var import_zod16 = require("zod");
|
|
3498
|
+
var ApiKeySchema = import_zod16.z.object({
|
|
3499
|
+
name: import_zod16.z.string().max(200),
|
|
3500
|
+
access: import_zod16.z.string().max(20)
|
|
3501
|
+
}).strict();
|
|
3502
|
+
|
|
3503
|
+
// src/schemas/gift-certificate.schema.ts
|
|
3504
|
+
var import_zod17 = require("zod");
|
|
3505
|
+
var text = (max) => import_zod17.z.string().max(max).nullable().optional();
|
|
3506
|
+
var GiftCertificateSchema = import_zod17.z.object({
|
|
3507
|
+
amountCents: import_zod17.z.number(),
|
|
3508
|
+
currency: import_zod17.z.string().max(10).optional(),
|
|
3509
|
+
expiresAt: import_zod17.z.string().max(40).nullable().optional(),
|
|
3510
|
+
recipientName: text(300),
|
|
3511
|
+
recipientEmail: text(300),
|
|
3512
|
+
purchaserName: text(300),
|
|
3513
|
+
purchaserEmail: text(300),
|
|
3514
|
+
message: text(1e3),
|
|
3515
|
+
paymentId: text(300),
|
|
3516
|
+
notes: text(2e3)
|
|
3517
|
+
}).strict();
|
|
3518
|
+
var GiftCertificateRestoreSchema = import_zod17.z.object({
|
|
3519
|
+
amountCents: import_zod17.z.number(),
|
|
3520
|
+
appointmentId: import_zod17.z.string().max(200).optional(),
|
|
3521
|
+
note: import_zod17.z.string().max(1e3).optional()
|
|
3522
|
+
}).strict();
|
|
3523
|
+
var GiftCertificateCheckSchema = import_zod17.z.object({
|
|
3524
|
+
code: import_zod17.z.string().max(64),
|
|
3525
|
+
calendarId: import_zod17.z.string().min(1).max(200)
|
|
3526
|
+
}).strict();
|
|
3527
|
+
|
|
3415
3528
|
// src/pagination.ts
|
|
3416
3529
|
var DEFAULT_LIMIT = 50;
|
|
3417
3530
|
var MAX_LIMIT = 200;
|
|
@@ -3433,12 +3546,12 @@ function parsePagination(request, maxLimit = MAX_LIMIT, defaultLimit = DEFAULT_L
|
|
|
3433
3546
|
}
|
|
3434
3547
|
|
|
3435
3548
|
// src/validation.ts
|
|
3436
|
-
var
|
|
3549
|
+
var import_zod18 = require("zod");
|
|
3437
3550
|
async function parseBody(request, schema) {
|
|
3438
3551
|
try {
|
|
3439
3552
|
return { success: true, data: schema.parse(await request.json()) };
|
|
3440
3553
|
} catch (error) {
|
|
3441
|
-
if (error instanceof
|
|
3554
|
+
if (error instanceof import_zod18.ZodError) {
|
|
3442
3555
|
const details = error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message }));
|
|
3443
3556
|
return { success: false, response: Response.json({ error: "Validation failed", details }, { status: 400 }) };
|
|
3444
3557
|
}
|
|
@@ -3452,7 +3565,7 @@ function validateData(data, schema) {
|
|
|
3452
3565
|
try {
|
|
3453
3566
|
return { success: true, data: schema.parse(data) };
|
|
3454
3567
|
} catch (error) {
|
|
3455
|
-
if (error instanceof
|
|
3568
|
+
if (error instanceof import_zod18.ZodError) {
|
|
3456
3569
|
return { success: false, errors: error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message })) };
|
|
3457
3570
|
}
|
|
3458
3571
|
return { success: false, errors: [{ field: "", message: "Validation failed" }] };
|
|
@@ -3938,7 +4051,7 @@ async function updatePackagePurchase(request, { host, params }) {
|
|
|
3938
4051
|
}
|
|
3939
4052
|
|
|
3940
4053
|
// src/handlers/admin-group-sessions.ts
|
|
3941
|
-
var
|
|
4054
|
+
var import_scheduling29 = require("@ordinatio/scheduling");
|
|
3942
4055
|
var MAX_RANGE_MS = 366 * 24 * 60 * 60 * 1e3;
|
|
3943
4056
|
async function listGroupSessions(request, { host }) {
|
|
3944
4057
|
try {
|
|
@@ -3956,29 +4069,29 @@ async function listGroupSessions(request, { host }) {
|
|
|
3956
4069
|
return Response.json({ error: "Invalid date format \u2014 use ISO 8601" }, { status: 400 });
|
|
3957
4070
|
}
|
|
3958
4071
|
if (startDate >= endDate) {
|
|
3959
|
-
const err = (0,
|
|
4072
|
+
const err = (0, import_scheduling29.schedError)("SCHED_310", { startDateStr, endDateStr });
|
|
3960
4073
|
return Response.json({ error: "startDate must be before endDate", ref: err.ref }, { status: 400 });
|
|
3961
4074
|
}
|
|
3962
4075
|
if (endDate.getTime() - startDate.getTime() > MAX_RANGE_MS) {
|
|
3963
|
-
const err = (0,
|
|
4076
|
+
const err = (0, import_scheduling29.schedError)("SCHED_312", { startDateStr, endDateStr });
|
|
3964
4077
|
return Response.json({ error: "Date range exceeds maximum allowed (366 days)", ref: err.ref }, { status: 400 });
|
|
3965
4078
|
}
|
|
3966
4079
|
const calendarId = params.get("calendarId") || void 0;
|
|
3967
4080
|
const visibleCalendarIds = await staff.visibleCalendarIds();
|
|
3968
|
-
const { sessions, hasMore } = await (0,
|
|
4081
|
+
const { sessions, hasMore } = await (0, import_scheduling29.getGroupSessions)(staff.db, { startDate, endDate, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
|
|
3969
4082
|
return Response.json({ sessions, total: sessions.length, hasMore });
|
|
3970
4083
|
} catch (error) {
|
|
3971
|
-
const err = (0,
|
|
4084
|
+
const err = (0, import_scheduling29.schedError)("SCHED_311", { error });
|
|
3972
4085
|
console.error("[group-sessions]", err.ref, error);
|
|
3973
4086
|
return Response.json({ error: "Failed to fetch group sessions", ref: err.ref }, { status: 500 });
|
|
3974
4087
|
}
|
|
3975
4088
|
}
|
|
3976
4089
|
|
|
3977
4090
|
// src/handlers/admin-recurring.ts
|
|
3978
|
-
var
|
|
4091
|
+
var import_scheduling32 = require("@ordinatio/scheduling");
|
|
3979
4092
|
|
|
3980
4093
|
// src/recurring/series-side-effects.ts
|
|
3981
|
-
var
|
|
4094
|
+
var import_scheduling30 = require("@ordinatio/scheduling");
|
|
3982
4095
|
|
|
3983
4096
|
// src/recurring/failure-collector.ts
|
|
3984
4097
|
function createFailureCollector() {
|
|
@@ -4042,7 +4155,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4042
4155
|
const sendConfirmation = async (url, appointmentId) => {
|
|
4043
4156
|
for (let tryNumber = 1; tryNumber <= 2; tryNumber += 1) {
|
|
4044
4157
|
try {
|
|
4045
|
-
await (0,
|
|
4158
|
+
await (0, import_scheduling30.scheduleNotifications)(db, appointmentId, url, { brand: Boolean(host.brand) });
|
|
4046
4159
|
return;
|
|
4047
4160
|
} catch (error) {
|
|
4048
4161
|
if (tryNumber === 2) record("Client confirmation", error);
|
|
@@ -4055,7 +4168,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4055
4168
|
await sendConfirmation(baseUrl, visit.id);
|
|
4056
4169
|
} else {
|
|
4057
4170
|
await attempt("Client notices", async () => {
|
|
4058
|
-
await (0,
|
|
4171
|
+
await (0, import_scheduling30.scheduleNotifications)(db, visit.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
4059
4172
|
});
|
|
4060
4173
|
}
|
|
4061
4174
|
}
|
|
@@ -4075,7 +4188,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4075
4188
|
await Promise.all(visits.slice(from, from + VISITS_PER_GROUP).map(handleVisit));
|
|
4076
4189
|
}
|
|
4077
4190
|
if (baseUrl && confirmationVisit) {
|
|
4078
|
-
await attempt("Staff alert", () => (0,
|
|
4191
|
+
await attempt("Staff alert", () => (0, import_scheduling30.queueStaffNotification)(db, confirmationVisit.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) }));
|
|
4079
4192
|
}
|
|
4080
4193
|
await attempt("Availability cache", () => host.availabilityCache.invalidate(first.calendarId));
|
|
4081
4194
|
await attempt(
|
|
@@ -4091,11 +4204,11 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4091
4204
|
}
|
|
4092
4205
|
|
|
4093
4206
|
// src/recurring/validate-timezone.ts
|
|
4094
|
-
var
|
|
4207
|
+
var import_scheduling31 = require("@ordinatio/scheduling");
|
|
4095
4208
|
var SUPPORTED_TIMEZONES = new Set(Intl.supportedValuesOf("timeZone"));
|
|
4096
4209
|
function validateRecurringTimezone(timezone) {
|
|
4097
4210
|
if (isValidIanaTimezone(timezone)) return null;
|
|
4098
|
-
const err = (0,
|
|
4211
|
+
const err = (0, import_scheduling31.schedError)("SCHED_704", { timezone });
|
|
4099
4212
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4100
4213
|
}
|
|
4101
4214
|
function isValidIanaTimezone(timezone) {
|
|
@@ -4148,12 +4261,12 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4148
4261
|
const validation = await parseBody(request, CreateRecurringSeriesSchema);
|
|
4149
4262
|
if (!validation.success) return validation.response;
|
|
4150
4263
|
const input = validation.data;
|
|
4151
|
-
if (input.occurrences < 1 || input.occurrences >
|
|
4152
|
-
const err = (0,
|
|
4264
|
+
if (input.occurrences < 1 || input.occurrences > import_scheduling32.RECURRING_MAX_OCCURRENCES) {
|
|
4265
|
+
const err = (0, import_scheduling32.schedError)("SCHED_701", { occurrences: input.occurrences });
|
|
4153
4266
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4154
4267
|
}
|
|
4155
|
-
if (!(0,
|
|
4156
|
-
const err = (0,
|
|
4268
|
+
if (!(0, import_scheduling32.parseTimeLocal)(input.startTimeLocal)) {
|
|
4269
|
+
const err = (0, import_scheduling32.schedError)("SCHED_700", { startTimeLocal: input.startTimeLocal });
|
|
4157
4270
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4158
4271
|
}
|
|
4159
4272
|
const tzError = validateRecurringTimezone(input.timezone);
|
|
@@ -4182,7 +4295,7 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4182
4295
|
});
|
|
4183
4296
|
const firstDate = new Date(input.firstDate);
|
|
4184
4297
|
const endsAt = input.endsAt ? new Date(input.endsAt) : void 0;
|
|
4185
|
-
const slots = (0,
|
|
4298
|
+
const slots = (0, import_scheduling32.buildRecurringSlots)(
|
|
4186
4299
|
firstDate,
|
|
4187
4300
|
input.frequency,
|
|
4188
4301
|
input.occurrences,
|
|
@@ -4271,17 +4384,17 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4271
4384
|
}
|
|
4272
4385
|
|
|
4273
4386
|
// src/handlers/admin-recurring-detail.ts
|
|
4274
|
-
var
|
|
4387
|
+
var import_scheduling34 = require("@ordinatio/scheduling");
|
|
4275
4388
|
|
|
4276
4389
|
// src/recurring/series-cancel-side-effects.ts
|
|
4277
|
-
var
|
|
4390
|
+
var import_scheduling33 = require("@ordinatio/scheduling");
|
|
4278
4391
|
var OCCURRENCES_PER_GROUP = 8;
|
|
4279
4392
|
async function runSeriesCancelSideEffects(host, db, organizationId, seriesId, seriesCalendarId, occurrences) {
|
|
4280
4393
|
if (occurrences.length === 0) return { failures: [] };
|
|
4281
4394
|
const { attempt, record, lines } = createFailureCollector();
|
|
4282
4395
|
const handle = async (occurrence) => {
|
|
4283
4396
|
const { id } = occurrence;
|
|
4284
|
-
await attempt("Pending reminders", () => (0,
|
|
4397
|
+
await attempt("Pending reminders", () => (0, import_scheduling33.cancelPendingNotifications)(db, id));
|
|
4285
4398
|
const hasPayment = hasPendingPayment(occurrence.paymentId, occurrence.paymentStatus);
|
|
4286
4399
|
await attempt("Refund review flag", async () => {
|
|
4287
4400
|
await writeRefundStatusAfterCancel(host, db, { appointmentId: id, hasPayment, clientName: occurrence.clientName });
|
|
@@ -4313,7 +4426,7 @@ async function runSeriesCancelSideEffects(host, db, organizationId, seriesId, se
|
|
|
4313
4426
|
}
|
|
4314
4427
|
const baseUrl = host.appUrl()?.trim();
|
|
4315
4428
|
if (baseUrl) {
|
|
4316
|
-
await attempt("Staff notice", () => (0,
|
|
4429
|
+
await attempt("Staff notice", () => (0, import_scheduling33.queueStaffNotification)(db, occurrences[0].id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }));
|
|
4317
4430
|
} else {
|
|
4318
4431
|
record("Staff notice", "skipped because the application address is not set");
|
|
4319
4432
|
}
|
|
@@ -4359,7 +4472,7 @@ async function getRecurringSeries(request, { host, params }) {
|
|
|
4359
4472
|
}
|
|
4360
4473
|
});
|
|
4361
4474
|
if (!series || !await staff.canSeeCalendar(series.calendar.id)) {
|
|
4362
|
-
const err = (0,
|
|
4475
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId });
|
|
4363
4476
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4364
4477
|
}
|
|
4365
4478
|
return Response.json({ series });
|
|
@@ -4386,14 +4499,14 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4386
4499
|
select: { id: true, status: true, clientName: true, clientEmail: true, frequency: true, occurrences: true, calendarId: true }
|
|
4387
4500
|
});
|
|
4388
4501
|
if (!series) {
|
|
4389
|
-
const err = (0,
|
|
4502
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId });
|
|
4390
4503
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4391
4504
|
}
|
|
4392
4505
|
if (!await staff.canSeeCalendar(series.calendarId)) {
|
|
4393
4506
|
return Response.json({ error: "Calendar not found" }, { status: 404 });
|
|
4394
4507
|
}
|
|
4395
4508
|
if ((input.scope === "ONE" || input.scope === "THIS_AND_FOLLOWING") && !input.fromAppointmentId) {
|
|
4396
|
-
const err = (0,
|
|
4509
|
+
const err = (0, import_scheduling34.schedError)("SCHED_703", { scope: input.scope });
|
|
4397
4510
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4398
4511
|
}
|
|
4399
4512
|
const NON_CANCELLABLE_STATUSES = ["CANCELLED", "COMPLETED", "NO_SHOW"];
|
|
@@ -4421,7 +4534,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4421
4534
|
if (hiddenCalendars) {
|
|
4422
4535
|
const hidden = await db.appointment.count({ where: { ...open, calendar: { organizationId, NOT: hiddenCalendars } } });
|
|
4423
4536
|
if (hidden > 0) {
|
|
4424
|
-
const err = (0,
|
|
4537
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId, reason: "open occurrence on a calendar outside the viewer scope" });
|
|
4425
4538
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4426
4539
|
}
|
|
4427
4540
|
}
|
|
@@ -4454,7 +4567,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4454
4567
|
return Response.json({ cancelledCount, newSeriesStatus, ...warnings.length > 0 && { warnings } });
|
|
4455
4568
|
} catch (error) {
|
|
4456
4569
|
if (error?.code === "P2025") {
|
|
4457
|
-
const err = (0,
|
|
4570
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { race: "series vanished between org-scoped pre-check and cancellation transaction" });
|
|
4458
4571
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4459
4572
|
}
|
|
4460
4573
|
return Response.json({ error: getErrorMessage(error, "Failed to cancel recurring series") }, { status: 500 });
|
|
@@ -4462,7 +4575,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4462
4575
|
}
|
|
4463
4576
|
|
|
4464
4577
|
// src/handlers/booking-analytics.ts
|
|
4465
|
-
var
|
|
4578
|
+
var import_scheduling35 = require("@ordinatio/scheduling");
|
|
4466
4579
|
async function getAnalytics(request, { host }) {
|
|
4467
4580
|
try {
|
|
4468
4581
|
const staff = await host.staff.resolve(request);
|
|
@@ -4474,7 +4587,7 @@ async function getAnalytics(request, { host }) {
|
|
|
4474
4587
|
const limited = await host.rateLimit(`analytics:${ip}`, "GENERAL");
|
|
4475
4588
|
if (limited) return limited;
|
|
4476
4589
|
if (!staff.isAdmin) {
|
|
4477
|
-
const err = (0,
|
|
4590
|
+
const err = (0, import_scheduling35.schedError)("SCHED_900", { userId: staff.userId, role: staff.role });
|
|
4478
4591
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
4479
4592
|
}
|
|
4480
4593
|
const params = new URL(request.url).searchParams;
|
|
@@ -4500,7 +4613,7 @@ async function getAnalytics(request, { host }) {
|
|
|
4500
4613
|
}
|
|
4501
4614
|
}
|
|
4502
4615
|
const visibleCalendarIds = await staff.visibleCalendarIds();
|
|
4503
|
-
const analytics = await (0,
|
|
4616
|
+
const analytics = await (0, import_scheduling35.getBookingAnalytics)(staff.db, { days, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
|
|
4504
4617
|
return Response.json(analytics);
|
|
4505
4618
|
} catch (error) {
|
|
4506
4619
|
const ref = getErrorRef(error);
|
|
@@ -4513,17 +4626,17 @@ async function getAnalytics(request, { host }) {
|
|
|
4513
4626
|
}
|
|
4514
4627
|
|
|
4515
4628
|
// src/sanitize/escape-html.ts
|
|
4516
|
-
function escapeHtml(
|
|
4517
|
-
if (!
|
|
4518
|
-
return
|
|
4629
|
+
function escapeHtml(text2) {
|
|
4630
|
+
if (!text2) return "";
|
|
4631
|
+
return text2.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4519
4632
|
}
|
|
4520
4633
|
|
|
4521
4634
|
// src/brand/brand-http.ts
|
|
4522
|
-
var
|
|
4635
|
+
var import_scheduling36 = require("@ordinatio/scheduling");
|
|
4523
4636
|
var NOT_ENABLED = { error: "Branding is not enabled on this server" };
|
|
4524
4637
|
function brandErrorResponse(error, fallback, cors) {
|
|
4525
4638
|
const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
|
|
4526
|
-
if (error instanceof
|
|
4639
|
+
if (error instanceof import_scheduling36.SchedulingValidationError) {
|
|
4527
4640
|
const details = error.context.errors;
|
|
4528
4641
|
return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, 400);
|
|
4529
4642
|
}
|
|
@@ -4539,7 +4652,7 @@ async function requireBrandAdmin(host, request, options) {
|
|
|
4539
4652
|
async function businessName(host, db, organizationId) {
|
|
4540
4653
|
if (host.brand) {
|
|
4541
4654
|
try {
|
|
4542
|
-
const brand = await (0,
|
|
4655
|
+
const brand = await (0, import_scheduling36.getBrand)(db, organizationId);
|
|
4543
4656
|
if (brand) return brand.displayName;
|
|
4544
4657
|
} catch (error) {
|
|
4545
4658
|
console.error("[brand] could not read the brand for a message:", error);
|
|
@@ -4707,7 +4820,7 @@ We look forward to seeing you!
|
|
|
4707
4820
|
}
|
|
4708
4821
|
|
|
4709
4822
|
// src/handlers/calendar-ownership.ts
|
|
4710
|
-
var
|
|
4823
|
+
var import_scheduling37 = require("@ordinatio/scheduling");
|
|
4711
4824
|
var SAFE_CALENDAR_FIELDS = [
|
|
4712
4825
|
"id",
|
|
4713
4826
|
"organizationId",
|
|
@@ -4774,7 +4887,7 @@ async function getOwnedCalendarForRoute(db, id, organizationId) {
|
|
|
4774
4887
|
async function validateStaffLink(host, userId, organizationId) {
|
|
4775
4888
|
if (!userId) return null;
|
|
4776
4889
|
if (await host.staffDirectory.isMember(organizationId, userId)) return null;
|
|
4777
|
-
const err = (0,
|
|
4890
|
+
const err = (0, import_scheduling37.schedError)("SCHED_104", { userId, organizationId });
|
|
4778
4891
|
return Response.json({ error: "That staff member is not part of this organization", ref: err.ref }, { status: 400 });
|
|
4779
4892
|
}
|
|
4780
4893
|
function buildCalendarUpdateData(input) {
|
|
@@ -4821,7 +4934,7 @@ async function releaseCalendarSlugIfStillInactive(host, db, calendarId, organiza
|
|
|
4821
4934
|
}
|
|
4822
4935
|
async function undoArchive(host, db, calendarId, organizationId, slug) {
|
|
4823
4936
|
try {
|
|
4824
|
-
await (0,
|
|
4937
|
+
await (0, import_scheduling37.updateCalendar)(db, calendarId, organizationId, { isActive: true });
|
|
4825
4938
|
} catch (restoreError) {
|
|
4826
4939
|
console.error("[calendar update] could not switch the calendar back on after a failed update", calendarId, restoreError);
|
|
4827
4940
|
try {
|
|
@@ -4920,7 +5033,7 @@ async function createCalendar(request, { host }) {
|
|
|
4920
5033
|
}
|
|
4921
5034
|
|
|
4922
5035
|
// src/handlers/admin-calendar-update.ts
|
|
4923
|
-
var
|
|
5036
|
+
var import_scheduling38 = require("@ordinatio/scheduling");
|
|
4924
5037
|
var NOT_FOUND5 = () => Response.json({ error: "Calendar not found" }, { status: 404 });
|
|
4925
5038
|
async function getCalendar(request, { host, params }) {
|
|
4926
5039
|
try {
|
|
@@ -4962,10 +5075,10 @@ async function putCalendar(request, { host, params }) {
|
|
|
4962
5075
|
let updated;
|
|
4963
5076
|
try {
|
|
4964
5077
|
if (archiving) {
|
|
4965
|
-
await (0,
|
|
5078
|
+
await (0, import_scheduling38.archiveCalendar)(db, id, organizationId);
|
|
4966
5079
|
archived = true;
|
|
4967
5080
|
}
|
|
4968
|
-
({ calendar: updated } = await (0,
|
|
5081
|
+
({ calendar: updated } = await (0, import_scheduling38.updateCalendar)(db, id, organizationId, buildCalendarUpdateData(input)));
|
|
4969
5082
|
} catch (error) {
|
|
4970
5083
|
if (archived) await undoArchive(host, db, id, organizationId, existing.slug);
|
|
4971
5084
|
throw error;
|
|
@@ -4994,7 +5107,7 @@ async function deleteCalendar(request, { host, params }) {
|
|
|
4994
5107
|
if (!await staff.canSeeCalendar(id)) return NOT_FOUND5();
|
|
4995
5108
|
const existing = await getOwnedCalendarForRoute(db, id, organizationId);
|
|
4996
5109
|
if (!existing) return NOT_FOUND5();
|
|
4997
|
-
await (0,
|
|
5110
|
+
await (0, import_scheduling38.archiveCalendar)(db, id, organizationId);
|
|
4998
5111
|
await releaseCalendarSlugIfStillInactive(host, db, id, organizationId, existing.slug);
|
|
4999
5112
|
await bustCalendarCachesOnArchive(host, organizationId, existing.slug, id);
|
|
5000
5113
|
await host.activity.log(db, {
|
|
@@ -5145,7 +5258,7 @@ async function disconnectOutlook(request, { host, params }) {
|
|
|
5145
5258
|
}
|
|
5146
5259
|
|
|
5147
5260
|
// src/handlers/admin-calendar-location-recents.ts
|
|
5148
|
-
var
|
|
5261
|
+
var import_scheduling39 = require("@ordinatio/scheduling");
|
|
5149
5262
|
async function getLocationRecents(request, { host, params }) {
|
|
5150
5263
|
try {
|
|
5151
5264
|
const staff = await requireAdminStaff(host, request, {
|
|
@@ -5190,14 +5303,14 @@ async function getLocationRecents(request, { host, params }) {
|
|
|
5190
5303
|
}
|
|
5191
5304
|
return Response.json({ locations });
|
|
5192
5305
|
} catch (error) {
|
|
5193
|
-
const diagnostic = (0,
|
|
5306
|
+
const diagnostic = (0, import_scheduling39.schedError)("SCHED_207", { error });
|
|
5194
5307
|
console.error("[location-recents]", diagnostic.ref, error);
|
|
5195
5308
|
return Response.json({ error: "Failed to fetch location recents", ref: diagnostic.ref }, { status: 500 });
|
|
5196
5309
|
}
|
|
5197
5310
|
}
|
|
5198
5311
|
|
|
5199
5312
|
// src/handlers/admin-availability-rules.ts
|
|
5200
|
-
var
|
|
5313
|
+
var import_scheduling40 = require("@ordinatio/scheduling");
|
|
5201
5314
|
|
|
5202
5315
|
// src/availability/admin-calendar.ts
|
|
5203
5316
|
async function verifyCalendar(db, calendarId, organizationId) {
|
|
@@ -5271,7 +5384,7 @@ async function listRules(request, { host, params }) {
|
|
|
5271
5384
|
const calendar = await requireOwnedVisibleCalendar(staff, calendarId);
|
|
5272
5385
|
if (calendar instanceof Response) return calendar;
|
|
5273
5386
|
const { limit, offset } = parsePagination(request, 500, 200);
|
|
5274
|
-
const { rules, total, hasMore } = await (0,
|
|
5387
|
+
const { rules, total, hasMore } = await (0, import_scheduling40.listAvailabilityRules)(staff.db, calendarId, { limit, offset });
|
|
5275
5388
|
return Response.json({ rules, total, hasMore });
|
|
5276
5389
|
} catch (error) {
|
|
5277
5390
|
return Response.json({ error: getErrorMessage(error, "Failed to fetch availability") }, { status: 500 });
|
|
@@ -5290,7 +5403,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5290
5403
|
if (!Array.isArray(rules)) return Response.json({ error: "rules must be an array" }, { status: 400 });
|
|
5291
5404
|
const validationError = validateWeeklyRules(rules);
|
|
5292
5405
|
if (validationError) return Response.json({ error: validationError }, { status: 400 });
|
|
5293
|
-
const created = await (0,
|
|
5406
|
+
const created = await (0, import_scheduling40.setWeeklyAvailability)(db, calendarId, rules);
|
|
5294
5407
|
await clearAvailabilityCache(host, calendarId);
|
|
5295
5408
|
const activeDays = rules.map((r) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][r.dayOfWeek]).join(", ");
|
|
5296
5409
|
await host.activity.log(db, {
|
|
@@ -5301,7 +5414,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5301
5414
|
return Response.json(created);
|
|
5302
5415
|
} catch (error) {
|
|
5303
5416
|
const msg = getErrorMessage(error, "Failed to update availability");
|
|
5304
|
-
if (error instanceof
|
|
5417
|
+
if (error instanceof import_scheduling40.SchedulingValidationError) {
|
|
5305
5418
|
console.error("[PUT /admin/availability]", error.ref, error.code, error.context);
|
|
5306
5419
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5307
5420
|
}
|
|
@@ -5310,18 +5423,18 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5310
5423
|
}
|
|
5311
5424
|
|
|
5312
5425
|
// src/handlers/admin-availability-overrides.ts
|
|
5313
|
-
var
|
|
5426
|
+
var import_scheduling42 = require("@ordinatio/scheduling");
|
|
5314
5427
|
|
|
5315
5428
|
// src/availability/override-helpers.ts
|
|
5316
|
-
var
|
|
5429
|
+
var import_scheduling41 = require("@ordinatio/scheduling");
|
|
5317
5430
|
function sanitizeBlockReason(raw) {
|
|
5318
5431
|
if (!raw) return void 0;
|
|
5319
5432
|
return String(raw).replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<[^>]*>/g, "").slice(0, 500).trim() || void 0;
|
|
5320
5433
|
}
|
|
5321
5434
|
async function checkOverlappingAppointments(db, calendarId, calendarTimezone, dateStr, startTime, endTime) {
|
|
5322
5435
|
const tz = calendarTimezone ?? "America/New_York";
|
|
5323
|
-
const blockStart = (0,
|
|
5324
|
-
const blockEnd = (0,
|
|
5436
|
+
const blockStart = (0, import_scheduling41.localToUTC)(dateStr, startTime, tz);
|
|
5437
|
+
const blockEnd = (0, import_scheduling41.localToUTC)(dateStr, endTime, tz);
|
|
5325
5438
|
const conflictCount = await db.appointment.count({
|
|
5326
5439
|
where: {
|
|
5327
5440
|
calendarId,
|
|
@@ -5351,14 +5464,14 @@ async function addOverride(request, { host, params }) {
|
|
|
5351
5464
|
const isBlockedFlag = body.isBlocked ?? true;
|
|
5352
5465
|
let override;
|
|
5353
5466
|
if (isBlockedFlag && body.startTime && body.endTime) {
|
|
5354
|
-
override = await (0,
|
|
5467
|
+
override = await (0, import_scheduling42.addTimeBlock)(db, calendarId, {
|
|
5355
5468
|
date,
|
|
5356
5469
|
startTime: body.startTime,
|
|
5357
5470
|
endTime: body.endTime,
|
|
5358
5471
|
reason: blockReason
|
|
5359
5472
|
});
|
|
5360
5473
|
} else {
|
|
5361
|
-
override = await (0,
|
|
5474
|
+
override = await (0, import_scheduling42.addDateOverride)(db, calendarId, {
|
|
5362
5475
|
date,
|
|
5363
5476
|
isBlocked: isBlockedFlag,
|
|
5364
5477
|
blockReason,
|
|
@@ -5395,7 +5508,7 @@ async function addOverride(request, { host, params }) {
|
|
|
5395
5508
|
return Response.json({ ...override, ...overlapWarning && { warning: overlapWarning } }, { status: 201 });
|
|
5396
5509
|
} catch (error) {
|
|
5397
5510
|
const msg = getErrorMessage(error, "Failed to add override");
|
|
5398
|
-
if (error instanceof
|
|
5511
|
+
if (error instanceof import_scheduling42.SchedulingValidationError) {
|
|
5399
5512
|
console.error("[POST /admin/availability]", error.ref, error.code, error.context);
|
|
5400
5513
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5401
5514
|
}
|
|
@@ -5412,7 +5525,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5412
5525
|
if (calendar instanceof Response) return calendar;
|
|
5413
5526
|
const { ruleId } = await request.json();
|
|
5414
5527
|
if (!ruleId) return Response.json({ error: "ruleId is required" }, { status: 400 });
|
|
5415
|
-
const deletedRule = await (0,
|
|
5528
|
+
const deletedRule = await (0, import_scheduling42.removeDateOverride)(db, calendarId, ruleId);
|
|
5416
5529
|
await clearAvailabilityCache(host, calendarId);
|
|
5417
5530
|
const deletedIsTimeBlock = deletedRule?.isBlocked && !(deletedRule.startTime === "00:00" && deletedRule.endTime === "00:00");
|
|
5418
5531
|
await host.activity.log(db, {
|
|
@@ -5423,7 +5536,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5423
5536
|
return Response.json({ success: true });
|
|
5424
5537
|
} catch (error) {
|
|
5425
5538
|
const msg = getErrorMessage(error, "Failed to remove override");
|
|
5426
|
-
if (error instanceof
|
|
5539
|
+
if (error instanceof import_scheduling42.SchedulingNotFoundError) {
|
|
5427
5540
|
console.error("[DELETE /admin/availability]", error.ref, error.code, error.context);
|
|
5428
5541
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5429
5542
|
}
|
|
@@ -5432,7 +5545,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5432
5545
|
}
|
|
5433
5546
|
|
|
5434
5547
|
// src/handlers/admin-templates.ts
|
|
5435
|
-
var
|
|
5548
|
+
var import_scheduling43 = require("@ordinatio/scheduling");
|
|
5436
5549
|
|
|
5437
5550
|
// src/sanitize/notification-body.ts
|
|
5438
5551
|
var import_sanitize_html = __toESM(require("sanitize-html"));
|
|
@@ -5456,7 +5569,7 @@ async function listTemplates(request, { host }) {
|
|
|
5456
5569
|
try {
|
|
5457
5570
|
const staff = await requireAdminStaff(host, request, { action: "admin-templates-list", tier: "GENERAL" });
|
|
5458
5571
|
if (staff instanceof Response) return staff;
|
|
5459
|
-
return Response.json(await (0,
|
|
5572
|
+
return Response.json(await (0, import_scheduling43.listNotificationTemplates)(staff.db, staff.organizationId));
|
|
5460
5573
|
} catch (error) {
|
|
5461
5574
|
return Response.json({ error: getErrorMessage(error, "Failed to fetch templates") }, { status: 500 });
|
|
5462
5575
|
}
|
|
@@ -5481,7 +5594,7 @@ async function createTemplate(request, { host }) {
|
|
|
5481
5594
|
if (input.channel === "EMAIL" && !stripHtml(input.subject).trim()) {
|
|
5482
5595
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
5483
5596
|
}
|
|
5484
|
-
const template = await (0,
|
|
5597
|
+
const template = await (0, import_scheduling43.createNotificationTemplate)(db, organizationId, {
|
|
5485
5598
|
name: input.name,
|
|
5486
5599
|
channel: input.channel,
|
|
5487
5600
|
trigger: input.trigger,
|
|
@@ -5507,7 +5620,7 @@ async function createTemplate(request, { host }) {
|
|
|
5507
5620
|
}
|
|
5508
5621
|
|
|
5509
5622
|
// src/handlers/admin-template-update.ts
|
|
5510
|
-
var
|
|
5623
|
+
var import_scheduling44 = require("@ordinatio/scheduling");
|
|
5511
5624
|
async function updateTemplate(request, { host, params }) {
|
|
5512
5625
|
try {
|
|
5513
5626
|
const staff = await requireAdminStaff(host, request, { action: "admin-templates-update", tier: "UPDATE" });
|
|
@@ -5539,7 +5652,7 @@ async function updateTemplate(request, { host, params }) {
|
|
|
5539
5652
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
5540
5653
|
}
|
|
5541
5654
|
}
|
|
5542
|
-
const updated = await (0,
|
|
5655
|
+
const updated = await (0, import_scheduling44.updateNotificationTemplate)(db, organizationId, id, {
|
|
5543
5656
|
name: input.name,
|
|
5544
5657
|
subject: sanitizedSubject,
|
|
5545
5658
|
body: input.body !== void 0 ? sanitizeNotificationBody(input.body, existing.channel) : void 0,
|
|
@@ -5553,11 +5666,11 @@ async function updateTemplate(request, { host, params }) {
|
|
|
5553
5666
|
return Response.json(updated);
|
|
5554
5667
|
} catch (error) {
|
|
5555
5668
|
const msg = getErrorMessage(error, "Failed to update template");
|
|
5556
|
-
if (error instanceof
|
|
5669
|
+
if (error instanceof import_scheduling44.SchedulingValidationError) {
|
|
5557
5670
|
console.error("[PUT /admin/templates]", error.ref, error.code, error.context);
|
|
5558
5671
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5559
5672
|
}
|
|
5560
|
-
if (error instanceof
|
|
5673
|
+
if (error instanceof import_scheduling44.SchedulingNotFoundError) {
|
|
5561
5674
|
console.error("[PUT /admin/templates]", error.ref, error.code, error.context);
|
|
5562
5675
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5563
5676
|
}
|
|
@@ -5574,7 +5687,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5574
5687
|
where: { id, organizationId },
|
|
5575
5688
|
select: { name: true }
|
|
5576
5689
|
});
|
|
5577
|
-
await (0,
|
|
5690
|
+
await (0, import_scheduling44.deleteNotificationTemplate)(db, organizationId, id);
|
|
5578
5691
|
await host.activity.log(db, {
|
|
5579
5692
|
action: "scheduling.template_deleted",
|
|
5580
5693
|
description: `deleted notification template "${template?.name || id}"`,
|
|
@@ -5583,7 +5696,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5583
5696
|
return Response.json({ success: true });
|
|
5584
5697
|
} catch (error) {
|
|
5585
5698
|
const msg = getErrorMessage(error, "Failed to delete template");
|
|
5586
|
-
if (error instanceof
|
|
5699
|
+
if (error instanceof import_scheduling44.SchedulingNotFoundError) {
|
|
5587
5700
|
console.error("[DELETE /admin/templates]", error.ref, error.code, error.context);
|
|
5588
5701
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5589
5702
|
}
|
|
@@ -5592,7 +5705,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5592
5705
|
}
|
|
5593
5706
|
|
|
5594
5707
|
// src/handlers/admin-types.ts
|
|
5595
|
-
var
|
|
5708
|
+
var import_scheduling45 = require("@ordinatio/scheduling");
|
|
5596
5709
|
async function listTypes(request, { host }) {
|
|
5597
5710
|
try {
|
|
5598
5711
|
const staff = await requireAdminStaff(host, request, { action: "admin-types-list", tier: "GENERAL" });
|
|
@@ -5622,7 +5735,7 @@ async function createType(request, { host }) {
|
|
|
5622
5735
|
if (!validation.success) return validation.response;
|
|
5623
5736
|
if (!organizationId) return Response.json({ error: "Organization context required" }, { status: 400 });
|
|
5624
5737
|
const input = validation.data;
|
|
5625
|
-
const type = await (0,
|
|
5738
|
+
const type = await (0, import_scheduling45.createAppointmentType)(db, {
|
|
5626
5739
|
name: input.name,
|
|
5627
5740
|
slug: input.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""),
|
|
5628
5741
|
description: input.description || void 0,
|
|
@@ -5681,7 +5794,7 @@ async function createType(request, { host }) {
|
|
|
5681
5794
|
}
|
|
5682
5795
|
|
|
5683
5796
|
// src/handlers/admin-type-update.ts
|
|
5684
|
-
var
|
|
5797
|
+
var import_scheduling46 = require("@ordinatio/scheduling");
|
|
5685
5798
|
|
|
5686
5799
|
// src/handlers/type-ownership.ts
|
|
5687
5800
|
async function getOwnedAppointmentType(db, id, organizationId) {
|
|
@@ -5762,7 +5875,7 @@ async function updateType(request, { host, params }) {
|
|
|
5762
5875
|
const validation = await parseBody(request, UpdateAppointmentTypeSchema);
|
|
5763
5876
|
if (!validation.success) return validation.response;
|
|
5764
5877
|
const input = validation.data;
|
|
5765
|
-
const { type: updated, wasActive } = await (0,
|
|
5878
|
+
const { type: updated, wasActive } = await (0, import_scheduling46.updateAppointmentType)(db, id, organizationId, input);
|
|
5766
5879
|
if (input.isActive === false && wasActive && typeToUpdate.organizationId) {
|
|
5767
5880
|
await releaseTypeSlugIfStillInactive(host, db, id, typeToUpdate.organizationId, typeToUpdate.slug);
|
|
5768
5881
|
}
|
|
@@ -5779,7 +5892,7 @@ async function updateType(request, { host, params }) {
|
|
|
5779
5892
|
return Response.json({ error: getErrorMessage(error, "Validation error") }, { status: schedErrorStatus(code) });
|
|
5780
5893
|
}
|
|
5781
5894
|
const message = isSchedulingServiceError(error) ? error.description || error.message : getErrorMessage(error, "Failed to update appointment type");
|
|
5782
|
-
if (error instanceof
|
|
5895
|
+
if (error instanceof import_scheduling46.SchedulingValidationError) return Response.json({ error: message }, { status: 400 });
|
|
5783
5896
|
return Response.json({ error: message }, { status: 500 });
|
|
5784
5897
|
}
|
|
5785
5898
|
}
|
|
@@ -6031,7 +6144,7 @@ async function getStaffOptions(request, { host }) {
|
|
|
6031
6144
|
|
|
6032
6145
|
// src/handlers/appointment-ical.ts
|
|
6033
6146
|
var import_ical_generator = __toESM(require("ical-generator"));
|
|
6034
|
-
var
|
|
6147
|
+
var import_scheduling47 = require("@ordinatio/scheduling");
|
|
6035
6148
|
async function getAppointmentIcal(request, { host }) {
|
|
6036
6149
|
let token = null;
|
|
6037
6150
|
try {
|
|
@@ -6065,7 +6178,7 @@ async function getAppointmentIcal(request, { host }) {
|
|
|
6065
6178
|
timezone: appointment.timezone,
|
|
6066
6179
|
summary,
|
|
6067
6180
|
description,
|
|
6068
|
-
location: (0,
|
|
6181
|
+
location: (0, import_scheduling47.resolveLocation)(appointment) ?? void 0,
|
|
6069
6182
|
url: manageUrl,
|
|
6070
6183
|
organizer: staffName && staffEmail ? { name: staffName, email: staffEmail } : void 0
|
|
6071
6184
|
});
|
|
@@ -6077,17 +6190,17 @@ async function getAppointmentIcal(request, { host }) {
|
|
|
6077
6190
|
}
|
|
6078
6191
|
});
|
|
6079
6192
|
} catch (error) {
|
|
6080
|
-
const diagnostic = (0,
|
|
6193
|
+
const diagnostic = (0, import_scheduling47.schedError)("SCHED_600", { error, token: token ?? "unknown" });
|
|
6081
6194
|
console.error("[GET /ical]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
6082
6195
|
return Response.json({ error: "Failed to generate calendar file", ref: diagnostic.ref }, { status: 500 });
|
|
6083
6196
|
}
|
|
6084
6197
|
}
|
|
6085
6198
|
|
|
6086
6199
|
// src/handlers/admin-webhooks.ts
|
|
6087
|
-
var
|
|
6200
|
+
var import_scheduling49 = require("@ordinatio/scheduling");
|
|
6088
6201
|
|
|
6089
6202
|
// src/webhooks/require-webhooks.ts
|
|
6090
|
-
var
|
|
6203
|
+
var import_scheduling48 = require("@ordinatio/scheduling");
|
|
6091
6204
|
async function requireWebhooksAdmin(host, request, options) {
|
|
6092
6205
|
const staff = await requireAdminStaff(host, request, options);
|
|
6093
6206
|
if (staff instanceof Response) return staff;
|
|
@@ -6095,10 +6208,10 @@ async function requireWebhooksAdmin(host, request, options) {
|
|
|
6095
6208
|
return { staff, settings: host.webhooks };
|
|
6096
6209
|
}
|
|
6097
6210
|
function webhookErrorResponse(error, fallback) {
|
|
6098
|
-
if (error instanceof
|
|
6211
|
+
if (error instanceof import_scheduling48.SchedulingValidationError) {
|
|
6099
6212
|
return Response.json({ error: error.message, ref: getErrorRef(error) }, { status: 400 });
|
|
6100
6213
|
}
|
|
6101
|
-
if (error instanceof
|
|
6214
|
+
if (error instanceof import_scheduling48.SchedulingNotFoundError) {
|
|
6102
6215
|
return Response.json({ error: error.message, ref: getErrorRef(error) }, { status: 404 });
|
|
6103
6216
|
}
|
|
6104
6217
|
return Response.json({ error: getErrorMessage(error, fallback) }, { status: 500 });
|
|
@@ -6110,7 +6223,7 @@ async function listWebhooks(request, { host }) {
|
|
|
6110
6223
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-list", tier: "GENERAL" });
|
|
6111
6224
|
if (guard instanceof Response) return guard;
|
|
6112
6225
|
const { db, organizationId } = guard.staff;
|
|
6113
|
-
return Response.json({ endpoints: await (0,
|
|
6226
|
+
return Response.json({ endpoints: await (0, import_scheduling49.listWebhookEndpoints)(db, organizationId), eventTypes: import_scheduling49.WEBHOOK_EVENT_TYPES });
|
|
6114
6227
|
} catch (error) {
|
|
6115
6228
|
return webhookErrorResponse(error, "Failed to list webhooks");
|
|
6116
6229
|
}
|
|
@@ -6123,7 +6236,7 @@ async function createWebhook(request, { host }) {
|
|
|
6123
6236
|
const validation = await parseBody(request, CreateWebhookEndpointSchema);
|
|
6124
6237
|
if (!validation.success) return validation.response;
|
|
6125
6238
|
const input = validation.data;
|
|
6126
|
-
const { endpoint, secret } = await (0,
|
|
6239
|
+
const { endpoint, secret } = await (0, import_scheduling49.createWebhookEndpoint)(
|
|
6127
6240
|
db,
|
|
6128
6241
|
{ organizationId, url: input.url, eventTypes: input.eventTypes, description: input.description },
|
|
6129
6242
|
{ allowInsecureTargets: guard.settings.allowInsecureTargets }
|
|
@@ -6140,14 +6253,14 @@ async function createWebhook(request, { host }) {
|
|
|
6140
6253
|
}
|
|
6141
6254
|
|
|
6142
6255
|
// src/handlers/admin-webhook-detail.ts
|
|
6143
|
-
var
|
|
6256
|
+
var import_scheduling50 = require("@ordinatio/scheduling");
|
|
6144
6257
|
var STATUSES = /* @__PURE__ */ new Set(["PENDING", "PROCESSING", "SUCCEEDED", "DEAD_LETTER"]);
|
|
6145
6258
|
async function deleteWebhook(request, { host, params }) {
|
|
6146
6259
|
try {
|
|
6147
6260
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-delete", tier: "DELETE" });
|
|
6148
6261
|
if (guard instanceof Response) return guard;
|
|
6149
6262
|
const { db, organizationId } = guard.staff;
|
|
6150
|
-
await (0,
|
|
6263
|
+
await (0, import_scheduling50.deleteWebhookEndpoint)(db, organizationId, params.id);
|
|
6151
6264
|
await host.activity.log(db, {
|
|
6152
6265
|
action: "scheduling.webhook_deleted",
|
|
6153
6266
|
description: "removed a webhook endpoint",
|
|
@@ -6163,7 +6276,7 @@ async function testWebhook(request, { host, params }) {
|
|
|
6163
6276
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-test", tier: "CREATE" });
|
|
6164
6277
|
if (guard instanceof Response) return guard;
|
|
6165
6278
|
const { db, organizationId } = guard.staff;
|
|
6166
|
-
const result = await (0,
|
|
6279
|
+
const result = await (0, import_scheduling50.sendTestWebhook)(
|
|
6167
6280
|
db,
|
|
6168
6281
|
{ organizationId, endpointId: params.id },
|
|
6169
6282
|
{ transport: guard.settings.transport, allowInsecureTargets: guard.settings.allowInsecureTargets }
|
|
@@ -6179,13 +6292,13 @@ async function listWebhookEndpointDeliveries(request, { host, params }) {
|
|
|
6179
6292
|
if (guard instanceof Response) return guard;
|
|
6180
6293
|
const { db, organizationId } = guard.staff;
|
|
6181
6294
|
const owned = await db.webhookEndpoint.count({ where: { id: params.id, organizationId } });
|
|
6182
|
-
if (owned === 0) throw new
|
|
6295
|
+
if (owned === 0) throw new import_scheduling50.SchedulingNotFoundError("Webhook endpoint not found", "SCHED_1003", { endpointId: params.id });
|
|
6183
6296
|
const status = new URL(request.url).searchParams.get("status");
|
|
6184
6297
|
if (status && !STATUSES.has(status)) {
|
|
6185
6298
|
return Response.json({ error: `status must be one of ${[...STATUSES].join(", ")}` }, { status: 400 });
|
|
6186
6299
|
}
|
|
6187
6300
|
const { limit, offset } = parsePagination(request);
|
|
6188
|
-
const { deliveries, total } = await (0,
|
|
6301
|
+
const { deliveries, total } = await (0, import_scheduling50.listWebhookDeliveries)(db, {
|
|
6189
6302
|
organizationId,
|
|
6190
6303
|
endpointId: params.id,
|
|
6191
6304
|
status: status ?? void 0,
|
|
@@ -6199,13 +6312,13 @@ async function listWebhookEndpointDeliveries(request, { host, params }) {
|
|
|
6199
6312
|
}
|
|
6200
6313
|
|
|
6201
6314
|
// src/handlers/admin-webhook-delivery-retry.ts
|
|
6202
|
-
var
|
|
6315
|
+
var import_scheduling51 = require("@ordinatio/scheduling");
|
|
6203
6316
|
async function retryWebhook(request, { host, params }) {
|
|
6204
6317
|
try {
|
|
6205
6318
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-retry", tier: "UPDATE" });
|
|
6206
6319
|
if (guard instanceof Response) return guard;
|
|
6207
6320
|
const { db, organizationId } = guard.staff;
|
|
6208
|
-
await (0,
|
|
6321
|
+
await (0, import_scheduling51.retryWebhookDelivery)(db, organizationId, params.id);
|
|
6209
6322
|
return Response.json({ success: true });
|
|
6210
6323
|
} catch (error) {
|
|
6211
6324
|
return webhookErrorResponse(error, "Failed to retry the delivery");
|
|
@@ -6213,7 +6326,7 @@ async function retryWebhook(request, { host, params }) {
|
|
|
6213
6326
|
}
|
|
6214
6327
|
|
|
6215
6328
|
// src/handlers/internal-webhooks-deliver.ts
|
|
6216
|
-
var
|
|
6329
|
+
var import_scheduling52 = require("@ordinatio/scheduling");
|
|
6217
6330
|
async function deliverWebhooks(request, { host }) {
|
|
6218
6331
|
if (!await host.internalAccess.isAuthorized(request)) {
|
|
6219
6332
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
@@ -6222,7 +6335,7 @@ async function deliverWebhooks(request, { host }) {
|
|
|
6222
6335
|
const limited = await host.rateLimit(`${request.headers.get("x-forwarded-for") ?? "worker"}:webhooks-deliver`, "INTERNAL");
|
|
6223
6336
|
if (limited) return limited;
|
|
6224
6337
|
try {
|
|
6225
|
-
const summary = await (0,
|
|
6338
|
+
const summary = await (0, import_scheduling52.deliverDueWebhooks)(await host.publicDb(), {
|
|
6226
6339
|
transport: host.webhooks.transport,
|
|
6227
6340
|
allowInsecureTargets: host.webhooks.allowInsecureTargets
|
|
6228
6341
|
});
|
|
@@ -6234,11 +6347,11 @@ async function deliverWebhooks(request, { host }) {
|
|
|
6234
6347
|
}
|
|
6235
6348
|
|
|
6236
6349
|
// src/handlers/waitlist-join.ts
|
|
6237
|
-
var
|
|
6238
|
-
var
|
|
6350
|
+
var import_scheduling54 = require("@ordinatio/scheduling");
|
|
6351
|
+
var import_zod19 = require("zod");
|
|
6239
6352
|
|
|
6240
6353
|
// src/waitlist/waitlist-http.ts
|
|
6241
|
-
var
|
|
6354
|
+
var import_scheduling53 = require("@ordinatio/scheduling");
|
|
6242
6355
|
var NOT_ENABLED2 = { error: "The waitlist is not enabled on this server" };
|
|
6243
6356
|
var STATUS_BY_CODE = {
|
|
6244
6357
|
SCHED_1100: 404,
|
|
@@ -6253,8 +6366,8 @@ async function resolveWaitlistDb(host, orgSlug) {
|
|
|
6253
6366
|
return host.organizations.resolve({ orgSlug, logPrefix: "[waitlist]" });
|
|
6254
6367
|
}
|
|
6255
6368
|
function waitlistErrorResponse(cors, error, fallback) {
|
|
6256
|
-
if (error instanceof
|
|
6257
|
-
const status = STATUS_BY_CODE[error.code] ?? (error instanceof
|
|
6369
|
+
if (error instanceof import_scheduling53.SchedulingValidationError || error instanceof import_scheduling53.SchedulingNotFoundError) {
|
|
6370
|
+
const status = STATUS_BY_CODE[error.code] ?? (error instanceof import_scheduling53.SchedulingNotFoundError ? 404 : 400);
|
|
6258
6371
|
return corsJson(cors, { error: error.message, code: error.code, ref: getErrorRef(error) }, { status });
|
|
6259
6372
|
}
|
|
6260
6373
|
console.error("[waitlist]", error);
|
|
@@ -6268,15 +6381,15 @@ async function requireWaitlistAdmin(host, request, options) {
|
|
|
6268
6381
|
}
|
|
6269
6382
|
|
|
6270
6383
|
// src/handlers/waitlist-join.ts
|
|
6271
|
-
var JoinWaitlistSchema =
|
|
6272
|
-
orgSlug:
|
|
6273
|
-
typeId:
|
|
6274
|
-
calendarId:
|
|
6275
|
-
day:
|
|
6276
|
-
slotStart:
|
|
6277
|
-
clientName:
|
|
6278
|
-
clientEmail:
|
|
6279
|
-
clientPhone:
|
|
6384
|
+
var JoinWaitlistSchema = import_zod19.z.object({
|
|
6385
|
+
orgSlug: import_zod19.z.string().min(1).max(100).optional(),
|
|
6386
|
+
typeId: import_zod19.z.string().min(1),
|
|
6387
|
+
calendarId: import_zod19.z.string().min(1).optional(),
|
|
6388
|
+
day: import_zod19.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Day must be YYYY-MM-DD"),
|
|
6389
|
+
slotStart: import_zod19.z.string().datetime({ message: "Invalid date/time format" }).optional(),
|
|
6390
|
+
clientName: import_zod19.z.string().trim().min(1, "Name is required").max(200),
|
|
6391
|
+
clientEmail: import_zod19.z.string().email("Invalid email").max(254),
|
|
6392
|
+
clientPhone: import_zod19.z.string().max(30).optional()
|
|
6280
6393
|
});
|
|
6281
6394
|
async function joinWaitlistRoute(request, { host }) {
|
|
6282
6395
|
const cors = host.cors(request);
|
|
@@ -6298,7 +6411,7 @@ async function joinWaitlistRoute(request, { host }) {
|
|
|
6298
6411
|
organizationId = type?.organizationId ?? null;
|
|
6299
6412
|
}
|
|
6300
6413
|
if (!organizationId) return corsJson(cors, { error: "Appointment type not found" }, { status: 404 });
|
|
6301
|
-
const { entry, token } = await (0,
|
|
6414
|
+
const { entry, token } = await (0, import_scheduling54.joinWaitlist)(context.db, {
|
|
6302
6415
|
organizationId,
|
|
6303
6416
|
typeId: body.typeId,
|
|
6304
6417
|
calendarId: body.calendarId,
|
|
@@ -6324,7 +6437,7 @@ async function leaveWaitlistRoute(request, { host }) {
|
|
|
6324
6437
|
if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6325
6438
|
const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
|
|
6326
6439
|
if (!context) return corsJson(cors, { error: "No waitlist entry for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6327
|
-
const freed = await (0,
|
|
6440
|
+
const freed = await (0, import_scheduling54.leaveWaitlist)(context.db, token);
|
|
6328
6441
|
if (freed) await offerAndAnnounce(host, host.waitlist, context.db, freed);
|
|
6329
6442
|
return corsJson(cors, { success: true });
|
|
6330
6443
|
} catch (error) {
|
|
@@ -6333,40 +6446,40 @@ async function leaveWaitlistRoute(request, { host }) {
|
|
|
6333
6446
|
}
|
|
6334
6447
|
|
|
6335
6448
|
// src/handlers/waitlist-offer.ts
|
|
6336
|
-
var
|
|
6337
|
-
var
|
|
6449
|
+
var import_scheduling59 = require("@ordinatio/scheduling");
|
|
6450
|
+
var import_zod21 = require("zod");
|
|
6338
6451
|
|
|
6339
6452
|
// src/handlers/appointments-book.ts
|
|
6340
|
-
var
|
|
6453
|
+
var import_scheduling58 = require("@ordinatio/scheduling");
|
|
6341
6454
|
|
|
6342
6455
|
// src/booking/booking-schema.ts
|
|
6343
|
-
var
|
|
6344
|
-
var BookingSchema =
|
|
6345
|
-
calendarId:
|
|
6346
|
-
preferredCalendarId:
|
|
6347
|
-
typeId:
|
|
6348
|
-
startTime:
|
|
6349
|
-
timezone:
|
|
6350
|
-
clientName:
|
|
6351
|
-
clientEmail:
|
|
6352
|
-
clientPhone:
|
|
6456
|
+
var import_zod20 = require("zod");
|
|
6457
|
+
var BookingSchema = import_zod20.z.object({
|
|
6458
|
+
calendarId: import_zod20.z.string().min(1).optional(),
|
|
6459
|
+
preferredCalendarId: import_zod20.z.string().min(1).optional(),
|
|
6460
|
+
typeId: import_zod20.z.string().min(1),
|
|
6461
|
+
startTime: import_zod20.z.string().datetime({ message: "Invalid date/time format" }),
|
|
6462
|
+
timezone: import_zod20.z.string().max(50).optional(),
|
|
6463
|
+
clientName: import_zod20.z.string().trim().min(1, "Name is required").max(200),
|
|
6464
|
+
clientEmail: import_zod20.z.string().email("Invalid email").max(254),
|
|
6465
|
+
clientPhone: import_zod20.z.string().max(30).optional(),
|
|
6353
6466
|
// Untrusted: the host's client resolver decides whether to honor it.
|
|
6354
|
-
clientId:
|
|
6355
|
-
notes:
|
|
6467
|
+
clientId: import_zod20.z.string().optional(),
|
|
6468
|
+
notes: import_zod20.z.string().max(1e3).optional(),
|
|
6356
6469
|
// Only the primitive types a form field produces; z.unknown() would accept anything.
|
|
6357
|
-
intakeResponses:
|
|
6358
|
-
|
|
6359
|
-
|
|
6470
|
+
intakeResponses: import_zod20.z.record(
|
|
6471
|
+
import_zod20.z.string(),
|
|
6472
|
+
import_zod20.z.union([import_zod20.z.string().max(1e3), import_zod20.z.number(), import_zod20.z.boolean(), import_zod20.z.null()])
|
|
6360
6473
|
).optional(),
|
|
6361
|
-
paymentId:
|
|
6362
|
-
couponCode:
|
|
6363
|
-
packagePurchaseId:
|
|
6474
|
+
paymentId: import_zod20.z.string().optional(),
|
|
6475
|
+
couponCode: import_zod20.z.string().min(1).max(50).transform((value) => value.trim().toUpperCase()).optional(),
|
|
6476
|
+
packagePurchaseId: import_zod20.z.string().optional(),
|
|
6364
6477
|
// Names the organization, so the calendar and type lookups can run against its own database.
|
|
6365
|
-
orgSlug:
|
|
6478
|
+
orgSlug: import_zod20.z.string().min(1).max(100).optional()
|
|
6366
6479
|
});
|
|
6367
6480
|
|
|
6368
6481
|
// src/booking/finalize-booking.ts
|
|
6369
|
-
var
|
|
6482
|
+
var import_scheduling55 = require("@ordinatio/scheduling");
|
|
6370
6483
|
async function finalizeBooking(host, cors, db, organizationId, body, appointment, appointmentType, discountCents, appliedCouponCode, noShowApprovalOverride, clientId) {
|
|
6371
6484
|
const logActivity = (action, description, metadata) => host.activity.log(db, { action, description, metadata });
|
|
6372
6485
|
if (noShowApprovalOverride && appointment.status === "CONFIRMED") {
|
|
@@ -6409,7 +6522,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6409
6522
|
AND ("expiresAt" IS NULL OR "expiresAt" > NOW())
|
|
6410
6523
|
`;
|
|
6411
6524
|
if (counted === 0) {
|
|
6412
|
-
await (0,
|
|
6525
|
+
await (0, import_scheduling55.cancelAppointment)(db, {
|
|
6413
6526
|
appointmentId: appointment.id,
|
|
6414
6527
|
cancelledBy: "system",
|
|
6415
6528
|
reason: "Coupon exhausted by concurrent booking during payment"
|
|
@@ -6428,7 +6541,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6428
6541
|
}
|
|
6429
6542
|
let meetingUrl = null;
|
|
6430
6543
|
if (appointmentType.locationType === "VIRTUAL") {
|
|
6431
|
-
meetingUrl = (0,
|
|
6544
|
+
meetingUrl = (0, import_scheduling55.buildJitsiUrl)(appointment.id);
|
|
6432
6545
|
try {
|
|
6433
6546
|
await db.appointment.update({ where: { id: appointment.id }, data: { meetingUrl } });
|
|
6434
6547
|
} catch (meetingError) {
|
|
@@ -6453,7 +6566,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6453
6566
|
const baseUrl = host.appUrl();
|
|
6454
6567
|
if (!baseUrl) throw new Error("The host must supply appUrl() to book appointments");
|
|
6455
6568
|
try {
|
|
6456
|
-
await (0,
|
|
6569
|
+
await (0, import_scheduling55.scheduleNotifications)(db, appointment.id, baseUrl, { brand: Boolean(host.brand) });
|
|
6457
6570
|
} catch (error) {
|
|
6458
6571
|
await logActivity(
|
|
6459
6572
|
"scheduling.notification_schedule_failed",
|
|
@@ -6462,7 +6575,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6462
6575
|
);
|
|
6463
6576
|
}
|
|
6464
6577
|
try {
|
|
6465
|
-
await (0,
|
|
6578
|
+
await (0, import_scheduling55.queueStaffNotification)(db, appointment.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) });
|
|
6466
6579
|
} catch (error) {
|
|
6467
6580
|
await logActivity(
|
|
6468
6581
|
"scheduling.staff_notification_failed",
|
|
@@ -6516,7 +6629,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6516
6629
|
}
|
|
6517
6630
|
|
|
6518
6631
|
// src/booking/refund-blocked-booking.ts
|
|
6519
|
-
var
|
|
6632
|
+
var import_scheduling56 = require("@ordinatio/scheduling");
|
|
6520
6633
|
var REFUND_ON_CODES = ["SCHED_301", "SCHED_307", "SCHED_802", "SCHED_800", "SCHED_801", "SCHED_201", "SCHED_100", "SCHED_200", "SCHED_102"];
|
|
6521
6634
|
function isBlockedBookingCode(code) {
|
|
6522
6635
|
return code !== void 0 && REFUND_ON_CODES.includes(code);
|
|
@@ -6531,12 +6644,12 @@ async function respondToBlockedPaidBooking(db, payments, cors, paymentId, blocke
|
|
|
6531
6644
|
try {
|
|
6532
6645
|
existingBooking = await db.appointment.findFirst({ where: { paymentId }, select: { id: true } });
|
|
6533
6646
|
} catch (lookupError) {
|
|
6534
|
-
const err = (0,
|
|
6647
|
+
const err = (0, import_scheduling56.schedError)("SCHED_409", { paymentId, blockerCode, error: lookupError });
|
|
6535
6648
|
console.error("[booking] Could not check for an existing booking before refunding:", err.ref, lookupError);
|
|
6536
6649
|
return corsJson(cors, { error: "We could not confirm your booking just now. Please try again.", ref: err.ref }, { status: 503 });
|
|
6537
6650
|
}
|
|
6538
6651
|
if (existingBooking) {
|
|
6539
|
-
const err = (0,
|
|
6652
|
+
const err = (0, import_scheduling56.schedError)("SCHED_404", { paymentId, existingAppointmentId: existingBooking.id });
|
|
6540
6653
|
return corsJson(
|
|
6541
6654
|
cors,
|
|
6542
6655
|
{ error: "This payment has already been used for a booking", ref: err.ref, code: "PAYMENT_ALREADY_USED" },
|
|
@@ -6667,7 +6780,7 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6667
6780
|
}
|
|
6668
6781
|
|
|
6669
6782
|
// src/booking/verify-booking-payment.ts
|
|
6670
|
-
var
|
|
6783
|
+
var import_scheduling57 = require("@ordinatio/scheduling");
|
|
6671
6784
|
async function verifyBookingPayment(db, payments, cors, organizationId, appointmentType, body) {
|
|
6672
6785
|
const refuse = (status, payload) => ({
|
|
6673
6786
|
ok: false,
|
|
@@ -6684,7 +6797,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6684
6797
|
select: { id: true }
|
|
6685
6798
|
});
|
|
6686
6799
|
if (existingBooking) {
|
|
6687
|
-
const err = (0,
|
|
6800
|
+
const err = (0, import_scheduling57.schedError)("SCHED_404", { paymentId: body.paymentId, existingAppointmentId: existingBooking.id });
|
|
6688
6801
|
return refuse(409, {
|
|
6689
6802
|
error: "This payment has already been used for a booking",
|
|
6690
6803
|
ref: err.ref,
|
|
@@ -6694,7 +6807,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6694
6807
|
const metaTypeId = payment.metadata?.typeId;
|
|
6695
6808
|
const metaClientEmail = payment.metadata?.clientEmail;
|
|
6696
6809
|
if (metaTypeId !== body.typeId || metaClientEmail && metaClientEmail.toLowerCase() !== body.clientEmail.toLowerCase()) {
|
|
6697
|
-
const err = (0,
|
|
6810
|
+
const err = (0, import_scheduling57.schedError)("SCHED_405", {
|
|
6698
6811
|
paymentId: body.paymentId,
|
|
6699
6812
|
metaTypeId,
|
|
6700
6813
|
bodyTypeId: body.typeId,
|
|
@@ -6724,7 +6837,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6724
6837
|
}
|
|
6725
6838
|
}
|
|
6726
6839
|
if (payment.amount === void 0) {
|
|
6727
|
-
const err = (0,
|
|
6840
|
+
const err = (0, import_scheduling57.schedError)("SCHED_405", { paymentId: body.paymentId, currency: payment.currency });
|
|
6728
6841
|
return refuse(400, { error: "Payment currency is not supported", ref: err.ref });
|
|
6729
6842
|
}
|
|
6730
6843
|
if (Math.round(payment.amount * 100) !== expectedCents) {
|
|
@@ -6765,7 +6878,7 @@ async function bookAppointmentRoute(request, { host }) {
|
|
|
6765
6878
|
} catch (linkError) {
|
|
6766
6879
|
console.error("[booking] client link lookup failed \u2014 saving the appointment unlinked:", linkError instanceof Error ? linkError.message : linkError);
|
|
6767
6880
|
}
|
|
6768
|
-
const appointment = await (0,
|
|
6881
|
+
const appointment = await (0, import_scheduling58.bookAppointment)(db, {
|
|
6769
6882
|
calendarId: body.calendarId,
|
|
6770
6883
|
preferredCalendarId: body.preferredCalendarId,
|
|
6771
6884
|
typeId: body.typeId,
|
|
@@ -6839,7 +6952,7 @@ async function getWaitlistOfferRoute(request, { host }) {
|
|
|
6839
6952
|
if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6840
6953
|
const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
|
|
6841
6954
|
if (!context) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6842
|
-
const offer = await (0,
|
|
6955
|
+
const offer = await (0, import_scheduling59.getWaitlistOffer)(context.db, token);
|
|
6843
6956
|
return corsJson(cors, {
|
|
6844
6957
|
typeName: offer.typeName,
|
|
6845
6958
|
calendarName: offer.calendarName,
|
|
@@ -6852,7 +6965,7 @@ async function getWaitlistOfferRoute(request, { host }) {
|
|
|
6852
6965
|
return waitlistErrorResponse(cors, error, "Failed to read the offer");
|
|
6853
6966
|
}
|
|
6854
6967
|
}
|
|
6855
|
-
var AcceptSchema =
|
|
6968
|
+
var AcceptSchema = import_zod21.z.object({ token: import_zod21.z.string().min(1).max(200), orgSlug: import_zod21.z.string().min(1).max(100).optional() });
|
|
6856
6969
|
async function acceptWaitlistOfferRoute(request, context) {
|
|
6857
6970
|
const { host } = context;
|
|
6858
6971
|
const cors = host.cors(request);
|
|
@@ -6868,7 +6981,7 @@ async function acceptWaitlistOfferRoute(request, context) {
|
|
|
6868
6981
|
if (!parsed.success) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6869
6982
|
db = await resolveWaitlistDb(host, parsed.data.orgSlug);
|
|
6870
6983
|
if (!db) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6871
|
-
const offer = await (0,
|
|
6984
|
+
const offer = await (0, import_scheduling59.beginWaitlistAccept)(db.db, parsed.data.token);
|
|
6872
6985
|
entryId = offer.entryId;
|
|
6873
6986
|
const headers = new Headers(request.headers);
|
|
6874
6987
|
headers.set("content-type", "application/json");
|
|
@@ -6893,20 +7006,20 @@ async function acceptWaitlistOfferRoute(request, context) {
|
|
|
6893
7006
|
booked = true;
|
|
6894
7007
|
const appointment = await response.clone().json().catch(() => null);
|
|
6895
7008
|
try {
|
|
6896
|
-
await (0,
|
|
7009
|
+
await (0, import_scheduling59.completeWaitlistAccept)(db.db, entryId, appointment?.id ?? "");
|
|
6897
7010
|
} catch (completeError) {
|
|
6898
7011
|
console.error("[waitlist] the booking was saved but its waitlist entry could not be marked booked:", completeError);
|
|
6899
7012
|
}
|
|
6900
7013
|
return response;
|
|
6901
7014
|
}
|
|
6902
|
-
const saved = await (0,
|
|
7015
|
+
const saved = await (0, import_scheduling59.settleBookedAccept)(db.db, entryId);
|
|
6903
7016
|
if (saved) return corsJson(cors, saved, { status: 201 });
|
|
6904
7017
|
await endFailedAccept(host, settings, db.db, entryId, releaseFor(response.status));
|
|
6905
7018
|
return response;
|
|
6906
7019
|
} catch (error) {
|
|
6907
7020
|
if (entryId && db && !booked) {
|
|
6908
7021
|
try {
|
|
6909
|
-
const saved = await (0,
|
|
7022
|
+
const saved = await (0, import_scheduling59.settleBookedAccept)(db.db, entryId);
|
|
6910
7023
|
if (saved) return corsJson(cors, saved, { status: 201 });
|
|
6911
7024
|
await endFailedAccept(host, settings, db.db, entryId, "KEEP_OFFER");
|
|
6912
7025
|
} catch (releaseError) {
|
|
@@ -6922,12 +7035,12 @@ function releaseFor(status) {
|
|
|
6922
7035
|
return "DROP";
|
|
6923
7036
|
}
|
|
6924
7037
|
async function endFailedAccept(host, settings, db, entryId, outcome) {
|
|
6925
|
-
const freed = await (0,
|
|
7038
|
+
const freed = await (0, import_scheduling59.releaseWaitlistAccept)(db, entryId, outcome);
|
|
6926
7039
|
if (freed) await offerAndAnnounce(host, settings, db, freed);
|
|
6927
7040
|
}
|
|
6928
7041
|
|
|
6929
7042
|
// src/handlers/admin-waitlist.ts
|
|
6930
|
-
var
|
|
7043
|
+
var import_scheduling60 = require("@ordinatio/scheduling");
|
|
6931
7044
|
var STATUSES2 = /* @__PURE__ */ new Set(["WAITING", "OFFERED", "ACCEPTING", "BOOKED", "EXPIRED"]);
|
|
6932
7045
|
async function listWaitlistEntries(request, { host }) {
|
|
6933
7046
|
try {
|
|
@@ -6938,7 +7051,7 @@ async function listWaitlistEntries(request, { host }) {
|
|
|
6938
7051
|
return Response.json({ error: `status must be one of ${[...STATUSES2].join(", ")}` }, { status: 400 });
|
|
6939
7052
|
}
|
|
6940
7053
|
const { limit, offset } = parsePagination(request);
|
|
6941
|
-
const { entries, total } = await (0,
|
|
7054
|
+
const { entries, total } = await (0, import_scheduling60.listWaitlist)(guard.staff.db, {
|
|
6942
7055
|
organizationId: guard.staff.organizationId,
|
|
6943
7056
|
status: status ?? void 0,
|
|
6944
7057
|
limit,
|
|
@@ -6954,7 +7067,7 @@ async function removeWaitlistEntryRoute(request, { host, params }) {
|
|
|
6954
7067
|
const guard = await requireWaitlistAdmin(host, request, { action: "admin-waitlist-remove", tier: "DELETE" });
|
|
6955
7068
|
if (guard instanceof Response) return guard;
|
|
6956
7069
|
const { db, organizationId } = guard.staff;
|
|
6957
|
-
const freed = await (0,
|
|
7070
|
+
const freed = await (0, import_scheduling60.removeWaitlistEntry)(db, organizationId, params.id);
|
|
6958
7071
|
await host.activity.log(db, {
|
|
6959
7072
|
action: "scheduling.waitlist_entry_removed",
|
|
6960
7073
|
description: "removed someone from the waitlist",
|
|
@@ -6968,7 +7081,7 @@ async function removeWaitlistEntryRoute(request, { host, params }) {
|
|
|
6968
7081
|
}
|
|
6969
7082
|
|
|
6970
7083
|
// src/handlers/internal-waitlist-sweep.ts
|
|
6971
|
-
var
|
|
7084
|
+
var import_scheduling61 = require("@ordinatio/scheduling");
|
|
6972
7085
|
async function sweepWaitlist(request, { host }) {
|
|
6973
7086
|
if (!await host.internalAccess.isAuthorized(request)) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
6974
7087
|
if (!host.waitlist) return Response.json(NOT_ENABLED2, { status: 501 });
|
|
@@ -6976,7 +7089,7 @@ async function sweepWaitlist(request, { host }) {
|
|
|
6976
7089
|
if (limited) return limited;
|
|
6977
7090
|
try {
|
|
6978
7091
|
const db = await host.publicDb();
|
|
6979
|
-
const { lapsed, released, booked } = await (0,
|
|
7092
|
+
const { lapsed, released, booked } = await (0, import_scheduling61.expireWaitlistOffers)(db);
|
|
6980
7093
|
let reoffered = 0;
|
|
6981
7094
|
for (const slot of lapsed) {
|
|
6982
7095
|
if (await offerAndAnnounce(host, host.waitlist, db, slot)) reoffered++;
|
|
@@ -6989,15 +7102,15 @@ async function sweepWaitlist(request, { host }) {
|
|
|
6989
7102
|
}
|
|
6990
7103
|
|
|
6991
7104
|
// src/handlers/routing-forms-public.ts
|
|
6992
|
-
var
|
|
7105
|
+
var import_scheduling63 = require("@ordinatio/scheduling");
|
|
6993
7106
|
|
|
6994
7107
|
// src/routing/routing-http.ts
|
|
6995
|
-
var
|
|
7108
|
+
var import_scheduling62 = require("@ordinatio/scheduling");
|
|
6996
7109
|
var NOT_ENABLED3 = { error: "Routing forms are not enabled on this server" };
|
|
6997
7110
|
var STATUS_BY_CODE2 = { SCHED_1201: 404, SCHED_1202: 409, SCHED_1204: 409 };
|
|
6998
7111
|
function routingErrorResponse(error, fallback, cors) {
|
|
6999
7112
|
const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
|
|
7000
|
-
if (error instanceof
|
|
7113
|
+
if (error instanceof import_scheduling62.SchedulingValidationError || error instanceof import_scheduling62.SchedulingNotFoundError) {
|
|
7001
7114
|
const details = error.context.errors;
|
|
7002
7115
|
const status = STATUS_BY_CODE2[error.code] ?? 400;
|
|
7003
7116
|
return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, status);
|
|
@@ -7028,7 +7141,7 @@ async function getRoutingFormRoute(request, { host }) {
|
|
|
7028
7141
|
if (!slug) return corsJson(cors, { error: "slug is required" }, { status: 400 });
|
|
7029
7142
|
const context = await resolveOrganization(host, url.searchParams.get("orgSlug"));
|
|
7030
7143
|
if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
|
|
7031
|
-
return corsJson(cors, await (0,
|
|
7144
|
+
return corsJson(cors, await (0, import_scheduling63.getPublicRoutingForm)(context.db, { organizationId: context.organizationId, slug }));
|
|
7032
7145
|
} catch (error) {
|
|
7033
7146
|
return routingErrorResponse(error, "Failed to read the form", cors);
|
|
7034
7147
|
}
|
|
@@ -7046,7 +7159,7 @@ async function routeClientRoute(request, { host }) {
|
|
|
7046
7159
|
}
|
|
7047
7160
|
const context = await resolveOrganization(host, parsed.data.orgSlug);
|
|
7048
7161
|
if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
|
|
7049
|
-
const outcome = await (0,
|
|
7162
|
+
const outcome = await (0, import_scheduling63.routeClient)(context.db, { organizationId: context.organizationId, slug: parsed.data.slug, answers: parsed.data.answers });
|
|
7050
7163
|
return corsJson(cors, outcome);
|
|
7051
7164
|
} catch (error) {
|
|
7052
7165
|
return routingErrorResponse(error, "Failed to route the answers", cors);
|
|
@@ -7054,12 +7167,12 @@ async function routeClientRoute(request, { host }) {
|
|
|
7054
7167
|
}
|
|
7055
7168
|
|
|
7056
7169
|
// src/handlers/admin-routing-forms.ts
|
|
7057
|
-
var
|
|
7170
|
+
var import_scheduling64 = require("@ordinatio/scheduling");
|
|
7058
7171
|
async function listRoutingFormsRoute(request, { host }) {
|
|
7059
7172
|
try {
|
|
7060
7173
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-list", tier: "GENERAL" });
|
|
7061
7174
|
if (staff instanceof Response) return staff;
|
|
7062
|
-
return Response.json({ forms: await (0,
|
|
7175
|
+
return Response.json({ forms: await (0, import_scheduling64.listRoutingForms)(staff.db, staff.organizationId) });
|
|
7063
7176
|
} catch (error) {
|
|
7064
7177
|
return routingErrorResponse(error, "Failed to list the forms");
|
|
7065
7178
|
}
|
|
@@ -7070,7 +7183,7 @@ async function createRoutingFormRoute(request, { host }) {
|
|
|
7070
7183
|
if (staff instanceof Response) return staff;
|
|
7071
7184
|
const validation = await parseBody(request, CreateRoutingFormSchema);
|
|
7072
7185
|
if (!validation.success) return validation.response;
|
|
7073
|
-
const form = await (0,
|
|
7186
|
+
const form = await (0, import_scheduling64.createRoutingForm)(staff.db, staff.organizationId, validation.data);
|
|
7074
7187
|
await host.activity.log(staff.db, {
|
|
7075
7188
|
action: "scheduling.routing_form_created",
|
|
7076
7189
|
description: `created routing form "${form.name}"`,
|
|
@@ -7083,7 +7196,7 @@ async function createRoutingFormRoute(request, { host }) {
|
|
|
7083
7196
|
}
|
|
7084
7197
|
|
|
7085
7198
|
// src/handlers/brand-public.ts
|
|
7086
|
-
var
|
|
7199
|
+
var import_scheduling65 = require("@ordinatio/scheduling");
|
|
7087
7200
|
async function getBrandRoute(request, { host }) {
|
|
7088
7201
|
const cors = host.cors(request);
|
|
7089
7202
|
if (!host.brand) return corsJson(cors, NOT_ENABLED, { status: 501 });
|
|
@@ -7092,7 +7205,7 @@ async function getBrandRoute(request, { host }) {
|
|
|
7092
7205
|
if (limited) return limited;
|
|
7093
7206
|
const orgSlug = new URL(request.url).searchParams.get("orgSlug");
|
|
7094
7207
|
const context = orgSlug ? await host.organizations.resolve({ orgSlug, logPrefix: "[brand]" }) : { db: await host.publicDb(), organizationId: null };
|
|
7095
|
-
const brand = context ? await (0,
|
|
7208
|
+
const brand = context ? await (0, import_scheduling65.getPublicBrand)(context.db, context.organizationId) : null;
|
|
7096
7209
|
if (!brand) return corsJson(cors, { error: "No brand set" }, { status: 404 });
|
|
7097
7210
|
return corsJson(cors, { brand }, { headers: WIDGET_CACHE_HEADERS });
|
|
7098
7211
|
} catch (error) {
|
|
@@ -7101,12 +7214,12 @@ async function getBrandRoute(request, { host }) {
|
|
|
7101
7214
|
}
|
|
7102
7215
|
|
|
7103
7216
|
// src/handlers/admin-brand.ts
|
|
7104
|
-
var
|
|
7217
|
+
var import_scheduling66 = require("@ordinatio/scheduling");
|
|
7105
7218
|
async function getBrandAdminRoute(request, { host }) {
|
|
7106
7219
|
try {
|
|
7107
7220
|
const staff = await requireBrandAdmin(host, request, { action: "admin-brand-get", tier: "GENERAL" });
|
|
7108
7221
|
if (staff instanceof Response) return staff;
|
|
7109
|
-
return Response.json({ brand: await (0,
|
|
7222
|
+
return Response.json({ brand: await (0, import_scheduling66.getBrand)(staff.db, staff.organizationId) });
|
|
7110
7223
|
} catch (error) {
|
|
7111
7224
|
return brandErrorResponse(error, "Failed to read the brand");
|
|
7112
7225
|
}
|
|
@@ -7118,7 +7231,7 @@ async function saveBrandRoute(request, { host }) {
|
|
|
7118
7231
|
const validation = await parseBody(request, BrandSchema);
|
|
7119
7232
|
if (!validation.success) return validation.response;
|
|
7120
7233
|
const verifier = host.brand?.isSendingDomainVerified;
|
|
7121
|
-
const brand = await (0,
|
|
7234
|
+
const brand = await (0, import_scheduling66.saveBrand)(staff.db, staff.organizationId, validation.data, {
|
|
7122
7235
|
isSendingDomainVerified: verifier ? async (domain) => Boolean(await verifier.call(host.brand, domain, staff.organizationId)) : void 0
|
|
7123
7236
|
});
|
|
7124
7237
|
await host.activity.log(staff.db, {
|
|
@@ -7135,7 +7248,7 @@ async function deleteBrandRoute(request, { host }) {
|
|
|
7135
7248
|
try {
|
|
7136
7249
|
const staff = await requireBrandAdmin(host, request, { action: "admin-brand-delete", tier: "DELETE" });
|
|
7137
7250
|
if (staff instanceof Response) return staff;
|
|
7138
|
-
const removed = await (0,
|
|
7251
|
+
const removed = await (0, import_scheduling66.deleteBrand)(staff.db, staff.organizationId);
|
|
7139
7252
|
if (removed) await host.activity.log(staff.db, { action: "scheduling.brand_removed", description: "removed the brand", metadata: {} });
|
|
7140
7253
|
return Response.json({ removed });
|
|
7141
7254
|
} catch (error) {
|
|
@@ -7143,11 +7256,211 @@ async function deleteBrandRoute(request, { host }) {
|
|
|
7143
7256
|
}
|
|
7144
7257
|
}
|
|
7145
7258
|
|
|
7146
|
-
// src/handlers/admin-
|
|
7147
|
-
var
|
|
7148
|
-
var NOT_ENABLED4 = { error: "
|
|
7259
|
+
// src/handlers/admin-api-keys.ts
|
|
7260
|
+
var import_scheduling67 = require("@ordinatio/scheduling");
|
|
7261
|
+
var NOT_ENABLED4 = { error: "API keys are not enabled on this server" };
|
|
7149
7262
|
function failure3(error, fallback) {
|
|
7150
|
-
if (error instanceof
|
|
7263
|
+
if (error instanceof import_scheduling67.SchedulingValidationError) {
|
|
7264
|
+
const details = error.context.errors;
|
|
7265
|
+
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
|
|
7266
|
+
}
|
|
7267
|
+
console.error("[api-keys]", error);
|
|
7268
|
+
return Response.json({ error: fallback }, { status: 500 });
|
|
7269
|
+
}
|
|
7270
|
+
async function requireKeyAdmin(host, request, options) {
|
|
7271
|
+
const staff = await requireAdminStaff(host, request, options);
|
|
7272
|
+
if (staff instanceof Response) return staff;
|
|
7273
|
+
if (!host.apiKeys) return Response.json(NOT_ENABLED4, { status: 501 });
|
|
7274
|
+
if (staff.role.startsWith(API_KEY_ROLE_PREFIX)) return Response.json({ error: "API keys are managed by a signed-in person, not with an API key" }, { status: 403 });
|
|
7275
|
+
return staff;
|
|
7276
|
+
}
|
|
7277
|
+
async function listApiKeysRoute(request, { host }) {
|
|
7278
|
+
try {
|
|
7279
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-list", tier: "GENERAL" });
|
|
7280
|
+
if (staff instanceof Response) return staff;
|
|
7281
|
+
return Response.json({ keys: await (0, import_scheduling67.listApiKeys)(staff.db, staff.organizationId) });
|
|
7282
|
+
} catch (error) {
|
|
7283
|
+
return failure3(error, "Failed to list the API keys");
|
|
7284
|
+
}
|
|
7285
|
+
}
|
|
7286
|
+
async function createApiKeyRoute(request, { host }) {
|
|
7287
|
+
try {
|
|
7288
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-create", tier: "SETTINGS" });
|
|
7289
|
+
if (staff instanceof Response) return staff;
|
|
7290
|
+
const validation = await parseBody(request, ApiKeySchema);
|
|
7291
|
+
if (!validation.success) return validation.response;
|
|
7292
|
+
const { key, view } = await (0, import_scheduling67.createApiKey)(staff.db, staff.organizationId, validation.data, staff.userId);
|
|
7293
|
+
await host.activity.log(staff.db, { action: "scheduling.api_key_created", description: `made the API key "${view.name}"`, metadata: { keyId: view.id, access: view.access } }).catch((error) => {
|
|
7294
|
+
console.error("[api-keys] could not record the new key in the activity log", error);
|
|
7295
|
+
});
|
|
7296
|
+
return Response.json({ key, apiKey: view }, { status: 201, headers: { "Cache-Control": "no-store" } });
|
|
7297
|
+
} catch (error) {
|
|
7298
|
+
return failure3(error, "Failed to make the API key");
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
async function revokeApiKeyRoute(request, { host, params }) {
|
|
7302
|
+
try {
|
|
7303
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-revoke", tier: "DELETE" });
|
|
7304
|
+
if (staff instanceof Response) return staff;
|
|
7305
|
+
const revoked = await (0, import_scheduling67.revokeApiKey)(staff.db, staff.organizationId, params.id);
|
|
7306
|
+
if (revoked) await host.activity.log(staff.db, { action: "scheduling.api_key_revoked", description: "revoked an API key", metadata: { keyId: params.id } });
|
|
7307
|
+
return Response.json({ revoked });
|
|
7308
|
+
} catch (error) {
|
|
7309
|
+
return failure3(error, "Failed to revoke the API key");
|
|
7310
|
+
}
|
|
7311
|
+
}
|
|
7312
|
+
|
|
7313
|
+
// src/handlers/admin-gift-certificates.ts
|
|
7314
|
+
var import_scheduling69 = require("@ordinatio/scheduling");
|
|
7315
|
+
|
|
7316
|
+
// src/gift-certificates/gift-http.ts
|
|
7317
|
+
var import_scheduling68 = require("@ordinatio/scheduling");
|
|
7318
|
+
var NOT_ENABLED5 = { error: "Gift certificates are not enabled on this server" };
|
|
7319
|
+
var BAD_REQUEST = /* @__PURE__ */ new Set(["SCHED_1700", "SCHED_1706", "SCHED_1709"]);
|
|
7320
|
+
var CONFLICT = /* @__PURE__ */ new Set(["SCHED_1702", "SCHED_1703", "SCHED_1704", "SCHED_1707", "SCHED_1708", "SCHED_1710"]);
|
|
7321
|
+
var CODE_SHAPE = /\b[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}\b/g;
|
|
7322
|
+
function safeErrorText(error) {
|
|
7323
|
+
if (!(error instanceof Error)) return "unknown error";
|
|
7324
|
+
const code = error.code;
|
|
7325
|
+
return `${error.name}${typeof code === "string" ? ` ${code}` : ""}: ${error.message.replace(CODE_SHAPE, "[code]").slice(0, 300)}`;
|
|
7326
|
+
}
|
|
7327
|
+
function forCaller(staff, certificate) {
|
|
7328
|
+
if (!staff.role.startsWith(API_KEY_ROLE_PREFIX) || staff.role === `${API_KEY_ROLE_PREFIX}FULL`) return certificate;
|
|
7329
|
+
return { ...certificate, code: `\u2026${certificate.code.slice(-4)}`, codeHidden: true };
|
|
7330
|
+
}
|
|
7331
|
+
function noStoreJson(body, init = {}) {
|
|
7332
|
+
return Response.json(body, { status: init.status ?? 200, headers: { "Cache-Control": "no-store" } });
|
|
7333
|
+
}
|
|
7334
|
+
function giftFailure(error, fallback) {
|
|
7335
|
+
if (error instanceof import_scheduling68.SchedulingNotFoundError) return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error) }, { status: 404 });
|
|
7336
|
+
if (error instanceof import_scheduling68.SchedulingValidationError) {
|
|
7337
|
+
const status = BAD_REQUEST.has(error.code) ? 400 : CONFLICT.has(error.code) ? 409 : 500;
|
|
7338
|
+
if (status !== 500) {
|
|
7339
|
+
const details = error.context?.errors;
|
|
7340
|
+
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status });
|
|
7341
|
+
}
|
|
7342
|
+
}
|
|
7343
|
+
console.error("[gift-certificates]", safeErrorText(error));
|
|
7344
|
+
return Response.json({ error: fallback }, { status: 500 });
|
|
7345
|
+
}
|
|
7346
|
+
async function recordGiftActivity(host, staff, entry) {
|
|
7347
|
+
await host.activity.log(staff.db, entry).catch((error) => {
|
|
7348
|
+
console.error("[gift-certificates] could not record the activity", safeErrorText(error));
|
|
7349
|
+
});
|
|
7350
|
+
}
|
|
7351
|
+
async function requireGiftAdmin(host, request, options) {
|
|
7352
|
+
const staff = await requireAdminStaff(host, request, options);
|
|
7353
|
+
if (staff instanceof Response) return staff;
|
|
7354
|
+
if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501 });
|
|
7355
|
+
return staff;
|
|
7356
|
+
}
|
|
7357
|
+
|
|
7358
|
+
// src/handlers/admin-gift-certificates.ts
|
|
7359
|
+
async function listGiftCertificatesRoute(request, { host }) {
|
|
7360
|
+
try {
|
|
7361
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-list", tier: "GENERAL" });
|
|
7362
|
+
if (staff instanceof Response) return staff;
|
|
7363
|
+
const params = new URL(request.url).searchParams;
|
|
7364
|
+
const status = params.get("status");
|
|
7365
|
+
if (status !== null && status !== "ACTIVE" && status !== "VOID") return Response.json({ error: "status must be ACTIVE or VOID" }, { status: 400 });
|
|
7366
|
+
const limit = params.get("limit");
|
|
7367
|
+
const certificates = await (0, import_scheduling69.listGiftCertificates)(staff.db, staff.organizationId, { ...status ? { status } : {}, ...limit ? { limit: Number(limit) } : {} });
|
|
7368
|
+
return noStoreJson({ certificates: certificates.map((certificate) => forCaller(staff, certificate)) });
|
|
7369
|
+
} catch (error) {
|
|
7370
|
+
return giftFailure(error, "Failed to list the gift certificates");
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
async function issueGiftCertificateRoute(request, { host }) {
|
|
7374
|
+
try {
|
|
7375
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-issue", tier: "CREATE" });
|
|
7376
|
+
if (staff instanceof Response) return staff;
|
|
7377
|
+
const validation = await parseBody(request, GiftCertificateSchema);
|
|
7378
|
+
if (!validation.success) return validation.response;
|
|
7379
|
+
const { certificate, created } = await (0, import_scheduling69.issueGiftCertificateOnce)(staff.db, staff.organizationId, validation.data, staff.userId);
|
|
7380
|
+
if (!created) return noStoreJson({ certificate: forCaller(staff, certificate) });
|
|
7381
|
+
await recordGiftActivity(host, staff, {
|
|
7382
|
+
action: "scheduling.gift_certificate_issued",
|
|
7383
|
+
description: "issued a gift certificate",
|
|
7384
|
+
metadata: { certificateId: certificate.id, amountCents: certificate.initialCents, currency: certificate.currency }
|
|
7385
|
+
});
|
|
7386
|
+
return noStoreJson({ certificate: forCaller(staff, certificate) }, { status: 201 });
|
|
7387
|
+
} catch (error) {
|
|
7388
|
+
return giftFailure(error, "Failed to issue the gift certificate");
|
|
7389
|
+
}
|
|
7390
|
+
}
|
|
7391
|
+
|
|
7392
|
+
// src/handlers/admin-gift-certificate-detail.ts
|
|
7393
|
+
var import_scheduling70 = require("@ordinatio/scheduling");
|
|
7394
|
+
async function getGiftCertificateRoute(request, { host, params }) {
|
|
7395
|
+
try {
|
|
7396
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-get", tier: "GENERAL" });
|
|
7397
|
+
if (staff instanceof Response) return staff;
|
|
7398
|
+
const found = await (0, import_scheduling70.getGiftCertificate)(staff.db, staff.organizationId, params.id);
|
|
7399
|
+
return noStoreJson({ ...found, certificate: forCaller(staff, found.certificate) });
|
|
7400
|
+
} catch (error) {
|
|
7401
|
+
return giftFailure(error, "Failed to read the gift certificate");
|
|
7402
|
+
}
|
|
7403
|
+
}
|
|
7404
|
+
async function voidGiftCertificateRoute(request, { host, params }) {
|
|
7405
|
+
try {
|
|
7406
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-void", tier: "DELETE" });
|
|
7407
|
+
if (staff instanceof Response) return staff;
|
|
7408
|
+
const voided = await (0, import_scheduling70.voidGiftCertificate)(staff.db, staff.organizationId, params.id, staff.userId);
|
|
7409
|
+
if (!voided) return Response.json({ error: "Gift certificate not found, or already void" }, { status: 404 });
|
|
7410
|
+
await recordGiftActivity(host, staff, { action: "scheduling.gift_certificate_voided", description: "voided a gift certificate", metadata: { certificateId: params.id } });
|
|
7411
|
+
return noStoreJson({ voided: true });
|
|
7412
|
+
} catch (error) {
|
|
7413
|
+
return giftFailure(error, "Failed to void the gift certificate");
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
async function restoreGiftCertificateRoute(request, { host, params }) {
|
|
7417
|
+
try {
|
|
7418
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-restore", tier: "UPDATE" });
|
|
7419
|
+
if (staff instanceof Response) return staff;
|
|
7420
|
+
const validation = await parseBody(request, GiftCertificateRestoreSchema);
|
|
7421
|
+
if (!validation.success) return validation.response;
|
|
7422
|
+
const restored = await (0, import_scheduling70.restoreGiftCertificate)(staff.db, staff.organizationId, params.id, validation.data, staff.userId);
|
|
7423
|
+
await recordGiftActivity(host, staff, {
|
|
7424
|
+
action: "scheduling.gift_certificate_restored",
|
|
7425
|
+
description: "gave value back to a gift certificate",
|
|
7426
|
+
metadata: { certificateId: params.id, amountCents: restored.restoredCents, ...validation.data.appointmentId ? { appointmentId: validation.data.appointmentId } : {} }
|
|
7427
|
+
});
|
|
7428
|
+
return noStoreJson({ restored });
|
|
7429
|
+
} catch (error) {
|
|
7430
|
+
return giftFailure(error, "Failed to give value back to the gift certificate");
|
|
7431
|
+
}
|
|
7432
|
+
}
|
|
7433
|
+
|
|
7434
|
+
// src/handlers/gift-certificates-check.ts
|
|
7435
|
+
var import_scheduling71 = require("@ordinatio/scheduling");
|
|
7436
|
+
async function checkGiftCertificateRoute(request, { host }) {
|
|
7437
|
+
const cors = host.cors(request);
|
|
7438
|
+
const headers = { ...cors, "Cache-Control": "no-store" };
|
|
7439
|
+
if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501, headers });
|
|
7440
|
+
const limited = await host.rateLimit(`gift-check:${clientAddress(request)}`, "PUBLIC_BOOKING");
|
|
7441
|
+
if (limited) return limited;
|
|
7442
|
+
const parsed = validateData(await request.json().catch(() => null), GiftCertificateCheckSchema);
|
|
7443
|
+
if (!parsed.success) return Response.json({ error: "Validation failed" }, { status: 400, headers });
|
|
7444
|
+
const { code, calendarId } = parsed.data;
|
|
7445
|
+
try {
|
|
7446
|
+
const db = await host.publicDb();
|
|
7447
|
+
const calendar = await db.schedulingCalendar.findUnique({ where: { id: calendarId }, select: { organizationId: true } });
|
|
7448
|
+
const found = calendar?.organizationId ? await (0, import_scheduling71.checkGiftCertificate)(db, calendar.organizationId, code) : null;
|
|
7449
|
+
if (!found) return Response.json({ valid: false, reason: "not_found" }, { headers });
|
|
7450
|
+
if (found.state !== "ACTIVE") return Response.json({ valid: false, reason: found.state.toLowerCase() }, { headers });
|
|
7451
|
+
return Response.json({ valid: true, balanceCents: found.balanceCents, currency: found.currency, expiresAt: found.expiresAt }, { headers });
|
|
7452
|
+
} catch (error) {
|
|
7453
|
+
const err = (0, import_scheduling71.schedError)("SCHED_408", { calendarId, error: safeErrorText(error) });
|
|
7454
|
+
console.error(`[${err.ref}] gift certificate check failed:`, safeErrorText(error));
|
|
7455
|
+
return Response.json({ valid: false, reason: "error", error: err.description, ref: err.ref }, { status: 500, headers });
|
|
7456
|
+
}
|
|
7457
|
+
}
|
|
7458
|
+
|
|
7459
|
+
// src/handlers/admin-text-settings.ts
|
|
7460
|
+
var import_scheduling72 = require("@ordinatio/scheduling");
|
|
7461
|
+
var NOT_ENABLED6 = { error: "Text-message settings are not enabled on this server" };
|
|
7462
|
+
function failure4(error, fallback) {
|
|
7463
|
+
if (error instanceof import_scheduling72.SchedulingValidationError) {
|
|
7151
7464
|
const details = error.context.errors;
|
|
7152
7465
|
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
|
|
7153
7466
|
}
|
|
@@ -7157,16 +7470,16 @@ function failure3(error, fallback) {
|
|
|
7157
7470
|
async function requireTextAdmin(host, request, options) {
|
|
7158
7471
|
const staff = await requireAdminStaff(host, request, options);
|
|
7159
7472
|
if (staff instanceof Response) return staff;
|
|
7160
|
-
if (!host.textMessages) return Response.json(
|
|
7473
|
+
if (!host.textMessages) return Response.json(NOT_ENABLED6, { status: 501 });
|
|
7161
7474
|
return staff;
|
|
7162
7475
|
}
|
|
7163
7476
|
async function getTextSettingsRoute(request, { host }) {
|
|
7164
7477
|
try {
|
|
7165
7478
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-get", tier: "GENERAL" });
|
|
7166
7479
|
if (staff instanceof Response) return staff;
|
|
7167
|
-
return Response.json({ settings: await (0,
|
|
7480
|
+
return Response.json({ settings: await (0, import_scheduling72.getTextSettings)(staff.db, staff.organizationId), providers: host.textMessages?.providers ?? ["TELNYX", "TWILIO"] });
|
|
7168
7481
|
} catch (error) {
|
|
7169
|
-
return
|
|
7482
|
+
return failure4(error, "Failed to read the text-message settings");
|
|
7170
7483
|
}
|
|
7171
7484
|
}
|
|
7172
7485
|
async function saveTextSettingsRoute(request, { host }) {
|
|
@@ -7175,7 +7488,7 @@ async function saveTextSettingsRoute(request, { host }) {
|
|
|
7175
7488
|
if (staff instanceof Response) return staff;
|
|
7176
7489
|
const validation = await parseBody(request, TextSettingsSchema);
|
|
7177
7490
|
if (!validation.success) return validation.response;
|
|
7178
|
-
const settings = await (0,
|
|
7491
|
+
const settings = await (0, import_scheduling72.saveTextSettings)(staff.db, staff.organizationId, validation.data, { providers: host.textMessages?.providers });
|
|
7179
7492
|
await host.activity.log(staff.db, {
|
|
7180
7493
|
action: "scheduling.text_settings_saved",
|
|
7181
7494
|
description: "changed the text-message settings",
|
|
@@ -7183,18 +7496,18 @@ async function saveTextSettingsRoute(request, { host }) {
|
|
|
7183
7496
|
});
|
|
7184
7497
|
return Response.json({ settings });
|
|
7185
7498
|
} catch (error) {
|
|
7186
|
-
return
|
|
7499
|
+
return failure4(error, "Failed to save the text-message settings");
|
|
7187
7500
|
}
|
|
7188
7501
|
}
|
|
7189
7502
|
async function deleteTextSettingsRoute(request, { host }) {
|
|
7190
7503
|
try {
|
|
7191
7504
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-delete", tier: "DELETE" });
|
|
7192
7505
|
if (staff instanceof Response) return staff;
|
|
7193
|
-
const removed = await (0,
|
|
7506
|
+
const removed = await (0, import_scheduling72.deleteTextSettings)(staff.db, staff.organizationId);
|
|
7194
7507
|
if (removed) await host.activity.log(staff.db, { action: "scheduling.text_settings_removed", description: "removed the text-message settings", metadata: {} });
|
|
7195
7508
|
return Response.json({ removed });
|
|
7196
7509
|
} catch (error) {
|
|
7197
|
-
return
|
|
7510
|
+
return failure4(error, "Failed to remove the text-message settings");
|
|
7198
7511
|
}
|
|
7199
7512
|
}
|
|
7200
7513
|
|
|
@@ -7267,14 +7580,14 @@ async function checkSendingDomainRoute(request, { host }) {
|
|
|
7267
7580
|
}
|
|
7268
7581
|
|
|
7269
7582
|
// src/handlers/admin-privacy.ts
|
|
7270
|
-
var
|
|
7583
|
+
var import_scheduling74 = require("@ordinatio/scheduling");
|
|
7271
7584
|
|
|
7272
7585
|
// src/privacy/privacy-http.ts
|
|
7273
|
-
var
|
|
7274
|
-
var
|
|
7586
|
+
var import_scheduling73 = require("@ordinatio/scheduling");
|
|
7587
|
+
var NOT_ENABLED7 = { error: "Data export and erasure are not enabled on this server" };
|
|
7275
7588
|
var STATUS_BY_CODE3 = { SCHED_1300: 400, SCHED_1301: 409 };
|
|
7276
7589
|
function privacyErrorResponse(error, fallback) {
|
|
7277
|
-
if (error instanceof
|
|
7590
|
+
if (error instanceof import_scheduling73.SchedulingValidationError) {
|
|
7278
7591
|
return Response.json(
|
|
7279
7592
|
{ error: error.message, code: error.code, ref: getErrorRef(error), details: error.context },
|
|
7280
7593
|
{ status: STATUS_BY_CODE3[error.code] ?? 400 }
|
|
@@ -7286,7 +7599,7 @@ function privacyErrorResponse(error, fallback) {
|
|
|
7286
7599
|
async function requirePrivacyAdmin(host, request, options) {
|
|
7287
7600
|
const staff = await requireAdminStaff(host, request, options);
|
|
7288
7601
|
if (staff instanceof Response) return staff;
|
|
7289
|
-
if (!host.privacy) return Response.json(
|
|
7602
|
+
if (!host.privacy) return Response.json(NOT_ENABLED7, { status: 501 });
|
|
7290
7603
|
return staff;
|
|
7291
7604
|
}
|
|
7292
7605
|
|
|
@@ -7304,7 +7617,7 @@ async function exportPrivacyRoute(request, { host }) {
|
|
|
7304
7617
|
if (staff instanceof Response) return staff;
|
|
7305
7618
|
const validation = await parseBody(request, PrivacySubjectSchema);
|
|
7306
7619
|
if (!validation.success) return validation.response;
|
|
7307
|
-
const result = await (0,
|
|
7620
|
+
const result = await (0, import_scheduling74.exportSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...validation.data });
|
|
7308
7621
|
await logQuietly(host, staff.db, {
|
|
7309
7622
|
action: "scheduling.privacy_export",
|
|
7310
7623
|
description: "exported the data held about one person",
|
|
@@ -7331,10 +7644,10 @@ async function erasePrivacyRoute(request, { host }) {
|
|
|
7331
7644
|
if (!validation.success) return validation.response;
|
|
7332
7645
|
const { confirm, ...subject2 } = validation.data;
|
|
7333
7646
|
if (confirm !== true) {
|
|
7334
|
-
const preview = await (0,
|
|
7647
|
+
const preview = await (0, import_scheduling74.previewErase)(staff.db, { organizationId: staff.organizationId, ...subject2 });
|
|
7335
7648
|
return Response.json({ erased: false, preview }, { headers: { "cache-control": "no-store" } });
|
|
7336
7649
|
}
|
|
7337
|
-
const { counts } = await (0,
|
|
7650
|
+
const { counts } = await (0, import_scheduling74.eraseSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...subject2 });
|
|
7338
7651
|
await logQuietly(host, staff.db, {
|
|
7339
7652
|
action: "scheduling.privacy_erase",
|
|
7340
7653
|
description: "erased the data held about one person",
|
|
@@ -7350,7 +7663,7 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7350
7663
|
const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-requests", tier: "GENERAL" });
|
|
7351
7664
|
if (staff instanceof Response) return staff;
|
|
7352
7665
|
const { limit, offset } = parsePagination(request);
|
|
7353
|
-
const { requests, total } = await (0,
|
|
7666
|
+
const { requests, total } = await (0, import_scheduling74.listPrivacyRequests)(staff.db, { organizationId: staff.organizationId, limit, offset });
|
|
7354
7667
|
return Response.json({ requests, total, hasMore: offset + requests.length < total });
|
|
7355
7668
|
} catch (error) {
|
|
7356
7669
|
return privacyErrorResponse(error, "Failed to list the requests");
|
|
@@ -7358,12 +7671,12 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7358
7671
|
}
|
|
7359
7672
|
|
|
7360
7673
|
// src/handlers/admin-routing-form-detail.ts
|
|
7361
|
-
var
|
|
7674
|
+
var import_scheduling75 = require("@ordinatio/scheduling");
|
|
7362
7675
|
async function getRoutingFormAdminRoute(request, { host, params }) {
|
|
7363
7676
|
try {
|
|
7364
7677
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-get", tier: "GENERAL" });
|
|
7365
7678
|
if (staff instanceof Response) return staff;
|
|
7366
|
-
return Response.json({ form: await (0,
|
|
7679
|
+
return Response.json({ form: await (0, import_scheduling75.getRoutingForm)(staff.db, staff.organizationId, params.id) });
|
|
7367
7680
|
} catch (error) {
|
|
7368
7681
|
return routingErrorResponse(error, "Failed to read the form");
|
|
7369
7682
|
}
|
|
@@ -7374,7 +7687,7 @@ async function updateRoutingFormRoute(request, { host, params }) {
|
|
|
7374
7687
|
if (staff instanceof Response) return staff;
|
|
7375
7688
|
const validation = await parseBody(request, UpdateRoutingFormSchema);
|
|
7376
7689
|
if (!validation.success) return validation.response;
|
|
7377
|
-
const form = await (0,
|
|
7690
|
+
const form = await (0, import_scheduling75.updateRoutingForm)(staff.db, staff.organizationId, params.id, validation.data);
|
|
7378
7691
|
await host.activity.log(staff.db, {
|
|
7379
7692
|
action: "scheduling.routing_form_updated",
|
|
7380
7693
|
description: `changed routing form "${form.name}"`,
|
|
@@ -7389,7 +7702,7 @@ async function deleteRoutingFormRoute(request, { host, params }) {
|
|
|
7389
7702
|
try {
|
|
7390
7703
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-delete", tier: "DELETE" });
|
|
7391
7704
|
if (staff instanceof Response) return staff;
|
|
7392
|
-
await (0,
|
|
7705
|
+
await (0, import_scheduling75.deleteRoutingForm)(staff.db, staff.organizationId, params.id);
|
|
7393
7706
|
await host.activity.log(staff.db, { action: "scheduling.routing_form_deleted", description: "removed a routing form", metadata: { formId: params.id } });
|
|
7394
7707
|
return Response.json({ success: true });
|
|
7395
7708
|
} catch (error) {
|
|
@@ -7402,14 +7715,14 @@ async function testRoutingFormRoute(request, { host, params }) {
|
|
|
7402
7715
|
if (staff instanceof Response) return staff;
|
|
7403
7716
|
const validation = await parseBody(request, TestRoutingFormSchema);
|
|
7404
7717
|
if (!validation.success) return validation.response;
|
|
7405
|
-
return Response.json(await (0,
|
|
7718
|
+
return Response.json(await (0, import_scheduling75.testRoutingForm)(staff.db, { organizationId: staff.organizationId, id: params.id, answers: validation.data.answers }));
|
|
7406
7719
|
} catch (error) {
|
|
7407
7720
|
return routingErrorResponse(error, "Failed to test the form");
|
|
7408
7721
|
}
|
|
7409
7722
|
}
|
|
7410
7723
|
|
|
7411
7724
|
// src/handlers/appointments-list.ts
|
|
7412
|
-
var
|
|
7725
|
+
var import_scheduling76 = require("@ordinatio/scheduling");
|
|
7413
7726
|
var DEFAULT_LIMIT2 = 50;
|
|
7414
7727
|
var MAX_LIMIT2 = 500;
|
|
7415
7728
|
async function listAppointments(request, { host }) {
|
|
@@ -7421,7 +7734,7 @@ async function listAppointments(request, { host }) {
|
|
|
7421
7734
|
const clientId = params.get("clientId") || void 0;
|
|
7422
7735
|
const status = params.get("status") || void 0;
|
|
7423
7736
|
if (!clientId && !staff.isAdmin) {
|
|
7424
|
-
const err = (0,
|
|
7737
|
+
const err = (0, import_scheduling76.schedError)("SCHED_900", { role: staff.role });
|
|
7425
7738
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
7426
7739
|
}
|
|
7427
7740
|
const startDate = params.get("startDate");
|
|
@@ -7432,7 +7745,7 @@ async function listAppointments(request, { host }) {
|
|
|
7432
7745
|
MAX_LIMIT2
|
|
7433
7746
|
);
|
|
7434
7747
|
const visibility = await staff.visibleCalendars();
|
|
7435
|
-
const where = (0,
|
|
7748
|
+
const where = (0, import_scheduling76.withOrganization)({
|
|
7436
7749
|
...visibility ? { calendar: visibility } : {},
|
|
7437
7750
|
...calendarId ? { calendarId } : {},
|
|
7438
7751
|
...clientId ? { clientId } : {},
|
|
@@ -7501,7 +7814,7 @@ async function listAppointments(request, { host }) {
|
|
|
7501
7814
|
}
|
|
7502
7815
|
|
|
7503
7816
|
// src/handlers/availability.ts
|
|
7504
|
-
var
|
|
7817
|
+
var import_scheduling77 = require("@ordinatio/scheduling");
|
|
7505
7818
|
|
|
7506
7819
|
// src/availability/picked-day.ts
|
|
7507
7820
|
var CALENDAR_DAY_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -7614,7 +7927,7 @@ async function getAvailability(request, { host }) {
|
|
|
7614
7927
|
const cached = await readCache(host.availabilityCache, calendarId, cacheDay, typeDuration);
|
|
7615
7928
|
if (cached != null) return corsJson(cors, cached);
|
|
7616
7929
|
}
|
|
7617
|
-
const result = await (0,
|
|
7930
|
+
const result = await (0, import_scheduling77.getAvailableSlots)(db, {
|
|
7618
7931
|
calendarId,
|
|
7619
7932
|
date: dateObj,
|
|
7620
7933
|
localDate: pickedDay,
|
|
@@ -7635,7 +7948,7 @@ async function getAvailability(request, { host }) {
|
|
|
7635
7948
|
}
|
|
7636
7949
|
|
|
7637
7950
|
// src/handlers/availability-team.ts
|
|
7638
|
-
var
|
|
7951
|
+
var import_scheduling78 = require("@ordinatio/scheduling");
|
|
7639
7952
|
|
|
7640
7953
|
// src/loaders/team-type.ts
|
|
7641
7954
|
async function loadTeamType(db, typeId, organizationId) {
|
|
@@ -7683,7 +7996,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7683
7996
|
{ status: 400 }
|
|
7684
7997
|
);
|
|
7685
7998
|
}
|
|
7686
|
-
const result = await (0,
|
|
7999
|
+
const result = await (0, import_scheduling78.getTeamAvailableSlots)(db, {
|
|
7687
8000
|
typeId,
|
|
7688
8001
|
date: dateObj,
|
|
7689
8002
|
localDate: pickedCalendarDay(date),
|
|
@@ -7706,7 +8019,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7706
8019
|
}
|
|
7707
8020
|
|
|
7708
8021
|
// src/handlers/appointment-types.ts
|
|
7709
|
-
var
|
|
8022
|
+
var import_scheduling79 = require("@ordinatio/scheduling");
|
|
7710
8023
|
|
|
7711
8024
|
// src/loaders/types-by-calendar.ts
|
|
7712
8025
|
function loadTypesByCalendarSlug(cache, db, organizationId, calendarSlug) {
|
|
@@ -7780,19 +8093,19 @@ async function getAppointmentTypes(request, { host }) {
|
|
|
7780
8093
|
}));
|
|
7781
8094
|
return corsJson(cors, response, { headers: WIDGET_CACHE_HEADERS });
|
|
7782
8095
|
} catch (error) {
|
|
7783
|
-
const diagnostic = (0,
|
|
8096
|
+
const diagnostic = (0, import_scheduling79.schedError)("SCHED_202", { error });
|
|
7784
8097
|
console.error("[appointment-types]", diagnostic.ref, error);
|
|
7785
8098
|
return corsJson(cors, { error: "Failed to fetch appointment types", ref: diagnostic.ref }, { status: 500 });
|
|
7786
8099
|
}
|
|
7787
8100
|
}
|
|
7788
8101
|
|
|
7789
8102
|
// src/handlers/coupons-validate.ts
|
|
7790
|
-
var
|
|
7791
|
-
var
|
|
7792
|
-
var Schema4 =
|
|
7793
|
-
code:
|
|
7794
|
-
calendarId:
|
|
7795
|
-
price:
|
|
8103
|
+
var import_zod22 = require("zod");
|
|
8104
|
+
var import_scheduling80 = require("@ordinatio/scheduling");
|
|
8105
|
+
var Schema4 = import_zod22.z.object({
|
|
8106
|
+
code: import_zod22.z.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
|
|
8107
|
+
calendarId: import_zod22.z.string().min(1),
|
|
8108
|
+
price: import_zod22.z.number().positive()
|
|
7796
8109
|
});
|
|
7797
8110
|
function calculateDiscount(price, discountType, discountValue) {
|
|
7798
8111
|
if (discountType === "PERCENTAGE") {
|
|
@@ -7850,7 +8163,7 @@ async function validateCoupon(request, { host }) {
|
|
|
7850
8163
|
{ headers: host.cors(request) }
|
|
7851
8164
|
);
|
|
7852
8165
|
} catch (error) {
|
|
7853
|
-
const err = (0,
|
|
8166
|
+
const err = (0, import_scheduling80.schedError)("SCHED_408", {
|
|
7854
8167
|
calendarId,
|
|
7855
8168
|
error: error instanceof Error ? error.message : String(error)
|
|
7856
8169
|
});
|
|
@@ -7930,7 +8243,7 @@ async function listActiveCalendars(request, { host }) {
|
|
|
7930
8243
|
}
|
|
7931
8244
|
|
|
7932
8245
|
// src/handlers/type.ts
|
|
7933
|
-
var
|
|
8246
|
+
var import_scheduling81 = require("@ordinatio/scheduling");
|
|
7934
8247
|
|
|
7935
8248
|
// src/loaders/type-by-slug.ts
|
|
7936
8249
|
function loadTypeBySlug(cache, db, organizationId, slug) {
|
|
@@ -8035,14 +8348,14 @@ async function getType(request, { host }) {
|
|
|
8035
8348
|
{ headers: WIDGET_CACHE_HEADERS }
|
|
8036
8349
|
);
|
|
8037
8350
|
} catch (error) {
|
|
8038
|
-
const diagnostic = (0,
|
|
8351
|
+
const diagnostic = (0, import_scheduling81.schedError)("SCHED_207", { error });
|
|
8039
8352
|
console.error("[type]", diagnostic.ref, error);
|
|
8040
8353
|
return corsJson(cors, { error: "Failed to fetch appointment type", ref: diagnostic.ref }, { status: 500 });
|
|
8041
8354
|
}
|
|
8042
8355
|
}
|
|
8043
8356
|
|
|
8044
8357
|
// src/handlers/widget-init.ts
|
|
8045
|
-
var
|
|
8358
|
+
var import_scheduling82 = require("@ordinatio/scheduling");
|
|
8046
8359
|
|
|
8047
8360
|
// src/loaders/widget-data.ts
|
|
8048
8361
|
function loadWidgetData(cache, db, organizationId, calendarSlug) {
|
|
@@ -8131,7 +8444,7 @@ async function getWidgetInit(request, { host }) {
|
|
|
8131
8444
|
}));
|
|
8132
8445
|
return corsJson(cors, { calendar, types: sanitizedTypes }, { headers: WIDGET_CACHE_HEADERS });
|
|
8133
8446
|
} catch (error) {
|
|
8134
|
-
const diagnostic = (0,
|
|
8447
|
+
const diagnostic = (0, import_scheduling82.schedError)("SCHED_206", { error });
|
|
8135
8448
|
console.error("[widget-init]", diagnostic.ref, error);
|
|
8136
8449
|
return corsJson(cors, { error: "Failed to load widget data", ref: diagnostic.ref }, { status: 500 });
|
|
8137
8450
|
}
|
|
@@ -8140,6 +8453,7 @@ async function getWidgetInit(request, { host }) {
|
|
|
8140
8453
|
// src/routes.ts
|
|
8141
8454
|
var ROUTES = [
|
|
8142
8455
|
{ method: "POST", path: "/coupons/validate", public: true, handler: validateCoupon },
|
|
8456
|
+
{ method: "POST", path: "/gift-certificates/check", public: true, handler: checkGiftCertificateRoute },
|
|
8143
8457
|
{ method: "POST", path: "/payments/intent", public: true, handler: createPaymentIntentRoute },
|
|
8144
8458
|
{ method: "GET", path: "/widget-init", public: true, handler: getWidgetInit },
|
|
8145
8459
|
{ method: "GET", path: "/type", public: true, handler: getType },
|
|
@@ -8209,6 +8523,14 @@ var ROUTES = [
|
|
|
8209
8523
|
{ method: "GET", path: "/admin/text-settings", public: false, handler: getTextSettingsRoute },
|
|
8210
8524
|
{ method: "PUT", path: "/admin/text-settings", public: false, handler: saveTextSettingsRoute },
|
|
8211
8525
|
{ method: "DELETE", path: "/admin/text-settings", public: false, handler: deleteTextSettingsRoute },
|
|
8526
|
+
{ method: "GET", path: "/admin/api-keys", public: false, handler: listApiKeysRoute },
|
|
8527
|
+
{ method: "POST", path: "/admin/api-keys", public: false, handler: createApiKeyRoute },
|
|
8528
|
+
{ method: "DELETE", path: "/admin/api-keys/[id]", public: false, handler: revokeApiKeyRoute },
|
|
8529
|
+
{ method: "GET", path: "/admin/gift-certificates", public: false, handler: listGiftCertificatesRoute },
|
|
8530
|
+
{ method: "POST", path: "/admin/gift-certificates", public: false, handler: issueGiftCertificateRoute },
|
|
8531
|
+
{ method: "GET", path: "/admin/gift-certificates/[id]", public: false, handler: getGiftCertificateRoute },
|
|
8532
|
+
{ method: "POST", path: "/admin/gift-certificates/[id]/void", public: false, handler: voidGiftCertificateRoute },
|
|
8533
|
+
{ method: "POST", path: "/admin/gift-certificates/[id]/restore", public: false, handler: restoreGiftCertificateRoute },
|
|
8212
8534
|
{ method: "GET", path: "/admin/brand/sending-domain", public: false, handler: checkSendingDomainRoute },
|
|
8213
8535
|
{ method: "POST", path: "/admin/privacy/export", public: false, handler: exportPrivacyRoute },
|
|
8214
8536
|
{ method: "POST", path: "/admin/privacy/erase", public: false, handler: erasePrivacyRoute },
|
|
@@ -8243,11 +8565,11 @@ var ROUTES = [
|
|
|
8243
8565
|
{ method: "POST", path: "/appointments/[id]/followup", public: false, handler: sendFollowup },
|
|
8244
8566
|
{ method: "POST", path: "/appointments/[id]/remind", public: false, handler: sendReminder },
|
|
8245
8567
|
{ method: "POST", path: "/appointments/[id]/cancel", public: false, handler: cancelByStaff },
|
|
8246
|
-
{ method: "GET", path: "/calendars/connect-google", public: false, handler: startGoogleConnection },
|
|
8247
|
-
{ method: "POST", path: "/calendars/connect-google", public: false, handler: setGoogleCalendar },
|
|
8248
|
-
{ method: "GET", path: "/calendars/connect-google/callback", public: false, handler: finishGoogleConnection },
|
|
8249
|
-
{ method: "GET", path: "/calendars/connect-outlook", public: false, handler: startOutlookConnection },
|
|
8250
|
-
{ method: "GET", path: "/calendars/connect-outlook/callback", public: false, handler: finishOutlookConnection },
|
|
8568
|
+
{ method: "GET", path: "/calendars/connect-google", public: false, personOnly: true, handler: startGoogleConnection },
|
|
8569
|
+
{ method: "POST", path: "/calendars/connect-google", public: false, personOnly: true, handler: setGoogleCalendar },
|
|
8570
|
+
{ method: "GET", path: "/calendars/connect-google/callback", public: false, personOnly: true, handler: finishGoogleConnection },
|
|
8571
|
+
{ method: "GET", path: "/calendars/connect-outlook", public: false, personOnly: true, handler: startOutlookConnection },
|
|
8572
|
+
{ method: "GET", path: "/calendars/connect-outlook/callback", public: false, personOnly: true, handler: finishOutlookConnection },
|
|
8251
8573
|
{ method: "POST", path: "/appointments/[id]/cancel-sync", public: false, handler: cancelFromCalendarSync },
|
|
8252
8574
|
{ method: "POST", path: "/appointments/[id]/approve", public: false, handler: approveOrReject },
|
|
8253
8575
|
{ method: "POST", path: "/appointments/[id]/reschedule", public: false, handler: rescheduleByStaff },
|
|
@@ -8305,6 +8627,8 @@ function createSchedulingApi(config) {
|
|
|
8305
8627
|
privacy: config.host.privacy ?? null,
|
|
8306
8628
|
brand: config.host.brand ?? null,
|
|
8307
8629
|
textMessages: config.host.textMessages ?? null,
|
|
8630
|
+
apiKeys: config.host.apiKeys ?? null,
|
|
8631
|
+
giftCertificates: config.host.giftCertificates ?? null,
|
|
8308
8632
|
icalUidDomain: config.host.icalUidDomain?.bind(config.host) ?? (() => null),
|
|
8309
8633
|
calendarSync: config.host.calendarSync ?? { upsertEvent: async () => ({}), removeEvent: async () => void 0 },
|
|
8310
8634
|
activity: config.host.activity ?? { log: async () => void 0, isOpen: async () => false, resolve: async () => void 0 },
|
|
@@ -8332,6 +8656,14 @@ function createSchedulingApi(config) {
|
|
|
8332
8656
|
cors: config.host.cors?.bind(config.host) ?? defaultCorsHeaders
|
|
8333
8657
|
};
|
|
8334
8658
|
host.events = withWebhooks(withWaitlist(config.host.events ?? { emit: async () => void 0 }, host), host);
|
|
8659
|
+
async function hostForRoute(route, request) {
|
|
8660
|
+
try {
|
|
8661
|
+
return await hostForRequest(host, request, route);
|
|
8662
|
+
} catch (error) {
|
|
8663
|
+
console.error("[scheduling-api] could not check the API key:", error);
|
|
8664
|
+
return Response.json({ error: "Internal error" }, { status: 500 });
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8335
8667
|
async function handle(request) {
|
|
8336
8668
|
const { pathname } = new URL(request.url);
|
|
8337
8669
|
if (pathname !== basePath && !pathname.startsWith(`${basePath}/`)) return notFound();
|
|
@@ -8349,7 +8681,9 @@ function createSchedulingApi(config) {
|
|
|
8349
8681
|
return Response.json({ error: "Method not allowed" }, { status: 405, headers: { Allow: allowed.join(", ") } });
|
|
8350
8682
|
}
|
|
8351
8683
|
try {
|
|
8352
|
-
|
|
8684
|
+
const runHost = await hostForRoute(hit.route, request);
|
|
8685
|
+
if (runHost instanceof Response) return runHost;
|
|
8686
|
+
return await hit.route.handler(request, { host: runHost, params: hit.params });
|
|
8353
8687
|
} catch (error) {
|
|
8354
8688
|
console.error("[scheduling-api] unhandled error:", error);
|
|
8355
8689
|
return Response.json({ error: "Internal error" }, { status: 500 });
|
|
@@ -8360,7 +8694,9 @@ function createSchedulingApi(config) {
|
|
|
8360
8694
|
if (!route) throw new Error(`No route ${method} ${path}`);
|
|
8361
8695
|
return async (request, context) => {
|
|
8362
8696
|
const params = await context?.params ?? {};
|
|
8363
|
-
|
|
8697
|
+
const runHost = await hostForRoute(route, request);
|
|
8698
|
+
if (runHost instanceof Response) return runHost;
|
|
8699
|
+
return route.handler(request, { host: runHost, params });
|
|
8364
8700
|
};
|
|
8365
8701
|
}
|
|
8366
8702
|
return { routes, handle, handler };
|
|
@@ -8549,8 +8885,8 @@ function readHeader(headers, name) {
|
|
|
8549
8885
|
}
|
|
8550
8886
|
var STOP_WORDS = ["STOP", "STOPALL", "UNSUBSCRIBE", "END", "QUIT"];
|
|
8551
8887
|
var START_WORDS = ["START", "UNSTOP"];
|
|
8552
|
-
function classifyReply(
|
|
8553
|
-
const word =
|
|
8888
|
+
function classifyReply(text2) {
|
|
8889
|
+
const word = text2.trim().toUpperCase().replace(/[.!?,]+$/, "");
|
|
8554
8890
|
return STOP_WORDS.includes(word) ? "opt-out" : START_WORDS.includes(word) ? "opt-in" : "reply";
|
|
8555
8891
|
}
|
|
8556
8892
|
|
|
@@ -8609,12 +8945,12 @@ function createTelnyxSmsAdapter(config) {
|
|
|
8609
8945
|
const id = body?.data?.id;
|
|
8610
8946
|
return id ? { status: "SENT", id } : { status: "SENT" };
|
|
8611
8947
|
}
|
|
8612
|
-
const { code, text } = firstError(body);
|
|
8948
|
+
const { code, text: text2 } = firstError(body);
|
|
8613
8949
|
if (code === OPTED_OUT_CODE) return { status: "SKIPPED", reason: "The recipient opted out of text messages" };
|
|
8614
8950
|
const serverFault = response.status >= 500;
|
|
8615
8951
|
const retryable = response.status === 429 || serverFault;
|
|
8616
8952
|
throw new SmsSendError(
|
|
8617
|
-
`Telnyx refused the message (HTTP ${response.status}${code ? `, code ${code}` : ""}): ${
|
|
8953
|
+
`Telnyx refused the message (HTTP ${response.status}${code ? `, code ${code}` : ""}): ${text2}`,
|
|
8618
8954
|
retryable,
|
|
8619
8955
|
serverFault,
|
|
8620
8956
|
response.status,
|
|
@@ -8660,9 +8996,9 @@ function handleTelnyxWebhook(rawBody, headers, options) {
|
|
|
8660
8996
|
if (eventType === "message.received") {
|
|
8661
8997
|
const from = payload?.from?.phone_number;
|
|
8662
8998
|
if (!id || !from || !to) return { ok: false, status: 400, reason: "The message is missing its id or phone numbers" };
|
|
8663
|
-
const
|
|
8664
|
-
const type = classifyReply(
|
|
8665
|
-
return { ok: true, event: { type, id, from, to, text } };
|
|
8999
|
+
const text2 = typeof payload?.text === "string" ? payload.text : "";
|
|
9000
|
+
const type = classifyReply(text2);
|
|
9001
|
+
return { ok: true, event: { type, id, from, to, text: text2 } };
|
|
8666
9002
|
}
|
|
8667
9003
|
if (eventType === "message.finalized" || eventType === "message.sent") {
|
|
8668
9004
|
if (!id || !to) return { ok: false, status: 400, reason: "The delivery report is missing its id or number" };
|
|
@@ -8747,7 +9083,7 @@ function createTwilioSmsAdapter(config) {
|
|
|
8747
9083
|
var import_node_crypto4 = require("crypto");
|
|
8748
9084
|
function expectedSignature(params, options) {
|
|
8749
9085
|
const keys = [...new Set(params.keys())].sort();
|
|
8750
|
-
const signed = keys.reduce((
|
|
9086
|
+
const signed = keys.reduce((text2, key) => text2 + key + params.getAll(key).join(""), options.url);
|
|
8751
9087
|
return (0, import_node_crypto4.createHmac)("sha1", options.authToken.trim()).update(signed).digest("base64");
|
|
8752
9088
|
}
|
|
8753
9089
|
function verifyTwilioSignature(rawBody, headers, options) {
|
|
@@ -8772,8 +9108,8 @@ function handleTwilioWebhook(rawBody, headers, options) {
|
|
|
8772
9108
|
}
|
|
8773
9109
|
if (params.has("Body")) {
|
|
8774
9110
|
if (!id || !from || !to) return { ok: false, status: 400, reason: "The message is missing its id or phone numbers" };
|
|
8775
|
-
const
|
|
8776
|
-
return { ok: true, event: { type: classifyReply(
|
|
9111
|
+
const text2 = params.get("Body") ?? "";
|
|
9112
|
+
return { ok: true, event: { type: classifyReply(text2), id, from, to, text: text2 } };
|
|
8777
9113
|
}
|
|
8778
9114
|
return { ok: true, event: { type: "ignored", eventType: "unknown" } };
|
|
8779
9115
|
}
|
|
@@ -8819,10 +9155,10 @@ function createPerBusinessSmsAdapter(options) {
|
|
|
8819
9155
|
}
|
|
8820
9156
|
|
|
8821
9157
|
// src/sms/text-settings-resolver.ts
|
|
8822
|
-
var
|
|
9158
|
+
var import_scheduling83 = require("@ordinatio/scheduling");
|
|
8823
9159
|
function createTextSettingsResolver(options) {
|
|
8824
9160
|
return async (organizationId) => {
|
|
8825
|
-
const settings = await (0,
|
|
9161
|
+
const settings = await (0, import_scheduling83.getTextSettings)(await options.db(organizationId), organizationId);
|
|
8826
9162
|
if (!settings || !settings.enabled) return null;
|
|
8827
9163
|
try {
|
|
8828
9164
|
if (settings.provider === "TELNYX" && options.telnyx?.apiKey?.trim()) {
|
|
@@ -9116,44 +9452,6 @@ function createOutlookCalendarSync(config, hooks) {
|
|
|
9116
9452
|
};
|
|
9117
9453
|
}
|
|
9118
9454
|
|
|
9119
|
-
// src/staff/simple-staff.ts
|
|
9120
|
-
var DEFAULT_ADMIN_ROLES = ["OWNER", "ADMIN", "MANAGER"];
|
|
9121
|
-
function createStaffContext(input) {
|
|
9122
|
-
const adminRoles = (input.adminRoles ?? DEFAULT_ADMIN_ROLES).map((role) => role.toUpperCase());
|
|
9123
|
-
const { db, organizationId } = input;
|
|
9124
|
-
return {
|
|
9125
|
-
userId: input.userId,
|
|
9126
|
-
organizationId,
|
|
9127
|
-
role: input.role,
|
|
9128
|
-
isAdmin: adminRoles.includes(input.role.toUpperCase()),
|
|
9129
|
-
schedulingEnabled: input.schedulingEnabled ?? true,
|
|
9130
|
-
db,
|
|
9131
|
-
visibleCalendars: async () => null,
|
|
9132
|
-
visibleCalendarIds: async () => void 0,
|
|
9133
|
-
canSeeCalendar: async (calendarId) => Boolean(await db.schedulingCalendar.findFirst({ where: { id: calendarId, organizationId }, select: { id: true } })),
|
|
9134
|
-
canSeeAppointment: async (appointmentId) => Boolean(await db.appointment.findFirst({ where: { id: appointmentId, calendar: { organizationId } }, select: { id: true } })),
|
|
9135
|
-
// The package has no client table, so there is no preference to read.
|
|
9136
|
-
preferredLocationOf: async () => null
|
|
9137
|
-
};
|
|
9138
|
-
}
|
|
9139
|
-
var BEARER = /^bearer\s+(\S+)$/i;
|
|
9140
|
-
function createBearerStaffResolver(input) {
|
|
9141
|
-
return {
|
|
9142
|
-
async resolve(request) {
|
|
9143
|
-
const token = BEARER.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
9144
|
-
if (!token) return null;
|
|
9145
|
-
const person = await input.authenticate(token, request);
|
|
9146
|
-
if (!person) return null;
|
|
9147
|
-
return createStaffContext({
|
|
9148
|
-
...person,
|
|
9149
|
-
db: await input.db(person),
|
|
9150
|
-
adminRoles: input.adminRoles,
|
|
9151
|
-
schedulingEnabled: input.schedulingEnabled ? await input.schedulingEnabled(person) : void 0
|
|
9152
|
-
});
|
|
9153
|
-
}
|
|
9154
|
-
};
|
|
9155
|
-
}
|
|
9156
|
-
|
|
9157
9455
|
// src/staff/staff-scope.ts
|
|
9158
9456
|
function isCalendarVisibleInScope(calendarUserId, scope) {
|
|
9159
9457
|
if (calendarUserId === null) return true;
|
|
@@ -9269,6 +9567,7 @@ function createNodeListener(api, options) {
|
|
|
9269
9567
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9270
9568
|
0 && (module.exports = {
|
|
9271
9569
|
ALL_REFUND_STATUSES,
|
|
9570
|
+
ApiKeySchema,
|
|
9272
9571
|
BALANCE_APPOINTMENT_SELECT,
|
|
9273
9572
|
BALANCE_BLOCKED_APPOINTMENT_STATUS,
|
|
9274
9573
|
BALANCE_REQUIRED_PAYMENT_STATUS,
|
|
@@ -9292,6 +9591,9 @@ function createNodeListener(api, options) {
|
|
|
9292
9591
|
CreateServicePackageSchema,
|
|
9293
9592
|
CreateWebhookEndpointSchema,
|
|
9294
9593
|
DEFAULT_CANCELLATION_POLICY,
|
|
9594
|
+
GiftCertificateCheckSchema,
|
|
9595
|
+
GiftCertificateRestoreSchema,
|
|
9596
|
+
GiftCertificateSchema,
|
|
9295
9597
|
IntakeFormFieldSchema,
|
|
9296
9598
|
NoShowPreventionActionSchema,
|
|
9297
9599
|
NotificationChannelSchema,
|
|
@@ -9323,6 +9625,7 @@ function createNodeListener(api, options) {
|
|
|
9323
9625
|
UpdateServicePackageSchema,
|
|
9324
9626
|
assertStripeTestKey,
|
|
9325
9627
|
attemptLegRefund,
|
|
9628
|
+
bearerKeyOf,
|
|
9326
9629
|
calendarVisibilityFilter,
|
|
9327
9630
|
canSeeAppointmentInScope,
|
|
9328
9631
|
canSeeCalendarInScope,
|