@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/dist/index.mjs CHANGED
@@ -17,6 +17,9 @@ import {
17
17
  CreateServicePackageSchema,
18
18
  CreateWebhookEndpointSchema,
19
19
  DEFAULT_CANCELLATION_POLICY,
20
+ GiftCertificateCheckSchema,
21
+ GiftCertificateRestoreSchema,
22
+ GiftCertificateSchema,
20
23
  IntakeFormFieldSchema,
21
24
  NoShowPreventionActionSchema,
22
25
  NotificationChannelSchema,
@@ -39,7 +42,7 @@ import {
39
42
  UpdatePackagePurchaseSchema,
40
43
  UpdateRoutingFormSchema,
41
44
  UpdateServicePackageSchema
42
- } from "./chunk-X5BVCLX6.mjs";
45
+ } from "./chunk-W3SY2DAU.mjs";
43
46
 
44
47
  // src/create-api.ts
45
48
  import * as engine from "@ordinatio/scheduling";
@@ -6785,11 +6788,157 @@ async function revokeApiKeyRoute(request, { host, params }) {
6785
6788
  }
6786
6789
  }
6787
6790
 
6791
+ // src/handlers/admin-gift-certificates.ts
6792
+ import { issueGiftCertificateOnce, listGiftCertificates } from "@ordinatio/scheduling";
6793
+
6794
+ // src/gift-certificates/gift-http.ts
6795
+ import { SchedulingNotFoundError as SchedulingNotFoundError11, SchedulingValidationError as SchedulingValidationError13 } from "@ordinatio/scheduling";
6796
+ var NOT_ENABLED5 = { error: "Gift certificates are not enabled on this server" };
6797
+ var BAD_REQUEST = /* @__PURE__ */ new Set(["SCHED_1700", "SCHED_1706", "SCHED_1709"]);
6798
+ var CONFLICT = /* @__PURE__ */ new Set(["SCHED_1702", "SCHED_1703", "SCHED_1704", "SCHED_1707", "SCHED_1708", "SCHED_1710"]);
6799
+ var CODE_SHAPE = /\b[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}[- ]?[A-Za-z0-9]{4}\b/g;
6800
+ function safeErrorText(error) {
6801
+ if (!(error instanceof Error)) return "unknown error";
6802
+ const code = error.code;
6803
+ return `${error.name}${typeof code === "string" ? ` ${code}` : ""}: ${error.message.replace(CODE_SHAPE, "[code]").slice(0, 300)}`;
6804
+ }
6805
+ function forCaller(staff, certificate) {
6806
+ if (!staff.role.startsWith(API_KEY_ROLE_PREFIX) || staff.role === `${API_KEY_ROLE_PREFIX}FULL`) return certificate;
6807
+ return { ...certificate, code: `\u2026${certificate.code.slice(-4)}`, codeHidden: true };
6808
+ }
6809
+ function noStoreJson(body, init = {}) {
6810
+ return Response.json(body, { status: init.status ?? 200, headers: { "Cache-Control": "no-store" } });
6811
+ }
6812
+ function giftFailure(error, fallback) {
6813
+ if (error instanceof SchedulingNotFoundError11) return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error) }, { status: 404 });
6814
+ if (error instanceof SchedulingValidationError13) {
6815
+ const status = BAD_REQUEST.has(error.code) ? 400 : CONFLICT.has(error.code) ? 409 : 500;
6816
+ if (status !== 500) {
6817
+ const details = error.context?.errors;
6818
+ return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status });
6819
+ }
6820
+ }
6821
+ console.error("[gift-certificates]", safeErrorText(error));
6822
+ return Response.json({ error: fallback }, { status: 500 });
6823
+ }
6824
+ async function recordGiftActivity(host, staff, entry) {
6825
+ await host.activity.log(staff.db, entry).catch((error) => {
6826
+ console.error("[gift-certificates] could not record the activity", safeErrorText(error));
6827
+ });
6828
+ }
6829
+ async function requireGiftAdmin(host, request, options) {
6830
+ const staff = await requireAdminStaff(host, request, options);
6831
+ if (staff instanceof Response) return staff;
6832
+ if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501 });
6833
+ return staff;
6834
+ }
6835
+
6836
+ // src/handlers/admin-gift-certificates.ts
6837
+ async function listGiftCertificatesRoute(request, { host }) {
6838
+ try {
6839
+ const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-list", tier: "GENERAL" });
6840
+ if (staff instanceof Response) return staff;
6841
+ const params = new URL(request.url).searchParams;
6842
+ const status = params.get("status");
6843
+ if (status !== null && status !== "ACTIVE" && status !== "VOID") return Response.json({ error: "status must be ACTIVE or VOID" }, { status: 400 });
6844
+ const limit = params.get("limit");
6845
+ const certificates = await listGiftCertificates(staff.db, staff.organizationId, { ...status ? { status } : {}, ...limit ? { limit: Number(limit) } : {} });
6846
+ return noStoreJson({ certificates: certificates.map((certificate) => forCaller(staff, certificate)) });
6847
+ } catch (error) {
6848
+ return giftFailure(error, "Failed to list the gift certificates");
6849
+ }
6850
+ }
6851
+ async function issueGiftCertificateRoute(request, { host }) {
6852
+ try {
6853
+ const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificates-issue", tier: "CREATE" });
6854
+ if (staff instanceof Response) return staff;
6855
+ const validation = await parseBody(request, GiftCertificateSchema);
6856
+ if (!validation.success) return validation.response;
6857
+ const { certificate, created } = await issueGiftCertificateOnce(staff.db, staff.organizationId, validation.data, staff.userId);
6858
+ if (!created) return noStoreJson({ certificate: forCaller(staff, certificate) });
6859
+ await recordGiftActivity(host, staff, {
6860
+ action: "scheduling.gift_certificate_issued",
6861
+ description: "issued a gift certificate",
6862
+ metadata: { certificateId: certificate.id, amountCents: certificate.initialCents, currency: certificate.currency }
6863
+ });
6864
+ return noStoreJson({ certificate: forCaller(staff, certificate) }, { status: 201 });
6865
+ } catch (error) {
6866
+ return giftFailure(error, "Failed to issue the gift certificate");
6867
+ }
6868
+ }
6869
+
6870
+ // src/handlers/admin-gift-certificate-detail.ts
6871
+ import { getGiftCertificate, restoreGiftCertificate, voidGiftCertificate } from "@ordinatio/scheduling";
6872
+ async function getGiftCertificateRoute(request, { host, params }) {
6873
+ try {
6874
+ const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-get", tier: "GENERAL" });
6875
+ if (staff instanceof Response) return staff;
6876
+ const found = await getGiftCertificate(staff.db, staff.organizationId, params.id);
6877
+ return noStoreJson({ ...found, certificate: forCaller(staff, found.certificate) });
6878
+ } catch (error) {
6879
+ return giftFailure(error, "Failed to read the gift certificate");
6880
+ }
6881
+ }
6882
+ async function voidGiftCertificateRoute(request, { host, params }) {
6883
+ try {
6884
+ const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-void", tier: "DELETE" });
6885
+ if (staff instanceof Response) return staff;
6886
+ const voided = await voidGiftCertificate(staff.db, staff.organizationId, params.id, staff.userId);
6887
+ if (!voided) return Response.json({ error: "Gift certificate not found, or already void" }, { status: 404 });
6888
+ await recordGiftActivity(host, staff, { action: "scheduling.gift_certificate_voided", description: "voided a gift certificate", metadata: { certificateId: params.id } });
6889
+ return noStoreJson({ voided: true });
6890
+ } catch (error) {
6891
+ return giftFailure(error, "Failed to void the gift certificate");
6892
+ }
6893
+ }
6894
+ async function restoreGiftCertificateRoute(request, { host, params }) {
6895
+ try {
6896
+ const staff = await requireGiftAdmin(host, request, { action: "admin-gift-certificate-restore", tier: "UPDATE" });
6897
+ if (staff instanceof Response) return staff;
6898
+ const validation = await parseBody(request, GiftCertificateRestoreSchema);
6899
+ if (!validation.success) return validation.response;
6900
+ const restored = await restoreGiftCertificate(staff.db, staff.organizationId, params.id, validation.data, staff.userId);
6901
+ await recordGiftActivity(host, staff, {
6902
+ action: "scheduling.gift_certificate_restored",
6903
+ description: "gave value back to a gift certificate",
6904
+ metadata: { certificateId: params.id, amountCents: restored.restoredCents, ...validation.data.appointmentId ? { appointmentId: validation.data.appointmentId } : {} }
6905
+ });
6906
+ return noStoreJson({ restored });
6907
+ } catch (error) {
6908
+ return giftFailure(error, "Failed to give value back to the gift certificate");
6909
+ }
6910
+ }
6911
+
6912
+ // src/handlers/gift-certificates-check.ts
6913
+ import { checkGiftCertificate, schedError as schedError28 } from "@ordinatio/scheduling";
6914
+ async function checkGiftCertificateRoute(request, { host }) {
6915
+ const cors = host.cors(request);
6916
+ const headers = { ...cors, "Cache-Control": "no-store" };
6917
+ if (!host.giftCertificates) return Response.json(NOT_ENABLED5, { status: 501, headers });
6918
+ const limited = await host.rateLimit(`gift-check:${clientAddress(request)}`, "PUBLIC_BOOKING");
6919
+ if (limited) return limited;
6920
+ const parsed = validateData(await request.json().catch(() => null), GiftCertificateCheckSchema);
6921
+ if (!parsed.success) return Response.json({ error: "Validation failed" }, { status: 400, headers });
6922
+ const { code, calendarId } = parsed.data;
6923
+ try {
6924
+ const db = await host.publicDb();
6925
+ const calendar = await db.schedulingCalendar.findUnique({ where: { id: calendarId }, select: { organizationId: true } });
6926
+ const found = calendar?.organizationId ? await checkGiftCertificate(db, calendar.organizationId, code) : null;
6927
+ if (!found) return Response.json({ valid: false, reason: "not_found" }, { headers });
6928
+ if (found.state !== "ACTIVE") return Response.json({ valid: false, reason: found.state.toLowerCase() }, { headers });
6929
+ return Response.json({ valid: true, balanceCents: found.balanceCents, currency: found.currency, expiresAt: found.expiresAt }, { headers });
6930
+ } catch (error) {
6931
+ const err = schedError28("SCHED_408", { calendarId, error: safeErrorText(error) });
6932
+ console.error(`[${err.ref}] gift certificate check failed:`, safeErrorText(error));
6933
+ return Response.json({ valid: false, reason: "error", error: err.description, ref: err.ref }, { status: 500, headers });
6934
+ }
6935
+ }
6936
+
6788
6937
  // src/handlers/admin-text-settings.ts
