-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit.ts
More file actions
89 lines (76 loc) · 3.12 KB
/
Copy pathaudit.ts
File metadata and controls
89 lines (76 loc) · 3.12 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { z } from "zod";
import { positiveId, paginationFields, embedParam, RECORD_EMBEDS } from "./shared-schemas.js";
import { capsuleGetList } from "../capsule/client.js";
// Audit & navigation tools that don't fit cleanly under a single entity.
//
// list_employees(partyId) — people who work at an organisation
// list_deleted_parties(since) — audit: parties deleted since a date
// list_deleted_opportunities(since) — audit: opportunities deleted since a date
// list_deleted_projects(since) — audit: projects deleted since a date
//
// All deleted-* endpoints REQUIRE the `since` parameter (Capsule returns
// 422 without it). They also include a `restrictedParties` /
// `restrictedOpportunities` / `restrictedProjects` sibling key in the
// response: records that the integration user can see were deleted but
// cannot read in full. We surface both keys verbatim.
// ── Employees of an organisation ────────────────────────────────────────────
export const listEmployeesSchema = z.object({
partyId: positiveId.describe(
"The organisation's party id. Returns the people whose `organisation` field links to this party.",
),
...paginationFields,
embed: embedParam(RECORD_EMBEDS),
});
export async function listEmployees(input: z.infer<typeof listEmployeesSchema>) {
return capsuleGetList<{ parties: unknown[] }>(`/parties/${input.partyId}/people`, {
page: input.page,
perPage: input.perPage,
embed: input.embed,
});
}
// ── Deleted entities (audit) ────────────────────────────────────────────────
const DeletedSinceSchema = z
.string()
.describe(
"REQUIRED. ISO-8601 timestamp; only deletions on or after this point are returned. Example: '2026-01-01T00:00:00Z'.",
);
const DeletedPagination = {
since: DeletedSinceSchema,
...paginationFields,
};
export const listDeletedPartiesSchema = z.object(DeletedPagination);
export async function listDeletedParties(input: z.infer<typeof listDeletedPartiesSchema>) {
return capsuleGetList<{
parties: unknown[];
restrictedParties?: unknown[];
}>("/parties/deleted", {
since: input.since,
page: input.page,
perPage: input.perPage,
});
}
export const listDeletedOpportunitiesSchema = z.object(DeletedPagination);
export async function listDeletedOpportunities(
input: z.infer<typeof listDeletedOpportunitiesSchema>,
) {
return capsuleGetList<{
opportunities: unknown[];
restrictedOpportunities?: unknown[];
}>("/opportunities/deleted", {
since: input.since,
page: input.page,
perPage: input.perPage,
});
}
export const listDeletedProjectsSchema = z.object(DeletedPagination);
export async function listDeletedProjects(input: z.infer<typeof listDeletedProjectsSchema>) {
// Capsule's API uses /kases for projects.
return capsuleGetList<{
projects: unknown[];
restrictedProjects?: unknown[];
}>("/kases/deleted", {
since: input.since,
page: input.page,
perPage: input.perPage,
});
}