-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-fields.ts
More file actions
48 lines (40 loc) · 1.97 KB
/
Copy pathcustom-fields.ts
File metadata and controls
48 lines (40 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { z } from "zod";
import { ENTITY_PATH, positiveId } from "./shared-schemas.js";
import { capsuleGetCached } from "../capsule/client.js";
// Custom field SCHEMA endpoints (read-only here). Each entity type
// (parties, opportunities, projects) has its own custom-field namespace.
//
// GET /<entity>/fields/definitions — list all field definitions
// GET /<entity>/fields/definitions/{id} — show one definition
//
// These describe the SHAPE of custom fields (name, type, options for
// list-type fields, validation rules) — NOT the values on individual
// records. To read values on a record, use the entity's `embed=fields`
// parameter on get_party / get_opportunity / get_project.
//
// Create / update / delete of custom field definitions is admin work
// best done in Capsule's web UI; not exposed.
const CustomFieldEntity = z
.enum(["parties", "opportunities", "projects"])
.describe("Which entity type's custom field schema to inspect.");
// ── List custom field definitions ───────────────────────────────────────────
export const listCustomFieldsSchema = z.object({
entity: CustomFieldEntity,
});
export async function listCustomFields(input: z.infer<typeof listCustomFieldsSchema>) {
const { data } = await capsuleGetCached<{ definitions: unknown[] }>(
`/${ENTITY_PATH[input.entity]}/fields/definitions`,
);
return data;
}
// ── Show one custom field definition ────────────────────────────────────────
export const getCustomFieldSchema = z.object({
entity: CustomFieldEntity,
id: positiveId.describe("Custom field definition id."),
});
export async function getCustomField(input: z.infer<typeof getCustomFieldSchema>) {
const { data } = await capsuleGetCached<{ definition: unknown }>(
`/${ENTITY_PATH[input.entity]}/fields/definitions/${input.id}`,
);
return data;
}