6789
- import { deleteTextSettings, getTextSettings, saveTextSettings, SchedulingValidationError as SchedulingValidationError13 } from "@ordinatio/scheduling";
6790
- var NOT_ENABLED5 = { error: "Text-message settings are not enabled on this server" };
6938
+ import { deleteTextSettings, getTextSettings, saveTextSettings, SchedulingValidationError as SchedulingValidationError14 } from "@ordinatio/scheduling";
6939
+ var NOT_ENABLED6 = { error: "Text-message settings are not enabled on this server" };
6791
6940
  function failure4(error, fallback) {
6792
- if (error instanceof SchedulingValidationError13) {
6941
+ if (error instanceof SchedulingValidationError14) {
6793
6942
  const details = error.context.errors;
6794
6943
  return Response.json({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, { status: 400 });
6795
6944
  }
@@ -6799,7 +6948,7 @@ function failure4(error, fallback) {
6799
6948
  async function requireTextAdmin(host, request, options) {
6800
6949
  const staff = await requireAdminStaff(host, request, options);
6801
6950
  if (staff instanceof Response) return staff;
6802
- if (!host.textMessages) return Response.json(NOT_ENABLED5, { status: 501 });
6951
+ if (!host.textMessages) return Response.json(NOT_ENABLED6, { status: 501 });
6803
6952
  return staff;
6804
6953
  }
6805
6954
  async function getTextSettingsRoute(request, { host }) {
@@ -6912,11 +7061,11 @@ async function checkSendingDomainRoute(request, { host }) {
6912
7061
  import { eraseSubject, exportSubject, listPrivacyRequests, previewErase } from "@ordinatio/scheduling";
6913
7062
 
6914
7063
  // src/privacy/privacy-http.ts
6915
- import { SchedulingValidationError as SchedulingValidationError14 } from "@ordinatio/scheduling";
6916
- var NOT_ENABLED6 = { error: "Data export and erasure are not enabled on this server" };
7064
+ import { SchedulingValidationError as SchedulingValidationError15 } from "@ordinatio/scheduling";
7065
+ var NOT_ENABLED7 = { error: "Data export and erasure are not enabled on this server" };
6917
7066
  var STATUS_BY_CODE3 = { SCHED_1300: 400, SCHED_1301: 409 };
6918
7067
  function privacyErrorResponse(error, fallback) {
6919
- if (error instanceof SchedulingValidationError14) {
7068
+ if (error instanceof SchedulingValidationError15) {
6920
7069
  return Response.json(
6921
7070
  { error: error.message, code: error.code, ref: getErrorRef(error), details: error.context },
6922
7071
  { status: STATUS_BY_CODE3[error.code] ?? 400 }
@@ -6928,7 +7077,7 @@ function privacyErrorResponse(error, fallback) {
6928
7077
  async function requirePrivacyAdmin(host, request, options) {
6929
7078
  const staff = await requireAdminStaff(host, request, options);
6930
7079
  if (staff instanceof Response) return staff;
6931
- if (!host.privacy) return Response.json(NOT_ENABLED6, { status: 501 });
7080
+ if (!host.privacy) return Response.json(NOT_ENABLED7, { status: 501 });
6932
7081
  return staff;
6933
7082
  }
6934
7083
 
@@ -7051,7 +7200,7 @@ async function testRoutingFormRoute(request, { host, params }) {
7051
7200
  }
7052
7201
 
7053
7202
  // src/handlers/appointments-list.ts
7054
- import { schedError as schedError28, withOrganization } from "@ordinatio/scheduling";
7203
+ import { schedError as schedError29, withOrganization } from "@ordinatio/scheduling";
7055
7204
  var DEFAULT_LIMIT2 = 50;
7056
7205
  var MAX_LIMIT2 = 500;
7057
7206
  async function listAppointments(request, { host }) {
@@ -7063,7 +7212,7 @@ async function listAppointments(request, { host }) {
7063
7212
  const clientId = params.get("clientId") || void 0;
7064
7213
  const status = params.get("status") || void 0;
7065
7214
  if (!clientId && !staff.isAdmin) {
7066
- const err = schedError28("SCHED_900", { role: staff.role });
7215
+ const err = schedError29("SCHED_900", { role: staff.role });
7067
7216
  return Response.json({ error: "Forbidden", ref: err.ref }, { status: 403 });
7068
7217
  }
7069
7218
  const startDate = params.get("startDate");
@@ -7348,7 +7497,7 @@ async function getTeamAvailability(request, { host }) {
7348
7497
  }
7349
7498
 
7350
7499
  // src/handlers/appointment-types.ts
7351
- import { schedError as schedError29 } from "@ordinatio/scheduling";
7500
+ import { schedError as schedError30 } from "@ordinatio/scheduling";
7352
7501
 
7353
7502
  // src/loaders/types-by-calendar.ts
7354
7503
  function loadTypesByCalendarSlug(cache, db, organizationId, calendarSlug) {
@@ -7422,7 +7571,7 @@ async function getAppointmentTypes(request, { host }) {
7422
7571
  }));
7423
7572
  return corsJson(cors, response, { headers: WIDGET_CACHE_HEADERS });
7424
7573
  } catch (error) {
7425
- const diagnostic = schedError29("SCHED_202", { error });
7574
+ const diagnostic = schedError30("SCHED_202", { error });
7426
7575
  console.error("[appointment-types]", diagnostic.ref, error);
7427
7576
  return corsJson(cors, { error: "Failed to fetch appointment types", ref: diagnostic.ref }, { status: 500 });
7428
7577
  }
@@ -7430,7 +7579,7 @@ async function getAppointmentTypes(request, { host }) {
7430
7579
 
7431
7580
  // src/handlers/coupons-validate.ts
7432
7581
  import { z as z10 } from "zod";
7433
- import { schedError as schedError30 } from "@ordinatio/scheduling";
7582
+ import { schedError as schedError31 } from "@ordinatio/scheduling";
7434
7583
  var Schema4 = z10.object({
7435
7584
  code: z10.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
7436
7585
  calendarId: z10.string().min(1),
@@ -7492,7 +7641,7 @@ async function validateCoupon(request, { host }) {
7492
7641
  { headers: host.cors(request) }
7493
7642
  );
7494
7643
  } catch (error) {
7495
- const err = schedError30("SCHED_408", {
7644
+ const err = schedError31("SCHED_408", {
7496
7645
  calendarId,
7497
7646
  error: error instanceof Error ? error.message : String(error)
7498
7647
  });
@@ -7572,7 +7721,7 @@ async function listActiveCalendars(request, { host }) {
7572
7721
  }
7573
7722
 
7574
7723
  // src/handlers/type.ts
7575
- import { schedError as schedError31 } from "@ordinatio/scheduling";
7724
+ import { schedError as schedError32 } from "@ordinatio/scheduling";
7576
7725
 
7577
7726
  // src/loaders/type-by-slug.ts
7578
7727
  function loadTypeBySlug(cache, db, organizationId, slug) {
@@ -7677,14 +7826,14 @@ async function getType(request, { host }) {
7677
7826
  { headers: WIDGET_CACHE_HEADERS }
7678
7827
  );
7679
7828
  } catch (error) {
7680
- const diagnostic = schedError31("SCHED_207", { error });
7829
+ const diagnostic = schedError32("SCHED_207", { error });
7681
7830
  console.error("[type]", diagnostic.ref, error);
7682
7831
  return corsJson(cors, { error: "Failed to fetch appointment type", ref: diagnostic.ref }, { status: 500 });
7683
7832
  }
7684
7833
  }
7685
7834
 
7686
7835
  // src/handlers/widget-init.ts
7687
- import { schedError as schedError32 } from "@ordinatio/scheduling";
7836
+ import { schedError as schedError33 } from "@ordinatio/scheduling";
7688
7837
 
7689
7838
  // src/loaders/widget-data.ts
7690
7839
  function loadWidgetData(cache, db, organizationId, calendarSlug) {
@@ -7773,7 +7922,7 @@ async function getWidgetInit(request, { host }) {
7773
7922
  }));
7774
7923
  return corsJson(cors, { calendar, types: sanitizedTypes }, { headers: WIDGET_CACHE_HEADERS });
7775
7924
  } catch (error) {
7776
- const diagnostic = schedError32("SCHED_206", { error });
7925
+ const diagnostic = schedError33("SCHED_206", { error });
7777
7926
  console.error("[widget-init]", diagnostic.ref, error);
7778
7927
  return corsJson(cors, { error: "Failed to load widget data", ref: diagnostic.ref }, { status: 500 });
7779
7928
  }
@@ -7782,6 +7931,7 @@ async function getWidgetInit(request, { host }) {
7782
7931
  // src/routes.ts
7783
7932
  var ROUTES = [
7784
7933
  { method: "POST", path: "/coupons/validate", public: true, handler: validateCoupon },
7934
+ { method: "POST", path: "/gift-certificates/check", public: true, handler: checkGiftCertificateRoute },
7785
7935
  { method: "POST", path: "/payments/intent", public: true, handler: createPaymentIntentRoute },
7786
7936
  { method: "GET", path: "/widget-init", public: true, handler: getWidgetInit },
7787
7937
  { method: "GET", path: "/type", public: true, handler: getType },
@@ -7854,6 +8004,11 @@ var ROUTES = [
7854
8004
  { method: "GET", path: "/admin/api-keys", public: false, handler: listApiKeysRoute },
7855
8005
  { method: "POST", path: "/admin/api-keys", public: false, handler: createApiKeyRoute },
7856
8006
  { method: "DELETE", path: "/admin/api-keys/[id]", public: false, handler: revokeApiKeyRoute },
8007
+ { method: "GET", path: "/admin/gift-certificates", public: false, handler: listGiftCertificatesRoute },
8008
+ { method: "POST", path: "/admin/gift-certificates", public: false, handler: issueGiftCertificateRoute },
8009
+ { method: "GET", path: "/admin/gift-certificates/[id]", public: false, handler: getGiftCertificateRoute },
8010
+ { method: "POST", path: "/admin/gift-certificates/[id]/void", public: false, handler: voidGiftCertificateRoute },
8011
+ { method: "POST", path: "/admin/gift-certificates/[id]/restore", public: false, handler: restoreGiftCertificateRoute },
7857
8012
  { method: "GET", path: "/admin/brand/sending-domain", public: false, handler: checkSendingDomainRoute },
7858
8013
  { method: "POST", path: "/admin/privacy/export", public: false, handler: exportPrivacyRoute },
7859
8014
  { method: "POST", path: "/admin/privacy/erase", public: false, handler: erasePrivacyRoute },
@@ -7951,6 +8106,7 @@ function createSchedulingApi(config) {
7951
8106
  brand: config.host.brand ?? null,
7952
8107
  textMessages: config.host.textMessages ?? null,
7953
8108
  apiKeys: config.host.apiKeys ?? null,
8109
+ giftCertificates: config.host.giftCertificates ?? null,
7954
8110
  icalUidDomain: config.host.icalUidDomain?.bind(config.host) ?? (() => null),
7955
8111
  calendarSync: config.host.calendarSync ?? { upsertEvent: async () => ({}), removeEvent: async () => void 0 },
7956
8112
  activity: config.host.activity ?? { log: async () => void 0, isOpen: async () => false, resolve: async () => void 0 },
@@ -8912,6 +9068,9 @@ export {
8912
9068
  CreateServicePackageSchema,
8913
9069
  CreateWebhookEndpointSchema,
8914
9070
  DEFAULT_CANCELLATION_POLICY,
9071
+ GiftCertificateCheckSchema,
9072
+ GiftCertificateRestoreSchema,
9073
+ GiftCertificateSchema,
8915
9074
  IntakeFormFieldSchema,
8916
9075
  NoShowPreventionActionSchema,
8917
9076
  NotificationChannelSchema,
@@ -324,6 +324,11 @@ interface ApiKeySettings {
324
324
  */
325
325
  db(): Promise<SchedulingDb>;
326
326
  }
327
+ /**
328
+ * Switches gift certificates on. A host that supplies none has them off: the routes answer 501. Needs the
329
+ * GiftCertificate and GiftCertificateTransaction tables from @ordinatio/scheduling 0.8.0.
330
+ */
331
+ type GiftCertificateSettings = Record<string, never>;
327
332
  /** Switches data export and erasure on. A host that supplies none has them off: the routes answer 501. */
328
333
  type PrivacySettings = Record<string, never>;
329
334
  interface SchedulingHost {
@@ -390,6 +395,8 @@ interface SchedulingHost {
390
395
  * Turns on API keys for outside tools. Needs the API key table. Default: off, so a Bearer key is ignored and the key routes answer 501.
391
396
  */
392
397
  apiKeys?: ApiKeySettings | null;
398
+ /** Turns gift certificates on. Needs their two tables. Default: off, so the gift certificate routes answer 501. */
399
+ giftCertificates?: GiftCertificateSettings | null;
393
400
  /** The domain used after the "@" in calendar-file event ids. Keep it unchanged once calendars have subscribed. Default: ordinatio-scheduling. */
394
401
  icalUidDomain?(): string | null | undefined;
395
402
  /** Records what happened in the activity feed. Default: nothing is recorded. */
@@ -324,6 +324,11 @@ interface ApiKeySettings {
324
324
  */
325
325
  db(): Promise<SchedulingDb>;
326
326
  }
327
+ /**
328
+ * Switches gift certificates on. A host that supplies none has them off: the routes answer 501. Needs the
329
+ * GiftCertificate and GiftCertificateTransaction tables from @ordinatio/scheduling 0.8.0.
330
+ */
331
+ type GiftCertificateSettings = Record<string, never>;
327
332
  /** Switches data export and erasure on. A host that supplies none has them off: the routes answer 501. */
328
333
  type PrivacySettings = Record<string, never>;
329
334
  interface SchedulingHost {
@@ -390,6 +395,8 @@ interface SchedulingHost {
390
395
  * Turns on API keys for outside tools. Needs the API key table. Default: off, so a Bearer key is ignored and the key routes answer 501.
391
396
  */
392
397
  apiKeys?: ApiKeySettings | null;
398
+ /** Turns gift certificates on. Needs their two tables. Default: off, so the gift certificate routes answer 501. */
399
+ giftCertificates?: GiftCertificateSettings | null;
393
400
  /** The domain used after the "@" in calendar-file event ids. Keep it unchanged once calendars have subscribed. Default: ordinatio-scheduling. */
394
401
  icalUidDomain?(): string | null | undefined;
395
402
  /** Records what happened in the activity feed. Default: nothing is recorded. */
@@ -526,4 +526,27 @@ declare const ApiKeySchema: z.ZodObject<{
526
526
  access: z.ZodString;
527
527
  }, z.core.$strict>;
528
528
 
529
- export { ApiKeySchema, type BookingPageConfig, BookingPageConfigSchema, type BookingPageTheme, BookingPageThemeSchema, BrandSchema, CancelRecurringScopeSchema, type CancelRecurringSeriesInput, CancelRecurringSeriesSchema, type CreateAppointmentCategoryInput, CreateAppointmentCategorySchema, type CreateAppointmentTypeInput, CreateAppointmentTypeSchema, type CreateAvailabilityRuleInput, CreateAvailabilityRuleSchema, type CreateCalendarInput, CreateCalendarSchema, type CreateCouponCodeInput, CreateCouponCodeSchema, type CreateNotificationTemplateInput, CreateNotificationTemplateSchema, type CreatePackagePurchaseInput, CreatePackagePurchaseSchema, type CreateRecurringSeriesInput, CreateRecurringSeriesSchema, type CreateRoutingFormInput, CreateRoutingFormSchema, type CreateServicePackageInput, CreateServicePackageSchema, type CreateWebhookEndpointInput, CreateWebhookEndpointSchema, DEFAULT_CANCELLATION_POLICY, IntakeFormFieldSchema, type NoShowPrevention, type NoShowPreventionAction, NoShowPreventionActionSchema, NotificationChannelSchema, NotificationTriggerSchema, type OrgCancellationPolicy, OrgCancellationPolicySchema, PrivacyEraseSchema, PrivacySubjectSchema, RecurringFrequencySchema, RouteClientSchema, SLOT_GRANULARITY_DEFAULT, SLOT_GRANULARITY_OPTIONS, type SlotGranularityMinutes, TestRoutingFormSchema, TextSettingsSchema, type UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, type UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, type UpdateBookingPageInput, UpdateBookingPageSchema, type UpdateCalendarInput, UpdateCalendarSchema, type UpdateCouponCodeInput, UpdateCouponCodeSchema, type UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, type UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, type UpdateRoutingFormInput, UpdateRoutingFormSchema, type UpdateServicePackageInput, UpdateServicePackageSchema };
529
+ declare const GiftCertificateSchema: z.ZodObject<{
530
+ amountCents: z.ZodNumber;
531
+ currency: z.ZodOptional<z.ZodString>;
532
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
533
+ recipientName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
534
+ recipientEmail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
535
+ purchaserName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
536
+ purchaserEmail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
537
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
538
+ paymentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
539
+ notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
540
+ }, z.core.$strict>;
541
+ declare const GiftCertificateRestoreSchema: z.ZodObject<{
542
+ amountCents: z.ZodNumber;
543
+ appointmentId: z.ZodOptional<z.ZodString>;
544
+ note: z.ZodOptional<z.ZodString>;
545
+ }, z.core.$strict>;
546
+ /** A visitor's balance check. The calendar says which business's certificates to look in. */
547
+ declare const GiftCertificateCheckSchema: z.ZodObject<{
548
+ code: z.ZodString;
549
+ calendarId: z.ZodString;
550
+ }, z.core.$strict>;
551
+
552
+ export { ApiKeySchema, type BookingPageConfig, BookingPageConfigSchema, type BookingPageTheme, BookingPageThemeSchema, BrandSchema, CancelRecurringScopeSchema, type CancelRecurringSeriesInput, CancelRecurringSeriesSchema, type CreateAppointmentCategoryInput, CreateAppointmentCategorySchema, type CreateAppointmentTypeInput, CreateAppointmentTypeSchema, type CreateAvailabilityRuleInput, CreateAvailabilityRuleSchema, type CreateCalendarInput, CreateCalendarSchema, type CreateCouponCodeInput, CreateCouponCodeSchema, type CreateNotificationTemplateInput, CreateNotificationTemplateSchema, type CreatePackagePurchaseInput, CreatePackagePurchaseSchema, type CreateRecurringSeriesInput, CreateRecurringSeriesSchema, type CreateRoutingFormInput, CreateRoutingFormSchema, type CreateServicePackageInput, CreateServicePackageSchema, type CreateWebhookEndpointInput, CreateWebhookEndpointSchema, DEFAULT_CANCELLATION_POLICY, GiftCertificateCheckSchema, GiftCertificateRestoreSchema, GiftCertificateSchema, IntakeFormFieldSchema, type NoShowPrevention, type NoShowPreventionAction, NoShowPreventionActionSchema, NotificationChannelSchema, NotificationTriggerSchema, type OrgCancellationPolicy, OrgCancellationPolicySchema, PrivacyEraseSchema, PrivacySubjectSchema, RecurringFrequencySchema, RouteClientSchema, SLOT_GRANULARITY_DEFAULT, SLOT_GRANULARITY_OPTIONS, type SlotGranularityMinutes, TestRoutingFormSchema, TextSettingsSchema, type UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, type UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, type UpdateBookingPageInput, UpdateBookingPageSchema, type UpdateCalendarInput, UpdateCalendarSchema, type UpdateCouponCodeInput, UpdateCouponCodeSchema, type UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, type UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, type UpdateRoutingFormInput, UpdateRoutingFormSchema, type UpdateServicePackageInput, UpdateServicePackageSchema };
@@ -526,4 +526,27 @@ declare const ApiKeySchema: z.ZodObject<{
526
526
  access: z.ZodString;
527
527
  }, z.core.$strict>;
528
528
 
529
- export { ApiKeySchema, type BookingPageConfig, BookingPageConfigSchema, type BookingPageTheme, BookingPageThemeSchema, BrandSchema, CancelRecurringScopeSchema, type CancelRecurringSeriesInput, CancelRecurringSeriesSchema, type CreateAppointmentCategoryInput, CreateAppointmentCategorySchema, type CreateAppointmentTypeInput, CreateAppointmentTypeSchema, type CreateAvailabilityRuleInput, CreateAvailabilityRuleSchema, type CreateCalendarInput, CreateCalendarSchema, type CreateCouponCodeInput, CreateCouponCodeSchema, type CreateNotificationTemplateInput, CreateNotificationTemplateSchema, type CreatePackagePurchaseInput, CreatePackagePurchaseSchema, type CreateRecurringSeriesInput, CreateRecurringSeriesSchema, type CreateRoutingFormInput, CreateRoutingFormSchema, type CreateServicePackageInput, CreateServicePackageSchema, type CreateWebhookEndpointInput, CreateWebhookEndpointSchema, DEFAULT_CANCELLATION_POLICY, IntakeFormFieldSchema, type NoShowPrevention, type NoShowPreventionAction, NoShowPreventionActionSchema, NotificationChannelSchema, NotificationTriggerSchema, type OrgCancellationPolicy, OrgCancellationPolicySchema, PrivacyEraseSchema, PrivacySubjectSchema, RecurringFrequencySchema, RouteClientSchema, SLOT_GRANULARITY_DEFAULT, SLOT_GRANULARITY_OPTIONS, type SlotGranularityMinutes, TestRoutingFormSchema, TextSettingsSchema, type UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, type UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, type UpdateBookingPageInput, UpdateBookingPageSchema, type UpdateCalendarInput, UpdateCalendarSchema, type UpdateCouponCodeInput, UpdateCouponCodeSchema, type UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, type UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, type UpdateRoutingFormInput, UpdateRoutingFormSchema, type UpdateServicePackageInput, UpdateServicePackageSchema };
529
+ declare const GiftCertificateSchema: z.ZodObject<{
530
+ amountCents: z.ZodNumber;
531
+ currency: z.ZodOptional<z.ZodString>;
532
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
533
+ recipientName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
534
+ recipientEmail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
535
+ purchaserName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
536
+ purchaserEmail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
537
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
538
+ paymentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
539
+ notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
540
+ }, z.core.$strict>;
541
+ declare const GiftCertificateRestoreSchema: z.ZodObject<{
542
+ amountCents: z.ZodNumber;
543
+ appointmentId: z.ZodOptional<z.ZodString>;
544
+ note: z.ZodOptional<z.ZodString>;
545
+ }, z.core.$strict>;
546
+ /** A visitor's balance check. The calendar says which business's certificates to look in. */
547
+ declare const GiftCertificateCheckSchema: z.ZodObject<{
548
+ code: z.ZodString;
549
+ calendarId: z.ZodString;
550
+ }, z.core.$strict>;
551
+
552
+ export { ApiKeySchema, type BookingPageConfig, BookingPageConfigSchema, type BookingPageTheme, BookingPageThemeSchema, BrandSchema, CancelRecurringScopeSchema, type CancelRecurringSeriesInput, CancelRecurringSeriesSchema, type CreateAppointmentCategoryInput, CreateAppointmentCategorySchema, type CreateAppointmentTypeInput, CreateAppointmentTypeSchema, type CreateAvailabilityRuleInput, CreateAvailabilityRuleSchema, type CreateCalendarInput, CreateCalendarSchema, type CreateCouponCodeInput, CreateCouponCodeSchema, type CreateNotificationTemplateInput, CreateNotificationTemplateSchema, type CreatePackagePurchaseInput, CreatePackagePurchaseSchema, type CreateRecurringSeriesInput, CreateRecurringSeriesSchema, type CreateRoutingFormInput, CreateRoutingFormSchema, type CreateServicePackageInput, CreateServicePackageSchema, type CreateWebhookEndpointInput, CreateWebhookEndpointSchema, DEFAULT_CANCELLATION_POLICY, GiftCertificateCheckSchema, GiftCertificateRestoreSchema, GiftCertificateSchema, IntakeFormFieldSchema, type NoShowPrevention, type NoShowPreventionAction, NoShowPreventionActionSchema, NotificationChannelSchema, NotificationTriggerSchema, type OrgCancellationPolicy, OrgCancellationPolicySchema, PrivacyEraseSchema, PrivacySubjectSchema, RecurringFrequencySchema, RouteClientSchema, SLOT_GRANULARITY_DEFAULT, SLOT_GRANULARITY_OPTIONS, type SlotGranularityMinutes, TestRoutingFormSchema, TextSettingsSchema, type UpdateAppointmentCategoryInput, UpdateAppointmentCategorySchema, type UpdateAppointmentTypeInput, UpdateAppointmentTypeSchema, type UpdateBookingPageInput, UpdateBookingPageSchema, type UpdateCalendarInput, UpdateCalendarSchema, type UpdateCouponCodeInput, UpdateCouponCodeSchema, type UpdateNotificationTemplateInput, UpdateNotificationTemplateSchema, type UpdatePackagePurchaseInput, UpdatePackagePurchaseSchema, type UpdateRoutingFormInput, UpdateRoutingFormSchema, type UpdateServicePackageInput, UpdateServicePackageSchema };
@@ -38,6 +38,9 @@ __export(schemas_exports, {
38
38
  CreateServicePackageSchema: () => CreateServicePackageSchema,
39
39
  CreateWebhookEndpointSchema: () => CreateWebhookEndpointSchema,
40
40
  DEFAULT_CANCELLATION_POLICY: () => DEFAULT_CANCELLATION_POLICY,
41
+ GiftCertificateCheckSchema: () => GiftCertificateCheckSchema,
42
+ GiftCertificateRestoreSchema: () => GiftCertificateRestoreSchema,
43
+ GiftCertificateSchema: () => GiftCertificateSchema,
41
44
  IntakeFormFieldSchema: () => IntakeFormFieldSchema,
42
45
  NoShowPreventionActionSchema: () => NoShowPreventionActionSchema,
43
46
  NotificationChannelSchema: () => NotificationChannelSchema,
@@ -508,6 +511,31 @@ var ApiKeySchema = import_zod10.z.object({
508
511
  name: import_zod10.z.string().max(200),
509
512
  access: import_zod10.z.string().max(20)
510
513
  }).strict();
514
+
515
+ // src/schemas/gift-certificate.schema.ts
516
+ var import_zod11 = require("zod");
517
+ var text = (max) => import_zod11.z.string().max(max).nullable().optional();
518
+ var GiftCertificateSchema = import_zod11.z.object({
519
+ amountCents: import_zod11.z.number(),
520
+ currency: import_zod11.z.string().max(10).optional(),
521
+ expiresAt: import_zod11.z.string().max(40).nullable().optional(),
522
+ recipientName: text(300),
523
+ recipientEmail: text(300),
524
+ purchaserName: text(300),
525
+ purchaserEmail: text(300),
526
+ message: text(1e3),
527
+ paymentId: text(300),
528
+ notes: text(2e3)
529
+ }).strict();
530
+ var GiftCertificateRestoreSchema = import_zod11.z.object({
531
+ amountCents: import_zod11.z.number(),
532
+ appointmentId: import_zod11.z.string().max(200).optional(),
533
+ note: import_zod11.z.string().max(1e3).optional()
534
+ }).strict();
535
+ var GiftCertificateCheckSchema = import_zod11.z.object({
536
+ code: import_zod11.z.string().max(64),
537
+ calendarId: import_zod11.z.string().min(1).max(200)
538
+ }).strict();
511
539
  // Annotate the CommonJS export names for ESM import in node:
512
540
  0 && (module.exports = {
513
541
  ApiKeySchema,
@@ -528,6 +556,9 @@ var ApiKeySchema = import_zod10.z.object({
528
556
  CreateServicePackageSchema,
529
557
  CreateWebhookEndpointSchema,
530
558
  DEFAULT_CANCELLATION_POLICY,
559
+ GiftCertificateCheckSchema,
560
+ GiftCertificateRestoreSchema,
561
+ GiftCertificateSchema,
531
562
  IntakeFormFieldSchema,
532
563
  NoShowPreventionActionSchema,
533
564
  NotificationChannelSchema,
@@ -17,6 +17,9 @@ import {
17
17
  CreateServicePackageSchema,
18
18
  CreateWebhookEndpointSchema,
19
19
  DEFAULT_CANCELLATION_POLICY,
20
+ GiftCertificateCheckSchema,
21
+ GiftCertificateRestoreSchema,
22
+ GiftCertificateSchema,
20
23
  IntakeFormFieldSchema,
21
24
  NoShowPreventionActionSchema,
22
25
  NotificationChannelSchema,
@@ -39,7 +42,7 @@ import {
39
42
  UpdatePackagePurchaseSchema,
40
43
  UpdateRoutingFormSchema,
41
44
  UpdateServicePackageSchema
42
- } from "../chunk-X5BVCLX6.mjs";
45
+ } from "../chunk-W3SY2DAU.mjs";
43
46
  export {
44
47
  ApiKeySchema,
45
48
  BookingPageConfigSchema,
@@ -59,6 +62,9 @@ export {
59
62
  CreateServicePackageSchema,
60
63
  CreateWebhookEndpointSchema,
61
64
  DEFAULT_CANCELLATION_POLICY,
65
+ GiftCertificateCheckSchema,
66
+ GiftCertificateRestoreSchema,
67
+ GiftCertificateSchema,
62
68
  IntakeFormFieldSchema,
63
69
  NoShowPreventionActionSchema,
64
70
  NotificationChannelSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordinatio/scheduling-api",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "description": "HTTP API for @ordinatio/scheduling. Every handler takes a Request and returns a Response.",
6
6
  "main": "./dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "sanitize-html": "^2.16.0"
12
12
  },
13
13
  "peerDependencies": {
14
- "@ordinatio/scheduling": "^0.7.0"
14
+ "@ordinatio/scheduling": "^0.8.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/sanitize-html": "^2.13.0",
@@ -19,7 +19,7 @@
19
19
  "tsup": "^8.0.0",
20
20
  "typescript": "5",
21
21
  "vitest": "4.0.18",
22
- "@ordinatio/scheduling": "0.7.0"
22
+ "@ordinatio/scheduling": "0.8.0"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=22.0.0"