62e0a1db88
* feat: add contact-book variable registry for campaign personalization * test: include contact-book variables default in service expectation * fix: address personalization review issues * fix text * fix: normalize contact variable access across contact flows * stuff * fix
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import { createRoute, z } from "@hono/zod-openapi";
|
|
import { ContactBookSchema } from "~/lib/zod/contact-book-schema";
|
|
import { PublicAPIApp } from "~/server/public-api/hono";
|
|
import { updateContactBook as updateContactBookService } from "~/server/service/contact-book-service";
|
|
import { getContactBook } from "../../api-utils";
|
|
|
|
const route = createRoute({
|
|
method: "patch",
|
|
path: "/v1/contactBooks/{contactBookId}",
|
|
request: {
|
|
params: z.object({
|
|
contactBookId: z.string().openapi({
|
|
param: {
|
|
name: "contactBookId",
|
|
in: "path",
|
|
},
|
|
example: "clx1234567890",
|
|
}),
|
|
}),
|
|
body: {
|
|
required: true,
|
|
content: {
|
|
"application/json": {
|
|
schema: z.object({
|
|
name: z.string().min(1).optional(),
|
|
emoji: z.string().optional(),
|
|
properties: z.record(z.string()).optional(),
|
|
doubleOptInEnabled: z.boolean().optional(),
|
|
doubleOptInFrom: z.string().nullable().optional(),
|
|
doubleOptInSubject: z.string().optional(),
|
|
doubleOptInContent: z.string().optional(),
|
|
variables: z.array(z.string()).optional(),
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
responses: {
|
|
200: {
|
|
content: {
|
|
"application/json": {
|
|
schema: ContactBookSchema,
|
|
},
|
|
},
|
|
description: "Update the contact book",
|
|
},
|
|
403: {
|
|
content: {
|
|
"application/json": {
|
|
schema: z.object({
|
|
error: z.string(),
|
|
}),
|
|
},
|
|
},
|
|
description:
|
|
"Forbidden - API key doesn't have access to this contact book",
|
|
},
|
|
404: {
|
|
content: {
|
|
"application/json": {
|
|
schema: z.object({
|
|
error: z.string(),
|
|
}),
|
|
},
|
|
},
|
|
description: "Contact book not found",
|
|
},
|
|
},
|
|
});
|
|
|
|
function updateContactBook(app: PublicAPIApp) {
|
|
app.openapi(route, async (c) => {
|
|
const team = c.var.team;
|
|
const contactBookId = c.req.valid("param").contactBookId;
|
|
const body = c.req.valid("json");
|
|
|
|
await getContactBook(c, team.id);
|
|
|
|
const updated = await updateContactBookService(contactBookId, body);
|
|
|
|
return c.json({
|
|
...updated,
|
|
properties: updated.properties as Record<string, string>,
|
|
variables: updated.variables,
|
|
});
|
|
});
|
|
}
|
|
|
|
export default updateContactBook;
|