@uidu/client 3.18.0 → 3.19.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.
- package/CHANGELOG.md +20 -0
- package/dist/declarations/src/calls.d.ts +9 -1
- package/dist/declarations/src/candidates.d.ts +102 -0
- package/dist/declarations/src/contracts.d.ts +8 -0
- package/dist/declarations/src/field-values.d.ts +34 -0
- package/dist/declarations/src/generated/index.d.ts +11792 -5143
- package/dist/declarations/src/index.d.ts +17 -3
- package/dist/declarations/src/meetings.d.ts +41 -0
- package/dist/declarations/src/mutations.d.ts +80 -131
- package/dist/declarations/src/reviews.d.ts +195 -0
- package/dist/declarations/src/skills.d.ts +34 -0
- package/dist/declarations/src/work-sites.d.ts +9 -0
- package/dist/uidu-client.cjs.dev.js +402 -31
- package/dist/uidu-client.cjs.prod.js +402 -31
- package/dist/uidu-client.esm.js +373 -32
- package/package.json +1 -1
- package/src/calls.ts +37 -0
- package/src/candidates.ts +105 -0
- package/src/contracts.ts +44 -0
- package/src/field-values.ts +95 -0
- package/src/generated/index.ts +404 -332
- package/src/index.ts +53 -2
- package/src/meetings.ts +37 -0
- package/src/mutations.test.ts +40 -1
- package/src/mutations.ts +122 -60
- package/src/queries/calls/ListCallStatuses.graphql +26 -0
- package/src/queries/candidates/CandidateFields.graphql +28 -0
- package/src/queries/candidates/CandidateMutations.graphql +35 -0
- package/src/queries/candidates/CandidateQueries.graphql +94 -0
- package/src/queries/contacts/ContactMutations.graphql +0 -13
- package/src/queries/contracts/ContractQueries.graphql +67 -0
- package/src/queries/courses/CourseMutations.graphql +0 -13
- package/src/queries/discardable/DiscardableMutations.graphql +32 -0
- package/src/queries/field-values/FieldValueFields.graphql +18 -0
- package/src/queries/field-values/FieldValueQueries.graphql +43 -0
- package/src/queries/forms/FormMutations.graphql +0 -13
- package/src/queries/help-center/ChannelMutations.graphql +0 -13
- package/src/queries/kb/KbMutations.graphql +0 -26
- package/src/queries/meetings/MeetingQueries.graphql +48 -0
- package/src/queries/notes/NoteMutations.graphql +0 -13
- package/src/queries/people/PeopleMutations.graphql +0 -13
- package/src/queries/reviews/ReviewFields.graphql +35 -0
- package/src/queries/reviews/ReviewMutations.graphql +32 -0
- package/src/queries/reviews/ReviewQueries.graphql +86 -0
- package/src/queries/skills/SkillQueries.graphql +53 -0
- package/src/queries/spaces/SpaceMutations.graphql +0 -13
- package/src/queries/tasks/TaskMutations.graphql +0 -13
- package/src/queries/work-sites/ListWorkSites.graphql +32 -0
- package/src/recruiting.test.ts +196 -0
- package/src/reviews.ts +114 -0
- package/src/skills.ts +47 -0
- package/src/work-sites.ts +28 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { listCallStatuses } from './calls';
|
|
3
|
+
import { getCandidate } from './candidates';
|
|
4
|
+
import type { UiduClient } from './client';
|
|
5
|
+
import {
|
|
6
|
+
type RecordFieldValue,
|
|
7
|
+
fieldValueAsOf,
|
|
8
|
+
getRecordFieldValues,
|
|
9
|
+
listFieldValueHistory,
|
|
10
|
+
} from './field-values';
|
|
11
|
+
import { createReview, listReviews } from './reviews';
|
|
12
|
+
|
|
13
|
+
const queryClient = (...pages: unknown[]) => {
|
|
14
|
+
const query = vi.fn();
|
|
15
|
+
for (const page of pages) query.mockResolvedValueOnce(page);
|
|
16
|
+
return { client: { query } as unknown as UiduClient, query };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const conn = <T>(
|
|
20
|
+
items: T[],
|
|
21
|
+
hasNextPage = false,
|
|
22
|
+
endCursor: string | null = null,
|
|
23
|
+
) => ({
|
|
24
|
+
pageInfo: { hasNextPage, endCursor },
|
|
25
|
+
edges: items.map((node) => ({ node })),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('getCandidate', () => {
|
|
29
|
+
it('returns the node when it is a Candidate', async () => {
|
|
30
|
+
const { client } = queryClient({
|
|
31
|
+
node: { __typename: 'Candidate', id: 'c1' },
|
|
32
|
+
});
|
|
33
|
+
expect(await getCandidate(client, { id: 'c1' })).toEqual({
|
|
34
|
+
__typename: 'Candidate',
|
|
35
|
+
id: 'c1',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('returns null for any other type', async () => {
|
|
40
|
+
const { client } = queryClient({ node: { __typename: 'Contact' } });
|
|
41
|
+
expect(await getCandidate(client, { id: 'x' })).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('listReviews', () => {
|
|
46
|
+
it('reads the connection of whichever owner the id resolves to', async () => {
|
|
47
|
+
const { client } = queryClient(
|
|
48
|
+
{
|
|
49
|
+
node: { __typename: 'Employee', employeeReviews: conn([{ id: 'r1' }]) },
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
node: { __typename: 'ReviewCycle', cycleReviews: conn([{ id: 'r2' }]) },
|
|
53
|
+
},
|
|
54
|
+
{ node: { __typename: 'Contact' } },
|
|
55
|
+
);
|
|
56
|
+
expect(await listReviews(client, { ownerId: 'e1' })).toEqual([
|
|
57
|
+
{ id: 'r1' },
|
|
58
|
+
]);
|
|
59
|
+
expect(await listReviews(client, { ownerId: 'rc1' })).toEqual([
|
|
60
|
+
{ id: 'r2' },
|
|
61
|
+
]);
|
|
62
|
+
expect(await listReviews(client, { ownerId: 'x' })).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('createReview', () => {
|
|
67
|
+
it('wraps one set of attributes into createReviews', async () => {
|
|
68
|
+
const payload = { createReviews: { reviews: [], errors: [] } };
|
|
69
|
+
const mutate = vi.fn().mockResolvedValue(payload);
|
|
70
|
+
const client = { mutate } as unknown as UiduClient;
|
|
71
|
+
|
|
72
|
+
const attributes = {
|
|
73
|
+
userId: 'u1',
|
|
74
|
+
reviewTemplateId: 't1',
|
|
75
|
+
dueOn: '2026-12-01',
|
|
76
|
+
};
|
|
77
|
+
const result = await createReview(client, attributes);
|
|
78
|
+
|
|
79
|
+
expect(mutate.mock.calls[0][1]).toEqual({
|
|
80
|
+
input: { attributes: [attributes] },
|
|
81
|
+
});
|
|
82
|
+
expect(result).toEqual(payload.createReviews);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('listCallStatuses', () => {
|
|
87
|
+
it('walks every page and sorts by position', async () => {
|
|
88
|
+
const page = (
|
|
89
|
+
statuses: unknown,
|
|
90
|
+
hasNext: boolean,
|
|
91
|
+
cursor: string | null,
|
|
92
|
+
) => ({
|
|
93
|
+
currentWorkspace: {
|
|
94
|
+
call: { statuses: conn(statuses as object[], hasNext, cursor) },
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const { client, query } = queryClient(
|
|
98
|
+
page(
|
|
99
|
+
[
|
|
100
|
+
{ id: 's3', position: 3 },
|
|
101
|
+
{ id: 's1', position: 1 },
|
|
102
|
+
],
|
|
103
|
+
true,
|
|
104
|
+
'c1',
|
|
105
|
+
),
|
|
106
|
+
page([{ id: 's2', position: 2 }], false, null),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const statuses = await listCallStatuses(client, { callId: 'call1' });
|
|
110
|
+
|
|
111
|
+
expect(statuses.map((s) => s.id)).toEqual(['s1', 's2', 's3']);
|
|
112
|
+
expect(query.mock.calls[1][1]).toEqual({
|
|
113
|
+
first: 100,
|
|
114
|
+
callId: 'call1',
|
|
115
|
+
after: 'c1',
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('getRecordFieldValues', () => {
|
|
121
|
+
it('returns the values of a record that carries fields', async () => {
|
|
122
|
+
const { client } = queryClient({
|
|
123
|
+
node: {
|
|
124
|
+
__typename: 'Contract',
|
|
125
|
+
id: 'k1',
|
|
126
|
+
fieldValuesByShortname: { fte: 1 },
|
|
127
|
+
fieldValues: [{ id: 'fv1' }],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
expect(await getRecordFieldValues(client, { id: 'k1' })).toEqual({
|
|
131
|
+
typename: 'Contract',
|
|
132
|
+
id: 'k1',
|
|
133
|
+
byShortname: { fte: 1 },
|
|
134
|
+
fieldValues: [{ id: 'fv1' }],
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('returns null for a type without fields', async () => {
|
|
139
|
+
const { client } = queryClient({ node: { __typename: 'Pool', id: 'p1' } });
|
|
140
|
+
expect(await getRecordFieldValues(client, { id: 'p1' })).toBeNull();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('listFieldValueHistory', () => {
|
|
145
|
+
it('flattens every page of the field history', async () => {
|
|
146
|
+
const page = (
|
|
147
|
+
values: unknown[],
|
|
148
|
+
hasNext: boolean,
|
|
149
|
+
cursor: string | null,
|
|
150
|
+
) => ({
|
|
151
|
+
currentWorkspace: {
|
|
152
|
+
field: { fieldValues: conn(values as object[], hasNext, cursor) },
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const { client } = queryClient(
|
|
156
|
+
page([{ id: 'a' }], true, 'c'),
|
|
157
|
+
page([{ id: 'b' }], false, null),
|
|
158
|
+
);
|
|
159
|
+
const history = await listFieldValueHistory(client, {
|
|
160
|
+
fieldId: 'f',
|
|
161
|
+
modelId: 'm',
|
|
162
|
+
});
|
|
163
|
+
expect(history.map((v) => v.id)).toEqual(['a', 'b']);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('fieldValueAsOf', () => {
|
|
168
|
+
const v = (id: string, validFrom: string | null, createdAt: string) =>
|
|
169
|
+
({ id, validFrom, createdAt }) as RecordFieldValue;
|
|
170
|
+
|
|
171
|
+
const history = [
|
|
172
|
+
v('old', '2024-01-01', '2024-01-01T09:00:00Z'),
|
|
173
|
+
v('mid', '2024-06-01', '2024-06-01T09:00:00Z'),
|
|
174
|
+
v('mid-fix', '2024-06-01', '2024-06-02T09:00:00Z'),
|
|
175
|
+
v('legacy', null, '2024-09-15T10:00:00Z'),
|
|
176
|
+
v('scheduled', '2027-01-01', '2026-11-01T09:00:00Z'),
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
it('picks the latest value holding on the date, ties to the last written', () => {
|
|
180
|
+
expect(fieldValueAsOf(history, '2024-06-30')?.id).toBe('mid-fix');
|
|
181
|
+
expect(fieldValueAsOf(history, '2024-03-01')?.id).toBe('old');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('dates a row without validFrom by its createdAt day', () => {
|
|
185
|
+
expect(fieldValueAsOf(history, '2024-09-15')?.id).toBe('legacy');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('leaves out values that start after the date', () => {
|
|
189
|
+
expect(fieldValueAsOf(history, '2026-12-31')?.id).toBe('legacy');
|
|
190
|
+
expect(fieldValueAsOf(history, '2027-01-01')?.id).toBe('scheduled');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('returns null before the first value', () => {
|
|
194
|
+
expect(fieldValueAsOf(history, '2023-12-31')).toBeNull();
|
|
195
|
+
});
|
|
196
|
+
});
|
package/src/reviews.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateReviewsDocument,
|
|
4
|
+
type CreateReviewsMutationVariables,
|
|
5
|
+
GetReviewDocument,
|
|
6
|
+
type GetReviewQueryVariables,
|
|
7
|
+
ListReviewsDocument,
|
|
8
|
+
type ListReviewsQueryVariables,
|
|
9
|
+
ListReviewTemplatesDocument,
|
|
10
|
+
type ListReviewTemplatesQuery,
|
|
11
|
+
type ListReviewTemplatesQueryVariables,
|
|
12
|
+
type ReviewAttributes,
|
|
13
|
+
type ReviewSummaryFragment,
|
|
14
|
+
UpdateReviewDocument,
|
|
15
|
+
type UpdateReviewMutationVariables,
|
|
16
|
+
} from './generated';
|
|
17
|
+
import { nodes } from './utils/relay';
|
|
18
|
+
|
|
19
|
+
// Reviews: a person (`userId`) assessed against a `ReviewTemplate`'s form.
|
|
20
|
+
// A review either belongs to a `ReviewCycle` (which brings the template) or
|
|
21
|
+
// stands on its own with `reviewTemplateId` and an optional `dueOn` — what a
|
|
22
|
+
// probation check, a 1:1 or a placement follow-up is.
|
|
23
|
+
//
|
|
24
|
+
// Reads and writes need an account (Bearer / apiKey), server-side.
|
|
25
|
+
|
|
26
|
+
export type Review = ReviewSummaryFragment;
|
|
27
|
+
export type ReviewTemplate = NonNullable<
|
|
28
|
+
NonNullable<
|
|
29
|
+
NonNullable<
|
|
30
|
+
NonNullable<
|
|
31
|
+
ListReviewTemplatesQuery['currentWorkspace']
|
|
32
|
+
>['reviewTemplates']['edges']
|
|
33
|
+
>[number]
|
|
34
|
+
>['node']
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The reviews of one person or cycle — `ownerId` is the GlobalID of an
|
|
39
|
+
* Employee, a User or a ReviewCycle — as a flat array; page with
|
|
40
|
+
* `first`/`after`.
|
|
41
|
+
*/
|
|
42
|
+
export async function listReviews(
|
|
43
|
+
client: UiduClient,
|
|
44
|
+
variables: ListReviewsQueryVariables,
|
|
45
|
+
): Promise<Review[]> {
|
|
46
|
+
const result = await client.query(ListReviewsDocument, variables);
|
|
47
|
+
const node = result.node;
|
|
48
|
+
if (!node) return [];
|
|
49
|
+
if (node.__typename === 'Employee' && 'employeeReviews' in node) {
|
|
50
|
+
return nodes(node.employeeReviews);
|
|
51
|
+
}
|
|
52
|
+
if (node.__typename === 'User' && 'userReviews' in node) {
|
|
53
|
+
return nodes(node.userReviews);
|
|
54
|
+
}
|
|
55
|
+
if (node.__typename === 'ReviewCycle' && 'cycleReviews' in node) {
|
|
56
|
+
return nodes(node.cycleReviews);
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One review by id, or null. */
|
|
62
|
+
export async function getReview(
|
|
63
|
+
client: UiduClient,
|
|
64
|
+
variables: GetReviewQueryVariables,
|
|
65
|
+
): Promise<Review | null> {
|
|
66
|
+
const result = await client.query(GetReviewDocument, variables);
|
|
67
|
+
return result.currentWorkspace?.review ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create one review. Without a cycle pass `reviewTemplateId` (and optionally
|
|
72
|
+
* `dueOn`) with the `userId`; with one pass `reviewCycleId`. Returns the
|
|
73
|
+
* `createReviews` payload as-is (including any `errors`).
|
|
74
|
+
*/
|
|
75
|
+
export async function createReview(
|
|
76
|
+
client: UiduClient,
|
|
77
|
+
attributes: ReviewAttributes,
|
|
78
|
+
) {
|
|
79
|
+
return createReviews(client, { input: { attributes: [attributes] } });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create several reviews in one call (`input.attributes` is a list). Returns
|
|
84
|
+
* the mutation payload as-is (including any `errors`).
|
|
85
|
+
*/
|
|
86
|
+
export async function createReviews(
|
|
87
|
+
client: UiduClient,
|
|
88
|
+
variables: CreateReviewsMutationVariables,
|
|
89
|
+
) {
|
|
90
|
+
const result = await client.mutate(CreateReviewsDocument, variables);
|
|
91
|
+
return result.createReviews ?? null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Update a review — its `dueOn`, its answers (`formResponseAttributes`) or its
|
|
96
|
+
* skill scores (`skillsAttributes`). Returns the mutation payload as-is
|
|
97
|
+
* (including any `errors`).
|
|
98
|
+
*/
|
|
99
|
+
export async function updateReview(
|
|
100
|
+
client: UiduClient,
|
|
101
|
+
variables: UpdateReviewMutationVariables,
|
|
102
|
+
) {
|
|
103
|
+
const result = await client.mutate(UpdateReviewDocument, variables);
|
|
104
|
+
return result.updateReview ?? null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The workspace's review templates; page with `first`/`after`. */
|
|
108
|
+
export async function listReviewTemplates(
|
|
109
|
+
client: UiduClient,
|
|
110
|
+
variables: ListReviewTemplatesQueryVariables = {},
|
|
111
|
+
): Promise<ReviewTemplate[]> {
|
|
112
|
+
const result = await client.query(ListReviewTemplatesDocument, variables);
|
|
113
|
+
return nodes(result.currentWorkspace?.reviewTemplates);
|
|
114
|
+
}
|
package/src/skills.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateSkillDocument,
|
|
4
|
+
type CreateSkillMutationVariables,
|
|
5
|
+
ListSkillsDocument,
|
|
6
|
+
type ListSkillsQuery,
|
|
7
|
+
type ListSkillsQueryVariables,
|
|
8
|
+
} from './generated';
|
|
9
|
+
import { nodes } from './utils/relay';
|
|
10
|
+
|
|
11
|
+
// Skills: `WorkspaceSkill` is the workspace's catalog entry ("Forklift
|
|
12
|
+
// licence", "Italian B2"); a `Skill` is one of them held by someone
|
|
13
|
+
// (`skillableId`, e.g. a User), with an optional `score` and the review it
|
|
14
|
+
// came from (`sourceId`). Reads and writes need an account (Bearer / apiKey).
|
|
15
|
+
|
|
16
|
+
export type WorkspaceSkill = NonNullable<
|
|
17
|
+
NonNullable<
|
|
18
|
+
NonNullable<
|
|
19
|
+
NonNullable<
|
|
20
|
+
ListSkillsQuery['currentWorkspace']
|
|
21
|
+
>['workspaceSkills']['edges']
|
|
22
|
+
>[number]
|
|
23
|
+
>['node']
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
/** The workspace's skill catalog; page with `first`/`after`. */
|
|
27
|
+
export async function listSkills(
|
|
28
|
+
client: UiduClient,
|
|
29
|
+
variables: ListSkillsQueryVariables = {},
|
|
30
|
+
): Promise<WorkspaceSkill[]> {
|
|
31
|
+
const result = await client.query(ListSkillsDocument, variables);
|
|
32
|
+
return nodes(result.currentWorkspace?.workspaceSkills);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Give someone a skill: `attributes: { skillableId, workspaceSkillId, score? }`
|
|
37
|
+
* (`skillableId` is e.g. a User's GlobalID; `sourceId` a Review, when the
|
|
38
|
+
* skill was assessed in one). Returns the mutation payload as-is (including
|
|
39
|
+
* any `errors`).
|
|
40
|
+
*/
|
|
41
|
+
export async function createSkill(
|
|
42
|
+
client: UiduClient,
|
|
43
|
+
variables: CreateSkillMutationVariables,
|
|
44
|
+
) {
|
|
45
|
+
const result = await client.mutate(CreateSkillDocument, variables);
|
|
46
|
+
return result.createSkill ?? null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
ListWorkSitesDocument,
|
|
4
|
+
type ListWorkSitesQuery,
|
|
5
|
+
type ListWorkSitesQueryVariables,
|
|
6
|
+
} from './generated';
|
|
7
|
+
import { nodes } from './utils/relay';
|
|
8
|
+
|
|
9
|
+
export type WorkSite = NonNullable<
|
|
10
|
+
NonNullable<
|
|
11
|
+
NonNullable<
|
|
12
|
+
NonNullable<ListWorkSitesQuery['currentWorkspace']>['workSites']['edges']
|
|
13
|
+
>[number]
|
|
14
|
+
>['node']
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The workspace's work sites — where people are placed, each with its
|
|
19
|
+
* analytic account, address and custom fields (`fieldValuesByShortname`) — as
|
|
20
|
+
* a flat array; page with `first`/`after`. Requires a Bearer token (`apiKey`).
|
|
21
|
+
*/
|
|
22
|
+
export async function listWorkSites(
|
|
23
|
+
client: UiduClient,
|
|
24
|
+
variables: ListWorkSitesQueryVariables = {},
|
|
25
|
+
): Promise<WorkSite[]> {
|
|
26
|
+
const result = await client.query(ListWorkSitesDocument, variables);
|
|
27
|
+
return nodes(result.currentWorkspace?.workSites);
|
|
28
|
+
}
|