Files
outline/plugins/granola/server/api/schema.ts
T
Tom Moor ba2d9888cc feat: Granola integration (#14906)
* wip

* fix: Address review feedback on Granola integration

- Limit the size of Granola API responses
- Load the team when authorizing notes into personal collections
- Add the user's connection from granola.list to the integrations store

* feat: Connect Granola from a dialog

* fix: Accept Granola webhook test events

* Copy pass

* Copy pass
2026-12-05 14:59:12 -05:00

65 lines
1.8 KiB
TypeScript

import { z } from "zod";
import { BaseSchema } from "@server/routes/api/schema";
export const GranolaConnectSchema = BaseSchema.extend({
body: z.object({
/** A personal Granola API key. */
apiKey: z.string().trim().min(1).max(255),
}),
});
export type GranolaConnectReq = z.infer<typeof GranolaConnectSchema>;
export const GranolaFoldersSchema = BaseSchema.extend({
body: z.object({
/** The ID of the Granola integration. */
id: z.uuid(),
}),
});
export type GranolaFoldersReq = z.infer<typeof GranolaFoldersSchema>;
const RuleSchema = z
.object({
folderId: z.string().min(1).max(255).nullable(),
folderName: z.string().max(255).optional(),
collectionId: z.uuid().optional(),
documentId: z.uuid().optional(),
locationName: z.string().max(255).optional(),
})
.refine((rule) => !rule.collectionId !== !rule.documentId, {
message: "One of collectionId or documentId is required",
});
export const GranolaUpdateSchema = BaseSchema.extend({
body: z.object({
/** The ID of the Granola integration. */
id: z.uuid(),
/** The rules that choose where notes go. */
rules: z
.array(RuleSchema)
.max(50)
.refine(
(rules) =>
new Set(rules.map((rule) => rule.folderId)).size === rules.length,
{ message: "Each Granola folder can have only one rule" }
),
}),
});
export type GranolaUpdateReq = z.infer<typeof GranolaUpdateSchema>;
export const GranolaWebhookSchema = BaseSchema.extend({
query: z.object({
/** The ID of the Granola integration that the webhook belongs to. */
id: z.uuid(),
}),
body: z.object({
event_type: z.string(),
/** Missing on events that are not about a note, such as webhook.test. */
note_id: z.string().optional(),
}),
});
export type GranolaWebhookReq = z.infer<typeof GranolaWebhookSchema>;