Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c89c2fd6b4 | |||
| 203b600713 | |||
| b230e015c2 | |||
| 53b2dc6067 | |||
| 1bdfa9f3d2 | |||
| 369c2ce182 | |||
| 5e24678fa5 | |||
| c438f5772c |
@@ -23,7 +23,7 @@
|
|||||||
"node-cron": "^3.0.3",
|
"node-cron": "^3.0.3",
|
||||||
"nodemailer": "^6.9.16",
|
"nodemailer": "^6.9.16",
|
||||||
"stripe": "^22.0.0",
|
"stripe": "^22.0.0",
|
||||||
"telnyx": "^6.41.0",
|
|
||||||
"zod": "^4.3.6"
|
"zod": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { resolveStaffMiddleware, requireRole, requireRoleOrSuperUser, requireSup
|
|||||||
import { devRouter } from "./routes/dev.js";
|
import { devRouter } from "./routes/dev.js";
|
||||||
import { adminSeedRouter } from "./routes/admin/seed.js";
|
import { adminSeedRouter } from "./routes/admin/seed.js";
|
||||||
import { startReminderScheduler } from "./services/reminders.js";
|
import { startReminderScheduler } from "./services/reminders.js";
|
||||||
|
import { webhooksRouter } from "./routes/stripe-webhooks.js";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@@ -50,6 +51,9 @@ app.route("/api/book", bookRouter);
|
|||||||
// Public portal routes — client-facing, authenticated via impersonation session header
|
// Public portal routes — client-facing, authenticated via impersonation session header
|
||||||
app.route("/api/portal", portalRouter);
|
app.route("/api/portal", portalRouter);
|
||||||
|
|
||||||
|
// Public Stripe webhook endpoint — signature-verified, no auth required
|
||||||
|
app.route("/api/webhooks/stripe", webhooksRouter);
|
||||||
|
|
||||||
// Dev/demo routes — config is always public, users endpoint is guarded internally
|
// Dev/demo routes — config is always public, users endpoint is guarded internally
|
||||||
app.route("/api/dev", devRouter);
|
app.route("/api/dev", devRouter);
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
import { Hono } from "hono";
|
|
||||||
import { getDb, businessSettings, reminderLogs, eq, sql, and, gte, lt } from "@groombook/db";
|
|
||||||
import { requireRole } from "../middleware/rbac.js";
|
|
||||||
import { createSmsProvider } from "../services/sms.js";
|
|
||||||
|
|
||||||
export const adminSmsRouter = new Hono();
|
|
||||||
|
|
||||||
adminSmsRouter.get("/status", requireManager(), async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
|
|
||||||
const [settings] = await db.select().from(businessSettings).limit(1);
|
|
||||||
|
|
||||||
const provider = createSmsProvider();
|
|
||||||
const smsEnabled = process.env.SMS_ENABLED === "true";
|
|
||||||
const providerName = process.env.SMS_PROVIDER ?? "none";
|
|
||||||
const fromNumber = process.env.TELNYX_FROM_NUMBER ?? null;
|
|
||||||
const connectionStatus = provider ? "connected" : "disconnected";
|
|
||||||
|
|
||||||
const now = new Date();
|
|
||||||
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
||||||
|
|
||||||
const statsRows = await db
|
|
||||||
.select({
|
|
||||||
status: reminderLogs.deliveryStatus,
|
|
||||||
count: sql<number>`count(*)::int`,
|
|
||||||
})
|
|
||||||
.from(reminderLogs)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(reminderLogs.channel, "sms"),
|
|
||||||
gte(reminderLogs.sentAt, startOfMonth)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.groupBy(reminderLogs.deliveryStatus);
|
|
||||||
|
|
||||||
const totals = { sent: 0, delivered: 0, failed: 0 };
|
|
||||||
for (const row of statsRows) {
|
|
||||||
if (row.status === "delivered") totals.delivered = row.count;
|
|
||||||
else if (row.status === "failed") totals.failed = row.count;
|
|
||||||
else totals.sent += row.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.json({
|
|
||||||
providerName,
|
|
||||||
fromNumber,
|
|
||||||
connectionStatus,
|
|
||||||
smsEnabled,
|
|
||||||
businessSmsEnabled: settings?.smsEnabled ?? false,
|
|
||||||
stats: totals,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -16,8 +16,9 @@ import {
|
|||||||
services,
|
services,
|
||||||
staff,
|
staff,
|
||||||
} from "@groombook/db";
|
} from "@groombook/db";
|
||||||
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
|
|
||||||
export const appointmentGroupsRouter = new Hono();
|
export const appointmentGroupsRouter = new Hono<AppEnv>();
|
||||||
|
|
||||||
// ─── Schemas ──────────────────────────────────────────────────────────────────
|
// ─── Schemas ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -49,6 +50,8 @@ appointmentGroupsRouter.get("/", async (c) => {
|
|||||||
const clientId = c.req.query("clientId");
|
const clientId = c.req.query("clientId");
|
||||||
const from = c.req.query("from");
|
const from = c.req.query("from");
|
||||||
const to = c.req.query("to");
|
const to = c.req.query("to");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
const groupConditions = clientId
|
const groupConditions = clientId
|
||||||
? [eq(appointmentGroups.clientId, clientId)]
|
? [eq(appointmentGroups.clientId, clientId)]
|
||||||
@@ -88,6 +91,16 @@ appointmentGroupsRouter.get("/", async (c) => {
|
|||||||
}))
|
}))
|
||||||
.filter((g) => !from || g.appointments.length > 0);
|
.filter((g) => !from || g.appointments.length > 0);
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
return c.json(
|
||||||
|
result.filter((g) =>
|
||||||
|
g.appointments.some(
|
||||||
|
(a) => a.staffId === staffRow.id || a.batherStaffId === staffRow.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return c.json(result);
|
return c.json(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,6 +109,8 @@ appointmentGroupsRouter.get("/", async (c) => {
|
|||||||
appointmentGroupsRouter.get("/:id", async (c) => {
|
appointmentGroupsRouter.get("/:id", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
const [group] = await db
|
const [group] = await db
|
||||||
.select()
|
.select()
|
||||||
@@ -111,6 +126,7 @@ appointmentGroupsRouter.get("/:id", async (c) => {
|
|||||||
serviceId: appointments.serviceId,
|
serviceId: appointments.serviceId,
|
||||||
serviceName: services.name,
|
serviceName: services.name,
|
||||||
staffId: appointments.staffId,
|
staffId: appointments.staffId,
|
||||||
|
batherStaffId: appointments.batherStaffId,
|
||||||
staffName: staff.name,
|
staffName: staff.name,
|
||||||
status: appointments.status,
|
status: appointments.status,
|
||||||
startTime: appointments.startTime,
|
startTime: appointments.startTime,
|
||||||
@@ -125,6 +141,15 @@ appointmentGroupsRouter.get("/:id", async (c) => {
|
|||||||
.where(eq(appointments.groupId, id))
|
.where(eq(appointments.groupId, id))
|
||||||
.orderBy(appointments.startTime);
|
.orderBy(appointments.startTime);
|
||||||
|
|
||||||
|
if (
|
||||||
|
isGroomer &&
|
||||||
|
!groupAppts.some(
|
||||||
|
(a) => a.staffId === staffRow.id || a.batherStaffId === staffRow.id
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
|
||||||
const [client] = await db
|
const [client] = await db
|
||||||
.select({ name: clients.name, email: clients.email })
|
.select({ name: clients.name, email: clients.email })
|
||||||
.from(clients)
|
.from(clients)
|
||||||
@@ -140,6 +165,13 @@ appointmentGroupsRouter.post(
|
|||||||
zValidator("json", createGroupSchema),
|
zValidator("json", createGroupSchema),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
if (staffRow?.role === "groomer") {
|
||||||
|
return c.json(
|
||||||
|
{ error: "Forbidden: groomers cannot create group bookings" },
|
||||||
|
403
|
||||||
|
);
|
||||||
|
}
|
||||||
const body = c.req.valid("json");
|
const body = c.req.valid("json");
|
||||||
const startTime = new Date(body.startTime);
|
const startTime = new Date(body.startTime);
|
||||||
|
|
||||||
@@ -244,6 +276,28 @@ appointmentGroupsRouter.patch(
|
|||||||
const db = getDb();
|
const db = getDb();
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
const body = c.req.valid("json");
|
const body = c.req.valid("json");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
|
const [group] = await db
|
||||||
|
.select({ id: appointmentGroups.id })
|
||||||
|
.from(appointmentGroups)
|
||||||
|
.where(eq(appointmentGroups.id, id));
|
||||||
|
if (!group) return c.json({ error: "Not found" }, 404);
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
const groupAppts = await db
|
||||||
|
.select({ staffId: appointments.staffId, batherStaffId: appointments.batherStaffId })
|
||||||
|
.from(appointments)
|
||||||
|
.where(eq(appointments.groupId, id));
|
||||||
|
if (
|
||||||
|
!groupAppts.some(
|
||||||
|
(a) => a.staffId === staffRow.id || a.batherStaffId === staffRow.id
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [updated] = await db
|
const [updated] = await db
|
||||||
.update(appointmentGroups)
|
.update(appointmentGroups)
|
||||||
@@ -261,6 +315,8 @@ appointmentGroupsRouter.patch(
|
|||||||
appointmentGroupsRouter.delete("/:id", async (c) => {
|
appointmentGroupsRouter.delete("/:id", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
const [group] = await db
|
const [group] = await db
|
||||||
.select({ id: appointmentGroups.id })
|
.select({ id: appointmentGroups.id })
|
||||||
@@ -268,6 +324,20 @@ appointmentGroupsRouter.delete("/:id", async (c) => {
|
|||||||
.where(eq(appointmentGroups.id, id));
|
.where(eq(appointmentGroups.id, id));
|
||||||
if (!group) return c.json({ error: "Not found" }, 404);
|
if (!group) return c.json({ error: "Not found" }, 404);
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
const groupAppts = await db
|
||||||
|
.select({ staffId: appointments.staffId, batherStaffId: appointments.batherStaffId })
|
||||||
|
.from(appointments)
|
||||||
|
.where(eq(appointments.groupId, id));
|
||||||
|
if (
|
||||||
|
!groupAppts.some(
|
||||||
|
(a) => a.staffId === staffRow.id || a.batherStaffId === staffRow.id
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(appointments)
|
.update(appointments)
|
||||||
.set({ status: "cancelled", updatedAt: new Date() })
|
.set({ status: "cancelled", updatedAt: new Date() })
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ const createAppointmentSchema = z.object({
|
|||||||
frequencyWeeks: z.number().int().min(1).max(52),
|
frequencyWeeks: z.number().int().min(1).max(52),
|
||||||
count: z.number().int().min(2).max(52),
|
count: z.number().int().min(2).max(52),
|
||||||
})
|
})
|
||||||
|
.refine(
|
||||||
|
(r) => r.frequencyWeeks * r.count <= 52,
|
||||||
|
{ message: "Recurrence series must not exceed 1 year" }
|
||||||
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,6 +167,29 @@ appointmentsRouter.post(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check batherStaffId conflicts if set
|
||||||
|
if (apptFields.batherStaffId) {
|
||||||
|
const conflicts = await tx
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, apptFields.batherStaffId),
|
||||||
|
eq(appointments.batherStaffId, apptFields.batherStaffId)
|
||||||
|
),
|
||||||
|
lt(appointments.startTime, end),
|
||||||
|
gte(appointments.endTime, start),
|
||||||
|
ne(appointments.status, "cancelled"),
|
||||||
|
ne(appointments.status, "no_show"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (conflicts.length > 0) {
|
||||||
|
throw Object.assign(new Error("conflict"), { statusCode: 409 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!recurrence) {
|
if (!recurrence) {
|
||||||
// Single appointment
|
// Single appointment
|
||||||
const [inserted] = await tx
|
const [inserted] = await tx
|
||||||
@@ -461,6 +488,34 @@ appointmentsRouter.patch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check batherStaffId conflicts if being updated or already set
|
||||||
|
const batherStaffId =
|
||||||
|
updateFields.batherStaffId !== undefined
|
||||||
|
? updateFields.batherStaffId
|
||||||
|
: current.batherStaffId;
|
||||||
|
if (batherStaffId) {
|
||||||
|
const conflicts = await tx
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, batherStaffId),
|
||||||
|
eq(appointments.batherStaffId, batherStaffId)
|
||||||
|
),
|
||||||
|
lt(appointments.startTime, end),
|
||||||
|
gte(appointments.endTime, start),
|
||||||
|
ne(appointments.status, "cancelled"),
|
||||||
|
ne(appointments.status, "no_show"),
|
||||||
|
ne(appointments.id, id),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (conflicts.length > 0) {
|
||||||
|
throw Object.assign(new Error("conflict"), { statusCode: 409 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [updated] = await tx
|
const [updated] = await tx
|
||||||
.update(appointments)
|
.update(appointments)
|
||||||
.set(update)
|
.set(update)
|
||||||
|
|||||||
@@ -102,7 +102,10 @@ bookRouter.get("/availability", async (c) => {
|
|||||||
|
|
||||||
const bookingSchema = z.object({
|
const bookingSchema = z.object({
|
||||||
serviceId: z.string().uuid(),
|
serviceId: z.string().uuid(),
|
||||||
startTime: z.string().datetime(),
|
startTime: z.string().datetime().refine(
|
||||||
|
(dt) => new Date(dt) > new Date(),
|
||||||
|
{ message: "Appointment must be in the future" }
|
||||||
|
),
|
||||||
clientName: z.string().min(1).max(200),
|
clientName: z.string().min(1).max(200),
|
||||||
clientEmail: z.string().email(),
|
clientEmail: z.string().email(),
|
||||||
clientPhone: z.string().max(50).optional(),
|
clientPhone: z.string().max(50).optional(),
|
||||||
|
|||||||
@@ -4,35 +4,12 @@ import { z } from "zod/v3";
|
|||||||
import { and, eq, exists, getDb, or, clients, appointments } from "@groombook/db";
|
import { and, eq, exists, getDb, or, clients, appointments } from "@groombook/db";
|
||||||
import type { AppEnv } from "../middleware/rbac.js";
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
|
|
||||||
function normalizeE164(phone: string): string | null {
|
|
||||||
const digits = phone.replace(/\D/g, "");
|
|
||||||
if (digits.length === 10) return `+1${digits}`;
|
|
||||||
if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
|
|
||||||
if (digits.length > 11 && digits.startsWith("1")) return `+${digits.slice(0, 11)}`;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function e164String() {
|
|
||||||
return z.string().transform((v, ctx) => {
|
|
||||||
if (!v) return v as unknown as undefined;
|
|
||||||
const normalized = normalizeE164(v);
|
|
||||||
if (!normalized) {
|
|
||||||
ctx.addIssue({
|
|
||||||
code: z.ZodIssueCode.custom,
|
|
||||||
message: "Invalid phone number. Must be a valid E.164 number (e.g. +12125551234).",
|
|
||||||
});
|
|
||||||
return z.NEVER;
|
|
||||||
}
|
|
||||||
return normalized;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const clientsRouter = new Hono<AppEnv>();
|
export const clientsRouter = new Hono<AppEnv>();
|
||||||
|
|
||||||
const createClientSchema = z.object({
|
const createClientSchema = z.object({
|
||||||
name: z.string().min(1).max(200),
|
name: z.string().min(1).max(200),
|
||||||
email: z.string().email().optional(),
|
email: z.string().email().optional(),
|
||||||
phone: e164String().optional(),
|
phone: z.string().max(50).optional(),
|
||||||
address: z.string().max(500).optional(),
|
address: z.string().max(500).optional(),
|
||||||
notes: z.string().max(2000).optional(),
|
notes: z.string().max(2000).optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { z } from "zod/v3";
|
import { z } from "zod/v3";
|
||||||
import { desc, eq, getDb, groomingVisitLogs } from "@groombook/db";
|
import { and, desc, eq, getDb, groomingVisitLogs, appointments, or } from "@groombook/db";
|
||||||
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
|
|
||||||
export const groomingLogsRouter = new Hono();
|
export const groomingLogsRouter = new Hono<AppEnv>();
|
||||||
|
|
||||||
const createLogSchema = z.object({
|
const createLogSchema = z.object({
|
||||||
petId: z.string().uuid(),
|
petId: z.string().uuid(),
|
||||||
@@ -20,6 +21,26 @@ groomingLogsRouter.get("/", async (c) => {
|
|||||||
const db = getDb();
|
const db = getDb();
|
||||||
const petId = c.req.query("petId");
|
const petId = c.req.query("petId");
|
||||||
if (!petId) return c.json({ error: "petId is required" }, 400);
|
if (!petId) return c.json({ error: "petId is required" }, 400);
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
const [appt] = await db
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(appointments.petId, petId),
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, staffRow.id),
|
||||||
|
eq(appointments.batherStaffId, staffRow.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (!appt) return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select()
|
.select()
|
||||||
.from(groomingVisitLogs)
|
.from(groomingVisitLogs)
|
||||||
@@ -33,11 +54,50 @@ groomingLogsRouter.post(
|
|||||||
zValidator("json", createLogSchema),
|
zValidator("json", createLogSchema),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const { groomedAt, ...rest } = c.req.valid("json");
|
const { groomedAt, petId, appointmentId, ...rest } = c.req.valid("json");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
if (appointmentId) {
|
||||||
|
const [appt] = await db
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(appointments.id, appointmentId),
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, staffRow.id),
|
||||||
|
eq(appointments.batherStaffId, staffRow.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (!appt) return c.json({ error: "Forbidden" }, 403);
|
||||||
|
} else {
|
||||||
|
const [appt] = await db
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(appointments.petId, petId),
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, staffRow.id),
|
||||||
|
eq(appointments.batherStaffId, staffRow.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (!appt) return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [row] = await db
|
const [row] = await db
|
||||||
.insert(groomingVisitLogs)
|
.insert(groomingVisitLogs)
|
||||||
.values({
|
.values({
|
||||||
...rest,
|
...rest,
|
||||||
|
petId,
|
||||||
|
appointmentId: appointmentId ?? null,
|
||||||
groomedAt: groomedAt ? new Date(groomedAt) : new Date(),
|
groomedAt: groomedAt ? new Date(groomedAt) : new Date(),
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
@@ -47,10 +107,37 @@ groomingLogsRouter.post(
|
|||||||
|
|
||||||
groomingLogsRouter.delete("/:id", async (c) => {
|
groomingLogsRouter.delete("/:id", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const [row] = await db
|
const id = c.req.param("id");
|
||||||
|
const staffRow = c.get("staff");
|
||||||
|
const isGroomer = staffRow?.role === "groomer";
|
||||||
|
|
||||||
|
const [log] = await db
|
||||||
|
.select()
|
||||||
|
.from(groomingVisitLogs)
|
||||||
|
.where(eq(groomingVisitLogs.id, id))
|
||||||
|
.limit(1);
|
||||||
|
if (!log) return c.json({ error: "Not found" }, 404);
|
||||||
|
|
||||||
|
if (isGroomer) {
|
||||||
|
const [appt] = await db
|
||||||
|
.select({ id: appointments.id })
|
||||||
|
.from(appointments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(appointments.petId, log.petId),
|
||||||
|
or(
|
||||||
|
eq(appointments.staffId, staffRow.id),
|
||||||
|
eq(appointments.batherStaffId, staffRow.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
if (!appt) return c.json({ error: "Forbidden" }, 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
.delete(groomingVisitLogs)
|
.delete(groomingVisitLogs)
|
||||||
.where(eq(groomingVisitLogs.id, c.req.param("id")))
|
.where(eq(groomingVisitLogs.id, id))
|
||||||
.returning();
|
.returning();
|
||||||
if (!row) return c.json({ error: "Not found" }, 404);
|
|
||||||
return c.json({ ok: true });
|
return c.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ import {
|
|||||||
clients,
|
clients,
|
||||||
sql,
|
sql,
|
||||||
} from "@groombook/db";
|
} from "@groombook/db";
|
||||||
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
|
|
||||||
export const invoicesRouter = new Hono();
|
export const invoicesRouter = new Hono<AppEnv>();
|
||||||
|
|
||||||
const createInvoiceSchema = z.object({
|
const createInvoiceSchema = z.object({
|
||||||
appointmentId: z.string().uuid().optional(),
|
appointmentId: z.string().uuid().optional(),
|
||||||
@@ -43,53 +44,61 @@ const updateInvoiceSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// List invoices
|
// List invoices
|
||||||
invoicesRouter.get("/", async (c) => {
|
const listInvoicesQuerySchema = z.object({
|
||||||
const db = getDb();
|
clientId: z.string().uuid().optional(),
|
||||||
const clientId = c.req.query("clientId");
|
appointmentId: z.string().uuid().optional(),
|
||||||
const appointmentId = c.req.query("appointmentId");
|
status: z.enum(["draft", "pending", "paid", "void"]).optional(),
|
||||||
const status = c.req.query("status");
|
limit: z.coerce.number().int().min(1).max(200).default(50),
|
||||||
const limit = Math.min(parseInt(c.req.query("limit") || "50", 10), 200);
|
offset: z.coerce.number().int().min(0).default(0),
|
||||||
const offset = parseInt(c.req.query("offset") || "0", 10);
|
|
||||||
|
|
||||||
const conditions = [];
|
|
||||||
if (clientId) conditions.push(eq(invoices.clientId, clientId));
|
|
||||||
if (appointmentId) conditions.push(eq(invoices.appointmentId, appointmentId));
|
|
||||||
if (status) conditions.push(eq(invoices.status, status as "draft" | "pending" | "paid" | "void"));
|
|
||||||
|
|
||||||
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
|
||||||
|
|
||||||
const [totalResult] = await db
|
|
||||||
.select({ count: sql<number>`count(*)` })
|
|
||||||
.from(invoices)
|
|
||||||
.where(whereClause);
|
|
||||||
|
|
||||||
const rows = await db
|
|
||||||
.select({
|
|
||||||
id: invoices.id,
|
|
||||||
appointmentId: invoices.appointmentId,
|
|
||||||
clientId: invoices.clientId,
|
|
||||||
clientName: clients.name,
|
|
||||||
subtotalCents: invoices.subtotalCents,
|
|
||||||
taxCents: invoices.taxCents,
|
|
||||||
tipCents: invoices.tipCents,
|
|
||||||
totalCents: invoices.totalCents,
|
|
||||||
status: invoices.status,
|
|
||||||
paymentMethod: invoices.paymentMethod,
|
|
||||||
paidAt: invoices.paidAt,
|
|
||||||
notes: invoices.notes,
|
|
||||||
createdAt: invoices.createdAt,
|
|
||||||
updatedAt: invoices.updatedAt,
|
|
||||||
})
|
|
||||||
.from(invoices)
|
|
||||||
.leftJoin(clients, eq(invoices.clientId, clients.id))
|
|
||||||
.where(whereClause)
|
|
||||||
.orderBy(invoices.createdAt)
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset);
|
|
||||||
|
|
||||||
return c.json({ data: rows, total: totalResult?.count ?? 0 });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
invoicesRouter.get(
|
||||||
|
"/",
|
||||||
|
zValidator("query", listInvoicesQuerySchema),
|
||||||
|
async (c) => {
|
||||||
|
const db = getDb();
|
||||||
|
const { clientId, appointmentId, status, limit, offset } = c.req.valid("query");
|
||||||
|
|
||||||
|
const conditions = [];
|
||||||
|
if (clientId) conditions.push(eq(invoices.clientId, clientId));
|
||||||
|
if (appointmentId) conditions.push(eq(invoices.appointmentId, appointmentId));
|
||||||
|
if (status) conditions.push(eq(invoices.status, status as "draft" | "pending" | "paid" | "void"));
|
||||||
|
|
||||||
|
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
||||||
|
|
||||||
|
const [totalResult] = await db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(invoices)
|
||||||
|
.where(whereClause);
|
||||||
|
|
||||||
|
const rows = await db
|
||||||
|
.select({
|
||||||
|
id: invoices.id,
|
||||||
|
appointmentId: invoices.appointmentId,
|
||||||
|
clientId: invoices.clientId,
|
||||||
|
clientName: clients.name,
|
||||||
|
subtotalCents: invoices.subtotalCents,
|
||||||
|
taxCents: invoices.taxCents,
|
||||||
|
tipCents: invoices.tipCents,
|
||||||
|
totalCents: invoices.totalCents,
|
||||||
|
status: invoices.status,
|
||||||
|
paymentMethod: invoices.paymentMethod,
|
||||||
|
paidAt: invoices.paidAt,
|
||||||
|
notes: invoices.notes,
|
||||||
|
createdAt: invoices.createdAt,
|
||||||
|
updatedAt: invoices.updatedAt,
|
||||||
|
})
|
||||||
|
.from(invoices)
|
||||||
|
.leftJoin(clients, eq(invoices.clientId, clients.id))
|
||||||
|
.where(whereClause)
|
||||||
|
.orderBy(invoices.createdAt)
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset);
|
||||||
|
|
||||||
|
return c.json({ data: rows, total: totalResult?.count ?? 0 });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Get single invoice with line items and tip splits
|
// Get single invoice with line items and tip splits
|
||||||
invoicesRouter.get("/:id", async (c) => {
|
invoicesRouter.get("/:id", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ portalRouter.get("/me", async (c) => {
|
|||||||
return c.json({ id: client.id, name: client.name, email: client.email, phone: client.phone });
|
return c.json({ id: client.id, name: client.name, email: client.email, phone: client.phone });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
portalRouter.get("/config", async (c) => {
|
||||||
|
return c.json({
|
||||||
|
stripePublishableKey: process.env.STRIPE_PUBLISHABLE_KEY ?? "",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
portalRouter.get("/services", async (c) => {
|
portalRouter.get("/services", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const allServices = await db.select().from(services).where(eq(services.active, true));
|
const allServices = await db.select().from(services).where(eq(services.active, true));
|
||||||
@@ -123,7 +129,7 @@ portalRouter.get("/invoices", async (c) => {
|
|||||||
id: inv.id,
|
id: inv.id,
|
||||||
status: inv.status,
|
status: inv.status,
|
||||||
totalCents: inv.totalCents,
|
totalCents: inv.totalCents,
|
||||||
createdAt: inv.createdAt,
|
date: inv.createdAt,
|
||||||
lineItems: (itemsByInvoice[inv.id] || []).map(li => ({ id: li.id, description: li.description, quantity: li.quantity, unitPriceCents: li.unitPriceCents, totalCents: li.totalCents })),
|
lineItems: (itemsByInvoice[inv.id] || []).map(li => ({ id: li.id, description: li.description, quantity: li.quantity, unitPriceCents: li.unitPriceCents, totalCents: li.totalCents })),
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
@@ -453,49 +459,12 @@ portalRouter.delete("/waitlist/:id", async (c) => {
|
|||||||
import {
|
import {
|
||||||
createPaymentIntent,
|
createPaymentIntent,
|
||||||
listPaymentMethods,
|
listPaymentMethods,
|
||||||
attachPaymentMethod,
|
|
||||||
detachPaymentMethod,
|
detachPaymentMethod,
|
||||||
createSetupIntent,
|
createSetupIntent,
|
||||||
getOrCreateStripeCustomer,
|
getOrCreateStripeCustomer,
|
||||||
|
getStripeClient,
|
||||||
} from "../services/payment.js";
|
} from "../services/payment.js";
|
||||||
|
|
||||||
const payInvoiceSchema = z.object({
|
|
||||||
invoiceId: z.string().uuid(),
|
|
||||||
});
|
|
||||||
|
|
||||||
portalRouter.post(
|
|
||||||
"/invoices/:id/pay",
|
|
||||||
zValidator("json", payInvoiceSchema),
|
|
||||||
async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const invoiceId = c.req.param("id");
|
|
||||||
const sessionId = c.req.header("X-Impersonation-Session-Id");
|
|
||||||
const clientId = await getClientIdFromSession(sessionId);
|
|
||||||
if (!clientId) return c.json({ error: "Unauthorized" }, 401);
|
|
||||||
|
|
||||||
const [invoice] = await db
|
|
||||||
.select()
|
|
||||||
.from(invoices)
|
|
||||||
.where(eq(invoices.id, invoiceId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!invoice) return c.json({ error: "Not found" }, 404);
|
|
||||||
if (invoice.clientId !== clientId) return c.json({ error: "Forbidden" }, 403);
|
|
||||||
if (invoice.status === "draft" || invoice.status === "void") {
|
|
||||||
return c.json({ error: "Cannot pay a draft or void invoice" }, 422);
|
|
||||||
}
|
|
||||||
if (invoice.status === "paid") {
|
|
||||||
return c.json({ error: "Invoice is already paid" }, 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
const stripePublishableKey = process.env.STRIPE_PUBLISHABLE_KEY ?? "";
|
|
||||||
const result = await createPaymentIntent(invoiceId, clientId);
|
|
||||||
if (!result) return c.json({ error: "Payment service unavailable" }, 503);
|
|
||||||
|
|
||||||
return c.json({ clientSecret: result.clientSecret, publishableKey: stripePublishableKey });
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const payMultipleSchema = z.object({
|
const payMultipleSchema = z.object({
|
||||||
invoiceIds: z.array(z.string().uuid()).min(1),
|
invoiceIds: z.array(z.string().uuid()).min(1),
|
||||||
});
|
});
|
||||||
@@ -530,6 +499,7 @@ portalRouter.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const firstInvoice = invoiceRows[0];
|
const firstInvoice = invoiceRows[0];
|
||||||
|
if (!firstInvoice) return c.json({ error: "No invoices found" }, 400);
|
||||||
const allSameClient = invoiceRows.every(inv => inv.clientId === firstInvoice.clientId);
|
const allSameClient = invoiceRows.every(inv => inv.clientId === firstInvoice.clientId);
|
||||||
if (!allSameClient) {
|
if (!allSameClient) {
|
||||||
return c.json({ error: "All invoices must belong to the same client" }, 422);
|
return c.json({ error: "All invoices must belong to the same client" }, 422);
|
||||||
@@ -574,19 +544,23 @@ portalRouter.delete("/payment-methods/:id", async (c) => {
|
|||||||
if (!clientId) return c.json({ error: "Unauthorized" }, 401);
|
if (!clientId) return c.json({ error: "Unauthorized" }, 401);
|
||||||
|
|
||||||
const paymentMethodId = c.req.param("id");
|
const paymentMethodId = c.req.param("id");
|
||||||
|
|
||||||
|
const stripeCustomerId = await getOrCreateStripeCustomer(clientId);
|
||||||
|
if (!stripeCustomerId) return c.json({ error: "No payment method found" }, 404);
|
||||||
|
|
||||||
|
const stripe = getStripeClient();
|
||||||
|
if (!stripe) return c.json({ error: "Payment service unavailable" }, 503);
|
||||||
|
|
||||||
|
const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodId);
|
||||||
|
if (!paymentMethod || paymentMethod.customer !== stripeCustomerId) {
|
||||||
|
return c.json({ error: "Payment method not found" }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
const ok = await detachPaymentMethod(paymentMethodId);
|
const ok = await detachPaymentMethod(paymentMethodId);
|
||||||
if (!ok) return c.json({ error: "Failed to detach payment method" }, 500);
|
if (!ok) return c.json({ error: "Failed to detach payment method" }, 500);
|
||||||
return c.json({ ok: true });
|
return c.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── Config endpoint ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
portalRouter.get("/config", (c) => {
|
|
||||||
return c.json({
|
|
||||||
stripePublishableKey: process.env.STRIPE_PUBLISHABLE_KEY ?? "",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ─── Dev-mode session creation ──────────────────────────────────────────────
|
// ─── Dev-mode session creation ──────────────────────────────────────────────
|
||||||
// Allows the dev login selector to vend an impersonation session for a client
|
// Allows the dev login selector to vend an impersonation session for a client
|
||||||
// without requiring manager auth. Only available when AUTH_DISABLED=true.
|
// without requiring manager auth. Only available when AUTH_DISABLED=true.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const createServiceSchema = z.object({
|
|||||||
name: z.string().min(1).max(200),
|
name: z.string().min(1).max(200),
|
||||||
description: z.string().max(2000).optional(),
|
description: z.string().max(2000).optional(),
|
||||||
basePriceCents: z.number().int().positive(),
|
basePriceCents: z.number().int().positive(),
|
||||||
durationMinutes: z.number().int().positive(),
|
durationMinutes: z.number().int().positive().max(480),
|
||||||
active: z.boolean().default(true),
|
active: z.boolean().default(true),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { Hono } from "hono";
|
||||||
|
import Stripe from "stripe";
|
||||||
|
import { z } from "zod/v3";
|
||||||
|
import { eq, getDb, invoices } from "@groombook/db";
|
||||||
|
import { getStripeClient } from "../services/payment.js";
|
||||||
|
|
||||||
|
export const webhooksRouter = new Hono();
|
||||||
|
|
||||||
|
webhooksRouter.post("/stripe", async (c) => {
|
||||||
|
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
||||||
|
if (!webhookSecret) {
|
||||||
|
return c.json({ error: "Webhook secret not configured" }, 503);
|
||||||
|
}
|
||||||
|
|
||||||
|
const signature = c.req.header("stripe-signature");
|
||||||
|
if (!signature) {
|
||||||
|
return c.json({ error: "Missing signature" }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
let rawBody: string;
|
||||||
|
try {
|
||||||
|
rawBody = await c.req.text();
|
||||||
|
} catch {
|
||||||
|
return c.json({ error: "Could not read body" }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const stripe = getStripeClient();
|
||||||
|
if (!stripe) {
|
||||||
|
return c.json({ error: "Stripe not configured" }, 503);
|
||||||
|
}
|
||||||
|
|
||||||
|
let event: Stripe.Event;
|
||||||
|
try {
|
||||||
|
event = stripe.webhooks.constructEvent(rawBody, signature, webhookSecret);
|
||||||
|
} catch (err) {
|
||||||
|
const message = err instanceof Error ? err.message : "Invalid signature";
|
||||||
|
return c.json({ error: message }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const db = getDb();
|
||||||
|
|
||||||
|
if (event.type === "payment_intent.succeeded") {
|
||||||
|
const pi = event.data.object as Stripe.PaymentIntent;
|
||||||
|
if (pi.metadata?.groombook_invoice_ids) {
|
||||||
|
const invoiceIds = pi.metadata.groombook_invoice_ids.split(",");
|
||||||
|
for (const invoiceId of invoiceIds) {
|
||||||
|
if (!invoiceId) continue;
|
||||||
|
const parsed = z.string().uuid().safeParse(invoiceId.trim());
|
||||||
|
if (!parsed.success) continue;
|
||||||
|
const invoiceIdTrimmed = invoiceId.trim();
|
||||||
|
const [inv] = await db
|
||||||
|
.select()
|
||||||
|
.from(invoices)
|
||||||
|
.where(eq(invoices.id, invoiceIdTrimmed))
|
||||||
|
.limit(1);
|
||||||
|
if (!inv) continue;
|
||||||
|
if (inv.stripePaymentIntentId && inv.stripePaymentIntentId !== pi.id) continue;
|
||||||
|
await db
|
||||||
|
.update(invoices)
|
||||||
|
.set({
|
||||||
|
status: "paid",
|
||||||
|
paymentMethod: "card",
|
||||||
|
paidAt: new Date(),
|
||||||
|
stripePaymentIntentId: pi.id,
|
||||||
|
updatedAt: new Date(),
|
||||||
|
})
|
||||||
|
.where(eq(invoices.id, invoiceIdTrimmed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (event.type === "payment_intent.payment_failed") {
|
||||||
|
const pi = event.data.object as Stripe.PaymentIntent;
|
||||||
|
if (pi.metadata?.groombook_invoice_ids) {
|
||||||
|
const invoiceIds = pi.metadata.groombook_invoice_ids.split(",");
|
||||||
|
for (const invoiceId of invoiceIds) {
|
||||||
|
if (!invoiceId) continue;
|
||||||
|
const parsed = z.string().uuid().safeParse(invoiceId.trim());
|
||||||
|
if (!parsed.success) continue;
|
||||||
|
const invoiceIdTrimmed = invoiceId.trim();
|
||||||
|
await db
|
||||||
|
.update(invoices)
|
||||||
|
.set({
|
||||||
|
paymentFailureReason: pi.last_payment_error?.message ?? "Payment failed",
|
||||||
|
updatedAt: new Date(),
|
||||||
|
})
|
||||||
|
.where(eq(invoices.id, invoiceIdTrimmed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (event.type === "charge.refunded") {
|
||||||
|
const charge = event.data.object as Stripe.Charge;
|
||||||
|
if (typeof charge.payment_intent === "string" && charge.payment_intent) {
|
||||||
|
const [inv] = await db
|
||||||
|
.select({ id: invoices.id })
|
||||||
|
.from(invoices)
|
||||||
|
.where(eq(invoices.stripePaymentIntentId, charge.payment_intent))
|
||||||
|
.limit(1);
|
||||||
|
if (inv) {
|
||||||
|
const refundId =
|
||||||
|
typeof charge.refunded === "boolean" && charge.refunded
|
||||||
|
? `ch_${charge.id}_refund`
|
||||||
|
: null;
|
||||||
|
await db
|
||||||
|
.update(invoices)
|
||||||
|
.set({
|
||||||
|
status: "void",
|
||||||
|
stripeRefundId: refundId,
|
||||||
|
updatedAt: new Date(),
|
||||||
|
})
|
||||||
|
.where(eq(invoices.id, inv.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (event.type === "charge.dispute.created") {
|
||||||
|
const dispute = event.data.object as Stripe.Dispute;
|
||||||
|
console.error(
|
||||||
|
`[Stripe Webhook] Dispute created for payment intent: ${dispute.payment_intent}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ received: true });
|
||||||
|
});
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
import { Hono } from "hono";
|
|
||||||
import {
|
|
||||||
and,
|
|
||||||
eq,
|
|
||||||
getDb,
|
|
||||||
clients,
|
|
||||||
reminderLogs,
|
|
||||||
smsSend,
|
|
||||||
} from "@groombook/db";
|
|
||||||
import { TelnyxProvider } from "../services/sms.js";
|
|
||||||
|
|
||||||
export const webhooksRouter = new Hono();
|
|
||||||
|
|
||||||
const telnyxProvider = new TelnyxProvider();
|
|
||||||
|
|
||||||
const STOP_KEYWORDS = new Set(["STOP", "STOPALL", "UNSUBSCRIBE", "CANCEL", "END", "QUIT"]);
|
|
||||||
const START_KEYWORDS = new Set(["START", "YES", "UNSTOP"]);
|
|
||||||
|
|
||||||
webhooksRouter.post("/sms/inbound", async (c) => {
|
|
||||||
if (!telnyxProvider.validateWebhookSignature(c.req.raw)) {
|
|
||||||
return c.json({ error: "Invalid signature" }, 401);
|
|
||||||
}
|
|
||||||
|
|
||||||
let body: Record<string, unknown>;
|
|
||||||
try {
|
|
||||||
body = await c.req.json();
|
|
||||||
} catch {
|
|
||||||
return c.json({ error: "Invalid JSON" }, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
const event = (body.data as Record<string, unknown>)?.event_type ?? body.event_type;
|
|
||||||
const payload = (body.data as Record<string, unknown>) ?? body;
|
|
||||||
|
|
||||||
if (event === "message.received") {
|
|
||||||
const fromField = payload.from;
|
|
||||||
const from = typeof fromField === "object" && fromField !== null
|
|
||||||
? (fromField as Record<string, unknown>).phone_number as string ?? (fromField as Record<string, unknown>).toString()
|
|
||||||
: String(fromField ?? "");
|
|
||||||
const text = String(payload.text ?? payload.body ?? "").trim().toUpperCase();
|
|
||||||
|
|
||||||
if (!from || !text) {
|
|
||||||
return c.json({ error: "Missing from or text" }, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
const db = getDb();
|
|
||||||
|
|
||||||
const [client] = await db
|
|
||||||
.select({ id: clients.id, smsOptIn: clients.smsOptIn })
|
|
||||||
.from(clients)
|
|
||||||
.where(eq(clients.phone, from))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (STOP_KEYWORDS.has(text)) {
|
|
||||||
await db
|
|
||||||
.update(clients)
|
|
||||||
.set({
|
|
||||||
smsOptIn: false,
|
|
||||||
smsOptOutDate: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.where(eq(clients.id, client.id));
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (START_KEYWORDS.has(text)) {
|
|
||||||
await db
|
|
||||||
.update(clients)
|
|
||||||
.set({
|
|
||||||
smsOptIn: true,
|
|
||||||
smsConsentDate: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.where(eq(clients.id, client.id));
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text === "HELP") {
|
|
||||||
const supportUrl = process.env.SUPPORT_URL ?? "https://groombook.app/support";
|
|
||||||
await smsSend(from, `GroomBook appointment reminders. Reply STOP to opt out. For help, visit ${supportUrl}.`);
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event === "message.finalized" || event === "message.status") {
|
|
||||||
const status = String(payload.status ?? "");
|
|
||||||
const toField = payload.to;
|
|
||||||
const toNumber = typeof toField === "object" && toField !== null
|
|
||||||
? (toField as Record<string, unknown>).phone_number as string ?? (toField as Record<string, unknown>).toString()
|
|
||||||
: String(toField ?? "");
|
|
||||||
|
|
||||||
if (!status || !toNumber) {
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
const validDelivery = ["delivered", "sent", "failed", "sending", "queued"];
|
|
||||||
if (!validDelivery.includes(status)) {
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
const db = getDb();
|
|
||||||
|
|
||||||
const [client] = await db
|
|
||||||
.select({ id: clients.id })
|
|
||||||
.from(clients)
|
|
||||||
.where(eq(clients.phone, toNumber))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (client) {
|
|
||||||
const [log] = await db
|
|
||||||
.select({ id: reminderLogs.id })
|
|
||||||
.from(reminderLogs)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(reminderLogs.channel, "sms")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (log) {
|
|
||||||
await db
|
|
||||||
.update(reminderLogs)
|
|
||||||
.set({ deliveryStatus: status })
|
|
||||||
.where(eq(reminderLogs.id, log.id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.json({ received: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.json({ received: true });
|
|
||||||
});
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import Stripe from "stripe";
|
import Stripe from "stripe";
|
||||||
import { getDb, clients, eq, invoices } from "@groombook/db";
|
import { getDb, clients, eq, inArray, invoices } from "@groombook/db";
|
||||||
|
|
||||||
let _stripe: Stripe | null | undefined;
|
let _stripe: Stripe | null | undefined;
|
||||||
|
|
||||||
function getStripeClient(): Stripe | null {
|
export function getStripeClient(): Stripe | null {
|
||||||
if (_stripe === undefined) {
|
if (_stripe === undefined) {
|
||||||
const secretKey = process.env.STRIPE_SECRET_KEY;
|
const secretKey = process.env.STRIPE_SECRET_KEY;
|
||||||
if (!secretKey) return null;
|
if (!secretKey) return null;
|
||||||
@@ -43,11 +43,13 @@ export async function createPaymentIntent(
|
|||||||
|
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const invoiceIds = Array.isArray(invoiceIdOrIds) ? invoiceIdOrIds : [invoiceIdOrIds];
|
const invoiceIds = Array.isArray(invoiceIdOrIds) ? invoiceIdOrIds : [invoiceIdOrIds];
|
||||||
|
const firstInvoiceId = invoiceIds[0];
|
||||||
|
if (!firstInvoiceId) return null;
|
||||||
|
|
||||||
const invoiceRows = await db
|
const invoiceRows = await db
|
||||||
.select()
|
.select()
|
||||||
.from(invoices)
|
.from(invoices)
|
||||||
.where(eq(invoices.id, invoiceIds[0]));
|
.where(eq(invoices.id, firstInvoiceId));
|
||||||
|
|
||||||
const [invoice] = invoiceRows;
|
const [invoice] = invoiceRows;
|
||||||
if (!invoice) return null;
|
if (!invoice) return null;
|
||||||
@@ -57,8 +59,8 @@ export async function createPaymentIntent(
|
|||||||
const allInvoices = await db
|
const allInvoices = await db
|
||||||
.select({ totalCents: invoices.totalCents })
|
.select({ totalCents: invoices.totalCents })
|
||||||
.from(invoices)
|
.from(invoices)
|
||||||
.where(eq(invoices.id, invoiceIds[0]));
|
.where(inArray(invoices.id, invoiceIds));
|
||||||
totalCents = allInvoices.reduce((sum, inv) => sum + inv.totalCents, totalCents);
|
totalCents = allInvoices.reduce((sum, inv) => sum + inv.totalCents, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stripeCustomerId = await getOrCreateStripeCustomer(clientId);
|
const stripeCustomerId = await getOrCreateStripeCustomer(clientId);
|
||||||
@@ -82,10 +84,10 @@ export async function createPaymentIntent(
|
|||||||
.where(eq(invoices.id, invId));
|
.where(eq(invoices.id, invId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const clientSecret = paymentIntent.client_secret;
|
||||||
clientSecret: paymentIntent.client_secret!,
|
if (!clientSecret) return null;
|
||||||
paymentIntentId: paymentIntent.id,
|
|
||||||
};
|
return { clientSecret, paymentIntentId: paymentIntent.id };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function processRefund(
|
export async function processRefund(
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ import {
|
|||||||
buildReminderEmail,
|
buildReminderEmail,
|
||||||
sendEmail,
|
sendEmail,
|
||||||
} from "./email.js";
|
} from "./email.js";
|
||||||
import { smsSend } from "./sms.js";
|
|
||||||
|
|
||||||
// TCPA-required opt-out text appended to every SMS reminder
|
// How many hours before the appointment to send each reminder.
|
||||||
const TCPA_OPT_OUT = "Reply STOP to opt out. Msg & data rates may apply.";
|
// Override via env: REMINDER_HOURS_EARLY (default 24) and REMINDER_HOURS_LATE (default 2).
|
||||||
function getReminderWindows(): { label: string; hours: number }[] {
|
function getReminderWindows(): { label: string; hours: number }[] {
|
||||||
const early = Number(process.env.REMINDER_HOURS_EARLY ?? 24);
|
const early = Number(process.env.REMINDER_HOURS_EARLY ?? 24);
|
||||||
const late = Number(process.env.REMINDER_HOURS_LATE ?? 2);
|
const late = Number(process.env.REMINDER_HOURS_LATE ?? 2);
|
||||||
@@ -66,39 +65,23 @@ export async function runReminderCheck(): Promise<void> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const appt of upcoming) {
|
for (const appt of upcoming) {
|
||||||
const [emailLog] = await db
|
// Check if reminder already sent (unique constraint prevents double-send)
|
||||||
|
const existing = await db
|
||||||
.select({ id: reminderLogs.id })
|
.select({ id: reminderLogs.id })
|
||||||
.from(reminderLogs)
|
.from(reminderLogs)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(reminderLogs.appointmentId, appt.id),
|
eq(reminderLogs.appointmentId, appt.id),
|
||||||
eq(reminderLogs.reminderType, window.label),
|
eq(reminderLogs.reminderType, window.label)
|
||||||
eq(reminderLogs.channel, "email")
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
const [smsLog] = await db
|
if (existing.length > 0) continue; // already sent
|
||||||
.select({ id: reminderLogs.id })
|
|
||||||
.from(reminderLogs)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(reminderLogs.appointmentId, appt.id),
|
|
||||||
eq(reminderLogs.reminderType, window.label),
|
|
||||||
eq(reminderLogs.channel, "sms")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
// Fetch related records for the email
|
// Fetch related records for the email
|
||||||
const [client] = await db
|
const [client] = await db
|
||||||
.select({
|
.select({ name: clients.name, email: clients.email, emailOptOut: clients.emailOptOut })
|
||||||
name: clients.name,
|
|
||||||
email: clients.email,
|
|
||||||
emailOptOut: clients.emailOptOut,
|
|
||||||
smsOptIn: clients.smsOptIn,
|
|
||||||
phoneE164: clients.phoneE164,
|
|
||||||
})
|
|
||||||
.from(clients)
|
.from(clients)
|
||||||
.where(eq(clients.id, appt.clientId))
|
.where(eq(clients.id, appt.clientId))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -129,6 +112,8 @@ export async function runReminderCheck(): Promise<void> {
|
|||||||
|
|
||||||
if (!pet || !service) continue;
|
if (!pet || !service) continue;
|
||||||
|
|
||||||
|
// Ensure the appointment has a confirmation token before sending the reminder.
|
||||||
|
// Generate one if it doesn't have one yet (e.g. pre-existing appointments).
|
||||||
let confirmationToken = appt.confirmationToken;
|
let confirmationToken = appt.confirmationToken;
|
||||||
if (!confirmationToken) {
|
if (!confirmationToken) {
|
||||||
confirmationToken = randomBytes(32).toString("hex");
|
confirmationToken = randomBytes(32).toString("hex");
|
||||||
@@ -138,53 +123,27 @@ export async function runReminderCheck(): Promise<void> {
|
|||||||
.where(eq(appointments.id, appt.id));
|
.where(eq(appointments.id, appt.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!emailLog) {
|
const sent = await sendEmail(
|
||||||
const sent = await sendEmail(
|
buildReminderEmail(
|
||||||
buildReminderEmail(
|
client.email,
|
||||||
client.email,
|
{
|
||||||
{
|
clientName: client.name,
|
||||||
clientName: client.name,
|
petName: pet.name,
|
||||||
petName: pet.name,
|
serviceName: service.name,
|
||||||
serviceName: service.name,
|
groomerName,
|
||||||
groomerName,
|
startTime: appt.startTime,
|
||||||
startTime: appt.startTime,
|
},
|
||||||
},
|
window.hours,
|
||||||
window.hours,
|
confirmationToken
|
||||||
confirmationToken
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (sent) {
|
if (sent) {
|
||||||
await db
|
// Record send — ignore conflicts (race condition between instances)
|
||||||
.insert(reminderLogs)
|
await db
|
||||||
.values({ appointmentId: appt.id, reminderType: window.label, channel: "email" })
|
.insert(reminderLogs)
|
||||||
.onConflictDoNothing();
|
.values({ appointmentId: appt.id, reminderType: window.label })
|
||||||
}
|
.onConflictDoNothing();
|
||||||
}
|
|
||||||
|
|
||||||
if (!smsLog && client.smsOptIn && client.phoneE164) {
|
|
||||||
const apiUrl = process.env.API_URL ?? "http://localhost:3000";
|
|
||||||
const confirmUrl = `${apiUrl}/api/book/confirm/${confirmationToken}`;
|
|
||||||
const cancelUrl = `${apiUrl}/api/book/cancel/${confirmationToken}`;
|
|
||||||
const when = window.hours >= 24 ? "tomorrow" : `in ${window.hours} hours`;
|
|
||||||
const smsBody = [
|
|
||||||
`Hi ${client.name}, just a reminder: ${pet.name}'s grooming appointment is ${when}.`,
|
|
||||||
`Service: ${service.name}${groomerName ? ` with ${groomerName}` : ""}`,
|
|
||||||
`Confirm: ${confirmUrl}`,
|
|
||||||
`Cancel: ${cancelUrl}`,
|
|
||||||
TCPA_OPT_OUT,
|
|
||||||
].join(". ");
|
|
||||||
try {
|
|
||||||
const smsOk = await smsSend(client.phoneE164, smsBody);
|
|
||||||
if (smsOk) {
|
|
||||||
await db
|
|
||||||
.insert(reminderLogs)
|
|
||||||
.values({ appointmentId: appt.id, reminderType: window.label, channel: "sms" })
|
|
||||||
.onConflictDoNothing();
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[reminders] SMS send failed:", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
import { Telnyx } from "telnyx";
|
|
||||||
|
|
||||||
export interface SmsProvider {
|
|
||||||
sendSms(to: string, body: string, mediaUrls?: string[]): Promise<{ messageId: string; status: string }>;
|
|
||||||
validateWebhookSignature(req: Request): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TelnyxSmsResult {
|
|
||||||
message_id: string;
|
|
||||||
status: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTelnyxClient(): Telnyx | null {
|
|
||||||
const apiKey = process.env.TELNYX_API_KEY;
|
|
||||||
if (!apiKey) return null;
|
|
||||||
return new Telnyx(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
let _client: Telnyx | null | undefined;
|
|
||||||
|
|
||||||
function getClient(): Telnyx | null {
|
|
||||||
if (_client === undefined) _client = createTelnyxClient();
|
|
||||||
return _client;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFromNumber(): string | null {
|
|
||||||
return process.env.TELNYX_FROM_NUMBER ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isE164(phone: string): boolean {
|
|
||||||
return /^\+[1-9]\d{7,14}$/.test(phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function sendSms(
|
|
||||||
to: string,
|
|
||||||
body: string,
|
|
||||||
mediaUrls?: string[]
|
|
||||||
): Promise<{ messageId: string; status: string }> {
|
|
||||||
const client = getClient();
|
|
||||||
if (!client) throw new Error("Telnyx client not initialized. Set TELNYX_API_KEY.");
|
|
||||||
|
|
||||||
const from = getFromNumber();
|
|
||||||
if (!from) throw new Error("TELNYX_FROM_NUMBER is not set");
|
|
||||||
|
|
||||||
if (!isE164(to)) throw new Error(`Invalid recipient phone format: ${to}. Expected E.164.`);
|
|
||||||
if (!isE164(from)) throw new Error(`Invalid sender phone format: ${from}. Expected E.164.`);
|
|
||||||
|
|
||||||
const payload: Record<string, unknown> = {
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
body,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (mediaUrls && mediaUrls.length > 0) {
|
|
||||||
payload.media_urls = mediaUrls;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await client.messages.create(payload as Record<string, string | string[]>);
|
|
||||||
const smsResult = result.data as unknown as TelnyxSmsResult;
|
|
||||||
return {
|
|
||||||
messageId: smsResult.message_id,
|
|
||||||
status: smsResult.status,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TelnyxProvider implements SmsProvider {
|
|
||||||
async sendSms(
|
|
||||||
to: string,
|
|
||||||
body: string,
|
|
||||||
mediaUrls?: string[]
|
|
||||||
): Promise<{ messageId: string; status: string }> {
|
|
||||||
return sendSms(to, body, mediaUrls);
|
|
||||||
}
|
|
||||||
|
|
||||||
validateWebhookSignature(req: Request): boolean {
|
|
||||||
const secret = process.env.TELNYX_WEBHOOK_SECRET;
|
|
||||||
if (!secret) return false;
|
|
||||||
|
|
||||||
const signature = req.headers.get("telnyx-signature");
|
|
||||||
if (!signature) return false;
|
|
||||||
|
|
||||||
const payload = JSON.stringify(req.body);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { createHmac } = await import("crypto");
|
|
||||||
const hmac = createHmac("sha256", secret);
|
|
||||||
const expected = `sha256=${hmac.update(payload).digest("hex")}`;
|
|
||||||
|
|
||||||
const sigBuf = Buffer.from(signature);
|
|
||||||
const expBuf = Buffer.from(expected);
|
|
||||||
|
|
||||||
if (sigBuf.length !== expBuf.length) return false;
|
|
||||||
|
|
||||||
let diff = 0;
|
|
||||||
for (let i = 0; i < sigBuf.length; i++) {
|
|
||||||
diff |= sigBuf[i] ^ expBuf[i];
|
|
||||||
}
|
|
||||||
return diff === 0;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let _provider: SmsProvider | null | undefined;
|
|
||||||
|
|
||||||
export function createSmsProvider(): SmsProvider | null {
|
|
||||||
if (_provider === undefined) {
|
|
||||||
if (process.env.SMS_ENABLED !== "true") {
|
|
||||||
_provider = null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
switch (process.env.SMS_PROVIDER) {
|
|
||||||
case "telnyx": {
|
|
||||||
const client = getClient();
|
|
||||||
if (!client) {
|
|
||||||
_provider = null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_provider = new TelnyxProvider();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
_provider = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function smsSend(
|
|
||||||
to: string,
|
|
||||||
body: string,
|
|
||||||
mediaUrls?: string[]
|
|
||||||
): Promise<boolean> {
|
|
||||||
const provider = createSmsProvider();
|
|
||||||
if (!provider) return false;
|
|
||||||
|
|
||||||
await provider.sendSms(to, body, mediaUrls);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -226,7 +226,6 @@ export function CustomerPortal() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{showReschedule && rescheduleAppointment && (
|
{showReschedule && rescheduleAppointment && (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
<RescheduleFlow
|
<RescheduleFlow
|
||||||
appointment={rescheduleAppointment as any}
|
appointment={rescheduleAppointment as any}
|
||||||
onClose={() => { setShowReschedule(false); setRescheduleAppointment(null); }}
|
onClose={() => { setShowReschedule(false); setRescheduleAppointment(null); }}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { loadStripe, type Stripe } from "@stripe/stripe-js";
|
import { loadStripe } from "@stripe/stripe-js";
|
||||||
import { Elements, PaymentElement, useStripe, useElements } from "@stripe/react-stripe-js";
|
import { Elements, PaymentElement, useStripe, useElements } from "@stripe/react-stripe-js";
|
||||||
import { CreditCard, DollarSign, Package, Zap } from "lucide-react";
|
import { CreditCard, DollarSign, Package, Zap } from "lucide-react";
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ interface BillingPaymentsProps {
|
|||||||
function BillingPaymentsInner({ sessionId, readOnly }: BillingPaymentsProps) {
|
function BillingPaymentsInner({ sessionId, readOnly }: BillingPaymentsProps) {
|
||||||
const [invoices, setInvoices] = useState<Invoice[]>([]);
|
const [invoices, setInvoices] = useState<Invoice[]>([]);
|
||||||
const [paymentMethods, setPaymentMethods] = useState<PaymentMethod[]>([]);
|
const [paymentMethods, setPaymentMethods] = useState<PaymentMethod[]>([]);
|
||||||
const [packages, setPackages] = useState<{ name: string; remaining: number }[]>([]);
|
const [packages] = useState<{ name: string; remaining: number }[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [tab, setTab] = useState<"invoices" | "payment" | "packages">("invoices");
|
const [tab, setTab] = useState<"invoices" | "payment" | "packages">("invoices");
|
||||||
@@ -398,7 +398,10 @@ function PaymentModal({ sessionId, pending, onClose, onSuccess }: PaymentModalPr
|
|||||||
const { error: stripeError } = await stripe.confirmPayment({
|
const { error: stripeError } = await stripe.confirmPayment({
|
||||||
elements,
|
elements,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
confirmParams: saveCard ? { setup_future_usage: "off_session" } : undefined,
|
confirmParams: saveCard
|
||||||
|
? { setup_future_usage: "off_session" }
|
||||||
|
: undefined,
|
||||||
|
redirect: "if_required",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (stripeError) {
|
if (stripeError) {
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
API_HOST="https://api.minimax.io"
|
|
||||||
API_KEY="$MINIMAX_API_KEY"
|
|
||||||
OUTPUT_DIR="minimax-output"
|
|
||||||
|
|
||||||
mkdir -p "$OUTPUT_DIR"
|
|
||||||
|
|
||||||
# Diverse dog image prompts
|
|
||||||
declare -a PROMPTS=(
|
|
||||||
"A beautiful red Irish Setter with long flowing silky coat, standing proudly in golden hour sunlight, professional pet portrait photography, warm tones"
|
|
||||||
"A fluffy white Pomeranian puppy with thick fluffy coat, sitting alert with bright expression, studio white background, cute grooming"
|
|
||||||
"A black Schnauzer with distinctive full beard and mustache, freshly groomed with neat styling, professional grooming salon setting"
|
|
||||||
"A cream and white Cavalier King Charles Spaniel with silky coat, gentle sad eyes, soft warm indoor lighting, elegant pose"
|
|
||||||
"A brown and white Basset Hound with long droopy ears, lying down in relaxed pose, natural outdoor setting, peaceful expression"
|
|
||||||
"A black and tan miniature Dachshund with glossy coat, alert standing pose, warm studio lighting, detailed paws visible"
|
|
||||||
"A white fluffy Bichon Frise after professional grooming with rounded topknot, happy bouncy expression, bright cheerful background"
|
|
||||||
"A muscular fawn Boxer dog, athletic build, standing confidently outdoors in park, energetic expression, natural lighting"
|
|
||||||
"A blue merle Shetland Sheepdog with alert ears and fluffy coat, running happily, green grass field background, vibrant"
|
|
||||||
"A buff colored Cocker Spaniel with beautiful silky coat, friendly gentle expression, warm natural window lighting, indoor"
|
|
||||||
)
|
|
||||||
|
|
||||||
declare -a FILENAMES=(
|
|
||||||
"dog-setter-red-sunlit.png"
|
|
||||||
"dog-pomeranian-white-studio.png"
|
|
||||||
"dog-schnauzer-black-groomed.png"
|
|
||||||
"dog-cavalier-cream-gentle.png"
|
|
||||||
"dog-basset-brown-white.png"
|
|
||||||
"dog-dachshund-black-tan.png"
|
|
||||||
"dog-bichon-white-groomed.png"
|
|
||||||
"dog-boxer-fawn-athletic.png"
|
|
||||||
"dog-sheepdog-merle-running.png"
|
|
||||||
"dog-cocker-buff-friendly.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Generating ${#PROMPTS[@]} diverse dog images..."
|
|
||||||
|
|
||||||
for i in "${!PROMPTS[@]}"; do
|
|
||||||
PROMPT="${PROMPTS[$i]}"
|
|
||||||
FILENAME="${FILENAMES[$i]}"
|
|
||||||
|
|
||||||
echo -n "[$((i+1))/${#PROMPTS[@]}] $FILENAME... "
|
|
||||||
|
|
||||||
RESPONSE=$(curl -s -X POST "${API_HOST}/v1/image_generation" \
|
|
||||||
-H "Authorization: Bearer ${API_KEY}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"model\":\"image-01\",\"prompt\":\"${PROMPT}\",\"image_count\":1}")
|
|
||||||
|
|
||||||
# Extract image URL from response
|
|
||||||
IMAGE_URL=$(echo "$RESPONSE" | grep -o '"image_urls":\["\([^"]*\)' | cut -d'"' -f4)
|
|
||||||
|
|
||||||
if [ -n "$IMAGE_URL" ]; then
|
|
||||||
curl -s "$IMAGE_URL" -o "$OUTPUT_DIR/$FILENAME" 2>/dev/null
|
|
||||||
if [ -f "$OUTPUT_DIR/$FILENAME" ] && [ -s "$OUTPUT_DIR/$FILENAME" ]; then
|
|
||||||
echo "✓"
|
|
||||||
else
|
|
||||||
echo "✗ (download failed)"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "✗ (no URL)"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Done! Generated images in $OUTPUT_DIR/"
|
|
||||||
ls -lh "$OUTPUT_DIR"/dog-*.png 2>/dev/null | wc -l
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Use the configured MiniMax API host
|
|
||||||
API_HOST="${MINIMAX_API_HOST:-https://api.minimax.io}"
|
|
||||||
API_KEY="$MINIMAX_API_KEY"
|
|
||||||
|
|
||||||
# Test endpoint - check which one works
|
|
||||||
echo "Testing API endpoints..."
|
|
||||||
echo "API_HOST: $API_HOST"
|
|
||||||
echo "API_KEY: ${API_KEY:0:15}..."
|
|
||||||
|
|
||||||
# Array of diverse dog images to generate
|
|
||||||
declare -a PROMPTS=(
|
|
||||||
"A beautiful red Irish Setter with flowing silky coat, standing proudly in a sunny garden, warm natural lighting, professional pet photography"
|
|
||||||
"A fluffy white Pomeranian with thick coat, sitting alert, bright studio background, cute expression"
|
|
||||||
"A black Schnauzer with distinctive beard, freshly groomed, professional salon setting, dignified pose"
|
|
||||||
"A cream-colored Cavalier King Charles Spaniel, silky coat, gentle expression, soft warm lighting"
|
|
||||||
"A brown and white Basset Hound, long ears, relaxed sitting pose, natural outdoor background"
|
|
||||||
"A black and tan Dachshund, elongated body, alert posture, warm studio lighting"
|
|
||||||
"A white Bichon Frise, fluffy groomed coat, happy expression, bright cheerful background"
|
|
||||||
"A fawn Boxer with muscular build, athletic posture, outdoor park setting, energetic expression"
|
|
||||||
"A merle Shetland Sheepdog, alert ears, running pose, green garden background"
|
|
||||||
"A buff-colored Cocker Spaniel, silky coat, friendly expression, warm natural light"
|
|
||||||
)
|
|
||||||
|
|
||||||
declare -a FILENAMES=(
|
|
||||||
"dog-setter-red-sunny.png"
|
|
||||||
"dog-pomeranian-white-alert.png"
|
|
||||||
"dog-schnauzer-groomed.png"
|
|
||||||
"dog-cavalier-cream.png"
|
|
||||||
"dog-basset-hound-outdoor.png"
|
|
||||||
"dog-dachshund-alert.png"
|
|
||||||
"dog-bichon-frise-happy.png"
|
|
||||||
"dog-boxer-athletic.png"
|
|
||||||
"dog-sheepdog-merle.png"
|
|
||||||
"dog-cocker-spaniel-buff.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
mkdir -p minimax-output
|
|
||||||
|
|
||||||
echo "Generating ${#PROMPTS[@]} diverse dog images..."
|
|
||||||
|
|
||||||
for i in "${!PROMPTS[@]}"; do
|
|
||||||
PROMPT="${PROMPTS[$i]}"
|
|
||||||
FILENAME="${FILENAMES[$i]}"
|
|
||||||
|
|
||||||
echo "[$((i+1))/${#PROMPTS[@]}] Generating: $FILENAME"
|
|
||||||
|
|
||||||
# Make API request
|
|
||||||
RESPONSE=$(curl -s -X POST "${API_HOST}/v1/image_generation" \
|
|
||||||
-H "Authorization: Bearer ${API_KEY}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"model\": \"image-01\",
|
|
||||||
\"prompt\": \"${PROMPT}\",
|
|
||||||
\"image_count\": 1
|
|
||||||
}")
|
|
||||||
|
|
||||||
# Check if response contains image data
|
|
||||||
if echo "$RESPONSE" | grep -q "data\|image_url\|file_content"; then
|
|
||||||
echo " ✓ Response received"
|
|
||||||
|
|
||||||
# Try to extract and save image data
|
|
||||||
# Different APIs format responses differently
|
|
||||||
IMAGE_DATA=$(echo "$RESPONSE" | grep -o '"file_content":"[^"]*' | head -1 | cut -d'"' -f4)
|
|
||||||
|
|
||||||
if [ -n "$IMAGE_DATA" ]; then
|
|
||||||
echo "$IMAGE_DATA" | base64 -d > "minimax-output/$FILENAME"
|
|
||||||
echo " ✓ Image saved to minimax-output/$FILENAME"
|
|
||||||
else
|
|
||||||
echo " ✗ Could not extract image data"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo " ✗ API response: ${RESPONSE:0:100}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Image generation complete!"
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import base64
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
|
|
||||||
api_key = os.environ.get("MINIMAX_API_KEY")
|
|
||||||
if not api_key:
|
|
||||||
raise ValueError("MINIMAX_API_KEY environment variable not set")
|
|
||||||
|
|
||||||
url = "https://api.minimax.io/v1/image_generation"
|
|
||||||
headers = {"Authorization": f"Bearer {api_key}"}
|
|
||||||
|
|
||||||
# Ensure output directory exists
|
|
||||||
os.makedirs("minimax-output", exist_ok=True)
|
|
||||||
|
|
||||||
prompts = [
|
|
||||||
{
|
|
||||||
"filename": "dog-puggle-fawn-playful.png",
|
|
||||||
"prompt": "Adorable fawn Puggle puppy with playful expression, compact muscular build, professional pet photography, studio lighting, photorealistic"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "dog-puggle-black-sitting.png",
|
|
||||||
"prompt": "Black and tan Puggle with alert sitting posture, pointed beagle-like ears, gentle eyes, professional studio lighting, photorealistic"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "dog-puggle-cream-groomed.png",
|
|
||||||
"prompt": "Cream Puggle freshly groomed with fluffy coat, happy expression, lying down comfortably, natural daylight, photorealistic"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "dog-puggle-tricolor-outdoor.png",
|
|
||||||
"prompt": "Tricolor Puggle in outdoor garden setting, alert playful pose, natural sunlight, professional pet photography, photorealistic"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "dog-puggle-fawn-grooming.png",
|
|
||||||
"prompt": "Fawn Puggle at grooming salon, gentle expression, compact muscular build with beagle-like features, professional grooming setup, warm lighting, photorealistic"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
print(f"Generating {len(prompts)} Puggle images...")
|
|
||||||
|
|
||||||
for item in prompts:
|
|
||||||
filename = item["filename"]
|
|
||||||
prompt = item["prompt"]
|
|
||||||
|
|
||||||
print(f"\nGenerating {filename}...")
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"model": "image-01",
|
|
||||||
"prompt": prompt,
|
|
||||||
"aspect_ratio": "1:1",
|
|
||||||
"response_format": "base64",
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.post(url, headers=headers, json=payload, timeout=60)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
if "data" in data and "image_base64" in data["data"]:
|
|
||||||
images = data["data"]["image_base64"]
|
|
||||||
|
|
||||||
# Save the first (and usually only) image
|
|
||||||
output_path = f"minimax-output/{filename}"
|
|
||||||
with open(output_path, "wb") as f:
|
|
||||||
f.write(base64.b64decode(images[0]))
|
|
||||||
|
|
||||||
file_size = os.path.getsize(output_path)
|
|
||||||
print(f"✓ Saved {filename} ({file_size} bytes)")
|
|
||||||
else:
|
|
||||||
print(f"✗ Unexpected response format: {json.dumps(data, indent=2)}")
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print(f"✗ Error generating {filename}: {e}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Unexpected error for {filename}: {e}")
|
|
||||||
|
|
||||||
print("\n✓ Image generation complete!")
|
|
||||||
print("Files saved to minimax-output/")
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
ALTER TABLE "reminder_logs" DROP CONSTRAINT "reminder_logs_appointment_id_reminder_type_unique";--> statement-breakpoint
|
|
||||||
ALTER TABLE "business_settings" ADD COLUMN "logo_key" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "clients" ADD COLUMN "sms_opt_in" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
|
||||||
ALTER TABLE "clients" ADD COLUMN "sms_consent_date" timestamp;--> statement-breakpoint
|
|
||||||
ALTER TABLE "clients" ADD COLUMN "sms_opt_out_date" timestamp;--> statement-breakpoint
|
|
||||||
ALTER TABLE "clients" ADD COLUMN "sms_consent_text" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "pets" ADD COLUMN "image" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "reminder_logs" ADD COLUMN "channel" text DEFAULT 'email' NOT NULL;--> statement-breakpoint
|
|
||||||
ALTER TABLE "reminder_logs" ADD CONSTRAINT "reminder_logs_appointment_id_reminder_type_channel_unique" UNIQUE("appointment_id","reminder_type","channel");
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
ALTER TABLE "clients" ADD COLUMN "stripe_customer_id" text;
|
||||||
|
ALTER TABLE "clients" ADD CONSTRAINT "idx_clients_stripe_customer_id" UNIQUE("stripe_customer_id");
|
||||||
|
ALTER TABLE "invoices" ADD COLUMN "stripe_payment_intent_id" text;
|
||||||
|
ALTER TABLE "invoices" ADD COLUMN "stripe_refund_id" text;
|
||||||
|
ALTER TABLE "invoices" ADD COLUMN "payment_failure_reason" text;
|
||||||
|
ALTER TABLE "invoices" ADD CONSTRAINT "idx_invoices_stripe_payment_intent_id" UNIQUE("stripe_payment_intent_id");
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
ALTER TABLE "clients" ADD COLUMN "stripe_customer_id" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "clients" ADD CONSTRAINT "idx_clients_stripe_customer_id" UNIQUE("stripe_customer_id");--> statement-breakpoint
|
|
||||||
ALTER TABLE "invoices" ADD COLUMN "stripe_payment_intent_id" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "invoices" ADD COLUMN "stripe_refund_id" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "invoices" ADD COLUMN "payment_failure_reason" text;--> statement-breakpoint
|
|
||||||
ALTER TABLE "invoices" ADD CONSTRAINT "idx_invoices_stripe_payment_intent_id" UNIQUE("stripe_payment_intent_id");
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ALTER TABLE "business_settings" ADD COLUMN "sms_enabled" boolean NOT NULL DEFAULT false;
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "0027_stripe_identifiers",
|
|
||||||
"version": "7",
|
|
||||||
"dialect": "postgresql",
|
|
||||||
"tables": {
|
|
||||||
"authProviderConfig": {
|
|
||||||
"name": "auth_provider_config",
|
|
||||||
"columns": {
|
|
||||||
"id": { "name": "id", "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()", "isNullable": false },
|
|
||||||
"providerId": { "name": "provider_id", "type": "text", "isNullable": false },
|
|
||||||
"displayName": { "name": "display_name", "type": "text", "isNullable": false },
|
|
||||||
"issuerUrl": { "name": "issuer_url", "type": "text", "isNullable": false },
|
|
||||||
"internalBaseUrl": { "name": "internal_base_url", "type": "text", "isNullable": true },
|
|
||||||
"clientId": { "name": "client_id", "type": "text", "isNullable": false },
|
|
||||||
"clientSecret": { "name": "client_secret", "type": "text", "isNullable": false },
|
|
||||||
"scopes": { "name": "scopes", "type": "text", "isNullable": false, "default": "'openid profile email'" },
|
|
||||||
"enabled": { "name": "enabled", "type": "boolean", "isNullable": false, "default": "true" },
|
|
||||||
"createdAt": { "name": "created_at", "type": "timestamp", "isNullable": false, "default": "now()" },
|
|
||||||
"updatedAt": { "name": "updated_at", "type": "timestamp", "isNullable": false, "default": "now()" }
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {}
|
|
||||||
},
|
|
||||||
"businessSettings": {
|
|
||||||
"name": "business_settings",
|
|
||||||
"columns": {
|
|
||||||
"id": { "name": "id", "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()", "isNullable": false },
|
|
||||||
"businessName": { "name": "business_name", "type": "text", "isNullable": false, "default": "'GroomBook'" },
|
|
||||||
"logoBase64": { "name": "logo_base64", "type": "text", "isNullable": true },
|
|
||||||
"logoMimeType": { "name": "logo_mime_type", "type": "text", "isNullable": true },
|
|
||||||
"logoKey": { "name": "logo_key", "type": "text", "isNullable": true },
|
|
||||||
"primaryColor": { "name": "primary_color", "type": "text", "isNullable": false, "default": "'#4f8a6f'" },
|
|
||||||
"accentColor": { "name": "accent_color", "type": "text", "isNullable": false, "default": "'#8b7355'" },
|
|
||||||
"createdAt": { "name": "created_at", "type": "timestamp", "isNullable": false, "default": "now()" },
|
|
||||||
"updatedAt": { "name": "updated_at", "type": "timestamp", "isNullable": false, "default": "now()" }
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {}
|
|
||||||
},
|
|
||||||
"clients": {
|
|
||||||
"name": "clients",
|
|
||||||
"columns": {
|
|
||||||
"id": { "name": "id", "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()", "isNullable": false },
|
|
||||||
"name": { "name": "name", "type": "text", "isNullable": false },
|
|
||||||
"email": { "name": "email", "type": "text", "isNullable": true },
|
|
||||||
"phone": { "name": "phone", "type": "text", "isNullable": true },
|
|
||||||
"address": { "name": "address", "type": "text", "isNullable": true },
|
|
||||||
"notes": { "name": "notes", "type": "text", "isNullable": true },
|
|
||||||
"emailOptOut": { "name": "email_opt_out", "type": "boolean", "isNullable": false, "default": "false" },
|
|
||||||
"smsOptIn": { "name": "sms_opt_in", "type": "boolean", "isNullable": false, "default": "false" },
|
|
||||||
"smsConsentDate": { "name": "sms_consent_date", "type": "timestamp", "isNullable": true },
|
|
||||||
"smsOptOutDate": { "name": "sms_opt_out_date", "type": "timestamp", "isNullable": true },
|
|
||||||
"smsConsentText": { "name": "sms_consent_text", "type": "text", "isNullable": true },
|
|
||||||
"stripeCustomerId": { "name": "stripe_customer_id", "type": "text", "isNullable": true },
|
|
||||||
"status": { "name": "status", "type": "client_status", "isNullable": false, "default": "'active'" },
|
|
||||||
"disabledAt": { "name": "disabled_at", "type": "timestamp", "isNullable": true },
|
|
||||||
"createdAt": { "name": "created_at", "type": "timestamp", "isNullable": false, "default": "now()" },
|
|
||||||
"updatedAt": { "name": "updated_at", "type": "timestamp", "isNullable": false, "default": "now()" }
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": { "idx_clients_stripe_customer_id": { "columns": ["stripe_customer_id"] } }
|
|
||||||
},
|
|
||||||
"invoices": {
|
|
||||||
"name": "invoices",
|
|
||||||
"columns": {
|
|
||||||
"id": { "name": "id", "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()", "isNullable": false },
|
|
||||||
"appointmentId": { "name": "appointment_id", "type": "uuid", "isNullable": true },
|
|
||||||
"clientId": { "name": "client_id", "type": "uuid", "isNullable": false },
|
|
||||||
"subtotalCents": { "name": "subtotal_cents", "type": "integer", "isNullable": false },
|
|
||||||
"taxCents": { "name": "tax_cents", "type": "integer", "isNullable": false, "default": "0" },
|
|
||||||
"tipCents": { "name": "tip_cents", "type": "integer", "isNullable": false, "default": "0" },
|
|
||||||
"totalCents": { "name": "total_cents", "type": "integer", "isNullable": false },
|
|
||||||
"status": { "name": "status", "type": "invoice_status", "isNullable": false, "default": "'draft'" },
|
|
||||||
"paymentMethod": { "name": "payment_method", "type": "payment_method", "isNullable": true },
|
|
||||||
"paidAt": { "name": "paid_at", "type": "timestamp", "isNullable": true },
|
|
||||||
"stripePaymentIntentId": { "name": "stripe_payment_intent_id", "type": "text", "isNullable": true },
|
|
||||||
"stripeRefundId": { "name": "stripe_refund_id", "type": "text", "isNullable": true },
|
|
||||||
"paymentFailureReason": { "name": "payment_failure_reason", "type": "text", "isNullable": true },
|
|
||||||
"notes": { "name": "notes", "type": "text", "isNullable": true },
|
|
||||||
"createdAt": { "name": "created_at", "type": "timestamp", "isNullable": false, "default": "now()" },
|
|
||||||
"updatedAt": { "name": "updated_at", "type": "timestamp", "isNullable": false, "default": "now()" }
|
|
||||||
},
|
|
||||||
"indexes": { "idx_invoices_client_id": { "columns": ["client_id"] }, "idx_invoices_status": { "columns": ["status"] }, "idx_invoices_created_at": { "columns": ["created_at"] } },
|
|
||||||
"foreignKeys": { "invoices_appointment_id_fkey": { "columns": ["appointmentId"], "reference": { "table": "appointments", "columns": ["id"] } }, "invoices_client_id_fkey": { "columns": ["clientId"], "reference": { "table": "clients", "columns": ["id"] } } },
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": { "idx_invoices_stripe_payment_intent_id": { "columns": ["stripe_payment_intent_id"] } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"enums": {
|
|
||||||
"appointment_status": { "name": "appointment_status", "values": ["scheduled", "confirmed", "in_progress", "completed", "cancelled", "no_show"] },
|
|
||||||
"client_status": { "name": "client_status", "values": ["active", "disabled"] },
|
|
||||||
"impersonation_session_status": { "name": "impersonation_session_status", "values": ["active", "ended", "expired"] },
|
|
||||||
"invoice_status": { "name": "invoice_status", "values": ["draft", "pending", "paid", "void"] },
|
|
||||||
"payment_method": { "name": "payment_method", "values": ["cash", "card", "check", "other"] },
|
|
||||||
"staff_role": { "name": "staff_role", "values": ["groomer", "receptionist", "manager"] },
|
|
||||||
"waitlist_status": { "name": "waitlist_status", "values": ["active", "notified", "expired", "cancelled"] }
|
|
||||||
},
|
|
||||||
"nativeEnums": {}
|
|
||||||
}
|
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
{
|
{
|
||||||
"idx": 26,
|
"idx": 26,
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"when": 1776035812477,
|
"when": 1775568867192,
|
||||||
"tag": "0026_boring_storm",
|
"tag": "0026_stripe_payment",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -71,10 +71,7 @@ export function buildClient(overrides: Partial<ClientRow> = {}): ClientRow {
|
|||||||
address: "1 Main St, Springfield, CA 90000",
|
address: "1 Main St, Springfield, CA 90000",
|
||||||
notes: null,
|
notes: null,
|
||||||
emailOptOut: false,
|
emailOptOut: false,
|
||||||
smsOptIn: false,
|
stripeCustomerId: null,
|
||||||
smsConsentDate: null,
|
|
||||||
smsOptOutDate: null,
|
|
||||||
smsConsentText: null,
|
|
||||||
status: "active",
|
status: "active",
|
||||||
disabledAt: null,
|
disabledAt: null,
|
||||||
createdAt: new Date("2025-01-01T00:00:00Z"),
|
createdAt: new Date("2025-01-01T00:00:00Z"),
|
||||||
|
|||||||
@@ -110,10 +110,7 @@ export const clients = pgTable("clients", {
|
|||||||
address: text("address"),
|
address: text("address"),
|
||||||
notes: text("notes"),
|
notes: text("notes"),
|
||||||
emailOptOut: boolean("email_opt_out").notNull().default(false),
|
emailOptOut: boolean("email_opt_out").notNull().default(false),
|
||||||
smsOptIn: boolean("sms_opt_in").notNull().default(false),
|
stripeCustomerId: text("stripe_customer_id"),
|
||||||
smsConsentDate: timestamp("sms_consent_date"),
|
|
||||||
smsOptOutDate: timestamp("sms_opt_out_date"),
|
|
||||||
smsConsentText: text("sms_consent_text"),
|
|
||||||
status: clientStatusEnum("status").notNull().default("active"),
|
status: clientStatusEnum("status").notNull().default("active"),
|
||||||
disabledAt: timestamp("disabled_at"),
|
disabledAt: timestamp("disabled_at"),
|
||||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||||
@@ -254,6 +251,9 @@ export const invoices = pgTable(
|
|||||||
status: invoiceStatusEnum("status").notNull().default("draft"),
|
status: invoiceStatusEnum("status").notNull().default("draft"),
|
||||||
paymentMethod: paymentMethodEnum("payment_method"),
|
paymentMethod: paymentMethodEnum("payment_method"),
|
||||||
paidAt: timestamp("paid_at"),
|
paidAt: timestamp("paid_at"),
|
||||||
|
stripePaymentIntentId: text("stripe_payment_intent_id"),
|
||||||
|
stripeRefundId: text("stripe_refund_id"),
|
||||||
|
paymentFailureReason: text("payment_failure_reason"),
|
||||||
notes: text("notes"),
|
notes: text("notes"),
|
||||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||||
@@ -262,6 +262,7 @@ export const invoices = pgTable(
|
|||||||
index("idx_invoices_client_id").on(t.clientId),
|
index("idx_invoices_client_id").on(t.clientId),
|
||||||
index("idx_invoices_status").on(t.status),
|
index("idx_invoices_status").on(t.status),
|
||||||
index("idx_invoices_created_at").on(t.createdAt),
|
index("idx_invoices_created_at").on(t.createdAt),
|
||||||
|
index("idx_invoices_stripe_payment_intent_id").on(t.stripePaymentIntentId),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -308,11 +309,11 @@ export const reminderLogs = pgTable(
|
|||||||
appointmentId: uuid("appointment_id")
|
appointmentId: uuid("appointment_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => appointments.id, { onDelete: "cascade" }),
|
.references(() => appointments.id, { onDelete: "cascade" }),
|
||||||
|
// "confirmation" | "24h" | "2h"
|
||||||
reminderType: text("reminder_type").notNull(),
|
reminderType: text("reminder_type").notNull(),
|
||||||
channel: text("channel").notNull().default("email"),
|
|
||||||
sentAt: timestamp("sent_at").notNull().defaultNow(),
|
sentAt: timestamp("sent_at").notNull().defaultNow(),
|
||||||
},
|
},
|
||||||
(t) => [unique().on(t.appointmentId, t.reminderType, t.channel)]
|
(t) => [unique().on(t.appointmentId, t.reminderType)]
|
||||||
);
|
);
|
||||||
|
|
||||||
// ─── Impersonation ──────────────────────────────────────────────────────────
|
// ─── Impersonation ──────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -43,9 +43,6 @@ importers:
|
|||||||
stripe:
|
stripe:
|
||||||
specifier: ^22.0.0
|
specifier: ^22.0.0
|
||||||
version: 22.0.1(@types/node@22.19.15)
|
version: 22.0.1(@types/node@22.19.15)
|
||||||
telnyx:
|
|
||||||
specifier: ^6.41.0
|
|
||||||
version: 6.41.0(ws@8.19.0)
|
|
||||||
zod:
|
zod:
|
||||||
specifier: ^4.3.6
|
specifier: ^4.3.6
|
||||||
version: 4.3.6
|
version: 4.3.6
|
||||||
@@ -2115,9 +2112,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-O/IEdcCUKkubz60tFbGA7ceITTAJsty+lBjNoorP4Z6XRqaFb/OjQjZODophEcuq68nKm6/0r+6/lLQ+XVpk8g==}
|
resolution: {integrity: sha512-O/IEdcCUKkubz60tFbGA7ceITTAJsty+lBjNoorP4Z6XRqaFb/OjQjZODophEcuq68nKm6/0r+6/lLQ+XVpk8g==}
|
||||||
engines: {node: '>=18.0.0'}
|
engines: {node: '>=18.0.0'}
|
||||||
|
|
||||||
'@stablelib/base64@1.0.1':
|
|
||||||
resolution: {integrity: sha512-1bnPQqSxSuc3Ii6MhBysoWCg58j97aUjuCSZrGSmDxNqtytIi0k8utUenAwTZN4V5mXXYGsVUI9zeBqy+jBOSQ==}
|
|
||||||
|
|
||||||
'@standard-schema/spec@1.1.0':
|
'@standard-schema/spec@1.1.0':
|
||||||
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
|
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
|
||||||
|
|
||||||
@@ -3099,9 +3093,6 @@ packages:
|
|||||||
fast-levenshtein@2.0.6:
|
fast-levenshtein@2.0.6:
|
||||||
resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==}
|
resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==}
|
||||||
|
|
||||||
fast-sha256@1.3.0:
|
|
||||||
resolution: {integrity: sha512-n11RGP/lrWEFI/bWdygLxhI+pVeo1ZYIVwvvPkW7azl/rOy+F3HYRZ2K5zeE9mmkhQppyv9sQFx0JM9UabnpPQ==}
|
|
||||||
|
|
||||||
fast-uri@3.1.0:
|
fast-uri@3.1.0:
|
||||||
resolution: {integrity: sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==}
|
resolution: {integrity: sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==}
|
||||||
|
|
||||||
@@ -4109,9 +4100,6 @@ packages:
|
|||||||
stackback@0.0.2:
|
stackback@0.0.2:
|
||||||
resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==}
|
resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==}
|
||||||
|
|
||||||
standardwebhooks@1.0.0:
|
|
||||||
resolution: {integrity: sha512-BbHGOQK9olHPMvQNHWul6MYlrRTAOKn03rOe4A8O3CLWhNf4YHBqq2HJKKC+sfqpxiBY52pNeesD6jIiLDz8jg==}
|
|
||||||
|
|
||||||
std-env@3.10.0:
|
std-env@3.10.0:
|
||||||
resolution: {integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==}
|
resolution: {integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==}
|
||||||
|
|
||||||
@@ -4200,14 +4188,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==}
|
resolution: {integrity: sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
telnyx@6.41.0:
|
|
||||||
resolution: {integrity: sha512-93eKksI6HnLYp8e4DGlpC3SkBAfagblE+uug0FNDLT/+mix3PP0RveoQ/YZeRdxDhjMcoXVgeusJsgFP6PvUdw==}
|
|
||||||
peerDependencies:
|
|
||||||
ws: ^8.18.0
|
|
||||||
peerDependenciesMeta:
|
|
||||||
ws:
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
temp-dir@2.0.0:
|
temp-dir@2.0.0:
|
||||||
resolution: {integrity: sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==}
|
resolution: {integrity: sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -6730,8 +6710,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.8.1
|
tslib: 2.8.1
|
||||||
|
|
||||||
'@stablelib/base64@1.0.1': {}
|
|
||||||
|
|
||||||
'@standard-schema/spec@1.1.0': {}
|
'@standard-schema/spec@1.1.0': {}
|
||||||
|
|
||||||
'@standard-schema/utils@0.3.0': {}
|
'@standard-schema/utils@0.3.0': {}
|
||||||
@@ -7777,8 +7755,6 @@ snapshots:
|
|||||||
|
|
||||||
fast-levenshtein@2.0.6: {}
|
fast-levenshtein@2.0.6: {}
|
||||||
|
|
||||||
fast-sha256@1.3.0: {}
|
|
||||||
|
|
||||||
fast-uri@3.1.0: {}
|
fast-uri@3.1.0: {}
|
||||||
|
|
||||||
fast-xml-builder@1.1.4:
|
fast-xml-builder@1.1.4:
|
||||||
@@ -8780,11 +8756,6 @@ snapshots:
|
|||||||
|
|
||||||
stackback@0.0.2: {}
|
stackback@0.0.2: {}
|
||||||
|
|
||||||
standardwebhooks@1.0.0:
|
|
||||||
dependencies:
|
|
||||||
'@stablelib/base64': 1.0.1
|
|
||||||
fast-sha256: 1.3.0
|
|
||||||
|
|
||||||
std-env@3.10.0: {}
|
std-env@3.10.0: {}
|
||||||
|
|
||||||
stop-iteration-iterator@1.1.0:
|
stop-iteration-iterator@1.1.0:
|
||||||
@@ -8887,12 +8858,6 @@ snapshots:
|
|||||||
|
|
||||||
tapable@2.3.0: {}
|
tapable@2.3.0: {}
|
||||||
|
|
||||||
telnyx@6.41.0(ws@8.19.0):
|
|
||||||
dependencies:
|
|
||||||
standardwebhooks: 1.0.0
|
|
||||||
optionalDependencies:
|
|
||||||
ws: 8.19.0
|
|
||||||
|
|
||||||
temp-dir@2.0.0: {}
|
temp-dir@2.0.0: {}
|
||||||
|
|
||||||
tempy@0.6.0:
|
tempy@0.6.0:
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 70 B |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 55 KiB |