@uidu/client 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +56 -0
  3. package/dist/declarations/src/bookings.d.ts +58 -0
  4. package/dist/declarations/src/calls.d.ts +26 -0
  5. package/dist/declarations/src/campaigns.d.ts +39 -0
  6. package/dist/declarations/src/client.d.ts +10 -0
  7. package/dist/declarations/src/cms.d.ts +75 -0
  8. package/dist/declarations/src/contacts.d.ts +36 -0
  9. package/dist/declarations/src/courses.d.ts +68 -0
  10. package/dist/declarations/src/donations.d.ts +51 -0
  11. package/dist/declarations/src/events.d.ts +59 -0
  12. package/dist/declarations/src/forms.d.ts +69 -0
  13. package/dist/declarations/src/generated/index.d.ts +45354 -0
  14. package/dist/declarations/src/help-center.d.ts +4 -0
  15. package/dist/declarations/src/index.d.ts +39 -0
  16. package/dist/declarations/src/kb.d.ts +30 -0
  17. package/dist/declarations/src/mutations.d.ts +515 -0
  18. package/dist/declarations/src/notes.d.ts +18 -0
  19. package/dist/declarations/src/people.d.ts +53 -0
  20. package/dist/declarations/src/search.d.ts +4 -0
  21. package/dist/declarations/src/spaces.d.ts +19 -0
  22. package/dist/declarations/src/stories.d.ts +28 -0
  23. package/dist/declarations/src/system.d.ts +36 -0
  24. package/dist/declarations/src/tasks.d.ts +16 -0
  25. package/dist/declarations/src/types.d.ts +19 -0
  26. package/dist/declarations/src/utils/paginate.d.ts +34 -0
  27. package/dist/uidu-client.cjs.d.ts +2 -2
  28. package/dist/uidu-client.cjs.dev.js +682 -0
  29. package/dist/uidu-client.cjs.js +6 -15
  30. package/dist/uidu-client.cjs.prod.js +682 -0
  31. package/dist/uidu-client.esm.js +560 -0
  32. package/package.json +8 -3
  33. package/src/cms.ts +43 -0
  34. package/src/donations.ts +10 -0
  35. package/src/events.ts +10 -0
  36. package/src/generated/index.ts +2967 -84
  37. package/src/index.ts +70 -5
  38. package/src/mutations.test.ts +43 -0
  39. package/src/mutations.ts +216 -0
  40. package/src/notes.ts +15 -0
  41. package/src/people.test.ts +63 -0
  42. package/src/people.ts +93 -0
  43. package/src/queries/cms/CreateFieldValue.graphql +16 -0
  44. package/src/queries/cms/CreatePage.graphql +15 -0
  45. package/src/queries/cms/CreatePageBlock.graphql +14 -0
  46. package/src/queries/cms/CreateProject.graphql +16 -0
  47. package/src/queries/contacts/ContactMutations.graphql +53 -0
  48. package/src/queries/courses/CourseMutations.graphql +38 -0
  49. package/src/queries/donations/CreateDonationCampaign.graphql +13 -0
  50. package/src/queries/donations/DonationCampaignMutations.graphql +25 -0
  51. package/src/queries/events/CreateEvent.graphql +13 -0
  52. package/src/queries/events/UpdateEvent.graphql +12 -0
  53. package/src/queries/forms/FormMutations.graphql +40 -0
  54. package/src/queries/help-center/ChannelMutations.graphql +40 -0
  55. package/src/queries/kb/KbMutations.graphql +81 -0
  56. package/src/queries/notes/CreateNote.graphql +14 -0
  57. package/src/queries/notes/NoteMutations.graphql +25 -0
  58. package/src/queries/people/ListCircles.graphql +17 -0
  59. package/src/queries/people/ListKinds.graphql +18 -0
  60. package/src/queries/people/ListOffices.graphql +16 -0
  61. package/src/queries/people/PeopleMutations.graphql +88 -0
  62. package/src/queries/spaces/CreateSpace.graphql +15 -0
  63. package/src/queries/spaces/SpaceMutations.graphql +25 -0
  64. package/src/queries/stories/CreateStory.graphql +13 -0
  65. package/src/queries/stories/UpdateStory.graphql +12 -0
  66. package/src/queries/system/CreateWorkspace.graphql +15 -0
  67. package/src/queries/system/GenerateWorkspaceApiCredentials.graphql +18 -0
  68. package/src/queries/tasks/CreateTask.graphql +13 -0
  69. package/src/queries/tasks/TaskMutations.graphql +25 -0
  70. package/src/spaces.ts +15 -0
  71. package/src/stories.ts +10 -0
  72. package/src/system.ts +33 -0
  73. package/src/tasks.ts +15 -0
  74. package/src/utils/paginate.test.ts +116 -0
  75. package/src/utils/relay.test.ts +35 -0
