@ordinatio/scheduling-api 0.7.0 → 0.8.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 +3 -0
- package/README.md +8 -0
- package/dist/agent/index.d.mts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -0
- package/dist/agent/index.mjs +3 -0
- package/dist/{chunk-IW6AN5WE.mjs → chunk-X5BVCLX6.mjs} +9 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +470 -351
- package/dist/index.mjs +172 -61
- package/dist/{routes-LaFljBCF.d.mts → routes-mii9tsbA.d.mts} +18 -1
- package/dist/{routes-LaFljBCF.d.ts → routes-mii9tsbA.d.ts} +18 -1
- package/dist/schemas/index.d.mts +6 -1
- package/dist/schemas/index.d.ts +6 -1
- package/dist/schemas/index.js +9 -0
- package/dist/schemas/index.mjs +3 -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,
|
|
@@ -85,6 +86,7 @@ __export(index_exports, {
|
|
|
85
86
|
UpdateServicePackageSchema: () => UpdateServicePackageSchema,
|
|
86
87
|
assertStripeTestKey: () => assertStripeTestKey,
|
|
87
88
|
attemptLegRefund: () => attemptLegRefund,
|
|
89
|
+
bearerKeyOf: () => bearerKeyOf,
|
|
88
90
|
calendarVisibilityFilter: () => calendarVisibilityFilter,
|
|
89
91
|
canSeeAppointmentInScope: () => canSeeAppointmentInScope,
|
|
90
92
|
canSeeCalendarInScope: () => canSeeCalendarInScope,
|
|
@@ -148,6 +150,82 @@ function defaultCorsHeaders() {
|
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
// src/api-keys/api-key-host.ts
|
|
154
|
+
var import_scheduling = require("@ordinatio/scheduling");
|
|
155
|
+
|
|
156
|
+
// src/staff/simple-staff.ts
|
|
157
|
+
var DEFAULT_ADMIN_ROLES = ["OWNER", "ADMIN", "MANAGER"];
|
|
158
|
+
function createStaffContext(input) {
|
|
159
|
+
const adminRoles = (input.adminRoles ?? DEFAULT_ADMIN_ROLES).map((role) => role.toUpperCase());
|
|
160
|
+
const { db, organizationId } = input;
|
|
161
|
+
return {
|
|
162
|
+
userId: input.userId,
|
|
163
|
+
organizationId,
|
|
164
|
+
role: input.role,
|
|
165
|
+
isAdmin: adminRoles.includes(input.role.toUpperCase()),
|
|
166
|
+
schedulingEnabled: input.schedulingEnabled ?? true,
|
|
167
|
+
db,
|
|
168
|
+
visibleCalendars: async () => null,
|
|
169
|
+
visibleCalendarIds: async () => void 0,
|
|
170
|
+
canSeeCalendar: async (calendarId) => Boolean(await db.schedulingCalendar.findFirst({ where: { id: calendarId, organizationId }, select: { id: true } })),
|
|
171
|
+
canSeeAppointment: async (appointmentId) => Boolean(await db.appointment.findFirst({ where: { id: appointmentId, calendar: { organizationId } }, select: { id: true } })),
|
|
172
|
+
// The package has no client table, so there is no preference to read.
|
|
173
|
+
preferredLocationOf: async () => null
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var BEARER = /^bearer\s+(\S+)$/i;
|
|
177
|
+
function createBearerStaffResolver(input) {
|
|
178
|
+
return {
|
|
179
|
+
async resolve(request) {
|
|
180
|
+
const token = BEARER.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
181
|
+
if (!token) return null;
|
|
182
|
+
const person = await input.authenticate(token, request);
|
|
183
|
+
if (!person) return null;
|
|
184
|
+
return createStaffContext({
|
|
185
|
+
...person,
|
|
186
|
+
db: await input.db(person),
|
|
187
|
+
adminRoles: input.adminRoles,
|
|
188
|
+
schedulingEnabled: input.schedulingEnabled ? await input.schedulingEnabled(person) : void 0
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/api-keys/api-key-host.ts
|
|
195
|
+
var API_KEY_ROLE_PREFIX = "API_KEY_";
|
|
196
|
+
var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
197
|
+
function bearerKeyOf(request) {
|
|
198
|
+
const header = request.headers.get("authorization");
|
|
199
|
+
if (!header) return null;
|
|
200
|
+
const match = /^[Bb][Ee][Aa][Rr][Ee][Rr]\s+(osk_\S+)$/.exec(header.trim());
|
|
201
|
+
return match ? match[1] : null;
|
|
202
|
+
}
|
|
203
|
+
function contextOf(key, db, schedulingEnabled) {
|
|
204
|
+
return createStaffContext({
|
|
205
|
+
// The key, not the person who made it, is what the rate limit counts.
|
|
206
|
+
userId: `api-key:${key.id}`,
|
|
207
|
+
organizationId: key.organizationId,
|
|
208
|
+
role: `${API_KEY_ROLE_PREFIX}${key.access}`,
|
|
209
|
+
adminRoles: [`${API_KEY_ROLE_PREFIX}READ`, `${API_KEY_ROLE_PREFIX}FULL`],
|
|
210
|
+
schedulingEnabled,
|
|
211
|
+
db
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async function hostForRequest(host, request, route) {
|
|
215
|
+
if (route.public || !host.apiKeys) return host;
|
|
216
|
+
const secret = bearerKeyOf(request);
|
|
217
|
+
if (secret === null) return host;
|
|
218
|
+
const db = await host.apiKeys.db();
|
|
219
|
+
const key = await (0, import_scheduling.verifyApiKey)(db, secret);
|
|
220
|
+
if (!key) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
221
|
+
if (route.personOnly) return Response.json({ error: "This needs a person signed in at a browser, not an API key" }, { status: 403 });
|
|
222
|
+
if (key.access === "READ" && !SAFE_METHODS.has(request.method.toUpperCase())) {
|
|
223
|
+
return Response.json({ error: "This API key is read-only" }, { status: 403 });
|
|
224
|
+
}
|
|
225
|
+
const context = contextOf(key, db, await host.schedulingEnabledFor(key.organizationId));
|
|
226
|
+
return { ...host, staff: { resolve: async () => context } };
|
|
227
|
+
}
|
|
228
|
+
|
|
151
229
|
// src/availability/memory-availability-cache.ts
|
|
152
230
|
var TTL_MS = 6e4;
|
|
153
231
|
var DEFAULT_MAX_ENTRIES = 2e3;
|
|
@@ -331,7 +409,7 @@ function createUnconfiguredConnector(provider) {
|
|
|
331
409
|
}
|
|
332
410
|
|
|
333
411
|
// src/webhooks/webhook-events.ts
|
|
334
|
-
var
|
|
412
|
+
var import_scheduling2 = require("@ordinatio/scheduling");
|
|
335
413
|
var WEBHOOK_EVENT_FOR = {
|
|
336
414
|
"appointment.created": "appointment.booked",
|
|
337
415
|
"appointment.updated": "appointment.rescheduled",
|
|
@@ -348,7 +426,7 @@ function withWebhooks(inner, host) {
|
|
|
348
426
|
if (host.webhooks && webhookType && typeof appointmentId === "string") {
|
|
349
427
|
try {
|
|
350
428
|
const db = await host.tenantDb(organizationId, "webhooks");
|
|
351
|
-
if (db) await (0,
|
|
429
|
+
if (db) await (0, import_scheduling2.enqueueAppointmentWebhook)(db, { organizationId, type: webhookType, appointmentId });
|
|
352
430
|
} catch (error) {
|
|
353
431
|
console.error("[scheduling-api] could not reach the database to queue a webhook:", error);
|
|
354
432
|
}
|
|
@@ -359,9 +437,9 @@ function withWebhooks(inner, host) {
|
|
|
359
437
|
}
|
|
360
438
|
|
|
361
439
|
// src/waitlist/announce-offer.ts
|
|
362
|
-
var
|
|
440
|
+
var import_scheduling3 = require("@ordinatio/scheduling");
|
|
363
441
|
async function offerAndAnnounce(host, settings, db, slot) {
|
|
364
|
-
const offer = await (0,
|
|
442
|
+
const offer = await (0, import_scheduling3.tryOfferFreedSlot)(db, { ...slot, offerMinutes: settings.offerMinutes });
|
|
365
443
|
if (!offer) return false;
|
|
366
444
|
const details = {
|
|
367
445
|
organizationId: slot.organizationId,
|
|
@@ -384,7 +462,7 @@ async function offerAndAnnounce(host, settings, db, slot) {
|
|
|
384
462
|
}
|
|
385
463
|
if (host.webhooks) {
|
|
386
464
|
try {
|
|
387
|
-
await (0,
|
|
465
|
+
await (0, import_scheduling3.enqueueWebhookEvent)(db, {
|
|
388
466
|
organizationId: slot.organizationId,
|
|
389
467
|
type: "waitlist.offered",
|
|
390
468
|
// Each offering has its own id, so offering the same slot to the same person again still reaches subscribers.
|
|
@@ -438,7 +516,7 @@ function withWaitlist(inner, host) {
|
|
|
438
516
|
}
|
|
439
517
|
|
|
440
518
|
// src/handlers/manage-cancel.ts
|
|
441
|
-
var
|
|
519
|
+
var import_scheduling7 = require("@ordinatio/scheduling");
|
|
442
520
|
|
|
443
521
|
// src/client-address.ts
|
|
444
522
|
function forwardedAddress(request) {
|
|
@@ -449,7 +527,7 @@ function clientAddress(request) {
|
|
|
449
527
|
}
|
|
450
528
|
|
|
451
529
|
// src/error-guards.ts
|
|
452
|
-
var
|
|
530
|
+
var import_scheduling4 = require("@ordinatio/scheduling");
|
|
453
531
|
function getErrorCode(error) {
|
|
454
532
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
455
533
|
const code = error.code;
|
|
@@ -476,20 +554,20 @@ function getErrorMessage(error, fallback) {
|
|
|
476
554
|
return fallback;
|
|
477
555
|
}
|
|
478
556
|
function schedErrorStatus(code) {
|
|
479
|
-
return
|
|
557
|
+
return import_scheduling4.SCHEDULING_ERRORS[code]?.httpStatus ?? 400;
|
|
480
558
|
}
|
|
481
559
|
|
|
482
560
|
// src/manage/cancel-via-token.ts
|
|
483
|
-
var
|
|
561
|
+
var import_scheduling6 = require("@ordinatio/scheduling");
|
|
484
562
|
|
|
485
563
|
// src/calendar-sync.ts
|
|
486
|
-
var
|
|
564
|
+
var import_scheduling5 = require("@ordinatio/scheduling");
|
|
487
565
|
async function runWithoutBlocking(code, appointmentId, step, recordFailure) {
|
|
488
566
|
try {
|
|
489
567
|
await step();
|
|
490
568
|
return { queued: true };
|
|
491
569
|
} catch (error) {
|
|
492
|
-
const diagnostic = (0,
|
|
570
|
+
const diagnostic = (0, import_scheduling5.schedError)(code, { error, appointmentId });
|
|
493
571
|
console.error("[calendar-sync]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
494
572
|
try {
|
|
495
573
|
await recordFailure?.(diagnostic.ref);
|
|
@@ -509,7 +587,7 @@ function runCalendarRemoveWithoutBlocking(sync, ref, recordFailure) {
|
|
|
509
587
|
// src/manage/cancel-via-token.ts
|
|
510
588
|
async function cancelViaToken(host, db, organizationId, appointment) {
|
|
511
589
|
const hasPayment = !!(appointment.paymentId && (appointment.paymentStatus === "PAID" || appointment.paymentStatus === "DEPOSIT_PAID"));
|
|
512
|
-
await (0,
|
|
590
|
+
await (0, import_scheduling6.cancelAppointment)(db, {
|
|
513
591
|
appointmentId: appointment.id,
|
|
514
592
|
cancelledBy: "client",
|
|
515
593
|
reason: "Cancelled via self-service link"
|
|
@@ -520,7 +598,7 @@ async function cancelViaToken(host, db, organizationId, appointment) {
|
|
|
520
598
|
data: { refundStatus: hasPayment ? "PENDING_REVIEW" : "NO_PAYMENT" }
|
|
521
599
|
});
|
|
522
600
|
} catch (refundStatusError) {
|
|
523
|
-
const diagnostic = (0,
|
|
601
|
+
const diagnostic = (0, import_scheduling6.schedError)("SCHED_602", {
|
|
524
602
|
error: refundStatusError,
|
|
525
603
|
appointmentId: appointment.id,
|
|
526
604
|
context: "refundStatus write failed after cancellation already committed",
|
|
@@ -565,9 +643,9 @@ async function cancelViaToken(host, db, organizationId, appointment) {
|
|
|
565
643
|
const baseUrl = host.appUrl();
|
|
566
644
|
if (baseUrl) {
|
|
567
645
|
try {
|
|
568
|
-
await (0,
|
|
646
|
+
await (0, import_scheduling6.queueStaffNotification)(db, appointment.id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
|
|
569
647
|
} catch (staffError) {
|
|
570
|
-
const diagnostic = (0,
|
|
648
|
+
const diagnostic = (0, import_scheduling6.schedError)("SCHED_607", { error: staffError, appointmentId: appointment.id });
|
|
571
649
|
console.error("[DELETE /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
|
|
572
650
|
}
|
|
573
651
|
}
|
|
@@ -641,14 +719,14 @@ async function cancelManagedAppointment(request, { host }) {
|
|
|
641
719
|
{ status: 409 }
|
|
642
720
|
);
|
|
643
721
|
}
|
|
644
|
-
const diagnostic = (0,
|
|
722
|
+
const diagnostic = (0, import_scheduling7.schedError)("SCHED_602", { error, token: token ?? "unknown", appointmentId });
|
|
645
723
|
console.error("[DELETE /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
646
724
|
return Response.json({ error: "Failed to cancel", ref: diagnostic.ref }, { status: 500 });
|
|
647
725
|
}
|
|
648
726
|
}
|
|
649
727
|
|
|
650
728
|
// src/handlers/manage-get.ts
|
|
651
|
-
var
|
|
729
|
+
var import_scheduling8 = require("@ordinatio/scheduling");
|
|
652
730
|
async function getManagedAppointment(request, { host }) {
|
|
653
731
|
let token = null;
|
|
654
732
|
try {
|
|
@@ -682,24 +760,24 @@ async function getManagedAppointment(request, { host }) {
|
|
|
682
760
|
staffName: appointment.calendar.staffName,
|
|
683
761
|
calendarId: appointment.calendarId,
|
|
684
762
|
allowReschedule: appointment.type.allowReschedule,
|
|
685
|
-
location: (0,
|
|
763
|
+
location: (0, import_scheduling8.resolveLocation)(appointment),
|
|
686
764
|
meetingUrl: appointment.meetingUrl ?? null,
|
|
687
765
|
theme: appointment.calendar.theme ?? null
|
|
688
766
|
});
|
|
689
767
|
} catch (error) {
|
|
690
|
-
const diagnostic = (0,
|
|
768
|
+
const diagnostic = (0, import_scheduling8.schedError)("SCHED_601", { error, token: token ?? "unknown" });
|
|
691
769
|
console.error("[GET /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
692
770
|
return Response.json({ error: "Failed to fetch appointment", ref: diagnostic.ref }, { status: 500 });
|
|
693
771
|
}
|
|
694
772
|
}
|
|
695
773
|
|
|
696
774
|
// src/handlers/manage-reschedule.ts
|
|
697
|
-
var
|
|
775
|
+
var import_scheduling10 = require("@ordinatio/scheduling");
|
|
698
776
|
|
|
699
777
|
// src/manage/reschedule-via-token.ts
|
|
700
|
-
var
|
|
778
|
+
var import_scheduling9 = require("@ordinatio/scheduling");
|
|
701
779
|
async function rescheduleViaToken(host, db, organizationId, appointment, newTime) {
|
|
702
|
-
const result = await (0,
|
|
780
|
+
const result = await (0, import_scheduling9.rescheduleAppointment)(db, {
|
|
703
781
|
appointmentId: appointment.id,
|
|
704
782
|
newStartTime: newTime,
|
|
705
783
|
reason: "Rescheduled via self-service link"
|
|
@@ -724,21 +802,21 @@ async function rescheduleViaToken(host, db, organizationId, appointment, newTime
|
|
|
724
802
|
);
|
|
725
803
|
const baseUrl = host.appUrl() ?? void 0;
|
|
726
804
|
if (baseUrl) {
|
|
727
|
-
await (0,
|
|
805
|
+
await (0, import_scheduling9.queueImmediateNotification)(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
728
806
|
} else {
|
|
729
807
|
console.warn("[manage] no appUrl \u2014 RESCHEDULE notification skipped");
|
|
730
808
|
}
|
|
731
809
|
try {
|
|
732
|
-
await (0,
|
|
810
|
+
await (0, import_scheduling9.scheduleNotifications)(db, appointment.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
733
811
|
} catch (error) {
|
|
734
|
-
const diagnostic = (0,
|
|
812
|
+
const diagnostic = (0, import_scheduling9.schedError)("SCHED_604", { error, appointmentId: appointment.id });
|
|
735
813
|
console.error("[PATCH /manage] scheduleNotifications failed (non-blocking):", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
736
814
|
}
|
|
737
815
|
if (baseUrl) {
|
|
738
816
|
try {
|
|
739
|
-
await (0,
|
|
817
|
+
await (0, import_scheduling9.queueStaffNotification)(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
740
818
|
} catch (staffError) {
|
|
741
|
-
const diagnostic = (0,
|
|
819
|
+
const diagnostic = (0, import_scheduling9.schedError)("SCHED_607", { error: staffError, appointmentId: appointment.id });
|
|
742
820
|
console.error("[PATCH /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
|
|
743
821
|
}
|
|
744
822
|
}
|
|
@@ -797,7 +875,7 @@ async function rescheduleManagedAppointment(request, { host }) {
|
|
|
797
875
|
if (target instanceof Response) return target;
|
|
798
876
|
return await rescheduleViaToken(host, target.db, target.organizationId, appointment, newTime);
|
|
799
877
|
} catch (error) {
|
|
800
|
-
if (error instanceof
|
|
878
|
+
if (error instanceof import_scheduling10.SchedulingValidationError) {
|
|
801
879
|
return Response.json({ error: error.message, ref: error.ref }, { status: 400 });
|
|
802
880
|
}
|
|
803
881
|
const code = getErrorCode(error);
|
|
@@ -816,14 +894,14 @@ async function rescheduleManagedAppointment(request, { host }) {
|
|
|
816
894
|
console.error("[PATCH /manage]", ref, "SCHED_306", error);
|
|
817
895
|
return Response.json({ error: "Appointment status prevents rescheduling", ...ref && { ref } }, { status: 400 });
|
|
818
896
|
}
|
|
819
|
-
const diagnostic = (0,
|
|
897
|
+
const diagnostic = (0, import_scheduling10.schedError)("SCHED_603", { error, token: token ?? "unknown", appointmentId });
|
|
820
898
|
console.error("[PATCH /manage]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
821
899
|
return Response.json({ error: "Failed to reschedule", ref: diagnostic.ref }, { status: 500 });
|
|
822
900
|
}
|
|
823
901
|
}
|
|
824
902
|
|
|
825
903
|
// src/handlers/capacity.ts
|
|
826
|
-
var
|
|
904
|
+
var import_scheduling11 = require("@ordinatio/scheduling");
|
|
827
905
|
|
|
828
906
|
// src/respond.ts
|
|
829
907
|
var WIDGET_CACHE_HEADERS = {
|
|
@@ -870,7 +948,7 @@ async function getCapacity(request, { host }) {
|
|
|
870
948
|
select: { isGroup: true }
|
|
871
949
|
});
|
|
872
950
|
if (!type || !type.isGroup) return corsJson(cors, NOT_FOUND, { status: 404 });
|
|
873
|
-
return corsJson(cors, await (0,
|
|
951
|
+
return corsJson(cors, await (0, import_scheduling11.getGroupCapacity)(db, { typeId, calendarId, startTime }));
|
|
874
952
|
} catch (error) {
|
|
875
953
|
console.error("[group-capacity] unexpected error:", error instanceof Error ? error.message : error);
|
|
876
954
|
return corsJson(cors, { error: "Failed to fetch capacity" }, { status: 500 });
|
|
@@ -878,7 +956,7 @@ async function getCapacity(request, { host }) {
|
|
|
878
956
|
}
|
|
879
957
|
|
|
880
958
|
// src/handlers/payment-intent.ts
|
|
881
|
-
var
|
|
959
|
+
var import_scheduling12 = require("@ordinatio/scheduling");
|
|
882
960
|
var import_zod = require("zod");
|
|
883
961
|
|
|
884
962
|
// src/payments/create-payment-intent.ts
|
|
@@ -994,7 +1072,7 @@ async function createPaymentIntentRoute(request, { host }) {
|
|
|
994
1072
|
if (!result.ok) return corsJson(cors, { error: result.error }, { status: result.status });
|
|
995
1073
|
return corsJson(cors, result.body, { status: result.status });
|
|
996
1074
|
} catch (error) {
|
|
997
|
-
const err = (0,
|
|
1075
|
+
const err = (0, import_scheduling12.schedError)("SCHED_407", {
|
|
998
1076
|
typeId,
|
|
999
1077
|
calendarId,
|
|
1000
1078
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -1005,7 +1083,7 @@ async function createPaymentIntentRoute(request, { host }) {
|
|
|
1005
1083
|
}
|
|
1006
1084
|
|
|
1007
1085
|
// src/handlers/appointment-cancel.ts
|
|
1008
|
-
var
|
|
1086
|
+
var import_scheduling14 = require("@ordinatio/scheduling");
|
|
1009
1087
|
|
|
1010
1088
|
// src/appointments/owned-appointment.ts
|
|
1011
1089
|
async function verifyAppointmentOwnership(db, appointmentId, organizationId) {
|
|
@@ -1058,7 +1136,7 @@ async function writeRefundStatusAfterCancel(host, db, input) {
|
|
|
1058
1136
|
}
|
|
1059
1137
|
|
|
1060
1138
|
// src/staff/require-staff.ts
|
|
1061
|
-
var
|
|
1139
|
+
var import_scheduling13 = require("@ordinatio/scheduling");
|
|
1062
1140
|
async function requireAdminStaff(host, request, options) {
|
|
1063
1141
|
const staff = await host.staff.resolve(request);
|
|
1064
1142
|
if (!staff) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
@@ -1067,7 +1145,7 @@ async function requireAdminStaff(host, request, options) {
|
|
|
1067
1145
|
if (limited) return limited;
|
|
1068
1146
|
}
|
|
1069
1147
|
if (!staff.isAdmin && !options.allowAnyRole) {
|
|
1070
|
-
const err = (0,
|
|
1148
|
+
const err = (0, import_scheduling13.schedError)("SCHED_900", { userId: staff.userId, role: staff.role });
|
|
1071
1149
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
1072
1150
|
}
|
|
1073
1151
|
if (!staff.schedulingEnabled && !options.ignoreSchedulingSwitch) {
|
|
@@ -1110,7 +1188,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1110
1188
|
const appointment = await verifyAppointmentOwnership(db, id, organizationId);
|
|
1111
1189
|
if (!appointment) return Response.json({ error: "Appointment not found" }, { status: 404 });
|
|
1112
1190
|
const hasPayment = hasPendingPayment(appointment.paymentId, appointment.paymentStatus);
|
|
1113
|
-
const result = await (0,
|
|
1191
|
+
const result = await (0, import_scheduling14.cancelAppointment)(db, { appointmentId: id, cancelledBy: "staff", reason });
|
|
1114
1192
|
await writeRefundStatusAfterCancel(host, db, { appointmentId: id, hasPayment, clientName: appointment.clientName });
|
|
1115
1193
|
if (hasPayment) {
|
|
1116
1194
|
await host.activity.log(db, {
|
|
@@ -1130,7 +1208,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1130
1208
|
const baseUrl = host.appUrl();
|
|
1131
1209
|
if (baseUrl) {
|
|
1132
1210
|
try {
|
|
1133
|
-
await (0,
|
|
1211
|
+
await (0, import_scheduling14.queueStaffNotification)(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
|
|
1134
1212
|
} catch (error) {
|
|
1135
1213
|
await host.activity.log(db, {
|
|
1136
1214
|
action: "scheduling.staff_notification_failed",
|
|
@@ -1157,7 +1235,7 @@ async function cancelByStaff(request, { host, params }) {
|
|
|
1157
1235
|
});
|
|
1158
1236
|
return Response.json(withoutManageToken(result));
|
|
1159
1237
|
} catch (error) {
|
|
1160
|
-
if (error instanceof
|
|
1238
|
+
if (error instanceof import_scheduling14.SchedulingNotFoundError) {
|
|
1161
1239
|
return Response.json({ error: error.message, ref: error.ref }, { status: 404 });
|
|
1162
1240
|
}
|
|
1163
1241
|
const ref = getErrorRef(error);
|
|
@@ -1362,7 +1440,7 @@ function finishOutlookConnection(request, { host }) {
|
|
|
1362
1440
|
}
|
|
1363
1441
|
|
|
1364
1442
|
// src/handlers/appointment-cancel-sync.ts
|
|
1365
|
-
var
|
|
1443
|
+
var import_scheduling15 = require("@ordinatio/scheduling");
|
|
1366
1444
|
var import_zod2 = require("zod");
|
|
1367
1445
|
var Schema2 = import_zod2.z.object({
|
|
1368
1446
|
source: import_zod2.z.enum(["google", "outlook"]),
|
|
@@ -1405,13 +1483,13 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1405
1483
|
return Response.json({ error: "Appointment not available for sync" }, { status: 503 });
|
|
1406
1484
|
}
|
|
1407
1485
|
try {
|
|
1408
|
-
await (0,
|
|
1486
|
+
await (0, import_scheduling15.cancelAppointment)(db, {
|
|
1409
1487
|
appointmentId: id,
|
|
1410
1488
|
cancelledBy: "system",
|
|
1411
1489
|
reason: reason ?? `Cancelled via ${source === "google" ? "Google" : "Outlook"} Calendar`
|
|
1412
1490
|
});
|
|
1413
1491
|
} catch (error) {
|
|
1414
|
-
if (error instanceof
|
|
1492
|
+
if (error instanceof import_scheduling15.SchedulingNotFoundError) {
|
|
1415
1493
|
return Response.json({ error: "Appointment not found", ref: error.ref }, { status: 404 });
|
|
1416
1494
|
}
|
|
1417
1495
|
const ref = getErrorRef(error);
|
|
@@ -1445,7 +1523,7 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1445
1523
|
await host.workerCommands.queue(source === "google" ? "delete-from-outlook" : "delete-from-google", { appointmentId: id });
|
|
1446
1524
|
const baseUrl = host.appUrl();
|
|
1447
1525
|
if (baseUrl) {
|
|
1448
|
-
await (0,
|
|
1526
|
+
await (0, import_scheduling15.queueImmediateNotification)(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }).catch(
|
|
1449
1527
|
(err) => console.warn("[cancel-sync] Failed to queue cancellation notification:", id, err instanceof Error ? err.message : err)
|
|
1450
1528
|
);
|
|
1451
1529
|
}
|
|
@@ -1458,10 +1536,10 @@ async function cancelFromCalendarSync(request, { host, params }) {
|
|
|
1458
1536
|
}
|
|
1459
1537
|
|
|
1460
1538
|
// src/handlers/appointment-approve.ts
|
|
1461
|
-
var
|
|
1539
|
+
var import_scheduling16 = require("@ordinatio/scheduling");
|
|
1462
1540
|
async function rejectAppointment(host, db, organizationId, appointment, reason) {
|
|
1463
1541
|
const { id } = appointment;
|
|
1464
|
-
const result = await (0,
|
|
1542
|
+
const result = await (0, import_scheduling16.cancelAppointment)(db, {
|
|
1465
1543
|
appointmentId: id,
|
|
1466
1544
|
cancelledBy: "staff",
|
|
1467
1545
|
reason: reason || "Appointment request rejected"
|
|
@@ -1543,10 +1621,10 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1543
1621
|
if (confirmed.count === 0) {
|
|
1544
1622
|
return Response.json({ error: "Appointment was already processed by a concurrent request" }, { status: 409 });
|
|
1545
1623
|
}
|
|
1546
|
-
await (0,
|
|
1624
|
+
await (0, import_scheduling16.cancelPendingNotifications)(db, id);
|
|
1547
1625
|
const baseUrl = host.appUrl();
|
|
1548
1626
|
if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
|
|
1549
|
-
await (0,
|
|
1627
|
+
await (0, import_scheduling16.scheduleNotifications)(db, id, baseUrl, { brand: Boolean(host.brand) });
|
|
1550
1628
|
await host.availabilityCache.invalidate(appointment.calendarId);
|
|
1551
1629
|
await host.events.emit(organizationId, "appointment.confirmed", { appointmentId: id });
|
|
1552
1630
|
await host.activity.log(db, {
|
|
@@ -1554,7 +1632,7 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1554
1632
|
description: `approved ${appointment.clientName}'s appointment`,
|
|
1555
1633
|
metadata: { appointmentId: id, clientName: appointment.clientName }
|
|
1556
1634
|
});
|
|
1557
|
-
const confirmedAppointment = await (0,
|
|
1635
|
+
const confirmedAppointment = await (0, import_scheduling16.getAppointment)(db, id);
|
|
1558
1636
|
return Response.json({ success: true, status: "CONFIRMED", appointment: withoutManageToken(confirmedAppointment) });
|
|
1559
1637
|
} catch (error) {
|
|
1560
1638
|
if (getErrorCode(error) === "SCHED_306") {
|
|
@@ -1567,7 +1645,7 @@ async function approveOrReject(request, { host, params }) {
|
|
|
1567
1645
|
}
|
|
1568
1646
|
|
|
1569
1647
|
// src/handlers/appointment-reschedule.ts
|
|
1570
|
-
var
|
|
1648
|
+
var import_scheduling17 = require("@ordinatio/scheduling");
|
|
1571
1649
|
var RESCHEDULE_BLOCKER_CODES = ["SCHED_301", "SCHED_307", "SCHED_309", "SCHED_802"];
|
|
1572
1650
|
async function rescheduleByStaff(request, { host, params }) {
|
|
1573
1651
|
try {
|
|
@@ -1595,21 +1673,21 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1595
1673
|
if (newTime < /* @__PURE__ */ new Date()) {
|
|
1596
1674
|
return Response.json({ error: "Cannot reschedule to a past time" }, { status: 400 });
|
|
1597
1675
|
}
|
|
1598
|
-
const result = await (0,
|
|
1676
|
+
const result = await (0, import_scheduling17.rescheduleAppointment)(db, {
|
|
1599
1677
|
appointmentId: id,
|
|
1600
1678
|
newStartTime: newTime,
|
|
1601
1679
|
reason: "Rescheduled via calendar drag"
|
|
1602
1680
|
});
|
|
1603
1681
|
const baseUrl = host.appUrl();
|
|
1604
1682
|
if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
|
|
1605
|
-
await (0,
|
|
1683
|
+
await (0, import_scheduling17.queueImmediateNotification)(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
1606
1684
|
try {
|
|
1607
|
-
await (0,
|
|
1685
|
+
await (0, import_scheduling17.scheduleNotifications)(db, id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
1608
1686
|
} catch (error) {
|
|
1609
1687
|
console.warn("[reschedule] scheduleNotifications failed:", error instanceof Error ? error.message : error);
|
|
1610
1688
|
}
|
|
1611
1689
|
try {
|
|
1612
|
-
await (0,
|
|
1690
|
+
await (0, import_scheduling17.queueStaffNotification)(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
|
|
1613
1691
|
} catch (error) {
|
|
1614
1692
|
await host.activity.log(db, {
|
|
1615
1693
|
action: "scheduling.staff_notification_failed",
|
|
@@ -1647,8 +1725,8 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1647
1725
|
});
|
|
1648
1726
|
return Response.json(withoutManageToken(result));
|
|
1649
1727
|
} catch (error) {
|
|
1650
|
-
if (error instanceof
|
|
1651
|
-
if (error instanceof
|
|
1728
|
+
if (error instanceof import_scheduling17.SchedulingValidationError) return Response.json({ error: error.message }, { status: 400 });
|
|
1729
|
+
if (error instanceof import_scheduling17.SchedulingNotFoundError) return Response.json({ error: error.message }, { status: 404 });
|
|
1652
1730
|
const errorCode = getErrorCode(error) ?? "";
|
|
1653
1731
|
const status = errorCode === "SCHED_306" ? 400 : RESCHEDULE_BLOCKER_CODES.includes(errorCode) ? 409 : 500;
|
|
1654
1732
|
return Response.json({ error: getErrorMessage(error, "Failed to reschedule") }, { status });
|
|
@@ -1656,7 +1734,7 @@ async function rescheduleByStaff(request, { host, params }) {
|
|
|
1656
1734
|
}
|
|
1657
1735
|
|
|
1658
1736
|
// src/handlers/appointment-reassign.ts
|
|
1659
|
-
var
|
|
1737
|
+
var import_scheduling18 = require("@ordinatio/scheduling");
|
|
1660
1738
|
var import_zod3 = require("zod");
|
|
1661
1739
|
var REASSIGNABLE_STATUSES = ["PENDING", "CONFIRMED"];
|
|
1662
1740
|
var REASSIGN_MAX_ATTEMPTS = 2;
|
|
@@ -1707,7 +1785,7 @@ async function reassignAppointment(request, { host, params }) {
|
|
|
1707
1785
|
if (!current || !REASSIGNABLE_STATUSES.includes(current.status)) {
|
|
1708
1786
|
return { outcome: "statusChanged", currentStatus: current?.status ?? "unknown" };
|
|
1709
1787
|
}
|
|
1710
|
-
const available = await (0,
|
|
1788
|
+
const available = await (0, import_scheduling18.isSlotAvailable)(txDb, calendarId, current.startTime, current.duration, id);
|
|
1711
1789
|
if (!available) return { outcome: "conflict" };
|
|
1712
1790
|
const updated2 = await tx.appointment.update({
|
|
1713
1791
|
where: { id, status: { in: [...REASSIGNABLE_STATUSES] } },
|
|
@@ -1733,14 +1811,14 @@ async function reassignAppointment(request, { host, params }) {
|
|
|
1733
1811
|
};
|
|
1734
1812
|
const result = await attemptReassign();
|
|
1735
1813
|
if (result.outcome === "statusChanged") {
|
|
1736
|
-
const diagnostic = (0,
|
|
1814
|
+
const diagnostic = (0, import_scheduling18.schedError)("SCHED_309", { appointmentId: id, calendarId, currentStatus: result.currentStatus });
|
|
1737
1815
|
return Response.json(
|
|
1738
1816
|
{ error: "Appointment status changed before the reassignment could commit", ref: diagnostic.ref },
|
|
1739
1817
|
{ status: 409 }
|
|
1740
1818
|
);
|
|
1741
1819
|
}
|
|
1742
1820
|
if (result.outcome === "conflict") {
|
|
1743
|
-
const diagnostic = (0,
|
|
1821
|
+
const diagnostic = (0, import_scheduling18.schedError)("SCHED_301", { appointmentId: id, calendarId });
|
|
1744
1822
|
return Response.json(
|
|
1745
1823
|
{ error: "Target calendar is not available at this appointment's time", ref: diagnostic.ref },
|
|
1746
1824
|
{ status: 409 }
|
|
@@ -1903,7 +1981,7 @@ async function listNotifications(request, { host, params }) {
|
|
|
1903
1981
|
}
|
|
1904
1982
|
|
|
1905
1983
|
// src/handlers/appointment-no-show.ts
|
|
1906
|
-
var
|
|
1984
|
+
var import_scheduling19 = require("@ordinatio/scheduling");
|
|
1907
1985
|
async function markAppointmentNoShow(request, { host, params }) {
|
|
1908
1986
|
try {
|
|
1909
1987
|
const staff = await requireAdminStaff(host, request, {
|
|
@@ -1920,7 +1998,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1920
1998
|
}
|
|
1921
1999
|
const appointment = await verifyAppointmentOwnership(db, id, organizationId);
|
|
1922
2000
|
if (!appointment) return Response.json({ error: "Appointment not found" }, { status: 404 });
|
|
1923
|
-
const result = await (0,
|
|
2001
|
+
const result = await (0, import_scheduling19.markNoShow)(db, { appointmentId: id });
|
|
1924
2002
|
await host.events.emit(organizationId, "appointment.no_show", { appointmentId: id });
|
|
1925
2003
|
await host.activity.log(db, {
|
|
1926
2004
|
action: "scheduling.appointment_no_show",
|
|
@@ -1929,7 +2007,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1929
2007
|
});
|
|
1930
2008
|
return Response.json(withoutManageToken(result));
|
|
1931
2009
|
} catch (error) {
|
|
1932
|
-
if (error instanceof
|
|
2010
|
+
if (error instanceof import_scheduling19.SchedulingNotFoundError) {
|
|
1933
2011
|
return Response.json({ error: error.message, ref: error.ref }, { status: 404 });
|
|
1934
2012
|
}
|
|
1935
2013
|
const ref = getErrorRef(error);
|
|
@@ -1939,7 +2017,7 @@ async function markAppointmentNoShow(request, { host, params }) {
|
|
|
1939
2017
|
}
|
|
1940
2018
|
|
|
1941
2019
|
// src/handlers/appointment-collect-balance.ts
|
|
1942
|
-
var
|
|
2020
|
+
var import_scheduling22 = require("@ordinatio/scheduling");
|
|
1943
2021
|
|
|
1944
2022
|
// src/payments/balance/eligibility.ts
|
|
1945
2023
|
var BALANCE_BLOCKED_APPOINTMENT_STATUS = "CANCELLED";
|
|
@@ -2035,7 +2113,7 @@ function resolveBalanceEligibility(appointment, organizationId) {
|
|
|
2035
2113
|
}
|
|
2036
2114
|
|
|
2037
2115
|
// src/payments/balance/record-intent.ts
|
|
2038
|
-
var
|
|
2116
|
+
var import_scheduling20 = require("@ordinatio/scheduling");
|
|
2039
2117
|
var BALANCE_OUTCOME_TRACE = {
|
|
2040
2118
|
cancelled: {
|
|
2041
2119
|
action: "scheduling.balance_intent_cancelled",
|
|
@@ -2078,7 +2156,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2078
2156
|
data: { balancePaymentId: intentId }
|
|
2079
2157
|
});
|
|
2080
2158
|
} catch (writeError) {
|
|
2081
|
-
const diagnostic = (0,
|
|
2159
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2082
2160
|
error: writeError,
|
|
2083
2161
|
appointmentId,
|
|
2084
2162
|
paymentIntentId: intentId,
|
|
@@ -2100,7 +2178,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2100
2178
|
select: { balancePaymentId: true, status: true, refundStatus: true, paymentStatus: true }
|
|
2101
2179
|
});
|
|
2102
2180
|
} catch (rereadError) {
|
|
2103
|
-
const diagnostic = (0,
|
|
2181
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2104
2182
|
error: rereadError,
|
|
2105
2183
|
appointmentId,
|
|
2106
2184
|
paymentIntentId: intentId,
|
|
@@ -2117,7 +2195,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2117
2195
|
const stillEligible = current !== null && !isBalanceBlockedByStatus(current.status) && !hasBalanceRefundStarted(current.refundStatus);
|
|
2118
2196
|
if (current?.balancePaymentId === intentId) {
|
|
2119
2197
|
if (stillEligible) return { ok: true };
|
|
2120
|
-
const diagnostic = (0,
|
|
2198
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2121
2199
|
appointmentId,
|
|
2122
2200
|
paymentIntentId: intentId,
|
|
2123
2201
|
status: current.status,
|
|
@@ -2159,7 +2237,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2159
2237
|
outcome = "cancel-failed";
|
|
2160
2238
|
}
|
|
2161
2239
|
if (outcome !== cancelledOutcome) {
|
|
2162
|
-
const diagnostic = (0,
|
|
2240
|
+
const diagnostic = (0, import_scheduling20.schedError)("SCHED_605", {
|
|
2163
2241
|
error: cancelError,
|
|
2164
2242
|
appointmentId,
|
|
2165
2243
|
paymentIntentId: intentId,
|
|
@@ -2207,7 +2285,7 @@ async function recordBalanceIntent(db, payments, target) {
|
|
|
2207
2285
|
}
|
|
2208
2286
|
|
|
2209
2287
|
// src/payments/balance/create-intent.ts
|
|
2210
|
-
var
|
|
2288
|
+
var import_scheduling21 = require("@ordinatio/scheduling");
|
|
2211
2289
|
|
|
2212
2290
|
// src/payments/unverified-payment-error.ts
|
|
2213
2291
|
var UnverifiedPaymentError = class extends Error {
|
|
@@ -2253,7 +2331,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2253
2331
|
});
|
|
2254
2332
|
} catch (error) {
|
|
2255
2333
|
if (error instanceof UnverifiedPaymentError) {
|
|
2256
|
-
const diagnostic2 = (0,
|
|
2334
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2257
2335
|
error,
|
|
2258
2336
|
appointmentId,
|
|
2259
2337
|
paymentIntentId: error.paymentId,
|
|
@@ -2273,7 +2351,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2273
2351
|
return { paymentId: result.paymentId, clientSecret: result.clientSecret ?? null };
|
|
2274
2352
|
}
|
|
2275
2353
|
if (result.code === "IN_PROGRESS") {
|
|
2276
|
-
const diagnostic2 = (0,
|
|
2354
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2277
2355
|
error: result.error,
|
|
2278
2356
|
appointmentId,
|
|
2279
2357
|
key,
|
|
@@ -2283,7 +2361,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2283
2361
|
throw new BalanceRequestInProgressError(diagnostic2.ref);
|
|
2284
2362
|
}
|
|
2285
2363
|
if (result.code === "KEY_REUSED") {
|
|
2286
|
-
const diagnostic2 = (0,
|
|
2364
|
+
const diagnostic2 = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2287
2365
|
error: result.error,
|
|
2288
2366
|
appointmentId,
|
|
2289
2367
|
abandonedKey: key,
|
|
@@ -2299,7 +2377,7 @@ async function createBalanceIntent(payments, input, appointmentId) {
|
|
|
2299
2377
|
if (result.code === "CANCELED") continue;
|
|
2300
2378
|
throw new Error(result.error ?? "The payment provider did not create the balance payment");
|
|
2301
2379
|
}
|
|
2302
|
-
const diagnostic = (0,
|
|
2380
|
+
const diagnostic = (0, import_scheduling21.schedError)("SCHED_605", {
|
|
2303
2381
|
appointmentId,
|
|
2304
2382
|
phase: "balance-key-generations-exhausted",
|
|
2305
2383
|
generations: MAX_KEY_GENERATIONS2
|
|
@@ -2391,7 +2469,7 @@ async function collectAppointmentBalance(request, { host, params }) {
|
|
|
2391
2469
|
if (error instanceof BalanceRequestInProgressError || error instanceof BalanceIntentGenerationsExhaustedError) {
|
|
2392
2470
|
return Response.json({ error: error.message, ref: error.ref }, { status: 409 });
|
|
2393
2471
|
}
|
|
2394
|
-
const diagnostic = (0,
|
|
2472
|
+
const diagnostic = (0, import_scheduling22.schedError)("SCHED_605", { error, appointmentId });
|
|
2395
2473
|
console.error("[POST /collect-balance]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
2396
2474
|
return Response.json({ error: "Failed to create balance payment", ref: diagnostic.ref }, { status: 500 });
|
|
2397
2475
|
}
|
|
@@ -2401,7 +2479,7 @@ async function collectAppointmentBalance(request, { host, params }) {
|
|
|
2401
2479
|
var import_zod6 = require("zod");
|
|
2402
2480
|
|
|
2403
2481
|
// src/payments/refund/refund-status.ts
|
|
2404
|
-
var
|
|
2482
|
+
var import_scheduling23 = require("@ordinatio/scheduling");
|
|
2405
2483
|
var REFUND_STATUS_BUCKET = {
|
|
2406
2484
|
PENDING_REVIEW: "retryable",
|
|
2407
2485
|
REFUND_FAILED: "retryable",
|
|
@@ -2423,7 +2501,7 @@ var CREDIT_REFUSED_NEXT_STEP = "Retry the refund to resolve the remaining balanc
|
|
|
2423
2501
|
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
2502
|
function checkCreditGuard(action, refundAmount, refundStatus) {
|
|
2425
2503
|
if (refundStatus == null) {
|
|
2426
|
-
const diagnostic = (0,
|
|
2504
|
+
const diagnostic = (0, import_scheduling23.schedError)("SCHED_610", {
|
|
2427
2505
|
action,
|
|
2428
2506
|
refundAmount,
|
|
2429
2507
|
error: "checkCreditGuard was called without a refundStatus"
|
|
@@ -2469,10 +2547,10 @@ function checkCreditGuard(action, refundAmount, refundStatus) {
|
|
|
2469
2547
|
}
|
|
2470
2548
|
|
|
2471
2549
|
// src/money.ts
|
|
2472
|
-
var
|
|
2550
|
+
var import_scheduling24 = require("@ordinatio/scheduling");
|
|
2473
2551
|
function decimalToCents(value, field = "unknown") {
|
|
2474
2552
|
if (value === null || value === void 0) {
|
|
2475
|
-
throw new
|
|
2553
|
+
throw new import_scheduling24.SchedulingValidationError(
|
|
2476
2554
|
`Could not convert ${field} to cents \u2014 value is ${value}`,
|
|
2477
2555
|
"SCHED_406",
|
|
2478
2556
|
{ field, value }
|
|
@@ -2480,7 +2558,7 @@ function decimalToCents(value, field = "unknown") {
|
|
|
2480
2558
|
}
|
|
2481
2559
|
const cents = Math.round(Number(value) * 100);
|
|
2482
2560
|
if (!Number.isFinite(cents)) {
|
|
2483
|
-
throw new
|
|
2561
|
+
throw new import_scheduling24.SchedulingValidationError(
|
|
2484
2562
|
`Could not convert ${field} to cents \u2014 value is not numeric`,
|
|
2485
2563
|
"SCHED_406",
|
|
2486
2564
|
{ field, value }
|
|
@@ -2491,7 +2569,7 @@ function decimalToCents(value, field = "unknown") {
|
|
|
2491
2569
|
|
|
2492
2570
|
// src/payments/refund/refund-leg.ts
|
|
2493
2571
|
var import_node_crypto2 = require("crypto");
|
|
2494
|
-
var
|
|
2572
|
+
var import_scheduling25 = require("@ordinatio/scheduling");
|
|
2495
2573
|
async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix, appointmentId, errorCode, logLabel) {
|
|
2496
2574
|
const baseKey = `refund:${appointmentId}:${idempotencyKeySuffix}`;
|
|
2497
2575
|
let idempotencyKey = baseKey;
|
|
@@ -2524,7 +2602,7 @@ async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix,
|
|
|
2524
2602
|
return { succeeded: true, amountCents: null };
|
|
2525
2603
|
}
|
|
2526
2604
|
if (result.code === "IN_PROGRESS") {
|
|
2527
|
-
const inFlight = (0,
|
|
2605
|
+
const inFlight = (0, import_scheduling25.schedError)(errorCode, { error: result.error, appointmentId, paymentIntentId, kind: "idempotency_key_in_use" });
|
|
2528
2606
|
console.warn(
|
|
2529
2607
|
`[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
2608
|
inFlight.ref,
|
|
@@ -2549,22 +2627,22 @@ async function attemptLegRefund(payments, paymentIntentId, idempotencyKeySuffix,
|
|
|
2549
2627
|
return failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay, { error: result.error, message: result.error ?? result.code ?? "no reason given", requestId: result.requestId });
|
|
2550
2628
|
}
|
|
2551
2629
|
}
|
|
2552
|
-
function failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay,
|
|
2553
|
-
const diagnostic = (0,
|
|
2630
|
+
function failedLeg(errorCode, logLabel, appointmentId, paymentIntentId, idempotencyKey, retriedAfterReplay, failure5) {
|
|
2631
|
+
const diagnostic = (0, import_scheduling25.schedError)(errorCode, { error: failure5.error, appointmentId, paymentIntentId });
|
|
2554
2632
|
console.error(
|
|
2555
2633
|
`[resolve-refund] ${logLabel} refund failed${retriedAfterReplay ? " (after a fresh-key re-attempt)" : ""} \u2014 manual refund may be required:`,
|
|
2556
2634
|
diagnostic.ref,
|
|
2557
2635
|
appointmentId,
|
|
2558
2636
|
paymentIntentId,
|
|
2559
|
-
`requestId=${
|
|
2637
|
+
`requestId=${failure5.requestId}`,
|
|
2560
2638
|
`idempotencyKey=${idempotencyKey}`,
|
|
2561
|
-
|
|
2639
|
+
failure5.message
|
|
2562
2640
|
);
|
|
2563
2641
|
return { succeeded: false, amountCents: null };
|
|
2564
2642
|
}
|
|
2565
2643
|
|
|
2566
2644
|
// src/payments/refund/persist-refund-outcome.ts
|
|
2567
|
-
var
|
|
2645
|
+
var import_scheduling26 = require("@ordinatio/scheduling");
|
|
2568
2646
|
var WEBHOOK_RACE_OUTCOMES = ["REFUNDED", "PARTIAL_REFUND"];
|
|
2569
2647
|
var SUCCESS_RANK = {
|
|
2570
2648
|
REFUND_FAILED: 0,
|
|
@@ -2609,7 +2687,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2609
2687
|
});
|
|
2610
2688
|
} catch (writeErr) {
|
|
2611
2689
|
const dbMessage = writeErr instanceof Error ? writeErr.message : String(writeErr);
|
|
2612
|
-
const diagnostic = (0,
|
|
2690
|
+
const diagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2613
2691
|
error: writeErr,
|
|
2614
2692
|
dbMessage,
|
|
2615
2693
|
appointmentId: id,
|
|
@@ -2633,7 +2711,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2633
2711
|
}
|
|
2634
2712
|
if (writeResult.count === 0) {
|
|
2635
2713
|
const buildLostRaceError = () => {
|
|
2636
|
-
const diagnostic = (0,
|
|
2714
|
+
const diagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2637
2715
|
appointmentId: id,
|
|
2638
2716
|
phase: "persist-cas-lost-race",
|
|
2639
2717
|
refundOutcome,
|
|
@@ -2672,7 +2750,7 @@ async function persistRefundOutcome(db, id, refundOutcome, refundAmount, legs) {
|
|
|
2672
2750
|
if (reconcileResult.count === 0) {
|
|
2673
2751
|
throw buildLostRaceError();
|
|
2674
2752
|
}
|
|
2675
|
-
const reconcileDiagnostic = (0,
|
|
2753
|
+
const reconcileDiagnostic = (0, import_scheduling26.schedError)("SCHED_610", {
|
|
2676
2754
|
appointmentId: id,
|
|
2677
2755
|
phase: "persist-cas-reconciled",
|
|
2678
2756
|
refundOutcome,
|
|
@@ -2771,7 +2849,7 @@ async function executeRefundLegs(db, id, preClaimSnapshot, payments) {
|
|
|
2771
2849
|
}
|
|
2772
2850
|
|
|
2773
2851
|
// src/payments/refund/refund-housekeeping.ts
|
|
2774
|
-
var
|
|
2852
|
+
var import_scheduling27 = require("@ordinatio/scheduling");
|
|
2775
2853
|
async function runHousekeeping(db, activity, appointment, id, action, newRefundStatus, userId) {
|
|
2776
2854
|
const isTerminalSuccess = TERMINAL_SUCCESS_STATUSES.includes(newRefundStatus);
|
|
2777
2855
|
try {
|
|
@@ -2787,7 +2865,7 @@ async function runHousekeeping(db, activity, appointment, id, action, newRefundS
|
|
|
2787
2865
|
});
|
|
2788
2866
|
return void 0;
|
|
2789
2867
|
} catch (err) {
|
|
2790
|
-
const diagnostic = (0,
|
|
2868
|
+
const diagnostic = (0, import_scheduling27.schedError)("SCHED_606", { error: err, appointmentId: id, phase: "housekeeping" });
|
|
2791
2869
|
console.error(
|
|
2792
2870
|
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
2871
|
diagnostic.ref,
|
|
@@ -2872,9 +2950,9 @@ async function evaluatePreClaimState(input) {
|
|
|
2872
2950
|
}
|
|
2873
2951
|
|
|
2874
2952
|
// src/payments/refund/refund-failure-response.ts
|
|
2875
|
-
var
|
|
2953
|
+
var import_scheduling28 = require("@ordinatio/scheduling");
|
|
2876
2954
|
function refundFailureResponse({ error, id, stripeMayHaveMoved }) {
|
|
2877
|
-
const diagnostic = (0,
|
|
2955
|
+
const diagnostic = (0, import_scheduling28.schedError)("SCHED_610", { error, appointmentId: id, stripeMayHaveMoved });
|
|
2878
2956
|
console.error("[POST /resolve-refund]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
2879
2957
|
if (!stripeMayHaveMoved) {
|
|
2880
2958
|
return Response.json({ error: "Failed to resolve refund", ref: diagnostic.ref }, { status: 500 });
|
|
@@ -3412,6 +3490,13 @@ var TextSettingsSchema = import_zod15.z.object({
|
|
|
3412
3490
|
enabled: import_zod15.z.boolean().optional()
|
|
3413
3491
|
}).strict();
|
|
3414
3492
|
|
|
3493
|
+
// src/schemas/api-key.schema.ts
|
|
3494
|
+
var import_zod16 = require("zod");
|
|
3495
|
+
var ApiKeySchema = import_zod16.z.object({
|
|
3496
|
+
name: import_zod16.z.string().max(200),
|
|
3497
|
+
access: import_zod16.z.string().max(20)
|
|
3498
|
+
}).strict();
|
|
3499
|
+
|
|
3415
3500
|
// src/pagination.ts
|
|
3416
3501
|
var DEFAULT_LIMIT = 50;
|
|
3417
3502
|
var MAX_LIMIT = 200;
|
|
@@ -3433,12 +3518,12 @@ function parsePagination(request, maxLimit = MAX_LIMIT, defaultLimit = DEFAULT_L
|
|
|
3433
3518
|
}
|
|
3434
3519
|
|
|
3435
3520
|
// src/validation.ts
|
|
3436
|
-
var
|
|
3521
|
+
var import_zod17 = require("zod");
|
|
3437
3522
|
async function parseBody(request, schema) {
|
|
3438
3523
|
try {
|
|
3439
3524
|
return { success: true, data: schema.parse(await request.json()) };
|
|
3440
3525
|
} catch (error) {
|
|
3441
|
-
if (error instanceof
|
|
3526
|
+
if (error instanceof import_zod17.ZodError) {
|
|
3442
3527
|
const details = error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message }));
|
|
3443
3528
|
return { success: false, response: Response.json({ error: "Validation failed", details }, { status: 400 }) };
|
|
3444
3529
|
}
|
|
@@ -3452,7 +3537,7 @@ function validateData(data, schema) {
|
|
|
3452
3537
|
try {
|
|
3453
3538
|
return { success: true, data: schema.parse(data) };
|
|
3454
3539
|
} catch (error) {
|
|
3455
|
-
if (error instanceof
|
|
3540
|
+
if (error instanceof import_zod17.ZodError) {
|
|
3456
3541
|
return { success: false, errors: error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message })) };
|
|
3457
3542
|
}
|
|
3458
3543
|
return { success: false, errors: [{ field: "", message: "Validation failed" }] };
|
|
@@ -3938,7 +4023,7 @@ async function updatePackagePurchase(request, { host, params }) {
|
|
|
3938
4023
|
}
|
|
3939
4024
|
|
|
3940
4025
|
// src/handlers/admin-group-sessions.ts
|
|
3941
|
-
var
|
|
4026
|
+
var import_scheduling29 = require("@ordinatio/scheduling");
|
|
3942
4027
|
var MAX_RANGE_MS = 366 * 24 * 60 * 60 * 1e3;
|
|
3943
4028
|
async function listGroupSessions(request, { host }) {
|
|
3944
4029
|
try {
|
|
@@ -3956,29 +4041,29 @@ async function listGroupSessions(request, { host }) {
|
|
|
3956
4041
|
return Response.json({ error: "Invalid date format \u2014 use ISO 8601" }, { status: 400 });
|
|
3957
4042
|
}
|
|
3958
4043
|
if (startDate >= endDate) {
|
|
3959
|
-
const err = (0,
|
|
4044
|
+
const err = (0, import_scheduling29.schedError)("SCHED_310", { startDateStr, endDateStr });
|
|
3960
4045
|
return Response.json({ error: "startDate must be before endDate", ref: err.ref }, { status: 400 });
|
|
3961
4046
|
}
|
|
3962
4047
|
if (endDate.getTime() - startDate.getTime() > MAX_RANGE_MS) {
|
|
3963
|
-
const err = (0,
|
|
4048
|
+
const err = (0, import_scheduling29.schedError)("SCHED_312", { startDateStr, endDateStr });
|
|
3964
4049
|
return Response.json({ error: "Date range exceeds maximum allowed (366 days)", ref: err.ref }, { status: 400 });
|
|
3965
4050
|
}
|
|
3966
4051
|
const calendarId = params.get("calendarId") || void 0;
|
|
3967
4052
|
const visibleCalendarIds = await staff.visibleCalendarIds();
|
|
3968
|
-
const { sessions, hasMore } = await (0,
|
|
4053
|
+
const { sessions, hasMore } = await (0, import_scheduling29.getGroupSessions)(staff.db, { startDate, endDate, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
|
|
3969
4054
|
return Response.json({ sessions, total: sessions.length, hasMore });
|
|
3970
4055
|
} catch (error) {
|
|
3971
|
-
const err = (0,
|
|
4056
|
+
const err = (0, import_scheduling29.schedError)("SCHED_311", { error });
|
|
3972
4057
|
console.error("[group-sessions]", err.ref, error);
|
|
3973
4058
|
return Response.json({ error: "Failed to fetch group sessions", ref: err.ref }, { status: 500 });
|
|
3974
4059
|
}
|
|
3975
4060
|
}
|
|
3976
4061
|
|
|
3977
4062
|
// src/handlers/admin-recurring.ts
|
|
3978
|
-
var
|
|
4063
|
+
var import_scheduling32 = require("@ordinatio/scheduling");
|
|
3979
4064
|
|
|
3980
4065
|
// src/recurring/series-side-effects.ts
|
|
3981
|
-
var
|
|
4066
|
+
var import_scheduling30 = require("@ordinatio/scheduling");
|
|
3982
4067
|
|
|
3983
4068
|
// src/recurring/failure-collector.ts
|
|
3984
4069
|
function createFailureCollector() {
|
|
@@ -4042,7 +4127,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4042
4127
|
const sendConfirmation = async (url, appointmentId) => {
|
|
4043
4128
|
for (let tryNumber = 1; tryNumber <= 2; tryNumber += 1) {
|
|
4044
4129
|
try {
|
|
4045
|
-
await (0,
|
|
4130
|
+
await (0, import_scheduling30.scheduleNotifications)(db, appointmentId, url, { brand: Boolean(host.brand) });
|
|
4046
4131
|
return;
|
|
4047
4132
|
} catch (error) {
|
|
4048
4133
|
if (tryNumber === 2) record("Client confirmation", error);
|
|
@@ -4055,7 +4140,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4055
4140
|
await sendConfirmation(baseUrl, visit.id);
|
|
4056
4141
|
} else {
|
|
4057
4142
|
await attempt("Client notices", async () => {
|
|
4058
|
-
await (0,
|
|
4143
|
+
await (0, import_scheduling30.scheduleNotifications)(db, visit.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
|
|
4059
4144
|
});
|
|
4060
4145
|
}
|
|
4061
4146
|
}
|
|
@@ -4075,7 +4160,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4075
4160
|
await Promise.all(visits.slice(from, from + VISITS_PER_GROUP).map(handleVisit));
|
|
4076
4161
|
}
|
|
4077
4162
|
if (baseUrl && confirmationVisit) {
|
|
4078
|
-
await attempt("Staff alert", () => (0,
|
|
4163
|
+
await attempt("Staff alert", () => (0, import_scheduling30.queueStaffNotification)(db, confirmationVisit.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) }));
|
|
4079
4164
|
}
|
|
4080
4165
|
await attempt("Availability cache", () => host.availabilityCache.invalidate(first.calendarId));
|
|
4081
4166
|
await attempt(
|
|
@@ -4091,11 +4176,11 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
|
|
|
4091
4176
|
}
|
|
4092
4177
|
|
|
4093
4178
|
// src/recurring/validate-timezone.ts
|
|
4094
|
-
var
|
|
4179
|
+
var import_scheduling31 = require("@ordinatio/scheduling");
|
|
4095
4180
|
var SUPPORTED_TIMEZONES = new Set(Intl.supportedValuesOf("timeZone"));
|
|
4096
4181
|
function validateRecurringTimezone(timezone) {
|
|
4097
4182
|
if (isValidIanaTimezone(timezone)) return null;
|
|
4098
|
-
const err = (0,
|
|
4183
|
+
const err = (0, import_scheduling31.schedError)("SCHED_704", { timezone });
|
|
4099
4184
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4100
4185
|
}
|
|
4101
4186
|
function isValidIanaTimezone(timezone) {
|
|
@@ -4148,12 +4233,12 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4148
4233
|
const validation = await parseBody(request, CreateRecurringSeriesSchema);
|
|
4149
4234
|
if (!validation.success) return validation.response;
|
|
4150
4235
|
const input = validation.data;
|
|
4151
|
-
if (input.occurrences < 1 || input.occurrences >
|
|
4152
|
-
const err = (0,
|
|
4236
|
+
if (input.occurrences < 1 || input.occurrences > import_scheduling32.RECURRING_MAX_OCCURRENCES) {
|
|
4237
|
+
const err = (0, import_scheduling32.schedError)("SCHED_701", { occurrences: input.occurrences });
|
|
4153
4238
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4154
4239
|
}
|
|
4155
|
-
if (!(0,
|
|
4156
|
-
const err = (0,
|
|
4240
|
+
if (!(0, import_scheduling32.parseTimeLocal)(input.startTimeLocal)) {
|
|
4241
|
+
const err = (0, import_scheduling32.schedError)("SCHED_700", { startTimeLocal: input.startTimeLocal });
|
|
4157
4242
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4158
4243
|
}
|
|
4159
4244
|
const tzError = validateRecurringTimezone(input.timezone);
|
|
@@ -4182,7 +4267,7 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4182
4267
|
});
|
|
4183
4268
|
const firstDate = new Date(input.firstDate);
|
|
4184
4269
|
const endsAt = input.endsAt ? new Date(input.endsAt) : void 0;
|
|
4185
|
-
const slots = (0,
|
|
4270
|
+
const slots = (0, import_scheduling32.buildRecurringSlots)(
|
|
4186
4271
|
firstDate,
|
|
4187
4272
|
input.frequency,
|
|
4188
4273
|
input.occurrences,
|
|
@@ -4271,17 +4356,17 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4271
4356
|
}
|
|
4272
4357
|
|
|
4273
4358
|
// src/handlers/admin-recurring-detail.ts
|
|
4274
|
-
var
|
|
4359
|
+
var import_scheduling34 = require("@ordinatio/scheduling");
|
|
4275
4360
|
|
|
4276
4361
|
// src/recurring/series-cancel-side-effects.ts
|
|
4277
|
-
var
|
|
4362
|
+
var import_scheduling33 = require("@ordinatio/scheduling");
|
|
4278
4363
|
var OCCURRENCES_PER_GROUP = 8;
|
|
4279
4364
|
async function runSeriesCancelSideEffects(host, db, organizationId, seriesId, seriesCalendarId, occurrences) {
|
|
4280
4365
|
if (occurrences.length === 0) return { failures: [] };
|
|
4281
4366
|
const { attempt, record, lines } = createFailureCollector();
|
|
4282
4367
|
const handle = async (occurrence) => {
|
|
4283
4368
|
const { id } = occurrence;
|
|
4284
|
-
await attempt("Pending reminders", () => (0,
|
|
4369
|
+
await attempt("Pending reminders", () => (0, import_scheduling33.cancelPendingNotifications)(db, id));
|
|
4285
4370
|
const hasPayment = hasPendingPayment(occurrence.paymentId, occurrence.paymentStatus);
|
|
4286
4371
|
await attempt("Refund review flag", async () => {
|
|
4287
4372
|
await writeRefundStatusAfterCancel(host, db, { appointmentId: id, hasPayment, clientName: occurrence.clientName });
|
|
@@ -4313,7 +4398,7 @@ async function runSeriesCancelSideEffects(host, db, organizationId, seriesId, se
|
|
|
4313
4398
|
}
|
|
4314
4399
|
const baseUrl = host.appUrl()?.trim();
|
|
4315
4400
|
if (baseUrl) {
|
|
4316
|
-
await attempt("Staff notice", () => (0,
|
|
4401
|
+
await attempt("Staff notice", () => (0, import_scheduling33.queueStaffNotification)(db, occurrences[0].id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }));
|
|
4317
4402
|
} else {
|
|
4318
4403
|
record("Staff notice", "skipped because the application address is not set");
|
|
4319
4404
|
}
|
|
@@ -4359,7 +4444,7 @@ async function getRecurringSeries(request, { host, params }) {
|
|
|
4359
4444
|
}
|
|
4360
4445
|
});
|
|
4361
4446
|
if (!series || !await staff.canSeeCalendar(series.calendar.id)) {
|
|
4362
|
-
const err = (0,
|
|
4447
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId });
|
|
4363
4448
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4364
4449
|
}
|
|
4365
4450
|
return Response.json({ series });
|
|
@@ -4386,14 +4471,14 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4386
4471
|
select: { id: true, status: true, clientName: true, clientEmail: true, frequency: true, occurrences: true, calendarId: true }
|
|
4387
4472
|
});
|
|
4388
4473
|
if (!series) {
|
|
4389
|
-
const err = (0,
|
|
4474
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId });
|
|
4390
4475
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4391
4476
|
}
|
|
4392
4477
|
if (!await staff.canSeeCalendar(series.calendarId)) {
|
|
4393
4478
|
return Response.json({ error: "Calendar not found" }, { status: 404 });
|
|
4394
4479
|
}
|
|
4395
4480
|
if ((input.scope === "ONE" || input.scope === "THIS_AND_FOLLOWING") && !input.fromAppointmentId) {
|
|
4396
|
-
const err = (0,
|
|
4481
|
+
const err = (0, import_scheduling34.schedError)("SCHED_703", { scope: input.scope });
|
|
4397
4482
|
return Response.json({ error: err.description, ref: err.ref }, { status: 422 });
|
|
4398
4483
|
}
|
|
4399
4484
|
const NON_CANCELLABLE_STATUSES = ["CANCELLED", "COMPLETED", "NO_SHOW"];
|
|
@@ -4421,7 +4506,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4421
4506
|
if (hiddenCalendars) {
|
|
4422
4507
|
const hidden = await db.appointment.count({ where: { ...open, calendar: { organizationId, NOT: hiddenCalendars } } });
|
|
4423
4508
|
if (hidden > 0) {
|
|
4424
|
-
const err = (0,
|
|
4509
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { seriesId: id, organizationId, reason: "open occurrence on a calendar outside the viewer scope" });
|
|
4425
4510
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4426
4511
|
}
|
|
4427
4512
|
}
|
|
@@ -4454,7 +4539,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4454
4539
|
return Response.json({ cancelledCount, newSeriesStatus, ...warnings.length > 0 && { warnings } });
|
|
4455
4540
|
} catch (error) {
|
|
4456
4541
|
if (error?.code === "P2025") {
|
|
4457
|
-
const err = (0,
|
|
4542
|
+
const err = (0, import_scheduling34.schedError)("SCHED_702", { race: "series vanished between org-scoped pre-check and cancellation transaction" });
|
|
4458
4543
|
return Response.json({ error: err.description, ref: err.ref }, { status: 404 });
|
|
4459
4544
|
}
|
|
4460
4545
|
return Response.json({ error: getErrorMessage(error, "Failed to cancel recurring series") }, { status: 500 });
|
|
@@ -4462,7 +4547,7 @@ async function cancelRecurringSeries(request, { host, params }) {
|
|
|
4462
4547
|
}
|
|
4463
4548
|
|
|
4464
4549
|
// src/handlers/booking-analytics.ts
|
|
4465
|
-
var
|
|
4550
|
+
var import_scheduling35 = require("@ordinatio/scheduling");
|
|
4466
4551
|
async function getAnalytics(request, { host }) {
|
|
4467
4552
|
try {
|
|
4468
4553
|
const staff = await host.staff.resolve(request);
|
|
@@ -4474,7 +4559,7 @@ async function getAnalytics(request, { host }) {
|
|
|
4474
4559
|
const limited = await host.rateLimit(`analytics:${ip}`, "GENERAL");
|
|
4475
4560
|
if (limited) return limited;
|
|
4476
4561
|
if (!staff.isAdmin) {
|
|
4477
|
-
const err = (0,
|
|
4562
|
+
const err = (0, import_scheduling35.schedError)("SCHED_900", { userId: staff.userId, role: staff.role });
|
|
4478
4563
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
4479
4564
|
}
|
|
4480
4565
|
const params = new URL(request.url).searchParams;
|
|
@@ -4500,7 +4585,7 @@ async function getAnalytics(request, { host }) {
|
|
|
4500
4585
|
}
|
|
4501
4586
|
}
|
|
4502
4587
|
const visibleCalendarIds = await staff.visibleCalendarIds();
|
|
4503
|
-
const analytics = await (0,
|
|
4588
|
+
const analytics = await (0, import_scheduling35.getBookingAnalytics)(staff.db, { days, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
|
|
4504
4589
|
return Response.json(analytics);
|
|
4505
4590
|
} catch (error) {
|
|
4506
4591
|
const ref = getErrorRef(error);
|
|
@@ -4519,11 +4604,11 @@ function escapeHtml(text) {
|
|
|
4519
4604
|
}
|
|
4520
4605
|
|
|
4521
4606
|
// src/brand/brand-http.ts
|
|
4522
|
-
var
|
|
4607
|
+
var import_scheduling36 = require("@ordinatio/scheduling");
|
|
4523
4608
|
var NOT_ENABLED = { error: "Branding is not enabled on this server" };
|
|
4524
4609
|
function brandErrorResponse(error, fallback, cors) {
|
|
4525
4610
|
const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
|
|
4526
|
-
if (error instanceof
|
|
4611
|
+
if (error instanceof import_scheduling36.SchedulingValidationError) {
|
|
4527
4612
|
const details = error.context.errors;
|
|
4528
4613
|
return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, 400);
|
|
4529
4614
|
}
|
|
@@ -4539,7 +4624,7 @@ async function requireBrandAdmin(host, request, options) {
|
|
|
4539
4624
|
async function businessName(host, db, organizationId) {
|
|
4540
4625
|
if (host.brand) {
|
|
4541
4626
|
try {
|
|
4542
|
-
const brand = await (0,
|
|
4627
|
+
const brand = await (0, import_scheduling36.getBrand)(db, organizationId);
|
|
4543
4628
|
if (brand) return brand.displayName;
|
|
4544
4629
|
} catch (error) {
|
|
4545
4630
|
console.error("[brand] could not read the brand for a message:", error);
|
|
@@ -4707,7 +4792,7 @@ We look forward to seeing you!
|
|
|
4707
4792
|
}
|
|
4708
4793
|
|
|
4709
4794
|
// src/handlers/calendar-ownership.ts
|
|
4710
|
-
var
|
|
4795
|
+
var import_scheduling37 = require("@ordinatio/scheduling");
|
|
4711
4796
|
var SAFE_CALENDAR_FIELDS = [
|
|
4712
4797
|
"id",
|
|
4713
4798
|
"organizationId",
|
|
@@ -4774,7 +4859,7 @@ async function getOwnedCalendarForRoute(db, id, organizationId) {
|
|
|
4774
4859
|
async function validateStaffLink(host, userId, organizationId) {
|
|
4775
4860
|
if (!userId) return null;
|
|
4776
4861
|
if (await host.staffDirectory.isMember(organizationId, userId)) return null;
|
|
4777
|
-
const err = (0,
|
|
4862
|
+
const err = (0, import_scheduling37.schedError)("SCHED_104", { userId, organizationId });
|
|
4778
4863
|
return Response.json({ error: "That staff member is not part of this organization", ref: err.ref }, { status: 400 });
|
|
4779
4864
|
}
|
|
4780
4865
|
function buildCalendarUpdateData(input) {
|
|
@@ -4821,7 +4906,7 @@ async function releaseCalendarSlugIfStillInactive(host, db, calendarId, organiza
|
|
|
4821
4906
|
}
|
|
4822
4907
|
async function undoArchive(host, db, calendarId, organizationId, slug) {
|
|
4823
4908
|
try {
|
|
4824
|
-
await (0,
|
|
4909
|
+
await (0, import_scheduling37.updateCalendar)(db, calendarId, organizationId, { isActive: true });
|
|
4825
4910
|
} catch (restoreError) {
|
|
4826
4911
|
console.error("[calendar update] could not switch the calendar back on after a failed update", calendarId, restoreError);
|
|
4827
4912
|
try {
|
|
@@ -4920,7 +5005,7 @@ async function createCalendar(request, { host }) {
|
|
|
4920
5005
|
}
|
|
4921
5006
|
|
|
4922
5007
|
// src/handlers/admin-calendar-update.ts
|
|
4923
|
-
var
|
|
5008
|
+
var import_scheduling38 = require("@ordinatio/scheduling");
|
|
4924
5009
|
var NOT_FOUND5 = () => Response.json({ error: "Calendar not found" }, { status: 404 });
|
|
4925
5010
|
async function getCalendar(request, { host, params }) {
|
|
4926
5011
|
try {
|
|
@@ -4962,10 +5047,10 @@ async function putCalendar(request, { host, params }) {
|
|
|
4962
5047
|
let updated;
|
|
4963
5048
|
try {
|
|
4964
5049
|
if (archiving) {
|
|
4965
|
-
await (0,
|
|
5050
|
+
await (0, import_scheduling38.archiveCalendar)(db, id, organizationId);
|
|
4966
5051
|
archived = true;
|
|
4967
5052
|
}
|
|
4968
|
-
({ calendar: updated } = await (0,
|
|
5053
|
+
({ calendar: updated } = await (0, import_scheduling38.updateCalendar)(db, id, organizationId, buildCalendarUpdateData(input)));
|
|
4969
5054
|
} catch (error) {
|
|
4970
5055
|
if (archived) await undoArchive(host, db, id, organizationId, existing.slug);
|
|
4971
5056
|
throw error;
|
|
@@ -4994,7 +5079,7 @@ async function deleteCalendar(request, { host, params }) {
|
|
|
4994
5079
|
if (!await staff.canSeeCalendar(id)) return NOT_FOUND5();
|
|
4995
5080
|
const existing = await getOwnedCalendarForRoute(db, id, organizationId);
|
|
4996
5081
|
if (!existing) return NOT_FOUND5();
|
|
4997
|
-
await (0,
|
|
5082
|
+
await (0, import_scheduling38.archiveCalendar)(db, id, organizationId);
|
|
4998
5083
|
await releaseCalendarSlugIfStillInactive(host, db, id, organizationId, existing.slug);
|
|
4999
5084
|
await bustCalendarCachesOnArchive(host, organizationId, existing.slug, id);
|
|
5000
5085
|
await host.activity.log(db, {
|
|
@@ -5145,7 +5230,7 @@ async function disconnectOutlook(request, { host, params }) {
|
|
|
5145
5230
|
}
|
|
5146
5231
|
|
|
5147
5232
|
// src/handlers/admin-calendar-location-recents.ts
|
|
5148
|
-
var
|
|
5233
|
+
var import_scheduling39 = require("@ordinatio/scheduling");
|
|
5149
5234
|
async function getLocationRecents(request, { host, params }) {
|
|
5150
5235
|
try {
|
|
5151
5236
|
const staff = await requireAdminStaff(host, request, {
|
|
@@ -5190,14 +5275,14 @@ async function getLocationRecents(request, { host, params }) {
|
|
|
5190
5275
|
}
|
|
5191
5276
|
return Response.json({ locations });
|
|
5192
5277
|
} catch (error) {
|
|
5193
|
-
const diagnostic = (0,
|
|
5278
|
+
const diagnostic = (0, import_scheduling39.schedError)("SCHED_207", { error });
|
|
5194
5279
|
console.error("[location-recents]", diagnostic.ref, error);
|
|
5195
5280
|
return Response.json({ error: "Failed to fetch location recents", ref: diagnostic.ref }, { status: 500 });
|
|
5196
5281
|
}
|
|
5197
5282
|
}
|
|
5198
5283
|
|
|
5199
5284
|
// src/handlers/admin-availability-rules.ts
|
|
5200
|
-
var
|
|
5285
|
+
var import_scheduling40 = require("@ordinatio/scheduling");
|
|
5201
5286
|
|
|
5202
5287
|
// src/availability/admin-calendar.ts
|
|
5203
5288
|
async function verifyCalendar(db, calendarId, organizationId) {
|
|
@@ -5271,7 +5356,7 @@ async function listRules(request, { host, params }) {
|
|
|
5271
5356
|
const calendar = await requireOwnedVisibleCalendar(staff, calendarId);
|
|
5272
5357
|
if (calendar instanceof Response) return calendar;
|
|
5273
5358
|
const { limit, offset } = parsePagination(request, 500, 200);
|
|
5274
|
-
const { rules, total, hasMore } = await (0,
|
|
5359
|
+
const { rules, total, hasMore } = await (0, import_scheduling40.listAvailabilityRules)(staff.db, calendarId, { limit, offset });
|
|
5275
5360
|
return Response.json({ rules, total, hasMore });
|
|
5276
5361
|
} catch (error) {
|
|
5277
5362
|
return Response.json({ error: getErrorMessage(error, "Failed to fetch availability") }, { status: 500 });
|
|
@@ -5290,7 +5375,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5290
5375
|
if (!Array.isArray(rules)) return Response.json({ error: "rules must be an array" }, { status: 400 });
|
|
5291
5376
|
const validationError = validateWeeklyRules(rules);
|
|
5292
5377
|
if (validationError) return Response.json({ error: validationError }, { status: 400 });
|
|
5293
|
-
const created = await (0,
|
|
5378
|
+
const created = await (0, import_scheduling40.setWeeklyAvailability)(db, calendarId, rules);
|
|
5294
5379
|
await clearAvailabilityCache(host, calendarId);
|
|
5295
5380
|
const activeDays = rules.map((r) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][r.dayOfWeek]).join(", ");
|
|
5296
5381
|
await host.activity.log(db, {
|
|
@@ -5301,7 +5386,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5301
5386
|
return Response.json(created);
|
|
5302
5387
|
} catch (error) {
|
|
5303
5388
|
const msg = getErrorMessage(error, "Failed to update availability");
|
|
5304
|
-
if (error instanceof
|
|
5389
|
+
if (error instanceof import_scheduling40.SchedulingValidationError) {
|
|
5305
5390
|
console.error("[PUT /admin/availability]", error.ref, error.code, error.context);
|
|
5306
5391
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5307
5392
|
}
|
|
@@ -5310,18 +5395,18 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5310
5395
|
}
|
|
5311
5396
|
|
|
5312
5397
|
// src/handlers/admin-availability-overrides.ts
|
|
5313
|
-
var
|
|
5398
|
+
var import_scheduling42 = require("@ordinatio/scheduling");
|
|
5314
5399
|
|
|
5315
5400
|
// src/availability/override-helpers.ts
|
|
5316
|
-
var
|
|
5401
|
+
var import_scheduling41 = require("@ordinatio/scheduling");
|
|
5317
5402
|
function sanitizeBlockReason(raw) {
|
|
5318
5403
|
if (!raw) return void 0;
|
|
5319
5404
|
return String(raw).replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<[^>]*>/g, "").slice(0, 500).trim() || void 0;
|
|
5320
5405
|
}
|
|
5321
5406
|
async function checkOverlappingAppointments(db, calendarId, calendarTimezone, dateStr, startTime, endTime) {
|
|
5322
5407
|
const tz = calendarTimezone ?? "America/New_York";
|
|
5323
|
-
const blockStart = (0,
|
|
5324
|
-
const blockEnd = (0,
|
|
5408
|
+
const blockStart = (0, import_scheduling41.localToUTC)(dateStr, startTime, tz);
|
|
5409
|
+
const blockEnd = (0, import_scheduling41.localToUTC)(dateStr, endTime, tz);
|
|
5325
5410
|
const conflictCount = await db.appointment.count({
|
|
5326
5411
|
where: {
|
|
5327
5412
|
calendarId,
|
|
@@ -5351,14 +5436,14 @@ async function addOverride(request, { host, params }) {
|
|
|
5351
5436
|
const isBlockedFlag = body.isBlocked ?? true;
|
|
5352
5437
|
let override;
|
|
5353
5438
|
if (isBlockedFlag && body.startTime && body.endTime) {
|
|
5354
|
-
override = await (0,
|
|
5439
|
+
override = await (0, import_scheduling42.addTimeBlock)(db, calendarId, {
|
|
5355
5440
|
date,
|
|
5356
5441
|
startTime: body.startTime,
|
|
5357
5442
|
endTime: body.endTime,
|
|
5358
5443
|
reason: blockReason
|
|
5359
5444
|
});
|
|
5360
5445
|
} else {
|
|
5361
|
-
override = await (0,
|
|
5446
|
+
override = await (0, import_scheduling42.addDateOverride)(db, calendarId, {
|
|
5362
5447
|
date,
|
|
5363
5448
|
isBlocked: isBlockedFlag,
|
|
5364
5449
|
blockReason,
|
|
@@ -5395,7 +5480,7 @@ async function addOverride(request, { host, params }) {
|
|
|
5395
5480
|
return Response.json({ ...override, ...overlapWarning && { warning: overlapWarning } }, { status: 201 });
|
|
5396
5481
|
} catch (error) {
|
|
5397
5482
|
const msg = getErrorMessage(error, "Failed to add override");
|
|
5398
|
-
if (error instanceof
|
|
5483
|
+
if (error instanceof import_scheduling42.SchedulingValidationError) {
|
|
5399
5484
|
console.error("[POST /admin/availability]", error.ref, error.code, error.context);
|
|
5400
5485
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5401
5486
|
}
|
|
@@ -5412,7 +5497,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5412
5497
|
if (calendar instanceof Response) return calendar;
|
|
5413
5498
|
const { ruleId } = await request.json();
|
|
5414
5499
|
if (!ruleId) return Response.json({ error: "ruleId is required" }, { status: 400 });
|
|
5415
|
-
const deletedRule = await (0,
|
|
5500
|
+
const deletedRule = await (0, import_scheduling42.removeDateOverride)(db, calendarId, ruleId);
|
|
5416
5501
|
await clearAvailabilityCache(host, calendarId);
|
|
5417
5502
|
const deletedIsTimeBlock = deletedRule?.isBlocked && !(deletedRule.startTime === "00:00" && deletedRule.endTime === "00:00");
|
|
5418
5503
|
await host.activity.log(db, {
|
|
@@ -5423,7 +5508,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5423
5508
|
return Response.json({ success: true });
|
|
5424
5509
|
} catch (error) {
|
|
5425
5510
|
const msg = getErrorMessage(error, "Failed to remove override");
|
|
5426
|
-
if (error instanceof
|
|
5511
|
+
if (error instanceof import_scheduling42.SchedulingNotFoundError) {
|
|
5427
5512
|
console.error("[DELETE /admin/availability]", error.ref, error.code, error.context);
|
|
5428
5513
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5429
5514
|
}
|
|
@@ -5432,7 +5517,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5432
5517
|
}
|
|
5433
5518
|
|
|
5434
5519
|
// src/handlers/admin-templates.ts
|
|
5435
|
-
var
|
|
5520
|
+
var import_scheduling43 = require("@ordinatio/scheduling");
|
|
5436
5521
|
|
|
5437
5522
|
// src/sanitize/notification-body.ts
|
|
5438
5523
|
var import_sanitize_html = __toESM(require("sanitize-html"));
|
|
@@ -5456,7 +5541,7 @@ async function listTemplates(request, { host }) {
|
|
|
5456
5541
|
try {
|
|
5457
5542
|
const staff = await requireAdminStaff(host, request, { action: "admin-templates-list", tier: "GENERAL" });
|
|
5458
5543
|
if (staff instanceof Response) return staff;
|
|
5459
|
-
return Response.json(await (0,
|
|
5544
|
+
return Response.json(await (0, import_scheduling43.listNotificationTemplates)(staff.db, staff.organizationId));
|
|
5460
5545
|
} catch (error) {
|
|
5461
5546
|
return Response.json({ error: getErrorMessage(error, "Failed to fetch templates") }, { status: 500 });
|
|
5462
5547
|
}
|
|
@@ -5481,7 +5566,7 @@ async function createTemplate(request, { host }) {
|
|
|
5481
5566
|
if (input.channel === "EMAIL" && !stripHtml(input.subject).trim()) {
|
|
5482
5567
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
5483
5568
|
}
|
|
5484
|
-
const template = await (0,
|
|
5569
|
+
const template = await (0, import_scheduling43.createNotificationTemplate)(db, organizationId, {
|
|
5485
5570
|
name: input.name,
|
|
5486
5571
|
channel: input.channel,
|
|
5487
5572
|
trigger: input.trigger,
|
|
@@ -5507,7 +5592,7 @@ async function createTemplate(request, { host }) {
|
|
|
5507
5592
|
}
|
|
5508
5593
|
|
|
5509
5594
|
// src/handlers/admin-template-update.ts
|
|
5510
|
-
var
|
|
5595
|
+
var import_scheduling44 = require("@ordinatio/scheduling");
|
|
5511
5596
|
async function updateTemplate(request, { host, params }) {
|
|
5512
5597
|
try {
|
|
5513
5598
|
const staff = await requireAdminStaff(host, request, { action: "admin-templates-update", tier: "UPDATE" });
|
|
@@ -5539,7 +5624,7 @@ async function updateTemplate(request, { host, params }) {
|
|
|
5539
5624
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
5540
5625
|
}
|
|
5541
5626
|
}
|
|
5542
|
-
const updated = await (0,
|
|
5627
|
+
const updated = await (0, import_scheduling44.updateNotificationTemplate)(db, organizationId, id, {
|
|
5543
5628
|
name: input.name,
|
|
5544
5629
|
subject: sanitizedSubject,
|
|
5545
5630
|
body: input.body !== void 0 ? sanitizeNotificationBody(input.body, existing.channel) : void 0,
|
|
@@ -5553,11 +5638,11 @@ async function updateTemplate(request, { host, params }) {
|
|
|
5553
5638
|
return Response.json(updated);
|
|
5554
5639
|
} catch (error) {
|
|
5555
5640
|
const msg = getErrorMessage(error, "Failed to update template");
|
|
5556
|
-
if (error instanceof
|
|
5641
|
+
if (error instanceof import_scheduling44.SchedulingValidationError) {
|
|
5557
5642
|
console.error("[PUT /admin/templates]", error.ref, error.code, error.context);
|
|
5558
5643
|
return Response.json({ error: msg, ref: error.ref }, { status: 400 });
|
|
5559
5644
|
}
|
|
5560
|
-
if (error instanceof
|
|
5645
|
+
if (error instanceof import_scheduling44.SchedulingNotFoundError) {
|
|
5561
5646
|
console.error("[PUT /admin/templates]", error.ref, error.code, error.context);
|
|
5562
5647
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5563
5648
|
}
|
|
@@ -5574,7 +5659,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5574
5659
|
where: { id, organizationId },
|
|
5575
5660
|
select: { name: true }
|
|
5576
5661
|
});
|
|
5577
|
-
await (0,
|
|
5662
|
+
await (0, import_scheduling44.deleteNotificationTemplate)(db, organizationId, id);
|
|
5578
5663
|
await host.activity.log(db, {
|
|
5579
5664
|
action: "scheduling.template_deleted",
|
|
5580
5665
|
description: `deleted notification template "${template?.name || id}"`,
|
|
@@ -5583,7 +5668,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5583
5668
|
return Response.json({ success: true });
|
|
5584
5669
|
} catch (error) {
|
|
5585
5670
|
const msg = getErrorMessage(error, "Failed to delete template");
|
|
5586
|
-
if (error instanceof
|
|
5671
|
+
if (error instanceof import_scheduling44.SchedulingNotFoundError) {
|
|
5587
5672
|
console.error("[DELETE /admin/templates]", error.ref, error.code, error.context);
|
|
5588
5673
|
return Response.json({ error: msg, ref: error.ref }, { status: 404 });
|
|
5589
5674
|
}
|
|
@@ -5592,7 +5677,7 @@ async function deleteTemplate(request, { host, params }) {
|
|
|
5592
5677
|
}
|
|
5593
5678
|
|
|
5594
5679
|
// src/handlers/admin-types.ts
|
|
5595
|
-
var
|
|
5680
|
+
var import_scheduling45 = require("@ordinatio/scheduling");
|
|
5596
5681
|
async function listTypes(request, { host }) {
|
|
5597
5682
|
try {
|
|
5598
5683
|
const staff = await requireAdminStaff(host, request, { action: "admin-types-list", tier: "GENERAL" });
|
|
@@ -5622,7 +5707,7 @@ async function createType(request, { host }) {
|
|
|
5622
5707
|
if (!validation.success) return validation.response;
|
|
5623
5708
|
if (!organizationId) return Response.json({ error: "Organization context required" }, { status: 400 });
|
|
5624
5709
|
const input = validation.data;
|
|
5625
|
-
const type = await (0,
|
|
5710
|
+
const type = await (0, import_scheduling45.createAppointmentType)(db, {
|
|
5626
5711
|
name: input.name,
|
|
5627
5712
|
slug: input.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""),
|
|
5628
5713
|
description: input.description || void 0,
|
|
@@ -5681,7 +5766,7 @@ async function createType(request, { host }) {
|
|
|
5681
5766
|
}
|
|
5682
5767
|
|
|
5683
5768
|
// src/handlers/admin-type-update.ts
|
|
5684
|
-
var
|
|
5769
|
+
var import_scheduling46 = require("@ordinatio/scheduling");
|
|
5685
5770
|
|
|
5686
5771
|
// src/handlers/type-ownership.ts
|
|
5687
5772
|
async function getOwnedAppointmentType(db, id, organizationId) {
|
|
@@ -5762,7 +5847,7 @@ async function updateType(request, { host, params }) {
|
|
|
5762
5847
|
const validation = await parseBody(request, UpdateAppointmentTypeSchema);
|
|
5763
5848
|
if (!validation.success) return validation.response;
|
|
5764
5849
|
const input = validation.data;
|
|
5765
|
-
const { type: updated, wasActive } = await (0,
|
|
5850
|
+
const { type: updated, wasActive } = await (0, import_scheduling46.updateAppointmentType)(db, id, organizationId, input);
|
|
5766
5851
|
if (input.isActive === false && wasActive && typeToUpdate.organizationId) {
|
|
5767
5852
|
await releaseTypeSlugIfStillInactive(host, db, id, typeToUpdate.organizationId, typeToUpdate.slug);
|
|
5768
5853
|
}
|
|
@@ -5779,7 +5864,7 @@ async function updateType(request, { host, params }) {
|
|
|
5779
5864
|
return Response.json({ error: getErrorMessage(error, "Validation error") }, { status: schedErrorStatus(code) });
|
|
5780
5865
|
}
|
|
5781
5866
|
const message = isSchedulingServiceError(error) ? error.description || error.message : getErrorMessage(error, "Failed to update appointment type");
|
|
5782
|
-
if (error instanceof
|
|
5867
|
+
if (error instanceof import_scheduling46.SchedulingValidationError) return Response.json({ error: message }, { status: 400 });
|
|
5783
5868
|
return Response.json({ error: message }, { status: 500 });
|
|
5784
5869
|
}
|
|
5785
5870
|
}
|
|
@@ -6031,7 +6116,7 @@ async function getStaffOptions(request, { host }) {
|
|
|
6031
6116
|
|
|
6032
6117
|
// src/handlers/appointment-ical.ts
|
|
6033
6118
|
var import_ical_generator = __toESM(require("ical-generator"));
|
|
6034
|
-
var
|
|
6119
|
+
var import_scheduling47 = require("@ordinatio/scheduling");
|
|
6035
6120
|
async function getAppointmentIcal(request, { host }) {
|
|
6036
6121
|
let token = null;
|
|
6037
6122
|
try {
|
|
@@ -6065,7 +6150,7 @@ async function getAppointmentIcal(request, { host }) {
|
|
|
6065
6150
|
timezone: appointment.timezone,
|
|
6066
6151
|
summary,
|
|
6067
6152
|
description,
|
|
6068
|
-
location: (0,
|
|
6153
|
+
location: (0, import_scheduling47.resolveLocation)(appointment) ?? void 0,
|
|
6069
6154
|
url: manageUrl,
|
|
6070
6155
|
organizer: staffName && staffEmail ? { name: staffName, email: staffEmail } : void 0
|
|
6071
6156
|
});
|
|
@@ -6077,17 +6162,17 @@ async function getAppointmentIcal(request, { host }) {
|
|
|
6077
6162
|
}
|
|
6078
6163
|
});
|
|
6079
6164
|
} catch (error) {
|
|
6080
|
-
const diagnostic = (0,
|
|
6165
|
+
const diagnostic = (0, import_scheduling47.schedError)("SCHED_600", { error, token: token ?? "unknown" });
|
|
6081
6166
|
console.error("[GET /ical]", diagnostic.ref, error instanceof Error ? error.message : error);
|
|
6082
6167
|
return Response.json({ error: "Failed to generate calendar file", ref: diagnostic.ref }, { status: 500 });
|
|
6083
6168
|
}
|
|
6084
6169
|
}
|
|
6085
6170
|
|
|
6086
6171
|
// src/handlers/admin-webhooks.ts
|
|
6087
|
-
var
|
|
6172
|
+
var import_scheduling49 = require("@ordinatio/scheduling");
|
|
6088
6173
|
|
|
6089
6174
|
// src/webhooks/require-webhooks.ts
|
|
6090
|
-
var
|
|
6175
|
+
var import_scheduling48 = require("@ordinatio/scheduling");
|
|
6091
6176
|
async function requireWebhooksAdmin(host, request, options) {
|
|
6092
6177
|
const staff = await requireAdminStaff(host, request, options);
|
|
6093
6178
|
if (staff instanceof Response) return staff;
|
|
@@ -6095,10 +6180,10 @@ async function requireWebhooksAdmin(host, request, options) {
|
|
|
6095
6180
|
return { staff, settings: host.webhooks };
|
|
6096
6181
|
}
|
|
6097
6182
|
function webhookErrorResponse(error, fallback) {
|
|
6098
|
-
if (error instanceof
|
|
6183
|
+
if (error instanceof import_scheduling48.SchedulingValidationError) {
|
|
6099
6184
|
return Response.json({ error: error.message, ref: getErrorRef(error) }, { status: 400 });
|
|
6100
6185
|
}
|
|
6101
|
-
if (error instanceof
|
|
6186
|
+
if (error instanceof import_scheduling48.SchedulingNotFoundError) {
|
|
6102
6187
|
return Response.json({ error: error.message, ref: getErrorRef(error) }, { status: 404 });
|
|
6103
6188
|
}
|
|
6104
6189
|
return Response.json({ error: getErrorMessage(error, fallback) }, { status: 500 });
|
|
@@ -6110,7 +6195,7 @@ async function listWebhooks(request, { host }) {
|
|
|
6110
6195
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-list", tier: "GENERAL" });
|
|
6111
6196
|
if (guard instanceof Response) return guard;
|
|
6112
6197
|
const { db, organizationId } = guard.staff;
|
|
6113
|
-
return Response.json({ endpoints: await (0,
|
|
6198
|
+
return Response.json({ endpoints: await (0, import_scheduling49.listWebhookEndpoints)(db, organizationId), eventTypes: import_scheduling49.WEBHOOK_EVENT_TYPES });
|
|
6114
6199
|
} catch (error) {
|
|
6115
6200
|
return webhookErrorResponse(error, "Failed to list webhooks");
|
|
6116
6201
|
}
|
|
@@ -6123,7 +6208,7 @@ async function createWebhook(request, { host }) {
|
|
|
6123
6208
|
const validation = await parseBody(request, CreateWebhookEndpointSchema);
|
|
6124
6209
|
if (!validation.success) return validation.response;
|
|
6125
6210
|
const input = validation.data;
|
|
6126
|
-
const { endpoint, secret } = await (0,
|
|
6211
|
+
const { endpoint, secret } = await (0, import_scheduling49.createWebhookEndpoint)(
|
|
6127
6212
|
db,
|
|
6128
6213
|
{ organizationId, url: input.url, eventTypes: input.eventTypes, description: input.description },
|
|
6129
6214
|
{ allowInsecureTargets: guard.settings.allowInsecureTargets }
|
|
@@ -6140,14 +6225,14 @@ async function createWebhook(request, { host }) {
|
|
|
6140
6225
|
}
|
|
6141
6226
|
|
|
6142
6227
|
// src/handlers/admin-webhook-detail.ts
|
|
6143
|
-
var
|
|
6228
|
+
var import_scheduling50 = require("@ordinatio/scheduling");
|
|
6144
6229
|
var STATUSES = /* @__PURE__ */ new Set(["PENDING", "PROCESSING", "SUCCEEDED", "DEAD_LETTER"]);
|
|
6145
6230
|
async function deleteWebhook(request, { host, params }) {
|
|
6146
6231
|
try {
|
|
6147
6232
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-delete", tier: "DELETE" });
|
|
6148
6233
|
if (guard instanceof Response) return guard;
|
|
6149
6234
|
const { db, organizationId } = guard.staff;
|
|
6150
|
-
await (0,
|
|
6235
|
+
await (0, import_scheduling50.deleteWebhookEndpoint)(db, organizationId, params.id);
|
|
6151
6236
|
await host.activity.log(db, {
|
|
6152
6237
|
action: "scheduling.webhook_deleted",
|
|
6153
6238
|
description: "removed a webhook endpoint",
|
|
@@ -6163,7 +6248,7 @@ async function testWebhook(request, { host, params }) {
|
|
|
6163
6248
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-test", tier: "CREATE" });
|
|
6164
6249
|
if (guard instanceof Response) return guard;
|
|
6165
6250
|
const { db, organizationId } = guard.staff;
|
|
6166
|
-
const result = await (0,
|
|
6251
|
+
const result = await (0, import_scheduling50.sendTestWebhook)(
|
|
6167
6252
|
db,
|
|
6168
6253
|
{ organizationId, endpointId: params.id },
|
|
6169
6254
|
{ transport: guard.settings.transport, allowInsecureTargets: guard.settings.allowInsecureTargets }
|
|
@@ -6179,13 +6264,13 @@ async function listWebhookEndpointDeliveries(request, { host, params }) {
|
|
|
6179
6264
|
if (guard instanceof Response) return guard;
|
|
6180
6265
|
const { db, organizationId } = guard.staff;
|
|
6181
6266
|
const owned = await db.webhookEndpoint.count({ where: { id: params.id, organizationId } });
|
|
6182
|
-
if (owned === 0) throw new
|
|
6267
|
+
if (owned === 0) throw new import_scheduling50.SchedulingNotFoundError("Webhook endpoint not found", "SCHED_1003", { endpointId: params.id });
|
|
6183
6268
|
const status = new URL(request.url).searchParams.get("status");
|
|
6184
6269
|
if (status && !STATUSES.has(status)) {
|
|
6185
6270
|
return Response.json({ error: `status must be one of ${[...STATUSES].join(", ")}` }, { status: 400 });
|
|
6186
6271
|
}
|
|
6187
6272
|
const { limit, offset } = parsePagination(request);
|
|
6188
|
-
const { deliveries, total } = await (0,
|
|
6273
|
+
const { deliveries, total } = await (0, import_scheduling50.listWebhookDeliveries)(db, {
|
|
6189
6274
|
organizationId,
|
|
6190
6275
|
endpointId: params.id,
|
|
6191
6276
|
status: status ?? void 0,
|
|
@@ -6199,13 +6284,13 @@ async function listWebhookEndpointDeliveries(request, { host, params }) {
|
|
|
6199
6284
|
}
|
|
6200
6285
|
|
|
6201
6286
|
// src/handlers/admin-webhook-delivery-retry.ts
|
|
6202
|
-
var
|
|
6287
|
+
var import_scheduling51 = require("@ordinatio/scheduling");
|
|
6203
6288
|
async function retryWebhook(request, { host, params }) {
|
|
6204
6289
|
try {
|
|
6205
6290
|
const guard = await requireWebhooksAdmin(host, request, { action: "admin-webhooks-retry", tier: "UPDATE" });
|
|
6206
6291
|
if (guard instanceof Response) return guard;
|
|
6207
6292
|
const { db, organizationId } = guard.staff;
|
|
6208
|
-
await (0,
|
|
6293
|
+
await (0, import_scheduling51.retryWebhookDelivery)(db, organizationId, params.id);
|
|
6209
6294
|
return Response.json({ success: true });
|
|
6210
6295
|
} catch (error) {
|
|
6211
6296
|
return webhookErrorResponse(error, "Failed to retry the delivery");
|
|
@@ -6213,7 +6298,7 @@ async function retryWebhook(request, { host, params }) {
|
|
|
6213
6298
|
}
|
|
6214
6299
|
|
|
6215
6300
|
// src/handlers/internal-webhooks-deliver.ts
|
|
6216
|
-
var
|
|
6301
|
+
var import_scheduling52 = require("@ordinatio/scheduling");
|
|
6217
6302
|
async function deliverWebhooks(request, { host }) {
|
|
6218
6303
|
if (!await host.internalAccess.isAuthorized(request)) {
|
|
6219
6304
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
@@ -6222,7 +6307,7 @@ async function deliverWebhooks(request, { host }) {
|
|
|
6222
6307
|
const limited = await host.rateLimit(`${request.headers.get("x-forwarded-for") ?? "worker"}:webhooks-deliver`, "INTERNAL");
|
|
6223
6308
|
if (limited) return limited;
|
|
6224
6309
|
try {
|
|
6225
|
-
const summary = await (0,
|
|
6310
|
+
const summary = await (0, import_scheduling52.deliverDueWebhooks)(await host.publicDb(), {
|
|
6226
6311
|
transport: host.webhooks.transport,
|
|
6227
6312
|
allowInsecureTargets: host.webhooks.allowInsecureTargets
|
|
6228
6313
|
});
|
|
@@ -6234,11 +6319,11 @@ async function deliverWebhooks(request, { host }) {
|
|
|
6234
6319
|
}
|
|
6235
6320
|
|
|
6236
6321
|
// src/handlers/waitlist-join.ts
|
|
6237
|
-
var
|
|
6238
|
-
var
|
|
6322
|
+
var import_scheduling54 = require("@ordinatio/scheduling");
|
|
6323
|
+
var import_zod18 = require("zod");
|
|
6239
6324
|
|
|
6240
6325
|
// src/waitlist/waitlist-http.ts
|
|
6241
|
-
var
|
|
6326
|
+
var import_scheduling53 = require("@ordinatio/scheduling");
|
|
6242
6327
|
var NOT_ENABLED2 = { error: "The waitlist is not enabled on this server" };
|
|
6243
6328
|
var STATUS_BY_CODE = {
|
|
6244
6329
|
SCHED_1100: 404,
|
|
@@ -6253,8 +6338,8 @@ async function resolveWaitlistDb(host, orgSlug) {
|
|
|
6253
6338
|
return host.organizations.resolve({ orgSlug, logPrefix: "[waitlist]" });
|
|
6254
6339
|
}
|
|
6255
6340
|
function waitlistErrorResponse(cors, error, fallback) {
|
|
6256
|
-
if (error instanceof
|
|
6257
|
-
const status = STATUS_BY_CODE[error.code] ?? (error instanceof
|
|
6341
|
+
if (error instanceof import_scheduling53.SchedulingValidationError || error instanceof import_scheduling53.SchedulingNotFoundError) {
|
|
6342
|
+
const status = STATUS_BY_CODE[error.code] ?? (error instanceof import_scheduling53.SchedulingNotFoundError ? 404 : 400);
|
|
6258
6343
|
return corsJson(cors, { error: error.message, code: error.code, ref: getErrorRef(error) }, { status });
|
|
6259
6344
|
}
|
|
6260
6345
|
console.error("[waitlist]", error);
|
|
@@ -6268,15 +6353,15 @@ async function requireWaitlistAdmin(host, request, options) {
|
|
|
6268
6353
|
}
|
|
6269
6354
|
|
|
6270
6355
|
// src/handlers/waitlist-join.ts
|
|
6271
|
-
var JoinWaitlistSchema =
|
|
6272
|
-
orgSlug:
|
|
6273
|
-
typeId:
|
|
6274
|
-
calendarId:
|
|
6275
|
-
day:
|
|
6276
|
-
slotStart:
|
|
6277
|
-
clientName:
|
|
6278
|
-
clientEmail:
|
|
6279
|
-
clientPhone:
|
|
6356
|
+
var JoinWaitlistSchema = import_zod18.z.object({
|
|
6357
|
+
orgSlug: import_zod18.z.string().min(1).max(100).optional(),
|
|
6358
|
+
typeId: import_zod18.z.string().min(1),
|
|
6359
|
+
calendarId: import_zod18.z.string().min(1).optional(),
|
|
6360
|
+
day: import_zod18.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Day must be YYYY-MM-DD"),
|
|
6361
|
+
slotStart: import_zod18.z.string().datetime({ message: "Invalid date/time format" }).optional(),
|
|
6362
|
+
clientName: import_zod18.z.string().trim().min(1, "Name is required").max(200),
|
|
6363
|
+
clientEmail: import_zod18.z.string().email("Invalid email").max(254),
|
|
6364
|
+
clientPhone: import_zod18.z.string().max(30).optional()
|
|
6280
6365
|
});
|
|
6281
6366
|
async function joinWaitlistRoute(request, { host }) {
|
|
6282
6367
|
const cors = host.cors(request);
|
|
@@ -6298,7 +6383,7 @@ async function joinWaitlistRoute(request, { host }) {
|
|
|
6298
6383
|
organizationId = type?.organizationId ?? null;
|
|
6299
6384
|
}
|
|
6300
6385
|
if (!organizationId) return corsJson(cors, { error: "Appointment type not found" }, { status: 404 });
|
|
6301
|
-
const { entry, token } = await (0,
|
|
6386
|
+
const { entry, token } = await (0, import_scheduling54.joinWaitlist)(context.db, {
|
|
6302
6387
|
organizationId,
|
|
6303
6388
|
typeId: body.typeId,
|
|
6304
6389
|
calendarId: body.calendarId,
|
|
@@ -6324,7 +6409,7 @@ async function leaveWaitlistRoute(request, { host }) {
|
|
|
6324
6409
|
if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6325
6410
|
const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
|
|
6326
6411
|
if (!context) return corsJson(cors, { error: "No waitlist entry for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6327
|
-
const freed = await (0,
|
|
6412
|
+
const freed = await (0, import_scheduling54.leaveWaitlist)(context.db, token);
|
|
6328
6413
|
if (freed) await offerAndAnnounce(host, host.waitlist, context.db, freed);
|
|
6329
6414
|
return corsJson(cors, { success: true });
|
|
6330
6415
|
} catch (error) {
|
|
@@ -6333,40 +6418,40 @@ async function leaveWaitlistRoute(request, { host }) {
|
|
|
6333
6418
|
}
|
|
6334
6419
|
|
|
6335
6420
|
// src/handlers/waitlist-offer.ts
|
|
6336
|
-
var
|
|
6337
|
-
var
|
|
6421
|
+
var import_scheduling59 = require("@ordinatio/scheduling");
|
|
6422
|
+
var import_zod20 = require("zod");
|
|
6338
6423
|
|
|
6339
6424
|
// src/handlers/appointments-book.ts
|
|
6340
|
-
var
|
|
6425
|
+
var import_scheduling58 = require("@ordinatio/scheduling");
|
|
6341
6426
|
|
|
6342
6427
|
// 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:
|
|
6428
|
+
var import_zod19 = require("zod");
|
|
6429
|
+
var BookingSchema = import_zod19.z.object({
|
|
6430
|
+
calendarId: import_zod19.z.string().min(1).optional(),
|
|
6431
|
+
preferredCalendarId: import_zod19.z.string().min(1).optional(),
|
|
6432
|
+
typeId: import_zod19.z.string().min(1),
|
|
6433
|
+
startTime: import_zod19.z.string().datetime({ message: "Invalid date/time format" }),
|
|
6434
|
+
timezone: import_zod19.z.string().max(50).optional(),
|
|
6435
|
+
clientName: import_zod19.z.string().trim().min(1, "Name is required").max(200),
|
|
6436
|
+
clientEmail: import_zod19.z.string().email("Invalid email").max(254),
|
|
6437
|
+
clientPhone: import_zod19.z.string().max(30).optional(),
|
|
6353
6438
|
// Untrusted: the host's client resolver decides whether to honor it.
|
|
6354
|
-
clientId:
|
|
6355
|
-
notes:
|
|
6439
|
+
clientId: import_zod19.z.string().optional(),
|
|
6440
|
+
notes: import_zod19.z.string().max(1e3).optional(),
|
|
6356
6441
|
// Only the primitive types a form field produces; z.unknown() would accept anything.
|
|
6357
|
-
intakeResponses:
|
|
6358
|
-
|
|
6359
|
-
|
|
6442
|
+
intakeResponses: import_zod19.z.record(
|
|
6443
|
+
import_zod19.z.string(),
|
|
6444
|
+
import_zod19.z.union([import_zod19.z.string().max(1e3), import_zod19.z.number(), import_zod19.z.boolean(), import_zod19.z.null()])
|
|
6360
6445
|
).optional(),
|
|
6361
|
-
paymentId:
|
|
6362
|
-
couponCode:
|
|
6363
|
-
packagePurchaseId:
|
|
6446
|
+
paymentId: import_zod19.z.string().optional(),
|
|
6447
|
+
couponCode: import_zod19.z.string().min(1).max(50).transform((value) => value.trim().toUpperCase()).optional(),
|
|
6448
|
+
packagePurchaseId: import_zod19.z.string().optional(),
|
|
6364
6449
|
// Names the organization, so the calendar and type lookups can run against its own database.
|
|
6365
|
-
orgSlug:
|
|
6450
|
+
orgSlug: import_zod19.z.string().min(1).max(100).optional()
|
|
6366
6451
|
});
|
|
6367
6452
|
|
|
6368
6453
|
// src/booking/finalize-booking.ts
|
|
6369
|
-
var
|
|
6454
|
+
var import_scheduling55 = require("@ordinatio/scheduling");
|
|
6370
6455
|
async function finalizeBooking(host, cors, db, organizationId, body, appointment, appointmentType, discountCents, appliedCouponCode, noShowApprovalOverride, clientId) {
|
|
6371
6456
|
const logActivity = (action, description, metadata) => host.activity.log(db, { action, description, metadata });
|
|
6372
6457
|
if (noShowApprovalOverride && appointment.status === "CONFIRMED") {
|
|
@@ -6409,7 +6494,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6409
6494
|
AND ("expiresAt" IS NULL OR "expiresAt" > NOW())
|
|
6410
6495
|
`;
|
|
6411
6496
|
if (counted === 0) {
|
|
6412
|
-
await (0,
|
|
6497
|
+
await (0, import_scheduling55.cancelAppointment)(db, {
|
|
6413
6498
|
appointmentId: appointment.id,
|
|
6414
6499
|
cancelledBy: "system",
|
|
6415
6500
|
reason: "Coupon exhausted by concurrent booking during payment"
|
|
@@ -6428,7 +6513,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6428
6513
|
}
|
|
6429
6514
|
let meetingUrl = null;
|
|
6430
6515
|
if (appointmentType.locationType === "VIRTUAL") {
|
|
6431
|
-
meetingUrl = (0,
|
|
6516
|
+
meetingUrl = (0, import_scheduling55.buildJitsiUrl)(appointment.id);
|
|
6432
6517
|
try {
|
|
6433
6518
|
await db.appointment.update({ where: { id: appointment.id }, data: { meetingUrl } });
|
|
6434
6519
|
} catch (meetingError) {
|
|
@@ -6453,7 +6538,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6453
6538
|
const baseUrl = host.appUrl();
|
|
6454
6539
|
if (!baseUrl) throw new Error("The host must supply appUrl() to book appointments");
|
|
6455
6540
|
try {
|
|
6456
|
-
await (0,
|
|
6541
|
+
await (0, import_scheduling55.scheduleNotifications)(db, appointment.id, baseUrl, { brand: Boolean(host.brand) });
|
|
6457
6542
|
} catch (error) {
|
|
6458
6543
|
await logActivity(
|
|
6459
6544
|
"scheduling.notification_schedule_failed",
|
|
@@ -6462,7 +6547,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6462
6547
|
);
|
|
6463
6548
|
}
|
|
6464
6549
|
try {
|
|
6465
|
-
await (0,
|
|
6550
|
+
await (0, import_scheduling55.queueStaffNotification)(db, appointment.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) });
|
|
6466
6551
|
} catch (error) {
|
|
6467
6552
|
await logActivity(
|
|
6468
6553
|
"scheduling.staff_notification_failed",
|
|
@@ -6516,7 +6601,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
|
|
|
6516
6601
|
}
|
|
6517
6602
|
|
|
6518
6603
|
// src/booking/refund-blocked-booking.ts
|
|
6519
|
-
var
|
|
6604
|
+
var import_scheduling56 = require("@ordinatio/scheduling");
|
|
6520
6605
|
var REFUND_ON_CODES = ["SCHED_301", "SCHED_307", "SCHED_802", "SCHED_800", "SCHED_801", "SCHED_201", "SCHED_100", "SCHED_200", "SCHED_102"];
|
|
6521
6606
|
function isBlockedBookingCode(code) {
|
|
6522
6607
|
return code !== void 0 && REFUND_ON_CODES.includes(code);
|
|
@@ -6531,12 +6616,12 @@ async function respondToBlockedPaidBooking(db, payments, cors, paymentId, blocke
|
|
|
6531
6616
|
try {
|
|
6532
6617
|
existingBooking = await db.appointment.findFirst({ where: { paymentId }, select: { id: true } });
|
|
6533
6618
|
} catch (lookupError) {
|
|
6534
|
-
const err = (0,
|
|
6619
|
+
const err = (0, import_scheduling56.schedError)("SCHED_409", { paymentId, blockerCode, error: lookupError });
|
|
6535
6620
|
console.error("[booking] Could not check for an existing booking before refunding:", err.ref, lookupError);
|
|
6536
6621
|
return corsJson(cors, { error: "We could not confirm your booking just now. Please try again.", ref: err.ref }, { status: 503 });
|
|
6537
6622
|
}
|
|
6538
6623
|
if (existingBooking) {
|
|
6539
|
-
const err = (0,
|
|
6624
|
+
const err = (0, import_scheduling56.schedError)("SCHED_404", { paymentId, existingAppointmentId: existingBooking.id });
|
|
6540
6625
|
return corsJson(
|
|
6541
6626
|
cors,
|
|
6542
6627
|
{ error: "This payment has already been used for a booking", ref: err.ref, code: "PAYMENT_ALREADY_USED" },
|
|
@@ -6667,7 +6752,7 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6667
6752
|
}
|
|
6668
6753
|
|
|
6669
6754
|
// src/booking/verify-booking-payment.ts
|
|
6670
|
-
var
|
|
6755
|
+
var import_scheduling57 = require("@ordinatio/scheduling");
|
|
6671
6756
|
async function verifyBookingPayment(db, payments, cors, organizationId, appointmentType, body) {
|
|
6672
6757
|
const refuse = (status, payload) => ({
|
|
6673
6758
|
ok: false,
|
|
@@ -6684,7 +6769,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6684
6769
|
select: { id: true }
|
|
6685
6770
|
});
|
|
6686
6771
|
if (existingBooking) {
|
|
6687
|
-
const err = (0,
|
|
6772
|
+
const err = (0, import_scheduling57.schedError)("SCHED_404", { paymentId: body.paymentId, existingAppointmentId: existingBooking.id });
|
|
6688
6773
|
return refuse(409, {
|
|
6689
6774
|
error: "This payment has already been used for a booking",
|
|
6690
6775
|
ref: err.ref,
|
|
@@ -6694,7 +6779,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6694
6779
|
const metaTypeId = payment.metadata?.typeId;
|
|
6695
6780
|
const metaClientEmail = payment.metadata?.clientEmail;
|
|
6696
6781
|
if (metaTypeId !== body.typeId || metaClientEmail && metaClientEmail.toLowerCase() !== body.clientEmail.toLowerCase()) {
|
|
6697
|
-
const err = (0,
|
|
6782
|
+
const err = (0, import_scheduling57.schedError)("SCHED_405", {
|
|
6698
6783
|
paymentId: body.paymentId,
|
|
6699
6784
|
metaTypeId,
|
|
6700
6785
|
bodyTypeId: body.typeId,
|
|
@@ -6724,7 +6809,7 @@ async function verifyBookingPayment(db, payments, cors, organizationId, appointm
|
|
|
6724
6809
|
}
|
|
6725
6810
|
}
|
|
6726
6811
|
if (payment.amount === void 0) {
|
|
6727
|
-
const err = (0,
|
|
6812
|
+
const err = (0, import_scheduling57.schedError)("SCHED_405", { paymentId: body.paymentId, currency: payment.currency });
|
|
6728
6813
|
return refuse(400, { error: "Payment currency is not supported", ref: err.ref });
|
|
6729
6814
|
}
|
|
6730
6815
|
if (Math.round(payment.amount * 100) !== expectedCents) {
|
|
@@ -6765,7 +6850,7 @@ async function bookAppointmentRoute(request, { host }) {
|
|
|
6765
6850
|
} catch (linkError) {
|
|
6766
6851
|
console.error("[booking] client link lookup failed \u2014 saving the appointment unlinked:", linkError instanceof Error ? linkError.message : linkError);
|
|
6767
6852
|
}
|
|
6768
|
-
const appointment = await (0,
|
|
6853
|
+
const appointment = await (0, import_scheduling58.bookAppointment)(db, {
|
|
6769
6854
|
calendarId: body.calendarId,
|
|
6770
6855
|
preferredCalendarId: body.preferredCalendarId,
|
|
6771
6856
|
typeId: body.typeId,
|
|
@@ -6839,7 +6924,7 @@ async function getWaitlistOfferRoute(request, { host }) {
|
|
|
6839
6924
|
if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6840
6925
|
const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
|
|
6841
6926
|
if (!context) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6842
|
-
const offer = await (0,
|
|
6927
|
+
const offer = await (0, import_scheduling59.getWaitlistOffer)(context.db, token);
|
|
6843
6928
|
return corsJson(cors, {
|
|
6844
6929
|
typeName: offer.typeName,
|
|
6845
6930
|
calendarName: offer.calendarName,
|
|
@@ -6852,7 +6937,7 @@ async function getWaitlistOfferRoute(request, { host }) {
|
|
|
6852
6937
|
return waitlistErrorResponse(cors, error, "Failed to read the offer");
|
|
6853
6938
|
}
|
|
6854
6939
|
}
|
|
6855
|
-
var AcceptSchema =
|
|
6940
|
+
var AcceptSchema = import_zod20.z.object({ token: import_zod20.z.string().min(1).max(200), orgSlug: import_zod20.z.string().min(1).max(100).optional() });
|
|
6856
6941
|
async function acceptWaitlistOfferRoute(request, context) {
|
|
6857
6942
|
const { host } = context;
|
|
6858
6943
|
const cors = host.cors(request);
|
|
@@ -6868,7 +6953,7 @@ async function acceptWaitlistOfferRoute(request, context) {
|
|
|
6868
6953
|
if (!parsed.success) return corsJson(cors, { error: "token is required" }, { status: 400 });
|
|
6869
6954
|
db = await resolveWaitlistDb(host, parsed.data.orgSlug);
|
|
6870
6955
|
if (!db) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
|
|
6871
|
-
const offer = await (0,
|
|
6956
|
+
const offer = await (0, import_scheduling59.beginWaitlistAccept)(db.db, parsed.data.token);
|
|
6872
6957
|
entryId = offer.entryId;
|
|
6873
6958
|
const headers = new Headers(request.headers);
|
|
6874
6959
|
headers.set("content-type", "application/json");
|
|
@@ -6893,20 +6978,20 @@ async function acceptWaitlistOfferRoute(request, context) {
|
|
|
6893
6978
|
booked = true;
|
|
6894
6979
|
const appointment = await response.clone().json().catch(() => null);
|
|
6895
6980
|
try {
|
|
6896
|
-
await (0,
|
|
6981
|
+
await (0, import_scheduling59.completeWaitlistAccept)(db.db, entryId, appointment?.id ?? "");
|
|
6897
6982
|
} catch (completeError) {
|
|
6898
6983
|
console.error("[waitlist] the booking was saved but its waitlist entry could not be marked booked:", completeError);
|
|
6899
6984
|
}
|
|
6900
6985
|
return response;
|
|
6901
6986
|
}
|
|
6902
|
-
const saved = await (0,
|
|
6987
|
+
const saved = await (0, import_scheduling59.settleBookedAccept)(db.db, entryId);
|
|
6903
6988
|
if (saved) return corsJson(cors, saved, { status: 201 });
|
|
6904
6989
|
await endFailedAccept(host, settings, db.db, entryId, releaseFor(response.status));
|
|
6905
6990
|
return response;
|
|
6906
6991
|
} catch (error) {
|
|
6907
6992
|
if (entryId && db && !booked) {
|
|
6908
6993
|
try {
|
|
6909
|
-
const saved = await (0,
|
|
6994
|
+
const saved = await (0, import_scheduling59.settleBookedAccept)(db.db, entryId);
|
|
6910
6995
|
if (saved) return corsJson(cors, saved, { status: 201 });
|
|
6911
6996
|
await endFailedAccept(host, settings, db.db, entryId, "KEEP_OFFER");
|
|
6912
6997
|
} catch (releaseError) {
|
|
@@ -6922,12 +7007,12 @@ function releaseFor(status) {
|
|
|
6922
7007
|
return "DROP";
|
|
6923
7008
|
}
|
|
6924
7009
|
async function endFailedAccept(host, settings, db, entryId, outcome) {
|
|
6925
|
-
const freed = await (0,
|
|
7010
|
+
const freed = await (0, import_scheduling59.releaseWaitlistAccept)(db, entryId, outcome);
|
|
6926
7011
|
if (freed) await offerAndAnnounce(host, settings, db, freed);
|
|
6927
7012
|
}
|
|
6928
7013
|
|
|
6929
7014
|
// src/handlers/admin-waitlist.ts
|
|
6930
|
-
var
|
|
7015
|
+
var import_scheduling60 = require("@ordinatio/scheduling");
|
|
6931
7016
|
var STATUSES2 = /* @__PURE__ */ new Set(["WAITING", "OFFERED", "ACCEPTING", "BOOKED", "EXPIRED"]);
|
|
6932
7017
|
async function listWaitlistEntries(request, { host }) {
|
|
6933
7018
|
try {
|
|
@@ -6938,7 +7023,7 @@ async function listWaitlistEntries(request, { host }) {
|
|
|
6938
7023
|
return Response.json({ error: `status must be one of ${[...STATUSES2].join(", ")}` }, { status: 400 });
|
|
6939
7024
|
}
|
|
6940
7025
|
const { limit, offset } = parsePagination(request);
|
|
6941
|
-
const { entries, total } = await (0,
|
|
7026
|
+
const { entries, total } = await (0, import_scheduling60.listWaitlist)(guard.staff.db, {
|
|
6942
7027
|
organizationId: guard.staff.organizationId,
|
|
6943
7028
|
status: status ?? void 0,
|
|
6944
7029
|
limit,
|
|
@@ -6954,7 +7039,7 @@ async function removeWaitlistEntryRoute(request, { host, params }) {
|
|
|
6954
7039
|
const guard = await requireWaitlistAdmin(host, request, { action: "admin-waitlist-remove", tier: "DELETE" });
|
|
6955
7040
|
if (guard instanceof Response) return guard;
|
|
6956
7041
|
const { db, organizationId } = guard.staff;
|
|
6957
|
-
const freed = await (0,
|
|
7042
|
+
const freed = await (0, import_scheduling60.removeWaitlistEntry)(db, organizationId, params.id);
|
|
6958
7043
|
await host.activity.log(db, {
|
|
6959
7044
|
action: "scheduling.waitlist_entry_removed",
|
|
6960
7045
|
description: "removed someone from the waitlist",
|
|
@@ -6968,7 +7053,7 @@ async function removeWaitlistEntryRoute(request, { host, params }) {
|
|
|
6968
7053
|
}
|
|
6969
7054
|
|
|
6970
7055
|
// src/handlers/internal-waitlist-sweep.ts
|
|
6971
|
-
var
|
|
7056
|
+
var import_scheduling61 = require("@ordinatio/scheduling");
|
|
6972
7057
|
async function sweepWaitlist(request, { host }) {
|
|
6973
7058
|
if (!await host.internalAccess.isAuthorized(request)) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
6974
7059
|
if (!host.waitlist) return Response.json(NOT_ENABLED2, { status: 501 });
|
|
@@ -6976,7 +7061,7 @@ async function sweepWaitlist(request, { host }) {
|
|
|
6976
7061
|
if (limited) return limited;
|
|
6977
7062
|
try {
|
|
6978
7063
|
const db = await host.publicDb();
|
|
6979
|
-
const { lapsed, released, booked } = await (0,
|
|
7064
|
+
const { lapsed, released, booked } = await (0, import_scheduling61.expireWaitlistOffers)(db);
|
|
6980
7065
|
let reoffered = 0;
|
|
6981
7066
|
for (const slot of lapsed) {
|
|
6982
7067
|
if (await offerAndAnnounce(host, host.waitlist, db, slot)) reoffered++;
|
|
@@ -6989,15 +7074,15 @@ async function sweepWaitlist(request, { host }) {
|
|
|
6989
7074
|
}
|
|
6990
7075
|
|
|
6991
7076
|
// src/handlers/routing-forms-public.ts
|
|
6992
|
-
var
|
|
7077
|
+
var import_scheduling63 = require("@ordinatio/scheduling");
|
|
6993
7078
|
|
|
6994
7079
|
// src/routing/routing-http.ts
|
|
6995
|
-
var
|
|
7080
|
+
var import_scheduling62 = require("@ordinatio/scheduling");
|
|
6996
7081
|
var NOT_ENABLED3 = { error: "Routing forms are not enabled on this server" };
|
|
6997
7082
|
var STATUS_BY_CODE2 = { SCHED_1201: 404, SCHED_1202: 409, SCHED_1204: 409 };
|
|
6998
7083
|
function routingErrorResponse(error, fallback, cors) {
|
|
6999
7084
|
const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
|
|
7000
|
-
if (error instanceof
|
|
7085
|
+
if (error instanceof import_scheduling62.SchedulingValidationError || error instanceof import_scheduling62.SchedulingNotFoundError) {
|
|
7001
7086
|
const details = error.context.errors;
|
|
7002
7087
|
const status = STATUS_BY_CODE2[error.code] ?? 400;
|
|
7003
7088
|
return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, status);
|
|
@@ -7028,7 +7113,7 @@ async function getRoutingFormRoute(request, { host }) {
|
|
|
7028
7113
|
if (!slug) return corsJson(cors, { error: "slug is required" }, { status: 400 });
|
|
7029
7114
|
const context = await resolveOrganization(host, url.searchParams.get("orgSlug"));
|
|
7030
7115
|
if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
|
|
7031
|
-
return corsJson(cors, await (0,
|
|
7116
|
+
return corsJson(cors, await (0, import_scheduling63.getPublicRoutingForm)(context.db, { organizationId: context.organizationId, slug }));
|
|
7032
7117
|
} catch (error) {
|
|
7033
7118
|
return routingErrorResponse(error, "Failed to read the form", cors);
|
|
7034
7119
|
}
|
|
@@ -7046,7 +7131,7 @@ async function routeClientRoute(request, { host }) {
|
|
|
7046
7131
|
}
|
|
7047
7132
|
const context = await resolveOrganization(host, parsed.data.orgSlug);
|
|
7048
7133
|
if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
|
|
7049
|
-
const outcome = await (0,
|
|
7134
|
+
const outcome = await (0, import_scheduling63.routeClient)(context.db, { organizationId: context.organizationId, slug: parsed.data.slug, answers: parsed.data.answers });
|
|
7050
7135
|
return corsJson(cors, outcome);
|
|
7051
7136
|
} catch (error) {
|
|
7052
7137
|
return routingErrorResponse(error, "Failed to route the answers", cors);
|
|
@@ -7054,12 +7139,12 @@ async function routeClientRoute(request, { host }) {
|
|
|
7054
7139
|
}
|
|
7055
7140
|
|
|
7056
7141
|
// src/handlers/admin-routing-forms.ts
|
|
7057
|
-
var
|
|
7142
|
+
var import_scheduling64 = require("@ordinatio/scheduling");
|
|
7058
7143
|
async function listRoutingFormsRoute(request, { host }) {
|
|
7059
7144
|
try {
|
|
7060
7145
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-list", tier: "GENERAL" });
|
|
7061
7146
|
if (staff instanceof Response) return staff;
|
|
7062
|
-
return Response.json({ forms: await (0,
|
|
7147
|
+
return Response.json({ forms: await (0, import_scheduling64.listRoutingForms)(staff.db, staff.organizationId) });
|
|
7063
7148
|
} catch (error) {
|
|
7064
7149
|
return routingErrorResponse(error, "Failed to list the forms");
|
|
7065
7150
|
}
|
|
@@ -7070,7 +7155,7 @@ async function createRoutingFormRoute(request, { host }) {
|
|
|
7070
7155
|
if (staff instanceof Response) return staff;
|
|
7071
7156
|
const validation = await parseBody(request, CreateRoutingFormSchema);
|
|
7072
7157
|
if (!validation.success) return validation.response;
|
|
7073
|
-
const form = await (0,
|
|
7158
|
+
const form = await (0, import_scheduling64.createRoutingForm)(staff.db, staff.organizationId, validation.data);
|
|
7074
7159
|
await host.activity.log(staff.db, {
|
|
7075
7160
|
action: "scheduling.routing_form_created",
|
|
7076
7161
|
description: `created routing form "${form.name}"`,
|
|
@@ -7083,7 +7168,7 @@ async function createRoutingFormRoute(request, { host }) {
|
|
|
7083
7168
|
}
|
|
7084
7169
|
|
|
7085
7170
|
// src/handlers/brand-public.ts
|
|
7086
|
-
var
|
|
7171
|
+
var import_scheduling65 = require("@ordinatio/scheduling");
|
|
7087
7172
|
async function getBrandRoute(request, { host }) {
|
|
7088
7173
|
const cors = host.cors(request);
|
|
7089
7174
|
if (!host.brand) return corsJson(cors, NOT_ENABLED, { status: 501 });
|
|
@@ -7092,7 +7177,7 @@ async function getBrandRoute(request, { host }) {
|
|
|
7092
7177
|
if (limited) return limited;
|
|
7093
7178
|
const orgSlug = new URL(request.url).searchParams.get("orgSlug");
|
|
7094
7179
|
const context = orgSlug ? await host.organizations.resolve({ orgSlug, logPrefix: "[brand]" }) : { db: await host.publicDb(), organizationId: null };
|
|
7095
|
-
const brand = context ? await (0,
|
|
7180
|
+
const brand = context ? await (0, import_scheduling65.getPublicBrand)(context.db, context.organizationId) : null;
|
|
7096
7181
|
if (!brand) return corsJson(cors, { error: "No brand set" }, { status: 404 });
|
|
7097
7182
|
return corsJson(cors, { brand }, { headers: WIDGET_CACHE_HEADERS });
|
|
7098
7183
|
} catch (error) {
|
|
@@ -7101,12 +7186,12 @@ async function getBrandRoute(request, { host }) {
|
|
|
7101
7186
|
}
|
|
7102
7187
|
|
|
7103
7188
|
// src/handlers/admin-brand.ts
|
|
7104
|
-
var
|
|
7189
|
+
var import_scheduling66 = require("@ordinatio/scheduling");
|
|
7105
7190
|
async function getBrandAdminRoute(request, { host }) {
|
|
7106
7191
|
try {
|
|
7107
7192
|
const staff = await requireBrandAdmin(host, request, { action: "admin-brand-get", tier: "GENERAL" });
|
|
7108
7193
|
if (staff instanceof Response) return staff;
|
|
7109
|
-
return Response.json({ brand: await (0,
|
|
7194
|
+
return Response.json({ brand: await (0, import_scheduling66.getBrand)(staff.db, staff.organizationId) });
|
|
7110
7195
|
} catch (error) {
|
|
7111
7196
|
return brandErrorResponse(error, "Failed to read the brand");
|
|
7112
7197
|
}
|
|
@@ -7118,7 +7203,7 @@ async function saveBrandRoute(request, { host }) {
|
|
|
7118
7203
|
const validation = await parseBody(request, BrandSchema);
|
|
7119
7204
|
if (!validation.success) return validation.response;
|
|
7120
7205
|
const verifier = host.brand?.isSendingDomainVerified;
|
|
7121
|
-
const brand = await (0,
|
|
7206
|
+
const brand = await (0, import_scheduling66.saveBrand)(staff.db, staff.organizationId, validation.data, {
|
|
7122
7207
|
isSendingDomainVerified: verifier ? async (domain) => Boolean(await verifier.call(host.brand, domain, staff.organizationId)) : void 0
|
|
7123
7208
|
});
|
|
7124
7209
|
await host.activity.log(staff.db, {
|
|
@@ -7135,7 +7220,7 @@ async function deleteBrandRoute(request, { host }) {
|
|
|
7135
7220
|
try {
|
|
7136
7221
|
const staff = await requireBrandAdmin(host, request, { action: "admin-brand-delete", tier: "DELETE" });
|
|
7137
7222
|
if (staff instanceof Response) return staff;
|
|
7138
|
-
const removed = await (0,
|
|
7223
|
+
const removed = await (0, import_scheduling66.deleteBrand)(staff.db, staff.organizationId);
|
|
7139
7224
|
if (removed) await host.activity.log(staff.db, { action: "scheduling.brand_removed", description: "removed the brand", metadata: {} });
|
|
7140
7225
|
return Response.json({ removed });
|
|
7141
7226
|
} catch (error) {
|
|
@@ -7143,11 +7228,65 @@ async function deleteBrandRoute(request, { host }) {
|
|
|
7143
7228
|
}
|
|
7144
7229
|
}
|
|
7145
7230
|
|
|
7146
|
-
// src/handlers/admin-
|
|
7147
|
-
var
|
|
7148
|
-
var NOT_ENABLED4 = { error: "
|
|
7231
|
+
// src/handlers/admin-api-keys.ts
|
|
7232
|
+
var import_scheduling67 = require("@ordinatio/scheduling");
|
|
7233
|
+
var NOT_ENABLED4 = { error: "API keys are not enabled on this server" };
|
|
7149
7234
|
function failure3(error, fallback) {
|
|
7150
|
-
if (error instanceof
|
|
7235
|
+
if (error instanceof import_scheduling67.SchedulingValidationError) {
|
|
7236
|
+
const details = error.context.errors;
|
|
7237
|
+
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
|
|
7238
|
+
}
|
|
7239
|
+
console.error("[api-keys]", error);
|
|
7240
|
+
return Response.json({ error: fallback }, { status: 500 });
|
|
7241
|
+
}
|
|
7242
|
+
async function requireKeyAdmin(host, request, options) {
|
|
7243
|
+
const staff = await requireAdminStaff(host, request, options);
|
|
7244
|
+
if (staff instanceof Response) return staff;
|
|
7245
|
+
if (!host.apiKeys) return Response.json(NOT_ENABLED4, { status: 501 });
|
|
7246
|
+
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 });
|
|
7247
|
+
return staff;
|
|
7248
|
+
}
|
|
7249
|
+
async function listApiKeysRoute(request, { host }) {
|
|
7250
|
+
try {
|
|
7251
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-list", tier: "GENERAL" });
|
|
7252
|
+
if (staff instanceof Response) return staff;
|
|
7253
|
+
return Response.json({ keys: await (0, import_scheduling67.listApiKeys)(staff.db, staff.organizationId) });
|
|
7254
|
+
} catch (error) {
|
|
7255
|
+
return failure3(error, "Failed to list the API keys");
|
|
7256
|
+
}
|
|
7257
|
+
}
|
|
7258
|
+
async function createApiKeyRoute(request, { host }) {
|
|
7259
|
+
try {
|
|
7260
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-create", tier: "SETTINGS" });
|
|
7261
|
+
if (staff instanceof Response) return staff;
|
|
7262
|
+
const validation = await parseBody(request, ApiKeySchema);
|
|
7263
|
+
if (!validation.success) return validation.response;
|
|
7264
|
+
const { key, view } = await (0, import_scheduling67.createApiKey)(staff.db, staff.organizationId, validation.data, staff.userId);
|
|
7265
|
+
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) => {
|
|
7266
|
+
console.error("[api-keys] could not record the new key in the activity log", error);
|
|
7267
|
+
});
|
|
7268
|
+
return Response.json({ key, apiKey: view }, { status: 201, headers: { "Cache-Control": "no-store" } });
|
|
7269
|
+
} catch (error) {
|
|
7270
|
+
return failure3(error, "Failed to make the API key");
|
|
7271
|
+
}
|
|
7272
|
+
}
|
|
7273
|
+
async function revokeApiKeyRoute(request, { host, params }) {
|
|
7274
|
+
try {
|
|
7275
|
+
const staff = await requireKeyAdmin(host, request, { action: "admin-api-keys-revoke", tier: "DELETE" });
|
|
7276
|
+
if (staff instanceof Response) return staff;
|
|
7277
|
+
const revoked = await (0, import_scheduling67.revokeApiKey)(staff.db, staff.organizationId, params.id);
|
|
7278
|
+
if (revoked) await host.activity.log(staff.db, { action: "scheduling.api_key_revoked", description: "revoked an API key", metadata: { keyId: params.id } });
|
|
7279
|
+
return Response.json({ revoked });
|
|
7280
|
+
} catch (error) {
|
|
7281
|
+
return failure3(error, "Failed to revoke the API key");
|
|
7282
|
+
}
|
|
7283
|
+
}
|
|
7284
|
+
|
|
7285
|
+
// src/handlers/admin-text-settings.ts
|
|
7286
|
+
var import_scheduling68 = require("@ordinatio/scheduling");
|
|
7287
|
+
var NOT_ENABLED5 = { error: "Text-message settings are not enabled on this server" };
|
|
7288
|
+
function failure4(error, fallback) {
|
|
7289
|
+
if (error instanceof import_scheduling68.SchedulingValidationError) {
|
|
7151
7290
|
const details = error.context.errors;
|
|
7152
7291
|
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
|
|
7153
7292
|
}
|
|
@@ -7157,16 +7296,16 @@ function failure3(error, fallback) {
|
|
|
7157
7296
|
async function requireTextAdmin(host, request, options) {
|
|
7158
7297
|
const staff = await requireAdminStaff(host, request, options);
|
|
7159
7298
|
if (staff instanceof Response) return staff;
|
|
7160
|
-
if (!host.textMessages) return Response.json(
|
|
7299
|
+
if (!host.textMessages) return Response.json(NOT_ENABLED5, { status: 501 });
|
|
7161
7300
|
return staff;
|
|
7162
7301
|
}
|
|
7163
7302
|
async function getTextSettingsRoute(request, { host }) {
|
|
7164
7303
|
try {
|
|
7165
7304
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-get", tier: "GENERAL" });
|
|
7166
7305
|
if (staff instanceof Response) return staff;
|
|
7167
|
-
return Response.json({ settings: await (0,
|
|
7306
|
+
return Response.json({ settings: await (0, import_scheduling68.getTextSettings)(staff.db, staff.organizationId), providers: host.textMessages?.providers ?? ["TELNYX", "TWILIO"] });
|
|
7168
7307
|
} catch (error) {
|
|
7169
|
-
return
|
|
7308
|
+
return failure4(error, "Failed to read the text-message settings");
|
|
7170
7309
|
}
|
|
7171
7310
|
}
|
|
7172
7311
|
async function saveTextSettingsRoute(request, { host }) {
|
|
@@ -7175,7 +7314,7 @@ async function saveTextSettingsRoute(request, { host }) {
|
|
|
7175
7314
|
if (staff instanceof Response) return staff;
|
|
7176
7315
|
const validation = await parseBody(request, TextSettingsSchema);
|
|
7177
7316
|
if (!validation.success) return validation.response;
|
|
7178
|
-
const settings = await (0,
|
|
7317
|
+
const settings = await (0, import_scheduling68.saveTextSettings)(staff.db, staff.organizationId, validation.data, { providers: host.textMessages?.providers });
|
|
7179
7318
|
await host.activity.log(staff.db, {
|
|
7180
7319
|
action: "scheduling.text_settings_saved",
|
|
7181
7320
|
description: "changed the text-message settings",
|
|
@@ -7183,18 +7322,18 @@ async function saveTextSettingsRoute(request, { host }) {
|
|
|
7183
7322
|
});
|
|
7184
7323
|
return Response.json({ settings });
|
|
7185
7324
|
} catch (error) {
|
|
7186
|
-
return
|
|
7325
|
+
return failure4(error, "Failed to save the text-message settings");
|
|
7187
7326
|
}
|
|
7188
7327
|
}
|
|
7189
7328
|
async function deleteTextSettingsRoute(request, { host }) {
|
|
7190
7329
|
try {
|
|
7191
7330
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-delete", tier: "DELETE" });
|
|
7192
7331
|
if (staff instanceof Response) return staff;
|
|
7193
|
-
const removed = await (0,
|
|
7332
|
+
const removed = await (0, import_scheduling68.deleteTextSettings)(staff.db, staff.organizationId);
|
|
7194
7333
|
if (removed) await host.activity.log(staff.db, { action: "scheduling.text_settings_removed", description: "removed the text-message settings", metadata: {} });
|
|
7195
7334
|
return Response.json({ removed });
|
|
7196
7335
|
} catch (error) {
|
|
7197
|
-
return
|
|
7336
|
+
return failure4(error, "Failed to remove the text-message settings");
|
|
7198
7337
|
}
|
|
7199
7338
|
}
|
|
7200
7339
|
|
|
@@ -7267,14 +7406,14 @@ async function checkSendingDomainRoute(request, { host }) {
|
|
|
7267
7406
|
}
|
|
7268
7407
|
|
|
7269
7408
|
// src/handlers/admin-privacy.ts
|
|
7270
|
-
var
|
|
7409
|
+
var import_scheduling70 = require("@ordinatio/scheduling");
|
|
7271
7410
|
|
|
7272
7411
|
// src/privacy/privacy-http.ts
|
|
7273
|
-
var
|
|
7274
|
-
var
|
|
7412
|
+
var import_scheduling69 = require("@ordinatio/scheduling");
|
|
7413
|
+
var NOT_ENABLED6 = { error: "Data export and erasure are not enabled on this server" };
|
|
7275
7414
|
var STATUS_BY_CODE3 = { SCHED_1300: 400, SCHED_1301: 409 };
|
|
7276
7415
|
function privacyErrorResponse(error, fallback) {
|
|
7277
|
-
if (error instanceof
|
|
7416
|
+
if (error instanceof import_scheduling69.SchedulingValidationError) {
|
|
7278
7417
|
return Response.json(
|
|
7279
7418
|
{ error: error.message, code: error.code, ref: getErrorRef(error), details: error.context },
|
|
7280
7419
|
{ status: STATUS_BY_CODE3[error.code] ?? 400 }
|
|
@@ -7286,7 +7425,7 @@ function privacyErrorResponse(error, fallback) {
|
|
|
7286
7425
|
async function requirePrivacyAdmin(host, request, options) {
|
|
7287
7426
|
const staff = await requireAdminStaff(host, request, options);
|
|
7288
7427
|
if (staff instanceof Response) return staff;
|
|
7289
|
-
if (!host.privacy) return Response.json(
|
|
7428
|
+
if (!host.privacy) return Response.json(NOT_ENABLED6, { status: 501 });
|
|
7290
7429
|
return staff;
|
|
7291
7430
|
}
|
|
7292
7431
|
|
|
@@ -7304,7 +7443,7 @@ async function exportPrivacyRoute(request, { host }) {
|
|
|
7304
7443
|
if (staff instanceof Response) return staff;
|
|
7305
7444
|
const validation = await parseBody(request, PrivacySubjectSchema);
|
|
7306
7445
|
if (!validation.success) return validation.response;
|
|
7307
|
-
const result = await (0,
|
|
7446
|
+
const result = await (0, import_scheduling70.exportSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...validation.data });
|
|
7308
7447
|
await logQuietly(host, staff.db, {
|
|
7309
7448
|
action: "scheduling.privacy_export",
|
|
7310
7449
|
description: "exported the data held about one person",
|
|
@@ -7331,10 +7470,10 @@ async function erasePrivacyRoute(request, { host }) {
|
|
|
7331
7470
|
if (!validation.success) return validation.response;
|
|
7332
7471
|
const { confirm, ...subject2 } = validation.data;
|
|
7333
7472
|
if (confirm !== true) {
|
|
7334
|
-
const preview = await (0,
|
|
7473
|
+
const preview = await (0, import_scheduling70.previewErase)(staff.db, { organizationId: staff.organizationId, ...subject2 });
|
|
7335
7474
|
return Response.json({ erased: false, preview }, { headers: { "cache-control": "no-store" } });
|
|
7336
7475
|
}
|
|
7337
|
-
const { counts } = await (0,
|
|
7476
|
+
const { counts } = await (0, import_scheduling70.eraseSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...subject2 });
|
|
7338
7477
|
await logQuietly(host, staff.db, {
|
|
7339
7478
|
action: "scheduling.privacy_erase",
|
|
7340
7479
|
description: "erased the data held about one person",
|
|
@@ -7350,7 +7489,7 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7350
7489
|
const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-requests", tier: "GENERAL" });
|
|
7351
7490
|
if (staff instanceof Response) return staff;
|
|
7352
7491
|
const { limit, offset } = parsePagination(request);
|
|
7353
|
-
const { requests, total } = await (0,
|
|
7492
|
+
const { requests, total } = await (0, import_scheduling70.listPrivacyRequests)(staff.db, { organizationId: staff.organizationId, limit, offset });
|
|
7354
7493
|
return Response.json({ requests, total, hasMore: offset + requests.length < total });
|
|
7355
7494
|
} catch (error) {
|
|
7356
7495
|
return privacyErrorResponse(error, "Failed to list the requests");
|
|
@@ -7358,12 +7497,12 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7358
7497
|
}
|
|
7359
7498
|
|
|
7360
7499
|
// src/handlers/admin-routing-form-detail.ts
|
|
7361
|
-
var
|
|
7500
|
+
var import_scheduling71 = require("@ordinatio/scheduling");
|
|
7362
7501
|
async function getRoutingFormAdminRoute(request, { host, params }) {
|
|
7363
7502
|
try {
|
|
7364
7503
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-get", tier: "GENERAL" });
|
|
7365
7504
|
if (staff instanceof Response) return staff;
|
|
7366
|
-
return Response.json({ form: await (0,
|
|
7505
|
+
return Response.json({ form: await (0, import_scheduling71.getRoutingForm)(staff.db, staff.organizationId, params.id) });
|
|
7367
7506
|
} catch (error) {
|
|
7368
7507
|
return routingErrorResponse(error, "Failed to read the form");
|
|
7369
7508
|
}
|
|
@@ -7374,7 +7513,7 @@ async function updateRoutingFormRoute(request, { host, params }) {
|
|
|
7374
7513
|
if (staff instanceof Response) return staff;
|
|
7375
7514
|
const validation = await parseBody(request, UpdateRoutingFormSchema);
|
|
7376
7515
|
if (!validation.success) return validation.response;
|
|
7377
|
-
const form = await (0,
|
|
7516
|
+
const form = await (0, import_scheduling71.updateRoutingForm)(staff.db, staff.organizationId, params.id, validation.data);
|
|
7378
7517
|
await host.activity.log(staff.db, {
|
|
7379
7518
|
action: "scheduling.routing_form_updated",
|
|
7380
7519
|
description: `changed routing form "${form.name}"`,
|
|
@@ -7389,7 +7528,7 @@ async function deleteRoutingFormRoute(request, { host, params }) {
|
|
|
7389
7528
|
try {
|
|
7390
7529
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-delete", tier: "DELETE" });
|
|
7391
7530
|
if (staff instanceof Response) return staff;
|
|
7392
|
-
await (0,
|
|
7531
|
+
await (0, import_scheduling71.deleteRoutingForm)(staff.db, staff.organizationId, params.id);
|
|
7393
7532
|
await host.activity.log(staff.db, { action: "scheduling.routing_form_deleted", description: "removed a routing form", metadata: { formId: params.id } });
|
|
7394
7533
|
return Response.json({ success: true });
|
|
7395
7534
|
} catch (error) {
|
|
@@ -7402,14 +7541,14 @@ async function testRoutingFormRoute(request, { host, params }) {
|
|
|
7402
7541
|
if (staff instanceof Response) return staff;
|
|
7403
7542
|
const validation = await parseBody(request, TestRoutingFormSchema);
|
|
7404
7543
|
if (!validation.success) return validation.response;
|
|
7405
|
-
return Response.json(await (0,
|
|
7544
|
+
return Response.json(await (0, import_scheduling71.testRoutingForm)(staff.db, { organizationId: staff.organizationId, id: params.id, answers: validation.data.answers }));
|
|
7406
7545
|
} catch (error) {
|
|
7407
7546
|
return routingErrorResponse(error, "Failed to test the form");
|
|
7408
7547
|
}
|
|
7409
7548
|
}
|
|
7410
7549
|
|
|
7411
7550
|
// src/handlers/appointments-list.ts
|
|
7412
|
-
var
|
|
7551
|
+
var import_scheduling72 = require("@ordinatio/scheduling");
|
|
7413
7552
|
var DEFAULT_LIMIT2 = 50;
|
|
7414
7553
|
var MAX_LIMIT2 = 500;
|
|
7415
7554
|
async function listAppointments(request, { host }) {
|
|
@@ -7421,7 +7560,7 @@ async function listAppointments(request, { host }) {
|
|
|
7421
7560
|
const clientId = params.get("clientId") || void 0;
|
|
7422
7561
|
const status = params.get("status") || void 0;
|
|
7423
7562
|
if (!clientId && !staff.isAdmin) {
|
|
7424
|
-
const err = (0,
|
|
7563
|
+
const err = (0, import_scheduling72.schedError)("SCHED_900", { role: staff.role });
|
|
7425
7564
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
7426
7565
|
}
|
|
7427
7566
|
const startDate = params.get("startDate");
|
|
@@ -7432,7 +7571,7 @@ async function listAppointments(request, { host }) {
|
|
|
7432
7571
|
MAX_LIMIT2
|
|
7433
7572
|
);
|
|
7434
7573
|
const visibility = await staff.visibleCalendars();
|
|
7435
|
-
const where = (0,
|
|
7574
|
+
const where = (0, import_scheduling72.withOrganization)({
|
|
7436
7575
|
...visibility ? { calendar: visibility } : {},
|
|
7437
7576
|
...calendarId ? { calendarId } : {},
|
|
7438
7577
|
...clientId ? { clientId } : {},
|
|
@@ -7501,7 +7640,7 @@ async function listAppointments(request, { host }) {
|
|
|
7501
7640
|
}
|
|
7502
7641
|
|
|
7503
7642
|
// src/handlers/availability.ts
|
|
7504
|
-
var
|
|
7643
|
+
var import_scheduling73 = require("@ordinatio/scheduling");
|
|
7505
7644
|
|
|
7506
7645
|
// src/availability/picked-day.ts
|
|
7507
7646
|
var CALENDAR_DAY_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -7614,7 +7753,7 @@ async function getAvailability(request, { host }) {
|
|
|
7614
7753
|
const cached = await readCache(host.availabilityCache, calendarId, cacheDay, typeDuration);
|
|
7615
7754
|
if (cached != null) return corsJson(cors, cached);
|
|
7616
7755
|
}
|
|
7617
|
-
const result = await (0,
|
|
7756
|
+
const result = await (0, import_scheduling73.getAvailableSlots)(db, {
|
|
7618
7757
|
calendarId,
|
|
7619
7758
|
date: dateObj,
|
|
7620
7759
|
localDate: pickedDay,
|
|
@@ -7635,7 +7774,7 @@ async function getAvailability(request, { host }) {
|
|
|
7635
7774
|
}
|
|
7636
7775
|
|
|
7637
7776
|
// src/handlers/availability-team.ts
|
|
7638
|
-
var
|
|
7777
|
+
var import_scheduling74 = require("@ordinatio/scheduling");
|
|
7639
7778
|
|
|
7640
7779
|
// src/loaders/team-type.ts
|
|
7641
7780
|
async function loadTeamType(db, typeId, organizationId) {
|
|
@@ -7683,7 +7822,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7683
7822
|
{ status: 400 }
|
|
7684
7823
|
);
|
|
7685
7824
|
}
|
|
7686
|
-
const result = await (0,
|
|
7825
|
+
const result = await (0, import_scheduling74.getTeamAvailableSlots)(db, {
|
|
7687
7826
|
typeId,
|
|
7688
7827
|
date: dateObj,
|
|
7689
7828
|
localDate: pickedCalendarDay(date),
|
|
@@ -7706,7 +7845,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7706
7845
|
}
|
|
7707
7846
|
|
|
7708
7847
|
// src/handlers/appointment-types.ts
|
|
7709
|
-
var
|
|
7848
|
+
var import_scheduling75 = require("@ordinatio/scheduling");
|
|
7710
7849
|
|
|
7711
7850
|
// src/loaders/types-by-calendar.ts
|
|
7712
7851
|
function loadTypesByCalendarSlug(cache, db, organizationId, calendarSlug) {
|
|
@@ -7780,19 +7919,19 @@ async function getAppointmentTypes(request, { host }) {
|
|
|
7780
7919
|
}));
|
|
7781
7920
|
return corsJson(cors, response, { headers: WIDGET_CACHE_HEADERS });
|
|
7782
7921
|
} catch (error) {
|
|
7783
|
-
const diagnostic = (0,
|
|
7922
|
+
const diagnostic = (0, import_scheduling75.schedError)("SCHED_202", { error });
|
|
7784
7923
|
console.error("[appointment-types]", diagnostic.ref, error);
|
|
7785
7924
|
return corsJson(cors, { error: "Failed to fetch appointment types", ref: diagnostic.ref }, { status: 500 });
|
|
7786
7925
|
}
|
|
7787
7926
|
}
|
|
7788
7927
|
|
|
7789
7928
|
// src/handlers/coupons-validate.ts
|
|
7790
|
-
var
|
|
7791
|
-
var
|
|
7792
|
-
var Schema4 =
|
|
7793
|
-
code:
|
|
7794
|
-
calendarId:
|
|
7795
|
-
price:
|
|
7929
|
+
var import_zod21 = require("zod");
|
|
7930
|
+
var import_scheduling76 = require("@ordinatio/scheduling");
|
|
7931
|
+
var Schema4 = import_zod21.z.object({
|
|
7932
|
+
code: import_zod21.z.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
|
|
7933
|
+
calendarId: import_zod21.z.string().min(1),
|
|
7934
|
+
price: import_zod21.z.number().positive()
|
|
7796
7935
|
});
|
|
7797
7936
|
function calculateDiscount(price, discountType, discountValue) {
|
|
7798
7937
|
if (discountType === "PERCENTAGE") {
|
|
@@ -7850,7 +7989,7 @@ async function validateCoupon(request, { host }) {
|
|
|
7850
7989
|
{ headers: host.cors(request) }
|
|
7851
7990
|
);
|
|
7852
7991
|
} catch (error) {
|
|
7853
|
-
const err = (0,
|
|
7992
|
+
const err = (0, import_scheduling76.schedError)("SCHED_408", {
|
|
7854
7993
|
calendarId,
|
|
7855
7994
|
error: error instanceof Error ? error.message : String(error)
|
|
7856
7995
|
});
|
|
@@ -7930,7 +8069,7 @@ async function listActiveCalendars(request, { host }) {
|
|
|
7930
8069
|
}
|
|
7931
8070
|
|
|
7932
8071
|
// src/handlers/type.ts
|
|
7933
|
-
var
|
|
8072
|
+
var import_scheduling77 = require("@ordinatio/scheduling");
|
|
7934
8073
|
|
|
7935
8074
|
// src/loaders/type-by-slug.ts
|
|
7936
8075
|
function loadTypeBySlug(cache, db, organizationId, slug) {
|
|
@@ -8035,14 +8174,14 @@ async function getType(request, { host }) {
|
|
|
8035
8174
|
{ headers: WIDGET_CACHE_HEADERS }
|
|
8036
8175
|
);
|
|
8037
8176
|
} catch (error) {
|
|
8038
|
-
const diagnostic = (0,
|
|
8177
|
+
const diagnostic = (0, import_scheduling77.schedError)("SCHED_207", { error });
|
|
8039
8178
|
console.error("[type]", diagnostic.ref, error);
|
|
8040
8179
|
return corsJson(cors, { error: "Failed to fetch appointment type", ref: diagnostic.ref }, { status: 500 });
|
|
8041
8180
|
}
|
|
8042
8181
|
}
|
|
8043
8182
|
|
|
8044
8183
|
// src/handlers/widget-init.ts
|
|
8045
|
-
var
|
|
8184
|
+
var import_scheduling78 = require("@ordinatio/scheduling");
|
|
8046
8185
|
|
|
8047
8186
|
// src/loaders/widget-data.ts
|
|
8048
8187
|
function loadWidgetData(cache, db, organizationId, calendarSlug) {
|
|
@@ -8131,7 +8270,7 @@ async function getWidgetInit(request, { host }) {
|
|
|
8131
8270
|
}));
|
|
8132
8271
|
return corsJson(cors, { calendar, types: sanitizedTypes }, { headers: WIDGET_CACHE_HEADERS });
|
|
8133
8272
|
} catch (error) {
|
|
8134
|
-
const diagnostic = (0,
|
|
8273
|
+
const diagnostic = (0, import_scheduling78.schedError)("SCHED_206", { error });
|
|
8135
8274
|
console.error("[widget-init]", diagnostic.ref, error);
|
|
8136
8275
|
return corsJson(cors, { error: "Failed to load widget data", ref: diagnostic.ref }, { status: 500 });
|
|
8137
8276
|
}
|
|
@@ -8209,6 +8348,9 @@ var ROUTES = [
|
|
|
8209
8348
|
{ method: "GET", path: "/admin/text-settings", public: false, handler: getTextSettingsRoute },
|
|
8210
8349
|
{ method: "PUT", path: "/admin/text-settings", public: false, handler: saveTextSettingsRoute },
|
|
8211
8350
|
{ method: "DELETE", path: "/admin/text-settings", public: false, handler: deleteTextSettingsRoute },
|
|
8351
|
+
{ method: "GET", path: "/admin/api-keys", public: false, handler: listApiKeysRoute },
|
|
8352
|
+
{ method: "POST", path: "/admin/api-keys", public: false, handler: createApiKeyRoute },
|
|
8353
|
+
{ method: "DELETE", path: "/admin/api-keys/[id]", public: false, handler: revokeApiKeyRoute },
|
|
8212
8354
|
{ method: "GET", path: "/admin/brand/sending-domain", public: false, handler: checkSendingDomainRoute },
|
|
8213
8355
|
{ method: "POST", path: "/admin/privacy/export", public: false, handler: exportPrivacyRoute },
|
|
8214
8356
|
{ method: "POST", path: "/admin/privacy/erase", public: false, handler: erasePrivacyRoute },
|
|
@@ -8243,11 +8385,11 @@ var ROUTES = [
|
|
|
8243
8385
|
{ method: "POST", path: "/appointments/[id]/followup", public: false, handler: sendFollowup },
|
|
8244
8386
|
{ method: "POST", path: "/appointments/[id]/remind", public: false, handler: sendReminder },
|
|
8245
8387
|
{ 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 },
|
|
8388
|
+
{ method: "GET", path: "/calendars/connect-google", public: false, personOnly: true, handler: startGoogleConnection },
|
|
8389
|
+
{ method: "POST", path: "/calendars/connect-google", public: false, personOnly: true, handler: setGoogleCalendar },
|
|
8390
|
+
{ method: "GET", path: "/calendars/connect-google/callback", public: false, personOnly: true, handler: finishGoogleConnection },
|
|
8391
|
+
{ method: "GET", path: "/calendars/connect-outlook", public: false, personOnly: true, handler: startOutlookConnection },
|
|
8392
|
+
{ method: "GET", path: "/calendars/connect-outlook/callback", public: false, personOnly: true, handler: finishOutlookConnection },
|
|
8251
8393
|
{ method: "POST", path: "/appointments/[id]/cancel-sync", public: false, handler: cancelFromCalendarSync },
|
|
8252
8394
|
{ method: "POST", path: "/appointments/[id]/approve", public: false, handler: approveOrReject },
|
|
8253
8395
|
{ method: "POST", path: "/appointments/[id]/reschedule", public: false, handler: rescheduleByStaff },
|
|
@@ -8305,6 +8447,7 @@ function createSchedulingApi(config) {
|
|
|
8305
8447
|
privacy: config.host.privacy ?? null,
|
|
8306
8448
|
brand: config.host.brand ?? null,
|
|
8307
8449
|
textMessages: config.host.textMessages ?? null,
|
|
8450
|
+
apiKeys: config.host.apiKeys ?? null,
|
|
8308
8451
|
icalUidDomain: config.host.icalUidDomain?.bind(config.host) ?? (() => null),
|
|
8309
8452
|
calendarSync: config.host.calendarSync ?? { upsertEvent: async () => ({}), removeEvent: async () => void 0 },
|
|
8310
8453
|
activity: config.host.activity ?? { log: async () => void 0, isOpen: async () => false, resolve: async () => void 0 },
|
|
@@ -8332,6 +8475,14 @@ function createSchedulingApi(config) {
|
|
|
8332
8475
|
cors: config.host.cors?.bind(config.host) ?? defaultCorsHeaders
|
|
8333
8476
|
};
|
|
8334
8477
|
host.events = withWebhooks(withWaitlist(config.host.events ?? { emit: async () => void 0 }, host), host);
|
|
8478
|
+
async function hostForRoute(route, request) {
|
|
8479
|
+
try {
|
|
8480
|
+
return await hostForRequest(host, request, route);
|
|
8481
|
+
} catch (error) {
|
|
8482
|
+
console.error("[scheduling-api] could not check the API key:", error);
|
|
8483
|
+
return Response.json({ error: "Internal error" }, { status: 500 });
|
|
8484
|
+
}
|
|
8485
|
+
}
|
|
8335
8486
|
async function handle(request) {
|
|
8336
8487
|
const { pathname } = new URL(request.url);
|
|
8337
8488
|
if (pathname !== basePath && !pathname.startsWith(`${basePath}/`)) return notFound();
|
|
@@ -8349,7 +8500,9 @@ function createSchedulingApi(config) {
|
|
|
8349
8500
|
return Response.json({ error: "Method not allowed" }, { status: 405, headers: { Allow: allowed.join(", ") } });
|
|
8350
8501
|
}
|
|
8351
8502
|
try {
|
|
8352
|
-
|
|
8503
|
+
const runHost = await hostForRoute(hit.route, request);
|
|
8504
|
+
if (runHost instanceof Response) return runHost;
|
|
8505
|
+
return await hit.route.handler(request, { host: runHost, params: hit.params });
|
|
8353
8506
|
} catch (error) {
|
|
8354
8507
|
console.error("[scheduling-api] unhandled error:", error);
|
|
8355
8508
|
return Response.json({ error: "Internal error" }, { status: 500 });
|
|
@@ -8360,7 +8513,9 @@ function createSchedulingApi(config) {
|
|
|
8360
8513
|
if (!route) throw new Error(`No route ${method} ${path}`);
|
|
8361
8514
|
return async (request, context) => {
|
|
8362
8515
|
const params = await context?.params ?? {};
|
|
8363
|
-
|
|
8516
|
+
const runHost = await hostForRoute(route, request);
|
|
8517
|
+
if (runHost instanceof Response) return runHost;
|
|
8518
|
+
return route.handler(request, { host: runHost, params });
|
|
8364
8519
|
};
|
|
8365
8520
|
}
|
|
8366
8521
|
return { routes, handle, handler };
|
|
@@ -8819,10 +8974,10 @@ function createPerBusinessSmsAdapter(options) {
|
|
|
8819
8974
|
}
|
|
8820
8975
|
|
|
8821
8976
|
// src/sms/text-settings-resolver.ts
|
|
8822
|
-
var
|
|
8977
|
+
var import_scheduling79 = require("@ordinatio/scheduling");
|
|
8823
8978
|
function createTextSettingsResolver(options) {
|
|
8824
8979
|
return async (organizationId) => {
|
|
8825
|
-
const settings = await (0,
|
|
8980
|
+
const settings = await (0, import_scheduling79.getTextSettings)(await options.db(organizationId), organizationId);
|
|
8826
8981
|
if (!settings || !settings.enabled) return null;
|
|
8827
8982
|
try {
|
|
8828
8983
|
if (settings.provider === "TELNYX" && options.telnyx?.apiKey?.trim()) {
|
|
@@ -9116,44 +9271,6 @@ function createOutlookCalendarSync(config, hooks) {
|
|
|
9116
9271
|
};
|
|
9117
9272
|
}
|
|
9118
9273
|
|
|
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
9274
|
// src/staff/staff-scope.ts
|
|
9158
9275
|
function isCalendarVisibleInScope(calendarUserId, scope) {
|
|
9159
9276
|
if (calendarUserId === null) return true;
|
|
@@ -9269,6 +9386,7 @@ function createNodeListener(api, options) {
|
|
|
9269
9386
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9270
9387
|
0 && (module.exports = {
|
|
9271
9388
|
ALL_REFUND_STATUSES,
|
|
9389
|
+
ApiKeySchema,
|
|
9272
9390
|
BALANCE_APPOINTMENT_SELECT,
|
|
9273
9391
|
BALANCE_BLOCKED_APPOINTMENT_STATUS,
|
|
9274
9392
|
BALANCE_REQUIRED_PAYMENT_STATUS,
|
|
@@ -9323,6 +9441,7 @@ function createNodeListener(api, options) {
|
|
|
9323
9441
|
UpdateServicePackageSchema,
|
|
9324
9442
|
assertStripeTestKey,
|
|
9325
9443
|
attemptLegRefund,
|
|
9444
|
+
bearerKeyOf,
|
|
9326
9445
|
calendarVisibilityFilter,
|
|
9327
9446
|
canSeeAppointmentInScope,
|
|
9328
9447
|
canSeeCalendarInScope,
|