@ordinatio/scheduling-api 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -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 +156 -26
- package/dist/agent/index.mjs +156 -26
- package/dist/{chunk-X5BVCLX6.mjs → chunk-W3SY2DAU.mjs} +29 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +274 -90
- package/dist/index.mjs +178 -19
- package/dist/{routes-mii9tsbA.d.mts → routes-h90wEQuD.d.mts} +7 -0
- package/dist/{routes-mii9tsbA.d.ts → routes-h90wEQuD.d.ts} +7 -0
- package/dist/schemas/index.d.mts +24 -1
- package/dist/schemas/index.d.ts +24 -1
- package/dist/schemas/index.js +31 -0
- package/dist/schemas/index.mjs +7 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -55,6 +55,9 @@ __export(index_exports, {
|
|
|
55
55
|
CreateServicePackageSchema: () => CreateServicePackageSchema,
|
|
56
56
|
CreateWebhookEndpointSchema: () => CreateWebhookEndpointSchema,
|
|
57
57
|
DEFAULT_CANCELLATION_POLICY: () => DEFAULT_CANCELLATION_POLICY,
|
|
58
|
+
GiftCertificateCheckSchema: () => GiftCertificateCheckSchema,
|
|
59
|
+
GiftCertificateRestoreSchema: () => GiftCertificateRestoreSchema,
|
|
60
|
+
GiftCertificateSchema: () => GiftCertificateSchema,
|
|
58
61
|
IntakeFormFieldSchema: () => IntakeFormFieldSchema,
|
|
59
62
|
NoShowPreventionActionSchema: () => NoShowPreventionActionSchema,
|
|
60
63
|
NotificationChannelSchema: () => NotificationChannelSchema,
|
|
@@ -3497,6 +3500,31 @@ var ApiKeySchema = import_zod16.z.object({
|
|
|
3497
3500
|
access: import_zod16.z.string().max(20)
|
|
3498
3501
|
}).strict();
|
|
3499
3502
|
|
|
3503
|
+
// src/schemas/gift-certificate.schema.ts
|
|
3504
|
+
var import_zod17 = require("zod");
|
|
3505
|
+
var text = (max) => import_zod17.z.string().max(max).nullable().optional();
|
|
3506
|
+
var GiftCertificateSchema = import_zod17.z.object({
|
|
3507
|
+
amountCents: import_zod17.z.number(),
|
|
3508
|
+
currency: import_zod17.z.string().max(10).optional(),
|
|
3509
|
+
expiresAt: import_zod17.z.string().max(40).nullable().optional(),
|
|
3510
|
+
recipientName: text(300),
|
|
3511
|
+
recipientEmail: text(300),
|
|
3512
|
+
purchaserName: text(300),
|
|
3513
|
+
purchaserEmail: text(300),
|
|
3514
|
+
message: text(1e3),
|
|
3515
|
+
paymentId: text(300),
|
|
3516
|
+
notes: text(2e3)
|
|
3517
|
+
}).strict();
|
|
3518
|
+
var GiftCertificateRestoreSchema = import_zod17.z.object({
|
|
3519
|
+
amountCents: import_zod17.z.number(),
|
|
3520
|
+
appointmentId: import_zod17.z.string().max(200).optional(),
|
|
3521
|
+
note: import_zod17.z.string().max(1e3).optional()
|
|
3522
|
+
}).strict();
|
|
3523
|
+
var GiftCertificateCheckSchema = import_zod17.z.object({
|
|
3524
|
+
code: import_zod17.z.string().max(64),
|
|
3525
|
+
calendarId: import_zod17.z.string().min(1).max(200)
|
|
3526
|
+
}).strict();
|
|
3527
|
+
|
|
3500
3528
|
// src/pagination.ts
|
|
3501
3529
|
var DEFAULT_LIMIT = 50;
|
|
3502
3530
|
var MAX_LIMIT = 200;
|
|
@@ -3518,12 +3546,12 @@ function parsePagination(request, maxLimit = MAX_LIMIT, defaultLimit = DEFAULT_L
|
|
|
3518
3546
|
}
|
|
3519
3547
|
|
|
3520
3548
|
// src/validation.ts
|
|
3521
|
-
var
|
|
3549
|
+
var import_zod18 = require("zod");
|
|
3522
3550
|
async function parseBody(request, schema) {
|
|
3523
3551
|
try {
|
|
3524
3552
|
return { success: true, data: schema.parse(await request.json()) };
|
|
3525
3553
|
} catch (error) {
|
|
3526
|
-
if (error instanceof
|
|
3554
|
+
if (error instanceof import_zod18.ZodError) {
|
|
3527
3555
|
const details = error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message }));
|
|
3528
3556
|
return { success: false, response: Response.json({ error: "Validation failed", details }, { status: 400 }) };
|
|
3529
3557
|
}
|
|
@@ -3537,7 +3565,7 @@ function validateData(data, schema) {
|
|
|
3537
3565
|
try {
|
|
3538
3566
|
return { success: true, data: schema.parse(data) };
|
|
3539
3567
|
} catch (error) {
|
|
3540
|
-
if (error instanceof
|
|
3568
|
+
if (error instanceof import_zod18.ZodError) {
|
|
3541
3569
|
return { success: false, errors: error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message })) };
|
|
3542
3570
|
}
|
|
3543
3571
|
return { success: false, errors: [{ field: "", message: "Validation failed" }] };
|
|
@@ -4598,9 +4626,9 @@ async function getAnalytics(request, { host }) {
|
|
|
4598
4626
|
}
|
|
4599
4627
|
|
|
4600
4628
|
// src/sanitize/escape-html.ts
|
|
4601
|
-
function escapeHtml(
|
|
4602
|
-
if (!
|
|
4603
|
-
return
|
|
4629
|
+
function escapeHtml(text2) {
|
|
4630
|
+
if (!text2) return "";
|
|
4631
|
+
return text2.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4604
4632
|
}
|
|
4605
4633
|
|
|
4606
4634
|
// src/brand/brand-http.ts
|
|
@@ -6320,7 +6348,7 @@ async function deliverWebhooks(request, { host }) {
|
|
|
6320
6348
|
|
|
6321
6349
|
// src/handlers/waitlist-join.ts
|
|
6322
6350
|
var import_scheduling54 = require("@ordinatio/scheduling");
|
|
6323
|
-
var
|
|
6351
|
+
var import_zod19 = require("zod");
|
|
6324
6352
|
|
|
6325
6353
|
// src/waitlist/waitlist-http.ts
|
|
6326
6354
|
var import_scheduling53 = require("@ordinatio/scheduling");
|
|
@@ -6353,15 +6381,15 @@ async function requireWaitlistAdmin(host, request, options) {
|
|
|
6353
6381
|
}
|
|
6354
6382
|
|
|
6355
6383
|
// src/handlers/waitlist-join.ts
|
|
6356
|
-
var JoinWaitlistSchema =
|
|
6357
|
-
orgSlug:
|
|
6358
|
-
typeId:
|
|
6359
|
-
calendarId:
|
|
6360
|
-
day:
|
|
6361
|
-
slotStart:
|
|
6362
|
-
clientName:
|
|
6363
|
-
clientEmail:
|
|
6364
|
-
clientPhone:
|
|
6384
|
+
var JoinWaitlistSchema = import_zod19.z.object({
|
|
6385
|
+
orgSlug: import_zod19.z.string().min(1).max(100).optional(),
|
|
6386
|
+
typeId: import_zod19.z.string().min(1),
|
|
6387
|
+
calendarId: import_zod19.z.string().min(1).optional(),
|
|
6388
|
+
day: import_zod19.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Day must be YYYY-MM-DD"),
|
|
6389
|
+
slotStart: import_zod19.z.string().datetime({ message: "Invalid date/time format" }).optional(),
|
|
6390
|
+
clientName: import_zod19.z.string().trim().min(1, "Name is required").max(200),
|
|
6391
|
+
clientEmail: import_zod19.z.string().email("Invalid email").max(254),
|
|
6392
|
+
clientPhone: import_zod19.z.string().max(30).optional()
|
|
6365
6393
|
});
|
|
6366
6394
|
async function joinWaitlistRoute(request, { host }) {
|
|
6367
6395
|
const cors = host.cors(request);
|
|
@@ -6419,35 +6447,35 @@ async function leaveWaitlistRoute(request, { host }) {
|
|
|
6419
6447
|
|
|
6420
6448
|
// src/handlers/waitlist-offer.ts
|
|
6421
6449
|
var import_scheduling59 = require("@ordinatio/scheduling");
|
|
6422
|
-
var
|
|
6450
|
+
var import_zod21 = require("zod");
|
|
6423
6451
|
|
|
6424
6452
|
// src/handlers/appointments-book.ts
|
|
6425
6453
|
var import_scheduling58 = require("@ordinatio/scheduling");
|
|
6426
6454
|
|
|
6427
6455
|
// src/booking/booking-schema.ts
|
|
6428
|
-
var
|
|
6429
|
-
var BookingSchema =
|
|
6430
|
-
calendarId:
|
|
6431
|
-
preferredCalendarId:
|
|
6432
|
-
typeId:
|
|
6433
|
-
startTime:
|
|
6434
|
-
timezone:
|
|
6435
|
-
clientName:
|
|
6436
|
-
clientEmail:
|
|
6437
|
-
clientPhone:
|
|
6456
|
+
var import_zod20 = require("zod");
|
|
6457
|
+
var BookingSchema = import_zod20.z.object({
|
|
6458
|
+
calendarId: import_zod20.z.string().min(1).optional(),
|
|
6459
|
+
preferredCalendarId: import_zod20.z.string().min(1).optional(),
|
|
6460
|
+
typeId: import_zod20.z.string().min(1),
|
|
6461
|
+
startTime: import_zod20.z.string().datetime({ message: "Invalid date/time format" }),
|
|
6462
|
+
timezone: import_zod20.z.string().max(50).optional(),
|
|
6463
|
+
clientName: import_zod20.z.string().trim().min(1, "Name is required").max(200),
|
|
6464
|
+
clientEmail: import_zod20.z.string().email("Invalid email").max(254),
|
|
6465
|
+
clientPhone: import_zod20.z.string().max(30).optional(),
|
|
6438
6466
|
// Untrusted: the host's client resolver decides whether to honor it.
|
|
6439
|
-
clientId:
|
|
6440
|
-
notes:
|
|
6467
|
+
clientId: import_zod20.z.string().optional(),
|
|
6468
|
+
notes: import_zod20.z.string().max(1e3).optional(),
|
|
6441
6469
|
// Only the primitive types a form field produces; z.unknown() would accept anything.
|
|
6442
|
-
intakeResponses:
|
|
6443
|
-
|
|
6444
|
-
|
|
6470
|
+
intakeResponses: import_zod20.z.record(
|
|
6471
|
+
import_zod20.z.string(),
|
|
6472
|
+
import_zod20.z.union([import_zod20.z.string().max(1e3), import_zod20.z.number(), import_zod20.z.boolean(), import_zod20.z.null()])
|
|
6445
6473
|
).optional(),
|
|
6446
|
-
paymentId:
|
|
6447
|
-
couponCode:
|
|
6448
|
-
packagePurchaseId:
|
|
6474
|
+
paymentId: import_zod20.z.string().optional(),
|
|
6475
|
+
couponCode: import_zod20.z.string().min(1).max(50).transform((value) => value.trim().toUpperCase()).optional(),
|
|
6476
|
+
packagePurchaseId: import_zod20.z.string().optional(),
|
|
6449
6477
|
// Names the organization, so the calendar and type lookups can run against its own database.
|
|
6450
|
-
orgSlug:
|
|
6478
|
+
orgSlug: import_zod20.z.string().min(1).max(100).optional()
|
|
6451
6479
|
});
|
|
6452
6480
|
|
|
6453
6481
|
// src/booking/finalize-booking.ts
|
|
@@ -6937,7 +6965,7 @@ async function getWaitlistOfferRoute(request, { host }) {
|
|
|
6937
6965
|
return waitlistErrorResponse(cors, error, "Failed to read the offer");
|
|
6938
6966
|
}
|
|
6939
6967
|
}
|
|
6940
|
-
var AcceptSchema =
|
|
6968
|
+
var AcceptSchema = import_zod21.z.object({ token: import_zod21.z.string().min(1).max(200), orgSlug: import_zod21.z.string().min(1).max(100).optional() });
|
|
6941
6969
|
async function acceptWaitlistOfferRoute(request, context) {
|
|
6942
6970
|
const { host } = context;
|
|
6943
6971
|
const cors = host.cors(request);
|
|
@@ -7282,11 +7310,157 @@ async function revokeApiKeyRoute(request, { host, params }) {
|
|
|
7282
7310
|
}
|
|
7283
7311
|
}
|
|
7284
7312
|
|
|
7285
|
-
// src/handlers/admin-
|
|
7313
|
+
// src/handlers/admin-gift-certificates.ts
|
|
7314
|
+
var import_scheduling69 = require("@ordinatio/scheduling");
|
|
7315
|
+
|
|
7316
|
+
// src/gift-certificates/gift-http.ts
|
|
7286
7317
|
var import_scheduling68 = require("@ordinatio/scheduling");
|
|
7287
|
-
var NOT_ENABLED5 = { error: "
|
|
7288
|
-
|
|
7318
|
+
var NOT_ENABLED5 = { error: "Gift certificates are not enabled on this server" };
|
|
7319
|
+
var BAD_REQUEST = /* @__PURE__ */ new Set(["SCHED_1700", "SCHED_1706", "SCHED_1709"]);
|
|
7320
|
+
var CONFLICT = /* @__PURE__ */ new Set(["SCHED_1702", "SCHED_1703", "SCHED_1704", "SCHED_1707", "SCHED_1708", "SCHED_1710"]);
|
|
7321
|
+
var CODE_SHAPE = /\b[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}\b/g;
|
|
7322
|
+
function safeErrorText(error) {
|
|
7323
|
+
if (!(error instanceof Error)) return "unknown error";
|
|
7324
|
+
const code = error.code;
|
|
7325
|
+
return `${error.name}${typeof code === "string" ? ` ${code}` : ""}: ${error.message.replace(CODE_SHAPE, "[code]").slice(0, 300)}`;
|
|
7326
|
+
}
|
|
7327
|
+
function forCaller(staff, certificate) {
|
|
7328
|
+
if (!staff.role.startsWith(API_KEY_ROLE_PREFIX) || staff.role === `${API_KEY_ROLE_PREFIX}FULL`) return certificate;
|
|
7329
|
+
return { ...certificate, code: `\u2026${certificate.code.slice(-4)}`, codeHidden: true };
|
|
7330
|
+
}
|
|
7331
|
+
function noStoreJson(body, init = {}) {
|
|
7332
|
+
return Response.json(body, { status: init.status ?? 200, headers: { "Cache-Control": "no-store" } });
|
|
7333
|
+
}
|
|
7334
|
+
function giftFailure(error, fallback) {
|
|
7335
|
+
if (error instanceof import_scheduling68.SchedulingNotFoundError) return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error) }, { status: 404 });
|
|
7289
7336
|
if (error instanceof import_scheduling68.SchedulingValidationError) {
|
|
7337
|
+
const status = BAD_REQUEST.has(error.code) ? 400 : CONFLICT.has(error.code) ? 409 : 500;
|
|
7338
|
+
if (status !== 500) {
|
|
7339
|
+
const details = error.context?.errors;
|
|
7340
|
+
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status });
|
|
7341
|
+
}
|
|
7342
|
+
}
|
|
7343
|
+
console.error("[gift-certificates]", safeErrorText(error));
|
|
7344
|
+
return Response.json({ error: fallback }, { status: 500 });
|
|
7345
|
+
}
|
|
7346
|
+
async function recordGiftActivity(host, staff, entry) {
|
|
7347
|
+
await host.activity.log(staff.db, entry).catch((error) => {
|
|
7348
|
+
console.error("[gift-certificates] could not record the activity", safeErrorText(error));
|
|
7349
|
+
});
|
|
7350
|
+
}
|
|
7351
|
+
async function requireGiftAdmin(host, request, options) {
|
|
7352
|
+
const staff = await requireAdminStaff(host, request, options);
|
|
7353
|
+
if (staff instanceof Response) return staff;
|
|
7354
|
+
if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501 });
|
|
7355
|
+
return staff;
|
|
7356
|
+
}
|
|
7357
|
+
|
|
7358
|
+
// src/handlers/admin-gift-certificates.ts
|
|
7359
|
+
async function listGiftCertificatesRoute(request, { host }) {
|
|
7360
|
+
try {
|
|
7361
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-list", tier: "GENERAL" });
|
|
7362
|
+
if (staff instanceof Response) return staff;
|
|
7363
|
+
const params = new URL(request.url).searchParams;
|
|
7364
|
+
const status = params.get("status");
|
|
7365
|
+
if (status !== null && status !== "ACTIVE" && status !== "VOID") return Response.json({ error: "status must be ACTIVE or VOID" }, { status: 400 });
|
|
7366
|
+
const limit = params.get("limit");
|
|
7367
|
+
const certificates = await (0, import_scheduling69.listGiftCertificates)(staff.db, staff.organizationId, { ...status ? { status } : {}, ...limit ? { limit: Number(limit) } : {} });
|
|
7368
|
+
return noStoreJson({ certificates: certificates.map((certificate) => forCaller(staff, certificate)) });
|
|
7369
|
+
} catch (error) {
|
|
7370
|
+
return giftFailure(error, "Failed to list the gift certificates");
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
async function issueGiftCertificateRoute(request, { host }) {
|
|
7374
|
+
try {
|
|
7375
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-issue", tier: "CREATE" });
|
|
7376
|
+
if (staff instanceof Response) return staff;
|
|
7377
|
+
const validation = await parseBody(request, GiftCertificateSchema);
|
|
7378
|
+
if (!validation.success) return validation.response;
|
|
7379
|
+
const { certificate, created } = await (0, import_scheduling69.issueGiftCertificateOnce)(staff.db, staff.organizationId, validation.data, staff.userId);
|
|
7380
|
+
if (!created) return noStoreJson({ certificate: forCaller(staff, certificate) });
|
|
7381
|
+
await recordGiftActivity(host, staff, {
|
|
7382
|
+
action: "scheduling.gift_certificate_issued",
|
|
7383
|
+
description: "issued a gift certificate",
|
|
7384
|
+
metadata: { certificateId: certificate.id, amountCents: certificate.initialCents, currency: certificate.currency }
|
|
7385
|
+
});
|
|
7386
|
+
return noStoreJson({ certificate: forCaller(staff, certificate) }, { status: 201 });
|
|
7387
|
+
} catch (error) {
|
|
7388
|
+
return giftFailure(error, "Failed to issue the gift certificate");
|
|
7389
|
+
}
|
|
7390
|
+
}
|
|
7391
|
+
|
|
7392
|
+
// src/handlers/admin-gift-certificate-detail.ts
|
|
7393
|
+
var import_scheduling70 = require("@ordinatio/scheduling");
|
|
7394
|
+
async function getGiftCertificateRoute(request, { host, params }) {
|
|
7395
|
+
try {
|
|
7396
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-get", tier: "GENERAL" });
|
|
7397
|
+
if (staff instanceof Response) return staff;
|
|
7398
|
+
const found = await (0, import_scheduling70.getGiftCertificate)(staff.db, staff.organizationId, params.id);
|
|
7399
|
+
return noStoreJson({ ...found, certificate: forCaller(staff, found.certificate) });
|
|
7400
|
+
} catch (error) {
|
|
7401
|
+
return giftFailure(error, "Failed to read the gift certificate");
|
|
7402
|
+
}
|
|
7403
|
+
}
|
|
7404
|
+
async function voidGiftCertificateRoute(request, { host, params }) {
|
|
7405
|
+
try {
|
|
7406
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-void", tier: "DELETE" });
|
|
7407
|
+
if (staff instanceof Response) return staff;
|
|
7408
|
+
const voided = await (0, import_scheduling70.voidGiftCertificate)(staff.db, staff.organizationId, params.id, staff.userId);
|
|
7409
|
+
if (!voided) return Response.json({ error: "Gift certificate not found, or already void" }, { status: 404 });
|
|
7410
|
+
await recordGiftActivity(host, staff, { action: "scheduling.gift_certificate_voided", description: "voided a gift certificate", metadata: { certificateId: params.id } });
|
|
7411
|
+
return noStoreJson({ voided: true });
|
|
7412
|
+
} catch (error) {
|
|
7413
|
+
return giftFailure(error, "Failed to void the gift certificate");
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
async function restoreGiftCertificateRoute(request, { host, params }) {
|
|
7417
|
+
try {
|
|
7418
|
+
const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-restore", tier: "UPDATE" });
|
|
7419
|
+
if (staff instanceof Response) return staff;
|
|
7420
|
+
const validation = await parseBody(request, GiftCertificateRestoreSchema);
|
|
7421
|
+
if (!validation.success) return validation.response;
|
|
7422
|
+
const restored = await (0, import_scheduling70.restoreGiftCertificate)(staff.db, staff.organizationId, params.id, validation.data, staff.userId);
|
|
7423
|
+
await recordGiftActivity(host, staff, {
|
|
7424
|
+
action: "scheduling.gift_certificate_restored",
|
|
7425
|
+
description: "gave value back to a gift certificate",
|
|
7426
|
+
metadata: { certificateId: params.id, amountCents: restored.restoredCents, ...validation.data.appointmentId ? { appointmentId: validation.data.appointmentId } : {} }
|
|
7427
|
+
});
|
|
7428
|
+
return noStoreJson({ restored });
|
|
7429
|
+
} catch (error) {
|
|
7430
|
+
return giftFailure(error, "Failed to give value back to the gift certificate");
|
|
7431
|
+
}
|
|
7432
|
+
}
|
|
7433
|
+
|
|
7434
|
+
// src/handlers/gift-certificates-check.ts
|
|
7435
|
+
var import_scheduling71 = require("@ordinatio/scheduling");
|
|
7436
|
+
async function checkGiftCertificateRoute(request, { host }) {
|
|
7437
|
+
const cors = host.cors(request);
|
|
7438
|
+
const headers = { ...cors, "Cache-Control": "no-store" };
|
|
7439
|
+
if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501, headers });
|
|
7440
|
+
const limited = await host.rateLimit(`gift-check:${clientAddress(request)}`, "PUBLIC_BOOKING");
|
|
7441
|
+
if (limited) return limited;
|
|
7442
|
+
const parsed = validateData(await request.json().catch(() => null), GiftCertificateCheckSchema);
|
|
7443
|
+
if (!parsed.success) return Response.json({ error: "Validation failed" }, { status: 400, headers });
|
|
7444
|
+
const { code, calendarId } = parsed.data;
|
|
7445
|
+
try {
|
|
7446
|
+
const db = await host.publicDb();
|
|
7447
|
+
const calendar = await db.schedulingCalendar.findUnique({ where: { id: calendarId }, select: { organizationId: true } });
|
|
7448
|
+
const found = calendar?.organizationId ? await (0, import_scheduling71.checkGiftCertificate)(db, calendar.organizationId, code) : null;
|
|
7449
|
+
if (!found) return Response.json({ valid: false, reason: "not_found" }, { headers });
|
|
7450
|
+
if (found.state !== "ACTIVE") return Response.json({ valid: false, reason: found.state.toLowerCase() }, { headers });
|
|
7451
|
+
return Response.json({ valid: true, balanceCents: found.balanceCents, currency: found.currency, expiresAt: found.expiresAt }, { headers });
|
|
7452
|
+
} catch (error) {
|
|
7453
|
+
const err = (0, import_scheduling71.schedError)("SCHED_408", { calendarId, error: safeErrorText(error) });
|
|
7454
|
+
console.error(`[${err.ref}] gift certificate check failed:`, safeErrorText(error));
|
|
7455
|
+
return Response.json({ valid: false, reason: "error", error: err.description, ref: err.ref }, { status: 500, headers });
|
|
7456
|
+
}
|
|
7457
|
+
}
|
|
7458
|
+
|
|
7459
|
+
// src/handlers/admin-text-settings.ts
|
|
7460
|
+
var import_scheduling72 = require("@ordinatio/scheduling");
|
|
7461
|
+
var NOT_ENABLED6 = { error: "Text-message settings are not enabled on this server" };
|
|
7462
|
+
function failure4(error, fallback) {
|
|
7463
|
+
if (error instanceof import_scheduling72.SchedulingValidationError) {
|
|
7290
7464
|
const details = error.context.errors;
|
|
7291
7465
|
return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
|
|
7292
7466
|
}
|
|
@@ -7296,14 +7470,14 @@ function failure4(error, fallback) {
|
|
|
7296
7470
|
async function requireTextAdmin(host, request, options) {
|
|
7297
7471
|
const staff = await requireAdminStaff(host, request, options);
|
|
7298
7472
|
if (staff instanceof Response) return staff;
|
|
7299
|
-
if (!host.textMessages) return Response.json(
|
|
7473
|
+
if (!host.textMessages) return Response.json(NOT_ENABLED6, { status: 501 });
|
|
7300
7474
|
return staff;
|
|
7301
7475
|
}
|
|
7302
7476
|
async function getTextSettingsRoute(request, { host }) {
|
|
7303
7477
|
try {
|
|
7304
7478
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-get", tier: "GENERAL" });
|
|
7305
7479
|
if (staff instanceof Response) return staff;
|
|
7306
|
-
return Response.json({ settings: await (0,
|
|
7480
|
+
return Response.json({ settings: await (0, import_scheduling72.getTextSettings)(staff.db, staff.organizationId), providers: host.textMessages?.providers ?? ["TELNYX", "TWILIO"] });
|
|
7307
7481
|
} catch (error) {
|
|
7308
7482
|
return failure4(error, "Failed to read the text-message settings");
|
|
7309
7483
|
}
|
|
@@ -7314,7 +7488,7 @@ async function saveTextSettingsRoute(request, { host }) {
|
|
|
7314
7488
|
if (staff instanceof Response) return staff;
|
|
7315
7489
|
const validation = await parseBody(request, TextSettingsSchema);
|
|
7316
7490
|
if (!validation.success) return validation.response;
|
|
7317
|
-
const settings = await (0,
|
|
7491
|
+
const settings = await (0, import_scheduling72.saveTextSettings)(staff.db, staff.organizationId, validation.data, { providers: host.textMessages?.providers });
|
|
7318
7492
|
await host.activity.log(staff.db, {
|
|
7319
7493
|
action: "scheduling.text_settings_saved",
|
|
7320
7494
|
description: "changed the text-message settings",
|
|
@@ -7329,7 +7503,7 @@ async function deleteTextSettingsRoute(request, { host }) {
|
|
|
7329
7503
|
try {
|
|
7330
7504
|
const staff = await requireTextAdmin(host, request, { action: "admin-text-settings-delete", tier: "DELETE" });
|
|
7331
7505
|
if (staff instanceof Response) return staff;
|
|
7332
|
-
const removed = await (0,
|
|
7506
|
+
const removed = await (0, import_scheduling72.deleteTextSettings)(staff.db, staff.organizationId);
|
|
7333
7507
|
if (removed) await host.activity.log(staff.db, { action: "scheduling.text_settings_removed", description: "removed the text-message settings", metadata: {} });
|
|
7334
7508
|
return Response.json({ removed });
|
|
7335
7509
|
} catch (error) {
|
|
@@ -7406,14 +7580,14 @@ async function checkSendingDomainRoute(request, { host }) {
|
|
|
7406
7580
|
}
|
|
7407
7581
|
|
|
7408
7582
|
// src/handlers/admin-privacy.ts
|
|
7409
|
-
var
|
|
7583
|
+
var import_scheduling74 = require("@ordinatio/scheduling");
|
|
7410
7584
|
|
|
7411
7585
|
// src/privacy/privacy-http.ts
|
|
7412
|
-
var
|
|
7413
|
-
var
|
|
7586
|
+
var import_scheduling73 = require("@ordinatio/scheduling");
|
|
7587
|
+
var NOT_ENABLED7 = { error: "Data export and erasure are not enabled on this server" };
|
|
7414
7588
|
var STATUS_BY_CODE3 = { SCHED_1300: 400, SCHED_1301: 409 };
|
|
7415
7589
|
function privacyErrorResponse(error, fallback) {
|
|
7416
|
-
if (error instanceof
|
|
7590
|
+
if (error instanceof import_scheduling73.SchedulingValidationError) {
|
|
7417
7591
|
return Response.json(
|
|
7418
7592
|
{ error: error.message, code: error.code, ref: getErrorRef(error), details: error.context },
|
|
7419
7593
|
{ status: STATUS_BY_CODE3[error.code] ?? 400 }
|
|
@@ -7425,7 +7599,7 @@ function privacyErrorResponse(error, fallback) {
|
|
|
7425
7599
|
async function requirePrivacyAdmin(host, request, options) {
|
|
7426
7600
|
const staff = await requireAdminStaff(host, request, options);
|
|
7427
7601
|
if (staff instanceof Response) return staff;
|
|
7428
|
-
if (!host.privacy) return Response.json(
|
|
7602
|
+
if (!host.privacy) return Response.json(NOT_ENABLED7, { status: 501 });
|
|
7429
7603
|
return staff;
|
|
7430
7604
|
}
|
|
7431
7605
|
|
|
@@ -7443,7 +7617,7 @@ async function exportPrivacyRoute(request, { host }) {
|
|
|
7443
7617
|
if (staff instanceof Response) return staff;
|
|
7444
7618
|
const validation = await parseBody(request, PrivacySubjectSchema);
|
|
7445
7619
|
if (!validation.success) return validation.response;
|
|
7446
|
-
const result = await (0,
|
|
7620
|
+
const result = await (0, import_scheduling74.exportSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...validation.data });
|
|
7447
7621
|
await logQuietly(host, staff.db, {
|
|
7448
7622
|
action: "scheduling.privacy_export",
|
|
7449
7623
|
description: "exported the data held about one person",
|
|
@@ -7470,10 +7644,10 @@ async function erasePrivacyRoute(request, { host }) {
|
|
|
7470
7644
|
if (!validation.success) return validation.response;
|
|
7471
7645
|
const { confirm, ...subject2 } = validation.data;
|
|
7472
7646
|
if (confirm !== true) {
|
|
7473
|
-
const preview = await (0,
|
|
7647
|
+
const preview = await (0, import_scheduling74.previewErase)(staff.db, { organizationId: staff.organizationId, ...subject2 });
|
|
7474
7648
|
return Response.json({ erased: false, preview }, { headers: { "cache-control": "no-store" } });
|
|
7475
7649
|
}
|
|
7476
|
-
const { counts } = await (0,
|
|
7650
|
+
const { counts } = await (0, import_scheduling74.eraseSubject)(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...subject2 });
|
|
7477
7651
|
await logQuietly(host, staff.db, {
|
|
7478
7652
|
action: "scheduling.privacy_erase",
|
|
7479
7653
|
description: "erased the data held about one person",
|
|
@@ -7489,7 +7663,7 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7489
7663
|
const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-requests", tier: "GENERAL" });
|
|
7490
7664
|
if (staff instanceof Response) return staff;
|
|
7491
7665
|
const { limit, offset } = parsePagination(request);
|
|
7492
|
-
const { requests, total } = await (0,
|
|
7666
|
+
const { requests, total } = await (0, import_scheduling74.listPrivacyRequests)(staff.db, { organizationId: staff.organizationId, limit, offset });
|
|
7493
7667
|
return Response.json({ requests, total, hasMore: offset + requests.length < total });
|
|
7494
7668
|
} catch (error) {
|
|
7495
7669
|
return privacyErrorResponse(error, "Failed to list the requests");
|
|
@@ -7497,12 +7671,12 @@ async function listPrivacyRequestsRoute(request, { host }) {
|
|
|
7497
7671
|
}
|
|
7498
7672
|
|
|
7499
7673
|
// src/handlers/admin-routing-form-detail.ts
|
|
7500
|
-
var
|
|
7674
|
+
var import_scheduling75 = require("@ordinatio/scheduling");
|
|
7501
7675
|
async function getRoutingFormAdminRoute(request, { host, params }) {
|
|
7502
7676
|
try {
|
|
7503
7677
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-get", tier: "GENERAL" });
|
|
7504
7678
|
if (staff instanceof Response) return staff;
|
|
7505
|
-
return Response.json({ form: await (0,
|
|
7679
|
+
return Response.json({ form: await (0, import_scheduling75.getRoutingForm)(staff.db, staff.organizationId, params.id) });
|
|
7506
7680
|
} catch (error) {
|
|
7507
7681
|
return routingErrorResponse(error, "Failed to read the form");
|
|
7508
7682
|
}
|
|
@@ -7513,7 +7687,7 @@ async function updateRoutingFormRoute(request, { host, params }) {
|
|
|
7513
7687
|
if (staff instanceof Response) return staff;
|
|
7514
7688
|
const validation = await parseBody(request, UpdateRoutingFormSchema);
|
|
7515
7689
|
if (!validation.success) return validation.response;
|
|
7516
|
-
const form = await (0,
|
|
7690
|
+
const form = await (0, import_scheduling75.updateRoutingForm)(staff.db, staff.organizationId, params.id, validation.data);
|
|
7517
7691
|
await host.activity.log(staff.db, {
|
|
7518
7692
|
action: "scheduling.routing_form_updated",
|
|
7519
7693
|
description: `changed routing form "${form.name}"`,
|
|
@@ -7528,7 +7702,7 @@ async function deleteRoutingFormRoute(request, { host, params }) {
|
|
|
7528
7702
|
try {
|
|
7529
7703
|
const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-delete", tier: "DELETE" });
|
|
7530
7704
|
if (staff instanceof Response) return staff;
|
|
7531
|
-
await (0,
|
|
7705
|
+
await (0, import_scheduling75.deleteRoutingForm)(staff.db, staff.organizationId, params.id);
|
|
7532
7706
|
await host.activity.log(staff.db, { action: "scheduling.routing_form_deleted", description: "removed a routing form", metadata: { formId: params.id } });
|
|
7533
7707
|
return Response.json({ success: true });
|
|
7534
7708
|
} catch (error) {
|
|
@@ -7541,14 +7715,14 @@ async function testRoutingFormRoute(request, { host, params }) {
|
|
|
7541
7715
|
if (staff instanceof Response) return staff;
|
|
7542
7716
|
const validation = await parseBody(request, TestRoutingFormSchema);
|
|
7543
7717
|
if (!validation.success) return validation.response;
|
|
7544
|
-
return Response.json(await (0,
|
|
7718
|
+
return Response.json(await (0, import_scheduling75.testRoutingForm)(staff.db, { organizationId: staff.organizationId, id: params.id, answers: validation.data.answers }));
|
|
7545
7719
|
} catch (error) {
|
|
7546
7720
|
return routingErrorResponse(error, "Failed to test the form");
|
|
7547
7721
|
}
|
|
7548
7722
|
}
|
|
7549
7723
|
|
|
7550
7724
|
// src/handlers/appointments-list.ts
|
|
7551
|
-
var
|
|
7725
|
+
var import_scheduling76 = require("@ordinatio/scheduling");
|
|
7552
7726
|
var DEFAULT_LIMIT2 = 50;
|
|
7553
7727
|
var MAX_LIMIT2 = 500;
|
|
7554
7728
|
async function listAppointments(request, { host }) {
|
|
@@ -7560,7 +7734,7 @@ async function listAppointments(request, { host }) {
|
|
|
7560
7734
|
const clientId = params.get("clientId") || void 0;
|
|
7561
7735
|
const status = params.get("status") || void 0;
|
|
7562
7736
|
if (!clientId && !staff.isAdmin) {
|
|
7563
|
-
const err = (0,
|
|
7737
|
+
const err = (0, import_scheduling76.schedError)("SCHED_900", { role: staff.role });
|
|
7564
7738
|
return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
|
|
7565
7739
|
}
|
|
7566
7740
|
const startDate = params.get("startDate");
|
|
@@ -7571,7 +7745,7 @@ async function listAppointments(request, { host }) {
|
|
|
7571
7745
|
MAX_LIMIT2
|
|
7572
7746
|
);
|
|
7573
7747
|
const visibility = await staff.visibleCalendars();
|
|
7574
|
-
const where = (0,
|
|
7748
|
+
const where = (0, import_scheduling76.withOrganization)({
|
|
7575
7749
|
...visibility ? { calendar: visibility } : {},
|
|
7576
7750
|
...calendarId ? { calendarId } : {},
|
|
7577
7751
|
...clientId ? { clientId } : {},
|
|
@@ -7640,7 +7814,7 @@ async function listAppointments(request, { host }) {
|
|
|
7640
7814
|
}
|
|
7641
7815
|
|
|
7642
7816
|
// src/handlers/availability.ts
|
|
7643
|
-
var
|
|
7817
|
+
var import_scheduling77 = require("@ordinatio/scheduling");
|
|
7644
7818
|
|
|
7645
7819
|
// src/availability/picked-day.ts
|
|
7646
7820
|
var CALENDAR_DAY_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -7753,7 +7927,7 @@ async function getAvailability(request, { host }) {
|
|
|
7753
7927
|
const cached = await readCache(host.availabilityCache, calendarId, cacheDay, typeDuration);
|
|
7754
7928
|
if (cached != null) return corsJson(cors, cached);
|
|
7755
7929
|
}
|
|
7756
|
-
const result = await (0,
|
|
7930
|
+
const result = await (0, import_scheduling77.getAvailableSlots)(db, {
|
|
7757
7931
|
calendarId,
|
|
7758
7932
|
date: dateObj,
|
|
7759
7933
|
localDate: pickedDay,
|
|
@@ -7774,7 +7948,7 @@ async function getAvailability(request, { host }) {
|
|
|
7774
7948
|
}
|
|
7775
7949
|
|
|
7776
7950
|
// src/handlers/availability-team.ts
|
|
7777
|
-
var
|
|
7951
|
+
var import_scheduling78 = require("@ordinatio/scheduling");
|
|
7778
7952
|
|
|
7779
7953
|
// src/loaders/team-type.ts
|
|
7780
7954
|
async function loadTeamType(db, typeId, organizationId) {
|
|
@@ -7822,7 +7996,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7822
7996
|
{ status: 400 }
|
|
7823
7997
|
);
|
|
7824
7998
|
}
|
|
7825
|
-
const result = await (0,
|
|
7999
|
+
const result = await (0, import_scheduling78.getTeamAvailableSlots)(db, {
|
|
7826
8000
|
typeId,
|
|
7827
8001
|
date: dateObj,
|
|
7828
8002
|
localDate: pickedCalendarDay(date),
|
|
@@ -7845,7 +8019,7 @@ async function getTeamAvailability(request, { host }) {
|
|
|
7845
8019
|
}
|
|
7846
8020
|
|
|
7847
8021
|
// src/handlers/appointment-types.ts
|
|
7848
|
-
var
|
|
8022
|
+
var import_scheduling79 = require("@ordinatio/scheduling");
|
|
7849
8023
|
|
|
7850
8024
|
// src/loaders/types-by-calendar.ts
|
|
7851
8025
|
function loadTypesByCalendarSlug(cache, db, organizationId, calendarSlug) {
|
|
@@ -7919,19 +8093,19 @@ async function getAppointmentTypes(request, { host }) {
|
|
|
7919
8093
|
}));
|
|
7920
8094
|
return corsJson(cors, response, { headers: WIDGET_CACHE_HEADERS });
|
|
7921
8095
|
} catch (error) {
|
|
7922
|
-
const diagnostic = (0,
|
|
8096
|
+
const diagnostic = (0, import_scheduling79.schedError)("SCHED_202", { error });
|
|
7923
8097
|
console.error("[appointment-types]", diagnostic.ref, error);
|
|
7924
8098
|
return corsJson(cors, { error: "Failed to fetch appointment types", ref: diagnostic.ref }, { status: 500 });
|
|
7925
8099
|
}
|
|
7926
8100
|
}
|
|
7927
8101
|
|
|
7928
8102
|
// src/handlers/coupons-validate.ts
|
|
7929
|
-
var
|
|
7930
|
-
var
|
|
7931
|
-
var Schema4 =
|
|
7932
|
-
code:
|
|
7933
|
-
calendarId:
|
|
7934
|
-
price:
|
|
8103
|
+
var import_zod22 = require("zod");
|
|
8104
|
+
var import_scheduling80 = require("@ordinatio/scheduling");
|
|
8105
|
+
var Schema4 = import_zod22.z.object({
|
|
8106
|
+
code: import_zod22.z.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
|
|
8107
|
+
calendarId: import_zod22.z.string().min(1),
|
|
8108
|
+
price: import_zod22.z.number().positive()
|
|
7935
8109
|
});
|
|
7936
8110
|
function calculateDiscount(price, discountType, discountValue) {
|
|
7937
8111
|
if (discountType === "PERCENTAGE") {
|
|
@@ -7989,7 +8163,7 @@ async function validateCoupon(request, { host }) {
|
|
|
7989
8163
|
{ headers: host.cors(request) }
|
|
7990
8164
|
);
|
|
7991
8165
|
} catch (error) {
|
|
7992
|
-
const err = (0,
|
|
8166
|
+
const err = (0, import_scheduling80.schedError)("SCHED_408", {
|
|
7993
8167
|
calendarId,
|
|
7994
8168
|
error: error instanceof Error ? error.message : String(error)
|
|
7995
8169
|
});
|
|
@@ -8069,7 +8243,7 @@ async function listActiveCalendars(request, { host }) {
|
|
|
8069
8243
|
}
|
|
8070
8244
|
|
|
8071
8245
|
// src/handlers/type.ts
|
|
8072
|
-
var
|
|
8246
|
+
var import_scheduling81 = require("@ordinatio/scheduling");
|
|
8073
8247
|
|
|
8074
8248
|
// src/loaders/type-by-slug.ts
|
|
8075
8249
|
function loadTypeBySlug(cache, db, organizationId, slug) {
|
|
@@ -8174,14 +8348,14 @@ async function getType(request, { host }) {
|
|
|
8174
8348
|
{ headers: WIDGET_CACHE_HEADERS }
|
|
8175
8349
|
);
|
|
8176
8350
|
} catch (error) {
|
|
8177
|
-
const diagnostic = (0,
|
|
8351
|
+
const diagnostic = (0, import_scheduling81.schedError)("SCHED_207", { error });
|
|
8178
8352
|
console.error("[type]", diagnostic.ref, error);
|
|
8179
8353
|
return corsJson(cors, { error: "Failed to fetch appointment type", ref: diagnostic.ref }, { status: 500 });
|
|
8180
8354
|
}
|
|
8181
8355
|
}
|
|
8182
8356
|
|
|
8183
8357
|
// src/handlers/widget-init.ts
|
|
8184
|
-
var
|
|
8358
|
+
var import_scheduling82 = require("@ordinatio/scheduling");
|
|
8185
8359
|
|
|
8186
8360
|
// src/loaders/widget-data.ts
|
|
8187
8361
|
function loadWidgetData(cache, db, organizationId, calendarSlug) {
|
|
@@ -8270,7 +8444,7 @@ async function getWidgetInit(request, { host }) {
|
|
|
8270
8444
|
}));
|
|
8271
8445
|
return corsJson(cors, { calendar, types: sanitizedTypes }, { headers: WIDGET_CACHE_HEADERS });
|
|
8272
8446
|
} catch (error) {
|
|
8273
|
-
const diagnostic = (0,
|
|
8447
|
+
const diagnostic = (0, import_scheduling82.schedError)("SCHED_206", { error });
|
|
8274
8448
|
console.error("[widget-init]", diagnostic.ref, error);
|
|
8275
8449
|
return corsJson(cors, { error: "Failed to load widget data", ref: diagnostic.ref }, { status: 500 });
|
|
8276
8450
|
}
|
|
@@ -8279,6 +8453,7 @@ async function getWidgetInit(request, { host }) {
|
|
|
8279
8453
|
// src/routes.ts
|
|
8280
8454
|
var ROUTES = [
|
|
8281
8455
|
{ method: "POST", path: "/coupons/validate", public: true, handler: validateCoupon },
|
|
8456
|
+
{ method: "POST", path: "/gift-certificates/check", public: true, handler: checkGiftCertificateRoute },
|
|
8282
8457
|
{ method: "POST", path: "/payments/intent", public: true, handler: createPaymentIntentRoute },
|
|
8283
8458
|
{ method: "GET", path: "/widget-init", public: true, handler: getWidgetInit },
|
|
8284
8459
|
{ method: "GET", path: "/type", public: true, handler: getType },
|
|
@@ -8351,6 +8526,11 @@ var ROUTES = [
|
|
|
8351
8526
|
{ method: "GET", path: "/admin/api-keys", public: false, handler: listApiKeysRoute },
|
|
8352
8527
|
{ method: "POST", path: "/admin/api-keys", public: false, handler: createApiKeyRoute },
|
|
8353
8528
|
{ method: "DELETE", path: "/admin/api-keys/[id]", public: false, handler: revokeApiKeyRoute },
|
|
8529
|
+
{ method: "GET", path: "/admin/gift-certificates", public: false, handler: listGiftCertificatesRoute },
|
|
8530
|
+
{ method: "POST", path: "/admin/gift-certificates", public: false, handler: issueGiftCertificateRoute },
|
|
8531
|
+
{ method: "GET", path: "/admin/gift-certificates/[id]", public: false, handler: getGiftCertificateRoute },
|
|
8532
|
+
{ method: "POST", path: "/admin/gift-certificates/[id]/void", public: false, handler: voidGiftCertificateRoute },
|
|
8533
|
+
{ method: "POST", path: "/admin/gift-certificates/[id]/restore", public: false, handler: restoreGiftCertificateRoute },
|
|
8354
8534
|
{ method: "GET", path: "/admin/brand/sending-domain", public: false, handler: checkSendingDomainRoute },
|
|
8355
8535
|
{ method: "POST", path: "/admin/privacy/export", public: false, handler: exportPrivacyRoute },
|
|
8356
8536
|
{ method: "POST", path: "/admin/privacy/erase", public: false, handler: erasePrivacyRoute },
|
|
@@ -8448,6 +8628,7 @@ function createSchedulingApi(config) {
|
|
|
8448
8628
|
brand: config.host.brand ?? null,
|
|
8449
8629
|
textMessages: config.host.textMessages ?? null,
|
|
8450
8630
|
apiKeys: config.host.apiKeys ?? null,
|
|
8631
|
+
giftCertificates: config.host.giftCertificates ?? null,
|
|
8451
8632
|
icalUidDomain: config.host.icalUidDomain?.bind(config.host) ?? (() => null),
|
|
8452
8633
|
calendarSync: config.host.calendarSync ?? { upsertEvent: async () => ({}), removeEvent: async () => void 0 },
|
|
8453
8634
|
activity: config.host.activity ?? { log: async () => void 0, isOpen: async () => false, resolve: async () => void 0 },
|
|
@@ -8704,8 +8885,8 @@ function readHeader(headers, name) {
|
|
|
8704
8885
|
}
|
|
8705
8886
|
var STOP_WORDS = ["STOP", "STOPALL", "UNSUBSCRIBE", "END", "QUIT"];
|
|
8706
8887
|
var START_WORDS = ["START", "UNSTOP"];
|
|
8707
|
-
function classifyReply(
|
|
8708
|
-
const word =
|
|
8888
|
+
function classifyReply(text2) {
|
|
8889
|
+
const word = text2.trim().toUpperCase().replace(/[.!?,]+$/, "");
|
|
8709
8890
|
return STOP_WORDS.includes(word) ? "opt-out" : START_WORDS.includes(word) ? "opt-in" : "reply";
|
|
8710
8891
|
}
|
|
8711
8892
|
|
|
@@ -8764,12 +8945,12 @@ function createTelnyxSmsAdapter(config) {
|
|
|
8764
8945
|
const id = body?.data?.id;
|
|
8765
8946
|
return id ? { status: "SENT", id } : { status: "SENT" };
|
|
8766
8947
|
}
|
|
8767
|
-
const { code, text } = firstError(body);
|
|
8948
|
+
const { code, text: text2 } = firstError(body);
|
|
8768
8949
|
if (code === OPTED_OUT_CODE) return { status: "SKIPPED", reason: "The recipient opted out of text messages" };
|
|
8769
8950
|
const serverFault = response.status >= 500;
|
|
8770
8951
|
const retryable = response.status === 429 || serverFault;
|
|
8771
8952
|
throw new SmsSendError(
|
|
8772
|
-
`Telnyx refused the message (HTTP ${response.status}${code ? `, code ${code}` : ""}): ${
|
|
8953
|
+
`Telnyx refused the message (HTTP ${response.status}${code ? `, code ${code}` : ""}): ${text2}`,
|
|
8773
8954
|
retryable,
|
|
8774
8955
|
serverFault,
|
|
8775
8956
|
response.status,
|
|
@@ -8815,9 +8996,9 @@ function handleTelnyxWebhook(rawBody, headers, options) {
|
|
|
8815
8996
|
if (eventType === "message.received") {
|
|
8816
8997
|
const from = payload?.from?.phone_number;
|
|
8817
8998
|
if (!id || !from || !to) return { ok: false, status: 400, reason: "The message is missing its id or phone numbers" };
|
|
8818
|
-
const
|
|
8819
|
-
const type = classifyReply(
|
|
8820
|
-
return { ok: true, event: { type, id, from, to, text } };
|
|
8999
|
+
const text2 = typeof payload?.text === "string" ? payload.text : "";
|
|
9000
|
+
const type = classifyReply(text2);
|
|
9001
|
+
return { ok: true, event: { type, id, from, to, text: text2 } };
|
|
8821
9002
|
}
|
|
8822
9003
|
if (eventType === "message.finalized" || eventType === "message.sent") {
|
|
8823
9004
|
if (!id || !to) return { ok: false, status: 400, reason: "The delivery report is missing its id or number" };
|
|
@@ -8902,7 +9083,7 @@ function createTwilioSmsAdapter(config) {
|
|
|
8902
9083
|
var import_node_crypto4 = require("crypto");
|
|
8903
9084
|
function expectedSignature(params, options) {
|
|
8904
9085
|
const keys = [...new Set(params.keys())].sort();
|
|
8905
|
-
const signed = keys.reduce((
|
|
9086
|
+
const signed = keys.reduce((text2, key) => text2 + key + params.getAll(key).join(""), options.url);
|
|
8906
9087
|
return (0, import_node_crypto4.createHmac)("sha1", options.authToken.trim()).update(signed).digest("base64");
|
|
8907
9088
|
}
|
|
8908
9089
|
function verifyTwilioSignature(rawBody, headers, options) {
|
|
@@ -8927,8 +9108,8 @@ function handleTwilioWebhook(rawBody, headers, options) {
|
|
|
8927
9108
|
}
|
|
8928
9109
|
if (params.has("Body")) {
|
|
8929
9110
|
if (!id || !from || !to) return { ok: false, status: 400, reason: "The message is missing its id or phone numbers" };
|
|
8930
|
-
const
|
|
8931
|
-
return { ok: true, event: { type: classifyReply(
|
|
9111
|
+
const text2 = params.get("Body") ?? "";
|
|
9112
|
+
return { ok: true, event: { type: classifyReply(text2), id, from, to, text: text2 } };
|
|
8932
9113
|
}
|
|
8933
9114
|
return { ok: true, event: { type: "ignored", eventType: "unknown" } };
|
|
8934
9115
|
}
|
|
@@ -8974,10 +9155,10 @@ function createPerBusinessSmsAdapter(options) {
|
|
|
8974
9155
|
}
|
|
8975
9156
|
|
|
8976
9157
|
// src/sms/text-settings-resolver.ts
|
|
8977
|
-
var
|
|
9158
|
+
var import_scheduling83 = require("@ordinatio/scheduling");
|
|
8978
9159
|
function createTextSettingsResolver(options) {
|
|
8979
9160
|
return async (organizationId) => {
|
|
8980
|
-
const settings = await (0,
|
|
9161
|
+
const settings = await (0, import_scheduling83.getTextSettings)(await options.db(organizationId), organizationId);
|
|
8981
9162
|
if (!settings || !settings.enabled) return null;
|
|
8982
9163
|
try {
|
|
8983
9164
|
if (settings.provider === "TELNYX" && options.telnyx?.apiKey?.trim()) {
|
|
@@ -9410,6 +9591,9 @@ function createNodeListener(api, options) {
|
|
|
9410
9591
|
CreateServicePackageSchema,
|
|
9411
9592
|
CreateWebhookEndpointSchema,
|
|
9412
9593
|
DEFAULT_CANCELLATION_POLICY,
|
|
9594
|
+
GiftCertificateCheckSchema,
|
|
9595
|
+
GiftCertificateRestoreSchema,
|
|
9596
|
+
GiftCertificateSchema,
|
|
9413
9597
|
IntakeFormFieldSchema,
|
|
9414
9598
|
NoShowPreventionActionSchema,
|
|
9415
9599
|
NotificationChannelSchema,
|