package/src/index.ts CHANGED
@@ -26,9 +26,64 @@ export {
26
26
  ListStoriesDocument,
27
27
  } from './generated';
28
28
 
29
- export { getPage, listPages, getTemplate } from './cms';
29
+ export {
30
+ getPage,
31
+ listPages,
32
+ getTemplate,
33
+ createProject,
34
+ createPage,
35
+ createPageBlock,
36
+ createFieldValue,
37
+ } from './cms';
30
38
  export type { Page, Template } from './cms';
31
39
 
40
+ export {
41
+ createWorkspace,
42
+ generateWorkspaceApiCredentials,
43
+ } from './system';
44
+
45
+ export { createSpace } from './spaces';
46
+ export { createTask } from './tasks';
47
+ export { createNote } from './notes';
48
+
49
+ export {
50
+ createCourse,
51
+ updateCourse,
52
+ deleteCourse,
53
+ createForm,
54
+ updateForm,
55
+ deleteForm,
56
+ createContact,
57
+ deleteContact,
58
+ createDeal,
59
+ updateDeal,
60
+ createKbCollection,
61
+ updateKbCollection,
62
+ deleteKbCollection,
63
+ createKbArticle,
64
+ updateKbArticle,
65
+ deleteKbArticle,
66
+ createChannel,
67
+ updateChannel,
68
+ deleteChannel,
69
+ updateEvent,
70
+ updateStory,
71
+ updateDonationCampaign,
72
+ deleteDonationCampaign,
73
+ updateTask,
74
+ deleteTask,
75
+ updateNote,
76
+ deleteNote,
77
+ updateSpace,
78
+ deleteSpace,
79
+ createEmployee,
80
+ updateEmployee,
81
+ createEmployment,
82
+ updateEmployment,
83
+ deleteEmployment,
84
+ terminateEmployment,
85
+ } from './mutations';
86
+
32
87
  export {
33
88
  getForm,
34
89
  listForms,
@@ -43,7 +98,7 @@ export type { Channel } from './help-center';
43
98
  export { search } from './search';
44
99
  export type { SearchResult } from './search';
45
100
 
46
- export { getEvent, listEvents, createAttendance } from './events';
101
+ export { getEvent, listEvents, createAttendance, createEvent } from './events';
47
102
  export type { Event } from './events';
48
103
 
49
104
  export { getCall, listCalls } from './calls';
@@ -53,14 +108,24 @@ export {
53
108
  getDonationCampaign,
54
109
  listDonationCampaigns,
55
110
  createDonation,
111
+ createDonationCampaign,
56
112
  } from './donations';
57
113
  export type { DonationCampaign } from './donations';
58
114
 
59
- export { getStory, listStories } from './stories';
115
+ export { getStory, listStories, createStory } from './stories';
60
116
  export type { Story } from './stories';
61
117
 
62
- export { listEmployees, getEmployee, weekStartFor } from './people';
63
- export type { Employee } from './people';
118
+ export {
119
+ listEmployees,
120
+ getEmployee,
121
+ weekStartFor,
122
+ listOffices,
123
+ listCircles,
124
+ listRoles,
125
+ listKinds,
126
+ listCcnls,
127
+ } from './people';
128
+ export type { Employee, Office, Circle, Kind } from './people';
64
129
 
65
130
  export {
66
131
  getBooking,
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { UiduClient } from './client';
3
+ import { terminateEmployment } from './mutations';
4
+
5
+ describe('terminateEmployment', () => {
6
+ it('closes an employment via updateEmployment with endDate + endReason', async () => {
7
+ const mutate = vi
8
+ .fn()
9
+ .mockResolvedValue({ updateEmployment: { employment: { id: 'e1' }, errors: [] } });
10
+ const client = { mutate } as unknown as UiduClient;
11
+
12
+ const result = await terminateEmployment(client, {
13
+ id: 'e1',
14
+ endDate: '2026-07-31',
15
+ endReason: 'resignation',
16
+ });
17
+
18
+ expect(mutate).toHaveBeenCalledTimes(1);
19
+ const variables = mutate.mock.calls[0][1];
20
+ expect(variables).toEqual({
21
+ input: {
22
+ id: 'e1',
23
+ attributes: { endDate: '2026-07-31', endReason: 'resignation' },
24
+ },
25
+ });
26
+ expect(result).toEqual({ employment: { id: 'e1' }, errors: [] });
27
+ });
28
+
29
+ it('leaves endReason undefined when not provided', async () => {
30
+ const mutate = vi
31
+ .fn()
32
+ .mockResolvedValue({ updateEmployment: { employment: { id: 'e2' }, errors: [] } });
33
+ const client = { mutate } as unknown as UiduClient;
34
+
35
+ await terminateEmployment(client, { id: 'e2', endDate: '2026-08-15' });
36
+
37
+ const variables = mutate.mock.calls[0][1];
38
+ expect(variables.input.attributes).toEqual({
39
+ endDate: '2026-08-15',
40
+ endReason: undefined,
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,216 @@
1
+ // Authoring mutations (create / update / delete) added for the CLI + server-side
2
+ // provisioning. All require a Bearer token (client `apiKey`) and run under the
3
+ // backend's Pundit authorization. Each returns the mutation payload (including
4
+ // an `errors` array) or null. Grouped here to keep the authoring surface in one
5
+ // place; read functions stay in their per-scope domain files.
6
+ import type { UiduClient } from './client';
7
+ import {
8
+ CreateChannelDocument,
9
+ type CreateChannelMutationVariables,
10
+ CreateContactDocument,
11
+ type CreateContactMutationVariables,
12
+ CreateCourseDocument,
13
+ type CreateCourseMutationVariables,
14
+ CreateDealDocument,
15
+ type CreateDealMutationVariables,
16
+ CreateEmployeeDocument,
17
+ type CreateEmployeeMutationVariables,
18
+ CreateEmploymentDocument,
19
+ type CreateEmploymentMutationVariables,
20
+ CreateFormDocument,
21
+ type CreateFormMutationVariables,
22
+ CreateKbArticleDocument,
23
+ type CreateKbArticleMutationVariables,
24
+ CreateKbCollectionDocument,
25
+ type CreateKbCollectionMutationVariables,
26
+ DeleteChannelDocument,
27
+ type DeleteChannelMutationVariables,
28
+ DeleteContactDocument,
29
+ type DeleteContactMutationVariables,
30
+ DeleteCourseDocument,
31
+ type DeleteCourseMutationVariables,
32
+ DeleteDonationCampaignDocument,
33
+ type DeleteDonationCampaignMutationVariables,
34
+ DeleteEmploymentDocument,
35
+ type DeleteEmploymentMutationVariables,
36
+ DeleteFormDocument,
37
+ type DeleteFormMutationVariables,
38
+ DeleteKbArticleDocument,
39
+ type DeleteKbArticleMutationVariables,
40
+ DeleteKbCollectionDocument,
41
+ type DeleteKbCollectionMutationVariables,
42
+ DeleteNoteDocument,
43
+ type DeleteNoteMutationVariables,
44
+ DeleteSpaceDocument,
45
+ type DeleteSpaceMutationVariables,
46
+ DeleteTaskDocument,
47
+ type DeleteTaskMutationVariables,
48
+ UpdateChannelDocument,
49
+ type UpdateChannelMutationVariables,
50
+ UpdateCourseDocument,
51
+ type UpdateCourseMutationVariables,
52
+ UpdateDealDocument,
53
+ type UpdateDealMutationVariables,
54
+ UpdateDonationCampaignDocument,
55
+ type UpdateDonationCampaignMutationVariables,
56
+ UpdateEmployeeDocument,
57
+ type UpdateEmployeeMutationVariables,
58
+ UpdateEmploymentDocument,
59
+ type UpdateEmploymentMutationVariables,
60
+ UpdateEventDocument,
61
+ type UpdateEventMutationVariables,
62
+ UpdateFormDocument,
63
+ type UpdateFormMutationVariables,
64
+ UpdateKbArticleDocument,
65
+ type UpdateKbArticleMutationVariables,
66
+ UpdateKbCollectionDocument,
67
+ type UpdateKbCollectionMutationVariables,
68
+ UpdateNoteDocument,
69
+ type UpdateNoteMutationVariables,
70
+ UpdateSpaceDocument,
71
+ type UpdateSpaceMutationVariables,
72
+ UpdateStoryDocument,
73
+ type UpdateStoryMutationVariables,
74
+ UpdateTaskDocument,
75
+ type UpdateTaskMutationVariables,
76
+ } from './generated';
77
+
78
+ // --- Courses ---
79
+ export async function createCourse(c: UiduClient, v: CreateCourseMutationVariables) {
80
+ return (await c.mutate(CreateCourseDocument, v)).createCourse ?? null;
81
+ }
82
+ export async function updateCourse(c: UiduClient, v: UpdateCourseMutationVariables) {
83
+ return (await c.mutate(UpdateCourseDocument, v)).updateCourse ?? null;
84
+ }
85
+ export async function deleteCourse(c: UiduClient, v: DeleteCourseMutationVariables) {
86
+ return (await c.mutate(DeleteCourseDocument, v)).deleteCourse ?? null;
87
+ }
88
+
89
+ // --- Forms ---
90
+ export async function createForm(c: UiduClient, v: CreateFormMutationVariables) {
91
+ return (await c.mutate(CreateFormDocument, v)).createForm ?? null;
92
+ }
93
+ export async function updateForm(c: UiduClient, v: UpdateFormMutationVariables) {
94
+ return (await c.mutate(UpdateFormDocument, v)).updateForm ?? null;
95
+ }
96
+ export async function deleteForm(c: UiduClient, v: DeleteFormMutationVariables) {
97
+ return (await c.mutate(DeleteFormDocument, v)).deleteForm ?? null;
98
+ }
99
+
100
+ // --- Contacts & Deals ---
101
+ export async function createContact(c: UiduClient, v: CreateContactMutationVariables) {
102
+ return (await c.mutate(CreateContactDocument, v)).createContact ?? null;
103
+ }
104
+ export async function deleteContact(c: UiduClient, v: DeleteContactMutationVariables) {
105
+ return (await c.mutate(DeleteContactDocument, v)).deleteContact ?? null;
106
+ }
107
+ export async function createDeal(c: UiduClient, v: CreateDealMutationVariables) {
108
+ return (await c.mutate(CreateDealDocument, v)).createDeal ?? null;
109
+ }
110
+ export async function updateDeal(c: UiduClient, v: UpdateDealMutationVariables) {
111
+ return (await c.mutate(UpdateDealDocument, v)).updateDeal ?? null;
112
+ }
113
+
114
+ // --- People / HR (employees & employments) ---
115
+ // An Employee is the HR record wrapping a workspace User (`userId`); an
116
+ // Employment is a single contract (start/end dates, contract type, CCNL, role,
117
+ // offices, FTE…). A hire = createEmployment; a termination = updateEmployment
118
+ // with an `endDate` + `endReason` (see `terminateEmployment`); a contract
119
+ // variation = a new createEmployment (or updateEmployment on the current one).
120
+ export async function createEmployee(c: UiduClient, v: CreateEmployeeMutationVariables) {
121
+ return (await c.mutate(CreateEmployeeDocument, v)).createEmployee ?? null;
122
+ }
123
+ export async function updateEmployee(c: UiduClient, v: UpdateEmployeeMutationVariables) {
124
+ return (await c.mutate(UpdateEmployeeDocument, v)).updateEmployee ?? null;
125
+ }
126
+ export async function createEmployment(c: UiduClient, v: CreateEmploymentMutationVariables) {
127
+ return (await c.mutate(CreateEmploymentDocument, v)).createEmployment ?? null;
128
+ }
129
+ export async function updateEmployment(c: UiduClient, v: UpdateEmploymentMutationVariables) {
130
+ return (await c.mutate(UpdateEmploymentDocument, v)).updateEmployment ?? null;
131
+ }
132
+ export async function deleteEmployment(c: UiduClient, v: DeleteEmploymentMutationVariables) {
133
+ return (await c.mutate(DeleteEmploymentDocument, v)).deleteEmployment ?? null;
134
+ }
135
+
136
+ /**
137
+ * Terminate (cessazione) an employment by closing it with an end date and
138
+ * reason. Thin semantic wrapper over {@link updateEmployment}.
139
+ * `endReason` is one of: resignation, termination, contract_end, retirement, other.
140
+ */
141
+ export async function terminateEmployment(
142
+ c: UiduClient,
143
+ args: { id: string; endDate: string; endReason?: string },
144
+ ) {
145
+ return updateEmployment(c, {
146
+ input: {
147
+ id: args.id,
148
+ attributes: { endDate: args.endDate, endReason: args.endReason },
149
+ },
150
+ });
151
+ }
152
+
153
+ // --- Knowledge base ---
154
+ export async function createKbCollection(c: UiduClient, v: CreateKbCollectionMutationVariables) {
155
+ return (await c.mutate(CreateKbCollectionDocument, v)).createKbCollection ?? null;
156
+ }
157
+ export async function updateKbCollection(c: UiduClient, v: UpdateKbCollectionMutationVariables) {
158
+ return (await c.mutate(UpdateKbCollectionDocument, v)).updateKbCollection ?? null;
159
+ }
160
+ export async function deleteKbCollection(c: UiduClient, v: DeleteKbCollectionMutationVariables) {
161
+ return (await c.mutate(DeleteKbCollectionDocument, v)).deleteKbCollection ?? null;
162
+ }
163
+ export async function createKbArticle(c: UiduClient, v: CreateKbArticleMutationVariables) {
164
+ return (await c.mutate(CreateKbArticleDocument, v)).createKbArticle ?? null;
165
+ }
166
+ export async function updateKbArticle(c: UiduClient, v: UpdateKbArticleMutationVariables) {
167
+ return (await c.mutate(UpdateKbArticleDocument, v)).updateKbArticle ?? null;
168
+ }
169
+ export async function deleteKbArticle(c: UiduClient, v: DeleteKbArticleMutationVariables) {
170
+ return (await c.mutate(DeleteKbArticleDocument, v)).deleteKbArticle ?? null;
171
+ }
172
+
173
+ // --- Help center channels ---
174
+ export async function createChannel(c: UiduClient, v: CreateChannelMutationVariables) {
175
+ return (await c.mutate(CreateChannelDocument, v)).createChannel ?? null;
176
+ }
177
+ export async function updateChannel(c: UiduClient, v: UpdateChannelMutationVariables) {
178
+ return (await c.mutate(UpdateChannelDocument, v)).updateChannel ?? null;
179
+ }
180
+ export async function deleteChannel(c: UiduClient, v: DeleteChannelMutationVariables) {
181
+ return (await c.mutate(DeleteChannelDocument, v)).deleteChannel ?? null;
182
+ }
183
+
184
+ // --- Content updates (create lives in the scope's domain file) ---
185
+ export async function updateEvent(c: UiduClient, v: UpdateEventMutationVariables) {
186
+ return (await c.mutate(UpdateEventDocument, v)).updateEvent ?? null;
187
+ }
188
+ export async function updateStory(c: UiduClient, v: UpdateStoryMutationVariables) {
189
+ return (await c.mutate(UpdateStoryDocument, v)).updateStory ?? null;
190
+ }
191
+ export async function updateDonationCampaign(c: UiduClient, v: UpdateDonationCampaignMutationVariables) {
192
+ return (await c.mutate(UpdateDonationCampaignDocument, v)).updateDonationCampaign ?? null;
193
+ }
194
+ export async function deleteDonationCampaign(c: UiduClient, v: DeleteDonationCampaignMutationVariables) {
195
+ return (await c.mutate(DeleteDonationCampaignDocument, v)).deleteDonationCampaign ?? null;
196
+ }
197
+
198
+ // --- Tasks / Notes / Spaces (create lives in their domain files) ---
199
+ export async function updateTask(c: UiduClient, v: UpdateTaskMutationVariables) {
200
+ return (await c.mutate(UpdateTaskDocument, v)).updateTask ?? null;
201
+ }
202
+ export async function deleteTask(c: UiduClient, v: DeleteTaskMutationVariables) {
203
+ return (await c.mutate(DeleteTaskDocument, v)).deleteTask ?? null;
204
+ }
205
+ export async function updateNote(c: UiduClient, v: UpdateNoteMutationVariables) {
206
+ return (await c.mutate(UpdateNoteDocument, v)).updateNote ?? null;
207
+ }
208
+ export async function deleteNote(c: UiduClient, v: DeleteNoteMutationVariables) {
209
+ return (await c.mutate(DeleteNoteDocument, v)).deleteNote ?? null;
210
+ }
211
+ export async function updateSpace(c: UiduClient, v: UpdateSpaceMutationVariables) {
212
+ return (await c.mutate(UpdateSpaceDocument, v)).updateSpace ?? null;
213
+ }
214
+ export async function deleteSpace(c: UiduClient, v: DeleteSpaceMutationVariables) {
215
+ return (await c.mutate(DeleteSpaceDocument, v)).deleteSpace ?? null;
216
+ }
package/src/notes.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { UiduClient } from './client';
2
+ import {
3
+ CreateNoteDocument,
4
+ type CreateNoteMutationVariables,
5
+ } from './generated';
6
+
7
+ // Authoring (Bearer / doorkeeper token). Returns the payload, incl. `errors`.
8
+
9
+ export async function createNote(
10
+ client: UiduClient,
11
+ variables: CreateNoteMutationVariables,
12
+ ) {
13
+ const result = await client.mutate(CreateNoteDocument, variables);
14
+ return result.createNote ?? null;
15
+ }
@@ -0,0 +1,63 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { UiduClient } from './client';
3
+ import { listCcnls, listRoles, weekStartFor } from './people';
4
+
5
+ /** Minimal fake client whose `query` returns a fixed `currentWorkspace` payload. */
6
+ function fakeClient(currentWorkspace: unknown) {
7
+ const query = vi.fn().mockResolvedValue({ currentWorkspace });
8
+ return { client: { query } as unknown as UiduClient, query };
9
+ }
10
+
11
+ function circleEdges(...circles: Array<{ id: string; name: string; kind: string }>) {
12
+ return { circles: { edges: circles.map((node) => ({ node })) } };
13
+ }
14
+
15
+ describe('weekStartFor', () => {
16
+ it('returns the week Monday for a Wednesday', () => {
17
+ // 2026-07-08 is a Wednesday.
18
+ const date = new Date(Date.UTC(2026, 6, 8));
19
+ expect(weekStartFor(date)).toBe('2026-07-06');
20
+ });
21
+
22
+ it('returns the same date for a Monday', () => {
23
+ // 2026-07-06 is a Monday.
24
+ const date = new Date(Date.UTC(2026, 6, 6));
25
+ expect(weekStartFor(date)).toBe('2026-07-06');
26
+ });
27
+
28
+ it('returns the previous Monday for a Sunday', () => {
29
+ // 2026-07-12 is a Sunday; the previous Monday is 2026-07-06.
30
+ const date = new Date(Date.UTC(2026, 6, 12));
31
+ expect(weekStartFor(date)).toBe('2026-07-06');
32
+ });
33
+
34
+ it('crosses a month boundary correctly', () => {
35
+ // 2026-08-02 is a Sunday; the previous Monday is 2026-07-27 (prior month).
36
+ const date = new Date(Date.UTC(2026, 7, 2));
37
+ expect(weekStartFor(date)).toBe('2026-07-27');
38
+ });
39
+ });
40
+
41
+ describe('listRoles', () => {
42
+ it('keeps only role-Circles and drops org-unit circles', async () => {
43
+ const { client } = fakeClient(
44
+ circleEdges(
45
+ { id: '1', name: 'Engineering', kind: 'circle' },
46
+ { id: '2', name: 'Developer', kind: 'role' },
47
+ { id: '3', name: 'Designer', kind: 'role' },
48
+ ),
49
+ );
50
+ const roles = await listRoles(client);
51
+ expect(roles.map((r) => r.name)).toEqual(['Developer', 'Designer']);
52
+ });
53
+ });
54
+
55
+ describe('listCcnls', () => {
56
+ it('queries kinds scoped to the Ccnl model', async () => {
57
+ const { client, query } = fakeClient({ kinds: { edges: [] } });
58
+ await listCcnls(client);
59
+ expect(query).toHaveBeenCalledTimes(1);
60
+ const variables = query.mock.calls[0][1];
61
+ expect(variables).toMatchObject({ models: ['Ccnl'] });
62
+ });
63
+ });
package/src/people.ts CHANGED
@@ -3,15 +3,54 @@ import {
3
3
  GetEmployeeDocument,
4
4
  type GetEmployeeQuery,
5
5
  type GetEmployeeQueryVariables,
6
+ ListCirclesDocument,
7
+ type ListCirclesQuery,
8
+ type ListCirclesQueryVariables,
6
9
  ListEmployeesDocument,
7
10
  type ListEmployeesQueryVariables,
11
+ ListKindsDocument,
12
+ type ListKindsQuery,
13
+ type ListKindsQueryVariables,
14
+ ListOfficesDocument,
15
+ type ListOfficesQuery,
16
+ type ListOfficesQueryVariables,
8
17
  } from './generated';
18
+
9
19
  import { nodes } from './utils/relay';
10
20
 
11
21
  export type Employee = NonNullable<
12
22
  NonNullable<GetEmployeeQuery['currentWorkspace']>['employee']
13
23
  >;
14
24
 
25
+ export type Circle = NonNullable<
26
+ NonNullable<
27
+ NonNullable<
28
+ NonNullable<
29
+ NonNullable<ListCirclesQuery['currentWorkspace']>['circles']
30
+ >['edges']
31
+ >[number]
32
+ >['node']
33
+ >;
34
+ export type Office = NonNullable<
35
+ NonNullable<
36
+ NonNullable<
37
+ NonNullable<
38
+ NonNullable<ListOfficesQuery['currentWorkspace']>['offices']
39
+ >['edges']
40
+ >[number]
41
+ >['node']
42
+ >;
43
+ /** A `Kind` record — CCNLs (national collective labor contracts) are Kinds. */
44
+ export type Kind = NonNullable<
45
+ NonNullable<
46
+ NonNullable<
47
+ NonNullable<
48
+ NonNullable<ListKindsQuery['currentWorkspace']>['kinds']
49
+ >['edges']
50
+ >[number]
51
+ >['node']
52
+ >;
53
+
15
54
  export async function listEmployees(
16
55
  client: UiduClient,
17
56
  variables: ListEmployeesQueryVariables = {},
@@ -41,3 +80,57 @@ export function weekStartFor(date: Date = new Date()): string {
41
80
  d.setUTCDate(d.getUTCDate() - diff);
42
81
  return d.toISOString().slice(0, 10);
43
82
  }
83
+
84
+ // --- Reference data (for populating employment forms) ---
85
+
86
+ /** List the workspace offices — used for an employment's `employmentOfficesAttributes`. */
87
+ export async function listOffices(
88
+ client: UiduClient,
89
+ variables: ListOfficesQueryVariables = {},
90
+ ): Promise<Office[]> {
91
+ const result = await client.query(ListOfficesDocument, variables);
92
+ return nodes(result.currentWorkspace?.offices);
93
+ }
94
+
95
+ /**
96
+ * List the workspace circles. Circles come in two flavours distinguished by
97
+ * `kind`: org units (e.g. departments — used as an employment's `circleId`) and
98
+ * roles (`kind === 'role'` — used as an employment's `roleId`). Use
99
+ * {@link listRoles} when you only want the role-Circles.
100
+ */
101
+ export async function listCircles(
102
+ client: UiduClient,
103
+ variables: ListCirclesQueryVariables = {},
104
+ ): Promise<Circle[]> {
105
+ const result = await client.query(ListCirclesDocument, variables);
106
+ return nodes(result.currentWorkspace?.circles);
107
+ }
108
+
109
+ /** List only the role-Circles (structured job titles) — an employment's `roleId`. */
110
+ export async function listRoles(
111
+ client: UiduClient,
112
+ variables: ListCirclesQueryVariables = {},
113
+ ): Promise<Circle[]> {
114
+ const circles = await listCircles(client, variables);
115
+ return circles.filter((c) => c.kind === 'role');
116
+ }
117
+
118
+ /** List `Kind` records for the given polymorphic models. */
119
+ export async function listKinds(
120
+ client: UiduClient,
121
+ variables: ListKindsQueryVariables,
122
+ ): Promise<Kind[]> {
123
+ const result = await client.query(ListKindsDocument, variables);
124
+ return nodes(result.currentWorkspace?.kinds);
125
+ }
126
+
127
+ /**
128
+ * List the CCNLs (national collective labor contracts) configured for the
129
+ * workspace — used for an employment's `ccnlId`.
130
+ */
131
+ export async function listCcnls(
132
+ client: UiduClient,
133
+ variables: Omit<ListKindsQueryVariables, 'models'> = {},
134
+ ): Promise<Kind[]> {
135
+ return listKinds(client, { ...variables, models: ['Ccnl'] });
136
+ }
@@ -0,0 +1,16 @@
1
+ # Staged for codegen — validated on the next `yarn codegen` run. See plans/ai-connector.md.
2
+ mutation CreateFieldValue($input: CreateFieldValueInput!) {
3
+ createFieldValue(input: $input) {
4
+ fieldValue {
5
+ node {
6
+ id
7
+ content
8
+ }
9
+ }
10
+ errors {
11
+ key
12
+ name
13
+ type
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ # Staged for codegen — validated on the next `yarn codegen` run. See plans/ai-connector.md.
2
+ mutation CreatePage($input: CreatePageInput!) {
3
+ createPage(input: $input) {
4
+ page {
5
+ id
6
+ name
7
+ slug
8
+ }
9
+ errors {
10
+ key
11
+ name
12
+ type
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ # Staged for codegen — validated on the next `yarn codegen` run. See plans/ai-connector.md.
2
+ mutation CreatePageBlock($input: CreatePageBlockInput!) {
3
+ createPageBlock(input: $input) {
4
+ pageBlock {
5
+ id
6
+ shortname
7
+ }
8
+ errors {
9
+ key
10
+ name
11
+ type
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ # Staged for codegen — validated on the next `yarn codegen` run. See plans/ai-connector.md.
2
+ mutation CreateProject($input: CreateProjectInput!) {
3
+ createProject(input: $input) {
4
+ project {
5
+ node {
6
+ id
7
+ name
8
+ }
9
+ }
10
+ errors {
11
+ key
12
+ name
13
+ type
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,53 @@
1
+ mutation CreateContact($input: CreateContactInput!) {
2
+ createContact(input: $input) {
3
+ contact {
4
+ id
5
+ }
6
+ errors {
7
+ key
8
+ name
9
+ type
10
+ }
11
+ }
12
+ }
13
+
14
+ mutation DeleteContact($input: DeleteContactInput!) {
15
+ deleteContact(input: $input) {
16
+ contact {
17
+ id
18
+ }
19
+ errors {
20
+ key
21
+ name
22
+ type
23
+ }
24
+ }
25
+ }
26
+
27
+ mutation CreateDeal($input: CreateDealInput!) {
28
+ createDeal(input: $input) {
29
+ deal {
30
+ node {
31
+ id
32
+ }
33
+ }
34
+ errors {
35
+ key
36
+ name
37
+ type
38
+ }
39
+ }
40
+ }
41
+
42
+ mutation UpdateDeal($input: UpdateDealInput!) {
43
+ updateDeal(input: $input) {
44
+ deal {
45
+ id
46
+ }
47
+ errors {
48
+ key
49
+ name
50
+ type
51
+ }
52
+ }
53
+ }